[llvm] 9b6f264 - [XCOFF][llvm-readobj] improve the relocation output.
via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 7 19:16:26 PST 2021
Author: Esme-Yi
Date: 2021-11-08T03:15:52Z
New Revision: 9b6f264d2b09ab5e970e54f77119eb823f0fcc50
URL: https://github.com/llvm/llvm-project/commit/9b6f264d2b09ab5e970e54f77119eb823f0fcc50
DIFF: https://github.com/llvm/llvm-project/commit/9b6f264d2b09ab5e970e54f77119eb823f0fcc50.diff
LOG: [XCOFF][llvm-readobj] improve the relocation output.
Summary:
1. implemented the unexpanded relocations output.
2. modified the expanded output format to align.
Reviewed By: shchenz, jhenderson
Differential Revision: https://reviews.llvm.org/D111700
Added:
Modified:
llvm/test/tools/llvm-readobj/XCOFF/file-header.test
llvm/test/tools/llvm-readobj/XCOFF/relocations.test
llvm/test/tools/llvm-readobj/XCOFF/sections.test
llvm/tools/llvm-readobj/XCOFFDumper.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-readobj/XCOFF/file-header.test b/llvm/test/tools/llvm-readobj/XCOFF/file-header.test
index 9fe09a893997c..b7727dcf1d78a 100644
--- a/llvm/test/tools/llvm-readobj/XCOFF/file-header.test
+++ b/llvm/test/tools/llvm-readobj/XCOFF/file-header.test
@@ -4,7 +4,7 @@
# RUN: llvm-readobj %t1 --file-header | \
# RUN: FileCheck %s --strict-whitespace --match-full-lines --check-prefix=FILEHEADER32
-# FILEHEADER32:Format: aixcoff-rs6000
+# FILEHEADER32:Format: aixcoff-rs6000
# FILEHEADER32-NEXT:Arch: powerpc
# FILEHEADER32-NEXT:AddressSize: 32bit
# FILEHEADER32-NEXT:FileHeader {
@@ -35,7 +35,7 @@ Symbols:
# RUN: llvm-readobj %t2 --file-header | \
# RUN: FileCheck %s --strict-whitespace --match-full-lines --check-prefix=FILEHEADER64
-# FILEHEADER64:Format: aix5coff64-rs6000
+# FILEHEADER64:Format: aix5coff64-rs6000
# FILEHEADER64-NEXT:Arch: powerpc64
# FILEHEADER64-NEXT:AddressSize: 64bit
# FILEHEADER64-NEXT:FileHeader {
diff --git a/llvm/test/tools/llvm-readobj/XCOFF/relocations.test b/llvm/test/tools/llvm-readobj/XCOFF/relocations.test
index bff17120c15b4..9e327c4fbbdcc 100644
--- a/llvm/test/tools/llvm-readobj/XCOFF/relocations.test
+++ b/llvm/test/tools/llvm-readobj/XCOFF/relocations.test
@@ -3,40 +3,50 @@
# RUN: yaml2obj %s -o %t
# RUN: llvm-readobj --relocs --expand-relocs %t | \
# RUN: FileCheck %s --strict-whitespace --match-full-lines --check-prefix=RELOCSEXP
+# RUN: llvm-readobj --relocs %t | \
+# RUN: FileCheck %s --strict-whitespace --match-full-lines --check-prefix=RELOCS
-## TODO: Output of relocations not aligned.
-
-# RELOCSEXP:Relocations [
+# RELOCSEXP:Relocations [
# RELOCSEXP-NEXT: Section (index: 1) .text {
-# RELOCSEXP-NEXT: Relocation {
-# RELOCSEXP-NEXT: Virtual Address: 0x80
-# RELOCSEXP-NEXT: Symbol: foo (0)
-# RELOCSEXP-NEXT: IsSigned: No
-# RELOCSEXP-NEXT: FixupBitValue: 0
-# RELOCSEXP-NEXT: Length: 22
-# RELOCSEXP-NEXT: Type: R_POS (0x0)
+# RELOCSEXP-NEXT: Relocation {
+# RELOCSEXP-NEXT: Virtual Address: 0x80
+# RELOCSEXP-NEXT: Symbol: foo (0)
+# RELOCSEXP-NEXT: IsSigned: No
+# RELOCSEXP-NEXT: FixupBitValue: 0
+# RELOCSEXP-NEXT: Length: 22
+# RELOCSEXP-NEXT: Type: R_POS (0x0)
+# RELOCSEXP-NEXT: }
+# RELOCSEXP-NEXT: Relocation {
+# RELOCSEXP-NEXT: Virtual Address: 0x100
+# RELOCSEXP-NEXT: Symbol: foo (0)
+# RELOCSEXP-NEXT: IsSigned: No
+# RELOCSEXP-NEXT: FixupBitValue: 0
+# RELOCSEXP-NEXT: Length: 21
+# RELOCSEXP-NEXT: Type: R_REL (0x2)
+# RELOCSEXP-NEXT: }
# RELOCSEXP-NEXT: }
-# RELOCSEXP-NEXT: Relocation {
-# RELOCSEXP-NEXT: Virtual Address: 0x100
-# RELOCSEXP-NEXT: Symbol: foo (0)
-# RELOCSEXP-NEXT: IsSigned: No
-# RELOCSEXP-NEXT: FixupBitValue: 0
-# RELOCSEXP-NEXT: Length: 21
-# RELOCSEXP-NEXT: Type: R_REL (0x2)
+# RELOCSEXP-NEXT: Section (index: 2) .data {
+# RELOCSEXP-NEXT: Relocation {
+# RELOCSEXP-NEXT: Virtual Address: 0x200
+# RELOCSEXP-NEXT: Symbol: bar (1)
+# RELOCSEXP-NEXT: IsSigned: No
+# RELOCSEXP-NEXT: FixupBitValue: 0
+# RELOCSEXP-NEXT: Length: 20
+# RELOCSEXP-NEXT: Type: R_TOC (0x3)
+# RELOCSEXP-NEXT: }
# RELOCSEXP-NEXT: }
-# RELOCSEXP-NEXT:}
-# RELOCSEXP-NEXT:Section (index: 2) .data {
-# RELOCSEXP-NEXT:Relocation {
-# RELOCSEXP-NEXT: Virtual Address: 0x200
-# RELOCSEXP-NEXT: Symbol: bar (1)
-# RELOCSEXP-NEXT: IsSigned: No
-# RELOCSEXP-NEXT: FixupBitValue: 0
-# RELOCSEXP-NEXT: Length: 20
-# RELOCSEXP-NEXT: Type: R_TOC (0x3)
-# RELOCSEXP-NEXT:}
-# RELOCSEXP-NEXT:}
# RELOCSEXP-NEXT:]
+# RELOCS:Relocations [
+# RELOCS-NEXT: Section (index: 1) .text {
+# RELOCS-NEXT: 0x80 R_POS foo(0) 0x15
+# RELOCS-NEXT: 0x100 R_REL foo(0) 0x14
+# RELOCS-NEXT: }
+# RELOCS-NEXT: Section (index: 2) .data {
+# RELOCS-NEXT: 0x200 R_TOC bar(1) 0x13
+# RELOCS-NEXT: }
+# RELOCS-NEXT:]
+
--- !XCOFF
FileHeader:
MagicNumber: 0x01DF
diff --git a/llvm/test/tools/llvm-readobj/XCOFF/sections.test b/llvm/test/tools/llvm-readobj/XCOFF/sections.test
index 62695de1a70c5..be098939ce775 100644
--- a/llvm/test/tools/llvm-readobj/XCOFF/sections.test
+++ b/llvm/test/tools/llvm-readobj/XCOFF/sections.test
@@ -4,7 +4,7 @@
# RUN: llvm-readobj --section-headers %t1 | \
# RUN: FileCheck --strict-whitespace --match-full-lines --check-prefix=SEC32 %s
-# SEC32:Format: aixcoff-rs6000
+# SEC32:Format: aixcoff-rs6000
# SEC32-NEXT:Arch: powerpc
# SEC32-NEXT:AddressSize: 32bit
# SEC32-NEXT:Sections [
@@ -56,7 +56,7 @@ Sections:
# RUN: llvm-readobj --section-headers %t2 | \
# RUN: FileCheck --strict-whitespace --match-full-lines --check-prefix=SEC64 %s
-# SEC64:Format: aix5coff64-rs6000
+# SEC64:Format: aix5coff64-rs6000
# SEC64-NEXT:Arch: powerpc64
# SEC64-NEXT:AddressSize: 64bit
# SEC64-NEXT:Sections [
diff --git a/llvm/tools/llvm-readobj/XCOFFDumper.cpp b/llvm/tools/llvm-readobj/XCOFFDumper.cpp
index c67edd6a98bce..38e459cd5425b 100644
--- a/llvm/tools/llvm-readobj/XCOFFDumper.cpp
+++ b/llvm/tools/llvm-readobj/XCOFFDumper.cpp
@@ -48,6 +48,7 @@ class XCOFFDumper : public ObjDumper {
void printCsectAuxEnt(XCOFFCsectAuxRef AuxEntRef);
void printSectAuxEntForStat(const XCOFFSectAuxEntForStat *AuxEntPtr);
void printSymbol(const SymbolRef &);
+ template <typename RelTy> void printRelocation(RelTy Reloc);
template <typename Shdr, typename RelTy>
void printRelocations(ArrayRef<Shdr> Sections);
void printAuxiliaryHeader(const XCOFFAuxiliaryHeader32 *AuxHeader);
@@ -136,11 +137,33 @@ const EnumEntry<XCOFF::RelocationType> RelocationTypeNameclass[] = {
#undef ECase
};
+template <typename RelTy> void XCOFFDumper::printRelocation(RelTy Reloc) {
+ Expected<StringRef> ErrOrSymbolName =
+ Obj.getSymbolNameByIndex(Reloc.SymbolIndex);
+ if (Error E = ErrOrSymbolName.takeError()) {
+ reportUniqueWarning(std::move(E));
+ return;
+ }
+ StringRef SymbolName = *ErrOrSymbolName;
+ StringRef RelocName = XCOFF::getRelocationTypeString(Reloc.Type);
+ if (opts::ExpandRelocs) {
+ DictScope Group(W, "Relocation");
+ W.printHex("Virtual Address", Reloc.VirtualAddress);
+ W.printNumber("Symbol", SymbolName, Reloc.SymbolIndex);
+ W.printString("IsSigned", Reloc.isRelocationSigned() ? "Yes" : "No");
+ W.printNumber("FixupBitValue", Reloc.isFixupIndicated() ? 1 : 0);
+ W.printNumber("Length", Reloc.getRelocatedLength());
+ W.printEnum("Type", (uint8_t)Reloc.Type,
+ makeArrayRef(RelocationTypeNameclass));
+ } else {
+ raw_ostream &OS = W.startLine();
+ OS << W.hex(Reloc.VirtualAddress) << " " << RelocName << " " << SymbolName
+ << "(" << Reloc.SymbolIndex << ") " << W.hex(Reloc.Info) << "\n";
+ }
+}
+
template <typename Shdr, typename RelTy>
void XCOFFDumper::printRelocations(ArrayRef<Shdr> Sections) {
- if (!opts::ExpandRelocs)
- report_fatal_error("Unexpanded relocation output not implemented.");
-
ListScope LS(W, "Relocations");
uint16_t Index = 0;
for (const Shdr &Sec : Sections) {
@@ -161,24 +184,11 @@ void XCOFFDumper::printRelocations(ArrayRef<Shdr> Sections) {
W.startLine() << "Section (index: " << Index << ") " << Sec.getName()
<< " {\n";
- for (const RelTy Reloc : Relocations) {
- Expected<StringRef> ErrOrSymbolName =
- Obj.getSymbolNameByIndex(Reloc.SymbolIndex);
- if (Error E = ErrOrSymbolName.takeError()) {
- reportUniqueWarning(std::move(E));
- continue;
- }
+ W.indent();
+
+ for (const RelTy Reloc : Relocations)
+ printRelocation(Reloc);
- StringRef SymbolName = *ErrOrSymbolName;
- DictScope RelocScope(W, "Relocation");
- W.printHex("Virtual Address", Reloc.VirtualAddress);
- W.printNumber("Symbol", SymbolName, Reloc.SymbolIndex);
- W.printString("IsSigned", Reloc.isRelocationSigned() ? "Yes" : "No");
- W.printNumber("FixupBitValue", Reloc.isFixupIndicated() ? 1 : 0);
- W.printNumber("Length", Reloc.getRelocatedLength());
- W.printEnum("Type", (uint8_t)Reloc.Type,
- makeArrayRef(RelocationTypeNameclass));
- }
W.unindent();
W.startLine() << "}\n";
}
More information about the llvm-commits
mailing list