[lld] ee647d4 - [ELF] Optimize obj.getSectionIndex. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 29 18:02:03 PST 2022


Author: Fangrui Song
Date: 2022-01-29T18:01:58-08:00
New Revision: ee647d4c96081ac8ad2d005706db66bffb0cd916

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

LOG: [ELF] Optimize obj.getSectionIndex. NFC

Added: 
    

Modified: 
    lld/ELF/InputFiles.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 239a36768201..f5cdb199d4c9 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -1054,8 +1054,11 @@ void ObjFile<ELFT>::initializeSymbols(const object::ELFFile<ELFT> &obj) {
 
   for (size_t i = 0, end = firstGlobal; i != end; ++i) {
     const Elf_Sym &eSym = eSyms[i];
-    const uint32_t secIdx = check(obj.getSectionIndex(eSym, eSyms, shndxTable));
-
+    uint32_t secIdx = eSym.st_shndx;
+    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(toString(this) + ": invalid section index: " + Twine(secIdx));
     if (LLVM_UNLIKELY(eSym.getBinding() != STB_LOCAL))
@@ -1095,7 +1098,11 @@ void ObjFile<ELFT>::initializeSymbols(const object::ELFFile<ELFT> &obj) {
                   Twine(firstGlobal) + ")");
       continue;
     }
-    const uint32_t secIdx = check(obj.getSectionIndex(eSym, eSyms, shndxTable));
+    uint32_t secIdx = eSym.st_shndx;
+    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(toString(this) + ": invalid section index: " + Twine(secIdx));
     InputSectionBase *sec = sections[secIdx];


        


More information about the llvm-commits mailing list