diff --git a/llvm/docs/CommandGuide/llvm-readelf.rst b/llvm/docs/CommandGuide/llvm-readelf.rst index 675628fdda45e..284c3aa470a6f 100644 --- a/llvm/docs/CommandGuide/llvm-readelf.rst +++ b/llvm/docs/CommandGuide/llvm-readelf.rst @@ -152,10 +152,6 @@ OPTIONS Display the program headers. -.. option:: --raw-relr - - Do not decode relocations in RELR relocation sections when displaying them. - .. option:: --relocations, --relocs, -r Display the relocation entries in the file. diff --git a/llvm/docs/CommandGuide/llvm-readobj.rst b/llvm/docs/CommandGuide/llvm-readobj.rst index ca7fb253f00a0..8bd29eafbbfcf 100644 --- a/llvm/docs/CommandGuide/llvm-readobj.rst +++ b/llvm/docs/CommandGuide/llvm-readobj.rst @@ -255,10 +255,6 @@ The following options are implemented only for the ELF file format. Display the program headers. -.. option:: --raw-relr - - Do not decode relocations in RELR relocation sections when displaying them. - .. option:: --section-mapping Display the section to segment mapping. diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst index 76ef6ceb94078..580dc512d9690 100644 --- a/llvm/docs/ReleaseNotes.rst +++ b/llvm/docs/ReleaseNotes.rst @@ -198,6 +198,10 @@ Changes to the LLVM tools documentation for SPGO `_. +* llvm-readelf's ``-r`` output for RELR has been improved. + (`#89162 `_) + ``--raw-relr`` has been removed. + Changes to LLDB --------------------------------- diff --git a/llvm/test/tools/llvm-readobj/ELF/relr-relocs.test b/llvm/test/tools/llvm-readobj/ELF/relr-relocs.test index 9b59f991c051e..c22239900bcf2 100644 --- a/llvm/test/tools/llvm-readobj/ELF/relr-relocs.test +++ b/llvm/test/tools/llvm-readobj/ELF/relr-relocs.test @@ -1,16 +1,6 @@ ## This is a test to test how SHT_RELR sections are dumped. # RUN: yaml2obj --docnum=1 %s -o %t1 -# RUN: llvm-readobj --relocations --raw-relr %t1 \ -# RUN: | FileCheck --check-prefix=RAW-LLVM1 %s -# RAW-LLVM1: Section (1) .relr.dyn { -# RAW-LLVM1-NEXT: 0x10D60 -# RAW-LLVM1-NEXT: 0x103 -# RAW-LLVM1-NEXT: 0x20000 -# RAW-LLVM1-NEXT: 0xF0501 -# RAW-LLVM1-NEXT: 0xA700550400009 -# RAW-LLVM1-NEXT: } - # RUN: llvm-readobj --relocations %t1 | \ # RUN: FileCheck --match-full-lines --check-prefix=LLVM1 %s @@ -38,15 +28,6 @@ # LLVM1-NEXT: 0x20390 R_X86_64_RELATIVE - # LLVM1-NEXT: } -# RUN: llvm-readelf --relocations --raw-relr %t1 \ -# RUN: | FileCheck --check-prefix=RAW-GNU1 %s -# RAW-GNU1: Relocation section '.relr.dyn' at offset 0x40 contains 5 entries: -# RAW-GNU1: 0000000000010d60 -# RAW-GNU1-NEXT: 0000000000000103 -# RAW-GNU1-NEXT: 0000000000020000 -# RAW-GNU1-NEXT: 00000000000f0501 -# RAW-GNU1-NEXT: 000a700550400009 - # RUN: llvm-readelf --relocations %t1 | FileCheck --check-prefix=GNU1 --match-full-lines --strict-whitespace %s # GNU1:Relocation section '.relr.dyn' at offset 0x40 contains 21 entries: # GNU1-NEXT:Index: Entry Address Symbolic Address @@ -107,16 +88,6 @@ Symbols: Value: 0x20210 # RUN: yaml2obj --docnum=2 %s -o %t2 -# RUN: llvm-readobj --relocations --raw-relr %t2 | \ -# RUN: FileCheck --check-prefix=RAW-LLVM2 %s -# RAW-LLVM2: Section (1) .relr.dyn { -# RAW-LLVM2-NEXT: 0x10D60 -# RAW-LLVM2-NEXT: 0x103 -# RAW-LLVM2-NEXT: 0x20000 -# RAW-LLVM2-NEXT: 0xF0501 -# RAW-LLVM2-NEXT: 0x50400009 -# RAW-LLVM2-NEXT: } - # RUN: llvm-readobj --relocations %t2 | \ # RUN: FileCheck --match-full-lines --check-prefix=LLVM2 %s @@ -137,15 +108,6 @@ Symbols: # LLVM2-NEXT: 0x200F4 R_386_RELATIVE - # LLVM2-NEXT: } -# RUN: llvm-readelf --relocations --raw-relr %t2 | \ -# RUN: FileCheck --check-prefix=RAW-GNU2 %s -# RAW-GNU2: Relocation section '.relr.dyn' at offset 0x34 contains 5 entries: -# RAW-GNU2: 00010d60 -# RAW-GNU2-NEXT: 00000103 -# RAW-GNU2-NEXT: 00020000 -# RAW-GNU2-NEXT: 000f0501 -# RAW-GNU2-NEXT: 50400009 - # RUN: llvm-readelf --relocations %t2 | FileCheck --check-prefix=GNU2 --match-full-lines --strict-whitespace %s # GNU2:Relocation section '.relr.dyn' at offset 0x34 contains 14 entries: # GNU2-NEXT:Index: Entry Address Symbolic Address @@ -232,21 +194,14 @@ Symbols: ## only relative relocations and do not have an associated symbol table, like other ## relocation sections. -## Case A: check we do not report warnings when the sh_link field is set to an arbitrary value -## and the --relocations option is requested. +## Check we do not report warnings when the sh_link field is set to an arbitrary value +## and the --relocations option is requested. # RUN: yaml2obj --docnum=2 -DLINK=0xff %s -o %t2.has.link # RUN: llvm-readobj --relocations %t2.has.link 2>&1 | \ # RUN: FileCheck -DFILE=%t2.has.link --check-prefix=LLVM2 %s --implicit-check-not=warning: # RUN: llvm-readelf --relocations %t2.has.link 2>&1 | \ # RUN: FileCheck -DFILE=%t2.has.link --check-prefix=GNU2 %s --implicit-check-not=warning: -## Case B: check we do not report warnings when the sh_link field is set to an arbitrary value -## and --relocations and --raw-relr options are requested. -# RUN: llvm-readobj --relocations --raw-relr %t2.has.link | \ -# RUN: FileCheck -DFILE=%t2.has.link --check-prefix=RAW-LLVM2 %s -# RUN: llvm-readelf --relocations --raw-relr %t2.has.link 2>&1 | \ -# RUN: FileCheck -DFILE=%t2.has.link --check-prefix=RAW-GNU2 %s - ## .symtab is invalid. Check we report a warning and print entries without symbolization. # RUN: yaml2obj --docnum=3 -DENTSIZE=1 %s -o %t3.err1 # RUN: llvm-readelf -r %t3.err1 2>&1 | FileCheck -DFILE=%t3.err1 --check-prefixes=GNU3,GNU3-ERR1 --match-full-lines %s diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index f145653ac743c..a752cc4015293 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -285,7 +285,6 @@ template class ELFDumper : public ObjDumper { virtual void printRelRelaReloc(const Relocation &R, const RelSymbol &RelSym) = 0; - virtual void printRelrReloc(const Elf_Relr &R) = 0; virtual void printDynamicRelocHeader(unsigned Type, StringRef Name, const DynRegionInfo &Reg) {} void printReloc(const Relocation &R, unsigned RelIndex, @@ -294,11 +293,10 @@ template class ELFDumper : public ObjDumper { void printDynamicRelocationsHelper(); void printRelocationsHelper(const Elf_Shdr &Sec); void forEachRelocationDo( - const Elf_Shdr &Sec, bool RawRelr, + const Elf_Shdr &Sec, llvm::function_ref &, unsigned, const Elf_Shdr &, const Elf_Shdr *)> - RelRelaFn, - llvm::function_ref RelrFn); + RelRelaFn); virtual void printSymtabMessage(const Elf_Shdr *Symtab, size_t Offset, bool NonVisibilityBitsUsed, @@ -669,7 +667,6 @@ template class GNUELFDumper : public ELFDumper { DataRegion ShndxTable, StringRef StrTable, uint32_t Bucket); void printRelr(const Elf_Shdr &Sec); - void printRelrReloc(const Elf_Relr &R) override; void printRelRelaReloc(const Relocation &R, const RelSymbol &RelSym) override; void printSymbol(const Elf_Sym &Symbol, unsigned SymIndex, @@ -734,7 +731,6 @@ template class LLVMELFDumper : public ELFDumper { bool IsGnu) const override; private: - void printRelrReloc(const Elf_Relr &R) override; void printRelRelaReloc(const Relocation &R, const RelSymbol &RelSym) override; @@ -3800,11 +3796,6 @@ template void GNUELFDumper::printGroupSections() { OS << "There are no section groups in this file.\n"; } -template -void GNUELFDumper::printRelrReloc(const Elf_Relr &R) { - OS << to_string(format_hex_no_prefix(R, ELFT::Is64Bits ? 16 : 8)) << "\n"; -} - template void GNUELFDumper::printRelRelaReloc(const Relocation &R, const RelSymbol &RelSym) { @@ -3851,22 +3842,11 @@ template static void printRelocHeaderFields(formatted_raw_ostream &OS, unsigned SType, const typename ELFT::Ehdr &EHeader) { bool IsRela = SType == ELF::SHT_RELA || SType == ELF::SHT_ANDROID_RELA; - bool IsRelr = - SType == ELF::SHT_RELR || SType == ELF::SHT_ANDROID_RELR || - (EHeader.e_machine == EM_AARCH64 && SType == ELF::SHT_AARCH64_AUTH_RELR); - if (ELFT::Is64Bits) - OS << " "; - else - OS << " "; - if (IsRelr && opts::RawRelr) - OS << "Data "; - else - OS << "Offset"; if (ELFT::Is64Bits) - OS << " Info Type" - << " Symbol's Value Symbol's Name"; + OS << " Offset Info Type Symbol's " + "Value Symbol's Name"; else - OS << " Info Type Sym. Value Symbol's Name"; + OS << " Offset Info Type Sym. Value Symbol's Name"; if (IsRela) OS << " + Addend"; OS << "\n"; @@ -3894,10 +3874,10 @@ static bool isRelocationSec(const typename ELFT::Shdr &Sec, template void GNUELFDumper::printRelocations() { auto PrintAsRelr = [&](const Elf_Shdr &Sec) { - return !opts::RawRelr && (Sec.sh_type == ELF::SHT_RELR || - Sec.sh_type == ELF::SHT_ANDROID_RELR || - (this->Obj.getHeader().e_machine == EM_AARCH64 && - Sec.sh_type == ELF::SHT_AARCH64_AUTH_RELR)); + return Sec.sh_type == ELF::SHT_RELR || + Sec.sh_type == ELF::SHT_ANDROID_RELR || + (this->Obj.getHeader().e_machine == EM_AARCH64 && + Sec.sh_type == ELF::SHT_AARCH64_AUTH_RELR); }; auto GetEntriesNum = [&](const Elf_Shdr &Sec) -> Expected { // Android's packed relocation section needs to be unpacked first @@ -4902,10 +4882,8 @@ void ELFDumper::printDynamicReloc(const Relocation &R) { template void ELFDumper::printRelocationsHelper(const Elf_Shdr &Sec) { this->forEachRelocationDo( - Sec, opts::RawRelr, - [&](const Relocation &R, unsigned Ndx, const Elf_Shdr &Sec, - const Elf_Shdr *SymTab) { printReloc(R, Ndx, Sec, SymTab); }, - [&](const Elf_Relr &R) { printRelrReloc(R); }); + Sec, [&](const Relocation &R, unsigned Ndx, const Elf_Shdr &Sec, + const Elf_Shdr *SymTab) { printReloc(R, Ndx, Sec, SymTab); }); } template void ELFDumper::printDynamicRelocationsHelper() { @@ -6371,11 +6349,10 @@ void ELFDumper::printDependentLibsHelper( template void ELFDumper::forEachRelocationDo( - const Elf_Shdr &Sec, bool RawRelr, + const Elf_Shdr &Sec, llvm::function_ref &, unsigned, const Elf_Shdr &, const Elf_Shdr *)> - RelRelaFn, - llvm::function_ref RelrFn) { + RelRelaFn) { auto Warn = [&](Error &&E, const Twine &Prefix = "unable to read relocations from") { this->reportUniqueWarning(Prefix + " " + describe(Sec) + ": " + @@ -6427,11 +6404,6 @@ void ELFDumper::forEachRelocationDo( Warn(RangeOrErr.takeError()); break; } - if (RawRelr) { - for (const Elf_Relr &R : *RangeOrErr) - RelrFn(R); - break; - } for (const Elf_Rel &R : Obj.decode_relrs(*RangeOrErr)) RelRelaFn(Relocation(R, IsMips64EL), RelNdx++, Sec, @@ -6741,9 +6713,8 @@ void ELFDumper::printRelocatableStackSizes( DataExtractor Data(Contents, Obj.isLE(), sizeof(Elf_Addr)); forEachRelocationDo( - *RelocSec, /*RawRelr=*/false, - [&](const Relocation &R, unsigned Ndx, const Elf_Shdr &Sec, - const Elf_Shdr *SymTab) { + *RelocSec, [&](const Relocation &R, unsigned Ndx, + const Elf_Shdr &Sec, const Elf_Shdr *SymTab) { if (!IsSupportedFn || !IsSupportedFn(R.Type)) { reportUniqueWarning( describe(*RelocSec) + @@ -6754,10 +6725,6 @@ void ELFDumper::printRelocatableStackSizes( this->printStackSize(R, *RelocSec, Ndx, SymTab, FunctionSec, *StackSizesELFSec, Resolver, Data); - }, - [](const Elf_Relr &) { - llvm_unreachable("can't get here, because we only support " - "SHT_REL/SHT_RELA sections"); }); } } @@ -7147,11 +7114,6 @@ template void LLVMELFDumper::printRelocations() { } } -template -void LLVMELFDumper::printRelrReloc(const Elf_Relr &R) { - W.startLine() << W.hex(R) << "\n"; -} - template void LLVMELFDumper::printExpandedRelRelaReloc(const Relocation &R, StringRef SymbolName, diff --git a/llvm/tools/llvm-readobj/Opts.td b/llvm/tools/llvm-readobj/Opts.td index 1e9cde6b2e87c..7d574d875d22e 100644 --- a/llvm/tools/llvm-readobj/Opts.td +++ b/llvm/tools/llvm-readobj/Opts.td @@ -62,7 +62,6 @@ def memtag : FF<"memtag", "Display memory tagging metadata (modes, Android notes def needed_libs : FF<"needed-libs", "Display the needed libraries">, Group; def notes : FF<"notes", "Display notes">, Group; def program_headers : FF<"program-headers", "Display program headers">, Group; -def raw_relr : FF<"raw-relr", "Do not decode relocations in SHT_RELR section, display raw contents">, Group; def version_info : FF<"version-info", "Display version sections">, Group; // Mach-O specific options. diff --git a/llvm/tools/llvm-readobj/llvm-readobj.cpp b/llvm/tools/llvm-readobj/llvm-readobj.cpp index a0b5765660165..9ac324cc672f0 100644 --- a/llvm/tools/llvm-readobj/llvm-readobj.cpp +++ b/llvm/tools/llvm-readobj/llvm-readobj.cpp @@ -134,7 +134,6 @@ static bool Memtag; static bool NeededLibraries; static bool Notes; static bool ProgramHeaders; -bool RawRelr; static bool SectionGroups; static bool VersionInfo; @@ -273,7 +272,6 @@ static void parseOptions(const opt::InputArgList &Args) { opts::Notes = Args.hasArg(OPT_notes); opts::PrettyPrint = Args.hasArg(OPT_pretty_print); opts::ProgramHeaders = Args.hasArg(OPT_program_headers); - opts::RawRelr = Args.hasArg(OPT_raw_relr); opts::SectionGroups = Args.hasArg(OPT_section_groups); if (Arg *A = Args.getLastArg(OPT_sort_symbols_EQ)) { std::string SortKeysString = A->getValue(); diff --git a/llvm/tools/llvm-readobj/llvm-readobj.h b/llvm/tools/llvm-readobj/llvm-readobj.h index 532e43d4e16b0..e4ee2c1396b28 100644 --- a/llvm/tools/llvm-readobj/llvm-readobj.h +++ b/llvm/tools/llvm-readobj/llvm-readobj.h @@ -38,7 +38,6 @@ extern bool SectionRelocations; extern bool SectionSymbols; extern bool SectionData; extern bool ExpandRelocs; -extern bool RawRelr; extern bool CodeViewSubsectionBytes; extern bool Demangle; enum OutputStyleTy { LLVM, GNU, JSON, UNKNOWN };