Merge "Add a README.md for async_safe"
diff --git a/linker/Android.bp b/linker/Android.bp
index e67fca8..55a8625 100644
--- a/linker/Android.bp
+++ b/linker/Android.bp
@@ -178,6 +178,7 @@
     name: "linker_sources_arm",
     srcs: [
         "arch/arm/begin.S",
+        "arch/arm_neon/linker_gnu_hash_neon.cpp",
     ],
 }
 
@@ -186,6 +187,7 @@
     srcs: [
         "arch/arm64/begin.S",
         "arch/arm64/tlsdesc_resolver.S",
+        "arch/arm_neon/linker_gnu_hash_neon.cpp",
     ],
 }
 
@@ -458,6 +460,7 @@
         "linked_list_test.cpp",
         "linker_sleb128_test.cpp",
         "linker_utils_test.cpp",
+        "linker_gnu_hash_test.cpp",
 
         // Parts of the linker that we're testing.
         "linker_block_allocator.cpp",
@@ -472,4 +475,30 @@
         "libbase",
         "liblog",
     ],
+
+    arch: {
+        arm: {
+            srcs: ["arch/arm_neon/linker_gnu_hash_neon.cpp"],
+        },
+        arm64: {
+            srcs: ["arch/arm_neon/linker_gnu_hash_neon.cpp"],
+        },
+    },
+}
+
+cc_benchmark {
+    name: "linker-benchmarks",
+
+    srcs: [
+        "linker_gnu_hash_benchmark.cpp",
+    ],
+
+    arch: {
+        arm: {
+            srcs: ["arch/arm_neon/linker_gnu_hash_neon.cpp"],
+        },
+        arm64: {
+            srcs: ["arch/arm_neon/linker_gnu_hash_neon.cpp"],
+        },
+    },
 }
diff --git a/linker/arch/arm_neon/linker_gnu_hash_neon.cpp b/linker/arch/arm_neon/linker_gnu_hash_neon.cpp
new file mode 100644
index 0000000..f4127ce
--- /dev/null
+++ b/linker/arch/arm_neon/linker_gnu_hash_neon.cpp
@@ -0,0 +1,199 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+// A Neon vectorized implementation of the GNU symbol hash function.
+
+// This function generally accesses beyond the bounds of the name string. Specifically, it reads
+// each aligned 8-byte chunk containing a byte of the string, including the final NUL byte. This
+// should be acceptable for use with MTE, which uses 16-byte granules. Typically, the function is
+// used to hash strings in an ELF file's string table, where MTE is presumably unaware of the
+// bounds of each symbol, but the linker also hashes the symbol name passed to dlsym.
+
+#include "linker_gnu_hash_neon.h"
+
+#include <arm_neon.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+struct __attribute__((aligned(8))) GnuHashInitEntry {
+  uint64_t ignore_mask;
+  uint32_t accum;
+};
+
+constexpr uint32_t kStep0 = 1;
+constexpr uint32_t kStep1 = kStep0 * 33;
+constexpr uint32_t kStep2 = kStep1 * 33;
+constexpr uint32_t kStep3 = kStep2 * 33;
+constexpr uint32_t kStep4 = kStep3 * 33;
+constexpr uint32_t kStep5 = kStep4 * 33;
+constexpr uint32_t kStep6 = kStep5 * 33;
+constexpr uint32_t kStep7 = kStep6 * 33;
+constexpr uint32_t kStep8 = kStep7 * 33;
+constexpr uint32_t kStep9 = kStep8 * 33;
+constexpr uint32_t kStep10 = kStep9 * 33;
+constexpr uint32_t kStep11 = kStep10 * 33;
+
+// Step by -1 through -7:  33 * 0x3e0f83e1 == 1 (mod 2**32)
+constexpr uint32_t kStepN1 = kStep0 * 0x3e0f83e1;
+constexpr uint32_t kStepN2 = kStepN1 * 0x3e0f83e1;
+constexpr uint32_t kStepN3 = kStepN2 * 0x3e0f83e1;
+constexpr uint32_t kStepN4 = kStepN3 * 0x3e0f83e1;
+constexpr uint32_t kStepN5 = kStepN4 * 0x3e0f83e1;
+constexpr uint32_t kStepN6 = kStepN5 * 0x3e0f83e1;
+constexpr uint32_t kStepN7 = kStepN6 * 0x3e0f83e1;
+
+// Calculate the GNU hash and string length of the symbol name.
+//
+// The hash calculation is an optimized version of this function:
+//
+//    uint32_t calculate_gnu_hash(const uint8_t* name) {
+//      uint32_t h = 5381;
+//      for (; *name != '\0'; ++name) {
+//        h *= 33;
+//        h += *name;
+//      }
+//      return h;
+//    }
+//
+std::pair<uint32_t, uint32_t> calculate_gnu_hash_neon(const char* name) {
+
+  // The input string may be misaligned by 0-7 bytes (K). This function loads the first aligned
+  // 8-byte chunk, then counteracts the misalignment:
+  //  - The initial K bytes are set to 0xff in the working chunk vector.
+  //  - The accumulator is initialized to 5381 * modinv(33)**K.
+  //  - The accumulator also cancels out each initial 0xff byte.
+  // If we could set bytes to NUL instead, then the accumulator wouldn't need to cancel out the
+  // 0xff values, but this would break the NUL check.
+
+  static const struct GnuHashInitEntry kInitTable[] = {
+    { // (addr&7) == 0
+      0ull,
+      5381u*kStep0,
+    }, { // (addr&7) == 1
+      0xffull,
+      5381u*kStepN1 - 0xffu*kStepN1,
+    }, { // (addr&7) == 2
+      0xffffull,
+      5381u*kStepN2 - 0xffu*kStepN1 - 0xffu*kStepN2,
+    }, { // (addr&7) == 3
+      0xffffffull,
+      5381u*kStepN3 - 0xffu*kStepN1 - 0xffu*kStepN2 - 0xffu*kStepN3,
+    }, { // (addr&7) == 4
+      0xffffffffull,
+      5381u*kStepN4 - 0xffu*kStepN1 - 0xffu*kStepN2 - 0xffu*kStepN3 - 0xffu*kStepN4,
+    }, { // (addr&7) == 5
+      0xffffffffffull,
+      5381u*kStepN5 - 0xffu*kStepN1 - 0xffu*kStepN2 - 0xffu*kStepN3 - 0xffu*kStepN4 - 0xffu*kStepN5,
+    }, { // (addr&7) == 6
+      0xffffffffffffull,
+      5381u*kStepN6 - 0xffu*kStepN1 - 0xffu*kStepN2 - 0xffu*kStepN3 - 0xffu*kStepN4 - 0xffu*kStepN5 - 0xffu*kStepN6,
+    }, { // (addr&7) == 7
+      0xffffffffffffffull,
+      5381u*kStepN7 - 0xffu*kStepN1 - 0xffu*kStepN2 - 0xffu*kStepN3 - 0xffu*kStepN4 - 0xffu*kStepN5 - 0xffu*kStepN6 - 0xffu*kStepN7,
+    },
+  };
+
+  uint8_t offset = reinterpret_cast<uintptr_t>(name) & 7;
+  const uint64_t* chunk_ptr = reinterpret_cast<const uint64_t*>(reinterpret_cast<uintptr_t>(name) & ~7);
+  const struct GnuHashInitEntry* entry = &kInitTable[offset];
+
+  uint8x8_t chunk = vld1_u8(reinterpret_cast<const uint8_t*>(chunk_ptr));
+  chunk |= vld1_u8(reinterpret_cast<const uint8_t*>(&entry->ignore_mask));
+
+  uint32x4_t accum_lo = { 0 };
+  uint32x4_t accum_hi = { entry->accum, 0, 0, 0 };
+  const uint16x4_t kInclineVec = { kStep3, kStep2, kStep1, kStep0 };
+  const uint32x4_t kStep8Vec = vdupq_n_u32(kStep8);
+  uint8x8_t is_nul;
+  uint16x8_t expand;
+
+  while (1) {
+    // Exit the loop if any of the 8 bytes is NUL.
+    is_nul = vceq_u8(chunk, (uint8x8_t){ 0 });
+    expand = vmovl_u8(chunk);
+    uint64x1_t is_nul_64 = vreinterpret_u64_u8(is_nul);
+    if (vget_lane_u64(is_nul_64, 0)) break;
+
+    // Multiply both accumulators by 33**8.
+    accum_lo = vmulq_u32(accum_lo, kStep8Vec);
+    accum_hi = vmulq_u32(accum_hi, kStep8Vec);
+
+    // Multiply each 4-piece subchunk by (33**3, 33**2, 33*1, 1), then accumulate the result. The lo
+    // accumulator will be behind by 33**4 until the very end of the computation.
+    accum_lo = vmlal_u16(accum_lo, vget_low_u16(expand), kInclineVec);
+    accum_hi = vmlal_u16(accum_hi, vget_high_u16(expand), kInclineVec);
+
+    // Load the next chunk.
+    chunk = vld1_u8(reinterpret_cast<const uint8_t*>(++chunk_ptr));
+  }
+
+  // Reverse the is-NUL vector so we can use clz to count the number of remaining bytes.
+  is_nul = vrev64_u8(is_nul);
+  const uint64_t is_nul_u64 = vget_lane_u64(vreinterpret_u64_u8(is_nul), 0);
+  const uint32_t num_valid_bits = is_nul_u64 == 0 ? 64 : __builtin_clzll(is_nul_u64);
+
+  const uint32_t name_len = reinterpret_cast<const char*>(chunk_ptr) - name + (num_valid_bits >> 3);
+
+  static const uint32_t kFinalStepTable[] = {
+    kStep4, kStep0,   // 0 remaining bytes
+    kStep5, kStep1,   // 1 remaining byte
+    kStep6, kStep2,   // 2 remaining bytes
+    kStep7, kStep3,   // 3 remaining bytes
+    kStep8, kStep4,   // 4 remaining bytes
+    kStep9, kStep5,   // 5 remaining bytes
+    kStep10, kStep6,  // 6 remaining bytes
+    kStep11, kStep7,  // 7 remaining bytes
+  };
+
+  // Advance the lo/hi accumulators appropriately for the number of remaining bytes. Multiply 33**4
+  // into the lo accumulator to catch it up with the hi accumulator.
+  const uint32_t* final_step = &kFinalStepTable[num_valid_bits >> 2];
+  accum_lo = vmulq_u32(accum_lo, vdupq_n_u32(final_step[0]));
+  accum_lo = vmlaq_u32(accum_lo, accum_hi, vdupq_n_u32(final_step[1]));
+
+  static const uint32_t kFinalInclineTable[] = {
+    0,      kStep6, kStep5, kStep4, kStep3, kStep2, kStep1, kStep0,
+    0,      0,      0,      0,      0,      0,      0,      0,
+  };
+
+  // Prepare a vector to multiply powers of 33 into each of the remaining bytes.
+  const uint32_t* const incline = &kFinalInclineTable[8 - (num_valid_bits >> 3)];
+  const uint32x4_t incline_lo = vld1q_u32(incline);
+  const uint32x4_t incline_hi = vld1q_u32(incline + 4);
+
+  // Multiply 33 into each of the remaining 4-piece vectors, then accumulate everything into
+  // accum_lo. Combine everything into a single 32-bit result.
+  accum_lo = vmlaq_u32(accum_lo, vmovl_u16(vget_low_u16(expand)), incline_lo);
+  accum_lo = vmlaq_u32(accum_lo, vmovl_u16(vget_high_u16(expand)), incline_hi);
+
+  uint32x2_t sum = vadd_u32(vget_low_u32(accum_lo), vget_high_u32(accum_lo));
+  const uint32_t hash = sum[0] + sum[1];
+
+  return { hash, name_len };
+}
diff --git a/linker/arch/arm_neon/linker_gnu_hash_neon.h b/linker/arch/arm_neon/linker_gnu_hash_neon.h
new file mode 100644
index 0000000..647d640
--- /dev/null
+++ b/linker/arch/arm_neon/linker_gnu_hash_neon.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <stdint.h>
+
+#include <utility>
+
+std::pair<uint32_t, uint32_t> calculate_gnu_hash_neon(const char* name);
diff --git a/linker/linker_gnu_hash.h b/linker/linker_gnu_hash.h
index 8375743..f85e801 100644
--- a/linker/linker_gnu_hash.h
+++ b/linker/linker_gnu_hash.h
@@ -32,7 +32,18 @@
 
 #include <utility>
 
