Upgrade honggfuzz to 1.8

Test: build honggfuzz
Change-Id: I9af5d1cee5ce90e5735bf7d7362cf56cd9d48fd6
diff --git a/.gitmodules b/.gitmodules
deleted file mode 100644
index 48f0aa8..0000000
--- a/.gitmodules
+++ /dev/null
@@ -1,8 +0,0 @@
-[submodule "third_party/android/capstone"]
-	path = third_party/android/capstone
-	url = https://github.com/aquynh/capstone
-	branch = 3.0.4
-[submodule "third_party/android/libunwind"]
-	path = third_party/android/libunwind
-	url = git://git.sv.gnu.org/libunwind.git
-	branch = master
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..5fcd6bf
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,107 @@
+
+subdirs = [
+    "third_party/android/libBlocksRuntime",
+]
+
+cc_defaults {
+    name: "honggfuzz-defaults",
+    cflags: [
+        "-D_GNU_SOURCE",
+        "-fblocks",
+        "-Wall",
+        "-Wno-initializer-overrides",
+        "-Werror",
+        "-Wframe-larger-than=131072",
+        "-D__HF_USES_CAPSTONE__",
+        "-D_HF_ARCH_LINUX",
+    ],
+    c_std: "c11",
+    clang: true,
+}
+
+cc_library_headers {
+    name: "honggfuzz_libcommon_headers",
+    export_include_dirs: ["libhfcommon"],
+}
+
+cc_library {
+    name: "honggfuzz_libcommon",
+
+    defaults: ["honggfuzz-defaults"],
+
+    header_libs: ["honggfuzz_libcommon_headers"],
+    export_header_lib_headers: ["honggfuzz_libcommon_headers"],
+    srcs: [
+        "libhfcommon/*.c",
+    ],
+
+
+    static_libs: [
+        "libBlocksRuntime", // -fblocks
+    ],
+}
+
+cc_library_headers {
+    name: "honggfuzz_libhfuzz_headers",
+    export_include_dirs: ["libhfuzz"],
+}
+
+cc_library {
+    name: "honggfuzz_libhfuzz",
+    defaults: ["honggfuzz-defaults"],
+
+    arch: {
+        x86: {
+            cflags: [
+                // Suppress this performance warning for 32-bit x86.
+                "-Wno-atomic-alignment",
+            ],
+        },
+    },
+
+    header_libs: ["honggfuzz_libhfuzz_headers"],
+    export_header_lib_headers: ["honggfuzz_libhfuzz_headers"],
+
+    whole_static_libs: [
+        "honggfuzz_libcommon",
+        "libBlocksRuntime", // -fblocks
+    ],
+
+    srcs: [
+        "libhfuzz/*.c",
+    ],
+}
+
+
+
+cc_binary {
+    name: "honggfuzz",
+    defaults: ["honggfuzz-defaults"],
+
+    arch: {
+        x86: {
+            cflags: [
+                // Suppress this performance warning for 32-bit x86.
+                "-Wno-atomic-alignment",
+            ],
+        },
+    },
+
+    whole_static_libs: [
+        "honggfuzz_libcommon",
+        "libcapstone",
+        "libBlocksRuntime", // -fblocks
+
+        "libunwind_static",
+        "liblzma", // needed for libunwind
+    ],
+
+    srcs: [
+        "*.c",
+        "linux/*.c",
+    ],
+    exclude_srcs: [
+        "linux/bfd.c",
+    ],
+}
+
diff --git a/LICENSE b/LICENSE
new file mode 120000
index 0000000..d24842f
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1 @@
+COPYING
\ No newline at end of file
diff --git a/METADATA b/METADATA
new file mode 100644
index 0000000..ae3d060
--- /dev/null
+++ b/METADATA
@@ -0,0 +1,18 @@
+name: "Hongfuzz"
+description:
+    "A security oriented, feedback-driven, evolutionary, easy-to-use fuzzer "
+    "with interesting analysis options."
+
+third_party {
+  url {
+    type: HOMEPAGE
+    value: "https://github.com/google/honggfuzz"
+  }
+  url {
+    type: GIT
+    value: "https://github.com/google/honggfuzz"
+  }
+  version: "1.1"
+  last_upgrade_date { year: 2017 month: 9 day: 10 }
+  license_type: NOTICE
+}
diff --git a/MODULE_LICENSE_APACHE2 b/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/MODULE_LICENSE_APACHE2
diff --git a/NOTICE b/NOTICE
new file mode 120000
index 0000000..d24842f
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1 @@
+COPYING
\ No newline at end of file
diff --git a/OWNERS b/OWNERS
new file mode 100644
index 0000000..0981e44
--- /dev/null
+++ b/OWNERS
@@ -0,0 +1,4 @@
+# Default code reviewers picked from top 3 or more developers.
+# Please update this list if you find better candidates.
+olorin@google.com
+danielaustin@google.com
diff --git a/android/Android.mk b/android/Android.mk
deleted file mode 100644
index 280695d..0000000
--- a/android/Android.mk
+++ /dev/null
@@ -1,198 +0,0 @@
-#   honggfuzz - Android makefile
-#   -----------------------------------------
-#
-#   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.
-
-APP_UNIFIED_HEADERS := true
-LOCAL_PATH := $(abspath $(call my-dir)/..)
-
-# Maintain a local copy since some NDK versions lose LOCAL_PATH scope at POST_BUILD_EVENT
-MY_LOCAL_PATH := $(LOCAL_PATH)
-
-# Force a clean if target API has changed and a previous build exists
-CLEAN_RUN := false
-ifneq ("$(wildcard $(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/android_api.txt)","")
-  CACHED_API := $(shell cat "$(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/android_api.txt")
-  ifneq ($(APP_PLATFORM),$(CACHED_API))
-    $(info [!] Previous build was targeting different API level - cleaning)
-    CLEAN_RUN := $(shell make clean &>/dev/null && echo true || echo false)
-  endif
-endif
-
-# Force a clean if selected toolchain has changed and a previous build exists
-ifeq ($(CLEAN_RUN),false)
-  ifneq ("$(wildcard $(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/ndk_toolchain.txt)","")
-    CACHED_TOOLCHAIN := $(shell cat "$(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/ndk_toolchain.txt")
-    ifneq ($(NDK_TOOLCHAIN),$(CACHED_TOOLCHAIN))
-      $(info [!] Previous build was using different toolchain - cleaning)
-      CLEAN_RUN := $(shell make clean &>/dev/null && echo true || echo false)
-    endif
-  endif
-endif
-
-ifeq ($(APP_ABI),$(filter $(APP_ABI),armeabi armeabi-v7a))
-  ARCH_ABI := arm
-else ifeq ($(APP_ABI),$(filter $(APP_ABI),x86))
-  ARCH_ABI := x86
-else ifeq ($(APP_ABI),$(filter $(APP_ABI),arm64-v8a))
-  ARCH_ABI := arm64
-else ifeq ($(APP_ABI),$(filter $(APP_ABI),x86_64))
-  ARCH_ABI := x86_64
-else
-  $(error Unsuported / Unknown APP_API '$(APP_ABI)')
-endif
-
-# Enable Linux ptrace() instead of POSIX signal interface by default
-ANDROID_WITH_PTRACE ?= true
-
-ifeq ($(ANDROID_WITH_PTRACE),true)
-  # Additional libcrypto OpenSSL flags required to mitigate bug (ARM systems with API <= 21)
-  ifeq ($(APP_ABI),$(filter $(APP_ABI),armeabi))
-    OPENSSL_ARMCAP_ABI := "5"
-  else ifeq ($(APP_ABI),$(filter $(APP_ABI),armeabi-v7a))
-    OPENSSL_ARMCAP_ABI := "7"
-  endif
-
-  # Upstream libunwind compiled from sources with Android NDK toolchain
-  LIBUNWIND_A := third_party/android/libunwind/$(ARCH_ABI)/libunwind-$(ARCH_ABI).a
-  ifeq ("$(wildcard $(LIBUNWIND_A))","")
-    $(error libunwind-$(ARCH_ABI) is missing - to build execute \
-            'third_party/android/scripts/compile-libunwind.sh third_party/android/libunwind $(ARCH_ABI)')
-  endif
-
-  include $(CLEAR_VARS)
-  LOCAL_MODULE := libunwind
-  LOCAL_SRC_FILES := third_party/android/libunwind/$(ARCH_ABI)/libunwind.a
-  LOCAL_EXPORT_C_INCLUDES := third_party/android/libunwind/include
-  include $(PREBUILT_STATIC_LIBRARY)
-
-  include $(CLEAR_VARS)
-  LOCAL_MODULE := libunwind-arch
-  LOCAL_SRC_FILES := third_party/android/libunwind/$(ARCH_ABI)/libunwind-$(ARCH_ABI).a
-  LOCAL_EXPORT_C_INCLUDES := third_party/android/libunwind/include
-  include $(PREBUILT_STATIC_LIBRARY)
-
-  include $(CLEAR_VARS)
-  LOCAL_MODULE := libunwind-ptrace
-  LOCAL_SRC_FILES := third_party/android/libunwind/$(ARCH_ABI)/libunwind-ptrace.a
-  LOCAL_EXPORT_C_INCLUDES := third_party/android/libunwind/include
-  include $(PREBUILT_STATIC_LIBRARY)
-
-  LOCAL_MODULE := libunwind-dwarf-generic
-  LOCAL_SRC_FILES := third_party/android/libunwind/$(ARCH_ABI)/libunwind-dwarf-generic.a
-  LOCAL_EXPORT_C_INCLUDES := third_party/android/libunwind/include
-  include $(PREBUILT_STATIC_LIBRARY)
-
-  # Upstream capstone compiled from sources with Android NDK toolchain
-  LIBCAPSTONE_A := third_party/android/capstone/$(ARCH_ABI)/libcapstone.a
-  ifeq ("$(wildcard $(LIBCAPSTONE_A))","")
-    $(error libcapstone is missing - to build execute \
-            'third_party/android/scripts/compile-capstone.sh third_party/android/capstone $(ARCH_ABI)')
-  endif
-  include $(CLEAR_VARS)
-  LOCAL_MODULE := libcapstone
-  LOCAL_SRC_FILES := $(LIBCAPSTONE_A)
-  LOCAL_EXPORT_C_INCLUDES := third_party/android/capstone/include
-  include $(PREBUILT_STATIC_LIBRARY)
-endif
-
-ifneq (,$(findstring clang,$(NDK_TOOLCHAIN)))
-  LIBBRT_A := third_party/android/libBlocksRuntime/$(ARCH_ABI)/libblocksruntime.a
-  ifeq ("$(wildcard $(LIBBRT_A))","")
-    $(error libBlocksRuntime is missing - to build execute \
-            'third_party/android/scripts/compile-libBlocksRuntime.sh third_party/android/libBlocksRuntime $(ARCH_ABI)')
-  endif
-  include $(CLEAR_VARS)
-  LOCAL_MODULE := libblocksruntime
-  LOCAL_SRC_FILES := $(LIBBRT_A)
-  include $(PREBUILT_STATIC_LIBRARY)
-endif
-
-ifeq ($(ANDROID_WITH_PTRACE),true)
-  ARCH_SRCS := linux/arch.c linux/trace.c linux/perf.c linux/unwind.c linux/pt.c
-  ARCH := LINUX
-  $(info $(shell (echo "********************************************************************")))
-  $(info $(shell (echo "Android PTRACE build: Will prevent debuggerd from processing crashes")))
-  $(info $(shell (echo "********************************************************************")))
-else
-  ARCH_SRCS := posix/arch.c
-  ARCH := POSIX
-  $(info $(shell (echo "********************************************************************")))
-  $(info $(shell (echo "Android POSIX build: Will allow debuggerd to also process crashes")))
-  $(info $(shell (echo "********************************************************************")))
-endif
-
-COMMON_CFLAGS := -std=c11 \
-  -D_GNU_SOURCE \
-  -Wall -Wextra -Wno-initializer-overrides -Wno-override-init \
-  -Wno-unknown-warning-option -Werror -funroll-loops -O2 \
-  -Wframe-larger-than=60000 -Wno-format-truncation
-
-ifneq (,$(findstring clang,$(NDK_TOOLCHAIN)))
-  COMMON_CFLAGS += -fblocks -fno-sanitize=address,undefined,memory,thread -fsanitize-coverage=0
-  COMMON_STATIC_LIBS += libblocksruntime
-endif
-
-# libhfcommon module
-include $(CLEAR_VARS)
-LOCAL_MODULE := common
-LOCAL_SRC_FILES := $(wildcard libhfcommon/*.c)
-LOCAL_CFLAGS := -D_HF_ARCH_${ARCH} $(COMMON_CFLAGS)
-LOCAL_STATIC_LIBRARIES := $(COMMON_STATIC_LIBS)
-include $(BUILD_STATIC_LIBRARY)
-
-# libhfuzz module
-include $(CLEAR_VARS)
-LOCAL_MODULE := hfuzz
-LOCAL_SRC_FILES := $(wildcard libhfuzz/*.c)
-LOCAL_CFLAGS := -D_HF_ARCH_${ARCH} $(COMMON_CFLAGS) \
-  -fPIC -fno-builtin -fno-stack-protector
-LOCAL_STATIC_LIBRARIES := $(COMMON_STATIC_LIBS)
-include $(BUILD_STATIC_LIBRARY)
-
-# Main honggfuzz module
-include $(CLEAR_VARS)
-LOCAL_MODULE := honggfuzz
-LOCAL_SRC_FILES := $(wildcard *.c)
-LOCAL_CFLAGS := $(COMMON_CFLAGS)
-LOCAL_LDFLAGS := -lm -latomic
-LOCAL_STATIC_LIBRARIES := $(COMMON_STATIC_LIBS) common
-
-ifeq ($(ANDROID_WITH_PTRACE),true)
-  LOCAL_STATIC_LIBRARIES += libunwind-arch \
-    libunwind \
-    libunwind-ptrace \
-    libunwind-dwarf-generic \
-    libcapstone
-  LOCAL_CFLAGS += -D__HF_USE_CAPSTONE__
-  ifeq ($(ARCH_ABI),arm)
-    LOCAL_CFLAGS += -DOPENSSL_ARMCAP_ABI='$(OPENSSL_ARMCAP_ABI)'
-  endif
-endif
-
-LOCAL_SRC_FILES += $(ARCH_SRCS)
-LOCAL_CFLAGS += -D_HF_ARCH_${ARCH}
-
-include $(BUILD_EXECUTABLE)
-
-# The NDK build system does not copy static libraries into project/packages
-# so it has to be done manually in order to have all output under a single path.
-# Also save some build attribute cache files so that cleans can be enforced when
-# required.
-all:POST_BUILD_EVENT
-POST_BUILD_EVENT:
-	@echo $(APP_PLATFORM) > $(MY_LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/android_api.txt
-	@echo $(NDK_TOOLCHAIN) > $(MY_LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/ndk_toolchain.txt
-	@test -f $(MY_LOCAL_PATH)/obj/local/$(TARGET_ARCH_ABI)/libhfuzz.a && \
-    cp $(MY_LOCAL_PATH)/obj/local/$(TARGET_ARCH_ABI)/libhfuzz.a \
-    $(MY_LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/libhfuzz.a || true
diff --git a/third_party/android/capstone b/third_party/android/capstone
deleted file mode 160000
index 6531952..0000000
--- a/third_party/android/capstone
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 65319525ef51714a782650961fc9ea5552d41eef
diff --git a/third_party/android/libBlocksRuntime/Android.bp b/third_party/android/libBlocksRuntime/Android.bp
new file mode 100644
index 0000000..edb26d0
--- /dev/null
+++ b/third_party/android/libBlocksRuntime/Android.bp
@@ -0,0 +1,17 @@
+cc_library {
+    name: "libBlocksRuntime",
+    cflags: [
+        "-Wall",
+        "-Wextra",
+        "-Werror",
+        "-Wno-unused-parameter",
+        "-Wno-unused-function",
+        "-DHAVE_SYNC_BOOL_COMPARE_AND_SWAP_INT",
+        "-DHAVE_SYNC_BOOL_COMPARE_AND_SWAP_LONG",
+    ],
+    c_std: "c11",
+    clang:true,
+    srcs: [
+        "*.c",
+    ]
+}
diff --git a/third_party/android/libBlocksRuntime/Android.mk b/third_party/android/libBlocksRuntime/Android.mk
deleted file mode 100644
index e59992e..0000000
--- a/third_party/android/libBlocksRuntime/Android.mk
+++ /dev/null
@@ -1,12 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := libblocksruntime
-LOCAL_SRC_FILES := runtime.c data.c
-LOCAL_CFLAGS := -I. -std=c11 -Wall -Wextra -Wno-unused-parameter \
-                -Wno-unused-function \
-                -DHAVE_SYNC_BOOL_COMPARE_AND_SWAP_INT \
-                -DHAVE_SYNC_BOOL_COMPARE_AND_SWAP_LONG
-include $(BUILD_STATIC_LIBRARY)
-
diff --git a/third_party/android/libunwind b/third_party/android/libunwind
deleted file mode 160000
index bc8698f..0000000
--- a/third_party/android/libunwind
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit bc8698fd7ed13a629a8ec3cb2a89bd74f9d8b5c0
diff --git a/third_party/android/patches/libunwind.patch b/third_party/android/patches/libunwind.patch
deleted file mode 100644
index 24f84f3..0000000
--- a/third_party/android/patches/libunwind.patch
+++ /dev/null
@@ -1,398 +0,0 @@
-diff --git a/include/dwarf.h b/include/dwarf.h
-index 633868b..3fe3a3f 100644
---- a/include/dwarf.h
-+++ b/include/dwarf.h
-@@ -311,6 +311,7 @@ typedef struct dwarf_cursor
-     unw_word_t ret_addr_column; /* column for return-address */
-     unw_word_t eh_args[UNW_TDEP_NUM_EH_REGS];
-     unsigned int eh_valid_mask;
-+    unsigned int frame;
- 
-     dwarf_loc_t loc[DWARF_NUM_PRESERVED_REGS];
- 
-diff --git a/include/libunwind-aarch64.h b/include/libunwind-aarch64.h
-index cd01e57..3be8251 100644
---- a/include/libunwind-aarch64.h
-+++ b/include/libunwind-aarch64.h
-@@ -168,15 +168,37 @@ typedef struct unw_tdep_save_loc
-   }
- unw_tdep_save_loc_t;
- 
--
- /* On AArch64, we can directly use ucontext_t as the unwind context.  */
- typedef ucontext_t unw_tdep_context_t;
- 
- #include "libunwind-common.h"
- #include "libunwind-dynamic.h"
- 
--#define unw_tdep_getcontext(uc)         (getcontext (uc), 0)
--#define unw_tdep_is_fpreg               UNW_ARCH_OBJ(is_fpreg)
-+/* There is no getcontext in Android. */
-+#define unw_tdep_getcontext(uc) (({                 \
-+  unw_tdep_context_t *unw_ctx = (uc);                   \
-+  register uint64_t *unw_base asm ("x0") = (uint64_t*) unw_ctx->uc_mcontext.regs;       \
-+  __asm__ __volatile__ (                        \
-+     "stp x0, x1, [%[base], #0]\n" \
-+     "stp x2, x3, [%[base], #16]\n" \
-+     "stp x4, x5, [%[base], #32]\n" \
-+     "stp x6, x7, [%[base], #48]\n" \
-+     "stp x8, x9, [%[base], #64]\n" \
-+     "stp x10, x11, [%[base], #80]\n" \
-+     "stp x12, x13, [%[base], #96]\n" \
-+     "stp x14, x13, [%[base], #112]\n" \
-+     "stp x16, x17, [%[base], #128]\n" \
-+     "stp x18, x19, [%[base], #144]\n" \
-+     "stp x20, x21, [%[base], #160]\n" \
-+     "stp x22, x23, [%[base], #176]\n" \
-+     "stp x24, x25, [%[base], #192]\n" \
-+     "stp x26, x27, [%[base], #208]\n" \
-+     "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"); \
-+  }), 0)
- 
- extern int unw_tdep_is_fpreg (int);
- 
-diff --git a/src/aarch64/Gstep.c b/src/aarch64/Gstep.c
-index 0c35f98..2fe00ba 100644
---- a/src/aarch64/Gstep.c
-+++ b/src/aarch64/Gstep.c
-@@ -121,6 +121,30 @@ unw_step (unw_cursor_t *cursor)
-   ret = dwarf_step (&c->dwarf);
-   Debug(1, "dwarf_step()=%d\n", ret);
- 
-+  if (ret < 0 && c->dwarf.frame == 0)
-+    {
-+      /* If this is the first frame, the code may be executing garbage
-+       * in the middle of nowhere. In this case, try using the lr as
-+       * the pc.
-+       */
-+      unw_word_t lr;
-+      if (dwarf_get(&c->dwarf, c->dwarf.loc[UNW_AARCH64_X30], &lr) >= 0)
-+        {
-+          if (lr != c->dwarf.ip)
-+            {
-+              ret = 1;
-+              c->dwarf.ip = lr;
-+            }
-+        }
-+    }
-+
-+  if (ret >= 0)
-+  {
-+    if (c->dwarf.ip >= 4)
-+      c->dwarf.ip -= 4;
-+    c->dwarf.frame++;
-+  }
-+
-   if (unlikely (ret == -UNW_ESTOPUNWIND))
-     return ret;
- 
-diff --git a/src/aarch64/init.h b/src/aarch64/init.h
-index 0cedc1a..c418932 100644
---- a/src/aarch64/init.h
-+++ b/src/aarch64/init.h
-@@ -122,6 +122,7 @@ common_init (struct cursor *c, unsigned use_prev_instr)
-   c->dwarf.pi_is_dynamic = 0;
-   c->dwarf.hint = 0;
-   c->dwarf.prev_rs = 0;
-+  c->dwarf.frame = 0;
- 
-   return 0;
- }
-diff --git a/src/arm/Gstep.c b/src/arm/Gstep.c
-index 79f2dd2..28aa4c0 100644
---- a/src/arm/Gstep.c
-+++ b/src/arm/Gstep.c
-@@ -73,6 +73,39 @@ arm_exidx_step (struct cursor *c)
-   return (c->dwarf.ip == 0) ? 0 : 1;
- }
- 
-+/* When taking a step back up the stack, the pc will point to the next
-+ * instruction to execute, not the currently executing instruction. This
-+ * function adjusts the pc to the currently executing instruction.
-+ */
-+static void adjust_ip(struct cursor *c)
-+{
-+  unw_word_t ip, value;
-+  ip = c->dwarf.ip;
-+
-+  if (ip)
-+    {
-+      int adjust = 4;
-+      if (ip & 1)
-+        {
-+          /* Thumb instructions, the currently executing instruction could be
-+          * 2 or 4 bytes, so adjust appropriately.
-+          */
-+          unw_addr_space_t as;
-+          unw_accessors_t *a;
-+          void *arg;
-+
-+          as = c->dwarf.as;
-+          a = unw_get_accessors (as);
-+          arg = c->dwarf.as_arg;
-+
-+          if (ip < 5 || (*a->access_mem) (as, ip-5, &value, 0, arg) < 0 ||
-+              (value & 0xe000f000) != 0xe000f000)
-+            adjust = 2;
-+        }
-+      c->dwarf.ip -= adjust;
-+    }
-+}
-+
- PROTECTED int
- unw_handle_signal_frame (unw_cursor_t *cursor)
- {
-@@ -268,5 +301,28 @@ unw_step (unw_cursor_t *cursor)
-             }
-         }
-     }
-+
-+  if (ret < 0 && c->dwarf.frame == 0)
-+    {
-+      /* If this is the first frame, the code may be executing garbage
-+       * in the middle of nowhere. In this case, try using the lr as
-+       * the pc.
-+       */
-+      unw_word_t lr;
-+      if (dwarf_get(&c->dwarf, c->dwarf.loc[UNW_ARM_R14], &lr) >= 0)
-+        {
-+          if (lr != c->dwarf.ip)
-+            {
-+              ret = 1;
-+              c->dwarf.ip = lr;
-+            }
-+        }
-+    }
-+
-+  if (ret >= 0)
-+    {
-+      c->dwarf.frame++;
-+    }
-+
-   return ret == -UNW_ENOINFO ? 0 : 1;
- }
-diff --git a/src/arm/init.h b/src/arm/init.h
-index 6379d8e..8222c02 100644
---- a/src/arm/init.h
-+++ b/src/arm/init.h
-@@ -73,6 +73,7 @@ common_init (struct cursor *c, unsigned use_prev_instr)
-   c->dwarf.pi_is_dynamic = 0;
-   c->dwarf.hint = 0;
-   c->dwarf.prev_rs = 0;
-+  c->dwarf.frame = 0;
- 
-   return 0;
- }
-diff --git a/src/ptrace/_UPT_access_fpreg.c b/src/ptrace/_UPT_access_fpreg.c
-index e90ec47..50a4c25 100644
---- a/src/ptrace/_UPT_access_fpreg.c
-+++ b/src/ptrace/_UPT_access_fpreg.c
-@@ -46,8 +46,8 @@ _UPT_access_fpreg (unw_addr_space_t as, unw_regnum_t reg, unw_fpreg_t *val,
- #ifdef HAVE_TTRACE
- #       warning No support for ttrace() yet.
- #else
--        ptrace (PTRACE_POKEUSER, pid, _UPT_reg_offset[reg] + i * sizeof(wp[i]),
--                wp[i]);
-+        ptrace (PTRACE_POKEUSER, pid, (void*) (_UPT_reg_offset[reg] + i * sizeof(wp[i])),
-+                (void*) wp[i]);
- #endif
-         if (errno)
-           return -UNW_EBADREG;
-@@ -59,7 +59,7 @@ _UPT_access_fpreg (unw_addr_space_t as, unw_regnum_t reg, unw_fpreg_t *val,
- #       warning No support for ttrace() yet.
- #else
-         wp[i] = ptrace (PTRACE_PEEKUSER, pid,
--                        _UPT_reg_offset[reg] + i * sizeof(wp[i]), 0);
-+                        (void*) (_UPT_reg_offset[reg] + i * sizeof(wp[i])), 0);
- #endif
-         if (errno)
-           return -UNW_EBADREG;
-@@ -100,6 +100,14 @@ _UPT_access_fpreg (unw_addr_space_t as, unw_regnum_t reg, unw_fpreg_t *val,
- #endif
-   return 0;
- }
-+#elif defined(__aarch64__)
-+int
-+_UPT_access_fpreg (unw_addr_space_t as, unw_regnum_t reg, unw_fpreg_t *val,
-+           int write, void *arg)
-+{
-+# pragma message("_UPT_access_fpreg is not implemented and not currently used.")
-+  return -UNW_EBADREG;
-+}
- #else
- #error Fix me
- #endif
-diff --git a/src/ptrace/_UPT_access_reg.c b/src/ptrace/_UPT_access_reg.c
-index ae71608..8d40bcc 100644
---- a/src/ptrace/_UPT_access_reg.c
-+++ b/src/ptrace/_UPT_access_reg.c
-@@ -32,6 +32,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
- #   include <asm/ptrace_offsets.h>
- # endif
- # include "tdep-ia64/rse.h"
-+#elif defined(__aarch64__)
-+# include <sys/uio.h>
- #endif
- 
- #if HAVE_DECL_PTRACE_POKEUSER || HAVE_TTRACE
-@@ -239,13 +241,13 @@ _UPT_access_reg (unw_addr_space_t as, unw_regnum_t reg, unw_word_t *val,
- #else
-   errno = 0;
-   if (write)
--    ptrace (PTRACE_POKEUSER, pid, _UPT_reg_offset[reg], *val);
-+    ptrace (PTRACE_POKEUSER, pid, (void*) (uintptr_t) _UPT_reg_offset[reg], (void*) *val);
-   else {
- #if UNW_DEBUG
-     Debug(16, "ptrace PEEKUSER pid: %lu , reg: %lu , offs: %lu\n", (unsigned long)pid, (unsigned long)reg,
-         (unsigned long)_UPT_reg_offset[reg]);
- #endif
--    *val = ptrace (PTRACE_PEEKUSER, pid, _UPT_reg_offset[reg], 0);
-+    *val = ptrace (PTRACE_PEEKUSER, pid, (void*) (uintptr_t) _UPT_reg_offset[reg], 0);
-   }
-   if (errno) {
- #if UNW_DEBUG
-@@ -304,6 +306,60 @@ _UPT_access_reg (unw_addr_space_t as, unw_regnum_t reg, unw_word_t *val,
-   Debug (1, "bad register %s [%u] (error: %s)\n", unw_regname(reg), reg, strerror (errno));
-   return -UNW_EBADREG;
- }
-+#elif HAVE_DECL_PT_GETREGSET
-+int
-+_UPT_access_reg (unw_addr_space_t as, unw_regnum_t reg, unw_word_t *val,
-+         int write, void *arg)
-+{
-+  struct UPT_info *ui = arg;
-+  pid_t pid = ui->pid;
-+#if defined(__aarch64__)
-+  struct user_pt_regs regs;
-+  struct iovec io;
-+  io.iov_base = &regs;
-+  io.iov_len = sizeof(regs);
-+
-+#if UNW_DEBUG
-+  Debug(16, "using getregset: reg: %s [%u], val: %lx, write: %u\n", unw_regname(reg), (unsigned) reg, (long) val, write);
-+
-+  if (write)
-+    Debug (16, "%s [%u] <- %lx\n", unw_regname (reg), (unsigned) reg, (long) *val);
-+#endif
-+  if (ptrace(PTRACE_GETREGSET, pid, (void*)NT_PRSTATUS, (void*)&io) == -1)
-+    goto badreg;
-+  if (write)
-+    {
-+      if (reg == UNW_AARCH64_SP)
-+        regs.sp = *val;
-+      else if (reg == UNW_AARCH64_PC)
-+        regs.pc = *val;
-+      else if (reg < UNW_AARCH64_SP)
-+        regs.regs[reg] = *val;
-+      else
-+        goto badreg;
-+      if (ptrace(PTRACE_SETREGSET, pid, (void*)NT_PRSTATUS, (void*)&io) == -1)
-+        goto badreg;
-+    }
-+  else
-+    {
-+      if (reg == UNW_AARCH64_SP)
-+        *val = regs.sp;
-+      else if (reg == UNW_AARCH64_PC)
-+        *val = regs.pc;
-+      else if (reg < UNW_AARCH64_SP)
-+        *val = regs.regs[reg];
-+      else
-+        goto badreg;
-+    }
-+#else
-+#error Unsupported architecture for getregset
-+#endif
-+  return 0;
-+
-+ badreg:
-+  Debug (1, "bad register %s [%u] (error: %s)\n", unw_regname(reg), reg, strerror (errno));
-+  return -UNW_EBADREG;
-+}
- #else
- #error Port me
- #endif
-diff --git a/src/x86/Gos-linux.c b/src/x86/Gos-linux.c
-index 17aebc2..bafca96 100644
---- a/src/x86/Gos-linux.c
-+++ b/src/x86/Gos-linux.c
-@@ -283,7 +283,9 @@ HIDDEN int
- x86_local_resume (unw_addr_space_t as, unw_cursor_t *cursor, void *arg)
- {
-   struct cursor *c = (struct cursor *) cursor;
-+#if !defined(__ANDROID__)
-   ucontext_t *uc = c->uc;
-+#endif
- 
-   /* Ensure c->pi is up-to-date.  On x86, it's relatively common to be
-      missing DWARF unwind info.  We don't want to fail in that case,
-@@ -296,12 +298,16 @@ x86_local_resume (unw_addr_space_t as, unw_cursor_t *cursor, void *arg)
-       struct sigcontext *sc = (struct sigcontext *) c->sigcontext_addr;
- 
-       Debug (8, "resuming at ip=%x via sigreturn(%p)\n", c->dwarf.ip, sc);
-+#if !defined(__ANDROID__)
-       sigreturn (sc);
-+#endif
-     }
-   else
-     {
-       Debug (8, "resuming at ip=%x via setcontext()\n", c->dwarf.ip);
-+#if !defined(__ANDROID__)
-       setcontext (uc);
-+#endif
-     }
-   return -UNW_EINVAL;
- }
-diff --git a/src/x86/Gstep.c b/src/x86/Gstep.c
-index 10e2cbc..49a830d 100644
---- a/src/x86/Gstep.c
-+++ b/src/x86/Gstep.c
-@@ -110,6 +110,20 @@ unw_step (unw_cursor_t *cursor)
-       else
-         c->dwarf.ip = 0;
-     }
-+
-+  if (ret >= 0)
-+    {
-+      if (c->dwarf.ip)
-+        {
-+          /* Adjust the pc to the instruction before. */
-+          c->dwarf.ip--;
-+        }
-+      c->dwarf.frame++;
-+    }
-+
-+  if (unlikely (ret <= 0))
-+    return 0;
-+
-   ret = (c->dwarf.ip == 0) ? 0 : 1;
-   Debug (2, "returning %d\n", ret);
-   return ret;
-diff --git a/src/x86/init.h b/src/x86/init.h
-index 027aedc..4218aa3 100644
---- a/src/x86/init.h
-+++ b/src/x86/init.h
-@@ -65,6 +65,7 @@ common_init (struct cursor *c, unsigned use_prev_instr)
-   c->dwarf.pi_is_dynamic = 0;
-   c->dwarf.hint = 0;
-   c->dwarf.prev_rs = 0;
-+  c->dwarf.frame = 0;
- 
-   return 0;
- }
-diff --git a/src/x86_64/init.h b/src/x86_64/init.h
-index 442b2bf..737b9f7 100644
---- a/src/x86_64/init.h
-+++ b/src/x86_64/init.h
-@@ -84,6 +84,7 @@ common_init (struct cursor *c, unsigned use_prev_instr)
-   c->dwarf.pi_is_dynamic = 0;
-   c->dwarf.hint = 0;
-   c->dwarf.prev_rs = 0;
-+  c->dwarf.frame = 0;
- 
-   return 0;
- }
diff --git a/third_party/android/scripts/compile-capstone.sh b/third_party/android/scripts/compile-capstone.sh
deleted file mode 100755
index 82c7d22..0000000
--- a/third_party/android/scripts/compile-capstone.sh
+++ /dev/null
@@ -1,171 +0,0 @@
-#!/bin/bash
-#
-#   honggfuzz capstone build help script
-#   -----------------------------------------
-#
-#   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.
-
-#set -x # debug
-
-abort() {
-  cd - &>/dev/null
-  exit "$1"
-}
-
-trap "abort 1" SIGINT SIGTERM
-
-if [ $# -ne 2 ]; then
-  echo "[-] Invalid arguments"
-  echo "[!] $0 <CAPSTONE_DIR> <ARCH>"
-  echo "    ARCH: arm arm64 x86 x86_64"
-  exit 1
-fi
-
-readonly CAPSTONE_DIR="$1"
-
-if [ ! -d "$CAPSTONE_DIR/.git" ]; then
-  git submodule update --init third_party/android/capstone || {
-    echo "[-] git submodules init failed"
-    exit 1
-  }
-fi
-
-# register client hooks
-hooksDir="$(git -C "$CAPSTONE_DIR" rev-parse --git-dir)/hooks"
-mkdir -p "$hooksDir"
-
-if [ ! -f "$hooksDir/post-checkout" ]; then
-  cat > "$hooksDir/post-checkout" <<'endmsg'
-#!/usr/bin/env bash
-
-rm -f arm/*.a
-rm -f arm64/*.a
-rm -f x86/*.a
-rm -f x86_64/*.a
-endmsg
-  chmod +x "$hooksDir/post-checkout"
-fi
-
-# Change workspace
-cd "$CAPSTONE_DIR" &>/dev/null
-
-if [ -z "$NDK" ]; then
-  # Search in $PATH
-  if [[ $(which ndk-build) != "" ]]; then
-    NDK=$(dirname $(which ndk-build))
-  else
-    echo "[-] Could not detect Android NDK dir"
-    abort 1
-  fi
-fi
-
-case "$2" in
-  arm|arm64|x86|x86_64)
-    readonly ARCH=$2
-    if [ ! -d $ARCH ] ; then mkdir -p $ARCH; fi
-    ;;
-  *)
-    echo "[-] Invalid CPU architecture"
-    abort 1
-    ;;
-esac
-
-# Check if previous build exists and matches selected ANDROID_API level
-# If API cache file not there always rebuild
-if [ -f "$ARCH/libcapstone.a" ]; then
-  if [ -f "$ARCH/android_api.txt" ]; then
-    old_api=$(cat "$ARCH/android_api.txt")
-    if [[ "$old_api" == "$ANDROID_API" ]]; then
-      # No need to recompile
-      abort 0
-    fi
-  fi
-fi
-
-case "$ARCH" in
-  arm)
-    CS_ARCH="arm"
-    CS_BUILD_BIN="make"
-    TOOLCHAIN=arm-linux-androideabi
-    TOOLCHAIN_S=arm-linux-androideabi-4.9
-    ;;
-  arm64)
-    CS_ARCH="arm aarch64"
-    CS_BUILD_BIN="make"
-    TOOLCHAIN=aarch64-linux-android
-    TOOLCHAIN_S=aarch64-linux-android-4.9
-    ;;
-  x86)
-    CS_ARCH="x86"
-    CS_BUILD_BIN="make"
-    TOOLCHAIN=i686-linux-android
-    TOOLCHAIN_S=x86-4.9
-    ;;
-  x86_64)
-    CS_ARCH="x86"
-    CS_BUILD_BIN="make"
-    TOOLCHAIN=x86_64-linux-android
-    TOOLCHAIN_S=x86_64-4.9
-    ;;
-esac
-
-# Capstone ARM/ARM64 cross-compile automation is broken,
-# we need to prepare the Android NDK toolchains manually
-if [ -z "$NDK" ]; then
-  # Search in $PATH
-  if [[ $(which ndk-build) != "" ]]; then
-    $NDK=$(dirname $(which ndk-build))
-  else
-    echo "[-] Could not detect Android NDK dir"
-    abort 1
-  fi
-fi
-
-if [ -z "$ANDROID_API" ]; then
-  ANDROID_API="android-26"
-fi
-if ! echo "$ANDROID_API" | grep -qoE 'android-[0-9]{1,2}'; then
-  echo "[-] Invalid ANDROID_API '$ANDROID_API'"
-  abort 1
-fi
-ANDROID_API_V=$(echo "$ANDROID_API" | grep -oE '[0-9]{1,2}$')
-
-# Support both Linux & Darwin
-HOST_OS=$(uname -s | tr '[:upper:]' '[:lower:]')
-HOST_ARCH=$(uname -m)
-
-SYSROOT="$NDK/platforms/$ANDROID_API/arch-$ARCH"
-export CC="$NDK/toolchains/$TOOLCHAIN_S/prebuilt/$HOST_OS-$HOST_ARCH/bin/$TOOLCHAIN-gcc --sysroot=$SYSROOT -isystem $NDK/sysroot/usr/include/$TOOLCHAIN -isystem $NDK/sysroot/usr/include/ -D__ANDROID_API__=$ANDROID_API_V"
-export CXX="$NDK/toolchains/$TOOLCHAIN_S/prebuilt/$HOST_OS-$HOST_ARCH/bin/$TOOLCHAIN-g++ --sysroot=$SYSROOT -isystem $NDK/sysroot/usr/include/$TOOLCHAIN -isystem $NDK/sysroot/usr/include/ -D__ANDROID_API__=$ANDROID_API_V"
-export PATH="$NDK/toolchains/$TOOLCHAIN_S/prebuilt/$HOST_OS-$HOST_ARCH/bin":$PATH
-
-# We need to construct a cross variable that capstone Makefile can pick ar, strip & ranlib from
-export CROSS="$NDK/toolchains/$TOOLCHAIN_S/prebuilt/$HOST_OS-$HOST_ARCH/bin/$TOOLCHAIN-" CFLAGS="--sysroot=$SYSROOT -isystem $NDK/sysroot/usr/include/$TOOLCHAIN -isystem $NDK/sysroot/usr/include/" LDFLAGS="--sysroot=$SYSROOT -isystem $NDK/sysroot/usr/include/$TOOLCHAIN -isystem $NDK/sysroot/usr/include/"
-
-# Build it
-make clean
-
-NDK=$NDK CAPSTONE_BUILD_CORE_ONLY=yes CAPSTONE_ARCHS=$CS_ARCH \
-CAPSTONE_SHARED=no CAPSTONE_STATIC=yes \
-eval $CS_BUILD_BIN
-if [ $? -ne 0 ]; then
-    echo "[-] Compilation failed"
-    abort 1
-else
-    echo "[*] '$ARCH' libcapstone available at '$CAPSTONE_DIR/$ARCH'"
-fi
-
-cp libcapstone.a "$ARCH/"
-echo "$ANDROID_API" > "$ARCH/android_api.txt"
-
-abort 0
diff --git a/third_party/android/scripts/compile-libBlocksRuntime.sh b/third_party/android/scripts/compile-libBlocksRuntime.sh
deleted file mode 100755
index aa28f23..0000000
--- a/third_party/android/scripts/compile-libBlocksRuntime.sh
+++ /dev/null
@@ -1,110 +0,0 @@
-#!/bin/bash
-#
-#   honggfuzz libBlocksRuntime build help script
-#   -----------------------------------------
-#
-#   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.
-
-if [ -z "$NDK" ]; then
-  # Search in $PATH
-  if [[ $(which ndk-build) != "" ]]; then
-    NDK=$(dirname $(which ndk-build))
-  else
-    echo "[-] Could not detect Android NDK dir"
-    exit 1
-  fi
-fi
-
-if [ -z "$ANDROID_API" ]; then
-  ANDROID_API="android-26"
-fi
-if ! echo "$ANDROID_API" | grep -qoE 'android-[0-9]{1,2}'; then
-  echo "[-] Invalid ANDROID_API '$ANDROID_API'"
-  exit 1
-fi
-
-if [ $# -ne 2 ]; then
-  echo "[-] Invalid arguments"
-  echo "[!] $0 <libBlocksRuntime_DIR> <ARCH>"
-  echo "    ARCH: arm arm64 x86 x86_64"
-  exit 1
-fi
-
-readonly BRT_DIR="$1"
-
-case "$2" in
-  arm|arm64|x86|x86_64)
-    readonly ARCH=$2
-    if [ ! -d $BRT_DIR/$ARCH ] ; then mkdir -p $BRT_DIR/$ARCH; fi
-    ;;
-  *)
-    echo "[-] Invalid CPU architecture"
-    exit 1
-    ;;
-esac
-
-# Check if previous build exists and matches selected ANDROID_API level
-# If API cache file not there always rebuild
-if [ -f "$BRT_DIR/$ARCH/libblocksruntime.a" ]; then
-  if [ -f "$BRT_DIR/$ARCH/android_api.txt" ]; then
-    old_api=$(cat "$BRT_DIR/$ARCH/android_api.txt")
-    if [[ "$old_api" == "$ANDROID_API" ]]; then
-      # No need to recompile
-      exit 0
-    fi
-  fi
-fi
-
-case "$ARCH" in
-  arm)
-    BRT_ARCH="armeabi-v7a"
-    BRT_TOOLCHAIN="arm-linux-androideabi-clang"
-    ;;
-  arm64)
-    BRT_ARCH="arm64-v8a"
-    BRT_TOOLCHAIN="aarch64-linux-android-clang"
-    ;;
-  x86)
-    BRT_ARCH="x86"
-    BRT_TOOLCHAIN="x86-clang"
-    ;;
-  x86_64)
-    BRT_ARCH="x86_64"
-    BRT_TOOLCHAIN="x86_64-clang"
-    ;;
-esac
-
-# Clean first
-$NDK/ndk-build NDK_PROJECT_PATH=$BRT_DIR APP_BUILD_SCRIPT=$BRT_DIR/Android.mk \
-  APP_PLATFORM=$ANDROID_API APP_ABI=$BRT_ARCH \
-  NDK_TOOLCHAIN=$BRT_TOOLCHAIN clean
-
-# Build
-$NDK/ndk-build NDK_PROJECT_PATH=$BRT_DIR APP_BUILD_SCRIPT=$BRT_DIR/Android.mk \
-  APP_PLATFORM=$ANDROID_API APP_ABI=$BRT_ARCH \
-  NDK_TOOLCHAIN=$BRT_TOOLCHAIN
-if [ $? -ne 0 ]; then
-    echo "[-] Compilation failed"
-    exit 1
-else
-    echo "[*] '$ARCH' libBlocksRuntime available at '$BRT_DIR/$ARCH'"
-fi
-
-# Change workdir to simplify args
-cd $BRT_DIR
-
-cp obj/local/$BRT_ARCH/libblocksruntime.a "$ARCH/"
-echo "$ANDROID_API" > "$ARCH/android_api.txt"
-
-# Revert workdir to caller
-cd - &>/dev/null
diff --git a/third_party/android/scripts/compile-libunwind.sh b/third_party/android/scripts/compile-libunwind.sh
deleted file mode 100755
index 53d2eaf..0000000
--- a/third_party/android/scripts/compile-libunwind.sh
+++ /dev/null
@@ -1,231 +0,0 @@
-#!/bin/bash
-#
-#   honggfuzz libunwind build help script
-#   -----------------------------------------
-#
-#   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.
-
-#set -x # debug
-
-readonly JOBS=$(getconf _NPROCESSORS_ONLN)
-
-abort() {
-  # Revert patches if not debugging
-  if [[ "$-" == *x* ]]; then
-    echo "[!] git patches are not reverted since running under debug mode"
-  else
-    # Extra care to ensure we're under expected project
-    if [[ $# -eq 1 && "$(basename $(git rev-parse --show-toplevel))" == "libunwind" ]]; then
-      echo "[*] Resetting locally applied patches"
-      git reset --hard &>/dev/null || {
-        echo "[-] git reset failed"
-      }
-    fi
-  fi
-
-  cd - &>/dev/null
-  exit "$1"
-}
-
-trap "abort 1" SIGINT SIGTERM
-
-if [ $# -ne 2 ]; then
-  echo "[-] Invalid arguments"
-  echo "[!] $0 <LIBUNWIND_DIR> <ARCH>"
-  echo "    ARCH: arm arm64 x86 x86_64"
-  exit 1
-fi
-
-readonly LIBUNWIND_DIR="$1"
-
-if [ ! -d "$LIBUNWIND_DIR/.git" ]; then
-  git submodule update --init third_party/android/libunwind || {
-    echo "[-] git submodules init failed"
-    exit 1
-  }
-fi
-
-# register client hooks
-hooksDir="$(git -C "$LIBUNWIND_DIR" rev-parse --git-dir)/hooks"
-mkdir -p "$hooksDir"
-
-if [ ! -f "$hooksDir/post-checkout" ]; then
-  cat > "$hooksDir/post-checkout" <<'endmsg'
-#!/usr/bin/env bash
-
-rm -f arm/*.a
-rm -f arm64/*.a
-rm -f x86/*.a
-rm -f x86_64/*.a
-endmsg
-  chmod +x "$hooksDir/post-checkout"
-fi
-
-# Change workspace
-cd "$LIBUNWIND_DIR" &>/dev/null
-
-if [ -z "$NDK" ]; then
-  # Search in $PATH
-  if [[ $(which ndk-build) != "" ]]; then
-    NDK=$(dirname $(which ndk-build))
-  else
-    echo "[-] Could not detect Android NDK dir"
-    abort 1
-  fi
-fi
-
-if [ -z "$ANDROID_API" ]; then
-  ANDROID_API="android-26"
-fi
-if ! echo "$ANDROID_API" | grep -qoE 'android-[0-9]{1,2}'; then
-  echo "[-] Invalid ANDROID_API '$ANDROID_API'"
-  abort 1
-fi
-ANDROID_API_V=$(echo "$ANDROID_API" | grep -oE '[0-9]{1,2}$')
-
-case "$2" in
-  arm|arm64|x86|x86_64)
-    readonly ARCH="$2"
-    if [ ! -d "$ARCH" ] ; then mkdir -p "$ARCH"; fi
-    ;;
-  *)
-    echo "[-] Invalid architecture"
-    abort 1
-    ;;
-esac
-
-# Check if previous build exists and matches selected ANDROID_API level
-# If API cache file not there always rebuild
-if [ -f "$ARCH/libunwind-$ARCH.a" ]; then
-  if [ -f "$ARCH/android_api.txt" ]; then
-    old_api=$(cat "$ARCH/android_api.txt")
-    if [[ "$old_api" == "$ANDROID_API" ]]; then
-      # No need to recompile
-      abort 0 true
-    fi
-  fi
-fi
-
-LC_LDFLAGS="-static"
-
-# For debugging
-# Remember to export UNW_DEBUG_LEVEL=<level>
-# where 1 < level < 16 (usually values up to 5 are enough)
-#LC_CFLAGS="$LC_FLAGS -DDEBUG"
-
-# Prepare toolchain
-case "$ARCH" in
-  arm)
-    TOOLCHAIN=arm-linux-androideabi
-    TOOLCHAIN_S=arm-linux-androideabi-4.9
-    ;;
-  arm64)
-    TOOLCHAIN=aarch64-linux-android
-    TOOLCHAIN_S=aarch64-linux-android-4.9
-    ;;
-  x86)
-    TOOLCHAIN=i686-linux-android
-    TOOLCHAIN_S=x86-4.9
-    ;;
-  x86_64)
-    TOOLCHAIN=x86_64-linux-android
-    TOOLCHAIN_S=x86_64-4.9
-    ;;
-esac
-
-# Apply patches required for Android
-# TODO: Automate global patching when all archs have been tested
-
-# Ptrace patches due to Android incompatibilities
-git apply --check ../patches/libunwind.patch
-if [ $? -eq 0 ]; then
-  git apply ../patches/libunwind.patch
-  if [ $? -ne 0 ]; then
-    echo "[-] Failed to apply libunwind patches"
-    abort 1
-  fi
-else
-  echo "[-] Cannot apply libunwind patches"
-  abort 1
-fi
-
-# Support both Linux & Darwin
-HOST_OS=$(uname -s | tr '[:upper:]' '[:lower:]')
-HOST_ARCH=$(uname -m)
-
-
-SYSROOT="$NDK/platforms/$ANDROID_API/arch-$ARCH"
-export CC="$NDK/toolchains/$TOOLCHAIN_S/prebuilt/$HOST_OS-$HOST_ARCH/bin/$TOOLCHAIN-gcc"
-export CXX="$NDK/toolchains/$TOOLCHAIN_S/prebuilt/$HOST_OS-$HOST_ARCH/bin/$TOOLCHAIN-g++"
-export PATH="$NDK/toolchains/$TOOLCHAIN_S/prebuilt/$HOST_OS-$HOST_ARCH/bin":$PATH
-
-if [ ! -x "$CC" ]; then
-  echo "[-] gcc doesn't exist: $CC"
-  abort 1
-elif [ ! -x "$CXX" ]; then
-  echo "[-] g++ doesn't exist: $CXX"
-  abort 1
-fi
-
-export CC="$CC --sysroot=$SYSROOT -isystem $NDK/sysroot/usr/include/$TOOLCHAIN -isystem $NDK/sysroot/usr/include/ -D__ANDROID_API__=$ANDROID_API_V"
-export CXX="$CXX --sysroot=$SYSROOT -isystem $NDK/sysroot/usr/include/$TOOLCHAIN -isystem $NDK/sysroot/usr/include/ -D__ANDROID_API__=$ANDROID_API_V"
-
-if [ ! -f configure ]; then
-  NOCONFIGURE=true ./autogen.sh
-  if [ $? -ne 0 ]; then
-    echo "[-] autogen failed"
-    abort 1
-  fi
-  # Patch configure
-  sed -i -e 's/-lgcc_s/-lgcc/g' configure
-else
-  make clean
-fi
-
-./configure --host=$TOOLCHAIN --disable-coredump
-if [ $? -ne 0 ]; then
-  echo "[-] configure failed"
-  abort 1
-fi
-
-# Fix stuff that configure failed to detect
-# TODO: Investigate for more elegant patches
-if [ "$ARCH" == "arm64" ]; then
-  sed -i -e 's/#define HAVE_DECL_PTRACE_POKEUSER 1/#define HAVE_DECL_PTRACE_POKEUSER 0/g' include/config.h
-  echo "#define HAVE_DECL_PT_GETREGSET 1" >> include/config.h
-fi
-
-make -j"$JOBS" CFLAGS="$LC_CFLAGS" LDFLAGS="$LC_LDFLAGS"
-if [ $? -ne 0 ]; then
-    echo "[-] Compilation failed"
-    cd - &>/dev/null
-    abort 1
-fi
-
-echo "[*] '$ARCH' libunwind available at '$LIBUNWIND_DIR/$ARCH'"
-cp src/.libs/*.a "$ARCH"
-echo "$ANDROID_API" > "$ARCH/android_api.txt"
-
-# Naming conventions for arm64
-if [[ "$ARCH" == "arm64" ]]; then
-  cd "$ARCH"
-  find . -type f -name "*aarch64*.a" | while read -r libFile
-  do
-    fName=$(basename "$libFile")
-    newFName=$(echo "$fName" | sed "s#aarch64#arm64#")
-    ln -sf "$fName" "$newFName"
-  done
-  cd -
-fi
-
-abort 0