Merge "[GWP-ASan] Merge crash handler -> Android.bp"
am: f77bffd7de

Change-Id: Ic00f5aae5283f6289344884f5bd14d8752da3f73
diff --git a/Android.bp b/Android.bp
index d62ae86..4507363 100644
--- a/Android.bp
+++ b/Android.bp
@@ -22,17 +22,6 @@
     native_bridge_supported: true,
     ramdisk_available: true,
 
-    // GWP-ASan is used by bionic libc, and should have no libc/libc++
-    // dependencies.
-    system_shared_libs: [],
-    stl: "none",
-
-    // GWP-ASan requires platform (non-emulated) TLS. We use thread local
-    // variables in the core, inlined interface to GWP-ASan.
-    cflags: [
-        "-fno-emulated-tls",
-    ],
-
     // GWP-ASan currently has no support for darwin.
     target: {
         darwin: {
@@ -41,9 +30,22 @@
     },
 }
 
+cc_defaults {
+    name: "gwp_asan_no_libs_defaults",
+    defaults: ["gwp_asan_defaults"],
+
+    // GWP-ASan is used by bionic libc, and should have no libc/libc++
+    // dependencies.
+    system_shared_libs: [],
+    stl: "none",
+}
+
 cc_library_headers {
     name: "gwp_asan_headers",
-    defaults: ["gwp_asan_defaults"],
+    defaults: [
+        "gwp_asan_defaults",
+        "gwp_asan_no_libs_defaults",
+    ],
     export_include_dirs: [
         ".",
     ],
@@ -52,18 +54,44 @@
 // Only static linkage is provided for performance reasons.
 cc_library_static {
     name: "gwp_asan",
-    defaults: ["gwp_asan_defaults"],
+    defaults: ["gwp_asan_no_libs_defaults"],
     header_libs: [
         "gwp_asan_headers",
         "libc_headers", // Required for pthread.h in mutex.h.
     ],
     srcs: [
+        "gwp_asan/common.cpp",
         "gwp_asan/guarded_pool_allocator.cpp",
+        "gwp_asan/platform_specific/common_posix.cpp",
         "gwp_asan/platform_specific/guarded_pool_allocator_posix.cpp",
         "gwp_asan/platform_specific/mutex_posix.cpp",
+        "gwp_asan/platform_specific/utilities_posix.cpp",
         "gwp_asan/random.cpp",
         "gwp_asan/stack_trace_compressor.cpp",
     ],
+    // GWP-ASan requires platform (non-emulated) TLS. We use thread local
+    // variables in the core, inlined interface to GWP-ASan.
+    cflags: [
+        "-fno-emulated-tls",
+    ],
+}
+
+// GWP-ASan crash handler API. Provides all the tools you need to symbolize a
+// GWP-ASan crash.
+cc_library {
+    name: "gwp_asan_crash_handler",
+    defaults: ["gwp_asan_defaults"],
+    header_libs: [
+        "gwp_asan_headers",
+        "libc_headers", // Required for assert.h
+    ],
+    srcs: [
+        "gwp_asan/common.cpp",
+        "gwp_asan/crash_handler.cpp",
+        "gwp_asan/platform_specific/common_posix.cpp",
+        "gwp_asan/platform_specific/utilities_posix.cpp",
+        "gwp_asan/stack_trace_compressor.cpp",
+    ],
 }
 
 cc_fuzz {
@@ -79,6 +107,7 @@
     defaults: ["linux_bionic_supported"],
     static_libs: [
         "gwp_asan",
+        "gwp_asan_crash_handler",
         "libasync_safe",
     ],
     srcs: [
@@ -86,6 +115,7 @@
         "gwp_asan/tests/alignment.cpp",
         "gwp_asan/tests/basic.cpp",
         "gwp_asan/tests/compression.cpp",
+        "gwp_asan/tests/crash_handler_api.cpp",
         "gwp_asan/tests/harness.cpp",
         "gwp_asan/tests/late_init.cpp",
         "gwp_asan/tests/mutex_test.cpp",
diff --git a/android/test_printf.cpp b/android/test_printf.cpp
index 49ad049..086b0aa 100644
--- a/android/test_printf.cpp
+++ b/android/test_printf.cpp
@@ -2,6 +2,7 @@
 #include <stdarg.h>
 #include <unistd.h>
 
+#include "gwp_asan/optional/segv_handler.h"
 #include "gwp_asan/options.h"
 
 namespace {
@@ -17,8 +18,6 @@
 namespace test {
 // Android version of the Printf() function for use in gwp_asan_unittest. You
 // can find the declaration of this function in gwp_asan/tests/harness.h
-options::Printf_t getPrintfFunction() {
-    return PrintfWrapper;
-}
+crash_handler::Printf_t getPrintfFunction() { return PrintfWrapper; }
 }; // namespace test
 }; // namespace gwp_asan