[lld] [llvm] [llvm-readelf] Print more information for RELR (PR #89162)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 18 11:08:09 PDT 2024
================
@@ -3926,13 +3930,85 @@ template <class ELFT> void GNUELFDumper<ELFT>::printRelocations() {
OS << "\nRelocation section '" << Name << "' at offset 0x"
<< utohexstr(Offset, /*LowerCase=*/true) << " contains " << EntriesNum
<< " entries:\n";
- printRelocHeaderFields<ELFT>(OS, Sec.sh_type, this->Obj.getHeader());
- this->printRelocationsHelper(Sec);
+
+ if (PrintAsRelr(Sec)) {
+ printRelr(Sec);
+ } else {
+ printRelocHeaderFields<ELFT>(OS, Sec.sh_type, this->Obj.getHeader());
+ this->printRelocationsHelper(Sec);
+ }
}
if (!HasRelocSections)
OS << "\nThere are no relocations in this file.\n";
}
+template <class ELFT> void GNUELFDumper<ELFT>::printRelr(const Elf_Shdr &Sec) {
+ Expected<Elf_Relr_Range> RangeOrErr = this->Obj.relrs(Sec);
+ if (!RangeOrErr) {
+ this->reportUniqueWarning("unable to read relocations from " +
+ this->describe(Sec) + ": " +
+ toString(RangeOrErr.takeError()));
+ return;
+ }
+ if (ELFT::Is64Bits)
+ OS << "Index: Entry Address Symbolic Address\n";
+ else
+ OS << "Index: Entry Address Symbolic Address\n";
+
+ SmallVector<std::pair<uint64_t, std::string>, 0> Syms;
+ if (this->DotSymtabSec) {
+ if (auto SymsOrErr = this->Obj.symbols(this->DotSymtabSec)) {
+ StringRef Strtab =
+ unwrapOrError(this->FileName,
----------------
MaskRay wrote:
I added `getSymtabAndStrtab` to downgrade the error to a warning. The helper can be used to simplify other symtab/strtab code in the future.
https://github.com/llvm/llvm-project/pull/89162
More information about the llvm-commits
mailing list