[llvm-commits] [compiler-rt] r170666 - in /compiler-rt/trunk/lib: sanitizer_common/CMakeLists.txt sanitizer_common/sanitizer_symbolizer.h sanitizer_common/sanitizer_symbolizer_itanium.cc sanitizer_common/sanitizer_symbolizer_win.cc ubsan/ubsan_diag.cc

Richard Smith richard-llvm at metafoo.co.uk
Wed Dec 19 21:00:14 PST 2012


Author: rsmith
Date: Wed Dec 19 23:00:13 2012
New Revision: 170666

URL: http://llvm.org/viewvc/llvm-project?rev=170666&view=rev
Log:
Move C++ name demangling support from ubsan into sanitizer_common.

Added:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_itanium.cc
Modified:
    compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_win.cc
    compiler-rt/trunk/lib/ubsan/ubsan_diag.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt?rev=170666&r1=170665&r2=170666&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt Wed Dec 19 23:00:13 2012
@@ -13,6 +13,7 @@
   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

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h?rev=170666&r1=170665&r2=170666&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h Wed Dec 19 23:00:13 2012
@@ -60,6 +60,9 @@
 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);

Added: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_itanium.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_itanium.cc?rev=170666&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_itanium.cc (added)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_itanium.cc Wed Dec 19 23:00:13 2012
@@ -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__

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_win.cc?rev=170666&r1=170665&r2=170666&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_win.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_win.cc Wed Dec 19 23:00:13 2012
@@ -28,6 +28,10 @@
   UNIMPLEMENTED();
 };
 
+const char *Demangle(const char *MangledName) {
+  return MangledName;
+}
+
 }  // namespace __sanitizer
 
 #endif  // _WIN32

Modified: compiler-rt/trunk/lib/ubsan/ubsan_diag.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_diag.cc?rev=170666&r1=170665&r2=170666&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_diag.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_diag.cc Wed Dec 19 23:00:13 2012
@@ -91,15 +91,6 @@
   }
 }
 
-// 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 @@
         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;
       }





More information about the llvm-commits mailing list