From 2b11aef2f4ab80b595ac2e53b299cb49f18f4372 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 23 Jul 2015 09:11:05 +0000 Subject: [PATCH] Support printing relocations in files with no section table. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242998 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Object/Inputs/rel-no-sec-table.elf-x86-64 | Bin 0 -> 2152 bytes test/Object/relocation-executable.test | 12 ++++++++++++ tools/llvm-readobj/ELFDumper.cpp | 13 +++++++++---- 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100755 test/Object/Inputs/rel-no-sec-table.elf-x86-64 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 0000000000000000000000000000000000000000..d527305d65976ad7afc5e0c569a18d5d04285186 GIT binary patch literal 2152 zcmcIk&2G~`5T2wdl>Zb2LcpOyAR$p!%?S<&B`ryX2(1w102j-}CaL5kRcuhhg$LjT zcodF2N**EHd^0oa`CNCKAR)v`$v5-O%+BoWtiQIqoob~*SWEPbjy0kt3?*#R6RNT0 z3SFi%%-8tWRJ)5)<$)`zOO9og=Ru}L0I8mP2`xFnXRA36T-7)r;;I@)BFMU$18}A) z5Opej3M7q|bi%e|`CnQ6+6kJ@FW_%1;HgJm82E`#p0^*zUYz*jgsEYW?<;wve{vk@ zzv%9g8fSV=>6y01x_ztNPqQp5;!^cHtD8*K8GX2^{5eJFvahT)^}mp-1Uv5dyV|7> zvTo;KYZviHxj41`SHS%{Nu-x@M#1f!x6~U&!CJ#K8jhc<=H)L_>YPLFrBdZCX+F%? zMa!=c`i_3xWq#gV-Lw4Zxq7&Of4qRFkK{dnx6^v{VvD@(?(Sx*>+Nh=xrVg7M#alFhXopo`(D_Bc)Xib<8e+6FYXU| z!a_MezRz`R2uDTt{MVV6n&AGo@#`Gx_E=IO{~b|E%grCL4ZSV7(S{cEQ^`w=5{v$! jF9CC?U0p5AlzdtyS=R9=*!L{Wi(l75zZ9Oi;Ku(3s%wKW literal 0 HcmV?d00001 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) { -- 2.34.1