[PATCH] D30085: [LLD][ELF] Alloc local symbols to be added to the SymTab after global symbols

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 20 03:24:19 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL295650: [ELF] Allow local symbols to be added after global symbols (authored by psmith).

Changed prior to commit:
  https://reviews.llvm.org/D30085?vs=88869&id=89100#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D30085

Files:
  lld/trunk/ELF/SyntheticSections.cpp
  lld/trunk/ELF/Writer.cpp


Index: lld/trunk/ELF/Writer.cpp
===================================================================
--- lld/trunk/ELF/Writer.cpp
+++ lld/trunk/ELF/Writer.cpp
@@ -1103,13 +1103,7 @@
   if (In<ELFT>::Iplt && !In<ELFT>::Iplt->empty())
     In<ELFT>::Iplt->addSymbols();
 
-  // Some architectures use small displacements for jump instructions.
-  // It is linker's responsibility to create thunks containing long
-  // jump instructions if jump targets are too far. Create thunks.
-  if (Target->NeedsThunks)
-    createThunks<ELFT>(OutputSections);
-
-  // Now that we have defined all possible symbols including linker-
+  // Now that we have defined all possible global symbols including linker-
   // synthesized ones. Visit all symbols to give the finishing touches.
   for (Symbol *S : Symtab<ELFT>::X->getSymbols()) {
     SymbolBody *Body = S->body();
@@ -1159,6 +1153,12 @@
     fixHeaders();
   }
 
+  // Some architectures use small displacements for jump instructions.
+  // It is linker's responsibility to create thunks containing long
+  // jump instructions if jump targets are too far. Create thunks.
+  if (Target->NeedsThunks)
+    createThunks<ELFT>(OutputSections);
+
   // Fill other section headers. The dynamic table is finalized
   // at the end because some tags like RELSZ depend on result
   // of finalizing other sections.
Index: lld/trunk/ELF/SyntheticSections.cpp
===================================================================
--- lld/trunk/ELF/SyntheticSections.cpp
+++ lld/trunk/ELF/SyntheticSections.cpp
@@ -1085,9 +1085,17 @@
 
 template <class ELFT> void SymbolTableSection<ELFT>::finalize() {
   this->OutSec->Link = this->Link = StrTabSec.OutSec->SectionIndex;
-  this->OutSec->Info = this->Info = NumLocals + 1;
   this->OutSec->Entsize = this->Entsize;
 
+  if (!StrTabSec.isDynamic()) {
+    // All explictly added STB_LOCAL symbols without a Symbol are first
+    auto It = std::stable_partition(
+        Symbols.begin(), Symbols.end(),
+        [](const SymbolTableEntry &S) { return S.Symbol->isLocal(); });
+    NumLocals = It - Symbols.begin();
+  }
+  this->OutSec->Info = this->Info = 1 + NumLocals;
+
   if (Config->Relocatable)
     return;
 
@@ -1122,7 +1130,6 @@
 
 template <class ELFT> void SymbolTableSection<ELFT>::addLocal(SymbolBody *B) {
   assert(!StrTabSec.isDynamic());
-  ++NumLocals;
   Symbols.push_back({B, StrTabSec.addString(B->getName())});
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30085.89100.patch
Type: text/x-patch
Size: 2419 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170220/d499b8df/attachment.bin>


More information about the llvm-commits mailing list