[lld] r296318 - Add comments to SymbolTableSection.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 26 19:31:19 PST 2017


Author: ruiu
Date: Sun Feb 26 21:31:19 2017
New Revision: 296318

URL: http://llvm.org/viewvc/llvm-project?rev=296318&view=rev
Log:
Add comments to SymbolTableSection.

Modified:
    lld/trunk/ELF/SyntheticSections.cpp

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=296318&r1=296317&r2=296318&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Sun Feb 26 21:31:19 2017
@@ -1293,6 +1293,10 @@ static bool sortMipsSymbols(const Symbol
   return L->GotIndex < R->GotIndex;
 }
 
+// Finalize a symbol table. The ELF spec requires that all local
+// symbols precede global symbols, so we sort symbol entries in this
+// function. (For .dynsym, we don't do that because symbols for
+// dynamic linking are inherently all globals.)
 template <class ELFT> void SymbolTableSection<ELFT>::finalizeContents() {
   this->OutSec->Link = this->Link = StrTabSec.OutSec->SectionIndex;
   this->OutSec->Entsize = this->Entsize;
@@ -1321,14 +1325,16 @@ template <class ELFT> void SymbolTableSe
     return;
   }
 
-  if (In<ELFT>::GnuHashTab)
+  if (In<ELFT>::GnuHashTab) {
     // NB: It also sorts Symbols to meet the GNU hash table requirements.
     In<ELFT>::GnuHashTab->addSymbols(Symbols);
-  else if (Config->EMachine == EM_MIPS)
+  } else if (Config->EMachine == EM_MIPS) {
     std::stable_sort(Symbols.begin(), Symbols.end(),
                      [](const SymbolTableEntry &L, const SymbolTableEntry &R) {
                        return sortMipsSymbols(L.Symbol, R.Symbol);
                      });
+  }
+
   size_t I = 0;
   for (const SymbolTableEntry &S : Symbols)
     S.Symbol->DynsymIndex = ++I;




More information about the llvm-commits mailing list