Index: lld/trunk/ELF/SyntheticSections.h =================================================================== --- lld/trunk/ELF/SyntheticSections.h +++ lld/trunk/ELF/SyntheticSections.h @@ -50,8 +50,6 @@ // If the section has the SHF_ALLOC flag and the size may be changed if // thunks are added, update the section size. virtual bool updateAllocSize() { return false; } - // If any additional finalization of contents are needed post thunk creation. - virtual void postThunkContents() {} virtual bool empty() const { return false; } static bool classof(const SectionBase *D) { @@ -561,7 +559,6 @@ public: SymbolTableBaseSection(StringTableSection &StrTabSec); void finalizeContents() override; - void postThunkContents() override; size_t getSize() const override { return getNumSymbols() * Entsize; } void addSymbol(Symbol *Sym); unsigned getNumSymbols() const { return Symbols.size() + 1; } @@ -569,6 +566,8 @@ ArrayRef getSymbols() const { return Symbols; } protected: + void sortSymTabSymbols(); + // A vector of symbols and their string table offsets. std::vector Symbols; Index: lld/trunk/ELF/SyntheticSections.cpp =================================================================== --- lld/trunk/ELF/SyntheticSections.cpp +++ lld/trunk/ELF/SyntheticSections.cpp @@ -1845,8 +1845,10 @@ void SymbolTableBaseSection::finalizeContents() { getParent()->Link = StrTabSec.getParent()->SectionIndex; - if (this->Type != SHT_DYNSYM) + if (this->Type != SHT_DYNSYM) { + sortSymTabSymbols(); return; + } // If it is a .dynsym, there should be no local symbols, but we need // to do a few things for the dynamic linker. @@ -1874,9 +1876,7 @@ // Aside from above, we put local symbols in groups starting with the STT_FILE // symbol. That is convenient for purpose of identifying where are local symbols // coming from. -void SymbolTableBaseSection::postThunkContents() { - assert(this->Type == SHT_SYMTAB); - +void SymbolTableBaseSection::sortSymTabSymbols() { // Move all local symbols before global symbols. auto E = std::stable_partition( Symbols.begin(), Symbols.end(), [](const SymbolTableEntry &S) { Index: lld/trunk/ELF/Writer.cpp =================================================================== --- lld/trunk/ELF/Writer.cpp +++ lld/trunk/ELF/Writer.cpp @@ -1659,13 +1659,12 @@ // Dynamic section must be the last one in this list and dynamic // symbol table section (DynSymTab) must be the first one. applySynthetic( - {InX::DynSymTab, InX::Bss, InX::BssRelRo, InX::GnuHashTab, - InX::HashTab, InX::SymTab, InX::SymTabShndx, InX::ShStrTab, - InX::StrTab, In::VerDef, InX::DynStrTab, InX::Got, - InX::MipsGot, InX::IgotPlt, InX::GotPlt, InX::RelaDyn, - InX::RelrDyn, InX::RelaIplt, InX::RelaPlt, InX::Plt, - InX::Iplt, InX::EhFrameHdr, In::VerSym, In::VerNeed, - InX::Dynamic}, + {InX::DynSymTab, InX::Bss, InX::BssRelRo, InX::GnuHashTab, + InX::HashTab, InX::SymTabShndx, InX::ShStrTab, InX::StrTab, + In::VerDef, InX::DynStrTab, InX::Got, InX::MipsGot, + InX::IgotPlt, InX::GotPlt, InX::RelaDyn, InX::RelrDyn, + InX::RelaIplt, InX::RelaPlt, InX::Plt, InX::Iplt, + InX::EhFrameHdr, In::VerSym, In::VerNeed, InX::Dynamic}, [](SyntheticSection *SS) { SS->finalizeContents(); }); if (!Script->HasSectionsCommand && !Config->Relocatable) @@ -1705,7 +1704,7 @@ // createThunks may have added local symbols to the static symbol table applySynthetic({InX::SymTab}, - [](SyntheticSection *SS) { SS->postThunkContents(); }); + [](SyntheticSection *SS) { SS->finalizeContents(); }); // Fill other section headers. The dynamic table is finalized // at the end because some tags like RELSZ depend on result