1 //===-- sanitizer_symbolizer_itanium.cc -----------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file is shared between the sanitizer run-time libraries.
11 // Itanium C++ ABI-specific implementation of symbolizer parts.
12 //===----------------------------------------------------------------------===//
13
14 #include "sanitizer_platform.h"
15 #if SANITIZER_MAC || SANITIZER_LINUX
16
17 #include "sanitizer_symbolizer.h"
18
19 #include <stdlib.h>
20
21 // C++ demangling function, as required by Itanium C++ ABI. This is weak,
22 // because we do not require a C++ ABI library to be linked to a program
23 // using sanitizers; if it's not present, we'll just use the mangled name.
24 namespace __cxxabiv1 {
25 extern "C" char *__cxa_demangle(const char *mangled, char *buffer,
26 size_t *length, int *status)
27 SANITIZER_WEAK_ATTRIBUTE;
28 }
29
DemangleCXXABI(const char * name)30 const char *__sanitizer::DemangleCXXABI(const char *name) {
31 // FIXME: __cxa_demangle aggressively insists on allocating memory.
32 // There's not much we can do about that, short of providing our
33 // own demangler (libc++abi's implementation could be adapted so that
34 // it does not allocate). For now, we just call it anyway, and we leak
35 // the returned value.
36 if (__cxxabiv1::__cxa_demangle)
37 if (const char *demangled_name =
38 __cxxabiv1::__cxa_demangle(name, 0, 0, 0))
39 return demangled_name;
40
41 return name;
42 }
43
44 #endif // SANITIZER_MAC || SANITIZER_LINUX
45