diff options
-rw-r--r-- | lld/ELF/SyntheticSections.cpp | 50 | ||||
-rw-r--r-- | lld/ELF/SyntheticSections.h | 2 |
2 files changed, 22 insertions, 30 deletions
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 170583d7488..b408e653dfa 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -981,7 +981,24 @@ DynamicSection<ELFT>::DynamicSection() if (Config->EMachine == EM_MIPS || Config->ZRodynamic) this->Flags = SHF_ALLOC; - addEntries(); + // Add strings to .dynstr early so that .dynstr's size will be + // fixed early. + for (StringRef S : Config->FilterList) + addInt(DT_FILTER, InX::DynStrTab->addString(S)); + for (StringRef S : Config->AuxiliaryList) + addInt(DT_AUXILIARY, InX::DynStrTab->addString(S)); + + if (!Config->Rpath.empty()) + addInt(Config->EnableNewDtags ? DT_RUNPATH : DT_RPATH, + InX::DynStrTab->addString(Config->Rpath)); + + for (InputFile *File : SharedFiles) { + SharedFile<ELFT> *F = cast<SharedFile<ELFT>>(File); + if (F->IsNeeded) + addInt(DT_NEEDED, InX::DynStrTab->addString(F->SoName)); + } + if (!Config->SoName.empty()) + addInt(DT_SONAME, InX::DynStrTab->addString(Config->SoName)); } template <class ELFT> @@ -1015,27 +1032,10 @@ void DynamicSection<ELFT>::addSym(int32_t Tag, Symbol *Sym) { Entries.push_back({Tag, [=] { return Sym->getVA(); }}); } -// There are some dynamic entries that don't depend on other sections. -// Such entries can be set early. -template <class ELFT> void DynamicSection<ELFT>::addEntries() { - // Add strings to .dynstr early so that .dynstr's size will be - // fixed early. - for (StringRef S : Config->FilterList) - addInt(DT_FILTER, InX::DynStrTab->addString(S)); - for (StringRef S : Config->AuxiliaryList) - addInt(DT_AUXILIARY, InX::DynStrTab->addString(S)); - - if (!Config->Rpath.empty()) - addInt(Config->EnableNewDtags ? DT_RUNPATH : DT_RPATH, - InX::DynStrTab->addString(Config->Rpath)); - - for (InputFile *File : SharedFiles) { - SharedFile<ELFT> *F = cast<SharedFile<ELFT>>(File); - if (F->IsNeeded) - addInt(DT_NEEDED, InX::DynStrTab->addString(F->SoName)); - } - if (!Config->SoName.empty()) - addInt(DT_SONAME, InX::DynStrTab->addString(Config->SoName)); +// Add remaining entries to complete .dynamic contents. +template <class ELFT> void DynamicSection<ELFT>::finalizeContents() { + if (this->Size) + return; // Already finalized. // Set DT_FLAGS and DT_FLAGS_1. uint32_t DtFlags = 0; @@ -1070,12 +1070,6 @@ template <class ELFT> void DynamicSection<ELFT>::addEntries() { // If the target is such a system (used -z rodynamic) don't write DT_DEBUG. if (!Config->Shared && !Config->Relocatable && !Config->ZRodynamic) addInt(DT_DEBUG, 0); -} - -// Add remaining entries to complete .dynamic contents. -template <class ELFT> void DynamicSection<ELFT>::finalizeContents() { - if (this->Size) - return; // Already finalized. this->Link = InX::DynStrTab->getParent()->SectionIndex; if (InX::RelaDyn->getParent() && !InX::RelaDyn->empty()) { diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index 99e2b0e62a3..5aaf479f3e3 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -347,8 +347,6 @@ public: size_t getSize() const override { return Size; } private: - void addEntries(); - void add(int32_t Tag, std::function<uint64_t()> Fn); void addInt(int32_t Tag, uint64_t Val); void addInSec(int32_t Tag, InputSection *Sec); |