diff options
-rw-r--r-- | lld/ELF/LinkerScript.cpp | 46 | ||||
-rw-r--r-- | lld/ELF/LinkerScript.h | 2 |
2 files changed, 22 insertions, 26 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index fec2e197ee7..ecc68388ee3 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -90,30 +90,33 @@ template <class ELFT> bool LinkerScript::shouldKeep(InputSectionBase<ELFT> *S) { return R && R->Keep; } -// This method finalizes the Locations list. Adds neccesary locations for -// orphan sections, what prepares it for futher use without -// changes in LinkerScript::assignAddresses(). template <class ELFT> -void LinkerScript::fixupLocations(std::vector<OutputSectionBase<ELFT> *> &S) { +static OutputSectionBase<ELFT> * +findSection(std::vector<OutputSectionBase<ELFT> *> &V, StringRef Name) { + for (OutputSectionBase<ELFT> *Sec : V) + if (Sec->getName() == Name) + return Sec; + return nullptr; +} + +template <class ELFT> +void LinkerScript::assignAddresses( + std::vector<OutputSectionBase<ELFT> *> &Sections) { + typedef typename ELFT::uint uintX_t; + // Orphan sections are sections present in the input files which - // are not explicitly placed into the output file by the linker - // script. We place orphan sections at end of file. Other linkers places - // them using some heuristics as described in + // are not explicitly placed into the output file by the linker script. + // We place orphan sections at end of file. + // Other linkers places them using some heuristics as described in // https://sourceware.org/binutils/docs/ld/Orphan-Sections.html#Orphan-Sections. - for (OutputSectionBase<ELFT> *Sec : S) { + for (OutputSectionBase<ELFT> *Sec : Sections) { StringRef Name = Sec->getName(); auto I = std::find(SectionOrder.begin(), SectionOrder.end(), Name); if (I == SectionOrder.end()) Locations.push_back({Command::Section, {}, {Name}}); } -} - -template <class ELFT> -void LinkerScript::assignAddresses(std::vector<OutputSectionBase<ELFT> *> &S) { - typedef typename ELFT::uint uintX_t; - - Script->fixupLocations(S); + // Assign addresses as instructed by linker script SECTIONS sub-commands. uintX_t ThreadBssOffset = 0; uintX_t VA = Out<ELFT>::ElfHeader->getSize() + Out<ELFT>::ProgramHeaders->getSize(); @@ -124,25 +127,20 @@ void LinkerScript::assignAddresses(std::vector<OutputSectionBase<ELFT> *> &S) { continue; } - auto I = - std::find_if(S.begin(), S.end(), [&](OutputSectionBase<ELFT> *Sec) { - return Sec->getName() == Node.SectionName; - }); - if (I == S.end()) + OutputSectionBase<ELFT> *Sec = findSection(Sections, Node.SectionName); + if (!Sec) continue; - OutputSectionBase<ELFT> *Sec = *I; - uintX_t Align = Sec->getAlign(); if ((Sec->getFlags() & SHF_TLS) && Sec->getType() == SHT_NOBITS) { uintX_t TVA = VA + ThreadBssOffset; - TVA = alignTo(TVA, Align); + TVA = alignTo(TVA, Sec->getAlign()); Sec->setVA(TVA); ThreadBssOffset = TVA - VA + Sec->getSize(); continue; } if (Sec->getFlags() & SHF_ALLOC) { - VA = alignTo(VA, Align); + VA = alignTo(VA, Sec->getAlign()); Sec->setVA(VA); VA += Sec->getSize(); continue; diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h index c67ab1fc317..309599b7df9 100644 --- a/lld/ELF/LinkerScript.h +++ b/lld/ELF/LinkerScript.h @@ -72,8 +72,6 @@ public: bool DoLayout = false; private: - template <class ELFT> - void fixupLocations(std::vector<OutputSectionBase<ELFT> *> &); uint64_t evaluate(std::vector<StringRef> &Tokens, uint64_t LocCounter); template <class ELFT> SectionRule *find(InputSectionBase<ELFT> *S); |