-static inline std::pair<uint32_t, uint32_t> calculate_gnu_hash(const char* name) {
+#if defined(__arm__) || defined(__aarch64__)
+#define USE_GNU_HASH_NEON 1
+#else
+#define USE_GNU_HASH_NEON 0
+#endif
+
+#if USE_GNU_HASH_NEON
+#include "arch/arm_neon/linker_gnu_hash_neon.h"
+#endif
+
+__attribute__((unused))
+static std::pair<uint32_t, uint32_t> calculate_gnu_hash_simple(const char* name) {
   uint32_t h = 5381;
   const uint8_t* name_bytes = reinterpret_cast<const uint8_t*>(name);
   #pragma unroll 8
@@ -41,3 +52,11 @@
   }
   return { h, reinterpret_cast<const char*>(name_bytes) - name };
 }
+
+static inline std::pair<uint32_t, uint32_t> calculate_gnu_hash(const char* name) {
+#if USE_GNU_HASH_NEON
+  return calculate_gnu_hash_neon(name);
+#else
+  return calculate_gnu_hash_simple(name);
+#endif
+}
diff --git a/linker/linker_gnu_hash_benchmark.cpp b/linker/linker_gnu_hash_benchmark.cpp
new file mode 100644
index 0000000..dbbbc00
--- /dev/null
+++ b/linker/linker_gnu_hash_benchmark.cpp
@@ -0,0 +1,311 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <benchmark/benchmark.h>
+
+#include "linker_gnu_hash.h"
+
+// 250 symbols from the relocations of system/lib/libhwbinder.so in aosp/master, aosp_walleye.
+// ROT13-encoded so as not to pollute code search.
+static const char* const kSampleSymbolList[] = {
+    "_MA7naqebvq8uneqjner9OUjOvaqre8genafnpgRwEXAF0_6CnepryRCF2_wAFg3__18shapgvbaVSiEF2_RRR",
+    "_MA7naqebvq8uneqjner9OUjOvaqre11yvaxGbQrnguREXAF_2fcVAF0_7VOvaqre14QrnguErpvcvragRRRCiw",
+    "_MA7naqebvq8uneqjner9OUjOvaqre13hayvaxGbQrnguREXAF_2jcVAF0_7VOvaqre14QrnguErpvcvragRRRCiwCF5_",
+    "_MAX7naqebvq8uneqjner7VOvaqre13purpxFhopynffRCXi",
+    "_MA7naqebvq8uneqjner9OUjOvaqre12nggnpuBowrpgRCXiCiF4_CSiF3_F4_F4_R",
+    "_MAX7naqebvq8uneqjner9OUjOvaqre10svaqBowrpgRCXi",
+    "_MA7naqebvq8uneqjner9OUjOvaqre12qrgnpuBowrpgRCXi",
+    "_MA7naqebvq8uneqjner9OUjOvaqre11ybpnyOvaqreRi",
+    "_MA7naqebvq8uneqjner7VOvaqre12erzbgrOvaqreRi",
+    "_MA7naqebvq8uneqjner9OUjOvaqreQ1Ri",
+    "_MA7naqebvq8uneqjner9OUjOvaqreQ0Ri",
+    "_MA7naqebvq8uneqjner9OUjOvaqre10baGenafnpgRwEXAF0_6CnepryRCF2_wAFg3__18shapgvbaVSiEF2_RRR",
+    "_MGi0_a12_A7naqebvq8uneqjner9OUjOvaqreQ1Ri",
+    "_MGi0_a12_A7naqebvq8uneqjner9OUjOvaqreQ0Ri",
+    "_MA7naqebvq7ErsOnfr10baSvefgErsRi",
+    "_MA7naqebvq7ErsOnfr15baYnfgFgebatErsRCXi",
+    "_MA7naqebvq7ErsOnfr20baVapFgebatNggrzcgrqRwCXi",
+    "_MA7naqebvq7ErsOnfr13baYnfgJrnxErsRCXi",
+    "_MA7naqebvq8uneqjner11OcUjErsOnfrQ1Ri",
+    "_MA7naqebvq8uneqjner11OcUjErsOnfrQ0Ri",
+    "_MA7naqebvq8uneqjner11OcUjErsOnfr10baSvefgErsRi",
+    "_MA7naqebvq8uneqjner11OcUjErsOnfr15baYnfgFgebatErsRCXi",
+    "_MA7naqebvq8uneqjner11OcUjErsOnfr20baVapFgebatNggrzcgrqRwCXi",
+    "_MGi0_a12_A7naqebvq8uneqjner11OcUjErsOnfrQ1Ri",
+    "_MGi0_a12_A7naqebvq8uneqjner11OcUjErsOnfrQ0Ri",
+    "_MGi0_a16_A7naqebvq8uneqjner11OcUjErsOnfr10baSvefgErsRi",
+    "_MGi0_a20_A7naqebvq8uneqjner11OcUjErsOnfr15baYnfgFgebatErsRCXi",
+    "_MGi0_a24_A7naqebvq8uneqjner11OcUjErsOnfr20baVapFgebatNggrzcgrqRwCXi",
+    "_MA7naqebvq7ErsOnfr13baYnfgJrnxErsRCXi",
+    "__pkn_cher_iveghny",
+    "__pkn_cher_iveghny",
+    "__pkn_cher_iveghny",
+    "_MAX7naqebvq8uneqjner7VOvaqre13purpxFhopynffRCXi",
+    "__pkn_cher_iveghny",
+    "__pkn_cher_iveghny",
+    "__pkn_cher_iveghny",
+    "_MA7naqebvq8uneqjner7VOvaqre11ybpnyOvaqreRi",
+    "_MA7naqebvq8uneqjner7VOvaqre12erzbgrOvaqreRi",
+    "_MA7naqebvq8uneqjner7VOvaqreQ1Ri",
+    "_MA7naqebvq8uneqjner7VOvaqreQ0Ri",
+    "_MGi0_a12_A7naqebvq8uneqjner7VOvaqreQ1Ri",
+    "_MGi0_a12_A7naqebvq8uneqjner7VOvaqreQ0Ri",
+    "_MA7naqebvq7ErsOnfr10baSvefgErsRi",
+    "_MA7naqebvq7ErsOnfr15baYnfgFgebatErsRCXi",
+    "_MA7naqebvq7ErsOnfr20baVapFgebatNggrzcgrqRwCXi",
+    "_MA7naqebvq7ErsOnfr13baYnfgJrnxErsRCXi",
+    "__pkn_cher_iveghny",
+    "__pkn_cher_iveghny",
+    "__pkn_cher_iveghny",
+    "_MAX7naqebvq8uneqjner7VOvaqre13purpxFhopynffRCXi",
+    "__pkn_cher_iveghny",
+    "__pkn_cher_iveghny",
+    "__pkn_cher_iveghny",
+    "_MA7naqebvq8uneqjner7VOvaqre11ybpnyOvaqreRi",
+    "_MA7naqebvq8uneqjner7VOvaqre12erzbgrOvaqreRi",
+    "_MA7naqebvq8uneqjner7VOvaqreQ1Ri",
+    "_MA7naqebvq8uneqjner7VOvaqreQ0Ri",
+    "_MGi0_a12_A7naqebvq8uneqjner7VOvaqreQ1Ri",
+    "_MGi0_a12_A7naqebvq8uneqjner7VOvaqreQ0Ri",
+    "_MA7naqebvq7ErsOnfr10baSvefgErsRi",
+    "_MA7naqebvq7ErsOnfr15baYnfgFgebatErsRCXi",
+    "_MA7naqebvq7ErsOnfr20baVapFgebatNggrzcgrqRwCXi",
+    "_MA7naqebvq7ErsOnfr13baYnfgJrnxErsRCXi",
+    "_MA7naqebvq8uneqjner10OcUjOvaqre8genafnpgRwEXAF0_6CnepryRCF2_wAFg3__18shapgvbaVSiEF2_RRR",
+    "_MA7naqebvq8uneqjner10OcUjOvaqre11yvaxGbQrnguREXAF_2fcVAF0_7VOvaqre14QrnguErpvcvragRRRCiw",
+    "_MA7naqebvq8uneqjner10OcUjOvaqre13hayvaxGbQrnguREXAF_2jcVAF0_7VOvaqre14QrnguErpvcvragRRRCiwCF5_",
+    "_MAX7naqebvq8uneqjner7VOvaqre13purpxFhopynffRCXi",
+    "_MA7naqebvq8uneqjner10OcUjOvaqre12nggnpuBowrpgRCXiCiF4_CSiF3_F4_F4_R",
+    "_MAX7naqebvq8uneqjner10OcUjOvaqre10svaqBowrpgRCXi",
+    "_MA7naqebvq8uneqjner10OcUjOvaqre12qrgnpuBowrpgRCXi",
+    "_MA7naqebvq8uneqjner7VOvaqre11ybpnyOvaqreRi",
+    "_MA7naqebvq8uneqjner10OcUjOvaqre12erzbgrOvaqreRi",
+    "_MA7naqebvq8uneqjner10OcUjOvaqreQ1Ri",
+    "_MA7naqebvq8uneqjner10OcUjOvaqreQ0Ri",
+    "_MA7naqebvq8uneqjner10OcUjOvaqre10baSvefgErsRi",
+    "_MA7naqebvq8uneqjner10OcUjOvaqre15baYnfgFgebatErsRCXi",
+    "_MA7naqebvq8uneqjner10OcUjOvaqre20baVapFgebatNggrzcgrqRwCXi",
+    "_MGi0_a12_A7naqebvq8uneqjner10OcUjOvaqreQ1Ri",
+    "_MGi0_a12_A7naqebvq8uneqjner10OcUjOvaqreQ0Ri",
+    "_MGi0_a16_A7naqebvq8uneqjner10OcUjOvaqre10baSvefgErsRi",
+    "_MGi0_a20_A7naqebvq8uneqjner10OcUjOvaqre15baYnfgFgebatErsRCXi",
+    "_MGi0_a24_A7naqebvq8uneqjner10OcUjOvaqre20baVapFgebatNggrzcgrqRwCXi",
+    "_MA7naqebvq7ErsOnfr13baYnfgJrnxErsRCXi",
+    "__pkn_cher_iveghny",
+    "__pkn_cher_iveghny",
+    "__pkn_cher_iveghny",
+    "_MAX7naqebvq8uneqjner7VOvaqre13purpxFhopynffRCXi",
+    "__pkn_cher_iveghny",
+    "__pkn_cher_iveghny",
+    "__pkn_cher_iveghny",
+    "_MA7naqebvq8uneqjner7VOvaqre11ybpnyOvaqreRi",
+    "_MA7naqebvq8uneqjner7VOvaqre12erzbgrOvaqreRi",
+    "_MA7naqebvq8uneqjner7VOvaqreQ1Ri",
+    "_MA7naqebvq8uneqjner7VOvaqreQ0Ri",
+    "_MGi0_a12_A7naqebvq8uneqjner7VOvaqreQ1Ri",
+    "_MGi0_a12_A7naqebvq8uneqjner7VOvaqreQ0Ri",
+    "_MA7naqebvq7ErsOnfr10baSvefgErsRi",
+    "_MA7naqebvq7ErsOnfr15baYnfgFgebatErsRCXi",
+    "_MA7naqebvq7ErsOnfr20baVapFgebatNggrzcgrqRwCXi",
+    "_MA7naqebvq7ErsOnfr13baYnfgJrnxErsRCXi",
+    "_MA7naqebvq8uneqjner18OhssrerqGrkgBhgchgQ2Ri",
+    "_MA7naqebvq8uneqjner18OhssrerqGrkgBhgchgQ0Ri",
+    "_MA7naqebvq8uneqjner18OhssrerqGrkgBhgchg5cevagRCXpw",
+    "_MA7naqebvq8uneqjner18OhssrerqGrkgBhgchg10zbirVaqragRv",
+    "_MA7naqebvq8uneqjner18OhssrerqGrkgBhgchg10chfuOhaqyrRi",
+    "_MA7naqebvq8uneqjner18OhssrerqGrkgBhgchg9cbcOhaqyrRi",
+    "__pkn_cher_iveghny",
+    "_MA7naqebvq7ErsOnfr10baSvefgErsRi",
+    "_MA7naqebvq7ErsOnfr15baYnfgFgebatErsRCXi",
+    "_MA7naqebvq7ErsOnfr20baVapFgebatNggrzcgrqRwCXi",
+    "_MA7naqebvq7ErsOnfr13baYnfgJrnxErsRCXi",
+    "_MA7naqebvq8uneqjner10VVagresnprQ1Ri",
+    "_MA7naqebvq8uneqjner10VVagresnprQ0Ri",
+    "__pkn_cher_iveghny",
+    "_MGi0_a12_A7naqebvq8uneqjner10VVagresnprQ1Ri",
+    "_MGi0_a12_A7naqebvq8uneqjner10VVagresnprQ0Ri",
+    "_MA7naqebvq7ErsOnfr10baSvefgErsRi",
+    "_MA7naqebvq7ErsOnfr15baYnfgFgebatErsRCXi",
+    "_MA7naqebvq7ErsOnfr20baVapFgebatNggrzcgrqRwCXi",
+    "_MA7naqebvq7ErsOnfr13baYnfgJrnxErsRCXi",
+    "_MAFg3__114onfvp_vbfgernzVpAF_11pune_genvgfVpRRRQ1Ri",
+    "_MAFg3__114onfvp_vbfgernzVpAF_11pune_genvgfVpRRRQ0Ri",
+    "_MGua8_AFg3__114onfvp_vbfgernzVpAF_11pune_genvgfVpRRRQ1Ri",
+    "_MGua8_AFg3__114onfvp_vbfgernzVpAF_11pune_genvgfVpRRRQ0Ri",
+    "_MGi0_a12_AFg3__114onfvp_vbfgernzVpAF_11pune_genvgfVpRRRQ1Ri",
+    "_MGi0_a12_AFg3__114onfvp_vbfgernzVpAF_11pune_genvgfVpRRRQ0Ri",
+    "_MAFg3__113onfvp_vfgernzVpAF_11pune_genvgfVpRRRQ1Ri",
+    "_MAFg3__113onfvp_vfgernzVpAF_11pune_genvgfVpRRRQ0Ri",
+    "_MGi0_a12_AFg3__113onfvp_vfgernzVpAF_11pune_genvgfVpRRRQ1Ri",
+    "_MGi0_a12_AFg3__113onfvp_vfgernzVpAF_11pune_genvgfVpRRRQ0Ri",
+    "_MAFg3__113onfvp_bfgernzVpAF_11pune_genvgfVpRRRQ1Ri",
+    "_MAFg3__113onfvp_bfgernzVpAF_11pune_genvgfVpRRRQ0Ri",
+    "_MGi0_a12_AFg3__113onfvp_bfgernzVpAF_11pune_genvgfVpRRRQ1Ri",
+    "_MGi0_a12_AFg3__113onfvp_bfgernzVpAF_11pune_genvgfVpRRRQ0Ri",
+    "_MAFg3__115onfvp_fgernzohsVpAF_11pune_genvgfVpRRR5vzohrREXAF_6ybpnyrR",
+    "_MAFg3__115onfvp_fgernzohsVpAF_11pune_genvgfVpRRR6frgohsRCpv",
+    "_MAFg3__115onfvp_fgernzohsVpAF_11pune_genvgfVpRRR4flapRi",
+    "_MAFg3__115onfvp_fgernzohsVpAF_11pune_genvgfVpRRR9fubjznalpRi",
+    "_MAFg3__115onfvp_fgernzohsVpAF_11pune_genvgfVpRRR6kftrgaRCpv",
+    "_MAFg3__115onfvp_fgernzohsVpAF_11pune_genvgfVpRRR5hsybjRi",
+    "_MAFg3__115onfvp_fgernzohsVpAF_11pune_genvgfVpRRR6kfchgaRCXpv",
+    "_MA7naqebvq8uneqjner12CebprffFgngrQ1Ri",
+    "_MA7naqebvq8uneqjner12CebprffFgngrQ0Ri",
+    "_MGi0_a12_A7naqebvq8uneqjner12CebprffFgngrQ1Ri",
+    "_MGi0_a12_A7naqebvq8uneqjner12CebprffFgngrQ0Ri",
+    "_MA7naqebvq7ErsOnfr10baSvefgErsRi",
+    "_MA7naqebvq7ErsOnfr15baYnfgFgebatErsRCXi",
+    "_MA7naqebvq7ErsOnfr20baVapFgebatNggrzcgrqRwCXi",
+    "_MA7naqebvq7ErsOnfr13baYnfgJrnxErsRCXi",
+    "_MA7naqebvq6Guernq3ehaRCXpvw",
+    "_MA7naqebvq6Guernq11erdhrfgRkvgRi",
+    "_MA7naqebvq6Guernq10ernqlGbEhaRi",
+    "_MA7naqebvq7ErsOnfr10baSvefgErsRi",
+    "_MA7naqebvq7ErsOnfr15baYnfgFgebatErsRCXi",
+    "_MA7naqebvq7ErsOnfr20baVapFgebatNggrzcgrqRwCXi",
+    "_MA7naqebvq7ErsOnfr13baYnfgJrnxErsRCXi",
+    "_MA7naqebvq6GuernqQ1Ri",
+    "_MA7naqebvq6GuernqQ0Ri",
+    "_MA7naqebvq6Guernq3ehaRCXpvw",
+    "_MA7naqebvq6Guernq11erdhrfgRkvgRi",
+    "_MA7naqebvq6Guernq10ernqlGbEhaRi",
+    "__pkn_cher_iveghny",
+    "_MGi0_a12_A7naqebvq6GuernqQ1Ri",
+    "_MGi0_a12_A7naqebvq6GuernqQ0Ri",
+    "_MA7naqebvq7ErsOnfr10baSvefgErsRi",
+    "_MA7naqebvq7ErsOnfr15baYnfgFgebatErsRCXi",
+    "_MA7naqebvq7ErsOnfr20baVapFgebatNggrzcgrqRwCXi",
+    "_MA7naqebvq7ErsOnfr13baYnfgJrnxErsRCXi",
+    "_MA7naqebvq8uneqjner18OhssrerqGrkgBhgchgQ2Ri",
+    "_MA7naqebvq8uneqjner18OhssrerqGrkgBhgchg5cevagRCXpw",
+    "_MA7naqebvq8uneqjner18OhssrerqGrkgBhgchg10zbirVaqragRv",
+    "_MA7naqebvq8uneqjner18OhssrerqGrkgBhgchg10chfuOhaqyrRi",
+    "_MA7naqebvq8uneqjner18OhssrerqGrkgBhgchg9cbcOhaqyrRi",
+    "_MA7naqebvq8uneqjner18OhssrerqGrkgBhgchgQ2Ri",
+    "_MA7naqebvq8uneqjner18OhssrerqGrkgBhgchg5cevagRCXpw",
+    "_MA7naqebvq8uneqjner18OhssrerqGrkgBhgchg10zbirVaqragRv",
+    "_MA7naqebvq8uneqjner18OhssrerqGrkgBhgchg10chfuOhaqyrRi",
+    "_MA7naqebvq8uneqjner18OhssrerqGrkgBhgchg9cbcOhaqyrRi",
+    "_MA7naqebvq8uneqjner10GrkgBhgchgQ2Ri",
+    "_MA7naqebvq8uneqjner10GrkgBhgchgQ0Ri",
+    "__pkn_cher_iveghny",
+    "__pkn_cher_iveghny",
+    "__pkn_cher_iveghny",
+    "__pkn_cher_iveghny",
+    "_MGIA7naqebvq8uneqjner9OUjOvaqreR",
+    "_MGPA7naqebvq8uneqjner9OUjOvaqreR0_AF0_7VOvaqreR",
+    "_MGPA7naqebvq8uneqjner9OUjOvaqreR0_AF0_7VOvaqreR",
+    "_MGIA7naqebvq8uneqjner9OUjOvaqreR",
+    "_MGIA7naqebvq8uneqjner11OcUjErsOnfrR",
+    "_MGIA7naqebvq8uneqjner11OcUjErsOnfrR",
+    "_MGIA7naqebvq8uneqjner7VOvaqreR",
+    "_MGIA7naqebvq8uneqjner7VOvaqreR",
+    "_MGIA7naqebvq8uneqjner10OcUjOvaqreR",
+    "_MGPA7naqebvq8uneqjner10OcUjOvaqreR0_AF0_7VOvaqreR",
+    "_MGPA7naqebvq8uneqjner10OcUjOvaqreR0_AF0_7VOvaqreR",
+    "_MGIA7naqebvq8uneqjner10OcUjOvaqreR",
+    "_MGIA7naqebvq8uneqjner10VVagresnprR",
+    "_MGIA7naqebvq8uneqjner10VVagresnprR",
+    "_MGIAFg3__118onfvp_fgevatfgernzVpAF_11pune_genvgfVpRRAF_9nyybpngbeVpRRRR",
+    "_MGPAFg3__118onfvp_fgevatfgernzVpAF_11pune_genvgfVpRRAF_9nyybpngbeVpRRRR0_AF_14onfvp_vbfgernzVpF2_RR",
+    "_MGPAFg3__118onfvp_fgevatfgernzVpAF_11pune_genvgfVpRRAF_9nyybpngbeVpRRRR0_AF_13onfvp_vfgernzVpF2_RR",
+    "_MGPAFg3__118onfvp_fgevatfgernzVpAF_11pune_genvgfVpRRAF_9nyybpngbeVpRRRR0_AF_13onfvp_vfgernzVpF2_RR",
+    "_MGPAFg3__118onfvp_fgevatfgernzVpAF_11pune_genvgfVpRRAF_9nyybpngbeVpRRRR8_AF_13onfvp_bfgernzVpF2_RR",
+    "_MGPAFg3__118onfvp_fgevatfgernzVpAF_11pune_genvgfVpRRAF_9nyybpngbeVpRRRR8_AF_13onfvp_bfgernzVpF2_RR",
+    "_MGPAFg3__118onfvp_fgevatfgernzVpAF_11pune_genvgfVpRRAF_9nyybpngbeVpRRRR0_AF_14onfvp_vbfgernzVpF2_RR",
+    "_MGPAFg3__118onfvp_fgevatfgernzVpAF_11pune_genvgfVpRRAF_9nyybpngbeVpRRRR0_AF_14onfvp_vbfgernzVpF2_RR",
+    "_MGIAFg3__118onfvp_fgevatfgernzVpAF_11pune_genvgfVpRRAF_9nyybpngbeVpRRRR",
+    "_MGIAFg3__118onfvp_fgevatfgernzVpAF_11pune_genvgfVpRRAF_9nyybpngbeVpRRRR",
+    "_MGIA7naqebvq8uneqjner12CebprffFgngrR",
+    "_MGIA7naqebvq8uneqjner12CebprffFgngrR",
+    "_MGIA7naqebvq8uneqjner10CbbyGuernqR",
+    "_MGPA7naqebvq8uneqjner10CbbyGuernqR0_AF_6GuernqR",
+    "_MGPA7naqebvq8uneqjner10CbbyGuernqR0_AF_6GuernqR",
+    "_MGIA7naqebvq8uneqjner10CbbyGuernqR",
+    "_MGIA7naqebvq8uneqjner9OUjOvaqreR",
+    "__fgnpx_pux_thneq",
+    "_MGIA7naqebvq8uneqjner11OcUjErsOnfrR",
+    "_MGIA7naqebvq12FbegrqIrpgbeVAF_16xrl_inyhr_cnve_gVCXiAF_8uneqjner10OcUjOvaqre13BowrpgZnantre7ragel_gRRRRR",
+    "_MGPA7naqebvq8uneqjner10OcUjOvaqreR0_AF0_7VOvaqreR",
+    "_MGIA7naqebvq8uneqjner10OcUjOvaqreR",
+    "_MGIA7naqebvq6IrpgbeVAF_8uneqjner10OcUjOvaqre8BovghnelRRR",
+    "_MGGA7naqebvq8uneqjner10OcUjOvaqreR",
+    "_MGIA7naqebvq6IrpgbeVAF_2fcVAF_8uneqjner18OhssrerqGrkgBhgchg11OhssreFgngrRRRRR",
+    "_MA7naqebvq8uneqjner18OhssrerqGrkgBhgchg16guernqQrfgehpgbeRCi",
+    "_MGIA7naqebvq8uneqjner18OhssrerqGrkgBhgchgR",
+    "_MA7naqebvq8uneqjner12tGrkgOhssrefR",
+    "_MGIA7naqebvq8uneqjner18OhssrerqGrkgBhgchg11OhssreFgngrR",
+    "_MA7naqebvq8uneqjner14VCPGuernqFgngr16guernqQrfgehpgbeRCi",
+    "_MA7naqebvq8uneqjner14VCPGuernqFgngr10serrOhssreRCAF0_6CnepryRCXuwCXlwCi",
+    "_MA7naqebvq8uneqjner18gur_pbagrkg_bowrpgR",
+    "_MA7naqebvq9PnyyFgnpx18trgPheeragVagreanyRv",
+    "_MA7naqebvq9PnyyFgnpx16ybtFgnpxVagreanyRCXpCXF0_19naqebvq_YbtCevbevgl",
+    "_MGIA7naqebvq6IrpgbeVCAF_8uneqjner9OUjOvaqreRRR",
+    "_MGIA7naqebvq6IrpgbeVCAF_7ErsOnfr12jrnxers_glcrRRR",
+    "_MGIA7naqebvq6IrpgbeVCAF_7ErsOnfrRRR",
+    "_MFg7abguebj",
+    "_MGPAFg3__118onfvp_fgevatfgernzVpAF_11pune_genvgfVpRRAF_9nyybpngbeVpRRRR0_AF_13onfvp_vfgernzVpF2_RR",
+    "_MGIAFg3__118onfvp_fgevatfgernzVpAF_11pune_genvgfVpRRAF_9nyybpngbeVpRRRR",
+    "_MGIAFg3__115onfvp_fgevatohsVpAF_11pune_genvgfVpRRAF_9nyybpngbeVpRRRR",
+    "_MAFg3__15pglcrVpR2vqR",
+    "_MA7naqebvq8uneqjner13tCebprffZhgrkR",
+    "_MA7naqebvq8uneqjner8tCebprffR",
+    "_MGIA7naqebvq8uneqjner12CebprffFgngrR",
+    "_MGIA7naqebvq6IrpgbeVAF_8uneqjner12CebprffFgngr12unaqyr_ragelRRR",
+    "_MGIA7naqebvq12FbegrqIrpgbeVAF_16xrl_inyhr_cnve_gVAF_8Fgevat16RAF_2fcVAF_8uneqjner7VOvaqreRRRRRRR",
+    "_MGIA7naqebvq8uneqjner10CbbyGuernqR",
+    "_MGGA7naqebvq8uneqjner12CebprffFgngrR",
+    "_MGIA7naqebvq6IrpgbeVvRR",
+    "_MGIA7naqebvq8uneqjner13YbtGrkgBhgchgR",
+};
+
+static void BM_gnu_hash_simple(benchmark::State& state) {
+  for (auto _ : state) {
+    for (const char* sym_name : kSampleSymbolList) {
+      benchmark::DoNotOptimize(calculate_gnu_hash_simple(sym_name));
+    }
+  }
+}
+
+BENCHMARK(BM_gnu_hash_simple);
+
+#if USE_GNU_HASH_NEON
+
+static void BM_gnu_hash_neon(benchmark::State& state) {
+  for (auto _ : state) {
+    for (const char* sym_name : kSampleSymbolList) {
+      benchmark::DoNotOptimize(calculate_gnu_hash_neon(sym_name));
+    }
+  }
+}
+
+BENCHMARK(BM_gnu_hash_neon);
+
+#endif  // USE_GNU_HASH_NEON
+
+BENCHMARK_MAIN();
diff --git a/linker/linker_gnu_hash_test.cpp b/linker/linker_gnu_hash_test.cpp
new file mode 100644
index 0000000..a289749
--- /dev/null
+++ b/linker/linker_gnu_hash_test.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <gtest/gtest.h>
+
+#include "linker_gnu_hash.h"
+
+TEST(linker_gnu_hash, compare_neon_to_simple) {
+#if USE_GNU_HASH_NEON
+  auto check_input = [&](const char* name) {
+    auto expected = calculate_gnu_hash_simple(name);
+    auto actual = calculate_gnu_hash_neon(name);
+    EXPECT_EQ(expected.first, actual.first) << name;
+    EXPECT_EQ(expected.second, actual.second) << name;
+  };
+
+  __attribute__((aligned(8))) const char test1[] = "abcdefghijklmnop\0qrstuvwxyz";
+  for (size_t i = 0; i < sizeof(test1) - 1; ++i) {
+    check_input(&test1[i]);
+  }
+
+  __attribute__((aligned(8))) const char test2[] = "abcdefghijklmnopqrs\0tuvwxyz";
+  for (size_t i = 0; i < sizeof(test2) - 1; ++i) {
+    check_input(&test2[i]);
+  }
+
+  __attribute__((aligned(8))) const char test3[] = "abcdefghijklmnopqrstuv\0wxyz";
+  for (size_t i = 0; i < sizeof(test3) - 1; ++i) {
+    check_input(&test3[i]);
+  }
+#else
+  GTEST_SKIP() << "This test is only implemented on arm/arm64";
+#endif
+}
diff --git a/tests/Android.build.mk b/tests/Android.build.mk
deleted file mode 100644
index 04fc92d..0000000
--- a/tests/Android.build.mk
+++ /dev/null
@@ -1,128 +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)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(common_additional_dependencies)
-
-LOCAL_MODULE := $(module)
-LOCAL_MODULE_TAGS := $(module_tag)
-ifeq ($(build_type),host)
-  # Always make host multilib
-  LOCAL_MULTILIB := both
-endif
-
-ifneq ($(findstring LIBRARY, $(build_target)),LIBRARY)
-  LOCAL_MODULE_STEM_32 := $(module)32
-  LOCAL_MODULE_STEM_64 := $(module)64
-else
-ifneq ($($(module)_install_to_native_tests_dir),)
-  ifeq ($(build_type),host)
-    native_tests_var := HOST_OUT_NATIVE_TESTS
-  else
-    native_tests_var := TARGET_OUT_DATA_NATIVE_TESTS
-  endif
-
-  ifneq ($($(module)_install_to_native_tests_dir_32),)
-    tests_dir_32 := $($(module)_install_to_native_tests_dir_32)
-  else
-    tests_dir_32 := $($(module)_install_to_native_tests_dir)
-  endif
-
-  ifneq ($($(module)_install_to_native_tests_dir_64),)
-    tests_dir_64 := $($(module)_install_to_native_tests_dir_64)
-  else
-    tests_dir_64 := $($(module)_install_to_native_tests_dir)
-  endif
-
-  LOCAL_MODULE_PATH_32 := $($(TARGET_2ND_ARCH_VAR_PREFIX)$(native_tests_var))/$(tests_dir_32)
-  LOCAL_MODULE_PATH_64 := $($(native_tests_var))/$(tests_dir_64)
-endif
-endif
-
-LOCAL_CLANG := $($(module)_clang_$(build_type))
-
-ifneq ($($(module)_allow_asan),true)
-  LOCAL_SANITIZE := never
-endif
-
-LOCAL_FORCE_STATIC_EXECUTABLE := $($(module)_force_static_executable)
-
-LOCAL_ALLOW_UNDEFINED_SYMBOLS := $($(module)_allow_undefined_symbols)
-
-ifneq ($($(module)_multilib),)
-  LOCAL_MULTILIB := $($(module)_multilib)
-endif
-
-ifneq ($($(module)_relative_path),)
-  LOCAL_MODULE_RELATIVE_PATH := $($(module)_relative_path)
-endif
-
-LOCAL_CFLAGS := \
-    $(common_cflags) \
-    $($(module)_cflags) \
-    $($(module)_cflags_$(build_type)) \
-
-LOCAL_CONLYFLAGS += \
-    $(common_conlyflags) \
-    $($(module)_conlyflags) \
-    $($(module)_conlyflags_$(build_type)) \
-
-LOCAL_CPPFLAGS += \
-    $(common_cppflags) \
-    $($(module)_cppflags) \
-    $($(module)_cppflags_$(build_type)) \
-
-LOCAL_C_INCLUDES := \
-    $(common_c_includes) \
-    $($(module)_c_includes) \
-    $($(module)_c_includes_$(build_type)) \
-
-LOCAL_SRC_FILES := \
-    $($(module)_src_files) \
-    $($(module)_src_files_$(build_type)) \
-
-LOCAL_STATIC_LIBRARIES := \
-    $($(module)_static_libraries) \
-    $($(module)_static_libraries_$(build_type)) \
-
-LOCAL_SHARED_LIBRARIES := \
-    $($(module)_shared_libraries) \
-    $($(module)_shared_libraries_$(build_type)) \
-
-LOCAL_WHOLE_STATIC_LIBRARIES := \
-    $($(module)_whole_static_libraries) \
-    $($(module)_whole_static_libraries_$(build_type)) \
-
-LOCAL_LDFLAGS := \
-    $($(module)_ldflags) \
-    $($(module)_ldflags_$(build_type)) \
-
-LOCAL_LDLIBS := \
-    $($(module)_ldlibs) \
-    $($(module)_ldlibs_$(build_type)) \
-
-LOCAL_CXX_STL := libc++_static
-
-ifeq ($(build_type),target)
-  include $(BUILD_$(build_target))
-endif
-
-ifeq ($(build_type),host)
-  # Only build if host builds are supported.
-  ifeq ($(build_host),true)
-    include $(BUILD_HOST_$(build_target))
-  endif
-endif
diff --git a/tests/libs/Android.bp b/tests/libs/Android.bp
index 98d4f25..2ee6c86 100644
--- a/tests/libs/Android.bp
+++ b/tests/libs/Android.bp
@@ -83,21 +83,30 @@
     name: "libtest_elftls_dynamic_filler_1",
     defaults: ["bionic_testlib_defaults"],
     srcs: ["elftls_dynamic_filler.cpp"],
