[lld] aabe901 - [ELF] Remove one redundant computeBinding

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 25 23:59:32 PST 2021


Author: Fangrui Song
Date: 2021-12-25T23:59:27-08:00
New Revision: aabe901d57d6df4cd2786163359a7b2a7aae8c32

URL: https://github.com/llvm/llvm-project/commit/aabe901d57d6df4cd2786163359a7b2a7aae8c32
DIFF: https://github.com/llvm/llvm-project/commit/aabe901d57d6df4cd2786163359a7b2a7aae8c32.diff

LOG: [ELF] Remove one redundant computeBinding

This does resolve the redundancy in includeInDynsym().

Added: 
    

Modified: 
    lld/ELF/SyntheticSections.cpp
    lld/ELF/Writer.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index b8775097f1fc..86b2f33196ec 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -2116,9 +2116,8 @@ void SymbolTableBaseSection::finalizeContents() {
 void SymbolTableBaseSection::sortSymTabSymbols() {
   // Move all local symbols before global symbols.
   auto e = std::stable_partition(
-      symbols.begin(), symbols.end(), [](const SymbolTableEntry &s) {
-        return s.sym->isLocal() || s.sym->computeBinding() == STB_LOCAL;
-      });
+      symbols.begin(), symbols.end(),
+      [](const SymbolTableEntry &s) { return s.sym->isLocal(); });
   size_t numLocals = e - symbols.begin();
   getParent()->info = numLocals + 1;
 
@@ -2208,12 +2207,8 @@ template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *buf) {
 
     // Set st_info and st_other.
     eSym->st_other = 0;
-    if (sym->isLocal()) {
-      eSym->setBindingAndType(STB_LOCAL, sym->type);
-    } else {
-      eSym->setBindingAndType(sym->computeBinding(), sym->type);
-      eSym->setVisibility(sym->visibility);
-    }
+    eSym->setBindingAndType(sym->binding, sym->type);
+    eSym->setVisibility(sym->visibility);
 
     // The 3 most significant bits of st_other are used by OpenPOWER ABI.
     // See getPPC64GlobalEntryToLocalEntryOffset() for more details.

diff  --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 497e56886b72..6fbb3f7bf471 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -1973,6 +1973,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
     for (Symbol *sym : symtab->symbols()) {
       if (!sym->isUsedInRegularObj || !includeInSymtab(*sym))
         continue;
+      sym->binding = sym->computeBinding();
       if (in.symTab)
         in.symTab->addSymbol(sym);
 


        


More information about the llvm-commits mailing list