diff --git a/test/Object/Inputs/rel-no-sec-table.elf-x86-64 b/test/Object/Inputs/rel-no-sec-table.elf-x86-64 new file mode 100755 index 00000000000..d527305d659 Binary files /dev/null and b/test/Object/Inputs/rel-no-sec-table.elf-x86-64 differ diff --git a/test/Object/relocation-executable.test b/test/Object/relocation-executable.test index 38ad5968af8..93d4dee3089 100644 --- a/test/Object/relocation-executable.test +++ b/test/Object/relocation-executable.test @@ -35,3 +35,15 @@ RUN: %p/Inputs/hello-world.elf-x86-64 | FileCheck %s --check-prefix=DYN // DYN-NEXT: Addend: 0x0 // DYN-NEXT: } // DYN-NEXT: } + +RUN: llvm-readobj -dyn-relocations -expand-relocs \ +RUN: %p/Inputs/rel-no-sec-table.elf-x86-64 | FileCheck %s --check-prefix=DYN2 + +// DYN2: Dynamic Relocations { +// DYN2-NEXT: Relocation { +// DYN2-NEXT: Offset: 0x12F0 +// DYN2-NEXT: Type: R_X86_64_GLOB_DAT (6) +// DYN2-NEXT: Symbol: g +// DYN2-NEXT: Addend: 0x0 +// DYN2-NEXT: } +// DYN2-NEXT: } diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp index 6e4eaec475c..b4118f06665 100644 --- a/tools/llvm-readobj/ELFDumper.cpp +++ b/tools/llvm-readobj/ELFDumper.cpp @@ -110,6 +110,7 @@ private: DynRegionInfo DynRelaRegion; DynRegionInfo DynamicRegion; StringRef DynamicStringTable; + const Elf_Sym *DynSymStart = nullptr; StringRef SOName; const Elf_Hash *HashTable = nullptr; }; @@ -660,6 +661,10 @@ ELFDumper::ELFDumper(const ELFFile *Obj, StreamWriter &Writer) case ELF::DT_STRSZ: StringTableSize = Dyn.getVal(); break; + case ELF::DT_SYMTAB: + DynSymStart = + reinterpret_cast(toMappedAddr(Dyn.getPtr())); + break; } } if (StringTableBegin) @@ -837,7 +842,7 @@ void ELFDumper::printDynamicRelocations() { Obj->getRelocationTypeName(Rel.getType(Obj->isMips64EL()), RelocName); StringRef SymbolName; uint32_t SymIndex = Rel.getSymbol(Obj->isMips64EL()); - const Elf_Sym *Sym = Obj->dynamic_symbol_begin() + SymIndex; + const Elf_Sym *Sym = DynSymStart + SymIndex; SymbolName = errorOrDefault(Sym->getName(DynamicStringTable)); if (opts::ExpandRelocs) { DictScope Group(W, "Relocation"); @@ -931,7 +936,7 @@ void ELFDumper::printDynamicSymbols() { ErrorOr StrTableOrErr = Obj->getStringTableForSymtab(*Symtab); error(StrTableOrErr.getError()); StringRef StrTable = *StrTableOrErr; - for (const Elf_Sym &Sym : Obj->dynamic_symbols()) + for (const Elf_Sym &Sym : Obj->symbols(Symtab)) printSymbol(&Sym, StrTable, true); } @@ -1431,8 +1436,8 @@ template void MipsGOTParser::parseGOT() { const Elf_Shdr *DynSymSec = Obj->getDotDynSymSec(); ErrorOr StrTable = Obj->getStringTableForSymtab(*DynSymSec); error(StrTable.getError()); - const Elf_Sym *DynSymBegin = Obj->dynamic_symbol_begin(); - const Elf_Sym *DynSymEnd = Obj->dynamic_symbol_end(); + const Elf_Sym *DynSymBegin = Obj->symbol_begin(DynSymSec); + const Elf_Sym *DynSymEnd = Obj->symbol_end(DynSymSec); std::size_t DynSymTotal = std::size_t(std::distance(DynSymBegin, DynSymEnd)); if (*DtGotSym > DynSymTotal) {