-    cflags: ["-fno-emulated-tls", "-DTLS_FILLER=100"],
+    cflags: [
+        "-fno-emulated-tls",
+        "-DTLS_FILLER=100",
+    ],
 }
 
 cc_test_library {
     name: "libtest_elftls_dynamic_filler_2",
     defaults: ["bionic_testlib_defaults"],
     srcs: ["elftls_dynamic_filler.cpp"],
-    cflags: ["-fno-emulated-tls", "-DTLS_FILLER=200"],
+    cflags: [
+        "-fno-emulated-tls",
+        "-DTLS_FILLER=200",
+    ],
 }
 
 cc_test_library {
     name: "libtest_elftls_dynamic_filler_3",
     defaults: ["bionic_testlib_defaults"],
     srcs: ["elftls_dynamic_filler.cpp"],
-    cflags: ["-fno-emulated-tls", "-DTLS_FILLER=300"],
+    cflags: [
+        "-fno-emulated-tls",
+        "-DTLS_FILLER=300",
+    ],
 }
 
 // -----------------------------------------------------------------------------
@@ -131,7 +140,13 @@
 // -----------------------------------------------------------------------------
 // Library used by dlext tests - with GNU RELRO program header
 // -----------------------------------------------------------------------------
-// In Android.mk to support creating symlinks
+cc_test_library {
+    name: "libdlext_test",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlext_test_library.cpp"],
+    ldflags: ["-Wl,-z,relro"],
+    shared_libs: ["libtest_simple"],
+}
 
 // -----------------------------------------------------------------------------
 // Library used by dlext tests - without GNU RELRO program header
