[lld] r250463 - ELF2: Do not treat .strtab specially when creating sections.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 15 14:50:30 PDT 2015


Author: ruiu
Date: Thu Oct 15 16:50:30 2015
New Revision: 250463

URL: http://llvm.org/viewvc/llvm-project?rev=250463&view=rev
Log:
ELF2: Do not treat .strtab specially when creating sections.

String table is added to end of the file so that all the other sections
are finalized before string table. But we can just add section names to
the string table before calling finalize() on any section instead.

Modified:
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=250463&r1=250462&r2=250463&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Oct 15 16:50:30 2015
@@ -470,7 +470,10 @@ template <class ELFT> void Writer<ELFT>:
   }
   addCommonSymbols(CommonSymbols);
 
+  // This order is not the same as the final output order
+  // because we sort the sections using their attributes below.
   OutputSections.push_back(Out<ELFT>::SymTab);
+  OutputSections.push_back(Out<ELFT>::StrTab);
   if (isOutputDynamic()) {
     OutputSections.push_back(Out<ELFT>::DynSymTab);
     OutputSections.push_back(Out<ELFT>::HashTab);
@@ -487,21 +490,19 @@ template <class ELFT> void Writer<ELFT>:
   std::stable_sort(OutputSections.begin(), OutputSections.end(),
                    compareOutputSections<ELFT>);
 
-  // Always put StrTabSec last so that no section names are added to it after
-  // it's finalized.
-  OutputSections.push_back(Out<ELFT>::StrTab);
-
   for (unsigned I = 0, N = OutputSections.size(); I < N; ++I)
     OutputSections[I]->SectionIndex = I + 1;
 
-  // Fill the DynStrTab early.
+  for (OutputSectionBase<ELFT::Is64Bits> *Sec : OutputSections)
+    Out<ELFT>::StrTab->add(Sec->getName());
+
+  // Fill the DynStrTab early because Dynamic adds strings to
+  // DynStrTab but .dynstr may appear before .dynamic.
   Out<ELFT>::Dynamic->finalize();
 
-  // Fix each section's header (e.g. sh_size, sh_link, etc.)
-  for (OutputSectionBase<ELFT::Is64Bits> *Sec : OutputSections) {
-    Out<ELFT>::StrTab->add(Sec->getName());
+  // Fill other section headers.
+  for (OutputSectionBase<ELFT::Is64Bits> *Sec : OutputSections)
     Sec->finalize();
-  }
 
   // If we have a .opd section (used under PPC64 for function descriptors),
   // store a pointer to it here so that we can use it later when processing




More information about the llvm-commits mailing list