[llvm] 1108cf6 - ELFObjectWriter: Optimize isInSymtab

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 28 17:36:19 PDT 2025


Author: Fangrui Song
Date: 2025-06-28T17:36:14-07:00
New Revision: 1108cf64196a056aa350baba98e3fab6d7529a59

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

LOG: ELFObjectWriter: Optimize isInSymtab

Added: 
    

Modified: 
    llvm/lib/MC/ELFObjectWriter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 3ee9a5e619df3..bd87b42ff61fd 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -121,7 +121,7 @@ struct ELFWriter {
   } Mode;
 
   uint64_t symbolValue(const MCSymbol &Sym);
-  bool isInSymtab(const MCSymbolELF &Symbol, bool Used, bool Renamed);
+  bool isInSymtab(const MCSymbolELF &Symbol);
 
   /// Helper struct for containing some precomputed information on symbols.
   struct ELFSymbolData {
@@ -469,7 +469,7 @@ void ELFWriter::writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex,
                      IsReserved);
 }
 
-bool ELFWriter::isInSymtab(const MCSymbolELF &Symbol, bool Used, bool Renamed) {
+bool ELFWriter::isInSymtab(const MCSymbolELF &Symbol) {
   if (Symbol.isVariable()) {
     const MCExpr *Expr = Symbol.getVariableValue();
     // Target Expressions that are always inlined do not appear in the symtab
@@ -479,27 +479,18 @@ bool ELFWriter::isInSymtab(const MCSymbolELF &Symbol, bool Used, bool Renamed) {
     // The .weakref alias does not appear in the symtab.
     if (Symbol.isWeakref())
       return false;
-  }
-
-  if (Used)
-    return true;
 
-  if (Renamed)
-    return false;
-
-  if (Symbol.isVariable() && Symbol.isUndefined()) {
-    // FIXME: this is here just to diagnose the case of a var = commmon_sym.
-    Asm.getBaseSymbol(Symbol);
-    return false;
+    if (Symbol.isUndefined()) {
+      // FIXME: this is here just to diagnose the case of a var = commmon_sym.
+      Asm.getBaseSymbol(Symbol);
+      return false;
+    }
   }
 
   if (Symbol.isTemporary())
     return false;
 
-  if (Symbol.getType() == ELF::STT_SECTION)
-    return false;
-
-  return true;
+  return Symbol.getType() != ELF::STT_SECTION;
 }
 
 void ELFWriter::computeSymbolTable(const RevGroupMapTy &RevGroupMap) {
@@ -531,8 +522,7 @@ void ELFWriter::computeSymbolTable(const RevGroupMapTy &RevGroupMap) {
     const auto &Symbol = cast<MCSymbolELF>(It.value());
     bool Used = Symbol.isUsedInReloc();
     bool isSignature = Symbol.isSignature();
-    if (!isInSymtab(Symbol, Used || isSignature,
-                    OWriter.Renames.count(&Symbol)))
+    if (!(Used || (!OWriter.Renames.count(&Symbol) && isInSymtab(Symbol))))
       continue;
 
     if (Symbol.isTemporary() && Symbol.isUndefined()) {


        


More information about the llvm-commits mailing list