summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-12-20 05:00:13 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-12-20 05:00:13 +0000
commit64e25ce53d6f533842271a593942258aadaca05b (patch)
tree93ecb9ff1dd76ec43bf4472a35a281e3e2f8e583
parentfd633229f70c19213a450d9d932982041b870aca (diff)
downloadbcm5719-llvm-64e25ce53d6f533842271a593942258aadaca05b.tar.gz
bcm5719-llvm-64e25ce53d6f533842271a593942258aadaca05b.zip
Move C++ name demangling support from ubsan into sanitizer_common.
llvm-svn: 170666
-rw-r--r--compiler-rt/lib/sanitizer_common/CMakeLists.txt1
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.h3
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_itanium.cc42
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_win.cc4
-rw-r--r--compiler-rt/lib/ubsan/ubsan_diag.cc19
5 files changed, 51 insertions, 18 deletions
diff --git a/compiler-rt/lib/sanitizer_common/CMakeLists.txt b/compiler-rt/lib/sanitizer_common/CMakeLists.txt
index f3461630b08..c9eff4db7ae 100644
--- a/compiler-rt/lib/sanitizer_common/CMakeLists.txt
+++ b/compiler-rt/lib/sanitizer_common/CMakeLists.txt
@@ -13,6 +13,7 @@ set(SANITIZER_SOURCES
sanitizer_stackdepot.cc
sanitizer_stacktrace.cc
sanitizer_symbolizer.cc
+ sanitizer_symbolizer_itanium.cc
sanitizer_symbolizer_linux.cc
sanitizer_symbolizer_mac.cc
sanitizer_symbolizer_win.cc
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.h b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.h
index 196e1080f07..abc84dfefc2 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.h
@@ -60,6 +60,9 @@ struct AddressInfo {
uptr SymbolizeCode(uptr address, AddressInfo *frames, uptr max_frames);
bool SymbolizeData(uptr address, AddressInfo *frame);
+// Attempts to demangle the provided C++ mangled name.
+const char *Demangle(const char *Name);
+
// Starts external symbolizer program in a subprocess. Sanitizer communicates
// with external symbolizer via pipes.
bool InitializeExternalSymbolizer(const char *path_to_symbolizer);
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_itanium.cc b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_itanium.cc
new file mode 100644
index 00000000000..8f71546a817
--- /dev/null
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_itanium.cc
@@ -0,0 +1,42 @@
+//===-- sanitizer_symbolizer_itanium.cc -----------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is shared between the sanitizer run-time libraries.
+// Itanium C++ ABI-specific implementation of symbolizer parts.
+//===----------------------------------------------------------------------===//
+#if defined(__APPLE__) || defined(__linux__)
+
+#include "sanitizer_symbolizer.h"
+
+#include <stdlib.h>
+
+// C++ demangling function, as required by Itanium C++ ABI. This is weak,
+// because we do not require a C++ ABI library to be linked to a program
+// using sanitizers; if it's not present, we'll just use the mangled name.
+namespace __cxxabiv1 {
+ extern "C" char *__cxa_demangle(const char *mangled, char *buffer,
+ size_t *length, int *status)
+ SANITIZER_WEAK_ATTRIBUTE;
+}
+
+const char *__sanitizer::Demangle(const char *MangledName) {
+ // FIXME: __cxa_demangle aggressively insists on allocating memory.
+ // There's not much we can do about that, short of providing our
+ // own demangler (libc++abi's implementation could be adapted so that
+ // it does not allocate). For now, we just call it anyway, and we leak
+ // the returned value.
+ if (__cxxabiv1::__cxa_demangle)
+ if (const char *Demangled =
+ __cxxabiv1::__cxa_demangle(MangledName, 0, 0, 0))
+ return Demangled;
+
+ return MangledName;
+}
+
+#endif // __APPLE__ || __linux__
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_win.cc b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_win.cc
index ad6c303ceb7..f1b6a02a6f9 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_win.cc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_win.cc
@@ -28,6 +28,10 @@ uptr GetListOfModules(LoadedModule *modules, uptr max_modules) {
UNIMPLEMENTED();
};
+const char *Demangle(const char *MangledName) {
+ return MangledName;
+}
+
} // namespace __sanitizer
#endif // _WIN32
diff --git a/compiler-rt/lib/ubsan/ubsan_diag.cc b/compiler-rt/lib/ubsan/ubsan_diag.cc
index a726f4b55d9..8a31494a495 100644
--- a/compiler-rt/lib/ubsan/ubsan_diag.cc
+++ b/compiler-rt/lib/ubsan/ubsan_diag.cc
@@ -91,15 +91,6 @@ static void renderLocation(Location Loc) {
}
}
-// C++ demangling function, as required by Itanium C++ ABI. This is weak,
-// because we do not require a C++ ABI library to be linked to a program
-// using UBSan; if it's not present, we'll just print the string mangled.
-namespace __cxxabiv1 {
- extern "C" char *__cxa_demangle(const char *mangled, char *buffer,
- size_t *length, int *status)
- __attribute__((weak));
-}
-
static void renderText(const char *Message, const Diag::Arg *Args) {
for (const char *Msg = Message; *Msg; ++Msg) {
if (*Msg != '%') {
@@ -117,16 +108,8 @@ static void renderText(const char *Message, const Diag::Arg *Args) {
Printf("%s", A.String);
break;
case Diag::AK_Mangled: {
- const char *String = 0;
- // FIXME: __cxa_demangle aggressively insists on allocating memory.
- // There's not much we can do about that, short of providing our
- // own demangler (libc++abi's implementation could easily be made
- // to not allocate). For now, we just call it anyway, and we leak
- // the returned value.
- if (__cxxabiv1::__cxa_demangle)
- String = __cxxabiv1::__cxa_demangle(A.String, 0, 0, 0);
RawWrite("'");
- RawWrite(String ? String : A.String);
+ RawWrite(Demangle(A.String));
RawWrite("'");
break;
}
OpenPOWER on IntegriCloud