[lld] a09df64 - [ELF] postParse: remove some branches in the fast path

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 1 14:18:15 PST 2024


Author: Fangrui Song
Date: 2024-12-01T14:18:10-08:00
New Revision: a09df64f406be162b0bd096dbe2466603b7a4f29

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

LOG: [ELF] postParse: remove some branches in the fast path

Added: 
    

Modified: 
    lld/ELF/InputFiles.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index f262e537a6d038..373292b4391c56 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -1219,14 +1219,17 @@ template <class ELFT> void ObjFile<ELFT>::postParse() {
 
     // Handle non-COMMON defined symbol below. !sym.file allows a symbol
     // assignment to redefine a symbol without an error.
-    if (!sym.file || !sym.isDefined() || secIdx == SHN_UNDEF ||
-        secIdx == SHN_COMMON)
+    if (!sym.file || !sym.isDefined() || secIdx == SHN_UNDEF)
       continue;
+    if (LLVM_UNLIKELY(secIdx >= SHN_LORESERVE)) {
+      if (secIdx == SHN_COMMON)
+        continue;
+      if (secIdx == SHN_XINDEX)
+        secIdx = check(getExtendedSymbolTableIndex<ELFT>(eSym, i, shndxTable));
+      else
+        secIdx = 0;
+    }
 
-    if (LLVM_UNLIKELY(secIdx == SHN_XINDEX))
-      secIdx = check(getExtendedSymbolTableIndex<ELFT>(eSym, i, shndxTable));
-    else if (secIdx >= SHN_LORESERVE)
-      secIdx = 0;
     if (LLVM_UNLIKELY(secIdx >= sections.size()))
       Fatal(ctx) << this << ": invalid section index: " << secIdx;
     InputSectionBase *sec = sections[secIdx];


        


More information about the llvm-commits mailing list