diff options
-rw-r--r-- | lld/lib/ReaderWriter/ELF/ELFFile.cpp | 16 | ||||
-rw-r--r-- | lld/lib/ReaderWriter/ELF/ELFFile.h | 1 |
2 files changed, 14 insertions, 3 deletions
diff --git a/lld/lib/ReaderWriter/ELF/ELFFile.cpp b/lld/lib/ReaderWriter/ELF/ELFFile.cpp index b0b84b9261f..66f3a012f05 100644 --- a/lld/lib/ReaderWriter/ELF/ELFFile.cpp +++ b/lld/lib/ReaderWriter/ELF/ELFFile.cpp @@ -125,9 +125,17 @@ std::error_code ELFFile<ELFT>::createAtomizableSections() { // Record the number of relocs to guess at preallocating the buffer. uint64_t totalRelocs = 0; for (const Elf_Shdr §ion : _objFile->sections()) { - if (section.sh_type == llvm::ELF::SHT_SYMTAB) { + switch (section.sh_type) { + case llvm::ELF::SHT_SYMTAB: _symtab = §ion; continue; + case llvm::ELF::SHT_SYMTAB_SHNDX: { + ErrorOr<ArrayRef<Elf_Word>> tableOrErr = _objFile->getSHNDXTable(section); + if (std::error_code ec = tableOrErr.getError()) + return ec; + _shndxTable = *tableOrErr; + continue; + } } if (isIgnoredSection(§ion)) @@ -228,7 +236,8 @@ std::error_code ELFFile<ELFT>::createSymbolsFromAtomizableSections() { ++SymI; for (; SymI != SymE; ++SymI) { - ErrorOr<const Elf_Shdr *> section = _objFile->getSection(SymI); + ErrorOr<const Elf_Shdr *> section = + _objFile->getSection(SymI, _symtab, _shndxTable); if (std::error_code ec = section.getError()) return ec; @@ -673,7 +682,8 @@ template <class ELFT> void ELFFile<ELFT>::updateReferences() { continue; const Elf_Sym *symbol = _objFile->getSymbol(_symtab, ri->targetSymbolIndex()); - ErrorOr<const Elf_Shdr *> shdr = _objFile->getSection(symbol); + ErrorOr<const Elf_Shdr *> shdr = + _objFile->getSection(symbol, _symtab, _shndxTable); // If the atom is not in mergeable string section, the target atom is // simply that atom. diff --git a/lld/lib/ReaderWriter/ELF/ELFFile.h b/lld/lib/ReaderWriter/ELF/ELFFile.h index 16c3edde98b..f413471c709 100644 --- a/lld/lib/ReaderWriter/ELF/ELFFile.h +++ b/lld/lib/ReaderWriter/ELF/ELFFile.h @@ -321,6 +321,7 @@ protected: llvm::BumpPtrAllocator _readerStorage; std::unique_ptr<llvm::object::ELFFile<ELFT> > _objFile; const Elf_Shdr *_symtab = nullptr; + ArrayRef<Elf_Word> _shndxTable; /// \brief _relocationAddendReferences and _relocationReferences contain the /// list of relocations references. In ELF, if a section named, ".text" has |