aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2016-09-06 19:16:48 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2016-09-06 19:16:48 +0000
commitb940b66c6032096d40dfd1859e2598749a30378c (patch)
tree8bbfb87f1e7b0e4584ca5d6b4096e13827addaf9 /llvm/tools
parent34ecf42bffe57ed1f4c45ac1ff0a3be2d5ed0dd1 (diff)
downloadllvm-b940b66c6032096d40dfd1859e2598749a30378c.zip
llvm-b940b66c6032096d40dfd1859e2598749a30378c.tar.gz
llvm-b940b66c6032096d40dfd1859e2598749a30378c.tar.bz2
Add an c++ itanium demangler to llvm.
This adds a copy of the demangler in libcxxabi. The code also has no dependencies on anything else in LLVM. To enforce that I added it as another library. That way a BUILD_SHARED_LIBS will fail if anyone adds an use of StringRef for example. The no llvm dependency combined with the fact that this has to build on linux, OS X and Windows required a few changes to the code. In particular: No constexpr. No alignas On OS X at least this library has only one global symbol: __ZN4llvm16itanium_demangleEPKcPcPmPi My current plan is: Commit something like this Change lld to use it Change lldb to use it as the fallback Add a few #ifdefs so that exactly the same file can be used in libcxxabi to export abi::__cxa_demangle. Once the fast demangler in lldb can handle any names this implementation can be replaced with it and we will have the one true demangler. llvm-svn: 280732
Diffstat (limited to 'llvm/tools')
-rw-r--r--llvm/tools/llvm-cxxfilt/CMakeLists.txt7
-rw-r--r--llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp29
-rw-r--r--llvm/tools/llvm-objdump/CMakeLists.txt1
-rw-r--r--llvm/tools/llvm-objdump/LLVMBuild.txt2
-rw-r--r--llvm/tools/llvm-objdump/MachODump.cpp21
5 files changed, 43 insertions, 17 deletions
diff --git a/llvm/tools/llvm-cxxfilt/CMakeLists.txt b/llvm/tools/llvm-cxxfilt/CMakeLists.txt
new file mode 100644
index 0000000..4d0e5b0
--- /dev/null
+++ b/llvm/tools/llvm-cxxfilt/CMakeLists.txt
@@ -0,0 +1,7 @@
+set(LLVM_LINK_COMPONENTS
+ Demangle
+ )
+
+add_llvm_tool(llvm-cxxfilt
+ llvm-cxxfilt.cpp
+ )
diff --git a/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp b/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
new file mode 100644
index 0000000..d2c1ba3
--- /dev/null
+++ b/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
@@ -0,0 +1,29 @@
+//===-- llvm-c++filt.cpp --------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Demangle/Demangle.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+using namespace llvm;
+
+int main(int argc, char **argv) {
+ for (int I = 1; I < argc; ++I) {
+ const char *Mangled = argv[I];
+ int Status;
+ char *Demangled = itaniumDemangle(Mangled, nullptr, nullptr, &Status);
+ if (Demangled)
+ printf("%s\n", Demangled);
+ else
+ printf("%s\n", Mangled);
+ free(Demangled);
+ }
+ return 0;
+}
diff --git a/llvm/tools/llvm-objdump/CMakeLists.txt b/llvm/tools/llvm-objdump/CMakeLists.txt
index 73868d8..f1239a2 100644
--- a/llvm/tools/llvm-objdump/CMakeLists.txt
+++ b/llvm/tools/llvm-objdump/CMakeLists.txt
@@ -6,6 +6,7 @@ set(LLVM_LINK_COMPONENTS
CodeGen
DebugInfoDWARF
DebugInfoPDB
+ Demangle
MC
MCDisassembler
Object
diff --git a/llvm/tools/llvm-objdump/LLVMBuild.txt b/llvm/tools/llvm-objdump/LLVMBuild.txt
index 4232873..3a96691 100644
--- a/llvm/tools/llvm-objdump/LLVMBuild.txt
+++ b/llvm/tools/llvm-objdump/LLVMBuild.txt
@@ -19,4 +19,4 @@
type = Tool
name = llvm-objdump
parent = Tools
-required_libraries = DebugInfoDWARF MC MCDisassembler MCParser Object all-targets
+required_libraries = DebugInfoDWARF MC MCDisassembler MCParser Object all-targets Demangle
diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp
index 9782659..2e7a3b2 100644
--- a/llvm/tools/llvm-objdump/MachODump.cpp
+++ b/llvm/tools/llvm-objdump/MachODump.cpp
@@ -20,6 +20,7 @@
#include "llvm/Config/config.h"
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
+#include "llvm/Demangle/Demangle.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDisassembler/MCDisassembler.h"
@@ -48,10 +49,6 @@
#include <cstring>
#include <system_error>
-#if HAVE_CXXABI_H
-#include <cxxabi.h>
-#endif
-
#ifdef HAVE_LIBXAR
extern "C" {
#include <xar/xar.h>
@@ -6235,11 +6232,9 @@ static const char *GuessLiteralPointer(uint64_t ReferenceValue,
// Out type and the ReferenceName will also be set which is added as a comment
// to the disassembled instruction.
//
-#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
@@ -6274,21 +6269,18 @@ static const char *SymbolizerSymbolLookUp(void *DisInfo,
method_reference(info, ReferenceType, ReferenceName);
if (*ReferenceType != LLVMDisassembler_ReferenceType_Out_Objc_Message)
*ReferenceType = LLVMDisassembler_ReferenceType_Out_SymbolStub;
- } else
-#if HAVE_CXXABI_H
- if (SymbolName != nullptr && strncmp(SymbolName, "__Z", 3) == 0) {
+ } 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);
+ itaniumDemangle(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 =
@@ -6377,20 +6369,17 @@ static const char *SymbolizerSymbolLookUp(void *DisInfo,
GuessLiteralPointer(ReferenceValue, ReferencePC, ReferenceType, info);
if (*ReferenceName == nullptr)
*ReferenceType = LLVMDisassembler_ReferenceType_InOut_None;
- }
-#if HAVE_CXXABI_H
- else if (SymbolName != nullptr && strncmp(SymbolName, "__Z", 3) == 0) {
+ } 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);
+ itaniumDemangle(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;