From aabe901d57d6df4cd2786163359a7b2a7aae8c32 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 25 Dec 2021 23:59:27 -0800 Subject: [PATCH] [ELF] Remove one redundant computeBinding This does resolve the redundancy in includeInDynsym(). --- lld/ELF/SyntheticSections.cpp | 13 ++++--------- lld/ELF/Writer.cpp | 1 + 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index b877509..86b2f33 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 void SymbolTableSection::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 497e5688..6fbb3f7 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1973,6 +1973,7 @@ template void Writer::finalizeSections() { for (Symbol *sym : symtab->symbols()) { if (!sym->isUsedInRegularObj || !includeInSymtab(*sym)) continue; + sym->binding = sym->computeBinding(); if (in.symTab) in.symTab->addSymbol(sym); -- 2.7.4