diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -875,7 +875,7 @@ // Partially parse the shared object file so that we can call // getSoName on this object. template void SharedFile::parseDynamic() { - const Elf_Shdr *DynamicSec = nullptr; + ArrayRef DynamicTags; const ELFFile Obj = this->getObj(); ArrayRef Sections = CHECK(Obj.sections(), this); @@ -888,7 +888,8 @@ this->initSymtab(Sections, &Sec); break; case SHT_DYNAMIC: - DynamicSec = &Sec; + DynamicTags = + CHECK(Obj.template getSectionContentsAsArray(&Sec), this); break; case SHT_SYMTAB_SHNDX: this->SymtabSHNDX = CHECK(Obj.getSHNDXTable(Sec, Sections), this); @@ -906,11 +907,7 @@ error("SHT_GNU_versym should be associated with symbol table"); // Search for a DT_SONAME tag to initialize this->SoName. - if (!DynamicSec) - return; - ArrayRef Arr = - CHECK(Obj.template getSectionContentsAsArray(DynamicSec), this); - for (const Elf_Dyn &Dyn : Arr) { + for (const Elf_Dyn &Dyn : DynamicTags) { if (Dyn.d_tag == DT_NEEDED) { uint64_t Val = Dyn.getVal(); if (Val >= this->StringTable.size())