forked from OSchip/llvm-project
[ELF] Change global variable backwardReferences to a LinkerDriver member variable. NFC
Similar to whyExtract.
This commit is contained in:
parent
7fd3849b35
commit
d14d8664e3
|
@ -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:
|
||||
//
|
||||
|
|
|
@ -35,6 +35,7 @@ private:
|
|||
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 @@ 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;
|
||||
};
|
||||
|
||||
// Parses command line options.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue