[lld] d14d866 - [ELF] Change global variable backwardReferences to a LinkerDriver member variable. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 27 12:33:34 PST 2022
Author: Fangrui Song
Date: 2022-02-27T20:33:28Z
New Revision: d14d8664e3e44a0b87b39c3eeace3d82fabbbd27
URL: https://github.com/llvm/llvm-project/commit/d14d8664e3e44a0b87b39c3eeace3d82fabbbd27
DIFF: https://github.com/llvm/llvm-project/commit/d14d8664e3e44a0b87b39c3eeace3d82fabbbd27.diff
LOG: [ELF] Change global variable backwardReferences to a LinkerDriver member variable. NFC
Similar to whyExtract.
Added:
Modified:
lld/ELF/Driver.cpp
lld/ELF/Driver.h
lld/ELF/Symbols.cpp
lld/ELF/Symbols.h
Removed:
################################################################################
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 78350260ee4b..3f767b5df946 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -102,7 +102,6 @@ bool elf::link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
lazyBitcodeFiles.clear();
objectFiles.clear();
sharedFiles.clear();
- backwardReferences.clear();
symAux.clear();
tar = nullptr;
@@ -1781,6 +1780,25 @@ void LinkerDriver::writeWhyExtract() const {
}
}
+void LinkerDriver::reportBackrefs() const {
+ for (auto &ref : 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
+ // with --warn-backrefs-exclude=. The value may look like (for --start-lib)
+ // *.o or (archive member) *.a(*.o).
+ bool exclude = false;
+ for (const llvm::GlobPattern &pat : config->warnBackrefsExclude)
+ if (pat.match(to)) {
+ exclude = true;
+ break;
+ }
+ if (!exclude)
+ warn("backward reference detected: " + sym.getName() + " in " +
+ toString(ref.second.first) + " refers to " + to);
+ }
+}
+
// Handle --dependency-file=<path>. If that option is given, lld creates a
// file at a given path with the following contents:
//
diff --git a/lld/ELF/Driver.h b/lld/ELF/Driver.h
index 0ec47d2a8121..09d2f761feeb 100644
--- a/lld/ELF/Driver.h
+++ b/lld/ELF/Driver.h
@@ -35,6 +35,7 @@ class LinkerDriver {
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;
@@ -52,6 +53,11 @@ class LinkerDriver {
// 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;
};
// Parses command line options.
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index 4fab75ab7526..484ad8ea27e6 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -49,8 +49,6 @@ Defined *ElfSym::relaIpltStart;
Defined *ElfSym::relaIpltEnd;
Defined *ElfSym::riscvGlobalPointer;
Defined *ElfSym::tlsModuleBase;
-DenseMap<const Symbol *, std::pair<const InputFile *, const InputFile *>>
- elf::backwardReferences;
SmallVector<SymbolAux, 0> elf::symAux;
static uint64_t getSymVA(const Symbol &sym, int64_t addend) {
@@ -350,24 +348,6 @@ bool elf::computeIsPreemptible(const Symbol &sym) {
return true;
}
-void elf::reportBackrefs() {
- for (auto &it : backwardReferences) {
- const Symbol &sym = *it.first;
- std::string to = toString(it.second.second);
- // Some libraries have known problems and can cause noise. Filter them out
- // with --warn-backrefs-exclude=. to may look like *.o or *.a(*.o).
- bool exclude = false;
- for (const llvm::GlobPattern &pat : config->warnBackrefsExclude)
- if (pat.match(to)) {
- exclude = true;
- break;
- }
- if (!exclude)
- warn("backward reference detected: " + sym.getName() + " in " +
- toString(it.second.first) + " refers to " + to);
- }
-}
-
static uint8_t getMinVisibility(uint8_t va, uint8_t vb) {
if (va == STV_DEFAULT)
return vb;
@@ -509,7 +489,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())
- backwardReferences.try_emplace(this, std::make_pair(other.file, file));
+ driver->backwardReferences.try_emplace(this,
+ std::make_pair(other.file, file));
return;
}
@@ -633,7 +614,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())) {
- backwardReferences.erase(this);
+ driver->backwardReferences.erase(this);
replace(other);
other.extract();
return;
@@ -642,7 +623,7 @@ void Symbol::resolveLazy(const LazyObject &other) {
if (!isUndefined()) {
// See the comment in resolveUndefined().
if (isDefined())
- backwardReferences.erase(this);
+ driver->backwardReferences.erase(this);
return;
}
diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index 4108cb8220aa..b210659f9a35 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -563,12 +563,6 @@ void maybeWarnUnorderableSymbol(const Symbol *sym);
bool computeIsPreemptible(const Symbol &sym);
void reportBackrefs();
-// A mapping from a symbol to an InputFile referencing it backward. Used by
-// --warn-backrefs.
-extern llvm::DenseMap<const Symbol *,
- std::pair<const InputFile *, const InputFile *>>
- backwardReferences;
-
} // namespace elf
} // namespace lld
More information about the llvm-commits
mailing list