llvm.org GIT mirror llvm / 92b052b
[llvm-objdump] - Demangle the symbols when printing symbol table and relocations. This is https://bugs.llvm.org/show_bug.cgi?id=40009, llvm-objdump does not demangle the symbols when prints symbol table and/or relocations. Patch teaches it to do that. Differential revision: https://reviews.llvm.org/D55821 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349613 91177308-0d34-0410-b5e6-96231b3b80d8 George Rimar 10 months ago
2 changed file(s) with 51 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
0 # RUN: llvm-mc %s -filetype=obj -triple=x86_64-pc-linux -o %t
1 # RUN: llvm-objdump -syms -reloc -demangle %t | FileCheck %s
2
3 ## Check we demangle symbols when printing relocations.
4 # CHECK: 000000000000001 R_X86_64_PLT32 foo()-4
5
6 ## Check we demangle symbols when printing symbol table.
7 # CHECK: SYMBOL TABLE:
8 # CHECK-NEXT: 0000000000000000 *UND* 00000000
9 # CHECK-NEXT: 0000000000000000 g F .text 00000000 foo()
10
11 ## Check the case when relocations are inlined into disassembly.
12 # RUN: llvm-objdump -d -r -demangle %t | FileCheck %s --check-prefix=INLINE
13 # INLINE: Disassembly of section .text:
14 # INLINE-NEXT: foo():
15 # INLINE-NEXT: 0: {{.*}} callq 0 <_Z3foov+0x5>
16 # INLINE-NEXT: 0000000000000001: R_X86_64_PLT32 foo()-4
17
18 .text
19 .globl _Z3foov
20 .type _Z3foov,@function
21 _Z3foov:
22 callq _Z3foov@PLT
503503 break;
504504 }
505505 }
506 StringRef Target;
506 std::string Target;
507507 if (!undef) {
508508 symbol_iterator SI = RelRef.getSymbol();
509509 const Elf_Sym *symb = Obj->getSymbol(SI->getRawDataRefImpl());
520520 Expected SymName = symb->getName(StrTab);
521521 if (!SymName)
522522 return errorToErrorCode(SymName.takeError());
523 Target = *SymName;
523 Target = Demangle ? demangle(*SymName) : *SymName;
524524 }
525525 } else
526526 Target = "*ABS*";
12791279 }
12801280 }
12811281
1282 static std::string demangle(StringRef Name) {
1283 char *Demangled = nullptr;
1284 size_t Size = 0;
1285 if (Name.startswith("_Z"))
1286 Demangled = itaniumDemangle(Name.data(), Demangled, &Size, nullptr);
1287 else if (Name.startswith("?"))
1288 Demangled = microsoftDemangle(Name.data(), Demangled, &Size, nullptr);
1289
1290 if (!Demangled)
1291 return Name;
1292
1293 std::string Ret = Demangled;
1294 free(Demangled);
1295 return Ret;
1296 }
1297
12821298 static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
12831299 if (StartAddress > StopAddress)
12841300 error("Start address should be less than stop address");
15721588 }
15731589 }
15741590
1575 auto PrintSymbol = [](StringRef Name) {
1576 outs() << '\n' << Name << ":\n";
1577 };
1591 outs() << '\n';
15781592 StringRef SymbolName = std::get<1>(Symbols[si]);
1579 if (Demangle) {
1580 char *DemangledSymbol = nullptr;
1581 size_t Size = 0;
1582 int Status = -1;
1583 if (SymbolName.startswith("_Z"))
1584 DemangledSymbol = itaniumDemangle(SymbolName.data(), DemangledSymbol,
1585 &Size, &Status);
1586 else if (SymbolName.startswith("?"))
1587 DemangledSymbol = microsoftDemangle(SymbolName.data(),
1588 DemangledSymbol, &Size, &Status);
1589
1590 if (Status == 0 && DemangledSymbol)
1591 PrintSymbol(StringRef(DemangledSymbol));
1592 else
1593 PrintSymbol(SymbolName);
1594
1595 if (DemangledSymbol)
1596 free(DemangledSymbol);
1597 } else
1598 PrintSymbol(SymbolName);
1593 if (Demangle)
1594 outs() << demangle(SymbolName) << ":\n";
1595 else
1596 outs() << SymbolName << ":\n";
15991597
16001598 // Don't print raw contents of a virtual section. A virtual section
16011599 // doesn't have any contents in the file.
20602058 if (Hidden) {
20612059 outs() << ".hidden ";
20622060 }
2063 outs() << Name
2064 << '\n';
2061
2062 if (Demangle)
2063 outs() << demangle(Name) << '\n';
2064 else
2065 outs() << Name << '\n';
20652066 }
20662067 }
20672068