Merge "Silence the CFI death tests."
diff --git a/benchmarks/pthread_benchmark.cpp b/benchmarks/pthread_benchmark.cpp
index 856f150..6790c77 100644
--- a/benchmarks/pthread_benchmark.cpp
+++ b/benchmarks/pthread_benchmark.cpp
@@ -75,6 +75,7 @@
 }
 BIONIC_BENCHMARK(BM_pthread_mutex_lock);
 
+#if !defined(ANDROID_HOST_MUSL)
 static void BM_pthread_mutex_lock_ERRORCHECK(benchmark::State& state) {
   pthread_mutex_t mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
 
@@ -84,7 +85,9 @@
   }
 }
 BIONIC_BENCHMARK(BM_pthread_mutex_lock_ERRORCHECK);
+#endif
 
+#if !defined(ANDROID_HOST_MUSL)
 static void BM_pthread_mutex_lock_RECURSIVE(benchmark::State& state) {
   pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
 
@@ -94,6 +97,7 @@
   }
 }
 BIONIC_BENCHMARK(BM_pthread_mutex_lock_RECURSIVE);
+#endif
 
 namespace {
 struct PIMutex {
diff --git a/benchmarks/time_benchmark.cpp b/benchmarks/time_benchmark.cpp
index a765e3e..70cc662 100644
--- a/benchmarks/time_benchmark.cpp
+++ b/benchmarks/time_benchmark.cpp
@@ -22,6 +22,21 @@
 #include <benchmark/benchmark.h>
 #include "util.h"
 
+// Musl doesn't define __NR_gettimeofday, __NR_clock_gettime32, __NR_gettimeofday_time32 or
+// __NR_clock_getres on 32-bit architectures.
+#if !defined(__NR_gettimeofday)
+#define __NR_gettimeofday __NR_gettimeofday_time32
+#endif
+#if !defined(__NR_clock_gettime)
+#define __NR_clock_gettime __NR_clock_gettime32
+#endif
+#if !defined(__NR_gettimeofday)
+#define __NR_gettimeofday __NR_gettimeofday_time32
+#endif
+#if !defined(__NR_clock_getres)
+#define __NR_clock_getres __NR_clock_getres_time32
+#endif
+
 static void BM_time_clock_gettime(benchmark::State& state) {
   // CLOCK_MONOTONIC is required supported in vdso
   timespec t;
diff --git a/libc/Android.bp b/libc/Android.bp
index 2dc10fc..f45b044 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -2572,8 +2572,133 @@
             enabled: true,
         },
     },
+    stl: "none",
+}
+
+cc_library_host_static {
+    name: "libexecinfo",
+    visibility: ["//external/musl"],
+    srcs: ["bionic/execinfo.cpp"],
+    export_include_dirs: ["execinfo/include"],
+    local_include_dirs: ["private"],
+    enabled: false,
+    target: {
+        musl: {
+            enabled: true,
+            system_shared_libs: [],
+            header_libs: ["libc_musl_headers"],
+        },
+    },
+    stl: "none",
+}
+
+cc_library_host_static {
+    name: "libb64",
+    visibility: ["//external/musl"],
+    srcs: ["upstream-openbsd/lib/libc/net/base64.c"],
+    export_include_dirs: ["b64/include"],
+    local_include_dirs: [
+        "private",
+        "upstream-openbsd/android/include",
+    ],
+    cflags: [
+        "-include openbsd-compat.h",
+    ],
+    enabled: false,
+    target: {
+        musl: {
+            enabled: true,
+            system_shared_libs: [],
+            header_libs: ["libc_musl_headers"],
+        },
+    },
+    stl: "none",
 }
 
 subdirs = [
     "bionic/scudo",
 ]
+
+// Export kernel uapi headers to be used in the musl sysroot.
+// Also include the execinfo headers for the libexecinfo and the
+// b64 headers for libb64 embedded in musl libc.
+cc_genrule {
+    name: "libc_musl_sysroot_bionic_headers",
+    visibility: ["//external/musl"],
+    host_supported: true,
+    device_supported: false,
+    enabled: false,
+    target: {
+        musl: {
+            enabled: true,
+        },
+    },
+    srcs: [
+        "kernel/uapi/**/*.h",
+        "kernel/android/**/*.h",
+        "execinfo/include/**/*.h",
+        "b64/include/**/*.h",
+
+        // This file is used to identify the location of the bionic/libc directory
+        // to simplify accessing the rest of the files.
+        "NOTICE",
+
+        ":libc_musl_sysroot_bionic_arch_headers",
+    ],
+    out: ["libc_musl_sysroot_bionic_headers.zip"],
+    tools: [
+        "soong_zip",
+        "merge_zips",
+        "zip2zip",
+    ],
+    cmd: "BIONIC_LIBC_DIR=$$(dirname $(location NOTICE)) && " +
+        "$(location soong_zip) -o $(genDir)/sysroot.zip -symlinks=false" +
+        // headers
+        " -P include " +
+        "  -C $${BIONIC_LIBC_DIR}/kernel/uapi " +
+        "  -D $${BIONIC_LIBC_DIR}/kernel/uapi " +
+        "  -C $${BIONIC_LIBC_DIR}/kernel/android/scsi " +
+        "  -D $${BIONIC_LIBC_DIR}/kernel/android/scsi " +
+        "  -C $${BIONIC_LIBC_DIR}/kernel/android/uapi " +
+        "  -D $${BIONIC_LIBC_DIR}/kernel/android/uapi " +
+        "  -C $${BIONIC_LIBC_DIR}/execinfo/include " +
+        "  -D $${BIONIC_LIBC_DIR}/execinfo/include " +
+        "  -C $${BIONIC_LIBC_DIR}/b64/include " +
+        "  -D $${BIONIC_LIBC_DIR}/b64/include " +
+        " && " +
+        "$(location merge_zips) $(out) $(location :libc_musl_sysroot_bionic_arch_headers) $(genDir)/sysroot.zip",
+}
+
+// The architecture-specific bits have to be handled separately because the label varies based
+// on architecture, which prevents using $(locations) to find them and requires using $(in)
+// instead, which would mix in all the other files if this were part of the main libc_musl_sysroot
+// genrule.
+cc_genrule {
+    name: "libc_musl_sysroot_bionic_arch_headers",
+    visibility: ["//visibility:private"],
+    host_supported: true,
+    device_supported: false,
+    enabled: false,
+    target: {
+        musl: {
+            enabled: true,
+        },
+    },
+    arch: {
+        arm: {
+            srcs: ["kernel/uapi/asm-arm/**/*.h"],
+        },
+        arm64: {
+            srcs: ["kernel/uapi/asm-arm64/**/*.h"],
+        },
+        x86: {
+            srcs: ["kernel/uapi/asm-x86/**/*.h"],
+        },
+        x86_64: {
+            srcs: ["kernel/uapi/asm-x86/**/*.h"],
+        },
+    },
+    out: ["libc_musl_sysroot_bionic_arch_headers.zip"],
+    tools: ["soong_zip"],
+    cmd: "includes=($(in)) && $(location soong_zip) -o $(out) -P include/asm -j -D $$(dirname $${includes[0]})",
+}
diff --git a/libc/NOTICE b/libc/NOTICE
index ff16da7..9cbbde2 100644
--- a/libc/NOTICE
+++ b/libc/NOTICE
@@ -910,6 +910,34 @@
 
 -------------------------------------------------------------------
 
