[llvm] bcca6ae - [llvm-objdump][XCOFF] Print more symbol info in relocation
via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 22 06:52:24 PDT 2020
Author: jasonliu
Date: 2020-04-22T13:52:08Z
New Revision: bcca6ae3cd6d8b259d428767fed3b13eca3db67c
URL: https://github.com/llvm/llvm-project/commit/bcca6ae3cd6d8b259d428767fed3b13eca3db67c
DIFF: https://github.com/llvm/llvm-project/commit/bcca6ae3cd6d8b259d428767fed3b13eca3db67c.diff
LOG: [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
Added:
Modified:
llvm/test/tools/llvm-objdump/XCOFF/disassemble-symbol-description.test
llvm/test/tools/llvm-objdump/XCOFF/print-reloc.test
llvm/tools/llvm-objdump/XCOFFDump.cpp
llvm/tools/llvm-objdump/XCOFFDump.h
llvm/tools/llvm-objdump/llvm-objdump.cpp
llvm/tools/llvm-objdump/llvm-objdump.h
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-objdump/XCOFF/disassemble-symbol-description.test b/llvm/test/tools/llvm-objdump/XCOFF/disassemble-symbol-description.test
index 5fb74b61180e..c92772b8cbad 100644
--- a/llvm/test/tools/llvm-objdump/XCOFF/disassemble-symbol-description.test
+++ b/llvm/test/tools/llvm-objdump/XCOFF/disassemble-symbol-description.test
@@ -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]:
diff --git a/llvm/test/tools/llvm-objdump/XCOFF/print-reloc.test b/llvm/test/tools/llvm-objdump/XCOFF/print-reloc.test
index ee821360e5cb..2ddf97cbbb25 100644
--- a/llvm/test/tools/llvm-objdump/XCOFF/print-reloc.test
+++ b/llvm/test/tools/llvm-objdump/XCOFF/print-reloc.test
@@ -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:
diff --git a/llvm/tools/llvm-objdump/XCOFFDump.cpp b/llvm/tools/llvm-objdump/XCOFFDump.cpp
index eedb8daa5f37..df37abbd3881 100644
--- a/llvm/tools/llvm-objdump/XCOFFDump.cpp
+++ b/llvm/tools/llvm-objdump/XCOFFDump.cpp
@@ -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,
- StringRef SymbolName) {
+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;
}
diff --git a/llvm/tools/llvm-objdump/XCOFFDump.h b/llvm/tools/llvm-objdump/XCOFFDump.h
index f4b64e7dec41..dbf520021594 100644
--- a/llvm/tools/llvm-objdump/XCOFFDump.h
+++ b/llvm/tools/llvm-objdump/XCOFFDump.h
@@ -22,8 +22,8 @@ getXCOFFSymbolCsectSMC(const object::XCOFFObjectFile *Obj,
bool isLabel(const object::XCOFFObjectFile *Obj, const object::SymbolRef &Sym);
-void printXCOFFSymbolDescription(const SymbolInfoTy &SymbolInfo,
- StringRef SymbolName);
+std::string getXCOFFSymbolDescription(const SymbolInfoTy &SymbolInfo,
+ StringRef SymbolName);
Error getXCOFFRelocationValueString(const object::XCOFFObjectFile *Obj,
const object::RelocationRef &RelRef,
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 4ce8f691acbc..92c130be113a 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -131,11 +131,11 @@ static cl::alias DisassembleAllShort("D",
cl::NotHidden, cl::Grouping,
cl::aliasopt(DisassembleAll));
-static cl::opt<bool>
- SymbolDescription("symbol-description",
- cl::desc("Add symbol description for disassembly. This "
- "option is for XCOFF files only"),
- cl::init(false), cl::cat(ObjdumpCat));
+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));
static cl::list<std::string>
DisassembleSymbols("disassemble-symbols", cl::CommaSeparated,
@@ -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";
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.h b/llvm/tools/llvm-objdump/llvm-objdump.h
index 18fd9032c0d5..360ff09f1379 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.h
+++ b/llvm/tools/llvm-objdump/llvm-objdump.h
@@ -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
More information about the llvm-commits
mailing list