1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00

[llvm-objdump][XCOFF] Print more symbol info in relocation

Summary:
Print more symbol info in relocation printing when
--symbol-description is specified.

Differential Revision: https://reviews.llvm.org/D78499
This commit is contained in:
jasonliu 2020-04-21 21:52:08 +00:00
parent 01d2bbce45
commit d6af2bbecf
6 changed files with 63 additions and 17 deletions

View File

@ -6,6 +6,9 @@
# RUN: llvm-objdump -D --symbol-description %p/Inputs/xcoff-section-headers.o | \
# RUN: FileCheck --check-prefixes=COMMON,DESC %s
# RUN: llvm-objdump -D -r --symbol-description %p/Inputs/xcoff-section-headers.o | \
# RUN: FileCheck --check-prefixes=COMMON,DESC,RELOC %s
# xcoff-section-headers.o Compiled with IBM XL C/C++ for AIX, V16.1.0
# compiler command: xlc -qtls -o xcoff-section-headers.o -c test.c
@ -24,6 +27,7 @@ COMMON: Disassembly of section .text:
PLAIN: 00000000 <.text>:
DESC: 00000000 (idx: 4) .text:
COMMON-NEXT: 0: 80 62 00 04 lwz 3, 4(2)
RELOC: 00000002: R_TOC (idx: 26) a[TC]
COMMON-NEXT: 4: 80 63 00 00 lwz 3, 0(3)
COMMON-NEXT: 8: 4e 80 00 20 blr
COMMON-NEXT: c: 00 00 00 00 <unknown>
@ -37,22 +41,29 @@ COMMON: Disassembly of section .data:
PLAIN: 00000080 <func>:
DESC: 00000080 (idx: 22) func[TC]:
COMMON-NEXT: 80: 00 00 00 94 <unknown>
RELOC: 00000080: R_POS (idx: 20) func[DS]
PLAIN: 00000084 <a>:
DESC: 00000084 (idx: 26) a[TC]:
COMMON-NEXT: 84: 00 00 00 a4 <unknown>
RELOC: 00000084: R_POS (idx: 24) a[RW]
PLAIN: 00000088 <b>:
DESC: 00000088 (idx: 30) b[TC]:
COMMON-NEXT: 88: 00 00 00 a0 <unknown>
RELOC: 00000088: R_POS (idx: 28) b[RW]
PLAIN: 0000008c <c>:
DESC: 0000008c (idx: 34) c[TC]:
COMMON-NEXT: 8c: 00 00 00 08 <unknown>
RELOC: 0000008c: R_TLS (idx: 32) c[UL]
PLAIN: 00000090 <d>:
DESC: 00000090 (idx: 38) d[TC]:
COMMON-NEXT: 90: 00 00 00 00 <unknown>
RELOC: 00000090: R_TLS (idx: 36) d[TL]
PLAIN: 00000094 <func>:
DESC: 00000094 (idx: 20) func[DS]:
COMMON-NEXT: 94: 00 00 00 00 <unknown>
RELOC: 00000094: R_POS (idx: 16) .func
COMMON-NEXT: 98: 00 00 00 80 <unknown>
RELOC: 00000098: R_POS (idx: 18) TOC[TC0]
COMMON-NEXT: 9c: 00 00 00 00 <unknown>
PLAIN: 000000a0 <b>:
DESC: 000000a0 (idx: 28) b[RW]:

View File

@ -3,6 +3,9 @@
# RUN: llvm-objdump -r %p/Inputs/xcoff-section-headers.o | \
# RUN: FileCheck --match-full-lines --strict-whitespace %s
# RUN: llvm-objdump -r --symbol-description %p/Inputs/xcoff-section-headers.o | \
# RUN: FileCheck --match-full-lines --strict-whitespace --check-prefix=DESCP %s
## xcoff-section-headers.o Compiled with IBM XL C/C++ for AIX, V16.1.0
## compiler command: xlc -qtls -o xcoff-section-headers.o -c test.c
## test.c:
@ -29,3 +32,18 @@ CHECK-EMPTY:
CHECK-NEXT:00000014 R_POS .func
CHECK-NEXT:00000018 R_POS TOC
CHECK-EMPTY:
DESCP:RELOCATION RECORDS FOR [.text]:
DESCP-NEXT:OFFSET TYPE VALUE
DESCP-NEXT:00000002 R_TOC (idx: 26) a[TC]
DESCP-EMPTY:
DESCP:RELOCATION RECORDS FOR [.data]:
DESCP-NEXT:OFFSET TYPE VALUE
DESCP-NEXT:00000000 R_POS (idx: 20) func[DS]
DESCP-NEXT:00000004 R_POS (idx: 24) a[RW]
DESCP-NEXT:00000008 R_POS (idx: 28) b[RW]
DESCP-NEXT:0000000c R_TLS (idx: 32) c[UL]
DESCP-NEXT:00000010 R_TLS (idx: 36) d[TL]
DESCP-NEXT:00000014 R_POS (idx: 16) .func
DESCP-NEXT:00000018 R_POS (idx: 18) TOC[TC0]
DESCP-EMPTY:

