Ctx was recently added as a more suitable place for such singletons.
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.
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`
sym->extract();
}
-void LinkerDriver::writeArchiveStats() const {
+static void writeArchiveStats() {
if (config->printArchiveStats.empty())
return;
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.
}
}
-void LinkerDriver::writeWhyExtract() const {
+static void writeWhyExtract() {
if (config->whyExtract.empty())
return;
}
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
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;
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.
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) {
// 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;
}
// 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;
if (!isUndefined()) {
// See the comment in resolveUndefined().
if (isDefined())
- driver->backwardReferences.erase(this);
+ ctx->backwardReferences.erase(this);
return;
}
InputSectionBase *errSec, uint64_t errOffset);
void maybeWarnUnorderableSymbol(const Symbol *sym);
bool computeIsPreemptible(const Symbol &sym);
-void reportBackrefs();
} // namespace elf
} // namespace lld