[PATCH] D49547: [ELF] - Get rid of postThunkContents().
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 19 08:05:51 PDT 2018
grimar created this revision.
grimar added reviewers: ruiu, psmith.
Herald added subscribers: arichardson, emaste.
Herald added a reviewer: espindola.
It turns out that postThunkContents() is only used for
sorting symbols in `.symtab`.
Though we can instead move the logic to `finalizeContents`,
postpone calling it and then get rid of `postThunkContents()` completely.
https://reviews.llvm.org/D49547
Files:
ELF/SyntheticSections.cpp
ELF/SyntheticSections.h
ELF/Writer.cpp
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -1639,12 +1639,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::ShStrTab, InX::StrTab,
- In<ELFT>::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<ELFT>::VerSym, In<ELFT>::VerNeed, InX::Dynamic},
+ {InX::DynSymTab, InX::Bss, InX::BssRelRo, InX::GnuHashTab,
+ InX::HashTab, InX::ShStrTab, InX::StrTab, In<ELFT>::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<ELFT>::VerSym, In<ELFT>::VerNeed, InX::Dynamic},
[](SyntheticSection *SS) { SS->finalizeContents(); });
if (!Script->HasSectionsCommand && !Config->Relocatable)
@@ -1684,7 +1684,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
Index: ELF/SyntheticSections.h
===================================================================
--- ELF/SyntheticSections.h
+++ 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,14 +559,15 @@
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; }
size_t getSymbolIndex(Symbol *Sym);
ArrayRef<SymbolTableEntry> getSymbols() const { return Symbols; }
protected:
+ void sortSymTabSymbols();
+
// A vector of symbols and their string table offsets.
std::vector<SymbolTableEntry> Symbols;
Index: ELF/SyntheticSections.cpp
===================================================================
--- ELF/SyntheticSections.cpp
+++ ELF/SyntheticSections.cpp
@@ -1819,8 +1819,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.
@@ -1848,9 +1850,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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49547.156274.patch
Type: text/x-patch
Size: 3926 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180719/22758318/attachment.bin>
More information about the llvm-commits
mailing list