[PATCH] D13910: [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:54:19 PDT 2015


This revision was automatically updated to reflect the committed changes.
Closed by commit rL250855: [ELF2] Extract calculation of symbol binding as a separate function. (authored by ikudrin).

Changed prior to commit:
  http://reviews.llvm.org/D13910?vs=37909&id=37914#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D13910

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

Index: lld/trunk/ELF/OutputSections.h
===================================================================
--- lld/trunk/ELF/OutputSections.h
+++ lld/trunk/ELF/OutputSections.h
@@ -180,6 +180,8 @@
   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;
Index: lld/trunk/ELF/OutputSections.cpp
===================================================================
--- lld/trunk/ELF/OutputSections.cpp
+++ lld/trunk/ELF/OutputSections.cpp
@@ -789,23 +789,17 @@
       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 @@
         });
 }
 
+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>;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13910.37914.patch
Type: text/x-patch
Size: 2008 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151020/cc3ee2d7/attachment.bin>


More information about the llvm-commits mailing list