@@ -145,19 +160,58 @@
 }
 
 // -----------------------------------------------------------------------------
+// Library used by dlext tests - recursive use of RELRO sharing
+// -----------------------------------------------------------------------------
+cc_test_library {
+    name: "libdlext_test_recursive",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlext_test_recursive_library.cpp"],
+    ldflags: ["-Wl,-z,relro"],
+    shared_libs: ["libdlext_test"],
+}
+
+// -----------------------------------------------------------------------------
 // Library used by dlext tests - different name non-default location
 // -----------------------------------------------------------------------------
-// In Android.mk to support installing to /data
+cc_test_library {
+    name: "libdlext_test_fd",
+    defaults: ["bionic_testlib_defaults"],
+    host_supported: false,
+    srcs: ["dlext_test_library.cpp"],
+    ldflags: ["-Wl,--rpath,${ORIGIN}/.."],
+    relative_install_path: "bionic-loader-test-libs/libdlext_test_fd",
+    shared_libs: ["libtest_simple"],
+}
 
 // -----------------------------------------------------------------------------
 // Libraries used by dlext tests for open from a zip-file
 // -----------------------------------------------------------------------------
-// In Android.mk to support installing to /data
+cc_test_library {
+    name: "libdlext_test_zip",
+    defaults: ["bionic_testlib_defaults"],
+    host_supported: false,
+    srcs: ["dlext_test_library.cpp"],
+    shared_libs: ["libatest_simple_zip"],
+    relative_install_path: "bionic-loader-test-libs/libdlext_test_zip",
+}
+
+cc_test_library {
+    name: "libatest_simple_zip",
+    defaults: ["bionic_testlib_defaults"],
+    host_supported: false,
+    srcs: ["dlopen_testlib_simple.cpp"],
+    relative_install_path: "bionic-loader-test-libs/libatest_simple_zip",
+}
 
 // ----------------------------------------------------------------------------
 // Library with soname which does not match filename
 // ----------------------------------------------------------------------------
