summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
Diffstat (limited to 'llvm')
-rwxr-xr-xllvm/test/tools/llvm-objdump/X86/Inputs/hello_cpp.exe.macho-x86_64bin0 -> 15100 bytes
-rw-r--r--llvm/test/tools/llvm-objdump/X86/macho-symbolized-disassembly.test3
-rw-r--r--llvm/tools/llvm-objdump/MachODump.cpp47
3 files changed, 44 insertions, 6 deletions
diff --git a/llvm/test/tools/llvm-objdump/X86/Inputs/hello_cpp.exe.macho-x86_64 b/llvm/test/tools/llvm-objdump/X86/Inputs/hello_cpp.exe.macho-x86_64
new file mode 100755
index 00000000000..6b54b15c0c5
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/X86/Inputs/hello_cpp.exe.macho-x86_64
Binary files differ
diff --git a/llvm/test/tools/llvm-objdump/X86/macho-symbolized-disassembly.test b/llvm/test/tools/llvm-objdump/X86/macho-symbolized-disassembly.test
index c8322bc7df6..e33d3b56073 100644
--- a/llvm/test/tools/llvm-objdump/X86/macho-symbolized-disassembly.test
+++ b/llvm/test/tools/llvm-objdump/X86/macho-symbolized-disassembly.test
@@ -2,6 +2,7 @@
// RUN: llvm-objdump -d -m -no-show-raw-insn -full-leading-addr -print-imm-hex %p/Inputs/hello.exe.macho-x86_64 | FileCheck %s -check-prefix=EXE
// RUN: llvm-objdump -d -m -no-show-raw-insn -full-leading-addr -print-imm-hex %p/Inputs/ObjC.obj.macho-x86_64 | FileCheck %s -check-prefix=ObjC-OBJ
// RUN: llvm-objdump -d -m -no-show-raw-insn -full-leading-addr -print-imm-hex %p/Inputs/ObjC.exe.macho-x86_64 | FileCheck %s -check-prefix=ObjC-EXE
+// RUN: llvm-objdump -d -m -no-show-raw-insn -full-leading-addr -print-imm-hex %p/Inputs/hello_cpp.exe.macho-x86_64 | FileCheck %s -check-prefix=CXX-EXE
OBJ: 0000000000000008 leaq L_.str(%rip), %rax ## literal pool for: "Hello world\n"
OBJ: 0000000000000026 callq _printf
@@ -23,3 +24,5 @@ ObjC-EXE: 0000000100000f14 movq 0x125(%rip), %rax ## Objc class ref: _OBJC
ObjC-EXE: 0000000100000f1b movq 0x10e(%rip), %rsi ## Objc selector ref: date
ObjC-EXE: 0000000100000f25 callq 0x100000f4a ## Objc message: +[NSDate date]
ObjC-EXE: 0000000100000f33 callq 0x100000f44 ## symbol stub for: _NSLog
+
+CXX-EXE: 00000001000014cb callq __ZNSt3__116__pad_and_outputIcNS_11char_traitsIcEEEENS_19ostreambuf_iteratorIT_T0_EES6_PKS4_S8_S8_RNS_8ios_baseES4_ ## std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > std::__1::__pad_and_output<char, std::__1::char_traits<char> >(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> >, char const*, char const*, char const*, std::__1::ios_base&, char)
diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp
index 9c3dfec92e4..7d7eb80569c 100644
--- a/llvm/tools/llvm-objdump/MachODump.cpp
+++ b/llvm/tools/llvm-objdump/MachODump.cpp
@@ -16,6 +16,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/Triple.h"
+#include "llvm/Config/config.h"
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
@@ -43,6 +44,11 @@
#include <algorithm>
#include <cstring>
#include <system_error>
+
+#if HAVE_CXXABI_H
+#include <cxxabi.h>
+#endif
+
using namespace llvm;
using namespace object;
@@ -249,6 +255,7 @@ struct DisassembleInfo {
const char *class_name;
const char *selector_name;
char *method;
+ char *demangled_name;
BindTable *bindtable;
};
@@ -1045,9 +1052,11 @@ const char *GuessLiteralPointer(uint64_t ReferenceValue, uint64_t ReferencePC,
// Out type and the ReferenceName will also be set which is added as a comment
// to the disassembled instruction.
//
-// TODO: If the symbol name is a C++ mangled name then the demangled name is
+#if HAVE_CXXABI_H
+// If the symbol name is a C++ mangled name then the demangled name is
// returned through ReferenceName and ReferenceType is set to
// LLVMDisassembler_ReferenceType_DeMangled_Name .
+#endif
//
// When this is called to get a symbol name for a branch target then the
// ReferenceType will be LLVMDisassembler_ReferenceType_In_Branch and then
@@ -1083,13 +1092,25 @@ const char *SymbolizerSymbolLookUp(void *DisInfo, uint64_t ReferenceValue,
if (*ReferenceType == LLVMDisassembler_ReferenceType_In_Branch) {
*ReferenceName = GuessIndirectSymbol(ReferenceValue, info);
- if (*ReferenceName) {
+ if (*ReferenceName != nullptr) {
method_reference(info, ReferenceType, ReferenceName);
if (*ReferenceType != LLVMDisassembler_ReferenceType_Out_Objc_Message)
*ReferenceType = LLVMDisassembler_ReferenceType_Out_SymbolStub;
} else
- // TODO: if SymbolName is not nullptr see if it is a C++ name
- // and demangle it.
+#if HAVE_CXXABI_H
+ if (SymbolName != nullptr && strncmp(SymbolName, "__Z", 3) == 0) {
+ if (info->demangled_name != nullptr)
+ free(info->demangled_name);
+ int status;
+ info->demangled_name = abi::__cxa_demangle(SymbolName + 1, nullptr,
+ nullptr, &status);
+ if (info->demangled_name != nullptr) {
+ *ReferenceName = info->demangled_name;
+ *ReferenceType = LLVMDisassembler_ReferenceType_DeMangled_Name;
+ } else
+ *ReferenceType = LLVMDisassembler_ReferenceType_InOut_None;
+ } else
+#endif
*ReferenceType = LLVMDisassembler_ReferenceType_InOut_None;
} else if (*ReferenceType == LLVMDisassembler_ReferenceType_In_PCrel_Load) {
*ReferenceName =
@@ -1099,8 +1120,19 @@ const char *SymbolizerSymbolLookUp(void *DisInfo, uint64_t ReferenceValue,
else
*ReferenceType = LLVMDisassembler_ReferenceType_InOut_None;
}
- // TODO: if SymbolName is not nullptr see if it is a C++ name
- // and demangle it.
+#if HAVE_CXXABI_H
+ else if (SymbolName != nullptr && strncmp(SymbolName, "__Z", 3) == 0) {
+ if (info->demangled_name != nullptr)
+ free(info->demangled_name);
+ int status;
+ info->demangled_name = abi::__cxa_demangle(SymbolName + 1, nullptr, nullptr,
+ &status);
+ if (info->demangled_name != nullptr) {
+ *ReferenceName = info->demangled_name;
+ *ReferenceType = LLVMDisassembler_ReferenceType_DeMangled_Name;
+ }
+ }
+#endif
else {
*ReferenceName = nullptr;
*ReferenceType = LLVMDisassembler_ReferenceType_InOut_None;
@@ -1392,6 +1424,7 @@ static void DisassembleInputMachO2(StringRef Filename,
SymbolizerInfo.class_name = nullptr;
SymbolizerInfo.selector_name = nullptr;
SymbolizerInfo.method = nullptr;
+ SymbolizerInfo.demangled_name = nullptr;
SymbolizerInfo.bindtable = nullptr;
// Disassemble symbol by symbol.
@@ -1569,6 +1602,8 @@ static void DisassembleInputMachO2(StringRef Filename,
}
if (SymbolizerInfo.method != nullptr)
free(SymbolizerInfo.method);
+ if (SymbolizerInfo.demangled_name != nullptr)
+ free(SymbolizerInfo.demangled_name);
if (SymbolizerInfo.bindtable != nullptr)
delete SymbolizerInfo.bindtable;
}
OpenPOWER on IntegriCloud