[lld] r251789 - [ELF2] Ensure that .dynsym section is finalized before .gnu.hash.
Igor Kudrin via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 2 02:46:14 PST 2015
Author: ikudrin
Date: Mon Nov 2 04:46:14 2015
New Revision: 251789
URL: http://llvm.org/viewvc/llvm-project?rev=251789&view=rev
Log:
[ELF2] Ensure that .dynsym section is finalized before .gnu.hash.
It is required to fill up the GNU hash table section before its
finalize() method is called.
Differential Revision: http://reviews.llvm.org/D14196
Modified:
lld/trunk/ELF/OutputSections.cpp
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=251789&r1=251788&r2=251789&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Mon Nov 2 04:46:14 2015
@@ -340,8 +340,7 @@ unsigned GnuHashTableSection<ELFT>::calc
}
template <class ELFT> void GnuHashTableSection<ELFT>::finalize() {
- ArrayRef<SymbolBody *> A = Out<ELFT>::DynSymTab->getSymbols();
- unsigned NumHashed = std::count_if(A.begin(), A.end(), includeInGnuHashTable);
+ unsigned NumHashed = HashedSymbols.size();
NBuckets = calcNBuckets(NumHashed);
MaskWords = calcMaskWords(NumHashed);
// Second hash shift estimation: just predefined values.
@@ -900,6 +899,9 @@ SymbolTableSection<ELFT>::SymbolTableSec
}
template <class ELFT> void SymbolTableSection<ELFT>::finalize() {
+ if (this->Header.sh_size)
+ return; // Already finalized.
+
this->Header.sh_size = getNumSymbols() * sizeof(Elf_Sym);
this->Header.sh_link = StrTabSec.SectionIndex;
this->Header.sh_info = NumLocals + 1;
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=251789&r1=251788&r2=251789&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Nov 2 04:46:14 2015
@@ -581,9 +581,13 @@ template <class ELFT> void Writer<ELFT>:
for (OutputSectionBase<ELFT> *Sec : OutputSections)
Out<ELFT>::ShStrTab->add(Sec->getName());
- // Fill the DynStrTab early because Dynamic adds strings to
- // DynStrTab but .dynstr may appear before .dynamic.
+ // Finalizers fix each section's size.
+ // .dynamic section's finalizer may add strings to .dynstr,
+ // so finalize that early.
+ // Likewise, .dynsym is finalized early since that may fill up .gnu.hash.
Out<ELFT>::Dynamic->finalize();
+ if (isOutputDynamic())
+ Out<ELFT>::DynSymTab->finalize();
// Fill other section headers.
for (OutputSectionBase<ELFT> *Sec : OutputSections)
More information about the llvm-commits
mailing list