diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-12-20 05:00:13 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-12-20 05:00:13 +0000 |
commit | ab6374326389ff649ad857842b45488721c949db (patch) | |
tree | 301580aa6f0f44d40e0392f5a8afc087d8a47b36 | |
parent | c47a45154543b5eba68c9473d3ed807927027cf3 (diff) | |
download | compiler-rt-ab6374326389ff649ad857842b45488721c949db.tar.gz compiler-rt-ab6374326389ff649ad857842b45488721c949db.tar.bz2 compiler-rt-ab6374326389ff649ad857842b45488721c949db.tar.xz |
Move C++ name demangling support from ubsan into sanitizer_common.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@170666 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/sanitizer_common/CMakeLists.txt | 1 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_symbolizer.h | 3 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_symbolizer_itanium.cc | 42 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_symbolizer_win.cc | 4 | ||||
-rw-r--r-- | lib/ubsan/ubsan_diag.cc | 19 |
5 files changed, 51 insertions, 18 deletions
diff --git a/lib/sanitizer_common/CMakeLists.txt b/lib/sanitizer_common/CMakeLists.txt index f3461630..c9eff4db 100644 --- a/lib/sanitizer_common/CMakeLists.txt +++ b/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/lib/sanitizer_common/sanitizer_symbolizer.h b/lib/sanitizer_common/sanitizer_symbolizer.h index 196e1080..abc84dfe 100644 --- a/lib/sanitizer_common/sanitizer_symbolizer.h +++ b/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/lib/sanitizer_common/sanitizer_symbolizer_itanium.cc b/lib/sanitizer_common/sanitizer_symbolizer_itanium.cc new file mode 100644 index 00000000..8f71546a --- /dev/null +++ b/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/lib/sanitizer_common/sanitizer_symbolizer_win.cc b/lib/sanitizer_common/sanitizer_symbolizer_win.cc index ad6c303c..f1b6a02a 100644 --- a/lib/sanitizer_common/sanitizer_symbolizer_win.cc +++ b/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/lib/ubsan/ubsan_diag.cc b/lib/ubsan/ubsan_diag.cc index a726f4b5..8a31494a 100644 --- a/lib/ubsan/ubsan_diag.cc +++ b/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; } |