-// In Android.mk to support zipped and aligned tests
+cc_test_library {
+    name: "libdlext_test_different_soname",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlext_test_library.cpp"],
+    ldflags: ["-Wl,-soname=libdlext_test_soname.so"],
+}
 
 // -----------------------------------------------------------------------------
 // Library used by dlext tests - zipped and aligned
@@ -375,39 +429,545 @@
 }
 
 // -----------------------------------------------------------------------------
-// Build DT_RUNPATH test helper libraries
+// Build test helper libraries for linker namespaces
+//
+// This set of libraries is to test isolated namespaces
+//
+// Isolated namespaces do not allow loading of the library outside of
+// the search paths.
+//
+// This library cannot be loaded in isolated namespace because one of DT_NEEDED
+// libraries is outside of the search paths.
+//
+// libnstest_root_not_isolated.so (DT_RUNPATH = $ORIGIN/../private_namespace_libs_external/)
+// +-> libnstest_public.so
+// +-> libnstest_private_external.so (located in $ORIGIN/../private_namespace_libs_external/)
+//
+// Search path: $NATIVE_TESTS/private_namespace_libs/
+//
 // -----------------------------------------------------------------------------
-// include $(LOCAL_PATH)/Android.build.dt_runpath.mk
+
+cc_test_library {
+    name: "libnstest_root_not_isolated",
+    defaults: ["bionic_testlib_defaults"],
+    host_supported: false,
+    srcs: ["namespaces_root.cpp"],
+    shared_libs: [
+        "libnstest_public",
+        "libnstest_private_external",
+    ],
+    relative_install_path: "bionic-loader-test-libs/private_namespace_libs",
+    ldflags: ["-Wl,--rpath,$ORIGIN/../private_namespace_libs_external"],
+}
+
+cc_test_library {
+    name: "libnstest_private_external",
+    defaults: ["bionic_testlib_defaults"],
+    host_supported: false,
+    srcs: ["namespaces_private.cpp"],
+    relative_install_path: "bionic-loader-test-libs/private_namespace_libs_external",
+}
+
+// -----------------------------------------------------------------------------
+// Build DT_RUNPATH test helper libraries
+//
+// Dependencies
+//
+// libtest_dt_runpath_d.so                       runpath: ${ORIGIN}/dt_runpath_b_c_x, ${ORIGIN}/dt_runpath_y/${LIB}
+// |-> dt_runpath_b_c_x/libtest_dt_runpath_b.so  runpath: ${ORIGIN}/../dt_runpath_a
+// |   |-> dt_runpath_a/libtest_dt_runpath_a.so
+// |-> dt_runpath_b_c_x/libtest_dt_runpath_c.so  runpath: ${ORIGIN}/invalid_dt_runpath
+// |   |-> libtest_dt_runpath_a.so (soname)
+// |-> dt_runpath_y/lib[64]/libtest_dt_runpath_y.so
+//
+// This one is used to test dlopen
+// dt_runpath_b_c_x/libtest_dt_runpath_x.so
+//
+// -----------------------------------------------------------------------------
+
+// A leaf library in a non-standard directory.
+cc_test_library {
+    name: "libtest_dt_runpath_a",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["empty.cpp"],
+    relative_install_path: "bionic-loader-test-libs/dt_runpath_a",
+}
+
+// Depends on library A with a DT_RUNPATH
+cc_test_library {
+    name: "libtest_dt_runpath_b",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["empty.cpp"],
+    shared_libs: ["libtest_dt_runpath_a"],
+    relative_install_path: "bionic-loader-test-libs/dt_runpath_b_c_x",
+    ldflags: ["-Wl,--rpath,${ORIGIN}/../dt_runpath_a"],
+}
+
+// Depends on library A with an incorrect DT_RUNPATH. This does not matter
+// because B is the first in the D (below) dependency order, and library A
+// is already loaded using the correct DT_RUNPATH from library B.
+cc_test_library {
+    name: "libtest_dt_runpath_c",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["empty.cpp"],
+    shared_libs: ["libtest_dt_runpath_a"],
+    relative_install_path: "bionic-loader-test-libs/dt_runpath_b_c_x",
+    ldflags: ["-Wl,--rpath,${ORIGIN}/invalid_dt_runpath"],
+}
+
+// D depends on B, C, and Y with DT_RUNPATH.
+cc_test_library {
+    name: "libtest_dt_runpath_d",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_b.cpp"],
+    shared_libs: [
+        "libtest_dt_runpath_b",
+        "libtest_dt_runpath_c",
+        "libtest_dt_runpath_y",
+    ],
+    ldflags: [
+        "-Wl,--rpath,${ORIGIN}/dt_runpath_b_c_x",
+        "-Wl,--rpath,${ORIGIN}/dt_runpath_y/${LIB}",
+    ],
+}
+
+// D version for open-from-zip test with runpath
+cc_test_library {
+    name: "libtest_dt_runpath_d_zip",
+    srcs: ["dlopen_b.cpp"],
+    shared_libs: [
+        "libtest_dt_runpath_b",
+        "libtest_dt_runpath_c",
+        "libtest_dt_runpath_y",
+    ],
+    cflags: [
+        "-Wall",
+        "-Werror",
+    ],
+    gtest: false,
+    relative_install_path: "libtest_dt_runpath_d_zip",
+    ldflags: [
+        "-Wl,--rpath,${ORIGIN}/dt_runpath_b_c_x",
+        "-Wl,--rpath,${ORIGIN}/dt_runpath_y/${LIB}",
+    ],
+    sanitize: {
+        address: false,
+        fuzzer: false,
+    },
+    stl: "libc++_static",
+    target: {
+        darwin: {
+            enabled: false,
+        },
+    },
+}
+
+// A leaf library in a directory library D has DT_RUNPATH for.
+cc_test_library {
+    name: "libtest_dt_runpath_x",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["empty.cpp"],
+    relative_install_path: "bionic-loader-test-libs/dt_runpath_b_c_x",
+}
+
+// A leaf library in lib or lib64 directory
+cc_test_library {
+    name: "libtest_dt_runpath_y",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["empty.cpp"],
+
+    multilib: {
+        lib32: {
+            relative_install_path: "bionic-loader-test-libs/dt_runpath_y/lib",
+        },
+        lib64: {
+            relative_install_path: "bionic-loader-test-libs/dt_runpath_y/lib64",
+        },
+    },
+}
 
 // -----------------------------------------------------------------------------
 // Build library with two parents
+//
+// Libraries used by dlfcn tests to verify local group ref_counting
+// libtest_two_parents*.so
 // -----------------------------------------------------------------------------
-// include $(LOCAL_PATH)/Android.build.dlopen_2_parents_reloc.mk
+
+// ..._child.so - correct answer
+cc_test_library {
+    name: "libtest_two_parents_child",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_2_parents_reloc_answer.cpp"],
+}
+
+// ..._parent1.so - correct answer
+cc_test_library {
+    name: "libtest_two_parents_parent1",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_check_order_reloc_answer_impl.cpp"],
+    shared_libs: ["libtest_two_parents_child"],
+    cflags: ["-D__ANSWER=42"],
+}
+
+// ..._parent2.so - incorrect answer
+cc_test_library {
+    name: "libtest_two_parents_parent2",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_check_order_reloc_answer_impl.cpp"],
+    shared_libs: ["libtest_two_parents_child"],
+    cflags: ["-D__ANSWER=1"],
+}
 
 // -----------------------------------------------------------------------------
 // Build libtest_check_order_dlsym.so with its dependencies.
+//
+// Libraries used by dlfcn tests to verify correct load order:
 // -----------------------------------------------------------------------------
-// include $(LOCAL_PATH)/Android.build.dlopen_check_order_dlsym.mk
+
+// libtest_check_order_2_right.so
+cc_test_library {
+    name: "libtest_check_order_dlsym_2_right",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_check_order_dlsym_answer.cpp"],
+    cflags: ["-D__ANSWER=42"],
+}
+
+// libtest_check_order_a.so
+cc_test_library {
+    name: "libtest_check_order_dlsym_a",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_check_order_dlsym_answer.cpp"],
+    cflags: ["-D__ANSWER=1"],
+}
+
+// libtest_check_order_b.so
+cc_test_library {
+    name: "libtest_check_order_dlsym_b",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_check_order_dlsym_answer.cpp"],
+    cflags: [
+        "-D__ANSWER=2",
+        "-D__ANSWER2=43",
+    ],
+}
+
+// libtest_check_order_c.so
+cc_test_library {
+    name: "libtest_check_order_dlsym_3_c",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_check_order_dlsym_answer.cpp"],
+    cflags: ["-D__ANSWER=3"],
+}
+
+// libtest_check_order_d.so
+cc_test_library {
+    name: "libtest_check_order_dlsym_d",
+    defaults: ["bionic_testlib_defaults"],
+    shared_libs: ["libtest_check_order_dlsym_b"],
+    srcs: ["dlopen_check_order_dlsym_answer.cpp"],
+    cflags: [
+        "-D__ANSWER=4",
+        "-D__ANSWER2=4",
+    ],
+}
+
+// libtest_check_order_left.so
+cc_test_library {
+    name: "libtest_check_order_dlsym_1_left",
+    defaults: ["bionic_testlib_defaults"],
+    shared_libs: [
+        "libtest_check_order_dlsym_a",
+        "libtest_check_order_dlsym_b",
+    ],
+    srcs: ["empty.cpp"],
+}
+
+// libtest_check_order.so
+cc_test_library {
+    name: "libtest_check_order_dlsym",
+    defaults: ["bionic_testlib_defaults"],
+    shared_libs: [
+        "libtest_check_order_dlsym_1_left",
+        "libtest_check_order_dlsym_2_right",
+        "libtest_check_order_dlsym_3_c",
+    ],
+    srcs: ["empty.cpp"],
+}
 
 // -----------------------------------------------------------------------------
 // Build libtest_check_order_siblings.so with its dependencies.
+//
+// Libraries used by dlfcn tests to verify correct relocation order:
+// libtest_check_order_reloc_siblings*.so
 // -----------------------------------------------------------------------------
-// include $(LOCAL_PATH)/Android.build.dlopen_check_order_reloc_siblings.mk
+
+// ..._1.so - empty
+cc_test_library {
+    name: "libtest_check_order_reloc_siblings_1",
+    defaults: ["bionic_testlib_defaults"],
+    shared_libs: [
+        "libtest_check_order_reloc_siblings_a",
+        "libtest_check_order_reloc_siblings_b",
+    ],
+    srcs: ["empty.cpp"],
+}
+
+// ..._2.so - empty
+cc_test_library {
+    name: "libtest_check_order_reloc_siblings_2",
+    defaults: ["bionic_testlib_defaults"],
+    shared_libs: [
+        "libtest_check_order_reloc_siblings_c",
+        "libtest_check_order_reloc_siblings_d",
+    ],
+    srcs: [
+        "dlopen_check_order_reloc_grandchild_answer.cpp",
+    ],
+    allow_undefined_symbols: true,
+}
+
+// ..._3.so - get_answer2();
+cc_test_library {
+    name: "libtest_check_order_reloc_siblings_3",
+    defaults: ["bionic_testlib_defaults"],
+    shared_libs: [
+        "libtest_check_order_reloc_siblings_e",
+        "libtest_check_order_reloc_siblings_f",
+    ],
+    srcs: [
+        "dlopen_check_order_reloc_nephew_answer.cpp",
+    ],
+}
+
+// ..._a.so <- correct impl
+cc_test_library {
+    name: "libtest_check_order_reloc_siblings_a",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: [
+        "dlopen_check_order_reloc_answer_impl.cpp",
+    ],
+    cflags: ["-D__ANSWER=42"],
+}
+
+// ..._b.so
+cc_test_library {
+    name: "libtest_check_order_reloc_siblings_b",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: [
+        "dlopen_check_order_reloc_answer_impl.cpp",
+    ],
+    cflags: ["-D__ANSWER=1"],
+}
+
+// ..._c.so
+cc_test_library {
+    name: "libtest_check_order_reloc_siblings_c",
+    defaults: ["bionic_testlib_defaults"],
+    shared_libs: [
+        "libtest_check_order_reloc_siblings_c_1",
+        "libtest_check_order_reloc_siblings_c_2",
+    ],
+    srcs: [
+        "dlopen_check_order_reloc_answer_impl.cpp",
+    ],
+    cflags: ["-D__ANSWER=2"],
+}
+
+// ..._d.so
+cc_test_library {
+    name: "libtest_check_order_reloc_siblings_d",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: [
+        "dlopen_check_order_reloc_answer_impl.cpp",
+    ],
+    cflags: ["-D__ANSWER=3"],
+}
+
+// ..._e.so
+cc_test_library {
+    name: "libtest_check_order_reloc_siblings_e",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: [
+        "dlopen_check_order_reloc_answer_impl.cpp",
+    ],
+    cflags: [
+        "-D__ANSWER=4",
+    ],
+}
+
+// ..._f.so <- get_answer()
+cc_test_library {
+    name: "libtest_check_order_reloc_siblings_f",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: [
+        "dlopen_check_order_reloc_answer.cpp",
+    ],
+}
+
+// ..._c_1.so
+cc_test_library {
+    name: "libtest_check_order_reloc_siblings_c_1",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: [
+        "dlopen_check_order_reloc_grandchild_answer_impl.cpp",
+    ],
+    cflags: ["-D__ANSWER=42"],
+}
+
+// ..._c_2.so
+cc_test_library {
+    name: "libtest_check_order_reloc_siblings_c_2",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: [
+        "dlopen_check_order_reloc_grandchild_answer_impl.cpp",
+    ],
+    cflags: ["-D__ANSWER=0"],
+}
+
+// libtest_check_order_reloc_siblings.so
+cc_test_library {
+    name: "libtest_check_order_reloc_siblings",
+    defaults: ["bionic_testlib_defaults"],
+    shared_libs: [
+        "libtest_check_order_reloc_siblings_1",
+        "libtest_check_order_reloc_siblings_2",
+        "libtest_check_order_reloc_siblings_3",
+    ],
+    srcs: [
+        "empty.cpp",
+    ],
+}
 
 // -----------------------------------------------------------------------------
 // Build libtest_check_order_root.so with its dependencies.
