[lld] r250855 - [ELF2] Extract calculation of symbol binding as a separate function.

Igor Kudrin via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 20 13:52:14 PDT 2015


Author: ikudrin
Date: Tue Oct 20 15:52:14 2015
New Revision: 250855

URL: http://llvm.org/viewvc/llvm-project?rev=250855&view=rev
Log:
[ELF2] Extract calculation of symbol binding as a separate function.

Differential Revision: http://reviews.llvm.org/D13910

Modified:
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/ELF/OutputSections.h

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=250855&r1=250854&r2=250855&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Tue Oct 20 15:52:14 2015
@@ -789,23 +789,17 @@ void SymbolTableSection<ELFT>::writeGlob
       break;
     }
 
-    unsigned char Binding = Body->isWeak() ? STB_WEAK : STB_GLOBAL;
     unsigned char Type = STT_NOTYPE;
     uintX_t Size = 0;
     if (const auto *EBody = dyn_cast<ELFSymbolBody<ELFT>>(Body)) {
       const Elf_Sym &InputSym = EBody->Sym;
-      Binding = InputSym.getBinding();
       Type = InputSym.getType();
       Size = InputSym.st_size;
     }
 
-    unsigned char Visibility = Body->getMostConstrainingVisibility();
-    if (Visibility != STV_DEFAULT && Visibility != STV_PROTECTED)
-      Binding = STB_LOCAL;
-
-    ESym->setBindingAndType(Binding, Type);
+    ESym->setBindingAndType(getSymbolBinding(Body), Type);
     ESym->st_size = Size;
-    ESym->setVisibility(Visibility);
+    ESym->setVisibility(Body->getMostConstrainingVisibility());
     ESym->st_value = getSymVA<ELFT>(*Body);
 
     if (Section)
@@ -824,6 +818,16 @@ void SymbolTableSection<ELFT>::writeGlob
         });
 }
 
+template <class ELFT>
+uint8_t SymbolTableSection<ELFT>::getSymbolBinding(SymbolBody *Body) {
+  uint8_t Visibility = Body->getMostConstrainingVisibility();
+  if (Visibility != STV_DEFAULT && Visibility != STV_PROTECTED)
+    return STB_LOCAL;
+  if (const auto *EBody = dyn_cast<ELFSymbolBody<ELFT>>(Body))
+    return EBody->Sym.getBinding();
+  return Body->isWeak() ? STB_WEAK : STB_GLOBAL;
+}
+
 namespace lld {
 namespace elf2 {
 template class OutputSectionBase<ELF32LE>;

Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=250855&r1=250854&r2=250855&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Tue Oct 20 15:52:14 2015
@@ -180,6 +180,8 @@ private:
   void writeLocalSymbols(uint8_t *&Buf);
   void writeGlobalSymbols(uint8_t *Buf);
 
+  static uint8_t getSymbolBinding(SymbolBody *Body);
+
   SymbolTable<ELFT> &Table;
   StringTableSection<ELFT> &StrTabSec;
   unsigned NumVisible = 0;




More information about the llvm-commits mailing list