[lld] r296400 - Refactor write{Global,Local}Symbols.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 27 14:39:50 PST 2017


Author: ruiu
Date: Mon Feb 27 16:39:50 2017
New Revision: 296400

URL: http://llvm.org/viewvc/llvm-project?rev=296400&view=rev
Log:
Refactor write{Global,Local}Symbols.

This part of code is hard to understand because NumLocals does not
actually mean the number of local symbols but something else (!).
We need to rewrite. But before that we need to clean it up.

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=296400&r1=296399&r2=296400&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Mon Feb 27 16:39:50 2017
@@ -1377,7 +1377,6 @@ template <class ELFT> void SymbolTableSe
   // .dynsym only contains global symbols.
   if (Config->Discard != DiscardPolicy::All && !StrTabSec.isDynamic())
     writeLocalSymbols(Buf);
-
   writeGlobalSymbols(Buf);
 }
 
@@ -1386,22 +1385,23 @@ void SymbolTableSection<ELFT>::writeLoca
   // Iterate over all input object files to copy their local symbols
   // to the output symbol table pointed by Buf.
 
-  for (auto I = Symbols.begin(); I != Symbols.begin() + NumLocals; ++I) {
-    const DefinedRegular<ELFT> &Body = *cast<DefinedRegular<ELFT>>(I->Symbol);
-    InputSectionBase *Section = Body.Section;
+  for (auto It = Symbols.begin(), End = Symbols.begin() + NumLocals;
+       It != End; ++It) {
+    auto *Body = cast<DefinedRegular<ELFT>>(It->Symbol);
+    InputSectionBase *Section = Body->Section;
     auto *ESym = reinterpret_cast<Elf_Sym *>(Buf);
 
     if (!Section) {
       ESym->st_shndx = SHN_ABS;
-      ESym->st_value = Body.Value;
+      ESym->st_value = Body->Value;
     } else {
       const OutputSection *OutSec = Section->getOutputSection<ELFT>();
       ESym->st_shndx = OutSec->SectionIndex;
-      ESym->st_value = OutSec->Addr + Section->getOffset(Body);
+      ESym->st_value = OutSec->Addr + Section->getOffset(*Body);
     }
-    ESym->st_name = I->StrTabOffset;
-    ESym->st_size = Body.template getSize<ELFT>();
-    ESym->setBindingAndType(STB_LOCAL, Body.Type);
+    ESym->st_name = It->StrTabOffset;
+    ESym->st_size = Body->template getSize<ELFT>();
+    ESym->setBindingAndType(STB_LOCAL, Body->Type);
     Buf += sizeof(*ESym);
   }
 }
@@ -1412,17 +1412,13 @@ void SymbolTableSection<ELFT>::writeGlob
   // pointed by Buf.
   auto *ESym = reinterpret_cast<Elf_Sym *>(Buf);
 
-  for (auto I = Symbols.begin() + NumLocals; I != Symbols.end(); ++I) {
-    const SymbolTableEntry &S = *I;
-    SymbolBody *Body = S.Symbol;
-    size_t StrOff = S.StrTabOffset;
-
-    uint8_t Type = Body->Type;
-    uintX_t Size = Body->getSize<ELFT>();
-
-    ESym->setBindingAndType(Body->symbol()->computeBinding(), Type);
-    ESym->st_size = Size;
-    ESym->st_name = StrOff;
+  for (auto It = Symbols.begin() + NumLocals, End = Symbols.end();
+       It != End; ++It) {
+    SymbolBody *Body = It->Symbol;
+
+    ESym->setBindingAndType(Body->symbol()->computeBinding(), Body->Type);
+    ESym->st_size = Body->getSize<ELFT>();
+    ESym->st_name = It->StrTabOffset;
     ESym->setVisibility(Body->symbol()->Visibility);
     ESym->st_value = Body->getVA<ELFT>();
 




More information about the llvm-commits mailing list