Index: llvm/test/tools/llvm-objdump/XCOFF/disassemble-symbol-description.test =================================================================== --- llvm/test/tools/llvm-objdump/XCOFF/disassemble-symbol-description.test +++ 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 @@ 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 @@ -37,22 +41,29 @@ PLAIN: 00000080 : DESC: 00000080 (idx: 22) func[TC]: COMMON-NEXT: 80: 00 00 00 94 +RELOC: 00000080: R_POS (idx: 20) func[DS] PLAIN: 00000084 : DESC: 00000084 (idx: 26) a[TC]: COMMON-NEXT: 84: 00 00 00 a4 +RELOC: 00000084: R_POS (idx: 24) a[RW] PLAIN: 00000088 : DESC: 00000088 (idx: 30) b[TC]: COMMON-NEXT: 88: 00 00 00 a0 +RELOC: 00000088: R_POS (idx: 28) b[RW] PLAIN: 0000008c : DESC: 0000008c (idx: 34) c[TC]: COMMON-NEXT: 8c: 00 00 00 08 +RELOC: 0000008c: R_TLS (idx: 32) c[UL] PLAIN: 00000090 : DESC: 00000090 (idx: 38) d[TC]: COMMON-NEXT: 90: 00 00 00 00 +RELOC: 00000090: R_TLS (idx: 36) d[TL] PLAIN: 00000094 : DESC: 00000094 (idx: 20) func[DS]: COMMON-NEXT: 94: 00 00 00 00 +RELOC: 00000094: R_POS (idx: 16) .func COMMON-NEXT: 98: 00 00 00 80 +RELOC: 00000098: R_POS (idx: 18) TOC[TC0] COMMON-NEXT: 9c: 00 00 00 00 PLAIN: 000000a0 : DESC: 000000a0 (idx: 28) b[RW]: Index: llvm/test/tools/llvm-objdump/XCOFF/print-reloc.test =================================================================== --- llvm/test/tools/llvm-objdump/XCOFF/print-reloc.test +++ 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-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: Index: llvm/tools/llvm-objdump/XCOFFDump.h =================================================================== --- llvm/tools/llvm-objdump/XCOFFDump.h +++ llvm/tools/llvm-objdump/XCOFFDump.h @@ -22,8 +22,8 @@ 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, Index: llvm/tools/llvm-objdump/XCOFFDump.cpp =================================================================== --- llvm/tools/llvm-objdump/XCOFFDump.cpp +++ llvm/tools/llvm-objdump/XCOFFDump.cpp @@ -12,6 +12,9 @@ //===----------------------------------------------------------------------===// #include "XCOFFDump.h" + +#include "llvm-objdump.h" +#include "llvm/Demangle/Demangle.h" #include "llvm/MC/MCDisassembler/MCDisassembler.h" using namespace llvm; @@ -29,7 +32,14 @@ Expected SymNameOrErr = SymI->getName(); if (!SymNameOrErr) return SymNameOrErr.takeError(); - StringRef SymName = *SymNameOrErr; + + std::string SymName = (*SymNameOrErr).str(); + if (Demangle) + SymName = demangle(std::string(SymName)); + + if (SymbolDescription) + SymName = getXCOFFSymbolDescription(createSymbolInfo(Obj, *SymI), SymName); + Result.append(SymName.begin(), SymName.end()); return Error::success(); } @@ -55,20 +65,26 @@ 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() << ") "; + Result = std::string("(idx: ") + + std::to_string(SymbolInfo.XCOFFSymInfo.Index.getValue()) + + std::string(") "); - outs() << SymbolName; + Result.append(SymbolName.str()); if (SymbolInfo.XCOFFSymInfo.StorageMappingClass && !SymbolInfo.XCOFFSymInfo.IsLabel) { const XCOFF::StorageMappingClass Smc = SymbolInfo.XCOFFSymInfo.StorageMappingClass.getValue(); - outs() << "[" << XCOFF::getMappingClassString(Smc) << "]"; + Result.append(std::string("[") + + std::string(XCOFF::getMappingClassString(Smc)) + + std::string("]")); } + + return Result; } Index: llvm/tools/llvm-objdump/llvm-objdump.h =================================================================== --- llvm/tools/llvm-objdump/llvm-objdump.h +++ 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 Relocations; extern cl::opt SectionHeaders; extern cl::opt SectionContents; +extern cl::opt SymbolDescription; extern cl::opt SymbolTable; extern cl::opt TripleName; extern cl::opt UnwindInfo; @@ -151,6 +153,8 @@ std::string getFileNameForError(const object::Archive::Child &C, unsigned Index); +SymbolInfoTy createSymbolInfo(const object::ObjectFile *Obj, + const object::SymbolRef &Symbol); } // end namespace llvm Index: llvm/tools/llvm-objdump/llvm-objdump.cpp =================================================================== --- llvm/tools/llvm-objdump/llvm-objdump.cpp +++ llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -131,11 +131,11 @@ cl::NotHidden, cl::Grouping, cl::aliasopt(DisassembleAll)); -static cl::opt - 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 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 DisassembleSymbols("disassemble-symbols", cl::CommaSeparated, @@ -1417,8 +1417,7 @@ 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";