[lld] e980f16 - [ELF] Move whyExtract/backwardReferences from LinkerDriver to Ctx. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 29 17:34:35 PDT 2022
Author: Fangrui Song
Date: 2022-06-29T17:34:31-07:00
New Revision: e980f16d52196fb2bc672ecb87e0f622253addec
URL: https://github.com/llvm/llvm-project/commit/e980f16d52196fb2bc672ecb87e0f622253addec
DIFF: https://github.com/llvm/llvm-project/commit/e980f16d52196fb2bc672ecb87e0f622253addec.diff
LOG: [ELF] Move whyExtract/backwardReferences from LinkerDriver to Ctx. NFC
Ctx was recently added as a more suitable place for such singletons.
Added:
Modified:
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/Driver.h
lld/ELF/Symbols.cpp
lld/ELF/Symbols.h
Removed:
################################################################################
diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index 590c19e6d88dd..915c4d94e8704 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -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.
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 8315d43c776e8..2ab698c91b019 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -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
diff --git a/lld/ELF/Driver.h b/lld/ELF/Driver.h
index 09d2f761feeb5..c5c46fbf1e208 100644
--- a/lld/ELF/Driver.h
+++ b/lld/ELF/Driver.h
@@ -33,9 +33,6 @@ class LinkerDriver {
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 @@ class LinkerDriver {
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.
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index 5706f54c2e0c7..985e483df2adf 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -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;
}
diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index 8f193e3fbdd56..657c19a00ba36 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -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
More information about the llvm-commits
mailing list