+//
+// Libraries used by dlfcn tests to verify correct relocation order:
+// libtest_check_order_reloc_root*.so
 // -----------------------------------------------------------------------------
-// include $(LOCAL_PATH)/Android.build.dlopen_check_order_reloc_main_executable.mk
+
+// ..._1.so - empty
+cc_test_library {
+    name: "libtest_check_order_reloc_root_1",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["empty.cpp"],
+}
+
+// ..._2.so - this one has the incorrect answer
+cc_test_library {
+    name: "libtest_check_order_reloc_root_2",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_check_order_reloc_root_answer_impl.cpp"],
+    cflags: ["-D__ANSWER=2"],
+}
+
+// libtest_check_order_reloc_root.so <- implements get_answer3()
+cc_test_library {
+    name: "libtest_check_order_reloc_root",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_check_order_reloc_root_answer.cpp"],
+    shared_libs: [
+        "libtest_check_order_reloc_root_1",
+        "libtest_check_order_reloc_root_2",
+    ],
+}
 
 // -----------------------------------------------------------------------------
 // Build libtest_versioned_lib.so with its dependencies.
+//
+// Libraries used to test versioned symbols
 // -----------------------------------------------------------------------------
-// include $(LOCAL_PATH)/Android.build.versioned_lib.mk
+
+cc_test_library {
+    name: "libtest_versioned_uselibv1",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["versioned_uselib.cpp"],
+    shared_libs: ["libtest_versioned_libv1"],
+}
+
+cc_test_library {
+    name: "libtest_versioned_uselibv2",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["versioned_uselib.cpp"],
+    shared_libs: ["libtest_versioned_libv2"],
+    version_script: "versioned_uselib.map",
+}
+
+cc_test_library {
+    name: "libtest_versioned_uselibv2_other",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["versioned_uselib.cpp"],
+    shared_libs: [
+        "libtest_versioned_otherlib_empty",
+        "libtest_versioned_libv2",
+    ],
+}
+
+cc_test_library {
+    name: "libtest_versioned_uselibv3_other",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["versioned_uselib.cpp"],
+    shared_libs: [
+        "libtest_versioned_otherlib_empty",
+        "libtest_versioned_lib",
+    ],
+}
+
+// lib v1 - this one used during static linking but never used at runtime
+// which forces libtest_versioned_uselibv1 to use function v1 from
+// libtest_versioned_lib.so
+cc_test_library {
+    name: "libtest_versioned_libv1",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["versioned_lib_v1.cpp"],
+    version_script: "versioned_lib_v1.map",
+    ldflags: ["-Wl,-soname,libtest_versioned_lib.so"],
+}
+
+// lib v2 - to make libtest_versioned_uselibv2.so use version 2 of versioned_function()
+cc_test_library {
+    name: "libtest_versioned_libv2",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["versioned_lib_v2.cpp"],
+    version_script: "versioned_lib_v2.map",
+    ldflags: ["-Wl,-soname,libtest_versioned_lib.so"],
+}
+
+// last version - this one is used at the runtime and exports 3 versions
+// of versioned_symbol().
+cc_test_library {
+    name: "libtest_versioned_lib",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["versioned_lib_v3.cpp"],
+    version_script: "versioned_lib_v3.map",
+}
+
+// This library is empty, the actual implementation will provide an unversioned
+// symbol for versioned_function().
+cc_test_library {
+    name: "libtest_versioned_otherlib_empty",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["empty.cpp"],
+    ldflags: ["-Wl,-soname,libtest_versioned_otherlib.so"],
+}
+
+cc_test_library {
+    name: "libtest_versioned_otherlib",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["versioned_lib_other.cpp"],
+    version_script: "versioned_lib_other.map",
+}
 
 // -----------------------------------------------------------------------------
 // Build libraries needed by pthread_atfork tests
+
+// This library used to test phtread_atfork handler behaviour
+// during/after dlclose.
 // -----------------------------------------------------------------------------
-// include $(LOCAL_PATH)/Android.build.pthread_atfork.mk
+cc_test_library {
+    name: "libtest_pthread_atfork",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["pthread_atfork.cpp"],
+}
 
 // -----------------------------------------------------------------------------
 // Library with dependency loop used by dlfcn tests
@@ -496,7 +1056,12 @@
 // -----------------------------------------------------------------------------
 // Library with dependency used by dlfcn tests
 // -----------------------------------------------------------------------------
-// In Android.mk to support dependency on libdlext_test
+cc_test_library {
+    name: "libtest_with_dependency",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_testlib_simple.cpp"],
+    shared_libs: ["libdlext_test"],
+}
 
 // -----------------------------------------------------------------------------
 // Library used by ifunc tests
@@ -777,7 +1342,6 @@
     ],
 }
 
-
 // -----------------------------------------------------------------------------
 // Tool to use to align the shared libraries in a zip file.
 // -----------------------------------------------------------------------------
