Index: llvm/tools/llvm-readobj/ELFDumper.cpp =================================================================== --- llvm/tools/llvm-readobj/ELFDumper.cpp +++ llvm/tools/llvm-readobj/ELFDumper.cpp @@ -120,11 +120,11 @@ /// order (DT_REL, DT_RELSZ, DT_RELENT for example). struct DynRegionInfo { DynRegionInfo(StringRef ObjName) : FileName(ObjName) {} - DynRegionInfo(const void *A, uint64_t S, uint64_t ES, StringRef ObjName) + DynRegionInfo(const uint8_t *A, uint64_t S, uint64_t ES, StringRef ObjName) : Addr(A), Size(S), EntSize(ES), FileName(ObjName) {} /// Address in current address space. - const void *Addr = nullptr; + const uint8_t *Addr = nullptr; /// Size in bytes of the region. uint64_t Size = 0; /// Size of each entity in the region. @@ -878,8 +878,6 @@ } void printHashedSymbol(const ELFO *Obj, const Elf_Sym *FirstSym, uint32_t Sym, StringRef StrTable, uint32_t Bucket); - void printRelocHeader(unsigned SType); - void printRelReloc(const ELFO *Obj, unsigned SecIndex, const Elf_Shdr *SymTab, const Elf_Rel &R, unsigned RelIndex) override; void printRelaReloc(const ELFO *Obj, unsigned SecIndex, @@ -3715,7 +3713,8 @@ OS << Addend << "\n"; } -template void GNUStyle::printRelocHeader(unsigned SType) { +template +static void printRelocHeaderFields(formatted_raw_ostream &OS, unsigned SType) { bool IsRela = SType == ELF::SHT_RELA || SType == ELF::SHT_ANDROID_RELA; bool IsRelr = SType == ELF::SHT_RELR || SType == ELF::SHT_ANDROID_RELR; if (ELFT::Is64Bits) @@ -3736,6 +3735,16 @@ OS << "\n"; } +template +static void printDynamicRelocHeader(const ELFFile *Obj, + formatted_raw_ostream &OS, unsigned Type, + StringRef Name, const DynRegionInfo &Reg) { + uint64_t Offset = Reg.Addr - Obj->base(); + OS << "\n'" << Name.str().c_str() << "' relocation section at offset 0x" + << to_hexString(Offset, false) << " contains " << Reg.Size << " bytes:\n"; + printRelocHeaderFields(OS, Type); +} + template static bool isRelocationSec(const typename ELFT::Shdr &Sec) { return Sec.sh_type == ELF::SHT_REL || Sec.sh_type == ELF::SHT_RELA || @@ -3787,7 +3796,7 @@ OS << "\nRelocation section '" << Name << "' at offset 0x" << to_hexString(Offset, false) << " contains " << EntriesNum << " entries:\n"; - printRelocHeader(Sec.sh_type); + printRelocHeaderFields(OS, Sec.sh_type); this->printRelocationsHelper(Obj, Sec); } if (!HasRelocSections) @@ -4478,49 +4487,28 @@ const DynRegionInfo &DynRelrRegion = this->dumper()->getDynRelrRegion(); const DynRegionInfo &DynPLTRelRegion = this->dumper()->getDynPLTRelRegion(); if (DynRelaRegion.Size > 0) { - OS << "\n'RELA' relocation section at offset " - << format_hex(reinterpret_cast(DynRelaRegion.Addr) - - Obj->base(), - 1) - << " contains " << DynRelaRegion.Size << " bytes:\n"; - printRelocHeader(ELF::SHT_RELA); + printDynamicRelocHeader(Obj, OS, ELF::SHT_RELA, "RELA", DynRelaRegion); for (const Elf_Rela &Rela : this->dumper()->dyn_relas()) printDynamicRelocation(Obj, Rela); } if (DynRelRegion.Size > 0) { - OS << "\n'REL' relocation section at offset " - << format_hex(reinterpret_cast(DynRelRegion.Addr) - - Obj->base(), - 1) - << " contains " << DynRelRegion.Size << " bytes:\n"; - printRelocHeader(ELF::SHT_REL); + printDynamicRelocHeader(Obj, OS, ELF::SHT_REL, "REL", DynRelRegion); for (const Elf_Rel &Rel : this->dumper()->dyn_rels()) printDynamicRelocation(Obj, Rel); } if (DynRelrRegion.Size > 0) { - OS << "\n'RELR' relocation section at offset " - << format_hex(reinterpret_cast(DynRelrRegion.Addr) - - Obj->base(), - 1) - << " contains " << DynRelrRegion.Size << " bytes:\n"; - printRelocHeader(ELF::SHT_REL); + printDynamicRelocHeader(Obj, OS, ELF::SHT_REL, "RELR", DynRelrRegion); Elf_Relr_Range Relrs = this->dumper()->dyn_relrs(); for (const Elf_Rel &R : Obj->decode_relrs(Relrs)) printDynamicRelocation(Obj, R); } if (DynPLTRelRegion.Size) { - OS << "\n'PLT' relocation section at offset " - << format_hex(reinterpret_cast(DynPLTRelRegion.Addr) - - Obj->base(), - 1) - << " contains " << DynPLTRelRegion.Size << " bytes:\n"; - if (DynPLTRelRegion.EntSize == sizeof(Elf_Rela)) { - printRelocHeader(ELF::SHT_RELA); + printDynamicRelocHeader(Obj, OS, ELF::SHT_RELA, "PLT", DynPLTRelRegion); for (const Elf_Rela &Rela : DynPLTRelRegion.getAsArrayRef()) printDynamicRelocation(Obj, Rela); } else { - printRelocHeader(ELF::SHT_REL); + printDynamicRelocHeader(Obj, OS, ELF::SHT_REL, "PLT", DynPLTRelRegion); for (const Elf_Rel &Rel : DynPLTRelRegion.getAsArrayRef()) printDynamicRelocation(Obj, Rel); }