diff options
-rw-r--r-- | lld/ELF/LinkerScript.cpp | 2 | ||||
-rw-r--r-- | lld/ELF/OutputSections.cpp | 2 | ||||
-rw-r--r-- | lld/ELF/Writer.cpp | 38 | ||||
-rw-r--r-- | lld/ELF/Writer.h | 1 |
4 files changed, 19 insertions, 24 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 0d60e6511f7..57172ffdcfe 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -318,7 +318,7 @@ std::vector<PhdrEntry<ELFT>> LinkerScript<ELFT>::createPhdrs() { Phdr.add(Out<ELFT>::Interp); break; case PT_DYNAMIC: - if (isOutputDynamic<ELFT>()) { + if (Out<ELFT>::DynSymTab) { Phdr.H.p_flags = Out<ELFT>::Dynamic->getPhdrFlags(); Phdr.add(Out<ELFT>::Dynamic); } diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 10d08c6c50d..6a562113cad 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -395,7 +395,7 @@ template <class ELFT> unsigned RelocationSection<ELFT>::getRelocOffset() { } template <class ELFT> void RelocationSection<ELFT>::finalize() { - this->Header.sh_link = isOutputDynamic<ELFT>() + this->Header.sh_link = Out<ELFT>::DynSymTab ? Out<ELFT>::DynSymTab->SectionIndex : Out<ELFT>::SymTab->SectionIndex; this->Header.sh_size = Relocs.size() * this->Header.sh_entsize; diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index f078b8a89bb..2f421275d29 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -120,9 +120,7 @@ template <class ELFT> void elf::writeResult() { PltSection<ELFT> Plt; RelocationSection<ELFT> RelaDyn(Config->Rela ? ".rela.dyn" : ".rel.dyn", Config->ZCombreloc); - StringTableSection<ELFT> DynStrTab(".dynstr", true); StringTableSection<ELFT> ShStrTab(".shstrtab", false); - SymbolTableSection<ELFT> DynSymTab(DynStrTab); VersionTableSection<ELFT> VerSym; VersionNeedSection<ELFT> VerNeed; @@ -134,6 +132,8 @@ template <class ELFT> void elf::writeResult() { // Instantiate optional output sections if they are needed. std::unique_ptr<InterpSection<ELFT>> Interp; std::unique_ptr<BuildIdSection<ELFT>> BuildId; + std::unique_ptr<StringTableSection<ELFT>> DynStrTab; + std::unique_ptr<SymbolTableSection<ELFT>> DynSymTab; std::unique_ptr<EhFrameHeader<ELFT>> EhFrameHdr; std::unique_ptr<GnuHashTableSection<ELFT>> GnuHashTab; std::unique_ptr<GotPltSection<ELFT>> GotPlt; @@ -156,6 +156,11 @@ template <class ELFT> void elf::writeResult() { else if (Config->BuildId == BuildIdKind::Hexstring) BuildId.reset(new BuildIdHexstring<ELFT>); + if (!Symtab<ELFT>::X->getSharedFiles().empty() || Config->Pic) { + DynStrTab.reset(new StringTableSection<ELFT>(".dynstr", true)); + DynSymTab.reset(new SymbolTableSection<ELFT>(*DynStrTab)); + } + if (Config->EhFrameHdr) EhFrameHdr.reset(new EhFrameHeader<ELFT>); @@ -185,8 +190,8 @@ template <class ELFT> void elf::writeResult() { Out<ELFT>::Bss = &Bss; Out<ELFT>::BuildId = BuildId.get(); - Out<ELFT>::DynStrTab = &DynStrTab; - Out<ELFT>::DynSymTab = &DynSymTab; + Out<ELFT>::DynStrTab = DynStrTab.get(); + Out<ELFT>::DynSymTab = DynSymTab.get(); Out<ELFT>::Dynamic = &Dynamic; Out<ELFT>::EhFrame = &EhFrame; Out<ELFT>::EhFrameHdr = EhFrameHdr.get(); @@ -481,10 +486,6 @@ static bool compareSections(OutputSectionBase<ELFT> *A, return false; } -template <class ELFT> bool elf::isOutputDynamic() { - return !Symtab<ELFT>::X->getSharedFiles().empty() || Config->Pic; -} - template <class ELFT> static bool isDiscarded(InputSectionBase<ELFT> *S) { return !S || S == &InputSection<ELFT>::Discarded || !S->Live; } @@ -523,7 +524,7 @@ static Symbol *addOptionalSynthetic(StringRef Name, // need these symbols, since IRELATIVE relocs are resolved through GOT // and PLT. For details, see http://www.airs.com/blog/archives/403. template <class ELFT> void Writer<ELFT>::addRelIpltSymbols() { - if (isOutputDynamic<ELFT>() || !Out<ELFT>::RelaPlt) + if (Out<ELFT>::DynSymTab || !Out<ELFT>::RelaPlt) return; StringRef S = Config->Rela ? "__rela_iplt_start" : "__rel_iplt_start"; addOptionalSynthetic(S, Out<ELFT>::RelaPlt, 0); @@ -576,7 +577,7 @@ template <class ELFT> void Writer<ELFT>::addReservedSymbols() { // 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<ELFT>()) + if (!Out<ELFT>::DynSymTab) Symtab<ELFT>::X->addIgnored("__tls_get_addr"); // If linker script do layout we do not need to create any standart symbols. @@ -685,7 +686,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() { // It should be okay as no one seems to care about the type. // Even the author of gold doesn't remember why gold behaves that way. // https://sourceware.org/ml/binutils/2002-03/msg00360.html - if (isOutputDynamic<ELFT>()) + if (Out<ELFT>::DynSymTab) Symtab<ELFT>::X->addSynthetic("_DYNAMIC", Out<ELFT>::Dynamic, 0); // Define __rel[a]_iplt_{start,end} symbols if needed. @@ -725,7 +726,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() { if (Out<ELFT>::SymTab) Out<ELFT>::SymTab->addSymbol(Body); - if (isOutputDynamic<ELFT>() && S->includeInDynsym()) { + if (Out<ELFT>::DynSymTab && S->includeInDynsym()) { Out<ELFT>::DynSymTab->addSymbol(Body); if (auto *SS = dyn_cast<SharedSymbol<ELFT>>(Body)) if (SS->file()->isNeeded()) @@ -759,7 +760,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() { // Finalizers fix each section's size. // .dynsym is finalized early since that may fill up .gnu.hash. - if (isOutputDynamic<ELFT>()) + if (Out<ELFT>::DynSymTab) Out<ELFT>::DynSymTab->finalize(); // Fill other section headers. The dynamic table is finalized @@ -771,7 +772,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() { if (Sec != Out<ELFT>::DynStrTab && Sec != Out<ELFT>::Dynamic) Sec->finalize(); - if (isOutputDynamic<ELFT>()) + if (Out<ELFT>::DynSymTab) Out<ELFT>::Dynamic->finalize(); // Now that all output offsets are fixed. Finalize mergeable sections @@ -817,7 +818,7 @@ template <class ELFT> void Writer<ELFT>::addPredefinedSections() { Add(Out<ELFT>::SymTab); Add(Out<ELFT>::ShStrTab); Add(Out<ELFT>::StrTab); - if (isOutputDynamic<ELFT>()) { + if (Out<ELFT>::DynSymTab) { Add(Out<ELFT>::DynSymTab); bool HasVerNeed = Out<ELFT>::VerNeed->getNeedNum() != 0; @@ -979,7 +980,7 @@ std::vector<PhdrEntry<ELFT>> Writer<ELFT>::createPhdrs() { Ret.push_back(std::move(TlsHdr)); // Add an entry for .dynamic. - if (isOutputDynamic<ELFT>()) { + if (Out<ELFT>::DynSymTab) { Phdr &H = *AddHdr(PT_DYNAMIC, Out<ELFT>::Dynamic->getPhdrFlags()); H.add(Out<ELFT>::Dynamic); } @@ -1286,11 +1287,6 @@ template struct elf::PhdrEntry<ELF32BE>; template struct elf::PhdrEntry<ELF64LE>; template struct elf::PhdrEntry<ELF64BE>; -template bool elf::isOutputDynamic<ELF32LE>(); -template bool elf::isOutputDynamic<ELF32BE>(); -template bool elf::isOutputDynamic<ELF64LE>(); -template bool elf::isOutputDynamic<ELF64BE>(); - template bool elf::isRelroSection<ELF32LE>(OutputSectionBase<ELF32LE> *); template bool elf::isRelroSection<ELF32BE>(OutputSectionBase<ELF32BE> *); template bool elf::isRelroSection<ELF64LE>(OutputSectionBase<ELF64LE> *); diff --git a/lld/ELF/Writer.h b/lld/ELF/Writer.h index 30472821f03..914db53e8e4 100644 --- a/lld/ELF/Writer.h +++ b/lld/ELF/Writer.h @@ -25,7 +25,6 @@ template <class ELFT> class ObjectFile; template <class ELFT> class SymbolTable; template <class ELFT> void writeResult(); template <class ELFT> void markLive(); -template <class ELFT> bool isOutputDynamic(); template <class ELFT> bool isRelroSection(OutputSectionBase<ELFT> *Sec); // This describes a program header entry. |