diff --git a/tests/libs/Android.build.dlopen_2_parents_reloc.mk b/tests/libs/Android.build.dlopen_2_parents_reloc.mk
deleted file mode 100644
index 29ae10d..0000000
--- a/tests/libs/Android.build.dlopen_2_parents_reloc.mk
+++ /dev/null
@@ -1,52 +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.
-#
-
-# -----------------------------------------------------------------------------
-# Libraries used by dlfcn tests to verify local group ref_counting
-# libtest_two_parents*.so
-# -----------------------------------------------------------------------------
-
-# -----------------------------------------------------------------------------
-# ..._child.so - correct answer
-# -----------------------------------------------------------------------------
-libtest_two_parents_child_src_files := \
-    dlopen_2_parents_reloc_answer.cpp
-
-module := libtest_two_parents_child
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# ..._parent1.so - correct answer
-# -----------------------------------------------------------------------------
-libtest_two_parents_parent1_src_files := \
-    dlopen_check_order_reloc_answer_impl.cpp
-
-libtest_two_parents_parent1_shared_libraries := libtest_two_parents_child
-libtest_two_parents_parent1_cflags := -D__ANSWER=42
-module := libtest_two_parents_parent1
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# ..._parent2.so - incorrect answer
-# -----------------------------------------------------------------------------
-libtest_two_parents_parent2_src_files := \
-    dlopen_check_order_reloc_answer_impl.cpp
-
-libtest_two_parents_parent2_shared_libraries := libtest_two_parents_child
-libtest_two_parents_parent2_cflags := -D__ANSWER=1
-module := libtest_two_parents_parent2
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
diff --git a/tests/libs/Android.build.dlopen_check_order_dlsym.mk b/tests/libs/Android.build.dlopen_check_order_dlsym.mk
deleted file mode 100644
index 73d8c1a..0000000
--- a/tests/libs/Android.build.dlopen_check_order_dlsym.mk
+++ /dev/null
@@ -1,90 +0,0 @@
-#
-# Copyright (C) 2012 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.
-#
-
-# -----------------------------------------------------------------------------
-# Libraries used by dlfcn tests to verify correct load order:
-# libtest_check_order_2_right.so
-# -----------------------------------------------------------------------------
-libtest_check_order_dlsym_2_right_src_files := \
-    dlopen_check_order_dlsym_answer.cpp
-
-libtest_check_order_dlsym_2_right_cflags := -D__ANSWER=42
-module := libtest_check_order_dlsym_2_right
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# libtest_check_order_a.so
-# -----------------------------------------------------------------------------
-libtest_check_order_dlsym_a_src_files := \
-    dlopen_check_order_dlsym_answer.cpp
-
-libtest_check_order_dlsym_a_cflags := -D__ANSWER=1
-module := libtest_check_order_dlsym_a
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# libtest_check_order_b.so
-# -----------------------------------------------------------------------------
-libtest_check_order_dlsym_b_src_files := \
-    dlopen_check_order_dlsym_answer.cpp
-
-libtest_check_order_dlsym_b_cflags := -D__ANSWER=2 -D__ANSWER2=43
-module := libtest_check_order_dlsym_b
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# libtest_check_order_c.so
-# -----------------------------------------------------------------------------
-libtest_check_order_dlsym_3_c_src_files := \
-    dlopen_check_order_dlsym_answer.cpp
-
-libtest_check_order_dlsym_3_c_cflags := -D__ANSWER=3
-module := libtest_check_order_dlsym_3_c
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# libtest_check_order_d.so
-# -----------------------------------------------------------------------------
-libtest_check_order_dlsym_d_src_files := \
-   dlopen_check_order_dlsym_answer.cpp
-
-libtest_check_order_dlsym_d_shared_libraries := libtest_check_order_dlsym_b
-libtest_check_order_dlsym_d_cflags := -D__ANSWER=4 -D__ANSWER2=4
-module := libtest_check_order_dlsym_d
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# libtest_check_order_left.so
-# -----------------------------------------------------------------------------
-libtest_check_order_dlsym_1_left_src_files := \
-    empty.cpp
-
-libtest_check_order_dlsym_1_left_shared_libraries := libtest_check_order_dlsym_a libtest_check_order_dlsym_b
-
-module := libtest_check_order_dlsym_1_left
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# libtest_check_order.so
-# -----------------------------------------------------------------------------
-libtest_check_order_dlsym_src_files := \
-    empty.cpp
-
-libtest_check_order_dlsym_shared_libraries := libtest_check_order_dlsym_1_left \
-  libtest_check_order_dlsym_2_right libtest_check_order_dlsym_3_c
-
-module := libtest_check_order_dlsym
-include $(LOCAL_PATH)/Android.build.testlib.mk
diff --git a/tests/libs/Android.build.dlopen_check_order_reloc_main_executable.mk b/tests/libs/Android.build.dlopen_check_order_reloc_main_executable.mk
deleted file mode 100644
index 639696b..0000000
--- a/tests/libs/Android.build.dlopen_check_order_reloc_main_executable.mk
+++ /dev/null
@@ -1,56 +0,0 @@
-#
-# Copyright (C) 2012 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.
-#
-
-# -----------------------------------------------------------------------------
-# Libraries used by dlfcn tests to verify correct relocation order:
-# libtest_check_order_reloc_root*.so
-# -----------------------------------------------------------------------------
-
-
-# -----------------------------------------------------------------------------
-# ..._1.so - empty
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_root_1_src_files := \
-    empty.cpp
-
-
-module := libtest_check_order_reloc_root_1
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-
-# -----------------------------------------------------------------------------
-# ..._2.so - this one has the incorrect answer
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_root_2_src_files := \
-    dlopen_check_order_reloc_root_answer_impl.cpp
-
-libtest_check_order_reloc_root_2_cflags := -D__ANSWER=2
-
-module := libtest_check_order_reloc_root_2
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# libtest_check_order_reloc_root.so <- implements get_answer3()
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_root_src_files := \
-    dlopen_check_order_reloc_root_answer.cpp
-
-libtest_check_order_reloc_root_shared_libraries := \
-    libtest_check_order_reloc_root_1 \
-    libtest_check_order_reloc_root_2
-
-module := libtest_check_order_reloc_root
-include $(LOCAL_PATH)/Android.build.testlib.mk
diff --git a/tests/libs/Android.build.dlopen_check_order_reloc_siblings.mk b/tests/libs/Android.build.dlopen_check_order_reloc_siblings.mk
deleted file mode 100644
index bd35a51..0000000
--- a/tests/libs/Android.build.dlopen_check_order_reloc_siblings.mk
+++ /dev/null
@@ -1,158 +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.
-#
-
-# -----------------------------------------------------------------------------
-# Libraries used by dlfcn tests to verify correct relocation order:
-# libtest_check_order_reloc_siblings*.so
-# -----------------------------------------------------------------------------
-
-# -----------------------------------------------------------------------------
-# ..._1.so - empty
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_siblings_1_src_files := \
-    empty.cpp
-
-libtest_check_order_reloc_siblings_1_shared_libraries := \
-    libtest_check_order_reloc_siblings_a \
-    libtest_check_order_reloc_siblings_b
-
-module := libtest_check_order_reloc_siblings_1
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-
-# -----------------------------------------------------------------------------
-# ..._2.so - empty
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_siblings_2_src_files := \
-    dlopen_check_order_reloc_grandchild_answer.cpp
-
-libtest_check_order_reloc_siblings_2_shared_libraries := \
-    libtest_check_order_reloc_siblings_c \
-    libtest_check_order_reloc_siblings_d
-
-libtest_check_order_reloc_siblings_2_allow_undefined_symbols := true
-module := libtest_check_order_reloc_siblings_2
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# ..._3.so - get_answer2();
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_siblings_3_src_files := \
-    dlopen_check_order_reloc_nephew_answer.cpp
-
-libtest_check_order_reloc_siblings_3_shared_libraries := \
-    libtest_check_order_reloc_siblings_e \
-    libtest_check_order_reloc_siblings_f
-
-module := libtest_check_order_reloc_siblings_3
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# ..._a.so <- correct impl
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_siblings_a_src_files := \
-    dlopen_check_order_reloc_answer_impl.cpp
-
-libtest_check_order_reloc_siblings_a_cflags := -D__ANSWER=42
-module := libtest_check_order_reloc_siblings_a
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# ..._b.so
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_siblings_b_src_files := \
-    dlopen_check_order_reloc_answer_impl.cpp
-
-libtest_check_order_reloc_siblings_b_cflags := -D__ANSWER=1
-module := libtest_check_order_reloc_siblings_b
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# ..._c.so
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_siblings_c_src_files := \
-    dlopen_check_order_reloc_answer_impl.cpp
-
-libtest_check_order_reloc_siblings_c_cflags := -D__ANSWER=2
-libtest_check_order_reloc_siblings_c_shared_libraries := \
-    libtest_check_order_reloc_siblings_c_1 \
-    libtest_check_order_reloc_siblings_c_2
-
-module := libtest_check_order_reloc_siblings_c
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# ..._d.so
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_siblings_d_src_files := \
-    dlopen_check_order_reloc_answer_impl.cpp
-
-libtest_check_order_reloc_siblings_d_cflags := -D__ANSWER=3
-module := libtest_check_order_reloc_siblings_d
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# ..._e.so
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_siblings_e_src_files := \
-    dlopen_check_order_reloc_answer_impl.cpp
-
-libtest_check_order_reloc_siblings_e_cflags := -D__ANSWER=4
-module := libtest_check_order_reloc_siblings_e
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# ..._f.so <- get_answer()
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_siblings_f_src_files := \
-    dlopen_check_order_reloc_answer.cpp
-
-module := libtest_check_order_reloc_siblings_f
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# ..._c_1.so
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_siblings_c_1_src_files := \
-    dlopen_check_order_reloc_grandchild_answer_impl.cpp
-
-libtest_check_order_reloc_siblings_c_1_cflags := -D__ANSWER=42
-module := libtest_check_order_reloc_siblings_c_1
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# ..._c_2.so
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_siblings_c_2_src_files := \
-    dlopen_check_order_reloc_grandchild_answer_impl.cpp
-
-libtest_check_order_reloc_siblings_c_2_cflags := -D__ANSWER=0
-module := libtest_check_order_reloc_siblings_c_2
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# libtest_check_order_reloc_siblings.so
-# -----------------------------------------------------------------------------
-libtest_check_order_reloc_siblings_src_files := \
-    empty.cpp
-
-libtest_check_order_reloc_siblings_shared_libraries := \
-    libtest_check_order_reloc_siblings_1 \
-    libtest_check_order_reloc_siblings_2 \
-    libtest_check_order_reloc_siblings_3
-
-module := libtest_check_order_reloc_siblings
-include $(LOCAL_PATH)/Android.build.testlib.mk
diff --git a/tests/libs/Android.build.dt_runpath.mk b/tests/libs/Android.build.dt_runpath.mk
deleted file mode 100644
index b0d8e4b..0000000
--- a/tests/libs/Android.build.dt_runpath.mk
+++ /dev/null
@@ -1,128 +0,0 @@
-#
-# Copyright (C) 2012 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.
-#
-
-# -----------------------------------------------------------------------------
-# Libraries used by dt_runpath tests.
-# -----------------------------------------------------------------------------
-
-#
-# Dependencies
-#
-# libtest_dt_runpath_d.so                       runpath: ${ORIGIN}/dt_runpath_b_c_x, ${ORIGIN}/dt_runpath_y/${LIB}
-# |-> dt_runpath_b_c_x/libtest_dt_runpath_b.so  runpath: ${ORIGIN}/../dt_runpath_a
-# |   |-> dt_runpath_a/libtest_dt_runpath_a.so
-# |-> dt_runpath_b_c_x/libtest_dt_runpath_c.so  runpath: ${ORIGIN}/invalid_dt_runpath
-# |   |-> libtest_dt_runpath_a.so (soname)
-# |-> dt_runpath_y/lib[64]/libtest_dt_runpath_y.so
-#
-# This one is used to test dlopen
-# dt_runpath_b_c_x/libtest_dt_runpath_x.so
-#
-
-# A leaf library in a non-standard directory.
-libtest_dt_runpath_a_src_files := \
-    empty.cpp
-
-libtest_dt_runpath_a_relative_path := dt_runpath_a
-module := libtest_dt_runpath_a
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# Depends on library A with a DT_RUNPATH
-libtest_dt_runpath_b_src_files := \
-    empty.cpp
-
-libtest_dt_runpath_b_shared_libraries := libtest_dt_runpath_a
-libtest_dt_runpath_b_ldflags := -Wl,--rpath,\$${ORIGIN}/../dt_runpath_a -Wl,--enable-new-dtags
-libtest_dt_runpath_b_relative_path := dt_runpath_b_c_x
-module := libtest_dt_runpath_b
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# Depends on library A with an incorrect DT_RUNPATH. This does not matter
-# because B is the first in the D (below) dependency order, and library A
-# is already loaded using the correct DT_RUNPATH from library B.
-libtest_dt_runpath_c_src_files := \
-    empty.cpp
-
-libtest_dt_runpath_c_shared_libraries := libtest_dt_runpath_a
-libtest_dt_runpath_c_ldflags := -Wl,--rpath,\$${ORIGIN}/invalid_dt_runpath -Wl,--enable-new-dtags
-libtest_dt_runpath_c_relative_path := dt_runpath_b_c_x
-module := libtest_dt_runpath_c
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# D depends on B, C, and Y with DT_RUNPATH.
-libtest_dt_runpath_d_src_files := \
-    dlopen_b.cpp
-
-libtest_dt_runpath_d_shared_libraries := \
-    libtest_dt_runpath_b \
-    libtest_dt_runpath_c \
-    libtest_dt_runpath_y
-libtest_dt_runpath_d_ldflags := \
-    -Wl,--rpath,\$${ORIGIN}/dt_runpath_b_c_x \
-    -Wl,--rpath,\$${ORIGIN}/dt_runpath_y/\$${LIB} \
-    -Wl,--enable-new-dtags
-libtest_dt_runpath_d_ldlibs := -ldl
-module := libtest_dt_runpath_d
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# D version for open-from-zip test with runpath
-module := libtest_dt_runpath_d_zip
-
-libtest_dt_runpath_d_zip_src_files := \
-    dlopen_b.cpp
-
-libtest_dt_runpath_d_zip_shared_libraries := \
-    libtest_dt_runpath_b \
-    libtest_dt_runpath_c \
-    libtest_dt_runpath_y
-libtest_dt_runpath_d_zip_ldflags := \
-    -Wl,--rpath,\$${ORIGIN}/dt_runpath_b_c_x \
-    -Wl,--rpath,\$${ORIGIN}/dt_runpath_y/\$${LIB} \
-    -Wl,--enable-new-dtags
-libtest_dt_runpath_d_zip_ldlibs := -ldl
-libtest_dt_runpath_d_zip_install_to_native_tests_dir := $(module)
-
-module_tag := optional
-build_type := target
-build_target := SHARED_LIBRARY
-include $(TEST_PATH)/Android.build.mk
-
-
-# A leaf library in a directory library D has DT_RUNPATH for.
-libtest_dt_runpath_x_src_files := \
-    empty.cpp
-
-libtest_dt_runpath_x_relative_path := dt_runpath_b_c_x
-module := libtest_dt_runpath_x
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# A leaf library in lib or lib64 directory
-libtest_dt_runpath_y_src_files := \
-    empty.cpp
-
-ifeq ($(TARGET_TRANSLATE_2ND_ARCH),true)
-libtest_dt_runpath_y_install_to_native_tests_dir_32 := bionic-loader-test-libs/dt_runpath_y/lib/$(TARGET_2ND_ARCH)
-else
-libtest_dt_runpath_y_install_to_native_tests_dir_32 := bionic-loader-test-libs/dt_runpath_y/lib
-endif
-ifeq ($(TARGET_IS_64_BIT),true)
-libtest_dt_runpath_y_install_to_native_tests_dir_64 := bionic-loader-test-libs/dt_runpath_y/lib64
-else
-libtest_dt_runpath_y_install_to_native_tests_dir_64 := bionic-loader-test-libs/dt_runpath_y/lib
-endif
-
-module := libtest_dt_runpath_y
-include $(LOCAL_PATH)/Android.build.testlib.mk
diff --git a/tests/libs/Android.build.linker_namespaces.mk b/tests/libs/Android.build.linker_namespaces.mk
deleted file mode 100644
index e2b01a7..0000000
--- a/tests/libs/Android.build.linker_namespaces.mk
+++ /dev/null
@@ -1,48 +0,0 @@
-#
-# Copyright (C) 2015 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.
-#
-
-# -----------------------------------------------------------------------------
-# This set of libraries are used to verify linker namespaces.
-# -----------------------------------------------------------------------------
-
-# -----------------------------------------------------------------------------
-# This set of libraries is to test isolated namespaces
-#
-# Isolated namespaces do not allow loading of the library outside of
-# the search paths.
-#
-# This library cannot be loaded in isolated namespace because one of DT_NEEDED
-# libraries is outside of the search paths.
-#
-# libnstest_root_not_isolated.so (DT_RUNPATH = $ORIGIN/../private_namespace_libs_external/)
-# +-> libnstest_public.so
-# +-> libnstest_private_external.so (located in $ORIGIN/../private_namespace_libs_external/)
-#
-# Search path: $NATIVE_TESTS/private_namespace_libs/
-# -----------------------------------------------------------------------------
-libnstest_root_not_isolated_src_files := namespaces_root.cpp
-libnstest_root_not_isolated_shared_libraries := libnstest_public libnstest_private_external
-libnstest_root_not_isolated_relative_install_path := private_namespace_libs
-libnstest_root_not_isolated_ldflags := -Wl,--rpath,\$$ORIGIN/../private_namespace_libs_external \
-                                       -Wl,--enable-new-dtags
-
-module := libnstest_root_not_isolated
-include $(LOCAL_PATH)/Android.build.testlib.target.mk
-
-libnstest_private_external_src_files := namespaces_private.cpp
-libnstest_private_external_relative_install_path := private_namespace_libs_external
-module := libnstest_private_external
-include $(LOCAL_PATH)/Android.build.testlib.target.mk
diff --git a/tests/libs/Android.build.pthread_atfork.mk b/tests/libs/Android.build.pthread_atfork.mk
deleted file mode 100644
index 72ffec4..0000000
--- a/tests/libs/Android.build.pthread_atfork.mk
+++ /dev/null
@@ -1,25 +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.
-#
-
-# -----------------------------------------------------------------------------
-# This library used to test phtread_atfork handler behaviour
-# during/after dlclose.
-# -----------------------------------------------------------------------------
-libtest_pthread_atfork_src_files := pthread_atfork.cpp
-
-module := libtest_pthread_atfork
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
diff --git a/tests/libs/Android.build.testlib.host.mk b/tests/libs/Android.build.testlib.host.mk
deleted file mode 100644
index 38970dc..0000000
--- a/tests/libs/Android.build.testlib.host.mk
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Copyright (C) 2016 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.
-#
-
-build_target := SHARED_LIBRARY
-build_type := host
-include $(LOCAL_PATH)/Android.build.testlib.internal.mk
diff --git a/tests/libs/Android.build.testlib.internal.mk b/tests/libs/Android.build.testlib.internal.mk
deleted file mode 100644
index e1fec2b..0000000
--- a/tests/libs/Android.build.testlib.internal.mk
+++ /dev/null
@@ -1,27 +0,0 @@
-#
-# Copyright (C) 2016 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.
-#
-
-# 1. Install test libraries to $ANDROID_DATA/nativetests../bionic-loader-test-libs/
-#    by default.
-ifeq ($($(module)_relative_install_path),)
-  $(module)_install_to_native_tests_dir := bionic-loader-test-libs
-else
-  $(module)_install_to_native_tests_dir := bionic-loader-test-libs/$($(module)_relative_install_path)
-endif
-# 2. Set dt_runpath to origin to resolve dependencies
-$(module)_ldflags += -Wl,--rpath,\$${ORIGIN} -Wl,--enable-new-dtags
-
-include $(TEST_PATH)/Android.build.mk
diff --git a/tests/libs/Android.build.testlib.mk b/tests/libs/Android.build.testlib.mk
deleted file mode 100644
index a46c457..0000000
--- a/tests/libs/Android.build.testlib.mk
+++ /dev/null
@@ -1,19 +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 $(LOCAL_PATH)/Android.build.testlib.host.mk
-
-include $(LOCAL_PATH)/Android.build.testlib.target.mk
diff --git a/tests/libs/Android.build.testlib.target.mk b/tests/libs/Android.build.testlib.target.mk
deleted file mode 100644
index 5ec0d71..0000000
--- a/tests/libs/Android.build.testlib.target.mk
+++ /dev/null
@@ -1,19 +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.
-#
-
-build_target := SHARED_LIBRARY
-build_type := target
-include $(LOCAL_PATH)/Android.build.testlib.internal.mk
diff --git a/tests/libs/Android.build.versioned_lib.mk b/tests/libs/Android.build.versioned_lib.mk
deleted file mode 100644
index f3a6374..0000000
--- a/tests/libs/Android.build.versioned_lib.mk
+++ /dev/null
@@ -1,120 +0,0 @@
-#
-# Copyright (C) 2015 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.
-#
-
-# -----------------------------------------------------------------------------
-# Libraries used to test versioned symbols
-# -----------------------------------------------------------------------------
-libtest_versioned_uselibv1_src_files := versioned_uselib.cpp
-
-libtest_versioned_uselibv1_shared_libraries := \
-    libtest_versioned_libv1
-
-module := libtest_versioned_uselibv1
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-libtest_versioned_uselibv2_src_files := \
-    versioned_uselib.cpp
-
-libtest_versioned_uselibv2_shared_libraries := \
-    libtest_versioned_libv2
-
-libtest_versioned_uselibv2_ldflags := \
-    -Wl,--version-script,$(LOCAL_PATH)/versioned_uselib.map
-
-module := libtest_versioned_uselibv2
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-libtest_versioned_uselibv2_other_src_files := \
-    versioned_uselib.cpp
-
-libtest_versioned_uselibv2_other_shared_libraries := \
-    libtest_versioned_otherlib_empty libtest_versioned_libv2
-
-module := libtest_versioned_uselibv2_other
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-libtest_versioned_uselibv3_other_src_files := \
-    versioned_uselib.cpp
-
-libtest_versioned_uselibv3_other_shared_libraries := \
-    libtest_versioned_otherlib_empty libtest_versioned_lib
-
-module := libtest_versioned_uselibv3_other
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# lib v1 - this one used during static linking but never used at runtime
-# which forces libtest_versioned_uselibv1 to use function v1 from
-# libtest_versioned_lib.so
-# -----------------------------------------------------------------------------
-libtest_versioned_libv1_src_files := \
-    versioned_lib_v1.cpp
-
-libtest_versioned_libv1_ldflags := \
-    -Wl,--version-script,$(LOCAL_PATH)/versioned_lib_v1.map \
-    -Wl,-soname,libtest_versioned_lib.so
-
-module := libtest_versioned_libv1
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# lib v2 - to make libtest_versioned_uselibv2.so use version 2 of versioned_function()
-# -----------------------------------------------------------------------------
-libtest_versioned_libv2_src_files := \
-    versioned_lib_v2.cpp
-
-libtest_versioned_libv2_ldflags := \
-    -Wl,--version-script,$(LOCAL_PATH)/versioned_lib_v2.map \
-    -Wl,-soname,libtest_versioned_lib.so
-
-module := libtest_versioned_libv2
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-
-# -----------------------------------------------------------------------------
-# last version - this one is used at the runtime and exports 3 versions
-# of versioned_symbol().
-# -----------------------------------------------------------------------------
-libtest_versioned_lib_src_files := \
-    versioned_lib_v3.cpp
-
-libtest_versioned_lib_ldflags := \
-    -Wl,--version-script,$(LOCAL_PATH)/versioned_lib_v3.map
-
-module := libtest_versioned_lib
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# This library is empty, the actual implementation will provide an unversioned
-# symbol for versioned_function().
-# -----------------------------------------------------------------------------
-libtest_versioned_otherlib_empty_src_files := empty.cpp
-
-libtest_versioned_otherlib_empty_ldflags := -Wl,-soname,libtest_versioned_otherlib.so
-module := libtest_versioned_otherlib_empty
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-libtest_versioned_otherlib_src_files := versioned_lib_other.cpp
-
-libtest_versioned_otherlib_ldflags := \
-    -Wl,--version-script,$(LOCAL_PATH)/versioned_lib_other.map
-
-module := libtest_versioned_otherlib
-include $(LOCAL_PATH)/Android.build.testlib.mk
diff --git a/tests/libs/Android.mk b/tests/libs/Android.mk
index c40277d..08416ac 100644
--- a/tests/libs/Android.mk
+++ b/tests/libs/Android.mk
@@ -15,105 +15,6 @@
 #
 
 LOCAL_PATH := $(call my-dir)
