[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 12:24:00 PDT 2015


ikudrin created this revision.
ikudrin added a reviewer: rafael.
ikudrin added a subscriber: llvm-commits.
ikudrin added a project: lld.

http://reviews.llvm.org/D13910

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

Index: ELF/OutputSections.h
===================================================================
--- ELF/OutputSections.h
+++ ELF/OutputSections.h
@@ -180,6 +180,8 @@
   void writeLocalSymbols(uint8_t *&Buf);
   void writeGlobalSymbols(uint8_t *Buf);
 
+  static unsigned char getSymbolBinding(SymbolBody *Body);
+
   SymbolTable<ELFT> &Table;
   StringTableSection<ELFT> &StrTabSec;
   unsigned NumVisible = 0;
Index: ELF/OutputSections.cpp
===================================================================
--- ELF/OutputSections.cpp
+++ 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>
+unsigned char SymbolTableSection<ELFT>::getSymbolBinding(SymbolBody *Body) {
+  unsigned char 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.37909.patch
Type: text/x-patch
Size: 1966 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151020/e7dbaae1/attachment.bin>


More information about the llvm-commits mailing list