mirror of
https://github.com/intel/llvm.git
synced 2026-01-17 23:45:25 +08:00
[ELF] Move whyExtract/backwardReferences from LinkerDriver to Ctx. NFC
Ctx was recently added as a more suitable place for such singletons.
This commit is contained in:
@@ -380,6 +380,14 @@ struct Ctx {
|
||||
SmallVector<std::pair<Symbol *, unsigned>, 0> nonPrevailingSyms;
|
||||
// True if SHT_LLVM_SYMPART is used.
|
||||
std::atomic<bool> hasSympart{false};
|
||||
// A tuple of (reference, extractedFile, sym). Used by --why-extract=.
|
||||
SmallVector<std::tuple<std::string, const InputFile *, const Symbol &>, 0>
|
||||
whyExtractRecords;
|
||||
// A mapping from a symbol to an InputFile referencing it backward. Used by
|
||||
// --warn-backrefs.
|
||||
llvm::DenseMap<const Symbol *,
|
||||
std::pair<const InputFile *, const InputFile *>>
|
||||
backwardReferences;
|
||||
};
|
||||
|
||||
// The only instance of Ctx struct.
|
||||
|
||||
@@ -1774,7 +1774,7 @@ static void handleUndefined(Symbol *sym, const char *option) {
|
||||
return;
|
||||
sym->extract();
|
||||
if (!config->whyExtract.empty())
|
||||
driver->whyExtract.emplace_back(option, sym->file, *sym);
|
||||
ctx->whyExtractRecords.emplace_back(option, sym->file, *sym);
|
||||
}
|
||||
|
||||
// As an extension to GNU linkers, lld supports a variant of `-u`
|
||||
@@ -1810,7 +1810,7 @@ static void handleLibcall(StringRef name) {
|
||||
sym->extract();
|
||||
}
|
||||
|
||||
void LinkerDriver::writeArchiveStats() const {
|
||||
static void writeArchiveStats() {
|
||||
if (config->printArchiveStats.empty())
|
||||
return;
|
||||
|
||||
@@ -1832,7 +1832,7 @@ void LinkerDriver::writeArchiveStats() const {
|
||||
for (BitcodeFile *file : bitcodeFiles)
|
||||
if (file->archiveName.size())
|
||||
++extracted[CachedHashStringRef(file->archiveName)];
|
||||
for (std::pair<StringRef, unsigned> f : archiveFiles) {
|
||||
for (std::pair<StringRef, unsigned> f : driver->archiveFiles) {
|
||||
unsigned &v = extracted[CachedHashString(f.first)];
|
||||
os << f.second << '\t' << v << '\t' << f.first << '\n';
|
||||
// If the archive occurs multiple times, other instances have a count of 0.
|
||||
@@ -1840,7 +1840,7 @@ void LinkerDriver::writeArchiveStats() const {
|
||||
}
|
||||
}
|
||||
|
||||
void LinkerDriver::writeWhyExtract() const {
|
||||
static void writeWhyExtract() {
|
||||
if (config->whyExtract.empty())
|
||||
return;
|
||||
|
||||
@@ -1853,14 +1853,14 @@ void LinkerDriver::writeWhyExtract() const {
|
||||
}
|
||||
|
||||
os << "reference\textracted\tsymbol\n";
|
||||
for (auto &entry : whyExtract) {
|
||||
for (auto &entry : ctx->whyExtractRecords) {
|
||||
os << std::get<0>(entry) << '\t' << toString(std::get<1>(entry)) << '\t'
|
||||
<< toString(std::get<2>(entry)) << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
void LinkerDriver::reportBackrefs() const {
|
||||
for (auto &ref : backwardReferences) {
|
||||
static void reportBackrefs() {
|
||||
for (auto &ref : ctx->backwardReferences) {
|
||||
const Symbol &sym = *ref.first;
|
||||
std::string to = toString(ref.second.second);
|
||||
// Some libraries have known problems and can cause noise. Filter them out
|
||||
|
||||
@@ -33,9 +33,6 @@ private:
|
||||
void inferMachineType();
|
||||
void link(llvm::opt::InputArgList &args);
|
||||
template <class ELFT> void compileBitcodeFiles(bool skipLinkedOutput);
|
||||
void writeArchiveStats() const;
|
||||
void writeWhyExtract() const;
|
||||
void reportBackrefs() const;
|
||||
|
||||
// True if we are in --whole-archive and --no-whole-archive.
|
||||
bool inWholeArchive = false;
|
||||
@@ -47,17 +44,9 @@ private:
|
||||
std::unique_ptr<BitcodeCompiler> lto;
|
||||
|
||||
std::vector<InputFile *> files;
|
||||
SmallVector<std::pair<StringRef, unsigned>, 0> archiveFiles;
|
||||
|
||||
public:
|
||||
// A tuple of (reference, extractedFile, sym). Used by --why-extract=.
|
||||
SmallVector<std::tuple<std::string, const InputFile *, const Symbol &>, 0>
|
||||
whyExtract;
|
||||
// A mapping from a symbol to an InputFile referencing it backward. Used by
|
||||
// --warn-backrefs.
|
||||
llvm::DenseMap<const Symbol *,
|
||||
std::pair<const InputFile *, const InputFile *>>
|
||||
backwardReferences;
|
||||
SmallVector<std::pair<StringRef, unsigned>, 0> archiveFiles;
|
||||
};
|
||||
|
||||
// Parses command line options.
|
||||
|
||||
@@ -304,7 +304,7 @@ void elf::printTraceSymbol(const Symbol &sym, StringRef name) {
|
||||
|
||||
static void recordWhyExtract(const InputFile *reference,
|
||||
const InputFile &extracted, const Symbol &sym) {
|
||||
driver->whyExtract.emplace_back(toString(reference), &extracted, sym);
|
||||
ctx->whyExtractRecords.emplace_back(toString(reference), &extracted, sym);
|
||||
}
|
||||
|
||||
void elf::maybeWarnUnorderableSymbol(const Symbol *sym) {
|
||||
@@ -508,8 +508,8 @@ void Symbol::resolveUndefined(const Undefined &other) {
|
||||
// definition. this->file needs to be saved because in the case of LTO it
|
||||
// may be reset to nullptr or be replaced with a file named lto.tmp.
|
||||
if (backref && !isWeak())
|
||||
driver->backwardReferences.try_emplace(this,
|
||||
std::make_pair(other.file, file));
|
||||
ctx->backwardReferences.try_emplace(this,
|
||||
std::make_pair(other.file, file));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -647,7 +647,7 @@ void Symbol::resolveLazy(const LazyObject &other) {
|
||||
// should be extracted as the canonical definition instead.
|
||||
if (LLVM_UNLIKELY(isCommon()) && elf::config->fortranCommon &&
|
||||
other.file->shouldExtractForCommon(getName())) {
|
||||
driver->backwardReferences.erase(this);
|
||||
ctx->backwardReferences.erase(this);
|
||||
replace(other);
|
||||
other.extract();
|
||||
return;
|
||||
@@ -656,7 +656,7 @@ void Symbol::resolveLazy(const LazyObject &other) {
|
||||
if (!isUndefined()) {
|
||||
// See the comment in resolveUndefined().
|
||||
if (isDefined())
|
||||
driver->backwardReferences.erase(this);
|
||||
ctx->backwardReferences.erase(this);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -554,7 +554,6 @@ void reportDuplicate(const Symbol &sym, const InputFile *newFile,
|
||||
InputSectionBase *errSec, uint64_t errOffset);
|
||||
void maybeWarnUnorderableSymbol(const Symbol *sym);
|
||||
bool computeIsPreemptible(const Symbol &sym);
|
||||
void reportBackrefs();
|
||||
|
||||
} // namespace elf
|
||||
} // namespace lld
|
||||
|
||||
Reference in New Issue
Block a user