Use abi::__cxa_demangle declared in cxxabi.h

Bug: http://b/175635923
Test: treehugger
Change-Id: Ia191be0b4861b011640edc703b55c13c88bce300
diff --git a/libc/malloc_debug/PointerData.cpp b/libc/malloc_debug/PointerData.cpp
index 5ab2232..e3a35a6 100644
--- a/libc/malloc_debug/PointerData.cpp
+++ b/libc/malloc_debug/PointerData.cpp
@@ -26,6 +26,7 @@
  * SUCH DAMAGE.
  */
 
+#include <cxxabi.h>
 #include <errno.h>
 #include <inttypes.h>
 #include <signal.h>
@@ -54,8 +55,6 @@
 #include "malloc_debug.h"
 #include "UnwindBacktrace.h"
 
-extern "C" char* __cxa_demangle(const char*, char*, size_t*, int*);
-
 std::atomic_uint8_t PointerData::backtrace_enabled_;
 std::atomic_bool PointerData::backtrace_dump_;
 
@@ -617,8 +616,8 @@
         if (frame.function_name.empty()) {
           dprintf(fd, " \"\" 0}");
         } else {
-          char* demangled_name = __cxa_demangle(frame.function_name.c_str(), nullptr, nullptr,
-                                                nullptr);
+          char* demangled_name =
+              abi::__cxa_demangle(frame.function_name.c_str(), nullptr, nullptr, nullptr);
           const char* name;
           if (demangled_name != nullptr) {
             name = demangled_name;
diff --git a/libc/malloc_debug/UnwindBacktrace.cpp b/libc/malloc_debug/UnwindBacktrace.cpp
index c892a39..8a6ff7b 100644
--- a/libc/malloc_debug/UnwindBacktrace.cpp
+++ b/libc/malloc_debug/UnwindBacktrace.cpp
@@ -26,6 +26,7 @@
  * SUCH DAMAGE.
  */
 
+#include <cxxabi.h>
 #include <inttypes.h>
 #include <pthread.h>
 #include <stdint.h>
@@ -48,8 +49,6 @@
 #define PAD_PTR "08" PRIx64
 #endif
 
-extern "C" char* __cxa_demangle(const char*, char*, size_t*, int*);
-
 bool Unwind(std::vector<uintptr_t>* frames, std::vector<unwindstack::FrameData>* frame_info,
             size_t max_frames) {
   [[clang::no_destroy]] static unwindstack::AndroidLocalUnwinder unwinder(
@@ -89,7 +88,8 @@
 
     if (!info->function_name.empty()) {
       line += " (";
-      char* demangled_name = __cxa_demangle(info->function_name.c_str(), nullptr, nullptr, nullptr);
+      char* demangled_name =
+          abi::__cxa_demangle(info->function_name.c_str(), nullptr, nullptr, nullptr);
       if (demangled_name != nullptr) {
         line += demangled_name;
         free(demangled_name);
diff --git a/libc/malloc_debug/backtrace.cpp b/libc/malloc_debug/backtrace.cpp
index 0649571..ecb3a80 100644
--- a/libc/malloc_debug/backtrace.cpp
+++ b/libc/malloc_debug/backtrace.cpp
@@ -26,6 +26,7 @@
  * SUCH DAMAGE.
  */
 
+#include <cxxabi.h>
 #include <dlfcn.h>
 #include <errno.h>
 #include <inttypes.h>
@@ -48,8 +49,6 @@
 
 typedef struct _Unwind_Context __unwind_context;
 
-extern "C" char* __cxa_demangle(const char*, char*, size_t*, int*);
-
 static MapData g_map_data;
 static const MapEntry* g_current_code_map = nullptr;
 
@@ -145,7 +144,7 @@
 
     char buf[1024];
     if (symbol != nullptr) {
-      char* demangled_name = __cxa_demangle(symbol, nullptr, nullptr, nullptr);
+      char* demangled_name = abi::__cxa_demangle(symbol, nullptr, nullptr, nullptr);
       const char* name;
       if (demangled_name != nullptr) {
         name = demangled_name;