[PATCH] D30494: [ELF] - Do not list sections explicitly for finalizeSynthetic()
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 2 05:15:50 PST 2017
grimar updated this revision to Diff 90320.
grimar added a comment.
- Addressed review comments.
https://reviews.llvm.org/D30494
Files:
ELF/Writer.cpp
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -1020,13 +1020,26 @@
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 because depends on
+// other section contents. Dynamic symbol table section must be the
+// first one for the same reasons. Dynamic string table also should go after
+// others because some sections may add strings there during finalizing.
+template <class ELFT> static void finalizeSyntheticSections() {
+ finalizeSynthetic<ELFT>(In<ELFT>::DynSymTab);
+ for (InputSectionBase *S : InputSections)
+ if (SyntheticSection *SS = dyn_cast<SyntheticSection>(S))
+ if (SS != In<ELFT>::DynSymTab && SS != In<ELFT>::Dynamic &&
+ SS != In<ELFT>::DynStrTab)
+ 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 +1096,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 +1169,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});
+ finalizeSyntheticSections<ELFT>();
}
template <class ELFT> void Writer<ELFT>::addPredefinedSections() {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30494.90320.patch
Type: text/x-patch
Size: 2856 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170302/ed7fcf06/attachment.bin>
More information about the llvm-commits
mailing list