From 84907c514379acc152a33fb41f2d93c7c39b4c46 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Tue, 9 Aug 2016 03:38:23 +0000 Subject: [PATCH] Do not pass the SymbolTable to writeResult. The SymbolTable is always accessible as Symtab::X, so no need to pass it as an argument. llvm-svn: 278091 --- lld/ELF/Driver.cpp | 2 +- lld/ELF/Writer.cpp | 76 ++++++++++++++++++++++------------------------ lld/ELF/Writer.h | 2 +- 3 files changed, 38 insertions(+), 42 deletions(-) diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 70d16801f621..07782c2f9563 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -588,5 +588,5 @@ template void LinkerDriver::link(opt::InputArgList &Args) { MS->splitIntoPieces(); } - writeResult(&Symtab); + writeResult(); } diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index efb29e4ae49c..e780e2e4c66d 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -40,7 +40,6 @@ public: typedef typename ELFT::Sym Elf_Sym; typedef typename ELFT::SymRange Elf_Sym_Range; typedef typename ELFT::Rela Elf_Rela; - Writer(SymbolTable &S) : Symtab(S) {} void run(); private: @@ -79,7 +78,6 @@ private: void addStartStopSymbols(OutputSectionBase *Sec); OutputSectionBase *findSection(StringRef Name); - SymbolTable &Symtab; std::vector Phdrs; uintX_t FileSize; @@ -110,7 +108,7 @@ template static bool needsInterpSection() { !Config->DynamicLinker.empty(); } -template void elf::writeResult(SymbolTable *Symtab) { +template void elf::writeResult() { typedef typename ELFT::uint uintX_t; typedef typename ELFT::Ehdr Elf_Ehdr; @@ -213,7 +211,7 @@ template void elf::writeResult(SymbolTable *Symtab) { Out::ElfHeader = &ElfHeader; Out::ProgramHeaders = &ProgramHeaders; - Writer(*Symtab).run(); + Writer().run(); } template @@ -273,8 +271,7 @@ template void Writer::run() { error(EC, "failed to write to the output file"); } -template -static void reportUndefined(SymbolTable &Symtab, SymbolBody *Sym) { +template static void reportUndefined(SymbolBody *Sym) { if (Config->UnresolvedSymbols == UnresolvedPolicy::Ignore) return; @@ -346,7 +343,7 @@ template void Writer::copyLocalSymbols() { if (!Out::SymTab) return; for (const std::unique_ptr> &F : - Symtab.getObjectFiles()) { + Symtab::X->getObjectFiles()) { const char *StrTab = F->getStringTable().data(); for (SymbolBody *B : F->getLocalSymbols()) { auto *DR = dyn_cast>(B); @@ -504,15 +501,15 @@ void PhdrEntry::add(OutputSectionBase *Sec) { } template -static Symbol *addOptionalSynthetic(SymbolTable &Table, StringRef Name, +static Symbol *addOptionalSynthetic(StringRef Name, OutputSectionBase *Sec, typename ELFT::uint Val) { - SymbolBody *S = Table.find(Name); + SymbolBody *S = Symtab::X->find(Name); if (!S) return nullptr; if (!S->isUndefined() && !S->isShared()) return S->symbol(); - return Table.addSynthetic(Name, Sec, Val); + return Symtab::X->addSynthetic(Name, Sec, Val); } // The beginning and the ending of .rel[a].plt section are marked @@ -525,10 +522,10 @@ template void Writer::addRelIpltSymbols() { if (isOutputDynamic() || !Out::RelaPlt) return; StringRef S = Config->Rela ? "__rela_iplt_start" : "__rel_iplt_start"; - addOptionalSynthetic(Symtab, S, Out::RelaPlt, 0); + addOptionalSynthetic(S, Out::RelaPlt, 0); S = Config->Rela ? "__rela_iplt_end" : "__rel_iplt_end"; - addOptionalSynthetic(Symtab, S, Out::RelaPlt, + addOptionalSynthetic(S, Out::RelaPlt, DefinedSynthetic::SectionEnd); } @@ -540,12 +537,12 @@ template void Writer::addReservedSymbols() { // so that it points to an absolute address which is relative to GOT. // See "Global Data Symbols" in Chapter 6 in the following document: // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf - Symtab.addSynthetic("_gp", Out::Got, MipsGPOffset); + Symtab::X->addSynthetic("_gp", Out::Got, MipsGPOffset); // On MIPS O32 ABI, _gp_disp is a magic symbol designates offset between // start of function and 'gp' pointer into GOT. Symbol *Sym = - addOptionalSynthetic(Symtab, "_gp_disp", Out::Got, MipsGPOffset); + addOptionalSynthetic("_gp_disp", Out::Got, MipsGPOffset); if (Sym) ElfSym::MipsGpDisp = Sym->body(); @@ -553,8 +550,7 @@ template void Writer::addReservedSymbols() { // 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 - addOptionalSynthetic(Symtab, "__gnu_local_gp", Out::Got, - MipsGPOffset); + addOptionalSynthetic("__gnu_local_gp", Out::Got, MipsGPOffset); } // In the assembly for 32 bit x86 the _GLOBAL_OFFSET_TABLE_ symbol @@ -570,14 +566,14 @@ template void Writer::addReservedSymbols() { // Given that the symbol is effectively unused, we just create a dummy // hidden one to avoid the undefined symbol error. if (!Config->Relocatable) - Symtab.addIgnored("_GLOBAL_OFFSET_TABLE_"); + Symtab::X->addIgnored("_GLOBAL_OFFSET_TABLE_"); // __tls_get_addr is defined by the dynamic linker for dynamic ELFs. For // static linking the linker is required to optimize away any references to // __tls_get_addr, so it's not defined anywhere. Create a hidden definition // to avoid the undefined symbol error. if (!isOutputDynamic()) - Symtab.addIgnored("__tls_get_addr"); + Symtab::X->addIgnored("__tls_get_addr"); // If linker script do layout we do not need to create any standart symbols. if (ScriptConfig->HasContents) @@ -585,15 +581,15 @@ template void Writer::addReservedSymbols() { auto Define = [this](StringRef S, DefinedRegular *&Sym1, DefinedRegular *&Sym2) { - Sym1 = Symtab.addIgnored(S, STV_DEFAULT); + Sym1 = Symtab::X->addIgnored(S, STV_DEFAULT); // The name without the underscore is not a reserved name, // so it is defined only when there is a reference against it. assert(S.startswith("_")); S = S.substr(1); - if (SymbolBody *B = Symtab.find(S)) + if (SymbolBody *B = Symtab::X->find(S)) if (B->isUndefined()) - Sym2 = Symtab.addAbsolute(S, STV_DEFAULT); + Sym2 = Symtab::X->addAbsolute(S, STV_DEFAULT); }; Define("_end", ElfSym::End, ElfSym::End2); @@ -619,7 +615,7 @@ void Writer::forEachRelSec( std::function &, const typename ELFT::Shdr &)> Fn) { for (const std::unique_ptr> &F : - Symtab.getObjectFiles()) { + Symtab::X->getObjectFiles()) { for (InputSectionBase *C : F->getSections()) { if (isDiscarded(C)) continue; @@ -644,7 +640,7 @@ void Writer::forEachRelSec( template void Writer::createSections() { for (const std::unique_ptr> &F : - Symtab.getObjectFiles()) { + Symtab::X->getObjectFiles()) { for (InputSectionBase *C : F->getSections()) { if (isDiscarded(C)) { reportDiscarded(C); @@ -686,7 +682,7 @@ template void Writer::finalizeSections() { // Even the author of gold doesn't remember why gold behaves that way. // https://sourceware.org/ml/binutils/2002-03/msg00360.html if (isOutputDynamic()) - Symtab.addSynthetic("_DYNAMIC", Out::Dynamic, 0); + Symtab::X->addSynthetic("_DYNAMIC", Out::Dynamic, 0); // Define __rel[a]_iplt_{start,end} symbols if needed. addRelIpltSymbols(); @@ -712,13 +708,13 @@ template void Writer::finalizeSections() { // Now that we have defined all possible symbols including linker- // synthesized ones. Visit all symbols to give the finishing touches. - for (Symbol *S : Symtab.getSymbols()) { + for (Symbol *S : Symtab::X->getSymbols()) { SymbolBody *Body = S->body(); // We only report undefined symbols in regular objects. This means that we // will accept an undefined reference in bitcode if it can be optimized out. if (S->IsUsedInRegularObj && Body->isUndefined() && !S->isWeak()) - reportUndefined(Symtab, Body); + reportUndefined(Body); if (!includeInSymtab(*Body)) continue; @@ -861,13 +857,12 @@ template void Writer::addStartEndSymbols() { auto Define = [&](StringRef Start, StringRef End, OutputSectionBase *OS) { if (OS) { - this->Symtab.addSynthetic(Start, OS, 0); - this->Symtab.addSynthetic(End, OS, DefinedSynthetic::SectionEnd); + Symtab::X->addSynthetic(Start, OS, 0); + Symtab::X->addSynthetic(End, OS, + DefinedSynthetic::SectionEnd); } else { - addOptionalSynthetic(this->Symtab, Start, - (OutputSectionBase *)nullptr, 0); - addOptionalSynthetic(this->Symtab, End, - (OutputSectionBase *)nullptr, 0); + addOptionalSynthetic(Start, (OutputSectionBase *)nullptr, 0); + addOptionalSynthetic(End, (OutputSectionBase *)nullptr, 0); } }; @@ -892,12 +887,13 @@ void Writer::addStartStopSymbols(OutputSectionBase *Sec) { StringSaver Saver(Alloc); StringRef Start = Saver.save("__start_" + S); StringRef Stop = Saver.save("__stop_" + S); - if (SymbolBody *B = Symtab.find(Start)) + if (SymbolBody *B = Symtab::X->find(Start)) if (B->isUndefined()) - Symtab.addSynthetic(Start, Sec, 0); - if (SymbolBody *B = Symtab.find(Stop)) + Symtab::X->addSynthetic(Start, Sec, 0); + if (SymbolBody *B = Symtab::X->find(Stop)) if (B->isUndefined()) - Symtab.addSynthetic(Stop, Sec, DefinedSynthetic::SectionEnd); + Symtab::X->addSynthetic(Stop, Sec, + DefinedSynthetic::SectionEnd); } template @@ -1280,10 +1276,10 @@ template void Writer::writeBuildId() { Out::BuildId->writeBuildId(Regions); } -template void elf::writeResult(SymbolTable *Symtab); -template void elf::writeResult(SymbolTable *Symtab); -template void elf::writeResult(SymbolTable *Symtab); -template void elf::writeResult(SymbolTable *Symtab); +template void elf::writeResult(); +template void elf::writeResult(); +template void elf::writeResult(); +template void elf::writeResult(); template struct elf::PhdrEntry; template struct elf::PhdrEntry; diff --git a/lld/ELF/Writer.h b/lld/ELF/Writer.h index 9caf7a7a10e6..30472821f030 100644 --- a/lld/ELF/Writer.h +++ b/lld/ELF/Writer.h @@ -23,7 +23,7 @@ template class OutputSectionBase; template class InputSectionBase; template class ObjectFile; template class SymbolTable; -template void writeResult(SymbolTable *Symtab); +template void writeResult(); template void markLive(); template bool isOutputDynamic(); template bool isRelroSection(OutputSectionBase *Sec);