+Copyright (C) 2022 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.
+
+-------------------------------------------------------------------
+
 Copyright (c) 1980, 1983, 1988, 1993
    The Regents of the University of California.  All rights reserved.
 
diff --git a/libc/arch-arm/bionic/kuser_helper_on.S b/libc/arch-arm/bionic/kuser_helper_on.S
index 2a1d86d..08291f7 100644
--- a/libc/arch-arm/bionic/kuser_helper_on.S
+++ b/libc/arch-arm/bionic/kuser_helper_on.S
@@ -32,10 +32,10 @@
   .balign 4
   .type kuser_helper_on, %object
 kuser_helper_on:
-  .long 2f-1f         // int32_t namesz
-  .long 3f-2f         // int32_t descsz
-  .long NT_TYPE_KUSER // int32_t type
-1:.ascii "Android\0"  // char name[]
-2:.long 1             // int32_t on
+  .long 2f-1f                 // int32_t namesz
+  .long 3f-2f                 // int32_t descsz
+  .long NT_ANDROID_TYPE_KUSER // int32_t type
+1:.ascii "Android\0"          // char name[]
+2:.long 1                     // int32_t on
 3:
   .size kuser_helper_on, .-kuser_helper_on
diff --git a/libc/arch-arm64/bionic/note_memtag_heap_async.S b/libc/arch-arm64/bionic/note_memtag_heap_async.S
index 208115c..931f40b 100644
--- a/libc/arch-arm64/bionic/note_memtag_heap_async.S
+++ b/libc/arch-arm64/bionic/note_memtag_heap_async.S
@@ -33,11 +33,11 @@
 
   .section ".note.android.memtag", "a", %note
   .p2align 2
-  .long 1f - 0f         // int32_t namesz
-  .long 3f - 2f         // int32_t descsz
-  .long NT_TYPE_MEMTAG  // int32_t type
+  .long 1f - 0f                 // int32_t namesz
+  .long 3f - 2f                 // int32_t descsz
+  .long NT_ANDROID_TYPE_MEMTAG  // int32_t type
 0:
-  .asciz "Android"      // char name[]
+  .asciz "Android"              // char name[]
 1:
   .p2align 2
 2:
diff --git a/libc/arch-arm64/bionic/note_memtag_heap_sync.S b/libc/arch-arm64/bionic/note_memtag_heap_sync.S
index d71ad02..77ab03a 100644
--- a/libc/arch-arm64/bionic/note_memtag_heap_sync.S
+++ b/libc/arch-arm64/bionic/note_memtag_heap_sync.S
@@ -33,11 +33,11 @@
 
   .section ".note.android.memtag", "a", %note
   .p2align 2
-  .long 1f - 0f         // int32_t namesz
-  .long 3f - 2f         // int32_t descsz
-  .long NT_TYPE_MEMTAG  // int32_t type
+  .long 1f - 0f                 // int32_t namesz
+  .long 3f - 2f                 // int32_t descsz
+  .long NT_ANDROID_TYPE_MEMTAG  // int32_t type
 0:
-  .asciz "Android"      // char name[]
+  .asciz "Android"              // char name[]
 1:
   .p2align 2
 2:
diff --git a/libc/arch-common/bionic/crtbrand.S b/libc/arch-common/bionic/crtbrand.S
index 307ef2e..b7540e9 100644
--- a/libc/arch-common/bionic/crtbrand.S
+++ b/libc/arch-common/bionic/crtbrand.S
@@ -40,7 +40,7 @@
 abitag:
   .long 2f-1f                 // int32_t namesz
   .long 3f-2f                 // int32_t descsz
-  .long NT_TYPE_IDENT         // int32_t type
+  .long NT_ANDROID_TYPE_IDENT // int32_t type
 #ifdef __ANDROID__
 1:.ascii "Android\0"          // char name[]
 2:.long PLATFORM_SDK_VERSION  // int32_t android_api
diff --git a/libc/b64/include/bionic/b64.h b/libc/b64/include/bionic/b64.h
new file mode 100644
index 0000000..f365bae
--- /dev/null
+++ b/libc/b64/include/bionic/b64.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2022 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 <sys/cdefs.h>
+#include <sys/types.h>
+
+__BEGIN_DECLS
+
+int b64_ntop(unsigned char const* __src, size_t __src_size, char* __dst, size_t __dst_size);
+int b64_pton(char const* __src, u_char* __dst, size_t __dst_size);
+
+__END_DECLS
diff --git a/libc/bionic/android_profiling_dynamic.cpp b/libc/bionic/android_profiling_dynamic.cpp
index 4fafd67..3460a6d 100644
--- a/libc/bionic/android_profiling_dynamic.cpp
+++ b/libc/bionic/android_profiling_dynamic.cpp
@@ -33,6 +33,7 @@
 #include <fcntl.h>
 #include <signal.h>
 #include <string.h>
+#include <sys/prctl.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -137,13 +138,25 @@
     return;
   }
 
+  // If the process is undumpable, /proc/self/mem will be owned by root:root, and therefore
+  // inaccessible to the process itself (see man 5 proc). We temporarily mark the process as
+  // dumpable to allow for the open. Note: prctl is not async signal safe per posix, but bionic's
+  // implementation is. Error checking on prctls is omitted due to them being trivial.
+  int orig_dumpable = prctl(PR_GET_DUMPABLE, 0, 0, 0, 0);
+  if (!orig_dumpable) {
+    prctl(PR_SET_DUMPABLE, 1, 0, 0, 0);
+  }
   ScopedFd maps_fd{ open("/proc/self/maps", O_RDONLY | O_CLOEXEC) };
