[PATCH] D30494: [ELF] - Do not list sections explicitly for finalizeSynthetic()
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 1 04:02:03 PST 2017
grimar created this revision.
That allows to add new synthetic sections and not worry
about updating one more list for finalization.
https://reviews.llvm.org/D30494
Files:
ELF/Writer.cpp
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -1020,13 +1020,30 @@
Script<ELFT>::X->adjustSectionsAfterSorting();
}
-template <class ELFT>
-static void finalizeSynthetic(const std::vector<SyntheticSection *> &Sections) {
- for (SyntheticSection *SS : Sections)
- if (SS && SS->OutSec && !SS->empty()) {
- SS->finalizeContents();
- SS->OutSec->template assignOffsets<ELFT>();
- }
+template <class ELFT> static void finalizeSynthetic(SyntheticSection *SS) {
+ if (!SS || !SS->OutSec || SS->empty())
+ return;
+ SS->finalizeContents();
+ SS->OutSec->template assignOffsets<ELFT>();
+}
+
+// Dynamic section must be the last one in this list and dynamic
+// symbol table section (DynSymTab) must be the first one. Dynamic
+// string table should go after others because some sections may
+// add strings there during finalizing.
+template <class ELFT> static void finalizeAllSynthetics() {
+ auto IsSpecial = [](SyntheticSection *SS) {
+ return SS == In<ELFT>::DynSymTab || SS == In<ELFT>::Dynamic ||
+ SS == In<ELFT>::DynStrTab;
+ };
+
+ finalizeSynthetic<ELFT>(In<ELFT>::DynSymTab);
+ for (InputSectionBase *S : InputSections)
+ if (SyntheticSection *SS = dyn_cast<SyntheticSection>(S))
+ if (!IsSpecial(SS))
+ finalizeSynthetic<ELFT>(SS);
+ finalizeSynthetic<ELFT>(In<ELFT>::DynStrTab);
+ finalizeSynthetic<ELFT>(In<ELFT>::Dynamic);
}
// We need to add input synthetic sections early in createSyntheticSections()
@@ -1083,7 +1100,7 @@
// This responsible for splitting up .eh_frame section into
// pieces. The relocation scan uses those peaces, so this has to be
// earlier.
- finalizeSynthetic<ELFT>({In<ELFT>::EhFrame});
+ finalizeSynthetic<ELFT>(In<ELFT>::EhFrame);
// Scan relocations. This must be done after every symbol is declared so that
// we can correctly decide if a dynamic relocation is needed.
@@ -1156,17 +1173,7 @@
for (OutputSection *Sec : OutputSections)
Sec->finalize<ELFT>();
- // Dynamic section must be the last one in this list and dynamic
- // symbol table section (DynSymTab) must be the first one.
- finalizeSynthetic<ELFT>(
- {In<ELFT>::DynSymTab, In<ELFT>::GnuHashTab, In<ELFT>::HashTab,
- In<ELFT>::SymTab, In<ELFT>::ShStrTab, In<ELFT>::StrTab,
- In<ELFT>::VerDef, In<ELFT>::DynStrTab, In<ELFT>::GdbIndex,
- In<ELFT>::Got, In<ELFT>::MipsGot, In<ELFT>::IgotPlt,
- In<ELFT>::GotPlt, In<ELFT>::RelaDyn, In<ELFT>::RelaIplt,
- In<ELFT>::RelaPlt, In<ELFT>::Plt, In<ELFT>::Iplt,
- In<ELFT>::Plt, In<ELFT>::EhFrameHdr, In<ELFT>::VerSym,
- In<ELFT>::VerNeed, In<ELFT>::Dynamic});
+ finalizeAllSynthetics<ELFT>();
}
template <class ELFT> void Writer<ELFT>::addPredefinedSections() {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30494.90157.patch
Type: text/x-patch
Size: 2879 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170301/c438050a/attachment.bin>
More information about the llvm-commits
mailing list