View File

@ -12,7 +12,9 @@
//===----------------------------------------------------------------------===//
#include "XCOFFDump.h"
#include "llvm/MC/MCDisassembler/MCDisassembler.h"
#include "llvm-objdump.h"
#include "llvm/Demangle/Demangle.h"
using namespace llvm;
using namespace llvm::object;
@ -29,7 +31,14 @@ Error objdump::getXCOFFRelocationValueString(const XCOFFObjectFile *Obj,
Expected<StringRef> SymNameOrErr = SymI->getName();
if (!SymNameOrErr)
return SymNameOrErr.takeError();
StringRef SymName = *SymNameOrErr;
std::string SymName = (*SymNameOrErr).str();
if (Demangle)
SymName = demangle(SymName);
if (SymbolDescription)
SymName = getXCOFFSymbolDescription(createSymbolInfo(Obj, *SymI), SymName);
Result.append(SymName.begin(), SymName.end());
return Error::success();
}
@ -55,20 +64,25 @@ bool objdump::isLabel(const XCOFFObjectFile *Obj, const SymbolRef &Sym) {
return false;
}
void objdump::printXCOFFSymbolDescription(const SymbolInfoTy &SymbolInfo,
std::string objdump::getXCOFFSymbolDescription(const SymbolInfoTy &SymbolInfo,
StringRef SymbolName) {
assert(SymbolInfo.isXCOFF() && "Must be a XCOFFSymInfo.");
std::string Result;
// Dummy symbols have no symbol index.
if (SymbolInfo.XCOFFSymInfo.Index)
outs() << "(idx: " << SymbolInfo.XCOFFSymInfo.Index.getValue() << ") ";
outs() << SymbolName;
Result = ("(idx: " + Twine(SymbolInfo.XCOFFSymInfo.Index.getValue()) +
") " + SymbolName)
.str();
else
Result.append(SymbolName.begin(), SymbolName.end());
if (SymbolInfo.XCOFFSymInfo.StorageMappingClass &&
!SymbolInfo.XCOFFSymInfo.IsLabel) {
const XCOFF::StorageMappingClass Smc =
SymbolInfo.XCOFFSymInfo.StorageMappingClass.getValue();
outs() << "[" << XCOFF::getMappingClassString(Smc) << "]";
Result.append(("[" + XCOFF::getMappingClassString(Smc) + "]").str());
}
return Result;
}

View File

@ -22,7 +22,7 @@ getXCOFFSymbolCsectSMC(const object::XCOFFObjectFile *Obj,
bool isLabel(const object::XCOFFObjectFile *Obj, const object::SymbolRef &Sym);
void printXCOFFSymbolDescription(const SymbolInfoTy &SymbolInfo,
std::string getXCOFFSymbolDescription(const SymbolInfoTy &SymbolInfo,
StringRef SymbolName);
Error getXCOFFRelocationValueString(const object::XCOFFObjectFile *Obj,

View File

@ -131,8 +131,8 @@ static cl::alias DisassembleAllShort("D",
cl::NotHidden, cl::Grouping,
cl::aliasopt(DisassembleAll));
static cl::opt<bool>
SymbolDescription("symbol-description",
cl::opt<bool> objdump::SymbolDescription(
"symbol-description",
cl::desc("Add symbol description for disassembly. This "
"option is for XCOFF files only"),
cl::init(false), cl::cat(ObjdumpCat));
@ -1422,8 +1422,7 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
outs() << format(Is64Bits ? "%016" PRIx64 " " : "%08" PRIx64 " ",
SectionAddr + Start + VMAAdjustment);
if (Obj->isXCOFF() && SymbolDescription) {
printXCOFFSymbolDescription(Symbols[SI], SymbolName);
outs() << ":\n";
outs() << getXCOFFSymbolDescription(Symbols[SI], SymbolName) << ":\n";
} else
outs() << '<' << SymbolName << ">:\n";

View File

@ -10,6 +10,7 @@
#include "llvm/ADT/StringSet.h"
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/MC/MCDisassembler/MCDisassembler.h"
#include "llvm/Object/Archive.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
@ -43,6 +44,7 @@ extern cl::opt<bool> PrivateHeaders;
extern cl::opt<bool> Relocations;
extern cl::opt<bool> SectionHeaders;
extern cl::opt<bool> SectionContents;
extern cl::opt<bool> SymbolDescription;
extern cl::opt<bool> SymbolTable;
extern cl::opt<std::string> TripleName;
extern cl::opt<bool> UnwindInfo;
@ -151,6 +153,8 @@ T unwrapOrError(Expected<T> EO, Ts &&... Args) {
std::string getFileNameForError(const object::Archive::Child &C,
unsigned Index);
SymbolInfoTy createSymbolInfo(const object::ObjectFile *Obj,
const object::SymbolRef &Symbol);
} // end namespace llvm