Move the demangler into its own library.
am: 8144d214ae

Change-Id: Iaa23e6a09a8a228294e36105f6d2b587549138ec
diff --git a/Android.bp b/Android.bp
index 157963d..cb14814 100644
--- a/Android.bp
+++ b/Android.bp
@@ -14,12 +14,44 @@
 // limitations under the License.
 //
 
-cc_library_static {
-    name: "libc++abi",
-    host_supported: true,
+cc_defaults {
+    name: "libc++abi_defaults",
     vendor_available: true,
     recovery_available: true,
     native_bridge_supported: true,
+    include_dirs: ["external/libcxx/include"],
+    local_include_dirs:  ["include"],
+    export_include_dirs: ["include"],
+    cflags: [
+        "-Wall",
+        "-Werror",
+    ],
+    cppflags: [
+        "-std=c++14",
+        "-fexceptions",
+        "-Wextra",
+        "-Wno-unused-function",
+        "-Wno-implicit-fallthrough",
+        // src/cxa_demangle.cpp:2591 -Wimplicit-fallthrough
+    ],
+    sanitize: {
+        never: true,
+    },
+    stl: "none",
+    rtti: true,
+}
+
+cc_library_static {
+    name: "libc++demangle",
+    defaults: ["libc++abi_defaults"],
+    host_supported: false,
+    srcs: ["src/cxa_demangle.cpp"],
+}
+
+cc_library_static {
+    name: "libc++abi",
+    defaults: ["libc++abi_defaults"],
+    host_supported: true,
     srcs: [
         "src/abort_message.cpp",
         "src/cxa_aux_runtime.cpp",
@@ -41,26 +73,6 @@
         "src/stdlib_stdexcept.cpp",
         "src/stdlib_typeinfo.cpp",
     ],
-    include_dirs: ["external/libcxx/include"],
-    local_include_dirs:  ["include"],
-    export_include_dirs: ["include"],
-    cflags: [
-        "-Wall",
-        "-Werror",
-    ],
-    cppflags: [
-        "-std=c++14",
-        "-fexceptions",
-        "-Wextra",
-        "-Wno-unused-function",
-        "-Wno-implicit-fallthrough",
-        // src/cxa_demangle.cpp:2591 -Wimplicit-fallthrough
-    ],
-    sanitize: {
-        never: true,
-    },
-    stl: "none",
-    rtti: true,
     arch: {
         arm: {
             include_dirs: ["external/libunwind_llvm/include"],
@@ -85,6 +97,8 @@
     target: {
         android: {
             cppflags: ["-DHAVE___CXA_THREAD_ATEXIT_IMPL"],
+            // Packaged in libc++demangle for Android to reduce bloat.
+            exclude_srcs: ["src/cxa_demangle.cpp"],
         },
         darwin: {
             // libcxxabi really doesn't like the non-LLVM assembler on Darwin
@@ -121,5 +135,4 @@
             ],
         }
     },
-
 }
diff --git a/src/cxa_default_handlers.cpp b/src/cxa_default_handlers.cpp
index f00e959..3dbde8d 100644
--- a/src/cxa_default_handlers.cpp
+++ b/src/cxa_default_handlers.cpp
@@ -45,6 +45,7 @@
                         exception_header + 1;
                 const __shim_type_info* thrown_type =
                     static_cast<const __shim_type_info*>(exception_header->exceptionType);
+#if !defined(__ANDROID__)
                 // Try to get demangled name of thrown_type
                 int status;
                 char buf[1024];
@@ -52,6 +53,9 @@
                 const char* name = __cxa_demangle(thrown_type->name(), buf, &len, &status);
                 if (status != 0)
                     name = thrown_type->name();
+#else
+                const char* name = thrown_type->name();
+#endif
                 // If the uncaught exception can be caught with std::exception&
                 const __shim_type_info* catch_type =
 				 static_cast<const __shim_type_info*>(&typeid(std::exception));