-TEST_PATH := $(LOCAL_PATH)/..
-
-common_cppflags := -Wall -Werror
-common_additional_dependencies := \
-    $(LOCAL_PATH)/Android.mk \
-    $(LOCAL_PATH)/Android.build.dt_runpath.mk \
-    $(LOCAL_PATH)/Android.build.dlext_testzip.mk \
-    $(LOCAL_PATH)/Android.build.dlopen_2_parents_reloc.mk \
-    $(LOCAL_PATH)/Android.build.dlopen_check_order_dlsym.mk \
-    $(LOCAL_PATH)/Android.build.dlopen_check_order_reloc_siblings.mk \
-    $(LOCAL_PATH)/Android.build.dlopen_check_order_reloc_main_executable.mk \
-    $(LOCAL_PATH)/Android.build.linker_namespaces.mk \
-    $(LOCAL_PATH)/Android.build.pthread_atfork.mk \
-    $(LOCAL_PATH)/Android.build.testlib.mk \
-    $(LOCAL_PATH)/Android.build.testlib.target.mk \
-    $(LOCAL_PATH)/Android.build.versioned_lib.mk \
-    $(TEST_PATH)/Android.build.mk
-
-# -----------------------------------------------------------------------------
-# Library used by dlext tests - with GNU RELRO program header
-# -----------------------------------------------------------------------------
-libdlext_test_src_files := \
-    dlext_test_library.cpp \
-
-libdlext_test_ldflags := \
-    -Wl,-z,relro \
-
-libdlext_test_shared_libraries := libtest_simple
-
-module := libdlext_test
-module_tag := optional
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# Library used by dlext tests - recursive use of RELRO sharing
-# -----------------------------------------------------------------------------
-libdlext_test_recursive_src_files := \
-    dlext_test_recursive_library.cpp \
-
-libdlext_test_recursive_ldflags := \
-    -Wl,-z,relro \
-
-libdlext_test_recursive_shared_libraries := libdlext_test
-
-module := libdlext_test_recursive
-module_tag := optional
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# Library used by dlext tests - different name non-default location
-# -----------------------------------------------------------------------------
-module := libdlext_test_fd
-
-libdlext_test_fd_src_files := \
-    dlext_test_library.cpp \
-
-libdlext_test_fd_shared_libraries := libtest_simple
-
-libdlext_test_fd_relative_install_path := $(module)
-
-libdlext_test_fd_ldflags := -Wl,--rpath,\$${ORIGIN}/.. -Wl,--enable-new-dtags
-
-module_tag := optional
-include $(LOCAL_PATH)/Android.build.testlib.target.mk
-
-
-# -----------------------------------------------------------------------------
-# Libraries used by dlext tests for open from a zip-file
-# -----------------------------------------------------------------------------
-module := libdlext_test_zip
-
-libdlext_test_zip_src_files := \
-    dlext_test_library.cpp \
-
-libdlext_test_zip_shared_libraries := libatest_simple_zip
-
-libdlext_test_zip_relative_install_path := $(module)
-module_tag := optional
-include $(LOCAL_PATH)/Android.build.testlib.target.mk
-
-module := libatest_simple_zip
-
-libatest_simple_zip_src_files := \
-    dlopen_testlib_simple.cpp
-
-libatest_simple_zip_relative_install_path := $(module)
-module_tag := optional
-include $(LOCAL_PATH)/Android.build.testlib.target.mk
-
-# ----------------------------------------------------------------------------
-# Library with soname which does not match filename
-# ----------------------------------------------------------------------------
-libdlext_test_different_soname_src_files := \
-    dlext_test_library.cpp \
-
-module := libdlext_test_different_soname
-module_tag := optional
-libdlext_test_different_soname_ldflags := -Wl,-soname=libdlext_test_soname.so
-include $(LOCAL_PATH)/Android.build.testlib.mk
 
 # -----------------------------------------------------------------------------
 # Library used by dlext tests - zipped and aligned
@@ -125,54 +26,3 @@
   bionic_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX)
   include $(LOCAL_PATH)/Android.build.dlext_testzip.mk
 endif
-
-# -----------------------------------------------------------------------------
-# Build test helper libraries for linker namespaces
-# -----------------------------------------------------------------------------
-include $(LOCAL_PATH)/Android.build.linker_namespaces.mk
-
-# -----------------------------------------------------------------------------
-# Build DT_RUNPATH test helper libraries
-# -----------------------------------------------------------------------------
-include $(LOCAL_PATH)/Android.build.dt_runpath.mk
-
-# -----------------------------------------------------------------------------
-# Build library with two parents
-# -----------------------------------------------------------------------------
-include $(LOCAL_PATH)/Android.build.dlopen_2_parents_reloc.mk
-
-# -----------------------------------------------------------------------------
-# Build libtest_check_order_dlsym.so with its dependencies.
-# -----------------------------------------------------------------------------
-include $(LOCAL_PATH)/Android.build.dlopen_check_order_dlsym.mk
-
-# -----------------------------------------------------------------------------
-# Build libtest_check_order_siblings.so with its dependencies.
-# -----------------------------------------------------------------------------
-include $(LOCAL_PATH)/Android.build.dlopen_check_order_reloc_siblings.mk
-
-# -----------------------------------------------------------------------------
-# Build libtest_check_order_root.so with its dependencies.
-# -----------------------------------------------------------------------------
-include $(LOCAL_PATH)/Android.build.dlopen_check_order_reloc_main_executable.mk
-
-# -----------------------------------------------------------------------------
-# Build libtest_versioned_lib.so with its dependencies.
-# -----------------------------------------------------------------------------
-include $(LOCAL_PATH)/Android.build.versioned_lib.mk
-
-# -----------------------------------------------------------------------------
-# Build libraries needed by pthread_atfork tests
-# -----------------------------------------------------------------------------
-include $(LOCAL_PATH)/Android.build.pthread_atfork.mk
-
-# -----------------------------------------------------------------------------
-# Library with dependency used by dlfcn tests
-# -----------------------------------------------------------------------------
-libtest_with_dependency_src_files := \
-    dlopen_testlib_simple.cpp
-
-libtest_with_dependency_shared_libraries := libdlext_test
-
-module := libtest_with_dependency
-include $(LOCAL_PATH)/Android.build.testlib.mk