Merge "Export the unwinder implementation from libc." am: 39d9156bdc am: a5dfea78bf

Change-Id: I26084c804bbd836e435f5fcdd13c450ebf597a66
diff --git a/libc/Android.bp b/libc/Android.bp
index d663667..daca9c4 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -1721,7 +1721,7 @@
                 keep_symbols_and_debug_frame: true,
             },
 
-            whole_static_libs: [ "libgcc_stripped" ],
+            whole_static_libs: [ "libunwind_llvm" ],
         },
         arm64: {
             version_script: ":libc.arm64.map",
@@ -1731,6 +1731,8 @@
             strip: {
                 keep_symbols: true,
             },
+
+            whole_static_libs: [ "libgcc_stripped" ],
         },
         x86: {
             // TODO: This is to work around b/24465209. Remove after root cause is fixed.
@@ -1744,6 +1746,8 @@
             strip: {
                 keep_symbols: true,
             },
+
+            whole_static_libs: [ "libgcc_stripped" ],
         },
         x86_64: {
             version_script: ":libc.x86_64.map",
@@ -1753,6 +1757,8 @@
             strip: {
                 keep_symbols: true,
             },
+
+            whole_static_libs: [ "libgcc_stripped" ],
         },
     },
 
@@ -1840,6 +1846,14 @@
     stl: "none",
     system_shared_libs: [],
 
+    // The build system generally requires that any dependencies of a target
+    // with an sdk_version must have a lower sdk_version. By setting sdk_version
+    // to 1 we let targets with an sdk_version that need to depend on the libc
+    // headers but cannot depend on libc itself due to circular dependencies
+    // (such as libunwind_llvm) depend on the headers. Setting sdk_version to 1
+    // is correct because the headers can support any sdk_version.
+    sdk_version: "1",
+
     export_include_dirs: [
         "include",
         "kernel/uapi",
diff --git a/libc/libc.map.txt b/libc/libc.map.txt
index 3ffa305..2710fb2 100644
--- a/libc/libc.map.txt
+++ b/libc/libc.map.txt
@@ -1517,6 +1517,36 @@
     tss_delete;
     tss_get;
     tss_set;
+
+    # Unwinder implementation
+    __aeabi_unwind_cpp_pr0; # apex llndk arm
+    __aeabi_unwind_cpp_pr1; # apex llndk arm
+    __aeabi_unwind_cpp_pr2; # apex llndk arm
+    __deregister_frame; # apex llndk arm64 x86 x86_64
+    __gnu_unwind_frame; # apex llndk arm
+    __register_frame; # apex llndk arm64 x86 x86_64
+    _Unwind_Backtrace; # apex llndk
+    _Unwind_Complete; # apex llndk arm
+    _Unwind_DeleteException; # apex llndk
+    _Unwind_Find_FDE; # apex llndk
+    _Unwind_FindEnclosingFunction; # apex llndk
+    _Unwind_ForcedUnwind; # apex llndk arm64 x86 x86_64
+    _Unwind_GetCFA; # apex llndk
+    _Unwind_GetDataRelBase; # apex llndk
+    _Unwind_GetGR; # apex llndk
+    _Unwind_GetIP; # apex llndk
+    _Unwind_GetIPInfo; # apex llndk
+    _Unwind_GetLanguageSpecificData; # apex llndk
+    _Unwind_GetRegionStart; # apex llndk
+    _Unwind_GetTextRelBase; # apex llndk
+    _Unwind_RaiseException; # apex llndk
+    _Unwind_Resume; # apex llndk
+    _Unwind_Resume_or_Rethrow; # apex llndk
+    _Unwind_SetGR; # apex llndk
+    _Unwind_SetIP; # apex llndk
+    _Unwind_VRS_Get; # apex llndk arm
+    _Unwind_VRS_Pop; # apex llndk arm
+    _Unwind_VRS_Set; # apex llndk arm
 } LIBC_Q;
 
 LIBC_PRIVATE {
@@ -1591,9 +1621,6 @@
     __aeabi_ul2d; # arm
     __aeabi_ul2f; # arm
     __aeabi_uldivmod; # arm
-    __aeabi_unwind_cpp_pr0; # arm
-    __aeabi_unwind_cpp_pr1; # arm
-    __aeabi_unwind_cpp_pr2; # arm
     __arm_fadvise64_64; # arm
     __ashldi3; # arm
     __ashrdi3; # arm
@@ -1631,7 +1658,6 @@
     __gnu_ldivmod_helper; # arm
     __gnu_uldivmod_helper; # arm
     __gnu_Unwind_Find_exidx; # arm
-    __gnu_unwind_frame; # arm
     __gtdf2; # arm
     __gtsf2; # arm
     __ledf2; # arm
@@ -1676,18 +1702,6 @@
     __unordsf2; # arm
     __wait4; # arm x86 mips
     _fwalk; # arm x86 mips
-    _Unwind_Backtrace; # arm
-    _Unwind_Complete; # arm
-    _Unwind_DeleteException; # arm
-    _Unwind_GetDataRelBase; # arm
-    _Unwind_GetLanguageSpecificData; # arm
-    _Unwind_GetRegionStart; # arm
-    _Unwind_GetTextRelBase; # arm
-    _Unwind_RaiseException; # arm
-    _Unwind_Resume; # arm
-    _Unwind_Resume_or_Rethrow; # arm
-    _Unwind_VRS_Get; # arm
-    _Unwind_VRS_Set; # arm
     android_getaddrinfofornetcontext;
     android_gethostbyaddrfornet;
     android_gethostbyaddrfornetcontext;
diff --git a/libc/malloc_debug/Android.bp b/libc/malloc_debug/Android.bp
index 4256cc4..b04cfe1 100644
--- a/libc/malloc_debug/Android.bp
+++ b/libc/malloc_debug/Android.bp
@@ -65,14 +65,6 @@
 
     stl: "libc++_static",
 
-    // Only need this for arm since libc++ uses its own unwind code that
-    // doesn't mix with the other default unwind code.
-    arch: {
-        arm: {
-            static_libs: ["libunwind_llvm"],
-        },
-    },
-
     static_libs: [
         "libasync_safe",
         "libbase",
diff --git a/linker/Android.bp b/linker/Android.bp
index 55a8625..acdf094 100644
--- a/linker/Android.bp
+++ b/linker/Android.bp
@@ -247,18 +247,23 @@
         },
         arm64: {
             srcs: [":linker_sources_arm64"],
+            static_libs: ["libgcc_stripped"],
         },
         x86: {
             srcs: [":linker_sources_x86"],
+            static_libs: ["libgcc_stripped"],
         },
         x86_64: {
             srcs: [":linker_sources_x86_64"],
+            static_libs: ["libgcc_stripped"],
         },
         mips: {
             srcs: [":linker_sources_mips"],
+            static_libs: ["libgcc_stripped"],
         },
         mips64: {
             srcs: [":linker_sources_mips64"],
+            static_libs: ["libgcc_stripped"],
         },
     },