Move large structure off the stack.
am: f7eef920b5

Change-Id: I626d94bcfeee703f9c783c0f8eced9d11666995d
diff --git a/Android.bp b/Android.bp
index 4fcbd7d..1ced88e 100644
--- a/Android.bp
+++ b/Android.bp
@@ -17,68 +17,81 @@
 // Set to true to enable a debug build of the libraries.
 // To control what is logged, set the environment variable UNW_DEBUG_LEVEL=x,
 // where x controls the verbosity (from 1 to 20).
-libunwind_debug = ["false"]
+//libunwind_debug = false
 
-libunwind_common_cppflags = [
-    "-Wno-old-style-cast",
-]
+cc_defaults {
+    name: "libunwind_defaults",
+    host_supported: true,
 
-libunwind_common_cflags = [
-    "-Wno-unused-parameter",
-    "-Werror",
-]
+    cppflags: [
+        "-Wno-old-style-cast",
+    ],
 
-// gcc 4.8 appears to be overeager declaring that a variable is uninitialized,
-// under certain circumstances. Turn off this warning only for target so that
-// coverage is still present for the host code. When the entire build system
-// is switched to 4.9, then this can be removed.
-libunwind_common_cflags_target = ["-Wno-maybe-uninitialized"]
+    cflags: [
+        "-Werror",
+        "-Wno-#pragma-messages",
+        "-Wno-unused-parameter",
 
-// src/mi/backtrace.c is misdetected as a bogus header guard by clang 3.5
-// src/x86_64/Gstash_frame.c has unnecessary calls to labs.
-libunwind_common_clang_cflags = [
-    "-Wno-header-guard",
-    "-Wno-absolute-value",
-    // The latest clang (r230699) does not allow SP/PC to be declared in inline asm lists.
-    "-Wno-inline-asm",
-]
+        "-DHAVE_CONFIG_H",
+        "-D_GNU_SOURCE",
+        "-DNDEBUG",
+    ],
 
-libunwind_common_cflags += [
-    "-DHAVE_CONFIG_H",
-    "-D_GNU_SOURCE",
-    "-DNDEBUG",
-]
-
-libunwind_common_debug_cflags = [
-    "-UNDEBUG",
-    "-DDEBUG",
-    "-U_FORTIFY_SOURCE",
-]
-
-libunwind_common_c_local_includes = [
-    "src",
-    "include",
-]
-
-libunwind_common_arch_includes = {
-    arm: {
-        local_include_dirs: ["include/tdep-arm"],
+    arch: {
+        arm: {
+            local_include_dirs: ["include/tdep-arm"],
+        },
+        arm64: {
+            local_include_dirs: ["include/tdep-aarch64"],
+        },
+        mips: {
+            local_include_dirs: ["include/tdep-mips"],
+        },
+        mips64: {
+            local_include_dirs: ["include/tdep-mips"],
+        },
+        x86: {
+            local_include_dirs: ["include/tdep-x86"],
+        },
+        x86_64: {
+            local_include_dirs: ["include/tdep-x86_64"],
+        },
     },
-    arm64: {
-        local_include_dirs: ["include/tdep-aarch64"],
+
+    target: {
+        android: {
+            // gcc 4.8 appears to be overeager declaring that a variable is uninitialized,
+            // under certain circumstances. Turn off this warning only for target so that
+            // coverage is still present for the host code. When the entire build system
+            // is switched to 4.9, then this can be removed.
+            cflags: ["-Wno-maybe-uninitialized"],
+        },
+        darwin: {
+            enabled: false,
+        },
     },
-    mips: {
-        local_include_dirs: ["include/tdep-mips"],
+
+    clang_cflags: [
+        // src/mi/backtrace.c is misdetected as a bogus header guard by clang 3.5
+        // src/x86_64/Gstash_frame.c has unnecessary calls to labs.
+        "-Wno-header-guard",
+        "-Wno-absolute-value",
+        // The latest clang (r230699) does not allow SP/PC to be declared in inline asm lists.
+        "-Wno-inline-asm",
+    ],
+
+    debug: {
+        cflags: [
+            "-UNDEBUG",
+            "-DDEBUG",
+            "-U_FORTIFY_SOURCE",
+        ],
     },
-    mips64: {
-        local_include_dirs: ["include/tdep-mips"],
-    },
-    x86: {
-        local_include_dirs: ["include/tdep-x86"],
-    },
-    x86_64: {
-        local_include_dirs: ["include/tdep-x86_64"],
-    },
+
+    local_include_dirs: [
+        "src",
+        "include",
+    ],
 }
 
 //-----------------------------------------------------------------------
@@ -87,7 +100,10 @@
 
 cc_library {
     name: "libunwind",
-    host_supported: true,
+    defaults: ["libunwind_defaults"],
+    sdk_version: "21",
+    stl: "none",
+
     srcs: [
         "src/mi/init.c",
         "src/mi/flush_cache.c",
@@ -157,10 +173,6 @@
         "src/ptrace/_UPT_resume.c",
      ],
 
-    cflags: libunwind_common_cflags,
-    clang_cflags: libunwind_common_clang_cflags,
-    local_include_dirs: libunwind_common_c_local_includes,
-
     arch: {
         arm: {
             srcs: [
@@ -352,7 +364,7 @@
                 "src/x86_64/setcontext.S",
             ],
         },
-    } + libunwind_common_arch_includes,
+    },
 
     multilib: {
         lib32: {
@@ -366,29 +378,27 @@
     target: {
         android: {
             shared_libs: ["libdl"],
-            cflags: libunwind_common_cflags_target,
         },
-        host: {
+        linux: {
             ldflags: ["-nostdlib"],
             host_ldlibs: [
                 "-lc",
                 "-lpthread",
             ],
         },
-        darwin: {
-            enabled: false,
+        linux_bionic: {
+            enabled: true,
+            shared_libs: ["libdl"],
         },
     },
 
     export_include_dirs: ["include"],
-    stl: "none",
 
     shared_libs: ["liblzma"],
 
-    /*debug: {
-    shared_libs: ["liblog"],
-    cflags: libunwind_common_debug_cflags,
-    },*/
+    debug: {
+        //shared_libs: ["liblog"],
+    },
 }
 
 //-----------------------------------------------------------------------
@@ -396,7 +406,8 @@
 //-----------------------------------------------------------------------
 cc_library_static {
     name: "libunwindbacktrace",
-    host_supported: true,
+    defaults: ["libunwind_defaults"],
+    sdk_version: "21",
     srcs: [
         "src/unwind/BacktraceWrapper.c",
         "src/unwind/DeleteException.c",
@@ -418,55 +429,39 @@
         "src/unwind/SetIP.c",
     ],
 
-    cflags: libunwind_common_cflags + [
+    cflags: [
         "-Wno-old-style-declaration",
         "-fvisibility=hidden",
     ],
 
-    clang_cflags: libunwind_common_clang_cflags,
-    local_include_dirs: libunwind_common_c_local_includes,
-
-    arch: libunwind_common_arch_includes,
+    whole_static_libs: ["libunwind"],
 
     target: {
-        android: {
-            cflags: libunwind_common_cflags_target,
-        },
-        darwin: {
-            enabled: false,
+        linux_bionic: {
+            enabled: true,
         },
     },
-
-    whole_static_libs: ["libunwind"],
-    stl: "none",
 }
 
-/*
 //-----------------------------------------------------------------------
 // libunwind testing
 //-----------------------------------------------------------------------
-libunwind-unit-tests_cflags = [
-"-fno-builtin",
-"-O0",
-"-g",
-]
+cc_test {
+    name: "libunwind-unit-tests",
+    srcs: ["android/tests/local_test.cpp"],
+    defaults: ["libunwind_defaults"],
 
-libunwind-unit-tests_c_local_includes = ["include"]
+    cflags: [
+        "-fno-builtin",
+        "-O0",
+        "-g",
+    ],
 
-libunwind-unit-tests_src_files = ["android/tests/local_test.cpp"]
+    local_include_dirs: ["include"],
+    shared_libs: ["libunwind"],
+}
 
-libunwind-unit-tests_shared_libraries = ["libunwind"]
-
-libunwind-unit-tests_multilib = ["both"]
-module = ["libunwind-unit-tests"]
-module_tag = ["optional"]
-build_type = ["target"]
-build_target = ["NATIVE_TEST"]
-// ANDROIDMK TRANSLATION ERROR: unsupported include
-// include $(LOCAL_PATH)/Android.build.mk
-build_type = ["host"]
-// ANDROIDMK TRANSLATION ERROR: unsupported include
-// include $(LOCAL_PATH)/Android.build.mk
+/*
 // Run the unit tests built for x86 or x86_64.
 // ANDROIDMK TRANSLATION ERROR: unsupported conditional
 // ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
diff --git a/Android.build.mk b/Android.build.mk
deleted file mode 100644
index 5d91049..0000000
--- a/Android.build.mk
+++ /dev/null
@@ -1,127 +0,0 @@
-#
-# Copyright (C) 2014 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-include $(CLEAR_VARS)
-
-ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),mips mips64 x86_64))
-# Many init services failed to start with clang for x86_64, mips, mips64
-LOCAL_CLANG := false
-endif
-
-LOCAL_MODULE := $(libunwind_module)
-LOCAL_MODULE_TAGS := $(libunwind_module_tag)
-ifeq ($(libunwind_build_type),host)
-# Always make host multilib, and always use clang.
-LOCAL_MULTILIB := both
-LOCAL_CLANG := true
-else
-LOCAL_MULTILIB := $($(libunwind_module)_multilib)
-endif
-
-ifneq ($(findstring LIBRARY, $(libunwind_build_target)),LIBRARY)
-ifeq ($(LOCAL_MULTILIB),both)
-    LOCAL_MODULE_STEM_32 := $(libunwind_module)32
-    LOCAL_MODULE_STEM_64 := $(libunwind_module)64
-endif
-endif
-
-LOCAL_ADDITIONAL_DEPENDENCIES := \
-    $(LOCAL_PATH)/Android.mk \
-    $(LOCAL_PATH)/Android.build.mk \
-
-LOCAL_CFLAGS += \
-    $(libunwind_common_cflags) \
-    $(libunwind_common_cflags_$(libunwind_build_type)) \
-    $($(libunwind_module)_cflags) \
-    $($(libunwind_module)_cflags_$(libunwind_build_type)) \
-
-LOCAL_CLANG_CFLAGS += \
-    $(libunwind_common_clang_cflags) \
-    $(libunwind_common_clang_cflags_$(libunwind_build_type)) \
-    $($(libunwind_module)_clang_cflags) \
-    $($(libunwind_module)_clang_cflags_$(libunwind_build_type)) \
-
-LOCAL_CONLYFLAGS += \
-    $(libunwind_common_conlyflags) \
-    $(libunwind_common_conlyflags_$(libunwind_build_type)) \
-    $($(libunwind_module)_conlyflags) \
-    $($(libunwind_module)_conlyflags_$(libunwind_build_type)) \
-
-LOCAL_CPPFLAGS += \
-    $(libunwind_common_cppflags) \
-    $($(libunwind_module)_cppflags) \
-    $($(libunwind_module)_cppflags_$(libunwind_build_type)) \
-
-LOCAL_C_INCLUDES := \
-    $(libunwind_common_c_includes) \
-    $($(libunwind_module)_c_includes) \
-    $($(libunwind_module)_c_includes_$(libunwind_build_type)) \
-
-LOCAL_EXPORT_C_INCLUDE_DIRS := \
-    $($(libunwind_module)_export_c_include_dirs)
-
-$(foreach arch,$(libunwind_arches), \
-    $(eval LOCAL_C_INCLUDES_$(arch) := $(libunwind_common_c_includes_$(arch))))
-
-LOCAL_SRC_FILES := \
-    $($(libunwind_module)_src_files) \
-    $($(libunwind_module)_src_files_$(build_type)) \
-
-$(foreach arch,$(libunwind_arches), \
-    $(eval LOCAL_SRC_FILES_$(arch) := $($(libunwind_module)_src_files_$(arch))))
-
-LOCAL_SRC_FILES_32 := $($(libunwind_module)_src_files_32)
-LOCAL_SRC_FILES_64 := $($(libunwind_module)_src_files_64)
-
-LOCAL_STATIC_LIBRARIES := \
-    $($(libunwind_module)_static_libraries) \
-    $($(libunwind_module)_static_libraries_$(libunwind_build_type)) \
-
-LOCAL_WHOLE_STATIC_LIBRARIES := \
-    $($(libunwind_module)_whole_static_libraries) \
-    $($(libunwind_module)_whole_static_libraries_$(libunwind_build_type)) \
-
-LOCAL_SHARED_LIBRARIES := \
-    $($(libunwind_module)_shared_libraries) \
-    $($(libunwind_module)_shared_libraries_$(libunwind_build_type)) \
-
-LOCAL_LDLIBS := \
-    $($(libunwind_module)_ldlibs) \
-    $($(libunwind_module)_ldlibs_$(libunwind_build_type)) \
-
-LOCAL_LDFLAGS := \
-    $($(libunwind_module)_ldflags) \
-    $($(libunwind_module)_ldflags_$(libunwind_build_type)) \
-
-# Translate arm64 to aarch64 in c includes and src files.
-LOCAL_C_INCLUDES_arm64 := \
-    $(subst tdep-arm64,tdep-aarch64,$(LOCAL_C_INCLUDES_arm64))
-
-LOCAL_SRC_FILES_arm64 := \
-    $(subst src/arm64,src/aarch64,$(LOCAL_SRC_FILES_arm64))
-
-LOCAL_SANITIZE := never
-
-ifeq ($(libunwind_build_type),target)
-  include $(BUILD_$(libunwind_build_target))
-endif
-
-ifeq ($(libunwind_build_type),host)
-  # Only build if host builds are supported.
-  ifeq ($(libunwind_build_host),true)
-    include $(BUILD_HOST_$(libunwind_build_target))
-  endif
-endif
diff --git a/Android.mk b/Android.mk
deleted file mode 100644
index 0704164..0000000
--- a/Android.mk
+++ /dev/null
@@ -1,347 +0,0 @@
-#
-# Copyright (C) 2014 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-LOCAL_PATH := $(call my-dir)
-
-libunwind_build_host := false
-ifeq ($(HOST_OS),linux)
-libunwind_build_host := true
-endif
-
-# Set to true to enable a debug build of the libraries.
-# To control what is logged, set the environment variable UNW_DEBUG_LEVEL=x,
-# where x controls the verbosity (from 1 to 20).
-libunwind_debug := false
-
-libunwind_common_cppflags := \
-    -Wno-old-style-cast \
-
-libunwind_common_cflags := \
-    -Wno-unused-parameter \
-    -Werror \
-
-# gcc 4.8 appears to be overeager declaring that a variable is uninitialized,
-# under certain circumstances. Turn off this warning only for target so that
-# coverage is still present for the host code. When the entire build system
-# is switched to 4.9, then this can be removed.
-libunwind_common_cflags_target := \
-    -Wno-maybe-uninitialized \
-
-# src/mi/backtrace.c is misdetected as a bogus header guard by clang 3.5
-# src/x86_64/Gstash_frame.c has unnecessary calls to labs.
-libunwind_common_clang_cflags += \
-    -Wno-header-guard \
-    -Wno-absolute-value \
-
-# The latest clang (r230699) does not allow SP/PC to be declared in inline asm lists.
-libunwind_common_clang_cflags += \
-    -Wno-inline-asm
-
-ifneq ($(libunwind_debug),true)
-libunwind_common_cflags += \
-    -DHAVE_CONFIG_H \
-    -DNDEBUG \
-    -D_GNU_SOURCE \
-
-else
-libunwind_common_cflags += \
-    -DHAVE_CONFIG_H \
-    -DDEBUG \
-    -D_GNU_SOURCE \
-    -U_FORTIFY_SOURCE \
-
-endif
-
-libunwind_common_c_includes := \
-    $(LOCAL_PATH)/src \
-    $(LOCAL_PATH)/include \
-
-# Since mips and mips64 use the same source, only generate includes/srcs
-# for the below set of arches.
-libunwind_generate_arches := arm arm64 mips x86 x86_64
-# The complete list of arches used by Android.build.mk to set arch
-# variables.
-libunwind_arches := $(libunwind_generate_arches) mips64
-
-$(foreach arch,$(libunwind_generate_arches), \
-  $(eval libunwind_common_c_includes_$(arch) := $(LOCAL_PATH)/include/tdep-$(arch)))
-
-#-----------------------------------------------------------------------
-# libunwind shared library
-#-----------------------------------------------------------------------
-libunwind_src_files := \
-    src/mi/init.c \
-    src/mi/flush_cache.c \
-    src/mi/mempool.c \
-    src/mi/strerror.c \
-    src/mi/backtrace.c \
-    src/mi/dyn-cancel.c \
-    src/mi/dyn-info-list.c \
-    src/mi/dyn-register.c \
-    src/mi/map.c \
-    src/mi/Lmap.c \
-    src/mi/Ldyn-extract.c \
-    src/mi/Lfind_dynamic_proc_info.c \
-    src/mi/Lget_proc_info_by_ip.c \
-    src/mi/Lget_proc_name.c \
-    src/mi/Lput_dynamic_unwind_info.c \
-    src/mi/Ldestroy_addr_space.c \
-    src/mi/Lget_reg.c \
-    src/mi/Lset_reg.c \
-    src/mi/Lget_fpreg.c \
-    src/mi/Lset_fpreg.c \
-    src/mi/Lset_caching_policy.c \
-    src/mi/Gdyn-extract.c \
-    src/mi/Gdyn-remote.c \
-    src/mi/Gfind_dynamic_proc_info.c \
-    src/mi/Gget_accessors.c \
-    src/mi/Gget_proc_info_by_ip.c \
-    src/mi/Gget_proc_name.c \
-    src/mi/Gput_dynamic_unwind_info.c \
-    src/mi/Gdestroy_addr_space.c \
-    src/mi/Gget_reg.c \
-    src/mi/Gset_reg.c \
-    src/mi/Gget_fpreg.c \
-    src/mi/Gset_fpreg.c \
-    src/mi/Gset_caching_policy.c \
-    src/dwarf/Lexpr.c \
-    src/dwarf/Lfde.c \
-    src/dwarf/Lparser.c \
-    src/dwarf/Lpe.c \
-    src/dwarf/Lstep_dwarf.c \
-    src/dwarf/Lfind_proc_info-lsb.c \
-    src/dwarf/Lfind_unwind_table.c \
-    src/dwarf/Gexpr.c \
-    src/dwarf/Gfde.c \
-    src/dwarf/Gfind_proc_info-lsb.c \
-    src/dwarf/Gfind_unwind_table.c \
-    src/dwarf/Gparser.c \
-    src/dwarf/Gpe.c \
-    src/dwarf/Gstep_dwarf.c \
-    src/dwarf/global.c \
-    src/os-common.c \
-    src/os-linux.c \
-    src/Los-common.c \
-
-# ptrace files for remote unwinding.
-libunwind_src_files += \
-    src/ptrace/_UPT_accessors.c \
-    src/ptrace/_UPT_access_fpreg.c \
-    src/ptrace/_UPT_access_mem.c \
-    src/ptrace/_UPT_access_reg.c \
-    src/ptrace/_UPT_create.c \
-    src/ptrace/_UPT_destroy.c \
-    src/ptrace/_UPT_find_proc_info.c \
-    src/ptrace/_UPT_get_dyn_info_list_addr.c \
-    src/ptrace/_UPT_put_unwind_info.c \
-    src/ptrace/_UPT_get_proc_name.c \
-    src/ptrace/_UPT_reg_offset.c \
-    src/ptrace/_UPT_resume.c \
-
-# Arch specific source files.
-$(foreach arch,$(libunwind_generate_arches), \
-  $(eval libunwind_src_files_$(arch) += \
-    src/$(arch)/is_fpreg.c \
-    src/$(arch)/regname.c \
-    src/$(arch)/Gcreate_addr_space.c \
-    src/$(arch)/Gget_proc_info.c \
-    src/$(arch)/Gget_save_loc.c \
-    src/$(arch)/Gglobal.c \
-    src/$(arch)/Ginit.c \
-    src/$(arch)/Ginit_local.c \
-    src/$(arch)/Ginit_remote.c \
-    src/$(arch)/Gregs.c \
-    src/$(arch)/Gresume.c \
-    src/$(arch)/Gstep.c \
-    src/$(arch)/Lcreate_addr_space.c \
-    src/$(arch)/Lget_proc_info.c \
-    src/$(arch)/Lget_save_loc.c \
-    src/$(arch)/Lglobal.c \
-    src/$(arch)/Linit.c \
-    src/$(arch)/Linit_local.c \
-    src/$(arch)/Linit_remote.c \
-    src/$(arch)/Lregs.c \
-    src/$(arch)/Lresume.c \
-    src/$(arch)/Lstep.c \
-    ))
-
-libunwind_src_files_arm += \
-    src/arm/getcontext.S \
-    src/arm/Gis_signal_frame.c \
-    src/arm/Gex_tables.c \
-    src/arm/Lis_signal_frame.c \
-    src/arm/Lex_tables.c \
-
-libunwind_src_files_arm64 += \
-    src/aarch64/Gis_signal_frame.c \
-    src/aarch64/Lis_signal_frame.c \
-
-libunwind_src_files_mips += \
-    src/mips/getcontext-android.S \
-    src/mips/Gis_signal_frame.c \
-    src/mips/Lis_signal_frame.c \
-
-libunwind_src_files_x86 += \
-    src/x86/getcontext-linux.S \
-    src/x86/Gos-linux.c \
-    src/x86/Los-linux.c \
-
-libunwind_src_files_x86_64 += \
-    src/x86_64/getcontext.S \
-    src/x86_64/Gstash_frame.c \
-    src/x86_64/Gtrace.c \
-    src/x86_64/Gos-linux.c \
-    src/x86_64/Lstash_frame.c \
-    src/x86_64/Ltrace.c \
-    src/x86_64/Los-linux.c \
-    src/x86_64/setcontext.S \
-
-# mips and mips64 use the same sources but define _MIP_SIM differently
-# to change the behavior.
-#   mips uses o32 abi (_MIPS_SIM == _ABIO32).
-#   mips64 uses n64 abi (_MIPS_SIM == _ABI64).
-libunwind_common_c_includes_mips64 := $(LOCAL_PATH)/include/tdep-mips
-libunwind_src_files_mips64 := $(libunwind_src_files_mips)
-
-# 64-bit architectures
-libunwind_src_files_arm64 += src/elf64.c
-libunwind_src_files_mips64 += src/elf64.c
-libunwind_src_files_x86_64 += src/elf64.c
-
-# 32-bit architectures
-libunwind_src_files_arm   += src/elf32.c
-libunwind_src_files_mips  += src/elf32.c
-libunwind_src_files_x86   += src/elf32.c
-
-libunwind_shared_libraries += liblzma
-
-libunwind_shared_libraries_target := \
-    libdl \
-
-libunwind_ldflags_host := \
-    -nostdlib
-
-libunwind_ldlibs_host := \
-    -lc \
-    -lpthread \
-
-libunwind_export_c_include_dirs := \
-    $(LOCAL_PATH)/include
-
-ifeq ($(libunwind_debug),true)
-libunwind_shared_libraries += \
-    liblog \
-
-endif
-
-libunwind_module := libunwind
-libunwind_module_tag := optional
-libunwind_build_type := target
-libunwind_build_target := SHARED_LIBRARY
-include $(LOCAL_PATH)/Android.build.mk
-libunwind_build_type := host
-include $(LOCAL_PATH)/Android.build.mk
-libunwind_build_type := target
-libunwind_build_target := STATIC_LIBRARY
-include $(LOCAL_PATH)/Android.build.mk
-libunwind_build_type := host
-include $(LOCAL_PATH)/Android.build.mk
-
-#-----------------------------------------------------------------------
-# libunwindbacktrace static library
-#-----------------------------------------------------------------------
-libunwindbacktrace_src_files += \
-    src/unwind/BacktraceWrapper.c \
-    src/unwind/DeleteException.c \
-    src/unwind/FindEnclosingFunction.c \
-    src/unwind/ForcedUnwind.c \
-    src/unwind/GetBSP.c \
-    src/unwind/GetCFA.c \
-    src/unwind/GetDataRelBase.c \
-    src/unwind/GetGR.c \
-    src/unwind/GetIP.c \
-    src/unwind/GetIPInfo.c \
-    src/unwind/GetLanguageSpecificData.c \
-    src/unwind/GetRegionStart.c \
-    src/unwind/GetTextRelBase.c \
-    src/unwind/RaiseException.c \
-    src/unwind/Resume.c \
-    src/unwind/Resume_or_Rethrow.c \
-    src/unwind/SetGR.c \
-    src/unwind/SetIP.c \
-
-libunwindbacktrace_cflags += \
-    -Wno-old-style-declaration \
-    -fvisibility=hidden
-
-libunwind_module := libunwindbacktrace
-libunwind_module_tag := optional
-libunwind_build_type := target
-libunwind_build_target := STATIC_LIBRARY
-libunwindbacktrace_whole_static_libraries := libunwind
-include $(LOCAL_PATH)/Android.build.mk
-libunwind_build_type := host
-include $(LOCAL_PATH)/Android.build.mk
-
-#-----------------------------------------------------------------------
-# libunwind testing
-#-----------------------------------------------------------------------
-libunwind-unit-tests_cflags := \
-    -fno-builtin \
-    -O0 \
-    -g \
-
-libunwind-unit-tests_c_includes := \
-    $(LOCAL_PATH)/include \
-
-libunwind-unit-tests_src_files := \
-    android/tests/local_test.cpp \
-
-libunwind-unit-tests_shared_libraries := \
-    libunwind \
-
-libunwind-unit-tests_multilib := both
-libunwind_module := libunwind-unit-tests
-libunwind_module_tag := optional
-libunwind_build_type := target
-libunwind_build_target := NATIVE_TEST
-include $(LOCAL_PATH)/Android.build.mk
-libunwind_build_type := host
-include $(LOCAL_PATH)/Android.build.mk
-
-# Run the unit tests built for x86 or x86_64.
-ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
-ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86))
-LINKER = linker64
-TEST_SUFFIX = 64
-else
-LINKER = linker
-TEST_SUFFIX = 32
-endif
-
-libunwind-unit-tests-run-on-host: libunwind-unit-tests $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh
-	if [ ! -d /system -o ! -d /system/bin ]; then \
-	  echo "Attempting to create /system/bin"; \
-	  sudo mkdir -p -m 0777 /system/bin; \
-	fi
-	mkdir -p $(TARGET_OUT_DATA)/local/tmp
-	cp $(TARGET_OUT_EXECUTABLES)/$(LINKER) /system/bin
-	cp $(TARGET_OUT_EXECUTABLES)/sh /system/bin
-	ANDROID_DATA=$(TARGET_OUT_DATA) \
-	ANDROID_ROOT=$(TARGET_OUT) \
-	LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \
-		$(TARGET_OUT_DATA_NATIVE_TESTS)/libunwind-unit-tests/libunwind-unit-tests$(TEST_SUFFIX) $(LIBUNWIND_TEST_FLAGS)
-endif
diff --git a/include/libunwind-aarch64.h b/include/libunwind-aarch64.h
index 9883cf3..f942586 100644
--- a/include/libunwind-aarch64.h
+++ b/include/libunwind-aarch64.h
@@ -187,6 +187,7 @@
   unw_tdep_context_t *unw_ctx = (uc);					\
   register uint64_t *unw_base asm ("x0") = (uint64_t*) unw_ctx->uc_mcontext.regs;		\
   __asm__ __volatile__ (						\
+     "1:\n" \
      "stp x0, x1, [%[base], #0]\n" \
      "stp x2, x3, [%[base], #16]\n" \
      "stp x4, x5, [%[base], #32]\n" \
@@ -204,8 +205,9 @@
      "stp x28, x29, [%[base], #224]\n" \
      "str x30, [%[base], #240]\n" \
      "mov x1, sp\n" \
-     "stp x1, x30, [%[base], #248]\n" \
-     : [base] "+r" (unw_base) : : "x1", "memory"); \
+     "adr x2, 1b\n" \
+     "stp x1, x2, [%[base], #248]\n" \
+     : [base] "+r" (unw_base) : : "x1", "x2", "memory"); \
   }), 0)
 /* End of ANDROID update. */
 #define unw_tdep_is_fpreg		UNW_ARCH_OBJ(is_fpreg)