Skip to content

Commit

Permalink
[llvm-readobj] Remove --raw-relr
Browse files Browse the repository at this point in the history
https://reviews.llvm.org/D47919 dumped RELR relocations as
`R_*_RELATIVE` and added --raw-relr (not in GNU) for testing purposes
(more readable than `llvm-readelf -x .relr.dyn`). The option is obsolete
after `llvm-readelf -r` output gets improved (#89162).

Since --raw-relr never seems to get more adoption. Let's remove it to
avoid some complexity.

Pull Request: #89426
  • Loading branch information
MaskRay committed Apr 22, 2024
1 parent a6f1b3a commit 89c95ef
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 112 deletions.
4 changes: 0 additions & 4 deletions llvm/docs/CommandGuide/llvm-readelf.rst
Expand Up @@ -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.
Expand Down
4 changes: 0 additions & 4 deletions llvm/docs/CommandGuide/llvm-readobj.rst
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions llvm/docs/ReleaseNotes.rst
Expand Up @@ -198,6 +198,10 @@ Changes to the LLVM tools
documentation for SPGO
<https://clang.llvm.org/docs/UsersManual.html#using-sampling-profilers>`_.

* llvm-readelf's ``-r`` output for RELR has been improved.
(`#89162 <https://github.com/llvm/llvm-project/pull/89162>`_)
``--raw-relr`` has been removed.

Changes to LLDB
---------------------------------

Expand Down
49 changes: 2 additions & 47 deletions 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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
68 changes: 15 additions & 53 deletions llvm/tools/llvm-readobj/ELFDumper.cpp
Expand Up @@ -285,7 +285,6 @@ template <typename ELFT> class ELFDumper : public ObjDumper {

virtual void printRelRelaReloc(const Relocation<ELFT> &R,
const RelSymbol<ELFT> &RelSym) = 0;
virtual void printRelrReloc(const Elf_Relr &R) = 0;
virtual void printDynamicRelocHeader(unsigned Type, StringRef Name,
const DynRegionInfo &Reg) {}
void printReloc(const Relocation<ELFT> &R, unsigned RelIndex,
Expand All @@ -294,11 +293,10 @@ template <typename ELFT> 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<void(const Relocation<ELFT> &, unsigned,
const Elf_Shdr &, const Elf_Shdr *)>
RelRelaFn,
llvm::function_ref<void(const Elf_Relr &)> RelrFn);
RelRelaFn);

virtual void printSymtabMessage(const Elf_Shdr *Symtab, size_t Offset,
bool NonVisibilityBitsUsed,
Expand Down Expand Up @@ -669,7 +667,6 @@ template <typename ELFT> class GNUELFDumper : public ELFDumper<ELFT> {
DataRegion<Elf_Word> ShndxTable, StringRef StrTable,
uint32_t Bucket);
void printRelr(const Elf_Shdr &Sec);
void printRelrReloc(const Elf_Relr &R) override;
void printRelRelaReloc(const Relocation<ELFT> &R,
const RelSymbol<ELFT> &RelSym) override;
void printSymbol(const Elf_Sym &Symbol, unsigned SymIndex,
Expand Down Expand Up @@ -734,7 +731,6 @@ template <typename ELFT> class LLVMELFDumper : public ELFDumper<ELFT> {
bool IsGnu) const override;

private:
void printRelrReloc(const Elf_Relr &R) override;
void printRelRelaReloc(const Relocation<ELFT> &R,
const RelSymbol<ELFT> &RelSym) override;

Expand Down Expand Up @@ -3800,11 +3796,6 @@ template <class ELFT> void GNUELFDumper<ELFT>::printGroupSections() {
OS << "There are no section groups in this file.\n";
}

template <class ELFT>
void GNUELFDumper<ELFT>::printRelrReloc(const Elf_Relr &R) {
OS << to_string(format_hex_no_prefix(R, ELFT::Is64Bits ? 16 : 8)) << "\n";
}

template <class ELFT>
void GNUELFDumper<ELFT>::printRelRelaReloc(const Relocation<ELFT> &R,
const RelSymbol<ELFT> &RelSym) {
Expand Down Expand Up @@ -3851,22 +3842,11 @@ template <class ELFT>
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";
Expand Down Expand Up @@ -3894,10 +3874,10 @@ static bool isRelocationSec(const typename ELFT::Shdr &Sec,

template <class ELFT> void GNUELFDumper<ELFT>::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<size_t> {
// Android's packed relocation section needs to be unpacked first
Expand Down Expand Up @@ -4902,10 +4882,8 @@ void ELFDumper<ELFT>::printDynamicReloc(const Relocation<ELFT> &R) {
template <class ELFT>
void ELFDumper<ELFT>::printRelocationsHelper(const Elf_Shdr &Sec) {
this->forEachRelocationDo(
Sec, opts::RawRelr,
[&](const Relocation<ELFT> &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<ELFT> &R, unsigned Ndx, const Elf_Shdr &Sec,
const Elf_Shdr *SymTab) { printReloc(R, Ndx, Sec, SymTab); });
}

template <class ELFT> void ELFDumper<ELFT>::printDynamicRelocationsHelper() {
Expand Down Expand Up @@ -6371,11 +6349,10 @@ void ELFDumper<ELFT>::printDependentLibsHelper(

template <class ELFT>
void ELFDumper<ELFT>::forEachRelocationDo(
const Elf_Shdr &Sec, bool RawRelr,
const Elf_Shdr &Sec,
llvm::function_ref<void(const Relocation<ELFT> &, unsigned,
const Elf_Shdr &, const Elf_Shdr *)>
RelRelaFn,
llvm::function_ref<void(const Elf_Relr &)> RelrFn) {
RelRelaFn) {
auto Warn = [&](Error &&E,
const Twine &Prefix = "unable to read relocations from") {
this->reportUniqueWarning(Prefix + " " + describe(Sec) + ": " +
Expand Down Expand Up @@ -6427,11 +6404,6 @@ void ELFDumper<ELFT>::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<ELFT>(R, IsMips64EL), RelNdx++, Sec,
Expand Down Expand Up @@ -6741,9 +6713,8 @@ void ELFDumper<ELFT>::printRelocatableStackSizes(
DataExtractor Data(Contents, Obj.isLE(), sizeof(Elf_Addr));

forEachRelocationDo(
*RelocSec, /*RawRelr=*/false,
[&](const Relocation<ELFT> &R, unsigned Ndx, const Elf_Shdr &Sec,
const Elf_Shdr *SymTab) {
*RelocSec, [&](const Relocation<ELFT> &R, unsigned Ndx,
const Elf_Shdr &Sec, const Elf_Shdr *SymTab) {
if (!IsSupportedFn || !IsSupportedFn(R.Type)) {
reportUniqueWarning(
describe(*RelocSec) +
Expand All @@ -6754,10 +6725,6 @@ void ELFDumper<ELFT>::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");
});
}
}
Expand Down Expand Up @@ -7147,11 +7114,6 @@ template <class ELFT> void LLVMELFDumper<ELFT>::printRelocations() {
}
}

template <class ELFT>
void LLVMELFDumper<ELFT>::printRelrReloc(const Elf_Relr &R) {
W.startLine() << W.hex(R) << "\n";
}

template <class ELFT>
void LLVMELFDumper<ELFT>::printExpandedRelRelaReloc(const Relocation<ELFT> &R,
StringRef SymbolName,
Expand Down
1 change: 0 additions & 1 deletion llvm/tools/llvm-readobj/Opts.td
Expand Up @@ -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<grp_elf>;
def notes : FF<"notes", "Display notes">, Group<grp_elf>;
def program_headers : FF<"program-headers", "Display program headers">, Group<grp_elf>;
def raw_relr : FF<"raw-relr", "Do not decode relocations in SHT_RELR section, display raw contents">, Group<grp_elf>;
def version_info : FF<"version-info", "Display version sections">, Group<grp_elf>;

// Mach-O specific options.
Expand Down
2 changes: 0 additions & 2 deletions llvm/tools/llvm-readobj/llvm-readobj.cpp
Expand Up @@ -134,7 +134,6 @@ static bool Memtag;
static bool NeededLibraries;
static bool Notes;
static bool ProgramHeaders;
bool RawRelr;
static bool SectionGroups;
static bool VersionInfo;

Expand Down Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion llvm/tools/llvm-readobj/llvm-readobj.h
Expand Up @@ -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 };
Expand Down

0 comments on commit 89c95ef

Please sign in to comment.