[ELF] Remove symtab indirection. NFC

Add LLVM_LIBRARY_VISIBILITY to remove unneeded GOT and unique_ptr indirection.
This commit is contained in:
Fangrui Song 2022-10-01 14:46:49 -07:00
parent 424c69190c
commit 9c626d4a0d
14 changed files with 77 additions and 82 deletions

View File

@ -194,7 +194,7 @@ void elf::writePrefixedInstruction(uint8_t *loc, uint64_t insn) {
static bool addOptional(StringRef name, uint64_t value,
std::vector<Defined *> &defined) {
Symbol *sym = symtab->find(name);
Symbol *sym = symtab.find(name);
if (!sym || sym->isDefined())
return false;
sym->resolve(Defined{/*file=*/nullptr, StringRef(), STB_GLOBAL, STV_HIDDEN,

View File

@ -111,6 +111,7 @@ bool elf::link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
ctx->e.initialize(stdoutOS, stderrOS, exitEarly, disableOutput);
ctx->e.cleanupCallback = []() {
elf::ctx.reset();
symtab = SymbolTable();
inputSections.clear();
ehInputSections.clear();
@ -132,7 +133,6 @@ bool elf::link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
config = ConfigWrapper();
driver = std::make_unique<LinkerDriver>();
script = std::make_unique<LinkerScript>();
symtab = std::make_unique<SymbolTable>();
symAux.emplace_back();
@ -1837,7 +1837,7 @@ static void handleUndefinedGlob(StringRef arg) {
// Calling sym->extract() in the loop is not safe because it may add new
// symbols to the symbol table, invalidating the current iterator.
SmallVector<Symbol *, 0> syms;
for (Symbol *sym : symtab->getSymbols())
for (Symbol *sym : symtab.getSymbols())
if (!sym->isPlaceholder() && pat->match(sym->getName()))
syms.push_back(sym);
@ -1846,7 +1846,7 @@ static void handleUndefinedGlob(StringRef arg) {
}
static void handleLibcall(StringRef name) {
Symbol *sym = symtab->find(name);
Symbol *sym = symtab.find(name);
if (!sym || !sym->isLazy())
return;
@ -2024,7 +2024,7 @@ static void replaceCommonSymbols() {
// --no-allow-shlib-undefined diagnostics. Similarly, demote lazy symbols.
static void demoteSharedAndLazySymbols() {
llvm::TimeTraceScope timeScope("Demote shared and lazy symbols");
for (Symbol *sym : symtab->getSymbols()) {
for (Symbol *sym : symtab.getSymbols()) {
auto *s = dyn_cast<SharedSymbol>(sym);
if (!(s && !cast<SharedFile>(s->file)->isNeeded) && !sym->isLazy())
continue;
@ -2054,7 +2054,7 @@ template <class ELFT>
static void findKeepUniqueSections(opt::InputArgList &args) {
for (auto *arg : args.filtered(OPT_keep_unique)) {
StringRef name = arg->getValue();
auto *d = dyn_cast_or_null<Defined>(symtab->find(name));
auto *d = dyn_cast_or_null<Defined>(symtab.find(name));
if (!d || !d->section) {
warn("could not find symbol " + name + " to keep unique");
continue;
@ -2069,7 +2069,7 @@ static void findKeepUniqueSections(opt::InputArgList &args) {
// Symbols in the dynsym could be address-significant in other executables
// or DSOs, so we conservatively mark them as address-significant.
for (Symbol *sym : symtab->getSymbols())
for (Symbol *sym : symtab.getSymbols())
if (sym->includeInDynsym())
markAddrsig(sym);
@ -2152,7 +2152,7 @@ static void readSymbolPartitionSection(InputSectionBase *s) {
static Symbol *addUnusedUndefined(StringRef name,
uint8_t binding = STB_GLOBAL) {
return symtab->addSymbol(Undefined{nullptr, name, binding, STV_DEFAULT, 0});
return symtab.addSymbol(Undefined{nullptr, name, binding, STV_DEFAULT, 0});
}
static void markBuffersAsDontNeed(bool skipLinkedOutput) {
@ -2236,7 +2236,7 @@ static std::vector<WrappedSymbol> addWrappedSymbols(opt::InputArgList &args) {
if (!seen.insert(name).second)
continue;
Symbol *sym = symtab->find(name);
Symbol *sym = symtab.find(name);
if (!sym)
continue;
@ -2277,7 +2277,7 @@ static void combineVersionedSymbol(Symbol &sym,
//
// * There is a definition of foo@v1 and foo@@v1.
// * There is a definition of foo@v1 and foo.
Defined *sym2 = dyn_cast_or_null<Defined>(symtab->find(sym.getName()));
Defined *sym2 = dyn_cast_or_null<Defined>(symtab.find(sym.getName()));
if (!sym2)
return;
const char *suffix2 = sym2->getVersionSuffix();
@ -2332,7 +2332,7 @@ static void redirectSymbols(ArrayRef<WrappedSymbol> wrapped) {
// symbols with a non-default version (foo@v1) and check whether it should be
// combined with foo or foo@@v1.
if (config->versionDefinitions.size() > 2)
for (Symbol *sym : symtab->getSymbols())
for (Symbol *sym : symtab.getSymbols())
if (sym->hasVersionSuffix)
combineVersionedSymbol(*sym, map);
@ -2348,7 +2348,7 @@ static void redirectSymbols(ArrayRef<WrappedSymbol> wrapped) {
// Update pointers in the symbol table.
for (const WrappedSymbol &w : wrapped)
symtab->wrap(w.sym, w.real, w.wrap);
symtab.wrap(w.sym, w.real, w.wrap);
}
static void checkAndReportMissingFeature(StringRef config, uint32_t features,
@ -2502,7 +2502,7 @@ void LinkerDriver::link(opt::InputArgList &args) {
// Handle --trace-symbol.
for (auto *arg : args.filtered(OPT_trace_symbol))
symtab->insert(arg->getValue())->traced = true;
symtab.insert(arg->getValue())->traced = true;
// Handle -u/--undefined before input files. If both a.a and b.so define foo,
// -u foo a.a b.so will extract a.a.
@ -2540,11 +2540,11 @@ void LinkerDriver::link(opt::InputArgList &args) {
// Prevent LTO from removing any definition referenced by -u.
for (StringRef name : config->undefined)
if (Defined *sym = dyn_cast_or_null<Defined>(symtab->find(name)))
if (Defined *sym = dyn_cast_or_null<Defined>(symtab.find(name)))
sym->isUsedInRegularObj = true;
// If an entry symbol is in a static archive, pull out that file now.
if (Symbol *sym = symtab->find(config->entry))
if (Symbol *sym = symtab.find(config->entry))
handleUndefined(sym, "--entry");
// Handle the `--undefined-glob <pattern>` options.
@ -2552,9 +2552,9 @@ void LinkerDriver::link(opt::InputArgList &args) {
handleUndefinedGlob(pat);
// Mark -init and -fini symbols so that the LTO doesn't eliminate them.
if (Symbol *sym = dyn_cast_or_null<Defined>(symtab->find(config->init)))
if (Symbol *sym = dyn_cast_or_null<Defined>(symtab.find(config->init)))
sym->isUsedInRegularObj = true;
if (Symbol *sym = dyn_cast_or_null<Defined>(symtab->find(config->fini)))
if (Symbol *sym = dyn_cast_or_null<Defined>(symtab.find(config->fini)))
sym->isUsedInRegularObj = true;
// If any of our inputs are bitcode files, the LTO code generator may create
@ -2633,7 +2633,7 @@ void LinkerDriver::link(opt::InputArgList &args) {
// name "foo@ver1") rather do harm, so we don't call this if -r is given.
if (!config->relocatable) {
llvm::TimeTraceScope timeScope("Process symbol versions");
symtab->scanVersionScript();
symtab.scanVersionScript();
}
// Skip the normal linked output if some LTO options are specified.

View File

@ -460,7 +460,7 @@ template <class ELFT> void ICF<ELFT>::run() {
// cannot be merged with the later computeIsPreemptible() pass which is used
// by scanRelocations().
if (config->hasDynSymTab)
for (Symbol *sym : symtab->getSymbols())
for (Symbol *sym : symtab.getSymbols())
sym->isPreemptible = computeIsPreemptible(*sym);
// Two text sections may have identical content and relocations but different
@ -558,7 +558,7 @@ template <class ELFT> void ICF<ELFT>::run() {
d->folded = true;
}
};
for (Symbol *sym : symtab->getSymbols())
for (Symbol *sym : symtab.getSymbols())
fold(sym);
parallelForEach(ctx.objectFiles, [&](ELFFileBase *file) {
for (Symbol *sym : file->getLocalSymbols())

View File

@ -616,7 +616,7 @@ template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
bool keepGroup =
(flag & GRP_COMDAT) == 0 || ignoreComdats ||
symtab->comdatGroups.try_emplace(CachedHashStringRef(signature), this)
symtab.comdatGroups.try_emplace(CachedHashStringRef(signature), this)
.second;
if (keepGroup) {
if (config->relocatable)
@ -754,7 +754,7 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats,
ArrayRef<Elf_Word> entries =
cantFail(obj.template getSectionContentsAsArray<Elf_Word>(sec));
if ((entries[0] & GRP_COMDAT) == 0 || ignoreComdats ||
symtab->comdatGroups.find(CachedHashStringRef(signature))->second ==
symtab.comdatGroups.find(CachedHashStringRef(signature))->second ==
this)
selectedGroups.push_back(entries);
break;
@ -1031,8 +1031,6 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(uint32_t idx,
// its corresponding ELF symbol table.
template <class ELFT>
void ObjFile<ELFT>::initializeSymbols(const object::ELFFile<ELFT> &obj) {
SymbolTable &symtab = *elf::symtab;
ArrayRef<Elf_Sym> eSyms = this->getELFSyms<ELFT>();
symbols.resize(eSyms.size());
@ -1412,7 +1410,7 @@ template <class ELFT> void SharedFile::parse() {
DenseMap<CachedHashStringRef, SharedFile *>::iterator it;
bool wasInserted;
std::tie(it, wasInserted) =
symtab->soNames.try_emplace(CachedHashStringRef(soName), this);
symtab.soNames.try_emplace(CachedHashStringRef(soName), this);
// If a DSO appears more than once on the command line with and without
// --as-needed, --no-as-needed takes precedence over --as-needed because a
@ -1447,7 +1445,6 @@ template <class ELFT> void SharedFile::parse() {
SmallString<0> versionedNameBuffer;
// Add symbols to the symbol table.
SymbolTable &symtab = *elf::symtab;
ArrayRef<Elf_Sym> syms = this->getGlobalELFSyms<ELFT>();
for (size_t i = 0, e = syms.size(); i != e; ++i) {
const Elf_Sym &sym = syms[i];
@ -1639,7 +1636,7 @@ createBitcodeSymbol(Symbol *&sym, const std::vector<bool> &keptComdats,
uint8_t visibility = mapVisibility(objSym.getVisibility());
if (!sym)
sym = symtab->insert(saver().save(objSym.getName()));
sym = symtab.insert(saver().save(objSym.getName()));
int c = objSym.getComdatIndex();
if (objSym.isUndefined() || (c != -1 && !keptComdats[c])) {
@ -1665,7 +1662,7 @@ void BitcodeFile::parse() {
for (std::pair<StringRef, Comdat::SelectionKind> s : obj->getComdatTable()) {
keptComdats.push_back(
s.second == Comdat::NoDeduplicate ||
symtab->comdatGroups.try_emplace(CachedHashStringRef(s.first), this)
symtab.comdatGroups.try_emplace(CachedHashStringRef(s.first), this)
.second);
}
@ -1684,7 +1681,6 @@ void BitcodeFile::parse() {
}
void BitcodeFile::parseLazy() {
SymbolTable &symtab = *elf::symtab;
symbols.resize(obj->symbols().size());
for (auto [i, irSym] : llvm::enumerate(obj->symbols()))
if (!irSym.isUndefined()) {
@ -1724,13 +1720,13 @@ void BinaryFile::parse() {
llvm::StringSaver &saver = lld::saver();
symtab->addAndCheckDuplicate(Defined{nullptr, saver.save(s + "_start"),
STB_GLOBAL, STV_DEFAULT, STT_OBJECT, 0,
0, section});
symtab->addAndCheckDuplicate(Defined{nullptr, saver.save(s + "_end"),
symtab.addAndCheckDuplicate(Defined{nullptr, saver.save(s + "_start"),
STB_GLOBAL, STV_DEFAULT, STT_OBJECT, 0, 0,
section});
symtab.addAndCheckDuplicate(Defined{nullptr, saver.save(s + "_end"),
STB_GLOBAL, STV_DEFAULT, STT_OBJECT,
data.size(), 0, section});
symtab->addAndCheckDuplicate(Defined{nullptr, saver.save(s + "_size"),
symtab.addAndCheckDuplicate(Defined{nullptr, saver.save(s + "_size"),
STB_GLOBAL, STV_DEFAULT, STT_OBJECT,
data.size(), 0, nullptr});
}
@ -1760,8 +1756,6 @@ ELFFileBase *elf::createObjFile(MemoryBufferRef mb, StringRef archiveName,
template <class ELFT> void ObjFile<ELFT>::parseLazy() {
const ArrayRef<typename ELFT::Sym> eSyms = this->getELFSyms<ELFT>();
SymbolTable &symtab = *elf::symtab;
symbols.resize(eSyms.size());
for (size_t i = firstGlobal, end = eSyms.size(); i != end; ++i)
if (eSyms[i].st_shndx != SHN_UNDEF)

View File

@ -1119,7 +1119,7 @@ static void switchMorestackCallsToMorestackNonSplit(
// If the target adjusted a function's prologue, all calls to
// __morestack inside that function should be switched to
// __morestack_non_split.
Symbol *moreStackNonSplit = symtab->find("__morestack_non_split");
Symbol *moreStackNonSplit = symtab.find("__morestack_non_split");
if (!moreStackNonSplit) {
error("mixing split-stack objects requires a definition of "
"__morestack_non_split");

View File

@ -213,7 +213,7 @@ BitcodeCompiler::BitcodeCompiler() {
// Initialize usedStartStop.
if (ctx.bitcodeFiles.empty())
return;
for (Symbol *sym : symtab->getSymbols()) {
for (Symbol *sym : symtab.getSymbols()) {
if (sym->isPlaceholder())
continue;
StringRef s = sym->getName();

View File

@ -203,7 +203,7 @@ static bool shouldDefineSym(SymbolAssignment *cmd) {
// If a symbol was in PROVIDE(), we need to define it only
// when it is a referenced undefined symbol.
Symbol *b = symtab->find(cmd->name);
Symbol *b = symtab.find(cmd->name);
if (b && !b->isDefined() && !b->isCommon())
return true;
return false;
@ -236,7 +236,7 @@ void LinkerScript::addSymbol(SymbolAssignment *cmd) {
Defined newSym(nullptr, cmd->name, STB_GLOBAL, visibility, value.type,
symValue, 0, sec);
Symbol *sym = symtab->insert(cmd->name);
Symbol *sym = symtab.insert(cmd->name);
sym->mergeProperties(newSym);
newSym.overwrite(*sym);
sym->isUsedInRegularObj = true;
@ -254,7 +254,7 @@ static void declareSymbol(SymbolAssignment *cmd) {
nullptr);
// We can't calculate final value right now.
Symbol *sym = symtab->insert(cmd->name);
Symbol *sym = symtab.insert(cmd->name);
sym->mergeProperties(newSym);
newSym.overwrite(*sym);
@ -1386,7 +1386,7 @@ ExprValue LinkerScript::getSymbolValue(StringRef name, const Twine &loc) {
return 0;
}
if (Symbol *sym = symtab->find(name)) {
if (Symbol *sym = symtab.find(name)) {
if (auto *ds = dyn_cast<Defined>(sym)) {
ExprValue v{ds->section, false, ds->value, loc};
// Retain the original st_type, so that the alias will get the same

View File

@ -213,7 +213,7 @@ template <class ELFT> void MarkLive<ELFT>::run() {
// Preserve externally-visible symbols if the symbols defined by this
// file can interrupt other ELF file's symbols at runtime.
for (Symbol *sym : symtab->getSymbols())
for (Symbol *sym : symtab.getSymbols())
if (sym->includeInDynsym() && sym->partition == partition)
markSymbol(sym);
@ -223,13 +223,13 @@ template <class ELFT> void MarkLive<ELFT>::run() {
return;
}
markSymbol(symtab->find(config->entry));
markSymbol(symtab->find(config->init));
markSymbol(symtab->find(config->fini));
markSymbol(symtab.find(config->entry));
markSymbol(symtab.find(config->init));
markSymbol(symtab.find(config->fini));
for (StringRef s : config->undefined)
markSymbol(symtab->find(s));
markSymbol(symtab.find(s));
for (StringRef s : script->referencedSymbols)
markSymbol(symtab->find(s));
markSymbol(symtab.find(s));
// Mark .eh_frame sections as live because there are usually no relocations
// that point to .eh_frames. Otherwise, the garbage collector would drop
@ -338,8 +338,8 @@ template <class ELFT> void MarkLive<ELFT>::moveToMain() {
for (InputSectionBase *sec : inputSections) {
if (!sec->isLive() || !isValidCIdentifier(sec->name))
continue;
if (symtab->find(("__start_" + sec->name).str()) ||
symtab->find(("__stop_" + sec->name).str()))
if (symtab.find(("__start_" + sec->name).str()) ||
symtab.find(("__stop_" + sec->name).str()))
enqueue(sec, 0);
}
@ -354,7 +354,7 @@ template <class ELFT> void elf::markLive() {
// If --gc-sections is not given, retain all input sections.
if (!config->gcSections) {
// If a DSO defines a symbol referenced in a regular object, it is needed.
for (Symbol *sym : symtab->getSymbols())
for (Symbol *sym : symtab.getSymbols())
if (auto *s = dyn_cast<SharedSymbol>(sym))
if (s->isUsedInRegularObj && !s->isWeak())
cast<SharedFile>(s->file)->isNeeded = true;

View File

@ -275,7 +275,7 @@ static SmallSet<SharedSymbol *, 4> getSymbolsAt(SharedSymbol &ss) {
s.getType() == STT_TLS || s.st_value != ss.value)
continue;
StringRef name = check(s.getName(file.getStringTable()));
Symbol *sym = symtab->find(name);
Symbol *sym = symtab.find(name);
if (auto *alias = dyn_cast_or_null<SharedSymbol>(sym))
ret.insert(alias);
}
@ -550,7 +550,7 @@ static std::string maybeReportDiscarded(Undefined &sym) {
// If the discarded section is a COMDAT.
StringRef signature = file->getShtGroupSignature(objSections, elfSec);
if (const InputFile *prevailing =
symtab->comdatGroups.lookup(CachedHashStringRef(signature))) {
symtab.comdatGroups.lookup(CachedHashStringRef(signature))) {
msg += "\n>>> section group signature: " + signature.str() +
"\n>>> prevailing definition is in " + toString(prevailing);
if (sym.nonPrevailing) {
@ -623,7 +623,7 @@ static const Symbol *getAlternativeSpelling(const Undefined &sym,
return s;
// If in the symbol table and not undefined.
if (const Symbol *s = symtab->find(newName))
if (const Symbol *s = symtab.find(newName))
if (!s->isUndefined())
return s;
@ -672,7 +672,7 @@ static const Symbol *getAlternativeSpelling(const Undefined &sym,
for (auto &it : map)
if (name.equals_insensitive(it.first))
return it.second;
for (Symbol *sym : symtab->getSymbols())
for (Symbol *sym : symtab.getSymbols())
if (!sym->isUndefined() && name.equals_insensitive(sym->getName()))
return sym;
@ -698,7 +698,7 @@ static const Symbol *getAlternativeSpelling(const Undefined &sym,
break;
}
if (!s)
for (Symbol *sym : symtab->getSymbols())
for (Symbol *sym : symtab.getSymbols())
if (canSuggestExternCForCXX(name, sym->getName())) {
s = sym;
break;
@ -1748,7 +1748,7 @@ void elf::postScanRelocations() {
}
assert(symAux.size() == 1);
for (Symbol *sym : symtab->getSymbols())
for (Symbol *sym : symtab.getSymbols())
fn(*sym);
// Local symbols may need the aforementioned non-preemptible ifunc and GOT
@ -2263,7 +2263,7 @@ bool elf::hexagonNeedsTLSSymbol(ArrayRef<OutputSection *> outputSections) {
}
void elf::hexagonTLSSymbolUpdate(ArrayRef<OutputSection *> outputSections) {
Symbol *sym = symtab->find("__tls_get_addr");
Symbol *sym = symtab.find("__tls_get_addr");
if (!sym)
return;
bool needEntry = true;

View File

@ -1449,7 +1449,7 @@ Expr ScriptParser::readPrimary() {
if (tok == "DEFINED") {
StringRef name = unquote(readParenLiteral());
return [=] {
Symbol *b = symtab->find(name);
Symbol *b = symtab.find(name);
return (b && b->isDefined()) ? 1 : 0;
};
}

View File

@ -28,7 +28,7 @@ using namespace llvm::ELF;
using namespace lld;
using namespace lld::elf;
std::unique_ptr<SymbolTable> elf::symtab;
SymbolTable elf::symtab;
void SymbolTable::wrap(Symbol *sym, Symbol *real, Symbol *wrap) {
// Redirect __real_foo to the original foo and foo to the original __wrap_foo.

View File

@ -12,6 +12,7 @@
#include "Symbols.h"
#include "llvm/ADT/CachedHashString.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/Compiler.h"
namespace lld::elf {
@ -87,7 +88,7 @@ private:
llvm::Optional<llvm::StringMap<SmallVector<Symbol *, 0>>> demangledSyms;
};
extern std::unique_ptr<SymbolTable> symtab;
LLVM_LIBRARY_VISIBILITY extern SymbolTable symtab;
} // namespace lld::elf

View File

@ -1458,10 +1458,10 @@ DynamicSection<ELFT>::computeContents() {
addInt(DT_FINI_ARRAYSZ, Out::finiArray->size);
}
if (Symbol *b = symtab->find(config->init))
if (Symbol *b = symtab.find(config->init))
if (b->isDefined())
addInt(DT_INIT, b->getVA());
if (Symbol *b = symtab->find(config->fini))
if (Symbol *b = symtab.find(config->fini))
if (b->isDefined())
addInt(DT_FINI, b->getVA());
}

View File

@ -144,7 +144,7 @@ void elf::copySectionsIntoPartitions() {
static Defined *addOptionalRegular(StringRef name, SectionBase *sec,
uint64_t val, uint8_t stOther = STV_HIDDEN) {
Symbol *s = symtab->find(name);
Symbol *s = symtab.find(name);
if (!s || s->isDefined() || s->isCommon())
return nullptr;
@ -155,7 +155,7 @@ static Defined *addOptionalRegular(StringRef name, SectionBase *sec,
}
static Defined *addAbsolute(StringRef name) {
Symbol *sym = symtab->addSymbol(Defined{nullptr, name, STB_GLOBAL, STV_HIDDEN,
Symbol *sym = symtab.addSymbol(Defined{nullptr, name, STB_GLOBAL, STV_HIDDEN,
STT_NOTYPE, 0, 0, nullptr});
sym->isUsedInRegularObj = true;
return cast<Defined>(sym);
@ -174,14 +174,14 @@ void elf::addReservedSymbols() {
// On MIPS O32 ABI, _gp_disp is a magic symbol designates offset between
// start of function and 'gp' pointer into GOT.
if (symtab->find("_gp_disp"))
if (symtab.find("_gp_disp"))
ElfSym::mipsGpDisp = addAbsolute("_gp_disp");
// The __gnu_local_gp is a magic symbol equal to the current value of 'gp'
// pointer. This symbol is used in the code generated by .cpload pseudo-op
// in case of using -mno-shared option.
// https://sourceware.org/ml/binutils/2004-12/msg00094.html
if (symtab->find("__gnu_local_gp"))
if (symtab.find("__gnu_local_gp"))
ElfSym::mipsLocalGp = addAbsolute("__gnu_local_gp");
} else if (config->emachine == EM_PPC) {
// glibc *crt1.o has a undefined reference to _SDA_BASE_. Since we don't
@ -202,7 +202,7 @@ void elf::addReservedSymbols() {
StringRef gotSymName =
(config->emachine == EM_PPC64) ? ".TOC." : "_GLOBAL_OFFSET_TABLE_";
if (Symbol *s = symtab->find(gotSymName)) {
if (Symbol *s = symtab.find(gotSymName)) {
if (s->isDefined()) {
error(toString(s->file) + " cannot redefine linker defined symbol '" +
gotSymName + "'");
@ -1278,7 +1278,7 @@ static DenseMap<const InputSectionBase *, int> buildSectionOrder() {
// We want both global and local symbols. We get the global ones from the
// symbol table and iterate the object files for the local ones.
for (Symbol *sym : symtab->getSymbols())
for (Symbol *sym : symtab.getSymbols())
addSym(*sym);
for (ELFFileBase *file : ctx.objectFiles)
@ -1846,8 +1846,8 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
// Even the author of gold doesn't remember why gold behaves that way.
// https://sourceware.org/ml/binutils/2002-03/msg00360.html
if (mainPart->dynamic->parent)
symtab->addSymbol(Defined{/*file=*/nullptr, "_DYNAMIC", STB_WEAK, STV_HIDDEN, STT_NOTYPE,
/*value=*/0, /*size=*/0, mainPart->dynamic.get()})->isUsedInRegularObj = true;
symtab.addSymbol(Defined{/*file=*/nullptr, "_DYNAMIC", STB_WEAK, STV_HIDDEN,
STT_NOTYPE, /*value=*/0, /*size=*/0, mainPart->dynamic.get()})->isUsedInRegularObj = true;
// Define __rel[a]_iplt_{start,end} symbols if needed.
addRelIpltSymbols();
@ -1875,7 +1875,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
// 2) is special cased in @tpoff computation. To satisfy 1), we define it as
// an absolute symbol of zero. This is different from GNU linkers which
// define _TLS_MODULE_BASE_ relative to the first TLS section.
Symbol *s = symtab->find("_TLS_MODULE_BASE_");
Symbol *s = symtab.find("_TLS_MODULE_BASE_");
if (s && s->isUndefined()) {
s->resolve(Defined{/*file=*/nullptr, StringRef(), STB_GLOBAL, STV_HIDDEN,
STT_TLS, /*value=*/0, 0,
@ -1894,7 +1894,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
}
if (config->hasDynSymTab) {
parallelForEach(symtab->getSymbols(), [](Symbol *sym) {
parallelForEach(symtab.getSymbols(), [](Symbol *sym) {
sym->isPreemptible = computeIsPreemptible(*sym);
});
}
@ -1937,7 +1937,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
for (SharedFile *file : ctx.sharedFiles) {
bool allNeededIsKnown =
llvm::all_of(file->dtNeeded, [&](StringRef needed) {
return symtab->soNames.count(CachedHashStringRef(needed));
return symtab.soNames.count(CachedHashStringRef(needed));
});
if (!allNeededIsKnown)
continue;
@ -1952,7 +1952,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
llvm::TimeTraceScope timeScope("Add symbols to symtabs");
// Now that we have defined all possible global symbols including linker-
// synthesized ones. Visit all symbols to give the finishing touches.
for (Symbol *sym : symtab->getSymbols()) {
for (Symbol *sym : symtab.getSymbols()) {
if (!sym->isUsedInRegularObj || !includeInSymtab(*sym))
continue;
if (!config->relocatable)
@ -2009,7 +2009,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
// With the outputSections available check for GDPLT relocations
// and add __tls_get_addr symbol if needed.
if (config->emachine == EM_HEXAGON && hexagonNeedsTLSSymbol(outputSections)) {
Symbol *sym = symtab->addSymbol(Undefined{
Symbol *sym = symtab.addSymbol(Undefined{
nullptr, "__tls_get_addr", STB_GLOBAL, STV_DEFAULT, STT_NOTYPE});
sym->isPreemptible = true;
partitions[0].dynSymTab->addSymbol(sym);
@ -2739,7 +2739,7 @@ template <class ELFT> void Writer<ELFT>::checkSections() {
// 5. the address 0.
static uint64_t getEntryAddr() {
// Case 1, 2 or 3
if (Symbol *b = symtab->find(config->entry))
if (Symbol *b = symtab.find(config->entry))
return b->getVA();
// Case 4