From ee647d4c96081ac8ad2d005706db66bffb0cd916 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 29 Jan 2022 18:01:58 -0800 Subject: [PATCH] [ELF] Optimize obj.getSectionIndex. NFC --- lld/ELF/InputFiles.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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::initializeSymbols(const object::ELFFile &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(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::initializeSymbols(const object::ELFFile &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(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];