+  ScopedFd mem_fd{ open("/proc/self/mem", O_RDONLY | O_CLOEXEC) };
+  if (!orig_dumpable) {
+    prctl(PR_SET_DUMPABLE, orig_dumpable, 0, 0, 0);
+  }
+
   if (maps_fd.get() == -1) {
     async_safe_format_log(ANDROID_LOG_ERROR, "libc", "failed to open /proc/self/maps: %s",
                           strerror(errno));
     return;
   }
-  ScopedFd mem_fd{ open("/proc/self/mem", O_RDONLY | O_CLOEXEC) };
   if (mem_fd.get() == -1) {
     async_safe_format_log(ANDROID_LOG_ERROR, "libc", "failed to open /proc/self/mem: %s",
                           strerror(errno));
diff --git a/libc/bionic/libc_init_dynamic.cpp b/libc/bionic/libc_init_dynamic.cpp
index 4625fa1..24efbf5 100644
--- a/libc/bionic/libc_init_dynamic.cpp
+++ b/libc/bionic/libc_init_dynamic.cpp
@@ -93,6 +93,15 @@
   __libc_init_common();
   __libc_init_scudo();
 
+#if __has_feature(hwaddress_sanitizer)
+  // Notify the HWASan runtime library whenever a library is loaded or unloaded
+  // so that it can update its shadow memory.
+  // This has to happen before _libc_init_malloc which might dlopen to load
+  // profiler libraries.
+  __libc_shared_globals()->load_hook = __hwasan_library_loaded;
+  __libc_shared_globals()->unload_hook = __hwasan_library_unloaded;
+#endif
+
   // Hooks for various libraries to let them know that we're starting up.
   __libc_globals.mutate(__libc_init_malloc);
 
@@ -101,13 +110,6 @@
 
   __libc_init_fork_handler();
 
-#if __has_feature(hwaddress_sanitizer)
-  // Notify the HWASan runtime library whenever a library is loaded or unloaded
-  // so that it can update its shadow memory.
-  __libc_shared_globals()->load_hook = __hwasan_library_loaded;
-  __libc_shared_globals()->unload_hook = __hwasan_library_unloaded;
-#endif
-
   __libc_shared_globals()->set_target_sdk_version_hook = __libc_set_target_sdk_version;
 
   netdClientInit();
diff --git a/libc/bionic/libc_init_static.cpp b/libc/bionic/libc_init_static.cpp
index 67e692c..815b938 100644
--- a/libc/bionic/libc_init_static.cpp
+++ b/libc/bionic/libc_init_static.cpp
@@ -191,14 +191,17 @@
 #ifdef __aarch64__
 static bool __read_memtag_note(const ElfW(Nhdr)* note, const char* name, const char* desc,
                                unsigned* result) {
+  if (note->n_type != NT_ANDROID_TYPE_MEMTAG) {
+    return false;
+  }
   if (note->n_namesz != 8 || strncmp(name, "Android", 8) != 0) {
     return false;
   }
-  if (note->n_type != NT_TYPE_MEMTAG) {
-    return false;
-  }
-  if (note->n_descsz != 4) {
-    async_safe_fatal("unrecognized android.memtag note: n_descsz = %d, expected 4", note->n_descsz);
+  // Previously (in Android 12), if the note was != 4 bytes, we check-failed
+  // here. Let's be more permissive to allow future expansion.
+  if (note->n_descsz < 4) {
+    async_safe_fatal("unrecognized android.memtag note: n_descsz = %d, expected >= 4",
+                     note->n_descsz);
   }
   *result = *reinterpret_cast<const ElfW(Word)*>(desc);
   return true;
@@ -237,6 +240,7 @@
 // level into *level.
 static bool get_environment_memtag_setting(HeapTaggingLevel* level) {
   static const char kMemtagPrognameSyspropPrefix[] = "arm64.memtag.process.";
+  static const char kMemtagGlobalSysprop[] = "persist.arm64.memtag.default";
 
   const char* progname = __libc_shared_globals()->init_progname;
   if (progname == nullptr) return false;
@@ -250,9 +254,10 @@
 
   async_safe_format_buffer(sysprop_name, sysprop_size, "%s%s", kMemtagPrognameSyspropPrefix,
                            basename);
+  const char* sys_prop_names[] = {sysprop_name, kMemtagGlobalSysprop};
 
-  if (!get_config_from_env_or_sysprops("MEMTAG_OPTIONS", &sysprop_name,
-                                       /* sys_prop_names_size */ 1, options_str, kOptionsSize)) {
+  if (!get_config_from_env_or_sysprops("MEMTAG_OPTIONS", sys_prop_names, arraysize(sys_prop_names),
+                                       options_str, kOptionsSize)) {
     return false;
   }
 
@@ -283,21 +288,29 @@
 
   unsigned note_val =
       __get_memtag_note(reinterpret_cast<const ElfW(Phdr)*>(phdr_start), phdr_ct, load_bias);
-  if (note_val & ~(NT_MEMTAG_LEVEL_MASK | NT_MEMTAG_HEAP)) {
-    async_safe_fatal("unrecognized android.memtag note: desc = %d", note_val);
-  }
 
+  // Note, previously (in Android 12), any value outside of bits [0..3] resulted
+  // in a check-fail. In order to be permissive of further extensions, we
+  // relaxed this restriction. For now, we still only support MTE heap.
   if (!(note_val & NT_MEMTAG_HEAP)) return M_HEAP_TAGGING_LEVEL_TBI;
 
-  unsigned memtag_level = note_val & NT_MEMTAG_LEVEL_MASK;
-  switch (memtag_level) {
+  unsigned mode = note_val & NT_MEMTAG_LEVEL_MASK;
+  switch (mode) {
+    case NT_MEMTAG_LEVEL_NONE:
+      // Note, previously (in Android 12), NT_MEMTAG_LEVEL_NONE was
+      // NT_MEMTAG_LEVEL_DEFAULT, which implied SYNC mode. This was never used
+      // by anyone, but we note it (heh) here for posterity, in case the zero
+      // level becomes meaningful, and binaries with this note can be executed
+      // on Android 12 devices.
+      return M_HEAP_TAGGING_LEVEL_TBI;
     case NT_MEMTAG_LEVEL_ASYNC:
       return M_HEAP_TAGGING_LEVEL_ASYNC;
-    case NT_MEMTAG_LEVEL_DEFAULT:
     case NT_MEMTAG_LEVEL_SYNC:
-      return M_HEAP_TAGGING_LEVEL_SYNC;
     default:
-      async_safe_fatal("unrecognized android.memtag note: level = %d", memtag_level);
+      // We allow future extensions to specify mode 3 (currently unused), with
+      // the idea that it might be used for ASYMM mode or something else. On
+      // this version of Android, it falls back to SYNC mode.
+      return M_HEAP_TAGGING_LEVEL_SYNC;
   }
 }
 
diff --git a/libc/execinfo/include/bionic/execinfo.h b/libc/execinfo/include/bionic/execinfo.h
new file mode 120000
index 0000000..0068019
--- /dev/null
+++ b/libc/execinfo/include/bionic/execinfo.h
@@ -0,0 +1 @@
+../../../include/execinfo.h
\ No newline at end of file
diff --git a/libc/execinfo/include/execinfo.h b/libc/execinfo/include/execinfo.h
new file mode 100644
index 0000000..e092c00
--- /dev/null
+++ b/libc/execinfo/include/execinfo.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2021 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
+
+/*
+ * This file is exported as part of libexecinfo for use with musl, which doesn't
+ * define __INTRODUCED_IN.  Stub it out.
+ */
+#define __INTRODUCED_IN(x)
+#include <bionic/execinfo.h>
+#undef __INTRODUCED_IN
diff --git a/libc/include/bits/fortify/stdio.h b/libc/include/bits/fortify/stdio.h
index 42698dd..77bdbb4 100644
--- a/libc/include/bits/fortify/stdio.h
+++ b/libc/include/bits/fortify/stdio.h
@@ -40,6 +40,7 @@
 /* No diag -- clang diagnoses misuses of this on its own.  */
 __BIONIC_FORTIFY_INLINE __printflike(3, 0)
 int vsnprintf(char* const __pass_object_size dest, size_t size, const char* format, va_list ap)
+        __diagnose_as_builtin(__builtin_vsnprintf, 1, 2, 3, 4)
         __overloadable {
     return __builtin___vsnprintf_chk(dest, size, 0, __bos(dest), format, ap);
 }
@@ -70,6 +71,7 @@
 /* No diag -- clang diagnoses misuses of this on its own.  */
 __BIONIC_FORTIFY_VARIADIC __printflike(3, 4)
 int snprintf(char* const __pass_object_size dest, size_t size, const char* format, ...)
+        __diagnose_as_builtin(__builtin_snprintf, 1, 2, 3)
         __overloadable {
     va_list va;
     va_start(va, format);
diff --git a/libc/include/bits/fortify/string.h b/libc/include/bits/fortify/string.h
index beb5ff5..08bce2d 100644
--- a/libc/include/bits/fortify/string.h
+++ b/libc/include/bits/fortify/string.h
@@ -44,13 +44,16 @@
 /* No diag -- clang diagnoses misuses of this on its own.  */
 __BIONIC_FORTIFY_INLINE
 void* memcpy(void* const dst __pass_object_size0, const void* src, size_t copy_amount)
+        __diagnose_as_builtin(__builtin_memcpy, 1, 2, 3)
         __overloadable {
     return __builtin___memcpy_chk(dst, src, copy_amount, __bos0(dst));
 }
 
 /* No diag -- clang diagnoses misuses of this on its own.  */
 __BIONIC_FORTIFY_INLINE
-void* memmove(void* const dst __pass_object_size0, const void* src, size_t len) __overloadable {
+void* memmove(void* const dst __pass_object_size0, const void* src, size_t len)
+        __diagnose_as_builtin(__builtin_memmove, 1, 2, 3)
+        __overloadable {
     return __builtin___memmove_chk(dst, src, len, __bos0(dst));
 }
 #endif
@@ -59,6 +62,7 @@
 #if __ANDROID_API__ >= 30
 __BIONIC_FORTIFY_INLINE
 void* mempcpy(void* const dst __pass_object_size0, const void* src, size_t copy_amount)
+        __diagnose_as_builtin(__builtin_mempcpy, 1, 2, 3)
         __overloadable
         __clang_error_if(__bos_unevaluated_lt(__bos0(dst), copy_amount),
                          "'mempcpy' called with size bigger than buffer") {
@@ -87,6 +91,7 @@
 
 __BIONIC_FORTIFY_INLINE
 char* strcpy(char* const dst __pass_object_size, const char* src)
+        __diagnose_as_builtin(__builtin_strcpy, 1, 2)
         __overloadable
         __clang_error_if(__bos_unevaluated_le(__bos(dst), __builtin_strlen(src)),
                          "'strcpy' called with string bigger than buffer") {
@@ -112,7 +117,9 @@
 #if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
 /* No diag -- clang diagnoses misuses of this on its own.  */
 __BIONIC_FORTIFY_INLINE
-char* strncat(char* const dst __pass_object_size, const char* src, size_t n) __overloadable {
+char* strncat(char* const dst __pass_object_size, const char* src, size_t n)
+       __diagnose_as_builtin(__builtin_strncat, 1, 2, 3)
+       __overloadable {
     return __builtin___strncat_chk(dst, src, n, __bos(dst));
 }
 #endif
@@ -120,6 +127,7 @@
 /* No diag -- clang diagnoses misuses of this on its own.  */
 __BIONIC_FORTIFY_INLINE
 void* memset(void* const s __pass_object_size0, int c, size_t n) __overloadable
+        __diagnose_as_builtin(__builtin_memset, 1, 2, 3)
         /* If you're a user who wants this warning to go away: use `(&memset)(foo, bar, baz)`. */
         __clang_warning_if(c && !n, "'memset' will set 0 bytes; maybe the arguments got flipped?") {
 #if __ANDROID_API__ >= 17 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
@@ -157,6 +165,7 @@
 /* No diag -- clang diagnoses misuses of this on its own.  */
 __BIONIC_FORTIFY_INLINE
 char* stpncpy(char* const dst __pass_object_size, const char* const src __pass_object_size, size_t n)
+        __diagnose_as_builtin(__builtin_stpncpy, 1, 2, 3)
         __overloadable {
     size_t bos_dst = __bos(dst);
     size_t bos_src = __bos(src);
@@ -172,6 +181,7 @@
 /* No diag -- clang diagnoses misuses of this on its own.  */
 __BIONIC_FORTIFY_INLINE
 char* strncpy(char* const dst __pass_object_size, const char* const src __pass_object_size, size_t n)
+        __diagnose_as_builtin(__builtin_strncpy, 1, 2, 3)
         __overloadable {
     size_t bos_dst = __bos(dst);
     size_t bos_src = __bos(src);
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index 2556d11..99a200a 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -327,6 +327,13 @@
 
 #define __overloadable __attribute__((overloadable))
 
+// TODO(pirama) Remove this version check after switching to clang-r445002
+#if __clang_major__ == 14 && __clang_patchlevel__ >= 2
+#define __diagnose_as_builtin(...) __attribute__((diagnose_as_builtin(__VA_ARGS__)))
+#else
+#define __diagnose_as_builtin(...)
+#endif
+
 /* Used to tag non-static symbols that are private and never exposed by the shared library. */
 #define __LIBC_HIDDEN__ __attribute__((visibility("hidden")))
 
diff --git a/libc/malloc_debug/UnwindBacktrace.cpp b/libc/malloc_debug/UnwindBacktrace.cpp
index dbaebb3..a7036d9 100644
--- a/libc/malloc_debug/UnwindBacktrace.cpp
+++ b/libc/malloc_debug/UnwindBacktrace.cpp
@@ -90,11 +90,13 @@
     std::shared_ptr<unwindstack::MapInfo> map_info = info->map_info;
 
     std::string line = android::base::StringPrintf("          #%0zd  pc %" PAD_PTR "  ", i, info->rel_pc);
-    if (map_info->offset() != 0) {
+    if (map_info != nullptr && map_info->offset() != 0) {
       line += android::base::StringPrintf("(offset 0x%" PRIx64 ") ", map_info->offset());
     }
 
-    if (map_info->name().empty()) {
+    if (map_info == nullptr) {
+      line += "<unknown>";
+    } else if (map_info->name().empty()) {
       line += android::base::StringPrintf("<anonymous:%" PRIx64 ">", map_info->start());
     } else {
       line += map_info->name();
diff --git a/libc/private/bionic_asm_arm64.h b/libc/private/bionic_asm_arm64.h
index ee51a8e..5d83d9b 100644
--- a/libc/private/bionic_asm_arm64.h
+++ b/libc/private/bionic_asm_arm64.h
@@ -72,7 +72,7 @@
     .popsection;
 
 #define NT_MEMTAG_LEVEL_MASK 3
-#define NT_MEMTAG_LEVEL_DEFAULT 0
+#define NT_MEMTAG_LEVEL_NONE 0
 #define NT_MEMTAG_LEVEL_ASYNC 1
 #define NT_MEMTAG_LEVEL_SYNC 2
 #define NT_MEMTAG_HEAP 4
diff --git a/libc/private/bionic_asm_note.h b/libc/private/bionic_asm_note.h
index 80b8f01..d8559ff 100644
--- a/libc/private/bionic_asm_note.h
+++ b/libc/private/bionic_asm_note.h
@@ -28,6 +28,6 @@
 
 #pragma once
 
-#define NT_TYPE_IDENT 1
-#define NT_TYPE_KUSER 3
-#define NT_TYPE_MEMTAG 4
+#define NT_ANDROID_TYPE_IDENT 1
+#define NT_ANDROID_TYPE_KUSER 3
+#define NT_ANDROID_TYPE_MEMTAG 4
diff --git a/linker/linked_list.h b/linker/linked_list.h
index b8a8f0e..2741008 100644
--- a/linker/linked_list.h
+++ b/linker/linked_list.h
@@ -79,76 +79,89 @@
   typedef LinkedListIterator<T> iterator;
   typedef T* value_type;
 
-  LinkedList() : head_(nullptr), tail_(nullptr) {}
+  // Allocating the head/tail fields separately from the LinkedList struct saves memory in the
+  // Zygote (e.g. because adding an soinfo to a namespace doesn't dirty the page containing the
+  // soinfo).
+  struct LinkedListHeader {
+    LinkedListEntry<T>* head;
+    LinkedListEntry<T>* tail;
+  };
+
+  // The allocator returns a LinkedListEntry<T>* but we want to treat it as a LinkedListHeader
+  // struct instead.
+  static_assert(sizeof(LinkedListHeader) == sizeof(LinkedListEntry<T>));
+  static_assert(alignof(LinkedListHeader) == alignof(LinkedListEntry<T>));
+
+  constexpr LinkedList() : header_(nullptr) {}
   ~LinkedList() {
     clear();
+    if (header_ != nullptr) {
+      Allocator::free(reinterpret_cast<LinkedListEntry<T>*>(header_));
+    }
   }
 
   LinkedList(LinkedList&& that) noexcept {
-    this->head_ = that.head_;
-    this->tail_ = that.tail_;
-    that.head_ = that.tail_ = nullptr;
+    this->header_ = that.header_;
+    that.header_ = nullptr;
+  }
+
+  bool empty() const {
+    return header_ == nullptr || header_->head == nullptr;
   }
 
   void push_front(T* const element) {
+    alloc_header();
     LinkedListEntry<T>* new_entry = Allocator::alloc();
-    new_entry->next = head_;
+    new_entry->next = header_->head;
     new_entry->element = element;
-    head_ = new_entry;
-    if (tail_ == nullptr) {
-      tail_ = new_entry;
+    header_->head = new_entry;
+    if (header_->tail == nullptr) {
+      header_->tail = new_entry;
     }
   }
 
   void push_back(T* const element) {
+    alloc_header();
     LinkedListEntry<T>* new_entry = Allocator::alloc();
     new_entry->next = nullptr;
     new_entry->element = element;
-    if (tail_ == nullptr) {
-      tail_ = head_ = new_entry;
+    if (header_->tail == nullptr) {
+      header_->tail = header_->head = new_entry;
     } else {
-      tail_->next = new_entry;
-      tail_ = new_entry;
+      header_->tail->next = new_entry;
+      header_->tail = new_entry;
     }
   }
 
   T* pop_front() {
-    if (head_ == nullptr) {
-      return nullptr;
-    }
+    if (empty()) return nullptr;
 
-    LinkedListEntry<T>* entry = head_;
+    LinkedListEntry<T>* entry = header_->head;
     T* element = entry->element;
-    head_ = entry->next;
+    header_->head = entry->next;
     Allocator::free(entry);
 
-    if (head_ == nullptr) {
-      tail_ = nullptr;
+    if (header_->head == nullptr) {
+      header_->tail = nullptr;
     }
 
     return element;
   }
 
   T* front() const {
-    if (head_ == nullptr) {
-      return nullptr;
-    }
-
-    return head_->element;
+    return empty() ? nullptr : header_->head->element;
   }
 
   void clear() {
-    while (head_ != nullptr) {
-      LinkedListEntry<T>* p = head_;
-      head_ = head_->next;
+    if (empty()) return;
+
+    while (header_->head != nullptr) {
+      LinkedListEntry<T>* p = header_->head;
+      header_->head = header_->head->next;
       Allocator::free(p);
     }
 
-    tail_ = nullptr;
-  }
-
-  bool empty() {
-    return (head_ == nullptr);
+    header_->tail = nullptr;
   }
 
   template<typename F>
@@ -161,7 +174,7 @@
 
   template<typename F>
   bool visit(F action) const {
-    for (LinkedListEntry<T>* e = head_; e != nullptr; e = e->next) {
+    for (LinkedListEntry<T>* e = head(); e != nullptr; e = e->next) {
       if (!action(e->element)) {
         return false;
       }
@@ -171,17 +184,18 @@
 
   template<typename F>
   void remove_if(F predicate) {
-    for (LinkedListEntry<T>* e = head_, *p = nullptr; e != nullptr;) {
+    if (empty()) return;
+    for (LinkedListEntry<T>* e = header_->head, *p = nullptr; e != nullptr;) {
       if (predicate(e->element)) {
         LinkedListEntry<T>* next = e->next;
         if (p == nullptr) {
-          head_ = next;
+          header_->head = next;
         } else {
           p->next = next;
         }
 
-        if (tail_ == e) {
-          tail_ = p;
+        if (header_->tail == e) {
+          header_->tail = p;
         }
 
         Allocator::free(e);
@@ -202,7 +216,7 @@
 
   template<typename F>
   T* find_if(F predicate) const {
-    for (LinkedListEntry<T>* e = head_; e != nullptr; e = e->next) {
+    for (LinkedListEntry<T>* e = head(); e != nullptr; e = e->next) {
       if (predicate(e->element)) {
         return e->element;
       }
@@ -212,7 +226,7 @@
   }
 
   iterator begin() const {
-    return iterator(head_);
+    return iterator(head());
   }
 
   iterator end() const {
@@ -220,7 +234,7 @@
   }
 
   iterator find(T* value) const {
-    for (LinkedListEntry<T>* e = head_; e != nullptr; e = e->next) {
+    for (LinkedListEntry<T>* e = head(); e != nullptr; e = e->next) {
       if (e->element == value) {
         return iterator(e);
       }
@@ -231,7 +245,7 @@
 
   size_t copy_to_array(T* array[], size_t array_length) const {
     size_t sz = 0;
-    for (LinkedListEntry<T>* e = head_; sz < array_length && e != nullptr; e = e->next) {
+    for (LinkedListEntry<T>* e = head(); sz < array_length && e != nullptr; e = e->next) {
       array[sz++] = e->element;
     }
 
@@ -239,7 +253,7 @@
   }
 
   bool contains(const T* el) const {
-    for (LinkedListEntry<T>* e = head_; e != nullptr; e = e->next) {
+    for (LinkedListEntry<T>* e = head(); e != nullptr; e = e->next) {
       if (e->element == el) {
         return true;
       }
@@ -260,7 +274,17 @@
   }
 
  private:
-  LinkedListEntry<T>* head_;
-  LinkedListEntry<T>* tail_;
+  void alloc_header() {
+    if (header_ == nullptr) {
+      header_ = reinterpret_cast<LinkedListHeader*>(Allocator::alloc());
+      header_->head = header_->tail = nullptr;
+    }
+  }
+
+  LinkedListEntry<T>* head() const {
+    return header_ != nullptr ? header_->head : nullptr;
+  }
+
+  LinkedListHeader* header_;
   DISALLOW_COPY_AND_ASSIGN(LinkedList);
 };
diff --git a/linker/linker_block_allocator.cpp b/linker/linker_block_allocator.cpp
index 5b68b1d..60e5e1c 100644
--- a/linker/linker_block_allocator.cpp
+++ b/linker/linker_block_allocator.cpp
@@ -31,6 +31,7 @@
 #include <inttypes.h>
 #include <string.h>
 #include <sys/mman.h>
+#include <sys/param.h>
 #include <sys/prctl.h>
 #include <unistd.h>
 
@@ -39,11 +40,6 @@
 static constexpr size_t kAllocateSize = PAGE_SIZE * 100;
 static_assert(kAllocateSize % PAGE_SIZE == 0, "Invalid kAllocateSize.");
 
-// the multiplier should be power of 2
-static constexpr size_t round_up(size_t size, size_t multiplier) {
-  return (size + (multiplier - 1)) & ~(multiplier-1);
-}
-
 struct LinkerBlockAllocatorPage {
   LinkerBlockAllocatorPage* next;
   uint8_t bytes[kAllocateSize - 16] __attribute__((aligned(16)));
@@ -54,13 +50,14 @@
   size_t num_free_blocks;
 };
 
+static_assert(kBlockSizeAlign >= alignof(FreeBlockInfo));
+static_assert(kBlockSizeMin == sizeof(FreeBlockInfo));
+
 LinkerBlockAllocator::LinkerBlockAllocator(size_t block_size)
-  : block_size_(
-      round_up(block_size < sizeof(FreeBlockInfo) ? sizeof(FreeBlockInfo) : block_size, 16)),
-    page_list_(nullptr),
-    free_block_list_(nullptr),
-    allocated_(0)
-{}
+    : block_size_(__BIONIC_ALIGN(MAX(block_size, kBlockSizeMin), kBlockSizeAlign)),
+      page_list_(nullptr),
+      free_block_list_(nullptr),
+      allocated_(0) {}
 
 void* LinkerBlockAllocator::alloc() {
   if (free_block_list_ == nullptr) {
diff --git a/linker/linker_block_allocator.h b/linker/linker_block_allocator.h
index 8ae4094..32656c7 100644
--- a/linker/linker_block_allocator.h
+++ b/linker/linker_block_allocator.h
@@ -33,6 +33,9 @@
 
 #include <android-base/macros.h>
 
+static constexpr size_t kBlockSizeAlign = sizeof(void*);
+static constexpr size_t kBlockSizeMin = sizeof(void*) * 2;
+
 struct LinkerBlockAllocatorPage;
 
 /*
diff --git a/linker/linker_block_allocator_test.cpp b/linker/linker_block_allocator_test.cpp
index 6fb2b26..56fbee8 100644
--- a/linker/linker_block_allocator_test.cpp
+++ b/linker/linker_block_allocator_test.cpp
@@ -29,6 +29,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/mman.h>
+#include <sys/param.h>
 
 #include <gtest/gtest.h>
 
@@ -44,12 +45,16 @@
 };
 
 /*
- * this one has size below allocator cap which is 2*sizeof(void*)
+ * this one has size below kBlockSizeAlign
  */
 struct test_struct_small {
-  char str[5];
+  char str[3];
 };
 
+struct test_struct_max_align {
+  char str[16];
+} __attribute__((aligned(16)));
+
 /*
  * 1009 byte struct (1009 is prime)
  */
@@ -58,54 +63,49 @@
 };
 
 static size_t kPageSize = sysconf(_SC_PAGE_SIZE);
-};
 
-TEST(linker_allocator, test_nominal) {
-  LinkerTypeAllocator<test_struct_nominal> allocator;
+template <typename Element>
+void linker_allocator_test_helper() {
+  LinkerTypeAllocator<Element> allocator;
 
-  test_struct_nominal* ptr1 = allocator.alloc();
+  Element* ptr1 = allocator.alloc();
   ASSERT_TRUE(ptr1 != nullptr);
-  ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr1) % 16);
-  test_struct_nominal* ptr2 = allocator.alloc();
-  ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr2) % 16);
+  ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr1) % kBlockSizeAlign);
+  ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr1) % alignof(Element));
+  Element* ptr2 = allocator.alloc();
+  ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr2) % kBlockSizeAlign);
+  ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr2) % alignof(Element));
   ASSERT_TRUE(ptr2 != nullptr);
-  // they should be next to each other.
-  ASSERT_EQ(reinterpret_cast<uint8_t*>(ptr1)+16, reinterpret_cast<uint8_t*>(ptr2));
 
-  ptr1->value = 42;
+  // they should be next to each other.
+  size_t dist = __BIONIC_ALIGN(MAX(sizeof(Element), kBlockSizeMin), kBlockSizeAlign);
+  ASSERT_EQ(reinterpret_cast<uint8_t*>(ptr1) + dist, reinterpret_cast<uint8_t*>(ptr2));
 
   allocator.free(ptr1);
   allocator.free(ptr2);
 }
 
+};  // anonymous namespace
+
+TEST(linker_allocator, test_nominal) {
+  linker_allocator_test_helper<test_struct_nominal>();
+}
+
 TEST(linker_allocator, test_small) {
-  LinkerTypeAllocator<test_struct_small> allocator;
+  linker_allocator_test_helper<test_struct_small>();
+}
 
-  char* ptr1 = reinterpret_cast<char*>(allocator.alloc());
-  char* ptr2 = reinterpret_cast<char*>(allocator.alloc());
-
-  ASSERT_TRUE(ptr1 != nullptr);
-  ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr1) % 16);
-  ASSERT_TRUE(ptr2 != nullptr);
-  ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr2) % 16);
-  ASSERT_EQ(ptr1+16, ptr2); // aligned to 16
+TEST(linker_allocator, test_max_align) {
+  linker_allocator_test_helper<test_struct_max_align>();
 }
 
 TEST(linker_allocator, test_larger) {
+  linker_allocator_test_helper<test_struct_larger>();
+
   LinkerTypeAllocator<test_struct_larger> allocator;
 
-  test_struct_larger* ptr1 = allocator.alloc();
-  test_struct_larger* ptr2 = allocator.alloc();
-
-  ASSERT_TRUE(ptr1 != nullptr);
-  ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr1) % 16);
-  ASSERT_TRUE(ptr2 != nullptr);
-  ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr2) % 16);
-
-  ASSERT_EQ(reinterpret_cast<uint8_t*>(ptr1) + 1024, reinterpret_cast<uint8_t*>(ptr2));
-
   // lets allocate until we reach next page.
-  size_t n = kPageSize/sizeof(test_struct_larger) + 1 - 2;
+  size_t n = kPageSize / sizeof(test_struct_larger) + 1;
 
   for (size_t i=0; i<n; ++i) {
     ASSERT_TRUE(allocator.alloc() != nullptr);
@@ -113,7 +113,6 @@
 
   test_struct_larger* ptr_to_free = allocator.alloc();
   ASSERT_TRUE(ptr_to_free != nullptr);
-  allocator.free(ptr1);
 }
 
 static void protect_all() {
diff --git a/tests/Android.bp b/tests/Android.bp
index 19d18ab..b30eac9 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -474,9 +474,6 @@
                 // musl doesn't have error.h
                 "error_test.cpp",
 
-                // musl doesn't have execinfo.h
-                "execinfo_test.cpp",
-
                 // musl doesn't define noreturn for C++
                 "stdnoreturn_test.cpp",
 
@@ -602,6 +599,10 @@
         host: {
             clang_cflags: ["-D__clang__"],
         },
+        musl: {
+            // Musl doesn't have fortify
+            enabled: false,
+        },
     },
 }
 
@@ -723,6 +724,7 @@
 cc_test_library {
     name: "libBionicTests",
     defaults: ["bionic_tests_defaults"],
+    host_supported: false,
     whole_static_libs: [
         "libBionicStandardTests",
         "libBionicElfTlsTests",
@@ -1120,6 +1122,14 @@
     lto: {
         never: true,
     },
+    data_bins: [
+        "heap_tagging_async_helper",
+        "heap_tagging_disabled_helper",
+        "heap_tagging_static_async_helper",
+        "heap_tagging_static_disabled_helper",
+        "heap_tagging_static_sync_helper",
+        "heap_tagging_sync_helper",
+    ],
 }
 
 // -----------------------------------------------------------------------------
diff --git a/tests/headers/posix/Android.bp b/tests/headers/posix/Android.bp
index 0809cdb..4a20d45 100644
--- a/tests/headers/posix/Android.bp
+++ b/tests/headers/posix/Android.bp
@@ -33,5 +33,8 @@
         darwin: {
             enabled: false,
         },
+        musl: {
+            enabled: false,
+        },
     },
 }
diff --git a/tests/malloc_test.cpp b/tests/malloc_test.cpp
index 8272d39..f157ec4 100644
--- a/tests/malloc_test.cpp
+++ b/tests/malloc_test.cpp
@@ -765,7 +765,7 @@
 }
 
 TEST(malloc, mallinfo) {
-#if defined(__BIONIC__)
+#if defined(__BIONIC__) || defined(ANDROID_HOST_MUSL)
   SKIP_WITH_HWASAN << "hwasan does not implement mallinfo";
   static size_t sizes[] = {
     8, 32, 128, 4096, 32768, 131072, 1024000, 10240000, 20480000, 300000000
@@ -810,7 +810,7 @@
 }
 
 TEST(malloc, mallinfo2) {
-#if defined(__BIONIC__)
+#if defined(__BIONIC__) || defined(ANDROID_HOST_MUSL)
   SKIP_WITH_HWASAN << "hwasan does not implement mallinfo2";
   static size_t sizes[] = {8, 32, 128, 4096, 32768, 131072, 1024000, 10240000, 20480000, 300000000};
 
@@ -828,16 +828,16 @@
       struct mallinfo info = mallinfo();
       struct mallinfo2 info2 = mallinfo2();
       // Verify that mallinfo and mallinfo2 are exactly the same.
-      ASSERT_EQ(info.arena, info2.arena);
-      ASSERT_EQ(info.ordblks, info2.ordblks);
-      ASSERT_EQ(info.smblks, info2.smblks);
-      ASSERT_EQ(info.hblks, info2.hblks);
-      ASSERT_EQ(info.hblkhd, info2.hblkhd);
-      ASSERT_EQ(info.usmblks, info2.usmblks);
-      ASSERT_EQ(info.fsmblks, info2.fsmblks);
-      ASSERT_EQ(info.uordblks, info2.uordblks);
-      ASSERT_EQ(info.fordblks, info2.fordblks);
-      ASSERT_EQ(info.keepcost, info2.keepcost);
+      ASSERT_EQ(static_cast<size_t>(info.arena), info2.arena);
+      ASSERT_EQ(static_cast<size_t>(info.ordblks), info2.ordblks);
+      ASSERT_EQ(static_cast<size_t>(info.smblks), info2.smblks);
+      ASSERT_EQ(static_cast<size_t>(info.hblks), info2.hblks);
+      ASSERT_EQ(static_cast<size_t>(info.hblkhd), info2.hblkhd);
+      ASSERT_EQ(static_cast<size_t>(info.usmblks), info2.usmblks);
+      ASSERT_EQ(static_cast<size_t>(info.fsmblks), info2.fsmblks);
+      ASSERT_EQ(static_cast<size_t>(info.uordblks), info2.uordblks);
+      ASSERT_EQ(static_cast<size_t>(info.fordblks), info2.fordblks);
+      ASSERT_EQ(static_cast<size_t>(info.keepcost), info2.keepcost);
 
       size_t allocated = info2.uordblks;
       ptrs[i] = malloc(size);
@@ -846,16 +846,16 @@
       info = mallinfo();
       info2 = mallinfo2();
       // Verify that mallinfo and mallinfo2 are exactly the same.
-      ASSERT_EQ(info.arena, info2.arena);
-      ASSERT_EQ(info.ordblks, info2.ordblks);
-      ASSERT_EQ(info.smblks, info2.smblks);
-      ASSERT_EQ(info.hblks, info2.hblks);
-      ASSERT_EQ(info.hblkhd, info2.hblkhd);
-      ASSERT_EQ(info.usmblks, info2.usmblks);
-      ASSERT_EQ(info.fsmblks, info2.fsmblks);
-      ASSERT_EQ(info.uordblks, info2.uordblks);
-      ASSERT_EQ(info.fordblks, info2.fordblks);
-      ASSERT_EQ(info.keepcost, info2.keepcost);
+      ASSERT_EQ(static_cast<size_t>(info.arena), info2.arena);
+      ASSERT_EQ(static_cast<size_t>(info.ordblks), info2.ordblks);
+      ASSERT_EQ(static_cast<size_t>(info.smblks), info2.smblks);
+      ASSERT_EQ(static_cast<size_t>(info.hblks), info2.hblks);
+      ASSERT_EQ(static_cast<size_t>(info.hblkhd), info2.hblkhd);
+      ASSERT_EQ(static_cast<size_t>(info.usmblks), info2.usmblks);
+      ASSERT_EQ(static_cast<size_t>(info.fsmblks), info2.fsmblks);
+      ASSERT_EQ(static_cast<size_t>(info.uordblks), info2.uordblks);
+      ASSERT_EQ(static_cast<size_t>(info.fordblks), info2.fordblks);
+      ASSERT_EQ(static_cast<size_t>(info.keepcost), info2.keepcost);
 
       size_t new_allocated = info2.uordblks;
       if (allocated != new_allocated) {
diff --git a/tests/resolv_test.cpp b/tests/resolv_test.cpp
index 4425503..0cd8e63 100644
--- a/tests/resolv_test.cpp
+++ b/tests/resolv_test.cpp
@@ -33,7 +33,6 @@
 #include <gtest/gtest.h>
 
 TEST(resolv, b64_pton_28035006) {
-#if !defined(ANDROID_HOST_MUSL)
   // Test data from https://groups.google.com/forum/#!topic/mailing.openbsd.tech/w3ACIlklJkI.
   const char* data =
       "p1v3+nehH3N3n+/OokzXpsyGF2VVpxIxkjSn3Mv/Sq74OE1iFuVU+K4bQImuVj"
@@ -44,33 +43,22 @@
   // incorrectly required an extra byte. http://b/28035006.
   uint8_t buf[128];
   ASSERT_EQ(128, b64_pton(data, buf, sizeof(buf)));
-#else
-  GTEST_SKIP() << "musl doesn't have b64_pton";
-#endif
 }
 
 TEST(resolv, b64_ntop) {
-#if !defined(ANDROID_HOST_MUSL)
   char buf[128];
   memset(buf, 'x', sizeof(buf));
   ASSERT_EQ(static_cast<int>(strlen("aGVsbG8=")),
             b64_ntop(reinterpret_cast<u_char const*>("hello"), strlen("hello"),
                      buf, sizeof(buf)));
   ASSERT_STREQ(buf, "aGVsbG8=");
-#else
-  GTEST_SKIP() << "musl doesn't have b64_ntop";
-#endif
 }
 
 TEST(resolv, b64_pton) {
-#if !defined(ANDROID_HOST_MUSL)
   u_char buf[128];
   memset(buf, 'x', sizeof(buf));
   ASSERT_EQ(static_cast<int>(strlen("hello")), b64_pton("aGVsbG8=", buf, sizeof(buf)));
   ASSERT_STREQ(reinterpret_cast<char*>(buf), "hello");
-#else
-  GTEST_SKIP() << "musl doesn't have b64_pton";
-#endif
 }
 
 TEST(resolv, p_class) {