resolve merge conflicts of 241a272 to nyc-mr1-dev-plus-aosp

Change-Id: I03618ad2f106cb9cdda007154a90c5dc64f9ff58
diff --git a/.clang-format b/.clang-format
index 9b7478c..b8c6428 100644
--- a/.clang-format
+++ b/.clang-format
@@ -6,7 +6,6 @@
 CommentPragmas: NOLINT:.*
 DerivePointerAlignment: false
 IndentWidth: 2
-ContinuationIndentWidth: 2
 PointerAlignment: Left
 TabWidth: 2
 UseTab: Never
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..dbe5c97
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,2 @@
+subdirs = ["*"]
+
diff --git a/Android.mk b/Android.mk
index 9f0f0c3..888404c 100644
--- a/Android.mk
+++ b/Android.mk
@@ -1,20 +1,4 @@
-#
-# Copyright (C) 2008 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
 LOCAL_PATH := $(call my-dir)
 
-include $(call all-makefiles-under,$(LOCAL_PATH)) \
-	$(call all-makefiles-under,$(LOCAL_PATH)/libc)
+include $(call all-makefiles-under,$(LOCAL_PATH))
+
diff --git a/README.md b/README.md
index c6b9278..0bf6c6d 100644
--- a/README.md
+++ b/README.md
@@ -153,10 +153,13 @@
      the appropriate POSIX header file in libc/include/ includes the
      relevant file or files.
   4. Add function declarations to the appropriate header file.
-  5. Add at least basic tests. Even a test that deliberately supplies
+  5. Add the function name to the correct section in libc/libc.map.txt and
+     run `./libc/tools/genversion-scripts.py`.
+  6. Add at least basic tests. Even a test that deliberately supplies
      an invalid argument helps check that we're generating the right symbol
-     and have the right declaration in the header file. (And strace(1) can
-     confirm that the correct system call is being made.)
+     and have the right declaration in the header file, and that you correctly
+     updated the maps in step 5. (You can use strace(1) to confirm that the
+     correct system call is being made.)
 
 
 Updating kernel header files
@@ -208,23 +211,27 @@
     $ adb shell \
         /data/nativetest64/bionic-unit-tests-static/bionic-unit-tests-static64
 
+Note that we use our own custom gtest runner that offers a superset of the
+options documented at
+<https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md#running-test-programs-advanced-options>,
+in particular for test isolation and parallelism (both on by default).
+
 ### Host tests
 
 The host tests require that you have `lunch`ed either an x86 or x86_64 target.
 
-    $ mma
-    $ mm bionic-unit-tests-run-on-host32
-    $ mm bionic-unit-tests-run-on-host64  # For 64-bit *targets* only.
+    $ ./tests/run-on-host.sh 32
+    $ ./tests/run-on-host.sh 64   # For x86_64-bit *targets* only.
+
+You can supply gtest flags as extra arguments to this script.
 
 ### Against glibc
 
 As a way to check that our tests do in fact test the correct behavior (and not
 just the behavior we think is correct), it is possible to run the tests against
-the host's glibc. The executables are already in your path.
+the host's glibc.
 
-    $ mma
-    $ bionic-unit-tests-glibc32
-    $ bionic-unit-tests-glibc64
+    $ ./tests/run-on-host.sh glibc
 
 
 Gathering test coverage
diff --git a/benchmarks/Android.bp b/benchmarks/Android.bp
new file mode 100644
index 0000000..12f4940
--- /dev/null
+++ b/benchmarks/Android.bp
@@ -0,0 +1,64 @@
+//
+// Copyright (C) 2013 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.
+//
+
+cc_defaults {
+    name: "bionic-benchmarks-defaults",
+    cflags: [
+        "-O2",
+        "-fno-builtin",
+        "-Wall",
+        "-Wextra",
+        "-Werror",
+        "-Wunused",
+    ],
+    srcs: [
+        "math_benchmark.cpp",
+        "property_benchmark.cpp",
+        "pthread_benchmark.cpp",
+        "semaphore_benchmark.cpp",
+        "stdio_benchmark.cpp",
+        "string_benchmark.cpp",
+        "time_benchmark.cpp",
+        "unistd_benchmark.cpp",
+    ],
+}
+
+// Build benchmarks for the device (with bionic's .so). Run with:
+//   adb shell bionic-benchmarks32
+//   adb shell bionic-benchmarks64
+cc_benchmark {
+    name: "bionic-benchmarks",
+    defaults: ["bionic-benchmarks-defaults"],
+}
+
+// We don't build a static benchmark executable because it's not usually
+// useful. If you're trying to run the current benchmarks on an older
+// release, it's (so far at least) always because you want to measure the
+// performance of the old release's libc, and a static benchmark isn't
+// going to let you do that.
+
+// Build benchmarks for the host (against glibc!). Run with:
+cc_benchmark_host {
+    name: "bionic-benchmarks-glibc",
+    defaults: ["bionic-benchmarks-defaults"],
+    host_ldlibs: ["-lrt"],
+    target: {
+        darwin: {
+            // Only supported on linux systems.
+            enabled: false,
+        },
+    },
+}
diff --git a/benchmarks/Android.mk b/benchmarks/Android.mk
deleted file mode 100644
index 6f2651e..0000000
--- a/benchmarks/Android.mk
+++ /dev/null
@@ -1,94 +0,0 @@
-#
-# Copyright (C) 2013 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-LOCAL_PATH := $(call my-dir)
-
-benchmark_cflags := \
-    -O2 \
-    -fno-builtin \
-    -Wall \
-    -Wextra \
-    -Werror \
-    -Wunused \
-
-benchmark_cppflags := \
-
-benchmark_src_files := \
-    math_benchmark.cpp \
-    property_benchmark.cpp \
-    pthread_benchmark.cpp \
-    semaphore_benchmark.cpp \
-    stdio_benchmark.cpp \
-    string_benchmark.cpp \
-    time_benchmark.cpp \
-    unistd_benchmark.cpp \
-
-# Build benchmarks for the device (with bionic's .so). Run with:
-#   adb shell bionic-benchmarks32
-#   adb shell bionic-benchmarks64
-include $(CLEAR_VARS)
-LOCAL_MODULE := bionic-benchmarks
-LOCAL_MODULE_STEM_32 := bionic-benchmarks32
-LOCAL_MODULE_STEM_64 := bionic-benchmarks64
-LOCAL_MULTILIB := both
-LOCAL_CFLAGS := $(benchmark_cflags)
-LOCAL_CPPFLAGS := $(benchmark_cppflags)
-LOCAL_SRC_FILES := $(benchmark_src_files)
-include $(BUILD_NATIVE_BENCHMARK)
-
-# We don't build a static benchmark executable because it's not usually
-# useful. If you're trying to run the current benchmarks on an older
-# release, it's (so far at least) always because you want to measure the
-# performance of the old release's libc, and a static benchmark isn't
-# going to let you do that.
-
-# Only supported on linux systems.
-ifeq ($(HOST_OS),linux)
-
-# Build benchmarks for the host (against glibc!). Run with:
-include $(CLEAR_VARS)
-LOCAL_MODULE := bionic-benchmarks-glibc
-LOCAL_MODULE_STEM_32 := bionic-benchmarks-glibc32
-LOCAL_MODULE_STEM_64 := bionic-benchmarks-glibc64
-LOCAL_MULTILIB := both
-LOCAL_CFLAGS := $(benchmark_cflags)
-LOCAL_CPPFLAGS := $(benchmark_cppflags)
-LOCAL_LDFLAGS := -lrt
-LOCAL_SRC_FILES := $(benchmark_src_files)
-LOCAL_STATIC_LIBRARIES := libgoogle-benchmark
-# TODO: BUILD_HOST_NATIVE_BENCHMARK
-include $(BUILD_HOST_EXECUTABLE)
-
-endif
-
-ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
-include $(LOCAL_PATH)/../build/run-on-host.mk
-
-ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
-bionic-benchmarks-run-on-host32: bionic-benchmarks bionic-prepare-run-on-host
-	ANDROID_DATA=$(TARGET_OUT_DATA) \
-	ANDROID_ROOT=$(TARGET_OUT) \
-		$(TARGET_OUT_EXECUTABLES)/bionic-benchmarks32 $(BIONIC_BENCHMARKS_FLAGS)
-endif
-
-ifeq ($(TARGET_IS_64_BIT),true)
-bionic-benchmarks-run-on-host64: bionic-benchmarks bionic-prepare-run-on-host
-	ANDROID_DATA=$(TARGET_OUT_DATA) \
-	ANDROID_ROOT=$(TARGET_OUT) \
-		$(TARGET_OUT_EXECUTABLES)/bionic-benchmarks64 $(BIONIC_BENCHMARKS_FLAGS)
-endif
-
-endif
diff --git a/benchmarks/property_benchmark.cpp b/benchmarks/property_benchmark.cpp
index 2f72d60..4e82117 100644
--- a/benchmarks/property_benchmark.cpp
+++ b/benchmarks/property_benchmark.cpp
@@ -36,7 +36,7 @@
     Arg(1)->Arg(4)->Arg(16)->Arg(64)->Arg(128)->Arg(256)->Arg(512)
 
 struct LocalPropertyTestState {
-  LocalPropertyTestState(int nprops) : nprops(nprops), valid(false) {
+  explicit LocalPropertyTestState(int nprops) : nprops(nprops), valid(false) {
     static const char prop_name_chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_.";
 
     const char* android_data = getenv("ANDROID_DATA");
diff --git a/benchmarks/run-on-host.sh b/benchmarks/run-on-host.sh
new file mode 100755
index 0000000..bc63628
--- /dev/null
+++ b/benchmarks/run-on-host.sh
@@ -0,0 +1,33 @@
+#!/bin/bash -e
+
+. $(dirname $0)/../build/run-on-host.sh
+
+if [ "$1" = glibc ]; then
+    m -j bionic-benchmarks-glibc
+    (
+        cd ${ANDROID_BUILD_TOP}
+        export ANDROID_DATA=${TARGET_OUT_DATA}
+        export ANDROID_ROOT=${TARGET_OUT}
+        ${HOST_OUT}/nativetest64/bionic-benchmarks-glibc/bionic-benchmarks-glibc $@
+    )
+    exit 0
+elif [ "$1" != 32 -a "$1" != 64 ]; then
+    echo "Usage: $0 [ 32 | 64 | glibc ] [gtest flags]"
+    exit 1
+fi
+
+if [ ${HOST_OS}-${HOST_ARCH} = linux-x86 -o ${HOST_OS}-${HOST_ARCH} = linux-x86_64 ]; then
+
+    prepare $1 bionic-benchmarks
+
+    if [ ${TARGET_ARCH} = x86 -o ${TARGET_ARCH} = x86_64 ]; then
+        (
+            cd ${ANDROID_BUILD_TOP}
+            export ANDROID_DATA=${TARGET_OUT_DATA}
+            export ANDROID_ROOT=${TARGET_OUT}
+            ${NATIVETEST}/bionic-benchmarks/bionic-benchmarks $@
+        )
+    else
+        echo "$0 not supported on TARGET_ARCH=$TARGET_ARCH"
+    fi
+fi
diff --git a/benchmarks/semaphore_benchmark.cpp b/benchmarks/semaphore_benchmark.cpp
index d260803..b932a2b3 100644
--- a/benchmarks/semaphore_benchmark.cpp
+++ b/benchmarks/semaphore_benchmark.cpp
@@ -96,22 +96,27 @@
     sched_setscheduler(0, SCHED_IDLE, &param);
 
     BM_semaphore_sem_post_running = 1;
+    setup = true;
   }
 
   ~SemaphoreFixture() {
-    sched_setscheduler(0, SCHED_OTHER, &param);
+    if (setup) {
+      // Only do this if the test was actually run.
+      sched_setscheduler(0, SCHED_OTHER, &param);
 
-    if (BM_semaphore_sem_post_running > 0) {
-      BM_semaphore_sem_post_running = 0;
+      if (BM_semaphore_sem_post_running > 0) {
+        BM_semaphore_sem_post_running = 0;
+      }
+      do {
+        sem_post(&semaphore);
+        sched_yield();
+      } while (BM_semaphore_sem_post_running != -1);
     }
-    do {
-      sem_post(&semaphore);
-      sched_yield();
-    } while (BM_semaphore_sem_post_running != -1);
   }
 
   sem_t semaphore;
   sched_param param;
+  bool setup = false;
 };
 
 BENCHMARK_F(SemaphoreFixture, semaphore_sem_post)(benchmark::State& state) {
diff --git a/benchmarks/stdio_benchmark.cpp b/benchmarks/stdio_benchmark.cpp
index cc07128..a556d17 100644
--- a/benchmarks/stdio_benchmark.cpp
+++ b/benchmarks/stdio_benchmark.cpp
@@ -20,8 +20,7 @@
 
 #include <benchmark/benchmark.h>
 
-#define KB 1024
-#define MB 1024*KB
+constexpr auto KB = 1024;
 
 #define AT_COMMON_SIZES \
     Arg(1)->Arg(2)->Arg(3)->Arg(4)->Arg(8)->Arg(16)->Arg(32)->Arg(64)->Arg(512)-> \
diff --git a/benchmarks/string_benchmark.cpp b/benchmarks/string_benchmark.cpp
index c04409d..0a38512 100644
--- a/benchmarks/string_benchmark.cpp
+++ b/benchmarks/string_benchmark.cpp
@@ -19,8 +19,7 @@
 
 #include <benchmark/benchmark.h>
 
-#define KB 1024
-#define MB 1024*KB
+constexpr auto KB = 1024;
 
 #define AT_COMMON_SIZES \
     Arg(8)->Arg(64)->Arg(512)->Arg(1*KB)->Arg(8*KB)->Arg(16*KB)->Arg(32*KB)->Arg(64*KB)
diff --git a/build/run-on-host.mk b/build/run-on-host.mk
deleted file mode 100644
index dc7e5d5..0000000
--- a/build/run-on-host.mk
+++ /dev/null
@@ -1,44 +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 once
-ifneq ($(bionic_run_on_host_mk_included),true)
-bionic_run_on_host_mk_included:=true
-
-ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm mips x86))
-LINKER = linker64
-else
-LINKER = linker
-endif
-
-ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
-# gtest needs ANDROID_DATA/local/tmp for death test output.
-# Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
-# bionic itself should always work relative to ANDROID_DATA or ANDROID_ROOT.
-bionic-prepare-run-on-host: $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT)/etc/hosts $(TARGET_OUT_EXECUTABLES)/sh
-	if [ ! -d /system ]; then \
-	  echo "Attempting to create /system"; \
-	  sudo mkdir -p -m 0777 /system; \
-	fi
-	mkdir -p $(TARGET_OUT_DATA)/local/tmp
-	ln -fs `realpath $(TARGET_OUT)/bin` /system/
-	ln -fs `realpath $(TARGET_OUT)/etc` /system/
-	ln -fs `realpath $(TARGET_OUT)/lib` /system/
-	if [ -d "$(TARGET_OUT)/lib64" ]; then \
-	  ln -fs `realpath $(TARGET_OUT)/lib64` /system/; \
-	fi
-endif
-endif
diff --git a/build/run-on-host.sh b/build/run-on-host.sh
new file mode 100644
index 0000000..c3a2751
--- /dev/null
+++ b/build/run-on-host.sh
@@ -0,0 +1,47 @@
+#!/bin/bash -e
+
+source ${ANDROID_BUILD_TOP}/build/envsetup.sh
+
+TARGET_ARCH=$(get_build_var TARGET_ARCH)
+TARGET_OUT=$(get_build_var TARGET_OUT)
+TARGET_OUT_EXECUTABLES=$(get_build_var TARGET_OUT_EXECUTABLES)
+TARGET_OUT_DATA=$(get_build_var TARGET_OUT_DATA)
+HOST_OS=$(get_build_var HOST_OS)
+HOST_ARCH=$(get_build_var HOST_ARCH)
+HOST_OUT=$(get_build_var HOST_OUT)
+
+function prepare()
+{
+    BITS=$1
+    shift
+
+    NATIVETEST=${TARGET_OUT_DATA}/nativetest
+    if [ "${BITS}" = 64 ]; then
+        NATIVETEST=${NATIVETEST}64
+    fi
+
+    if [ ${TARGET_ARCH} = arm -o ${TARGET_ARCH} = mips -o ${TARGET_ARCH} = x86 ]; then
+        LINKER=${TARGET_OUT_EXECUTABLES}/linker
+    else
+        LINKER="${TARGET_OUT_EXECUTABLES}/linker64 ${TARGET_OUT_EXECUTABLES}/linker"
+    fi
+
+    if [ ${TARGET_ARCH} = x86 -o ${TARGET_ARCH} = x86_64 ]; then
+        m -j ${LINKER} ${TARGET_OUT}/etc/hosts ${TARGET_OUT_EXECUTABLES}/sh $@
+
+        if [ ! -d /system ]; then
+            echo "Attempting to create /system";
+            sudo mkdir -p -m 0777 /system;
+        fi
+        (
+            cd ${ANDROID_BUILD_TOP}
+            mkdir -p ${TARGET_OUT_DATA}/local/tmp
+            ln -fs `realpath ${TARGET_OUT}/bin` /system/
+            ln -fs `realpath ${TARGET_OUT}/etc` /system/
+            ln -fs `realpath ${TARGET_OUT}/lib` /system/
+            if [ -d "${TARGET_OUT}/lib64" ]; then
+                ln -fs `realpath ${TARGET_OUT}/lib64` /system/;
+            fi
+        )
+    fi
+}
diff --git a/libc/Android.bp b/libc/Android.bp
index 4cae16c..2ea6789 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -17,44 +17,10 @@
     "bionic/system_properties_compat.c",
     "stdio/fread.c",
     "stdio/refill.c",
-    "stdio/snprintf.c",
-    "stdio/sprintf.c",
     "stdio/stdio.cpp",
     "stdio/stdio_ext.cpp",
     "stdlib/atexit.c",
     "stdlib/exit.c",
-
-    // Fortify implementations of libc functions.
-    "bionic/__FD_chk.cpp",
-    "bionic/__fgets_chk.cpp",
-    "bionic/__fread_chk.cpp",
-    "bionic/__fwrite_chk.cpp",
-    "bionic/__getcwd_chk.cpp",
-    "bionic/__memchr_chk.cpp",
-    "bionic/__memmove_chk.cpp",
-    "bionic/__memrchr_chk.cpp",
-    "bionic/__poll_chk.cpp",
-    "bionic/__pread64_chk.cpp",
-    "bionic/__pread_chk.cpp",
-    "bionic/__pwrite64_chk.cpp",
-    "bionic/__pwrite_chk.cpp",
-    "bionic/__read_chk.cpp",
-    "bionic/__readlink_chk.cpp",
-    "bionic/__readlinkat_chk.cpp",
-    "bionic/__recvfrom_chk.cpp",
-    "bionic/__stpcpy_chk.cpp",
-    "bionic/__stpncpy_chk.cpp",
-    "bionic/__strchr_chk.cpp",
-    "bionic/__strlcat_chk.cpp",
-    "bionic/__strlcpy_chk.cpp",
-    "bionic/__strlen_chk.cpp",
-    "bionic/__strncat_chk.cpp",
-    "bionic/__strncpy_chk.cpp",
-    "bionic/__strrchr_chk.cpp",
-    "bionic/__umask_chk.cpp",
-    "bionic/__vsnprintf_chk.cpp",
-    "bionic/__vsprintf_chk.cpp",
-    "bionic/__write_chk.cpp",
 ]
 
 // Various kinds of cruft.
@@ -68,58 +34,37 @@
     "bionic/time64.c",
 ]
 
+libc_common_flags = [
+    "-D_LIBC=1",
+    "-Wall",
+    "-Wextra",
+    "-Wunused",
+    "-Wno-deprecated-declarations",
+
+    // Try to catch typical 32-bit assumptions that break with 64-bit pointers.
+    "-Werror=pointer-to-int-cast",
+    "-Werror=int-to-pointer-cast",
+    "-Werror=type-limits",
+    "-Werror",
+]
+
 // Define some common cflags
 // ========================================================
 cc_defaults {
     name: "libc_defaults",
-    cflags: [
-        "-D_LIBC=1",
-        "-Wall",
-        "-Wextra",
-        "-Wunused",
-
-        // Try to catch typical 32-bit assumptions that break with 64-bit pointers.
-        "-Werror=pointer-to-int-cast",
-        "-Werror=int-to-pointer-cast",
-        "-Werror=type-limits",
-        "-Werror",
-    ],
-    // TODO: split out the asflags.
-    asflags: [
-        "-D_LIBC=1",
-        "-Wall",
-        "-Wextra",
-        "-Wunused",
-
-        // Try to catch typical 32-bit assumptions that break with 64-bit pointers.
-        "-Werror=pointer-to-int-cast",
-        "-Werror=int-to-pointer-cast",
-        "-Werror=type-limits",
-        "-Werror",
-    ],
+    cflags: libc_common_flags,
+    asflags: libc_common_flags,
     conlyflags: ["-std=gnu99"],
     cppflags: [],
     include_dirs: ["external/jemalloc/include"],
 
-    arch: {
-        // Clang/llvm has incompatible long double (fp128) for x86_64.
-        // https://llvm.org/bugs/show_bug.cgi?id=23897
-        x86_64: {
-            clang: false,
-        },
-        // b/25291096, Clang/llvm compiled libc.so for mips/mips64 failed to boot.
-        mips: {
-            clang: false,
-        },
-        mips64: {
-            clang: false,
-        },
-    },
-
     stl: "none",
     system_shared_libs: [],
-    sanitize: ["never"],
+    sanitize: {
+        never: true,
+    },
     native_coverage: false,
+    clang: true,
 }
 
 // ANDROIDMK TRANSLATION ERROR: unsupported directive
@@ -148,7 +93,7 @@
             srcs: ["arch-arm64/bionic/__set_tls.c"],
         },
         x86: {
-            srcs: ["arch-x86/bionic/__set_tls.c"],
+            srcs: ["arch-x86/bionic/__set_tls.cpp"],
         },
         x86_64: {
             srcs: ["arch-x86_64/bionic/__set_tls.c"],
@@ -186,7 +131,6 @@
     ],
 
     cflags: [
-        "-fvisibility=hidden",
         "-Wno-unused-parameter",
         // Don't use ridiculous amounts of stack.
         "-DALL_STATE",
@@ -198,7 +142,8 @@
         "-DTM_GMTOFF=tm_gmtoff",
         // Where we store our tzdata.
         "-DTZDIR=\\\"/system/usr/share/zoneinfo\\\"",
-        // Include timezone and daylight globals.
+        // Include `tzname`, `timezone`, and `daylight` globals.
+        "-DHAVE_POSIX_DECLS=0",
         "-DUSG_COMPAT=1",
         // Use the empty string (instead of "   ") as the timezone abbreviation
         // fallback.
@@ -229,7 +174,6 @@
     cflags: [
         "-DANDROID_CHANGES",
         "-DINET6",
-        "-fvisibility=hidden",
         "-Wno-unused-parameter",
         "-include netbsd-compat.h",
     ],
@@ -343,8 +287,6 @@
     defaults: ["libc_defaults"],
     srcs: [
         "upstream-netbsd/common/lib/libc/stdlib/random.c",
-        "upstream-netbsd/lib/libc/gen/ftw.c",
-        "upstream-netbsd/lib/libc/gen/nftw.c",
         "upstream-netbsd/lib/libc/gen/nice.c",
         "upstream-netbsd/lib/libc/gen/popen.c",
         "upstream-netbsd/lib/libc/gen/psignal.c",
@@ -450,6 +392,7 @@
         "upstream-openbsd/lib/libc/locale/wcsxfrm.c",
         "upstream-openbsd/lib/libc/locale/wctob.c",
         "upstream-openbsd/lib/libc/locale/wctomb.c",
+        "upstream-openbsd/lib/libc/net/base64.c",
         "upstream-openbsd/lib/libc/net/htonl.c",
         "upstream-openbsd/lib/libc/net/htons.c",
         "upstream-openbsd/lib/libc/net/inet_lnaof.c",
@@ -461,60 +404,31 @@
         "upstream-openbsd/lib/libc/net/ntohl.c",
         "upstream-openbsd/lib/libc/net/ntohs.c",
         "upstream-openbsd/lib/libc/net/res_random.c",
-        "upstream-openbsd/lib/libc/stdio/asprintf.c",
-        "upstream-openbsd/lib/libc/stdio/clrerr.c",
-        "upstream-openbsd/lib/libc/stdio/dprintf.c",
-        "upstream-openbsd/lib/libc/stdio/feof.c",
-        "upstream-openbsd/lib/libc/stdio/ferror.c",
         "upstream-openbsd/lib/libc/stdio/fflush.c",
-        "upstream-openbsd/lib/libc/stdio/fgetc.c",
         "upstream-openbsd/lib/libc/stdio/fgetln.c",
         "upstream-openbsd/lib/libc/stdio/fgets.c",
         "upstream-openbsd/lib/libc/stdio/fgetwc.c",
         "upstream-openbsd/lib/libc/stdio/fgetws.c",
         "upstream-openbsd/lib/libc/stdio/flags.c",
         "upstream-openbsd/lib/libc/stdio/fmemopen.c",
-        "upstream-openbsd/lib/libc/stdio/fprintf.c",
         "upstream-openbsd/lib/libc/stdio/fpurge.c",
-        "upstream-openbsd/lib/libc/stdio/fputc.c",
         "upstream-openbsd/lib/libc/stdio/fputs.c",
         "upstream-openbsd/lib/libc/stdio/fputwc.c",
         "upstream-openbsd/lib/libc/stdio/fputws.c",
-        "upstream-openbsd/lib/libc/stdio/fscanf.c",
         "upstream-openbsd/lib/libc/stdio/fvwrite.c",
         "upstream-openbsd/lib/libc/stdio/fwalk.c",
         "upstream-openbsd/lib/libc/stdio/fwide.c",
-        "upstream-openbsd/lib/libc/stdio/fwprintf.c",
         "upstream-openbsd/lib/libc/stdio/fwrite.c",
-        "upstream-openbsd/lib/libc/stdio/fwscanf.c",
-        "upstream-openbsd/lib/libc/stdio/getc.c",
-        "upstream-openbsd/lib/libc/stdio/getchar.c",
         "upstream-openbsd/lib/libc/stdio/getdelim.c",
-        "upstream-openbsd/lib/libc/stdio/getline.c",
         "upstream-openbsd/lib/libc/stdio/gets.c",
-        "upstream-openbsd/lib/libc/stdio/getwc.c",
-        "upstream-openbsd/lib/libc/stdio/getwchar.c",
         "upstream-openbsd/lib/libc/stdio/makebuf.c",
         "upstream-openbsd/lib/libc/stdio/mktemp.c",
         "upstream-openbsd/lib/libc/stdio/open_memstream.c",
         "upstream-openbsd/lib/libc/stdio/open_wmemstream.c",
         "upstream-openbsd/lib/libc/stdio/perror.c",
-        "upstream-openbsd/lib/libc/stdio/printf.c",
-        "upstream-openbsd/lib/libc/stdio/putc.c",
-        "upstream-openbsd/lib/libc/stdio/putchar.c",
         "upstream-openbsd/lib/libc/stdio/puts.c",
-        "upstream-openbsd/lib/libc/stdio/putwc.c",
-        "upstream-openbsd/lib/libc/stdio/putwchar.c",
-        "upstream-openbsd/lib/libc/stdio/remove.c",
-        "upstream-openbsd/lib/libc/stdio/rewind.c",
         "upstream-openbsd/lib/libc/stdio/rget.c",
-        "upstream-openbsd/lib/libc/stdio/scanf.c",
-        "upstream-openbsd/lib/libc/stdio/setbuf.c",
-        "upstream-openbsd/lib/libc/stdio/setbuffer.c",
         "upstream-openbsd/lib/libc/stdio/setvbuf.c",
-        "upstream-openbsd/lib/libc/stdio/sscanf.c",
-        "upstream-openbsd/lib/libc/stdio/swprintf.c",
-        "upstream-openbsd/lib/libc/stdio/swscanf.c",
         "upstream-openbsd/lib/libc/stdio/tempnam.c",
         "upstream-openbsd/lib/libc/stdio/tmpnam.c",
         "upstream-openbsd/lib/libc/stdio/ungetc.c",
@@ -525,24 +439,18 @@
         "upstream-openbsd/lib/libc/stdio/vfscanf.c",
         "upstream-openbsd/lib/libc/stdio/vfwprintf.c",
         "upstream-openbsd/lib/libc/stdio/vfwscanf.c",
-        "upstream-openbsd/lib/libc/stdio/vprintf.c",
-        "upstream-openbsd/lib/libc/stdio/vscanf.c",
         "upstream-openbsd/lib/libc/stdio/vsnprintf.c",
-        "upstream-openbsd/lib/libc/stdio/vsprintf.c",
         "upstream-openbsd/lib/libc/stdio/vsscanf.c",
         "upstream-openbsd/lib/libc/stdio/vswprintf.c",
         "upstream-openbsd/lib/libc/stdio/vswscanf.c",
-        "upstream-openbsd/lib/libc/stdio/vwprintf.c",
-        "upstream-openbsd/lib/libc/stdio/vwscanf.c",
         "upstream-openbsd/lib/libc/stdio/wbuf.c",
-        "upstream-openbsd/lib/libc/stdio/wprintf.c",
-        "upstream-openbsd/lib/libc/stdio/wscanf.c",
         "upstream-openbsd/lib/libc/stdio/wsetup.c",
         "upstream-openbsd/lib/libc/stdlib/abs.c",
         "upstream-openbsd/lib/libc/stdlib/atoi.c",
         "upstream-openbsd/lib/libc/stdlib/atol.c",
         "upstream-openbsd/lib/libc/stdlib/atoll.c",
         "upstream-openbsd/lib/libc/stdlib/getenv.c",
+        "upstream-openbsd/lib/libc/stdlib/getsubopt.c",
         "upstream-openbsd/lib/libc/stdlib/insque.c",
         "upstream-openbsd/lib/libc/stdlib/imaxabs.c",
         "upstream-openbsd/lib/libc/stdlib/imaxdiv.c",
@@ -619,12 +527,6 @@
         "upstream-openbsd/lib/libc/string/strncmp.c",
         "upstream-openbsd/lib/libc/string/strncpy.c",
     ],
-    multilib: {
-        lib32: {
-            // LP32 cruft
-            srcs: ["upstream-openbsd/lib/libc/stdio/putw.c"],
-        },
-    },
 
     arch: {
         arm: {
@@ -791,7 +693,6 @@
     cflags: [
         "-Wno-sign-compare",
         "-Wno-uninitialized",
-        "-fvisibility=hidden",
         "-include openbsd-compat.h",
     ],
 
@@ -830,7 +731,6 @@
         "bionic/setjmp_cookie.cpp",
 
         "bionic/__memcpy_chk.cpp",
-        "bionic/__memset_chk.cpp",
         "bionic/__strcat_chk.cpp",
         "bionic/__strcpy_chk.cpp",
         "bionic/strchr.cpp",
@@ -862,7 +762,6 @@
             ],
             exclude_srcs: [
                 "bionic/__memcpy_chk.cpp",
-                "bionic/__memset_chk.cpp",
             ],
             cortex_a7: {
                 srcs: [
@@ -1109,22 +1008,23 @@
                 "arch-mips/string/memcpy.S",
                 "arch-mips/string/memset.S",
                 "arch-mips/string/strcmp.S",
-                "arch-mips/string/strlen.c",
 
                 "arch-mips/bionic/__bionic_clone.S",
-                "arch-mips/bionic/bzero.S",
                 "arch-mips/bionic/cacheflush.cpp",
                 "arch-mips/bionic/_exit_with_stack_teardown.S",
+                "arch-mips/bionic/libgcc_compat.c",
                 "arch-mips/bionic/setjmp.S",
                 "arch-mips/bionic/syscall.S",
                 "arch-mips/bionic/vfork.S",
+
+                "arch-mips/string/mips_strlen.c",
             ],
             rev6: {
                 srcs: [
-                    "arch-mips/string/mips_strlen.c",
+                    "arch-mips/string/strlen.c",
                 ],
                 exclude_srcs: [
-                    "arch-mips/string/strlen.c",
+                    "arch-mips/string/mips_strlen.c",
                 ],
             },
         },
@@ -1160,8 +1060,6 @@
                 "arch-x86/atom/string/sse2-wcsrchr-atom.S",
                 "arch-x86/atom/string/sse2-wcslen-atom.S",
                 "arch-x86/atom/string/sse2-wcscmp-atom.S",
-                "arch-x86/silvermont/string/sse2-bcopy-slm.S",
-                "arch-x86/silvermont/string/sse2-bzero-slm.S",
                 "arch-x86/silvermont/string/sse2-memcpy-slm.S",
                 "arch-x86/silvermont/string/sse2-memmove-slm.S",
                 "arch-x86/silvermont/string/sse2-memset-slm.S",
@@ -1187,10 +1085,8 @@
             ],
             atom: {
                 srcs: [
-                    "arch-x86/atom/string/sse2-bzero-atom.S",
                     "arch-x86/atom/string/sse2-memset-atom.S",
                     "arch-x86/atom/string/sse2-strlen-atom.S",
-                    "arch-x86/atom/string/ssse3-bcopy-atom.S",
                     "arch-x86/atom/string/ssse3-memcmp-atom.S",
                     "arch-x86/atom/string/ssse3-memcpy-atom.S",
                     "arch-x86/atom/string/ssse3-memmove-atom.S",
@@ -1200,8 +1096,6 @@
                 ],
                 exclude_srcs: [
                     "arch-x86/generic/string/memcmp.S",
-                    "arch-x86/silvermont/string/sse2-bcopy-slm.S",
-                    "arch-x86/silvermont/string/sse2-bzero-slm.S",
                     "arch-x86/silvermont/string/sse2-memcpy-slm.S",
                     "arch-x86/silvermont/string/sse2-memmove-slm.S",
                     "arch-x86/silvermont/string/sse2-memset-slm.S",
@@ -1318,16 +1212,21 @@
         "bionic/fgetxattr.cpp",
         "bionic/flistxattr.cpp",
         "bionic/flockfile.cpp",
+        "bionic/fortify.cpp",
         "bionic/fpclassify.cpp",
         "bionic/fsetxattr.cpp",
         "bionic/ftruncate.cpp",
+        "bionic/ftw.cpp",
         "bionic/futimens.cpp",
         "bionic/getcwd.cpp",
+        "bionic/getdomainname.cpp",
         "bionic/gethostname.cpp",
+        "bionic/getpagesize.cpp",
         "bionic/getpgrp.cpp",
         "bionic/getpid.cpp",
         "bionic/gettid.cpp",
         "bionic/__gnu_basename.cpp",
+        "bionic/grp_pwd.cpp",
         "bionic/ifaddrs.cpp",
         "bionic/inotify_init.cpp",
         "bionic/ioctl.cpp",
@@ -1343,6 +1242,7 @@
         "bionic/lockf.cpp",
         "bionic/lstat.cpp",
         "bionic/malloc_info.cpp",
+        "bionic/mblen.cpp",
         "bionic/mbrtoc16.cpp",
         "bionic/mbrtoc32.cpp",
         "bionic/mbstate.cpp",
@@ -1352,9 +1252,11 @@
         "bionic/mknod.cpp",
         "bionic/mntent.cpp",
         "bionic/mremap.cpp",
+        "bionic/netdb.cpp",
         "bionic/NetdClientDispatch.cpp",
         "bionic/net_if.cpp",
         "bionic/netinet_in.cpp",
+        "bionic/nl_types.cpp",
         "bionic/open.cpp",
         "bionic/pathconf.cpp",
         "bionic/pause.cpp",
@@ -1387,12 +1289,17 @@
         "bionic/sigdelset.cpp",
         "bionic/sigemptyset.cpp",
         "bionic/sigfillset.cpp",
+        "bionic/sighold.cpp",
+        "bionic/sigignore.cpp",
         "bionic/sigismember.cpp",
         "bionic/signal.cpp",
         "bionic/signalfd.cpp",
+        "bionic/sigpause.cpp",
         "bionic/sigpending.cpp",
         "bionic/sigprocmask.cpp",
         "bionic/sigqueue.cpp",
+        "bionic/sigrelse.cpp",
+        "bionic/sigset.cpp",
         "bionic/sigsuspend.cpp",
         "bionic/sigtimedwait.cpp",
         "bionic/sigwait.cpp",
@@ -1405,12 +1312,13 @@
         "bionic/strerror_r.cpp",
         "bionic/strsignal.cpp",
         "bionic/strtold.cpp",
-        "bionic/stubs.cpp",
         "bionic/symlink.cpp",
+        "bionic/sync_file_range.cpp",
         "bionic/sysinfo.cpp",
         "bionic/syslog.cpp",
         "bionic/sys_siglist.c",
         "bionic/sys_signame.c",
+        "bionic/sys_time.cpp",
         "bionic/system_properties.cpp",
         "bionic/tdestroy.cpp",
         "bionic/termios.cpp",
@@ -1418,7 +1326,6 @@
         "bionic/tmpfile.cpp",
         "bionic/umount.cpp",
         "bionic/unlink.cpp",
-        "bionic/utimes.cpp",
         "bionic/wait.cpp",
         "bionic/wchar.cpp",
         "bionic/wctype.cpp",
@@ -1482,36 +1389,11 @@
 }
 
 // ========================================================
-// libc_cxa.a - Things traditionally in libstdc++
-// ========================================================
-
-cc_library_static {
-    defaults: ["libc_defaults"],
-    srcs: [
-        "bionic/__cxa_guard.cpp",
-        "bionic/__cxa_pure_virtual.cpp",
-        "bionic/new.cpp",
-    ],
-    cflags: ["-fvisibility=hidden"],
-    include_dirs: ["bionic/libstdc++/include"],
-    name: "libc_cxa",
-    clang: true, // GCC refuses to hide new/delete
-
-    // b/17574078: Need to disable coverage until we have a prebuilt libprofile_rt.
-    // Since this is a static library built with clang, it needs to link
-    // libprofile_rt when it is linked into the final binary. Since the final binary
-    // is built with GCC, it won't link libprofile_rt. We can't very easily just add
-    // libprofile_rt to all link lines the way we've done for libgcov because
-    // libprofile_rt isn't prebuilt, and it would be tricky to write a rule that
-    // would make sure libprofile_rt is built.
-    native_coverage: false,
-}
-
-// ========================================================
 // libc_syscalls.a
 // ========================================================
 
 cc_library_static {
+    defaults: ["libc_defaults"],
     arch: {
         arm: {
             srcs: ["arch-arm/syscalls/**/*.S"],
@@ -1593,7 +1475,6 @@
 
     whole_static_libs: [
         "libc_bionic_ndk",
-        "libc_cxa",
         "libc_freebsd",
         "libc_gdtoa",
         "libc_malloc",
@@ -1604,6 +1485,7 @@
         "libc_tzcode",
         "libm",
         "libjemalloc",
+        "libstdc++",
     ],
 }
 
@@ -1624,7 +1506,6 @@
     whole_static_libs: [
         "libc_bionic",
         "libc_bionic_ndk",
-        "libc_cxa",
         "libc_dns",
         "libc_freebsd",
         "libc_gdtoa",
@@ -1636,6 +1517,7 @@
         "libc_stack_protector",
         "libc_syscalls",
         "libc_tzcode",
+        "libstdc++",
     ],
 
     arch: {
@@ -1699,30 +1581,34 @@
             asflags: ["-DPLATFORM_SDK_VERSION=%d"],
         },
     },
-    srcs: ["bionic/malloc_common.cpp"],
     static: {
         srcs: [
             "bionic/dl_iterate_phdr_static.cpp",
+            "bionic/malloc_common.cpp",
             "bionic/libc_init_static.cpp",
         ],
         cflags: ["-DLIBC_STATIC"],
-        whole_static_libs: ["libc_init_static"],
+        whole_static_libs: ["libc_init_static", "libjemalloc"],
     },
     shared: {
         srcs: [
             "arch-common/bionic/crtbegin_so.c",
             "arch-common/bionic/crtbrand.S",
+            "bionic/malloc_common.cpp",
             "bionic/libc_init_dynamic.cpp",
             "bionic/NetdClient.cpp",
             "arch-common/bionic/crtend_so.S",
         ],
+        whole_static_libs: ["libjemalloc"],
     },
 
     required: ["tzdata"],
 
     // Leave the symbols in the shared library so that stack unwinders can produce
     // meaningful name resolution.
-    strip: "keep_symbols",
+    strip: {
+        keep_symbols: true,
+    },
 
     // WARNING: The only library libc.so should depend on is libdl.so!  If you add other libraries,
     // make sure to add -Wl,--exclude-libs=libgcc.a to the LOCAL_LDFLAGS for those libraries.  This
@@ -1733,16 +1619,7 @@
     // you wanted!
 
     shared_libs: ["libdl"],
-    whole_static_libs: ["libc_common", "libjemalloc"],
-
-    // We'd really like to do this for all architectures, but since this wasn't done
-    // before, these symbols must continue to be exported on LP32 for binary
-    // compatibility.
-    multilib: {
-        lib64: {
-            ldflags: ["-Wl,--exclude-libs,libgcc.a"],
-        },
-    },
+    whole_static_libs: ["libc_common"],
 
     nocrt: true,
 
@@ -1760,17 +1637,18 @@
             },
 
             shared: {
-                srcs: ["arch-arm/bionic/exidx_dynamic.c"],
+                srcs: [
+                    "arch-arm/bionic/exidx_dynamic.c",
+
+                    // special for arm
+                    "arch-arm/bionic/atexit_legacy.c",
+                ],
+                // special for arm
+                cflags: ["-DCRT_LEGACY_WORKAROUND"],
             },
             static: {
                 srcs: ["arch-arm/bionic/exidx_static.c"],
             },
-
-            // special for arm
-            cflags: ["-DCRT_LEGACY_WORKAROUND"],
-            srcs: [
-                "arch-arm/bionic/atexit_legacy.c",
-            ],
         },
         arm64: {
             // Don't re-export new/delete and friends, even if the compiler really wants to.
@@ -1838,13 +1716,27 @@
         static_libs: ["libc_logging"],
     },
 
-    //TODO: This is to work around b/24465209. Remove after root cause is fixed
+    //TODO (dimitry): This is to work around b/24465209. Remove after root cause is fixed
     arch: {
         arm: {
             ldflags: ["-Wl,--hash-style=both"],
+            version_script: "libstdc++.arm.map",
+        },
+        arm64: {
+            version_script: "libstdc++.arm64.map",
+        },
+        mips: {
+            version_script: "libstdc++.mips.map",
+        },
+        mips64: {
+            version_script: "libstdc++.mips64.map",
         },
         x86: {
             ldflags: ["-Wl,--hash-style=both"],
+            version_script: "libstdc++.x86.map",
+        },
+        x86_64: {
+            version_script: "libstdc++.x86_64.map",
         },
     },
 }
@@ -1952,7 +1844,7 @@
         "crt_defaults",
         "crt_so_defaults",
     ],
-    deps: [
+    objs: [
         "crtbegin_so1",
         "crtbrand",
     ],
@@ -2010,7 +1902,7 @@
 cc_object {
     name: "crtbegin_static",
 
-    deps: [
+    objs: [
         "crtbegin_static1",
         "crtbrand",
     ],
@@ -2056,7 +1948,7 @@
 cc_object {
     name: "crtbegin_dynamic",
 
-    deps: [
+    objs: [
         "crtbegin_dynamic1",
         "crtbrand",
     ],
@@ -2073,3 +1965,5 @@
 
     defaults: ["crt_defaults"],
 }
+
+subdirs = ["malloc_debug"]
diff --git a/libc/Android.mk b/libc/Android.mk
index 1ca84c1..888404c 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -1,1520 +1,4 @@
 LOCAL_PATH := $(call my-dir)
 
-bionic_coverage ?= false
-
-# Make everything depend on any changes to included makefiles.
-libc_common_additional_dependencies := $(LOCAL_PATH)/Android.mk
-
-# Load config for TARGET_ARCH
-my_2nd_arch_prefix :=
-include $(LOCAL_PATH)/arch-$(TARGET_ARCH)/$(TARGET_ARCH).mk
-libc_common_additional_dependencies += \
-    $(LOCAL_PATH)/arch-$(TARGET_ARCH)/$(TARGET_ARCH).mk
-
-
-ifdef TARGET_2ND_ARCH
-# Load config for TARGET_2ND_ARCH
-my_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX)
-include $(LOCAL_PATH)/arch-$(TARGET_2ND_ARCH)/$(TARGET_2ND_ARCH).mk
-my_2nd_arch_prefix :=
-libc_common_additional_dependencies += \
-    $(LOCAL_PATH)/arch-$(TARGET_2ND_ARCH)/$(TARGET_2ND_ARCH).mk
-endif
-
-# crt obj files
-# ========================================================
-# crtbrand.c needs <stdint.h> and a #define for the platform SDK version.
-libc_crt_target_cflags := \
-    -I$(LOCAL_PATH)/include \
-    -DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION) \
-
-my_2nd_arch_prefix :=
-include $(LOCAL_PATH)/crt.mk
-ifdef TARGET_2ND_ARCH
-my_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX)
-include $(LOCAL_PATH)/crt.mk
-my_2nd_arch_prefix :=
-endif
-
-# Define the common source files for all the libc instances
-# =========================================================
-libc_common_src_files := \
-    bionic/ether_aton.c \
-    bionic/ether_ntoa.c \
-    bionic/fts.c \
-    bionic/getpriority.c \
-    bionic/initgroups.c \
-    bionic/isatty.c \
-    bionic/memmem.c \
-    bionic/pututline.c \
-    bionic/sched_cpualloc.c \
-    bionic/sched_cpucount.c \
-    bionic/sigblock.c \
-    bionic/siginterrupt.c \
-    bionic/sigsetmask.c \
-    bionic/system_properties_compat.c \
-    stdio/fread.c \
-    stdio/refill.c \
-    stdio/snprintf.c\
-    stdio/sprintf.c \
-    stdio/stdio.cpp \
-    stdio/stdio_ext.cpp \
-    stdlib/atexit.c \
-    stdlib/exit.c \
-
-# Fortify implementations of libc functions.
-libc_common_src_files += \
-    bionic/__FD_chk.cpp \
-    bionic/__fgets_chk.cpp \
-    bionic/__fread_chk.cpp \
-    bionic/__fwrite_chk.cpp \
-    bionic/__getcwd_chk.cpp \
-    bionic/__memchr_chk.cpp \
-    bionic/__memmove_chk.cpp \
-    bionic/__memrchr_chk.cpp \
-    bionic/__poll_chk.cpp \
-    bionic/__pread64_chk.cpp \
-    bionic/__pread_chk.cpp \
-    bionic/__pwrite64_chk.cpp \
-    bionic/__pwrite_chk.cpp \
-    bionic/__read_chk.cpp \
-    bionic/__readlink_chk.cpp \
-    bionic/__readlinkat_chk.cpp \
-    bionic/__recvfrom_chk.cpp \
-    bionic/__stpcpy_chk.cpp \
-    bionic/__stpncpy_chk.cpp \
-    bionic/__strchr_chk.cpp \
-    bionic/__strlcat_chk.cpp \
-    bionic/__strlcpy_chk.cpp \
-    bionic/__strlen_chk.cpp \
-    bionic/__strncat_chk.cpp \
-    bionic/__strncpy_chk.cpp \
-    bionic/__strrchr_chk.cpp \
-    bionic/__umask_chk.cpp \
-    bionic/__vsnprintf_chk.cpp \
-    bionic/__vsprintf_chk.cpp \
-    bionic/__write_chk.cpp
-
-libc_bionic_ndk_src_files := \
-    bionic/abort.cpp \
-    bionic/accept.cpp \
-    bionic/accept4.cpp \
-    bionic/access.cpp \
-    bionic/arpa_inet.cpp \
-    bionic/assert.cpp \
-    bionic/atof.cpp \
-    bionic/bionic_netlink.cpp \
-    bionic/bionic_systrace.cpp \
-    bionic/bionic_time_conversions.cpp \
-    bionic/brk.cpp \
-    bionic/c16rtomb.cpp \
-    bionic/c32rtomb.cpp \
-    bionic/chmod.cpp \
-    bionic/chown.cpp \
-    bionic/clearenv.cpp \
-    bionic/clock.cpp \
-    bionic/clock_getcpuclockid.cpp \
-    bionic/clock_nanosleep.cpp \
-    bionic/clone.cpp \
-    bionic/close.cpp \
-    bionic/__cmsg_nxthdr.cpp \
-    bionic/connect.cpp \
-    bionic/ctype.cpp \
-    bionic/dirent.cpp \
-    bionic/dup2.cpp \
-    bionic/epoll_create.cpp \
-    bionic/epoll_pwait.cpp \
-    bionic/epoll_wait.cpp \
-    bionic/__errno.cpp \
-    bionic/error.cpp \
-    bionic/eventfd_read.cpp \
-    bionic/eventfd_write.cpp \
-    bionic/faccessat.cpp \
-    bionic/fchmod.cpp \
-    bionic/fchmodat.cpp \
-    bionic/ffs.cpp \
-    bionic/fgetxattr.cpp \
-    bionic/flistxattr.cpp \
-    bionic/flockfile.cpp \
-    bionic/fpclassify.cpp \
-    bionic/fsetxattr.cpp \
-    bionic/ftruncate.cpp \
-    bionic/futimens.cpp \
-    bionic/getcwd.cpp \
-    bionic/gethostname.cpp \
-    bionic/getpgrp.cpp \
-    bionic/getpid.cpp \
-    bionic/gettid.cpp \
-    bionic/__gnu_basename.cpp \
-    bionic/ifaddrs.cpp \
-    bionic/inotify_init.cpp \
-    bionic/ioctl.cpp \
-    bionic/lchown.cpp \
-    bionic/lfs64_support.cpp \
-    bionic/__libc_current_sigrtmax.cpp \
-    bionic/__libc_current_sigrtmin.cpp \
-    bionic/libc_init_common.cpp \
-    bionic/libc_logging.cpp \
-    bionic/libgen.cpp \
-    bionic/link.cpp \
-    bionic/locale.cpp \
-    bionic/lockf.cpp \
-    bionic/lstat.cpp \
-    bionic/malloc_info.cpp \
-    bionic/mbrtoc16.cpp \
-    bionic/mbrtoc32.cpp \
-    bionic/mbstate.cpp \
-    bionic/mempcpy.cpp \
-    bionic/mkdir.cpp \
-    bionic/mkfifo.cpp \
-    bionic/mknod.cpp \
-    bionic/mntent.cpp \
-    bionic/mremap.cpp \
-    bionic/NetdClientDispatch.cpp \
-    bionic/net_if.cpp \
-    bionic/netinet_in.cpp \
-    bionic/open.cpp \
-    bionic/pathconf.cpp \
-    bionic/pause.cpp \
-    bionic/pipe.cpp \
-    bionic/poll.cpp \
-    bionic/posix_fadvise.cpp \
-    bionic/posix_fallocate.cpp \
-    bionic/posix_madvise.cpp \
-    bionic/posix_timers.cpp \
-    bionic/ptrace.cpp \
-    bionic/pty.cpp \
-    bionic/raise.cpp \
-    bionic/rand.cpp \
-    bionic/readlink.cpp \
-    bionic/reboot.cpp \
-    bionic/recv.cpp \
-    bionic/rename.cpp \
-    bionic/rmdir.cpp \
-    bionic/scandir.cpp \
-    bionic/sched_getaffinity.cpp \
-    bionic/sched_getcpu.cpp \
-    bionic/semaphore.cpp \
-    bionic/send.cpp \
-    bionic/setegid.cpp \
-    bionic/__set_errno.cpp \
-    bionic/seteuid.cpp \
-    bionic/setpgrp.cpp \
-    bionic/sigaction.cpp \
-    bionic/sigaddset.cpp \
-    bionic/sigdelset.cpp \
-    bionic/sigemptyset.cpp \
-    bionic/sigfillset.cpp \
-    bionic/sigismember.cpp \
-    bionic/signal.cpp \
-    bionic/signalfd.cpp \
-    bionic/sigpending.cpp \
-    bionic/sigprocmask.cpp \
-    bionic/sigqueue.cpp \
-    bionic/sigsuspend.cpp \
-    bionic/sigtimedwait.cpp \
-    bionic/sigwait.cpp \
-    bionic/sigwaitinfo.cpp \
-    bionic/socket.cpp \
-    bionic/stat.cpp \
-    bionic/statvfs.cpp \
-    bionic/strchrnul.cpp \
-    bionic/strerror.cpp \
-    bionic/strerror_r.cpp \
-    bionic/strsignal.cpp \
-    bionic/strtold.cpp \
-    bionic/stubs.cpp \
-    bionic/symlink.cpp \
-    bionic/sysinfo.cpp \
-    bionic/syslog.cpp \
-    bionic/sys_siglist.c \
-    bionic/sys_signame.c \
-    bionic/system_properties.cpp \
-    bionic/tdestroy.cpp \
-    bionic/termios.cpp \
-    bionic/thread_private.cpp \
-    bionic/tmpfile.cpp \
-    bionic/umount.cpp \
-    bionic/unlink.cpp \
-    bionic/utimes.cpp \
-    bionic/wait.cpp \
-    bionic/wchar.cpp \
-    bionic/wctype.cpp \
-    bionic/wmempcpy.cpp \
-
-libc_bionic_src_files :=
-
-# The following implementations depend on pthread data, so we can't include
-# them in libc_ndk.a.
-libc_bionic_src_files += \
-    bionic/__cxa_thread_atexit_impl.cpp \
-    bionic/fork.cpp \
-
-# The data that backs getauxval is initialized in the libc init functions which
-# are invoked by the linker. If this file is included in libc_ndk.a, only one of
-# the copies of the global data will be initialized, resulting in nullptr
-# dereferences.
-libc_bionic_src_files += bionic/getauxval.cpp
-
-# These four require getauxval, which isn't available on older platforms.
-libc_bionic_src_files += bionic/getentropy_linux.c
-libc_bionic_src_files += bionic/sysconf.cpp
-libc_bionic_src_files += bionic/vdso.cpp
-libc_bionic_src_files += bionic/setjmp_cookie.cpp
-
-libc_bionic_src_files += \
-    bionic/__memcpy_chk.cpp \
-    bionic/__memset_chk.cpp \
-    bionic/__strcat_chk.cpp \
-    bionic/__strcpy_chk.cpp \
-    bionic/strchr.cpp \
-    bionic/strnlen.c \
-    bionic/strrchr.cpp \
-
-libc_cxa_src_files := \
-    bionic/__cxa_guard.cpp \
-    bionic/__cxa_pure_virtual.cpp \
-    bionic/new.cpp \
-
-libc_upstream_freebsd_src_files := \
-    upstream-freebsd/lib/libc/gen/ldexp.c \
-    upstream-freebsd/lib/libc/gen/sleep.c \
-    upstream-freebsd/lib/libc/gen/usleep.c \
-    upstream-freebsd/lib/libc/stdlib/getopt_long.c \
-    upstream-freebsd/lib/libc/stdlib/qsort.c \
-    upstream-freebsd/lib/libc/stdlib/quick_exit.c \
-    upstream-freebsd/lib/libc/stdlib/realpath.c \
-    upstream-freebsd/lib/libc/string/wcpcpy.c \
-    upstream-freebsd/lib/libc/string/wcpncpy.c \
-    upstream-freebsd/lib/libc/string/wcscasecmp.c \
-    upstream-freebsd/lib/libc/string/wcscat.c \
-    upstream-freebsd/lib/libc/string/wcschr.c \
-    upstream-freebsd/lib/libc/string/wcscmp.c \
-    upstream-freebsd/lib/libc/string/wcscpy.c \
-    upstream-freebsd/lib/libc/string/wcscspn.c \
-    upstream-freebsd/lib/libc/string/wcsdup.c \
-    upstream-freebsd/lib/libc/string/wcslcat.c \
-    upstream-freebsd/lib/libc/string/wcslen.c \
-    upstream-freebsd/lib/libc/string/wcsncasecmp.c \
-    upstream-freebsd/lib/libc/string/wcsncat.c \
-    upstream-freebsd/lib/libc/string/wcsncmp.c \
-    upstream-freebsd/lib/libc/string/wcsncpy.c \
-    upstream-freebsd/lib/libc/string/wcsnlen.c \
-    upstream-freebsd/lib/libc/string/wcspbrk.c \
-    upstream-freebsd/lib/libc/string/wcsrchr.c \
-    upstream-freebsd/lib/libc/string/wcsspn.c \
-    upstream-freebsd/lib/libc/string/wcstok.c \
-    upstream-freebsd/lib/libc/string/wmemchr.c \
-    upstream-freebsd/lib/libc/string/wmemcmp.c \
-    upstream-freebsd/lib/libc/string/wmemmove.c \
-    upstream-freebsd/lib/libc/string/wmemset.c \
-
-libc_upstream_netbsd_src_files := \
-    upstream-netbsd/common/lib/libc/stdlib/random.c \
-    upstream-netbsd/lib/libc/gen/ftw.c \
-    upstream-netbsd/lib/libc/gen/nftw.c \
-    upstream-netbsd/lib/libc/gen/nice.c \
-    upstream-netbsd/lib/libc/gen/popen.c \
-    upstream-netbsd/lib/libc/gen/psignal.c \
-    upstream-netbsd/lib/libc/gen/utime.c \
-    upstream-netbsd/lib/libc/gen/utmp.c \
-    upstream-netbsd/lib/libc/inet/nsap_addr.c \
-    upstream-netbsd/lib/libc/regex/regcomp.c \
-    upstream-netbsd/lib/libc/regex/regerror.c \
-    upstream-netbsd/lib/libc/regex/regexec.c \
-    upstream-netbsd/lib/libc/regex/regfree.c \
-    upstream-netbsd/lib/libc/stdlib/bsearch.c \
-    upstream-netbsd/lib/libc/stdlib/div.c \
-    upstream-netbsd/lib/libc/stdlib/drand48.c \
-    upstream-netbsd/lib/libc/stdlib/erand48.c \
-    upstream-netbsd/lib/libc/stdlib/jrand48.c \
-    upstream-netbsd/lib/libc/stdlib/lcong48.c \
-    upstream-netbsd/lib/libc/stdlib/ldiv.c \
-    upstream-netbsd/lib/libc/stdlib/lldiv.c \
-    upstream-netbsd/lib/libc/stdlib/lrand48.c \
-    upstream-netbsd/lib/libc/stdlib/mrand48.c \
-    upstream-netbsd/lib/libc/stdlib/nrand48.c \
-    upstream-netbsd/lib/libc/stdlib/_rand48.c \
-    upstream-netbsd/lib/libc/stdlib/rand_r.c \
-    upstream-netbsd/lib/libc/stdlib/reallocarr.c \
-    upstream-netbsd/lib/libc/stdlib/seed48.c \
-    upstream-netbsd/lib/libc/stdlib/srand48.c \
-    upstream-netbsd/lib/libc/string/memccpy.c \
-    upstream-netbsd/lib/libc/string/strcasestr.c \
-    upstream-netbsd/lib/libc/string/strcoll.c \
-    upstream-netbsd/lib/libc/string/strxfrm.c \
-
-libc_upstream_openbsd_gdtoa_src_files := \
-    upstream-openbsd/android/gdtoa_support.cpp \
-    upstream-openbsd/lib/libc/gdtoa/dmisc.c \
-    upstream-openbsd/lib/libc/gdtoa/dtoa.c \
-    upstream-openbsd/lib/libc/gdtoa/gdtoa.c \
-    upstream-openbsd/lib/libc/gdtoa/gethex.c \
-    upstream-openbsd/lib/libc/gdtoa/gmisc.c \
-    upstream-openbsd/lib/libc/gdtoa/hd_init.c \
-    upstream-openbsd/lib/libc/gdtoa/hdtoa.c \
-    upstream-openbsd/lib/libc/gdtoa/hexnan.c \
-    upstream-openbsd/lib/libc/gdtoa/ldtoa.c \
-    upstream-openbsd/lib/libc/gdtoa/misc.c \
-    upstream-openbsd/lib/libc/gdtoa/smisc.c \
-    upstream-openbsd/lib/libc/gdtoa/strtod.c \
-    upstream-openbsd/lib/libc/gdtoa/strtodg.c \
-    upstream-openbsd/lib/libc/gdtoa/strtof.c \
-    upstream-openbsd/lib/libc/gdtoa/strtord.c \
-    upstream-openbsd/lib/libc/gdtoa/sum.c \
-    upstream-openbsd/lib/libc/gdtoa/ulp.c \
-
-libc_upstream_openbsd_gdtoa_src_files_32 := \
-    $(libc_upstream_openbsd_gdtoa_src_files) \
-
-libc_upstream_openbsd_gdtoa_src_files_64 := \
-    $(libc_upstream_openbsd_gdtoa_src_files) \
-    upstream-openbsd/lib/libc/gdtoa/strtorQ.c \
-
-# These two depend on getentropy_linux.c, which isn't in libc_ndk.a.
-libc_upstream_openbsd_src_files := \
-    upstream-openbsd/lib/libc/crypt/arc4random.c \
-    upstream-openbsd/lib/libc/crypt/arc4random_uniform.c \
-
-libc_upstream_openbsd_src_files += \
-    upstream-openbsd/lib/libc/string/memchr.c \
-    upstream-openbsd/lib/libc/string/memmove.c \
-    upstream-openbsd/lib/libc/string/memrchr.c \
-    upstream-openbsd/lib/libc/string/stpcpy.c \
-    upstream-openbsd/lib/libc/string/stpncpy.c \
-    upstream-openbsd/lib/libc/string/strcat.c \
-    upstream-openbsd/lib/libc/string/strcpy.c \
-    upstream-openbsd/lib/libc/string/strlcat.c \
-    upstream-openbsd/lib/libc/string/strlcpy.c \
-    upstream-openbsd/lib/libc/string/strncat.c \
-    upstream-openbsd/lib/libc/string/strncmp.c \
-    upstream-openbsd/lib/libc/string/strncpy.c \
-
-libc_upstream_openbsd_ndk_src_files := \
-    upstream-openbsd/lib/libc/compat-43/killpg.c \
-    upstream-openbsd/lib/libc/gen/alarm.c \
-    upstream-openbsd/lib/libc/gen/ctype_.c \
-    upstream-openbsd/lib/libc/gen/daemon.c \
-    upstream-openbsd/lib/libc/gen/err.c \
-    upstream-openbsd/lib/libc/gen/errx.c \
-    upstream-openbsd/lib/libc/gen/exec.c \
-    upstream-openbsd/lib/libc/gen/fnmatch.c \
-    upstream-openbsd/lib/libc/gen/ftok.c \
-    upstream-openbsd/lib/libc/gen/getprogname.c \
-    upstream-openbsd/lib/libc/gen/isctype.c \
-    upstream-openbsd/lib/libc/gen/setprogname.c \
-    upstream-openbsd/lib/libc/gen/time.c \
-    upstream-openbsd/lib/libc/gen/tolower_.c \
-    upstream-openbsd/lib/libc/gen/toupper_.c \
-    upstream-openbsd/lib/libc/gen/verr.c \
-    upstream-openbsd/lib/libc/gen/verrx.c \
-    upstream-openbsd/lib/libc/gen/vwarn.c \
-    upstream-openbsd/lib/libc/gen/vwarnx.c \
-    upstream-openbsd/lib/libc/gen/warn.c \
-    upstream-openbsd/lib/libc/gen/warnx.c \
-    upstream-openbsd/lib/libc/locale/btowc.c \
-    upstream-openbsd/lib/libc/locale/mbrlen.c \
-    upstream-openbsd/lib/libc/locale/mbstowcs.c \
-    upstream-openbsd/lib/libc/locale/mbtowc.c \
-    upstream-openbsd/lib/libc/locale/wcscoll.c \
-    upstream-openbsd/lib/libc/locale/wcstod.c \
-    upstream-openbsd/lib/libc/locale/wcstof.c \
-    upstream-openbsd/lib/libc/locale/wcstoimax.c \
-    upstream-openbsd/lib/libc/locale/wcstol.c \
-    upstream-openbsd/lib/libc/locale/wcstold.c \
-    upstream-openbsd/lib/libc/locale/wcstoll.c \
-    upstream-openbsd/lib/libc/locale/wcstombs.c \
-    upstream-openbsd/lib/libc/locale/wcstoul.c \
-    upstream-openbsd/lib/libc/locale/wcstoull.c \
-    upstream-openbsd/lib/libc/locale/wcstoumax.c \
-    upstream-openbsd/lib/libc/locale/wcsxfrm.c \
-    upstream-openbsd/lib/libc/locale/wctob.c \
-    upstream-openbsd/lib/libc/locale/wctomb.c \
-    upstream-openbsd/lib/libc/net/htonl.c \
-    upstream-openbsd/lib/libc/net/htons.c \
-    upstream-openbsd/lib/libc/net/inet_lnaof.c \
-    upstream-openbsd/lib/libc/net/inet_makeaddr.c \
-    upstream-openbsd/lib/libc/net/inet_netof.c \
-    upstream-openbsd/lib/libc/net/inet_ntoa.c \
-    upstream-openbsd/lib/libc/net/inet_ntop.c \
-    upstream-openbsd/lib/libc/net/inet_pton.c \
-    upstream-openbsd/lib/libc/net/ntohl.c \
-    upstream-openbsd/lib/libc/net/ntohs.c \
-    upstream-openbsd/lib/libc/net/res_random.c \
-    upstream-openbsd/lib/libc/stdio/asprintf.c \
-    upstream-openbsd/lib/libc/stdio/clrerr.c \
-    upstream-openbsd/lib/libc/stdio/dprintf.c \
-    upstream-openbsd/lib/libc/stdio/feof.c \
-    upstream-openbsd/lib/libc/stdio/ferror.c \
-    upstream-openbsd/lib/libc/stdio/fflush.c \
-    upstream-openbsd/lib/libc/stdio/fgetc.c \
-    upstream-openbsd/lib/libc/stdio/fgetln.c \
-    upstream-openbsd/lib/libc/stdio/fgets.c \
-    upstream-openbsd/lib/libc/stdio/fgetwc.c \
-    upstream-openbsd/lib/libc/stdio/fgetws.c \
-    upstream-openbsd/lib/libc/stdio/flags.c \
-    upstream-openbsd/lib/libc/stdio/fmemopen.c \
-    upstream-openbsd/lib/libc/stdio/fprintf.c \
-    upstream-openbsd/lib/libc/stdio/fpurge.c \
-    upstream-openbsd/lib/libc/stdio/fputc.c \
-    upstream-openbsd/lib/libc/stdio/fputs.c \
-    upstream-openbsd/lib/libc/stdio/fputwc.c \
-    upstream-openbsd/lib/libc/stdio/fputws.c \
-    upstream-openbsd/lib/libc/stdio/fscanf.c \
-    upstream-openbsd/lib/libc/stdio/fvwrite.c \
-    upstream-openbsd/lib/libc/stdio/fwalk.c \
-    upstream-openbsd/lib/libc/stdio/fwide.c \
-    upstream-openbsd/lib/libc/stdio/fwprintf.c \
-    upstream-openbsd/lib/libc/stdio/fwrite.c \
-    upstream-openbsd/lib/libc/stdio/fwscanf.c \
-    upstream-openbsd/lib/libc/stdio/getc.c \
-    upstream-openbsd/lib/libc/stdio/getchar.c \
-    upstream-openbsd/lib/libc/stdio/getdelim.c \
-    upstream-openbsd/lib/libc/stdio/getline.c \
-    upstream-openbsd/lib/libc/stdio/gets.c \
-    upstream-openbsd/lib/libc/stdio/getwc.c \
-    upstream-openbsd/lib/libc/stdio/getwchar.c \
-    upstream-openbsd/lib/libc/stdio/makebuf.c \
-    upstream-openbsd/lib/libc/stdio/mktemp.c \
-    upstream-openbsd/lib/libc/stdio/open_memstream.c \
-    upstream-openbsd/lib/libc/stdio/open_wmemstream.c \
-    upstream-openbsd/lib/libc/stdio/perror.c \
-    upstream-openbsd/lib/libc/stdio/printf.c \
-    upstream-openbsd/lib/libc/stdio/putc.c \
-    upstream-openbsd/lib/libc/stdio/putchar.c \
-    upstream-openbsd/lib/libc/stdio/puts.c \
-    upstream-openbsd/lib/libc/stdio/putwc.c \
-    upstream-openbsd/lib/libc/stdio/putwchar.c \
-    upstream-openbsd/lib/libc/stdio/remove.c \
-    upstream-openbsd/lib/libc/stdio/rewind.c \
-    upstream-openbsd/lib/libc/stdio/rget.c \
-    upstream-openbsd/lib/libc/stdio/scanf.c \
-    upstream-openbsd/lib/libc/stdio/setbuf.c \
-    upstream-openbsd/lib/libc/stdio/setbuffer.c \
-    upstream-openbsd/lib/libc/stdio/setvbuf.c \
-    upstream-openbsd/lib/libc/stdio/sscanf.c \
-    upstream-openbsd/lib/libc/stdio/swprintf.c \
-    upstream-openbsd/lib/libc/stdio/swscanf.c \
-    upstream-openbsd/lib/libc/stdio/tempnam.c \
-    upstream-openbsd/lib/libc/stdio/tmpnam.c \
-    upstream-openbsd/lib/libc/stdio/ungetc.c \
-    upstream-openbsd/lib/libc/stdio/ungetwc.c \
-    upstream-openbsd/lib/libc/stdio/vasprintf.c \
-    upstream-openbsd/lib/libc/stdio/vdprintf.c \
-    upstream-openbsd/lib/libc/stdio/vfprintf.c \
-    upstream-openbsd/lib/libc/stdio/vfscanf.c \
-    upstream-openbsd/lib/libc/stdio/vfwprintf.c \
-    upstream-openbsd/lib/libc/stdio/vfwscanf.c \
-    upstream-openbsd/lib/libc/stdio/vprintf.c \
-    upstream-openbsd/lib/libc/stdio/vscanf.c \
-    upstream-openbsd/lib/libc/stdio/vsnprintf.c \
-    upstream-openbsd/lib/libc/stdio/vsprintf.c \
-    upstream-openbsd/lib/libc/stdio/vsscanf.c \
-    upstream-openbsd/lib/libc/stdio/vswprintf.c \
-    upstream-openbsd/lib/libc/stdio/vswscanf.c \
-    upstream-openbsd/lib/libc/stdio/vwprintf.c \
-    upstream-openbsd/lib/libc/stdio/vwscanf.c \
-    upstream-openbsd/lib/libc/stdio/wbuf.c \
-    upstream-openbsd/lib/libc/stdio/wprintf.c \
-    upstream-openbsd/lib/libc/stdio/wscanf.c \
-    upstream-openbsd/lib/libc/stdio/wsetup.c \
-    upstream-openbsd/lib/libc/stdlib/abs.c \
-    upstream-openbsd/lib/libc/stdlib/atoi.c \
-    upstream-openbsd/lib/libc/stdlib/atol.c \
-    upstream-openbsd/lib/libc/stdlib/atoll.c \
-    upstream-openbsd/lib/libc/stdlib/getenv.c \
-    upstream-openbsd/lib/libc/stdlib/insque.c \
-    upstream-openbsd/lib/libc/stdlib/imaxabs.c \
-    upstream-openbsd/lib/libc/stdlib/imaxdiv.c \
-    upstream-openbsd/lib/libc/stdlib/labs.c \
-    upstream-openbsd/lib/libc/stdlib/llabs.c \
-    upstream-openbsd/lib/libc/stdlib/lsearch.c \
-    upstream-openbsd/lib/libc/stdlib/reallocarray.c \
-    upstream-openbsd/lib/libc/stdlib/remque.c \
-    upstream-openbsd/lib/libc/stdlib/setenv.c \
-    upstream-openbsd/lib/libc/stdlib/strtoimax.c \
-    upstream-openbsd/lib/libc/stdlib/strtol.c \
-    upstream-openbsd/lib/libc/stdlib/strtoll.c \
-    upstream-openbsd/lib/libc/stdlib/strtoul.c \
-    upstream-openbsd/lib/libc/stdlib/strtoull.c \
-    upstream-openbsd/lib/libc/stdlib/strtoumax.c \
-    upstream-openbsd/lib/libc/stdlib/system.c \
-    upstream-openbsd/lib/libc/stdlib/tfind.c \
-    upstream-openbsd/lib/libc/stdlib/tsearch.c \
-    upstream-openbsd/lib/libc/string/strcasecmp.c \
-    upstream-openbsd/lib/libc/string/strcspn.c \
-    upstream-openbsd/lib/libc/string/strdup.c \
-    upstream-openbsd/lib/libc/string/strndup.c \
-    upstream-openbsd/lib/libc/string/strpbrk.c \
-    upstream-openbsd/lib/libc/string/strsep.c \
-    upstream-openbsd/lib/libc/string/strspn.c \
-    upstream-openbsd/lib/libc/string/strstr.c \
-    upstream-openbsd/lib/libc/string/strtok.c \
-    upstream-openbsd/lib/libc/string/wmemcpy.c \
-    upstream-openbsd/lib/libc/string/wcslcpy.c \
-    upstream-openbsd/lib/libc/string/wcsstr.c \
-    upstream-openbsd/lib/libc/string/wcswidth.c \
-
-libc_pthread_src_files := \
-    bionic/pthread_atfork.cpp \
-    bionic/pthread_attr.cpp \
-    bionic/pthread_barrier.cpp \
-    bionic/pthread_cond.cpp \
-    bionic/pthread_create.cpp \
-    bionic/pthread_detach.cpp \
-    bionic/pthread_equal.cpp \
-    bionic/pthread_exit.cpp \
-    bionic/pthread_getcpuclockid.cpp \
-    bionic/pthread_getschedparam.cpp \
-    bionic/pthread_gettid_np.cpp \
-    bionic/pthread_internal.cpp \
-    bionic/pthread_join.cpp \
-    bionic/pthread_key.cpp \
-    bionic/pthread_kill.cpp \
-    bionic/pthread_mutex.cpp \
-    bionic/pthread_once.cpp \
-    bionic/pthread_rwlock.cpp \
-    bionic/pthread_self.cpp \
-    bionic/pthread_setname_np.cpp \
-    bionic/pthread_setschedparam.cpp \
-    bionic/pthread_sigmask.cpp \
-    bionic/pthread_spinlock.cpp \
-
-libc_arch_static_src_files := \
-    bionic/dl_iterate_phdr_static.cpp \
-
-# Various kinds of cruft.
-# ========================================================
-libc_common_src_files += \
-    bionic/ndk_cruft.cpp \
-
-libc_bionic_ndk_src_files_32 += \
-    bionic/mmap.cpp \
-
-libc_common_src_files_32 += \
-    bionic/legacy_32_bit_support.cpp \
-    bionic/time64.c \
-
-libc_netbsd_src_files_32 += \
-    upstream-netbsd/common/lib/libc/hash/sha1/sha1.c \
-
-libc_openbsd_src_files_32 += \
-    upstream-openbsd/lib/libc/stdio/putw.c \
-
-
-# Define some common cflags
-# ========================================================
-libc_common_cflags := \
-    -D_LIBC=1 \
-    -Wall -Wextra -Wunused \
-
-use_clang := $(USE_CLANG_PLATFORM_BUILD)
-
-# Clang/llvm has incompatible long double (fp128) for x86_64.
-# https://llvm.org/bugs/show_bug.cgi?id=23897
-ifeq ($(TARGET_ARCH),x86_64)
-  use_clang := false
-endif
-
-# b/25291096, Clang/llvm compiled libc.so for mips/mips64 failed to boot.
-ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),mips mips64))
-  use_clang := false
-endif
-
-ifeq ($(use_clang),)
-  use_clang := true
-endif
-
-# Try to catch typical 32-bit assumptions that break with 64-bit pointers.
-libc_common_cflags += \
-    -Werror=pointer-to-int-cast \
-    -Werror=int-to-pointer-cast \
-    -Werror=type-limits \
-    -Werror \
-
-ifeq ($(strip $(DEBUG_BIONIC_LIBC)),true)
-  libc_common_cflags += -DDEBUG
-endif
-
-libc_malloc_src := bionic/jemalloc_wrapper.cpp
-libc_common_c_includes += external/jemalloc/include
-
-# Define some common conlyflags
-libc_common_conlyflags := \
-    -std=gnu99
-
-# Define some common cppflags
-libc_common_cppflags := \
-
-# Define some common includes
-# ========================================================
-libc_common_c_includes += \
-    $(LOCAL_PATH)/stdio   \
-
-# ========================================================
-# Add in the arch or 32-bit specific flags
-# Must be called with $(eval).
-# $(1): the LOCAL_ variable name
-# $(2): the bionic variable name to pull in
-define patch-up-arch-specific-flags
-$(1)_$(TARGET_ARCH) += $($(2)_$(TARGET_ARCH))
-$(1)_32 += $($(2)_32)
-ifdef TARGET_2ND_ARCH
-$(1)_$(TARGET_2ND_ARCH) += $($(2)_$(TARGET_2ND_ARCH))
-endif
-endef
-
-
-# ========================================================
-# libc_stack_protector.a - stack protector code
-# ========================================================
-#
-# Code that implements the stack protector (or that runs
-# before TLS has been set up) needs to be compiled with
-# -fno-stack-protector, since it accesses the stack canary
-# TLS slot.
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-    bionic/__libc_init_main_thread.cpp \
-    bionic/__stack_chk_fail.cpp \
-
-LOCAL_SRC_FILES_arm64 := arch-arm64/bionic/__set_tls.c
-LOCAL_SRC_FILES_x86 := arch-x86/bionic/__set_tls.c
-LOCAL_SRC_FILES_x86_64 := arch-x86_64/bionic/__set_tls.c
-
-LOCAL_CFLAGS := $(libc_common_cflags) -fno-stack-protector
-LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
-LOCAL_CPPFLAGS := $(libc_common_cppflags)
-LOCAL_C_INCLUDES := $(libc_common_c_includes)
-LOCAL_MODULE := libc_stack_protector
-LOCAL_CLANG := $(use_clang)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
-LOCAL_CXX_STL := none
-LOCAL_SYSTEM_SHARED_LIBRARIES :=
-LOCAL_SANITIZE := never
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-
-$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
-include $(BUILD_STATIC_LIBRARY)
-
-
-# libc_init_static.cpp also needs to be built without stack protector,
-# because it's responsible for setting up TLS for static executables.
-# This isn't the case for dynamic executables because the dynamic linker
-# has already set up the main thread's TLS.
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := bionic/libc_init_static.cpp
-LOCAL_CFLAGS := $(libc_common_cflags) -fno-stack-protector
-LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
-LOCAL_CPPFLAGS := $(libc_common_cppflags)
-LOCAL_C_INCLUDES := $(libc_common_c_includes)
-LOCAL_MODULE := libc_init_static
-LOCAL_CLANG := $(use_clang)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
-LOCAL_CXX_STL := none
-LOCAL_SYSTEM_SHARED_LIBRARIES :=
-LOCAL_SANITIZE := never
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-
-$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
-include $(BUILD_STATIC_LIBRARY)
-
-
-# ========================================================
-# libc_tzcode.a - upstream 'tzcode' code
-# ========================================================
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(call all-c-files-under,tzcode)
-# tzcode doesn't include wcsftime, so we use the OpenBSD one.
-LOCAL_SRC_FILES += upstream-openbsd/lib/libc/time/wcsftime.c
-
-LOCAL_CFLAGS := $(libc_common_cflags) \
-    -fvisibility=hidden \
-    -Wno-unused-parameter \
-
-# Don't use ridiculous amounts of stack.
-LOCAL_CFLAGS += -DALL_STATE
-# Include tzsetwall, timelocal, timegm, time2posix, and posix2time.
-LOCAL_CFLAGS += -DSTD_INSPIRED
-# Obviously, we want to be thread-safe.
-LOCAL_CFLAGS += -DTHREAD_SAFE
-# The name of the tm_gmtoff field in our struct tm.
-LOCAL_CFLAGS += -DTM_GMTOFF=tm_gmtoff
-# Where we store our tzdata.
-LOCAL_CFLAGS += -DTZDIR=\"/system/usr/share/zoneinfo\"
-# Include timezone and daylight globals.
-LOCAL_CFLAGS += -DUSG_COMPAT=1
-# Use the empty string (instead of "   ") as the timezone abbreviation fallback.
-LOCAL_CFLAGS += -DWILDABBR=\"\"
-LOCAL_CFLAGS += -DNO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU
-LOCAL_CFLAGS += -Dlint
-
-LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
-LOCAL_CPPFLAGS := $(libc_common_cppflags)
-LOCAL_C_INCLUDES := $(libc_common_c_includes) $(LOCAL_PATH)/tzcode/
-LOCAL_MODULE := libc_tzcode
-LOCAL_CLANG := $(use_clang)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
-LOCAL_CXX_STL := none
-LOCAL_SYSTEM_SHARED_LIBRARIES :=
-LOCAL_SANITIZE := never
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-
-$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
-include $(BUILD_STATIC_LIBRARY)
-
-
-# ========================================================
-# libc_dns.a - modified NetBSD DNS code
-# ========================================================
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-    $(call all-c-files-under,dns) \
-    upstream-netbsd/lib/libc/isc/ev_streams.c \
-    upstream-netbsd/lib/libc/isc/ev_timers.c \
-    upstream-netbsd/lib/libc/resolv/mtctxres.c \
-
-LOCAL_CFLAGS += \
-    $(libc_common_cflags) \
-    -DANDROID_CHANGES \
-    -DINET6 \
-    -fvisibility=hidden \
-    -Wno-unused-parameter \
-    -include netbsd-compat.h \
-
-LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
-LOCAL_CPPFLAGS := $(libc_common_cppflags)
-LOCAL_C_INCLUDES := $(libc_common_c_includes) \
-    $(LOCAL_PATH)/dns/include \
-    $(LOCAL_PATH)/private \
-    $(LOCAL_PATH)/upstream-netbsd/lib/libc/include \
-    $(LOCAL_PATH)/upstream-netbsd/android/include \
-
-LOCAL_MODULE := libc_dns
-LOCAL_CLANG := $(use_clang)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
-LOCAL_CXX_STL := none
-LOCAL_SYSTEM_SHARED_LIBRARIES :=
-LOCAL_SANITIZE := never
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-
-$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
-include $(BUILD_STATIC_LIBRARY)
-
-
-# ========================================================
-# libc_freebsd.a - upstream FreeBSD C library code
-# ========================================================
-#
-# These files are built with the freebsd-compat.h header file
-# automatically included.
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(libc_upstream_freebsd_src_files)
-LOCAL_CFLAGS := \
-    $(libc_common_cflags) \
-    -Wno-sign-compare -Wno-uninitialized \
-    -include freebsd-compat.h \
-
-LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
-LOCAL_CPPFLAGS := $(libc_common_cppflags)
-LOCAL_C_INCLUDES := $(libc_common_c_includes) \
-    $(LOCAL_PATH)/upstream-freebsd/android/include \
-    $(LOCAL_PATH)/upstream-freebsd/lib/libc/include \
-
-LOCAL_MODULE := libc_freebsd
-LOCAL_CLANG := $(use_clang)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
-LOCAL_CXX_STL := none
-LOCAL_SYSTEM_SHARED_LIBRARIES :=
-LOCAL_SANITIZE := never
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-
-$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
-$(eval $(call patch-up-arch-specific-flags,LOCAL_SRC_FILES_EXCLUDE,libc_freebsd_src_files_exclude))
-include $(BUILD_STATIC_LIBRARY)
-
-
-# ========================================================
-# libc_netbsd.a - upstream NetBSD C library code
-# ========================================================
-#
-# These files are built with the netbsd-compat.h header file
-# automatically included.
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(libc_upstream_netbsd_src_files)
-LOCAL_CFLAGS := \
-    $(libc_common_cflags) \
-    -Wno-sign-compare \
-    -Wno-uninitialized \
-    -Wno-unused-parameter \
-    -DPOSIX_MISTAKE \
-    -include netbsd-compat.h \
-
-LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
-LOCAL_CPPFLAGS := $(libc_common_cppflags)
-LOCAL_C_INCLUDES := $(libc_common_c_includes) \
-    $(LOCAL_PATH)/upstream-netbsd/android/include \
-    $(LOCAL_PATH)/upstream-netbsd/lib/libc/include \
-
-LOCAL_MODULE := libc_netbsd
-LOCAL_CLANG := $(use_clang)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
-LOCAL_CXX_STL := none
-LOCAL_SYSTEM_SHARED_LIBRARIES :=
-LOCAL_SANITIZE := never
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-
-$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
-$(eval $(call patch-up-arch-specific-flags,LOCAL_SRC_FILES,libc_netbsd_src_files))
-include $(BUILD_STATIC_LIBRARY)
-
-
-# ========================================================
-# libc_openbsd_ndk.a - upstream OpenBSD C library code
-# that can be safely included in the libc_ndk.a (doesn't
-# contain any troublesome global data or constructors).
-# ========================================================
-#
-# These files are built with the openbsd-compat.h header file
-# automatically included.
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(libc_upstream_openbsd_ndk_src_files)
-LOCAL_CLANG := $(use_clang)
-
-LOCAL_CFLAGS := \
-    $(libc_common_cflags) \
-    -Wno-sign-compare \
-    -Wno-uninitialized \
-    -Wno-unused-parameter \
-    -include openbsd-compat.h \
-
-LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
-LOCAL_CPPFLAGS := $(libc_common_cppflags)
-LOCAL_C_INCLUDES := $(libc_common_c_includes) \
-    $(LOCAL_PATH)/private \
-    $(LOCAL_PATH)/upstream-openbsd/android/include \
-    $(LOCAL_PATH)/upstream-openbsd/lib/libc/include \
-    $(LOCAL_PATH)/upstream-openbsd/lib/libc/gdtoa/ \
-
-LOCAL_MODULE := libc_openbsd_ndk
-LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
-LOCAL_CXX_STL := none
-LOCAL_SYSTEM_SHARED_LIBRARIES :=
-LOCAL_SANITIZE := never
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-
-$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
-include $(BUILD_STATIC_LIBRARY)
-
-
-# ========================================================
-# libc_openbsd.a - upstream OpenBSD C library code
-# ========================================================
-#
-# These files are built with the openbsd-compat.h header file
-# automatically included.
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(libc_upstream_openbsd_src_files)
-LOCAL_CLANG := $(use_clang)
-
-LOCAL_CFLAGS := \
-    $(libc_common_cflags) \
-    -Wno-sign-compare \
-    -Wno-uninitialized \
-    -Wno-unused-parameter \
-    -include openbsd-compat.h \
-
-LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
-LOCAL_CPPFLAGS := $(libc_common_cppflags)
-LOCAL_C_INCLUDES := $(libc_common_c_includes) \
-    $(LOCAL_PATH)/private \
-    $(LOCAL_PATH)/upstream-openbsd/android/include \
-    $(LOCAL_PATH)/upstream-openbsd/lib/libc/include \
-    $(LOCAL_PATH)/upstream-openbsd/lib/libc/gdtoa/ \
-
-LOCAL_MODULE := libc_openbsd
-LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
-LOCAL_CXX_STL := none
-LOCAL_SYSTEM_SHARED_LIBRARIES :=
-LOCAL_SANITIZE := never
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-
-$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
-$(eval $(call patch-up-arch-specific-flags,LOCAL_SRC_FILES,libc_openbsd_src_files))
-$(eval $(call patch-up-arch-specific-flags,LOCAL_SRC_FILES_EXCLUDE,libc_openbsd_src_files_exclude))
-include $(BUILD_STATIC_LIBRARY)
-
-
-# ========================================================
-# libc_gdtoa.a - upstream OpenBSD C library gdtoa code
-# ========================================================
-#
-# These files are built with the openbsd-compat.h header file
-# automatically included.
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES_32 := $(libc_upstream_openbsd_gdtoa_src_files_32)
-LOCAL_SRC_FILES_64 := $(libc_upstream_openbsd_gdtoa_src_files_64)
-LOCAL_CLANG := $(use_clang)
-
-LOCAL_CFLAGS := \
-    $(libc_common_cflags) \
-    -Wno-sign-compare -Wno-uninitialized \
-    -fvisibility=hidden \
-    -include openbsd-compat.h \
-
-LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
-LOCAL_CPPFLAGS := $(libc_common_cppflags)
-LOCAL_C_INCLUDES := $(libc_common_c_includes) \
-    $(LOCAL_PATH)/private \
-    $(LOCAL_PATH)/upstream-openbsd/android/include \
-    $(LOCAL_PATH)/upstream-openbsd/lib/libc/include \
-
-LOCAL_MODULE := libc_gdtoa
-LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
-LOCAL_CXX_STL := none
-LOCAL_SYSTEM_SHARED_LIBRARIES :=
-LOCAL_SANITIZE := never
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-
-$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
-include $(BUILD_STATIC_LIBRARY)
-
-
-# ========================================================
-# libc_bionic.a - home-grown C library code
-# ========================================================
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(libc_bionic_src_files)
-LOCAL_CFLAGS := $(libc_common_cflags) \
-    -Wframe-larger-than=2048 \
-
-LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
-LOCAL_CPPFLAGS := $(libc_common_cppflags) -Wold-style-cast
-LOCAL_C_INCLUDES := $(libc_common_c_includes) bionic/libstdc++/include
-LOCAL_MODULE := libc_bionic
-LOCAL_CLANG := $(use_clang)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
-LOCAL_CXX_STL := none
-LOCAL_SYSTEM_SHARED_LIBRARIES :=
-LOCAL_SANITIZE := never
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-
-$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
-$(eval $(call patch-up-arch-specific-flags,LOCAL_SRC_FILES,libc_bionic_src_files))
-$(eval $(call patch-up-arch-specific-flags,LOCAL_SRC_FILES_EXCLUDE,libc_bionic_src_files_exclude))
-include $(BUILD_STATIC_LIBRARY)
-
-
-# ========================================================
-# libc_bionic_ndk.a - The portions of libc_bionic that can
-# be safely used in libc_ndk.a (no troublesome global data
-# or constructors).
-# ========================================================
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(libc_bionic_ndk_src_files)
-LOCAL_CFLAGS := $(libc_common_cflags) \
-    -Wframe-larger-than=2048 \
-
-LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
-LOCAL_CPPFLAGS := $(libc_common_cppflags) -Wold-style-cast
-LOCAL_C_INCLUDES := $(libc_common_c_includes) bionic/libstdc++/include
-LOCAL_MODULE := libc_bionic_ndk
-LOCAL_CLANG := $(use_clang)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
-LOCAL_CXX_STL := none
-LOCAL_SYSTEM_SHARED_LIBRARIES :=
-LOCAL_SANITIZE := never
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-
-$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
-$(eval $(call patch-up-arch-specific-flags,LOCAL_SRC_FILES,libc_bionic_ndk_src_files))
-include $(BUILD_STATIC_LIBRARY)
-
-
-# ========================================================
-# libc_pthread.a - pthreads parts that previously lived in
-# libc_bionic.a. Relocated to their own library because
-# they can't be included in libc_ndk.a (as they layout of
-# pthread_t has changed over the years and has ABI
-# compatibility issues).
-# ========================================================
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(libc_pthread_src_files)
-LOCAL_CFLAGS := $(libc_common_cflags) \
-    -Wframe-larger-than=2048 \
-
-LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
-LOCAL_CPPFLAGS := $(libc_common_cppflags) -Wold-style-cast
-LOCAL_C_INCLUDES := $(libc_common_c_includes)
-LOCAL_MODULE := libc_pthread
-LOCAL_CLANG := $(use_clang)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
-LOCAL_CXX_STL := none
-LOCAL_SYSTEM_SHARED_LIBRARIES :=
-LOCAL_SANITIZE := never
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-
-include $(BUILD_STATIC_LIBRARY)
-
-
-# ========================================================
-# libc_cxa.a - Things traditionally in libstdc++
-# ========================================================
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(libc_cxa_src_files)
-LOCAL_CFLAGS := $(libc_common_cflags) \
-    -fvisibility=hidden \
-
-LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
-LOCAL_CPPFLAGS := $(libc_common_cppflags)
-LOCAL_C_INCLUDES := $(libc_common_c_includes) bionic/libstdc++/include
-LOCAL_MODULE := libc_cxa
-LOCAL_CLANG := true # GCC refuses to hide new/delete
-LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
-LOCAL_CXX_STL := none
-LOCAL_SYSTEM_SHARED_LIBRARIES :=
-LOCAL_SANITIZE := never
-# b/17574078: Need to disable coverage until we have a prebuilt libprofile_rt.
-# Since this is a static library built with clang, it needs to link
-# libprofile_rt when it is linked into the final binary. Since the final binary
-# is built with GCC, it won't link libprofile_rt. We can't very easily just add
-# libprofile_rt to all link lines the way we've done for libgcov because
-# libprofile_rt isn't prebuilt, and it would be tricky to write a rule that
-# would make sure libprofile_rt is built.
-LOCAL_NATIVE_COVERAGE := false
-
-include $(BUILD_STATIC_LIBRARY)
-
-
-# ========================================================
-# libc_syscalls.a
-# ========================================================
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES_$(TARGET_ARCH) := $(call all-S-files-under,arch-$(TARGET_ARCH)/syscalls)
-ifdef TARGET_2ND_ARCH
-LOCAL_SRC_FILES_$(TARGET_2ND_ARCH) := $(call all-S-files-under,arch-$(TARGET_2ND_ARCH)/syscalls)
-endif
-LOCAL_MODULE := libc_syscalls
-LOCAL_CLANG := $(use_clang)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
-LOCAL_CXX_STL := none
-LOCAL_SYSTEM_SHARED_LIBRARIES :=
-LOCAL_SANITIZE := never
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-
-include $(BUILD_STATIC_LIBRARY)
-
-
-# ========================================================
-# libc_aeabi.a
-# This is an LP32 ARM-only library that needs to be built with -fno-builtin
-# to avoid infinite recursion. For the other architectures we just build an
-# empty library to keep this makefile simple.
-# ========================================================
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES_arm := arch-arm/bionic/__aeabi.c
-LOCAL_MODULE := libc_aeabi
-LOCAL_CLANG := $(use_clang)
-LOCAL_CFLAGS := $(libc_common_cflags) -fno-builtin
-LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
-LOCAL_CXX_STL := none
-LOCAL_SYSTEM_SHARED_LIBRARIES :=
-LOCAL_SANITIZE := never
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-
-include $(BUILD_STATIC_LIBRARY)
-
-# ========================================================
-# libc_ndk.a
-# Compatibility library for the NDK. This library contains
-# all the parts of libc that are safe to statically link.
-# We can't safely statically link things that can only run
-# on a certain version of the OS. Examples include
-# anything that talks to netd (a large portion of the DNS
-# code) and anything that is dependent on the layout of a
-# data structure that has changed across releases (such as
-# pthread_t).
-# ========================================================
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := libc_ndk
-LOCAL_CLANG := $(use_clang)
-LOCAL_ASFLAGS := $(LOCAL_CFLAGS)
-LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
-LOCAL_CFLAGS := $(libc_common_cflags) -fvisibility=hidden -O0
-LOCAL_CPPFLAGS := $(libc_common_cppflags)
-LOCAL_C_INCLUDES := $(libc_common_c_includes)
-LOCAL_SANITIZE := never
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-LOCAL_SYSTEM_SHARED_LIBRARIES :=
-
-LOCAL_SRC_FILES := \
-    $(libc_common_src_files) \
-    $(libc_arch_dynamic_src_files) \
-    $(libc_ndk_stub_src_files) \
-    bionic/malloc_common.cpp \
-
-LOCAL_SRC_FILES_arm += \
-    arch-common/bionic/crtbegin_so.c \
-    arch-arm/bionic/atexit_legacy.c \
-    arch-common/bionic/crtend_so.S \
-
-LOCAL_CFLAGS := $(libc_common_cflags) \
-    -DLIBC_STATIC \
-
-LOCAL_WHOLE_STATIC_LIBRARIES := \
-    libc_bionic_ndk \
-    libc_cxa \
-    libc_freebsd \
-    libc_gdtoa \
-    libc_malloc \
-    libc_netbsd \
-    libc_openbsd_ndk \
-    libc_stack_protector \
-    libc_syscalls \
-    libc_tzcode \
-    libm \
-    libjemalloc \
-
-LOCAL_WHOLE_STATIC_LIBRARIES_arm := libc_aeabi
-LOCAL_CXX_STL := none
-
-$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
-$(eval $(call patch-up-arch-specific-flags,LOCAL_SRC_FILES,libc_common_src_files))
-$(eval $(call patch-up-arch-specific-flags,LOCAL_SRC_FILES,libc_arch_dynamic_src_files))
-$(eval $(call patch-up-arch-specific-flags,LOCAL_ASFLAGS,LOCAL_CFLAGS))
-
-LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
-include $(BUILD_STATIC_LIBRARY)
-
-# ========================================================
-# libc_common.a
-# ========================================================
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(libc_common_src_files)
-LOCAL_CFLAGS := $(libc_common_cflags)
-LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
-LOCAL_CPPFLAGS := $(libc_common_cppflags)
-LOCAL_C_INCLUDES := $(libc_common_c_includes)
-LOCAL_MODULE := libc_common
-LOCAL_CLANG := $(use_clang)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
-LOCAL_WHOLE_STATIC_LIBRARIES := \
-    libc_bionic \
-    libc_bionic_ndk \
-    libc_cxa \
-    libc_dns \
-    libc_freebsd \
-    libc_gdtoa \
-    libc_malloc \
-    libc_netbsd \
-    libc_openbsd \
-    libc_openbsd_ndk \
-    libc_pthread \
-    libc_stack_protector \
-    libc_syscalls \
-    libc_tzcode \
-
-LOCAL_WHOLE_STATIC_LIBRARIES_arm := libc_aeabi
-
-LOCAL_CXX_STL := none
-LOCAL_SYSTEM_SHARED_LIBRARIES :=
-
-# TODO: split out the asflags.
-LOCAL_ASFLAGS := $(LOCAL_CFLAGS)
-LOCAL_SANITIZE := never
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-
-$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
-$(eval $(call patch-up-arch-specific-flags,LOCAL_SRC_FILES,libc_common_src_files))
-$(eval $(call patch-up-arch-specific-flags,LOCAL_ASFLAGS,LOCAL_CFLAGS))
-include $(BUILD_STATIC_LIBRARY)
-
-
-# ========================================================
-# libc_nomalloc.a
-# ========================================================
-#
-# This is a version of the static C library that does not
-# include malloc. It's useful in situations when the user wants
-# to provide their own malloc implementation, or wants to
-# explicitly disallow the use of malloc, such as in the
-# dynamic linker.
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-    $(libc_arch_static_src_files) \
-
-LOCAL_C_INCLUDES := $(libc_common_c_includes)
-LOCAL_CFLAGS := $(libc_common_cflags) \
-    -DLIBC_STATIC \
-
-LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
-LOCAL_CPPFLAGS := $(libc_common_cppflags)
-
-LOCAL_MODULE := libc_nomalloc
-LOCAL_CLANG := $(use_clang)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
-LOCAL_WHOLE_STATIC_LIBRARIES := libc_common libc_init_static
-LOCAL_CXX_STL := none
-LOCAL_SYSTEM_SHARED_LIBRARIES :=
-LOCAL_SANITIZE := never
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-
-$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
-$(eval $(call patch-up-arch-specific-flags,LOCAL_SRC_FILES,libc_arch_static_src_files))
-include $(BUILD_STATIC_LIBRARY)
-
-
-# ========================================================
-# libc_malloc.a: the _prefixed_ malloc functions (like dlcalloc).
-# ========================================================
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := $(libc_malloc_src)
-LOCAL_CFLAGS := $(libc_common_cflags) \
-    -fvisibility=hidden \
-
-LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
-LOCAL_CPPFLAGS := $(libc_common_cppflags)
-LOCAL_C_INCLUDES := $(libc_common_c_includes)
-LOCAL_MODULE := libc_malloc
-LOCAL_CLANG := $(use_clang)
-LOCAL_CXX_STL := none
-LOCAL_SANITIZE := never
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
-include $(BUILD_STATIC_LIBRARY)
-
-
-# ========================================================
-# libc.a
-# ========================================================
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-    $(libc_arch_static_src_files) \
-    bionic/malloc_common.cpp \
-    bionic/libc_init_static.cpp \
-
-LOCAL_CFLAGS := $(libc_common_cflags) \
-    -DLIBC_STATIC \
-
-LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
-LOCAL_CPPFLAGS := $(libc_common_cppflags)
-LOCAL_C_INCLUDES := $(libc_common_c_includes)
-LOCAL_MODULE := libc
-LOCAL_CLANG := $(use_clang)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
-LOCAL_WHOLE_STATIC_LIBRARIES := libc_common libc_init_static libjemalloc
-
-LOCAL_CXX_STL := none
-LOCAL_SYSTEM_SHARED_LIBRARIES :=
-LOCAL_SANITIZE := never
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-
-$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
-$(eval $(call patch-up-arch-specific-flags,LOCAL_SRC_FILES,libc_arch_static_src_files))
-include $(BUILD_STATIC_LIBRARY)
-
-
-# ========================================================
-# libc.so
-# ========================================================
-include $(CLEAR_VARS)
-
-LOCAL_CFLAGS := $(libc_common_cflags)
-LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
-LOCAL_CPPFLAGS := $(libc_common_cppflags)
-
-LOCAL_C_INCLUDES := $(libc_common_c_includes)
-LOCAL_SRC_FILES := \
-    arch-common/bionic/crtbegin_so.c \
-    arch-common/bionic/crtbrand.S \
-    $(libc_arch_dynamic_src_files) \
-    bionic/malloc_common.cpp \
-    bionic/libc_init_dynamic.cpp \
-    bionic/NetdClient.cpp \
-    arch-common/bionic/crtend_so.S \
-
-LOCAL_MODULE := libc
-LOCAL_CLANG := $(use_clang)
-LOCAL_REQUIRED_MODULES := tzdata
-LOCAL_ADDITIONAL_DEPENDENCIES := \
-    $(libc_common_additional_dependencies) \
-    $(LOCAL_PATH)/libc.arm.map \
-    $(LOCAL_PATH)/libc.arm64.map \
-    $(LOCAL_PATH)/libc.mips.map \
-    $(LOCAL_PATH)/libc.mips64.map \
-    $(LOCAL_PATH)/libc.x86.map \
-    $(LOCAL_PATH)/libc.x86_64.map \
-    $(LOCAL_PATH)/libc.arm.brillo.map \
-    $(LOCAL_PATH)/libc.mips.brillo.map \
-    $(LOCAL_PATH)/libc.x86.brillo.map \
-
-# Leave the symbols in the shared library so that stack unwinders can produce
-# meaningful name resolution.
-LOCAL_STRIP_MODULE := keep_symbols
-
-# Do not pack libc.so relocations; see http://b/20645321 for details.
-LOCAL_PACK_MODULE_RELOCATIONS := false
-
-# WARNING: The only library libc.so should depend on is libdl.so!  If you add other libraries,
-# make sure to add -Wl,--exclude-libs=libgcc.a to the LOCAL_LDFLAGS for those libraries.  This
-# ensures that symbols that are pulled into those new libraries from libgcc.a are not declared
-# external; if that were the case, then libc would not pull those symbols from libgcc.a as it
-# should, instead relying on the external symbols from the dependent libraries.  That would
-# create a "cloaked" dependency on libgcc.a in libc though the libraries, which is not what
-# you wanted!
-
-LOCAL_SHARED_LIBRARIES := libdl
-LOCAL_WHOLE_STATIC_LIBRARIES := libc_common libjemalloc
-
-LOCAL_CXX_STL := none
-LOCAL_SYSTEM_SHARED_LIBRARIES :=
-
-# TODO: This is to work around b/24465209. Remove after root cause is fixed
-LOCAL_LDFLAGS_arm := -Wl,--hash-style=both
-LOCAL_LDFLAGS_x86 := -Wl,--hash-style=both
-
-# Don't re-export new/delete and friends, even if the compiler really wants to.
-ifdef BRILLO
-LOCAL_LDFLAGS_arm    += -Wl,--version-script,$(LOCAL_PATH)/libc.arm.brillo.map
-LOCAL_LDFLAGS_mips   += -Wl,--version-script,$(LOCAL_PATH)/libc.mips.brillo.map
-LOCAL_LDFLAGS_x86    += -Wl,--version-script,$(LOCAL_PATH)/libc.x86.brillo.map
-else
-LOCAL_LDFLAGS_arm    += -Wl,--version-script,$(LOCAL_PATH)/libc.arm.map
-LOCAL_LDFLAGS_mips   += -Wl,--version-script,$(LOCAL_PATH)/libc.mips.map
-LOCAL_LDFLAGS_x86    += -Wl,--version-script,$(LOCAL_PATH)/libc.x86.map
-endif
-
-LOCAL_LDFLAGS_arm64  += -Wl,--version-script,$(LOCAL_PATH)/libc.arm64.map
-LOCAL_LDFLAGS_mips64 += -Wl,--version-script,$(LOCAL_PATH)/libc.mips64.map
-LOCAL_LDFLAGS_x86_64 += -Wl,--version-script,$(LOCAL_PATH)/libc.x86_64.map
-
-# We'd really like to do this for all architectures, but since this wasn't done
-# before, these symbols must continue to be exported on LP32 for binary
-# compatibility.
-LOCAL_LDFLAGS_64 := -Wl,--exclude-libs,libgcc.a
-
-# Unfortunately --exclude-libs clobbers our version script, so we have to
-# prevent the build system from using this flag.
-LOCAL_NO_EXCLUDE_LIBS := true
-
-$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
-$(eval $(call patch-up-arch-specific-flags,LOCAL_SRC_FILES,libc_arch_dynamic_src_files))
-
-LOCAL_NO_CRT := true
-LOCAL_ASFLAGS += $(libc_crt_target_cflags)
-
-# special for arm
-LOCAL_CFLAGS_arm += -DCRT_LEGACY_WORKAROUND
-LOCAL_SRC_FILES_arm += \
-    arch-arm/bionic/atexit_legacy.c
-
-LOCAL_SANITIZE := never
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-
-include $(BUILD_SHARED_LIBRARY)
-
-# ========================================================
-# libc_logging.a
-# ========================================================
-include $(CLEAR_VARS)
-
-LOCAL_CFLAGS := $(libc_common_cflags)
-LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
-LOCAL_CPPFLAGS := $(libc_common_cppflags)
-LOCAL_C_INCLUDES := $(libc_common_c_includes)
-
-LOCAL_SRC_FILES := \
-    bionic/libc_logging.cpp \
-
-LOCAL_MODULE := libc_logging
-
-LOCAL_CLANG := $(use_clang)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
-LOCAL_SYSTEM_SHARED_LIBRARIES :=
-
-LOCAL_SANITIZE := never
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-
-$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
-include $(BUILD_STATIC_LIBRARY)
-
-# ========================================================
-# libstdc++.so
-# ========================================================
-libstdcxx_common_src_files := \
-    bionic/__cxa_guard.cpp \
-    bionic/__cxa_pure_virtual.cpp \
-    bionic/new.cpp \
-
-include $(CLEAR_VARS)
-LOCAL_C_INCLUDES := $(libc_common_c_includes) bionic/libstdc++/include
-LOCAL_CFLAGS := $(libc_common_cflags)
-LOCAL_CPPFLAGS := $(libc_common_cppflags)
-
-# TODO: This is to work around b/24465209. Remove after root cause is fixed
-LOCAL_LDFLAGS_arm := -Wl,--hash-style=both
-LOCAL_LDFLAGS_x86 := -Wl,--hash-style=both
-
-LOCAL_SRC_FILES := $(libstdcxx_common_src_files)
-LOCAL_MODULE:= libstdc++
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-LOCAL_CXX_STL := none
-LOCAL_SYSTEM_SHARED_LIBRARIES := libc
-LOCAL_STATIC_LIBRARIES := libc_logging
-LOCAL_SANITIZE := never
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-include $(BUILD_SHARED_LIBRARY)
+include $(call all-makefiles-under,$(LOCAL_PATH))
 
-# ========================================================
-# libstdc++.a
-# ========================================================
-include $(CLEAR_VARS)
-LOCAL_C_INCLUDES := $(libc_common_c_includes) bionic/libstdc++/include
-LOCAL_CFLAGS := $(libc_common_cflags)
-LOCAL_CPPFLAGS := $(libc_common_cppflags)
-LOCAL_SRC_FILES := $(libstdcxx_common_src_files)
-LOCAL_MODULE:= libstdc++
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-LOCAL_CXX_STL := none
-LOCAL_SYSTEM_SHARED_LIBRARIES := libc
-LOCAL_SANITIZE := never
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-include $(BUILD_STATIC_LIBRARY)
diff --git a/libc/NOTICE b/libc/NOTICE
index 2121246..735b6c4 100644
--- a/libc/NOTICE
+++ b/libc/NOTICE
@@ -1457,23 +1457,6 @@
 Copyright (c) 1989 The Regents of the University of California.
 All rights reserved.
 
-Redistribution and use in source and binary forms are permitted
-provided that the above copyright notice and this paragraph are
-duplicated in all such forms and that any documentation,
-advertising materials, and other materials related to such
-distribution and use acknowledge that the software was developed
-by the University of California, Berkeley. The name of the
-University may not be used to endorse or promote products derived
-from this software without specific prior written permission.
-THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
-IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-
--------------------------------------------------------------------
-
-Copyright (c) 1989 The Regents of the University of California.
-All rights reserved.
-
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
@@ -1658,35 +1641,6 @@
 
 -------------------------------------------------------------------
 
-Copyright (c) 1989, 1993, 1994
-   The Regents of the University of California.  All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. 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.
-3. Neither the name of the University nor the names of its contributors
-   may be used to endorse or promote products derived from this software
-   without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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) 1990 Regents of the University of California.
 All rights reserved.
 
@@ -1751,37 +1705,6 @@
 Copyright (c) 1990 The Regents of the University of California.
 All rights reserved.
 
-This code is derived from locore.s.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. 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.
-3. Neither the name of the University nor the names of its contributors
-   may be used to endorse or promote products derived from this software
-   without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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) 1990 The Regents of the University of California.
-All rights reserved.
-
 This code is derived from software contributed to Berkeley by
 Chris Torek.
 
@@ -3036,42 +2959,6 @@
 All rights reserved.
 
 This code is derived from software contributed to The NetBSD Foundation
-by Atsushi Onoe.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. 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.
-3. All advertising materials mentioning features or use of this software
-   must display the following acknowledgement:
-   This product includes software developed by the NetBSD
-   Foundation, Inc. and its contributors.
-4. Neither the name of The NetBSD Foundation nor the names of its
-   contributors may be used to endorse or promote products derived
-   from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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) 2000 The NetBSD Foundation, Inc.
-All rights reserved.
-
-This code is derived from software contributed to The NetBSD Foundation
 by Dieter Baron and Thomas Klausner.
 
 Redistribution and use in source and binary forms, with or without
@@ -3185,6 +3072,32 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2001-2011 The FreeBSD 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:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. 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 AUTHOR 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 AUTHOR 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) 2002 Daniel Hartmeier
 All rights reserved.
 
@@ -3524,6 +3437,26 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2003, 2004 Todd C. Miller <Todd.Miller@courtesan.com>
+
+Permission to use, copy, modify, and distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+Sponsored in part by the Defense Advanced Research Projects
+Agency (DARPA) and Air Force Research Laboratory, Air Force
+Materiel Command, USAF, under agreement number F39502-99-1-0512.
+
+-------------------------------------------------------------------
+
 Copyright (c) 2004 The NetBSD Foundation, Inc.
 All rights reserved.
 
@@ -3739,6 +3672,58 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2004-2005 David Schultz <das (at) FreeBSD.ORG>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. 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 AUTHOR 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 AUTHOR 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) 2004-2005 David Schultz <das@FreeBSD.ORG>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. 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 AUTHOR 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 AUTHOR 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) 2005 Tim J. Robbins.
 All rights reserved.
 
@@ -4051,6 +4036,32 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2010 The NetBSD Foundation, Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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) 2010 Todd C. Miller <Todd.Miller@courtesan.com>
 
 Permission to use, copy, modify, and distribute this software for any
@@ -4787,6 +4798,34 @@
 
 -------------------------------------------------------------------
 
+Copyright 1989 The Regents of the University of California.
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+   1. Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+   2. 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.
+   3. Neither the name of the University nor the names of its contributors
+      may be used to endorse or promote products derived from this software
+      without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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
+
+-------------------------------------------------------------------
+
 Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
 Copyright 2008 Damien Miller <djm@openbsd.org>
 All rights reserved.
diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT
index d5dd206..5188b6d 100644
--- a/libc/SYSCALLS.TXT
+++ b/libc/SYSCALLS.TXT
@@ -232,7 +232,7 @@
 int     __rt_sigpending:rt_sigpending(sigset_t*, size_t)  all
 int     __rt_sigprocmask:rt_sigprocmask(int, const sigset_t*, sigset_t*, size_t)  all
 int     __rt_sigsuspend:rt_sigsuspend(const sigset_t*, size_t)  all
-int     __rt_sigtimedwait:rt_sigtimedwait(const sigset_t*, struct siginfo_t*, struct timespec_t*, size_t)  all
+int     __rt_sigtimedwait:rt_sigtimedwait(const sigset_t*, siginfo_t*, const timespec*, size_t)  all
 int     ___rt_sigqueueinfo:rt_sigqueueinfo(pid_t, int, siginfo_t*)  all
 int     __signalfd4:signalfd4(int, const sigset_t*, size_t, int)  all
 
@@ -322,13 +322,19 @@
 ssize_t process_vm_readv(pid_t, const struct iovec*, unsigned long, const struct iovec*, unsigned long, unsigned long)  all
 ssize_t process_vm_writev(pid_t, const struct iovec*, unsigned long, const struct iovec*, unsigned long, unsigned long)  all
 
+int quotactl(int, const char*, int, char*)  all
+
 int __set_tid_address:set_tid_address(int*)  all
 
 int setfsgid(gid_t)  all
 int setfsuid(uid_t)  all
 
+int setdomainname(const char*, size_t)  all
 int sethostname(const char*, size_t)  all
 
+int __sync_file_range:sync_file_range(int, off64_t, off64_t, unsigned int) arm64,mips,mips64,x86,x86_64
+int __sync_file_range2:sync_file_range2(int, unsigned int, off64_t, off64_t) arm
+
 pid_t wait4(pid_t, int*, int, struct rusage*)  all
 int __waitid:waitid(int, pid_t, struct siginfo_t*, int, void*)  all
 
@@ -344,7 +350,7 @@
 int     __set_thread_area:set_thread_area(void*) x86
 
 # vdso stuff.
-int clock_gettime(clockid_t, timespec*)                 arm,mips,mips64
-int __clock_gettime:clock_gettime(clockid_t, timespec*) arm64,x86,x86_64
-int gettimeofday(timeval*, timezone*)                   arm,mips,mips64
-int __gettimeofday:gettimeofday(timeval*, timezone*)    arm64,x86,x86_64
+int clock_gettime(clockid_t, timespec*)                 mips,mips64
+int __clock_gettime:clock_gettime(clockid_t, timespec*) arm,arm64,x86,x86_64
+int gettimeofday(timeval*, timezone*)                   mips,mips64
+int __gettimeofday:gettimeofday(timeval*, timezone*)    arm,arm64,x86,x86_64
diff --git a/libc/arch-arm/arm.mk b/libc/arch-arm/arm.mk
deleted file mode 100644
index 76f465e..0000000
--- a/libc/arch-arm/arm.mk
+++ /dev/null
@@ -1,63 +0,0 @@
-# 32-bit arm.
-
-libc_bionic_src_files_arm += \
-    arch-arm/generic/bionic/memcmp.S \
-    arch-arm/generic/bionic/memcpy.S \
-    arch-arm/generic/bionic/memset.S \
-    arch-arm/generic/bionic/strcmp.S \
-    arch-arm/generic/bionic/strcpy.S \
-    arch-arm/generic/bionic/strlen.c \
-
-libc_bionic_src_files_exclude_arm += \
-    bionic/__memcpy_chk.cpp \
-    bionic/__memset_chk.cpp \
-
-libc_openbsd_src_files_exclude_arm += \
-    upstream-openbsd/lib/libc/string/strcpy.c \
-
-#
-# Inherently architecture-specific code.
-#
-
-libc_bionic_src_files_arm += \
-    arch-arm/bionic/abort_arm.S \
-    arch-arm/bionic/atomics_arm.c \
-    arch-arm/bionic/__bionic_clone.S \
-    arch-arm/bionic/_exit_with_stack_teardown.S \
-    arch-arm/bionic/libgcc_compat.c \
-    arch-arm/bionic/popcount_tab.c \
-    arch-arm/bionic/__restore.S \
-    arch-arm/bionic/setjmp.S \
-    arch-arm/bionic/syscall.S \
-    arch-arm/bionic/vfork.S \
-
-libc_arch_static_src_files_arm := arch-arm/bionic/exidx_static.c
-libc_arch_dynamic_src_files_arm := arch-arm/bionic/exidx_dynamic.c
-
-## CPU variant specific source files
-ifeq ($(strip $(TARGET_$(my_2nd_arch_prefix)CPU_VARIANT)),)
-  $(warning TARGET_$(my_2nd_arch_prefix)ARCH is arm, but TARGET_$(my_2nd_arch_prefix)CPU_VARIANT is not defined)
-endif
-ifneq ($(TARGET_$(my_2nd_arch_prefix)CPU_VARIANT),generic)
-cpu_variant_mk := $(LOCAL_PATH)/arch-arm/$(TARGET_$(my_2nd_arch_prefix)CPU_VARIANT)/$(TARGET_$(my_2nd_arch_prefix)CPU_VARIANT).mk
-ifeq ($(wildcard $(cpu_variant_mk)),)
-$(error "TARGET_$(my_2nd_arch_prefix)CPU_VARIANT not set or set to an unknown value. Possible values are cortex-a7, cortex-a8, cortex-a9, cortex-a15, krait, denver. Use generic for devices that do not have a CPU similar to any of the supported cpu variants.")
-endif
-include $(cpu_variant_mk)
-libc_common_additional_dependencies += $(cpu_variant_mk)
-
-cpu_variant_mk :=
-endif
-
-
-libc_crt_target_cflags_arm := \
-    -I$(LOCAL_PATH)/arch-arm/include \
-    -mthumb-interwork
-
-libc_crt_target_so_cflags_arm :=
-
-libc_crt_target_crtbegin_file_arm := \
-    $(LOCAL_PATH)/arch-common/bionic/crtbegin.c
-
-libc_crt_target_crtbegin_so_file_arm := \
-    $(LOCAL_PATH)/arch-common/bionic/crtbegin_so.c
diff --git a/libc/arch-arm/bionic/libgcc_compat.c b/libc/arch-arm/bionic/libgcc_compat.c
index 10faf2d..abd1422 100644
--- a/libc/arch-arm/bionic/libgcc_compat.c
+++ b/libc/arch-arm/bionic/libgcc_compat.c
@@ -1,4 +1,30 @@
-/* Generated by genlibgcc_compat.py */
+/*
+ * Copyright (C) 2016 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.
+ */
 
 extern char __adddf3;
 extern char __addsf3;
diff --git a/libc/arch-arm/cortex-a15/bionic/__strcat_chk_common.S b/libc/arch-arm/cortex-a15/bionic/__strcat_chk_common.S
index de66967..a610dd5 100644
--- a/libc/arch-arm/cortex-a15/bionic/__strcat_chk_common.S
+++ b/libc/arch-arm/cortex-a15/bionic/__strcat_chk_common.S
@@ -27,7 +27,6 @@
  */
 
 #include <private/bionic_asm.h>
-#include <private/libc_events.h>
 
     .syntax unified
 
@@ -177,7 +176,9 @@
 .L_strlen_done:
     add     r2, r3, r4
     cmp     r2, lr
-    bhi     .L_strcat_chk_failed
+    itt     hi
+    movhi   r0, lr
+    bhi     __strcat_chk_fail
 
     // Set up the registers for the memcpy code.
     mov     r1, r5
@@ -195,18 +196,4 @@
     .cfi_adjust_cfa_offset 8
     .cfi_rel_offset r4, 0
     .cfi_rel_offset r5, 4
-.L_strcat_chk_failed:
-    ldr     r0, error_message
-    ldr     r1, error_code
-1:
-    add     r0, pc
-    bl      __fortify_chk_fail
-error_code:
-    .word   BIONIC_EVENT_STRCAT_BUFFER_OVERFLOW
-error_message:
-    .word   error_string-(1b+4)
 END(__strcat_chk)
-
-    .data
-error_string:
-    .string "strcat: prevented write past end of buffer"
diff --git a/libc/arch-arm/cortex-a15/bionic/__strcpy_chk_common.S b/libc/arch-arm/cortex-a15/bionic/__strcpy_chk_common.S
index 69ebcb4..377e720 100644
--- a/libc/arch-arm/cortex-a15/bionic/__strcpy_chk_common.S
+++ b/libc/arch-arm/cortex-a15/bionic/__strcpy_chk_common.S
@@ -27,7 +27,6 @@
  */
 
 #include <private/bionic_asm.h>
-#include <private/libc_events.h>
 
     .syntax unified
 
@@ -148,26 +147,15 @@
     pld     [r1, #0]
     pld     [r1, #64]
     ldr     r0, [sp]
-    cmp     r3, lr
-    bhs     .L_strcpy_chk_failed
 
     // Add 1 for copy length to get the string terminator.
     add     r2, r3, #1
 
+    cmp     r2, lr
+    itt     hi
+    movhi   r0, r2
+    bhi     __strcpy_chk_fail
+
 #include MEMCPY_BASE
 
-.L_strcpy_chk_failed:
-    ldr     r0, error_message
-    ldr     r1, error_code
-1:
-    add     r0, pc
-    bl      __fortify_chk_fail
-error_code:
-    .word   BIONIC_EVENT_STRCPY_BUFFER_OVERFLOW
-error_message:
-    .word   error_string-(1b+4)
 END(__strcpy_chk)
-
-    .data
-error_string:
-    .string "strcpy: prevented write past end of buffer"
diff --git a/libc/arch-arm/cortex-a15/bionic/memcpy_common.S b/libc/arch-arm/cortex-a15/bionic/memcpy_common.S
index 464fb46..4d1167f 100644
--- a/libc/arch-arm/cortex-a15/bionic/memcpy_common.S
+++ b/libc/arch-arm/cortex-a15/bionic/memcpy_common.S
@@ -54,17 +54,20 @@
  */
 
 #include <private/bionic_asm.h>
-#include <private/libc_events.h>
 
         .text
         .syntax unified
         .fpu    neon
 
 ENTRY(__memcpy_chk)
-        cmp     r2, r3
-        bhi     .L_memcpy_chk_fail
+        cmp r2, r3
+        bls memcpy
 
-        // Fall through to memcpy...
+        // Preserve lr for backtrace.
+        push        {lr}
+        .cfi_def_cfa_offset 4
+        .cfi_rel_offset lr, 0
+        bl          __memcpy_chk_fail
 END(__memcpy_chk)
 
 // Prototype: void *memcpy (void *dst, const void *src, size_t count).
@@ -76,28 +79,4 @@
         .cfi_rel_offset lr, 4
 
 #include MEMCPY_BASE
-
-        // Undo the cfi instructions from above.
-        .cfi_def_cfa_offset 0
-        .cfi_restore r0
-        .cfi_restore lr
-.L_memcpy_chk_fail:
-        // Preserve lr for backtrace.
-        push    {lr}
-        .cfi_adjust_cfa_offset 4
-        .cfi_rel_offset lr, 0
-
-        ldr     r0, error_message
-        ldr     r1, error_code
-1:
-        add     r0, pc
-        bl      __fortify_chk_fail
-error_code:
-        .word   BIONIC_EVENT_MEMCPY_BUFFER_OVERFLOW
-error_message:
-        .word   error_string-(1b+8)
 END(memcpy)
-
-        .data
-error_string:
-        .string "memcpy: prevented write past end of buffer"
diff --git a/libc/arch-arm/cortex-a15/bionic/memset.S b/libc/arch-arm/cortex-a15/bionic/memset.S
index e4a1ec8..2542f3f 100644
--- a/libc/arch-arm/cortex-a15/bionic/memset.S
+++ b/libc/arch-arm/cortex-a15/bionic/memset.S
@@ -26,9 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/cpu-features.h>
 #include <private/bionic_asm.h>
-#include <private/libc_events.h>
 
         /*
          * Optimized memset() for ARM.
@@ -41,31 +39,16 @@
 
 ENTRY(__memset_chk)
         cmp         r2, r3
-        bls         .L_done
+        bls         memset
 
         // Preserve lr for backtrace.
         push        {lr}
         .cfi_def_cfa_offset 4
         .cfi_rel_offset lr, 0
 
-        ldr         r0, error_message
-        ldr         r1, error_code
-1:
-        add         r0, pc
-        bl          __fortify_chk_fail
-error_code:
-        .word       BIONIC_EVENT_MEMSET_BUFFER_OVERFLOW
-error_message:
-        .word       error_string-(1b+8)
+        bl          __memset_chk_fail
 END(__memset_chk)
 
-ENTRY(bzero)
-        mov         r2, r1
-        mov         r1, #0
-.L_done:
-        // Fall through to memset...
-END(bzero)
-
 ENTRY(memset)
         stmfd       sp!, {r0}
         .cfi_def_cfa_offset 4
@@ -185,7 +168,3 @@
         ldmfd       sp!, {r0}
         bx          lr
 END(memset)
-
-        .data
-error_string:
-        .string     "memset: prevented write past end of buffer"
diff --git a/libc/arch-arm/cortex-a15/bionic/strcmp.S b/libc/arch-arm/cortex-a15/bionic/strcmp.S
index acedf0e..5c8914b 100644
--- a/libc/arch-arm/cortex-a15/bionic/strcmp.S
+++ b/libc/arch-arm/cortex-a15/bionic/strcmp.S
@@ -26,7 +26,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <machine/cpu-features.h>
 #include <private/bionic_asm.h>
 
 #ifdef __ARMEB__
diff --git a/libc/arch-arm/cortex-a15/cortex-a15.mk b/libc/arch-arm/cortex-a15/cortex-a15.mk
deleted file mode 100644
index 20202a7..0000000
--- a/libc/arch-arm/cortex-a15/cortex-a15.mk
+++ /dev/null
@@ -1,27 +0,0 @@
-libc_openbsd_src_files_exclude_arm += \
-    upstream-openbsd/lib/libc/string/memmove.c \
-    upstream-openbsd/lib/libc/string/stpcpy.c \
-    upstream-openbsd/lib/libc/string/strcat.c \
-
-libc_bionic_src_files_exclude_arm += \
-    arch-arm/generic/bionic/memcpy.S \
-    arch-arm/generic/bionic/memset.S \
-    arch-arm/generic/bionic/strcmp.S \
-    arch-arm/generic/bionic/strcpy.S \
-    arch-arm/generic/bionic/strlen.c \
-    bionic/__strcat_chk.cpp \
-    bionic/__strcpy_chk.cpp \
-
-libc_bionic_src_files_arm += \
-    arch-arm/cortex-a15/bionic/memcpy.S \
-    arch-arm/cortex-a15/bionic/memset.S \
-    arch-arm/cortex-a15/bionic/stpcpy.S \
-    arch-arm/cortex-a15/bionic/strcat.S \
-    arch-arm/cortex-a15/bionic/__strcat_chk.S \
-    arch-arm/cortex-a15/bionic/strcmp.S \
-    arch-arm/cortex-a15/bionic/strcpy.S \
-    arch-arm/cortex-a15/bionic/__strcpy_chk.S \
-    arch-arm/cortex-a15/bionic/strlen.S \
-
-libc_bionic_src_files_arm += \
-    arch-arm/denver/bionic/memmove.S \
diff --git a/libc/arch-arm/cortex-a53.a57/cortex-a53.a57.mk b/libc/arch-arm/cortex-a53.a57/cortex-a53.a57.mk
deleted file mode 100644
index 6455d04..0000000
--- a/libc/arch-arm/cortex-a53.a57/cortex-a53.a57.mk
+++ /dev/null
@@ -1,32 +0,0 @@
-# This file represents the best optimized routines that are the middle
-# ground when running on a big/little system that is cortex-a57/cortex-a53.
-# The cortex-a7 optimized routines, and the cortex-a53 optimized routines
-# decrease performance on cortex-a57 processors by as much as 20%.
-
-libc_openbsd_src_files_exclude_arm += \
-    upstream-openbsd/lib/libc/string/memmove.c \
-    upstream-openbsd/lib/libc/string/stpcpy.c \
-    upstream-openbsd/lib/libc/string/strcat.c \
-
-libc_bionic_src_files_exclude_arm += \
-    arch-arm/generic/bionic/memcpy.S \
-    arch-arm/generic/bionic/memset.S \
-    arch-arm/generic/bionic/strcmp.S \
-    arch-arm/generic/bionic/strcpy.S \
-    arch-arm/generic/bionic/strlen.c \
-    bionic/__strcat_chk.cpp \
-    bionic/__strcpy_chk.cpp \
-
-libc_bionic_src_files_arm += \
-    arch-arm/cortex-a15/bionic/memcpy.S \
-    arch-arm/cortex-a15/bionic/memset.S \
-    arch-arm/cortex-a15/bionic/stpcpy.S \
-    arch-arm/cortex-a15/bionic/strcat.S \
-    arch-arm/cortex-a15/bionic/__strcat_chk.S \
-    arch-arm/cortex-a15/bionic/strcmp.S \
-    arch-arm/cortex-a15/bionic/strcpy.S \
-    arch-arm/cortex-a15/bionic/__strcpy_chk.S \
-    arch-arm/cortex-a15/bionic/strlen.S \
-
-libc_bionic_src_files_arm += \
-    arch-arm/denver/bionic/memmove.S \
diff --git a/libc/arch-arm/cortex-a53/cortex-a53.mk b/libc/arch-arm/cortex-a53/cortex-a53.mk
deleted file mode 100644
index 9b431ae..0000000
--- a/libc/arch-arm/cortex-a53/cortex-a53.mk
+++ /dev/null
@@ -1,31 +0,0 @@
-libc_openbsd_src_files_exclude_arm += \
-    upstream-openbsd/lib/libc/string/memmove.c \
-    upstream-openbsd/lib/libc/string/stpcpy.c \
-    upstream-openbsd/lib/libc/string/strcat.c \
-
-libc_bionic_src_files_exclude_arm += \
-    arch-arm/generic/bionic/memcpy.S \
-    arch-arm/generic/bionic/memset.S \
-    arch-arm/generic/bionic/strcmp.S \
-    arch-arm/generic/bionic/strcpy.S \
-    arch-arm/generic/bionic/strlen.c \
-    bionic/__strcat_chk.cpp \
-    bionic/__strcpy_chk.cpp \
-
-libc_bionic_src_files_arm += \
-    arch-arm/cortex-a53/bionic/memcpy.S \
-    arch-arm/cortex-a53/bionic/__strcat_chk.S \
-    arch-arm/cortex-a53/bionic/__strcpy_chk.S \
-
-libc_bionic_src_files_arm += \
-    arch-arm/cortex-a7/bionic/memset.S \
-
-libc_bionic_src_files_arm += \
-    arch-arm/cortex-a15/bionic/stpcpy.S \
-    arch-arm/cortex-a15/bionic/strcat.S \
-    arch-arm/cortex-a15/bionic/strcmp.S \
-    arch-arm/cortex-a15/bionic/strcpy.S \
-    arch-arm/cortex-a15/bionic/strlen.S \
-
-libc_bionic_src_files_arm += \
-    arch-arm/denver/bionic/memmove.S \
diff --git a/libc/arch-arm/cortex-a7/bionic/memset.S b/libc/arch-arm/cortex-a7/bionic/memset.S
index 6365b06..e4fb1b4 100644
--- a/libc/arch-arm/cortex-a7/bionic/memset.S
+++ b/libc/arch-arm/cortex-a7/bionic/memset.S
@@ -26,9 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/cpu-features.h>
 #include <private/bionic_asm.h>
-#include <private/libc_events.h>
 
         /*
          * Optimized memset() for ARM.
@@ -41,31 +39,16 @@
 
 ENTRY(__memset_chk)
         cmp         r2, r3
-        bls         .L_done
+        bls         memset
 
         // Preserve lr for backtrace.
         push        {lr}
         .cfi_def_cfa_offset 4
         .cfi_rel_offset lr, 0
 
-        ldr         r0, error_message
-        ldr         r1, error_code
-1:
-        add         r0, pc
-        bl          __fortify_chk_fail
-error_code:
-        .word       BIONIC_EVENT_MEMSET_BUFFER_OVERFLOW
-error_message:
-        .word       error_string-(1b+8)
+        bl          __memset_chk_fail
 END(__memset_chk)
 
-ENTRY(bzero)
-        mov         r2, r1
-        mov         r1, #0
-.L_done:
-        // Fall through to memset...
-END(bzero)
-
 ENTRY(memset)
         mov         r3, r0
         // At this point only d0, d1 are going to be used below.
@@ -174,7 +157,3 @@
         strbcs      r1, [r3], #1
         bx          lr
 END(memset)
-
-        .data
-error_string:
-        .string     "memset: prevented write past end of buffer"
diff --git a/libc/arch-arm/cortex-a7/cortex-a7.mk b/libc/arch-arm/cortex-a7/cortex-a7.mk
deleted file mode 100644
index f570d0f..0000000
--- a/libc/arch-arm/cortex-a7/cortex-a7.mk
+++ /dev/null
@@ -1,29 +0,0 @@
-libc_openbsd_src_files_exclude_arm += \
-    upstream-openbsd/lib/libc/string/memmove.c \
-    upstream-openbsd/lib/libc/string/stpcpy.c \
-    upstream-openbsd/lib/libc/string/strcat.c \
-
-libc_bionic_src_files_exclude_arm += \
-    arch-arm/generic/bionic/memcpy.S \
-    arch-arm/generic/bionic/memset.S \
-    arch-arm/generic/bionic/strcmp.S \
-    arch-arm/generic/bionic/strcpy.S \
-    arch-arm/generic/bionic/strlen.c \
-    bionic/__strcat_chk.cpp \
-    bionic/__strcpy_chk.cpp \
-
-libc_bionic_src_files_arm += \
-    arch-arm/cortex-a7/bionic/memset.S \
-
-libc_bionic_src_files_arm += \
-    arch-arm/cortex-a15/bionic/memcpy.S \
-    arch-arm/cortex-a15/bionic/stpcpy.S \
-    arch-arm/cortex-a15/bionic/strcat.S \
-    arch-arm/cortex-a15/bionic/__strcat_chk.S \
-    arch-arm/cortex-a15/bionic/strcmp.S \
-    arch-arm/cortex-a15/bionic/strcpy.S \
-    arch-arm/cortex-a15/bionic/__strcpy_chk.S \
-    arch-arm/cortex-a15/bionic/strlen.S \
-
-libc_bionic_src_files_arm += \
-    arch-arm/denver/bionic/memmove.S \
diff --git a/libc/arch-arm/cortex-a8/cortex-a8.mk b/libc/arch-arm/cortex-a8/cortex-a8.mk
deleted file mode 100644
index 9af03d9..0000000
--- a/libc/arch-arm/cortex-a8/cortex-a8.mk
+++ /dev/null
@@ -1 +0,0 @@
-include bionic/libc/arch-arm/cortex-a15/cortex-a15.mk
diff --git a/libc/arch-arm/cortex-a9/bionic/__strcat_chk.S b/libc/arch-arm/cortex-a9/bionic/__strcat_chk.S
index 45517f1..776c782 100644
--- a/libc/arch-arm/cortex-a9/bionic/__strcat_chk.S
+++ b/libc/arch-arm/cortex-a9/bionic/__strcat_chk.S
@@ -27,7 +27,6 @@
  */
 
 #include <private/bionic_asm.h>
-#include <private/libc_events.h>
 
     .syntax unified
     .fpu    neon
@@ -180,6 +179,8 @@
 .L_strlen_done:
     add     r2, r3, r4
     cmp     r2, lr
+    itt     hi
+    movhi   r0, lr
     bhi     __strcat_chk_fail
 
     // Set up the registers for the memcpy code.
@@ -195,26 +196,3 @@
 #define MEMCPY_BASE         __strcat_chk_memcpy_base
 #define MEMCPY_BASE_ALIGNED __strcat_chk_memcpy_base_aligned
 #include "memcpy_base.S"
-
-ENTRY_PRIVATE(__strcat_chk_fail)
-    .cfi_def_cfa_offset 8
-    .cfi_rel_offset r0, 0
-    .cfi_rel_offset lr, 4
-    .cfi_adjust_cfa_offset 8
-    .cfi_rel_offset r4, 0
-    .cfi_rel_offset r5, 4
-
-    ldr     r0, error_message
-    ldr     r1, error_code
-1:
-    add     r0, pc
-    bl      __fortify_chk_fail
-error_code:
-    .word   BIONIC_EVENT_STRCAT_BUFFER_OVERFLOW
-error_message:
-    .word   error_string-(1b+4)
-END(__strcat_chk_fail)
-
-    .data
-error_string:
-    .string "strcat: prevented write past end of buffer"
diff --git a/libc/arch-arm/cortex-a9/bionic/__strcpy_chk.S b/libc/arch-arm/cortex-a9/bionic/__strcpy_chk.S
index 67eca08..1d5e70b 100644
--- a/libc/arch-arm/cortex-a9/bionic/__strcpy_chk.S
+++ b/libc/arch-arm/cortex-a9/bionic/__strcpy_chk.S
@@ -27,7 +27,6 @@
  */
 
 #include <private/bionic_asm.h>
-#include <private/libc_events.h>
 
     .syntax unified
     .fpu    neon
@@ -150,36 +149,18 @@
     pld     [r1, #0]
     pld     [r1, #64]
     ldr     r0, [sp]
-    cmp     r3, lr
-    bhs     __strcpy_chk_fail
 
     // Add 1 for copy length to get the string terminator.
     add     r2, r3, #1
 
+    cmp     r2, lr
+    itt     hi
+    movhi   r0, r2
+    bhi     __strcpy_chk_fail
+
     // Fall through into the memcpy_base function.
 END(__strcpy_chk)
 
 #define MEMCPY_BASE         __strcpy_chk_memcpy_base
 #define MEMCPY_BASE_ALIGNED __strcpy_chk_memcpy_base_aligned
 #include "memcpy_base.S"
-
-ENTRY_PRIVATE(__strcpy_chk_fail)
-    .cfi_def_cfa_offset 8
-    .cfi_rel_offset r0, 0
-    .cfi_rel_offset lr, 4
-
-    ldr     r0, error_message
-    ldr     r1, error_code
-1:
-    add     r0, pc
-    bl      __fortify_chk_fail
-
-error_code:
-    .word   BIONIC_EVENT_STRCPY_BUFFER_OVERFLOW
-error_message:
-    .word   error_string-(1b+4)
-END(__strcpy_chk_fail)
-
-    .data
-error_string:
-    .string "strcpy: prevented write past end of buffer"
diff --git a/libc/arch-arm/cortex-a9/bionic/memcpy.S b/libc/arch-arm/cortex-a9/bionic/memcpy.S
index db3e26f..93a8629 100644
--- a/libc/arch-arm/cortex-a9/bionic/memcpy.S
+++ b/libc/arch-arm/cortex-a9/bionic/memcpy.S
@@ -27,7 +27,6 @@
  */
 
 #include <private/bionic_asm.h>
-#include <private/libc_events.h>
 
 /*
  * This code assumes it is running on a processor that supports all arm v7
@@ -42,9 +41,14 @@
 
 ENTRY(__memcpy_chk)
         cmp         r2, r3
-        bhi         __memcpy_chk_fail
+        bls         memcpy
 
-        // Fall through to memcpy...
+        // Preserve lr for backtrace.
+        push        {lr}
+        .cfi_def_cfa_offset 4
+        .cfi_rel_offset lr, 0
+
+        bl          __memcpy_chk_fail
 END(__memcpy_chk)
 
 ENTRY(memcpy)
@@ -59,24 +63,3 @@
 #define MEMCPY_BASE         __memcpy_base
 #define MEMCPY_BASE_ALIGNED __memcpy_base_aligned
 #include "memcpy_base.S"
-
-ENTRY_PRIVATE(__memcpy_chk_fail)
-        // Preserve lr for backtrace.
-        push    {lr}
-        .cfi_def_cfa_offset 4
-        .cfi_rel_offset lr, 0
-
-        ldr     r0, error_message
-        ldr     r1, error_code
-1:
-        add     r0, pc
-        bl      __fortify_chk_fail
-error_code:
-        .word   BIONIC_EVENT_MEMCPY_BUFFER_OVERFLOW
-error_message:
-        .word   error_string-(1b+4)
-END(__memcpy_chk_fail)
-
-        .data
-error_string:
-        .string     "memcpy: prevented write past end of buffer"
diff --git a/libc/arch-arm/cortex-a9/bionic/memset.S b/libc/arch-arm/cortex-a9/bionic/memset.S
index b39fcc4..d00231b 100644
--- a/libc/arch-arm/cortex-a9/bionic/memset.S
+++ b/libc/arch-arm/cortex-a9/bionic/memset.S
@@ -27,7 +27,6 @@
  */
 
 #include <private/bionic_asm.h>
-#include <private/libc_events.h>
 
 /*
  * This code assumes it is running on a processor that supports all arm v7
@@ -39,32 +38,16 @@
 
 ENTRY(__memset_chk)
         cmp         r2, r3
-        bls         .L_done
+        bls         memset
 
         // Preserve lr for backtrace.
         push        {lr}
         .cfi_def_cfa_offset 4
         .cfi_rel_offset lr, 0
 
-        ldr         r0, error_message
-        ldr         r1, error_code
-1:
-        add         r0, pc
-        bl          __fortify_chk_fail
-error_code:
-        .word       BIONIC_EVENT_MEMSET_BUFFER_OVERFLOW
-error_message:
-        .word       error_string-(1b+8)
+        bl          __memset_chk_fail
 END(__memset_chk)
 
-ENTRY(bzero)
-        mov     r2, r1
-        mov     r1, #0
-
-.L_done:
-        // Fall through to memset...
-END(bzero)
-
 /* memset() returns its first argument.  */
 ENTRY(memset)
         // The neon memset only wins for less than 132.
@@ -176,7 +159,3 @@
         strbcs      r1, [r0]
         ldmfd       sp!, {r0, r4-r7, pc}
 END(memset)
-
-        .data
-error_string:
-        .string     "memset: prevented write past end of buffer"
diff --git a/libc/arch-arm/cortex-a9/bionic/strcmp.S b/libc/arch-arm/cortex-a9/bionic/strcmp.S
index 4ff26c0..ba191d6 100644
--- a/libc/arch-arm/cortex-a9/bionic/strcmp.S
+++ b/libc/arch-arm/cortex-a9/bionic/strcmp.S
@@ -26,7 +26,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <machine/cpu-features.h>
 #include <private/bionic_asm.h>
 
 #ifdef __ARMEB__
diff --git a/libc/arch-arm/cortex-a9/cortex-a9.mk b/libc/arch-arm/cortex-a9/cortex-a9.mk
deleted file mode 100644
index 8a26d6b..0000000
--- a/libc/arch-arm/cortex-a9/cortex-a9.mk
+++ /dev/null
@@ -1,28 +0,0 @@
-libc_openbsd_src_files_exclude_arm += \
-    upstream-openbsd/lib/libc/string/memmove.c \
-    upstream-openbsd/lib/libc/string/stpcpy.c \
-    upstream-openbsd/lib/libc/string/strcat.c \
-    upstream-openbsd/lib/libc/string/strcpy.c \
-
-libc_bionic_src_files_exclude_arm += \
-    arch-arm/generic/bionic/memcpy.S \
-    arch-arm/generic/bionic/memset.S \
-    arch-arm/generic/bionic/strcmp.S \
-    arch-arm/generic/bionic/strcpy.S \
-    arch-arm/generic/bionic/strlen.c \
-    bionic/__strcat_chk.cpp \
-    bionic/__strcpy_chk.cpp \
-
-libc_bionic_src_files_arm += \
-    arch-arm/cortex-a9/bionic/memcpy.S \
-    arch-arm/cortex-a9/bionic/memset.S \
-    arch-arm/cortex-a9/bionic/stpcpy.S \
-    arch-arm/cortex-a9/bionic/strcat.S \
-    arch-arm/cortex-a9/bionic/__strcat_chk.S \
-    arch-arm/cortex-a9/bionic/strcmp.S \
-    arch-arm/cortex-a9/bionic/strcpy.S \
-    arch-arm/cortex-a9/bionic/__strcpy_chk.S \
-    arch-arm/cortex-a9/bionic/strlen.S \
-
-libc_bionic_src_files_arm += \
-    arch-arm/denver/bionic/memmove.S \
diff --git a/libc/arch-arm/denver/bionic/__strcat_chk.S b/libc/arch-arm/denver/bionic/__strcat_chk.S
index a2e9c22..9f7db59 100644
--- a/libc/arch-arm/denver/bionic/__strcat_chk.S
+++ b/libc/arch-arm/denver/bionic/__strcat_chk.S
@@ -27,7 +27,6 @@
  */
 
 #include <private/bionic_asm.h>
-#include <private/libc_events.h>
 
     .syntax unified
 
@@ -177,7 +176,9 @@
 .L_strlen_done:
     add     r2, r3, r4
     cmp     r2, lr
-    bhi     __strcat_chk_failed
+    itt     hi
+    movhi   r0, lr
+    bhi     __strcat_chk_fail
 
     // Set up the registers for the memcpy code.
     mov     r1, r5
@@ -191,26 +192,3 @@
 #define MEMCPY_BASE_ALIGNED __strcat_chk_memcpy_base_aligned
 
 #include "memcpy_base.S"
-
-ENTRY_PRIVATE(__strcat_chk_failed)
-    .cfi_def_cfa_offset 8
-    .cfi_rel_offset r0, 0
-    .cfi_rel_offset lr, 4
-    .cfi_adjust_cfa_offset 8
-    .cfi_rel_offset r4, 0
-    .cfi_rel_offset r5, 4
-
-    ldr     r0, error_message
-    ldr     r1, error_code
-1:
-    add     r0, pc
-    bl      __fortify_chk_fail
-error_code:
-    .word   BIONIC_EVENT_STRCAT_BUFFER_OVERFLOW
-error_message:
-    .word   error_string-(1b+4)
-END(__strcat_chk_failed)
-
-    .data
-error_string:
-    .string "strcat: prevented write past end of buffer"
diff --git a/libc/arch-arm/denver/bionic/__strcpy_chk.S b/libc/arch-arm/denver/bionic/__strcpy_chk.S
index db76686..9b7ea91 100644
--- a/libc/arch-arm/denver/bionic/__strcpy_chk.S
+++ b/libc/arch-arm/denver/bionic/__strcpy_chk.S
@@ -27,7 +27,6 @@
  */
 
 #include <private/bionic_asm.h>
-#include <private/libc_events.h>
 
     .syntax unified
 
@@ -148,33 +147,18 @@
     pld     [r1, #0]
     pld     [r1, #64]
     ldr     r0, [sp]
-    cmp     r3, lr
-    bhs     __strcpy_chk_failed
 
     // Add 1 for copy length to get the string terminator.
     add     r2, r3, #1
+
+    cmp     r2, lr
+    itt     hi
+    movhi   r0, r2
+    bhi     __strcpy_chk_fail
+
+    // Fall through into the memcpy_base function.
 END(__strcpy_chk)
 
 #define MEMCPY_BASE         __strcpy_chk_memcpy_base
 #define MEMCPY_BASE_ALIGNED __strcpy_chk_memcpy_base_aligned
 #include "memcpy_base.S"
-
-ENTRY_PRIVATE(__strcpy_chk_failed)
-    .cfi_def_cfa_offset 8
-    .cfi_rel_offset r0, 0
-    .cfi_rel_offset lr, 4
-
-    ldr     r0, error_message
-    ldr     r1, error_code
-1:
-    add     r0, pc
-    bl      __fortify_chk_fail
-error_code:
-    .word   BIONIC_EVENT_STRCPY_BUFFER_OVERFLOW
-error_message:
-    .word   error_string-(1b+4)
-END(__strcpy_chk_failed)
-
-    .data
-error_string:
-    .string "strcpy: prevented write past end of buffer"
diff --git a/libc/arch-arm/denver/bionic/memcpy.S b/libc/arch-arm/denver/bionic/memcpy.S
index 410b663..d4e0fb4 100644
--- a/libc/arch-arm/denver/bionic/memcpy.S
+++ b/libc/arch-arm/denver/bionic/memcpy.S
@@ -56,7 +56,6 @@
 // Prototype: void *memcpy (void *dst, const void *src, size_t count).
 
 #include <private/bionic_asm.h>
-#include <private/libc_events.h>
 
         .text
         .syntax unified
@@ -64,9 +63,14 @@
 
 ENTRY(__memcpy_chk)
         cmp     r2, r3
-        bhi     __memcpy_chk_fail
+        bls     memcpy
 
-        // Fall through to memcpy...
+        // Preserve lr for backtrace.
+        push    {lr}
+        .cfi_def_cfa_offset 4
+        .cfi_rel_offset lr, 0
+
+        bl      __memcpy_chk_fail
 END(__memcpy_chk)
 
 ENTRY(memcpy)
@@ -80,24 +84,3 @@
 #define MEMCPY_BASE         __memcpy_base
 #define MEMCPY_BASE_ALIGNED __memcpy_base_aligned
 #include "memcpy_base.S"
-
-ENTRY_PRIVATE(__memcpy_chk_fail)
-        // Preserve lr for backtrace.
-        push    {lr}
-        .cfi_def_cfa_offset 4
-        .cfi_rel_offset lr, 0
-
-        ldr     r0, error_message
-        ldr     r1, error_code
-1:
-        add     r0, pc
-        bl      __fortify_chk_fail
-error_code:
-        .word   BIONIC_EVENT_MEMCPY_BUFFER_OVERFLOW
-error_message:
-        .word   error_string-(1b+8)
-END(__memcpy_chk_fail)
-
-        .data
-error_string:
-        .string "memcpy: prevented write past end of buffer"
diff --git a/libc/arch-arm/denver/bionic/memmove.S b/libc/arch-arm/denver/bionic/memmove.S
index 132190b..94302f3 100644
--- a/libc/arch-arm/denver/bionic/memmove.S
+++ b/libc/arch-arm/denver/bionic/memmove.S
@@ -28,7 +28,6 @@
  */
 
 #include <private/bionic_asm.h>
-#include <private/libc_events.h>
 
         .text
         .syntax unified
diff --git a/libc/arch-arm/denver/bionic/memset.S b/libc/arch-arm/denver/bionic/memset.S
index d77c244..88ffe5c 100644
--- a/libc/arch-arm/denver/bionic/memset.S
+++ b/libc/arch-arm/denver/bionic/memset.S
@@ -27,9 +27,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/cpu-features.h>
 #include <private/bionic_asm.h>
-#include <private/libc_events.h>
 
         /*
          * Optimized memset() for ARM.
@@ -43,32 +41,16 @@
 
 ENTRY(__memset_chk)
         cmp         r2, r3
-        bls         .L_done
+        bls         memset
 
         // Preserve lr for backtrace.
         push        {lr}
         .cfi_def_cfa_offset 4
         .cfi_rel_offset lr, 0
 
-
-        ldr         r0, error_message
-        ldr         r1, error_code
-1:
-        add         r0, pc
-        bl          __fortify_chk_fail
-error_code:
-        .word       BIONIC_EVENT_MEMSET_BUFFER_OVERFLOW
-error_message:
-        .word       error_string-(1b+8)
+        bl          __memset_chk_fail
 END(__memset_chk)
 
-ENTRY(bzero)
-        mov         r2, r1
-        mov         r1, #0
-.L_done:
-        // Fall through to memset...
-END(bzero)
-
 ENTRY(memset)
         pldw        [r0]
         mov         r3, r0
@@ -202,7 +184,3 @@
 2:
         bx          lr
 END(memset)
-
-        .data
-error_string:
-        .string     "memset: prevented write past end of buffer"
diff --git a/libc/arch-arm/denver/denver.mk b/libc/arch-arm/denver/denver.mk
deleted file mode 100644
index f167991..0000000
--- a/libc/arch-arm/denver/denver.mk
+++ /dev/null
@@ -1,28 +0,0 @@
-libc_openbsd_src_files_exclude_arm += \
-    upstream-openbsd/lib/libc/string/memmove.c \
-    upstream-openbsd/lib/libc/string/stpcpy.c \
-    upstream-openbsd/lib/libc/string/strcat.c \
-
-libc_bionic_src_files_exclude_arm += \
-    arch-arm/generic/bionic/memcpy.S \
-    arch-arm/generic/bionic/memset.S \
-    arch-arm/generic/bionic/strcmp.S \
-    arch-arm/generic/bionic/strcpy.S \
-    arch-arm/generic/bionic/strlen.c \
-    bionic/__strcat_chk.cpp \
-    bionic/__strcpy_chk.cpp \
-
-libc_bionic_src_files_arm += \
-    arch-arm/denver/bionic/memcpy.S \
-    arch-arm/denver/bionic/memmove.S \
-    arch-arm/denver/bionic/memset.S \
-    arch-arm/denver/bionic/__strcat_chk.S \
-    arch-arm/denver/bionic/__strcpy_chk.S \
-
-# Use cortex-a15 versions of strcat/strcpy/strlen.
-libc_bionic_src_files_arm += \
-    arch-arm/cortex-a15/bionic/stpcpy.S \
-    arch-arm/cortex-a15/bionic/strcat.S \
-    arch-arm/cortex-a15/bionic/strcmp.S \
-    arch-arm/cortex-a15/bionic/strcpy.S \
-    arch-arm/cortex-a15/bionic/strlen.S \
diff --git a/libc/arch-arm/generic/bionic/memcmp.S b/libc/arch-arm/generic/bionic/memcmp.S
index 6643d55..e648720 100644
--- a/libc/arch-arm/generic/bionic/memcmp.S
+++ b/libc/arch-arm/generic/bionic/memcmp.S
@@ -26,7 +26,6 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/cpu-features.h>
 #include <private/bionic_asm.h>
 
 
diff --git a/libc/arch-arm/generic/bionic/memcpy.S b/libc/arch-arm/generic/bionic/memcpy.S
index 65cba4c..a3ebb95 100644
--- a/libc/arch-arm/generic/bionic/memcpy.S
+++ b/libc/arch-arm/generic/bionic/memcpy.S
@@ -26,9 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/cpu-features.h>
 #include <private/bionic_asm.h>
-#include <private/libc_events.h>
 
         /*
          * Optimized memcpy() for ARM.
@@ -41,9 +39,14 @@
 
 ENTRY(__memcpy_chk)
         cmp         r2, r3
-        bhi         __memcpy_chk_fail
+        bls         memcpy
 
-        // Fall through to memcpy...
+        // Preserve lr for backtrace.
+        push        {lr}
+        .cfi_def_cfa_offset 4
+        .cfi_rel_offset lr, 0
+
+        bl          __memcpy_chk_fail
 END(__memcpy_chk)
 
 ENTRY(memcpy)
@@ -386,25 +389,3 @@
         add         sp,  sp, #28
         ldmfd       sp!, {r0, r4, pc}
 END(memcpy)
-
-        // Only reached when the __memcpy_chk check fails.
-ENTRY_PRIVATE(__memcpy_chk_fail)
-        // Preserve lr for backtrace.
-        push    {lr}
-        .cfi_def_cfa_offset 4
-        .cfi_rel_offset lr, 0
-
-        ldr     r0, error_message
-        ldr     r1, error_code
-1:
-        add     r0, pc
-        bl      __fortify_chk_fail
-error_code:
-        .word   BIONIC_EVENT_MEMCPY_BUFFER_OVERFLOW
-error_message:
-        .word   error_string-(1b+8)
-END(__memcpy_chk_fail)
-
-        .data
-error_string:
-        .string     "memcpy: prevented write past end of buffer"
diff --git a/libc/arch-arm/generic/bionic/memset.S b/libc/arch-arm/generic/bionic/memset.S
index b8eabbf..1fd0de1 100644
--- a/libc/arch-arm/generic/bionic/memset.S
+++ b/libc/arch-arm/generic/bionic/memset.S
@@ -27,7 +27,6 @@
  */
 
 #include <private/bionic_asm.h>
-#include <private/libc_events.h>
 
         /*
          * Optimized memset() for ARM.
@@ -39,28 +38,11 @@
 
 ENTRY(__memset_chk)
         cmp         r2, r3
-        bls         done
+        bls         memset
 
-        ldr         r0, error_message
-        ldr         r1, error_code
-1:
-        add         r0, pc
-        bl          __fortify_chk_fail
-error_code:
-        .word       BIONIC_EVENT_MEMSET_BUFFER_OVERFLOW
-error_message:
-        .word       error_string-(1b+8)
-
+        bl          __memset_chk_fail
 END(__memset_chk)
 
-ENTRY(bzero)
-        mov     r2, r1
-        mov     r1, #0
-
-done:
-        // Fall through to memset...
-END(bzero)
-
 ENTRY(memset)
         /* compute the offset to align the destination
          * offset = (4-(src&3))&3 = -src & 3
@@ -127,7 +109,3 @@
         strbcs      r1, [r0]
         ldmfd       sp!, {r0, r4-r7, pc}
 END(memset)
-
-        .data
-error_string:
-        .string     "memset: prevented write past end of buffer"
diff --git a/libc/arch-arm/generic/bionic/strcmp.S b/libc/arch-arm/generic/bionic/strcmp.S
index 6dba942..10b6704 100644
--- a/libc/arch-arm/generic/bionic/strcmp.S
+++ b/libc/arch-arm/generic/bionic/strcmp.S
@@ -27,7 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <machine/cpu-features.h>
 #include <private/bionic_asm.h>
 
 	.text
diff --git a/libc/arch-arm/generic/bionic/strcpy.S b/libc/arch-arm/generic/bionic/strcpy.S
index 89ea098..c0ab9e5 100644
--- a/libc/arch-arm/generic/bionic/strcpy.S
+++ b/libc/arch-arm/generic/bionic/strcpy.S
@@ -29,7 +29,6 @@
  * Android adaptation and tweak by Jim Huang <jserv@0xlab.org>.
  */
 
-#include <machine/cpu-features.h>
 #include <private/bionic_asm.h>
 
 .syntax unified
diff --git a/libc/arch-arm/generic/bionic/strlen.c b/libc/arch-arm/generic/bionic/strlen.c
index 811e1e0..b9f3a2a 100644
--- a/libc/arch-arm/generic/bionic/strlen.c
+++ b/libc/arch-arm/generic/bionic/strlen.c
@@ -25,9 +25,9 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #include <string.h>
 #include <stdint.h>
-#include <machine/cpu-features.h>
 
 size_t strlen(const char *s)
 {
diff --git a/libm/include/arm/machine/fenv.h b/libc/arch-arm/include/machine/fenv.h
similarity index 100%
rename from libm/include/arm/machine/fenv.h
rename to libc/arch-arm/include/machine/fenv.h
diff --git a/libc/arch-arm/krait/bionic/__strcat_chk.S b/libc/arch-arm/krait/bionic/__strcat_chk.S
index 1a39c5b..a46ff98 100644
--- a/libc/arch-arm/krait/bionic/__strcat_chk.S
+++ b/libc/arch-arm/krait/bionic/__strcat_chk.S
@@ -27,7 +27,6 @@
  */
 
 #include <private/bionic_asm.h>
-#include <private/libc_events.h>
 
     .syntax unified
 
@@ -177,7 +176,9 @@
 .L_strlen_done:
     add     r2, r3, r4
     cmp     r2, lr
-    bhi     .L_strcat_chk_failed
+    itt     hi
+    movhi   r0, lr
+    bhi     __strcat_chk_fail
 
     // Set up the registers for the memcpy code.
     mov     r1, r5
@@ -195,18 +196,4 @@
     .cfi_adjust_cfa_offset 8
     .cfi_rel_offset r4, 0
     .cfi_rel_offset r5, 4
-.L_strcat_chk_failed:
-    ldr     r0, error_message
-    ldr     r1, error_code
-1:
-    add     r0, pc
-    bl      __fortify_chk_fail
-error_code:
-    .word   BIONIC_EVENT_STRCAT_BUFFER_OVERFLOW
-error_message:
-    .word   error_string-(1b+4)
 END(__strcat_chk)
-
-    .data
-error_string:
-    .string "strcat: prevented write past end of buffer"
diff --git a/libc/arch-arm/krait/bionic/__strcpy_chk.S b/libc/arch-arm/krait/bionic/__strcpy_chk.S
index 00202f3..9c2f66a 100644
--- a/libc/arch-arm/krait/bionic/__strcpy_chk.S
+++ b/libc/arch-arm/krait/bionic/__strcpy_chk.S
@@ -27,7 +27,6 @@
  */
 
 #include <private/bionic_asm.h>
-#include <private/libc_events.h>
 
     .syntax unified
 
@@ -148,26 +147,15 @@
     pld     [r1, #0]
     pld     [r1, #64]
     ldr     r0, [sp]
-    cmp     r3, lr
-    bhs     .L_strcpy_chk_failed
 
     // Add 1 for copy length to get the string terminator.
     add     r2, r3, #1
 
+    cmp     r2, lr
+    itt     hi
+    movhi   r0, r2
+    bhi     __strcpy_chk_fail
+
 #include "memcpy_base.S"
 
-.L_strcpy_chk_failed:
-    ldr     r0, error_message
-    ldr     r1, error_code
-1:
-    add     r0, pc
-    bl      __fortify_chk_fail
-error_code:
-    .word   BIONIC_EVENT_STRCPY_BUFFER_OVERFLOW
-error_message:
-    .word   error_string-(1b+4)
 END(__strcpy_chk)
-
-    .data
-error_string:
-    .string "strcpy: prevented write past end of buffer"
diff --git a/libc/arch-arm/krait/bionic/memcpy.S b/libc/arch-arm/krait/bionic/memcpy.S
index 5d27b57..de6f432 100644
--- a/libc/arch-arm/krait/bionic/memcpy.S
+++ b/libc/arch-arm/krait/bionic/memcpy.S
@@ -29,7 +29,6 @@
 /* Assumes neon instructions and a cache line size of 32 bytes. */
 
 #include <private/bionic_asm.h>
-#include <private/libc_events.h>
 
 /*
  * This code assumes it is running on a processor that supports all arm v7
@@ -45,9 +44,14 @@
 
 ENTRY(__memcpy_chk)
         cmp         r2, r3
-        bhi         .L_memcpy_chk_fail
+        bls         memcpy
 
-        // Fall through to memcpy...
+        // Preserve lr for backtrace.
+        push        {lr}
+        .cfi_def_cfa_offset 4
+        .cfi_rel_offset lr, 0
+
+        bl          __memcpy_chk_fail
 END(__memcpy_chk)
 
 ENTRY(memcpy)
@@ -58,28 +62,4 @@
         .cfi_rel_offset lr, 4
 
 #include "memcpy_base.S"
-
-        // Undo the cfi directives from above.
-        .cfi_adjust_cfa_offset -8
-        .cfi_restore r0
-        .cfi_restore lr
-.L_memcpy_chk_fail:
-        // Preserve lr for backtrace.
-        push    {lr}
-        .cfi_adjust_cfa_offset 4
-        .cfi_rel_offset lr, 0
-
-        ldr     r0, error_message
-        ldr     r1, error_code
-1:
-        add     r0, pc
-        bl      __fortify_chk_fail
-error_code:
-        .word   BIONIC_EVENT_MEMCPY_BUFFER_OVERFLOW
-error_message:
-        .word   error_string-(1b+4)
 END(memcpy)
-
-        .data
-error_string:
-        .string     "memcpy: prevented write past end of buffer"
diff --git a/libc/arch-arm/krait/bionic/memcpy_base.S b/libc/arch-arm/krait/bionic/memcpy_base.S
index 76c5a84..7368e63 100644
--- a/libc/arch-arm/krait/bionic/memcpy_base.S
+++ b/libc/arch-arm/krait/bionic/memcpy_base.S
@@ -27,7 +27,6 @@
 
 /* Assumes neon instructions and a cache line size of 64 bytes. */
 
-#include <machine/cpu-features.h>
 #include <machine/asm.h>
 
 #define PLDOFFS	(10)
diff --git a/libc/arch-arm/krait/bionic/memset.S b/libc/arch-arm/krait/bionic/memset.S
index ae05965..228942c 100644
--- a/libc/arch-arm/krait/bionic/memset.S
+++ b/libc/arch-arm/krait/bionic/memset.S
@@ -26,9 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/cpu-features.h>
 #include <private/bionic_asm.h>
-#include <private/libc_events.h>
 
 /*
  * This code assumes it is running on a processor that supports all arm v7
@@ -41,32 +39,16 @@
 
 ENTRY(__memset_chk)
         cmp         r2, r3
-        bls         .L_done
+        bls         memset
 
         // Preserve lr for backtrace.
         push        {lr}
         .cfi_def_cfa_offset 4
         .cfi_rel_offset lr, 0
 
-        ldr         r0, error_message
-        ldr         r1, error_code
-1:
-        add         r0, pc
-        bl          __fortify_chk_fail
-error_code:
-        .word       BIONIC_EVENT_MEMSET_BUFFER_OVERFLOW
-error_message:
-        .word       error_string-(1b+8)
+        bl          __memset_chk_fail
 END(__memset_chk)
 
-ENTRY(bzero)
-        mov     r2, r1
-        mov     r1, #0
-
-.L_done:
-        // Fall through to memset...
-END(bzero)
-
 /* memset() returns its first argument.  */
 ENTRY(memset)
         mov         r3, r0
@@ -101,7 +83,3 @@
         strbcs      r1, [r3], #1
         bx          lr
 END(memset)
-
-        .data
-error_string:
-        .string     "memset: prevented write past end of buffer"
diff --git a/libc/arch-arm/krait/bionic/strcmp.S b/libc/arch-arm/krait/bionic/strcmp.S
index 9121c01..b871c76 100644
--- a/libc/arch-arm/krait/bionic/strcmp.S
+++ b/libc/arch-arm/krait/bionic/strcmp.S
@@ -26,7 +26,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <machine/cpu-features.h>
 #include <private/bionic_asm.h>
 
 #ifdef __ARMEB__
diff --git a/libc/arch-arm/krait/krait.mk b/libc/arch-arm/krait/krait.mk
deleted file mode 100644
index f8e3452..0000000
--- a/libc/arch-arm/krait/krait.mk
+++ /dev/null
@@ -1,31 +0,0 @@
-libc_openbsd_src_files_exclude_arm += \
-    upstream-openbsd/lib/libc/string/memmove.c \
-    upstream-openbsd/lib/libc/string/stpcpy.c \
-    upstream-openbsd/lib/libc/string/stpcpy.c \
-    upstream-openbsd/lib/libc/string/strcat.c \
-
-libc_bionic_src_files_exclude_arm += \
-    arch-arm/generic/bionic/memcpy.S \
-    arch-arm/generic/bionic/memset.S \
-    arch-arm/generic/bionic/strcmp.S \
-    arch-arm/generic/bionic/strcpy.S \
-    arch-arm/generic/bionic/strlen.c \
-    bionic/__strcat_chk.cpp \
-    bionic/__strcpy_chk.cpp \
-
-libc_bionic_src_files_arm += \
-    arch-arm/krait/bionic/memcpy.S \
-    arch-arm/krait/bionic/memset.S \
-    arch-arm/krait/bionic/strcmp.S \
-    arch-arm/krait/bionic/__strcat_chk.S \
-    arch-arm/krait/bionic/__strcpy_chk.S \
-
-# Use cortex-a15 versions of strcat/strcpy/strlen and standard memmove
-libc_bionic_src_files_arm += \
-    arch-arm/cortex-a15/bionic/stpcpy.S \
-    arch-arm/cortex-a15/bionic/strcat.S \
-    arch-arm/cortex-a15/bionic/strcpy.S \
-    arch-arm/cortex-a15/bionic/strlen.S \
-
-libc_bionic_src_files_arm += \
-    arch-arm/denver/bionic/memmove.S \
diff --git a/libc/arch-arm/syscalls/clock_gettime.S b/libc/arch-arm/syscalls/__clock_gettime.S
similarity index 87%
rename from libc/arch-arm/syscalls/clock_gettime.S
rename to libc/arch-arm/syscalls/__clock_gettime.S
index 61a95dd..30eff03 100644
--- a/libc/arch-arm/syscalls/clock_gettime.S
+++ b/libc/arch-arm/syscalls/__clock_gettime.S
@@ -2,7 +2,7 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(clock_gettime)
+ENTRY(__clock_gettime)
     mov     ip, r7
     .cfi_register r7, ip
     ldr     r7, =__NR_clock_gettime
@@ -13,4 +13,4 @@
     bxls    lr
     neg     r0, r0
     b       __set_errno_internal
-END(clock_gettime)
+END(__clock_gettime)
diff --git a/libc/arch-arm/syscalls/gettimeofday.S b/libc/arch-arm/syscalls/__gettimeofday.S
similarity index 88%
rename from libc/arch-arm/syscalls/gettimeofday.S
rename to libc/arch-arm/syscalls/__gettimeofday.S
index f5ed674..de0eca5 100644
--- a/libc/arch-arm/syscalls/gettimeofday.S
+++ b/libc/arch-arm/syscalls/__gettimeofday.S
@@ -2,7 +2,7 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(gettimeofday)
+ENTRY(__gettimeofday)
     mov     ip, r7
     .cfi_register r7, ip
     ldr     r7, =__NR_gettimeofday
@@ -13,4 +13,4 @@
     bxls    lr
     neg     r0, r0
     b       __set_errno_internal
-END(gettimeofday)
+END(__gettimeofday)
diff --git a/libc/arch-arm/syscalls/__sync_file_range2.S b/libc/arch-arm/syscalls/__sync_file_range2.S
new file mode 100644
index 0000000..4346e1b
--- /dev/null
+++ b/libc/arch-arm/syscalls/__sync_file_range2.S
@@ -0,0 +1,22 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__sync_file_range2)
+    mov     ip, sp
+    stmfd   sp!, {r4, r5, r6, r7}
+    .cfi_def_cfa_offset 16
+    .cfi_rel_offset r4, 0
+    .cfi_rel_offset r5, 4
+    .cfi_rel_offset r6, 8
+    .cfi_rel_offset r7, 12
+    ldmfd   ip, {r4, r5, r6}
+    ldr     r7, =__NR_sync_file_range2
+    swi     #0
+    ldmfd   sp!, {r4, r5, r6, r7}
+    .cfi_def_cfa_offset 0
+    cmn     r0, #(MAX_ERRNO + 1)
+    bxls    lr
+    neg     r0, r0
+    b       __set_errno_internal
+END(__sync_file_range2)
diff --git a/libc/arch-arm/syscalls/gettimeofday.S b/libc/arch-arm/syscalls/quotactl.S
similarity index 79%
copy from libc/arch-arm/syscalls/gettimeofday.S
copy to libc/arch-arm/syscalls/quotactl.S
index f5ed674..fde17f4 100644
--- a/libc/arch-arm/syscalls/gettimeofday.S
+++ b/libc/arch-arm/syscalls/quotactl.S
@@ -2,10 +2,10 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(gettimeofday)
+ENTRY(quotactl)
     mov     ip, r7
     .cfi_register r7, ip
-    ldr     r7, =__NR_gettimeofday
+    ldr     r7, =__NR_quotactl
     swi     #0
     mov     r7, ip
     .cfi_restore r7
@@ -13,4 +13,4 @@
     bxls    lr
     neg     r0, r0
     b       __set_errno_internal
-END(gettimeofday)
+END(quotactl)
diff --git a/libc/arch-arm/syscalls/clock_gettime.S b/libc/arch-arm/syscalls/setdomainname.S
similarity index 78%
copy from libc/arch-arm/syscalls/clock_gettime.S
copy to libc/arch-arm/syscalls/setdomainname.S
index 61a95dd..4014a48 100644
--- a/libc/arch-arm/syscalls/clock_gettime.S
+++ b/libc/arch-arm/syscalls/setdomainname.S
@@ -2,10 +2,10 @@
 
 #include <private/bionic_asm.h>
 
-ENTRY(clock_gettime)
+ENTRY(setdomainname)
     mov     ip, r7
     .cfi_register r7, ip
-    ldr     r7, =__NR_clock_gettime
+    ldr     r7, =__NR_setdomainname
     swi     #0
     mov     r7, ip
     .cfi_restore r7
@@ -13,4 +13,4 @@
     bxls    lr
     neg     r0, r0
     b       __set_errno_internal
-END(clock_gettime)
+END(setdomainname)
diff --git a/libc/arch-arm64/arm64.mk b/libc/arch-arm64/arm64.mk
deleted file mode 100644
index 9a76072..0000000
--- a/libc/arch-arm64/arm64.mk
+++ /dev/null
@@ -1,71 +0,0 @@
-# 64-bit arm.
-
-#
-# Generic arm64 optimizations, may be overriden by CPU variants.
-#
-
-libc_bionic_src_files_arm64 += \
-    arch-arm64/generic/bionic/memchr.S \
-    arch-arm64/generic/bionic/memcmp.S \
-    arch-arm64/generic/bionic/memcpy.S \
-    arch-arm64/generic/bionic/memmove.S \
-    arch-arm64/generic/bionic/memset.S \
-    arch-arm64/generic/bionic/stpcpy.S \
-    arch-arm64/generic/bionic/strchr.S \
-    arch-arm64/generic/bionic/strcmp.S \
-    arch-arm64/generic/bionic/strcpy.S \
-    arch-arm64/generic/bionic/strlen.S \
-    arch-arm64/generic/bionic/strncmp.S \
-    arch-arm64/generic/bionic/strnlen.S \
-    arch-arm64/generic/bionic/wmemmove.S \
-
-libc_bionic_src_files_exclude_arm64 += \
-    bionic/__memcpy_chk.cpp \
-    bionic/strchr.cpp \
-    bionic/strnlen.c \
-
-libc_freebsd_src_files_exclude_arm64 += \
-    upstream-freebsd/lib/libc/string/wmemmove.c \
-
-libc_openbsd_src_files_exclude_arm64 += \
-    upstream-openbsd/lib/libc/string/memchr.c \
-    upstream-openbsd/lib/libc/string/memmove.c \
-    upstream-openbsd/lib/libc/string/stpcpy.c \
-    upstream-openbsd/lib/libc/string/strcpy.c \
-    upstream-openbsd/lib/libc/string/strncmp.c \
-
-#
-# Inherently architecture-specific code.
-#
-
-libc_bionic_src_files_arm64 += \
-    arch-arm64/bionic/__bionic_clone.S \
-    arch-arm64/bionic/_exit_with_stack_teardown.S \
-    arch-arm64/bionic/setjmp.S \
-    arch-arm64/bionic/syscall.S \
-    arch-arm64/bionic/vfork.S \
-
-
-libc_crt_target_cflags_arm64 := \
-    -I$(LOCAL_PATH)/arch-arm64/include
-
-libc_crt_target_crtbegin_file_arm64 := \
-    $(LOCAL_PATH)/arch-arm64/bionic/crtbegin.c
-
-libc_crt_target_crtbegin_so_file_arm64 := \
-    $(LOCAL_PATH)/arch-common/bionic/crtbegin_so.c
-
-## CPU variant specific source files
-ifeq ($(strip $(TARGET_CPU_VARIANT)),)
-  $(warning TARGET_ARCH is arm64, but TARGET_CPU_VARIANT is not defined)
-endif
-ifneq ($(TARGET_CPU_VARIANT),generic)
-cpu_variant_mk := $(LOCAL_PATH)/arch-arm64/$(TARGET_CPU_VARIANT)/$(TARGET_CPU_VARIANT).mk
-ifeq ($(wildcard $(cpu_variant_mk)),)
-$(error "TARGET_CPU_VARIANT not set or set to an unknown value. Possible values are generic, denver64. Use generic for devices that do not have a CPU similar to any of the supported cpu variants.")
-endif
-include $(cpu_variant_mk)
-libc_common_additional_dependencies += $(cpu_variant_mk)
-
-cpu_variant_mk :=
-endif
diff --git a/libc/arch-arm64/denver64/bionic/memcpy.S b/libc/arch-arm64/denver64/bionic/memcpy.S
index 85129fe..0be2aac 100644
--- a/libc/arch-arm64/denver64/bionic/memcpy.S
+++ b/libc/arch-arm64/denver64/bionic/memcpy.S
@@ -29,35 +29,20 @@
 // Prototype: void *memcpy (void *dst, const void *src, size_t count).
 
 #include <private/bionic_asm.h>
-#include <private/libc_events.h>
 
 ENTRY(__memcpy_chk)
-  cmp   x2, x3
-  b.hi  __memcpy_chk_fail
+  cmp x2, x3
+  bls memcpy
 
-  // Fall through to memcpy...
+  // Preserve for accurate backtrace.
+  stp x29, x30, [sp, -16]!
+  .cfi_def_cfa_offset 16
+  .cfi_rel_offset x29, 0
+  .cfi_rel_offset x30, 8
+
+  bl __memcpy_chk_fail
 END(__memcpy_chk)
 
 ENTRY(memcpy)
   #include "memcpy_base.S"
 END(memcpy)
-
-ENTRY_PRIVATE(__memcpy_chk_fail)
-  // Preserve for accurate backtrace.
-  stp  x29, x30, [sp, -16]!
-  .cfi_def_cfa_offset 16
-  .cfi_rel_offset x29, 0
-  .cfi_rel_offset x30, 8
-
-  adrp  x0, error_string
-  add   x0, x0, :lo12:error_string
-  ldr   x1, error_code
-  bl    __fortify_chk_fail
-error_code:
-  .word   BIONIC_EVENT_MEMCPY_BUFFER_OVERFLOW
-END(__memcpy_chk_fail)
-
-  .data
-  .align 2
-error_string:
-  .string "memcpy: prevented write past end of buffer"
diff --git a/libc/arch-arm64/denver64/bionic/memset.S b/libc/arch-arm64/denver64/bionic/memset.S
index 9127d89..bea5b26 100644
--- a/libc/arch-arm64/denver64/bionic/memset.S
+++ b/libc/arch-arm64/denver64/bionic/memset.S
@@ -48,6 +48,7 @@
 #define dstin		x0
 #define val		w1
 #define count		x2
+#define dst_count x3 /* for __memset_chk */
 #define tmp1		x3
 #define tmp1w		w3
 #define tmp2		x4
@@ -63,6 +64,19 @@
 
 #define QA_l		q0
 
+ENTRY(__memset_chk)
+  cmp count, dst_count
+  bls memset
+
+  // Preserve for accurate backtrace.
+  stp x29, x30, [sp, -16]!
+  .cfi_def_cfa_offset 16
+  .cfi_rel_offset x29, 0
+  .cfi_rel_offset x30, 8
+
+  bl __memset_chk_fail
+END(__memset_chk)
+
 ENTRY(memset)
 
 	mov	dst, dstin		/* Preserve return value.  */
diff --git a/libc/arch-arm64/denver64/denver64.mk b/libc/arch-arm64/denver64/denver64.mk
deleted file mode 100644
index 703af45..0000000
--- a/libc/arch-arm64/denver64/denver64.mk
+++ /dev/null
@@ -1,7 +0,0 @@
-libc_bionic_src_files_arm64 += \
-    arch-arm64/denver64/bionic/memcpy.S \
-    arch-arm64/denver64/bionic/memset.S \
-
-libc_bionic_src_files_exclude_arm64 += \
-    arch-arm64/generic/bionic/memcpy.S \
-    arch-arm64/generic/bionic/memset.S \
diff --git a/libc/arch-arm64/generic/bionic/memcpy.S b/libc/arch-arm64/generic/bionic/memcpy.S
index 85129fe..0be2aac 100644
--- a/libc/arch-arm64/generic/bionic/memcpy.S
+++ b/libc/arch-arm64/generic/bionic/memcpy.S
@@ -29,35 +29,20 @@
 // Prototype: void *memcpy (void *dst, const void *src, size_t count).
 
 #include <private/bionic_asm.h>
-#include <private/libc_events.h>
 
 ENTRY(__memcpy_chk)
-  cmp   x2, x3
-  b.hi  __memcpy_chk_fail
+  cmp x2, x3
+  bls memcpy
 
-  // Fall through to memcpy...
+  // Preserve for accurate backtrace.
+  stp x29, x30, [sp, -16]!
+  .cfi_def_cfa_offset 16
+  .cfi_rel_offset x29, 0
+  .cfi_rel_offset x30, 8
+
+  bl __memcpy_chk_fail
 END(__memcpy_chk)
 
 ENTRY(memcpy)
   #include "memcpy_base.S"
 END(memcpy)
-
-ENTRY_PRIVATE(__memcpy_chk_fail)
-  // Preserve for accurate backtrace.
-  stp  x29, x30, [sp, -16]!
-  .cfi_def_cfa_offset 16
-  .cfi_rel_offset x29, 0
-  .cfi_rel_offset x30, 8
-
-  adrp  x0, error_string
-  add   x0, x0, :lo12:error_string
-  ldr   x1, error_code
-  bl    __fortify_chk_fail
-error_code:
-  .word   BIONIC_EVENT_MEMCPY_BUFFER_OVERFLOW
-END(__memcpy_chk_fail)
-
-  .data
-  .align 2
-error_string:
-  .string "memcpy: prevented write past end of buffer"
diff --git a/libc/arch-arm64/generic/bionic/memset.S b/libc/arch-arm64/generic/bionic/memset.S
index 7c204b4..9626c0b 100644
--- a/libc/arch-arm64/generic/bionic/memset.S
+++ b/libc/arch-arm64/generic/bionic/memset.S
@@ -45,12 +45,9 @@
    values rather than re-reading them each call.  */
 
 #define dstin		x0
-#ifdef BZERO
-#define count		x1
-#else
-#define count		x2
-#endif
 #define val		w1
+#define count		x2
+#define dst_count x3 /* for __memset_chk */
 #define tmp1		x3
 #define tmp1w		w3
 #define tmp2		x4
@@ -64,16 +61,22 @@
 #define dst		x8
 #define tmp3w		w9
 
-#ifdef BZERO
-ENTRY(bzero)
-#else
+ENTRY(__memset_chk)
+  cmp count, dst_count
+  bls memset
+
+  // Preserve for accurate backtrace.
+  stp x29, x30, [sp, -16]!
+  .cfi_def_cfa_offset 16
+  .cfi_rel_offset x29, 0
+  .cfi_rel_offset x30, 8
+
+  bl __memset_chk_fail
+END(__memset_chk)
+
 ENTRY(memset)
-#endif
 
 	mov	dst, dstin		/* Preserve return value.  */
-#ifdef BZERO
-	b	.Lzero_mem
-#endif
 	ands	A_lw, val, #255
 	b.eq	.Lzero_mem
 	orr	A_lw, A_lw, A_lw, lsl #8
@@ -233,11 +236,7 @@
 	ands	count, count, zva_bits_x
 	b.ne	.Ltail_maybe_long
 	ret
-#ifdef BZERO
-END(bzero)
-#else
 END(memset)
-#endif
 
 #ifdef MAYBE_VIRT
 	.bss
diff --git a/libm/include/arm64/machine/fenv.h b/libc/arch-arm64/include/machine/fenv.h
similarity index 100%
rename from libm/include/arm64/machine/fenv.h
rename to libc/arch-arm64/include/machine/fenv.h
diff --git a/libc/arch-arm64/syscalls/__sync_file_range.S b/libc/arch-arm64/syscalls/__sync_file_range.S
new file mode 100644
index 0000000..776e900
--- /dev/null
+++ b/libc/arch-arm64/syscalls/__sync_file_range.S
@@ -0,0 +1,15 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__sync_file_range)
+    mov     x8, __NR_sync_file_range
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno_internal
+
+    ret
+END(__sync_file_range)
+.hidden __sync_file_range
diff --git a/libc/arch-arm64/syscalls/quotactl.S b/libc/arch-arm64/syscalls/quotactl.S
new file mode 100644
index 0000000..b67d47e
--- /dev/null
+++ b/libc/arch-arm64/syscalls/quotactl.S
@@ -0,0 +1,14 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(quotactl)
+    mov     x8, __NR_quotactl
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno_internal
+
+    ret
+END(quotactl)
diff --git a/libc/arch-arm64/syscalls/setdomainname.S b/libc/arch-arm64/syscalls/setdomainname.S
new file mode 100644
index 0000000..18f8d4b
--- /dev/null
+++ b/libc/arch-arm64/syscalls/setdomainname.S
@@ -0,0 +1,14 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setdomainname)
+    mov     x8, __NR_setdomainname
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno_internal
+
+    ret
+END(setdomainname)
diff --git a/libc/arch-mips/bionic/bzero.S b/libc/arch-mips/bionic/libgcc_compat.c
similarity index 81%
copy from libc/arch-mips/bionic/bzero.S
copy to libc/arch-mips/bionic/libgcc_compat.c
index 6e5d294..1a0f566 100644
--- a/libc/arch-mips/bionic/bzero.S
+++ b/libc/arch-mips/bionic/libgcc_compat.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) 2016 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,14 +26,16 @@
  * SUCH DAMAGE.
  */
 
-#include <private/bionic_asm.h>
+extern char __divdi3;
+extern char __moddi3;
+extern char __popcountsi2;
+extern char __udivdi3;
+extern char __umoddi3;
 
-// void bzero(void*, size_t);
-ENTRY(bzero)
-	.set	noreorder
-	.cpload	t9
-	move	a2,a1
-	la	t9,memset
-	j	t9
-	 move	a1,zero
-END(bzero)
+void* __bionic_libgcc_compat_symbols[] = {
+    &__divdi3,
+    &__moddi3,
+    &__popcountsi2,
+    &__udivdi3,
+    &__umoddi3,
+};
diff --git a/libc/arch-mips/bionic/setjmp.S b/libc/arch-mips/bionic/setjmp.S
index 73002e8..3b4ff55 100644
--- a/libc/arch-mips/bionic/setjmp.S
+++ b/libc/arch-mips/bionic/setjmp.S
@@ -136,7 +136,7 @@
 /* following fields are 8-byte aligned */
 #define	SC_FLAG_OFFSET	(2*4)		/* 8 bytes, cookie and savesigs flag, first actual field  */
 #define	SC_MASK_OFFSET	(4*4)		/* 16 bytes, mips32/mips64 version of sigset_t */
-#define	SC_SPARE_OFFSET	(8*4)		/* 8 bytes, reserved for future uses */
+#define	SC_CKSUM_OFFSET	(8*4)		/* 8 bytes, used for checksum */
 
 /* Registers that are 4-byte on mips32 o32, and 8-byte on mips64 n64 abi */
 #define	SC_REGS_OFFSET	(10*4)		/* SC_REGS_BYTES */
@@ -165,6 +165,8 @@
 #error _JBLEN is too small
 #endif
 
+#define USE_CHECKSUM 1
+
 .macro m_mangle_reg_and_store reg, cookie, temp, offset
 	xor	\temp, \reg, \cookie
 	REG_S	\temp, \offset
@@ -175,6 +177,20 @@
 	xor	\reg, \temp, \cookie
 .endm
 
+.macro m_calculate_checksum dst, src, scratch
+	REG_L \dst, REGSZ(\src)
+#ifdef __LP64__
+	/* 64 bit: checksum offset is 4 (actual _JBLEN is 25) */
+	.irp i,2,3,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24
+#else
+	/* 32 bit: checksum offset is 8 (actual _JBLEN is 34) */
+	.irp i,2,3,4,5,6,7,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33
+#endif
+		REG_L \scratch, \i*REGSZ(\src)
+		xor \dst, \dst, \scratch
+	.endr
+.endm
+
 /*
  *
  *  GPOFF and FRAMESIZE must be the same for all setjmp/longjmp routines
@@ -263,6 +279,10 @@
 	s.d	$f30, SC_FPREGS+5*REGSZ_FP(a0)
 #endif
 	sw	v0, SC_FPSR_OFFSET(a0)
+#if USE_CHECKSUM
+	m_calculate_checksum t0, a0, t1
+	REG_S t0, SC_CKSUM_OFFSET(a0)
+#endif
 	move	v0, zero
 	RESTORE_GP64
 	PTR_ADDU sp, FRAMESZ
@@ -311,6 +331,16 @@
 	move	s1, a1				# temp spill
 	move	s0, a0
 
+#if USE_CHECKSUM
+	m_calculate_checksum t0, s0, s2
+	REG_L	s2, SC_CKSUM_OFFSET(s0)
+	beq	t0, s2, 0f
+	nop
+	jal	__bionic_setjmp_checksum_mismatch
+	nop
+0:
+#endif
+
 	# extract savesigs flag
 	REG_L	s2, SC_FLAG_OFFSET(s0)
 	andi	t0, s2, 1
diff --git a/libc/arch-mips/include/machine/elf_machdep.h b/libc/arch-mips/include/machine/elf_machdep.h
index 0aacedf..4db087b 100644
--- a/libc/arch-mips/include/machine/elf_machdep.h
+++ b/libc/arch-mips/include/machine/elf_machdep.h
@@ -121,7 +121,7 @@
 #define	DT_MIPS_GOTSYM		0x70000013	/* first dynamic sym in got */
 #define DT_MIPS_HIPAGENO	0x70000014
 #define	DT_MIPS_RLD_MAP		0x70000016	/* address of loader map */
-#define DT_MIPS_RLD_MAP2	0x70000035	/* offset of loader map, used for PIE */
+#define DT_MIPS_RLD_MAP_REL	0x70000035	/* offset of loader map, used for PIE */
 
 /*
  * ELF Flags
diff --git a/libm/include/mips/machine/fenv.h b/libc/arch-mips/include/machine/fenv.h
similarity index 100%
rename from libm/include/mips/machine/fenv.h
rename to libc/arch-mips/include/machine/fenv.h
diff --git a/libc/arch-mips/mips.mk b/libc/arch-mips/mips.mk
deleted file mode 100644
index b184abb..0000000
--- a/libc/arch-mips/mips.mk
+++ /dev/null
@@ -1,46 +0,0 @@
-# 32-bit mips.
-
-libc_bionic_src_files_mips += \
-    arch-mips/string/memcmp.c \
-    arch-mips/string/memcpy.S \
-    arch-mips/string/memset.S \
-    arch-mips/string/strcmp.S \
-
-#
-# Inherently architecture-specific code.
-#
-
-libc_bionic_src_files_mips += \
-    arch-mips/bionic/__bionic_clone.S \
-    arch-mips/bionic/bzero.S \
-    arch-mips/bionic/cacheflush.cpp \
-    arch-mips/bionic/_exit_with_stack_teardown.S \
-    arch-mips/bionic/setjmp.S \
-    arch-mips/bionic/syscall.S \
-    arch-mips/bionic/vfork.S \
-
-ifndef ARCH_MIPS_REV6
-libc_bionic_src_files_mips += \
-    arch-mips/string/mips_strlen.c \
-
-else
-libc_bionic_src_files_mips += \
-    arch-mips/string/strlen.c \
-
-endif
-
-libc_crt_target_cflags_mips := \
-    $($(my_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS) \
-    -I$(LOCAL_PATH)/arch-mips/include
-
-libc_crt_target_crtbegin_file_mips := \
-    $(LOCAL_PATH)/arch-mips/bionic/crtbegin.c
-
-libc_crt_target_crtbegin_so_file_mips := \
-    $(LOCAL_PATH)/arch-common/bionic/crtbegin_so.c
-
-libc_crt_target_so_cflags_mips := \
-    -fPIC
-
-libc_crt_target_ldflags_mips := \
-    -melf32ltsmip
diff --git a/libc/arch-mips/string/memset.S b/libc/arch-mips/string/memset.S
index 65bb5b5..7ea6753 100644
--- a/libc/arch-mips/string/memset.S
+++ b/libc/arch-mips/string/memset.S
@@ -170,11 +170,6 @@
 # define R6_CODE
 #endif
 
-/* Allow the routine to be named something else if desired.  */
-#ifndef MEMSET_NAME
-# define MEMSET_NAME memset
-#endif
-
 /* We load/store 64 bits at a time when USE_DOUBLE is true.
    The C_ prefix stands for CHUNK and is used to avoid macro name
    conflicts with system header files.  */
@@ -209,9 +204,25 @@
 #define UNITM1(unit) (((unit)*NSIZE)-1)
 
 #ifdef __ANDROID__
-LEAF(MEMSET_NAME,0)
+LEAF(__memset_chk,0)
 #else
-LEAF(MEMSET_NAME)
+LEAF(__memset_chk)
+#endif
+	.set	noreorder
+        sltu    t2, a3, a2
+        beq     t2, zero, memset
+        nop
+        .cpsetup t9, t8, __memset_chk
+        LA      t9, __memset_chk_fail
+        jr      t9
+        nop
+        .set	reorder
+END(__memset_chk)
+
+#ifdef __ANDROID__
+LEAF(memset,0)
+#else
+LEAF(memset)
 #endif
 
 	.set	nomips16
@@ -428,9 +439,10 @@
 
 	.set	at
 	.set	reorder
-END(MEMSET_NAME)
+END(memset)
 #ifndef __ANDROID__
 # ifdef _LIBC
-libc_hidden_builtin_def (MEMSET_NAME)
+libc_hidden_builtin_def (memset)
+libc_hidden_builtin_def (__memset_chk)
 # endif
 #endif
diff --git a/libc/arch-mips/syscalls/__sync_file_range.S b/libc/arch-mips/syscalls/__sync_file_range.S
new file mode 100644
index 0000000..79d41e0
--- /dev/null
+++ b/libc/arch-mips/syscalls/__sync_file_range.S
@@ -0,0 +1,19 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__sync_file_range)
+    .set noreorder
+    .cpload t9
+    li v0, __NR_sync_file_range
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    la t9,__set_errno_internal
+    j t9
+    nop
+    .set reorder
+END(__sync_file_range)
diff --git a/libc/arch-mips/syscalls/quotactl.S b/libc/arch-mips/syscalls/quotactl.S
new file mode 100644
index 0000000..fef336a
--- /dev/null
+++ b/libc/arch-mips/syscalls/quotactl.S
@@ -0,0 +1,19 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(quotactl)
+    .set noreorder
+    .cpload t9
+    li v0, __NR_quotactl
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    la t9,__set_errno_internal
+    j t9
+    nop
+    .set reorder
+END(quotactl)
diff --git a/libc/arch-mips/syscalls/setdomainname.S b/libc/arch-mips/syscalls/setdomainname.S
new file mode 100644
index 0000000..ec0504c
--- /dev/null
+++ b/libc/arch-mips/syscalls/setdomainname.S
@@ -0,0 +1,19 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setdomainname)
+    .set noreorder
+    .cpload t9
+    li v0, __NR_setdomainname
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    la t9,__set_errno_internal
+    j t9
+    nop
+    .set reorder
+END(setdomainname)
diff --git a/libc/arch-mips64/mips64.mk b/libc/arch-mips64/mips64.mk
deleted file mode 100644
index 20ee639..0000000
--- a/libc/arch-mips64/mips64.mk
+++ /dev/null
@@ -1,36 +0,0 @@
-# 64-bit mips.
-
-libc_bionic_src_files_mips64 += \
-    arch-mips/string/memcmp.c \
-    arch-mips/string/memcpy.S \
-    arch-mips/string/memset.S \
-    arch-mips/string/strcmp.S \
-    arch-mips/string/strlen.c \
-
-#
-# Inherently architecture-specific code.
-#
-
-libc_bionic_src_files_mips64 += \
-    arch-mips64/bionic/__bionic_clone.S \
-    arch-mips64/bionic/_exit_with_stack_teardown.S \
-    arch-mips64/bionic/setjmp.S \
-    arch-mips64/bionic/syscall.S \
-    arch-mips64/bionic/vfork.S \
-    arch-mips64/bionic/stat.cpp \
-
-libc_crt_target_cflags_mips64 := \
-    $($(my_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS) \
-    -I$(LOCAL_PATH)/arch-mips64/include \
-
-libc_crt_target_crtbegin_file_mips64 := \
-    $(LOCAL_PATH)/arch-mips64/bionic/crtbegin.c \
-
-libc_crt_target_crtbegin_so_file_mips64 := \
-    $(LOCAL_PATH)/arch-common/bionic/crtbegin_so.c \
-
-libc_crt_target_so_cflags_mips64 := \
-    -fPIC \
-
-libc_crt_target_ldflags_mips64 := \
-    -melf64ltsmip \
diff --git a/libc/arch-mips64/syscalls/__sync_file_range.S b/libc/arch-mips64/syscalls/__sync_file_range.S
new file mode 100644
index 0000000..e22c36e
--- /dev/null
+++ b/libc/arch-mips64/syscalls/__sync_file_range.S
@@ -0,0 +1,26 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__sync_file_range)
+    .set push
+    .set noreorder
+    li v0, __NR_sync_file_range
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(__sync_file_range)
+.hidden __sync_file_range
diff --git a/libc/arch-mips64/syscalls/quotactl.S b/libc/arch-mips64/syscalls/quotactl.S
new file mode 100644
index 0000000..861947c
--- /dev/null
+++ b/libc/arch-mips64/syscalls/quotactl.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(quotactl)
+    .set push
+    .set noreorder
+    li v0, __NR_quotactl
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(quotactl)
diff --git a/libc/arch-mips64/syscalls/setdomainname.S b/libc/arch-mips64/syscalls/setdomainname.S
new file mode 100644
index 0000000..6cee88e
--- /dev/null
+++ b/libc/arch-mips64/syscalls/setdomainname.S
@@ -0,0 +1,25 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setdomainname)
+    .set push
+    .set noreorder
+    li v0, __NR_setdomainname
+    syscall
+    bnez a3, 1f
+    move a0, v0
+    j ra
+    nop
+1:
+    move t0, ra
+    bal     2f
+    nop
+2:
+    .cpsetup ra, t1, 2b
+    LA t9,__set_errno_internal
+    .cpreturn
+    j t9
+    move ra, t0
+    .set pop
+END(setdomainname)
diff --git a/libc/arch-x86/atom/atom.mk b/libc/arch-x86/atom/atom.mk
deleted file mode 100644
index 1afabac..0000000
--- a/libc/arch-x86/atom/atom.mk
+++ /dev/null
@@ -1,27 +0,0 @@
-libc_bionic_src_files_x86 += \
-    arch-x86/atom/string/sse2-bzero-atom.S \
-    arch-x86/atom/string/sse2-memset-atom.S \
-    arch-x86/atom/string/sse2-strlen-atom.S \
-    arch-x86/atom/string/ssse3-bcopy-atom.S \
-    arch-x86/atom/string/ssse3-memcmp-atom.S \
-    arch-x86/atom/string/ssse3-memcpy-atom.S \
-    arch-x86/atom/string/ssse3-memmove-atom.S \
-    arch-x86/atom/string/ssse3-strcpy-atom.S \
-    arch-x86/atom/string/ssse3-strncpy-atom.S \
-    arch-x86/atom/string/ssse3-wmemcmp-atom.S
-
-libc_bionic_src_files_exclude_x86 += \
-    arch-x86/generic/string/memcmp.S \
-
-libc_bionic_src_files_exclude_x86 += \
-    arch-x86/silvermont/string/sse2-bcopy-slm.S \
-    arch-x86/silvermont/string/sse2-bzero-slm.S \
-    arch-x86/silvermont/string/sse2-memcpy-slm.S \
-    arch-x86/silvermont/string/sse2-memmove-slm.S \
-    arch-x86/silvermont/string/sse2-memset-slm.S \
-    arch-x86/silvermont/string/sse2-strcpy-slm.S \
-    arch-x86/silvermont/string/sse2-strlen-slm.S \
-    arch-x86/silvermont/string/sse2-strncpy-slm.S \
-
-libc_freebsd_src_files_exclude_x86 += \
-    upstream-freebsd/lib/libc/string/wmemcmp.c \
diff --git a/libc/arch-x86/atom/string/sse2-bzero-atom.S b/libc/arch-x86/atom/string/sse2-bzero-atom.S
deleted file mode 100644
index 0ddc499..0000000
--- a/libc/arch-x86/atom/string/sse2-bzero-atom.S
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
-Copyright (c) 2010, Intel Corporation
-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.
-
-    * Neither the name of Intel Corporation nor the names of its contributors
-    * may be used to endorse or promote products derived from this software
-    * without specific prior written permission.
-
-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.
-*/
-
-#define USE_AS_BZERO
-#define MEMSET  bzero
-#include "sse2-memset-atom.S"
diff --git a/libc/arch-x86/atom/string/sse2-memset-atom.S b/libc/arch-x86/atom/string/sse2-memset-atom.S
index b0963a1..4e211ca 100644
--- a/libc/arch-x86/atom/string/sse2-memset-atom.S
+++ b/libc/arch-x86/atom/string/sse2-memset-atom.S
@@ -28,6 +28,8 @@
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
+#include <private/bionic_asm.h>
+
 #include "cache.h"
 
 #ifndef L
@@ -38,69 +40,28 @@
 # define ALIGN(n)	.p2align n
 #endif
 
-#ifndef cfi_startproc
-# define cfi_startproc			.cfi_startproc
-#endif
-
-#ifndef cfi_endproc
-# define cfi_endproc			.cfi_endproc
-#endif
-
-#ifndef cfi_rel_offset
-# define cfi_rel_offset(reg, off)	.cfi_rel_offset reg, off
-#endif
-
-#ifndef cfi_restore
-# define cfi_restore(reg)		.cfi_restore reg
-#endif
-
-#ifndef cfi_adjust_cfa_offset
-# define cfi_adjust_cfa_offset(off)	.cfi_adjust_cfa_offset off
-#endif
-
-#ifndef ENTRY
-# define ENTRY(name)			\
-	.type name,  @function; 	\
-	.globl name;			\
-	.p2align 4;			\
-name:					\
-	cfi_startproc
-#endif
-
-#ifndef END
-# define END(name)			\
-	cfi_endproc;			\
-	.size name, .-name
-#endif
-
 #define CFI_PUSH(REG)						\
-  cfi_adjust_cfa_offset (4);					\
-  cfi_rel_offset (REG, 0)
+  .cfi_adjust_cfa_offset 4;					\
+  .cfi_rel_offset REG, 0
 
 #define CFI_POP(REG)						\
-  cfi_adjust_cfa_offset (-4);					\
-  cfi_restore (REG)
+  .cfi_adjust_cfa_offset -4;					\
+  .cfi_restore REG
 
-#define PUSH(REG)	pushl REG; CFI_PUSH (REG)
-#define POP(REG)	popl REG; CFI_POP (REG)
+#define PUSH(REG)	pushl REG; CFI_PUSH(REG)
+#define POP(REG)	popl REG; CFI_POP(REG)
 
-#ifdef USE_AS_BZERO
-# define DEST		PARMS
-# define LEN		DEST+4
-# define SETRTNVAL
-#else
-# define DEST		PARMS
-# define CHR		DEST+4
-# define LEN		CHR+4
-# define SETRTNVAL	movl DEST(%esp), %eax
-#endif
+#define PARMS 8  /* Preserve EBX. */
+#define DST PARMS
+#define CHR (DST+4)
+#define LEN (CHR+4)
+#define CHK_DST_LEN (LEN+4)
+#define SETRTNVAL	movl DST(%esp), %eax
 
-#if (defined SHARED || defined __PIC__)
-# define ENTRANCE	PUSH (%ebx);
-# define RETURN_END	POP (%ebx); ret
-# define RETURN		RETURN_END; CFI_PUSH (%ebx)
-# define PARMS		8		/* Preserve EBX.  */
-# define JMPTBL(I, B)	I - B
+#define ENTRANCE	PUSH(%ebx);
+#define RETURN_END	POP(%ebx); ret
+#define RETURN		RETURN_END; CFI_PUSH(%ebx)
+#define JMPTBL(I, B)	I - B
 
 /* Load an entry in a jump table into EBX and branch to it.  TABLE is a
    jump table with relative offsets.   */
@@ -113,97 +74,88 @@
        absolute address.  */					\
     add		(%ebx,%ecx,4), %ebx;				\
     add		%ecx, %edx;					\
-    /* We loaded the jump table and adjuested EDX. Go.  */	\
+    /* We loaded the jump table and adjusted EDX. Go.  */	\
     jmp		*%ebx
 
 	.section	.gnu.linkonce.t.__x86.get_pc_thunk.bx,"ax",@progbits
 	.globl	__x86.get_pc_thunk.bx
 	.hidden	__x86.get_pc_thunk.bx
-	ALIGN (4)
+	ALIGN(4)
 	.type	__x86.get_pc_thunk.bx,@function
 __x86.get_pc_thunk.bx:
 	movl	(%esp), %ebx
 	ret
-#else
-# define ENTRANCE
-# define RETURN_END	ret
-# define RETURN		RETURN_END
-# define PARMS		4
-# define JMPTBL(I, B)	I
 
-/* Branch to an entry in a jump table.  TABLE is a jump table with
-   absolute offsets.  */
-# define BRANCH_TO_JMPTBL_ENTRY(TABLE)				\
-    add		%ecx, %edx;					\
-    jmp		*TABLE(,%ecx,4)
-#endif
+ENTRY(__memset_chk)
+  ENTRANCE
 
-#ifndef MEMSET
-# define MEMSET memset
-#endif
+  movl LEN(%esp), %ecx
+  cmpl CHK_DST_LEN(%esp), %ecx
+  jna L(memset_length_loaded)
+
+  POP(%ebx) // Undo ENTRANCE without returning.
+  jmp __memset_chk_fail
+END(__memset_chk)
 
 	.section .text.sse2,"ax",@progbits
-	ALIGN (4)
-ENTRY (MEMSET)
+	ALIGN(4)
+ENTRY(memset)
 	ENTRANCE
 
 	movl	LEN(%esp), %ecx
-#ifdef USE_AS_BZERO
-	xor	%eax, %eax
-#else
+L(memset_length_loaded):
 	movzbl	CHR(%esp), %eax
 	movb	%al, %ah
 	/* Fill the whole EAX with pattern.  */
 	movl	%eax, %edx
 	shl	$16, %eax
 	or	%edx, %eax
-#endif
-	movl	DEST(%esp), %edx
+	movl	DST(%esp), %edx
 	cmp	$32, %ecx
 	jae	L(32bytesormore)
 
 L(write_less32bytes):
-	BRANCH_TO_JMPTBL_ENTRY (L(table_less_32bytes))
+	BRANCH_TO_JMPTBL_ENTRY(L(table_less_32bytes))
 
 
 	.pushsection .rodata.sse2,"a",@progbits
-	ALIGN (2)
+	ALIGN(2)
 L(table_less_32bytes):
-	.int	JMPTBL (L(write_0bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_1bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_2bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_3bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_4bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_5bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_6bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_7bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_8bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_9bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_10bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_11bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_12bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_13bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_14bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_15bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_16bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_17bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_18bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_19bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_20bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_21bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_22bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_23bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_24bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_25bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_26bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_27bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_28bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_29bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_30bytes), L(table_less_32bytes))
-	.int	JMPTBL (L(write_31bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_0bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_1bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_2bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_3bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_4bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_5bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_6bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_7bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_8bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_9bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_10bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_11bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_12bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_13bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_14bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_15bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_16bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_17bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_18bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_19bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_20bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_21bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_22bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_23bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_24bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_25bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_26bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_27bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_28bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_29bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_30bytes), L(table_less_32bytes))
+	.int	JMPTBL(L(write_31bytes), L(table_less_32bytes))
 	.popsection
 
-	ALIGN (4)
+	ALIGN(4)
 L(write_28bytes):
 	movl	%eax, -28(%edx)
 L(write_24bytes):
@@ -222,7 +174,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(write_29bytes):
 	movl	%eax, -29(%edx)
 L(write_25bytes):
@@ -242,7 +194,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(write_30bytes):
 	movl	%eax, -30(%edx)
 L(write_26bytes):
@@ -262,7 +214,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(write_31bytes):
 	movl	%eax, -31(%edx)
 L(write_27bytes):
@@ -283,16 +235,12 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 /* ECX > 32 and EDX is 4 byte aligned.  */
 L(32bytesormore):
 	/* Fill xmm0 with the pattern.  */
-#ifdef USE_AS_BZERO
-	pxor	%xmm0, %xmm0
-#else
 	movd	%eax, %xmm0
 	pshufd	$0, %xmm0, %xmm0
-#endif
 	testl	$0xf, %edx
 	jz	L(aligned_16)
 /* ECX > 32 and EDX is not 16 byte aligned.  */
@@ -305,49 +253,25 @@
 	add	%eax, %ecx
 	movd	%xmm0, %eax
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16):
 	cmp	$128, %ecx
 	jae	L(128bytesormore)
 
 L(aligned_16_less128bytes):
-	BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes))
+	BRANCH_TO_JMPTBL_ENTRY(L(table_16_128bytes))
 
-	ALIGN (4)
+	ALIGN(4)
 L(128bytesormore):
-#ifdef SHARED_CACHE_SIZE
-	PUSH (%ebx)
+	PUSH(%ebx)
 	mov	$SHARED_CACHE_SIZE, %ebx
-#else
-# if (defined SHARED || defined __PIC__)
-	call	__x86.get_pc_thunk.bx
-	add	$_GLOBAL_OFFSET_TABLE_, %ebx
-	mov	__x86_shared_cache_size@GOTOFF(%ebx), %ebx
-# else
-	PUSH (%ebx)
-	mov	__x86_shared_cache_size, %ebx
-# endif
-#endif
 	cmp	%ebx, %ecx
 	jae	L(128bytesormore_nt_start)
 
 
-#ifdef DATA_CACHE_SIZE
-	POP (%ebx)
-# define RESTORE_EBX_STATE CFI_PUSH (%ebx)
+	POP(%ebx)
+# define RESTORE_EBX_STATE CFI_PUSH(%ebx)
 	cmp	$DATA_CACHE_SIZE, %ecx
-#else
-# if (defined SHARED || defined __PIC__)
-#  define RESTORE_EBX_STATE
-	call	__x86.get_pc_thunk.bx
-	add	$_GLOBAL_OFFSET_TABLE_, %ebx
-	cmp	__x86_data_cache_size@GOTOFF(%ebx), %ecx
-# else
-	POP (%ebx)
-#  define RESTORE_EBX_STATE CFI_PUSH (%ebx)
-	cmp	__x86_data_cache_size, %ecx
-# endif
-#endif
 
 	jae	L(128bytes_L2_normal)
 	subl	$128, %ecx
@@ -379,9 +303,9 @@
 
 L(128bytesless_normal):
 	add	$128, %ecx
-	BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes))
+	BRANCH_TO_JMPTBL_ENTRY(L(table_16_128bytes))
 
-	ALIGN (4)
+	ALIGN(4)
 L(128bytes_L2_normal):
 	prefetcht0	0x380(%edx)
 	prefetcht0	0x3c0(%edx)
@@ -399,7 +323,7 @@
 	jae	L(128bytes_L2_normal)
 
 L(128bytesless_L2_normal):
-	BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes))
+	BRANCH_TO_JMPTBL_ENTRY(L(table_16_128bytes))
 
 	RESTORE_EBX_STATE
 L(128bytesormore_nt_start):
@@ -408,7 +332,7 @@
 	and	$0x7f, %eax
 	add	%eax, %ecx
 	movd	%xmm0, %eax
-	ALIGN (4)
+	ALIGN(4)
 L(128bytesormore_shared_cache_loop):
 	prefetcht0	0x3c0(%edx)
 	prefetcht0	0x380(%edx)
@@ -426,7 +350,7 @@
 	jae	L(128bytesormore_shared_cache_loop)
 	cmp	$0x80, %ecx
 	jb	L(shared_cache_loop_end)
-	ALIGN (4)
+	ALIGN(4)
 L(128bytesormore_nt):
 	sub	$0x80, %ecx
 	movntdq	%xmm0, (%edx)
@@ -442,146 +366,144 @@
 	jae	L(128bytesormore_nt)
 	sfence
 L(shared_cache_loop_end):
-#if defined DATA_CACHE_SIZE || !(defined SHARED || defined __PIC__)
-	POP (%ebx)
-#endif
-	BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes))
+	POP(%ebx)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_16_128bytes))
 
 
 	.pushsection .rodata.sse2,"a",@progbits
-	ALIGN (2)
+	ALIGN(2)
 L(table_16_128bytes):
-	.int	JMPTBL (L(aligned_16_0bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_1bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_2bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_3bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_4bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_5bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_6bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_7bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_8bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_9bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_10bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_11bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_12bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_13bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_14bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_15bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_16bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_17bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_18bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_19bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_20bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_21bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_22bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_23bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_24bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_25bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_26bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_27bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_28bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_29bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_30bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_31bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_32bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_33bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_34bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_35bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_36bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_37bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_38bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_39bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_40bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_41bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_42bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_43bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_44bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_45bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_46bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_47bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_48bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_49bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_50bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_51bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_52bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_53bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_54bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_55bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_56bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_57bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_58bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_59bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_60bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_61bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_62bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_63bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_64bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_65bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_66bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_67bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_68bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_69bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_70bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_71bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_72bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_73bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_74bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_75bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_76bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_77bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_78bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_79bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_80bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_81bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_82bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_83bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_84bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_85bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_86bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_87bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_88bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_89bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_90bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_91bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_92bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_93bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_94bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_95bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_96bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_97bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_98bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_99bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_100bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_101bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_102bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_103bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_104bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_105bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_106bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_107bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_108bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_109bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_110bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_111bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_112bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_113bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_114bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_115bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_116bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_117bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_118bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_119bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_120bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_121bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_122bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_123bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_124bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_125bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_126bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_127bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_0bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_1bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_2bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_3bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_4bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_5bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_6bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_7bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_8bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_9bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_10bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_11bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_12bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_13bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_14bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_15bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_16bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_17bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_18bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_19bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_20bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_21bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_22bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_23bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_24bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_25bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_26bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_27bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_28bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_29bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_30bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_31bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_32bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_33bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_34bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_35bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_36bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_37bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_38bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_39bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_40bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_41bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_42bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_43bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_44bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_45bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_46bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_47bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_48bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_49bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_50bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_51bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_52bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_53bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_54bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_55bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_56bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_57bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_58bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_59bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_60bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_61bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_62bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_63bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_64bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_65bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_66bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_67bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_68bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_69bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_70bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_71bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_72bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_73bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_74bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_75bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_76bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_77bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_78bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_79bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_80bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_81bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_82bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_83bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_84bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_85bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_86bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_87bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_88bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_89bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_90bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_91bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_92bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_93bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_94bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_95bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_96bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_97bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_98bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_99bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_100bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_101bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_102bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_103bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_104bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_105bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_106bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_107bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_108bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_109bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_110bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_111bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_112bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_113bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_114bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_115bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_116bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_117bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_118bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_119bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_120bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_121bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_122bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_123bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_124bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_125bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_126bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_127bytes), L(table_16_128bytes))
 	.popsection
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_112bytes):
 	movdqa	%xmm0, -112(%edx)
 L(aligned_16_96bytes):
@@ -600,7 +522,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_113bytes):
 	movdqa	%xmm0, -113(%edx)
 L(aligned_16_97bytes):
@@ -620,7 +542,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_114bytes):
 	movdqa	%xmm0, -114(%edx)
 L(aligned_16_98bytes):
@@ -640,7 +562,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_115bytes):
 	movdqa	%xmm0, -115(%edx)
 L(aligned_16_99bytes):
@@ -661,7 +583,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_116bytes):
 	movdqa	%xmm0, -116(%edx)
 L(aligned_16_100bytes):
@@ -681,7 +603,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_117bytes):
 	movdqa	%xmm0, -117(%edx)
 L(aligned_16_101bytes):
@@ -702,7 +624,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_118bytes):
 	movdqa	%xmm0, -118(%edx)
 L(aligned_16_102bytes):
@@ -723,7 +645,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_119bytes):
 	movdqa	%xmm0, -119(%edx)
 L(aligned_16_103bytes):
@@ -745,7 +667,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_120bytes):
 	movdqa	%xmm0, -120(%edx)
 L(aligned_16_104bytes):
@@ -765,7 +687,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_121bytes):
 	movdqa	%xmm0, -121(%edx)
 L(aligned_16_105bytes):
@@ -786,7 +708,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_122bytes):
 	movdqa	%xmm0, -122(%edx)
 L(aligned_16_106bytes):
@@ -807,7 +729,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_123bytes):
 	movdqa	%xmm0, -123(%edx)
 L(aligned_16_107bytes):
@@ -829,7 +751,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_124bytes):
 	movdqa	%xmm0, -124(%edx)
 L(aligned_16_108bytes):
@@ -850,7 +772,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_125bytes):
 	movdqa	%xmm0, -125(%edx)
 L(aligned_16_109bytes):
@@ -872,7 +794,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_126bytes):
 	movdqa	%xmm0, -126(%edx)
 L(aligned_16_110bytes):
@@ -894,7 +816,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_127bytes):
 	movdqa	%xmm0, -127(%edx)
 L(aligned_16_111bytes):
@@ -917,4 +839,4 @@
 	SETRTNVAL
 	RETURN_END
 
-END (MEMSET)
+END(memset)
diff --git a/libc/arch-x86/atom/string/ssse3-bcopy-atom.S b/libc/arch-x86/atom/string/ssse3-bcopy-atom.S
deleted file mode 100644
index e4b791a..0000000
--- a/libc/arch-x86/atom/string/ssse3-bcopy-atom.S
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
-Copyright (c) 2010, Intel Corporation
-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.
-
-    * Neither the name of Intel Corporation nor the names of its contributors
-    * may be used to endorse or promote products derived from this software
-    * without specific prior written permission.
-
-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.
-*/
-
-
-#define MEMCPY	bcopy
-#define USE_AS_MEMMOVE
-#define USE_AS_BCOPY
-#include "ssse3-memcpy-atom.S"
diff --git a/libc/arch-x86/atom/string/ssse3-memcpy-atom.S b/libc/arch-x86/atom/string/ssse3-memcpy-atom.S
index ac5ec2d..4b2fb8e 100644
--- a/libc/arch-x86/atom/string/ssse3-memcpy-atom.S
+++ b/libc/arch-x86/atom/string/ssse3-memcpy-atom.S
@@ -73,15 +73,9 @@
 	.size name, .-name
 #endif
 
-#ifdef USE_AS_BCOPY
-# define SRC		PARMS
-# define DEST		SRC+4
-# define LEN		DEST+4
-#else
-# define DEST		PARMS
-# define SRC		DEST+4
-# define LEN		SRC+4
-#endif
+#define DEST		PARMS
+#define SRC		DEST+4
+#define LEN		SRC+4
 
 #define CFI_PUSH(REG)		\
   cfi_adjust_cfa_offset (4);		\
@@ -2018,12 +2012,10 @@
 L(fwd_write_4bytes):
 	movl	-4(%eax), %ecx
 	movl	%ecx, -4(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN
 
@@ -2044,12 +2036,10 @@
 	movq	-8(%eax), %xmm0
 	movq	%xmm0, -8(%edx)
 L(fwd_write_0bytes):
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN
 
@@ -2059,12 +2049,10 @@
 	movl	-4(%eax), %eax
 	movl	%ecx, -5(%edx)
 	movl	%eax, -4(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN
 
@@ -2088,12 +2076,10 @@
 	movl	%ecx, -5(%edx)
 	movzbl	-1(%eax), %ecx
 	movb	%cl, -1(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN
 
@@ -2116,12 +2102,10 @@
 L(fwd_write_1bytes):
 	movzbl	-1(%eax), %ecx
 	movb	%cl, -1(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN
 
@@ -2146,12 +2130,10 @@
 	movl	%ecx, -6(%edx)
 	movzwl	-2(%eax), %ecx
 	movw	%cx, -2(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN
 
@@ -2174,12 +2156,10 @@
 L(fwd_write_2bytes):
 	movzwl	-2(%eax), %ecx
 	movw	%cx, -2(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN
 
@@ -2206,12 +2186,10 @@
 	movzbl	-1(%eax), %eax
 	movw	%cx, -3(%edx)
 	movb	%al, -1(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN
 
@@ -2236,12 +2214,10 @@
 	movzbl	-1(%eax), %eax
 	movw	%cx, -3(%edx)
 	movb	%al, -1(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN
 
@@ -2256,12 +2232,10 @@
 	movq	-8(%eax), %xmm0
 	movq	%xmm0, -8(%edx)
 L(fwd_write_0bytes_align):
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN
 
@@ -2272,12 +2246,10 @@
 L(fwd_write_16bytes_align):
 	movdqa	-16(%eax), %xmm0
 	movdqa	%xmm0, -16(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN
 
@@ -2287,12 +2259,10 @@
 	movl	-4(%eax), %eax
 	movl	%ecx, -5(%edx)
 	movl	%eax, -4(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN
 
@@ -2310,12 +2280,10 @@
 	movl	%ecx, -5(%edx)
 	movzbl	-1(%eax), %ecx
 	movb	%cl, -1(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN
 
@@ -2330,12 +2298,10 @@
 	movl	%ecx, -5(%edx)
 	movzbl	-1(%eax), %ecx
 	movb	%cl, -1(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN
 
@@ -2352,12 +2318,10 @@
 L(fwd_write_1bytes_align):
 	movzbl	-1(%eax), %ecx
 	movb	%cl, -1(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN
 
@@ -2370,12 +2334,10 @@
 	movdqa	%xmm0, -17(%edx)
 	movzbl	-1(%eax), %ecx
 	movb	%cl, -1(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN
 
@@ -2394,12 +2356,10 @@
 	movl	%ecx, -6(%edx)
 	movzwl	-2(%eax), %ecx
 	movw	%cx, -2(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN
 
@@ -2414,12 +2374,10 @@
 	movl	%ecx, -6(%edx)
 	movzwl	-2(%eax), %ecx
 	movw	%cx, -2(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN
 
@@ -2436,12 +2394,10 @@
 L(fwd_write_2bytes_align):
 	movzwl	-2(%eax), %ecx
 	movw	%cx, -2(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN
 
@@ -2454,12 +2410,10 @@
 	movdqa	%xmm0, -18(%edx)
 	movzwl	-2(%eax), %ecx
 	movw	%cx, -2(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN
 
@@ -2480,12 +2434,10 @@
 	movzbl	-1(%eax), %eax
 	movw	%cx, -3(%edx)
 	movb	%al, -1(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN
 
@@ -2502,12 +2454,10 @@
 	movzbl	-1(%eax), %eax
 	movw	%cx, -3(%edx)
 	movb	%al, -1(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN
 
@@ -2526,12 +2476,10 @@
 	movzbl	-1(%eax), %eax
 	movw	%cx, -3(%edx)
 	movb	%al, -1(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN
 
@@ -2546,12 +2494,10 @@
 	movzbl	-1(%eax), %eax
 	movw	%cx, -3(%edx)
 	movb	%al, -1(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN
 
@@ -2568,12 +2514,10 @@
 L(fwd_write_4bytes_align):
 	movl	-4(%eax), %ecx
 	movl	%ecx, -4(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN
 
@@ -2586,12 +2530,10 @@
 	movdqa	%xmm0, -20(%edx)
 	movl	-4(%eax), %ecx
 	movl	%ecx, -4(%edx)
-#ifndef USE_AS_BCOPY
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	%edx, %eax
-# else
+#else
 	movl	DEST(%esp), %eax
-# endif
 #endif
 	RETURN_END
 
@@ -2685,12 +2627,10 @@
 	movl	(%eax), %ecx
 	movl	%ecx, (%edx)
 L(bk_write_0bytes):
-#ifndef USE_AS_BCOPY
 	movl	DEST(%esp), %eax
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	LEN(%esp), %ecx
 	add	%ecx, %eax
-# endif
 #endif
 	RETURN
 
@@ -2710,12 +2650,10 @@
 L(bk_write_8bytes):
 	movq	(%eax), %xmm0
 	movq	%xmm0, (%edx)
-#ifndef USE_AS_BCOPY
 	movl	DEST(%esp), %eax
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	LEN(%esp), %ecx
 	add	%ecx, %eax
-# endif
 #endif
 	RETURN
 
@@ -2741,12 +2679,10 @@
 L(bk_write_1bytes):
 	movzbl	(%eax), %ecx
 	movb	%cl, (%edx)
-#ifndef USE_AS_BCOPY
 	movl	DEST(%esp), %eax
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	LEN(%esp), %ecx
 	add	%ecx, %eax
-# endif
 #endif
 	RETURN
 
@@ -2768,12 +2704,10 @@
 	movq	%xmm0, 1(%edx)
 	movzbl	(%eax), %ecx
 	movb	%cl, (%edx)
-#ifndef USE_AS_BCOPY
 	movl	DEST(%esp), %eax
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	LEN(%esp), %ecx
 	add	%ecx, %eax
-# endif
 #endif
 	RETURN
 
@@ -2798,12 +2732,10 @@
 	movl	%ecx, 2(%edx)
 	movzwl	(%eax), %ecx
 	movw	%cx, (%edx)
-#ifndef USE_AS_BCOPY
 	movl	DEST(%esp), %eax
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	LEN(%esp), %ecx
 	add	%ecx, %eax
-# endif
 #endif
 	RETURN
 
@@ -2826,12 +2758,10 @@
 L(bk_write_2bytes):
 	movzwl	(%eax), %ecx
 	movw	%cx, (%edx)
-#ifndef USE_AS_BCOPY
 	movl	DEST(%esp), %eax
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	LEN(%esp), %ecx
 	add	%ecx, %eax
-# endif
 #endif
 	RETURN
 
@@ -2858,12 +2788,10 @@
 	movw	%cx, 1(%edx)
 	movzbl	(%eax), %eax
 	movb	%al, (%edx)
-#ifndef USE_AS_BCOPY
 	movl	DEST(%esp), %eax
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	LEN(%esp), %ecx
 	add	%ecx, %eax
-# endif
 #endif
 	RETURN
 
@@ -2888,12 +2816,10 @@
 	movw	%cx, 1(%edx)
 	movzbl	(%eax), %eax
 	movb	%al, (%edx)
-#ifndef USE_AS_BCOPY
 	movl	DEST(%esp), %eax
-# ifdef USE_AS_MEMPCPY
+#ifdef USE_AS_MEMPCPY
 	movl	LEN(%esp), %ecx
 	add	%ecx, %eax
-# endif
 #endif
 	RETURN_END
 
diff --git a/libc/arch-x86/bionic/__set_tls.c b/libc/arch-x86/bionic/__set_tls.cpp
similarity index 92%
rename from libc/arch-x86/bionic/__set_tls.c
rename to libc/arch-x86/bionic/__set_tls.cpp
index 38ed3c9..b26fd56 100644
--- a/libc/arch-x86/bionic/__set_tls.c
+++ b/libc/arch-x86/bionic/__set_tls.cpp
@@ -32,7 +32,7 @@
 
 #include <asm/ldt.h>
 
-extern int __set_thread_area(struct user_desc*);
+extern "C" int __set_thread_area(struct user_desc*);
 
 __LIBC_HIDDEN__ void __init_user_desc(struct user_desc* result, bool allocate, void* base_addr) {
   if (allocate) {
@@ -45,9 +45,9 @@
     result->entry_number = (gs & 0xffff) >> 3;
   }
 
-  result->base_addr = (uintptr_t) base_addr;
+  result->base_addr = reinterpret_cast<uintptr_t>(base_addr);
 
-  result->limit = PAGE_SIZE;
+  result->limit = 0xfffff;
 
   result->seg_32bit = 1;
   result->contents = MODIFY_LDT_CONTENTS_DATA;
@@ -57,7 +57,7 @@
   result->useable = 1;
 }
 
-__LIBC_HIDDEN__ int __set_tls(void* ptr) {
+extern "C" __LIBC_HIDDEN__ int __set_tls(void* ptr) {
   struct user_desc tls_descriptor;
   __init_user_desc(&tls_descriptor, true, ptr);
 
diff --git a/libc/arch-x86/bionic/libgcc_compat.c b/libc/arch-x86/bionic/libgcc_compat.c
index c723263..1a0f566 100644
--- a/libc/arch-x86/bionic/libgcc_compat.c
+++ b/libc/arch-x86/bionic/libgcc_compat.c
@@ -1,4 +1,30 @@
-/* Generated by genlibgcc_compat.py */
+/*
+ * Copyright (C) 2016 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.
+ */
 
 extern char __divdi3;
 extern char __moddi3;
diff --git a/libc/arch-x86/generic/string/bcopy.S b/libc/arch-x86/generic/string/bcopy.S
deleted file mode 100644
index f425c58..0000000
--- a/libc/arch-x86/generic/string/bcopy.S
+++ /dev/null
@@ -1,98 +0,0 @@
-/*	$OpenBSD: bcopy.S,v 1.5 2005/08/07 11:30:38 espie Exp $	*/
-
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from locore.s.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <private/bionic_asm.h>
-
-	/*
-	 * (ov)bcopy (src,dst,cnt)
-	 *  ws@tools.de     (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
-	 */
-
-#if defined(MEMCOPY)
-ENTRY(memcpy)
-#elif defined(MEMMOVE)
-ENTRY(memmove)
-#else
-ENTRY(bcopy)
-#endif
-	pushl	%esi
-	pushl	%edi
-#if defined(MEMCOPY) || defined(MEMMOVE)
-	movl	12(%esp),%edi
-	movl	16(%esp),%esi
-	movl	%edi, %eax
-#else
-	movl	12(%esp),%esi
-	movl	16(%esp),%edi
-#endif
-	movl	20(%esp),%ecx
-	movl	%ecx,%edx
-	cmpl	%esi,%edi	/* potentially overlapping? */
-	jnb	1f
-	cld			/* nope, copy forwards. */
-	shrl	$2,%ecx		/* copy by words */
-	rep
-	movsl
-	movl	%edx,%ecx
-	andl	$3,%ecx		/* any bytes left? */
-	rep
-	movsb
-	popl	%edi
-	popl	%esi
-	ret
-1:
-	addl	%ecx,%edi	/* copy backwards. */
-	addl	%ecx,%esi
-	std
-	andl	$3,%ecx		/* any fractional bytes? */
-	decl	%edi
-	decl	%esi
-	rep
-	movsb
-	movl	%edx,%ecx
-	shrl	$2,%ecx
-	subl	$3,%esi
-	subl	$3,%edi
-	rep
-	movsl
-	popl	%edi
-	popl	%esi
-	cld
-	ret
-#if defined(MEMCOPY)
-END(memcpy)
-#elif defined(MEMMOVE)
-END(memmove)
-#else
-END(bcopy)
-#endif
diff --git a/libc/arch-x86/generic/string/memcpy.S b/libc/arch-x86/generic/string/memcpy.S
deleted file mode 100644
index 95c8a83..0000000
--- a/libc/arch-x86/generic/string/memcpy.S
+++ /dev/null
@@ -1,3 +0,0 @@
-/*	$OpenBSD: memcpy.S,v 1.3 2005/08/07 11:30:38 espie Exp $ */
-#define MEMCOPY
-#include "bcopy.S"
diff --git a/libc/arch-x86/generic/string/memmove.S b/libc/arch-x86/generic/string/memmove.S
deleted file mode 100644
index c5bfd19..0000000
--- a/libc/arch-x86/generic/string/memmove.S
+++ /dev/null
@@ -1,3 +0,0 @@
-/*	$OpenBSD: memmove.S,v 1.3 2005/08/07 11:30:38 espie Exp $ */
-#define MEMMOVE
-#include "bcopy.S"
diff --git a/libm/include/i387/machine/fenv.h b/libc/arch-x86/include/machine/fenv.h
similarity index 100%
rename from libm/include/i387/machine/fenv.h
rename to libc/arch-x86/include/machine/fenv.h
diff --git a/libc/arch-x86/silvermont/silvermont.mk b/libc/arch-x86/silvermont/silvermont.mk
deleted file mode 100644
index e69de29..0000000
--- a/libc/arch-x86/silvermont/silvermont.mk
+++ /dev/null
diff --git a/libc/arch-x86/silvermont/string/sse2-bcopy-slm.S b/libc/arch-x86/silvermont/string/sse2-bcopy-slm.S
deleted file mode 100644
index 190d52f..0000000
--- a/libc/arch-x86/silvermont/string/sse2-bcopy-slm.S
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
-Copyright (c) 2014, Intel Corporation
-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.
-
-    * Neither the name of Intel Corporation nor the names of its contributors
-    * may be used to endorse or promote products derived from this software
-    * without specific prior written permission.
-
-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.
-*/
-
-
-#define MEMMOVE	bcopy
-#define USE_AS_BCOPY
-#include "sse2-memmove-slm.S"
diff --git a/libc/arch-x86/silvermont/string/sse2-bzero-slm.S b/libc/arch-x86/silvermont/string/sse2-bzero-slm.S
deleted file mode 100644
index b682ed6..0000000
--- a/libc/arch-x86/silvermont/string/sse2-bzero-slm.S
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
-Copyright (c) 2014, Intel Corporation
-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.
-
-    * Neither the name of Intel Corporation nor the names of its contributors
-    * may be used to endorse or promote products derived from this software
-    * without specific prior written permission.
-
-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.
-*/
-
-#define USE_AS_BZERO
-#define MEMSET  bzero
-#include "sse2-memset-slm.S"
diff --git a/libc/arch-x86/silvermont/string/sse2-memmove-slm.S b/libc/arch-x86/silvermont/string/sse2-memmove-slm.S
index 6a8f067..bf9f85d 100644
--- a/libc/arch-x86/silvermont/string/sse2-memmove-slm.S
+++ b/libc/arch-x86/silvermont/string/sse2-memmove-slm.S
@@ -73,15 +73,9 @@
 	.size name, .-name
 #endif
 
-#ifdef USE_AS_BCOPY
-# define SRC		PARMS
-# define DEST		SRC+4
-# define LEN		DEST+4
-#else
-# define DEST		PARMS
-# define SRC		DEST+4
-# define LEN		SRC+4
-#endif
+#define DEST		PARMS
+#define SRC		DEST+4
+#define LEN		SRC+4
 
 #define CFI_PUSH(REG)		\
   cfi_adjust_cfa_offset (4);		\
diff --git a/libc/arch-x86/silvermont/string/sse2-memset-slm.S b/libc/arch-x86/silvermont/string/sse2-memset-slm.S
index c30bf74..03a552d 100644
--- a/libc/arch-x86/silvermont/string/sse2-memset-slm.S
+++ b/libc/arch-x86/silvermont/string/sse2-memset-slm.S
@@ -28,11 +28,9 @@
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-#include "cache.h"
+#include <private/bionic_asm.h>
 
-#ifndef MEMSET
-# define MEMSET memset
-#endif
+#include "cache.h"
 
 #ifndef L
 # define L(label)	.L##label
@@ -42,68 +40,27 @@
 # define ALIGN(n)	.p2align n
 #endif
 
-#ifndef cfi_startproc
-# define cfi_startproc			.cfi_startproc
-#endif
-
-#ifndef cfi_endproc
-# define cfi_endproc			.cfi_endproc
-#endif
-
-#ifndef cfi_rel_offset
-# define cfi_rel_offset(reg, off)	.cfi_rel_offset reg, off
-#endif
-
-#ifndef cfi_restore
-# define cfi_restore(reg)		.cfi_restore reg
-#endif
-
-#ifndef cfi_adjust_cfa_offset
-# define cfi_adjust_cfa_offset(off)	.cfi_adjust_cfa_offset off
-#endif
-
-#ifndef ENTRY
-# define ENTRY(name)			\
-	.type name,  @function;		\
-	.globl name;			\
-	.p2align 4;			\
-name:					\
-	cfi_startproc
-#endif
-
-#ifndef END
-# define END(name)			\
-	cfi_endproc;			\
-	.size name, .-name
-#endif
-
 #define CFI_PUSH(REG)						\
-  cfi_adjust_cfa_offset (4);					\
-  cfi_rel_offset (REG, 0)
+  .cfi_adjust_cfa_offset 4;					\
+  .cfi_rel_offset REG, 0
 
 #define CFI_POP(REG)						\
-  cfi_adjust_cfa_offset (-4);					\
-  cfi_restore (REG)
+  .cfi_adjust_cfa_offset -4;					\
+  .cfi_restore REG
 
-#define PUSH(REG)	pushl REG; CFI_PUSH (REG)
-#define POP(REG)	popl REG; CFI_POP (REG)
+#define PUSH(REG)	pushl REG; CFI_PUSH(REG)
+#define POP(REG)	popl REG; CFI_POP(REG)
 
-#ifdef USE_AS_BZERO
-# define DEST		PARMS
-# define LEN		DEST+4
-# define SETRTNVAL
-#else
-# define DEST		PARMS
-# define CHR		DEST+4
-# define LEN		CHR+4
-# define SETRTNVAL	movl DEST(%esp), %eax
-#endif
+#define PARMS 8 /* Preserve EBX. */
+#define DST PARMS
+#define CHR (DST+4)
+#define LEN (CHR+4)
+#define CHK_DST_LEN (LEN+4)
+#define SETRTNVAL	movl DST(%esp), %eax
 
-#if (defined SHARED || defined __PIC__)
-# define ENTRANCE	PUSH (%ebx);
-# define RETURN_END	POP (%ebx); ret
-# define RETURN		RETURN_END; CFI_PUSH (%ebx)
-# define PARMS		8		/* Preserve EBX.  */
+# define ENTRANCE	PUSH(%ebx);
+# define RETURN_END	POP(%ebx); ret
+# define RETURN		RETURN_END; CFI_PUSH(%ebx)
 # define JMPTBL(I, B)	I - B
 
 /* Load an entry in a jump table into EBX and branch to it.  TABLE is a
@@ -117,54 +74,49 @@
        absolute address.  */					\
     add		(%ebx,%ecx,4), %ebx;				\
     add		%ecx, %edx;					\
-    /* We loaded the jump table and adjuested EDX. Go.  */	\
+    /* We loaded the jump table and adjusted EDX. Go.  */	\
     jmp		*%ebx
 
 	.section	.gnu.linkonce.t.__x86.get_pc_thunk.bx,"ax",@progbits
 	.globl	__x86.get_pc_thunk.bx
 	.hidden	__x86.get_pc_thunk.bx
-	ALIGN (4)
+	ALIGN(4)
 	.type	__x86.get_pc_thunk.bx,@function
 __x86.get_pc_thunk.bx:
 	movl	(%esp), %ebx
 	ret
-#else
-# define ENTRANCE
-# define RETURN_END	ret
-# define RETURN		RETURN_END
-# define PARMS		4
-# define JMPTBL(I, B)	I
 
-/* Branch to an entry in a jump table.  TABLE is a jump table with
-   absolute offsets.  */
-# define BRANCH_TO_JMPTBL_ENTRY(TABLE)				\
-    add		%ecx, %edx;					\
-    jmp		*TABLE(,%ecx,4)
-#endif
+ENTRY(__memset_chk)
+  ENTRANCE
+
+  movl LEN(%esp), %ecx
+  cmpl CHK_DST_LEN(%esp), %ecx
+  jna L(memset_length_loaded)
+
+  POP(%ebx) // Undo ENTRANCE without returning.
+  jmp __memset_chk_fail
+END(__memset_chk)
 
 	.section .text.sse2,"ax",@progbits
-	ALIGN (4)
-ENTRY (MEMSET)
+	ALIGN(4)
+ENTRY(memset)
 	ENTRANCE
 
 	movl	LEN(%esp), %ecx
+L(memset_length_loaded):
 	cmp	$0, %ecx
 	ja	L(1byteormore)
 	SETRTNVAL
 	RETURN
 
 L(1byteormore):
-#ifdef USE_AS_BZERO
-	xor	%eax, %eax
-#else
 	movzbl	CHR(%esp), %eax
 	movb	%al, %ah
 	/* Fill the whole EAX with pattern.  */
 	movl	%eax, %edx
 	shl	 $16, %eax
 	or	%edx, %eax
-#endif
-	movl	DEST(%esp), %edx
+	movl	DST(%esp), %edx
 	cmp	$1, %ecx
 	je	L(1byte)
 	cmp	$16, %ecx
@@ -193,14 +145,10 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(16bytesormore):
-#ifdef USE_AS_BZERO
-	pxor	%xmm0, %xmm0
-#else
 	movd	%eax, %xmm0
 	pshufd	$0, %xmm0, %xmm0
-#endif
 
 	cmp	$64, %ecx
 	ja	L(64bytesmore)
@@ -226,47 +174,25 @@
 	add	%eax, %ecx
 	movd	%xmm0, %eax
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16):
 	cmp	$128, %ecx
 	jae	L(128bytesormore)
 
 L(aligned_16_less128bytes):
-	BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes))
+	BRANCH_TO_JMPTBL_ENTRY(L(table_16_128bytes))
 
-	ALIGN (4)
+	ALIGN(4)
 L(128bytesormore):
-#ifdef SHARED_CACHE_SIZE
-	PUSH (%ebx)
+	PUSH(%ebx)
 	mov	$SHARED_CACHE_SIZE, %ebx
-#else
-# if (defined SHARED || defined __PIC__)
-	call	__x86.get_pc_thunk.bx
-	add	$_GLOBAL_OFFSET_TABLE_, %ebx
-	mov	$__x86_shared_cache_size@GOTOFF(%ebx), %ebx
-# else
-	PUSH (%ebx)
-	mov	$__x86_shared_cache_size, %ebx
-# endif
-#endif
 	cmp	%ebx, %ecx
 	jae	L(128bytesormore_nt_start)
 
-	POP (%ebx)
+	POP(%ebx)
 
-#ifdef DATA_CACHE_SIZE
-	PUSH (%ebx)
+	PUSH(%ebx)
 	mov	$DATA_CACHE_SIZE, %ebx
-#else
-# if (defined SHARED || defined __PIC__)
-	call	__x86.get_pc_thunk.bx
-	add	$_GLOBAL_OFFSET_TABLE_, %ebx
-	mov	$__x86_data_cache_size@GOTOFF(%ebx), %ebx
-# else
-	PUSH (%ebx)
-	mov	$__x86_data_cache_size, %ebx
-# endif
-#endif
 
 	cmp	%ebx, %ecx
 	jae	L(128bytes_L2_normal)
@@ -299,12 +225,10 @@
 
 L(128bytesless_normal):
 	lea	128(%ecx), %ecx
-#if defined DATA_CACHE_SIZE || !(defined SHARED || defined __PIC__)
-	POP (%ebx)
-#endif
-	BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes))
+	POP(%ebx)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_16_128bytes))
 
-	ALIGN (4)
+	ALIGN(4)
 L(128bytes_L2_normal):
 	prefetchnta	0x380(%edx)
 	prefetchnta	0x3c0(%edx)
@@ -322,14 +246,12 @@
 	jae	L(128bytes_L2_normal)
 
 L(128bytesless_L2_normal):
-#if defined DATA_CACHE_SIZE || !(defined SHARED || defined __PIC__)
-	POP (%ebx)
-#endif
-	BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes))
+	POP(%ebx)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_16_128bytes))
 
 L(128bytesormore_nt_start):
 	sub	%ebx, %ecx
-	ALIGN (4)
+	ALIGN(4)
 L(128bytesormore_shared_cache_loop):
 	prefetchnta	0x3c0(%edx)
 	prefetchnta	0x380(%edx)
@@ -347,7 +269,7 @@
 	jae	L(128bytesormore_shared_cache_loop)
 	cmp	$0x80, %ecx
 	jb	L(shared_cache_loop_end)
-	ALIGN (4)
+	ALIGN(4)
 L(128bytesormore_nt):
 	sub	$0x80, %ecx
 	movntdq	%xmm0, (%edx)
@@ -363,146 +285,144 @@
 	jae	L(128bytesormore_nt)
 	sfence
 L(shared_cache_loop_end):
-#if defined SHARED_CACHE_SIZE || !(defined SHARED || defined __PIC__)
-	POP (%ebx)
-#endif
-	BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes))
+	POP(%ebx)
+	BRANCH_TO_JMPTBL_ENTRY(L(table_16_128bytes))
 
 
 	.pushsection .rodata.sse2,"a",@progbits
-	ALIGN (2)
+	ALIGN(2)
 L(table_16_128bytes):
-	.int	JMPTBL (L(aligned_16_0bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_1bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_2bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_3bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_4bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_5bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_6bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_7bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_8bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_9bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_10bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_11bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_12bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_13bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_14bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_15bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_16bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_17bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_18bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_19bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_20bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_21bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_22bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_23bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_24bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_25bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_26bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_27bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_28bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_29bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_30bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_31bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_32bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_33bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_34bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_35bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_36bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_37bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_38bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_39bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_40bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_41bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_42bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_43bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_44bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_45bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_46bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_47bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_48bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_49bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_50bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_51bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_52bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_53bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_54bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_55bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_56bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_57bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_58bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_59bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_60bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_61bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_62bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_63bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_64bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_65bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_66bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_67bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_68bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_69bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_70bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_71bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_72bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_73bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_74bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_75bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_76bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_77bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_78bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_79bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_80bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_81bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_82bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_83bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_84bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_85bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_86bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_87bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_88bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_89bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_90bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_91bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_92bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_93bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_94bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_95bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_96bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_97bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_98bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_99bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_100bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_101bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_102bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_103bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_104bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_105bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_106bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_107bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_108bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_109bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_110bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_111bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_112bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_113bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_114bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_115bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_116bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_117bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_118bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_119bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_120bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_121bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_122bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_123bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_124bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_125bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_126bytes), L(table_16_128bytes))
-	.int	JMPTBL (L(aligned_16_127bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_0bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_1bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_2bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_3bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_4bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_5bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_6bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_7bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_8bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_9bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_10bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_11bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_12bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_13bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_14bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_15bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_16bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_17bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_18bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_19bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_20bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_21bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_22bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_23bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_24bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_25bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_26bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_27bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_28bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_29bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_30bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_31bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_32bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_33bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_34bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_35bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_36bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_37bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_38bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_39bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_40bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_41bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_42bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_43bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_44bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_45bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_46bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_47bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_48bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_49bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_50bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_51bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_52bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_53bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_54bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_55bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_56bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_57bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_58bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_59bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_60bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_61bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_62bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_63bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_64bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_65bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_66bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_67bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_68bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_69bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_70bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_71bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_72bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_73bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_74bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_75bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_76bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_77bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_78bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_79bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_80bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_81bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_82bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_83bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_84bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_85bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_86bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_87bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_88bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_89bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_90bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_91bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_92bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_93bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_94bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_95bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_96bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_97bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_98bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_99bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_100bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_101bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_102bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_103bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_104bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_105bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_106bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_107bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_108bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_109bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_110bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_111bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_112bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_113bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_114bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_115bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_116bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_117bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_118bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_119bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_120bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_121bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_122bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_123bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_124bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_125bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_126bytes), L(table_16_128bytes))
+	.int	JMPTBL(L(aligned_16_127bytes), L(table_16_128bytes))
 	.popsection
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_112bytes):
 	movdqa	%xmm0, -112(%edx)
 L(aligned_16_96bytes):
@@ -521,7 +441,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_113bytes):
 	movdqa	%xmm0, -113(%edx)
 L(aligned_16_97bytes):
@@ -541,7 +461,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_114bytes):
 	movdqa	%xmm0, -114(%edx)
 L(aligned_16_98bytes):
@@ -561,7 +481,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_115bytes):
 	movdqa	%xmm0, -115(%edx)
 L(aligned_16_99bytes):
@@ -582,7 +502,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_116bytes):
 	movdqa	%xmm0, -116(%edx)
 L(aligned_16_100bytes):
@@ -602,7 +522,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_117bytes):
 	movdqa	%xmm0, -117(%edx)
 L(aligned_16_101bytes):
@@ -623,7 +543,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_118bytes):
 	movdqa	%xmm0, -118(%edx)
 L(aligned_16_102bytes):
@@ -644,7 +564,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_119bytes):
 	movdqa	%xmm0, -119(%edx)
 L(aligned_16_103bytes):
@@ -666,7 +586,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_120bytes):
 	movdqa	%xmm0, -120(%edx)
 L(aligned_16_104bytes):
@@ -686,7 +606,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_121bytes):
 	movdqa	%xmm0, -121(%edx)
 L(aligned_16_105bytes):
@@ -707,7 +627,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_122bytes):
 	movdqa	%xmm0, -122(%edx)
 L(aligned_16_106bytes):
@@ -728,7 +648,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_123bytes):
 	movdqa	%xmm0, -123(%edx)
 L(aligned_16_107bytes):
@@ -750,7 +670,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_124bytes):
 	movdqa	%xmm0, -124(%edx)
 L(aligned_16_108bytes):
@@ -771,7 +691,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_125bytes):
 	movdqa	%xmm0, -125(%edx)
 L(aligned_16_109bytes):
@@ -793,7 +713,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_126bytes):
 	movdqa	%xmm0, -126(%edx)
 L(aligned_16_110bytes):
@@ -815,7 +735,7 @@
 	SETRTNVAL
 	RETURN
 
-	ALIGN (4)
+	ALIGN(4)
 L(aligned_16_127bytes):
 	movdqa	%xmm0, -127(%edx)
 L(aligned_16_111bytes):
@@ -838,4 +758,4 @@
 	SETRTNVAL
 	RETURN_END
 
-END (MEMSET)
+END(memset)
diff --git a/libc/arch-x86/syscalls/__sync_file_range.S b/libc/arch-x86/syscalls/__sync_file_range.S
new file mode 100644
index 0000000..f5bf3ec
--- /dev/null
+++ b/libc/arch-x86/syscalls/__sync_file_range.S
@@ -0,0 +1,54 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__sync_file_range)
+    pushl   %ebx
+    .cfi_def_cfa_offset 8
+    .cfi_rel_offset ebx, 0
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+    pushl   %edi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edi, 0
+    pushl   %ebp
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ebp, 0
+
+    call    __kernel_syscall
+    pushl   %eax
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset eax, 0
+
+    mov     32(%esp), %ebx
+    mov     36(%esp), %ecx
+    mov     40(%esp), %edx
+    mov     44(%esp), %esi
+    mov     48(%esp), %edi
+    mov     52(%esp), %ebp
+    movl    $__NR_sync_file_range, %eax
+    call    *(%esp)
+    addl    $4, %esp
+
+    cmpl    $-MAX_ERRNO, %eax
+    jb      1f
+    negl    %eax
+    pushl   %eax
+    call    __set_errno_internal
+    addl    $4, %esp
+1:
+    popl    %ebp
+    popl    %edi
+    popl    %esi
+    popl    %edx
+    popl    %ecx
+    popl    %ebx
+    ret
+END(__sync_file_range)
diff --git a/libc/arch-x86/syscalls/quotactl.S b/libc/arch-x86/syscalls/quotactl.S
new file mode 100644
index 0000000..326cf87
--- /dev/null
+++ b/libc/arch-x86/syscalls/quotactl.S
@@ -0,0 +1,44 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(quotactl)
+    pushl   %ebx
+    .cfi_def_cfa_offset 8
+    .cfi_rel_offset ebx, 0
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+    pushl   %edx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset edx, 0
+    pushl   %esi
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset esi, 0
+
+    call    __kernel_syscall
+    pushl   %eax
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset eax, 0
+
+    mov     24(%esp), %ebx
+    mov     28(%esp), %ecx
+    mov     32(%esp), %edx
+    mov     36(%esp), %esi
+    movl    $__NR_quotactl, %eax
+    call    *(%esp)
+    addl    $4, %esp
+
+    cmpl    $-MAX_ERRNO, %eax
+    jb      1f
+    negl    %eax
+    pushl   %eax
+    call    __set_errno_internal
+    addl    $4, %esp
+1:
+    popl    %esi
+    popl    %edx
+    popl    %ecx
+    popl    %ebx
+    ret
+END(quotactl)
diff --git a/libc/arch-x86/syscalls/setdomainname.S b/libc/arch-x86/syscalls/setdomainname.S
new file mode 100644
index 0000000..8b6afe2
--- /dev/null
+++ b/libc/arch-x86/syscalls/setdomainname.S
@@ -0,0 +1,34 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setdomainname)
+    pushl   %ebx
+    .cfi_def_cfa_offset 8
+    .cfi_rel_offset ebx, 0
+    pushl   %ecx
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset ecx, 0
+
+    call    __kernel_syscall
+    pushl   %eax
+    .cfi_adjust_cfa_offset 4
+    .cfi_rel_offset eax, 0
+
+    mov     16(%esp), %ebx
+    mov     20(%esp), %ecx
+    movl    $__NR_setdomainname, %eax
+    call    *(%esp)
+    addl    $4, %esp
+
+    cmpl    $-MAX_ERRNO, %eax
+    jb      1f
+    negl    %eax
+    pushl   %eax
+    call    __set_errno_internal
+    addl    $4, %esp
+1:
+    popl    %ecx
+    popl    %ebx
+    ret
+END(setdomainname)
diff --git a/libc/arch-x86/x86.mk b/libc/arch-x86/x86.mk
deleted file mode 100644
index 1d717aa..0000000
--- a/libc/arch-x86/x86.mk
+++ /dev/null
@@ -1,140 +0,0 @@
-# 32-bit x86.
-
-#
-# Generic x86 optimizations, may be overriden by CPU variants.
-#
-
-libc_bionic_src_files_x86 += \
-    arch-x86/atom/string/sse2-memchr-atom.S \
-    arch-x86/atom/string/sse2-memrchr-atom.S \
-    arch-x86/atom/string/sse2-strchr-atom.S \
-    arch-x86/atom/string/sse2-strnlen-atom.S \
-    arch-x86/atom/string/sse2-strrchr-atom.S \
-    arch-x86/atom/string/sse2-wcschr-atom.S \
-    arch-x86/atom/string/sse2-wcsrchr-atom.S \
-    arch-x86/atom/string/sse2-wcslen-atom.S \
-    arch-x86/atom/string/sse2-wcscmp-atom.S \
-    arch-x86/silvermont/string/sse2-bcopy-slm.S \
-    arch-x86/silvermont/string/sse2-bzero-slm.S \
-    arch-x86/silvermont/string/sse2-memcpy-slm.S \
-    arch-x86/silvermont/string/sse2-memmove-slm.S \
-    arch-x86/silvermont/string/sse2-memset-slm.S \
-    arch-x86/silvermont/string/sse2-stpcpy-slm.S \
-    arch-x86/silvermont/string/sse2-stpncpy-slm.S \
-    arch-x86/silvermont/string/sse2-strcpy-slm.S \
-    arch-x86/silvermont/string/sse2-strlen-slm.S \
-    arch-x86/silvermont/string/sse2-strncpy-slm.S
-
-libc_bionic_src_files_x86 += \
-    arch-x86/generic/string/memcmp.S \
-    arch-x86/generic/string/strcmp.S \
-    arch-x86/generic/string/strncmp.S \
-    arch-x86/generic/string/strcat.S
-
-ifeq ($(ARCH_X86_HAVE_SSSE3),true)
-libc_bionic_src_files_x86 += \
-    arch-x86/atom/string/ssse3-strncat-atom.S \
-    arch-x86/atom/string/ssse3-strlcat-atom.S \
-    arch-x86/atom/string/ssse3-strlcpy-atom.S \
-    arch-x86/atom/string/ssse3-strcmp-atom.S \
-    arch-x86/atom/string/ssse3-strncmp-atom.S \
-    arch-x86/atom/string/ssse3-strcat-atom.S \
-    arch-x86/atom/string/ssse3-wcscat-atom.S \
-    arch-x86/atom/string/ssse3-wcscpy-atom.S
-libc_bionic_src_files_exclude_x86 += \
-    arch-x86/generic/string/strcmp.S \
-    arch-x86/generic/string/strncmp.S \
-    arch-x86/generic/string/strcat.S
-endif
-
-ifeq ($(ARCH_X86_HAVE_SSE4),true)
-libc_bionic_src_files_x86 += \
-    arch-x86/silvermont/string/sse4-memcmp-slm.S \
-    arch-x86/silvermont/string/sse4-wmemcmp-slm.S
-libc_bionic_src_files_exclude_x86 += \
-    arch-x86/generic/string/memcmp.S
-endif
-
-#
-# Remove default implementations that we have optimized versions of.
-#
-
-libc_freebsd_src_files_exclude_x86 += \
-    upstream-freebsd/lib/libc/string/wcschr.c \
-    upstream-freebsd/lib/libc/string/wcscmp.c \
-    upstream-freebsd/lib/libc/string/wcslen.c \
-    upstream-freebsd/lib/libc/string/wcsrchr.c \
-
-ifeq ($(ARCH_X86_HAVE_SSSE3),true)
-libc_freebsd_src_files_exclude_x86 += \
-    upstream-freebsd/lib/libc/string/wcscat.c \
-    upstream-freebsd/lib/libc/string/wcscpy.c
-endif
-
-ifeq ($(ARCH_X86_HAVE_SSE4),true)
-libc_freebsd_src_files_exclude_x86 += \
-    upstream-freebsd/lib/libc/string/wmemcmp.c
-endif
-
-libc_openbsd_src_files_exclude_x86 += \
-    upstream-openbsd/lib/libc/string/memchr.c \
-    upstream-openbsd/lib/libc/string/memmove.c \
-    upstream-openbsd/lib/libc/string/memrchr.c \
-    upstream-openbsd/lib/libc/string/stpcpy.c \
-    upstream-openbsd/lib/libc/string/stpncpy.c \
-    upstream-openbsd/lib/libc/string/strcat.c \
-    upstream-openbsd/lib/libc/string/strcpy.c \
-    upstream-openbsd/lib/libc/string/strncmp.c \
-    upstream-openbsd/lib/libc/string/strncpy.c \
-
-ifeq ($(ARCH_X86_HAVE_SSSE3),true)
-libc_openbsd_src_files_exclude_x86 += \
-    upstream-openbsd/lib/libc/string/strlcat.c \
-    upstream-openbsd/lib/libc/string/strlcpy.c \
-    upstream-openbsd/lib/libc/string/strncat.c
-endif
-
-libc_bionic_src_files_exclude_x86 += \
-    bionic/strchr.cpp \
-    bionic/strnlen.c \
-    bionic/strrchr.cpp \
-
-#
-# Inherently architecture-specific functions.
-#
-
-libc_bionic_src_files_x86 += \
-    arch-x86/bionic/__bionic_clone.S \
-    arch-x86/bionic/_exit_with_stack_teardown.S \
-    arch-x86/bionic/libgcc_compat.c \
-    arch-x86/bionic/__restore.S \
-    arch-x86/bionic/setjmp.S \
-    arch-x86/bionic/syscall.S \
-    arch-x86/bionic/vfork.S \
-
-## ARCH variant specific source files
-arch_variant_mk := $(LOCAL_PATH)/arch-x86/$(TARGET_ARCH_VARIANT)/$(TARGET_ARCH_VARIANT).mk
-ifeq ($(wildcard $(arch_variant_mk)),)
-    arch_variant_mk :=
-endif
-ifneq ($(arch_variant_mk),)
-include $(arch_variant_mk)
-libc_common_additional_dependencies += $(arch_variant_mk)
-
-arch_variant_mk :=
-endif
-
-libc_crt_target_cflags_x86 := \
-    -m32 \
-    -I$(LOCAL_PATH)/arch-x86/include
-
-libc_crt_target_ldflags_x86 := -melf_i386
-
-libc_crt_target_crtbegin_file_x86 := \
-     $(LOCAL_PATH)/arch-common/bionic/crtbegin.c
-
-libc_crt_target_crtbegin_so_file_x86 := \
-    $(LOCAL_PATH)/arch-common/bionic/crtbegin_so.c
-
-libc_crt_target_so_cflags_x86 := \
-    -fPIC
diff --git a/libm/include/amd64/machine/fenv.h b/libc/arch-x86_64/include/machine/fenv.h
similarity index 100%
rename from libm/include/amd64/machine/fenv.h
rename to libc/arch-x86_64/include/machine/fenv.h
diff --git a/libc/arch-x86_64/string/sse2-memset-slm.S b/libc/arch-x86_64/string/sse2-memset-slm.S
index bfcafae..fc502c0 100644
--- a/libc/arch-x86_64/string/sse2-memset-slm.S
+++ b/libc/arch-x86_64/string/sse2-memset-slm.S
@@ -28,11 +28,9 @@
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-#include "cache.h"
+#include <private/bionic_asm.h>
 
-#ifndef MEMSET
-# define MEMSET		memset
-#endif
+#include "cache.h"
 
 #ifndef L
 # define L(label)	.L##label
@@ -42,39 +40,21 @@
 # define ALIGN(n)	.p2align n
 #endif
 
-#ifndef cfi_startproc
-# define cfi_startproc			.cfi_startproc
-#endif
 
-#ifndef cfi_endproc
-# define cfi_endproc			.cfi_endproc
-#endif
+ENTRY(__memset_chk)
+  # %rdi = dst, %rsi = byte, %rdx = n, %rcx = dst_len
+  cmp %rcx, %rdx
+  ja __memset_chk_fail
+  // Fall through to memset...
+END(__memset_chk)
 
-#ifndef ENTRY
-# define ENTRY(name)			\
-	.type name,  @function;	\
-	.globl name;			\
-name:					\
-	cfi_startproc
-#endif
-
-#ifndef END
-# define END(name)			\
-	cfi_endproc;			\
-	.size name, .-name
-#endif
 
 	.section .text.sse2,"ax",@progbits
-ENTRY (MEMSET)
+ENTRY(memset)
 	movq	%rdi, %rax
-#ifdef USE_AS_BZERO_P
-	mov	%rsi, %rdx
-	xor	%rcx, %rcx
-#else
 	and	$0xff, %rsi
 	mov	$0x0101010101010101, %rcx
 	imul	%rsi, %rcx
-#endif
 	cmpq	$16, %rdx
 	jae	L(16bytesormore)
 	testb	$8, %dl
@@ -106,12 +86,8 @@
 
 	ALIGN (4)
 L(16bytesormore):
-#ifdef USE_AS_BZERO_P
-	pxor	%xmm0, %xmm0
-#else
 	movd	%rcx, %xmm0
 	pshufd	$0, %xmm0, %xmm0
-#endif
 	movdqu	%xmm0, (%rdi)
 	movdqu	%xmm0, -16(%rdi, %rdx)
 	cmpq	$32, %rdx
@@ -170,4 +146,4 @@
 	sfence
 	ret
 
-END (MEMSET)
+END(memset)
diff --git a/libc/arch-x86_64/syscalls/__sync_file_range.S b/libc/arch-x86_64/syscalls/__sync_file_range.S
new file mode 100644
index 0000000..6a2c430
--- /dev/null
+++ b/libc/arch-x86_64/syscalls/__sync_file_range.S
@@ -0,0 +1,17 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(__sync_file_range)
+    movq    %rcx, %r10
+    movl    $__NR_sync_file_range, %eax
+    syscall
+    cmpq    $-MAX_ERRNO, %rax
+    jb      1f
+    negl    %eax
+    movl    %eax, %edi
+    call    __set_errno_internal
+1:
+    ret
+END(__sync_file_range)
+.hidden __sync_file_range
diff --git a/libc/arch-x86_64/syscalls/quotactl.S b/libc/arch-x86_64/syscalls/quotactl.S
new file mode 100644
index 0000000..427358a
--- /dev/null
+++ b/libc/arch-x86_64/syscalls/quotactl.S
@@ -0,0 +1,16 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(quotactl)
+    movq    %rcx, %r10
+    movl    $__NR_quotactl, %eax
+    syscall
+    cmpq    $-MAX_ERRNO, %rax
+    jb      1f
+    negl    %eax
+    movl    %eax, %edi
+    call    __set_errno_internal
+1:
+    ret
+END(quotactl)
diff --git a/libc/arch-x86_64/syscalls/setdomainname.S b/libc/arch-x86_64/syscalls/setdomainname.S
new file mode 100644
index 0000000..40d1a33
--- /dev/null
+++ b/libc/arch-x86_64/syscalls/setdomainname.S
@@ -0,0 +1,15 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(setdomainname)
+    movl    $__NR_setdomainname, %eax
+    syscall
+    cmpq    $-MAX_ERRNO, %rax
+    jb      1f
+    negl    %eax
+    movl    %eax, %edi
+    call    __set_errno_internal
+1:
+    ret
+END(setdomainname)
diff --git a/libc/arch-x86_64/x86_64.mk b/libc/arch-x86_64/x86_64.mk
deleted file mode 100644
index ce06217..0000000
--- a/libc/arch-x86_64/x86_64.mk
+++ /dev/null
@@ -1,65 +0,0 @@
-# 64-bit x86.
-
-#
-# Remove default implementations that we have optimized versions of.
-#
-
-libc_openbsd_src_files_exclude_x86_64 += \
-    upstream-openbsd/lib/libc/string/memmove.c \
-    upstream-openbsd/lib/libc/string/stpcpy.c \
-    upstream-openbsd/lib/libc/string/stpncpy.c \
-    upstream-openbsd/lib/libc/string/strcat.c \
-    upstream-openbsd/lib/libc/string/strcpy.c \
-    upstream-openbsd/lib/libc/string/strlcat.c \
-    upstream-openbsd/lib/libc/string/strlcpy.c \
-    upstream-openbsd/lib/libc/string/strncat.c \
-    upstream-openbsd/lib/libc/string/strncmp.c \
-    upstream-openbsd/lib/libc/string/strncpy.c \
-
-#
-# Inherently architecture-specific code.
-#
-
-libc_bionic_src_files_x86_64 += \
-    arch-x86_64/bionic/__bionic_clone.S \
-    arch-x86_64/bionic/_exit_with_stack_teardown.S \
-    arch-x86_64/bionic/__restore_rt.S \
-    arch-x86_64/bionic/setjmp.S \
-    arch-x86_64/bionic/syscall.S \
-    arch-x86_64/bionic/vfork.S \
-
-#
-# Optimized memory/string functions.
-#
-
-libc_bionic_src_files_x86_64 += \
-    arch-x86_64/string/sse2-memcpy-slm.S \
-    arch-x86_64/string/sse2-memmove-slm.S \
-    arch-x86_64/string/sse2-memset-slm.S \
-    arch-x86_64/string/sse2-stpcpy-slm.S \
-    arch-x86_64/string/sse2-stpncpy-slm.S \
-    arch-x86_64/string/sse2-strcat-slm.S \
-    arch-x86_64/string/sse2-strcpy-slm.S \
-    arch-x86_64/string/sse2-strlcat-slm.S \
-    arch-x86_64/string/sse2-strlcpy-slm.S \
-    arch-x86_64/string/sse2-strlen-slm.S \
-    arch-x86_64/string/sse2-strncat-slm.S \
-    arch-x86_64/string/sse2-strncpy-slm.S \
-    arch-x86_64/string/sse4-memcmp-slm.S \
-    arch-x86_64/string/ssse3-strcmp-slm.S \
-    arch-x86_64/string/ssse3-strncmp-slm.S \
-
-libc_crt_target_cflags_x86_64 += \
-    -m64 \
-    -I$(LOCAL_PATH)/arch-x86_64/include \
-
-libc_crt_target_ldflags_x86_64 := -melf_x86_64 \
-
-libc_crt_target_crtbegin_file_x86_64 := \
-    $(LOCAL_PATH)/arch-common/bionic/crtbegin.c \
-
-libc_crt_target_crtbegin_so_file_x86_64 := \
-    $(LOCAL_PATH)/arch-common/bionic/crtbegin_so.c \
-
-libc_crt_target_so_cflags_x86_64 := \
-    -fPIC \
diff --git a/libc/bionic/__FD_chk.cpp b/libc/bionic/__FD_chk.cpp
deleted file mode 100644
index af8427a..0000000
--- a/libc/bionic/__FD_chk.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2013 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.
- */
-
-#undef _FORTIFY_SOURCE
-#include <sys/select.h>
-#include "private/libc_logging.h"
-
-extern "C" int __FD_ISSET_chk(int fd, fd_set* set, size_t set_size) {
-  if (__predict_false(fd < 0)) {
-    __fortify_chk_fail("FD_ISSET: file descriptor < 0", 0);
-  }
-  if (__predict_false(fd >= FD_SETSIZE)) {
-    __fortify_chk_fail("FD_ISSET: file descriptor >= FD_SETSIZE", 0);
-  }
-  if (__predict_false(set_size < sizeof(fd_set))) {
-    __fortify_chk_fail("FD_ISSET: set is too small", 0);
-  }
-  return FD_ISSET(fd, set);
-}
-
-extern "C" void __FD_CLR_chk(int fd, fd_set* set, size_t set_size) {
-  if (__predict_false(fd < 0)) {
-    __fortify_chk_fail("FD_CLR: file descriptor < 0", 0);
-  }
-  if (__predict_false(fd >= FD_SETSIZE)) {
-    __fortify_chk_fail("FD_CLR: file descriptor >= FD_SETSIZE", 0);
-  }
-  if (__predict_false(set_size < sizeof(fd_set))) {
-    __fortify_chk_fail("FD_CLR: set is too small", 0);
-  }
-  FD_CLR(fd, set);
-}
-
-extern "C" void __FD_SET_chk(int fd, fd_set* set, size_t set_size) {
-  if (__predict_false(fd < 0)) {
-    __fortify_chk_fail("FD_SET: file descriptor < 0", 0);
-  }
-  if (__predict_false(fd >= FD_SETSIZE)) {
-    __fortify_chk_fail("FD_SET: file descriptor >= FD_SETSIZE", 0);
-  }
-  if (__predict_false(set_size < sizeof(fd_set))) {
-    __fortify_chk_fail("FD_SET: set is too small", 0);
-  }
-  FD_SET(fd, set);
-}
diff --git a/libc/bionic/__fgets_chk.cpp b/libc/bionic/__fgets_chk.cpp
deleted file mode 100644
index 75e4ca0..0000000
--- a/libc/bionic/__fgets_chk.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2012 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.
- */
-
-#undef _FORTIFY_SOURCE
-
-#include <stdio.h>
-#include <stdlib.h>
-#include "private/libc_logging.h"
-
-/*
- * __fgets_chk. Called in place of fgets() when we know the
- * size of the buffer we're writing into.
- *
- * See
- *   http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
- * for details.
- *
- * This fgets check is called if _FORTIFY_SOURCE is defined and
- * greater than 0.
- */
-char* __fgets_chk(char* dest, int supplied_size, FILE* stream,
-                  size_t dest_len_from_compiler) {
-  if (supplied_size < 0) {
-    __fortify_chk_fail("fgets: buffer size < 0", 0);
-  }
-
-  if (((size_t) supplied_size) > dest_len_from_compiler) {
-    __fortify_chk_fail("fgets: prevented write past end of buffer", 0);
-  }
-
-  return fgets(dest, supplied_size, stream);
-}
diff --git a/libc/bionic/__fread_chk.cpp b/libc/bionic/__fread_chk.cpp
deleted file mode 100644
index afc8d90..0000000
--- a/libc/bionic/__fread_chk.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-#undef _FORTIFY_SOURCE
-#include <stdio.h>
-#include <sys/cdefs.h>
-#include "private/libc_logging.h"
-
-extern "C" size_t __fread_chk(void * __restrict buf, size_t size, size_t count,
-                              FILE * __restrict stream, size_t buf_size) {
-  size_t total;
-  if (__predict_false(__size_mul_overflow(size, count, &total))) {
-    // overflow: trigger the error path in fread
-    return fread(buf, size, count, stream);
-  }
-
-  if (__predict_false(total > buf_size)) {
-    __fortify_chk_fail("fread: prevented write past end of buffer", 0);
-  }
-
-  return fread(buf, size, count, stream);
-}
diff --git a/libc/bionic/__fwrite_chk.cpp b/libc/bionic/__fwrite_chk.cpp
deleted file mode 100644
index 2af13d6..0000000
--- a/libc/bionic/__fwrite_chk.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-#undef _FORTIFY_SOURCE
-#include <stdio.h>
-#include <sys/cdefs.h>
-#include "private/libc_logging.h"
-
-extern "C" size_t __fwrite_chk(const void * __restrict buf, size_t size, size_t count,
-                               FILE * __restrict stream, size_t buf_size) {
-  size_t total;
-  if (__predict_false(__size_mul_overflow(size, count, &total))) {
-    // overflow: trigger the error path in fwrite
-    return fwrite(buf, size, count, stream);
-  }
-
-  if (__predict_false(total > buf_size)) {
-    __fortify_chk_fail("fwrite: prevented read past end of buffer", 0);
-  }
-
-  return fwrite(buf, size, count, stream);
-}
diff --git a/libc/bionic/__getcwd_chk.cpp b/libc/bionic/__getcwd_chk.cpp
deleted file mode 100644
index b53ab5c..0000000
--- a/libc/bionic/__getcwd_chk.cpp
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-#undef _FORTIFY_SOURCE
-
-#include <unistd.h>
-#include "private/libc_logging.h"
-
-extern char* __getcwd_chk(char* buf, size_t len, size_t buflen) {
-  if (__predict_false(len > buflen)) {
-    __fortify_chk_fail("getcwd: prevented write past end of buffer", 0);
-  }
-
-  return getcwd(buf, len);
-}
diff --git a/libc/bionic/__libc_init_main_thread.cpp b/libc/bionic/__libc_init_main_thread.cpp
index 01bb9bb..2643eee 100644
--- a/libc/bionic/__libc_init_main_thread.cpp
+++ b/libc/bionic/__libc_init_main_thread.cpp
@@ -28,14 +28,24 @@
 
 #include "libc_init_common.h"
 
+#include "private/KernelArgumentBlock.h"
 #include "private/bionic_auxv.h"
 #include "private/bionic_globals.h"
-#include "private/KernelArgumentBlock.h"
+#include "private/bionic_ssp.h"
 #include "pthread_internal.h"
 
 extern "C" int __set_tls(void* ptr);
 extern "C" int __set_tid_address(int* tid_address);
 
+// Declared in "private/bionic_ssp.h".
+uintptr_t __stack_chk_guard = 0;
+
+void __libc_init_global_stack_chk_guard(KernelArgumentBlock& args) {
+  // AT_RANDOM is a pointer to 16 bytes of randomness on the stack.
+  // Take the first 4/8 for the -fstack-protector implementation.
+  __stack_chk_guard = *reinterpret_cast<uintptr_t*>(args.getauxval(AT_RANDOM));
+}
+
 // Setup for the main thread. For dynamic executables, this is called by the
 // linker _before_ libc is mapped in memory. This means that all writes to
 // globals from this function will apply to linker-private copies and will not
@@ -78,7 +88,8 @@
   // TODO: the main thread's sched_policy and sched_priority need to be queried.
 
   // The TLS stack guard is set from the global, so ensure that we've initialized the global
-  // before we initialize the TLS.
+  // before we initialize the TLS. Dynamic executables will initialize their copy of the global
+  // stack protector from the one in the main thread's TLS.
   __libc_init_global_stack_chk_guard(args);
 
   __init_thread(&main_thread);
diff --git a/libc/bionic/__memcpy_chk.cpp b/libc/bionic/__memcpy_chk.cpp
index 8a4f207..7b42d99 100644
--- a/libc/bionic/__memcpy_chk.cpp
+++ b/libc/bionic/__memcpy_chk.cpp
@@ -27,27 +27,14 @@
  */
 
 #undef _FORTIFY_SOURCE
+
 #include <string.h>
-#include <stdlib.h>
-#include "private/libc_logging.h"
 
-/*
- * Runtime implementation of __memcpy_chk.
- *
- * See
- *   http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
- *   http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
- * for details.
- *
- * This memcpy check is called if _FORTIFY_SOURCE is defined and
- * greater than 0.
- */
-extern "C" void* __memcpy_chk(void* dest, const void* src,
-                              size_t copy_amount, size_t dest_len) {
-  if (__predict_false(copy_amount > dest_len)) {
-    __fortify_chk_fail("memcpy: prevented write past end of buffer",
-                       BIONIC_EVENT_MEMCPY_BUFFER_OVERFLOW);
-  }
+#include "private/bionic_fortify.h"
 
-  return memcpy(dest, src, copy_amount);
+// Runtime implementation of __memcpy_chk (used directly by compiler, not in headers).
+extern "C" void* __memcpy_chk(void* dst, const void* src, size_t count, size_t dst_len) {
+  __check_count("memcpy", "count", count);
+  __check_buffer_access("memcpy", "write into", count, dst_len);
+  return memcpy(dst, src, count);
 }
diff --git a/libc/bionic/__memmove_chk.cpp b/libc/bionic/__memmove_chk.cpp
deleted file mode 100644
index b88a94f..0000000
--- a/libc/bionic/__memmove_chk.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2012 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.
- */
-
-#undef _FORTIFY_SOURCE
-
-#include <string.h>
-#include <stdlib.h>
-#include "private/libc_logging.h"
-
-/*
- * Runtime implementation of __builtin____memmove_chk.
- *
- * See
- *   http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
- *   http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
- * for details.
- *
- * This memmove check is called if _FORTIFY_SOURCE is defined and
- * greater than 0.
- */
-extern "C" void* __memmove_chk (void* dest, const void* src,
-                                size_t len, size_t dest_len) {
-  if (__predict_false(len > dest_len)) {
-    __fortify_chk_fail("memmove: prevented write past end of buffer",
-                       BIONIC_EVENT_MEMMOVE_BUFFER_OVERFLOW);
-  }
-
-  return memmove(dest, src, len);
-}
diff --git a/libc/bionic/__memrchr_chk.cpp b/libc/bionic/__memrchr_chk.cpp
deleted file mode 100644
index 8529dfc..0000000
--- a/libc/bionic/__memrchr_chk.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-#undef _FORTIFY_SOURCE
-#include <string.h>
-#include "private/libc_logging.h"
-
-extern "C" void* __memrchr_chk(const void* s, int c, size_t n, size_t buf_size) {
-  if (__predict_false(n > buf_size)) {
-    __fortify_chk_fail("memrchr: prevented read past end of buffer", 0);
-  }
-
-  return memrchr(s, c, n);
-}
diff --git a/libc/bionic/__memset_chk.cpp b/libc/bionic/__memset_chk.cpp
deleted file mode 100644
index 5f20452..0000000
--- a/libc/bionic/__memset_chk.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2012 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.
- */
-
-#undef _FORTIFY_SOURCE
-
-#include <string.h>
-#include <stdlib.h>
-#include "private/libc_logging.h"
-
-/*
- * Runtime implementation of __builtin____memset_chk.
- *
- * See
- *   http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
- *   http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
- * for details.
- *
- * This memset check is called if _FORTIFY_SOURCE is defined and
- * greater than 0.
- */
-extern "C" void* __memset_chk (void* dest, int c, size_t n, size_t dest_len) {
-  if (__predict_false(n > dest_len)) {
-    __fortify_chk_fail("memset: prevented write past end of buffer",
-                       BIONIC_EVENT_MEMSET_BUFFER_OVERFLOW);
-  }
-
-  return memset(dest, c, n);
-}
diff --git a/libc/bionic/__poll_chk.cpp b/libc/bionic/__poll_chk.cpp
deleted file mode 100644
index a24ab8e..0000000
--- a/libc/bionic/__poll_chk.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-#undef _FORTIFY_SOURCE
-#include <poll.h>
-#include "private/libc_logging.h"
-
-extern "C" int __poll_chk(struct pollfd* fds, nfds_t fd_count, int timeout, size_t fds_size) {
-  if (__predict_false(fds_size / sizeof(*fds) < fd_count)) {
-    __fortify_chk_fail("poll: pollfd array smaller than fd count", 0);
-  }
-  return poll(fds, fd_count, timeout);
-}
-
-extern "C" int __ppoll_chk(struct pollfd* fds, nfds_t fd_count, const struct timespec* timeout, const sigset_t* mask, size_t fds_size) {
-  if (__predict_false(fds_size / sizeof(*fds) < fd_count)) {
-    __fortify_chk_fail("ppoll: pollfd array smaller than fd count", 0);
-  }
-  return ppoll(fds, fd_count, timeout, mask);
-}
diff --git a/libc/bionic/__pread64_chk.cpp b/libc/bionic/__pread64_chk.cpp
deleted file mode 100644
index 5d6ad2d..0000000
--- a/libc/bionic/__pread64_chk.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-#undef _FORTIFY_SOURCE
-#include <unistd.h>
-#include "private/libc_logging.h"
-
-extern "C" ssize_t __pread64_chk(int fd, void* buf, size_t count, off64_t offset, size_t buf_size) {
-  if (__predict_false(count > buf_size)) {
-    __fortify_chk_fail("pread64: prevented write past end of buffer", 0);
-  }
-
-  if (__predict_false(count > SSIZE_MAX)) {
-    __fortify_chk_fail("pread64: count > SSIZE_MAX", 0);
-  }
-
-  return pread64(fd, buf, count, offset);
-}
diff --git a/libc/bionic/__pread_chk.cpp b/libc/bionic/__pread_chk.cpp
deleted file mode 100644
index 7109ce6..0000000
--- a/libc/bionic/__pread_chk.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-#undef _FORTIFY_SOURCE
-#include <unistd.h>
-#include "private/libc_logging.h"
-
-extern "C" ssize_t __pread_chk(int fd, void* buf, size_t count, off_t offset, size_t buf_size) {
-  if (__predict_false(count > buf_size)) {
-    __fortify_chk_fail("pread: prevented write past end of buffer", 0);
-  }
-
-  if (__predict_false(count > SSIZE_MAX)) {
-    __fortify_chk_fail("pread: count > SSIZE_MAX", 0);
-  }
-
-  return pread(fd, buf, count, offset);
-}
diff --git a/libc/bionic/__pwrite64_chk.cpp b/libc/bionic/__pwrite64_chk.cpp
deleted file mode 100644
index e488ca1..0000000
--- a/libc/bionic/__pwrite64_chk.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-#undef _FORTIFY_SOURCE
-#include <unistd.h>
-#include "private/libc_logging.h"
-
-extern "C" ssize_t __pwrite64_chk(int fd, const void* buf, size_t count, off64_t offset,
-                                  size_t buf_size) {
-  if (__predict_false(count > buf_size)) {
-    __fortify_chk_fail("pwrite64: prevented read past end of buffer", 0);
-  }
-
-  if (__predict_false(count > SSIZE_MAX)) {
-    __fortify_chk_fail("pwrite64: count > SSIZE_MAX", 0);
-  }
-
-  return pwrite64(fd, buf, count, offset);
-}
diff --git a/libc/bionic/__pwrite_chk.cpp b/libc/bionic/__pwrite_chk.cpp
deleted file mode 100644
index a889ef6..0000000
--- a/libc/bionic/__pwrite_chk.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-#undef _FORTIFY_SOURCE
-#include <unistd.h>
-#include "private/libc_logging.h"
-
-extern "C" ssize_t __pwrite_chk(int fd, const void* buf, size_t count, off_t offset,
-                                size_t buf_size) {
-  if (__predict_false(count > buf_size)) {
-    __fortify_chk_fail("pwrite: prevented read past end of buffer", 0);
-  }
-
-  if (__predict_false(count > SSIZE_MAX)) {
-    __fortify_chk_fail("pwrite: count > SSIZE_MAX", 0);
-  }
-
-  return pwrite(fd, buf, count, offset);
-}
diff --git a/libc/bionic/__read_chk.cpp b/libc/bionic/__read_chk.cpp
deleted file mode 100644
index ff50983..0000000
--- a/libc/bionic/__read_chk.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2013 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.
- */
-
-#undef _FORTIFY_SOURCE
-#include <unistd.h>
-#include "private/libc_logging.h"
-
-extern "C" ssize_t __read_chk(int fd, void* buf, size_t count, size_t buf_size) {
-  if (__predict_false(count > buf_size)) {
-    __fortify_chk_fail("read: prevented write past end of buffer", 0);
-  }
-
-  if (__predict_false(count > SSIZE_MAX)) {
-    __fortify_chk_fail("read: count > SSIZE_MAX", 0);
-  }
-
-  return read(fd, buf, count);
-}
diff --git a/libc/bionic/__readlink_chk.cpp b/libc/bionic/__readlink_chk.cpp
deleted file mode 100644
index f19f917..0000000
--- a/libc/bionic/__readlink_chk.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-#undef _FORTIFY_SOURCE
-#include <unistd.h>
-#include "private/libc_logging.h"
-
-extern "C" ssize_t __readlink_chk(const char* path, char* buf, size_t size, size_t buf_size) {
-  if (__predict_false(size > buf_size)) {
-    __fortify_chk_fail("readlink: prevented write past end of buffer", 0);
-  }
-
-  if (__predict_false(size > SSIZE_MAX)) {
-    __fortify_chk_fail("readlink: size > SSIZE_MAX", 0);
-  }
-
-  return readlink(path, buf, size);
-}
diff --git a/libc/bionic/__readlinkat_chk.cpp b/libc/bionic/__readlinkat_chk.cpp
deleted file mode 100644
index a11db8e..0000000
--- a/libc/bionic/__readlinkat_chk.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-#undef _FORTIFY_SOURCE
-#include <unistd.h>
-#include "private/libc_logging.h"
-
-extern "C" ssize_t __readlinkat_chk(int dirfd, const char* path, char* buf, size_t size, size_t buf_size) {
-  if (__predict_false(size > buf_size)) {
-    __fortify_chk_fail("readlinkat: prevented write past end of buffer", 0);
-  }
-
-  if (__predict_false(size > SSIZE_MAX)) {
-    __fortify_chk_fail("readlinkat: size > SSIZE_MAX", 0);
-  }
-
-  return readlinkat(dirfd, path, buf, size);
-}
diff --git a/libc/bionic/__recvfrom_chk.cpp b/libc/bionic/__recvfrom_chk.cpp
deleted file mode 100644
index 9c894b0..0000000
--- a/libc/bionic/__recvfrom_chk.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2013 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.
- */
-
-#undef _FORTIFY_SOURCE
-
-#include <stddef.h>
-#include <sys/socket.h>
-#include "private/libc_logging.h"
-
-ssize_t __recvfrom_chk(int socket, void* buf, size_t len, size_t buflen,
-                       int flags, const struct sockaddr* src_addr,
-                       socklen_t* addrlen) {
-  if (__predict_false(len > buflen)) {
-    __fortify_chk_fail("recvfrom: prevented write past end of buffer", 0);
-  }
-
-  return recvfrom(socket, buf, len, flags, src_addr, addrlen);
-}
diff --git a/libc/bionic/__stpcpy_chk.cpp b/libc/bionic/__stpcpy_chk.cpp
deleted file mode 100644
index 3ce81ee..0000000
--- a/libc/bionic/__stpcpy_chk.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2014 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.
- */
-
-#undef _FORTIFY_SOURCE
-
-#include <string.h>
-#include <stdlib.h>
-#include "private/libc_logging.h"
-
-/*
- * Runtime implementation of __builtin____stpcpy_chk.
- *
- * See
- *   http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
- *   http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
- * for details.
- *
- * This stpcpy check is called if _FORTIFY_SOURCE is defined and
- * greater than 0.
- */
-extern "C" char* __stpcpy_chk(char* dest, const char* src, size_t dest_len) {
-  // TODO: optimize so we don't scan src twice.
-  size_t src_len = strlen(src) + 1;
-  if (__predict_false(src_len > dest_len)) {
-    __fortify_chk_fail("stpcpy: prevented write past end of buffer",
-                       BIONIC_EVENT_STPCPY_BUFFER_OVERFLOW);
-  }
-
-  return stpcpy(dest, src);
-}
diff --git a/libc/bionic/__stpncpy_chk.cpp b/libc/bionic/__stpncpy_chk.cpp
deleted file mode 100644
index 6c9215c..0000000
--- a/libc/bionic/__stpncpy_chk.cpp
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (C) 2014 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.
- */
-
-#undef _FORTIFY_SOURCE
-
-#include <string.h>
-#include <stdlib.h>
-#include "private/libc_logging.h"
-
-/*
- * Runtime implementation of __builtin____stpncpy_chk.
- *
- * See
- *   http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
- *   http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
- * for details.
- *
- * This stpncpy check is called if _FORTIFY_SOURCE is defined and
- * greater than 0.
- */
-extern "C" char* __stpncpy_chk(char* __restrict dest, const char* __restrict src,
-                               size_t len, size_t dest_len) {
-  if (__predict_false(len > dest_len)) {
-    __fortify_chk_fail("stpncpy: prevented write past end of buffer",
-                       BIONIC_EVENT_STPNCPY_BUFFER_OVERFLOW);
-  }
-
-  return stpncpy(dest, src, len);
-}
-
-/*
- * __stpncpy_chk2
- *
- * This is a variant of __stpncpy_chk, but it also checks to make
- * sure we don't read beyond the end of "src". The code for this is
- * based on the original version of stpncpy, but modified to check
- * how much we read from "src" at the end of the copy operation.
- */
-extern "C" char* __stpncpy_chk2(char* __restrict dst, const char* __restrict src,
-              size_t n, size_t dest_len, size_t src_len)
-{
-  if (__predict_false(n > dest_len)) {
-    __fortify_chk_fail("stpncpy: prevented write past end of buffer",
-                       BIONIC_EVENT_STPNCPY_BUFFER_OVERFLOW);
-  }
-  if (n != 0) {
-    char* d = dst;
-    const char* s = src;
-
-    do {
-      if ((*d++ = *s++) == 0) {
-        /* NUL pad the remaining n-1 bytes */
-        while (--n != 0) {
-          *d++ = 0;
-        }
-        break;
-      }
-    } while (--n != 0);
-
-    size_t s_copy_len = static_cast<size_t>(s - src);
-    if (__predict_false(s_copy_len > src_len)) {
-      __fortify_chk_fail("stpncpy: prevented read past end of buffer", 0);
-    }
-  }
-
-  return dst;
-}
diff --git a/libc/bionic/__strcat_chk.cpp b/libc/bionic/__strcat_chk.cpp
index a0ab09e..16b2327 100644
--- a/libc/bionic/__strcat_chk.cpp
+++ b/libc/bionic/__strcat_chk.cpp
@@ -27,33 +27,22 @@
  */
 
 #include <string.h>
-#include <stdlib.h>
-#include "private/libc_logging.h"
 
-/*
- * Runtime implementation of __builtin____strcat_chk.
- *
- * See
- *   http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
- *   http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
- * for details.
- *
- * This strcat check is called if _FORTIFY_SOURCE is defined and
- * greater than 0.
- */
-extern "C" char* __strcat_chk(char* __restrict dest, const char* __restrict src,
-                              size_t dest_buf_size) {
-  char* save = dest;
-  size_t dest_len = __strlen_chk(dest, dest_buf_size);
+#include "private/bionic_fortify.h"
 
-  dest += dest_len;
-  dest_buf_size -= dest_len;
+// Runtime implementation of __builtin____strcat_chk (used directly by compiler, not in headers).
+extern "C" char* __strcat_chk(char* __restrict dst, const char* __restrict src,
+                              size_t dst_buf_size) {
+  char* save = dst;
+  size_t dst_len = __strlen_chk(dst, dst_buf_size);
 
-  while ((*dest++ = *src++) != '\0') {
-    dest_buf_size--;
-    if (__predict_false(dest_buf_size == 0)) {
-      __fortify_chk_fail("strcat: prevented write past end of buffer",
-                         BIONIC_EVENT_STRCAT_BUFFER_OVERFLOW);
+  dst += dst_len;
+  dst_buf_size -= dst_len;
+
+  while ((*dst++ = *src++) != '\0') {
+    dst_buf_size--;
+    if (__predict_false(dst_buf_size == 0)) {
+      __fortify_fatal("strcat: prevented write past end of %zu-byte buffer", dst_buf_size);
     }
   }
 
diff --git a/libc/bionic/__strchr_chk.cpp b/libc/bionic/__strchr_chk.cpp
deleted file mode 100644
index 03b6b30..0000000
--- a/libc/bionic/__strchr_chk.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <string.h>
-#include "private/libc_logging.h"
-
-extern "C" char* __strchr_chk(const char* p, int ch, size_t s_len) {
-  for (;; ++p, s_len--) {
-    if (__predict_false(s_len == 0)) {
-      __fortify_chk_fail("strchr: prevented read past end of buffer", 0);
-    }
-    if (*p == static_cast<char>(ch)) {
-      return const_cast<char*>(p);
-    }
-    if (*p == '\0') {
-      return NULL;
-    }
-  }
-  /* NOTREACHED */
-}
diff --git a/libc/bionic/__strcpy_chk.cpp b/libc/bionic/__strcpy_chk.cpp
index ad3ef50..116fff4 100644
--- a/libc/bionic/__strcpy_chk.cpp
+++ b/libc/bionic/__strcpy_chk.cpp
@@ -29,27 +29,13 @@
 #undef _FORTIFY_SOURCE
 
 #include <string.h>
-#include <stdlib.h>
-#include "private/libc_logging.h"
 
-/*
- * Runtime implementation of __builtin____strcpy_chk.
- *
- * See
- *   http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
- *   http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
- * for details.
- *
- * This strcpy check is called if _FORTIFY_SOURCE is defined and
- * greater than 0.
- */
-extern "C" char* __strcpy_chk(char* dest, const char* src, size_t dest_len) {
+#include "private/bionic_fortify.h"
+
+// Runtime implementation of __builtin____strcpy_chk (used directly by compiler, not in headers).
+extern "C" char* __strcpy_chk(char* dst, const char* src, size_t dst_len) {
   // TODO: optimize so we don't scan src twice.
   size_t src_len = strlen(src) + 1;
-  if (__predict_false(src_len > dest_len)) {
-    __fortify_chk_fail("strcpy: prevented write past end of buffer",
-                       BIONIC_EVENT_STRCPY_BUFFER_OVERFLOW);
-  }
-
-  return strcpy(dest, src);
+  __check_buffer_access("strcpy", "write into", src_len, dst_len);
+  return strcpy(dst, src);
 }
diff --git a/libc/bionic/__strlcat_chk.cpp b/libc/bionic/__strlcat_chk.cpp
deleted file mode 100644
index 2b7373b..0000000
--- a/libc/bionic/__strlcat_chk.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2012 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.
- */
-
-#undef _FORTIFY_SOURCE
-
-#include <string.h>
-#include <stdlib.h>
-#include "private/libc_logging.h"
-
-/*
- * __strlcat_chk. Called in place of strlcat() when we know the
- * size of the buffer we're writing into.
- *
- * See
- *   http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
- *   http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
- * for details.
- *
- * This strlcat check is called if _FORTIFY_SOURCE is defined and
- * greater than 0.
- */
-extern "C" size_t __strlcat_chk(char* dest, const char* src,
-                                size_t supplied_size, size_t dest_len_from_compiler) {
-  if (__predict_false(supplied_size > dest_len_from_compiler)) {
-    __fortify_chk_fail("strlcat: prevented write past end of buffer", 0);
-  }
-
-  return strlcat(dest, src, supplied_size);
-}
diff --git a/libc/bionic/__strlcpy_chk.cpp b/libc/bionic/__strlcpy_chk.cpp
deleted file mode 100644
index 6b21879..0000000
--- a/libc/bionic/__strlcpy_chk.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2012 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.
- */
-
-#undef _FORTIFY_SOURCE
-
-#include <string.h>
-#include <stdlib.h>
-#include "private/libc_logging.h"
-
-/*
- * __strlcpy_chk. Called in place of strlcpy() when we know the
- * size of the buffer we're writing into.
- *
- * See
- *   http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
- *   http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
- * for details.
- *
- * This strlcpy check is called if _FORTIFY_SOURCE is defined and
- * greater than 0.
- */
-extern "C" size_t __strlcpy_chk(char* dest, const char* src,
-                                size_t supplied_size, size_t dest_len_from_compiler) {
-  if (__predict_false(supplied_size > dest_len_from_compiler)) {
-    __fortify_chk_fail("strlcpy: prevented write past end of buffer", 0);
-  }
-
-  return strlcpy(dest, src, supplied_size);
-}
diff --git a/libc/bionic/__strlen_chk.cpp b/libc/bionic/__strlen_chk.cpp
deleted file mode 100644
index a67e15e..0000000
--- a/libc/bionic/__strlen_chk.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (C) 2012 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.
- */
-
-#undef _FORTIFY_SOURCE
-
-#include <string.h>
-#include <stdlib.h>
-#include "private/libc_logging.h"
-
-/*
- * Runtime implementation of __strlen_chk.
- *
- * See
- *   http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
- *   http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
- * for details.
- *
- * This strlen check is called if _FORTIFY_SOURCE is defined and
- * greater than 0.
- *
- * This test is designed to detect code such as:
- *
- * int main() {
- *   char buf[10];
- *   memcpy(buf, "1234567890", sizeof(buf));
- *   size_t len = strlen(buf); // segfault here with _FORTIFY_SOURCE
- *   printf("%d\n", len);
- *   return 0;
- * }
- *
- * or anytime strlen reads beyond an object boundary.
- */
-extern "C" size_t __strlen_chk(const char* s, size_t s_len) {
-  size_t ret = strlen(s);
-
-  if (__predict_false(ret >= s_len)) {
-    __fortify_chk_fail("strlen: prevented read past end of buffer", 0);
-  }
-
-  return ret;
-}
diff --git a/libc/bionic/__strncat_chk.cpp b/libc/bionic/__strncat_chk.cpp
deleted file mode 100644
index 21e5e39..0000000
--- a/libc/bionic/__strncat_chk.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2012 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 <string.h>
-#include <stdlib.h>
-#include "private/libc_logging.h"
-
-/*
- * Runtime implementation of __builtin____strncat_chk.
- *
- * See
- *   http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
- *   http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
- * for details.
- *
- * This strncat check is called if _FORTIFY_SOURCE is defined and
- * greater than 0.
- */
-extern "C" char* __strncat_chk(char* __restrict dest, const char* __restrict src,
-                               size_t len, size_t dest_buf_size) {
-  if (len == 0) {
-    return dest;
-  }
-
-  size_t dest_len = __strlen_chk(dest, dest_buf_size);
-  char *d = dest + dest_len;
-  dest_buf_size -= dest_len;
-
-  while (*src != '\0') {
-    *d++ = *src++;
-    len--; dest_buf_size--;
-
-    if (__predict_false(dest_buf_size == 0)) {
-      __fortify_chk_fail("strncat: prevented write past end of buffer",
-                         BIONIC_EVENT_STRNCAT_BUFFER_OVERFLOW);
-    }
-
-    if (len == 0) {
-      break;
-    }
-  }
-
-  *d = '\0';
-  return dest;
-}
diff --git a/libc/bionic/__strncpy_chk.cpp b/libc/bionic/__strncpy_chk.cpp
deleted file mode 100644
index 9625929..0000000
--- a/libc/bionic/__strncpy_chk.cpp
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (C) 2012 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.
- */
-
-#undef _FORTIFY_SOURCE
-
-#include <string.h>
-#include <stdlib.h>
-#include "private/libc_logging.h"
-
-/*
- * Runtime implementation of __builtin____strncpy_chk.
- *
- * See
- *   http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
- *   http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
- * for details.
- *
- * This strncpy check is called if _FORTIFY_SOURCE is defined and
- * greater than 0.
- */
-extern "C" char* __strncpy_chk(char* __restrict dest, const char* __restrict src,
-                               size_t len, size_t dest_len) {
-  if (__predict_false(len > dest_len)) {
-    __fortify_chk_fail("strncpy: prevented write past end of buffer",
-                       BIONIC_EVENT_STRNCPY_BUFFER_OVERFLOW);
-  }
-
-  return strncpy(dest, src, len);
-}
-
-/*
- * __strncpy_chk2
- *
- * This is a variant of __strncpy_chk, but it also checks to make
- * sure we don't read beyond the end of "src". The code for this is
- * based on the original version of strncpy, but modified to check
- * how much we read from "src" at the end of the copy operation.
- */
-extern "C" char* __strncpy_chk2(char* __restrict dst, const char* __restrict src,
-              size_t n, size_t dest_len, size_t src_len)
-{
-  if (__predict_false(n > dest_len)) {
-    __fortify_chk_fail("strncpy: prevented write past end of buffer",
-                       BIONIC_EVENT_STRNCPY_BUFFER_OVERFLOW);
-  }
-  if (n != 0) {
-    char* d = dst;
-    const char* s = src;
-
-    do {
-      if ((*d++ = *s++) == 0) {
-        /* NUL pad the remaining n-1 bytes */
-        while (--n != 0) {
-          *d++ = 0;
-        }
-        break;
-      }
-    } while (--n != 0);
-
-    size_t s_copy_len = static_cast<size_t>(s - src);
-    if (__predict_false(s_copy_len > src_len)) {
-      __fortify_chk_fail("strncpy: prevented read past end of buffer", 0);
-    }
-  }
-
-  return dst;
-}
diff --git a/libc/bionic/__strrchr_chk.cpp b/libc/bionic/__strrchr_chk.cpp
deleted file mode 100644
index 69198c0..0000000
--- a/libc/bionic/__strrchr_chk.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 1988 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <string.h>
-#include "private/libc_logging.h"
-
-extern "C" char* __strrchr_chk(const char *p, int ch, size_t s_len) {
-  for (char* save = NULL;; ++p, s_len--) {
-    if (s_len == 0) {
-      __fortify_chk_fail("strrchr: prevented read past end of buffer", 0);
-    }
-    if (*p == (char) ch) {
-      save = (char *)p;
-    }
-    if (!*p) {
-      return(save);
-    }
-  }
-  /* NOTREACHED */
-}
diff --git a/libc/bionic/__umask_chk.cpp b/libc/bionic/__umask_chk.cpp
deleted file mode 100644
index 33b7121..0000000
--- a/libc/bionic/__umask_chk.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (C) 2012 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.
- */
-
-#undef _FORTIFY_SOURCE
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdlib.h>
-
-#include "private/libc_logging.h"
-
-/*
- * Runtime implementation of __umask_chk.
- *
- * Validate that umask is called with sane mode.
- *
- * This umask check is called if _FORTIFY_SOURCE is defined and
- * greater than 0.
- */
-extern "C" mode_t __umask_chk(mode_t mode) {
-  if (__predict_false((mode & 0777) != mode)) {
-    __fortify_chk_fail("umask: called with invalid mask", 0);
-  }
-
-  return umask(mode);
-}
diff --git a/libc/bionic/__vsnprintf_chk.cpp b/libc/bionic/__vsnprintf_chk.cpp
deleted file mode 100644
index 8c09111..0000000
--- a/libc/bionic/__vsnprintf_chk.cpp
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2012 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.
- */
-
-#undef _FORTIFY_SOURCE
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include "private/libc_logging.h"
-
-/*
- * Runtime implementation of __builtin____vsnprintf_chk.
- *
- * See
- *   http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
- *   http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
- * for details.
- *
- * This vsnprintf check is called if _FORTIFY_SOURCE is defined and
- * greater than 0.
- */
-extern "C" int __vsnprintf_chk(char* dest, size_t supplied_size, int /*flags*/,
-                               size_t dest_len_from_compiler, const char* format, va_list va) {
-  if (__predict_false(supplied_size > dest_len_from_compiler)) {
-    __fortify_chk_fail("vsnprintf: prevented write past end of buffer", 0);
-  }
-
-  return vsnprintf(dest, supplied_size, format, va);
-}
-
-/*
- * Runtime implementation of __builtin____snprintf_chk.
- *
- * See
- *   http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
- *   http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
- * for details.
- *
- * This snprintf check is called if _FORTIFY_SOURCE is defined and
- * greater than 0.
- */
-extern "C" int __snprintf_chk(char* dest, size_t supplied_size, int flags,
-                              size_t dest_len_from_compiler, const char* format, ...) {
-  va_list va;
-  va_start(va, format);
-  int result = __vsnprintf_chk(dest, supplied_size, flags, dest_len_from_compiler, format, va);
-  va_end(va);
-  return result;
-}
diff --git a/libc/bionic/__vsprintf_chk.cpp b/libc/bionic/__vsprintf_chk.cpp
deleted file mode 100644
index 5914026..0000000
--- a/libc/bionic/__vsprintf_chk.cpp
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2012 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.
- */
-
-#undef _FORTIFY_SOURCE
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include "private/libc_logging.h"
-
-/*
- * Runtime implementation of __builtin____vsprintf_chk.
- *
- * See
- *   http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
- *   http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
- * for details.
- *
- * This vsprintf check is called if _FORTIFY_SOURCE is defined and
- * greater than 0.
- */
-extern "C" int __vsprintf_chk(char* dest, int /*flags*/,
-                              size_t dest_len_from_compiler, const char* format, va_list va) {
-  int result = vsnprintf(dest, dest_len_from_compiler, format, va);
-  if ((size_t) result >= dest_len_from_compiler) {
-    __fortify_chk_fail("vsprintf: prevented write past end of buffer", 0);
-  }
-  return result;
-}
-
-/*
- * Runtime implementation of __builtin____sprintf_chk.
- *
- * See
- *   http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
- *   http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
- * for details.
- *
- * This sprintf check is called if _FORTIFY_SOURCE is defined and
- * greater than 0.
- */
-extern "C" int __sprintf_chk(char* dest, int flags,
-                             size_t dest_len_from_compiler, const char* format, ...) {
-  va_list va;
-  va_start(va, format);
-  int result = __vsprintf_chk(dest, flags, dest_len_from_compiler, format, va);
-  va_end(va);
-  return result;
-}
diff --git a/libc/bionic/__write_chk.cpp b/libc/bionic/__write_chk.cpp
deleted file mode 100644
index cbd247a..0000000
--- a/libc/bionic/__write_chk.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-#undef _FORTIFY_SOURCE
-#include <unistd.h>
-#include "private/libc_logging.h"
-
-extern "C" ssize_t __write_chk(int fd, const void* buf, size_t count, size_t buf_size) {
-  if (__predict_false(count > buf_size)) {
-    __fortify_chk_fail("write: prevented read past end of buffer", 0);
-  }
-
-  if (__predict_false(count > SSIZE_MAX)) {
-    __fortify_chk_fail("write: count > SSIZE_MAX", 0);
-  }
-
-  return write(fd, buf, count);
-}
diff --git a/libc/bionic/bionic_netlink.h b/libc/bionic/bionic_netlink.h
index 4b103f3..bc0e3f0 100644
--- a/libc/bionic/bionic_netlink.h
+++ b/libc/bionic/bionic_netlink.h
@@ -50,10 +50,4 @@
   size_t size_;
 };
 
-#if !defined(__clang__)
-// GCC gets confused by NLMSG_DATA and doesn't realize that the old-style
-// cast is from a system header and should be ignored.
-#pragma GCC diagnostic ignored "-Wold-style-cast"
-#endif
-
 #endif
diff --git a/libc/bionic/bionic_time_conversions.cpp b/libc/bionic/bionic_time_conversions.cpp
index f3ca46a..ade3a55 100644
--- a/libc/bionic/bionic_time_conversions.cpp
+++ b/libc/bionic/bionic_time_conversions.cpp
@@ -51,13 +51,3 @@
   tv.tv_sec = ts.tv_sec;
   tv.tv_usec = ts.tv_nsec / 1000;
 }
-
-void absolute_timespec_from_timespec(timespec& abs_ts, const timespec& ts, clockid_t clock) {
-  clock_gettime(clock, &abs_ts);
-  abs_ts.tv_sec += ts.tv_sec;
-  abs_ts.tv_nsec += ts.tv_nsec;
-  if (abs_ts.tv_nsec >= NS_PER_S) {
-    abs_ts.tv_nsec -= NS_PER_S;
-    abs_ts.tv_sec++;
-  }
-}
diff --git a/libc/bionic/brk.cpp b/libc/bionic/brk.cpp
index 4e46193..a8c078b 100644
--- a/libc/bionic/brk.cpp
+++ b/libc/bionic/brk.cpp
@@ -35,6 +35,8 @@
 void* __bionic_brk; // Accidentally exported by the NDK.
 #endif
 
+extern "C" void* __brk(void* __addr);
+
 int brk(void* end_data) {
   __bionic_brk = __brk(end_data);
   if (__bionic_brk < end_data) {
diff --git a/libc/bionic/clock.cpp b/libc/bionic/clock.cpp
index 053e9e7..fda0708 100644
--- a/libc/bionic/clock.cpp
+++ b/libc/bionic/clock.cpp
@@ -26,9 +26,9 @@
  * SUCH DAMAGE.
  */
 
-#include <time.h>
-#include <sys/sysconf.h>
 #include <sys/times.h>
+#include <time.h>
+#include <unistd.h>
 
 #include "private/bionic_constants.h"
 
diff --git a/libc/bionic/clock_getcpuclockid.cpp b/libc/bionic/clock_getcpuclockid.cpp
index 5511eb4..9ff1845 100644
--- a/libc/bionic/clock_getcpuclockid.cpp
+++ b/libc/bionic/clock_getcpuclockid.cpp
@@ -40,8 +40,7 @@
   result |= 2;
   // Bit 2: thread (set) or process (clear). Bit 2 already 0.
 
-  timespec ts;
-  if (clock_getres(result, &ts) == -1) {
+  if (clock_getres(result, nullptr) == -1) {
     return ESRCH;
   }
 
diff --git a/libc/bionic/clock_nanosleep.cpp b/libc/bionic/clock_nanosleep.cpp
index 8e2146f..eade850 100644
--- a/libc/bionic/clock_nanosleep.cpp
+++ b/libc/bionic/clock_nanosleep.cpp
@@ -33,6 +33,8 @@
 extern "C" int ___clock_nanosleep(clockid_t, int, const timespec*, timespec*);
 
 int clock_nanosleep(clockid_t clock_id, int flags, const timespec* in, timespec* out) {
+  if (clock_id == CLOCK_THREAD_CPUTIME_ID) return EINVAL;
+
   ErrnoRestorer errno_restorer;
   return (___clock_nanosleep(clock_id, flags, in, out) == 0) ? 0 : errno;
 }
diff --git a/libc/bionic/clone.cpp b/libc/bionic/clone.cpp
index 9b5c9e7..8281ac8 100644
--- a/libc/bionic/clone.cpp
+++ b/libc/bionic/clone.cpp
@@ -47,6 +47,11 @@
   void* new_tls = NULL;
   int* child_tid = NULL;
 
+  if (fn != nullptr && child_stack == nullptr) {
+    errno = EINVAL;
+    return -1;
+  }
+
   // Extract any optional parameters required by the flags.
   va_list args;
   va_start(args, arg);
@@ -71,7 +76,16 @@
   pid_t parent_pid = self->invalidate_cached_pid();
 
   // Actually do the clone.
-  int clone_result = __bionic_clone(flags, child_stack, parent_tid, new_tls, child_tid, fn, arg);
+  int clone_result;
+  if (fn != nullptr) {
+    clone_result = __bionic_clone(flags, child_stack, parent_tid, new_tls, child_tid, fn, arg);
+  } else {
+#if defined(__x86_64__) // sys_clone's last two arguments are flipped on x86-64.
+    clone_result = syscall(__NR_clone, flags, child_stack, parent_tid, child_tid, new_tls);
+#else
+    clone_result = syscall(__NR_clone, flags, child_stack, parent_tid, new_tls, child_tid);
+#endif
+  }
 
   // We're the parent, so put our known pid back in place.
   // We leave the child without a cached pid, but:
diff --git a/libc/bionic/epoll_create.cpp b/libc/bionic/epoll_create.cpp
index 1dfafa8..74f664f 100644
--- a/libc/bionic/epoll_create.cpp
+++ b/libc/bionic/epoll_create.cpp
@@ -26,8 +26,13 @@
  * SUCH DAMAGE.
  */
 
+#include <errno.h>
 #include <sys/epoll.h>
 
-int epoll_create(int /*obsolete_size*/) {
+int epoll_create(int size) {
+  if (size <= 0) {
+    errno = EINVAL;
+    return -1;
+  }
   return epoll_create1(0);
 }
diff --git a/libc/bionic/ether_aton.c b/libc/bionic/ether_aton.c
index 6540c07..edd6b11 100644
--- a/libc/bionic/ether_aton.c
+++ b/libc/bionic/ether_aton.c
@@ -26,11 +26,11 @@
  * SUCH DAMAGE.
  */
 
+#include <net/ethernet.h>
+
+#include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <sys/types.h>
-#include <net/if_ether.h>
-#include <ctype.h>
 
 static inline int
 xdigit (char c) {
diff --git a/libc/bionic/ether_ntoa.c b/libc/bionic/ether_ntoa.c
index f56e48b..7c31af3 100644
--- a/libc/bionic/ether_ntoa.c
+++ b/libc/bionic/ether_ntoa.c
@@ -28,7 +28,7 @@
 
 #include <stdio.h>
 #include <sys/types.h>
-#include <net/if_ether.h>
+#include <net/ethernet.h>
 
 /*
  * Convert Ethernet address to standard hex-digits-and-colons printable form.
diff --git a/libc/bionic/fork.cpp b/libc/bionic/fork.cpp
index 6cfc736..ffe94f4 100644
--- a/libc/bionic/fork.cpp
+++ b/libc/bionic/fork.cpp
@@ -31,8 +31,6 @@
 
 #include "pthread_internal.h"
 
-#define FORK_FLAGS (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD)
-
 int fork() {
   __bionic_atfork_run_prepare();
 
@@ -41,11 +39,13 @@
   // Remember the parent pid and invalidate the cached value while we fork.
   pid_t parent_pid = self->invalidate_cached_pid();
 
-#if defined(__x86_64__) // sys_clone's last two arguments are flipped on x86-64.
-  int result = syscall(__NR_clone, FORK_FLAGS, NULL, NULL, &(self->tid), NULL);
-#else
-  int result = syscall(__NR_clone, FORK_FLAGS, NULL, NULL, NULL, &(self->tid));
-#endif
+  int result = clone(nullptr,
+                     nullptr,
+                     (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD),
+                     nullptr,
+                     nullptr,
+                     nullptr,
+                     &(self->tid));
   if (result == 0) {
     self->set_cached_pid(gettid());
     __bionic_atfork_run_child();
diff --git a/libc/bionic/fortify.cpp b/libc/bionic/fortify.cpp
new file mode 100644
index 0000000..11abeb1
--- /dev/null
+++ b/libc/bionic/fortify.cpp
@@ -0,0 +1,446 @@
+/*
+ * Copyright (C) 2012 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) 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ */
+
+#undef _FORTIFY_SOURCE
+
+#include <poll.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/cdefs.h>
+#include <sys/select.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "private/bionic_fortify.h"
+
+//
+// For more details see:
+//   http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
+//   http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
+//
+// TODO: add a link to similar clang documentation?
+//
+
+int __FD_ISSET_chk(int fd, fd_set* set, size_t set_size) {
+  __check_fd_set("FD_ISSET", fd, set_size);
+  return FD_ISSET(fd, set);
+}
+
+void __FD_CLR_chk(int fd, fd_set* set, size_t set_size) {
+  __check_fd_set("FD_CLR", fd, set_size);
+  FD_CLR(fd, set);
+}
+
+void __FD_SET_chk(int fd, fd_set* set, size_t set_size) {
+  __check_fd_set("FD_SET", fd, set_size);
+  FD_SET(fd, set);
+}
+
+char* __fgets_chk(char* dst, int supplied_size, FILE* stream, size_t dst_len_from_compiler) {
+  if (supplied_size < 0) {
+    __fortify_fatal("fgets: buffer size %d < 0", supplied_size);
+  }
+  __check_buffer_access("fgets", "write into", supplied_size, dst_len_from_compiler);
+  return fgets(dst, supplied_size, stream);
+}
+
+size_t __fread_chk(void* __restrict buf, size_t size, size_t count,
+                   FILE* __restrict stream, size_t buf_size) {
+  size_t total;
+  if (__predict_false(__size_mul_overflow(size, count, &total))) {
+    // overflow: trigger the error path in fread
+    return fread(buf, size, count, stream);
+  }
+  __check_buffer_access("fread", "write into", total, buf_size);
+  return fread(buf, size, count, stream);
+}
+
+size_t __fwrite_chk(const void* __restrict buf, size_t size, size_t count,
+                    FILE* __restrict stream, size_t buf_size) {
+  size_t total;
+  if (__predict_false(__size_mul_overflow(size, count, &total))) {
+    // overflow: trigger the error path in fwrite
+    return fwrite(buf, size, count, stream);
+  }
+  __check_buffer_access("fwrite", "read from", total, buf_size);
+  return fwrite(buf, size, count, stream);
+}
+
+extern char* __getcwd_chk(char* buf, size_t len, size_t actual_size) {
+  __check_buffer_access("getcwd", "write into", len, actual_size);
+  return getcwd(buf, len);
+}
+
+void* __memchr_chk(const void* s, int c, size_t n, size_t actual_size) {
+  __check_buffer_access("memchr", "read from", n, actual_size);
+  return memchr(s, c, n);
+}
+
+// Runtime implementation of __builtin____memmove_chk (used directly by compiler, not in headers).
+extern "C" void* __memmove_chk(void* dst, const void* src, size_t len, size_t dst_len) {
+  __check_buffer_access("memmove", "write into", len, dst_len);
+  return memmove(dst, src, len);
+}
+
+// memcpy is performance-critical enough that we have assembler __memcpy_chk implementations.
+// This function is used to give better diagnostics than we can easily do from assembler.
+extern "C" void* __memcpy_chk_fail(void* /*dst*/, const void* /*src*/, size_t count, size_t dst_len) {
+  __check_count("memcpy", "count", count);
+  __check_buffer_access("memcpy", "write into", count, dst_len);
+  abort(); // One of the above is supposed to have failed, otherwise we shouldn't have been called.
+}
+
+void* __memrchr_chk(const void* s, int c, size_t n, size_t actual_size) {
+  __check_buffer_access("memrchr", "read from", n, actual_size);
+  return memrchr(s, c, n);
+}
+
+// memset is performance-critical enough that we have assembler __memset_chk implementations.
+// This function is used to give better diagnostics than we can easily do from assembler.
+extern "C" void* __memset_chk_fail(void* /*dst*/, int /*byte*/, size_t count, size_t dst_len) {
+  __check_count("memset", "count", count);
+  __check_buffer_access("memset", "write into", count, dst_len);
+  abort(); // One of the above is supposed to have failed, otherwise we shouldn't have been called.
+}
+
+int __poll_chk(pollfd* fds, nfds_t fd_count, int timeout, size_t fds_size) {
+  __check_pollfd_array("poll", fds_size, fd_count);
+  return poll(fds, fd_count, timeout);
+}
+
+int __ppoll_chk(pollfd* fds, nfds_t fd_count, const timespec* timeout,
+                const sigset_t* mask, size_t fds_size) {
+  __check_pollfd_array("ppoll", fds_size, fd_count);
+  return ppoll(fds, fd_count, timeout, mask);
+}
+
+ssize_t __pread64_chk(int fd, void* buf, size_t count, off64_t offset, size_t buf_size) {
+  __check_count("pread64", "count", count);
+  __check_buffer_access("pread64", "write into", count, buf_size);
+  return pread64(fd, buf, count, offset);
+}
+
+ssize_t __pread_chk(int fd, void* buf, size_t count, off_t offset, size_t buf_size) {
+  __check_count("pread", "count", count);
+  __check_buffer_access("pread", "write into", count, buf_size);
+  return pread(fd, buf, count, offset);
+}
+
+ssize_t __pwrite64_chk(int fd, const void* buf, size_t count, off64_t offset,
+                                  size_t buf_size) {
+  __check_count("pwrite64", "count", count);
+  __check_buffer_access("pwrite64", "read from", count, buf_size);
+  return pwrite64(fd, buf, count, offset);
+}
+
+ssize_t __pwrite_chk(int fd, const void* buf, size_t count, off_t offset,
+                                size_t buf_size) {
+  __check_count("pwrite", "count", count);
+  __check_buffer_access("pwrite", "read from", count, buf_size);
+  return pwrite(fd, buf, count, offset);
+}
+
+ssize_t __read_chk(int fd, void* buf, size_t count, size_t buf_size) {
+  __check_count("read", "count", count);
+  __check_buffer_access("read", "write into", count, buf_size);
+  return read(fd, buf, count);
+}
+
+ssize_t __readlinkat_chk(int dirfd, const char* path, char* buf, size_t size, size_t buf_size) {
+  __check_count("readlinkat", "size", size);
+  __check_buffer_access("readlinkat", "write into", size, buf_size);
+  return readlinkat(dirfd, path, buf, size);
+}
+
+ssize_t __readlink_chk(const char* path, char* buf, size_t size, size_t buf_size) {
+  __check_count("readlink", "size", size);
+  __check_buffer_access("readlink", "write into", size, buf_size);
+  return readlink(path, buf, size);
+}
+
+ssize_t __recvfrom_chk(int socket, void* buf, size_t len, size_t buf_size,
+                       int flags, const sockaddr* src_addr,
+                       socklen_t* addrlen) {
+  __check_buffer_access("recvfrom", "write into", len, buf_size);
+  return recvfrom(socket, buf, len, flags, src_addr, addrlen);
+}
+
+// Runtime implementation of __builtin____stpcpy_chk (used directly by compiler, not in headers)..
+extern "C" char* __stpcpy_chk(char* dst, const char* src, size_t dst_len) {
+  // TODO: optimize so we don't scan src twice.
+  size_t src_len = strlen(src) + 1;
+  __check_buffer_access("stpcpy", "write into", src_len, dst_len);
+  return stpcpy(dst, src);
+}
+
+// Runtime implementation of __builtin____stpncpy_chk (used directly by compiler, not in headers).
+extern "C" char* __stpncpy_chk(char* __restrict dst, const char* __restrict src,
+                               size_t len, size_t dst_len) {
+  __check_buffer_access("stpncpy", "write into", len, dst_len);
+  return stpncpy(dst, src, len);
+}
+
+// This is a variant of __stpncpy_chk, but it also checks to make
+// sure we don't read beyond the end of "src". The code for this is
+// based on the original version of stpncpy, but modified to check
+// how much we read from "src" at the end of the copy operation.
+char* __stpncpy_chk2(char* __restrict dst, const char* __restrict src,
+                     size_t n, size_t dst_len, size_t src_len) {
+  __check_buffer_access("stpncpy", "write into", n, dst_len);
+  if (n != 0) {
+    char* d = dst;
+    const char* s = src;
+
+    do {
+      if ((*d++ = *s++) == 0) {
+        // NUL pad the remaining n-1 bytes.
+        while (--n != 0) {
+          *d++ = 0;
+        }
+        break;
+      }
+    } while (--n != 0);
+
+    size_t s_copy_len = static_cast<size_t>(s - src);
+    if (__predict_false(s_copy_len > src_len)) {
+      __fortify_fatal("stpncpy: detected read past end of %zu-byte buffer", src_len);
+    }
+  }
+
+  return dst;
+}
+
+// strcat is performance-critical enough that we have assembler __strcat_chk implementations.
+// This function is used to give better diagnostics than we can easily do from assembler.
+extern "C" void __strcat_chk_fail(size_t dst_buf_size) {
+  __fortify_fatal("strcat: prevented write past end of %zu-byte buffer", dst_buf_size);
+}
+
+char* __strchr_chk(const char* p, int ch, size_t s_len) {
+  for (;; ++p, s_len--) {
+    if (__predict_false(s_len == 0)) {
+      __fortify_fatal("strchr: prevented read past end of buffer");
+    }
+    if (*p == static_cast<char>(ch)) {
+      return const_cast<char*>(p);
+    }
+    if (*p == '\0') {
+      return NULL;
+    }
+  }
+}
+
+// strcpy is performance-critical enough that we have assembler __strcpy_chk implementations.
+// This function is used to give better diagnostics than we can easily do from assembler.
+extern "C" void __strcpy_chk_fail(size_t dst_buf_size) {
+  __fortify_fatal("strcpy: prevented write past end of %zu-byte buffer", dst_buf_size);
+}
+
+size_t __strlcat_chk(char* dst, const char* src,
+                     size_t supplied_size, size_t dst_len_from_compiler) {
+  __check_buffer_access("strlcat", "write into", supplied_size, dst_len_from_compiler);
+  return strlcat(dst, src, supplied_size);
+}
+
+size_t __strlcpy_chk(char* dst, const char* src,
+                     size_t supplied_size, size_t dst_len_from_compiler) {
+  __check_buffer_access("strlcpy", "write into", supplied_size, dst_len_from_compiler);
+  return strlcpy(dst, src, supplied_size);
+}
+
+size_t __strlen_chk(const char* s, size_t s_len) {
+  // TODO: "prevented" here would be a lie because this strlen can run off the end.
+  // strlen is too important to be expensive, so we wanted to be able to call the optimized
+  // implementation, but I think we need to implement optimized assembler __strlen_chk routines.
+  size_t ret = strlen(s);
+  if (__predict_false(ret >= s_len)) {
+    __fortify_fatal("strlen: detected read past end of buffer");
+  }
+  return ret;
+}
+
+// Runtime implementation of __builtin____strncat_chk (used directly by compiler, not in headers).
+extern "C" char* __strncat_chk(char* __restrict dst, const char* __restrict src,
+                               size_t len, size_t dst_buf_size) {
+  if (len == 0) {
+    return dst;
+  }
+
+  size_t dst_len = __strlen_chk(dst, dst_buf_size);
+  char* d = dst + dst_len;
+  dst_buf_size -= dst_len;
+
+  while (*src != '\0') {
+    *d++ = *src++;
+    len--; dst_buf_size--;
+
+    if (__predict_false(dst_buf_size == 0)) {
+      __fortify_fatal("strncat: prevented write past end of buffer");
+    }
+
+    if (len == 0) {
+      break;
+    }
+  }
+
+  *d = '\0';
+  return dst;
+}
+
+// Runtime implementation of __builtin____strncpy_chk (used directly by compiler, not in headers).
+extern "C" char* __strncpy_chk(char* __restrict dst, const char* __restrict src,
+                               size_t len, size_t dst_len) {
+  __check_buffer_access("strncpy", "write into", len, dst_len);
+  return strncpy(dst, src, len);
+}
+
+// This is a variant of __strncpy_chk, but it also checks to make
+// sure we don't read beyond the end of "src". The code for this is
+// based on the original version of strncpy, but modified to check
+// how much we read from "src" at the end of the copy operation.
+char* __strncpy_chk2(char* __restrict dst, const char* __restrict src,
+                                size_t n, size_t dst_len, size_t src_len) {
+  __check_buffer_access("strncpy", "write into", n, dst_len);
+  if (n != 0) {
+    char* d = dst;
+    const char* s = src;
+
+    do {
+      if ((*d++ = *s++) == 0) {
+        // NUL pad the remaining n-1 bytes.
+        while (--n != 0) {
+          *d++ = 0;
+        }
+        break;
+      }
+    } while (--n != 0);
+
+    size_t s_copy_len = static_cast<size_t>(s - src);
+    if (__predict_false(s_copy_len > src_len)) {
+      __fortify_fatal("strncpy: detected read past end of %zu-byte buffer", src_len);
+    }
+  }
+
+  return dst;
+}
+
+char* __strrchr_chk(const char* p, int ch, size_t s_len) {
+  for (const char* save = NULL;; ++p, s_len--) {
+    if (s_len == 0) {
+      __fortify_fatal("strrchr: prevented read past end of buffer");
+    }
+    if (*p == static_cast<char>(ch)) {
+      save = p;
+    }
+    if (!*p) {
+      return const_cast<char*>(save);
+    }
+  }
+}
+
+mode_t __umask_chk(mode_t mode) {
+  if (__predict_false((mode & 0777) != mode)) {
+    __fortify_fatal("umask: called with invalid mask %o", mode);
+  }
+
+  return umask(mode);
+}
+
+// Runtime implementation of __builtin____vsnprintf_chk (used directly by compiler, not in headers).
+extern "C" int __vsnprintf_chk(char* dst, size_t supplied_size, int /*flags*/,
+                               size_t dst_len_from_compiler, const char* format, va_list va) {
+  __check_buffer_access("vsnprintf", "write into", supplied_size, dst_len_from_compiler);
+  return vsnprintf(dst, supplied_size, format, va);
+}
+
+// Runtime implementation of __builtin____snprintf_chk (used directly by compiler, not in headers).
+extern "C" int __snprintf_chk(char* dst, size_t supplied_size, int flags,
+                              size_t dst_len_from_compiler, const char* format, ...) {
+  va_list va;
+  va_start(va, format);
+  int result = __vsnprintf_chk(dst, supplied_size, flags, dst_len_from_compiler, format, va);
+  va_end(va);
+  return result;
+}
+
+// Runtime implementation of __builtin____vsprintf_chk (used directly by compiler, not in headers).
+extern "C" int __vsprintf_chk(char* dst, int /*flags*/,
+                              size_t dst_len_from_compiler, const char* format, va_list va) {
+  int result = vsnprintf(dst, dst_len_from_compiler, format, va);
+  __check_buffer_access("vsprintf", "write into", result + 1, dst_len_from_compiler);
+  return result;
+}
+
+// Runtime implementation of __builtin____sprintf_chk (used directly by compiler, not in headers).
+extern "C" int __sprintf_chk(char* dst, int flags, size_t dst_len_from_compiler,
+                             const char* format, ...) {
+  va_list va;
+  va_start(va, format);
+  int result = __vsprintf_chk(dst, flags, dst_len_from_compiler, format, va);
+  va_end(va);
+  return result;
+}
+
+ssize_t __write_chk(int fd, const void* buf, size_t count, size_t buf_size) {
+  __check_count("write", "count", count);
+  __check_buffer_access("write", "read from", count, buf_size);
+  return write(fd, buf, count);
+}
diff --git a/libc/bionic/fpclassify.cpp b/libc/bionic/fpclassify.cpp
index 21ff946..f8cea80 100644
--- a/libc/bionic/fpclassify.cpp
+++ b/libc/bionic/fpclassify.cpp
@@ -29,7 +29,8 @@
 #include <sys/types.h>
 
 #include <math.h>
-#include <machine/ieee.h>
+
+#include "private/bionic_ieee.h"
 
 // These aren't declared in our <math.h>.
 extern "C" int __isinf(double);
diff --git a/libc/bionic/ftw.cpp b/libc/bionic/ftw.cpp
new file mode 100644
index 0000000..2123619
--- /dev/null
+++ b/libc/bionic/ftw.cpp
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2003, 2004 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Sponsored in part by the Defense Advanced Research Projects
+ * Agency (DARPA) and Air Force Research Laboratory, Air Force
+ * Materiel Command, USAF, under agreement number F39502-99-1-0512.
+ */
+
+#include <errno.h>
+#include <fts.h>
+#include <ftw.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+static int do_nftw(const char *path,
+                   int (*ftw_fn)(const char*, const struct stat*, int),
+                   int (*nftw_fn)(const char*, const struct stat*, int, FTW*),
+                   int nfds,
+                   int nftw_flags) {
+  // TODO: nfds is currently unused.
+  if (nfds < 1) {
+    errno = EINVAL;
+    return -1;
+  }
+
+  // Translate to fts_open options.
+  int fts_options = FTS_LOGICAL | FTS_COMFOLLOW | FTS_NOCHDIR;
+  if (nftw_fn) {
+    fts_options = FTS_COMFOLLOW | ((nftw_flags & FTW_PHYS) ? FTS_PHYSICAL : FTS_LOGICAL);
+    if (!(nftw_flags & FTW_CHDIR)) fts_options |= FTS_NOCHDIR;
+    if (nftw_flags & FTW_MOUNT) fts_options |= FTS_XDEV;
+  }
+  bool postorder = (nftw_flags & FTW_DEPTH) != 0;
+
+  // Call fts_open.
+  char* const paths[2] = { const_cast<char*>(path), nullptr };
+  FTS* fts = fts_open(paths, fts_options, nullptr);
+  if (fts == nullptr) {
+    return -1;
+  }
+
+  // Translate fts_read results into ftw/nftw callbacks.
+  int error = 0;
+  FTSENT* cur;
+  while (error == 0 && (cur = fts_read(fts)) != nullptr) {
+    int fn_flag;
+    switch (cur->fts_info) {
+      case FTS_D:
+        // In the postorder case, we'll translate FTS_DP to FTW_DP later.
+        // In the can't-access case, we'll translate FTS_DNR to FTW_DNR later.
+        if (postorder || access(cur->fts_path, R_OK) == -1) continue;
+        fn_flag = FTW_D;
+        break;
+      case FTS_DNR:
+        fn_flag = FTW_DNR;
+        break;
+      case FTS_DP:
+        if (!postorder) continue;
+        fn_flag = FTW_DP;
+        break;
+      case FTS_F:
+      case FTS_DEFAULT:
+        fn_flag = FTW_F;
+        break;
+      case FTS_NS:
+      case FTS_NSOK:
+        fn_flag = FTW_NS;
+        break;
+      case FTS_SL:
+        fn_flag = FTW_SL;
+        break;
+      case FTS_SLNONE:
+        fn_flag = (nftw_fn != nullptr) ? FTW_SLN : FTW_NS;
+        break;
+      case FTS_DC:
+        errno = ELOOP;
+        error = -1;
+        continue;
+      default:
+        error = -1;
+        continue;
+    }
+
+    // Call the appropriate function.
+    if (nftw_fn != nullptr) {
+      FTW ftw;
+      ftw.base = cur->fts_pathlen - cur->fts_namelen;
+      ftw.level = cur->fts_level;
+      error = nftw_fn(cur->fts_path, cur->fts_statp, fn_flag, &ftw);
+    } else {
+      error = ftw_fn(cur->fts_path, cur->fts_statp, fn_flag);
+    }
+  }
+
+  int saved_errno = errno;
+  if (fts_close(fts) != 0 && error == 0) {
+    error = -1;
+  } else {
+    errno = saved_errno;
+  }
+  return error;
+}
+
+int ftw(const char* path, int (*ftw_fn)(const char*, const struct stat*, int), int nfds) {
+  return do_nftw(path, ftw_fn, nullptr, nfds, 0);
+}
+
+int nftw(const char* path, int (*nftw_fn)(const char*, const struct stat*, int, FTW*),
+         int nfds, int nftw_flags) {
+  return do_nftw(path, nullptr, nftw_fn, nfds, nftw_flags);
+}
diff --git a/libc/bionic/utimes.cpp b/libc/bionic/getdomainname.cpp
similarity index 71%
rename from libc/bionic/utimes.cpp
rename to libc/bionic/getdomainname.cpp
index 0b66e6c..761a999 100644
--- a/libc/bionic/utimes.cpp
+++ b/libc/bionic/getdomainname.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 The Android Open Source Project
+ * Copyright (C) 2016 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -27,21 +27,23 @@
  */
 
 #include <errno.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/time.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/utsname.h>
 
-#include "private/bionic_time_conversions.h"
+int getdomainname(char* name, size_t len) {
+  utsname uts;
+  if (uname(&uts) == -1) return -1;
 
-int utimes(const char* path, const timeval tv[2]) {
-  timespec ts[2];
-  timespec* ts_ptr = NULL;
-  if (tv != NULL) {
-    if (!timespec_from_timeval(ts[0], tv[0]) || !timespec_from_timeval(ts[1], tv[1])) {
+  // Note: getdomainname()'s behavior varies across implementations when len is
+  // too small.  bionic follows the historical libc policy of returning EINVAL,
+  // instead of glibc's policy of copying the first len bytes without a NULL
+  // terminator.
+  if (strlen(uts.domainname) >= len) {
       errno = EINVAL;
       return -1;
-    }
-    ts_ptr = ts;
   }
-  return utimensat(AT_FDCWD, path, ts_ptr, 0);
+
+  strncpy(name, uts.domainname, len);
+  return 0;
 }
diff --git a/libc/arch-mips/bionic/bzero.S b/libc/bionic/getpagesize.cpp
similarity index 85%
rename from libc/arch-mips/bionic/bzero.S
rename to libc/bionic/getpagesize.cpp
index 6e5d294..3a59900 100644
--- a/libc/arch-mips/bionic/bzero.S
+++ b/libc/bionic/getpagesize.cpp
@@ -26,14 +26,10 @@
  * SUCH DAMAGE.
  */
 
-#include <private/bionic_asm.h>
+#include <unistd.h>
 
-// void bzero(void*, size_t);
-ENTRY(bzero)
-	.set	noreorder
-	.cpload	t9
-	move	a2,a1
-	la	t9,memset
-	j	t9
-	 move	a1,zero
-END(bzero)
+// Portable code should use sysconf(_SC_PAGE_SIZE) directly instead.
+int getpagesize() {
+  // We dont use sysconf(3) here because that drags in stdio, which makes static binaries fat.
+  return PAGE_SIZE;
+}
diff --git a/libc/bionic/getpid.cpp b/libc/bionic/getpid.cpp
index a3d5b35..779b147 100644
--- a/libc/bionic/getpid.cpp
+++ b/libc/bionic/getpid.cpp
@@ -35,10 +35,12 @@
 pid_t getpid() {
   pthread_internal_t* self = __get_thread();
 
-  // Do we have a valid cached pid?
-  pid_t cached_pid;
-  if (__predict_true(self->get_cached_pid(&cached_pid))) {
-    return cached_pid;
+  if (__predict_true(self)) {
+    // Do we have a valid cached pid?
+    pid_t cached_pid;
+    if (__predict_true(self->get_cached_pid(&cached_pid))) {
+      return cached_pid;
+    }
   }
 
   // We're still in the dynamic linker or we're in the middle of forking, so ask the kernel.
diff --git a/libc/bionic/stubs.cpp b/libc/bionic/grp_pwd.cpp
similarity index 82%
rename from libc/bionic/stubs.cpp
rename to libc/bionic/grp_pwd.cpp
index 374d015..332b2b8 100644
--- a/libc/bionic/stubs.cpp
+++ b/libc/bionic/grp_pwd.cpp
@@ -30,7 +30,6 @@
 #include <errno.h>
 #include <grp.h>
 #include <mntent.h>
-#include <netdb.h>
 #include <pthread.h>
 #include <pwd.h>
 #include <stdio.h>
@@ -55,6 +54,8 @@
   group group_;
   char* group_members_[2];
   char group_name_buffer_[32];
+  // Must be last so init_group_state can run a simple memset for the above
+  ssize_t getgrent_idx;
 };
 
 struct passwd_state_t {
@@ -62,13 +63,14 @@
   char name_buffer_[32];
   char dir_buffer_[32];
   char sh_buffer_[32];
+  ssize_t getpwent_idx;
 };
 
 static ThreadLocalBuffer<group_state_t> g_group_tls_buffer;
 static ThreadLocalBuffer<passwd_state_t> g_passwd_tls_buffer;
 
 static void init_group_state(group_state_t* state) {
-  memset(state, 0, sizeof(group_state_t));
+  memset(state, 0, sizeof(group_state_t) - sizeof(state->getgrent_idx));
   state->group_.gr_mem = state->group_members_;
 }
 
@@ -313,27 +315,34 @@
   }
 }
 
+// oem_XXXX -> uid
+//  Supported ranges:
+//   AID_OEM_RESERVED_START to AID_OEM_RESERVED_END (2900-2999)
+//   AID_OEM_RESERVED_2_START to AID_OEM_RESERVED_2_END (5000-5999)
+// Check OEM id is within range.
+static bool is_oem_id(id_t id) {
+  return (((id >= AID_OEM_RESERVED_START) && (id <= AID_OEM_RESERVED_END)) ||
+      ((id >= AID_OEM_RESERVED_2_START) && (id <= AID_OEM_RESERVED_2_END)));
+}
+
 // Translate an OEM name to the corresponding user/group id.
-// oem_XXX -> AID_OEM_RESERVED_2_START + XXX, iff XXX is within range.
 static id_t oem_id_from_name(const char* name) {
   unsigned int id;
   if (sscanf(name, "oem_%u", &id) != 1) {
     return 0;
   }
-  // Check OEM id is within range.
-  if (id > (AID_OEM_RESERVED_2_END - AID_OEM_RESERVED_2_START)) {
+  if (!is_oem_id(id)) {
     return 0;
   }
-  return AID_OEM_RESERVED_2_START + static_cast<id_t>(id);
+  return static_cast<id_t>(id);
 }
 
 static passwd* oem_id_to_passwd(uid_t uid, passwd_state_t* state) {
-  if (uid < AID_OEM_RESERVED_2_START || uid > AID_OEM_RESERVED_2_END) {
+  if (!is_oem_id(uid)) {
     return NULL;
   }
 
-  snprintf(state->name_buffer_, sizeof(state->name_buffer_), "oem_%u",
-           uid - AID_OEM_RESERVED_2_START);
+  snprintf(state->name_buffer_, sizeof(state->name_buffer_), "oem_%u", uid);
   snprintf(state->dir_buffer_, sizeof(state->dir_buffer_), "/");
   snprintf(state->sh_buffer_, sizeof(state->sh_buffer_), "/system/bin/sh");
 
@@ -347,12 +356,12 @@
 }
 
 static group* oem_id_to_group(gid_t gid, group_state_t* state) {
-  if (gid < AID_OEM_RESERVED_2_START || gid > AID_OEM_RESERVED_2_END) {
+  if (!is_oem_id(gid)) {
     return NULL;
   }
 
   snprintf(state->group_name_buffer_, sizeof(state->group_name_buffer_),
-           "oem_%u", gid - AID_OEM_RESERVED_2_START);
+           "oem_%u", gid);
 
   group* gr = &state->group_;
   gr->gr_name   = state->group_name_buffer_;
@@ -461,6 +470,60 @@
   return (pw != NULL) ? pw->pw_name : NULL;
 }
 
+void setpwent() {
+  passwd_state_t* state = g_passwd_tls_buffer.get();
+  if (state) {
+    state->getpwent_idx = 0;
+  }
+}
+
+void endpwent() {
+  setpwent();
+}
+
+passwd* getpwent() {
+  passwd_state_t* state = g_passwd_tls_buffer.get();
+  if (state == NULL) {
+    return NULL;
+  }
+  if (state->getpwent_idx < 0) {
+    return NULL;
+  }
+
+  size_t start = 0;
+  ssize_t end = android_id_count;
+  if (state->getpwent_idx < end) {
+    return android_iinfo_to_passwd(state, android_ids + state->getpwent_idx++);
+  }
+
+  start = end;
+  end += AID_OEM_RESERVED_END - AID_OEM_RESERVED_START + 1;
+
+  if (state->getpwent_idx < end) {
+    return oem_id_to_passwd(
+        state->getpwent_idx++ - start + AID_OEM_RESERVED_START, state);
+  }
+
+  start = end;
+  end += AID_OEM_RESERVED_2_END - AID_OEM_RESERVED_2_START + 1;
+
+  if (state->getpwent_idx < end) {
+    return oem_id_to_passwd(
+        state->getpwent_idx++ - start + AID_OEM_RESERVED_2_START, state);
+  }
+
+  start = end;
+  end += AID_USER - AID_APP; // Do not expose higher users
+
+  if (state->getpwent_idx < end) {
+    return app_id_to_passwd(state->getpwent_idx++ - start + AID_APP, state);
+  }
+
+  // We are not reporting u1_a* and higher or we will be here forever
+  state->getpwent_idx = -1;
+  return NULL;
+}
+
 static group* getgrgid_internal(gid_t gid, group_state_t* state) {
   group* grp = android_id_to_group(state, gid);
   if (grp != NULL) {
@@ -532,28 +595,60 @@
   return getgroup_r(true, name, 0, grp, buf, buflen, result);
 }
 
-// We don't have an /etc/networks, so all inputs return NULL.
-netent* getnetbyname(const char* /*name*/) {
-  return NULL;
+void setgrent() {
+  group_state_t* state = g_group_tls_buffer.get();
+  if (state) {
+    state->getgrent_idx = 0;
+  }
 }
 
-// We don't have an /etc/networks, so all inputs return NULL.
-netent* getnetbyaddr(uint32_t /*net*/, int /*type*/) {
-  return NULL;
+void endgrent() {
+  setgrent();
 }
 
-// We don't have an /etc/protocols, so all inputs return NULL.
-protoent* getprotobyname(const char* /*name*/) {
-  return NULL;
-}
+group* getgrent() {
+  group_state_t* state = g_group_tls_buffer.get();
+  if (state == NULL) {
+    return NULL;
+  }
+  if (state->getgrent_idx < 0) {
+    return NULL;
+  }
 
-// We don't have an /etc/protocols, so all inputs return NULL.
-protoent* getprotobynumber(int /*proto*/) {
-  return NULL;
-}
+  size_t start = 0;
+  ssize_t end = android_id_count;
+  if (state->getgrent_idx < end) {
+    init_group_state(state);
+    return android_iinfo_to_group(state, android_ids + state->getgrent_idx++);
+  }
 
-// Portable code should use sysconf(_SC_PAGE_SIZE) directly instead.
-int getpagesize() {
-  // We dont use sysconf(3) here because that drags in stdio, which makes static binaries fat.
-  return PAGE_SIZE;
+  start = end;
+  end += AID_OEM_RESERVED_END - AID_OEM_RESERVED_START + 1;
+
+  if (state->getgrent_idx < end) {
+    init_group_state(state);
+    return oem_id_to_group(
+        state->getgrent_idx++ - start + AID_OEM_RESERVED_START, state);
+  }
+
+  start = end;
+  end += AID_OEM_RESERVED_2_END - AID_OEM_RESERVED_2_START + 1;
+
+  if (state->getgrent_idx < end) {
+    init_group_state(state);
+    return oem_id_to_group(
+        state->getgrent_idx++ - start + AID_OEM_RESERVED_2_START, state);
+  }
+
+  start = end;
+  end += AID_USER - AID_APP; // Do not expose higher groups
+
+  if (state->getgrent_idx < end) {
+    init_group_state(state);
+    return app_id_to_group(state->getgrent_idx++ - start + AID_APP, state);
+  }
+
+  // We are not reporting u1_a* and higher or we will be here forever
+  state->getgrent_idx = -1;
+  return NULL;
 }
diff --git a/libc/bionic/ifaddrs.cpp b/libc/bionic/ifaddrs.cpp
index 408949c..f5b080c 100644
--- a/libc/bionic/ifaddrs.cpp
+++ b/libc/bionic/ifaddrs.cpp
@@ -59,7 +59,7 @@
   sockaddr_storage ifa_ifu;
   char name[IFNAMSIZ + 1];
 
-  ifaddrs_storage(ifaddrs** list) {
+  explicit ifaddrs_storage(ifaddrs** list) {
     memset(this, 0, sizeof(*this));
 
     // push_front onto `list`.
diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp
index 4f1226d..919080b 100644
--- a/libc/bionic/libc_init_common.cpp
+++ b/libc/bionic/libc_init_common.cpp
@@ -41,13 +41,13 @@
 #include <sys/time.h>
 #include <unistd.h>
 
+#include "private/KernelArgumentBlock.h"
+#include "private/WriteProtected.h"
 #include "private/bionic_auxv.h"
 #include "private/bionic_globals.h"
-#include "private/bionic_ssp.h"
 #include "private/bionic_tls.h"
-#include "private/KernelArgumentBlock.h"
 #include "private/libc_logging.h"
-#include "private/WriteProtected.h"
+#include "private/thread_private.h"
 #include "pthread_internal.h"
 
 extern "C" abort_msg_t** __abort_message_ptr;
@@ -61,15 +61,6 @@
 // Declared in <unistd.h>.
 char** environ;
 
-// Declared in "private/bionic_ssp.h".
-uintptr_t __stack_chk_guard = 0;
-
-void __libc_init_global_stack_chk_guard(KernelArgumentBlock& args) {
-  // AT_RANDOM is a pointer to 16 bytes of randomness on the stack.
-  // Take the first 4/8 for the -fstack-protector implementation.
-  __stack_chk_guard = *reinterpret_cast<uintptr_t*>(args.getauxval(AT_RANDOM));
-}
-
 #if defined(__i386__)
 __LIBC_HIDDEN__ void* __libc_sysinfo = nullptr;
 
@@ -78,7 +69,7 @@
 }
 
 // TODO: lose this function and just access __libc_sysinfo directly.
-extern "C" void* __kernel_syscall() {
+__LIBC_HIDDEN__ extern "C" void* __kernel_syscall() {
   return __libc_sysinfo;
 }
 #endif
@@ -90,7 +81,6 @@
   // Initialize libc globals that are needed in both the linker and in libc.
   // In dynamic binaries, this is run at least twice for different copies of the
   // globals, once for the linker's copy and once for the one in libc.so.
-  __libc_init_global_stack_chk_guard(args);
   __libc_auxv = args.auxv;
   __libc_globals.initialize();
   __libc_globals.mutate([&args](libc_globals* globals) {
@@ -99,6 +89,20 @@
   });
 }
 
+#if !defined(__LP64__)
+static void __check_max_thread_id() {
+  if (gettid() > 65535) {
+    __libc_fatal("Limited by the size of pthread_mutex_t, 32 bit bionic libc only accepts "
+                 "pid <= 65535, but current pid is %d", gettid());
+  }
+}
+#endif
+
+static void arc4random_fork_handler() {
+  _rs_forked = 1;
+  _thread_arc4_lock();
+}
+
 void __libc_init_common(KernelArgumentBlock& args) {
   // Initialize various globals.
   environ = args.envp;
@@ -106,10 +110,17 @@
   __progname = args.argv[0] ? args.argv[0] : "<unknown>";
   __abort_message_ptr = args.abort_message_ptr;
 
+#if !defined(__LP64__)
+  __check_max_thread_id();
+#endif
+
   // Get the main thread from TLS and add it to the thread list.
   pthread_internal_t* main_thread = __get_thread();
   __pthread_internal_add(main_thread);
 
+  // Register atfork handlers to take and release the arc4random lock.
+  pthread_atfork(arc4random_fork_handler, _thread_arc4_unlock, _thread_arc4_unlock);
+
   __system_properties_init(); // Requires 'environ'.
 }
 
diff --git a/libc/bionic/libc_init_dynamic.cpp b/libc/bionic/libc_init_dynamic.cpp
index ab48fb8..43bca30 100644
--- a/libc/bionic/libc_init_dynamic.cpp
+++ b/libc/bionic/libc_init_dynamic.cpp
@@ -52,6 +52,7 @@
 #include "libc_init_common.h"
 
 #include "private/bionic_globals.h"
+#include "private/bionic_ssp.h"
 #include "private/bionic_tls.h"
 #include "private/KernelArgumentBlock.h"
 
@@ -74,6 +75,10 @@
   // __libc_init_common() will change the TLS area so the old one won't be accessible anyway.
   *args_slot = NULL;
 
+  // The linker has initialized its copy of the global stack_chk_guard, and filled in the main
+  // thread's TLS slot with that value. Initialize the local global stack guard with its value.
+  __stack_chk_guard = reinterpret_cast<uintptr_t>(tls[TLS_SLOT_STACK_GUARD]);
+
   __libc_init_globals(*args);
   __libc_init_common(*args);
 
diff --git a/libc/bionic/libc_init_static.cpp b/libc/bionic/libc_init_static.cpp
index d1494d7..5e06d39 100644
--- a/libc/bionic/libc_init_static.cpp
+++ b/libc/bionic/libc_init_static.cpp
@@ -39,6 +39,7 @@
 #include "libc_init_common.h"
 #include "pthread_internal.h"
 
+#include "private/bionic_globals.h"
 #include "private/bionic_page.h"
 #include "private/bionic_tls.h"
 #include "private/KernelArgumentBlock.h"
@@ -85,6 +86,7 @@
   __libc_init_main_thread(args);
 
   // Initializing the globals requires TLS to be available for errno.
+  __init_thread_stack_guard(__get_thread());
   __libc_init_globals(args);
 
   __libc_init_AT_SECURE(args);
diff --git a/libc/bionic/libc_logging.cpp b/libc/bionic/libc_logging.cpp
index fffaea8..517d047 100644
--- a/libc/bionic/libc_logging.cpp
+++ b/libc/bionic/libc_logging.cpp
@@ -107,7 +107,7 @@
 
 struct FdOutputStream {
  public:
-  FdOutputStream(int fd) : total(0), fd_(fd) {
+  explicit FdOutputStream(int fd) : total(0), fd_(fd) {
   }
 
   void Send(const char* data, int len) {
@@ -459,13 +459,8 @@
   // found that all logd crashes thus far have had no problem stuffing
   // the UNIX domain socket and moving on so not critical *today*.
 
-  int log_fd = TEMP_FAILURE_RETRY(socket(PF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0));
-  if (log_fd < 0) {
-    return -1;
-  }
-
-  if (fcntl(log_fd, F_SETFL, O_NONBLOCK) == -1) {
-    close(log_fd);
+  int log_fd = TEMP_FAILURE_RETRY(socket(PF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0));
+  if (log_fd == -1) {
     return -1;
   }
 
@@ -597,57 +592,15 @@
   return result;
 }
 
-static int __libc_android_log_event(int32_t tag, char type, const void* payload, size_t len) {
-  iovec vec[6];
-  char log_id = LOG_ID_EVENTS;
-  vec[0].iov_base = &log_id;
-  vec[0].iov_len = sizeof(log_id);
-  uint16_t tid = gettid();
-  vec[1].iov_base = &tid;
-  vec[1].iov_len = sizeof(tid);
-  timespec ts;
-  clock_gettime(__android_log_clockid(), &ts);
-  log_time realtime_ts;
-  realtime_ts.tv_sec = ts.tv_sec;
-  realtime_ts.tv_nsec = ts.tv_nsec;
-  vec[2].iov_base = &realtime_ts;
-  vec[2].iov_len = sizeof(realtime_ts);
-
-  vec[3].iov_base = &tag;
-  vec[3].iov_len = sizeof(tag);
-  vec[4].iov_base = &type;
-  vec[4].iov_len = sizeof(type);
-  vec[5].iov_base = const_cast<void*>(payload);
-  vec[5].iov_len = len;
-
-  int event_log_fd = __libc_open_log_socket();
-
-  if (event_log_fd == -1) {
-    return -1;
-  }
-  int result = TEMP_FAILURE_RETRY(writev(event_log_fd, vec, sizeof(vec) / sizeof(vec[0])));
-  close(event_log_fd);
-  return result;
-}
-
-void __libc_android_log_event_int(int32_t tag, int value) {
-  __libc_android_log_event(tag, EVENT_TYPE_INT, &value, sizeof(value));
-}
-
-void __libc_android_log_event_uid(int32_t tag) {
-  __libc_android_log_event_int(tag, getuid());
-}
-
-void __fortify_chk_fail(const char* msg, uint32_t tag) {
-  if (tag != 0) {
-    __libc_android_log_event_uid(tag);
-  }
-  __libc_fatal("FORTIFY: %s", msg);
-}
-
-static void __libc_fatal(const char* format, va_list args) {
+static void __libc_fatal_va_list(const char* prefix, const char* format, va_list args) {
   char msg[1024];
   BufferOutputStream os(msg, sizeof(msg));
+
+  if (prefix) {
+    os.Send(prefix, strlen(prefix));
+    os.Send(": ", 2);
+  }
+
   out_vformat(os, format, args);
 
   // Log to stderr for the benefit of "adb shell" users.
@@ -663,17 +616,18 @@
   android_set_abort_message(msg);
 }
 
-void __libc_fatal_no_abort(const char* format, ...) {
+void __libc_fatal(const char* fmt, ...) {
   va_list args;
-  va_start(args, format);
-  __libc_fatal(format, args);
+  va_start(args, fmt);
+  __libc_fatal_va_list(nullptr, fmt, args);
   va_end(args);
+  abort();
 }
 
-void __libc_fatal(const char* format, ...) {
+void __fortify_fatal(const char* fmt, ...) {
   va_list args;
-  va_start(args, format);
-  __libc_fatal(format, args);
+  va_start(args, fmt);
+  __libc_fatal_va_list("FORTIFY", fmt, args);
   va_end(args);
   abort();
 }
diff --git a/libc/bionic/locale.cpp b/libc/bionic/locale.cpp
index b42b440..2a4ce68 100644
--- a/libc/bionic/locale.cpp
+++ b/libc/bionic/locale.cpp
@@ -44,10 +44,10 @@
 struct __locale_t {
   size_t mb_cur_max;
 
-  __locale_t(size_t mb_cur_max) : mb_cur_max(mb_cur_max) {
+  explicit __locale_t(size_t mb_cur_max) : mb_cur_max(mb_cur_max) {
   }
 
-  __locale_t(const __locale_t* other) {
+  explicit __locale_t(const __locale_t* other) {
     if (other == LC_GLOBAL_LOCALE) {
       mb_cur_max = __bionic_current_locale_is_utf8 ? 4 : 1;
     } else {
@@ -192,10 +192,6 @@
   return strerror(error);
 }
 
-size_t strftime_l(char* s, size_t max, const char* format, const struct tm* tm, locale_t) {
-  return strftime(s, max, format, tm);
-}
-
 int strncasecmp_l(const char* s1, const char* s2, size_t n, locale_t) {
   return strncasecmp(s1, s2, n);
 }
diff --git a/libc/include/sys/utime.h b/libc/bionic/mblen.cpp
similarity index 87%
copy from libc/include/sys/utime.h
copy to libc/bionic/mblen.cpp
index 9f8810e..7def6f1 100644
--- a/libc/include/sys/utime.h
+++ b/libc/bionic/mblen.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) 2016 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -25,9 +25,11 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-#ifndef _SYS_UTIME_H_
-#define _SYS_UTIME_H_
 
-#include <linux/utime.h>
+#include <stdlib.h>
+#include <wchar.h>
 
-#endif /* _SYS_UTIME_H_ */
+int mblen(const char* s, size_t n) {
+  mbstate_t state = {};
+  return mbrlen(s, n, &state);
+}
diff --git a/libc/bionic/mntent.cpp b/libc/bionic/mntent.cpp
index d169e29..994b84d 100644
--- a/libc/bionic/mntent.cpp
+++ b/libc/bionic/mntent.cpp
@@ -77,3 +77,24 @@
   }
   return 1;
 }
+
+char* hasmntopt(const struct mntent* mnt, const char* opt) {
+  char* token = mnt->mnt_opts;
+  char* const end = mnt->mnt_opts + strlen(mnt->mnt_opts);
+  const size_t optLen = strlen(opt);
+
+  while (token) {
+    char* const tokenEnd = token + optLen;
+    if (tokenEnd > end) break;
+
+    if (memcmp(token, opt, optLen) == 0 &&
+        (*tokenEnd == '\0' || *tokenEnd == ',' || *tokenEnd == '=')) {
+      return token;
+    }
+
+    token = strchr(token, ',');
+    if (token) token++;
+  }
+
+  return nullptr;
+}
diff --git a/libc/bionic/ndk_cruft.cpp b/libc/bionic/ndk_cruft.cpp
index 3ac88f8..53efef0 100644
--- a/libc/bionic/ndk_cruft.cpp
+++ b/libc/bionic/ndk_cruft.cpp
@@ -45,6 +45,7 @@
 #include <unistd.h>
 #include <wchar.h>
 
+#include "private/bionic_macros.h"
 #include "private/libc_logging.h"
 
 extern "C" {
@@ -240,15 +241,17 @@
   return signal(signum, handler);
 }
 
-#if !defined(__i386__)
 // This was removed from POSIX 2008.
 #undef bcopy
 void bcopy(const void* src, void* dst, size_t n) {
   memmove(dst, src, n);
 }
-#else
-// x86 has an assembler implementation.
-#endif
+
+// This was removed from POSIX 2008.
+#undef bzero
+void bzero(void* dst, size_t n) {
+  memset(dst, 0, n);
+}
 
 // sysv_signal() was never in POSIX.
 extern "C++" sighandler_t _signal(int signum, sighandler_t handler, int flags);
@@ -364,10 +367,6 @@
   return __set_errno_internal(n);
 }
 
-// This was never implemented in bionic, only needed for ABI compatibility with the NDK.
-// In the M time frame, over 1000 apps have a reference to this!
-void endpwent() { }
-
 // Since dlmalloc_inspect_all and dlmalloc_trim are exported for systems
 // that use dlmalloc, be consistent and export them everywhere.
 void dlmalloc_inspect_all(void (*)(void*, void*, size_t, void*), void*) {
@@ -378,4 +377,12 @@
 
 #endif // !defined(__BRILLO__) && !defined (__LP64__)
 
+#if !defined(__LP64__)
+// LP32's <stdio.h> had putw (but not getw).
+// TODO: does brillo intentionally include this, or is there a missing `nobrillo`?
+int putw(int value, FILE* fp) {
+    return fwrite(&value, sizeof(value), 1, fp) == 1 ? 0 : EOF;
+}
+#endif
+
 } // extern "C"
diff --git a/libc/bionic/net_if.cpp b/libc/bionic/net_if.cpp
index f8d73bd..db9c9ea2 100644
--- a/libc/bionic/net_if.cpp
+++ b/libc/bionic/net_if.cpp
@@ -77,7 +77,7 @@
   if_list* next;
   struct if_nameindex data;
 
-  if_list(if_list** list) {
+  explicit if_list(if_list** list) {
     // push_front onto `list`.
     next = *list;
     *list = this;
diff --git a/libc/arch-mips/bionic/bzero.S b/libc/bionic/netdb.cpp
similarity index 71%
copy from libc/arch-mips/bionic/bzero.S
copy to libc/bionic/netdb.cpp
index 6e5d294..da61f98 100644
--- a/libc/arch-mips/bionic/bzero.S
+++ b/libc/bionic/netdb.cpp
@@ -26,14 +26,24 @@
  * SUCH DAMAGE.
  */
 
-#include <private/bionic_asm.h>
+#include <netdb.h>
 
-// void bzero(void*, size_t);
-ENTRY(bzero)
-	.set	noreorder
-	.cpload	t9
-	move	a2,a1
-	la	t9,memset
-	j	t9
-	 move	a1,zero
-END(bzero)
+// We don't have an /etc/networks, so all inputs return NULL.
+netent* getnetbyname(const char* /*name*/) {
+  return NULL;
+}
+
+// We don't have an /etc/networks, so all inputs return NULL.
+netent* getnetbyaddr(uint32_t /*net*/, int /*type*/) {
+  return NULL;
+}
+
+// We don't have an /etc/protocols, so all inputs return NULL.
+protoent* getprotobyname(const char* /*name*/) {
+  return NULL;
+}
+
+// We don't have an /etc/protocols, so all inputs return NULL.
+protoent* getprotobynumber(int /*proto*/) {
+  return NULL;
+}
diff --git a/libc/bionic/new.cpp b/libc/bionic/new.cpp
index cd84c2e..76c46ee 100644
--- a/libc/bionic/new.cpp
+++ b/libc/bionic/new.cpp
@@ -14,8 +14,9 @@
  * limitations under the License.
  */
 
-#include <errno.h>
 #include <new>
+
+#include <errno.h>
 #include <stdlib.h>
 
 #include "private/libc_logging.h"
diff --git a/libstdc++/include/cerrno b/libc/bionic/nl_types.cpp
similarity index 77%
rename from libstdc++/include/cerrno
rename to libc/bionic/nl_types.cpp
index e53ca25..2cde591 100644
--- a/libstdc++/include/cerrno
+++ b/libc/bionic/nl_types.cpp
@@ -1,6 +1,5 @@
-/* -*- c++ -*- */
 /*
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2016 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -27,14 +26,20 @@
  * SUCH DAMAGE.
  */
 
-#ifndef BIONIC_LIBSTDCPP_INCLUDE_CERRNO__
-#define BIONIC_LIBSTDCPP_INCLUDE_CERRNO__
+#include <nl_types.h>
 
-/*
- * Standard C++ Library wrapper around the C errno.h header file.
- */
 #include <errno.h>
 
-// errno is a macro, so we can't define std::errno
+nl_catd catopen(const char*, int) {
+  return reinterpret_cast<nl_catd>(-1);
+}
 
-#endif  // BIONIC_LIBSTDCPP_INCLUDE_CERRNO__
+char* catgets(nl_catd, int, int, const char* message) {
+  return const_cast<char*>(message);
+}
+
+int catclose(nl_catd) {
+  // Since we didn't hand out a valid nl_catd, you can't be returning one to us.
+  errno = EBADF;
+  return -1;
+}
diff --git a/libc/bionic/open.cpp b/libc/bionic/open.cpp
index a6d8086..41dce43 100644
--- a/libc/bionic/open.cpp
+++ b/libc/bionic/open.cpp
@@ -64,7 +64,7 @@
 
 int __open_2(const char* pathname, int flags) {
   if (__predict_false((flags & O_CREAT) != 0)) {
-    __fortify_chk_fail("open(O_CREAT): called without specifying a mode", 0);
+    __fortify_fatal("open(O_CREAT): called without specifying a mode");
   }
 
   return __openat(AT_FDCWD, pathname, force_O_LARGEFILE(flags), 0);
@@ -86,7 +86,7 @@
 
 int __openat_2(int fd, const char* pathname, int flags) {
   if ((flags & O_CREAT) != 0) {
-    __fortify_chk_fail("openat(O_CREAT): called without specifying a mode", 0);
+    __fortify_fatal("openat(O_CREAT): called without specifying a mode");
   }
 
   return __openat(fd, pathname, force_O_LARGEFILE(flags), 0);
diff --git a/libc/bionic/posix_timers.cpp b/libc/bionic/posix_timers.cpp
index c8f71c8..c46965f 100644
--- a/libc/bionic/posix_timers.cpp
+++ b/libc/bionic/posix_timers.cpp
@@ -37,7 +37,7 @@
 #include <time.h>
 
 // System calls.
-extern "C" int __rt_sigtimedwait(const sigset_t*, siginfo_t*, const struct timespec*, size_t);
+extern "C" int __rt_sigtimedwait(const sigset_t*, siginfo_t*, const timespec*, size_t);
 extern "C" int __timer_create(clockid_t, sigevent*, __kernel_timer_t*);
 extern "C" int __timer_delete(__kernel_timer_t);
 extern "C" int __timer_getoverrun(__kernel_timer_t);
diff --git a/libc/bionic/pthread_create.cpp b/libc/bionic/pthread_create.cpp
index 34826db..1956a8f 100644
--- a/libc/bionic/pthread_create.cpp
+++ b/libc/bionic/pthread_create.cpp
@@ -46,7 +46,7 @@
 // x86 uses segment descriptors rather than a direct pointer to TLS.
 #if __i386__
 #include <asm/ldt.h>
-extern "C" __LIBC_HIDDEN__ void __init_user_desc(struct user_desc*, int, void*);
+void __init_user_desc(struct user_desc*, bool, void*);
 #endif
 
 extern "C" int __isthreaded;
@@ -56,6 +56,10 @@
   // Slot 0 must point to itself. The x86 Linux kernel reads the TLS from %fs:0.
   thread->tls[TLS_SLOT_SELF] = thread->tls;
   thread->tls[TLS_SLOT_THREAD_ID] = thread;
+  __init_thread_stack_guard(thread);
+}
+
+void __init_thread_stack_guard(pthread_internal_t* thread) {
   // GCC looks in the TLS for the stack guard on x86, so copy it there from our global.
   thread->tls[TLS_SLOT_STACK_GUARD] = reinterpret_cast<void*>(__stack_chk_guard);
 }
diff --git a/libc/bionic/pthread_exit.cpp b/libc/bionic/pthread_exit.cpp
index ceda931..3401ed7 100644
--- a/libc/bionic/pthread_exit.cpp
+++ b/libc/bionic/pthread_exit.cpp
@@ -30,6 +30,7 @@
 
 #include <signal.h>
 #include <stdlib.h>
+#include <string.h>
 #include <sys/mman.h>
 
 #include "pthread_internal.h"
@@ -82,7 +83,7 @@
   if (thread->alternate_signal_stack != NULL) {
     // Tell the kernel to stop using the alternate signal stack.
     stack_t ss;
-    ss.ss_sp = NULL;
+    memset(&ss, 0, sizeof(ss));
     ss.ss_flags = SS_DISABLE;
     sigaltstack(&ss, NULL);
 
diff --git a/libc/bionic/pthread_internal.h b/libc/bionic/pthread_internal.h
index e8be4ae..d2abea0 100644
--- a/libc/bionic/pthread_internal.h
+++ b/libc/bionic/pthread_internal.h
@@ -114,6 +114,7 @@
 
 __LIBC_HIDDEN__ int __init_thread(pthread_internal_t* thread);
 __LIBC_HIDDEN__ void __init_tls(pthread_internal_t* thread);
+__LIBC_HIDDEN__ void __init_thread_stack_guard(pthread_internal_t* thread);
 __LIBC_HIDDEN__ void __init_alternate_signal_stack(pthread_internal_t*);
 
 __LIBC_HIDDEN__ pthread_t           __pthread_internal_add(pthread_internal_t* thread);
@@ -123,11 +124,25 @@
 
 // Make __get_thread() inlined for performance reason. See http://b/19825434.
 static inline __always_inline pthread_internal_t* __get_thread() {
-  return reinterpret_cast<pthread_internal_t*>(__get_tls()[TLS_SLOT_THREAD_ID]);
+  void** tls = __get_tls();
+  if (__predict_true(tls)) {
+    return reinterpret_cast<pthread_internal_t*>(tls[TLS_SLOT_THREAD_ID]);
+  }
+
+  // This happens when called during libc initialization before TLS has been initialized.
+  return nullptr;
 }
 
 __LIBC_HIDDEN__ void pthread_key_clean_all(void);
 
+#if defined(__LP64__)
+// SIGSTKSZ is not big enough for 64-bit arch.
+// See https://code.google.com/p/android/issues/detail?id=187064.
+#define SIGNAL_STACK_SIZE_WITHOUT_GUARD_PAGE (16 * 1024)
+#else
+#define SIGNAL_STACK_SIZE_WITHOUT_GUARD_PAGE SIGSTKSZ
+#endif
+
 /*
  * Traditionally we gave threads a 1MiB stack. When we started
  * allocating per-thread alternate signal stacks to ease debugging of
@@ -135,15 +150,10 @@
  * from the default thread stack size. This should keep memory usage
  * roughly constant.
  */
-#define PTHREAD_STACK_SIZE_DEFAULT ((1 * 1024 * 1024) - SIGSTKSZ)
+#define PTHREAD_STACK_SIZE_DEFAULT ((1 * 1024 * 1024) - SIGNAL_STACK_SIZE_WITHOUT_GUARD_PAGE)
 
 // Leave room for a guard page in the internally created signal stacks.
-#if defined(__LP64__)
-// SIGSTKSZ is not big enough for 64-bit arch. See http://b/23041777.
-#define SIGNAL_STACK_SIZE (16 * 1024 + PAGE_SIZE)
-#else
-#define SIGNAL_STACK_SIZE (SIGSTKSZ + PAGE_SIZE)
-#endif
+#define SIGNAL_STACK_SIZE (SIGNAL_STACK_SIZE_WITHOUT_GUARD_PAGE + PAGE_SIZE)
 
 /* Needed by fork. */
 __LIBC_HIDDEN__ extern void __bionic_atfork_run_prepare();
diff --git a/libc/bionic/pthread_mutex.cpp b/libc/bionic/pthread_mutex.cpp
index 7d8e8a8..14e0ab0 100644
--- a/libc/bionic/pthread_mutex.cpp
+++ b/libc/bionic/pthread_mutex.cpp
@@ -502,6 +502,9 @@
 
 int pthread_mutex_lock(pthread_mutex_t* mutex_interface) {
 #if !defined(__LP64__)
+    // Some apps depend on being able to pass NULL as a mutex and get EINVAL
+    // back. Don't need to worry about it for LP64 since the ABI is brand new,
+    // but keep compatibility for LP32. http://b/19995172.
     if (mutex_interface == NULL) {
         return EINVAL;
     }
@@ -523,6 +526,9 @@
 
 int pthread_mutex_unlock(pthread_mutex_t* mutex_interface) {
 #if !defined(__LP64__)
+    // Some apps depend on being able to pass NULL as a mutex and get EINVAL
+    // back. Don't need to worry about it for LP64 since the ABI is brand new,
+    // but keep compatibility for LP32. http://b/19995172.
     if (mutex_interface == NULL) {
         return EINVAL;
     }
diff --git a/libc/bionic/pthread_setname_np.cpp b/libc/bionic/pthread_setname_np.cpp
index bb1114e..6d2880e 100644
--- a/libc/bionic/pthread_setname_np.cpp
+++ b/libc/bionic/pthread_setname_np.cpp
@@ -41,41 +41,69 @@
 
 // This value is not exported by kernel headers.
 #define MAX_TASK_COMM_LEN 16
-#define TASK_COMM_FMT "/proc/self/task/%d/comm"
+
+static int __open_task_comm_fd(pthread_t t, int flags) {
+  pthread_internal_t* thread = __pthread_internal_find(t);
+  if (thread == nullptr) {
+    errno = ENOENT;
+    return -1;
+  }
+
+  char comm_name[64];
+  snprintf(comm_name, sizeof(comm_name), "/proc/self/task/%d/comm", thread->tid);
+  return open(comm_name, O_CLOEXEC | flags);
+}
+
+int pthread_getname_np(pthread_t t, char* buf, size_t buf_size) {
+  ErrnoRestorer errno_restorer;
+
+  if (buf_size < MAX_TASK_COMM_LEN) return ERANGE;
+
+  // Getting our own name is an easy special case.
+  if (t == pthread_self()) {
+    return prctl(PR_GET_NAME, buf) ? errno : 0;
+  }
+
+  // We have to get another thread's name.
+  int fd = __open_task_comm_fd(t, O_RDONLY);
+  if (fd == -1) return errno;
+
+  ssize_t n = TEMP_FAILURE_RETRY(read(fd, buf, buf_size));
+  close(fd);
+
+  if (n == -1) return errno;
+
+  // The kernel adds a trailing '\n' to the /proc file,
+  // so this is actually the normal case for short names.
+  if (n > 0 && buf[n - 1] == '\n') {
+    buf[n - 1] = '\0';
+    return 0;
+  }
+
+  if (n == static_cast<ssize_t>(buf_size)) return ERANGE;
+  buf[n] = '\0';
+  return 0;
+}
 
 int pthread_setname_np(pthread_t t, const char* thread_name) {
   ErrnoRestorer errno_restorer;
 
   size_t thread_name_len = strlen(thread_name);
-  if (thread_name_len >= MAX_TASK_COMM_LEN) {
-    return ERANGE;
-  }
+  if (thread_name_len >= MAX_TASK_COMM_LEN) return ERANGE;
 
-  // Changing our own name is an easy special case.
+  // Setting our own name is an easy special case.
   if (t == pthread_self()) {
     return prctl(PR_SET_NAME, thread_name) ? errno : 0;
   }
 
-  // We have to change another thread's name.
-  pthread_internal_t* thread = __pthread_internal_find(t);
-  if (thread == NULL) {
-    return ENOENT;
-  }
-  pid_t tid = thread->tid;
+  // We have to set another thread's name.
+  int fd = __open_task_comm_fd(t, O_WRONLY);
+  if (fd == -1) return errno;
 
-  char comm_name[sizeof(TASK_COMM_FMT) + 8];
-  snprintf(comm_name, sizeof(comm_name), TASK_COMM_FMT, tid);
-  int fd = open(comm_name, O_CLOEXEC | O_WRONLY);
-  if (fd == -1) {
-    return errno;
-  }
   ssize_t n = TEMP_FAILURE_RETRY(write(fd, thread_name, thread_name_len));
   close(fd);
 
-  if (n < 0) {
-    return errno;
-  } else if (n != static_cast<ssize_t>(thread_name_len)) {
-    return EIO;
-  }
+  if (n == -1) return errno;
+  if (n != static_cast<ssize_t>(thread_name_len)) return EIO;
   return 0;
 }
diff --git a/libc/arch-mips/bionic/bzero.S b/libc/bionic/sighold.cpp
similarity index 83%
copy from libc/arch-mips/bionic/bzero.S
copy to libc/bionic/sighold.cpp
index 6e5d294..e9c8ca1 100644
--- a/libc/arch-mips/bionic/bzero.S
+++ b/libc/bionic/sighold.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) 2016 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,14 +26,11 @@
  * SUCH DAMAGE.
  */
 
-#include <private/bionic_asm.h>
+#include <signal.h>
 
-// void bzero(void*, size_t);
-ENTRY(bzero)
-	.set	noreorder
-	.cpload	t9
-	move	a2,a1
-	la	t9,memset
-	j	t9
-	 move	a1,zero
-END(bzero)
+int sighold(int sig) {
+  sigset_t set;
+  if (sigemptyset(&set) == -1) return -1;
+  if (sigaddset(&set, sig) == -1) return -1;
+  return sigprocmask(SIG_BLOCK, &set, nullptr);
+}
diff --git a/libstdc++/include/climits b/libc/bionic/sigignore.cpp
similarity index 81%
rename from libstdc++/include/climits
rename to libc/bionic/sigignore.cpp
index df85cb9..06f458e 100644
--- a/libstdc++/include/climits
+++ b/libc/bionic/sigignore.cpp
@@ -1,6 +1,5 @@
-/* -*- c++ -*- */
 /*
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2016 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -27,13 +26,13 @@
  * SUCH DAMAGE.
  */
 
-#ifndef BIONIC_LIBSTDCPP_INCLUDE_CLIMITS__
-#define BIONIC_LIBSTDCPP_INCLUDE_CLIMITS__
+#include <signal.h>
+#include <string.h>
 
-/*
- * Standard C++ Library wrapper around the C limits.h header file.
- */
-
-#include <limits.h>
-
-#endif  // BIONIC_LIBSTDCPP_INCLUDE_CLIMITS__
+int sigignore(int sig) {
+  struct sigaction sa;
+  memset(&sa, 0, sizeof(sa));
+  if (sigemptyset(&sa.sa_mask) == -1) return -1;
+  sa.sa_handler = SIG_IGN;
+  return sigaction(sig, &sa, nullptr);
+}
diff --git a/libc/arch-mips/bionic/bzero.S b/libc/bionic/sigpause.cpp
similarity index 83%
copy from libc/arch-mips/bionic/bzero.S
copy to libc/bionic/sigpause.cpp
index 6e5d294..8ba42d4 100644
--- a/libc/arch-mips/bionic/bzero.S
+++ b/libc/bionic/sigpause.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) 2016 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,14 +26,11 @@
  * SUCH DAMAGE.
  */
 
-#include <private/bionic_asm.h>
+#include <signal.h>
 
-// void bzero(void*, size_t);
-ENTRY(bzero)
-	.set	noreorder
-	.cpload	t9
-	move	a2,a1
-	la	t9,memset
-	j	t9
-	 move	a1,zero
-END(bzero)
+int sigpause(int sig) {
+  sigset_t set;
+  if (sigprocmask(SIG_SETMASK, nullptr, &set) == -1) return -1;
+  if (sigdelset(&set, sig) == -1) return -1;
+  return sigsuspend(&set);
+}
diff --git a/libc/arch-mips/bionic/bzero.S b/libc/bionic/sigrelse.cpp
similarity index 83%
copy from libc/arch-mips/bionic/bzero.S
copy to libc/bionic/sigrelse.cpp
index 6e5d294..ab5554e 100644
--- a/libc/arch-mips/bionic/bzero.S
+++ b/libc/bionic/sigrelse.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) 2016 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,14 +26,11 @@
  * SUCH DAMAGE.
  */
 
-#include <private/bionic_asm.h>
+#include <signal.h>
 
-// void bzero(void*, size_t);
-ENTRY(bzero)
-	.set	noreorder
-	.cpload	t9
-	move	a2,a1
-	la	t9,memset
-	j	t9
-	 move	a1,zero
-END(bzero)
+int sigrelse(int sig) {
+  sigset_t set;
+  if (sigemptyset(&set) == -1) return -1;
+  if (sigaddset(&set, sig) == -1) return -1;
+  return sigprocmask(SIG_UNBLOCK, &set, nullptr);
+}
diff --git a/libc/bionic/__memchr_chk.cpp b/libc/bionic/sigset.cpp
similarity index 64%
copy from libc/bionic/__memchr_chk.cpp
copy to libc/bionic/sigset.cpp
index d141c04..e3f3e72 100644
--- a/libc/bionic/__memchr_chk.cpp
+++ b/libc/bionic/sigset.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 The Android Open Source Project
+ * Copyright (C) 2016 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,14 +26,31 @@
  * SUCH DAMAGE.
  */
 
-#undef _FORTIFY_SOURCE
+#include <signal.h>
 #include <string.h>
-#include "private/libc_logging.h"
 
-extern "C" void* __memchr_chk(const void* s, int c, size_t n, size_t buf_size) {
-  if (__predict_false(n > buf_size)) {
-    __fortify_chk_fail("memchr: prevented read past end of buffer", 0);
+sighandler_t sigset(int sig, sighandler_t disp) {
+  struct sigaction new_sa;
+  if (disp != SIG_HOLD) {
+    memset(&new_sa, 0, sizeof(new_sa));
+    new_sa.sa_handler = disp;
+    sigemptyset(&new_sa.sa_mask);
   }
 
-  return memchr(s, c, n);
+  struct sigaction old_sa;
+  if (sigaction(sig, disp == SIG_HOLD ? nullptr : &new_sa, &old_sa) == -1) {
+    return SIG_ERR;
+  }
+
+  sigset_t new_proc_mask;
+  sigemptyset(&new_proc_mask);
+  sigaddset(&new_proc_mask, sig);
+
+  sigset_t old_proc_mask;
+  if (sigprocmask(disp == SIG_HOLD ? SIG_BLOCK : SIG_UNBLOCK,
+                  &new_proc_mask, &old_proc_mask) == -1) {
+    return SIG_ERR;
+  }
+
+  return sigismember(&old_proc_mask, sig) ? SIG_HOLD : old_sa.sa_handler;
 }
diff --git a/libc/bionic/sigwait.cpp b/libc/bionic/sigwait.cpp
index 873a368..2534b89 100644
--- a/libc/bionic/sigwait.cpp
+++ b/libc/bionic/sigwait.cpp
@@ -33,7 +33,7 @@
 
 #include "private/kernel_sigset_t.h"
 
-extern "C" int __rt_sigtimedwait(const sigset_t* uthese, siginfo_t* uinfo, const struct timespec* uts, size_t sigsetsize);
+extern "C" int __rt_sigtimedwait(const sigset_t*, siginfo_t*, const timespec*, size_t);
 
 int sigwait(const sigset_t* set, int* sig) {
   kernel_sigset_t sigset(set);
diff --git a/libc/bionic/strerror_r.cpp b/libc/bionic/strerror_r.cpp
index d419fb1..a0a0809 100644
--- a/libc/bionic/strerror_r.cpp
+++ b/libc/bionic/strerror_r.cpp
@@ -31,7 +31,7 @@
 
 static const Pair _sys_error_strings[] = {
 #define  __BIONIC_ERRDEF(x,y,z)  { x, z },
-#include <sys/_errdefs.h>
+#include "private/bionic_errdefs.h"
   { 0, NULL }
 };
 
@@ -41,7 +41,7 @@
 
 static const Pair _sys_signal_strings[] = {
 #define  __BIONIC_SIGDEF(signal_number, signal_description)  { signal_number, signal_description },
-#include <sys/_sigdefs.h>
+#include "private/bionic_sigdefs.h"
   { 0, NULL }
 };
 
diff --git a/libc/bionic/__memchr_chk.cpp b/libc/bionic/sync_file_range.cpp
similarity index 75%
copy from libc/bionic/__memchr_chk.cpp
copy to libc/bionic/sync_file_range.cpp
index d141c04..7f60882 100644
--- a/libc/bionic/__memchr_chk.cpp
+++ b/libc/bionic/sync_file_range.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 The Android Open Source Project
+ * Copyright (C) 2016 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,14 +26,15 @@
  * SUCH DAMAGE.
  */
 
-#undef _FORTIFY_SOURCE
-#include <string.h>
-#include "private/libc_logging.h"
+#include <fcntl.h>
 
-extern "C" void* __memchr_chk(const void* s, int c, size_t n, size_t buf_size) {
-  if (__predict_false(n > buf_size)) {
-    __fortify_chk_fail("memchr: prevented read past end of buffer", 0);
-  }
+extern "C" int __sync_file_range(int, off64_t, off64_t, unsigned int);
+extern "C" int __sync_file_range2(int, unsigned int, off64_t, off64_t);
 
-  return memchr(s, c, n);
+int sync_file_range(int fd, off64_t offset, off64_t length, unsigned int flags) {
+#if __arm__
+  return __sync_file_range2(fd, flags, offset, length);
+#else
+  return __sync_file_range(fd, offset, length, flags);
+#endif
 }
diff --git a/libc/bionic/sys_siglist.c b/libc/bionic/sys_siglist.c
index 3cfddbf..8e33d64 100644
--- a/libc/bionic/sys_siglist.c
+++ b/libc/bionic/sys_siglist.c
@@ -30,5 +30,5 @@
 
 const char* const sys_siglist[NSIG] = {
 #define __BIONIC_SIGDEF(signal_number, signal_description) [ signal_number ] = signal_description,
-#include <sys/_sigdefs.h>
+#include "private/bionic_sigdefs.h"
 };
diff --git a/libc/bionic/sys_signame.c b/libc/bionic/sys_signame.c
index e1286f2..5158b83 100644
--- a/libc/bionic/sys_signame.c
+++ b/libc/bionic/sys_signame.c
@@ -30,5 +30,5 @@
 
 const char* const sys_signame[NSIG] = {
 #define __BIONIC_SIGDEF(signal_number, unused) [ signal_number ] = #signal_number + 3,
-#include <sys/_sigdefs.h>
+#include "private/bionic_sigdefs.h"
 };
diff --git a/libc/bionic/utimes.cpp b/libc/bionic/sys_time.cpp
similarity index 67%
copy from libc/bionic/utimes.cpp
copy to libc/bionic/sys_time.cpp
index 0b66e6c..3d0cd87 100644
--- a/libc/bionic/utimes.cpp
+++ b/libc/bionic/sys_time.cpp
@@ -26,22 +26,40 @@
  * SUCH DAMAGE.
  */
 
+#include <sys/time.h>
+
 #include <errno.h>
 #include <fcntl.h>
 #include <sys/stat.h>
-#include <sys/time.h>
 
 #include "private/bionic_time_conversions.h"
 
-int utimes(const char* path, const timeval tv[2]) {
+static int futimesat(int fd, const char* path, const timeval tv[2], int flags) {
   timespec ts[2];
-  timespec* ts_ptr = NULL;
-  if (tv != NULL) {
-    if (!timespec_from_timeval(ts[0], tv[0]) || !timespec_from_timeval(ts[1], tv[1])) {
-      errno = EINVAL;
-      return -1;
-    }
-    ts_ptr = ts;
+  if (tv && (!timespec_from_timeval(ts[0], tv[0]) || !timespec_from_timeval(ts[1], tv[1]))) {
+    errno = EINVAL;
+    return -1;
   }
-  return utimensat(AT_FDCWD, path, ts_ptr, 0);
+  return utimensat(fd, path, tv ? ts : nullptr, flags);
+}
+
+int utimes(const char* path, const timeval tv[2]) {
+  return futimesat(AT_FDCWD, path, tv, 0);
+}
+
+int lutimes(const char* path, const timeval tv[2]) {
+  return futimesat(AT_FDCWD, path, tv, AT_SYMLINK_NOFOLLOW);
+}
+
+int futimesat(int fd, const char* path, const timeval tv[2]) {
+  return futimesat(fd, path, tv, 0);
+}
+
+int futimes(int fd, const timeval tv[2]) {
+  timespec ts[2];
+  if (tv && (!timespec_from_timeval(ts[0], tv[0]) || !timespec_from_timeval(ts[1], tv[1]))) {
+    errno = EINVAL;
+    return -1;
+  }
+  return futimens(fd, tv ? ts : nullptr);
 }
diff --git a/libc/bionic/sysconf.cpp b/libc/bionic/sysconf.cpp
index 125b3c9..7be0ab7 100644
--- a/libc/bionic/sysconf.cpp
+++ b/libc/bionic/sysconf.cpp
@@ -34,7 +34,6 @@
 #include <stdio.h>  // For FOPEN_MAX.
 #include <sys/auxv.h>
 #include <sys/resource.h>
-#include <sys/sysconf.h>
 #include <sys/sysinfo.h>
 #include <time.h>
 #include <unistd.h>
@@ -124,8 +123,8 @@
     case _SC_THREAD_DESTRUCTOR_ITERATIONS: return PTHREAD_DESTRUCTOR_ITERATIONS;
     case _SC_THREAD_KEYS_MAX:   return PTHREAD_KEYS_MAX;
     case _SC_THREAD_STACK_MIN:    return PTHREAD_STACK_MIN;
-    case _SC_THREAD_THREADS_MAX:  return PTHREAD_THREADS_MAX;
-    case _SC_TTY_NAME_MAX:        return 32;  // Seems default on linux.
+    case _SC_THREAD_THREADS_MAX:  return -1; // No specific limit.
+    case _SC_TTY_NAME_MAX:        return 32; // Seems default on linux.
     case _SC_THREADS:             return _POSIX_THREADS;
     case _SC_THREAD_ATTR_STACKADDR:   return _POSIX_THREAD_ATTR_STACKADDR;
     case _SC_THREAD_ATTR_STACKSIZE:   return _POSIX_THREAD_ATTR_STACKSIZE;
diff --git a/libc/bionic/system_properties.cpp b/libc/bionic/system_properties.cpp
index 9c992da..0f68431 100644
--- a/libc/bionic/system_properties.cpp
+++ b/libc/bionic/system_properties.cpp
@@ -192,7 +192,7 @@
     const uint32_t n;
     const prop_info *pi;
 
-    find_nth_cookie(uint32_t n) : count(0), n(n), pi(NULL) {
+    explicit find_nth_cookie(uint32_t n) : count(0), n(n), pi(NULL) {
     }
 };
 
diff --git a/libc/bionic/vdso.cpp b/libc/bionic/vdso.cpp
index 029c148..f3d95ca 100644
--- a/libc/bionic/vdso.cpp
+++ b/libc/bionic/vdso.cpp
@@ -17,7 +17,7 @@
 #include "private/bionic_globals.h"
 #include "private/bionic_vdso.h"
 
-#if defined(__aarch64__) || defined(__x86_64__) || defined (__i386__)
+#if defined(__aarch64__) || defined(__arm__) || defined(__i386__) || defined(__x86_64__)
 
 #include <limits.h>
 #include <link.h>
@@ -28,6 +28,8 @@
 #include <unistd.h>
 #include "private/KernelArgumentBlock.h"
 
+#define AT_SYSINFO_EHDR 33 /* until we have new enough uapi headers... */
+
 int clock_gettime(int clock_id, timespec* tp) {
   auto vdso_clock_gettime = reinterpret_cast<decltype(&clock_gettime)>(
     __libc_globals->vdso[VDSO_CLOCK_GETTIME].fn);
diff --git a/libc/bionic/wctype.cpp b/libc/bionic/wctype.cpp
index f2d7861..05e9c90 100644
--- a/libc/bionic/wctype.cpp
+++ b/libc/bionic/wctype.cpp
@@ -26,11 +26,13 @@
  * SUCH DAMAGE.
  */
 
+#include <wctype.h>
+
 #include <ctype.h>
+#include <errno.h>
 #include <stdlib.h>
 #include <string.h>
 #include <wchar.h>
-#include <wctype.h>
 
 // TODO: these only work for the ASCII range; rewrite to dlsym icu4c? http://b/14499654
 
@@ -85,8 +87,8 @@
 wint_t towlower(wint_t wc) { return tolower(wc); }
 wint_t towupper(wint_t wc) { return toupper(wc); }
 
-int towupper_l(int c, locale_t) { return towupper(c); }
-int towlower_l(int c, locale_t) { return towlower(c); }
+wint_t towupper_l(int c, locale_t) { return towupper(c); }
+wint_t towlower_l(int c, locale_t) { return towlower(c); }
 
 wctype_t wctype(const char* property) {
   static const char* const  properties[WC_TYPE_MAX] = {
@@ -109,3 +111,27 @@
 int wcwidth(wchar_t wc) {
   return (wc > 0);
 }
+
+static wctrans_t wctrans_tolower = wctrans_t(1);
+static wctrans_t wctrans_toupper = wctrans_t(2);
+
+wctrans_t wctrans(const char* name) {
+  if (strcmp(name, "tolower") == 0) return wctrans_tolower;
+  if (strcmp(name, "toupper") == 0) return wctrans_toupper;
+  return 0;
+}
+
+wctrans_t wctrans_l(const char* name, locale_t) {
+  return wctrans(name);
+}
+
+wint_t towctrans(wint_t c, wctrans_t t) {
+  if (t == wctrans_tolower) return towlower(c);
+  if (t == wctrans_toupper) return towupper(c);
+  errno = EINVAL;
+  return 0;
+}
+
+wint_t towctrans_l(wint_t c, wctrans_t t, locale_t) {
+  return towctrans(c, t);
+}
diff --git a/libc/crt.mk b/libc/crt.mk
deleted file mode 100644
index 7b96bf2..0000000
--- a/libc/crt.mk
+++ /dev/null
@@ -1,146 +0,0 @@
-# Define the libc run-time (crt) support object files that must be built,
-# which are needed to build all other objects (shared/static libs and
-# executables)
-# ==========================================================================
-# AArch64, ARM, MIPS, and x86 all need crtbegin_so/crtend_so.
-#
-# For x86, the .init section must point to a function that calls all
-# entries in the .ctors section. (on ARM this is done through the
-# .init_array section instead).
-#
-# For all the platforms, the .fini_array section must point to a function
-# that will call __cxa_finalize(&__dso_handle) in order to ensure that
-# static C++ destructors are properly called on dlclose().
-#
-# Args:
-#     my_2nd_arch_prefix: set to $(TARGET_2ND_ARCH_VAR_PREFIX) if it's
-#                         for the 2nd arch; otherwise empty.
-
-my_arch := $(TARGET_$(my_2nd_arch_prefix)ARCH)
-
-my_libc_crt_target_crtbegin_file := $(libc_crt_target_crtbegin_file_$(my_arch))
-my_libc_crt_target_crtbegin_so_file := $(libc_crt_target_crtbegin_so_file_$(my_arch))
-
-my_libc_crt_target_cflags := \
-    $(libc_crt_target_cflags) \
-    $(libc_crt_target_cflags_$(my_arch))
-
-my_libc_crt_target_so_cflags := \
-    $(libc_crt_target_so_cflags_$(my_arch)) \
-    $(my_libc_crt_target_cflags)
-
-my_libc_crt_target_ldflags := $(libc_crt_target_ldflags_$(my_arch))
-
-# crtbrand.S -> crtbrand.o
-GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.o
-$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC)
-$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_so_cflags)
-$(GEN): $(LOCAL_PATH)/arch-common/bionic/crtbrand.S
-	@mkdir -p $(dir $@)
-	$(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) \
-		-MD -MF $(@:%.o=%.d) -o $@ -c $<
-	$(transform-d-to-p)
-$(call include-depfile,$(GEN:%.o=%.P),$(GEN))
-
-# crtbegin_so.c -> crtbegin_so1.o
-GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so1.o
-$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC)
-$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_so_cflags)
-$(GEN): $(my_libc_crt_target_crtbegin_so_file)
-	@mkdir -p $(dir $@)
-	$(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) \
-		-MD -MF $(@:%.o=%.d) -o $@ -c $<
-	$(transform-d-to-p)
-$(call include-depfile,$(GEN:%.o=%.P),$(GEN))
-
-# crtbegin_so1.o + crtbrand.o -> crtbegin_so.o
-GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so.o
-$(GEN): PRIVATE_LD := $($(my_2nd_arch_prefix)TARGET_LD)
-$(GEN): PRIVATE_LDFLAGS := $(my_libc_crt_target_ldflags)
-$(GEN): $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so1.o \
-    $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.o
-	@mkdir -p $(dir $@)
-	$(hide) $(PRIVATE_LD) $(PRIVATE_LDFLAGS) -r -o $@ $^
-
-# crtend_so.S -> crtend_so.o
-GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_so.o
-$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC)
-$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_so_cflags)
-$(GEN): $(LOCAL_PATH)/arch-common/bionic/crtend_so.S
-	@mkdir -p $(dir $@)
-	$(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) \
-		-MD -MF $(@:%.o=%.d) -o $@ -c $<
-	$(transform-d-to-p)
-$(call include-depfile,$(GEN:%.o=%.P),$(GEN))
-
-# crtbegin_so.o and crtend_so.o are installed to device
-GEN := $($(my_2nd_arch_prefix)TARGET_OUT_SHARED_LIBRARIES)/crtbegin_so.o
-$(GEN): $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so.o
-	$(hide) mkdir -p $(dir $@) && cp -f $< $@
-ALL_GENERATED_SOURCES += $(GEN)
-
-GEN := $($(my_2nd_arch_prefix)TARGET_OUT_SHARED_LIBRARIES)/crtend_so.o
-$(GEN): $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_so.o
-	$(hide) mkdir -p $(dir $@) && cp -f $< $@
-ALL_GENERATED_SOURCES += $(GEN)
-
-# crtbegin.c -> crtbegin_static1.o
-GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static1.o
-$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC)
-$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_cflags)
-$(GEN): $(my_libc_crt_target_crtbegin_file)
-	@mkdir -p $(dir $@)
-	$(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) \
-		-MD -MF $(@:%.o=%.d) -o $@ -c $<
-	$(transform-d-to-p)
-$(call include-depfile,$(GEN:%.o=%.P),$(GEN))
-
-# crtbegin_static1.o + crtbrand.o -> crtbegin_static.o
-GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static.o
-$(GEN): PRIVATE_LD := $($(my_2nd_arch_prefix)TARGET_LD)
-$(GEN): PRIVATE_LDFLAGS := $(my_libc_crt_target_ldflags)
-$(GEN): $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static1.o \
-    $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.o
-	@mkdir -p $(dir $@)
-	$(hide) $(PRIVATE_LD) $(PRIVATE_LDFLAGS) -r -o $@ $^
-
-# crtbegin.c -> crtbegin_dynamic1.o
-GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic1.o
-$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC)
-$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_cflags)
-$(GEN): $(my_libc_crt_target_crtbegin_file)
-	@mkdir -p $(dir $@)
-	$(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) \
-		-MD -MF $(@:%.o=%.d) -o $@ -c $<
-	$(transform-d-to-p)
-$(call include-depfile,$(GEN:%.o=%.P),$(GEN))
-
-# crtbegin_dynamic1.o + crtbrand.o -> crtbegin_dynamic.o
-GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic.o
-$(GEN): PRIVATE_LD := $($(my_2nd_arch_prefix)TARGET_LD)
-$(GEN): PRIVATE_LDFLAGS := $(my_libc_crt_target_ldflags)
-$(GEN): $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic1.o \
-    $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.o
-	@mkdir -p $(dir $@)
-	$(hide) $(PRIVATE_LD) $(PRIVATE_LDFLAGS) -r -o $@ $^
-
-# crtend.S -> crtend_android.o
-# We rename crtend.o to crtend_android.o to avoid a
-# name clash between gcc and bionic.
-GEN := $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_android.o
-$(GEN): PRIVATE_CC := $($(my_2nd_arch_prefix)TARGET_CC)
-$(GEN): PRIVATE_CFLAGS := $(my_libc_crt_target_cflags)
-$(GEN): $(LOCAL_PATH)/arch-common/bionic/crtend.S
-	@mkdir -p $(dir $@)
-	$(hide) $(PRIVATE_CC) $(PRIVATE_CFLAGS) \
-		-MD -MF $(@:%.o=%.d) -o $@ -c $<
-	$(transform-d-to-p)
-$(call include-depfile,$(GEN:%.o=%.P),$(GEN))
-
-# Clear temp vars
-my_libc_crt_target_ldflags :=
-my_libc_crt_target_so_cflags :=
-my_libc_crt_target_cflags :=
-my_libc_crt_target_crtbegin_so_file :=
-my_libc_crt_target_crtbegin_file :=
-my_arch :=
diff --git a/libc/include/nsswitch.h b/libc/dns/include/nsswitch.h
similarity index 92%
rename from libc/include/nsswitch.h
rename to libc/dns/include/nsswitch.h
index af88433..a0ae83b 100644
--- a/libc/include/nsswitch.h
+++ b/libc/dns/include/nsswitch.h
@@ -144,19 +144,6 @@
 
 
 /*
- * Default sourcelists (if nsswitch.conf is missing, corrupt,
- * or the requested database doesn't have an entry)
- */
-extern const ns_src __nsdefaultsrc[];
-extern const ns_src __nsdefaultcompat[];
-extern const ns_src __nsdefaultcompat_forceall[];
-extern const ns_src __nsdefaultfiles[];
-extern const ns_src __nsdefaultfiles_forceall[];
-extern const ns_src __nsdefaultnis[];
-extern const ns_src __nsdefaultnis_forceall[];
-
-
-/*
  * ns_mtab - `nsswitch method table'
  * An nsswitch module provides a mapping from (database name, method name)
  * tuples to the nss_method and associated callback data.  Effectively,
@@ -215,7 +202,7 @@
 
 __BEGIN_DECLS
 int	nsdispatch(void *, const ns_dtab [], const char *,
-			const char *, const ns_src [], ...) __LIBC_ABI_PUBLIC__;
+			const char *, const ns_src [], ...);
 
 #ifdef _NS_PRIVATE
 int		 _nsdbtaddsrc(ns_dbt *, const ns_src *);
diff --git a/libc/dns/include/resolv_netid.h b/libc/dns/include/resolv_netid.h
index 266193a..7182ca6 100644
--- a/libc/dns/include/resolv_netid.h
+++ b/libc/dns/include/resolv_netid.h
@@ -101,9 +101,6 @@
 int android_getnameinfofornet(const struct sockaddr *, socklen_t, char *, size_t, char *, size_t, int, unsigned, unsigned) __LIBC_HIDDEN__;
 FILE* android_open_proxy(void) __LIBC_HIDDEN__;
 
-/* delete the cache associated with a certain network */
-extern void _resolv_delete_cache_for_net(unsigned netid);
-
 __END_DECLS
 
 #endif /* _RESOLV_NETID_H */
diff --git a/libc/dns/include/resolv_private.h b/libc/dns/include/resolv_private.h
index 3ab8ea6..54b9626 100644
--- a/libc/dns/include/resolv_private.h
+++ b/libc/dns/include/resolv_private.h
@@ -63,9 +63,6 @@
 #include <net/if.h>
 #include <time.h>
 
-/* Despite this file's name, it's part of libresolv. On Android, that means it's part of libc :-( */
-#pragma GCC visibility push(default)
-
 // Linux defines MAXHOSTNAMELEN as 64, while the domain name limit in
 // RFC 1034 and RFC 1035 is 255 octets.
 #ifdef MAXHOSTNAMELEN
@@ -536,8 +533,15 @@
 
 #undef __socketcall
 
-__END_DECLS
+// Symbols that are supposed to be in resolv.h, but that we aren't exporting.
+int ns_parserr2(ns_msg*, ns_sect, int, ns_rr2*);
+int ns_name_pton2(const char*, u_char*, size_t, size_t*);
+int ns_name_unpack2(const u_char*, const u_char*, const u_char*, u_char*, size_t, size_t*);
+int ns_name_eq(ns_nname_ct, size_t, ns_nname_ct, size_t);
+int ns_name_owned(ns_namemap_ct, int, ns_namemap_ct, int);
+int ns_name_map(ns_nname_ct, size_t, ns_namemap_t, int);
+int ns_name_labels(ns_nname_ct, size_t);
 
-#pragma GCC visibility pop
+__END_DECLS
 
 #endif /* !_RESOLV_PRIVATE_H_ */
diff --git a/libc/dns/nameser/ns_parse.c b/libc/dns/nameser/ns_parse.c
index 2d6d530..3a1901a 100644
--- a/libc/dns/nameser/ns_parse.c
+++ b/libc/dns/nameser/ns_parse.c
@@ -52,6 +52,8 @@
 
 /* Public. */
 
+struct _ns_flagdata {  int mask, shift;  };
+
 /* These need to be in the same order as the nres.h:ns_flag enum. */
 const struct _ns_flagdata _ns_flagdata[16] = {
 	{ 0x8000, 15 },		/* qr. */
diff --git a/libc/dns/net/getaddrinfo.c b/libc/dns/net/getaddrinfo.c
index 829b679..cc8b8b4 100644
--- a/libc/dns/net/getaddrinfo.c
+++ b/libc/dns/net/getaddrinfo.c
@@ -1791,10 +1791,14 @@
 			return -1;
 		}
 	}
-	if (mark != MARK_UNSET && setsockopt(sock, SOL_SOCKET, SO_MARK, &mark, sizeof(mark)) < 0)
+	if (mark != MARK_UNSET && setsockopt(sock, SOL_SOCKET, SO_MARK, &mark, sizeof(mark)) < 0) {
+		close(sock);
 		return 0;
-	if (uid > 0 && uid != NET_CONTEXT_INVALID_UID && fchown(sock, uid, (gid_t)-1) < 0)
+	}
+	if (uid > 0 && uid != NET_CONTEXT_INVALID_UID && fchown(sock, uid, (gid_t)-1) < 0) {
+		close(sock);
 		return 0;
+	}
 	do {
 		ret = __connect(sock, addr, len);
 	} while (ret == -1 && errno == EINTR);
diff --git a/libc/dns/net/getnameinfo.c b/libc/dns/net/getnameinfo.c
index 893e982..63a347e 100644
--- a/libc/dns/net/getnameinfo.c
+++ b/libc/dns/net/getnameinfo.c
@@ -54,8 +54,6 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <net/if.h>
-#include <net/if_ieee1394.h>
-#include <net/if_types.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <assert.h>
diff --git a/libc/dns/resolv/res_send.c b/libc/dns/resolv/res_send.c
index 1ae675b..4c4b953 100644
--- a/libc/dns/resolv/res_send.c
+++ b/libc/dns/resolv/res_send.c
@@ -1219,9 +1219,6 @@
 		 * XXX - potential security hazard could
 		 *	 be detected here.
 		 */
-#ifdef ANDROID_CHANGES
-		__libc_android_log_event_uid(BIONIC_EVENT_RESOLVER_OLD_RESPONSE);
-#endif
 		DprintQ((statp->options & RES_DEBUG) ||
 			(statp->pfcode & RES_PRF_REPLY),
 			(stdout, ";; old answer:\n"),
@@ -1235,9 +1232,6 @@
 		 * XXX - potential security hazard could
 		 *	 be detected here.
 		 */
-#ifdef ANDROID_CHANGES
-		__libc_android_log_event_uid(BIONIC_EVENT_RESOLVER_WRONG_SERVER);
-#endif
 		DprintQ((statp->options & RES_DEBUG) ||
 			(statp->pfcode & RES_PRF_REPLY),
 			(stdout, ";; not our server:\n"),
@@ -1268,9 +1262,6 @@
 		 * XXX - potential security hazard could
 		 *	 be detected here.
 		 */
-#ifdef ANDROID_CHANGES
-		__libc_android_log_event_uid(BIONIC_EVENT_RESOLVER_WRONG_QUERY);
-#endif
 		DprintQ((statp->options & RES_DEBUG) ||
 			(statp->pfcode & RES_PRF_REPLY),
 			(stdout, ";; wrong query name:\n"),
diff --git a/libc/include/alloca.h b/libc/include/alloca.h
index 0c50fc3..0508d31 100644
--- a/libc/include/alloca.h
+++ b/libc/include/alloca.h
@@ -25,9 +25,12 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #ifndef _ALLOCA_H
 #define _ALLOCA_H
 
+#include <sys/cdefs.h>
+
 #define alloca(size)   __builtin_alloca(size)
 
 #endif /* _ALLOCA_H */
diff --git a/libc/include/android/api-level.h b/libc/include/android/api-level.h
index 2d2f096..001877b 100644
--- a/libc/include/android/api-level.h
+++ b/libc/include/android/api-level.h
@@ -29,10 +29,14 @@
 #ifndef ANDROID_API_LEVEL_H
 #define ANDROID_API_LEVEL_H
 
+#include <sys/cdefs.h>
+
 /*
  * Magic version number for a current development build, which has
  * not yet turned into an official release.
  */
+#ifndef __ANDROID_API__
 #define __ANDROID_API__ 10000
+#endif
 
 #endif /* ANDROID_API_LEVEL_H */
diff --git a/libc/include/android/dlext.h b/libc/include/android/dlext.h
index aa36f1e..ca3bd25 100644
--- a/libc/include/android/dlext.h
+++ b/libc/include/android/dlext.h
@@ -17,6 +17,7 @@
 #ifndef __ANDROID_DLEXT_H__
 #define __ANDROID_DLEXT_H__
 
+#include <stdbool.h>
 #include <stddef.h>
 #include <stdint.h>
 #include <sys/cdefs.h>
@@ -128,7 +129,8 @@
   struct android_namespace_t* library_namespace;
 } android_dlextinfo;
 
-extern void* android_dlopen_ext(const char* filename, int flag, const android_dlextinfo* extinfo);
+void* android_dlopen_ext(const char* filename, int flag, const android_dlextinfo* extinfo)
+  __INTRODUCED_IN(21);
 
 __END_DECLS
 
diff --git a/libc/include/android/legacy_errno_inlines.h b/libc/include/android/legacy_errno_inlines.h
index 71096fc..93cba1f 100644
--- a/libc/include/android/legacy_errno_inlines.h
+++ b/libc/include/android/legacy_errno_inlines.h
@@ -29,8 +29,11 @@
 #ifndef _ANDROID_LEGACY_ERRNO_INLINES_H
 #define _ANDROID_LEGACY_ERRNO_INLINES_H
 
+#include <errno.h>
 #include <sys/cdefs.h>
 
+#if __ANDROID_API__ < 21
+
 __BEGIN_DECLS
 
 static __inline int __attribute__((deprecated)) __set_errno(int n) {
@@ -40,4 +43,5 @@
 
 __END_DECLS
 
+#endif
 #endif /* _ANDROID_LEGACY_ERRNO_INLINES_H */
diff --git a/libc/include/android/legacy_signal_inlines.h b/libc/include/android/legacy_signal_inlines.h
index 1b6e687..8ba7894 100644
--- a/libc/include/android/legacy_signal_inlines.h
+++ b/libc/include/android/legacy_signal_inlines.h
@@ -29,14 +29,19 @@
 #ifndef _ANDROID_LEGACY_SIGNAL_INLINES_H_
 #define _ANDROID_LEGACY_SIGNAL_INLINES_H_
 
+#include <errno.h>
+#include <signal.h>
 #include <string.h>
 #include <sys/cdefs.h>
 
+
 __BEGIN_DECLS
 
-extern sighandler_t bsd_signal(int signum, sighandler_t handler);
+sighandler_t bsd_signal(int signum, sighandler_t handler) __REMOVED_IN(21);
 
-static __inline int sigismember(sigset_t *set, int signum) {
+#if __ANDROID_API__ < 21
+
+static __inline int sigismember(const sigset_t *set, int signum) {
   /* Signal numbers start at 1, but bit positions start at 0. */
   int bit = signum - 1;
   const unsigned long *local_set = (const unsigned long *)set;
@@ -93,6 +98,8 @@
   return bsd_signal(s, f);
 }
 
+#endif /* __ANDROID_API__ < 21 */
+
 __END_DECLS
 
 #endif /* _ANDROID_LEGACY_SIGNAL_INLINES_H_ */
diff --git a/libc/include/android/legacy_stdlib_inlines.h b/libc/include/android/legacy_stdlib_inlines.h
index 58a2a9e..93554e5 100644
--- a/libc/include/android/legacy_stdlib_inlines.h
+++ b/libc/include/android/legacy_stdlib_inlines.h
@@ -29,8 +29,11 @@
 #ifndef _ANDROID_LEGACY_STDLIB_INLINES_H_
 #define _ANDROID_LEGACY_STDLIB_INLINES_H_
 
+#include <stdlib.h>
 #include <sys/cdefs.h>
 
+#if __ANDROID_API__ < 21
+
 __BEGIN_DECLS
 
 static __inline float strtof(const char *nptr, char **endptr) {
@@ -61,4 +64,5 @@
 
 __END_DECLS
 
+#endif
 #endif /* _ANDROID_LEGACY_STDLIB_INLINES_H_ */
diff --git a/libc/include/android/legacy_sys_atomics_inlines.h b/libc/include/android/legacy_sys_atomics_inlines.h
deleted file mode 100644
index 85cbade..0000000
--- a/libc/include/android/legacy_sys_atomics_inlines.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-#ifndef _ANDROID_LEGACY_SYS_ATOMICS_INLINES_H_
-#define _ANDROID_LEGACY_SYS_ATOMICS_INLINES_H_
-
-#include <sys/cdefs.h>
-
-__BEGIN_DECLS
-
-/* Note: atomic operations that were exported by the C library didn't
- *       provide any memory barriers, which created potential issues on
- *       multi-core devices. We now define them as inlined calls to
- *       GCC sync builtins, which always provide a full barrier.
- *
- *       NOTE: The C library still exports atomic functions by the same
- *              name to ensure ABI stability for existing NDK machine code.
- *
- *       If you are an NDK developer, we encourage you to rebuild your
- *       unmodified sources against this header as soon as possible.
- */
-#define __ATOMIC_INLINE__ static __inline __attribute__((always_inline))
-
-__ATOMIC_INLINE__ int __atomic_cmpxchg(int old, int _new, volatile int *ptr) {
-  /* We must return 0 on success */
-  return __sync_val_compare_and_swap(ptr, old, _new) != old;
-}
-
-__ATOMIC_INLINE__ int __atomic_swap(int _new, volatile int *ptr) {
-  int prev;
-  do {
-    prev = *ptr;
-  } while (__sync_val_compare_and_swap(ptr, prev, _new) != prev);
-  return prev;
-}
-
-__ATOMIC_INLINE__ int __atomic_dec(volatile int *ptr) {
-  return __sync_fetch_and_sub(ptr, 1);
-}
-
-__ATOMIC_INLINE__ int __atomic_inc(volatile int *ptr) {
-  return __sync_fetch_and_add(ptr, 1);
-}
-
-__END_DECLS
-
-#endif /* _ANDROID_LEGACY_SYS_ATOMICS_INLINES_H_ */
diff --git a/libc/include/android/legacy_sys_stat_inlines.h b/libc/include/android/legacy_sys_stat_inlines.h
index f6d3c0f..c08edfa 100644
--- a/libc/include/android/legacy_sys_stat_inlines.h
+++ b/libc/include/android/legacy_sys_stat_inlines.h
@@ -30,6 +30,9 @@
 #define _ANDROID_LEGACY_SYS_STAT_INLINES_H_
 
 #include <sys/cdefs.h>
+#include <sys/stat.h>
+
+#if __ANDROID_API__ < 21
 
 __BEGIN_DECLS
 
@@ -39,4 +42,5 @@
 
 __END_DECLS
 
+#endif
 #endif /* _ANDROID_LEGACY_SYS_STAT_INLINES_H_ */
diff --git a/libc/include/android/legacy_termios_inlines.h b/libc/include/android/legacy_termios_inlines.h
index fb61f27..41ea955 100644
--- a/libc/include/android/legacy_termios_inlines.h
+++ b/libc/include/android/legacy_termios_inlines.h
@@ -34,6 +34,8 @@
 #include <sys/ioctl.h>
 #include <sys/types.h>
 
+#if __ANDROID_API__ < 21
+
 __BEGIN_DECLS
 
 static __inline int tcgetattr(int fd, struct termios *s) {
@@ -90,4 +92,5 @@
 
 __END_DECLS
 
+#endif
 #endif /* _ANDROID_LEGACY_TERMIOS_INLINES_H_ */
diff --git a/libc/include/android/set_abort_message.h b/libc/include/android/set_abort_message.h
index 4b3d82b..18881a3 100644
--- a/libc/include/android/set_abort_message.h
+++ b/libc/include/android/set_abort_message.h
@@ -33,8 +33,8 @@
 
 __BEGIN_DECLS
 
-void android_set_abort_message(const char* msg);
+void android_set_abort_message(const char* msg) __INTRODUCED_IN(21);
 
 __END_DECLS
 
-#endif // _SET_ABORT_MESSAGE_H
+#endif
diff --git a/libc/include/ar.h b/libc/include/ar.h
index 835290b..413f767 100644
--- a/libc/include/ar.h
+++ b/libc/include/ar.h
@@ -43,6 +43,8 @@
 #ifndef _AR_H_
 #define	_AR_H_
 
+#include <sys/cdefs.h>
+
 /* Pre-4BSD archives had these magic numbers in them. */
 #define	OARMAG1	0177555
 #define	OARMAG2	0177545
diff --git a/libc/include/arpa/inet.h b/libc/include/arpa/inet.h
index 86265bf..d137130 100644
--- a/libc/include/arpa/inet.h
+++ b/libc/include/arpa/inet.h
@@ -29,18 +29,19 @@
 #ifndef _ARPA_INET_H_
 #define _ARPA_INET_H_
 
-#include <stdint.h>
-#include <sys/types.h>
 #include <netinet/in.h>
+#include <stdint.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
 
 __BEGIN_DECLS
 
 in_addr_t inet_addr(const char*);
 int inet_aton(const char*, struct in_addr*);
-in_addr_t inet_lnaof(struct in_addr);
-struct in_addr inet_makeaddr(in_addr_t, in_addr_t);
-in_addr_t inet_netof(struct in_addr);
-in_addr_t inet_network(const char*);
+in_addr_t inet_lnaof(struct in_addr) __INTRODUCED_IN(21);
+struct in_addr inet_makeaddr(in_addr_t, in_addr_t) __INTRODUCED_IN(21);
+in_addr_t inet_netof(struct in_addr) __INTRODUCED_IN(21);
+in_addr_t inet_network(const char*) __INTRODUCED_IN(21);
 char* inet_ntoa(struct in_addr);
 const char* inet_ntop(int, const void*, char*, socklen_t);
 unsigned int inet_nsap_addr(const char*, unsigned char*, int);
diff --git a/libc/include/arpa/nameser.h b/libc/include/arpa/nameser.h
index 91561ce..9507f49 100644
--- a/libc/include/arpa/nameser.h
+++ b/libc/include/arpa/nameser.h
@@ -141,10 +141,6 @@
 };
 typedef struct ns_newmsg ns_newmsg;
 
-/* Private data structure - do not use from outside library. */
-struct _ns_flagdata {  int mask, shift;  };
-extern const struct _ns_flagdata _ns_flagdata[];
-
 /* Accessor macros - this is part of the public interface. */
 
 #define ns_msg_id(handle) ((handle)._id + 0)
@@ -518,6 +514,8 @@
 	(cp) += NS_INT32SZ; \
 } while (/*CONSTCOND*/0)
 
+__BEGIN_DECLS
+
 #if !defined(__LP64__)
 /* Annoyingly, LP32 shipped with __ names. */
 #define	ns_msg_getflag		__ns_msg_getflag
@@ -563,73 +561,66 @@
 #define	ns_subdomain		__ns_subdomain
 #define	ns_makecanon		__ns_makecanon
 #define	ns_samename		__ns_samename
-#endif
 
-__BEGIN_DECLS
-int		ns_msg_getflag(ns_msg, int) __LIBC_ABI_PUBLIC__;
-uint16_t	ns_get16(const u_char *) __LIBC_ABI_PUBLIC__;
-uint32_t	ns_get32(const u_char *) __LIBC_ABI_PUBLIC__;
-void		ns_put16(uint16_t, u_char *) __LIBC_ABI_PUBLIC__;
-void		ns_put32(uint32_t, u_char *) __LIBC_ABI_PUBLIC__;
-int		ns_initparse(const u_char *, int, ns_msg *) __LIBC_ABI_PUBLIC__;
-int		ns_skiprr(const u_char *, const u_char *, ns_sect, int) __LIBC_ABI_PUBLIC__;
-int		ns_parserr(ns_msg *, ns_sect, int, ns_rr *) __LIBC_ABI_PUBLIC__;
-int		ns_parserr2(ns_msg *, ns_sect, int, ns_rr2 *) __LIBC_HIDDEN__;
-int		ns_sprintrr(const ns_msg *, const ns_rr *,
-				 const char *, const char *, char *, size_t) __LIBC_ABI_PUBLIC__;
-int		ns_sprintrrf(const u_char *, size_t, const char *,
-				  ns_class, ns_type, u_long, const u_char *,
-				  size_t, const char *, const char *,
-				  char *, size_t) __LIBC_ABI_PUBLIC__;
-int		ns_format_ttl(u_long, char *, size_t) __LIBC_ABI_PUBLIC__;
-int		ns_parse_ttl(const char *, u_long *) __LIBC_ABI_PUBLIC__;
-uint32_t	ns_datetosecs(const char *cp, int *errp) __LIBC_ABI_PUBLIC__;
-int		ns_name_ntol(const u_char *, u_char *, size_t) __LIBC_ABI_PUBLIC__;
-int		ns_name_ntop(const u_char *, char *, size_t) __LIBC_ABI_PUBLIC__;
-int		ns_name_pton(const char *, u_char *, size_t) __LIBC_ABI_PUBLIC__;
-int		ns_name_pton2(const char *, u_char *, size_t, size_t *) __LIBC_HIDDEN__;
-int		ns_name_unpack(const u_char *, const u_char *,
-				    const u_char *, u_char *, size_t) __LIBC_ABI_PUBLIC__;
-int		ns_name_unpack2(const u_char *, const u_char *,
-				     const u_char *, u_char *, size_t,
-				     size_t *) __LIBC_HIDDEN__;
-int		ns_name_pack(const u_char *, u_char *, int,
-				  const u_char **, const u_char **) __LIBC_ABI_PUBLIC__;
-int		ns_name_uncompress(const u_char *, const u_char *,
-					const u_char *, char *, size_t) __LIBC_ABI_PUBLIC__;
-int		ns_name_compress(const char *, u_char *, size_t,
-				      const u_char **, const u_char **) __LIBC_ABI_PUBLIC__;
-int		ns_name_skip(const u_char **, const u_char *) __LIBC_ABI_PUBLIC__;
-void		ns_name_rollback(const u_char *, const u_char **,
-				      const u_char **) __LIBC_ABI_PUBLIC__;
-int		ns_sign(u_char *, int *, int, int, void *,
-			     const u_char *, int, u_char *, int *, time_t) __LIBC_ABI_PUBLIC__;
-int		ns_sign2(u_char *, int *, int, int, void *,
-			      const u_char *, int, u_char *, int *, time_t,
-			      u_char **, u_char **) __LIBC_ABI_PUBLIC__;
-ssize_t		ns_name_length(ns_nname_ct, size_t) __LIBC_HIDDEN__;
-int		ns_name_eq(ns_nname_ct, size_t, ns_nname_ct, size_t) __LIBC_HIDDEN__;
-int		ns_name_owned(ns_namemap_ct, int, ns_namemap_ct, int) __LIBC_HIDDEN__;
-int		ns_name_map(ns_nname_ct, size_t, ns_namemap_t, int) __LIBC_HIDDEN__;
-int		ns_name_labels(ns_nname_ct, size_t) __LIBC_HIDDEN__;
-int		ns_sign_tcp(u_char *, int *, int, int,
-				 ns_tcp_tsig_state *, int) __LIBC_ABI_PUBLIC__;
-int		ns_sign_tcp2(u_char *, int *, int, int,
-				  ns_tcp_tsig_state *, int,
-				  u_char **, u_char **) __LIBC_ABI_PUBLIC__;
-int		ns_sign_tcp_init(void *, const u_char *, int,
-					ns_tcp_tsig_state *) __LIBC_ABI_PUBLIC__;
-u_char		*ns_find_tsig(u_char *, u_char *) __LIBC_ABI_PUBLIC__;
-int		ns_verify(u_char *, int *, void *,
-			       const u_char *, int, u_char *, int *,
-			       time_t *, int) __LIBC_ABI_PUBLIC__;
-int		ns_verify_tcp(u_char *, int *, ns_tcp_tsig_state *, int);
-int		ns_verify_tcp_init(void *, const u_char *, int,
-					ns_tcp_tsig_state *) __LIBC_ABI_PUBLIC__;
-int		ns_samedomain(const char *, const char *) __LIBC_ABI_PUBLIC__;
-int		ns_subdomain(const char *, const char *) __LIBC_ABI_PUBLIC__;
-int		ns_makecanon(const char *, char *, size_t) __LIBC_ABI_PUBLIC__;
-int		ns_samename(const char *, const char *) __LIBC_ABI_PUBLIC__;
+int ns_msg_getflag(ns_msg, int);
+uint16_t ns_get16(const u_char*);
+uint32_t ns_get32(const u_char*);
+void ns_put16(uint16_t, u_char*);
+void ns_put32(uint32_t, u_char*);
+int ns_initparse(const u_char*, int, ns_msg*);
+int ns_skiprr(const u_char*, const u_char*, ns_sect, int);
+int ns_parserr(ns_msg*, ns_sect, int, ns_rr*);
+int ns_sprintrr(const ns_msg*, const ns_rr*, const char*, const char*, char*, size_t);
+int ns_sprintrrf(const u_char*, size_t, const char*, ns_class, ns_type, u_long, const u_char*,
+                 size_t, const char*, const char*, char*, size_t);
+int ns_format_ttl(u_long, char*, size_t);
+int ns_name_ntol(const u_char*, u_char*, size_t);
+int ns_name_ntop(const u_char*, char*, size_t);
+int ns_name_pton(const char*, u_char*, size_t);
+int ns_name_unpack(const u_char*, const u_char*, const u_char*, u_char*, size_t);
+int ns_name_pack(const u_char*, u_char*, int, const u_char**, const u_char**);
+int ns_name_uncompress(const u_char*, const u_char*, const u_char*, char*, size_t);
+int ns_name_compress(const char*, u_char*, size_t, const u_char**, const u_char**);
+int ns_name_skip(const u_char**, const u_char*);
+void ns_name_rollback(const u_char*, const u_char**, const u_char**);
+
+int ns_makecanon(const char*, char*, size_t);
+int ns_samename(const char*, const char*);
+
+#else
+/* The names of these symbols were accidentally prefixed with __ in L. */
+/* The duplication here is intentional to avoid declaring different symbols with the same
+ * declaration. */
+int ns_msg_getflag(ns_msg, int) __INTRODUCED_IN_64(23);
+uint16_t ns_get16(const u_char*) __INTRODUCED_IN_64(23);
+uint32_t ns_get32(const u_char*) __INTRODUCED_IN_64(23);
+void ns_put16(uint16_t, u_char*) __INTRODUCED_IN_64(23);
+void ns_put32(uint32_t, u_char*) __INTRODUCED_IN_64(23);
+int ns_initparse(const u_char*, int, ns_msg*) __INTRODUCED_IN_64(23);
+int ns_skiprr(const u_char*, const u_char*, ns_sect, int) __INTRODUCED_IN_64(23);
+int ns_parserr(ns_msg*, ns_sect, int, ns_rr*) __INTRODUCED_IN_64(23);
+int ns_sprintrr(const ns_msg*, const ns_rr*, const char*, const char*, char*, size_t)
+  __INTRODUCED_IN_64(23);
+int ns_sprintrrf(const u_char*, size_t, const char*, ns_class, ns_type, u_long, const u_char*,
+                 size_t, const char*, const char*, char*, size_t) __INTRODUCED_IN_64(23);
+int ns_format_ttl(u_long, char*, size_t) __INTRODUCED_IN_64(23);
+int ns_name_ntol(const u_char*, u_char*, size_t) __INTRODUCED_IN_64(23);
+int ns_name_ntop(const u_char*, char*, size_t) __INTRODUCED_IN_64(23);
+int ns_name_pton(const char*, u_char*, size_t) __INTRODUCED_IN_64(23);
+int ns_name_unpack(const u_char*, const u_char*, const u_char*, u_char*, size_t)
+  __INTRODUCED_IN_64(23);
+int ns_name_pack(const u_char*, u_char*, int, const u_char**, const u_char**) __INTRODUCED_IN_64(23);
+int ns_name_uncompress(const u_char*, const u_char*, const u_char*, char*, size_t)
+  __INTRODUCED_IN_64(23);
+int ns_name_compress(const char*, u_char*, size_t, const u_char**, const u_char**)
+  __INTRODUCED_IN_64(23);
+int ns_name_skip(const u_char**, const u_char*) __INTRODUCED_IN_64(23);
+void ns_name_rollback(const u_char*, const u_char**, const u_char**) __INTRODUCED_IN_64(23);
+
+int ns_makecanon(const char*, char*, size_t) __INTRODUCED_IN_64(23);
+int ns_samename(const char*, const char*) __INTRODUCED_IN_64(23);
+#endif /* !defined(__LP64__) */
+
 __END_DECLS
 
 #ifdef BIND_4_COMPAT
diff --git a/libc/include/arpa/nameser_compat.h b/libc/include/arpa/nameser_compat.h
index 539864e..6868876 100644
--- a/libc/include/arpa/nameser_compat.h
+++ b/libc/include/arpa/nameser_compat.h
@@ -40,9 +40,10 @@
 #ifndef _ARPA_NAMESER_COMPAT_
 #define	_ARPA_NAMESER_COMPAT_
 
-#define	__BIND		19950621	/* (DEAD) interface version stamp. */
-
 #include <endian.h>
+#include <sys/cdefs.h>
+
+#define	__BIND		19950621	/* (DEAD) interface version stamp. */
 
 /*
  * Structure for query header.  The order of the fields is machine- and
diff --git a/libc/include/arpa/telnet.h b/libc/include/arpa/telnet.h
index d318e08..594dc7a 100644
--- a/libc/include/arpa/telnet.h
+++ b/libc/include/arpa/telnet.h
@@ -32,6 +32,8 @@
 #ifndef _ARPA_TELNET_H
 #define	_ARPA_TELNET_H 1
 
+#include <sys/cdefs.h>
+
 /*
  * Definitions for the TELNET protocol.
  */
@@ -64,8 +66,6 @@
 	"SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC",
 	"EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC", 0,
 };
-#else
-extern char *telcmds[];
 #endif
 
 #define	TELCMD_FIRST	xEOF
@@ -206,8 +206,6 @@
 const char *slc_names[] = {
 	SLC_NAMELIST
 };
-#else
-extern char *slc_names[];
 #define	SLC_NAMES SLC_NAMELIST
 #endif
 
@@ -266,8 +264,6 @@
 const char *authtype_names[] = {
 	"NULL", "KERBEROS_V4", "KERBEROS_V5", "SPX", "MINK", 0,
 };
-#else
-extern char *authtype_names[];
 #endif
 
 #define	AUTHTYPE_NAME_OK(x)	((unsigned int)(x) < AUTHTYPE_CNT)
@@ -301,9 +297,6 @@
 const char *enctype_names[] = {
 	"ANY", "DES_CFB64",  "DES_OFB64",  0,
 };
-#else
-extern const char *encrypt_names[];
-extern const char *enctype_names[];
 #endif
 
 
diff --git a/libc/include/assert.h b/libc/include/assert.h
index 361a5ff..8c456ef 100644
--- a/libc/include/assert.h
+++ b/libc/include/assert.h
@@ -1,6 +1,3 @@
-/*	$OpenBSD: assert.h,v 1.12 2006/01/31 10:53:51 hshoexer Exp $	*/
-/*	$NetBSD: assert.h,v 1.6 1994/10/26 00:55:44 cgd Exp $	*/
-
 /*-
  * Copyright (c) 1992, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -33,33 +30,36 @@
  * 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.
- *
- *	@(#)assert.h	8.2 (Berkeley) 1/21/94
  */
 
 /*
- * Unlike other ANSI header files, <assert.h> may usefully be included
- * multiple times, with and without NDEBUG defined.
+ * There's no include guard in this file because <assert.h> may usefully be
+ * included multiple times, with and without NDEBUG defined.
  */
 
 #include <sys/cdefs.h>
 
 #undef assert
-#undef _assert
+#undef __assert_no_op
+
+#define __assert_no_op __BIONIC_CAST(static_cast, void, 0)
 
 #ifdef NDEBUG
-# define	assert(e)	((void)0)
-# define	_assert(e)	((void)0)
+# define assert(e) __assert_no_op
 #else
-# define	_assert(e)	assert(e)
-# if __ISO_C_VISIBLE >= 1999
-#  define	assert(e)	((e) ? (void)0 : __assert2(__FILE__, __LINE__, __func__, #e))
+# if defined(__cplusplus) || __STDC_VERSION__ >= 199901L
+#  define assert(e) ((e) ? __assert_no_op : __assert2(__FILE__, __LINE__, __PRETTY_FUNCTION__, #e))
 # else
-#  define	assert(e)	((e) ? (void)0 : __assert(__FILE__, __LINE__, #e))
+#  define assert(e) ((e) ? __assert_no_op : __assert(__FILE__, __LINE__, #e))
 # endif
 #endif
 
+#if !defined(__cplusplus) && __STDC_VERSION__ >= 201112L
+# undef static_assert
+# define static_assert _Static_assert
+#endif
+
 __BEGIN_DECLS
-__dead void __assert(const char *, int, const char *) __noreturn;
-__dead void __assert2(const char *, int, const char *, const char *) __noreturn;
+void __assert(const char*, int, const char*) __noreturn;
+void __assert2(const char*, int, const char*, const char*) __noreturn;
 __END_DECLS
diff --git a/libc/include/sys/utime.h b/libc/include/bits/fcntl.h
similarity index 87%
copy from libc/include/sys/utime.h
copy to libc/include/bits/fcntl.h
index 9f8810e..604d35a 100644
--- a/libc/include/sys/utime.h
+++ b/libc/include/bits/fcntl.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) 2016 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -25,9 +25,16 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-#ifndef _SYS_UTIME_H_
-#define _SYS_UTIME_H_
 
-#include <linux/utime.h>
+#ifndef _BITS_FCNTL_H_
+#define _BITS_FCNTL_H_
 
-#endif /* _SYS_UTIME_H_ */
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
+int fcntl(int, int, ...);
+
+__END_DECLS
+
+#endif
diff --git a/libc/include/machine/endian.h b/libc/include/bits/getopt.h
similarity index 81%
rename from libc/include/machine/endian.h
rename to libc/include/bits/getopt.h
index ac89519..7153d48 100644
--- a/libc/include/machine/endian.h
+++ b/libc/include/bits/getopt.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 The Android Open Source Project
+ * Copyright (C) 2016 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,10 +26,18 @@
  * SUCH DAMAGE.
  */
 
-#ifndef _MACHINE_ENDIAN_H_
-#define _MACHINE_ENDIAN_H_
+#ifndef _BITS_GETOPT_H_
+#define _BITS_GETOPT_H_
 
-/* This file is for BSD source compatibility only. Use <endian.h> or <sys/endian.h> instead. */
-#include <sys/endian.h>
+#include <sys/cdefs.h>
 
-#endif /* _MACHINE_ENDIAN_H_ */
+__BEGIN_DECLS
+
+int	 getopt(int, char * const [], const char *);
+
+extern char *optarg;			/* getopt(3) external variables */
+extern int optind, opterr, optopt;
+
+__END_DECLS
+
+#endif
diff --git a/libc/include/bits/glibc-syscalls.h b/libc/include/bits/glibc-syscalls.h
new file mode 100644
index 0000000..48e20a2
--- /dev/null
+++ b/libc/include/bits/glibc-syscalls.h
@@ -0,0 +1,1225 @@
+/* Generated by gensyscalls.py. Do not edit. */
+#ifndef _BIONIC_BITS_GLIBC_SYSCALLS_H_
+#define _BIONIC_BITS_GLIBC_SYSCALLS_H_
+#if defined(__NR_accept)
+  #define SYS_accept __NR_accept
+#endif
+#if defined(__NR_accept4)
+  #define SYS_accept4 __NR_accept4
+#endif
+#if defined(__NR_access)
+  #define SYS_access __NR_access
+#endif
+#if defined(__NR_acct)
+  #define SYS_acct __NR_acct
+#endif
+#if defined(__NR_add_key)
+  #define SYS_add_key __NR_add_key
+#endif
+#if defined(__NR_adjtimex)
+  #define SYS_adjtimex __NR_adjtimex
+#endif
+#if defined(__NR_afs_syscall)
+  #define SYS_afs_syscall __NR_afs_syscall
+#endif
+#if defined(__NR_alarm)
+  #define SYS_alarm __NR_alarm
+#endif
+#if defined(__NR_arch_prctl)
+  #define SYS_arch_prctl __NR_arch_prctl
+#endif
+#if defined(__NR_arch_specific_syscall)
+  #define SYS_arch_specific_syscall __NR_arch_specific_syscall
+#endif
+#if defined(__NR_arm_fadvise64_64)
+  #define SYS_arm_fadvise64_64 __NR_arm_fadvise64_64
+#endif
+#if defined(__NR_arm_sync_file_range)
+  #define SYS_arm_sync_file_range __NR_arm_sync_file_range
+#endif
+#if defined(__NR_bdflush)
+  #define SYS_bdflush __NR_bdflush
+#endif
+#if defined(__NR_bind)
+  #define SYS_bind __NR_bind
+#endif
+#if defined(__NR_bpf)
+  #define SYS_bpf __NR_bpf
+#endif
+#if defined(__NR_break)
+  #define SYS_break __NR_break
+#endif
+#if defined(__NR_brk)
+  #define SYS_brk __NR_brk
+#endif
+#if defined(__NR_cachectl)
+  #define SYS_cachectl __NR_cachectl
+#endif
+#if defined(__NR_cacheflush)
+  #define SYS_cacheflush __NR_cacheflush
+#endif
+#if defined(__NR_capget)
+  #define SYS_capget __NR_capget
+#endif
+#if defined(__NR_capset)
+  #define SYS_capset __NR_capset
+#endif
+#if defined(__NR_chdir)
+  #define SYS_chdir __NR_chdir
+#endif
+#if defined(__NR_chmod)
+  #define SYS_chmod __NR_chmod
+#endif
+#if defined(__NR_chown)
+  #define SYS_chown __NR_chown
+#endif
+#if defined(__NR_chown32)
+  #define SYS_chown32 __NR_chown32
+#endif
+#if defined(__NR_chroot)
+  #define SYS_chroot __NR_chroot
+#endif
+#if defined(__NR_clock_adjtime)
+  #define SYS_clock_adjtime __NR_clock_adjtime
+#endif
+#if defined(__NR_clock_getres)
+  #define SYS_clock_getres __NR_clock_getres
+#endif
+#if defined(__NR_clock_gettime)
+  #define SYS_clock_gettime __NR_clock_gettime
+#endif
+#if defined(__NR_clock_nanosleep)
+  #define SYS_clock_nanosleep __NR_clock_nanosleep
+#endif
+#if defined(__NR_clock_settime)
+  #define SYS_clock_settime __NR_clock_settime
+#endif
+#if defined(__NR_clone)
+  #define SYS_clone __NR_clone
+#endif
+#if defined(__NR_close)
+  #define SYS_close __NR_close
+#endif
+#if defined(__NR_connect)
+  #define SYS_connect __NR_connect
+#endif
+#if defined(__NR_creat)
+  #define SYS_creat __NR_creat
+#endif
+#if defined(__NR_create_module)
+  #define SYS_create_module __NR_create_module
+#endif
+#if defined(__NR_delete_module)
+  #define SYS_delete_module __NR_delete_module
+#endif
+#if defined(__NR_dup)
+  #define SYS_dup __NR_dup
+#endif
+#if defined(__NR_dup2)
+  #define SYS_dup2 __NR_dup2
+#endif
+#if defined(__NR_dup3)
+  #define SYS_dup3 __NR_dup3
+#endif
+#if defined(__NR_epoll_create)
+  #define SYS_epoll_create __NR_epoll_create
+#endif
+#if defined(__NR_epoll_create1)
+  #define SYS_epoll_create1 __NR_epoll_create1
+#endif
+#if defined(__NR_epoll_ctl)
+  #define SYS_epoll_ctl __NR_epoll_ctl
+#endif
+#if defined(__NR_epoll_ctl_old)
+  #define SYS_epoll_ctl_old __NR_epoll_ctl_old
+#endif
+#if defined(__NR_epoll_pwait)
+  #define SYS_epoll_pwait __NR_epoll_pwait
+#endif
+#if defined(__NR_epoll_wait)
+  #define SYS_epoll_wait __NR_epoll_wait
+#endif
+#if defined(__NR_epoll_wait_old)
+  #define SYS_epoll_wait_old __NR_epoll_wait_old
+#endif
+#if defined(__NR_eventfd)
+  #define SYS_eventfd __NR_eventfd
+#endif
+#if defined(__NR_eventfd2)
+  #define SYS_eventfd2 __NR_eventfd2
+#endif
+#if defined(__NR_execve)
+  #define SYS_execve __NR_execve
+#endif
+#if defined(__NR_execveat)
+  #define SYS_execveat __NR_execveat
+#endif
+#if defined(__NR_exit)
+  #define SYS_exit __NR_exit
+#endif
+#if defined(__NR_exit_group)
+  #define SYS_exit_group __NR_exit_group
+#endif
+#if defined(__NR_faccessat)
+  #define SYS_faccessat __NR_faccessat
+#endif
+#if defined(__NR_fadvise64)
+  #define SYS_fadvise64 __NR_fadvise64
+#endif
+#if defined(__NR_fadvise64_64)
+  #define SYS_fadvise64_64 __NR_fadvise64_64
+#endif
+#if defined(__NR_fallocate)
+  #define SYS_fallocate __NR_fallocate
+#endif
+#if defined(__NR_fanotify_init)
+  #define SYS_fanotify_init __NR_fanotify_init
+#endif
+#if defined(__NR_fanotify_mark)
+  #define SYS_fanotify_mark __NR_fanotify_mark
+#endif
+#if defined(__NR_fchdir)
+  #define SYS_fchdir __NR_fchdir
+#endif
+#if defined(__NR_fchmod)
+  #define SYS_fchmod __NR_fchmod
+#endif
+#if defined(__NR_fchmodat)
+  #define SYS_fchmodat __NR_fchmodat
+#endif
+#if defined(__NR_fchown)
+  #define SYS_fchown __NR_fchown
+#endif
+#if defined(__NR_fchown32)
+  #define SYS_fchown32 __NR_fchown32
+#endif
+#if defined(__NR_fchownat)
+  #define SYS_fchownat __NR_fchownat
+#endif
+#if defined(__NR_fcntl)
+  #define SYS_fcntl __NR_fcntl
+#endif
+#if defined(__NR_fcntl64)
+  #define SYS_fcntl64 __NR_fcntl64
+#endif
+#if defined(__NR_fdatasync)
+  #define SYS_fdatasync __NR_fdatasync
+#endif
+#if defined(__NR_fgetxattr)
+  #define SYS_fgetxattr __NR_fgetxattr
+#endif
+#if defined(__NR_finit_module)
+  #define SYS_finit_module __NR_finit_module
+#endif
+#if defined(__NR_flistxattr)
+  #define SYS_flistxattr __NR_flistxattr
+#endif
+#if defined(__NR_flock)
+  #define SYS_flock __NR_flock
+#endif
+#if defined(__NR_fork)
+  #define SYS_fork __NR_fork
+#endif
+#if defined(__NR_fremovexattr)
+  #define SYS_fremovexattr __NR_fremovexattr
+#endif
+#if defined(__NR_fsetxattr)
+  #define SYS_fsetxattr __NR_fsetxattr
+#endif
+#if defined(__NR_fstat)
+  #define SYS_fstat __NR_fstat
+#endif
+#if defined(__NR_fstat64)
+  #define SYS_fstat64 __NR_fstat64
+#endif
+#if defined(__NR_fstatat64)
+  #define SYS_fstatat64 __NR_fstatat64
+#endif
+#if defined(__NR_fstatfs)
+  #define SYS_fstatfs __NR_fstatfs
+#endif
+#if defined(__NR_fstatfs64)
+  #define SYS_fstatfs64 __NR_fstatfs64
+#endif
+#if defined(__NR_fsync)
+  #define SYS_fsync __NR_fsync
+#endif
+#if defined(__NR_ftime)
+  #define SYS_ftime __NR_ftime
+#endif
+#if defined(__NR_ftruncate)
+  #define SYS_ftruncate __NR_ftruncate
+#endif
+#if defined(__NR_ftruncate64)
+  #define SYS_ftruncate64 __NR_ftruncate64
+#endif
+#if defined(__NR_futex)
+  #define SYS_futex __NR_futex
+#endif
+#if defined(__NR_futimesat)
+  #define SYS_futimesat __NR_futimesat
+#endif
+#if defined(__NR_get_kernel_syms)
+  #define SYS_get_kernel_syms __NR_get_kernel_syms
+#endif
+#if defined(__NR_get_mempolicy)
+  #define SYS_get_mempolicy __NR_get_mempolicy
+#endif
+#if defined(__NR_get_robust_list)
+  #define SYS_get_robust_list __NR_get_robust_list
+#endif
+#if defined(__NR_get_thread_area)
+  #define SYS_get_thread_area __NR_get_thread_area
+#endif
+#if defined(__NR_getcpu)
+  #define SYS_getcpu __NR_getcpu
+#endif
+#if defined(__NR_getcwd)
+  #define SYS_getcwd __NR_getcwd
+#endif
+#if defined(__NR_getdents)
+  #define SYS_getdents __NR_getdents
+#endif
+#if defined(__NR_getdents64)
+  #define SYS_getdents64 __NR_getdents64
+#endif
+#if defined(__NR_getegid)
+  #define SYS_getegid __NR_getegid
+#endif
+#if defined(__NR_getegid32)
+  #define SYS_getegid32 __NR_getegid32
+#endif
+#if defined(__NR_geteuid)
+  #define SYS_geteuid __NR_geteuid
+#endif
+#if defined(__NR_geteuid32)
+  #define SYS_geteuid32 __NR_geteuid32
+#endif
+#if defined(__NR_getgid)
+  #define SYS_getgid __NR_getgid
+#endif
+#if defined(__NR_getgid32)
+  #define SYS_getgid32 __NR_getgid32
+#endif
+#if defined(__NR_getgroups)
+  #define SYS_getgroups __NR_getgroups
+#endif
+#if defined(__NR_getgroups32)
+  #define SYS_getgroups32 __NR_getgroups32
+#endif
+#if defined(__NR_getitimer)
+  #define SYS_getitimer __NR_getitimer
+#endif
+#if defined(__NR_getpeername)
+  #define SYS_getpeername __NR_getpeername
+#endif
+#if defined(__NR_getpgid)
+  #define SYS_getpgid __NR_getpgid
+#endif
+#if defined(__NR_getpgrp)
+  #define SYS_getpgrp __NR_getpgrp
+#endif
+#if defined(__NR_getpid)
+  #define SYS_getpid __NR_getpid
+#endif
+#if defined(__NR_getpmsg)
+  #define SYS_getpmsg __NR_getpmsg
+#endif
+#if defined(__NR_getppid)
+  #define SYS_getppid __NR_getppid
+#endif
+#if defined(__NR_getpriority)
+  #define SYS_getpriority __NR_getpriority
+#endif
+#if defined(__NR_getrandom)
+  #define SYS_getrandom __NR_getrandom
+#endif
+#if defined(__NR_getresgid)
+  #define SYS_getresgid __NR_getresgid
+#endif
+#if defined(__NR_getresgid32)
+  #define SYS_getresgid32 __NR_getresgid32
+#endif
+#if defined(__NR_getresuid)
+  #define SYS_getresuid __NR_getresuid
+#endif
+#if defined(__NR_getresuid32)
+  #define SYS_getresuid32 __NR_getresuid32
+#endif
+#if defined(__NR_getrlimit)
+  #define SYS_getrlimit __NR_getrlimit
+#endif
+#if defined(__NR_getrusage)
+  #define SYS_getrusage __NR_getrusage
+#endif
+#if defined(__NR_getsid)
+  #define SYS_getsid __NR_getsid
+#endif
+#if defined(__NR_getsockname)
+  #define SYS_getsockname __NR_getsockname
+#endif
+#if defined(__NR_getsockopt)
+  #define SYS_getsockopt __NR_getsockopt
+#endif
+#if defined(__NR_gettid)
+  #define SYS_gettid __NR_gettid
+#endif
+#if defined(__NR_gettimeofday)
+  #define SYS_gettimeofday __NR_gettimeofday
+#endif
+#if defined(__NR_getuid)
+  #define SYS_getuid __NR_getuid
+#endif
+#if defined(__NR_getuid32)
+  #define SYS_getuid32 __NR_getuid32
+#endif
+#if defined(__NR_getxattr)
+  #define SYS_getxattr __NR_getxattr
+#endif
+#if defined(__NR_gtty)
+  #define SYS_gtty __NR_gtty
+#endif
+#if defined(__NR_idle)
+  #define SYS_idle __NR_idle
+#endif
+#if defined(__NR_init_module)
+  #define SYS_init_module __NR_init_module
+#endif
+#if defined(__NR_inotify_add_watch)
+  #define SYS_inotify_add_watch __NR_inotify_add_watch
+#endif
+#if defined(__NR_inotify_init)
+  #define SYS_inotify_init __NR_inotify_init
+#endif
+#if defined(__NR_inotify_init1)
+  #define SYS_inotify_init1 __NR_inotify_init1
+#endif
+#if defined(__NR_inotify_rm_watch)
+  #define SYS_inotify_rm_watch __NR_inotify_rm_watch
+#endif
+#if defined(__NR_io_cancel)
+  #define SYS_io_cancel __NR_io_cancel
+#endif
+#if defined(__NR_io_destroy)
+  #define SYS_io_destroy __NR_io_destroy
+#endif
+#if defined(__NR_io_getevents)
+  #define SYS_io_getevents __NR_io_getevents
+#endif
+#if defined(__NR_io_setup)
+  #define SYS_io_setup __NR_io_setup
+#endif
+#if defined(__NR_io_submit)
+  #define SYS_io_submit __NR_io_submit
+#endif
+#if defined(__NR_ioctl)
+  #define SYS_ioctl __NR_ioctl
+#endif
+#if defined(__NR_ioperm)
+  #define SYS_ioperm __NR_ioperm
+#endif
+#if defined(__NR_iopl)
+  #define SYS_iopl __NR_iopl
+#endif
+#if defined(__NR_ioprio_get)
+  #define SYS_ioprio_get __NR_ioprio_get
+#endif
+#if defined(__NR_ioprio_set)
+  #define SYS_ioprio_set __NR_ioprio_set
+#endif
+#if defined(__NR_ipc)
+  #define SYS_ipc __NR_ipc
+#endif
+#if defined(__NR_kcmp)
+  #define SYS_kcmp __NR_kcmp
+#endif
+#if defined(__NR_kexec_file_load)
+  #define SYS_kexec_file_load __NR_kexec_file_load
+#endif
+#if defined(__NR_kexec_load)
+  #define SYS_kexec_load __NR_kexec_load
+#endif
+#if defined(__NR_keyctl)
+  #define SYS_keyctl __NR_keyctl
+#endif
+#if defined(__NR_kill)
+  #define SYS_kill __NR_kill
+#endif
+#if defined(__NR_lchown)
+  #define SYS_lchown __NR_lchown
+#endif
+#if defined(__NR_lchown32)
+  #define SYS_lchown32 __NR_lchown32
+#endif
+#if defined(__NR_lgetxattr)
+  #define SYS_lgetxattr __NR_lgetxattr
+#endif
+#if defined(__NR_link)
+  #define SYS_link __NR_link
+#endif
+#if defined(__NR_linkat)
+  #define SYS_linkat __NR_linkat
+#endif
+#if defined(__NR_listen)
+  #define SYS_listen __NR_listen
+#endif
+#if defined(__NR_listxattr)
+  #define SYS_listxattr __NR_listxattr
+#endif
+#if defined(__NR_llistxattr)
+  #define SYS_llistxattr __NR_llistxattr
+#endif
+#if defined(__NR_llseek)
+  #define SYS_llseek __NR_llseek
+#endif
+#if defined(__NR_lock)
+  #define SYS_lock __NR_lock
+#endif
+#if defined(__NR_lookup_dcookie)
+  #define SYS_lookup_dcookie __NR_lookup_dcookie
+#endif
+#if defined(__NR_lremovexattr)
+  #define SYS_lremovexattr __NR_lremovexattr
+#endif
+#if defined(__NR_lseek)
+  #define SYS_lseek __NR_lseek
+#endif
+#if defined(__NR_lsetxattr)
+  #define SYS_lsetxattr __NR_lsetxattr
+#endif
+#if defined(__NR_lstat)
+  #define SYS_lstat __NR_lstat
+#endif
+#if defined(__NR_lstat64)
+  #define SYS_lstat64 __NR_lstat64
+#endif
+#if defined(__NR_madvise)
+  #define SYS_madvise __NR_madvise
+#endif
+#if defined(__NR_mbind)
+  #define SYS_mbind __NR_mbind
+#endif
+#if defined(__NR_membarrier)
+  #define SYS_membarrier __NR_membarrier
+#endif
+#if defined(__NR_memfd_create)
+  #define SYS_memfd_create __NR_memfd_create
+#endif
+#if defined(__NR_migrate_pages)
+  #define SYS_migrate_pages __NR_migrate_pages
+#endif
+#if defined(__NR_mincore)
+  #define SYS_mincore __NR_mincore
+#endif
+#if defined(__NR_mkdir)
+  #define SYS_mkdir __NR_mkdir
+#endif
+#if defined(__NR_mkdirat)
+  #define SYS_mkdirat __NR_mkdirat
+#endif
+#if defined(__NR_mknod)
+  #define SYS_mknod __NR_mknod
+#endif
+#if defined(__NR_mknodat)
+  #define SYS_mknodat __NR_mknodat
+#endif
+#if defined(__NR_mlock)
+  #define SYS_mlock __NR_mlock
+#endif
+#if defined(__NR_mlock2)
+  #define SYS_mlock2 __NR_mlock2
+#endif
+#if defined(__NR_mlockall)
+  #define SYS_mlockall __NR_mlockall
+#endif
+#if defined(__NR_mmap)
+  #define SYS_mmap __NR_mmap
+#endif
+#if defined(__NR_mmap2)
+  #define SYS_mmap2 __NR_mmap2
+#endif
+#if defined(__NR_modify_ldt)
+  #define SYS_modify_ldt __NR_modify_ldt
+#endif
+#if defined(__NR_mount)
+  #define SYS_mount __NR_mount
+#endif
+#if defined(__NR_move_pages)
+  #define SYS_move_pages __NR_move_pages
+#endif
+#if defined(__NR_mprotect)
+  #define SYS_mprotect __NR_mprotect
+#endif
+#if defined(__NR_mpx)
+  #define SYS_mpx __NR_mpx
+#endif
+#if defined(__NR_mq_getsetattr)
+  #define SYS_mq_getsetattr __NR_mq_getsetattr
+#endif
+#if defined(__NR_mq_notify)
+  #define SYS_mq_notify __NR_mq_notify
+#endif
+#if defined(__NR_mq_open)
+  #define SYS_mq_open __NR_mq_open
+#endif
+#if defined(__NR_mq_timedreceive)
+  #define SYS_mq_timedreceive __NR_mq_timedreceive
+#endif
+#if defined(__NR_mq_timedsend)
+  #define SYS_mq_timedsend __NR_mq_timedsend
+#endif
+#if defined(__NR_mq_unlink)
+  #define SYS_mq_unlink __NR_mq_unlink
+#endif
+#if defined(__NR_mremap)
+  #define SYS_mremap __NR_mremap
+#endif
+#if defined(__NR_msgctl)
+  #define SYS_msgctl __NR_msgctl
+#endif
+#if defined(__NR_msgget)
+  #define SYS_msgget __NR_msgget
+#endif
+#if defined(__NR_msgrcv)
+  #define SYS_msgrcv __NR_msgrcv
+#endif
+#if defined(__NR_msgsnd)
+  #define SYS_msgsnd __NR_msgsnd
+#endif
+#if defined(__NR_msync)
+  #define SYS_msync __NR_msync
+#endif
+#if defined(__NR_munlock)
+  #define SYS_munlock __NR_munlock
+#endif
+#if defined(__NR_munlockall)
+  #define SYS_munlockall __NR_munlockall
+#endif
+#if defined(__NR_munmap)
+  #define SYS_munmap __NR_munmap
+#endif
+#if defined(__NR_name_to_handle_at)
+  #define SYS_name_to_handle_at __NR_name_to_handle_at
+#endif
+#if defined(__NR_nanosleep)
+  #define SYS_nanosleep __NR_nanosleep
+#endif
+#if defined(__NR_newfstatat)
+  #define SYS_newfstatat __NR_newfstatat
+#endif
+#if defined(__NR_nfsservctl)
+  #define SYS_nfsservctl __NR_nfsservctl
+#endif
+#if defined(__NR_nice)
+  #define SYS_nice __NR_nice
+#endif
+#if defined(__NR_oldfstat)
+  #define SYS_oldfstat __NR_oldfstat
+#endif
+#if defined(__NR_oldlstat)
+  #define SYS_oldlstat __NR_oldlstat
+#endif
+#if defined(__NR_oldolduname)
+  #define SYS_oldolduname __NR_oldolduname
+#endif
+#if defined(__NR_oldstat)
+  #define SYS_oldstat __NR_oldstat
+#endif
+#if defined(__NR_olduname)
+  #define SYS_olduname __NR_olduname
+#endif
+#if defined(__NR_oldwait4)
+  #define SYS_oldwait4 __NR_oldwait4
+#endif
+#if defined(__NR_open)
+  #define SYS_open __NR_open
+#endif
+#if defined(__NR_open_by_handle_at)
+  #define SYS_open_by_handle_at __NR_open_by_handle_at
+#endif
+#if defined(__NR_openat)
+  #define SYS_openat __NR_openat
+#endif
+#if defined(__NR_pause)
+  #define SYS_pause __NR_pause
+#endif
+#if defined(__NR_pciconfig_iobase)
+  #define SYS_pciconfig_iobase __NR_pciconfig_iobase
+#endif
+#if defined(__NR_pciconfig_read)
+  #define SYS_pciconfig_read __NR_pciconfig_read
+#endif
+#if defined(__NR_pciconfig_write)
+  #define SYS_pciconfig_write __NR_pciconfig_write
+#endif
+#if defined(__NR_perf_event_open)
+  #define SYS_perf_event_open __NR_perf_event_open
+#endif
+#if defined(__NR_personality)
+  #define SYS_personality __NR_personality
+#endif
+#if defined(__NR_pipe)
+  #define SYS_pipe __NR_pipe
+#endif
+#if defined(__NR_pipe2)
+  #define SYS_pipe2 __NR_pipe2
+#endif
+#if defined(__NR_pivot_root)
+  #define SYS_pivot_root __NR_pivot_root
+#endif
+#if defined(__NR_poll)
+  #define SYS_poll __NR_poll
+#endif
+#if defined(__NR_ppoll)
+  #define SYS_ppoll __NR_ppoll
+#endif
+#if defined(__NR_prctl)
+  #define SYS_prctl __NR_prctl
+#endif
+#if defined(__NR_pread64)
+  #define SYS_pread64 __NR_pread64
+#endif
+#if defined(__NR_preadv)
+  #define SYS_preadv __NR_preadv
+#endif
+#if defined(__NR_prlimit64)
+  #define SYS_prlimit64 __NR_prlimit64
+#endif
+#if defined(__NR_process_vm_readv)
+  #define SYS_process_vm_readv __NR_process_vm_readv
+#endif
+#if defined(__NR_process_vm_writev)
+  #define SYS_process_vm_writev __NR_process_vm_writev
+#endif
+#if defined(__NR_prof)
+  #define SYS_prof __NR_prof
+#endif
+#if defined(__NR_profil)
+  #define SYS_profil __NR_profil
+#endif
+#if defined(__NR_pselect6)
+  #define SYS_pselect6 __NR_pselect6
+#endif
+#if defined(__NR_ptrace)
+  #define SYS_ptrace __NR_ptrace
+#endif
+#if defined(__NR_putpmsg)
+  #define SYS_putpmsg __NR_putpmsg
+#endif
+#if defined(__NR_pwrite64)
+  #define SYS_pwrite64 __NR_pwrite64
+#endif
+#if defined(__NR_pwritev)
+  #define SYS_pwritev __NR_pwritev
+#endif
+#if defined(__NR_query_module)
+  #define SYS_query_module __NR_query_module
+#endif
+#if defined(__NR_quotactl)
+  #define SYS_quotactl __NR_quotactl
+#endif
+#if defined(__NR_read)
+  #define SYS_read __NR_read
+#endif
+#if defined(__NR_readahead)
+  #define SYS_readahead __NR_readahead
+#endif
+#if defined(__NR_readdir)
+  #define SYS_readdir __NR_readdir
+#endif
+#if defined(__NR_readlink)
+  #define SYS_readlink __NR_readlink
+#endif
+#if defined(__NR_readlinkat)
+  #define SYS_readlinkat __NR_readlinkat
+#endif
+#if defined(__NR_readv)
+  #define SYS_readv __NR_readv
+#endif
+#if defined(__NR_reboot)
+  #define SYS_reboot __NR_reboot
+#endif
+#if defined(__NR_recv)
+  #define SYS_recv __NR_recv
+#endif
+#if defined(__NR_recvfrom)
+  #define SYS_recvfrom __NR_recvfrom
+#endif
+#if defined(__NR_recvmmsg)
+  #define SYS_recvmmsg __NR_recvmmsg
+#endif
+#if defined(__NR_recvmsg)
+  #define SYS_recvmsg __NR_recvmsg
+#endif
+#if defined(__NR_remap_file_pages)
+  #define SYS_remap_file_pages __NR_remap_file_pages
+#endif
+#if defined(__NR_removexattr)
+  #define SYS_removexattr __NR_removexattr
+#endif
+#if defined(__NR_rename)
+  #define SYS_rename __NR_rename
+#endif
+#if defined(__NR_renameat)
+  #define SYS_renameat __NR_renameat
+#endif
+#if defined(__NR_renameat2)
+  #define SYS_renameat2 __NR_renameat2
+#endif
+#if defined(__NR_request_key)
+  #define SYS_request_key __NR_request_key
+#endif
+#if defined(__NR_restart_syscall)
+  #define SYS_restart_syscall __NR_restart_syscall
+#endif
+#if defined(__NR_rmdir)
+  #define SYS_rmdir __NR_rmdir
+#endif
+#if defined(__NR_rt_sigaction)
+  #define SYS_rt_sigaction __NR_rt_sigaction
+#endif
+#if defined(__NR_rt_sigpending)
+  #define SYS_rt_sigpending __NR_rt_sigpending
+#endif
+#if defined(__NR_rt_sigprocmask)
+  #define SYS_rt_sigprocmask __NR_rt_sigprocmask
+#endif
+#if defined(__NR_rt_sigqueueinfo)
+  #define SYS_rt_sigqueueinfo __NR_rt_sigqueueinfo
+#endif
+#if defined(__NR_rt_sigreturn)
+  #define SYS_rt_sigreturn __NR_rt_sigreturn
+#endif
+#if defined(__NR_rt_sigsuspend)
+  #define SYS_rt_sigsuspend __NR_rt_sigsuspend
+#endif
+#if defined(__NR_rt_sigtimedwait)
+  #define SYS_rt_sigtimedwait __NR_rt_sigtimedwait
+#endif
+#if defined(__NR_rt_tgsigqueueinfo)
+  #define SYS_rt_tgsigqueueinfo __NR_rt_tgsigqueueinfo
+#endif
+#if defined(__NR_sched_get_priority_max)
+  #define SYS_sched_get_priority_max __NR_sched_get_priority_max
+#endif
+#if defined(__NR_sched_get_priority_min)
+  #define SYS_sched_get_priority_min __NR_sched_get_priority_min
+#endif
+#if defined(__NR_sched_getaffinity)
+  #define SYS_sched_getaffinity __NR_sched_getaffinity
+#endif
+#if defined(__NR_sched_getattr)
+  #define SYS_sched_getattr __NR_sched_getattr
+#endif
+#if defined(__NR_sched_getparam)
+  #define SYS_sched_getparam __NR_sched_getparam
+#endif
+#if defined(__NR_sched_getscheduler)
+  #define SYS_sched_getscheduler __NR_sched_getscheduler
+#endif
+#if defined(__NR_sched_rr_get_interval)
+  #define SYS_sched_rr_get_interval __NR_sched_rr_get_interval
+#endif
+#if defined(__NR_sched_setaffinity)
+  #define SYS_sched_setaffinity __NR_sched_setaffinity
+#endif
+#if defined(__NR_sched_setattr)
+  #define SYS_sched_setattr __NR_sched_setattr
+#endif
+#if defined(__NR_sched_setparam)
+  #define SYS_sched_setparam __NR_sched_setparam
+#endif
+#if defined(__NR_sched_setscheduler)
+  #define SYS_sched_setscheduler __NR_sched_setscheduler
+#endif
+#if defined(__NR_sched_yield)
+  #define SYS_sched_yield __NR_sched_yield
+#endif
+#if defined(__NR_seccomp)
+  #define SYS_seccomp __NR_seccomp
+#endif
+#if defined(__NR_security)
+  #define SYS_security __NR_security
+#endif
+#if defined(__NR_select)
+  #define SYS_select __NR_select
+#endif
+#if defined(__NR_semctl)
+  #define SYS_semctl __NR_semctl
+#endif
+#if defined(__NR_semget)
+  #define SYS_semget __NR_semget
+#endif
+#if defined(__NR_semop)
+  #define SYS_semop __NR_semop
+#endif
+#if defined(__NR_semtimedop)
+  #define SYS_semtimedop __NR_semtimedop
+#endif
+#if defined(__NR_send)
+  #define SYS_send __NR_send
+#endif
+#if defined(__NR_sendfile)
+  #define SYS_sendfile __NR_sendfile
+#endif
+#if defined(__NR_sendfile64)
+  #define SYS_sendfile64 __NR_sendfile64
+#endif
+#if defined(__NR_sendmmsg)
+  #define SYS_sendmmsg __NR_sendmmsg
+#endif
+#if defined(__NR_sendmsg)
+  #define SYS_sendmsg __NR_sendmsg
+#endif
+#if defined(__NR_sendto)
+  #define SYS_sendto __NR_sendto
+#endif
+#if defined(__NR_set_mempolicy)
+  #define SYS_set_mempolicy __NR_set_mempolicy
+#endif
+#if defined(__NR_set_robust_list)
+  #define SYS_set_robust_list __NR_set_robust_list
+#endif
+#if defined(__NR_set_thread_area)
+  #define SYS_set_thread_area __NR_set_thread_area
+#endif
+#if defined(__NR_set_tid_address)
+  #define SYS_set_tid_address __NR_set_tid_address
+#endif
+#if defined(__NR_setdomainname)
+  #define SYS_setdomainname __NR_setdomainname
+#endif
+#if defined(__NR_setfsgid)
+  #define SYS_setfsgid __NR_setfsgid
+#endif
+#if defined(__NR_setfsgid32)
+  #define SYS_setfsgid32 __NR_setfsgid32
+#endif
+#if defined(__NR_setfsuid)
+  #define SYS_setfsuid __NR_setfsuid
+#endif
+#if defined(__NR_setfsuid32)
+  #define SYS_setfsuid32 __NR_setfsuid32
+#endif
+#if defined(__NR_setgid)
+  #define SYS_setgid __NR_setgid
+#endif
+#if defined(__NR_setgid32)
+  #define SYS_setgid32 __NR_setgid32
+#endif
+#if defined(__NR_setgroups)
+  #define SYS_setgroups __NR_setgroups
+#endif
+#if defined(__NR_setgroups32)
+  #define SYS_setgroups32 __NR_setgroups32
+#endif
+#if defined(__NR_sethostname)
+  #define SYS_sethostname __NR_sethostname
+#endif
+#if defined(__NR_setitimer)
+  #define SYS_setitimer __NR_setitimer
+#endif
+#if defined(__NR_setns)
+  #define SYS_setns __NR_setns
+#endif
+#if defined(__NR_setpgid)
+  #define SYS_setpgid __NR_setpgid
+#endif
+#if defined(__NR_setpriority)
+  #define SYS_setpriority __NR_setpriority
+#endif
+#if defined(__NR_setregid)
+  #define SYS_setregid __NR_setregid
+#endif
+#if defined(__NR_setregid32)
+  #define SYS_setregid32 __NR_setregid32
+#endif
+#if defined(__NR_setresgid)
+  #define SYS_setresgid __NR_setresgid
+#endif
+#if defined(__NR_setresgid32)
+  #define SYS_setresgid32 __NR_setresgid32
+#endif
+#if defined(__NR_setresuid)
+  #define SYS_setresuid __NR_setresuid
+#endif
+#if defined(__NR_setresuid32)
+  #define SYS_setresuid32 __NR_setresuid32
+#endif
+#if defined(__NR_setreuid)
+  #define SYS_setreuid __NR_setreuid
+#endif
+#if defined(__NR_setreuid32)
+  #define SYS_setreuid32 __NR_setreuid32
+#endif
+#if defined(__NR_setrlimit)
+  #define SYS_setrlimit __NR_setrlimit
+#endif
+#if defined(__NR_setsid)
+  #define SYS_setsid __NR_setsid
+#endif
+#if defined(__NR_setsockopt)
+  #define SYS_setsockopt __NR_setsockopt
+#endif
+#if defined(__NR_settimeofday)
+  #define SYS_settimeofday __NR_settimeofday
+#endif
+#if defined(__NR_setuid)
+  #define SYS_setuid __NR_setuid
+#endif
+#if defined(__NR_setuid32)
+  #define SYS_setuid32 __NR_setuid32
+#endif
+#if defined(__NR_setxattr)
+  #define SYS_setxattr __NR_setxattr
+#endif
+#if defined(__NR_sgetmask)
+  #define SYS_sgetmask __NR_sgetmask
+#endif
+#if defined(__NR_shmat)
+  #define SYS_shmat __NR_shmat
+#endif
+#if defined(__NR_shmctl)
+  #define SYS_shmctl __NR_shmctl
+#endif
+#if defined(__NR_shmdt)
+  #define SYS_shmdt __NR_shmdt
+#endif
+#if defined(__NR_shmget)
+  #define SYS_shmget __NR_shmget
+#endif
+#if defined(__NR_shutdown)
+  #define SYS_shutdown __NR_shutdown
+#endif
+#if defined(__NR_sigaction)
+  #define SYS_sigaction __NR_sigaction
+#endif
+#if defined(__NR_sigaltstack)
+  #define SYS_sigaltstack __NR_sigaltstack
+#endif
+#if defined(__NR_signal)
+  #define SYS_signal __NR_signal
+#endif
+#if defined(__NR_signalfd)
+  #define SYS_signalfd __NR_signalfd
+#endif
+#if defined(__NR_signalfd4)
+  #define SYS_signalfd4 __NR_signalfd4
+#endif
+#if defined(__NR_sigpending)
+  #define SYS_sigpending __NR_sigpending
+#endif
+#if defined(__NR_sigprocmask)
+  #define SYS_sigprocmask __NR_sigprocmask
+#endif
+#if defined(__NR_sigreturn)
+  #define SYS_sigreturn __NR_sigreturn
+#endif
+#if defined(__NR_sigsuspend)
+  #define SYS_sigsuspend __NR_sigsuspend
+#endif
+#if defined(__NR_socket)
+  #define SYS_socket __NR_socket
+#endif
+#if defined(__NR_socketcall)
+  #define SYS_socketcall __NR_socketcall
+#endif
+#if defined(__NR_socketpair)
+  #define SYS_socketpair __NR_socketpair
+#endif
+#if defined(__NR_splice)
+  #define SYS_splice __NR_splice
+#endif
+#if defined(__NR_ssetmask)
+  #define SYS_ssetmask __NR_ssetmask
+#endif
+#if defined(__NR_stat)
+  #define SYS_stat __NR_stat
+#endif
+#if defined(__NR_stat64)
+  #define SYS_stat64 __NR_stat64
+#endif
+#if defined(__NR_statfs)
+  #define SYS_statfs __NR_statfs
+#endif
+#if defined(__NR_statfs64)
+  #define SYS_statfs64 __NR_statfs64
+#endif
+#if defined(__NR_stime)
+  #define SYS_stime __NR_stime
+#endif
+#if defined(__NR_stty)
+  #define SYS_stty __NR_stty
+#endif
+#if defined(__NR_swapoff)
+  #define SYS_swapoff __NR_swapoff
+#endif
+#if defined(__NR_swapon)
+  #define SYS_swapon __NR_swapon
+#endif
+#if defined(__NR_symlink)
+  #define SYS_symlink __NR_symlink
+#endif
+#if defined(__NR_symlinkat)
+  #define SYS_symlinkat __NR_symlinkat
+#endif
+#if defined(__NR_sync)
+  #define SYS_sync __NR_sync
+#endif
+#if defined(__NR_sync_file_range)
+  #define SYS_sync_file_range __NR_sync_file_range
+#endif
+#if defined(__NR_sync_file_range2)
+  #define SYS_sync_file_range2 __NR_sync_file_range2
+#endif
+#if defined(__NR_syncfs)
+  #define SYS_syncfs __NR_syncfs
+#endif
+#if defined(__NR_syscall)
+  #define SYS_syscall __NR_syscall
+#endif
+#if defined(__NR_syscalls)
+  #define SYS_syscalls __NR_syscalls
+#endif
+#if defined(__NR_sysfs)
+  #define SYS_sysfs __NR_sysfs
+#endif
+#if defined(__NR_sysinfo)
+  #define SYS_sysinfo __NR_sysinfo
+#endif
+#if defined(__NR_syslog)
+  #define SYS_syslog __NR_syslog
+#endif
+#if defined(__NR_sysmips)
+  #define SYS_sysmips __NR_sysmips
+#endif
+#if defined(__NR_tee)
+  #define SYS_tee __NR_tee
+#endif
+#if defined(__NR_tgkill)
+  #define SYS_tgkill __NR_tgkill
+#endif
+#if defined(__NR_time)
+  #define SYS_time __NR_time
+#endif
+#if defined(__NR_timer_create)
+  #define SYS_timer_create __NR_timer_create
+#endif
+#if defined(__NR_timer_delete)
+  #define SYS_timer_delete __NR_timer_delete
+#endif
+#if defined(__NR_timer_getoverrun)
+  #define SYS_timer_getoverrun __NR_timer_getoverrun
+#endif
+#if defined(__NR_timer_gettime)
+  #define SYS_timer_gettime __NR_timer_gettime
+#endif
+#if defined(__NR_timer_settime)
+  #define SYS_timer_settime __NR_timer_settime
+#endif
+#if defined(__NR_timerfd)
+  #define SYS_timerfd __NR_timerfd
+#endif
+#if defined(__NR_timerfd_create)
+  #define SYS_timerfd_create __NR_timerfd_create
+#endif
+#if defined(__NR_timerfd_gettime)
+  #define SYS_timerfd_gettime __NR_timerfd_gettime
+#endif
+#if defined(__NR_timerfd_settime)
+  #define SYS_timerfd_settime __NR_timerfd_settime
+#endif
+#if defined(__NR_times)
+  #define SYS_times __NR_times
+#endif
+#if defined(__NR_tkill)
+  #define SYS_tkill __NR_tkill
+#endif
+#if defined(__NR_truncate)
+  #define SYS_truncate __NR_truncate
+#endif
+#if defined(__NR_truncate64)
+  #define SYS_truncate64 __NR_truncate64
+#endif
+#if defined(__NR_tuxcall)
+  #define SYS_tuxcall __NR_tuxcall
+#endif
+#if defined(__NR_ugetrlimit)
+  #define SYS_ugetrlimit __NR_ugetrlimit
+#endif
+#if defined(__NR_ulimit)
+  #define SYS_ulimit __NR_ulimit
+#endif
+#if defined(__NR_umask)
+  #define SYS_umask __NR_umask
+#endif
+#if defined(__NR_umount)
+  #define SYS_umount __NR_umount
+#endif
+#if defined(__NR_umount2)
+  #define SYS_umount2 __NR_umount2
+#endif
+#if defined(__NR_uname)
+  #define SYS_uname __NR_uname
+#endif
+#if defined(__NR_unlink)
+  #define SYS_unlink __NR_unlink
+#endif
+#if defined(__NR_unlinkat)
+  #define SYS_unlinkat __NR_unlinkat
+#endif
+#if defined(__NR_unshare)
+  #define SYS_unshare __NR_unshare
+#endif
+#if defined(__NR_uselib)
+  #define SYS_uselib __NR_uselib
+#endif
+#if defined(__NR_userfaultfd)
+  #define SYS_userfaultfd __NR_userfaultfd
+#endif
+#if defined(__NR_ustat)
+  #define SYS_ustat __NR_ustat
+#endif
+#if defined(__NR_utime)
+  #define SYS_utime __NR_utime
+#endif
+#if defined(__NR_utimensat)
+  #define SYS_utimensat __NR_utimensat
+#endif
+#if defined(__NR_utimes)
+  #define SYS_utimes __NR_utimes
+#endif
+#if defined(__NR_vfork)
+  #define SYS_vfork __NR_vfork
+#endif
+#if defined(__NR_vhangup)
+  #define SYS_vhangup __NR_vhangup
+#endif
+#if defined(__NR_vm86)
+  #define SYS_vm86 __NR_vm86
+#endif
+#if defined(__NR_vm86old)
+  #define SYS_vm86old __NR_vm86old
+#endif
+#if defined(__NR_vmsplice)
+  #define SYS_vmsplice __NR_vmsplice
+#endif
+#if defined(__NR_vserver)
+  #define SYS_vserver __NR_vserver
+#endif
+#if defined(__NR_wait4)
+  #define SYS_wait4 __NR_wait4
+#endif
+#if defined(__NR_waitid)
+  #define SYS_waitid __NR_waitid
+#endif
+#if defined(__NR_waitpid)
+  #define SYS_waitpid __NR_waitpid
+#endif
+#if defined(__NR_write)
+  #define SYS_write __NR_write
+#endif
+#if defined(__NR_writev)
+  #define SYS_writev __NR_writev
+#endif
+#endif /* _BIONIC_BITS_GLIBC_SYSCALLS_H_ */
diff --git a/libc/include/sys/utime.h b/libc/include/bits/ioctl.h
similarity index 87%
copy from libc/include/sys/utime.h
copy to libc/include/bits/ioctl.h
index 9f8810e..53116ca 100644
--- a/libc/include/sys/utime.h
+++ b/libc/include/bits/ioctl.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) 2016 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -25,9 +25,16 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-#ifndef _SYS_UTIME_H_
-#define _SYS_UTIME_H_
 
-#include <linux/utime.h>
+#ifndef _BITS_IOCTL_H_
+#define _BITS_IOCTL_H_
 
-#endif /* _SYS_UTIME_H_ */
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
+int ioctl(int, int, ...);
+
+__END_DECLS
+
+#endif
diff --git a/libc/include/bits/lockf.h b/libc/include/bits/lockf.h
index d814807..655514d 100644
--- a/libc/include/bits/lockf.h
+++ b/libc/include/bits/lockf.h
@@ -30,6 +30,7 @@
 #define _BITS_LOCKF_H_
 
 #include <sys/cdefs.h>
+#include <sys/types.h>
 
 #define F_ULOCK 0
 #define F_LOCK 1
@@ -41,9 +42,9 @@
 #if defined(__USE_FILE_OFFSET64)
 int lockf(int, int, off_t) __RENAME(lockf64);
 #else
-int lockf(int, int, off_t);
+int lockf(int, int, off_t) __INTRODUCED_IN(24);
 #endif
-int lockf64(int, int, off64_t);
+int lockf64(int, int, off64_t) __INTRODUCED_IN(24);
 
 __END_DECLS
 
diff --git a/libc/arch-mips/bionic/bzero.S b/libc/include/bits/mbstate_t.h
similarity index 83%
copy from libc/arch-mips/bionic/bzero.S
copy to libc/include/bits/mbstate_t.h
index 6e5d294..057a2c9 100644
--- a/libc/arch-mips/bionic/bzero.S
+++ b/libc/include/bits/mbstate_t.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) 2016 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,14 +26,16 @@
  * SUCH DAMAGE.
  */
 
-#include <private/bionic_asm.h>
+#ifndef _BITS_MBSTATE_T_H_
+#define _BITS_MBSTATE_T_H_
 
-// void bzero(void*, size_t);
-ENTRY(bzero)
-	.set	noreorder
-	.cpload	t9
-	move	a2,a1
-	la	t9,memset
-	j	t9
-	 move	a1,zero
-END(bzero)
+#include <sys/cdefs.h>
+
+typedef struct {
+  unsigned char __seq[4];
+#ifdef __LP64__
+  unsigned char __reserved[4];
+#endif
+} mbstate_t;
+
+#endif
diff --git a/libc/include/bits/posix_limits.h b/libc/include/bits/posix_limits.h
index 31016a8..1bd87f4 100644
--- a/libc/include/bits/posix_limits.h
+++ b/libc/include/bits/posix_limits.h
@@ -29,6 +29,7 @@
 #ifndef _BITS_POSIX_LIMITS_H_
 #define _BITS_POSIX_LIMITS_H_
 
+#include <sys/cdefs.h>
 
 /* Any constant values here other than -1 or 200809L are explicitly specified by POSIX.1-2008. */
 /* Keep it sorted. */
@@ -94,8 +95,8 @@
 #define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4
 #define _POSIX_THREAD_KEYS_MAX      128
 #define _POSIX_THREAD_PRIORITY_SCHEDULING 200809L
-#define _POSIX_THREAD_PRIO_INHERIT  200809L  /* linux feature */
-#define _POSIX_THREAD_PRIO_PROTECT  200809L  /* linux feature */
+#define _POSIX_THREAD_PRIO_INHERIT -1  /* not implemented */
+#define _POSIX_THREAD_PRIO_PROTECT -1  /* not implemented */
 #define _POSIX_THREAD_PROCESS_SHARED  -1  /* not implemented */
 #define _POSIX_THREAD_ROBUST_PRIO_INHERIT -1  /* not implemented */
 #define _POSIX_THREAD_ROBUST_PRIO_PROTECT -1  /* not implemented */
diff --git a/libc/include/bits/pthread_types.h b/libc/include/bits/pthread_types.h
index 6ac1c68..194a49b 100644
--- a/libc/include/bits/pthread_types.h
+++ b/libc/include/bits/pthread_types.h
@@ -29,6 +29,7 @@
 #ifndef _BITS_PTHREAD_TYPES_H_
 #define _BITS_PTHREAD_TYPES_H_
 
+#include <sys/cdefs.h>
 #include <sys/types.h>
 
 typedef long pthread_t;
diff --git a/libc/include/sys/utime.h b/libc/include/bits/sa_family_t.h
similarity index 87%
rename from libc/include/sys/utime.h
rename to libc/include/bits/sa_family_t.h
index 9f8810e..98ca27f 100644
--- a/libc/include/sys/utime.h
+++ b/libc/include/bits/sa_family_t.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) 2016 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -25,9 +25,12 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-#ifndef _SYS_UTIME_H_
-#define _SYS_UTIME_H_
 
-#include <linux/utime.h>
+#ifndef _BITS_SA_FAMILY_T_H_
+#define _BITS_SA_FAMILY_T_H_
 
-#endif /* _SYS_UTIME_H_ */
+#include <sys/cdefs.h>
+
+typedef unsigned short sa_family_t;
+
+#endif
diff --git a/libc/bionic/__memchr_chk.cpp b/libc/include/bits/strcasecmp.h
similarity index 72%
copy from libc/bionic/__memchr_chk.cpp
copy to libc/include/bits/strcasecmp.h
index d141c04..7cb713e 100644
--- a/libc/bionic/__memchr_chk.cpp
+++ b/libc/include/bits/strcasecmp.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 The Android Open Source Project
+ * Copyright (C) 2016 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,14 +26,20 @@
  * SUCH DAMAGE.
  */
 
-#undef _FORTIFY_SOURCE
-#include <string.h>
-#include "private/libc_logging.h"
+#ifndef _BITS_STRCASECMP_H_
+#define _BITS_STRCASECMP_H_
 
-extern "C" void* __memchr_chk(const void* s, int c, size_t n, size_t buf_size) {
-  if (__predict_false(n > buf_size)) {
-    __fortify_chk_fail("memchr: prevented read past end of buffer", 0);
-  }
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <xlocale.h>
 
-  return memchr(s, c, n);
-}
+__BEGIN_DECLS
+
+int strcasecmp(const char*, const char*) __purefunc;
+int strcasecmp_l(const char*, const char*, locale_t) __purefunc __INTRODUCED_IN(23);
+int strncasecmp(const char*, const char*, size_t) __purefunc;
+int strncasecmp_l(const char*, const char*, size_t, locale_t) __purefunc __INTRODUCED_IN(23);
+
+__END_DECLS
+
+#endif
diff --git a/libc/include/bits/sysconf.h b/libc/include/bits/sysconf.h
new file mode 100644
index 0000000..2cbbb11
--- /dev/null
+++ b/libc/include/bits/sysconf.h
@@ -0,0 +1,196 @@
+/*
+ * Copyright (C) 2008 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.
+ */
+
+#ifndef _BITS_SYSCONF_H_
+#define _BITS_SYSCONF_H_
+
+#include <sys/cdefs.h>
+
+/* as listed by Posix sysconf() description */
+/* most of these will return -1 and ENOSYS  */
+
+#define _SC_ARG_MAX             0x0000
+#define _SC_BC_BASE_MAX         0x0001
+#define _SC_BC_DIM_MAX          0x0002
+#define _SC_BC_SCALE_MAX        0x0003
+#define _SC_BC_STRING_MAX       0x0004
+#define _SC_CHILD_MAX           0x0005
+#define _SC_CLK_TCK             0x0006
+#define _SC_COLL_WEIGHTS_MAX    0x0007
+#define _SC_EXPR_NEST_MAX       0x0008
+#define _SC_LINE_MAX            0x0009
+#define _SC_NGROUPS_MAX         0x000a
+#define _SC_OPEN_MAX            0x000b
+#define _SC_PASS_MAX            0x000c
+#define _SC_2_C_BIND            0x000d
+#define _SC_2_C_DEV             0x000e
+#define _SC_2_C_VERSION         0x000f  /* Obsolescent in POSIX.1-2008, TODO: remove it. */
+#define _SC_2_CHAR_TERM         0x0010
+#define _SC_2_FORT_DEV          0x0011
+#define _SC_2_FORT_RUN          0x0012
+#define _SC_2_LOCALEDEF         0x0013
+#define _SC_2_SW_DEV            0x0014
+#define _SC_2_UPE               0x0015
+#define _SC_2_VERSION           0x0016
+#define _SC_JOB_CONTROL         0x0017
+#define _SC_SAVED_IDS           0x0018
+#define _SC_VERSION             0x0019
+#define _SC_RE_DUP_MAX          0x001a
+#define _SC_STREAM_MAX          0x001b
+#define _SC_TZNAME_MAX          0x001c
+#define _SC_XOPEN_CRYPT         0x001d
+#define _SC_XOPEN_ENH_I18N      0x001e
+#define _SC_XOPEN_SHM           0x001f
+#define _SC_XOPEN_VERSION       0x0020
+#define _SC_XOPEN_XCU_VERSION   0x0021  /* Obsolescent in POSIX.1-2008, TODO: remove it. */
+#define _SC_XOPEN_REALTIME      0x0022
+#define _SC_XOPEN_REALTIME_THREADS  0x0023
+#define _SC_XOPEN_LEGACY        0x0024
+#define _SC_ATEXIT_MAX          0x0025
+#define _SC_IOV_MAX             0x0026
+#define _SC_PAGESIZE            0x0027
+#define _SC_PAGE_SIZE           0x0028
+#define _SC_XOPEN_UNIX          0x0029
+#define _SC_XBS5_ILP32_OFF32    0x002a  /* Obsolescent in POSIX.1-2008, TODO: remove it. */
+#define _SC_XBS5_ILP32_OFFBIG   0x002b  /* Obsolescent in POSIX.1-2008, TODO: remove it. */
+#define _SC_XBS5_LP64_OFF64     0x002c  /* Obsolescent in POSIX.1-2008, TODO: remove it. */
+#define _SC_XBS5_LPBIG_OFFBIG   0x002d  /* Obsolescent in POSIX.1-2008, TODO: remove it. */
+#define _SC_AIO_LISTIO_MAX      0x002e
+#define _SC_AIO_MAX             0x002f
+#define _SC_AIO_PRIO_DELTA_MAX  0x0030
+#define _SC_DELAYTIMER_MAX      0x0031
+#define _SC_MQ_OPEN_MAX         0x0032
+#define _SC_MQ_PRIO_MAX         0x0033
+#define _SC_RTSIG_MAX           0x0034
+#define _SC_SEM_NSEMS_MAX       0x0035
+#define _SC_SEM_VALUE_MAX       0x0036
+#define _SC_SIGQUEUE_MAX        0x0037
+#define _SC_TIMER_MAX           0x0038
+#define _SC_ASYNCHRONOUS_IO     0x0039
+#define _SC_FSYNC               0x003a
+#define _SC_MAPPED_FILES        0x003b
+#define _SC_MEMLOCK             0x003c
+#define _SC_MEMLOCK_RANGE       0x003d
+#define _SC_MEMORY_PROTECTION   0x003e
+#define _SC_MESSAGE_PASSING     0x003f
+#define _SC_PRIORITIZED_IO      0x0040
+#define _SC_PRIORITY_SCHEDULING 0x0041
+#define _SC_REALTIME_SIGNALS    0x0042
+#define _SC_SEMAPHORES          0x0043
+#define _SC_SHARED_MEMORY_OBJECTS  0x0044
+#define _SC_SYNCHRONIZED_IO     0x0045
+#define _SC_TIMERS              0x0046
+#define _SC_GETGR_R_SIZE_MAX    0x0047
+#define _SC_GETPW_R_SIZE_MAX    0x0048
+#define _SC_LOGIN_NAME_MAX      0x0049
+#define _SC_THREAD_DESTRUCTOR_ITERATIONS  0x004a
+#define _SC_THREAD_KEYS_MAX     0x004b
+#define _SC_THREAD_STACK_MIN    0x004c
+#define _SC_THREAD_THREADS_MAX  0x004d
+#define _SC_TTY_NAME_MAX        0x004e
+
+#define _SC_THREADS                     0x004f
+#define _SC_THREAD_ATTR_STACKADDR       0x0050
+#define _SC_THREAD_ATTR_STACKSIZE       0x0051
+#define _SC_THREAD_PRIORITY_SCHEDULING  0x0052
+#define _SC_THREAD_PRIO_INHERIT         0x0053
+#define _SC_THREAD_PRIO_PROTECT         0x0054
+#define _SC_THREAD_SAFE_FUNCTIONS       0x0055
+
+#define _SC_NPROCESSORS_CONF            0x0060
+#define _SC_NPROCESSORS_ONLN            0x0061
+#define _SC_PHYS_PAGES                  0x0062
+#define _SC_AVPHYS_PAGES                0x0063
+#define _SC_MONOTONIC_CLOCK             0x0064
+
+#define _SC_2_PBS               0x0065
+#define _SC_2_PBS_ACCOUNTING    0x0066
+#define _SC_2_PBS_CHECKPOINT    0x0067
+#define _SC_2_PBS_LOCATE        0x0068
+#define _SC_2_PBS_MESSAGE       0x0069
+#define _SC_2_PBS_TRACK         0x006a
+#define _SC_ADVISORY_INFO       0x006b
+#define _SC_BARRIERS            0x006c
+#define _SC_CLOCK_SELECTION     0x006d
+#define _SC_CPUTIME             0x006e
+#define _SC_HOST_NAME_MAX       0x006f
+#define _SC_IPV6                0x0070
+#define _SC_RAW_SOCKETS         0x0071
+#define _SC_READER_WRITER_LOCKS 0x0072
+#define _SC_REGEXP              0x0073
+#define _SC_SHELL               0x0074
+#define _SC_SPAWN               0x0075
+#define _SC_SPIN_LOCKS          0x0076
+#define _SC_SPORADIC_SERVER     0x0077
+#define _SC_SS_REPL_MAX         0x0078
+#define _SC_SYMLOOP_MAX         0x0079
+#define _SC_THREAD_CPUTIME      0x007a
+#define _SC_THREAD_PROCESS_SHARED       0x007b
+#define _SC_THREAD_ROBUST_PRIO_INHERIT  0x007c
+#define _SC_THREAD_ROBUST_PRIO_PROTECT  0x007d
+#define _SC_THREAD_SPORADIC_SERVER      0x007e
+#define _SC_TIMEOUTS            0x007f
+#define _SC_TRACE               0x0080
+#define _SC_TRACE_EVENT_FILTER  0x0081
+#define _SC_TRACE_EVENT_NAME_MAX  0x0082
+#define _SC_TRACE_INHERIT       0x0083
+#define _SC_TRACE_LOG           0x0084
+#define _SC_TRACE_NAME_MAX      0x0085
+#define _SC_TRACE_SYS_MAX       0x0086
+#define _SC_TRACE_USER_EVENT_MAX  0x0087
+#define _SC_TYPED_MEMORY_OBJECTS  0x0088
+#define _SC_V7_ILP32_OFF32      0x0089
+#define _SC_V7_ILP32_OFFBIG     0x008a
+#define _SC_V7_LP64_OFF64       0x008b
+#define _SC_V7_LPBIG_OFFBIG     0x008c
+#define _SC_XOPEN_STREAMS       0x008d
+#define _SC_XOPEN_UUCP          0x008e
+
+#define _SC_LEVEL1_ICACHE_SIZE      0x008f
+#define _SC_LEVEL1_ICACHE_ASSOC     0x0090
+#define _SC_LEVEL1_ICACHE_LINESIZE  0x0091
+#define _SC_LEVEL1_DCACHE_SIZE      0x0092
+#define _SC_LEVEL1_DCACHE_ASSOC     0x0093
+#define _SC_LEVEL1_DCACHE_LINESIZE  0x0094
+#define _SC_LEVEL2_CACHE_SIZE       0x0095
+#define _SC_LEVEL2_CACHE_ASSOC      0x0096
+#define _SC_LEVEL2_CACHE_LINESIZE   0x0097
+#define _SC_LEVEL3_CACHE_SIZE       0x0098
+#define _SC_LEVEL3_CACHE_ASSOC      0x0099
+#define _SC_LEVEL3_CACHE_LINESIZE   0x009a
+#define _SC_LEVEL4_CACHE_SIZE       0x009b
+#define _SC_LEVEL4_CACHE_ASSOC      0x009c
+#define _SC_LEVEL4_CACHE_LINESIZE   0x009d
+
+__BEGIN_DECLS
+
+long sysconf(int __name);
+
+__END_DECLS
+
+#endif /* _SYS_SYSCONF_H_ */
diff --git a/libc/include/bits/timespec.h b/libc/include/bits/timespec.h
index 046d898..df7a7ce 100644
--- a/libc/include/bits/timespec.h
+++ b/libc/include/bits/timespec.h
@@ -29,6 +29,7 @@
 #ifndef _BITS_TIMESPEC_H_
 #define _BITS_TIMESPEC_H_
 
+#include <sys/cdefs.h>
 #include <sys/types.h>
 
 /*
diff --git a/libc/include/bits/wchar_limits.h b/libc/include/bits/wchar_limits.h
index f779c1a..ffad604 100644
--- a/libc/include/bits/wchar_limits.h
+++ b/libc/include/bits/wchar_limits.h
@@ -29,6 +29,8 @@
 #ifndef _BITS_WCHAR_LIMITS_H_
 #define _BITS_WCHAR_LIMITS_H_
 
+#include <sys/cdefs.h>
+
 /* Both GCC and clang define __WCHAR_MAX__. */
 #define WCHAR_MAX __WCHAR_MAX__
 
diff --git a/libstdc++/include/cassert b/libc/include/bits/wctype.h
similarity index 62%
copy from libstdc++/include/cassert
copy to libc/include/bits/wctype.h
index 5753e34..b98e500 100644
--- a/libstdc++/include/cassert
+++ b/libc/include/bits/wctype.h
@@ -1,6 +1,5 @@
-/* -*- c++ -*- */
 /*
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2016 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -27,13 +26,41 @@
  * SUCH DAMAGE.
  */
 
-/*
- * Standard C++ Library wrapper around the C assert.h header file.  This file
- * can be included multiple times with different definition of NDEBUG, hence the
- * absence of include guards.
- */
+#ifndef _BITS_WCTYPE_H_
+#define _BITS_WCTYPE_H_
 
-#ifndef BIONIC_LIBSTDCPP_INCLUDE_CASSERT__
-#define BIONIC_LIBSTDCPP_INCLUDE_CASSERT__
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
+typedef __WINT_TYPE__ wint_t;
+
+#define WEOF __BIONIC_CAST(static_cast, wint_t, -1)
+
+int iswalnum(wint_t);
+int iswalpha(wint_t);
+int iswblank(wint_t) __INTRODUCED_IN(21);
+int iswcntrl(wint_t);
+int iswdigit(wint_t);
+int iswgraph(wint_t);
+int iswlower(wint_t);
+int iswprint(wint_t);
+int iswpunct(wint_t);
+int iswspace(wint_t);
+int iswupper(wint_t);
+int iswxdigit(wint_t);
+
+wint_t towlower(wint_t);
+wint_t towupper(wint_t);
+
+typedef long wctype_t;
+wctype_t wctype(const char*);
+int iswctype(wint_t, wctype_t);
+
+typedef const void* wctrans_t;
+wint_t towctrans(wint_t, wctrans_t) __INTRODUCED_IN_FUTURE;
+wctrans_t wctrans(const char*) __INTRODUCED_IN_FUTURE;
+
+__END_DECLS
+
 #endif
-#include <assert.h>
diff --git a/libc/include/byteswap.h b/libc/include/byteswap.h
index 628fb7f..0838e6c 100644
--- a/libc/include/byteswap.h
+++ b/libc/include/byteswap.h
@@ -25,9 +25,11 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #ifndef _BYTESWAP_H_
 #define _BYTESWAP_H_
 
+#include <sys/cdefs.h>
 #include <sys/endian.h>
 
 #define bswap_16(x) __swap16(x)
diff --git a/libc/include/complex.h b/libc/include/complex.h
new file mode 100644
index 0000000..f4dc124
--- /dev/null
+++ b/libc/include/complex.h
@@ -0,0 +1,160 @@
+/*-
+ * Copyright (c) 2001-2011 The FreeBSD 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:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 AUTHOR 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 AUTHOR 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _COMPLEX_H
+#define	_COMPLEX_H
+
+#include <sys/cdefs.h>
+
+#ifdef __GNUC__
+#define	_Complex_I	((float _Complex)1.0i)
+#endif
+
+#ifdef __generic
+_Static_assert(__generic(_Complex_I, float _Complex, 1, 0),
+    "_Complex_I must be of type float _Complex");
+#endif
+
+#define	complex		_Complex
+#define	I		_Complex_I
+
+#if __STDC_VERSION__ >= 201112L
+#ifdef __clang__
+#define	CMPLX(x, y)	((double complex){ x, y })
+#define	CMPLXF(x, y)	((float complex){ x, y })
+#define	CMPLXL(x, y)	((long double complex){ x, y })
+#else
+#define	CMPLX(x, y)	__builtin_complex((double)(x), (double)(y))
+#define	CMPLXF(x, y)	__builtin_complex((float)(x), (float)(y))
+#define	CMPLXL(x, y)	__builtin_complex((long double)(x), (long double)(y))
+#endif
+#endif
+
+__BEGIN_DECLS
+
+/* 7.3.5 Trigonometric functions */
+/* 7.3.5.1 The cacos functions */
+double complex cacos(double complex) __INTRODUCED_IN(23);
+float complex cacosf(float complex) __INTRODUCED_IN(23);
+long double complex cacosl(long double complex) __INTRODUCED_IN_FUTURE;
+/* 7.3.5.2 The casin functions */
+double complex casin(double complex) __INTRODUCED_IN(23);
+float complex casinf(float complex) __INTRODUCED_IN(23);
+long double complex casinl(long double complex) __INTRODUCED_IN_FUTURE;
+/* 7.3.5.1 The catan functions */
+double complex catan(double complex) __INTRODUCED_IN(23);
+float complex catanf(float complex) __INTRODUCED_IN(23);
+long double complex catanl(long double complex) __INTRODUCED_IN_FUTURE;
+/* 7.3.5.1 The ccos functions */
+double complex ccos(double complex) __INTRODUCED_IN(23);
+float complex ccosf(float complex) __INTRODUCED_IN(23);
+long double complex ccosl(long double complex) __INTRODUCED_IN_FUTURE;
+/* 7.3.5.1 The csin functions */
+double complex csin(double complex) __INTRODUCED_IN(23);
+float complex csinf(float complex) __INTRODUCED_IN(23);
+long double complex csinl(long double complex) __INTRODUCED_IN_FUTURE;
+/* 7.3.5.1 The ctan functions */
+double complex ctan(double complex) __INTRODUCED_IN(23);
+float complex ctanf(float complex) __INTRODUCED_IN(23);
+long double complex ctanl(long double complex) __INTRODUCED_IN_FUTURE;
+
+/* 7.3.6 Hyperbolic functions */
+/* 7.3.6.1 The cacosh functions */
+double complex cacosh(double complex) __INTRODUCED_IN(23);
+float complex cacoshf(float complex) __INTRODUCED_IN(23);
+long double complex cacoshl(long double complex) __INTRODUCED_IN_FUTURE;
+/* 7.3.6.2 The casinh functions */
+double complex casinh(double complex) __INTRODUCED_IN(23);
+float complex casinhf(float complex) __INTRODUCED_IN(23);
+long double complex casinhl(long double complex) __INTRODUCED_IN_FUTURE;
+/* 7.3.6.3 The catanh functions */
+double complex catanh(double complex) __INTRODUCED_IN(23);
+float complex catanhf(float complex) __INTRODUCED_IN(23);
+long double complex catanhl(long double complex) __INTRODUCED_IN_FUTURE;
+/* 7.3.6.4 The ccosh functions */
+double complex ccosh(double complex) __INTRODUCED_IN(23);
+float complex ccoshf(float complex) __INTRODUCED_IN(23);
+long double complex ccoshl(long double complex) __INTRODUCED_IN_FUTURE;
+/* 7.3.6.5 The csinh functions */
+double complex csinh(double complex) __INTRODUCED_IN(23);
+float complex csinhf(float complex) __INTRODUCED_IN(23);
+long double complex csinhl(long double complex) __INTRODUCED_IN_FUTURE;
+/* 7.3.6.6 The ctanh functions */
+double complex ctanh(double complex) __INTRODUCED_IN(23);
+float complex ctanhf(float complex) __INTRODUCED_IN(23);
+long double complex ctanhl(long double complex) __INTRODUCED_IN_FUTURE;
+
+/* 7.3.7 Exponential and logarithmic functions */
+/* 7.3.7.1 The cexp functions */
+double complex cexp(double complex) __INTRODUCED_IN(23);
+float complex cexpf(float complex) __INTRODUCED_IN(23);
+long double complex cexpl(long double complex) __INTRODUCED_IN_FUTURE;
+/* 7.3.7.2 The clog functions */
+double complex clog(double complex) __INTRODUCED_IN_FUTURE;
+float complex clogf(float complex) __INTRODUCED_IN_FUTURE;
+long double complex clogl(long double complex) __INTRODUCED_IN_FUTURE;
+
+/* 7.3.8 Power and absolute-value functions */
+/* 7.3.8.1 The cabs functions */
+double cabs(double complex) __INTRODUCED_IN(23);
+float cabsf(float complex) __INTRODUCED_IN(23);
+long double cabsl(long double complex) __INTRODUCED_IN_32(21) __INTRODUCED_IN_64(23);
+/* 7.3.8.2 The cpow functions */
+double complex cpow(double complex, double complex) __INTRODUCED_IN_FUTURE;
+float complex cpowf(float complex, float complex) __INTRODUCED_IN_FUTURE;
+long double complex cpowl(long double complex, long double complex) __INTRODUCED_IN_FUTURE;
+/* 7.3.8.3 The csqrt functions */
+double complex csqrt(double complex) __INTRODUCED_IN(23);
+float complex csqrtf(float complex) __INTRODUCED_IN(23);
+long double complex csqrtl(long double complex) __INTRODUCED_IN_32(21) __INTRODUCED_IN_64(23);
+
+/* 7.3.9 Manipulation functions */
+/* 7.3.9.1 The carg functions */
+double carg(double complex) __INTRODUCED_IN(23);
+float cargf(float complex) __INTRODUCED_IN(23);
+long double cargl(long double complex) __INTRODUCED_IN(23);
+/* 7.3.9.2 The cimag functions */
+double cimag(double complex) __INTRODUCED_IN(23);
+float cimagf(float complex) __INTRODUCED_IN(23);
+long double cimagl(long double complex) __INTRODUCED_IN(23);
+/* 7.3.9.3 The conj functions */
+double complex conj(double complex) __INTRODUCED_IN(23);
+float complex conjf(float complex) __INTRODUCED_IN(23);
+long double complex conjl(long double complex) __INTRODUCED_IN(23);
+/* 7.3.9.4 The cproj functions */
+double complex cproj(double complex) __INTRODUCED_IN(23);
+float complex cprojf(float complex) __INTRODUCED_IN(23);
+long double complex cprojl(long double complex) __INTRODUCED_IN_32(21) __INTRODUCED_IN_64(23);
+/* 7.3.9.5 The creal functions */
+double creal(double complex) __INTRODUCED_IN(23);
+float crealf(float complex) __INTRODUCED_IN(23);
+long double creall(long double complex) __INTRODUCED_IN(23);
+
+__END_DECLS
+
+#endif /* _COMPLEX_H */
diff --git a/libc/include/ctype.h b/libc/include/ctype.h
index 83b5ba7..a07f9c8 100644
--- a/libc/include/ctype.h
+++ b/libc/include/ctype.h
@@ -54,13 +54,16 @@
 #define _CTYPE_R (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_D|_CTYPE_B)
 #define _CTYPE_A (_CTYPE_L|_CTYPE_U)
 
+/* _CTYPE_N was added to NDK r10 and is expected by gnu-libstdc++ */
+#define _CTYPE_N _CTYPE_D
+
 __BEGIN_DECLS
 
-extern const char	*_ctype_;
+extern const char* _ctype_;
 
-#if defined(__GNUC__) || defined(_ANSI_LIBRARY) || defined(lint)
 int isalnum(int);
 int isalpha(int);
+int isblank(int);
 int iscntrl(int);
 int isdigit(int);
 int isgraph(int);
@@ -73,36 +76,24 @@
 int tolower(int);
 int toupper(int);
 
-#if __ANDROID_API__ >= 21
-int isalnum_l(int, locale_t);
-int isalpha_l(int, locale_t);
-int isblank_l(int, locale_t);
-int iscntrl_l(int, locale_t);
-int isdigit_l(int, locale_t);
-int isgraph_l(int, locale_t);
-int islower_l(int, locale_t);
-int isprint_l(int, locale_t);
-int ispunct_l(int, locale_t);
-int isspace_l(int, locale_t);
-int isupper_l(int, locale_t);
-int isxdigit_l(int, locale_t);
-int tolower_l(int, locale_t);
-int toupper_l(int, locale_t);
-#endif /* __ANDROID_API__ >= 21 */
-
-#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE > 200112 \
-    || __XPG_VISIBLE > 600
-int isblank(int);
-#endif
-
-#if __BSD_VISIBLE || __XPG_VISIBLE
+int isalnum_l(int, locale_t) __INTRODUCED_IN(21);
+int isalpha_l(int, locale_t) __INTRODUCED_IN(21);
+int isblank_l(int, locale_t) __INTRODUCED_IN(21);
+int iscntrl_l(int, locale_t) __INTRODUCED_IN(21);
+int isdigit_l(int, locale_t) __INTRODUCED_IN(21);
+int isgraph_l(int, locale_t) __INTRODUCED_IN(21);
+int islower_l(int, locale_t) __INTRODUCED_IN(21);
+int isprint_l(int, locale_t) __INTRODUCED_IN(21);
+int ispunct_l(int, locale_t) __INTRODUCED_IN(21);
+int isspace_l(int, locale_t) __INTRODUCED_IN(21);
+int isupper_l(int, locale_t) __INTRODUCED_IN(21);
+int isxdigit_l(int, locale_t) __INTRODUCED_IN(21);
+int tolower_l(int, locale_t) __INTRODUCED_IN(21);
+int toupper_l(int, locale_t) __INTRODUCED_IN(21);
 int isascii(int);
 int toascii(int);
-int _tolower(int);
-int _toupper(int);
-#endif /* __BSD_VISIBLE || __XPG_VISIBLE */
-
-#endif /* __GNUC__ || _ANSI_LIBRARY || lint */
+int _tolower(int) __INTRODUCED_IN(21);
+int _toupper(int) __INTRODUCED_IN(21);
 
 __END_DECLS
 
diff --git a/libc/include/dirent.h b/libc/include/dirent.h
index 3cdfa68..3f9ad18 100644
--- a/libc/include/dirent.h
+++ b/libc/include/dirent.h
@@ -68,25 +68,28 @@
 
 typedef struct DIR DIR;
 
-extern DIR* opendir(const char*);
-extern DIR* fdopendir(int);
-extern struct dirent* readdir(DIR*);
-extern struct dirent64* readdir64(DIR*);
-extern int readdir_r(DIR*, struct dirent*, struct dirent**);
-extern int readdir64_r(DIR*, struct dirent64*, struct dirent64**);
-extern int closedir(DIR*);
-extern void rewinddir(DIR*);
-extern void seekdir(DIR*, long);
-extern long telldir(DIR*);
-extern int dirfd(DIR*);
-extern int alphasort(const struct dirent**, const struct dirent**);
-extern int alphasort64(const struct dirent64**, const struct dirent64**);
-extern int scandir64(const char*, struct dirent64***, int (*)(const struct dirent64*), int (*)(const struct dirent64**, const struct dirent64**));
-extern int scandir(const char*, struct dirent***, int (*)(const struct dirent*), int (*)(const struct dirent**, const struct dirent**));
+DIR* opendir(const char*);
+DIR* fdopendir(int);
+struct dirent* readdir(DIR*);
+struct dirent64* readdir64(DIR*) __INTRODUCED_IN(21);
+int readdir_r(DIR*, struct dirent*, struct dirent**);
+int readdir64_r(DIR*, struct dirent64*, struct dirent64**) __INTRODUCED_IN(21);
+int closedir(DIR*);
+void rewinddir(DIR*);
+void seekdir(DIR*, long) __INTRODUCED_IN(23);
+long telldir(DIR*) __INTRODUCED_IN(23);
+int dirfd(DIR*);
+int alphasort(const struct dirent**, const struct dirent**);
+int alphasort64(const struct dirent64**, const struct dirent64**) __INTRODUCED_IN(21);
+int scandir64(const char*, struct dirent64***, int (*)(const struct dirent64*),
+              int (*)(const struct dirent64**, const struct dirent64**)) __INTRODUCED_IN(21);
+int scandir(const char*, struct dirent***, int (*)(const struct dirent*), int (*)(const struct dirent**, const struct dirent**));
 
 #if defined(__USE_GNU)
-int scandirat64(int, const char*, struct dirent64***, int (*)(const struct dirent64*), int (*)(const struct dirent64**, const struct dirent64**));
-int scandirat(int, const char*, struct dirent***, int (*)(const struct dirent*), int (*)(const struct dirent**, const struct dirent**));
+int scandirat64(int, const char*, struct dirent64***, int (*)(const struct dirent64*),
+                int (*)(const struct dirent64**, const struct dirent64**)) __INTRODUCED_IN(24);
+int scandirat(int, const char*, struct dirent***, int (*)(const struct dirent*),
+              int (*)(const struct dirent**, const struct dirent**)) __INTRODUCED_IN(24);
 #endif
 
 __END_DECLS
diff --git a/libc/include/dlfcn.h b/libc/include/dlfcn.h
index c2e8980..a53f664 100644
--- a/libc/include/dlfcn.h
+++ b/libc/include/dlfcn.h
@@ -25,6 +25,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #ifndef __DLFCN_H__
 #define __DLFCN_H__
 
@@ -32,23 +33,28 @@
 
 __BEGIN_DECLS
 
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnullability-completeness"
+#endif
+
 typedef struct {
-    const char *dli_fname;  /* Pathname of shared object that
-                               contains address */
-    void       *dli_fbase;  /* Address at which shared object
-                               is loaded */
-    const char *dli_sname;  /* Name of nearest symbol with address
-                               lower than addr */
-    void       *dli_saddr;  /* Exact address of symbol named
-                               in dli_sname */
+  /* Pathname of shared object that contains address. */
+  const char* dli_fname;
+  /* Address at which shared object is loaded. */
+  void* dli_fbase;
+  /* Name of nearest symbol with address lower than addr. */
+  const char* dli_sname;
+  /* Exact address of symbol named in dli_sname. */
+  void* dli_saddr;
 } Dl_info;
 
-extern void* dlopen(const char*  filename, int flag);
-extern int dlclose(void*  handle);
-extern const char* dlerror(void);
-extern void* dlsym(void* handle, const char* symbol) __nonnull((2));
-extern void* dlvsym(void* handle, const char* symbol, const char* version) __nonnull((2, 3));
-extern int dladdr(const void* addr, Dl_info *info);
+void* dlopen(const char* filename, int flag);
+int dlclose(void* _Nonnull handle);
+const char* dlerror(void);
+void* dlsym(void* handle, const char* _Nonnull symbol);
+void* dlvsym(void* handle, const char* _Nonnull symbol, const char* _Nonnull version) __INTRODUCED_IN(24);
+int dladdr(const void* addr, Dl_info* _Nonnull info);
 
 enum {
 #if defined(__LP64__)
@@ -69,15 +75,17 @@
 };
 
 #if defined (__LP64__)
-#define RTLD_DEFAULT  ((void*) 0)
-#define RTLD_NEXT     ((void*) -1L)
+#define RTLD_DEFAULT  __BIONIC_CAST(reinterpret_cast, void*, 0)
+#define RTLD_NEXT     __BIONIC_CAST(reinterpret_cast, void*, -1L)
 #else
-#define RTLD_DEFAULT  ((void*) 0xffffffff)
-#define RTLD_NEXT     ((void*) 0xfffffffe)
+#define RTLD_DEFAULT  __BIONIC_CAST(reinterpret_cast, void*, 0xffffffff)
+#define RTLD_NEXT     __BIONIC_CAST(reinterpret_cast, void*, 0xfffffffe)
+#endif
+
+#if defined(__clang__)
+#pragma clang diagnostic pop
 #endif
 
 __END_DECLS
 
 #endif /* __DLFCN_H */
-
-
diff --git a/libc/include/elf.h b/libc/include/elf.h
index eaad1d3..1a99337 100644
--- a/libc/include/elf.h
+++ b/libc/include/elf.h
@@ -25,14 +25,15 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #ifndef _ELF_H
 #define _ELF_H
 
 #include <linux/auxvec.h>
 #include <linux/elf.h>
 #include <linux/elf-em.h>
-
 #include <machine/elf_machdep.h>
+#include <sys/cdefs.h>
 
 #define ELF32_R_INFO(sym, type) ((((Elf32_Word)sym) << 8) | ((type) & 0xff))
 #define ELF64_R_INFO(sym, type) ((((Elf64_Xword)sym) << 32) | ((type) & 0xffffffff))
diff --git a/libc/include/endian.h b/libc/include/endian.h
index 475b48c..65e2930 100644
--- a/libc/include/endian.h
+++ b/libc/include/endian.h
@@ -1,33 +1 @@
-/*
- * Copyright (C) 2008 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.
- */
-#ifndef _ENDIAN_H_
-#define _ENDIAN_H_
-
 #include <sys/endian.h>
-
-#endif /* _ENDIAN_H_ */
diff --git a/libc/include/errno.h b/libc/include/errno.h
index 82f4b42..8b2e8ed 100644
--- a/libc/include/errno.h
+++ b/libc/include/errno.h
@@ -41,15 +41,13 @@
 #endif
 
 /* internal function returning the address of the thread-specific errno */
-extern volatile int* __errno(void) __pure2;
+volatile int* __errno(void) __pure2;
 
 /* a macro expanding to the errno l-value */
 #define  errno   (*__errno())
 
-#if __ANDROID_API__ < 21
-#include <android/legacy_errno_inlines.h>
-#endif
-
 __END_DECLS
 
+#include <android/legacy_errno_inlines.h>
+
 #endif /* _ERRNO_H */
diff --git a/libc/include/error.h b/libc/include/error.h
index dd12884..05ce35d 100644
--- a/libc/include/error.h
+++ b/libc/include/error.h
@@ -33,12 +33,13 @@
 
 __BEGIN_DECLS
 
-void error(int, int, const char*, ...) __printflike(3, 4);
-void error_at_line(int, int, const char*, unsigned int, const char*, ...) __printflike(5, 6);
+extern void (* _Nullable error_print_progname)(void) __INTRODUCED_IN(23);
+extern unsigned int error_message_count __INTRODUCED_IN(23);
+extern int error_one_per_line __INTRODUCED_IN(23);
 
-extern void (*error_print_progname)(void);
-extern unsigned int error_message_count;
-extern int error_one_per_line;
+void error(int, int, const char* _Nonnull, ...) __printflike(3, 4) __INTRODUCED_IN(23);
+void error_at_line(int, int, const char* _Nullable, unsigned int, const char* _Nonnull, ...)
+    __printflike(5, 6) __INTRODUCED_IN(23);
 
 __END_DECLS
 
diff --git a/libc/include/fcntl.h b/libc/include/fcntl.h
index 6e2ad51..872a727 100644
--- a/libc/include/fcntl.h
+++ b/libc/include/fcntl.h
@@ -36,6 +36,8 @@
 #include <linux/stat.h>
 #include <linux/uio.h>
 
+#include <bits/fcntl.h>
+
 #if defined(__USE_GNU) || defined(__USE_BSD)
 #include <bits/lockf.h>
 #endif
@@ -61,35 +63,38 @@
 #define SYNC_FILE_RANGE_WRITE 2
 #define SYNC_FILE_RANGE_WAIT_AFTER 4
 
-extern int creat(const char*, mode_t);
-extern int creat64(const char*, mode_t);
-extern int fcntl(int, int, ...);
-extern int openat(int, const char*, int, ...);
-extern int openat64(int, const char*, int, ...);
-extern int open(const char*, int, ...);
-extern int open64(const char*, int, ...);
-extern ssize_t splice(int, off64_t*, int, off64_t*, size_t, unsigned int);
-extern ssize_t tee(int, int, size_t, unsigned int);
-extern int unlinkat(int, const char*, int);
-extern ssize_t vmsplice(int, const struct iovec*, size_t, unsigned int);
+int creat(const char*, mode_t);
+int creat64(const char*, mode_t) __INTRODUCED_IN(21);
+int openat(int, const char*, int, ...);
+int openat64(int, const char*, int, ...) __INTRODUCED_IN(21);
+int open(const char*, int, ...);
+int open64(const char*, int, ...) __INTRODUCED_IN(21);
+ssize_t splice(int, off64_t*, int, off64_t*, size_t, unsigned int) __INTRODUCED_IN(21);
+ssize_t tee(int, int, size_t, unsigned int) __INTRODUCED_IN(21);
+ssize_t vmsplice(int, const struct iovec*, size_t, unsigned int) __INTRODUCED_IN(21);
 
 #if defined(__USE_FILE_OFFSET64)
-extern int fallocate(int, int, off_t, off_t) __RENAME(fallocate64);
-extern int posix_fadvise(int, off_t, off_t, int) __RENAME(posix_fadvise64);
-extern int posix_fallocate(int, off_t, off_t) __RENAME(posix_fallocate);
+int fallocate(int, int, off_t, off_t) __RENAME(fallocate64) __INTRODUCED_IN(21);
+int posix_fadvise(int, off_t, off_t, int) __RENAME(posix_fadvise64) __INTRODUCED_IN(21);
+int posix_fallocate(int, off_t, off_t) __RENAME(posix_fallocate) __INTRODUCED_IN(21);
 #else
-extern int fallocate(int, int, off_t, off_t);
-extern int posix_fadvise(int, off_t, off_t, int);
-extern int posix_fallocate(int, off_t, off_t);
+int fallocate(int, int, off_t, off_t) __INTRODUCED_IN(21);
+int posix_fadvise(int, off_t, off_t, int) __INTRODUCED_IN(21);
+int posix_fallocate(int, off_t, off_t) __INTRODUCED_IN(21);
 #endif
-extern int fallocate64(int, int, off64_t, off64_t);
-extern int posix_fadvise64(int, off64_t, off64_t, int);
-extern int posix_fallocate64(int, off64_t, off64_t);
+int fallocate64(int, int, off64_t, off64_t) __INTRODUCED_IN(21);
+int posix_fadvise64(int, off64_t, off64_t, int) __INTRODUCED_IN(21);
+int posix_fallocate64(int, off64_t, off64_t) __INTRODUCED_IN(21);
 
-extern int __open_2(const char*, int);
-extern int __open_real(const char*, int, ...) __RENAME(open);
-extern int __openat_2(int, const char*, int);
-extern int __openat_real(int, const char*, int, ...) __RENAME(openat);
+#if defined(__USE_GNU)
+ssize_t readahead(int, off64_t, size_t) __INTRODUCED_IN(16);
+int sync_file_range(int, off64_t, off64_t, unsigned int) __INTRODUCED_IN_FUTURE;
+#endif
+
+int __open_2(const char*, int) __INTRODUCED_IN(17);
+int __open_real(const char*, int, ...) __RENAME(open);
+int __openat_2(int, const char*, int) __INTRODUCED_IN(17);
+int __openat_real(int, const char*, int, ...) __RENAME(openat);
 __errordecl(__creat_missing_mode, "called with O_CREAT, but missing mode");
 __errordecl(__creat_too_many_args, "too many arguments");
 
@@ -101,12 +106,12 @@
 int open(const char* pathname, int flags, ...) {
     if (__builtin_constant_p(flags)) {
         if ((flags & O_CREAT) && __builtin_va_arg_pack_len() == 0) {
-            __creat_missing_mode();  // compile time error
+            __creat_missing_mode();  /* Compile time error. */
         }
     }
 
     if (__builtin_va_arg_pack_len() > 1) {
-        __creat_too_many_args();  // compile time error
+        __creat_too_many_args();  /* Compile time error. */
     }
 
     if ((__builtin_va_arg_pack_len() == 0) && !__builtin_constant_p(flags)) {
@@ -120,12 +125,12 @@
 int openat(int dirfd, const char* pathname, int flags, ...) {
     if (__builtin_constant_p(flags)) {
         if ((flags & O_CREAT) && __builtin_va_arg_pack_len() == 0) {
-            __creat_missing_mode();  // compile time error
+            __creat_missing_mode();  /* Compile time error. */
         }
     }
 
     if (__builtin_va_arg_pack_len() > 1) {
-        __creat_too_many_args();  // compile time error
+        __creat_too_many_args();  /* Compile time error. */
     }
 
     if ((__builtin_va_arg_pack_len() == 0) && !__builtin_constant_p(flags)) {
diff --git a/libc/include/fenv.h b/libc/include/fenv.h
new file mode 100644
index 0000000..f1b2b25
--- /dev/null
+++ b/libc/include/fenv.h
@@ -0,0 +1,73 @@
+/*  $OpenBSD: fenv.h,v 1.2 2011/05/25 21:46:49 martynas Exp $ */
+/*  $NetBSD: fenv.h,v 1.2.4.1 2011/02/08 16:18:55 bouyer Exp $  */
+
+/*
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+#ifndef _FENV_H_
+#define _FENV_H_
+
+#include <sys/cdefs.h>
+#include <machine/fenv.h>
+
+__BEGIN_DECLS
+
+// fenv was always available on x86.
+int feclearexcept(int) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_MIPS(21) __INTRODUCED_IN_X86(9);
+int fegetexceptflag(fexcept_t*, int) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_MIPS(21)
+    __INTRODUCED_IN_X86(9);
+int feraiseexcept(int) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_MIPS(21) __INTRODUCED_IN_X86(9);
+int fesetexceptflag(const fexcept_t*, int) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_MIPS(21)
+    __INTRODUCED_IN_X86(9);
+int fetestexcept(int) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_MIPS(21) __INTRODUCED_IN_X86(9);
+
+int fegetround(void) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_MIPS(21) __INTRODUCED_IN_X86(9);
+int fesetround(int) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_MIPS(21) __INTRODUCED_IN_X86(9);
+
+int fegetenv(fenv_t*) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_MIPS(21) __INTRODUCED_IN_X86(9);
+int feholdexcept(fenv_t*) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_MIPS(21) __INTRODUCED_IN_X86(9);
+int fesetenv(const fenv_t*) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_MIPS(21) __INTRODUCED_IN_X86(9);
+int feupdateenv(const fenv_t*) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_MIPS(21)
+    __INTRODUCED_IN_X86(9);
+
+int feenableexcept(int) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_MIPS(21) __INTRODUCED_IN_X86(9);
+int fedisableexcept(int) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_MIPS(21) __INTRODUCED_IN_X86(9);
+int fegetexcept(void) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_MIPS(21) __INTRODUCED_IN_X86(9);
+
+/*
+ * The following constant represents the default floating-point environment
+ * (that is, the one installed at program startup) and has type pointer to
+ * const-qualified fenv_t.
+ *
+ * It can be used as an argument to the functions that manage the floating-point
+ * environment, namely fesetenv() and feupdateenv().
+ */
+extern const fenv_t __fe_dfl_env;
+#define FE_DFL_ENV  (&__fe_dfl_env)
+
+__END_DECLS
+
+#endif  /* ! _FENV_H_ */
diff --git a/libc/include/fnmatch.h b/libc/include/fnmatch.h
index 772b4ef..1a5348b 100644
--- a/libc/include/fnmatch.h
+++ b/libc/include/fnmatch.h
@@ -44,9 +44,8 @@
 #define FNM_IGNORECASE   FNM_CASEFOLD
 #define FNM_FILE_NAME    FNM_PATHNAME
 
-extern int  fnmatch(const char *pattern, const char *string, int flags);
+int fnmatch(const char* pattern, const char* string, int flags);
 
 __END_DECLS
 
 #endif /* _FNMATCH_H */
-
diff --git a/libc/include/fts.h b/libc/include/fts.h
index cde0349..b46c19c 100644
--- a/libc/include/fts.h
+++ b/libc/include/fts.h
@@ -35,6 +35,7 @@
 #ifndef	_FTS_H_
 #define	_FTS_H_
 
+#include <sys/cdefs.h>
 #include <sys/types.h>
 
 typedef struct {
diff --git a/libc/include/ftw.h b/libc/include/ftw.h
index af524d0..cb8ae7d 100644
--- a/libc/include/ftw.h
+++ b/libc/include/ftw.h
@@ -25,8 +25,9 @@
 #ifndef	_FTW_H
 #define	_FTW_H
 
-#include <sys/types.h>
+#include <sys/cdefs.h>
 #include <sys/stat.h>
+#include <sys/types.h>
 
 /*
  * Valid flags for the 3rd argument to the function that is passed as the
@@ -54,12 +55,12 @@
 };
 
 __BEGIN_DECLS
-int	ftw(const char *, int (*)(const char *, const struct stat *, int), int);
-int	nftw(const char *, int (*)(const char *, const struct stat *, int,
-	    struct FTW *), int, int);
-int	ftw64(const char *, int (*)(const char *, const struct stat64 *, int), int);
-int	nftw64(const char *, int (*)(const char *, const struct stat64 *, int,
-	    struct FTW *), int, int);
+int ftw(const char*, int (*)(const char*, const struct stat*, int), int) __INTRODUCED_IN(17);
+int nftw(const char*, int (*)(const char*, const struct stat*, int, struct FTW*), int, int)
+  __INTRODUCED_IN(17);
+int ftw64(const char*, int (*)(const char*, const struct stat64*, int), int) __INTRODUCED_IN(21);
+int nftw64(const char*, int (*)(const char*, const struct stat64*, int, struct FTW*), int, int)
+  __INTRODUCED_IN(21);
 __END_DECLS
 
 #endif	/* !_FTW_H */
diff --git a/libc/include/getopt.h b/libc/include/getopt.h
index 4451941..46d2eb7 100644
--- a/libc/include/getopt.h
+++ b/libc/include/getopt.h
@@ -35,9 +35,10 @@
 
 #include <sys/cdefs.h>
 
+#include <bits/getopt.h>
+
 /*
  * GNU-like getopt_long()/getopt_long_only() with 4.4BSD optreset extension.
- * getopt() is declared here too for GNU programs.
  */
 #define no_argument        0
 #define required_argument  1
@@ -62,13 +63,7 @@
 	const struct option *, int *);
 int	getopt_long_only(int, char * const *, const char *,
 	const struct option *, int *);
-#ifndef _GETOPT_DECLARED
-#define	_GETOPT_DECLARED
-int	 getopt(int, char * const [], const char *);
 
-extern char *optarg;			/* getopt(3) external variables */
-extern int optind, opterr, optopt;
-#endif
 #ifndef _OPTRESET_DECLARED
 #define	_OPTRESET_DECLARED
 extern int optreset;			/* getopt(3) external variable */
diff --git a/libc/include/grp.h b/libc/include/grp.h
index df7a613..1d38265 100644
--- a/libc/include/grp.h
+++ b/libc/include/grp.h
@@ -1,9 +1,6 @@
-/*	$OpenBSD: grp.h,v 1.8 2005/12/13 00:35:22 millert Exp $	*/
-/*	$NetBSD: grp.h,v 1.7 1995/04/29 05:30:40 cgd Exp $	*/
-
 /*-
  * Copyright (c) 1989, 1993
- *	The Regents of the University of California.  All rights reserved.
+ *    The Regents of the University of California.  All rights reserved.
  * (c) UNIX System Laboratories, Inc.
  * All or some portions of this file are derived from material licensed
  * to the University of California by American Telephone and Telegraph
@@ -33,40 +30,35 @@
  * 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.
- *
- *	@(#)grp.h	8.2 (Berkeley) 1/21/94
  */
 
 #ifndef _GRP_H_
-#define	_GRP_H_
+#define _GRP_H_
 
 #include <sys/cdefs.h>
 #include <sys/types.h>
 
 struct group {
-	char	*gr_name;		/* group name */
-	char	*gr_passwd;		/* group password */
-	gid_t	gr_gid;			/* group id */
-	char	**gr_mem;		/* group members */
+  char* gr_name; /* group name */
+  char* gr_passwd; /* group password */
+  gid_t gr_gid; /* group id */
+  char** gr_mem; /* group members */
 };
 
 __BEGIN_DECLS
-struct group	*getgrgid(gid_t);
-struct group	*getgrnam(const char *);
-#if __POSIX_VISIBLE >= 200112 || __XPG_VISIBLE
-struct group	*getgrent(void)  __attribute__((deprecated("getgrent is meaningless on Android")));
-void setgrent(void) __attribute__((deprecated("setgrent is meaningless on Android")));
-void endgrent(void) __attribute__((deprecated("endgrent is meaningless on Android")));
-int		 getgrgid_r(gid_t, struct group *, char *,
-		    size_t, struct group **);
-int		 getgrnam_r(const char *, struct group *, char *,
-		    size_t, struct group **);
-#endif
 
-int   getgrouplist (const char *user, gid_t group,
-                  gid_t *groups, int *ngroups);
+struct group* getgrgid(gid_t);
+struct group* getgrnam(const char*);
 
-int   initgroups (const char *user, gid_t group);
+/* Note: Android has thousands and thousands of ids to iterate through. */
+struct group* getgrent(void) __INTRODUCED_IN_FUTURE;
+
+void setgrent(void) __INTRODUCED_IN_FUTURE;
+void endgrent(void) __INTRODUCED_IN_FUTURE;
+int getgrgid_r(gid_t, struct group*, char*, size_t, struct group**) __INTRODUCED_IN(24);
+int getgrnam_r(const char*, struct group*, char*, size_t, struct group**) __INTRODUCED_IN(24);
+int getgrouplist (const char*, gid_t, gid_t*, int*);
+int initgroups (const char*, gid_t);
 
 __END_DECLS
 
diff --git a/libc/include/ifaddrs.h b/libc/include/ifaddrs.h
index 54a5a2c..083b27a 100644
--- a/libc/include/ifaddrs.h
+++ b/libc/include/ifaddrs.h
@@ -51,8 +51,8 @@
 #define ifa_broadaddr ifa_ifu.ifu_broadaddr
 #define ifa_dstaddr ifa_ifu.ifu_dstaddr
 
-void freeifaddrs(struct ifaddrs*);
-int getifaddrs(struct ifaddrs**);
+void freeifaddrs(struct ifaddrs*) __INTRODUCED_IN(24);
+int getifaddrs(struct ifaddrs**) __INTRODUCED_IN(24);
 
 __END_DECLS
 
diff --git a/libc/include/inttypes.h b/libc/include/inttypes.h
index 8853c08..54b5ee2 100644
--- a/libc/include/inttypes.h
+++ b/libc/include/inttypes.h
@@ -254,14 +254,12 @@
 } imaxdiv_t;
 
 __BEGIN_DECLS
-intmax_t	imaxabs(intmax_t) __pure2;
-imaxdiv_t	imaxdiv(intmax_t, intmax_t) __pure2;
+intmax_t imaxabs(intmax_t) __pure2 __INTRODUCED_IN(19);
+imaxdiv_t imaxdiv(intmax_t, intmax_t) __pure2 __INTRODUCED_IN(19);
 intmax_t	strtoimax(const char *, char **, int);
 uintmax_t	strtoumax(const char *, char **, int);
-intmax_t	wcstoimax(const wchar_t * __restrict,
-		    wchar_t ** __restrict, int);
-uintmax_t	wcstoumax(const wchar_t * __restrict,
-		    wchar_t ** __restrict, int);
+intmax_t wcstoimax(const wchar_t* __restrict, wchar_t** __restrict, int) __INTRODUCED_IN(21);
+uintmax_t wcstoumax(const wchar_t* __restrict, wchar_t** __restrict, int) __INTRODUCED_IN(21);
 __END_DECLS
 
 #endif /* _INTTYPES_H_ */
diff --git a/libc/include/lastlog.h b/libc/include/lastlog.h
index e69de29..4f46106 100644
--- a/libc/include/lastlog.h
+++ b/libc/include/lastlog.h
@@ -0,0 +1,2 @@
+/* This is a BSD synonym for <utmp.h> that's also provided by glibc. */
+#include <utmp.h>
diff --git a/libc/include/libgen.h b/libc/include/libgen.h
index 4d22d15..f864ee1 100644
--- a/libc/include/libgen.h
+++ b/libc/include/libgen.h
@@ -42,17 +42,17 @@
  * Note that this has the wrong argument cv-qualifiers, but doesn't modify its
  * input and uses thread-local storage for the result if necessary.
  */
-extern char* __posix_basename(const char*) __RENAME(basename);
+char* __posix_basename(const char*) __RENAME(basename);
 
 #define basename __posix_basename
 
 /* This has the wrong argument cv-qualifiers, but doesn't modify its input and uses thread-local storage for the result if necessary. */
-extern char* dirname(const char*);
+char* dirname(const char*);
 
 #if !defined(__LP64__)
 /* These non-standard functions are not needed on Android; basename and dirname use thread-local storage. */
-extern int dirname_r(const char*, char*, size_t);
-extern int basename_r(const char*, char*, size_t);
+int dirname_r(const char*, char*, size_t);
+int basename_r(const char*, char*, size_t);
 #endif
 
 __END_DECLS
diff --git a/libc/include/limits.h b/libc/include/limits.h
index 342217b..a1124b3 100644
--- a/libc/include/limits.h
+++ b/libc/include/limits.h
@@ -37,7 +37,6 @@
 
 #include <sys/cdefs.h>
 
-#if __XPG_VISIBLE
 #define PASS_MAX		128	/* _PASSWORD_LEN from <pwd.h> */
 
 #define NL_ARGMAX		9
@@ -48,14 +47,9 @@
 #define NL_TEXTMAX		255
 
 #define TMP_MAX                 308915776
-#endif /* __XPG_VISIBLE */
 
 #include <sys/limits.h>
 
-#if __POSIX_VISIBLE
-#include <sys/syslimits.h>
-#endif
-
 /* GLibc compatibility definitions.
    Note that these are defined by GCC's <limits.h>
    only when __GNU_LIBRARY__ is defined, i.e. when
@@ -72,15 +66,23 @@
 #define ULONG_LONG_MAX  ULLONG_MAX
 #endif
 
-/* BSD compatibility definitions. */
-#if __BSD_VISIBLE
+#if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
+#if defined(__LP64__)
 #define SIZE_T_MAX ULONG_MAX
-#endif /* __BSD_VISIBLE */
+#else
+#define SIZE_T_MAX UINT_MAX
+#endif
+#endif
 
+#if defined(__LP64__)
 #define SSIZE_MAX LONG_MAX
+#else
+#define SSIZE_MAX INT_MAX
+#endif
 
 #define MB_LEN_MAX 4
 
+#define IOV_MAX 1024
 #define SEM_VALUE_MAX 0x3fffffff
 
 /* POSIX says these belong in <unistd.h> but BSD has some in <limits.h>. */
diff --git a/libc/include/link.h b/libc/include/link.h
index cb8e139..f40e7e4 100644
--- a/libc/include/link.h
+++ b/libc/include/link.h
@@ -28,8 +28,9 @@
 #ifndef _LINK_H_
 #define _LINK_H_
 
-#include <sys/types.h>
 #include <elf.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
 
 __BEGIN_DECLS
 
@@ -46,7 +47,11 @@
   ElfW(Half) dlpi_phnum;
 };
 
+#if defined(__arm__)
+int dl_iterate_phdr(int (*)(struct dl_phdr_info*, size_t, void*), void*) __INTRODUCED_IN(21);
+#else
 int dl_iterate_phdr(int (*)(struct dl_phdr_info*, size_t, void*), void*);
+#endif
 
 #ifdef __arm__
 typedef long unsigned int* _Unwind_Ptr;
diff --git a/libc/include/locale.h b/libc/include/locale.h
index 7fd8c2c..a8f03bc 100644
--- a/libc/include/locale.h
+++ b/libc/include/locale.h
@@ -25,6 +25,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #ifndef _LOCALE_H_
 #define _LOCALE_H_
 
@@ -66,41 +67,41 @@
                      LC_IDENTIFICATION_MASK)
 
 struct lconv {
-    char* decimal_point;
-    char* thousands_sep;
-    char* grouping;
-    char* int_curr_symbol;
-    char* currency_symbol;
-    char* mon_decimal_point;
-    char* mon_thousands_sep;
-    char* mon_grouping;
-    char* positive_sign;
-    char* negative_sign;
-    char  int_frac_digits;
-    char  frac_digits;
-    char  p_cs_precedes;
-    char  p_sep_by_space;
-    char  n_cs_precedes;
-    char  n_sep_by_space;
-    char  p_sign_posn;
-    char  n_sign_posn;
-    char  int_p_cs_precedes;
-    char  int_p_sep_by_space;
-    char  int_n_cs_precedes;
-    char  int_n_sep_by_space;
-    char  int_p_sign_posn;
-    char  int_n_sign_posn;
+  char* decimal_point;
+  char* thousands_sep;
+  char* grouping;
+  char* int_curr_symbol;
+  char* currency_symbol;
+  char* mon_decimal_point;
+  char* mon_thousands_sep;
+  char* mon_grouping;
+  char* positive_sign;
+  char* negative_sign;
+  char int_frac_digits;
+  char frac_digits;
+  char p_cs_precedes;
+  char p_sep_by_space;
+  char n_cs_precedes;
+  char n_sep_by_space;
+  char p_sign_posn;
+  char n_sign_posn;
+  char int_p_cs_precedes;
+  char int_p_sep_by_space;
+  char int_n_cs_precedes;
+  char int_n_sep_by_space;
+  char int_p_sign_posn;
+  char int_n_sign_posn;
 };
 
-struct lconv* localeconv(void);
+struct lconv* localeconv(void) __INTRODUCED_IN(21);
 
-locale_t duplocale(locale_t);
-void freelocale(locale_t);
-locale_t newlocale(int, const char*, locale_t);
+locale_t duplocale(locale_t) __INTRODUCED_IN(21);
+void freelocale(locale_t) __INTRODUCED_IN(21);
+locale_t newlocale(int, const char*, locale_t) __INTRODUCED_IN(21);
 char* setlocale(int, const char*);
-locale_t uselocale(locale_t);
+locale_t uselocale(locale_t) __INTRODUCED_IN(21);
 
-#define LC_GLOBAL_LOCALE ((locale_t) -1L)
+#define LC_GLOBAL_LOCALE __BIONIC_CAST(reinterpret_cast, locale_t, -1L)
 
 __END_DECLS
 
diff --git a/libc/include/malloc.h b/libc/include/malloc.h
index 87555a9..7452e53 100644
--- a/libc/include/malloc.h
+++ b/libc/include/malloc.h
@@ -23,13 +23,19 @@
 
 __BEGIN_DECLS
 
-extern void* malloc(size_t byte_count) __mallocfunc __wur __attribute__((alloc_size(1)));
-extern void* calloc(size_t item_count, size_t item_size) __mallocfunc __wur __attribute__((alloc_size(1,2)));
-extern void* realloc(void* p, size_t byte_count) __wur __attribute__((alloc_size(2)));
-extern void free(void* p);
+#if defined(__clang__)
+#define __BIONIC_ALLOC_SIZE(...) /* clang doesn't support attribute alloc_size. */
+#else
+#define __BIONIC_ALLOC_SIZE(...) __attribute__((__alloc_size__(__VA_ARGS__)))
+#endif
 
-extern void* memalign(size_t alignment, size_t byte_count) __mallocfunc __wur __attribute__((alloc_size(2)));
-extern size_t malloc_usable_size(const void* p);
+void* malloc(size_t byte_count) __mallocfunc __BIONIC_ALLOC_SIZE(1) __wur;
+void* calloc(size_t item_count, size_t item_size) __mallocfunc __BIONIC_ALLOC_SIZE(1,2) __wur;
+void* realloc(void* p, size_t byte_count) __BIONIC_ALLOC_SIZE(2) __wur;
+void free(void* p);
+
+void* memalign(size_t alignment, size_t byte_count) __mallocfunc __BIONIC_ALLOC_SIZE(2) __wur;
+size_t malloc_usable_size(const void* p) __INTRODUCED_IN(17);
 
 #ifndef STRUCT_MALLINFO_DECLARED
 #define STRUCT_MALLINFO_DECLARED 1
@@ -47,7 +53,7 @@
 };
 #endif  /* STRUCT_MALLINFO_DECLARED */
 
-extern struct mallinfo mallinfo(void);
+struct mallinfo mallinfo(void);
 
 /*
  * XML structure for malloc_info(3) is in the following format:
@@ -68,7 +74,7 @@
  *   <!-- more heaps -->
  * </malloc>
  */
-extern int malloc_info(int, FILE *);
+int malloc_info(int, FILE*) __INTRODUCED_IN(23);
 
 __END_DECLS
 
diff --git a/libc/include/math.h b/libc/include/math.h
new file mode 100644
index 0000000..1afef4c
--- /dev/null
+++ b/libc/include/math.h
@@ -0,0 +1,370 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/*
+ * from: @(#)fdlibm.h 5.1 93/09/24
+ * $FreeBSD$
+ */
+
+#ifndef _MATH_H_
+#define _MATH_H_
+
+#include <sys/cdefs.h>
+#include <limits.h>
+
+__BEGIN_DECLS
+
+#define HUGE_VAL	__builtin_huge_val()
+
+#define FP_ILOGB0	(-INT_MAX)
+#define FP_ILOGBNAN	INT_MAX
+
+#define HUGE_VALF	__builtin_huge_valf()
+#define HUGE_VALL	__builtin_huge_vall()
+#define INFINITY	__builtin_inff()
+#define NAN		__builtin_nanf("")
+
+#define MATH_ERRNO	1
+#define MATH_ERREXCEPT	2
+#define math_errhandling	MATH_ERREXCEPT
+
+#if defined(__FP_FAST_FMA)
+#define FP_FAST_FMA 1
+#endif
+#if defined(__FP_FAST_FMAF)
+#define FP_FAST_FMAF 1
+#endif
+#if defined(__FP_FAST_FMAL)
+#define FP_FAST_FMAL 1
+#endif
+
+/* Symbolic constants to classify floating point numbers. */
+#define FP_INFINITE	0x01
+#define FP_NAN		0x02
+#define FP_NORMAL	0x04
+#define FP_SUBNORMAL	0x08
+#define FP_ZERO		0x10
+#define fpclassify(x) \
+    __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)
+
+#define isfinite(x) __builtin_isfinite(x)
+#define isinf(x) __builtin_isinf(x)
+#define isnan(x) __builtin_isnan(x)
+#define isnormal(x) __builtin_isnormal(x)
+
+#define isgreater(x, y) __builtin_isgreater((x), (y))
+#define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y))
+#define isless(x, y) __builtin_isless((x), (y))
+#define islessequal(x, y) __builtin_islessequal((x), (y))
+#define islessgreater(x, y) __builtin_islessgreater((x), (y))
+#define isunordered(x, y) __builtin_isunordered((x), (y))
+
+#define signbit(x) \
+    ((sizeof(x) == sizeof(float)) ? __builtin_signbitf(x) \
+    : (sizeof(x) == sizeof(double)) ? __builtin_signbit(x) \
+    : __builtin_signbitl(x))
+
+typedef double __double_t;
+typedef __double_t double_t;
+typedef float __float_t;
+typedef __float_t float_t;
+
+#if defined(__USE_BSD)
+#define HUGE MAXFLOAT
+#endif
+
+/*
+ * Most of these functions depend on the rounding mode and have the side
+ * effect of raising floating-point exceptions, so they are not declared
+ * as __pure2.  In C99, FENV_ACCESS affects the purity of these functions.
+ */
+
+int __fpclassifyd(double) __pure2;
+int __fpclassifyf(float) __pure2;
+int __fpclassifyl(long double) __pure2;
+int __isfinitef(float) __pure2;
+int __isfinite(double) __pure2;
+int __isfinitel(long double) __pure2;
+int __isinff(float) __pure2;
+int __isinfl(long double) __pure2;
+int __isnanf(float) __pure2 __INTRODUCED_IN(21);
+int __isnanl(long double) __pure2;
+int __isnormalf(float) __pure2;
+int __isnormal(double) __pure2;
+int __isnormall(long double) __pure2;
+int __signbit(double) __pure2;
+int __signbitf(float) __pure2;
+int __signbitl(long double) __pure2;
+
+double	acos(double);
+double	asin(double);
+double	atan(double);
+double	atan2(double, double);
+double	cos(double);
+double	sin(double);
+double	tan(double);
+
+double	cosh(double);
+double	sinh(double);
+double	tanh(double);
+
+double	exp(double);
+double	frexp(double, int *);	/* fundamentally !__pure2 */
+double	ldexp(double, int);
+double	log(double);
+double	log10(double);
+double	modf(double, double *);	/* fundamentally !__pure2 */
+
+double	pow(double, double);
+double	sqrt(double);
+
+double	ceil(double);
+double	fabs(double) __pure2;
+double	floor(double);
+double	fmod(double, double);
+
+double	acosh(double);
+double	asinh(double);
+double	atanh(double);
+double	cbrt(double);
+double	erf(double);
+double	erfc(double);
+double	exp2(double);
+double	expm1(double);
+double	fma(double, double, double);
+double	hypot(double, double);
+int	ilogb(double) __pure2;
+int(isinf)(double) __pure2 __INTRODUCED_IN(21);
+int	(isnan)(double) __pure2;
+double	lgamma(double);
+long long llrint(double);
+long long llround(double);
+double	log1p(double);
+double log2(double) __INTRODUCED_IN(18);
+double	logb(double);
+long	lrint(double);
+long	lround(double);
+
+double nan(const char*) __pure2 __INTRODUCED_IN_ARM(13) __INTRODUCED_IN_MIPS(13)
+    __INTRODUCED_IN_X86(9);
+
+double	nextafter(double, double);
+double	remainder(double, double);
+double	remquo(double, double, int*);
+double	rint(double);
+
+double	copysign(double, double) __pure2;
+double	fdim(double, double);
+double	fmax(double, double) __pure2;
+double	fmin(double, double) __pure2;
+double	nearbyint(double);
+double	round(double);
+double scalbln(double, long) __INTRODUCED_IN_X86(18);
+double scalbn(double, int);
+double	tgamma(double);
+double	trunc(double);
+
+float	acosf(float);
+float	asinf(float);
+float	atanf(float);
+float	atan2f(float, float);
+float	cosf(float);
+float	sinf(float);
+float	tanf(float);
+
+float	coshf(float);
+float	sinhf(float);
+float	tanhf(float);
+
+float	exp2f(float);
+float	expf(float);
+float	expm1f(float);
+float	frexpf(float, int *);	/* fundamentally !__pure2 */
+int	ilogbf(float) __pure2;
+float	ldexpf(float, int);
+float	log10f(float);
+float	log1pf(float);
+float log2f(float) __INTRODUCED_IN(18);
+float	logf(float);
+float	modff(float, float *);	/* fundamentally !__pure2 */
+
+float	powf(float, float);
+float	sqrtf(float);
+
+float	ceilf(float);
+float	fabsf(float) __pure2;
+float	floorf(float);
+float	fmodf(float, float);
+float	roundf(float);
+
+float	erff(float);
+float	erfcf(float);
+float	hypotf(float, float);
+float	lgammaf(float);
+float tgammaf(float) __INTRODUCED_IN_ARM(13) __INTRODUCED_IN_MIPS(13) __INTRODUCED_IN_X86(9);
+
+float	acoshf(float);
+float	asinhf(float);
+float	atanhf(float);
+float	cbrtf(float);
+float	logbf(float);
+float	copysignf(float, float) __pure2;
+long long llrintf(float);
+long long llroundf(float);
+long	lrintf(float);
+long	lroundf(float);
+float nanf(const char*) __pure2 __INTRODUCED_IN_ARM(13) __INTRODUCED_IN_MIPS(13)
+    __INTRODUCED_IN_X86(9);
+float	nearbyintf(float);
+float	nextafterf(float, float);
+float	remainderf(float, float);
+float	remquof(float, float, int *);
+float	rintf(float);
+float	scalblnf(float, long) __INTRODUCED_IN_X86(18);
+float scalbnf(float, int);
+float	truncf(float);
+
+float	fdimf(float, float);
+float	fmaf(float, float, float);
+float	fmaxf(float, float) __pure2;
+float	fminf(float, float) __pure2;
+
+long double acoshl(long double) __INTRODUCED_IN(21);
+long double acosl(long double) __INTRODUCED_IN(21);
+long double asinhl(long double) __INTRODUCED_IN(21);
+long double asinl(long double) __INTRODUCED_IN(21);
+long double atan2l(long double, long double) __INTRODUCED_IN(21);
+long double atanhl(long double) __INTRODUCED_IN(21);
+long double atanl(long double) __INTRODUCED_IN(21);
+long double cbrtl(long double) __INTRODUCED_IN(21);
+long double ceill(long double);
+long double copysignl(long double, long double) __pure2;
+long double coshl(long double) __INTRODUCED_IN(21);
+long double cosl(long double) __INTRODUCED_IN(21);
+long double erfcl(long double) __INTRODUCED_IN(21);
+long double erfl(long double) __INTRODUCED_IN(21);
+long double exp2l(long double) __INTRODUCED_IN(21);
+long double expl(long double) __INTRODUCED_IN(21);
+long double expm1l(long double) __INTRODUCED_IN(21);
+long double fabsl(long double) __pure2;
+long double fdiml(long double, long double);
+long double floorl(long double);
+long double fmal(long double, long double, long double) __INTRODUCED_IN(21);
+long double fmaxl(long double, long double) __pure2;
+long double fminl(long double, long double) __pure2;
+long double fmodl(long double, long double) __INTRODUCED_IN(21);
+long double frexpl(long double value, int*) __INTRODUCED_IN(21); /* fundamentally !__pure2 */
+long double hypotl(long double, long double) __INTRODUCED_IN(21);
+int ilogbl(long double) __pure2;
+long double ldexpl(long double, int);
+long double lgammal(long double) __INTRODUCED_IN(21);
+long long llrintl(long double) __INTRODUCED_IN(21);
+long long llroundl(long double);
+long double log10l(long double) __INTRODUCED_IN(21);
+long double log1pl(long double) __INTRODUCED_IN(21);
+long double log2l(long double) __INTRODUCED_IN(18);
+long double logbl(long double) __INTRODUCED_IN(18);
+long double logl(long double) __INTRODUCED_IN(21);
+long lrintl(long double) __INTRODUCED_IN(21);
+long lroundl(long double);
+long double modfl(long double, long double*) __INTRODUCED_IN(21); /* fundamentally !__pure2 */
+long double nanl(const char*) __pure2 __INTRODUCED_IN(13);
+long double nearbyintl(long double) __INTRODUCED_IN(21);
+long double nextafterl(long double, long double) __INTRODUCED_IN(21);
+double nexttoward(double, long double) __INTRODUCED_IN(18);
+float nexttowardf(float, long double);
+long double nexttowardl(long double, long double) __INTRODUCED_IN(18);
+long double powl(long double, long double) __INTRODUCED_IN(21);
+long double remainderl(long double, long double) __INTRODUCED_IN(21);
+long double remquol(long double, long double, int*) __INTRODUCED_IN(21);
+long double rintl(long double) __INTRODUCED_IN(21);
+long double roundl(long double);
+long double scalblnl(long double, long) __INTRODUCED_IN_X86(18);
+long double scalbnl(long double, int);
+long double sinhl(long double) __INTRODUCED_IN(21);
+long double sinl(long double) __INTRODUCED_IN(21);
+long double sqrtl(long double) __INTRODUCED_IN(21);
+long double tanhl(long double) __INTRODUCED_IN(21);
+long double tanl(long double) __INTRODUCED_IN(21);
+long double tgammal(long double) __INTRODUCED_IN(21);
+long double truncl(long double);
+
+#define M_E		2.7182818284590452354	/* e */
+#define M_LOG2E		1.4426950408889634074	/* log 2e */
+#define M_LOG10E	0.43429448190325182765	/* log 10e */
+#define M_LN2		0.69314718055994530942	/* log e2 */
+#define M_LN10		2.30258509299404568402	/* log e10 */
+#define M_PI		3.14159265358979323846	/* pi */
+#define M_PI_2		1.57079632679489661923	/* pi/2 */
+#define M_PI_4		0.78539816339744830962	/* pi/4 */
+#define M_1_PI		0.31830988618379067154	/* 1/pi */
+#define M_2_PI		0.63661977236758134308	/* 2/pi */
+#define M_2_SQRTPI	1.12837916709551257390	/* 2/sqrt(pi) */
+#define M_SQRT2		1.41421356237309504880	/* sqrt(2) */
+#define M_SQRT1_2	0.70710678118654752440	/* 1/sqrt(2) */
+
+#define MAXFLOAT	((float)3.40282346638528860e+38)
+
+#if defined(__USE_BSD) || defined(__USE_GNU)
+extern int signgam;
+double j0(double);
+double j1(double);
+double jn(int, double);
+double y0(double);
+double y1(double);
+double yn(int, double);
+double gamma(double);
+double scalb(double, double);
+double drem(double, double);
+int finite(double) __pure2;
+int isnanf(float) __pure2;
+double gamma_r(double, int*);
+double lgamma_r(double, int*);
+double significand(double);
+long double lgammal_r(long double, int*) __INTRODUCED_IN(23);
+long double significandl(long double) __INTRODUCED_IN(21);
+float dremf(float, float);
+int finitef(float) __pure2;
+float gammaf(float);
+float j0f(float);
+float j1f(float);
+float jnf(int, float);
+float scalbf(float, float);
+float y0f(float);
+float y1f(float);
+float ynf(int, float);
+float gammaf_r(float, int *);
+float lgammaf_r(float, int *);
+float significandf(float);
+#endif
+
+#if defined(__USE_GNU)
+#define M_El            2.718281828459045235360287471352662498L /* e */
+#define M_LOG2El        1.442695040888963407359924681001892137L /* log 2e */
+#define M_LOG10El       0.434294481903251827651128918916605082L /* log 10e */
+#define M_LN2l          0.693147180559945309417232121458176568L /* log e2 */
+#define M_LN10l         2.302585092994045684017991454684364208L /* log e10 */
+#define M_PIl           3.141592653589793238462643383279502884L /* pi */
+#define M_PI_2l         1.570796326794896619231321691639751442L /* pi/2 */
+#define M_PI_4l         0.785398163397448309615660845819875721L /* pi/4 */
+#define M_1_PIl         0.318309886183790671537767526745028724L /* 1/pi */
+#define M_2_PIl         0.636619772367581343075535053490057448L /* 2/pi */
+#define M_2_SQRTPIl     1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
+#define M_SQRT2l        1.414213562373095048801688724209698079L /* sqrt(2) */
+#define M_SQRT1_2l      0.707106781186547524400844362104849039L /* 1/sqrt(2) */
+void sincos(double, double*, double*);
+void sincosf(float, float*, float*);
+void sincosl(long double, long double*, long double*);
+#endif
+
+__END_DECLS
+
+#endif /* !_MATH_H_ */
diff --git a/libc/include/mntent.h b/libc/include/mntent.h
index de285d0..ad9d72f 100644
--- a/libc/include/mntent.h
+++ b/libc/include/mntent.h
@@ -25,6 +25,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #ifndef _MNTENT_H_
 #define _MNTENT_H_
 
@@ -33,7 +34,17 @@
 #include <paths.h>  /* for _PATH_MOUNTED */
 
 #define MOUNTED _PATH_MOUNTED
+
 #define MNTTYPE_IGNORE "ignore"
+#define MNTTYPE_NFS "nfs"
+#define MNTTYPE_SWAP "swap"
+
+#define MNTOPT_DEFAULTS "defaults"
+#define MNTOPT_NOAUTO "noauto"
+#define MNTOPT_NOSUID "nosuid"
+#define MNTOPT_RO "ro"
+#define MNTOPT_RW "rw"
+#define MNTOPT_SUID "suid"
 
 struct mntent {
   char* mnt_fsname;
@@ -46,10 +57,11 @@
 
 __BEGIN_DECLS
 
-int endmntent(FILE*);
+int endmntent(FILE*) __INTRODUCED_IN(21);
 struct mntent* getmntent(FILE*);
-struct mntent* getmntent_r(FILE*, struct mntent*, char*, int);
-FILE* setmntent(const char*, const char*);
+struct mntent* getmntent_r(FILE*, struct mntent*, char*, int) __INTRODUCED_IN(21);
+FILE* setmntent(const char*, const char*) __INTRODUCED_IN(21);
+char* hasmntopt(const struct mntent*, const char*) __INTRODUCED_IN_FUTURE;
 
 __END_DECLS
 
diff --git a/libc/include/net/ethernet.h b/libc/include/net/ethernet.h
index 47858b3..d5ba11f 100644
--- a/libc/include/net/ethernet.h
+++ b/libc/include/net/ethernet.h
@@ -29,7 +29,52 @@
 #ifndef _NET_ETHERNET_H_
 #define _NET_ETHERNET_H_
 
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
 #include <linux/if_ether.h>
-#include <net/if_ether.h>
+
+#define ETHERTYPE_IP 0x0800
+#define ETHERTYPE_ARP 0x0806
+#define ETHERTYPE_REVARP 0x8035
+#define ETHERTYPE_VLAN 0x8100
+#define ETHERTYPE_IPX 0x8137
+#define ETHERTYPE_IPV6 0x86dd
+#define ETHERTYPE_LOOPBACK 0x9000
+
+#define ETHERTYPE_TRAIL 0x1000
+#define ETHERTYPE_NTRAILER 16
+
+/*
+ * Some basic Ethernet constants.
+ */
+#define	ETHER_ADDR_LEN	6	/* length of an Ethernet address */
+#define	ETHER_TYPE_LEN	2	/* length of the Ethernet type field */
+#define	ETHER_CRC_LEN	4	/* length of the Ethernet CRC */
+#define	ETHER_HDR_LEN	((ETHER_ADDR_LEN * 2) + ETHER_TYPE_LEN)
+#define	ETHER_MIN_LEN	64	/* minimum frame length, including CRC */
+#define	ETHER_MAX_LEN	1518	/* maximum frame length, including CRC */
+#define	ETHER_MAX_LEN_JUMBO 9018 /* maximum jumbo frame len, including CRC */
+
+/*
+ * Ethernet address - 6 octets
+ * this is only used by the ethers(3) functions.
+ */
+struct ether_addr {
+	u_int8_t ether_addr_octet[ETHER_ADDR_LEN];
+} __attribute__((__packed__));
+
+/*
+ * Structure of a 10Mb/s Ethernet header.
+ */
+struct	ether_header {
+	u_int8_t  ether_dhost[ETHER_ADDR_LEN];
+	u_int8_t  ether_shost[ETHER_ADDR_LEN];
+	u_int16_t ether_type;
+} __attribute__((__packed__));
+
+#define	ETHERMTU_JUMBO	(ETHER_MAX_LEN_JUMBO - ETHER_HDR_LEN - ETHER_CRC_LEN)
+#define	ETHERMTU	(ETHER_MAX_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
+#define	ETHERMIN	(ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
 
 #endif
diff --git a/libc/include/net/ethertypes.h b/libc/include/net/ethertypes.h
deleted file mode 100644
index 1cfd2cd..0000000
--- a/libc/include/net/ethertypes.h
+++ /dev/null
@@ -1,313 +0,0 @@
-/*	$NetBSD: ethertypes.h,v 1.17 2005/12/10 23:21:38 elad Exp $	*/
-
-/*
- * Copyright (c) 1982, 1986, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- *
- *	@(#)if_ether.h	8.1 (Berkeley) 6/10/93
- */
-
-/*
- * Ethernet protocol types.
- *
- * According to "assigned numbers", the Ethernet protocol numbers are also
- * used as ARP protocol type numbers.
- *
- * I factor them out here to avoid pulling all the Ethernet header file
- * into the hardware independent ARP code. -is
- *
- * Additional sources of information:
- *	http://www.mit.edu/~map/Ethernet/Ethernet.txt
- *	ftp://venera.isi.edu/in-notes/iana/assignments/ethernet-numbers
- *
- */
-
-#ifndef _NET_ETHERTYPES_H_
-#define	_NET_ETHERTYPES_H_
-
-/*
- *  NOTE: 0x0000-0x05DC (0..1500) are generally IEEE 802.3 length fields.
- *  However, there are some conflicts.
- */
-
-#define	ETHERTYPE_8023		0x0004	/* IEEE 802.3 packet */
-		   /* 0x0101 .. 0x1FF	   Experimental */
-#define	ETHERTYPE_PUP		0x0200	/* Xerox PUP protocol - see 0A00 */
-#define	ETHERTYPE_PUPAT		0x0200	/* PUP Address Translation - see 0A01 */
-#define	ETHERTYPE_SPRITE	0x0500	/* ??? */
-			     /* 0x0400	   Nixdorf */
-#define	ETHERTYPE_NS		0x0600	/* XNS */
-#define	ETHERTYPE_NSAT		0x0601	/* XNS Address Translation (3Mb only) */
-#define	ETHERTYPE_DLOG1 	0x0660	/* DLOG (?) */
-#define	ETHERTYPE_DLOG2 	0x0661	/* DLOG (?) */
-#define	ETHERTYPE_IP		0x0800	/* IP protocol */
-#define	ETHERTYPE_X75		0x0801	/* X.75 Internet */
-#define	ETHERTYPE_NBS		0x0802	/* NBS Internet */
-#define	ETHERTYPE_ECMA		0x0803	/* ECMA Internet */
-#define	ETHERTYPE_CHAOS 	0x0804	/* CHAOSnet */
-#define	ETHERTYPE_X25		0x0805	/* X.25 Level 3 */
-#define	ETHERTYPE_ARP		0x0806	/* Address resolution protocol */
-#define	ETHERTYPE_NSCOMPAT	0x0807	/* XNS Compatibility */
-#define	ETHERTYPE_FRARP 	0x0808	/* Frame Relay ARP (RFC1701) */
-			     /* 0x081C	   Symbolics Private */
-		    /* 0x0888 - 0x088A	   Xyplex */
-#define	ETHERTYPE_UBDEBUG	0x0900	/* Ungermann-Bass network debugger */
-#define	ETHERTYPE_IEEEPUP	0x0A00	/* Xerox IEEE802.3 PUP */
-#define	ETHERTYPE_IEEEPUPAT	0x0A01	/* Xerox IEEE802.3 PUP Address Translation */
-#define	ETHERTYPE_VINES 	0x0BAD	/* Banyan VINES */
-#define	ETHERTYPE_VINESLOOP	0x0BAE	/* Banyan VINES Loopback */
-#define	ETHERTYPE_VINESECHO	0x0BAF	/* Banyan VINES Echo */
-
-/*		       0x1000 - 0x100F	   Berkeley Trailer */
-/*
- * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
- * (type-ETHERTYPE_TRAIL)*512 bytes of data followed
- * by an ETHER type (as given above) and then the (variable-length) header.
- */
-#define	ETHERTYPE_TRAIL		0x1000	/* Trailer packet */
-#define	ETHERTYPE_NTRAILER	16
-
-#define	ETHERTYPE_DCA		0x1234	/* DCA - Multicast */
-#define	ETHERTYPE_VALID 	0x1600	/* VALID system protocol */
-#define	ETHERTYPE_DOGFIGHT	0x1989	/* Artificial Horizons ("Aviator" dogfight simulator [on Sun]) */
-#define	ETHERTYPE_RCL		0x1995	/* Datapoint Corporation (RCL lan protocol) */
-
-					/* The following 3C0x types
-					   are unregistered: */
-#define	ETHERTYPE_NBPVCD	0x3C00	/* 3Com NBP virtual circuit datagram (like XNS SPP) not registered */
-#define	ETHERTYPE_NBPSCD	0x3C01	/* 3Com NBP System control datagram not registered */
-#define	ETHERTYPE_NBPCREQ	0x3C02	/* 3Com NBP Connect request (virtual cct) not registered */
-#define	ETHERTYPE_NBPCRSP	0x3C03	/* 3Com NBP Connect repsonse not registered */
-#define	ETHERTYPE_NBPCC		0x3C04	/* 3Com NBP Connect complete not registered */
-#define	ETHERTYPE_NBPCLREQ	0x3C05	/* 3Com NBP Close request (virtual cct) not registered */
-#define	ETHERTYPE_NBPCLRSP	0x3C06	/* 3Com NBP Close response not registered */
-#define	ETHERTYPE_NBPDG		0x3C07	/* 3Com NBP Datagram (like XNS IDP) not registered */
-#define	ETHERTYPE_NBPDGB	0x3C08	/* 3Com NBP Datagram broadcast not registered */
-#define	ETHERTYPE_NBPCLAIM	0x3C09	/* 3Com NBP Claim NetBIOS name not registered */
-#define	ETHERTYPE_NBPDLTE	0x3C0A	/* 3Com NBP Delete Netbios name not registered */
-#define	ETHERTYPE_NBPRAS	0x3C0B	/* 3Com NBP Remote adaptor status request not registered */
-#define	ETHERTYPE_NBPRAR	0x3C0C	/* 3Com NBP Remote adaptor response not registered */
-#define	ETHERTYPE_NBPRST	0x3C0D	/* 3Com NBP Reset not registered */
-
-#define	ETHERTYPE_PCS		0x4242	/* PCS Basic Block Protocol */
-#define	ETHERTYPE_IMLBLDIAG	0x424C	/* Information Modes Little Big LAN diagnostic */
-#define	ETHERTYPE_DIDDLE	0x4321	/* THD - Diddle */
-#define	ETHERTYPE_IMLBL		0x4C42	/* Information Modes Little Big LAN */
-#define	ETHERTYPE_SIMNET	0x5208	/* BBN Simnet Private */
-#define	ETHERTYPE_DECEXPER	0x6000	/* DEC Unassigned, experimental */
-#define	ETHERTYPE_MOPDL		0x6001	/* DEC MOP dump/load */
-#define	ETHERTYPE_MOPRC		0x6002	/* DEC MOP remote console */
-#define	ETHERTYPE_DECnet	0x6003	/* DEC DECNET Phase IV route */
-#define	ETHERTYPE_DN		ETHERTYPE_DECnet	/* libpcap, tcpdump */
-#define	ETHERTYPE_LAT		0x6004	/* DEC LAT */
-#define	ETHERTYPE_DECDIAG	0x6005	/* DEC diagnostic protocol (at interface initialization?) */
-#define	ETHERTYPE_DECCUST	0x6006	/* DEC customer protocol */
-#define	ETHERTYPE_SCA		0x6007	/* DEC LAVC, SCA */
-#define	ETHERTYPE_AMBER		0x6008	/* DEC AMBER */
-#define	ETHERTYPE_DECMUMPS	0x6009	/* DEC MUMPS */
-		    /* 0x6010 - 0x6014	   3Com Corporation */
-#define	ETHERTYPE_TRANSETHER	0x6558	/* Trans Ether Bridging (RFC1701)*/
-#define	ETHERTYPE_RAWFR		0x6559	/* Raw Frame Relay (RFC1701) */
-#define	ETHERTYPE_UBDL		0x7000	/* Ungermann-Bass download */
-#define	ETHERTYPE_UBNIU		0x7001	/* Ungermann-Bass NIUs */
-#define	ETHERTYPE_UBDIAGLOOP	0x7002	/* Ungermann-Bass diagnostic/loopback */
-#define	ETHERTYPE_UBNMC		0x7003	/* Ungermann-Bass ??? (NMC to/from UB Bridge) */
-#define	ETHERTYPE_UBBST		0x7005	/* Ungermann-Bass Bridge Spanning Tree */
-#define	ETHERTYPE_OS9		0x7007	/* OS/9 Microware */
-#define	ETHERTYPE_OS9NET	0x7009	/* OS/9 Net? */
-		    /* 0x7020 - 0x7029	   LRT (England) (now Sintrom) */
-#define	ETHERTYPE_RACAL		0x7030	/* Racal-Interlan */
-#define	ETHERTYPE_PRIMENTS	0x7031	/* Prime NTS (Network Terminal Service) */
-#define	ETHERTYPE_CABLETRON	0x7034	/* Cabletron */
-#define	ETHERTYPE_CRONUSVLN	0x8003	/* Cronus VLN */
-#define	ETHERTYPE_CRONUS	0x8004	/* Cronus Direct */
-#define	ETHERTYPE_HP		0x8005	/* HP Probe */
-#define	ETHERTYPE_NESTAR	0x8006	/* Nestar */
-#define	ETHERTYPE_ATTSTANFORD	0x8008	/* AT&T/Stanford (local use) */
-#define	ETHERTYPE_EXCELAN	0x8010	/* Excelan */
-#define	ETHERTYPE_SG_DIAG	0x8013	/* SGI diagnostic type */
-#define	ETHERTYPE_SG_NETGAMES	0x8014	/* SGI network games */
-#define	ETHERTYPE_SG_RESV	0x8015	/* SGI reserved type */
-#define	ETHERTYPE_SG_BOUNCE	0x8016	/* SGI bounce server */
-#define	ETHERTYPE_APOLLODOMAIN	0x8019	/* Apollo DOMAIN */
-#define	ETHERTYPE_TYMSHARE	0x802E	/* Tymeshare */
-#define	ETHERTYPE_TIGAN		0x802F	/* Tigan, Inc. */
-#define	ETHERTYPE_REVARP	0x8035	/* Reverse addr resolution protocol */
-#define	ETHERTYPE_AEONIC	0x8036	/* Aeonic Systems */
-#define	ETHERTYPE_IPXNEW	0x8037	/* IPX (Novell Netware?) */
-#define	ETHERTYPE_LANBRIDGE	0x8038	/* DEC LANBridge */
-#define	ETHERTYPE_DSMD	0x8039	/* DEC DSM/DDP */
-#define	ETHERTYPE_ARGONAUT	0x803A	/* DEC Argonaut Console */
-#define	ETHERTYPE_VAXELN	0x803B	/* DEC VAXELN */
-#define	ETHERTYPE_DECDNS	0x803C	/* DEC DNS Naming Service */
-#define	ETHERTYPE_ENCRYPT	0x803D	/* DEC Ethernet Encryption */
-#define	ETHERTYPE_DECDTS	0x803E	/* DEC Distributed Time Service */
-#define	ETHERTYPE_DECLTM	0x803F	/* DEC LAN Traffic Monitor */
-#define	ETHERTYPE_DECNETBIOS	0x8040	/* DEC PATHWORKS DECnet NETBIOS Emulation */
-#define	ETHERTYPE_DECLAST	0x8041	/* DEC Local Area System Transport */
-			     /* 0x8042	   DEC Unassigned */
-#define	ETHERTYPE_PLANNING	0x8044	/* Planning Research Corp. */
-		    /* 0x8046 - 0x8047	   AT&T */
-#define	ETHERTYPE_DECAM		0x8048	/* DEC Availability Manager for Distributed Systems DECamds (but someone at DEC says not) */
-#define	ETHERTYPE_EXPERDATA	0x8049	/* ExperData */
-#define	ETHERTYPE_VEXP		0x805B	/* Stanford V Kernel exp. */
-#define	ETHERTYPE_VPROD		0x805C	/* Stanford V Kernel prod. */
-#define	ETHERTYPE_ES		0x805D	/* Evans & Sutherland */
-#define	ETHERTYPE_LITTLE	0x8060	/* Little Machines */
-#define	ETHERTYPE_COUNTERPOINT	0x8062	/* Counterpoint Computers */
-		    /* 0x8065 - 0x8066	   Univ. of Mass @ Amherst */
-#define	ETHERTYPE_VEECO		0x8067	/* Veeco Integrated Auto. */
-#define	ETHERTYPE_GENDYN	0x8068	/* General Dynamics */
-#define	ETHERTYPE_ATT		0x8069	/* AT&T */
-#define	ETHERTYPE_AUTOPHON	0x806A	/* Autophon */
-#define	ETHERTYPE_COMDESIGN	0x806C	/* ComDesign */
-#define	ETHERTYPE_COMPUGRAPHIC	0x806D	/* Compugraphic Corporation */
-		    /* 0x806E - 0x8077	   Landmark Graphics Corp. */
-#define	ETHERTYPE_MATRA		0x807A	/* Matra */
-#define	ETHERTYPE_DDE		0x807B	/* Dansk Data Elektronik */
-#define	ETHERTYPE_MERIT		0x807C	/* Merit Internodal (or Univ of Michigan?) */
-		    /* 0x807D - 0x807F	   Vitalink Communications */
-#define	ETHERTYPE_VLTLMAN	0x8080	/* Vitalink TransLAN III Management */
-		    /* 0x8081 - 0x8083	   Counterpoint Computers */
-		    /* 0x8088 - 0x808A	   Xyplex */
-#define	ETHERTYPE_ATALK		0x809B	/* AppleTalk */
-#define	ETHERTYPE_AT		ETHERTYPE_ATALK		/* old NetBSD */
-#define	ETHERTYPE_APPLETALK	ETHERTYPE_ATALK		/* HP-UX */
-		    /* 0x809C - 0x809E	   Datability */
-#define	ETHERTYPE_SPIDER	0x809F	/* Spider Systems Ltd. */
-			     /* 0x80A3	   Nixdorf */
-		    /* 0x80A4 - 0x80B3	   Siemens Gammasonics Inc. */
-		    /* 0x80C0 - 0x80C3	   DCA (Digital Comm. Assoc.) Data Exchange Cluster */
-		    /* 0x80C4 - 0x80C5	   Banyan Systems */
-#define	ETHERTYPE_PACER		0x80C6	/* Pacer Software */
-#define	ETHERTYPE_APPLITEK	0x80C7	/* Applitek Corporation */
-		    /* 0x80C8 - 0x80CC	   Intergraph Corporation */
-		    /* 0x80CD - 0x80CE	   Harris Corporation */
-		    /* 0x80CF - 0x80D2	   Taylor Instrument */
-		    /* 0x80D3 - 0x80D4	   Rosemount Corporation */
-#define	ETHERTYPE_SNA		0x80D5	/* IBM SNA Services over Ethernet */
-#define	ETHERTYPE_VARIAN	0x80DD	/* Varian Associates */
-		    /* 0x80DE - 0x80DF	   TRFS (Integrated Solutions Transparent Remote File System) */
-		    /* 0x80E0 - 0x80E3	   Allen-Bradley */
-		    /* 0x80E4 - 0x80F0	   Datability */
-#define	ETHERTYPE_RETIX		0x80F2	/* Retix */
-#define	ETHERTYPE_AARP		0x80F3	/* AppleTalk AARP */
-		    /* 0x80F4 - 0x80F5	   Kinetics */
-#define	ETHERTYPE_APOLLO	0x80F7	/* Apollo Computer */
-#define ETHERTYPE_VLAN		0x8100	/* IEEE 802.1Q VLAN tagging (XXX conflicts) */
-		    /* 0x80FF - 0x8101	   Wellfleet Communications (XXX conflicts) */
-#define	ETHERTYPE_BOFL		0x8102	/* Wellfleet; BOFL (Breath OF Life) pkts [every 5-10 secs.] */
-#define	ETHERTYPE_WELLFLEET	0x8103	/* Wellfleet Communications */
-		    /* 0x8107 - 0x8109	   Symbolics Private */
-#define	ETHERTYPE_TALARIS	0x812B	/* Talaris */
-#define	ETHERTYPE_WATERLOO	0x8130	/* Waterloo Microsystems Inc. (XXX which?) */
-#define	ETHERTYPE_HAYES		0x8130	/* Hayes Microcomputers (XXX which?) */
-#define	ETHERTYPE_VGLAB		0x8131	/* VG Laboratory Systems */
-		    /* 0x8132 - 0x8137	   Bridge Communications */
-#define	ETHERTYPE_IPX		0x8137	/* Novell (old) NetWare IPX (ECONFIG E option) */
-#define	ETHERTYPE_NOVELL	0x8138	/* Novell, Inc. */
-		    /* 0x8139 - 0x813D	   KTI */
-#define	ETHERTYPE_MUMPS		0x813F	/* M/MUMPS data sharing */
-#define	ETHERTYPE_AMOEBA	0x8145	/* Vrije Universiteit (NL) Amoeba 4 RPC (obsolete) */
-#define	ETHERTYPE_FLIP		0x8146	/* Vrije Universiteit (NL) FLIP (Fast Local Internet Protocol) */
-#define	ETHERTYPE_VURESERVED	0x8147	/* Vrije Universiteit (NL) [reserved] */
-#define	ETHERTYPE_LOGICRAFT	0x8148	/* Logicraft */
-#define	ETHERTYPE_NCD		0x8149	/* Network Computing Devices */
-#define	ETHERTYPE_ALPHA		0x814A	/* Alpha Micro */
-#define	ETHERTYPE_SNMP		0x814C	/* SNMP over Ethernet (see RFC1089) */
-		    /* 0x814D - 0x814E	   BIIN */
-#define	ETHERTYPE_TEC	0x814F	/* Technically Elite Concepts */
-#define	ETHERTYPE_RATIONAL	0x8150	/* Rational Corp */
-		    /* 0x8151 - 0x8153	   Qualcomm */
-		    /* 0x815C - 0x815E	   Computer Protocol Pty Ltd */
-		    /* 0x8164 - 0x8166	   Charles River Data Systems */
-#define	ETHERTYPE_XTP		0x817D	/* Protocol Engines XTP */
-#define	ETHERTYPE_SGITW		0x817E	/* SGI/Time Warner prop. */
-#define	ETHERTYPE_HIPPI_FP	0x8180	/* HIPPI-FP encapsulation */
-#define	ETHERTYPE_STP		0x8181	/* Scheduled Transfer STP, HIPPI-ST */
-		    /* 0x8182 - 0x8183	   Reserved for HIPPI-6400 */
-		    /* 0x8184 - 0x818C	   SGI prop. */
-#define	ETHERTYPE_MOTOROLA	0x818D	/* Motorola */
-#define	ETHERTYPE_NETBEUI	0x8191	/* PowerLAN NetBIOS/NetBEUI (PC) */
-		    /* 0x819A - 0x81A3	   RAD Network Devices */
-		    /* 0x81B7 - 0x81B9	   Xyplex */
-		    /* 0x81CC - 0x81D5	   Apricot Computers */
-		    /* 0x81D6 - 0x81DD	   Artisoft Lantastic */
-		    /* 0x81E6 - 0x81EF	   Polygon */
-		    /* 0x81F0 - 0x81F2	   Comsat Labs */
-		    /* 0x81F3 - 0x81F5	   SAIC */
-		    /* 0x81F6 - 0x81F8	   VG Analytical */
-		    /* 0x8203 - 0x8205	   QNX Software Systems Ltd. */
-		    /* 0x8221 - 0x8222	   Ascom Banking Systems */
-		    /* 0x823E - 0x8240	   Advanced Encryption Systems */
-		    /* 0x8263 - 0x826A	   Charles River Data Systems */
-		    /* 0x827F - 0x8282	   Athena Programming */
-		    /* 0x829A - 0x829B	   Inst Ind Info Tech */
-		    /* 0x829C - 0x82AB	   Taurus Controls */
-		    /* 0x82AC - 0x8693	   Walker Richer & Quinn */
-#define	ETHERTYPE_ACCTON	0x8390	/* Accton Technologies (unregistered) */
-#define	ETHERTYPE_TALARISMC	0x852B	/* Talaris multicast */
-#define	ETHERTYPE_KALPANA	0x8582	/* Kalpana */
-		    /* 0x8694 - 0x869D	   Idea Courier */
-		    /* 0x869E - 0x86A1	   Computer Network Tech */
-		    /* 0x86A3 - 0x86AC	   Gateway Communications */
-#define	ETHERTYPE_SECTRA	0x86DB	/* SECTRA */
-#define	ETHERTYPE_IPV6		0x86DD	/* IP protocol version 6 */
-#define	ETHERTYPE_DELTACON	0x86DE	/* Delta Controls */
-#define	ETHERTYPE_ATOMIC	0x86DF	/* ATOMIC */
-		    /* 0x86E0 - 0x86EF	   Landis & Gyr Powers */
-		    /* 0x8700 - 0x8710	   Motorola */
-#define	ETHERTYPE_RDP		0x8739	/* Control Technology Inc. RDP Without IP */
-#define	ETHERTYPE_MICP		0x873A	/* Control Technology Inc. Mcast Industrial Ctrl Proto. */
-		    /* 0x873B - 0x873C	   Control Technology Inc. Proprietary */
-#define	ETHERTYPE_TCPCOMP	0x876B	/* TCP/IP Compression (RFC1701) */
-#define	ETHERTYPE_IPAS		0x876C	/* IP Autonomous Systems (RFC1701) */
-#define	ETHERTYPE_SECUREDATA	0x876D	/* Secure Data (RFC1701) */
-#define	ETHERTYPE_FLOWCONTROL	0x8808	/* 802.3x flow control packet */
-#define	ETHERTYPE_SLOWPROTOCOLS	0x8809	/* Slow protocols */
-#define	ETHERTYPE_PPP		0x880B	/* PPP (obsolete by PPPOE) */
-#define	ETHERTYPE_HITACHI	0x8820	/* Hitachi Cable (Optoelectronic Systems Laboratory) */
-#define	ETHERTYPE_MPLS		0x8847	/* MPLS Unicast */
-#define	ETHERTYPE_MPLS_MCAST	0x8848	/* MPLS Multicast */
-#define	ETHERTYPE_AXIS		0x8856	/* Axis Communications AB proprietary bootstrap/config */
-#define	ETHERTYPE_PPPOEDISC	0x8863	/* PPP Over Ethernet Discovery Stage */
-#define	ETHERTYPE_PPPOE		0x8864	/* PPP Over Ethernet Session Stage */
-#define	ETHERTYPE_LANPROBE	0x8888	/* HP LanProbe test? */
-#define	ETHERTYPE_PAE		0x888e	/* EAPOL PAE/802.1x */
-#define	ETHERTYPE_LOOPBACK	0x9000	/* Loopback */
-#define	ETHERTYPE_LBACK		ETHERTYPE_LOOPBACK	/* DEC MOP loopback */
-#define	ETHERTYPE_XNSSM		0x9001	/* 3Com (Formerly Bridge Communications), XNS Systems Management */
-#define	ETHERTYPE_TCPSM		0x9002	/* 3Com (Formerly Bridge Communications), TCP/IP Systems Management */
-#define	ETHERTYPE_BCLOOP	0x9003	/* 3Com (Formerly Bridge Communications), loopback detection */
-#define	ETHERTYPE_DEBNI		0xAAAA	/* DECNET? Used by VAX 6220 DEBNI */
-#define	ETHERTYPE_SONIX		0xFAF5	/* Sonix Arpeggio */
-#define	ETHERTYPE_VITAL		0xFF00	/* BBN VITAL-LanBridge cache wakeups */
-		    /* 0xFF00 - 0xFFOF	   ISC Bunker Ramo */
-
-#define	ETHERTYPE_MAX		0xFFFF	/* Maximum valid ethernet type, reserved */
-
-#endif /* !_NET_ETHERTYPES_H_ */
diff --git a/libc/include/net/if.h b/libc/include/net/if.h
index aa4c19e..eac7699 100644
--- a/libc/include/net/if.h
+++ b/libc/include/net/if.h
@@ -46,8 +46,8 @@
 
 char* if_indextoname(unsigned, char*);
 unsigned if_nametoindex(const char*);
-struct if_nameindex* if_nameindex(void);
-void if_freenameindex(struct if_nameindex*);
+struct if_nameindex* if_nameindex(void) __INTRODUCED_IN(24);
+void if_freenameindex(struct if_nameindex*) __INTRODUCED_IN(24);
 
 __END_DECLS
 
diff --git a/libc/include/net/if_ether.h b/libc/include/net/if_ether.h
deleted file mode 100644
index 8daa16b..0000000
--- a/libc/include/net/if_ether.h
+++ /dev/null
@@ -1,219 +0,0 @@
-/*	$NetBSD: if_ether.h,v 1.43 2006/11/24 01:04:30 rpaulo Exp $	*/
-
-/*
- * Copyright (c) 1982, 1986, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- *
- *	@(#)if_ether.h	8.1 (Berkeley) 6/10/93
- */
-
-#ifndef _NET_IF_ETHER_H_
-#define _NET_IF_ETHER_H_
-
-#include <sys/types.h>
-
-#ifdef _KERNEL
-#ifdef _KERNEL_OPT
-#include "opt_mbuftrace.h"
-#endif
-#include <sys/mbuf.h>
-#endif
-
-/*
- * Some basic Ethernet constants.
- */
-#define	ETHER_ADDR_LEN	6	/* length of an Ethernet address */
-#define	ETHER_TYPE_LEN	2	/* length of the Ethernet type field */
-#define	ETHER_CRC_LEN	4	/* length of the Ethernet CRC */
-#define	ETHER_HDR_LEN	((ETHER_ADDR_LEN * 2) + ETHER_TYPE_LEN)
-#define	ETHER_MIN_LEN	64	/* minimum frame length, including CRC */
-#define	ETHER_MAX_LEN	1518	/* maximum frame length, including CRC */
-#define	ETHER_MAX_LEN_JUMBO 9018 /* maximum jumbo frame len, including CRC */
-
-/*
- * Some Ethernet extensions.
- */
-#define	ETHER_VLAN_ENCAP_LEN 4	/* length of 802.1Q VLAN encapsulation */
-
-/*
- * Ethernet address - 6 octets
- * this is only used by the ethers(3) functions.
- */
-struct ether_addr {
-	u_int8_t ether_addr_octet[ETHER_ADDR_LEN];
-} __attribute__((__packed__));
-
-/*
- * Structure of a 10Mb/s Ethernet header.
- */
-struct	ether_header {
-	u_int8_t  ether_dhost[ETHER_ADDR_LEN];
-	u_int8_t  ether_shost[ETHER_ADDR_LEN];
-	u_int16_t ether_type;
-} __attribute__((__packed__));
-
-#include <net/ethertypes.h>
-
-#define	ETHER_IS_MULTICAST(addr) (*(addr) & 0x01) /* is address mcast/bcast? */
-
-#define	ETHERMTU_JUMBO	(ETHER_MAX_LEN_JUMBO - ETHER_HDR_LEN - ETHER_CRC_LEN)
-#define	ETHERMTU	(ETHER_MAX_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
-#define	ETHERMIN	(ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
-
-/*
- * Compute the maximum frame size based on ethertype (i.e. possible
- * encapsulation) and whether or not an FCS is present.
- */
-#define	ETHER_MAX_FRAME(ifp, etype, hasfcs)				\
-	((ifp)->if_mtu + ETHER_HDR_LEN +				\
-	 ((hasfcs) ? ETHER_CRC_LEN : 0) +				\
-	 (((etype) == ETHERTYPE_VLAN) ? ETHER_VLAN_ENCAP_LEN : 0))
-
-/*
- * Ethernet CRC32 polynomials (big- and little-endian verions).
- */
-#define	ETHER_CRC_POLY_LE	0xedb88320
-#define	ETHER_CRC_POLY_BE	0x04c11db6
-
-#ifndef _STANDALONE
-
-/*
- * Ethernet-specific mbuf flags.
- */
-#define	M_HASFCS	M_LINK0	/* FCS included at end of frame */
-#define	M_PROMISC	M_LINK1	/* this packet is not for us */
-
-#ifdef _KERNEL
-/*
- * Macro to map an IP multicast address to an Ethernet multicast address.
- * The high-order 25 bits of the Ethernet address are statically assigned,
- * and the low-order 23 bits are taken from the low end of the IP address.
- */
-#define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr)				\
-	/* struct in_addr *ipaddr; */					\
-	/* u_int8_t enaddr[ETHER_ADDR_LEN]; */				\
-{									\
-	(enaddr)[0] = 0x01;						\
-	(enaddr)[1] = 0x00;						\
-	(enaddr)[2] = 0x5e;						\
-	(enaddr)[3] = ((u_int8_t *)ipaddr)[1] & 0x7f;			\
-	(enaddr)[4] = ((u_int8_t *)ipaddr)[2];				\
-	(enaddr)[5] = ((u_int8_t *)ipaddr)[3];				\
-}
-/*
- * Macro to map an IP6 multicast address to an Ethernet multicast address.
- * The high-order 16 bits of the Ethernet address are statically assigned,
- * and the low-order 32 bits are taken from the low end of the IP6 address.
- */
-#define ETHER_MAP_IPV6_MULTICAST(ip6addr, enaddr)			\
-	/* struct in6_addr *ip6addr; */					\
-	/* u_int8_t enaddr[ETHER_ADDR_LEN]; */				\
-{                                                                       \
-	(enaddr)[0] = 0x33;						\
-	(enaddr)[1] = 0x33;						\
-	(enaddr)[2] = ((u_int8_t *)ip6addr)[12];			\
-	(enaddr)[3] = ((u_int8_t *)ip6addr)[13];			\
-	(enaddr)[4] = ((u_int8_t *)ip6addr)[14];			\
-	(enaddr)[5] = ((u_int8_t *)ip6addr)[15];			\
-}
-#endif
-
-#define	ETHERCAP_VLAN_MTU	0x00000001	/* VLAN-compatible MTU */
-#define	ETHERCAP_VLAN_HWTAGGING	0x00000002	/* hardware VLAN tag support */
-#define	ETHERCAP_JUMBO_MTU	0x00000004	/* 9000 byte MTU supported */
-
-#ifdef	_KERNEL
-extern const uint8_t etherbroadcastaddr[ETHER_ADDR_LEN];
-extern const uint8_t ethermulticastaddr_slowprotocols[ETHER_ADDR_LEN];
-extern const uint8_t ether_ipmulticast_min[ETHER_ADDR_LEN];
-extern const uint8_t ether_ipmulticast_max[ETHER_ADDR_LEN];
-
-int	ether_ioctl(struct ifnet *, u_long, caddr_t);
-int	ether_addmulti (struct ifreq *, struct ethercom *);
-int	ether_delmulti (struct ifreq *, struct ethercom *);
-int	ether_changeaddr (struct ifreq *, struct ethercom *);
-int	ether_multiaddr(struct sockaddr *, u_int8_t[], u_int8_t[]);
-
-/*
- * Ethernet 802.1Q VLAN structures.
- */
-
-/* add VLAN tag to input/received packet */
-#define	VLAN_INPUT_TAG(ifp, m, vlanid, _errcase)	\
-	do {								\
-                struct m_tag *mtag =					\
-                    m_tag_get(PACKET_TAG_VLAN, sizeof(u_int), M_NOWAIT);\
-                if (mtag == NULL) {					\
-			ifp->if_ierrors++;				\
-                        printf("%s: unable to allocate VLAN tag\n",	\
-                            ifp->if_xname);				\
-                        m_freem(m);					\
-                        _errcase;					\
-                }							\
-                *(u_int *)(mtag + 1) = vlanid;				\
-                m_tag_prepend(m, mtag);					\
-	} while(0)
-
-/* extract VLAN tag from output/trasmit packet */
-#define VLAN_OUTPUT_TAG(ec, m0)			\
-	VLAN_ATTACHED(ec) ? m_tag_find((m0), PACKET_TAG_VLAN, NULL) : NULL
-
-/* extract VLAN ID value from a VLAN tag */
-#define VLAN_TAG_VALUE(mtag)	\
-	((*(u_int *)(mtag + 1)) & 4095)
-
-/* test if any VLAN is configured for this interface */
-#define VLAN_ATTACHED(ec)	((ec)->ec_nvlans > 0)
-
-void	ether_ifattach(struct ifnet *, const u_int8_t *);
-void	ether_ifdetach(struct ifnet *);
-
-char	*ether_sprintf(const u_int8_t *);
-char	*ether_snprintf(char *, size_t, const u_int8_t *);
-
-u_int32_t ether_crc32_le(const u_int8_t *, size_t);
-u_int32_t ether_crc32_be(const u_int8_t *, size_t);
-
-int	ether_nonstatic_aton(u_char *, char *);
-#else
-/*
- * Prototype ethers(3) functions.
- */
-#include <sys/cdefs.h>
-__BEGIN_DECLS
-char *	ether_ntoa __P((const struct ether_addr *));
-struct ether_addr *
-	ether_aton __P((const char *));
-int	ether_ntohost __P((char *, const struct ether_addr *));
-int	ether_hostton __P((const char *, struct ether_addr *));
-int	ether_line __P((const char *, struct ether_addr *, char *));
-__END_DECLS
-#endif
-
-#endif /* _STANDALONE */
-
-#endif /* !_NET_IF_ETHER_H_ */
diff --git a/libc/include/net/if_ieee1394.h b/libc/include/net/if_ieee1394.h
deleted file mode 100644
index 5a61581..0000000
--- a/libc/include/net/if_ieee1394.h
+++ /dev/null
@@ -1,127 +0,0 @@
-/*	$NetBSD: if_ieee1394.h,v 1.6 2005/12/10 23:21:38 elad Exp $	*/
-
-/*
- * Copyright (c) 2000 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Atsushi Onoe.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the NetBSD
- *	Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
- */
-
-#ifndef _NET_IF_IEEE1394_H_
-#define _NET_IF_IEEE1394_H_
-
-/* hardware address information for arp / nd */
-struct ieee1394_hwaddr {
-	u_int8_t	iha_uid[8];		/* node unique ID */
-	u_int8_t	iha_maxrec;		/* max_rec in the config ROM */
-	u_int8_t	iha_speed;		/* min of link/PHY speed */
-	u_int8_t	iha_offset[6];		/* unicast FIFO address */
-};
-
-/*
- * BPF wants to see one of these.
- */
-struct ieee1394_bpfhdr {
-	uint8_t		ibh_dhost[8];
-	uint8_t		ibh_shost[8];
-	uint16_t	ibh_type;
-};
-
-#ifdef _KERNEL
-
-/* pseudo header */
-struct ieee1394_header {
-	u_int8_t	ih_uid[8];		/* dst/src uid */
-	u_int8_t	ih_maxrec;		/* dst maxrec for tx */
-	u_int8_t	ih_speed;		/* speed */
-	u_int8_t	ih_offset[6];		/* dst offset */
-};
-
-/* unfragment encapsulation header */
-struct ieee1394_unfraghdr {
-	u_int16_t	iuh_ft;			/* fragment type == 0 */
-	u_int16_t	iuh_etype;		/* ether_type */
-};
-
-/* fragmented encapsulation header */
-struct ieee1394_fraghdr {
-	u_int16_t	ifh_ft_size;		/* fragment type, data size-1 */
-	u_int16_t	ifh_etype_off;		/* etype for first fragment */
-						/* offset for subseq frag */
-	u_int16_t	ifh_dgl;		/* datagram label */
-	u_int16_t	ifh_reserved;
-};
-
-#define	IEEE1394_FT_SUBSEQ	0x8000
-#define	IEEE1394_FT_MORE	0x4000
-
-#define	IEEE1394MTU		1500
-
-#define	IEEE1394_GASP_LEN	8		/* GASP header for Stream */
-#define	IEEE1394_ADDR_LEN	8
-#define	IEEE1394_CRC_LEN	4
-
-struct ieee1394_reass_pkt {
-	LIST_ENTRY(ieee1394_reass_pkt) rp_next;
-	struct mbuf	*rp_m;
-	u_int16_t	rp_size;
-	u_int16_t	rp_etype;
-	u_int16_t	rp_off;
-	u_int16_t	rp_dgl;
-	u_int16_t	rp_len;
-	u_int16_t	rp_ttl;
-};
-
-struct ieee1394_reassq {
-	LIST_ENTRY(ieee1394_reassq) rq_node;
-	LIST_HEAD(, ieee1394_reass_pkt) rq_pkt;
-	u_int32_t	fr_id;
-};
-
-struct ieee1394com {
-	struct ifnet	fc_if;
-	struct ieee1394_hwaddr ic_hwaddr;
-	u_int16_t	ic_dgl;
-	LIST_HEAD(, ieee1394_reassq) ic_reassq;
-};
-
-const char *ieee1394_sprintf(const u_int8_t *);
-void ieee1394_input(struct ifnet *, struct mbuf *, u_int16_t);
-void ieee1394_ifattach(struct ifnet *, const struct ieee1394_hwaddr *);
-void ieee1394_ifdetach(struct ifnet *);
-int  ieee1394_ioctl(struct ifnet *, u_long, caddr_t);
-struct mbuf * ieee1394_fragment(struct ifnet *, struct mbuf *, int, u_int16_t);
-void ieee1394_drain(struct ifnet *);
-void ieee1394_watchdog(struct ifnet *);
-#endif /* _KERNEL */
-
-#endif /* !_NET_IF_IEEE1394_H_ */
diff --git a/libc/include/net/if_types.h b/libc/include/net/if_types.h
deleted file mode 100644
index eff6d53..0000000
--- a/libc/include/net/if_types.h
+++ /dev/null
@@ -1,268 +0,0 @@
-/*	$NetBSD: if_types.h,v 1.26 2012/08/05 21:21:41 wiz Exp $	*/
-
-/*
- * Copyright (c) 1989, 1993, 1994
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- *
- *	@(#)if_types.h	8.3 (Berkeley) 4/28/95
- */
-
-#ifndef _NET_IF_TYPES_H_
-#define _NET_IF_TYPES_H_
-
-/*
- * Interface types for benefit of parsing media address headers.
- * This list is derived from the SNMP list of ifTypes, originally
- * documented in RFC1573, now maintained as:
- *
- * <URL:http://www.iana.org/assignments/smi-numbers>
- */
-
-#define	IFT_OTHER	0x1		/* none of the following */
-#define	IFT_1822	0x2		/* old-style arpanet imp */
-#define	IFT_HDH1822	0x3		/* HDH arpanet imp */
-#define	IFT_X25DDN	0x4		/* x25 to imp */
-#define	IFT_X25		0x5		/* PDN X25 interface (RFC877) */
-#define	IFT_ETHER	0x6		/* Ethernet CSMA/CD */
-#define	IFT_ISO88023	0x7		/* CSMA/CD */
-#define	IFT_ISO88024	0x8		/* Token Bus */
-#define	IFT_ISO88025	0x9		/* Token Ring */
-#define	IFT_ISO88026	0xa		/* MAN */
-#define	IFT_STARLAN	0xb
-#define	IFT_P10		0xc		/* Proteon 10MBit ring */
-#define	IFT_P80		0xd		/* Proteon 80MBit ring */
-#define	IFT_HY		0xe		/* Hyperchannel */
-#define	IFT_FDDI	0xf
-#define	IFT_LAPB	0x10
-#define	IFT_SDLC	0x11
-#define	IFT_T1		0x12
-#define	IFT_CEPT	0x13		/* E1 - european T1 */
-#define	IFT_ISDNBASIC	0x14
-#define	IFT_ISDNPRIMARY	0x15
-#define	IFT_PTPSERIAL	0x16		/* Proprietary PTP serial */
-#define	IFT_PPP		0x17		/* RFC 1331 */
-#define	IFT_LOOP	0x18		/* loopback */
-#define	IFT_EON		0x19		/* ISO over IP */
-#define	IFT_XETHER	0x1a		/* obsolete 3MB experimental ethernet */
-#define	IFT_NSIP	0x1b		/* XNS over IP */
-#define	IFT_SLIP	0x1c		/* IP over generic TTY */
-#define	IFT_ULTRA	0x1d		/* Ultra Technologies */
-#define	IFT_DS3		0x1e		/* Generic T3 */
-#define	IFT_SIP		0x1f		/* SMDS */
-#define	IFT_FRELAY	0x20		/* Frame Relay DTE only */
-#define	IFT_RS232	0x21
-#define	IFT_PARA	0x22		/* parallel-port */
-#define	IFT_ARCNET	0x23
-#define	IFT_ARCNETPLUS	0x24
-#define	IFT_ATM		0x25		/* ATM cells */
-#define	IFT_MIOX25	0x26
-#define	IFT_SONET	0x27		/* SONET or SDH */
-#define	IFT_X25PLE	0x28
-#define	IFT_ISO88022LLC	0x29
-#define	IFT_LOCALTALK	0x2a
-#define	IFT_SMDSDXI	0x2b
-#define	IFT_FRELAYDCE	0x2c		/* Frame Relay DCE */
-#define	IFT_V35		0x2d
-#define	IFT_HSSI	0x2e
-#define	IFT_HIPPI	0x2f
-#define	IFT_MODEM	0x30		/* Generic Modem */
-#define	IFT_AAL5	0x31		/* AAL5 over ATM */
-#define	IFT_SONETPATH	0x32
-#define	IFT_SONETVT	0x33
-#define	IFT_SMDSICIP	0x34		/* SMDS InterCarrier Interface */
-#define	IFT_PROPVIRTUAL	0x35		/* Proprietary Virtual/internal */
-#define	IFT_PROPMUX	0x36		/* Proprietary Multiplexing */
-#define IFT_IEEE80212		   0x37 /* 100BaseVG */
-#define IFT_FIBRECHANNEL	   0x38 /* Fibre Channel */
-#define IFT_HIPPIINTERFACE	   0x39 /* HIPPI interfaces	 */
-#define IFT_FRAMERELAYINTERCONNECT 0x3a /* Obsolete, use either 0x20 or 0x2c */
-#define IFT_AFLANE8023		   0x3b /* ATM Emulated LAN for 802.3 */
-#define IFT_AFLANE8025		   0x3c /* ATM Emulated LAN for 802.5 */
-#define IFT_CCTEMUL		   0x3d /* ATM Emulated circuit		  */
-#define IFT_FASTETHER		   0x3e /* Fast Ethernet (100BaseT) */
-#define IFT_ISDN		   0x3f /* ISDN and X.25	    */
-#define IFT_V11			   0x40 /* CCITT V.11/X.21		*/
-#define IFT_V36			   0x41 /* CCITT V.36			*/
-#define IFT_G703AT64K		   0x42 /* CCITT G703 at 64Kbps */
-#define IFT_G703AT2MB		   0x43 /* Obsolete see DS1-MIB */
-#define IFT_QLLC		   0x44 /* SNA QLLC			*/
-#define IFT_FASTETHERFX		   0x45 /* Fast Ethernet (100BaseFX)	*/
-#define IFT_CHANNEL		   0x46 /* channel			*/
-#define IFT_IEEE80211		   0x47 /* radio spread spectrum	*/
-#define IFT_IBM370PARCHAN	   0x48 /* IBM System 360/370 OEMI Channel */
-#define IFT_ESCON		   0x49 /* IBM Enterprise Systems Connection */
-#define IFT_DLSW		   0x4a /* Data Link Switching */
-#define IFT_ISDNS		   0x4b /* ISDN S/T interface */
-#define IFT_ISDNU		   0x4c /* ISDN U interface */
-#define IFT_LAPD		   0x4d /* Link Access Protocol D */
-#define IFT_IPSWITCH		   0x4e /* IP Switching Objects */
-#define IFT_RSRB		   0x4f /* Remote Source Route Bridging */
-#define IFT_ATMLOGICAL		   0x50 /* ATM Logical Port */
-#define IFT_DS0			   0x51 /* Digital Signal Level 0 */
-#define IFT_DS0BUNDLE		   0x52 /* group of ds0s on the same ds1 */
-#define IFT_BSC			   0x53 /* Bisynchronous Protocol */
-#define IFT_ASYNC		   0x54 /* Asynchronous Protocol */
-#define IFT_CNR			   0x55 /* Combat Net Radio */
-#define IFT_ISO88025DTR		   0x56 /* ISO 802.5r DTR */
-#define IFT_EPLRS		   0x57 /* Ext Pos Loc Report Sys */
-#define IFT_ARAP		   0x58 /* Appletalk Remote Access Protocol */
-#define IFT_PROPCNLS		   0x59 /* Proprietary Connectionless Protocol*/
-#define IFT_HOSTPAD		   0x5a /* CCITT-ITU X.29 PAD Protocol */
-#define IFT_TERMPAD		   0x5b /* CCITT-ITU X.3 PAD Facility */
-#define IFT_FRAMERELAYMPI	   0x5c /* Multiproto Interconnect over FR */
-#define IFT_X213		   0x5d /* CCITT-ITU X213 */
-#define IFT_ADSL		   0x5e /* Asymmetric Digital Subscriber Loop */
-#define IFT_RADSL		   0x5f /* Rate-Adapt. Digital Subscriber Loop*/
-#define IFT_SDSL		   0x60 /* Symmetric Digital Subscriber Loop */
-#define IFT_VDSL		   0x61 /* Very H-Speed Digital Subscrib. Loop*/
-#define IFT_ISO88025CRFPINT	   0x62 /* ISO 802.5 CRFP */
-#define IFT_MYRINET		   0x63 /* Myricom Myrinet */
-#define IFT_VOICEEM		   0x64 /* voice recEive and transMit */
-#define IFT_VOICEFXO		   0x65 /* voice Foreign Exchange Office */
-#define IFT_VOICEFXS		   0x66 /* voice Foreign Exchange Station */
-#define IFT_VOICEENCAP		   0x67 /* voice encapsulation */
-#define IFT_VOICEOVERIP		   0x68 /* voice over IP encapsulation */
-#define IFT_ATMDXI		   0x69 /* ATM DXI */
-#define IFT_ATMFUNI		   0x6a /* ATM FUNI */
-#define IFT_ATMIMA		   0x6b /* ATM IMA		      */
-#define IFT_PPPMULTILINKBUNDLE	   0x6c /* PPP Multilink Bundle */
-#define IFT_IPOVERCDLC		   0x6d /* IBM ipOverCdlc */
-#define IFT_IPOVERCLAW		   0x6e /* IBM Common Link Access to Workstn */
-#define IFT_STACKTOSTACK	   0x6f /* IBM stackToStack */
-#define IFT_VIRTUALIPADDRESS	   0x70 /* IBM VIPA */
-#define IFT_MPC			   0x71 /* IBM multi-protocol channel support */
-#define IFT_IPOVERATM		   0x72 /* IBM ipOverAtm */
-#define IFT_ISO88025FIBER	   0x73 /* ISO 802.5j Fiber Token Ring */
-#define IFT_TDLC		   0x74 /* IBM twinaxial data link control */
-#define IFT_GIGABITETHERNET	   0x75 /* Gigabit Ethernet */
-#define IFT_HDLC		   0x76 /* HDLC */
-#define IFT_LAPF		   0x77 /* LAP F */
-#define IFT_V37			   0x78 /* V.37 */
-#define IFT_X25MLP		   0x79 /* Multi-Link Protocol */
-#define IFT_X25HUNTGROUP	   0x7a /* X25 Hunt Group */
-#define IFT_TRANSPHDLC		   0x7b /* Transp HDLC */
-#define IFT_INTERLEAVE		   0x7c /* Interleave channel */
-#define IFT_FAST		   0x7d /* Fast channel */
-#define IFT_IP			   0x7e /* IP (for APPN HPR in IP networks) */
-#define IFT_DOCSCABLEMACLAYER	   0x7f /* CATV Mac Layer */
-#define IFT_DOCSCABLEDOWNSTREAM	   0x80 /* CATV Downstream interface */
-#define IFT_DOCSCABLEUPSTREAM	   0x81 /* CATV Upstream interface */
-#define IFT_A12MPPSWITCH	   0x82	/* Avalon Parallel Processor */
-#define IFT_TUNNEL		   0x83	/* Encapsulation interface */
-#define IFT_COFFEE		   0x84	/* coffee pot */
-#define IFT_CES			   0x85	/* Circiut Emulation Service */
-#define IFT_ATMSUBINTERFACE	   0x86	/* (x)  ATM Sub Interface */
-#define IFT_L2VLAN		   0x87	/* Layer 2 Virtual LAN using 802.1Q */
-#define IFT_L3IPVLAN		   0x88	/* Layer 3 Virtual LAN - IP Protocol */
-#define IFT_L3IPXVLAN		   0x89	/* Layer 3 Virtual LAN - IPX Prot. */
-#define IFT_DIGITALPOWERLINE	   0x8a	/* IP over Power Lines */
-#define IFT_MEDIAMAILOVERIP	   0x8b	/* (xxx)  Multimedia Mail over IP */
-#define IFT_DTM			   0x8c	/* Dynamic synchronous Transfer Mode */
-#define IFT_DCN			   0x8d	/* Data Communications Network */
-#define IFT_IPFORWARD		   0x8e	/* IP Forwarding Interface */
-#define IFT_MSDSL		   0x8f	/* Multi-rate Symmetric DSL */
-#define IFT_IEEE1394		   0x90	/* IEEE1394 High Performance SerialBus*/
-#define IFT_IFGSN		   0x91	/* HIPPI-6400 */
-#define IFT_DVBRCCMACLAYER	   0x92	/* DVB-RCC MAC Layer */
-#define IFT_DVBRCCDOWNSTREAM	   0x93	/* DVB-RCC Downstream Channel */
-#define IFT_DVBRCCUPSTREAM	   0x94	/* DVB-RCC Upstream Channel */
-#define IFT_ATMVIRTUAL		   0x95	/* ATM Virtual Interface */
-#define IFT_MPLSTUNNEL		   0x96	/* MPLS Tunnel Virtual Interface */
-#define IFT_SRP			   0x97	/* Spatial Reuse Protocol */
-#define IFT_VOICEOVERATM	   0x98	/* Voice over ATM */
-#define IFT_VOICEOVERFRAMERELAY	   0x99	/* Voice Over Frame Relay */
-#define IFT_IDSL		   0x9a	/* Digital Subscriber Loop over ISDN */
-#define IFT_COMPOSITELINK	   0x9b	/* Avici Composite Link Interface */
-#define IFT_SS7SIGLINK		   0x9c	/* SS7 Signaling Link */
-#define IFT_PROPWIRELESSP2P	   0x9d	/* Prop. P2P wireless interface */
-#define IFT_FRFORWARD		   0x9e	/* Frame forward Interface */
-#define IFT_RFC1483		   0x9f	/* Multiprotocol over ATM AAL5 */
-#define IFT_USB			   0xa0	/* USB Interface */
-#define IFT_IEEE8023ADLAG	   0xa1	/* IEEE 802.3ad Link Aggregate*/
-#define IFT_BGPPOLICYACCOUNTING	   0xa2	/* BGP Policy Accounting */
-#define IFT_FRF16MFRBUNDLE	   0xa3	/* FRF.16 Multilik Frame Relay*/
-#define IFT_H323GATEKEEPER	   0xa4	/* H323 Gatekeeper */
-#define IFT_H323PROXY		   0xa5	/* H323 Voice and Video Proxy */
-#define IFT_MPLS		   0xa6	/* MPLS */
-#define IFT_MFSIGLINK		   0xa7	/* Multi-frequency signaling link */
-#define IFT_HDSL2		   0xa8	/* High Bit-Rate DSL, 2nd gen. */
-#define IFT_SHDSL		   0xa9	/* Multirate HDSL2 */
-#define IFT_DS1FDL		   0xaa	/* Facility Data Link (4Kbps) on a DS1*/
-#define IFT_POS			   0xab	/* Packet over SONET/SDH Interface */
-#define IFT_DVBASILN		   0xac	/* DVB-ASI Input */
-#define IFT_DVBASIOUT		   0xad	/* DVB-ASI Output */
-#define IFT_PLC			   0xae	/* Power Line Communications */
-#define IFT_NFAS		   0xaf	/* Non-Facility Associated Signaling */
-#define IFT_TR008		   0xb0	/* TROO8 */
-#define IFT_GR303RDT		   0xb1	/* Remote Digital Terminal */
-#define IFT_GR303IDT		   0xb2	/* Integrated Digital Terminal */
-#define IFT_ISUP		   0xb3	/* ISUP */
-#define IFT_PROPDOCSWIRELESSMACLAYER	   0xb4	/* prop/Wireless MAC Layer */
-#define IFT_PROPDOCSWIRELESSDOWNSTREAM	   0xb5	/* prop/Wireless Downstream */
-#define IFT_PROPDOCSWIRELESSUPSTREAM	   0xb6	/* prop/Wireless Upstream */
-#define IFT_HIPERLAN2		   0xb7	/* HIPERLAN Type 2 Radio Interface */
-#define IFT_PROPBWAP2MP		   0xb8	/* PropBroadbandWirelessAccess P2MP*/
-#define IFT_SONETOVERHEADCHANNEL   0xb9	/* SONET Overhead Channel */
-#define IFT_DIGITALWRAPPEROVERHEADCHANNEL  0xba	/* Digital Wrapper Overhead */
-#define IFT_AAL2		   0xbb	/* ATM adaptation layer 2 */
-#define IFT_RADIOMAC		   0xbc	/* MAC layer over radio links */
-#define IFT_ATMRADIO		   0xbd	/* ATM over radio links */
-#define IFT_IMT			   0xbe /* Inter-Machine Trunks */
-#define IFT_MVL			   0xbf /* Multiple Virtual Lines DSL */
-#define IFT_REACHDSL		   0xc0 /* Long Reach DSL */
-#define IFT_FRDLCIENDPT		   0xc1 /* Frame Relay DLCI End Point */
-#define IFT_ATMVCIENDPT		   0xc2 /* ATM VCI End Point */
-#define IFT_OPTICALCHANNEL	   0xc3 /* Optical Channel */
-#define IFT_OPTICALTRANSPORT	   0xc4 /* Optical Transport */
-#define IFT_PROPATM		   0xc5 /* Proprietary ATM */
-#define IFT_VOICEOVERCABLE	   0xc6 /* Voice Over Cable Interface */
-#define IFT_INFINIBAND		   0xc7 /* Infiniband */
-#define IFT_TELINK		   0xc8 /* TE Link */
-#define IFT_Q2931		   0xc9 /* Q.2931 */
-#define IFT_VIRTUALTG		   0xca /* Virtual Trunk Group */
-#define IFT_SIPTG		   0xcb /* SIP Trunk Group */
-#define IFT_SIPSIG		   0xcc /* SIP Signaling */
-#define IFT_DOCSCABLEUPSTREAMCHANNEL 0xcd /* CATV Upstream Channel */
-#define IFT_ECONET		   0xce /* Acorn Econet */
-#define IFT_PON155		   0xcf /* FSAN 155Mb Symetrical PON interface */
-#define IFT_PON622		   0xd0 /* FSAN 622Mb Symetrical PON interface */
-#define IFT_BRIDGE		   0xd1 /* Transparent bridge interface */
-#define IFT_LINEGROUP		   0xd2 /* Interface common to multiple lines */
-#define IFT_VOICEEMFGD		   0xd3 /* voice E&M Feature Group D */
-#define IFT_VOICEFGDEANA	   0xd4 /* voice FGD Exchange Access North American */
-#define IFT_VOICEDID		   0xd5 /* voice Direct Inward Dialing */
-#define IFT_STF			   0xd7	/* 6to4 interface */
-
-/* not based on IANA assignments - how should we treat these? */
-#define IFT_GIF		0xf0
-#define IFT_PVC		0xf1
-#define IFT_FAITH	0xf2
-#define IFT_PFLOG	0xf5		/* Packet filter logging */
-#define IFT_PFSYNC	0xf6		/* Packet filter state syncing */
-#define IFT_CARP	0xf8		/* Common Address Redundancy Protocol */
-
-#endif /* !_NET_IF_TYPES_H_ */
diff --git a/libc/include/net/route.h b/libc/include/net/route.h
index 326fbe7..9c53875 100644
--- a/libc/include/net/route.h
+++ b/libc/include/net/route.h
@@ -29,6 +29,7 @@
 #ifndef _NET_ROUTE_H_
 #define _NET_ROUTE_H_
 
+#include <sys/cdefs.h>
 #include <sys/socket.h>
 #include <linux/route.h>
 #include <linux/in6.h>
diff --git a/libc/include/netdb.h b/libc/include/netdb.h
index 3bb973c..7fcb11f 100644
--- a/libc/include/netdb.h
+++ b/libc/include/netdb.h
@@ -193,58 +193,37 @@
 #define	SCOPE_DELIMITER	'%'
 
 __BEGIN_DECLS
-#pragma GCC visibility push(default)
 
 /* BIONIC-BEGIN */
 #define  h_errno   (*__get_h_errno())
 int*  __get_h_errno(void);
 /* BIONIC-END */
-void endhostent(void);
-void endnetent(void);
-void endnetgrent(void);
-void endprotoent(void);
 void endservent(void);
-void freehostent(struct hostent *);
-struct hostent	*gethostbyaddr(const void *, socklen_t, int);
-int gethostbyaddr_r(const void *, socklen_t, int, struct hostent *, char *, size_t, struct hostent **, int *);
-struct hostent	*gethostbyname(const char *);
-int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *);
-struct hostent	*gethostbyname2(const char *, int);
-int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *);
-struct hostent	*gethostent(void);
-int gethostent_r(struct hostent *, char *, size_t, struct hostent **, int *);
-struct hostent	*getipnodebyaddr(const void *, size_t, int, int *);
-struct hostent	*getipnodebyname(const char *, int, int, int *);
-struct netent	*getnetbyaddr(uint32_t, int);
-int getnetbyaddr_r(uint32_t, int, struct netent *, char *, size_t, struct netent**, int *);
-struct netent	*getnetbyname(const char *);
-int getnetbyname_r(const char *, struct netent *, char *, size_t, struct netent **, int *);
-struct netent	*getnetent(void);
-int getnetent_r(struct netent *, char *, size_t, struct netent **, int *);
-int getnetgrent(char **, char **, char **);
-struct protoent	*getprotobyname(const char *);
-int getprotobyname_r(const char *, struct protoent *, char *, size_t, struct protoent **);
-struct protoent	*getprotobynumber(int);
-int getprotobynumber_r(int, struct protoent *, char *, size_t, struct protoent **);
-struct protoent	*getprotoent(void);
-int getprotoent_r(struct protoent *, char *, size_t, struct protoent **);
-struct servent	*getservbyname(const char *, const char *);
-struct servent	*getservbyport(int, const char *);
-struct servent	*getservent(void);
-void herror(const char *);
-const char	*hstrerror(int);
-int innetgr(const char *, const char *, const char *, const char *);
-void sethostent(int);
-void setnetent(int);
-void setprotoent(int);
+struct hostent* gethostbyaddr(const void*, socklen_t, int);
+int gethostbyaddr_r(const void*, socklen_t, int, struct hostent*, char*, size_t, struct hostent**,
+                    int*) __INTRODUCED_IN(23);
+struct hostent* gethostbyname(const char*);
+int gethostbyname_r(const char*, struct hostent*, char*, size_t, struct hostent**, int*);
+struct hostent* gethostbyname2(const char*, int);
+int gethostbyname2_r(const char*, int, struct hostent*, char*, size_t, struct hostent**, int*)
+  __INTRODUCED_IN(23);
+struct hostent* gethostent(void);
+struct netent* getnetbyaddr(uint32_t, int);
+struct netent* getnetbyname(const char*);
+struct protoent* getprotobyname(const char*);
+struct protoent* getprotobynumber(int);
+struct servent* getservbyname(const char*, const char*);
+struct servent* getservbyport(int, const char*);
+struct servent* getservent(void);
+void herror(const char*);
+const char* hstrerror(int);
+
 int getaddrinfo(const char *, const char *, const struct addrinfo *, struct addrinfo **);
 int getnameinfo(const struct sockaddr *, socklen_t, char *, size_t, char *, size_t, int);
 void freeaddrinfo(struct addrinfo *);
 const char	*gai_strerror(int);
-void setnetgrent(const char *);
 void setservent(int);
 
-#pragma GCC visibility pop
 __END_DECLS
 
 #endif /* !_NETDB_H_ */
diff --git a/libc/include/netinet/ether.h b/libc/include/netinet/ether.h
index a1c9cbb..e69cdaf 100644
--- a/libc/include/netinet/ether.h
+++ b/libc/include/netinet/ether.h
@@ -25,4 +25,20 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-#include <net/if_ether.h>
+
+#ifndef _NETINET_ETHER_H_
+#define _NETINET_ETHER_H_ 1
+
+#include <sys/cdefs.h>
+#include <netinet/if_ether.h>
+
+__BEGIN_DECLS
+
+char* ether_ntoa(const struct ether_addr*) __INTRODUCED_IN(11);
+char* ether_ntoa_r(const struct ether_addr*, char*) __INTRODUCED_IN(11);
+struct ether_addr* ether_aton(const char*) __INTRODUCED_IN(11);
+struct ether_addr* ether_aton_r(const char*, struct ether_addr*) __INTRODUCED_IN(11);
+
+__END_DECLS
+
+#endif
diff --git a/libc/include/netinet/icmp6.h b/libc/include/netinet/icmp6.h
index 6625712..eca7b45 100644
--- a/libc/include/netinet/icmp6.h
+++ b/libc/include/netinet/icmp6.h
@@ -66,6 +66,7 @@
 #define _NETINET_ICMP6_H_
 
 #include <netinet/in.h> /* android-added: glibc source compatibility. */
+#include <sys/cdefs.h>
 
 #define ICMPV6_PLD_MAXLEN	1232	/* IPV6_MMTU - sizeof(struct ip6_hdr)
 					   - sizeof(struct icmp6_hdr) */
@@ -107,13 +108,6 @@
 #define ICMP6_MEMBERSHIP_REPORT		131	/* group membership report */
 #define ICMP6_MEMBERSHIP_REDUCTION	132	/* group membership termination */
 
-#ifndef _KERNEL
-/* the followings are for backward compatibility to old KAME apps. */
-#define MLD6_LISTENER_QUERY	MLD_LISTENER_QUERY
-#define MLD6_LISTENER_REPORT	MLD_LISTENER_REPORT
-#define MLD6_LISTENER_DONE	MLD_LISTENER_DONE
-#endif
-
 #define ND_ROUTER_SOLICIT		133	/* router solicitation */
 #define ND_ROUTER_ADVERT		134	/* router advertisement */
 #define ND_NEIGHBOR_SOLICIT		135	/* neighbor solicitation */
@@ -134,12 +128,6 @@
 #define MLD_MTRACE_RESP			200	/* mtrace response(to sender) */
 #define MLD_MTRACE			201	/* mtrace messages */
 
-#ifndef _KERNEL
-/* the followings are for backward compatibility to old KAME apps. */
-#define MLD6_MTRACE_RESP	MLD_MTRACE_RESP
-#define MLD6_MTRACE		MLD_MTRACE
-#endif
-
 #define ICMP6_MAXTYPE			201
 
 #define ICMP6_DST_UNREACH_NOROUTE	0	/* no route to destination */
@@ -185,17 +173,6 @@
 	struct in6_addr		mld_addr; /* multicast address */
 } __packed;
 
-/* definitions to provide backward compatibility to old KAME applications */
-#ifndef _KERNEL
-#define mld6_hdr	mld_hdr
-#define mld6_type	mld_type
-#define mld6_code	mld_code
-#define mld6_cksum	mld_cksum
-#define mld6_maxdelay	mld_maxdelay
-#define mld6_reserved	mld_reserved
-#define mld6_addr	mld_addr
-#endif
-
 /* shortcut macro definitions */
 #define mld_type	mld_icmp6_hdr.icmp6_type
 #define mld_code	mld_icmp6_hdr.icmp6_code
@@ -562,233 +539,4 @@
  * END android-changed
  */
 
-/*
- * Variables related to this implementation
- * of the internet control message protocol version 6.
- */
-
-/*
- * IPv6 ICMP statistics.
- * Each counter is an unsigned 64-bit value.
- */
-#define	ICMP6_STAT_ERROR	0	/* # of calls to icmp6_error */
-#define	ICMP6_STAT_CANTERROR	1	/* no error (old was icmp) */
-#define	ICMP6_STAT_TOOFREQ	2	/* no error (rate limitation) */
-#define	ICMP6_STAT_OUTHIST	3	/* # of output messages */
-		/* space for 256 counters */
-#define	ICMP6_STAT_BADCODE	259	/* icmp6_code out of range */
-#define	ICMP6_STAT_TOOSHORT	260	/* packet < sizeof(struct icmp6_hdr) */
-#define	ICMP6_STAT_CHECKSUM	261	/* bad checksum */
-#define	ICMP6_STAT_BADLEN	262	/* calculated bound mismatch */
-	/*
-	 * number of responses; this member is inherited from the netinet code,
-	 * but for netinet6 code, it is already available in outhist[].
-	 */
-#define	ICMP6_STAT_REFLECT	263
-#define	ICMP6_STAT_INHIST	264	/* # of input messages */
-		/* space for 256 counters */
-#define	ICMP6_STAT_ND_TOOMANYOPT 520	/* too many ND options */
-#define	ICMP6_STAT_OUTERRHIST	521
-		/* space for 13 counters */
-#define	ICMP6_STAT_PMTUCHG	534	/* path MTU changes */
-#define	ICMP6_STAT_ND_BADOPT	535	/* bad ND options */
-#define	ICMP6_STAT_BADNS	536	/* bad neighbor solicititation */
-#define	ICMP6_STAT_BADNA	537	/* bad neighbor advertisement */
-#define	ICMP6_STAT_BADRS	538	/* bad router solicitiation */
-#define	ICMP6_STAT_BADRA	539	/* bad router advertisement */
-#define	ICMP6_STAT_BADREDIRECT	540	/* bad redirect message */
-#define ICMP6_STAT_DROPPED_RAROUTE 541	/* discarded routes from router advertisement */
-
-#define	ICMP6_NSTATS		542
-
-#define	ICMP6_ERRSTAT_DST_UNREACH_NOROUTE	0
-#define	ICMP6_ERRSTAT_DST_UNREACH_ADMIN		1
-#define	ICMP6_ERRSTAT_DST_UNREACH_BEYONDSCOPE	2
-#define	ICMP6_ERRSTAT_DST_UNREACH_ADDR		3
-#define	ICMP6_ERRSTAT_DST_UNREACH_NOPORT	4
-#define	ICMP6_ERRSTAT_PACKET_TOO_BIG		5
-#define	ICMP6_ERRSTAT_TIME_EXCEED_TRANSIT	6
-#define	ICMP6_ERRSTAT_TIME_EXCEED_REASSEMBLY	7
-#define	ICMP6_ERRSTAT_PARAMPROB_HEADER		8
-#define	ICMP6_ERRSTAT_PARAMPROB_NEXTHEADER	9
-#define	ICMP6_ERRSTAT_PARAMPROB_OPTION		10
-#define	ICMP6_ERRSTAT_REDIRECT			11
-#define	ICMP6_ERRSTAT_UNKNOWN			12
-
-/*
- * Names for ICMP sysctl objects
- */
-#define ICMPV6CTL_STATS		1
-#define ICMPV6CTL_REDIRACCEPT	2	/* accept/process redirects */
-#define ICMPV6CTL_REDIRTIMEOUT	3	/* redirect cache time */
-#if 0	/*obsoleted*/
-#define ICMPV6CTL_ERRRATELIMIT	5	/* ICMPv6 error rate limitation */
-#endif
-#define ICMPV6CTL_ND6_PRUNE	6
-#define ICMPV6CTL_ND6_DELAY	8
-#define ICMPV6CTL_ND6_UMAXTRIES	9
-#define ICMPV6CTL_ND6_MMAXTRIES		10
-#define ICMPV6CTL_ND6_USELOOPBACK	11
-/*#define ICMPV6CTL_ND6_PROXYALL	12	obsoleted, do not reuse here */
-#define ICMPV6CTL_NODEINFO	13
-#define ICMPV6CTL_ERRPPSLIMIT	14	/* ICMPv6 error pps limitation */
-#define ICMPV6CTL_ND6_MAXNUDHINT	15
-#define ICMPV6CTL_MTUDISC_HIWAT	16
-#define ICMPV6CTL_MTUDISC_LOWAT	17
-#define ICMPV6CTL_ND6_DEBUG	18
-#define ICMPV6CTL_ND6_DRLIST	19
-#define ICMPV6CTL_ND6_PRLIST	20
-#define	ICMPV6CTL_ND6_MAXQLEN	24
-#define ICMPV6CTL_MAXID		25
-
-#define ICMPV6CTL_NAMES { \
-	{ 0, 0 }, \
-	{ 0, 0 }, \
-	{ "rediraccept", CTLTYPE_INT }, \
-	{ "redirtimeout", CTLTYPE_INT }, \
-	{ 0, 0 }, \
-	{ 0, 0 }, \
-	{ "nd6_prune", CTLTYPE_INT }, \
-	{ 0, 0 }, \
-	{ "nd6_delay", CTLTYPE_INT }, \
-	{ "nd6_umaxtries", CTLTYPE_INT }, \
-	{ "nd6_mmaxtries", CTLTYPE_INT }, \
-	{ "nd6_useloopback", CTLTYPE_INT }, \
-	{ 0, 0 }, \
-	{ "nodeinfo", CTLTYPE_INT }, \
-	{ "errppslimit", CTLTYPE_INT }, \
-	{ "nd6_maxnudhint", CTLTYPE_INT }, \
-	{ "mtudisc_hiwat", CTLTYPE_INT }, \
-	{ "mtudisc_lowat", CTLTYPE_INT }, \
-	{ "nd6_debug", CTLTYPE_INT }, \
-	{ 0, 0 }, \
-	{ 0, 0 }, \
-	{ 0, 0 }, \
-	{ 0, 0 }, \
-	{ 0, 0 }, \
-	{ "nd6_maxqueuelen", CTLTYPE_INT }, \
-}
-
-#ifdef _KERNEL
-struct	rtentry;
-struct	rttimer;
-struct	in6_multi;
-
-void	icmp6_init(void);
-void	icmp6_paramerror(struct mbuf *, int);
-void	icmp6_error(struct mbuf *, int, int, int);
-void	icmp6_error2(struct mbuf *, int, int, int, struct ifnet *);
-int	icmp6_input(struct mbuf **, int *, int);
-void	icmp6_fasttimo(void);
-void	icmp6_reflect(struct mbuf *, size_t);
-void	icmp6_prepare(struct mbuf *);
-void	icmp6_redirect_input(struct mbuf *, int);
-void	icmp6_redirect_output(struct mbuf *, struct rtentry *);
-int	icmp6_sysctl(int *, u_int, void *, size_t *, void *, size_t);
-
-void	icmp6_statinc(u_int);
-
-struct	ip6ctlparam;
-void	icmp6_mtudisc_update(struct ip6ctlparam *, int);
-void	icmp6_mtudisc_callback_register(void (*)(struct in6_addr *));
-
-/* XXX: is this the right place for these macros? */
-#define icmp6_ifstat_inc(ifp, tag) \
-do {								\
-	if (ifp)						\
-		((struct in6_ifextra *)((ifp)->if_afdata[AF_INET6]))->icmp6_ifstat->tag++; \
-} while (/*CONSTCOND*/ 0)
-
-#define icmp6_ifoutstat_inc(ifp, type, code) \
-do { \
-		icmp6_ifstat_inc(ifp, ifs6_out_msg); \
-		switch(type) { \
-		 case ICMP6_DST_UNREACH: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_dstunreach); \
-			 if (code == ICMP6_DST_UNREACH_ADMIN) \
-				 icmp6_ifstat_inc(ifp, ifs6_out_adminprohib); \
-			 break; \
-		 case ICMP6_PACKET_TOO_BIG: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_pkttoobig); \
-			 break; \
-		 case ICMP6_TIME_EXCEEDED: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_timeexceed); \
-			 break; \
-		 case ICMP6_PARAM_PROB: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_paramprob); \
-			 break; \
-		 case ICMP6_ECHO_REQUEST: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_echo); \
-			 break; \
-		 case ICMP6_ECHO_REPLY: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_echoreply); \
-			 break; \
-		 case MLD_LISTENER_QUERY: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_mldquery); \
-			 break; \
-		 case MLD_LISTENER_REPORT: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_mldreport); \
-			 break; \
-		 case MLD_LISTENER_DONE: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_mlddone); \
-			 break; \
-		 case ND_ROUTER_SOLICIT: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_routersolicit); \
-			 break; \
-		 case ND_ROUTER_ADVERT: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_routeradvert); \
-			 break; \
-		 case ND_NEIGHBOR_SOLICIT: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_neighborsolicit); \
-			 break; \
-		 case ND_NEIGHBOR_ADVERT: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_neighboradvert); \
-			 break; \
-		 case ND_REDIRECT: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_redirect); \
-			 break; \
-		} \
-} while (/*CONSTCOND*/ 0)
-
-extern int	icmp6_rediraccept;	/* accept/process redirects */
-extern int	icmp6_redirtimeout;	/* cache time for redirect routes */
-#endif /* _KERNEL */
-
-#ifdef ICMP6_STRINGS
-/* Info: http://www.iana.org/assignments/icmpv6-parameters */
-
-static const char * const icmp6_type_err[] = {
-	"reserved0", "unreach", "packet_too_big", "timxceed", "paramprob",
-	NULL
-};
-
-static const char * const icmp6_type_info[] = {
-	"echo", "echoreply",
-	"mcastlistenq", "mcastlistenrep", "mcastlistendone",
-	"rtsol", "rtadv", "neighsol", "neighadv", "redirect",
-	"routerrenum", "nodeinfoq", "nodeinfor", "invneighsol", "invneighrep",
-	"mcastlistenrep2", "haad_req", "haad_rep",
-	"mobile_psol", "mobile_padv", "cga_sol", "cga_adv",
-	"experimental150", "mcast_rtadv", "mcast_rtsol", "mcast_rtterm",
-	"fmipv6_msg", "rpl_control", NULL
-};
-
-static const char * const icmp6_code_none[] = { "none", NULL };
-
-static const char * const icmp6_code_unreach[] = {
-	"noroute", "admin", "beyondscope", "addr", "port",
-	"srcaddr_policy", "reject_route", "source_route_err", NULL
-};
-
-static const char * const icmp6_code_timxceed[] = {
-	"intrans", "reass", NULL
-};
-
-static const char * const icmp6_code_paramprob[] = {
-	"hdr_field", "nxthdr_type", "option", NULL
-};      
-
-/* not all informational icmps that have codes have a names array */
-#endif
-
 #endif /* !_NETINET_ICMP6_H_ */
diff --git a/libc/include/netinet/if_ether.h b/libc/include/netinet/if_ether.h
index e4317fa..b1b9ed0 100644
--- a/libc/include/netinet/if_ether.h
+++ b/libc/include/netinet/if_ether.h
@@ -1,35 +1,110 @@
+/*	$NetBSD: if_ether.h,v 1.34 2007/12/25 18:33:46 perry Exp $	*/
+
 /*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
+ * Copyright (c) 1982, 1986, 1993
+ *	The Regents of the University of California.  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
+ * 1. 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.
+ * 2. 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
  *
- * 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
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ *
+ *	@(#)if_ether.h	8.3 (Berkeley) 5/2/95
  */
 
-#include <sys/socket.h>
+#ifndef _NETINET_IF_ETHER_H_
+#define _NETINET_IF_ETHER_H_
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#if defined(__USE_BSD)
+
+/* pull in Ethernet-specific definitions and packet structures */
+
 #include <linux/if_ether.h>
-#include <linux/if_arp.h>
-#ifndef ETHER_ADDR_LEN
-#define ETHER_ADDR_LEN ETH_ALEN
-#include <net/ethertypes.h>
-#endif
+
+/* pull in ARP-specific definitions and packet structures */
+
+#include <net/if_arp.h>
+
+#include <net/ethernet.h>
+
+/* ... and define some more which we don't need anymore: */
+
+/*
+ * Ethernet Address Resolution Protocol.
+ *
+ * See RFC 826 for protocol description.  Structure below is not
+ * used by our kernel!!! Only for userland programs which are externally
+ * maintained and need it.
+ */
+
+struct	ether_arp {
+	struct	 arphdr ea_hdr;			/* fixed-size header */
+	u_int8_t arp_sha[ETHER_ADDR_LEN];	/* sender hardware address */
+	u_int8_t arp_spa[4];			/* sender protocol address */
+	u_int8_t arp_tha[ETHER_ADDR_LEN];	/* target hardware address */
+	u_int8_t arp_tpa[4];			/* target protocol address */
+} __packed;
+#define	arp_hrd	ea_hdr.ar_hrd
+#define	arp_pro	ea_hdr.ar_pro
+#define	arp_hln	ea_hdr.ar_hln
+#define	arp_pln	ea_hdr.ar_pln
+#define	arp_op	ea_hdr.ar_op
+
+/*
+ * Macro to map an IP multicast address to an Ethernet multicast address.
+ * The high-order 25 bits of the Ethernet address are statically assigned,
+ * and the low-order 23 bits are taken from the low end of the IP address.
+ */
+#define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr)				\
+	/* struct in_addr *ipaddr; */					\
+	/* u_int8_t enaddr[ETHER_ADDR_LEN]; */				\
+{									\
+	(enaddr)[0] = 0x01;						\
+	(enaddr)[1] = 0x00;						\
+	(enaddr)[2] = 0x5e;						\
+	(enaddr)[3] = ((u_int8_t *)ipaddr)[1] & 0x7f;			\
+	(enaddr)[4] = ((u_int8_t *)ipaddr)[2];				\
+	(enaddr)[5] = ((u_int8_t *)ipaddr)[3];				\
+}
+/*
+ * Macro to map an IP6 multicast address to an Ethernet multicast address.
+ * The high-order 16 bits of the Ethernet address are statically assigned,
+ * and the low-order 32 bits are taken from the low end of the IP6 address.
+ */
+#define ETHER_MAP_IPV6_MULTICAST(ip6addr, enaddr)			\
+	/* struct in6_addr *ip6addr; */					\
+	/* u_int8_t enaddr[ETHER_ADDR_LEN]; */				\
+{                                                                       \
+	(enaddr)[0] = 0x33;						\
+	(enaddr)[1] = 0x33;						\
+	(enaddr)[2] = ((u_int8_t *)ip6addr)[12];			\
+	(enaddr)[3] = ((u_int8_t *)ip6addr)[13];			\
+	(enaddr)[4] = ((u_int8_t *)ip6addr)[14];			\
+	(enaddr)[5] = ((u_int8_t *)ip6addr)[15];			\
+}
+
+#endif /* __USE_BSD */
+
+#endif /* !_NET_IF_ETHER_H_ */
diff --git a/libc/include/netinet/in.h b/libc/include/netinet/in.h
index 5f3d11f..b524b05 100644
--- a/libc/include/netinet/in.h
+++ b/libc/include/netinet/in.h
@@ -49,8 +49,8 @@
 
 int bindresvport(int, struct sockaddr_in*);
 
-extern const struct in6_addr in6addr_any;
-extern const struct in6_addr in6addr_loopback;
+extern const struct in6_addr in6addr_any __INTRODUCED_IN(24);
+extern const struct in6_addr in6addr_loopback __INTRODUCED_IN(24);
 
 __END_DECLS
 
diff --git a/libc/include/netinet/in6.h b/libc/include/netinet/in6.h
index 879ac75..ae20f83 100644
--- a/libc/include/netinet/in6.h
+++ b/libc/include/netinet/in6.h
@@ -29,33 +29,34 @@
 #ifndef _NETINET_IN6_H
 #define _NETINET_IN6_H
 
+#include <sys/cdefs.h>
+
 #include <linux/in6.h>
 
 #define IN6_IS_ADDR_UNSPECIFIED(a) \
-  ((*(const uint32_t*)(&(a)->s6_addr[0]) == 0) && \
-   (*(const uint32_t*)(&(a)->s6_addr[4]) == 0) && \
-   (*(const uint32_t*)(&(a)->s6_addr[8]) == 0) && \
-   (*(const uint32_t*)(&(a)->s6_addr[12]) == 0))
+  ((((a)->s6_addr32[0]) == 0) && \
+   (((a)->s6_addr32[1]) == 0) && \
+   (((a)->s6_addr32[2]) == 0) && \
+   (((a)->s6_addr32[3]) == 0))
 
 #define IN6_IS_ADDR_LOOPBACK(a) \
-  ((*(const uint32_t*)(&(a)->s6_addr[0]) == 0) && \
-   (*(const uint32_t*)(&(a)->s6_addr[4]) == 0) && \
-   (*(const uint32_t*)(&(a)->s6_addr[8]) == 0) && \
-   (*(const uint32_t*)(&(a)->s6_addr[12]) == ntohl(1)))
+  ((((a)->s6_addr32[0]) == 0) && \
+   (((a)->s6_addr32[1]) == 0) && \
+   (((a)->s6_addr32[2]) == 0) && \
+   (((a)->s6_addr32[3]) == ntohl(1)))
 
 #define IN6_IS_ADDR_V4COMPAT(a) \
-  ((*(const uint32_t*)(&(a)->s6_addr[0]) == 0) && \
-   (*(const uint32_t*)(&(a)->s6_addr[4]) == 0) && \
-   (*(const uint32_t*)(&(a)->s6_addr[8]) == 0) && \
-   (*(const uint32_t*)(&(a)->s6_addr[12]) != 0) && \
-   (*(const uint32_t*)(&(a)->s6_addr[12]) != ntohl(1)))
+  ((((a)->s6_addr32[0]) == 0) && \
+   (((a)->s6_addr32[1]) == 0) && \
+   (((a)->s6_addr32[2]) == 0) && \
+   (((a)->s6_addr32[3]) != 0) && (((a)->s6_addr32[3]) != ntohl(1)))
 
 #define IN6_IS_ADDR_V4MAPPED(a) \
-  ((*(const uint32_t*)(&(a)->s6_addr[0]) == 0) && \
-   (*(const uint32_t*)(&(a)->s6_addr[4]) == 0) && \
-   (*(const uint32_t*)(&(a)->s6_addr[8]) == ntohl(0x0000ffff)))
+  ((((a)->s6_addr32[0]) == 0) && \
+   (((a)->s6_addr32[1]) == 0) && \
+   (((a)->s6_addr32[2]) == ntohl(0x0000ffff)))
 
-#define __bionic_s6_addr(a) ((const uint8_t*)(a))
+#define __bionic_s6_addr(a) __BIONIC_CAST(reinterpret_cast, const uint8_t*, a)
 
 #define IN6_IS_ADDR_LINKLOCAL(a) \
   ((__bionic_s6_addr(a)[0] == 0xfe) && ((__bionic_s6_addr(a)[1] & 0xc0) == 0x80))
diff --git a/libc/include/netinet/in_systm.h b/libc/include/netinet/in_systm.h
index ff53fb7..8da19a5 100644
--- a/libc/include/netinet/in_systm.h
+++ b/libc/include/netinet/in_systm.h
@@ -34,6 +34,9 @@
 #ifndef _NETINET_IN_SYSTM_H_
 #define _NETINET_IN_SYSTM_H_
 
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
 /*
  * Miscellaneous internetwork
  * definitions for kernel.
@@ -52,8 +55,4 @@
 
 typedef u_int32_t n_time;		/* ms since 00:00 GMT, byte rev */
 
-#ifdef _KERNEL
-n_time	 iptime (void);
-#endif
-
 #endif /* !_NETINET_IN_SYSTM_H_ */
diff --git a/libc/include/netinet/ip6.h b/libc/include/netinet/ip6.h
index aa816c2..639637e 100644
--- a/libc/include/netinet/ip6.h
+++ b/libc/include/netinet/ip6.h
@@ -64,6 +64,11 @@
 #ifndef _NETINET_IP6_H_
 #define _NETINET_IP6_H_
 
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <linux/in6.h>
+
 /*
  * Definition for internet protocol version 6.
  * RFC 2460
@@ -108,20 +113,6 @@
 #define IP6TOS_ECT		0x02	/* ECN-capable transport */
 #endif
 
-#ifdef _KERNEL
-/*
- * for IPv6 pseudo header checksum
- * XXX nonstandard
- */
-struct ip6_hdr_pseudo {
-	struct in6_addr ip6ph_src;
-	struct in6_addr ip6ph_dst;
-	u_int32_t	ip6ph_len;
-	u_int8_t	ip6ph_zero[3];
-	u_int8_t	ip6ph_nxt;
-} __packed;
-#endif
-
 /*
  * Extension Headers
  */
@@ -267,53 +258,4 @@
 #define IPV6_MMTU	1280	/* minimal MTU and reassembly. 1024 + 256 */
 #define IPV6_MAXPACKET	65535	/* ip6 max packet size without Jumbo payload*/
 
-#ifdef _KERNEL
-/*
- * IP6_EXTHDR_GET ensures that intermediate protocol header (from "off" to
- * "len") is located in single mbuf, on contiguous memory region.
- * The pointer to the region will be returned to pointer variable "val",
- * with type "typ".
- * IP6_EXTHDR_GET0 does the same, except that it aligns the structure at the
- * very top of mbuf.  GET0 is likely to make memory copy than GET.
- *
- * XXX we're now testing this, needs m_pulldown()
- */
-#define IP6_EXTHDR_GET(val, typ, m, off, len) \
-do {									\
-	struct mbuf *_t;						\
-	int _tmp;							\
-	if ((m)->m_len >= (off) + (len))				\
-		(val) = (typ)(mtod((m), char *) + (off));		\
-	else {								\
-		_t = m_pulldown((m), (off), (len), &_tmp);		\
-		if (_t) {						\
-			if (_t->m_len < _tmp + (len))			\
-				panic("m_pulldown malfunction");	\
-			(val) = (typ)(mtod(_t, char *) + _tmp);	\
-		} else {						\
-			(val) = (typ)NULL;				\
-			(m) = NULL;					\
-		}							\
-	}								\
-} while (/*CONSTCOND*/ 0)
-
-#define IP6_EXTHDR_GET0(val, typ, m, off, len) \
-do {									\
-	struct mbuf *_t;						\
-	if ((off) == 0 && (m)->m_len >= len)				\
-		(val) = (typ)mtod((m), void *);			\
-	else {								\
-		_t = m_pulldown((m), (off), (len), NULL);		\
-		if (_t) {						\
-			if (_t->m_len < (len))				\
-				panic("m_pulldown malfunction");	\
-			(val) = (typ)mtod(_t, void *);			\
-		} else {						\
-			(val) = (typ)NULL;				\
-			(m) = NULL;					\
-		}							\
-	}								\
-} while (/*CONSTCOND*/ 0)
-#endif /*_KERNEL*/
-
 #endif /* !_NETINET_IP6_H_ */
diff --git a/libc/include/netinet/tcp.h b/libc/include/netinet/tcp.h
index 5601645..147f6f7 100644
--- a/libc/include/netinet/tcp.h
+++ b/libc/include/netinet/tcp.h
@@ -29,10 +29,57 @@
 #ifndef _NETINET_TCP_H
 #define _NETINET_TCP_H
 
+#include <sys/cdefs.h>
+#include <stdint.h>
+
+#define tcphdr __kernel_tcphdr
 #include <linux/tcp.h>
+#undef tcphdr
 
 __BEGIN_DECLS
 
+struct tcphdr {
+  __extension__ union {
+    struct {
+      uint16_t th_sport;
+      uint16_t th_dport;
+      uint32_t th_seq;
+      uint32_t th_ack;
+      uint8_t th_x2:4;
+      uint8_t th_off:4;
+      uint8_t th_flags;
+      uint16_t th_win;
+      uint16_t th_sum;
+      uint16_t th_urp;
+    };
+    struct {
+      uint16_t source;
+      uint16_t dest;
+      uint32_t seq;
+      uint32_t ack_seq;
+      uint16_t res1:4;
+      uint16_t doff:4;
+      uint16_t fin:1;
+      uint16_t syn:1;
+      uint16_t rst:1;
+      uint16_t psh:1;
+      uint16_t ack:1;
+      uint16_t urg:1;
+      uint16_t res2:2;
+      uint16_t window;
+      uint16_t check;
+      uint16_t urg_ptr;
+    };
+  };
+};
+
+#define TH_FIN 0x01
+#define TH_SYN 0x02
+#define TH_RST 0x04
+#define TH_PUSH 0x08
+#define TH_ACK 0x10
+#define TH_URG 0x20
+
 enum {
   TCP_ESTABLISHED = 1,
   TCP_SYN_SENT,
diff --git a/libc/include/netinet/udp.h b/libc/include/netinet/udp.h
index d4eb368..ef517d6 100644
--- a/libc/include/netinet/udp.h
+++ b/libc/include/netinet/udp.h
@@ -29,6 +29,7 @@
 #ifndef _NETINET_UDP_H
 #define _NETINET_UDP_H
 
+#include <sys/cdefs.h>
 #include <sys/types.h>
 
 #include <linux/udp.h>
diff --git a/libstdc++/include/cassert b/libc/include/nl_types.h
similarity index 76%
rename from libstdc++/include/cassert
rename to libc/include/nl_types.h
index 5753e34..bcaab06 100644
--- a/libstdc++/include/cassert
+++ b/libc/include/nl_types.h
@@ -1,6 +1,5 @@
-/* -*- c++ -*- */
 /*
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2016 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -27,13 +26,23 @@
  * SUCH DAMAGE.
  */
 
-/*
- * Standard C++ Library wrapper around the C assert.h header file.  This file
- * can be included multiple times with different definition of NDEBUG, hence the
- * absence of include guards.
- */
+#ifndef _NL_TYPES_H_
+#define _NL_TYPES_H_
 
-#ifndef BIONIC_LIBSTDCPP_INCLUDE_CASSERT__
-#define BIONIC_LIBSTDCPP_INCLUDE_CASSERT__
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
+#define NL_CAT_LOCALE 1
+#define NL_SETD 1
+
+typedef void* nl_catd;
+typedef int nl_item;
+
+nl_catd catopen(const char*, int) __INTRODUCED_IN_FUTURE;
+char* catgets(nl_catd, int, int, const char*) __INTRODUCED_IN_FUTURE;
+int catclose(nl_catd) __INTRODUCED_IN_FUTURE;
+
+__END_DECLS
+
 #endif
-#include <assert.h>
diff --git a/libc/include/paths.h b/libc/include/paths.h
index 82c2804..b76d045 100644
--- a/libc/include/paths.h
+++ b/libc/include/paths.h
@@ -32,9 +32,11 @@
 #ifndef _PATHS_H_
 #define	_PATHS_H_
 
+#include <sys/cdefs.h>
+
 #define	_PATH_BSHELL	"/system/bin/sh"
 #define	_PATH_CONSOLE	"/dev/console"
-#define	_PATH_DEFPATH	"/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin"
+#define	_PATH_DEFPATH	"/sbin:/system/sbin:/system/bin:/system/xbin:/vendor/bin:/vendor/xbin"
 #define	_PATH_DEV	"/dev/"
 #define	_PATH_DEVNULL	"/dev/null"
 #define	_PATH_KLOG	"/proc/kmsg"
diff --git a/libc/include/poll.h b/libc/include/poll.h
index 7c16d81..0fa55d2 100644
--- a/libc/include/poll.h
+++ b/libc/include/poll.h
@@ -39,18 +39,21 @@
 typedef unsigned int nfds_t;
 
 int poll(struct pollfd*, nfds_t, int);
-int ppoll(struct pollfd*, nfds_t, const struct timespec*, const sigset_t*);
+int ppoll(struct pollfd*, nfds_t, const struct timespec*, const sigset_t*) __INTRODUCED_IN(21);
 
-int __poll_chk(struct pollfd*, nfds_t, int, size_t);
+int __poll_chk(struct pollfd*, nfds_t, int, size_t) __INTRODUCED_IN(23);
 int __poll_real(struct pollfd*, nfds_t, int) __RENAME(poll);
 __errordecl(__poll_too_small_error, "poll: pollfd array smaller than fd count");
 
-int __ppoll_chk(struct pollfd*, nfds_t, const struct timespec*, const sigset_t*, size_t);
-int __ppoll_real(struct pollfd*, nfds_t, const struct timespec*, const sigset_t*) __RENAME(ppoll);
+int __ppoll_chk(struct pollfd*, nfds_t, const struct timespec*, const sigset_t*, size_t)
+  __INTRODUCED_IN(23);
+int __ppoll_real(struct pollfd*, nfds_t, const struct timespec*, const sigset_t*) __RENAME(ppoll)
+  __INTRODUCED_IN(21);
 __errordecl(__ppoll_too_small_error, "ppoll: pollfd array smaller than fd count");
 
 #if defined(__BIONIC_FORTIFY)
 
+#if __ANDROID_API__ >= 23
 __BIONIC_FORTIFY_INLINE
 int poll(struct pollfd* fds, nfds_t fd_count, int timeout) {
 #if defined(__clang__)
@@ -82,6 +85,7 @@
   return __ppoll_real(fds, fd_count, timeout, mask);
 #endif
 }
+#endif /* __ANDROID_API__ >= 23 */
 
 #endif
 
diff --git a/libc/include/pthread.h b/libc/include/pthread.h
index 50f2024..1153695 100644
--- a/libc/include/pthread.h
+++ b/libc/include/pthread.h
@@ -36,6 +36,13 @@
 #include <sys/types.h>
 #include <time.h>
 
+__BEGIN_DECLS
+
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnullability-completeness"
+#endif
+
 typedef struct {
 #if defined(__LP64__)
   int32_t __private[10];
@@ -131,123 +138,125 @@
 #define PTHREAD_SCOPE_SYSTEM     0
 #define PTHREAD_SCOPE_PROCESS    1
 
-__BEGIN_DECLS
+int pthread_atfork(void (*)(void), void (*)(void), void (*)(void)) __INTRODUCED_IN(12);
 
-int pthread_atfork(void (*)(void), void (*)(void), void(*)(void));
+int pthread_attr_destroy(pthread_attr_t* _Nonnull);
+int pthread_attr_getdetachstate(const pthread_attr_t* _Nonnull, int* _Nonnull);
+int pthread_attr_getguardsize(const pthread_attr_t* _Nonnull, size_t* _Nonnull);
+int pthread_attr_getschedparam(const pthread_attr_t* _Nonnull, struct sched_param* _Nonnull);
+int pthread_attr_getschedpolicy(const pthread_attr_t* _Nonnull, int* _Nonnull);
+int pthread_attr_getscope(const pthread_attr_t* _Nonnull, int* _Nonnull);
+int pthread_attr_getstack(const pthread_attr_t* _Nonnull, void** _Nonnull, size_t* _Nonnull);
+int pthread_attr_getstacksize(const pthread_attr_t* _Nonnull, size_t* _Nonnull);
+int pthread_attr_init(pthread_attr_t* _Nonnull);
+int pthread_attr_setdetachstate(pthread_attr_t* _Nonnull, int);
+int pthread_attr_setguardsize(pthread_attr_t* _Nonnull, size_t);
+int pthread_attr_setschedparam(pthread_attr_t* _Nonnull, const struct sched_param* _Nonnull);
+int pthread_attr_setschedpolicy(pthread_attr_t* _Nonnull, int);
+int pthread_attr_setscope(pthread_attr_t* _Nonnull, int);
+int pthread_attr_setstack(pthread_attr_t* _Nonnull, void*, size_t);
+int pthread_attr_setstacksize(pthread_attr_t* _Nonnull, size_t);
 
-int pthread_attr_destroy(pthread_attr_t*) __nonnull((1));
-int pthread_attr_getdetachstate(const pthread_attr_t*, int*) __nonnull((1, 2));
-int pthread_attr_getguardsize(const pthread_attr_t*, size_t*) __nonnull((1, 2));
-int pthread_attr_getschedparam(const pthread_attr_t*, struct sched_param*) __nonnull((1, 2));
-int pthread_attr_getschedpolicy(const pthread_attr_t*, int*) __nonnull((1, 2));
-int pthread_attr_getscope(const pthread_attr_t*, int*) __nonnull((1, 2));
-int pthread_attr_getstack(const pthread_attr_t*, void**, size_t*) __nonnull((1, 2, 3));
-int pthread_attr_getstacksize(const pthread_attr_t*, size_t*) __nonnull((1, 2));
-int pthread_attr_init(pthread_attr_t*) __nonnull((1));
-int pthread_attr_setdetachstate(pthread_attr_t*, int) __nonnull((1));
-int pthread_attr_setguardsize(pthread_attr_t*, size_t) __nonnull((1));
-int pthread_attr_setschedparam(pthread_attr_t*, const struct sched_param*) __nonnull((1, 2));
-int pthread_attr_setschedpolicy(pthread_attr_t*, int) __nonnull((1));
-int pthread_attr_setscope(pthread_attr_t*, int) __nonnull((1));
-int pthread_attr_setstack(pthread_attr_t*, void*, size_t) __nonnull((1));
-int pthread_attr_setstacksize(pthread_attr_t*, size_t) __nonnull((1));
+int pthread_condattr_destroy(pthread_condattr_t* _Nonnull);
+int pthread_condattr_getclock(const pthread_condattr_t* _Nonnull, clockid_t* _Nonnull)
+  __INTRODUCED_IN(21);
+int pthread_condattr_getpshared(const pthread_condattr_t* _Nonnull, int* _Nonnull);
+int pthread_condattr_init(pthread_condattr_t* _Nonnull);
+int pthread_condattr_setclock(pthread_condattr_t* _Nonnull, clockid_t) __INTRODUCED_IN(21);
+int pthread_condattr_setpshared(pthread_condattr_t* _Nonnull, int);
 
-int pthread_condattr_destroy(pthread_condattr_t*) __nonnull((1));
-int pthread_condattr_getclock(const pthread_condattr_t*, clockid_t*) __nonnull((1, 2));
-int pthread_condattr_getpshared(const pthread_condattr_t*, int*) __nonnull((1, 2));
-int pthread_condattr_init(pthread_condattr_t*) __nonnull((1));
-int pthread_condattr_setclock(pthread_condattr_t*, clockid_t) __nonnull((1));
-int pthread_condattr_setpshared(pthread_condattr_t*, int) __nonnull((1));
+int pthread_cond_broadcast(pthread_cond_t* _Nonnull);
+int pthread_cond_destroy(pthread_cond_t* _Nonnull);
+int pthread_cond_init(pthread_cond_t* _Nonnull, const pthread_condattr_t*);
+int pthread_cond_signal(pthread_cond_t* _Nonnull);
+int pthread_cond_timedwait(pthread_cond_t* _Nonnull, pthread_mutex_t* _Nonnull,
+                           const struct timespec* _Nonnull);
+int pthread_cond_wait(pthread_cond_t* _Nonnull, pthread_mutex_t* _Nonnull);
 
-int pthread_cond_broadcast(pthread_cond_t*) __nonnull((1));
-int pthread_cond_destroy(pthread_cond_t*) __nonnull((1));
-int pthread_cond_init(pthread_cond_t*, const pthread_condattr_t*) __nonnull((1));
-int pthread_cond_signal(pthread_cond_t*) __nonnull((1));
-int pthread_cond_timedwait(pthread_cond_t*, pthread_mutex_t*, const struct timespec*) __nonnull((1, 2, 3));
-int pthread_cond_wait(pthread_cond_t*, pthread_mutex_t*) __nonnull((1, 2));
-
-int pthread_create(pthread_t*, pthread_attr_t const*, void *(*)(void*), void*) __nonnull((1, 3));
+int pthread_create(pthread_t* _Nonnull, pthread_attr_t const*,
+                   void* (* _Nonnull start_routine)(void*), void*);
 int pthread_detach(pthread_t);
 void pthread_exit(void*) __noreturn;
 
 int pthread_equal(pthread_t, pthread_t);
 
-int pthread_getattr_np(pthread_t, pthread_attr_t*) __nonnull((2));
+int pthread_getattr_np(pthread_t, pthread_attr_t* _Nonnull);
 
-int pthread_getcpuclockid(pthread_t, clockid_t*) __nonnull((2));
+int pthread_getcpuclockid(pthread_t, clockid_t* _Nonnull);
 
-int pthread_getschedparam(pthread_t, int*, struct sched_param*) __nonnull((2, 3));
+int pthread_getschedparam(pthread_t, int* _Nonnull, struct sched_param* _Nonnull);
 
 void* pthread_getspecific(pthread_key_t);
 
-pid_t pthread_gettid_np(pthread_t);
+pid_t pthread_gettid_np(pthread_t) __INTRODUCED_IN(21);
 
 int pthread_join(pthread_t, void**);
 
-int pthread_key_create(pthread_key_t*, void (*)(void*)) __nonnull((1));
+int pthread_key_create(pthread_key_t* _Nonnull, void (*)(void*));
 int pthread_key_delete(pthread_key_t);
 
-int pthread_mutexattr_destroy(pthread_mutexattr_t*) __nonnull((1));
-int pthread_mutexattr_getpshared(const pthread_mutexattr_t*, int*) __nonnull((1, 2));
-int pthread_mutexattr_gettype(const pthread_mutexattr_t*, int*) __nonnull((1, 2));
-int pthread_mutexattr_init(pthread_mutexattr_t*) __nonnull((1));
-int pthread_mutexattr_setpshared(pthread_mutexattr_t*, int) __nonnull((1));
-int pthread_mutexattr_settype(pthread_mutexattr_t*, int) __nonnull((1));
+int pthread_mutexattr_destroy(pthread_mutexattr_t* _Nonnull);
+int pthread_mutexattr_getpshared(const pthread_mutexattr_t* _Nonnull, int* _Nonnull);
+int pthread_mutexattr_gettype(const pthread_mutexattr_t* _Nonnull, int* _Nonnull);
+int pthread_mutexattr_init(pthread_mutexattr_t* _Nonnull);
+int pthread_mutexattr_setpshared(pthread_mutexattr_t* _Nonnull, int);
+int pthread_mutexattr_settype(pthread_mutexattr_t* _Nonnull, int);
 
-int pthread_mutex_destroy(pthread_mutex_t*) __nonnull((1));
-int pthread_mutex_init(pthread_mutex_t*, const pthread_mutexattr_t*) __nonnull((1));
-#if !defined(__LP64__)
-int pthread_mutex_lock(pthread_mutex_t*) /* __nonnull((1)) */;
-#else
-int pthread_mutex_lock(pthread_mutex_t*) __nonnull((1));
-#endif
-int pthread_mutex_timedlock(pthread_mutex_t*, const struct timespec*) __nonnull((1, 2));
-int pthread_mutex_trylock(pthread_mutex_t*) __nonnull((1));
-#if !defined(__LP4__)
-int pthread_mutex_unlock(pthread_mutex_t*) /* __nonnull((1)) */;
-#else
-int pthread_mutex_unlock(pthread_mutex_t*) __nonnull((1));
-#endif
+int pthread_mutex_destroy(pthread_mutex_t* _Nonnull);
+int pthread_mutex_init(pthread_mutex_t* _Nonnull, const pthread_mutexattr_t*);
+int pthread_mutex_lock(pthread_mutex_t* _Nonnull);
+int pthread_mutex_timedlock(pthread_mutex_t* _Nonnull, const struct timespec* _Nonnull)
+  __INTRODUCED_IN(21);
+int pthread_mutex_trylock(pthread_mutex_t* _Nonnull);
+int pthread_mutex_unlock(pthread_mutex_t* _Nonnull);
 
-int pthread_once(pthread_once_t*, void (*)(void)) __nonnull((1, 2));
+int pthread_once(pthread_once_t* _Nonnull, void (* _Nonnull init_routine)(void));
 
-int pthread_rwlockattr_init(pthread_rwlockattr_t*) __nonnull((1));
-int pthread_rwlockattr_destroy(pthread_rwlockattr_t*) __nonnull((1));
-int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t*, int*) __nonnull((1, 2));
-int pthread_rwlockattr_setpshared(pthread_rwlockattr_t*, int) __nonnull((1));
-int pthread_rwlockattr_getkind_np(const pthread_rwlockattr_t*, int*) __nonnull((1, 2));
-int pthread_rwlockattr_setkind_np(pthread_rwlockattr_t*, int) __nonnull((1));
+int pthread_rwlockattr_init(pthread_rwlockattr_t* _Nonnull);
+int pthread_rwlockattr_destroy(pthread_rwlockattr_t* _Nonnull);
+int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t* _Nonnull, int* _Nonnull);
+int pthread_rwlockattr_setpshared(pthread_rwlockattr_t* _Nonnull, int);
+int pthread_rwlockattr_getkind_np(const pthread_rwlockattr_t* _Nonnull, int* _Nonnull)
+  __INTRODUCED_IN(23);
+int pthread_rwlockattr_setkind_np(pthread_rwlockattr_t* _Nonnull, int) __INTRODUCED_IN(23);
 
-int pthread_rwlock_destroy(pthread_rwlock_t*) __nonnull((1));
-int pthread_rwlock_init(pthread_rwlock_t*, const pthread_rwlockattr_t*) __nonnull((1));
-int pthread_rwlock_rdlock(pthread_rwlock_t*) __nonnull((1));
-int pthread_rwlock_timedrdlock(pthread_rwlock_t*, const struct timespec*) __nonnull((1, 2));
-int pthread_rwlock_timedwrlock(pthread_rwlock_t*, const struct timespec*) __nonnull((1, 2));
-int pthread_rwlock_tryrdlock(pthread_rwlock_t*) __nonnull((1));
-int pthread_rwlock_trywrlock(pthread_rwlock_t*) __nonnull((1));
-int pthread_rwlock_unlock(pthread_rwlock_t *) __nonnull((1));
-int pthread_rwlock_wrlock(pthread_rwlock_t*) __nonnull((1));
+int pthread_rwlock_destroy(pthread_rwlock_t* _Nonnull);
+int pthread_rwlock_init(pthread_rwlock_t* _Nonnull, const pthread_rwlockattr_t*);
+int pthread_rwlock_rdlock(pthread_rwlock_t* _Nonnull);
+int pthread_rwlock_timedrdlock(pthread_rwlock_t* _Nonnull, const struct timespec* _Nonnull);
+int pthread_rwlock_timedwrlock(pthread_rwlock_t* _Nonnull, const struct timespec* _Nonnull);
+int pthread_rwlock_tryrdlock(pthread_rwlock_t* _Nonnull);
+int pthread_rwlock_trywrlock(pthread_rwlock_t* _Nonnull);
+int pthread_rwlock_unlock(pthread_rwlock_t* _Nonnull);
+int pthread_rwlock_wrlock(pthread_rwlock_t* _Nonnull);
 
-int pthread_barrierattr_init(pthread_barrierattr_t* attr) __nonnull((1));
-int pthread_barrierattr_destroy(pthread_barrierattr_t* attr) __nonnull((1));
-int pthread_barrierattr_getpshared(pthread_barrierattr_t* attr, int* pshared) __nonnull((1, 2));
-int pthread_barrierattr_setpshared(pthread_barrierattr_t* attr, int pshared) __nonnull((1));
+int pthread_barrierattr_init(pthread_barrierattr_t* _Nonnull attr) __INTRODUCED_IN(24);
+int pthread_barrierattr_destroy(pthread_barrierattr_t* _Nonnull attr) __INTRODUCED_IN(24);
+int pthread_barrierattr_getpshared(pthread_barrierattr_t* _Nonnull attr, int* _Nonnull pshared)
+  __INTRODUCED_IN(24);
+int pthread_barrierattr_setpshared(pthread_barrierattr_t* _Nonnull attr, int pshared)
+  __INTRODUCED_IN(24);
 
-int pthread_barrier_init(pthread_barrier_t*, const pthread_barrierattr_t*, unsigned) __nonnull((1));
-int pthread_barrier_destroy(pthread_barrier_t*) __nonnull((1));
-int pthread_barrier_wait(pthread_barrier_t*) __nonnull((1));
+int pthread_barrier_init(pthread_barrier_t* _Nonnull, const pthread_barrierattr_t*, unsigned)
+  __INTRODUCED_IN(24);
+int pthread_barrier_destroy(pthread_barrier_t* _Nonnull) __INTRODUCED_IN(24);
+int pthread_barrier_wait(pthread_barrier_t* _Nonnull) __INTRODUCED_IN(24);
 
-int pthread_spin_destroy(pthread_spinlock_t*) __nonnull((1));
-int pthread_spin_init(pthread_spinlock_t*, int) __nonnull((1));
-int pthread_spin_lock(pthread_spinlock_t*) __nonnull((1));
-int pthread_spin_trylock(pthread_spinlock_t*) __nonnull((1));
-int pthread_spin_unlock(pthread_spinlock_t*) __nonnull((1));
+int pthread_spin_destroy(pthread_spinlock_t* _Nonnull) __INTRODUCED_IN(24);
+int pthread_spin_init(pthread_spinlock_t* _Nonnull, int) __INTRODUCED_IN(24);
+int pthread_spin_lock(pthread_spinlock_t* _Nonnull) __INTRODUCED_IN(24);
+int pthread_spin_trylock(pthread_spinlock_t* _Nonnull) __INTRODUCED_IN(24);
+int pthread_spin_unlock(pthread_spinlock_t* _Nonnull) __INTRODUCED_IN(24);
 
 pthread_t pthread_self(void) __pure2;
 
-int pthread_setname_np(pthread_t, const char*) __nonnull((2));
+#if defined(__USE_GNU)
+int pthread_getname_np(pthread_t, char* _Nonnull, size_t) __INTRODUCED_IN_FUTURE;
+#endif
+/* TODO: this should be __USE_GNU too. */
+int pthread_setname_np(pthread_t, const char* _Nonnull);
 
-int pthread_setschedparam(pthread_t, int, const struct sched_param*) __nonnull((3));
+int pthread_setschedparam(pthread_t, int, const struct sched_param* _Nonnull);
 
 int pthread_setspecific(pthread_key_t, const void*);
 
@@ -259,8 +268,8 @@
   void*                         __cleanup_arg;
 } __pthread_cleanup_t;
 
-extern void __pthread_cleanup_push(__pthread_cleanup_t* c, __pthread_cleanup_func_t, void*);
-extern void __pthread_cleanup_pop(__pthread_cleanup_t*, int);
+void __pthread_cleanup_push(__pthread_cleanup_t* c, __pthread_cleanup_func_t, void*);
+void __pthread_cleanup_pop(__pthread_cleanup_t*, int);
 
 /* Believe or not, the definitions of pthread_cleanup_push and
  * pthread_cleanup_pop below are correct. Posix states that these
@@ -277,22 +286,9 @@
         __pthread_cleanup_pop( &__cleanup, (execute)); \
     } while (0);                                       \
 
-
-#if !defined(__LP64__)
-
-// Bionic additions that are deprecated even in the 32-bit ABI.
-//
-// TODO: Remove them once chromium_org / NFC have switched over.
-int pthread_cond_timedwait_monotonic_np(pthread_cond_t*, pthread_mutex_t*, const struct timespec*);
-int pthread_cond_timedwait_monotonic(pthread_cond_t*, pthread_mutex_t*, const struct timespec*);
-
-int pthread_cond_timedwait_relative_np(pthread_cond_t*, pthread_mutex_t*, const struct timespec*) /* TODO: __attribute__((deprecated("use pthread_cond_timedwait instead")))*/;
-#define HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE 1 /* TODO: stop defining this to push LP32 off this API sooner. */
-int pthread_cond_timeout_np(pthread_cond_t*, pthread_mutex_t*, unsigned) /* TODO: __attribute__((deprecated("use pthread_cond_timedwait instead")))*/;
-
-int pthread_mutex_lock_timeout_np(pthread_mutex_t*, unsigned) __attribute__((deprecated("use pthread_mutex_timedlock instead")));
-
-#endif /* !defined(__LP64__) */
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
 
 __END_DECLS
 
diff --git a/libc/include/pty.h b/libc/include/pty.h
index bca1137..ec257a5 100644
--- a/libc/include/pty.h
+++ b/libc/include/pty.h
@@ -36,8 +36,8 @@
 
 __BEGIN_DECLS
 
-int openpty(int*, int*, char*, const struct termios*, const struct winsize*);
-int forkpty(int*, char*, const struct termios*, const struct winsize*);
+int openpty(int*, int*, char*, const struct termios*, const struct winsize*) __INTRODUCED_IN(23);
+int forkpty(int*, char*, const struct termios*, const struct winsize*) __INTRODUCED_IN(23);
 
 __END_DECLS
 
diff --git a/libc/include/pwd.h b/libc/include/pwd.h
index 905bc75..a686d05 100644
--- a/libc/include/pwd.h
+++ b/libc/include/pwd.h
@@ -1,6 +1,6 @@
 /*-
  * Copyright (c) 1989, 1993
- *	The Regents of the University of California.  All rights reserved.
+ *    The Regents of the University of California.  All rights reserved.
  * (c) UNIX System Laboratories, Inc.
  * All or some portions of this file are derived from material licensed
  * to the University of California by American Telephone and Telegraph
@@ -30,8 +30,6 @@
  * 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.
- *
- *	@(#)pwd.h	8.2 (Berkeley) 1/21/94
  */
 
 /*-
@@ -65,6 +63,8 @@
 #include <sys/cdefs.h>
 #include <sys/types.h>
 
+__BEGIN_DECLS
+
 #define _PATH_PASSWD        "/etc/passwd"
 #define _PATH_MASTERPASSWD  "/etc/master.passwd"
 #define _PATH_MASTERPASSWD_LOCK "/etc/ptmp"
@@ -98,8 +98,7 @@
 #define _PASSWORD_WARNDAYS  14  /* days to warn about expiry */
 #define _PASSWORD_CHGNOW    -1  /* special day to force password change at next login */
 
-struct passwd
-{
+struct passwd {
   char* pw_name;
   char* pw_passwd;
   uid_t pw_uid;
@@ -107,20 +106,24 @@
 #ifdef __LP64__
   char* pw_gecos;
 #else
-  // Note: On LP32, we define pw_gecos to pw_passwd since they're both NULL.
+  /* Note: On LP32, we define pw_gecos to pw_passwd since they're both NULL. */
 # define pw_gecos pw_passwd
 #endif
   char* pw_dir;
   char* pw_shell;
 };
 
-__BEGIN_DECLS
-
 struct passwd* getpwnam(const char*);
 struct passwd* getpwuid(uid_t);
 
-int getpwnam_r(const char*, struct passwd*, char*, size_t, struct passwd**);
-int getpwuid_r(uid_t, struct passwd*, char*, size_t, struct passwd**);
+/* Note: Android has thousands and thousands of ids to iterate through */
+struct passwd* getpwent(void) __INTRODUCED_IN_FUTURE;
+
+void setpwent(void) __INTRODUCED_IN_FUTURE;
+void endpwent(void) __INTRODUCED_IN_FUTURE;
+
+int getpwnam_r(const char*, struct passwd*, char*, size_t, struct passwd**) __INTRODUCED_IN(12);
+int getpwuid_r(uid_t, struct passwd*, char*, size_t, struct passwd**) __INTRODUCED_IN(12);
 
 __END_DECLS
 
diff --git a/libc/include/resolv.h b/libc/include/resolv.h
index c8899ed..2c12819 100644
--- a/libc/include/resolv.h
+++ b/libc/include/resolv.h
@@ -25,6 +25,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #ifndef _RESOLV_H_
 #define _RESOLV_H_
 
@@ -37,23 +38,27 @@
 #include <netinet/in.h>
 
 __BEGIN_DECLS
-#pragma GCC visibility push(default)
-
-struct res_state;
-
-extern struct __res_state *__res_state(void);
-#define _res (*__res_state())
 
 #define b64_ntop __b64_ntop
+int b64_ntop(u_char const*, size_t, char*, size_t);
 #define b64_pton __b64_pton
-extern int b64_ntop(u_char const*, size_t, char*, size_t);
-extern int b64_pton(char const*, u_char*, size_t);
+int b64_pton(char const*, u_char*, size_t);
 
 #define dn_comp __dn_comp
-extern int dn_comp(const char*, u_char*, int, u_char**, u_char**);
-extern int dn_expand(const u_char*, const u_char*, const u_char*, char*, int);
+int dn_comp(const char*, u_char*, int, u_char**, u_char**);
 
-#pragma GCC visibility pop
+int dn_expand(const u_char*, const u_char*, const u_char*, char*, int);
+
+#define p_class __p_class
+const char* p_class(int);
+#define p_type __p_type
+const char* p_type(int);
+
+int res_init(void);
+int res_mkquery(int, const char*, int, int, const u_char*, int, const u_char*, u_char*, int);
+int res_query(const char*, int, int, u_char*, int);
+int res_search(const char*, int, int, u_char*, int);
+
 __END_DECLS
 
 #endif /* _RESOLV_H_ */
diff --git a/libc/include/sched.h b/libc/include/sched.h
index 0b9235b..d407202 100644
--- a/libc/include/sched.h
+++ b/libc/include/sched.h
@@ -41,21 +41,22 @@
   int sched_priority;
 };
 
-extern int sched_setscheduler(pid_t, int, const struct sched_param*);
-extern int sched_getscheduler(pid_t);
-extern int sched_yield(void);
-extern int sched_get_priority_max(int);
-extern int sched_get_priority_min(int);
-extern int sched_setparam(pid_t, const struct sched_param*);
-extern int sched_getparam(pid_t, struct sched_param*);
-extern int sched_rr_get_interval(pid_t, struct timespec*);
+int sched_setscheduler(pid_t, int, const struct sched_param*);
+int sched_getscheduler(pid_t);
+int sched_yield(void);
+int sched_get_priority_max(int);
+int sched_get_priority_min(int);
+int sched_setparam(pid_t, const struct sched_param*);
+int sched_getparam(pid_t, struct sched_param*);
+int sched_rr_get_interval(pid_t, struct timespec*);
 
 #if defined(__USE_GNU)
 
-extern int clone(int (*)(void*), void*, int, void*, ...);
-extern int unshare(int);
-extern int sched_getcpu(void);
-extern int setns(int, int);
+int clone(int (*)(void*), void*, int, void*, ...) __INTRODUCED_IN_ARM(9)
+    __INTRODUCED_IN_MIPS(12) __INTRODUCED_IN_X86(17);
+int unshare(int) __INTRODUCED_IN(17);
+int sched_getcpu(void) __INTRODUCED_IN(12);
+int setns(int, int) __INTRODUCED_IN(21);
 
 #ifdef __LP64__
 #define CPU_SETSIZE 1024
@@ -72,9 +73,8 @@
   __CPU_BITTYPE  __bits[ CPU_SETSIZE / __CPU_BITS ];
 } cpu_set_t;
 
-extern int sched_setaffinity(pid_t pid, size_t setsize, const cpu_set_t* set);
-
-extern int sched_getaffinity(pid_t pid, size_t setsize, cpu_set_t* set);
+int sched_setaffinity(pid_t pid, size_t setsize, const cpu_set_t* set) __INTRODUCED_IN(12);
+int sched_getaffinity(pid_t pid, size_t setsize, cpu_set_t* set) __INTRODUCED_IN(12);
 
 #define CPU_ZERO(set)          CPU_ZERO_S(sizeof(cpu_set_t), set)
 #define CPU_SET(cpu, set)      CPU_SET_S(cpu, sizeof(cpu_set_t), set)
@@ -97,8 +97,8 @@
 #define CPU_ALLOC(count)  __sched_cpualloc((count))
 #define CPU_FREE(set)     __sched_cpufree((set))
 
-extern cpu_set_t* __sched_cpualloc(size_t count);
-extern void       __sched_cpufree(cpu_set_t* set);
+cpu_set_t* __sched_cpualloc(size_t count) __INTRODUCED_IN(12);
+void __sched_cpufree(cpu_set_t* set) __INTRODUCED_IN(12);
 
 #define CPU_ZERO_S(setsize, set)  __builtin_memset(set, 0, setsize)
 
@@ -142,7 +142,7 @@
 
 #define CPU_COUNT_S(setsize, set)  __sched_cpucount((setsize), (set))
 
-extern int __sched_cpucount(size_t setsize, cpu_set_t* set);
+int __sched_cpucount(size_t setsize, cpu_set_t* set) __INTRODUCED_IN(12);
 
 #endif /* __USE_GNU */
 
diff --git a/libc/include/search.h b/libc/include/search.h
index 9b01e12..dc160e9 100644
--- a/libc/include/search.h
+++ b/libc/include/search.h
@@ -29,17 +29,20 @@
 
 __BEGIN_DECLS
 
-void insque(void*, void*);
-void remque(void*);
+void insque(void*, void*) __INTRODUCED_IN(21);
+void remque(void*) __INTRODUCED_IN(21);
 
-void* lfind(const void*, const void*, size_t*, size_t, int (*)(const void*, const void*));
-void* lsearch(const void*, void*, size_t*, size_t, int (*)(const void*, const void*));
+void* lfind(const void*, const void*, size_t*, size_t, int (*)(const void*, const void*))
+  __INTRODUCED_IN(21);
+void* lsearch(const void*, void*, size_t*, size_t, int (*)(const void*, const void*))
+  __INTRODUCED_IN(21);
 
-void* tdelete(const void* __restrict, void** __restrict, int (*)(const void*, const void*));
-void tdestroy(void*, void (*)(void*));
-void* tfind(const void*, void* const*, int (*)(const void*, const void*));
-void* tsearch(const void*, void**, int (*)(const void*, const void*));
-void twalk(const void*, void (*)(const void*, VISIT, int));
+void* tdelete(const void* __restrict, void** __restrict, int (*)(const void*, const void*))
+  __INTRODUCED_IN(16);
+void tdestroy(void*, void (*)(void*)) __INTRODUCED_IN(16);
+void* tfind(const void*, void* const*, int (*)(const void*, const void*)) __INTRODUCED_IN(16);
+void* tsearch(const void*, void**, int (*)(const void*, const void*)) __INTRODUCED_IN(16);
+void twalk(const void*, void (*)(const void*, VISIT, int)) __INTRODUCED_IN(21);
 
 __END_DECLS
 
diff --git a/libc/include/setjmp.h b/libc/include/setjmp.h
index 02b06f5..7adeb35 100644
--- a/libc/include/setjmp.h
+++ b/libc/include/setjmp.h
@@ -54,8 +54,10 @@
 int     setjmp(jmp_buf);
 void    longjmp(jmp_buf, int);
 
-int     sigsetjmp(sigjmp_buf, int);
-void    siglongjmp(sigjmp_buf, int);
+int sigsetjmp(sigjmp_buf, int) __INTRODUCED_IN_ARM(9) __INTRODUCED_IN_MIPS(12)
+    __INTRODUCED_IN_X86(12);
+void siglongjmp(sigjmp_buf, int) __INTRODUCED_IN_ARM(9) __INTRODUCED_IN_MIPS(12)
+    __INTRODUCED_IN_X86(12);
 
 __END_DECLS
 
diff --git a/libc/include/sgtty.h b/libc/include/sgtty.h
deleted file mode 100644
index 1ac3100..0000000
--- a/libc/include/sgtty.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*	$NetBSD: sgtty.h,v 1.8 2005/02/03 04:39:32 perry Exp $	*/
-
-/*
- * Copyright (c) 1985, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- *
- *	@(#)sgtty.h	8.1 (Berkeley) 6/2/93
- */
-
-#ifndef _SGTTY_H_
-#define _SGTTY_H_
-
-#ifndef USE_OLD_TTY
-#define	USE_OLD_TTY
-#endif
-#include <sys/ioctl.h>
-#include <sys/cdefs.h>
-
-__BEGIN_DECLS
-int gtty(int, struct sgttyb *);
-int stty(int, struct sgttyb *);
-__END_DECLS
-
-#endif /* _SGTTY_H_ */
diff --git a/libc/include/signal.h b/libc/include/signal.h
index 85c46c0..a9df04b 100644
--- a/libc/include/signal.h
+++ b/libc/include/signal.h
@@ -53,6 +53,11 @@
 
 __BEGIN_DECLS
 
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnullability-completeness"
+#endif
+
 typedef int sig_atomic_t;
 
 /* The arm and x86 kernel header files don't define _NSIG. */
@@ -64,14 +69,19 @@
 #define _NSIG (_KERNEL__NSIG + 1)
 #define NSIG _NSIG
 
+/* The kernel headers define SIG_DFL (0) and SIG_IGN (1) but not SIG_HOLD, since
+ * SIG_HOLD is only used by the deprecated SysV signal API.
+ */
+#define SIG_HOLD __BIONIC_CAST(reinterpret_cast, sighandler_t, 2)
+
 /* We take a few real-time signals for ourselves. May as well use the same names as glibc. */
 #define SIGRTMIN (__libc_current_sigrtmin())
 #define SIGRTMAX (__libc_current_sigrtmax())
-extern int __libc_current_sigrtmin(void);
-extern int __libc_current_sigrtmax(void);
+int __libc_current_sigrtmin(void) __INTRODUCED_IN(21);
+int __libc_current_sigrtmax(void) __INTRODUCED_IN(21);
 
-extern const char* const sys_siglist[];
-extern const char* const sys_signame[]; /* BSD compatibility. */
+extern const char* const sys_siglist[_NSIG];
+extern const char* const sys_signame[_NSIG]; /* BSD compatibility. */
 
 typedef __sighandler_t sig_t; /* BSD compatibility. */
 typedef __sighandler_t sighandler_t; /* glibc compatibility. */
@@ -103,43 +113,61 @@
 
 #endif
 
-extern int sigaction(int, const struct sigaction*, struct sigaction*);
+int sigaction(int, const struct sigaction*, struct sigaction*);
 
-extern sighandler_t signal(int, sighandler_t) __INTRODUCED_IN(21);
+int siginterrupt(int, int);
 
-extern int siginterrupt(int, int);
+#if __ANDROID_API__ >= 21
+sighandler_t signal(int, sighandler_t) __INTRODUCED_IN(21);
+int sigaddset(sigset_t*, int) __INTRODUCED_IN(21);
+int sigdelset(sigset_t*, int) __INTRODUCED_IN(21);
+int sigemptyset(sigset_t*) __INTRODUCED_IN(21);
+int sigfillset(sigset_t*) __INTRODUCED_IN(21);
+int sigismember(const sigset_t*, int) __INTRODUCED_IN(21);
+#else
+// Implemented as static inlines before 21.
+#endif
 
-extern int sigaddset(sigset_t*, int) __INTRODUCED_IN(21);
-extern int sigdelset(sigset_t*, int) __INTRODUCED_IN(21);
-extern int sigemptyset(sigset_t*) __INTRODUCED_IN(21);
-extern int sigfillset(sigset_t*) __INTRODUCED_IN(21);
-extern int sigismember(const sigset_t*, int) __INTRODUCED_IN(21);
+int sigpending(sigset_t* _Nonnull);
+int sigprocmask(int, const sigset_t*, sigset_t*);
+int sigsuspend(const sigset_t* _Nonnull);
+int sigwait(const sigset_t* _Nonnull, int* _Nonnull);
 
-extern int sigpending(sigset_t*) __nonnull((1));
-extern int sigprocmask(int, const sigset_t*, sigset_t*);
-extern int sigsuspend(const sigset_t*) __nonnull((1));
-extern int sigwait(const sigset_t*, int*) __nonnull((1, 2));
+int sighold(int)
+  __attribute__((deprecated("use sigprocmask() or pthread_sigmask() instead")))
+  __INTRODUCED_IN_FUTURE;
+int sigignore(int)
+  __attribute__((deprecated("use sigaction() instead"))) __INTRODUCED_IN_FUTURE;
+int sigpause(int)
+  __attribute__((deprecated("use sigsuspend() instead"))) __INTRODUCED_IN_FUTURE;
+int sigrelse(int)
+  __attribute__((deprecated("use sigprocmask() or pthread_sigmask() instead")))
+  __INTRODUCED_IN_FUTURE;
+sighandler_t sigset(int, sighandler_t)
+  __attribute__((deprecated("use sigaction() instead"))) __INTRODUCED_IN_FUTURE;
 
-extern int raise(int);
-extern int kill(pid_t, int);
-extern int killpg(int, int);
+int raise(int);
+int kill(pid_t, int);
+int killpg(int, int);
 
-extern int sigaltstack(const stack_t*, stack_t*);
+int sigaltstack(const stack_t*, stack_t*);
 
-extern void psiginfo(const siginfo_t*, const char*);
-extern void psignal(int, const char*);
+void psiginfo(const siginfo_t*, const char*) __INTRODUCED_IN(17);
+void psignal(int, const char*) __INTRODUCED_IN(17);
 
-extern int pthread_kill(pthread_t, int);
-extern int pthread_sigmask(int, const sigset_t*, sigset_t*);
+int pthread_kill(pthread_t, int);
+int pthread_sigmask(int, const sigset_t*, sigset_t*);
 
-extern int sigqueue(pid_t, int, const union sigval);
-extern int sigtimedwait(const sigset_t*, siginfo_t*, const struct timespec*);
-extern int sigwaitinfo(const sigset_t*, siginfo_t*);
+int sigqueue(pid_t, int, const union sigval) __INTRODUCED_IN(23);
+int sigtimedwait(const sigset_t* _Nonnull, siginfo_t*, const struct timespec*) __INTRODUCED_IN(23);
+int sigwaitinfo(const sigset_t* _Nonnull, siginfo_t*) __INTRODUCED_IN(23);
 
-#if __ANDROID_API__ < 21
-#include <android/legacy_signal_inlines.h>
+#if defined(__clang__)
+#pragma clang diagnostic pop
 #endif
 
 __END_DECLS
 
+#include <android/legacy_signal_inlines.h>
+
 #endif /* _SIGNAL_H_ */
diff --git a/libc/include/stdatomic.h b/libc/include/stdatomic.h
index 2c4f1ce..8d573b2 100644
--- a/libc/include/stdatomic.h
+++ b/libc/include/stdatomic.h
@@ -32,22 +32,13 @@
 
 #include <sys/cdefs.h>
 
-#if defined(__GNUC__) && !defined(__GNUC_PREREQ)
-/* Duplicate definition here, since the mingw sys/cdefs.h omits the  */
-/* definition, and this needs to be usable there.                    */
-#define	__GNUC_PREREQ(x, y)    \
-	((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || (__GNUC__ > (x)))
-#endif /* __GNUC__ && ... */
-
 #if defined(__cplusplus) && __cplusplus >= 201103L && defined(_USING_LIBCXX)
 # ifdef __clang__
 #  if __has_feature(cxx_atomic)
 #   define _STDATOMIC_HAVE_ATOMIC
 #  endif
 # else /* gcc */
-#  if __GNUC_PREREQ(4, 7)
-#   define _STDATOMIC_HAVE_ATOMIC
-#  endif
+#  define _STDATOMIC_HAVE_ATOMIC
 # endif
 #endif
 
@@ -150,12 +141,16 @@
  * bits as a T.
  */
 
-#include <stddef.h>  /* For ptrdiff_t.                          */
-#include <stdint.h>  /* TODO: Should pollute namespace less.    */
+#include <stddef.h>  /* For ptrdiff_t. */
+#include <stdint.h>  /* TODO: don't drag in all the macros, just the types. */
+// Include uchar.h only when needed.  Bionic's stdatomic.h is also used for the
+// host (via a copy in prebuilts/clang) and uchar.h is not available in the
+// glibc used for the host.
 #if __STDC_VERSION__ >= 201112L
 # include <uchar.h>  /* For char16_t and char32_t.              */
 #endif
 
+
 #ifdef __clang__
 # if __has_extension(c_atomic) || __has_extension(cxx_atomic)
 #  define       __CLANG_ATOMICS
@@ -166,14 +161,7 @@
 #  define __HAS_BUILTIN_SYNC_SWAP
 # endif
 #else
-# if __GNUC_PREREQ(4, 7)
-#  define	__GNUC_ATOMICS
-# else
-#  define	__SYNC_ATOMICS
-#  ifdef __cplusplus
-#   define       __ATOMICS_AVOID_DOT_INIT
-#  endif
-# endif
+# define __GNUC_ATOMICS
 #endif
 
 /*
@@ -182,53 +170,33 @@
 
 #ifdef __GCC_ATOMIC_BOOL_LOCK_FREE
 #define	ATOMIC_BOOL_LOCK_FREE		__GCC_ATOMIC_BOOL_LOCK_FREE
-#elif defined(__SYNC_ATOMICS)
-#define	ATOMIC_BOOL_LOCK_FREE           2 /* For all modern platforms */
 #endif
 #ifdef __GCC_ATOMIC_CHAR_LOCK_FREE
 #define	ATOMIC_CHAR_LOCK_FREE		__GCC_ATOMIC_CHAR_LOCK_FREE
-#elif defined(__SYNC_ATOMICS)
-#define	ATOMIC_CHAR_LOCK_FREE           2
 #endif
 #ifdef __GCC_ATOMIC_CHAR16_T_LOCK_FREE
 #define	ATOMIC_CHAR16_T_LOCK_FREE	__GCC_ATOMIC_CHAR16_T_LOCK_FREE
-#elif defined(__SYNC_ATOMICS)
-#define	ATOMIC_CHAR16_T_LOCK_FREE       2
 #endif
 #ifdef __GCC_ATOMIC_CHAR32_T_LOCK_FREE
 #define	ATOMIC_CHAR32_T_LOCK_FREE	__GCC_ATOMIC_CHAR32_T_LOCK_FREE
-#elif defined(__SYNC_ATOMICS)
-#define	ATOMIC_CHAR32_T_LOCK_FREE       2
 #endif
 #ifdef __GCC_ATOMIC_WCHAR_T_LOCK_FREE
 #define	ATOMIC_WCHAR_T_LOCK_FREE	__GCC_ATOMIC_WCHAR_T_LOCK_FREE
-#elif defined(__SYNC_ATOMICS)
-#define	ATOMIC_WCHAR_T_LOCK_FREE        2
 #endif
 #ifdef __GCC_ATOMIC_SHORT_LOCK_FREE
 #define	ATOMIC_SHORT_LOCK_FREE		__GCC_ATOMIC_SHORT_LOCK_FREE
-#elif defined(__SYNC_ATOMICS)
-#define	ATOMIC_SHORT_LOCK_FREE          2
 #endif
 #ifdef __GCC_ATOMIC_INT_LOCK_FREE
 #define	ATOMIC_INT_LOCK_FREE		__GCC_ATOMIC_INT_LOCK_FREE
-#elif defined(__SYNC_ATOMICS)
-#define	ATOMIC_INT_LOCK_FREE            2
 #endif
 #ifdef __GCC_ATOMIC_LONG_LOCK_FREE
 #define	ATOMIC_LONG_LOCK_FREE		__GCC_ATOMIC_LONG_LOCK_FREE
-#elif defined(__SYNC_ATOMICS)
-#define	ATOMIC_LONG_LOCK_FREE           2
 #endif
 #ifdef __GCC_ATOMIC_LLONG_LOCK_FREE
 #define	ATOMIC_LLONG_LOCK_FREE		__GCC_ATOMIC_LLONG_LOCK_FREE
-#elif defined(__SYNC_ATOMICS)
-#define	ATOMIC_LLONG_LOCK_FREE          1 /* maybe */
 #endif
 #ifdef __GCC_ATOMIC_POINTER_LOCK_FREE
 #define	ATOMIC_POINTER_LOCK_FREE	__GCC_ATOMIC_POINTER_LOCK_FREE
-#elif defined(__SYNC_ATOMICS)
-#define	ATOMIC_POINTER_LOCK_FREE        2
 #endif
 
 /*
@@ -239,11 +207,7 @@
 #define	ATOMIC_VAR_INIT(value)		(value)
 #define	atomic_init(obj, value)		__c11_atomic_init(obj, value)
 #else
-#ifdef __ATOMICS_AVOID_DOT_INIT
-#define	ATOMIC_VAR_INIT(value)		{ value }
-#else
 #define	ATOMIC_VAR_INIT(value)		{ .__val = (value) }
-#endif
 #define	atomic_init(obj, value)		((void)((obj)->__val = (value)))
 #endif
 
diff --git a/libc/include/stdint.h b/libc/include/stdint.h
index a66e21e..1cedca1 100644
--- a/libc/include/stdint.h
+++ b/libc/include/stdint.h
@@ -31,8 +31,9 @@
 
 #include <bits/wchar_limits.h>
 #include <stddef.h>
+#include <sys/cdefs.h>
 
-typedef __signed char __int8_t;
+typedef signed char __int8_t;
 typedef unsigned char __uint8_t;
 typedef short __int16_t;
 typedef unsigned short __uint16_t;
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index 623995b..097be3a 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -49,19 +49,34 @@
 
 __BEGIN_DECLS
 
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnullability-completeness"
+#endif
+
 typedef off_t fpos_t;
 typedef off64_t fpos64_t;
 
 struct __sFILE;
 typedef struct __sFILE FILE;
 
-extern FILE* stdin;
-extern FILE* stdout;
-extern FILE* stderr;
+#if __ANDROID_API__ >= 23
+extern FILE* stdin __INTRODUCED_IN(23);
+extern FILE* stdout __INTRODUCED_IN(23);
+extern FILE* stderr __INTRODUCED_IN(23);
+
 /* C99 and earlier plus current C++ standards say these must be macros. */
 #define stdin stdin
 #define stdout stdout
 #define stderr stderr
+#else
+/* Before M the actual symbols for stdin and friends had different names. */
+extern FILE* __sF[] __REMOVED_IN(23);
+
+#define stdin __sF[0]
+#define stdout __sF[1]
+#define stderr __sF[2]
+#endif
 
 /*
  * The following three definitions are for ANSI C, which took them
@@ -88,10 +103,6 @@
 #define	FOPEN_MAX	20	/* must be <= OPEN_MAX <sys/syslimits.h> */
 #define	FILENAME_MAX	1024	/* must be <= PATH_MAX <sys/syslimits.h> */
 
-/* System V/ANSI C; this is the wrong way to do this, do *not* use these. */
-#if __BSD_VISIBLE || __XPG_VISIBLE
-#define	P_tmpdir	"/tmp/"
-#endif
 #define	L_tmpnam	1024	/* XXX must be == PATH_MAX */
 #define	TMP_MAX		308915776
 
@@ -109,57 +120,45 @@
 int	 fflush(FILE *);
 int	 fgetc(FILE *);
 char	*fgets(char * __restrict, int, FILE * __restrict);
-int	 fprintf(FILE * __restrict , const char * __restrict, ...)
-		__printflike(2, 3);
+int	 fprintf(FILE * __restrict , const char * __restrict _Nonnull, ...) __printflike(2, 3);
 int	 fputc(int, FILE *);
 int	 fputs(const char * __restrict, FILE * __restrict);
 size_t	 fread(void * __restrict, size_t, size_t, FILE * __restrict);
-int	 fscanf(FILE * __restrict, const char * __restrict, ...)
-		__scanflike(2, 3);
+int	 fscanf(FILE * __restrict, const char * __restrict _Nonnull, ...) __scanflike(2, 3);
 size_t	 fwrite(const void * __restrict, size_t, size_t, FILE * __restrict);
 int	 getc(FILE *);
 int	 getchar(void);
-ssize_t	 getdelim(char ** __restrict, size_t * __restrict, int,
-	    FILE * __restrict);
-ssize_t	 getline(char ** __restrict, size_t * __restrict, FILE * __restrict);
+ssize_t getdelim(char** __restrict, size_t* __restrict, int, FILE* __restrict) __INTRODUCED_IN(18);
+ssize_t getline(char** __restrict, size_t* __restrict, FILE* __restrict) __INTRODUCED_IN(18);
 
 void	 perror(const char *);
-int	 printf(const char * __restrict, ...)
-		__printflike(1, 2);
+int	 printf(const char * __restrict _Nonnull, ...) __printflike(1, 2);
 int	 putc(int, FILE *);
 int	 putchar(int);
 int	 puts(const char *);
 int	 remove(const char *);
 void	 rewind(FILE *);
-int	 scanf(const char * __restrict, ...)
-		__scanflike(1, 2);
+int	 scanf(const char * __restrict _Nonnull, ...) __scanflike(1, 2);
 void	 setbuf(FILE * __restrict, char * __restrict);
 int	 setvbuf(FILE * __restrict, char * __restrict, int, size_t);
-int	 sscanf(const char * __restrict, const char * __restrict, ...)
-		__scanflike(2, 3);
+int	 sscanf(const char * __restrict, const char * __restrict _Nonnull, ...) __scanflike(2, 3);
 int	 ungetc(int, FILE *);
-int	 vfprintf(FILE * __restrict, const char * __restrict, __va_list)
-		__printflike(2, 0);
-int	 vprintf(const char * __restrict, __va_list)
-		__printflike(1, 0);
+int	 vfprintf(FILE * __restrict, const char * __restrict _Nonnull, __va_list) __printflike(2, 0);
+int	 vprintf(const char * __restrict _Nonnull, __va_list) __printflike(1, 0);
 
-int dprintf(int, const char * __restrict, ...) __printflike(2, 3);
-int vdprintf(int, const char * __restrict, __va_list) __printflike(2, 0);
+int dprintf(int, const char* __restrict _Nonnull, ...) __printflike(2, 3) __INTRODUCED_IN(21);
+int vdprintf(int, const char* __restrict _Nonnull, __va_list) __printflike(2, 0) __INTRODUCED_IN(21);
 
-#ifndef __AUDIT__
-#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ < 201112L) || \
+    (defined(__cplusplus) && __cplusplus <= 201103L)
 char* gets(char*) __attribute__((deprecated("gets is unsafe, use fgets instead")));
 #endif
-int sprintf(char* __restrict, const char* __restrict, ...)
-    __printflike(2, 3) __warnattr("sprintf is often misused; please use snprintf");
-int vsprintf(char* __restrict, const char* __restrict, __va_list)
-    __printflike(2, 0) __warnattr("vsprintf is often misused; please use vsnprintf");
+int sprintf(char* __restrict, const char* __restrict _Nonnull, ...) __printflike(2, 3);
+int vsprintf(char* __restrict, const char* __restrict _Nonnull, __va_list) __printflike(2, 0);
 char* tmpnam(char*) __attribute__((deprecated("tmpnam is unsafe, use mkstemp or tmpfile instead")));
-#if __XPG_VISIBLE
+#define P_tmpdir "/tmp/" /* deprecated */
 char* tempnam(const char*, const char*)
     __attribute__((deprecated("tempnam is unsafe, use mkstemp or tmpfile instead")));
-#endif
-#endif
 
 int rename(const char*, const char*);
 int renameat(int, const char*, int, const char*);
@@ -192,125 +191,89 @@
               int (*)(void*));
 #  endif
 #endif
-int fgetpos64(FILE*, fpos64_t*);
-int fsetpos64(FILE*, const fpos64_t*);
-int fseeko64(FILE*, off64_t, int);
-off64_t ftello64(FILE*);
+int fgetpos64(FILE*, fpos64_t*) __INTRODUCED_IN(24);
+int fsetpos64(FILE*, const fpos64_t*) __INTRODUCED_IN(24);
+int fseeko64(FILE*, off64_t, int) __INTRODUCED_IN(24);
+off64_t ftello64(FILE*) __INTRODUCED_IN(24);
 #if defined(__USE_BSD)
-FILE* funopen64(const void*,
-                int (*)(void*, char*, int),
-                int (*)(void*, const char*, int),
-                fpos64_t (*)(void*, fpos64_t, int),
-                int (*)(void*));
+FILE* funopen64(const void*, int (*)(void*, char*, int), int (*)(void*, const char*, int),
+                fpos64_t (*)(void*, fpos64_t, int), int (*)(void*)) __INTRODUCED_IN(24);
 #endif
 
 FILE* fopen(const char* __restrict, const char* __restrict);
-FILE* fopen64(const char* __restrict, const char* __restrict);
+FILE* fopen64(const char* __restrict, const char* __restrict) __INTRODUCED_IN(24);
 FILE* freopen(const char* __restrict, const char* __restrict, FILE* __restrict);
-FILE* freopen64(const char* __restrict, const char* __restrict, FILE* __restrict);
+FILE* freopen64(const char* __restrict, const char* __restrict, FILE* __restrict)
+  __INTRODUCED_IN(24);
 FILE* tmpfile(void);
-FILE* tmpfile64(void);
+FILE* tmpfile64(void) __INTRODUCED_IN(24);
 
-#if __ISO_C_VISIBLE >= 1999 || __BSD_VISIBLE
-int	 snprintf(char * __restrict, size_t, const char * __restrict, ...)
-		__printflike(3, 4);
-int	 vfscanf(FILE * __restrict, const char * __restrict, __va_list)
-		__scanflike(2, 0);
-int	 vscanf(const char *, __va_list)
-		__scanflike(1, 0);
-int	 vsnprintf(char * __restrict, size_t, const char * __restrict, __va_list)
-		__printflike(3, 0);
-int	 vsscanf(const char * __restrict, const char * __restrict, __va_list)
-		__scanflike(2, 0);
-#endif /* __ISO_C_VISIBLE >= 1999 || __BSD_VISIBLE */
+int snprintf(char* __restrict, size_t, const char* __restrict _Nonnull, ...) __printflike(3, 4);
+int vfscanf(FILE* __restrict, const char* __restrict _Nonnull, __va_list) __scanflike(2, 0);
+int vscanf(const char* _Nonnull , __va_list) __scanflike(1, 0);
+int vsnprintf(char* __restrict, size_t, const char* __restrict _Nonnull, __va_list) __printflike(3, 0);
+int vsscanf(const char* __restrict _Nonnull, const char* __restrict _Nonnull, __va_list) __scanflike(2, 0);
 
-/*
- * Functions defined in POSIX 1003.1.
- */
-#if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE
-#define	L_ctermid	1024	/* size for ctermid(); PATH_MAX */
+#define L_ctermid 1024 /* size for ctermid() */
+char* ctermid(char*) __INTRODUCED_IN_FUTURE;
 
-FILE	*fdopen(int, const char *);
-int	 fileno(FILE *);
+FILE* fdopen(int, const char*);
+int fileno(FILE*);
+int pclose(FILE*);
+FILE* popen(const char*, const char*);
+void flockfile(FILE*);
+int ftrylockfile(FILE*);
+void funlockfile(FILE*);
+int getc_unlocked(FILE*);
+int getchar_unlocked(void);
+int putc_unlocked(int, FILE*);
+int putchar_unlocked(int);
 
-#if (__POSIX_VISIBLE >= 199209)
-int	 pclose(FILE *);
-FILE	*popen(const char *, const char *);
-#endif
+FILE* fmemopen(void*, size_t, const char*) __INTRODUCED_IN(23);
+FILE* open_memstream(char**, size_t*) __INTRODUCED_IN(23);
 
-#if __POSIX_VISIBLE >= 199506
-void	 flockfile(FILE *);
-int	 ftrylockfile(FILE *);
-void	 funlockfile(FILE *);
-
-/*
- * These are normally used through macros as defined below, but POSIX
- * requires functions as well.
- */
-int	 getc_unlocked(FILE *);
-int	 getchar_unlocked(void);
-int	 putc_unlocked(int, FILE *);
-int	 putchar_unlocked(int);
-#endif /* __POSIX_VISIBLE >= 199506 */
-
-#if __POSIX_VISIBLE >= 200809
-FILE* fmemopen(void*, size_t, const char*);
-FILE* open_memstream(char**, size_t*);
-#endif /* __POSIX_VISIBLE >= 200809 */
-
-#endif /* __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE */
-
-/*
- * Routines that are purely local.
- */
-#if __BSD_VISIBLE
-int	 asprintf(char ** __restrict, const char * __restrict, ...)
-		__printflike(2, 3);
-char	*fgetln(FILE * __restrict, size_t * __restrict);
-int	 fpurge(FILE *);
-void	 setbuffer(FILE *, char *, int);
-int	 setlinebuf(FILE *);
-int	 vasprintf(char ** __restrict, const char * __restrict,
-    __va_list)
-		__printflike(2, 0);
-
-void clearerr_unlocked(FILE*);
-int feof_unlocked(FILE*);
-int ferror_unlocked(FILE*);
-int fileno_unlocked(FILE*);
-
+#if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
+int  asprintf(char** __restrict, const char* __restrict _Nonnull, ...) __printflike(2, 3);
+char* fgetln(FILE* __restrict, size_t* __restrict);
+int fpurge(FILE*);
+void setbuffer(FILE*, char*, int);
+int setlinebuf(FILE*);
+int vasprintf(char** __restrict, const char* __restrict _Nonnull, __va_list) __printflike(2, 0);
+void clearerr_unlocked(FILE*) __INTRODUCED_IN(23);
+int feof_unlocked(FILE*) __INTRODUCED_IN(23);
+int ferror_unlocked(FILE*) __INTRODUCED_IN(23);
+int fileno_unlocked(FILE*) __INTRODUCED_IN(24);
 #define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
 #define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
-#endif /* __BSD_VISIBLE */
+#endif /* __USE_BSD */
 
-extern char* __fgets_chk(char*, int, FILE*, size_t);
-extern char* __fgets_real(char*, int, FILE*) __RENAME(fgets);
+char* __fgets_chk(char*, int, FILE*, size_t) __INTRODUCED_IN(17);
+char* __fgets_real(char*, int, FILE*) __RENAME(fgets);
 __errordecl(__fgets_too_big_error, "fgets called with size bigger than buffer");
 __errordecl(__fgets_too_small_error, "fgets called with size less than zero");
 
-extern size_t __fread_chk(void * __restrict, size_t, size_t, FILE * __restrict, size_t);
-extern size_t __fread_real(void * __restrict, size_t, size_t, FILE * __restrict) __RENAME(fread);
+size_t __fread_chk(void* __restrict, size_t, size_t, FILE* __restrict, size_t)
+  __INTRODUCED_IN(24);
+size_t __fread_real(void * __restrict, size_t, size_t, FILE * __restrict) __RENAME(fread);
 __errordecl(__fread_too_big_error, "fread called with size * count bigger than buffer");
 __errordecl(__fread_overflow, "fread called with overflowing size * count");
 
-extern size_t __fwrite_chk(const void * __restrict, size_t, size_t, FILE * __restrict, size_t);
-extern size_t __fwrite_real(const void * __restrict, size_t, size_t, FILE * __restrict) __RENAME(fwrite);
+size_t __fwrite_chk(const void* __restrict, size_t, size_t, FILE* __restrict, size_t)
+  __INTRODUCED_IN(24);
+size_t __fwrite_real(const void * __restrict, size_t, size_t, FILE * __restrict) __RENAME(fwrite);
 __errordecl(__fwrite_too_big_error, "fwrite called with size * count bigger than buffer");
 __errordecl(__fwrite_overflow, "fwrite called with overflowing size * count");
 
-#if defined(__BIONIC_FORTIFY)
+#if defined(__BIONIC_FORTIFY) && !defined(__BIONIC_NO_STDIO_FORTIFY)
 
+#if __ANDROID_API__ >= 17
 __BIONIC_FORTIFY_INLINE
-__printflike(3, 0)
-int vsnprintf(char *dest, size_t size, const char *format, __va_list ap)
-{
+__printflike(3, 0) int vsnprintf(char* dest, size_t size, const char* _Nonnull format, __va_list ap) {
     return __builtin___vsnprintf_chk(dest, size, 0, __bos(dest), format, ap);
 }
 
 __BIONIC_FORTIFY_INLINE
-__printflike(2, 0)
-int vsprintf(char *dest, const char *format, __va_list ap)
-{
+__printflike(2, 0) int vsprintf(char* dest, const char* _Nonnull format, __va_list ap) {
     return __builtin___vsprintf_chk(dest, 0, __bos(dest), format, ap);
 }
 
@@ -321,11 +284,8 @@
   #endif
 #else
 __BIONIC_FORTIFY_INLINE
-__printflike(3, 4)
-int snprintf(char *dest, size_t size, const char *format, ...)
-{
-    return __builtin___snprintf_chk(dest, size, 0,
-        __bos(dest), format, __builtin_va_arg_pack());
+__printflike(3, 4) int snprintf(char* dest, size_t size, const char* _Nonnull format, ...) {
+    return __builtin___snprintf_chk(dest, size, 0, __bos(dest), format, __builtin_va_arg_pack());
 }
 #endif
 
@@ -336,14 +296,13 @@
   #endif
 #else
 __BIONIC_FORTIFY_INLINE
-__printflike(2, 3)
-int sprintf(char *dest, const char *format, ...)
-{
-    return __builtin___sprintf_chk(dest, 0,
-        __bos(dest), format, __builtin_va_arg_pack());
+__printflike(2, 3) int sprintf(char* dest, const char* _Nonnull format, ...) {
+    return __builtin___sprintf_chk(dest, 0, __bos(dest), format, __builtin_va_arg_pack());
 }
 #endif
+#endif /* __ANDROID_API__ >= 17 */
 
+#if __ANDROID_API__ >= 24
 __BIONIC_FORTIFY_INLINE
 size_t fread(void * __restrict buf, size_t size, size_t count, FILE * __restrict stream) {
     size_t bos = __bos0(buf);
@@ -395,6 +354,7 @@
 
     return __fwrite_chk(buf, size, count, stream, bos);
 }
+#endif /* __ANDROID_API__ >= 24 */
 
 #if !defined(__clang__)
 
@@ -432,6 +392,10 @@
 
 #endif /* defined(__BIONIC_FORTIFY) */
 
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
+
 __END_DECLS
 
 #endif /* _STDIO_H_ */
diff --git a/libc/include/stdio_ext.h b/libc/include/stdio_ext.h
index f299e54..fdf6772 100644
--- a/libc/include/stdio_ext.h
+++ b/libc/include/stdio_ext.h
@@ -38,16 +38,14 @@
 
 __BEGIN_DECLS
 
-size_t __fbufsize(FILE*);
-int __freading(FILE*);
-int __fwriting(FILE*);
-int __freadable(FILE*);
-int __fwritable(FILE*);
-int __flbf(FILE*);
-void __fpurge(FILE*);
-size_t __fpending(FILE*);
-void _flushlbf(void);
-int __fsetlocking(FILE*, int);
+size_t __fbufsize(FILE*) __INTRODUCED_IN(23);
+int __freadable(FILE*) __INTRODUCED_IN(23);
+int __fwritable(FILE*) __INTRODUCED_IN(23);
+int __flbf(FILE*) __INTRODUCED_IN(23);
+void __fpurge(FILE*) __INTRODUCED_IN(23);
+size_t __fpending(FILE*) __INTRODUCED_IN(23);
+void _flushlbf(void) __INTRODUCED_IN(23);
+int __fsetlocking(FILE*, int) __INTRODUCED_IN(23);
 
 __END_DECLS
 
diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h
index d9d277a..28cd4a8 100644
--- a/libc/include/stdlib.h
+++ b/libc/include/stdlib.h
@@ -41,67 +41,57 @@
 #define EXIT_FAILURE 1
 #define EXIT_SUCCESS 0
 
-extern __noreturn void abort(void);
-extern __noreturn void exit(int);
-extern __noreturn void _Exit(int);
-extern int atexit(void (*)(void));
+__noreturn void abort(void);
+__noreturn void exit(int);
+__noreturn void _Exit(int) __INTRODUCED_IN(21);
+int atexit(void (*)(void));
 
-#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L
-int at_quick_exit(void (*)(void));
-void quick_exit(int) __noreturn;
-#endif
+int at_quick_exit(void (*)(void)) __INTRODUCED_IN(21);
+void quick_exit(int) __noreturn __INTRODUCED_IN(21);
 
-extern char* getenv(const char*);
-extern int putenv(char*);
-extern int setenv(const char*, const char*, int);
-extern int unsetenv(const char*);
-extern int clearenv(void);
+char* getenv(const char*);
+int putenv(char*);
+int setenv(const char*, const char*, int);
+int unsetenv(const char*);
+int clearenv(void);
 
-extern char* mkdtemp(char*);
-extern char* mktemp(char*) __attribute__((deprecated("mktemp is unsafe, use mkstemp or tmpfile instead")));
+char* mkdtemp(char*);
+char* mktemp(char*) __attribute__((deprecated("mktemp is unsafe, use mkstemp or tmpfile instead")));
 
-extern int mkostemp64(char*, int);
-extern int mkostemp(char*, int);
-extern int mkostemps64(char*, int, int);
-extern int mkostemps(char*, int, int);
-extern int mkstemp64(char*);
-extern int mkstemp(char*);
-extern int mkstemps64(char*, int);
-extern int mkstemps(char*, int);
+int mkostemp64(char*, int) __INTRODUCED_IN(23);
+int mkostemp(char*, int) __INTRODUCED_IN(23);
+int mkostemps64(char*, int, int) __INTRODUCED_IN(23);
+int mkostemps(char*, int, int) __INTRODUCED_IN(23);
+int mkstemp64(char*) __INTRODUCED_IN(21);
+int mkstemp(char*);
+int mkstemps64(char*, int) __INTRODUCED_IN(23);
+int mkstemps(char*, int);
 
-extern long strtol(const char *, char **, int);
-extern long long strtoll(const char *, char **, int);
-extern unsigned long strtoul(const char *, char **, int);
-extern unsigned long long strtoull(const char *, char **, int);
+long strtol(const char *, char **, int);
+long long strtoll(const char *, char **, int);
+unsigned long strtoul(const char *, char **, int);
+unsigned long long strtoull(const char *, char **, int);
 
-extern int posix_memalign(void **memptr, size_t alignment, size_t size);
+int posix_memalign(void** memptr, size_t alignment, size_t size) __INTRODUCED_IN(16);
 
-extern double atof(const char*) __INTRODUCED_IN(21);
+double strtod(const char*, char**);
+long double strtold(const char*, char**) __INTRODUCED_IN(21);
 
-extern double strtod(const char*, char**) __LIBC_ABI_PUBLIC__;
-extern float strtof(const char*, char**) __LIBC_ABI_PUBLIC__ __INTRODUCED_IN(21);
-extern long double strtold(const char*, char**) __LIBC_ABI_PUBLIC__;
+long double strtold_l(const char*, char**, locale_t) __INTRODUCED_IN(21);
+long long strtoll_l(const char*, char**, int, locale_t) __INTRODUCED_IN(21);
+unsigned long long strtoull_l(const char*, char**, int, locale_t) __INTRODUCED_IN(21);
 
-extern long double strtold_l(const char *, char **, locale_t) __LIBC_ABI_PUBLIC__;
-extern long long strtoll_l(const char *, char **, int, locale_t) __LIBC_ABI_PUBLIC__;
-extern unsigned long long strtoull_l(const char *, char **, int, locale_t) __LIBC_ABI_PUBLIC__;
+int atoi(const char*) __purefunc;
+long atol(const char*) __purefunc;
+long long atoll(const char*) __purefunc;
 
-extern int atoi(const char*) __purefunc;
-extern long atol(const char*) __purefunc;
-extern long long atoll(const char*) __purefunc;
+char* realpath(const char* path, char* resolved);
+int system(const char* string);
 
-extern int abs(int) __pure2 __INTRODUCED_IN(21);
-extern long labs(long) __pure2 __INTRODUCED_IN(21);
-extern long long llabs(long long) __pure2 __INTRODUCED_IN(21);
+void* bsearch(const void* key, const void* base0, size_t nmemb, size_t size,
+              int (*compar)(const void*, const void*));
 
-extern char * realpath(const char *path, char *resolved);
-extern int system(const char *string);
-
-extern void * bsearch(const void *key, const void *base0,
-	size_t nmemb, size_t size,
-	int (*compar)(const void *, const void *));
-
-extern void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
+void qsort(void*, size_t, size_t, int (*)(const void*, const void*));
 
 uint32_t arc4random(void);
 uint32_t arc4random_uniform(uint32_t);
@@ -109,76 +99,66 @@
 
 #define RAND_MAX 0x7fffffff
 
-int rand(void) __INTRODUCED_IN(21);
-int rand_r(unsigned int*);
-void srand(unsigned int) __INTRODUCED_IN(21);
+int rand_r(unsigned int*) __INTRODUCED_IN(21);
 
 double drand48(void);
 double erand48(unsigned short[3]);
 long jrand48(unsigned short[3]);
-void lcong48(unsigned short[7]);
+void lcong48(unsigned short[7]) __INTRODUCED_IN(23);
 long lrand48(void);
 long mrand48(void);
 long nrand48(unsigned short[3]);
 unsigned short* seed48(unsigned short[3]);
 void srand48(long);
 
-char* initstate(unsigned int, char*, size_t);
-long random(void) __INTRODUCED_IN(21);
-char* setstate(char*);
-void srandom(unsigned int) __INTRODUCED_IN(21);
+char* initstate(unsigned int, char*, size_t) __INTRODUCED_IN(21);
+char* setstate(char*) __INTRODUCED_IN(21);
 
 int getpt(void);
-int grantpt(int) __INTRODUCED_IN(21);
-int posix_openpt(int);
+int posix_openpt(int) __INTRODUCED_IN(21);
 char* ptsname(int);
 int ptsname_r(int, char*, size_t);
 int unlockpt(int);
 
+int getsubopt(char**, char* const*, char**) __INTRODUCED_IN_FUTURE;
+
 typedef struct {
     int  quot;
     int  rem;
 } div_t;
 
-extern div_t   div(int, int) __pure2;
+div_t div(int, int) __pure2;
 
 typedef struct {
     long int  quot;
     long int  rem;
 } ldiv_t;
 
-extern ldiv_t   ldiv(long, long) __pure2;
+ldiv_t ldiv(long, long) __pure2;
 
 typedef struct {
     long long int  quot;
     long long int  rem;
 } lldiv_t;
 
-extern lldiv_t   lldiv(long long, long long) __pure2;
+lldiv_t lldiv(long long, long long) __pure2;
 
 /* BSD compatibility. */
-extern const char* getprogname(void);
-extern void setprogname(const char*);
+const char* getprogname(void) __INTRODUCED_IN(21);
+void setprogname(const char*) __INTRODUCED_IN(21);
 
-/* make STLPort happy */
-extern int      mblen(const char *, size_t);
-extern size_t   mbstowcs(wchar_t *, const char *, size_t);
-extern int      mbtowc(wchar_t *, const char *, size_t);
+int mblen(const char*, size_t) __INTRODUCED_IN_FUTURE;
+size_t mbstowcs(wchar_t*, const char*, size_t);
+int mbtowc(wchar_t*, const char*, size_t) __INTRODUCED_IN(21);
+int wctomb(char*, wchar_t) __INTRODUCED_IN(21);
+size_t wcstombs(char*, const wchar_t*, size_t);
 
-/* Likewise, make libstdc++-v3 happy.  */
-extern int	wctomb(char *, wchar_t);
-extern size_t	wcstombs(char *, const wchar_t *, size_t);
-
-extern size_t __ctype_get_mb_cur_max(void);
+size_t __ctype_get_mb_cur_max(void) __INTRODUCED_IN(21);
 #define MB_CUR_MAX __ctype_get_mb_cur_max()
 
-#if __ANDROID_API__ < 21
-#include <android/legacy_stdlib_inlines.h>
-#endif
-
 #if defined(__BIONIC_FORTIFY)
 
-extern char* __realpath_real(const char*, char*) __RENAME(realpath);
+char* __realpath_real(const char*, char*) __RENAME(realpath);
 __errordecl(__realpath_size_error, "realpath output parameter must be NULL or a >= PATH_MAX bytes buffer");
 
 #if !defined(__clang__)
@@ -197,6 +177,23 @@
 
 #endif /* defined(__BIONIC_FORTIFY) */
 
+#if __ANDROID_API__ >= 21
+float strtof(const char*, char**) __INTRODUCED_IN(21);
+double atof(const char*) __INTRODUCED_IN(21);
+int abs(int) __pure2 __INTRODUCED_IN(21);
+long labs(long) __pure2 __INTRODUCED_IN(21);
+long long llabs(long long) __pure2 __INTRODUCED_IN(21);
+int rand(void) __INTRODUCED_IN(21);
+void srand(unsigned int) __INTRODUCED_IN(21);
+long random(void) __INTRODUCED_IN(21);
+void srandom(unsigned int) __INTRODUCED_IN(21);
+int grantpt(int) __INTRODUCED_IN(21);
+#else
+// Implemented as static inlines before 21.
+#endif
+
 __END_DECLS
 
+#include <android/legacy_stdlib_inlines.h>
+
 #endif /* _STDLIB_H */
diff --git a/libc/include/string.h b/libc/include/string.h
index 32d4a18..18b12bd 100644
--- a/libc/include/string.h
+++ b/libc/include/string.h
@@ -33,120 +33,124 @@
 #include <stddef.h>
 #include <xlocale.h>
 
+#include <bits/strcasecmp.h>
+
 __BEGIN_DECLS
 
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnullability-completeness"
+#endif
+
 #if defined(__USE_BSD)
 #include <strings.h>
 #endif
 
-extern void*  memccpy(void* __restrict, const void* __restrict, int, size_t);
-extern void*  memchr(const void *, int, size_t) __purefunc;
-extern void*  memrchr(const void *, int, size_t) __purefunc;
-extern int    memcmp(const void *, const void *, size_t) __purefunc;
-extern void*  memcpy(void* __restrict, const void* __restrict, size_t);
+void* memccpy(void* _Nonnull __restrict, const void* _Nonnull __restrict, int, size_t);
+void* memchr(const void* _Nonnull, int, size_t) __purefunc;
+void* memrchr(const void* _Nonnull, int, size_t) __purefunc;
+int memcmp(const void* _Nonnull, const void* _Nonnull, size_t) __purefunc;
+void* memcpy(void* _Nonnull __restrict, const void* _Nonnull __restrict, size_t);
 #if defined(__USE_GNU)
-extern void*  mempcpy(void* __restrict, const void* __restrict, size_t);
+void* mempcpy(void* _Nonnull __restrict, const void* _Nonnull __restrict, size_t) __INTRODUCED_IN(23);
 #endif
-extern void*  memmove(void *, const void *, size_t);
-extern void*  memset(void *, int, size_t);
-extern void*  memmem(const void *, size_t, const void *, size_t) __purefunc;
+void* memmove(void* _Nonnull, const void* _Nonnull, size_t);
+void* memset(void* _Nonnull, int, size_t);
+void* memmem(const void* _Nonnull, size_t, const void* _Nonnull, size_t) __purefunc;
 
-extern char*  strchr(const char *, int) __purefunc;
-extern char* __strchr_chk(const char *, int, size_t);
+char* strchr(const char* _Nonnull, int) __purefunc;
+char* __strchr_chk(const char* _Nonnull, int, size_t) __INTRODUCED_IN(18);
 #if defined(__USE_GNU)
 #if defined(__cplusplus)
-extern "C++" char* strchrnul(char*, int) __RENAME(strchrnul) __purefunc;
-extern "C++" const char* strchrnul(const char*, int) __RENAME(strchrnul) __purefunc;
+extern "C++" char* strchrnul(char* _Nonnull, int) __RENAME(strchrnul) __purefunc;
+extern "C++" const char* strchrnul(const char* _Nonnull, int) __RENAME(strchrnul) __purefunc;
 #else
-char* strchrnul(const char*, int) __purefunc;
+char* strchrnul(const char* _Nonnull, int) __purefunc __INTRODUCED_IN(24);
 #endif
 #endif
 
-extern char*  strrchr(const char *, int) __purefunc;
-extern char* __strrchr_chk(const char *, int, size_t);
+char* strrchr(const char* _Nonnull, int) __purefunc;
+char* __strrchr_chk(const char* _Nonnull, int, size_t) __INTRODUCED_IN(18);
 
-extern size_t strlen(const char *) __purefunc;
-extern size_t __strlen_chk(const char *, size_t);
-extern int    strcmp(const char *, const char *) __purefunc;
-extern char*  stpcpy(char* __restrict, const char* __restrict);
-extern char*  strcpy(char* __restrict, const char* __restrict);
-extern char*  strcat(char* __restrict, const char* __restrict);
+size_t strlen(const char* _Nonnull) __purefunc;
+size_t __strlen_chk(const char* _Nonnull, size_t) __INTRODUCED_IN(17);
+int strcmp(const char* _Nonnull, const char* _Nonnull) __purefunc;
+char* stpcpy(char* _Nonnull __restrict, const char* _Nonnull__restrict) __INTRODUCED_IN(21);
+char* strcpy(char* _Nonnull __restrict, const char* _Nonnull __restrict);
+char* strcat(char* _Nonnull __restrict, const char* _Nonnull __restrict);
 
-int strcasecmp(const char*, const char*) __purefunc;
-int strcasecmp_l(const char*, const char*, locale_t) __purefunc;
-int strncasecmp(const char*, const char*, size_t) __purefunc;
-int strncasecmp_l(const char*, const char*, size_t, locale_t) __purefunc;
+char* strdup(const char* _Nonnull);
 
-extern char*  strdup(const char *);
+char* strstr(const char* _Nonnull, const char* _Nonnull) __purefunc;
+char* strcasestr(const char* _Nonnull, const char* _Nonnull) __purefunc;
+char* strtok(char* __restrict, const char* _Nonnull __restrict);
+char* strtok_r(char* __restrict, const char* _Nonnull __restrict, char** _Nonnull __restrict);
 
-extern char*  strstr(const char *, const char *) __purefunc;
-extern char*  strcasestr(const char *haystack, const char *needle) __purefunc;
-extern char*  strtok(char* __restrict, const char* __restrict);
-extern char*  strtok_r(char* __restrict, const char* __restrict, char** __restrict);
-
-extern char* strerror(int);
-extern char* strerror_l(int, locale_t);
+char* strerror(int);
+char* strerror_l(int, locale_t) __INTRODUCED_IN(23);
 #if defined(__USE_GNU)
-extern char* strerror_r(int, char*, size_t) __RENAME(__gnu_strerror_r);
+char* strerror_r(int, char*, size_t) __RENAME(__gnu_strerror_r) __INTRODUCED_IN(23);
 #else /* POSIX */
-extern int strerror_r(int, char*, size_t);
+int strerror_r(int, char*, size_t);
 #endif
 
-extern size_t strnlen(const char *, size_t) __purefunc;
-extern char*  strncat(char* __restrict, const char* __restrict, size_t);
-extern char*  strndup(const char *, size_t);
-extern int    strncmp(const char *, const char *, size_t) __purefunc;
-extern char*  stpncpy(char* __restrict, const char* __restrict, size_t);
-extern char*  strncpy(char* __restrict, const char* __restrict, size_t);
+size_t strnlen(const char* _Nonnull, size_t) __purefunc;
+char* strncat(char* _Nonnull __restrict, const char* _Nonnull __restrict, size_t);
+char* strndup(const char* _Nonnull, size_t);
+int strncmp(const char* _Nonnull, const char* _Nonnull, size_t) __purefunc;
+char* stpncpy(char* _Nonnull __restrict, const char* _Nonnull __restrict, size_t) __INTRODUCED_IN(21);
+char* strncpy(char* _Nonnull __restrict, const char* _Nonnull __restrict, size_t);
 
-extern size_t strlcat(char* __restrict, const char* __restrict, size_t);
-extern size_t strlcpy(char* __restrict, const char* __restrict, size_t);
+size_t strlcat(char* _Nonnull __restrict, const char* _Nonnull __restrict, size_t);
+size_t strlcpy(char* _Nonnull __restrict, const char* _Nonnull __restrict, size_t);
 
-extern size_t strcspn(const char *, const char *) __purefunc;
-extern char*  strpbrk(const char *, const char *) __purefunc;
-extern char*  strsep(char** __restrict, const char* __restrict);
-extern size_t strspn(const char *, const char *);
+size_t strcspn(const char* _Nonnull, const char* _Nonnull) __purefunc;
+char* strpbrk(const char* _Nonnull, const char* _Nonnull) __purefunc;
+char* strsep(char** _Nonnull __restrict, const char* _Nonnull __restrict);
+size_t strspn(const char* _Nonnull, const char* _Nonnull);
 
-extern char*  strsignal(int  sig);
+char* strsignal(int);
 
-extern int    strcoll(const char *, const char *) __purefunc;
-extern size_t strxfrm(char* __restrict, const char* __restrict, size_t);
+int strcoll(const char* _Nonnull, const char* _Nonnull) __purefunc;
+size_t strxfrm(char* __restrict, const char* _Nonnull __restrict, size_t);
 
-extern int    strcoll_l(const char *, const char *, locale_t) __purefunc;
-extern size_t strxfrm_l(char* __restrict, const char* __restrict, size_t, locale_t);
+int strcoll_l(const char* _Nonnull, const char* _Nonnull, locale_t) __purefunc __INTRODUCED_IN(21);
+size_t strxfrm_l(char* __restrict, const char* _Nonnull __restrict, size_t, locale_t) __INTRODUCED_IN(21);
 
 #if defined(__USE_GNU) && !defined(basename)
 /*
  * glibc has a basename in <string.h> that's different to the POSIX one in <libgen.h>.
  * It doesn't modify its argument, and in C++ it's const-correct.
  */
-
 #if defined(__cplusplus)
-extern "C++" char* basename(char*) __RENAME(__gnu_basename) __nonnull((1));
-extern "C++" const char* basename(const char*) __RENAME(__gnu_basename) __nonnull((1));
+extern "C++" char* basename(char* _Nonnull) __RENAME(__gnu_basename);
+extern "C++" const char* basename(const char* _Nonnull) __RENAME(__gnu_basename);
 #else
-extern char* basename(const char*) __RENAME(__gnu_basename) __nonnull((1));
+char* basename(const char* _Nonnull) __RENAME(__gnu_basename) __INTRODUCED_IN(23);
 #endif
 #endif
 
-extern void* __memchr_chk(const void*, int, size_t, size_t);
+void* __memchr_chk(const void* _Nonnull, int, size_t, size_t) __INTRODUCED_IN(23);
 __errordecl(__memchr_buf_size_error, "memchr called with size bigger than buffer");
 
-extern void* __memrchr_chk(const void*, int, size_t, size_t);
+void* __memrchr_chk(const void* _Nonnull, int, size_t, size_t) __INTRODUCED_IN(23);
 __errordecl(__memrchr_buf_size_error, "memrchr called with size bigger than buffer");
-extern void* __memrchr_real(const void*, int, size_t) __RENAME(memrchr);
+void* __memrchr_real(const void* _Nonnull, int, size_t) __RENAME(memrchr);
 
-extern char* __stpncpy_chk2(char* __restrict, const char* __restrict, size_t, size_t, size_t);
-extern char* __strncpy_chk2(char* __restrict, const char* __restrict, size_t, size_t, size_t);
-extern size_t __strlcpy_real(char* __restrict, const char* __restrict, size_t) __RENAME(strlcpy);
-extern size_t __strlcpy_chk(char *, const char *, size_t, size_t);
-extern size_t __strlcat_real(char* __restrict, const char* __restrict, size_t) __RENAME(strlcat);
-extern size_t __strlcat_chk(char* __restrict, const char* __restrict, size_t, size_t);
+char* __stpncpy_chk2(char* _Nonnull __restrict, const char* _Nonnull __restrict, size_t, size_t, size_t)
+  __INTRODUCED_IN(21);
+char* __strncpy_chk2(char* _Nonnull __restrict, const char* _Nonnull __restrict, size_t, size_t, size_t)
+  __INTRODUCED_IN(21);
+size_t __strlcpy_real(char* _Nonnull __restrict, const char* _Nonnull __restrict, size_t) __RENAME(strlcpy);
+size_t __strlcpy_chk(char* _Nonnull __restrict, const char* _Nonnull __restrict, size_t, size_t) __INTRODUCED_IN(17);
+size_t __strlcat_real(char* _Nonnull __restrict, const char* _Nonnull __restrict, size_t) __RENAME(strlcat);
+size_t __strlcat_chk(char* _Nonnull __restrict, const char* _Nonnull __restrict, size_t, size_t) __INTRODUCED_IN(17);
 
 #if defined(__BIONIC_FORTIFY)
 
+#if __ANDROID_API__ >= 23
 __BIONIC_FORTIFY_INLINE
-void* memchr(const void *s, int c, size_t n) {
+void* memchr(const void* s, int c, size_t n) {
     size_t bos = __bos(s);
 
 #if !defined(__clang__)
@@ -167,7 +171,7 @@
 }
 
 __BIONIC_FORTIFY_INLINE
-void* memrchr(const void *s, int c, size_t n) {
+void* memrchr(const void* s, int c, size_t n) {
     size_t bos = __bos(s);
 
 #if !defined(__clang__)
@@ -186,127 +190,137 @@
 
     return __memrchr_chk(s, c, n, bos);
 }
+#endif /* __ANDROID_API__ >= 23 */
 
+#if __ANDROID_API__ >= 17
 __BIONIC_FORTIFY_INLINE
-void* memcpy(void* __restrict dest, const void* __restrict src, size_t copy_amount) {
-    return __builtin___memcpy_chk(dest, src, copy_amount, __bos0(dest));
+void* memcpy(void* _Nonnull __restrict dst, const void* _Nonnull __restrict src, size_t copy_amount) {
+    return __builtin___memcpy_chk(dst, src, copy_amount, __bos0(dst));
 }
 
 __BIONIC_FORTIFY_INLINE
-void* memmove(void *dest, const void *src, size_t len) {
-    return __builtin___memmove_chk(dest, src, len, __bos0(dest));
+void* memmove(void* _Nonnull dst, const void* _Nonnull src, size_t len) {
+    return __builtin___memmove_chk(dst, src, len, __bos0(dst));
 }
+#endif /* __ANDROID_API__ >= 17 */
 
+#if __ANDROID_API__ >= 21
 __BIONIC_FORTIFY_INLINE
-char* stpcpy(char* __restrict dest, const char* __restrict src) {
-    return __builtin___stpcpy_chk(dest, src, __bos(dest));
+char* stpcpy(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src) {
+    return __builtin___stpcpy_chk(dst, src, __bos(dst));
 }
+#endif /* __ANDROID_API__ >= 21 */
 
+#if __ANDROID_API__ >= 17
 __BIONIC_FORTIFY_INLINE
-char* strcpy(char* __restrict dest, const char* __restrict src) {
-    return __builtin___strcpy_chk(dest, src, __bos(dest));
+char* strcpy(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src) {
+    return __builtin___strcpy_chk(dst, src, __bos(dst));
 }
+#endif /* __ANDROID_API__ >= 17 */
 
+#if __ANDROID_API__ >= 21
 __BIONIC_FORTIFY_INLINE
-char* stpncpy(char* __restrict dest, const char* __restrict src, size_t n) {
-    size_t bos_dest = __bos(dest);
+char* stpncpy(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src, size_t n) {
+    size_t bos_dst = __bos(dst);
     size_t bos_src = __bos(src);
 
     if (bos_src == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
-        return __builtin___stpncpy_chk(dest, src, n, bos_dest);
+        return __builtin___stpncpy_chk(dst, src, n, bos_dst);
     }
 
     if (__builtin_constant_p(n) && (n <= bos_src)) {
-        return __builtin___stpncpy_chk(dest, src, n, bos_dest);
+        return __builtin___stpncpy_chk(dst, src, n, bos_dst);
     }
 
     size_t slen = __builtin_strlen(src);
     if (__builtin_constant_p(slen)) {
-        return __builtin___stpncpy_chk(dest, src, n, bos_dest);
+        return __builtin___stpncpy_chk(dst, src, n, bos_dst);
     }
 
-    return __stpncpy_chk2(dest, src, n, bos_dest, bos_src);
+    return __stpncpy_chk2(dst, src, n, bos_dst, bos_src);
 }
+#endif /* __ANDROID_API__ >= 21 */
 
+#if __ANDROID_API__ >= 17
 __BIONIC_FORTIFY_INLINE
-char* strncpy(char* __restrict dest, const char* __restrict src, size_t n) {
-    size_t bos_dest = __bos(dest);
+char* strncpy(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src, size_t n) {
+    size_t bos_dst = __bos(dst);
     size_t bos_src = __bos(src);
 
     if (bos_src == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
-        return __builtin___strncpy_chk(dest, src, n, bos_dest);
+        return __builtin___strncpy_chk(dst, src, n, bos_dst);
     }
 
     if (__builtin_constant_p(n) && (n <= bos_src)) {
-        return __builtin___strncpy_chk(dest, src, n, bos_dest);
+        return __builtin___strncpy_chk(dst, src, n, bos_dst);
     }
 
     size_t slen = __builtin_strlen(src);
     if (__builtin_constant_p(slen)) {
-        return __builtin___strncpy_chk(dest, src, n, bos_dest);
+        return __builtin___strncpy_chk(dst, src, n, bos_dst);
     }
 
-    return __strncpy_chk2(dest, src, n, bos_dest, bos_src);
+    return __strncpy_chk2(dst, src, n, bos_dst, bos_src);
 }
 
 __BIONIC_FORTIFY_INLINE
-char* strcat(char* __restrict dest, const char* __restrict src) {
-    return __builtin___strcat_chk(dest, src, __bos(dest));
+char* strcat(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src) {
+    return __builtin___strcat_chk(dst, src, __bos(dst));
 }
 
 __BIONIC_FORTIFY_INLINE
-char *strncat(char* __restrict dest, const char* __restrict src, size_t n) {
-    return __builtin___strncat_chk(dest, src, n, __bos(dest));
+char *strncat(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src, size_t n) {
+    return __builtin___strncat_chk(dst, src, n, __bos(dst));
 }
 
 __BIONIC_FORTIFY_INLINE
-void* memset(void *s, int c, size_t n) {
+void* memset(void* _Nonnull s, int c, size_t n) {
     return __builtin___memset_chk(s, c, n, __bos0(s));
 }
 
 __BIONIC_FORTIFY_INLINE
-size_t strlcpy(char* __restrict dest, const char* __restrict src, size_t size) {
-    size_t bos = __bos(dest);
+size_t strlcpy(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src, size_t size) {
+    size_t bos = __bos(dst);
 
 #if !defined(__clang__)
     // Compiler doesn't know destination size. Don't call __strlcpy_chk
     if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
-        return __strlcpy_real(dest, src, size);
+        return __strlcpy_real(dst, src, size);
     }
 
     // Compiler can prove, at compile time, that the passed in size
     // is always <= the actual object size. Don't call __strlcpy_chk
     if (__builtin_constant_p(size) && (size <= bos)) {
-        return __strlcpy_real(dest, src, size);
+        return __strlcpy_real(dst, src, size);
     }
 #endif /* !defined(__clang__) */
 
-    return __strlcpy_chk(dest, src, size, bos);
+    return __strlcpy_chk(dst, src, size, bos);
 }
 
 
 __BIONIC_FORTIFY_INLINE
-size_t strlcat(char* __restrict dest, const char* __restrict src, size_t size) {
-    size_t bos = __bos(dest);
+size_t strlcat(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src, size_t size) {
+    size_t bos = __bos(dst);
 
 #if !defined(__clang__)
     // Compiler doesn't know destination size. Don't call __strlcat_chk
     if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
-        return __strlcat_real(dest, src, size);
+        return __strlcat_real(dst, src, size);
     }
 
     // Compiler can prove, at compile time, that the passed in size
     // is always <= the actual object size. Don't call __strlcat_chk
     if (__builtin_constant_p(size) && (size <= bos)) {
-        return __strlcat_real(dest, src, size);
+        return __strlcat_real(dst, src, size);
     }
 #endif /* !defined(__clang__) */
 
-    return __strlcat_chk(dest, src, size, bos);
+    return __strlcat_chk(dst, src, size, bos);
 }
 
 __BIONIC_FORTIFY_INLINE
-size_t strlen(const char *s) {
+size_t strlen(const char* _Nonnull s) {
     size_t bos = __bos(s);
 
 #if !defined(__clang__)
@@ -323,9 +337,11 @@
 
     return __strlen_chk(s, bos);
 }
+#endif /* __ANDROID_API__ >= 17 */
 
+#if  __ANDROID_API__ >= 18
 __BIONIC_FORTIFY_INLINE
-char* strchr(const char *s, int c) {
+char* strchr(const char* _Nonnull s, int c) {
     size_t bos = __bos(s);
 
 #if !defined(__clang__)
@@ -344,7 +360,7 @@
 }
 
 __BIONIC_FORTIFY_INLINE
-char* strrchr(const char *s, int c) {
+char* strrchr(const char* _Nonnull s, int c) {
     size_t bos = __bos(s);
 
 #if !defined(__clang__)
@@ -361,10 +377,14 @@
 
     return __strrchr_chk(s, c, bos);
 }
-
+#endif /* __ANDROID_API__ >= 18 */
 
 #endif /* defined(__BIONIC_FORTIFY) */
 
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
+
 __END_DECLS
 
 #endif /* _STRING_H */
diff --git a/libc/include/strings.h b/libc/include/strings.h
index 1253006..021e2b4 100644
--- a/libc/include/strings.h
+++ b/libc/include/strings.h
@@ -43,6 +43,8 @@
 #include <sys/cdefs.h>
 #include <xlocale.h>
 
+#include <bits/strcasecmp.h>
+
 __BEGIN_DECLS
 #if defined(__BIONIC_FORTIFY)
 #define bcopy(b1, b2, len) (void)(__builtin___memmove_chk((b2), (b1), (len), __bos0(b2)))
@@ -52,12 +54,7 @@
 #define bzero(b, len) (void)(__builtin_memset((b), '\0', (len)))
 #endif
 
-int ffs(int);
-
-int strcasecmp(const char*, const char*) __purefunc;
-int strcasecmp_l(const char*, const char*, locale_t) __purefunc;
-int strncasecmp(const char*, const char*, size_t) __purefunc;
-int strncasecmp_l(const char*, const char*, size_t, locale_t) __purefunc;
+int ffs(int) __INTRODUCED_IN_X86(18);
 
 __END_DECLS
 
diff --git a/libc/include/sys/_system_properties.h b/libc/include/sys/_system_properties.h
index 3b1f7d0..60789d4 100644
--- a/libc/include/sys/_system_properties.h
+++ b/libc/include/sys/_system_properties.h
@@ -29,6 +29,8 @@
 #ifndef _INCLUDE_SYS__SYSTEM_PROPERTIES_H
 #define _INCLUDE_SYS__SYSTEM_PROPERTIES_H
 
+#include <sys/cdefs.h>
+
 #ifndef _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
 #error you should #include <sys/system_properties.h> instead
 #else
diff --git a/libc/include/sys/atomics.h b/libc/include/sys/atomics.h
deleted file mode 100644
index 38ab366..0000000
--- a/libc/include/sys/atomics.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-#ifndef _SYS_ATOMICS_H_
-#define _SYS_ATOMICS_H_
-
-/*
- * These got proper out of line definitions in L. Putting the inline definitions
- * back for old targets brings us closer to being able to use one set of headers
- * for all API levels.
- *
- * The other inlines we put back went in to their appropriate headers, but the
- * sys/atomics.h header was removed, so we'll just add these somewhere we can be
- * sure they will be included.
- */
-#if __ANDROID_API__ < 21
-#include <android/legacy_sys_atomics_inlines.h>
-#endif
-
-#endif /* _SYS_ATOMICS_H_ */
diff --git a/libc/include/sys/auxv.h b/libc/include/sys/auxv.h
index 0d753c3..2fa637e 100644
--- a/libc/include/sys/auxv.h
+++ b/libc/include/sys/auxv.h
@@ -33,7 +33,7 @@
 
 __BEGIN_DECLS
 
-unsigned long int getauxval(unsigned long int type);
+unsigned long int getauxval(unsigned long int type) __INTRODUCED_IN(18);
 
 __END_DECLS
 
diff --git a/libc/include/sys/cachectl.h b/libc/include/sys/cachectl.h
index a302ff8..5b20c19 100644
--- a/libc/include/sys/cachectl.h
+++ b/libc/include/sys/cachectl.h
@@ -25,11 +25,13 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #ifndef _SYS_CACHECTL_H
 #define _SYS_CACHECTL_H 1
 
+#include <sys/cdefs.h>
 #ifdef __mips__
 #include <asm/cachectl.h>
-extern int __cachectl (void *addr, __const int nbytes, __const int op);
 #endif
+
 #endif /* sys/cachectl.h */
diff --git a/libc/include/sys/capability.h b/libc/include/sys/capability.h
index 7718a6c..b9a40b3 100644
--- a/libc/include/sys/capability.h
+++ b/libc/include/sys/capability.h
@@ -34,8 +34,8 @@
 
 __BEGIN_DECLS
 
-extern int capget(cap_user_header_t hdrp, cap_user_data_t datap);
-extern int capset(cap_user_header_t hdrp, const cap_user_data_t datap);
+int capget(cap_user_header_t hdrp, cap_user_data_t datap);
+int capset(cap_user_header_t hdrp, const cap_user_data_t datap);
 
 __END_DECLS
 
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index f51942b..4d1e34c 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -58,25 +58,6 @@
 #endif
 
 
-/*
- * Macro to test if we're using a GNU C compiler of a specific vintage
- * or later, for e.g. features that appeared in a particular version
- * of GNU C.  Usage:
- *
- *	#if __GNUC_PREREQ(major, minor)
- *	...cool feature...
- *	#else
- *	...delete feature...
- *	#endif
- */
-#ifdef __GNUC__
-#define	__GNUC_PREREQ(x, y)						\
-	((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) ||			\
-	 (__GNUC__ > (x)))
-#else
-#define	__GNUC_PREREQ(x, y)	0
-#endif
-
 #define __strong_alias(alias, sym) \
     __asm__(".global " #alias "\n" \
             #alias " = " #sym);
@@ -91,6 +72,12 @@
 #define	__static_cast(x,y)	(x)y
 #endif
 
+#if defined(__cplusplus)
+#define __BIONIC_CAST(_k,_t,_v) (_k<_t>(_v))
+#else
+#define __BIONIC_CAST(_k,_t,_v) ((_t) (_v))
+#endif
+
 /*
  * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
  * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
@@ -107,15 +94,8 @@
 #define	__CONCAT(x,y)	x ## y
 #define	__STRING(x)	#x
 
-#define	__const		const		/* define reserved names to standard */
-#define	__signed	signed
-#define	__volatile	volatile
 #if defined(__cplusplus)
 #define	__inline	inline		/* convert to C++ keyword */
-#else
-#if !defined(__GNUC__) && !defined(__lint__)
-#define	__inline			/* delete GCC keyword */
-#endif /* !__GNUC__  && !__lint__ */
 #endif /* !__cplusplus */
 
 #else	/* !(__STDC__ || __cplusplus) */
@@ -123,61 +103,57 @@
 #define	__CONCAT(x,y)	x/**/y
 #define	__STRING(x)	"x"
 
-#ifndef __GNUC__
-#define	__const				/* delete pseudo-ANSI C keywords */
-#define	__inline
-#define	__signed
-#define	__volatile
-#endif	/* !__GNUC__ */
-
 #endif	/* !(__STDC__ || __cplusplus) */
 
-/*
- * The following macro is used to remove const cast-away warnings
- * from gcc -Wcast-qual; it should be used with caution because it
- * can hide valid errors; in particular most valid uses are in
- * situations where the API requires it, not to cast away string
- * constants. We don't use *intptr_t on purpose here and we are
- * explicit about unsigned long so that we don't have additional
- * dependencies.
- */
-#define __UNCONST(a)	((void *)(unsigned long)(const void *)(a))
-
+#define __always_inline __attribute__((__always_inline__))
 #define __dead __attribute__((__noreturn__))
+#define __noreturn __attribute__((__noreturn__))
+#define __mallocfunc  __attribute__((malloc))
+#define __packed __attribute__((__packed__))
 #define __pure __attribute__((__const__))
 #define __pure2 __attribute__((__const__)) /* Android-added: used by FreeBSD libm */
-
-#define	__unused	__attribute__((__unused__))
-
-#define	__used		__attribute__((__used__))
-
-#define	__packed	__attribute__((__packed__))
-#define	__aligned(x)	__attribute__((__aligned__(x)))
-#define	__section(x)	__attribute__((__section__(x)))
-
-#define __statement(x)	__extension__(x)
-
-#define __nonnull(args) __attribute__((__nonnull__ args))
-
-#define __printflike(x, y) __attribute__((__format__(printf, x, y))) __nonnull((x))
-#define __scanflike(x, y) __attribute__((__format__(scanf, x, y))) __nonnull((x))
+#define __purefunc    __attribute__((pure))
+#define __unused __attribute__((__unused__))
+#define __used __attribute__((__used__))
 
 /*
- * C99 defines the restrict type qualifier keyword.
+ * _Nonnull is similar to the nonnull attribute in that it will instruct
+ * compilers to warn the user if it can prove that a null argument is being
+ * passed. Unlike the nonnull attribute, this annotation indicated that a value
+ * *should not* be null, not that it *cannot* be null, or even that the behavior
+ * is undefined. The important distinction is that the optimizer will perform
+ * surprising optimizations like the following:
+ *
+ *     void foo(void*) __attribute__(nonnull, 1);
+ *
+ *     int bar(int* p) {
+ *       foo(p);
+ *
+ *       // The following null check will be elided because nonnull attribute
+ *       // means that, since we call foo with p, p can be assumed to not be
+ *       // null. Thus this will crash if we are called with a null pointer.
+ *       if (p != NULL) {
+ *         return *p;
+ *       }
+ *       return 0;
+ *     }
+ *
+ *     int main() {
+ *       return bar(NULL);
+ *     }
+ *
+ * http://clang.llvm.org/docs/AttributeReference.html#nonnull
  */
-#if defined(__STDC__VERSION__) && __STDC_VERSION__ >= 199901L
-#define	__restrict	restrict
+#if !(defined(__clang__) && __has_feature(nullability))
+#define _Nonnull
+#define _Nullable
 #endif
 
-/*
- * C99 defines __func__ predefined identifier.
- */
-#if !defined(__STDC_VERSION__) || !(__STDC_VERSION__ >= 199901L)
-#define	__func__	__PRETTY_FUNCTION__
-#endif /* !(__STDC_VERSION__ >= 199901L) */
+#define __printflike(x, y) __attribute__((__format__(printf, x, y)))
+#define __scanflike(x, y) __attribute__((__format__(scanf, x, y)))
 
 /*
- * GNU C version 2.96 adds explicit branch prediction so that
+ * GNU C version 2.96 added explicit branch prediction so that
  * the CPU back-end can hint the processor and also so that
  * code blocks can be reordered such that the predicted path
  * sees a more linear flow, thus improving cache behavior, etc.
@@ -207,16 +183,13 @@
 #define	__predict_true(exp)	__builtin_expect((exp) != 0, 1)
 #define	__predict_false(exp)	__builtin_expect((exp) != 0, 0)
 
-#define __noreturn    __attribute__((__noreturn__))
-#define __mallocfunc  __attribute__((malloc))
-#define __purefunc    __attribute__((pure))
-
-#define __always_inline __attribute__((__always_inline__))
-
 #define __wur __attribute__((__warn_unused_result__))
 
+#ifdef __clang__
+#define __errorattr(msg) __attribute__((unavailable(msg)))
+#else
 #define __errorattr(msg) __attribute__((__error__(msg)))
-#define __warnattr(msg) __attribute__((__warning__(msg)))
+#endif
 
 #define __errordecl(name, msg) extern void name(void) __errorattr(msg)
 
@@ -232,175 +205,34 @@
 #define __SCCSID(_s) /* nothing */
 
 /*
- * _BSD_SOURCE and _GNU_SOURCE are expected to be defined by callers before
- * any standard header file is included. In those header files we test
- * against __USE_BSD and __USE_GNU. glibc does this in <features.h> but we
- * do it in <sys/cdefs.h> instead because that's where our existing
- * _POSIX_C_SOURCE tests were, and we're already confident that <sys/cdefs.h>
- * is included everywhere it should be.
+ * With bionic, you always get all C and POSIX API.
  *
- * The _GNU_SOURCE test needs to come before any _BSD_SOURCE or _POSIX* tests
- * because _GNU_SOURCE implies everything else.
+ * If you want BSD and/or GNU extensions, _BSD_SOURCE and/or _GNU_SOURCE are
+ * expected to be defined by callers before *any* standard header file is
+ * included.
+ *
+ * In our header files we test against __USE_BSD and __USE_GNU.
  */
 #if defined(_GNU_SOURCE)
+# define __USE_BSD 1
 # define __USE_GNU 1
-# undef _POSIX_SOURCE
-# define _POSIX_SOURCE 1
-# undef _POSIX_C_SOURCE
-# define _POSIX_C_SOURCE 200809L
-# undef _BSD_SOURCE
-# define _BSD_SOURCE 1
 #endif
 
 #if defined(_BSD_SOURCE)
 # define __USE_BSD 1
 #endif
 
-/*
- * _FILE_OFFSET_BITS 64 support.
- */
+/* _FILE_OFFSET_BITS 64 support. */
 #if !defined(__LP64__) && defined(_FILE_OFFSET_BITS)
 #if _FILE_OFFSET_BITS == 64
 #define __USE_FILE_OFFSET64 1
 #endif
 #endif
 
-/*-
- * POSIX.1 requires that the macros we test be defined before any standard
- * header file is included.
- *
- * Here's a quick run-down of the versions:
- *  defined(_POSIX_SOURCE)		1003.1-1988
- *  _POSIX_C_SOURCE == 1		1003.1-1990
- *  _POSIX_C_SOURCE == 2		1003.2-1992 C Language Binding Option
- *  _POSIX_C_SOURCE == 199309		1003.1b-1993
- *  _POSIX_C_SOURCE == 199506		1003.1c-1995, 1003.1i-1995,
- *					and the omnibus ISO/IEC 9945-1: 1996
- *  _POSIX_C_SOURCE == 200112		1003.1-2001
- *  _POSIX_C_SOURCE == 200809		1003.1-2008
- *
- * In addition, the X/Open Portability Guide, which is now the Single UNIX
- * Specification, defines a feature-test macro which indicates the version of
- * that specification, and which subsumes _POSIX_C_SOURCE.
- *
- * Our macros begin with two underscores to avoid namespace screwage.
- */
-
-/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */
-#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1
-#undef _POSIX_C_SOURCE		/* Probably illegal, but beyond caring now. */
-#define	_POSIX_C_SOURCE		199009
-#endif
-
-/* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */
-#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2
-#undef _POSIX_C_SOURCE
-#define	_POSIX_C_SOURCE		199209
-#endif
-
-/* Deal with various X/Open Portability Guides and Single UNIX Spec. */
-#ifdef _XOPEN_SOURCE
-#if _XOPEN_SOURCE - 0 >= 700
-#define	__XSI_VISIBLE		700
-#undef _POSIX_C_SOURCE
-#define	_POSIX_C_SOURCE		200809
-#elif _XOPEN_SOURCE - 0 >= 600
-#define	__XSI_VISIBLE		600
-#undef _POSIX_C_SOURCE
-#define	_POSIX_C_SOURCE		200112
-#elif _XOPEN_SOURCE - 0 >= 500
-#define	__XSI_VISIBLE		500
-#undef _POSIX_C_SOURCE
-#define	_POSIX_C_SOURCE		199506
-#endif
-#endif
-
-/*
- * Deal with all versions of POSIX.  The ordering relative to the tests above is
- * important.
- */
-#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
-#define	_POSIX_C_SOURCE		198808
-#endif
-#ifdef _POSIX_C_SOURCE
-#if _POSIX_C_SOURCE >= 200809
-#define	__POSIX_VISIBLE		200809
-#define	__ISO_C_VISIBLE		1999
-#elif _POSIX_C_SOURCE >= 200112
-#define	__POSIX_VISIBLE		200112
-#define	__ISO_C_VISIBLE		1999
-#elif _POSIX_C_SOURCE >= 199506
-#define	__POSIX_VISIBLE		199506
-#define	__ISO_C_VISIBLE		1990
-#elif _POSIX_C_SOURCE >= 199309
-#define	__POSIX_VISIBLE		199309
-#define	__ISO_C_VISIBLE		1990
-#elif _POSIX_C_SOURCE >= 199209
-#define	__POSIX_VISIBLE		199209
-#define	__ISO_C_VISIBLE		1990
-#elif _POSIX_C_SOURCE >= 199009
-#define	__POSIX_VISIBLE		199009
-#define	__ISO_C_VISIBLE		1990
-#else
-#define	__POSIX_VISIBLE		198808
-#define	__ISO_C_VISIBLE		0
-#endif /* _POSIX_C_SOURCE */
-#else
-/*-
- * Deal with _ANSI_SOURCE:
- * If it is defined, and no other compilation environment is explicitly
- * requested, then define our internal feature-test macros to zero.  This
- * makes no difference to the preprocessor (undefined symbols in preprocessing
- * expressions are defined to have value zero), but makes it more convenient for
- * a test program to print out the values.
- *
- * If a program mistakenly defines _ANSI_SOURCE and some other macro such as
- * _POSIX_C_SOURCE, we will assume that it wants the broader compilation
- * environment (and in fact we will never get here).
- */
-#if defined(_ANSI_SOURCE)	/* Hide almost everything. */
-#define	__POSIX_VISIBLE		0
-#define	__XSI_VISIBLE		0
-#define	__BSD_VISIBLE		0
-#define	__ISO_C_VISIBLE		1990
-#elif defined(_C99_SOURCE)	/* Localism to specify strict C99 env. */
-#define	__POSIX_VISIBLE		0
-#define	__XSI_VISIBLE		0
-#define	__BSD_VISIBLE		0
-#define	__ISO_C_VISIBLE		1999
-#else				/* Default environment: show everything. */
-#define	__POSIX_VISIBLE		200809
-#define	__XSI_VISIBLE		700
-#define	__BSD_VISIBLE		1
-#define	__ISO_C_VISIBLE		1999
-#endif
-#endif
-
-/*
- * Default values.
- */
-#ifndef __XPG_VISIBLE
-# define __XPG_VISIBLE          700
-#endif
-#ifndef __POSIX_VISIBLE
-# define __POSIX_VISIBLE        200809
-#endif
-#ifndef __ISO_C_VISIBLE
-# define __ISO_C_VISIBLE        1999
-#endif
-#ifndef __BSD_VISIBLE
-# define __BSD_VISIBLE          1
-#endif
-
 #define  __BIONIC__   1
 #include <android/api-level.h>
 
 /* glibc compatibility. */
-#if __POSIX_VISIBLE >= 200809
-#define __USE_ISOC99 1
-#define __USE_XOPEN2K 1
-#define __USE_XOPEN2K8 1
-#endif
 #if __LP64__
 #define __WORDSIZE 64
 #else
@@ -423,37 +255,67 @@
 #    define __bos(s) __builtin_object_size((s), 0)
 #  endif
 #  define __bos0(s) __builtin_object_size((s), 0)
-#  define __BIONIC_FORTIFY_INLINE extern __inline__ __always_inline __attribute__((gnu_inline)) __attribute__((__artificial__))
+#  if defined(__clang__)
+#    define __BIONIC_FORTIFY_INLINE extern __inline__ __always_inline __attribute__((gnu_inline))
+#  else
+#    define __BIONIC_FORTIFY_INLINE extern __inline__ __always_inline __attribute__((gnu_inline)) __attribute__((__artificial__))
+#  endif
 #endif
-#define __BIONIC_FORTIFY_UNKNOWN_SIZE ((size_t) -1)
+#define __BIONIC_FORTIFY_UNKNOWN_SIZE __BIONIC_CAST(static_cast, size_t, -1)
 
 /* Used to tag non-static symbols that are private and never exposed by the shared library. */
 #define __LIBC_HIDDEN__ __attribute__((visibility("hidden")))
 
-/* Like __LIBC_HIDDEN__, but preserves binary compatibility for LP32. */
+/*
+ * Used to tag symbols that should be hidden for 64-bit,
+ * but visible to preserve binary compatibility for LP32.
+ */
 #ifdef __LP64__
-#define __LIBC32_LEGACY_PUBLIC__ __LIBC_HIDDEN__
+#define __LIBC32_LEGACY_PUBLIC__ __attribute__((visibility("hidden")))
 #else
-#define __LIBC32_LEGACY_PUBLIC__ __LIBC_ABI_PUBLIC__
+#define __LIBC32_LEGACY_PUBLIC__ __attribute__((visibility("default")))
 #endif
 
-/* Used to tag non-static symbols that are public and exposed by the shared library. */
-#define __LIBC_ABI_PUBLIC__ __attribute__((visibility ("default")))
-
 /* Used to rename functions so that the compiler emits a call to 'x' rather than the function this was applied to. */
 #define __RENAME(x) __asm__(#x)
 
 #ifdef __clang__
 #define __AVAILABILITY(...) __attribute__((availability(android,__VA_ARGS__)))
+#else
+#define __AVAILABILITY(...)
+#endif
+
 #define __INTRODUCED_IN(api_level) __AVAILABILITY(introduced=api_level)
 #define __DEPRECATED_IN(api_level) __AVAILABILITY(deprecated=api_level)
 #define __REMOVED_IN(api_level) __AVAILABILITY(obsoleted=api_level)
+
+#define __INTRODUCED_IN_FUTURE __INTRODUCED_IN(10000)
+
+#if __LP64__
+#define __INTRODUCED_IN_32(api_level)
+#define __INTRODUCED_IN_64 __INTRODUCED_IN
 #else
-#define __AVAILABILITY(...)
-#define __INTRODUCED_IN(api_level)
-#define __DEPRECATED_IN(api_level)
-#define __REMOVED_IN(api_level)
-#endif // __clang__
+#define __INTRODUCED_IN_32 __INTRODUCED_IN
+#define __INTRODUCED_IN_64(api_level)
+#endif
+
+#if defined(__arm__)
+#define __INTRODUCED_IN_ARM __INTRODUCED_IN
+#else
+#define __INTRODUCED_IN_ARM(x)
+#endif
+
+#if defined(__i386__)
+#define __INTRODUCED_IN_X86 __INTRODUCED_IN
+#else
+#define __INTRODUCED_IN_X86(x)
+#endif
+
+#if defined(__mips__)
+#define __INTRODUCED_IN_MIPS __INTRODUCED_IN
+#else
+#define __INTRODUCED_IN_MIPS(x)
+#endif
 
 #if __has_builtin(__builtin_umul_overflow) || __GNUC__ >= 5
 #if __LP64__
@@ -470,4 +332,17 @@
 }
 #endif
 
+/*
+ * TODO(danalbert): Remove this once we've moved entirely off prebuilts/ndk.
+ *
+ * The NDK used to have a __NDK_FPABI__ that was defined to empty for most cases
+ * but `__attribute__((pcs("aapcs")))` for the now defunct armeabi-v7a-hard ABI.
+ *
+ * During the transition from prebuilts/ndk to ndk_headers, we'll have some
+ * headers that still use __NDK_FPABI__ while the libc headers have stopped
+ * defining it. In the interim, just provide an empty definition to keep the
+ * build working.
+ */
+#define __NDK_FPABI__
+
 #endif /* !_SYS_CDEFS_H_ */
diff --git a/libc/include/sys/endian.h b/libc/include/sys/endian.h
index 60cc030..b9e4758 100644
--- a/libc/include/sys/endian.h
+++ b/libc/include/sys/endian.h
@@ -49,10 +49,10 @@
 
 /* glibc compatibility. */
 __BEGIN_DECLS
-uint32_t htonl(uint32_t) __pure2;
-uint16_t htons(uint16_t) __pure2;
-uint32_t ntohl(uint32_t) __pure2;
-uint16_t ntohs(uint16_t) __pure2;
+uint32_t htonl(uint32_t) __pure2 __INTRODUCED_IN(21);
+uint16_t htons(uint16_t) __pure2 __INTRODUCED_IN(21);
+uint32_t ntohl(uint32_t) __pure2 __INTRODUCED_IN(21);
+uint16_t ntohs(uint16_t) __pure2 __INTRODUCED_IN(21);
 __END_DECLS
 
 #define htonl(x) __swap32(x)
@@ -64,7 +64,7 @@
 #define htonq(x) __swap64(x)
 #define ntohq(x) __swap64(x)
 
-#if __BSD_VISIBLE
+#if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
 #define LITTLE_ENDIAN _LITTLE_ENDIAN
 #define BIG_ENDIAN _BIG_ENDIAN
 #define PDP_ENDIAN _PDP_ENDIAN
@@ -101,6 +101,6 @@
 #define le16toh(x) htole16(x)
 #define le32toh(x) htole32(x)
 #define le64toh(x) htole64(x)
-#endif /* __BSD_VISIBLE */
+#endif /* __USE_BSD */
 
 #endif /* _SYS_ENDIAN_H_ */
diff --git a/libc/include/sys/epoll.h b/libc/include/sys/epoll.h
index 4a5a37c..4ec8969 100644
--- a/libc/include/sys/epoll.h
+++ b/libc/include/sys/epoll.h
@@ -74,10 +74,10 @@
 ;
 
 int epoll_create(int);
-int epoll_create1(int);
+int epoll_create1(int) __INTRODUCED_IN(21);
 int epoll_ctl(int, int, int, struct epoll_event*);
 int epoll_wait(int, struct epoll_event*, int, int);
-int epoll_pwait(int, struct epoll_event*, int, int, const sigset_t*);
+int epoll_pwait(int, struct epoll_event*, int, int, const sigset_t*) __INTRODUCED_IN(21);
 
 __END_DECLS
 
diff --git a/libc/include/sys/eventfd.h b/libc/include/sys/eventfd.h
index 4c8da0c..6b9749a 100644
--- a/libc/include/sys/eventfd.h
+++ b/libc/include/sys/eventfd.h
@@ -40,10 +40,10 @@
 /* type of event counter */
 typedef uint64_t eventfd_t;
 
-extern int eventfd(unsigned int initial_value, int flags);
+int eventfd(unsigned int initial_value, int flags);
 
-extern int eventfd_read(int fd, eventfd_t* value);
-extern int eventfd_write(int fd, eventfd_t value);
+int eventfd_read(int fd, eventfd_t* value);
+int eventfd_write(int fd, eventfd_t value);
 
 __END_DECLS
 
diff --git a/libc/include/sys/fsuid.h b/libc/include/sys/fsuid.h
index 03355b7..e4d9ebc 100644
--- a/libc/include/sys/fsuid.h
+++ b/libc/include/sys/fsuid.h
@@ -34,8 +34,8 @@
 
 __BEGIN_DECLS
 
-extern int setfsuid(uid_t);
-extern int setfsgid(gid_t);
+int setfsuid(uid_t) __INTRODUCED_IN(21);
+int setfsgid(gid_t) __INTRODUCED_IN(21);
 
 __END_DECLS
 
diff --git a/libc/include/sys/glibc-syscalls.h b/libc/include/sys/glibc-syscalls.h
deleted file mode 100644
index 26887b1..0000000
--- a/libc/include/sys/glibc-syscalls.h
+++ /dev/null
@@ -1,1759 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-#ifndef _BIONIC_GLIBC_SYSCALLS_H_
-#define _BIONIC_GLIBC_SYSCALLS_H_
-#if defined(__aarch64__)
-#define SYS_accept __NR_accept
-#define SYS_accept4 __NR_accept4
-#define SYS_access __NR_access
-#define SYS_acct __NR_acct
-#define SYS_add_key __NR_add_key
-#define SYS_adjtimex __NR_adjtimex
-#define SYS_alarm __NR_alarm
-#define SYS_arch_specific_syscall __NR_arch_specific_syscall
-#define SYS_bdflush __NR_bdflush
-#define SYS_bind __NR_bind
-#define SYS_bpf __NR_bpf
-#define SYS_brk __NR_brk
-#define SYS_capget __NR_capget
-#define SYS_capset __NR_capset
-#define SYS_chdir __NR_chdir
-#define SYS_chmod __NR_chmod
-#define SYS_chown __NR_chown
-#define SYS_chroot __NR_chroot
-#define SYS_clock_adjtime __NR_clock_adjtime
-#define SYS_clock_getres __NR_clock_getres
-#define SYS_clock_gettime __NR_clock_gettime
-#define SYS_clock_nanosleep __NR_clock_nanosleep
-#define SYS_clock_settime __NR_clock_settime
-#define SYS_clone __NR_clone
-#define SYS_close __NR_close
-#define SYS_connect __NR_connect
-#define SYS_creat __NR_creat
-#define SYS_delete_module __NR_delete_module
-#define SYS_dup __NR_dup
-#define SYS_dup2 __NR_dup2
-#define SYS_dup3 __NR_dup3
-#define SYS_epoll_create __NR_epoll_create
-#define SYS_epoll_create1 __NR_epoll_create1
-#define SYS_epoll_ctl __NR_epoll_ctl
-#define SYS_epoll_pwait __NR_epoll_pwait
-#define SYS_epoll_wait __NR_epoll_wait
-#define SYS_eventfd __NR_eventfd
-#define SYS_eventfd2 __NR_eventfd2
-#define SYS_execve __NR_execve
-#define SYS_execveat __NR_execveat
-#define SYS_exit __NR_exit
-#define SYS_exit_group __NR_exit_group
-#define SYS_faccessat __NR_faccessat
-#define SYS_fadvise64 __NR_fadvise64
-#define SYS_fadvise64_64 __NR_fadvise64_64
-#define SYS_fallocate __NR_fallocate
-#define SYS_fanotify_init __NR_fanotify_init
-#define SYS_fanotify_mark __NR_fanotify_mark
-#define SYS_fchdir __NR_fchdir
-#define SYS_fchmod __NR_fchmod
-#define SYS_fchmodat __NR_fchmodat
-#define SYS_fchown __NR_fchown
-#define SYS_fchownat __NR_fchownat
-#define SYS_fcntl __NR_fcntl
-#define SYS_fcntl64 __NR_fcntl64
-#define SYS_fdatasync __NR_fdatasync
-#define SYS_fgetxattr __NR_fgetxattr
-#define SYS_finit_module __NR_finit_module
-#define SYS_flistxattr __NR_flistxattr
-#define SYS_flock __NR_flock
-#define SYS_fork __NR_fork
-#define SYS_fremovexattr __NR_fremovexattr
-#define SYS_fsetxattr __NR_fsetxattr
-#define SYS_fstat __NR_fstat
-#define SYS_fstat64 __NR_fstat64
-#define SYS_fstatat64 __NR_fstatat64
-#define SYS_fstatfs __NR_fstatfs
-#define SYS_fstatfs64 __NR_fstatfs64
-#define SYS_fsync __NR_fsync
-#define SYS_ftruncate __NR_ftruncate
-#define SYS_ftruncate64 __NR_ftruncate64
-#define SYS_futex __NR_futex
-#define SYS_futimesat __NR_futimesat
-#define SYS_get_mempolicy __NR_get_mempolicy
-#define SYS_get_robust_list __NR_get_robust_list
-#define SYS_getcpu __NR_getcpu
-#define SYS_getcwd __NR_getcwd
-#define SYS_getdents __NR_getdents
-#define SYS_getdents64 __NR_getdents64
-#define SYS_getegid __NR_getegid
-#define SYS_geteuid __NR_geteuid
-#define SYS_getgid __NR_getgid
-#define SYS_getgroups __NR_getgroups
-#define SYS_getitimer __NR_getitimer
-#define SYS_getpeername __NR_getpeername
-#define SYS_getpgid __NR_getpgid
-#define SYS_getpgrp __NR_getpgrp
-#define SYS_getpid __NR_getpid
-#define SYS_getppid __NR_getppid
-#define SYS_getpriority __NR_getpriority
-#define SYS_getrandom __NR_getrandom
-#define SYS_getresgid __NR_getresgid
-#define SYS_getresuid __NR_getresuid
-#define SYS_getrlimit __NR_getrlimit
-#define SYS_getrusage __NR_getrusage
-#define SYS_getsid __NR_getsid
-#define SYS_getsockname __NR_getsockname
-#define SYS_getsockopt __NR_getsockopt
-#define SYS_gettid __NR_gettid
-#define SYS_gettimeofday __NR_gettimeofday
-#define SYS_getuid __NR_getuid
-#define SYS_getxattr __NR_getxattr
-#define SYS_init_module __NR_init_module
-#define SYS_inotify_add_watch __NR_inotify_add_watch
-#define SYS_inotify_init __NR_inotify_init
-#define SYS_inotify_init1 __NR_inotify_init1
-#define SYS_inotify_rm_watch __NR_inotify_rm_watch
-#define SYS_io_cancel __NR_io_cancel
-#define SYS_io_destroy __NR_io_destroy
-#define SYS_io_getevents __NR_io_getevents
-#define SYS_io_setup __NR_io_setup
-#define SYS_io_submit __NR_io_submit
-#define SYS_ioctl __NR_ioctl
-#define SYS_ioprio_get __NR_ioprio_get
-#define SYS_ioprio_set __NR_ioprio_set
-#define SYS_kcmp __NR_kcmp
-#define SYS_kexec_load __NR_kexec_load
-#define SYS_keyctl __NR_keyctl
-#define SYS_kill __NR_kill
-#define SYS_lchown __NR_lchown
-#define SYS_lgetxattr __NR_lgetxattr
-#define SYS_link __NR_link
-#define SYS_linkat __NR_linkat
-#define SYS_listen __NR_listen
-#define SYS_listxattr __NR_listxattr
-#define SYS_llistxattr __NR_llistxattr
-#define SYS_llseek __NR_llseek
-#define SYS_lookup_dcookie __NR_lookup_dcookie
-#define SYS_lremovexattr __NR_lremovexattr
-#define SYS_lseek __NR_lseek
-#define SYS_lsetxattr __NR_lsetxattr
-#define SYS_lstat __NR_lstat
-#define SYS_lstat64 __NR_lstat64
-#define SYS_madvise __NR_madvise
-#define SYS_mbind __NR_mbind
-#define SYS_membarrier __NR_membarrier
-#define SYS_memfd_create __NR_memfd_create
-#define SYS_migrate_pages __NR_migrate_pages
-#define SYS_mincore __NR_mincore
-#define SYS_mkdir __NR_mkdir
-#define SYS_mkdirat __NR_mkdirat
-#define SYS_mknod __NR_mknod
-#define SYS_mknodat __NR_mknodat
-#define SYS_mlock __NR_mlock
-#define SYS_mlock2 __NR_mlock2
-#define SYS_mlockall __NR_mlockall
-#define SYS_mmap __NR_mmap
-#define SYS_mmap2 __NR_mmap2
-#define SYS_mount __NR_mount
-#define SYS_move_pages __NR_move_pages
-#define SYS_mprotect __NR_mprotect
-#define SYS_mq_getsetattr __NR_mq_getsetattr
-#define SYS_mq_notify __NR_mq_notify
-#define SYS_mq_open __NR_mq_open
-#define SYS_mq_timedreceive __NR_mq_timedreceive
-#define SYS_mq_timedsend __NR_mq_timedsend
-#define SYS_mq_unlink __NR_mq_unlink
-#define SYS_mremap __NR_mremap
-#define SYS_msgctl __NR_msgctl
-#define SYS_msgget __NR_msgget
-#define SYS_msgrcv __NR_msgrcv
-#define SYS_msgsnd __NR_msgsnd
-#define SYS_msync __NR_msync
-#define SYS_munlock __NR_munlock
-#define SYS_munlockall __NR_munlockall
-#define SYS_munmap __NR_munmap
-#define SYS_name_to_handle_at __NR_name_to_handle_at
-#define SYS_nanosleep __NR_nanosleep
-#define SYS_newfstatat __NR_newfstatat
-#define SYS_nfsservctl __NR_nfsservctl
-#define SYS_oldwait4 __NR_oldwait4
-#define SYS_open __NR_open
-#define SYS_open_by_handle_at __NR_open_by_handle_at
-#define SYS_openat __NR_openat
-#define SYS_pause __NR_pause
-#define SYS_perf_event_open __NR_perf_event_open
-#define SYS_personality __NR_personality
-#define SYS_pipe __NR_pipe
-#define SYS_pipe2 __NR_pipe2
-#define SYS_pivot_root __NR_pivot_root
-#define SYS_poll __NR_poll
-#define SYS_ppoll __NR_ppoll
-#define SYS_prctl __NR_prctl
-#define SYS_pread64 __NR_pread64
-#define SYS_preadv __NR_preadv
-#define SYS_prlimit64 __NR_prlimit64
-#define SYS_process_vm_readv __NR_process_vm_readv
-#define SYS_process_vm_writev __NR_process_vm_writev
-#define SYS_pselect6 __NR_pselect6
-#define SYS_ptrace __NR_ptrace
-#define SYS_pwrite64 __NR_pwrite64
-#define SYS_pwritev __NR_pwritev
-#define SYS_quotactl __NR_quotactl
-#define SYS_read __NR_read
-#define SYS_readahead __NR_readahead
-#define SYS_readlink __NR_readlink
-#define SYS_readlinkat __NR_readlinkat
-#define SYS_readv __NR_readv
-#define SYS_reboot __NR_reboot
-#define SYS_recv __NR_recv
-#define SYS_recvfrom __NR_recvfrom
-#define SYS_recvmmsg __NR_recvmmsg
-#define SYS_recvmsg __NR_recvmsg
-#define SYS_remap_file_pages __NR_remap_file_pages
-#define SYS_removexattr __NR_removexattr
-#define SYS_rename __NR_rename
-#define SYS_renameat __NR_renameat
-#define SYS_renameat2 __NR_renameat2
-#define SYS_request_key __NR_request_key
-#define SYS_restart_syscall __NR_restart_syscall
-#define SYS_rmdir __NR_rmdir
-#define SYS_rt_sigaction __NR_rt_sigaction
-#define SYS_rt_sigpending __NR_rt_sigpending
-#define SYS_rt_sigprocmask __NR_rt_sigprocmask
-#define SYS_rt_sigqueueinfo __NR_rt_sigqueueinfo
-#define SYS_rt_sigreturn __NR_rt_sigreturn
-#define SYS_rt_sigsuspend __NR_rt_sigsuspend
-#define SYS_rt_sigtimedwait __NR_rt_sigtimedwait
-#define SYS_rt_tgsigqueueinfo __NR_rt_tgsigqueueinfo
-#define SYS_sched_get_priority_max __NR_sched_get_priority_max
-#define SYS_sched_get_priority_min __NR_sched_get_priority_min
-#define SYS_sched_getaffinity __NR_sched_getaffinity
-#define SYS_sched_getattr __NR_sched_getattr
-#define SYS_sched_getparam __NR_sched_getparam
-#define SYS_sched_getscheduler __NR_sched_getscheduler
-#define SYS_sched_rr_get_interval __NR_sched_rr_get_interval
-#define SYS_sched_setaffinity __NR_sched_setaffinity
-#define SYS_sched_setattr __NR_sched_setattr
-#define SYS_sched_setparam __NR_sched_setparam
-#define SYS_sched_setscheduler __NR_sched_setscheduler
-#define SYS_sched_yield __NR_sched_yield
-#define SYS_seccomp __NR_seccomp
-#define SYS_select __NR_select
-#define SYS_semctl __NR_semctl
-#define SYS_semget __NR_semget
-#define SYS_semop __NR_semop
-#define SYS_semtimedop __NR_semtimedop
-#define SYS_send __NR_send
-#define SYS_sendfile __NR_sendfile
-#define SYS_sendfile64 __NR_sendfile64
-#define SYS_sendmmsg __NR_sendmmsg
-#define SYS_sendmsg __NR_sendmsg
-#define SYS_sendto __NR_sendto
-#define SYS_set_mempolicy __NR_set_mempolicy
-#define SYS_set_robust_list __NR_set_robust_list
-#define SYS_set_tid_address __NR_set_tid_address
-#define SYS_setdomainname __NR_setdomainname
-#define SYS_setfsgid __NR_setfsgid
-#define SYS_setfsuid __NR_setfsuid
-#define SYS_setgid __NR_setgid
-#define SYS_setgroups __NR_setgroups
-#define SYS_sethostname __NR_sethostname
-#define SYS_setitimer __NR_setitimer
-#define SYS_setns __NR_setns
-#define SYS_setpgid __NR_setpgid
-#define SYS_setpriority __NR_setpriority
-#define SYS_setregid __NR_setregid
-#define SYS_setresgid __NR_setresgid
-#define SYS_setresuid __NR_setresuid
-#define SYS_setreuid __NR_setreuid
-#define SYS_setrlimit __NR_setrlimit
-#define SYS_setsid __NR_setsid
-#define SYS_setsockopt __NR_setsockopt
-#define SYS_settimeofday __NR_settimeofday
-#define SYS_setuid __NR_setuid
-#define SYS_setxattr __NR_setxattr
-#define SYS_shmat __NR_shmat
-#define SYS_shmctl __NR_shmctl
-#define SYS_shmdt __NR_shmdt
-#define SYS_shmget __NR_shmget
-#define SYS_shutdown __NR_shutdown
-#define SYS_sigaltstack __NR_sigaltstack
-#define SYS_signalfd __NR_signalfd
-#define SYS_signalfd4 __NR_signalfd4
-#define SYS_socket __NR_socket
-#define SYS_socketpair __NR_socketpair
-#define SYS_splice __NR_splice
-#define SYS_stat __NR_stat
-#define SYS_stat64 __NR_stat64
-#define SYS_statfs __NR_statfs
-#define SYS_statfs64 __NR_statfs64
-#define SYS_swapoff __NR_swapoff
-#define SYS_swapon __NR_swapon
-#define SYS_symlink __NR_symlink
-#define SYS_symlinkat __NR_symlinkat
-#define SYS_sync __NR_sync
-#define SYS_sync_file_range __NR_sync_file_range
-#define SYS_sync_file_range2 __NR_sync_file_range2
-#define SYS_syncfs __NR_syncfs
-#define SYS_syscalls __NR_syscalls
-#define SYS_sysinfo __NR_sysinfo
-#define SYS_syslog __NR_syslog
-#define SYS_tee __NR_tee
-#define SYS_tgkill __NR_tgkill
-#define SYS_time __NR_time
-#define SYS_timer_create __NR_timer_create
-#define SYS_timer_delete __NR_timer_delete
-#define SYS_timer_getoverrun __NR_timer_getoverrun
-#define SYS_timer_gettime __NR_timer_gettime
-#define SYS_timer_settime __NR_timer_settime
-#define SYS_timerfd_create __NR_timerfd_create
-#define SYS_timerfd_gettime __NR_timerfd_gettime
-#define SYS_timerfd_settime __NR_timerfd_settime
-#define SYS_times __NR_times
-#define SYS_tkill __NR_tkill
-#define SYS_truncate __NR_truncate
-#define SYS_truncate64 __NR_truncate64
-#define SYS_umask __NR_umask
-#define SYS_umount __NR_umount
-#define SYS_umount2 __NR_umount2
-#define SYS_uname __NR_uname
-#define SYS_unlink __NR_unlink
-#define SYS_unlinkat __NR_unlinkat
-#define SYS_unshare __NR_unshare
-#define SYS_uselib __NR_uselib
-#define SYS_userfaultfd __NR_userfaultfd
-#define SYS_ustat __NR_ustat
-#define SYS_utime __NR_utime
-#define SYS_utimensat __NR_utimensat
-#define SYS_utimes __NR_utimes
-#define SYS_vfork __NR_vfork
-#define SYS_vhangup __NR_vhangup
-#define SYS_vmsplice __NR_vmsplice
-#define SYS_wait4 __NR_wait4
-#define SYS_waitid __NR_waitid
-#define SYS_write __NR_write
-#define SYS_writev __NR_writev
-#elif defined(__arm__)
-#define SYS_accept __NR_accept
-#define SYS_accept4 __NR_accept4
-#define SYS_access __NR_access
-#define SYS_acct __NR_acct
-#define SYS_add_key __NR_add_key
-#define SYS_adjtimex __NR_adjtimex
-#define SYS_alarm __NR_alarm
-#define SYS_arm_fadvise64_64 __NR_arm_fadvise64_64
-#define SYS_arm_sync_file_range __NR_arm_sync_file_range
-#define SYS_bdflush __NR_bdflush
-#define SYS_bind __NR_bind
-#define SYS_bpf __NR_bpf
-#define SYS_brk __NR_brk
-#define SYS_capget __NR_capget
-#define SYS_capset __NR_capset
-#define SYS_chdir __NR_chdir
-#define SYS_chmod __NR_chmod
-#define SYS_chown __NR_chown
-#define SYS_chown32 __NR_chown32
-#define SYS_chroot __NR_chroot
-#define SYS_clock_adjtime __NR_clock_adjtime
-#define SYS_clock_getres __NR_clock_getres
-#define SYS_clock_gettime __NR_clock_gettime
-#define SYS_clock_nanosleep __NR_clock_nanosleep
-#define SYS_clock_settime __NR_clock_settime
-#define SYS_clone __NR_clone
-#define SYS_close __NR_close
-#define SYS_connect __NR_connect
-#define SYS_creat __NR_creat
-#define SYS_delete_module __NR_delete_module
-#define SYS_dup __NR_dup
-#define SYS_dup2 __NR_dup2
-#define SYS_dup3 __NR_dup3
-#define SYS_epoll_create __NR_epoll_create
-#define SYS_epoll_create1 __NR_epoll_create1
-#define SYS_epoll_ctl __NR_epoll_ctl
-#define SYS_epoll_pwait __NR_epoll_pwait
-#define SYS_epoll_wait __NR_epoll_wait
-#define SYS_eventfd __NR_eventfd
-#define SYS_eventfd2 __NR_eventfd2
-#define SYS_execve __NR_execve
-#define SYS_execveat __NR_execveat
-#define SYS_exit __NR_exit
-#define SYS_exit_group __NR_exit_group
-#define SYS_faccessat __NR_faccessat
-#define SYS_fallocate __NR_fallocate
-#define SYS_fanotify_init __NR_fanotify_init
-#define SYS_fanotify_mark __NR_fanotify_mark
-#define SYS_fchdir __NR_fchdir
-#define SYS_fchmod __NR_fchmod
-#define SYS_fchmodat __NR_fchmodat
-#define SYS_fchown __NR_fchown
-#define SYS_fchown32 __NR_fchown32
-#define SYS_fchownat __NR_fchownat
-#define SYS_fcntl __NR_fcntl
-#define SYS_fcntl64 __NR_fcntl64
-#define SYS_fdatasync __NR_fdatasync
-#define SYS_fgetxattr __NR_fgetxattr
-#define SYS_finit_module __NR_finit_module
-#define SYS_flistxattr __NR_flistxattr
-#define SYS_flock __NR_flock
-#define SYS_fork __NR_fork
-#define SYS_fremovexattr __NR_fremovexattr
-#define SYS_fsetxattr __NR_fsetxattr
-#define SYS_fstat __NR_fstat
-#define SYS_fstat64 __NR_fstat64
-#define SYS_fstatat64 __NR_fstatat64
-#define SYS_fstatfs __NR_fstatfs
-#define SYS_fstatfs64 __NR_fstatfs64
-#define SYS_fsync __NR_fsync
-#define SYS_ftruncate __NR_ftruncate
-#define SYS_ftruncate64 __NR_ftruncate64
-#define SYS_futex __NR_futex
-#define SYS_futimesat __NR_futimesat
-#define SYS_get_mempolicy __NR_get_mempolicy
-#define SYS_get_robust_list __NR_get_robust_list
-#define SYS_getcpu __NR_getcpu
-#define SYS_getcwd __NR_getcwd
-#define SYS_getdents __NR_getdents
-#define SYS_getdents64 __NR_getdents64
-#define SYS_getegid __NR_getegid
-#define SYS_getegid32 __NR_getegid32
-#define SYS_geteuid __NR_geteuid
-#define SYS_geteuid32 __NR_geteuid32
-#define SYS_getgid __NR_getgid
-#define SYS_getgid32 __NR_getgid32
-#define SYS_getgroups __NR_getgroups
-#define SYS_getgroups32 __NR_getgroups32
-#define SYS_getitimer __NR_getitimer
-#define SYS_getpeername __NR_getpeername
-#define SYS_getpgid __NR_getpgid
-#define SYS_getpgrp __NR_getpgrp
-#define SYS_getpid __NR_getpid
-#define SYS_getppid __NR_getppid
-#define SYS_getpriority __NR_getpriority
-#define SYS_getrandom __NR_getrandom
-#define SYS_getresgid __NR_getresgid
-#define SYS_getresgid32 __NR_getresgid32
-#define SYS_getresuid __NR_getresuid
-#define SYS_getresuid32 __NR_getresuid32
-#define SYS_getrlimit __NR_getrlimit
-#define SYS_getrusage __NR_getrusage
-#define SYS_getsid __NR_getsid
-#define SYS_getsockname __NR_getsockname
-#define SYS_getsockopt __NR_getsockopt
-#define SYS_gettid __NR_gettid
-#define SYS_gettimeofday __NR_gettimeofday
-#define SYS_getuid __NR_getuid
-#define SYS_getuid32 __NR_getuid32
-#define SYS_getxattr __NR_getxattr
-#define SYS_init_module __NR_init_module
-#define SYS_inotify_add_watch __NR_inotify_add_watch
-#define SYS_inotify_init __NR_inotify_init
-#define SYS_inotify_init1 __NR_inotify_init1
-#define SYS_inotify_rm_watch __NR_inotify_rm_watch
-#define SYS_io_cancel __NR_io_cancel
-#define SYS_io_destroy __NR_io_destroy
-#define SYS_io_getevents __NR_io_getevents
-#define SYS_io_setup __NR_io_setup
-#define SYS_io_submit __NR_io_submit
-#define SYS_ioctl __NR_ioctl
-#define SYS_ioprio_get __NR_ioprio_get
-#define SYS_ioprio_set __NR_ioprio_set
-#define SYS_ipc __NR_ipc
-#define SYS_kcmp __NR_kcmp
-#define SYS_kexec_load __NR_kexec_load
-#define SYS_keyctl __NR_keyctl
-#define SYS_kill __NR_kill
-#define SYS_lchown __NR_lchown
-#define SYS_lchown32 __NR_lchown32
-#define SYS_lgetxattr __NR_lgetxattr
-#define SYS_link __NR_link
-#define SYS_linkat __NR_linkat
-#define SYS_listen __NR_listen
-#define SYS_listxattr __NR_listxattr
-#define SYS_llistxattr __NR_llistxattr
-#define SYS_lookup_dcookie __NR_lookup_dcookie
-#define SYS_lremovexattr __NR_lremovexattr
-#define SYS_lseek __NR_lseek
-#define SYS_lsetxattr __NR_lsetxattr
-#define SYS_lstat __NR_lstat
-#define SYS_lstat64 __NR_lstat64
-#define SYS_madvise __NR_madvise
-#define SYS_mbind __NR_mbind
-#define SYS_membarrier __NR_membarrier
-#define SYS_memfd_create __NR_memfd_create
-#define SYS_mincore __NR_mincore
-#define SYS_mkdir __NR_mkdir
-#define SYS_mkdirat __NR_mkdirat
-#define SYS_mknod __NR_mknod
-#define SYS_mknodat __NR_mknodat
-#define SYS_mlock __NR_mlock
-#define SYS_mlock2 __NR_mlock2
-#define SYS_mlockall __NR_mlockall
-#define SYS_mmap __NR_mmap
-#define SYS_mmap2 __NR_mmap2
-#define SYS_mount __NR_mount
-#define SYS_move_pages __NR_move_pages
-#define SYS_mprotect __NR_mprotect
-#define SYS_mq_getsetattr __NR_mq_getsetattr
-#define SYS_mq_notify __NR_mq_notify
-#define SYS_mq_open __NR_mq_open
-#define SYS_mq_timedreceive __NR_mq_timedreceive
-#define SYS_mq_timedsend __NR_mq_timedsend
-#define SYS_mq_unlink __NR_mq_unlink
-#define SYS_mremap __NR_mremap
-#define SYS_msgctl __NR_msgctl
-#define SYS_msgget __NR_msgget
-#define SYS_msgrcv __NR_msgrcv
-#define SYS_msgsnd __NR_msgsnd
-#define SYS_msync __NR_msync
-#define SYS_munlock __NR_munlock
-#define SYS_munlockall __NR_munlockall
-#define SYS_munmap __NR_munmap
-#define SYS_name_to_handle_at __NR_name_to_handle_at
-#define SYS_nanosleep __NR_nanosleep
-#define SYS_nfsservctl __NR_nfsservctl
-#define SYS_nice __NR_nice
-#define SYS_open __NR_open
-#define SYS_open_by_handle_at __NR_open_by_handle_at
-#define SYS_openat __NR_openat
-#define SYS_pause __NR_pause
-#define SYS_pciconfig_iobase __NR_pciconfig_iobase
-#define SYS_pciconfig_read __NR_pciconfig_read
-#define SYS_pciconfig_write __NR_pciconfig_write
-#define SYS_perf_event_open __NR_perf_event_open
-#define SYS_personality __NR_personality
-#define SYS_pipe __NR_pipe
-#define SYS_pipe2 __NR_pipe2
-#define SYS_pivot_root __NR_pivot_root
-#define SYS_poll __NR_poll
-#define SYS_ppoll __NR_ppoll
-#define SYS_prctl __NR_prctl
-#define SYS_pread64 __NR_pread64
-#define SYS_preadv __NR_preadv
-#define SYS_prlimit64 __NR_prlimit64
-#define SYS_process_vm_readv __NR_process_vm_readv
-#define SYS_process_vm_writev __NR_process_vm_writev
-#define SYS_pselect6 __NR_pselect6
-#define SYS_ptrace __NR_ptrace
-#define SYS_pwrite64 __NR_pwrite64
-#define SYS_pwritev __NR_pwritev
-#define SYS_quotactl __NR_quotactl
-#define SYS_read __NR_read
-#define SYS_readahead __NR_readahead
-#define SYS_readdir __NR_readdir
-#define SYS_readlink __NR_readlink
-#define SYS_readlinkat __NR_readlinkat
-#define SYS_readv __NR_readv
-#define SYS_reboot __NR_reboot
-#define SYS_recv __NR_recv
-#define SYS_recvfrom __NR_recvfrom
-#define SYS_recvmmsg __NR_recvmmsg
-#define SYS_recvmsg __NR_recvmsg
-#define SYS_remap_file_pages __NR_remap_file_pages
-#define SYS_removexattr __NR_removexattr
-#define SYS_rename __NR_rename
-#define SYS_renameat __NR_renameat
-#define SYS_renameat2 __NR_renameat2
-#define SYS_request_key __NR_request_key
-#define SYS_restart_syscall __NR_restart_syscall
-#define SYS_rmdir __NR_rmdir
-#define SYS_rt_sigaction __NR_rt_sigaction
-#define SYS_rt_sigpending __NR_rt_sigpending
-#define SYS_rt_sigprocmask __NR_rt_sigprocmask
-#define SYS_rt_sigqueueinfo __NR_rt_sigqueueinfo
-#define SYS_rt_sigreturn __NR_rt_sigreturn
-#define SYS_rt_sigsuspend __NR_rt_sigsuspend
-#define SYS_rt_sigtimedwait __NR_rt_sigtimedwait
-#define SYS_rt_tgsigqueueinfo __NR_rt_tgsigqueueinfo
-#define SYS_sched_get_priority_max __NR_sched_get_priority_max
-#define SYS_sched_get_priority_min __NR_sched_get_priority_min
-#define SYS_sched_getaffinity __NR_sched_getaffinity
-#define SYS_sched_getattr __NR_sched_getattr
-#define SYS_sched_getparam __NR_sched_getparam
-#define SYS_sched_getscheduler __NR_sched_getscheduler
-#define SYS_sched_rr_get_interval __NR_sched_rr_get_interval
-#define SYS_sched_setaffinity __NR_sched_setaffinity
-#define SYS_sched_setattr __NR_sched_setattr
-#define SYS_sched_setparam __NR_sched_setparam
-#define SYS_sched_setscheduler __NR_sched_setscheduler
-#define SYS_sched_yield __NR_sched_yield
-#define SYS_seccomp __NR_seccomp
-#define SYS_select __NR_select
-#define SYS_semctl __NR_semctl
-#define SYS_semget __NR_semget
-#define SYS_semop __NR_semop
-#define SYS_semtimedop __NR_semtimedop
-#define SYS_send __NR_send
-#define SYS_sendfile __NR_sendfile
-#define SYS_sendfile64 __NR_sendfile64
-#define SYS_sendmmsg __NR_sendmmsg
-#define SYS_sendmsg __NR_sendmsg
-#define SYS_sendto __NR_sendto
-#define SYS_set_mempolicy __NR_set_mempolicy
-#define SYS_set_robust_list __NR_set_robust_list
-#define SYS_set_tid_address __NR_set_tid_address
-#define SYS_setdomainname __NR_setdomainname
-#define SYS_setfsgid __NR_setfsgid
-#define SYS_setfsgid32 __NR_setfsgid32
-#define SYS_setfsuid __NR_setfsuid
-#define SYS_setfsuid32 __NR_setfsuid32
-#define SYS_setgid __NR_setgid
-#define SYS_setgid32 __NR_setgid32
-#define SYS_setgroups __NR_setgroups
-#define SYS_setgroups32 __NR_setgroups32
-#define SYS_sethostname __NR_sethostname
-#define SYS_setitimer __NR_setitimer
-#define SYS_setns __NR_setns
-#define SYS_setpgid __NR_setpgid
-#define SYS_setpriority __NR_setpriority
-#define SYS_setregid __NR_setregid
-#define SYS_setregid32 __NR_setregid32
-#define SYS_setresgid __NR_setresgid
-#define SYS_setresgid32 __NR_setresgid32
-#define SYS_setresuid __NR_setresuid
-#define SYS_setresuid32 __NR_setresuid32
-#define SYS_setreuid __NR_setreuid
-#define SYS_setreuid32 __NR_setreuid32
-#define SYS_setrlimit __NR_setrlimit
-#define SYS_setsid __NR_setsid
-#define SYS_setsockopt __NR_setsockopt
-#define SYS_settimeofday __NR_settimeofday
-#define SYS_setuid __NR_setuid
-#define SYS_setuid32 __NR_setuid32
-#define SYS_setxattr __NR_setxattr
-#define SYS_shmat __NR_shmat
-#define SYS_shmctl __NR_shmctl
-#define SYS_shmdt __NR_shmdt
-#define SYS_shmget __NR_shmget
-#define SYS_shutdown __NR_shutdown
-#define SYS_sigaction __NR_sigaction
-#define SYS_sigaltstack __NR_sigaltstack
-#define SYS_signalfd __NR_signalfd
-#define SYS_signalfd4 __NR_signalfd4
-#define SYS_sigpending __NR_sigpending
-#define SYS_sigprocmask __NR_sigprocmask
-#define SYS_sigreturn __NR_sigreturn
-#define SYS_sigsuspend __NR_sigsuspend
-#define SYS_socket __NR_socket
-#define SYS_socketcall __NR_socketcall
-#define SYS_socketpair __NR_socketpair
-#define SYS_splice __NR_splice
-#define SYS_stat __NR_stat
-#define SYS_stat64 __NR_stat64
-#define SYS_statfs __NR_statfs
-#define SYS_statfs64 __NR_statfs64
-#define SYS_stime __NR_stime
-#define SYS_swapoff __NR_swapoff
-#define SYS_swapon __NR_swapon
-#define SYS_symlink __NR_symlink
-#define SYS_symlinkat __NR_symlinkat
-#define SYS_sync __NR_sync
-#define SYS_sync_file_range2 __NR_sync_file_range2
-#define SYS_syncfs __NR_syncfs
-#define SYS_syscall __NR_syscall
-#define SYS_sysfs __NR_sysfs
-#define SYS_sysinfo __NR_sysinfo
-#define SYS_syslog __NR_syslog
-#define SYS_tee __NR_tee
-#define SYS_tgkill __NR_tgkill
-#define SYS_time __NR_time
-#define SYS_timer_create __NR_timer_create
-#define SYS_timer_delete __NR_timer_delete
-#define SYS_timer_getoverrun __NR_timer_getoverrun
-#define SYS_timer_gettime __NR_timer_gettime
-#define SYS_timer_settime __NR_timer_settime
-#define SYS_timerfd_create __NR_timerfd_create
-#define SYS_timerfd_gettime __NR_timerfd_gettime
-#define SYS_timerfd_settime __NR_timerfd_settime
-#define SYS_times __NR_times
-#define SYS_tkill __NR_tkill
-#define SYS_truncate __NR_truncate
-#define SYS_truncate64 __NR_truncate64
-#define SYS_ugetrlimit __NR_ugetrlimit
-#define SYS_umask __NR_umask
-#define SYS_umount __NR_umount
-#define SYS_umount2 __NR_umount2
-#define SYS_uname __NR_uname
-#define SYS_unlink __NR_unlink
-#define SYS_unlinkat __NR_unlinkat
-#define SYS_unshare __NR_unshare
-#define SYS_uselib __NR_uselib
-#define SYS_userfaultfd __NR_userfaultfd
-#define SYS_ustat __NR_ustat
-#define SYS_utime __NR_utime
-#define SYS_utimensat __NR_utimensat
-#define SYS_utimes __NR_utimes
-#define SYS_vfork __NR_vfork
-#define SYS_vhangup __NR_vhangup
-#define SYS_vmsplice __NR_vmsplice
-#define SYS_vserver __NR_vserver
-#define SYS_wait4 __NR_wait4
-#define SYS_waitid __NR_waitid
-#define SYS_write __NR_write
-#define SYS_writev __NR_writev
-#elif defined(__mips__)
-#define SYS_accept __NR_accept
-#define SYS_accept4 __NR_accept4
-#define SYS_access __NR_access
-#define SYS_acct __NR_acct
-#define SYS_add_key __NR_add_key
-#define SYS_adjtimex __NR_adjtimex
-#define SYS_afs_syscall __NR_afs_syscall
-#define SYS_alarm __NR_alarm
-#define SYS_bdflush __NR_bdflush
-#define SYS_bind __NR_bind
-#define SYS_bpf __NR_bpf
-#define SYS_break __NR_break
-#define SYS_brk __NR_brk
-#define SYS_cachectl __NR_cachectl
-#define SYS_cacheflush __NR_cacheflush
-#define SYS_capget __NR_capget
-#define SYS_capset __NR_capset
-#define SYS_chdir __NR_chdir
-#define SYS_chmod __NR_chmod
-#define SYS_chown __NR_chown
-#define SYS_chroot __NR_chroot
-#define SYS_clock_adjtime __NR_clock_adjtime
-#define SYS_clock_getres __NR_clock_getres
-#define SYS_clock_gettime __NR_clock_gettime
-#define SYS_clock_nanosleep __NR_clock_nanosleep
-#define SYS_clock_settime __NR_clock_settime
-#define SYS_clone __NR_clone
-#define SYS_close __NR_close
-#define SYS_connect __NR_connect
-#define SYS_creat __NR_creat
-#define SYS_create_module __NR_create_module
-#define SYS_delete_module __NR_delete_module
-#define SYS_dup __NR_dup
-#define SYS_dup2 __NR_dup2
-#define SYS_dup3 __NR_dup3
-#define SYS_epoll_create __NR_epoll_create
-#define SYS_epoll_create1 __NR_epoll_create1
-#define SYS_epoll_ctl __NR_epoll_ctl
-#define SYS_epoll_pwait __NR_epoll_pwait
-#define SYS_epoll_wait __NR_epoll_wait
-#define SYS_eventfd __NR_eventfd
-#define SYS_eventfd2 __NR_eventfd2
-#define SYS_execve __NR_execve
-#define SYS_execveat __NR_execveat
-#define SYS_exit __NR_exit
-#define SYS_exit_group __NR_exit_group
-#define SYS_faccessat __NR_faccessat
-#define SYS_fadvise64 __NR_fadvise64
-#define SYS_fallocate __NR_fallocate
-#define SYS_fanotify_init __NR_fanotify_init
-#define SYS_fanotify_mark __NR_fanotify_mark
-#define SYS_fchdir __NR_fchdir
-#define SYS_fchmod __NR_fchmod
-#define SYS_fchmodat __NR_fchmodat
-#define SYS_fchown __NR_fchown
-#define SYS_fchownat __NR_fchownat
-#define SYS_fcntl __NR_fcntl
-#define SYS_fcntl64 __NR_fcntl64
-#define SYS_fdatasync __NR_fdatasync
-#define SYS_fgetxattr __NR_fgetxattr
-#define SYS_finit_module __NR_finit_module
-#define SYS_flistxattr __NR_flistxattr
-#define SYS_flock __NR_flock
-#define SYS_fork __NR_fork
-#define SYS_fremovexattr __NR_fremovexattr
-#define SYS_fsetxattr __NR_fsetxattr
-#define SYS_fstat __NR_fstat
-#define SYS_fstat64 __NR_fstat64
-#define SYS_fstatat64 __NR_fstatat64
-#define SYS_fstatfs __NR_fstatfs
-#define SYS_fstatfs64 __NR_fstatfs64
-#define SYS_fsync __NR_fsync
-#define SYS_ftime __NR_ftime
-#define SYS_ftruncate __NR_ftruncate
-#define SYS_ftruncate64 __NR_ftruncate64
-#define SYS_futex __NR_futex
-#define SYS_futimesat __NR_futimesat
-#define SYS_get_kernel_syms __NR_get_kernel_syms
-#define SYS_get_mempolicy __NR_get_mempolicy
-#define SYS_get_robust_list __NR_get_robust_list
-#define SYS_getcpu __NR_getcpu
-#define SYS_getcwd __NR_getcwd
-#define SYS_getdents __NR_getdents
-#define SYS_getdents64 __NR_getdents64
-#define SYS_getegid __NR_getegid
-#define SYS_geteuid __NR_geteuid
-#define SYS_getgid __NR_getgid
-#define SYS_getgroups __NR_getgroups
-#define SYS_getitimer __NR_getitimer
-#define SYS_getpeername __NR_getpeername
-#define SYS_getpgid __NR_getpgid
-#define SYS_getpgrp __NR_getpgrp
-#define SYS_getpid __NR_getpid
-#define SYS_getpmsg __NR_getpmsg
-#define SYS_getppid __NR_getppid
-#define SYS_getpriority __NR_getpriority
-#define SYS_getrandom __NR_getrandom
-#define SYS_getresgid __NR_getresgid
-#define SYS_getresuid __NR_getresuid
-#define SYS_getrlimit __NR_getrlimit
-#define SYS_getrusage __NR_getrusage
-#define SYS_getsid __NR_getsid
-#define SYS_getsockname __NR_getsockname
-#define SYS_getsockopt __NR_getsockopt
-#define SYS_gettid __NR_gettid
-#define SYS_gettimeofday __NR_gettimeofday
-#define SYS_getuid __NR_getuid
-#define SYS_getxattr __NR_getxattr
-#define SYS_gtty __NR_gtty
-#define SYS_idle __NR_idle
-#define SYS_init_module __NR_init_module
-#define SYS_inotify_add_watch __NR_inotify_add_watch
-#define SYS_inotify_init __NR_inotify_init
-#define SYS_inotify_init1 __NR_inotify_init1
-#define SYS_inotify_rm_watch __NR_inotify_rm_watch
-#define SYS_io_cancel __NR_io_cancel
-#define SYS_io_destroy __NR_io_destroy
-#define SYS_io_getevents __NR_io_getevents
-#define SYS_io_setup __NR_io_setup
-#define SYS_io_submit __NR_io_submit
-#define SYS_ioctl __NR_ioctl
-#define SYS_ioperm __NR_ioperm
-#define SYS_iopl __NR_iopl
-#define SYS_ioprio_get __NR_ioprio_get
-#define SYS_ioprio_set __NR_ioprio_set
-#define SYS_ipc __NR_ipc
-#define SYS_kcmp __NR_kcmp
-#define SYS_kexec_load __NR_kexec_load
-#define SYS_keyctl __NR_keyctl
-#define SYS_kill __NR_kill
-#define SYS_lchown __NR_lchown
-#define SYS_lgetxattr __NR_lgetxattr
-#define SYS_link __NR_link
-#define SYS_linkat __NR_linkat
-#define SYS_listen __NR_listen
-#define SYS_listxattr __NR_listxattr
-#define SYS_llistxattr __NR_llistxattr
-#define SYS_lock __NR_lock
-#define SYS_lookup_dcookie __NR_lookup_dcookie
-#define SYS_lremovexattr __NR_lremovexattr
-#define SYS_lseek __NR_lseek
-#define SYS_lsetxattr __NR_lsetxattr
-#define SYS_lstat __NR_lstat
-#define SYS_lstat64 __NR_lstat64
-#define SYS_madvise __NR_madvise
-#define SYS_mbind __NR_mbind
-#define SYS_membarrier __NR_membarrier
-#define SYS_memfd_create __NR_memfd_create
-#define SYS_migrate_pages __NR_migrate_pages
-#define SYS_mincore __NR_mincore
-#define SYS_mkdir __NR_mkdir
-#define SYS_mkdirat __NR_mkdirat
-#define SYS_mknod __NR_mknod
-#define SYS_mknodat __NR_mknodat
-#define SYS_mlock __NR_mlock
-#define SYS_mlock2 __NR_mlock2
-#define SYS_mlockall __NR_mlockall
-#define SYS_mmap __NR_mmap
-#define SYS_mmap2 __NR_mmap2
-#define SYS_modify_ldt __NR_modify_ldt
-#define SYS_mount __NR_mount
-#define SYS_move_pages __NR_move_pages
-#define SYS_mprotect __NR_mprotect
-#define SYS_mpx __NR_mpx
-#define SYS_mq_getsetattr __NR_mq_getsetattr
-#define SYS_mq_notify __NR_mq_notify
-#define SYS_mq_open __NR_mq_open
-#define SYS_mq_timedreceive __NR_mq_timedreceive
-#define SYS_mq_timedsend __NR_mq_timedsend
-#define SYS_mq_unlink __NR_mq_unlink
-#define SYS_mremap __NR_mremap
-#define SYS_msgctl __NR_msgctl
-#define SYS_msgget __NR_msgget
-#define SYS_msgrcv __NR_msgrcv
-#define SYS_msgsnd __NR_msgsnd
-#define SYS_msync __NR_msync
-#define SYS_munlock __NR_munlock
-#define SYS_munlockall __NR_munlockall
-#define SYS_munmap __NR_munmap
-#define SYS_name_to_handle_at __NR_name_to_handle_at
-#define SYS_nanosleep __NR_nanosleep
-#define SYS_newfstatat __NR_newfstatat
-#define SYS_nfsservctl __NR_nfsservctl
-#define SYS_nice __NR_nice
-#define SYS_open __NR_open
-#define SYS_open_by_handle_at __NR_open_by_handle_at
-#define SYS_openat __NR_openat
-#define SYS_pause __NR_pause
-#define SYS_perf_event_open __NR_perf_event_open
-#define SYS_personality __NR_personality
-#define SYS_pipe __NR_pipe
-#define SYS_pipe2 __NR_pipe2
-#define SYS_pivot_root __NR_pivot_root
-#define SYS_poll __NR_poll
-#define SYS_ppoll __NR_ppoll
-#define SYS_prctl __NR_prctl
-#define SYS_pread64 __NR_pread64
-#define SYS_preadv __NR_preadv
-#define SYS_prlimit64 __NR_prlimit64
-#define SYS_process_vm_readv __NR_process_vm_readv
-#define SYS_process_vm_writev __NR_process_vm_writev
-#define SYS_prof __NR_prof
-#define SYS_profil __NR_profil
-#define SYS_pselect6 __NR_pselect6
-#define SYS_ptrace __NR_ptrace
-#define SYS_putpmsg __NR_putpmsg
-#define SYS_pwrite64 __NR_pwrite64
-#define SYS_pwritev __NR_pwritev
-#define SYS_query_module __NR_query_module
-#define SYS_quotactl __NR_quotactl
-#define SYS_read __NR_read
-#define SYS_readahead __NR_readahead
-#define SYS_readdir __NR_readdir
-#define SYS_readlink __NR_readlink
-#define SYS_readlinkat __NR_readlinkat
-#define SYS_readv __NR_readv
-#define SYS_reboot __NR_reboot
-#define SYS_recv __NR_recv
-#define SYS_recvfrom __NR_recvfrom
-#define SYS_recvmmsg __NR_recvmmsg
-#define SYS_recvmsg __NR_recvmsg
-#define SYS_remap_file_pages __NR_remap_file_pages
-#define SYS_removexattr __NR_removexattr
-#define SYS_rename __NR_rename
-#define SYS_renameat __NR_renameat
-#define SYS_renameat2 __NR_renameat2
-#define SYS_request_key __NR_request_key
-#define SYS_reserved177 __NR_reserved177
-#define SYS_reserved193 __NR_reserved193
-#define SYS_reserved221 __NR_reserved221
-#define SYS_reserved82 __NR_reserved82
-#define SYS_restart_syscall __NR_restart_syscall
-#define SYS_rmdir __NR_rmdir
-#define SYS_rt_sigaction __NR_rt_sigaction
-#define SYS_rt_sigpending __NR_rt_sigpending
-#define SYS_rt_sigprocmask __NR_rt_sigprocmask
-#define SYS_rt_sigqueueinfo __NR_rt_sigqueueinfo
-#define SYS_rt_sigreturn __NR_rt_sigreturn
-#define SYS_rt_sigsuspend __NR_rt_sigsuspend
-#define SYS_rt_sigtimedwait __NR_rt_sigtimedwait
-#define SYS_rt_tgsigqueueinfo __NR_rt_tgsigqueueinfo
-#define SYS_sched_get_priority_max __NR_sched_get_priority_max
-#define SYS_sched_get_priority_min __NR_sched_get_priority_min
-#define SYS_sched_getaffinity __NR_sched_getaffinity
-#define SYS_sched_getattr __NR_sched_getattr
-#define SYS_sched_getparam __NR_sched_getparam
-#define SYS_sched_getscheduler __NR_sched_getscheduler
-#define SYS_sched_rr_get_interval __NR_sched_rr_get_interval
-#define SYS_sched_setaffinity __NR_sched_setaffinity
-#define SYS_sched_setattr __NR_sched_setattr
-#define SYS_sched_setparam __NR_sched_setparam
-#define SYS_sched_setscheduler __NR_sched_setscheduler
-#define SYS_sched_yield __NR_sched_yield
-#define SYS_seccomp __NR_seccomp
-#define SYS_semctl __NR_semctl
-#define SYS_semget __NR_semget
-#define SYS_semop __NR_semop
-#define SYS_semtimedop __NR_semtimedop
-#define SYS_send __NR_send
-#define SYS_sendfile __NR_sendfile
-#define SYS_sendfile64 __NR_sendfile64
-#define SYS_sendmmsg __NR_sendmmsg
-#define SYS_sendmsg __NR_sendmsg
-#define SYS_sendto __NR_sendto
-#define SYS_set_mempolicy __NR_set_mempolicy
-#define SYS_set_robust_list __NR_set_robust_list
-#define SYS_set_thread_area __NR_set_thread_area
-#define SYS_set_tid_address __NR_set_tid_address
-#define SYS_setdomainname __NR_setdomainname
-#define SYS_setfsgid __NR_setfsgid
-#define SYS_setfsuid __NR_setfsuid
-#define SYS_setgid __NR_setgid
-#define SYS_setgroups __NR_setgroups
-#define SYS_sethostname __NR_sethostname
-#define SYS_setitimer __NR_setitimer
-#define SYS_setns __NR_setns
-#define SYS_setpgid __NR_setpgid
-#define SYS_setpriority __NR_setpriority
-#define SYS_setregid __NR_setregid
-#define SYS_setresgid __NR_setresgid
-#define SYS_setresuid __NR_setresuid
-#define SYS_setreuid __NR_setreuid
-#define SYS_setrlimit __NR_setrlimit
-#define SYS_setsid __NR_setsid
-#define SYS_setsockopt __NR_setsockopt
-#define SYS_settimeofday __NR_settimeofday
-#define SYS_setuid __NR_setuid
-#define SYS_setxattr __NR_setxattr
-#define SYS_sgetmask __NR_sgetmask
-#define SYS_shmat __NR_shmat
-#define SYS_shmctl __NR_shmctl
-#define SYS_shmdt __NR_shmdt
-#define SYS_shmget __NR_shmget
-#define SYS_shutdown __NR_shutdown
-#define SYS_sigaction __NR_sigaction
-#define SYS_sigaltstack __NR_sigaltstack
-#define SYS_signal __NR_signal
-#define SYS_signalfd __NR_signalfd
-#define SYS_signalfd4 __NR_signalfd4
-#define SYS_sigpending __NR_sigpending
-#define SYS_sigprocmask __NR_sigprocmask
-#define SYS_sigreturn __NR_sigreturn
-#define SYS_sigsuspend __NR_sigsuspend
-#define SYS_socket __NR_socket
-#define SYS_socketcall __NR_socketcall
-#define SYS_socketpair __NR_socketpair
-#define SYS_splice __NR_splice
-#define SYS_ssetmask __NR_ssetmask
-#define SYS_stat __NR_stat
-#define SYS_stat64 __NR_stat64
-#define SYS_statfs __NR_statfs
-#define SYS_statfs64 __NR_statfs64
-#define SYS_stime __NR_stime
-#define SYS_stty __NR_stty
-#define SYS_swapoff __NR_swapoff
-#define SYS_swapon __NR_swapon
-#define SYS_symlink __NR_symlink
-#define SYS_symlinkat __NR_symlinkat
-#define SYS_sync __NR_sync
-#define SYS_sync_file_range __NR_sync_file_range
-#define SYS_syncfs __NR_syncfs
-#define SYS_syscall __NR_syscall
-#define SYS_sysfs __NR_sysfs
-#define SYS_sysinfo __NR_sysinfo
-#define SYS_syslog __NR_syslog
-#define SYS_sysmips __NR_sysmips
-#define SYS_tee __NR_tee
-#define SYS_tgkill __NR_tgkill
-#define SYS_time __NR_time
-#define SYS_timer_create __NR_timer_create
-#define SYS_timer_delete __NR_timer_delete
-#define SYS_timer_getoverrun __NR_timer_getoverrun
-#define SYS_timer_gettime __NR_timer_gettime
-#define SYS_timer_settime __NR_timer_settime
-#define SYS_timerfd __NR_timerfd
-#define SYS_timerfd_create __NR_timerfd_create
-#define SYS_timerfd_gettime __NR_timerfd_gettime
-#define SYS_timerfd_settime __NR_timerfd_settime
-#define SYS_times __NR_times
-#define SYS_tkill __NR_tkill
-#define SYS_truncate __NR_truncate
-#define SYS_truncate64 __NR_truncate64
-#define SYS_ulimit __NR_ulimit
-#define SYS_umask __NR_umask
-#define SYS_umount __NR_umount
-#define SYS_umount2 __NR_umount2
-#define SYS_uname __NR_uname
-#define SYS_unlink __NR_unlink
-#define SYS_unlinkat __NR_unlinkat
-#define SYS_unshare __NR_unshare
-#define SYS_unused109 __NR_unused109
-#define SYS_unused150 __NR_unused150
-#define SYS_unused18 __NR_unused18
-#define SYS_unused28 __NR_unused28
-#define SYS_unused59 __NR_unused59
-#define SYS_unused84 __NR_unused84
-#define SYS_uselib __NR_uselib
-#define SYS_userfaultfd __NR_userfaultfd
-#define SYS_ustat __NR_ustat
-#define SYS_utime __NR_utime
-#define SYS_utimensat __NR_utimensat
-#define SYS_utimes __NR_utimes
-#define SYS_vhangup __NR_vhangup
-#define SYS_vm86 __NR_vm86
-#define SYS_vmsplice __NR_vmsplice
-#define SYS_vserver __NR_vserver
-#define SYS_wait4 __NR_wait4
-#define SYS_waitid __NR_waitid
-#define SYS_waitpid __NR_waitpid
-#define SYS_write __NR_write
-#define SYS_writev __NR_writev
-#elif defined(__i386__)
-#define SYS_accept4 __NR_accept4
-#define SYS_access __NR_access
-#define SYS_acct __NR_acct
-#define SYS_add_key __NR_add_key
-#define SYS_adjtimex __NR_adjtimex
-#define SYS_afs_syscall __NR_afs_syscall
-#define SYS_alarm __NR_alarm
-#define SYS_bdflush __NR_bdflush
-#define SYS_bind __NR_bind
-#define SYS_bpf __NR_bpf
-#define SYS_break __NR_break
-#define SYS_brk __NR_brk
-#define SYS_capget __NR_capget
-#define SYS_capset __NR_capset
-#define SYS_chdir __NR_chdir
-#define SYS_chmod __NR_chmod
-#define SYS_chown __NR_chown
-#define SYS_chown32 __NR_chown32
-#define SYS_chroot __NR_chroot
-#define SYS_clock_adjtime __NR_clock_adjtime
-#define SYS_clock_getres __NR_clock_getres
-#define SYS_clock_gettime __NR_clock_gettime
-#define SYS_clock_nanosleep __NR_clock_nanosleep
-#define SYS_clock_settime __NR_clock_settime
-#define SYS_clone __NR_clone
-#define SYS_close __NR_close
-#define SYS_connect __NR_connect
-#define SYS_creat __NR_creat
-#define SYS_create_module __NR_create_module
-#define SYS_delete_module __NR_delete_module
-#define SYS_dup __NR_dup
-#define SYS_dup2 __NR_dup2
-#define SYS_dup3 __NR_dup3
-#define SYS_epoll_create __NR_epoll_create
-#define SYS_epoll_create1 __NR_epoll_create1
-#define SYS_epoll_ctl __NR_epoll_ctl
-#define SYS_epoll_pwait __NR_epoll_pwait
-#define SYS_epoll_wait __NR_epoll_wait
-#define SYS_eventfd __NR_eventfd
-#define SYS_eventfd2 __NR_eventfd2
-#define SYS_execve __NR_execve
-#define SYS_execveat __NR_execveat
-#define SYS_exit __NR_exit
-#define SYS_exit_group __NR_exit_group
-#define SYS_faccessat __NR_faccessat
-#define SYS_fadvise64 __NR_fadvise64
-#define SYS_fadvise64_64 __NR_fadvise64_64
-#define SYS_fallocate __NR_fallocate
-#define SYS_fanotify_init __NR_fanotify_init
-#define SYS_fanotify_mark __NR_fanotify_mark
-#define SYS_fchdir __NR_fchdir
-#define SYS_fchmod __NR_fchmod
-#define SYS_fchmodat __NR_fchmodat
-#define SYS_fchown __NR_fchown
-#define SYS_fchown32 __NR_fchown32
-#define SYS_fchownat __NR_fchownat
-#define SYS_fcntl __NR_fcntl
-#define SYS_fcntl64 __NR_fcntl64
-#define SYS_fdatasync __NR_fdatasync
-#define SYS_fgetxattr __NR_fgetxattr
-#define SYS_finit_module __NR_finit_module
-#define SYS_flistxattr __NR_flistxattr
-#define SYS_flock __NR_flock
-#define SYS_fork __NR_fork
-#define SYS_fremovexattr __NR_fremovexattr
-#define SYS_fsetxattr __NR_fsetxattr
-#define SYS_fstat __NR_fstat
-#define SYS_fstat64 __NR_fstat64
-#define SYS_fstatat64 __NR_fstatat64
-#define SYS_fstatfs __NR_fstatfs
-#define SYS_fstatfs64 __NR_fstatfs64
-#define SYS_fsync __NR_fsync
-#define SYS_ftime __NR_ftime
-#define SYS_ftruncate __NR_ftruncate
-#define SYS_ftruncate64 __NR_ftruncate64
-#define SYS_futex __NR_futex
-#define SYS_futimesat __NR_futimesat
-#define SYS_get_kernel_syms __NR_get_kernel_syms
-#define SYS_get_mempolicy __NR_get_mempolicy
-#define SYS_get_robust_list __NR_get_robust_list
-#define SYS_get_thread_area __NR_get_thread_area
-#define SYS_getcpu __NR_getcpu
-#define SYS_getcwd __NR_getcwd
-#define SYS_getdents __NR_getdents
-#define SYS_getdents64 __NR_getdents64
-#define SYS_getegid __NR_getegid
-#define SYS_getegid32 __NR_getegid32
-#define SYS_geteuid __NR_geteuid
-#define SYS_geteuid32 __NR_geteuid32
-#define SYS_getgid __NR_getgid
-#define SYS_getgid32 __NR_getgid32
-#define SYS_getgroups __NR_getgroups
-#define SYS_getgroups32 __NR_getgroups32
-#define SYS_getitimer __NR_getitimer
-#define SYS_getpeername __NR_getpeername
-#define SYS_getpgid __NR_getpgid
-#define SYS_getpgrp __NR_getpgrp
-#define SYS_getpid __NR_getpid
-#define SYS_getpmsg __NR_getpmsg
-#define SYS_getppid __NR_getppid
-#define SYS_getpriority __NR_getpriority
-#define SYS_getrandom __NR_getrandom
-#define SYS_getresgid __NR_getresgid
-#define SYS_getresgid32 __NR_getresgid32
-#define SYS_getresuid __NR_getresuid
-#define SYS_getresuid32 __NR_getresuid32
-#define SYS_getrlimit __NR_getrlimit
-#define SYS_getrusage __NR_getrusage
-#define SYS_getsid __NR_getsid
-#define SYS_getsockname __NR_getsockname
-#define SYS_getsockopt __NR_getsockopt
-#define SYS_gettid __NR_gettid
-#define SYS_gettimeofday __NR_gettimeofday
-#define SYS_getuid __NR_getuid
-#define SYS_getuid32 __NR_getuid32
-#define SYS_getxattr __NR_getxattr
-#define SYS_gtty __NR_gtty
-#define SYS_idle __NR_idle
-#define SYS_init_module __NR_init_module
-#define SYS_inotify_add_watch __NR_inotify_add_watch
-#define SYS_inotify_init __NR_inotify_init
-#define SYS_inotify_init1 __NR_inotify_init1
-#define SYS_inotify_rm_watch __NR_inotify_rm_watch
-#define SYS_io_cancel __NR_io_cancel
-#define SYS_io_destroy __NR_io_destroy
-#define SYS_io_getevents __NR_io_getevents
-#define SYS_io_setup __NR_io_setup
-#define SYS_io_submit __NR_io_submit
-#define SYS_ioctl __NR_ioctl
-#define SYS_ioperm __NR_ioperm
-#define SYS_iopl __NR_iopl
-#define SYS_ioprio_get __NR_ioprio_get
-#define SYS_ioprio_set __NR_ioprio_set
-#define SYS_ipc __NR_ipc
-#define SYS_kcmp __NR_kcmp
-#define SYS_kexec_load __NR_kexec_load
-#define SYS_keyctl __NR_keyctl
-#define SYS_kill __NR_kill
-#define SYS_lchown __NR_lchown
-#define SYS_lchown32 __NR_lchown32
-#define SYS_lgetxattr __NR_lgetxattr
-#define SYS_link __NR_link
-#define SYS_linkat __NR_linkat
-#define SYS_listen __NR_listen
-#define SYS_listxattr __NR_listxattr
-#define SYS_llistxattr __NR_llistxattr
-#define SYS_lock __NR_lock
-#define SYS_lookup_dcookie __NR_lookup_dcookie
-#define SYS_lremovexattr __NR_lremovexattr
-#define SYS_lseek __NR_lseek
-#define SYS_lsetxattr __NR_lsetxattr
-#define SYS_lstat __NR_lstat
-#define SYS_lstat64 __NR_lstat64
-#define SYS_madvise __NR_madvise
-#define SYS_mbind __NR_mbind
-#define SYS_membarrier __NR_membarrier
-#define SYS_memfd_create __NR_memfd_create
-#define SYS_migrate_pages __NR_migrate_pages
-#define SYS_mincore __NR_mincore
-#define SYS_mkdir __NR_mkdir
-#define SYS_mkdirat __NR_mkdirat
-#define SYS_mknod __NR_mknod
-#define SYS_mknodat __NR_mknodat
-#define SYS_mlock __NR_mlock
-#define SYS_mlock2 __NR_mlock2
-#define SYS_mlockall __NR_mlockall
-#define SYS_mmap __NR_mmap
-#define SYS_mmap2 __NR_mmap2
-#define SYS_modify_ldt __NR_modify_ldt
-#define SYS_mount __NR_mount
-#define SYS_move_pages __NR_move_pages
-#define SYS_mprotect __NR_mprotect
-#define SYS_mpx __NR_mpx
-#define SYS_mq_getsetattr __NR_mq_getsetattr
-#define SYS_mq_notify __NR_mq_notify
-#define SYS_mq_open __NR_mq_open
-#define SYS_mq_timedreceive __NR_mq_timedreceive
-#define SYS_mq_timedsend __NR_mq_timedsend
-#define SYS_mq_unlink __NR_mq_unlink
-#define SYS_mremap __NR_mremap
-#define SYS_msync __NR_msync
-#define SYS_munlock __NR_munlock
-#define SYS_munlockall __NR_munlockall
-#define SYS_munmap __NR_munmap
-#define SYS_name_to_handle_at __NR_name_to_handle_at
-#define SYS_nanosleep __NR_nanosleep
-#define SYS_nfsservctl __NR_nfsservctl
-#define SYS_nice __NR_nice
-#define SYS_oldfstat __NR_oldfstat
-#define SYS_oldlstat __NR_oldlstat
-#define SYS_oldolduname __NR_oldolduname
-#define SYS_oldstat __NR_oldstat
-#define SYS_olduname __NR_olduname
-#define SYS_open __NR_open
-#define SYS_open_by_handle_at __NR_open_by_handle_at
-#define SYS_openat __NR_openat
-#define SYS_pause __NR_pause
-#define SYS_perf_event_open __NR_perf_event_open
-#define SYS_personality __NR_personality
-#define SYS_pipe __NR_pipe
-#define SYS_pipe2 __NR_pipe2
-#define SYS_pivot_root __NR_pivot_root
-#define SYS_poll __NR_poll
-#define SYS_ppoll __NR_ppoll
-#define SYS_prctl __NR_prctl
-#define SYS_pread64 __NR_pread64
-#define SYS_preadv __NR_preadv
-#define SYS_prlimit64 __NR_prlimit64
-#define SYS_process_vm_readv __NR_process_vm_readv
-#define SYS_process_vm_writev __NR_process_vm_writev
-#define SYS_prof __NR_prof
-#define SYS_profil __NR_profil
-#define SYS_pselect6 __NR_pselect6
-#define SYS_ptrace __NR_ptrace
-#define SYS_putpmsg __NR_putpmsg
-#define SYS_pwrite64 __NR_pwrite64
-#define SYS_pwritev __NR_pwritev
-#define SYS_query_module __NR_query_module
-#define SYS_quotactl __NR_quotactl
-#define SYS_read __NR_read
-#define SYS_readahead __NR_readahead
-#define SYS_readdir __NR_readdir
-#define SYS_readlink __NR_readlink
-#define SYS_readlinkat __NR_readlinkat
-#define SYS_readv __NR_readv
-#define SYS_reboot __NR_reboot
-#define SYS_recvfrom __NR_recvfrom
-#define SYS_recvmmsg __NR_recvmmsg
-#define SYS_recvmsg __NR_recvmsg
-#define SYS_remap_file_pages __NR_remap_file_pages
-#define SYS_removexattr __NR_removexattr
-#define SYS_rename __NR_rename
-#define SYS_renameat __NR_renameat
-#define SYS_renameat2 __NR_renameat2
-#define SYS_request_key __NR_request_key
-#define SYS_restart_syscall __NR_restart_syscall
-#define SYS_rmdir __NR_rmdir
-#define SYS_rt_sigaction __NR_rt_sigaction
-#define SYS_rt_sigpending __NR_rt_sigpending
-#define SYS_rt_sigprocmask __NR_rt_sigprocmask
-#define SYS_rt_sigqueueinfo __NR_rt_sigqueueinfo
-#define SYS_rt_sigreturn __NR_rt_sigreturn
-#define SYS_rt_sigsuspend __NR_rt_sigsuspend
-#define SYS_rt_sigtimedwait __NR_rt_sigtimedwait
-#define SYS_rt_tgsigqueueinfo __NR_rt_tgsigqueueinfo
-#define SYS_sched_get_priority_max __NR_sched_get_priority_max
-#define SYS_sched_get_priority_min __NR_sched_get_priority_min
-#define SYS_sched_getaffinity __NR_sched_getaffinity
-#define SYS_sched_getattr __NR_sched_getattr
-#define SYS_sched_getparam __NR_sched_getparam
-#define SYS_sched_getscheduler __NR_sched_getscheduler
-#define SYS_sched_rr_get_interval __NR_sched_rr_get_interval
-#define SYS_sched_setaffinity __NR_sched_setaffinity
-#define SYS_sched_setattr __NR_sched_setattr
-#define SYS_sched_setparam __NR_sched_setparam
-#define SYS_sched_setscheduler __NR_sched_setscheduler
-#define SYS_sched_yield __NR_sched_yield
-#define SYS_seccomp __NR_seccomp
-#define SYS_select __NR_select
-#define SYS_sendfile __NR_sendfile
-#define SYS_sendfile64 __NR_sendfile64
-#define SYS_sendmmsg __NR_sendmmsg
-#define SYS_sendmsg __NR_sendmsg
-#define SYS_sendto __NR_sendto
-#define SYS_set_mempolicy __NR_set_mempolicy
-#define SYS_set_robust_list __NR_set_robust_list
-#define SYS_set_thread_area __NR_set_thread_area
-#define SYS_set_tid_address __NR_set_tid_address
-#define SYS_setdomainname __NR_setdomainname
-#define SYS_setfsgid __NR_setfsgid
-#define SYS_setfsgid32 __NR_setfsgid32
-#define SYS_setfsuid __NR_setfsuid
-#define SYS_setfsuid32 __NR_setfsuid32
-#define SYS_setgid __NR_setgid
-#define SYS_setgid32 __NR_setgid32
-#define SYS_setgroups __NR_setgroups
-#define SYS_setgroups32 __NR_setgroups32
-#define SYS_sethostname __NR_sethostname
-#define SYS_setitimer __NR_setitimer
-#define SYS_setns __NR_setns
-#define SYS_setpgid __NR_setpgid
-#define SYS_setpriority __NR_setpriority
-#define SYS_setregid __NR_setregid
-#define SYS_setregid32 __NR_setregid32
-#define SYS_setresgid __NR_setresgid
-#define SYS_setresgid32 __NR_setresgid32
-#define SYS_setresuid __NR_setresuid
-#define SYS_setresuid32 __NR_setresuid32
-#define SYS_setreuid __NR_setreuid
-#define SYS_setreuid32 __NR_setreuid32
-#define SYS_setrlimit __NR_setrlimit
-#define SYS_setsid __NR_setsid
-#define SYS_setsockopt __NR_setsockopt
-#define SYS_settimeofday __NR_settimeofday
-#define SYS_setuid __NR_setuid
-#define SYS_setuid32 __NR_setuid32
-#define SYS_setxattr __NR_setxattr
-#define SYS_sgetmask __NR_sgetmask
-#define SYS_shutdown __NR_shutdown
-#define SYS_sigaction __NR_sigaction
-#define SYS_sigaltstack __NR_sigaltstack
-#define SYS_signal __NR_signal
-#define SYS_signalfd __NR_signalfd
-#define SYS_signalfd4 __NR_signalfd4
-#define SYS_sigpending __NR_sigpending
-#define SYS_sigprocmask __NR_sigprocmask
-#define SYS_sigreturn __NR_sigreturn
-#define SYS_sigsuspend __NR_sigsuspend
-#define SYS_socket __NR_socket
-#define SYS_socketcall __NR_socketcall
-#define SYS_socketpair __NR_socketpair
-#define SYS_splice __NR_splice
-#define SYS_ssetmask __NR_ssetmask
-#define SYS_stat __NR_stat
-#define SYS_stat64 __NR_stat64
-#define SYS_statfs __NR_statfs
-#define SYS_statfs64 __NR_statfs64
-#define SYS_stime __NR_stime
-#define SYS_stty __NR_stty
-#define SYS_swapoff __NR_swapoff
-#define SYS_swapon __NR_swapon
-#define SYS_symlink __NR_symlink
-#define SYS_symlinkat __NR_symlinkat
-#define SYS_sync __NR_sync
-#define SYS_sync_file_range __NR_sync_file_range
-#define SYS_syncfs __NR_syncfs
-#define SYS_sysfs __NR_sysfs
-#define SYS_sysinfo __NR_sysinfo
-#define SYS_syslog __NR_syslog
-#define SYS_tee __NR_tee
-#define SYS_tgkill __NR_tgkill
-#define SYS_time __NR_time
-#define SYS_timer_create __NR_timer_create
-#define SYS_timer_delete __NR_timer_delete
-#define SYS_timer_getoverrun __NR_timer_getoverrun
-#define SYS_timer_gettime __NR_timer_gettime
-#define SYS_timer_settime __NR_timer_settime
-#define SYS_timerfd_create __NR_timerfd_create
-#define SYS_timerfd_gettime __NR_timerfd_gettime
-#define SYS_timerfd_settime __NR_timerfd_settime
-#define SYS_times __NR_times
-#define SYS_tkill __NR_tkill
-#define SYS_truncate __NR_truncate
-#define SYS_truncate64 __NR_truncate64
-#define SYS_ugetrlimit __NR_ugetrlimit
-#define SYS_ulimit __NR_ulimit
-#define SYS_umask __NR_umask
-#define SYS_umount __NR_umount
-#define SYS_umount2 __NR_umount2
-#define SYS_uname __NR_uname
-#define SYS_unlink __NR_unlink
-#define SYS_unlinkat __NR_unlinkat
-#define SYS_unshare __NR_unshare
-#define SYS_uselib __NR_uselib
-#define SYS_userfaultfd __NR_userfaultfd
-#define SYS_ustat __NR_ustat
-#define SYS_utime __NR_utime
-#define SYS_utimensat __NR_utimensat
-#define SYS_utimes __NR_utimes
-#define SYS_vfork __NR_vfork
-#define SYS_vhangup __NR_vhangup
-#define SYS_vm86 __NR_vm86
-#define SYS_vm86old __NR_vm86old
-#define SYS_vmsplice __NR_vmsplice
-#define SYS_vserver __NR_vserver
-#define SYS_wait4 __NR_wait4
-#define SYS_waitid __NR_waitid
-#define SYS_waitpid __NR_waitpid
-#define SYS_write __NR_write
-#define SYS_writev __NR_writev
-#elif defined(__x86_64__)
-#define SYS_accept __NR_accept
-#define SYS_accept4 __NR_accept4
-#define SYS_access __NR_access
-#define SYS_acct __NR_acct
-#define SYS_add_key __NR_add_key
-#define SYS_adjtimex __NR_adjtimex
-#define SYS_afs_syscall __NR_afs_syscall
-#define SYS_alarm __NR_alarm
-#define SYS_arch_prctl __NR_arch_prctl
-#define SYS_bind __NR_bind
-#define SYS_bpf __NR_bpf
-#define SYS_brk __NR_brk
-#define SYS_capget __NR_capget
-#define SYS_capset __NR_capset
-#define SYS_chdir __NR_chdir
-#define SYS_chmod __NR_chmod
-#define SYS_chown __NR_chown
-#define SYS_chroot __NR_chroot
-#define SYS_clock_adjtime __NR_clock_adjtime
-#define SYS_clock_getres __NR_clock_getres
-#define SYS_clock_gettime __NR_clock_gettime
-#define SYS_clock_nanosleep __NR_clock_nanosleep
-#define SYS_clock_settime __NR_clock_settime
-#define SYS_clone __NR_clone
-#define SYS_close __NR_close
-#define SYS_connect __NR_connect
-#define SYS_creat __NR_creat
-#define SYS_create_module __NR_create_module
-#define SYS_delete_module __NR_delete_module
-#define SYS_dup __NR_dup
-#define SYS_dup2 __NR_dup2
-#define SYS_dup3 __NR_dup3
-#define SYS_epoll_create __NR_epoll_create
-#define SYS_epoll_create1 __NR_epoll_create1
-#define SYS_epoll_ctl __NR_epoll_ctl
-#define SYS_epoll_ctl_old __NR_epoll_ctl_old
-#define SYS_epoll_pwait __NR_epoll_pwait
-#define SYS_epoll_wait __NR_epoll_wait
-#define SYS_epoll_wait_old __NR_epoll_wait_old
-#define SYS_eventfd __NR_eventfd
-#define SYS_eventfd2 __NR_eventfd2
-#define SYS_execve __NR_execve
-#define SYS_execveat __NR_execveat
-#define SYS_exit __NR_exit
-#define SYS_exit_group __NR_exit_group
-#define SYS_faccessat __NR_faccessat
-#define SYS_fadvise64 __NR_fadvise64
-#define SYS_fallocate __NR_fallocate
-#define SYS_fanotify_init __NR_fanotify_init
-#define SYS_fanotify_mark __NR_fanotify_mark
-#define SYS_fchdir __NR_fchdir
-#define SYS_fchmod __NR_fchmod
-#define SYS_fchmodat __NR_fchmodat
-#define SYS_fchown __NR_fchown
-#define SYS_fchownat __NR_fchownat
-#define SYS_fcntl __NR_fcntl
-#define SYS_fdatasync __NR_fdatasync
-#define SYS_fgetxattr __NR_fgetxattr
-#define SYS_finit_module __NR_finit_module
-#define SYS_flistxattr __NR_flistxattr
-#define SYS_flock __NR_flock
-#define SYS_fork __NR_fork
-#define SYS_fremovexattr __NR_fremovexattr
-#define SYS_fsetxattr __NR_fsetxattr
-#define SYS_fstat __NR_fstat
-#define SYS_fstatfs __NR_fstatfs
-#define SYS_fsync __NR_fsync
-#define SYS_ftruncate __NR_ftruncate
-#define SYS_futex __NR_futex
-#define SYS_futimesat __NR_futimesat
-#define SYS_get_kernel_syms __NR_get_kernel_syms
-#define SYS_get_mempolicy __NR_get_mempolicy
-#define SYS_get_robust_list __NR_get_robust_list
-#define SYS_get_thread_area __NR_get_thread_area
-#define SYS_getcpu __NR_getcpu
-#define SYS_getcwd __NR_getcwd
-#define SYS_getdents __NR_getdents
-#define SYS_getdents64 __NR_getdents64
-#define SYS_getegid __NR_getegid
-#define SYS_geteuid __NR_geteuid
-#define SYS_getgid __NR_getgid
-#define SYS_getgroups __NR_getgroups
-#define SYS_getitimer __NR_getitimer
-#define SYS_getpeername __NR_getpeername
-#define SYS_getpgid __NR_getpgid
-#define SYS_getpgrp __NR_getpgrp
-#define SYS_getpid __NR_getpid
-#define SYS_getpmsg __NR_getpmsg
-#define SYS_getppid __NR_getppid
-#define SYS_getpriority __NR_getpriority
-#define SYS_getrandom __NR_getrandom
-#define SYS_getresgid __NR_getresgid
-#define SYS_getresuid __NR_getresuid
-#define SYS_getrlimit __NR_getrlimit
-#define SYS_getrusage __NR_getrusage
-#define SYS_getsid __NR_getsid
-#define SYS_getsockname __NR_getsockname
-#define SYS_getsockopt __NR_getsockopt
-#define SYS_gettid __NR_gettid
-#define SYS_gettimeofday __NR_gettimeofday
-#define SYS_getuid __NR_getuid
-#define SYS_getxattr __NR_getxattr
-#define SYS_init_module __NR_init_module
-#define SYS_inotify_add_watch __NR_inotify_add_watch
-#define SYS_inotify_init __NR_inotify_init
-#define SYS_inotify_init1 __NR_inotify_init1
-#define SYS_inotify_rm_watch __NR_inotify_rm_watch
-#define SYS_io_cancel __NR_io_cancel
-#define SYS_io_destroy __NR_io_destroy
-#define SYS_io_getevents __NR_io_getevents
-#define SYS_io_setup __NR_io_setup
-#define SYS_io_submit __NR_io_submit
-#define SYS_ioctl __NR_ioctl
-#define SYS_ioperm __NR_ioperm
-#define SYS_iopl __NR_iopl
-#define SYS_ioprio_get __NR_ioprio_get
-#define SYS_ioprio_set __NR_ioprio_set
-#define SYS_kcmp __NR_kcmp
-#define SYS_kexec_file_load __NR_kexec_file_load
-#define SYS_kexec_load __NR_kexec_load
-#define SYS_keyctl __NR_keyctl
-#define SYS_kill __NR_kill
-#define SYS_lchown __NR_lchown
-#define SYS_lgetxattr __NR_lgetxattr
-#define SYS_link __NR_link
-#define SYS_linkat __NR_linkat
-#define SYS_listen __NR_listen
-#define SYS_listxattr __NR_listxattr
-#define SYS_llistxattr __NR_llistxattr
-#define SYS_lookup_dcookie __NR_lookup_dcookie
-#define SYS_lremovexattr __NR_lremovexattr
-#define SYS_lseek __NR_lseek
-#define SYS_lsetxattr __NR_lsetxattr
-#define SYS_lstat __NR_lstat
-#define SYS_madvise __NR_madvise
-#define SYS_mbind __NR_mbind
-#define SYS_membarrier __NR_membarrier
-#define SYS_memfd_create __NR_memfd_create
-#define SYS_migrate_pages __NR_migrate_pages
-#define SYS_mincore __NR_mincore
-#define SYS_mkdir __NR_mkdir
-#define SYS_mkdirat __NR_mkdirat
-#define SYS_mknod __NR_mknod
-#define SYS_mknodat __NR_mknodat
-#define SYS_mlock __NR_mlock
-#define SYS_mlock2 __NR_mlock2
-#define SYS_mlockall __NR_mlockall
-#define SYS_mmap __NR_mmap
-#define SYS_modify_ldt __NR_modify_ldt
-#define SYS_mount __NR_mount
-#define SYS_move_pages __NR_move_pages
-#define SYS_mprotect __NR_mprotect
-#define SYS_mq_getsetattr __NR_mq_getsetattr
-#define SYS_mq_notify __NR_mq_notify
-#define SYS_mq_open __NR_mq_open
-#define SYS_mq_timedreceive __NR_mq_timedreceive
-#define SYS_mq_timedsend __NR_mq_timedsend
-#define SYS_mq_unlink __NR_mq_unlink
-#define SYS_mremap __NR_mremap
-#define SYS_msgctl __NR_msgctl
-#define SYS_msgget __NR_msgget
-#define SYS_msgrcv __NR_msgrcv
-#define SYS_msgsnd __NR_msgsnd
-#define SYS_msync __NR_msync
-#define SYS_munlock __NR_munlock
-#define SYS_munlockall __NR_munlockall
-#define SYS_munmap __NR_munmap
-#define SYS_name_to_handle_at __NR_name_to_handle_at
-#define SYS_nanosleep __NR_nanosleep
-#define SYS_newfstatat __NR_newfstatat
-#define SYS_nfsservctl __NR_nfsservctl
-#define SYS_open __NR_open
-#define SYS_open_by_handle_at __NR_open_by_handle_at
-#define SYS_openat __NR_openat
-#define SYS_pause __NR_pause
-#define SYS_perf_event_open __NR_perf_event_open
-#define SYS_personality __NR_personality
-#define SYS_pipe __NR_pipe
-#define SYS_pipe2 __NR_pipe2
-#define SYS_pivot_root __NR_pivot_root
-#define SYS_poll __NR_poll
-#define SYS_ppoll __NR_ppoll
-#define SYS_prctl __NR_prctl
-#define SYS_pread64 __NR_pread64
-#define SYS_preadv __NR_preadv
-#define SYS_prlimit64 __NR_prlimit64
-#define SYS_process_vm_readv __NR_process_vm_readv
-#define SYS_process_vm_writev __NR_process_vm_writev
-#define SYS_pselect6 __NR_pselect6
-#define SYS_ptrace __NR_ptrace
-#define SYS_putpmsg __NR_putpmsg
-#define SYS_pwrite64 __NR_pwrite64
-#define SYS_pwritev __NR_pwritev
-#define SYS_query_module __NR_query_module
-#define SYS_quotactl __NR_quotactl
-#define SYS_read __NR_read
-#define SYS_readahead __NR_readahead
-#define SYS_readlink __NR_readlink
-#define SYS_readlinkat __NR_readlinkat
-#define SYS_readv __NR_readv
-#define SYS_reboot __NR_reboot
-#define SYS_recvfrom __NR_recvfrom
-#define SYS_recvmmsg __NR_recvmmsg
-#define SYS_recvmsg __NR_recvmsg
-#define SYS_remap_file_pages __NR_remap_file_pages
-#define SYS_removexattr __NR_removexattr
-#define SYS_rename __NR_rename
-#define SYS_renameat __NR_renameat
-#define SYS_renameat2 __NR_renameat2
-#define SYS_request_key __NR_request_key
-#define SYS_restart_syscall __NR_restart_syscall
-#define SYS_rmdir __NR_rmdir
-#define SYS_rt_sigaction __NR_rt_sigaction
-#define SYS_rt_sigpending __NR_rt_sigpending
-#define SYS_rt_sigprocmask __NR_rt_sigprocmask
-#define SYS_rt_sigqueueinfo __NR_rt_sigqueueinfo
-#define SYS_rt_sigreturn __NR_rt_sigreturn
-#define SYS_rt_sigsuspend __NR_rt_sigsuspend
-#define SYS_rt_sigtimedwait __NR_rt_sigtimedwait
-#define SYS_rt_tgsigqueueinfo __NR_rt_tgsigqueueinfo
-#define SYS_sched_get_priority_max __NR_sched_get_priority_max
-#define SYS_sched_get_priority_min __NR_sched_get_priority_min
-#define SYS_sched_getaffinity __NR_sched_getaffinity
-#define SYS_sched_getattr __NR_sched_getattr
-#define SYS_sched_getparam __NR_sched_getparam
-#define SYS_sched_getscheduler __NR_sched_getscheduler
-#define SYS_sched_rr_get_interval __NR_sched_rr_get_interval
-#define SYS_sched_setaffinity __NR_sched_setaffinity
-#define SYS_sched_setattr __NR_sched_setattr
-#define SYS_sched_setparam __NR_sched_setparam
-#define SYS_sched_setscheduler __NR_sched_setscheduler
-#define SYS_sched_yield __NR_sched_yield
-#define SYS_seccomp __NR_seccomp
-#define SYS_security __NR_security
-#define SYS_select __NR_select
-#define SYS_semctl __NR_semctl
-#define SYS_semget __NR_semget
-#define SYS_semop __NR_semop
-#define SYS_semtimedop __NR_semtimedop
-#define SYS_sendfile __NR_sendfile
-#define SYS_sendmmsg __NR_sendmmsg
-#define SYS_sendmsg __NR_sendmsg
-#define SYS_sendto __NR_sendto
-#define SYS_set_mempolicy __NR_set_mempolicy
-#define SYS_set_robust_list __NR_set_robust_list
-#define SYS_set_thread_area __NR_set_thread_area
-#define SYS_set_tid_address __NR_set_tid_address
-#define SYS_setdomainname __NR_setdomainname
-#define SYS_setfsgid __NR_setfsgid
-#define SYS_setfsuid __NR_setfsuid
-#define SYS_setgid __NR_setgid
-#define SYS_setgroups __NR_setgroups
-#define SYS_sethostname __NR_sethostname
-#define SYS_setitimer __NR_setitimer
-#define SYS_setns __NR_setns
-#define SYS_setpgid __NR_setpgid
-#define SYS_setpriority __NR_setpriority
-#define SYS_setregid __NR_setregid
-#define SYS_setresgid __NR_setresgid
-#define SYS_setresuid __NR_setresuid
-#define SYS_setreuid __NR_setreuid
-#define SYS_setrlimit __NR_setrlimit
-#define SYS_setsid __NR_setsid
-#define SYS_setsockopt __NR_setsockopt
-#define SYS_settimeofday __NR_settimeofday
-#define SYS_setuid __NR_setuid
-#define SYS_setxattr __NR_setxattr
-#define SYS_shmat __NR_shmat
-#define SYS_shmctl __NR_shmctl
-#define SYS_shmdt __NR_shmdt
-#define SYS_shmget __NR_shmget
-#define SYS_shutdown __NR_shutdown
-#define SYS_sigaltstack __NR_sigaltstack
-#define SYS_signalfd __NR_signalfd
-#define SYS_signalfd4 __NR_signalfd4
-#define SYS_socket __NR_socket
-#define SYS_socketpair __NR_socketpair
-#define SYS_splice __NR_splice
-#define SYS_stat __NR_stat
-#define SYS_statfs __NR_statfs
-#define SYS_swapoff __NR_swapoff
-#define SYS_swapon __NR_swapon
-#define SYS_symlink __NR_symlink
-#define SYS_symlinkat __NR_symlinkat
-#define SYS_sync __NR_sync
-#define SYS_sync_file_range __NR_sync_file_range
-#define SYS_syncfs __NR_syncfs
-#define SYS_sysfs __NR_sysfs
-#define SYS_sysinfo __NR_sysinfo
-#define SYS_syslog __NR_syslog
-#define SYS_tee __NR_tee
-#define SYS_tgkill __NR_tgkill
-#define SYS_time __NR_time
-#define SYS_timer_create __NR_timer_create
-#define SYS_timer_delete __NR_timer_delete
-#define SYS_timer_getoverrun __NR_timer_getoverrun
-#define SYS_timer_gettime __NR_timer_gettime
-#define SYS_timer_settime __NR_timer_settime
-#define SYS_timerfd_create __NR_timerfd_create
-#define SYS_timerfd_gettime __NR_timerfd_gettime
-#define SYS_timerfd_settime __NR_timerfd_settime
-#define SYS_times __NR_times
-#define SYS_tkill __NR_tkill
-#define SYS_truncate __NR_truncate
-#define SYS_tuxcall __NR_tuxcall
-#define SYS_umask __NR_umask
-#define SYS_umount2 __NR_umount2
-#define SYS_uname __NR_uname
-#define SYS_unlink __NR_unlink
-#define SYS_unlinkat __NR_unlinkat
-#define SYS_unshare __NR_unshare
-#define SYS_uselib __NR_uselib
-#define SYS_userfaultfd __NR_userfaultfd
-#define SYS_ustat __NR_ustat
-#define SYS_utime __NR_utime
-#define SYS_utimensat __NR_utimensat
-#define SYS_utimes __NR_utimes
-#define SYS_vfork __NR_vfork
-#define SYS_vhangup __NR_vhangup
-#define SYS_vmsplice __NR_vmsplice
-#define SYS_vserver __NR_vserver
-#define SYS_wait4 __NR_wait4
-#define SYS_waitid __NR_waitid
-#define SYS_write __NR_write
-#define SYS_writev __NR_writev
-#endif
-#endif /* _BIONIC_GLIBC_SYSCALLS_H_ */
diff --git a/libc/include/sys/inotify.h b/libc/include/sys/inotify.h
index dcdd29a..2e99144 100644
--- a/libc/include/sys/inotify.h
+++ b/libc/include/sys/inotify.h
@@ -40,10 +40,10 @@
 #define IN_CLOEXEC O_CLOEXEC
 #define IN_NONBLOCK O_NONBLOCK
 
-extern int inotify_init(void);
-extern int inotify_init1(int);
-extern int inotify_add_watch(int, const char*, uint32_t);
-extern int inotify_rm_watch(int, uint32_t);
+int inotify_init(void);
+int inotify_init1(int) __INTRODUCED_IN(21);
+int inotify_add_watch(int, const char*, uint32_t);
+int inotify_rm_watch(int, uint32_t);
 
 __END_DECLS
 
diff --git a/libc/include/sys/ioctl.h b/libc/include/sys/ioctl.h
index a1014dc..efbcb0c 100644
--- a/libc/include/sys/ioctl.h
+++ b/libc/include/sys/ioctl.h
@@ -37,13 +37,8 @@
 #include <linux/termios.h>
 #include <asm/ioctls.h>
 #include <asm/termbits.h>
-#include <sys/ioctl_compat.h>
 #include <linux/tty.h>
 
-__BEGIN_DECLS
-
-extern int ioctl(int, int, ...);
-
-__END_DECLS
+#include <bits/ioctl.h>
 
 #endif /* _SYS_IOCTL_H_ */
diff --git a/libc/include/sys/ioctl_compat.h b/libc/include/sys/ioctl_compat.h
deleted file mode 100644
index d9ba4c7..0000000
--- a/libc/include/sys/ioctl_compat.h
+++ /dev/null
@@ -1,174 +0,0 @@
-/*	$NetBSD: ioctl_compat.h,v 1.15 2005/12/03 17:10:46 christos Exp $	*/
-
-/*
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- * (c) UNIX System Laboratories, Inc.
- * All or some portions of this file are derived from material licensed
- * to the University of California by American Telephone and Telegraph
- * Co. or Unix System Laboratories, Inc. and are reproduced herein with
- * the permission of UNIX System Laboratories, Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- *
- *	@(#)ioctl_compat.h	8.4 (Berkeley) 1/21/94
- */
-
-#ifndef _SYS_IOCTL_COMPAT_H_
-#define	_SYS_IOCTL_COMPAT_H_
-
-/*#include <sys/ttychars.h>*/
-/*#include <sys/ttydev.h>*/
-
-#if !defined(__mips__)
-struct tchars {
-	char	t_intrc;	/* interrupt */
-	char	t_quitc;	/* quit */
-	char	t_startc;	/* start output */
-	char	t_stopc;	/* stop output */
-	char	t_eofc;		/* end-of-file */
-	char	t_brkc;		/* input delimiter (like nl) */
-};
-
-struct ltchars {
-	char	t_suspc;	/* stop process signal */
-	char	t_dsuspc;	/* delayed stop process signal */
-	char	t_rprntc;	/* reprint line */
-	char	t_flushc;	/* flush output (toggles) */
-	char	t_werasc;	/* word erase */
-	char	t_lnextc;	/* literal next character */
-};
-
-/*
- * Structure for TIOCGETP and TIOCSETP ioctls.
- */
-#ifndef _SGTTYB_
-#define	_SGTTYB_
-struct sgttyb {
-	char	sg_ispeed;		/* input speed */
-	char	sg_ospeed;		/* output speed */
-	char	sg_erase;		/* erase character */
-	char	sg_kill;		/* kill character */
-	short	sg_flags;		/* mode flags */
-};
-#endif
-#endif
-
-#ifdef USE_OLD_TTY
-# undef  TIOCGETD
-# define TIOCGETD	_IOR('t', 0, int)	/* get line discipline */
-# undef  TIOCSETD
-# define TIOCSETD	_IOW('t', 1, int)	/* set line discipline */
-#else
-# define OTIOCGETD	_IOR('t', 0, int)	/* get line discipline */
-# define OTIOCSETD	_IOW('t', 1, int)	/* set line discipline */
-#endif
-#define	TIOCHPCL	_IO('t', 2)		/* hang up on last close */
-#if !defined(__mips__)
-#define	TIOCGETP	_IOR('t', 8,struct sgttyb)/* get parameters -- gtty */
-#define	TIOCSETP	_IOW('t', 9,struct sgttyb)/* set parameters -- stty */
-#define	TIOCSETN	_IOW('t',10,struct sgttyb)/* as above, but no flushtty*/
-#endif
-#define	TIOCSETC	_IOW('t',17,struct tchars)/* set special characters */
-#define	TIOCGETC	_IOR('t',18,struct tchars)/* get special characters */
-#if 0
-/* BUG: a bunch of these conflict with #defines in asm/termbits.h */
-#define		TANDEM		0x00000001	/* send stopc on out q full */
-#define		CBREAK		0x00000002	/* half-cooked mode */
-#define		LCASE		0x00000004	/* simulate lower case */
-#define		ECHO		0x00000008	/* enable echoing */
-#define		CRMOD		0x00000010	/* map \r to \r\n on output */
-#define		RAW		0x00000020	/* no i/o processing */
-#define		ODDP		0x00000040	/* get/send odd parity */
-#define		EVENP		0x00000080	/* get/send even parity */
-#define		ANYP		0x000000c0	/* get any parity/send none */
-#define		NLDELAY		0x00000300	/* \n delay */
-#define			NL0	0x00000000
-#define			NL1	0x00000100	/* tty 37 */
-#define			NL2	0x00000200	/* vt05 */
-#define			NL3	0x00000300
-#define		TBDELAY		0x00000c00	/* horizontal tab delay */
-#define			TAB0	0x00000000
-#define			TAB1	0x00000400	/* tty 37 */
-#define			TAB2	0x00000800
-#define		XTABS		0x00000c00	/* expand tabs on output */
-#define		CRDELAY		0x00003000	/* \r delay */
-#define			CR0	0x00000000
-#define			CR1	0x00001000	/* tn 300 */
-#define			CR2	0x00002000	/* tty 37 */
-#define			CR3	0x00003000	/* concept 100 */
-#define		VTDELAY		0x00004000	/* vertical tab delay */
-#define			FF0	0x00000000
-#define			FF1	0x00004000	/* tty 37 */
-#define		BSDELAY		0x00008000	/* \b delay */
-#define			BS0	0x00000000
-#define			BS1	0x00008000
-#define		ALLDELAY	(NLDELAY|TBDELAY|CRDELAY|VTDELAY|BSDELAY)
-#define		CRTBS		0x00010000	/* do backspacing for crt */
-#define		PRTERA		0x00020000	/* \ ... / erase */
-#define		CRTERA		0x00040000	/* " \b " to wipe out char */
-#define		TILDE		0x00080000	/* hazeltine tilde kludge */
-#define		MDMBUF		0x00100000	/* DTR/DCD hardware flow control */
-#define		LITOUT		0x00200000	/* literal output */
-#define		TOSTOP		0x00400000	/* stop background jobs on output */
-#define		FLUSHO		0x00800000	/* output being flushed (state) */
-#define		NOHANG		0x01000000	/* (no-op) was no SIGHUP on carrier drop */
-#define		L001000		0x02000000
-#define		CRTKIL		0x04000000	/* kill line with " \b " */
-#define		PASS8		0x08000000
-#define		CTLECH		0x10000000	/* echo control chars as ^X */
-#define		PENDIN		0x20000000	/* re-echo input buffer at next read */
-#define		DECCTQ		0x40000000	/* only ^Q starts after ^S */
-#define		NOFLSH		0x80000000	/* don't flush output on signal */
-#endif
-#define	TIOCLBIS	_IOW('t', 127, int)	/* bis local mode bits */
-#define	TIOCLBIC	_IOW('t', 126, int)	/* bic local mode bits */
-#define	TIOCLSET	_IOW('t', 125, int)	/* set entire local mode word */
-#define	TIOCLGET	_IOR('t', 124, int)	/* get local modes */
-#define		LCRTBS		(CRTBS>>16)
-#define		LPRTERA		(PRTERA>>16)
-#define		LCRTERA		(CRTERA>>16)
-#define		LTILDE		(TILDE>>16)
-#define		LMDMBUF		(MDMBUF>>16)
-#define		LLITOUT		(LITOUT>>16)
-#define		LTOSTOP		(TOSTOP>>16)
-#define		LFLUSHO		(FLUSHO>>16)
-#define		LNOHANG		(NOHANG>>16)
-#define		LCRTKIL		(CRTKIL>>16)
-#define		LPASS8		(PASS8>>16)
-#define		LCTLECH		(CTLECH>>16)
-#define		LPENDIN		(PENDIN>>16)
-#define		LDECCTQ		(DECCTQ>>16)
-#define		LNOFLSH		(NOFLSH>>16)
-#if !defined(__mips__)
-#define	TIOCSLTC	_IOW('t',117,struct ltchars)/* set local special chars*/
-#define	TIOCGLTC	_IOR('t',116,struct ltchars)/* get local special chars*/
-#endif
-#define OTIOCCONS	_IO('t', 98)	/* for hp300 -- sans int arg */
-#define	OTTYDISC	0
-#define	NETLDISC	1
-#define	NTTYDISC	2
-
-#endif /* !_SYS_IOCTL_COMPAT_H_ */
diff --git a/libc/include/sys/ipc.h b/libc/include/sys/ipc.h
index c0ae0ba..99bc5db 100644
--- a/libc/include/sys/ipc.h
+++ b/libc/include/sys/ipc.h
@@ -25,6 +25,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #ifndef _SYS_IPC_H
 #define _SYS_IPC_H
 
@@ -34,7 +35,7 @@
 
 __BEGIN_DECLS
 
-extern key_t  ftok(const char*  path, int  id);
+key_t ftok(const char* path, int id);
 
 __END_DECLS
 
diff --git a/libc/include/sys/klog.h b/libc/include/sys/klog.h
index acfaa20..47eb3a4 100644
--- a/libc/include/sys/klog.h
+++ b/libc/include/sys/klog.h
@@ -46,7 +46,7 @@
 #define KLOG_SIZE_UNREAD   9
 #define KLOG_SIZE_BUFFER   10
 
-extern int klogctl(int, char *, int);
+int klogctl(int, char *, int);
 
 __END_DECLS
 
diff --git a/libc/include/sys/limits.h b/libc/include/sys/limits.h
index be79cf3..5aa3d80 100644
--- a/libc/include/sys/limits.h
+++ b/libc/include/sys/limits.h
@@ -66,16 +66,14 @@
 # define LONG_MIN	(-0x7fffffffL-1)/* min value for a long */
 #endif
 
-#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
 # define ULLONG_MAX	0xffffffffffffffffULL
 					/* max value for unsigned long long */
 # define LLONG_MAX	0x7fffffffffffffffLL
 					/* max value for a signed long long */
 # define LLONG_MIN	(-0x7fffffffffffffffLL-1)
 					/* min value for a signed long long */
-#endif
 
-#if __BSD_VISIBLE
+#if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
 # define UID_MAX	UINT_MAX	/* max value for a uid_t */
 # define GID_MAX	UINT_MAX	/* max value for a gid_t */
 #endif
@@ -120,8 +118,11 @@
 #define  _XOPEN_VERSION             700       /* by Posix definition */
 
 
-#define PTHREAD_DESTRUCTOR_ITERATIONS 4     // >= _POSIX_THREAD_DESTRUCTOR_ITERATIONS
-#define PTHREAD_KEYS_MAX              128   // >= _POSIX_THREAD_KEYS_MAX
-#define PTHREAD_THREADS_MAX           2048  // bionic has no specific limit
+/* >= _POSIX_THREAD_DESTRUCTOR_ITERATIONS */
+#define PTHREAD_DESTRUCTOR_ITERATIONS 4
+/* >= _POSIX_THREAD_KEYS_MAX */
+#define PTHREAD_KEYS_MAX 128
+/* bionic has no specific limit */
+#undef PTHREAD_THREADS_MAX
 
 #endif
diff --git a/libc/include/sys/mman.h b/libc/include/sys/mman.h
index a19ceb5..934963f 100644
--- a/libc/include/sys/mman.h
+++ b/libc/include/sys/mman.h
@@ -38,7 +38,7 @@
 #define MAP_ANON  MAP_ANONYMOUS
 #endif
 
-#define MAP_FAILED ((void *)-1)
+#define MAP_FAILED __BIONIC_CAST(reinterpret_cast, void*, -1)
 
 #define MREMAP_MAYMOVE  1
 #define MREMAP_FIXED    2
@@ -50,29 +50,26 @@
 #define POSIX_MADV_DONTNEED   MADV_DONTNEED
 
 #if defined(__USE_FILE_OFFSET64)
-extern void* mmap(void*, size_t, int, int, int, off_t) __RENAME(mmap64);
+void* mmap(void*, size_t, int, int, int, off_t) __RENAME(mmap64) __INTRODUCED_IN(21);
 #else
-extern void* mmap(void*, size_t, int, int, int, off_t);
+void* mmap(void*, size_t, int, int, int, off_t);
 #endif
-extern void* mmap64(void*, size_t, int, int, int, off64_t);
+void* mmap64(void*, size_t, int, int, int, off64_t) __INTRODUCED_IN(21);
 
-extern int munmap(void*, size_t);
-extern int msync(const void*, size_t, int);
-extern int mprotect(const void*, size_t, int);
-extern void* mremap(void*, size_t, size_t, int, ...);
+int munmap(void*, size_t);
+int msync(const void*, size_t, int);
+int mprotect(const void*, size_t, int);
+void* mremap(void*, size_t, size_t, int, ...);
 
-extern int mlockall(int);
-extern int munlockall(void);
-extern int mlock(const void*, size_t);
-extern int munlock(const void*, size_t);
-extern int madvise(void*, size_t, int);
+int mlockall(int) __INTRODUCED_IN(17);
+int munlockall(void) __INTRODUCED_IN(17);
+int mlock(const void*, size_t);
+int munlock(const void*, size_t);
 
-extern int mlock(const void*, size_t);
-extern int munlock(const void*, size_t);
+int mincore(void*, size_t, unsigned char*);
 
-extern int mincore(void*, size_t, unsigned char*);
-
-extern int posix_madvise(void*, size_t, int);
+int madvise(void*, size_t, int);
+int posix_madvise(void*, size_t, int) __INTRODUCED_IN(23);
 
 __END_DECLS
 
diff --git a/libc/include/sys/mount.h b/libc/include/sys/mount.h
index fd7cf17..26c0e0f 100644
--- a/libc/include/sys/mount.h
+++ b/libc/include/sys/mount.h
@@ -41,9 +41,9 @@
 #define MNT_EXPIRE 4
 #define UMOUNT_NOFOLLOW 8
 
-extern int mount(const char*, const char*, const char*, unsigned long, const void*);
-extern int umount(const char*);
-extern int umount2(const char*, int);
+int mount(const char*, const char*, const char*, unsigned long, const void*);
+int umount(const char*);
+int umount2(const char*, int);
 
 __END_DECLS
 
diff --git a/libc/include/sys/msg.h b/libc/include/sys/msg.h
index 1a6d30d..73965f2 100644
--- a/libc/include/sys/msg.h
+++ b/libc/include/sys/msg.h
@@ -29,6 +29,7 @@
 #ifndef _SYS_MSG_H_
 #define _SYS_MSG_H_
 
+#include <sys/cdefs.h>
 #include <linux/msg.h>
 
 #endif /* _SYS_MSG_H_ */
diff --git a/libc/include/sys/param.h b/libc/include/sys/param.h
index e64d6ce..d3686e0 100644
--- a/libc/include/sys/param.h
+++ b/libc/include/sys/param.h
@@ -25,11 +25,15 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #ifndef _SYS_PARAM_H_
 #define _SYS_PARAM_H_
 
 #include <limits.h>
 #include <linux/param.h>
+#include <sys/cdefs.h>
+
+#define DEV_BSIZE 512
 
 #define MAXPATHLEN  PATH_MAX
 #define MAXSYMLINKS 8
diff --git a/libc/include/sys/personality.h b/libc/include/sys/personality.h
index 7764468..6f3a3c9 100644
--- a/libc/include/sys/personality.h
+++ b/libc/include/sys/personality.h
@@ -34,7 +34,7 @@
 
 __BEGIN_DECLS
 
-extern int personality (unsigned int persona);
+int personality(unsigned int persona) __INTRODUCED_IN(15);
 
 __END_DECLS
 
diff --git a/libc/include/sys/prctl.h b/libc/include/sys/prctl.h
index d96b8b6..742ed57 100644
--- a/libc/include/sys/prctl.h
+++ b/libc/include/sys/prctl.h
@@ -35,7 +35,7 @@
 
 __BEGIN_DECLS
 
-extern int prctl(int option, ...);
+int prctl(int option, ...);
 
 __END_DECLS
 
diff --git a/libc/include/sys/queue.h b/libc/include/sys/queue.h
index b0e6b38..0890838 100644
--- a/libc/include/sys/queue.h
+++ b/libc/include/sys/queue.h
@@ -32,6 +32,8 @@
 #ifndef	_SYS_QUEUE_H_
 #define	_SYS_QUEUE_H_
 
+#include <sys/cdefs.h>
+
 /*
  * This file defines five types of data structures: singly-linked lists,
  * lists, simple queues, tail queues, and circular queues.
diff --git a/libc/include/sys/utime.h b/libc/include/sys/quota.h
similarity index 77%
copy from libc/include/sys/utime.h
copy to libc/include/sys/quota.h
index 9f8810e..08ca982 100644
--- a/libc/include/sys/utime.h
+++ b/libc/include/sys/quota.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) 2016 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -25,9 +25,23 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-#ifndef _SYS_UTIME_H_
-#define _SYS_UTIME_H_
 
-#include <linux/utime.h>
+#ifndef _SYS_QUOTA_H_
+#define _SYS_QUOTA_H_
 
-#endif /* _SYS_UTIME_H_ */
+#include <sys/cdefs.h>
+
+// The uapi header uses different names from userspace, oddly.
+#define if_dqblk dqblk
+#define if_dqinfo dqinfo
+#include <linux/quota.h>
+#undef if_dqblk
+#undef if_dqinfo
+
+__BEGIN_DECLS
+
+int quotactl(int, const char*, int, char*) __INTRODUCED_IN_FUTURE;
+
+__END_DECLS
+
+#endif
diff --git a/libc/include/sys/reboot.h b/libc/include/sys/reboot.h
index 7d202f7..df4739e 100644
--- a/libc/include/sys/reboot.h
+++ b/libc/include/sys/reboot.h
@@ -25,6 +25,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #ifndef _SYS_REBOOT_H_
 #define _SYS_REBOOT_H_
 
@@ -41,7 +42,7 @@
 #define RB_DISABLE_CAD  LINUX_REBOOT_CMD_CAD_OFF
 #define RB_POWER_OFF    LINUX_REBOOT_CMD_POWER_OFF
 
-extern int reboot(int  reboot_type);
+int reboot(int reboot_type);
 
 __END_DECLS
 
diff --git a/libc/include/sys/reg.h b/libc/include/sys/reg.h
index b3d2aac..1066b6d 100644
--- a/libc/include/sys/reg.h
+++ b/libc/include/sys/reg.h
@@ -29,6 +29,8 @@
 #ifndef _SYS_REG_H_
 #define _SYS_REG_H_
 
+#include <sys/cdefs.h>
+
 #if defined(__i386__)
 
 #define EBX 0
diff --git a/libc/include/sys/resource.h b/libc/include/sys/resource.h
index 8209dfb..248310e 100644
--- a/libc/include/sys/resource.h
+++ b/libc/include/sys/resource.h
@@ -42,19 +42,20 @@
 
 typedef unsigned long rlim_t;
 
-extern int getrlimit(int, struct rlimit*);
-extern int setrlimit(int, const struct rlimit*);
+int getrlimit(int, struct rlimit*);
+int setrlimit(int, const struct rlimit*);
 
-extern int getrlimit64(int, struct rlimit64*);
-extern int setrlimit64(int, const struct rlimit64*);
+int getrlimit64(int, struct rlimit64*) __INTRODUCED_IN(21);
+int setrlimit64(int, const struct rlimit64*) __INTRODUCED_IN(21);
 
-extern int getpriority(int, int);
-extern int setpriority(int, int, int);
+int getpriority(int, int);
+int setpriority(int, int, int);
 
-extern int getrusage(int, struct rusage*);
+int getrusage(int, struct rusage*);
 
-extern int prlimit(pid_t, int, const struct rlimit*, struct rlimit*);
-extern int prlimit64(pid_t, int, const struct rlimit64*, struct rlimit64*);
+int prlimit(pid_t, int, const struct rlimit*, struct rlimit*) __INTRODUCED_IN_32(24)
+  __INTRODUCED_IN_64(21);
+int prlimit64(pid_t, int, const struct rlimit64*, struct rlimit64*) __INTRODUCED_IN(21);
 
 __END_DECLS
 
diff --git a/libc/include/sys/select.h b/libc/include/sys/select.h
index 0c4a823..0f454b0 100644
--- a/libc/include/sys/select.h
+++ b/libc/include/sys/select.h
@@ -46,7 +46,7 @@
 
 #define __FDELT(fd) ((fd) / NFDBITS)
 #define __FDMASK(fd) (1UL << ((fd) % NFDBITS))
-#define __FDS_BITS(set) (((fd_set*)(set))->fds_bits)
+#define __FDS_BITS(set) (__BIONIC_CAST(static_cast, fd_set*, set)->fds_bits)
 
 /* Inline loop so we don't have to declare memset. */
 #define FD_ZERO(set) \
@@ -57,9 +57,9 @@
     } \
   } while (0)
 
-extern void __FD_CLR_chk(int, fd_set*, size_t);
-extern void __FD_SET_chk(int, fd_set*, size_t);
-extern int  __FD_ISSET_chk(int, fd_set*, size_t);
+void __FD_CLR_chk(int, fd_set*, size_t) __INTRODUCED_IN(21);
+void __FD_SET_chk(int, fd_set*, size_t) __INTRODUCED_IN(21);
+int __FD_ISSET_chk(int, fd_set*, size_t) __INTRODUCED_IN(21);
 
 #if defined(__BIONIC_FORTIFY)
 #define FD_CLR(fd, set) __FD_CLR_chk(fd, set, __bos(set))
@@ -71,8 +71,8 @@
 #define FD_ISSET(fd, set) ((__FDS_BITS(set)[__FDELT(fd)] & __FDMASK(fd)) != 0)
 #endif /* defined(__BIONIC_FORTIFY) */
 
-extern int select(int, fd_set*, fd_set*, fd_set*, struct timeval*);
-extern int pselect(int, fd_set*, fd_set*, fd_set*, const struct timespec*, const sigset_t*);
+int select(int, fd_set*, fd_set*, fd_set*, struct timeval*);
+int pselect(int, fd_set*, fd_set*, fd_set*, const struct timespec*, const sigset_t*);
 
 __END_DECLS
 
diff --git a/libc/include/sys/sem.h b/libc/include/sys/sem.h
index a1ecd1f..753fc37 100644
--- a/libc/include/sys/sem.h
+++ b/libc/include/sys/sem.h
@@ -29,6 +29,7 @@
 #ifndef _SYS_SEM_H_
 #define _SYS_SEM_H_
 
+#include <sys/cdefs.h>
 #include <linux/sem.h>
 
 #endif /* _SYS_SEM_H_ */
diff --git a/libc/include/sys/sendfile.h b/libc/include/sys/sendfile.h
index c588e68..3ac8fdf 100644
--- a/libc/include/sys/sendfile.h
+++ b/libc/include/sys/sendfile.h
@@ -35,11 +35,12 @@
 __BEGIN_DECLS
 
 #if defined(__USE_FILE_OFFSET64)
-extern ssize_t sendfile(int out_fd, int in_fd, off_t* offset, size_t count) __RENAME(sendfile64);
+ssize_t sendfile(int out_fd, int in_fd, off_t* offset, size_t count) __RENAME(sendfile64)
+  __INTRODUCED_IN(21);
 #else
-extern ssize_t sendfile(int out_fd, int in_fd, off_t* offset, size_t count);
+ssize_t sendfile(int out_fd, int in_fd, off_t* offset, size_t count);
 #endif
-extern ssize_t sendfile64(int out_fd, int in_fd, off64_t* offset, size_t count);
+ssize_t sendfile64(int out_fd, int in_fd, off64_t* offset, size_t count) __INTRODUCED_IN(21);
 
 __END_DECLS
 
diff --git a/libc/include/sys/signalfd.h b/libc/include/sys/signalfd.h
index 2537ab9..a21c57b 100644
--- a/libc/include/sys/signalfd.h
+++ b/libc/include/sys/signalfd.h
@@ -35,7 +35,7 @@
 
 __BEGIN_DECLS
 
-extern int signalfd(int fd, const sigset_t* mask, int flags) __nonnull((2));
+int signalfd(int fd, const sigset_t* _Nonnull mask, int flags) __INTRODUCED_IN(18);
 
 __END_DECLS
 
diff --git a/libc/include/sys/socket.h b/libc/include/sys/socket.h
index c7e9acc..223c3b2 100644
--- a/libc/include/sys/socket.h
+++ b/libc/include/sys/socket.h
@@ -40,10 +40,11 @@
 #include <linux/types.h>
 #include <linux/compiler.h>
 
+#include <bits/sa_family_t.h>
+
 __BEGIN_DECLS
 
 #define sockaddr_storage __kernel_sockaddr_storage
-typedef unsigned short sa_family_t;
 
 struct timespec;
 
@@ -113,7 +114,7 @@
    ? (struct cmsghdr*) (msg)->msg_control : (struct cmsghdr*) NULL)
 #define CMSG_OK(mhdr, cmsg) ((cmsg)->cmsg_len >= sizeof(struct cmsghdr) &&   (cmsg)->cmsg_len <= (unsigned long)   ((mhdr)->msg_controllen -   ((char*)(cmsg) - (char*)(mhdr)->msg_control)))
 
-struct cmsghdr* __cmsg_nxthdr(struct msghdr*, struct cmsghdr*);
+struct cmsghdr* __cmsg_nxthdr(struct msghdr*, struct cmsghdr*) __INTRODUCED_IN(21);
 
 #define SCM_RIGHTS 0x01
 #define SCM_CREDENTIALS 0x02
@@ -269,34 +270,37 @@
 #endif
 
 __socketcall int accept(int, struct sockaddr*, socklen_t*);
-__socketcall int accept4(int, struct sockaddr*, socklen_t*, int);
+__socketcall int accept4(int, struct sockaddr*, socklen_t*, int) __INTRODUCED_IN(21);
 __socketcall int bind(int, const struct sockaddr*, int);
 __socketcall int connect(int, const struct sockaddr*, socklen_t);
 __socketcall int getpeername(int, struct sockaddr*, socklen_t*);
 __socketcall int getsockname(int, struct sockaddr*, socklen_t*);
 __socketcall int getsockopt(int, int, int, void*, socklen_t*);
 __socketcall int listen(int, int);
-__socketcall int recvmmsg(int, struct mmsghdr*, unsigned int, int, const struct timespec*);
+__socketcall int recvmmsg(int, struct mmsghdr*, unsigned int, int, const struct timespec*)
+  __INTRODUCED_IN(21);
 __socketcall int recvmsg(int, struct msghdr*, int);
-__socketcall int sendmmsg(int, const struct mmsghdr*, unsigned int, int);
+__socketcall int sendmmsg(int, const struct mmsghdr*, unsigned int, int) __INTRODUCED_IN(21);
 __socketcall int sendmsg(int, const struct msghdr*, int);
 __socketcall int setsockopt(int, int, int, const void*, socklen_t);
 __socketcall int shutdown(int, int);
 __socketcall int socket(int, int, int);
 __socketcall int socketpair(int, int, int, int*);
 
-extern ssize_t send(int, const void*, size_t, int);
-extern ssize_t recv(int, void*, size_t, int);
+ssize_t send(int, const void*, size_t, int);
+ssize_t recv(int, void*, size_t, int);
 
 __socketcall ssize_t sendto(int, const void*, size_t, int, const struct sockaddr*, socklen_t);
 __socketcall ssize_t recvfrom(int, void*, size_t, int, const struct sockaddr*, socklen_t*);
 
 __errordecl(__recvfrom_error, "recvfrom called with size bigger than buffer");
-extern ssize_t __recvfrom_chk(int, void*, size_t, size_t, int, const struct sockaddr*, socklen_t*);
-extern ssize_t __recvfrom_real(int, void*, size_t, int, const struct sockaddr*, socklen_t*) __RENAME(recvfrom);
+ssize_t __recvfrom_chk(int, void*, size_t, size_t, int, const struct sockaddr*, socklen_t*)
+  __INTRODUCED_IN(21);
+ssize_t __recvfrom_real(int, void*, size_t, int, const struct sockaddr*, socklen_t*) __RENAME(recvfrom);
 
 #if defined(__BIONIC_FORTIFY)
 
+#if __ANDROID_API__ >= 24
 __BIONIC_FORTIFY_INLINE
 ssize_t recvfrom(int fd, void* buf, size_t len, int flags, const struct sockaddr* src_addr, socklen_t* addr_len) {
   size_t bos = __bos0(buf);
@@ -317,6 +321,7 @@
 
   return __recvfrom_chk(fd, buf, len, bos, flags, src_addr, addr_len);
 }
+#endif /* __ANDROID_API__ >= 24 */
 
 __BIONIC_FORTIFY_INLINE
 ssize_t recv(int socket, void* buf, size_t len, int flags) {
diff --git a/libc/include/sys/socketcalls.h b/libc/include/sys/socketcalls.h
deleted file mode 100644
index 131e0bb..0000000
--- a/libc/include/sys/socketcalls.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-#ifndef _SYS_SOCKETCALLS_H_
-#define _SYS_SOCKETCALLS_H_
-
-/* socketcalls by number */
-
-#define SYS_SOCKET      1               /* sys_socket(2)                */
-#define SYS_BIND        2               /* sys_bind(2)                  */
-#define SYS_CONNECT     3               /* sys_connect(2)               */
-#define SYS_LISTEN      4               /* sys_listen(2)                */
-#define SYS_ACCEPT      5               /* sys_accept(2)                */
-#define SYS_GETSOCKNAME 6               /* sys_getsockname(2)           */
-#define SYS_GETPEERNAME 7               /* sys_getpeername(2)           */
-#define SYS_SOCKETPAIR  8               /* sys_socketpair(2)            */
-#define SYS_SEND        9               /* sys_send(2)                  */
-#define SYS_RECV        10              /* sys_recv(2)                  */
-#define SYS_SENDTO      11              /* sys_sendto(2)                */
-#define SYS_RECVFROM    12              /* sys_recvfrom(2)              */
-#define SYS_SHUTDOWN    13              /* sys_shutdown(2)              */
-#define SYS_SETSOCKOPT  14              /* sys_setsockopt(2)            */
-#define SYS_GETSOCKOPT  15              /* sys_getsockopt(2)            */
-#define SYS_SENDMSG     16              /* sys_sendmsg(2)               */
-#define SYS_RECVMSG     17              /* sys_recvmsg(2)               */
-#define SYS_ACCEPT4     18              /* sys_accept4(2)               */
-#define SYS_RECVMMSG    19              /* sys_recvmmsg(2)              */
-#define SYS_SENDMMSG    20              /* sys_sendmmsg(2)              */
-
-#endif /* _SYS_SOCKETCALLS_H_ */
diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h
index 257ded0..775fb08 100644
--- a/libc/include/sys/stat.h
+++ b/libc/include/sys/stat.h
@@ -128,35 +128,42 @@
 #define st_mtimensec st_mtim.tv_nsec
 #define st_ctimensec st_ctim.tv_nsec
 
-#ifdef __USE_BSD
+#if defined(__USE_BSD)
 /* Permission macros provided by glibc for compatibility with BSDs. */
 #define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */
 #define ALLPERMS    (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) /* 07777 */
 #define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) /* 0666 */
 #endif
 
-extern int chmod(const char*, mode_t);
-extern int fchmod(int, mode_t);
-extern int mkdir(const char*, mode_t);
+#if defined(__USE_BSD) || defined(__USE_GNU)
+#define S_IREAD S_IRUSR
+#define S_IWRITE S_IWUSR
+#define S_IEXEC S_IXUSR
+#endif
 
-extern int fstat(int, struct stat*);
-extern int fstat64(int, struct stat64*);
-extern int fstatat(int, const char*, struct stat*, int);
-extern int fstatat64(int, const char*, struct stat64*, int);
-extern int lstat(const char*, struct stat*);
-extern int lstat64(const char*, struct stat64*);
-extern int stat(const char*, struct stat*);
-extern int stat64(const char*, struct stat64*);
+int chmod(const char*, mode_t);
+int fchmod(int, mode_t);
+int mkdir(const char*, mode_t);
 
-extern int mknod(const char*, mode_t, dev_t);
-extern mode_t umask(mode_t);
+int fstat(int, struct stat*);
+int fstat64(int, struct stat64*) __INTRODUCED_IN(21);
+int fstatat(int, const char*, struct stat*, int);
+int fstatat64(int, const char*, struct stat64*, int) __INTRODUCED_IN(21);
+int lstat(const char*, struct stat*);
+int lstat64(const char*, struct stat64*) __INTRODUCED_IN(21);
+int stat(const char*, struct stat*);
+int stat64(const char*, struct stat64*) __INTRODUCED_IN(21);
 
-extern mode_t __umask_chk(mode_t);
-extern mode_t __umask_real(mode_t) __RENAME(umask);
+int mknod(const char*, mode_t, dev_t);
+mode_t umask(mode_t);
+
+mode_t __umask_chk(mode_t) __INTRODUCED_IN(18);
+mode_t __umask_real(mode_t) __RENAME(umask);
 __errordecl(__umask_invalid_mode, "umask called with invalid mode");
 
 #if defined(__BIONIC_FORTIFY)
 
+#if __ANDROID_API__ >= 18
 __BIONIC_FORTIFY_INLINE
 mode_t umask(mode_t mode) {
 #if !defined(__clang__)
@@ -169,24 +176,30 @@
 #endif
   return __umask_chk(mode);
 }
+#endif /* __ANDROID_API__ >= 18 */
+
 #endif /* defined(__BIONIC_FORTIFY) */
 
-extern int mkfifo(const char*, mode_t) __INTRODUCED_IN(21);
-extern int mkfifoat(int, const char*, mode_t);
+#if __ANDROID_API__ >= 21
+int mkfifo(const char*, mode_t) __INTRODUCED_IN(21);
+#else
+// Implemented as a static inline before 21.
+#endif
 
-extern int fchmodat(int, const char*, mode_t, int);
-extern int mkdirat(int, const char*, mode_t);
-extern int mknodat(int, const char*, mode_t, dev_t);
+int mkfifoat(int, const char*, mode_t) __INTRODUCED_IN(23);
+
+int fchmodat(int, const char*, mode_t, int);
+int mkdirat(int, const char*, mode_t);
+int mknodat(int, const char*, mode_t, dev_t) __INTRODUCED_IN(21);
 
 #define UTIME_NOW  ((1L << 30) - 1L)
 #define UTIME_OMIT ((1L << 30) - 2L)
-extern int utimensat(int fd, const char *path, const struct timespec times[2], int flags);
-extern int futimens(int fd, const struct timespec times[2]);
-
-#if __ANDROID_API__ < 21
-#include <android/legacy_sys_stat_inlines.h>
-#endif
+int utimensat(int fd, const char* path, const struct timespec times[2], int flags)
+  __INTRODUCED_IN(12);
+int futimens(int fd, const struct timespec times[2]) __INTRODUCED_IN(19);
 
 __END_DECLS
 
+#include <android/legacy_sys_stat_inlines.h>
+
 #endif /* _SYS_STAT_H_ */
diff --git a/libc/include/sys/statvfs.h b/libc/include/sys/statvfs.h
index 3495546..af1b9c0 100644
--- a/libc/include/sys/statvfs.h
+++ b/libc/include/sys/statvfs.h
@@ -59,10 +59,12 @@
 #define ST_NODIRATIME  0x0800
 #define ST_RELATIME    0x1000
 
-extern int statvfs(const char* __restrict, struct statvfs* __restrict) __nonnull((1, 2));
-extern int statvfs64(const char* __restrict, struct statvfs64* __restrict) __nonnull((1, 2));
-extern int fstatvfs(int, struct statvfs*) __nonnull((2));
-extern int fstatvfs64(int, struct statvfs64*) __nonnull((2));
+int statvfs(const char* __restrict _Nonnull, struct statvfs* __restrict _Nonnull)
+  __INTRODUCED_IN(19);
+int statvfs64(const char* __restrict _Nonnull, struct statvfs64* __restrict _Nonnull)
+  __INTRODUCED_IN(21);
+int fstatvfs(int, struct statvfs* _Nonnull) __INTRODUCED_IN(19);
+int fstatvfs64(int, struct statvfs64* _Nonnull) __INTRODUCED_IN(21);
 
 __END_DECLS
 
diff --git a/libc/include/sys/swap.h b/libc/include/sys/swap.h
index e4c1819..3444736 100644
--- a/libc/include/sys/swap.h
+++ b/libc/include/sys/swap.h
@@ -38,8 +38,8 @@
 #define SWAP_FLAG_PRIO_MASK 0x7fff
 #define SWAP_FLAG_PRIO_SHIFT 0
 
-extern int swapon(const char*, int) __nonnull((1));
-extern int swapoff(const char*) __nonnull((1));
+int swapon(const char* _Nonnull, int) __INTRODUCED_IN(19);
+int swapoff(const char* _Nonnull) __INTRODUCED_IN(19);
 
 __END_DECLS
 
diff --git a/libc/include/sys/syscall.h b/libc/include/sys/syscall.h
index 21eaf33..a49323d 100644
--- a/libc/include/sys/syscall.h
+++ b/libc/include/sys/syscall.h
@@ -30,7 +30,8 @@
 #define _SYS_SYSCALL_H_
 
 #include <asm/unistd.h> /* Linux kernel __NR_* names. */
-#include <sys/glibc-syscalls.h> /* glibc-compatible SYS_* aliases. */
+#include <bits/glibc-syscalls.h> /* glibc-compatible SYS_* aliases. */
+#include <sys/cdefs.h>
 
 /* The syscall function itself is declared in <unistd.h>, not here. */
 
diff --git a/libc/include/sys/sysconf.h b/libc/include/sys/sysconf.h
index ca32132..eb30faf 100644
--- a/libc/include/sys/sysconf.h
+++ b/libc/include/sys/sysconf.h
@@ -1,195 +1,6 @@
 /*
- * Copyright (C) 2008 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.
+ * This file used to contain the declarations of sysconf and its associated constants.
+ * No standard mentions a <sys/sysconf.h>, but there are enough users in vendor (and potential ones
+ * in the NDK) to warrant not breaking source compatibility.
  */
-#ifndef _SYS_SYSCONF_H_
-#define _SYS_SYSCONF_H_
-
-#include <sys/cdefs.h>
-
-__BEGIN_DECLS
-
-/* as listed by Posix sysconf() description */
-/* most of these will return -1 and ENOSYS  */
-
-#define _SC_ARG_MAX             0x0000
-#define _SC_BC_BASE_MAX         0x0001
-#define _SC_BC_DIM_MAX          0x0002
-#define _SC_BC_SCALE_MAX        0x0003
-#define _SC_BC_STRING_MAX       0x0004
-#define _SC_CHILD_MAX           0x0005
-#define _SC_CLK_TCK             0x0006
-#define _SC_COLL_WEIGHTS_MAX    0x0007
-#define _SC_EXPR_NEST_MAX       0x0008
-#define _SC_LINE_MAX            0x0009
-#define _SC_NGROUPS_MAX         0x000a
-#define _SC_OPEN_MAX            0x000b
-#define _SC_PASS_MAX            0x000c
-#define _SC_2_C_BIND            0x000d
-#define _SC_2_C_DEV             0x000e
-#define _SC_2_C_VERSION         0x000f  /* Obsolescent in POSIX.1-2008, TODO: remove it. */
-#define _SC_2_CHAR_TERM         0x0010
-#define _SC_2_FORT_DEV          0x0011
-#define _SC_2_FORT_RUN          0x0012
-#define _SC_2_LOCALEDEF         0x0013
-#define _SC_2_SW_DEV            0x0014
-#define _SC_2_UPE               0x0015
-#define _SC_2_VERSION           0x0016
-#define _SC_JOB_CONTROL         0x0017
-#define _SC_SAVED_IDS           0x0018
-#define _SC_VERSION             0x0019
-#define _SC_RE_DUP_MAX          0x001a
-#define _SC_STREAM_MAX          0x001b
-#define _SC_TZNAME_MAX          0x001c
-#define _SC_XOPEN_CRYPT         0x001d
-#define _SC_XOPEN_ENH_I18N      0x001e
-#define _SC_XOPEN_SHM           0x001f
-#define _SC_XOPEN_VERSION       0x0020
-#define _SC_XOPEN_XCU_VERSION   0x0021  /* Obsolescent in POSIX.1-2008, TODO: remove it. */
-#define _SC_XOPEN_REALTIME      0x0022
-#define _SC_XOPEN_REALTIME_THREADS  0x0023
-#define _SC_XOPEN_LEGACY        0x0024
-#define _SC_ATEXIT_MAX          0x0025
-#define _SC_IOV_MAX             0x0026
-#define _SC_PAGESIZE            0x0027
-#define _SC_PAGE_SIZE           0x0028
-#define _SC_XOPEN_UNIX          0x0029
-#define _SC_XBS5_ILP32_OFF32    0x002a  /* Obsolescent in POSIX.1-2008, TODO: remove it. */
-#define _SC_XBS5_ILP32_OFFBIG   0x002b  /* Obsolescent in POSIX.1-2008, TODO: remove it. */
-#define _SC_XBS5_LP64_OFF64     0x002c  /* Obsolescent in POSIX.1-2008, TODO: remove it. */
-#define _SC_XBS5_LPBIG_OFFBIG   0x002d  /* Obsolescent in POSIX.1-2008, TODO: remove it. */
-#define _SC_AIO_LISTIO_MAX      0x002e
-#define _SC_AIO_MAX             0x002f
-#define _SC_AIO_PRIO_DELTA_MAX  0x0030
-#define _SC_DELAYTIMER_MAX      0x0031
-#define _SC_MQ_OPEN_MAX         0x0032
-#define _SC_MQ_PRIO_MAX         0x0033
-#define _SC_RTSIG_MAX           0x0034
-#define _SC_SEM_NSEMS_MAX       0x0035
-#define _SC_SEM_VALUE_MAX       0x0036
-#define _SC_SIGQUEUE_MAX        0x0037
-#define _SC_TIMER_MAX           0x0038
-#define _SC_ASYNCHRONOUS_IO     0x0039
-#define _SC_FSYNC               0x003a
-#define _SC_MAPPED_FILES        0x003b
-#define _SC_MEMLOCK             0x003c
-#define _SC_MEMLOCK_RANGE       0x003d
-#define _SC_MEMORY_PROTECTION   0x003e
-#define _SC_MESSAGE_PASSING     0x003f
-#define _SC_PRIORITIZED_IO      0x0040
-#define _SC_PRIORITY_SCHEDULING 0x0041
-#define _SC_REALTIME_SIGNALS    0x0042
-#define _SC_SEMAPHORES          0x0043
-#define _SC_SHARED_MEMORY_OBJECTS  0x0044
-#define _SC_SYNCHRONIZED_IO     0x0045
-#define _SC_TIMERS              0x0046
-#define _SC_GETGR_R_SIZE_MAX    0x0047
-#define _SC_GETPW_R_SIZE_MAX    0x0048
-#define _SC_LOGIN_NAME_MAX      0x0049
-#define _SC_THREAD_DESTRUCTOR_ITERATIONS  0x004a
-#define _SC_THREAD_KEYS_MAX     0x004b
-#define _SC_THREAD_STACK_MIN    0x004c
-#define _SC_THREAD_THREADS_MAX  0x004d
-#define _SC_TTY_NAME_MAX        0x004e
-
-#define _SC_THREADS                     0x004f
-#define _SC_THREAD_ATTR_STACKADDR       0x0050
-#define _SC_THREAD_ATTR_STACKSIZE       0x0051
-#define _SC_THREAD_PRIORITY_SCHEDULING  0x0052
-#define _SC_THREAD_PRIO_INHERIT         0x0053
-#define _SC_THREAD_PRIO_PROTECT         0x0054
-#define _SC_THREAD_SAFE_FUNCTIONS       0x0055
-
-#define _SC_NPROCESSORS_CONF            0x0060
-#define _SC_NPROCESSORS_ONLN            0x0061
-#define _SC_PHYS_PAGES                  0x0062
-#define _SC_AVPHYS_PAGES                0x0063
-#define _SC_MONOTONIC_CLOCK             0x0064
-
-#define _SC_2_PBS               0x0065
-#define _SC_2_PBS_ACCOUNTING    0x0066
-#define _SC_2_PBS_CHECKPOINT    0x0067
-#define _SC_2_PBS_LOCATE        0x0068
-#define _SC_2_PBS_MESSAGE       0x0069
-#define _SC_2_PBS_TRACK         0x006a
-#define _SC_ADVISORY_INFO       0x006b
-#define _SC_BARRIERS            0x006c
-#define _SC_CLOCK_SELECTION     0x006d
-#define _SC_CPUTIME             0x006e
-#define _SC_HOST_NAME_MAX       0x006f
-#define _SC_IPV6                0x0070
-#define _SC_RAW_SOCKETS         0x0071
-#define _SC_READER_WRITER_LOCKS 0x0072
-#define _SC_REGEXP              0x0073
-#define _SC_SHELL               0x0074
-#define _SC_SPAWN               0x0075
-#define _SC_SPIN_LOCKS          0x0076
-#define _SC_SPORADIC_SERVER     0x0077
-#define _SC_SS_REPL_MAX         0x0078
-#define _SC_SYMLOOP_MAX         0x0079
-#define _SC_THREAD_CPUTIME      0x007a
-#define _SC_THREAD_PROCESS_SHARED       0x007b
-#define _SC_THREAD_ROBUST_PRIO_INHERIT  0x007c
-#define _SC_THREAD_ROBUST_PRIO_PROTECT  0x007d
-#define _SC_THREAD_SPORADIC_SERVER      0x007e
-#define _SC_TIMEOUTS            0x007f
-#define _SC_TRACE               0x0080
-#define _SC_TRACE_EVENT_FILTER  0x0081
-#define _SC_TRACE_EVENT_NAME_MAX  0x0082
-#define _SC_TRACE_INHERIT       0x0083
-#define _SC_TRACE_LOG           0x0084
-#define _SC_TRACE_NAME_MAX      0x0085
-#define _SC_TRACE_SYS_MAX       0x0086
-#define _SC_TRACE_USER_EVENT_MAX  0x0087
-#define _SC_TYPED_MEMORY_OBJECTS  0x0088
-#define _SC_V7_ILP32_OFF32      0x0089
-#define _SC_V7_ILP32_OFFBIG     0x008a
-#define _SC_V7_LP64_OFF64       0x008b
-#define _SC_V7_LPBIG_OFFBIG     0x008c
-#define _SC_XOPEN_STREAMS       0x008d
-#define _SC_XOPEN_UUCP          0x008e
-
-#define _SC_LEVEL1_ICACHE_SIZE      0x008f
-#define _SC_LEVEL1_ICACHE_ASSOC     0x0090
-#define _SC_LEVEL1_ICACHE_LINESIZE  0x0091
-#define _SC_LEVEL1_DCACHE_SIZE      0x0092
-#define _SC_LEVEL1_DCACHE_ASSOC     0x0093
-#define _SC_LEVEL1_DCACHE_LINESIZE  0x0094
-#define _SC_LEVEL2_CACHE_SIZE       0x0095
-#define _SC_LEVEL2_CACHE_ASSOC      0x0096
-#define _SC_LEVEL2_CACHE_LINESIZE   0x0097
-#define _SC_LEVEL3_CACHE_SIZE       0x0098
-#define _SC_LEVEL3_CACHE_ASSOC      0x0099
-#define _SC_LEVEL3_CACHE_LINESIZE   0x009a
-#define _SC_LEVEL4_CACHE_SIZE       0x009b
-#define _SC_LEVEL4_CACHE_ASSOC      0x009c
-#define _SC_LEVEL4_CACHE_LINESIZE   0x009d
-
-long sysconf(int);
-
-__END_DECLS
-
-#endif /* _SYS_SYSCONF_H_ */
+#include <bits/sysconf.h>
diff --git a/libc/include/sys/sysinfo.h b/libc/include/sys/sysinfo.h
index b66bc8e..9a10d64 100644
--- a/libc/include/sys/sysinfo.h
+++ b/libc/include/sys/sysinfo.h
@@ -35,13 +35,13 @@
 
 int sysinfo(struct sysinfo* info);
 
-int get_nprocs_conf(void);
+int get_nprocs_conf(void) __INTRODUCED_IN(23);
 
-int get_nprocs(void);
+int get_nprocs(void) __INTRODUCED_IN(23);
 
-long get_phys_pages(void);
+long get_phys_pages(void) __INTRODUCED_IN(23);
 
-long get_avphys_pages(void);
+long get_avphys_pages(void) __INTRODUCED_IN(23);
 
 __END_DECLS
 
diff --git a/libc/include/sys/sysmacros.h b/libc/include/sys/sysmacros.h
index 54e43dd..592cc5e 100644
--- a/libc/include/sys/sysmacros.h
+++ b/libc/include/sys/sysmacros.h
@@ -29,6 +29,8 @@
 #ifndef _SYS_SYSMACROS_H_
 #define _SYS_SYSMACROS_H_
 
+#include <sys/cdefs.h>
+
 #define makedev(__major, __minor) \
   ( \
     (((__major) & 0xfffff000ULL) << 32) | (((__major) & 0xfffULL) << 8) | \
diff --git a/libc/include/sys/system_properties.h b/libc/include/sys/system_properties.h
index 01c3db3..d3e0d8d 100644
--- a/libc/include/sys/system_properties.h
+++ b/libc/include/sys/system_properties.h
@@ -48,7 +48,7 @@
 
 /* Set a system property by name.
 **/
-int __system_property_set(const char *key, const char *value);
+int __system_property_set(const char* key, const char* value) __INTRODUCED_IN(12);
 
 /* Return a pointer to the system property named name, if it
 ** exists, or NULL if there is no such property.  Use 
@@ -93,9 +93,8 @@
 ** Order of results may change from call to call.  This is
 ** not a bug.
 */
-int __system_property_foreach(
-        void (*propfn)(const prop_info *pi, void *cookie),
-        void *cookie);
+int __system_property_foreach(void (*propfn)(const prop_info* pi, void* cookie), void* cookie)
+  __INTRODUCED_IN(19);
 
 __END_DECLS
 
diff --git a/libc/include/sys/time.h b/libc/include/sys/time.h
index f60c905..ad5844a 100644
--- a/libc/include/sys/time.h
+++ b/libc/include/sys/time.h
@@ -38,13 +38,22 @@
 
 __BEGIN_DECLS
 
-extern int gettimeofday(struct timeval *, struct timezone *);
-extern int settimeofday(const struct timeval *, const struct timezone *);
+int gettimeofday(struct timeval*, struct timezone*);
+int settimeofday(const struct timeval*, const struct timezone*);
 
-extern int getitimer(int, struct itimerval *);
-extern int setitimer(int, const struct itimerval *, struct itimerval *);
+int getitimer(int, struct itimerval*);
+int setitimer(int, const struct itimerval*, struct itimerval*);
 
-extern int utimes(const char *, const struct timeval *);
+int utimes(const char*, const struct timeval*);
+
+#if defined(__USE_BSD)
+int futimes(int, const struct timeval[2]) __INTRODUCED_IN_FUTURE;
+int lutimes(const char*, const struct timeval[2]) __INTRODUCED_IN_FUTURE;
+#endif
+
+#if defined(__USE_GNU)
+int futimesat(int, const char*, const struct timeval[2]) __INTRODUCED_IN_FUTURE;
+#endif
 
 #define timerclear(a)   \
         ((a)->tv_sec = (a)->tv_usec = 0)
diff --git a/libc/include/sys/timerfd.h b/libc/include/sys/timerfd.h
index 1aa97b4..a500060 100644
--- a/libc/include/sys/timerfd.h
+++ b/libc/include/sys/timerfd.h
@@ -31,6 +31,7 @@
 
 #include <fcntl.h> /* For O_CLOEXEC and O_NONBLOCK. */
 #include <time.h>
+#include <sys/cdefs.h>
 #include <sys/types.h>
 
 __BEGIN_DECLS
@@ -41,10 +42,9 @@
 #define TFD_CLOEXEC O_CLOEXEC
 #define TFD_NONBLOCK O_NONBLOCK
 
-extern int timerfd_create(clockid_t, int);
-extern int timerfd_settime(int, int, const struct itimerspec*,
-                           struct itimerspec*);
-extern int timerfd_gettime(int, struct itimerspec*);
+int timerfd_create(clockid_t, int) __INTRODUCED_IN(19);
+int timerfd_settime(int, int, const struct itimerspec*, struct itimerspec*) __INTRODUCED_IN(19);
+int timerfd_gettime(int, struct itimerspec*) __INTRODUCED_IN(19);
 
 __END_DECLS
 
diff --git a/libc/include/sys/times.h b/libc/include/sys/times.h
index 6ce5b55..f52db1f 100644
--- a/libc/include/sys/times.h
+++ b/libc/include/sys/times.h
@@ -35,7 +35,7 @@
 
 __BEGIN_DECLS
 
-extern clock_t times(struct tms*);
+clock_t times(struct tms*);
 
 __END_DECLS
 
diff --git a/libc/include/sys/timex.h b/libc/include/sys/timex.h
index fade5c3..f704ce8 100644
--- a/libc/include/sys/timex.h
+++ b/libc/include/sys/timex.h
@@ -35,8 +35,8 @@
 
 __BEGIN_DECLS
 
-int adjtimex(struct timex*);
-int clock_adjtime(clockid_t, struct timex*);
+int adjtimex(struct timex*) __INTRODUCED_IN(24);
+int clock_adjtime(clockid_t, struct timex*) __INTRODUCED_IN(24);
 
 __END_DECLS
 
diff --git a/libc/include/sys/ttychars.h b/libc/include/sys/ttychars.h
deleted file mode 100644
index e69de29..0000000
--- a/libc/include/sys/ttychars.h
+++ /dev/null
diff --git a/libc/include/sys/ttydefaults.h b/libc/include/sys/ttydefaults.h
index 405e759..62af84b 100644
--- a/libc/include/sys/ttydefaults.h
+++ b/libc/include/sys/ttydefaults.h
@@ -42,6 +42,8 @@
 #ifndef _SYS_TTYDEFAULTS_H_
 #define	_SYS_TTYDEFAULTS_H_
 
+#include <sys/cdefs.h>
+
 /*
  * Defaults on "first" open.
  */
@@ -84,7 +86,6 @@
 /*
  * #define TTYDEFCHARS to include an array of default control characters.
  */
-#ifdef _KERNEL
 #ifdef TTYDEFCHARS
 const cc_t ttydefchars[NCCS] = {
 	[VEOF] = CEOF,
@@ -109,7 +110,4 @@
 	[19] = _POSIX_VDISABLE,	/* spare */
 };
 #undef TTYDEFCHARS
-#else
-extern const cc_t ttydefchars[NCCS];
 #endif
-#endif /* _KERNEL */
diff --git a/libc/include/sys/ttydev.h b/libc/include/sys/ttydev.h
deleted file mode 100644
index e69de29..0000000
--- a/libc/include/sys/ttydev.h
+++ /dev/null
diff --git a/libc/include/sys/types.h b/libc/include/sys/types.h
index 217fd60..2895057 100644
--- a/libc/include/sys/types.h
+++ b/libc/include/sys/types.h
@@ -66,6 +66,8 @@
 typedef __kernel_ino_t __ino_t;
 typedef __ino_t ino_t;
 
+typedef uint64_t ino64_t;
+
 typedef uint32_t __nlink_t;
 typedef __nlink_t nlink_t;
 
@@ -139,7 +141,7 @@
 typedef unsigned int        uint_t;
 typedef unsigned int        uint;
 
-#ifdef __BSD_VISIBLE
+#if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
 #include <sys/sysmacros.h>
 
 typedef unsigned char  u_char;
diff --git a/libc/include/sys/ucontext.h b/libc/include/sys/ucontext.h
index 9e3c653..fdb3015 100644
--- a/libc/include/sys/ucontext.h
+++ b/libc/include/sys/ucontext.h
@@ -30,6 +30,7 @@
 #define _SYS_UCONTEXT_H_
 
 #include <signal.h>
+#include <sys/cdefs.h>
 #include <sys/user.h>
 
 __BEGIN_DECLS
@@ -70,9 +71,9 @@
   stack_t uc_stack;
   mcontext_t uc_mcontext;
   sigset_t uc_sigmask;
-  // Android has a wrong (smaller) sigset_t on ARM.
+  /* Android has a wrong (smaller) sigset_t on ARM. */
   uint32_t __padding_rt_sigset;
-  // The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM.
+  /* The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM. */
   char __padding[120];
   unsigned long uc_regspace[128] __attribute__((__aligned__(8)));
 } ucontext_t;
@@ -92,7 +93,7 @@
   struct ucontext *uc_link;
   stack_t uc_stack;
   sigset_t uc_sigmask;
-  // The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM64.
+  /* The kernel adds extra padding after uc_sigmask to match glibc sigset_t on ARM64. */
   char __padding[128 - sizeof(sigset_t)];
   mcontext_t uc_mcontext;
 } ucontext_t;
@@ -157,7 +158,7 @@
   stack_t uc_stack;
   mcontext_t uc_mcontext;
   sigset_t uc_sigmask;
-  // Android has a wrong (smaller) sigset_t on x86.
+  /* Android has a wrong (smaller) sigset_t on x86. */
   uint32_t __padding_rt_sigset;
   struct _libc_fpstate __fpregs_mem;
 } ucontext_t;
diff --git a/libc/include/sys/uio.h b/libc/include/sys/uio.h
index 72675d1..7a009b4 100644
--- a/libc/include/sys/uio.h
+++ b/libc/include/sys/uio.h
@@ -42,16 +42,18 @@
 ssize_t preadv(int, const struct iovec*, int, off_t) __RENAME(preadv64);
 ssize_t pwritev(int, const struct iovec*, int, off_t) __RENAME(pwritev64);
 #else
-ssize_t preadv(int, const struct iovec*, int, off_t);
-ssize_t pwritev(int, const struct iovec*, int, off_t);
+ssize_t preadv(int, const struct iovec*, int, off_t) __INTRODUCED_IN(24);
+ssize_t pwritev(int, const struct iovec*, int, off_t) __INTRODUCED_IN(24);
 #endif
-ssize_t preadv64(int, const struct iovec*, int, off64_t);
-ssize_t pwritev64(int, const struct iovec*, int, off64_t);
+ssize_t preadv64(int, const struct iovec*, int, off64_t) __INTRODUCED_IN(24);
+ssize_t pwritev64(int, const struct iovec*, int, off64_t) __INTRODUCED_IN(24);
 #endif
 
 #if defined(__USE_GNU)
-ssize_t process_vm_readv(pid_t, const struct iovec*, unsigned long, const struct iovec*, unsigned long, unsigned long);
-ssize_t process_vm_writev(pid_t, const struct iovec*, unsigned long, const struct iovec*, unsigned long, unsigned long);
+ssize_t process_vm_readv(pid_t, const struct iovec*, unsigned long, const struct iovec*,
+                         unsigned long, unsigned long) __INTRODUCED_IN(23);
+ssize_t process_vm_writev(pid_t, const struct iovec*, unsigned long, const struct iovec*,
+                          unsigned long, unsigned long) __INTRODUCED_IN(23);
 #endif
 
 __END_DECLS
diff --git a/libc/include/sys/un.h b/libc/include/sys/un.h
index 65ffbdcf..3e1c429 100644
--- a/libc/include/sys/un.h
+++ b/libc/include/sys/un.h
@@ -25,11 +25,12 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #ifndef _SYS_UN_H_
 #define _SYS_UN_H_
 
-typedef unsigned short sa_family_t;
-
+#include <bits/sa_family_t.h>
 #include <linux/un.h>
+#include <sys/cdefs.h>
 
-#endif /* _SYS_UN_H_ */
+#endif
diff --git a/libc/include/sys/user.h b/libc/include/sys/user.h
index 3312981..5601b02 100644
--- a/libc/include/sys/user.h
+++ b/libc/include/sys/user.h
@@ -31,6 +31,7 @@
 
 #include <sys/cdefs.h>
 #include <stddef.h> /* For size_t. */
+#include <stdint.h>
 
 __BEGIN_DECLS
 
@@ -108,13 +109,13 @@
   unsigned short swd;
   unsigned short ftw;
   unsigned short fop;
-  __u64 rip;
-  __u64 rdp;
-  __u32 mxcsr;
-  __u32 mxcr_mask;
-  __u32 st_space[32];
-  __u32 xmm_space[64];
-  __u32 padding[24];
+  unsigned long rip;
+  unsigned long rdp;
+  unsigned int mxcsr;
+  unsigned int mxcr_mask;
+  unsigned int st_space[32];
+  unsigned int xmm_space[64];
+  unsigned int padding[24];
 };
 struct user_regs_struct {
   unsigned long r15;
diff --git a/libc/include/sys/utsname.h b/libc/include/sys/utsname.h
index d54a994..b3856a7 100644
--- a/libc/include/sys/utsname.h
+++ b/libc/include/sys/utsname.h
@@ -25,6 +25,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #ifndef _SYS_UTSNAME_H_
 #define _SYS_UTSNAME_H_
 
@@ -43,7 +44,7 @@
     char  domainname[SYS_NMLN];
 };
 
-extern int uname(struct utsname *);
+int uname(struct utsname*);
 
 __END_DECLS
 
diff --git a/libc/include/sys/vfs.h b/libc/include/sys/vfs.h
index 1fbc8be..1231eb1 100644
--- a/libc/include/sys/vfs.h
+++ b/libc/include/sys/vfs.h
@@ -137,10 +137,10 @@
 #define XENIX_SUPER_MAGIC     0x012FF7B4
 #define XFS_SUPER_MAGIC       0x58465342
 
-extern int statfs(const char*, struct statfs*) __nonnull((1, 2));
-extern int statfs64(const char*, struct statfs64*) __nonnull((1, 2));
-extern int fstatfs(int, struct statfs*) __nonnull((2));
-extern int fstatfs64(int, struct statfs64*) __nonnull((2));
+int statfs(const char* _Nonnull, struct statfs* _Nonnull);
+int statfs64(const char* _Nonnull, struct statfs64* _Nonnull) __INTRODUCED_IN(21);
+int fstatfs(int, struct statfs* _Nonnull);
+int fstatfs64(int, struct statfs64* _Nonnull) __INTRODUCED_IN(21);
 
 __END_DECLS
 
diff --git a/libc/include/sys/wait.h b/libc/include/sys/wait.h
index 2317b02..90eb35b 100644
--- a/libc/include/sys/wait.h
+++ b/libc/include/sys/wait.h
@@ -49,9 +49,9 @@
 #define W_EXITCODE(ret, sig)    ((ret) << 8 | (sig))
 #define W_STOPCODE(sig)         ((sig) << 8 | 0x7f)
 
-extern pid_t  wait(int *);
-extern pid_t  waitpid(pid_t, int *, int);
-extern pid_t  wait4(pid_t, int *, int, struct rusage *);
+pid_t wait(int*);
+pid_t waitpid(pid_t, int*, int);
+pid_t wait4(pid_t, int*, int, struct rusage*) __INTRODUCED_IN(18);
 
 /* Posix states that idtype_t should be an enumeration type, but
  * the kernel headers define P_ALL, P_PID and P_PGID as constant macros
@@ -59,7 +59,7 @@
  */
 typedef int idtype_t;
 
-extern int  waitid(idtype_t which, id_t id, siginfo_t *info, int options);
+int waitid(idtype_t which, id_t id, siginfo_t* info, int options);
 
 __END_DECLS
 
diff --git a/libc/include/sys/xattr.h b/libc/include/sys/xattr.h
index 39b25b1..37e352d 100644
--- a/libc/include/sys/xattr.h
+++ b/libc/include/sys/xattr.h
@@ -25,31 +25,34 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #ifndef _SYS_XATTR_H_
 #define _SYS_XATTR_H_
 
+#include <linux/xattr.h>
+#include <sys/cdefs.h>
 #include <sys/types.h>
 
 __BEGIN_DECLS
 
-#define XATTR_CREATE 1
-#define XATTR_REPLACE 2
+int fsetxattr(int fd, const char* name, const void* value, size_t size, int flags)
+  __INTRODUCED_IN(16);
+int setxattr(const char* path, const char* name, const void* value, size_t size, int flags)
+  __INTRODUCED_IN(16);
+int lsetxattr(const char* path, const char* name, const void* value, size_t size, int flags)
+  __INTRODUCED_IN(16);
 
-extern int fsetxattr(int fd, const char *name, const void *value, size_t size, int flags);
-extern int setxattr(const char *path, const char *name, const void *value, size_t size, int flags);
-extern int lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags);
+ssize_t fgetxattr(int fd, const char* name, void* value, size_t size) __INTRODUCED_IN(16);
+ssize_t getxattr(const char* path, const char* name, void* value, size_t size) __INTRODUCED_IN(16);
+ssize_t lgetxattr(const char* path, const char* name, void* value, size_t size) __INTRODUCED_IN(16);
 
-extern ssize_t fgetxattr(int fd, const char *name, void *value, size_t size);
-extern ssize_t getxattr(const char *path, const char *name, void *value, size_t size);
-extern ssize_t lgetxattr(const char *path, const char *name, void *value, size_t size);
+ssize_t listxattr(const char* path, char* list, size_t size) __INTRODUCED_IN(16);
+ssize_t llistxattr(const char* path, char* list, size_t size) __INTRODUCED_IN(16);
+ssize_t flistxattr(int fd, char* list, size_t size) __INTRODUCED_IN(16);
 
-extern ssize_t listxattr(const char *path, char *list, size_t size);
-extern ssize_t llistxattr(const char *path, char *list, size_t size);
-extern ssize_t flistxattr(int fd, char *list, size_t size);
-
-extern int removexattr(const char *path, const char *name);
-extern int lremovexattr(const char *path, const char *name);
-extern int fremovexattr(int fd, const char *name);
+int removexattr(const char* path, const char* name) __INTRODUCED_IN(16);
+int lremovexattr(const char* path, const char* name) __INTRODUCED_IN(16);
+int fremovexattr(int fd, const char* name) __INTRODUCED_IN(16);
 
 __END_DECLS
 
diff --git a/libc/include/sysexits.h b/libc/include/sysexits.h
index e244836..97f5366 100644
--- a/libc/include/sysexits.h
+++ b/libc/include/sysexits.h
@@ -35,6 +35,8 @@
 #ifndef	_SYSEXITS_H_
 #define	_SYSEXITS_H_
 
+#include <sys/cdefs.h>
+
 /*
  *  SYSEXITS.H -- Exit status codes for system programs.
  *
diff --git a/libc/include/syslog.h b/libc/include/syslog.h
index 8000f03..ee288e5 100644
--- a/libc/include/syslog.h
+++ b/libc/include/syslog.h
@@ -86,10 +86,10 @@
 #define LOG_PERROR 0x20
 
 void closelog(void);
-void openlog(const char*, int, int);
+void openlog(const char* _Nullable, int, int);
 int setlogmask(int);
-void syslog(int, const char*, ...) __printflike(2, 3);
-void vsyslog(int, const char*, va_list) __printflike(2, 0);
+void syslog(int, const char* _Nonnull, ...) __printflike(2, 3);
+void vsyslog(int, const char* _Nonnull, va_list) __printflike(2, 0);
 
 __END_DECLS
 
diff --git a/libc/include/termio.h b/libc/include/termio.h
index 99d3630..9e26956 100644
--- a/libc/include/termio.h
+++ b/libc/include/termio.h
@@ -1,32 +1 @@
-/*
- * Copyright (C) 2010 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.
- */
-
-/* All definitions related to termio are in Linux kernel headers
- * that are already included by <termios.h>
- */
 #include <termios.h>
diff --git a/libc/include/termios.h b/libc/include/termios.h
index 683fde2..c17794c 100644
--- a/libc/include/termios.h
+++ b/libc/include/termios.h
@@ -36,23 +36,25 @@
 __BEGIN_DECLS
 
 #if __ANDROID_API__ >= 21
-speed_t cfgetispeed(const struct termios*);
-speed_t cfgetospeed(const struct termios*);
-void cfmakeraw(struct termios*);
-int cfsetispeed(struct termios*, speed_t);
-int cfsetospeed(struct termios*, speed_t);
-int cfsetspeed(struct termios*, speed_t);
-int tcdrain(int);
-int tcflow(int, int);
-int tcflush(int, int);
-int tcgetattr(int, struct termios*);
-pid_t tcgetsid(int);
-int tcsendbreak(int, int);
-int tcsetattr(int, int, const struct termios*);
-#else
-#include <android/legacy_termios_inlines.h>
+// Implemented as static inlines before 21.
+speed_t cfgetispeed(const struct termios*) __INTRODUCED_IN(21);
+speed_t cfgetospeed(const struct termios*) __INTRODUCED_IN(21);
+void cfmakeraw(struct termios*) __INTRODUCED_IN(21);
+int cfsetispeed(struct termios*, speed_t) __INTRODUCED_IN(21);
+int cfsetospeed(struct termios*, speed_t) __INTRODUCED_IN(21);
+int tcflow(int, int) __INTRODUCED_IN(21);
+int tcflush(int, int) __INTRODUCED_IN(21);
+int tcgetattr(int, struct termios*) __INTRODUCED_IN(21);
+pid_t tcgetsid(int) __INTRODUCED_IN(21);
+int tcsendbreak(int, int) __INTRODUCED_IN(21);
+int tcsetattr(int, int, const struct termios*) __INTRODUCED_IN(21);
 #endif
 
+int cfsetspeed(struct termios*, speed_t) __INTRODUCED_IN(21);
+int tcdrain(int) __INTRODUCED_IN(21);
+
 __END_DECLS
 
+#include <android/legacy_termios_inlines.h>
+
 #endif /* _TERMIOS_H_ */
diff --git a/libc/include/time.h b/libc/include/time.h
index 1b0f6a1..888ce12 100644
--- a/libc/include/time.h
+++ b/libc/include/time.h
@@ -37,9 +37,9 @@
 
 #define CLOCKS_PER_SEC 1000000
 
-extern char* tzname[] __LIBC_ABI_PUBLIC__;
-extern int daylight __LIBC_ABI_PUBLIC__;
-extern long int timezone __LIBC_ABI_PUBLIC__;
+extern char* tzname[];
+extern int daylight;
+extern long int timezone;
 
 struct sigevent;
 
@@ -59,48 +59,48 @@
 
 #define TM_ZONE tm_zone
 
-extern time_t time(time_t*) __LIBC_ABI_PUBLIC__;
-extern int nanosleep(const struct timespec*, struct timespec*) __LIBC_ABI_PUBLIC__;
+time_t time(time_t*);
+int nanosleep(const struct timespec*, struct timespec*);
 
-extern char* asctime(const struct tm*) __LIBC_ABI_PUBLIC__;
-extern char* asctime_r(const struct tm*, char*) __LIBC_ABI_PUBLIC__;
+char* asctime(const struct tm*);
+char* asctime_r(const struct tm*, char*);
 
-extern double difftime(time_t, time_t) __LIBC_ABI_PUBLIC__;
-extern time_t mktime(struct tm*) __LIBC_ABI_PUBLIC__;
+double difftime(time_t, time_t);
+time_t mktime(struct tm*);
 
-extern struct tm* localtime(const time_t*) __LIBC_ABI_PUBLIC__;
-extern struct tm* localtime_r(const time_t*, struct tm*) __LIBC_ABI_PUBLIC__;
+struct tm* localtime(const time_t*);
+struct tm* localtime_r(const time_t*, struct tm*);
 
-extern struct tm* gmtime(const time_t*) __LIBC_ABI_PUBLIC__;
-extern struct tm* gmtime_r(const time_t*, struct tm*) __LIBC_ABI_PUBLIC__;
+struct tm* gmtime(const time_t*);
+struct tm* gmtime_r(const time_t*, struct tm*);
 
-extern char* strptime(const char*, const char*, struct tm*) __LIBC_ABI_PUBLIC__;
-extern size_t strftime(char*, size_t, const char*, const struct tm*) __LIBC_ABI_PUBLIC__;
-extern size_t strftime_l(char *, size_t, const char *, const struct tm *, locale_t) __LIBC_ABI_PUBLIC__;
+char* strptime(const char*, const char*, struct tm*);
+size_t strftime(char*, size_t, const char*, const struct tm*);
+size_t strftime_l(char*, size_t, const char*, const struct tm*, locale_t) __INTRODUCED_IN(21);
 
-extern char* ctime(const time_t*) __LIBC_ABI_PUBLIC__;
-extern char* ctime_r(const time_t*, char*) __LIBC_ABI_PUBLIC__;
+char* ctime(const time_t*);
+char* ctime_r(const time_t*, char*);
 
-extern void tzset(void) __LIBC_ABI_PUBLIC__;
+void tzset(void);
 
-extern clock_t clock(void) __LIBC_ABI_PUBLIC__;
+clock_t clock(void);
 
-extern int clock_getcpuclockid(pid_t, clockid_t*) __LIBC_ABI_PUBLIC__;
+int clock_getcpuclockid(pid_t, clockid_t*) __INTRODUCED_IN(23);
 
-extern int clock_getres(clockid_t, struct timespec*) __LIBC_ABI_PUBLIC__;
-extern int clock_gettime(clockid_t, struct timespec*) __LIBC_ABI_PUBLIC__;
-extern int clock_nanosleep(clockid_t, int, const struct timespec*, struct timespec*) __LIBC_ABI_PUBLIC__;
-extern int clock_settime(clockid_t, const struct timespec*) __LIBC_ABI_PUBLIC__;
+int clock_getres(clockid_t, struct timespec*);
+int clock_gettime(clockid_t, struct timespec*);
+int clock_nanosleep(clockid_t, int, const struct timespec*, struct timespec*);
+int clock_settime(clockid_t, const struct timespec*);
 
-extern int timer_create(int, struct sigevent*, timer_t*) __LIBC_ABI_PUBLIC__;
-extern int timer_delete(timer_t) __LIBC_ABI_PUBLIC__;
-extern int timer_settime(timer_t, int, const struct itimerspec*, struct itimerspec*) __LIBC_ABI_PUBLIC__;
-extern int timer_gettime(timer_t, struct itimerspec*) __LIBC_ABI_PUBLIC__;
-extern int timer_getoverrun(timer_t) __LIBC_ABI_PUBLIC__;
+int timer_create(int, struct sigevent*, timer_t*);
+int timer_delete(timer_t);
+int timer_settime(timer_t, int, const struct itimerspec*, struct itimerspec*);
+int timer_gettime(timer_t, struct itimerspec*);
+int timer_getoverrun(timer_t);
 
 /* Non-standard extensions that are in the BSDs and glibc. */
-extern time_t timelocal(struct tm*) __LIBC_ABI_PUBLIC__;
-extern time_t timegm(struct tm*) __LIBC_ABI_PUBLIC__;
+time_t timelocal(struct tm*) __INTRODUCED_IN(12);
+time_t timegm(struct tm*) __INTRODUCED_IN(12);
 
 __END_DECLS
 
diff --git a/libc/include/uchar.h b/libc/include/uchar.h
index a5e72ea..818acb1 100644
--- a/libc/include/uchar.h
+++ b/libc/include/uchar.h
@@ -29,12 +29,13 @@
 #ifndef _UCHAR_H_
 #define _UCHAR_H_
 
+#include <stddef.h>
 #include <sys/cdefs.h>
-#include <wchar.h>
+#include <bits/mbstate_t.h>
 
 __BEGIN_DECLS
 
-#if __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
+#if !defined(__cplusplus)
 typedef __CHAR16_TYPE__ char16_t;
 typedef __CHAR32_TYPE__ char32_t;
 #endif
@@ -42,16 +43,12 @@
 #define __STD_UTF_16__ 1
 #define __STD_UTF_32__ 1
 
-size_t c16rtomb(char* __restrict, char16_t, mbstate_t* __restrict);
-size_t c32rtomb(char* __restrict, char32_t, mbstate_t* __restrict);
-size_t mbrtoc16(char16_t* __restrict,
-                const char* __restrict,
-                size_t,
-                mbstate_t* __restrict);
-size_t mbrtoc32(char32_t* __restrict,
-                const char* __restrict,
-                size_t,
-                mbstate_t* __restrict);
+size_t c16rtomb(char* __restrict, char16_t, mbstate_t* __restrict) __INTRODUCED_IN(21);
+size_t c32rtomb(char* __restrict, char32_t, mbstate_t* __restrict) __INTRODUCED_IN(21);
+size_t mbrtoc16(char16_t* __restrict, const char* __restrict, size_t, mbstate_t* __restrict)
+  __INTRODUCED_IN(21);
+size_t mbrtoc32(char32_t* __restrict, const char* __restrict, size_t, mbstate_t* __restrict)
+  __INTRODUCED_IN(21);
 
 __END_DECLS
 
diff --git a/libc/include/ucontext.h b/libc/include/ucontext.h
index 5ea2982..73c2166 100644
--- a/libc/include/ucontext.h
+++ b/libc/include/ucontext.h
@@ -1,34 +1 @@
-/*
- * Copyright (C) 2014 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.
- */
-
-#ifndef _UCONTEXT_H_
-#define _UCONTEXT_H_
-
 #include <sys/ucontext.h>
-
-#endif /* _UCONTEXT_H_ */
diff --git a/libc/include/unistd.h b/libc/include/unistd.h
index 5045267..c792289 100644
--- a/libc/include/unistd.h
+++ b/libc/include/unistd.h
@@ -33,10 +33,13 @@
 #include <sys/cdefs.h>
 #include <sys/types.h>
 #include <sys/select.h>
-#include <sys/sysconf.h>
 
+#include <bits/fcntl.h>
+#include <bits/getopt.h>
+#include <bits/ioctl.h>
 #include <bits/lockf.h>
 #include <bits/posix_limits.h>
+#include <bits/sysconf.h>
 
 __BEGIN_DECLS
 
@@ -76,151 +79,137 @@
 
 extern char** environ;
 
-extern __noreturn void _exit(int __status);
+__noreturn void _exit(int __status);
 
-extern pid_t  fork(void);
-extern pid_t  vfork(void);
-extern pid_t  getpid(void);
-extern pid_t  gettid(void) __pure2;
-extern pid_t  getpgid(pid_t __pid);
-extern int    setpgid(pid_t __pid, pid_t __pgid);
-extern pid_t  getppid(void);
-extern pid_t  getpgrp(void);
-extern int    setpgrp(void);
-extern pid_t  getsid(pid_t __pid) __INTRODUCED_IN(21);
-extern pid_t  setsid(void);
+pid_t  fork(void);
+pid_t  vfork(void);
+pid_t  getpid(void);
+pid_t  gettid(void) __pure2;
+pid_t  getpgid(pid_t __pid);
+int    setpgid(pid_t __pid, pid_t __pgid);
+pid_t  getppid(void);
+pid_t  getpgrp(void);
+int    setpgrp(void);
+pid_t  getsid(pid_t __pid) __INTRODUCED_IN(17);
+pid_t  setsid(void);
 
-extern int execv(const char* __path, char* const* __argv);
-extern int execvp(const char* __file, char* const* __argv);
-extern int execvpe(const char* __file, char* const* __argv, char* const* __envp)
-  __INTRODUCED_IN(21);
-extern int execve(const char* __file, char* const* __argv, char* const* __envp);
-extern int execl(const char* __path, const char* __arg0, ...);
-extern int execlp(const char* __file, const char* __arg0, ...);
-extern int execle(const char* __path, const char* __arg0, ...);
+int execv(const char* __path, char* const* __argv);
+int execvp(const char* __file, char* const* __argv);
+int execvpe(const char* __file, char* const* __argv, char* const* __envp) __INTRODUCED_IN(21);
+int execve(const char* __file, char* const* __argv, char* const* __envp);
+int execl(const char* __path, const char* __arg0, ...);
+int execlp(const char* __file, const char* __arg0, ...);
+int execle(const char* __path, const char* __arg0, ...);
 
-extern int nice(int __incr);
+int nice(int __incr);
 
-extern int setuid(uid_t __uid);
-extern uid_t getuid(void);
-extern int seteuid(uid_t __uid);
-extern uid_t geteuid(void);
-extern int setgid(gid_t __gid);
-extern gid_t getgid(void);
-extern int setegid(gid_t __gid);
-extern gid_t getegid(void);
-extern int getgroups(int __size, gid_t* __list);
-extern int setgroups(size_t __size, const gid_t* __list);
-extern int setreuid(uid_t __ruid, uid_t __euid);
-extern int setregid(gid_t __rgid, gid_t __egid);
-extern int setresuid(uid_t __ruid, uid_t __euid, uid_t __suid);
-extern int setresgid(gid_t __rgid, gid_t __egid, gid_t __sgid);
-extern int getresuid(uid_t* __ruid, uid_t* __euid, uid_t* __suid);
-extern int getresgid(gid_t* __rgid, gid_t* __egid, gid_t* __sgid);
-extern char* getlogin(void);
+int setuid(uid_t __uid);
+uid_t getuid(void);
+int seteuid(uid_t __uid);
+uid_t geteuid(void);
+int setgid(gid_t __gid);
+gid_t getgid(void);
+int setegid(gid_t __gid);
+gid_t getegid(void);
+int getgroups(int __size, gid_t* __list);
+int setgroups(size_t __size, const gid_t* __list);
+int setreuid(uid_t __ruid, uid_t __euid);
+int setregid(gid_t __rgid, gid_t __egid);
+int setresuid(uid_t __ruid, uid_t __euid, uid_t __suid);
+int setresgid(gid_t __rgid, gid_t __egid, gid_t __sgid);
+int getresuid(uid_t* __ruid, uid_t* __euid, uid_t* __suid);
+int getresgid(gid_t* __rgid, gid_t* __egid, gid_t* __sgid);
+char* getlogin(void);
 
-extern long fpathconf(int __fd, int __name);
-extern long pathconf(const char* __path, int __name);
+long fpathconf(int __fd, int __name);
+long pathconf(const char* __path, int __name);
 
-extern int access(const char* __path, int __mode);
-extern int faccessat(int __dirfd, const char* __path, int __mode, int __flags)
-  __INTRODUCED_IN(21);
-extern int link(const char* __oldpath, const char* __newpath);
-extern int linkat(int __olddirfd, const char* __oldpath, int __newdirfd,
-                  const char* __newpath, int __flags) __INTRODUCED_IN(21);
-extern int unlink(const char* __path);
-extern int unlinkat(int __dirfd, const char* __path, int __flags);
-extern int chdir(const char* __path);
-extern int fchdir(int __fd);
-extern int rmdir(const char* __path);
-extern int pipe(int* __pipefd);
+int access(const char* __path, int __mode);
+int faccessat(int __dirfd, const char* __path, int __mode, int __flags) __INTRODUCED_IN(16);
+int link(const char* __oldpath, const char* __newpath);
+int linkat(int __olddirfd, const char* __oldpath, int __newdirfd,
+           const char* __newpath, int __flags) __INTRODUCED_IN(21);
+int unlink(const char* __path);
+int unlinkat(int __dirfd, const char* __path, int __flags);
+int chdir(const char* __path);
+int fchdir(int __fd);
+int rmdir(const char* __path);
+int pipe(int* __pipefd);
 #if defined(__USE_GNU)
-extern int pipe2(int* __pipefd, int __flags) __INTRODUCED_IN(9);
+int pipe2(int* __pipefd, int __flags) __INTRODUCED_IN(9);
 #endif
-extern int chroot(const char* __path);
-extern int symlink(const char* __oldpath, const char* __newpath);
-extern int symlinkat(const char* __oldpath, int __newdirfd,
-                     const char* __newpath) __INTRODUCED_IN(21);
-extern ssize_t readlink(const char* __path, char* __buf, size_t __bufsiz);
-extern ssize_t readlinkat(int __dirfd, const char* __path, char* __buf,
-                          size_t __bufsiz) __INTRODUCED_IN(21);
-extern int chown(const char* __path, uid_t __owner, gid_t __group);
-extern int fchown(int __fd, uid_t __owner, gid_t __group);
-extern int fchownat(int __dirfd, const char* __path, uid_t __owner,
-                    gid_t __group, int __flags);
-extern int lchown(const char* __path, uid_t __owner, gid_t __group);
-extern char* getcwd(char* __buf, size_t __size);
+int chroot(const char* __path);
+int symlink(const char* __oldpath, const char* __newpath);
+int symlinkat(const char* __oldpath, int __newdirfd, const char* __newpath) __INTRODUCED_IN(21);
+ssize_t readlink(const char* __path, char* __buf, size_t __bufsiz);
+ssize_t readlinkat(int __dirfd, const char* __path, char* __buf,
+                   size_t __bufsiz) __INTRODUCED_IN(21);
+int chown(const char* __path, uid_t __owner, gid_t __group);
+int fchown(int __fd, uid_t __owner, gid_t __group);
+int fchownat(int __dirfd, const char* __path, uid_t __owner, gid_t __group, int __flags);
+int lchown(const char* __path, uid_t __owner, gid_t __group);
+char* getcwd(char* __buf, size_t __size);
 
-extern int sync(void);
+int sync(void);
 
-extern int close(int __fd);
+int close(int __fd);
 
-extern ssize_t read(int __fd, void* __buf, size_t __count);
-extern ssize_t write(int __fd, const void* __buf, size_t __count);
+ssize_t read(int __fd, void* __buf, size_t __count);
+ssize_t write(int __fd, const void* __buf, size_t __count);
 
-extern int dup(int __oldfd);
-extern int dup2(int __oldfd, int __newfd);
-extern int dup3(int __oldfd, int __newfd, int __flags) __INTRODUCED_IN(21);
-extern int fcntl(int __fd, int __cmd, ...);
-extern int ioctl(int __fd, int __request, ...);
-extern int fsync(int __fd);
-extern int fdatasync(int __fd) __INTRODUCED_IN(9);
+int dup(int __oldfd);
+int dup2(int __oldfd, int __newfd);
+int dup3(int __oldfd, int __newfd, int __flags) __INTRODUCED_IN(21);
+int fsync(int __fd);
+int fdatasync(int __fd) __INTRODUCED_IN(9);
 
 #if defined(__USE_FILE_OFFSET64)
-extern off_t lseek(int __fd, off_t __offset, int __whence) __RENAME(lseek64);
+off_t lseek(int __fd, off_t __offset, int __whence) __RENAME(lseek64);
 #else
-extern off_t lseek(int __fd, off_t __offset, int __whence);
+off_t lseek(int __fd, off_t __offset, int __whence);
 #endif
 
-extern off64_t lseek64(int __fd, off64_t __offset, int __whence);
+off64_t lseek64(int __fd, off64_t __offset, int __whence);
 
 #if defined(__USE_FILE_OFFSET64) && __ANDROID_API__ >= 21
-extern int truncate(const char* __path, off_t __length) __RENAME(truncate64);
-extern ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset)
-  __RENAME(pread64);
-extern ssize_t pwrite(int __fd, const void* __buf, size_t __count,
-                      off_t __offset) __RENAME(pwrite64);
-extern int ftruncate(int __fd, off_t __length) __RENAME(ftruncate64);
+int truncate(const char* __path, off_t __length) __RENAME(truncate64) __INTRODUCED_IN(21);
+ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset) __RENAME(pread64)
+  __INTRODUCED_IN(12);
+ssize_t pwrite(int __fd, const void* __buf, size_t __count, off_t __offset)
+  __RENAME(pwrite64) __INTRODUCED_IN(12);
+int ftruncate(int __fd, off_t __length) __RENAME(ftruncate64) __INTRODUCED_IN(12);
 #else
-extern int truncate(const char* __path, off_t __length);
-extern ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset);
-extern ssize_t pwrite(int __fd, const void* __buf, size_t __count,
-                      off_t __offset);
-extern int ftruncate(int __fd, off_t __length);
+int truncate(const char* __path, off_t __length);
+ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset);
+ssize_t pwrite(int __fd, const void* __buf, size_t __count, off_t __offset);
+int ftruncate(int __fd, off_t __length);
 #endif
 
-extern int truncate64(const char* __path, off64_t __length) __INTRODUCED_IN(21);
-extern ssize_t pread64(int __fd, void* __buf, size_t __count, off64_t __offset) __INTRODUCED_IN(21);
-extern ssize_t pwrite64(int __fd, const void* __buf, size_t __count,
-                        off64_t __offset) __INTRODUCED_IN(21);
-extern int ftruncate64(int __fd, off64_t __length) __INTRODUCED_IN(21);
+int truncate64(const char* __path, off64_t __length) __INTRODUCED_IN(21);
+ssize_t pread64(int __fd, void* __buf, size_t __count, off64_t __offset) __INTRODUCED_IN(12);
+ssize_t pwrite64(int __fd, const void* __buf, size_t __count, off64_t __offset)
+  __INTRODUCED_IN(12);
+int ftruncate64(int __fd, off64_t __length) __INTRODUCED_IN(12);
 
-extern int pause(void);
-extern unsigned int alarm(unsigned int __seconds);
-extern unsigned int sleep(unsigned int __seconds);
-extern int usleep(useconds_t __usec);
+int pause(void);
+unsigned int alarm(unsigned int __seconds);
+unsigned int sleep(unsigned int __seconds);
+int usleep(useconds_t __usec);
 
 int gethostname(char* __name, size_t __len);
-int sethostname(const char* __name, size_t __len);
+int sethostname(const char* __name, size_t __len) __INTRODUCED_IN(23);
 
-extern void* __brk(void* __addr);
-extern int brk(void* __addr);
-extern void* sbrk(ptrdiff_t __increment);
+int brk(void* __addr);
+void* sbrk(ptrdiff_t __increment);
 
-extern int getopt(int __argc, char* const* __argv, const char* __argstring);
-extern char* optarg;
-extern int optind, opterr, optopt;
+int isatty(int __fd);
+char* ttyname(int __fd);
+int ttyname_r(int __fd, char* __buf, size_t __buflen) __INTRODUCED_IN(8);
 
-extern int isatty(int __fd);
-extern char* ttyname(int __fd);
-extern int ttyname_r(int __fd, char* __buf, size_t __buflen) __INTRODUCED_IN(8);
-
-extern int acct(const char* __filepath);
-
-long sysconf(int __name);
+int acct(const char* __filepath);
 
 #if __ANDROID_API__ >= 21
-int getpagesize(void);
+int getpagesize(void) __INTRODUCED_IN(21);
 #else
 __inline__ int getpagesize(void) {
   return sysconf(_SC_PAGESIZE);
@@ -229,15 +218,15 @@
 
 long syscall(long __number, ...);
 
-extern int daemon(int __nochdir, int __noclose);
+int daemon(int __nochdir, int __noclose);
 
 #if defined(__arm__) || (defined(__mips__) && !defined(__LP64__))
-extern int cacheflush(long __addr, long __nbytes, long __cache);
+int cacheflush(long __addr, long __nbytes, long __cache);
     /* __attribute__((deprecated("use __builtin___clear_cache instead"))); */
 #endif
 
-extern pid_t tcgetpgrp(int __fd);
-extern int tcsetpgrp(int __fd, pid_t __pid);
+pid_t tcgetpgrp(int __fd);
+int tcsetpgrp(int __fd, pid_t __pid);
 
 /* Used to retry syscalls that can return EINTR. */
 #define TEMP_FAILURE_RETRY(exp) ({         \
@@ -248,52 +237,56 @@
     _rc; })
 
 /* TODO(unified-headers): Factor out all the FORTIFY features. */
-extern char* __getcwd_chk(char*, size_t, size_t);
+char* __getcwd_chk(char*, size_t, size_t) __INTRODUCED_IN(24);
 __errordecl(__getcwd_dest_size_error, "getcwd called with size bigger than destination");
-extern char* __getcwd_real(char*, size_t) __RENAME(getcwd);
+char* __getcwd_real(char*, size_t) __RENAME(getcwd);
 
-extern ssize_t __pread_chk(int, void*, size_t, off_t, size_t);
+ssize_t __pread_chk(int, void*, size_t, off_t, size_t) __INTRODUCED_IN(23);
 __errordecl(__pread_dest_size_error, "pread called with size bigger than destination");
 __errordecl(__pread_count_toobig_error, "pread called with count > SSIZE_MAX");
-extern ssize_t __pread_real(int, void*, size_t, off_t) __RENAME(pread);
+ssize_t __pread_real(int, void*, size_t, off_t) __RENAME(pread);
 
-extern ssize_t __pread64_chk(int, void*, size_t, off64_t, size_t);
+ssize_t __pread64_chk(int, void*, size_t, off64_t, size_t) __INTRODUCED_IN(23);
 __errordecl(__pread64_dest_size_error, "pread64 called with size bigger than destination");
 __errordecl(__pread64_count_toobig_error, "pread64 called with count > SSIZE_MAX");
-extern ssize_t __pread64_real(int, void*, size_t, off64_t) __RENAME(pread64);
+ssize_t __pread64_real(int, void*, size_t, off64_t) __RENAME(pread64) __INTRODUCED_IN(12);
 
-extern ssize_t __pwrite_chk(int, const void*, size_t, off_t, size_t);
+ssize_t __pwrite_chk(int, const void*, size_t, off_t, size_t) __INTRODUCED_IN(24);
 __errordecl(__pwrite_dest_size_error, "pwrite called with size bigger than destination");
 __errordecl(__pwrite_count_toobig_error, "pwrite called with count > SSIZE_MAX");
-extern ssize_t __pwrite_real(int, const void*, size_t, off_t) __RENAME(pwrite);
+ssize_t __pwrite_real(int, const void*, size_t, off_t) __RENAME(pwrite);
 
-extern ssize_t __pwrite64_chk(int, const void*, size_t, off64_t, size_t);
+ssize_t __pwrite64_chk(int, const void*, size_t, off64_t, size_t) __INTRODUCED_IN(24);
 __errordecl(__pwrite64_dest_size_error, "pwrite64 called with size bigger than destination");
 __errordecl(__pwrite64_count_toobig_error, "pwrite64 called with count > SSIZE_MAX");
-extern ssize_t __pwrite64_real(int, const void*, size_t, off64_t) __RENAME(pwrite64);
+ssize_t __pwrite64_real(int, const void*, size_t, off64_t) __RENAME(pwrite64) __INTRODUCED_IN(12);
 
-extern ssize_t __read_chk(int, void*, size_t, size_t);
+ssize_t __read_chk(int, void*, size_t, size_t) __INTRODUCED_IN(21);
 __errordecl(__read_dest_size_error, "read called with size bigger than destination");
 __errordecl(__read_count_toobig_error, "read called with count > SSIZE_MAX");
-extern ssize_t __read_real(int, void*, size_t) __RENAME(read);
+ssize_t __read_real(int, void*, size_t) __RENAME(read);
 
-extern ssize_t __write_chk(int, const void*, size_t, size_t);
+ssize_t __write_chk(int, const void*, size_t, size_t) __INTRODUCED_IN(24);
 __errordecl(__write_dest_size_error, "write called with size bigger than destination");
 __errordecl(__write_count_toobig_error, "write called with count > SSIZE_MAX");
-extern ssize_t __write_real(int, const void*, size_t) __RENAME(write);
+ssize_t __write_real(int, const void*, size_t) __RENAME(write);
 
-extern ssize_t __readlink_chk(const char*, char*, size_t, size_t);
+ssize_t __readlink_chk(const char*, char*, size_t, size_t) __INTRODUCED_IN(23);
 __errordecl(__readlink_dest_size_error, "readlink called with size bigger than destination");
 __errordecl(__readlink_size_toobig_error, "readlink called with size > SSIZE_MAX");
-extern ssize_t __readlink_real(const char*, char*, size_t) __RENAME(readlink);
+ssize_t __readlink_real(const char*, char*, size_t) __RENAME(readlink);
 
-extern ssize_t __readlinkat_chk(int dirfd, const char*, char*, size_t, size_t);
+ssize_t __readlinkat_chk(int dirfd, const char*, char*, size_t, size_t) __INTRODUCED_IN(23);
 __errordecl(__readlinkat_dest_size_error, "readlinkat called with size bigger than destination");
 __errordecl(__readlinkat_size_toobig_error, "readlinkat called with size > SSIZE_MAX");
-extern ssize_t __readlinkat_real(int dirfd, const char*, char*, size_t) __RENAME(readlinkat);
+ssize_t __readlinkat_real(int dirfd, const char*, char*, size_t) __RENAME(readlinkat) __INTRODUCED_IN(21);
+
+int getdomainname(char*, size_t) __INTRODUCED_IN_FUTURE;
+int setdomainname(const char*, size_t) __INTRODUCED_IN_FUTURE;
 
 #if defined(__BIONIC_FORTIFY)
 
+#if __ANDROID_API__ >= 24
 __BIONIC_FORTIFY_INLINE
 char* getcwd(char* buf, size_t size) {
     size_t bos = __bos(buf);
@@ -324,6 +317,7 @@
 
     return __getcwd_chk(buf, size, bos);
 }
+#endif /* __ANDROID_API__ >= 24 */
 
 #if defined(__USE_FILE_OFFSET64)
 #define __PREAD_PREFIX(x) __pread64_ ## x
@@ -331,6 +325,7 @@
 #define __PREAD_PREFIX(x) __pread_ ## x
 #endif
 
+#if __ANDROID_API__ >= 23
 __BIONIC_FORTIFY_INLINE
 ssize_t pread(int fd, void* buf, size_t count, off_t offset) {
     size_t bos = __bos0(buf);
@@ -380,6 +375,7 @@
 
     return __pread64_chk(fd, buf, count, offset, bos);
 }
+#endif /* __ANDROID_API__ >= 23 */
 
 #if defined(__USE_FILE_OFFSET64)
 #define __PWRITE_PREFIX(x) __pwrite64_ ## x
@@ -387,6 +383,7 @@
 #define __PWRITE_PREFIX(x) __pwrite_ ## x
 #endif
 
+#if __ANDROID_API__ >= 24
 __BIONIC_FORTIFY_INLINE
 ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset) {
     size_t bos = __bos0(buf);
@@ -436,7 +433,9 @@
 
     return __pwrite64_chk(fd, buf, count, offset, bos);
 }
+#endif /* __ANDROID_API__ >= 24 */
 
+#if __ANDROID_API__ >= 21
 __BIONIC_FORTIFY_INLINE
 ssize_t read(int fd, void* buf, size_t count) {
     size_t bos = __bos0(buf);
@@ -461,7 +460,9 @@
 
     return __read_chk(fd, buf, count, bos);
 }
+#endif /* __ANDROID_API__ >= 21 */
 
+#if __ANDROID_API__ >= 24
 __BIONIC_FORTIFY_INLINE
 ssize_t write(int fd, const void* buf, size_t count) {
     size_t bos = __bos0(buf);
@@ -488,6 +489,7 @@
 
     return __write_chk(fd, buf, count, bos);
 }
+#endif /* __ANDROID_API__ >= 24 */
 
 __BIONIC_FORTIFY_INLINE
 ssize_t readlink(const char* path, char* buf, size_t size) {
diff --git a/libc/include/util.h b/libc/include/util.h
deleted file mode 100644
index e69de29..0000000
--- a/libc/include/util.h
+++ /dev/null
diff --git a/libc/include/utime.h b/libc/include/utime.h
index 3d72da4..9783859 100644
--- a/libc/include/utime.h
+++ b/libc/include/utime.h
@@ -35,7 +35,7 @@
 
 __BEGIN_DECLS
 
-extern int utime(const char*, const struct utimbuf*);
+int utime(const char*, const struct utimbuf*);
 
 __END_DECLS
 
diff --git a/libc/include/utmp.h b/libc/include/utmp.h
index c6f22a5..62e8d59 100644
--- a/libc/include/utmp.h
+++ b/libc/include/utmp.h
@@ -101,7 +101,7 @@
 struct utmp* getutent(void);
 void endutent(void);
 
-int login_tty(int);
+int login_tty(int) __INTRODUCED_IN(23);
 
 __END_DECLS
 
diff --git a/libc/include/wchar.h b/libc/include/wchar.h
index 0a94cee..ee75148 100644
--- a/libc/include/wchar.h
+++ b/libc/include/wchar.h
@@ -36,18 +36,12 @@
 #include <time.h>
 #include <xlocale.h>
 
+#include <bits/mbstate_t.h>
 #include <bits/wchar_limits.h>
+#include <bits/wctype.h>
 
 __BEGIN_DECLS
 
-typedef __WINT_TYPE__  wint_t;
-typedef struct {
-  uint8_t __seq[4];
-#ifdef __LP64__
-  char __reserved[4];
-#endif
-} mbstate_t;
-
 enum {
     WC_TYPE_INVALID = 0,
     WC_TYPE_ALNUM,
@@ -65,119 +59,92 @@
     WC_TYPE_MAX
 };
 
-typedef long wctype_t;
-
-#define  WEOF        ((wint_t)(-1))
-
-extern wint_t            btowc(int);
-extern int               fwprintf(FILE *, const wchar_t *, ...);
-extern int               fwscanf(FILE *, const wchar_t *, ...);
-extern int               iswalnum(wint_t);
-extern int               iswalpha(wint_t);
-extern int               iswblank(wint_t);
-extern int               iswcntrl(wint_t);
-extern int               iswdigit(wint_t);
-extern int               iswgraph(wint_t);
-extern int               iswlower(wint_t);
-extern int               iswprint(wint_t);
-extern int               iswpunct(wint_t);
-extern int               iswspace(wint_t);
-extern int               iswupper(wint_t);
-extern int               iswxdigit(wint_t);
-extern int               iswctype(wint_t, wctype_t);
-extern wint_t            fgetwc(FILE *);
-extern wchar_t          *fgetws(wchar_t *, int, FILE *);
-extern wint_t            fputwc(wchar_t, FILE *);
-extern int               fputws(const wchar_t *, FILE *);
-extern int               fwide(FILE *, int);
-extern wint_t            getwc(FILE *);
-extern wint_t            getwchar(void);
-extern int               mbsinit(const mbstate_t *);
-extern size_t            mbrlen(const char *, size_t, mbstate_t *);
-extern size_t            mbrtowc(wchar_t *, const char *, size_t, mbstate_t *);
-extern size_t mbsrtowcs(wchar_t*, const char**, size_t, mbstate_t*);
-extern size_t mbsnrtowcs(wchar_t*, const char**, size_t, size_t, mbstate_t*);
-extern size_t            mbstowcs(wchar_t *, const char *, size_t);
-extern wint_t            putwc(wchar_t, FILE *);
-extern wint_t            putwchar(wchar_t);
-extern int               swprintf(wchar_t *, size_t, const wchar_t *, ...);
-extern int               swscanf(const wchar_t *, const wchar_t *, ...);
-extern wint_t            towlower(wint_t);
-extern wint_t            towupper(wint_t);
-extern wint_t            ungetwc(wint_t, FILE *);
-extern int vfwprintf(FILE*, const wchar_t*, va_list);
-extern int vfwscanf(FILE*, const wchar_t*, va_list);
-extern int vswprintf(wchar_t*, size_t, const wchar_t*, va_list);
-extern int vswscanf(const wchar_t*, const wchar_t*, va_list);
-extern int vwprintf(const wchar_t*, va_list);
-extern int vwscanf(const wchar_t*, va_list);
-extern wchar_t* wcpcpy (wchar_t*, const wchar_t *);
-extern wchar_t* wcpncpy (wchar_t*, const wchar_t *, size_t);
-extern size_t            wcrtomb(char *, wchar_t, mbstate_t *);
-extern int               wcscasecmp(const wchar_t *, const wchar_t *);
-extern int               wcscasecmp_l(const wchar_t *, const wchar_t *, locale_t);
-extern wchar_t          *wcscat(wchar_t *, const wchar_t *);
-extern wchar_t          *wcschr(const wchar_t *, wchar_t);
-extern int               wcscmp(const wchar_t *, const wchar_t *);
-extern int               wcscoll(const wchar_t *, const wchar_t *);
-extern wchar_t          *wcscpy(wchar_t *, const wchar_t *);
-extern size_t            wcscspn(const wchar_t *, const wchar_t *);
-extern size_t            wcsftime(wchar_t *, size_t, const wchar_t *, const struct tm *) __LIBC_ABI_PUBLIC__;
-extern size_t            wcslen(const wchar_t *);
-extern int               wcsncasecmp(const wchar_t *, const wchar_t *, size_t);
-extern int               wcsncasecmp_l(const wchar_t *, const wchar_t *, size_t, locale_t);
-extern wchar_t          *wcsncat(wchar_t *, const wchar_t *, size_t);
-extern int               wcsncmp(const wchar_t *, const wchar_t *, size_t);
-extern wchar_t          *wcsncpy(wchar_t *, const wchar_t *, size_t);
-extern size_t wcsnrtombs(char*, const wchar_t**, size_t, size_t, mbstate_t*);
-extern wchar_t          *wcspbrk(const wchar_t *, const wchar_t *);
-extern wchar_t          *wcsrchr(const wchar_t *, wchar_t);
-extern size_t wcsrtombs(char*, const wchar_t**, size_t, mbstate_t*);
-extern size_t            wcsspn(const wchar_t *, const wchar_t *);
-extern wchar_t          *wcsstr(const wchar_t *, const wchar_t *);
-extern double wcstod(const wchar_t*, wchar_t**);
-extern float wcstof(const wchar_t*, wchar_t**);
-extern wchar_t* wcstok(wchar_t*, const wchar_t*, wchar_t**);
-extern long wcstol(const wchar_t*, wchar_t**, int);
-extern long long wcstoll(const wchar_t*, wchar_t**, int);
-extern long double wcstold(const wchar_t*, wchar_t**);
-extern unsigned long wcstoul(const wchar_t*, wchar_t**, int);
-extern unsigned long long wcstoull(const wchar_t*, wchar_t**, int);
-extern int               wcswidth(const wchar_t *, size_t);
-extern size_t            wcsxfrm(wchar_t *, const wchar_t *, size_t);
-extern int               wctob(wint_t);
-extern wctype_t          wctype(const char *);
-extern int               wcwidth(wchar_t);
-extern wchar_t          *wmemchr(const wchar_t *, wchar_t, size_t);
-extern int               wmemcmp(const wchar_t *, const wchar_t *, size_t);
-extern wchar_t          *wmemcpy(wchar_t *, const wchar_t *, size_t);
+wint_t            btowc(int);
+int               fwprintf(FILE *, const wchar_t *, ...);
+int               fwscanf(FILE *, const wchar_t *, ...);
+wint_t            fgetwc(FILE *);
+wchar_t          *fgetws(wchar_t *, int, FILE *);
+wint_t            fputwc(wchar_t, FILE *);
+int               fputws(const wchar_t *, FILE *);
+int               fwide(FILE *, int);
+wint_t            getwc(FILE *);
+wint_t            getwchar(void);
+int               mbsinit(const mbstate_t *);
+size_t            mbrlen(const char *, size_t, mbstate_t *);
+size_t            mbrtowc(wchar_t *, const char *, size_t, mbstate_t *);
+size_t mbsrtowcs(wchar_t*, const char**, size_t, mbstate_t*);
+size_t mbsnrtowcs(wchar_t*, const char**, size_t, size_t, mbstate_t*) __INTRODUCED_IN(21);
+wint_t            putwc(wchar_t, FILE *);
+wint_t            putwchar(wchar_t);
+int               swprintf(wchar_t *, size_t, const wchar_t *, ...);
+int               swscanf(const wchar_t *, const wchar_t *, ...);
+wint_t            ungetwc(wint_t, FILE *);
+int vfwprintf(FILE*, const wchar_t*, va_list);
+int vfwscanf(FILE*, const wchar_t*, va_list) __INTRODUCED_IN(21);
+int vswprintf(wchar_t*, size_t, const wchar_t*, va_list);
+int vswscanf(const wchar_t*, const wchar_t*, va_list) __INTRODUCED_IN(21);
+int vwprintf(const wchar_t*, va_list);
+int vwscanf(const wchar_t*, va_list) __INTRODUCED_IN(21);
+wchar_t* wcpcpy (wchar_t*, const wchar_t *);
+wchar_t* wcpncpy (wchar_t*, const wchar_t *, size_t);
+size_t            wcrtomb(char *, wchar_t, mbstate_t *);
+int               wcscasecmp(const wchar_t *, const wchar_t *);
+int wcscasecmp_l(const wchar_t*, const wchar_t*, locale_t) __INTRODUCED_IN(23);
+wchar_t          *wcscat(wchar_t *, const wchar_t *);
+wchar_t          *wcschr(const wchar_t *, wchar_t);
+int               wcscmp(const wchar_t *, const wchar_t *);
+int               wcscoll(const wchar_t *, const wchar_t *);
+wchar_t          *wcscpy(wchar_t *, const wchar_t *);
+size_t            wcscspn(const wchar_t *, const wchar_t *);
+size_t            wcsftime(wchar_t *, size_t, const wchar_t *, const struct tm *);
+size_t            wcslen(const wchar_t *);
+int               wcsncasecmp(const wchar_t *, const wchar_t *, size_t);
+int wcsncasecmp_l(const wchar_t*, const wchar_t*, size_t, locale_t) __INTRODUCED_IN(23);
+wchar_t          *wcsncat(wchar_t *, const wchar_t *, size_t);
+int               wcsncmp(const wchar_t *, const wchar_t *, size_t);
+wchar_t          *wcsncpy(wchar_t *, const wchar_t *, size_t);
+size_t wcsnrtombs(char*, const wchar_t**, size_t, size_t, mbstate_t*) __INTRODUCED_IN(21);
+wchar_t          *wcspbrk(const wchar_t *, const wchar_t *);
+wchar_t          *wcsrchr(const wchar_t *, wchar_t);
+size_t wcsrtombs(char*, const wchar_t**, size_t, mbstate_t*);
+size_t            wcsspn(const wchar_t *, const wchar_t *);
+wchar_t          *wcsstr(const wchar_t *, const wchar_t *);
+double wcstod(const wchar_t*, wchar_t**);
+float wcstof(const wchar_t*, wchar_t**) __INTRODUCED_IN(21);
+wchar_t* wcstok(wchar_t*, const wchar_t*, wchar_t**);
+long wcstol(const wchar_t*, wchar_t**, int);
+long long wcstoll(const wchar_t*, wchar_t**, int) __INTRODUCED_IN(21);
+long double wcstold(const wchar_t*, wchar_t**) __INTRODUCED_IN(21);
+unsigned long wcstoul(const wchar_t*, wchar_t**, int);
+unsigned long long wcstoull(const wchar_t*, wchar_t**, int) __INTRODUCED_IN(21);
+int               wcswidth(const wchar_t *, size_t);
+size_t            wcsxfrm(wchar_t *, const wchar_t *, size_t);
+int               wctob(wint_t);
+int               wcwidth(wchar_t);
+wchar_t          *wmemchr(const wchar_t *, wchar_t, size_t);
+int               wmemcmp(const wchar_t *, const wchar_t *, size_t);
+wchar_t          *wmemcpy(wchar_t *, const wchar_t *, size_t);
 #if defined(__USE_GNU)
-extern wchar_t          *wmempcpy(wchar_t *, const wchar_t *, size_t);
+wchar_t* wmempcpy(wchar_t*, const wchar_t*, size_t) __INTRODUCED_IN(23);
 #endif
-extern wchar_t          *wmemmove(wchar_t *, const wchar_t *, size_t);
-extern wchar_t          *wmemset(wchar_t *, wchar_t, size_t);
-extern int               wprintf(const wchar_t *, ...);
-extern int               wscanf(const wchar_t *, ...);
+wchar_t          *wmemmove(wchar_t *, const wchar_t *, size_t);
+wchar_t          *wmemset(wchar_t *, wchar_t, size_t);
+int               wprintf(const wchar_t *, ...);
+int               wscanf(const wchar_t *, ...);
 
-extern long long          wcstoll_l(const wchar_t *, wchar_t **, int, locale_t);
-extern unsigned long long wcstoull_l(const wchar_t *, wchar_t **, int, locale_t);
-extern long double        wcstold_l(const wchar_t *, wchar_t **, locale_t );
+long long wcstoll_l(const wchar_t*, wchar_t**, int, locale_t) __INTRODUCED_IN(21);
+unsigned long long wcstoull_l(const wchar_t*, wchar_t**, int, locale_t) __INTRODUCED_IN(21);
+long double wcstold_l(const wchar_t*, wchar_t**, locale_t) __INTRODUCED_IN(21);
 
-extern int    wcscoll_l(const wchar_t *, const wchar_t *, locale_t);
-extern size_t wcsxfrm_l(wchar_t *, const wchar_t *, size_t, locale_t);
+int wcscoll_l(const wchar_t*, const wchar_t*, locale_t) __INTRODUCED_IN(21);
+size_t wcsxfrm_l(wchar_t*, const wchar_t*, size_t, locale_t) __INTRODUCED_IN(21);
 
-extern size_t wcslcat(wchar_t*, const wchar_t*, size_t);
-extern size_t wcslcpy(wchar_t*, const wchar_t*, size_t);
+size_t wcslcat(wchar_t*, const wchar_t*, size_t);
+size_t wcslcpy(wchar_t*, const wchar_t*, size_t);
 
-typedef void *wctrans_t;
-extern wint_t towctrans(wint_t, wctrans_t);
-extern wctrans_t wctrans(const char*);
-
-#if __POSIX_VISIBLE >= 200809
-FILE* open_wmemstream(wchar_t**, size_t*);
+FILE* open_wmemstream(wchar_t**, size_t*) __INTRODUCED_IN(23);
 wchar_t* wcsdup(const wchar_t*);
 size_t wcsnlen(const wchar_t*, size_t);
-#endif
 
 __END_DECLS
 
diff --git a/libc/include/wctype.h b/libc/include/wctype.h
index 1a4a05e..1c9731f 100644
--- a/libc/include/wctype.h
+++ b/libc/include/wctype.h
@@ -29,27 +29,33 @@
 #ifndef _WCTYPE_H_
 #define _WCTYPE_H_
 
-#include <wchar.h>
+#include <bits/wctype.h>
+#include <sys/cdefs.h>
+#include <xlocale.h>
 
 __BEGIN_DECLS
 
-extern int iswalnum_l(wint_t, locale_t);
-extern int iswalpha_l(wint_t, locale_t);
-extern int iswblank_l(wint_t, locale_t);
-extern int iswcntrl_l(wint_t, locale_t);
-extern int iswdigit_l(wint_t, locale_t);
-extern int iswgraph_l(wint_t, locale_t);
-extern int iswlower_l(wint_t, locale_t);
-extern int iswprint_l(wint_t, locale_t);
-extern int iswpunct_l(wint_t, locale_t);
-extern int iswspace_l(wint_t, locale_t);
-extern int iswupper_l(wint_t, locale_t);
-extern int iswxdigit_l(wint_t, locale_t);
-extern int towlower_l(int, locale_t);
-extern int towupper_l(int, locale_t);
+int iswalnum_l(wint_t, locale_t) __INTRODUCED_IN(21);
+int iswalpha_l(wint_t, locale_t) __INTRODUCED_IN(21);
+int iswblank_l(wint_t, locale_t) __INTRODUCED_IN(21);
+int iswcntrl_l(wint_t, locale_t) __INTRODUCED_IN(21);
+int iswdigit_l(wint_t, locale_t) __INTRODUCED_IN(21);
+int iswgraph_l(wint_t, locale_t) __INTRODUCED_IN(21);
+int iswlower_l(wint_t, locale_t) __INTRODUCED_IN(21);
+int iswprint_l(wint_t, locale_t) __INTRODUCED_IN(21);
+int iswpunct_l(wint_t, locale_t) __INTRODUCED_IN(21);
+int iswspace_l(wint_t, locale_t) __INTRODUCED_IN(21);
+int iswupper_l(wint_t, locale_t) __INTRODUCED_IN(21);
+int iswxdigit_l(wint_t, locale_t) __INTRODUCED_IN(21);
 
-extern int iswctype_l(wint_t, wctype_t, locale_t);
-extern wctype_t wctype_l(const char*, locale_t);
+wint_t towlower_l(int, locale_t) __INTRODUCED_IN(21);
+wint_t towupper_l(int, locale_t) __INTRODUCED_IN(21);
+
+wint_t towctrans_l(wint_t, wctrans_t, locale_t) __INTRODUCED_IN_FUTURE;
+wctrans_t wctrans_l(const char*, locale_t) __INTRODUCED_IN_FUTURE;
+
+wctype_t wctype_l(const char*, locale_t) __INTRODUCED_IN(21);
+int iswctype_l(wint_t, wctype_t, locale_t) __INTRODUCED_IN(21);
 
 __END_DECLS
 
diff --git a/libc/include/xlocale.h b/libc/include/xlocale.h
index f7eb8f4..559d24d 100644
--- a/libc/include/xlocale.h
+++ b/libc/include/xlocale.h
@@ -29,6 +29,8 @@
 #ifndef _XLOCALE_H_
 #define _XLOCALE_H_
 
+#include <sys/cdefs.h>
+
 /* If we just use void* here, GCC exposes that in error messages. */
 struct __locale_t;
 typedef struct __locale_t* locale_t;
diff --git a/libc/kernel/README.TXT b/libc/kernel/README.TXT
index e7312ef..313dc0d 100644
--- a/libc/kernel/README.TXT
+++ b/libc/kernel/README.TXT
@@ -1,3 +1,6 @@
+Bionic Kernel Header Files
+==========================
+
 Bionic comes with a processed set of all of the uapi Linux kernel headers that
 can safely be included by userland applications and libraries.
 
@@ -43,19 +46,34 @@
     Automatically update all clean headers from the content of
     'external/kernel-headers/original'.
 
-
-HOW TO UPDATE THE HEADERS WHEN NEEDED:
-======================================
+How To Update The Headers
+=========================
 
 IMPORTANT IMPORTANT:
 
-  WHEN UPDATING THE HEADERS, ALWAYS CHECK THAT THE NEW CLEAN HEADERS DO
-  NOT BREAK THE KERNEL <-> USER ABI, FOR EXAMPLE BY CHANGING THE SIZE
-  OF A GIVEN TYPE. THIS TASK CANNOT BE EASILY AUTOMATED AT THE MOMENT
+WHEN UPDATING THE HEADERS, ALWAYS CHECK THAT THE NEW CLEAN HEADERS DO
+NOT BREAK THE KERNEL <-> USER ABI, FOR EXAMPLE BY CHANGING THE SIZE
+OF A GIVEN TYPE. THIS TASK CANNOT BE EASILY AUTOMATED AT THE MOMENT.
 
-Grab the latest headers from the android kernel by running this command:
+Download the Linux kernel source code:
 
-  bionic/libc/kernel/tools/generate_uapi_headers.sh --download-kernel
+  > mkdir kernel_src
+  > cd kernel_src
+  kernel_src> git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
+
+Then checkout the stable tag for the new kernel headers to import:
+
+  kernel_src> cd linux-stable
+  kernel_src/linux-stable> git checkout tags/vXXX
+
+Before running the command to import the headers, make sure that you have
+done a lunch TARGET. The script uses a variable set by the lunch command
+to determine which directory to use as the destination directory.
+
+After running lunch, run this command to import the headers into the android
+source tree:
+
+  bionic/libc/kernel/tools/generate_uapi_headers.sh --use-kernel-dir kernel_src
 
 Next, run this command to copy the parsed files to bionic/libc/kernel/uapi:
 
diff --git a/libc/kernel/android/README.TXT b/libc/kernel/android/README.TXT
new file mode 100644
index 0000000..bc2efde
--- /dev/null
+++ b/libc/kernel/android/README.TXT
@@ -0,0 +1,17 @@
+The files under the uapi directory are android kernel uapi header files that
+exist in android kernels, but have not been upstreamed into the regular
+kernel.
+
+None of these files will get updated automatically, and are frozen at their
+current value.
+
+The files under the scsi directory are frozen copies of kernel scsi headers.
+Linux's scsi headers are a mix of userspace-facing and kernel-facing
+declarations that can't be directly used by userspace. The glibc
+maintainers manually copy-and-pasted these definitions into their own
+scsi headers and haven't substantially updated them in 15 years. The
+musl libc project has a similar set of definitions in its scsi headers.
+
+These files are actually maintained in external/kernel-headers/modified/scsi.
+Any modification should first be made there then copied into the scsi
+directory.
diff --git a/libc/kernel/android/scsi/scsi.h b/libc/kernel/android/scsi/scsi.h
new file mode 100644
index 0000000..bcbcffe
--- /dev/null
+++ b/libc/kernel/android/scsi/scsi.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef _SCSI_SCSI_H
+#define _SCSI_SCSI_H
+#include <linux/types.h>
+#include <scsi/scsi_proto.h>
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct ccs_modesel_head {
+  __u8 _r1;
+  __u8 medium;
+  __u8 _r2;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+  __u8 block_desc_length;
+  __u8 density;
+  __u8 number_blocks_hi;
+  __u8 number_blocks_med;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+  __u8 number_blocks_lo;
+  __u8 _r3;
+  __u8 block_length_hi;
+  __u8 block_length_med;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+  __u8 block_length_lo;
+};
+#define COMMAND_COMPLETE 0x00
+#define EXTENDED_MESSAGE 0x01
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define EXTENDED_MODIFY_DATA_POINTER 0x00
+#define EXTENDED_SDTR 0x01
+#define EXTENDED_EXTENDED_IDENTIFY 0x02
+#define EXTENDED_WDTR 0x03
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define EXTENDED_PPR 0x04
+#define EXTENDED_MODIFY_BIDI_DATA_PTR 0x05
+#define SAVE_POINTERS 0x02
+#define RESTORE_POINTERS 0x03
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define DISCONNECT 0x04
+#define INITIATOR_ERROR 0x05
+#define ABORT_TASK_SET 0x06
+#define MESSAGE_REJECT 0x07
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NOP 0x08
+#define MSG_PARITY_ERROR 0x09
+#define LINKED_CMD_COMPLETE 0x0a
+#define LINKED_FLG_CMD_COMPLETE 0x0b
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define TARGET_RESET 0x0c
+#define ABORT_TASK 0x0d
+#define CLEAR_TASK_SET 0x0e
+#define INITIATE_RECOVERY 0x0f
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define RELEASE_RECOVERY 0x10
+#define CLEAR_ACA 0x16
+#define LOGICAL_UNIT_RESET 0x17
+#define SIMPLE_QUEUE_TAG 0x20
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define HEAD_OF_QUEUE_TAG 0x21
+#define ORDERED_QUEUE_TAG 0x22
+#define IGNORE_WIDE_RESIDUE 0x23
+#define ACA 0x24
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define QAS_REQUEST 0x55
+#define BUS_DEVICE_RESET TARGET_RESET
+#define ABORT ABORT_TASK_SET
+#define SCSI_IOCTL_GET_IDLUN 0x5382
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SCSI_IOCTL_PROBE_HOST 0x5385
+#define SCSI_IOCTL_GET_BUS_NUMBER 0x5386
+#define SCSI_IOCTL_GET_PCI 0x5387
+#endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/common/scsi/scsi_ioctl.h b/libc/kernel/android/scsi/scsi_ioctl.h
similarity index 100%
rename from libc/kernel/common/scsi/scsi_ioctl.h
rename to libc/kernel/android/scsi/scsi_ioctl.h
diff --git a/libc/kernel/common/scsi/scsi.h b/libc/kernel/android/scsi/scsi_proto.h
similarity index 75%
rename from libc/kernel/common/scsi/scsi.h
rename to libc/kernel/android/scsi/scsi_proto.h
index 9e5edd7..acb18e7 100644
--- a/libc/kernel/common/scsi/scsi.h
+++ b/libc/kernel/android/scsi/scsi_proto.h
@@ -16,8 +16,8 @@
  ***
  ****************************************************************************
  ****************************************************************************/
-#ifndef _SCSI_SCSI_H
-#define _SCSI_SCSI_H
+#ifndef _SCSI_PROTO_H_
+#define _SCSI_PROTO_H_
 #include <linux/types.h>
 #define TEST_UNIT_READY 0x00
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
@@ -112,36 +112,41 @@
 #define EXCHANGE_MEDIUM 0xa6
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define READ_12 0xa8
+#define SERVICE_ACTION_OUT_12 0xa9
 #define WRITE_12 0xaa
 #define READ_MEDIA_SERIAL_NUMBER 0xab
-#define WRITE_VERIFY_12 0xae
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SERVICE_ACTION_IN_12 0xab
+#define WRITE_VERIFY_12 0xae
 #define VERIFY_12 0xaf
 #define SEARCH_HIGH_12 0xb0
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SEARCH_EQUAL_12 0xb1
 #define SEARCH_LOW_12 0xb2
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SECURITY_PROTOCOL_OUT 0xb5
 #define READ_ELEMENT_STATUS 0xb8
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SEND_VOLUME_TAG 0xb6
 #define WRITE_LONG_2 0xea
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define EXTENDED_COPY 0x83
 #define RECEIVE_COPY_RESULTS 0x84
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ACCESS_CONTROL_IN 0x86
 #define ACCESS_CONTROL_OUT 0x87
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define READ_16 0x88
 #define COMPARE_AND_WRITE 0x89
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define WRITE_16 0x8a
 #define READ_ATTRIBUTE 0x8c
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define WRITE_ATTRIBUTE 0x8d
 #define VERIFY_16 0x8f
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SYNCHRONIZE_CACHE_16 0x91
 #define WRITE_SAME_16 0x93
+#define SERVICE_ACTION_BIDIRECTIONAL 0x9d
+#define SERVICE_ACTION_IN_16 0x9e
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define SERVICE_ACTION_IN 0x9e
+#define SERVICE_ACTION_OUT_16 0x9f
 #define GOOD 0x00
 #define CHECK_CONDITION 0x01
 #define CONDITION_GOOD 0x02
@@ -194,68 +199,5 @@
 #define TYPE_ZBC 0x14
 #define TYPE_WLUN 0x1e
 #define TYPE_NO_LUN 0x7f
-struct ccs_modesel_head {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 _r1;
-  __u8 medium;
-  __u8 _r2;
-  __u8 block_desc_length;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 density;
-  __u8 number_blocks_hi;
-  __u8 number_blocks_med;
-  __u8 number_blocks_lo;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 _r3;
-  __u8 block_length_hi;
-  __u8 block_length_med;
-  __u8 block_length_lo;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-};
-#define COMMAND_COMPLETE 0x00
-#define EXTENDED_MESSAGE 0x01
-#define EXTENDED_MODIFY_DATA_POINTER 0x00
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define EXTENDED_SDTR 0x01
-#define EXTENDED_EXTENDED_IDENTIFY 0x02
-#define EXTENDED_WDTR 0x03
-#define EXTENDED_PPR 0x04
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define EXTENDED_MODIFY_BIDI_DATA_PTR 0x05
-#define SAVE_POINTERS 0x02
-#define RESTORE_POINTERS 0x03
-#define DISCONNECT 0x04
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define INITIATOR_ERROR 0x05
-#define ABORT_TASK_SET 0x06
-#define MESSAGE_REJECT 0x07
-#define NOP 0x08
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSG_PARITY_ERROR 0x09
-#define LINKED_CMD_COMPLETE 0x0a
-#define LINKED_FLG_CMD_COMPLETE 0x0b
-#define TARGET_RESET 0x0c
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define ABORT_TASK 0x0d
-#define CLEAR_TASK_SET 0x0e
-#define INITIATE_RECOVERY 0x0f
-#define RELEASE_RECOVERY 0x10
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define CLEAR_ACA 0x16
-#define LOGICAL_UNIT_RESET 0x17
-#define SIMPLE_QUEUE_TAG 0x20
-#define HEAD_OF_QUEUE_TAG 0x21
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define ORDERED_QUEUE_TAG 0x22
-#define IGNORE_WIDE_RESIDUE 0x23
-#define ACA 0x24
-#define QAS_REQUEST 0x55
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define BUS_DEVICE_RESET TARGET_RESET
-#define ABORT ABORT_TASK_SET
-#define SCSI_IOCTL_GET_IDLUN 0x5382
-#define SCSI_IOCTL_PROBE_HOST 0x5385
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define SCSI_IOCTL_GET_BUS_NUMBER 0x5386
-#define SCSI_IOCTL_GET_PCI 0x5387
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/common/scsi/sg.h b/libc/kernel/android/scsi/sg.h
similarity index 99%
rename from libc/kernel/common/scsi/sg.h
rename to libc/kernel/android/scsi/sg.h
index a38eccb..4472385 100644
--- a/libc/kernel/common/scsi/sg.h
+++ b/libc/kernel/android/scsi/sg.h
@@ -127,53 +127,54 @@
 #define SG_SCSI_RESET_HOST 3
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SG_SCSI_RESET_TARGET 4
+#define SG_SCSI_RESET_NO_ESCALATE 0x100
 #define SG_IO 0x2285
 #define SG_GET_REQUEST_TABLE 0x2286
-#define SG_SET_KEEP_ORPHAN 0x2287
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SG_SET_KEEP_ORPHAN 0x2287
 #define SG_GET_KEEP_ORPHAN 0x2288
 #define SG_GET_ACCESS_COUNT 0x2289
 #define SG_SCATTER_SZ (8 * 4096)
-#define SG_DEFAULT_RETRIES 0
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SG_DEFAULT_RETRIES 0
 #define SG_DEF_FORCE_LOW_DMA 0
 #define SG_DEF_FORCE_PACK_ID 0
 #define SG_DEF_KEEP_ORPHAN 0
-#define SG_DEF_RESERVED_SIZE SG_SCATTER_SZ
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SG_DEF_RESERVED_SIZE SG_SCATTER_SZ
 #define SG_MAX_QUEUE 16
 #define SG_BIG_BUFF SG_DEF_RESERVED_SIZE
 typedef struct sg_io_hdr Sg_io_hdr;
-typedef struct sg_io_vec Sg_io_vec;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+typedef struct sg_io_vec Sg_io_vec;
 typedef struct sg_scsi_id Sg_scsi_id;
 typedef struct sg_req_info Sg_req_info;
 #define SG_MAX_SENSE 16
-struct sg_header {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct sg_header {
   int pack_len;
   int reply_len;
   int pack_id;
-  int result;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+  int result;
   unsigned int twelve_byte : 1;
   unsigned int target_status : 5;
   unsigned int host_status : 8;
-  unsigned int driver_status : 8;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+  unsigned int driver_status : 8;
   unsigned int other_flags : 10;
   unsigned char sense_buffer[SG_MAX_SENSE];
 };
-#define SG_SET_TIMEOUT 0x2201
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SG_SET_TIMEOUT 0x2201
 #define SG_GET_TIMEOUT 0x2202
 #define SG_GET_COMMAND_Q 0x2270
 #define SG_SET_COMMAND_Q 0x2271
-#define SG_SET_DEBUG 0x227e
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SG_SET_DEBUG 0x227e
 #define SG_NEXT_CMD_LEN 0x2283
 #define SG_DEFAULT_TIMEOUT (60 * HZ)
 #define SG_DEF_COMMAND_Q 0
-#define SG_DEF_UNDERRUN_FLAG 0
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define SG_DEF_UNDERRUN_FLAG 0
 #endif
diff --git a/libc/kernel/uapi/linux/compiler.h b/libc/kernel/android/uapi/linux/compiler.h
similarity index 100%
rename from libc/kernel/uapi/linux/compiler.h
rename to libc/kernel/android/uapi/linux/compiler.h
diff --git a/libc/kernel/uapi/linux/keychord.h b/libc/kernel/android/uapi/linux/keychord.h
similarity index 100%
rename from libc/kernel/uapi/linux/keychord.h
rename to libc/kernel/android/uapi/linux/keychord.h
diff --git a/libc/kernel/uapi/linux/netfilter_ipv4/ipt_ULOG.h b/libc/kernel/android/uapi/linux/netfilter_ipv4/ipt_ULOG.h
similarity index 100%
rename from libc/kernel/uapi/linux/netfilter_ipv4/ipt_ULOG.h
rename to libc/kernel/android/uapi/linux/netfilter_ipv4/ipt_ULOG.h
diff --git a/libc/kernel/uapi/linux/usb/f_accessory.h b/libc/kernel/android/uapi/linux/usb/f_accessory.h
similarity index 100%
rename from libc/kernel/uapi/linux/usb/f_accessory.h
rename to libc/kernel/android/uapi/linux/usb/f_accessory.h
diff --git a/libc/kernel/uapi/linux/usb/f_mtp.h b/libc/kernel/android/uapi/linux/usb/f_mtp.h
similarity index 100%
rename from libc/kernel/uapi/linux/usb/f_mtp.h
rename to libc/kernel/android/uapi/linux/usb/f_mtp.h
diff --git a/libc/kernel/uapi/video/adf.h b/libc/kernel/android/uapi/video/adf.h
similarity index 100%
rename from libc/kernel/uapi/video/adf.h
rename to libc/kernel/android/uapi/video/adf.h
diff --git a/libc/kernel/tools/clean_header.py b/libc/kernel/tools/clean_header.py
index e84bcf9..99f4c7f 100755
--- a/libc/kernel/tools/clean_header.py
+++ b/libc/kernel/tools/clean_header.py
@@ -117,7 +117,7 @@
                 statics = statics.union(kernel_known_statics.get(arch, set()))
         # common headers (ie non-asm and non-uapi)
         else:
-            dst_path = os.path.join("common", rel_path)
+            dst_path = os.path.join("android", rel_path)
 
     dst_path = os.path.join(dst_dir, dst_path)
 
diff --git a/libc/kernel/tools/generate_uapi_headers.sh b/libc/kernel/tools/generate_uapi_headers.sh
index 3c80d9f..4603fbe 100755
--- a/libc/kernel/tools/generate_uapi_headers.sh
+++ b/libc/kernel/tools/generate_uapi_headers.sh
@@ -30,6 +30,9 @@
 ###   --use-kernel-dir <DIR>
 ###     Do not check out the kernel source, use the kernel directory
 ###     pointed to by <DIR>.
+###   --verify-modified-headers-only <DIR>
+###     Do not build anything, simply verify that the set of modified
+###     kernel headers have not changed.
 
 # Terminate the script if any command fails.
 set -eE
@@ -42,6 +45,7 @@
 ARCH_LIST=("arm" "arm64" "mips" "x86")
 ANDROID_KERNEL_DIR="external/kernel-headers/original"
 SKIP_GENERATION=0
+VERIFY_HEADERS_ONLY=0
 
 function cleanup () {
   if [[ "${TMPDIR}" =~ /tmp ]] && [[ -d "${TMPDIR}" ]]; then
@@ -99,7 +103,7 @@
   done
 }
 
-function check_hdrs () {
+function verify_modified_hdrs () {
   local src_dir=$1
   local tgt_dir=$2
   local kernel_dir=$3
@@ -124,7 +128,7 @@
   done
 
   for dir in "${search_dirs[@]}"; do
-    check_hdrs "${dir}" ${tgt_dir}/$(basename ${dir}) "${kernel_dir}"
+    verify_modified_hdrs "${dir}" ${tgt_dir}/$(basename ${dir}) "${kernel_dir}"
   done
 }
 
@@ -149,6 +153,16 @@
       KERNEL_DIR="$1"
       KERNEL_DOWNLOAD=0
       ;;
+    "--verify-modified-headers-only")
+      if [[ $# -lt 2 ]]; then
+        echo "--verify-modified-headers-only requires an argument."
+        exit 1
+      fi
+      shift
+      KERNEL_DIR="$1"
+      KERNEL_DOWNLOAD=0
+      VERIFY_HEADERS_ONLY=1
+      ;;
     "-h" | "--help")
       usage
       exit 1
@@ -183,6 +197,14 @@
   src_dir="common"
 fi
 
+if [[ ${VERIFY_HEADERS_ONLY} -eq 1 ]]; then
+  # Verify if modified headers have changed.
+  verify_modified_hdrs "${KERNEL_DIR}/${src_dir}/include/scsi" \
+                       "${ANDROID_KERNEL_DIR}/scsi" \
+                       "${KERNEL_DIR}/${src_dir}"
+  exit 0
+fi
+
 if [[ ${KERNEL_DOWNLOAD} -eq 1 ]]; then
   TMPDIR=$(mktemp -d /tmp/android_kernelXXXXXXXX)
   cd "${TMPDIR}"
@@ -202,6 +224,9 @@
 fi
 
 if [[ ${SKIP_GENERATION} -eq 0 ]]; then
+  # Clean up any leftover headers.
+  make distclean
+
   # Build all of the generated headers.
   for arch in "${ARCH_LIST[@]}"; do
     echo "Generating headers for arch ${arch}"
@@ -209,6 +234,11 @@
   done
 fi
 
+# Completely delete the old original headers so that any deleted/moved
+# headers are also removed.
+rm -rf "${ANDROID_KERNEL_DIR}/uapi"
+mkdir -p "${ANDROID_KERNEL_DIR}/uapi"
+
 cd ${ANDROID_BUILD_TOP}
 
 # Copy all of the include/uapi files to the kernel headers uapi directory.
@@ -237,7 +267,12 @@
                  "${ANDROID_KERNEL_DIR}/uapi/asm-${arch}/asm"
 done
 
+# The arm types.h uapi header is not properly being generated, so copy it
+# directly.
+cp "${KERNEL_DIR}/${src_dir}/include/uapi/asm-generic/types.h" \
+   "${ANDROID_KERNEL_DIR}/uapi/asm-arm/asm"
+
 # Verify if modified headers have changed.
-check_hdrs "${KERNEL_DIR}/${src_dir}/include/scsi" \
-           "${ANDROID_KERNEL_DIR}/scsi" \
-           "${KERNEL_DIR}/${src_dir}"
+verify_modified_hdrs "${KERNEL_DIR}/${src_dir}/include/scsi" \
+                     "${ANDROID_KERNEL_DIR}/scsi" \
+                     "${KERNEL_DIR}/${src_dir}"
diff --git a/libc/kernel/tools/update_all.py b/libc/kernel/tools/update_all.py
index 7f3657c..5031168 100755
--- a/libc/kernel/tools/update_all.py
+++ b/libc/kernel/tools/update_all.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 #
-import sys, cpp, kernel, glob, os, re, getopt, clean_header, subprocess
+import sys, cpp, kernel, glob, os, re, getopt, clean_header, subprocess, shutil
 from defaults import *
 from utils import *
 
@@ -20,7 +20,7 @@
         android tree
 
       - the clean headers will be placed in 'bionic/libc/kernel/arch-<arch>/asm',
-        'bionic/libc/kernel/common', etc..
+        'bionic/libc/kernel/android', etc..
 """ % { "progname" : os.path.basename(sys.argv[0]) }
     sys.exit(0)
 
@@ -75,7 +75,13 @@
 for arch in kernel_archs:
     b.readDir(os.path.join(kernel_dir, "arch-%s" % arch))
 
-b.readDir(os.path.join(kernel_dir, "common"))
+b.readDir(os.path.join(kernel_dir, "android"))
+
+# Delete the old uapi headers before updating to handle headers that
+# get moved/deleted.
+uapi_dir = os.path.join(get_kernel_dir(), "uapi")
+shutil.rmtree(uapi_dir)
+os.mkdir(uapi_dir, 0755)
 
 oldlen = 120
 android_root_len = len(get_android_root()) + 1
diff --git a/libc/kernel/uapi/asm-arm/asm/a.out.h b/libc/kernel/uapi/asm-arm/asm/a.out.h
deleted file mode 100644
index 3d51506..0000000
--- a/libc/kernel/uapi/asm-arm/asm/a.out.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/****************************************************************************
- ****************************************************************************
- ***
- ***   This header was automatically generated from a Linux kernel header
- ***   of the same name, to make information necessary for userspace to
- ***   call into the kernel available to libc.  It contains only constants,
- ***   structures, and macros generated from the original header, and thus,
- ***   contains no copyrightable information.
- ***
- ***   To edit the content of this header, modify the corresponding
- ***   source file (e.g. under external/kernel-headers/original/) then
- ***   run bionic/libc/kernel/tools/update_all.py
- ***
- ***   Any manual change here will be lost the next time this script will
- ***   be run. You've been warned!
- ***
- ****************************************************************************
- ****************************************************************************/
-#ifndef __ARM_A_OUT_H__
-#define __ARM_A_OUT_H__
-#include <linux/personality.h>
-#include <linux/types.h>
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-struct exec {
-  __u32 a_info;
-  __u32 a_text;
-  __u32 a_data;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u32 a_bss;
-  __u32 a_syms;
-  __u32 a_entry;
-  __u32 a_trsize;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u32 a_drsize;
-};
-#define N_TXTADDR(a) (0x00008000)
-#define N_TRSIZE(a) ((a).a_trsize)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define N_DRSIZE(a) ((a).a_drsize)
-#define N_SYMSIZE(a) ((a).a_syms)
-#define M_ARM 103
-#ifndef LIBRARY_START_TEXT
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define LIBRARY_START_TEXT (0x00c00000)
-#endif
-#endif
diff --git a/libc/kernel/uapi/asm-x86/asm/msr-index.h b/libc/kernel/uapi/asm-x86/asm/msr-index.h
deleted file mode 100644
index 221cec2..0000000
--- a/libc/kernel/uapi/asm-x86/asm/msr-index.h
+++ /dev/null
@@ -1,601 +0,0 @@
-/****************************************************************************
- ****************************************************************************
- ***
- ***   This header was automatically generated from a Linux kernel header
- ***   of the same name, to make information necessary for userspace to
- ***   call into the kernel available to libc.  It contains only constants,
- ***   structures, and macros generated from the original header, and thus,
- ***   contains no copyrightable information.
- ***
- ***   To edit the content of this header, modify the corresponding
- ***   source file (e.g. under external/kernel-headers/original/) then
- ***   run bionic/libc/kernel/tools/update_all.py
- ***
- ***   Any manual change here will be lost the next time this script will
- ***   be run. You've been warned!
- ***
- ****************************************************************************
- ****************************************************************************/
-#ifndef _ASM_X86_MSR_INDEX_H
-#define _ASM_X86_MSR_INDEX_H
-#define MSR_EFER 0xc0000080
-#define MSR_STAR 0xc0000081
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_LSTAR 0xc0000082
-#define MSR_CSTAR 0xc0000083
-#define MSR_SYSCALL_MASK 0xc0000084
-#define MSR_FS_BASE 0xc0000100
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_GS_BASE 0xc0000101
-#define MSR_KERNEL_GS_BASE 0xc0000102
-#define MSR_TSC_AUX 0xc0000103
-#define _EFER_SCE 0
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define _EFER_LME 8
-#define _EFER_LMA 10
-#define _EFER_NX 11
-#define _EFER_SVME 12
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define _EFER_LMSLE 13
-#define _EFER_FFXSR 14
-#define EFER_SCE (1 << _EFER_SCE)
-#define EFER_LME (1 << _EFER_LME)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define EFER_LMA (1 << _EFER_LMA)
-#define EFER_NX (1 << _EFER_NX)
-#define EFER_SVME (1 << _EFER_SVME)
-#define EFER_LMSLE (1 << _EFER_LMSLE)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define EFER_FFXSR (1 << _EFER_FFXSR)
-#define MSR_IA32_PERFCTR0 0x000000c1
-#define MSR_IA32_PERFCTR1 0x000000c2
-#define MSR_FSB_FREQ 0x000000cd
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_NHM_PLATFORM_INFO 0x000000ce
-#define MSR_NHM_SNB_PKG_CST_CFG_CTL 0x000000e2
-#define NHM_C3_AUTO_DEMOTE (1UL << 25)
-#define NHM_C1_AUTO_DEMOTE (1UL << 26)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define ATM_LNC_C6_AUTO_DEMOTE (1UL << 25)
-#define SNB_C1_AUTO_UNDEMOTE (1UL << 27)
-#define SNB_C3_AUTO_UNDEMOTE (1UL << 28)
-#define MSR_PLATFORM_INFO 0x000000ce
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_MTRRcap 0x000000fe
-#define MSR_IA32_BBL_CR_CTL 0x00000119
-#define MSR_IA32_BBL_CR_CTL3 0x0000011e
-#define MSR_IA32_SYSENTER_CS 0x00000174
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_SYSENTER_ESP 0x00000175
-#define MSR_IA32_SYSENTER_EIP 0x00000176
-#define MSR_IA32_MCG_CAP 0x00000179
-#define MSR_IA32_MCG_STATUS 0x0000017a
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_MCG_CTL 0x0000017b
-#define MSR_OFFCORE_RSP_0 0x000001a6
-#define MSR_OFFCORE_RSP_1 0x000001a7
-#define MSR_NHM_TURBO_RATIO_LIMIT 0x000001ad
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IVT_TURBO_RATIO_LIMIT 0x000001ae
-#define MSR_LBR_SELECT 0x000001c8
-#define MSR_LBR_TOS 0x000001c9
-#define MSR_LBR_NHM_FROM 0x00000680
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_LBR_NHM_TO 0x000006c0
-#define MSR_LBR_CORE_FROM 0x00000040
-#define MSR_LBR_CORE_TO 0x00000060
-#define MSR_IA32_PEBS_ENABLE 0x000003f1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_DS_AREA 0x00000600
-#define MSR_IA32_PERF_CAPABILITIES 0x00000345
-#define MSR_PEBS_LD_LAT_THRESHOLD 0x000003f6
-#define MSR_MTRRfix64K_00000 0x00000250
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_MTRRfix16K_80000 0x00000258
-#define MSR_MTRRfix16K_A0000 0x00000259
-#define MSR_MTRRfix4K_C0000 0x00000268
-#define MSR_MTRRfix4K_C8000 0x00000269
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_MTRRfix4K_D0000 0x0000026a
-#define MSR_MTRRfix4K_D8000 0x0000026b
-#define MSR_MTRRfix4K_E0000 0x0000026c
-#define MSR_MTRRfix4K_E8000 0x0000026d
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_MTRRfix4K_F0000 0x0000026e
-#define MSR_MTRRfix4K_F8000 0x0000026f
-#define MSR_MTRRdefType 0x000002ff
-#define MSR_IA32_CR_PAT 0x00000277
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_DEBUGCTLMSR 0x000001d9
-#define MSR_IA32_LASTBRANCHFROMIP 0x000001db
-#define MSR_IA32_LASTBRANCHTOIP 0x000001dc
-#define MSR_IA32_LASTINTFROMIP 0x000001dd
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_LASTINTTOIP 0x000001de
-#define DEBUGCTLMSR_LBR (1UL << 0)
-#define DEBUGCTLMSR_BTF (1UL << 1)
-#define DEBUGCTLMSR_TR (1UL << 6)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define DEBUGCTLMSR_BTS (1UL << 7)
-#define DEBUGCTLMSR_BTINT (1UL << 8)
-#define DEBUGCTLMSR_BTS_OFF_OS (1UL << 9)
-#define DEBUGCTLMSR_BTS_OFF_USR (1UL << 10)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define DEBUGCTLMSR_FREEZE_LBRS_ON_PMI (1UL << 11)
-#define MSR_IA32_POWER_CTL 0x000001fc
-#define MSR_IA32_MC0_CTL 0x00000400
-#define MSR_IA32_MC0_STATUS 0x00000401
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_MC0_ADDR 0x00000402
-#define MSR_IA32_MC0_MISC 0x00000403
-#define MSR_PKG_C3_RESIDENCY 0x000003f8
-#define MSR_PKG_C6_RESIDENCY 0x000003f9
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_PKG_C7_RESIDENCY 0x000003fa
-#define MSR_CORE_C3_RESIDENCY 0x000003fc
-#define MSR_CORE_C6_RESIDENCY 0x000003fd
-#define MSR_CORE_C7_RESIDENCY 0x000003fe
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_PKG_C2_RESIDENCY 0x0000060d
-#define MSR_PKG_C8_RESIDENCY 0x00000630
-#define MSR_PKG_C9_RESIDENCY 0x00000631
-#define MSR_PKG_C10_RESIDENCY 0x00000632
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_RAPL_POWER_UNIT 0x00000606
-#define MSR_PKG_POWER_LIMIT 0x00000610
-#define MSR_PKG_ENERGY_STATUS 0x00000611
-#define MSR_PKG_PERF_STATUS 0x00000613
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_PKG_POWER_INFO 0x00000614
-#define MSR_DRAM_POWER_LIMIT 0x00000618
-#define MSR_DRAM_ENERGY_STATUS 0x00000619
-#define MSR_DRAM_PERF_STATUS 0x0000061b
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_DRAM_POWER_INFO 0x0000061c
-#define MSR_PP0_POWER_LIMIT 0x00000638
-#define MSR_PP0_ENERGY_STATUS 0x00000639
-#define MSR_PP0_POLICY 0x0000063a
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_PP0_PERF_STATUS 0x0000063b
-#define MSR_PP1_POWER_LIMIT 0x00000640
-#define MSR_PP1_ENERGY_STATUS 0x00000641
-#define MSR_PP1_POLICY 0x00000642
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_CORE_C1_RES 0x00000660
-#define MSR_CC6_DEMOTION_POLICY_CONFIG 0x00000668
-#define MSR_MC6_DEMOTION_POLICY_CONFIG 0x00000669
-#define MSR_AMD64_MC0_MASK 0xc0010044
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_MCx_CTL(x) (MSR_IA32_MC0_CTL + 4 * (x))
-#define MSR_IA32_MCx_STATUS(x) (MSR_IA32_MC0_STATUS + 4 * (x))
-#define MSR_IA32_MCx_ADDR(x) (MSR_IA32_MC0_ADDR + 4 * (x))
-#define MSR_IA32_MCx_MISC(x) (MSR_IA32_MC0_MISC + 4 * (x))
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_AMD64_MCx_MASK(x) (MSR_AMD64_MC0_MASK + (x))
-#define MSR_IA32_MC0_CTL2 0x00000280
-#define MSR_IA32_MCx_CTL2(x) (MSR_IA32_MC0_CTL2 + (x))
-#define MSR_P6_PERFCTR0 0x000000c1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_P6_PERFCTR1 0x000000c2
-#define MSR_P6_EVNTSEL0 0x00000186
-#define MSR_P6_EVNTSEL1 0x00000187
-#define MSR_KNC_PERFCTR0 0x00000020
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_KNC_PERFCTR1 0x00000021
-#define MSR_KNC_EVNTSEL0 0x00000028
-#define MSR_KNC_EVNTSEL1 0x00000029
-#define MSR_IA32_PMC0 0x000004c1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_AMD64_PATCH_LEVEL 0x0000008b
-#define MSR_AMD64_TSC_RATIO 0xc0000104
-#define MSR_AMD64_NB_CFG 0xc001001f
-#define MSR_AMD64_PATCH_LOADER 0xc0010020
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_AMD64_OSVW_ID_LENGTH 0xc0010140
-#define MSR_AMD64_OSVW_STATUS 0xc0010141
-#define MSR_AMD64_LS_CFG 0xc0011020
-#define MSR_AMD64_DC_CFG 0xc0011022
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_AMD64_BU_CFG2 0xc001102a
-#define MSR_AMD64_IBSFETCHCTL 0xc0011030
-#define MSR_AMD64_IBSFETCHLINAD 0xc0011031
-#define MSR_AMD64_IBSFETCHPHYSAD 0xc0011032
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_AMD64_IBSFETCH_REG_COUNT 3
-#define MSR_AMD64_IBSFETCH_REG_MASK ((1UL << MSR_AMD64_IBSFETCH_REG_COUNT) - 1)
-#define MSR_AMD64_IBSOPCTL 0xc0011033
-#define MSR_AMD64_IBSOPRIP 0xc0011034
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_AMD64_IBSOPDATA 0xc0011035
-#define MSR_AMD64_IBSOPDATA2 0xc0011036
-#define MSR_AMD64_IBSOPDATA3 0xc0011037
-#define MSR_AMD64_IBSDCLINAD 0xc0011038
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_AMD64_IBSDCPHYSAD 0xc0011039
-#define MSR_AMD64_IBSOP_REG_COUNT 7
-#define MSR_AMD64_IBSOP_REG_MASK ((1UL << MSR_AMD64_IBSOP_REG_COUNT) - 1)
-#define MSR_AMD64_IBSCTL 0xc001103a
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_AMD64_IBSBRTARGET 0xc001103b
-#define MSR_AMD64_IBS_REG_COUNT_MAX 8
-#define MSR_F16H_L2I_PERF_CTL 0xc0010230
-#define MSR_F16H_L2I_PERF_CTR 0xc0010231
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_F15H_PERF_CTL 0xc0010200
-#define MSR_F15H_PERF_CTR 0xc0010201
-#define MSR_F15H_NB_PERF_CTL 0xc0010240
-#define MSR_F15H_NB_PERF_CTR 0xc0010241
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_FAM10H_MMIO_CONF_BASE 0xc0010058
-#define FAM10H_MMIO_CONF_ENABLE (1 << 0)
-#define FAM10H_MMIO_CONF_BUSRANGE_MASK 0xf
-#define FAM10H_MMIO_CONF_BUSRANGE_SHIFT 2
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define FAM10H_MMIO_CONF_BASE_MASK 0xfffffffULL
-#define FAM10H_MMIO_CONF_BASE_SHIFT 20
-#define MSR_FAM10H_NODE_ID 0xc001100c
-#define MSR_K8_TOP_MEM1 0xc001001a
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_K8_TOP_MEM2 0xc001001d
-#define MSR_K8_SYSCFG 0xc0010010
-#define MSR_K8_INT_PENDING_MSG 0xc0010055
-#define K8_INTP_C1E_ACTIVE_MASK 0x18000000
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_K8_TSEG_ADDR 0xc0010112
-#define K8_MTRRFIXRANGE_DRAM_ENABLE 0x00040000
-#define K8_MTRRFIXRANGE_DRAM_MODIFY 0x00080000
-#define K8_MTRR_RDMEM_WRMEM_MASK 0x18181818
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_K7_EVNTSEL0 0xc0010000
-#define MSR_K7_PERFCTR0 0xc0010004
-#define MSR_K7_EVNTSEL1 0xc0010001
-#define MSR_K7_PERFCTR1 0xc0010005
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_K7_EVNTSEL2 0xc0010002
-#define MSR_K7_PERFCTR2 0xc0010006
-#define MSR_K7_EVNTSEL3 0xc0010003
-#define MSR_K7_PERFCTR3 0xc0010007
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_K7_CLK_CTL 0xc001001b
-#define MSR_K7_HWCR 0xc0010015
-#define MSR_K7_FID_VID_CTL 0xc0010041
-#define MSR_K7_FID_VID_STATUS 0xc0010042
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_K6_WHCR 0xc0000082
-#define MSR_K6_UWCCR 0xc0000085
-#define MSR_K6_EPMR 0xc0000086
-#define MSR_K6_PSOR 0xc0000087
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_K6_PFIR 0xc0000088
-#define MSR_IDT_FCR1 0x00000107
-#define MSR_IDT_FCR2 0x00000108
-#define MSR_IDT_FCR3 0x00000109
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IDT_FCR4 0x0000010a
-#define MSR_IDT_MCR0 0x00000110
-#define MSR_IDT_MCR1 0x00000111
-#define MSR_IDT_MCR2 0x00000112
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IDT_MCR3 0x00000113
-#define MSR_IDT_MCR4 0x00000114
-#define MSR_IDT_MCR5 0x00000115
-#define MSR_IDT_MCR6 0x00000116
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IDT_MCR7 0x00000117
-#define MSR_IDT_MCR_CTRL 0x00000120
-#define MSR_VIA_FCR 0x00001107
-#define MSR_VIA_LONGHAUL 0x0000110a
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_VIA_RNG 0x0000110b
-#define MSR_VIA_BCR2 0x00001147
-#define MSR_TMTA_LONGRUN_CTRL 0x80868010
-#define MSR_TMTA_LONGRUN_FLAGS 0x80868011
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_TMTA_LRTI_READOUT 0x80868018
-#define MSR_TMTA_LRTI_VOLT_MHZ 0x8086801a
-#define MSR_IA32_P5_MC_ADDR 0x00000000
-#define MSR_IA32_P5_MC_TYPE 0x00000001
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_TSC 0x00000010
-#define MSR_IA32_PLATFORM_ID 0x00000017
-#define MSR_IA32_EBL_CR_POWERON 0x0000002a
-#define MSR_EBC_FREQUENCY_ID 0x0000002c
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_SMI_COUNT 0x00000034
-#define MSR_IA32_FEATURE_CONTROL 0x0000003a
-#define MSR_IA32_TSC_ADJUST 0x0000003b
-#define MSR_IA32_BNDCFGS 0x00000d90
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_XSS 0x00000da0
-#define FEATURE_CONTROL_LOCKED (1 << 0)
-#define FEATURE_CONTROL_VMXON_ENABLED_INSIDE_SMX (1 << 1)
-#define FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX (1 << 2)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_APICBASE 0x0000001b
-#define MSR_IA32_APICBASE_BSP (1 << 8)
-#define MSR_IA32_APICBASE_ENABLE (1 << 11)
-#define MSR_IA32_APICBASE_BASE (0xfffff << 12)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_TSCDEADLINE 0x000006e0
-#define MSR_IA32_UCODE_WRITE 0x00000079
-#define MSR_IA32_UCODE_REV 0x0000008b
-#define MSR_IA32_PERF_STATUS 0x00000198
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_PERF_CTL 0x00000199
-#define MSR_AMD_PSTATE_DEF_BASE 0xc0010064
-#define MSR_AMD_PERF_STATUS 0xc0010063
-#define MSR_AMD_PERF_CTL 0xc0010062
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_MPERF 0x000000e7
-#define MSR_IA32_APERF 0x000000e8
-#define MSR_IA32_THERM_CONTROL 0x0000019a
-#define MSR_IA32_THERM_INTERRUPT 0x0000019b
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define THERM_INT_HIGH_ENABLE (1 << 0)
-#define THERM_INT_LOW_ENABLE (1 << 1)
-#define THERM_INT_PLN_ENABLE (1 << 24)
-#define MSR_IA32_THERM_STATUS 0x0000019c
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define THERM_STATUS_PROCHOT (1 << 0)
-#define THERM_STATUS_POWER_LIMIT (1 << 10)
-#define MSR_THERM2_CTL 0x0000019d
-#define MSR_THERM2_CTL_TM_SELECT (1ULL << 16)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_MISC_ENABLE 0x000001a0
-#define MSR_IA32_TEMPERATURE_TARGET 0x000001a2
-#define MSR_IA32_ENERGY_PERF_BIAS 0x000001b0
-#define ENERGY_PERF_BIAS_PERFORMANCE 0
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define ENERGY_PERF_BIAS_NORMAL 6
-#define ENERGY_PERF_BIAS_POWERSAVE 15
-#define MSR_IA32_PACKAGE_THERM_STATUS 0x000001b1
-#define PACKAGE_THERM_STATUS_PROCHOT (1 << 0)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define PACKAGE_THERM_STATUS_POWER_LIMIT (1 << 10)
-#define MSR_IA32_PACKAGE_THERM_INTERRUPT 0x000001b2
-#define PACKAGE_THERM_INT_HIGH_ENABLE (1 << 0)
-#define PACKAGE_THERM_INT_LOW_ENABLE (1 << 1)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define PACKAGE_THERM_INT_PLN_ENABLE (1 << 24)
-#define THERM_INT_THRESHOLD0_ENABLE (1 << 15)
-#define THERM_SHIFT_THRESHOLD0 8
-#define THERM_MASK_THRESHOLD0 (0x7f << THERM_SHIFT_THRESHOLD0)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define THERM_INT_THRESHOLD1_ENABLE (1 << 23)
-#define THERM_SHIFT_THRESHOLD1 16
-#define THERM_MASK_THRESHOLD1 (0x7f << THERM_SHIFT_THRESHOLD1)
-#define THERM_STATUS_THRESHOLD0 (1 << 6)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define THERM_LOG_THRESHOLD0 (1 << 7)
-#define THERM_STATUS_THRESHOLD1 (1 << 8)
-#define THERM_LOG_THRESHOLD1 (1 << 9)
-#define MSR_IA32_MISC_ENABLE_FAST_STRING_BIT 0
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_MISC_ENABLE_FAST_STRING (1ULL << MSR_IA32_MISC_ENABLE_FAST_STRING_BIT)
-#define MSR_IA32_MISC_ENABLE_TCC_BIT 1
-#define MSR_IA32_MISC_ENABLE_TCC (1ULL << MSR_IA32_MISC_ENABLE_TCC_BIT)
-#define MSR_IA32_MISC_ENABLE_EMON_BIT 7
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_MISC_ENABLE_EMON (1ULL << MSR_IA32_MISC_ENABLE_EMON_BIT)
-#define MSR_IA32_MISC_ENABLE_BTS_UNAVAIL_BIT 11
-#define MSR_IA32_MISC_ENABLE_BTS_UNAVAIL (1ULL << MSR_IA32_MISC_ENABLE_BTS_UNAVAIL_BIT)
-#define MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL_BIT 12
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL (1ULL << MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL_BIT)
-#define MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP_BIT 16
-#define MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP (1ULL << MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP_BIT)
-#define MSR_IA32_MISC_ENABLE_MWAIT_BIT 18
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_MISC_ENABLE_MWAIT (1ULL << MSR_IA32_MISC_ENABLE_MWAIT_BIT)
-#define MSR_IA32_MISC_ENABLE_LIMIT_CPUID_BIT 22
-#define MSR_IA32_MISC_ENABLE_LIMIT_CPUID (1ULL << MSR_IA32_MISC_ENABLE_LIMIT_CPUID_BIT)
-#define MSR_IA32_MISC_ENABLE_XTPR_DISABLE_BIT 23
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_MISC_ENABLE_XTPR_DISABLE (1ULL << MSR_IA32_MISC_ENABLE_XTPR_DISABLE_BIT)
-#define MSR_IA32_MISC_ENABLE_XD_DISABLE_BIT 34
-#define MSR_IA32_MISC_ENABLE_XD_DISABLE (1ULL << MSR_IA32_MISC_ENABLE_XD_DISABLE_BIT)
-#define MSR_IA32_MISC_ENABLE_X87_COMPAT_BIT 2
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_MISC_ENABLE_X87_COMPAT (1ULL << MSR_IA32_MISC_ENABLE_X87_COMPAT_BIT)
-#define MSR_IA32_MISC_ENABLE_TM1_BIT 3
-#define MSR_IA32_MISC_ENABLE_TM1 (1ULL << MSR_IA32_MISC_ENABLE_TM1_BIT)
-#define MSR_IA32_MISC_ENABLE_SPLIT_LOCK_DISABLE_BIT 4
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_MISC_ENABLE_SPLIT_LOCK_DISABLE (1ULL << MSR_IA32_MISC_ENABLE_SPLIT_LOCK_DISABLE_BIT)
-#define MSR_IA32_MISC_ENABLE_L3CACHE_DISABLE_BIT 6
-#define MSR_IA32_MISC_ENABLE_L3CACHE_DISABLE (1ULL << MSR_IA32_MISC_ENABLE_L3CACHE_DISABLE_BIT)
-#define MSR_IA32_MISC_ENABLE_SUPPRESS_LOCK_BIT 8
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_MISC_ENABLE_SUPPRESS_LOCK (1ULL << MSR_IA32_MISC_ENABLE_SUPPRESS_LOCK_BIT)
-#define MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE_BIT 9
-#define MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE (1ULL << MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE_BIT)
-#define MSR_IA32_MISC_ENABLE_FERR_BIT 10
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_MISC_ENABLE_FERR (1ULL << MSR_IA32_MISC_ENABLE_FERR_BIT)
-#define MSR_IA32_MISC_ENABLE_FERR_MULTIPLEX_BIT 10
-#define MSR_IA32_MISC_ENABLE_FERR_MULTIPLEX (1ULL << MSR_IA32_MISC_ENABLE_FERR_MULTIPLEX_BIT)
-#define MSR_IA32_MISC_ENABLE_TM2_BIT 13
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_MISC_ENABLE_TM2 (1ULL << MSR_IA32_MISC_ENABLE_TM2_BIT)
-#define MSR_IA32_MISC_ENABLE_ADJ_PREF_DISABLE_BIT 19
-#define MSR_IA32_MISC_ENABLE_ADJ_PREF_DISABLE (1ULL << MSR_IA32_MISC_ENABLE_ADJ_PREF_DISABLE_BIT)
-#define MSR_IA32_MISC_ENABLE_SPEEDSTEP_LOCK_BIT 20
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_MISC_ENABLE_SPEEDSTEP_LOCK (1ULL << MSR_IA32_MISC_ENABLE_SPEEDSTEP_LOCK_BIT)
-#define MSR_IA32_MISC_ENABLE_L1D_CONTEXT_BIT 24
-#define MSR_IA32_MISC_ENABLE_L1D_CONTEXT (1ULL << MSR_IA32_MISC_ENABLE_L1D_CONTEXT_BIT)
-#define MSR_IA32_MISC_ENABLE_DCU_PREF_DISABLE_BIT 37
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_MISC_ENABLE_DCU_PREF_DISABLE (1ULL << MSR_IA32_MISC_ENABLE_DCU_PREF_DISABLE_BIT)
-#define MSR_IA32_MISC_ENABLE_TURBO_DISABLE_BIT 38
-#define MSR_IA32_MISC_ENABLE_TURBO_DISABLE (1ULL << MSR_IA32_MISC_ENABLE_TURBO_DISABLE_BIT)
-#define MSR_IA32_MISC_ENABLE_IP_PREF_DISABLE_BIT 39
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_MISC_ENABLE_IP_PREF_DISABLE (1ULL << MSR_IA32_MISC_ENABLE_IP_PREF_DISABLE_BIT)
-#define MSR_IA32_TSC_DEADLINE 0x000006E0
-#define MSR_IA32_MCG_EAX 0x00000180
-#define MSR_IA32_MCG_EBX 0x00000181
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_MCG_ECX 0x00000182
-#define MSR_IA32_MCG_EDX 0x00000183
-#define MSR_IA32_MCG_ESI 0x00000184
-#define MSR_IA32_MCG_EDI 0x00000185
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_MCG_EBP 0x00000186
-#define MSR_IA32_MCG_ESP 0x00000187
-#define MSR_IA32_MCG_EFLAGS 0x00000188
-#define MSR_IA32_MCG_EIP 0x00000189
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_MCG_RESERVED 0x0000018a
-#define MSR_P4_BPU_PERFCTR0 0x00000300
-#define MSR_P4_BPU_PERFCTR1 0x00000301
-#define MSR_P4_BPU_PERFCTR2 0x00000302
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_P4_BPU_PERFCTR3 0x00000303
-#define MSR_P4_MS_PERFCTR0 0x00000304
-#define MSR_P4_MS_PERFCTR1 0x00000305
-#define MSR_P4_MS_PERFCTR2 0x00000306
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_P4_MS_PERFCTR3 0x00000307
-#define MSR_P4_FLAME_PERFCTR0 0x00000308
-#define MSR_P4_FLAME_PERFCTR1 0x00000309
-#define MSR_P4_FLAME_PERFCTR2 0x0000030a
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_P4_FLAME_PERFCTR3 0x0000030b
-#define MSR_P4_IQ_PERFCTR0 0x0000030c
-#define MSR_P4_IQ_PERFCTR1 0x0000030d
-#define MSR_P4_IQ_PERFCTR2 0x0000030e
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_P4_IQ_PERFCTR3 0x0000030f
-#define MSR_P4_IQ_PERFCTR4 0x00000310
-#define MSR_P4_IQ_PERFCTR5 0x00000311
-#define MSR_P4_BPU_CCCR0 0x00000360
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_P4_BPU_CCCR1 0x00000361
-#define MSR_P4_BPU_CCCR2 0x00000362
-#define MSR_P4_BPU_CCCR3 0x00000363
-#define MSR_P4_MS_CCCR0 0x00000364
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_P4_MS_CCCR1 0x00000365
-#define MSR_P4_MS_CCCR2 0x00000366
-#define MSR_P4_MS_CCCR3 0x00000367
-#define MSR_P4_FLAME_CCCR0 0x00000368
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_P4_FLAME_CCCR1 0x00000369
-#define MSR_P4_FLAME_CCCR2 0x0000036a
-#define MSR_P4_FLAME_CCCR3 0x0000036b
-#define MSR_P4_IQ_CCCR0 0x0000036c
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_P4_IQ_CCCR1 0x0000036d
-#define MSR_P4_IQ_CCCR2 0x0000036e
-#define MSR_P4_IQ_CCCR3 0x0000036f
-#define MSR_P4_IQ_CCCR4 0x00000370
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_P4_IQ_CCCR5 0x00000371
-#define MSR_P4_ALF_ESCR0 0x000003ca
-#define MSR_P4_ALF_ESCR1 0x000003cb
-#define MSR_P4_BPU_ESCR0 0x000003b2
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_P4_BPU_ESCR1 0x000003b3
-#define MSR_P4_BSU_ESCR0 0x000003a0
-#define MSR_P4_BSU_ESCR1 0x000003a1
-#define MSR_P4_CRU_ESCR0 0x000003b8
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_P4_CRU_ESCR1 0x000003b9
-#define MSR_P4_CRU_ESCR2 0x000003cc
-#define MSR_P4_CRU_ESCR3 0x000003cd
-#define MSR_P4_CRU_ESCR4 0x000003e0
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_P4_CRU_ESCR5 0x000003e1
-#define MSR_P4_DAC_ESCR0 0x000003a8
-#define MSR_P4_DAC_ESCR1 0x000003a9
-#define MSR_P4_FIRM_ESCR0 0x000003a4
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_P4_FIRM_ESCR1 0x000003a5
-#define MSR_P4_FLAME_ESCR0 0x000003a6
-#define MSR_P4_FLAME_ESCR1 0x000003a7
-#define MSR_P4_FSB_ESCR0 0x000003a2
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_P4_FSB_ESCR1 0x000003a3
-#define MSR_P4_IQ_ESCR0 0x000003ba
-#define MSR_P4_IQ_ESCR1 0x000003bb
-#define MSR_P4_IS_ESCR0 0x000003b4
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_P4_IS_ESCR1 0x000003b5
-#define MSR_P4_ITLB_ESCR0 0x000003b6
-#define MSR_P4_ITLB_ESCR1 0x000003b7
-#define MSR_P4_IX_ESCR0 0x000003c8
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_P4_IX_ESCR1 0x000003c9
-#define MSR_P4_MOB_ESCR0 0x000003aa
-#define MSR_P4_MOB_ESCR1 0x000003ab
-#define MSR_P4_MS_ESCR0 0x000003c0
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_P4_MS_ESCR1 0x000003c1
-#define MSR_P4_PMH_ESCR0 0x000003ac
-#define MSR_P4_PMH_ESCR1 0x000003ad
-#define MSR_P4_RAT_ESCR0 0x000003bc
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_P4_RAT_ESCR1 0x000003bd
-#define MSR_P4_SAAT_ESCR0 0x000003ae
-#define MSR_P4_SAAT_ESCR1 0x000003af
-#define MSR_P4_SSU_ESCR0 0x000003be
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_P4_SSU_ESCR1 0x000003bf
-#define MSR_P4_TBPU_ESCR0 0x000003c2
-#define MSR_P4_TBPU_ESCR1 0x000003c3
-#define MSR_P4_TC_ESCR0 0x000003c4
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_P4_TC_ESCR1 0x000003c5
-#define MSR_P4_U2L_ESCR0 0x000003b0
-#define MSR_P4_U2L_ESCR1 0x000003b1
-#define MSR_P4_PEBS_MATRIX_VERT 0x000003f2
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_CORE_PERF_FIXED_CTR0 0x00000309
-#define MSR_CORE_PERF_FIXED_CTR1 0x0000030a
-#define MSR_CORE_PERF_FIXED_CTR2 0x0000030b
-#define MSR_CORE_PERF_FIXED_CTR_CTRL 0x0000038d
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_CORE_PERF_GLOBAL_STATUS 0x0000038e
-#define MSR_CORE_PERF_GLOBAL_CTRL 0x0000038f
-#define MSR_CORE_PERF_GLOBAL_OVF_CTRL 0x00000390
-#define MSR_GEODE_BUSCONT_CONF0 0x00001900
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_VMX_BASIC 0x00000480
-#define MSR_IA32_VMX_PINBASED_CTLS 0x00000481
-#define MSR_IA32_VMX_PROCBASED_CTLS 0x00000482
-#define MSR_IA32_VMX_EXIT_CTLS 0x00000483
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_VMX_ENTRY_CTLS 0x00000484
-#define MSR_IA32_VMX_MISC 0x00000485
-#define MSR_IA32_VMX_CR0_FIXED0 0x00000486
-#define MSR_IA32_VMX_CR0_FIXED1 0x00000487
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_VMX_CR4_FIXED0 0x00000488
-#define MSR_IA32_VMX_CR4_FIXED1 0x00000489
-#define MSR_IA32_VMX_VMCS_ENUM 0x0000048a
-#define MSR_IA32_VMX_PROCBASED_CTLS2 0x0000048b
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_VMX_EPT_VPID_CAP 0x0000048c
-#define MSR_IA32_VMX_TRUE_PINBASED_CTLS 0x0000048d
-#define MSR_IA32_VMX_TRUE_PROCBASED_CTLS 0x0000048e
-#define MSR_IA32_VMX_TRUE_EXIT_CTLS 0x0000048f
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_IA32_VMX_TRUE_ENTRY_CTLS 0x00000490
-#define MSR_IA32_VMX_VMFUNC 0x00000491
-#define VMX_BASIC_VMCS_SIZE_SHIFT 32
-#define VMX_BASIC_TRUE_CTLS (1ULL << 55)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define VMX_BASIC_64 0x0001000000000000LLU
-#define VMX_BASIC_MEM_TYPE_SHIFT 50
-#define VMX_BASIC_MEM_TYPE_MASK 0x003c000000000000LLU
-#define VMX_BASIC_MEM_TYPE_WB 6LLU
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define VMX_BASIC_INOUT 0x0040000000000000LLU
-#define MSR_IA32_VMX_MISC_VMWRITE_SHADOW_RO_FIELDS (1ULL << 29)
-#define MSR_IA32_VMX_MISC_PREEMPTION_TIMER_SCALE 0x1F
-#define MSR_VM_CR 0xc0010114
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define MSR_VM_IGNNE 0xc0010115
-#define MSR_VM_HSAVE_PA 0xc0010117
-#endif
diff --git a/libc/kernel/uapi/linux/android_alarm.h b/libc/kernel/uapi/linux/android_alarm.h
deleted file mode 100644
index 801a01e..0000000
--- a/libc/kernel/uapi/linux/android_alarm.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/****************************************************************************
- ****************************************************************************
- ***
- ***   This header was automatically generated from a Linux kernel header
- ***   of the same name, to make information necessary for userspace to
- ***   call into the kernel available to libc.  It contains only constants,
- ***   structures, and macros generated from the original header, and thus,
- ***   contains no copyrightable information.
- ***
- ***   To edit the content of this header, modify the corresponding
- ***   source file (e.g. under external/kernel-headers/original/) then
- ***   run bionic/libc/kernel/tools/update_all.py
- ***
- ***   Any manual change here will be lost the next time this script will
- ***   be run. You've been warned!
- ***
- ****************************************************************************
- ****************************************************************************/
-#ifndef _UAPI_LINUX_ANDROID_ALARM_H
-#define _UAPI_LINUX_ANDROID_ALARM_H
-#include <linux/ioctl.h>
-#include <linux/time.h>
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-enum android_alarm_type {
-  ANDROID_ALARM_RTC_WAKEUP,
-  ANDROID_ALARM_RTC,
-  ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  ANDROID_ALARM_ELAPSED_REALTIME,
-  ANDROID_ALARM_SYSTEMTIME,
-  ANDROID_ALARM_TYPE_COUNT,
-};
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-enum android_alarm_return_flags {
-  ANDROID_ALARM_RTC_WAKEUP_MASK = 1U << ANDROID_ALARM_RTC_WAKEUP,
-  ANDROID_ALARM_RTC_MASK = 1U << ANDROID_ALARM_RTC,
-  ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP_MASK = 1U << ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  ANDROID_ALARM_ELAPSED_REALTIME_MASK = 1U << ANDROID_ALARM_ELAPSED_REALTIME,
-  ANDROID_ALARM_SYSTEMTIME_MASK = 1U << ANDROID_ALARM_SYSTEMTIME,
-  ANDROID_ALARM_TIME_CHANGE_MASK = 1U << 16
-};
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define ANDROID_ALARM_CLEAR(type) _IO('a', 0 | ((type) << 4))
-#define ANDROID_ALARM_WAIT _IO('a', 1)
-#define ALARM_IOW(c,type,size) _IOW('a', (c) | ((type) << 4), size)
-#define ANDROID_ALARM_SET(type) ALARM_IOW(2, type, struct timespec)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define ANDROID_ALARM_SET_AND_WAIT(type) ALARM_IOW(3, type, struct timespec)
-#define ANDROID_ALARM_GET_TIME(type) ALARM_IOW(4, type, struct timespec)
-#define ANDROID_ALARM_SET_RTC _IOW('a', 5, struct timespec)
-#define ANDROID_ALARM_BASE_CMD(cmd) (cmd & ~(_IOC(0, 0, 0xf0, 0)))
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define ANDROID_ALARM_IOCTL_TO_TYPE(cmd) (_IOC_NR(cmd) >> 4)
-#endif
diff --git a/libc/kernel/uapi/linux/binder.h b/libc/kernel/uapi/linux/binder.h
deleted file mode 100644
index af3cea9..0000000
--- a/libc/kernel/uapi/linux/binder.h
+++ /dev/null
@@ -1,190 +0,0 @@
-/****************************************************************************
- ****************************************************************************
- ***
- ***   This header was automatically generated from a Linux kernel header
- ***   of the same name, to make information necessary for userspace to
- ***   call into the kernel available to libc.  It contains only constants,
- ***   structures, and macros generated from the original header, and thus,
- ***   contains no copyrightable information.
- ***
- ***   To edit the content of this header, modify the corresponding
- ***   source file (e.g. under external/kernel-headers/original/) then
- ***   run bionic/libc/kernel/tools/update_all.py
- ***
- ***   Any manual change here will be lost the next time this script will
- ***   be run. You've been warned!
- ***
- ****************************************************************************
- ****************************************************************************/
-#ifndef _UAPI_LINUX_BINDER_H
-#define _UAPI_LINUX_BINDER_H
-#include <linux/ioctl.h>
-#define B_PACK_CHARS(c1,c2,c3,c4) ((((c1) << 24)) | (((c2) << 16)) | (((c3) << 8)) | (c4))
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define B_TYPE_LARGE 0x85
-enum {
-  BINDER_TYPE_BINDER = B_PACK_CHARS('s', 'b', '*', B_TYPE_LARGE),
-  BINDER_TYPE_WEAK_BINDER = B_PACK_CHARS('w', 'b', '*', B_TYPE_LARGE),
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  BINDER_TYPE_HANDLE = B_PACK_CHARS('s', 'h', '*', B_TYPE_LARGE),
-  BINDER_TYPE_WEAK_HANDLE = B_PACK_CHARS('w', 'h', '*', B_TYPE_LARGE),
-  BINDER_TYPE_FD = B_PACK_CHARS('f', 'd', '*', B_TYPE_LARGE),
-};
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-enum {
-  FLAT_BINDER_FLAG_PRIORITY_MASK = 0xff,
-  FLAT_BINDER_FLAG_ACCEPTS_FDS = 0x100,
-};
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#ifdef BINDER_IPC_32BIT
-typedef __u32 binder_size_t;
-typedef __u32 binder_uintptr_t;
-#else
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-typedef __u64 binder_size_t;
-typedef __u64 binder_uintptr_t;
-#endif
-struct flat_binder_object {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u32 type;
-  __u32 flags;
-  union {
-    binder_uintptr_t binder;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-    __u32 handle;
-  };
-  binder_uintptr_t cookie;
-};
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-struct binder_write_read {
-  binder_size_t write_size;
-  binder_size_t write_consumed;
-  binder_uintptr_t write_buffer;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  binder_size_t read_size;
-  binder_size_t read_consumed;
-  binder_uintptr_t read_buffer;
-};
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-struct binder_version {
-  __s32 protocol_version;
-};
-#ifdef BINDER_IPC_32BIT
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define BINDER_CURRENT_PROTOCOL_VERSION 7
-#else
-#define BINDER_CURRENT_PROTOCOL_VERSION 8
-#endif
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define BINDER_WRITE_READ _IOWR('b', 1, struct binder_write_read)
-#define BINDER_SET_IDLE_TIMEOUT _IOW('b', 3, __s64)
-#define BINDER_SET_MAX_THREADS _IOW('b', 5, __u32)
-#define BINDER_SET_IDLE_PRIORITY _IOW('b', 6, __s32)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define BINDER_SET_CONTEXT_MGR _IOW('b', 7, __s32)
-#define BINDER_THREAD_EXIT _IOW('b', 8, __s32)
-#define BINDER_VERSION _IOWR('b', 9, struct binder_version)
-enum transaction_flags {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  TF_ONE_WAY = 0x01,
-  TF_ROOT_OBJECT = 0x04,
-  TF_STATUS_CODE = 0x08,
-  TF_ACCEPT_FDS = 0x10,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-};
-struct binder_transaction_data {
-  union {
-    __u32 handle;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-    binder_uintptr_t ptr;
-  } target;
-  binder_uintptr_t cookie;
-  __u32 code;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u32 flags;
-  pid_t sender_pid;
-  uid_t sender_euid;
-  binder_size_t data_size;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  binder_size_t offsets_size;
-  union {
-    struct {
-      binder_uintptr_t buffer;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-      binder_uintptr_t offsets;
-    } ptr;
-    __u8 buf[8];
-  } data;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-};
-struct binder_ptr_cookie {
-  binder_uintptr_t ptr;
-  binder_uintptr_t cookie;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-};
-struct binder_handle_cookie {
-  __u32 handle;
-  binder_uintptr_t cookie;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-} __packed;
-struct binder_pri_desc {
-  __s32 priority;
-  __u32 desc;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-};
-struct binder_pri_ptr_cookie {
-  __s32 priority;
-  binder_uintptr_t ptr;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  binder_uintptr_t cookie;
-};
-enum binder_driver_return_protocol {
-  BR_ERROR = _IOR('r', 0, __s32),
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  BR_OK = _IO('r', 1),
-  BR_TRANSACTION = _IOR('r', 2, struct binder_transaction_data),
-  BR_REPLY = _IOR('r', 3, struct binder_transaction_data),
-  BR_ACQUIRE_RESULT = _IOR('r', 4, __s32),
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  BR_DEAD_REPLY = _IO('r', 5),
-  BR_TRANSACTION_COMPLETE = _IO('r', 6),
-  BR_INCREFS = _IOR('r', 7, struct binder_ptr_cookie),
-  BR_ACQUIRE = _IOR('r', 8, struct binder_ptr_cookie),
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  BR_RELEASE = _IOR('r', 9, struct binder_ptr_cookie),
-  BR_DECREFS = _IOR('r', 10, struct binder_ptr_cookie),
-  BR_ATTEMPT_ACQUIRE = _IOR('r', 11, struct binder_pri_ptr_cookie),
-  BR_NOOP = _IO('r', 12),
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  BR_SPAWN_LOOPER = _IO('r', 13),
-  BR_FINISHED = _IO('r', 14),
-  BR_DEAD_BINDER = _IOR('r', 15, binder_uintptr_t),
-  BR_CLEAR_DEATH_NOTIFICATION_DONE = _IOR('r', 16, binder_uintptr_t),
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  BR_FAILED_REPLY = _IO('r', 17),
-};
-enum binder_driver_command_protocol {
-  BC_TRANSACTION = _IOW('c', 0, struct binder_transaction_data),
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  BC_REPLY = _IOW('c', 1, struct binder_transaction_data),
-  BC_ACQUIRE_RESULT = _IOW('c', 2, __s32),
-  BC_FREE_BUFFER = _IOW('c', 3, binder_uintptr_t),
-  BC_INCREFS = _IOW('c', 4, __u32),
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  BC_ACQUIRE = _IOW('c', 5, __u32),
-  BC_RELEASE = _IOW('c', 6, __u32),
-  BC_DECREFS = _IOW('c', 7, __u32),
-  BC_INCREFS_DONE = _IOW('c', 8, struct binder_ptr_cookie),
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  BC_ACQUIRE_DONE = _IOW('c', 9, struct binder_ptr_cookie),
-  BC_ATTEMPT_ACQUIRE = _IOW('c', 10, struct binder_pri_desc),
-  BC_REGISTER_LOOPER = _IO('c', 11),
-  BC_ENTER_LOOPER = _IO('c', 12),
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  BC_EXIT_LOOPER = _IO('c', 13),
-  BC_REQUEST_DEATH_NOTIFICATION = _IOW('c', 14, struct binder_handle_cookie),
-  BC_CLEAR_DEATH_NOTIFICATION = _IOW('c', 15, struct binder_handle_cookie),
-  BC_DEAD_BINDER_DONE = _IOW('c', 16, binder_uintptr_t),
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-};
-#endif
diff --git a/libc/kernel/uapi/linux/if.h b/libc/kernel/uapi/linux/if.h
index f7b4e22..fb93c48 100644
--- a/libc/kernel/uapi/linux/if.h
+++ b/libc/kernel/uapi/linux/if.h
@@ -18,63 +18,58 @@
  ****************************************************************************/
 #ifndef _LINUX_IF_H
 #define _LINUX_IF_H
+#include <linux/libc-compat.h>
 #include <linux/types.h>
-#include <linux/socket.h>
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#include <linux/socket.h>
 #include <linux/compiler.h>
+#if __UAPI_DEF_IF_IFNAMSIZ
 #define IFNAMSIZ 16
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
 #define IFALIASZ 256
 #include <linux/hdlc/ioctl.h>
+#if __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO != 0 && __UAPI_DEF_IF_NET_DEVICE_FLAGS != 0
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum net_device_flags {
-  IFF_UP = 1 << 0,
-  IFF_BROADCAST = 1 << 1,
-  IFF_DEBUG = 1 << 2,
+#if __UAPI_DEF_IF_NET_DEVICE_FLAGS
+  IFF_UP = 1 << 0, IFF_BROADCAST = 1 << 1, IFF_DEBUG = 1 << 2, IFF_LOOPBACK = 1 << 3, IFF_POINTOPOINT = 1 << 4, IFF_NOTRAILERS = 1 << 5, IFF_RUNNING = 1 << 6, IFF_NOARP = 1 << 7, IFF_PROMISC = 1 << 8, IFF_ALLMULTI = 1 << 9, IFF_MASTER = 1 << 10, IFF_SLAVE = 1 << 11, IFF_MULTICAST = 1 << 12, IFF_PORTSEL = 1 << 13, IFF_AUTOMEDIA = 1 << 14, IFF_DYNAMIC = 1 << 15,
+#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  IFF_LOOPBACK = 1 << 3,
-  IFF_POINTOPOINT = 1 << 4,
-  IFF_NOTRAILERS = 1 << 5,
-  IFF_RUNNING = 1 << 6,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  IFF_NOARP = 1 << 7,
-  IFF_PROMISC = 1 << 8,
-  IFF_ALLMULTI = 1 << 9,
-  IFF_MASTER = 1 << 10,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  IFF_SLAVE = 1 << 11,
-  IFF_MULTICAST = 1 << 12,
-  IFF_PORTSEL = 1 << 13,
-  IFF_AUTOMEDIA = 1 << 14,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  IFF_DYNAMIC = 1 << 15,
-  IFF_LOWER_UP = 1 << 16,
-  IFF_DORMANT = 1 << 17,
-  IFF_ECHO = 1 << 18,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#if __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
+  IFF_LOWER_UP = 1 << 16, IFF_DORMANT = 1 << 17, IFF_ECHO = 1 << 18,
+#endif
 };
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
+#if __UAPI_DEF_IF_NET_DEVICE_FLAGS
 #define IFF_UP IFF_UP
 #define IFF_BROADCAST IFF_BROADCAST
-#define IFF_DEBUG IFF_DEBUG
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IFF_DEBUG IFF_DEBUG
 #define IFF_LOOPBACK IFF_LOOPBACK
 #define IFF_POINTOPOINT IFF_POINTOPOINT
 #define IFF_NOTRAILERS IFF_NOTRAILERS
-#define IFF_RUNNING IFF_RUNNING
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IFF_RUNNING IFF_RUNNING
 #define IFF_NOARP IFF_NOARP
 #define IFF_PROMISC IFF_PROMISC
 #define IFF_ALLMULTI IFF_ALLMULTI
-#define IFF_MASTER IFF_MASTER
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IFF_MASTER IFF_MASTER
 #define IFF_SLAVE IFF_SLAVE
 #define IFF_MULTICAST IFF_MULTICAST
 #define IFF_PORTSEL IFF_PORTSEL
-#define IFF_AUTOMEDIA IFF_AUTOMEDIA
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define IFF_AUTOMEDIA IFF_AUTOMEDIA
 #define IFF_DYNAMIC IFF_DYNAMIC
+#endif
+#if __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IFF_LOWER_UP IFF_LOWER_UP
 #define IFF_DORMANT IFF_DORMANT
 #define IFF_ECHO IFF_ECHO
+#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define IFF_VOLATILE (IFF_LOOPBACK | IFF_POINTOPOINT | IFF_BROADCAST | IFF_ECHO | IFF_MASTER | IFF_SLAVE | IFF_RUNNING | IFF_LOWER_UP | IFF_DORMANT)
 #define IF_GET_IFACE 0x0001
@@ -121,58 +116,63 @@
   IF_LINK_MODE_DORMANT,
 };
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#if __UAPI_DEF_IF_IFMAP
 struct ifmap {
   unsigned long mem_start;
   unsigned long mem_end;
-  unsigned short base_addr;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+  unsigned short base_addr;
   unsigned char irq;
   unsigned char dma;
   unsigned char port;
-};
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#endif
 struct if_settings {
   unsigned int type;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
   unsigned int size;
   union {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
     raw_hdlc_proto __user * raw_hdlc;
     cisco_proto __user * cisco;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
     fr_proto __user * fr;
     fr_proto_pvc __user * fr_pvc;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
     fr_proto_pvc_info __user * fr_pvc_info;
     sync_serial_settings __user * sync;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
     te1_settings __user * te1;
   } ifs_ifsu;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+#if __UAPI_DEF_IF_IFREQ
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 struct ifreq {
 #define IFHWADDRLEN 6
   union {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
     char ifrn_name[IFNAMSIZ];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
   } ifr_ifrn;
   union {
     struct sockaddr ifru_addr;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
     struct sockaddr ifru_dstaddr;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
     struct sockaddr ifru_broadaddr;
     struct sockaddr ifru_netmask;
     struct sockaddr ifru_hwaddr;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
     short ifru_flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
     int ifru_ivalue;
     int ifru_mtu;
     struct ifmap ifru_map;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
     char ifru_slave[IFNAMSIZ];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
     char ifru_newname[IFNAMSIZ];
     void __user * ifru_data;
     struct if_settings ifru_settings;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
   } ifr_ifru;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
+#endif
 #define ifr_name ifr_ifrn.ifrn_name
 #define ifr_hwaddr ifr_ifru.ifru_hwaddr
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
@@ -194,16 +194,18 @@
 #define ifr_qlen ifr_ifru.ifru_ivalue
 #define ifr_newname ifr_ifru.ifru_newname
 #define ifr_settings ifr_ifru.ifru_settings
-struct ifconf {
+#if __UAPI_DEF_IF_IFCONF
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct ifconf {
   int ifc_len;
   union {
     char __user * ifcu_buf;
-    struct ifreq __user * ifcu_req;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+    struct ifreq __user * ifcu_req;
   } ifc_ifcu;
 };
+#endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ifc_buf ifc_ifcu.ifcu_buf
 #define ifc_req ifc_ifcu.ifcu_req
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
diff --git a/libc/kernel/uapi/linux/if_pppolac.h b/libc/kernel/uapi/linux/if_pppolac.h
deleted file mode 100644
index 303a899..0000000
--- a/libc/kernel/uapi/linux/if_pppolac.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/****************************************************************************
- ****************************************************************************
- ***
- ***   This header was automatically generated from a Linux kernel header
- ***   of the same name, to make information necessary for userspace to
- ***   call into the kernel available to libc.  It contains only constants,
- ***   structures, and macros generated from the original header, and thus,
- ***   contains no copyrightable information.
- ***
- ***   To edit the content of this header, modify the corresponding
- ***   source file (e.g. under external/kernel-headers/original/) then
- ***   run bionic/libc/kernel/tools/update_all.py
- ***
- ***   Any manual change here will be lost the next time this script will
- ***   be run. You've been warned!
- ***
- ****************************************************************************
- ****************************************************************************/
-#ifndef _UAPI_LINUX_IF_PPPOLAC_H
-#define _UAPI_LINUX_IF_PPPOLAC_H
-#include <linux/socket.h>
-#include <linux/types.h>
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-struct sockaddr_pppolac {
-  sa_family_t sa_family;
-  unsigned int sa_protocol;
-  int udp_socket;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  struct __attribute__((packed)) {
-    __u16 tunnel, session;
-  } local, remote;
-} __attribute__((packed));
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#endif
diff --git a/libc/kernel/uapi/linux/if_pppopns.h b/libc/kernel/uapi/linux/if_pppopns.h
deleted file mode 100644
index bd96e94..0000000
--- a/libc/kernel/uapi/linux/if_pppopns.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/****************************************************************************
- ****************************************************************************
- ***
- ***   This header was automatically generated from a Linux kernel header
- ***   of the same name, to make information necessary for userspace to
- ***   call into the kernel available to libc.  It contains only constants,
- ***   structures, and macros generated from the original header, and thus,
- ***   contains no copyrightable information.
- ***
- ***   To edit the content of this header, modify the corresponding
- ***   source file (e.g. under external/kernel-headers/original/) then
- ***   run bionic/libc/kernel/tools/update_all.py
- ***
- ***   Any manual change here will be lost the next time this script will
- ***   be run. You've been warned!
- ***
- ****************************************************************************
- ****************************************************************************/
-#ifndef _UAPI_LINUX_IF_PPPOPNS_H
-#define _UAPI_LINUX_IF_PPPOPNS_H
-#include <linux/socket.h>
-#include <linux/types.h>
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-struct sockaddr_pppopns {
-  sa_family_t sa_family;
-  unsigned int sa_protocol;
-  int tcp_socket;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u16 local;
-  __u16 remote;
-} __attribute__((packed));
-#endif
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/ioprio.h b/libc/kernel/uapi/linux/ioprio.h
deleted file mode 100644
index 5886e77..0000000
--- a/libc/kernel/uapi/linux/ioprio.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/****************************************************************************
- ****************************************************************************
- ***
- ***   This header was automatically generated from a Linux kernel header
- ***   of the same name, to make information necessary for userspace to
- ***   call into the kernel available to libc.  It contains only constants,
- ***   structures, and macros generated from the original header, and thus,
- ***   contains no copyrightable information.
- ***
- ***   To edit the content of this header, modify the corresponding
- ***   source file (e.g. under external/kernel-headers/original/) then
- ***   run bionic/libc/kernel/tools/update_all.py
- ***
- ***   Any manual change here will be lost the next time this script will
- ***   be run. You've been warned!
- ***
- ****************************************************************************
- ****************************************************************************/
-#ifndef _UAPI_LINUX_IOPRIO_H
-#define _UAPI_LINUX_IOPRIO_H
-#define IOPRIO_BITS (16)
-#define IOPRIO_CLASS_SHIFT (13)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define IOPRIO_PRIO_MASK ((1UL << IOPRIO_CLASS_SHIFT) - 1)
-#define IOPRIO_PRIO_CLASS(mask) ((mask) >> IOPRIO_CLASS_SHIFT)
-#define IOPRIO_PRIO_DATA(mask) ((mask) & IOPRIO_PRIO_MASK)
-#define IOPRIO_PRIO_VALUE(class,data) (((class) << IOPRIO_CLASS_SHIFT) | data)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define ioprio_valid(mask) (IOPRIO_PRIO_CLASS((mask)) != IOPRIO_CLASS_NONE)
-enum {
-  IOPRIO_CLASS_NONE,
-  IOPRIO_CLASS_RT,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  IOPRIO_CLASS_BE,
-  IOPRIO_CLASS_IDLE,
-};
-#define IOPRIO_BE_NR (8)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-enum {
-  IOPRIO_WHO_PROCESS = 1,
-  IOPRIO_WHO_PGRP,
-  IOPRIO_WHO_USER,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-};
-#define IOPRIO_NORM (4)
-#endif
diff --git a/libc/kernel/uapi/linux/libc-compat.h b/libc/kernel/uapi/linux/libc-compat.h
index c91df87..6c95cff 100644
--- a/libc/kernel/uapi/linux/libc-compat.h
+++ b/libc/kernel/uapi/linux/libc-compat.h
@@ -19,76 +19,105 @@
 #ifndef _UAPI_LIBC_COMPAT_H
 #define _UAPI_LIBC_COMPAT_H
 #ifdef __GLIBC__
-#ifdef _NETINET_IN_H
+#ifdef _NET_IF_H
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define __UAPI_DEF_IF_IFCONF 0
+#define __UAPI_DEF_IF_IFMAP 0
+#define __UAPI_DEF_IF_IFNAMSIZ 0
+#define __UAPI_DEF_IF_IFREQ 0
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define __UAPI_DEF_IF_NET_DEVICE_FLAGS 0
+#ifndef __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
+#define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1
+#endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#else
+#define __UAPI_DEF_IF_IFCONF 1
+#define __UAPI_DEF_IF_IFMAP 1
+#define __UAPI_DEF_IF_IFNAMSIZ 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define __UAPI_DEF_IF_IFREQ 1
+#define __UAPI_DEF_IF_NET_DEVICE_FLAGS 1
+#define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1
+#endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#ifdef _NETINET_IN_H
 #define __UAPI_DEF_IN_ADDR 0
 #define __UAPI_DEF_IN_IPPROTO 0
 #define __UAPI_DEF_IN_PKTINFO 0
-#define __UAPI_DEF_IP_MREQ 0
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define __UAPI_DEF_IP_MREQ 0
 #define __UAPI_DEF_SOCKADDR_IN 0
 #define __UAPI_DEF_IN_CLASS 0
 #define __UAPI_DEF_IN6_ADDR 0
-#if defined(__USE_MISC) || defined(__USE_GNU)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#if defined(__USE_MISC) || defined(__USE_GNU)
 #define __UAPI_DEF_IN6_ADDR_ALT 0
 #else
 #define __UAPI_DEF_IN6_ADDR_ALT 1
-#endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
 #define __UAPI_DEF_SOCKADDR_IN6 0
 #define __UAPI_DEF_IPV6_MREQ 0
 #define __UAPI_DEF_IPPROTO_V6 0
-#define __UAPI_DEF_IPV6_OPTIONS 0
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define __UAPI_DEF_IPV6_OPTIONS 0
 #define __UAPI_DEF_IN6_PKTINFO 0
 #define __UAPI_DEF_IP6_MTUINFO 0
 #else
-#define __UAPI_DEF_IN_ADDR 1
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define __UAPI_DEF_IN_ADDR 1
 #define __UAPI_DEF_IN_IPPROTO 1
 #define __UAPI_DEF_IN_PKTINFO 1
 #define __UAPI_DEF_IP_MREQ 1
-#define __UAPI_DEF_SOCKADDR_IN 1
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define __UAPI_DEF_SOCKADDR_IN 1
 #define __UAPI_DEF_IN_CLASS 1
 #define __UAPI_DEF_IN6_ADDR 1
 #define __UAPI_DEF_IN6_ADDR_ALT 1
-#define __UAPI_DEF_SOCKADDR_IN6 1
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define __UAPI_DEF_SOCKADDR_IN6 1
 #define __UAPI_DEF_IPV6_MREQ 1
 #define __UAPI_DEF_IPPROTO_V6 1
 #define __UAPI_DEF_IPV6_OPTIONS 1
-#define __UAPI_DEF_IN6_PKTINFO 1
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define __UAPI_DEF_IN6_PKTINFO 1
 #define __UAPI_DEF_IP6_MTUINFO 1
 #endif
 #ifdef _SYS_XATTR_H
-#define __UAPI_DEF_XATTR 0
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define __UAPI_DEF_XATTR 0
 #else
 #define __UAPI_DEF_XATTR 1
 #endif
-#else
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#else
+#define __UAPI_DEF_IF_IFCONF 1
+#define __UAPI_DEF_IF_IFMAP 1
+#define __UAPI_DEF_IF_IFNAMSIZ 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define __UAPI_DEF_IF_IFREQ 1
+#define __UAPI_DEF_IF_NET_DEVICE_FLAGS 1
+#define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1
 #define __UAPI_DEF_IN_ADDR 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __UAPI_DEF_IN_IPPROTO 1
 #define __UAPI_DEF_IN_PKTINFO 1
 #define __UAPI_DEF_IP_MREQ 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __UAPI_DEF_SOCKADDR_IN 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __UAPI_DEF_IN_CLASS 1
 #define __UAPI_DEF_IN6_ADDR 1
 #define __UAPI_DEF_IN6_ADDR_ALT 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __UAPI_DEF_SOCKADDR_IN6 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __UAPI_DEF_IPV6_MREQ 1
 #define __UAPI_DEF_IPPROTO_V6 1
 #define __UAPI_DEF_IPV6_OPTIONS 1
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __UAPI_DEF_IN6_PKTINFO 1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define __UAPI_DEF_IP6_MTUINFO 1
 #define __UAPI_DEF_XATTR 1
 #endif
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/kernel/uapi/linux/netfilter_bridge/ebt_ulog.h b/libc/kernel/uapi/linux/netfilter_bridge/ebt_ulog.h
deleted file mode 100644
index 029d6b1..0000000
--- a/libc/kernel/uapi/linux/netfilter_bridge/ebt_ulog.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/****************************************************************************
- ****************************************************************************
- ***
- ***   This header was automatically generated from a Linux kernel header
- ***   of the same name, to make information necessary for userspace to
- ***   call into the kernel available to libc.  It contains only constants,
- ***   structures, and macros generated from the original header, and thus,
- ***   contains no copyrightable information.
- ***
- ***   To edit the content of this header, modify the corresponding
- ***   source file (e.g. under external/kernel-headers/original/) then
- ***   run bionic/libc/kernel/tools/update_all.py
- ***
- ***   Any manual change here will be lost the next time this script will
- ***   be run. You've been warned!
- ***
- ****************************************************************************
- ****************************************************************************/
-#ifndef _EBT_ULOG_H
-#define _EBT_ULOG_H
-#include <linux/types.h>
-#define EBT_ULOG_DEFAULT_NLGROUP 0
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define EBT_ULOG_DEFAULT_QTHRESHOLD 1
-#define EBT_ULOG_MAXNLGROUPS 32
-#define EBT_ULOG_PREFIX_LEN 32
-#define EBT_ULOG_MAX_QLEN 50
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define EBT_ULOG_WATCHER "ulog"
-#define EBT_ULOG_VERSION 1
-struct ebt_ulog_info {
-  __u32 nlgroup;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  unsigned int cprange;
-  unsigned int qthreshold;
-  char prefix[EBT_ULOG_PREFIX_LEN];
-};
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-typedef struct ebt_ulog_packet_msg {
-  int version;
-  char indev[IFNAMSIZ];
-  char outdev[IFNAMSIZ];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  char physindev[IFNAMSIZ];
-  char physoutdev[IFNAMSIZ];
-  char prefix[EBT_ULOG_PREFIX_LEN];
-  struct timeval stamp;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  unsigned long mark;
-  unsigned int hook;
-  size_t data_len;
-  unsigned char data[0] __attribute__((aligned(__alignof__(struct ebt_ulog_info))));
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-} ebt_ulog_packet_msg_t;
-#endif
diff --git a/libc/kernel/uapi/linux/nvme.h b/libc/kernel/uapi/linux/nvme.h
deleted file mode 100644
index 030f01c..0000000
--- a/libc/kernel/uapi/linux/nvme.h
+++ /dev/null
@@ -1,595 +0,0 @@
-/****************************************************************************
- ****************************************************************************
- ***
- ***   This header was automatically generated from a Linux kernel header
- ***   of the same name, to make information necessary for userspace to
- ***   call into the kernel available to libc.  It contains only constants,
- ***   structures, and macros generated from the original header, and thus,
- ***   contains no copyrightable information.
- ***
- ***   To edit the content of this header, modify the corresponding
- ***   source file (e.g. under external/kernel-headers/original/) then
- ***   run bionic/libc/kernel/tools/update_all.py
- ***
- ***   Any manual change here will be lost the next time this script will
- ***   be run. You've been warned!
- ***
- ****************************************************************************
- ****************************************************************************/
-#ifndef _UAPI_LINUX_NVME_H
-#define _UAPI_LINUX_NVME_H
-#include <linux/types.h>
-struct nvme_id_power_state {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __le16 max_power;
-  __u8 rsvd2;
-  __u8 flags;
-  __le32 entry_lat;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __le32 exit_lat;
-  __u8 read_tput;
-  __u8 read_lat;
-  __u8 write_tput;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 write_lat;
-  __le16 idle_power;
-  __u8 idle_scale;
-  __u8 rsvd19;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __le16 active_power;
-  __u8 active_work_scale;
-  __u8 rsvd23[9];
-};
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-enum {
-  NVME_PS_FLAGS_MAX_POWER_SCALE = 1 << 0,
-  NVME_PS_FLAGS_NON_OP_STATE = 1 << 1,
-};
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-struct nvme_id_ctrl {
-  __le16 vid;
-  __le16 ssvid;
-  char sn[20];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  char mn[40];
-  char fr[8];
-  __u8 rab;
-  __u8 ieee[3];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 mic;
-  __u8 mdts;
-  __u16 cntlid;
-  __u32 ver;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 rsvd84[172];
-  __le16 oacs;
-  __u8 acl;
-  __u8 aerl;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 frmw;
-  __u8 lpa;
-  __u8 elpe;
-  __u8 npss;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 avscc;
-  __u8 apsta;
-  __le16 wctemp;
-  __le16 cctemp;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 rsvd270[242];
-  __u8 sqes;
-  __u8 cqes;
-  __u8 rsvd514[2];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __le32 nn;
-  __le16 oncs;
-  __le16 fuses;
-  __u8 fna;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 vwc;
-  __le16 awun;
-  __le16 awupf;
-  __u8 nvscc;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 rsvd531;
-  __le16 acwu;
-  __u8 rsvd534[2];
-  __le32 sgls;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 rsvd540[1508];
-  struct nvme_id_power_state psd[32];
-  __u8 vs[1024];
-};
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-enum {
-  NVME_CTRL_ONCS_COMPARE = 1 << 0,
-  NVME_CTRL_ONCS_WRITE_UNCORRECTABLE = 1 << 1,
-  NVME_CTRL_ONCS_DSM = 1 << 2,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_CTRL_VWC_PRESENT = 1 << 0,
-};
-struct nvme_lbaf {
-  __le16 ms;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 ds;
-  __u8 rp;
-};
-struct nvme_id_ns {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __le64 nsze;
-  __le64 ncap;
-  __le64 nuse;
-  __u8 nsfeat;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 nlbaf;
-  __u8 flbas;
-  __u8 mc;
-  __u8 dpc;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 dps;
-  __u8 nmic;
-  __u8 rescap;
-  __u8 fpi;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 rsvd33;
-  __le16 nawun;
-  __le16 nawupf;
-  __le16 nacwu;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 rsvd40[80];
-  __u8 eui64[8];
-  struct nvme_lbaf lbaf[16];
-  __u8 rsvd192[192];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 vs[3712];
-};
-enum {
-  NVME_NS_FEAT_THIN = 1 << 0,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_LBAF_RP_BEST = 0,
-  NVME_LBAF_RP_BETTER = 1,
-  NVME_LBAF_RP_GOOD = 2,
-  NVME_LBAF_RP_DEGRADED = 3,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-};
-struct nvme_smart_log {
-  __u8 critical_warning;
-  __u8 temperature[2];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 avail_spare;
-  __u8 spare_thresh;
-  __u8 percent_used;
-  __u8 rsvd6[26];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 data_units_read[16];
-  __u8 data_units_written[16];
-  __u8 host_reads[16];
-  __u8 host_writes[16];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 ctrl_busy_time[16];
-  __u8 power_cycles[16];
-  __u8 power_on_hours[16];
-  __u8 unsafe_shutdowns[16];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 media_errors[16];
-  __u8 num_err_log_entries[16];
-  __le32 warning_temp_time;
-  __le32 critical_comp_time;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __le16 temp_sensor[8];
-  __u8 rsvd216[296];
-};
-enum {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_SMART_CRIT_SPARE = 1 << 0,
-  NVME_SMART_CRIT_TEMPERATURE = 1 << 1,
-  NVME_SMART_CRIT_RELIABILITY = 1 << 2,
-  NVME_SMART_CRIT_MEDIA = 1 << 3,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_SMART_CRIT_VOLATILE_MEMORY = 1 << 4,
-};
-struct nvme_lba_range_type {
-  __u8 type;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 attributes;
-  __u8 rsvd2[14];
-  __u64 slba;
-  __u64 nlb;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 guid[16];
-  __u8 rsvd48[16];
-};
-enum {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_LBART_TYPE_FS = 0x01,
-  NVME_LBART_TYPE_RAID = 0x02,
-  NVME_LBART_TYPE_CACHE = 0x03,
-  NVME_LBART_TYPE_SWAP = 0x04,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_LBART_ATTRIB_TEMP = 1 << 0,
-  NVME_LBART_ATTRIB_HIDE = 1 << 1,
-};
-enum nvme_opcode {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  nvme_cmd_flush = 0x00,
-  nvme_cmd_write = 0x01,
-  nvme_cmd_read = 0x02,
-  nvme_cmd_write_uncor = 0x04,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  nvme_cmd_compare = 0x05,
-  nvme_cmd_dsm = 0x09,
-};
-struct nvme_common_command {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 opcode;
-  __u8 flags;
-  __u16 command_id;
-  __le32 nsid;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __le32 cdw2[2];
-  __le64 metadata;
-  __le64 prp1;
-  __le64 prp2;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __le32 cdw10[6];
-};
-struct nvme_rw_command {
-  __u8 opcode;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 flags;
-  __u16 command_id;
-  __le32 nsid;
-  __u64 rsvd2;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __le64 metadata;
-  __le64 prp1;
-  __le64 prp2;
-  __le64 slba;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __le16 length;
-  __le16 control;
-  __le32 dsmgmt;
-  __le32 reftag;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __le16 apptag;
-  __le16 appmask;
-};
-enum {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_RW_LR = 1 << 15,
-  NVME_RW_FUA = 1 << 14,
-  NVME_RW_DSM_FREQ_UNSPEC = 0,
-  NVME_RW_DSM_FREQ_TYPICAL = 1,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_RW_DSM_FREQ_RARE = 2,
-  NVME_RW_DSM_FREQ_READS = 3,
-  NVME_RW_DSM_FREQ_WRITES = 4,
-  NVME_RW_DSM_FREQ_RW = 5,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_RW_DSM_FREQ_ONCE = 6,
-  NVME_RW_DSM_FREQ_PREFETCH = 7,
-  NVME_RW_DSM_FREQ_TEMP = 8,
-  NVME_RW_DSM_LATENCY_NONE = 0 << 4,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_RW_DSM_LATENCY_IDLE = 1 << 4,
-  NVME_RW_DSM_LATENCY_NORM = 2 << 4,
-  NVME_RW_DSM_LATENCY_LOW = 3 << 4,
-  NVME_RW_DSM_SEQ_REQ = 1 << 6,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_RW_DSM_COMPRESSED = 1 << 7,
-};
-struct nvme_dsm_cmd {
-  __u8 opcode;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 flags;
-  __u16 command_id;
-  __le32 nsid;
-  __u64 rsvd2[2];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __le64 prp1;
-  __le64 prp2;
-  __le32 nr;
-  __le32 attributes;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u32 rsvd12[4];
-};
-enum {
-  NVME_DSMGMT_IDR = 1 << 0,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_DSMGMT_IDW = 1 << 1,
-  NVME_DSMGMT_AD = 1 << 2,
-};
-struct nvme_dsm_range {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __le32 cattr;
-  __le32 nlb;
-  __le64 slba;
-};
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-enum nvme_admin_opcode {
-  nvme_admin_delete_sq = 0x00,
-  nvme_admin_create_sq = 0x01,
-  nvme_admin_get_log_page = 0x02,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  nvme_admin_delete_cq = 0x04,
-  nvme_admin_create_cq = 0x05,
-  nvme_admin_identify = 0x06,
-  nvme_admin_abort_cmd = 0x08,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  nvme_admin_set_features = 0x09,
-  nvme_admin_get_features = 0x0a,
-  nvme_admin_async_event = 0x0c,
-  nvme_admin_activate_fw = 0x10,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  nvme_admin_download_fw = 0x11,
-  nvme_admin_format_nvm = 0x80,
-  nvme_admin_security_send = 0x81,
-  nvme_admin_security_recv = 0x82,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-};
-enum {
-  NVME_QUEUE_PHYS_CONTIG = (1 << 0),
-  NVME_CQ_IRQ_ENABLED = (1 << 1),
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_SQ_PRIO_URGENT = (0 << 1),
-  NVME_SQ_PRIO_HIGH = (1 << 1),
-  NVME_SQ_PRIO_MEDIUM = (2 << 1),
-  NVME_SQ_PRIO_LOW = (3 << 1),
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_FEAT_ARBITRATION = 0x01,
-  NVME_FEAT_POWER_MGMT = 0x02,
-  NVME_FEAT_LBA_RANGE = 0x03,
-  NVME_FEAT_TEMP_THRESH = 0x04,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_FEAT_ERR_RECOVERY = 0x05,
-  NVME_FEAT_VOLATILE_WC = 0x06,
-  NVME_FEAT_NUM_QUEUES = 0x07,
-  NVME_FEAT_IRQ_COALESCE = 0x08,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_FEAT_IRQ_CONFIG = 0x09,
-  NVME_FEAT_WRITE_ATOMIC = 0x0a,
-  NVME_FEAT_ASYNC_EVENT = 0x0b,
-  NVME_FEAT_SW_PROGRESS = 0x0c,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_LOG_ERROR = 0x01,
-  NVME_LOG_SMART = 0x02,
-  NVME_LOG_FW_SLOT = 0x03,
-  NVME_LOG_RESERVATION = 0x80,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_FWACT_REPL = (0 << 3),
-  NVME_FWACT_REPL_ACTV = (1 << 3),
-  NVME_FWACT_ACTV = (2 << 3),
-};
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-struct nvme_identify {
-  __u8 opcode;
-  __u8 flags;
-  __u16 command_id;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __le32 nsid;
-  __u64 rsvd2[2];
-  __le64 prp1;
-  __le64 prp2;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __le32 cns;
-  __u32 rsvd11[5];
-};
-struct nvme_features {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 opcode;
-  __u8 flags;
-  __u16 command_id;
-  __le32 nsid;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u64 rsvd2[2];
-  __le64 prp1;
-  __le64 prp2;
-  __le32 fid;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __le32 dword11;
-  __u32 rsvd12[4];
-};
-struct nvme_create_cq {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 opcode;
-  __u8 flags;
-  __u16 command_id;
-  __u32 rsvd1[5];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __le64 prp1;
-  __u64 rsvd8;
-  __le16 cqid;
-  __le16 qsize;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __le16 cq_flags;
-  __le16 irq_vector;
-  __u32 rsvd12[4];
-};
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-struct nvme_create_sq {
-  __u8 opcode;
-  __u8 flags;
-  __u16 command_id;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u32 rsvd1[5];
-  __le64 prp1;
-  __u64 rsvd8;
-  __le16 sqid;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __le16 qsize;
-  __le16 sq_flags;
-  __le16 cqid;
-  __u32 rsvd12[4];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-};
-struct nvme_delete_queue {
-  __u8 opcode;
-  __u8 flags;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u16 command_id;
-  __u32 rsvd1[9];
-  __le16 qid;
-  __u16 rsvd10;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u32 rsvd11[5];
-};
-struct nvme_abort_cmd {
-  __u8 opcode;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 flags;
-  __u16 command_id;
-  __u32 rsvd1[9];
-  __le16 sqid;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u16 cid;
-  __u32 rsvd11[5];
-};
-struct nvme_download_firmware {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 opcode;
-  __u8 flags;
-  __u16 command_id;
-  __u32 rsvd1[5];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __le64 prp1;
-  __le64 prp2;
-  __le32 numd;
-  __le32 offset;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u32 rsvd12[4];
-};
-struct nvme_format_cmd {
-  __u8 opcode;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 flags;
-  __u16 command_id;
-  __le32 nsid;
-  __u64 rsvd2[4];
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __le32 cdw10;
-  __u32 rsvd11[5];
-};
-struct nvme_command {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  union {
-    struct nvme_common_command common;
-    struct nvme_rw_command rw;
-    struct nvme_identify identify;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-    struct nvme_features features;
-    struct nvme_create_cq create_cq;
-    struct nvme_create_sq create_sq;
-    struct nvme_delete_queue delete_queue;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-    struct nvme_download_firmware dlfw;
-    struct nvme_format_cmd format;
-    struct nvme_dsm_cmd dsm;
-    struct nvme_abort_cmd abort;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  };
-};
-enum {
-  NVME_SC_SUCCESS = 0x0,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_SC_INVALID_OPCODE = 0x1,
-  NVME_SC_INVALID_FIELD = 0x2,
-  NVME_SC_CMDID_CONFLICT = 0x3,
-  NVME_SC_DATA_XFER_ERROR = 0x4,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_SC_POWER_LOSS = 0x5,
-  NVME_SC_INTERNAL = 0x6,
-  NVME_SC_ABORT_REQ = 0x7,
-  NVME_SC_ABORT_QUEUE = 0x8,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_SC_FUSED_FAIL = 0x9,
-  NVME_SC_FUSED_MISSING = 0xa,
-  NVME_SC_INVALID_NS = 0xb,
-  NVME_SC_CMD_SEQ_ERROR = 0xc,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_SC_LBA_RANGE = 0x80,
-  NVME_SC_CAP_EXCEEDED = 0x81,
-  NVME_SC_NS_NOT_READY = 0x82,
-  NVME_SC_CQ_INVALID = 0x100,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_SC_QID_INVALID = 0x101,
-  NVME_SC_QUEUE_SIZE = 0x102,
-  NVME_SC_ABORT_LIMIT = 0x103,
-  NVME_SC_ABORT_MISSING = 0x104,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_SC_ASYNC_LIMIT = 0x105,
-  NVME_SC_FIRMWARE_SLOT = 0x106,
-  NVME_SC_FIRMWARE_IMAGE = 0x107,
-  NVME_SC_INVALID_VECTOR = 0x108,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_SC_INVALID_LOG_PAGE = 0x109,
-  NVME_SC_INVALID_FORMAT = 0x10a,
-  NVME_SC_BAD_ATTRIBUTES = 0x180,
-  NVME_SC_WRITE_FAULT = 0x280,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_SC_READ_ERROR = 0x281,
-  NVME_SC_GUARD_CHECK = 0x282,
-  NVME_SC_APPTAG_CHECK = 0x283,
-  NVME_SC_REFTAG_CHECK = 0x284,
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  NVME_SC_COMPARE_FAILED = 0x285,
-  NVME_SC_ACCESS_DENIED = 0x286,
-  NVME_SC_DNR = 0x4000,
-};
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-struct nvme_completion {
-  __le32 result;
-  __u32 rsvd;
-  __le16 sq_head;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __le16 sq_id;
-  __u16 command_id;
-  __le16 status;
-};
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-struct nvme_user_io {
-  __u8 opcode;
-  __u8 flags;
-  __u16 control;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u16 nblocks;
-  __u16 rsvd;
-  __u64 metadata;
-  __u64 addr;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u64 slba;
-  __u32 dsmgmt;
-  __u32 reftag;
-  __u16 apptag;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u16 appmask;
-};
-struct nvme_admin_cmd {
-  __u8 opcode;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u8 flags;
-  __u16 rsvd1;
-  __u32 nsid;
-  __u32 cdw2;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u32 cdw3;
-  __u64 metadata;
-  __u64 addr;
-  __u32 metadata_len;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u32 data_len;
-  __u32 cdw10;
-  __u32 cdw11;
-  __u32 cdw12;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u32 cdw13;
-  __u32 cdw14;
-  __u32 cdw15;
-  __u32 timeout_ms;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  __u32 result;
-};
-#define NVME_IOCTL_ID _IO('N', 0x40)
-#define NVME_IOCTL_ADMIN_CMD _IOWR('N', 0x41, struct nvme_admin_cmd)
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define NVME_IOCTL_SUBMIT_IO _IOW('N', 0x42, struct nvme_user_io)
-#endif
diff --git a/libc/kernel/uapi/linux/som.h b/libc/kernel/uapi/linux/som.h
deleted file mode 100644
index cb76e70..0000000
--- a/libc/kernel/uapi/linux/som.h
+++ /dev/null
@@ -1,170 +0,0 @@
-/****************************************************************************
- ****************************************************************************
- ***
- ***   This header was automatically generated from a Linux kernel header
- ***   of the same name, to make information necessary for userspace to
- ***   call into the kernel available to libc.  It contains only constants,
- ***   structures, and macros generated from the original header, and thus,
- ***   contains no copyrightable information.
- ***
- ***   To edit the content of this header, modify the corresponding
- ***   source file (e.g. under external/kernel-headers/original/) then
- ***   run bionic/libc/kernel/tools/update_all.py
- ***
- ***   Any manual change here will be lost the next time this script will
- ***   be run. You've been warned!
- ***
- ****************************************************************************
- ****************************************************************************/
-#ifndef _LINUX_SOM_H
-#define _LINUX_SOM_H
-#include <linux/time.h>
-#define SOM_PAGESIZE 4096
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-struct som_hdr {
-  short system_id;
-  short a_magic;
-  unsigned int version_id;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  struct timespec file_time;
-  unsigned int entry_space;
-  unsigned int entry_subspace;
-  unsigned int entry_offset;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  unsigned int aux_header_location;
-  unsigned int aux_header_size;
-  unsigned int som_length;
-  unsigned int presumed_dp;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  unsigned int space_location;
-  unsigned int space_total;
-  unsigned int subspace_location;
-  unsigned int subspace_total;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  unsigned int loader_fixup_location;
-  unsigned int loader_fixup_total;
-  unsigned int space_strings_location;
-  unsigned int space_strings_size;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  unsigned int init_array_location;
-  unsigned int init_array_total;
-  unsigned int compiler_location;
-  unsigned int compiler_total;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  unsigned int symbol_location;
-  unsigned int symbol_total;
-  unsigned int fixup_request_location;
-  unsigned int fixup_request_total;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  unsigned int symbol_strings_location;
-  unsigned int symbol_strings_size;
-  unsigned int unloadable_sp_location;
-  unsigned int unloadable_sp_size;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  unsigned int checksum;
-};
-#define SOM_SID_PARISC_1_0 0x020b
-#define SOM_SID_PARISC_1_1 0x0210
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define SOM_SID_PARISC_2_0 0x0214
-#define SOM_LIB_EXEC 0x0104
-#define SOM_RELOCATABLE 0x0106
-#define SOM_EXEC_NONSHARE 0x0107
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define SOM_EXEC_SHARE 0x0108
-#define SOM_EXEC_DEMAND 0x010B
-#define SOM_LIB_DYN 0x010D
-#define SOM_LIB_SHARE 0x010E
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define SOM_LIB_RELOC 0x0619
-#define SOM_ID_OLD 85082112
-#define SOM_ID_NEW 87102412
-struct aux_id {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  unsigned int mandatory : 1;
-  unsigned int copy : 1;
-  unsigned int append : 1;
-  unsigned int ignore : 1;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  unsigned int reserved : 12;
-  unsigned int type : 16;
-  unsigned int length;
-};
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-struct som_exec_auxhdr {
-  struct aux_id som_auxhdr;
-  int exec_tsize;
-  int exec_tmem;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  int exec_tfile;
-  int exec_dsize;
-  int exec_dmem;
-  int exec_dfile;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  int exec_bsize;
-  int exec_entry;
-  int exec_flags;
-  int exec_bfill;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-};
-union name_pt {
-  char * n_name;
-  unsigned int n_strx;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-};
-struct space_dictionary_record {
-  union name_pt name;
-  unsigned int is_loadable : 1;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  unsigned int is_defined : 1;
-  unsigned int is_private : 1;
-  unsigned int has_intermediate_code : 1;
-  unsigned int is_tspecific : 1;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  unsigned int reserved : 11;
-  unsigned int sort_key : 8;
-  unsigned int reserved2 : 8;
-  int space_number;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  int subspace_index;
-  unsigned int subspace_quantity;
-  int loader_fix_index;
-  unsigned int loader_fix_quantity;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  int init_pointer_index;
-  unsigned int init_pointer_quantity;
-};
-struct subspace_dictionary_record {
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  int space_index;
-  unsigned int access_control_bits : 7;
-  unsigned int memory_resident : 1;
-  unsigned int dup_common : 1;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  unsigned int is_common : 1;
-  unsigned int quadrant : 2;
-  unsigned int initially_frozen : 1;
-  unsigned int is_first : 1;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  unsigned int code_only : 1;
-  unsigned int sort_key : 8;
-  unsigned int replicate_init : 1;
-  unsigned int continuation : 1;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  unsigned int is_tspecific : 1;
-  unsigned int is_comdat : 1;
-  unsigned int reserved : 4;
-  int file_loc_init_value;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  unsigned int initialization_length;
-  unsigned int subspace_start;
-  unsigned int subspace_length;
-  unsigned int reserved2 : 5;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-  unsigned int alignment : 27;
-  union name_pt name;
-  int fixup_request_index;
-  unsigned int fixup_request_quantity;
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-};
-#endif
diff --git a/libc/kernel/uapi/linux/v4l2-dv-timings.h b/libc/kernel/uapi/linux/v4l2-dv-timings.h
index ac5fb64..2485e28 100644
--- a/libc/kernel/uapi/linux/v4l2-dv-timings.h
+++ b/libc/kernel/uapi/linux/v4l2-dv-timings.h
@@ -63,27 +63,27 @@
 #define V4L2_DV_BT_CEA_1920X1080P60 {.type = V4L2_DV_BT_656_1120, V4L2_INIT_BT_TIMINGS(1920, 1080, 0, V4L2_DV_HSYNC_POS_POL | V4L2_DV_VSYNC_POS_POL, 148500000, 88, 44, 148, 4, 5, 36, 0, 0, 0, V4L2_DV_BT_STD_DMT | V4L2_DV_BT_STD_CEA861, V4L2_DV_FL_CAN_REDUCE_FPS | V4L2_DV_FL_IS_CE_VIDEO) \
 }
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define V4L2_DV_BT_CEA_3840X2160P24 {.type = V4L2_DV_BT_656_1120, V4L2_INIT_BT_TIMINGS(3840, 2160, 0, V4L2_DV_HSYNC_POS_POL, 297000000, 1276, 88, 296, 8, 10, 72, 0, 0, 0, V4L2_DV_BT_STD_CEA861, V4L2_DV_FL_CAN_REDUCE_FPS | V4L2_DV_FL_IS_CE_VIDEO) \
+#define V4L2_DV_BT_CEA_3840X2160P24 {.type = V4L2_DV_BT_656_1120, V4L2_INIT_BT_TIMINGS(3840, 2160, 0, V4L2_DV_HSYNC_POS_POL | V4L2_DV_VSYNC_POS_POL, 297000000, 1276, 88, 296, 8, 10, 72, 0, 0, 0, V4L2_DV_BT_STD_CEA861, V4L2_DV_FL_CAN_REDUCE_FPS | V4L2_DV_FL_IS_CE_VIDEO) \
 }
-#define V4L2_DV_BT_CEA_3840X2160P25 {.type = V4L2_DV_BT_656_1120, V4L2_INIT_BT_TIMINGS(3840, 2160, 0, V4L2_DV_HSYNC_POS_POL, 297000000, 1056, 88, 296, 8, 10, 72, 0, 0, 0, V4L2_DV_BT_STD_CEA861, V4L2_DV_FL_IS_CE_VIDEO) \
+#define V4L2_DV_BT_CEA_3840X2160P25 {.type = V4L2_DV_BT_656_1120, V4L2_INIT_BT_TIMINGS(3840, 2160, 0, V4L2_DV_HSYNC_POS_POL | V4L2_DV_VSYNC_POS_POL, 297000000, 1056, 88, 296, 8, 10, 72, 0, 0, 0, V4L2_DV_BT_STD_CEA861, V4L2_DV_FL_IS_CE_VIDEO) \
 }
-#define V4L2_DV_BT_CEA_3840X2160P30 {.type = V4L2_DV_BT_656_1120, V4L2_INIT_BT_TIMINGS(3840, 2160, 0, V4L2_DV_HSYNC_POS_POL, 297000000, 176, 88, 296, 8, 10, 72, 0, 0, 0, V4L2_DV_BT_STD_CEA861, V4L2_DV_FL_CAN_REDUCE_FPS | V4L2_DV_FL_IS_CE_VIDEO) \
+#define V4L2_DV_BT_CEA_3840X2160P30 {.type = V4L2_DV_BT_656_1120, V4L2_INIT_BT_TIMINGS(3840, 2160, 0, V4L2_DV_HSYNC_POS_POL | V4L2_DV_VSYNC_POS_POL, 297000000, 176, 88, 296, 8, 10, 72, 0, 0, 0, V4L2_DV_BT_STD_CEA861, V4L2_DV_FL_CAN_REDUCE_FPS | V4L2_DV_FL_IS_CE_VIDEO) \
 }
-#define V4L2_DV_BT_CEA_3840X2160P50 {.type = V4L2_DV_BT_656_1120, V4L2_INIT_BT_TIMINGS(3840, 2160, 0, V4L2_DV_HSYNC_POS_POL, 594000000, 1056, 88, 296, 8, 10, 72, 0, 0, 0, V4L2_DV_BT_STD_CEA861, V4L2_DV_FL_IS_CE_VIDEO) \
+#define V4L2_DV_BT_CEA_3840X2160P50 {.type = V4L2_DV_BT_656_1120, V4L2_INIT_BT_TIMINGS(3840, 2160, 0, V4L2_DV_HSYNC_POS_POL | V4L2_DV_VSYNC_POS_POL, 594000000, 1056, 88, 296, 8, 10, 72, 0, 0, 0, V4L2_DV_BT_STD_CEA861, V4L2_DV_FL_IS_CE_VIDEO) \
 }
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define V4L2_DV_BT_CEA_3840X2160P60 {.type = V4L2_DV_BT_656_1120, V4L2_INIT_BT_TIMINGS(3840, 2160, 0, V4L2_DV_HSYNC_POS_POL, 594000000, 176, 88, 296, 8, 10, 72, 0, 0, 0, V4L2_DV_BT_STD_CEA861, V4L2_DV_FL_CAN_REDUCE_FPS | V4L2_DV_FL_IS_CE_VIDEO) \
+#define V4L2_DV_BT_CEA_3840X2160P60 {.type = V4L2_DV_BT_656_1120, V4L2_INIT_BT_TIMINGS(3840, 2160, 0, V4L2_DV_HSYNC_POS_POL | V4L2_DV_VSYNC_POS_POL, 594000000, 176, 88, 296, 8, 10, 72, 0, 0, 0, V4L2_DV_BT_STD_CEA861, V4L2_DV_FL_CAN_REDUCE_FPS | V4L2_DV_FL_IS_CE_VIDEO) \
 }
-#define V4L2_DV_BT_CEA_4096X2160P24 {.type = V4L2_DV_BT_656_1120, V4L2_INIT_BT_TIMINGS(4096, 2160, 0, V4L2_DV_HSYNC_POS_POL, 297000000, 1020, 88, 296, 8, 10, 72, 0, 0, 0, V4L2_DV_BT_STD_CEA861, V4L2_DV_FL_CAN_REDUCE_FPS | V4L2_DV_FL_IS_CE_VIDEO) \
+#define V4L2_DV_BT_CEA_4096X2160P24 {.type = V4L2_DV_BT_656_1120, V4L2_INIT_BT_TIMINGS(4096, 2160, 0, V4L2_DV_HSYNC_POS_POL | V4L2_DV_VSYNC_POS_POL, 297000000, 1020, 88, 296, 8, 10, 72, 0, 0, 0, V4L2_DV_BT_STD_CEA861, V4L2_DV_FL_CAN_REDUCE_FPS | V4L2_DV_FL_IS_CE_VIDEO) \
 }
-#define V4L2_DV_BT_CEA_4096X2160P25 {.type = V4L2_DV_BT_656_1120, V4L2_INIT_BT_TIMINGS(4096, 2160, 0, V4L2_DV_HSYNC_POS_POL, 297000000, 968, 88, 128, 8, 10, 72, 0, 0, 0, V4L2_DV_BT_STD_CEA861, V4L2_DV_FL_IS_CE_VIDEO) \
+#define V4L2_DV_BT_CEA_4096X2160P25 {.type = V4L2_DV_BT_656_1120, V4L2_INIT_BT_TIMINGS(4096, 2160, 0, V4L2_DV_HSYNC_POS_POL | V4L2_DV_VSYNC_POS_POL, 297000000, 968, 88, 128, 8, 10, 72, 0, 0, 0, V4L2_DV_BT_STD_CEA861, V4L2_DV_FL_IS_CE_VIDEO) \
 }
-#define V4L2_DV_BT_CEA_4096X2160P30 {.type = V4L2_DV_BT_656_1120, V4L2_INIT_BT_TIMINGS(4096, 2160, 0, V4L2_DV_HSYNC_POS_POL, 297000000, 88, 88, 128, 8, 10, 72, 0, 0, 0, V4L2_DV_BT_STD_CEA861, V4L2_DV_FL_CAN_REDUCE_FPS | V4L2_DV_FL_IS_CE_VIDEO) \
+#define V4L2_DV_BT_CEA_4096X2160P30 {.type = V4L2_DV_BT_656_1120, V4L2_INIT_BT_TIMINGS(4096, 2160, 0, V4L2_DV_HSYNC_POS_POL | V4L2_DV_VSYNC_POS_POL, 297000000, 88, 88, 128, 8, 10, 72, 0, 0, 0, V4L2_DV_BT_STD_CEA861, V4L2_DV_FL_CAN_REDUCE_FPS | V4L2_DV_FL_IS_CE_VIDEO) \
 }
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define V4L2_DV_BT_CEA_4096X2160P50 {.type = V4L2_DV_BT_656_1120, V4L2_INIT_BT_TIMINGS(4096, 2160, 0, V4L2_DV_HSYNC_POS_POL, 594000000, 968, 88, 128, 8, 10, 72, 0, 0, 0, V4L2_DV_BT_STD_CEA861, V4L2_DV_FL_IS_CE_VIDEO) \
+#define V4L2_DV_BT_CEA_4096X2160P50 {.type = V4L2_DV_BT_656_1120, V4L2_INIT_BT_TIMINGS(4096, 2160, 0, V4L2_DV_HSYNC_POS_POL | V4L2_DV_VSYNC_POS_POL, 594000000, 968, 88, 128, 8, 10, 72, 0, 0, 0, V4L2_DV_BT_STD_CEA861, V4L2_DV_FL_IS_CE_VIDEO) \
 }
-#define V4L2_DV_BT_CEA_4096X2160P60 {.type = V4L2_DV_BT_656_1120, V4L2_INIT_BT_TIMINGS(4096, 2160, 0, V4L2_DV_HSYNC_POS_POL, 594000000, 88, 88, 128, 8, 10, 72, 0, 0, 0, V4L2_DV_BT_STD_CEA861, V4L2_DV_FL_CAN_REDUCE_FPS | V4L2_DV_FL_IS_CE_VIDEO) \
+#define V4L2_DV_BT_CEA_4096X2160P60 {.type = V4L2_DV_BT_656_1120, V4L2_INIT_BT_TIMINGS(4096, 2160, 0, V4L2_DV_HSYNC_POS_POL | V4L2_DV_VSYNC_POS_POL, 594000000, 88, 88, 128, 8, 10, 72, 0, 0, 0, V4L2_DV_BT_STD_CEA861, V4L2_DV_FL_CAN_REDUCE_FPS | V4L2_DV_FL_IS_CE_VIDEO) \
 }
 #define V4L2_DV_BT_DMT_640X350P85 {.type = V4L2_DV_BT_656_1120, V4L2_INIT_BT_TIMINGS(640, 350, 0, V4L2_DV_HSYNC_POS_POL, 31500000, 32, 64, 96, 32, 3, 60, 0, 0, 0, V4L2_DV_BT_STD_DMT, 0) \
 }
diff --git a/libc/kernel/uapi/linux/version.h b/libc/kernel/uapi/linux/version.h
index 7bd7753..dd12026 100644
--- a/libc/kernel/uapi/linux/version.h
+++ b/libc/kernel/uapi/linux/version.h
@@ -16,5 +16,5 @@
  ***
  ****************************************************************************
  ****************************************************************************/
-#define LINUX_VERSION_CODE 263169
+#define LINUX_VERSION_CODE 263179
 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
diff --git a/libc/libc.arm.brillo.map b/libc/libc.arm.brillo.map
index 4e5b5c8..4e8212b 100644
--- a/libc/libc.arm.brillo.map
+++ b/libc/libc.arm.brillo.map
@@ -1,4 +1,4 @@
-# Generated by genversionscripts.py. Do not edit.
+# Generated by genversion-scripts.py. Do not edit.
 LIBC {
   global:
     __assert;
@@ -9,45 +9,44 @@
     __atomic_swap; # arm
     __b64_ntop;
     __b64_pton;
-    __brk; # arm x86 mips
-    __cmsg_nxthdr;
-    __connect; # arm x86 mips
-    __ctype_get_mb_cur_max;
+    __cmsg_nxthdr; # introduced=21
+    __connect; # arm x86 mips introduced=21
+    __ctype_get_mb_cur_max; # introduced=21
     __cxa_atexit;
     __cxa_finalize;
-    __cxa_thread_atexit_impl;
+    __cxa_thread_atexit_impl; # introduced=23
     __dn_comp;
     __dn_count_labels;
     __dn_skipname;
-    __epoll_pwait; # arm x86 mips
+    __epoll_pwait; # arm x86 mips introduced=21
     __errno;
-    __exit; # arm x86 mips
-    __fbufsize;
+    __exit; # arm x86 mips introduced=21
+    __fbufsize; # introduced=23
     __fcntl64; # arm x86 mips
-    __FD_CLR_chk;
-    __FD_ISSET_chk;
-    __FD_SET_chk;
-    __fgets_chk;
-    __flbf;
+    __FD_CLR_chk; # introduced=21
+    __FD_ISSET_chk; # introduced=21
+    __FD_SET_chk; # introduced=21
+    __fgets_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __flbf; # introduced=23
     __fp_nquery;
     __fp_query;
-    __fpclassify;
+    __fpclassify; # introduced=21
     __fpclassifyd;
     __fpclassifyf;
     __fpclassifyl;
-    __fpending;
-    __fpurge;
-    __freadable;
-    __fsetlocking;
+    __fpending; # introduced=23
+    __fpurge; # introduced=23
+    __freadable; # introduced=23
+    __fsetlocking; # introduced=23
     __fstatfs64; # arm x86 mips
-    __fwritable;
+    __fwritable; # introduced=23
     __get_h_errno;
-    __getcpu; # arm x86 mips
+    __getcpu; # arm x86 mips introduced-arm=12 introduced-mips=16 introduced-x86=12
     __getcwd; # arm x86 mips
-    __getpid; # arm x86 mips
+    __getpid; # arm x86 mips introduced=21
     __getpriority; # arm x86 mips
-    __gnu_basename;
-    __gnu_strerror_r;
+    __gnu_basename; # introduced=23
+    __gnu_strerror_r; # introduced=23
     __hostalias;
     __ioctl; # arm x86 mips
     __isfinite;
@@ -56,24 +55,24 @@
     __isinf;
     __isinff;
     __isinfl;
-    __isnan;
-    __isnanf;
+    __isnan; # introduced=21
+    __isnanf; # introduced=21
     __isnanl;
     __isnormal;
     __isnormalf;
     __isnormall;
-    __isthreaded; # arm x86 mips
-    __libc_current_sigrtmax;
-    __libc_current_sigrtmin;
+    __isthreaded; # arm x86 mips var
+    __libc_current_sigrtmax; # introduced=21
+    __libc_current_sigrtmin; # introduced=21
     __libc_init;
     __llseek; # arm x86 mips
     __loc_aton;
     __loc_ntoa;
-    __memchr_chk;
-    __memcpy_chk;
-    __memmove_chk;
-    __memrchr_chk;
-    __memset_chk;
+    __memchr_chk; # introduced=23
+    __memcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __memmove_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __memrchr_chk; # introduced=23
+    __memset_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __mmap2; # arm x86 mips
     __ns_format_ttl; # arm x86 mips
     __ns_get16; # arm x86 mips
@@ -97,13 +96,13 @@
     __ns_skiprr; # arm x86 mips
     __ns_sprintrr; # arm x86 mips
     __ns_sprintrrf; # arm x86 mips
-    __open_2;
+    __open_2; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __openat; # arm x86 mips
-    __openat_2;
+    __openat_2; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __p_cdname;
     __p_cdnname;
     __p_class;
-    __p_class_syms;
+    __p_class_syms; # var
     __p_fqname;
     __p_fqnname;
     __p_option;
@@ -112,25 +111,25 @@
     __p_secstodate;
     __p_time;
     __p_type;
-    __p_type_syms;
-    __poll_chk;
-    __ppoll; # arm x86 mips
-    __ppoll_chk;
-    __pread64_chk;
-    __pread_chk;
-    __progname;
-    __pselect6; # arm x86 mips
+    __p_type_syms; # var
+    __poll_chk; # introduced=23
+    __ppoll; # arm x86 mips introduced=21
+    __ppoll_chk; # introduced=23
+    __pread64_chk; # introduced=23
+    __pread_chk; # introduced=23
+    __progname; # var
+    __pselect6; # arm x86 mips introduced=21
     __pthread_cleanup_pop;
     __pthread_cleanup_push;
     __ptrace; # arm x86 mips
     __putlong;
     __putshort;
-    __read_chk;
-    __readlink_chk;
-    __readlinkat_chk;
+    __read_chk; # introduced=21
+    __readlink_chk; # introduced=23
+    __readlinkat_chk; # introduced=23
     __reboot; # arm x86 mips
-    __recvfrom_chk;
-    __register_atfork;
+    __recvfrom_chk; # introduced=21
+    __register_atfork; # introduced=23
     __res_close;
     __res_dnok;
     __res_hnok;
@@ -152,89 +151,89 @@
     __res_send_setqhook;
     __res_send_setrhook;
     __rt_sigaction; # arm x86 mips
-    __rt_sigpending; # arm x86 mips
+    __rt_sigpending; # arm x86 mips introduced=21
     __rt_sigprocmask; # arm x86 mips
-    __rt_sigsuspend; # arm x86 mips
+    __rt_sigsuspend; # arm x86 mips introduced=21
     __rt_sigtimedwait; # arm x86 mips
-    __sched_cpualloc;
-    __sched_cpucount;
-    __sched_cpufree;
-    __sched_getaffinity; # arm x86 mips
-    __set_tid_address; # arm x86 mips
+    __sched_cpualloc; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_cpucount; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_cpufree; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_getaffinity; # arm x86 mips introduced=12
+    __set_tid_address; # arm x86 mips introduced=21
     __set_tls; # arm mips
-    __sF;
-    __sigaction; # arm x86 mips
-    __snprintf_chk;
-    __socket; # arm x86 mips
-    __sprintf_chk;
+    __sF; # var
+    __sigaction; # arm x86 mips introduced=21
+    __snprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __socket; # arm x86 mips introduced=21
+    __sprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __stack_chk_fail;
-    __stack_chk_guard;
+    __stack_chk_guard; # var
     __statfs64; # arm x86 mips
-    __stpcpy_chk;
-    __stpncpy_chk;
-    __stpncpy_chk2;
-    __strcat_chk;
-    __strchr_chk;
-    __strcpy_chk;
-    __strlcat_chk;
-    __strlcpy_chk;
-    __strlen_chk;
-    __strncat_chk;
-    __strncpy_chk;
-    __strncpy_chk2;
-    __strrchr_chk;
+    __stpcpy_chk; # introduced=21
+    __stpncpy_chk; # introduced=21
+    __stpncpy_chk2; # introduced=21
+    __strcat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strchr_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
+    __strcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlcat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlen_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncpy_chk2; # introduced=21
+    __strrchr_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     __sym_ntop;
     __sym_ntos;
     __sym_ston;
     __system_properties_init;
-    __system_property_add;
-    __system_property_area__;
-    __system_property_area_init;
-    __system_property_area_serial;
+    __system_property_add; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_area__; # var
+    __system_property_area_init; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_area_serial; # introduced=23
     __system_property_find;
     __system_property_find_nth;
-    __system_property_foreach;
+    __system_property_foreach; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     __system_property_get;
     __system_property_read;
-    __system_property_serial;
-    __system_property_set;
-    __system_property_set_filename;
-    __system_property_update;
-    __system_property_wait_any;
+    __system_property_serial; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_set; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __system_property_set_filename; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_update; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_wait_any; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     __timer_create; # arm x86 mips
     __timer_delete; # arm x86 mips
     __timer_getoverrun; # arm x86 mips
     __timer_gettime; # arm x86 mips
     __timer_settime; # arm x86 mips
-    __umask_chk;
-    __vsnprintf_chk;
-    __vsprintf_chk;
+    __umask_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
+    __vsnprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __vsprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __waitid; # arm x86 mips
-    _ctype_;
-    _Exit;
+    _ctype_; # var
+    _Exit; # introduced=21
     _exit;
-    _flushlbf;
+    _flushlbf; # introduced=23
     _getlong;
     _getshort;
     _longjmp;
-    _resolv_delete_cache_for_net;
-    _resolv_flush_cache_for_net;
-    _resolv_set_nameservers_for_net;
+    _resolv_delete_cache_for_net; # introduced=21
+    _resolv_flush_cache_for_net; # introduced=21
+    _resolv_set_nameservers_for_net; # introduced=21
     _setjmp;
-    _tolower;
-    _tolower_tab_; # arm x86 mips
-    _toupper;
-    _toupper_tab_; # arm x86 mips
+    _tolower; # introduced=21
+    _tolower_tab_; # arm x86 mips var
+    _toupper; # introduced=21
+    _toupper_tab_; # arm x86 mips var
     abort;
-    abs;
+    abs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     accept;
-    accept4;
+    accept4; # introduced=21
     access;
     acct;
     alarm;
     alphasort;
-    alphasort64;
-    android_set_abort_message;
+    alphasort64; # introduced=21
+    android_set_abort_message; # introduced=21
     arc4random;
     arc4random_buf;
     arc4random_uniform;
@@ -243,8 +242,8 @@
     asctime64_r; # arm x86 mips
     asctime_r;
     asprintf;
-    at_quick_exit;
-    atof;
+    at_quick_exit; # introduced=21
+    atof; # introduced=21
     atoi;
     atol;
     atoll;
@@ -255,44 +254,44 @@
     brk;
     bsearch;
     btowc;
-    c16rtomb;
-    c32rtomb;
+    c16rtomb; # introduced=21
+    c32rtomb; # introduced=21
     cacheflush; # arm mips
     calloc;
     capget;
     capset;
-    cfgetispeed;
-    cfgetospeed;
-    cfmakeraw;
-    cfsetispeed;
-    cfsetospeed;
-    cfsetspeed;
+    cfgetispeed; # introduced=21
+    cfgetospeed; # introduced=21
+    cfmakeraw; # introduced=21
+    cfsetispeed; # introduced=21
+    cfsetospeed; # introduced=21
+    cfsetspeed; # introduced=21
     chdir;
     chmod;
     chown;
     chroot;
     clearenv;
     clearerr;
-    clearerr_unlocked;
+    clearerr_unlocked; # introduced=23
     clock;
-    clock_getcpuclockid;
+    clock_getcpuclockid; # introduced=23
     clock_getres;
     clock_gettime;
     clock_nanosleep;
     clock_settime;
-    clone;
+    clone; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     close;
     closedir;
     closelog;
     connect;
     creat;
-    creat64;
+    creat64; # introduced=21
     ctime;
     ctime64; # arm x86 mips
     ctime64_r; # arm x86 mips
     ctime_r;
     daemon;
-    daylight;
+    daylight; # var
     delete_module;
     difftime;
     dirfd;
@@ -300,33 +299,33 @@
     dirname_r; # arm x86 mips
     div;
     dn_expand;
-    dprintf;
+    dprintf; # introduced=21
     drand48;
     dup;
     dup2;
-    dup3;
-    duplocale;
-    endmntent;
+    dup3; # introduced=21
+    duplocale; # introduced=21
+    endmntent; # introduced=21
     endservent;
     endutent;
-    environ;
+    environ; # var
     epoll_create;
-    epoll_create1;
+    epoll_create1; # introduced=21
     epoll_ctl;
-    epoll_pwait;
+    epoll_pwait; # introduced=21
     epoll_wait;
     erand48;
     err;
-    error;
-    error_at_line;
-    error_message_count;
-    error_one_per_line;
-    error_print_progname;
+    error; # introduced=23
+    error_at_line; # introduced=23
+    error_message_count; # var introduced=23
+    error_one_per_line; # var introduced=23
+    error_print_progname; # var introduced=23
     errx;
-    ether_aton;
-    ether_aton_r;
-    ether_ntoa;
-    ether_ntoa_r;
+    ether_aton; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_aton_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_ntoa; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_ntoa_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     eventfd;
     eventfd_read;
     eventfd_write;
@@ -336,11 +335,11 @@
     execv;
     execve;
     execvp;
-    execvpe;
+    execvpe; # introduced=21
     exit;
-    faccessat;
-    fallocate;
-    fallocate64;
+    faccessat; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    fallocate; # introduced=21
+    fallocate64; # introduced=21
     fchdir;
     fchmod;
     fchmodat;
@@ -352,27 +351,27 @@
     fdopen;
     fdopendir;
     feof;
-    feof_unlocked;
+    feof_unlocked; # introduced=23
     ferror;
-    ferror_unlocked;
+    ferror_unlocked; # introduced=23
     fflush;
-    ffs;
+    ffs; # introduced-arm=9 introduced-arm64=21 introduced-mips=9 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     fgetc;
     fgetln;
     fgetpos;
     fgets;
     fgetwc;
     fgetws;
-    fgetxattr;
+    fgetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     fileno;
-    flistxattr;
+    flistxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     flock;
     flockfile;
-    fmemopen;
+    fmemopen; # introduced=23
     fnmatch;
     fopen;
     fork;
-    forkpty;
+    forkpty; # introduced=23
     fpathconf;
     fprintf;
     fpurge;
@@ -383,56 +382,56 @@
     fread;
     free;
     freeaddrinfo;
-    freelocale;
-    fremovexattr;
+    freelocale; # introduced=21
+    fremovexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     freopen;
     fscanf;
     fseek;
     fseeko;
     fsetpos;
-    fsetxattr;
+    fsetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     fstat;
-    fstat64;
+    fstat64; # introduced=21
     fstatat;
-    fstatat64;
+    fstatat64; # introduced=21
     fstatfs;
-    fstatfs64;
-    fstatvfs;
-    fstatvfs64;
+    fstatfs64; # introduced=21
+    fstatvfs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    fstatvfs64; # introduced=21
     fsync;
     ftell;
     ftello;
     ftok;
     ftruncate;
-    ftruncate64;
+    ftruncate64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     ftrylockfile;
     fts_children;
     fts_close;
     fts_open;
     fts_read;
     fts_set;
-    ftw;
-    ftw64;
+    ftw; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    ftw64; # introduced=21
     funlockfile;
     funopen;
-    futimens;
+    futimens; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     fwide;
     fwprintf;
     fwrite;
     fwscanf;
     gai_strerror;
-    get_avphys_pages;
-    get_nprocs;
-    get_nprocs_conf;
-    get_phys_pages;
+    get_avphys_pages; # introduced=23
+    get_nprocs; # introduced=23
+    get_nprocs_conf; # introduced=23
+    get_phys_pages; # introduced=23
     getaddrinfo;
-    getauxval;
+    getauxval; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getc;
     getc_unlocked;
     getchar;
     getchar_unlocked;
     getcwd;
-    getdelim;
+    getdelim; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getegid;
     getenv;
     geteuid;
@@ -442,49 +441,49 @@
     getgrouplist;
     getgroups;
     gethostbyaddr;
-    gethostbyaddr_r;
+    gethostbyaddr_r; # introduced=23
     gethostbyname;
     gethostbyname2;
-    gethostbyname2_r;
+    gethostbyname2_r; # introduced=23
     gethostbyname_r;
     gethostent;
     gethostname;
     getitimer;
-    getline;
+    getline; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getlogin;
     getmntent;
-    getmntent_r;
+    getmntent_r; # introduced=21
     getnameinfo;
     getnetbyaddr;
     getnetbyname;
     getopt;
     getopt_long;
     getopt_long_only;
-    getpagesize;
+    getpagesize; # introduced=21
     getpeername;
     getpgid;
     getpgrp;
     getpid;
     getppid;
     getpriority;
-    getprogname;
+    getprogname; # introduced=21
     getprotobyname;
     getprotobynumber;
     getpt;
     getpwnam;
-    getpwnam_r;
+    getpwnam_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     getpwuid;
-    getpwuid_r;
+    getpwuid_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     getresgid;
     getresuid;
     getrlimit;
-    getrlimit64;
+    getrlimit64; # introduced=21
     getrusage;
     gets;
     getservbyname;
     getservbyport;
     getservent;
-    getsid;
+    getsid; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     getsockname;
     getsockopt;
     gettid;
@@ -493,26 +492,26 @@
     getutent;
     getwc;
     getwchar;
-    getxattr;
+    getxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     gmtime;
     gmtime64; # arm x86 mips
     gmtime64_r; # arm x86 mips
     gmtime_r;
-    grantpt;
+    grantpt; # introduced=21
     herror;
     hstrerror;
-    htonl;
-    htons;
+    htonl; # introduced=21
+    htons; # introduced=21
     if_indextoname;
     if_nametoindex;
-    imaxabs;
-    imaxdiv;
+    imaxabs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    imaxdiv; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     inet_addr;
     inet_aton;
-    inet_lnaof;
-    inet_makeaddr;
-    inet_netof;
-    inet_network;
+    inet_lnaof; # introduced=21
+    inet_makeaddr; # introduced=21
+    inet_netof; # introduced=21
+    inet_network; # introduced=21
     inet_nsap_addr;
     inet_nsap_ntoa;
     inet_ntoa;
@@ -520,124 +519,124 @@
     inet_pton;
     init_module;
     initgroups;
-    initstate;
+    initstate; # introduced=21
     inotify_add_watch;
     inotify_init;
-    inotify_init1;
+    inotify_init1; # introduced=21
     inotify_rm_watch;
-    insque;
+    insque; # introduced=21
     ioctl;
     isalnum;
-    isalnum_l;
+    isalnum_l; # introduced=21
     isalpha;
-    isalpha_l;
+    isalpha_l; # introduced=21
     isascii;
     isatty;
     isblank;
-    isblank_l;
+    isblank_l; # introduced=21
     iscntrl;
-    iscntrl_l;
+    iscntrl_l; # introduced=21
     isdigit;
-    isdigit_l;
-    isfinite;
-    isfinitef;
-    isfinitel;
+    isdigit_l; # introduced=21
+    isfinite; # introduced=21
+    isfinitef; # introduced=21
+    isfinitel; # introduced=21
     isgraph;
-    isgraph_l;
-    isinf;
-    isinff;
-    isinfl;
+    isgraph_l; # introduced=21
+    isinf; # introduced=21
+    isinff; # introduced=21
+    isinfl; # introduced=21
     islower;
-    islower_l;
+    islower_l; # introduced=21
     isnan;
     isnanf;
-    isnanl;
-    isnormal;
-    isnormalf;
-    isnormall;
+    isnanl; # introduced=21
+    isnormal; # introduced=21
+    isnormalf; # introduced=21
+    isnormall; # introduced=21
     isprint;
-    isprint_l;
+    isprint_l; # introduced=21
     ispunct;
-    ispunct_l;
+    ispunct_l; # introduced=21
     isspace;
-    isspace_l;
+    isspace_l; # introduced=21
     isupper;
-    isupper_l;
+    isupper_l; # introduced=21
     iswalnum;
-    iswalnum_l;
+    iswalnum_l; # introduced=21
     iswalpha;
-    iswalpha_l;
-    iswblank;
-    iswblank_l;
+    iswalpha_l; # introduced=21
+    iswblank; # introduced=21
+    iswblank_l; # introduced=21
     iswcntrl;
-    iswcntrl_l;
+    iswcntrl_l; # introduced=21
     iswctype;
-    iswctype_l;
+    iswctype_l; # introduced=21
     iswdigit;
-    iswdigit_l;
+    iswdigit_l; # introduced=21
     iswgraph;
-    iswgraph_l;
+    iswgraph_l; # introduced=21
     iswlower;
-    iswlower_l;
+    iswlower_l; # introduced=21
     iswprint;
-    iswprint_l;
+    iswprint_l; # introduced=21
     iswpunct;
-    iswpunct_l;
+    iswpunct_l; # introduced=21
     iswspace;
-    iswspace_l;
+    iswspace_l; # introduced=21
     iswupper;
-    iswupper_l;
+    iswupper_l; # introduced=21
     iswxdigit;
-    iswxdigit_l;
+    iswxdigit_l; # introduced=21
     isxdigit;
-    isxdigit_l;
+    isxdigit_l; # introduced=21
     jrand48;
     kill;
     killpg;
     klogctl;
-    labs;
+    labs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     lchown;
-    lcong48;
+    lcong48; # introduced=23
     ldexp;
     ldiv;
-    lfind;
-    lgetxattr;
+    lfind; # introduced=21
+    lgetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     link;
-    linkat;
+    linkat; # introduced=21
     listen;
-    listxattr;
-    llabs;
+    listxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    llabs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     lldiv;
-    llistxattr;
-    localeconv;
+    llistxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    localeconv; # introduced=21
     localtime;
     localtime64; # arm x86 mips
     localtime64_r; # arm x86 mips
     localtime_r;
-    login_tty;
+    login_tty; # introduced=23
     longjmp;
     lrand48;
-    lremovexattr;
-    lsearch;
+    lremovexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    lsearch; # introduced=21
     lseek;
     lseek64;
-    lsetxattr;
+    lsetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     lstat;
-    lstat64;
+    lstat64; # introduced=21
     madvise;
     mallinfo;
     malloc;
-    malloc_info;
-    malloc_usable_size;
+    malloc_info; # introduced=23
+    malloc_usable_size; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     mbrlen;
-    mbrtoc16;
-    mbrtoc32;
+    mbrtoc16; # introduced=21
+    mbrtoc32; # introduced=21
     mbrtowc;
     mbsinit;
-    mbsnrtowcs;
+    mbsnrtowcs; # introduced=21
     mbsrtowcs;
     mbstowcs;
-    mbtowc;
+    mbtowc; # introduced=21
     memalign;
     memccpy;
     memchr;
@@ -645,91 +644,91 @@
     memcpy;
     memmem;
     memmove;
-    mempcpy;
+    mempcpy; # introduced=23
     memrchr;
     memset;
     mincore;
     mkdir;
     mkdirat;
     mkdtemp;
-    mkfifo;
-    mkfifoat;
+    mkfifo; # introduced=21
+    mkfifoat; # introduced=23
     mknod;
-    mknodat;
-    mkostemp;
-    mkostemp64;
-    mkostemps;
-    mkostemps64;
+    mknodat; # introduced=21
+    mkostemp; # introduced=23
+    mkostemp64; # introduced=23
+    mkostemps; # introduced=23
+    mkostemps64; # introduced=23
     mkstemp;
-    mkstemp64;
+    mkstemp64; # introduced=21
     mkstemps;
-    mkstemps64;
+    mkstemps64; # introduced=23
     mktemp;
     mktime;
     mktime64; # arm x86 mips
     mlock;
-    mlockall;
+    mlockall; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     mmap;
-    mmap64;
+    mmap64; # introduced=21
     mount;
     mprotect;
     mrand48;
     mremap;
     msync;
     munlock;
-    munlockall;
+    munlockall; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     munmap;
     nanosleep;
-    newlocale;
-    nftw;
-    nftw64;
+    newlocale; # introduced=21
+    nftw; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    nftw64; # introduced=21
     nice;
     nrand48;
     nsdispatch;
-    ntohl;
-    ntohs;
+    ntohl; # introduced=21
+    ntohs; # introduced=21
     open;
-    open64;
-    open_memstream;
-    open_wmemstream;
+    open64; # introduced=21
+    open_memstream; # introduced=23
+    open_wmemstream; # introduced=23
     openat;
-    openat64;
+    openat64; # introduced=21
     opendir;
     openlog;
-    openpty;
-    optarg;
-    opterr;
-    optind;
-    optopt;
-    optreset;
+    openpty; # introduced=23
+    optarg; # var
+    opterr; # var
+    optind; # var
+    optopt; # var
+    optreset; # var
     pathconf;
     pause;
     pclose;
     perror;
-    personality;
+    personality; # introduced-arm=15 introduced-arm64=21 introduced-mips=15 introduced-mips64=21 introduced-x86=15 introduced-x86_64=21
     pipe;
     pipe2;
     poll;
     popen;
-    posix_fadvise;
-    posix_fadvise64;
-    posix_fallocate;
-    posix_fallocate64;
-    posix_madvise;
-    posix_memalign;
-    posix_openpt;
-    ppoll;
+    posix_fadvise; # introduced=21
+    posix_fadvise64; # introduced=21
+    posix_fallocate; # introduced=21
+    posix_fallocate64; # introduced=21
+    posix_madvise; # introduced=23
+    posix_memalign; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    posix_openpt; # introduced=21
+    ppoll; # introduced=21
     prctl;
     pread;
-    pread64;
+    pread64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     printf;
-    prlimit64;
-    process_vm_readv;
-    process_vm_writev;
+    prlimit64; # introduced=21
+    process_vm_readv; # introduced=23
+    process_vm_writev; # introduced=23
     pselect;
-    psiginfo;
-    psignal;
-    pthread_atfork;
+    psiginfo; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    psignal; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    pthread_atfork; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     pthread_attr_destroy;
     pthread_attr_getdetachstate;
     pthread_attr_getguardsize;
@@ -757,10 +756,10 @@
     pthread_cond_timeout_np; # arm x86 mips
     pthread_cond_wait;
     pthread_condattr_destroy;
-    pthread_condattr_getclock;
+    pthread_condattr_getclock; # introduced=21
     pthread_condattr_getpshared;
     pthread_condattr_init;
-    pthread_condattr_setclock;
+    pthread_condattr_setclock; # introduced=21
     pthread_condattr_setpshared;
     pthread_create;
     pthread_detach;
@@ -770,7 +769,7 @@
     pthread_getcpuclockid;
     pthread_getschedparam;
     pthread_getspecific;
-    pthread_gettid_np;
+    pthread_gettid_np; # introduced=21
     pthread_join;
     pthread_key_create;
     pthread_key_delete;
@@ -779,7 +778,7 @@
     pthread_mutex_init;
     pthread_mutex_lock;
     pthread_mutex_lock_timeout_np; # arm x86 mips
-    pthread_mutex_timedlock;
+    pthread_mutex_timedlock; # introduced=21
     pthread_mutex_trylock;
     pthread_mutex_unlock;
     pthread_mutexattr_destroy;
@@ -799,10 +798,10 @@
     pthread_rwlock_unlock;
     pthread_rwlock_wrlock;
     pthread_rwlockattr_destroy;
-    pthread_rwlockattr_getkind_np;
+    pthread_rwlockattr_getkind_np; # introduced=23
     pthread_rwlockattr_getpshared;
     pthread_rwlockattr_init;
-    pthread_rwlockattr_setkind_np;
+    pthread_rwlockattr_setkind_np; # introduced=23
     pthread_rwlockattr_setpshared;
     pthread_self;
     pthread_setname_np;
@@ -822,38 +821,38 @@
     putw; # arm x86 mips
     putwc;
     putwchar;
-    pvalloc; # arm x86 mips
+    pvalloc; # arm x86 mips introduced=17
     pwrite;
-    pwrite64;
+    pwrite64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     qsort;
-    quick_exit;
+    quick_exit; # introduced=21
     raise;
-    rand;
-    rand_r;
-    random;
+    rand; # introduced=21
+    rand_r; # introduced=21
+    random; # introduced=21
     read;
-    readahead;
+    readahead; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     readdir;
-    readdir64;
-    readdir64_r;
+    readdir64; # introduced=21
+    readdir64_r; # introduced=21
     readdir_r;
     readlink;
-    readlinkat;
+    readlinkat; # introduced=21
     readv;
     realloc;
     realpath;
     reboot;
     recv;
     recvfrom;
-    recvmmsg;
+    recvmmsg; # introduced=21
     recvmsg;
     regcomp;
     regerror;
     regexec;
     regfree;
     remove;
-    removexattr;
-    remque;
+    removexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    remque; # introduced=21
     rename;
     renameat;
     res_init;
@@ -865,21 +864,21 @@
     rmdir;
     sbrk;
     scandir;
-    scandir64;
+    scandir64; # introduced=21
     scanf;
     sched_get_priority_max;
     sched_get_priority_min;
-    sched_getaffinity;
-    sched_getcpu;
+    sched_getaffinity; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    sched_getcpu; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sched_getparam;
     sched_getscheduler;
     sched_rr_get_interval;
-    sched_setaffinity;
+    sched_setaffinity; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sched_setparam;
     sched_setscheduler;
     sched_yield;
     seed48;
-    seekdir;
+    seekdir; # introduced=23
     select;
     sem_close;
     sem_destroy;
@@ -893,8 +892,8 @@
     sem_wait;
     send;
     sendfile;
-    sendfile64;
-    sendmmsg;
+    sendfile64; # introduced=21
+    sendmmsg; # introduced=21
     sendmsg;
     sendto;
     setbuf;
@@ -902,101 +901,101 @@
     setegid;
     setenv;
     seteuid;
-    setfsgid;
-    setfsuid;
+    setfsgid; # introduced=21
+    setfsuid; # introduced=21
     setgid;
     setgroups;
-    sethostname;
+    sethostname; # introduced=23
     setitimer;
     setjmp;
     setlinebuf;
     setlocale;
     setlogmask;
-    setmntent;
-    setns;
+    setmntent; # introduced=21
+    setns; # introduced=21
     setpgid;
     setpgrp;
     setpriority;
-    setprogname;
+    setprogname; # introduced=21
     setregid;
     setresgid;
     setresuid;
     setreuid;
     setrlimit;
-    setrlimit64;
+    setrlimit64; # introduced=21
     setservent;
     setsid;
     setsockopt;
-    setstate;
+    setstate; # introduced=21
     settimeofday;
     setuid;
     setutent;
     setvbuf;
-    setxattr;
+    setxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     shutdown;
     sigaction;
-    sigaddset;
+    sigaddset; # introduced=21
     sigaltstack;
     sigblock;
-    sigdelset;
-    sigemptyset;
-    sigfillset;
+    sigdelset; # introduced=21
+    sigemptyset; # introduced=21
+    sigfillset; # introduced=21
     siginterrupt;
-    sigismember;
-    siglongjmp;
-    signal;
-    signalfd;
+    sigismember; # introduced=21
+    siglongjmp; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    signal; # introduced=21
+    signalfd; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     sigpending;
     sigprocmask;
-    sigqueue;
-    sigsetjmp;
+    sigqueue; # introduced=23
+    sigsetjmp; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sigsetmask;
     sigsuspend;
-    sigtimedwait;
+    sigtimedwait; # introduced=23
     sigwait;
-    sigwaitinfo;
+    sigwaitinfo; # introduced=23
     sleep;
     snprintf;
     socket;
     socketpair;
-    splice;
+    splice; # introduced=21
     sprintf;
-    srand;
+    srand; # introduced=21
     srand48;
-    srandom;
+    srandom; # introduced=21
     sscanf;
     stat;
-    stat64;
+    stat64; # introduced=21
     statfs;
-    statfs64;
-    statvfs;
-    statvfs64;
-    stderr;
-    stdin;
-    stdout;
-    stpcpy;
-    stpncpy;
+    statfs64; # introduced=21
+    statvfs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    statvfs64; # introduced=21
+    stderr; # var introduced=23
+    stdin; # var introduced=23
+    stdout; # var introduced=23
+    stpcpy; # introduced=21
+    stpncpy; # introduced=21
     strcasecmp;
-    strcasecmp_l;
+    strcasecmp_l; # introduced=23
     strcasestr;
     strcat;
     strchr;
     strcmp;
     strcoll;
-    strcoll_l;
+    strcoll_l; # introduced=21
     strcpy;
     strcspn;
     strdup;
     strerror;
-    strerror_l;
+    strerror_l; # introduced=23
     strerror_r;
     strftime;
-    strftime_l;
+    strftime_l; # introduced=21
     strlcat;
     strlcpy;
     strlen;
     strncasecmp;
-    strncasecmp_l;
+    strncasecmp_l; # introduced=23
     strncat;
     strncmp;
     strncpy;
@@ -1010,86 +1009,86 @@
     strspn;
     strstr;
     strtod;
-    strtof;
+    strtof; # introduced=21
     strtoimax;
     strtok;
     strtok_r;
     strtol;
-    strtold;
-    strtold_l;
+    strtold; # introduced=21
+    strtold_l; # introduced=21
     strtoll;
-    strtoll_l;
-    strtoq;
+    strtoll_l; # introduced=21
+    strtoq; # introduced=21
     strtoul;
     strtoull;
-    strtoull_l;
+    strtoull_l; # introduced=21
     strtoumax;
-    strtouq;
+    strtouq; # introduced=21
     strxfrm;
-    strxfrm_l;
-    swapoff;
-    swapon;
+    strxfrm_l; # introduced=21
+    swapoff; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    swapon; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     swprintf;
     swscanf;
     symlink;
-    symlinkat;
+    symlinkat; # introduced=21
     sync;
-    sys_siglist;
-    sys_signame;
+    sys_siglist; # var
+    sys_signame; # var
     syscall;
     sysconf;
     sysinfo;
     syslog;
     system;
-    tcdrain;
-    tcflow;
-    tcflush;
-    tcgetattr;
+    tcdrain; # introduced=21
+    tcflow; # introduced=21
+    tcflush; # introduced=21
+    tcgetattr; # introduced=21
     tcgetpgrp;
-    tcgetsid;
-    tcsendbreak;
-    tcsetattr;
+    tcgetsid; # introduced=21
+    tcsendbreak; # introduced=21
+    tcsetattr; # introduced=21
     tcsetpgrp;
-    tdelete;
-    tdestroy;
-    tee;
-    telldir;
+    tdelete; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tdestroy; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tee; # introduced=21
+    telldir; # introduced=23
     tempnam;
-    tfind;
-    tgkill;
+    tfind; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tgkill; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     time;
-    timegm;
+    timegm; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     timegm64; # arm x86 mips
-    timelocal;
+    timelocal; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     timelocal64; # arm x86 mips
     timer_create;
     timer_delete;
     timer_getoverrun;
     timer_gettime;
     timer_settime;
-    timerfd_create;
-    timerfd_gettime;
-    timerfd_settime;
+    timerfd_create; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    timerfd_gettime; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    timerfd_settime; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     times;
-    timezone;
+    timezone; # var
     tmpfile;
     tmpnam;
     toascii;
     tolower;
-    tolower_l;
+    tolower_l; # introduced=21
     toupper;
-    toupper_l;
+    toupper_l; # introduced=21
     towlower;
-    towlower_l;
+    towlower_l; # introduced=21
     towupper;
-    towupper_l;
+    towupper_l; # introduced=21
     truncate;
-    truncate64;
-    tsearch;
+    truncate64; # introduced=21
+    tsearch; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     ttyname;
     ttyname_r;
-    twalk;
-    tzname;
+    twalk; # introduced=21
+    tzname; # var
     tzset;
     umask;
     umount;
@@ -1101,38 +1100,38 @@
     unlinkat;
     unlockpt;
     unsetenv;
-    unshare;
-    uselocale;
+    unshare; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    uselocale; # introduced=21
     usleep;
     utime;
-    utimensat;
+    utimensat; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     utimes;
     utmpname;
     valloc; # arm x86 mips
     vasprintf;
-    vdprintf;
+    vdprintf; # introduced=21
     verr;
     verrx;
     vfork;
     vfprintf;
     vfscanf;
     vfwprintf;
-    vfwscanf;
-    vmsplice;
+    vfwscanf; # introduced=21
+    vmsplice; # introduced=21
     vprintf;
     vscanf;
     vsnprintf;
     vsprintf;
     vsscanf;
     vswprintf;
-    vswscanf;
+    vswscanf; # introduced=21
     vsyslog;
     vwarn;
     vwarnx;
     vwprintf;
-    vwscanf;
+    vwscanf; # introduced=21
     wait;
-    wait4;
+    wait4; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     waitid;
     waitpid;
     warn;
@@ -1141,12 +1140,12 @@
     wcpncpy;
     wcrtomb;
     wcscasecmp;
-    wcscasecmp_l;
+    wcscasecmp_l; # introduced=23
     wcscat;
     wcschr;
     wcscmp;
     wcscoll;
-    wcscoll_l;
+    wcscoll_l; # introduced=21
     wcscpy;
     wcscspn;
     wcsdup;
@@ -1155,44 +1154,44 @@
     wcslcpy;
     wcslen;
     wcsncasecmp;
-    wcsncasecmp_l;
+    wcsncasecmp_l; # introduced=23
     wcsncat;
     wcsncmp;
     wcsncpy;
     wcsnlen;
-    wcsnrtombs;
+    wcsnrtombs; # introduced=21
     wcspbrk;
     wcsrchr;
     wcsrtombs;
     wcsspn;
     wcsstr;
     wcstod;
-    wcstof;
-    wcstoimax;
+    wcstof; # introduced=21
+    wcstoimax; # introduced=21
     wcstok;
     wcstol;
-    wcstold;
-    wcstold_l;
-    wcstoll;
-    wcstoll_l;
+    wcstold; # introduced=21
+    wcstold_l; # introduced=21
+    wcstoll; # introduced=21
+    wcstoll_l; # introduced=21
     wcstombs;
     wcstoul;
-    wcstoull;
-    wcstoull_l;
-    wcstoumax;
+    wcstoull; # introduced=21
+    wcstoull_l; # introduced=21
+    wcstoumax; # introduced=21
     wcswidth;
     wcsxfrm;
-    wcsxfrm_l;
+    wcsxfrm_l; # introduced=21
     wctob;
-    wctomb;
+    wctomb; # introduced=21
     wctype;
-    wctype_l;
+    wctype_l; # introduced=21
     wcwidth;
     wmemchr;
     wmemcmp;
     wmemcpy;
     wmemmove;
-    wmempcpy;
+    wmempcpy; # introduced=23
     wmemset;
     wprintf;
     write;
@@ -1202,71 +1201,105 @@
     *;
 };
 
-LIBC_N {
+LIBC_N { # introduced-arm64=24 introduced-mips=24 introduced-mips64=24 introduced-x86=24 introduced-x86_64=24
   global:
-    __aeabi_atexit; # arm
-    __aeabi_memclr; # arm
-    __aeabi_memclr4; # arm
-    __aeabi_memclr8; # arm
-    __aeabi_memcpy; # arm
-    __aeabi_memcpy4; # arm
-    __aeabi_memcpy8; # arm
-    __aeabi_memmove; # arm
-    __aeabi_memmove4; # arm
-    __aeabi_memmove8; # arm
-    __aeabi_memset; # arm
-    __aeabi_memset4; # arm
-    __aeabi_memset8; # arm
-    __fread_chk;
-    __fwrite_chk;
-    __getcwd_chk;
-    __gnu_Unwind_Find_exidx; # arm
-    __pwrite_chk;
-    __pwrite64_chk;
-    __write_chk;
-    adjtimex;
-    clock_adjtime;
-    fgetpos64;
-    fileno_unlocked;
-    fopen64;
-    freeifaddrs;
-    freopen64;
-    fseeko64;
-    fsetpos64;
-    ftello64;
-    funopen64;
-    getgrgid_r;
-    getgrnam_r;
-    getifaddrs;
-    if_freenameindex;
-    if_nameindex;
-    in6addr_any;
-    in6addr_loopback;
-    lockf;
-    lockf64;
-    preadv;
-    preadv64;
-    prlimit; # arm mips x86
-    pthread_barrierattr_destroy;
-    pthread_barrierattr_getpshared;
-    pthread_barrierattr_init;
-    pthread_barrierattr_setpshared;
-    pthread_barrier_destroy;
-    pthread_barrier_init;
-    pthread_barrier_wait;
-    pthread_spin_destroy;
-    pthread_spin_init;
-    pthread_spin_lock;
-    pthread_spin_trylock;
-    pthread_spin_unlock;
-    pwritev;
-    pwritev64;
-    scandirat;
-    scandirat64;
-    strchrnul;
-    tmpfile64;
+    __aeabi_atexit; # arm versioned=24
+    __aeabi_memclr; # arm versioned=24
+    __aeabi_memclr4; # arm versioned=24
+    __aeabi_memclr8; # arm versioned=24
+    __aeabi_memcpy; # arm versioned=24
+    __aeabi_memcpy4; # arm versioned=24
+    __aeabi_memcpy8; # arm versioned=24
+    __aeabi_memmove; # arm versioned=24
+    __aeabi_memmove4; # arm versioned=24
+    __aeabi_memmove8; # arm versioned=24
+    __aeabi_memset; # arm versioned=24
+    __aeabi_memset4; # arm versioned=24
+    __aeabi_memset8; # arm versioned=24
+    __fread_chk; # introduced=24
+    __fwrite_chk; # introduced=24
+    __getcwd_chk; # introduced=24
+    __gnu_Unwind_Find_exidx; # arm versioned=24
+    __pwrite_chk; # introduced=24
+    __pwrite64_chk; # introduced=24
+    __write_chk; # introduced=24
+    adjtimex; # introduced=24
+    clock_adjtime; # introduced=24
+    fgetpos64; # introduced=24
+    fileno_unlocked; # introduced=24
+    fopen64; # introduced=24
+    freeifaddrs; # introduced=24
+    freopen64; # introduced=24
+    fseeko64; # introduced=24
+    fsetpos64; # introduced=24
+    ftello64; # introduced=24
+    funopen64; # introduced=24
+    getgrgid_r; # introduced=24
+    getgrnam_r; # introduced=24
+    getifaddrs; # introduced=24
+    if_freenameindex; # introduced=24
+    if_nameindex; # introduced=24
+    in6addr_any; # var introduced=24
+    in6addr_loopback; # var introduced=24
+    lockf; # introduced=24
+    lockf64; # introduced=24
+    preadv; # introduced=24
+    preadv64; # introduced=24
+    prlimit; # arm mips x86 introduced=24
+    pthread_barrierattr_destroy; # introduced=24
+    pthread_barrierattr_getpshared; # introduced=24
+    pthread_barrierattr_init; # introduced=24
+    pthread_barrierattr_setpshared; # introduced=24
+    pthread_barrier_destroy; # introduced=24
+    pthread_barrier_init; # introduced=24
+    pthread_barrier_wait; # introduced=24
+    pthread_spin_destroy; # introduced=24
+    pthread_spin_init; # introduced=24
+    pthread_spin_lock; # introduced=24
+    pthread_spin_trylock; # introduced=24
+    pthread_spin_unlock; # introduced=24
+    pwritev; # introduced=24
+    pwritev64; # introduced=24
+    scandirat; # introduced=24
+    scandirat64; # introduced=24
+    strchrnul; # introduced=24
+    tmpfile64; # introduced=24
 } LIBC;
 
+LIBC_O {
+  global:
+    catclose; # future
+    catgets; # future
+    catopen; # future
+    ctermid; # future
+    endgrent; # future
+    endpwent; # future
+    futimes; # future
+    futimesat; # future
+    getdomainname; # future
+    getgrent; # future
+    getpwent; # future
+    getsubopt; # future
+    hasmntopt; # future
+    lutimes; # future
+    mblen; # future
+    pthread_getname_np; # future
+    quotactl; # future
+    setdomainname; # future
+    setgrent; # future
+    setpwent; # future
+    sighold; # future
+    sigignore; # future
+    sigpause; # future
+    sigrelse; # future
+    sigset; # future
+    sync_file_range; # future
+    towctrans; # future
+    towctrans_l; # future
+    wctrans; # future
+    wctrans_l; # future
+} LIBC_N;
+
 LIBC_PRIVATE {
   global:
     ___Unwind_Backtrace; # arm
@@ -1444,7 +1477,7 @@
     SHA1Init; # arm x86 mips
     SHA1Transform; # arm x86 mips
     SHA1Update; # arm x86 mips
-} LIBC_N;
+} LIBC_O;
 
 LIBC_PLATFORM {
   global:
@@ -1455,4 +1488,4 @@
     malloc_disable;
     malloc_enable;
     malloc_iterate;
-} LIBC_N;
+} LIBC_O;
diff --git a/libc/libc.arm.map b/libc/libc.arm.map
index 38f8437..0ee2308 100644
--- a/libc/libc.arm.map
+++ b/libc/libc.arm.map
@@ -1,4 +1,4 @@
-# Generated by genversionscripts.py. Do not edit.
+# Generated by genversion-scripts.py. Do not edit.
 LIBC {
   global:
     __assert;
@@ -9,45 +9,44 @@
     __atomic_swap; # arm
     __b64_ntop;
     __b64_pton;
-    __brk; # arm x86 mips
-    __cmsg_nxthdr;
-    __connect; # arm x86 mips
-    __ctype_get_mb_cur_max;
+    __cmsg_nxthdr; # introduced=21
+    __connect; # arm x86 mips introduced=21
+    __ctype_get_mb_cur_max; # introduced=21
     __cxa_atexit;
     __cxa_finalize;
-    __cxa_thread_atexit_impl;
+    __cxa_thread_atexit_impl; # introduced=23
     __dn_comp;
     __dn_count_labels;
     __dn_skipname;
-    __epoll_pwait; # arm x86 mips
+    __epoll_pwait; # arm x86 mips introduced=21
     __errno;
-    __exit; # arm x86 mips
-    __fbufsize;
+    __exit; # arm x86 mips introduced=21
+    __fbufsize; # introduced=23
     __fcntl64; # arm x86 mips
-    __FD_CLR_chk;
-    __FD_ISSET_chk;
-    __FD_SET_chk;
-    __fgets_chk;
-    __flbf;
+    __FD_CLR_chk; # introduced=21
+    __FD_ISSET_chk; # introduced=21
+    __FD_SET_chk; # introduced=21
+    __fgets_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __flbf; # introduced=23
     __fp_nquery;
     __fp_query;
-    __fpclassify;
+    __fpclassify; # introduced=21
     __fpclassifyd;
     __fpclassifyf;
     __fpclassifyl;
-    __fpending;
-    __fpurge;
-    __freadable;
-    __fsetlocking;
+    __fpending; # introduced=23
+    __fpurge; # introduced=23
+    __freadable; # introduced=23
+    __fsetlocking; # introduced=23
     __fstatfs64; # arm x86 mips
-    __fwritable;
+    __fwritable; # introduced=23
     __get_h_errno;
-    __getcpu; # arm x86 mips
+    __getcpu; # arm x86 mips introduced-arm=12 introduced-mips=16 introduced-x86=12
     __getcwd; # arm x86 mips
-    __getpid; # arm x86 mips
+    __getpid; # arm x86 mips introduced=21
     __getpriority; # arm x86 mips
-    __gnu_basename;
-    __gnu_strerror_r;
+    __gnu_basename; # introduced=23
+    __gnu_strerror_r; # introduced=23
     __hostalias;
     __ioctl; # arm x86 mips
     __isfinite;
@@ -56,24 +55,24 @@
     __isinf;
     __isinff;
     __isinfl;
-    __isnan;
-    __isnanf;
+    __isnan; # introduced=21
+    __isnanf; # introduced=21
     __isnanl;
     __isnormal;
     __isnormalf;
     __isnormall;
-    __isthreaded; # arm x86 mips
-    __libc_current_sigrtmax;
-    __libc_current_sigrtmin;
+    __isthreaded; # arm x86 mips var
+    __libc_current_sigrtmax; # introduced=21
+    __libc_current_sigrtmin; # introduced=21
     __libc_init;
     __llseek; # arm x86 mips
     __loc_aton;
     __loc_ntoa;
-    __memchr_chk;
-    __memcpy_chk;
-    __memmove_chk;
-    __memrchr_chk;
-    __memset_chk;
+    __memchr_chk; # introduced=23
+    __memcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __memmove_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __memrchr_chk; # introduced=23
+    __memset_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __mmap2; # arm x86 mips
     __ns_format_ttl; # arm x86 mips
     __ns_get16; # arm x86 mips
@@ -97,13 +96,13 @@
     __ns_skiprr; # arm x86 mips
     __ns_sprintrr; # arm x86 mips
     __ns_sprintrrf; # arm x86 mips
-    __open_2;
+    __open_2; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __openat; # arm x86 mips
-    __openat_2;
+    __openat_2; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __p_cdname;
     __p_cdnname;
     __p_class;
-    __p_class_syms;
+    __p_class_syms; # var
     __p_fqname;
     __p_fqnname;
     __p_option;
@@ -112,25 +111,25 @@
     __p_secstodate;
     __p_time;
     __p_type;
-    __p_type_syms;
-    __poll_chk;
-    __ppoll; # arm x86 mips
-    __ppoll_chk;
-    __pread64_chk;
-    __pread_chk;
-    __progname;
-    __pselect6; # arm x86 mips
+    __p_type_syms; # var
+    __poll_chk; # introduced=23
+    __ppoll; # arm x86 mips introduced=21
+    __ppoll_chk; # introduced=23
+    __pread64_chk; # introduced=23
+    __pread_chk; # introduced=23
+    __progname; # var
+    __pselect6; # arm x86 mips introduced=21
     __pthread_cleanup_pop;
     __pthread_cleanup_push;
     __ptrace; # arm x86 mips
     __putlong;
     __putshort;
-    __read_chk;
-    __readlink_chk;
-    __readlinkat_chk;
+    __read_chk; # introduced=21
+    __readlink_chk; # introduced=23
+    __readlinkat_chk; # introduced=23
     __reboot; # arm x86 mips
-    __recvfrom_chk;
-    __register_atfork;
+    __recvfrom_chk; # introduced=21
+    __register_atfork; # introduced=23
     __res_close;
     __res_dnok;
     __res_hnok;
@@ -152,89 +151,89 @@
     __res_send_setqhook;
     __res_send_setrhook;
     __rt_sigaction; # arm x86 mips
-    __rt_sigpending; # arm x86 mips
+    __rt_sigpending; # arm x86 mips introduced=21
     __rt_sigprocmask; # arm x86 mips
-    __rt_sigsuspend; # arm x86 mips
+    __rt_sigsuspend; # arm x86 mips introduced=21
     __rt_sigtimedwait; # arm x86 mips
-    __sched_cpualloc;
-    __sched_cpucount;
-    __sched_cpufree;
-    __sched_getaffinity; # arm x86 mips
-    __set_tid_address; # arm x86 mips
+    __sched_cpualloc; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_cpucount; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_cpufree; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_getaffinity; # arm x86 mips introduced=12
+    __set_tid_address; # arm x86 mips introduced=21
     __set_tls; # arm mips
-    __sF;
-    __sigaction; # arm x86 mips
-    __snprintf_chk;
-    __socket; # arm x86 mips
-    __sprintf_chk;
+    __sF; # var
+    __sigaction; # arm x86 mips introduced=21
+    __snprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __socket; # arm x86 mips introduced=21
+    __sprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __stack_chk_fail;
-    __stack_chk_guard;
+    __stack_chk_guard; # var
     __statfs64; # arm x86 mips
-    __stpcpy_chk;
-    __stpncpy_chk;
-    __stpncpy_chk2;
-    __strcat_chk;
-    __strchr_chk;
-    __strcpy_chk;
-    __strlcat_chk;
-    __strlcpy_chk;
-    __strlen_chk;
-    __strncat_chk;
-    __strncpy_chk;
-    __strncpy_chk2;
-    __strrchr_chk;
+    __stpcpy_chk; # introduced=21
+    __stpncpy_chk; # introduced=21
+    __stpncpy_chk2; # introduced=21
+    __strcat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strchr_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
+    __strcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlcat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlen_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncpy_chk2; # introduced=21
+    __strrchr_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     __sym_ntop;
     __sym_ntos;
     __sym_ston;
     __system_properties_init;
-    __system_property_add;
-    __system_property_area__;
-    __system_property_area_init;
-    __system_property_area_serial;
+    __system_property_add; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_area__; # var
+    __system_property_area_init; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_area_serial; # introduced=23
     __system_property_find;
     __system_property_find_nth;
-    __system_property_foreach;
+    __system_property_foreach; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     __system_property_get;
     __system_property_read;
-    __system_property_serial;
-    __system_property_set;
-    __system_property_set_filename;
-    __system_property_update;
-    __system_property_wait_any;
+    __system_property_serial; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_set; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __system_property_set_filename; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_update; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_wait_any; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     __timer_create; # arm x86 mips
     __timer_delete; # arm x86 mips
     __timer_getoverrun; # arm x86 mips
     __timer_gettime; # arm x86 mips
     __timer_settime; # arm x86 mips
-    __umask_chk;
-    __vsnprintf_chk;
-    __vsprintf_chk;
+    __umask_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
+    __vsnprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __vsprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __waitid; # arm x86 mips
-    _ctype_;
-    _Exit;
+    _ctype_; # var
+    _Exit; # introduced=21
     _exit;
-    _flushlbf;
+    _flushlbf; # introduced=23
     _getlong;
     _getshort;
     _longjmp;
-    _resolv_delete_cache_for_net;
-    _resolv_flush_cache_for_net;
-    _resolv_set_nameservers_for_net;
+    _resolv_delete_cache_for_net; # introduced=21
+    _resolv_flush_cache_for_net; # introduced=21
+    _resolv_set_nameservers_for_net; # introduced=21
     _setjmp;
-    _tolower;
-    _tolower_tab_; # arm x86 mips
-    _toupper;
-    _toupper_tab_; # arm x86 mips
+    _tolower; # introduced=21
+    _tolower_tab_; # arm x86 mips var
+    _toupper; # introduced=21
+    _toupper_tab_; # arm x86 mips var
     abort;
-    abs;
+    abs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     accept;
-    accept4;
+    accept4; # introduced=21
     access;
     acct;
     alarm;
     alphasort;
-    alphasort64;
-    android_set_abort_message;
+    alphasort64; # introduced=21
+    android_set_abort_message; # introduced=21
     arc4random;
     arc4random_buf;
     arc4random_uniform;
@@ -243,8 +242,8 @@
     asctime64_r; # arm x86 mips
     asctime_r;
     asprintf;
-    at_quick_exit;
-    atof;
+    at_quick_exit; # introduced=21
+    atof; # introduced=21
     atoi;
     atol;
     atoll;
@@ -255,44 +254,44 @@
     brk;
     bsearch;
     btowc;
-    c16rtomb;
-    c32rtomb;
+    c16rtomb; # introduced=21
+    c32rtomb; # introduced=21
     cacheflush; # arm mips
     calloc;
     capget;
     capset;
-    cfgetispeed;
-    cfgetospeed;
-    cfmakeraw;
-    cfsetispeed;
-    cfsetospeed;
-    cfsetspeed;
+    cfgetispeed; # introduced=21
+    cfgetospeed; # introduced=21
+    cfmakeraw; # introduced=21
+    cfsetispeed; # introduced=21
+    cfsetospeed; # introduced=21
+    cfsetspeed; # introduced=21
     chdir;
     chmod;
     chown;
     chroot;
     clearenv;
     clearerr;
-    clearerr_unlocked;
+    clearerr_unlocked; # introduced=23
     clock;
-    clock_getcpuclockid;
+    clock_getcpuclockid; # introduced=23
     clock_getres;
     clock_gettime;
     clock_nanosleep;
     clock_settime;
-    clone;
+    clone; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     close;
     closedir;
     closelog;
     connect;
     creat;
-    creat64;
+    creat64; # introduced=21
     ctime;
     ctime64; # arm x86 mips
     ctime64_r; # arm x86 mips
     ctime_r;
     daemon;
-    daylight;
+    daylight; # var
     delete_module;
     difftime;
     dirfd;
@@ -300,33 +299,33 @@
     dirname_r; # arm x86 mips
     div;
     dn_expand;
-    dprintf;
+    dprintf; # introduced=21
     drand48;
     dup;
     dup2;
-    dup3;
-    duplocale;
-    endmntent;
+    dup3; # introduced=21
+    duplocale; # introduced=21
+    endmntent; # introduced=21
     endservent;
     endutent;
-    environ;
+    environ; # var
     epoll_create;
-    epoll_create1;
+    epoll_create1; # introduced=21
     epoll_ctl;
-    epoll_pwait;
+    epoll_pwait; # introduced=21
     epoll_wait;
     erand48;
     err;
-    error;
-    error_at_line;
-    error_message_count;
-    error_one_per_line;
-    error_print_progname;
+    error; # introduced=23
+    error_at_line; # introduced=23
+    error_message_count; # var introduced=23
+    error_one_per_line; # var introduced=23
+    error_print_progname; # var introduced=23
     errx;
-    ether_aton;
-    ether_aton_r;
-    ether_ntoa;
-    ether_ntoa_r;
+    ether_aton; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_aton_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_ntoa; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_ntoa_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     eventfd;
     eventfd_read;
     eventfd_write;
@@ -336,11 +335,11 @@
     execv;
     execve;
     execvp;
-    execvpe;
+    execvpe; # introduced=21
     exit;
-    faccessat;
-    fallocate;
-    fallocate64;
+    faccessat; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    fallocate; # introduced=21
+    fallocate64; # introduced=21
     fchdir;
     fchmod;
     fchmodat;
@@ -352,27 +351,27 @@
     fdopen;
     fdopendir;
     feof;
-    feof_unlocked;
+    feof_unlocked; # introduced=23
     ferror;
-    ferror_unlocked;
+    ferror_unlocked; # introduced=23
     fflush;
-    ffs;
+    ffs; # introduced-arm=9 introduced-arm64=21 introduced-mips=9 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     fgetc;
     fgetln;
     fgetpos;
     fgets;
     fgetwc;
     fgetws;
-    fgetxattr;
+    fgetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     fileno;
-    flistxattr;
+    flistxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     flock;
     flockfile;
-    fmemopen;
+    fmemopen; # introduced=23
     fnmatch;
     fopen;
     fork;
-    forkpty;
+    forkpty; # introduced=23
     fpathconf;
     fprintf;
     fpurge;
@@ -383,56 +382,56 @@
     fread;
     free;
     freeaddrinfo;
-    freelocale;
-    fremovexattr;
+    freelocale; # introduced=21
+    fremovexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     freopen;
     fscanf;
     fseek;
     fseeko;
     fsetpos;
-    fsetxattr;
+    fsetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     fstat;
-    fstat64;
+    fstat64; # introduced=21
     fstatat;
-    fstatat64;
+    fstatat64; # introduced=21
     fstatfs;
-    fstatfs64;
-    fstatvfs;
-    fstatvfs64;
+    fstatfs64; # introduced=21
+    fstatvfs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    fstatvfs64; # introduced=21
     fsync;
     ftell;
     ftello;
     ftok;
     ftruncate;
-    ftruncate64;
+    ftruncate64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     ftrylockfile;
     fts_children;
     fts_close;
     fts_open;
     fts_read;
     fts_set;
-    ftw;
-    ftw64;
+    ftw; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    ftw64; # introduced=21
     funlockfile;
     funopen;
-    futimens;
+    futimens; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     fwide;
     fwprintf;
     fwrite;
     fwscanf;
     gai_strerror;
-    get_avphys_pages;
-    get_nprocs;
-    get_nprocs_conf;
-    get_phys_pages;
+    get_avphys_pages; # introduced=23
+    get_nprocs; # introduced=23
+    get_nprocs_conf; # introduced=23
+    get_phys_pages; # introduced=23
     getaddrinfo;
-    getauxval;
+    getauxval; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getc;
     getc_unlocked;
     getchar;
     getchar_unlocked;
     getcwd;
-    getdelim;
+    getdelim; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getegid;
     getenv;
     geteuid;
@@ -442,49 +441,49 @@
     getgrouplist;
     getgroups;
     gethostbyaddr;
-    gethostbyaddr_r;
+    gethostbyaddr_r; # introduced=23
     gethostbyname;
     gethostbyname2;
-    gethostbyname2_r;
+    gethostbyname2_r; # introduced=23
     gethostbyname_r;
     gethostent;
     gethostname;
     getitimer;
-    getline;
+    getline; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getlogin;
     getmntent;
-    getmntent_r;
+    getmntent_r; # introduced=21
     getnameinfo;
     getnetbyaddr;
     getnetbyname;
     getopt;
     getopt_long;
     getopt_long_only;
-    getpagesize;
+    getpagesize; # introduced=21
     getpeername;
     getpgid;
     getpgrp;
     getpid;
     getppid;
     getpriority;
-    getprogname;
+    getprogname; # introduced=21
     getprotobyname;
     getprotobynumber;
     getpt;
     getpwnam;
-    getpwnam_r;
+    getpwnam_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     getpwuid;
-    getpwuid_r;
+    getpwuid_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     getresgid;
     getresuid;
     getrlimit;
-    getrlimit64;
+    getrlimit64; # introduced=21
     getrusage;
     gets;
     getservbyname;
     getservbyport;
     getservent;
-    getsid;
+    getsid; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     getsockname;
     getsockopt;
     gettid;
@@ -493,26 +492,26 @@
     getutent;
     getwc;
     getwchar;
-    getxattr;
+    getxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     gmtime;
     gmtime64; # arm x86 mips
     gmtime64_r; # arm x86 mips
     gmtime_r;
-    grantpt;
+    grantpt; # introduced=21
     herror;
     hstrerror;
-    htonl;
-    htons;
+    htonl; # introduced=21
+    htons; # introduced=21
     if_indextoname;
     if_nametoindex;
-    imaxabs;
-    imaxdiv;
+    imaxabs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    imaxdiv; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     inet_addr;
     inet_aton;
-    inet_lnaof;
-    inet_makeaddr;
-    inet_netof;
-    inet_network;
+    inet_lnaof; # introduced=21
+    inet_makeaddr; # introduced=21
+    inet_netof; # introduced=21
+    inet_network; # introduced=21
     inet_nsap_addr;
     inet_nsap_ntoa;
     inet_ntoa;
@@ -520,124 +519,124 @@
     inet_pton;
     init_module;
     initgroups;
-    initstate;
+    initstate; # introduced=21
     inotify_add_watch;
     inotify_init;
-    inotify_init1;
+    inotify_init1; # introduced=21
     inotify_rm_watch;
-    insque;
+    insque; # introduced=21
     ioctl;
     isalnum;
-    isalnum_l;
+    isalnum_l; # introduced=21
     isalpha;
-    isalpha_l;
+    isalpha_l; # introduced=21
     isascii;
     isatty;
     isblank;
-    isblank_l;
+    isblank_l; # introduced=21
     iscntrl;
-    iscntrl_l;
+    iscntrl_l; # introduced=21
     isdigit;
-    isdigit_l;
-    isfinite;
-    isfinitef;
-    isfinitel;
+    isdigit_l; # introduced=21
+    isfinite; # introduced=21
+    isfinitef; # introduced=21
+    isfinitel; # introduced=21
     isgraph;
-    isgraph_l;
-    isinf;
-    isinff;
-    isinfl;
+    isgraph_l; # introduced=21
+    isinf; # introduced=21
+    isinff; # introduced=21
+    isinfl; # introduced=21
     islower;
-    islower_l;
+    islower_l; # introduced=21
     isnan;
     isnanf;
-    isnanl;
-    isnormal;
-    isnormalf;
-    isnormall;
+    isnanl; # introduced=21
+    isnormal; # introduced=21
+    isnormalf; # introduced=21
+    isnormall; # introduced=21
     isprint;
-    isprint_l;
+    isprint_l; # introduced=21
     ispunct;
-    ispunct_l;
+    ispunct_l; # introduced=21
     isspace;
-    isspace_l;
+    isspace_l; # introduced=21
     isupper;
-    isupper_l;
+    isupper_l; # introduced=21
     iswalnum;
-    iswalnum_l;
+    iswalnum_l; # introduced=21
     iswalpha;
-    iswalpha_l;
-    iswblank;
-    iswblank_l;
+    iswalpha_l; # introduced=21
+    iswblank; # introduced=21
+    iswblank_l; # introduced=21
     iswcntrl;
-    iswcntrl_l;
+    iswcntrl_l; # introduced=21
     iswctype;
-    iswctype_l;
+    iswctype_l; # introduced=21
     iswdigit;
-    iswdigit_l;
+    iswdigit_l; # introduced=21
     iswgraph;
-    iswgraph_l;
+    iswgraph_l; # introduced=21
     iswlower;
-    iswlower_l;
+    iswlower_l; # introduced=21
     iswprint;
-    iswprint_l;
+    iswprint_l; # introduced=21
     iswpunct;
-    iswpunct_l;
+    iswpunct_l; # introduced=21
     iswspace;
-    iswspace_l;
+    iswspace_l; # introduced=21
     iswupper;
-    iswupper_l;
+    iswupper_l; # introduced=21
     iswxdigit;
-    iswxdigit_l;
+    iswxdigit_l; # introduced=21
     isxdigit;
-    isxdigit_l;
+    isxdigit_l; # introduced=21
     jrand48;
     kill;
     killpg;
     klogctl;
-    labs;
+    labs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     lchown;
-    lcong48;
+    lcong48; # introduced=23
     ldexp;
     ldiv;
-    lfind;
-    lgetxattr;
+    lfind; # introduced=21
+    lgetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     link;
-    linkat;
+    linkat; # introduced=21
     listen;
-    listxattr;
-    llabs;
+    listxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    llabs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     lldiv;
-    llistxattr;
-    localeconv;
+    llistxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    localeconv; # introduced=21
     localtime;
     localtime64; # arm x86 mips
     localtime64_r; # arm x86 mips
     localtime_r;
-    login_tty;
+    login_tty; # introduced=23
     longjmp;
     lrand48;
-    lremovexattr;
-    lsearch;
+    lremovexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    lsearch; # introduced=21
     lseek;
     lseek64;
-    lsetxattr;
+    lsetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     lstat;
-    lstat64;
+    lstat64; # introduced=21
     madvise;
     mallinfo;
     malloc;
-    malloc_info;
-    malloc_usable_size;
+    malloc_info; # introduced=23
+    malloc_usable_size; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     mbrlen;
-    mbrtoc16;
-    mbrtoc32;
+    mbrtoc16; # introduced=21
+    mbrtoc32; # introduced=21
     mbrtowc;
     mbsinit;
-    mbsnrtowcs;
+    mbsnrtowcs; # introduced=21
     mbsrtowcs;
     mbstowcs;
-    mbtowc;
+    mbtowc; # introduced=21
     memalign;
     memccpy;
     memchr;
@@ -645,91 +644,91 @@
     memcpy;
     memmem;
     memmove;
-    mempcpy;
+    mempcpy; # introduced=23
     memrchr;
     memset;
     mincore;
     mkdir;
     mkdirat;
     mkdtemp;
-    mkfifo;
-    mkfifoat;
+    mkfifo; # introduced=21
+    mkfifoat; # introduced=23
     mknod;
-    mknodat;
-    mkostemp;
-    mkostemp64;
-    mkostemps;
-    mkostemps64;
+    mknodat; # introduced=21
+    mkostemp; # introduced=23
+    mkostemp64; # introduced=23
+    mkostemps; # introduced=23
+    mkostemps64; # introduced=23
     mkstemp;
-    mkstemp64;
+    mkstemp64; # introduced=21
     mkstemps;
-    mkstemps64;
+    mkstemps64; # introduced=23
     mktemp;
     mktime;
     mktime64; # arm x86 mips
     mlock;
-    mlockall;
+    mlockall; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     mmap;
-    mmap64;
+    mmap64; # introduced=21
     mount;
     mprotect;
     mrand48;
     mremap;
     msync;
     munlock;
-    munlockall;
+    munlockall; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     munmap;
     nanosleep;
-    newlocale;
-    nftw;
-    nftw64;
+    newlocale; # introduced=21
+    nftw; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    nftw64; # introduced=21
     nice;
     nrand48;
     nsdispatch;
-    ntohl;
-    ntohs;
+    ntohl; # introduced=21
+    ntohs; # introduced=21
     open;
-    open64;
-    open_memstream;
-    open_wmemstream;
+    open64; # introduced=21
+    open_memstream; # introduced=23
+    open_wmemstream; # introduced=23
     openat;
-    openat64;
+    openat64; # introduced=21
     opendir;
     openlog;
-    openpty;
-    optarg;
-    opterr;
-    optind;
-    optopt;
-    optreset;
+    openpty; # introduced=23
+    optarg; # var
+    opterr; # var
+    optind; # var
+    optopt; # var
+    optreset; # var
     pathconf;
     pause;
     pclose;
     perror;
-    personality;
+    personality; # introduced-arm=15 introduced-arm64=21 introduced-mips=15 introduced-mips64=21 introduced-x86=15 introduced-x86_64=21
     pipe;
     pipe2;
     poll;
     popen;
-    posix_fadvise;
-    posix_fadvise64;
-    posix_fallocate;
-    posix_fallocate64;
-    posix_madvise;
-    posix_memalign;
-    posix_openpt;
-    ppoll;
+    posix_fadvise; # introduced=21
+    posix_fadvise64; # introduced=21
+    posix_fallocate; # introduced=21
+    posix_fallocate64; # introduced=21
+    posix_madvise; # introduced=23
+    posix_memalign; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    posix_openpt; # introduced=21
+    ppoll; # introduced=21
     prctl;
     pread;
-    pread64;
+    pread64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     printf;
-    prlimit64;
-    process_vm_readv;
-    process_vm_writev;
+    prlimit64; # introduced=21
+    process_vm_readv; # introduced=23
+    process_vm_writev; # introduced=23
     pselect;
-    psiginfo;
-    psignal;
-    pthread_atfork;
+    psiginfo; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    psignal; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    pthread_atfork; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     pthread_attr_destroy;
     pthread_attr_getdetachstate;
     pthread_attr_getguardsize;
@@ -757,10 +756,10 @@
     pthread_cond_timeout_np; # arm x86 mips
     pthread_cond_wait;
     pthread_condattr_destroy;
-    pthread_condattr_getclock;
+    pthread_condattr_getclock; # introduced=21
     pthread_condattr_getpshared;
     pthread_condattr_init;
-    pthread_condattr_setclock;
+    pthread_condattr_setclock; # introduced=21
     pthread_condattr_setpshared;
     pthread_create;
     pthread_detach;
@@ -770,7 +769,7 @@
     pthread_getcpuclockid;
     pthread_getschedparam;
     pthread_getspecific;
-    pthread_gettid_np;
+    pthread_gettid_np; # introduced=21
     pthread_join;
     pthread_key_create;
     pthread_key_delete;
@@ -779,7 +778,7 @@
     pthread_mutex_init;
     pthread_mutex_lock;
     pthread_mutex_lock_timeout_np; # arm x86 mips
-    pthread_mutex_timedlock;
+    pthread_mutex_timedlock; # introduced=21
     pthread_mutex_trylock;
     pthread_mutex_unlock;
     pthread_mutexattr_destroy;
@@ -799,10 +798,10 @@
     pthread_rwlock_unlock;
     pthread_rwlock_wrlock;
     pthread_rwlockattr_destroy;
-    pthread_rwlockattr_getkind_np;
+    pthread_rwlockattr_getkind_np; # introduced=23
     pthread_rwlockattr_getpshared;
     pthread_rwlockattr_init;
-    pthread_rwlockattr_setkind_np;
+    pthread_rwlockattr_setkind_np; # introduced=23
     pthread_rwlockattr_setpshared;
     pthread_self;
     pthread_setname_np;
@@ -822,38 +821,38 @@
     putw; # arm x86 mips
     putwc;
     putwchar;
-    pvalloc; # arm x86 mips
+    pvalloc; # arm x86 mips introduced=17
     pwrite;
-    pwrite64;
+    pwrite64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     qsort;
-    quick_exit;
+    quick_exit; # introduced=21
     raise;
-    rand;
-    rand_r;
-    random;
+    rand; # introduced=21
+    rand_r; # introduced=21
+    random; # introduced=21
     read;
-    readahead;
+    readahead; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     readdir;
-    readdir64;
-    readdir64_r;
+    readdir64; # introduced=21
+    readdir64_r; # introduced=21
     readdir_r;
     readlink;
-    readlinkat;
+    readlinkat; # introduced=21
     readv;
     realloc;
     realpath;
     reboot;
     recv;
     recvfrom;
-    recvmmsg;
+    recvmmsg; # introduced=21
     recvmsg;
     regcomp;
     regerror;
     regexec;
     regfree;
     remove;
-    removexattr;
-    remque;
+    removexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    remque; # introduced=21
     rename;
     renameat;
     res_init;
@@ -865,21 +864,21 @@
     rmdir;
     sbrk;
     scandir;
-    scandir64;
+    scandir64; # introduced=21
     scanf;
     sched_get_priority_max;
     sched_get_priority_min;
-    sched_getaffinity;
-    sched_getcpu;
+    sched_getaffinity; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    sched_getcpu; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sched_getparam;
     sched_getscheduler;
     sched_rr_get_interval;
-    sched_setaffinity;
+    sched_setaffinity; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sched_setparam;
     sched_setscheduler;
     sched_yield;
     seed48;
-    seekdir;
+    seekdir; # introduced=23
     select;
     sem_close;
     sem_destroy;
@@ -893,8 +892,8 @@
     sem_wait;
     send;
     sendfile;
-    sendfile64;
-    sendmmsg;
+    sendfile64; # introduced=21
+    sendmmsg; # introduced=21
     sendmsg;
     sendto;
     setbuf;
@@ -902,101 +901,101 @@
     setegid;
     setenv;
     seteuid;
-    setfsgid;
-    setfsuid;
+    setfsgid; # introduced=21
+    setfsuid; # introduced=21
     setgid;
     setgroups;
-    sethostname;
+    sethostname; # introduced=23
     setitimer;
     setjmp;
     setlinebuf;
     setlocale;
     setlogmask;
-    setmntent;
-    setns;
+    setmntent; # introduced=21
+    setns; # introduced=21
     setpgid;
     setpgrp;
     setpriority;
-    setprogname;
+    setprogname; # introduced=21
     setregid;
     setresgid;
     setresuid;
     setreuid;
     setrlimit;
-    setrlimit64;
+    setrlimit64; # introduced=21
     setservent;
     setsid;
     setsockopt;
-    setstate;
+    setstate; # introduced=21
     settimeofday;
     setuid;
     setutent;
     setvbuf;
-    setxattr;
+    setxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     shutdown;
     sigaction;
-    sigaddset;
+    sigaddset; # introduced=21
     sigaltstack;
     sigblock;
-    sigdelset;
-    sigemptyset;
-    sigfillset;
+    sigdelset; # introduced=21
+    sigemptyset; # introduced=21
+    sigfillset; # introduced=21
     siginterrupt;
-    sigismember;
-    siglongjmp;
-    signal;
-    signalfd;
+    sigismember; # introduced=21
+    siglongjmp; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    signal; # introduced=21
+    signalfd; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     sigpending;
     sigprocmask;
-    sigqueue;
-    sigsetjmp;
+    sigqueue; # introduced=23
+    sigsetjmp; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sigsetmask;
     sigsuspend;
-    sigtimedwait;
+    sigtimedwait; # introduced=23
     sigwait;
-    sigwaitinfo;
+    sigwaitinfo; # introduced=23
     sleep;
     snprintf;
     socket;
     socketpair;
-    splice;
+    splice; # introduced=21
     sprintf;
-    srand;
+    srand; # introduced=21
     srand48;
-    srandom;
+    srandom; # introduced=21
     sscanf;
     stat;
-    stat64;
+    stat64; # introduced=21
     statfs;
-    statfs64;
-    statvfs;
-    statvfs64;
-    stderr;
-    stdin;
-    stdout;
-    stpcpy;
-    stpncpy;
+    statfs64; # introduced=21
+    statvfs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    statvfs64; # introduced=21
+    stderr; # var introduced=23
+    stdin; # var introduced=23
+    stdout; # var introduced=23
+    stpcpy; # introduced=21
+    stpncpy; # introduced=21
     strcasecmp;
-    strcasecmp_l;
+    strcasecmp_l; # introduced=23
     strcasestr;
     strcat;
     strchr;
     strcmp;
     strcoll;
-    strcoll_l;
+    strcoll_l; # introduced=21
     strcpy;
     strcspn;
     strdup;
     strerror;
-    strerror_l;
+    strerror_l; # introduced=23
     strerror_r;
     strftime;
-    strftime_l;
+    strftime_l; # introduced=21
     strlcat;
     strlcpy;
     strlen;
     strncasecmp;
-    strncasecmp_l;
+    strncasecmp_l; # introduced=23
     strncat;
     strncmp;
     strncpy;
@@ -1010,86 +1009,86 @@
     strspn;
     strstr;
     strtod;
-    strtof;
+    strtof; # introduced=21
     strtoimax;
     strtok;
     strtok_r;
     strtol;
-    strtold;
-    strtold_l;
+    strtold; # introduced=21
+    strtold_l; # introduced=21
     strtoll;
-    strtoll_l;
-    strtoq;
+    strtoll_l; # introduced=21
+    strtoq; # introduced=21
     strtoul;
     strtoull;
-    strtoull_l;
+    strtoull_l; # introduced=21
     strtoumax;
-    strtouq;
+    strtouq; # introduced=21
     strxfrm;
-    strxfrm_l;
-    swapoff;
-    swapon;
+    strxfrm_l; # introduced=21
+    swapoff; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    swapon; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     swprintf;
     swscanf;
     symlink;
-    symlinkat;
+    symlinkat; # introduced=21
     sync;
-    sys_siglist;
-    sys_signame;
+    sys_siglist; # var
+    sys_signame; # var
     syscall;
     sysconf;
     sysinfo;
     syslog;
     system;
-    tcdrain;
-    tcflow;
-    tcflush;
-    tcgetattr;
+    tcdrain; # introduced=21
+    tcflow; # introduced=21
+    tcflush; # introduced=21
+    tcgetattr; # introduced=21
     tcgetpgrp;
-    tcgetsid;
-    tcsendbreak;
-    tcsetattr;
+    tcgetsid; # introduced=21
+    tcsendbreak; # introduced=21
+    tcsetattr; # introduced=21
     tcsetpgrp;
-    tdelete;
-    tdestroy;
-    tee;
-    telldir;
+    tdelete; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tdestroy; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tee; # introduced=21
+    telldir; # introduced=23
     tempnam;
-    tfind;
-    tgkill;
+    tfind; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tgkill; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     time;
-    timegm;
+    timegm; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     timegm64; # arm x86 mips
-    timelocal;
+    timelocal; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     timelocal64; # arm x86 mips
     timer_create;
     timer_delete;
     timer_getoverrun;
     timer_gettime;
     timer_settime;
-    timerfd_create;
-    timerfd_gettime;
-    timerfd_settime;
+    timerfd_create; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    timerfd_gettime; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    timerfd_settime; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     times;
-    timezone;
+    timezone; # var
     tmpfile;
     tmpnam;
     toascii;
     tolower;
-    tolower_l;
+    tolower_l; # introduced=21
     toupper;
-    toupper_l;
+    toupper_l; # introduced=21
     towlower;
-    towlower_l;
+    towlower_l; # introduced=21
     towupper;
-    towupper_l;
+    towupper_l; # introduced=21
     truncate;
-    truncate64;
-    tsearch;
+    truncate64; # introduced=21
+    tsearch; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     ttyname;
     ttyname_r;
-    twalk;
-    tzname;
+    twalk; # introduced=21
+    tzname; # var
     tzset;
     umask;
     umount;
@@ -1101,38 +1100,38 @@
     unlinkat;
     unlockpt;
     unsetenv;
-    unshare;
-    uselocale;
+    unshare; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    uselocale; # introduced=21
     usleep;
     utime;
-    utimensat;
+    utimensat; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     utimes;
     utmpname;
     valloc; # arm x86 mips
     vasprintf;
-    vdprintf;
+    vdprintf; # introduced=21
     verr;
     verrx;
     vfork;
     vfprintf;
     vfscanf;
     vfwprintf;
-    vfwscanf;
-    vmsplice;
+    vfwscanf; # introduced=21
+    vmsplice; # introduced=21
     vprintf;
     vscanf;
     vsnprintf;
     vsprintf;
     vsscanf;
     vswprintf;
-    vswscanf;
+    vswscanf; # introduced=21
     vsyslog;
     vwarn;
     vwarnx;
     vwprintf;
-    vwscanf;
+    vwscanf; # introduced=21
     wait;
-    wait4;
+    wait4; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     waitid;
     waitpid;
     warn;
@@ -1141,12 +1140,12 @@
     wcpncpy;
     wcrtomb;
     wcscasecmp;
-    wcscasecmp_l;
+    wcscasecmp_l; # introduced=23
     wcscat;
     wcschr;
     wcscmp;
     wcscoll;
-    wcscoll_l;
+    wcscoll_l; # introduced=21
     wcscpy;
     wcscspn;
     wcsdup;
@@ -1155,44 +1154,44 @@
     wcslcpy;
     wcslen;
     wcsncasecmp;
-    wcsncasecmp_l;
+    wcsncasecmp_l; # introduced=23
     wcsncat;
     wcsncmp;
     wcsncpy;
     wcsnlen;
-    wcsnrtombs;
+    wcsnrtombs; # introduced=21
     wcspbrk;
     wcsrchr;
     wcsrtombs;
     wcsspn;
     wcsstr;
     wcstod;
-    wcstof;
-    wcstoimax;
+    wcstof; # introduced=21
+    wcstoimax; # introduced=21
     wcstok;
     wcstol;
-    wcstold;
-    wcstold_l;
-    wcstoll;
-    wcstoll_l;
+    wcstold; # introduced=21
+    wcstold_l; # introduced=21
+    wcstoll; # introduced=21
+    wcstoll_l; # introduced=21
     wcstombs;
     wcstoul;
-    wcstoull;
-    wcstoull_l;
-    wcstoumax;
+    wcstoull; # introduced=21
+    wcstoull_l; # introduced=21
+    wcstoumax; # introduced=21
     wcswidth;
     wcsxfrm;
-    wcsxfrm_l;
+    wcsxfrm_l; # introduced=21
     wctob;
-    wctomb;
+    wctomb; # introduced=21
     wctype;
-    wctype_l;
+    wctype_l; # introduced=21
     wcwidth;
     wmemchr;
     wmemcmp;
     wmemcpy;
     wmemmove;
-    wmempcpy;
+    wmempcpy; # introduced=23
     wmemset;
     wprintf;
     write;
@@ -1202,71 +1201,106 @@
     *;
 };
 
-LIBC_N {
+LIBC_N { # introduced-arm64=24 introduced-mips=24 introduced-mips64=24 introduced-x86=24 introduced-x86_64=24
   global:
-    __aeabi_atexit; # arm
-    __aeabi_memclr; # arm
-    __aeabi_memclr4; # arm
-    __aeabi_memclr8; # arm
-    __aeabi_memcpy; # arm
-    __aeabi_memcpy4; # arm
-    __aeabi_memcpy8; # arm
-    __aeabi_memmove; # arm
-    __aeabi_memmove4; # arm
-    __aeabi_memmove8; # arm
-    __aeabi_memset; # arm
-    __aeabi_memset4; # arm
-    __aeabi_memset8; # arm
-    __fread_chk;
-    __fwrite_chk;
-    __getcwd_chk;
-    __gnu_Unwind_Find_exidx; # arm
-    __pwrite_chk;
-    __pwrite64_chk;
-    __write_chk;
-    adjtimex;
-    clock_adjtime;
-    fgetpos64;
-    fileno_unlocked;
-    fopen64;
-    freeifaddrs;
-    freopen64;
-    fseeko64;
-    fsetpos64;
-    ftello64;
-    funopen64;
-    getgrgid_r;
-    getgrnam_r;
-    getifaddrs;
-    if_freenameindex;
-    if_nameindex;
-    in6addr_any;
-    in6addr_loopback;
-    lockf;
-    lockf64;
-    preadv;
-    preadv64;
-    prlimit; # arm mips x86
-    pthread_barrierattr_destroy;
-    pthread_barrierattr_getpshared;
-    pthread_barrierattr_init;
-    pthread_barrierattr_setpshared;
-    pthread_barrier_destroy;
-    pthread_barrier_init;
-    pthread_barrier_wait;
-    pthread_spin_destroy;
-    pthread_spin_init;
-    pthread_spin_lock;
-    pthread_spin_trylock;
-    pthread_spin_unlock;
-    pwritev;
-    pwritev64;
-    scandirat;
-    scandirat64;
-    strchrnul;
-    tmpfile64;
+    __aeabi_atexit; # arm versioned=24
+    __aeabi_memclr; # arm versioned=24
+    __aeabi_memclr4; # arm versioned=24
+    __aeabi_memclr8; # arm versioned=24
+    __aeabi_memcpy; # arm versioned=24
+    __aeabi_memcpy4; # arm versioned=24
+    __aeabi_memcpy8; # arm versioned=24
+    __aeabi_memmove; # arm versioned=24
+    __aeabi_memmove4; # arm versioned=24
+    __aeabi_memmove8; # arm versioned=24
+    __aeabi_memset; # arm versioned=24
+    __aeabi_memset4; # arm versioned=24
+    __aeabi_memset8; # arm versioned=24
+    __fread_chk; # introduced=24
+    __fwrite_chk; # introduced=24
+    __getcwd_chk; # introduced=24
+    __gnu_Unwind_Find_exidx; # arm versioned=24
+    __pwrite_chk; # introduced=24
+    __pwrite64_chk; # introduced=24
+    __write_chk; # introduced=24
+    adjtimex; # introduced=24
+    clock_adjtime; # introduced=24
+    fgetpos64; # introduced=24
+    fileno_unlocked; # introduced=24
+    fopen64; # introduced=24
+    freeifaddrs; # introduced=24
+    freopen64; # introduced=24
+    fseeko64; # introduced=24
+    fsetpos64; # introduced=24
+    ftello64; # introduced=24
+    funopen64; # introduced=24
+    getgrgid_r; # introduced=24
+    getgrnam_r; # introduced=24
+    getifaddrs; # introduced=24
+    if_freenameindex; # introduced=24
+    if_nameindex; # introduced=24
+    in6addr_any; # var introduced=24
+    in6addr_loopback; # var introduced=24
+    lockf; # introduced=24
+    lockf64; # introduced=24
+    preadv; # introduced=24
+    preadv64; # introduced=24
+    prlimit; # arm mips x86 introduced=24
+    pthread_barrierattr_destroy; # introduced=24
+    pthread_barrierattr_getpshared; # introduced=24
+    pthread_barrierattr_init; # introduced=24
+    pthread_barrierattr_setpshared; # introduced=24
+    pthread_barrier_destroy; # introduced=24
+    pthread_barrier_init; # introduced=24
+    pthread_barrier_wait; # introduced=24
+    pthread_spin_destroy; # introduced=24
+    pthread_spin_init; # introduced=24
+    pthread_spin_lock; # introduced=24
+    pthread_spin_trylock; # introduced=24
+    pthread_spin_unlock; # introduced=24
+    pwritev; # introduced=24
+    pwritev64; # introduced=24
+    scandirat; # introduced=24
+    scandirat64; # introduced=24
+    strchrnul; # introduced=24
+    tmpfile64; # introduced=24
 } LIBC;
 
+LIBC_O {
+  global:
+    bsd_signal; # arm x86 mips nobrillo versioned=26
+    catclose; # future
+    catgets; # future
+    catopen; # future
+    ctermid; # future
+    endgrent; # future
+    endpwent; # future
+    futimes; # future
+    futimesat; # future
+    getdomainname; # future
+    getgrent; # future
+    getpwent; # future
+    getsubopt; # future
+    hasmntopt; # future
+    lutimes; # future
+    mblen; # future
+    pthread_getname_np; # future
+    quotactl; # future
+    setdomainname; # future
+    setgrent; # future
+    setpwent; # future
+    sighold; # future
+    sigignore; # future
+    sigpause; # future
+    sigrelse; # future
+    sigset; # future
+    sync_file_range; # future
+    towctrans; # future
+    towctrans_l; # future
+    wctrans; # future
+    wctrans_l; # future
+} LIBC_N;
+
 LIBC_PRIVATE {
   global:
     ___Unwind_Backtrace; # arm
@@ -1452,12 +1486,10 @@
     atexit; # arm
     bcopy; # arm x86 mips nobrillo
     bzero; # arm x86 mips nobrillo
-    bsd_signal; # arm x86 mips nobrillo
     dlmalloc; # arm x86 mips nobrillo
     dlmalloc_inspect_all; # arm x86 mips nobrillo
     dlmalloc_trim; # arm x86 mips nobrillo
     dlmalloc_usable_size; # arm x86 mips nobrillo
-    endpwent; # arm x86 mips nobrillo
     fdprintf; # arm x86 mips nobrillo
     free_malloc_leak_info;
     ftime; # arm x86 mips nobrillo
@@ -1483,7 +1515,7 @@
     vfdprintf; # arm x86 mips nobrillo
     wait3; # arm x86 mips nobrillo
     wcswcs; # arm x86 mips nobrillo
-} LIBC_N;
+} LIBC_O;
 
 LIBC_PLATFORM {
   global:
@@ -1494,4 +1526,4 @@
     malloc_disable;
     malloc_enable;
     malloc_iterate;
-} LIBC_N;
+} LIBC_O;
diff --git a/libc/libc.arm64.map b/libc/libc.arm64.map
index afbd0ee..f080340 100644
--- a/libc/libc.arm64.map
+++ b/libc/libc.arm64.map
@@ -1,39 +1,39 @@
-# Generated by genversionscripts.py. Do not edit.
+# Generated by genversion-scripts.py. Do not edit.
 LIBC {
   global:
     __assert;
     __assert2;
     __b64_ntop;
     __b64_pton;
-    __cmsg_nxthdr;
-    __ctype_get_mb_cur_max;
+    __cmsg_nxthdr; # introduced=21
+    __ctype_get_mb_cur_max; # introduced=21
     __cxa_atexit;
     __cxa_finalize;
-    __cxa_thread_atexit_impl;
+    __cxa_thread_atexit_impl; # introduced=23
     __dn_comp;
     __dn_count_labels;
     __dn_skipname;
     __errno;
-    __fbufsize;
-    __FD_CLR_chk;
-    __FD_ISSET_chk;
-    __FD_SET_chk;
-    __fgets_chk;
-    __flbf;
+    __fbufsize; # introduced=23
+    __FD_CLR_chk; # introduced=21
+    __FD_ISSET_chk; # introduced=21
+    __FD_SET_chk; # introduced=21
+    __fgets_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __flbf; # introduced=23
     __fp_nquery;
     __fp_query;
-    __fpclassify;
+    __fpclassify; # introduced=21
     __fpclassifyd;
     __fpclassifyf;
     __fpclassifyl;
-    __fpending;
-    __fpurge;
-    __freadable;
-    __fsetlocking;
-    __fwritable;
+    __fpending; # introduced=23
+    __fpurge; # introduced=23
+    __freadable; # introduced=23
+    __fsetlocking; # introduced=23
+    __fwritable; # introduced=23
     __get_h_errno;
-    __gnu_basename;
-    __gnu_strerror_r;
+    __gnu_basename; # introduced=23
+    __gnu_strerror_r; # introduced=23
     __hostalias;
     __isfinite;
     __isfinitef;
@@ -41,28 +41,28 @@
     __isinf;
     __isinff;
     __isinfl;
-    __isnan;
-    __isnanf;
+    __isnan; # introduced=21
+    __isnanf; # introduced=21
     __isnanl;
     __isnormal;
     __isnormalf;
     __isnormall;
-    __libc_current_sigrtmax;
-    __libc_current_sigrtmin;
+    __libc_current_sigrtmax; # introduced=21
+    __libc_current_sigrtmin; # introduced=21
     __libc_init;
     __loc_aton;
     __loc_ntoa;
-    __memchr_chk;
-    __memcpy_chk;
-    __memmove_chk;
-    __memrchr_chk;
-    __memset_chk;
-    __open_2;
-    __openat_2;
+    __memchr_chk; # introduced=23
+    __memcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __memmove_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __memrchr_chk; # introduced=23
+    __memset_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __open_2; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __openat_2; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __p_cdname;
     __p_cdnname;
     __p_class;
-    __p_class_syms;
+    __p_class_syms; # var
     __p_fqname;
     __p_fqnname;
     __p_option;
@@ -71,21 +71,21 @@
     __p_secstodate;
     __p_time;
     __p_type;
-    __p_type_syms;
-    __poll_chk;
-    __ppoll_chk;
-    __pread64_chk;
-    __pread_chk;
-    __progname;
+    __p_type_syms; # var
+    __poll_chk; # introduced=23
+    __ppoll_chk; # introduced=23
+    __pread64_chk; # introduced=23
+    __pread_chk; # introduced=23
+    __progname; # var
     __pthread_cleanup_pop;
     __pthread_cleanup_push;
     __putlong;
     __putshort;
-    __read_chk;
-    __readlink_chk;
-    __readlinkat_chk;
-    __recvfrom_chk;
-    __register_atfork;
+    __read_chk; # introduced=21
+    __readlink_chk; # introduced=23
+    __readlinkat_chk; # introduced=23
+    __recvfrom_chk; # introduced=21
+    __register_atfork; # introduced=23
     __res_close;
     __res_dnok;
     __res_hnok;
@@ -106,79 +106,79 @@
     __res_send;
     __res_send_setqhook;
     __res_send_setrhook;
-    __sched_cpualloc;
-    __sched_cpucount;
-    __sched_cpufree;
-    __sF;
-    __snprintf_chk;
-    __sprintf_chk;
+    __sched_cpualloc; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_cpucount; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_cpufree; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sF; # var
+    __snprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __sprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __stack_chk_fail;
-    __stack_chk_guard;
-    __stpcpy_chk;
-    __stpncpy_chk;
-    __stpncpy_chk2;
-    __strcat_chk;
-    __strchr_chk;
-    __strcpy_chk;
-    __strlcat_chk;
-    __strlcpy_chk;
-    __strlen_chk;
-    __strncat_chk;
-    __strncpy_chk;
-    __strncpy_chk2;
-    __strrchr_chk;
+    __stack_chk_guard; # var
+    __stpcpy_chk; # introduced=21
+    __stpncpy_chk; # introduced=21
+    __stpncpy_chk2; # introduced=21
+    __strcat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strchr_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
+    __strcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlcat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlen_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncpy_chk2; # introduced=21
+    __strrchr_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     __sym_ntop;
     __sym_ntos;
     __sym_ston;
     __system_properties_init;
-    __system_property_add;
-    __system_property_area__;
-    __system_property_area_init;
-    __system_property_area_serial;
+    __system_property_add; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_area__; # var
+    __system_property_area_init; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_area_serial; # introduced=23
     __system_property_find;
     __system_property_find_nth;
-    __system_property_foreach;
+    __system_property_foreach; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     __system_property_get;
     __system_property_read;
-    __system_property_serial;
-    __system_property_set;
-    __system_property_set_filename;
-    __system_property_update;
-    __system_property_wait_any;
-    __umask_chk;
-    __vsnprintf_chk;
-    __vsprintf_chk;
-    _ctype_;
-    _Exit;
+    __system_property_serial; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_set; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __system_property_set_filename; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_update; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_wait_any; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __umask_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
+    __vsnprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __vsprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    _ctype_; # var
+    _Exit; # introduced=21
     _exit;
-    _flushlbf;
+    _flushlbf; # introduced=23
     _getlong;
     _getshort;
     _longjmp;
-    _resolv_delete_cache_for_net;
-    _resolv_flush_cache_for_net;
-    _resolv_set_nameservers_for_net;
+    _resolv_delete_cache_for_net; # introduced=21
+    _resolv_flush_cache_for_net; # introduced=21
+    _resolv_set_nameservers_for_net; # introduced=21
     _setjmp;
-    _tolower;
-    _toupper;
+    _tolower; # introduced=21
+    _toupper; # introduced=21
     abort;
-    abs;
+    abs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     accept;
-    accept4;
+    accept4; # introduced=21
     access;
     acct;
     alarm;
     alphasort;
-    alphasort64;
-    android_set_abort_message;
+    alphasort64; # introduced=21
+    android_set_abort_message; # introduced=21
     arc4random;
     arc4random_buf;
     arc4random_uniform;
     asctime;
     asctime_r;
     asprintf;
-    at_quick_exit;
-    atof;
+    at_quick_exit; # introduced=21
+    atof; # introduced=21
     atoi;
     atol;
     atoll;
@@ -188,74 +188,74 @@
     brk;
     bsearch;
     btowc;
-    c16rtomb;
-    c32rtomb;
+    c16rtomb; # introduced=21
+    c32rtomb; # introduced=21
     calloc;
     capget;
     capset;
-    cfgetispeed;
-    cfgetospeed;
-    cfmakeraw;
-    cfsetispeed;
-    cfsetospeed;
-    cfsetspeed;
+    cfgetispeed; # introduced=21
+    cfgetospeed; # introduced=21
+    cfmakeraw; # introduced=21
+    cfsetispeed; # introduced=21
+    cfsetospeed; # introduced=21
+    cfsetspeed; # introduced=21
     chdir;
     chmod;
     chown;
     chroot;
     clearenv;
     clearerr;
-    clearerr_unlocked;
+    clearerr_unlocked; # introduced=23
     clock;
-    clock_getcpuclockid;
+    clock_getcpuclockid; # introduced=23
     clock_getres;
     clock_gettime;
     clock_nanosleep;
     clock_settime;
-    clone;
+    clone; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     close;
     closedir;
     closelog;
     connect;
     creat;
-    creat64;
+    creat64; # introduced=21
     ctime;
     ctime_r;
     daemon;
-    daylight;
+    daylight; # var
     delete_module;
     difftime;
     dirfd;
     dirname;
     div;
     dn_expand;
-    dprintf;
+    dprintf; # introduced=21
     drand48;
     dup;
     dup2;
-    dup3;
-    duplocale;
-    endmntent;
+    dup3; # introduced=21
+    duplocale; # introduced=21
+    endmntent; # introduced=21
     endservent;
     endutent;
-    environ;
+    environ; # var
     epoll_create;
-    epoll_create1;
+    epoll_create1; # introduced=21
     epoll_ctl;
-    epoll_pwait;
+    epoll_pwait; # introduced=21
     epoll_wait;
     erand48;
     err;
-    error;
-    error_at_line;
-    error_message_count;
-    error_one_per_line;
-    error_print_progname;
+    error; # introduced=23
+    error_at_line; # introduced=23
+    error_message_count; # var introduced=23
+    error_one_per_line; # var introduced=23
+    error_print_progname; # var introduced=23
     errx;
-    ether_aton;
-    ether_aton_r;
-    ether_ntoa;
-    ether_ntoa_r;
+    ether_aton; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_aton_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_ntoa; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_ntoa_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     eventfd;
     eventfd_read;
     eventfd_write;
@@ -265,11 +265,11 @@
     execv;
     execve;
     execvp;
-    execvpe;
+    execvpe; # introduced=21
     exit;
-    faccessat;
-    fallocate;
-    fallocate64;
+    faccessat; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    fallocate; # introduced=21
+    fallocate64; # introduced=21
     fchdir;
     fchmod;
     fchmodat;
@@ -281,27 +281,27 @@
     fdopen;
     fdopendir;
     feof;
-    feof_unlocked;
+    feof_unlocked; # introduced=23
     ferror;
-    ferror_unlocked;
+    ferror_unlocked; # introduced=23
     fflush;
-    ffs;
+    ffs; # introduced-arm=9 introduced-arm64=21 introduced-mips=9 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     fgetc;
     fgetln;
     fgetpos;
     fgets;
     fgetwc;
     fgetws;
-    fgetxattr;
+    fgetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     fileno;
-    flistxattr;
+    flistxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     flock;
     flockfile;
-    fmemopen;
+    fmemopen; # introduced=23
     fnmatch;
     fopen;
     fork;
-    forkpty;
+    forkpty; # introduced=23
     fpathconf;
     fprintf;
     fpurge;
@@ -312,56 +312,56 @@
     fread;
     free;
     freeaddrinfo;
-    freelocale;
-    fremovexattr;
+    freelocale; # introduced=21
+    fremovexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     freopen;
     fscanf;
     fseek;
     fseeko;
     fsetpos;
-    fsetxattr;
+    fsetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     fstat;
-    fstat64;
+    fstat64; # introduced=21
     fstatat;
-    fstatat64;
+    fstatat64; # introduced=21
     fstatfs;
-    fstatfs64;
-    fstatvfs;
-    fstatvfs64;
+    fstatfs64; # introduced=21
+    fstatvfs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    fstatvfs64; # introduced=21
     fsync;
     ftell;
     ftello;
     ftok;
     ftruncate;
-    ftruncate64;
+    ftruncate64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     ftrylockfile;
     fts_children;
     fts_close;
     fts_open;
     fts_read;
     fts_set;
-    ftw;
-    ftw64;
+    ftw; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    ftw64; # introduced=21
     funlockfile;
     funopen;
-    futimens;
+    futimens; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     fwide;
     fwprintf;
     fwrite;
     fwscanf;
     gai_strerror;
-    get_avphys_pages;
-    get_nprocs;
-    get_nprocs_conf;
-    get_phys_pages;
+    get_avphys_pages; # introduced=23
+    get_nprocs; # introduced=23
+    get_nprocs_conf; # introduced=23
+    get_phys_pages; # introduced=23
     getaddrinfo;
-    getauxval;
+    getauxval; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getc;
     getc_unlocked;
     getchar;
     getchar_unlocked;
     getcwd;
-    getdelim;
+    getdelim; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getegid;
     getenv;
     geteuid;
@@ -371,49 +371,49 @@
     getgrouplist;
     getgroups;
     gethostbyaddr;
-    gethostbyaddr_r;
+    gethostbyaddr_r; # introduced=23
     gethostbyname;
     gethostbyname2;
-    gethostbyname2_r;
+    gethostbyname2_r; # introduced=23
     gethostbyname_r;
     gethostent;
     gethostname;
     getitimer;
-    getline;
+    getline; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getlogin;
     getmntent;
-    getmntent_r;
+    getmntent_r; # introduced=21
     getnameinfo;
     getnetbyaddr;
     getnetbyname;
     getopt;
     getopt_long;
     getopt_long_only;
-    getpagesize;
+    getpagesize; # introduced=21
     getpeername;
     getpgid;
     getpgrp;
     getpid;
     getppid;
     getpriority;
-    getprogname;
+    getprogname; # introduced=21
     getprotobyname;
     getprotobynumber;
     getpt;
     getpwnam;
-    getpwnam_r;
+    getpwnam_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     getpwuid;
-    getpwuid_r;
+    getpwuid_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     getresgid;
     getresuid;
     getrlimit;
-    getrlimit64;
+    getrlimit64; # introduced=21
     getrusage;
     gets;
     getservbyname;
     getservbyport;
     getservent;
-    getsid;
+    getsid; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     getsockname;
     getsockopt;
     gettid;
@@ -422,24 +422,24 @@
     getutent;
     getwc;
     getwchar;
-    getxattr;
+    getxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     gmtime;
     gmtime_r;
-    grantpt;
+    grantpt; # introduced=21
     herror;
     hstrerror;
-    htonl;
-    htons;
+    htonl; # introduced=21
+    htons; # introduced=21
     if_indextoname;
     if_nametoindex;
-    imaxabs;
-    imaxdiv;
+    imaxabs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    imaxdiv; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     inet_addr;
     inet_aton;
-    inet_lnaof;
-    inet_makeaddr;
-    inet_netof;
-    inet_network;
+    inet_lnaof; # introduced=21
+    inet_makeaddr; # introduced=21
+    inet_netof; # introduced=21
+    inet_network; # introduced=21
     inet_nsap_addr;
     inet_nsap_ntoa;
     inet_ntoa;
@@ -447,122 +447,122 @@
     inet_pton;
     init_module;
     initgroups;
-    initstate;
+    initstate; # introduced=21
     inotify_add_watch;
     inotify_init;
-    inotify_init1;
+    inotify_init1; # introduced=21
     inotify_rm_watch;
-    insque;
+    insque; # introduced=21
     ioctl;
     isalnum;
-    isalnum_l;
+    isalnum_l; # introduced=21
     isalpha;
-    isalpha_l;
+    isalpha_l; # introduced=21
     isascii;
     isatty;
     isblank;
-    isblank_l;
+    isblank_l; # introduced=21
     iscntrl;
-    iscntrl_l;
+    iscntrl_l; # introduced=21
     isdigit;
-    isdigit_l;
-    isfinite;
-    isfinitef;
-    isfinitel;
+    isdigit_l; # introduced=21
+    isfinite; # introduced=21
+    isfinitef; # introduced=21
+    isfinitel; # introduced=21
     isgraph;
-    isgraph_l;
-    isinf;
-    isinff;
-    isinfl;
+    isgraph_l; # introduced=21
+    isinf; # introduced=21
+    isinff; # introduced=21
+    isinfl; # introduced=21
     islower;
-    islower_l;
+    islower_l; # introduced=21
     isnan;
     isnanf;
-    isnanl;
-    isnormal;
-    isnormalf;
-    isnormall;
+    isnanl; # introduced=21
+    isnormal; # introduced=21
+    isnormalf; # introduced=21
+    isnormall; # introduced=21
     isprint;
-    isprint_l;
+    isprint_l; # introduced=21
     ispunct;
-    ispunct_l;
+    ispunct_l; # introduced=21
     isspace;
-    isspace_l;
+    isspace_l; # introduced=21
     isupper;
-    isupper_l;
+    isupper_l; # introduced=21
     iswalnum;
-    iswalnum_l;
+    iswalnum_l; # introduced=21
     iswalpha;
-    iswalpha_l;
-    iswblank;
-    iswblank_l;
+    iswalpha_l; # introduced=21
+    iswblank; # introduced=21
+    iswblank_l; # introduced=21
     iswcntrl;
-    iswcntrl_l;
+    iswcntrl_l; # introduced=21
     iswctype;
-    iswctype_l;
+    iswctype_l; # introduced=21
     iswdigit;
-    iswdigit_l;
+    iswdigit_l; # introduced=21
     iswgraph;
-    iswgraph_l;
+    iswgraph_l; # introduced=21
     iswlower;
-    iswlower_l;
+    iswlower_l; # introduced=21
     iswprint;
-    iswprint_l;
+    iswprint_l; # introduced=21
     iswpunct;
-    iswpunct_l;
+    iswpunct_l; # introduced=21
     iswspace;
-    iswspace_l;
+    iswspace_l; # introduced=21
     iswupper;
-    iswupper_l;
+    iswupper_l; # introduced=21
     iswxdigit;
-    iswxdigit_l;
+    iswxdigit_l; # introduced=21
     isxdigit;
-    isxdigit_l;
+    isxdigit_l; # introduced=21
     jrand48;
     kill;
     killpg;
     klogctl;
-    labs;
+    labs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     lchown;
-    lcong48;
+    lcong48; # introduced=23
     ldexp;
     ldiv;
-    lfind;
-    lgetxattr;
+    lfind; # introduced=21
+    lgetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     link;
-    linkat;
+    linkat; # introduced=21
     listen;
-    listxattr;
-    llabs;
+    listxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    llabs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     lldiv;
-    llistxattr;
-    localeconv;
+    llistxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    localeconv; # introduced=21
     localtime;
     localtime_r;
-    login_tty;
+    login_tty; # introduced=23
     longjmp;
     lrand48;
-    lremovexattr;
-    lsearch;
+    lremovexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    lsearch; # introduced=21
     lseek;
     lseek64;
-    lsetxattr;
+    lsetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     lstat;
-    lstat64;
+    lstat64; # introduced=21
     madvise;
     mallinfo;
     malloc;
-    malloc_info;
-    malloc_usable_size;
+    malloc_info; # introduced=23
+    malloc_usable_size; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     mbrlen;
-    mbrtoc16;
-    mbrtoc32;
+    mbrtoc16; # introduced=21
+    mbrtoc32; # introduced=21
     mbrtowc;
     mbsinit;
-    mbsnrtowcs;
+    mbsnrtowcs; # introduced=21
     mbsrtowcs;
     mbstowcs;
-    mbtowc;
+    mbtowc; # introduced=21
     memalign;
     memccpy;
     memchr;
@@ -570,113 +570,113 @@
     memcpy;
     memmem;
     memmove;
-    mempcpy;
+    mempcpy; # introduced=23
     memrchr;
     memset;
     mincore;
     mkdir;
     mkdirat;
     mkdtemp;
-    mkfifo;
-    mkfifoat;
+    mkfifo; # introduced=21
+    mkfifoat; # introduced=23
     mknod;
-    mknodat;
-    mkostemp;
-    mkostemp64;
-    mkostemps;
-    mkostemps64;
+    mknodat; # introduced=21
+    mkostemp; # introduced=23
+    mkostemp64; # introduced=23
+    mkostemps; # introduced=23
+    mkostemps64; # introduced=23
     mkstemp;
-    mkstemp64;
+    mkstemp64; # introduced=21
     mkstemps;
-    mkstemps64;
+    mkstemps64; # introduced=23
     mktemp;
     mktime;
     mlock;
-    mlockall;
+    mlockall; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     mmap;
-    mmap64;
+    mmap64; # introduced=21
     mount;
     mprotect;
     mrand48;
     mremap;
     msync;
     munlock;
-    munlockall;
+    munlockall; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     munmap;
     nanosleep;
-    newlocale;
-    nftw;
-    nftw64;
+    newlocale; # introduced=21
+    nftw; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    nftw64; # introduced=21
     nice;
     nrand48;
-    ns_format_ttl; # arm64 x86_64 mips64
-    ns_get16; # arm64 x86_64 mips64
-    ns_get32; # arm64 x86_64 mips64
-    ns_initparse; # arm64 x86_64 mips64
-    ns_makecanon; # arm64 x86_64 mips64
-    ns_msg_getflag; # arm64 x86_64 mips64
-    ns_name_compress; # arm64 x86_64 mips64
-    ns_name_ntol; # arm64 x86_64 mips64
-    ns_name_ntop; # arm64 x86_64 mips64
-    ns_name_pack; # arm64 x86_64 mips64
-    ns_name_pton; # arm64 x86_64 mips64
-    ns_name_rollback; # arm64 x86_64 mips64
-    ns_name_skip; # arm64 x86_64 mips64
-    ns_name_uncompress; # arm64 x86_64 mips64
-    ns_name_unpack; # arm64 x86_64 mips64
-    ns_parserr; # arm64 x86_64 mips64
-    ns_put16; # arm64 x86_64 mips64
-    ns_put32; # arm64 x86_64 mips64
-    ns_samename; # arm64 x86_64 mips64
-    ns_skiprr; # arm64 x86_64 mips64
-    ns_sprintrr; # arm64 x86_64 mips64
-    ns_sprintrrf; # arm64 x86_64 mips64
+    ns_format_ttl; # arm64 x86_64 mips64 introduced=22
+    ns_get16; # arm64 x86_64 mips64 introduced=22
+    ns_get32; # arm64 x86_64 mips64 introduced=22
+    ns_initparse; # arm64 x86_64 mips64 introduced=22
+    ns_makecanon; # arm64 x86_64 mips64 introduced=22
+    ns_msg_getflag; # arm64 x86_64 mips64 introduced=22
+    ns_name_compress; # arm64 x86_64 mips64 introduced=22
+    ns_name_ntol; # arm64 x86_64 mips64 introduced=22
+    ns_name_ntop; # arm64 x86_64 mips64 introduced=22
+    ns_name_pack; # arm64 x86_64 mips64 introduced=22
+    ns_name_pton; # arm64 x86_64 mips64 introduced=23
+    ns_name_rollback; # arm64 x86_64 mips64 introduced=22
+    ns_name_skip; # arm64 x86_64 mips64 introduced=22
+    ns_name_uncompress; # arm64 x86_64 mips64 introduced=22
+    ns_name_unpack; # arm64 x86_64 mips64 introduced=22
+    ns_parserr; # arm64 x86_64 mips64 introduced=22
+    ns_put16; # arm64 x86_64 mips64 introduced=22
+    ns_put32; # arm64 x86_64 mips64 introduced=22
+    ns_samename; # arm64 x86_64 mips64 introduced=22
+    ns_skiprr; # arm64 x86_64 mips64 introduced=22
+    ns_sprintrr; # arm64 x86_64 mips64 introduced=22
+    ns_sprintrrf; # arm64 x86_64 mips64 introduced=22
     nsdispatch;
-    ntohl;
-    ntohs;
+    ntohl; # introduced=21
+    ntohs; # introduced=21
     open;
-    open64;
-    open_memstream;
-    open_wmemstream;
+    open64; # introduced=21
+    open_memstream; # introduced=23
+    open_wmemstream; # introduced=23
     openat;
-    openat64;
+    openat64; # introduced=21
     opendir;
     openlog;
-    openpty;
-    optarg;
-    opterr;
-    optind;
-    optopt;
-    optreset;
+    openpty; # introduced=23
+    optarg; # var
+    opterr; # var
+    optind; # var
+    optopt; # var
+    optreset; # var
     pathconf;
     pause;
     pclose;
     perror;
-    personality;
+    personality; # introduced-arm=15 introduced-arm64=21 introduced-mips=15 introduced-mips64=21 introduced-x86=15 introduced-x86_64=21
     pipe;
     pipe2;
     poll;
     popen;
-    posix_fadvise;
-    posix_fadvise64;
-    posix_fallocate;
-    posix_fallocate64;
-    posix_madvise;
-    posix_memalign;
-    posix_openpt;
-    ppoll;
+    posix_fadvise; # introduced=21
+    posix_fadvise64; # introduced=21
+    posix_fallocate; # introduced=21
+    posix_fallocate64; # introduced=21
+    posix_madvise; # introduced=23
+    posix_memalign; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    posix_openpt; # introduced=21
+    ppoll; # introduced=21
     prctl;
     pread;
-    pread64;
+    pread64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     printf;
     prlimit; # arm64 x86_64 mips64
-    prlimit64;
-    process_vm_readv;
-    process_vm_writev;
+    prlimit64; # introduced=21
+    process_vm_readv; # introduced=23
+    process_vm_writev; # introduced=23
     pselect;
-    psiginfo;
-    psignal;
-    pthread_atfork;
+    psiginfo; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    psignal; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    pthread_atfork; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     pthread_attr_destroy;
     pthread_attr_getdetachstate;
     pthread_attr_getguardsize;
@@ -700,10 +700,10 @@
     pthread_cond_timedwait;
     pthread_cond_wait;
     pthread_condattr_destroy;
-    pthread_condattr_getclock;
+    pthread_condattr_getclock; # introduced=21
     pthread_condattr_getpshared;
     pthread_condattr_init;
-    pthread_condattr_setclock;
+    pthread_condattr_setclock; # introduced=21
     pthread_condattr_setpshared;
     pthread_create;
     pthread_detach;
@@ -713,7 +713,7 @@
     pthread_getcpuclockid;
     pthread_getschedparam;
     pthread_getspecific;
-    pthread_gettid_np;
+    pthread_gettid_np; # introduced=21
     pthread_join;
     pthread_key_create;
     pthread_key_delete;
@@ -721,7 +721,7 @@
     pthread_mutex_destroy;
     pthread_mutex_init;
     pthread_mutex_lock;
-    pthread_mutex_timedlock;
+    pthread_mutex_timedlock; # introduced=21
     pthread_mutex_trylock;
     pthread_mutex_unlock;
     pthread_mutexattr_destroy;
@@ -741,10 +741,10 @@
     pthread_rwlock_unlock;
     pthread_rwlock_wrlock;
     pthread_rwlockattr_destroy;
-    pthread_rwlockattr_getkind_np;
+    pthread_rwlockattr_getkind_np; # introduced=23
     pthread_rwlockattr_getpshared;
     pthread_rwlockattr_init;
-    pthread_rwlockattr_setkind_np;
+    pthread_rwlockattr_setkind_np; # introduced=23
     pthread_rwlockattr_setpshared;
     pthread_self;
     pthread_setname_np;
@@ -764,36 +764,36 @@
     putwc;
     putwchar;
     pwrite;
-    pwrite64;
+    pwrite64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     qsort;
-    quick_exit;
+    quick_exit; # introduced=21
     raise;
-    rand;
-    rand_r;
-    random;
+    rand; # introduced=21
+    rand_r; # introduced=21
+    random; # introduced=21
     read;
-    readahead;
+    readahead; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     readdir;
-    readdir64;
-    readdir64_r;
+    readdir64; # introduced=21
+    readdir64_r; # introduced=21
     readdir_r;
     readlink;
-    readlinkat;
+    readlinkat; # introduced=21
     readv;
     realloc;
     realpath;
     reboot;
     recv;
     recvfrom;
-    recvmmsg;
+    recvmmsg; # introduced=21
     recvmsg;
     regcomp;
     regerror;
     regexec;
     regfree;
     remove;
-    removexattr;
-    remque;
+    removexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    remque; # introduced=21
     rename;
     renameat;
     res_init;
@@ -805,21 +805,21 @@
     rmdir;
     sbrk;
     scandir;
-    scandir64;
+    scandir64; # introduced=21
     scanf;
     sched_get_priority_max;
     sched_get_priority_min;
-    sched_getaffinity;
-    sched_getcpu;
+    sched_getaffinity; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    sched_getcpu; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sched_getparam;
     sched_getscheduler;
     sched_rr_get_interval;
-    sched_setaffinity;
+    sched_setaffinity; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sched_setparam;
     sched_setscheduler;
     sched_yield;
     seed48;
-    seekdir;
+    seekdir; # introduced=23
     select;
     sem_close;
     sem_destroy;
@@ -833,8 +833,8 @@
     sem_wait;
     send;
     sendfile;
-    sendfile64;
-    sendmmsg;
+    sendfile64; # introduced=21
+    sendmmsg; # introduced=21
     sendmsg;
     sendto;
     setbuf;
@@ -842,101 +842,101 @@
     setegid;
     setenv;
     seteuid;
-    setfsgid;
-    setfsuid;
+    setfsgid; # introduced=21
+    setfsuid; # introduced=21
     setgid;
     setgroups;
-    sethostname;
+    sethostname; # introduced=23
     setitimer;
     setjmp;
     setlinebuf;
     setlocale;
     setlogmask;
-    setmntent;
-    setns;
+    setmntent; # introduced=21
+    setns; # introduced=21
     setpgid;
     setpgrp;
     setpriority;
-    setprogname;
+    setprogname; # introduced=21
     setregid;
     setresgid;
     setresuid;
     setreuid;
     setrlimit;
-    setrlimit64;
+    setrlimit64; # introduced=21
     setservent;
     setsid;
     setsockopt;
-    setstate;
+    setstate; # introduced=21
     settimeofday;
     setuid;
     setutent;
     setvbuf;
-    setxattr;
+    setxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     shutdown;
     sigaction;
-    sigaddset;
+    sigaddset; # introduced=21
     sigaltstack;
     sigblock;
-    sigdelset;
-    sigemptyset;
-    sigfillset;
+    sigdelset; # introduced=21
+    sigemptyset; # introduced=21
+    sigfillset; # introduced=21
     siginterrupt;
-    sigismember;
-    siglongjmp;
-    signal;
-    signalfd;
+    sigismember; # introduced=21
+    siglongjmp; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    signal; # introduced=21
+    signalfd; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     sigpending;
     sigprocmask;
-    sigqueue;
-    sigsetjmp;
+    sigqueue; # introduced=23
+    sigsetjmp; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sigsetmask;
     sigsuspend;
-    sigtimedwait;
+    sigtimedwait; # introduced=23
     sigwait;
-    sigwaitinfo;
+    sigwaitinfo; # introduced=23
     sleep;
     snprintf;
     socket;
     socketpair;
-    splice;
+    splice; # introduced=21
     sprintf;
-    srand;
+    srand; # introduced=21
     srand48;
-    srandom;
+    srandom; # introduced=21
     sscanf;
     stat;
-    stat64;
+    stat64; # introduced=21
     statfs;
-    statfs64;
-    statvfs;
-    statvfs64;
-    stderr;
-    stdin;
-    stdout;
-    stpcpy;
-    stpncpy;
+    statfs64; # introduced=21
+    statvfs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    statvfs64; # introduced=21
+    stderr; # var introduced=23
+    stdin; # var introduced=23
+    stdout; # var introduced=23
+    stpcpy; # introduced=21
+    stpncpy; # introduced=21
     strcasecmp;
-    strcasecmp_l;
+    strcasecmp_l; # introduced=23
     strcasestr;
     strcat;
     strchr;
     strcmp;
     strcoll;
-    strcoll_l;
+    strcoll_l; # introduced=21
     strcpy;
     strcspn;
     strdup;
     strerror;
-    strerror_l;
+    strerror_l; # introduced=23
     strerror_r;
     strftime;
-    strftime_l;
+    strftime_l; # introduced=21
     strlcat;
     strlcpy;
     strlen;
     strncasecmp;
-    strncasecmp_l;
+    strncasecmp_l; # introduced=23
     strncat;
     strncmp;
     strncpy;
@@ -950,84 +950,84 @@
     strspn;
     strstr;
     strtod;
-    strtof;
+    strtof; # introduced=21
     strtoimax;
     strtok;
     strtok_r;
     strtol;
-    strtold;
-    strtold_l;
+    strtold; # introduced=21
+    strtold_l; # introduced=21
     strtoll;
-    strtoll_l;
-    strtoq;
+    strtoll_l; # introduced=21
+    strtoq; # introduced=21
     strtoul;
     strtoull;
-    strtoull_l;
+    strtoull_l; # introduced=21
     strtoumax;
-    strtouq;
+    strtouq; # introduced=21
     strxfrm;
-    strxfrm_l;
-    swapoff;
-    swapon;
+    strxfrm_l; # introduced=21
+    swapoff; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    swapon; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     swprintf;
     swscanf;
     symlink;
-    symlinkat;
+    symlinkat; # introduced=21
     sync;
-    sys_siglist;
-    sys_signame;
+    sys_siglist; # var
+    sys_signame; # var
     syscall;
     sysconf;
     sysinfo;
     syslog;
     system;
-    tcdrain;
-    tcflow;
-    tcflush;
-    tcgetattr;
+    tcdrain; # introduced=21
+    tcflow; # introduced=21
+    tcflush; # introduced=21
+    tcgetattr; # introduced=21
     tcgetpgrp;
-    tcgetsid;
-    tcsendbreak;
-    tcsetattr;
+    tcgetsid; # introduced=21
+    tcsendbreak; # introduced=21
+    tcsetattr; # introduced=21
     tcsetpgrp;
-    tdelete;
-    tdestroy;
-    tee;
-    telldir;
+    tdelete; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tdestroy; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tee; # introduced=21
+    telldir; # introduced=23
     tempnam;
-    tfind;
-    tgkill;
+    tfind; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tgkill; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     time;
-    timegm;
-    timelocal;
+    timegm; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    timelocal; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     timer_create;
     timer_delete;
     timer_getoverrun;
     timer_gettime;
     timer_settime;
-    timerfd_create;
-    timerfd_gettime;
-    timerfd_settime;
+    timerfd_create; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    timerfd_gettime; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    timerfd_settime; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     times;
-    timezone;
+    timezone; # var
     tmpfile;
     tmpnam;
     toascii;
     tolower;
-    tolower_l;
+    tolower_l; # introduced=21
     toupper;
-    toupper_l;
+    toupper_l; # introduced=21
     towlower;
-    towlower_l;
+    towlower_l; # introduced=21
     towupper;
-    towupper_l;
+    towupper_l; # introduced=21
     truncate;
-    truncate64;
-    tsearch;
+    truncate64; # introduced=21
+    tsearch; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     ttyname;
     ttyname_r;
-    twalk;
-    tzname;
+    twalk; # introduced=21
+    tzname; # var
     tzset;
     umask;
     umount;
@@ -1039,37 +1039,37 @@
     unlinkat;
     unlockpt;
     unsetenv;
-    unshare;
-    uselocale;
+    unshare; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    uselocale; # introduced=21
     usleep;
     utime;
-    utimensat;
+    utimensat; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     utimes;
     utmpname;
     vasprintf;
-    vdprintf;
+    vdprintf; # introduced=21
     verr;
     verrx;
     vfork;
     vfprintf;
     vfscanf;
     vfwprintf;
-    vfwscanf;
-    vmsplice;
+    vfwscanf; # introduced=21
+    vmsplice; # introduced=21
     vprintf;
     vscanf;
     vsnprintf;
     vsprintf;
     vsscanf;
     vswprintf;
-    vswscanf;
+    vswscanf; # introduced=21
     vsyslog;
     vwarn;
     vwarnx;
     vwprintf;
-    vwscanf;
+    vwscanf; # introduced=21
     wait;
-    wait4;
+    wait4; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     waitid;
     waitpid;
     warn;
@@ -1078,12 +1078,12 @@
     wcpncpy;
     wcrtomb;
     wcscasecmp;
-    wcscasecmp_l;
+    wcscasecmp_l; # introduced=23
     wcscat;
     wcschr;
     wcscmp;
     wcscoll;
-    wcscoll_l;
+    wcscoll_l; # introduced=21
     wcscpy;
     wcscspn;
     wcsdup;
@@ -1092,44 +1092,44 @@
     wcslcpy;
     wcslen;
     wcsncasecmp;
-    wcsncasecmp_l;
+    wcsncasecmp_l; # introduced=23
     wcsncat;
     wcsncmp;
     wcsncpy;
     wcsnlen;
-    wcsnrtombs;
+    wcsnrtombs; # introduced=21
     wcspbrk;
     wcsrchr;
     wcsrtombs;
     wcsspn;
     wcsstr;
     wcstod;
-    wcstof;
-    wcstoimax;
+    wcstof; # introduced=21
+    wcstoimax; # introduced=21
     wcstok;
     wcstol;
-    wcstold;
-    wcstold_l;
-    wcstoll;
-    wcstoll_l;
+    wcstold; # introduced=21
+    wcstold_l; # introduced=21
+    wcstoll; # introduced=21
+    wcstoll_l; # introduced=21
     wcstombs;
     wcstoul;
-    wcstoull;
-    wcstoull_l;
-    wcstoumax;
+    wcstoull; # introduced=21
+    wcstoull_l; # introduced=21
+    wcstoumax; # introduced=21
     wcswidth;
     wcsxfrm;
-    wcsxfrm_l;
+    wcsxfrm_l; # introduced=21
     wctob;
-    wctomb;
+    wctomb; # introduced=21
     wctype;
-    wctype_l;
+    wctype_l; # introduced=21
     wcwidth;
     wmemchr;
     wmemcmp;
     wmemcpy;
     wmemmove;
-    wmempcpy;
+    wmempcpy; # introduced=23
     wmemset;
     wprintf;
     write;
@@ -1139,56 +1139,90 @@
     *;
 };
 
-LIBC_N {
+LIBC_N { # introduced-arm64=24 introduced-mips=24 introduced-mips64=24 introduced-x86=24 introduced-x86_64=24
   global:
-    __fread_chk;
-    __fwrite_chk;
-    __getcwd_chk;
-    __pwrite_chk;
-    __pwrite64_chk;
-    __write_chk;
-    adjtimex;
-    clock_adjtime;
-    fgetpos64;
-    fileno_unlocked;
-    fopen64;
-    freeifaddrs;
-    freopen64;
-    fseeko64;
-    fsetpos64;
-    ftello64;
-    funopen64;
-    getgrgid_r;
-    getgrnam_r;
-    getifaddrs;
-    if_freenameindex;
-    if_nameindex;
-    in6addr_any;
-    in6addr_loopback;
-    lockf;
-    lockf64;
-    preadv;
-    preadv64;
-    pthread_barrierattr_destroy;
-    pthread_barrierattr_getpshared;
-    pthread_barrierattr_init;
-    pthread_barrierattr_setpshared;
-    pthread_barrier_destroy;
-    pthread_barrier_init;
-    pthread_barrier_wait;
-    pthread_spin_destroy;
-    pthread_spin_init;
-    pthread_spin_lock;
-    pthread_spin_trylock;
-    pthread_spin_unlock;
-    pwritev;
-    pwritev64;
-    scandirat;
-    scandirat64;
-    strchrnul;
-    tmpfile64;
+    __fread_chk; # introduced=24
+    __fwrite_chk; # introduced=24
+    __getcwd_chk; # introduced=24
+    __pwrite_chk; # introduced=24
+    __pwrite64_chk; # introduced=24
+    __write_chk; # introduced=24
+    adjtimex; # introduced=24
+    clock_adjtime; # introduced=24
+    fgetpos64; # introduced=24
+    fileno_unlocked; # introduced=24
+    fopen64; # introduced=24
+    freeifaddrs; # introduced=24
+    freopen64; # introduced=24
+    fseeko64; # introduced=24
+    fsetpos64; # introduced=24
+    ftello64; # introduced=24
+    funopen64; # introduced=24
+    getgrgid_r; # introduced=24
+    getgrnam_r; # introduced=24
+    getifaddrs; # introduced=24
+    if_freenameindex; # introduced=24
+    if_nameindex; # introduced=24
+    in6addr_any; # var introduced=24
+    in6addr_loopback; # var introduced=24
+    lockf; # introduced=24
+    lockf64; # introduced=24
+    preadv; # introduced=24
+    preadv64; # introduced=24
+    pthread_barrierattr_destroy; # introduced=24
+    pthread_barrierattr_getpshared; # introduced=24
+    pthread_barrierattr_init; # introduced=24
+    pthread_barrierattr_setpshared; # introduced=24
+    pthread_barrier_destroy; # introduced=24
+    pthread_barrier_init; # introduced=24
+    pthread_barrier_wait; # introduced=24
+    pthread_spin_destroy; # introduced=24
+    pthread_spin_init; # introduced=24
+    pthread_spin_lock; # introduced=24
+    pthread_spin_trylock; # introduced=24
+    pthread_spin_unlock; # introduced=24
+    pwritev; # introduced=24
+    pwritev64; # introduced=24
+    scandirat; # introduced=24
+    scandirat64; # introduced=24
+    strchrnul; # introduced=24
+    tmpfile64; # introduced=24
 } LIBC;
 
+LIBC_O {
+  global:
+    catclose; # future
+    catgets; # future
+    catopen; # future
+    ctermid; # future
+    endgrent; # future
+    endpwent; # future
+    futimes; # future
+    futimesat; # future
+    getdomainname; # future
+    getgrent; # future
+    getpwent; # future
+    getsubopt; # future
+    hasmntopt; # future
+    lutimes; # future
+    mblen; # future
+    pthread_getname_np; # future
+    quotactl; # future
+    setdomainname; # future
+    setgrent; # future
+    setpwent; # future
+    sighold; # future
+    sigignore; # future
+    sigpause; # future
+    sigrelse; # future
+    sigset; # future
+    sync_file_range; # future
+    towctrans; # future
+    towctrans_l; # future
+    wctrans; # future
+    wctrans_l; # future
+} LIBC_N;
+
 LIBC_PRIVATE {
   global:
     android_getaddrinfofornet;
@@ -1198,7 +1232,7 @@
     free_malloc_leak_info;
     get_malloc_leak_info;
     gMallocLeakZygoteChild;
-} LIBC_N;
+} LIBC_O;
 
 LIBC_PLATFORM {
   global:
@@ -1209,4 +1243,4 @@
     malloc_disable;
     malloc_enable;
     malloc_iterate;
-} LIBC_N;
+} LIBC_O;
diff --git a/libc/libc.map.txt b/libc/libc.map.txt
index 0e41f6c..8c3da20 100644
--- a/libc/libc.map.txt
+++ b/libc/libc.map.txt
@@ -8,46 +8,45 @@
     __atomic_swap; # arm
     __b64_ntop;
     __b64_pton;
-    __brk; # arm x86 mips
-    __cmsg_nxthdr;
-    __connect; # arm x86 mips
-    __ctype_get_mb_cur_max;
+    __cmsg_nxthdr; # introduced=21
+    __connect; # arm x86 mips introduced=21
+    __ctype_get_mb_cur_max; # introduced=21
     __cxa_atexit;
     __cxa_finalize;
-    __cxa_thread_atexit_impl;
+    __cxa_thread_atexit_impl; # introduced=23
     __dn_comp;
     __dn_count_labels;
     __dn_skipname;
-    __epoll_pwait; # arm x86 mips
+    __epoll_pwait; # arm x86 mips introduced=21
     __errno;
-    __exit; # arm x86 mips
-    __fadvise64; # x86 mips
-    __fbufsize;
+    __exit; # arm x86 mips introduced=21
+    __fadvise64; # x86 mips introduced=21
+    __fbufsize; # introduced=23
     __fcntl64; # arm x86 mips
-    __FD_CLR_chk;
-    __FD_ISSET_chk;
-    __FD_SET_chk;
-    __fgets_chk;
-    __flbf;
+    __FD_CLR_chk; # introduced=21
+    __FD_ISSET_chk; # introduced=21
+    __FD_SET_chk; # introduced=21
+    __fgets_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __flbf; # introduced=23
     __fp_nquery;
     __fp_query;
-    __fpclassify;
+    __fpclassify; # introduced=21
     __fpclassifyd;
     __fpclassifyf;
     __fpclassifyl;
-    __fpending;
-    __fpurge;
-    __freadable;
-    __fsetlocking;
+    __fpending; # introduced=23
+    __fpurge; # introduced=23
+    __freadable; # introduced=23
+    __fsetlocking; # introduced=23
     __fstatfs64; # arm x86 mips
-    __fwritable;
+    __fwritable; # introduced=23
     __get_h_errno;
-    __getcpu; # arm x86 mips
+    __getcpu; # arm x86 mips introduced-arm=12 introduced-mips=16 introduced-x86=12
     __getcwd; # arm x86 mips
-    __getpid; # arm x86 mips
+    __getpid; # arm x86 mips introduced=21
     __getpriority; # arm x86 mips
-    __gnu_basename;
-    __gnu_strerror_r;
+    __gnu_basename; # introduced=23
+    __gnu_strerror_r; # introduced=23
     __hostalias;
     __ioctl; # arm x86 mips
     __isfinite;
@@ -56,24 +55,24 @@
     __isinf;
     __isinff;
     __isinfl;
-    __isnan;
-    __isnanf;
+    __isnan; # introduced=21
+    __isnanf; # introduced=21
     __isnanl;
     __isnormal;
     __isnormalf;
     __isnormall;
-    __isthreaded; # arm x86 mips
-    __libc_current_sigrtmax;
-    __libc_current_sigrtmin;
+    __isthreaded; # arm x86 mips var
+    __libc_current_sigrtmax; # introduced=21
+    __libc_current_sigrtmin; # introduced=21
     __libc_init;
     __llseek; # arm x86 mips
     __loc_aton;
     __loc_ntoa;
-    __memchr_chk;
-    __memcpy_chk;
-    __memmove_chk;
-    __memrchr_chk;
-    __memset_chk;
+    __memchr_chk; # introduced=23
+    __memcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __memmove_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __memrchr_chk; # introduced=23
+    __memset_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __mmap2; # arm x86 mips
     __ns_format_ttl; # arm x86 mips
     __ns_get16; # arm x86 mips
@@ -97,13 +96,13 @@
     __ns_skiprr; # arm x86 mips
     __ns_sprintrr; # arm x86 mips
     __ns_sprintrrf; # arm x86 mips
-    __open_2;
+    __open_2; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __openat; # arm x86 mips
-    __openat_2;
+    __openat_2; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __p_cdname;
     __p_cdnname;
     __p_class;
-    __p_class_syms;
+    __p_class_syms; # var
     __p_fqname;
     __p_fqnname;
     __p_option;
@@ -112,25 +111,25 @@
     __p_secstodate;
     __p_time;
     __p_type;
-    __p_type_syms;
-    __poll_chk;
-    __ppoll; # arm x86 mips
-    __ppoll_chk;
-    __pread64_chk;
-    __pread_chk;
-    __progname;
-    __pselect6; # arm x86 mips
+    __p_type_syms; # var
+    __poll_chk; # introduced=23
+    __ppoll; # arm x86 mips introduced=21
+    __ppoll_chk; # introduced=23
+    __pread64_chk; # introduced=23
+    __pread_chk; # introduced=23
+    __progname; # var
+    __pselect6; # arm x86 mips introduced=21
     __pthread_cleanup_pop;
     __pthread_cleanup_push;
     __ptrace; # arm x86 mips
     __putlong;
     __putshort;
-    __read_chk;
-    __readlink_chk;
-    __readlinkat_chk;
+    __read_chk; # introduced=21
+    __readlink_chk; # introduced=23
+    __readlinkat_chk; # introduced=23
     __reboot; # arm x86 mips
-    __recvfrom_chk;
-    __register_atfork;
+    __recvfrom_chk; # introduced=21
+    __register_atfork; # introduced=23
     __res_close;
     __res_dnok;
     __res_hnok;
@@ -152,91 +151,91 @@
     __res_send_setqhook;
     __res_send_setrhook;
     __rt_sigaction; # arm x86 mips
-    __rt_sigpending; # arm x86 mips
+    __rt_sigpending; # arm x86 mips introduced=21
     __rt_sigprocmask; # arm x86 mips
-    __rt_sigsuspend; # arm x86 mips
+    __rt_sigsuspend; # arm x86 mips introduced=21
     __rt_sigtimedwait; # arm x86 mips
-    __sched_cpualloc;
-    __sched_cpucount;
-    __sched_cpufree;
-    __sched_getaffinity; # arm x86 mips
+    __sched_cpualloc; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_cpucount; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_cpufree; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_getaffinity; # arm x86 mips introduced=12
     __set_thread_area; # x86
-    __set_tid_address; # arm x86 mips
+    __set_tid_address; # arm x86 mips introduced=21
     __set_tls; # arm mips
-    __sF;
-    __sigaction; # arm x86 mips
-    __snprintf_chk;
-    __socket; # arm x86 mips
-    __sprintf_chk;
+    __sF; # var
+    __sigaction; # arm x86 mips introduced=21
+    __snprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __socket; # arm x86 mips introduced=21
+    __sprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __stack_chk_fail;
-    __stack_chk_guard;
+    __stack_chk_guard; # var
     __statfs64; # arm x86 mips
-    __stpcpy_chk;
-    __stpncpy_chk;
-    __stpncpy_chk2;
-    __strcat_chk;
-    __strchr_chk;
-    __strcpy_chk;
-    __strlcat_chk;
-    __strlcpy_chk;
-    __strlen_chk;
-    __strncat_chk;
-    __strncpy_chk;
-    __strncpy_chk2;
-    __strrchr_chk;
+    __stpcpy_chk; # introduced=21
+    __stpncpy_chk; # introduced=21
+    __stpncpy_chk2; # introduced=21
+    __strcat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strchr_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
+    __strcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlcat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlen_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncpy_chk2; # introduced=21
+    __strrchr_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     __sym_ntop;
     __sym_ntos;
     __sym_ston;
     __system_properties_init;
-    __system_property_add;
-    __system_property_area__;
-    __system_property_area_init;
-    __system_property_area_serial;
+    __system_property_add; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_area__; # var
+    __system_property_area_init; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_area_serial; # introduced=23
     __system_property_find;
     __system_property_find_nth;
-    __system_property_foreach;
+    __system_property_foreach; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     __system_property_get;
     __system_property_read;
-    __system_property_serial;
-    __system_property_set;
-    __system_property_set_filename;
-    __system_property_update;
-    __system_property_wait_any;
+    __system_property_serial; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_set; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __system_property_set_filename; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_update; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_wait_any; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     __timer_create; # arm x86 mips
     __timer_delete; # arm x86 mips
     __timer_getoverrun; # arm x86 mips
     __timer_gettime; # arm x86 mips
     __timer_settime; # arm x86 mips
-    __umask_chk;
-    __vsnprintf_chk;
-    __vsprintf_chk;
+    __umask_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
+    __vsnprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __vsprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __waitid; # arm x86 mips
-    _ctype_;
-    _Exit;
+    _ctype_; # var
+    _Exit; # introduced=21
     _exit;
     _flush_cache; # mips
-    _flushlbf;
+    _flushlbf; # introduced=23
     _getlong;
     _getshort;
     _longjmp;
-    _resolv_delete_cache_for_net;
-    _resolv_flush_cache_for_net;
-    _resolv_set_nameservers_for_net;
+    _resolv_delete_cache_for_net; # introduced=21
+    _resolv_flush_cache_for_net; # introduced=21
+    _resolv_set_nameservers_for_net; # introduced=21
     _setjmp;
-    _tolower;
-    _tolower_tab_; # arm x86 mips
-    _toupper;
-    _toupper_tab_; # arm x86 mips
+    _tolower; # introduced=21
+    _tolower_tab_; # arm x86 mips var
+    _toupper; # introduced=21
+    _toupper_tab_; # arm x86 mips var
     abort;
-    abs;
+    abs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     accept;
-    accept4;
+    accept4; # introduced=21
     access;
     acct;
     alarm;
     alphasort;
-    alphasort64;
-    android_set_abort_message;
+    alphasort64; # introduced=21
+    android_set_abort_message; # introduced=21
     arc4random;
     arc4random_buf;
     arc4random_uniform;
@@ -245,8 +244,8 @@
     asctime64_r; # arm x86 mips
     asctime_r;
     asprintf;
-    at_quick_exit;
-    atof;
+    at_quick_exit; # introduced=21
+    atof; # introduced=21
     atoi;
     atol;
     atoll;
@@ -257,44 +256,44 @@
     brk;
     bsearch;
     btowc;
-    c16rtomb;
-    c32rtomb;
+    c16rtomb; # introduced=21
+    c32rtomb; # introduced=21
     cacheflush; # arm mips
     calloc;
     capget;
     capset;
-    cfgetispeed;
-    cfgetospeed;
-    cfmakeraw;
-    cfsetispeed;
-    cfsetospeed;
-    cfsetspeed;
+    cfgetispeed; # introduced=21
+    cfgetospeed; # introduced=21
+    cfmakeraw; # introduced=21
+    cfsetispeed; # introduced=21
+    cfsetospeed; # introduced=21
+    cfsetspeed; # introduced=21
     chdir;
     chmod;
     chown;
     chroot;
     clearenv;
     clearerr;
-    clearerr_unlocked;
+    clearerr_unlocked; # introduced=23
     clock;
-    clock_getcpuclockid;
+    clock_getcpuclockid; # introduced=23
     clock_getres;
     clock_gettime;
     clock_nanosleep;
     clock_settime;
-    clone;
+    clone; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     close;
     closedir;
     closelog;
     connect;
     creat;
-    creat64;
+    creat64; # introduced=21
     ctime;
     ctime64; # arm x86 mips
     ctime64_r; # arm x86 mips
     ctime_r;
     daemon;
-    daylight;
+    daylight; # var
     delete_module;
     difftime;
     dirfd;
@@ -302,33 +301,33 @@
     dirname_r; # arm x86 mips
     div;
     dn_expand;
-    dprintf;
+    dprintf; # introduced=21
     drand48;
     dup;
     dup2;
-    dup3;
-    duplocale;
-    endmntent;
+    dup3; # introduced=21
+    duplocale; # introduced=21
+    endmntent; # introduced=21
     endservent;
     endutent;
-    environ;
+    environ; # var
     epoll_create;
-    epoll_create1;
+    epoll_create1; # introduced=21
     epoll_ctl;
-    epoll_pwait;
+    epoll_pwait; # introduced=21
     epoll_wait;
     erand48;
     err;
-    error;
-    error_at_line;
-    error_message_count;
-    error_one_per_line;
-    error_print_progname;
+    error; # introduced=23
+    error_at_line; # introduced=23
+    error_message_count; # var introduced=23
+    error_one_per_line; # var introduced=23
+    error_print_progname; # var introduced=23
     errx;
-    ether_aton;
-    ether_aton_r;
-    ether_ntoa;
-    ether_ntoa_r;
+    ether_aton; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_aton_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_ntoa; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_ntoa_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     eventfd;
     eventfd_read;
     eventfd_write;
@@ -338,11 +337,11 @@
     execv;
     execve;
     execvp;
-    execvpe;
+    execvpe; # introduced=21
     exit;
-    faccessat;
-    fallocate;
-    fallocate64;
+    faccessat; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    fallocate; # introduced=21
+    fallocate64; # introduced=21
     fchdir;
     fchmod;
     fchmodat;
@@ -354,27 +353,27 @@
     fdopen;
     fdopendir;
     feof;
-    feof_unlocked;
+    feof_unlocked; # introduced=23
     ferror;
-    ferror_unlocked;
+    ferror_unlocked; # introduced=23
     fflush;
-    ffs;
+    ffs; # introduced-arm=9 introduced-arm64=21 introduced-mips=9 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     fgetc;
     fgetln;
     fgetpos;
     fgets;
     fgetwc;
     fgetws;
-    fgetxattr;
+    fgetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     fileno;
-    flistxattr;
+    flistxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     flock;
     flockfile;
-    fmemopen;
+    fmemopen; # introduced=23
     fnmatch;
     fopen;
     fork;
-    forkpty;
+    forkpty; # introduced=23
     fpathconf;
     fprintf;
     fpurge;
@@ -385,56 +384,56 @@
     fread;
     free;
     freeaddrinfo;
-    freelocale;
-    fremovexattr;
+    freelocale; # introduced=21
+    fremovexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     freopen;
     fscanf;
     fseek;
     fseeko;
     fsetpos;
-    fsetxattr;
+    fsetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     fstat;
-    fstat64;
+    fstat64; # introduced=21
     fstatat;
-    fstatat64;
+    fstatat64; # introduced=21
     fstatfs;
-    fstatfs64;
-    fstatvfs;
-    fstatvfs64;
+    fstatfs64; # introduced=21
+    fstatvfs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    fstatvfs64; # introduced=21
     fsync;
     ftell;
     ftello;
     ftok;
     ftruncate;
-    ftruncate64;
+    ftruncate64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     ftrylockfile;
     fts_children;
     fts_close;
     fts_open;
     fts_read;
     fts_set;
-    ftw;
-    ftw64;
+    ftw; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    ftw64; # introduced=21
     funlockfile;
     funopen;
-    futimens;
+    futimens; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     fwide;
     fwprintf;
     fwrite;
     fwscanf;
     gai_strerror;
-    get_avphys_pages;
-    get_nprocs;
-    get_nprocs_conf;
-    get_phys_pages;
+    get_avphys_pages; # introduced=23
+    get_nprocs; # introduced=23
+    get_nprocs_conf; # introduced=23
+    get_phys_pages; # introduced=23
     getaddrinfo;
-    getauxval;
+    getauxval; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getc;
     getc_unlocked;
     getchar;
     getchar_unlocked;
     getcwd;
-    getdelim;
+    getdelim; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getegid;
     getenv;
     geteuid;
@@ -444,49 +443,49 @@
     getgrouplist;
     getgroups;
     gethostbyaddr;
-    gethostbyaddr_r;
+    gethostbyaddr_r; # introduced=23
     gethostbyname;
     gethostbyname2;
-    gethostbyname2_r;
+    gethostbyname2_r; # introduced=23
     gethostbyname_r;
     gethostent;
     gethostname;
     getitimer;
-    getline;
+    getline; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getlogin;
     getmntent;
-    getmntent_r;
+    getmntent_r; # introduced=21
     getnameinfo;
     getnetbyaddr;
     getnetbyname;
     getopt;
     getopt_long;
     getopt_long_only;
-    getpagesize;
+    getpagesize; # introduced=21
     getpeername;
     getpgid;
     getpgrp;
     getpid;
     getppid;
     getpriority;
-    getprogname;
+    getprogname; # introduced=21
     getprotobyname;
     getprotobynumber;
     getpt;
     getpwnam;
-    getpwnam_r;
+    getpwnam_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     getpwuid;
-    getpwuid_r;
+    getpwuid_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     getresgid;
     getresuid;
     getrlimit;
-    getrlimit64;
+    getrlimit64; # introduced=21
     getrusage;
     gets;
     getservbyname;
     getservbyport;
     getservent;
-    getsid;
+    getsid; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     getsockname;
     getsockopt;
     gettid;
@@ -495,26 +494,26 @@
     getutent;
     getwc;
     getwchar;
-    getxattr;
+    getxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     gmtime;
     gmtime64; # arm x86 mips
     gmtime64_r; # arm x86 mips
     gmtime_r;
-    grantpt;
+    grantpt; # introduced=21
     herror;
     hstrerror;
-    htonl;
-    htons;
+    htonl; # introduced=21
+    htons; # introduced=21
     if_indextoname;
     if_nametoindex;
-    imaxabs;
-    imaxdiv;
+    imaxabs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    imaxdiv; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     inet_addr;
     inet_aton;
-    inet_lnaof;
-    inet_makeaddr;
-    inet_netof;
-    inet_network;
+    inet_lnaof; # introduced=21
+    inet_makeaddr; # introduced=21
+    inet_netof; # introduced=21
+    inet_network; # introduced=21
     inet_nsap_addr;
     inet_nsap_ntoa;
     inet_ntoa;
@@ -522,124 +521,124 @@
     inet_pton;
     init_module;
     initgroups;
-    initstate;
+    initstate; # introduced=21
     inotify_add_watch;
     inotify_init;
-    inotify_init1;
+    inotify_init1; # introduced=21
     inotify_rm_watch;
-    insque;
+    insque; # introduced=21
     ioctl;
     isalnum;
-    isalnum_l;
+    isalnum_l; # introduced=21
     isalpha;
-    isalpha_l;
+    isalpha_l; # introduced=21
     isascii;
     isatty;
     isblank;
-    isblank_l;
+    isblank_l; # introduced=21
     iscntrl;
-    iscntrl_l;
+    iscntrl_l; # introduced=21
     isdigit;
-    isdigit_l;
-    isfinite;
-    isfinitef;
-    isfinitel;
+    isdigit_l; # introduced=21
+    isfinite; # introduced=21
+    isfinitef; # introduced=21
+    isfinitel; # introduced=21
     isgraph;
-    isgraph_l;
-    isinf;
-    isinff;
-    isinfl;
+    isgraph_l; # introduced=21
+    isinf; # introduced=21
+    isinff; # introduced=21
+    isinfl; # introduced=21
     islower;
-    islower_l;
+    islower_l; # introduced=21
     isnan;
     isnanf;
-    isnanl;
-    isnormal;
-    isnormalf;
-    isnormall;
+    isnanl; # introduced=21
+    isnormal; # introduced=21
+    isnormalf; # introduced=21
+    isnormall; # introduced=21
     isprint;
-    isprint_l;
+    isprint_l; # introduced=21
     ispunct;
-    ispunct_l;
+    ispunct_l; # introduced=21
     isspace;
-    isspace_l;
+    isspace_l; # introduced=21
     isupper;
-    isupper_l;
+    isupper_l; # introduced=21
     iswalnum;
-    iswalnum_l;
+    iswalnum_l; # introduced=21
     iswalpha;
-    iswalpha_l;
-    iswblank;
-    iswblank_l;
+    iswalpha_l; # introduced=21
+    iswblank; # introduced=21
+    iswblank_l; # introduced=21
     iswcntrl;
-    iswcntrl_l;
+    iswcntrl_l; # introduced=21
     iswctype;
-    iswctype_l;
+    iswctype_l; # introduced=21
     iswdigit;
-    iswdigit_l;
+    iswdigit_l; # introduced=21
     iswgraph;
-    iswgraph_l;
+    iswgraph_l; # introduced=21
     iswlower;
-    iswlower_l;
+    iswlower_l; # introduced=21
     iswprint;
-    iswprint_l;
+    iswprint_l; # introduced=21
     iswpunct;
-    iswpunct_l;
+    iswpunct_l; # introduced=21
     iswspace;
-    iswspace_l;
+    iswspace_l; # introduced=21
     iswupper;
-    iswupper_l;
+    iswupper_l; # introduced=21
     iswxdigit;
-    iswxdigit_l;
+    iswxdigit_l; # introduced=21
     isxdigit;
-    isxdigit_l;
+    isxdigit_l; # introduced=21
     jrand48;
     kill;
     killpg;
     klogctl;
-    labs;
+    labs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     lchown;
-    lcong48;
+    lcong48; # introduced=23
     ldexp;
     ldiv;
-    lfind;
-    lgetxattr;
+    lfind; # introduced=21
+    lgetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     link;
-    linkat;
+    linkat; # introduced=21
     listen;
-    listxattr;
-    llabs;
+    listxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    llabs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     lldiv;
-    llistxattr;
-    localeconv;
+    llistxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    localeconv; # introduced=21
     localtime;
     localtime64; # arm x86 mips
     localtime64_r; # arm x86 mips
     localtime_r;
-    login_tty;
+    login_tty; # introduced=23
     longjmp;
     lrand48;
-    lremovexattr;
-    lsearch;
+    lremovexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    lsearch; # introduced=21
     lseek;
     lseek64;
-    lsetxattr;
+    lsetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     lstat;
-    lstat64;
+    lstat64; # introduced=21
     madvise;
     mallinfo;
     malloc;
-    malloc_info;
-    malloc_usable_size;
+    malloc_info; # introduced=23
+    malloc_usable_size; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     mbrlen;
-    mbrtoc16;
-    mbrtoc32;
+    mbrtoc16; # introduced=21
+    mbrtoc32; # introduced=21
     mbrtowc;
     mbsinit;
-    mbsnrtowcs;
+    mbsnrtowcs; # introduced=21
     mbsrtowcs;
     mbstowcs;
-    mbtowc;
+    mbtowc; # introduced=21
     memalign;
     memccpy;
     memchr;
@@ -647,114 +646,114 @@
     memcpy;
     memmem;
     memmove;
-    mempcpy;
+    mempcpy; # introduced=23
     memrchr;
     memset;
     mincore;
     mkdir;
     mkdirat;
     mkdtemp;
-    mkfifo;
-    mkfifoat;
+    mkfifo; # introduced=21
+    mkfifoat; # introduced=23
     mknod;
-    mknodat;
-    mkostemp;
-    mkostemp64;
-    mkostemps;
-    mkostemps64;
+    mknodat; # introduced=21
+    mkostemp; # introduced=23
+    mkostemp64; # introduced=23
+    mkostemps; # introduced=23
+    mkostemps64; # introduced=23
     mkstemp;
-    mkstemp64;
+    mkstemp64; # introduced=21
     mkstemps;
-    mkstemps64;
+    mkstemps64; # introduced=23
     mktemp;
     mktime;
     mktime64; # arm x86 mips
     mlock;
-    mlockall;
+    mlockall; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     mmap;
-    mmap64;
+    mmap64; # introduced=21
     mount;
     mprotect;
     mrand48;
     mremap;
     msync;
     munlock;
-    munlockall;
+    munlockall; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     munmap;
     nanosleep;
-    newlocale;
-    nftw;
-    nftw64;
+    newlocale; # introduced=21
+    nftw; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    nftw64; # introduced=21
     nice;
     nrand48;
-    ns_format_ttl; # arm64 x86_64 mips64
-    ns_get16; # arm64 x86_64 mips64
-    ns_get32; # arm64 x86_64 mips64
-    ns_initparse; # arm64 x86_64 mips64
-    ns_makecanon; # arm64 x86_64 mips64
-    ns_msg_getflag; # arm64 x86_64 mips64
-    ns_name_compress; # arm64 x86_64 mips64
-    ns_name_ntol; # arm64 x86_64 mips64
-    ns_name_ntop; # arm64 x86_64 mips64
-    ns_name_pack; # arm64 x86_64 mips64
-    ns_name_pton; # arm64 x86_64 mips64
-    ns_name_rollback; # arm64 x86_64 mips64
-    ns_name_skip; # arm64 x86_64 mips64
-    ns_name_uncompress; # arm64 x86_64 mips64
-    ns_name_unpack; # arm64 x86_64 mips64
-    ns_parserr; # arm64 x86_64 mips64
-    ns_put16; # arm64 x86_64 mips64
-    ns_put32; # arm64 x86_64 mips64
-    ns_samename; # arm64 x86_64 mips64
-    ns_skiprr; # arm64 x86_64 mips64
-    ns_sprintrr; # arm64 x86_64 mips64
-    ns_sprintrrf; # arm64 x86_64 mips64
+    ns_format_ttl; # arm64 x86_64 mips64 introduced=22
+    ns_get16; # arm64 x86_64 mips64 introduced=22
+    ns_get32; # arm64 x86_64 mips64 introduced=22
+    ns_initparse; # arm64 x86_64 mips64 introduced=22
+    ns_makecanon; # arm64 x86_64 mips64 introduced=22
+    ns_msg_getflag; # arm64 x86_64 mips64 introduced=22
+    ns_name_compress; # arm64 x86_64 mips64 introduced=22
+    ns_name_ntol; # arm64 x86_64 mips64 introduced=22
+    ns_name_ntop; # arm64 x86_64 mips64 introduced=22
+    ns_name_pack; # arm64 x86_64 mips64 introduced=22
+    ns_name_pton; # arm64 x86_64 mips64 introduced=23
+    ns_name_rollback; # arm64 x86_64 mips64 introduced=22
+    ns_name_skip; # arm64 x86_64 mips64 introduced=22
+    ns_name_uncompress; # arm64 x86_64 mips64 introduced=22
+    ns_name_unpack; # arm64 x86_64 mips64 introduced=22
+    ns_parserr; # arm64 x86_64 mips64 introduced=22
+    ns_put16; # arm64 x86_64 mips64 introduced=22
+    ns_put32; # arm64 x86_64 mips64 introduced=22
+    ns_samename; # arm64 x86_64 mips64 introduced=22
+    ns_skiprr; # arm64 x86_64 mips64 introduced=22
+    ns_sprintrr; # arm64 x86_64 mips64 introduced=22
+    ns_sprintrrf; # arm64 x86_64 mips64 introduced=22
     nsdispatch;
-    ntohl;
-    ntohs;
+    ntohl; # introduced=21
+    ntohs; # introduced=21
     open;
-    open64;
-    open_memstream;
-    open_wmemstream;
+    open64; # introduced=21
+    open_memstream; # introduced=23
+    open_wmemstream; # introduced=23
     openat;
-    openat64;
+    openat64; # introduced=21
     opendir;
     openlog;
-    openpty;
-    optarg;
-    opterr;
-    optind;
-    optopt;
-    optreset;
+    openpty; # introduced=23
+    optarg; # var
+    opterr; # var
+    optind; # var
+    optopt; # var
+    optreset; # var
     pathconf;
     pause;
     pclose;
     perror;
-    personality;
+    personality; # introduced-arm=15 introduced-arm64=21 introduced-mips=15 introduced-mips64=21 introduced-x86=15 introduced-x86_64=21
     pipe;
     pipe2;
     poll;
     popen;
-    posix_fadvise;
-    posix_fadvise64;
-    posix_fallocate;
-    posix_fallocate64;
-    posix_madvise;
-    posix_memalign;
-    posix_openpt;
-    ppoll;
+    posix_fadvise; # introduced=21
+    posix_fadvise64; # introduced=21
+    posix_fallocate; # introduced=21
+    posix_fallocate64; # introduced=21
+    posix_madvise; # introduced=23
+    posix_memalign; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    posix_openpt; # introduced=21
+    ppoll; # introduced=21
     prctl;
     pread;
-    pread64;
+    pread64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     printf;
     prlimit; # arm64 x86_64 mips64
-    prlimit64;
-    process_vm_readv;
-    process_vm_writev;
+    prlimit64; # introduced=21
+    process_vm_readv; # introduced=23
+    process_vm_writev; # introduced=23
     pselect;
-    psiginfo;
-    psignal;
-    pthread_atfork;
+    psiginfo; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    psignal; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    pthread_atfork; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     pthread_attr_destroy;
     pthread_attr_getdetachstate;
     pthread_attr_getguardsize;
@@ -782,10 +781,10 @@
     pthread_cond_timeout_np; # arm x86 mips
     pthread_cond_wait;
     pthread_condattr_destroy;
-    pthread_condattr_getclock;
+    pthread_condattr_getclock; # introduced=21
     pthread_condattr_getpshared;
     pthread_condattr_init;
-    pthread_condattr_setclock;
+    pthread_condattr_setclock; # introduced=21
     pthread_condattr_setpshared;
     pthread_create;
     pthread_detach;
@@ -795,7 +794,7 @@
     pthread_getcpuclockid;
     pthread_getschedparam;
     pthread_getspecific;
-    pthread_gettid_np;
+    pthread_gettid_np; # introduced=21
     pthread_join;
     pthread_key_create;
     pthread_key_delete;
@@ -804,7 +803,7 @@
     pthread_mutex_init;
     pthread_mutex_lock;
     pthread_mutex_lock_timeout_np; # arm x86 mips
-    pthread_mutex_timedlock;
+    pthread_mutex_timedlock; # introduced=21
     pthread_mutex_trylock;
     pthread_mutex_unlock;
     pthread_mutexattr_destroy;
@@ -824,10 +823,10 @@
     pthread_rwlock_unlock;
     pthread_rwlock_wrlock;
     pthread_rwlockattr_destroy;
-    pthread_rwlockattr_getkind_np;
+    pthread_rwlockattr_getkind_np; # introduced=23
     pthread_rwlockattr_getpshared;
     pthread_rwlockattr_init;
-    pthread_rwlockattr_setkind_np;
+    pthread_rwlockattr_setkind_np; # introduced=23
     pthread_rwlockattr_setpshared;
     pthread_self;
     pthread_setname_np;
@@ -847,38 +846,38 @@
     putw; # arm x86 mips
     putwc;
     putwchar;
-    pvalloc; # arm x86 mips
+    pvalloc; # arm x86 mips introduced=17
     pwrite;
-    pwrite64;
+    pwrite64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     qsort;
-    quick_exit;
+    quick_exit; # introduced=21
     raise;
-    rand;
-    rand_r;
-    random;
+    rand; # introduced=21
+    rand_r; # introduced=21
+    random; # introduced=21
     read;
-    readahead;
+    readahead; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     readdir;
-    readdir64;
-    readdir64_r;
+    readdir64; # introduced=21
+    readdir64_r; # introduced=21
     readdir_r;
     readlink;
-    readlinkat;
+    readlinkat; # introduced=21
     readv;
     realloc;
     realpath;
     reboot;
     recv;
     recvfrom;
-    recvmmsg;
+    recvmmsg; # introduced=21
     recvmsg;
     regcomp;
     regerror;
     regexec;
     regfree;
     remove;
-    removexattr;
-    remque;
+    removexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    remque; # introduced=21
     rename;
     renameat;
     res_init;
@@ -890,21 +889,21 @@
     rmdir;
     sbrk;
     scandir;
-    scandir64;
+    scandir64; # introduced=21
     scanf;
     sched_get_priority_max;
     sched_get_priority_min;
-    sched_getaffinity;
-    sched_getcpu;
+    sched_getaffinity; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    sched_getcpu; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sched_getparam;
     sched_getscheduler;
     sched_rr_get_interval;
-    sched_setaffinity;
+    sched_setaffinity; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sched_setparam;
     sched_setscheduler;
     sched_yield;
     seed48;
-    seekdir;
+    seekdir; # introduced=23
     select;
     sem_close;
     sem_destroy;
@@ -918,8 +917,8 @@
     sem_wait;
     send;
     sendfile;
-    sendfile64;
-    sendmmsg;
+    sendfile64; # introduced=21
+    sendmmsg; # introduced=21
     sendmsg;
     sendto;
     setbuf;
@@ -927,101 +926,101 @@
     setegid;
     setenv;
     seteuid;
-    setfsgid;
-    setfsuid;
+    setfsgid; # introduced=21
+    setfsuid; # introduced=21
     setgid;
     setgroups;
-    sethostname;
+    sethostname; # introduced=23
     setitimer;
     setjmp;
     setlinebuf;
     setlocale;
     setlogmask;
-    setmntent;
-    setns;
+    setmntent; # introduced=21
+    setns; # introduced=21
     setpgid;
     setpgrp;
     setpriority;
-    setprogname;
+    setprogname; # introduced=21
     setregid;
     setresgid;
     setresuid;
     setreuid;
     setrlimit;
-    setrlimit64;
+    setrlimit64; # introduced=21
     setservent;
     setsid;
     setsockopt;
-    setstate;
+    setstate; # introduced=21
     settimeofday;
     setuid;
     setutent;
     setvbuf;
-    setxattr;
+    setxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     shutdown;
     sigaction;
-    sigaddset;
+    sigaddset; # introduced=21
     sigaltstack;
     sigblock;
-    sigdelset;
-    sigemptyset;
-    sigfillset;
+    sigdelset; # introduced=21
+    sigemptyset; # introduced=21
+    sigfillset; # introduced=21
     siginterrupt;
-    sigismember;
-    siglongjmp;
-    signal;
-    signalfd;
+    sigismember; # introduced=21
+    siglongjmp; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    signal; # introduced=21
+    signalfd; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     sigpending;
     sigprocmask;
-    sigqueue;
-    sigsetjmp;
+    sigqueue; # introduced=23
+    sigsetjmp; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sigsetmask;
     sigsuspend;
-    sigtimedwait;
+    sigtimedwait; # introduced=23
     sigwait;
-    sigwaitinfo;
+    sigwaitinfo; # introduced=23
     sleep;
     snprintf;
     socket;
     socketpair;
-    splice;
+    splice; # introduced=21
     sprintf;
-    srand;
+    srand; # introduced=21
     srand48;
-    srandom;
+    srandom; # introduced=21
     sscanf;
     stat;
-    stat64;
+    stat64; # introduced=21
     statfs;
-    statfs64;
-    statvfs;
-    statvfs64;
-    stderr;
-    stdin;
-    stdout;
-    stpcpy;
-    stpncpy;
+    statfs64; # introduced=21
+    statvfs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    statvfs64; # introduced=21
+    stderr; # var introduced=23
+    stdin; # var introduced=23
+    stdout; # var introduced=23
+    stpcpy; # introduced=21
+    stpncpy; # introduced=21
     strcasecmp;
-    strcasecmp_l;
+    strcasecmp_l; # introduced=23
     strcasestr;
     strcat;
     strchr;
     strcmp;
     strcoll;
-    strcoll_l;
+    strcoll_l; # introduced=21
     strcpy;
     strcspn;
     strdup;
     strerror;
-    strerror_l;
+    strerror_l; # introduced=23
     strerror_r;
     strftime;
-    strftime_l;
+    strftime_l; # introduced=21
     strlcat;
     strlcpy;
     strlen;
     strncasecmp;
-    strncasecmp_l;
+    strncasecmp_l; # introduced=23
     strncat;
     strncmp;
     strncpy;
@@ -1035,86 +1034,86 @@
     strspn;
     strstr;
     strtod;
-    strtof;
+    strtof; # introduced=21
     strtoimax;
     strtok;
     strtok_r;
     strtol;
-    strtold;
-    strtold_l;
+    strtold; # introduced=21
+    strtold_l; # introduced=21
     strtoll;
-    strtoll_l;
-    strtoq;
+    strtoll_l; # introduced=21
+    strtoq; # introduced=21
     strtoul;
     strtoull;
-    strtoull_l;
+    strtoull_l; # introduced=21
     strtoumax;
-    strtouq;
+    strtouq; # introduced=21
     strxfrm;
-    strxfrm_l;
-    swapoff;
-    swapon;
+    strxfrm_l; # introduced=21
+    swapoff; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    swapon; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     swprintf;
     swscanf;
     symlink;
-    symlinkat;
+    symlinkat; # introduced=21
     sync;
-    sys_siglist;
-    sys_signame;
+    sys_siglist; # var
+    sys_signame; # var
     syscall;
     sysconf;
     sysinfo;
     syslog;
     system;
-    tcdrain;
-    tcflow;
-    tcflush;
-    tcgetattr;
+    tcdrain; # introduced=21
+    tcflow; # introduced=21
+    tcflush; # introduced=21
+    tcgetattr; # introduced=21
     tcgetpgrp;
-    tcgetsid;
-    tcsendbreak;
-    tcsetattr;
+    tcgetsid; # introduced=21
+    tcsendbreak; # introduced=21
+    tcsetattr; # introduced=21
     tcsetpgrp;
-    tdelete;
-    tdestroy;
-    tee;
-    telldir;
+    tdelete; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tdestroy; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tee; # introduced=21
+    telldir; # introduced=23
     tempnam;
-    tfind;
-    tgkill;
+    tfind; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tgkill; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     time;
-    timegm;
+    timegm; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     timegm64; # arm x86 mips
-    timelocal;
+    timelocal; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     timelocal64; # arm x86 mips
     timer_create;
     timer_delete;
     timer_getoverrun;
     timer_gettime;
     timer_settime;
-    timerfd_create;
-    timerfd_gettime;
-    timerfd_settime;
+    timerfd_create; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    timerfd_gettime; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    timerfd_settime; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     times;
-    timezone;
+    timezone; # var
     tmpfile;
     tmpnam;
     toascii;
     tolower;
-    tolower_l;
+    tolower_l; # introduced=21
     toupper;
-    toupper_l;
+    toupper_l; # introduced=21
     towlower;
-    towlower_l;
+    towlower_l; # introduced=21
     towupper;
-    towupper_l;
+    towupper_l; # introduced=21
     truncate;
-    truncate64;
-    tsearch;
+    truncate64; # introduced=21
+    tsearch; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     ttyname;
     ttyname_r;
-    twalk;
-    tzname;
+    twalk; # introduced=21
+    tzname; # var
     tzset;
     umask;
     umount;
@@ -1126,38 +1125,38 @@
     unlinkat;
     unlockpt;
     unsetenv;
-    unshare;
-    uselocale;
+    unshare; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    uselocale; # introduced=21
     usleep;
     utime;
-    utimensat;
+    utimensat; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     utimes;
     utmpname;
     valloc; # arm x86 mips
     vasprintf;
-    vdprintf;
+    vdprintf; # introduced=21
     verr;
     verrx;
     vfork;
     vfprintf;
     vfscanf;
     vfwprintf;
-    vfwscanf;
-    vmsplice;
+    vfwscanf; # introduced=21
+    vmsplice; # introduced=21
     vprintf;
     vscanf;
     vsnprintf;
     vsprintf;
     vsscanf;
     vswprintf;
-    vswscanf;
+    vswscanf; # introduced=21
     vsyslog;
     vwarn;
     vwarnx;
     vwprintf;
-    vwscanf;
+    vwscanf; # introduced=21
     wait;
-    wait4;
+    wait4; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     waitid;
     waitpid;
     warn;
@@ -1166,12 +1165,12 @@
     wcpncpy;
     wcrtomb;
     wcscasecmp;
-    wcscasecmp_l;
+    wcscasecmp_l; # introduced=23
     wcscat;
     wcschr;
     wcscmp;
     wcscoll;
-    wcscoll_l;
+    wcscoll_l; # introduced=21
     wcscpy;
     wcscspn;
     wcsdup;
@@ -1180,44 +1179,44 @@
     wcslcpy;
     wcslen;
     wcsncasecmp;
-    wcsncasecmp_l;
+    wcsncasecmp_l; # introduced=23
     wcsncat;
     wcsncmp;
     wcsncpy;
     wcsnlen;
-    wcsnrtombs;
+    wcsnrtombs; # introduced=21
     wcspbrk;
     wcsrchr;
     wcsrtombs;
     wcsspn;
     wcsstr;
     wcstod;
-    wcstof;
-    wcstoimax;
+    wcstof; # introduced=21
+    wcstoimax; # introduced=21
     wcstok;
     wcstol;
-    wcstold;
-    wcstold_l;
-    wcstoll;
-    wcstoll_l;
+    wcstold; # introduced=21
+    wcstold_l; # introduced=21
+    wcstoll; # introduced=21
+    wcstoll_l; # introduced=21
     wcstombs;
     wcstoul;
-    wcstoull;
-    wcstoull_l;
-    wcstoumax;
+    wcstoull; # introduced=21
+    wcstoull_l; # introduced=21
+    wcstoumax; # introduced=21
     wcswidth;
     wcsxfrm;
-    wcsxfrm_l;
+    wcsxfrm_l; # introduced=21
     wctob;
-    wctomb;
+    wctomb; # introduced=21
     wctype;
-    wctype_l;
+    wctype_l; # introduced=21
     wcwidth;
     wmemchr;
     wmemcmp;
     wmemcpy;
     wmemmove;
-    wmempcpy;
+    wmempcpy; # introduced=23
     wmemset;
     wprintf;
     write;
@@ -1227,71 +1226,106 @@
     *;
 };
 
-LIBC_N {
+LIBC_N { # introduced-arm64=24 introduced-mips=24 introduced-mips64=24 introduced-x86=24 introduced-x86_64=24
   global:
-    __aeabi_atexit; # arm
-    __aeabi_memclr; # arm
-    __aeabi_memclr4; # arm
-    __aeabi_memclr8; # arm
-    __aeabi_memcpy; # arm
-    __aeabi_memcpy4; # arm
-    __aeabi_memcpy8; # arm
-    __aeabi_memmove; # arm
-    __aeabi_memmove4; # arm
-    __aeabi_memmove8; # arm
-    __aeabi_memset; # arm
-    __aeabi_memset4; # arm
-    __aeabi_memset8; # arm
-    __fread_chk;
-    __fwrite_chk;
-    __getcwd_chk;
-    __gnu_Unwind_Find_exidx; # arm
-    __pwrite_chk;
-    __pwrite64_chk;
-    __write_chk;
-    adjtimex;
-    clock_adjtime;
-    fgetpos64;
-    fileno_unlocked;
-    fopen64;
-    freeifaddrs;
-    freopen64;
-    fseeko64;
-    fsetpos64;
-    ftello64;
-    funopen64;
-    getgrgid_r;
-    getgrnam_r;
-    getifaddrs;
-    if_freenameindex;
-    if_nameindex;
-    in6addr_any;
-    in6addr_loopback;
-    lockf;
-    lockf64;
-    preadv;
-    preadv64;
-    prlimit; # arm mips x86
-    pthread_barrierattr_destroy;
-    pthread_barrierattr_getpshared;
-    pthread_barrierattr_init;
-    pthread_barrierattr_setpshared;
-    pthread_barrier_destroy;
-    pthread_barrier_init;
-    pthread_barrier_wait;
-    pthread_spin_destroy;
-    pthread_spin_init;
-    pthread_spin_lock;
-    pthread_spin_trylock;
-    pthread_spin_unlock;
-    pwritev;
-    pwritev64;
-    scandirat;
-    scandirat64;
-    strchrnul;
-    tmpfile64;
+    __aeabi_atexit; # arm versioned=24
+    __aeabi_memclr; # arm versioned=24
+    __aeabi_memclr4; # arm versioned=24
+    __aeabi_memclr8; # arm versioned=24
+    __aeabi_memcpy; # arm versioned=24
+    __aeabi_memcpy4; # arm versioned=24
+    __aeabi_memcpy8; # arm versioned=24
+    __aeabi_memmove; # arm versioned=24
+    __aeabi_memmove4; # arm versioned=24
+    __aeabi_memmove8; # arm versioned=24
+    __aeabi_memset; # arm versioned=24
+    __aeabi_memset4; # arm versioned=24
+    __aeabi_memset8; # arm versioned=24
+    __fread_chk; # introduced=24
+    __fwrite_chk; # introduced=24
+    __getcwd_chk; # introduced=24
+    __gnu_Unwind_Find_exidx; # arm versioned=24
+    __pwrite_chk; # introduced=24
+    __pwrite64_chk; # introduced=24
+    __write_chk; # introduced=24
+    adjtimex; # introduced=24
+    clock_adjtime; # introduced=24
+    fgetpos64; # introduced=24
+    fileno_unlocked; # introduced=24
+    fopen64; # introduced=24
+    freeifaddrs; # introduced=24
+    freopen64; # introduced=24
+    fseeko64; # introduced=24
+    fsetpos64; # introduced=24
+    ftello64; # introduced=24
+    funopen64; # introduced=24
+    getgrgid_r; # introduced=24
+    getgrnam_r; # introduced=24
+    getifaddrs; # introduced=24
+    if_freenameindex; # introduced=24
+    if_nameindex; # introduced=24
+    in6addr_any; # var introduced=24
+    in6addr_loopback; # var introduced=24
+    lockf; # introduced=24
+    lockf64; # introduced=24
+    preadv; # introduced=24
+    preadv64; # introduced=24
+    prlimit; # arm mips x86 introduced=24
+    pthread_barrierattr_destroy; # introduced=24
+    pthread_barrierattr_getpshared; # introduced=24
+    pthread_barrierattr_init; # introduced=24
+    pthread_barrierattr_setpshared; # introduced=24
+    pthread_barrier_destroy; # introduced=24
+    pthread_barrier_init; # introduced=24
+    pthread_barrier_wait; # introduced=24
+    pthread_spin_destroy; # introduced=24
+    pthread_spin_init; # introduced=24
+    pthread_spin_lock; # introduced=24
+    pthread_spin_trylock; # introduced=24
+    pthread_spin_unlock; # introduced=24
+    pwritev; # introduced=24
+    pwritev64; # introduced=24
+    scandirat; # introduced=24
+    scandirat64; # introduced=24
+    strchrnul; # introduced=24
+    tmpfile64; # introduced=24
 } LIBC;
 
+LIBC_O {
+  global:
+    bsd_signal; # arm x86 mips nobrillo versioned=26
+    catclose; # future
+    catgets; # future
+    catopen; # future
+    ctermid; # future
+    endgrent; # future
+    endpwent; # future
+    futimes; # future
+    futimesat; # future
+    getdomainname; # future
+    getgrent; # future
+    getpwent; # future
+    getsubopt; # future
+    hasmntopt; # future
+    lutimes; # future
+    mblen; # future
+    pthread_getname_np; # future
+    quotactl; # future
+    setdomainname; # future
+    setgrent; # future
+    setpwent; # future
+    sighold; # future
+    sigignore; # future
+    sigpause; # future
+    sigrelse; # future
+    sigset; # future
+    sync_file_range; # future
+    towctrans; # future
+    towctrans_l; # future
+    wctrans; # future
+    wctrans_l; # future
+} LIBC_N;
+
 LIBC_PRIVATE {
   global:
     ___Unwind_Backtrace; # arm
@@ -1478,12 +1512,10 @@
     atexit; # arm
     bcopy; # arm x86 mips nobrillo
     bzero; # arm x86 mips nobrillo
-    bsd_signal; # arm x86 mips nobrillo
     dlmalloc; # arm x86 mips nobrillo
     dlmalloc_inspect_all; # arm x86 mips nobrillo
     dlmalloc_trim; # arm x86 mips nobrillo
     dlmalloc_usable_size; # arm x86 mips nobrillo
-    endpwent; # arm x86 mips nobrillo
     fdprintf; # arm x86 mips nobrillo
     free_malloc_leak_info;
     ftime; # arm x86 mips nobrillo
@@ -1509,7 +1541,7 @@
     vfdprintf; # arm x86 mips nobrillo
     wait3; # arm x86 mips nobrillo
     wcswcs; # arm x86 mips nobrillo
-} LIBC_N;
+} LIBC_O;
 
 LIBC_PLATFORM {
   global:
@@ -1520,4 +1552,4 @@
     malloc_disable;
     malloc_enable;
     malloc_iterate;
-} LIBC_N;
+} LIBC_O;
diff --git a/libc/libc.mips.brillo.map b/libc/libc.mips.brillo.map
index d11a5ab..3911b20 100644
--- a/libc/libc.mips.brillo.map
+++ b/libc/libc.mips.brillo.map
@@ -1,50 +1,49 @@
-# Generated by genversionscripts.py. Do not edit.
+# Generated by genversion-scripts.py. Do not edit.
 LIBC {
   global:
     __assert;
     __assert2;
     __b64_ntop;
     __b64_pton;
-    __brk; # arm x86 mips
-    __cmsg_nxthdr;
-    __connect; # arm x86 mips
-    __ctype_get_mb_cur_max;
+    __cmsg_nxthdr; # introduced=21
+    __connect; # arm x86 mips introduced=21
+    __ctype_get_mb_cur_max; # introduced=21
     __cxa_atexit;
     __cxa_finalize;
-    __cxa_thread_atexit_impl;
+    __cxa_thread_atexit_impl; # introduced=23
     __dn_comp;
     __dn_count_labels;
     __dn_skipname;
-    __epoll_pwait; # arm x86 mips
+    __epoll_pwait; # arm x86 mips introduced=21
     __errno;
-    __exit; # arm x86 mips
-    __fadvise64; # x86 mips
-    __fbufsize;
+    __exit; # arm x86 mips introduced=21
+    __fadvise64; # x86 mips introduced=21
+    __fbufsize; # introduced=23
     __fcntl64; # arm x86 mips
-    __FD_CLR_chk;
-    __FD_ISSET_chk;
-    __FD_SET_chk;
-    __fgets_chk;
-    __flbf;
+    __FD_CLR_chk; # introduced=21
+    __FD_ISSET_chk; # introduced=21
+    __FD_SET_chk; # introduced=21
+    __fgets_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __flbf; # introduced=23
     __fp_nquery;
     __fp_query;
-    __fpclassify;
+    __fpclassify; # introduced=21
     __fpclassifyd;
     __fpclassifyf;
     __fpclassifyl;
-    __fpending;
-    __fpurge;
-    __freadable;
-    __fsetlocking;
+    __fpending; # introduced=23
+    __fpurge; # introduced=23
+    __freadable; # introduced=23
+    __fsetlocking; # introduced=23
     __fstatfs64; # arm x86 mips
-    __fwritable;
+    __fwritable; # introduced=23
     __get_h_errno;
-    __getcpu; # arm x86 mips
+    __getcpu; # arm x86 mips introduced-arm=12 introduced-mips=16 introduced-x86=12
     __getcwd; # arm x86 mips
-    __getpid; # arm x86 mips
+    __getpid; # arm x86 mips introduced=21
     __getpriority; # arm x86 mips
-    __gnu_basename;
-    __gnu_strerror_r;
+    __gnu_basename; # introduced=23
+    __gnu_strerror_r; # introduced=23
     __hostalias;
     __ioctl; # arm x86 mips
     __isfinite;
@@ -53,24 +52,24 @@
     __isinf;
     __isinff;
     __isinfl;
-    __isnan;
-    __isnanf;
+    __isnan; # introduced=21
+    __isnanf; # introduced=21
     __isnanl;
     __isnormal;
     __isnormalf;
     __isnormall;
-    __isthreaded; # arm x86 mips
-    __libc_current_sigrtmax;
-    __libc_current_sigrtmin;
+    __isthreaded; # arm x86 mips var
+    __libc_current_sigrtmax; # introduced=21
+    __libc_current_sigrtmin; # introduced=21
     __libc_init;
     __llseek; # arm x86 mips
     __loc_aton;
     __loc_ntoa;
-    __memchr_chk;
-    __memcpy_chk;
-    __memmove_chk;
-    __memrchr_chk;
-    __memset_chk;
+    __memchr_chk; # introduced=23
+    __memcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __memmove_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __memrchr_chk; # introduced=23
+    __memset_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __mmap2; # arm x86 mips
     __ns_format_ttl; # arm x86 mips
     __ns_get16; # arm x86 mips
@@ -94,13 +93,13 @@
     __ns_skiprr; # arm x86 mips
     __ns_sprintrr; # arm x86 mips
     __ns_sprintrrf; # arm x86 mips
-    __open_2;
+    __open_2; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __openat; # arm x86 mips
-    __openat_2;
+    __openat_2; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __p_cdname;
     __p_cdnname;
     __p_class;
-    __p_class_syms;
+    __p_class_syms; # var
     __p_fqname;
     __p_fqnname;
     __p_option;
@@ -109,25 +108,25 @@
     __p_secstodate;
     __p_time;
     __p_type;
-    __p_type_syms;
-    __poll_chk;
-    __ppoll; # arm x86 mips
-    __ppoll_chk;
-    __pread64_chk;
-    __pread_chk;
-    __progname;
-    __pselect6; # arm x86 mips
+    __p_type_syms; # var
+    __poll_chk; # introduced=23
+    __ppoll; # arm x86 mips introduced=21
+    __ppoll_chk; # introduced=23
+    __pread64_chk; # introduced=23
+    __pread_chk; # introduced=23
+    __progname; # var
+    __pselect6; # arm x86 mips introduced=21
     __pthread_cleanup_pop;
     __pthread_cleanup_push;
     __ptrace; # arm x86 mips
     __putlong;
     __putshort;
-    __read_chk;
-    __readlink_chk;
-    __readlinkat_chk;
+    __read_chk; # introduced=21
+    __readlink_chk; # introduced=23
+    __readlinkat_chk; # introduced=23
     __reboot; # arm x86 mips
-    __recvfrom_chk;
-    __register_atfork;
+    __recvfrom_chk; # introduced=21
+    __register_atfork; # introduced=23
     __res_close;
     __res_dnok;
     __res_hnok;
@@ -149,90 +148,90 @@
     __res_send_setqhook;
     __res_send_setrhook;
     __rt_sigaction; # arm x86 mips
-    __rt_sigpending; # arm x86 mips
+    __rt_sigpending; # arm x86 mips introduced=21
     __rt_sigprocmask; # arm x86 mips
-    __rt_sigsuspend; # arm x86 mips
+    __rt_sigsuspend; # arm x86 mips introduced=21
     __rt_sigtimedwait; # arm x86 mips
-    __sched_cpualloc;
-    __sched_cpucount;
-    __sched_cpufree;
-    __sched_getaffinity; # arm x86 mips
-    __set_tid_address; # arm x86 mips
+    __sched_cpualloc; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_cpucount; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_cpufree; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_getaffinity; # arm x86 mips introduced=12
+    __set_tid_address; # arm x86 mips introduced=21
     __set_tls; # arm mips
-    __sF;
-    __sigaction; # arm x86 mips
-    __snprintf_chk;
-    __socket; # arm x86 mips
-    __sprintf_chk;
+    __sF; # var
+    __sigaction; # arm x86 mips introduced=21
+    __snprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __socket; # arm x86 mips introduced=21
+    __sprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __stack_chk_fail;
-    __stack_chk_guard;
+    __stack_chk_guard; # var
     __statfs64; # arm x86 mips
-    __stpcpy_chk;
-    __stpncpy_chk;
-    __stpncpy_chk2;
-    __strcat_chk;
-    __strchr_chk;
-    __strcpy_chk;
-    __strlcat_chk;
-    __strlcpy_chk;
-    __strlen_chk;
-    __strncat_chk;
-    __strncpy_chk;
-    __strncpy_chk2;
-    __strrchr_chk;
+    __stpcpy_chk; # introduced=21
+    __stpncpy_chk; # introduced=21
+    __stpncpy_chk2; # introduced=21
+    __strcat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strchr_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
+    __strcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlcat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlen_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncpy_chk2; # introduced=21
+    __strrchr_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     __sym_ntop;
     __sym_ntos;
     __sym_ston;
     __system_properties_init;
-    __system_property_add;
-    __system_property_area__;
-    __system_property_area_init;
-    __system_property_area_serial;
+    __system_property_add; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_area__; # var
+    __system_property_area_init; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_area_serial; # introduced=23
     __system_property_find;
     __system_property_find_nth;
-    __system_property_foreach;
+    __system_property_foreach; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     __system_property_get;
     __system_property_read;
-    __system_property_serial;
-    __system_property_set;
-    __system_property_set_filename;
-    __system_property_update;
-    __system_property_wait_any;
+    __system_property_serial; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_set; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __system_property_set_filename; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_update; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_wait_any; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     __timer_create; # arm x86 mips
     __timer_delete; # arm x86 mips
     __timer_getoverrun; # arm x86 mips
     __timer_gettime; # arm x86 mips
     __timer_settime; # arm x86 mips
-    __umask_chk;
-    __vsnprintf_chk;
-    __vsprintf_chk;
+    __umask_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
+    __vsnprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __vsprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __waitid; # arm x86 mips
-    _ctype_;
-    _Exit;
+    _ctype_; # var
+    _Exit; # introduced=21
     _exit;
     _flush_cache; # mips
-    _flushlbf;
+    _flushlbf; # introduced=23
     _getlong;
     _getshort;
     _longjmp;
-    _resolv_delete_cache_for_net;
-    _resolv_flush_cache_for_net;
-    _resolv_set_nameservers_for_net;
+    _resolv_delete_cache_for_net; # introduced=21
+    _resolv_flush_cache_for_net; # introduced=21
+    _resolv_set_nameservers_for_net; # introduced=21
     _setjmp;
-    _tolower;
-    _tolower_tab_; # arm x86 mips
-    _toupper;
-    _toupper_tab_; # arm x86 mips
+    _tolower; # introduced=21
+    _tolower_tab_; # arm x86 mips var
+    _toupper; # introduced=21
+    _toupper_tab_; # arm x86 mips var
     abort;
-    abs;
+    abs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     accept;
-    accept4;
+    accept4; # introduced=21
     access;
     acct;
     alarm;
     alphasort;
-    alphasort64;
-    android_set_abort_message;
+    alphasort64; # introduced=21
+    android_set_abort_message; # introduced=21
     arc4random;
     arc4random_buf;
     arc4random_uniform;
@@ -241,8 +240,8 @@
     asctime64_r; # arm x86 mips
     asctime_r;
     asprintf;
-    at_quick_exit;
-    atof;
+    at_quick_exit; # introduced=21
+    atof; # introduced=21
     atoi;
     atol;
     atoll;
@@ -253,44 +252,44 @@
     brk;
     bsearch;
     btowc;
-    c16rtomb;
-    c32rtomb;
+    c16rtomb; # introduced=21
+    c32rtomb; # introduced=21
     cacheflush; # arm mips
     calloc;
     capget;
     capset;
-    cfgetispeed;
-    cfgetospeed;
-    cfmakeraw;
-    cfsetispeed;
-    cfsetospeed;
-    cfsetspeed;
+    cfgetispeed; # introduced=21
+    cfgetospeed; # introduced=21
+    cfmakeraw; # introduced=21
+    cfsetispeed; # introduced=21
+    cfsetospeed; # introduced=21
+    cfsetspeed; # introduced=21
     chdir;
     chmod;
     chown;
     chroot;
     clearenv;
     clearerr;
-    clearerr_unlocked;
+    clearerr_unlocked; # introduced=23
     clock;
-    clock_getcpuclockid;
+    clock_getcpuclockid; # introduced=23
     clock_getres;
     clock_gettime;
     clock_nanosleep;
     clock_settime;
-    clone;
+    clone; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     close;
     closedir;
     closelog;
     connect;
     creat;
-    creat64;
+    creat64; # introduced=21
     ctime;
     ctime64; # arm x86 mips
     ctime64_r; # arm x86 mips
     ctime_r;
     daemon;
-    daylight;
+    daylight; # var
     delete_module;
     difftime;
     dirfd;
@@ -298,33 +297,33 @@
     dirname_r; # arm x86 mips
     div;
     dn_expand;
-    dprintf;
+    dprintf; # introduced=21
     drand48;
     dup;
     dup2;
-    dup3;
-    duplocale;
-    endmntent;
+    dup3; # introduced=21
+    duplocale; # introduced=21
+    endmntent; # introduced=21
     endservent;
     endutent;
-    environ;
+    environ; # var
     epoll_create;
-    epoll_create1;
+    epoll_create1; # introduced=21
     epoll_ctl;
-    epoll_pwait;
+    epoll_pwait; # introduced=21
     epoll_wait;
     erand48;
     err;
-    error;
-    error_at_line;
-    error_message_count;
-    error_one_per_line;
-    error_print_progname;
+    error; # introduced=23
+    error_at_line; # introduced=23
+    error_message_count; # var introduced=23
+    error_one_per_line; # var introduced=23
+    error_print_progname; # var introduced=23
     errx;
-    ether_aton;
-    ether_aton_r;
-    ether_ntoa;
-    ether_ntoa_r;
+    ether_aton; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_aton_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_ntoa; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_ntoa_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     eventfd;
     eventfd_read;
     eventfd_write;
@@ -334,11 +333,11 @@
     execv;
     execve;
     execvp;
-    execvpe;
+    execvpe; # introduced=21
     exit;
-    faccessat;
-    fallocate;
-    fallocate64;
+    faccessat; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    fallocate; # introduced=21
+    fallocate64; # introduced=21
     fchdir;
     fchmod;
     fchmodat;
@@ -350,27 +349,27 @@
     fdopen;
     fdopendir;
     feof;
-    feof_unlocked;
+    feof_unlocked; # introduced=23
     ferror;
-    ferror_unlocked;
+    ferror_unlocked; # introduced=23
     fflush;
-    ffs;
+    ffs; # introduced-arm=9 introduced-arm64=21 introduced-mips=9 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     fgetc;
     fgetln;
     fgetpos;
     fgets;
     fgetwc;
     fgetws;
-    fgetxattr;
+    fgetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     fileno;
-    flistxattr;
+    flistxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     flock;
     flockfile;
-    fmemopen;
+    fmemopen; # introduced=23
     fnmatch;
     fopen;
     fork;
-    forkpty;
+    forkpty; # introduced=23
     fpathconf;
     fprintf;
     fpurge;
@@ -381,56 +380,56 @@
     fread;
     free;
     freeaddrinfo;
-    freelocale;
-    fremovexattr;
+    freelocale; # introduced=21
+    fremovexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     freopen;
     fscanf;
     fseek;
     fseeko;
     fsetpos;
-    fsetxattr;
+    fsetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     fstat;
-    fstat64;
+    fstat64; # introduced=21
     fstatat;
-    fstatat64;
+    fstatat64; # introduced=21
     fstatfs;
-    fstatfs64;
-    fstatvfs;
-    fstatvfs64;
+    fstatfs64; # introduced=21
+    fstatvfs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    fstatvfs64; # introduced=21
     fsync;
     ftell;
     ftello;
     ftok;
     ftruncate;
-    ftruncate64;
+    ftruncate64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     ftrylockfile;
     fts_children;
     fts_close;
     fts_open;
     fts_read;
     fts_set;
-    ftw;
-    ftw64;
+    ftw; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    ftw64; # introduced=21
     funlockfile;
     funopen;
-    futimens;
+    futimens; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     fwide;
     fwprintf;
     fwrite;
     fwscanf;
     gai_strerror;
-    get_avphys_pages;
-    get_nprocs;
-    get_nprocs_conf;
-    get_phys_pages;
+    get_avphys_pages; # introduced=23
+    get_nprocs; # introduced=23
+    get_nprocs_conf; # introduced=23
+    get_phys_pages; # introduced=23
     getaddrinfo;
-    getauxval;
+    getauxval; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getc;
     getc_unlocked;
     getchar;
     getchar_unlocked;
     getcwd;
-    getdelim;
+    getdelim; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getegid;
     getenv;
     geteuid;
@@ -440,49 +439,49 @@
     getgrouplist;
     getgroups;
     gethostbyaddr;
-    gethostbyaddr_r;
+    gethostbyaddr_r; # introduced=23
     gethostbyname;
     gethostbyname2;
-    gethostbyname2_r;
+    gethostbyname2_r; # introduced=23
     gethostbyname_r;
     gethostent;
     gethostname;
     getitimer;
-    getline;
+    getline; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getlogin;
     getmntent;
-    getmntent_r;
+    getmntent_r; # introduced=21
     getnameinfo;
     getnetbyaddr;
     getnetbyname;
     getopt;
     getopt_long;
     getopt_long_only;
-    getpagesize;
+    getpagesize; # introduced=21
     getpeername;
     getpgid;
     getpgrp;
     getpid;
     getppid;
     getpriority;
-    getprogname;
+    getprogname; # introduced=21
     getprotobyname;
     getprotobynumber;
     getpt;
     getpwnam;
-    getpwnam_r;
+    getpwnam_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     getpwuid;
-    getpwuid_r;
+    getpwuid_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     getresgid;
     getresuid;
     getrlimit;
-    getrlimit64;
+    getrlimit64; # introduced=21
     getrusage;
     gets;
     getservbyname;
     getservbyport;
     getservent;
-    getsid;
+    getsid; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     getsockname;
     getsockopt;
     gettid;
@@ -491,26 +490,26 @@
     getutent;
     getwc;
     getwchar;
-    getxattr;
+    getxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     gmtime;
     gmtime64; # arm x86 mips
     gmtime64_r; # arm x86 mips
     gmtime_r;
-    grantpt;
+    grantpt; # introduced=21
     herror;
     hstrerror;
-    htonl;
-    htons;
+    htonl; # introduced=21
+    htons; # introduced=21
     if_indextoname;
     if_nametoindex;
-    imaxabs;
-    imaxdiv;
+    imaxabs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    imaxdiv; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     inet_addr;
     inet_aton;
-    inet_lnaof;
-    inet_makeaddr;
-    inet_netof;
-    inet_network;
+    inet_lnaof; # introduced=21
+    inet_makeaddr; # introduced=21
+    inet_netof; # introduced=21
+    inet_network; # introduced=21
     inet_nsap_addr;
     inet_nsap_ntoa;
     inet_ntoa;
@@ -518,124 +517,124 @@
     inet_pton;
     init_module;
     initgroups;
-    initstate;
+    initstate; # introduced=21
     inotify_add_watch;
     inotify_init;
-    inotify_init1;
+    inotify_init1; # introduced=21
     inotify_rm_watch;
-    insque;
+    insque; # introduced=21
     ioctl;
     isalnum;
-    isalnum_l;
+    isalnum_l; # introduced=21
     isalpha;
-    isalpha_l;
+    isalpha_l; # introduced=21
     isascii;
     isatty;
     isblank;
-    isblank_l;
+    isblank_l; # introduced=21
     iscntrl;
-    iscntrl_l;
+    iscntrl_l; # introduced=21
     isdigit;
-    isdigit_l;
-    isfinite;
-    isfinitef;
-    isfinitel;
+    isdigit_l; # introduced=21
+    isfinite; # introduced=21
+    isfinitef; # introduced=21
+    isfinitel; # introduced=21
     isgraph;
-    isgraph_l;
-    isinf;
-    isinff;
-    isinfl;
+    isgraph_l; # introduced=21
+    isinf; # introduced=21
+    isinff; # introduced=21
+    isinfl; # introduced=21
     islower;
-    islower_l;
+    islower_l; # introduced=21
     isnan;
     isnanf;
-    isnanl;
-    isnormal;
-    isnormalf;
-    isnormall;
+    isnanl; # introduced=21
+    isnormal; # introduced=21
+    isnormalf; # introduced=21
+    isnormall; # introduced=21
     isprint;
-    isprint_l;
+    isprint_l; # introduced=21
     ispunct;
-    ispunct_l;
+    ispunct_l; # introduced=21
     isspace;
-    isspace_l;
+    isspace_l; # introduced=21
     isupper;
-    isupper_l;
+    isupper_l; # introduced=21
     iswalnum;
-    iswalnum_l;
+    iswalnum_l; # introduced=21
     iswalpha;
-    iswalpha_l;
-    iswblank;
-    iswblank_l;
+    iswalpha_l; # introduced=21
+    iswblank; # introduced=21
+    iswblank_l; # introduced=21
     iswcntrl;
-    iswcntrl_l;
+    iswcntrl_l; # introduced=21
     iswctype;
-    iswctype_l;
+    iswctype_l; # introduced=21
     iswdigit;
-    iswdigit_l;
+    iswdigit_l; # introduced=21
     iswgraph;
-    iswgraph_l;
+    iswgraph_l; # introduced=21
     iswlower;
-    iswlower_l;
+    iswlower_l; # introduced=21
     iswprint;
-    iswprint_l;
+    iswprint_l; # introduced=21
     iswpunct;
-    iswpunct_l;
+    iswpunct_l; # introduced=21
     iswspace;
-    iswspace_l;
+    iswspace_l; # introduced=21
     iswupper;
-    iswupper_l;
+    iswupper_l; # introduced=21
     iswxdigit;
-    iswxdigit_l;
+    iswxdigit_l; # introduced=21
     isxdigit;
-    isxdigit_l;
+    isxdigit_l; # introduced=21
     jrand48;
     kill;
     killpg;
     klogctl;
-    labs;
+    labs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     lchown;
-    lcong48;
+    lcong48; # introduced=23
     ldexp;
     ldiv;
-    lfind;
-    lgetxattr;
+    lfind; # introduced=21
+    lgetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     link;
-    linkat;
+    linkat; # introduced=21
     listen;
-    listxattr;
-    llabs;
+    listxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    llabs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     lldiv;
-    llistxattr;
-    localeconv;
+    llistxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    localeconv; # introduced=21
     localtime;
     localtime64; # arm x86 mips
     localtime64_r; # arm x86 mips
     localtime_r;
-    login_tty;
+    login_tty; # introduced=23
     longjmp;
     lrand48;
-    lremovexattr;
-    lsearch;
+    lremovexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    lsearch; # introduced=21
     lseek;
     lseek64;
-    lsetxattr;
+    lsetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     lstat;
-    lstat64;
+    lstat64; # introduced=21
     madvise;
     mallinfo;
     malloc;
-    malloc_info;
-    malloc_usable_size;
+    malloc_info; # introduced=23
+    malloc_usable_size; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     mbrlen;
-    mbrtoc16;
-    mbrtoc32;
+    mbrtoc16; # introduced=21
+    mbrtoc32; # introduced=21
     mbrtowc;
     mbsinit;
-    mbsnrtowcs;
+    mbsnrtowcs; # introduced=21
     mbsrtowcs;
     mbstowcs;
-    mbtowc;
+    mbtowc; # introduced=21
     memalign;
     memccpy;
     memchr;
@@ -643,91 +642,91 @@
     memcpy;
     memmem;
     memmove;
-    mempcpy;
+    mempcpy; # introduced=23
     memrchr;
     memset;
     mincore;
     mkdir;
     mkdirat;
     mkdtemp;
-    mkfifo;
-    mkfifoat;
+    mkfifo; # introduced=21
+    mkfifoat; # introduced=23
     mknod;
-    mknodat;
-    mkostemp;
-    mkostemp64;
-    mkostemps;
-    mkostemps64;
+    mknodat; # introduced=21
+    mkostemp; # introduced=23
+    mkostemp64; # introduced=23
+    mkostemps; # introduced=23
+    mkostemps64; # introduced=23
     mkstemp;
-    mkstemp64;
+    mkstemp64; # introduced=21
     mkstemps;
-    mkstemps64;
+    mkstemps64; # introduced=23
     mktemp;
     mktime;
     mktime64; # arm x86 mips
     mlock;
-    mlockall;
+    mlockall; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     mmap;
-    mmap64;
+    mmap64; # introduced=21
     mount;
     mprotect;
     mrand48;
     mremap;
     msync;
     munlock;
-    munlockall;
+    munlockall; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     munmap;
     nanosleep;
-    newlocale;
-    nftw;
-    nftw64;
+    newlocale; # introduced=21
+    nftw; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    nftw64; # introduced=21
     nice;
     nrand48;
     nsdispatch;
-    ntohl;
-    ntohs;
+    ntohl; # introduced=21
+    ntohs; # introduced=21
     open;
-    open64;
-    open_memstream;
-    open_wmemstream;
+    open64; # introduced=21
+    open_memstream; # introduced=23
+    open_wmemstream; # introduced=23
     openat;
-    openat64;
+    openat64; # introduced=21
     opendir;
     openlog;
-    openpty;
-    optarg;
-    opterr;
-    optind;
-    optopt;
-    optreset;
+    openpty; # introduced=23
+    optarg; # var
+    opterr; # var
+    optind; # var
+    optopt; # var
+    optreset; # var
     pathconf;
     pause;
     pclose;
     perror;
-    personality;
+    personality; # introduced-arm=15 introduced-arm64=21 introduced-mips=15 introduced-mips64=21 introduced-x86=15 introduced-x86_64=21
     pipe;
     pipe2;
     poll;
     popen;
-    posix_fadvise;
-    posix_fadvise64;
-    posix_fallocate;
-    posix_fallocate64;
-    posix_madvise;
-    posix_memalign;
-    posix_openpt;
-    ppoll;
+    posix_fadvise; # introduced=21
+    posix_fadvise64; # introduced=21
+    posix_fallocate; # introduced=21
+    posix_fallocate64; # introduced=21
+    posix_madvise; # introduced=23
+    posix_memalign; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    posix_openpt; # introduced=21
+    ppoll; # introduced=21
     prctl;
     pread;
-    pread64;
+    pread64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     printf;
-    prlimit64;
-    process_vm_readv;
-    process_vm_writev;
+    prlimit64; # introduced=21
+    process_vm_readv; # introduced=23
+    process_vm_writev; # introduced=23
     pselect;
-    psiginfo;
-    psignal;
-    pthread_atfork;
+    psiginfo; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    psignal; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    pthread_atfork; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     pthread_attr_destroy;
     pthread_attr_getdetachstate;
     pthread_attr_getguardsize;
@@ -755,10 +754,10 @@
     pthread_cond_timeout_np; # arm x86 mips
     pthread_cond_wait;
     pthread_condattr_destroy;
-    pthread_condattr_getclock;
+    pthread_condattr_getclock; # introduced=21
     pthread_condattr_getpshared;
     pthread_condattr_init;
-    pthread_condattr_setclock;
+    pthread_condattr_setclock; # introduced=21
     pthread_condattr_setpshared;
     pthread_create;
     pthread_detach;
@@ -768,7 +767,7 @@
     pthread_getcpuclockid;
     pthread_getschedparam;
     pthread_getspecific;
-    pthread_gettid_np;
+    pthread_gettid_np; # introduced=21
     pthread_join;
     pthread_key_create;
     pthread_key_delete;
@@ -777,7 +776,7 @@
     pthread_mutex_init;
     pthread_mutex_lock;
     pthread_mutex_lock_timeout_np; # arm x86 mips
-    pthread_mutex_timedlock;
+    pthread_mutex_timedlock; # introduced=21
     pthread_mutex_trylock;
     pthread_mutex_unlock;
     pthread_mutexattr_destroy;
@@ -797,10 +796,10 @@
     pthread_rwlock_unlock;
     pthread_rwlock_wrlock;
     pthread_rwlockattr_destroy;
-    pthread_rwlockattr_getkind_np;
+    pthread_rwlockattr_getkind_np; # introduced=23
     pthread_rwlockattr_getpshared;
     pthread_rwlockattr_init;
-    pthread_rwlockattr_setkind_np;
+    pthread_rwlockattr_setkind_np; # introduced=23
     pthread_rwlockattr_setpshared;
     pthread_self;
     pthread_setname_np;
@@ -820,38 +819,38 @@
     putw; # arm x86 mips
     putwc;
     putwchar;
-    pvalloc; # arm x86 mips
+    pvalloc; # arm x86 mips introduced=17
     pwrite;
-    pwrite64;
+    pwrite64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     qsort;
-    quick_exit;
+    quick_exit; # introduced=21
     raise;
-    rand;
-    rand_r;
-    random;
+    rand; # introduced=21
+    rand_r; # introduced=21
+    random; # introduced=21
     read;
-    readahead;
+    readahead; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     readdir;
-    readdir64;
-    readdir64_r;
+    readdir64; # introduced=21
+    readdir64_r; # introduced=21
     readdir_r;
     readlink;
-    readlinkat;
+    readlinkat; # introduced=21
     readv;
     realloc;
     realpath;
     reboot;
     recv;
     recvfrom;
-    recvmmsg;
+    recvmmsg; # introduced=21
     recvmsg;
     regcomp;
     regerror;
     regexec;
     regfree;
     remove;
-    removexattr;
-    remque;
+    removexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    remque; # introduced=21
     rename;
     renameat;
     res_init;
@@ -863,21 +862,21 @@
     rmdir;
     sbrk;
     scandir;
-    scandir64;
+    scandir64; # introduced=21
     scanf;
     sched_get_priority_max;
     sched_get_priority_min;
-    sched_getaffinity;
-    sched_getcpu;
+    sched_getaffinity; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    sched_getcpu; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sched_getparam;
     sched_getscheduler;
     sched_rr_get_interval;
-    sched_setaffinity;
+    sched_setaffinity; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sched_setparam;
     sched_setscheduler;
     sched_yield;
     seed48;
-    seekdir;
+    seekdir; # introduced=23
     select;
     sem_close;
     sem_destroy;
@@ -891,8 +890,8 @@
     sem_wait;
     send;
     sendfile;
-    sendfile64;
-    sendmmsg;
+    sendfile64; # introduced=21
+    sendmmsg; # introduced=21
     sendmsg;
     sendto;
     setbuf;
@@ -900,101 +899,101 @@
     setegid;
     setenv;
     seteuid;
-    setfsgid;
-    setfsuid;
+    setfsgid; # introduced=21
+    setfsuid; # introduced=21
     setgid;
     setgroups;
-    sethostname;
+    sethostname; # introduced=23
     setitimer;
     setjmp;
     setlinebuf;
     setlocale;
     setlogmask;
-    setmntent;
-    setns;
+    setmntent; # introduced=21
+    setns; # introduced=21
     setpgid;
     setpgrp;
     setpriority;
-    setprogname;
+    setprogname; # introduced=21
     setregid;
     setresgid;
     setresuid;
     setreuid;
     setrlimit;
-    setrlimit64;
+    setrlimit64; # introduced=21
     setservent;
     setsid;
     setsockopt;
-    setstate;
+    setstate; # introduced=21
     settimeofday;
     setuid;
     setutent;
     setvbuf;
-    setxattr;
+    setxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     shutdown;
     sigaction;
-    sigaddset;
+    sigaddset; # introduced=21
     sigaltstack;
     sigblock;
-    sigdelset;
-    sigemptyset;
-    sigfillset;
+    sigdelset; # introduced=21
+    sigemptyset; # introduced=21
+    sigfillset; # introduced=21
     siginterrupt;
-    sigismember;
-    siglongjmp;
-    signal;
-    signalfd;
+    sigismember; # introduced=21
+    siglongjmp; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    signal; # introduced=21
+    signalfd; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     sigpending;
     sigprocmask;
-    sigqueue;
-    sigsetjmp;
+    sigqueue; # introduced=23
+    sigsetjmp; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sigsetmask;
     sigsuspend;
-    sigtimedwait;
+    sigtimedwait; # introduced=23
     sigwait;
-    sigwaitinfo;
+    sigwaitinfo; # introduced=23
     sleep;
     snprintf;
     socket;
     socketpair;
-    splice;
+    splice; # introduced=21
     sprintf;
-    srand;
+    srand; # introduced=21
     srand48;
-    srandom;
+    srandom; # introduced=21
     sscanf;
     stat;
-    stat64;
+    stat64; # introduced=21
     statfs;
-    statfs64;
-    statvfs;
-    statvfs64;
-    stderr;
-    stdin;
-    stdout;
-    stpcpy;
-    stpncpy;
+    statfs64; # introduced=21
+    statvfs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    statvfs64; # introduced=21
+    stderr; # var introduced=23
+    stdin; # var introduced=23
+    stdout; # var introduced=23
+    stpcpy; # introduced=21
+    stpncpy; # introduced=21
     strcasecmp;
-    strcasecmp_l;
+    strcasecmp_l; # introduced=23
     strcasestr;
     strcat;
     strchr;
     strcmp;
     strcoll;
-    strcoll_l;
+    strcoll_l; # introduced=21
     strcpy;
     strcspn;
     strdup;
     strerror;
-    strerror_l;
+    strerror_l; # introduced=23
     strerror_r;
     strftime;
-    strftime_l;
+    strftime_l; # introduced=21
     strlcat;
     strlcpy;
     strlen;
     strncasecmp;
-    strncasecmp_l;
+    strncasecmp_l; # introduced=23
     strncat;
     strncmp;
     strncpy;
@@ -1008,86 +1007,86 @@
     strspn;
     strstr;
     strtod;
-    strtof;
+    strtof; # introduced=21
     strtoimax;
     strtok;
     strtok_r;
     strtol;
-    strtold;
-    strtold_l;
+    strtold; # introduced=21
+    strtold_l; # introduced=21
     strtoll;
-    strtoll_l;
-    strtoq;
+    strtoll_l; # introduced=21
+    strtoq; # introduced=21
     strtoul;
     strtoull;
-    strtoull_l;
+    strtoull_l; # introduced=21
     strtoumax;
-    strtouq;
+    strtouq; # introduced=21
     strxfrm;
-    strxfrm_l;
-    swapoff;
-    swapon;
+    strxfrm_l; # introduced=21
+    swapoff; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    swapon; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     swprintf;
     swscanf;
     symlink;
-    symlinkat;
+    symlinkat; # introduced=21
     sync;
-    sys_siglist;
-    sys_signame;
+    sys_siglist; # var
+    sys_signame; # var
     syscall;
     sysconf;
     sysinfo;
     syslog;
     system;
-    tcdrain;
-    tcflow;
-    tcflush;
-    tcgetattr;
+    tcdrain; # introduced=21
+    tcflow; # introduced=21
+    tcflush; # introduced=21
+    tcgetattr; # introduced=21
     tcgetpgrp;
-    tcgetsid;
-    tcsendbreak;
-    tcsetattr;
+    tcgetsid; # introduced=21
+    tcsendbreak; # introduced=21
+    tcsetattr; # introduced=21
     tcsetpgrp;
-    tdelete;
-    tdestroy;
-    tee;
-    telldir;
+    tdelete; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tdestroy; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tee; # introduced=21
+    telldir; # introduced=23
     tempnam;
-    tfind;
-    tgkill;
+    tfind; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tgkill; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     time;
-    timegm;
+    timegm; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     timegm64; # arm x86 mips
-    timelocal;
+    timelocal; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     timelocal64; # arm x86 mips
     timer_create;
     timer_delete;
     timer_getoverrun;
     timer_gettime;
     timer_settime;
-    timerfd_create;
-    timerfd_gettime;
-    timerfd_settime;
+    timerfd_create; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    timerfd_gettime; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    timerfd_settime; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     times;
-    timezone;
+    timezone; # var
     tmpfile;
     tmpnam;
     toascii;
     tolower;
-    tolower_l;
+    tolower_l; # introduced=21
     toupper;
-    toupper_l;
+    toupper_l; # introduced=21
     towlower;
-    towlower_l;
+    towlower_l; # introduced=21
     towupper;
-    towupper_l;
+    towupper_l; # introduced=21
     truncate;
-    truncate64;
-    tsearch;
+    truncate64; # introduced=21
+    tsearch; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     ttyname;
     ttyname_r;
-    twalk;
-    tzname;
+    twalk; # introduced=21
+    tzname; # var
     tzset;
     umask;
     umount;
@@ -1099,38 +1098,38 @@
     unlinkat;
     unlockpt;
     unsetenv;
-    unshare;
-    uselocale;
+    unshare; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    uselocale; # introduced=21
     usleep;
     utime;
-    utimensat;
+    utimensat; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     utimes;
     utmpname;
     valloc; # arm x86 mips
     vasprintf;
-    vdprintf;
+    vdprintf; # introduced=21
     verr;
     verrx;
     vfork;
     vfprintf;
     vfscanf;
     vfwprintf;
-    vfwscanf;
-    vmsplice;
+    vfwscanf; # introduced=21
+    vmsplice; # introduced=21
     vprintf;
     vscanf;
     vsnprintf;
     vsprintf;
     vsscanf;
     vswprintf;
-    vswscanf;
+    vswscanf; # introduced=21
     vsyslog;
     vwarn;
     vwarnx;
     vwprintf;
-    vwscanf;
+    vwscanf; # introduced=21
     wait;
-    wait4;
+    wait4; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     waitid;
     waitpid;
     warn;
@@ -1139,12 +1138,12 @@
     wcpncpy;
     wcrtomb;
     wcscasecmp;
-    wcscasecmp_l;
+    wcscasecmp_l; # introduced=23
     wcscat;
     wcschr;
     wcscmp;
     wcscoll;
-    wcscoll_l;
+    wcscoll_l; # introduced=21
     wcscpy;
     wcscspn;
     wcsdup;
@@ -1153,44 +1152,44 @@
     wcslcpy;
     wcslen;
     wcsncasecmp;
-    wcsncasecmp_l;
+    wcsncasecmp_l; # introduced=23
     wcsncat;
     wcsncmp;
     wcsncpy;
     wcsnlen;
-    wcsnrtombs;
+    wcsnrtombs; # introduced=21
     wcspbrk;
     wcsrchr;
     wcsrtombs;
     wcsspn;
     wcsstr;
     wcstod;
-    wcstof;
-    wcstoimax;
+    wcstof; # introduced=21
+    wcstoimax; # introduced=21
     wcstok;
     wcstol;
-    wcstold;
-    wcstold_l;
-    wcstoll;
-    wcstoll_l;
+    wcstold; # introduced=21
+    wcstold_l; # introduced=21
+    wcstoll; # introduced=21
+    wcstoll_l; # introduced=21
     wcstombs;
     wcstoul;
-    wcstoull;
-    wcstoull_l;
-    wcstoumax;
+    wcstoull; # introduced=21
+    wcstoull_l; # introduced=21
+    wcstoumax; # introduced=21
     wcswidth;
     wcsxfrm;
-    wcsxfrm_l;
+    wcsxfrm_l; # introduced=21
     wctob;
-    wctomb;
+    wctomb; # introduced=21
     wctype;
-    wctype_l;
+    wctype_l; # introduced=21
     wcwidth;
     wmemchr;
     wmemcmp;
     wmemcpy;
     wmemmove;
-    wmempcpy;
+    wmempcpy; # introduced=23
     wmemset;
     wprintf;
     write;
@@ -1200,57 +1199,91 @@
     *;
 };
 
-LIBC_N {
+LIBC_N { # introduced-arm64=24 introduced-mips=24 introduced-mips64=24 introduced-x86=24 introduced-x86_64=24
   global:
-    __fread_chk;
-    __fwrite_chk;
-    __getcwd_chk;
-    __pwrite_chk;
-    __pwrite64_chk;
-    __write_chk;
-    adjtimex;
-    clock_adjtime;
-    fgetpos64;
-    fileno_unlocked;
-    fopen64;
-    freeifaddrs;
-    freopen64;
-    fseeko64;
-    fsetpos64;
-    ftello64;
-    funopen64;
-    getgrgid_r;
-    getgrnam_r;
-    getifaddrs;
-    if_freenameindex;
-    if_nameindex;
-    in6addr_any;
-    in6addr_loopback;
-    lockf;
-    lockf64;
-    preadv;
-    preadv64;
-    prlimit; # arm mips x86
-    pthread_barrierattr_destroy;
-    pthread_barrierattr_getpshared;
-    pthread_barrierattr_init;
-    pthread_barrierattr_setpshared;
-    pthread_barrier_destroy;
-    pthread_barrier_init;
-    pthread_barrier_wait;
-    pthread_spin_destroy;
-    pthread_spin_init;
-    pthread_spin_lock;
-    pthread_spin_trylock;
-    pthread_spin_unlock;
-    pwritev;
-    pwritev64;
-    scandirat;
-    scandirat64;
-    strchrnul;
-    tmpfile64;
+    __fread_chk; # introduced=24
+    __fwrite_chk; # introduced=24
+    __getcwd_chk; # introduced=24
+    __pwrite_chk; # introduced=24
+    __pwrite64_chk; # introduced=24
+    __write_chk; # introduced=24
+    adjtimex; # introduced=24
+    clock_adjtime; # introduced=24
+    fgetpos64; # introduced=24
+    fileno_unlocked; # introduced=24
+    fopen64; # introduced=24
+    freeifaddrs; # introduced=24
+    freopen64; # introduced=24
+    fseeko64; # introduced=24
+    fsetpos64; # introduced=24
+    ftello64; # introduced=24
+    funopen64; # introduced=24
+    getgrgid_r; # introduced=24
+    getgrnam_r; # introduced=24
+    getifaddrs; # introduced=24
+    if_freenameindex; # introduced=24
+    if_nameindex; # introduced=24
+    in6addr_any; # var introduced=24
+    in6addr_loopback; # var introduced=24
+    lockf; # introduced=24
+    lockf64; # introduced=24
+    preadv; # introduced=24
+    preadv64; # introduced=24
+    prlimit; # arm mips x86 introduced=24
+    pthread_barrierattr_destroy; # introduced=24
+    pthread_barrierattr_getpshared; # introduced=24
+    pthread_barrierattr_init; # introduced=24
+    pthread_barrierattr_setpshared; # introduced=24
+    pthread_barrier_destroy; # introduced=24
+    pthread_barrier_init; # introduced=24
+    pthread_barrier_wait; # introduced=24
+    pthread_spin_destroy; # introduced=24
+    pthread_spin_init; # introduced=24
+    pthread_spin_lock; # introduced=24
+    pthread_spin_trylock; # introduced=24
+    pthread_spin_unlock; # introduced=24
+    pwritev; # introduced=24
+    pwritev64; # introduced=24
+    scandirat; # introduced=24
+    scandirat64; # introduced=24
+    strchrnul; # introduced=24
+    tmpfile64; # introduced=24
 } LIBC;
 
+LIBC_O {
+  global:
+    catclose; # future
+    catgets; # future
+    catopen; # future
+    ctermid; # future
+    endgrent; # future
+    endpwent; # future
+    futimes; # future
+    futimesat; # future
+    getdomainname; # future
+    getgrent; # future
+    getpwent; # future
+    getsubopt; # future
+    hasmntopt; # future
+    lutimes; # future
+    mblen; # future
+    pthread_getname_np; # future
+    quotactl; # future
+    setdomainname; # future
+    setgrent; # future
+    setpwent; # future
+    sighold; # future
+    sigignore; # future
+    sigpause; # future
+    sigrelse; # future
+    sigset; # future
+    sync_file_range; # future
+    towctrans; # future
+    towctrans_l; # future
+    wctrans; # future
+    wctrans_l; # future
+} LIBC_N;
+
 LIBC_PRIVATE {
   global:
     __accept4; # arm x86 mips
@@ -1285,7 +1318,7 @@
     SHA1Init; # arm x86 mips
     SHA1Transform; # arm x86 mips
     SHA1Update; # arm x86 mips
-} LIBC_N;
+} LIBC_O;
 
 LIBC_PLATFORM {
   global:
@@ -1296,4 +1329,4 @@
     malloc_disable;
     malloc_enable;
     malloc_iterate;
-} LIBC_N;
+} LIBC_O;
diff --git a/libc/libc.mips.map b/libc/libc.mips.map
index 46c835b..cc143c8 100644
--- a/libc/libc.mips.map
+++ b/libc/libc.mips.map
@@ -1,50 +1,49 @@
-# Generated by genversionscripts.py. Do not edit.
+# Generated by genversion-scripts.py. Do not edit.
 LIBC {
   global:
     __assert;
     __assert2;
     __b64_ntop;
     __b64_pton;
-    __brk; # arm x86 mips
-    __cmsg_nxthdr;
-    __connect; # arm x86 mips
-    __ctype_get_mb_cur_max;
+    __cmsg_nxthdr; # introduced=21
+    __connect; # arm x86 mips introduced=21
+    __ctype_get_mb_cur_max; # introduced=21
     __cxa_atexit;
     __cxa_finalize;
-    __cxa_thread_atexit_impl;
+    __cxa_thread_atexit_impl; # introduced=23
     __dn_comp;
     __dn_count_labels;
     __dn_skipname;
-    __epoll_pwait; # arm x86 mips
+    __epoll_pwait; # arm x86 mips introduced=21
     __errno;
-    __exit; # arm x86 mips
-    __fadvise64; # x86 mips
-    __fbufsize;
+    __exit; # arm x86 mips introduced=21
+    __fadvise64; # x86 mips introduced=21
+    __fbufsize; # introduced=23
     __fcntl64; # arm x86 mips
-    __FD_CLR_chk;
-    __FD_ISSET_chk;
-    __FD_SET_chk;
-    __fgets_chk;
-    __flbf;
+    __FD_CLR_chk; # introduced=21
+    __FD_ISSET_chk; # introduced=21
+    __FD_SET_chk; # introduced=21
+    __fgets_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __flbf; # introduced=23
     __fp_nquery;
     __fp_query;
-    __fpclassify;
+    __fpclassify; # introduced=21
     __fpclassifyd;
     __fpclassifyf;
     __fpclassifyl;
-    __fpending;
-    __fpurge;
-    __freadable;
-    __fsetlocking;
+    __fpending; # introduced=23
+    __fpurge; # introduced=23
+    __freadable; # introduced=23
+    __fsetlocking; # introduced=23
     __fstatfs64; # arm x86 mips
-    __fwritable;
+    __fwritable; # introduced=23
     __get_h_errno;
-    __getcpu; # arm x86 mips
+    __getcpu; # arm x86 mips introduced-arm=12 introduced-mips=16 introduced-x86=12
     __getcwd; # arm x86 mips
-    __getpid; # arm x86 mips
+    __getpid; # arm x86 mips introduced=21
     __getpriority; # arm x86 mips
-    __gnu_basename;
-    __gnu_strerror_r;
+    __gnu_basename; # introduced=23
+    __gnu_strerror_r; # introduced=23
     __hostalias;
     __ioctl; # arm x86 mips
     __isfinite;
@@ -53,24 +52,24 @@
     __isinf;
     __isinff;
     __isinfl;
-    __isnan;
-    __isnanf;
+    __isnan; # introduced=21
+    __isnanf; # introduced=21
     __isnanl;
     __isnormal;
     __isnormalf;
     __isnormall;
-    __isthreaded; # arm x86 mips
-    __libc_current_sigrtmax;
-    __libc_current_sigrtmin;
+    __isthreaded; # arm x86 mips var
+    __libc_current_sigrtmax; # introduced=21
+    __libc_current_sigrtmin; # introduced=21
     __libc_init;
     __llseek; # arm x86 mips
     __loc_aton;
     __loc_ntoa;
-    __memchr_chk;
-    __memcpy_chk;
-    __memmove_chk;
-    __memrchr_chk;
-    __memset_chk;
+    __memchr_chk; # introduced=23
+    __memcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __memmove_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __memrchr_chk; # introduced=23
+    __memset_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __mmap2; # arm x86 mips
     __ns_format_ttl; # arm x86 mips
     __ns_get16; # arm x86 mips
@@ -94,13 +93,13 @@
     __ns_skiprr; # arm x86 mips
     __ns_sprintrr; # arm x86 mips
     __ns_sprintrrf; # arm x86 mips
-    __open_2;
+    __open_2; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __openat; # arm x86 mips
-    __openat_2;
+    __openat_2; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __p_cdname;
     __p_cdnname;
     __p_class;
-    __p_class_syms;
+    __p_class_syms; # var
     __p_fqname;
     __p_fqnname;
     __p_option;
@@ -109,25 +108,25 @@
     __p_secstodate;
     __p_time;
     __p_type;
-    __p_type_syms;
-    __poll_chk;
-    __ppoll; # arm x86 mips
-    __ppoll_chk;
-    __pread64_chk;
-    __pread_chk;
-    __progname;
-    __pselect6; # arm x86 mips
+    __p_type_syms; # var
+    __poll_chk; # introduced=23
+    __ppoll; # arm x86 mips introduced=21
+    __ppoll_chk; # introduced=23
+    __pread64_chk; # introduced=23
+    __pread_chk; # introduced=23
+    __progname; # var
+    __pselect6; # arm x86 mips introduced=21
     __pthread_cleanup_pop;
     __pthread_cleanup_push;
     __ptrace; # arm x86 mips
     __putlong;
     __putshort;
-    __read_chk;
-    __readlink_chk;
-    __readlinkat_chk;
+    __read_chk; # introduced=21
+    __readlink_chk; # introduced=23
+    __readlinkat_chk; # introduced=23
     __reboot; # arm x86 mips
-    __recvfrom_chk;
-    __register_atfork;
+    __recvfrom_chk; # introduced=21
+    __register_atfork; # introduced=23
     __res_close;
     __res_dnok;
     __res_hnok;
@@ -149,90 +148,90 @@
     __res_send_setqhook;
     __res_send_setrhook;
     __rt_sigaction; # arm x86 mips
-    __rt_sigpending; # arm x86 mips
+    __rt_sigpending; # arm x86 mips introduced=21
     __rt_sigprocmask; # arm x86 mips
-    __rt_sigsuspend; # arm x86 mips
+    __rt_sigsuspend; # arm x86 mips introduced=21
     __rt_sigtimedwait; # arm x86 mips
-    __sched_cpualloc;
-    __sched_cpucount;
-    __sched_cpufree;
-    __sched_getaffinity; # arm x86 mips
-    __set_tid_address; # arm x86 mips
+    __sched_cpualloc; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_cpucount; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_cpufree; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_getaffinity; # arm x86 mips introduced=12
+    __set_tid_address; # arm x86 mips introduced=21
     __set_tls; # arm mips
-    __sF;
-    __sigaction; # arm x86 mips
-    __snprintf_chk;
-    __socket; # arm x86 mips
-    __sprintf_chk;
+    __sF; # var
+    __sigaction; # arm x86 mips introduced=21
+    __snprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __socket; # arm x86 mips introduced=21
+    __sprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __stack_chk_fail;
-    __stack_chk_guard;
+    __stack_chk_guard; # var
     __statfs64; # arm x86 mips
-    __stpcpy_chk;
-    __stpncpy_chk;
-    __stpncpy_chk2;
-    __strcat_chk;
-    __strchr_chk;
-    __strcpy_chk;
-    __strlcat_chk;
-    __strlcpy_chk;
-    __strlen_chk;
-    __strncat_chk;
-    __strncpy_chk;
-    __strncpy_chk2;
-    __strrchr_chk;
+    __stpcpy_chk; # introduced=21
+    __stpncpy_chk; # introduced=21
+    __stpncpy_chk2; # introduced=21
+    __strcat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strchr_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
+    __strcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlcat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlen_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncpy_chk2; # introduced=21
+    __strrchr_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     __sym_ntop;
     __sym_ntos;
     __sym_ston;
     __system_properties_init;
-    __system_property_add;
-    __system_property_area__;
-    __system_property_area_init;
-    __system_property_area_serial;
+    __system_property_add; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_area__; # var
+    __system_property_area_init; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_area_serial; # introduced=23
     __system_property_find;
     __system_property_find_nth;
-    __system_property_foreach;
+    __system_property_foreach; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     __system_property_get;
     __system_property_read;
-    __system_property_serial;
-    __system_property_set;
-    __system_property_set_filename;
-    __system_property_update;
-    __system_property_wait_any;
+    __system_property_serial; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_set; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __system_property_set_filename; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_update; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_wait_any; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     __timer_create; # arm x86 mips
     __timer_delete; # arm x86 mips
     __timer_getoverrun; # arm x86 mips
     __timer_gettime; # arm x86 mips
     __timer_settime; # arm x86 mips
-    __umask_chk;
-    __vsnprintf_chk;
-    __vsprintf_chk;
+    __umask_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
+    __vsnprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __vsprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __waitid; # arm x86 mips
-    _ctype_;
-    _Exit;
+    _ctype_; # var
+    _Exit; # introduced=21
     _exit;
     _flush_cache; # mips
-    _flushlbf;
+    _flushlbf; # introduced=23
     _getlong;
     _getshort;
     _longjmp;
-    _resolv_delete_cache_for_net;
-    _resolv_flush_cache_for_net;
-    _resolv_set_nameservers_for_net;
+    _resolv_delete_cache_for_net; # introduced=21
+    _resolv_flush_cache_for_net; # introduced=21
+    _resolv_set_nameservers_for_net; # introduced=21
     _setjmp;
-    _tolower;
-    _tolower_tab_; # arm x86 mips
-    _toupper;
-    _toupper_tab_; # arm x86 mips
+    _tolower; # introduced=21
+    _tolower_tab_; # arm x86 mips var
+    _toupper; # introduced=21
+    _toupper_tab_; # arm x86 mips var
     abort;
-    abs;
+    abs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     accept;
-    accept4;
+    accept4; # introduced=21
     access;
     acct;
     alarm;
     alphasort;
-    alphasort64;
-    android_set_abort_message;
+    alphasort64; # introduced=21
+    android_set_abort_message; # introduced=21
     arc4random;
     arc4random_buf;
     arc4random_uniform;
@@ -241,8 +240,8 @@
     asctime64_r; # arm x86 mips
     asctime_r;
     asprintf;
-    at_quick_exit;
-    atof;
+    at_quick_exit; # introduced=21
+    atof; # introduced=21
     atoi;
     atol;
     atoll;
@@ -253,44 +252,44 @@
     brk;
     bsearch;
     btowc;
-    c16rtomb;
-    c32rtomb;
+    c16rtomb; # introduced=21
+    c32rtomb; # introduced=21
     cacheflush; # arm mips
     calloc;
     capget;
     capset;
-    cfgetispeed;
-    cfgetospeed;
-    cfmakeraw;
-    cfsetispeed;
-    cfsetospeed;
-    cfsetspeed;
+    cfgetispeed; # introduced=21
+    cfgetospeed; # introduced=21
+    cfmakeraw; # introduced=21
+    cfsetispeed; # introduced=21
+    cfsetospeed; # introduced=21
+    cfsetspeed; # introduced=21
     chdir;
     chmod;
     chown;
     chroot;
     clearenv;
     clearerr;
-    clearerr_unlocked;
+    clearerr_unlocked; # introduced=23
     clock;
-    clock_getcpuclockid;
+    clock_getcpuclockid; # introduced=23
     clock_getres;
     clock_gettime;
     clock_nanosleep;
     clock_settime;
-    clone;
+    clone; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     close;
     closedir;
     closelog;
     connect;
     creat;
-    creat64;
+    creat64; # introduced=21
     ctime;
     ctime64; # arm x86 mips
     ctime64_r; # arm x86 mips
     ctime_r;
     daemon;
-    daylight;
+    daylight; # var
     delete_module;
     difftime;
     dirfd;
@@ -298,33 +297,33 @@
     dirname_r; # arm x86 mips
     div;
     dn_expand;
-    dprintf;
+    dprintf; # introduced=21
     drand48;
     dup;
     dup2;
-    dup3;
-    duplocale;
-    endmntent;
+    dup3; # introduced=21
+    duplocale; # introduced=21
+    endmntent; # introduced=21
     endservent;
     endutent;
-    environ;
+    environ; # var
     epoll_create;
-    epoll_create1;
+    epoll_create1; # introduced=21
     epoll_ctl;
-    epoll_pwait;
+    epoll_pwait; # introduced=21
     epoll_wait;
     erand48;
     err;
-    error;
-    error_at_line;
-    error_message_count;
-    error_one_per_line;
-    error_print_progname;
+    error; # introduced=23
+    error_at_line; # introduced=23
+    error_message_count; # var introduced=23
+    error_one_per_line; # var introduced=23
+    error_print_progname; # var introduced=23
     errx;
-    ether_aton;
-    ether_aton_r;
-    ether_ntoa;
-    ether_ntoa_r;
+    ether_aton; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_aton_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_ntoa; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_ntoa_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     eventfd;
     eventfd_read;
     eventfd_write;
@@ -334,11 +333,11 @@
     execv;
     execve;
     execvp;
-    execvpe;
+    execvpe; # introduced=21
     exit;
-    faccessat;
-    fallocate;
-    fallocate64;
+    faccessat; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    fallocate; # introduced=21
+    fallocate64; # introduced=21
     fchdir;
     fchmod;
     fchmodat;
@@ -350,27 +349,27 @@
     fdopen;
     fdopendir;
     feof;
-    feof_unlocked;
+    feof_unlocked; # introduced=23
     ferror;
-    ferror_unlocked;
+    ferror_unlocked; # introduced=23
     fflush;
-    ffs;
+    ffs; # introduced-arm=9 introduced-arm64=21 introduced-mips=9 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     fgetc;
     fgetln;
     fgetpos;
     fgets;
     fgetwc;
     fgetws;
-    fgetxattr;
+    fgetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     fileno;
-    flistxattr;
+    flistxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     flock;
     flockfile;
-    fmemopen;
+    fmemopen; # introduced=23
     fnmatch;
     fopen;
     fork;
-    forkpty;
+    forkpty; # introduced=23
     fpathconf;
     fprintf;
     fpurge;
@@ -381,56 +380,56 @@
     fread;
     free;
     freeaddrinfo;
-    freelocale;
-    fremovexattr;
+    freelocale; # introduced=21
+    fremovexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     freopen;
     fscanf;
     fseek;
     fseeko;
     fsetpos;
-    fsetxattr;
+    fsetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     fstat;
-    fstat64;
+    fstat64; # introduced=21
     fstatat;
-    fstatat64;
+    fstatat64; # introduced=21
     fstatfs;
-    fstatfs64;
-    fstatvfs;
-    fstatvfs64;
+    fstatfs64; # introduced=21
+    fstatvfs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    fstatvfs64; # introduced=21
     fsync;
     ftell;
     ftello;
     ftok;
     ftruncate;
-    ftruncate64;
+    ftruncate64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     ftrylockfile;
     fts_children;
     fts_close;
     fts_open;
     fts_read;
     fts_set;
-    ftw;
-    ftw64;
+    ftw; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    ftw64; # introduced=21
     funlockfile;
     funopen;
-    futimens;
+    futimens; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     fwide;
     fwprintf;
     fwrite;
     fwscanf;
     gai_strerror;
-    get_avphys_pages;
-    get_nprocs;
-    get_nprocs_conf;
-    get_phys_pages;
+    get_avphys_pages; # introduced=23
+    get_nprocs; # introduced=23
+    get_nprocs_conf; # introduced=23
+    get_phys_pages; # introduced=23
     getaddrinfo;
-    getauxval;
+    getauxval; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getc;
     getc_unlocked;
     getchar;
     getchar_unlocked;
     getcwd;
-    getdelim;
+    getdelim; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getegid;
     getenv;
     geteuid;
@@ -440,49 +439,49 @@
     getgrouplist;
     getgroups;
     gethostbyaddr;
-    gethostbyaddr_r;
+    gethostbyaddr_r; # introduced=23
     gethostbyname;
     gethostbyname2;
-    gethostbyname2_r;
+    gethostbyname2_r; # introduced=23
     gethostbyname_r;
     gethostent;
     gethostname;
     getitimer;
-    getline;
+    getline; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getlogin;
     getmntent;
-    getmntent_r;
+    getmntent_r; # introduced=21
     getnameinfo;
     getnetbyaddr;
     getnetbyname;
     getopt;
     getopt_long;
     getopt_long_only;
-    getpagesize;
+    getpagesize; # introduced=21
     getpeername;
     getpgid;
     getpgrp;
     getpid;
     getppid;
     getpriority;
-    getprogname;
+    getprogname; # introduced=21
     getprotobyname;
     getprotobynumber;
     getpt;
     getpwnam;
-    getpwnam_r;
+    getpwnam_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     getpwuid;
-    getpwuid_r;
+    getpwuid_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     getresgid;
     getresuid;
     getrlimit;
-    getrlimit64;
+    getrlimit64; # introduced=21
     getrusage;
     gets;
     getservbyname;
     getservbyport;
     getservent;
-    getsid;
+    getsid; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     getsockname;
     getsockopt;
     gettid;
@@ -491,26 +490,26 @@
     getutent;
     getwc;
     getwchar;
-    getxattr;
+    getxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     gmtime;
     gmtime64; # arm x86 mips
     gmtime64_r; # arm x86 mips
     gmtime_r;
-    grantpt;
+    grantpt; # introduced=21
     herror;
     hstrerror;
-    htonl;
-    htons;
+    htonl; # introduced=21
+    htons; # introduced=21
     if_indextoname;
     if_nametoindex;
-    imaxabs;
-    imaxdiv;
+    imaxabs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    imaxdiv; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     inet_addr;
     inet_aton;
-    inet_lnaof;
-    inet_makeaddr;
-    inet_netof;
-    inet_network;
+    inet_lnaof; # introduced=21
+    inet_makeaddr; # introduced=21
+    inet_netof; # introduced=21
+    inet_network; # introduced=21
     inet_nsap_addr;
     inet_nsap_ntoa;
     inet_ntoa;
@@ -518,124 +517,124 @@
     inet_pton;
     init_module;
     initgroups;
-    initstate;
+    initstate; # introduced=21
     inotify_add_watch;
     inotify_init;
-    inotify_init1;
+    inotify_init1; # introduced=21
     inotify_rm_watch;
-    insque;
+    insque; # introduced=21
     ioctl;
     isalnum;
-    isalnum_l;
+    isalnum_l; # introduced=21
     isalpha;
-    isalpha_l;
+    isalpha_l; # introduced=21
     isascii;
     isatty;
     isblank;
-    isblank_l;
+    isblank_l; # introduced=21
     iscntrl;
-    iscntrl_l;
+    iscntrl_l; # introduced=21
     isdigit;
-    isdigit_l;
-    isfinite;
-    isfinitef;
-    isfinitel;
+    isdigit_l; # introduced=21
+    isfinite; # introduced=21
+    isfinitef; # introduced=21
+    isfinitel; # introduced=21
     isgraph;
-    isgraph_l;
-    isinf;
-    isinff;
-    isinfl;
+    isgraph_l; # introduced=21
+    isinf; # introduced=21
+    isinff; # introduced=21
+    isinfl; # introduced=21
     islower;
-    islower_l;
+    islower_l; # introduced=21
     isnan;
     isnanf;
-    isnanl;
-    isnormal;
-    isnormalf;
-    isnormall;
+    isnanl; # introduced=21
+    isnormal; # introduced=21
+    isnormalf; # introduced=21
+    isnormall; # introduced=21
     isprint;
-    isprint_l;
+    isprint_l; # introduced=21
     ispunct;
-    ispunct_l;
+    ispunct_l; # introduced=21
     isspace;
-    isspace_l;
+    isspace_l; # introduced=21
     isupper;
-    isupper_l;
+    isupper_l; # introduced=21
     iswalnum;
-    iswalnum_l;
+    iswalnum_l; # introduced=21
     iswalpha;
-    iswalpha_l;
-    iswblank;
-    iswblank_l;
+    iswalpha_l; # introduced=21
+    iswblank; # introduced=21
+    iswblank_l; # introduced=21
     iswcntrl;
-    iswcntrl_l;
+    iswcntrl_l; # introduced=21
     iswctype;
-    iswctype_l;
+    iswctype_l; # introduced=21
     iswdigit;
-    iswdigit_l;
+    iswdigit_l; # introduced=21
     iswgraph;
-    iswgraph_l;
+    iswgraph_l; # introduced=21
     iswlower;
-    iswlower_l;
+    iswlower_l; # introduced=21
     iswprint;
-    iswprint_l;
+    iswprint_l; # introduced=21
     iswpunct;
-    iswpunct_l;
+    iswpunct_l; # introduced=21
     iswspace;
-    iswspace_l;
+    iswspace_l; # introduced=21
     iswupper;
-    iswupper_l;
+    iswupper_l; # introduced=21
     iswxdigit;
-    iswxdigit_l;
+    iswxdigit_l; # introduced=21
     isxdigit;
-    isxdigit_l;
+    isxdigit_l; # introduced=21
     jrand48;
     kill;
     killpg;
     klogctl;
-    labs;
+    labs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     lchown;
-    lcong48;
+    lcong48; # introduced=23
     ldexp;
     ldiv;
-    lfind;
-    lgetxattr;
+    lfind; # introduced=21
+    lgetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     link;
-    linkat;
+    linkat; # introduced=21
     listen;
-    listxattr;
-    llabs;
+    listxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    llabs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     lldiv;
-    llistxattr;
-    localeconv;
+    llistxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    localeconv; # introduced=21
     localtime;
     localtime64; # arm x86 mips
     localtime64_r; # arm x86 mips
     localtime_r;
-    login_tty;
+    login_tty; # introduced=23
     longjmp;
     lrand48;
-    lremovexattr;
-    lsearch;
+    lremovexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    lsearch; # introduced=21
     lseek;
     lseek64;
-    lsetxattr;
+    lsetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     lstat;
-    lstat64;
+    lstat64; # introduced=21
     madvise;
     mallinfo;
     malloc;
-    malloc_info;
-    malloc_usable_size;
+    malloc_info; # introduced=23
+    malloc_usable_size; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     mbrlen;
-    mbrtoc16;
-    mbrtoc32;
+    mbrtoc16; # introduced=21
+    mbrtoc32; # introduced=21
     mbrtowc;
     mbsinit;
-    mbsnrtowcs;
+    mbsnrtowcs; # introduced=21
     mbsrtowcs;
     mbstowcs;
-    mbtowc;
+    mbtowc; # introduced=21
     memalign;
     memccpy;
     memchr;
@@ -643,91 +642,91 @@
     memcpy;
     memmem;
     memmove;
-    mempcpy;
+    mempcpy; # introduced=23
     memrchr;
     memset;
     mincore;
     mkdir;
     mkdirat;
     mkdtemp;
-    mkfifo;
-    mkfifoat;
+    mkfifo; # introduced=21
+    mkfifoat; # introduced=23
     mknod;
-    mknodat;
-    mkostemp;
-    mkostemp64;
-    mkostemps;
-    mkostemps64;
+    mknodat; # introduced=21
+    mkostemp; # introduced=23
+    mkostemp64; # introduced=23
+    mkostemps; # introduced=23
+    mkostemps64; # introduced=23
     mkstemp;
-    mkstemp64;
+    mkstemp64; # introduced=21
     mkstemps;
-    mkstemps64;
+    mkstemps64; # introduced=23
     mktemp;
     mktime;
     mktime64; # arm x86 mips
     mlock;
-    mlockall;
+    mlockall; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     mmap;
-    mmap64;
+    mmap64; # introduced=21
     mount;
     mprotect;
     mrand48;
     mremap;
     msync;
     munlock;
-    munlockall;
+    munlockall; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     munmap;
     nanosleep;
-    newlocale;
-    nftw;
-    nftw64;
+    newlocale; # introduced=21
+    nftw; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    nftw64; # introduced=21
     nice;
     nrand48;
     nsdispatch;
-    ntohl;
-    ntohs;
+    ntohl; # introduced=21
+    ntohs; # introduced=21
     open;
-    open64;
-    open_memstream;
-    open_wmemstream;
+    open64; # introduced=21
+    open_memstream; # introduced=23
+    open_wmemstream; # introduced=23
     openat;
-    openat64;
+    openat64; # introduced=21
     opendir;
     openlog;
-    openpty;
-    optarg;
-    opterr;
-    optind;
-    optopt;
-    optreset;
+    openpty; # introduced=23
+    optarg; # var
+    opterr; # var
+    optind; # var
+    optopt; # var
+    optreset; # var
     pathconf;
     pause;
     pclose;
     perror;
-    personality;
+    personality; # introduced-arm=15 introduced-arm64=21 introduced-mips=15 introduced-mips64=21 introduced-x86=15 introduced-x86_64=21
     pipe;
     pipe2;
     poll;
     popen;
-    posix_fadvise;
-    posix_fadvise64;
-    posix_fallocate;
-    posix_fallocate64;
-    posix_madvise;
-    posix_memalign;
-    posix_openpt;
-    ppoll;
+    posix_fadvise; # introduced=21
+    posix_fadvise64; # introduced=21
+    posix_fallocate; # introduced=21
+    posix_fallocate64; # introduced=21
+    posix_madvise; # introduced=23
+    posix_memalign; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    posix_openpt; # introduced=21
+    ppoll; # introduced=21
     prctl;
     pread;
-    pread64;
+    pread64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     printf;
-    prlimit64;
-    process_vm_readv;
-    process_vm_writev;
+    prlimit64; # introduced=21
+    process_vm_readv; # introduced=23
+    process_vm_writev; # introduced=23
     pselect;
-    psiginfo;
-    psignal;
-    pthread_atfork;
+    psiginfo; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    psignal; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    pthread_atfork; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     pthread_attr_destroy;
     pthread_attr_getdetachstate;
     pthread_attr_getguardsize;
@@ -755,10 +754,10 @@
     pthread_cond_timeout_np; # arm x86 mips
     pthread_cond_wait;
     pthread_condattr_destroy;
-    pthread_condattr_getclock;
+    pthread_condattr_getclock; # introduced=21
     pthread_condattr_getpshared;
     pthread_condattr_init;
-    pthread_condattr_setclock;
+    pthread_condattr_setclock; # introduced=21
     pthread_condattr_setpshared;
     pthread_create;
     pthread_detach;
@@ -768,7 +767,7 @@
     pthread_getcpuclockid;
     pthread_getschedparam;
     pthread_getspecific;
-    pthread_gettid_np;
+    pthread_gettid_np; # introduced=21
     pthread_join;
     pthread_key_create;
     pthread_key_delete;
@@ -777,7 +776,7 @@
     pthread_mutex_init;
     pthread_mutex_lock;
     pthread_mutex_lock_timeout_np; # arm x86 mips
-    pthread_mutex_timedlock;
+    pthread_mutex_timedlock; # introduced=21
     pthread_mutex_trylock;
     pthread_mutex_unlock;
     pthread_mutexattr_destroy;
@@ -797,10 +796,10 @@
     pthread_rwlock_unlock;
     pthread_rwlock_wrlock;
     pthread_rwlockattr_destroy;
-    pthread_rwlockattr_getkind_np;
+    pthread_rwlockattr_getkind_np; # introduced=23
     pthread_rwlockattr_getpshared;
     pthread_rwlockattr_init;
-    pthread_rwlockattr_setkind_np;
+    pthread_rwlockattr_setkind_np; # introduced=23
     pthread_rwlockattr_setpshared;
     pthread_self;
     pthread_setname_np;
@@ -820,38 +819,38 @@
     putw; # arm x86 mips
     putwc;
     putwchar;
-    pvalloc; # arm x86 mips
+    pvalloc; # arm x86 mips introduced=17
     pwrite;
-    pwrite64;
+    pwrite64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     qsort;
-    quick_exit;
+    quick_exit; # introduced=21
     raise;
-    rand;
-    rand_r;
-    random;
+    rand; # introduced=21
+    rand_r; # introduced=21
+    random; # introduced=21
     read;
-    readahead;
+    readahead; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     readdir;
-    readdir64;
-    readdir64_r;
+    readdir64; # introduced=21
+    readdir64_r; # introduced=21
     readdir_r;
     readlink;
-    readlinkat;
+    readlinkat; # introduced=21
     readv;
     realloc;
     realpath;
     reboot;
     recv;
     recvfrom;
-    recvmmsg;
+    recvmmsg; # introduced=21
     recvmsg;
     regcomp;
     regerror;
     regexec;
     regfree;
     remove;
-    removexattr;
-    remque;
+    removexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    remque; # introduced=21
     rename;
     renameat;
     res_init;
@@ -863,21 +862,21 @@
     rmdir;
     sbrk;
     scandir;
-    scandir64;
+    scandir64; # introduced=21
     scanf;
     sched_get_priority_max;
     sched_get_priority_min;
-    sched_getaffinity;
-    sched_getcpu;
+    sched_getaffinity; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    sched_getcpu; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sched_getparam;
     sched_getscheduler;
     sched_rr_get_interval;
-    sched_setaffinity;
+    sched_setaffinity; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sched_setparam;
     sched_setscheduler;
     sched_yield;
     seed48;
-    seekdir;
+    seekdir; # introduced=23
     select;
     sem_close;
     sem_destroy;
@@ -891,8 +890,8 @@
     sem_wait;
     send;
     sendfile;
-    sendfile64;
-    sendmmsg;
+    sendfile64; # introduced=21
+    sendmmsg; # introduced=21
     sendmsg;
     sendto;
     setbuf;
@@ -900,101 +899,101 @@
     setegid;
     setenv;
     seteuid;
-    setfsgid;
-    setfsuid;
+    setfsgid; # introduced=21
+    setfsuid; # introduced=21
     setgid;
     setgroups;
-    sethostname;
+    sethostname; # introduced=23
     setitimer;
     setjmp;
     setlinebuf;
     setlocale;
     setlogmask;
-    setmntent;
-    setns;
+    setmntent; # introduced=21
+    setns; # introduced=21
     setpgid;
     setpgrp;
     setpriority;
-    setprogname;
+    setprogname; # introduced=21
     setregid;
     setresgid;
     setresuid;
     setreuid;
     setrlimit;
-    setrlimit64;
+    setrlimit64; # introduced=21
     setservent;
     setsid;
     setsockopt;
-    setstate;
+    setstate; # introduced=21
     settimeofday;
     setuid;
     setutent;
     setvbuf;
-    setxattr;
+    setxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     shutdown;
     sigaction;
-    sigaddset;
+    sigaddset; # introduced=21
     sigaltstack;
     sigblock;
-    sigdelset;
-    sigemptyset;
-    sigfillset;
+    sigdelset; # introduced=21
+    sigemptyset; # introduced=21
+    sigfillset; # introduced=21
     siginterrupt;
-    sigismember;
-    siglongjmp;
-    signal;
-    signalfd;
+    sigismember; # introduced=21
+    siglongjmp; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    signal; # introduced=21
+    signalfd; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     sigpending;
     sigprocmask;
-    sigqueue;
-    sigsetjmp;
+    sigqueue; # introduced=23
+    sigsetjmp; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sigsetmask;
     sigsuspend;
-    sigtimedwait;
+    sigtimedwait; # introduced=23
     sigwait;
-    sigwaitinfo;
+    sigwaitinfo; # introduced=23
     sleep;
     snprintf;
     socket;
     socketpair;
-    splice;
+    splice; # introduced=21
     sprintf;
-    srand;
+    srand; # introduced=21
     srand48;
-    srandom;
+    srandom; # introduced=21
     sscanf;
     stat;
-    stat64;
+    stat64; # introduced=21
     statfs;
-    statfs64;
-    statvfs;
-    statvfs64;
-    stderr;
-    stdin;
-    stdout;
-    stpcpy;
-    stpncpy;
+    statfs64; # introduced=21
+    statvfs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    statvfs64; # introduced=21
+    stderr; # var introduced=23
+    stdin; # var introduced=23
+    stdout; # var introduced=23
+    stpcpy; # introduced=21
+    stpncpy; # introduced=21
     strcasecmp;
-    strcasecmp_l;
+    strcasecmp_l; # introduced=23
     strcasestr;
     strcat;
     strchr;
     strcmp;
     strcoll;
-    strcoll_l;
+    strcoll_l; # introduced=21
     strcpy;
     strcspn;
     strdup;
     strerror;
-    strerror_l;
+    strerror_l; # introduced=23
     strerror_r;
     strftime;
-    strftime_l;
+    strftime_l; # introduced=21
     strlcat;
     strlcpy;
     strlen;
     strncasecmp;
-    strncasecmp_l;
+    strncasecmp_l; # introduced=23
     strncat;
     strncmp;
     strncpy;
@@ -1008,86 +1007,86 @@
     strspn;
     strstr;
     strtod;
-    strtof;
+    strtof; # introduced=21
     strtoimax;
     strtok;
     strtok_r;
     strtol;
-    strtold;
-    strtold_l;
+    strtold; # introduced=21
+    strtold_l; # introduced=21
     strtoll;
-    strtoll_l;
-    strtoq;
+    strtoll_l; # introduced=21
+    strtoq; # introduced=21
     strtoul;
     strtoull;
-    strtoull_l;
+    strtoull_l; # introduced=21
     strtoumax;
-    strtouq;
+    strtouq; # introduced=21
     strxfrm;
-    strxfrm_l;
-    swapoff;
-    swapon;
+    strxfrm_l; # introduced=21
+    swapoff; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    swapon; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     swprintf;
     swscanf;
     symlink;
-    symlinkat;
+    symlinkat; # introduced=21
     sync;
-    sys_siglist;
-    sys_signame;
+    sys_siglist; # var
+    sys_signame; # var
     syscall;
     sysconf;
     sysinfo;
     syslog;
     system;
-    tcdrain;
-    tcflow;
-    tcflush;
-    tcgetattr;
+    tcdrain; # introduced=21
+    tcflow; # introduced=21
+    tcflush; # introduced=21
+    tcgetattr; # introduced=21
     tcgetpgrp;
-    tcgetsid;
-    tcsendbreak;
-    tcsetattr;
+    tcgetsid; # introduced=21
+    tcsendbreak; # introduced=21
+    tcsetattr; # introduced=21
     tcsetpgrp;
-    tdelete;
-    tdestroy;
-    tee;
-    telldir;
+    tdelete; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tdestroy; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tee; # introduced=21
+    telldir; # introduced=23
     tempnam;
-    tfind;
-    tgkill;
+    tfind; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tgkill; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     time;
-    timegm;
+    timegm; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     timegm64; # arm x86 mips
-    timelocal;
+    timelocal; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     timelocal64; # arm x86 mips
     timer_create;
     timer_delete;
     timer_getoverrun;
     timer_gettime;
     timer_settime;
-    timerfd_create;
-    timerfd_gettime;
-    timerfd_settime;
+    timerfd_create; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    timerfd_gettime; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    timerfd_settime; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     times;
-    timezone;
+    timezone; # var
     tmpfile;
     tmpnam;
     toascii;
     tolower;
-    tolower_l;
+    tolower_l; # introduced=21
     toupper;
-    toupper_l;
+    toupper_l; # introduced=21
     towlower;
-    towlower_l;
+    towlower_l; # introduced=21
     towupper;
-    towupper_l;
+    towupper_l; # introduced=21
     truncate;
-    truncate64;
-    tsearch;
+    truncate64; # introduced=21
+    tsearch; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     ttyname;
     ttyname_r;
-    twalk;
-    tzname;
+    twalk; # introduced=21
+    tzname; # var
     tzset;
     umask;
     umount;
@@ -1099,38 +1098,38 @@
     unlinkat;
     unlockpt;
     unsetenv;
-    unshare;
-    uselocale;
+    unshare; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    uselocale; # introduced=21
     usleep;
     utime;
-    utimensat;
+    utimensat; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     utimes;
     utmpname;
     valloc; # arm x86 mips
     vasprintf;
-    vdprintf;
+    vdprintf; # introduced=21
     verr;
     verrx;
     vfork;
     vfprintf;
     vfscanf;
     vfwprintf;
-    vfwscanf;
-    vmsplice;
+    vfwscanf; # introduced=21
+    vmsplice; # introduced=21
     vprintf;
     vscanf;
     vsnprintf;
     vsprintf;
     vsscanf;
     vswprintf;
-    vswscanf;
+    vswscanf; # introduced=21
     vsyslog;
     vwarn;
     vwarnx;
     vwprintf;
-    vwscanf;
+    vwscanf; # introduced=21
     wait;
-    wait4;
+    wait4; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     waitid;
     waitpid;
     warn;
@@ -1139,12 +1138,12 @@
     wcpncpy;
     wcrtomb;
     wcscasecmp;
-    wcscasecmp_l;
+    wcscasecmp_l; # introduced=23
     wcscat;
     wcschr;
     wcscmp;
     wcscoll;
-    wcscoll_l;
+    wcscoll_l; # introduced=21
     wcscpy;
     wcscspn;
     wcsdup;
@@ -1153,44 +1152,44 @@
     wcslcpy;
     wcslen;
     wcsncasecmp;
-    wcsncasecmp_l;
+    wcsncasecmp_l; # introduced=23
     wcsncat;
     wcsncmp;
     wcsncpy;
     wcsnlen;
-    wcsnrtombs;
+    wcsnrtombs; # introduced=21
     wcspbrk;
     wcsrchr;
     wcsrtombs;
     wcsspn;
     wcsstr;
     wcstod;
-    wcstof;
-    wcstoimax;
+    wcstof; # introduced=21
+    wcstoimax; # introduced=21
     wcstok;
     wcstol;
-    wcstold;
-    wcstold_l;
-    wcstoll;
-    wcstoll_l;
+    wcstold; # introduced=21
+    wcstold_l; # introduced=21
+    wcstoll; # introduced=21
+    wcstoll_l; # introduced=21
     wcstombs;
     wcstoul;
-    wcstoull;
-    wcstoull_l;
-    wcstoumax;
+    wcstoull; # introduced=21
+    wcstoull_l; # introduced=21
+    wcstoumax; # introduced=21
     wcswidth;
     wcsxfrm;
-    wcsxfrm_l;
+    wcsxfrm_l; # introduced=21
     wctob;
-    wctomb;
+    wctomb; # introduced=21
     wctype;
-    wctype_l;
+    wctype_l; # introduced=21
     wcwidth;
     wmemchr;
     wmemcmp;
     wmemcpy;
     wmemmove;
-    wmempcpy;
+    wmempcpy; # introduced=23
     wmemset;
     wprintf;
     write;
@@ -1200,57 +1199,92 @@
     *;
 };
 
-LIBC_N {
+LIBC_N { # introduced-arm64=24 introduced-mips=24 introduced-mips64=24 introduced-x86=24 introduced-x86_64=24
   global:
-    __fread_chk;
-    __fwrite_chk;
-    __getcwd_chk;
-    __pwrite_chk;
-    __pwrite64_chk;
-    __write_chk;
-    adjtimex;
-    clock_adjtime;
-    fgetpos64;
-    fileno_unlocked;
-    fopen64;
-    freeifaddrs;
-    freopen64;
-    fseeko64;
-    fsetpos64;
-    ftello64;
-    funopen64;
-    getgrgid_r;
-    getgrnam_r;
-    getifaddrs;
-    if_freenameindex;
-    if_nameindex;
-    in6addr_any;
-    in6addr_loopback;
-    lockf;
-    lockf64;
-    preadv;
-    preadv64;
-    prlimit; # arm mips x86
-    pthread_barrierattr_destroy;
-    pthread_barrierattr_getpshared;
-    pthread_barrierattr_init;
-    pthread_barrierattr_setpshared;
-    pthread_barrier_destroy;
-    pthread_barrier_init;
-    pthread_barrier_wait;
-    pthread_spin_destroy;
-    pthread_spin_init;
-    pthread_spin_lock;
-    pthread_spin_trylock;
-    pthread_spin_unlock;
-    pwritev;
-    pwritev64;
-    scandirat;
-    scandirat64;
-    strchrnul;
-    tmpfile64;
+    __fread_chk; # introduced=24
+    __fwrite_chk; # introduced=24
+    __getcwd_chk; # introduced=24
+    __pwrite_chk; # introduced=24
+    __pwrite64_chk; # introduced=24
+    __write_chk; # introduced=24
+    adjtimex; # introduced=24
+    clock_adjtime; # introduced=24
+    fgetpos64; # introduced=24
+    fileno_unlocked; # introduced=24
+    fopen64; # introduced=24
+    freeifaddrs; # introduced=24
+    freopen64; # introduced=24
+    fseeko64; # introduced=24
+    fsetpos64; # introduced=24
+    ftello64; # introduced=24
+    funopen64; # introduced=24
+    getgrgid_r; # introduced=24
+    getgrnam_r; # introduced=24
+    getifaddrs; # introduced=24
+    if_freenameindex; # introduced=24
+    if_nameindex; # introduced=24
+    in6addr_any; # var introduced=24
+    in6addr_loopback; # var introduced=24
+    lockf; # introduced=24
+    lockf64; # introduced=24
+    preadv; # introduced=24
+    preadv64; # introduced=24
+    prlimit; # arm mips x86 introduced=24
+    pthread_barrierattr_destroy; # introduced=24
+    pthread_barrierattr_getpshared; # introduced=24
+    pthread_barrierattr_init; # introduced=24
+    pthread_barrierattr_setpshared; # introduced=24
+    pthread_barrier_destroy; # introduced=24
+    pthread_barrier_init; # introduced=24
+    pthread_barrier_wait; # introduced=24
+    pthread_spin_destroy; # introduced=24
+    pthread_spin_init; # introduced=24
+    pthread_spin_lock; # introduced=24
+    pthread_spin_trylock; # introduced=24
+    pthread_spin_unlock; # introduced=24
+    pwritev; # introduced=24
+    pwritev64; # introduced=24
+    scandirat; # introduced=24
+    scandirat64; # introduced=24
+    strchrnul; # introduced=24
+    tmpfile64; # introduced=24
 } LIBC;
 
+LIBC_O {
+  global:
+    bsd_signal; # arm x86 mips nobrillo versioned=26
+    catclose; # future
+    catgets; # future
+    catopen; # future
+    ctermid; # future
+    endgrent; # future
+    endpwent; # future
+    futimes; # future
+    futimesat; # future
+    getdomainname; # future
+    getgrent; # future
+    getpwent; # future
+    getsubopt; # future
+    hasmntopt; # future
+    lutimes; # future
+    mblen; # future
+    pthread_getname_np; # future
+    quotactl; # future
+    setdomainname; # future
+    setgrent; # future
+    setpwent; # future
+    sighold; # future
+    sigignore; # future
+    sigpause; # future
+    sigrelse; # future
+    sigset; # future
+    sync_file_range; # future
+    towctrans; # future
+    towctrans_l; # future
+    wctrans; # future
+    wctrans_l; # future
+} LIBC_N;
+
 LIBC_PRIVATE {
   global:
     __accept4; # arm x86 mips
@@ -1294,12 +1328,10 @@
     arc4random_stir; # arm x86 mips nobrillo
     bcopy; # arm x86 mips nobrillo
     bzero; # arm x86 mips nobrillo
-    bsd_signal; # arm x86 mips nobrillo
     dlmalloc; # arm x86 mips nobrillo
     dlmalloc_inspect_all; # arm x86 mips nobrillo
     dlmalloc_trim; # arm x86 mips nobrillo
     dlmalloc_usable_size; # arm x86 mips nobrillo
-    endpwent; # arm x86 mips nobrillo
     fdprintf; # arm x86 mips nobrillo
     free_malloc_leak_info;
     ftime; # arm x86 mips nobrillo
@@ -1324,7 +1356,7 @@
     vfdprintf; # arm x86 mips nobrillo
     wait3; # arm x86 mips nobrillo
     wcswcs; # arm x86 mips nobrillo
-} LIBC_N;
+} LIBC_O;
 
 LIBC_PLATFORM {
   global:
@@ -1335,4 +1367,4 @@
     malloc_disable;
     malloc_enable;
     malloc_iterate;
-} LIBC_N;
+} LIBC_O;
diff --git a/libc/libc.mips64.map b/libc/libc.mips64.map
index afbd0ee..f080340 100644
--- a/libc/libc.mips64.map
+++ b/libc/libc.mips64.map
@@ -1,39 +1,39 @@
-# Generated by genversionscripts.py. Do not edit.
+# Generated by genversion-scripts.py. Do not edit.
 LIBC {
   global:
     __assert;
     __assert2;
     __b64_ntop;
     __b64_pton;
-    __cmsg_nxthdr;
-    __ctype_get_mb_cur_max;
+    __cmsg_nxthdr; # introduced=21
+    __ctype_get_mb_cur_max; # introduced=21
     __cxa_atexit;
     __cxa_finalize;
-    __cxa_thread_atexit_impl;
+    __cxa_thread_atexit_impl; # introduced=23
     __dn_comp;
     __dn_count_labels;
     __dn_skipname;
     __errno;
-    __fbufsize;
-    __FD_CLR_chk;
-    __FD_ISSET_chk;
-    __FD_SET_chk;
-    __fgets_chk;
-    __flbf;
+    __fbufsize; # introduced=23
+    __FD_CLR_chk; # introduced=21
+    __FD_ISSET_chk; # introduced=21
+    __FD_SET_chk; # introduced=21
+    __fgets_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __flbf; # introduced=23
     __fp_nquery;
     __fp_query;
-    __fpclassify;
+    __fpclassify; # introduced=21
     __fpclassifyd;
     __fpclassifyf;
     __fpclassifyl;
-    __fpending;
-    __fpurge;
-    __freadable;
-    __fsetlocking;
-    __fwritable;
+    __fpending; # introduced=23
+    __fpurge; # introduced=23
+    __freadable; # introduced=23
+    __fsetlocking; # introduced=23
+    __fwritable; # introduced=23
     __get_h_errno;
-    __gnu_basename;
-    __gnu_strerror_r;
+    __gnu_basename; # introduced=23
+    __gnu_strerror_r; # introduced=23
     __hostalias;
     __isfinite;
     __isfinitef;
@@ -41,28 +41,28 @@
     __isinf;
     __isinff;
     __isinfl;
-    __isnan;
-    __isnanf;
+    __isnan; # introduced=21
+    __isnanf; # introduced=21
     __isnanl;
     __isnormal;
     __isnormalf;
     __isnormall;
-    __libc_current_sigrtmax;
-    __libc_current_sigrtmin;
+    __libc_current_sigrtmax; # introduced=21
+    __libc_current_sigrtmin; # introduced=21
     __libc_init;
     __loc_aton;
     __loc_ntoa;
-    __memchr_chk;
-    __memcpy_chk;
-    __memmove_chk;
-    __memrchr_chk;
-    __memset_chk;
-    __open_2;
-    __openat_2;
+    __memchr_chk; # introduced=23
+    __memcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __memmove_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __memrchr_chk; # introduced=23
+    __memset_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __open_2; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __openat_2; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __p_cdname;
     __p_cdnname;
     __p_class;
-    __p_class_syms;
+    __p_class_syms; # var
     __p_fqname;
     __p_fqnname;
     __p_option;
@@ -71,21 +71,21 @@
     __p_secstodate;
     __p_time;
     __p_type;
-    __p_type_syms;
-    __poll_chk;
-    __ppoll_chk;
-    __pread64_chk;
-    __pread_chk;
-    __progname;
+    __p_type_syms; # var
+    __poll_chk; # introduced=23
+    __ppoll_chk; # introduced=23
+    __pread64_chk; # introduced=23
+    __pread_chk; # introduced=23
+    __progname; # var
     __pthread_cleanup_pop;
     __pthread_cleanup_push;
     __putlong;
     __putshort;
-    __read_chk;
-    __readlink_chk;
-    __readlinkat_chk;
-    __recvfrom_chk;
-    __register_atfork;
+    __read_chk; # introduced=21
+    __readlink_chk; # introduced=23
+    __readlinkat_chk; # introduced=23
+    __recvfrom_chk; # introduced=21
+    __register_atfork; # introduced=23
     __res_close;
     __res_dnok;
     __res_hnok;
@@ -106,79 +106,79 @@
     __res_send;
     __res_send_setqhook;
     __res_send_setrhook;
-    __sched_cpualloc;
-    __sched_cpucount;
-    __sched_cpufree;
-    __sF;
-    __snprintf_chk;
-    __sprintf_chk;
+    __sched_cpualloc; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_cpucount; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_cpufree; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sF; # var
+    __snprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __sprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __stack_chk_fail;
-    __stack_chk_guard;
-    __stpcpy_chk;
-    __stpncpy_chk;
-    __stpncpy_chk2;
-    __strcat_chk;
-    __strchr_chk;
-    __strcpy_chk;
-    __strlcat_chk;
-    __strlcpy_chk;
-    __strlen_chk;
-    __strncat_chk;
-    __strncpy_chk;
-    __strncpy_chk2;
-    __strrchr_chk;
+    __stack_chk_guard; # var
+    __stpcpy_chk; # introduced=21
+    __stpncpy_chk; # introduced=21
+    __stpncpy_chk2; # introduced=21
+    __strcat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strchr_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
+    __strcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlcat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlen_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncpy_chk2; # introduced=21
+    __strrchr_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     __sym_ntop;
     __sym_ntos;
     __sym_ston;
     __system_properties_init;
-    __system_property_add;
-    __system_property_area__;
-    __system_property_area_init;
-    __system_property_area_serial;
+    __system_property_add; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_area__; # var
+    __system_property_area_init; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_area_serial; # introduced=23
     __system_property_find;
     __system_property_find_nth;
-    __system_property_foreach;
+    __system_property_foreach; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     __system_property_get;
     __system_property_read;
-    __system_property_serial;
-    __system_property_set;
-    __system_property_set_filename;
-    __system_property_update;
-    __system_property_wait_any;
-    __umask_chk;
-    __vsnprintf_chk;
-    __vsprintf_chk;
-    _ctype_;
-    _Exit;
+    __system_property_serial; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_set; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __system_property_set_filename; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_update; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_wait_any; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __umask_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
+    __vsnprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __vsprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    _ctype_; # var
+    _Exit; # introduced=21
     _exit;
-    _flushlbf;
+    _flushlbf; # introduced=23
     _getlong;
     _getshort;
     _longjmp;
-    _resolv_delete_cache_for_net;
-    _resolv_flush_cache_for_net;
-    _resolv_set_nameservers_for_net;
+    _resolv_delete_cache_for_net; # introduced=21
+    _resolv_flush_cache_for_net; # introduced=21
+    _resolv_set_nameservers_for_net; # introduced=21
     _setjmp;
-    _tolower;
-    _toupper;
+    _tolower; # introduced=21
+    _toupper; # introduced=21
     abort;
-    abs;
+    abs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     accept;
-    accept4;
+    accept4; # introduced=21
     access;
     acct;
     alarm;
     alphasort;
-    alphasort64;
-    android_set_abort_message;
+    alphasort64; # introduced=21
+    android_set_abort_message; # introduced=21
     arc4random;
     arc4random_buf;
     arc4random_uniform;
     asctime;
     asctime_r;
     asprintf;
-    at_quick_exit;
-    atof;
+    at_quick_exit; # introduced=21
+    atof; # introduced=21
     atoi;
     atol;
     atoll;
@@ -188,74 +188,74 @@
     brk;
     bsearch;
     btowc;
-    c16rtomb;
-    c32rtomb;
+    c16rtomb; # introduced=21
+    c32rtomb; # introduced=21
     calloc;
     capget;
     capset;
-    cfgetispeed;
-    cfgetospeed;
-    cfmakeraw;
-    cfsetispeed;
-    cfsetospeed;
-    cfsetspeed;
+    cfgetispeed; # introduced=21
+    cfgetospeed; # introduced=21
+    cfmakeraw; # introduced=21
+    cfsetispeed; # introduced=21
+    cfsetospeed; # introduced=21
+    cfsetspeed; # introduced=21
     chdir;
     chmod;
     chown;
     chroot;
     clearenv;
     clearerr;
-    clearerr_unlocked;
+    clearerr_unlocked; # introduced=23
     clock;
-    clock_getcpuclockid;
+    clock_getcpuclockid; # introduced=23
     clock_getres;
     clock_gettime;
     clock_nanosleep;
     clock_settime;
-    clone;
+    clone; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     close;
     closedir;
     closelog;
     connect;
     creat;
-    creat64;
+    creat64; # introduced=21
     ctime;
     ctime_r;
     daemon;
-    daylight;
+    daylight; # var
     delete_module;
     difftime;
     dirfd;
     dirname;
     div;
     dn_expand;
-    dprintf;
+    dprintf; # introduced=21
     drand48;
     dup;
     dup2;
-    dup3;
-    duplocale;
-    endmntent;
+    dup3; # introduced=21
+    duplocale; # introduced=21
+    endmntent; # introduced=21
     endservent;
     endutent;
-    environ;
+    environ; # var
     epoll_create;
-    epoll_create1;
+    epoll_create1; # introduced=21
     epoll_ctl;
-    epoll_pwait;
+    epoll_pwait; # introduced=21
     epoll_wait;
     erand48;
     err;
-    error;
-    error_at_line;
-    error_message_count;
-    error_one_per_line;
-    error_print_progname;
+    error; # introduced=23
+    error_at_line; # introduced=23
+    error_message_count; # var introduced=23
+    error_one_per_line; # var introduced=23
+    error_print_progname; # var introduced=23
     errx;
-    ether_aton;
-    ether_aton_r;
-    ether_ntoa;
-    ether_ntoa_r;
+    ether_aton; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_aton_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_ntoa; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_ntoa_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     eventfd;
     eventfd_read;
     eventfd_write;
@@ -265,11 +265,11 @@
     execv;
     execve;
     execvp;
-    execvpe;
+    execvpe; # introduced=21
     exit;
-    faccessat;
-    fallocate;
-    fallocate64;
+    faccessat; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    fallocate; # introduced=21
+    fallocate64; # introduced=21
     fchdir;
     fchmod;
     fchmodat;
@@ -281,27 +281,27 @@
     fdopen;
     fdopendir;
     feof;
-    feof_unlocked;
+    feof_unlocked; # introduced=23
     ferror;
-    ferror_unlocked;
+    ferror_unlocked; # introduced=23
     fflush;
-    ffs;
+    ffs; # introduced-arm=9 introduced-arm64=21 introduced-mips=9 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     fgetc;
     fgetln;
     fgetpos;
     fgets;
     fgetwc;
     fgetws;
-    fgetxattr;
+    fgetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     fileno;
-    flistxattr;
+    flistxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     flock;
     flockfile;
-    fmemopen;
+    fmemopen; # introduced=23
     fnmatch;
     fopen;
     fork;
-    forkpty;
+    forkpty; # introduced=23
     fpathconf;
     fprintf;
     fpurge;
@@ -312,56 +312,56 @@
     fread;
     free;
     freeaddrinfo;
-    freelocale;
-    fremovexattr;
+    freelocale; # introduced=21
+    fremovexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     freopen;
     fscanf;
     fseek;
     fseeko;
     fsetpos;
-    fsetxattr;
+    fsetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     fstat;
-    fstat64;
+    fstat64; # introduced=21
     fstatat;
-    fstatat64;
+    fstatat64; # introduced=21
     fstatfs;
-    fstatfs64;
-    fstatvfs;
-    fstatvfs64;
+    fstatfs64; # introduced=21
+    fstatvfs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    fstatvfs64; # introduced=21
     fsync;
     ftell;
     ftello;
     ftok;
     ftruncate;
-    ftruncate64;
+    ftruncate64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     ftrylockfile;
     fts_children;
     fts_close;
     fts_open;
     fts_read;
     fts_set;
-    ftw;
-    ftw64;
+    ftw; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    ftw64; # introduced=21
     funlockfile;
     funopen;
-    futimens;
+    futimens; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     fwide;
     fwprintf;
     fwrite;
     fwscanf;
     gai_strerror;
-    get_avphys_pages;
-    get_nprocs;
-    get_nprocs_conf;
-    get_phys_pages;
+    get_avphys_pages; # introduced=23
+    get_nprocs; # introduced=23
+    get_nprocs_conf; # introduced=23
+    get_phys_pages; # introduced=23
     getaddrinfo;
-    getauxval;
+    getauxval; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getc;
     getc_unlocked;
     getchar;
     getchar_unlocked;
     getcwd;
-    getdelim;
+    getdelim; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getegid;
     getenv;
     geteuid;
@@ -371,49 +371,49 @@
     getgrouplist;
     getgroups;
     gethostbyaddr;
-    gethostbyaddr_r;
+    gethostbyaddr_r; # introduced=23
     gethostbyname;
     gethostbyname2;
-    gethostbyname2_r;
+    gethostbyname2_r; # introduced=23
     gethostbyname_r;
     gethostent;
     gethostname;
     getitimer;
-    getline;
+    getline; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getlogin;
     getmntent;
-    getmntent_r;
+    getmntent_r; # introduced=21
     getnameinfo;
     getnetbyaddr;
     getnetbyname;
     getopt;
     getopt_long;
     getopt_long_only;
-    getpagesize;
+    getpagesize; # introduced=21
     getpeername;
     getpgid;
     getpgrp;
     getpid;
     getppid;
     getpriority;
-    getprogname;
+    getprogname; # introduced=21
     getprotobyname;
     getprotobynumber;
     getpt;
     getpwnam;
-    getpwnam_r;
+    getpwnam_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     getpwuid;
-    getpwuid_r;
+    getpwuid_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     getresgid;
     getresuid;
     getrlimit;
-    getrlimit64;
+    getrlimit64; # introduced=21
     getrusage;
     gets;
     getservbyname;
     getservbyport;
     getservent;
-    getsid;
+    getsid; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     getsockname;
     getsockopt;
     gettid;
@@ -422,24 +422,24 @@
     getutent;
     getwc;
     getwchar;
-    getxattr;
+    getxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     gmtime;
     gmtime_r;
-    grantpt;
+    grantpt; # introduced=21
     herror;
     hstrerror;
-    htonl;
-    htons;
+    htonl; # introduced=21
+    htons; # introduced=21
     if_indextoname;
     if_nametoindex;
-    imaxabs;
-    imaxdiv;
+    imaxabs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    imaxdiv; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     inet_addr;
     inet_aton;
-    inet_lnaof;
-    inet_makeaddr;
-    inet_netof;
-    inet_network;
+    inet_lnaof; # introduced=21
+    inet_makeaddr; # introduced=21
+    inet_netof; # introduced=21
+    inet_network; # introduced=21
     inet_nsap_addr;
     inet_nsap_ntoa;
     inet_ntoa;
@@ -447,122 +447,122 @@
     inet_pton;
     init_module;
     initgroups;
-    initstate;
+    initstate; # introduced=21
     inotify_add_watch;
     inotify_init;
-    inotify_init1;
+    inotify_init1; # introduced=21
     inotify_rm_watch;
-    insque;
+    insque; # introduced=21
     ioctl;
     isalnum;
-    isalnum_l;
+    isalnum_l; # introduced=21
     isalpha;
-    isalpha_l;
+    isalpha_l; # introduced=21
     isascii;
     isatty;
     isblank;
-    isblank_l;
+    isblank_l; # introduced=21
     iscntrl;
-    iscntrl_l;
+    iscntrl_l; # introduced=21
     isdigit;
-    isdigit_l;
-    isfinite;
-    isfinitef;
-    isfinitel;
+    isdigit_l; # introduced=21
+    isfinite; # introduced=21
+    isfinitef; # introduced=21
+    isfinitel; # introduced=21
     isgraph;
-    isgraph_l;
-    isinf;
-    isinff;
-    isinfl;
+    isgraph_l; # introduced=21
+    isinf; # introduced=21
+    isinff; # introduced=21
+    isinfl; # introduced=21
     islower;
-    islower_l;
+    islower_l; # introduced=21
     isnan;
     isnanf;
-    isnanl;
-    isnormal;
-    isnormalf;
-    isnormall;
+    isnanl; # introduced=21
+    isnormal; # introduced=21
+    isnormalf; # introduced=21
+    isnormall; # introduced=21
     isprint;
-    isprint_l;
+    isprint_l; # introduced=21
     ispunct;
-    ispunct_l;
+    ispunct_l; # introduced=21
     isspace;
-    isspace_l;
+    isspace_l; # introduced=21
     isupper;
-    isupper_l;
+    isupper_l; # introduced=21
     iswalnum;
-    iswalnum_l;
+    iswalnum_l; # introduced=21
     iswalpha;
-    iswalpha_l;
-    iswblank;
-    iswblank_l;
+    iswalpha_l; # introduced=21
+    iswblank; # introduced=21
+    iswblank_l; # introduced=21
     iswcntrl;
-    iswcntrl_l;
+    iswcntrl_l; # introduced=21
     iswctype;
-    iswctype_l;
+    iswctype_l; # introduced=21
     iswdigit;
-    iswdigit_l;
+    iswdigit_l; # introduced=21
     iswgraph;
-    iswgraph_l;
+    iswgraph_l; # introduced=21
     iswlower;
-    iswlower_l;
+    iswlower_l; # introduced=21
     iswprint;
-    iswprint_l;
+    iswprint_l; # introduced=21
     iswpunct;
-    iswpunct_l;
+    iswpunct_l; # introduced=21
     iswspace;
-    iswspace_l;
+    iswspace_l; # introduced=21
     iswupper;
-    iswupper_l;
+    iswupper_l; # introduced=21
     iswxdigit;
-    iswxdigit_l;
+    iswxdigit_l; # introduced=21
     isxdigit;
-    isxdigit_l;
+    isxdigit_l; # introduced=21
     jrand48;
     kill;
     killpg;
     klogctl;
-    labs;
+    labs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     lchown;
-    lcong48;
+    lcong48; # introduced=23
     ldexp;
     ldiv;
-    lfind;
-    lgetxattr;
+    lfind; # introduced=21
+    lgetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     link;
-    linkat;
+    linkat; # introduced=21
     listen;
-    listxattr;
-    llabs;
+    listxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    llabs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     lldiv;
-    llistxattr;
-    localeconv;
+    llistxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    localeconv; # introduced=21
     localtime;
     localtime_r;
-    login_tty;
+    login_tty; # introduced=23
     longjmp;
     lrand48;
-    lremovexattr;
-    lsearch;
+    lremovexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    lsearch; # introduced=21
     lseek;
     lseek64;
-    lsetxattr;
+    lsetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     lstat;
-    lstat64;
+    lstat64; # introduced=21
     madvise;
     mallinfo;
     malloc;
-    malloc_info;
-    malloc_usable_size;
+    malloc_info; # introduced=23
+    malloc_usable_size; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     mbrlen;
-    mbrtoc16;
-    mbrtoc32;
+    mbrtoc16; # introduced=21
+    mbrtoc32; # introduced=21
     mbrtowc;
     mbsinit;
-    mbsnrtowcs;
+    mbsnrtowcs; # introduced=21
     mbsrtowcs;
     mbstowcs;
-    mbtowc;
+    mbtowc; # introduced=21
     memalign;
     memccpy;
     memchr;
@@ -570,113 +570,113 @@
     memcpy;
     memmem;
     memmove;
-    mempcpy;
+    mempcpy; # introduced=23
     memrchr;
     memset;
     mincore;
     mkdir;
     mkdirat;
     mkdtemp;
-    mkfifo;
-    mkfifoat;
+    mkfifo; # introduced=21
+    mkfifoat; # introduced=23
     mknod;
-    mknodat;
-    mkostemp;
-    mkostemp64;
-    mkostemps;
-    mkostemps64;
+    mknodat; # introduced=21
+    mkostemp; # introduced=23
+    mkostemp64; # introduced=23
+    mkostemps; # introduced=23
+    mkostemps64; # introduced=23
     mkstemp;
-    mkstemp64;
+    mkstemp64; # introduced=21
     mkstemps;
-    mkstemps64;
+    mkstemps64; # introduced=23
     mktemp;
     mktime;
     mlock;
-    mlockall;
+    mlockall; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     mmap;
-    mmap64;
+    mmap64; # introduced=21
     mount;
     mprotect;
     mrand48;
     mremap;
     msync;
     munlock;
-    munlockall;
+    munlockall; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     munmap;
     nanosleep;
-    newlocale;
-    nftw;
-    nftw64;
+    newlocale; # introduced=21
+    nftw; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    nftw64; # introduced=21
     nice;
     nrand48;
-    ns_format_ttl; # arm64 x86_64 mips64
-    ns_get16; # arm64 x86_64 mips64
-    ns_get32; # arm64 x86_64 mips64
-    ns_initparse; # arm64 x86_64 mips64
-    ns_makecanon; # arm64 x86_64 mips64
-    ns_msg_getflag; # arm64 x86_64 mips64
-    ns_name_compress; # arm64 x86_64 mips64
-    ns_name_ntol; # arm64 x86_64 mips64
-    ns_name_ntop; # arm64 x86_64 mips64
-    ns_name_pack; # arm64 x86_64 mips64
-    ns_name_pton; # arm64 x86_64 mips64
-    ns_name_rollback; # arm64 x86_64 mips64
-    ns_name_skip; # arm64 x86_64 mips64
-    ns_name_uncompress; # arm64 x86_64 mips64
-    ns_name_unpack; # arm64 x86_64 mips64
-    ns_parserr; # arm64 x86_64 mips64
-    ns_put16; # arm64 x86_64 mips64
-    ns_put32; # arm64 x86_64 mips64
-    ns_samename; # arm64 x86_64 mips64
-    ns_skiprr; # arm64 x86_64 mips64
-    ns_sprintrr; # arm64 x86_64 mips64
-    ns_sprintrrf; # arm64 x86_64 mips64
+    ns_format_ttl; # arm64 x86_64 mips64 introduced=22
+    ns_get16; # arm64 x86_64 mips64 introduced=22
+    ns_get32; # arm64 x86_64 mips64 introduced=22
+    ns_initparse; # arm64 x86_64 mips64 introduced=22
+    ns_makecanon; # arm64 x86_64 mips64 introduced=22
+    ns_msg_getflag; # arm64 x86_64 mips64 introduced=22
+    ns_name_compress; # arm64 x86_64 mips64 introduced=22
+    ns_name_ntol; # arm64 x86_64 mips64 introduced=22
+    ns_name_ntop; # arm64 x86_64 mips64 introduced=22
+    ns_name_pack; # arm64 x86_64 mips64 introduced=22
+    ns_name_pton; # arm64 x86_64 mips64 introduced=23
+    ns_name_rollback; # arm64 x86_64 mips64 introduced=22
+    ns_name_skip; # arm64 x86_64 mips64 introduced=22
+    ns_name_uncompress; # arm64 x86_64 mips64 introduced=22
+    ns_name_unpack; # arm64 x86_64 mips64 introduced=22
+    ns_parserr; # arm64 x86_64 mips64 introduced=22
+    ns_put16; # arm64 x86_64 mips64 introduced=22
+    ns_put32; # arm64 x86_64 mips64 introduced=22
+    ns_samename; # arm64 x86_64 mips64 introduced=22
+    ns_skiprr; # arm64 x86_64 mips64 introduced=22
+    ns_sprintrr; # arm64 x86_64 mips64 introduced=22
+    ns_sprintrrf; # arm64 x86_64 mips64 introduced=22
     nsdispatch;
-    ntohl;
-    ntohs;
+    ntohl; # introduced=21
+    ntohs; # introduced=21
     open;
-    open64;
-    open_memstream;
-    open_wmemstream;
+    open64; # introduced=21
+    open_memstream; # introduced=23
+    open_wmemstream; # introduced=23
     openat;
-    openat64;
+    openat64; # introduced=21
     opendir;
     openlog;
-    openpty;
-    optarg;
-    opterr;
-    optind;
-    optopt;
-    optreset;
+    openpty; # introduced=23
+    optarg; # var
+    opterr; # var
+    optind; # var
+    optopt; # var
+    optreset; # var
     pathconf;
     pause;
     pclose;
     perror;
-    personality;
+    personality; # introduced-arm=15 introduced-arm64=21 introduced-mips=15 introduced-mips64=21 introduced-x86=15 introduced-x86_64=21
     pipe;
     pipe2;
     poll;
     popen;
-    posix_fadvise;
-    posix_fadvise64;
-    posix_fallocate;
-    posix_fallocate64;
-    posix_madvise;
-    posix_memalign;
-    posix_openpt;
-    ppoll;
+    posix_fadvise; # introduced=21
+    posix_fadvise64; # introduced=21
+    posix_fallocate; # introduced=21
+    posix_fallocate64; # introduced=21
+    posix_madvise; # introduced=23
+    posix_memalign; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    posix_openpt; # introduced=21
+    ppoll; # introduced=21
     prctl;
     pread;
-    pread64;
+    pread64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     printf;
     prlimit; # arm64 x86_64 mips64
-    prlimit64;
-    process_vm_readv;
-    process_vm_writev;
+    prlimit64; # introduced=21
+    process_vm_readv; # introduced=23
+    process_vm_writev; # introduced=23
     pselect;
-    psiginfo;
-    psignal;
-    pthread_atfork;
+    psiginfo; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    psignal; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    pthread_atfork; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     pthread_attr_destroy;
     pthread_attr_getdetachstate;
     pthread_attr_getguardsize;
@@ -700,10 +700,10 @@
     pthread_cond_timedwait;
     pthread_cond_wait;
     pthread_condattr_destroy;
-    pthread_condattr_getclock;
+    pthread_condattr_getclock; # introduced=21
     pthread_condattr_getpshared;
     pthread_condattr_init;
-    pthread_condattr_setclock;
+    pthread_condattr_setclock; # introduced=21
     pthread_condattr_setpshared;
     pthread_create;
     pthread_detach;
@@ -713,7 +713,7 @@
     pthread_getcpuclockid;
     pthread_getschedparam;
     pthread_getspecific;
-    pthread_gettid_np;
+    pthread_gettid_np; # introduced=21
     pthread_join;
     pthread_key_create;
     pthread_key_delete;
@@ -721,7 +721,7 @@
     pthread_mutex_destroy;
     pthread_mutex_init;
     pthread_mutex_lock;
-    pthread_mutex_timedlock;
+    pthread_mutex_timedlock; # introduced=21
     pthread_mutex_trylock;
     pthread_mutex_unlock;
     pthread_mutexattr_destroy;
@@ -741,10 +741,10 @@
     pthread_rwlock_unlock;
     pthread_rwlock_wrlock;
     pthread_rwlockattr_destroy;
-    pthread_rwlockattr_getkind_np;
+    pthread_rwlockattr_getkind_np; # introduced=23
     pthread_rwlockattr_getpshared;
     pthread_rwlockattr_init;
-    pthread_rwlockattr_setkind_np;
+    pthread_rwlockattr_setkind_np; # introduced=23
     pthread_rwlockattr_setpshared;
     pthread_self;
     pthread_setname_np;
@@ -764,36 +764,36 @@
     putwc;
     putwchar;
     pwrite;
-    pwrite64;
+    pwrite64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     qsort;
-    quick_exit;
+    quick_exit; # introduced=21
     raise;
-    rand;
-    rand_r;
-    random;
+    rand; # introduced=21
+    rand_r; # introduced=21
+    random; # introduced=21
     read;
-    readahead;
+    readahead; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     readdir;
-    readdir64;
-    readdir64_r;
+    readdir64; # introduced=21
+    readdir64_r; # introduced=21
     readdir_r;
     readlink;
-    readlinkat;
+    readlinkat; # introduced=21
     readv;
     realloc;
     realpath;
     reboot;
     recv;
     recvfrom;
-    recvmmsg;
+    recvmmsg; # introduced=21
     recvmsg;
     regcomp;
     regerror;
     regexec;
     regfree;
     remove;
-    removexattr;
-    remque;
+    removexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    remque; # introduced=21
     rename;
     renameat;
     res_init;
@@ -805,21 +805,21 @@
     rmdir;
     sbrk;
     scandir;
-    scandir64;
+    scandir64; # introduced=21
     scanf;
     sched_get_priority_max;
     sched_get_priority_min;
-    sched_getaffinity;
-    sched_getcpu;
+    sched_getaffinity; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    sched_getcpu; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sched_getparam;
     sched_getscheduler;
     sched_rr_get_interval;
-    sched_setaffinity;
+    sched_setaffinity; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sched_setparam;
     sched_setscheduler;
     sched_yield;
     seed48;
-    seekdir;
+    seekdir; # introduced=23
     select;
     sem_close;
     sem_destroy;
@@ -833,8 +833,8 @@
     sem_wait;
     send;
     sendfile;
-    sendfile64;
-    sendmmsg;
+    sendfile64; # introduced=21
+    sendmmsg; # introduced=21
     sendmsg;
     sendto;
     setbuf;
@@ -842,101 +842,101 @@
     setegid;
     setenv;
     seteuid;
-    setfsgid;
-    setfsuid;
+    setfsgid; # introduced=21
+    setfsuid; # introduced=21
     setgid;
     setgroups;
-    sethostname;
+    sethostname; # introduced=23
     setitimer;
     setjmp;
     setlinebuf;
     setlocale;
     setlogmask;
-    setmntent;
-    setns;
+    setmntent; # introduced=21
+    setns; # introduced=21
     setpgid;
     setpgrp;
     setpriority;
-    setprogname;
+    setprogname; # introduced=21
     setregid;
     setresgid;
     setresuid;
     setreuid;
     setrlimit;
-    setrlimit64;
+    setrlimit64; # introduced=21
     setservent;
     setsid;
     setsockopt;
-    setstate;
+    setstate; # introduced=21
     settimeofday;
     setuid;
     setutent;
     setvbuf;
-    setxattr;
+    setxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     shutdown;
     sigaction;
-    sigaddset;
+    sigaddset; # introduced=21
     sigaltstack;
     sigblock;
-    sigdelset;
-    sigemptyset;
-    sigfillset;
+    sigdelset; # introduced=21
+    sigemptyset; # introduced=21
+    sigfillset; # introduced=21
     siginterrupt;
-    sigismember;
-    siglongjmp;
-    signal;
-    signalfd;
+    sigismember; # introduced=21
+    siglongjmp; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    signal; # introduced=21
+    signalfd; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     sigpending;
     sigprocmask;
-    sigqueue;
-    sigsetjmp;
+    sigqueue; # introduced=23
+    sigsetjmp; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sigsetmask;
     sigsuspend;
-    sigtimedwait;
+    sigtimedwait; # introduced=23
     sigwait;
-    sigwaitinfo;
+    sigwaitinfo; # introduced=23
     sleep;
     snprintf;
     socket;
     socketpair;
-    splice;
+    splice; # introduced=21
     sprintf;
-    srand;
+    srand; # introduced=21
     srand48;
-    srandom;
+    srandom; # introduced=21
     sscanf;
     stat;
-    stat64;
+    stat64; # introduced=21
     statfs;
-    statfs64;
-    statvfs;
-    statvfs64;
-    stderr;
-    stdin;
-    stdout;
-    stpcpy;
-    stpncpy;
+    statfs64; # introduced=21
+    statvfs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    statvfs64; # introduced=21
+    stderr; # var introduced=23
+    stdin; # var introduced=23
+    stdout; # var introduced=23
+    stpcpy; # introduced=21
+    stpncpy; # introduced=21
     strcasecmp;
-    strcasecmp_l;
+    strcasecmp_l; # introduced=23
     strcasestr;
     strcat;
     strchr;
     strcmp;
     strcoll;
-    strcoll_l;
+    strcoll_l; # introduced=21
     strcpy;
     strcspn;
     strdup;
     strerror;
-    strerror_l;
+    strerror_l; # introduced=23
     strerror_r;
     strftime;
-    strftime_l;
+    strftime_l; # introduced=21
     strlcat;
     strlcpy;
     strlen;
     strncasecmp;
-    strncasecmp_l;
+    strncasecmp_l; # introduced=23
     strncat;
     strncmp;
     strncpy;
@@ -950,84 +950,84 @@
     strspn;
     strstr;
     strtod;
-    strtof;
+    strtof; # introduced=21
     strtoimax;
     strtok;
     strtok_r;
     strtol;
-    strtold;
-    strtold_l;
+    strtold; # introduced=21
+    strtold_l; # introduced=21
     strtoll;
-    strtoll_l;
-    strtoq;
+    strtoll_l; # introduced=21
+    strtoq; # introduced=21
     strtoul;
     strtoull;
-    strtoull_l;
+    strtoull_l; # introduced=21
     strtoumax;
-    strtouq;
+    strtouq; # introduced=21
     strxfrm;
-    strxfrm_l;
-    swapoff;
-    swapon;
+    strxfrm_l; # introduced=21
+    swapoff; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    swapon; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     swprintf;
     swscanf;
     symlink;
-    symlinkat;
+    symlinkat; # introduced=21
     sync;
-    sys_siglist;
-    sys_signame;
+    sys_siglist; # var
+    sys_signame; # var
     syscall;
     sysconf;
     sysinfo;
     syslog;
     system;
-    tcdrain;
-    tcflow;
-    tcflush;
-    tcgetattr;
+    tcdrain; # introduced=21
+    tcflow; # introduced=21
+    tcflush; # introduced=21
+    tcgetattr; # introduced=21
     tcgetpgrp;
-    tcgetsid;
-    tcsendbreak;
-    tcsetattr;
+    tcgetsid; # introduced=21
+    tcsendbreak; # introduced=21
+    tcsetattr; # introduced=21
     tcsetpgrp;
-    tdelete;
-    tdestroy;
-    tee;
-    telldir;
+    tdelete; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tdestroy; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tee; # introduced=21
+    telldir; # introduced=23
     tempnam;
-    tfind;
-    tgkill;
+    tfind; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tgkill; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     time;
-    timegm;
-    timelocal;
+    timegm; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    timelocal; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     timer_create;
     timer_delete;
     timer_getoverrun;
     timer_gettime;
     timer_settime;
-    timerfd_create;
-    timerfd_gettime;
-    timerfd_settime;
+    timerfd_create; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    timerfd_gettime; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    timerfd_settime; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     times;
-    timezone;
+    timezone; # var
     tmpfile;
     tmpnam;
     toascii;
     tolower;
-    tolower_l;
+    tolower_l; # introduced=21
     toupper;
-    toupper_l;
+    toupper_l; # introduced=21
     towlower;
-    towlower_l;
+    towlower_l; # introduced=21
     towupper;
-    towupper_l;
+    towupper_l; # introduced=21
     truncate;
-    truncate64;
-    tsearch;
+    truncate64; # introduced=21
+    tsearch; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     ttyname;
     ttyname_r;
-    twalk;
-    tzname;
+    twalk; # introduced=21
+    tzname; # var
     tzset;
     umask;
     umount;
@@ -1039,37 +1039,37 @@
     unlinkat;
     unlockpt;
     unsetenv;
-    unshare;
-    uselocale;
+    unshare; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    uselocale; # introduced=21
     usleep;
     utime;
-    utimensat;
+    utimensat; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     utimes;
     utmpname;
     vasprintf;
-    vdprintf;
+    vdprintf; # introduced=21
     verr;
     verrx;
     vfork;
     vfprintf;
     vfscanf;
     vfwprintf;
-    vfwscanf;
-    vmsplice;
+    vfwscanf; # introduced=21
+    vmsplice; # introduced=21
     vprintf;
     vscanf;
     vsnprintf;
     vsprintf;
     vsscanf;
     vswprintf;
-    vswscanf;
+    vswscanf; # introduced=21
     vsyslog;
     vwarn;
     vwarnx;
     vwprintf;
-    vwscanf;
+    vwscanf; # introduced=21
     wait;
-    wait4;
+    wait4; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     waitid;
     waitpid;
     warn;
@@ -1078,12 +1078,12 @@
     wcpncpy;
     wcrtomb;
     wcscasecmp;
-    wcscasecmp_l;
+    wcscasecmp_l; # introduced=23
     wcscat;
     wcschr;
     wcscmp;
     wcscoll;
-    wcscoll_l;
+    wcscoll_l; # introduced=21
     wcscpy;
     wcscspn;
     wcsdup;
@@ -1092,44 +1092,44 @@
     wcslcpy;
     wcslen;
     wcsncasecmp;
-    wcsncasecmp_l;
+    wcsncasecmp_l; # introduced=23
     wcsncat;
     wcsncmp;
     wcsncpy;
     wcsnlen;
-    wcsnrtombs;
+    wcsnrtombs; # introduced=21
     wcspbrk;
     wcsrchr;
     wcsrtombs;
     wcsspn;
     wcsstr;
     wcstod;
-    wcstof;
-    wcstoimax;
+    wcstof; # introduced=21
+    wcstoimax; # introduced=21
     wcstok;
     wcstol;
-    wcstold;
-    wcstold_l;
-    wcstoll;
-    wcstoll_l;
+    wcstold; # introduced=21
+    wcstold_l; # introduced=21
+    wcstoll; # introduced=21
+    wcstoll_l; # introduced=21
     wcstombs;
     wcstoul;
-    wcstoull;
-    wcstoull_l;
-    wcstoumax;
+    wcstoull; # introduced=21
+    wcstoull_l; # introduced=21
+    wcstoumax; # introduced=21
     wcswidth;
     wcsxfrm;
-    wcsxfrm_l;
+    wcsxfrm_l; # introduced=21
     wctob;
-    wctomb;
+    wctomb; # introduced=21
     wctype;
-    wctype_l;
+    wctype_l; # introduced=21
     wcwidth;
     wmemchr;
     wmemcmp;
     wmemcpy;
     wmemmove;
-    wmempcpy;
+    wmempcpy; # introduced=23
     wmemset;
     wprintf;
     write;
@@ -1139,56 +1139,90 @@
     *;
 };
 
-LIBC_N {
+LIBC_N { # introduced-arm64=24 introduced-mips=24 introduced-mips64=24 introduced-x86=24 introduced-x86_64=24
   global:
-    __fread_chk;
-    __fwrite_chk;
-    __getcwd_chk;
-    __pwrite_chk;
-    __pwrite64_chk;
-    __write_chk;
-    adjtimex;
-    clock_adjtime;
-    fgetpos64;
-    fileno_unlocked;
-    fopen64;
-    freeifaddrs;
-    freopen64;
-    fseeko64;
-    fsetpos64;
-    ftello64;
-    funopen64;
-    getgrgid_r;
-    getgrnam_r;
-    getifaddrs;
-    if_freenameindex;
-    if_nameindex;
-    in6addr_any;
-    in6addr_loopback;
-    lockf;
-    lockf64;
-    preadv;
-    preadv64;
-    pthread_barrierattr_destroy;
-    pthread_barrierattr_getpshared;
-    pthread_barrierattr_init;
-    pthread_barrierattr_setpshared;
-    pthread_barrier_destroy;
-    pthread_barrier_init;
-    pthread_barrier_wait;
-    pthread_spin_destroy;
-    pthread_spin_init;
-    pthread_spin_lock;
-    pthread_spin_trylock;
-    pthread_spin_unlock;
-    pwritev;
-    pwritev64;
-    scandirat;
-    scandirat64;
-    strchrnul;
-    tmpfile64;
+    __fread_chk; # introduced=24
+    __fwrite_chk; # introduced=24
+    __getcwd_chk; # introduced=24
+    __pwrite_chk; # introduced=24
+    __pwrite64_chk; # introduced=24
+    __write_chk; # introduced=24
+    adjtimex; # introduced=24
+    clock_adjtime; # introduced=24
+    fgetpos64; # introduced=24
+    fileno_unlocked; # introduced=24
+    fopen64; # introduced=24
+    freeifaddrs; # introduced=24
+    freopen64; # introduced=24
+    fseeko64; # introduced=24
+    fsetpos64; # introduced=24
+    ftello64; # introduced=24
+    funopen64; # introduced=24
+    getgrgid_r; # introduced=24
+    getgrnam_r; # introduced=24
+    getifaddrs; # introduced=24
+    if_freenameindex; # introduced=24
+    if_nameindex; # introduced=24
+    in6addr_any; # var introduced=24
+    in6addr_loopback; # var introduced=24
+    lockf; # introduced=24
+    lockf64; # introduced=24
+    preadv; # introduced=24
+    preadv64; # introduced=24
+    pthread_barrierattr_destroy; # introduced=24
+    pthread_barrierattr_getpshared; # introduced=24
+    pthread_barrierattr_init; # introduced=24
+    pthread_barrierattr_setpshared; # introduced=24
+    pthread_barrier_destroy; # introduced=24
+    pthread_barrier_init; # introduced=24
+    pthread_barrier_wait; # introduced=24
+    pthread_spin_destroy; # introduced=24
+    pthread_spin_init; # introduced=24
+    pthread_spin_lock; # introduced=24
+    pthread_spin_trylock; # introduced=24
+    pthread_spin_unlock; # introduced=24
+    pwritev; # introduced=24
+    pwritev64; # introduced=24
+    scandirat; # introduced=24
+    scandirat64; # introduced=24
+    strchrnul; # introduced=24
+    tmpfile64; # introduced=24
 } LIBC;
 
+LIBC_O {
+  global:
+    catclose; # future
+    catgets; # future
+    catopen; # future
+    ctermid; # future
+    endgrent; # future
+    endpwent; # future
+    futimes; # future
+    futimesat; # future
+    getdomainname; # future
+    getgrent; # future
+    getpwent; # future
+    getsubopt; # future
+    hasmntopt; # future
+    lutimes; # future
+    mblen; # future
+    pthread_getname_np; # future
+    quotactl; # future
+    setdomainname; # future
+    setgrent; # future
+    setpwent; # future
+    sighold; # future
+    sigignore; # future
+    sigpause; # future
+    sigrelse; # future
+    sigset; # future
+    sync_file_range; # future
+    towctrans; # future
+    towctrans_l; # future
+    wctrans; # future
+    wctrans_l; # future
+} LIBC_N;
+
 LIBC_PRIVATE {
   global:
     android_getaddrinfofornet;
@@ -1198,7 +1232,7 @@
     free_malloc_leak_info;
     get_malloc_leak_info;
     gMallocLeakZygoteChild;
-} LIBC_N;
+} LIBC_O;
 
 LIBC_PLATFORM {
   global:
@@ -1209,4 +1243,4 @@
     malloc_disable;
     malloc_enable;
     malloc_iterate;
-} LIBC_N;
+} LIBC_O;
diff --git a/libc/libc.x86.brillo.map b/libc/libc.x86.brillo.map
index 34f5e0e..a02d358 100644
--- a/libc/libc.x86.brillo.map
+++ b/libc/libc.x86.brillo.map
@@ -1,50 +1,49 @@
-# Generated by genversionscripts.py. Do not edit.
+# Generated by genversion-scripts.py. Do not edit.
 LIBC {
   global:
     __assert;
     __assert2;
     __b64_ntop;
     __b64_pton;
-    __brk; # arm x86 mips
-    __cmsg_nxthdr;
-    __connect; # arm x86 mips
-    __ctype_get_mb_cur_max;
+    __cmsg_nxthdr; # introduced=21
+    __connect; # arm x86 mips introduced=21
+    __ctype_get_mb_cur_max; # introduced=21
     __cxa_atexit;
     __cxa_finalize;
-    __cxa_thread_atexit_impl;
+    __cxa_thread_atexit_impl; # introduced=23
     __dn_comp;
     __dn_count_labels;
     __dn_skipname;
-    __epoll_pwait; # arm x86 mips
+    __epoll_pwait; # arm x86 mips introduced=21
     __errno;
-    __exit; # arm x86 mips
-    __fadvise64; # x86 mips
-    __fbufsize;
+    __exit; # arm x86 mips introduced=21
+    __fadvise64; # x86 mips introduced=21
+    __fbufsize; # introduced=23
     __fcntl64; # arm x86 mips
-    __FD_CLR_chk;
-    __FD_ISSET_chk;
-    __FD_SET_chk;
-    __fgets_chk;
-    __flbf;
+    __FD_CLR_chk; # introduced=21
+    __FD_ISSET_chk; # introduced=21
+    __FD_SET_chk; # introduced=21
+    __fgets_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __flbf; # introduced=23
     __fp_nquery;
     __fp_query;
-    __fpclassify;
+    __fpclassify; # introduced=21
     __fpclassifyd;
     __fpclassifyf;
     __fpclassifyl;
-    __fpending;
-    __fpurge;
-    __freadable;
-    __fsetlocking;
+    __fpending; # introduced=23
+    __fpurge; # introduced=23
+    __freadable; # introduced=23
+    __fsetlocking; # introduced=23
     __fstatfs64; # arm x86 mips
-    __fwritable;
+    __fwritable; # introduced=23
     __get_h_errno;
-    __getcpu; # arm x86 mips
+    __getcpu; # arm x86 mips introduced-arm=12 introduced-mips=16 introduced-x86=12
     __getcwd; # arm x86 mips
-    __getpid; # arm x86 mips
+    __getpid; # arm x86 mips introduced=21
     __getpriority; # arm x86 mips
-    __gnu_basename;
-    __gnu_strerror_r;
+    __gnu_basename; # introduced=23
+    __gnu_strerror_r; # introduced=23
     __hostalias;
     __ioctl; # arm x86 mips
     __isfinite;
@@ -53,24 +52,24 @@
     __isinf;
     __isinff;
     __isinfl;
-    __isnan;
-    __isnanf;
+    __isnan; # introduced=21
+    __isnanf; # introduced=21
     __isnanl;
     __isnormal;
     __isnormalf;
     __isnormall;
-    __isthreaded; # arm x86 mips
-    __libc_current_sigrtmax;
-    __libc_current_sigrtmin;
+    __isthreaded; # arm x86 mips var
+    __libc_current_sigrtmax; # introduced=21
+    __libc_current_sigrtmin; # introduced=21
     __libc_init;
     __llseek; # arm x86 mips
     __loc_aton;
     __loc_ntoa;
-    __memchr_chk;
-    __memcpy_chk;
-    __memmove_chk;
-    __memrchr_chk;
-    __memset_chk;
+    __memchr_chk; # introduced=23
+    __memcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __memmove_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __memrchr_chk; # introduced=23
+    __memset_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __mmap2; # arm x86 mips
     __ns_format_ttl; # arm x86 mips
     __ns_get16; # arm x86 mips
@@ -94,13 +93,13 @@
     __ns_skiprr; # arm x86 mips
     __ns_sprintrr; # arm x86 mips
     __ns_sprintrrf; # arm x86 mips
-    __open_2;
+    __open_2; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __openat; # arm x86 mips
-    __openat_2;
+    __openat_2; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __p_cdname;
     __p_cdnname;
     __p_class;
-    __p_class_syms;
+    __p_class_syms; # var
     __p_fqname;
     __p_fqnname;
     __p_option;
@@ -109,25 +108,25 @@
     __p_secstodate;
     __p_time;
     __p_type;
-    __p_type_syms;
-    __poll_chk;
-    __ppoll; # arm x86 mips
-    __ppoll_chk;
-    __pread64_chk;
-    __pread_chk;
-    __progname;
-    __pselect6; # arm x86 mips
+    __p_type_syms; # var
+    __poll_chk; # introduced=23
+    __ppoll; # arm x86 mips introduced=21
+    __ppoll_chk; # introduced=23
+    __pread64_chk; # introduced=23
+    __pread_chk; # introduced=23
+    __progname; # var
+    __pselect6; # arm x86 mips introduced=21
     __pthread_cleanup_pop;
     __pthread_cleanup_push;
     __ptrace; # arm x86 mips
     __putlong;
     __putshort;
-    __read_chk;
-    __readlink_chk;
-    __readlinkat_chk;
+    __read_chk; # introduced=21
+    __readlink_chk; # introduced=23
+    __readlinkat_chk; # introduced=23
     __reboot; # arm x86 mips
-    __recvfrom_chk;
-    __register_atfork;
+    __recvfrom_chk; # introduced=21
+    __register_atfork; # introduced=23
     __res_close;
     __res_dnok;
     __res_hnok;
@@ -149,89 +148,89 @@
     __res_send_setqhook;
     __res_send_setrhook;
     __rt_sigaction; # arm x86 mips
-    __rt_sigpending; # arm x86 mips
+    __rt_sigpending; # arm x86 mips introduced=21
     __rt_sigprocmask; # arm x86 mips
-    __rt_sigsuspend; # arm x86 mips
+    __rt_sigsuspend; # arm x86 mips introduced=21
     __rt_sigtimedwait; # arm x86 mips
-    __sched_cpualloc;
-    __sched_cpucount;
-    __sched_cpufree;
-    __sched_getaffinity; # arm x86 mips
+    __sched_cpualloc; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_cpucount; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_cpufree; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_getaffinity; # arm x86 mips introduced=12
     __set_thread_area; # x86
-    __set_tid_address; # arm x86 mips
-    __sF;
-    __sigaction; # arm x86 mips
-    __snprintf_chk;
-    __socket; # arm x86 mips
-    __sprintf_chk;
+    __set_tid_address; # arm x86 mips introduced=21
+    __sF; # var
+    __sigaction; # arm x86 mips introduced=21
+    __snprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __socket; # arm x86 mips introduced=21
+    __sprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __stack_chk_fail;
-    __stack_chk_guard;
+    __stack_chk_guard; # var
     __statfs64; # arm x86 mips
-    __stpcpy_chk;
-    __stpncpy_chk;
-    __stpncpy_chk2;
-    __strcat_chk;
-    __strchr_chk;
-    __strcpy_chk;
-    __strlcat_chk;
-    __strlcpy_chk;
-    __strlen_chk;
-    __strncat_chk;
-    __strncpy_chk;
-    __strncpy_chk2;
-    __strrchr_chk;
+    __stpcpy_chk; # introduced=21
+    __stpncpy_chk; # introduced=21
+    __stpncpy_chk2; # introduced=21
+    __strcat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strchr_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
+    __strcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlcat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlen_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncpy_chk2; # introduced=21
+    __strrchr_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     __sym_ntop;
     __sym_ntos;
     __sym_ston;
     __system_properties_init;
-    __system_property_add;
-    __system_property_area__;
-    __system_property_area_init;
-    __system_property_area_serial;
+    __system_property_add; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_area__; # var
+    __system_property_area_init; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_area_serial; # introduced=23
     __system_property_find;
     __system_property_find_nth;
-    __system_property_foreach;
+    __system_property_foreach; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     __system_property_get;
     __system_property_read;
-    __system_property_serial;
-    __system_property_set;
-    __system_property_set_filename;
-    __system_property_update;
-    __system_property_wait_any;
+    __system_property_serial; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_set; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __system_property_set_filename; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_update; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_wait_any; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     __timer_create; # arm x86 mips
     __timer_delete; # arm x86 mips
     __timer_getoverrun; # arm x86 mips
     __timer_gettime; # arm x86 mips
     __timer_settime; # arm x86 mips
-    __umask_chk;
-    __vsnprintf_chk;
-    __vsprintf_chk;
+    __umask_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
+    __vsnprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __vsprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __waitid; # arm x86 mips
-    _ctype_;
-    _Exit;
+    _ctype_; # var
+    _Exit; # introduced=21
     _exit;
-    _flushlbf;
+    _flushlbf; # introduced=23
     _getlong;
     _getshort;
     _longjmp;
-    _resolv_delete_cache_for_net;
-    _resolv_flush_cache_for_net;
-    _resolv_set_nameservers_for_net;
+    _resolv_delete_cache_for_net; # introduced=21
+    _resolv_flush_cache_for_net; # introduced=21
+    _resolv_set_nameservers_for_net; # introduced=21
     _setjmp;
-    _tolower;
-    _tolower_tab_; # arm x86 mips
-    _toupper;
-    _toupper_tab_; # arm x86 mips
+    _tolower; # introduced=21
+    _tolower_tab_; # arm x86 mips var
+    _toupper; # introduced=21
+    _toupper_tab_; # arm x86 mips var
     abort;
-    abs;
+    abs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     accept;
-    accept4;
+    accept4; # introduced=21
     access;
     acct;
     alarm;
     alphasort;
-    alphasort64;
-    android_set_abort_message;
+    alphasort64; # introduced=21
+    android_set_abort_message; # introduced=21
     arc4random;
     arc4random_buf;
     arc4random_uniform;
@@ -240,8 +239,8 @@
     asctime64_r; # arm x86 mips
     asctime_r;
     asprintf;
-    at_quick_exit;
-    atof;
+    at_quick_exit; # introduced=21
+    atof; # introduced=21
     atoi;
     atol;
     atoll;
@@ -252,43 +251,43 @@
     brk;
     bsearch;
     btowc;
-    c16rtomb;
-    c32rtomb;
+    c16rtomb; # introduced=21
+    c32rtomb; # introduced=21
     calloc;
     capget;
     capset;
-    cfgetispeed;
-    cfgetospeed;
-    cfmakeraw;
-    cfsetispeed;
-    cfsetospeed;
-    cfsetspeed;
+    cfgetispeed; # introduced=21
+    cfgetospeed; # introduced=21
+    cfmakeraw; # introduced=21
+    cfsetispeed; # introduced=21
+    cfsetospeed; # introduced=21
+    cfsetspeed; # introduced=21
     chdir;
     chmod;
     chown;
     chroot;
     clearenv;
     clearerr;
-    clearerr_unlocked;
+    clearerr_unlocked; # introduced=23
     clock;
-    clock_getcpuclockid;
+    clock_getcpuclockid; # introduced=23
     clock_getres;
     clock_gettime;
     clock_nanosleep;
     clock_settime;
-    clone;
+    clone; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     close;
     closedir;
     closelog;
     connect;
     creat;
-    creat64;
+    creat64; # introduced=21
     ctime;
     ctime64; # arm x86 mips
     ctime64_r; # arm x86 mips
     ctime_r;
     daemon;
-    daylight;
+    daylight; # var
     delete_module;
     difftime;
     dirfd;
@@ -296,33 +295,33 @@
     dirname_r; # arm x86 mips
     div;
     dn_expand;
-    dprintf;
+    dprintf; # introduced=21
     drand48;
     dup;
     dup2;
-    dup3;
-    duplocale;
-    endmntent;
+    dup3; # introduced=21
+    duplocale; # introduced=21
+    endmntent; # introduced=21
     endservent;
     endutent;
-    environ;
+    environ; # var
     epoll_create;
-    epoll_create1;
+    epoll_create1; # introduced=21
     epoll_ctl;
-    epoll_pwait;
+    epoll_pwait; # introduced=21
     epoll_wait;
     erand48;
     err;
-    error;
-    error_at_line;
-    error_message_count;
-    error_one_per_line;
-    error_print_progname;
+    error; # introduced=23
+    error_at_line; # introduced=23
+    error_message_count; # var introduced=23
+    error_one_per_line; # var introduced=23
+    error_print_progname; # var introduced=23
     errx;
-    ether_aton;
-    ether_aton_r;
-    ether_ntoa;
-    ether_ntoa_r;
+    ether_aton; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_aton_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_ntoa; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_ntoa_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     eventfd;
     eventfd_read;
     eventfd_write;
@@ -332,11 +331,11 @@
     execv;
     execve;
     execvp;
-    execvpe;
+    execvpe; # introduced=21
     exit;
-    faccessat;
-    fallocate;
-    fallocate64;
+    faccessat; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    fallocate; # introduced=21
+    fallocate64; # introduced=21
     fchdir;
     fchmod;
     fchmodat;
@@ -348,27 +347,27 @@
     fdopen;
     fdopendir;
     feof;
-    feof_unlocked;
+    feof_unlocked; # introduced=23
     ferror;
-    ferror_unlocked;
+    ferror_unlocked; # introduced=23
     fflush;
-    ffs;
+    ffs; # introduced-arm=9 introduced-arm64=21 introduced-mips=9 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     fgetc;
     fgetln;
     fgetpos;
     fgets;
     fgetwc;
     fgetws;
-    fgetxattr;
+    fgetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     fileno;
-    flistxattr;
+    flistxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     flock;
     flockfile;
-    fmemopen;
+    fmemopen; # introduced=23
     fnmatch;
     fopen;
     fork;
-    forkpty;
+    forkpty; # introduced=23
     fpathconf;
     fprintf;
     fpurge;
@@ -379,56 +378,56 @@
     fread;
     free;
     freeaddrinfo;
-    freelocale;
-    fremovexattr;
+    freelocale; # introduced=21
+    fremovexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     freopen;
     fscanf;
     fseek;
     fseeko;
     fsetpos;
-    fsetxattr;
+    fsetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     fstat;
-    fstat64;
+    fstat64; # introduced=21
     fstatat;
-    fstatat64;
+    fstatat64; # introduced=21
     fstatfs;
-    fstatfs64;
-    fstatvfs;
-    fstatvfs64;
+    fstatfs64; # introduced=21
+    fstatvfs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    fstatvfs64; # introduced=21
     fsync;
     ftell;
     ftello;
     ftok;
     ftruncate;
-    ftruncate64;
+    ftruncate64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     ftrylockfile;
     fts_children;
     fts_close;
     fts_open;
     fts_read;
     fts_set;
-    ftw;
-    ftw64;
+    ftw; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    ftw64; # introduced=21
     funlockfile;
     funopen;
-    futimens;
+    futimens; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     fwide;
     fwprintf;
     fwrite;
     fwscanf;
     gai_strerror;
-    get_avphys_pages;
-    get_nprocs;
-    get_nprocs_conf;
-    get_phys_pages;
+    get_avphys_pages; # introduced=23
+    get_nprocs; # introduced=23
+    get_nprocs_conf; # introduced=23
+    get_phys_pages; # introduced=23
     getaddrinfo;
-    getauxval;
+    getauxval; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getc;
     getc_unlocked;
     getchar;
     getchar_unlocked;
     getcwd;
-    getdelim;
+    getdelim; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getegid;
     getenv;
     geteuid;
@@ -438,49 +437,49 @@
     getgrouplist;
     getgroups;
     gethostbyaddr;
-    gethostbyaddr_r;
+    gethostbyaddr_r; # introduced=23
     gethostbyname;
     gethostbyname2;
-    gethostbyname2_r;
+    gethostbyname2_r; # introduced=23
     gethostbyname_r;
     gethostent;
     gethostname;
     getitimer;
-    getline;
+    getline; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getlogin;
     getmntent;
-    getmntent_r;
+    getmntent_r; # introduced=21
     getnameinfo;
     getnetbyaddr;
     getnetbyname;
     getopt;
     getopt_long;
     getopt_long_only;
-    getpagesize;
+    getpagesize; # introduced=21
     getpeername;
     getpgid;
     getpgrp;
     getpid;
     getppid;
     getpriority;
-    getprogname;
+    getprogname; # introduced=21
     getprotobyname;
     getprotobynumber;
     getpt;
     getpwnam;
-    getpwnam_r;
+    getpwnam_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     getpwuid;
-    getpwuid_r;
+    getpwuid_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     getresgid;
     getresuid;
     getrlimit;
-    getrlimit64;
+    getrlimit64; # introduced=21
     getrusage;
     gets;
     getservbyname;
     getservbyport;
     getservent;
-    getsid;
+    getsid; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     getsockname;
     getsockopt;
     gettid;
@@ -489,26 +488,26 @@
     getutent;
     getwc;
     getwchar;
-    getxattr;
+    getxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     gmtime;
     gmtime64; # arm x86 mips
     gmtime64_r; # arm x86 mips
     gmtime_r;
-    grantpt;
+    grantpt; # introduced=21
     herror;
     hstrerror;
-    htonl;
-    htons;
+    htonl; # introduced=21
+    htons; # introduced=21
     if_indextoname;
     if_nametoindex;
-    imaxabs;
-    imaxdiv;
+    imaxabs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    imaxdiv; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     inet_addr;
     inet_aton;
-    inet_lnaof;
-    inet_makeaddr;
-    inet_netof;
-    inet_network;
+    inet_lnaof; # introduced=21
+    inet_makeaddr; # introduced=21
+    inet_netof; # introduced=21
+    inet_network; # introduced=21
     inet_nsap_addr;
     inet_nsap_ntoa;
     inet_ntoa;
@@ -516,124 +515,124 @@
     inet_pton;
     init_module;
     initgroups;
-    initstate;
+    initstate; # introduced=21
     inotify_add_watch;
     inotify_init;
-    inotify_init1;
+    inotify_init1; # introduced=21
     inotify_rm_watch;
-    insque;
+    insque; # introduced=21
     ioctl;
     isalnum;
-    isalnum_l;
+    isalnum_l; # introduced=21
     isalpha;
-    isalpha_l;
+    isalpha_l; # introduced=21
     isascii;
     isatty;
     isblank;
-    isblank_l;
+    isblank_l; # introduced=21
     iscntrl;
-    iscntrl_l;
+    iscntrl_l; # introduced=21
     isdigit;
-    isdigit_l;
-    isfinite;
-    isfinitef;
-    isfinitel;
+    isdigit_l; # introduced=21
+    isfinite; # introduced=21
+    isfinitef; # introduced=21
+    isfinitel; # introduced=21
     isgraph;
-    isgraph_l;
-    isinf;
-    isinff;
-    isinfl;
+    isgraph_l; # introduced=21
+    isinf; # introduced=21
+    isinff; # introduced=21
+    isinfl; # introduced=21
     islower;
-    islower_l;
+    islower_l; # introduced=21
     isnan;
     isnanf;
-    isnanl;
-    isnormal;
-    isnormalf;
-    isnormall;
+    isnanl; # introduced=21
+    isnormal; # introduced=21
+    isnormalf; # introduced=21
+    isnormall; # introduced=21
     isprint;
-    isprint_l;
+    isprint_l; # introduced=21
     ispunct;
-    ispunct_l;
+    ispunct_l; # introduced=21
     isspace;
-    isspace_l;
+    isspace_l; # introduced=21
     isupper;
-    isupper_l;
+    isupper_l; # introduced=21
     iswalnum;
-    iswalnum_l;
+    iswalnum_l; # introduced=21
     iswalpha;
-    iswalpha_l;
-    iswblank;
-    iswblank_l;
+    iswalpha_l; # introduced=21
+    iswblank; # introduced=21
+    iswblank_l; # introduced=21
     iswcntrl;
-    iswcntrl_l;
+    iswcntrl_l; # introduced=21
     iswctype;
-    iswctype_l;
+    iswctype_l; # introduced=21
     iswdigit;
-    iswdigit_l;
+    iswdigit_l; # introduced=21
     iswgraph;
-    iswgraph_l;
+    iswgraph_l; # introduced=21
     iswlower;
-    iswlower_l;
+    iswlower_l; # introduced=21
     iswprint;
-    iswprint_l;
+    iswprint_l; # introduced=21
     iswpunct;
-    iswpunct_l;
+    iswpunct_l; # introduced=21
     iswspace;
-    iswspace_l;
+    iswspace_l; # introduced=21
     iswupper;
-    iswupper_l;
+    iswupper_l; # introduced=21
     iswxdigit;
-    iswxdigit_l;
+    iswxdigit_l; # introduced=21
     isxdigit;
-    isxdigit_l;
+    isxdigit_l; # introduced=21
     jrand48;
     kill;
     killpg;
     klogctl;
-    labs;
+    labs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     lchown;
-    lcong48;
+    lcong48; # introduced=23
     ldexp;
     ldiv;
-    lfind;
-    lgetxattr;
+    lfind; # introduced=21
+    lgetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     link;
-    linkat;
+    linkat; # introduced=21
     listen;
-    listxattr;
-    llabs;
+    listxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    llabs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     lldiv;
-    llistxattr;
-    localeconv;
+    llistxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    localeconv; # introduced=21
     localtime;
     localtime64; # arm x86 mips
     localtime64_r; # arm x86 mips
     localtime_r;
-    login_tty;
+    login_tty; # introduced=23
     longjmp;
     lrand48;
-    lremovexattr;
-    lsearch;
+    lremovexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    lsearch; # introduced=21
     lseek;
     lseek64;
-    lsetxattr;
+    lsetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     lstat;
-    lstat64;
+    lstat64; # introduced=21
     madvise;
     mallinfo;
     malloc;
-    malloc_info;
-    malloc_usable_size;
+    malloc_info; # introduced=23
+    malloc_usable_size; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     mbrlen;
-    mbrtoc16;
-    mbrtoc32;
+    mbrtoc16; # introduced=21
+    mbrtoc32; # introduced=21
     mbrtowc;
     mbsinit;
-    mbsnrtowcs;
+    mbsnrtowcs; # introduced=21
     mbsrtowcs;
     mbstowcs;
-    mbtowc;
+    mbtowc; # introduced=21
     memalign;
     memccpy;
     memchr;
@@ -641,91 +640,91 @@
     memcpy;
     memmem;
     memmove;
-    mempcpy;
+    mempcpy; # introduced=23
     memrchr;
     memset;
     mincore;
     mkdir;
     mkdirat;
     mkdtemp;
-    mkfifo;
-    mkfifoat;
+    mkfifo; # introduced=21
+    mkfifoat; # introduced=23
     mknod;
-    mknodat;
-    mkostemp;
-    mkostemp64;
-    mkostemps;
-    mkostemps64;
+    mknodat; # introduced=21
+    mkostemp; # introduced=23
+    mkostemp64; # introduced=23
+    mkostemps; # introduced=23
+    mkostemps64; # introduced=23
     mkstemp;
-    mkstemp64;
+    mkstemp64; # introduced=21
     mkstemps;
-    mkstemps64;
+    mkstemps64; # introduced=23
     mktemp;
     mktime;
     mktime64; # arm x86 mips
     mlock;
-    mlockall;
+    mlockall; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     mmap;
-    mmap64;
+    mmap64; # introduced=21
     mount;
     mprotect;
     mrand48;
     mremap;
     msync;
     munlock;
-    munlockall;
+    munlockall; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     munmap;
     nanosleep;
-    newlocale;
-    nftw;
-    nftw64;
+    newlocale; # introduced=21
+    nftw; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    nftw64; # introduced=21
     nice;
     nrand48;
     nsdispatch;
-    ntohl;
-    ntohs;
+    ntohl; # introduced=21
+    ntohs; # introduced=21
     open;
-    open64;
-    open_memstream;
-    open_wmemstream;
+    open64; # introduced=21
+    open_memstream; # introduced=23
+    open_wmemstream; # introduced=23
     openat;
-    openat64;
+    openat64; # introduced=21
     opendir;
     openlog;
-    openpty;
-    optarg;
-    opterr;
-    optind;
-    optopt;
-    optreset;
+    openpty; # introduced=23
+    optarg; # var
+    opterr; # var
+    optind; # var
+    optopt; # var
+    optreset; # var
     pathconf;
     pause;
     pclose;
     perror;
-    personality;
+    personality; # introduced-arm=15 introduced-arm64=21 introduced-mips=15 introduced-mips64=21 introduced-x86=15 introduced-x86_64=21
     pipe;
     pipe2;
     poll;
     popen;
-    posix_fadvise;
-    posix_fadvise64;
-    posix_fallocate;
-    posix_fallocate64;
-    posix_madvise;
-    posix_memalign;
-    posix_openpt;
-    ppoll;
+    posix_fadvise; # introduced=21
+    posix_fadvise64; # introduced=21
+    posix_fallocate; # introduced=21
+    posix_fallocate64; # introduced=21
+    posix_madvise; # introduced=23
+    posix_memalign; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    posix_openpt; # introduced=21
+    ppoll; # introduced=21
     prctl;
     pread;
-    pread64;
+    pread64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     printf;
-    prlimit64;
-    process_vm_readv;
-    process_vm_writev;
+    prlimit64; # introduced=21
+    process_vm_readv; # introduced=23
+    process_vm_writev; # introduced=23
     pselect;
-    psiginfo;
-    psignal;
-    pthread_atfork;
+    psiginfo; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    psignal; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    pthread_atfork; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     pthread_attr_destroy;
     pthread_attr_getdetachstate;
     pthread_attr_getguardsize;
@@ -753,10 +752,10 @@
     pthread_cond_timeout_np; # arm x86 mips
     pthread_cond_wait;
     pthread_condattr_destroy;
-    pthread_condattr_getclock;
+    pthread_condattr_getclock; # introduced=21
     pthread_condattr_getpshared;
     pthread_condattr_init;
-    pthread_condattr_setclock;
+    pthread_condattr_setclock; # introduced=21
     pthread_condattr_setpshared;
     pthread_create;
     pthread_detach;
@@ -766,7 +765,7 @@
     pthread_getcpuclockid;
     pthread_getschedparam;
     pthread_getspecific;
-    pthread_gettid_np;
+    pthread_gettid_np; # introduced=21
     pthread_join;
     pthread_key_create;
     pthread_key_delete;
@@ -775,7 +774,7 @@
     pthread_mutex_init;
     pthread_mutex_lock;
     pthread_mutex_lock_timeout_np; # arm x86 mips
-    pthread_mutex_timedlock;
+    pthread_mutex_timedlock; # introduced=21
     pthread_mutex_trylock;
     pthread_mutex_unlock;
     pthread_mutexattr_destroy;
@@ -795,10 +794,10 @@
     pthread_rwlock_unlock;
     pthread_rwlock_wrlock;
     pthread_rwlockattr_destroy;
-    pthread_rwlockattr_getkind_np;
+    pthread_rwlockattr_getkind_np; # introduced=23
     pthread_rwlockattr_getpshared;
     pthread_rwlockattr_init;
-    pthread_rwlockattr_setkind_np;
+    pthread_rwlockattr_setkind_np; # introduced=23
     pthread_rwlockattr_setpshared;
     pthread_self;
     pthread_setname_np;
@@ -818,38 +817,38 @@
     putw; # arm x86 mips
     putwc;
     putwchar;
-    pvalloc; # arm x86 mips
+    pvalloc; # arm x86 mips introduced=17
     pwrite;
-    pwrite64;
+    pwrite64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     qsort;
-    quick_exit;
+    quick_exit; # introduced=21
     raise;
-    rand;
-    rand_r;
-    random;
+    rand; # introduced=21
+    rand_r; # introduced=21
+    random; # introduced=21
     read;
-    readahead;
+    readahead; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     readdir;
-    readdir64;
-    readdir64_r;
+    readdir64; # introduced=21
+    readdir64_r; # introduced=21
     readdir_r;
     readlink;
-    readlinkat;
+    readlinkat; # introduced=21
     readv;
     realloc;
     realpath;
     reboot;
     recv;
     recvfrom;
-    recvmmsg;
+    recvmmsg; # introduced=21
     recvmsg;
     regcomp;
     regerror;
     regexec;
     regfree;
     remove;
-    removexattr;
-    remque;
+    removexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    remque; # introduced=21
     rename;
     renameat;
     res_init;
@@ -861,21 +860,21 @@
     rmdir;
     sbrk;
     scandir;
-    scandir64;
+    scandir64; # introduced=21
     scanf;
     sched_get_priority_max;
     sched_get_priority_min;
-    sched_getaffinity;
-    sched_getcpu;
+    sched_getaffinity; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    sched_getcpu; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sched_getparam;
     sched_getscheduler;
     sched_rr_get_interval;
-    sched_setaffinity;
+    sched_setaffinity; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sched_setparam;
     sched_setscheduler;
     sched_yield;
     seed48;
-    seekdir;
+    seekdir; # introduced=23
     select;
     sem_close;
     sem_destroy;
@@ -889,8 +888,8 @@
     sem_wait;
     send;
     sendfile;
-    sendfile64;
-    sendmmsg;
+    sendfile64; # introduced=21
+    sendmmsg; # introduced=21
     sendmsg;
     sendto;
     setbuf;
@@ -898,101 +897,101 @@
     setegid;
     setenv;
     seteuid;
-    setfsgid;
-    setfsuid;
+    setfsgid; # introduced=21
+    setfsuid; # introduced=21
     setgid;
     setgroups;
-    sethostname;
+    sethostname; # introduced=23
     setitimer;
     setjmp;
     setlinebuf;
     setlocale;
     setlogmask;
-    setmntent;
-    setns;
+    setmntent; # introduced=21
+    setns; # introduced=21
     setpgid;
     setpgrp;
     setpriority;
-    setprogname;
+    setprogname; # introduced=21
     setregid;
     setresgid;
     setresuid;
     setreuid;
     setrlimit;
-    setrlimit64;
+    setrlimit64; # introduced=21
     setservent;
     setsid;
     setsockopt;
-    setstate;
+    setstate; # introduced=21
     settimeofday;
     setuid;
     setutent;
     setvbuf;
-    setxattr;
+    setxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     shutdown;
     sigaction;
-    sigaddset;
+    sigaddset; # introduced=21
     sigaltstack;
     sigblock;
-    sigdelset;
-    sigemptyset;
-    sigfillset;
+    sigdelset; # introduced=21
+    sigemptyset; # introduced=21
+    sigfillset; # introduced=21
     siginterrupt;
-    sigismember;
-    siglongjmp;
-    signal;
-    signalfd;
+    sigismember; # introduced=21
+    siglongjmp; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    signal; # introduced=21
+    signalfd; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     sigpending;
     sigprocmask;
-    sigqueue;
-    sigsetjmp;
+    sigqueue; # introduced=23
+    sigsetjmp; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sigsetmask;
     sigsuspend;
-    sigtimedwait;
+    sigtimedwait; # introduced=23
     sigwait;
-    sigwaitinfo;
+    sigwaitinfo; # introduced=23
     sleep;
     snprintf;
     socket;
     socketpair;
-    splice;
+    splice; # introduced=21
     sprintf;
-    srand;
+    srand; # introduced=21
     srand48;
-    srandom;
+    srandom; # introduced=21
     sscanf;
     stat;
-    stat64;
+    stat64; # introduced=21
     statfs;
-    statfs64;
-    statvfs;
-    statvfs64;
-    stderr;
-    stdin;
-    stdout;
-    stpcpy;
-    stpncpy;
+    statfs64; # introduced=21
+    statvfs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    statvfs64; # introduced=21
+    stderr; # var introduced=23
+    stdin; # var introduced=23
+    stdout; # var introduced=23
+    stpcpy; # introduced=21
+    stpncpy; # introduced=21
     strcasecmp;
-    strcasecmp_l;
+    strcasecmp_l; # introduced=23
     strcasestr;
     strcat;
     strchr;
     strcmp;
     strcoll;
-    strcoll_l;
+    strcoll_l; # introduced=21
     strcpy;
     strcspn;
     strdup;
     strerror;
-    strerror_l;
+    strerror_l; # introduced=23
     strerror_r;
     strftime;
-    strftime_l;
+    strftime_l; # introduced=21
     strlcat;
     strlcpy;
     strlen;
     strncasecmp;
-    strncasecmp_l;
+    strncasecmp_l; # introduced=23
     strncat;
     strncmp;
     strncpy;
@@ -1006,86 +1005,86 @@
     strspn;
     strstr;
     strtod;
-    strtof;
+    strtof; # introduced=21
     strtoimax;
     strtok;
     strtok_r;
     strtol;
-    strtold;
-    strtold_l;
+    strtold; # introduced=21
+    strtold_l; # introduced=21
     strtoll;
-    strtoll_l;
-    strtoq;
+    strtoll_l; # introduced=21
+    strtoq; # introduced=21
     strtoul;
     strtoull;
-    strtoull_l;
+    strtoull_l; # introduced=21
     strtoumax;
-    strtouq;
+    strtouq; # introduced=21
     strxfrm;
-    strxfrm_l;
-    swapoff;
-    swapon;
+    strxfrm_l; # introduced=21
+    swapoff; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    swapon; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     swprintf;
     swscanf;
     symlink;
-    symlinkat;
+    symlinkat; # introduced=21
     sync;
-    sys_siglist;
-    sys_signame;
+    sys_siglist; # var
+    sys_signame; # var
     syscall;
     sysconf;
     sysinfo;
     syslog;
     system;
-    tcdrain;
-    tcflow;
-    tcflush;
-    tcgetattr;
+    tcdrain; # introduced=21
+    tcflow; # introduced=21
+    tcflush; # introduced=21
+    tcgetattr; # introduced=21
     tcgetpgrp;
-    tcgetsid;
-    tcsendbreak;
-    tcsetattr;
+    tcgetsid; # introduced=21
+    tcsendbreak; # introduced=21
+    tcsetattr; # introduced=21
     tcsetpgrp;
-    tdelete;
-    tdestroy;
-    tee;
-    telldir;
+    tdelete; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tdestroy; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tee; # introduced=21
+    telldir; # introduced=23
     tempnam;
-    tfind;
-    tgkill;
+    tfind; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tgkill; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     time;
-    timegm;
+    timegm; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     timegm64; # arm x86 mips
-    timelocal;
+    timelocal; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     timelocal64; # arm x86 mips
     timer_create;
     timer_delete;
     timer_getoverrun;
     timer_gettime;
     timer_settime;
-    timerfd_create;
-    timerfd_gettime;
-    timerfd_settime;
+    timerfd_create; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    timerfd_gettime; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    timerfd_settime; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     times;
-    timezone;
+    timezone; # var
     tmpfile;
     tmpnam;
     toascii;
     tolower;
-    tolower_l;
+    tolower_l; # introduced=21
     toupper;
-    toupper_l;
+    toupper_l; # introduced=21
     towlower;
-    towlower_l;
+    towlower_l; # introduced=21
     towupper;
-    towupper_l;
+    towupper_l; # introduced=21
     truncate;
-    truncate64;
-    tsearch;
+    truncate64; # introduced=21
+    tsearch; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     ttyname;
     ttyname_r;
-    twalk;
-    tzname;
+    twalk; # introduced=21
+    tzname; # var
     tzset;
     umask;
     umount;
@@ -1097,38 +1096,38 @@
     unlinkat;
     unlockpt;
     unsetenv;
-    unshare;
-    uselocale;
+    unshare; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    uselocale; # introduced=21
     usleep;
     utime;
-    utimensat;
+    utimensat; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     utimes;
     utmpname;
     valloc; # arm x86 mips
     vasprintf;
-    vdprintf;
+    vdprintf; # introduced=21
     verr;
     verrx;
     vfork;
     vfprintf;
     vfscanf;
     vfwprintf;
-    vfwscanf;
-    vmsplice;
+    vfwscanf; # introduced=21
+    vmsplice; # introduced=21
     vprintf;
     vscanf;
     vsnprintf;
     vsprintf;
     vsscanf;
     vswprintf;
-    vswscanf;
+    vswscanf; # introduced=21
     vsyslog;
     vwarn;
     vwarnx;
     vwprintf;
-    vwscanf;
+    vwscanf; # introduced=21
     wait;
-    wait4;
+    wait4; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     waitid;
     waitpid;
     warn;
@@ -1137,12 +1136,12 @@
     wcpncpy;
     wcrtomb;
     wcscasecmp;
-    wcscasecmp_l;
+    wcscasecmp_l; # introduced=23
     wcscat;
     wcschr;
     wcscmp;
     wcscoll;
-    wcscoll_l;
+    wcscoll_l; # introduced=21
     wcscpy;
     wcscspn;
     wcsdup;
@@ -1151,44 +1150,44 @@
     wcslcpy;
     wcslen;
     wcsncasecmp;
-    wcsncasecmp_l;
+    wcsncasecmp_l; # introduced=23
     wcsncat;
     wcsncmp;
     wcsncpy;
     wcsnlen;
-    wcsnrtombs;
+    wcsnrtombs; # introduced=21
     wcspbrk;
     wcsrchr;
     wcsrtombs;
     wcsspn;
     wcsstr;
     wcstod;
-    wcstof;
-    wcstoimax;
+    wcstof; # introduced=21
+    wcstoimax; # introduced=21
     wcstok;
     wcstol;
-    wcstold;
-    wcstold_l;
-    wcstoll;
-    wcstoll_l;
+    wcstold; # introduced=21
+    wcstold_l; # introduced=21
+    wcstoll; # introduced=21
+    wcstoll_l; # introduced=21
     wcstombs;
     wcstoul;
-    wcstoull;
-    wcstoull_l;
-    wcstoumax;
+    wcstoull; # introduced=21
+    wcstoull_l; # introduced=21
+    wcstoumax; # introduced=21
     wcswidth;
     wcsxfrm;
-    wcsxfrm_l;
+    wcsxfrm_l; # introduced=21
     wctob;
-    wctomb;
+    wctomb; # introduced=21
     wctype;
-    wctype_l;
+    wctype_l; # introduced=21
     wcwidth;
     wmemchr;
     wmemcmp;
     wmemcpy;
     wmemmove;
-    wmempcpy;
+    wmempcpy; # introduced=23
     wmemset;
     wprintf;
     write;
@@ -1198,57 +1197,91 @@
     *;
 };
 
-LIBC_N {
+LIBC_N { # introduced-arm64=24 introduced-mips=24 introduced-mips64=24 introduced-x86=24 introduced-x86_64=24
   global:
-    __fread_chk;
-    __fwrite_chk;
-    __getcwd_chk;
-    __pwrite_chk;
-    __pwrite64_chk;
-    __write_chk;
-    adjtimex;
-    clock_adjtime;
-    fgetpos64;
-    fileno_unlocked;
-    fopen64;
-    freeifaddrs;
-    freopen64;
-    fseeko64;
-    fsetpos64;
-    ftello64;
-    funopen64;
-    getgrgid_r;
-    getgrnam_r;
-    getifaddrs;
-    if_freenameindex;
-    if_nameindex;
-    in6addr_any;
-    in6addr_loopback;
-    lockf;
-    lockf64;
-    preadv;
-    preadv64;
-    prlimit; # arm mips x86
-    pthread_barrierattr_destroy;
-    pthread_barrierattr_getpshared;
-    pthread_barrierattr_init;
-    pthread_barrierattr_setpshared;
-    pthread_barrier_destroy;
-    pthread_barrier_init;
-    pthread_barrier_wait;
-    pthread_spin_destroy;
-    pthread_spin_init;
-    pthread_spin_lock;
-    pthread_spin_trylock;
-    pthread_spin_unlock;
-    pwritev;
-    pwritev64;
-    scandirat;
-    scandirat64;
-    strchrnul;
-    tmpfile64;
+    __fread_chk; # introduced=24
+    __fwrite_chk; # introduced=24
+    __getcwd_chk; # introduced=24
+    __pwrite_chk; # introduced=24
+    __pwrite64_chk; # introduced=24
+    __write_chk; # introduced=24
+    adjtimex; # introduced=24
+    clock_adjtime; # introduced=24
+    fgetpos64; # introduced=24
+    fileno_unlocked; # introduced=24
+    fopen64; # introduced=24
+    freeifaddrs; # introduced=24
+    freopen64; # introduced=24
+    fseeko64; # introduced=24
+    fsetpos64; # introduced=24
+    ftello64; # introduced=24
+    funopen64; # introduced=24
+    getgrgid_r; # introduced=24
+    getgrnam_r; # introduced=24
+    getifaddrs; # introduced=24
+    if_freenameindex; # introduced=24
+    if_nameindex; # introduced=24
+    in6addr_any; # var introduced=24
+    in6addr_loopback; # var introduced=24
+    lockf; # introduced=24
+    lockf64; # introduced=24
+    preadv; # introduced=24
+    preadv64; # introduced=24
+    prlimit; # arm mips x86 introduced=24
+    pthread_barrierattr_destroy; # introduced=24
+    pthread_barrierattr_getpshared; # introduced=24
+    pthread_barrierattr_init; # introduced=24
+    pthread_barrierattr_setpshared; # introduced=24
+    pthread_barrier_destroy; # introduced=24
+    pthread_barrier_init; # introduced=24
+    pthread_barrier_wait; # introduced=24
+    pthread_spin_destroy; # introduced=24
+    pthread_spin_init; # introduced=24
+    pthread_spin_lock; # introduced=24
+    pthread_spin_trylock; # introduced=24
+    pthread_spin_unlock; # introduced=24
+    pwritev; # introduced=24
+    pwritev64; # introduced=24
+    scandirat; # introduced=24
+    scandirat64; # introduced=24
+    strchrnul; # introduced=24
+    tmpfile64; # introduced=24
 } LIBC;
 
+LIBC_O {
+  global:
+    catclose; # future
+    catgets; # future
+    catopen; # future
+    ctermid; # future
+    endgrent; # future
+    endpwent; # future
+    futimes; # future
+    futimesat; # future
+    getdomainname; # future
+    getgrent; # future
+    getpwent; # future
+    getsubopt; # future
+    hasmntopt; # future
+    lutimes; # future
+    mblen; # future
+    pthread_getname_np; # future
+    quotactl; # future
+    setdomainname; # future
+    setgrent; # future
+    setpwent; # future
+    sighold; # future
+    sigignore; # future
+    sigpause; # future
+    sigrelse; # future
+    sigset; # future
+    sync_file_range; # future
+    towctrans; # future
+    towctrans_l; # future
+    wctrans; # future
+    wctrans_l; # future
+} LIBC_N;
+
 LIBC_PRIVATE {
   global:
     __accept4; # arm x86 mips
@@ -1284,7 +1317,7 @@
     SHA1Init; # arm x86 mips
     SHA1Transform; # arm x86 mips
     SHA1Update; # arm x86 mips
-} LIBC_N;
+} LIBC_O;
 
 LIBC_PLATFORM {
   global:
@@ -1295,4 +1328,4 @@
     malloc_disable;
     malloc_enable;
     malloc_iterate;
-} LIBC_N;
+} LIBC_O;
diff --git a/libc/libc.x86.map b/libc/libc.x86.map
index 9417d56..6e31a41 100644
--- a/libc/libc.x86.map
+++ b/libc/libc.x86.map
@@ -1,50 +1,49 @@
-# Generated by genversionscripts.py. Do not edit.
+# Generated by genversion-scripts.py. Do not edit.
 LIBC {
   global:
     __assert;
     __assert2;
     __b64_ntop;
     __b64_pton;
-    __brk; # arm x86 mips
-    __cmsg_nxthdr;
-    __connect; # arm x86 mips
-    __ctype_get_mb_cur_max;
+    __cmsg_nxthdr; # introduced=21
+    __connect; # arm x86 mips introduced=21
+    __ctype_get_mb_cur_max; # introduced=21
     __cxa_atexit;
     __cxa_finalize;
-    __cxa_thread_atexit_impl;
+    __cxa_thread_atexit_impl; # introduced=23
     __dn_comp;
     __dn_count_labels;
     __dn_skipname;
-    __epoll_pwait; # arm x86 mips
+    __epoll_pwait; # arm x86 mips introduced=21
     __errno;
-    __exit; # arm x86 mips
-    __fadvise64; # x86 mips
-    __fbufsize;
+    __exit; # arm x86 mips introduced=21
+    __fadvise64; # x86 mips introduced=21
+    __fbufsize; # introduced=23
     __fcntl64; # arm x86 mips
-    __FD_CLR_chk;
-    __FD_ISSET_chk;
-    __FD_SET_chk;
-    __fgets_chk;
-    __flbf;
+    __FD_CLR_chk; # introduced=21
+    __FD_ISSET_chk; # introduced=21
+    __FD_SET_chk; # introduced=21
+    __fgets_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __flbf; # introduced=23
     __fp_nquery;
     __fp_query;
-    __fpclassify;
+    __fpclassify; # introduced=21
     __fpclassifyd;
     __fpclassifyf;
     __fpclassifyl;
-    __fpending;
-    __fpurge;
-    __freadable;
-    __fsetlocking;
+    __fpending; # introduced=23
+    __fpurge; # introduced=23
+    __freadable; # introduced=23
+    __fsetlocking; # introduced=23
     __fstatfs64; # arm x86 mips
-    __fwritable;
+    __fwritable; # introduced=23
     __get_h_errno;
-    __getcpu; # arm x86 mips
+    __getcpu; # arm x86 mips introduced-arm=12 introduced-mips=16 introduced-x86=12
     __getcwd; # arm x86 mips
-    __getpid; # arm x86 mips
+    __getpid; # arm x86 mips introduced=21
     __getpriority; # arm x86 mips
-    __gnu_basename;
-    __gnu_strerror_r;
+    __gnu_basename; # introduced=23
+    __gnu_strerror_r; # introduced=23
     __hostalias;
     __ioctl; # arm x86 mips
     __isfinite;
@@ -53,24 +52,24 @@
     __isinf;
     __isinff;
     __isinfl;
-    __isnan;
-    __isnanf;
+    __isnan; # introduced=21
+    __isnanf; # introduced=21
     __isnanl;
     __isnormal;
     __isnormalf;
     __isnormall;
-    __isthreaded; # arm x86 mips
-    __libc_current_sigrtmax;
-    __libc_current_sigrtmin;
+    __isthreaded; # arm x86 mips var
+    __libc_current_sigrtmax; # introduced=21
+    __libc_current_sigrtmin; # introduced=21
     __libc_init;
     __llseek; # arm x86 mips
     __loc_aton;
     __loc_ntoa;
-    __memchr_chk;
-    __memcpy_chk;
-    __memmove_chk;
-    __memrchr_chk;
-    __memset_chk;
+    __memchr_chk; # introduced=23
+    __memcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __memmove_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __memrchr_chk; # introduced=23
+    __memset_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __mmap2; # arm x86 mips
     __ns_format_ttl; # arm x86 mips
     __ns_get16; # arm x86 mips
@@ -94,13 +93,13 @@
     __ns_skiprr; # arm x86 mips
     __ns_sprintrr; # arm x86 mips
     __ns_sprintrrf; # arm x86 mips
-    __open_2;
+    __open_2; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __openat; # arm x86 mips
-    __openat_2;
+    __openat_2; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __p_cdname;
     __p_cdnname;
     __p_class;
-    __p_class_syms;
+    __p_class_syms; # var
     __p_fqname;
     __p_fqnname;
     __p_option;
@@ -109,25 +108,25 @@
     __p_secstodate;
     __p_time;
     __p_type;
-    __p_type_syms;
-    __poll_chk;
-    __ppoll; # arm x86 mips
-    __ppoll_chk;
-    __pread64_chk;
-    __pread_chk;
-    __progname;
-    __pselect6; # arm x86 mips
+    __p_type_syms; # var
+    __poll_chk; # introduced=23
+    __ppoll; # arm x86 mips introduced=21
+    __ppoll_chk; # introduced=23
+    __pread64_chk; # introduced=23
+    __pread_chk; # introduced=23
+    __progname; # var
+    __pselect6; # arm x86 mips introduced=21
     __pthread_cleanup_pop;
     __pthread_cleanup_push;
     __ptrace; # arm x86 mips
     __putlong;
     __putshort;
-    __read_chk;
-    __readlink_chk;
-    __readlinkat_chk;
+    __read_chk; # introduced=21
+    __readlink_chk; # introduced=23
+    __readlinkat_chk; # introduced=23
     __reboot; # arm x86 mips
-    __recvfrom_chk;
-    __register_atfork;
+    __recvfrom_chk; # introduced=21
+    __register_atfork; # introduced=23
     __res_close;
     __res_dnok;
     __res_hnok;
@@ -149,89 +148,89 @@
     __res_send_setqhook;
     __res_send_setrhook;
     __rt_sigaction; # arm x86 mips
-    __rt_sigpending; # arm x86 mips
+    __rt_sigpending; # arm x86 mips introduced=21
     __rt_sigprocmask; # arm x86 mips
-    __rt_sigsuspend; # arm x86 mips
+    __rt_sigsuspend; # arm x86 mips introduced=21
     __rt_sigtimedwait; # arm x86 mips
-    __sched_cpualloc;
-    __sched_cpucount;
-    __sched_cpufree;
-    __sched_getaffinity; # arm x86 mips
+    __sched_cpualloc; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_cpucount; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_cpufree; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_getaffinity; # arm x86 mips introduced=12
     __set_thread_area; # x86
-    __set_tid_address; # arm x86 mips
-    __sF;
-    __sigaction; # arm x86 mips
-    __snprintf_chk;
-    __socket; # arm x86 mips
-    __sprintf_chk;
+    __set_tid_address; # arm x86 mips introduced=21
+    __sF; # var
+    __sigaction; # arm x86 mips introduced=21
+    __snprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __socket; # arm x86 mips introduced=21
+    __sprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __stack_chk_fail;
-    __stack_chk_guard;
+    __stack_chk_guard; # var
     __statfs64; # arm x86 mips
-    __stpcpy_chk;
-    __stpncpy_chk;
-    __stpncpy_chk2;
-    __strcat_chk;
-    __strchr_chk;
-    __strcpy_chk;
-    __strlcat_chk;
-    __strlcpy_chk;
-    __strlen_chk;
-    __strncat_chk;
-    __strncpy_chk;
-    __strncpy_chk2;
-    __strrchr_chk;
+    __stpcpy_chk; # introduced=21
+    __stpncpy_chk; # introduced=21
+    __stpncpy_chk2; # introduced=21
+    __strcat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strchr_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
+    __strcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlcat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlen_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncpy_chk2; # introduced=21
+    __strrchr_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     __sym_ntop;
     __sym_ntos;
     __sym_ston;
     __system_properties_init;
-    __system_property_add;
-    __system_property_area__;
-    __system_property_area_init;
-    __system_property_area_serial;
+    __system_property_add; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_area__; # var
+    __system_property_area_init; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_area_serial; # introduced=23
     __system_property_find;
     __system_property_find_nth;
-    __system_property_foreach;
+    __system_property_foreach; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     __system_property_get;
     __system_property_read;
-    __system_property_serial;
-    __system_property_set;
-    __system_property_set_filename;
-    __system_property_update;
-    __system_property_wait_any;
+    __system_property_serial; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_set; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __system_property_set_filename; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_update; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_wait_any; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     __timer_create; # arm x86 mips
     __timer_delete; # arm x86 mips
     __timer_getoverrun; # arm x86 mips
     __timer_gettime; # arm x86 mips
     __timer_settime; # arm x86 mips
-    __umask_chk;
-    __vsnprintf_chk;
-    __vsprintf_chk;
+    __umask_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
+    __vsnprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __vsprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __waitid; # arm x86 mips
-    _ctype_;
-    _Exit;
+    _ctype_; # var
+    _Exit; # introduced=21
     _exit;
-    _flushlbf;
+    _flushlbf; # introduced=23
     _getlong;
     _getshort;
     _longjmp;
-    _resolv_delete_cache_for_net;
-    _resolv_flush_cache_for_net;
-    _resolv_set_nameservers_for_net;
+    _resolv_delete_cache_for_net; # introduced=21
+    _resolv_flush_cache_for_net; # introduced=21
+    _resolv_set_nameservers_for_net; # introduced=21
     _setjmp;
-    _tolower;
-    _tolower_tab_; # arm x86 mips
-    _toupper;
-    _toupper_tab_; # arm x86 mips
+    _tolower; # introduced=21
+    _tolower_tab_; # arm x86 mips var
+    _toupper; # introduced=21
+    _toupper_tab_; # arm x86 mips var
     abort;
-    abs;
+    abs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     accept;
-    accept4;
+    accept4; # introduced=21
     access;
     acct;
     alarm;
     alphasort;
-    alphasort64;
-    android_set_abort_message;
+    alphasort64; # introduced=21
+    android_set_abort_message; # introduced=21
     arc4random;
     arc4random_buf;
     arc4random_uniform;
@@ -240,8 +239,8 @@
     asctime64_r; # arm x86 mips
     asctime_r;
     asprintf;
-    at_quick_exit;
-    atof;
+    at_quick_exit; # introduced=21
+    atof; # introduced=21
     atoi;
     atol;
     atoll;
@@ -252,43 +251,43 @@
     brk;
     bsearch;
     btowc;
-    c16rtomb;
-    c32rtomb;
+    c16rtomb; # introduced=21
+    c32rtomb; # introduced=21
     calloc;
     capget;
     capset;
-    cfgetispeed;
-    cfgetospeed;
-    cfmakeraw;
-    cfsetispeed;
-    cfsetospeed;
-    cfsetspeed;
+    cfgetispeed; # introduced=21
+    cfgetospeed; # introduced=21
+    cfmakeraw; # introduced=21
+    cfsetispeed; # introduced=21
+    cfsetospeed; # introduced=21
+    cfsetspeed; # introduced=21
     chdir;
     chmod;
     chown;
     chroot;
     clearenv;
     clearerr;
-    clearerr_unlocked;
+    clearerr_unlocked; # introduced=23
     clock;
-    clock_getcpuclockid;
+    clock_getcpuclockid; # introduced=23
     clock_getres;
     clock_gettime;
     clock_nanosleep;
     clock_settime;
-    clone;
+    clone; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     close;
     closedir;
     closelog;
     connect;
     creat;
-    creat64;
+    creat64; # introduced=21
     ctime;
     ctime64; # arm x86 mips
     ctime64_r; # arm x86 mips
     ctime_r;
     daemon;
-    daylight;
+    daylight; # var
     delete_module;
     difftime;
     dirfd;
@@ -296,33 +295,33 @@
     dirname_r; # arm x86 mips
     div;
     dn_expand;
-    dprintf;
+    dprintf; # introduced=21
     drand48;
     dup;
     dup2;
-    dup3;
-    duplocale;
-    endmntent;
+    dup3; # introduced=21
+    duplocale; # introduced=21
+    endmntent; # introduced=21
     endservent;
     endutent;
-    environ;
+    environ; # var
     epoll_create;
-    epoll_create1;
+    epoll_create1; # introduced=21
     epoll_ctl;
-    epoll_pwait;
+    epoll_pwait; # introduced=21
     epoll_wait;
     erand48;
     err;
-    error;
-    error_at_line;
-    error_message_count;
-    error_one_per_line;
-    error_print_progname;
+    error; # introduced=23
+    error_at_line; # introduced=23
+    error_message_count; # var introduced=23
+    error_one_per_line; # var introduced=23
+    error_print_progname; # var introduced=23
     errx;
-    ether_aton;
-    ether_aton_r;
-    ether_ntoa;
-    ether_ntoa_r;
+    ether_aton; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_aton_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_ntoa; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_ntoa_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     eventfd;
     eventfd_read;
     eventfd_write;
@@ -332,11 +331,11 @@
     execv;
     execve;
     execvp;
-    execvpe;
+    execvpe; # introduced=21
     exit;
-    faccessat;
-    fallocate;
-    fallocate64;
+    faccessat; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    fallocate; # introduced=21
+    fallocate64; # introduced=21
     fchdir;
     fchmod;
     fchmodat;
@@ -348,27 +347,27 @@
     fdopen;
     fdopendir;
     feof;
-    feof_unlocked;
+    feof_unlocked; # introduced=23
     ferror;
-    ferror_unlocked;
+    ferror_unlocked; # introduced=23
     fflush;
-    ffs;
+    ffs; # introduced-arm=9 introduced-arm64=21 introduced-mips=9 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     fgetc;
     fgetln;
     fgetpos;
     fgets;
     fgetwc;
     fgetws;
-    fgetxattr;
+    fgetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     fileno;
-    flistxattr;
+    flistxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     flock;
     flockfile;
-    fmemopen;
+    fmemopen; # introduced=23
     fnmatch;
     fopen;
     fork;
-    forkpty;
+    forkpty; # introduced=23
     fpathconf;
     fprintf;
     fpurge;
@@ -379,56 +378,56 @@
     fread;
     free;
     freeaddrinfo;
-    freelocale;
-    fremovexattr;
+    freelocale; # introduced=21
+    fremovexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     freopen;
     fscanf;
     fseek;
     fseeko;
     fsetpos;
-    fsetxattr;
+    fsetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     fstat;
-    fstat64;
+    fstat64; # introduced=21
     fstatat;
-    fstatat64;
+    fstatat64; # introduced=21
     fstatfs;
-    fstatfs64;
-    fstatvfs;
-    fstatvfs64;
+    fstatfs64; # introduced=21
+    fstatvfs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    fstatvfs64; # introduced=21
     fsync;
     ftell;
     ftello;
     ftok;
     ftruncate;
-    ftruncate64;
+    ftruncate64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     ftrylockfile;
     fts_children;
     fts_close;
     fts_open;
     fts_read;
     fts_set;
-    ftw;
-    ftw64;
+    ftw; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    ftw64; # introduced=21
     funlockfile;
     funopen;
-    futimens;
+    futimens; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     fwide;
     fwprintf;
     fwrite;
     fwscanf;
     gai_strerror;
-    get_avphys_pages;
-    get_nprocs;
-    get_nprocs_conf;
-    get_phys_pages;
+    get_avphys_pages; # introduced=23
+    get_nprocs; # introduced=23
+    get_nprocs_conf; # introduced=23
+    get_phys_pages; # introduced=23
     getaddrinfo;
-    getauxval;
+    getauxval; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getc;
     getc_unlocked;
     getchar;
     getchar_unlocked;
     getcwd;
-    getdelim;
+    getdelim; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getegid;
     getenv;
     geteuid;
@@ -438,49 +437,49 @@
     getgrouplist;
     getgroups;
     gethostbyaddr;
-    gethostbyaddr_r;
+    gethostbyaddr_r; # introduced=23
     gethostbyname;
     gethostbyname2;
-    gethostbyname2_r;
+    gethostbyname2_r; # introduced=23
     gethostbyname_r;
     gethostent;
     gethostname;
     getitimer;
-    getline;
+    getline; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getlogin;
     getmntent;
-    getmntent_r;
+    getmntent_r; # introduced=21
     getnameinfo;
     getnetbyaddr;
     getnetbyname;
     getopt;
     getopt_long;
     getopt_long_only;
-    getpagesize;
+    getpagesize; # introduced=21
     getpeername;
     getpgid;
     getpgrp;
     getpid;
     getppid;
     getpriority;
-    getprogname;
+    getprogname; # introduced=21
     getprotobyname;
     getprotobynumber;
     getpt;
     getpwnam;
-    getpwnam_r;
+    getpwnam_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     getpwuid;
-    getpwuid_r;
+    getpwuid_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     getresgid;
     getresuid;
     getrlimit;
-    getrlimit64;
+    getrlimit64; # introduced=21
     getrusage;
     gets;
     getservbyname;
     getservbyport;
     getservent;
-    getsid;
+    getsid; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     getsockname;
     getsockopt;
     gettid;
@@ -489,26 +488,26 @@
     getutent;
     getwc;
     getwchar;
-    getxattr;
+    getxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     gmtime;
     gmtime64; # arm x86 mips
     gmtime64_r; # arm x86 mips
     gmtime_r;
-    grantpt;
+    grantpt; # introduced=21
     herror;
     hstrerror;
-    htonl;
-    htons;
+    htonl; # introduced=21
+    htons; # introduced=21
     if_indextoname;
     if_nametoindex;
-    imaxabs;
-    imaxdiv;
+    imaxabs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    imaxdiv; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     inet_addr;
     inet_aton;
-    inet_lnaof;
-    inet_makeaddr;
-    inet_netof;
-    inet_network;
+    inet_lnaof; # introduced=21
+    inet_makeaddr; # introduced=21
+    inet_netof; # introduced=21
+    inet_network; # introduced=21
     inet_nsap_addr;
     inet_nsap_ntoa;
     inet_ntoa;
@@ -516,124 +515,124 @@
     inet_pton;
     init_module;
     initgroups;
-    initstate;
+    initstate; # introduced=21
     inotify_add_watch;
     inotify_init;
-    inotify_init1;
+    inotify_init1; # introduced=21
     inotify_rm_watch;
-    insque;
+    insque; # introduced=21
     ioctl;
     isalnum;
-    isalnum_l;
+    isalnum_l; # introduced=21
     isalpha;
-    isalpha_l;
+    isalpha_l; # introduced=21
     isascii;
     isatty;
     isblank;
-    isblank_l;
+    isblank_l; # introduced=21
     iscntrl;
-    iscntrl_l;
+    iscntrl_l; # introduced=21
     isdigit;
-    isdigit_l;
-    isfinite;
-    isfinitef;
-    isfinitel;
+    isdigit_l; # introduced=21
+    isfinite; # introduced=21
+    isfinitef; # introduced=21
+    isfinitel; # introduced=21
     isgraph;
-    isgraph_l;
-    isinf;
-    isinff;
-    isinfl;
+    isgraph_l; # introduced=21
+    isinf; # introduced=21
+    isinff; # introduced=21
+    isinfl; # introduced=21
     islower;
-    islower_l;
+    islower_l; # introduced=21
     isnan;
     isnanf;
-    isnanl;
-    isnormal;
-    isnormalf;
-    isnormall;
+    isnanl; # introduced=21
+    isnormal; # introduced=21
+    isnormalf; # introduced=21
+    isnormall; # introduced=21
     isprint;
-    isprint_l;
+    isprint_l; # introduced=21
     ispunct;
-    ispunct_l;
+    ispunct_l; # introduced=21
     isspace;
-    isspace_l;
+    isspace_l; # introduced=21
     isupper;
-    isupper_l;
+    isupper_l; # introduced=21
     iswalnum;
-    iswalnum_l;
+    iswalnum_l; # introduced=21
     iswalpha;
-    iswalpha_l;
-    iswblank;
-    iswblank_l;
+    iswalpha_l; # introduced=21
+    iswblank; # introduced=21
+    iswblank_l; # introduced=21
     iswcntrl;
-    iswcntrl_l;
+    iswcntrl_l; # introduced=21
     iswctype;
-    iswctype_l;
+    iswctype_l; # introduced=21
     iswdigit;
-    iswdigit_l;
+    iswdigit_l; # introduced=21
     iswgraph;
-    iswgraph_l;
+    iswgraph_l; # introduced=21
     iswlower;
-    iswlower_l;
+    iswlower_l; # introduced=21
     iswprint;
-    iswprint_l;
+    iswprint_l; # introduced=21
     iswpunct;
-    iswpunct_l;
+    iswpunct_l; # introduced=21
     iswspace;
-    iswspace_l;
+    iswspace_l; # introduced=21
     iswupper;
-    iswupper_l;
+    iswupper_l; # introduced=21
     iswxdigit;
-    iswxdigit_l;
+    iswxdigit_l; # introduced=21
     isxdigit;
-    isxdigit_l;
+    isxdigit_l; # introduced=21
     jrand48;
     kill;
     killpg;
     klogctl;
-    labs;
+    labs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     lchown;
-    lcong48;
+    lcong48; # introduced=23
     ldexp;
     ldiv;
-    lfind;
-    lgetxattr;
+    lfind; # introduced=21
+    lgetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     link;
-    linkat;
+    linkat; # introduced=21
     listen;
-    listxattr;
-    llabs;
+    listxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    llabs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     lldiv;
-    llistxattr;
-    localeconv;
+    llistxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    localeconv; # introduced=21
     localtime;
     localtime64; # arm x86 mips
     localtime64_r; # arm x86 mips
     localtime_r;
-    login_tty;
+    login_tty; # introduced=23
     longjmp;
     lrand48;
-    lremovexattr;
-    lsearch;
+    lremovexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    lsearch; # introduced=21
     lseek;
     lseek64;
-    lsetxattr;
+    lsetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     lstat;
-    lstat64;
+    lstat64; # introduced=21
     madvise;
     mallinfo;
     malloc;
-    malloc_info;
-    malloc_usable_size;
+    malloc_info; # introduced=23
+    malloc_usable_size; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     mbrlen;
-    mbrtoc16;
-    mbrtoc32;
+    mbrtoc16; # introduced=21
+    mbrtoc32; # introduced=21
     mbrtowc;
     mbsinit;
-    mbsnrtowcs;
+    mbsnrtowcs; # introduced=21
     mbsrtowcs;
     mbstowcs;
-    mbtowc;
+    mbtowc; # introduced=21
     memalign;
     memccpy;
     memchr;
@@ -641,91 +640,91 @@
     memcpy;
     memmem;
     memmove;
-    mempcpy;
+    mempcpy; # introduced=23
     memrchr;
     memset;
     mincore;
     mkdir;
     mkdirat;
     mkdtemp;
-    mkfifo;
-    mkfifoat;
+    mkfifo; # introduced=21
+    mkfifoat; # introduced=23
     mknod;
-    mknodat;
-    mkostemp;
-    mkostemp64;
-    mkostemps;
-    mkostemps64;
+    mknodat; # introduced=21
+    mkostemp; # introduced=23
+    mkostemp64; # introduced=23
+    mkostemps; # introduced=23
+    mkostemps64; # introduced=23
     mkstemp;
-    mkstemp64;
+    mkstemp64; # introduced=21
     mkstemps;
-    mkstemps64;
+    mkstemps64; # introduced=23
     mktemp;
     mktime;
     mktime64; # arm x86 mips
     mlock;
-    mlockall;
+    mlockall; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     mmap;
-    mmap64;
+    mmap64; # introduced=21
     mount;
     mprotect;
     mrand48;
     mremap;
     msync;
     munlock;
-    munlockall;
+    munlockall; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     munmap;
     nanosleep;
-    newlocale;
-    nftw;
-    nftw64;
+    newlocale; # introduced=21
+    nftw; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    nftw64; # introduced=21
     nice;
     nrand48;
     nsdispatch;
-    ntohl;
-    ntohs;
+    ntohl; # introduced=21
+    ntohs; # introduced=21
     open;
-    open64;
-    open_memstream;
-    open_wmemstream;
+    open64; # introduced=21
+    open_memstream; # introduced=23
+    open_wmemstream; # introduced=23
     openat;
-    openat64;
+    openat64; # introduced=21
     opendir;
     openlog;
-    openpty;
-    optarg;
-    opterr;
-    optind;
-    optopt;
-    optreset;
+    openpty; # introduced=23
+    optarg; # var
+    opterr; # var
+    optind; # var
+    optopt; # var
+    optreset; # var
     pathconf;
     pause;
     pclose;
     perror;
-    personality;
+    personality; # introduced-arm=15 introduced-arm64=21 introduced-mips=15 introduced-mips64=21 introduced-x86=15 introduced-x86_64=21
     pipe;
     pipe2;
     poll;
     popen;
-    posix_fadvise;
-    posix_fadvise64;
-    posix_fallocate;
-    posix_fallocate64;
-    posix_madvise;
-    posix_memalign;
-    posix_openpt;
-    ppoll;
+    posix_fadvise; # introduced=21
+    posix_fadvise64; # introduced=21
+    posix_fallocate; # introduced=21
+    posix_fallocate64; # introduced=21
+    posix_madvise; # introduced=23
+    posix_memalign; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    posix_openpt; # introduced=21
+    ppoll; # introduced=21
     prctl;
     pread;
-    pread64;
+    pread64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     printf;
-    prlimit64;
-    process_vm_readv;
-    process_vm_writev;
+    prlimit64; # introduced=21
+    process_vm_readv; # introduced=23
+    process_vm_writev; # introduced=23
     pselect;
-    psiginfo;
-    psignal;
-    pthread_atfork;
+    psiginfo; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    psignal; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    pthread_atfork; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     pthread_attr_destroy;
     pthread_attr_getdetachstate;
     pthread_attr_getguardsize;
@@ -753,10 +752,10 @@
     pthread_cond_timeout_np; # arm x86 mips
     pthread_cond_wait;
     pthread_condattr_destroy;
-    pthread_condattr_getclock;
+    pthread_condattr_getclock; # introduced=21
     pthread_condattr_getpshared;
     pthread_condattr_init;
-    pthread_condattr_setclock;
+    pthread_condattr_setclock; # introduced=21
     pthread_condattr_setpshared;
     pthread_create;
     pthread_detach;
@@ -766,7 +765,7 @@
     pthread_getcpuclockid;
     pthread_getschedparam;
     pthread_getspecific;
-    pthread_gettid_np;
+    pthread_gettid_np; # introduced=21
     pthread_join;
     pthread_key_create;
     pthread_key_delete;
@@ -775,7 +774,7 @@
     pthread_mutex_init;
     pthread_mutex_lock;
     pthread_mutex_lock_timeout_np; # arm x86 mips
-    pthread_mutex_timedlock;
+    pthread_mutex_timedlock; # introduced=21
     pthread_mutex_trylock;
     pthread_mutex_unlock;
     pthread_mutexattr_destroy;
@@ -795,10 +794,10 @@
     pthread_rwlock_unlock;
     pthread_rwlock_wrlock;
     pthread_rwlockattr_destroy;
-    pthread_rwlockattr_getkind_np;
+    pthread_rwlockattr_getkind_np; # introduced=23
     pthread_rwlockattr_getpshared;
     pthread_rwlockattr_init;
-    pthread_rwlockattr_setkind_np;
+    pthread_rwlockattr_setkind_np; # introduced=23
     pthread_rwlockattr_setpshared;
     pthread_self;
     pthread_setname_np;
@@ -818,38 +817,38 @@
     putw; # arm x86 mips
     putwc;
     putwchar;
-    pvalloc; # arm x86 mips
+    pvalloc; # arm x86 mips introduced=17
     pwrite;
-    pwrite64;
+    pwrite64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     qsort;
-    quick_exit;
+    quick_exit; # introduced=21
     raise;
-    rand;
-    rand_r;
-    random;
+    rand; # introduced=21
+    rand_r; # introduced=21
+    random; # introduced=21
     read;
-    readahead;
+    readahead; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     readdir;
-    readdir64;
-    readdir64_r;
+    readdir64; # introduced=21
+    readdir64_r; # introduced=21
     readdir_r;
     readlink;
-    readlinkat;
+    readlinkat; # introduced=21
     readv;
     realloc;
     realpath;
     reboot;
     recv;
     recvfrom;
-    recvmmsg;
+    recvmmsg; # introduced=21
     recvmsg;
     regcomp;
     regerror;
     regexec;
     regfree;
     remove;
-    removexattr;
-    remque;
+    removexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    remque; # introduced=21
     rename;
     renameat;
     res_init;
@@ -861,21 +860,21 @@
     rmdir;
     sbrk;
     scandir;
-    scandir64;
+    scandir64; # introduced=21
     scanf;
     sched_get_priority_max;
     sched_get_priority_min;
-    sched_getaffinity;
-    sched_getcpu;
+    sched_getaffinity; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    sched_getcpu; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sched_getparam;
     sched_getscheduler;
     sched_rr_get_interval;
-    sched_setaffinity;
+    sched_setaffinity; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sched_setparam;
     sched_setscheduler;
     sched_yield;
     seed48;
-    seekdir;
+    seekdir; # introduced=23
     select;
     sem_close;
     sem_destroy;
@@ -889,8 +888,8 @@
     sem_wait;
     send;
     sendfile;
-    sendfile64;
-    sendmmsg;
+    sendfile64; # introduced=21
+    sendmmsg; # introduced=21
     sendmsg;
     sendto;
     setbuf;
@@ -898,101 +897,101 @@
     setegid;
     setenv;
     seteuid;
-    setfsgid;
-    setfsuid;
+    setfsgid; # introduced=21
+    setfsuid; # introduced=21
     setgid;
     setgroups;
-    sethostname;
+    sethostname; # introduced=23
     setitimer;
     setjmp;
     setlinebuf;
     setlocale;
     setlogmask;
-    setmntent;
-    setns;
+    setmntent; # introduced=21
+    setns; # introduced=21
     setpgid;
     setpgrp;
     setpriority;
-    setprogname;
+    setprogname; # introduced=21
     setregid;
     setresgid;
     setresuid;
     setreuid;
     setrlimit;
-    setrlimit64;
+    setrlimit64; # introduced=21
     setservent;
     setsid;
     setsockopt;
-    setstate;
+    setstate; # introduced=21
     settimeofday;
     setuid;
     setutent;
     setvbuf;
-    setxattr;
+    setxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     shutdown;
     sigaction;
-    sigaddset;
+    sigaddset; # introduced=21
     sigaltstack;
     sigblock;
-    sigdelset;
-    sigemptyset;
-    sigfillset;
+    sigdelset; # introduced=21
+    sigemptyset; # introduced=21
+    sigfillset; # introduced=21
     siginterrupt;
-    sigismember;
-    siglongjmp;
-    signal;
-    signalfd;
+    sigismember; # introduced=21
+    siglongjmp; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    signal; # introduced=21
+    signalfd; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     sigpending;
     sigprocmask;
-    sigqueue;
-    sigsetjmp;
+    sigqueue; # introduced=23
+    sigsetjmp; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sigsetmask;
     sigsuspend;
-    sigtimedwait;
+    sigtimedwait; # introduced=23
     sigwait;
-    sigwaitinfo;
+    sigwaitinfo; # introduced=23
     sleep;
     snprintf;
     socket;
     socketpair;
-    splice;
+    splice; # introduced=21
     sprintf;
-    srand;
+    srand; # introduced=21
     srand48;
-    srandom;
+    srandom; # introduced=21
     sscanf;
     stat;
-    stat64;
+    stat64; # introduced=21
     statfs;
-    statfs64;
-    statvfs;
-    statvfs64;
-    stderr;
-    stdin;
-    stdout;
-    stpcpy;
-    stpncpy;
+    statfs64; # introduced=21
+    statvfs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    statvfs64; # introduced=21
+    stderr; # var introduced=23
+    stdin; # var introduced=23
+    stdout; # var introduced=23
+    stpcpy; # introduced=21
+    stpncpy; # introduced=21
     strcasecmp;
-    strcasecmp_l;
+    strcasecmp_l; # introduced=23
     strcasestr;
     strcat;
     strchr;
     strcmp;
     strcoll;
-    strcoll_l;
+    strcoll_l; # introduced=21
     strcpy;
     strcspn;
     strdup;
     strerror;
-    strerror_l;
+    strerror_l; # introduced=23
     strerror_r;
     strftime;
-    strftime_l;
+    strftime_l; # introduced=21
     strlcat;
     strlcpy;
     strlen;
     strncasecmp;
-    strncasecmp_l;
+    strncasecmp_l; # introduced=23
     strncat;
     strncmp;
     strncpy;
@@ -1006,86 +1005,86 @@
     strspn;
     strstr;
     strtod;
-    strtof;
+    strtof; # introduced=21
     strtoimax;
     strtok;
     strtok_r;
     strtol;
-    strtold;
-    strtold_l;
+    strtold; # introduced=21
+    strtold_l; # introduced=21
     strtoll;
-    strtoll_l;
-    strtoq;
+    strtoll_l; # introduced=21
+    strtoq; # introduced=21
     strtoul;
     strtoull;
-    strtoull_l;
+    strtoull_l; # introduced=21
     strtoumax;
-    strtouq;
+    strtouq; # introduced=21
     strxfrm;
-    strxfrm_l;
-    swapoff;
-    swapon;
+    strxfrm_l; # introduced=21
+    swapoff; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    swapon; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     swprintf;
     swscanf;
     symlink;
-    symlinkat;
+    symlinkat; # introduced=21
     sync;
-    sys_siglist;
-    sys_signame;
+    sys_siglist; # var
+    sys_signame; # var
     syscall;
     sysconf;
     sysinfo;
     syslog;
     system;
-    tcdrain;
-    tcflow;
-    tcflush;
-    tcgetattr;
+    tcdrain; # introduced=21
+    tcflow; # introduced=21
+    tcflush; # introduced=21
+    tcgetattr; # introduced=21
     tcgetpgrp;
-    tcgetsid;
-    tcsendbreak;
-    tcsetattr;
+    tcgetsid; # introduced=21
+    tcsendbreak; # introduced=21
+    tcsetattr; # introduced=21
     tcsetpgrp;
-    tdelete;
-    tdestroy;
-    tee;
-    telldir;
+    tdelete; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tdestroy; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tee; # introduced=21
+    telldir; # introduced=23
     tempnam;
-    tfind;
-    tgkill;
+    tfind; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tgkill; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     time;
-    timegm;
+    timegm; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     timegm64; # arm x86 mips
-    timelocal;
+    timelocal; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     timelocal64; # arm x86 mips
     timer_create;
     timer_delete;
     timer_getoverrun;
     timer_gettime;
     timer_settime;
-    timerfd_create;
-    timerfd_gettime;
-    timerfd_settime;
+    timerfd_create; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    timerfd_gettime; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    timerfd_settime; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     times;
-    timezone;
+    timezone; # var
     tmpfile;
     tmpnam;
     toascii;
     tolower;
-    tolower_l;
+    tolower_l; # introduced=21
     toupper;
-    toupper_l;
+    toupper_l; # introduced=21
     towlower;
-    towlower_l;
+    towlower_l; # introduced=21
     towupper;
-    towupper_l;
+    towupper_l; # introduced=21
     truncate;
-    truncate64;
-    tsearch;
+    truncate64; # introduced=21
+    tsearch; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     ttyname;
     ttyname_r;
-    twalk;
-    tzname;
+    twalk; # introduced=21
+    tzname; # var
     tzset;
     umask;
     umount;
@@ -1097,38 +1096,38 @@
     unlinkat;
     unlockpt;
     unsetenv;
-    unshare;
-    uselocale;
+    unshare; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    uselocale; # introduced=21
     usleep;
     utime;
-    utimensat;
+    utimensat; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     utimes;
     utmpname;
     valloc; # arm x86 mips
     vasprintf;
-    vdprintf;
+    vdprintf; # introduced=21
     verr;
     verrx;
     vfork;
     vfprintf;
     vfscanf;
     vfwprintf;
-    vfwscanf;
-    vmsplice;
+    vfwscanf; # introduced=21
+    vmsplice; # introduced=21
     vprintf;
     vscanf;
     vsnprintf;
     vsprintf;
     vsscanf;
     vswprintf;
-    vswscanf;
+    vswscanf; # introduced=21
     vsyslog;
     vwarn;
     vwarnx;
     vwprintf;
-    vwscanf;
+    vwscanf; # introduced=21
     wait;
-    wait4;
+    wait4; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     waitid;
     waitpid;
     warn;
@@ -1137,12 +1136,12 @@
     wcpncpy;
     wcrtomb;
     wcscasecmp;
-    wcscasecmp_l;
+    wcscasecmp_l; # introduced=23
     wcscat;
     wcschr;
     wcscmp;
     wcscoll;
-    wcscoll_l;
+    wcscoll_l; # introduced=21
     wcscpy;
     wcscspn;
     wcsdup;
@@ -1151,44 +1150,44 @@
     wcslcpy;
     wcslen;
     wcsncasecmp;
-    wcsncasecmp_l;
+    wcsncasecmp_l; # introduced=23
     wcsncat;
     wcsncmp;
     wcsncpy;
     wcsnlen;
-    wcsnrtombs;
+    wcsnrtombs; # introduced=21
     wcspbrk;
     wcsrchr;
     wcsrtombs;
     wcsspn;
     wcsstr;
     wcstod;
-    wcstof;
-    wcstoimax;
+    wcstof; # introduced=21
+    wcstoimax; # introduced=21
     wcstok;
     wcstol;
-    wcstold;
-    wcstold_l;
-    wcstoll;
-    wcstoll_l;
+    wcstold; # introduced=21
+    wcstold_l; # introduced=21
+    wcstoll; # introduced=21
+    wcstoll_l; # introduced=21
     wcstombs;
     wcstoul;
-    wcstoull;
-    wcstoull_l;
-    wcstoumax;
+    wcstoull; # introduced=21
+    wcstoull_l; # introduced=21
+    wcstoumax; # introduced=21
     wcswidth;
     wcsxfrm;
-    wcsxfrm_l;
+    wcsxfrm_l; # introduced=21
     wctob;
-    wctomb;
+    wctomb; # introduced=21
     wctype;
-    wctype_l;
+    wctype_l; # introduced=21
     wcwidth;
     wmemchr;
     wmemcmp;
     wmemcpy;
     wmemmove;
-    wmempcpy;
+    wmempcpy; # introduced=23
     wmemset;
     wprintf;
     write;
@@ -1198,57 +1197,92 @@
     *;
 };
 
-LIBC_N {
+LIBC_N { # introduced-arm64=24 introduced-mips=24 introduced-mips64=24 introduced-x86=24 introduced-x86_64=24
   global:
-    __fread_chk;
-    __fwrite_chk;
-    __getcwd_chk;
-    __pwrite_chk;
-    __pwrite64_chk;
-    __write_chk;
-    adjtimex;
-    clock_adjtime;
-    fgetpos64;
-    fileno_unlocked;
-    fopen64;
-    freeifaddrs;
-    freopen64;
-    fseeko64;
-    fsetpos64;
-    ftello64;
-    funopen64;
-    getgrgid_r;
-    getgrnam_r;
-    getifaddrs;
-    if_freenameindex;
-    if_nameindex;
-    in6addr_any;
-    in6addr_loopback;
-    lockf;
-    lockf64;
-    preadv;
-    preadv64;
-    prlimit; # arm mips x86
-    pthread_barrierattr_destroy;
-    pthread_barrierattr_getpshared;
-    pthread_barrierattr_init;
-    pthread_barrierattr_setpshared;
-    pthread_barrier_destroy;
-    pthread_barrier_init;
-    pthread_barrier_wait;
-    pthread_spin_destroy;
-    pthread_spin_init;
-    pthread_spin_lock;
-    pthread_spin_trylock;
-    pthread_spin_unlock;
-    pwritev;
-    pwritev64;
-    scandirat;
-    scandirat64;
-    strchrnul;
-    tmpfile64;
+    __fread_chk; # introduced=24
+    __fwrite_chk; # introduced=24
+    __getcwd_chk; # introduced=24
+    __pwrite_chk; # introduced=24
+    __pwrite64_chk; # introduced=24
+    __write_chk; # introduced=24
+    adjtimex; # introduced=24
+    clock_adjtime; # introduced=24
+    fgetpos64; # introduced=24
+    fileno_unlocked; # introduced=24
+    fopen64; # introduced=24
+    freeifaddrs; # introduced=24
+    freopen64; # introduced=24
+    fseeko64; # introduced=24
+    fsetpos64; # introduced=24
+    ftello64; # introduced=24
+    funopen64; # introduced=24
+    getgrgid_r; # introduced=24
+    getgrnam_r; # introduced=24
+    getifaddrs; # introduced=24
+    if_freenameindex; # introduced=24
+    if_nameindex; # introduced=24
+    in6addr_any; # var introduced=24
+    in6addr_loopback; # var introduced=24
+    lockf; # introduced=24
+    lockf64; # introduced=24
+    preadv; # introduced=24
+    preadv64; # introduced=24
+    prlimit; # arm mips x86 introduced=24
+    pthread_barrierattr_destroy; # introduced=24
+    pthread_barrierattr_getpshared; # introduced=24
+    pthread_barrierattr_init; # introduced=24
+    pthread_barrierattr_setpshared; # introduced=24
+    pthread_barrier_destroy; # introduced=24
+    pthread_barrier_init; # introduced=24
+    pthread_barrier_wait; # introduced=24
+    pthread_spin_destroy; # introduced=24
+    pthread_spin_init; # introduced=24
+    pthread_spin_lock; # introduced=24
+    pthread_spin_trylock; # introduced=24
+    pthread_spin_unlock; # introduced=24
+    pwritev; # introduced=24
+    pwritev64; # introduced=24
+    scandirat; # introduced=24
+    scandirat64; # introduced=24
+    strchrnul; # introduced=24
+    tmpfile64; # introduced=24
 } LIBC;
 
+LIBC_O {
+  global:
+    bsd_signal; # arm x86 mips nobrillo versioned=26
+    catclose; # future
+    catgets; # future
+    catopen; # future
+    ctermid; # future
+    endgrent; # future
+    endpwent; # future
+    futimes; # future
+    futimesat; # future
+    getdomainname; # future
+    getgrent; # future
+    getpwent; # future
+    getsubopt; # future
+    hasmntopt; # future
+    lutimes; # future
+    mblen; # future
+    pthread_getname_np; # future
+    quotactl; # future
+    setdomainname; # future
+    setgrent; # future
+    setpwent; # future
+    sighold; # future
+    sigignore; # future
+    sigpause; # future
+    sigrelse; # future
+    sigset; # future
+    sync_file_range; # future
+    towctrans; # future
+    towctrans_l; # future
+    wctrans; # future
+    wctrans_l; # future
+} LIBC_N;
+
 LIBC_PRIVATE {
   global:
     __accept4; # arm x86 mips
@@ -1293,12 +1327,10 @@
     arc4random_stir; # arm x86 mips nobrillo
     bcopy; # arm x86 mips nobrillo
     bzero; # arm x86 mips nobrillo
-    bsd_signal; # arm x86 mips nobrillo
     dlmalloc; # arm x86 mips nobrillo
     dlmalloc_inspect_all; # arm x86 mips nobrillo
     dlmalloc_trim; # arm x86 mips nobrillo
     dlmalloc_usable_size; # arm x86 mips nobrillo
-    endpwent; # arm x86 mips nobrillo
     fdprintf; # arm x86 mips nobrillo
     free_malloc_leak_info;
     ftime; # arm x86 mips nobrillo
@@ -1323,7 +1355,7 @@
     vfdprintf; # arm x86 mips nobrillo
     wait3; # arm x86 mips nobrillo
     wcswcs; # arm x86 mips nobrillo
-} LIBC_N;
+} LIBC_O;
 
 LIBC_PLATFORM {
   global:
@@ -1334,4 +1366,4 @@
     malloc_disable;
     malloc_enable;
     malloc_iterate;
-} LIBC_N;
+} LIBC_O;
diff --git a/libc/libc.x86_64.map b/libc/libc.x86_64.map
index afbd0ee..f080340 100644
--- a/libc/libc.x86_64.map
+++ b/libc/libc.x86_64.map
@@ -1,39 +1,39 @@
-# Generated by genversionscripts.py. Do not edit.
+# Generated by genversion-scripts.py. Do not edit.
 LIBC {
   global:
     __assert;
     __assert2;
     __b64_ntop;
     __b64_pton;
-    __cmsg_nxthdr;
-    __ctype_get_mb_cur_max;
+    __cmsg_nxthdr; # introduced=21
+    __ctype_get_mb_cur_max; # introduced=21
     __cxa_atexit;
     __cxa_finalize;
-    __cxa_thread_atexit_impl;
+    __cxa_thread_atexit_impl; # introduced=23
     __dn_comp;
     __dn_count_labels;
     __dn_skipname;
     __errno;
-    __fbufsize;
-    __FD_CLR_chk;
-    __FD_ISSET_chk;
-    __FD_SET_chk;
-    __fgets_chk;
-    __flbf;
+    __fbufsize; # introduced=23
+    __FD_CLR_chk; # introduced=21
+    __FD_ISSET_chk; # introduced=21
+    __FD_SET_chk; # introduced=21
+    __fgets_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __flbf; # introduced=23
     __fp_nquery;
     __fp_query;
-    __fpclassify;
+    __fpclassify; # introduced=21
     __fpclassifyd;
     __fpclassifyf;
     __fpclassifyl;
-    __fpending;
-    __fpurge;
-    __freadable;
-    __fsetlocking;
-    __fwritable;
+    __fpending; # introduced=23
+    __fpurge; # introduced=23
+    __freadable; # introduced=23
+    __fsetlocking; # introduced=23
+    __fwritable; # introduced=23
     __get_h_errno;
-    __gnu_basename;
-    __gnu_strerror_r;
+    __gnu_basename; # introduced=23
+    __gnu_strerror_r; # introduced=23
     __hostalias;
     __isfinite;
     __isfinitef;
@@ -41,28 +41,28 @@
     __isinf;
     __isinff;
     __isinfl;
-    __isnan;
-    __isnanf;
+    __isnan; # introduced=21
+    __isnanf; # introduced=21
     __isnanl;
     __isnormal;
     __isnormalf;
     __isnormall;
-    __libc_current_sigrtmax;
-    __libc_current_sigrtmin;
+    __libc_current_sigrtmax; # introduced=21
+    __libc_current_sigrtmin; # introduced=21
     __libc_init;
     __loc_aton;
     __loc_ntoa;
-    __memchr_chk;
-    __memcpy_chk;
-    __memmove_chk;
-    __memrchr_chk;
-    __memset_chk;
-    __open_2;
-    __openat_2;
+    __memchr_chk; # introduced=23
+    __memcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __memmove_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __memrchr_chk; # introduced=23
+    __memset_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __open_2; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __openat_2; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __p_cdname;
     __p_cdnname;
     __p_class;
-    __p_class_syms;
+    __p_class_syms; # var
     __p_fqname;
     __p_fqnname;
     __p_option;
@@ -71,21 +71,21 @@
     __p_secstodate;
     __p_time;
     __p_type;
-    __p_type_syms;
-    __poll_chk;
-    __ppoll_chk;
-    __pread64_chk;
-    __pread_chk;
-    __progname;
+    __p_type_syms; # var
+    __poll_chk; # introduced=23
+    __ppoll_chk; # introduced=23
+    __pread64_chk; # introduced=23
+    __pread_chk; # introduced=23
+    __progname; # var
     __pthread_cleanup_pop;
     __pthread_cleanup_push;
     __putlong;
     __putshort;
-    __read_chk;
-    __readlink_chk;
-    __readlinkat_chk;
-    __recvfrom_chk;
-    __register_atfork;
+    __read_chk; # introduced=21
+    __readlink_chk; # introduced=23
+    __readlinkat_chk; # introduced=23
+    __recvfrom_chk; # introduced=21
+    __register_atfork; # introduced=23
     __res_close;
     __res_dnok;
     __res_hnok;
@@ -106,79 +106,79 @@
     __res_send;
     __res_send_setqhook;
     __res_send_setrhook;
-    __sched_cpualloc;
-    __sched_cpucount;
-    __sched_cpufree;
-    __sF;
-    __snprintf_chk;
-    __sprintf_chk;
+    __sched_cpualloc; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_cpucount; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sched_cpufree; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __sF; # var
+    __snprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __sprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     __stack_chk_fail;
-    __stack_chk_guard;
-    __stpcpy_chk;
-    __stpncpy_chk;
-    __stpncpy_chk2;
-    __strcat_chk;
-    __strchr_chk;
-    __strcpy_chk;
-    __strlcat_chk;
-    __strlcpy_chk;
-    __strlen_chk;
-    __strncat_chk;
-    __strncpy_chk;
-    __strncpy_chk2;
-    __strrchr_chk;
+    __stack_chk_guard; # var
+    __stpcpy_chk; # introduced=21
+    __stpncpy_chk; # introduced=21
+    __stpncpy_chk2; # introduced=21
+    __strcat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strchr_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
+    __strcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlcat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlcpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strlen_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncat_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncpy_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __strncpy_chk2; # introduced=21
+    __strrchr_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     __sym_ntop;
     __sym_ntos;
     __sym_ston;
     __system_properties_init;
-    __system_property_add;
-    __system_property_area__;
-    __system_property_area_init;
-    __system_property_area_serial;
+    __system_property_add; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_area__; # var
+    __system_property_area_init; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_area_serial; # introduced=23
     __system_property_find;
     __system_property_find_nth;
-    __system_property_foreach;
+    __system_property_foreach; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     __system_property_get;
     __system_property_read;
-    __system_property_serial;
-    __system_property_set;
-    __system_property_set_filename;
-    __system_property_update;
-    __system_property_wait_any;
-    __umask_chk;
-    __vsnprintf_chk;
-    __vsprintf_chk;
-    _ctype_;
-    _Exit;
+    __system_property_serial; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_set; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    __system_property_set_filename; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_update; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __system_property_wait_any; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    __umask_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
+    __vsnprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    __vsprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    _ctype_; # var
+    _Exit; # introduced=21
     _exit;
-    _flushlbf;
+    _flushlbf; # introduced=23
     _getlong;
     _getshort;
     _longjmp;
-    _resolv_delete_cache_for_net;
-    _resolv_flush_cache_for_net;
-    _resolv_set_nameservers_for_net;
+    _resolv_delete_cache_for_net; # introduced=21
+    _resolv_flush_cache_for_net; # introduced=21
+    _resolv_set_nameservers_for_net; # introduced=21
     _setjmp;
-    _tolower;
-    _toupper;
+    _tolower; # introduced=21
+    _toupper; # introduced=21
     abort;
-    abs;
+    abs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     accept;
-    accept4;
+    accept4; # introduced=21
     access;
     acct;
     alarm;
     alphasort;
-    alphasort64;
-    android_set_abort_message;
+    alphasort64; # introduced=21
+    android_set_abort_message; # introduced=21
     arc4random;
     arc4random_buf;
     arc4random_uniform;
     asctime;
     asctime_r;
     asprintf;
-    at_quick_exit;
-    atof;
+    at_quick_exit; # introduced=21
+    atof; # introduced=21
     atoi;
     atol;
     atoll;
@@ -188,74 +188,74 @@
     brk;
     bsearch;
     btowc;
-    c16rtomb;
-    c32rtomb;
+    c16rtomb; # introduced=21
+    c32rtomb; # introduced=21
     calloc;
     capget;
     capset;
-    cfgetispeed;
-    cfgetospeed;
-    cfmakeraw;
-    cfsetispeed;
-    cfsetospeed;
-    cfsetspeed;
+    cfgetispeed; # introduced=21
+    cfgetospeed; # introduced=21
+    cfmakeraw; # introduced=21
+    cfsetispeed; # introduced=21
+    cfsetospeed; # introduced=21
+    cfsetspeed; # introduced=21
     chdir;
     chmod;
     chown;
     chroot;
     clearenv;
     clearerr;
-    clearerr_unlocked;
+    clearerr_unlocked; # introduced=23
     clock;
-    clock_getcpuclockid;
+    clock_getcpuclockid; # introduced=23
     clock_getres;
     clock_gettime;
     clock_nanosleep;
     clock_settime;
-    clone;
+    clone; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     close;
     closedir;
     closelog;
     connect;
     creat;
-    creat64;
+    creat64; # introduced=21
     ctime;
     ctime_r;
     daemon;
-    daylight;
+    daylight; # var
     delete_module;
     difftime;
     dirfd;
     dirname;
     div;
     dn_expand;
-    dprintf;
+    dprintf; # introduced=21
     drand48;
     dup;
     dup2;
-    dup3;
-    duplocale;
-    endmntent;
+    dup3; # introduced=21
+    duplocale; # introduced=21
+    endmntent; # introduced=21
     endservent;
     endutent;
-    environ;
+    environ; # var
     epoll_create;
-    epoll_create1;
+    epoll_create1; # introduced=21
     epoll_ctl;
-    epoll_pwait;
+    epoll_pwait; # introduced=21
     epoll_wait;
     erand48;
     err;
-    error;
-    error_at_line;
-    error_message_count;
-    error_one_per_line;
-    error_print_progname;
+    error; # introduced=23
+    error_at_line; # introduced=23
+    error_message_count; # var introduced=23
+    error_one_per_line; # var introduced=23
+    error_print_progname; # var introduced=23
     errx;
-    ether_aton;
-    ether_aton_r;
-    ether_ntoa;
-    ether_ntoa_r;
+    ether_aton; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_aton_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_ntoa; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    ether_ntoa_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     eventfd;
     eventfd_read;
     eventfd_write;
@@ -265,11 +265,11 @@
     execv;
     execve;
     execvp;
-    execvpe;
+    execvpe; # introduced=21
     exit;
-    faccessat;
-    fallocate;
-    fallocate64;
+    faccessat; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    fallocate; # introduced=21
+    fallocate64; # introduced=21
     fchdir;
     fchmod;
     fchmodat;
@@ -281,27 +281,27 @@
     fdopen;
     fdopendir;
     feof;
-    feof_unlocked;
+    feof_unlocked; # introduced=23
     ferror;
-    ferror_unlocked;
+    ferror_unlocked; # introduced=23
     fflush;
-    ffs;
+    ffs; # introduced-arm=9 introduced-arm64=21 introduced-mips=9 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     fgetc;
     fgetln;
     fgetpos;
     fgets;
     fgetwc;
     fgetws;
-    fgetxattr;
+    fgetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     fileno;
-    flistxattr;
+    flistxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     flock;
     flockfile;
-    fmemopen;
+    fmemopen; # introduced=23
     fnmatch;
     fopen;
     fork;
-    forkpty;
+    forkpty; # introduced=23
     fpathconf;
     fprintf;
     fpurge;
@@ -312,56 +312,56 @@
     fread;
     free;
     freeaddrinfo;
-    freelocale;
-    fremovexattr;
+    freelocale; # introduced=21
+    fremovexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     freopen;
     fscanf;
     fseek;
     fseeko;
     fsetpos;
-    fsetxattr;
+    fsetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     fstat;
-    fstat64;
+    fstat64; # introduced=21
     fstatat;
-    fstatat64;
+    fstatat64; # introduced=21
     fstatfs;
-    fstatfs64;
-    fstatvfs;
-    fstatvfs64;
+    fstatfs64; # introduced=21
+    fstatvfs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    fstatvfs64; # introduced=21
     fsync;
     ftell;
     ftello;
     ftok;
     ftruncate;
-    ftruncate64;
+    ftruncate64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     ftrylockfile;
     fts_children;
     fts_close;
     fts_open;
     fts_read;
     fts_set;
-    ftw;
-    ftw64;
+    ftw; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    ftw64; # introduced=21
     funlockfile;
     funopen;
-    futimens;
+    futimens; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     fwide;
     fwprintf;
     fwrite;
     fwscanf;
     gai_strerror;
-    get_avphys_pages;
-    get_nprocs;
-    get_nprocs_conf;
-    get_phys_pages;
+    get_avphys_pages; # introduced=23
+    get_nprocs; # introduced=23
+    get_nprocs_conf; # introduced=23
+    get_phys_pages; # introduced=23
     getaddrinfo;
-    getauxval;
+    getauxval; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getc;
     getc_unlocked;
     getchar;
     getchar_unlocked;
     getcwd;
-    getdelim;
+    getdelim; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getegid;
     getenv;
     geteuid;
@@ -371,49 +371,49 @@
     getgrouplist;
     getgroups;
     gethostbyaddr;
-    gethostbyaddr_r;
+    gethostbyaddr_r; # introduced=23
     gethostbyname;
     gethostbyname2;
-    gethostbyname2_r;
+    gethostbyname2_r; # introduced=23
     gethostbyname_r;
     gethostent;
     gethostname;
     getitimer;
-    getline;
+    getline; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     getlogin;
     getmntent;
-    getmntent_r;
+    getmntent_r; # introduced=21
     getnameinfo;
     getnetbyaddr;
     getnetbyname;
     getopt;
     getopt_long;
     getopt_long_only;
-    getpagesize;
+    getpagesize; # introduced=21
     getpeername;
     getpgid;
     getpgrp;
     getpid;
     getppid;
     getpriority;
-    getprogname;
+    getprogname; # introduced=21
     getprotobyname;
     getprotobynumber;
     getpt;
     getpwnam;
-    getpwnam_r;
+    getpwnam_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     getpwuid;
-    getpwuid_r;
+    getpwuid_r; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     getresgid;
     getresuid;
     getrlimit;
-    getrlimit64;
+    getrlimit64; # introduced=21
     getrusage;
     gets;
     getservbyname;
     getservbyport;
     getservent;
-    getsid;
+    getsid; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     getsockname;
     getsockopt;
     gettid;
@@ -422,24 +422,24 @@
     getutent;
     getwc;
     getwchar;
-    getxattr;
+    getxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     gmtime;
     gmtime_r;
-    grantpt;
+    grantpt; # introduced=21
     herror;
     hstrerror;
-    htonl;
-    htons;
+    htonl; # introduced=21
+    htons; # introduced=21
     if_indextoname;
     if_nametoindex;
-    imaxabs;
-    imaxdiv;
+    imaxabs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    imaxdiv; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     inet_addr;
     inet_aton;
-    inet_lnaof;
-    inet_makeaddr;
-    inet_netof;
-    inet_network;
+    inet_lnaof; # introduced=21
+    inet_makeaddr; # introduced=21
+    inet_netof; # introduced=21
+    inet_network; # introduced=21
     inet_nsap_addr;
     inet_nsap_ntoa;
     inet_ntoa;
@@ -447,122 +447,122 @@
     inet_pton;
     init_module;
     initgroups;
-    initstate;
+    initstate; # introduced=21
     inotify_add_watch;
     inotify_init;
-    inotify_init1;
+    inotify_init1; # introduced=21
     inotify_rm_watch;
-    insque;
+    insque; # introduced=21
     ioctl;
     isalnum;
-    isalnum_l;
+    isalnum_l; # introduced=21
     isalpha;
-    isalpha_l;
+    isalpha_l; # introduced=21
     isascii;
     isatty;
     isblank;
-    isblank_l;
+    isblank_l; # introduced=21
     iscntrl;
-    iscntrl_l;
+    iscntrl_l; # introduced=21
     isdigit;
-    isdigit_l;
-    isfinite;
-    isfinitef;
-    isfinitel;
+    isdigit_l; # introduced=21
+    isfinite; # introduced=21
+    isfinitef; # introduced=21
+    isfinitel; # introduced=21
     isgraph;
-    isgraph_l;
-    isinf;
-    isinff;
-    isinfl;
+    isgraph_l; # introduced=21
+    isinf; # introduced=21
+    isinff; # introduced=21
+    isinfl; # introduced=21
     islower;
-    islower_l;
+    islower_l; # introduced=21
     isnan;
     isnanf;
-    isnanl;
-    isnormal;
-    isnormalf;
-    isnormall;
+    isnanl; # introduced=21
+    isnormal; # introduced=21
+    isnormalf; # introduced=21
+    isnormall; # introduced=21
     isprint;
-    isprint_l;
+    isprint_l; # introduced=21
     ispunct;
-    ispunct_l;
+    ispunct_l; # introduced=21
     isspace;
-    isspace_l;
+    isspace_l; # introduced=21
     isupper;
-    isupper_l;
+    isupper_l; # introduced=21
     iswalnum;
-    iswalnum_l;
+    iswalnum_l; # introduced=21
     iswalpha;
-    iswalpha_l;
-    iswblank;
-    iswblank_l;
+    iswalpha_l; # introduced=21
+    iswblank; # introduced=21
+    iswblank_l; # introduced=21
     iswcntrl;
-    iswcntrl_l;
+    iswcntrl_l; # introduced=21
     iswctype;
-    iswctype_l;
+    iswctype_l; # introduced=21
     iswdigit;
-    iswdigit_l;
+    iswdigit_l; # introduced=21
     iswgraph;
-    iswgraph_l;
+    iswgraph_l; # introduced=21
     iswlower;
-    iswlower_l;
+    iswlower_l; # introduced=21
     iswprint;
-    iswprint_l;
+    iswprint_l; # introduced=21
     iswpunct;
-    iswpunct_l;
+    iswpunct_l; # introduced=21
     iswspace;
-    iswspace_l;
+    iswspace_l; # introduced=21
     iswupper;
-    iswupper_l;
+    iswupper_l; # introduced=21
     iswxdigit;
-    iswxdigit_l;
+    iswxdigit_l; # introduced=21
     isxdigit;
-    isxdigit_l;
+    isxdigit_l; # introduced=21
     jrand48;
     kill;
     killpg;
     klogctl;
-    labs;
+    labs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     lchown;
-    lcong48;
+    lcong48; # introduced=23
     ldexp;
     ldiv;
-    lfind;
-    lgetxattr;
+    lfind; # introduced=21
+    lgetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     link;
-    linkat;
+    linkat; # introduced=21
     listen;
-    listxattr;
-    llabs;
+    listxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    llabs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     lldiv;
-    llistxattr;
-    localeconv;
+    llistxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    localeconv; # introduced=21
     localtime;
     localtime_r;
-    login_tty;
+    login_tty; # introduced=23
     longjmp;
     lrand48;
-    lremovexattr;
-    lsearch;
+    lremovexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    lsearch; # introduced=21
     lseek;
     lseek64;
-    lsetxattr;
+    lsetxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     lstat;
-    lstat64;
+    lstat64; # introduced=21
     madvise;
     mallinfo;
     malloc;
-    malloc_info;
-    malloc_usable_size;
+    malloc_info; # introduced=23
+    malloc_usable_size; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     mbrlen;
-    mbrtoc16;
-    mbrtoc32;
+    mbrtoc16; # introduced=21
+    mbrtoc32; # introduced=21
     mbrtowc;
     mbsinit;
-    mbsnrtowcs;
+    mbsnrtowcs; # introduced=21
     mbsrtowcs;
     mbstowcs;
-    mbtowc;
+    mbtowc; # introduced=21
     memalign;
     memccpy;
     memchr;
@@ -570,113 +570,113 @@
     memcpy;
     memmem;
     memmove;
-    mempcpy;
+    mempcpy; # introduced=23
     memrchr;
     memset;
     mincore;
     mkdir;
     mkdirat;
     mkdtemp;
-    mkfifo;
-    mkfifoat;
+    mkfifo; # introduced=21
+    mkfifoat; # introduced=23
     mknod;
-    mknodat;
-    mkostemp;
-    mkostemp64;
-    mkostemps;
-    mkostemps64;
+    mknodat; # introduced=21
+    mkostemp; # introduced=23
+    mkostemp64; # introduced=23
+    mkostemps; # introduced=23
+    mkostemps64; # introduced=23
     mkstemp;
-    mkstemp64;
+    mkstemp64; # introduced=21
     mkstemps;
-    mkstemps64;
+    mkstemps64; # introduced=23
     mktemp;
     mktime;
     mlock;
-    mlockall;
+    mlockall; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     mmap;
-    mmap64;
+    mmap64; # introduced=21
     mount;
     mprotect;
     mrand48;
     mremap;
     msync;
     munlock;
-    munlockall;
+    munlockall; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
     munmap;
     nanosleep;
-    newlocale;
-    nftw;
-    nftw64;
+    newlocale; # introduced=21
+    nftw; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    nftw64; # introduced=21
     nice;
     nrand48;
-    ns_format_ttl; # arm64 x86_64 mips64
-    ns_get16; # arm64 x86_64 mips64
-    ns_get32; # arm64 x86_64 mips64
-    ns_initparse; # arm64 x86_64 mips64
-    ns_makecanon; # arm64 x86_64 mips64
-    ns_msg_getflag; # arm64 x86_64 mips64
-    ns_name_compress; # arm64 x86_64 mips64
-    ns_name_ntol; # arm64 x86_64 mips64
-    ns_name_ntop; # arm64 x86_64 mips64
-    ns_name_pack; # arm64 x86_64 mips64
-    ns_name_pton; # arm64 x86_64 mips64
-    ns_name_rollback; # arm64 x86_64 mips64
-    ns_name_skip; # arm64 x86_64 mips64
-    ns_name_uncompress; # arm64 x86_64 mips64
-    ns_name_unpack; # arm64 x86_64 mips64
-    ns_parserr; # arm64 x86_64 mips64
-    ns_put16; # arm64 x86_64 mips64
-    ns_put32; # arm64 x86_64 mips64
-    ns_samename; # arm64 x86_64 mips64
-    ns_skiprr; # arm64 x86_64 mips64
-    ns_sprintrr; # arm64 x86_64 mips64
-    ns_sprintrrf; # arm64 x86_64 mips64
+    ns_format_ttl; # arm64 x86_64 mips64 introduced=22
+    ns_get16; # arm64 x86_64 mips64 introduced=22
+    ns_get32; # arm64 x86_64 mips64 introduced=22
+    ns_initparse; # arm64 x86_64 mips64 introduced=22
+    ns_makecanon; # arm64 x86_64 mips64 introduced=22
+    ns_msg_getflag; # arm64 x86_64 mips64 introduced=22
+    ns_name_compress; # arm64 x86_64 mips64 introduced=22
+    ns_name_ntol; # arm64 x86_64 mips64 introduced=22
+    ns_name_ntop; # arm64 x86_64 mips64 introduced=22
+    ns_name_pack; # arm64 x86_64 mips64 introduced=22
+    ns_name_pton; # arm64 x86_64 mips64 introduced=23
+    ns_name_rollback; # arm64 x86_64 mips64 introduced=22
+    ns_name_skip; # arm64 x86_64 mips64 introduced=22
+    ns_name_uncompress; # arm64 x86_64 mips64 introduced=22
+    ns_name_unpack; # arm64 x86_64 mips64 introduced=22
+    ns_parserr; # arm64 x86_64 mips64 introduced=22
+    ns_put16; # arm64 x86_64 mips64 introduced=22
+    ns_put32; # arm64 x86_64 mips64 introduced=22
+    ns_samename; # arm64 x86_64 mips64 introduced=22
+    ns_skiprr; # arm64 x86_64 mips64 introduced=22
+    ns_sprintrr; # arm64 x86_64 mips64 introduced=22
+    ns_sprintrrf; # arm64 x86_64 mips64 introduced=22
     nsdispatch;
-    ntohl;
-    ntohs;
+    ntohl; # introduced=21
+    ntohs; # introduced=21
     open;
-    open64;
-    open_memstream;
-    open_wmemstream;
+    open64; # introduced=21
+    open_memstream; # introduced=23
+    open_wmemstream; # introduced=23
     openat;
-    openat64;
+    openat64; # introduced=21
     opendir;
     openlog;
-    openpty;
-    optarg;
-    opterr;
-    optind;
-    optopt;
-    optreset;
+    openpty; # introduced=23
+    optarg; # var
+    opterr; # var
+    optind; # var
+    optopt; # var
+    optreset; # var
     pathconf;
     pause;
     pclose;
     perror;
-    personality;
+    personality; # introduced-arm=15 introduced-arm64=21 introduced-mips=15 introduced-mips64=21 introduced-x86=15 introduced-x86_64=21
     pipe;
     pipe2;
     poll;
     popen;
-    posix_fadvise;
-    posix_fadvise64;
-    posix_fallocate;
-    posix_fallocate64;
-    posix_madvise;
-    posix_memalign;
-    posix_openpt;
-    ppoll;
+    posix_fadvise; # introduced=21
+    posix_fadvise64; # introduced=21
+    posix_fallocate; # introduced=21
+    posix_fallocate64; # introduced=21
+    posix_madvise; # introduced=23
+    posix_memalign; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    posix_openpt; # introduced=21
+    ppoll; # introduced=21
     prctl;
     pread;
-    pread64;
+    pread64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     printf;
     prlimit; # arm64 x86_64 mips64
-    prlimit64;
-    process_vm_readv;
-    process_vm_writev;
+    prlimit64; # introduced=21
+    process_vm_readv; # introduced=23
+    process_vm_writev; # introduced=23
     pselect;
-    psiginfo;
-    psignal;
-    pthread_atfork;
+    psiginfo; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    psignal; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    pthread_atfork; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     pthread_attr_destroy;
     pthread_attr_getdetachstate;
     pthread_attr_getguardsize;
@@ -700,10 +700,10 @@
     pthread_cond_timedwait;
     pthread_cond_wait;
     pthread_condattr_destroy;
-    pthread_condattr_getclock;
+    pthread_condattr_getclock; # introduced=21
     pthread_condattr_getpshared;
     pthread_condattr_init;
-    pthread_condattr_setclock;
+    pthread_condattr_setclock; # introduced=21
     pthread_condattr_setpshared;
     pthread_create;
     pthread_detach;
@@ -713,7 +713,7 @@
     pthread_getcpuclockid;
     pthread_getschedparam;
     pthread_getspecific;
-    pthread_gettid_np;
+    pthread_gettid_np; # introduced=21
     pthread_join;
     pthread_key_create;
     pthread_key_delete;
@@ -721,7 +721,7 @@
     pthread_mutex_destroy;
     pthread_mutex_init;
     pthread_mutex_lock;
-    pthread_mutex_timedlock;
+    pthread_mutex_timedlock; # introduced=21
     pthread_mutex_trylock;
     pthread_mutex_unlock;
     pthread_mutexattr_destroy;
@@ -741,10 +741,10 @@
     pthread_rwlock_unlock;
     pthread_rwlock_wrlock;
     pthread_rwlockattr_destroy;
-    pthread_rwlockattr_getkind_np;
+    pthread_rwlockattr_getkind_np; # introduced=23
     pthread_rwlockattr_getpshared;
     pthread_rwlockattr_init;
-    pthread_rwlockattr_setkind_np;
+    pthread_rwlockattr_setkind_np; # introduced=23
     pthread_rwlockattr_setpshared;
     pthread_self;
     pthread_setname_np;
@@ -764,36 +764,36 @@
     putwc;
     putwchar;
     pwrite;
-    pwrite64;
+    pwrite64; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     qsort;
-    quick_exit;
+    quick_exit; # introduced=21
     raise;
-    rand;
-    rand_r;
-    random;
+    rand; # introduced=21
+    rand_r; # introduced=21
+    random; # introduced=21
     read;
-    readahead;
+    readahead; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     readdir;
-    readdir64;
-    readdir64_r;
+    readdir64; # introduced=21
+    readdir64_r; # introduced=21
     readdir_r;
     readlink;
-    readlinkat;
+    readlinkat; # introduced=21
     readv;
     realloc;
     realpath;
     reboot;
     recv;
     recvfrom;
-    recvmmsg;
+    recvmmsg; # introduced=21
     recvmsg;
     regcomp;
     regerror;
     regexec;
     regfree;
     remove;
-    removexattr;
-    remque;
+    removexattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    remque; # introduced=21
     rename;
     renameat;
     res_init;
@@ -805,21 +805,21 @@
     rmdir;
     sbrk;
     scandir;
-    scandir64;
+    scandir64; # introduced=21
     scanf;
     sched_get_priority_max;
     sched_get_priority_min;
-    sched_getaffinity;
-    sched_getcpu;
+    sched_getaffinity; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    sched_getcpu; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sched_getparam;
     sched_getscheduler;
     sched_rr_get_interval;
-    sched_setaffinity;
+    sched_setaffinity; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sched_setparam;
     sched_setscheduler;
     sched_yield;
     seed48;
-    seekdir;
+    seekdir; # introduced=23
     select;
     sem_close;
     sem_destroy;
@@ -833,8 +833,8 @@
     sem_wait;
     send;
     sendfile;
-    sendfile64;
-    sendmmsg;
+    sendfile64; # introduced=21
+    sendmmsg; # introduced=21
     sendmsg;
     sendto;
     setbuf;
@@ -842,101 +842,101 @@
     setegid;
     setenv;
     seteuid;
-    setfsgid;
-    setfsuid;
+    setfsgid; # introduced=21
+    setfsuid; # introduced=21
     setgid;
     setgroups;
-    sethostname;
+    sethostname; # introduced=23
     setitimer;
     setjmp;
     setlinebuf;
     setlocale;
     setlogmask;
-    setmntent;
-    setns;
+    setmntent; # introduced=21
+    setns; # introduced=21
     setpgid;
     setpgrp;
     setpriority;
-    setprogname;
+    setprogname; # introduced=21
     setregid;
     setresgid;
     setresuid;
     setreuid;
     setrlimit;
-    setrlimit64;
+    setrlimit64; # introduced=21
     setservent;
     setsid;
     setsockopt;
-    setstate;
+    setstate; # introduced=21
     settimeofday;
     setuid;
     setutent;
     setvbuf;
-    setxattr;
+    setxattr; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     shutdown;
     sigaction;
-    sigaddset;
+    sigaddset; # introduced=21
     sigaltstack;
     sigblock;
-    sigdelset;
-    sigemptyset;
-    sigfillset;
+    sigdelset; # introduced=21
+    sigemptyset; # introduced=21
+    sigfillset; # introduced=21
     siginterrupt;
-    sigismember;
-    siglongjmp;
-    signal;
-    signalfd;
+    sigismember; # introduced=21
+    siglongjmp; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    signal; # introduced=21
+    signalfd; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     sigpending;
     sigprocmask;
-    sigqueue;
-    sigsetjmp;
+    sigqueue; # introduced=23
+    sigsetjmp; # introduced-arm=9 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     sigsetmask;
     sigsuspend;
-    sigtimedwait;
+    sigtimedwait; # introduced=23
     sigwait;
-    sigwaitinfo;
+    sigwaitinfo; # introduced=23
     sleep;
     snprintf;
     socket;
     socketpair;
-    splice;
+    splice; # introduced=21
     sprintf;
-    srand;
+    srand; # introduced=21
     srand48;
-    srandom;
+    srandom; # introduced=21
     sscanf;
     stat;
-    stat64;
+    stat64; # introduced=21
     statfs;
-    statfs64;
-    statvfs;
-    statvfs64;
-    stderr;
-    stdin;
-    stdout;
-    stpcpy;
-    stpncpy;
+    statfs64; # introduced=21
+    statvfs; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    statvfs64; # introduced=21
+    stderr; # var introduced=23
+    stdin; # var introduced=23
+    stdout; # var introduced=23
+    stpcpy; # introduced=21
+    stpncpy; # introduced=21
     strcasecmp;
-    strcasecmp_l;
+    strcasecmp_l; # introduced=23
     strcasestr;
     strcat;
     strchr;
     strcmp;
     strcoll;
-    strcoll_l;
+    strcoll_l; # introduced=21
     strcpy;
     strcspn;
     strdup;
     strerror;
-    strerror_l;
+    strerror_l; # introduced=23
     strerror_r;
     strftime;
-    strftime_l;
+    strftime_l; # introduced=21
     strlcat;
     strlcpy;
     strlen;
     strncasecmp;
-    strncasecmp_l;
+    strncasecmp_l; # introduced=23
     strncat;
     strncmp;
     strncpy;
@@ -950,84 +950,84 @@
     strspn;
     strstr;
     strtod;
-    strtof;
+    strtof; # introduced=21
     strtoimax;
     strtok;
     strtok_r;
     strtol;
-    strtold;
-    strtold_l;
+    strtold; # introduced=21
+    strtold_l; # introduced=21
     strtoll;
-    strtoll_l;
-    strtoq;
+    strtoll_l; # introduced=21
+    strtoq; # introduced=21
     strtoul;
     strtoull;
-    strtoull_l;
+    strtoull_l; # introduced=21
     strtoumax;
-    strtouq;
+    strtouq; # introduced=21
     strxfrm;
-    strxfrm_l;
-    swapoff;
-    swapon;
+    strxfrm_l; # introduced=21
+    swapoff; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    swapon; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     swprintf;
     swscanf;
     symlink;
-    symlinkat;
+    symlinkat; # introduced=21
     sync;
-    sys_siglist;
-    sys_signame;
+    sys_siglist; # var
+    sys_signame; # var
     syscall;
     sysconf;
     sysinfo;
     syslog;
     system;
-    tcdrain;
-    tcflow;
-    tcflush;
-    tcgetattr;
+    tcdrain; # introduced=21
+    tcflow; # introduced=21
+    tcflush; # introduced=21
+    tcgetattr; # introduced=21
     tcgetpgrp;
-    tcgetsid;
-    tcsendbreak;
-    tcsetattr;
+    tcgetsid; # introduced=21
+    tcsendbreak; # introduced=21
+    tcsetattr; # introduced=21
     tcsetpgrp;
-    tdelete;
-    tdestroy;
-    tee;
-    telldir;
+    tdelete; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tdestroy; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tee; # introduced=21
+    telldir; # introduced=23
     tempnam;
-    tfind;
-    tgkill;
+    tfind; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
+    tgkill; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     time;
-    timegm;
-    timelocal;
+    timegm; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
+    timelocal; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     timer_create;
     timer_delete;
     timer_getoverrun;
     timer_gettime;
     timer_settime;
-    timerfd_create;
-    timerfd_gettime;
-    timerfd_settime;
+    timerfd_create; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    timerfd_gettime; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
+    timerfd_settime; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
     times;
-    timezone;
+    timezone; # var
     tmpfile;
     tmpnam;
     toascii;
     tolower;
-    tolower_l;
+    tolower_l; # introduced=21
     toupper;
-    toupper_l;
+    toupper_l; # introduced=21
     towlower;
-    towlower_l;
+    towlower_l; # introduced=21
     towupper;
-    towupper_l;
+    towupper_l; # introduced=21
     truncate;
-    truncate64;
-    tsearch;
+    truncate64; # introduced=21
+    tsearch; # introduced-arm=16 introduced-arm64=21 introduced-mips=16 introduced-mips64=21 introduced-x86=16 introduced-x86_64=21
     ttyname;
     ttyname_r;
-    twalk;
-    tzname;
+    twalk; # introduced=21
+    tzname; # var
     tzset;
     umask;
     umount;
@@ -1039,37 +1039,37 @@
     unlinkat;
     unlockpt;
     unsetenv;
-    unshare;
-    uselocale;
+    unshare; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
+    uselocale; # introduced=21
     usleep;
     utime;
-    utimensat;
+    utimensat; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
     utimes;
     utmpname;
     vasprintf;
-    vdprintf;
+    vdprintf; # introduced=21
     verr;
     verrx;
     vfork;
     vfprintf;
     vfscanf;
     vfwprintf;
-    vfwscanf;
-    vmsplice;
+    vfwscanf; # introduced=21
+    vmsplice; # introduced=21
     vprintf;
     vscanf;
     vsnprintf;
     vsprintf;
     vsscanf;
     vswprintf;
-    vswscanf;
+    vswscanf; # introduced=21
     vsyslog;
     vwarn;
     vwarnx;
     vwprintf;
-    vwscanf;
+    vwscanf; # introduced=21
     wait;
-    wait4;
+    wait4; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
     waitid;
     waitpid;
     warn;
@@ -1078,12 +1078,12 @@
     wcpncpy;
     wcrtomb;
     wcscasecmp;
-    wcscasecmp_l;
+    wcscasecmp_l; # introduced=23
     wcscat;
     wcschr;
     wcscmp;
     wcscoll;
-    wcscoll_l;
+    wcscoll_l; # introduced=21
     wcscpy;
     wcscspn;
     wcsdup;
@@ -1092,44 +1092,44 @@
     wcslcpy;
     wcslen;
     wcsncasecmp;
-    wcsncasecmp_l;
+    wcsncasecmp_l; # introduced=23
     wcsncat;
     wcsncmp;
     wcsncpy;
     wcsnlen;
-    wcsnrtombs;
+    wcsnrtombs; # introduced=21
     wcspbrk;
     wcsrchr;
     wcsrtombs;
     wcsspn;
     wcsstr;
     wcstod;
-    wcstof;
-    wcstoimax;
+    wcstof; # introduced=21
+    wcstoimax; # introduced=21
     wcstok;
     wcstol;
-    wcstold;
-    wcstold_l;
-    wcstoll;
-    wcstoll_l;
+    wcstold; # introduced=21
+    wcstold_l; # introduced=21
+    wcstoll; # introduced=21
+    wcstoll_l; # introduced=21
     wcstombs;
     wcstoul;
-    wcstoull;
-    wcstoull_l;
-    wcstoumax;
+    wcstoull; # introduced=21
+    wcstoull_l; # introduced=21
+    wcstoumax; # introduced=21
     wcswidth;
     wcsxfrm;
-    wcsxfrm_l;
+    wcsxfrm_l; # introduced=21
     wctob;
-    wctomb;
+    wctomb; # introduced=21
     wctype;
-    wctype_l;
+    wctype_l; # introduced=21
     wcwidth;
     wmemchr;
     wmemcmp;
     wmemcpy;
     wmemmove;
-    wmempcpy;
+    wmempcpy; # introduced=23
     wmemset;
     wprintf;
     write;
@@ -1139,56 +1139,90 @@
     *;
 };
 
-LIBC_N {
+LIBC_N { # introduced-arm64=24 introduced-mips=24 introduced-mips64=24 introduced-x86=24 introduced-x86_64=24
   global:
-    __fread_chk;
-    __fwrite_chk;
-    __getcwd_chk;
-    __pwrite_chk;
-    __pwrite64_chk;
-    __write_chk;
-    adjtimex;
-    clock_adjtime;
-    fgetpos64;
-    fileno_unlocked;
-    fopen64;
-    freeifaddrs;
-    freopen64;
-    fseeko64;
-    fsetpos64;
-    ftello64;
-    funopen64;
-    getgrgid_r;
-    getgrnam_r;
-    getifaddrs;
-    if_freenameindex;
-    if_nameindex;
-    in6addr_any;
-    in6addr_loopback;
-    lockf;
-    lockf64;
-    preadv;
-    preadv64;
-    pthread_barrierattr_destroy;
-    pthread_barrierattr_getpshared;
-    pthread_barrierattr_init;
-    pthread_barrierattr_setpshared;
-    pthread_barrier_destroy;
-    pthread_barrier_init;
-    pthread_barrier_wait;
-    pthread_spin_destroy;
-    pthread_spin_init;
-    pthread_spin_lock;
-    pthread_spin_trylock;
-    pthread_spin_unlock;
-    pwritev;
-    pwritev64;
-    scandirat;
-    scandirat64;
-    strchrnul;
-    tmpfile64;
+    __fread_chk; # introduced=24
+    __fwrite_chk; # introduced=24
+    __getcwd_chk; # introduced=24
+    __pwrite_chk; # introduced=24
+    __pwrite64_chk; # introduced=24
+    __write_chk; # introduced=24
+    adjtimex; # introduced=24
+    clock_adjtime; # introduced=24
+    fgetpos64; # introduced=24
+    fileno_unlocked; # introduced=24
+    fopen64; # introduced=24
+    freeifaddrs; # introduced=24
+    freopen64; # introduced=24
+    fseeko64; # introduced=24
+    fsetpos64; # introduced=24
+    ftello64; # introduced=24
+    funopen64; # introduced=24
+    getgrgid_r; # introduced=24
+    getgrnam_r; # introduced=24
+    getifaddrs; # introduced=24
+    if_freenameindex; # introduced=24
+    if_nameindex; # introduced=24
+    in6addr_any; # var introduced=24
+    in6addr_loopback; # var introduced=24
+    lockf; # introduced=24
+    lockf64; # introduced=24
+    preadv; # introduced=24
+    preadv64; # introduced=24
+    pthread_barrierattr_destroy; # introduced=24
+    pthread_barrierattr_getpshared; # introduced=24
+    pthread_barrierattr_init; # introduced=24
+    pthread_barrierattr_setpshared; # introduced=24
+    pthread_barrier_destroy; # introduced=24
+    pthread_barrier_init; # introduced=24
+    pthread_barrier_wait; # introduced=24
+    pthread_spin_destroy; # introduced=24
+    pthread_spin_init; # introduced=24
+    pthread_spin_lock; # introduced=24
+    pthread_spin_trylock; # introduced=24
+    pthread_spin_unlock; # introduced=24
+    pwritev; # introduced=24
+    pwritev64; # introduced=24
+    scandirat; # introduced=24
+    scandirat64; # introduced=24
+    strchrnul; # introduced=24
+    tmpfile64; # introduced=24
 } LIBC;
 
+LIBC_O {
+  global:
+    catclose; # future
+    catgets; # future
+    catopen; # future
+    ctermid; # future
+    endgrent; # future
+    endpwent; # future
+    futimes; # future
+    futimesat; # future
+    getdomainname; # future
+    getgrent; # future
+    getpwent; # future
+    getsubopt; # future
+    hasmntopt; # future
+    lutimes; # future
+    mblen; # future
+    pthread_getname_np; # future
+    quotactl; # future
+    setdomainname; # future
+    setgrent; # future
+    setpwent; # future
+    sighold; # future
+    sigignore; # future
+    sigpause; # future
+    sigrelse; # future
+    sigset; # future
+    sync_file_range; # future
+    towctrans; # future
+    towctrans_l; # future
+    wctrans; # future
+    wctrans_l; # future
+} LIBC_N;
+
 LIBC_PRIVATE {
   global:
     android_getaddrinfofornet;
@@ -1198,7 +1232,7 @@
     free_malloc_leak_info;
     get_malloc_leak_info;
     gMallocLeakZygoteChild;
-} LIBC_N;
+} LIBC_O;
 
 LIBC_PLATFORM {
   global:
@@ -1209,4 +1243,4 @@
     malloc_disable;
     malloc_enable;
     malloc_iterate;
-} LIBC_N;
+} LIBC_O;
diff --git a/libc/libstdc++.arm.map b/libc/libstdc++.arm.map
new file mode 100644
index 0000000..63fd8a0
--- /dev/null
+++ b/libc/libstdc++.arm.map
@@ -0,0 +1,19 @@
+# Generated by genversion-scripts.py. Do not edit.
+LIBC_O {
+  global:
+    _ZdaPv;
+    _ZdaPvRKSt9nothrow_t;
+    _ZdlPv;
+    _ZdlPvRKSt9nothrow_t;
+    _Znaj; # arm x86 mips
+    _ZnajRKSt9nothrow_t; # arm x86 mips
+    _Znwj; # arm x86 mips
+    _ZnwjRKSt9nothrow_t; # arm x86 mips
+    _ZSt7nothrow;
+    __cxa_guard_abort;
+    __cxa_guard_acquire;
+    __cxa_guard_release;
+    __cxa_pure_virtual;
+  local:
+    *;
+};
diff --git a/libc/libstdc++.arm64.map b/libc/libstdc++.arm64.map
new file mode 100644
index 0000000..60fe9ab
--- /dev/null
+++ b/libc/libstdc++.arm64.map
@@ -0,0 +1,19 @@
+# Generated by genversion-scripts.py. Do not edit.
+LIBC_O {
+  global:
+    _ZdaPv;
+    _ZdaPvRKSt9nothrow_t;
+    _ZdlPv;
+    _ZdlPvRKSt9nothrow_t;
+    _Znam; # arm64 x86_64 mips64
+    _ZnamRKSt9nothrow_t; # arm64 x86_64 mips64
+    _Znwm; # arm64 x86_64 mips64
+    _ZnwmRKSt9nothrow_t; # arm64 x86_64 mips64
+    _ZSt7nothrow;
+    __cxa_guard_abort;
+    __cxa_guard_acquire;
+    __cxa_guard_release;
+    __cxa_pure_virtual;
+  local:
+    *;
+};
diff --git a/libc/libstdc++.map.txt b/libc/libstdc++.map.txt
new file mode 100644
index 0000000..12e26cd
--- /dev/null
+++ b/libc/libstdc++.map.txt
@@ -0,0 +1,22 @@
+LIBC_O {
+  global:
+    _ZdaPv;
+    _ZdaPvRKSt9nothrow_t;
+    _ZdlPv;
+    _ZdlPvRKSt9nothrow_t;
+    _Znam; # arm64 x86_64 mips64
+    _ZnamRKSt9nothrow_t; # arm64 x86_64 mips64
+    _Znwm; # arm64 x86_64 mips64
+    _ZnwmRKSt9nothrow_t; # arm64 x86_64 mips64
+    _Znaj; # arm x86 mips
+    _ZnajRKSt9nothrow_t; # arm x86 mips
+    _Znwj; # arm x86 mips
+    _ZnwjRKSt9nothrow_t; # arm x86 mips
+    _ZSt7nothrow;
+    __cxa_guard_abort;
+    __cxa_guard_acquire;
+    __cxa_guard_release;
+    __cxa_pure_virtual;
+  local:
+    *;
+};
diff --git a/libc/libstdc++.mips.map b/libc/libstdc++.mips.map
new file mode 100644
index 0000000..63fd8a0
--- /dev/null
+++ b/libc/libstdc++.mips.map
@@ -0,0 +1,19 @@
+# Generated by genversion-scripts.py. Do not edit.
+LIBC_O {
+  global:
+    _ZdaPv;
+    _ZdaPvRKSt9nothrow_t;
+    _ZdlPv;
+    _ZdlPvRKSt9nothrow_t;
+    _Znaj; # arm x86 mips
+    _ZnajRKSt9nothrow_t; # arm x86 mips
+    _Znwj; # arm x86 mips
+    _ZnwjRKSt9nothrow_t; # arm x86 mips
+    _ZSt7nothrow;
+    __cxa_guard_abort;
+    __cxa_guard_acquire;
+    __cxa_guard_release;
+    __cxa_pure_virtual;
+  local:
+    *;
+};
diff --git a/libc/libstdc++.mips64.map b/libc/libstdc++.mips64.map
new file mode 100644
index 0000000..60fe9ab
--- /dev/null
+++ b/libc/libstdc++.mips64.map
@@ -0,0 +1,19 @@
+# Generated by genversion-scripts.py. Do not edit.
+LIBC_O {
+  global:
+    _ZdaPv;
+    _ZdaPvRKSt9nothrow_t;
+    _ZdlPv;
+    _ZdlPvRKSt9nothrow_t;
+    _Znam; # arm64 x86_64 mips64
+    _ZnamRKSt9nothrow_t; # arm64 x86_64 mips64
+    _Znwm; # arm64 x86_64 mips64
+    _ZnwmRKSt9nothrow_t; # arm64 x86_64 mips64
+    _ZSt7nothrow;
+    __cxa_guard_abort;
+    __cxa_guard_acquire;
+    __cxa_guard_release;
+    __cxa_pure_virtual;
+  local:
+    *;
+};
diff --git a/libc/libstdc++.x86.map b/libc/libstdc++.x86.map
new file mode 100644
index 0000000..63fd8a0
--- /dev/null
+++ b/libc/libstdc++.x86.map
@@ -0,0 +1,19 @@
+# Generated by genversion-scripts.py. Do not edit.
+LIBC_O {
+  global:
+    _ZdaPv;
+    _ZdaPvRKSt9nothrow_t;
+    _ZdlPv;
+    _ZdlPvRKSt9nothrow_t;
+    _Znaj; # arm x86 mips
+    _ZnajRKSt9nothrow_t; # arm x86 mips
+    _Znwj; # arm x86 mips
+    _ZnwjRKSt9nothrow_t; # arm x86 mips
+    _ZSt7nothrow;
+    __cxa_guard_abort;
+    __cxa_guard_acquire;
+    __cxa_guard_release;
+    __cxa_pure_virtual;
+  local:
+    *;
+};
diff --git a/libc/libstdc++.x86_64.map b/libc/libstdc++.x86_64.map
new file mode 100644
index 0000000..60fe9ab
--- /dev/null
+++ b/libc/libstdc++.x86_64.map
@@ -0,0 +1,19 @@
+# Generated by genversion-scripts.py. Do not edit.
+LIBC_O {
+  global:
+    _ZdaPv;
+    _ZdaPvRKSt9nothrow_t;
+    _ZdlPv;
+    _ZdlPvRKSt9nothrow_t;
+    _Znam; # arm64 x86_64 mips64
+    _ZnamRKSt9nothrow_t; # arm64 x86_64 mips64
+    _Znwm; # arm64 x86_64 mips64
+    _ZnwmRKSt9nothrow_t; # arm64 x86_64 mips64
+    _ZSt7nothrow;
+    __cxa_guard_abort;
+    __cxa_guard_acquire;
+    __cxa_guard_release;
+    __cxa_pure_virtual;
+  local:
+    *;
+};
diff --git a/libc/malloc_debug/Android.bp b/libc/malloc_debug/Android.bp
new file mode 100644
index 0000000..8ce3ff3
--- /dev/null
+++ b/libc/malloc_debug/Android.bp
@@ -0,0 +1,132 @@
+// ==============================================================
+// libc_malloc_debug_backtrace.a
+// ==============================================================
+// Used by libmemunreachable
+cc_library_static {
+
+    name: "libc_malloc_debug_backtrace",
+
+    srcs: [
+        "backtrace.cpp",
+        "MapData.cpp",
+    ],
+
+    stl: "libc++_static",
+
+    static_libs: ["libc_logging"],
+
+    include_dirs: ["bionic/libc"],
+    export_include_dirs: ["."],
+
+    sanitize: {
+        never: true,
+    },
+    native_coverage: false,
+
+    // -Wno-error=format-zero-length needed for gcc to compile.
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wno-error=format-zero-length",
+    ],
+
+}
+
+// ==============================================================
+// libc_malloc_debug.so
+// ==============================================================
+cc_library {
+    name: "libc_malloc_debug",
+
+    srcs: [
+        "BacktraceData.cpp",
+        "Config.cpp",
+        "DebugData.cpp",
+        "debug_disable.cpp",
+        "FreeTrackData.cpp",
+        "GuardData.cpp",
+        "malloc_debug.cpp",
+        "RecordData.cpp",
+        "TrackData.cpp",
+    ],
+
+    stl: "libc++_static",
+
+    // Only need this for arm since libc++ uses its own unwind code that
+    // doesn't mix with the other default unwind code.
+    arch: {
+        arm: {
+            static_libs: ["libunwind_llvm"],
+        },
+    },
+
+    static_libs: [
+        "libbase",
+        "libc_malloc_debug_backtrace",
+        "libc_logging",
+    ],
+
+    multilib: {
+        lib32: {
+            version_script: "exported32.map",
+        },
+        lib64: {
+            version_script: "exported64.map",
+        },
+    },
+    allow_undefined_symbols: true,
+    include_dirs: ["bionic/libc"],
+
+    sanitize: {
+        never: true,
+    },
+    native_coverage: false,
+
+    // -Wno-error=format-zero-length needed for gcc to compile.
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-fno-stack-protector",
+        "-Wno-error=format-zero-length",
+    ],
+
+}
+
+// ==============================================================
+// Unit Tests
+// ==============================================================
+cc_test {
+
+    name: "malloc_debug_unit_tests",
+    multilib: {
+        lib32: {
+            suffix: "32",
+        },
+        lib64: {
+            suffix: "64",
+        },
+    },
+
+    srcs: [
+        "tests/backtrace_fake.cpp",
+        "tests/log_fake.cpp",
+        "tests/libc_fake.cpp",
+        "tests/property_fake.cpp",
+        "tests/malloc_debug_config_tests.cpp",
+        "tests/malloc_debug_unit_tests.cpp",
+    ],
+
+    whole_static_libs: ["libc_malloc_debug"],
+
+    local_include_dirs: ["tests"],
+    include_dirs: ["bionic/libc"],
+
+    shared_libs: ["libbase"],
+
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wno-error=format-zero-length",
+    ],
+
+}
diff --git a/libc/malloc_debug/Android.mk b/libc/malloc_debug/Android.mk
deleted file mode 100644
index 3576611..0000000
--- a/libc/malloc_debug/Android.mk
+++ /dev/null
@@ -1,109 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-
-libc_malloc_debug_src_files := \
-    BacktraceData.cpp \
-    Config.cpp \
-    DebugData.cpp \
-    debug_disable.cpp \
-    FreeTrackData.cpp \
-    GuardData.cpp \
-    malloc_debug.cpp \
-    TrackData.cpp \
-
-# ==============================================================
-# libc_malloc_debug_backtrace.a
-# ==============================================================
-# Used by libmemunreachable
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := libc_malloc_debug_backtrace
-
-LOCAL_SRC_FILES := \
-    backtrace.cpp \
-    MapData.cpp \
-
-LOCAL_CXX_STL := libc++_static
-
-LOCAL_STATIC_LIBRARIES += \
-    libc_logging \
-
-LOCAL_C_INCLUDES += bionic/libc
-LOCAL_EXPORT_C_INCLUDE_DIRS += $(LOCAL_PATH)
-
-LOCAL_SANITIZE := never
-LOCAL_NATIVE_COVERAGE := false
-
-# -Wno-error=format-zero-length needed for gcc to compile.
-LOCAL_CFLAGS := \
-    -Wall \
-    -Werror \
-    -Wno-error=format-zero-length \
-
-include $(BUILD_STATIC_LIBRARY)
-
-# ==============================================================
-# libc_malloc_debug.so
-# ==============================================================
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := libc_malloc_debug
-
-LOCAL_SRC_FILES := \
-    $(libc_malloc_debug_src_files) \
-
-LOCAL_CXX_STL := libc++_static
-
-# Only need this for arm since libc++ uses its own unwind code that
-# doesn't mix with the other default unwind code.
-LOCAL_STATIC_LIBRARIES_arm := libunwind_llvm
-
-LOCAL_STATIC_LIBRARIES += \
-    libc_malloc_debug_backtrace \
-    libc_logging \
-
-LOCAL_LDFLAGS_32 := -Wl,--version-script,$(LOCAL_PATH)/exported32.map
-LOCAL_LDFLAGS_64 := -Wl,--version-script,$(LOCAL_PATH)/exported64.map
-LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
-LOCAL_C_INCLUDES += bionic/libc
-
-LOCAL_SANITIZE := never
-LOCAL_NATIVE_COVERAGE := false
-
-# -Wno-error=format-zero-length needed for gcc to compile.
-LOCAL_CFLAGS := \
-    -Wall \
-    -Werror \
-    -fno-stack-protector \
-    -Wno-error=format-zero-length \
-
-include $(BUILD_SHARED_LIBRARY)
-
-# ==============================================================
-# Unit Tests
-# ==============================================================
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := malloc_debug_unit_tests
-LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
-LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
-
-LOCAL_SRC_FILES := \
-    tests/backtrace_fake.cpp \
-    tests/log_fake.cpp \
-    tests/libc_fake.cpp \
-    tests/property_fake.cpp \
-    tests/malloc_debug_config_tests.cpp \
-    tests/malloc_debug_unit_tests.cpp \
-    $(libc_malloc_debug_src_files) \
-
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/tests
-LOCAL_C_INCLUDES += bionic/libc
-
-LOCAL_SHARED_LIBRARIES := libbase
-
-LOCAL_CFLAGS := \
-    -Wall \
-    -Werror \
-    -Wno-error=format-zero-length \
-
-include $(BUILD_NATIVE_TEST)
diff --git a/libc/malloc_debug/BacktraceData.cpp b/libc/malloc_debug/BacktraceData.cpp
index 400e282..3d46bf0 100644
--- a/libc/malloc_debug/BacktraceData.cpp
+++ b/libc/malloc_debug/BacktraceData.cpp
@@ -41,27 +41,24 @@
 #include "debug_log.h"
 #include "malloc_debug.h"
 
-BacktraceData::BacktraceData(const Config& config, size_t* offset) {
+static void EnableToggle(int, siginfo_t*, void*) {
+  if (g_debug->backtrace->enabled()) {
+    g_debug->backtrace->set_enabled(false);
+  } else {
+    g_debug->backtrace->set_enabled(true);
+  }
+}
+
+BacktraceData::BacktraceData(DebugData* debug_data, const Config& config, size_t* offset)
+    : OptionData(debug_data) {
   size_t hdr_len = sizeof(BacktraceHeader) + sizeof(uintptr_t) * config.backtrace_frames;
   alloc_offset_ = *offset;
   *offset += BIONIC_ALIGN(hdr_len, MINIMUM_ALIGNMENT_BYTES);
 }
 
-static BacktraceData* g_backtrace_data = nullptr;
-
-static void EnableToggle(int, siginfo_t*, void*) {
-  if (g_backtrace_data->enabled()) {
-    g_backtrace_data->set_enabled(false);
-  } else {
-    g_backtrace_data->set_enabled(true);
-  }
-}
-
 bool BacktraceData::Initialize(const Config& config) {
   enabled_ = config.backtrace_enabled;
   if (config.backtrace_enable_on_signal) {
-    g_backtrace_data = this;
-
     struct sigaction enable_act;
     memset(&enable_act, 0, sizeof(enable_act));
 
diff --git a/libc/malloc_debug/BacktraceData.h b/libc/malloc_debug/BacktraceData.h
index 842e372..dbc3989 100644
--- a/libc/malloc_debug/BacktraceData.h
+++ b/libc/malloc_debug/BacktraceData.h
@@ -33,12 +33,14 @@
 
 #include <private/bionic_macros.h>
 
+#include "OptionData.h"
+
 // Forward declarations.
 struct Config;
 
-class BacktraceData {
+class BacktraceData : public OptionData {
  public:
-  BacktraceData(const Config& config, size_t* offset);
+  BacktraceData(DebugData* debug_data, const Config& config, size_t* offset);
   virtual ~BacktraceData() = default;
 
   bool Initialize(const Config& config);
diff --git a/libc/malloc_debug/Config.cpp b/libc/malloc_debug/Config.cpp
index cc60086..885542e 100644
--- a/libc/malloc_debug/Config.cpp
+++ b/libc/malloc_debug/Config.cpp
@@ -64,29 +64,126 @@
 static constexpr size_t DEFAULT_FREE_TRACK_ALLOCATIONS = 100;
 static constexpr size_t MAX_FREE_TRACK_ALLOCATIONS = 16384;
 
-struct Feature {
-  Feature(std::string name, size_t default_value, size_t min_value, size_t max_value,
-          uint64_t option, size_t* value, bool* config, bool combo_option)
-      : name(name), default_value(default_value), min_value(min_value), max_value(max_value),
-        option(option), value(value), config(config), combo_option(combo_option) {}
-  std::string name;
-  size_t default_value = 0;
-  size_t min_value = 0;
-  size_t max_value = 0;
+static constexpr size_t DEFAULT_RECORD_ALLOCS = 8000000;
+static constexpr size_t MAX_RECORD_ALLOCS = 50000000;
+static constexpr const char DEFAULT_RECORD_ALLOCS_FILE[] = "/data/local/tmp/record_allocs.txt";
 
-  uint64_t option = 0;
-  size_t* value = nullptr;
-  bool* config = nullptr;
+struct Option {
+  Option(std::string name, uint64_t option, bool combo_option = false, bool* config = nullptr)
+      : name(name), option(option), combo_option(combo_option), config(config) {}
+  virtual ~Option() = default;
+
+  std::string name;
+
+  uint64_t option;
   // If set to true, then all of the options following are set on until
-  // for which the combo_option value is set.
+  // the combo_option value is set to false.
   bool combo_option = false;
+  bool* config;
+
+  virtual bool ParseValue(const std::string& option_name, const std::string& value) const;
+
+  virtual void SetDefault() const { }
 };
 
+bool Option::ParseValue(const std::string& option_name, const std::string& raw_value) const {
+  if (!raw_value.empty()) {
+    error_log("%s: value set for option '%s' which does not take a value",
+              getprogname(), option_name.c_str());
+    return false;
+  }
+  return true;
+}
+
+struct OptionString : public Option {
+  OptionString(std::string name, uint64_t option, std::string default_value,
+                std::string* value, bool combo_option = false,
+                bool* config = nullptr)
+      : Option(name, option, combo_option, config), default_value(default_value), value(value) {}
+  virtual ~OptionString() = default;
+
+  std::string default_value;
+  std::string* value;
+
+  bool ParseValue(const std::string& option_name, const std::string& value) const override;
+
+  void SetDefault() const override { if (value) *value = default_value; }
+};
+
+bool OptionString::ParseValue(const std::string&, const std::string& raw_value) const {
+  if (!raw_value.empty()) {
+    *value = raw_value;
+  }
+  return true;
+}
+
+struct OptionSizeT : public Option {
+  OptionSizeT(std::string name, size_t default_value, size_t min_value, size_t max_value,
+          uint64_t option, size_t* value, bool combo_option = false, bool* config = nullptr)
+      : Option(name, option, combo_option, config), default_value(default_value),
+        min_value(min_value), max_value(max_value), value(value) {}
+  virtual ~OptionSizeT() = default;
+
+  size_t default_value;
+  size_t min_value;
+  size_t max_value;
+
+  size_t* value;
+
+  bool ParseValue(const std::string& option_name, const std::string& value) const override;
+
+  void SetDefault() const override { if (value) *value = default_value; }
+};
+
+bool OptionSizeT::ParseValue(const std::string& option_name, const std::string& raw_value) const {
+  if (raw_value.empty()) {
+    // Value should have been set by the SetDefault() pass.
+    return true;
+  }
+
+  // Parse the value into a size_t value.
+  errno = 0;
+  char* end;
+  long parsed_value = strtol(raw_value.c_str(), &end, 10);
+  if (errno != 0) {
+    error_log("%s: bad value for option '%s': %s", getprogname(), option_name.c_str(),
+              strerror(errno));
+    return false;
+  }
+  if (end == raw_value.c_str()) {
+    error_log("%s: bad value for option '%s'", getprogname(), option_name.c_str());
+    return false;
+  }
+  if (static_cast<size_t>(end - raw_value.c_str()) != raw_value.size()) {
+    error_log("%s: bad value for option '%s', non space found after option: %s",
+              getprogname(), option_name.c_str(), end);
+    return false;
+  }
+  if (parsed_value < 0) {
+    error_log("%s: bad value for option '%s', value cannot be negative: %ld",
+              getprogname(), option_name.c_str(), parsed_value);
+    return false;
+  }
+
+  if (static_cast<size_t>(parsed_value) < min_value) {
+    error_log("%s: bad value for option '%s', value must be >= %zu: %ld",
+              getprogname(), option_name.c_str(), min_value, parsed_value);
+    return false;
+  }
+  if (static_cast<size_t>(parsed_value) > max_value) {
+    error_log("%s: bad value for option '%s', value must be <= %zu: %ld",
+              getprogname(), option_name.c_str(), max_value, parsed_value);
+    return false;
+  }
+  *value = static_cast<size_t>(parsed_value);
+  return true;
+}
+
 class PropertyParser {
  public:
-  PropertyParser(const char* property) : cur_(property) {}
+  explicit PropertyParser(const char* property) : cur_(property) {}
 
-  bool Get(std::string* property, size_t* value, bool* value_set);
+  bool Get(std::string* property, std::string* value);
 
   bool Done() { return done_; }
 
@@ -100,7 +197,7 @@
   DISALLOW_COPY_AND_ASSIGN(PropertyParser);
 };
 
-bool PropertyParser::Get(std::string* property, size_t* value, bool* value_set) {
+bool PropertyParser::Get(std::string* property, std::string* value) {
   // Process each property name we can find.
   while (isspace(*cur_))
     ++cur_;
@@ -110,44 +207,30 @@
     return false;
   }
 
-  const char* property_start = cur_;
+  const char* start = cur_;
   while (!isspace(*cur_) && *cur_ != '=' && *cur_ != '\0')
     ++cur_;
 
-  *property = std::string(property_start, cur_ - property_start);
+  *property = std::string(start, cur_ - start);
 
   // Skip any spaces after the name.
-  while (isspace(*cur_) && *cur_ != '=' && *cur_ != '\0')
+  while (isspace(*cur_))
     ++cur_;
 
+  value->clear();
   if (*cur_ == '=') {
     ++cur_;
-    errno = 0;
-    *value_set = true;
-    char* end;
-    long read_value = strtol(cur_, const_cast<char**>(&end), 10);
-    if (errno != 0) {
-      error_log("%s: bad value for option '%s': %s", getprogname(), property->c_str(),
-                strerror(errno));
-      return false;
+    // Skip the space after the equal.
+    while (isspace(*cur_))
+      ++cur_;
+
+    start = cur_;
+    while (!isspace(*cur_) && *cur_ != '\0')
+      ++cur_;
+
+    if (cur_ != start) {
+      *value = std::string(start, cur_ - start);
     }
-    if (cur_ == end || (!isspace(*end) && *end != '\0')) {
-      if (cur_ == end) {
-        error_log("%s: bad value for option '%s'", getprogname(), property->c_str());
-      } else {
-        error_log("%s: bad value for option '%s', non space found after option: %s",
-                  getprogname(), property->c_str(), end);
-      }
-      return false;
-    } else if (read_value < 0) {
-      error_log("%s: bad value for option '%s', value cannot be negative: %ld",
-                getprogname(), property->c_str(), read_value);
-      return false;
-    }
-    *value = static_cast<size_t>(read_value);
-    cur_ = end;
-  } else {
-    *value_set = false;
   }
   return true;
 }
@@ -229,34 +312,19 @@
   error_log("");
   error_log("  leak_track");
   error_log("    Enable the leak tracking of memory allocations.");
-}
-
-static bool SetFeature(
-    const std::string name, const Feature& feature, size_t value, bool value_set) {
-  if (feature.config) {
-    *feature.config = true;
-  }
-  if (feature.value != nullptr) {
-    if (value_set) {
-      if (value < feature.min_value) {
-        error_log("%s: bad value for option '%s', value must be >= %zu: %zu",
-                  getprogname(), name.c_str(), feature.min_value, value);
-        return false;
-      } else if (value > feature.max_value) {
-        error_log("%s: bad value for option '%s', value must be <= %zu: %zu",
-                  getprogname(), name.c_str(), feature.max_value, value);
-        return false;
-      }
-      *feature.value = value;
-    } else {
-      *feature.value = feature.default_value;
-    }
-  } else if (value_set) {
-     error_log("%s: value set for option '%s' which does not take a value",
-               getprogname(), name.c_str());
-     return false;
-  }
-  return true;
+  error_log("");
+  error_log("  record_allocs[=XX]");
+  error_log("    Record every single allocation/free call. When a specific signal");
+  error_log("    is sent to the process, the contents of recording are written to");
+  error_log("    a file (%s) and the recording is cleared.", DEFAULT_RECORD_ALLOCS_FILE);
+  error_log("    If XX is set, that is the total number of allocations/frees that can");
+  error_log("    recorded. of frames to capture. The default value is %zu.", DEFAULT_RECORD_ALLOCS);
+  error_log("    If the allocation list fills up, all further allocations are not recorded.");
+  error_log("");
+  error_log("  record_alloc_file[=FILE]");
+  error_log("    This option only has meaning if the record_allocs options has been specified.");
+  error_log("    This is the name of the file to which recording information will be dumped.");
+  error_log("    The default is %s.", DEFAULT_RECORD_ALLOCS_FILE);
 }
 
 // This function is designed to be called once. A second call will not
@@ -274,88 +342,123 @@
   front_guard_value = DEFAULT_FRONT_GUARD_VALUE;
   rear_guard_value = DEFAULT_REAR_GUARD_VALUE;
   backtrace_signal = SIGRTMAX - 19;
-  free_track_backtrace_num_frames = 16;
+  record_allocs_signal = SIGRTMAX - 18;
+  free_track_backtrace_num_frames = 0;
+  record_allocs_file.clear();
 
   // Parse the options are of the format:
   //   option_name or option_name=XX
 
-  // Supported features:
-  const Feature features[] = {
-    Feature("guard", DEFAULT_GUARD_BYTES, 1, MAX_GUARD_BYTES, 0, nullptr, nullptr, true),
-    // Enable front guard. Value is the size of the guard.
-    Feature("front_guard", DEFAULT_GUARD_BYTES, 1, MAX_GUARD_BYTES, FRONT_GUARD,
-            &this->front_guard_bytes, nullptr, true),
-    // Enable end guard. Value is the size of the guard.
-    Feature("rear_guard", DEFAULT_GUARD_BYTES, 1, MAX_GUARD_BYTES, REAR_GUARD,
-            &this->rear_guard_bytes, nullptr, true),
+  // Supported options:
+  const OptionSizeT option_guard(
+      "guard", DEFAULT_GUARD_BYTES, 1, MAX_GUARD_BYTES, 0, nullptr, true);
+  // Enable front guard. Value is the size of the guard.
+  const OptionSizeT option_front_guard(
+      "front_guard", DEFAULT_GUARD_BYTES, 1, MAX_GUARD_BYTES, FRONT_GUARD,
+      &this->front_guard_bytes, true);
+  // Enable end guard. Value is the size of the guard.
+  const OptionSizeT option_rear_guard(
+      "rear_guard", DEFAULT_GUARD_BYTES, 1, MAX_GUARD_BYTES, REAR_GUARD, &this->rear_guard_bytes,
+      true);
 
-    // Enable logging the backtrace on allocation. Value is the total
-    // number of frames to log.
-    Feature("backtrace", DEFAULT_BACKTRACE_FRAMES, 1, MAX_BACKTRACE_FRAMES,
-            BACKTRACE | TRACK_ALLOCS, &this->backtrace_frames, &this->backtrace_enabled, false),
-    // Enable gathering backtrace values on a signal.
-    Feature("backtrace_enable_on_signal", DEFAULT_BACKTRACE_FRAMES, 1, MAX_BACKTRACE_FRAMES,
-            BACKTRACE | TRACK_ALLOCS, &this->backtrace_frames, &this->backtrace_enable_on_signal,
-            false),
+  // Enable logging the backtrace on allocation. Value is the total
+  // number of frames to log.
+  const OptionSizeT option_backtrace(
+      "backtrace", DEFAULT_BACKTRACE_FRAMES, 1, MAX_BACKTRACE_FRAMES, BACKTRACE | TRACK_ALLOCS,
+      &this->backtrace_frames, false, &this->backtrace_enabled);
+  // Enable gathering backtrace values on a signal.
+  const OptionSizeT option_backtrace_enable_on_signal(
+      "backtrace_enable_on_signal", DEFAULT_BACKTRACE_FRAMES, 1, MAX_BACKTRACE_FRAMES,
+      BACKTRACE | TRACK_ALLOCS, &this->backtrace_frames, false, &this->backtrace_enable_on_signal);
 
-    Feature("fill", SIZE_MAX, 1, SIZE_MAX, 0, nullptr, nullptr, true),
-    // Fill the allocation with an arbitrary pattern on allocation.
-    // Value is the number of bytes of the allocation to fill
-    // (default entire allocation).
-    Feature("fill_on_alloc", SIZE_MAX, 1, SIZE_MAX, FILL_ON_ALLOC, &this->fill_on_alloc_bytes,
-            nullptr, true),
-    // Fill the allocation with an arbitrary pattern on free.
-    // Value is the number of bytes of the allocation to fill
-    // (default entire allocation).
-    Feature("fill_on_free", SIZE_MAX, 1, SIZE_MAX, FILL_ON_FREE, &this->fill_on_free_bytes, nullptr, true),
+  const OptionSizeT option_fill("fill", SIZE_MAX, 1, SIZE_MAX, 0, nullptr, true);
+  // Fill the allocation with an arbitrary pattern on allocation.
+  // Value is the number of bytes of the allocation to fill
+  // (default entire allocation).
+  const OptionSizeT option_fill_on_alloc(
+      "fill_on_alloc", SIZE_MAX, 1, SIZE_MAX, FILL_ON_ALLOC, &this->fill_on_alloc_bytes, true);
+  // Fill the allocation with an arbitrary pattern on free.
+  // Value is the number of bytes of the allocation to fill
+  // (default entire allocation).
+  const OptionSizeT option_fill_on_free(
+      "fill_on_free", SIZE_MAX, 1, SIZE_MAX, FILL_ON_FREE, &this->fill_on_free_bytes, true);
 
-    // Expand the size of every alloc by this number bytes. Value is
-    // the total number of bytes to expand every allocation by.
-    Feature ("expand_alloc", DEFAULT_EXPAND_BYTES, 1, MAX_EXPAND_BYTES, EXPAND_ALLOC,
-             &this->expand_alloc_bytes, nullptr, false),
+  // Expand the size of every alloc by this number bytes. Value is
+  // the total number of bytes to expand every allocation by.
+  const OptionSizeT option_expand_alloc(
+      "expand_alloc", DEFAULT_EXPAND_BYTES, 1, MAX_EXPAND_BYTES, EXPAND_ALLOC,
+      &this->expand_alloc_bytes);
 
-    // Keep track of the freed allocations and verify at a later date
-    // that they have not been used. Turning this on, also turns on
-    // fill on free.
-    Feature("free_track", DEFAULT_FREE_TRACK_ALLOCATIONS, 1, MAX_FREE_TRACK_ALLOCATIONS,
-            FREE_TRACK | FILL_ON_FREE, &this->free_track_allocations, nullptr, false),
-    // Number of backtrace frames to keep when free_track is enabled. If this
-    // value is set to zero, no backtrace will be kept.
-    Feature("free_track_backtrace_num_frames", DEFAULT_BACKTRACE_FRAMES,
-            0, MAX_BACKTRACE_FRAMES, 0, &this->free_track_backtrace_num_frames, nullptr, false),
+  // Keep track of the freed allocations and verify at a later date
+  // that they have not been used. Turning this on, also turns on
+  // fill on free.
+  const OptionSizeT option_free_track(
+      "free_track", DEFAULT_FREE_TRACK_ALLOCATIONS, 1, MAX_FREE_TRACK_ALLOCATIONS,
+      FREE_TRACK | FILL_ON_FREE, &this->free_track_allocations);
+  // Number of backtrace frames to keep when free_track is enabled. If this
+  // value is set to zero, no backtrace will be kept.
+  const OptionSizeT option_free_track_backtrace_num_frames(
+      "free_track_backtrace_num_frames", DEFAULT_BACKTRACE_FRAMES, 0, MAX_BACKTRACE_FRAMES, 0,
+      &this->free_track_backtrace_num_frames);
 
-    // Enable printing leaked allocations.
-    Feature("leak_track", 0, 0, 0, LEAK_TRACK | TRACK_ALLOCS, nullptr, nullptr, false),
+  // Enable printing leaked allocations.
+  const Option option_leak_track("leak_track", LEAK_TRACK | TRACK_ALLOCS);
+
+  const OptionSizeT option_record_allocs(
+      "record_allocs", DEFAULT_RECORD_ALLOCS, 1, MAX_RECORD_ALLOCS, RECORD_ALLOCS,
+      &this->record_allocs_num_entries);
+  const OptionString option_record_allocs_file(
+      "record_allocs_file", 0, DEFAULT_RECORD_ALLOCS_FILE, &this->record_allocs_file);
+
+  const Option* option_list[] = {
+    &option_guard, &option_front_guard, &option_rear_guard,
+    &option_backtrace, &option_backtrace_enable_on_signal,
+    &option_fill, &option_fill_on_alloc, &option_fill_on_free,
+    &option_expand_alloc,
+    &option_free_track, &option_free_track_backtrace_num_frames,
+    &option_leak_track,
+    &option_record_allocs, &option_record_allocs_file,
   };
 
+  // Set defaults for all of the options.
+  for (size_t i = 0; i < sizeof(option_list)/sizeof(Option*); i++) {
+    option_list[i]->SetDefault();
+  }
+
   // Process each property name we can find.
-  std::string property;
-  size_t value;
-  bool value_set;
   PropertyParser parser(property_str);
   bool valid = true;
-  while (valid && parser.Get(&property, &value, &value_set)) {
+  std::string property;
+  std::string value;
+  while (valid && parser.Get(&property, &value)) {
     bool found = false;
-    for (size_t i = 0; i < sizeof(features)/sizeof(Feature); i++) {
-      if (property == features[i].name) {
-        if (features[i].option == 0 && features[i].combo_option) {
+    for (size_t i = 0; i < sizeof(option_list)/sizeof(Option*); i++) {
+      if (property == option_list[i]->name) {
+        if (option_list[i]->option == 0 && option_list[i]->combo_option) {
+          const std::string* option_name = &option_list[i]->name;
           i++;
-          for (; i < sizeof(features)/sizeof(Feature) && features[i].combo_option; i++) {
-            if (!SetFeature(property, features[i], value, value_set)) {
+          for (; i < sizeof(option_list)/sizeof(Option*) && option_list[i]->combo_option; i++) {
+            if (!option_list[i]->ParseValue(*option_name, value)) {
               valid = false;
               break;
             }
-            options |= features[i].option;
+            if (option_list[i]->config) {
+              *option_list[i]->config = true;
+            }
+            options |= option_list[i]->option;
           }
           if (!valid) {
             break;
           }
         } else {
-          if (!SetFeature(property, features[i], value, value_set)) {
+          if (!option_list[i]->ParseValue(option_list[i]->name, value)) {
             valid = false;
             break;
           }
-          options |= features[i].option;
+          if (option_list[i]->config) {
+            *option_list[i]->config = true;
+          }
+          options |= option_list[i]->option;
         }
         found = true;
         break;
@@ -376,13 +479,6 @@
     if (options & FRONT_GUARD) {
       front_guard_bytes = BIONIC_ALIGN(front_guard_bytes, MINIMUM_ALIGNMENT_BYTES);
     }
-
-    // This situation can occur if the free_track option is specified and
-    // the fill_on_free option is not. In this case, indicate the whole
-    // allocation should be filled.
-    if ((options & FILL_ON_FREE) && fill_on_free_bytes == 0) {
-      fill_on_free_bytes = SIZE_MAX;
-    }
   } else {
     parser.LogUsage();
   }
diff --git a/libc/malloc_debug/Config.h b/libc/malloc_debug/Config.h
index cb1de5a..ac620ad 100644
--- a/libc/malloc_debug/Config.h
+++ b/libc/malloc_debug/Config.h
@@ -31,6 +31,8 @@
 
 #include <stdint.h>
 
+#include <string>
+
 constexpr uint64_t FRONT_GUARD = 0x1;
 constexpr uint64_t REAR_GUARD = 0x2;
 constexpr uint64_t BACKTRACE = 0x4;
@@ -40,6 +42,7 @@
 constexpr uint64_t FREE_TRACK = 0x40;
 constexpr uint64_t TRACK_ALLOCS = 0x80;
 constexpr uint64_t LEAK_TRACK = 0x100;
+constexpr uint64_t RECORD_ALLOCS = 0x200;
 
 // In order to guarantee posix compliance, set the minimum alignment
 // to 8 bytes for 32 bit systems and 16 bytes for 64 bit systems.
@@ -49,8 +52,8 @@
 constexpr size_t MINIMUM_ALIGNMENT_BYTES = 8;
 #endif
 
-// If only one or more of these options is set, then no special header is needed.
-constexpr uint64_t NO_HEADER_OPTIONS = FILL_ON_ALLOC | FILL_ON_FREE | EXPAND_ALLOC;
+// If one or more of these options is set, then a special header is needed.
+constexpr uint64_t HEADER_OPTIONS = FRONT_GUARD | REAR_GUARD | BACKTRACE | FREE_TRACK | LEAK_TRACK;
 
 struct Config {
   bool SetFromProperties();
@@ -71,6 +74,10 @@
   size_t free_track_allocations = 0;
   size_t free_track_backtrace_num_frames = 0;
 
+  int record_allocs_signal = 0;
+  size_t record_allocs_num_entries = 0;
+  std::string record_allocs_file;
+
   uint64_t options = 0;
   uint8_t fill_alloc_value;
   uint8_t fill_free_value;
diff --git a/libc/malloc_debug/DebugData.cpp b/libc/malloc_debug/DebugData.cpp
index 0447566..fdc2810 100644
--- a/libc/malloc_debug/DebugData.cpp
+++ b/libc/malloc_debug/DebugData.cpp
@@ -43,37 +43,44 @@
   }
 
   // Check to see if the options that require a header are enabled.
-  if ((config_.options & ~(NO_HEADER_OPTIONS)) != 0) {
+  if (config_.options & HEADER_OPTIONS) {
     need_header_ = true;
 
     // Initialize all of the static header offsets.
     pointer_offset_ = BIONIC_ALIGN(sizeof(Header), MINIMUM_ALIGNMENT_BYTES);
 
     if (config_.options & BACKTRACE) {
-      backtrace.reset(new BacktraceData(config_, &pointer_offset_));
+      backtrace.reset(new BacktraceData(this, config_, &pointer_offset_));
       if (!backtrace->Initialize(config_)) {
         return false;
       }
     }
 
     if (config_.options & FRONT_GUARD) {
-      front_guard.reset(new FrontGuardData(config_, &pointer_offset_));
+      front_guard.reset(new FrontGuardData(this, config_, &pointer_offset_));
     }
 
     extra_bytes_ = pointer_offset_;
 
     // Initialize all of the non-header data.
     if (config_.options & REAR_GUARD) {
-      rear_guard.reset(new RearGuardData(config_));
+      rear_guard.reset(new RearGuardData(this, config_));
       extra_bytes_ += config_.rear_guard_bytes;
     }
 
     if (config_.options & FREE_TRACK) {
-      free_track.reset(new FreeTrackData(config_));
+      free_track.reset(new FreeTrackData(this, config_));
     }
 
     if (config_.options & TRACK_ALLOCS) {
-      track.reset(new TrackData());
+      track.reset(new TrackData(this));
+    }
+  }
+
+  if (config_.options & RECORD_ALLOCS) {
+    record.reset(new RecordData());
+    if (!record->Initialize(config_)) {
+      return false;
     }
   }
 
diff --git a/libc/malloc_debug/DebugData.h b/libc/malloc_debug/DebugData.h
index 4600b33..7e2df0c 100644
--- a/libc/malloc_debug/DebugData.h
+++ b/libc/malloc_debug/DebugData.h
@@ -41,6 +41,7 @@
 #include "FreeTrackData.h"
 #include "GuardData.h"
 #include "malloc_debug.h"
+#include "RecordData.h"
 #include "TrackData.h"
 
 class DebugData {
@@ -91,6 +92,7 @@
   std::unique_ptr<FrontGuardData> front_guard;
   std::unique_ptr<RearGuardData> rear_guard;
   std::unique_ptr<FreeTrackData> free_track;
+  std::unique_ptr<RecordData> record;
 
  private:
   size_t extra_bytes_ = 0;
@@ -103,4 +105,6 @@
   DISALLOW_COPY_AND_ASSIGN(DebugData);
 };
 
+extern DebugData* g_debug;
+
 #endif // MALLOC_DEBUG_DEBUGDATA_H
diff --git a/libc/malloc_debug/FreeTrackData.cpp b/libc/malloc_debug/FreeTrackData.cpp
index 470f40b..8e6502e 100644
--- a/libc/malloc_debug/FreeTrackData.cpp
+++ b/libc/malloc_debug/FreeTrackData.cpp
@@ -36,19 +36,16 @@
 #include "FreeTrackData.h"
 #include "malloc_debug.h"
 
-FreeTrackData::FreeTrackData(const Config& config)
-    : backtrace_num_frames_(config.free_track_backtrace_num_frames) {
+FreeTrackData::FreeTrackData(DebugData* debug, const Config& config)
+    : OptionData(debug), backtrace_num_frames_(config.free_track_backtrace_num_frames) {
   cmp_mem_.resize(4096);
   memset(cmp_mem_.data(), config.fill_free_value, cmp_mem_.size());
 }
 
-void FreeTrackData::LogFreeError(DebugData& debug, const Header* header,
-                                 const uint8_t* pointer) {
-  ScopedDisableDebugCalls disable;
-
+void FreeTrackData::LogFreeError(const Header* header, const uint8_t* pointer) {
   error_log(LOG_DIVIDER);
   error_log("+++ ALLOCATION %p USED AFTER FREE", pointer);
-  uint8_t fill_free_value = debug.config().fill_free_value;
+  uint8_t fill_free_value = debug_->config().fill_free_value;
   for (size_t i = 0; i < header->usable_size; i++) {
     if (pointer[i] != fill_free_value) {
       error_log("  allocation[%zu] = 0x%02x (expected 0x%02x)", i, pointer[i], fill_free_value);
@@ -63,10 +60,8 @@
   error_log(LOG_DIVIDER);
 }
 
-void FreeTrackData::VerifyAndFree(DebugData& debug, const Header* header,
-                                  const void* pointer) {
-  ScopedDisableDebugCalls disable;
-
+void FreeTrackData::VerifyAndFree(const Header* header) {
+  const void* pointer = debug_->GetPointer(header);
   if (header->tag != DEBUG_FREE_TAG) {
     error_log(LOG_DIVIDER);
     error_log("+++ ALLOCATION %p HAS CORRUPTED HEADER TAG 0x%x AFTER FREE", pointer, header->tag);
@@ -74,11 +69,12 @@
   } else {
     const uint8_t* memory = reinterpret_cast<const uint8_t*>(pointer);
     size_t bytes = header->usable_size;
-    bytes = (bytes < debug.config().fill_on_free_bytes) ? bytes : debug.config().fill_on_free_bytes;
+    bytes = (bytes < debug_->config().fill_on_free_bytes) ? bytes
+        : debug_->config().fill_on_free_bytes;
     while (bytes > 0) {
       size_t bytes_to_cmp = (bytes < cmp_mem_.size()) ? bytes : cmp_mem_.size();
       if (memcmp(memory, cmp_mem_.data(), bytes_to_cmp) != 0) {
-        LogFreeError(debug, header, reinterpret_cast<const uint8_t*>(pointer));
+        LogFreeError(header, reinterpret_cast<const uint8_t*>(pointer));
         break;
       }
       bytes -= bytes_to_cmp;
@@ -94,14 +90,11 @@
   g_dispatch->free(header->orig_pointer);
 }
 
-void FreeTrackData::Add(DebugData& debug, const Header* header) {
-  // Make sure the stl calls below don't call the debug_XXX functions.
-  ScopedDisableDebugCalls disable;
-
+void FreeTrackData::Add(const Header* header) {
   pthread_mutex_lock(&mutex_);
-  if (list_.size() == debug.config().free_track_allocations) {
+  if (list_.size() == debug_->config().free_track_allocations) {
     const Header* old_header = list_.back();
-    VerifyAndFree(debug, old_header, debug.GetPointer(old_header));
+    VerifyAndFree(old_header);
     list_.pop_back();
   }
 
@@ -118,19 +111,14 @@
   pthread_mutex_unlock(&mutex_);
 }
 
-void FreeTrackData::VerifyAll(DebugData& debug) {
-  // Make sure the stl calls below don't call the debug_XXX functions.
-  ScopedDisableDebugCalls disable;
-
+void FreeTrackData::VerifyAll() {
   for (const auto& header : list_) {
-    VerifyAndFree(debug, header, debug.GetPointer(header));
+    VerifyAndFree(header);
   }
   list_.clear();
 }
 
 void FreeTrackData::LogBacktrace(const Header* header) {
-  ScopedDisableDebugCalls disable;
-
   auto back_iter = backtraces_.find(header);
   if (back_iter == backtraces_.end()) {
     return;
diff --git a/libc/malloc_debug/FreeTrackData.h b/libc/malloc_debug/FreeTrackData.h
index 804b5a6..21f845f 100644
--- a/libc/malloc_debug/FreeTrackData.h
+++ b/libc/malloc_debug/FreeTrackData.h
@@ -38,26 +38,28 @@
 
 #include <private/bionic_macros.h>
 
-// Forward declarations.
-struct Header;
-class DebugData;
-struct Config;
-struct BacktraceHeader;
+#include "OptionData.h"
 
-class FreeTrackData {
+// Forward declarations.
+struct BacktraceHeader;
+struct Config;
+class DebugData;
+struct Header;
+
+class FreeTrackData : public OptionData {
  public:
-  FreeTrackData(const Config& config);
+  FreeTrackData(DebugData* debug_data, const Config& config);
   virtual ~FreeTrackData() = default;
 
-  void Add(DebugData& debug, const Header* header);
+  void Add(const Header* header);
 
-  void VerifyAll(DebugData& debug);
+  void VerifyAll();
 
   void LogBacktrace(const Header* header);
 
  private:
-  void LogFreeError(DebugData& debug, const Header* header, const uint8_t* pointer);
-  void VerifyAndFree(DebugData& debug, const Header* header, const void* pointer);
+  void LogFreeError(const Header* header, const uint8_t* pointer);
+  void VerifyAndFree(const Header* header);
 
   pthread_mutex_t mutex_ = PTHREAD_MUTEX_INITIALIZER;
   std::deque<const Header*> list_;
diff --git a/libc/malloc_debug/GuardData.cpp b/libc/malloc_debug/GuardData.cpp
index 97b16ff..e207b86 100644
--- a/libc/malloc_debug/GuardData.cpp
+++ b/libc/malloc_debug/GuardData.cpp
@@ -39,15 +39,14 @@
 #include "malloc_debug.h"
 #include "GuardData.h"
 
-GuardData::GuardData(int init_value, size_t num_bytes) {
+GuardData::GuardData(DebugData* debug_data, int init_value, size_t num_bytes)
+    : OptionData(debug_data) {
   // Create a buffer for fast comparisons of the front guard.
   cmp_mem_.resize(num_bytes);
   memset(cmp_mem_.data(), init_value, cmp_mem_.size());
 }
 
 void GuardData::LogFailure(const Header* header, const void* pointer, const void* data) {
-  ScopedDisableDebugCalls disable;
-
   error_log(LOG_DIVIDER);
   error_log("+++ ALLOCATION %p SIZE %zu HAS A CORRUPTED %s GUARD", pointer,
             header->real_size(), GetTypeName());
@@ -70,8 +69,8 @@
   error_log(LOG_DIVIDER);
 }
 
-FrontGuardData::FrontGuardData(const Config& config, size_t* offset)
-   : GuardData(config.front_guard_value, config.front_guard_bytes) {
+FrontGuardData::FrontGuardData(DebugData* debug_data, const Config& config, size_t* offset)
+   : GuardData(debug_data, config.front_guard_value, config.front_guard_bytes) {
   // Create a buffer for fast comparisons of the front guard.
   cmp_mem_.resize(config.front_guard_bytes);
   memset(cmp_mem_.data(), config.front_guard_value, cmp_mem_.size());
@@ -80,22 +79,22 @@
   *offset += config.front_guard_bytes;
 }
 
-bool FrontGuardData::Valid(DebugData& debug, const Header* header) {
-  return GuardData::Valid(debug.GetFrontGuard(header));
+bool FrontGuardData::Valid(const Header* header) {
+  return GuardData::Valid(debug_->GetFrontGuard(header));
 }
 
-void FrontGuardData::LogFailure(DebugData& debug, const Header* header) {
-  GuardData::LogFailure(header, debug.GetPointer(header), debug.GetFrontGuard(header));
+void FrontGuardData::LogFailure(const Header* header) {
+  GuardData::LogFailure(header, debug_->GetPointer(header), debug_->GetFrontGuard(header));
 }
 
-RearGuardData::RearGuardData(const Config& config)
-    : GuardData(config.rear_guard_value, config.rear_guard_bytes) {
+RearGuardData::RearGuardData(DebugData* debug_data, const Config& config)
+    : GuardData(debug_data, config.rear_guard_value, config.rear_guard_bytes) {
 }
 
-bool RearGuardData::Valid(DebugData& debug, const Header* header) {
-  return GuardData::Valid(debug.GetRearGuard(header));
+bool RearGuardData::Valid(const Header* header) {
+  return GuardData::Valid(debug_->GetRearGuard(header));
 }
 
-void RearGuardData::LogFailure(DebugData& debug, const Header* header) {
-  GuardData::LogFailure(header, debug.GetPointer(header), debug.GetRearGuard(header));
+void RearGuardData::LogFailure(const Header* header) {
+  GuardData::LogFailure(header, debug_->GetPointer(header), debug_->GetRearGuard(header));
 }
diff --git a/libc/malloc_debug/GuardData.h b/libc/malloc_debug/GuardData.h
index 4de2702..bfb3949 100644
--- a/libc/malloc_debug/GuardData.h
+++ b/libc/malloc_debug/GuardData.h
@@ -36,14 +36,16 @@
 
 #include <private/bionic_macros.h>
 
+#include "OptionData.h"
+
 // Forward declarations.
 class DebugData;
 struct Header;
 struct Config;
 
-class GuardData {
+class GuardData : public OptionData {
  public:
-  GuardData(int init_value, size_t num_bytes);
+  GuardData(DebugData* debug_data, int init_value, size_t num_bytes);
   virtual ~GuardData() = default;
 
   bool Valid(void* data) { return memcmp(data, cmp_mem_.data(), cmp_mem_.size()) == 0; }
@@ -60,12 +62,12 @@
 
 class FrontGuardData : public GuardData {
  public:
-  FrontGuardData(const Config& config, size_t* offset);
+  FrontGuardData(DebugData* debug_data, const Config& config, size_t* offset);
   virtual ~FrontGuardData() = default;
 
-  bool Valid(DebugData& debug, const Header* header);
+  bool Valid(const Header* header);
 
-  void LogFailure(DebugData& debug, const Header* header);
+  void LogFailure(const Header* header);
 
   size_t offset() { return offset_; }
 
@@ -79,12 +81,12 @@
 
 class RearGuardData : public GuardData {
  public:
-  RearGuardData(const Config& config);
+  RearGuardData(DebugData* debug_data, const Config& config);
   virtual ~RearGuardData() = default;
 
-  bool Valid(DebugData& debug, const Header* header);
+  bool Valid(const Header* header);
 
-  void LogFailure(DebugData& debug, const Header* header);
+  void LogFailure(const Header* header);
 
  private:
   const char* GetTypeName() override { return "REAR"; }
diff --git a/libc/bionic/__memchr_chk.cpp b/libc/malloc_debug/OptionData.h
similarity index 77%
rename from libc/bionic/__memchr_chk.cpp
rename to libc/malloc_debug/OptionData.h
index d141c04..80190f5 100644
--- a/libc/bionic/__memchr_chk.cpp
+++ b/libc/malloc_debug/OptionData.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 The Android Open Source Project
+ * Copyright (C) 2016 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,14 +26,21 @@
  * SUCH DAMAGE.
  */
 
-#undef _FORTIFY_SOURCE
-#include <string.h>
-#include "private/libc_logging.h"
+#ifndef DEBUG_MALLOC_OPTIONDATA_H
+#define DEBUG_MALLOC_OPTIONDATA_H
 
-extern "C" void* __memchr_chk(const void* s, int c, size_t n, size_t buf_size) {
-  if (__predict_false(n > buf_size)) {
-    __fortify_chk_fail("memchr: prevented read past end of buffer", 0);
-  }
+// Forward Declarations
+class DebugData;
 
-  return memchr(s, c, n);
-}
+class OptionData {
+ public:
+  OptionData(DebugData* debug) : debug_(debug) {}
+  ~OptionData() = default;
+
+ protected:
+  DebugData* debug_;
+
+  DISALLOW_COPY_AND_ASSIGN(OptionData);
+};
+
+#endif // MALLOC_DEBUG_OPTIONDATA_H
diff --git a/libc/malloc_debug/README.md b/libc/malloc_debug/README.md
index 3fc2305..984430b 100644
--- a/libc/malloc_debug/README.md
+++ b/libc/malloc_debug/README.md
@@ -4,26 +4,31 @@
 Malloc debug is a method of debugging native memory problems. It can help
 detect memory corruption, memory leaks, and use after free issues.
 
-Currently, malloc debug requires root to enable. When it is enabled, it works
-by adding a shim layer that replaces the normal allocation calls. The replaced
-calls are:
+This documentation describes how to enable this feature on Android N or later
+versions of the Android OS.
 
-<pre>
-malloc
-free
-calloc
-realloc
-posix_memalign
-memalign
-malloc_usable_size
-</pre>
+The documentation for malloc debug on older versions of Android is
+[here](README_marshmallow_and_earlier.md).
+
+In order to enable malloc debug, you must be able to set special system
+properties using the setprop command from the shell. This requires the
+ability to run as root on the device.
+
+When malloc debug is enabled, it works by adding a shim layer that replaces
+the normal allocation calls. The replaced calls are:
+
+* `malloc`
+* `free`
+* `calloc`
+* `realloc`
+* `posix_memalign`
+* `memalign`
+* `malloc_usable_size`
 
 On 32 bit systems, these two deprecated functions are also replaced:
 
-<pre>
-pvalloc
-valloc
-</pre>
+* `pvalloc`
+* `valloc`
 
 Any errors detected by the library are reported in the log.
 
@@ -57,11 +62,9 @@
 
 Example error:
 
-<pre>
-04-10 12:00:45.621  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 SIZE 100 HAS A CORRUPTED FRONT GUARD
-04-10 12:00:45.622  7412  7412 E malloc_debug:   allocation[-32] = 0x00 (expected 0xaa)
-04-10 12:00:45.622  7412  7412 E malloc_debug:   allocation[-15] = 0x02 (expected 0xaa)
-</pre>
+    04-10 12:00:45.621  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 SIZE 100 HAS A CORRUPTED FRONT GUARD
+    04-10 12:00:45.622  7412  7412 E malloc_debug:   allocation[-32] = 0x00 (expected 0xaa)
+    04-10 12:00:45.622  7412  7412 E malloc_debug:   allocation[-15] = 0x02 (expected 0xaa)
 
 ### rear\_guard[=SIZE\_BYTES]
 Enables a small buffer placed after the allocated data. This is an attempt
@@ -79,11 +82,9 @@
 
 Example error:
 
-<pre>
-04-10 12:00:45.621  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 SIZE 100 HAS A CORRUPTED REAR GUARD
-04-10 12:00:45.622  7412  7412 E malloc_debug:   allocation[130] = 0xbf (expected 0xbb)
-04-10 12:00:45.622  7412  7412 E malloc_debug:   allocation[131] = 0x00 (expected 0xbb)
-</pre>
+    04-10 12:00:45.621  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 SIZE 100 HAS A CORRUPTED REAR GUARD
+    04-10 12:00:45.622  7412  7412 E malloc_debug:   allocation[130] = 0xbf (expected 0xbb)
+    04-10 12:00:45.622  7412  7412 E malloc_debug:   allocation[131] = 0x00 (expected 0xbb)
 
 ### guard[=SIZE\_BYTES]
 Enables both a front guard and a rear guard on all allocations.
@@ -173,25 +174,21 @@
 
 Example error:
 
-<pre>
-04-15 12:00:31.304  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 USED AFTER FREE
-04-15 12:00:31.305  7412  7412 E malloc_debug:   allocation[20] = 0xaf (expected 0xef)
-04-15 12:00:31.305  7412  7412 E malloc_debug:   allocation[99] = 0x12 (expected 0xef)
-04-15 12:00:31.305  7412  7412 E malloc_debug: Backtrace at time of free:
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
-</pre>
+    04-15 12:00:31.304  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 USED AFTER FREE
+    04-15 12:00:31.305  7412  7412 E malloc_debug:   allocation[20] = 0xaf (expected 0xef)
+    04-15 12:00:31.305  7412  7412 E malloc_debug:   allocation[99] = 0x12 (expected 0xef)
+    04-15 12:00:31.305  7412  7412 E malloc_debug: Backtrace at time of free:
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
 
 In addition, there is another type of error message that can occur if
 an allocation has a special header applied, and the header is corrupted
 before the verification occurs. This is the error message that will be found
 in the log:
 
-<pre>
-+++ ALLOCATION 0x12345678 HAS CORRUPTED HEADER TAG 0x1cc7dc00 AFTER FREE
-</pre>
+    04-15 12:00:31.604  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 HAS CORRUPTED HEADER TAG 0x1cc7dc00 AFTER FREE
 
 ### free\_track\_backtrace\_num\_frames[=MAX\_FRAMES]
 This option only has meaning if free\_track is set. It indicates how many
@@ -214,62 +211,156 @@
 
 Example leak error found in the log:
 
-<pre>
-04-15 12:35:33.304  7412  7412 E malloc_debug: +++ APP leaked block of size 100 at 0x2be3b0b0 (leak 1 of 2)
-04-15 12:35:33.304  7412  7412 E malloc_debug: Backtrace at time of allocation:
-04-15 12:35:33.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
-04-15 12:35:33.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
-04-15 12:35:33.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
-04-15 12:35:33.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
-04-15 12:35:33.305  7412  7412 E malloc_debug: +++ APP leaked block of size 24 at 0x7be32380 (leak 2 of 2)
-04-15 12:35:33.305  7412  7412 E malloc_debug: Backtrace at time of allocation:
-04-15 12:35:33.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
-04-15 12:35:33.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
-04-15 12:35:33.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
-04-15 12:35:33.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
-</pre>
+    04-15 12:35:33.304  7412  7412 E malloc_debug: +++ APP leaked block of size 100 at 0x2be3b0b0 (leak 1 of 2)
+    04-15 12:35:33.304  7412  7412 E malloc_debug: Backtrace at time of allocation:
+    04-15 12:35:33.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
+    04-15 12:35:33.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
+    04-15 12:35:33.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
+    04-15 12:35:33.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
+    04-15 12:35:33.305  7412  7412 E malloc_debug: +++ APP leaked block of size 24 at 0x7be32380 (leak 2 of 2)
+    04-15 12:35:33.305  7412  7412 E malloc_debug: Backtrace at time of allocation:
+    04-15 12:35:33.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
+    04-15 12:35:33.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
+    04-15 12:35:33.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
+    04-15 12:35:33.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
+
+### record\_allocs[=TOTAL\_ENTRIES]
+Keep track of every allocation/free made on every thread and dump them
+to a file when the signal SIGRTMAX - 18 (which is 46 on most Android devices)
+is received.
+
+If TOTAL\_ENTRIES is set, then it indicates the total number of
+allocation/free records that can be retained. If the number of records
+reaches the TOTAL\_ENTRIES value, then any further allocations/frees are
+not recorded. The default value is 8,000,000 and the maximum value this
+can be set to is 50,000,000.
+
+Once the signal is received, and the current records are written to the
+file, all current records are deleted. Any allocations/frees occuring while
+the data is being dumped to the file are ignored.
+
+**NOTE**: This option is not available until the O release of Android.
+
+The allocation data is written in a human readable format. Every line begins
+with the THREAD\_ID returned by gettid(), which is the thread that is making
+the allocation/free. If a new thread is created, no special line is added
+to the file. However, when a thread completes, a special entry is added to
+the file indicating this.
+
+The thread complete line is:
+
+**THREAD\_ID**: thread\_done 0x0
+
+Example:
+
+    187: thread_done 0x0
+
+Below is how each type of allocation/free call ends up in the file dump.
+
+pointer = malloc(size)
+
+**THREAD\_ID**: malloc pointer size
+
+Example:
+
+    186: malloc 0xb6038060 20
+
+free(pointer)
+
+**THREAD\_ID**: free pointer
+
+Example:
+
+    186: free 0xb6038060
+
+pointer = calloc(nmemb, size)
+
+**THREAD\_ID**: calloc pointer nmemb size
+
+Example:
+
+    186: calloc 0xb609f080 32 4
+
+new\_pointer = realloc(old\_pointer, size)
+
+**THREAD\_ID**: realloc new\_pointer old\_pointer size
+
+Example:
+
+    186: realloc 0xb609f080 0xb603e9a0 12
+
+pointer = memalign(alignment, size)
+
+**THREAD\_ID**: memalign pointer alignment size
+
+posix\_memalign(&pointer, alignment, size)
+
+**THREAD\_ID**: memalign pointer alignment size
+
+Example:
+
+    186: memalign 0x85423660 16 104
+
+pointer = valloc(size)
+
+**THREAD\_ID**: memalign pointer 4096 size
+
+Example:
+
+    186: memalign 0x85423660 4096 112
+
+pointer = pvalloc(size)
+
+**THREAD\_ID**: memalign pointer 4096 <b>SIZE\_ROUNDED\_UP\_TO\_4096</b>
+
+Example:
+
+    186: memalign 0x85423660 4096 8192
+
+### record\_allocs\_file[=FILE\_NAME]
+This option only has meaning if record\_allocs is set. It indicates the
+file where the recorded allocations will be found.
+
+If FILE\_NAME is set, then it indicates where the record allocation data
+will be placed.
+
+**NOTE**: This option is not available until the O release of Android.
 
 Additional Errors
 -----------------
 There are a few other error messages that might appear in the log.
 
 ### Use After Free
-<pre>
-04-15 12:00:31.304  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 USED AFTER FREE (free)
-04-15 12:00:31.305  7412  7412 E malloc_debug: Backtrace of original free:
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
-04-15 12:00:31.305  7412  7412 E malloc_debug: Backtrace at time of failure:
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
-</pre>
+    04-15 12:00:31.304  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 USED AFTER FREE (free)
+    04-15 12:00:31.305  7412  7412 E malloc_debug: Backtrace of original free:
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug: Backtrace at time of failure:
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
 
 This indicates that code is attempting to free an already freed pointer. The
 name in parenthesis indicates that the application called the function
-<i>free</i> with the bad pointer.
+*free* with the bad pointer.
 
 For example, this message:
 
-<pre>
-04-15 12:00:31.304  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 USED AFTER FREE (realloc)
-</pre>
+    04-15 12:00:31.304  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 USED AFTER FREE (realloc)
 
-Would indicate that the application called the <i>realloc</i> function
+Would indicate that the application called the *realloc* function
 with an already freed pointer.
 
 ### Invalid Tag
-<pre>
-04-15 12:00:31.304  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 HAS INVALID TAG 1ee7d000 (malloc_usable_size)
-04-15 12:00:31.305  7412  7412 E malloc_debug: Backtrace at time of failure:
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
-</pre>
+    04-15 12:00:31.304  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 HAS INVALID TAG 1ee7d000 (malloc_usable_size)
+    04-15 12:00:31.305  7412  7412 E malloc_debug: Backtrace at time of failure:
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
 
 This indicates that a function (malloc\_usable\_size) was called with
 a pointer that is either not allocated memory, or that the memory of
@@ -282,36 +373,28 @@
 ========
 Enable backtrace tracking of all allocation for all processes:
 
-<pre>
-  adb shell stop
-  adb shell setprop libc.debug.malloc.options backtrace
-  adb shell start
-</pre>
+    adb shell stop
+    adb shell setprop libc.debug.malloc.options backtrace
+    adb shell start
 
 Enable backtrace tracking for a specific process (ls):
 
-<pre>
-  adb shell setprop libc.debug.malloc.options backtrace
-  adb shell setprop libc.debug.malloc.program ls
-  adb shell ls
-</pre>
+    adb shell setprop libc.debug.malloc.options backtrace
+    adb shell setprop libc.debug.malloc.program ls
+    adb shell ls
 
 Enable backtrace tracking for the zygote and zygote based processes:
 
-<pre>
-  adb shell stop
-  adb shell setprop libc.debug.malloc.program app_process
-  adb shell setprop libc.debug.malloc.options backtrace
-  adb shell start
-</pre>
+    adb shell stop
+    adb shell setprop libc.debug.malloc.program app_process
+    adb shell setprop libc.debug.malloc.options backtrace
+    adb shell start
 
 Enable multiple options (backtrace and guards):
 
-<pre>
-  adb shell stop
-  adb shell setprop libc.debug.malloc.options "\"backtrace guards\""
-  adb shell start
-</pre>
+    adb shell stop
+    adb shell setprop libc.debug.malloc.options "\"backtrace guards\""
+    adb shell start
 
 Enable malloc debug when multiple processes have the same name. This method
 can be used to enable malloc debug for only a very specific process if
@@ -321,10 +404,8 @@
 the setprop command will fail since the backtrace guards options will look
 like two arguments instead of one.
 
-<pre>
-  adb shell
-  # setprop libc.debug.malloc.env_enabled
-  # setprop libc.debug.malloc.options backtrace
-  # export LIBC_DEBUG_MALLOC_ENABLE 1
-  # ls
-</pre>
+    adb shell
+    # setprop libc.debug.malloc.env_enabled
+    # setprop libc.debug.malloc.options backtrace
+    # export LIBC_DEBUG_MALLOC_ENABLE 1
+    # ls
diff --git a/libc/malloc_debug/README_api.md b/libc/malloc_debug/README_api.md
index cd04c32..63ad42a 100644
--- a/libc/malloc_debug/README_api.md
+++ b/libc/malloc_debug/README_api.md
@@ -7,57 +7,47 @@
 
 The function to gather the data:
 
-<pre>
-<b>
-extern "C" void get_malloc_leak_info(uint8_t** info, size_t* overall_size, size_t* info_size, size_t* total_memory, size_t* backtrace_size);
-</b>
-</pre>
+`extern "C" void get_malloc_leak_info(uint8_t** info, size_t* overall_size, size_t* info_size, size_t* total_memory, size_t* backtrace_size);`
 
-<i>info</i> is set to a buffer allocated by the call that contains all of
+*info* is set to a buffer allocated by the call that contains all of
 the allocation information.
-<i>overall\_size</i> is set to the total size of the buffer returned. If this
-<i>info\_size</i>
+*overall\_size* is set to the total size of the buffer returned. If this
+*info\_size*
 value is zero, then there are no allocation being tracked.
-<i>total\_memory</i> is set to the sum of all allocation sizes that are live at
+*total\_memory* is set to the sum of all allocation sizes that are live at
 the point of the function call. This does not include the memory allocated
 by the malloc debug library itself.
-<i>backtrace\_size</i> is set to the maximum number of backtrace entries
+*backtrace\_size* is set to the maximum number of backtrace entries
 that are present for each allocation.
 
 In order to free the buffer allocated by the function, call:
 
-<pre>
-<b>
-extern "C" void free_malloc_leak_info(uint8_t* info);
-</b>
-</pre>
+`extern "C" void free_malloc_leak_info(uint8_t* info);`
 
 ### Format of info Buffer
-<pre>
-size_t size_of_original_allocation
-size_t num_backtrace_frames
-uintptr_t pc1
-uintptr_t pc2
-uintptr_t pc3
-.
-.
-.
-</pre>
+    size_t size_of_original_allocation
+    size_t num_backtrace_frames
+    uintptr_t pc1
+    uintptr_t pc2
+    uintptr_t pc3
+    .
+    .
+    .
 
-The number of <i>uintptr\_t</i> values is determined by the value
-<i>backtrace\_size</i> as returned by the original call to
-<i>get\_malloc\_leak\_info</i>. This value is not variable, it is the same
+The number of *uintptr\_t* values is determined by the value
+*backtrace\_size* as returned by the original call to
+*get\_malloc\_leak\_info*. This value is not variable, it is the same
 for all the returned data. The value
-<i>num\_backtrace\_frames</i> contains the real number of frames found. The
-extra frames are set to zero. Each <i>uintptr\_t</i> is a pc of the callstack.
+*num\_backtrace\_frames* contains the real number of frames found. The
+extra frames are set to zero. Each *uintptr\_t* is a pc of the callstack.
 The calls from within the malloc debug library are automatically removed.
 
-For 32 bit systems, <i>size\_t</i> and <i>uintptr\_t</i> are both 4 byte values.
+For 32 bit systems, *size\_t* and *uintptr\_t* are both 4 byte values.
 
-For 64 bit systems, <i>size\_t</i> and <i>uintptr\_t</i> are both 8 byte values.
+For 64 bit systems, *size\_t* and *uintptr\_t* are both 8 byte values.
 
-The total number of these structures returned in <i>info</i> is
-<i>overall\_size</i> divided by <i>info\_size</i>.
+The total number of these structures returned in *info* is
+*overall\_size* divided by *info\_size*.
 
 Note, the size value in each allocation data structure will have bit 31 set
 if this allocation was created by the Zygote process. This helps to distinguish
diff --git a/libc/malloc_debug/README_marshmallow_and_earlier.md b/libc/malloc_debug/README_marshmallow_and_earlier.md
new file mode 100644
index 0000000..3513711
--- /dev/null
+++ b/libc/malloc_debug/README_marshmallow_and_earlier.md
@@ -0,0 +1,128 @@
+Malloc Debug
+============
+
+Malloc debug is a method of debugging native memory problems. It can help
+detect memory corruption, memory leaks, and use after free issues.
+
+This documentation describes how to enable this feature on versions of
+the Android OS, Marshmallow or older. Note: malloc debug was full of bugs
+and was not fully functional until KitKat, so using it on a version older
+than that is not guaranteed to work at all.
+
+The documentation for malloc debug on newer versions of Android is
+[here](README.md).
+
+On these old versions of the OS, you must be able to set system properties
+using the setprop command from the shell. This requires the ability to
+run as root on the device.
+
+When malloc debug is enabled, it works by adding a shim layer that replaces
+the normal allocation calls. The replaced calls are:
+
+* `malloc`
+* `free`
+* `calloc`
+* `realloc`
+* `posix_memalign`
+* `memalign`
+* `malloc_usable_size`
+
+On 32 bit systems, these two deprecated functions are also replaced:
+
+* `pvalloc`
+* `valloc`
+
+Any errors detected by the library are reported in the log.
+
+Controlling Malloc Debug Behavior
+---------------------------------
+Malloc debug is controlled by a system property that takes a numeric value
+named libc.debug.malloc. It has only a few distinct modes that enables a
+set of different malloc debug checks at once.
+
+Value 1
+--------
+When enabled, this value creates a special header to all allocations
+that contains information about the allocation.
+
+### Backtrace at Allocation Creation
+Enable capturing the backtrace of each allocation site. Only the
+first 16 frames of the backtrace will be captured.
+This option will slow down allocations by an order of magnitude, and
+might cause timeouts when trying to start a device.
+
+### Track Live Allocations
+All of the currently live allocations will be tracked and can be retrieved
+by a call to get\_malloc\_leak\_info (see README\_api.md for details).
+
+Note: If multiple allocations have the same exact backtrace, then only one
+entry is returned in the list.
+
+Value 5
+-------
+When enabled, this value does not create a special header. It only modifies
+the content of allocations.
+
+Whenever an allocation is created, initialize the data with a known
+pattern (0xeb). This does not happen for the calloc calls.
+Whenever an allocation is freed, write a known pattern over the data (0xef).
+
+Value 10
+--------
+When enabled, this value creates a special header to all allocations
+that contains information about the allocation.
+
+This value enables everything enabled with value 1 plus these other options.
+
+### Allocation Guards
+A 32 byte buffer is placed before the returned allocation (known as
+a front guard). This buffer is filled with the pattern (0xaa). In addition,
+a 32 byte buffer is placed after the data for the returned allocation (known
+as a rear guard). This buffer is filled with the pattern (0xbb).
+
+When the allocation is freed, both of these guards are verified to contain
+the expected patterns. If not, then an error message is printed to the log.
+
+### Free Memory Tracking
+When a pointer is freed, do not free the memory right away, but add it to
+a list of freed allocations. In addition to being added to the list, the
+entire allocation is filled with the value 0xef, and the backtrace at
+the time of the free is recorded. As with the backtrace on allocation,
+only up to 16 frames will be recorded.
+
+When the list of freed allocations reaches 100, the oldest allocation
+on the list is removed and verified that it still contains the pattern 0xef.
+If the entire allocation is not filled with this value, an error is printed
+to the log.
+
+### Log Leaks
+When the program completes, all of the allocations that are still live
+are printed to the log as leaks. This isn't very useful since it tends
+to display a lot of false positive because many programs do not free
+everything before terminating.
+
+Option 20
+---------
+Do not use this option value, it only works on the emulator. It has not
+been verified, so it may or may not work.
+
+Enable on Certain Processes
+---------------------------
+Using the special system property, libc.debug.malloc.program, will
+cause malloc debug to only be used on processes with that name. For example,
+if the property is set to ls, then only the program named ls will have malloc
+debug enabled.
+
+Examples
+========
+Enable malloc debug for all allocations for all processes:
+
+    adb shell stop
+    adb shell setprop libc.debug.malloc 1
+    adb shell start
+
+Enable malloc debug for a particular process:
+
+    adb shell setprop libc.debug.malloc.program ls
+    adb shell setprop libc.debug.malloc 10
+    adb shell ls /data/local/tmp
diff --git a/libc/malloc_debug/RecordData.cpp b/libc/malloc_debug/RecordData.cpp
new file mode 100644
index 0000000..c0f3486
--- /dev/null
+++ b/libc/malloc_debug/RecordData.cpp
@@ -0,0 +1,231 @@
+/*
+ * Copyright (C) 2016 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 <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <stdatomic.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+
+#include <mutex>
+
+#include <android-base/stringprintf.h>
+
+#include "Config.h"
+#include "debug_disable.h"
+#include "debug_log.h"
+#include "DebugData.h"
+#include "RecordData.h"
+
+RecordEntry::RecordEntry() : tid_(gettid()) {
+}
+
+std::string ThreadCompleteEntry::GetString() const {
+  return android::base::StringPrintf("%d: thread_done 0x0\n", tid_);
+}
+
+AllocEntry::AllocEntry(void* pointer) : pointer_(pointer) {
+}
+
+MallocEntry::MallocEntry(void* pointer, size_t size) : AllocEntry(pointer), size_(size) {
+}
+
+std::string MallocEntry::GetString() const {
+  return android::base::StringPrintf("%d: malloc %p %zu\n", tid_, pointer_, size_);
+}
+
+FreeEntry::FreeEntry(void* pointer) : AllocEntry(pointer) {
+}
+
+std::string FreeEntry::GetString() const {
+  return android::base::StringPrintf("%d: free %p\n", tid_, pointer_);
+}
+
+CallocEntry::CallocEntry(void* pointer, size_t nmemb, size_t size)
+    : MallocEntry(pointer, size), nmemb_(nmemb) {
+}
+
+std::string CallocEntry::GetString() const {
+  return android::base::StringPrintf("%d: calloc %p %zu %zu\n", tid_, pointer_, nmemb_, size_);
+}
+
+ReallocEntry::ReallocEntry(void* pointer, size_t size, void* old_pointer)
+    : MallocEntry(pointer, size), old_pointer_(old_pointer) {
+}
+
+std::string ReallocEntry::GetString() const {
+  return android::base::StringPrintf("%d: realloc %p %p %zu\n", tid_, pointer_,
+                                     old_pointer_, size_);
+}
+
+// posix_memalign, memalgin, pvalloc, valloc all recorded with this class.
+MemalignEntry::MemalignEntry(void* pointer, size_t size, size_t alignment)
+    : MallocEntry(pointer, size), alignment_(alignment) {
+}
+
+std::string MemalignEntry::GetString() const {
+  return android::base::StringPrintf("%d: memalign %p %zu %zu\n", tid_, pointer_,
+                                     alignment_, size_);
+}
+
+struct ThreadData {
+  ThreadData(RecordData* record_data, ThreadCompleteEntry* entry) : record_data(record_data), entry(entry) {}
+  RecordData* record_data;
+  ThreadCompleteEntry* entry;
+  size_t count = 0;
+};
+
+static void ThreadKeyDelete(void* data) {
+  ThreadData* thread_data = reinterpret_cast<ThreadData*>(data);
+
+  thread_data->count++;
+
+  // This should be the last time we are called.
+  if (thread_data->count == 4) {
+    ScopedDisableDebugCalls disable;
+
+    thread_data->record_data->AddEntryOnly(thread_data->entry);
+    delete thread_data;
+  } else {
+    pthread_setspecific(thread_data->record_data->key(), data);
+  }
+}
+
+static void RecordDump(int, siginfo_t*, void*) {
+  // It's not necessarily safe to do the dump here, instead wait for the
+  // next allocation call to do the dump.
+  g_debug->record->SetToDump();
+}
+
+void RecordData::Dump() {
+  std::lock_guard<std::mutex> lock(dump_lock_);
+
+  // Make it so that no more entries can be added while dumping.
+  unsigned int last_entry_index = cur_index_.exchange(static_cast<unsigned int>(num_entries_));
+  if (dump_ == false) {
+    // Multiple Dump() calls from different threads, and we lost. Do nothing.
+    return;
+  }
+
+  // cur_index_ keeps getting incremented even if we hit the num_entries_.
+  // If that happens, cap the entries to dump by num_entries_.
+  if (last_entry_index > num_entries_) {
+    last_entry_index = num_entries_;
+  }
+
+  int dump_fd = open(dump_file_.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NOFOLLOW,
+                     0755);
+  if (dump_fd != -1) {
+    for (size_t i = 0; i < last_entry_index; i++) {
+      std::string line = entries_[i]->GetString();
+      ssize_t bytes = write(dump_fd, line.c_str(), line.length());
+      if (bytes == -1 || static_cast<size_t>(bytes) != line.length()) {
+        error_log("Failed to write record alloc information: %s", strerror(errno));
+        // Free all of the rest of the errors, we don't have any way
+        // to dump a partial list of the entries.
+        for (i++; i < last_entry_index; i++) {
+          delete entries_[i];
+          entries_[i] = nullptr;
+        }
+        break;
+      }
+      delete entries_[i];
+      entries_[i] = nullptr;
+    }
+    close(dump_fd);
+
+    // Mark the entries dumped.
+    cur_index_ = 0U;
+  } else {
+    error_log("Cannot create record alloc file %s: %s", dump_file_.c_str(), strerror(errno));
+    // Since we couldn't create the file, reset the entries dumped back
+    // to the original value.
+    cur_index_ = last_entry_index;
+  }
+
+  dump_ = false;
+}
+
+RecordData::RecordData() {
+  pthread_key_create(&key_, ThreadKeyDelete);
+}
+
+bool RecordData::Initialize(const Config& config) {
+  struct sigaction dump_act;
+  memset(&dump_act, 0, sizeof(dump_act));
+
+  dump_act.sa_sigaction = RecordDump;
+  dump_act.sa_flags = SA_RESTART | SA_SIGINFO | SA_ONSTACK;
+  sigemptyset(&dump_act.sa_mask);
+  if (sigaction(config.record_allocs_signal, &dump_act, nullptr) != 0) {
+    error_log("Unable to set up record dump signal function: %s", strerror(errno));
+    return false;
+  }
+  pthread_setspecific(key_, nullptr);
+
+  info_log("%s: Run: 'kill -%d %d' to dump the allocation records.", getprogname(),
+           config.record_allocs_signal, getpid());
+
+  num_entries_ = config.record_allocs_num_entries;
+  entries_ = new const RecordEntry*[num_entries_];
+  cur_index_ = 0;
+  dump_ = false;
+  dump_file_ = config.record_allocs_file;
+
+  return true;
+}
+
+RecordData::~RecordData() {
+  delete [] entries_;
+  pthread_key_delete(key_);
+}
+
+void RecordData::AddEntryOnly(const RecordEntry* entry) {
+  unsigned int entry_index = cur_index_.fetch_add(1);
+  if (entry_index < num_entries_) {
+    entries_[entry_index] = entry;
+  }
+}
+
+void RecordData::AddEntry(const RecordEntry* entry) {
+  void* data = pthread_getspecific(key_);
+  if (data == nullptr) {
+    ThreadData* thread_data = new ThreadData(this, new ThreadCompleteEntry());
+    pthread_setspecific(key_, thread_data);
+  }
+
+  AddEntryOnly(entry);
+
+  // Check to see if it's time to dump the entries.
+  if (dump_) {
+    Dump();
+  }
+}
diff --git a/libc/malloc_debug/RecordData.h b/libc/malloc_debug/RecordData.h
new file mode 100644
index 0000000..741afd5
--- /dev/null
+++ b/libc/malloc_debug/RecordData.h
@@ -0,0 +1,177 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#ifndef DEBUG_MALLOC_RECORDDATA_H
+#define DEBUG_MALLOC_RECORDDATA_H
+
+#include <stdint.h>
+#include <pthread.h>
+#include <unistd.h>
+
+#include <atomic>
+#include <mutex>
+#include <string>
+
+#include <private/bionic_macros.h>
+
+class RecordEntry {
+ public:
+  RecordEntry();
+  virtual ~RecordEntry() = default;
+
+  virtual std::string GetString() const = 0;
+
+ protected:
+  pid_t tid_;
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(RecordEntry);
+};
+
+class ThreadCompleteEntry : public RecordEntry {
+ public:
+  ThreadCompleteEntry() = default;
+  virtual ~ThreadCompleteEntry() = default;
+
+  std::string GetString() const override;
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(ThreadCompleteEntry);
+};
+
+class AllocEntry : public RecordEntry {
+ public:
+  AllocEntry(void* pointer);
+  virtual ~AllocEntry() = default;
+
+ protected:
+  void* pointer_;
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(AllocEntry);
+};
+
+class MallocEntry : public AllocEntry {
+ public:
+  MallocEntry(void* pointer, size_t size);
+  virtual ~MallocEntry() = default;
+
+  std::string GetString() const override;
+
+ protected:
+  size_t size_;
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(MallocEntry);
+};
+
+class FreeEntry : public AllocEntry {
+ public:
+  FreeEntry(void* pointer);
+  virtual ~FreeEntry() = default;
+
+  std::string GetString() const override;
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(FreeEntry);
+};
+
+class CallocEntry : public MallocEntry {
+ public:
+  CallocEntry(void* pointer, size_t size, size_t nmemb);
+  virtual ~CallocEntry() = default;
+
+  std::string GetString() const override;
+
+ protected:
+  size_t nmemb_;
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(CallocEntry);
+};
+
+class ReallocEntry : public MallocEntry {
+ public:
+  ReallocEntry(void* pointer, size_t size, void* old_pointer);
+  virtual ~ReallocEntry() = default;
+
+  std::string GetString() const override;
+
+ protected:
+  void* old_pointer_;
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(ReallocEntry);
+};
+
+// posix_memalign, memalign, pvalloc, valloc all recorded with this class.
+class MemalignEntry : public MallocEntry {
+ public:
+  MemalignEntry(void* pointer, size_t size, size_t alignment);
+  virtual ~MemalignEntry() = default;
+
+  std::string GetString() const override;
+
+ protected:
+  size_t alignment_;
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(MemalignEntry);
+};
+
+struct Config;
+
+class RecordData {
+ public:
+  RecordData();
+  virtual ~RecordData();
+
+  bool Initialize(const Config& config);
+
+  void AddEntry(const RecordEntry* entry);
+  void AddEntryOnly(const RecordEntry* entry);
+
+  void SetToDump() { dump_ = true; }
+
+  pthread_key_t key() { return key_; }
+
+ private:
+  void Dump();
+
+  std::mutex dump_lock_;
+  pthread_key_t key_;
+  const RecordEntry** entries_ = nullptr;
+  size_t num_entries_ = 0;
+  std::atomic_uint cur_index_;
+  std::atomic_bool dump_;
+  std::string dump_file_;
+
+  DISALLOW_COPY_AND_ASSIGN(RecordData);
+};
+
+#endif // DEBUG_MALLOC_RECORDDATA_H
diff --git a/libc/malloc_debug/TrackData.cpp b/libc/malloc_debug/TrackData.cpp
index c9828d0..18f428b 100644
--- a/libc/malloc_debug/TrackData.cpp
+++ b/libc/malloc_debug/TrackData.cpp
@@ -44,9 +44,10 @@
 #include "malloc_debug.h"
 #include "TrackData.h"
 
-void TrackData::GetList(std::vector<const Header*>* list) {
-  ScopedDisableDebugCalls disable;
+TrackData::TrackData(DebugData* debug_data) : OptionData(debug_data) {
+}
 
+void TrackData::GetList(std::vector<const Header*>* list) {
   for (const auto& header : headers_) {
     list->push_back(header);
   }
@@ -59,8 +60,6 @@
 }
 
 void TrackData::Add(const Header* header, bool backtrace_found) {
-  ScopedDisableDebugCalls disable;
-
   pthread_mutex_lock(&mutex_);
   if (backtrace_found) {
     total_backtrace_allocs_++;
@@ -70,8 +69,6 @@
 }
 
 void TrackData::Remove(const Header* header, bool backtrace_found) {
-  ScopedDisableDebugCalls disable;
-
   pthread_mutex_lock(&mutex_);
   headers_.erase(header);
   if (backtrace_found) {
@@ -81,26 +78,22 @@
 }
 
 bool TrackData::Contains(const Header* header) {
-  ScopedDisableDebugCalls disable;
-
   pthread_mutex_lock(&mutex_);
   bool found = headers_.count(header);
   pthread_mutex_unlock(&mutex_);
   return found;
 }
 
-void TrackData::DisplayLeaks(DebugData& debug) {
-  ScopedDisableDebugCalls disable;
-
+void TrackData::DisplayLeaks() {
   std::vector<const Header*> list;
   GetList(&list);
 
   size_t track_count = 0;
   for (const auto& header : list) {
     error_log("+++ %s leaked block of size %zu at %p (leak %zu of %zu)", getprogname(),
-              header->real_size(), debug.GetPointer(header), ++track_count, list.size());
-    if (debug.config().options & BACKTRACE) {
-      BacktraceHeader* back_header = debug.GetAllocBacktrace(header);
+              header->real_size(), debug_->GetPointer(header), ++track_count, list.size());
+    if (debug_->config().options & BACKTRACE) {
+      BacktraceHeader* back_header = debug_->GetAllocBacktrace(header);
       if (back_header->num_frames > 0) {
         error_log("Backtrace at time of allocation:");
         backtrace_log(&back_header->frames[0], back_header->num_frames);
@@ -110,15 +103,15 @@
   }
 }
 
-void TrackData::GetInfo(DebugData& debug, uint8_t** info, size_t* overall_size,
-                        size_t* info_size, size_t* total_memory, size_t* backtrace_size) {
+void TrackData::GetInfo(uint8_t** info, size_t* overall_size, size_t* info_size,
+                        size_t* total_memory, size_t* backtrace_size) {
   ScopedPthreadMutexLocker scoped(&mutex_);
 
   if (headers_.size() == 0 || total_backtrace_allocs_ == 0) {
     return;
   }
 
-  *backtrace_size = debug.config().backtrace_frames;
+  *backtrace_size = debug_->config().backtrace_frames;
   *info_size = sizeof(size_t) * 2 + sizeof(uintptr_t) * *backtrace_size;
   *info = reinterpret_cast<uint8_t*>(g_dispatch->calloc(*info_size, total_backtrace_allocs_));
   if (*info == nullptr) {
@@ -131,7 +124,7 @@
 
   uint8_t* data = *info;
   for (const auto& header : list) {
-    BacktraceHeader* back_header = debug.GetAllocBacktrace(header);
+    BacktraceHeader* back_header = debug_->GetAllocBacktrace(header);
     if (back_header->num_frames > 0) {
       memcpy(data, &header->size, sizeof(size_t));
       memcpy(&data[sizeof(size_t)], &back_header->num_frames, sizeof(size_t));
diff --git a/libc/malloc_debug/TrackData.h b/libc/malloc_debug/TrackData.h
index 1234316..fcd8f2a 100644
--- a/libc/malloc_debug/TrackData.h
+++ b/libc/malloc_debug/TrackData.h
@@ -37,14 +37,16 @@
 
 #include <private/bionic_macros.h>
 
+#include "OptionData.h"
+
 // Forward declarations.
 struct Header;
 struct Config;
 class DebugData;
 
-class TrackData {
+class TrackData : public OptionData {
  public:
-  TrackData() = default;
+  TrackData(DebugData* debug_data);
   virtual ~TrackData() = default;
 
   void GetList(std::vector<const Header*>* list);
@@ -55,10 +57,10 @@
 
   bool Contains(const Header *header);
 
-  void GetInfo(DebugData& debug, uint8_t** info, size_t* overall_size,
-               size_t* info_size, size_t* total_memory, size_t* backtrace_size);
+  void GetInfo(uint8_t** info, size_t* overall_size, size_t* info_size,
+               size_t* total_memory, size_t* backtrace_size);
 
-  void DisplayLeaks(DebugData& debug);
+  void DisplayLeaks();
 
   void PrepareFork() { pthread_mutex_lock(&mutex_); }
   void PostForkParent() { pthread_mutex_unlock(&mutex_); }
diff --git a/libc/malloc_debug/debug_disable.cpp b/libc/malloc_debug/debug_disable.cpp
index af0264b..b80ba8c 100644
--- a/libc/malloc_debug/debug_disable.cpp
+++ b/libc/malloc_debug/debug_disable.cpp
@@ -32,7 +32,6 @@
 #include "debug_disable.h"
 #include "debug_log.h"
 
-extern DebugData* g_debug;
 pthread_key_t g_disable_key;
 
 bool DebugCallsDisabled() {
diff --git a/libc/malloc_debug/malloc_debug.cpp b/libc/malloc_debug/malloc_debug.cpp
index 1ee7689..d2bcf99 100644
--- a/libc/malloc_debug/malloc_debug.cpp
+++ b/libc/malloc_debug/malloc_debug.cpp
@@ -114,8 +114,6 @@
 }
 
 static void LogTagError(const Header* header, const void* pointer, const char* name) {
-  ScopedDisableDebugCalls disable;
-
   error_log(LOG_DIVIDER);
   if (header->tag == DEBUG_FREE_TAG) {
     error_log("+++ ALLOCATION %p USED AFTER FREE (%s)", pointer, name);
@@ -165,7 +163,6 @@
   if (g_debug->config().options & BACKTRACE) {
     BacktraceHeader* back_header = g_debug->GetAllocBacktrace(header);
     if (g_debug->backtrace->enabled()) {
-      ScopedDisableDebugCalls disable;
       back_header->num_frames = backtrace_get(
           &back_header->frames[0], g_debug->config().backtrace_frames);
       backtrace_found = back_header->num_frames > 0;
@@ -217,11 +214,11 @@
   }
 
   if (g_debug->config().options & FREE_TRACK) {
-    g_debug->free_track->VerifyAll(*g_debug);
+    g_debug->free_track->VerifyAll();
   }
 
   if (g_debug->config().options & LEAK_TRACK) {
-    g_debug->track->DisplayLeaks(*g_debug);
+    g_debug->track->DisplayLeaks();
   }
 
   DebugDisableSet(true);
@@ -257,32 +254,37 @@
     return;
   }
 
-  g_debug->track->GetInfo(*g_debug, info, overall_size, info_size, total_memory, backtrace_size);
+  g_debug->track->GetInfo(info, overall_size, info_size, total_memory, backtrace_size);
 }
 
 void debug_free_malloc_leak_info(uint8_t* info) {
   g_dispatch->free(info);
 }
 
-size_t debug_malloc_usable_size(void* pointer) {
-  if (DebugCallsDisabled() || !g_debug->need_header() || pointer == nullptr) {
+static size_t internal_malloc_usable_size(void* pointer) {
+  if (g_debug->need_header()) {
+    Header* header = g_debug->GetHeader(pointer);
+    if (header->tag != DEBUG_TAG) {
+      LogTagError(header, pointer, "malloc_usable_size");
+      return 0;
+    }
+
+    return header->usable_size;
+  } else {
     return g_dispatch->malloc_usable_size(pointer);
   }
-
-  Header* header = g_debug->GetHeader(pointer);
-  if (header->tag != DEBUG_TAG) {
-    LogTagError(header, pointer, "malloc_usable_size");
-    return 0;
-  }
-
-  return header->usable_size;
 }
 
-void* debug_malloc(size_t size) {
-  if (DebugCallsDisabled()) {
-    return g_dispatch->malloc(size);
+size_t debug_malloc_usable_size(void* pointer) {
+  if (DebugCallsDisabled() || pointer == nullptr) {
+    return g_dispatch->malloc_usable_size(pointer);
   }
+  ScopedDisableDebugCalls disable;
 
+  return internal_malloc_usable_size(pointer);
+}
+
+static void *internal_malloc(size_t size) {
   if (size == 0) {
     size = 1;
   }
@@ -312,7 +314,7 @@
   }
 
   if (pointer != nullptr && g_debug->config().options & FILL_ON_ALLOC) {
-    size_t bytes = debug_malloc_usable_size(pointer);
+    size_t bytes = internal_malloc_usable_size(pointer);
     size_t fill_bytes = g_debug->config().fill_on_alloc_bytes;
     bytes = (bytes < fill_bytes) ? bytes : fill_bytes;
     memset(pointer, g_debug->config().fill_alloc_value, bytes);
@@ -320,11 +322,22 @@
   return pointer;
 }
 
-void debug_free(void* pointer) {
-  if (DebugCallsDisabled() || pointer == nullptr) {
-    return g_dispatch->free(pointer);
+void* debug_malloc(size_t size) {
+  if (DebugCallsDisabled()) {
+    return g_dispatch->malloc(size);
+  }
+  ScopedDisableDebugCalls disable;
+
+  void* pointer = internal_malloc(size);
+
+  if (g_debug->config().options & RECORD_ALLOCS) {
+    g_debug->record->AddEntry(new MallocEntry(pointer, size));
   }
 
+  return pointer;
+}
+
+static void internal_free(void* pointer) {
   void* free_pointer = pointer;
   size_t bytes;
   Header* header;
@@ -337,13 +350,13 @@
     free_pointer = header->orig_pointer;
 
     if (g_debug->config().options & FRONT_GUARD) {
-      if (!g_debug->front_guard->Valid(*g_debug, header)) {
-        g_debug->front_guard->LogFailure(*g_debug, header);
+      if (!g_debug->front_guard->Valid(header)) {
+        g_debug->front_guard->LogFailure(header);
       }
     }
     if (g_debug->config().options & REAR_GUARD) {
-      if (!g_debug->rear_guard->Valid(*g_debug, header)) {
-        g_debug->rear_guard->LogFailure(*g_debug, header);
+      if (!g_debug->rear_guard->Valid(header)) {
+        g_debug->rear_guard->LogFailure(header);
       }
     }
 
@@ -374,16 +387,30 @@
     // frees at the same time and we wind up trying to really free this
     // pointer from another thread, while still trying to free it in
     // this function.
-    g_debug->free_track->Add(*g_debug, header);
+    g_debug->free_track->Add(header);
   } else {
     g_dispatch->free(free_pointer);
   }
 }
 
+void debug_free(void* pointer) {
+  if (DebugCallsDisabled() || pointer == nullptr) {
+    return g_dispatch->free(pointer);
+  }
+  ScopedDisableDebugCalls disable;
+
+  if (g_debug->config().options & RECORD_ALLOCS) {
+    g_debug->record->AddEntry(new FreeEntry(pointer));
+  }
+
+  internal_free(pointer);
+}
+
 void* debug_memalign(size_t alignment, size_t bytes) {
   if (DebugCallsDisabled()) {
     return g_dispatch->memalign(alignment, bytes);
   }
+  ScopedDisableDebugCalls disable;
 
   if (bytes == 0) {
     bytes = 1;
@@ -438,11 +465,16 @@
   }
 
   if (pointer != nullptr && g_debug->config().options & FILL_ON_ALLOC) {
-    size_t bytes = debug_malloc_usable_size(pointer);
+    size_t bytes = internal_malloc_usable_size(pointer);
     size_t fill_bytes = g_debug->config().fill_on_alloc_bytes;
     bytes = (bytes < fill_bytes) ? bytes : fill_bytes;
     memset(pointer, g_debug->config().fill_alloc_value, bytes);
   }
+
+  if (g_debug->config().options & RECORD_ALLOCS) {
+    g_debug->record->AddEntry(new MemalignEntry(pointer, bytes, alignment));
+  }
+
   return pointer;
 }
 
@@ -450,13 +482,22 @@
   if (DebugCallsDisabled()) {
     return g_dispatch->realloc(pointer, bytes);
   }
+  ScopedDisableDebugCalls disable;
 
   if (pointer == nullptr) {
-    return debug_malloc(bytes);
+    pointer = internal_malloc(bytes);
+    if (g_debug->config().options & RECORD_ALLOCS) {
+      g_debug->record->AddEntry(new ReallocEntry(pointer, bytes, nullptr));
+    }
+    return pointer;
   }
 
   if (bytes == 0) {
-    debug_free(pointer);
+    if (g_debug->config().options & RECORD_ALLOCS) {
+      g_debug->record->AddEntry(new ReallocEntry(nullptr, bytes, pointer));
+    }
+
+    internal_free(pointer);
     return nullptr;
   }
 
@@ -486,6 +527,7 @@
 
     // Same size, do nothing.
     if (real_size == header->real_size()) {
+      // Do not bother recording, this is essentially a nop.
       return pointer;
     }
 
@@ -502,11 +544,12 @@
         memset(g_debug->GetRearGuard(header), g_debug->config().rear_guard_value,
                g_debug->config().rear_guard_bytes);
       }
+      // Do not bother recording, this is essentially a nop.
       return pointer;
     }
 
     // Allocate the new size.
-    new_pointer = debug_malloc(bytes);
+    new_pointer = internal_malloc(bytes);
     if (new_pointer == nullptr) {
       errno = ENOMEM;
       return nullptr;
@@ -514,7 +557,7 @@
 
     prev_size = header->usable_size;
     memcpy(new_pointer, pointer, prev_size);
-    debug_free(pointer);
+    internal_free(pointer);
   } else {
     prev_size = g_dispatch->malloc_usable_size(pointer);
     new_pointer = g_dispatch->realloc(pointer, real_size);
@@ -524,7 +567,7 @@
   }
 
   if (g_debug->config().options & FILL_ON_ALLOC) {
-    size_t bytes = debug_malloc_usable_size(new_pointer);
+    size_t bytes = internal_malloc_usable_size(new_pointer);
     if (bytes > g_debug->config().fill_on_alloc_bytes) {
       bytes = g_debug->config().fill_on_alloc_bytes;
     }
@@ -534,6 +577,10 @@
     }
   }
 
+  if (g_debug->config().options & RECORD_ALLOCS) {
+    g_debug->record->AddEntry(new ReallocEntry(new_pointer, bytes, pointer));
+  }
+
   return new_pointer;
 }
 
@@ -541,6 +588,7 @@
   if (DebugCallsDisabled()) {
     return g_dispatch->calloc(nmemb, bytes);
   }
+  ScopedDisableDebugCalls disable;
 
   size_t size;
   if (__builtin_mul_overflow(nmemb, bytes, &size)) {
@@ -560,6 +608,7 @@
     return nullptr;
   }
 
+  void* pointer;
   if (g_debug->need_header()) {
     // The above check will guarantee the multiply will not overflow.
     if (size > Header::max_size()) {
@@ -574,10 +623,14 @@
       return nullptr;
     }
     memset(header, 0, g_dispatch->malloc_usable_size(header));
-    return InitHeader(header, header, size);
+    pointer = InitHeader(header, header, size);
   } else {
-    return g_dispatch->calloc(1, real_size);
+    pointer = g_dispatch->calloc(1, real_size);
   }
+  if (g_debug->config().options & RECORD_ALLOCS) {
+    g_debug->record->AddEntry(new CallocEntry(pointer, bytes, nmemb));
+  }
+  return pointer;
 }
 
 struct mallinfo debug_mallinfo() {
@@ -645,6 +698,7 @@
   if (DebugCallsDisabled() || pointer == nullptr) {
     return 0;
   }
+  ScopedDisableDebugCalls disable;
 
   if (g_debug->need_header()) {
     Header* header;
diff --git a/libc/malloc_debug/tests/malloc_debug_config_tests.cpp b/libc/malloc_debug/tests/malloc_debug_config_tests.cpp
index 85d5cb5..b8cf7cf 100644
--- a/libc/malloc_debug/tests/malloc_debug_config_tests.cpp
+++ b/libc/malloc_debug/tests/malloc_debug_config_tests.cpp
@@ -113,6 +113,19 @@
   "6 malloc_debug \n"
   "6 malloc_debug   leak_track\n"
   "6 malloc_debug     Enable the leak tracking of memory allocations.\n"
+  "6 malloc_debug \n"
+  "6 malloc_debug   record_allocs[=XX]\n"
+  "6 malloc_debug     Record every single allocation/free call. When a specific signal\n"
+  "6 malloc_debug     is sent to the process, the contents of recording are written to\n"
+  "6 malloc_debug     a file (/data/local/tmp/record_allocs.txt) and the recording is cleared.\n"
+  "6 malloc_debug     If XX is set, that is the total number of allocations/frees that can\n"
+  "6 malloc_debug     recorded. of frames to capture. The default value is 8000000.\n"
+  "6 malloc_debug     If the allocation list fills up, all further allocations are not recorded.\n"
+  "6 malloc_debug \n"
+  "6 malloc_debug   record_alloc_file[=FILE]\n"
+  "6 malloc_debug     This option only has meaning if the record_allocs options has been specified.\n"
+  "6 malloc_debug     This is the name of the file to which recording information will be dumped.\n"
+  "6 malloc_debug     The default is /data/local/tmp/record_allocs.txt.\n"
 );
 
 TEST_F(MallocDebugConfigTest, unknown_option) {
@@ -190,7 +203,7 @@
 }
 
 TEST_F(MallocDebugConfigTest, space_before_equal) {
-  ASSERT_TRUE(InitConfig("backtrace  =10"));
+  ASSERT_TRUE(InitConfig("backtrace  =10")) << getFakeLogPrint();
   ASSERT_EQ(BACKTRACE | TRACK_ALLOCS, config->options);
   ASSERT_EQ(10U, config->backtrace_frames);
 
@@ -199,7 +212,7 @@
 }
 
 TEST_F(MallocDebugConfigTest, space_after_equal) {
-  ASSERT_TRUE(InitConfig("backtrace=  10"));
+  ASSERT_TRUE(InitConfig("backtrace=  10")) << getFakeLogPrint();
   ASSERT_EQ(BACKTRACE | TRACK_ALLOCS, config->options);
   ASSERT_EQ(10U, config->backtrace_frames);
 
@@ -208,7 +221,7 @@
 }
 
 TEST_F(MallocDebugConfigTest, extra_space) {
-  ASSERT_TRUE(InitConfig("   backtrace=64   "));
+  ASSERT_TRUE(InitConfig("   backtrace=64   ")) << getFakeLogPrint();
   ASSERT_EQ(BACKTRACE | TRACK_ALLOCS, config->options);
   ASSERT_EQ(64U, config->backtrace_frames);
 
@@ -217,7 +230,7 @@
 }
 
 TEST_F(MallocDebugConfigTest, multiple_options) {
-  ASSERT_TRUE(InitConfig("  backtrace=64   front_guard=48"));
+  ASSERT_TRUE(InitConfig("  backtrace=64   front_guard=48")) << getFakeLogPrint();
   ASSERT_EQ(BACKTRACE | TRACK_ALLOCS | FRONT_GUARD, config->options);
   ASSERT_EQ(64U, config->backtrace_frames);
   ASSERT_EQ(48U, config->front_guard_bytes);
@@ -227,15 +240,15 @@
 }
 
 TEST_F(MallocDebugConfigTest, front_guard) {
-  ASSERT_TRUE(InitConfig("front_guard=48"));
+  ASSERT_TRUE(InitConfig("front_guard=48")) << getFakeLogPrint();
   ASSERT_EQ(FRONT_GUARD, config->options);
   ASSERT_EQ(48U, config->front_guard_bytes);
 
-  ASSERT_TRUE(InitConfig("front_guard"));
+  ASSERT_TRUE(InitConfig("front_guard")) << getFakeLogPrint();
   ASSERT_EQ(FRONT_GUARD, config->options);
   ASSERT_EQ(32U, config->front_guard_bytes);
 
-  ASSERT_TRUE(InitConfig("front_guard=39"));
+  ASSERT_TRUE(InitConfig("front_guard=39")) << getFakeLogPrint();
   ASSERT_EQ(FRONT_GUARD, config->options);
 #if defined(__LP64__)
   ASSERT_EQ(48U, config->front_guard_bytes);
@@ -243,7 +256,7 @@
   ASSERT_EQ(40U, config->front_guard_bytes);
 #endif
 
-  ASSERT_TRUE(InitConfig("front_guard=41"));
+  ASSERT_TRUE(InitConfig("front_guard=41")) << getFakeLogPrint();
   ASSERT_EQ(FRONT_GUARD, config->options);
   ASSERT_EQ(48U, config->front_guard_bytes);
 
@@ -252,11 +265,11 @@
 }
 
 TEST_F(MallocDebugConfigTest, rear_guard) {
-  ASSERT_TRUE(InitConfig("rear_guard=50"));
+  ASSERT_TRUE(InitConfig("rear_guard=50")) << getFakeLogPrint();
   ASSERT_EQ(REAR_GUARD, config->options);
   ASSERT_EQ(50U, config->rear_guard_bytes);
 
-  ASSERT_TRUE(InitConfig("rear_guard"));
+  ASSERT_TRUE(InitConfig("rear_guard")) << getFakeLogPrint();
   ASSERT_EQ(REAR_GUARD, config->options);
   ASSERT_EQ(32U, config->rear_guard_bytes);
 
@@ -265,12 +278,12 @@
 }
 
 TEST_F(MallocDebugConfigTest, guard) {
-  ASSERT_TRUE(InitConfig("guard=32"));
+  ASSERT_TRUE(InitConfig("guard=32")) << getFakeLogPrint();
   ASSERT_EQ(FRONT_GUARD | REAR_GUARD, config->options);
   ASSERT_EQ(32U, config->front_guard_bytes);
   ASSERT_EQ(32U, config->rear_guard_bytes);
 
-  ASSERT_TRUE(InitConfig("guard"));
+  ASSERT_TRUE(InitConfig("guard")) << getFakeLogPrint();
   ASSERT_EQ(FRONT_GUARD | REAR_GUARD, config->options);
   ASSERT_EQ(32U, config->front_guard_bytes);
   ASSERT_EQ(32U, config->rear_guard_bytes);
@@ -280,11 +293,11 @@
 }
 
 TEST_F(MallocDebugConfigTest, backtrace) {
-  ASSERT_TRUE(InitConfig("backtrace=64"));
+  ASSERT_TRUE(InitConfig("backtrace=64")) << getFakeLogPrint();
   ASSERT_EQ(BACKTRACE | TRACK_ALLOCS, config->options);
   ASSERT_EQ(64U, config->backtrace_frames);
 
-  ASSERT_TRUE(InitConfig("backtrace"));
+  ASSERT_TRUE(InitConfig("backtrace")) << getFakeLogPrint();
   ASSERT_EQ(BACKTRACE | TRACK_ALLOCS, config->options);
   ASSERT_EQ(16U, config->backtrace_frames);
 
@@ -293,11 +306,11 @@
 }
 
 TEST_F(MallocDebugConfigTest, backtrace_enable_on_signal) {
-  ASSERT_TRUE(InitConfig("backtrace_enable_on_signal=64"));
+  ASSERT_TRUE(InitConfig("backtrace_enable_on_signal=64")) << getFakeLogPrint();
   ASSERT_EQ(BACKTRACE | TRACK_ALLOCS, config->options);
   ASSERT_EQ(64U, config->backtrace_frames);
 
-  ASSERT_TRUE(InitConfig("backtrace_enable_on_signal"));
+  ASSERT_TRUE(InitConfig("backtrace_enable_on_signal")) << getFakeLogPrint();
   ASSERT_EQ(BACKTRACE | TRACK_ALLOCS, config->options);
   ASSERT_EQ(16U, config->backtrace_frames);
 
@@ -306,11 +319,11 @@
 }
 
 TEST_F(MallocDebugConfigTest, fill_on_alloc) {
-  ASSERT_TRUE(InitConfig("fill_on_alloc=64"));
+  ASSERT_TRUE(InitConfig("fill_on_alloc=64")) << getFakeLogPrint();
   ASSERT_EQ(FILL_ON_ALLOC, config->options);
   ASSERT_EQ(64U, config->fill_on_alloc_bytes);
 
-  ASSERT_TRUE(InitConfig("fill_on_alloc"));
+  ASSERT_TRUE(InitConfig("fill_on_alloc")) << getFakeLogPrint();
   ASSERT_EQ(FILL_ON_ALLOC, config->options);
   ASSERT_EQ(SIZE_MAX, config->fill_on_alloc_bytes);
 
@@ -319,11 +332,11 @@
 }
 
 TEST_F(MallocDebugConfigTest, fill_on_free) {
-  ASSERT_TRUE(InitConfig("fill_on_free=64"));
+  ASSERT_TRUE(InitConfig("fill_on_free=64")) << getFakeLogPrint();
   ASSERT_EQ(FILL_ON_FREE, config->options);
   ASSERT_EQ(64U, config->fill_on_free_bytes);
 
-  ASSERT_TRUE(InitConfig("fill_on_free"));
+  ASSERT_TRUE(InitConfig("fill_on_free")) << getFakeLogPrint();
   ASSERT_EQ(FILL_ON_FREE, config->options);
   ASSERT_EQ(SIZE_MAX, config->fill_on_free_bytes);
 
@@ -332,12 +345,12 @@
 }
 
 TEST_F(MallocDebugConfigTest, fill) {
-  ASSERT_TRUE(InitConfig("fill=64"));
+  ASSERT_TRUE(InitConfig("fill=64")) << getFakeLogPrint();
   ASSERT_EQ(FILL_ON_ALLOC | FILL_ON_FREE, config->options);
   ASSERT_EQ(64U, config->fill_on_alloc_bytes);
   ASSERT_EQ(64U, config->fill_on_free_bytes);
 
-  ASSERT_TRUE(InitConfig("fill"));
+  ASSERT_TRUE(InitConfig("fill")) << getFakeLogPrint();
   ASSERT_EQ(FILL_ON_ALLOC | FILL_ON_FREE, config->options);
   ASSERT_EQ(SIZE_MAX, config->fill_on_alloc_bytes);
   ASSERT_EQ(SIZE_MAX, config->fill_on_free_bytes);
@@ -347,11 +360,11 @@
 }
 
 TEST_F(MallocDebugConfigTest, expand_alloc) {
-  ASSERT_TRUE(InitConfig("expand_alloc=1234"));
+  ASSERT_TRUE(InitConfig("expand_alloc=1234")) << getFakeLogPrint();
   ASSERT_EQ(EXPAND_ALLOC, config->options);
   ASSERT_EQ(1234U, config->expand_alloc_bytes);
 
-  ASSERT_TRUE(InitConfig("expand_alloc"));
+  ASSERT_TRUE(InitConfig("expand_alloc")) << getFakeLogPrint();
   ASSERT_EQ(EXPAND_ALLOC, config->options);
   ASSERT_EQ(16U, config->expand_alloc_bytes);
 
@@ -360,13 +373,13 @@
 }
 
 TEST_F(MallocDebugConfigTest, free_track) {
-  ASSERT_TRUE(InitConfig("free_track=1234"));
+  ASSERT_TRUE(InitConfig("free_track=1234")) << getFakeLogPrint();
   ASSERT_EQ(FREE_TRACK | FILL_ON_FREE, config->options);
   ASSERT_EQ(1234U, config->free_track_allocations);
   ASSERT_EQ(SIZE_MAX, config->fill_on_free_bytes);
   ASSERT_EQ(16U, config->free_track_backtrace_num_frames);
 
-  ASSERT_TRUE(InitConfig("free_track"));
+  ASSERT_TRUE(InitConfig("free_track")) << getFakeLogPrint();
   ASSERT_EQ(FREE_TRACK | FILL_ON_FREE, config->options);
   ASSERT_EQ(100U, config->free_track_allocations);
   ASSERT_EQ(SIZE_MAX, config->fill_on_free_bytes);
@@ -377,13 +390,13 @@
 }
 
 TEST_F(MallocDebugConfigTest, free_track_and_fill_on_free) {
-  ASSERT_TRUE(InitConfig("free_track=1234 fill_on_free=32"));
+  ASSERT_TRUE(InitConfig("free_track=1234 fill_on_free=32")) << getFakeLogPrint();
   ASSERT_EQ(FREE_TRACK | FILL_ON_FREE, config->options);
   ASSERT_EQ(1234U, config->free_track_allocations);
   ASSERT_EQ(32U, config->fill_on_free_bytes);
   ASSERT_EQ(16U, config->free_track_backtrace_num_frames);
 
-  ASSERT_TRUE(InitConfig("free_track fill_on_free=60"));
+  ASSERT_TRUE(InitConfig("free_track fill_on_free=60")) << getFakeLogPrint();
   ASSERT_EQ(FREE_TRACK | FILL_ON_FREE, config->options);
   ASSERT_EQ(100U, config->free_track_allocations);
   ASSERT_EQ(60U, config->fill_on_free_bytes);
@@ -394,12 +407,12 @@
 }
 
 TEST_F(MallocDebugConfigTest, free_track_backtrace_num_frames) {
-  ASSERT_TRUE(InitConfig("free_track_backtrace_num_frames=123"));
+  ASSERT_TRUE(InitConfig("free_track_backtrace_num_frames=123")) << getFakeLogPrint();
 
   ASSERT_EQ(0U, config->options);
   ASSERT_EQ(123U, config->free_track_backtrace_num_frames);
 
-  ASSERT_TRUE(InitConfig("free_track_backtrace_num_frames"));
+  ASSERT_TRUE(InitConfig("free_track_backtrace_num_frames")) << getFakeLogPrint();
   ASSERT_EQ(0U, config->options);
   ASSERT_EQ(16U, config->free_track_backtrace_num_frames);
 
@@ -408,7 +421,7 @@
 }
 
 TEST_F(MallocDebugConfigTest, free_track_backtrace_num_frames_zero) {
-  ASSERT_TRUE(InitConfig("free_track_backtrace_num_frames=0"));
+  ASSERT_TRUE(InitConfig("free_track_backtrace_num_frames=0")) << getFakeLogPrint();
 
   ASSERT_EQ(0U, config->options);
   ASSERT_EQ(0U, config->free_track_backtrace_num_frames);
@@ -418,11 +431,11 @@
 }
 
 TEST_F(MallocDebugConfigTest, free_track_backtrace_num_frames_and_free_track) {
-  ASSERT_TRUE(InitConfig("free_track free_track_backtrace_num_frames=123"));
+  ASSERT_TRUE(InitConfig("free_track free_track_backtrace_num_frames=123")) << getFakeLogPrint();
   ASSERT_EQ(FREE_TRACK | FILL_ON_FREE, config->options);
   ASSERT_EQ(123U, config->free_track_backtrace_num_frames);
 
-  ASSERT_TRUE(InitConfig("free_track free_track_backtrace_num_frames"));
+  ASSERT_TRUE(InitConfig("free_track free_track_backtrace_num_frames")) << getFakeLogPrint();
   ASSERT_EQ(FREE_TRACK | FILL_ON_FREE, config->options);
   ASSERT_EQ(16U, config->free_track_backtrace_num_frames);
 
@@ -431,7 +444,7 @@
 }
 
 TEST_F(MallocDebugConfigTest, leak_track) {
-  ASSERT_TRUE(InitConfig("leak_track"));
+  ASSERT_TRUE(InitConfig("leak_track")) << getFakeLogPrint();
   ASSERT_EQ(LEAK_TRACK | TRACK_ALLOCS, config->options);
 
   ASSERT_STREQ("", getFakeLogBuf().c_str());
@@ -439,7 +452,7 @@
 }
 
 TEST_F(MallocDebugConfigTest, leak_track_fail) {
-  ASSERT_FALSE(InitConfig("leak_track=100"));
+  ASSERT_FALSE(InitConfig("leak_track=100")) << getFakeLogPrint();
 
   ASSERT_STREQ("", getFakeLogBuf().c_str());
   std::string log_msg(
@@ -448,6 +461,32 @@
   ASSERT_STREQ((log_msg + usage_string).c_str(), getFakeLogPrint().c_str());
 }
 
+TEST_F(MallocDebugConfigTest, record_allocs) {
+  ASSERT_TRUE(InitConfig("record_allocs=1234")) << getFakeLogPrint();
+  ASSERT_EQ(RECORD_ALLOCS, config->options);
+  ASSERT_EQ(1234U, config->record_allocs_num_entries);
+  ASSERT_STREQ("/data/local/tmp/record_allocs.txt", config->record_allocs_file.c_str());
+
+  ASSERT_TRUE(InitConfig("record_allocs")) << getFakeLogPrint();
+  ASSERT_EQ(RECORD_ALLOCS, config->options);
+  ASSERT_EQ(8000000U, config->record_allocs_num_entries);
+  ASSERT_STREQ("/data/local/tmp/record_allocs.txt", config->record_allocs_file.c_str());
+
+  ASSERT_STREQ("", getFakeLogBuf().c_str());
+  ASSERT_STREQ("", getFakeLogPrint().c_str());
+}
+
+TEST_F(MallocDebugConfigTest, record_allocs_file) {
+  ASSERT_TRUE(InitConfig("record_allocs=1234 record_allocs_file=/fake/file")) << getFakeLogPrint();
+  ASSERT_STREQ("/fake/file", config->record_allocs_file.c_str());
+
+  ASSERT_TRUE(InitConfig("record_allocs_file")) << getFakeLogPrint();
+  ASSERT_STREQ("/data/local/tmp/record_allocs.txt", config->record_allocs_file.c_str());
+
+  ASSERT_STREQ("", getFakeLogBuf().c_str());
+  ASSERT_STREQ("", getFakeLogPrint().c_str());
+}
+
 TEST_F(MallocDebugConfigTest, guard_min_error) {
   ASSERT_FALSE(InitConfig("guard=0"));
 
@@ -626,3 +665,23 @@
       "value must be <= 256: 400\n");
   ASSERT_STREQ((log_msg + usage_string).c_str(), getFakeLogPrint().c_str());
 }
+
+TEST_F(MallocDebugConfigTest, record_alloc_min_error) {
+  ASSERT_FALSE(InitConfig("record_allocs=0"));
+
+  ASSERT_STREQ("", getFakeLogBuf().c_str());
+  std::string log_msg(
+      "6 malloc_debug malloc_testing: bad value for option 'record_allocs', "
+      "value must be >= 1: 0\n");
+  ASSERT_STREQ((log_msg + usage_string).c_str(), getFakeLogPrint().c_str());
+}
+
+TEST_F(MallocDebugConfigTest, record_allocs_max_error) {
+  ASSERT_FALSE(InitConfig("record_allocs=100000000"));
+
+  ASSERT_STREQ("", getFakeLogBuf().c_str());
+  std::string log_msg(
+      "6 malloc_debug malloc_testing: bad value for option 'record_allocs', "
+      "value must be <= 50000000: 100000000\n");
+  ASSERT_STREQ((log_msg + usage_string).c_str(), getFakeLogPrint().c_str());
+}
diff --git a/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp b/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp
index 014b913..edb03f6 100644
--- a/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp
+++ b/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp
@@ -30,6 +30,7 @@
 
 #include <gtest/gtest.h>
 
+#include <android-base/file.h>
 #include <android-base/stringprintf.h>
 
 #include <private/bionic_macros.h>
@@ -79,12 +80,16 @@
   return offset;
 }
 
+static constexpr const char RECORD_ALLOCS_FILE[] = "/data/local/tmp/record_allocs.txt";
+
 class MallocDebugTest : public ::testing::Test {
  protected:
   void SetUp() override {
     initialized = false;
     resetLogs();
     backtrace_fake_clear_all();
+    // Delete the record data file if it exists.
+    unlink(RECORD_ALLOCS_FILE);
   }
 
   void TearDown() override {
@@ -1266,7 +1271,7 @@
   debug_free_malloc_leak_info(info);
 
   // Send the signal to enable.
-  ASSERT_TRUE(kill(getpid(), SIGRTMIN + 10) == 0);
+  ASSERT_TRUE(kill(getpid(), SIGRTMAX - 19) == 0);
   sleep(1);
 
   pointer = debug_malloc(100);
@@ -1291,7 +1296,7 @@
   debug_free_malloc_leak_info(info);
 
   // Send the signal to disable.
-  ASSERT_TRUE(kill(getpid(), SIGRTMIN + 10) == 0);
+  ASSERT_TRUE(kill(getpid(), SIGRTMAX - 19) == 0);
   sleep(1);
 
   pointer = debug_malloc(200);
@@ -1311,7 +1316,7 @@
   ASSERT_STREQ("", getFakeLogBuf().c_str());
   std::string expected_log = android::base::StringPrintf(
       "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to enable backtracing.\n",
-      SIGRTMIN + 10, getpid());
+      SIGRTMAX - 19, getpid());
   ASSERT_STREQ(expected_log.c_str(), getFakeLogPrint().c_str());
 }
 
@@ -1512,3 +1517,231 @@
   debug_free(pointer);
 }
 #endif
+
+void VerifyRecordAllocs() {
+  std::string expected;
+
+  void* pointer = debug_malloc(10);
+  ASSERT_TRUE(pointer != nullptr);
+  expected += android::base::StringPrintf("%d: malloc %p 10\n", getpid(), pointer);
+  debug_free(pointer);
+  expected += android::base::StringPrintf("%d: free %p\n", getpid(), pointer);
+
+  pointer = debug_calloc(1, 20);
+  ASSERT_TRUE(pointer != nullptr);
+  expected += android::base::StringPrintf("%d: calloc %p 20 1\n", getpid(), pointer);
+  debug_free(pointer);
+  expected += android::base::StringPrintf("%d: free %p\n", getpid(), pointer);
+
+  pointer = debug_realloc(nullptr, 30);
+  ASSERT_TRUE(pointer != nullptr);
+  expected += android::base::StringPrintf("%d: realloc %p 0x0 30\n", getpid(), pointer);
+  void* old_pointer = pointer;
+  pointer = debug_realloc(pointer, 2048);
+  ASSERT_TRUE(pointer != nullptr);
+  expected += android::base::StringPrintf("%d: realloc %p %p 2048\n", getpid(),
+                                          pointer, old_pointer);
+  debug_realloc(pointer, 0);
+  expected += android::base::StringPrintf("%d: realloc 0x0 %p 0\n", getpid(), pointer);
+
+  pointer = debug_memalign(16, 40);
+  ASSERT_TRUE(pointer != nullptr);
+  expected += android::base::StringPrintf("%d: memalign %p 16 40\n", getpid(), pointer);
+  debug_free(pointer);
+  expected += android::base::StringPrintf("%d: free %p\n", getpid(), pointer);
+
+  ASSERT_EQ(0, debug_posix_memalign(&pointer, 32, 50));
+  ASSERT_TRUE(pointer != nullptr);
+  expected += android::base::StringPrintf("%d: memalign %p 32 50\n", getpid(), pointer);
+  debug_free(pointer);
+  expected += android::base::StringPrintf("%d: free %p\n", getpid(), pointer);
+
+#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
+  pointer = debug_pvalloc(60);
+  ASSERT_TRUE(pointer != nullptr);
+  expected += android::base::StringPrintf("%d: memalign %p 4096 4096\n", getpid(), pointer);
+  debug_free(pointer);
+  expected += android::base::StringPrintf("%d: free %p\n", getpid(), pointer);
+
+  pointer = debug_valloc(70);
+  ASSERT_TRUE(pointer != nullptr);
+  expected += android::base::StringPrintf("%d: memalign %p 4096 70\n", getpid(), pointer);
+  debug_free(pointer);
+  expected += android::base::StringPrintf("%d: free %p\n", getpid(), pointer);
+#endif
+
+  // Dump all of the data accumulated so far.
+  ASSERT_TRUE(kill(getpid(), SIGRTMAX - 18) == 0);
+  sleep(1);
+
+  // This triggers the dumping.
+  pointer = debug_malloc(110);
+  ASSERT_TRUE(pointer != nullptr);
+  expected += android::base::StringPrintf("%d: malloc %p 110\n", getpid(), pointer);
+
+  // Read all of the contents.
+  std::string actual;
+  ASSERT_TRUE(android::base::ReadFileToString(RECORD_ALLOCS_FILE, &actual));
+
+  ASSERT_STREQ(expected.c_str(), actual.c_str());
+
+  ASSERT_STREQ("", getFakeLogBuf().c_str());
+  std::string expected_log = android::base::StringPrintf(
+      "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to dump the allocation records.\n",
+      SIGRTMAX - 18, getpid());
+  ASSERT_STREQ(expected_log.c_str(), getFakeLogPrint().c_str());
+
+  debug_free(pointer);
+}
+
+TEST_F(MallocDebugTest, record_allocs_no_header) {
+  Init("record_allocs");
+
+  VerifyRecordAllocs();
+}
+
+TEST_F(MallocDebugTest, record_allocs_with_header) {
+  Init("record_allocs front_guard");
+
+  VerifyRecordAllocs();
+}
+
+TEST_F(MallocDebugTest, record_allocs_max) {
+  Init("record_allocs=5");
+
+  std::string expected;
+
+  void* pointer = debug_malloc(10);
+  ASSERT_TRUE(pointer != nullptr);
+  expected += android::base::StringPrintf("%d: malloc %p 10\n", getpid(), pointer);
+  debug_free(pointer);
+  expected += android::base::StringPrintf("%d: free %p\n", getpid(), pointer);
+
+  pointer = debug_malloc(20);
+  ASSERT_TRUE(pointer != nullptr);
+  expected += android::base::StringPrintf("%d: malloc %p 20\n", getpid(), pointer);
+  debug_free(pointer);
+  expected += android::base::StringPrintf("%d: free %p\n", getpid(), pointer);
+
+  pointer = debug_malloc(1024);
+  ASSERT_TRUE(pointer != nullptr);
+  expected += android::base::StringPrintf("%d: malloc %p 1024\n", getpid(), pointer);
+  debug_free(pointer);
+
+  // Dump all of the data accumulated so far.
+  ASSERT_TRUE(kill(getpid(), SIGRTMAX - 18) == 0);
+  sleep(1);
+
+  // This triggers the dumping.
+  pointer = debug_malloc(110);
+  ASSERT_TRUE(pointer != nullptr);
+
+  // Read all of the contents.
+  std::string actual;
+  ASSERT_TRUE(android::base::ReadFileToString(RECORD_ALLOCS_FILE, &actual));
+
+  ASSERT_STREQ(expected.c_str(), actual.c_str());
+
+  ASSERT_STREQ("", getFakeLogBuf().c_str());
+  std::string expected_log = android::base::StringPrintf(
+      "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to dump the allocation records.\n",
+      SIGRTMAX - 18, getpid());
+  ASSERT_STREQ(expected_log.c_str(), getFakeLogPrint().c_str());
+
+  debug_free(pointer);
+}
+
+TEST_F(MallocDebugTest, record_allocs_thread_done) {
+  Init("record_allocs=5");
+
+  static pid_t tid = 0;
+  static void* pointer = nullptr;
+  std::thread thread([](){
+    tid = gettid();
+    pointer = debug_malloc(100);
+    write(0, pointer, 0);
+    debug_free(pointer);
+  });
+  thread.join();
+
+  std::string expected = android::base::StringPrintf("%d: malloc %p 100\n", tid, pointer);
+  expected += android::base::StringPrintf("%d: free %p\n", tid, pointer);
+  expected += android::base::StringPrintf("%d: thread_done 0x0\n", tid);
+
+  // Dump all of the data accumulated so far.
+  ASSERT_TRUE(kill(getpid(), SIGRTMAX - 18) == 0);
+  sleep(1);
+
+  // This triggers the dumping.
+  pointer = debug_malloc(23);
+  ASSERT_TRUE(pointer != nullptr);
+  expected += android::base::StringPrintf("%d: malloc %p 23\n", getpid(), pointer);
+
+  // Read all of the contents.
+  std::string actual;
+  ASSERT_TRUE(android::base::ReadFileToString(RECORD_ALLOCS_FILE, &actual));
+
+  ASSERT_STREQ(expected.c_str(), actual.c_str());
+
+  ASSERT_STREQ("", getFakeLogBuf().c_str());
+  std::string expected_log = android::base::StringPrintf(
+      "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to dump the allocation records.\n",
+      SIGRTMAX - 18, getpid());
+  ASSERT_STREQ(expected_log.c_str(), getFakeLogPrint().c_str());
+
+  debug_free(pointer);
+}
+
+TEST_F(MallocDebugTest, record_allocs_file_name_fail) {
+  Init("record_allocs=5");
+
+  // Delete the special.txt file and create a symbolic link there to
+  // make sure the create file will fail.
+  unlink(RECORD_ALLOCS_FILE);
+
+  ASSERT_EQ(0, symlink("/data/local/tmp/does_not_exist", RECORD_ALLOCS_FILE));
+
+  std::string expected;
+
+  void* pointer = debug_malloc(10);
+  ASSERT_TRUE(pointer != nullptr);
+  expected += android::base::StringPrintf("%d: malloc %p 10\n", getpid(), pointer);
+  debug_free(pointer);
+  expected += android::base::StringPrintf("%d: free %p\n", getpid(), pointer);
+
+  // Dump all of the data accumulated so far.
+  ASSERT_TRUE(kill(getpid(), SIGRTMAX - 18) == 0);
+  sleep(1);
+
+  // This triggers the dumping.
+  pointer = debug_malloc(110);
+  ASSERT_TRUE(pointer != nullptr);
+  expected += android::base::StringPrintf("%d: malloc %p 110\n", getpid(), pointer);
+
+  // Read all of the contents.
+  std::string actual;
+  ASSERT_FALSE(android::base::ReadFileToString(RECORD_ALLOCS_FILE, &actual));
+
+  // Unlink the file so the next dump passes.
+  ASSERT_EQ(0, unlink(RECORD_ALLOCS_FILE));
+
+  // Dump all of the data accumulated so far.
+  ASSERT_TRUE(kill(getpid(), SIGRTMAX - 18) == 0);
+  sleep(1);
+
+  // This triggers the dumping.
+  debug_free(pointer);
+  expected += android::base::StringPrintf("%d: free %p\n", getpid(), pointer);
+
+  ASSERT_TRUE(android::base::ReadFileToString(RECORD_ALLOCS_FILE, &actual));
+  ASSERT_STREQ(expected.c_str(), actual.c_str());
+
+  ASSERT_STREQ("", getFakeLogBuf().c_str());
+  std::string expected_log = android::base::StringPrintf(
+      "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to dump the allocation records.\n",
+      SIGRTMAX - 18, getpid());
+  expected_log += android::base::StringPrintf(
+      "6 malloc_debug Cannot create record alloc file %s: Too many symbolic links encountered\n",
+      RECORD_ALLOCS_FILE);
+  ASSERT_STREQ(expected_log.c_str(), getFakeLogPrint().c_str());
+}
diff --git a/libc/private/UniquePtr.h b/libc/private/UniquePtr.h
deleted file mode 100644
index 5ac7599..0000000
--- a/libc/private/UniquePtr.h
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Copyright (C) 2010 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.
- */
-
-#ifndef UNIQUE_PTR_H_included
-#define UNIQUE_PTR_H_included
-
-// Default deleter for pointer types.
-template <typename T>
-struct DefaultDelete {
-    enum { type_must_be_complete = sizeof(T) };
-    DefaultDelete() {}
-    void operator()(T* p) const {
-        delete p;
-    }
-};
-
-// Default deleter for array types.
-template <typename T>
-struct DefaultDelete<T[]> {
-    enum { type_must_be_complete = sizeof(T) };
-    void operator()(T* p) const {
-        delete[] p;
-    }
-};
-
-// A smart pointer that deletes the given pointer on destruction.
-// Equivalent to C++0x's std::unique_ptr (a combination of boost::scoped_ptr
-// and boost::scoped_array).
-// Named to be in keeping with Android style but also to avoid
-// collision with any other implementation, until we can switch over
-// to unique_ptr.
-// Use thus:
-//   UniquePtr<C> c(new C);
-template <typename T, typename D = DefaultDelete<T> >
-class UniquePtr {
-public:
-    // Construct a new UniquePtr, taking ownership of the given raw pointer.
-    explicit UniquePtr(T* ptr = nullptr) : mPtr(ptr) { }
-
-    UniquePtr(UniquePtr<T, D>&& that) {
-      mPtr = that.mPtr;
-      that.mPtr = nullptr;
-    }
-
-    ~UniquePtr() {
-        reset();
-    }
-
-    // Accessors.
-    T& operator*() const { return *mPtr; }
-    T* operator->() const { return mPtr; }
-    T* get() const { return mPtr; }
-
-    // Returns the raw pointer and hands over ownership to the caller.
-    // The pointer will not be deleted by UniquePtr.
-    T* release() __attribute__((warn_unused_result)) {
-        T* result = mPtr;
-        mPtr = nullptr;
-        return result;
-    }
-
-    // Takes ownership of the given raw pointer.
-    // If this smart pointer previously owned a different raw pointer, that
-    // raw pointer will be freed.
-    void reset(T* ptr = nullptr) {
-        if (ptr != mPtr) {
-            D()(mPtr);
-            mPtr = ptr;
-        }
-    }
-
-private:
-    // The raw pointer.
-    T* mPtr;
-
-    // Comparing unique pointers is probably a mistake, since they're unique.
-    template <typename T2> bool operator==(const UniquePtr<T2>& p) const = delete;
-    template <typename T2> bool operator!=(const UniquePtr<T2>& p) const = delete;
-
-    // Disallow copy and assignment.
-    UniquePtr(const UniquePtr&) = delete;
-    void operator=(const UniquePtr&) = delete;
-};
-
-// Partial specialization for array types. Like std::unique_ptr, this removes
-// operator* and operator-> but adds operator[].
-template <typename T, typename D>
-class UniquePtr<T[], D> {
-public:
-    explicit UniquePtr(T* ptr = NULL) : mPtr(ptr) {
-    }
-    UniquePtr(UniquePtr<T, D>&& that) {
-      mPtr = that.mPtr;
-      that.mPtr = nullptr;
-    }
-
-    ~UniquePtr() {
-        reset();
-    }
-
-    T& operator[](size_t i) const {
-        return mPtr[i];
-    }
-    T* get() const { return mPtr; }
-
-    T* release() __attribute__((warn_unused_result)) {
-        T* result = mPtr;
-        mPtr = NULL;
-        return result;
-    }
-
-    void reset(T* ptr = NULL) {
-        if (ptr != mPtr) {
-            D()(mPtr);
-            mPtr = ptr;
-        }
-    }
-
-private:
-    T* mPtr;
-
-    // Disallow copy and assignment.
-    UniquePtr(const UniquePtr&) = delete;
-    void operator=(const UniquePtr&) = delete;
-};
-
-#endif  // UNIQUE_PTR_H_included
diff --git a/libc/include/sys/_errdefs.h b/libc/private/bionic_errdefs.h
similarity index 100%
rename from libc/include/sys/_errdefs.h
rename to libc/private/bionic_errdefs.h
diff --git a/libc/private/bionic_fortify.h b/libc/private/bionic_fortify.h
new file mode 100644
index 0000000..df810ca
--- /dev/null
+++ b/libc/private/bionic_fortify.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2016 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 "private/libc_logging.h"
+
+#include <poll.h> // For struct pollfd.
+#include <sys/select.h> // For struct fd_set.
+
+//
+// Common helpers.
+//
+
+static inline void __check_fd_set(const char* fn, int fd, size_t set_size) {
+  if (__predict_false(fd < 0)) {
+    __fortify_fatal("%s: file descriptor %d < 0", fn, fd);
+  }
+  if (__predict_false(fd >= FD_SETSIZE)) {
+    __fortify_fatal("%s: file descriptor %d >= FD_SETSIZE %zu", fn, fd, set_size);
+  }
+  if (__predict_false(set_size < sizeof(fd_set))) {
+    __fortify_fatal("%s: set size %zu is too small to be an fd_set", fn, set_size);
+  }
+}
+
+static inline void __check_pollfd_array(const char* fn, size_t fds_size, nfds_t fd_count) {
+  size_t pollfd_array_length = fds_size / sizeof(pollfd);
+  if (__predict_false(pollfd_array_length < fd_count)) {
+    __fortify_fatal("%s: %zu-element pollfd array too small for %u fds",
+                    fn, pollfd_array_length, fd_count);
+  }
+}
+
+static inline void __check_count(const char* fn, const char* identifier, size_t value) {
+  if (__predict_false(value > SSIZE_MAX)) {
+    __fortify_fatal("%s: %s %zu > SSIZE_MAX", fn, identifier, value);
+  }
+}
+
+static inline void __check_buffer_access(const char* fn, const char* action,
+                                         size_t claim, size_t actual) {
+  if (__predict_false(claim > actual)) {
+    __fortify_fatal("%s: prevented %zu-byte %s %zu-byte buffer", fn, claim, action, actual);
+  }
+}
diff --git a/libc/private/bionic_globals.h b/libc/private/bionic_globals.h
index b45c0c3..94dd7e8 100644
--- a/libc/private/bionic_globals.h
+++ b/libc/private/bionic_globals.h
@@ -44,7 +44,6 @@
 __LIBC_HIDDEN__ extern WriteProtected<libc_globals> __libc_globals;
 
 class KernelArgumentBlock;
-__LIBC_HIDDEN__ void __libc_init_global_stack_chk_guard(KernelArgumentBlock& args);
 __LIBC_HIDDEN__ void __libc_init_malloc(libc_globals* globals);
 __LIBC_HIDDEN__ void __libc_init_setjmp_cookie(libc_globals* globals, KernelArgumentBlock& args);
 __LIBC_HIDDEN__ void __libc_init_vdso(libc_globals* globals, KernelArgumentBlock& args);
diff --git a/libc/include/machine/ieee.h b/libc/private/bionic_ieee.h
similarity index 100%
rename from libc/include/machine/ieee.h
rename to libc/private/bionic_ieee.h
diff --git a/libc/private/bionic_macros.h b/libc/private/bionic_macros.h
index 4969bd9..d5c5b9c 100644
--- a/libc/private/bionic_macros.h
+++ b/libc/private/bionic_macros.h
@@ -17,6 +17,8 @@
 #ifndef _BIONIC_MACROS_H_
 #define _BIONIC_MACROS_H_
 
+#include <stdint.h>
+
 // Frameworks OpenGL code currently leaks this header and allows
 // collisions with other declarations, e.g., from libnativehelper.
 // TODO: Remove once cleaned up. b/18334516
@@ -46,4 +48,22 @@
     ? (1UL << (64 - __builtin_clzl(static_cast<unsigned long>(value)))) \
     : (1UL << (32 - __builtin_clz(static_cast<unsigned int>(value)))))
 
+static inline uintptr_t align_down(uintptr_t p, size_t align) {
+  return p & ~(align - 1);
+}
+
+static inline uintptr_t align_up(uintptr_t p, size_t align) {
+  return (p + align - 1) & ~(align - 1);
+}
+
+template <typename T>
+static inline T* align_down(T* p, size_t align) {
+  return reinterpret_cast<T*>(align_down(reinterpret_cast<uintptr_t>(p), align));
+}
+
+template <typename T>
+static inline T* align_up(T* p, size_t align) {
+  return reinterpret_cast<T*>(align_up(reinterpret_cast<uintptr_t>(p), align));
+}
+
 #endif // _BIONIC_MACROS_H_
diff --git a/libc/include/sys/_sigdefs.h b/libc/private/bionic_sigdefs.h
similarity index 100%
rename from libc/include/sys/_sigdefs.h
rename to libc/private/bionic_sigdefs.h
diff --git a/libc/private/bionic_time_conversions.h b/libc/private/bionic_time_conversions.h
index a834843..b9eaad2 100644
--- a/libc/private/bionic_time_conversions.h
+++ b/libc/private/bionic_time_conversions.h
@@ -42,9 +42,6 @@
 
 __LIBC_HIDDEN__ void timeval_from_timespec(timeval& tv, const timespec& ts);
 
-__LIBC_HIDDEN__ void absolute_timespec_from_timespec(timespec& abs_ts, const timespec& ts,
-                                                     clockid_t clock);
-
 __END_DECLS
 
 static inline int check_timespec(const timespec* ts, bool null_allowed) {
@@ -62,4 +59,16 @@
   return 0;
 }
 
+#if !defined(__LP64__)
+static inline void absolute_timespec_from_timespec(timespec& abs_ts, const timespec& ts, clockid_t clock) {
+  clock_gettime(clock, &abs_ts);
+  abs_ts.tv_sec += ts.tv_sec;
+  abs_ts.tv_nsec += ts.tv_nsec;
+  if (abs_ts.tv_nsec >= NS_PER_S) {
+    abs_ts.tv_nsec -= NS_PER_S;
+    abs_ts.tv_sec++;
+  }
+}
+#endif
+
 #endif
diff --git a/libc/private/bionic_vdso.h b/libc/private/bionic_vdso.h
index 5400de5..8fd0743 100644
--- a/libc/private/bionic_vdso.h
+++ b/libc/private/bionic_vdso.h
@@ -25,6 +25,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #ifndef _PRIVATE_BIONIC_VDSO_H
 #define _PRIVATE_BIONIC_VDSO_H
 
@@ -33,7 +34,7 @@
 #if defined(__aarch64__)
 #define VDSO_CLOCK_GETTIME_SYMBOL "__kernel_clock_gettime"
 #define VDSO_GETTIMEOFDAY_SYMBOL  "__kernel_gettimeofday"
-#elif defined(__x86_64__) || defined(__i386__)
+#elif defined(__arm__) || defined(__i386__) || defined(__x86_64__)
 #define VDSO_CLOCK_GETTIME_SYMBOL "__vdso_clock_gettime"
 #define VDSO_GETTIMEOFDAY_SYMBOL  "__vdso_gettimeofday"
 #endif
diff --git a/libc/private/libc_events.h b/libc/private/libc_events.h
deleted file mode 100644
index f2b973d..0000000
--- a/libc/private/libc_events.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2013 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.
- */
-
-#ifndef _LIBC_EVENTS_H
-#define _LIBC_EVENTS_H
-
-
-// This is going to be included in assembler code so only allow #define
-// values instead of defining an enum.
-
-#define BIONIC_EVENT_MEMCPY_BUFFER_OVERFLOW   80100
-#define BIONIC_EVENT_STRCAT_BUFFER_OVERFLOW   80105
-#define BIONIC_EVENT_MEMMOVE_BUFFER_OVERFLOW  80110
-#define BIONIC_EVENT_STRNCAT_BUFFER_OVERFLOW  80115
-#define BIONIC_EVENT_STRNCPY_BUFFER_OVERFLOW  80120
-#define BIONIC_EVENT_MEMSET_BUFFER_OVERFLOW   80125
-#define BIONIC_EVENT_STRCPY_BUFFER_OVERFLOW   80130
-#define BIONIC_EVENT_STPCPY_BUFFER_OVERFLOW   80135
-#define BIONIC_EVENT_STPNCPY_BUFFER_OVERFLOW  80140
-
-#define BIONIC_EVENT_RESOLVER_OLD_RESPONSE    80300
-#define BIONIC_EVENT_RESOLVER_WRONG_SERVER    80305
-#define BIONIC_EVENT_RESOLVER_WRONG_QUERY     80310
-
-#endif // _LIBC_EVENTS_H
diff --git a/libc/private/libc_logging.h b/libc/private/libc_logging.h
index e389565..9fa5982 100644
--- a/libc/private/libc_logging.h
+++ b/libc/private/libc_logging.h
@@ -36,8 +36,6 @@
 
 __BEGIN_DECLS
 
-#include "libc_events.h"
-
 enum {
   ANDROID_LOG_UNKNOWN = 0,
   ANDROID_LOG_DEFAULT,    /* only for SetMinPriority() */
@@ -69,48 +67,26 @@
   char msg[0];
 };
 
-//
 // Formats a message to the log (priority 'fatal'), then aborts.
-//
+__noreturn void __libc_fatal(const char* _Nonnull, ...) __printflike(1, 2);
 
-__LIBC_HIDDEN__ __noreturn void __libc_fatal(const char* format, ...) __printflike(1, 2);
-
-//
-// Formats a message to the log (priority 'fatal'), but doesn't abort.
-// Used by the malloc implementation to ensure that debuggerd dumps memory
-// around the bad address.
-//
-
-__LIBC_HIDDEN__ void __libc_fatal_no_abort(const char* format, ...)
-    __printflike(1, 2);
+// Formats a message to the log (priority 'fatal'), prefixed by "FORTIFY: ", then aborts.
+__noreturn void __fortify_fatal(const char* _Nonnull, ...) __printflike(1, 2);
 
 //
 // Formatting routines for the C library's internal debugging.
 // Unlike the usual alternatives, these don't allocate, and they don't drag in all of stdio.
 //
 
-__LIBC_HIDDEN__ int __libc_format_buffer(char* buffer, size_t buffer_size, const char* format, ...)
-    __printflike(3, 4);
-
-__LIBC_HIDDEN__ int __libc_format_fd(int fd, const char* format, ...)
-    __printflike(2, 3);
-
-__LIBC_HIDDEN__ int __libc_format_log(int priority, const char* tag, const char* format, ...)
-    __printflike(3, 4);
-
-__LIBC_HIDDEN__ int __libc_format_log_va_list(int priority, const char* tag, const char* format,
-                                              va_list ap);
-
-__LIBC_HIDDEN__ int __libc_write_log(int priority, const char* tag, const char* msg);
-
-//
-// Event logging.
-//
-
-__LIBC_HIDDEN__ void __libc_android_log_event_int(int32_t tag, int value);
-__LIBC_HIDDEN__ void __libc_android_log_event_uid(int32_t tag);
-
-__LIBC_HIDDEN__ __noreturn void __fortify_chk_fail(const char* msg, uint32_t event_tag);
+int __libc_format_buffer(char* _Nonnull buf, size_t size, const char* _Nonnull fmt, ...) __printflike(3, 4);
+int __libc_format_fd(int fd, const char* _Nonnull format , ...) __printflike(2, 3);
+int __libc_format_log(int pri, const char* _Nonnull tag, const char* _Nonnull fmt, ...) __printflike(3, 4);
+#if defined(__arm__) || defined(__aarch64__) || defined(__x86_64__)
+int __libc_format_log_va_list(int pri, const char* _Nonnull tag, const char* _Nonnull fmt, va_list ap);
+#else // defined(__mips__) || defined(__i386__)
+int __libc_format_log_va_list(int pri, const char* _Nonnull tag, const char* _Nonnull fmt, va_list _Nonnull ap);
+#endif
+int __libc_write_log(int pri, const char* _Nonnull tag, const char* _Nonnull msg);
 
 __END_DECLS
 
diff --git a/libc/private/thread_private.h b/libc/private/thread_private.h
index 2e3ac3d..0081ad0 100644
--- a/libc/private/thread_private.h
+++ b/libc/private/thread_private.h
@@ -50,6 +50,8 @@
 #define _ARC4_UNLOCK() _thread_arc4_unlock()
 #define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
 
+extern volatile sig_atomic_t _rs_forked;
+
 __END_DECLS
 
 #endif /* _THREAD_PRIVATE_H_ */
diff --git a/libc/stdio/local.h b/libc/stdio/local.h
index 7fe339a..7be5a7c 100644
--- a/libc/stdio/local.h
+++ b/libc/stdio/local.h
@@ -200,8 +200,6 @@
 __LIBC32_LEGACY_PUBLIC__ int __sclose(void *);
 __LIBC32_LEGACY_PUBLIC__ int _fwalk(int (*)(FILE *));
 
-#pragma GCC visibility push(hidden)
-
 off64_t __sseek64(void*, off64_t, int);
 int	__sflush_locked(FILE *);
 int	__swhatbuf(FILE *, size_t *, int *);
@@ -248,19 +246,9 @@
 #define NO_PRINTF_PERCENT_N
 
 /* OpenBSD exposes these in <stdio.h>, but we only want them exposed to the implementation. */
-#define __sfeof(p)     (((p)->_flags & __SEOF) != 0)
 #define __sferror(p)   (((p)->_flags & __SERR) != 0)
 #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF)))
-#if !defined(__cplusplus)
 #define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
-static __inline int __sputc(int _c, FILE* _p) {
-  if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n')) {
-    return (*_p->_p++ = _c);
-  } else {
-    return (__swbuf(_c, _p));
-  }
-}
-#endif
 
 /* OpenBSD declares these in fvwrite.h but we want to ensure they're hidden. */
 struct __suio;
@@ -271,8 +259,6 @@
 extern void __sinit(void); // Not actually implemented.
 #define __sdidinit 1
 
-#pragma GCC visibility pop
-
 __END_DECLS
 
 #endif
diff --git a/libc/stdio/snprintf.c b/libc/stdio/snprintf.c
deleted file mode 100644
index 9a25ef2..0000000
--- a/libc/stdio/snprintf.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/*	$OpenBSD: snprintf.c,v 1.14 2005/10/10 12:00:52 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- */
-
-#undef _FORTIFY_SOURCE
-#include <limits.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-#include "local.h"
-
-int
-snprintf(char *str, size_t n, const char *fmt, ...)
-{
-	va_list ap;
-	int ret;
-	char dummy;
-	FILE f;
-	struct __sfileext fext;
-
-	/* While snprintf(3) specifies size_t stdio uses an int internally */
-	if (n > INT_MAX)
-		n = INT_MAX;
-	/* Stdio internals do not deal correctly with zero length buffer */
-	if (n == 0) {
-		str = &dummy;
-		n = 1;
-	}
-	_FILEEXT_SETUP(&f, &fext);
-	f._file = -1;
-	f._flags = __SWR | __SSTR;
-	f._bf._base = f._p = (unsigned char *)str;
-	f._bf._size = f._w = n - 1;
-	va_start(ap, fmt);
-	ret = __vfprintf(&f, fmt, ap);
-	va_end(ap);
-	*f._p = '\0';
-	return (ret);
-}
diff --git a/libc/stdio/sprintf.c b/libc/stdio/sprintf.c
deleted file mode 100644
index 1245552..0000000
--- a/libc/stdio/sprintf.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/*	$OpenBSD: sprintf.c,v 1.13 2005/10/10 12:00:52 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- */
-
-#undef _FORTIFY_SOURCE
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-#include <limits.h>
-#include "local.h"
-
-#if defined(APIWARN)
-__warn_references(sprintf,
-    "warning: sprintf() is often misused, please use snprintf()");
-#endif
-
-int
-sprintf(char *str, const char *fmt, ...)
-{
-	int ret;
-	va_list ap;
-	FILE f;
-	struct __sfileext fext;
-
-	_FILEEXT_SETUP(&f, &fext);
-	f._file = -1;
-	f._flags = __SWR | __SSTR;
-	f._bf._base = f._p = (unsigned char *)str;
-	f._bf._size = f._w = INT_MAX;
-	va_start(ap, fmt);
-	ret = __vfprintf(&f, fmt, ap);
-	va_end(ap);
-	*f._p = '\0';
-	return (ret);
-}
diff --git a/libc/stdio/stdio.cpp b/libc/stdio/stdio.cpp
index 1c31a27..c673611 100644
--- a/libc/stdio/stdio.cpp
+++ b/libc/stdio/stdio.cpp
@@ -31,11 +31,13 @@
  * SUCH DAMAGE.
  */
 
+#define __BIONIC_NO_STDIO_FORTIFY
 #include <stdio.h>
 
 #include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
+#include <paths.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/param.h>
@@ -52,6 +54,13 @@
 
 #define	NDYNAMIC 10		/* add ten more whenever necessary */
 
+#define PRINTF_IMPL(expr) \
+    va_list ap; \
+    va_start(ap, fmt); \
+    int result = (expr); \
+    va_end(ap); \
+    return result;
+
 #define std(flags, file) \
     {0,0,0,flags,file,{0,0},0,__sF+file,__sclose,__sread,nullptr,__swrite, \
     {(unsigned char *)(__sFext+file), 0},nullptr,0,{0},{0},{0,0},0,0}
@@ -90,7 +99,7 @@
 
 class ScopedFileLock {
  public:
-  ScopedFileLock(FILE* fp) : fp_(fp) {
+  explicit ScopedFileLock(FILE* fp) : fp_(fp) {
     FLOCKFILE(fp_);
   }
   ~ScopedFileLock() {
@@ -387,11 +396,47 @@
   return r;
 }
 
+int fileno_unlocked(FILE* fp) {
+  int fd = fp->_file;
+  if (fd == -1) {
+    errno = EBADF;
+    return -1;
+  }
+  return fd;
+}
+
 int fileno(FILE* fp) {
   ScopedFileLock sfl(fp);
   return fileno_unlocked(fp);
 }
 
+void clearerr_unlocked(FILE* fp) {
+  return __sclearerr(fp);
+}
+
+void clearerr(FILE* fp) {
+  ScopedFileLock sfl(fp);
+  clearerr_unlocked(fp);
+}
+
+int feof_unlocked(FILE* fp) {
+  return ((fp->_flags & __SEOF) != 0);
+}
+
+int feof(FILE* fp) {
+  ScopedFileLock sfl(fp);
+  return feof_unlocked(fp);
+}
+
+int ferror_unlocked(FILE* fp) {
+  return __sferror(fp);
+}
+
+int ferror(FILE* fp) {
+  ScopedFileLock sfl(fp);
+  return ferror_unlocked(fp);
+}
+
 int __sread(void* cookie, char* buf, int n) {
   FILE* fp = reinterpret_cast<FILE*>(cookie);
   return TEMP_FAILURE_RETRY(read(fp->_file, buf, n));
@@ -598,3 +643,181 @@
   }
   return fp;
 }
+
+int asprintf(char** s, const char* fmt, ...) {
+  PRINTF_IMPL(vasprintf(s, fmt, ap));
+}
+
+char* ctermid(char* s) {
+  return s ? strcpy(s, _PATH_TTY) : const_cast<char*>(_PATH_TTY);
+}
+
+int dprintf(int fd, const char* fmt, ...) {
+  PRINTF_IMPL(vdprintf(fd, fmt, ap));
+}
+
+int fprintf(FILE* fp, const char* fmt, ...) {
+  PRINTF_IMPL(vfprintf(fp, fmt, ap));
+}
+
+int fgetc(FILE* fp) {
+  return getc(fp);
+}
+
+int fputc(int c, FILE* fp) {
+  return putc(c, fp);
+}
+
+int fscanf(FILE* fp, const char* fmt, ...) {
+  PRINTF_IMPL(vfscanf(fp, fmt, ap));
+}
+
+int fwprintf(FILE* fp, const wchar_t* fmt, ...) {
+  PRINTF_IMPL(vfwprintf(fp, fmt, ap));
+}
+
+int fwscanf(FILE* fp, const wchar_t* fmt, ...) {
+  PRINTF_IMPL(vfwscanf(fp, fmt, ap));
+}
+
+int getc(FILE* fp) {
+  ScopedFileLock sfl(fp);
+  return getc_unlocked(fp);
+}
+
+int getc_unlocked(FILE* fp) {
+  return __sgetc(fp);
+}
+
+int getchar_unlocked() {
+  return getc_unlocked(stdin);
+}
+
+int getchar() {
+  return getc(stdin);
+}
+
+ssize_t getline(char** buf, size_t* len, FILE* fp) {
+  return getdelim(buf, len, '\n', fp);
+}
+
+wint_t getwc(FILE* fp) {
+  return fgetwc(fp);
+}
+
+wint_t getwchar() {
+  return fgetwc(stdin);
+}
+
+int printf(const char* fmt, ...) {
+  PRINTF_IMPL(vfprintf(stdout, fmt, ap));
+}
+
+int putc(int c, FILE* fp) {
+  ScopedFileLock sfl(fp);
+  return putc_unlocked(c, fp);
+}
+
+int putc_unlocked(int c, FILE* fp) {
+  if (cantwrite(fp)) {
+    errno = EBADF;
+    return EOF;
+  }
+  _SET_ORIENTATION(fp, -1);
+  if (--fp->_w >= 0 || (fp->_w >= fp->_lbfsize && c != '\n')) {
+    return (*fp->_p++ = c);
+  }
+  return (__swbuf(c, fp));
+}
+
+int putchar(int c) {
+  return putc(c, stdout);
+}
+
+int putchar_unlocked(int c) {
+  return putc_unlocked(c, stdout);
+}
+
+wint_t putwc(wchar_t wc, FILE* fp) {
+  return fputwc(wc, fp);
+}
+
+wint_t putwchar(wchar_t wc) {
+  return fputwc(wc, stdout);
+}
+
+int remove(const char* path) {
+  if (unlink(path) != -1) return 0;
+  if (errno != EISDIR) return -1;
+  return rmdir(path);
+}
+
+void rewind(FILE* fp) {
+  ScopedFileLock sfl(fp);
+  fseek(fp, 0, SEEK_SET);
+  clearerr_unlocked(fp);
+}
+
+int scanf(const char* fmt, ...) {
+  PRINTF_IMPL(vfscanf(stdin, fmt, ap));
+}
+
+void setbuf(FILE* fp, char* buf) {
+  setbuffer(fp, buf, BUFSIZ);
+}
+
+void setbuffer(FILE* fp, char* buf, int size) {
+  setvbuf(fp, buf, buf ? _IOFBF : _IONBF, size);
+}
+
+int setlinebuf(FILE* fp) {
+  return setvbuf(fp, nullptr, _IOLBF, 0);
+}
+
+int snprintf(char* s, size_t n, const char* fmt, ...) {
+  PRINTF_IMPL(vsnprintf(s, n, fmt, ap));
+}
+
+int sprintf(char* s, const char* fmt, ...) {
+  PRINTF_IMPL(vsnprintf(s, INT_MAX, fmt, ap));
+}
+
+int sscanf(const char* s, const char* fmt, ...) {
+  PRINTF_IMPL(vsscanf(s, fmt, ap));
+}
+
+int swprintf(wchar_t* s, size_t n, const wchar_t* fmt, ...) {
+  PRINTF_IMPL(vswprintf(s, n, fmt, ap));
+}
+
+int swscanf(const wchar_t* s, const wchar_t* fmt, ...) {
+  PRINTF_IMPL(vswscanf(s, fmt, ap));
+}
+
+int vprintf(const char* fmt, va_list ap) {
+  return vfprintf(stdout, fmt, ap);
+}
+
+int vscanf(const char* fmt, va_list ap) {
+  return vfscanf(stdin, fmt, ap);
+}
+
+int vsprintf(char* s, const char* fmt, va_list ap) {
+  return vsnprintf(s, INT_MAX, fmt, ap);
+}
+
+int vwprintf(const wchar_t* fmt, va_list ap) {
+  return vfwprintf(stdout, fmt, ap);
+}
+
+int vwscanf(const wchar_t* fmt, va_list ap) {
+  return vfwscanf(stdin, fmt, ap);
+}
+
+int wprintf(const wchar_t* fmt, ...) {
+  PRINTF_IMPL(vfwprintf(stdout, fmt, ap));
+}
+
+int wscanf(const wchar_t* fmt, ...) {
+  PRINTF_IMPL(vfwscanf(stdin, fmt, ap));
+}
diff --git a/libc/stdio/stdio_ext.cpp b/libc/stdio/stdio_ext.cpp
index 88e5951..f2f58c6 100644
--- a/libc/stdio/stdio_ext.cpp
+++ b/libc/stdio/stdio_ext.cpp
@@ -89,24 +89,3 @@
   _EXT(fp)->_caller_handles_locking = (type == FSETLOCKING_BYCALLER);
   return old_state;
 }
-
-void clearerr_unlocked(FILE* fp) {
-  return __sclearerr(fp);
-}
-
-int feof_unlocked(FILE* fp) {
-  return __sfeof(fp);
-}
-
-int ferror_unlocked(FILE* fp) {
-  return __sferror(fp);
-}
-
-int fileno_unlocked(FILE* fp) {
-  int fd = fp->_file;
-  if (fd == -1) {
-    errno = EBADF;
-    return -1;
-  }
-  return fd;
-}
diff --git a/libc/tools/check-symbols-glibc.py b/libc/tools/check-symbols-glibc.py
index c5dbdcf..631fd93 100755
--- a/libc/tools/check-symbols-glibc.py
+++ b/libc/tools/check-symbols-glibc.py
@@ -88,7 +88,7 @@
   'strlcpy',
   'sys_signame',
   'wcslcat',
-  'wcslcpy'
+  'wcslcpy',
 ])
 # Some symbols are part of the FORTIFY implementation.
 FORTIFY_stuff = set([
@@ -108,15 +108,16 @@
   '__strlen_chk',
   '__strncpy_chk2',
   '__strrchr_chk',
-  '__umask_chk'
+  '__umask_chk',
   '__write_chk',
 ])
-# Some symbols are used to implement public macros.
+# Some symbols are used to implement public functions/macros.
 macro_stuff = set([
   '__assert2',
   '__errno',
   '__fe_dfl_env',
   '__get_h_errno',
+  '__gnu_strerror_r',
   '__fpclassifyd',
   '__isfinite',
   '__isfinitef',
@@ -132,7 +133,8 @@
 linux_stuff = set([
   'getauxval',
   'gettid',
-  'tgkill'
+  'pthread_gettid_np',
+  'tgkill',
 ])
 # Some standard stuff isn't yet in the versions of glibc we're using.
 std_stuff = set([
@@ -168,6 +170,7 @@
 libresolv_stuff = set([
   '__res_send_setqhook',
   '__res_send_setrhook',
+  '_resolv_delete_cache_for_net',
   '_resolv_flush_cache_for_net',
   '_resolv_set_nameservers_for_net',
   'dn_expand',
@@ -178,6 +181,23 @@
   '_ctype_',
   '__libc_init',
 ])
+# POSIX has some stuff that's too stupid for words (a64l) or not actually
+# implemented in glibc unless you count always failing with ENOSYS as
+# being implemented (fattach).
+in_posix_and_glibc_but_actually_dead = set([
+  'a64l',
+  'fattach',
+  'fdetach',
+  'getmsg',
+  'getpmsg',
+  'isastream',
+  'l64a',
+  'putmsg',
+  'putpmsg',
+])
+
+posix = posix - in_posix_and_glibc_but_actually_dead
+glibc = glibc - in_posix_and_glibc_but_actually_dead
 
 if not only_unwanted:
   #print 'glibc:'
diff --git a/libc/tools/genlibgcc_compat.py b/libc/tools/genlibgcc_compat.py
deleted file mode 100755
index 628bf92..0000000
--- a/libc/tools/genlibgcc_compat.py
+++ /dev/null
@@ -1,136 +0,0 @@
-#!/usr/bin/python
-
-'''
-/* This file generates libgcc_compat.c file that contains dummy
- * references to libgcc.a functions to force the dynamic linker
- * to copy their definition into the final libc.so binary.
- *
- * They are required to ensure backwards binary compatibility with
- * libc.so provided by the platform and binaries built with the NDK or
- * different versions/configurations of toolchains.
- *
- * Now, for a more elaborate description of the issue:
- *
- * libgcc.a is a compiler-specific library containing various helper
- * functions used to implement certain operations that are not necessarily
- * supported by the target CPU. For example, integer division doesn't have a
- * corresponding CPU instruction on ARMv5, and is instead implemented in the
- * compiler-generated machine code as a call to an __idiv helper function.
- *
- * Normally, one has to place libgcc.a in the link command used to generate
- * target binaries (shared libraries and executables) after all objects and
- * static libraries, but before dependent shared libraries, i.e. something
- * like:
- *         gcc <options> -o libfoo.so  foo.a libgcc.a -lc -lm
- *
- * This ensures that any helper function needed by the code in foo.a is copied
- * into the final libfoo.so. However, doing so will link a bunch of other __cxa
- * functions from libgcc.a into each .so and executable, causing 4k+ increase
- * in every binary. Therefore the Android platform build system has been
- * using this instead:
- *
- *         gcc <options> -o libfoo.so foo.a -lc -lm libgcc.a
- *
- * The problem with this is that if one helper function needed by foo.a has
- * already been copied into libc.so or libm.so, then nothing will be copied
- * into libfoo.so. Instead, a symbol import definition will be added to it
- * so libfoo.so can directly call the one in libc.so at runtime.
- *
- * When refreshing toolchains for new versions or using different architecture
- * flags, the set of helper functions copied to libc.so may change, which
- * resulted in some native shared libraries generated with the NDK or prebuilts
- * from vendors to fail to load properly.
- *
- * The NDK has been fixed after 1.6_r1 to use the correct link command, so
- * any native shared library generated with it should now be safe from that
- * problem. On the other hand, existing shared libraries distributed with
- * applications that were generated with a previous version of the NDK
- * still need all 1.5/1.6 helper functions in libc.so and libm.so
- *
- * After 3.2, the toolchain was updated again, adding __aeabi_f2uiz to the
- * list of requirements. Technically, this is due to mis-linked NDK libraries
- * but it is easier to add a single function here than asking several app
- * developers to fix their build.
- *
- * The __aeabi_idiv function is added to the list since cortex-a15 supports
- * HW idiv instructions so the system libc.so doesn't pull in the reference to
- * __aeabi_idiv but legacy libraries built against cortex-a9 targets still need
- * it.
- *
- * Final note: some of the functions below should really be in libm.so to
- *             completely reflect the state of 1.5/1.6 system images. However,
- *             since libm.so depends on libc.so, it's easier to put all of
- *             these in libc.so instead, since the dynamic linker will always
- *             search in libc.so before libm.so for dependencies.
- */
-'''
-
-import os
-import sys
-import subprocess
-import tempfile
-import re
-
-libgcc_compat_header = "/* Generated by genlibgcc_compat.py */\n\n"
-
-class Generator:
-    def process(self):
-        android_build_top_path = os.environ["ANDROID_BUILD_TOP"]
-
-        print "* ANDROID_BUILD_TOP=" + android_build_top_path
-
-        # Check TARGET_ARCH
-        arch = subprocess.check_output(["CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core make --no-print-directory -f build/core/config.mk dumpvar-TARGET_ARCH"],
-                    cwd=android_build_top_path, shell=True).strip()
-
-        if arch != 'arm' and arch != 'x86':
-            sys.exit("Error: Invalid TARGET_ARCH='" + arch + "' expecting 'arm' or 'x86'")
-
-        build_path =  android_build_top_path + "/bionic/libc"
-        file_name = "libgcc_compat.c"
-        file_path = build_path + "/arch-" + arch + "/bionic/" + file_name
-
-        build_output_file_path = tempfile.mkstemp()[1]
-
-        p = subprocess.Popen(["ONE_SHOT_MAKEFILE=bionic/libc/Android.mk make -C " + android_build_top_path
-                    + " -f build/core/main.mk all_modules TARGET_LIBGCC= -j20 -B 2>&1 | tee " + build_output_file_path],
-                    cwd=build_path, shell=True)
-        p.wait()
-
-        print "* Build complete, logfile: " + build_output_file_path
-
-        symbol_set = set()
-        prog=re.compile("(?<=undefined reference to ')\w+")
-        fd = open(build_output_file_path, 'r')
-        for line in fd:
-            m = prog.search(line)
-            if m:
-                symbol_set.add(m.group(0))
-
-        fd.close()
-
-        symbol_list = sorted(symbol_set)
-
-        print "* Found " + repr(len(symbol_list)) + " referenced symbols: " + repr(symbol_list)
-
-        if 0 == len(symbol_list):
-            sys.exit("Error: symbol list is empty, please check the build log: " + build_output_file_path)
-
-        print "* Generating " + file_path
-        fres = open(file_path, 'w')
-        fres.write(libgcc_compat_header)
-
-        for sym_name in symbol_list:
-            fres.write("extern char "+sym_name+";\n")
-        fres.write("\n");
-
-        fres.write("void* __bionic_libgcc_compat_symbols[] = {\n");
-        for sym_name in symbol_list:
-            fres.write("    &"+sym_name+",\n")
-        fres.write("};\n");
-
-        fres.close()
-
-generator = Generator()
-generator.process()
-
diff --git a/libc/tools/gensyscalls.py b/libc/tools/gensyscalls.py
index 04ccf39..b4aa06c 100755
--- a/libc/tools/gensyscalls.py
+++ b/libc/tools/gensyscalls.py
@@ -555,41 +555,43 @@
             if syscall.has_key("x86_64"):
                 syscall["asm-x86_64"] = add_footer(64, x86_64_genstub(syscall), syscall)
 
-    # Scan a Linux kernel asm/unistd.h file containing __NR_* constants
+
+    # Scan Linux kernel asm/unistd.h files containing __NR_* constants
     # and write out equivalent SYS_* constants for glibc source compatibility.
-    def scan_linux_unistd_h(self, fp, path):
-        pattern = re.compile(r'^#define __NR_([a-z]\S+) .*')
-        syscalls = set() # MIPS defines everything three times; work around that.
-        for line in open(path):
-            m = re.search(pattern, line)
-            if m:
-                syscalls.add(m.group(1))
-        for syscall in sorted(syscalls):
-            fp.write("#define SYS_%s %s\n" % (syscall, make__NR_name(syscall)))
-
-
     def gen_glibc_syscalls_h(self):
-        # TODO: generate a separate file for each architecture, like glibc's bits/syscall.h.
-        glibc_syscalls_h_path = "include/sys/glibc-syscalls.h"
+        glibc_syscalls_h_path = "include/bits/glibc-syscalls.h"
         logging.info("generating " + glibc_syscalls_h_path)
         glibc_fp = create_file(glibc_syscalls_h_path)
         glibc_fp.write("/* %s */\n" % warning)
-        glibc_fp.write("#ifndef _BIONIC_GLIBC_SYSCALLS_H_\n")
-        glibc_fp.write("#define _BIONIC_GLIBC_SYSCALLS_H_\n")
+        glibc_fp.write("#ifndef _BIONIC_BITS_GLIBC_SYSCALLS_H_\n")
+        glibc_fp.write("#define _BIONIC_BITS_GLIBC_SYSCALLS_H_\n")
 
-        glibc_fp.write("#if defined(__aarch64__)\n")
-        self.scan_linux_unistd_h(glibc_fp, os.path.join(bionic_libc_root, "kernel/uapi/asm-generic/unistd.h"))
-        glibc_fp.write("#elif defined(__arm__)\n")
-        self.scan_linux_unistd_h(glibc_fp, os.path.join(bionic_libc_root, "kernel/uapi/asm-arm/asm/unistd.h"))
-        glibc_fp.write("#elif defined(__mips__)\n")
-        self.scan_linux_unistd_h(glibc_fp, os.path.join(bionic_libc_root, "kernel/uapi/asm-mips/asm/unistd.h"))
-        glibc_fp.write("#elif defined(__i386__)\n")
-        self.scan_linux_unistd_h(glibc_fp, os.path.join(bionic_libc_root, "kernel/uapi/asm-x86/asm/unistd_32.h"))
-        glibc_fp.write("#elif defined(__x86_64__)\n")
-        self.scan_linux_unistd_h(glibc_fp, os.path.join(bionic_libc_root, "kernel/uapi/asm-x86/asm/unistd_64.h"))
-        glibc_fp.write("#endif\n")
+        # Collect the set of all syscalls for all architectures.
+        syscalls = set()
+        pattern = re.compile(r'^\s*#\s*define\s*__NR_([a-z]\S+)')
+        for unistd_h in ["kernel/uapi/asm-generic/unistd.h",
+                         "kernel/uapi/asm-arm/asm/unistd.h",
+                         "kernel/uapi/asm-mips/asm/unistd.h",
+                         "kernel/uapi/asm-x86/asm/unistd_32.h",
+                         "kernel/uapi/asm-x86/asm/unistd_64.h"]:
+          for line in open(os.path.join(bionic_libc_root, unistd_h)):
+            m = re.search(pattern, line)
+            if m:
+              nr_name = m.group(1)
+              if 'reserved' not in nr_name and 'unused' not in nr_name:
+                syscalls.add(nr_name)
 
-        glibc_fp.write("#endif /* _BIONIC_GLIBC_SYSCALLS_H_ */\n")
+        # Write out a single file listing them all. Note that the input
+        # files include #if trickery, so even for a single architecture
+        # we don't know exactly which ones are available.
+        # https://code.google.com/p/android/issues/detail?id=215853
+        for syscall in sorted(syscalls):
+          nr_name = make__NR_name(syscall)
+          glibc_fp.write("#if defined(%s)\n" % nr_name)
+          glibc_fp.write("  #define SYS_%s %s\n" % (syscall, nr_name))
+          glibc_fp.write("#endif\n")
+
+        glibc_fp.write("#endif /* _BIONIC_BITS_GLIBC_SYSCALLS_H_ */\n")
         glibc_fp.close()
         self.other_files.append(glibc_syscalls_h_path)
 
diff --git a/libc/tools/genversion-scripts.py b/libc/tools/genversion-scripts.py
index e15c04e..53f4db4 100755
--- a/libc/tools/genversion-scripts.py
+++ b/libc/tools/genversion-scripts.py
@@ -7,6 +7,7 @@
 import os.path
 import shutil
 import tempfile
+import sys
 
 
 all_arches = ["arm", "arm64", "mips", "mips64", "x86", "x86_64"]
@@ -16,6 +17,9 @@
 libc_script = os.path.join(bionic_libc_root, "libc.map.txt")
 libm_script = os.path.join(bionic_libm_root, "libm.map.txt")
 libdl_script = os.path.join(bionic_libdl_root, "libdl.map.txt")
+libstdcxx_script = os.path.join(bionic_libc_root, "libstdc++.map.txt")
+
+script_name = os.path.basename(sys.argv[0])
 
 # TODO (dimity): generate architecture-specific version scripts as part of build
 
@@ -26,13 +30,22 @@
 
 bionic_libc_root = os.path.join(os.environ["ANDROID_BUILD_TOP"], "bionic/libc")
 
-warning = "Generated by genversionscripts.py. Do not edit."
+warning = "Generated by %s. Do not edit." % script_name
+
+
+def has_arch_tags(tags):
+  for arch in all_arches:
+    if arch in tags:
+      return True
+  if 'nobrillo' in tags:
+    return True
+  return False
 
 
 class VersionScriptGenerator(object):
 
   def run(self):
-    for script in [libc_script, libm_script, libdl_script]:
+    for script in [libc_script, libstdcxx_script, libm_script, libdl_script]:
       basename = os.path.basename(script)
       dirname = os.path.dirname(script)
       for arch in all_arches:
@@ -48,7 +61,7 @@
                 index = line.find("#")
                 if index != -1:
                   tags = line[index+1:].split()
-                  if arch not in tags:
+                  if arch not in tags and has_arch_tags(tags):
                     continue
                   if brillo and "nobrillo" in tags:
                     has_nobrillo = True
diff --git a/libc/tools/pylintrc b/libc/tools/pylintrc
new file mode 100644
index 0000000..2481b12
--- /dev/null
+++ b/libc/tools/pylintrc
@@ -0,0 +1,280 @@
+[MASTER]
+
+# Specify a configuration file.
+#rcfile=
+
+# Python code to execute, usually for sys.path manipulation such as
+# pygtk.require().
+#init-hook=
+
+# Profiled execution.
+profile=no
+
+# Add files or directories to the blacklist. They should be base names, not
+# paths.
+ignore=CVS
+
+# Pickle collected data for later comparisons.
+persistent=yes
+
+# List of plugins (as comma separated values of python modules names) to load,
+# usually to register additional checkers.
+load-plugins=
+
+
+[MESSAGES CONTROL]
+
+# Enable the message, report, category or checker with the given id(s). You can
+# either give multiple identifier separated by comma (,) or put this option
+# multiple time. See also the "--disable" option for examples.
+#enable=
+
+# Disable the message, report, category or checker with the given id(s). You
+# can either give multiple identifiers separated by comma (,) or put this
+# option multiple times (only on the command line, not in the configuration
+# file where it should appear only once).You can also use "--disable=all" to
+# disable everything first and then reenable specific checks. For example, if
+# you want to run only the similarities checker, you can use "--disable=all
+# --enable=similarities". If you want to run only the classes checker, but have
+# no Warning level messages displayed, use"--disable=all --enable=classes
+# --disable=W"
+disable=missing-docstring,invalid-name,no-self-use,fixme,design
+
+
+[REPORTS]
+
+# Set the output format. Available formats are text, parseable, colorized, msvs
+# (visual studio) and html. You can also give a reporter class, eg
+# mypackage.mymodule.MyReporterClass.
+output-format=text
+
+# Put messages in a separate file for each module / package specified on the
+# command line instead of printing them on stdout. Reports (if any) will be
+# written in a file name "pylint_global.[txt|html]".
+files-output=no
+
+# Tells whether to display a full report or only the messages
+reports=yes
+
+# Python expression which should return a note less than 10 (10 is the highest
+# note). You have access to the variables errors warning, statement which
+# respectively contain the number of errors / warnings messages and the total
+# number of statements analyzed. This is used by the global evaluation report
+# (RP0004).
+evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
+
+# Add a comment according to your evaluation note. This is used by the global
+# evaluation report (RP0004).
+comment=no
+
+# Template used to display messages. This is a python new-style format string
+# used to format the message information. See doc for all details
+#msg-template=
+
+
+[BASIC]
+
+# Required attributes for module, separated by a comma
+required-attributes=
+
+# List of builtins function names that should not be used, separated by a comma
+bad-functions=map,filter,apply,input
+
+# Regular expression which should only match correct module names
+module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
+
+# Regular expression which should only match correct module level names
+const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
+
+# Regular expression which should only match correct class names
+class-rgx=[A-Z_][a-zA-Z0-9]+$
+
+# Regular expression which should only match correct function names
+function-rgx=[a-z_][a-z0-9_]{2,30}$
+
+# Regular expression which should only match correct method names
+method-rgx=[a-z_][a-z0-9_]{2,30}$
+
+# Regular expression which should only match correct instance attribute names
+attr-rgx=[a-z_][a-z0-9_]{2,30}$
+
+# Regular expression which should only match correct argument names
+argument-rgx=[a-z_][a-z0-9_]{2,30}$
+
+# Regular expression which should only match correct variable names
+variable-rgx=[a-z_][a-z0-9_]{2,30}$
+
+# Regular expression which should only match correct attribute names in class
+# bodies
+class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
+
+# Regular expression which should only match correct list comprehension /
+# generator expression variable names
+inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
+
+# Good variable names which should always be accepted, separated by a comma
+good-names=i,j,k,ex,Run,_
+
+# Bad variable names which should always be refused, separated by a comma
+bad-names=foo,bar,baz,toto,tutu,tata
+
+# Regular expression which should only match function or class names that do
+# not require a docstring.
+no-docstring-rgx=__.*__
+
+# Minimum line length for functions/classes that require docstrings, shorter
+# ones are exempt.
+docstring-min-length=-1
+
+
+[TYPECHECK]
+
+# Tells whether missing members accessed in mixin class should be ignored. A
+# mixin class is detected if its name ends with "mixin" (case insensitive).
+ignore-mixin-members=yes
+
+# List of classes names for which member attributes should not be checked
+# (useful for classes with attributes dynamically set).
+ignored-classes=SQLObject
+
+# When zope mode is activated, add a predefined set of Zope acquired attributes
+# to generated-members.
+zope=no
+
+# List of members which are set dynamically and missed by pylint inference
+# system, and so shouldn't trigger E0201 when accessed. Python regular
+# expressions are accepted.
+generated-members=REQUEST,acl_users,aq_parent
+
+
+[MISCELLANEOUS]
+
+# List of note tags to take in consideration, separated by a comma.
+notes=FIXME,XXX,TODO
+
+
+[SIMILARITIES]
+
+# Minimum lines number of a similarity.
+min-similarity-lines=4
+
+# Ignore comments when computing similarities.
+ignore-comments=yes
+
+# Ignore docstrings when computing similarities.
+ignore-docstrings=yes
+
+# Ignore imports when computing similarities.
+ignore-imports=no
+
+
+[VARIABLES]
+
+# Tells whether we should check for unused import in __init__ files.
+init-import=no
+
+# A regular expression matching the beginning of the name of dummy variables
+# (i.e. not used).
+dummy-variables-rgx=_$|dummy
+
+# List of additional names supposed to be defined in builtins. Remember that
+# you should avoid to define new builtins when possible.
+additional-builtins=
+
+
+[FORMAT]
+
+# Maximum number of characters on a single line.
+max-line-length=100
+
+# Regexp for a line that is allowed to be longer than the limit.
+ignore-long-lines=^\s*(# )?<?https?://\S+>?$
+
+# Allow the body of an if to be on the same line as the test if there is no
+# else.
+single-line-if-stmt=no
+
+# List of optional constructs for which whitespace checking is disabled
+no-space-check=trailing-comma,dict-separator
+
+# Maximum number of lines in a module
+max-module-lines=1000
+
+# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
+# tab).
+indent-string='  '
+
+
+[IMPORTS]
+
+# Deprecated modules which should not be used, separated by a comma
+deprecated-modules=regsub,TERMIOS,Bastion,rexec
+
+# Create a graph of every (i.e. internal and external) dependencies in the
+# given file (report RP0402 must not be disabled)
+import-graph=
+
+# Create a graph of external dependencies in the given file (report RP0402 must
+# not be disabled)
+ext-import-graph=
+
+# Create a graph of internal dependencies in the given file (report RP0402 must
+# not be disabled)
+int-import-graph=
+
+
+[DESIGN]
+
+# Maximum number of arguments for function / method
+max-args=5
+
+# Argument names that match this expression will be ignored. Default to name
+# with leading underscore
+ignored-argument-names=_.*
+
+# Maximum number of locals for function / method body
+max-locals=15
+
+# Maximum number of return / yield for function / method body
+max-returns=6
+
+# Maximum number of branch for function / method body
+max-branches=12
+
+# Maximum number of statements in function / method body
+max-statements=50
+
+# Maximum number of parents for a class (see R0901).
+max-parents=7
+
+# Maximum number of attributes for a class (see R0902).
+max-attributes=7
+
+# Minimum number of public methods for a class (see R0903).
+min-public-methods=2
+
+# Maximum number of public methods for a class (see R0904).
+max-public-methods=20
+
+
+[CLASSES]
+
+# List of interface methods to ignore, separated by a comma. This is used for
+# instance to not check methods defines in Zope's Interface base class.
+ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by
+
+# List of method names used to declare (i.e. assign) instance attributes.
+defining-attr-methods=__init__,__new__,setUp
+
+# List of valid names for the first argument in a class method.
+valid-classmethod-first-arg=cls
+
+# List of valid names for the first argument in a metaclass class method.
+valid-metaclass-classmethod-first-arg=mcs
+
+
+[EXCEPTIONS]
+
+# Exceptions that will emit a warning when being caught. Defaults to
+# "Exception"
+overgeneral-exceptions=Exception
diff --git a/libc/tzcode/localtime.c b/libc/tzcode/localtime.c
index f370e87..0861015 100644
--- a/libc/tzcode/localtime.c
+++ b/libc/tzcode/localtime.c
@@ -178,11 +178,6 @@
 static char lcl_TZname[TZ_STRLEN_MAX + 1];
 static int  lcl_is_set;
 
-char * tzname[2] = {
-    (char *) wildabbr,
-    (char *) wildabbr
-};
-
 /*
 ** Section 4.12.3 of X3.159-1989 requires that
 **  Except for the strftime function, these functions [asctime,
@@ -193,10 +188,16 @@
 
 static struct tm	tm;
 
+#if !HAVE_POSIX_DECLS
+char *			tzname[2] = {
+	(char *) wildabbr,
+	(char *) wildabbr
+};
 #ifdef USG_COMPAT
 long			timezone;
 int			daylight;
-#endif /* defined USG_COMPAT */
+# endif
+#endif
 
 #ifdef ALTZONE
 long			altzone;
@@ -1317,11 +1318,11 @@
 {
 #if defined(__ANDROID__)
   // The TZ environment variable is meant to override the system-wide setting.
-  const char * name = getenv("TZ");
+  const char* name = getenv("TZ");
 
   // If that's not set, look at the "persist.sys.timezone" system property.
   if (name == NULL) {
-    static const prop_info *pi;
+    static const prop_info* pi;
 
     if (!pi) {
       pi = __system_property_find("persist.sys.timezone");
@@ -1336,12 +1337,21 @@
         s = serial;
       }
       if (ok) {
+        // POSIX and Java disagree about the sign in a timezone string. For POSIX, "GMT+3" means
+        // "3 hours west/behind", but for Java it means "3 hours east/ahead". Since (a) Java is
+        // the one that matches human expectations and (b) this system property is used directly
+        // by Java, we flip the sign here to translate from Java to POSIX. http://b/25463955.
+        if (buf[3] == '-') {
+          buf[3] = '+';
+        } else if (buf[3] == '+') {
+          buf[3] = '-';
+        }
         name = buf;
       }
     }
   }
 
-  // If that's not available (because you're running AOSP on a WiFi-only
+  // If the system property is also not available (because you're running AOSP on a WiFi-only
   // device, say), fall back to GMT.
   if (name == NULL) name = gmt;
 
diff --git a/libc/tzcode/private.h b/libc/tzcode/private.h
index 1c176e6..941e91b 100644
--- a/libc/tzcode/private.h
+++ b/libc/tzcode/private.h
@@ -22,6 +22,10 @@
 ** You can override these in your C compiler options, e.g. '-DHAVE_GETTEXT=1'.
 */
 
+#ifndef HAVE_DECL_ASCTIME_R
+#define HAVE_DECL_ASCTIME_R 1
+#endif
+
 #ifndef HAVE_GETTEXT
 #define HAVE_GETTEXT		0
 #endif /* !defined HAVE_GETTEXT */
@@ -34,6 +38,10 @@
 #define HAVE_LINK		1
 #endif /* !defined HAVE_LINK */
 
+#ifndef HAVE_POSIX_DECLS
+#define HAVE_POSIX_DECLS 1
+#endif
+
 #ifndef HAVE_STRDUP
 #define HAVE_STRDUP 1
 #endif
@@ -106,6 +114,9 @@
 #ifndef ENAMETOOLONG
 # define ENAMETOOLONG EINVAL
 #endif
+#ifndef ENOTSUP
+# define ENOTSUP EINVAL
+#endif
 #ifndef EOVERFLOW
 # define EOVERFLOW EINVAL
 #endif
@@ -379,25 +390,21 @@
 void tzset(void);
 #endif
 
-/*
-** Some time.h implementations don't declare asctime_r.
-** Others might define it as a macro.
-** Fix the former without affecting the latter.
-** Similarly for timezone, daylight, and altzone.
-*/
-
-#ifndef asctime_r
-extern char *	asctime_r(struct tm const *restrict, char *restrict);
+#if !HAVE_DECL_ASCTIME_R && !defined asctime_r
+extern char *asctime_r(struct tm const *restrict, char *restrict);
 #endif
 
-#ifdef USG_COMPAT
-# ifndef timezone
+#if !HAVE_POSIX_DECLS
+# ifdef USG_COMPAT
+#  ifndef timezone
 extern long timezone;
-# endif
-# ifndef daylight
+#  endif
+#  ifndef daylight
 extern int daylight;
+#  endif
 # endif
 #endif
+
 #if defined ALTZONE && !defined altzone
 extern long altzone;
 #endif
diff --git a/libc/tzcode/strftime.c b/libc/tzcode/strftime.c
index 4349cf6..b1e0d1c 100644
--- a/libc/tzcode/strftime.c
+++ b/libc/tzcode/strftime.c
@@ -1,29 +1,40 @@
+/* Convert a broken-down time stamp to a string.  */
+
+/* Copyright 1989 The Regents of the University of California.
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+   1. Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+   2. 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.
+   3. Neither the name of the University nor the names of its contributors
+      may be used to endorse or promote products derived from this software
+      without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.  */
+
 /*
-** Based on the UCB version with the copyright notice and sccsid
-** appearing below.
+** Based on the UCB version with the copyright notice appearing above.
 **
 ** This is ANSIish only when "multibyte character == plain character".
 */
 
 #include "private.h"
 
-/*
-** Copyright (c) 1989 The Regents of the University of California.
-** All rights reserved.
-**
-** Redistribution and use in source and binary forms are permitted
-** provided that the above copyright notice and this paragraph are
-** duplicated in all such forms and that any documentation,
-** advertising materials, and other materials related to such
-** distribution and use acknowledge that the software was developed
-** by the University of California, Berkeley. The name of the
-** University may not be used to endorse or promote products derived
-** from this software without specific prior written permission.
-** THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
-** IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
-** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-*/
-
 #include "tzfile.h"
 #include "fcntl.h"
 #include "locale.h"
@@ -108,9 +119,10 @@
 static char *   _fmt(const char *, const struct tm *, char *, const char *,
             int *);
 static char *   _yconv(int, int, bool, bool, char *, const char *, int);
-static char *   getformat(int, char *, char *, char *, char *);
 
+#if !HAVE_POSIX_DECLS
 extern char *   tzname[];
+#endif
 
 #ifndef YEAR_2000_NAME
 #define YEAR_2000_NAME  "CHECK_STRFTIME_FORMATS_FOR_TWO_DIGIT_YEARS"
@@ -121,7 +133,17 @@
 #define IN_THIS 2
 #define IN_ALL  3
 
-#define FORCE_LOWER_CASE 0x100
+#if HAVE_STRFTIME_L
+size_t
+strftime_l(char *s, size_t maxsize, char const *format, struct tm const *t,
+	   locale_t locale)
+{
+  /* Just call strftime, as only the C locale is supported.  */
+  return strftime(s, maxsize, format, t);
+}
+#endif
+
+#define FORCE_LOWER_CASE 0x100 /* Android extension. */
 
 size_t
 strftime(char *s, size_t maxsize, const char *format, const struct tm *t)
diff --git a/libc/upstream-freebsd/android/include/machine/endian.h b/libc/upstream-freebsd/android/include/machine/endian.h
new file mode 100644
index 0000000..2dc4d83
--- /dev/null
+++ b/libc/upstream-freebsd/android/include/machine/endian.h
@@ -0,0 +1 @@
+#include <endian.h>
diff --git a/libc/upstream-netbsd/android/include/netbsd-compat.h b/libc/upstream-netbsd/android/include/netbsd-compat.h
index bfd0401..45b974a 100644
--- a/libc/upstream-netbsd/android/include/netbsd-compat.h
+++ b/libc/upstream-netbsd/android/include/netbsd-compat.h
@@ -25,6 +25,17 @@
 // that they don't actually test or ship with this.
 #define _DIAGASSERT(e) /* nothing */
 
+/*
+ * The following macro is used to remove const cast-away warnings
+ * from gcc -Wcast-qual; it should be used with caution because it
+ * can hide valid errors; in particular most valid uses are in
+ * situations where the API requires it, not to cast away string
+ * constants. We don't use *intptr_t on purpose here and we are
+ * explicit about unsigned long so that we don't have additional
+ * dependencies.
+ */
+#define __UNCONST(a)    ((void *)(unsigned long)(const void *)(a))
+
 // TODO: we don't yet have thread-safe environment variables.
 #define __readlockenv() 0
 #define __unlockenv() 0
diff --git a/libc/upstream-netbsd/lib/libc/gen/ftw.c b/libc/upstream-netbsd/lib/libc/gen/ftw.c
deleted file mode 100644
index a7f6bbd..0000000
--- a/libc/upstream-netbsd/lib/libc/gen/ftw.c
+++ /dev/null
@@ -1,98 +0,0 @@
-/* $NetBSD: ftw.c,v 1.1 2005/12/30 23:07:32 agc Exp $ */
-
-/*	From OpenBSD: ftw.c,v 1.2 2003/07/21 21:15:32 millert Exp 	*/
-
-/*
- * Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * Sponsored in part by the Defense Advanced Research Projects
- * Agency (DARPA) and Air Force Research Laboratory, Air Force
- * Materiel Command, USAF, under agreement number F39502-99-1-0512.
- */
-#include <sys/cdefs.h>
-
-#ifndef lint
-__RCSID("$NetBSD: ftw.c,v 1.1 2005/12/30 23:07:32 agc Exp $");
-#endif
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <fts.h>
-#include <ftw.h>
-#include <limits.h>
-
-int
-ftw(const char *path, int (*fn)(const char *, const struct stat *, int),
-    int nfds)
-{
-	/* LINTED */
-	char * const paths[2] = { __UNCONST(path), NULL };
-	FTSENT *cur;
-	FTS *ftsp;
-	int fnflag, error, sverrno;
-
-	/* XXX - nfds is currently unused */
-	if (nfds < 1 || nfds > OPEN_MAX) {
-		errno = EINVAL;
-		return (-1);
-	}
-
-	ftsp = fts_open(paths, FTS_COMFOLLOW | FTS_NOCHDIR, NULL);
-	if (ftsp == NULL)
-		return (-1);
-	error = 0;
-	while ((cur = fts_read(ftsp)) != NULL) {
-		switch (cur->fts_info) {
-		case FTS_D:
-			fnflag = FTW_D;
-			break;
-		case FTS_DNR:
-			fnflag = FTW_DNR;
-			break;
-		case FTS_DP:
-			/* we only visit in preorder */
-			continue;
-		case FTS_F:
-		case FTS_DEFAULT:
-			fnflag = FTW_F;
-			break;
-		case FTS_NS:
-		case FTS_NSOK:
-		case FTS_SLNONE:
-			fnflag = FTW_NS;
-			break;
-		case FTS_SL:
-			fnflag = FTW_SL;
-			break;
-		case FTS_DC:
-			errno = ELOOP;
-			/* FALLTHROUGH */
-		default:
-			error = -1;
-			goto done;
-		}
-		error = fn(cur->fts_path, cur->fts_statp, fnflag);
-		if (error != 0)
-			break;
-	}
-done:
-	sverrno = errno;
-	if (fts_close(ftsp) != 0 && error == 0)
-		error = -1;
-	else
-		errno = sverrno;
-	return (error);
-}
diff --git a/libc/upstream-netbsd/lib/libc/gen/nftw.c b/libc/upstream-netbsd/lib/libc/gen/nftw.c
deleted file mode 100644
index 0e51342..0000000
--- a/libc/upstream-netbsd/lib/libc/gen/nftw.c
+++ /dev/null
@@ -1,114 +0,0 @@
-/* $NetBSD */
-
-/*	From OpenBSD: nftw.c,v 1.2 2003/07/21 21:15:32 millert Exp 	*/
-
-/*
- * Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * Sponsored in part by the Defense Advanced Research Projects
- * Agency (DARPA) and Air Force Research Laboratory, Air Force
- * Materiel Command, USAF, under agreement number F39502-99-1-0512.
- */
-
-#include <sys/cdefs.h>
-
-#ifndef lint
-__RCSID("$NetBSD: nftw.c,v 1.1 2005/12/30 23:07:32 agc Exp $");
-#endif
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <fts.h>
-#include <ftw.h>
-#include <limits.h>
-
-int
-nftw(const char *path, int (*fn)(const char *, const struct stat *, int,
-     struct FTW *), int nfds, int ftwflags)
-{
-	/* LINTED */
-	char * const paths[2] = { __UNCONST(path), NULL };
-	struct FTW f;
-	FTSENT *cur;
-	FTS *ftsp;
-	int ftsflags, fnflag, error, postorder, sverrno;
-
-	/* XXX - nfds is currently unused */
-	if (nfds < 1 || nfds > OPEN_MAX) {
-		errno = EINVAL;
-		return (-1);
-	}
-
-	ftsflags = FTS_COMFOLLOW;
-	if (!(ftwflags & FTW_CHDIR))
-		ftsflags |= FTS_NOCHDIR;
-	if (ftwflags & FTW_MOUNT)
-		ftsflags |= FTS_XDEV;
-	if (ftwflags & FTW_PHYS)
-		ftsflags |= FTS_PHYSICAL;
-	postorder = (ftwflags & FTW_DEPTH) != 0;
-	ftsp = fts_open(paths, ftsflags, NULL);
-	if (ftsp == NULL)
-		return (-1);
-	error = 0;
-	while ((cur = fts_read(ftsp)) != NULL) {
-		switch (cur->fts_info) {
-		case FTS_D:
-			if (postorder)
-				continue;
-			fnflag = FTW_D;
-			break;
-		case FTS_DNR:
-			fnflag = FTW_DNR;
-			break;
-		case FTS_DP:
-			if (!postorder)
-				continue;
-			fnflag = FTW_DP;
-			break;
-		case FTS_F:
-		case FTS_DEFAULT:
-			fnflag = FTW_F;
-			break;
-		case FTS_NS:
-		case FTS_NSOK:
-			fnflag = FTW_NS;
-			break;
-		case FTS_SL:
-			fnflag = FTW_SL;
-			break;
-		case FTS_SLNONE:
-			fnflag = FTW_SLN;
-			break;
-		case FTS_DC:
-			errno = ELOOP;
-			/* FALLTHROUGH */
-		default:
-			error = -1;
-			goto done;
-		}
-		f.base = cur->fts_pathlen - cur->fts_namelen;
-		f.level = cur->fts_level;
-		error = fn(cur->fts_path, cur->fts_statp, fnflag, &f);
-		if (error != 0)
-			break;
-	}
-done:
-	sverrno = errno;
-	(void) fts_close(ftsp);
-	errno = sverrno;
-	return (error);
-}
diff --git a/libc/upstream-openbsd/android/include/arc4random.h b/libc/upstream-openbsd/android/include/arc4random.h
index 96d9c9a..8d965e0 100644
--- a/libc/upstream-openbsd/android/include/arc4random.h
+++ b/libc/upstream-openbsd/android/include/arc4random.h
@@ -49,13 +49,7 @@
 	raise(SIGKILL);
 }
 
-static volatile sig_atomic_t _rs_forked;
-
-static inline void
-_rs_forkhandler(void)
-{
-	_rs_forked = 1;
-}
+volatile sig_atomic_t _rs_forked;
 
 static inline void
 _rs_forkdetect(void)
@@ -90,6 +84,5 @@
 	prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, *rsxp, sizeof(**rsxp),
 	    "arc4random _rsx structure");
 
-	_ARC4_ATFORK(_rs_forkhandler);
 	return (0);
 }
diff --git a/libc/upstream-openbsd/android/include/machine/ieee.h b/libc/upstream-openbsd/android/include/machine/ieee.h
new file mode 100644
index 0000000..dac332a
--- /dev/null
+++ b/libc/upstream-openbsd/android/include/machine/ieee.h
@@ -0,0 +1 @@
+#include "private/bionic_ieee.h"
diff --git a/libc/dns/net/base64.c b/libc/upstream-openbsd/lib/libc/net/base64.c
similarity index 82%
rename from libc/dns/net/base64.c
rename to libc/upstream-openbsd/lib/libc/net/base64.c
index 1886986..e90696d 100644
--- a/libc/dns/net/base64.c
+++ b/libc/upstream-openbsd/lib/libc/net/base64.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: base64.c,v 1.8 2002/11/11 01:15:17 thorpej Exp $	*/
+/*	$OpenBSD: base64.c,v 1.8 2015/01/16 16:48:51 deraadt Exp $	*/
 
 /*
  * Copyright (c) 1996 by Internet Software Consortium.
@@ -42,25 +42,14 @@
  * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
  */
 
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: base64.c,v 1.8 2002/11/11 01:15:17 thorpej Exp $");
-#endif /* LIBC_SCCS and not lint */
-
 #include <sys/types.h>
-#include <sys/param.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <arpa/nameser.h>
 
-#include <assert.h>
 #include <ctype.h>
-#ifdef ANDROID_CHANGES
-#include "resolv_private.h"
-#else
 #include <resolv.h>
-#endif
 #include <stdio.h>
 
 #include <stdlib.h>
@@ -118,9 +107,9 @@
    end of the data is performed using the '=' character.
 
    Since all base64 input is an integral number of octets, only the
-         -------------------------------------------------
+         -------------------------------------------------                       
    following cases can arise:
-
+   
        (1) the final quantum of encoding input is an integral
            multiple of 24 bits; here, the final unit of encoded
 	   output will be an integral multiple of 4 characters
@@ -141,12 +130,9 @@
 	size_t targsize;
 {
 	size_t datalength = 0;
-	u_char input[3] = { 0, 0, 0 };  /* make compiler happy */
+	u_char input[3];
 	u_char output[4];
-	size_t i;
-
-	assert(src != NULL);
-	assert(target != NULL);
+	int i;
 
 	while (2 < srclength) {
 		input[0] = *src++;
@@ -154,16 +140,10 @@
 		input[2] = *src++;
 		srclength -= 3;
 
-		output[0] = (u_int32_t)input[0] >> 2;
-		output[1] = ((u_int32_t)(input[0] & 0x03) << 4) +
-		    ((u_int32_t)input[1] >> 4);
-		output[2] = ((u_int32_t)(input[1] & 0x0f) << 2) +
-		    ((u_int32_t)input[2] >> 6);
+		output[0] = input[0] >> 2;
+		output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
+		output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
 		output[3] = input[2] & 0x3f;
-		assert(output[0] < 64);
-		assert(output[1] < 64);
-		assert(output[2] < 64);
-		assert(output[3] < 64);
 
 		if (datalength + 4 > targsize)
 			return (-1);
@@ -172,22 +152,17 @@
 		target[datalength++] = Base64[output[2]];
 		target[datalength++] = Base64[output[3]];
 	}
-
+    
 	/* Now we worry about padding. */
 	if (0 != srclength) {
 		/* Get what's left. */
 		input[0] = input[1] = input[2] = '\0';
 		for (i = 0; i < srclength; i++)
 			input[i] = *src++;
-
-		output[0] = (u_int32_t)input[0] >> 2;
-		output[1] = ((u_int32_t)(input[0] & 0x03) << 4) +
-		    ((u_int32_t)input[1] >> 4);
-		output[2] = ((u_int32_t)(input[1] & 0x0f) << 2) +
-		    ((u_int32_t)input[2] >> 6);
-		assert(output[0] < 64);
-		assert(output[1] < 64);
-		assert(output[2] < 64);
+	
+		output[0] = input[0] >> 2;
+		output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
+		output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
 
 		if (datalength + 4 > targsize)
 			return (-1);
@@ -217,17 +192,14 @@
 	u_char *target;
 	size_t targsize;
 {
-	size_t tarindex;
-	int state, ch;
+	int tarindex, state, ch;
+	u_char nextbyte;
 	char *pos;
 
-	assert(src != NULL);
-	assert(target != NULL);
-
 	state = 0;
 	tarindex = 0;
 
-	while ((ch = (u_char) *src++) != '\0') {
+	while ((ch = (unsigned char)*src++) != '\0') {
 		if (isspace(ch))	/* Skip whitespace anywhere. */
 			continue;
 
@@ -249,24 +221,28 @@
 			break;
 		case 1:
 			if (target) {
-				if (tarindex + 1 >= targsize)
+				if (tarindex >= targsize)
 					return (-1);
-				target[tarindex] |=
-				    (u_int32_t)(pos - Base64) >> 4;
-				target[tarindex+1]  = ((pos - Base64) & 0x0f)
-							<< 4 ;
+				target[tarindex]   |=  (pos - Base64) >> 4;
+				nextbyte = ((pos - Base64) & 0x0f) << 4;
+				if (tarindex + 1 < targsize)
+					target[tarindex+1] = nextbyte;
+				else if (nextbyte)
+					return (-1);
 			}
 			tarindex++;
 			state = 2;
 			break;
 		case 2:
 			if (target) {
-				if (tarindex + 1 >= targsize)
+				if (tarindex >= targsize)
 					return (-1);
-				target[tarindex] |=
-					(u_int32_t)(pos - Base64) >> 2;
-				target[tarindex+1] = ((pos - Base64) & 0x03)
-							<< 6;
+				target[tarindex]   |=  (pos - Base64) >> 2;
+				nextbyte = ((pos - Base64) & 0x03) << 6;
+				if (tarindex + 1 < targsize)
+					target[tarindex+1] = nextbyte;
+				else if (nextbyte)
+					return (-1);
 			}
 			tarindex++;
 			state = 3;
@@ -280,8 +256,6 @@
 			tarindex++;
 			state = 0;
 			break;
-		default:
-			abort();
 		}
 	}
 
@@ -290,8 +264,8 @@
 	 * on a byte boundary, and/or with erroneous trailing characters.
 	 */
 
-	if (ch == Pad64) {		/* We got a pad char. */
-		ch = *src++;		/* Skip it, get next. */
+	if (ch == Pad64) {			/* We got a pad char. */
+		ch = (unsigned char)*src++;	/* Skip it, get next. */
 		switch (state) {
 		case 0:		/* Invalid = in first position */
 		case 1:		/* Invalid = in second position */
@@ -299,13 +273,13 @@
 
 		case 2:		/* Valid, means one byte of info */
 			/* Skip any number of spaces. */
-			for (; ch != '\0'; ch = (u_char) *src++)
+			for (; ch != '\0'; ch = (unsigned char)*src++)
 				if (!isspace(ch))
 					break;
 			/* Make sure there is another trailing = sign. */
 			if (ch != Pad64)
 				return (-1);
-			ch = *src++;		/* Skip the = */
+			ch = (unsigned char)*src++;		/* Skip the = */
 			/* Fall through to "single trailing =" case. */
 			/* FALLTHROUGH */
 
@@ -314,7 +288,7 @@
 			 * We know this char is an =.  Is there anything but
 			 * whitespace after it?
 			 */
-			for (; ch != '\0'; ch = (u_char) *src++)
+			for (; ch != '\0'; ch = (unsigned char)*src++)
 				if (!isspace(ch))
 					return (-1);
 
@@ -324,7 +298,8 @@
 			 * zeros.  If we don't check them, they become a
 			 * subliminal channel.
 			 */
-			if (target && target[tarindex] != 0)
+			if (target && tarindex < targsize &&
+			    target[tarindex] != 0)
 				return (-1);
 		}
 	} else {
diff --git a/libc/upstream-openbsd/lib/libc/stdio/asprintf.c b/libc/upstream-openbsd/lib/libc/stdio/asprintf.c
deleted file mode 100644
index 4823677..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/asprintf.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/*	$OpenBSD: asprintf.c,v 1.22 2015/12/28 22:08:18 mmcc Exp $	*/
-
-/*
- * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <stdarg.h>
-#include "local.h"
-
-int
-asprintf(char **str, const char *fmt, ...)
-{
-	int ret;
-	va_list ap;
-	FILE f;
-	struct __sfileext fext;
-	unsigned char *_base;
-
-	_FILEEXT_SETUP(&f, &fext);
-	f._file = -1;
-	f._flags = __SWR | __SSTR | __SALC;
-	f._bf._base = f._p = malloc(128);
-	if (f._bf._base == NULL)
-		goto err;
-	f._bf._size = f._w = 127;		/* Leave room for the NUL */
-	va_start(ap, fmt);
-	ret = __vfprintf(&f, fmt, ap);
-	va_end(ap);
-	if (ret == -1)
-		goto err;
-	*f._p = '\0';
-	_base = realloc(f._bf._base, ret + 1);
-	if (_base == NULL)
-		goto err;
-	*str = (char *)_base;
-	return (ret);
-
-err:
-	free(f._bf._base);
-	f._bf._base = NULL;
-	*str = NULL;
-	errno = ENOMEM;
-	return (-1);
-}
-DEF_WEAK(asprintf);
diff --git a/libc/upstream-openbsd/lib/libc/stdio/clrerr.c b/libc/upstream-openbsd/lib/libc/stdio/clrerr.c
deleted file mode 100644
index ac08c72..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/clrerr.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*	$OpenBSD: clrerr.c,v 1.9 2009/11/09 00:18:27 kurt Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <stdio.h>
-#include "local.h"
-#undef	clearerr
-
-void
-clearerr(FILE *fp)
-{
-	FLOCKFILE(fp);
-	__sclearerr(fp);
-	FUNLOCKFILE(fp);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/dprintf.c b/libc/upstream-openbsd/lib/libc/stdio/dprintf.c
deleted file mode 100644
index dbf7d34..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/dprintf.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/*	$OpenBSD: dprintf.c,v 1.1 2013/01/30 00:08:13 brad Exp $	*/
-/*	$FreeBSD: src/lib/libc/stdio/dprintf.c,v 1.2 2012/11/17 01:49:39 svnexp Exp $	*/
-
-/*-
- * Copyright (c) 2009 David Schultz <das@FreeBSD.org>
- * All rights reserved.
- *
- * Copyright (c) 2011 The FreeBSD Foundation
- * All rights reserved.
- * Portions of this software were developed by David Chisnall
- * under sponsorship from the FreeBSD Foundation.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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 AUTHOR 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 AUTHOR 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 <stdio.h>
-#include <stdarg.h>
-
-int
-dprintf(int fd, const char * __restrict fmt, ...)
-{
-	va_list ap;
-	int ret;
-
-	va_start(ap, fmt);
-	ret = vdprintf(fd, fmt, ap);
-	va_end(ap);
-	return ret;
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/feof.c b/libc/upstream-openbsd/lib/libc/stdio/feof.c
deleted file mode 100644
index 0036bab..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/feof.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*	$OpenBSD: feof.c,v 1.8 2009/11/09 00:18:27 kurt Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <stdio.h>
-#include "local.h"
-
-/*
- * A subroutine version of the macro feof.
- */
-#undef feof
-
-int
-feof(FILE *fp)
-{
-	int	ret;
-
-	FLOCKFILE(fp);
-	ret = __sfeof(fp);
-	FUNLOCKFILE(fp);
-	return (ret);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/ferror.c b/libc/upstream-openbsd/lib/libc/stdio/ferror.c
deleted file mode 100644
index 00b9c8b..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/ferror.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*	$OpenBSD: ferror.c,v 1.8 2009/11/09 00:18:27 kurt Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <stdio.h>
-#include "local.h"
-
-/*
- * A subroutine version of the macro ferror.
- */
-#undef ferror
-
-int
-ferror(FILE *fp)
-{
-	int     ret;
-
-	FLOCKFILE(fp);
-	ret = __sferror(fp);
-	FUNLOCKFILE(fp);
-	return (ret);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fgetc.c b/libc/upstream-openbsd/lib/libc/stdio/fgetc.c
deleted file mode 100644
index c5d7dde..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/fgetc.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/*	$OpenBSD: fgetc.c,v 1.8 2009/11/09 00:18:27 kurt Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <stdio.h>
-
-int
-fgetc(FILE *fp)
-{
-	return (getc(fp));
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fprintf.c b/libc/upstream-openbsd/lib/libc/stdio/fprintf.c
deleted file mode 100644
index a391142..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/fprintf.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/*	$OpenBSD: fprintf.c,v 1.7 2011/05/30 18:48:33 martynas Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <stdio.h>
-#include <stdarg.h>
-
-/* PRINTFLIKE2 */
-int
-fprintf(FILE *fp, const char *fmt, ...)
-{
-	int ret;
-	va_list ap;
-
-	va_start(ap, fmt);
-	ret = vfprintf(fp, fmt, ap);
-	va_end(ap);
-	return (ret);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fputc.c b/libc/upstream-openbsd/lib/libc/stdio/fputc.c
deleted file mode 100644
index 98e3960..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/fputc.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/*	$OpenBSD: fputc.c,v 1.10 2009/11/09 00:18:27 kurt Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <stdio.h>
-#include <errno.h>
-
-int
-fputc(int c, FILE *fp)
-{
-	return (putc(c, fp));
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fscanf.c b/libc/upstream-openbsd/lib/libc/stdio/fscanf.c
deleted file mode 100644
index 5fd10d4..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/fscanf.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/*	$OpenBSD: fscanf.c,v 1.10 2011/05/30 18:48:33 martynas Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <stdio.h>
-#include <stdarg.h>
-
-/* SCANFLIKE2 */
-int
-fscanf(FILE *fp, const char *fmt, ...)
-{
-	int ret;
-	va_list ap;
-
-	va_start(ap, fmt);
-	ret = vfscanf(fp, fmt, ap);
-	va_end(ap);
-	return (ret);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fwprintf.c b/libc/upstream-openbsd/lib/libc/stdio/fwprintf.c
deleted file mode 100644
index 4474e8b..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/fwprintf.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/*	$OpenBSD: fwprintf.c,v 1.3 2011/04/28 17:38:46 stsp Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <stdio.h>
-#include <stdarg.h>
-#include <wchar.h>
-
-int
-fwprintf(FILE * __restrict fp, const wchar_t * __restrict fmt, ...)
-{
-	int ret;
-	va_list ap;
-
-	va_start(ap, fmt);
-	ret = vfwprintf(fp, fmt, ap);
-	va_end(ap);
-	return (ret);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/fwscanf.c b/libc/upstream-openbsd/lib/libc/stdio/fwscanf.c
deleted file mode 100644
index b716cbf..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/fwscanf.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/* $OpenBSD: fwscanf.c,v 1.2 2012/12/05 23:20:01 deraadt Exp $ */
-
-/*-
- * Copyright (c) 2002 Tim J. Robbins
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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 AUTHOR 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 AUTHOR 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 <stdarg.h>
-#include <stdio.h>
-#include <wchar.h>
-
-int
-fwscanf(FILE * __restrict fp, const wchar_t * __restrict fmt, ...)
-{
-	va_list ap;
-	int r;
-
-	va_start(ap, fmt);
-	r = vfwscanf(fp, fmt, ap);
-	va_end(ap);
-
-	return (r);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/getc.c b/libc/upstream-openbsd/lib/libc/stdio/getc.c
deleted file mode 100644
index 6879cbb..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/getc.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/*	$OpenBSD: getc.c,v 1.9 2009/11/09 00:18:27 kurt Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <stdio.h>
-#include "local.h"
-
-/*
- * A subroutine version of the macro getc_unlocked.
- */
-#undef getc_unlocked
-
-int
-getc_unlocked(FILE *fp)
-{
-	return (__sgetc(fp));
-}
-
-/*
- * A subroutine version of the macro getc.
- */
-#undef getc
-
-int
-getc(FILE *fp)
-{
-	int c;
-
-	FLOCKFILE(fp);
-	c = __sgetc(fp);
-	FUNLOCKFILE(fp);
-	return (c);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/getchar.c b/libc/upstream-openbsd/lib/libc/stdio/getchar.c
deleted file mode 100644
index 550817d..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/getchar.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*	$OpenBSD: getchar.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <stdio.h>
-
-/*
- * A subroutine version of the macro getchar_unlocked.
- */
-#undef getchar_unlocked
-
-int
-getchar_unlocked(void)
-{
-	return (getc_unlocked(stdin));
-}
-
-
-/*
- * A subroutine version of the macro getchar.
- */
-
-#undef getchar
-
-int
-getchar(void)
-{
-	return (getc(stdin));
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/getline.c b/libc/upstream-openbsd/lib/libc/stdio/getline.c
deleted file mode 100644
index 55ad396..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/getline.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/*	$OpenBSD: getline.c,v 1.1 2012/03/21 23:44:35 fgsch Exp $	*/
-/* $NetBSD: getline.c,v 1.3 2009/12/02 08:46:33 roy Exp $ */
-
-/*
- * Copyright (c) 2009 The NetBSD Foundation, Inc.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Roy Marples.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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 AUTHOR ``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 AUTHOR 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 <stdio.h>
-
-ssize_t
-getline(char **__restrict buf, size_t *__restrict buflen, FILE *__restrict fp)
-{
-	return getdelim(buf, buflen, '\n', fp);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/getwc.c b/libc/upstream-openbsd/lib/libc/stdio/getwc.c
deleted file mode 100644
index e9bbb7c..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/getwc.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*	$OpenBSD: getwc.c,v 1.1 2005/06/17 20:40:32 espie Exp $	*/
-/* $NetBSD: getwc.c,v 1.2 2003/01/18 11:29:55 thorpej Exp $ */
-
-/*-
- * Copyright (c)2001 Citrus 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:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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 AUTHOR 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 AUTHOR 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.
- *
- * $Citrus$
- */
-
-#include <stdio.h>
-#include <wchar.h>
-
-/*
- * A subroutine version of the macro getwc.
- */
-#undef getwc
-
-wint_t
-getwc(FILE *fp)
-{
-
-	return fgetwc(fp);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/getwchar.c b/libc/upstream-openbsd/lib/libc/stdio/getwchar.c
deleted file mode 100644
index 2a112ed..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/getwchar.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*	$OpenBSD: getwchar.c,v 1.1 2005/06/17 20:40:32 espie Exp $	*/
-/* $NetBSD: getwchar.c,v 1.2 2003/01/18 11:29:55 thorpej Exp $ */
-
-/*-
- * Copyright (c)2001 Citrus 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:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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 AUTHOR 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 AUTHOR 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.
- *
- * $Citrus$
- */
-
-#include <stdio.h>
-#include <wchar.h>
-
-/*
- * A subroutine version of the macro getwchar.
- */
-#undef getwchar
-
-wint_t
-getwchar()
-{
-
-	return fgetwc(stdin);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/printf.c b/libc/upstream-openbsd/lib/libc/stdio/printf.c
deleted file mode 100644
index 09bb3d7..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/printf.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/*	$OpenBSD: printf.c,v 1.8 2011/05/30 18:48:33 martynas Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <stdio.h>
-#include <stdarg.h>
-
-/* PRINTFLIKE1 */
-int
-printf(const char *fmt, ...)
-{
-	int ret;
-	va_list ap;
-
-	va_start(ap, fmt);
-	ret = vfprintf(stdout, fmt, ap);
-	va_end(ap);
-	return (ret);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/putc.c b/libc/upstream-openbsd/lib/libc/stdio/putc.c
deleted file mode 100644
index 762fecb..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/putc.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/*	$OpenBSD: putc.c,v 1.12 2009/11/21 10:11:54 guenther Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <stdio.h>
-#include <errno.h>
-#include "local.h"
-
-/*
- * A subroutine version of the macro putc_unlocked.
- */
-#undef putc_unlocked
-
-int
-putc_unlocked(int c, FILE *fp)
-{
-	if (cantwrite(fp)) {
-		errno = EBADF;
-		return (EOF);
-	}
-	_SET_ORIENTATION(fp, -1);
-	return (__sputc(c, fp));
-}
-
-/*
- * A subroutine version of the macro putc.
- */
-#undef putc
-
-int
-putc(int c, FILE *fp)
-{
-	int ret;
-
-	FLOCKFILE(fp);
-	ret = putc_unlocked(c, fp);
-	FUNLOCKFILE(fp);
-	return (ret);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/putchar.c b/libc/upstream-openbsd/lib/libc/stdio/putchar.c
deleted file mode 100644
index 233cdfd..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/putchar.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*	$OpenBSD: putchar.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <stdio.h>
-
-#undef putchar_unlocked
-/*
- * A subrouting version of the macro putchar_unlocked
- */
-int
-putchar_unlocked(int c)
-{
-	FILE *so = stdout;
-
-	return (putc_unlocked(c,so));
-}
-
-#undef putchar
-
-/*
- * A subroutine version of the macro putchar
- */
-int
-putchar(int c)
-{
-	FILE *so = stdout;
-
-	return (putc(c, so));
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/putw.c b/libc/upstream-openbsd/lib/libc/stdio/putw.c
deleted file mode 100644
index 47941a4..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/putw.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*	$OpenBSD: putw.c,v 1.10 2009/11/21 09:53:44 guenther Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <stdio.h>
-#include "local.h"
-#include "fvwrite.h"
-
-int
-putw(int w, FILE *fp)
-{
-	struct __suio uio;
-	struct __siov iov;
-	int ret;
-
-	iov.iov_base = &w;
-	iov.iov_len = uio.uio_resid = sizeof(w);
-	uio.uio_iov = &iov;
-	uio.uio_iovcnt = 1;
-	FLOCKFILE(fp);
-	_SET_ORIENTATION(fp, -1);
-	ret = __sfvwrite(fp, &uio);
-	FUNLOCKFILE(fp);
-	return (ret);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/putwc.c b/libc/upstream-openbsd/lib/libc/stdio/putwc.c
deleted file mode 100644
index 8e2ff2d..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/putwc.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*	$OpenBSD: putwc.c,v 1.1 2005/06/17 20:40:32 espie Exp $	*/
-/* $NetBSD: putwc.c,v 1.3 2003/01/18 11:29:56 thorpej Exp $ */
-
-/*-
- * Copyright (c)2001 Citrus 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:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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 AUTHOR 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 AUTHOR 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.
- *
- * $Citrus$
- */
-
-#include <stdio.h>
-#include <wchar.h>
-
-/*
- * A subroutine version of the macro putwc.
- */
-#undef putwc
-
-wint_t
-putwc(wchar_t wc, FILE *fp)
-{
-
-	return fputwc(wc, fp);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/putwchar.c b/libc/upstream-openbsd/lib/libc/stdio/putwchar.c
deleted file mode 100644
index 940ec05..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/putwchar.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*	$OpenBSD: putwchar.c,v 1.1 2005/06/17 20:40:32 espie Exp $	*/
-/* $NetBSD: putwchar.c,v 1.3 2003/01/18 11:29:56 thorpej Exp $ */
-
-/*-
- * Copyright (c)2001 Citrus 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:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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 AUTHOR 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 AUTHOR 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.
- *
- * $Citrus$
- */
-
-#include <stdio.h>
-#include <wchar.h>
-
-/*
- * A subroutine version of the macro putwchar.
- */
-#undef putwchar
-
-wint_t
-putwchar(wchar_t wc)
-{
-
-	return fputwc(wc, stdout);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/remove.c b/libc/upstream-openbsd/lib/libc/stdio/remove.c
deleted file mode 100644
index d09d76f..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/remove.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*	$OpenBSD: remove.c,v 1.7 2005/08/08 08:05:36 espie Exp $	*/
-
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <stdio.h>
-#include <unistd.h>
-#include <sys/stat.h>
-
-int
-remove(const char *file)
-{
-	struct stat st;
-
-	if (lstat(file, &st) < 0)
-		return (-1);
-	if (S_ISDIR(st.st_mode))
-		return (rmdir(file));
-	return (unlink(file));
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/rewind.c b/libc/upstream-openbsd/lib/libc/stdio/rewind.c
deleted file mode 100644
index 28119b6..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/rewind.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/*	$OpenBSD: rewind.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <errno.h>
-#include <stdio.h>
-
-void
-rewind(FILE *fp)
-{
-	(void) fseek(fp, 0L, SEEK_SET);
-	clearerr(fp);
-	errno = 0;      /* not required, but seems reasonable */
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/scanf.c b/libc/upstream-openbsd/lib/libc/stdio/scanf.c
deleted file mode 100644
index 90cf12a..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/scanf.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/*	$OpenBSD: scanf.c,v 1.10 2011/05/30 18:48:33 martynas Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <stdio.h>
-#include <stdarg.h>
-
-/* SCANFLIKE1 */
-int
-scanf(const char *fmt, ...)
-{
-	int ret;
-	va_list ap;
-
-	va_start(ap, fmt);
-	ret = vfscanf(stdin, fmt, ap);
-	va_end(ap);
-	return (ret);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/setbuf.c b/libc/upstream-openbsd/lib/libc/stdio/setbuf.c
deleted file mode 100644
index 883b895..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/setbuf.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/*	$OpenBSD: setbuf.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <stdio.h>
-#include "local.h"
-
-void
-setbuf(FILE *fp, char *buf)
-{
-	(void) setvbuf(fp, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/setbuffer.c b/libc/upstream-openbsd/lib/libc/stdio/setbuffer.c
deleted file mode 100644
index 8725ff7..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/setbuffer.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*	$OpenBSD: setbuffer.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <stdio.h>
-
-void
-setbuffer(FILE *fp, char *buf, int size)
-{
-
-	(void)setvbuf(fp, buf, buf ? _IOFBF : _IONBF, size);
-}
-
-/*
- * set line buffering
- */
-int
-setlinebuf(FILE *fp)
-{
-
-	return (setvbuf(fp, (char *)NULL, _IOLBF, (size_t)0));
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/sscanf.c b/libc/upstream-openbsd/lib/libc/stdio/sscanf.c
deleted file mode 100644
index e371ca6..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/sscanf.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/*	$OpenBSD: sscanf.c,v 1.14 2011/11/08 18:30:42 guenther Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-#include "local.h"
-
-/* ARGSUSED */
-static int
-eofread(void *cookie, char *buf, int len)
-{
-
-	return (0);
-}
-
-/* SCANFLIKE2 */
-int
-sscanf(const char *str, const char *fmt, ...)
-{
-	int ret;
-	va_list ap;
-	FILE f;
-	struct __sfileext fext;
-
-	_FILEEXT_SETUP(&f, &fext);
-	f._flags = __SRD;
-	f._bf._base = f._p = (unsigned char *)str;
-	f._bf._size = f._r = strlen(str);
-	f._read = eofread;
-	f._lb._base = NULL;
-	va_start(ap, fmt);
-	ret = __svfscanf(&f, fmt, ap);
-	va_end(ap);
-	return (ret);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/swprintf.c b/libc/upstream-openbsd/lib/libc/stdio/swprintf.c
deleted file mode 100644
index 8928aea..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/swprintf.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*	$OpenBSD: swprintf.c,v 1.5 2012/12/05 23:20:01 deraadt Exp $ */
-/*	$NetBSD: swprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp $	*/
-
-/*-
- * Copyright (c) 2002 Tim J. Robbins
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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 AUTHOR 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 AUTHOR 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 <stdarg.h>
-#include <stdio.h>
-#include <wchar.h>
-
-int
-swprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt, ...)
-{
-	int ret;
-	va_list ap;
-
-	va_start(ap, fmt);
-	ret = vswprintf(s, n, fmt, ap);
-	va_end(ap);
-
-	return (ret);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/swscanf.c b/libc/upstream-openbsd/lib/libc/stdio/swscanf.c
deleted file mode 100644
index a85e9ee..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/swscanf.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/* $OpenBSD: swscanf.c,v 1.2 2012/12/05 23:20:01 deraadt Exp $ */
-
-/*-
- * Copyright (c) 2002 Tim J. Robbins
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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 AUTHOR 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 AUTHOR 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 <stdarg.h>
-#include <stdio.h>
-#include <wchar.h>
-
-int
-swscanf(const wchar_t * __restrict str, const wchar_t * __restrict fmt, ...)
-{
-	va_list ap;
-	int r;
-
-	va_start(ap, fmt);
-	r = vswscanf(str, fmt, ap);
-	va_end(ap);
-
-	return (r);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/vprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vprintf.c
deleted file mode 100644
index fcc622c..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/vprintf.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/*	$OpenBSD: vprintf.c,v 1.8 2006/01/06 18:53:04 millert Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <stdio.h>
-
-int
-vprintf(const char *fmt, __va_list ap)
-{
-	return (vfprintf(stdout, fmt, ap));
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/vscanf.c b/libc/upstream-openbsd/lib/libc/stdio/vscanf.c
deleted file mode 100644
index 228498e..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/vscanf.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/*	$OpenBSD: vscanf.c,v 1.8 2006/01/06 18:53:04 millert Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Donn Seeley at UUNET Technologies, Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <stdio.h>
-
-int
-vscanf(const char *fmt, __va_list ap)
-{
-
-	return (vfscanf(stdin, fmt, ap));
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/vsprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vsprintf.c
deleted file mode 100644
index 308ff37..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/vsprintf.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*	$OpenBSD: vsprintf.c,v 1.16 2009/11/09 00:18:28 kurt Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <stdio.h>
-#include <string.h>
-#include <limits.h>
-#include "local.h"
-
-#if defined(APIWARN)
-__warn_references(vsprintf,
-    "warning: vsprintf() is often misused, please use vsnprintf()");
-#endif
-
-int
-vsprintf(char *str, const char *fmt, __va_list ap)
-{
-	int ret;
-	FILE f;
-	struct __sfileext fext;
-
-	_FILEEXT_SETUP(&f, &fext);
-	f._file = -1;
-	f._flags = __SWR | __SSTR;
-	f._bf._base = f._p = (unsigned char *)str;
-	f._bf._size = f._w = INT_MAX;
-	ret = __vfprintf(&f, fmt, ap);
-	*f._p = '\0';
-	return (ret);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/vwprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vwprintf.c
deleted file mode 100644
index 49569c1..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/vwprintf.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/*	$OpenBSD: vwprintf.c,v 1.3 2011/04/28 17:38:46 stsp Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <stdarg.h>
-#include <stdio.h>
-#include <wchar.h>
-
-int
-vwprintf(const wchar_t * __restrict fmt, __va_list ap)
-{
-	return (vfwprintf(stdout, fmt, ap));
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/vwscanf.c b/libc/upstream-openbsd/lib/libc/stdio/vwscanf.c
deleted file mode 100644
index 7039f02..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/vwscanf.c
+++ /dev/null
@@ -1,38 +0,0 @@
-/* $OpenBSD: vwscanf.c,v 1.2 2012/12/05 23:20:01 deraadt Exp $ */
-
-/*-
- * Copyright (c) 2002 Tim J. Robbins
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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 AUTHOR 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 AUTHOR 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 <stdarg.h>
-#include <stdio.h>
-#include <wchar.h>
-
-int
-vwscanf(const wchar_t * __restrict fmt, __va_list ap)
-{
-
-	return (vfwscanf(stdin, fmt, ap));
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/wprintf.c b/libc/upstream-openbsd/lib/libc/stdio/wprintf.c
deleted file mode 100644
index 9f7abb6..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/wprintf.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/*	$OpenBSD: wprintf.c,v 1.3 2011/04/28 17:38:46 stsp Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <stdio.h>
-#include <stdarg.h>
-#include <wchar.h>
-
-int
-wprintf(const wchar_t * __restrict fmt, ...)
-{
-	int ret;
-	va_list ap;
-
-	va_start(ap, fmt);
-	ret = vfwprintf(stdout, fmt, ap);
-	va_end(ap);
-	return (ret);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdio/wscanf.c b/libc/upstream-openbsd/lib/libc/stdio/wscanf.c
deleted file mode 100644
index 06c0829..0000000
--- a/libc/upstream-openbsd/lib/libc/stdio/wscanf.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/* $OpenBSD: wscanf.c,v 1.2 2012/12/05 23:20:01 deraadt Exp $ */
-
-/*-
- * Copyright (c) 2002 Tim J. Robbins
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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 AUTHOR 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 AUTHOR 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 <stdarg.h>
-#include <stdio.h>
-#include <wchar.h>
-
-int
-wscanf(const wchar_t * __restrict fmt, ...)
-{
-	va_list ap;
-	int r;
-
-	va_start(ap, fmt);
-	r = vfwscanf(stdin, fmt, ap);
-	va_end(ap);
-
-	return (r);
-}
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/getsubopt.c b/libc/upstream-openbsd/lib/libc/stdlib/getsubopt.c
new file mode 100644
index 0000000..735c85b
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdlib/getsubopt.c
@@ -0,0 +1,92 @@
+/*	$OpenBSD: getsubopt.c,v 1.4 2005/08/08 08:05:36 espie Exp $	*/
+
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+/*
+ * The SVID interface to getsubopt provides no way of figuring out which
+ * part of the suboptions list wasn't matched.  This makes error messages
+ * tricky...  The extern variable suboptarg is a pointer to the token
+ * which didn't match.
+ */
+char *suboptarg;
+
+int
+getsubopt(char **optionp, char * const *tokens, char **valuep)
+{
+	int cnt;
+	char *p;
+
+	suboptarg = *valuep = NULL;
+
+	if (!optionp || !*optionp)
+		return(-1);
+
+	/* skip leading white-space, commas */
+	for (p = *optionp; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p);
+
+	if (!*p) {
+		*optionp = p;
+		return(-1);
+	}
+
+	/* save the start of the token, and skip the rest of the token. */
+	for (suboptarg = p;
+	    *++p && *p != ',' && *p != '=' && *p != ' ' && *p != '\t';);
+
+	if (*p) {
+		/*
+		 * If there's an equals sign, set the value pointer, and
+		 * skip over the value part of the token.  Terminate the
+		 * token.
+		 */
+		if (*p == '=') {
+			*p = '\0';
+			for (*valuep = ++p;
+			    *p && *p != ',' && *p != ' ' && *p != '\t'; ++p);
+			if (*p) 
+				*p++ = '\0';
+		} else
+			*p++ = '\0';
+		/* Skip any whitespace or commas after this token. */
+		for (; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p);
+	}
+
+	/* set optionp for next round. */
+	*optionp = p;
+
+	for (cnt = 0; *tokens; ++tokens, ++cnt)
+		if (!strcmp(suboptarg, *tokens))
+			return(cnt);
+	return(-1);
+}
diff --git a/libdl/Android.bp b/libdl/Android.bp
index 2aa9b68..84561d9 100644
--- a/libdl/Android.bp
+++ b/libdl/Android.bp
@@ -56,5 +56,7 @@
     allow_undefined_symbols: true,
     system_shared_libs: [],
 
-    sanitize: ["never"],
+    sanitize: {
+        never: true,
+    },
 }
diff --git a/libdl/Android.mk b/libdl/Android.mk
deleted file mode 100644
index 1ea5dc7..0000000
--- a/libdl/Android.mk
+++ /dev/null
@@ -1,66 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-
-#
-# libdl
-#
-
-include $(CLEAR_VARS)
-
-# NOTE: --exclude-libs=libgcc.a makes sure that any symbols libdl.so pulls from
-# libgcc.a are made static to libdl.so.  This in turn ensures that libraries that
-# a) pull symbols from libgcc.a and b) depend on libdl.so will not rely on libdl.so
-# to provide those symbols, but will instead pull them from libgcc.a.  Specifically,
-# we use this property to make sure libc.so has its own copy of the code from
-# libgcc.a it uses.
-#
-# DO NOT REMOVE --exclude-libs!
-
-LOCAL_LDFLAGS := -Wl,--exclude-libs=libgcc.a
-
-# for x86, exclude libgcc_eh.a for the same reasons as above
-LOCAL_LDFLAGS_x86 := -Wl,--exclude-libs=libgcc_eh.a
-LOCAL_LDFLAGS_x86_64 := $(LOCAL_LDFLAGS_x86)
-
-LOCAL_LDFLAGS_arm    += -Wl,--version-script=$(LOCAL_PATH)/libdl.arm.map
-LOCAL_LDFLAGS_arm64  += -Wl,--version-script=$(LOCAL_PATH)/libdl.arm64.map
-LOCAL_LDFLAGS_mips   += -Wl,--version-script=$(LOCAL_PATH)/libdl.mips.map
-LOCAL_LDFLAGS_mips64 += -Wl,--version-script=$(LOCAL_PATH)/libdl.mips64.map
-LOCAL_LDFLAGS_x86    += -Wl,--version-script=$(LOCAL_PATH)/libdl.x86.map
-LOCAL_LDFLAGS_x86_64 += -Wl,--version-script=$(LOCAL_PATH)/libdl.x86_64.map
-
-LOCAL_SRC_FILES:= libdl.c
-LOCAL_CFLAGS := -Wall -Wextra -Wunused -Werror
-LOCAL_CXX_STL := none
-
-LOCAL_MODULE := libdl
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk \
-                                 $(LOCAL_PATH)/libdl.arm.map \
-                                 $(LOCAL_PATH)/libdl.arm64.map \
-                                 $(LOCAL_PATH)/libdl.mips.map \
-                                 $(LOCAL_PATH)/libdl.mips64.map \
-                                 $(LOCAL_PATH)/libdl.x86.map \
-                                 $(LOCAL_PATH)/libdl.x86_64.map \
-
-# NOTE: libdl needs __aeabi_unwind_cpp_pr0 from libgcc.a but libgcc.a needs a
-# few symbols from libc. Using --no-undefined here results in having to link
-# against libc creating a circular dependency which is removed and we end up
-# with missing symbols. Since this library is just a bunch of stubs, we set
-# LOCAL_ALLOW_UNDEFINED_SYMBOLS to remove --no-undefined from the linker flags.
-LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
-LOCAL_SYSTEM_SHARED_LIBRARIES :=
-
-LOCAL_SANITIZE := never
-include $(BUILD_SHARED_LIBRARY)
-
-# A dummy libdl.a. Need for static executables using the LLVM unwinder. Most
-# functions default to failure, others use a sensible default (dl_iterate_phdr()
-# returns 0, as would happen if the user iterated over every phdr).
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES:= libdl.c
-LOCAL_CFLAGS := -Wall -Wextra -Wunused -Werror
-LOCAL_CXX_STL := none
-
-LOCAL_MODULE := libdl
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-LOCAL_SANITIZE := never
-include $(BUILD_STATIC_LIBRARY)
diff --git a/libdl/NOTICE b/libdl/NOTICE
index 77b5743..7940d04 100644
--- a/libdl/NOTICE
+++ b/libdl/NOTICE
@@ -14,3 +14,19 @@
 
 -------------------------------------------------------------------
 
+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.
+
+-------------------------------------------------------------------
+
diff --git a/libdl/libdl.arm.map b/libdl/libdl.arm.map
index 2821509..1fdc1a7 100644
--- a/libdl/libdl.arm.map
+++ b/libdl/libdl.arm.map
@@ -1,9 +1,24 @@
-# Generated by genversionscripts.py. Do not edit.
+# Generated by genversion-scripts.py. Do not edit.
+#
+# 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.
+#
 
 LIBC {
   global:
-    android_dlopen_ext;
-    dl_iterate_phdr;
+    android_dlopen_ext; # introduced=21
+    dl_iterate_phdr; # introduced-arm=21
     dl_unwind_find_exidx; # arm
     dladdr;
     dlclose;
@@ -16,7 +31,7 @@
 
 LIBC_N {
   global:
-    dlvsym;
+    dlvsym; # introduced=24
 } LIBC;
 
 LIBC_PLATFORM {
diff --git a/libdl/libdl.arm64.map b/libdl/libdl.arm64.map
index f21859c..28d2613 100644
--- a/libdl/libdl.arm64.map
+++ b/libdl/libdl.arm64.map
@@ -1,9 +1,24 @@
-# Generated by genversionscripts.py. Do not edit.
+# Generated by genversion-scripts.py. Do not edit.
+#
+# 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.
+#
 
 LIBC {
   global:
-    android_dlopen_ext;
-    dl_iterate_phdr;
+    android_dlopen_ext; # introduced=21
+    dl_iterate_phdr; # introduced-arm=21
     dladdr;
     dlclose;
     dlerror;
@@ -15,7 +30,7 @@
 
 LIBC_N {
   global:
-    dlvsym;
+    dlvsym; # introduced=24
 } LIBC;
 
 LIBC_PLATFORM {
diff --git a/libdl/libdl.map.txt b/libdl/libdl.map.txt
index 962692e..0a82a2e 100644
--- a/libdl/libdl.map.txt
+++ b/libdl/libdl.map.txt
@@ -16,8 +16,8 @@
 
 LIBC {
   global:
-    android_dlopen_ext;
-    dl_iterate_phdr;
+    android_dlopen_ext; # introduced=21
+    dl_iterate_phdr; # introduced-arm=21
     dl_unwind_find_exidx; # arm
     dladdr;
     dlclose;
@@ -30,7 +30,7 @@
 
 LIBC_N {
   global:
-    dlvsym;
+    dlvsym; # introduced=24
 } LIBC;
 
 LIBC_PLATFORM {
diff --git a/libdl/libdl.mips.map b/libdl/libdl.mips.map
index f21859c..28d2613 100644
--- a/libdl/libdl.mips.map
+++ b/libdl/libdl.mips.map
@@ -1,9 +1,24 @@
-# Generated by genversionscripts.py. Do not edit.
+# Generated by genversion-scripts.py. Do not edit.
+#
+# 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.
+#
 
 LIBC {
   global:
-    android_dlopen_ext;
-    dl_iterate_phdr;
+    android_dlopen_ext; # introduced=21
+    dl_iterate_phdr; # introduced-arm=21
     dladdr;
     dlclose;
     dlerror;
@@ -15,7 +30,7 @@
 
 LIBC_N {
   global:
-    dlvsym;
+    dlvsym; # introduced=24
 } LIBC;
 
 LIBC_PLATFORM {
diff --git a/libdl/libdl.mips64.map b/libdl/libdl.mips64.map
index f21859c..28d2613 100644
--- a/libdl/libdl.mips64.map
+++ b/libdl/libdl.mips64.map
@@ -1,9 +1,24 @@
-# Generated by genversionscripts.py. Do not edit.
+# Generated by genversion-scripts.py. Do not edit.
+#
+# 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.
+#
 
 LIBC {
   global:
-    android_dlopen_ext;
-    dl_iterate_phdr;
+    android_dlopen_ext; # introduced=21
+    dl_iterate_phdr; # introduced-arm=21
     dladdr;
     dlclose;
     dlerror;
@@ -15,7 +30,7 @@
 
 LIBC_N {
   global:
-    dlvsym;
+    dlvsym; # introduced=24
 } LIBC;
 
 LIBC_PLATFORM {
diff --git a/libdl/libdl.x86.map b/libdl/libdl.x86.map
index f21859c..28d2613 100644
--- a/libdl/libdl.x86.map
+++ b/libdl/libdl.x86.map
@@ -1,9 +1,24 @@
-# Generated by genversionscripts.py. Do not edit.
+# Generated by genversion-scripts.py. Do not edit.
+#
+# 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.
+#
 
 LIBC {
   global:
-    android_dlopen_ext;
-    dl_iterate_phdr;
+    android_dlopen_ext; # introduced=21
+    dl_iterate_phdr; # introduced-arm=21
     dladdr;
     dlclose;
     dlerror;
@@ -15,7 +30,7 @@
 
 LIBC_N {
   global:
-    dlvsym;
+    dlvsym; # introduced=24
 } LIBC;
 
 LIBC_PLATFORM {
diff --git a/libdl/libdl.x86_64.map b/libdl/libdl.x86_64.map
index f21859c..28d2613 100644
--- a/libdl/libdl.x86_64.map
+++ b/libdl/libdl.x86_64.map
@@ -1,9 +1,24 @@
-# Generated by genversionscripts.py. Do not edit.
+# Generated by genversion-scripts.py. Do not edit.
+#
+# 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.
+#
 
 LIBC {
   global:
-    android_dlopen_ext;
-    dl_iterate_phdr;
+    android_dlopen_ext; # introduced=21
+    dl_iterate_phdr; # introduced-arm=21
     dladdr;
     dlclose;
     dlerror;
@@ -15,7 +30,7 @@
 
 LIBC_N {
   global:
-    dlvsym;
+    dlvsym; # introduced=24
 } LIBC;
 
 LIBC_PLATFORM {
diff --git a/libm/Android.bp b/libm/Android.bp
index 081a139..23b9d5e 100644
--- a/libm/Android.bp
+++ b/libm/Android.bp
@@ -1,307 +1,282 @@
-// ANDROIDMK TRANSLATION ERROR: unsupported directive
-// ifneq ($(TARGET_USE_PRIVATE_LIBM),true)
-
 bionic_coverage = false
 
-libm_common_src_files = [
-    "upstream-freebsd/lib/msun/bsdsrc/b_exp.c",
-    "upstream-freebsd/lib/msun/bsdsrc/b_log.c",
-    "upstream-freebsd/lib/msun/bsdsrc/b_tgamma.c",
-    "upstream-freebsd/lib/msun/src/catrig.c",
-    "upstream-freebsd/lib/msun/src/catrigf.c",
-    "upstream-freebsd/lib/msun/src/e_acos.c",
-    "upstream-freebsd/lib/msun/src/e_acosf.c",
-    "upstream-freebsd/lib/msun/src/e_acosh.c",
-    "upstream-freebsd/lib/msun/src/e_acoshf.c",
-    "upstream-freebsd/lib/msun/src/e_asin.c",
-    "upstream-freebsd/lib/msun/src/e_asinf.c",
-    "upstream-freebsd/lib/msun/src/e_atan2.c",
-    "upstream-freebsd/lib/msun/src/e_atan2f.c",
-    "upstream-freebsd/lib/msun/src/e_atanh.c",
-    "upstream-freebsd/lib/msun/src/e_atanhf.c",
-    "upstream-freebsd/lib/msun/src/e_cosh.c",
-    "upstream-freebsd/lib/msun/src/e_coshf.c",
-    "upstream-freebsd/lib/msun/src/e_exp.c",
-    "upstream-freebsd/lib/msun/src/e_expf.c",
-    "upstream-freebsd/lib/msun/src/e_fmod.c",
-    "upstream-freebsd/lib/msun/src/e_fmodf.c",
-    "upstream-freebsd/lib/msun/src/e_gamma.c",
-    "upstream-freebsd/lib/msun/src/e_gammaf.c",
-    "upstream-freebsd/lib/msun/src/e_gammaf_r.c",
-    "upstream-freebsd/lib/msun/src/e_gamma_r.c",
-    "upstream-freebsd/lib/msun/src/e_hypot.c",
-    "upstream-freebsd/lib/msun/src/e_hypotf.c",
-    "upstream-freebsd/lib/msun/src/e_j0.c",
-    "upstream-freebsd/lib/msun/src/e_j0f.c",
-    "upstream-freebsd/lib/msun/src/e_j1.c",
-    "upstream-freebsd/lib/msun/src/e_j1f.c",
-    "upstream-freebsd/lib/msun/src/e_jn.c",
-    "upstream-freebsd/lib/msun/src/e_jnf.c",
-    "upstream-freebsd/lib/msun/src/e_lgamma.c",
-    "upstream-freebsd/lib/msun/src/e_lgammaf.c",
-    "upstream-freebsd/lib/msun/src/e_lgammaf_r.c",
-    "upstream-freebsd/lib/msun/src/e_lgamma_r.c",
-    "upstream-freebsd/lib/msun/src/e_log10.c",
-    "upstream-freebsd/lib/msun/src/e_log10f.c",
-    "upstream-freebsd/lib/msun/src/e_log2.c",
-    "upstream-freebsd/lib/msun/src/e_log2f.c",
-    "upstream-freebsd/lib/msun/src/e_log.c",
-    "upstream-freebsd/lib/msun/src/e_logf.c",
-    "upstream-freebsd/lib/msun/src/e_pow.c",
-    "upstream-freebsd/lib/msun/src/e_powf.c",
-    "upstream-freebsd/lib/msun/src/e_remainder.c",
-    "upstream-freebsd/lib/msun/src/e_remainderf.c",
-    "upstream-freebsd/lib/msun/src/e_rem_pio2.c",
-    "upstream-freebsd/lib/msun/src/e_rem_pio2f.c",
-    "upstream-freebsd/lib/msun/src/e_scalb.c",
-    "upstream-freebsd/lib/msun/src/e_scalbf.c",
-    "upstream-freebsd/lib/msun/src/e_sinh.c",
-    "upstream-freebsd/lib/msun/src/e_sinhf.c",
-    "upstream-freebsd/lib/msun/src/e_sqrt.c",
-    "upstream-freebsd/lib/msun/src/e_sqrtf.c",
-    "upstream-freebsd/lib/msun/src/imprecise.c",
-    "upstream-freebsd/lib/msun/src/k_cos.c",
-    "upstream-freebsd/lib/msun/src/k_cosf.c",
-    "upstream-freebsd/lib/msun/src/k_exp.c",
-    "upstream-freebsd/lib/msun/src/k_expf.c",
-    "upstream-freebsd/lib/msun/src/k_rem_pio2.c",
-    "upstream-freebsd/lib/msun/src/k_sin.c",
-    "upstream-freebsd/lib/msun/src/k_sinf.c",
-    "upstream-freebsd/lib/msun/src/k_tan.c",
-    "upstream-freebsd/lib/msun/src/k_tanf.c",
-    "upstream-freebsd/lib/msun/src/s_asinh.c",
-    "upstream-freebsd/lib/msun/src/s_asinhf.c",
-    "upstream-freebsd/lib/msun/src/s_atan.c",
-    "upstream-freebsd/lib/msun/src/s_atanf.c",
-    "upstream-freebsd/lib/msun/src/s_carg.c",
-    "upstream-freebsd/lib/msun/src/s_cargf.c",
-    "upstream-freebsd/lib/msun/src/s_cargl.c",
-    "upstream-freebsd/lib/msun/src/s_cbrt.c",
-    "upstream-freebsd/lib/msun/src/s_cbrtf.c",
-    "upstream-freebsd/lib/msun/src/s_ccosh.c",
-    "upstream-freebsd/lib/msun/src/s_ccoshf.c",
-    "upstream-freebsd/lib/msun/src/s_ceil.c",
-    "upstream-freebsd/lib/msun/src/s_ceilf.c",
-    "upstream-freebsd/lib/msun/src/s_cexp.c",
-    "upstream-freebsd/lib/msun/src/s_cexpf.c",
-    "upstream-freebsd/lib/msun/src/s_cimag.c",
-    "upstream-freebsd/lib/msun/src/s_cimagf.c",
-    "upstream-freebsd/lib/msun/src/s_cimagl.c",
-    "upstream-freebsd/lib/msun/src/s_conj.c",
-    "upstream-freebsd/lib/msun/src/s_conjf.c",
-    "upstream-freebsd/lib/msun/src/s_conjl.c",
-    "upstream-freebsd/lib/msun/src/s_copysign.c",
-    "upstream-freebsd/lib/msun/src/s_copysignf.c",
-    "upstream-freebsd/lib/msun/src/s_cos.c",
-    "upstream-freebsd/lib/msun/src/s_cosf.c",
-    "upstream-freebsd/lib/msun/src/s_cproj.c",
-    "upstream-freebsd/lib/msun/src/s_cprojf.c",
-    "upstream-freebsd/lib/msun/src/s_cprojl.c",
-    "upstream-freebsd/lib/msun/src/s_creal.c",
-    "upstream-freebsd/lib/msun/src/s_crealf.c",
-    "upstream-freebsd/lib/msun/src/s_creall.c",
-    "upstream-freebsd/lib/msun/src/s_csinh.c",
-    "upstream-freebsd/lib/msun/src/s_csinhf.c",
-    "upstream-freebsd/lib/msun/src/s_csqrt.c",
-    "upstream-freebsd/lib/msun/src/s_csqrtf.c",
-    "upstream-freebsd/lib/msun/src/s_csqrtl.c",
-    "upstream-freebsd/lib/msun/src/s_ctanh.c",
-    "upstream-freebsd/lib/msun/src/s_ctanhf.c",
-    "upstream-freebsd/lib/msun/src/s_erf.c",
-    "upstream-freebsd/lib/msun/src/s_erff.c",
-    "upstream-freebsd/lib/msun/src/s_exp2.c",
-    "upstream-freebsd/lib/msun/src/s_exp2f.c",
-    "upstream-freebsd/lib/msun/src/s_expm1.c",
-    "upstream-freebsd/lib/msun/src/s_expm1f.c",
-    "upstream-freebsd/lib/msun/src/s_fdim.c",
-    "upstream-freebsd/lib/msun/src/s_finite.c",
-    "upstream-freebsd/lib/msun/src/s_finitef.c",
-    "upstream-freebsd/lib/msun/src/s_floor.c",
-    "upstream-freebsd/lib/msun/src/s_floorf.c",
-    "upstream-freebsd/lib/msun/src/s_fma.c",
-    "upstream-freebsd/lib/msun/src/s_fmaf.c",
-    "upstream-freebsd/lib/msun/src/s_fmax.c",
-    "upstream-freebsd/lib/msun/src/s_fmaxf.c",
-    "upstream-freebsd/lib/msun/src/s_fmin.c",
-    "upstream-freebsd/lib/msun/src/s_fminf.c",
-    "upstream-freebsd/lib/msun/src/s_frexp.c",
-    "upstream-freebsd/lib/msun/src/s_frexpf.c",
-    "upstream-freebsd/lib/msun/src/s_ilogb.c",
-    "upstream-freebsd/lib/msun/src/s_ilogbf.c",
-    "upstream-freebsd/lib/msun/src/s_llrint.c",
-    "upstream-freebsd/lib/msun/src/s_llrintf.c",
-    "upstream-freebsd/lib/msun/src/s_llround.c",
-    "upstream-freebsd/lib/msun/src/s_llroundf.c",
-    "upstream-freebsd/lib/msun/src/s_log1p.c",
-    "upstream-freebsd/lib/msun/src/s_log1pf.c",
-    "upstream-freebsd/lib/msun/src/s_logb.c",
-    "upstream-freebsd/lib/msun/src/s_logbf.c",
-    "upstream-freebsd/lib/msun/src/s_lrint.c",
-    "upstream-freebsd/lib/msun/src/s_lrintf.c",
-    "upstream-freebsd/lib/msun/src/s_lround.c",
-    "upstream-freebsd/lib/msun/src/s_lroundf.c",
-    "upstream-freebsd/lib/msun/src/s_modf.c",
-    "upstream-freebsd/lib/msun/src/s_modff.c",
-    "upstream-freebsd/lib/msun/src/s_nan.c",
-    "upstream-freebsd/lib/msun/src/s_nearbyint.c",
-    "upstream-freebsd/lib/msun/src/s_nextafter.c",
-    "upstream-freebsd/lib/msun/src/s_nextafterf.c",
-    "upstream-freebsd/lib/msun/src/s_remquo.c",
-    "upstream-freebsd/lib/msun/src/s_remquof.c",
-    "upstream-freebsd/lib/msun/src/s_rint.c",
-    "upstream-freebsd/lib/msun/src/s_rintf.c",
-    "upstream-freebsd/lib/msun/src/s_round.c",
-    "upstream-freebsd/lib/msun/src/s_roundf.c",
-    "upstream-freebsd/lib/msun/src/s_scalbln.c",
-    "upstream-freebsd/lib/msun/src/s_scalbn.c",
-    "upstream-freebsd/lib/msun/src/s_scalbnf.c",
-    "upstream-freebsd/lib/msun/src/s_signgam.c",
-    "upstream-freebsd/lib/msun/src/s_significand.c",
-    "upstream-freebsd/lib/msun/src/s_significandf.c",
-    "upstream-freebsd/lib/msun/src/s_sin.c",
-    "upstream-freebsd/lib/msun/src/s_sinf.c",
-    "upstream-freebsd/lib/msun/src/s_tan.c",
-    "upstream-freebsd/lib/msun/src/s_tanf.c",
-    "upstream-freebsd/lib/msun/src/s_tanh.c",
-    "upstream-freebsd/lib/msun/src/s_tanhf.c",
-    "upstream-freebsd/lib/msun/src/s_tgammaf.c",
-    "upstream-freebsd/lib/msun/src/s_trunc.c",
-    "upstream-freebsd/lib/msun/src/s_truncf.c",
-    "upstream-freebsd/lib/msun/src/w_cabs.c",
-    "upstream-freebsd/lib/msun/src/w_cabsf.c",
-    "upstream-freebsd/lib/msun/src/w_cabsl.c",
-    "upstream-freebsd/lib/msun/src/w_drem.c",
-    "upstream-freebsd/lib/msun/src/w_dremf.c",
-]
-
-libm_common_src_files += [
-    // TODO: this comes from from upstream's libc, not libm, but it's an
-    // implementation detail that should have hidden visibility, so it needs
-    // to be in whatever library the math code is in.
-    "digittoint.c",
-
-    // Functionality not in the BSDs.
-    "significandl.c",
-    "sincos.c",
-
-    // Modified versions of BSD code.
-    "signbit.c",
-
-    // Home-grown stuff.
-    "fabs.cpp",
-]
-
-libm_ld128_src_files = [
-    "upstream-freebsd/lib/msun/src/e_acosl.c",
-    "upstream-freebsd/lib/msun/src/e_acoshl.c",
-    "upstream-freebsd/lib/msun/src/e_asinl.c",
-    "upstream-freebsd/lib/msun/src/e_atan2l.c",
-    "upstream-freebsd/lib/msun/src/e_atanhl.c",
-    "upstream-freebsd/lib/msun/src/e_fmodl.c",
-    "upstream-freebsd/lib/msun/src/e_hypotl.c",
-    "upstream-freebsd/lib/msun/src/e_lgammal.c",
-    "upstream-freebsd/lib/msun/src/e_remainderl.c",
-    "upstream-freebsd/lib/msun/src/e_sqrtl.c",
-    "upstream-freebsd/lib/msun/src/s_asinhl.c",
-    "upstream-freebsd/lib/msun/src/s_atanl.c",
-    "upstream-freebsd/lib/msun/src/s_cbrtl.c",
-    "upstream-freebsd/lib/msun/src/s_ceill.c",
-    "upstream-freebsd/lib/msun/src/s_copysignl.c",
-    "upstream-freebsd/lib/msun/src/e_coshl.c",
-    "upstream-freebsd/lib/msun/src/s_cosl.c",
-    "upstream-freebsd/lib/msun/src/s_floorl.c",
-    "upstream-freebsd/lib/msun/src/s_fmal.c",
-    "upstream-freebsd/lib/msun/src/s_fmaxl.c",
-    "upstream-freebsd/lib/msun/src/s_fminl.c",
-    "upstream-freebsd/lib/msun/src/s_modfl.c",
-    "upstream-freebsd/lib/msun/src/s_frexpl.c",
-    "upstream-freebsd/lib/msun/src/s_ilogbl.c",
-    "upstream-freebsd/lib/msun/src/s_llrintl.c",
-    "upstream-freebsd/lib/msun/src/s_llroundl.c",
-    "upstream-freebsd/lib/msun/src/s_logbl.c",
-    "upstream-freebsd/lib/msun/src/s_lrintl.c",
-    "upstream-freebsd/lib/msun/src/s_lroundl.c",
-    "upstream-freebsd/lib/msun/src/s_nextafterl.c",
-    "upstream-freebsd/lib/msun/src/s_nexttoward.c",
-    "upstream-freebsd/lib/msun/src/s_nexttowardf.c",
-    "upstream-freebsd/lib/msun/src/s_remquol.c",
-    "upstream-freebsd/lib/msun/src/s_rintl.c",
-    "upstream-freebsd/lib/msun/src/s_roundl.c",
-    "upstream-freebsd/lib/msun/src/s_scalbnl.c",
-    "upstream-freebsd/lib/msun/src/e_sinhl.c",
-    "upstream-freebsd/lib/msun/src/s_sinl.c",
-    "upstream-freebsd/lib/msun/src/s_tanhl.c",
-    "upstream-freebsd/lib/msun/src/s_tanl.c",
-    "upstream-freebsd/lib/msun/src/s_truncl.c",
-]
-
-libm_ld128_src_files += [
-    "upstream-freebsd/lib/msun/ld128/invtrig.c",
-    "upstream-freebsd/lib/msun/ld128/e_lgammal_r.c",
-    "upstream-freebsd/lib/msun/ld128/k_cosl.c",
-    "upstream-freebsd/lib/msun/ld128/k_sinl.c",
-    "upstream-freebsd/lib/msun/ld128/k_tanl.c",
-    "upstream-freebsd/lib/msun/ld128/s_erfl.c",
-    "upstream-freebsd/lib/msun/ld128/s_exp2l.c",
-    "upstream-freebsd/lib/msun/ld128/s_expl.c",
-    "upstream-freebsd/lib/msun/ld128/s_logl.c",
-    "upstream-freebsd/lib/msun/ld128/s_nanl.c",
-]
-
-// TODO: re-enable i387/e_sqrtf.S for x86, and maybe others.
-
-libm_common_cflags = [
-    "-D__BIONIC_NO_MATH_INLINES",
-    "-DFLT_EVAL_METHOD=0",
-    "-include freebsd-compat.h",
-    "-Werror",
-    "-Wno-missing-braces",
-    "-Wno-parentheses",
-    "-Wno-sign-compare",
-    "-Wno-uninitialized",
-    "-Wno-unknown-pragmas",
-    "-fvisibility=hidden",
-]
-
-// Workaround the GCC "(long)fn -> lfn" optimization bug which will result in
-// self recursions for lrint, lrintf, and lrintl.
-// BUG: 14225968
-libm_common_cflags += [
-    "-fno-builtin-rint",
-    "-fno-builtin-rintf",
-    "-fno-builtin-rintl",
-]
-
-libm_common_local_includes = ["upstream-freebsd/lib/msun/src/"]
-
-libm_ld_local_includes = ["upstream-freebsd/lib/msun/ld128/"]
-
 //
 // libm.so and libm.a for target.
 //
 cc_library {
     name: "libm",
 
-    cflags: libm_common_cflags,
-    include_dirs: ["bionic/libc"],
-    local_include_dirs: libm_common_local_includes,
-    srcs: libm_common_src_files,
-    system_shared_libs: ["libc"],
+    srcs: [
+        "upstream-freebsd/lib/msun/bsdsrc/b_exp.c",
+        "upstream-freebsd/lib/msun/bsdsrc/b_log.c",
+        "upstream-freebsd/lib/msun/bsdsrc/b_tgamma.c",
+        "upstream-freebsd/lib/msun/src/catrig.c",
+        "upstream-freebsd/lib/msun/src/catrigf.c",
+        "upstream-freebsd/lib/msun/src/e_acos.c",
+        "upstream-freebsd/lib/msun/src/e_acosf.c",
+        "upstream-freebsd/lib/msun/src/e_acosh.c",
+        "upstream-freebsd/lib/msun/src/e_acoshf.c",
+        "upstream-freebsd/lib/msun/src/e_asin.c",
+        "upstream-freebsd/lib/msun/src/e_asinf.c",
+        "upstream-freebsd/lib/msun/src/e_atan2.c",
+        "upstream-freebsd/lib/msun/src/e_atan2f.c",
+        "upstream-freebsd/lib/msun/src/e_atanh.c",
+        "upstream-freebsd/lib/msun/src/e_atanhf.c",
+        "upstream-freebsd/lib/msun/src/e_cosh.c",
+        "upstream-freebsd/lib/msun/src/e_coshf.c",
+        "upstream-freebsd/lib/msun/src/e_exp.c",
+        "upstream-freebsd/lib/msun/src/e_expf.c",
+        "upstream-freebsd/lib/msun/src/e_fmod.c",
+        "upstream-freebsd/lib/msun/src/e_fmodf.c",
+        "upstream-freebsd/lib/msun/src/e_gamma.c",
+        "upstream-freebsd/lib/msun/src/e_gammaf.c",
+        "upstream-freebsd/lib/msun/src/e_gammaf_r.c",
+        "upstream-freebsd/lib/msun/src/e_gamma_r.c",
+        "upstream-freebsd/lib/msun/src/e_hypot.c",
+        "upstream-freebsd/lib/msun/src/e_hypotf.c",
+        "upstream-freebsd/lib/msun/src/e_j0.c",
+        "upstream-freebsd/lib/msun/src/e_j0f.c",
+        "upstream-freebsd/lib/msun/src/e_j1.c",
+        "upstream-freebsd/lib/msun/src/e_j1f.c",
+        "upstream-freebsd/lib/msun/src/e_jn.c",
+        "upstream-freebsd/lib/msun/src/e_jnf.c",
+        "upstream-freebsd/lib/msun/src/e_lgamma.c",
+        "upstream-freebsd/lib/msun/src/e_lgammaf.c",
+        "upstream-freebsd/lib/msun/src/e_lgammaf_r.c",
+        "upstream-freebsd/lib/msun/src/e_lgamma_r.c",
+        "upstream-freebsd/lib/msun/src/e_log10.c",
+        "upstream-freebsd/lib/msun/src/e_log10f.c",
+        "upstream-freebsd/lib/msun/src/e_log2.c",
+        "upstream-freebsd/lib/msun/src/e_log2f.c",
+        "upstream-freebsd/lib/msun/src/e_log.c",
+        "upstream-freebsd/lib/msun/src/e_logf.c",
+        "upstream-freebsd/lib/msun/src/e_pow.c",
+        "upstream-freebsd/lib/msun/src/e_powf.c",
+        "upstream-freebsd/lib/msun/src/e_remainder.c",
+        "upstream-freebsd/lib/msun/src/e_remainderf.c",
+        "upstream-freebsd/lib/msun/src/e_rem_pio2.c",
+        "upstream-freebsd/lib/msun/src/e_rem_pio2f.c",
+        "upstream-freebsd/lib/msun/src/e_scalb.c",
+        "upstream-freebsd/lib/msun/src/e_scalbf.c",
+        "upstream-freebsd/lib/msun/src/e_sinh.c",
+        "upstream-freebsd/lib/msun/src/e_sinhf.c",
+        "upstream-freebsd/lib/msun/src/e_sqrt.c",
+        "upstream-freebsd/lib/msun/src/e_sqrtf.c",
+        "upstream-freebsd/lib/msun/src/imprecise.c",
+        "upstream-freebsd/lib/msun/src/k_cos.c",
+        "upstream-freebsd/lib/msun/src/k_cosf.c",
+        "upstream-freebsd/lib/msun/src/k_exp.c",
+        "upstream-freebsd/lib/msun/src/k_expf.c",
+        "upstream-freebsd/lib/msun/src/k_rem_pio2.c",
+        "upstream-freebsd/lib/msun/src/k_sin.c",
+        "upstream-freebsd/lib/msun/src/k_sinf.c",
+        "upstream-freebsd/lib/msun/src/k_tan.c",
+        "upstream-freebsd/lib/msun/src/k_tanf.c",
+        "upstream-freebsd/lib/msun/src/s_asinh.c",
+        "upstream-freebsd/lib/msun/src/s_asinhf.c",
+        "upstream-freebsd/lib/msun/src/s_atan.c",
+        "upstream-freebsd/lib/msun/src/s_atanf.c",
+        "upstream-freebsd/lib/msun/src/s_carg.c",
+        "upstream-freebsd/lib/msun/src/s_cargf.c",
+        "upstream-freebsd/lib/msun/src/s_cargl.c",
+        "upstream-freebsd/lib/msun/src/s_cbrt.c",
+        "upstream-freebsd/lib/msun/src/s_cbrtf.c",
+        "upstream-freebsd/lib/msun/src/s_ccosh.c",
+        "upstream-freebsd/lib/msun/src/s_ccoshf.c",
+        "upstream-freebsd/lib/msun/src/s_ceil.c",
+        "upstream-freebsd/lib/msun/src/s_ceilf.c",
+        "upstream-freebsd/lib/msun/src/s_cexp.c",
+        "upstream-freebsd/lib/msun/src/s_cexpf.c",
+        "upstream-freebsd/lib/msun/src/s_cimag.c",
+        "upstream-freebsd/lib/msun/src/s_cimagf.c",
+        "upstream-freebsd/lib/msun/src/s_cimagl.c",
+        "upstream-freebsd/lib/msun/src/s_conj.c",
+        "upstream-freebsd/lib/msun/src/s_conjf.c",
+        "upstream-freebsd/lib/msun/src/s_conjl.c",
+        "upstream-freebsd/lib/msun/src/s_copysign.c",
+        "upstream-freebsd/lib/msun/src/s_copysignf.c",
+        "upstream-freebsd/lib/msun/src/s_cos.c",
+        "upstream-freebsd/lib/msun/src/s_cosf.c",
+        "upstream-freebsd/lib/msun/src/s_cproj.c",
+        "upstream-freebsd/lib/msun/src/s_cprojf.c",
+        "upstream-freebsd/lib/msun/src/s_cprojl.c",
+        "upstream-freebsd/lib/msun/src/s_creal.c",
+        "upstream-freebsd/lib/msun/src/s_crealf.c",
+        "upstream-freebsd/lib/msun/src/s_creall.c",
+        "upstream-freebsd/lib/msun/src/s_csinh.c",
+        "upstream-freebsd/lib/msun/src/s_csinhf.c",
+        "upstream-freebsd/lib/msun/src/s_csqrt.c",
+        "upstream-freebsd/lib/msun/src/s_csqrtf.c",
+        "upstream-freebsd/lib/msun/src/s_csqrtl.c",
+        "upstream-freebsd/lib/msun/src/s_ctanh.c",
+        "upstream-freebsd/lib/msun/src/s_ctanhf.c",
+        "upstream-freebsd/lib/msun/src/s_erf.c",
+        "upstream-freebsd/lib/msun/src/s_erff.c",
+        "upstream-freebsd/lib/msun/src/s_exp2.c",
+        "upstream-freebsd/lib/msun/src/s_exp2f.c",
+        "upstream-freebsd/lib/msun/src/s_expm1.c",
+        "upstream-freebsd/lib/msun/src/s_expm1f.c",
+        "upstream-freebsd/lib/msun/src/s_fdim.c",
+        "upstream-freebsd/lib/msun/src/s_finite.c",
+        "upstream-freebsd/lib/msun/src/s_finitef.c",
+        "upstream-freebsd/lib/msun/src/s_floor.c",
+        "upstream-freebsd/lib/msun/src/s_floorf.c",
+        "upstream-freebsd/lib/msun/src/s_fma.c",
+        "upstream-freebsd/lib/msun/src/s_fmaf.c",
+        "upstream-freebsd/lib/msun/src/s_fmax.c",
+        "upstream-freebsd/lib/msun/src/s_fmaxf.c",
+        "upstream-freebsd/lib/msun/src/s_fmin.c",
+        "upstream-freebsd/lib/msun/src/s_fminf.c",
+        "upstream-freebsd/lib/msun/src/s_frexp.c",
+        "upstream-freebsd/lib/msun/src/s_frexpf.c",
+        "upstream-freebsd/lib/msun/src/s_ilogb.c",
+        "upstream-freebsd/lib/msun/src/s_ilogbf.c",
+        "upstream-freebsd/lib/msun/src/s_llrint.c",
+        "upstream-freebsd/lib/msun/src/s_llrintf.c",
+        "upstream-freebsd/lib/msun/src/s_llround.c",
+        "upstream-freebsd/lib/msun/src/s_llroundf.c",
+        "upstream-freebsd/lib/msun/src/s_log1p.c",
+        "upstream-freebsd/lib/msun/src/s_log1pf.c",
+        "upstream-freebsd/lib/msun/src/s_logb.c",
+        "upstream-freebsd/lib/msun/src/s_logbf.c",
+        "upstream-freebsd/lib/msun/src/s_lrint.c",
+        "upstream-freebsd/lib/msun/src/s_lrintf.c",
+        "upstream-freebsd/lib/msun/src/s_lround.c",
+        "upstream-freebsd/lib/msun/src/s_lroundf.c",
+        "upstream-freebsd/lib/msun/src/s_modf.c",
+        "upstream-freebsd/lib/msun/src/s_modff.c",
+        "upstream-freebsd/lib/msun/src/s_nan.c",
+        "upstream-freebsd/lib/msun/src/s_nearbyint.c",
+        "upstream-freebsd/lib/msun/src/s_nextafter.c",
+        "upstream-freebsd/lib/msun/src/s_nextafterf.c",
+        "upstream-freebsd/lib/msun/src/s_remquo.c",
+        "upstream-freebsd/lib/msun/src/s_remquof.c",
+        "upstream-freebsd/lib/msun/src/s_rint.c",
+        "upstream-freebsd/lib/msun/src/s_rintf.c",
+        "upstream-freebsd/lib/msun/src/s_round.c",
+        "upstream-freebsd/lib/msun/src/s_roundf.c",
+        "upstream-freebsd/lib/msun/src/s_scalbln.c",
+        "upstream-freebsd/lib/msun/src/s_scalbn.c",
+        "upstream-freebsd/lib/msun/src/s_scalbnf.c",
+        "upstream-freebsd/lib/msun/src/s_signgam.c",
+        "upstream-freebsd/lib/msun/src/s_significand.c",
+        "upstream-freebsd/lib/msun/src/s_significandf.c",
+        "upstream-freebsd/lib/msun/src/s_sin.c",
+        "upstream-freebsd/lib/msun/src/s_sinf.c",
+        "upstream-freebsd/lib/msun/src/s_tan.c",
+        "upstream-freebsd/lib/msun/src/s_tanf.c",
+        "upstream-freebsd/lib/msun/src/s_tanh.c",
+        "upstream-freebsd/lib/msun/src/s_tanhf.c",
+        "upstream-freebsd/lib/msun/src/s_tgammaf.c",
+        "upstream-freebsd/lib/msun/src/s_trunc.c",
+        "upstream-freebsd/lib/msun/src/s_truncf.c",
+        "upstream-freebsd/lib/msun/src/w_cabs.c",
+        "upstream-freebsd/lib/msun/src/w_cabsf.c",
+        "upstream-freebsd/lib/msun/src/w_cabsl.c",
+        "upstream-freebsd/lib/msun/src/w_drem.c",
+        "upstream-freebsd/lib/msun/src/w_dremf.c",
 
-    native_coverage: bionic_coverage,
-    sanitize: ["never"],
+        // The FreeBSD complex functions appear to be better, but they're incomplete.
+        // We take the FreeBSD implementations when they exist, but fill out the rest
+        // of <complex.h> from NetBSD...
+        "upstream-netbsd/lib/libm/complex/cacoshl.c",
+        "upstream-netbsd/lib/libm/complex/cacosl.c",
+        "upstream-netbsd/lib/libm/complex/casinhl.c",
+        "upstream-netbsd/lib/libm/complex/casinl.c",
+        "upstream-netbsd/lib/libm/complex/catanhl.c",
+        "upstream-netbsd/lib/libm/complex/catanl.c",
+        "upstream-netbsd/lib/libm/complex/ccoshl.c",
+        "upstream-netbsd/lib/libm/complex/ccosl.c",
+        "upstream-netbsd/lib/libm/complex/cephes_subrl.c",
+        "upstream-netbsd/lib/libm/complex/cexpl.c",
+        "upstream-netbsd/lib/libm/complex/clog.c",
+        "upstream-netbsd/lib/libm/complex/clogf.c",
+        "upstream-netbsd/lib/libm/complex/clogl.c",
+        "upstream-netbsd/lib/libm/complex/cpow.c",
+        "upstream-netbsd/lib/libm/complex/cpowf.c",
+        "upstream-netbsd/lib/libm/complex/cpowl.c",
+        "upstream-netbsd/lib/libm/complex/csinhl.c",
+        "upstream-netbsd/lib/libm/complex/csinl.c",
+        "upstream-netbsd/lib/libm/complex/ctanhl.c",
+        "upstream-netbsd/lib/libm/complex/ctanl.c",
+
+        // TODO: this comes from from upstream's libc, not libm, but it's an
+        // implementation detail that should have hidden visibility, so it needs
+        // to be in whatever library the math code is in.
+        "digittoint.c",
+
+        // Functionality not in the BSDs.
+        "significandl.c",
+        "sincos.c",
+
+        // Modified versions of BSD code.
+        "signbit.c",
+
+        // Home-grown stuff.
+        "fabs.cpp",
+    ],
 
     multilib: {
         lib32: {
             srcs: ["fake_long_double.c"],
         },
+
         lib64: {
-            srcs: libm_ld128_src_files,
-            local_include_dirs: libm_ld_local_includes,
-            // We'd really like to do this for all architectures, but since this wasn't done
-            // before, these symbols must continue to be exported on LP32 for binary
-            // compatibility.
-            ldflags: ["-Wl,--exclude-libs,libgcc.a"],
+            srcs: [
+                "upstream-freebsd/lib/msun/src/e_acosl.c",
+                "upstream-freebsd/lib/msun/src/e_acoshl.c",
+                "upstream-freebsd/lib/msun/src/e_asinl.c",
+                "upstream-freebsd/lib/msun/src/e_atan2l.c",
+                "upstream-freebsd/lib/msun/src/e_atanhl.c",
+                "upstream-freebsd/lib/msun/src/e_fmodl.c",
+                "upstream-freebsd/lib/msun/src/e_hypotl.c",
+                "upstream-freebsd/lib/msun/src/e_lgammal.c",
+                "upstream-freebsd/lib/msun/src/e_remainderl.c",
+                "upstream-freebsd/lib/msun/src/e_sqrtl.c",
+                "upstream-freebsd/lib/msun/src/s_asinhl.c",
+                "upstream-freebsd/lib/msun/src/s_atanl.c",
+                "upstream-freebsd/lib/msun/src/s_cbrtl.c",
+                "upstream-freebsd/lib/msun/src/s_ceill.c",
+                "upstream-freebsd/lib/msun/src/s_copysignl.c",
+                "upstream-freebsd/lib/msun/src/e_coshl.c",
+                "upstream-freebsd/lib/msun/src/s_cosl.c",
+                "upstream-freebsd/lib/msun/src/s_floorl.c",
+                "upstream-freebsd/lib/msun/src/s_fmal.c",
+                "upstream-freebsd/lib/msun/src/s_fmaxl.c",
+                "upstream-freebsd/lib/msun/src/s_fminl.c",
+                "upstream-freebsd/lib/msun/src/s_modfl.c",
+                "upstream-freebsd/lib/msun/src/s_frexpl.c",
+                "upstream-freebsd/lib/msun/src/s_ilogbl.c",
+                "upstream-freebsd/lib/msun/src/s_llrintl.c",
+                "upstream-freebsd/lib/msun/src/s_llroundl.c",
+                "upstream-freebsd/lib/msun/src/s_logbl.c",
+                "upstream-freebsd/lib/msun/src/s_lrintl.c",
+                "upstream-freebsd/lib/msun/src/s_lroundl.c",
+                "upstream-freebsd/lib/msun/src/s_nextafterl.c",
+                "upstream-freebsd/lib/msun/src/s_nexttoward.c",
+                "upstream-freebsd/lib/msun/src/s_nexttowardf.c",
+                "upstream-freebsd/lib/msun/src/s_remquol.c",
+                "upstream-freebsd/lib/msun/src/s_rintl.c",
+                "upstream-freebsd/lib/msun/src/s_roundl.c",
+                "upstream-freebsd/lib/msun/src/s_scalbnl.c",
+                "upstream-freebsd/lib/msun/src/e_sinhl.c",
+                "upstream-freebsd/lib/msun/src/s_sinl.c",
+                "upstream-freebsd/lib/msun/src/s_tanhl.c",
+                "upstream-freebsd/lib/msun/src/s_tanl.c",
+                "upstream-freebsd/lib/msun/src/s_truncl.c",
+
+                "upstream-freebsd/lib/msun/ld128/invtrig.c",
+                "upstream-freebsd/lib/msun/ld128/e_lgammal_r.c",
+                "upstream-freebsd/lib/msun/ld128/k_cosl.c",
+                "upstream-freebsd/lib/msun/ld128/k_sinl.c",
+                "upstream-freebsd/lib/msun/ld128/k_tanl.c",
+                "upstream-freebsd/lib/msun/ld128/s_erfl.c",
+                "upstream-freebsd/lib/msun/ld128/s_exp2l.c",
+                "upstream-freebsd/lib/msun/ld128/s_expl.c",
+                "upstream-freebsd/lib/msun/ld128/s_logl.c",
+                "upstream-freebsd/lib/msun/ld128/s_nanl.c",
+            ],
+            local_include_dirs: ["upstream-freebsd/lib/msun/ld128/"],
         },
     },
 
@@ -316,6 +291,7 @@
                     "arm/sqrt.S",
                     "arm/floor.S",
                 ],
+
                 exclude_srcs: [
                     "upstream-freebsd/lib/msun/src/e_sqrt.c",
                     "upstream-freebsd/lib/msun/src/e_sqrtf.c",
@@ -387,6 +363,8 @@
                 "x86/libm_reduce_pi04l.S",
                 "x86/libm_sincos_huge.S",
                 "x86/libm_tancot_huge.S",
+                "x86/lrint.S",
+                "x86/lrintf.S",
                 "x86/s_atan.S",
                 "x86/s_cbrt.S",
                 "x86/s_cos.S",
@@ -414,6 +392,8 @@
                 "upstream-freebsd/lib/msun/src/s_cos.c",
                 "upstream-freebsd/lib/msun/src/s_expm1.c",
                 "upstream-freebsd/lib/msun/src/s_log1p.c",
+                "upstream-freebsd/lib/msun/src/s_lrint.c",
+                "upstream-freebsd/lib/msun/src/s_lrintf.c",
                 "upstream-freebsd/lib/msun/src/s_sin.c",
                 "upstream-freebsd/lib/msun/src/s_tan.c",
                 "upstream-freebsd/lib/msun/src/s_tanh.c",
@@ -424,6 +404,8 @@
                     "x86/ceilf.S",
                     "x86/floor.S",
                     "x86/floorf.S",
+                    "x86/rint.S",
+                    "x86/rintf.S",
                     "x86/trunc.S",
                     "x86/truncf.S",
                 ],
@@ -432,13 +414,13 @@
                     "upstream-freebsd/lib/msun/src/s_ceilf.c",
                     "upstream-freebsd/lib/msun/src/s_floor.c",
                     "upstream-freebsd/lib/msun/src/s_floorf.c",
+                    "upstream-freebsd/lib/msun/src/s_rint.c",
+                    "upstream-freebsd/lib/msun/src/s_rintf.c",
                     "upstream-freebsd/lib/msun/src/s_trunc.c",
                     "upstream-freebsd/lib/msun/src/s_truncf.c",
                 ],
             },
             local_include_dirs: ["i387"],
-            // Clang has wrong long double sizes for x86.
-            clang: false,
             ldflags: ["-Wl,--hash-style=both"],
             version_script: "libm.x86.map",
         },
@@ -458,6 +440,8 @@
                 "x86_64/e_log.S",
                 "x86_64/e_pow.S",
                 "x86_64/e_sinh.S",
+                "x86_64/lrint.S",
+                "x86_64/lrintf.S",
                 "x86_64/s_atan.S",
                 "x86_64/s_cbrt.S",
                 "x86_64/s_cos.S",
@@ -485,6 +469,10 @@
                 "upstream-freebsd/lib/msun/src/s_cos.c",
                 "upstream-freebsd/lib/msun/src/s_expm1.c",
                 "upstream-freebsd/lib/msun/src/s_log1p.c",
+                "upstream-freebsd/lib/msun/src/s_llrint.c",
+                "upstream-freebsd/lib/msun/src/s_llrintf.c",
+                "upstream-freebsd/lib/msun/src/s_lrint.c",
+                "upstream-freebsd/lib/msun/src/s_lrintf.c",
                 "upstream-freebsd/lib/msun/src/s_sin.c",
                 "upstream-freebsd/lib/msun/src/s_tan.c",
                 "upstream-freebsd/lib/msun/src/s_tanh.c",
@@ -495,6 +483,8 @@
                     "x86_64/ceilf.S",
                     "x86_64/floor.S",
                     "x86_64/floorf.S",
+                    "x86_64/rint.S",
+                    "x86_64/rintf.S",
                     "x86_64/trunc.S",
                     "x86_64/truncf.S",
                 ],
@@ -503,18 +493,41 @@
                     "upstream-freebsd/lib/msun/src/s_ceilf.c",
                     "upstream-freebsd/lib/msun/src/s_floor.c",
                     "upstream-freebsd/lib/msun/src/s_floorf.c",
+                    "upstream-freebsd/lib/msun/src/s_rint.c",
+                    "upstream-freebsd/lib/msun/src/s_rintf.c",
                     "upstream-freebsd/lib/msun/src/s_trunc.c",
                     "upstream-freebsd/lib/msun/src/s_truncf.c",
                 ],
             },
-            // Clang has wrong long double sizes for x86.
-            clang: false,
             version_script: "libm.x86_64.map",
         },
     },
 
+    local_include_dirs: [
+        "upstream-freebsd/android/include/",
+        "upstream-freebsd/lib/msun/src/",
+    ],
+
+    cflags: [
+        "-D__BIONIC_NO_MATH_INLINES",
+        "-D_BSD_SOURCE",
+        "-DFLT_EVAL_METHOD=0",
+        "-include freebsd-compat.h",
+        "-Werror",
+        "-Wno-missing-braces",
+        "-Wno-parentheses",
+        "-Wno-sign-compare",
+        "-Wno-uninitialized",
+        "-Wno-unknown-pragmas",
+    ],
+    conlyflags: ["-std=gnu11"],
+
+    include_dirs: ["bionic/libc"],
+    system_shared_libs: ["libc"],
+
+    native_coverage: bionic_coverage,
+    sanitize: {
+        never: true,
+    },
     stl: "none",
 }
-
-// ANDROIDMK TRANSLATION ERROR: unsupported directive
-// endif
diff --git a/libm/Android.mk b/libm/Android.mk
deleted file mode 100644
index 6575e1e..0000000
--- a/libm/Android.mk
+++ /dev/null
@@ -1,564 +0,0 @@
-ifneq ($(TARGET_USE_PRIVATE_LIBM),true)
-LOCAL_PATH:= $(call my-dir)
-
-bionic_coverage := false
-
-# Clang/llvm has incompatible long double (fp128) for x86_64.
-# https://llvm.org/bugs/show_bug.cgi?id=23897
-ifeq ($(TARGET_ARCH),x86_64)
-libm_clang := false
-endif
-
-# -----------------------------------------------------------------------------
-# libm.a
-# -----------------------------------------------------------------------------
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := libm
-
-LOCAL_SRC_FILES := \
-    upstream-freebsd/lib/msun/bsdsrc/b_exp.c \
-    upstream-freebsd/lib/msun/bsdsrc/b_log.c \
-    upstream-freebsd/lib/msun/bsdsrc/b_tgamma.c \
-    upstream-freebsd/lib/msun/src/catrig.c \
-    upstream-freebsd/lib/msun/src/catrigf.c \
-    upstream-freebsd/lib/msun/src/e_acos.c \
-    upstream-freebsd/lib/msun/src/e_acosf.c \
-    upstream-freebsd/lib/msun/src/e_acosh.c \
-    upstream-freebsd/lib/msun/src/e_acoshf.c \
-    upstream-freebsd/lib/msun/src/e_asin.c \
-    upstream-freebsd/lib/msun/src/e_asinf.c \
-    upstream-freebsd/lib/msun/src/e_atan2.c \
-    upstream-freebsd/lib/msun/src/e_atan2f.c \
-    upstream-freebsd/lib/msun/src/e_atanh.c \
-    upstream-freebsd/lib/msun/src/e_atanhf.c \
-    upstream-freebsd/lib/msun/src/e_cosh.c \
-    upstream-freebsd/lib/msun/src/e_coshf.c \
-    upstream-freebsd/lib/msun/src/e_exp.c \
-    upstream-freebsd/lib/msun/src/e_expf.c \
-    upstream-freebsd/lib/msun/src/e_fmod.c \
-    upstream-freebsd/lib/msun/src/e_fmodf.c \
-    upstream-freebsd/lib/msun/src/e_gamma.c \
-    upstream-freebsd/lib/msun/src/e_gammaf.c \
-    upstream-freebsd/lib/msun/src/e_gammaf_r.c \
-    upstream-freebsd/lib/msun/src/e_gamma_r.c \
-    upstream-freebsd/lib/msun/src/e_hypot.c \
-    upstream-freebsd/lib/msun/src/e_hypotf.c \
-    upstream-freebsd/lib/msun/src/e_j0.c \
-    upstream-freebsd/lib/msun/src/e_j0f.c \
-    upstream-freebsd/lib/msun/src/e_j1.c \
-    upstream-freebsd/lib/msun/src/e_j1f.c \
-    upstream-freebsd/lib/msun/src/e_jn.c \
-    upstream-freebsd/lib/msun/src/e_jnf.c \
-    upstream-freebsd/lib/msun/src/e_lgamma.c \
-    upstream-freebsd/lib/msun/src/e_lgammaf.c \
-    upstream-freebsd/lib/msun/src/e_lgammaf_r.c \
-    upstream-freebsd/lib/msun/src/e_lgamma_r.c \
-    upstream-freebsd/lib/msun/src/e_log10.c \
-    upstream-freebsd/lib/msun/src/e_log10f.c \
-    upstream-freebsd/lib/msun/src/e_log2.c \
-    upstream-freebsd/lib/msun/src/e_log2f.c \
-    upstream-freebsd/lib/msun/src/e_log.c \
-    upstream-freebsd/lib/msun/src/e_logf.c \
-    upstream-freebsd/lib/msun/src/e_pow.c \
-    upstream-freebsd/lib/msun/src/e_powf.c \
-    upstream-freebsd/lib/msun/src/e_remainder.c \
-    upstream-freebsd/lib/msun/src/e_remainderf.c \
-    upstream-freebsd/lib/msun/src/e_rem_pio2.c \
-    upstream-freebsd/lib/msun/src/e_rem_pio2f.c \
-    upstream-freebsd/lib/msun/src/e_scalb.c \
-    upstream-freebsd/lib/msun/src/e_scalbf.c \
-    upstream-freebsd/lib/msun/src/e_sinh.c \
-    upstream-freebsd/lib/msun/src/e_sinhf.c \
-    upstream-freebsd/lib/msun/src/e_sqrt.c \
-    upstream-freebsd/lib/msun/src/e_sqrtf.c \
-    upstream-freebsd/lib/msun/src/imprecise.c \
-    upstream-freebsd/lib/msun/src/k_cos.c \
-    upstream-freebsd/lib/msun/src/k_cosf.c \
-    upstream-freebsd/lib/msun/src/k_exp.c \
-    upstream-freebsd/lib/msun/src/k_expf.c \
-    upstream-freebsd/lib/msun/src/k_rem_pio2.c \
-    upstream-freebsd/lib/msun/src/k_sin.c \
-    upstream-freebsd/lib/msun/src/k_sinf.c \
-    upstream-freebsd/lib/msun/src/k_tan.c \
-    upstream-freebsd/lib/msun/src/k_tanf.c \
-    upstream-freebsd/lib/msun/src/s_asinh.c \
-    upstream-freebsd/lib/msun/src/s_asinhf.c \
-    upstream-freebsd/lib/msun/src/s_atan.c \
-    upstream-freebsd/lib/msun/src/s_atanf.c \
-    upstream-freebsd/lib/msun/src/s_carg.c \
-    upstream-freebsd/lib/msun/src/s_cargf.c \
-    upstream-freebsd/lib/msun/src/s_cargl.c \
-    upstream-freebsd/lib/msun/src/s_cbrt.c \
-    upstream-freebsd/lib/msun/src/s_cbrtf.c \
-    upstream-freebsd/lib/msun/src/s_ccosh.c \
-    upstream-freebsd/lib/msun/src/s_ccoshf.c \
-    upstream-freebsd/lib/msun/src/s_ceil.c \
-    upstream-freebsd/lib/msun/src/s_ceilf.c \
-    upstream-freebsd/lib/msun/src/s_cexp.c \
-    upstream-freebsd/lib/msun/src/s_cexpf.c \
-    upstream-freebsd/lib/msun/src/s_cimag.c \
-    upstream-freebsd/lib/msun/src/s_cimagf.c \
-    upstream-freebsd/lib/msun/src/s_cimagl.c \
-    upstream-freebsd/lib/msun/src/s_conj.c \
-    upstream-freebsd/lib/msun/src/s_conjf.c \
-    upstream-freebsd/lib/msun/src/s_conjl.c \
-    upstream-freebsd/lib/msun/src/s_copysign.c \
-    upstream-freebsd/lib/msun/src/s_copysignf.c \
-    upstream-freebsd/lib/msun/src/s_cos.c \
-    upstream-freebsd/lib/msun/src/s_cosf.c \
-    upstream-freebsd/lib/msun/src/s_cproj.c \
-    upstream-freebsd/lib/msun/src/s_cprojf.c \
-    upstream-freebsd/lib/msun/src/s_cprojl.c \
-    upstream-freebsd/lib/msun/src/s_creal.c \
-    upstream-freebsd/lib/msun/src/s_crealf.c \
-    upstream-freebsd/lib/msun/src/s_creall.c \
-    upstream-freebsd/lib/msun/src/s_csinh.c \
-    upstream-freebsd/lib/msun/src/s_csinhf.c \
-    upstream-freebsd/lib/msun/src/s_csqrt.c \
-    upstream-freebsd/lib/msun/src/s_csqrtf.c \
-    upstream-freebsd/lib/msun/src/s_csqrtl.c \
-    upstream-freebsd/lib/msun/src/s_ctanh.c \
-    upstream-freebsd/lib/msun/src/s_ctanhf.c \
-    upstream-freebsd/lib/msun/src/s_erf.c \
-    upstream-freebsd/lib/msun/src/s_erff.c \
-    upstream-freebsd/lib/msun/src/s_exp2.c \
-    upstream-freebsd/lib/msun/src/s_exp2f.c \
-    upstream-freebsd/lib/msun/src/s_expm1.c \
-    upstream-freebsd/lib/msun/src/s_expm1f.c \
-    upstream-freebsd/lib/msun/src/s_fdim.c \
-    upstream-freebsd/lib/msun/src/s_finite.c \
-    upstream-freebsd/lib/msun/src/s_finitef.c \
-    upstream-freebsd/lib/msun/src/s_floor.c \
-    upstream-freebsd/lib/msun/src/s_floorf.c \
-    upstream-freebsd/lib/msun/src/s_fma.c \
-    upstream-freebsd/lib/msun/src/s_fmaf.c \
-    upstream-freebsd/lib/msun/src/s_fmax.c \
-    upstream-freebsd/lib/msun/src/s_fmaxf.c \
-    upstream-freebsd/lib/msun/src/s_fmin.c \
-    upstream-freebsd/lib/msun/src/s_fminf.c \
-    upstream-freebsd/lib/msun/src/s_frexp.c \
-    upstream-freebsd/lib/msun/src/s_frexpf.c \
-    upstream-freebsd/lib/msun/src/s_ilogb.c \
-    upstream-freebsd/lib/msun/src/s_ilogbf.c \
-    upstream-freebsd/lib/msun/src/s_llrint.c \
-    upstream-freebsd/lib/msun/src/s_llrintf.c \
-    upstream-freebsd/lib/msun/src/s_llround.c \
-    upstream-freebsd/lib/msun/src/s_llroundf.c \
-    upstream-freebsd/lib/msun/src/s_log1p.c \
-    upstream-freebsd/lib/msun/src/s_log1pf.c \
-    upstream-freebsd/lib/msun/src/s_logb.c \
-    upstream-freebsd/lib/msun/src/s_logbf.c \
-    upstream-freebsd/lib/msun/src/s_lrint.c \
-    upstream-freebsd/lib/msun/src/s_lrintf.c \
-    upstream-freebsd/lib/msun/src/s_lround.c \
-    upstream-freebsd/lib/msun/src/s_lroundf.c \
-    upstream-freebsd/lib/msun/src/s_modf.c \
-    upstream-freebsd/lib/msun/src/s_modff.c \
-    upstream-freebsd/lib/msun/src/s_nan.c \
-    upstream-freebsd/lib/msun/src/s_nearbyint.c \
-    upstream-freebsd/lib/msun/src/s_nextafter.c \
-    upstream-freebsd/lib/msun/src/s_nextafterf.c \
-    upstream-freebsd/lib/msun/src/s_remquo.c \
-    upstream-freebsd/lib/msun/src/s_remquof.c \
-    upstream-freebsd/lib/msun/src/s_rint.c \
-    upstream-freebsd/lib/msun/src/s_rintf.c \
-    upstream-freebsd/lib/msun/src/s_round.c \
-    upstream-freebsd/lib/msun/src/s_roundf.c \
-    upstream-freebsd/lib/msun/src/s_scalbln.c \
-    upstream-freebsd/lib/msun/src/s_scalbn.c \
-    upstream-freebsd/lib/msun/src/s_scalbnf.c \
-    upstream-freebsd/lib/msun/src/s_signgam.c \
-    upstream-freebsd/lib/msun/src/s_significand.c \
-    upstream-freebsd/lib/msun/src/s_significandf.c \
-    upstream-freebsd/lib/msun/src/s_sin.c \
-    upstream-freebsd/lib/msun/src/s_sinf.c \
-    upstream-freebsd/lib/msun/src/s_tan.c \
-    upstream-freebsd/lib/msun/src/s_tanf.c \
-    upstream-freebsd/lib/msun/src/s_tanh.c \
-    upstream-freebsd/lib/msun/src/s_tanhf.c \
-    upstream-freebsd/lib/msun/src/s_tgammaf.c \
-    upstream-freebsd/lib/msun/src/s_trunc.c \
-    upstream-freebsd/lib/msun/src/s_truncf.c \
-    upstream-freebsd/lib/msun/src/w_cabs.c \
-    upstream-freebsd/lib/msun/src/w_cabsf.c \
-    upstream-freebsd/lib/msun/src/w_cabsl.c \
-    upstream-freebsd/lib/msun/src/w_drem.c \
-    upstream-freebsd/lib/msun/src/w_dremf.c \
-
-LOCAL_SRC_FILES_32 += \
-    fake_long_double.c \
-
-LOCAL_SRC_FILES_64 := \
-    upstream-freebsd/lib/msun/src/e_acosl.c \
-    upstream-freebsd/lib/msun/src/e_acoshl.c \
-    upstream-freebsd/lib/msun/src/e_asinl.c \
-    upstream-freebsd/lib/msun/src/e_atan2l.c \
-    upstream-freebsd/lib/msun/src/e_atanhl.c \
-    upstream-freebsd/lib/msun/src/e_fmodl.c \
-    upstream-freebsd/lib/msun/src/e_hypotl.c \
-    upstream-freebsd/lib/msun/src/e_lgammal.c \
-    upstream-freebsd/lib/msun/src/e_remainderl.c \
-    upstream-freebsd/lib/msun/src/e_sqrtl.c \
-    upstream-freebsd/lib/msun/src/s_asinhl.c \
-    upstream-freebsd/lib/msun/src/s_atanl.c \
-    upstream-freebsd/lib/msun/src/s_cbrtl.c \
-    upstream-freebsd/lib/msun/src/s_ceill.c \
-    upstream-freebsd/lib/msun/src/s_copysignl.c \
-    upstream-freebsd/lib/msun/src/e_coshl.c \
-    upstream-freebsd/lib/msun/src/s_cosl.c \
-    upstream-freebsd/lib/msun/src/s_floorl.c \
-    upstream-freebsd/lib/msun/src/s_fmal.c \
-    upstream-freebsd/lib/msun/src/s_fmaxl.c \
-    upstream-freebsd/lib/msun/src/s_fminl.c \
-    upstream-freebsd/lib/msun/src/s_modfl.c \
-    upstream-freebsd/lib/msun/src/s_frexpl.c \
-    upstream-freebsd/lib/msun/src/s_ilogbl.c \
-    upstream-freebsd/lib/msun/src/s_llrintl.c \
-    upstream-freebsd/lib/msun/src/s_llroundl.c \
-    upstream-freebsd/lib/msun/src/s_logbl.c \
-    upstream-freebsd/lib/msun/src/s_lrintl.c \
-    upstream-freebsd/lib/msun/src/s_lroundl.c \
-    upstream-freebsd/lib/msun/src/s_nextafterl.c \
-    upstream-freebsd/lib/msun/src/s_nexttoward.c \
-    upstream-freebsd/lib/msun/src/s_nexttowardf.c \
-    upstream-freebsd/lib/msun/src/s_remquol.c \
-    upstream-freebsd/lib/msun/src/s_rintl.c \
-    upstream-freebsd/lib/msun/src/s_roundl.c \
-    upstream-freebsd/lib/msun/src/s_scalbnl.c \
-    upstream-freebsd/lib/msun/src/e_sinhl.c \
-    upstream-freebsd/lib/msun/src/s_sinl.c \
-    upstream-freebsd/lib/msun/src/s_tanhl.c \
-    upstream-freebsd/lib/msun/src/s_tanl.c \
-    upstream-freebsd/lib/msun/src/s_truncl.c \
-
-LOCAL_SRC_FILES_64 += \
-    upstream-freebsd/lib/msun/ld128/invtrig.c \
-    upstream-freebsd/lib/msun/ld128/e_lgammal_r.c \
-    upstream-freebsd/lib/msun/ld128/k_cosl.c \
-    upstream-freebsd/lib/msun/ld128/k_sinl.c \
-    upstream-freebsd/lib/msun/ld128/k_tanl.c \
-    upstream-freebsd/lib/msun/ld128/s_erfl.c \
-    upstream-freebsd/lib/msun/ld128/s_exp2l.c \
-    upstream-freebsd/lib/msun/ld128/s_expl.c \
-    upstream-freebsd/lib/msun/ld128/s_logl.c \
-    upstream-freebsd/lib/msun/ld128/s_nanl.c \
-
-# TODO: this comes from from upstream's libc, not libm, but it's an
-# implementation detail that should have hidden visibility, so it needs
-# to be in whatever library the math code is in.
-LOCAL_SRC_FILES += \
-    digittoint.c  \
-
-# Functionality not in the BSDs.
-LOCAL_SRC_FILES += \
-    significandl.c \
-    sincos.c \
-
-# Modified versions of BSD code.
-LOCAL_SRC_FILES += \
-    signbit.c \
-
-# Home-grown stuff.
-LOCAL_SRC_FILES += \
-    fabs.cpp \
-
-# Arch specific optimizations.
-
-# -----------------------------------------------------------------------------
-# arm
-# -----------------------------------------------------------------------------
-LOCAL_SRC_FILES_arm += \
-    arm/fenv.c \
-
-# s_floor.S requires neon instructions.
-ifdef TARGET_2ND_ARCH
-arch_variant := $(TARGET_2ND_ARCH_VARIANT)
-else
-arch_variant := $(TARGET_ARCH_VARIANT)
-endif
-
-# Use the C version on armv7-a since it doesn't support neon instructions.
-ifneq ($(arch_variant),armv7-a)
-LOCAL_SRC_FILES_arm += \
-    arm/sqrt.S \
-    arm/floor.S \
-
-LOCAL_SRC_FILES_EXCLUDE_arm += \
-    upstream-freebsd/lib/msun/src/e_sqrt.c \
-    upstream-freebsd/lib/msun/src/e_sqrtf.c \
-    upstream-freebsd/lib/msun/src/s_floor.c \
-
-endif
-
-# -----------------------------------------------------------------------------
-# arm64
-# -----------------------------------------------------------------------------
-LOCAL_SRC_FILES_arm64 += \
-    arm64/ceil.S \
-    arm64/fenv.c \
-    arm64/fma.S \
-    arm64/floor.S \
-    arm64/lrint.S \
-    arm64/rint.S \
-    arm64/sqrt.S \
-    arm64/trunc.S \
-
-LOCAL_SRC_FILES_EXCLUDE_arm64 += \
-    upstream-freebsd/lib/msun/src/e_sqrt.c \
-    upstream-freebsd/lib/msun/src/e_sqrtf.c \
-    upstream-freebsd/lib/msun/src/s_ceil.c \
-    upstream-freebsd/lib/msun/src/s_ceilf.c \
-    upstream-freebsd/lib/msun/src/s_fma.c \
-    upstream-freebsd/lib/msun/src/s_fmaf.c \
-    upstream-freebsd/lib/msun/src/s_floor.c \
-    upstream-freebsd/lib/msun/src/s_floorf.c \
-    upstream-freebsd/lib/msun/src/s_llrint.c \
-    upstream-freebsd/lib/msun/src/s_llrintf.c \
-    upstream-freebsd/lib/msun/src/s_lrint.c \
-    upstream-freebsd/lib/msun/src/s_lrintf.c \
-    upstream-freebsd/lib/msun/src/s_rint.c \
-    upstream-freebsd/lib/msun/src/s_rintf.c \
-    upstream-freebsd/lib/msun/src/s_trunc.c \
-    upstream-freebsd/lib/msun/src/s_truncf.c \
-
-# -----------------------------------------------------------------------------
-# mips
-# -----------------------------------------------------------------------------
-libm_mips_arch_files := \
-    mips/fenv.c \
-
-LOCAL_SRC_FILES_mips += $(libm_mips_arch_files)
-LOCAL_SRC_FILES_mips64 += $(libm_mips_arch_files)
-
-# -----------------------------------------------------------------------------
-# x86
-# -----------------------------------------------------------------------------
-LOCAL_SRC_FILES_x86 += \
-    i387/fenv.c \
-    x86/sqrt.S \
-    x86/sqrtf.S \
-    x86/e_acos.S \
-    x86/e_asin.S \
-    x86/e_atan2.S \
-    x86/e_cosh.S \
-    x86/e_exp.S \
-    x86/e_hypot.S \
-    x86/e_log10.S \
-    x86/e_log.S \
-    x86/e_pow.S \
-    x86/e_sinh.S \
-    x86/libm_reduce_pi04l.S \
-    x86/libm_sincos_huge.S \
-    x86/libm_tancot_huge.S \
-    x86/lrint.S \
-    x86/lrintf.S \
-    x86/s_atan.S \
-    x86/s_cbrt.S \
-    x86/s_cos.S \
-    x86/s_expm1.S \
-    x86/s_log1p.S \
-    x86/s_sin.S \
-    x86/s_tanh.S \
-    x86/s_tan.S \
-
-LOCAL_SRC_FILES_EXCLUDE_x86 += \
-    upstream-freebsd/lib/msun/src/e_acos.c \
-    upstream-freebsd/lib/msun/src/e_asin.c \
-    upstream-freebsd/lib/msun/src/e_atan2.c \
-    upstream-freebsd/lib/msun/src/e_cosh.c \
-    upstream-freebsd/lib/msun/src/e_exp.c \
-    upstream-freebsd/lib/msun/src/e_hypot.c \
-    upstream-freebsd/lib/msun/src/e_log.c \
-    upstream-freebsd/lib/msun/src/e_log10.c \
-    upstream-freebsd/lib/msun/src/e_pow.c \
-    upstream-freebsd/lib/msun/src/e_sinh.c \
-    upstream-freebsd/lib/msun/src/e_sqrt.c \
-    upstream-freebsd/lib/msun/src/e_sqrtf.c \
-    upstream-freebsd/lib/msun/src/s_atan.c \
-    upstream-freebsd/lib/msun/src/s_cbrt.c \
-    upstream-freebsd/lib/msun/src/s_cos.c \
-    upstream-freebsd/lib/msun/src/s_expm1.c \
-    upstream-freebsd/lib/msun/src/s_log1p.c \
-    upstream-freebsd/lib/msun/src/s_lrint.c \
-    upstream-freebsd/lib/msun/src/s_lrintf.c \
-    upstream-freebsd/lib/msun/src/s_sin.c \
-    upstream-freebsd/lib/msun/src/s_tan.c \
-    upstream-freebsd/lib/msun/src/s_tanh.c \
-
-ifeq ($(ARCH_X86_HAVE_SSE4_1),true)
-LOCAL_SRC_FILES_x86 += \
-    x86/ceil.S \
-    x86/ceilf.S \
-    x86/floor.S \
-    x86/floorf.S \
-    x86/rint.S \
-    x86/rintf.S \
-    x86/trunc.S \
-    x86/truncf.S \
-
-LOCAL_SRC_FILES_EXCLUDE_x86 += \
-    upstream-freebsd/lib/msun/src/s_ceil.c \
-    upstream-freebsd/lib/msun/src/s_ceilf.c \
-    upstream-freebsd/lib/msun/src/s_floor.c \
-    upstream-freebsd/lib/msun/src/s_floorf.c \
-    upstream-freebsd/lib/msun/src/s_rint.c \
-    upstream-freebsd/lib/msun/src/s_rintf.c \
-    upstream-freebsd/lib/msun/src/s_trunc.c \
-    upstream-freebsd/lib/msun/src/s_truncf.c \
-
-endif
-
-# -----------------------------------------------------------------------------
-# x86_64
-# -----------------------------------------------------------------------------
-LOCAL_SRC_FILES_x86_64 += \
-    amd64/fenv.c \
-    x86_64/sqrt.S \
-    x86_64/sqrtf.S \
-    x86_64/e_acos.S \
-    x86_64/e_asin.S \
-    x86_64/e_atan2.S \
-    x86_64/e_cosh.S \
-    x86_64/e_exp.S \
-    x86_64/e_hypot.S \
-    x86_64/e_log10.S \
-    x86_64/e_log.S \
-    x86_64/e_pow.S \
-    x86_64/e_sinh.S \
-    x86_64/lrint.S \
-    x86_64/lrintf.S \
-    x86_64/s_atan.S \
-    x86_64/s_cbrt.S \
-    x86_64/s_cos.S \
-    x86_64/s_expm1.S \
-    x86_64/s_log1p.S \
-    x86_64/s_sin.S \
-    x86_64/s_tanh.S \
-    x86_64/s_tan.S \
-
-LOCAL_SRC_FILES_EXCLUDE_x86_64 += \
-    upstream-freebsd/lib/msun/src/e_acos.c \
-    upstream-freebsd/lib/msun/src/e_asin.c \
-    upstream-freebsd/lib/msun/src/e_atan2.c \
-    upstream-freebsd/lib/msun/src/e_cosh.c \
-    upstream-freebsd/lib/msun/src/e_exp.c \
-    upstream-freebsd/lib/msun/src/e_hypot.c \
-    upstream-freebsd/lib/msun/src/e_log.c \
-    upstream-freebsd/lib/msun/src/e_log10.c \
-    upstream-freebsd/lib/msun/src/e_pow.c \
-    upstream-freebsd/lib/msun/src/e_sinh.c \
-    upstream-freebsd/lib/msun/src/e_sqrt.c \
-    upstream-freebsd/lib/msun/src/e_sqrtf.c \
-    upstream-freebsd/lib/msun/src/s_atan.c \
-    upstream-freebsd/lib/msun/src/s_cbrt.c \
-    upstream-freebsd/lib/msun/src/s_cos.c \
-    upstream-freebsd/lib/msun/src/s_expm1.c \
-    upstream-freebsd/lib/msun/src/s_log1p.c \
-    upstream-freebsd/lib/msun/src/s_llrint.c \
-    upstream-freebsd/lib/msun/src/s_llrintf.c \
-    upstream-freebsd/lib/msun/src/s_lrint.c \
-    upstream-freebsd/lib/msun/src/s_lrintf.c \
-    upstream-freebsd/lib/msun/src/s_sin.c \
-    upstream-freebsd/lib/msun/src/s_tan.c \
-    upstream-freebsd/lib/msun/src/s_tanh.c \
-
-ifeq ($(ARCH_X86_HAVE_SSE4_1),true)
-LOCAL_SRC_FILES_x86_64 += \
-    x86_64/ceil.S \
-    x86_64/ceilf.S \
-    x86_64/floor.S \
-    x86_64/floorf.S \
-    x86_64/rint.S \
-    x86_64/rintf.S \
-    x86_64/trunc.S \
-    x86_64/truncf.S \
-
-LOCAL_SRC_FILES_EXCLUDE_x86_64 += \
-    upstream-freebsd/lib/msun/src/s_ceil.c \
-    upstream-freebsd/lib/msun/src/s_ceilf.c \
-    upstream-freebsd/lib/msun/src/s_floor.c \
-    upstream-freebsd/lib/msun/src/s_floorf.c \
-    upstream-freebsd/lib/msun/src/s_rint.c \
-    upstream-freebsd/lib/msun/src/s_rintf.c \
-    upstream-freebsd/lib/msun/src/s_trunc.c \
-    upstream-freebsd/lib/msun/src/s_truncf.c \
-
-endif
-
-LOCAL_C_INCLUDES_x86 += $(LOCAL_PATH)/i387
-
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/upstream-freebsd/lib/msun/src/
-LOCAL_C_INCLUDES_64 += $(LOCAL_PATH)/upstream-freebsd/lib/msun/ld128/
-
-LOCAL_CLANG := $(libm_clang)
-LOCAL_ARM_MODE := arm
-LOCAL_CFLAGS := \
-    -D__BIONIC_NO_MATH_INLINES \
-    -DFLT_EVAL_METHOD=0 \
-    -include $(LOCAL_PATH)/freebsd-compat.h \
-    -Werror \
-    -Wno-missing-braces \
-    -Wno-parentheses \
-    -Wno-sign-compare \
-    -Wno-uninitialized \
-    -Wno-unknown-pragmas \
-    -fvisibility=hidden \
-
-LOCAL_ASFLAGS := \
-    -Ibionic/libc \
-
-# Workaround the GCC "(long)fn -> lfn" optimization bug which will result in
-# self recursions for lrint, lrintf, and lrintl.
-# BUG: 14225968
-LOCAL_CFLAGS += \
-    -fno-builtin-rint \
-    -fno-builtin-rintf \
-    -fno-builtin-rintl \
-
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-LOCAL_SANITIZE := never
-include $(BUILD_STATIC_LIBRARY)
-
-# -----------------------------------------------------------------------------
-# libm.so
-# -----------------------------------------------------------------------------
-include $(CLEAR_VARS)
-
-LOCAL_ADDITIONAL_DEPENDENCIES := \
-    $(LOCAL_PATH)/libm.arm.map \
-    $(LOCAL_PATH)/libm.arm64.map \
-    $(LOCAL_PATH)/libm.mips.map \
-    $(LOCAL_PATH)/libm.mips64.map \
-    $(LOCAL_PATH)/libm.x86.map \
-    $(LOCAL_PATH)/libm.x86_64.map \
-
-# TODO: This is to work around b/24465209. Remove after root cause is fixed
-LOCAL_LDFLAGS_arm := -Wl,--hash-style=both
-LOCAL_LDFLAGS_x86 := -Wl,--hash-style=both
-
-LOCAL_LDFLAGS_arm    += -Wl,--version-script,$(LOCAL_PATH)/libm.arm.map
-LOCAL_LDFLAGS_arm64  += -Wl,--version-script,$(LOCAL_PATH)/libm.arm64.map
-LOCAL_LDFLAGS_mips   += -Wl,--version-script,$(LOCAL_PATH)/libm.mips.map
-LOCAL_LDFLAGS_mips64 += -Wl,--version-script,$(LOCAL_PATH)/libm.mips64.map
-LOCAL_LDFLAGS_x86    += -Wl,--version-script,$(LOCAL_PATH)/libm.x86.map
-LOCAL_LDFLAGS_x86_64 += -Wl,--version-script,$(LOCAL_PATH)/libm.x86_64.map
-
-
-LOCAL_MODULE := libm
-LOCAL_CLANG := $(libm_clang)
-LOCAL_SYSTEM_SHARED_LIBRARIES := libc
-LOCAL_WHOLE_STATIC_LIBRARIES := libm
-
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-LOCAL_SANITIZE := never
-
-LOCAL_CXX_STL := none
-
-# We'd really like to do this for all architectures, but since this wasn't done
-# before, these symbols must continue to be exported on LP32 for binary
-# compatibility.
-LOCAL_LDFLAGS_64 := -Wl,--exclude-libs,libgcc.a
-
-include $(BUILD_SHARED_LIBRARY)
-endif
diff --git a/libm/NOTICE b/libm/NOTICE
index c254c08..085c210 100644
--- a/libm/NOTICE
+++ b/libm/NOTICE
@@ -263,38 +263,6 @@
 
 -------------------------------------------------------------------
 
-Copyright (c) 1990 The Regents of the University of California.
-All rights reserved.
-
-This code is derived from software contributed to Berkeley by
-William Jolitz.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. 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.
-4. Neither the name of the University nor the names of its contributors
-   may be used to endorse or promote products derived from this software
-   without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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) 1992, 1993
    The Regents of the University of California.  All rights reserved.
 
@@ -328,32 +296,6 @@
 
 -------------------------------------------------------------------
 
-Copyright (c) 2001-2011 The FreeBSD 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:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. 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 AUTHOR 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 AUTHOR 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) 2003 Dag-Erling Smørgrav
 All rights reserved.
 
@@ -782,6 +724,35 @@
 
 -------------------------------------------------------------------
 
+Copyright (c) 2007 The NetBSD Foundation, Inc.
+All rights reserved.
+
+This code is derived from software written by Stephen L. Moshier.
+It is redistributed by the NetBSD Foundation by permission of the author.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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) 2007-2008 David Schultz <das@FreeBSD.ORG>
 All rights reserved.
 
@@ -888,32 +859,6 @@
 
 -------------------------------------------------------------------
 
-Copyright (c) 2010 The NetBSD Foundation, Inc.
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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) 2011 David Schultz
 All rights reserved.
 
@@ -1079,19 +1024,28 @@
 
 -------------------------------------------------------------------
 
-Copyright 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.
+Copyright (c) 2014, Intel Corporation
+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.
+    * Neither the name of Intel Corporation nor the names of its contributors
+    * may be used to endorse or promote products derived from this software
+    * without specific prior written permission.
+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.
 
 -------------------------------------------------------------------
 
diff --git a/libm/amd64/fenv.c b/libm/amd64/fenv.c
index 4b24ff9..9edaf88 100755
--- a/libm/amd64/fenv.c
+++ b/libm/amd64/fenv.c
@@ -28,7 +28,14 @@
  */
 
 #include <fenv.h>
-#include <machine/fpu.h>
+
+/*
+ * The i387 defaults to Intel extended precision mode and round to nearest,
+ * with all exceptions masked.
+ */
+#define	__INITIAL_NPXCW__	0x037f
+#define __INITIAL_MXCSR__ 	0x1f80
+#define __INITIAL_MXCSR_MASK__	0xffbf
 
 #define SSE_MASK_SHIFT 7
 
diff --git a/libm/arm64/ceil.S b/libm/arm64/ceil.S
index 006c988..7217d57 100644
--- a/libm/arm64/ceil.S
+++ b/libm/arm64/ceil.S
@@ -1,11 +1,11 @@
 /*
- * Copyright 2015, The Android Open Source Project
+ * 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
+ *      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,
diff --git a/libm/arm64/floor.S b/libm/arm64/floor.S
index 2d792e5..ca106bd 100644
--- a/libm/arm64/floor.S
+++ b/libm/arm64/floor.S
@@ -1,11 +1,11 @@
 /*
- * Copyright 2015, The Android Open Source Project
+ * 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
+ *      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,
diff --git a/libm/arm64/fma.S b/libm/arm64/fma.S
index e64e807..1a8a158 100644
--- a/libm/arm64/fma.S
+++ b/libm/arm64/fma.S
@@ -1,11 +1,11 @@
 /*
- * Copyright 2015, The Android Open Source Project
+ * 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
+ *      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,
diff --git a/libm/arm64/lrint.S b/libm/arm64/lrint.S
index d642759..5f95ae8 100644
--- a/libm/arm64/lrint.S
+++ b/libm/arm64/lrint.S
@@ -1,11 +1,11 @@
 /*
- * Copyright 2015, The Android Open Source Project
+ * 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
+ *      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,
diff --git a/libm/arm64/rint.S b/libm/arm64/rint.S
index 0820c22..bf49f5b 100644
--- a/libm/arm64/rint.S
+++ b/libm/arm64/rint.S
@@ -1,11 +1,11 @@
 /*
- * Copyright 2015, The Android Open Source Project
+ * 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
+ *      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,
diff --git a/libm/arm64/sqrt.S b/libm/arm64/sqrt.S
index fe0020b..3a58ef3 100644
--- a/libm/arm64/sqrt.S
+++ b/libm/arm64/sqrt.S
@@ -1,11 +1,11 @@
 /*
- * Copyright 2015, The Android Open Source Project
+ * 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
+ *      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,
diff --git a/libm/arm64/trunc.S b/libm/arm64/trunc.S
index 329c08d..aa0d4bd 100644
--- a/libm/arm64/trunc.S
+++ b/libm/arm64/trunc.S
@@ -1,11 +1,11 @@
 /*
- * Copyright 2015, The Android Open Source Project
+ * 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
+ *      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,
diff --git a/libm/i387/fenv.c b/libm/i387/fenv.c
index f64f8dc..09b4386 100644
--- a/libm/i387/fenv.c
+++ b/libm/i387/fenv.c
@@ -28,12 +28,31 @@
 
 #include <sys/cdefs.h>
 #include <sys/types.h>
-#include "npx.h"
 #include "fenv.h"
 
 #define ROUND_MASK   (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO)
 
 /*
+ * The hardware default control word for i387's and later coprocessors is
+ * 0x37F, giving:
+ *
+ *	round to nearest
+ *	64-bit precision
+ *	all exceptions masked.
+ *
+ * We modify the affine mode bit and precision bits in this to give:
+ *
+ *	affine mode for 287's (if they work at all) (1 in bitfield 1<<12)
+ *	53-bit precision (2 in bitfield 3<<8)
+ *
+ * 64-bit precision often gives bad results with high level languages
+ * because it makes the results of calculations depend on whether
+ * intermediate values are stored in memory or in FPU registers.
+ */
+#define	__INITIAL_NPXCW__	0x127F
+#define	__INITIAL_MXCSR__	0x1F80
+
+/*
  * As compared to the x87 control word, the SSE unit's control word
  * has the rounding control bits offset by 3 and the exception mask
  * bits offset by 7.
@@ -51,18 +70,18 @@
     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff } /*__other*/
 };
 
-#define __fldcw(__cw)           __asm __volatile("fldcw %0" : : "m" (__cw))
-#define __fldenv(__env)         __asm __volatile("fldenv %0" : : "m" (__env))
-#define __fldenvx(__env)        __asm __volatile("fldenv %0" : : "m" (__env)  \
+#define __fldcw(__cw)           __asm volatile("fldcw %0" : : "m" (__cw))
+#define __fldenv(__env)         __asm volatile("fldenv %0" : : "m" (__env))
+#define __fldenvx(__env)        __asm volatile("fldenv %0" : : "m" (__env)  \
                                 : "st", "st(1)", "st(2)", "st(3)", "st(4)",   \
                                 "st(5)", "st(6)", "st(7)")
-#define __fnclex()              __asm __volatile("fnclex")
-#define __fnstenv(__env)        __asm __volatile("fnstenv %0" : "=m" (*(__env)))
-#define __fnstcw(__cw)          __asm __volatile("fnstcw %0" : "=m" (*(__cw)))
-#define __fnstsw(__sw)          __asm __volatile("fnstsw %0" : "=am" (*(__sw)))
-#define __fwait()               __asm __volatile("fwait")
-#define __ldmxcsr(__csr)        __asm __volatile("ldmxcsr %0" : : "m" (__csr))
-#define __stmxcsr(__csr)        __asm __volatile("stmxcsr %0" : "=m" (*(__csr)))
+#define __fnclex()              __asm volatile("fnclex")
+#define __fnstenv(__env)        __asm volatile("fnstenv %0" : "=m" (*(__env)))
+#define __fnstcw(__cw)          __asm volatile("fnstcw %0" : "=m" (*(__cw)))
+#define __fnstsw(__sw)          __asm volatile("fnstsw %0" : "=am" (*(__sw)))
+#define __fwait()               __asm volatile("fwait")
+#define __ldmxcsr(__csr)        __asm volatile("ldmxcsr %0" : : "m" (__csr))
+#define __stmxcsr(__csr)        __asm volatile("stmxcsr %0" : "=m" (*(__csr)))
 
 /* After testing for SSE support once, we cache the result in __has_sse. */
 enum __sse_support { __SSE_YES, __SSE_NO, __SSE_UNK };
@@ -81,9 +100,9 @@
 #endif
 
 #ifndef __SSE__
-#define getfl(x)    __asm __volatile("pushfl\n\tpopl %0" : "=mr" (*(x)))
-#define setfl(x)    __asm __volatile("pushl %0\n\tpopfl" : : "g" (x))
-#define cpuid_dx(x) __asm __volatile("pushl %%ebx\n\tmovl $1, %%eax\n\t"  \
+#define getfl(x)    __asm volatile("pushfl\n\tpopl %0" : "=mr" (*(x)))
+#define setfl(x)    __asm volatile("pushl %0\n\tpopfl" : : "g" (x))
+#define cpuid_dx(x) __asm volatile("pushl %%ebx\n\tmovl $1, %%eax\n\t"  \
                     "cpuid\n\tpopl %%ebx"          \
                     : "=d" (*(x)) : : "eax", "ecx")
 
diff --git a/libm/i387/npx.h b/libm/i387/npx.h
deleted file mode 100644
index 38c2add..0000000
--- a/libm/i387/npx.h
+++ /dev/null
@@ -1,160 +0,0 @@
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- *
- *	from: @(#)npx.h	5.3 (Berkeley) 1/18/91
- * $FreeBSD: src/sys/i386/include/npx.h,v 1.29.2.1 2006/07/01 00:57:55 davidxu Exp $
- */
-
-/*
- * 287/387 NPX Coprocessor Data Structures and Constants
- * W. Jolitz 1/90
- */
-
-#ifndef _MACHINE_NPX_H_
-#define	_MACHINE_NPX_H_
-
-/* Environment information of floating point unit */
-struct env87 {
-	long	en_cw;		/* control word (16bits) */
-	long	en_sw;		/* status word (16bits) */
-	long	en_tw;		/* tag word (16bits) */
-	long	en_fip;		/* floating point instruction pointer */
-	u_short	en_fcs;		/* floating code segment selector */
-	u_short	en_opcode;	/* opcode last executed (11 bits ) */
-	long	en_foo;		/* floating operand offset */
-	long	en_fos;		/* floating operand segment selector */
-};
-
-/* Contents of each floating point accumulator */
-struct fpacc87 {
-#ifdef dontdef /* too unportable */
-	u_long	fp_mantlo;	/* mantissa low (31:0) */
-	u_long	fp_manthi;	/* mantissa high (63:32) */
-	int	fp_exp:15;	/* exponent */
-	int	fp_sgn:1;	/* mantissa sign */
-#else
-	u_char	fp_bytes[10];
-#endif
-};
-
-/* Floating point context */
-struct save87 {
-	struct	env87 sv_env;	/* floating point control/status */
-	struct	fpacc87	sv_ac[8];	/* accumulator contents, 0-7 */
-	u_char	sv_pad0[4];	/* padding for (now unused) saved status word */
-	/*
-	 * Bogus padding for emulators.  Emulators should use their own
-	 * struct and arrange to store into this struct (ending here)
-	 * before it is inspected for ptracing or for core dumps.  Some
-	 * emulators overwrite the whole struct.  We have no good way of
-	 * knowing how much padding to leave.  Leave just enough for the
-	 * GPL emulator's i387_union (176 bytes total).
-	 */
-	u_char	sv_pad[64];	/* padding; used by emulators */
-};
-
-struct  envxmm {
-	u_int16_t	en_cw;		/* control word (16bits) */
-	u_int16_t	en_sw;		/* status word (16bits) */
-	u_int16_t	en_tw;		/* tag word (16bits) */
-	u_int16_t	en_opcode;	/* opcode last executed (11 bits ) */
-	u_int32_t	en_fip;		/* floating point instruction pointer */
-	u_int16_t	en_fcs;		/* floating code segment selector */
-	u_int16_t	en_pad0;	/* padding */
-	u_int32_t	en_foo;		/* floating operand offset */
-	u_int16_t	en_fos;		/* floating operand segment selector */
-	u_int16_t	en_pad1;	/* padding */
-	u_int32_t	en_mxcsr;	/* SSE sontorol/status register */
-	u_int32_t	en_mxcsr_mask;	/* valid bits in mxcsr */
-};
-
-/* Contents of each SSE extended accumulator */
-struct  xmmacc {
-	u_char	xmm_bytes[16];
-};
-
-struct  savexmm {
-	struct	envxmm	sv_env;
-	struct {
-		struct fpacc87	fp_acc;
-		u_char		fp_pad[6];      /* padding */
-	} sv_fp[8];
-	struct xmmacc	sv_xmm[8];
-	u_char sv_pad[224];
-} __aligned(16);
-
-union	savefpu {
-	struct	save87	sv_87;
-	struct	savexmm	sv_xmm;
-};
-
-/*
- * The hardware default control word for i387's and later coprocessors is
- * 0x37F, giving:
- *
- *	round to nearest
- *	64-bit precision
- *	all exceptions masked.
- *
- * We modify the affine mode bit and precision bits in this to give:
- *
- *	affine mode for 287's (if they work at all) (1 in bitfield 1<<12)
- *	53-bit precision (2 in bitfield 3<<8)
- *
- * 64-bit precision often gives bad results with high level languages
- * because it makes the results of calculations depend on whether
- * intermediate values are stored in memory or in FPU registers.
- */
-#define	__INITIAL_NPXCW__	0x127F
-#define	__INITIAL_MXCSR__	0x1F80
-
-#ifdef _KERNEL
-
-#define	IO_NPX		0x0F0		/* Numeric Coprocessor */
-#define	IO_NPXSIZE	16		/* 80387/80487 NPX registers */
-
-#define	IRQ_NPX		13
-
-/* full reset on some systems, NOP on others */
-#define npx_full_reset() outb(IO_NPX + 1, 0)
-
-int	npxdna(void);
-void	npxdrop(void);
-void	npxexit(struct thread *td);
-int	npxformat(void);
-int	npxgetregs(struct thread *td, union savefpu *addr);
-void	npxinit(u_short control);
-void	npxsave(union savefpu *addr);
-void	npxsetregs(struct thread *td, union savefpu *addr);
-int	npxtrap(void);
-#endif
-
-#endif /* !_MACHINE_NPX_H_ */
diff --git a/libm/include/amd64/machine/fpu.h b/libm/include/amd64/machine/fpu.h
deleted file mode 100644
index bda8f05..0000000
--- a/libm/include/amd64/machine/fpu.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*	$OpenBSD: fpu.h,v 1.9 2011/03/23 16:54:34 pirofti Exp $	*/
-/*	$NetBSD: fpu.h,v 1.1 2003/04/26 18:39:40 fvdl Exp $	*/
-
-#ifndef	_MACHINE_FPU_H_
-#define	_MACHINE_FPU_H_
-
-#include <sys/types.h>
-
-/*
- * amd64 only uses the extended save/restore format used
- * by fxsave/fsrestore, to always deal with the SSE registers,
- * which are part of the ABI to pass floating point values.
- * Must be stored in memory on a 16-byte boundary.
- */
-
-struct fxsave64 {
-	u_int16_t  fx_fcw;
-	u_int16_t  fx_fsw;
-	u_int8_t   fx_ftw;
-	u_int8_t   fx_unused1;
-	u_int16_t  fx_fop;
-	u_int64_t  fx_rip;
-	u_int64_t  fx_rdp;
-	u_int32_t  fx_mxcsr;
-	u_int32_t  fx_mxcsr_mask;
-	u_int64_t  fx_st[8][2];   /* 8 normal FP regs */
-	u_int64_t  fx_xmm[16][2]; /* 16 SSE2 registers */
-	u_int8_t   fx_unused3[96];
-} __packed;
-
-struct savefpu {
-	struct fxsave64 fp_fxsave;	/* see above */
-	u_int16_t fp_ex_sw;		/* saved status from last exception */
-	u_int16_t fp_ex_tw;		/* saved tag from last exception */
-};
-
-/*
- * The i387 defaults to Intel extended precision mode and round to nearest,
- * with all exceptions masked.
- */
-#define	__INITIAL_NPXCW__	0x037f
-#define __INITIAL_MXCSR__ 	0x1f80
-#define __INITIAL_MXCSR_MASK__	0xffbf
-
-#ifdef _KERNEL
-/*
- * XXX
- */
-struct trapframe;
-struct cpu_info;
-
-extern uint32_t	fpu_mxcsr_mask;
-
-void fpuinit(struct cpu_info *);
-void fpudrop(void);
-void fpudiscard(struct proc *);
-void fputrap(struct trapframe *);
-void fpusave_proc(struct proc *, int);
-void fpusave_cpu(struct cpu_info *, int);
-void fpu_kernel_enter(void);
-void fpu_kernel_exit(void);
-
-#endif
-
-#endif /* _MACHINE_FPU_H_ */
diff --git a/libm/include/complex.h b/libm/include/complex.h
deleted file mode 100644
index ff6b166..0000000
--- a/libm/include/complex.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/*-
- * Copyright (c) 2001-2011 The FreeBSD 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:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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 AUTHOR 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 AUTHOR 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.
- *
- * $FreeBSD$
- */
-
-#ifndef _COMPLEX_H
-#define	_COMPLEX_H
-
-#include <sys/cdefs.h>
-
-#ifdef __GNUC__
-#if __STDC_VERSION__ < 199901
-#define	_Complex	__complex__
-#endif
-#define	_Complex_I	((float _Complex)1.0i)
-#endif
-
-#ifdef __generic
-_Static_assert(__generic(_Complex_I, float _Complex, 1, 0),
-    "_Complex_I must be of type float _Complex");
-#endif
-
-#define	complex		_Complex
-#define	I		_Complex_I
-
-#if __ISO_C_VISIBLE >= 2011
-#ifdef __clang__
-#define	CMPLX(x, y)	((double complex){ x, y })
-#define	CMPLXF(x, y)	((float complex){ x, y })
-#define	CMPLXL(x, y)	((long double complex){ x, y })
-#elif __GNUC_PREREQ__(4, 7)
-#define	CMPLX(x, y)	__builtin_complex((double)(x), (double)(y))
-#define	CMPLXF(x, y)	__builtin_complex((float)(x), (float)(y))
-#define	CMPLXL(x, y)	__builtin_complex((long double)(x), (long double)(y))
-#endif
-#endif /* __ISO_C_VISIBLE >= 2011 */
-
-__BEGIN_DECLS
-#pragma GCC visibility push(default)
-
-double		cabs(double complex);
-float		cabsf(float complex);
-long double	cabsl(long double complex);
-double complex	cacos(double complex);
-float complex	cacosf(float complex);
-double complex	cacosh(double complex);
-float complex	cacoshf(float complex);
-double		carg(double complex);
-float		cargf(float complex);
-long double	cargl(long double complex);
-double complex	casin(double complex);
-float complex	casinf(float complex);
-double complex	casinh(double complex);
-float complex	casinhf(float complex);
-double complex	catan(double complex);
-float complex	catanf(float complex);
-double complex	catanh(double complex);
-float complex	catanhf(float complex);
-double complex	ccos(double complex);
-float complex	ccosf(float complex);
-double complex	ccosh(double complex);
-float complex	ccoshf(float complex);
-double complex	cexp(double complex);
-float complex	cexpf(float complex);
-double		cimag(double complex) __pure2;
-float		cimagf(float complex) __pure2;
-long double	cimagl(long double complex) __pure2;
-double complex	conj(double complex) __pure2;
-float complex	conjf(float complex) __pure2;
-long double complex
-		conjl(long double complex) __pure2;
-float complex	cprojf(float complex) __pure2;
-double complex	cproj(double complex) __pure2;
-long double complex
-		cprojl(long double complex) __pure2;
-double		creal(double complex) __pure2;
-float		crealf(float complex) __pure2;
-long double	creall(long double complex) __pure2;
-double complex	csin(double complex);
-float complex	csinf(float complex);
-double complex	csinh(double complex);
-float complex	csinhf(float complex);
-double complex	csqrt(double complex);
-float complex	csqrtf(float complex);
-long double complex
-		csqrtl(long double complex);
-double complex	ctan(double complex);
-float complex	ctanf(float complex);
-double complex	ctanh(double complex);
-float complex	ctanhf(float complex);
-
-#pragma GCC visibility pop
-__END_DECLS
-
-#endif /* _COMPLEX_H */
diff --git a/libm/include/fenv.h b/libm/include/fenv.h
deleted file mode 100644
index 73ecc80..0000000
--- a/libm/include/fenv.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*  $OpenBSD: fenv.h,v 1.2 2011/05/25 21:46:49 martynas Exp $ */
-/*  $NetBSD: fenv.h,v 1.2.4.1 2011/02/08 16:18:55 bouyer Exp $  */
-
-/*
- * Copyright (c) 2010 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
- */
-
-#ifndef _FENV_H_
-#define _FENV_H_
-
-#include <sys/cdefs.h>
-#include <machine/fenv.h>
-
-__BEGIN_DECLS
-#pragma GCC visibility push(default)
-
-int feclearexcept(int);
-int fegetexceptflag(fexcept_t *, int);
-int feraiseexcept(int);
-int fesetexceptflag(const fexcept_t *, int);
-int fetestexcept(int);
-
-int fegetround(void);
-int fesetround(int);
-
-int fegetenv(fenv_t *);
-int feholdexcept(fenv_t *);
-int fesetenv(const fenv_t *);
-int feupdateenv(const fenv_t *);
-
-int feenableexcept(int);
-int fedisableexcept(int);
-int fegetexcept(void);
-
-/*
- * The following constant represents the default floating-point environment
- * (that is, the one installed at program startup) and has type pointer to
- * const-qualified fenv_t.
- *
- * It can be used as an argument to the functions that manage the floating-point
- * environment, namely fesetenv() and feupdateenv().
- */
-extern const fenv_t __fe_dfl_env;
-#define FE_DFL_ENV  (&__fe_dfl_env)
-
-#pragma GCC visibility pop
-__END_DECLS
-
-#endif  /* ! _FENV_H_ */
diff --git a/libm/include/math.h b/libm/include/math.h
deleted file mode 100644
index ce8e3b2..0000000
--- a/libm/include/math.h
+++ /dev/null
@@ -1,434 +0,0 @@
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunPro, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice
- * is preserved.
- * ====================================================
- */
-
-/*
- * from: @(#)fdlibm.h 5.1 93/09/24
- * $FreeBSD$
- */
-
-#ifndef _MATH_H_
-#define _MATH_H_
-
-#include <sys/cdefs.h>
-#include <limits.h>
-
-#if !defined(__BIONIC_NO_MATH_INLINES)
-#define __BIONIC_MATH_INLINE(__def) extern __inline__ __always_inline __attribute__((gnu_inline)) __attribute__((__artificial__)) __def
-#else
-#define __BIONIC_MATH_INLINE(__def)
-#endif
-
-__BEGIN_DECLS
-#pragma GCC visibility push(default)
-
-#define HUGE_VAL	__builtin_huge_val()
-
-#if __ISO_C_VISIBLE >= 1999
-#define FP_ILOGB0	(-INT_MAX)
-#define FP_ILOGBNAN	INT_MAX
-
-#define HUGE_VALF	__builtin_huge_valf()
-#define HUGE_VALL	__builtin_huge_vall()
-#define INFINITY	__builtin_inff()
-#define NAN		__builtin_nanf("")
-
-#define MATH_ERRNO	1
-#define MATH_ERREXCEPT	2
-#define math_errhandling	MATH_ERREXCEPT
-
-#if defined(__FP_FAST_FMA)
-#define FP_FAST_FMA 1
-#endif
-#if defined(__FP_FAST_FMAF)
-#define FP_FAST_FMAF 1
-#endif
-#if defined(__FP_FAST_FMAL)
-#define FP_FAST_FMAL 1
-#endif
-
-/* Symbolic constants to classify floating point numbers. */
-#define FP_INFINITE	0x01
-#define FP_NAN		0x02
-#define FP_NORMAL	0x04
-#define FP_SUBNORMAL	0x08
-#define FP_ZERO		0x10
-#define fpclassify(x) \
-    __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)
-
-#define isfinite(x) __builtin_isfinite(x)
-#define isinf(x) __builtin_isinf(x)
-#define isnan(x) __builtin_isnan(x)
-#define isnormal(x) __builtin_isnormal(x)
-
-#define isgreater(x, y) __builtin_isgreater((x), (y))
-#define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y))
-#define isless(x, y) __builtin_isless((x), (y))
-#define islessequal(x, y) __builtin_islessequal((x), (y))
-#define islessgreater(x, y) __builtin_islessgreater((x), (y))
-#define isunordered(x, y) __builtin_isunordered((x), (y))
-
-#define signbit(x) \
-    ((sizeof(x) == sizeof(float)) ? __builtin_signbitf(x) \
-    : (sizeof(x) == sizeof(double)) ? __builtin_signbit(x) \
-    : __builtin_signbitl(x))
-
-typedef double __double_t;
-typedef __double_t double_t;
-typedef float __float_t;
-typedef __float_t float_t;
-#endif /* __ISO_C_VISIBLE >= 1999 */
-
-/*
- * XOPEN/SVID
- */
-#if __BSD_VISIBLE || __XSI_VISIBLE
-#define	M_E		2.7182818284590452354	/* e */
-#define	M_LOG2E		1.4426950408889634074	/* log 2e */
-#define	M_LOG10E	0.43429448190325182765	/* log 10e */
-#define	M_LN2		0.69314718055994530942	/* log e2 */
-#define	M_LN10		2.30258509299404568402	/* log e10 */
-#define	M_PI		3.14159265358979323846	/* pi */
-#define	M_PI_2		1.57079632679489661923	/* pi/2 */
-#define	M_PI_4		0.78539816339744830962	/* pi/4 */
-#define	M_1_PI		0.31830988618379067154	/* 1/pi */
-#define	M_2_PI		0.63661977236758134308	/* 2/pi */
-#define	M_2_SQRTPI	1.12837916709551257390	/* 2/sqrt(pi) */
-#define	M_SQRT2		1.41421356237309504880	/* sqrt(2) */
-#define	M_SQRT1_2	0.70710678118654752440	/* 1/sqrt(2) */
-
-#define	MAXFLOAT	((float)3.40282346638528860e+38)
-extern int signgam;
-#endif /* __BSD_VISIBLE || __XSI_VISIBLE */
-
-#if __BSD_VISIBLE
-#if 0
-/* Old value from 4.4BSD-Lite math.h; this is probably better. */
-#define	HUGE		HUGE_VAL
-#else
-#define	HUGE		MAXFLOAT
-#endif
-#endif /* __BSD_VISIBLE */
-
-/*
- * Most of these functions depend on the rounding mode and have the side
- * effect of raising floating-point exceptions, so they are not declared
- * as __pure2.  In C99, FENV_ACCESS affects the purity of these functions.
- */
-
-/*
- * ANSI/POSIX
- */
-int	__fpclassifyd(double) __pure2;
-int	__fpclassifyf(float) __pure2;
-int	__fpclassifyl(long double) __pure2;
-int	__isfinitef(float) __pure2;
-int	__isfinite(double) __pure2;
-int	__isfinitel(long double) __pure2;
-int	__isinff(float) __pure2;
-int	__isinfl(long double) __pure2;
-int	__isnanf(float) __pure2;
-int	__isnanl(long double) __pure2;
-int	__isnormalf(float) __pure2;
-int	__isnormal(double) __pure2;
-int	__isnormall(long double) __pure2;
-int	__signbit(double) __pure2;
-int	__signbitf(float) __pure2;
-int	__signbitl(long double) __pure2;
-
-double	acos(double);
-double	asin(double);
-double	atan(double);
-double	atan2(double, double);
-double	cos(double);
-double	sin(double);
-double	tan(double);
-
-double	cosh(double);
-double	sinh(double);
-double	tanh(double);
-
-double	exp(double);
-double	frexp(double, int *);	/* fundamentally !__pure2 */
-double	ldexp(double, int);
-double	log(double);
-double	log10(double);
-double	modf(double, double *);	/* fundamentally !__pure2 */
-
-double	pow(double, double);
-double	sqrt(double);
-
-double	ceil(double);
-double	fabs(double) __pure2;
-__BIONIC_MATH_INLINE(double fabs(double x) { return __builtin_fabs(x); })
-double	floor(double);
-double	fmod(double, double);
-
-/*
- * These functions are not in C90.
- */
-#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE
-double	acosh(double);
-double	asinh(double);
-double	atanh(double);
-double	cbrt(double);
-double	erf(double);
-double	erfc(double);
-double	exp2(double);
-double	expm1(double);
-double	fma(double, double, double);
-double	hypot(double, double);
-int	ilogb(double) __pure2;
-int	(isinf)(double) __pure2;
-int	(isnan)(double) __pure2;
-double	lgamma(double);
-long long llrint(double);
-long long llround(double);
-double	log1p(double);
-double	log2(double);
-double	logb(double);
-long	lrint(double);
-long	lround(double);
-double	nan(const char *) __pure2;
-double	nextafter(double, double);
-double	remainder(double, double);
-double	remquo(double, double, int *);
-double	rint(double);
-#endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
-
-#if __BSD_VISIBLE || __XSI_VISIBLE
-double	j0(double);
-double	j1(double);
-double	jn(int, double);
-double	y0(double);
-double	y1(double);
-double	yn(int, double);
-
-#if __XSI_VISIBLE <= 500 || __BSD_VISIBLE
-double	gamma(double);
-#endif
-
-#if __XSI_VISIBLE <= 600 || __BSD_VISIBLE
-double	scalb(double, double);
-#endif
-#endif /* __BSD_VISIBLE || __XSI_VISIBLE */
-
-#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
-double	copysign(double, double) __pure2;
-double	fdim(double, double);
-double	fmax(double, double) __pure2;
-double	fmin(double, double) __pure2;
-double	nearbyint(double);
-double	round(double);
-double	scalbln(double, long);
-double	scalbn(double, int);
-double	tgamma(double);
-double	trunc(double);
-#endif
-
-/*
- * BSD math library entry points
- */
-#if __BSD_VISIBLE
-double	drem(double, double);
-int	finite(double) __pure2;
-int	isnanf(float) __pure2;
-long double significandl(long double);
-
-/*
- * Reentrant version of gamma & lgamma; passes signgam back by reference
- * as the second argument; user must allocate space for signgam.
- */
-double	gamma_r(double, int *);
-double	lgamma_r(double, int *);
-
-/*
- * IEEE Test Vector
- */
-double	significand(double);
-#endif /* __BSD_VISIBLE */
-
-/* float versions of ANSI/POSIX functions */
-#if __ISO_C_VISIBLE >= 1999
-float	acosf(float);
-float	asinf(float);
-float	atanf(float);
-float	atan2f(float, float);
-float	cosf(float);
-float	sinf(float);
-float	tanf(float);
-
-float	coshf(float);
-float	sinhf(float);
-float	tanhf(float);
-
-float	exp2f(float);
-float	expf(float);
-float	expm1f(float);
-float	frexpf(float, int *);	/* fundamentally !__pure2 */
-int	ilogbf(float) __pure2;
-float	ldexpf(float, int);
-float	log10f(float);
-float	log1pf(float);
-float	log2f(float);
-float	logf(float);
-float	modff(float, float *);	/* fundamentally !__pure2 */
-
-float	powf(float, float);
-float	sqrtf(float);
-
-float	ceilf(float);
-float	fabsf(float) __pure2;
-__BIONIC_MATH_INLINE(float fabsf(float x) { return __builtin_fabsf(x); })
-float	floorf(float);
-float	fmodf(float, float);
-float	roundf(float);
-
-float	erff(float);
-float	erfcf(float);
-float	hypotf(float, float);
-float	lgammaf(float);
-float	tgammaf(float);
-
-float	acoshf(float);
-float	asinhf(float);
-float	atanhf(float);
-float	cbrtf(float);
-float	logbf(float);
-float	copysignf(float, float) __pure2;
-long long llrintf(float);
-long long llroundf(float);
-long	lrintf(float);
-long	lroundf(float);
-float	nanf(const char *) __pure2;
-float	nearbyintf(float);
-float	nextafterf(float, float);
-float	remainderf(float, float);
-float	remquof(float, float, int *);
-float	rintf(float);
-float	scalblnf(float, long);
-float	scalbnf(float, int);
-float	truncf(float);
-
-float	fdimf(float, float);
-float	fmaf(float, float, float);
-float	fmaxf(float, float) __pure2;
-float	fminf(float, float) __pure2;
-#endif
-
-/*
- * float versions of BSD math library entry points
- */
-#if __BSD_VISIBLE
-float	dremf(float, float);
-int	finitef(float) __pure2;
-float	gammaf(float);
-float	j0f(float);
-float	j1f(float);
-float	jnf(int, float);
-float	scalbf(float, float);
-float	y0f(float);
-float	y1f(float);
-float	ynf(int, float);
-
-/*
- * Float versions of reentrant version of gamma & lgamma; passes
- * signgam back by reference as the second argument; user must
- * allocate space for signgam.
- */
-float	gammaf_r(float, int *);
-float	lgammaf_r(float, int *);
-
-/*
- * float version of IEEE Test Vector
- */
-float	significandf(float);
-#endif	/* __BSD_VISIBLE */
-
-/*
- * long double versions of ISO/POSIX math functions
- */
-#if __ISO_C_VISIBLE >= 1999
-long double	acoshl(long double);
-long double	acosl(long double);
-long double	asinhl(long double);
-long double	asinl(long double);
-long double	atan2l(long double, long double);
-long double	atanhl(long double);
-long double	atanl(long double);
-long double	cbrtl(long double);
-long double	ceill(long double);
-long double	copysignl(long double, long double) __pure2;
-long double	coshl(long double);
-long double	cosl(long double);
-long double	erfcl(long double);
-long double	erfl(long double);
-long double	exp2l(long double);
-long double	expl(long double);
-long double	expm1l(long double);
-long double	fabsl(long double) __pure2;
-__BIONIC_MATH_INLINE(long double fabsl(long double x) { return __builtin_fabsl(x); })
-long double	fdiml(long double, long double);
-long double	floorl(long double);
-long double	fmal(long double, long double, long double);
-long double	fmaxl(long double, long double) __pure2;
-long double	fminl(long double, long double) __pure2;
-long double	fmodl(long double, long double);
-long double	frexpl(long double value, int *); /* fundamentally !__pure2 */
-long double	hypotl(long double, long double);
-int		ilogbl(long double) __pure2;
-long double	ldexpl(long double, int);
-long double	lgammal(long double);
-long long	llrintl(long double);
-long long	llroundl(long double);
-long double	log10l(long double);
-long double	log1pl(long double);
-long double	log2l(long double);
-long double	logbl(long double);
-long double	logl(long double);
-long		lrintl(long double);
-long		lroundl(long double);
-long double	modfl(long double, long double *); /* fundamentally !__pure2 */
-long double	nanl(const char *) __pure2;
-long double	nearbyintl(long double);
-long double	nextafterl(long double, long double);
-double		nexttoward(double, long double);
-float		nexttowardf(float, long double);
-long double	nexttowardl(long double, long double);
-long double	powl(long double, long double);
-long double	remainderl(long double, long double);
-long double	remquol(long double, long double, int *);
-long double	rintl(long double);
-long double	roundl(long double);
-long double	scalblnl(long double, long);
-long double	scalbnl(long double, int);
-long double	sinhl(long double);
-long double	sinl(long double);
-long double	sqrtl(long double);
-long double	tanhl(long double);
-long double	tanl(long double);
-long double	tgammal(long double);
-long double	truncl(long double);
-#endif /* __ISO_C_VISIBLE >= 1999 */
-
-#if __BSD_VISIBLE
-long double	lgammal_r(long double, int *);
-#endif
-
-#if defined(__USE_GNU)
-void sincos(double, double*, double*);
-void sincosf(float, float*, float*);
-void sincosl(long double, long double*, long double*);
-#endif /* __USE_GNU */
-
-#pragma GCC visibility pop
-__END_DECLS
-
-#endif /* !_MATH_H_ */
diff --git a/libm/libm.arm.map b/libm/libm.arm.map
index e781f2d..a61dc2e 100644
--- a/libm/libm.arm.map
+++ b/libm/libm.arm.map
@@ -1,4 +1,4 @@
-# Generated by genversionscripts.py. Do not edit.
+# Generated by genversion-scripts.py. Do not edit.
 LIBC {
   global:
     __fe_dfl_env;
@@ -272,7 +272,30 @@
     *;
 };
 
-LIBC_PRIVATE { # arm mips
+LIBC_O {
+  global:
+    cacoshl;
+    cacosl;
+    casinhl;
+    casinl;
+    catanhl;
+    catanl;
+    ccoshl;
+    ccosl;
+    cexpl;
+    clog;
+    clogf;
+    clogl;
+    cpow;
+    cpowf;
+    cpowl;
+    csinhl;
+    csinl;
+    ctanhl;
+    ctanl;
+} LIBC;
+
+LIBC_DEPRECATED { # arm mips
   global: # arm mips
     ___Unwind_Backtrace; # arm
     ___Unwind_ForcedUnwind; # arm
@@ -375,4 +398,4 @@
     _Unwind_VRS_Pop; # arm
     _Unwind_VRS_Set; # arm
     restore_core_regs; # arm
-} LIBC; # arm mips
+} LIBC_O; # arm mips
diff --git a/libm/libm.arm64.map b/libm/libm.arm64.map
index 1623ea0..11032ca 100644
--- a/libm/libm.arm64.map
+++ b/libm/libm.arm64.map
@@ -1,4 +1,4 @@
-# Generated by genversionscripts.py. Do not edit.
+# Generated by genversion-scripts.py. Do not edit.
 LIBC {
   global:
     __fe_dfl_env;
@@ -272,3 +272,26 @@
     *;
 };
 
+LIBC_O {
+  global:
+    cacoshl;
+    cacosl;
+    casinhl;
+    casinl;
+    catanhl;
+    catanl;
+    ccoshl;
+    ccosl;
+    cexpl;
+    clog;
+    clogf;
+    clogl;
+    cpow;
+    cpowf;
+    cpowl;
+    csinhl;
+    csinl;
+    ctanhl;
+    ctanl;
+} LIBC;
+
diff --git a/libm/libm.map.txt b/libm/libm.map.txt
index 075ebd5..66dfd19 100644
--- a/libm/libm.map.txt
+++ b/libm/libm.map.txt
@@ -271,7 +271,30 @@
     *;
 };
 
-LIBC_PRIVATE { # arm mips
+LIBC_O {
+  global:
+    cacoshl;
+    cacosl;
+    casinhl;
+    casinl;
+    catanhl;
+    catanl;
+    ccoshl;
+    ccosl;
+    cexpl;
+    clog;
+    clogf;
+    clogl;
+    cpow;
+    cpowf;
+    cpowl;
+    csinhl;
+    csinl;
+    ctanhl;
+    ctanl;
+} LIBC;
+
+LIBC_DEPRECATED { # arm mips
   global: # arm mips
     ___Unwind_Backtrace; # arm
     ___Unwind_ForcedUnwind; # arm
@@ -374,4 +397,4 @@
     _Unwind_VRS_Pop; # arm
     _Unwind_VRS_Set; # arm
     restore_core_regs; # arm
-} LIBC; # arm mips
+} LIBC_O; # arm mips
diff --git a/libm/libm.mips.map b/libm/libm.mips.map
index 476c6ad..8353627 100644
--- a/libm/libm.mips.map
+++ b/libm/libm.mips.map
@@ -1,4 +1,4 @@
-# Generated by genversionscripts.py. Do not edit.
+# Generated by genversion-scripts.py. Do not edit.
 LIBC {
   global:
     __fe_dfl_env;
@@ -272,10 +272,33 @@
     *;
 };
 
-LIBC_PRIVATE { # arm mips
+LIBC_O {
+  global:
+    cacoshl;
+    cacosl;
+    casinhl;
+    casinl;
+    catanhl;
+    catanl;
+    ccoshl;
+    ccosl;
+    cexpl;
+    clog;
+    clogf;
+    clogl;
+    cpow;
+    cpowf;
+    cpowl;
+    csinhl;
+    csinl;
+    ctanhl;
+    ctanl;
+} LIBC;
+
+LIBC_DEPRECATED { # arm mips
   global: # arm mips
     __fixdfdi; # arm mips
     __fixsfdi; # arm mips
     __fixunsdfdi; # arm mips
     __fixunssfdi; # arm mips
-} LIBC; # arm mips
+} LIBC_O; # arm mips
diff --git a/libm/libm.mips64.map b/libm/libm.mips64.map
index 1623ea0..11032ca 100644
--- a/libm/libm.mips64.map
+++ b/libm/libm.mips64.map
@@ -1,4 +1,4 @@
-# Generated by genversionscripts.py. Do not edit.
+# Generated by genversion-scripts.py. Do not edit.
 LIBC {
   global:
     __fe_dfl_env;
@@ -272,3 +272,26 @@
     *;
 };
 
+LIBC_O {
+  global:
+    cacoshl;
+    cacosl;
+    casinhl;
+    casinl;
+    catanhl;
+    catanl;
+    ccoshl;
+    ccosl;
+    cexpl;
+    clog;
+    clogf;
+    clogl;
+    cpow;
+    cpowf;
+    cpowl;
+    csinhl;
+    csinl;
+    ctanhl;
+    ctanl;
+} LIBC;
+
diff --git a/libm/libm.x86.map b/libm/libm.x86.map
index 1623ea0..11032ca 100644
--- a/libm/libm.x86.map
+++ b/libm/libm.x86.map
@@ -1,4 +1,4 @@
-# Generated by genversionscripts.py. Do not edit.
+# Generated by genversion-scripts.py. Do not edit.
 LIBC {
   global:
     __fe_dfl_env;
@@ -272,3 +272,26 @@
     *;
 };
 
+LIBC_O {
+  global:
+    cacoshl;
+    cacosl;
+    casinhl;
+    casinl;
+    catanhl;
+    catanl;
+    ccoshl;
+    ccosl;
+    cexpl;
+    clog;
+    clogf;
+    clogl;
+    cpow;
+    cpowf;
+    cpowl;
+    csinhl;
+    csinl;
+    ctanhl;
+    ctanl;
+} LIBC;
+
diff --git a/libm/libm.x86_64.map b/libm/libm.x86_64.map
index 1623ea0..11032ca 100644
--- a/libm/libm.x86_64.map
+++ b/libm/libm.x86_64.map
@@ -1,4 +1,4 @@
-# Generated by genversionscripts.py. Do not edit.
+# Generated by genversion-scripts.py. Do not edit.
 LIBC {
   global:
     __fe_dfl_env;
@@ -272,3 +272,26 @@
     *;
 };
 
+LIBC_O {
+  global:
+    cacoshl;
+    cacosl;
+    casinhl;
+    casinl;
+    catanhl;
+    catanl;
+    ccoshl;
+    ccosl;
+    cexpl;
+    clog;
+    clogf;
+    clogl;
+    cpow;
+    cpowf;
+    cpowl;
+    csinhl;
+    csinl;
+    ctanhl;
+    ctanl;
+} LIBC;
+
diff --git a/libm/upstream-freebsd/android/include/machine/endian.h b/libm/upstream-freebsd/android/include/machine/endian.h
new file mode 100644
index 0000000..2dc4d83
--- /dev/null
+++ b/libm/upstream-freebsd/android/include/machine/endian.h
@@ -0,0 +1 @@
+#include <endian.h>
diff --git a/libm/upstream-netbsd/lib/libm/complex/cacoshl.c b/libm/upstream-netbsd/lib/libm/complex/cacoshl.c
new file mode 100644
index 0000000..4e4e006
--- /dev/null
+++ b/libm/upstream-netbsd/lib/libm/complex/cacoshl.c
@@ -0,0 +1,45 @@
+/* $NetBSD: cacoshl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */
+
+/*-
+ * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software written by Stephen L. Moshier.
+ * It is redistributed by the NetBSD Foundation by permission of the author.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <complex.h>
+
+long double complex
+cacoshl(long double complex z)
+{
+	long double complex w;
+
+#if 0 /* does not give the principal value */
+	w = I * cacosl(z);
+#else
+	w = clogl(z + csqrtl(z + 1) * csqrtl(z - 1));
+#endif
+	return w;
+}
diff --git a/libm/upstream-netbsd/lib/libm/complex/cacosl.c b/libm/upstream-netbsd/lib/libm/complex/cacosl.c
new file mode 100644
index 0000000..e481158
--- /dev/null
+++ b/libm/upstream-netbsd/lib/libm/complex/cacosl.c
@@ -0,0 +1,45 @@
+/* $NetBSD: cacosl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */
+
+/*-
+ * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software written by Stephen L. Moshier.
+ * It is redistributed by the NetBSD Foundation by permission of the author.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "../src/namespace.h"
+#include <complex.h>
+#include <math.h>
+#include "cephes_subrl.h"
+
+long double complex
+cacosl(long double complex z)
+{
+	long double complex w;
+
+	w = casinl(z);
+	w = (M_PI_2L - creall(w)) - cimagl(w) * I;
+	return w;
+}
diff --git a/libm/upstream-netbsd/lib/libm/complex/casinhl.c b/libm/upstream-netbsd/lib/libm/complex/casinhl.c
new file mode 100644
index 0000000..9f74ee9
--- /dev/null
+++ b/libm/upstream-netbsd/lib/libm/complex/casinhl.c
@@ -0,0 +1,42 @@
+/* $NetBSD: casinhl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */
+
+/*-
+ * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software written by Stephen L. Moshier.
+ * It is redistributed by the NetBSD Foundation by permission of the author.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "../src/namespace.h"
+#include <complex.h>
+
+long double complex
+casinhl(long double complex z)
+{
+	long double complex w;
+
+	w = -1.0L * I * casinl(z * I);
+	return w;
+}
diff --git a/libm/upstream-netbsd/lib/libm/complex/casinl.c b/libm/upstream-netbsd/lib/libm/complex/casinl.c
new file mode 100644
index 0000000..986a8c0
--- /dev/null
+++ b/libm/upstream-netbsd/lib/libm/complex/casinl.c
@@ -0,0 +1,120 @@
+/* $NetBSD: casinl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */
+
+/*-
+ * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software written by Stephen L. Moshier.
+ * It is redistributed by the NetBSD Foundation by permission of the author.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "../src/namespace.h"
+#include <complex.h>
+#include <math.h>
+
+#ifdef __weak_alias
+__weak_alias(casinl, _casinl)
+#endif
+
+long double complex
+casinl(long double complex z)
+{
+	long double complex w;
+	long double complex ca, ct, zz, z2;
+	long double x, y;
+
+	x = creall(z);
+	y = cimagl(z);
+
+#if 0 /* MD: test is incorrect, casin(>1) is defined */
+	if (y == 0.0L) {
+		if (fabsl(x) > 1.0L) {
+			w = M_PI_2L + 0.0L * I;
+#if 0
+			mtherr ("casinl", DOMAIN);
+#endif
+		} else {
+			w = asinl(x) + 0.0L * I;
+		}
+		return w;
+	}
+#endif
+
+/* Power series expansion */
+/*
+b = cabsl(z);
+if( b < 0.125L )
+{
+z2.r = (x - y) * (x + y);
+z2.i = 2.0L * x * y;
+
+cn = 1.0L;
+n = 1.0L;
+ca.r = x;
+ca.i = y;
+sum.r = x;
+sum.i = y;
+do
+	{
+	ct.r = z2.r * ca.r  -  z2.i * ca.i;
+	ct.i = z2.r * ca.i  +  z2.i * ca.r;
+	ca.r = ct.r;
+	ca.i = ct.i;
+
+	cn *= n;
+	n += 1.0;
+	cn /= n;
+	n += 1.0;
+	b = cn/n;
+
+	ct.r *= b;
+	ct.i *= b;
+	sum.r += ct.r;
+	sum.i += ct.i;
+	b = fabsl(ct.r) + fabsl(ct.i);
+	}
+while( b > MACHEPL );
+w->r = sum.r;
+w->i = sum.i;
+return;
+}
+*/
+
+
+	ca = x + y * I;
+	ct = ca * I;
+	/* sqrtl( 1 - z*z) */
+	/* cmull( &ca, &ca, &zz ) */
+	/*x * x  -  y * y */
+	zz = (x - y) * (x + y) + (2.0L * x * y) * I;
+
+	zz = 1.0L - creall(zz) - cimagl(zz) * I;
+	z2 = csqrtl(zz);
+
+	zz = ct + z2;
+	zz = clogl(zz);
+	/* multiply by 1/i = -i */
+	w = zz * (-1.0L * I);
+	return w;
+}
diff --git a/libm/upstream-netbsd/lib/libm/complex/catanhl.c b/libm/upstream-netbsd/lib/libm/complex/catanhl.c
new file mode 100644
index 0000000..4969b70
--- /dev/null
+++ b/libm/upstream-netbsd/lib/libm/complex/catanhl.c
@@ -0,0 +1,42 @@
+/* $NetBSD: catanhl.c,v 1.3 2014/10/10 12:43:15 christos Exp $ */
+
+/*-
+ * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software written by Stephen L. Moshier.
+ * It is redistributed by the NetBSD Foundation by permission of the author.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "../src/namespace.h"
+#include <complex.h>
+
+long double complex
+catanhl(long double complex z)
+{
+	long double complex w;
+
+	w = -1.0L * I * catanl(z * I);
+	return w;
+}
diff --git a/libm/upstream-netbsd/lib/libm/complex/catanl.c b/libm/upstream-netbsd/lib/libm/complex/catanl.c
new file mode 100644
index 0000000..bdff23f
--- /dev/null
+++ b/libm/upstream-netbsd/lib/libm/complex/catanl.c
@@ -0,0 +1,80 @@
+/* $NetBSD: catanl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */
+
+/*-
+ * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software written by Stephen L. Moshier.
+ * It is redistributed by the NetBSD Foundation by permission of the author.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "../src/namespace.h"
+#include <complex.h>
+#include <math.h>
+#include <float.h>
+#include "cephes_subrl.h"
+
+#ifdef __weak_alias
+__weak_alias(catanl, _catanl)
+#endif
+
+#define MAXNUM LDBL_MAX
+
+long double complex
+catanl(long double complex z)
+{
+	long double complex w;
+	long double a, t, x, x2, y;
+
+	x = creall(z);
+	y = cimagl(z);
+
+	if ((x == 0.0L) && (y > 1.0L))
+		goto ovrf;
+
+	x2 = x * x;
+	a = 1.0L - x2 - (y * y);
+	if (a == 0.0)
+		goto ovrf;
+
+	t = 0.5L * atan2l(2.0L * x, a);
+	w = _redupil(t);
+
+	t = y - 1.0L;
+	a = x2 + (t * t);
+	if (a == 0.0L)
+		goto ovrf;
+
+	t = y + 1.0L;
+	a = (x2 + (t * t))/a;
+	w = w + (0.25L * logl(a)) * I;
+	return w;
+
+ovrf:
+#if 0
+	mtherr ("catanl", OVERFLOW);
+#endif
+	w = MAXNUM + MAXNUM * I;
+	return w;
+}
diff --git a/libm/upstream-netbsd/lib/libm/complex/ccoshl.c b/libm/upstream-netbsd/lib/libm/complex/ccoshl.c
new file mode 100644
index 0000000..4c33f9d
--- /dev/null
+++ b/libm/upstream-netbsd/lib/libm/complex/ccoshl.c
@@ -0,0 +1,46 @@
+/* $NetBSD: ccoshl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */
+
+/*-
+ * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software written by Stephen L. Moshier.
+ * It is redistributed by the NetBSD Foundation by permission of the author.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "../src/namespace.h"
+#include <complex.h>
+#include <math.h>
+
+long double complex
+ccoshl(long double complex z)
+{
+	long double complex w;
+	long double x, y;
+
+	x = creall(z);
+	y = cimagl(z);
+	w = coshl(x) * cosl(y) + (sinhl(x) * sinl(y)) * I;
+	return w;
+}
diff --git a/libm/upstream-netbsd/lib/libm/complex/ccosl.c b/libm/upstream-netbsd/lib/libm/complex/ccosl.c
new file mode 100644
index 0000000..6ce5661
--- /dev/null
+++ b/libm/upstream-netbsd/lib/libm/complex/ccosl.c
@@ -0,0 +1,46 @@
+/* $NetBSD: ccosl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */
+
+/*-
+ * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software written by Stephen L. Moshier.
+ * It is redistributed by the NetBSD Foundation by permission of the author.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "../src/namespace.h"
+#include <complex.h>
+#include <math.h>
+#include "cephes_subrl.h"
+
+long double complex
+ccosl(long double complex z)
+{
+	long double complex w;
+	long double ch, sh;
+
+	_cchshl(cimagl(z), &ch, &sh);
+	w = cosl(creall(z)) * ch - (sinl(creall(z)) * sh) * I;
+	return w;
+}
diff --git a/libm/upstream-netbsd/lib/libm/complex/cephes_subrl.c b/libm/upstream-netbsd/lib/libm/complex/cephes_subrl.c
new file mode 100644
index 0000000..90dbd86
--- /dev/null
+++ b/libm/upstream-netbsd/lib/libm/complex/cephes_subrl.c
@@ -0,0 +1,129 @@
+/* $NetBSD: cephes_subrl.c,v 1.2 2014/10/10 14:06:40 christos Exp $ */
+
+/*-
+ * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software written by Stephen L. Moshier.
+ * It is redistributed by the NetBSD Foundation by permission of the author.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "../src/namespace.h"
+#include <complex.h>
+#include <math.h>
+#include "cephes_subrl.h"
+
+/* calculate cosh and sinh */
+
+void
+_cchshl(long double x, long double *c, long double *s)
+{
+	long double e, ei;
+
+	if (fabsl(x) <= 0.5L) {
+		*c = coshl(x);
+		*s = sinhl(x);
+	} else {
+		e = expl(x);
+		ei = 0.5L / e;
+		e = 0.5L * e;
+		*s = e - ei;
+		*c = e + ei;
+	}
+}
+
+/* Program to subtract nearest integer multiple of PI */
+
+/* extended precision value of PI: */
+static const long double DP1 = 3.14159265358979323829596852490908531763125L;
+static const long double DP2 = 1.6667485837041756656403424829301998703007e-19L;
+#ifndef __vax__
+static const long double DP3 = 1.8830410776607851167459095484560349402753e-39L;
+#define MACHEPL 1.1e-38L
+#else
+static const long double DP3 = 0L;
+#define MACHEPL 1.1e-19L
+#endif
+
+long double
+_redupil(long double x)
+{
+	long double t;
+	long long i;
+
+	t = x / M_PIL;
+	if (t >= 0.0L)
+		t += 0.5L;
+	else
+		t -= 0.5L;
+
+	i = t;	/* the multiple */
+	t = i;
+	t = ((x - t * DP1) - t * DP2) - t * DP3;
+	return t;
+}
+
+/* Taylor series expansion for cosh(2y) - cos(2x) */
+
+long double
+_ctansl(long double complex z)
+{
+	long double f, x, x2, y, y2, rn, t;
+	long double d;
+
+	x = fabsl(2.0L * creall(z));
+	y = fabsl(2.0L * cimagl(z));
+
+	x = _redupil(x);
+
+	x = x * x;
+	y = y * y;
+	x2 = 1.0;
+	y2 = 1.0;
+	f = 1.0;
+	rn = 0.0;
+	d = 0.0;
+	do {
+		rn += 1.0L;
+		f *= rn;
+		rn += 1.0L;
+		f *= rn;
+		x2 *= x;
+		y2 *= y;
+		t = y2 + x2;
+		t /= f;
+		d += t;
+
+		rn += 1.0L;
+		f *= rn;
+		rn += 1.0L;
+		f *= rn;
+		x2 *= x;
+		y2 *= y;
+		t = y2 - x2;
+		t /= f;
+		d += t;
+	} while (fabsl(t/d) > MACHEPL);
+	return d;
+}
diff --git a/libm/upstream-netbsd/lib/libm/complex/cephes_subrl.h b/libm/upstream-netbsd/lib/libm/complex/cephes_subrl.h
new file mode 100644
index 0000000..6354b23
--- /dev/null
+++ b/libm/upstream-netbsd/lib/libm/complex/cephes_subrl.h
@@ -0,0 +1,9 @@
+/* $NetBSD: cephes_subrl.h,v 1.1 2014/10/10 00:48:18 christos Exp $ */
+
+void _cchshl(long double, long double *, long double *);
+long double _redupil(long double);
+long double _ctansl(long double complex);
+
+#define	M_PIL	3.14159265358979323846264338327950280e+00L
+#define	M_PI_2L	1.57079632679489661923132169163975140e+00L
+
diff --git a/libm/upstream-netbsd/lib/libm/complex/cexpl.c b/libm/upstream-netbsd/lib/libm/complex/cexpl.c
new file mode 100644
index 0000000..a1e2235
--- /dev/null
+++ b/libm/upstream-netbsd/lib/libm/complex/cexpl.c
@@ -0,0 +1,47 @@
+/* $NetBSD: cexpl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */
+
+/*-
+ * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software written by Stephen L. Moshier.
+ * It is redistributed by the NetBSD Foundation by permission of the author.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "../src/namespace.h"
+#include <complex.h>
+#include <math.h>
+
+long double complex
+cexpl(long double complex z)
+{
+	long double complex w;
+	long double r, x, y;
+
+	x = creall(z);
+	y = cimagl(z);
+	r = expl(x);
+	w = r * cosl(y) + r * sinl(y) * I;
+	return w;
+}
diff --git a/libm/upstream-netbsd/lib/libm/complex/clog.c b/libm/upstream-netbsd/lib/libm/complex/clog.c
new file mode 100644
index 0000000..6362c44
--- /dev/null
+++ b/libm/upstream-netbsd/lib/libm/complex/clog.c
@@ -0,0 +1,47 @@
+/* $NetBSD: clog.c,v 1.1 2007/08/20 16:01:35 drochner Exp $ */
+
+/*-
+ * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software written by Stephen L. Moshier.
+ * It is redistributed by the NetBSD Foundation by permission of the author.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "../src/namespace.h"
+#include <complex.h>
+#include <math.h>
+
+double complex
+clog(double complex z)
+{
+	double complex w;
+	double p, rr;
+
+	rr = cabs(z);
+	p = log(rr);
+	rr = atan2(cimag(z), creal(z));
+	w = p + rr * I;
+	return w;
+}
diff --git a/libm/upstream-netbsd/lib/libm/complex/clogf.c b/libm/upstream-netbsd/lib/libm/complex/clogf.c
new file mode 100644
index 0000000..c3cdad0
--- /dev/null
+++ b/libm/upstream-netbsd/lib/libm/complex/clogf.c
@@ -0,0 +1,47 @@
+/* $NetBSD: clogf.c,v 1.1 2007/08/20 16:01:35 drochner Exp $ */
+
+/*-
+ * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software written by Stephen L. Moshier.
+ * It is redistributed by the NetBSD Foundation by permission of the author.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "../src/namespace.h"
+#include <complex.h>
+#include <math.h>
+
+float complex
+clogf(float complex z)
+{
+	float complex w;
+	float p, rr;
+
+	rr = cabsf(z);
+	p = logf(rr);
+	rr = atan2f(cimagf(z), crealf(z));
+	w = p + rr * I;
+	return w;
+}
diff --git a/libm/upstream-netbsd/lib/libm/complex/clogl.c b/libm/upstream-netbsd/lib/libm/complex/clogl.c
new file mode 100644
index 0000000..11e7a15
--- /dev/null
+++ b/libm/upstream-netbsd/lib/libm/complex/clogl.c
@@ -0,0 +1,47 @@
+/* $NetBSD: clogl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */
+
+/*-
+ * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software written by Stephen L. Moshier.
+ * It is redistributed by the NetBSD Foundation by permission of the author.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "../src/namespace.h"
+#include <complex.h>
+#include <math.h>
+
+long double complex
+clogl(long double complex z)
+{
+	long double complex w;
+	long double p, rr;
+
+	rr = cabsl(z);
+	p = logl(rr);
+	rr = atan2l(cimagl(z), creall(z));
+	w = p + rr * I;
+	return w;
+}
diff --git a/libm/upstream-netbsd/lib/libm/complex/cpow.c b/libm/upstream-netbsd/lib/libm/complex/cpow.c
new file mode 100644
index 0000000..5bc8d3f
--- /dev/null
+++ b/libm/upstream-netbsd/lib/libm/complex/cpow.c
@@ -0,0 +1,57 @@
+/* $NetBSD: cpow.c,v 1.1 2007/08/20 16:01:35 drochner Exp $ */
+
+/*-
+ * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software written by Stephen L. Moshier.
+ * It is redistributed by the NetBSD Foundation by permission of the author.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "../src/namespace.h"
+#include <complex.h>
+#include <math.h>
+
+double complex
+cpow(double complex a, double complex z)
+{
+	double complex w;
+	double x, y, r, theta, absa, arga;
+
+	x = creal(z);
+	y = cimag(z);
+	absa = cabs(a);
+	if (absa == 0.0) {
+		return (0.0 + 0.0 * I);
+	}
+	arga = carg(a);
+	r = pow(absa, x);
+	theta = x * arga;
+	if (y != 0.0) {
+		r = r * exp(-y * arga);
+		theta = theta + y * log(absa);
+	}
+	w = r * cos(theta) + (r * sin(theta)) * I;
+	return w;
+}
diff --git a/libm/upstream-netbsd/lib/libm/complex/cpowf.c b/libm/upstream-netbsd/lib/libm/complex/cpowf.c
new file mode 100644
index 0000000..f7af10a
--- /dev/null
+++ b/libm/upstream-netbsd/lib/libm/complex/cpowf.c
@@ -0,0 +1,57 @@
+/* $NetBSD: cpowf.c,v 1.1 2007/08/20 16:01:36 drochner Exp $ */
+
+/*-
+ * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software written by Stephen L. Moshier.
+ * It is redistributed by the NetBSD Foundation by permission of the author.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "../src/namespace.h"
+#include <complex.h>
+#include <math.h>
+
+float complex
+cpowf(float complex a, float complex z)
+{
+	float complex w;
+	float x, y, r, theta, absa, arga;
+
+	x = crealf(z);
+	y = cimagf(z);
+	absa = cabsf(a);
+	if (absa == 0.0f) {
+		return (0.0f + 0.0f * I);
+	}
+	arga = cargf(a);
+	r = powf(absa, x);
+	theta = x * arga;
+	if (y != 0.0f) {
+		r = r * expf(-y * arga);
+		theta = theta + y * logf(absa);
+	}
+	w = r * cosf(theta) + (r * sinf(theta)) * I;
+	return w;
+}
diff --git a/libm/upstream-netbsd/lib/libm/complex/cpowl.c b/libm/upstream-netbsd/lib/libm/complex/cpowl.c
new file mode 100644
index 0000000..39336ea
--- /dev/null
+++ b/libm/upstream-netbsd/lib/libm/complex/cpowl.c
@@ -0,0 +1,57 @@
+/* $NetBSD: cpowl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */
+
+/*-
+ * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software written by Stephen L. Moshier.
+ * It is redistributed by the NetBSD Foundation by permission of the author.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "../src/namespace.h"
+#include <complex.h>
+#include <math.h>
+
+long double complex
+cpowl(long double complex a, long double complex z)
+{
+	long double complex w;
+	long double x, y, r, theta, absa, arga;
+
+	x = creall(z);
+	y = cimagl(z);
+	absa = cabsl(a);
+	if (absa == 0.0L) {
+		return (0.0L + 0.0L * I);
+	}
+	arga = cargl(a);
+	r = powl(absa, x);
+	theta = x * arga;
+	if (y != 0.0L) {
+		r = r * expl(-y * arga);
+		theta = theta + y * logl(absa);
+	}
+	w = r * cosl(theta) + (r * sinl(theta)) * I;
+	return w;
+}
diff --git a/libm/upstream-netbsd/lib/libm/complex/csinhl.c b/libm/upstream-netbsd/lib/libm/complex/csinhl.c
new file mode 100644
index 0000000..b78f7f1
--- /dev/null
+++ b/libm/upstream-netbsd/lib/libm/complex/csinhl.c
@@ -0,0 +1,46 @@
+/* $NetBSD: csinhl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */
+
+/*-
+ * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software written by Stephen L. Moshier.
+ * It is redistributed by the NetBSD Foundation by permission of the author.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "../src/namespace.h"
+#include <complex.h>
+#include <math.h>
+
+long double complex
+csinhl(long double complex z)
+{
+	long double complex w;
+	long double x, y;
+
+	x = creall(z);
+	y = cimagl(z);
+	w = sinhl(x) * cosl(y) + (coshl(x) * sinl(y)) * I;
+	return w;
+}
diff --git a/libm/upstream-netbsd/lib/libm/complex/csinl.c b/libm/upstream-netbsd/lib/libm/complex/csinl.c
new file mode 100644
index 0000000..c86847b
--- /dev/null
+++ b/libm/upstream-netbsd/lib/libm/complex/csinl.c
@@ -0,0 +1,46 @@
+/* $NetBSD: csinl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */
+
+/*-
+ * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software written by Stephen L. Moshier.
+ * It is redistributed by the NetBSD Foundation by permission of the author.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "../src/namespace.h"
+#include <complex.h>
+#include <math.h>
+#include "cephes_subrl.h"
+
+long double complex
+csinl(long double complex z)
+{
+	long double complex w;
+	long double ch, sh;
+
+	_cchshl(cimagl(z), &ch, &sh);
+	w = sinl(creall(z)) * ch + (cosl(creall(z)) * sh) * I;
+	return w;
+}
diff --git a/libm/upstream-netbsd/lib/libm/complex/ctanhl.c b/libm/upstream-netbsd/lib/libm/complex/ctanhl.c
new file mode 100644
index 0000000..0894dd0
--- /dev/null
+++ b/libm/upstream-netbsd/lib/libm/complex/ctanhl.c
@@ -0,0 +1,48 @@
+/* $NetBSD: ctanhl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */
+
+/*-
+ * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software written by Stephen L. Moshier.
+ * It is redistributed by the NetBSD Foundation by permission of the author.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "../src/namespace.h"
+#include <complex.h>
+#include <math.h>
+
+long double complex
+ctanhl(long double complex z)
+{
+	long double complex w;
+	long double x, y, d;
+
+	x = creall(z);
+	y = cimagl(z);
+	d = coshl(2.0L * x) + cosl(2.0L * y);
+	w = sinhl(2.0L * x) / d  +  (sinl(2.0L * y) / d) * I;
+
+	return w;
+}
diff --git a/libm/upstream-netbsd/lib/libm/complex/ctanl.c b/libm/upstream-netbsd/lib/libm/complex/ctanl.c
new file mode 100644
index 0000000..7932aef
--- /dev/null
+++ b/libm/upstream-netbsd/lib/libm/complex/ctanl.c
@@ -0,0 +1,59 @@
+/* $NetBSD: ctanl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */
+
+/*-
+ * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software written by Stephen L. Moshier.
+ * It is redistributed by the NetBSD Foundation by permission of the author.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "../src/namespace.h"
+#include <complex.h>
+#include <math.h>
+#include <float.h>
+#include "cephes_subrl.h"
+
+#define MAXNUM LDBL_MAX
+
+long double complex
+ctanl(long double complex z)
+{
+	long double complex w;
+	long double d;
+
+	d = cosl(2.0L * creall(z)) + coshl(2.0L * cimagl(z));
+
+	if (fabsl(d) < 0.25L)
+		d = _ctansl(z);
+
+	if (d == 0.0L) {
+		/* mtherr ("ctan", OVERFLOW); */
+		w = MAXNUM + MAXNUM * I;
+		return w;
+	}
+
+	w = sinl(2.0L * creall(z)) / d + (sinhl(2.0L * cimagl(z)) / d) * I;
+	return w;
+}
diff --git a/libc/include/sys/syslimits.h b/libm/upstream-netbsd/lib/libm/src/namespace.h
similarity index 100%
rename from libc/include/sys/syslimits.h
rename to libm/upstream-netbsd/lib/libm/src/namespace.h
diff --git a/libstdc++/NOTICE b/libstdc++/NOTICE
index 492770d..e69de29 100644
--- a/libstdc++/NOTICE
+++ b/libstdc++/NOTICE
@@ -1,81 +0,0 @@
-Copyright (C) 2008 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) 2009 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) 1994
-Hewlett-Packard Company
-
-Permission to use, copy, modify, distribute and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation.  Hewlett-Packard Company makes no
-representations about the suitability of this software for any
-purpose.  It is provided "as is" without express or implied warranty.
-
-
-Copyright (c) 1996,1997
-Silicon Graphics Computer Systems, Inc.
-
-Permission to use, copy, modify, distribute and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation.  Silicon Graphics makes no
-representations about the suitability of this software for any
-purpose.  It is provided "as is" without express or implied warranty.
-
--------------------------------------------------------------------
-
diff --git a/libstdc++/include/cctype b/libstdc++/include/cctype
deleted file mode 100644
index e0eb981..0000000
--- a/libstdc++/include/cctype
+++ /dev/null
@@ -1,60 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright (C) 2009 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.
- */
-
-#ifndef BIONIC_LIBSTDCPP_INCLUDE_CCTYPE__
-#define BIONIC_LIBSTDCPP_INCLUDE_CCTYPE__
-
-/*
- * Standard C++ Library wrapper around the C ctype.h header file.
- */
-
-#include <ctype.h>
-
-extern "C++" {
-
-namespace std 
-{
-using ::isalnum;
-using ::isalpha;
-using ::iscntrl;
-using ::isdigit;
-using ::isgraph;
-using ::islower;
-using ::isprint;
-using ::ispunct;
-using ::isspace;
-using ::isupper;
-using ::isxdigit;
-using ::tolower;
-using ::toupper;
-}  // namespace std
-
-}  // extern C++
-
-#endif  // BIONIC_LIBSTDCPP_INCLUDE_CCTYPE__
diff --git a/libstdc++/include/cfloat b/libstdc++/include/cfloat
deleted file mode 100644
index 21c01d9..0000000
--- a/libstdc++/include/cfloat
+++ /dev/null
@@ -1,39 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright (C) 2009 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.
- */
-
-#ifndef BIONIC_LIBSTDCPP_INCLUDE_CFLOAT__
-#define BIONIC_LIBSTDCPP_INCLUDE_CFLOAT__
-
-/*
- * Standard C++ Library wrapper around the C float.h header file.
- */
-#include <sys/limits.h>
-#include <float.h>
-
-#endif  // BIONIC_LIBSTDCPP_INCLUDE_CFLOAT__
diff --git a/libstdc++/include/cmath b/libstdc++/include/cmath
deleted file mode 100644
index a15b2ac..0000000
--- a/libstdc++/include/cmath
+++ /dev/null
@@ -1,75 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright (C) 2009 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.
- */
-
-#ifndef BIONIC_LIBSTDCPP_INCLUDE_CMATH__
-#define BIONIC_LIBSTDCPP_INCLUDE_CMATH__
-
-/*
- * Standard C++ Library wrapper around the C math.h header file.
- */
-
-#include <cstddef>
-#include <math.h>
-
-extern "C++" {
-
-namespace std
-{
-// Functions.
-using ::cos;
-using ::sin;
-using ::tan;
-using ::acos;
-using ::asin;
-using ::atan;
-using ::atan2;
-
-using ::cosh;
-using ::sinh;
-using ::tanh;
-
-using ::exp;
-using ::frexp;
-using ::ldexp;
-using ::log;
-using ::log10;
-using ::modf;
-
-using ::pow;
-using ::sqrt;
-
-using ::ceil;
-using ::fabs;
-using ::floor;
-using ::fmod;
-}  // namespace std
-
-}  // extern C++
-
-#endif  // BIONIC_LIBSTDCPP_INCLUDE_CMATH__
diff --git a/libstdc++/include/csetjmp b/libstdc++/include/csetjmp
deleted file mode 100644
index ba82144..0000000
--- a/libstdc++/include/csetjmp
+++ /dev/null
@@ -1,53 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright (C) 2009 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.
- */
-
-#ifndef BIONIC_LIBSTDCPP_INCLUDE_CSETJMP__
-#define BIONIC_LIBSTDCPP_INCLUDE_CSETJMP__
-
-/*
- * Standard C++ Library wrapper around the C setjmp.h header file.
- */
-
-#include <setjmp.h>
-
-extern "C++" {
-
-#ifndef setjmp
-#define setjmp(env) setjmp (env)
-#endif
-
-namespace std
-{
-using ::jmp_buf;
-using ::longjmp;
-}  // namespace std
-
-}  // extern C++
-
-#endif  // BIONIC_LIBSTDCPP_INCLUDE_CSETJMP__
diff --git a/libstdc++/include/csignal b/libstdc++/include/csignal
deleted file mode 100644
index 84f0e1d..0000000
--- a/libstdc++/include/csignal
+++ /dev/null
@@ -1,50 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright (C) 2009 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.
- */
-
-#ifndef BIONIC_LIBSTDCPP_INCLUDE_CSIGNAL__
-#define BIONIC_LIBSTDCPP_INCLUDE_CSIGNAL__
-
-/*
- * Standard C++ Library wrapper around the C signal.h header file.
- */
-
-#include <signal.h>
-
-extern "C++" {
-
-namespace std
-{
-using ::sig_atomic_t;
-using ::signal;
-using ::raise;
-}  // namespace std
-
-}  // extern C++
-
-#endif  // BIONIC_LIBSTDCPP_INCLUDE_CSIGNAL__
diff --git a/libstdc++/include/cstddef b/libstdc++/include/cstddef
deleted file mode 100644
index cb06b49..0000000
--- a/libstdc++/include/cstddef
+++ /dev/null
@@ -1,50 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright (C) 2009 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.
- */
-
-#ifndef BIONIC_LIBSTDCPP_INCLUDE_CSTDDEF__
-#define BIONIC_LIBSTDCPP_INCLUDE_CSTDDEF__
-
-/*
- * Standard C++ Library wrapper around the C stddef.h header file.
- * The following 2 types are also declared in the 'std' namespace:
- *   . ptrdiff_t
- *   . size_t
- */
-#include <stddef.h>
-
-extern "C++" {
-
-namespace std {
-using ::ptrdiff_t;
-using ::size_t;
-}  // namespace std
-
-}  // extern C++
-
-#endif  // BIONIC_LIBSTDCPP_INCLUDE_CSTDDEF__
diff --git a/libstdc++/include/cstdint b/libstdc++/include/cstdint
deleted file mode 100644
index 3df56df..0000000
--- a/libstdc++/include/cstdint
+++ /dev/null
@@ -1,40 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright (C) 2009 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.
- */
-
-#ifndef BIONIC_LIBSTDCPP_INCLUDE_CSTDINT__
-#define BIONIC_LIBSTDCPP_INCLUDE_CSTDINT__
-
-/*
- * Standard C++ Library wrapper around the C stdint.h header file.
- */
-
-#include <stdint.h>
-
-
-#endif  // BIONIC_LIBSTDCPP_INCLUDE_CSTDINT__
diff --git a/libstdc++/include/cstdio b/libstdc++/include/cstdio
deleted file mode 100644
index 2948d85..0000000
--- a/libstdc++/include/cstdio
+++ /dev/null
@@ -1,98 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright (C) 2009 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.
- */
-
-#ifndef BIONIC_LIBSTDCPP_INCLUDE_CSTDIO__
-#define BIONIC_LIBSTDCPP_INCLUDE_CSTDIO__
-
-/*
- * Standard C++ Library wrapper around the C stdio.h header file.
- */
-#include <cstddef>
-#include <stdio.h>
-
-extern "C++" {
-
-namespace std {
-using ::FILE;
-using ::fpos_t;
-
-using ::clearerr;
-using ::fclose;
-using ::feof;
-using ::ferror;
-using ::fflush;
-using ::fgetc;
-using ::fgetpos;
-using ::fgets;
-using ::fopen;
-using ::fprintf;
-using ::fputc;
-using ::fputs;
-using ::fread;
-using ::freopen;
-using ::fscanf;
-using ::fseek;
-using ::fsetpos;
-using ::ftell;
-using ::fwrite;
-using ::getc;
-using ::getchar;
-#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L
-using ::gets;
-#endif
-using ::perror;
-using ::printf;
-using ::putc;
-using ::putchar;
-using ::puts;
-using ::remove;
-using ::rename;
-using ::rewind;
-using ::scanf;
-using ::setbuf;
-using ::setvbuf;
-using ::sprintf;
-using ::sscanf;
-using ::tmpfile;
-using ::tmpnam;
-using ::ungetc;
-using ::vfprintf;
-using ::vprintf;
-using ::vsprintf;
-
-using ::snprintf;
-using ::vfscanf;
-using ::vscanf;
-using ::vsnprintf;
-using ::vsscanf;
-}  // namespace std
-
-}  // extern C++
-
-#endif  // BIONIC_LIBSTDCPP_INCLUDE_CSTDIO__
diff --git a/libstdc++/include/cstdlib b/libstdc++/include/cstdlib
deleted file mode 100644
index bd1deae..0000000
--- a/libstdc++/include/cstdlib
+++ /dev/null
@@ -1,116 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright (C) 2009 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.
- */
-
-#ifndef BIONIC_LIBSTDCPP_INCLUDE_CSTDLIB__
-#define BIONIC_LIBSTDCPP_INCLUDE_CSTDLIB__
-
-/*
- * Standard C++ Library wrapper around the C stdlib.h header file.
- */
-#include <stdlib.h>
-
-extern "C++" {
-
-namespace std {
-
-using ::exit;
-using ::abort;
-using ::atexit;
-
-using ::getenv;
-using ::putenv;
-using ::setenv;
-using ::unsetenv;
-using ::clearenv;
-
-using ::mktemp;
-using ::mkstemp;
-
-using ::strtol;
-using ::strtoll;
-using ::strtoul;
-using ::strtoull;
-using ::strtod;
-using ::strtof;
-
-using ::atoi;
-using ::atol;
-using ::atoll;
-using ::atof;
-
-using ::abs;
-using ::labs;
-using ::llabs;
-
-using ::realpath;
-using ::system;
-
-using ::bsearch;
-using ::qsort;
-
-using ::jrand48;
-using ::mrand48;
-using ::nrand48;
-using ::lrand48;
-using ::seed48;
-using ::srand48;
-
-using ::rand;
-using ::srand;
-using ::random;
-using ::srandom;
-
-using ::malloc;
-using ::free;
-using ::calloc;
-using ::realloc;
-
-using ::unlockpt;
-using ::ptsname;
-using ::ptsname_r;
-using ::getpt;
-using ::grantpt;
-
-using ::div_t;
-using ::div;
-using ::ldiv_t;
-using ::ldiv;
-using ::lldiv_t;
-using ::lldiv;
-
-using ::mblen;
-using ::mbstowcs;
-using ::mbtowc;
-using ::wctomb;
-using ::wcstombs;
-}  // namespace std
-
-}  // extern C++
-
-#endif  // BIONIC_LIBSTDCPP_INCLUDE_CSTDLIB__
diff --git a/libstdc++/include/cstring b/libstdc++/include/cstring
deleted file mode 100644
index d3d9387..0000000
--- a/libstdc++/include/cstring
+++ /dev/null
@@ -1,70 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright (C) 2009 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.
- */
-
-#ifndef BIONIC_LIBSTDCPP_INCLUDE_CSTRING__
-#define BIONIC_LIBSTDCPP_INCLUDE_CSTRING__
-
-/*
- * Standard C++ Library wrapper around the C string.h header file.
- */
-
-#include <cstddef>
-#include <string.h>
-
-extern "C++" {
-
-namespace std
-{
-using ::memchr;
-using ::memcmp;
-using ::memcpy;
-using ::memmove;
-using ::memset;
-using ::strcat;
-using ::strchr;
-using ::strcmp;
-using ::strcoll;
-using ::strcpy;
-using ::strcspn;
-using ::strerror;
-using ::strlen;
-using ::strncat;
-using ::strncmp;
-using ::strncpy;
-using ::strpbrk;
-using ::strrchr;
-using ::strspn;
-using ::strstr;
-using ::strtok;
-using ::strxfrm;
-}  // namespace std
-
-}  // extern C++
-
-#endif  // BIONIC_LIBSTDCPP_INCLUDE_CSTRING__
diff --git a/libstdc++/include/ctime b/libstdc++/include/ctime
deleted file mode 100644
index 9e6744f..0000000
--- a/libstdc++/include/ctime
+++ /dev/null
@@ -1,63 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright (C) 2009 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.
- */
-
-#ifndef BIONIC_LIBSTDCPP_INCLUDE_CTIME__
-#define BIONIC_LIBSTDCPP_INCLUDE_CTIME__
-
-/*
- * Standard C++ Library wrapper around the C time.h header file.
- */
-
-#include <cstddef>
-#include <time.h>
-
-extern "C++" {
-
-namespace std 
-{
-// Types.
-using ::clock_t;
-using ::time_t;
-using ::tm;
-
-// Functions.
-using ::clock;
-using ::difftime;
-using ::mktime;
-using ::time;
-using ::asctime;
-using ::ctime;
-using ::gmtime;
-using ::localtime;
-using ::strftime;
-}  // namespace std
-
-}  // extern C++
-
-#endif  // BIONIC_LIBSTDCPP_INCLUDE_CTIME__
diff --git a/libstdc++/include/cwchar b/libstdc++/include/cwchar
deleted file mode 100644
index a4f9f42..0000000
--- a/libstdc++/include/cwchar
+++ /dev/null
@@ -1,31 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright (C) 2009 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.
- */
-
-/* IMPORTANT: cwchar and cwctype are not supported. See comment in
- * bionic/libc/include/wchar.h */
diff --git a/libstdc++/include/cwctype_is_not_supported b/libstdc++/include/cwctype_is_not_supported
deleted file mode 100644
index a4f9f42..0000000
--- a/libstdc++/include/cwctype_is_not_supported
+++ /dev/null
@@ -1,31 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright (C) 2009 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.
- */
-
-/* IMPORTANT: cwchar and cwctype are not supported. See comment in
- * bionic/libc/include/wchar.h */
diff --git a/libstdc++/include/new b/libstdc++/include/new
index c5a43de..cffab6e 100644
--- a/libstdc++/include/new
+++ b/libstdc++/include/new
@@ -2,30 +2,33 @@
 #ifndef __NEW__
 #define __NEW__
 
-#include <cstddef>
+#include <stddef.h>
 
 extern "C++" {
 
 namespace std {
-    struct nothrow_t {};
-    extern const nothrow_t nothrow;
+  using ::size_t;
+  struct nothrow_t {};
+  extern const nothrow_t nothrow;
 }
 
 void* operator new(std::size_t);
-void* operator new[](std::size_t);
-void  operator delete(void*) throw();
-void  operator delete[](void*) throw();
 void* operator new(std::size_t, const std::nothrow_t&);
-void* operator new[](std::size_t, const std::nothrow_t&);
-void  operator delete(void*, const std::nothrow_t&) throw();
-void  operator delete[](void*, const std::nothrow_t&) throw();
+void operator delete(void*) throw();
+// TODO: void operator delete(void*, std::size_t) throw();
+void operator delete(void*, const std::nothrow_t&) throw();
 
+void* operator new[](std::size_t);
+void* operator new[](std::size_t, const std::nothrow_t&);
+void operator delete[](void*) throw();
+// TODO: void operator delete[](void*, std::size_t) throw();
+void operator delete[](void*, const std::nothrow_t&) throw();
+
+// These four are not replaceable, so should be inlined.
 inline void* operator new(std::size_t, void* p) { return p; }
 inline void* operator new[](std::size_t, void* p) { return p; }
-
-// these next two are not really required, since exceptions are off
-inline void  operator delete(void*, void*) throw() { }
-inline void  operator delete[](void*, void*) throw() { }
+inline void operator delete(void*, void*) throw() { }
+inline void operator delete[](void*, void*) throw() { }
 
 }  // extern C++
 
diff --git a/libstdc++/include/stl_pair.h b/libstdc++/include/stl_pair.h
deleted file mode 100644
index 37f757b..0000000
--- a/libstdc++/include/stl_pair.h
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright (C) 2008 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) 1994
- * Hewlett-Packard Company
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation.  Hewlett-Packard Company makes no
- * representations about the suitability of this software for any
- * purpose.  It is provided "as is" without express or implied warranty.
- *
- *
- * Copyright (c) 1996,1997
- * Silicon Graphics Computer Systems, Inc.
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation.  Silicon Graphics makes no
- * representations about the suitability of this software for any
- * purpose.  It is provided "as is" without express or implied warranty.
- */
-
-/* NOTE: This is an internal header file, included by other STL headers.
- *   You should not attempt to use it directly.
- */
-
-#ifndef __SGI_STL_INTERNAL_PAIR_H
-#define __SGI_STL_INTERNAL_PAIR_H
-
-__STL_BEGIN_NAMESPACE
-
-template <class _T1, class _T2>
-struct pair {
-  typedef _T1 first_type;
-  typedef _T2 second_type;
-
-  _T1 first;
-  _T2 second;
-  pair() : first(), second() {}
-  pair(const _T1& __a, const _T2& __b) : first(__a), second(__b) {}
-
-  template <class _U1, class _U2>
-  pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {}
-};
-
-template <class _T1, class _T2>
-inline bool operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
-{
-  return __x.first == __y.first && __x.second == __y.second;
-}
-
-template <class _T1, class _T2>
-inline bool operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
-{
-  return __x.first < __y.first ||
-         (!(__y.first < __x.first) && __x.second < __y.second);
-}
-
-template <class _T1, class _T2>
-inline bool operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
-  return !(__x == __y);
-}
-
-template <class _T1, class _T2>
-inline bool operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
-  return __y < __x;
-}
-
-template <class _T1, class _T2>
-inline bool operator<=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
-  return !(__y < __x);
-}
-
-template <class _T1, class _T2>
-inline bool operator>=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
-  return !(__x < __y);
-}
-
-template <class _T1, class _T2>
-inline pair<_T1, _T2> make_pair(_T1 __x, _T2 __y)
-{
-  return pair<_T1, _T2>(__x, __y);
-}
-
-__STL_END_NAMESPACE
-
-#endif /* __SGI_STL_INTERNAL_PAIR_H */
-
-// Local Variables:
-// mode:C++
-// End:
diff --git a/libstdc++/include/typeinfo b/libstdc++/include/typeinfo
deleted file mode 100644
index 4b48a79..0000000
--- a/libstdc++/include/typeinfo
+++ /dev/null
@@ -1,31 +0,0 @@
-#ifndef _TYPEINFO_HEADER_GAURD
-#define _TYPEINFO_HEADER_GAURD
-
-extern "C++" {
-
-namespace std {
-    class type_info;
-    class bad_cast;
-    class bad_typeid;
-};
-
-
-class type_info {
-public:
-    type_info();
-    virtual ~type_info();
-
-    char const * name() const;
-
-    bool operator==(type_info const & right) const;
-    bool operator!=(type_info const & right) const;
-    bool before(type_info const & right) const;
-
-private:
-    type_info(type_info const & right);
-    type_info & operator=(type_info const & right);
-};
-
-}  // C++
-
-#endif
diff --git a/libstdc++/include/utility b/libstdc++/include/utility
deleted file mode 100644
index 12044a7..0000000
--- a/libstdc++/include/utility
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-#ifndef _CPP_UTILITY
-#define _CPP_UTILITY
-
-#pragma GCC system_header
-
-#define  __STL_BEGIN_NAMESPACE  namespace std {
-#define  __STL_END_NAMESPACE    }
-
-#include <stl_pair.h>
-
-#endif /* _CPP_UTILITY */
diff --git a/linker/Android.bp b/linker/Android.bp
new file mode 100644
index 0000000..39f1da9
--- /dev/null
+++ b/linker/Android.bp
@@ -0,0 +1,148 @@
+cc_library_static {
+    name: "liblinker_malloc",
+    clang: true,
+
+    srcs: [
+        "linker_allocator.cpp",
+        "linker_memory.cpp",
+    ],
+
+    // We need to access Bionic private headers in the linker.
+    include_dirs: ["bionic/libc"],
+}
+
+cc_binary {
+    clang: true,
+
+    srcs: [
+        "dlfcn.cpp",
+        "linker.cpp",
+        "linker_block_allocator.cpp",
+        "linker_dlwarning.cpp",
+        "linker_gdb_support.cpp",
+        "linker_globals.cpp",
+        "linker_libc_support.c",
+        "linker_namespaces.cpp",
+        "linker_logger.cpp",
+        "linker_mapped_file_fragment.cpp",
+        "linker_phdr.cpp",
+        "linker_sdk_versions.cpp",
+        "linker_soinfo.cpp",
+        "linker_utils.cpp",
+        "rt.cpp",
+    ],
+
+    arch: {
+        arm: {
+            srcs: ["arch/arm/begin.S"],
+
+            cflags: ["-D__work_around_b_24465209__"],
+        },
+        arm64: {
+            srcs: ["arch/arm64/begin.S"],
+        },
+        x86: {
+            srcs: ["arch/x86/begin.c"],
+
+            cflags: ["-D__work_around_b_24465209__"],
+        },
+        x86_64: {
+            srcs: ["arch/x86_64/begin.S"],
+        },
+        mips: {
+            srcs: [
+                "arch/mips/begin.S",
+                "linker_mips.cpp",
+            ],
+        },
+        mips64: {
+            srcs: [
+                "arch/mips64/begin.S",
+                "linker_mips.cpp",
+            ],
+        },
+    },
+
+    // We need to access Bionic private headers in the linker.
+    include_dirs: ["bionic/libc"],
+
+    // -shared is used to overwrite the -Bstatic and -static
+    // flags triggered by LOCAL_FORCE_STATIC_EXECUTABLE.
+    // This dynamic linker is actually a shared object linked with static libraries.
+    ldflags: [
+        "-shared",
+        "-Wl,-Bsymbolic",
+        "-Wl,--exclude-libs,ALL",
+    ],
+
+    cflags: [
+        "-fno-stack-protector",
+        "-Wstrict-overflow=5",
+        "-fvisibility=hidden",
+        "-Wall",
+        "-Wextra",
+        "-Wunused",
+        "-Werror",
+    ],
+
+    // TODO: split out the asflags.
+    asflags: [
+        "-fno-stack-protector",
+        "-Wstrict-overflow=5",
+        "-fvisibility=hidden",
+        "-Wall",
+        "-Wextra",
+        "-Wunused",
+        "-Werror",
+    ],
+
+    conlyflags: ["-std=gnu99"],
+
+    cppflags: ["-Wold-style-cast"],
+
+    // we don't want crtbegin.o (because we have begin.o), so unset it
+    // just for this module
+    nocrt: true,
+
+    static_libs: [
+        "libc_nomalloc",
+        "libziparchive",
+        "libutils",
+        "libbase",
+        "libz",
+        "liblog",
+        "libdebuggerd_client",
+
+        // Important: The liblinker_malloc should be the last library in the list
+        // to overwrite any other malloc implementations by other static libraries.
+        "liblinker_malloc"
+    ],
+    static_executable: true,
+
+    name: "linker",
+    multilib: {
+        lib32: {
+            symlinks: ["linker_asan"],
+        },
+        lib64: {
+            suffix: "64",
+            symlinks: ["linker_asan64"],
+       },
+    },
+    target: {
+        android64: {
+            cflags: ["-DTARGET_IS_64_BIT"],
+        },
+    },
+    compile_multilib: "both",
+
+    // Leave the symbols in the shared library so that stack unwinders can produce
+    // meaningful name resolution.
+    strip: {
+        keep_symbols: true,
+    },
+
+    // Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb
+    // looking up symbols in the linker by mistake.
+    prefix_symbols: "__dl_",
+}
diff --git a/linker/Android.mk b/linker/Android.mk
index 4a4ca5c..ea7451c 100644
--- a/linker/Android.mk
+++ b/linker/Android.mk
@@ -1,107 +1,3 @@
 LOCAL_PATH := $(call my-dir)
 
-include $(CLEAR_VARS)
-
-LOCAL_CLANG := true
-
-LOCAL_SRC_FILES := \
-    debugger.cpp \
-    dlfcn.cpp \
-    linker.cpp \
-    linker_allocator.cpp \
-    linker_block_allocator.cpp \
-    linker_dlwarning.cpp \
-    linker_gdb_support.cpp \
-    linker_libc_support.c \
-    linker_mapped_file_fragment.cpp \
-    linker_memory.cpp \
-    linker_phdr.cpp \
-    linker_sdk_versions.cpp \
-    linker_utils.cpp \
-    rt.cpp \
-
-LOCAL_SRC_FILES_arm     := arch/arm/begin.S
-LOCAL_SRC_FILES_arm64   := arch/arm64/begin.S
-LOCAL_SRC_FILES_x86     := arch/x86/begin.c
-LOCAL_SRC_FILES_x86_64  := arch/x86_64/begin.S
-LOCAL_SRC_FILES_mips    := arch/mips/begin.S linker_mips.cpp
-LOCAL_SRC_FILES_mips64  := arch/mips64/begin.S linker_mips.cpp
-
-# -shared is used to overwrite the -Bstatic and -static
-# flags triggered by LOCAL_FORCE_STATIC_EXECUTABLE.
-# This dynamic linker is actually a shared object linked with static libraries.
-LOCAL_LDFLAGS := \
-    -shared \
-    -Wl,-Bsymbolic \
-    -Wl,--exclude-libs,ALL \
-
-LOCAL_CFLAGS += \
-    -fno-stack-protector \
-    -Wstrict-overflow=5 \
-    -fvisibility=hidden \
-    -Wall -Wextra -Wunused -Werror \
-
-LOCAL_CFLAGS_arm += -D__work_around_b_24465209__
-LOCAL_CFLAGS_x86 += -D__work_around_b_24465209__
-
-LOCAL_CONLYFLAGS += \
-    -std=gnu99 \
-
-LOCAL_CPPFLAGS += \
-    -Wold-style-cast \
-
-ifeq ($(TARGET_IS_64_BIT),true)
-LOCAL_CPPFLAGS += -DTARGET_IS_64_BIT
-endif
-
-# We need to access Bionic private headers in the linker.
-LOCAL_CFLAGS += -I$(LOCAL_PATH)/../libc/
-
-# we don't want crtbegin.o (because we have begin.o), so unset it
-# just for this module
-LOCAL_NO_CRT := true
-# TODO: split out the asflags.
-LOCAL_ASFLAGS := $(LOCAL_CFLAGS)
-
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
-LOCAL_STATIC_LIBRARIES := libc_nomalloc libziparchive libutils libbase libz liblog
-
-LOCAL_FORCE_STATIC_EXECUTABLE := true
-
-LOCAL_MODULE := linker
-LOCAL_MODULE_STEM_32 := linker
-LOCAL_MODULE_STEM_64 := linker64
-LOCAL_MULTILIB := both
-
-# Leave the symbols in the shared library so that stack unwinders can produce
-# meaningful name resolution.
-LOCAL_STRIP_MODULE := keep_symbols
-
-# Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb
-# looking up symbols in the linker by mistake.
-#
-# Note we are using "=" instead of ":=" to defer the evaluation,
-# because LOCAL_2ND_ARCH_VAR_PREFIX or linked_module isn't set properly yet at this point.
-LOCAL_POST_LINK_CMD = $(hide) $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY) \
-  --prefix-symbols=__dl_ $(linked_module)
-
-include $(BUILD_EXECUTABLE)
-
-
-define add-linker-symlink
-$(eval _from := $(TARGET_OUT)/bin/$(1))
-$(eval _to:=$(2))
-$(_from): $(LOCAL_MODULE_MAKEFILE)
-	@echo "Symlink: $$@ -> $(_to)"
-	@mkdir -p $$(dir $$@)
-	@rm -rf $$@
-	$(hide) ln -sf $(_to) $$@
-endef
-
-$(eval $(call add-linker-symlink,linker_asan,linker))
-ifeq ($(TARGET_IS_64_BIT),true)
-$(eval $(call add-linker-symlink,linker_asan64,linker64))
-endif
-
 include $(call first-makefiles-under,$(LOCAL_PATH))
diff --git a/linker/NOTICE b/linker/NOTICE
index 2c70ab8..3ba0ff9 100644
--- a/linker/NOTICE
+++ b/linker/NOTICE
@@ -174,3 +174,47 @@
 
 -------------------------------------------------------------------
 
+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.
+
+-------------------------------------------------------------------
+
+Copyright (C) 2016 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.
+
+-------------------------------------------------------------------
+
diff --git a/linker/debugger.cpp b/linker/debugger.cpp
deleted file mode 100644
index d4c7928..0000000
--- a/linker/debugger.cpp
+++ /dev/null
@@ -1,321 +0,0 @@
-/*
- * Copyright (C) 2008 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 "linker.h"
-#include "linker_gdb_support.h"
-
-#include <errno.h>
-#include <inttypes.h>
-#include <pthread.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/mman.h>
-#include <sys/prctl.h>
-#include <sys/socket.h>
-#include <sys/syscall.h>
-#include <sys/un.h>
-#include <unistd.h>
-
-extern "C" int tgkill(int tgid, int tid, int sig);
-
-// Crash actions have to be sent to the proper debuggerd.
-// On 64 bit systems, the 32 bit debuggerd is named differently.
-#if defined(TARGET_IS_64_BIT) && !defined(__LP64__)
-#define DEBUGGER_SOCKET_NAME "android:debuggerd32"
-#else
-#define DEBUGGER_SOCKET_NAME "android:debuggerd"
-#endif
-
-enum debugger_action_t {
-  // dump a crash
-  DEBUGGER_ACTION_CRASH,
-  // dump a tombstone file
-  DEBUGGER_ACTION_DUMP_TOMBSTONE,
-  // dump a backtrace only back to the socket
-  DEBUGGER_ACTION_DUMP_BACKTRACE,
-};
-
-// Message sent over the socket.
-// NOTE: Any changes to this structure must also be reflected in
-//       system/core/include/cutils/debugger.h.
-struct __attribute__((packed)) debugger_msg_t {
-  int32_t action;
-  pid_t tid;
-  uint64_t abort_msg_address;
-  int32_t original_si_code;
-};
-
-// see man(2) prctl, specifically the section about PR_GET_NAME
-#define MAX_TASK_NAME_LEN (16)
-
-static int socket_abstract_client(const char* name, int type) {
-  sockaddr_un addr;
-
-  // Test with length +1 for the *initial* '\0'.
-  size_t namelen = strlen(name);
-  if ((namelen + 1) > sizeof(addr.sun_path)) {
-    errno = EINVAL;
-    return -1;
-  }
-
-  // This is used for abstract socket namespace, we need
-  // an initial '\0' at the start of the Unix socket path.
-  //
-  // Note: The path in this case is *not* supposed to be
-  // '\0'-terminated. ("man 7 unix" for the gory details.)
-  memset(&addr, 0, sizeof(addr));
-  addr.sun_family = AF_LOCAL;
-  addr.sun_path[0] = 0;
-  memcpy(addr.sun_path + 1, name, namelen);
-
-  socklen_t alen = namelen + offsetof(sockaddr_un, sun_path) + 1;
-
-  int s = socket(AF_LOCAL, type, 0);
-  if (s == -1) {
-    return -1;
-  }
-
-  int rc = TEMP_FAILURE_RETRY(connect(s, reinterpret_cast<sockaddr*>(&addr), alen));
-  if (rc == -1) {
-    close(s);
-    return -1;
-  }
-
-  return s;
-}
-
-/*
- * Writes a summary of the signal to the log file.  We do this so that, if
- * for some reason we're not able to contact debuggerd, there is still some
- * indication of the failure in the log.
- *
- * We could be here as a result of native heap corruption, or while a
- * mutex is being held, so we don't want to use any libc functions that
- * could allocate memory or hold a lock.
- */
-static void log_signal_summary(int signum, const siginfo_t* info) {
-  const char* signal_name = "???";
-  bool has_address = false;
-  switch (signum) {
-    case SIGABRT:
-      signal_name = "SIGABRT";
-      break;
-    case SIGBUS:
-      signal_name = "SIGBUS";
-      has_address = true;
-      break;
-    case SIGFPE:
-      signal_name = "SIGFPE";
-      has_address = true;
-      break;
-    case SIGILL:
-      signal_name = "SIGILL";
-      has_address = true;
-      break;
-    case SIGSEGV:
-      signal_name = "SIGSEGV";
-      has_address = true;
-      break;
-#if defined(SIGSTKFLT)
-    case SIGSTKFLT:
-      signal_name = "SIGSTKFLT";
-      break;
-#endif
-    case SIGTRAP:
-      signal_name = "SIGTRAP";
-      break;
-  }
-
-  char thread_name[MAX_TASK_NAME_LEN + 1]; // one more for termination
-  if (prctl(PR_GET_NAME, reinterpret_cast<unsigned long>(thread_name), 0, 0, 0) != 0) {
-    strcpy(thread_name, "<name unknown>");
-  } else {
-    // short names are null terminated by prctl, but the man page
-    // implies that 16 byte names are not.
-    thread_name[MAX_TASK_NAME_LEN] = 0;
-  }
-
-  // "info" will be null if the siginfo_t information was not available.
-  // Many signals don't have an address or a code.
-  char code_desc[32]; // ", code -6"
-  char addr_desc[32]; // ", fault addr 0x1234"
-  addr_desc[0] = code_desc[0] = 0;
-  if (info != nullptr) {
-    // For a rethrown signal, this si_code will be right and the one debuggerd shows will
-    // always be SI_TKILL.
-    __libc_format_buffer(code_desc, sizeof(code_desc), ", code %d", info->si_code);
-    if (has_address) {
-      __libc_format_buffer(addr_desc, sizeof(addr_desc), ", fault addr %p", info->si_addr);
-    }
-  }
-  __libc_format_log(ANDROID_LOG_FATAL, "libc",
-                    "Fatal signal %d (%s)%s%s in tid %d (%s)",
-                    signum, signal_name, code_desc, addr_desc, gettid(), thread_name);
-}
-
-/*
- * Returns true if the handler for signal "signum" has SA_SIGINFO set.
- */
-static bool have_siginfo(int signum) {
-  struct sigaction old_action, new_action;
-
-  memset(&new_action, 0, sizeof(new_action));
-  new_action.sa_handler = SIG_DFL;
-  new_action.sa_flags = SA_RESTART;
-  sigemptyset(&new_action.sa_mask);
-
-  if (sigaction(signum, &new_action, &old_action) < 0) {
-    __libc_format_log(ANDROID_LOG_WARN, "libc", "Failed testing for SA_SIGINFO: %s",
-                      strerror(errno));
-    return false;
-  }
-  bool result = (old_action.sa_flags & SA_SIGINFO) != 0;
-
-  if (sigaction(signum, &old_action, nullptr) == -1) {
-    __libc_format_log(ANDROID_LOG_WARN, "libc", "Restore failed in test for SA_SIGINFO: %s",
-                      strerror(errno));
-  }
-  return result;
-}
-
-static void send_debuggerd_packet(siginfo_t* info) {
-  // Mutex to prevent multiple crashing threads from trying to talk
-  // to debuggerd at the same time.
-  static pthread_mutex_t crash_mutex = PTHREAD_MUTEX_INITIALIZER;
-  int ret = pthread_mutex_trylock(&crash_mutex);
-  if (ret != 0) {
-    if (ret == EBUSY) {
-      __libc_format_log(ANDROID_LOG_INFO, "libc",
-          "Another thread contacted debuggerd first; not contacting debuggerd.");
-      // This will never complete since the lock is never released.
-      pthread_mutex_lock(&crash_mutex);
-    } else {
-      __libc_format_log(ANDROID_LOG_INFO, "libc",
-                        "pthread_mutex_trylock failed: %s", strerror(ret));
-    }
-    return;
-  }
-
-  int s = socket_abstract_client(DEBUGGER_SOCKET_NAME, SOCK_STREAM | SOCK_CLOEXEC);
-  if (s == -1) {
-    __libc_format_log(ANDROID_LOG_FATAL, "libc", "Unable to open connection to debuggerd: %s",
-                      strerror(errno));
-    return;
-  }
-
-  // debuggerd knows our pid from the credentials on the
-  // local socket but we need to tell it the tid of the crashing thread.
-  // debuggerd will be paranoid and verify that we sent a tid
-  // that's actually in our process.
-  debugger_msg_t msg;
-  msg.action = DEBUGGER_ACTION_CRASH;
-  msg.tid = gettid();
-  msg.abort_msg_address = reinterpret_cast<uintptr_t>(g_abort_message);
-  msg.original_si_code = (info != nullptr) ? info->si_code : 0;
-  ret = TEMP_FAILURE_RETRY(write(s, &msg, sizeof(msg)));
-  if (ret == sizeof(msg)) {
-    char debuggerd_ack;
-    ret = TEMP_FAILURE_RETRY(read(s, &debuggerd_ack, 1));
-    int saved_errno = errno;
-    notify_gdb_of_libraries();
-    errno = saved_errno;
-  } else {
-    // read or write failed -- broken connection?
-    __libc_format_log(ANDROID_LOG_FATAL, "libc", "Failed while talking to debuggerd: %s",
-                      strerror(errno));
-  }
-
-  close(s);
-}
-
-/*
- * Catches fatal signals so we can ask debuggerd to ptrace us before
- * we crash.
- */
-static void debuggerd_signal_handler(int signal_number, siginfo_t* info, void*) {
-  // It's possible somebody cleared the SA_SIGINFO flag, which would mean
-  // our "info" arg holds an undefined value.
-  if (!have_siginfo(signal_number)) {
-    info = nullptr;
-  }
-
-  log_signal_summary(signal_number, info);
-
-  send_debuggerd_packet(info);
-
-  // We need to return from the signal handler so that debuggerd can dump the
-  // thread that crashed, but returning here does not guarantee that the signal
-  // will be thrown again, even for SIGSEGV and friends, since the signal could
-  // have been sent manually. Resend the signal with rt_tgsigqueueinfo(2) to
-  // preserve the SA_SIGINFO contents.
-  signal(signal_number, SIG_DFL);
-
-  struct siginfo si;
-  if (!info) {
-    memset(&si, 0, sizeof(si));
-    si.si_code = SI_USER;
-    si.si_pid = getpid();
-    si.si_uid = getuid();
-    info = &si;
-  } else if (info->si_code >= 0 || info->si_code == SI_TKILL) {
-    // rt_tgsigqueueinfo(2)'s documentation appears to be incorrect on kernels
-    // that contain commit 66dd34a (3.9+). The manpage claims to only allow
-    // negative si_code values that are not SI_TKILL, but 66dd34a changed the
-    // check to allow all si_code values in calls coming from inside the house.
-  }
-
-  int rc = syscall(SYS_rt_tgsigqueueinfo, getpid(), gettid(), signal_number, info);
-  if (rc != 0) {
-    __libc_format_log(ANDROID_LOG_FATAL, "libc", "failed to resend signal during crash: %s",
-                      strerror(errno));
-    _exit(0);
-  }
-}
-
-__LIBC_HIDDEN__ void debuggerd_init() {
-  struct sigaction action;
-  memset(&action, 0, sizeof(action));
-  sigemptyset(&action.sa_mask);
-  action.sa_sigaction = debuggerd_signal_handler;
-  action.sa_flags = SA_RESTART | SA_SIGINFO;
-
-  // Use the alternate signal stack if available so we can catch stack overflows.
-  action.sa_flags |= SA_ONSTACK;
-
-  sigaction(SIGABRT, &action, nullptr);
-  sigaction(SIGBUS, &action, nullptr);
-  sigaction(SIGFPE, &action, nullptr);
-  sigaction(SIGILL, &action, nullptr);
-  sigaction(SIGSEGV, &action, nullptr);
-#if defined(SIGSTKFLT)
-  sigaction(SIGSTKFLT, &action, nullptr);
-#endif
-  sigaction(SIGTRAP, &action, nullptr);
-}
diff --git a/linker/dlfcn.cpp b/linker/dlfcn.cpp
index 12dd039..4d9a218 100644
--- a/linker/dlfcn.cpp
+++ b/linker/dlfcn.cpp
@@ -15,6 +15,7 @@
  */
 
 #include "linker.h"
+#include "linker_globals.h"
 #include "linker_dlwarning.h"
 
 #include <pthread.h>
@@ -69,6 +70,7 @@
 static void* dlopen_ext(const char* filename, int flags,
                         const android_dlextinfo* extinfo, void* caller_addr) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
+  g_linker_logger.ResetState();
   void* result = do_dlopen(filename, flags, extinfo, caller_addr);
   if (result == nullptr) {
     __bionic_format_dlerror("dlopen failed", linker_get_error_buffer());
@@ -89,6 +91,7 @@
 
 void* dlsym_impl(void* handle, const char* symbol, const char* version, void* caller_addr) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
+  g_linker_logger.ResetState();
   void* result;
   if (!do_dlsym(handle, symbol, version, caller_addr, &result)) {
     __bionic_format_dlerror(linker_get_error_buffer(), nullptr);
@@ -182,14 +185,14 @@
     { name_offset, \
       reinterpret_cast<Elf32_Addr>(value), \
       /* st_size */ 0, \
-      (shndx == 0) ? 0 : (STB_GLOBAL << 4), \
+      ((shndx) == 0) ? 0 : (STB_GLOBAL << 4), \
       /* st_other */ 0, \
       shndx, \
     }
 
 #define ELF64_SYM_INITIALIZER(name_offset, value, shndx) \
     { name_offset, \
-      (shndx == 0) ? 0 : (STB_GLOBAL << 4), \
+      ((shndx) == 0) ? 0 : (STB_GLOBAL << 4), \
       /* st_other */ 0, \
       shndx, \
       reinterpret_cast<Elf64_Addr>(value), \
@@ -259,8 +262,6 @@
 static uint8_t __libdl_info_buf[sizeof(soinfo)] __attribute__((aligned(8)));
 static soinfo* __libdl_info = nullptr;
 
-extern android_namespace_t g_default_namespace;
-
 // This is used by the dynamic linker. Every process gets these symbols for free.
 soinfo* get_libdl_info() {
   if (__libdl_info == nullptr) {
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 48638a8..9b90028 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -53,8 +53,10 @@
 #include "linker.h"
 #include "linker_block_allocator.h"
 #include "linker_gdb_support.h"
+#include "linker_globals.h"
 #include "linker_debug.h"
 #include "linker_dlwarning.h"
+#include "linker_namespaces.h"
 #include "linker_sleb128.h"
 #include "linker_phdr.h"
 #include "linker_relocs.h"
@@ -62,6 +64,8 @@
 #include "linker_utils.h"
 
 #include "android-base/strings.h"
+#include "android-base/stringprintf.h"
+#include "debuggerd/client.h"
 #include "ziparchive/zip_archive.h"
 
 extern void __libc_init_globals(KernelArgumentBlock&);
@@ -73,74 +77,6 @@
 #undef ELF_ST_TYPE
 #define ELF_ST_TYPE(x) (static_cast<uint32_t>(x) & 0xf)
 
-struct android_namespace_t {
- public:
-  android_namespace_t() : name_(nullptr), is_isolated_(false) {}
-
-  const char* get_name() const { return name_; }
-  void set_name(const char* name) { name_ = name; }
-
-  bool is_isolated() const { return is_isolated_; }
-  void set_isolated(bool isolated) { is_isolated_ = isolated; }
-
-  const std::vector<std::string>& get_ld_library_paths() const {
-    return ld_library_paths_;
-  }
-  void set_ld_library_paths(std::vector<std::string>&& library_paths) {
-    ld_library_paths_ = library_paths;
-  }
-
-  const std::vector<std::string>& get_default_library_paths() const {
-    return default_library_paths_;
-  }
-  void set_default_library_paths(std::vector<std::string>&& library_paths) {
-    default_library_paths_ = library_paths;
-  }
-
-  const std::vector<std::string>& get_permitted_paths() const {
-    return permitted_paths_;
-  }
-  void set_permitted_paths(std::vector<std::string>&& permitted_paths) {
-    permitted_paths_ = permitted_paths;
-  }
-
-  void add_soinfo(soinfo* si) {
-    soinfo_list_.push_back(si);
-  }
-
-  void add_soinfos(const soinfo::soinfo_list_t& soinfos) {
-    for (auto si : soinfos) {
-      add_soinfo(si);
-      si->add_secondary_namespace(this);
-    }
-  }
-
-  void remove_soinfo(soinfo* si) {
-    soinfo_list_.remove_if([&](soinfo* candidate) {
-      return si == candidate;
-    });
-  }
-
-  const soinfo::soinfo_list_t& soinfo_list() const { return soinfo_list_; }
-
-  // For isolated namespaces - checks if the file is on the search path;
-  // always returns true for not isolated namespace.
-  bool is_accessible(const std::string& path);
-
- private:
-  const char* name_;
-  bool is_isolated_;
-  std::vector<std::string> ld_library_paths_;
-  std::vector<std::string> default_library_paths_;
-  std::vector<std::string> permitted_paths_;
-  soinfo::soinfo_list_t soinfo_list_;
-
-  DISALLOW_COPY_AND_ASSIGN(android_namespace_t);
-};
-
-android_namespace_t g_default_namespace;
-
-static std::unordered_map<uintptr_t, soinfo*> g_soinfo_handles_map;
 static android_namespace_t* g_anonymous_namespace = &g_default_namespace;
 
 static ElfW(Addr) get_elf_exec_load_bias(const ElfW(Ehdr)* elf);
@@ -196,8 +132,6 @@
 static const char* const kSystemLibDir = "/system/lib";
 #endif
 
-static std::string dirname(const char *path);
-
 // TODO(dimitry): The grey-list is a workaround for http://b/26394120 ---
 // gradually remove libraries from this list until it is gone.
 static bool is_greylisted(const char* name, const soinfo* needed_by) {
@@ -248,28 +182,16 @@
 }
 // END OF WORKAROUND
 
-static const ElfW(Versym) kVersymNotNeeded = 0;
-static const ElfW(Versym) kVersymGlobal = 1;
-
 static const char* const* g_default_ld_paths;
 static std::vector<std::string> g_ld_preload_names;
 
 static std::vector<soinfo*> g_ld_preloads;
 
 static bool g_public_namespace_initialized;
-static soinfo::soinfo_list_t g_public_namespace;
+static soinfo_list_t g_public_namespace;
 
-__LIBC_HIDDEN__ int g_ld_debug_verbosity;
-
-__LIBC_HIDDEN__ abort_msg_t* g_abort_message = nullptr; // For debuggerd.
-
-static std::string dirname(const char *path) {
-  const char* last_slash = strrchr(path, '/');
-  if (last_slash == path) return "/";
-  else if (last_slash == nullptr) return ".";
-  else
-    return std::string(path, last_slash - path);
-}
+int g_ld_debug_verbosity;
+abort_msg_t* g_abort_message = nullptr; // For debuggerd.
 
 #if STATS
 struct linker_stats_t {
@@ -290,16 +212,6 @@
 uint32_t bitmask[4096];
 #endif
 
-static char __linker_dl_err_buf[768];
-
-char* linker_get_error_buffer() {
-  return &__linker_dl_err_buf[0];
-}
-
-size_t linker_get_error_buffer_size() {
-  return sizeof(__linker_dl_err_buf);
-}
-
 static void notify_gdb_of_load(soinfo* info) {
   if (info->is_linker() || info->is_main_executable()) {
     // gdb already knows about the linker and the main executable.
@@ -323,32 +235,6 @@
   notify_gdb_of_unload(&(info->link_map_head));
 }
 
-bool android_namespace_t::is_accessible(const std::string& file) {
-  if (!is_isolated_) {
-    return true;
-  }
-
-  for (const auto& dir : ld_library_paths_) {
-    if (file_is_in_dir(file, dir)) {
-      return true;
-    }
-  }
-
-  for (const auto& dir : default_library_paths_) {
-    if (file_is_in_dir(file, dir)) {
-      return true;
-    }
-  }
-
-  for (const auto& dir : permitted_paths_) {
-    if (file_is_under_dir(file, dir)) {
-      return true;
-    }
-  }
-
-  return false;
-}
-
 LinkedListEntry<soinfo>* SoinfoListAllocator::alloc() {
   return g_soinfo_links_allocator.alloc();
 }
@@ -432,60 +318,6 @@
   g_soinfo_allocator.free(si);
 }
 
-// For every path element this function checks of it exists, and is a directory,
-// and normalizes it:
-// 1. For regular path it converts it to realpath()
-// 2. For path in a zip file it uses realpath on the zipfile
-//    normalizes entry name by calling normalize_path function.
-static void resolve_paths(std::vector<std::string>& paths,
-                          std::vector<std::string>* resolved_paths) {
-  resolved_paths->clear();
-  for (const auto& path : paths) {
-    char resolved_path[PATH_MAX];
-    const char* original_path = path.c_str();
-    if (realpath(original_path, resolved_path) != nullptr) {
-      struct stat s;
-      if (stat(resolved_path, &s) == 0) {
-        if (S_ISDIR(s.st_mode)) {
-          resolved_paths->push_back(resolved_path);
-        } else {
-          DL_WARN("Warning: \"%s\" is not a directory (excluding from path)", resolved_path);
-          continue;
-        }
-      } else {
-        DL_WARN("Warning: cannot stat file \"%s\": %s", resolved_path, strerror(errno));
-        continue;
-      }
-    } else {
-      std::string zip_path;
-      std::string entry_path;
-
-      std::string normalized_path;
-
-      if (!normalize_path(original_path, &normalized_path)) {
-        DL_WARN("Warning: unable to normalize \"%s\"", original_path);
-        continue;
-      }
-
-      if (parse_zip_path(normalized_path.c_str(), &zip_path, &entry_path)) {
-        if (realpath(zip_path.c_str(), resolved_path) == nullptr) {
-          DL_WARN("Warning: unable to resolve \"%s\": %s", zip_path.c_str(), strerror(errno));
-          continue;
-        }
-
-        resolved_paths->push_back(std::string(resolved_path) + kZipFileSeparator + entry_path);
-      }
-    }
-  }
-}
-
-static void split_path(const char* path, const char* delimiters,
-                       std::vector<std::string>* paths) {
-  if (path != nullptr && path[0] != 0) {
-    *paths = android::base::Split(path, delimiters);
-  }
-}
-
 static void parse_path(const char* path, const char* delimiters,
                        std::vector<std::string>* resolved_paths) {
   std::vector<std::string> paths;
@@ -499,45 +331,6 @@
   g_default_namespace.set_ld_library_paths(std::move(ld_libary_paths));
 }
 
-void soinfo::set_dt_runpath(const char* path) {
-  if (!has_min_version(3)) {
-    return;
-  }
-
-  std::vector<std::string> runpaths;
-
-  split_path(path, ":", &runpaths);
-
-  std::string origin = dirname(get_realpath());
-  // FIXME: add $LIB and $PLATFORM.
-  std::pair<std::string, std::string> substs[] = {{"ORIGIN", origin}};
-  for (auto&& s : runpaths) {
-    size_t pos = 0;
-    while (pos < s.size()) {
-      pos = s.find("$", pos);
-      if (pos == std::string::npos) break;
-      for (const auto& subst : substs) {
-        const std::string& token = subst.first;
-        const std::string& replacement = subst.second;
-        if (s.substr(pos + 1, token.size()) == token) {
-          s.replace(pos, token.size() + 1, replacement);
-          // -1 to compensate for the ++pos below.
-          pos += replacement.size() - 1;
-          break;
-        } else if (s.substr(pos + 1, token.size() + 2) == "{" + token + "}") {
-          s.replace(pos, token.size() + 3, replacement);
-          pos += replacement.size() - 1;
-          break;
-        }
-      }
-      // Skip $ in case it did not match any of the known substitutions.
-      ++pos;
-    }
-  }
-
-  resolve_paths(runpaths, &dt_runpath_);
-}
-
 static void parse_LD_PRELOAD(const char* path) {
   g_ld_preload_names.clear();
   if (path != nullptr) {
@@ -604,336 +397,10 @@
   return rv;
 }
 
-const ElfW(Versym)* soinfo::get_versym(size_t n) const {
-  if (has_min_version(2) && versym_ != nullptr) {
-    return versym_ + n;
-  }
-
-  return nullptr;
-}
-
-ElfW(Addr) soinfo::get_verneed_ptr() const {
-  if (has_min_version(2)) {
-    return verneed_ptr_;
-  }
-
-  return 0;
-}
-
-size_t soinfo::get_verneed_cnt() const {
-  if (has_min_version(2)) {
-    return verneed_cnt_;
-  }
-
-  return 0;
-}
-
-ElfW(Addr) soinfo::get_verdef_ptr() const {
-  if (has_min_version(2)) {
-    return verdef_ptr_;
-  }
-
-  return 0;
-}
-
-size_t soinfo::get_verdef_cnt() const {
-  if (has_min_version(2)) {
-    return verdef_cnt_;
-  }
-
-  return 0;
-}
-
-template<typename F>
-static bool for_each_verdef(const soinfo* si, F functor) {
-  if (!si->has_min_version(2)) {
-    return true;
-  }
-
-  uintptr_t verdef_ptr = si->get_verdef_ptr();
-  if (verdef_ptr == 0) {
-    return true;
-  }
-
-  size_t offset = 0;
-
-  size_t verdef_cnt = si->get_verdef_cnt();
-  for (size_t i = 0; i<verdef_cnt; ++i) {
-    const ElfW(Verdef)* verdef = reinterpret_cast<ElfW(Verdef)*>(verdef_ptr + offset);
-    size_t verdaux_offset = offset + verdef->vd_aux;
-    offset += verdef->vd_next;
-
-    if (verdef->vd_version != 1) {
-      DL_ERR("unsupported verdef[%zd] vd_version: %d (expected 1) library: %s",
-          i, verdef->vd_version, si->get_realpath());
-      return false;
-    }
-
-    if ((verdef->vd_flags & VER_FLG_BASE) != 0) {
-      // "this is the version of the file itself.  It must not be used for
-      //  matching a symbol. It can be used to match references."
-      //
-      // http://www.akkadia.org/drepper/symbol-versioning
-      continue;
-    }
-
-    if (verdef->vd_cnt == 0) {
-      DL_ERR("invalid verdef[%zd] vd_cnt == 0 (version without a name)", i);
-      return false;
-    }
-
-    const ElfW(Verdaux)* verdaux = reinterpret_cast<ElfW(Verdaux)*>(verdef_ptr + verdaux_offset);
-
-    if (functor(i, verdef, verdaux) == true) {
-      break;
-    }
-  }
-
-  return true;
-}
-
-bool soinfo::find_verdef_version_index(const version_info* vi, ElfW(Versym)* versym) const {
-  if (vi == nullptr) {
-    *versym = kVersymNotNeeded;
-    return true;
-  }
-
-  *versym = kVersymGlobal;
-
-  return for_each_verdef(this,
-    [&](size_t, const ElfW(Verdef)* verdef, const ElfW(Verdaux)* verdaux) {
-      if (verdef->vd_hash == vi->elf_hash &&
-          strcmp(vi->name, get_string(verdaux->vda_name)) == 0) {
-        *versym = verdef->vd_ndx;
-        return true;
-      }
-
-      return false;
-    }
-  );
-}
-
-bool soinfo::find_symbol_by_name(SymbolName& symbol_name,
-                                 const version_info* vi,
-                                 const ElfW(Sym)** symbol) const {
-  uint32_t symbol_index;
-  bool success =
-      is_gnu_hash() ?
-      gnu_lookup(symbol_name, vi, &symbol_index) :
-      elf_lookup(symbol_name, vi, &symbol_index);
-
-  if (success) {
-    *symbol = symbol_index == 0 ? nullptr : symtab_ + symbol_index;
-  }
-
-  return success;
-}
-
-static bool is_symbol_global_and_defined(const soinfo* si, const ElfW(Sym)* s) {
-  if (ELF_ST_BIND(s->st_info) == STB_GLOBAL ||
-      ELF_ST_BIND(s->st_info) == STB_WEAK) {
-    return s->st_shndx != SHN_UNDEF;
-  } else if (ELF_ST_BIND(s->st_info) != STB_LOCAL) {
-    DL_WARN("unexpected ST_BIND value: %d for \"%s\" in \"%s\"",
-            ELF_ST_BIND(s->st_info), si->get_string(s->st_name), si->get_realpath());
-  }
-
-  return false;
-}
-
-static const ElfW(Versym) kVersymHiddenBit = 0x8000;
-
-static inline bool is_versym_hidden(const ElfW(Versym)* versym) {
-  // the symbol is hidden if bit 15 of versym is set.
-  return versym != nullptr && (*versym & kVersymHiddenBit) != 0;
-}
-
-static inline bool check_symbol_version(const ElfW(Versym) verneed,
-                                        const ElfW(Versym)* verdef) {
-  return verneed == kVersymNotNeeded ||
-      verdef == nullptr ||
-      verneed == (*verdef & ~kVersymHiddenBit);
-}
-
-bool soinfo::gnu_lookup(SymbolName& symbol_name,
-                        const version_info* vi,
-                        uint32_t* symbol_index) const {
-  uint32_t hash = symbol_name.gnu_hash();
-  uint32_t h2 = hash >> gnu_shift2_;
-
-  uint32_t bloom_mask_bits = sizeof(ElfW(Addr))*8;
-  uint32_t word_num = (hash / bloom_mask_bits) & gnu_maskwords_;
-  ElfW(Addr) bloom_word = gnu_bloom_filter_[word_num];
-
-  *symbol_index = 0;
-
-  TRACE_TYPE(LOOKUP, "SEARCH %s in %s@%p (gnu)",
-      symbol_name.get_name(), get_realpath(), reinterpret_cast<void*>(base));
-
-  // test against bloom filter
-  if ((1 & (bloom_word >> (hash % bloom_mask_bits)) & (bloom_word >> (h2 % bloom_mask_bits))) == 0) {
-    TRACE_TYPE(LOOKUP, "NOT FOUND %s in %s@%p",
-        symbol_name.get_name(), get_realpath(), reinterpret_cast<void*>(base));
-
-    return true;
-  }
-
-  // bloom test says "probably yes"...
-  uint32_t n = gnu_bucket_[hash % gnu_nbucket_];
-
-  if (n == 0) {
-    TRACE_TYPE(LOOKUP, "NOT FOUND %s in %s@%p",
-        symbol_name.get_name(), get_realpath(), reinterpret_cast<void*>(base));
-
-    return true;
-  }
-
-  // lookup versym for the version definition in this library
-  // note the difference between "version is not requested" (vi == nullptr)
-  // and "version not found". In the first case verneed is kVersymNotNeeded
-  // which implies that the default version can be accepted; the second case results in
-  // verneed = 1 (kVersymGlobal) and implies that we should ignore versioned symbols
-  // for this library and consider only *global* ones.
-  ElfW(Versym) verneed = 0;
-  if (!find_verdef_version_index(vi, &verneed)) {
-    return false;
-  }
-
-  do {
-    ElfW(Sym)* s = symtab_ + n;
-    const ElfW(Versym)* verdef = get_versym(n);
-    // skip hidden versions when verneed == kVersymNotNeeded (0)
-    if (verneed == kVersymNotNeeded && is_versym_hidden(verdef)) {
-        continue;
-    }
-    if (((gnu_chain_[n] ^ hash) >> 1) == 0 &&
-        check_symbol_version(verneed, verdef) &&
-        strcmp(get_string(s->st_name), symbol_name.get_name()) == 0 &&
-        is_symbol_global_and_defined(this, s)) {
-      TRACE_TYPE(LOOKUP, "FOUND %s in %s (%p) %zd",
-          symbol_name.get_name(), get_realpath(), reinterpret_cast<void*>(s->st_value),
-          static_cast<size_t>(s->st_size));
-      *symbol_index = n;
-      return true;
-    }
-  } while ((gnu_chain_[n++] & 1) == 0);
-
-  TRACE_TYPE(LOOKUP, "NOT FOUND %s in %s@%p",
-             symbol_name.get_name(), get_realpath(), reinterpret_cast<void*>(base));
-
-  return true;
-}
-
-bool soinfo::elf_lookup(SymbolName& symbol_name,
-                        const version_info* vi,
-                        uint32_t* symbol_index) const {
-  uint32_t hash = symbol_name.elf_hash();
-
-  TRACE_TYPE(LOOKUP, "SEARCH %s in %s@%p h=%x(elf) %zd",
-             symbol_name.get_name(), get_realpath(),
-             reinterpret_cast<void*>(base), hash, hash % nbucket_);
-
-  ElfW(Versym) verneed = 0;
-  if (!find_verdef_version_index(vi, &verneed)) {
-    return false;
-  }
-
-  for (uint32_t n = bucket_[hash % nbucket_]; n != 0; n = chain_[n]) {
-    ElfW(Sym)* s = symtab_ + n;
-    const ElfW(Versym)* verdef = get_versym(n);
-
-    // skip hidden versions when verneed == 0
-    if (verneed == kVersymNotNeeded && is_versym_hidden(verdef)) {
-        continue;
-    }
-
-    if (check_symbol_version(verneed, verdef) &&
-        strcmp(get_string(s->st_name), symbol_name.get_name()) == 0 &&
-        is_symbol_global_and_defined(this, s)) {
-      TRACE_TYPE(LOOKUP, "FOUND %s in %s (%p) %zd",
-                 symbol_name.get_name(), get_realpath(),
-                 reinterpret_cast<void*>(s->st_value),
-                 static_cast<size_t>(s->st_size));
-      *symbol_index = n;
-      return true;
-    }
-  }
-
-  TRACE_TYPE(LOOKUP, "NOT FOUND %s in %s@%p %x %zd",
-             symbol_name.get_name(), get_realpath(),
-             reinterpret_cast<void*>(base), hash, hash % nbucket_);
-
-  *symbol_index = 0;
-  return true;
-}
-
-soinfo::soinfo(android_namespace_t* ns, const char* realpath,
-               const struct stat* file_stat, off64_t file_offset,
-               int rtld_flags) {
-  memset(this, 0, sizeof(*this));
-
-  if (realpath != nullptr) {
-    realpath_ = realpath;
-  }
-
-  flags_ = FLAG_NEW_SOINFO;
-  version_ = SOINFO_VERSION;
-
-  if (file_stat != nullptr) {
-    this->st_dev_ = file_stat->st_dev;
-    this->st_ino_ = file_stat->st_ino;
-    this->file_offset_ = file_offset;
-  }
-
-  this->rtld_flags_ = rtld_flags;
-  this->primary_namespace_ = ns;
-}
-
-soinfo::~soinfo() {
-  g_soinfo_handles_map.erase(handle_);
-}
-
-static uint32_t calculate_elf_hash(const char* name) {
-  const uint8_t* name_bytes = reinterpret_cast<const uint8_t*>(name);
-  uint32_t h = 0, g;
-
-  while (*name_bytes) {
-    h = (h << 4) + *name_bytes++;
-    g = h & 0xf0000000;
-    h ^= g;
-    h ^= g >> 24;
-  }
-
-  return h;
-}
-
-uint32_t SymbolName::elf_hash() {
-  if (!has_elf_hash_) {
-    elf_hash_ = calculate_elf_hash(name_);
-    has_elf_hash_ = true;
-  }
-
-  return elf_hash_;
-}
-
-uint32_t SymbolName::gnu_hash() {
-  if (!has_gnu_hash_) {
-    uint32_t h = 5381;
-    const uint8_t* name = reinterpret_cast<const uint8_t*>(name_);
-    while (*name != 0) {
-      h += (h << 5) + *name++; // h*33 + c = h + h * 32 + c = h + h << 5 + c
-    }
-
-    gnu_hash_ =  h;
-    has_gnu_hash_ = true;
-  }
-
-  return gnu_hash_;
-}
 
 bool soinfo_do_lookup(soinfo* si_from, const char* name, const version_info* vi,
-                      soinfo** si_found_in, const soinfo::soinfo_list_t& global_group,
-                      const soinfo::soinfo_list_t& local_group, const ElfW(Sym)** symbol) {
+                      soinfo** si_found_in, const soinfo_list_t& global_group,
+                      const soinfo_list_t& local_group, const ElfW(Sym)** symbol) {
   SymbolName symbol_name(name);
   const ElfW(Sym)* s = nullptr;
 
@@ -1388,52 +855,6 @@
   return nullptr;
 }
 
-ElfW(Sym)* soinfo::find_symbol_by_address(const void* addr) {
-  return is_gnu_hash() ? gnu_addr_lookup(addr) : elf_addr_lookup(addr);
-}
-
-static bool symbol_matches_soaddr(const ElfW(Sym)* sym, ElfW(Addr) soaddr) {
-  return sym->st_shndx != SHN_UNDEF &&
-      soaddr >= sym->st_value &&
-      soaddr < sym->st_value + sym->st_size;
-}
-
-ElfW(Sym)* soinfo::gnu_addr_lookup(const void* addr) {
-  ElfW(Addr) soaddr = reinterpret_cast<ElfW(Addr)>(addr) - load_bias;
-
-  for (size_t i = 0; i < gnu_nbucket_; ++i) {
-    uint32_t n = gnu_bucket_[i];
-
-    if (n == 0) {
-      continue;
-    }
-
-    do {
-      ElfW(Sym)* sym = symtab_ + n;
-      if (symbol_matches_soaddr(sym, soaddr)) {
-        return sym;
-      }
-    } while ((gnu_chain_[n++] & 1) == 0);
-  }
-
-  return nullptr;
-}
-
-ElfW(Sym)* soinfo::elf_addr_lookup(const void* addr) {
-  ElfW(Addr) soaddr = reinterpret_cast<ElfW(Addr)>(addr) - load_bias;
-
-  // Search the library's symbol table for any defined symbol which
-  // contains this address.
-  for (size_t i = 0; i < nchain_; ++i) {
-    ElfW(Sym)* sym = symtab_ + i;
-    if (symbol_matches_soaddr(sym, soaddr)) {
-      return sym;
-    }
-  }
-
-  return nullptr;
-}
-
 class ZipArchiveCache {
  public:
   ZipArchiveCache() {}
@@ -1948,8 +1369,8 @@
 //
 // This group consists of the main executable, LD_PRELOADs
 // and libraries with the DF_1_GLOBAL flag set.
-static soinfo::soinfo_list_t make_global_group(android_namespace_t* ns) {
-  soinfo::soinfo_list_t global_group;
+static soinfo_list_t make_global_group(android_namespace_t* ns) {
+  soinfo_list_t global_group;
   ns->soinfo_list().for_each([&](soinfo* si) {
     if ((si->get_dt_flags_1() & DF_1_GLOBAL) != 0) {
       global_group.push_back(si);
@@ -1964,12 +1385,12 @@
 // group (see make_global_group). For all others this is a group
 // of RTLD_GLOBAL libraries (which includes the global group from
 // the default namespace).
-static soinfo::soinfo_list_t get_shared_group(android_namespace_t* ns) {
+static soinfo_list_t get_shared_group(android_namespace_t* ns) {
   if (ns == &g_default_namespace) {
     return make_global_group(ns);
   }
 
-  soinfo::soinfo_list_t shared_group;
+  soinfo_list_t shared_group;
   ns->soinfo_list().for_each([&](soinfo* si) {
     if ((si->get_rtld_flags() & RTLD_GLOBAL) != 0) {
       shared_group.push_back(si);
@@ -2009,7 +1430,7 @@
   }
 
   // Construct global_group.
-  soinfo::soinfo_list_t global_group = make_global_group(ns);
+  soinfo_list_t global_group = make_global_group(ns);
 
   // If soinfos array is null allocate one on stack.
   // The array is needed in case of failure; for example
@@ -2116,7 +1537,7 @@
 
 
   // Step 5: link libraries.
-  soinfo::soinfo_list_t local_group;
+  soinfo_list_t local_group;
   walk_dependencies_tree(
       (start_with != nullptr && add_as_children) ? &start_with : soinfos,
       (start_with != nullptr && add_as_children) ? 1 : soinfos_count,
@@ -2196,7 +1617,7 @@
     return;
   }
 
-  soinfo::soinfo_list_t unload_list;
+  soinfo_list_t unload_list;
   for (size_t i = 0; i < count; ++i) {
     soinfo* si = soinfos[i];
 
@@ -2219,8 +1640,8 @@
   // linked. This is why we can safely use the first one.
   soinfo* root = soinfos[0];
 
-  soinfo::soinfo_list_t local_unload_list;
-  soinfo::soinfo_list_t external_unload_list;
+  soinfo_list_t local_unload_list;
+  soinfo_list_t external_unload_list;
   soinfo* si = nullptr;
 
   while ((si = unload_list.pop_front()) != nullptr) {
@@ -2330,17 +1751,54 @@
   parse_LD_LIBRARY_PATH(ld_library_path);
 }
 
+static std::string android_dlextinfo_to_string(const android_dlextinfo* info) {
+  if (info == nullptr) {
+    return "(null)";
+  }
+
+  return android::base::StringPrintf("[flags=0x%" PRIx64 ","
+                                     " reserved_addr=%p,"
+                                     " reserved_size=0x%zx,"
+                                     " relro_fd=%d,"
+                                     " library_fd=%d,"
+                                     " library_fd_offset=0x%" PRIx64 ","
+                                     " library_namespace=%s@%p]",
+                                     info->flags,
+                                     info->reserved_addr,
+                                     info->reserved_size,
+                                     info->relro_fd,
+                                     info->library_fd,
+                                     info->library_fd_offset,
+                                     (info->flags & ANDROID_DLEXT_USE_NAMESPACE) != 0 ?
+                                        (info->library_namespace != nullptr ?
+                                          info->library_namespace->get_name() : "(null)") : "(n/a)",
+                                     (info->flags & ANDROID_DLEXT_USE_NAMESPACE) != 0 ?
+                                        info->library_namespace : nullptr);
+}
+
 void* do_dlopen(const char* name, int flags, const android_dlextinfo* extinfo,
                   void* caller_addr) {
   soinfo* const caller = find_containing_library(caller_addr);
+  android_namespace_t* ns = get_caller_namespace(caller);
+
+  LD_LOG(kLogDlopen,
+         "dlopen(name=\"%s\", flags=0x%x, extinfo=%s, caller=\"%s\", caller_ns=%s@%p) ...",
+         name,
+         flags,
+         android_dlextinfo_to_string(extinfo).c_str(),
+         caller == nullptr ? "(null)" : caller->get_realpath(),
+         ns == nullptr ? "(null)" : ns->get_name(),
+         ns);
+
+  auto failure_guard = make_scope_guard([&]() {
+    LD_LOG(kLogDlopen, "... dlopen failed: %s", linker_get_error_buffer());
+  });
 
   if ((flags & ~(RTLD_NOW|RTLD_LAZY|RTLD_LOCAL|RTLD_GLOBAL|RTLD_NODELETE|RTLD_NOLOAD)) != 0) {
     DL_ERR("invalid flags to dlopen: %x", flags);
     return nullptr;
   }
 
-  android_namespace_t* ns = get_caller_namespace(caller);
-
   if (extinfo != nullptr) {
     if ((extinfo->flags & ~(ANDROID_DLEXT_VALID_FLAG_BITS)) != 0) {
       DL_ERR("invalid extended flags to android_dlopen_ext: 0x%" PRIx64, extinfo->flags);
@@ -2373,8 +1831,13 @@
   ProtectedDataGuard guard;
   soinfo* si = find_library(ns, name, flags, extinfo, caller);
   if (si != nullptr) {
+    failure_guard.disable();
     si->call_constructors();
-    return si->to_handle();
+    void* handle = si->to_handle();
+    LD_LOG(kLogDlopen,
+           "... dlopen successful: realpath=\"%s\", soname=\"%s\", handle=%p",
+           si->get_realpath(), si->get_soname(), handle);
+    return handle;
   }
 
   return nullptr;
@@ -2484,12 +1947,16 @@
 }
 
 bool init_namespaces(const char* public_ns_sonames, const char* anon_ns_library_path) {
-  CHECK(public_ns_sonames != nullptr);
   if (g_public_namespace_initialized) {
     DL_ERR("public namespace has already been initialized.");
     return false;
   }
 
+  if (public_ns_sonames == nullptr || public_ns_sonames[0] == '\0') {
+    DL_ERR("error initializing public namespace: the list of public libraries is empty.");
+    return false;
+  }
+
   std::vector<std::string> sonames = android::base::Split(public_ns_sonames, ":");
 
   ProtectedDataGuard guard;
@@ -2532,6 +1999,13 @@
   return true;
 }
 
+static void add_soinfos_to_namespace(const soinfo_list_t& soinfos, android_namespace_t* ns) {
+  ns->add_soinfos(soinfos);
+  for (auto si : soinfos) {
+    si->add_secondary_namespace(ns);
+  }
+}
+
 android_namespace_t* create_namespace(const void* caller_addr,
                                       const char* name,
                                       const char* ld_library_path,
@@ -2571,16 +2045,16 @@
 
   if ((type & ANDROID_NAMESPACE_TYPE_SHARED) != 0) {
     // If shared - clone the parent namespace
-    ns->add_soinfos(parent_namespace->soinfo_list());
+    add_soinfos_to_namespace(parent_namespace->soinfo_list(), ns);
   } else {
     // If not shared - copy only the shared group
-    ns->add_soinfos(get_shared_group(parent_namespace));
+    add_soinfos_to_namespace(get_shared_group(parent_namespace), ns);
   }
 
   return ns;
 }
 
-static ElfW(Addr) call_ifunc_resolver(ElfW(Addr) resolver_addr) {
+ElfW(Addr) call_ifunc_resolver(ElfW(Addr) resolver_addr) {
   typedef ElfW(Addr) (*ifunc_resolver_t)(void);
   ifunc_resolver_t ifunc_resolver = reinterpret_cast<ifunc_resolver_t>(resolver_addr);
   ElfW(Addr) ifunc_addr = ifunc_resolver();
@@ -2659,6 +2133,75 @@
   return true;
 }
 
+template <typename F>
+static bool for_each_verdef(const soinfo* si, F functor) {
+  if (!si->has_min_version(2)) {
+    return true;
+  }
+
+  uintptr_t verdef_ptr = si->get_verdef_ptr();
+  if (verdef_ptr == 0) {
+    return true;
+  }
+
+  size_t offset = 0;
+
+  size_t verdef_cnt = si->get_verdef_cnt();
+  for (size_t i = 0; i<verdef_cnt; ++i) {
+    const ElfW(Verdef)* verdef = reinterpret_cast<ElfW(Verdef)*>(verdef_ptr + offset);
+    size_t verdaux_offset = offset + verdef->vd_aux;
+    offset += verdef->vd_next;
+
+    if (verdef->vd_version != 1) {
+      DL_ERR("unsupported verdef[%zd] vd_version: %d (expected 1) library: %s",
+          i, verdef->vd_version, si->get_realpath());
+      return false;
+    }
+
+    if ((verdef->vd_flags & VER_FLG_BASE) != 0) {
+      // "this is the version of the file itself.  It must not be used for
+      //  matching a symbol. It can be used to match references."
+      //
+      // http://www.akkadia.org/drepper/symbol-versioning
+      continue;
+    }
+
+    if (verdef->vd_cnt == 0) {
+      DL_ERR("invalid verdef[%zd] vd_cnt == 0 (version without a name)", i);
+      return false;
+    }
+
+    const ElfW(Verdaux)* verdaux = reinterpret_cast<ElfW(Verdaux)*>(verdef_ptr + verdaux_offset);
+
+    if (functor(i, verdef, verdaux) == true) {
+      break;
+    }
+  }
+
+  return true;
+}
+
+bool find_verdef_version_index(const soinfo* si, const version_info* vi, ElfW(Versym)* versym) {
+  if (vi == nullptr) {
+    *versym = kVersymNotNeeded;
+    return true;
+  }
+
+  *versym = kVersymGlobal;
+
+  return for_each_verdef(si,
+    [&](size_t, const ElfW(Verdef)* verdef, const ElfW(Verdaux)* verdaux) {
+      if (verdef->vd_hash == vi->elf_hash &&
+          strcmp(vi->name, si->get_string(verdaux->vda_name)) == 0) {
+        *versym = verdef->vd_ndx;
+        return true;
+      }
+
+      return false;
+    }
+  );
+}
+
 bool VersionTracker::init_verdef(const soinfo* si_from) {
   return for_each_verdef(si_from,
     [&](size_t, const ElfW(Verdef)* verdef, const ElfW(Verdaux)* verdaux) {
@@ -2677,6 +2220,10 @@
   return init_verneed(si_from) && init_verdef(si_from);
 }
 
+// TODO (dimitry): Methods below need to be moved out of soinfo
+// and in more isolated file in order minimize dependencies on
+// unnecessary object in the linker binary. Consider making them
+// independent from soinfo (?).
 bool soinfo::lookup_version_info(const VersionTracker& version_tracker, ElfW(Word) sym,
                                  const char* sym_name, const version_info** vi) {
   const ElfW(Versym)* sym_ver_ptr = get_versym(sym);
@@ -3077,394 +2624,8 @@
 }
 #endif  // !defined(__mips__)
 
-void soinfo::call_array(const char* array_name __unused, linker_function_t* functions,
-                        size_t count, bool reverse) {
-  if (functions == nullptr) {
-    return;
-  }
-
-  TRACE("[ Calling %s (size %zd) @ %p for \"%s\" ]", array_name, count, functions, get_realpath());
-
-  int begin = reverse ? (count - 1) : 0;
-  int end = reverse ? -1 : count;
-  int step = reverse ? -1 : 1;
-
-  for (int i = begin; i != end; i += step) {
-    TRACE("[ %s[%d] == %p ]", array_name, i, functions[i]);
-    call_function("function", functions[i]);
-  }
-
-  TRACE("[ Done calling %s for \"%s\" ]", array_name, get_realpath());
-}
-
-void soinfo::call_function(const char* function_name __unused, linker_function_t function) {
-  if (function == nullptr || reinterpret_cast<uintptr_t>(function) == static_cast<uintptr_t>(-1)) {
-    return;
-  }
-
-  TRACE("[ Calling %s @ %p for \"%s\" ]", function_name, function, get_realpath());
-  function();
-  TRACE("[ Done calling %s @ %p for \"%s\" ]", function_name, function, get_realpath());
-}
-
-void soinfo::call_pre_init_constructors() {
-  // DT_PREINIT_ARRAY functions are called before any other constructors for executables,
-  // but ignored in a shared library.
-  call_array("DT_PREINIT_ARRAY", preinit_array_, preinit_array_count_, false);
-}
-
-void soinfo::call_constructors() {
-  if (constructors_called) {
-    return;
-  }
-
-  // We set constructors_called before actually calling the constructors, otherwise it doesn't
-  // protect against recursive constructor calls. One simple example of constructor recursion
-  // is the libc debug malloc, which is implemented in libc_malloc_debug_leak.so:
-  // 1. The program depends on libc, so libc's constructor is called here.
-  // 2. The libc constructor calls dlopen() to load libc_malloc_debug_leak.so.
-  // 3. dlopen() calls the constructors on the newly created
-  //    soinfo for libc_malloc_debug_leak.so.
-  // 4. The debug .so depends on libc, so CallConstructors is
-  //    called again with the libc soinfo. If it doesn't trigger the early-
-  //    out above, the libc constructor will be called again (recursively!).
-  constructors_called = true;
-
-  if (!is_main_executable() && preinit_array_ != nullptr) {
-    // The GNU dynamic linker silently ignores these, but we warn the developer.
-    PRINT("\"%s\": ignoring DT_PREINIT_ARRAY in shared library!", get_realpath());
-  }
-
-  get_children().for_each([] (soinfo* si) {
-    si->call_constructors();
-  });
-
-  TRACE("\"%s\": calling constructors", get_realpath());
-
-  // DT_INIT should be called before DT_INIT_ARRAY if both are present.
-  call_function("DT_INIT", init_func_);
-  call_array("DT_INIT_ARRAY", init_array_, init_array_count_, false);
-}
-
-void soinfo::call_destructors() {
-  if (!constructors_called) {
-    return;
-  }
-  TRACE("\"%s\": calling destructors", get_realpath());
-
-  // DT_FINI_ARRAY must be parsed in reverse order.
-  call_array("DT_FINI_ARRAY", fini_array_, fini_array_count_, true);
-
-  // DT_FINI should be called after DT_FINI_ARRAY if both are present.
-  call_function("DT_FINI", fini_func_);
-
-  // This is needed on second call to dlopen
-  // after library has been unloaded with RTLD_NODELETE
-  constructors_called = false;
-}
-
-void soinfo::add_child(soinfo* child) {
-  if (has_min_version(0)) {
-    child->parents_.push_back(this);
-    this->children_.push_back(child);
-  }
-}
-
-void soinfo::remove_all_links() {
-  if (!has_min_version(0)) {
-    return;
-  }
-
-  // 1. Untie connected soinfos from 'this'.
-  children_.for_each([&] (soinfo* child) {
-    child->parents_.remove_if([&] (const soinfo* parent) {
-      return parent == this;
-    });
-  });
-
-  parents_.for_each([&] (soinfo* parent) {
-    parent->children_.remove_if([&] (const soinfo* child) {
-      return child == this;
-    });
-  });
-
-  // 2. Remove from the primary namespace
-  primary_namespace_->remove_soinfo(this);
-  primary_namespace_ = nullptr;
-
-  // 3. Remove from secondary namespaces
-  secondary_namespaces_.for_each([&](android_namespace_t* ns) {
-    ns->remove_soinfo(this);
-  });
-
-
-  // 4. Once everything untied - clear local lists.
-  parents_.clear();
-  children_.clear();
-  secondary_namespaces_.clear();
-}
-
-dev_t soinfo::get_st_dev() const {
-  if (has_min_version(0)) {
-    return st_dev_;
-  }
-
-  return 0;
-};
-
-ino_t soinfo::get_st_ino() const {
-  if (has_min_version(0)) {
-    return st_ino_;
-  }
-
-  return 0;
-}
-
-off64_t soinfo::get_file_offset() const {
-  if (has_min_version(1)) {
-    return file_offset_;
-  }
-
-  return 0;
-}
-
-uint32_t soinfo::get_rtld_flags() const {
-  if (has_min_version(1)) {
-    return rtld_flags_;
-  }
-
-  return 0;
-}
-
-uint32_t soinfo::get_dt_flags_1() const {
-  if (has_min_version(1)) {
-    return dt_flags_1_;
-  }
-
-  return 0;
-}
-
-void soinfo::set_dt_flags_1(uint32_t dt_flags_1) {
-  if (has_min_version(1)) {
-    if ((dt_flags_1 & DF_1_GLOBAL) != 0) {
-      rtld_flags_ |= RTLD_GLOBAL;
-    }
-
-    if ((dt_flags_1 & DF_1_NODELETE) != 0) {
-      rtld_flags_ |= RTLD_NODELETE;
-    }
-
-    dt_flags_1_ = dt_flags_1;
-  }
-}
-
-void soinfo::set_nodelete() {
-  rtld_flags_ |= RTLD_NODELETE;
-}
-
-const char* soinfo::get_realpath() const {
-#if defined(__work_around_b_24465209__)
-  if (has_min_version(2)) {
-    return realpath_.c_str();
-  } else {
-    return old_name_;
-  }
-#else
-  return realpath_.c_str();
-#endif
-}
-
-void soinfo::set_soname(const char* soname) {
-#if defined(__work_around_b_24465209__)
-  if (has_min_version(2)) {
-    soname_ = soname;
-  }
-  strlcpy(old_name_, soname_, sizeof(old_name_));
-#else
-  soname_ = soname;
-#endif
-}
-
-const char* soinfo::get_soname() const {
-#if defined(__work_around_b_24465209__)
-  if (has_min_version(2)) {
-    return soname_;
-  } else {
-    return old_name_;
-  }
-#else
-  return soname_;
-#endif
-}
-
-// This is a return on get_children()/get_parents() if
-// 'this->flags' does not have FLAG_NEW_SOINFO set.
-static soinfo::soinfo_list_t g_empty_list;
-
-soinfo::soinfo_list_t& soinfo::get_children() {
-  if (has_min_version(0)) {
-    return children_;
-  }
-
-  return g_empty_list;
-}
-
-const soinfo::soinfo_list_t& soinfo::get_children() const {
-  if (has_min_version(0)) {
-    return children_;
-  }
-
-  return g_empty_list;
-}
-
-soinfo::soinfo_list_t& soinfo::get_parents() {
-  if (has_min_version(0)) {
-    return parents_;
-  }
-
-  return g_empty_list;
-}
-
-static std::vector<std::string> g_empty_runpath;
-
-const std::vector<std::string>& soinfo::get_dt_runpath() const {
-  if (has_min_version(3)) {
-    return dt_runpath_;
-  }
-
-  return g_empty_runpath;
-}
-
-android_namespace_t* soinfo::get_primary_namespace() {
-  if (has_min_version(3)) {
-    return primary_namespace_;
-  }
-
-  return &g_default_namespace;
-}
-
-void soinfo::add_secondary_namespace(android_namespace_t* secondary_ns) {
-  CHECK(has_min_version(3));
-  secondary_namespaces_.push_back(secondary_ns);
-}
-
-ElfW(Addr) soinfo::resolve_symbol_address(const ElfW(Sym)* s) const {
-  if (ELF_ST_TYPE(s->st_info) == STT_GNU_IFUNC) {
-    return call_ifunc_resolver(s->st_value + load_bias);
-  }
-
-  return static_cast<ElfW(Addr)>(s->st_value + load_bias);
-}
-
-const char* soinfo::get_string(ElfW(Word) index) const {
-  if (has_min_version(1) && (index >= strtab_size_)) {
-    __libc_fatal("%s: strtab out of bounds error; STRSZ=%zd, name=%d",
-        get_realpath(), strtab_size_, index);
-  }
-
-  return strtab_ + index;
-}
-
-bool soinfo::is_gnu_hash() const {
-  return (flags_ & FLAG_GNU_HASH) != 0;
-}
-
-bool soinfo::can_unload() const {
-  return !is_linked() || ((get_rtld_flags() & (RTLD_NODELETE | RTLD_GLOBAL)) == 0);
-}
-
-bool soinfo::is_linked() const {
-  return (flags_ & FLAG_LINKED) != 0;
-}
-
-bool soinfo::is_main_executable() const {
-  return (flags_ & FLAG_EXE) != 0;
-}
-
-bool soinfo::is_linker() const {
-  return (flags_ & FLAG_LINKER) != 0;
-}
-
-void soinfo::set_linked() {
-  flags_ |= FLAG_LINKED;
-}
-
-void soinfo::set_linker_flag() {
-  flags_ |= FLAG_LINKER;
-}
-
-void soinfo::set_main_executable() {
-  flags_ |= FLAG_EXE;
-}
-
-void soinfo::increment_ref_count() {
-  local_group_root_->ref_count_++;
-}
-
-size_t soinfo::decrement_ref_count() {
-  return --local_group_root_->ref_count_;
-}
-
-soinfo* soinfo::get_local_group_root() const {
-  return local_group_root_;
-}
-
-
-void soinfo::set_mapped_by_caller(bool mapped_by_caller) {
-  if (mapped_by_caller) {
-    flags_ |= FLAG_MAPPED_BY_CALLER;
-  } else {
-    flags_ &= ~FLAG_MAPPED_BY_CALLER;
-  }
-}
-
-bool soinfo::is_mapped_by_caller() const {
-  return (flags_ & FLAG_MAPPED_BY_CALLER) != 0;
-}
-
-// This function returns api-level at the time of
-// dlopen/load. Note that libraries opened by system
-// will always have 'current' api level.
-uint32_t soinfo::get_target_sdk_version() const {
-  if (!has_min_version(2)) {
-    return __ANDROID_API__;
-  }
-
-  return local_group_root_->target_sdk_version_;
-}
-
-uintptr_t soinfo::get_handle() const {
-  CHECK(has_min_version(3));
-  CHECK(handle_ != 0);
-  return handle_;
-}
-
-void* soinfo::to_handle() {
-  if (get_application_target_sdk_version() <= 23 || !has_min_version(3)) {
-    return this;
-  }
-
-  return reinterpret_cast<void*>(get_handle());
-}
-
-void soinfo::generate_handle() {
-  CHECK(has_min_version(3));
-  CHECK(handle_ == 0); // Make sure this is the first call
-
-  // Make sure the handle is unique and does not collide
-  // with special values which are RTLD_DEFAULT and RTLD_NEXT.
-  do {
-    arc4random_buf(&handle_, sizeof(handle_));
-    // the least significant bit for the handle is always 1
-    // making it easy to test the type of handle passed to
-    // dl* functions.
-    handle_ = handle_ | 1;
-  } while (handle_ == reinterpret_cast<uintptr_t>(RTLD_DEFAULT) ||
-           handle_ == reinterpret_cast<uintptr_t>(RTLD_NEXT) ||
-           g_soinfo_handles_map.find(handle_) != g_soinfo_handles_map.end());
-
-  g_soinfo_handles_map[handle_] = this;
-}
+// An empty list of soinfos
+static soinfo_list_t g_empty_list;
 
 bool soinfo::prelink_image() {
   /* Extract dynamic section */
@@ -3702,17 +2863,17 @@
 
 #endif
       case DT_INIT:
-        init_func_ = reinterpret_cast<linker_function_t>(load_bias + d->d_un.d_ptr);
+        init_func_ = reinterpret_cast<linker_ctor_function_t>(load_bias + d->d_un.d_ptr);
         DEBUG("%s constructors (DT_INIT) found at %p", get_realpath(), init_func_);
         break;
 
       case DT_FINI:
-        fini_func_ = reinterpret_cast<linker_function_t>(load_bias + d->d_un.d_ptr);
+        fini_func_ = reinterpret_cast<linker_dtor_function_t>(load_bias + d->d_un.d_ptr);
         DEBUG("%s destructors (DT_FINI) found at %p", get_realpath(), fini_func_);
         break;
 
       case DT_INIT_ARRAY:
-        init_array_ = reinterpret_cast<linker_function_t*>(load_bias + d->d_un.d_ptr);
+        init_array_ = reinterpret_cast<linker_ctor_function_t*>(load_bias + d->d_un.d_ptr);
         DEBUG("%s constructors (DT_INIT_ARRAY) found at %p", get_realpath(), init_array_);
         break;
 
@@ -3721,7 +2882,7 @@
         break;
 
       case DT_FINI_ARRAY:
-        fini_array_ = reinterpret_cast<linker_function_t*>(load_bias + d->d_un.d_ptr);
+        fini_array_ = reinterpret_cast<linker_dtor_function_t*>(load_bias + d->d_un.d_ptr);
         DEBUG("%s destructors (DT_FINI_ARRAY) found at %p", get_realpath(), fini_array_);
         break;
 
@@ -3730,7 +2891,7 @@
         break;
 
       case DT_PREINIT_ARRAY:
-        preinit_array_ = reinterpret_cast<linker_function_t*>(load_bias + d->d_un.d_ptr);
+        preinit_array_ = reinterpret_cast<linker_ctor_function_t*>(load_bias + d->d_un.d_ptr);
         DEBUG("%s constructors (DT_PREINIT_ARRAY) found at %p", get_realpath(), preinit_array_);
         break;
 
@@ -3784,8 +2945,8 @@
           *dp = &_r_debug;
         }
         break;
-      case DT_MIPS_RLD_MAP2:
-        // Set the DT_MIPS_RLD_MAP2 entry to the address of _r_debug for GDB.
+      case DT_MIPS_RLD_MAP_REL:
+        // Set the DT_MIPS_RLD_MAP_REL entry to the address of _r_debug for GDB.
         {
           r_debug** dp = reinterpret_cast<r_debug**>(
               reinterpret_cast<ElfW(Addr)>(d) + d->d_un.d_val);
@@ -4078,7 +3239,7 @@
   si->load_bias = get_elf_exec_load_bias(ehdr_vdso);
 
   si->prelink_image();
-  si->link_image(g_empty_list, soinfo::soinfo_list_t::make_list(si), nullptr);
+  si->link_image(g_empty_list, soinfo_list_t::make_list(si), nullptr);
 #endif
 }
 
@@ -4167,7 +3328,16 @@
   // Initialize system properties
   __system_properties_init(); // may use 'environ'
 
-  debuggerd_init();
+  // Register the debuggerd signal handler.
+  debuggerd_callbacks_t callbacks = {
+    .get_abort_message = []() {
+      return g_abort_message;
+    },
+    .post_dump = &notify_gdb_of_libraries,
+  };
+  debuggerd_init(&callbacks);
+
+  g_linker_logger.ResetState();
 
   // Get a few environment variables.
   const char* LD_DEBUG = getenv("LD_DEBUG");
@@ -4222,7 +3392,6 @@
   // Extract information passed from the kernel.
   si->phdr = reinterpret_cast<ElfW(Phdr)*>(args.getauxval(AT_PHDR));
   si->phnum = args.getauxval(AT_PHNUM);
-  si->entry = args.getauxval(AT_ENTRY);
 
   /* Compute the value of si->base. We can't rely on the fact that
    * the first entry is the PHDR because this will not be true
@@ -4243,7 +3412,7 @@
   ElfW(Ehdr)* elf_hdr = reinterpret_cast<ElfW(Ehdr)*>(si->base);
   if (elf_hdr->e_type != ET_DYN) {
     __libc_fatal("\"%s\": error: only position independent executables (PIE) are supported.",
-                 args.argv[0]);
+                 g_argv[0]);
   }
 
   // Use LD_LIBRARY_PATH and LD_PRELOAD (but only if we aren't setuid/setgid).
@@ -4255,7 +3424,7 @@
   init_default_namespace();
 
   if (!si->prelink_image()) {
-    __libc_fatal("CANNOT LINK EXECUTABLE \"%s\": %s", args.argv[0], linker_get_error_buffer());
+    __libc_fatal("CANNOT LINK EXECUTABLE \"%s\": %s", g_argv[0], linker_get_error_buffer());
   }
 
   // add somain to global group
@@ -4286,10 +3455,10 @@
       !find_libraries(&g_default_namespace, si, needed_library_names, needed_libraries_count,
                       nullptr, &g_ld_preloads, ld_preloads_count, RTLD_GLOBAL, nullptr,
                       /* add_as_children */ true)) {
-    __libc_fatal("CANNOT LINK EXECUTABLE \"%s\": %s", args.argv[0], linker_get_error_buffer());
+    __libc_fatal("CANNOT LINK EXECUTABLE \"%s\": %s", g_argv[0], linker_get_error_buffer());
   } else if (needed_libraries_count == 0) {
-    if (!si->link_image(g_empty_list, soinfo::soinfo_list_t::make_list(si), nullptr)) {
-      __libc_fatal("CANNOT LINK EXECUTABLE \"%s\": %s", args.argv[0], linker_get_error_buffer());
+    if (!si->link_image(g_empty_list, soinfo_list_t::make_list(si), nullptr)) {
+      __libc_fatal("CANNOT LINK EXECUTABLE \"%s\": %s", g_argv[0], linker_get_error_buffer());
     }
     si->increment_ref_count();
   }
@@ -4312,12 +3481,12 @@
 
 #if TIMING
   gettimeofday(&t1, nullptr);
-  PRINT("LINKER TIME: %s: %d microseconds", args.argv[0], (int) (
+  PRINT("LINKER TIME: %s: %d microseconds", g_argv[0], (int) (
            (((long long)t1.tv_sec * 1000000LL) + (long long)t1.tv_usec) -
            (((long long)t0.tv_sec * 1000000LL) + (long long)t0.tv_usec)));
 #endif
 #if STATS
-  PRINT("RELO STATS: %s: %d abs, %d rel, %d copy, %d symbol", args.argv[0],
+  PRINT("RELO STATS: %s: %d abs, %d rel, %d copy, %d symbol", g_argv[0],
          linker_stats.count[kRelocAbsolute],
          linker_stats.count[kRelocRelative],
          linker_stats.count[kRelocCopy],
@@ -4343,7 +3512,7 @@
         }
       }
     }
-    PRINT("PAGES MODIFIED: %s: %d (%dKB)", args.argv[0], count, count * 4);
+    PRINT("PAGES MODIFIED: %s: %d (%dKB)", g_argv[0], count, count * 4);
   }
 #endif
 
@@ -4351,8 +3520,9 @@
   fflush(stdout);
 #endif
 
-  TRACE("[ Ready to execute \"%s\" @ %p ]", si->get_realpath(), reinterpret_cast<void*>(si->entry));
-  return si->entry;
+  ElfW(Addr) entry = args.getauxval(AT_ENTRY);
+  TRACE("[ Ready to execute \"%s\" @ %p ]", si->get_realpath(), reinterpret_cast<void*>(entry));
+  return entry;
 }
 
 /* Compute the load-bias of an existing executable. This shall only
@@ -4379,8 +3549,8 @@
   return 0;
 }
 
-static void __linker_cannot_link(KernelArgumentBlock& args) {
-  __libc_fatal("CANNOT LINK EXECUTABLE \"%s\": %s", args.argv[0], linker_get_error_buffer());
+static void __linker_cannot_link(const char* argv0) {
+  __libc_fatal("CANNOT LINK EXECUTABLE \"%s\": %s", argv0, linker_get_error_buffer());
 }
 
 /*
@@ -4424,7 +3594,7 @@
   linker_so.set_linker_flag();
 
   // Prelink the linker so we can access linker globals.
-  if (!linker_so.prelink_image()) __linker_cannot_link(args);
+  if (!linker_so.prelink_image()) __linker_cannot_link(args.argv[0]);
 
   // This might not be obvious... The reasons why we pass g_empty_list
   // in place of local_group here are (1) we do not really need it, because
@@ -4432,7 +3602,7 @@
   // itself without having to look into local_group and (2) allocators
   // are not yet initialized, and therefore we cannot use linked_list.push_*
   // functions at this point.
-  if (!linker_so.link_image(g_empty_list, g_empty_list, nullptr)) __linker_cannot_link(args);
+  if (!linker_so.link_image(g_empty_list, g_empty_list, nullptr)) __linker_cannot_link(args.argv[0]);
 
 #if defined(__i386__)
   // On x86, we can't make system calls before this point.
@@ -4448,11 +3618,16 @@
 
   // We didn't protect the linker's RELRO pages in link_image because we
   // couldn't make system calls on x86 at that point, but we can now...
-  if (!linker_so.protect_relro()) __linker_cannot_link(args);
+  if (!linker_so.protect_relro()) __linker_cannot_link(args.argv[0]);
 
   // Initialize the linker's static libc's globals
   __libc_init_globals(args);
 
+  // store argc/argv/envp to use them for calling constructors
+  g_argc = args.argc;
+  g_argv = args.argv;
+  g_envp = args.envp;
+
   // Initialize the linker's own global variables
   linker_so.call_constructors();
 
diff --git a/linker/linker.h b/linker/linker.h
index 49eee78..aa6d00b 100644
--- a/linker/linker.h
+++ b/linker/linker.h
@@ -40,31 +40,13 @@
 #include "private/bionic_page.h"
 #include "private/libc_logging.h"
 #include "linked_list.h"
+#include "linker_common_types.h"
+#include "linker_logger.h"
+#include "linker_soinfo.h"
 
 #include <string>
 #include <vector>
 
-#define DL_ERR(fmt, x...) \
-    do { \
-      __libc_format_buffer(linker_get_error_buffer(), linker_get_error_buffer_size(), fmt, ##x); \
-      /* If LD_DEBUG is set high enough, log every dlerror(3) message. */ \
-      DEBUG("%s\n", linker_get_error_buffer()); \
-    } while (false)
-
-#define DL_WARN(fmt, x...) \
-    do { \
-      __libc_format_log(ANDROID_LOG_WARN, "linker", fmt, ##x); \
-      __libc_format_fd(2, "WARNING: linker: "); \
-      __libc_format_fd(2, fmt, ##x); \
-      __libc_format_fd(2, "\n"); \
-    } while (false)
-
-#define DL_ERR_AND_LOG(fmt, x...) \
-  do { \
-    DL_ERR(fmt, x); \
-    PRINT(fmt, x); \
-  } while (false)
-
 #if defined(__LP64__)
 #define ELFW(what) ELF64_ ## what
 #else
@@ -85,82 +67,8 @@
 #define ELF64_R_TYPE(info)  (((info) >> 56) & 0xff)
 #endif
 
-#define FLAG_LINKED           0x00000001
-#define FLAG_EXE              0x00000004 // The main executable
-#define FLAG_LINKER           0x00000010 // The linker itself
-#define FLAG_GNU_HASH         0x00000040 // uses gnu hash
-#define FLAG_MAPPED_BY_CALLER 0x00000080 // the map is reserved by the caller
-                                         // and should not be unmapped
-#define FLAG_NEW_SOINFO       0x40000000 // new soinfo format
-
 #define SUPPORTED_DT_FLAGS_1 (DF_1_NOW | DF_1_GLOBAL | DF_1_NODELETE)
 
-#define SOINFO_VERSION 3
-
-#if defined(__work_around_b_24465209__)
-#define SOINFO_NAME_LEN 128
-#endif
-
-typedef void (*linker_function_t)();
-
-// Android uses RELA for aarch64 and x86_64. mips64 still uses REL.
-#if defined(__aarch64__) || defined(__x86_64__)
-#define USE_RELA 1
-#endif
-
-struct soinfo;
-
-class SoinfoListAllocator {
- public:
-  static LinkedListEntry<soinfo>* alloc();
-  static void free(LinkedListEntry<soinfo>* entry);
-
- private:
-  // unconstructable
-  DISALLOW_IMPLICIT_CONSTRUCTORS(SoinfoListAllocator);
-};
-
-class NamespaceListAllocator {
- public:
-  static LinkedListEntry<android_namespace_t>* alloc();
-  static void free(LinkedListEntry<android_namespace_t>* entry);
-
- private:
-  // unconstructable
-  DISALLOW_IMPLICIT_CONSTRUCTORS(NamespaceListAllocator);
-};
-
-class SymbolName {
- public:
-  explicit SymbolName(const char* name)
-      : name_(name), has_elf_hash_(false), has_gnu_hash_(false),
-        elf_hash_(0), gnu_hash_(0) { }
-
-  const char* get_name() {
-    return name_;
-  }
-
-  uint32_t elf_hash();
-  uint32_t gnu_hash();
-
- private:
-  const char* name_;
-  bool has_elf_hash_;
-  bool has_gnu_hash_;
-  uint32_t elf_hash_;
-  uint32_t gnu_hash_;
-
-  DISALLOW_IMPLICIT_CONSTRUCTORS(SymbolName);
-};
-
-struct version_info {
-  constexpr version_info() : elf_hash(0), name(nullptr), target_si(nullptr) {}
-
-  uint32_t elf_hash;
-  const char* name;
-  const soinfo* target_si;
-};
-
 // Class used construct version dependency graph.
 class VersionTracker {
  public:
@@ -179,267 +87,9 @@
   DISALLOW_COPY_AND_ASSIGN(VersionTracker);
 };
 
-struct soinfo {
- public:
-  typedef LinkedList<soinfo, SoinfoListAllocator> soinfo_list_t;
-  typedef LinkedList<android_namespace_t, NamespaceListAllocator> android_namespace_list_t;
-#if defined(__work_around_b_24465209__)
- private:
-  char old_name_[SOINFO_NAME_LEN];
-#endif
- public:
-  const ElfW(Phdr)* phdr;
-  size_t phnum;
-  ElfW(Addr) entry;
-  ElfW(Addr) base;
-  size_t size;
-
-#if defined(__work_around_b_24465209__)
-  uint32_t unused1;  // DO NOT USE, maintained for compatibility.
-#endif
-
-  ElfW(Dyn)* dynamic;
-
-#if defined(__work_around_b_24465209__)
-  uint32_t unused2; // DO NOT USE, maintained for compatibility
-  uint32_t unused3; // DO NOT USE, maintained for compatibility
-#endif
-
-  soinfo* next;
- private:
-  uint32_t flags_;
-
-  const char* strtab_;
-  ElfW(Sym)* symtab_;
-
-  size_t nbucket_;
-  size_t nchain_;
-  uint32_t* bucket_;
-  uint32_t* chain_;
-
-#if defined(__mips__) || !defined(__LP64__)
-  // This is only used by mips and mips64, but needs to be here for
-  // all 32-bit architectures to preserve binary compatibility.
-  ElfW(Addr)** plt_got_;
-#endif
-
-#if defined(USE_RELA)
-  ElfW(Rela)* plt_rela_;
-  size_t plt_rela_count_;
-
-  ElfW(Rela)* rela_;
-  size_t rela_count_;
-#else
-  ElfW(Rel)* plt_rel_;
-  size_t plt_rel_count_;
-
-  ElfW(Rel)* rel_;
-  size_t rel_count_;
-#endif
-
-  linker_function_t* preinit_array_;
-  size_t preinit_array_count_;
-
-  linker_function_t* init_array_;
-  size_t init_array_count_;
-  linker_function_t* fini_array_;
-  size_t fini_array_count_;
-
-  linker_function_t init_func_;
-  linker_function_t fini_func_;
-
-#if defined(__arm__)
- public:
-  // ARM EABI section used for stack unwinding.
-  uint32_t* ARM_exidx;
-  size_t ARM_exidx_count;
- private:
-#elif defined(__mips__)
-  uint32_t mips_symtabno_;
-  uint32_t mips_local_gotno_;
-  uint32_t mips_gotsym_;
-  bool mips_relocate_got(const VersionTracker& version_tracker,
-                         const soinfo_list_t& global_group,
-                         const soinfo_list_t& local_group);
-#if !defined(__LP64__)
-  bool mips_check_and_adjust_fp_modes();
-#endif
-#endif
-  size_t ref_count_;
- public:
-  link_map link_map_head;
-
-  bool constructors_called;
-
-  // When you read a virtual address from the ELF file, add this
-  // value to get the corresponding address in the process' address space.
-  ElfW(Addr) load_bias;
-
-#if !defined(__LP64__)
-  bool has_text_relocations;
-#endif
-  bool has_DT_SYMBOLIC;
-
- public:
-  soinfo(android_namespace_t* ns, const char* name, const struct stat* file_stat,
-         off64_t file_offset, int rtld_flags);
-  ~soinfo();
-
-  void call_constructors();
-  void call_destructors();
-  void call_pre_init_constructors();
-  bool prelink_image();
-  bool link_image(const soinfo_list_t& global_group, const soinfo_list_t& local_group,
-                  const android_dlextinfo* extinfo);
-  bool protect_relro();
-
-  void add_child(soinfo* child);
-  void remove_all_links();
-
-  ino_t get_st_ino() const;
-  dev_t get_st_dev() const;
-  off64_t get_file_offset() const;
-
-  uint32_t get_rtld_flags() const;
-  uint32_t get_dt_flags_1() const;
-  void set_dt_flags_1(uint32_t dt_flags_1);
-
-  soinfo_list_t& get_children();
-  const soinfo_list_t& get_children() const;
-
-  soinfo_list_t& get_parents();
-
-  bool find_symbol_by_name(SymbolName& symbol_name,
-                           const version_info* vi,
-                           const ElfW(Sym)** symbol) const;
-
-  ElfW(Sym)* find_symbol_by_address(const void* addr);
-  ElfW(Addr) resolve_symbol_address(const ElfW(Sym)* s) const;
-
-  const char* get_string(ElfW(Word) index) const;
-  bool can_unload() const;
-  bool is_gnu_hash() const;
-
-  bool inline has_min_version(uint32_t min_version __unused) const {
-#if defined(__work_around_b_24465209__)
-    return (flags_ & FLAG_NEW_SOINFO) != 0 && version_ >= min_version;
-#else
-    return true;
-#endif
-  }
-
-  bool is_linked() const;
-  bool is_linker() const;
-  bool is_main_executable() const;
-
-  void set_linked();
-  void set_linker_flag();
-  void set_main_executable();
-  void set_nodelete();
-
-  void increment_ref_count();
-  size_t decrement_ref_count();
-
-  soinfo* get_local_group_root() const;
-
-  void set_soname(const char* soname);
-  const char* get_soname() const;
-  const char* get_realpath() const;
-  const ElfW(Versym)* get_versym(size_t n) const;
-  ElfW(Addr) get_verneed_ptr() const;
-  size_t get_verneed_cnt() const;
-  ElfW(Addr) get_verdef_ptr() const;
-  size_t get_verdef_cnt() const;
-
-  bool find_verdef_version_index(const version_info* vi, ElfW(Versym)* versym) const;
-
-  uint32_t get_target_sdk_version() const;
-
-  void set_dt_runpath(const char *);
-  const std::vector<std::string>& get_dt_runpath() const;
-  android_namespace_t* get_primary_namespace();
-  void add_secondary_namespace(android_namespace_t* secondary_ns);
-
-  void set_mapped_by_caller(bool reserved_map);
-  bool is_mapped_by_caller() const;
-
-  uintptr_t get_handle() const;
-  void generate_handle();
-  void* to_handle();
-
- private:
-  bool elf_lookup(SymbolName& symbol_name, const version_info* vi, uint32_t* symbol_index) const;
-  ElfW(Sym)* elf_addr_lookup(const void* addr);
-  bool gnu_lookup(SymbolName& symbol_name, const version_info* vi, uint32_t* symbol_index) const;
-  ElfW(Sym)* gnu_addr_lookup(const void* addr);
-
-  bool lookup_version_info(const VersionTracker& version_tracker, ElfW(Word) sym,
-                           const char* sym_name, const version_info** vi);
-
-  void call_array(const char* array_name, linker_function_t* functions, size_t count, bool reverse);
-  void call_function(const char* function_name, linker_function_t function);
-  template<typename ElfRelIteratorT>
-  bool relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& rel_iterator,
-                const soinfo_list_t& global_group, const soinfo_list_t& local_group);
-
- private:
-  // This part of the structure is only available
-  // when FLAG_NEW_SOINFO is set in this->flags.
-  uint32_t version_;
-
-  // version >= 0
-  dev_t st_dev_;
-  ino_t st_ino_;
-
-  // dependency graph
-  soinfo_list_t children_;
-  soinfo_list_t parents_;
-
-  // version >= 1
-  off64_t file_offset_;
-  uint32_t rtld_flags_;
-  uint32_t dt_flags_1_;
-  size_t strtab_size_;
-
-  // version >= 2
-
-  size_t gnu_nbucket_;
-  uint32_t* gnu_bucket_;
-  uint32_t* gnu_chain_;
-  uint32_t gnu_maskwords_;
-  uint32_t gnu_shift2_;
-  ElfW(Addr)* gnu_bloom_filter_;
-
-  soinfo* local_group_root_;
-
-  uint8_t* android_relocs_;
-  size_t android_relocs_size_;
-
-  const char* soname_;
-  std::string realpath_;
-
-  const ElfW(Versym)* versym_;
-
-  ElfW(Addr) verdef_ptr_;
-  size_t verdef_cnt_;
-
-  ElfW(Addr) verneed_ptr_;
-  size_t verneed_cnt_;
-
-  uint32_t target_sdk_version_;
-
-  // version >= 3
-  std::vector<std::string> dt_runpath_;
-  android_namespace_t* primary_namespace_;
-  android_namespace_list_t secondary_namespaces_;
-  uintptr_t handle_;
-
-  friend soinfo* get_libdl_info();
-};
-
 bool soinfo_do_lookup(soinfo* si_from, const char* name, const version_info* vi,
-                      soinfo** si_found_in, const soinfo::soinfo_list_t& global_group,
-                      const soinfo::soinfo_list_t& local_group, const ElfW(Sym)** symbol);
+                      soinfo** si_found_in, const soinfo_list_t& global_group,
+                      const soinfo_list_t& local_group, const ElfW(Sym)** symbol);
 
 enum RelocationKind {
   kRelocAbsolute = 0,
@@ -465,12 +115,6 @@
 
 int do_dladdr(const void* addr, Dl_info* info);
 
-void debuggerd_init();
-extern "C" abort_msg_t* g_abort_message;
-
-char* linker_get_error_buffer();
-size_t linker_get_error_buffer_size();
-
 void set_application_target_sdk_version(uint32_t target);
 uint32_t get_application_target_sdk_version();
 
@@ -509,4 +153,7 @@
                                       const char* permitted_when_isolated_path,
                                       android_namespace_t* parent_namespace);
 
+constexpr unsigned kLibraryAlignmentBits = 18;
+constexpr size_t kLibraryAlignment = 1UL << kLibraryAlignmentBits;
+
 #endif
diff --git a/linker/linker_allocator.cpp b/linker/linker_allocator.cpp
index 57811d8..dc6dfc1 100644
--- a/linker/linker_allocator.cpp
+++ b/linker/linker_allocator.cpp
@@ -15,6 +15,7 @@
  */
 
 #include "linker_allocator.h"
+#include "linker_debug.h"
 #include "linker.h"
 
 #include <algorithm>
@@ -69,10 +70,12 @@
   return result;
 }
 
-LinkerSmallObjectAllocator::LinkerSmallObjectAllocator()
-    : type_(0), block_size_(0), free_pages_cnt_(0), free_blocks_list_(nullptr) {}
+LinkerSmallObjectAllocator::LinkerSmallObjectAllocator(uint32_t type, size_t block_size)
+    : type_(type), block_size_(block_size), free_pages_cnt_(0), free_blocks_list_(nullptr) {}
 
 void* LinkerSmallObjectAllocator::alloc() {
+  CHECK(block_size_ != 0);
+
   if (free_blocks_list_ == nullptr) {
     alloc_page();
   }
@@ -156,11 +159,6 @@
   }
 }
 
-void LinkerSmallObjectAllocator::init(uint32_t type, size_t block_size) {
-  type_ = type;
-  block_size_ = block_size;
-}
-
 linker_vector_t::iterator LinkerSmallObjectAllocator::find_page_record(void* ptr) {
   void* addr = reinterpret_cast<void*>(PAGE_START(reinterpret_cast<uintptr_t>(ptr)));
   small_object_page_record boundary;
@@ -218,11 +216,20 @@
 }
 
 
-LinkerMemoryAllocator::LinkerMemoryAllocator() {
+void LinkerMemoryAllocator::initialize_allocators() {
+  if (allocators_ != nullptr) {
+    return;
+  }
+
+  LinkerSmallObjectAllocator* allocators =
+      reinterpret_cast<LinkerSmallObjectAllocator*>(allocators_buf_);
+
   for (size_t i = 0; i < kSmallObjectAllocatorsCount; ++i) {
     uint32_t type = i + kSmallObjectMinSizeLog2;
-    allocators_[i].init(type, 1 << type);
+    new (allocators + i) LinkerSmallObjectAllocator(type, 1 << type);
   }
+
+  allocators_ = allocators;
 }
 
 void* LinkerMemoryAllocator::alloc_mmap(size_t size) {
@@ -333,5 +340,6 @@
     __libc_fatal("invalid type: %u", type);
   }
 
+  initialize_allocators();
   return &allocators_[type - kSmallObjectMinSizeLog2];
 }
diff --git a/linker/linker_allocator.h b/linker/linker_allocator.h
index 22a337a..8f90dbf 100644
--- a/linker/linker_allocator.h
+++ b/linker/linker_allocator.h
@@ -100,8 +100,7 @@
 
 class LinkerSmallObjectAllocator {
  public:
-  LinkerSmallObjectAllocator();
-  void init(uint32_t type, size_t block_size);
+  LinkerSmallObjectAllocator(uint32_t type, size_t block_size);
   void* alloc();
   void free(void* ptr);
 
@@ -124,7 +123,7 @@
 
 class LinkerMemoryAllocator {
  public:
-  LinkerMemoryAllocator();
+  constexpr LinkerMemoryAllocator() : allocators_(nullptr), allocators_buf_() {}
   void* alloc(size_t size);
 
   // Note that this implementation of realloc never shrinks allocation
@@ -134,8 +133,10 @@
   void* alloc_mmap(size_t size);
   page_info* get_page_info(void* ptr);
   LinkerSmallObjectAllocator* get_small_object_allocator(uint32_t type);
+  void initialize_allocators();
 
-  LinkerSmallObjectAllocator allocators_[kSmallObjectAllocatorsCount];
+  LinkerSmallObjectAllocator* allocators_;
+  uint8_t allocators_buf_[sizeof(LinkerSmallObjectAllocator)*kSmallObjectAllocatorsCount];
 };
 
 
diff --git a/linker/linker_common_types.h b/linker/linker_common_types.h
new file mode 100644
index 0000000..6afd950
--- /dev/null
+++ b/linker/linker_common_types.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#ifndef __LINKER_COMMON_TYPES_H
+#define __LINKER_COMMON_TYPES_H
+
+#include <android/dlext.h>
+#include "linked_list.h"
+
+// TODO(dimitry): move this to linker_defines.h? Unless it is removed by
+// consequent refactoring steps.
+
+// Android uses RELA for aarch64 and x86_64. mips64 still uses REL.
+#if defined(__aarch64__) || defined(__x86_64__)
+#define USE_RELA 1
+#endif
+
+
+struct soinfo;
+
+class SoinfoListAllocator {
+ public:
+  static LinkedListEntry<soinfo>* alloc();
+  static void free(LinkedListEntry<soinfo>* entry);
+
+ private:
+  // unconstructable
+  DISALLOW_IMPLICIT_CONSTRUCTORS(SoinfoListAllocator);
+};
+
+class NamespaceListAllocator {
+ public:
+  static LinkedListEntry<android_namespace_t>* alloc();
+  static void free(LinkedListEntry<android_namespace_t>* entry);
+
+ private:
+  // unconstructable
+  DISALLOW_IMPLICIT_CONSTRUCTORS(NamespaceListAllocator);
+};
+
+typedef LinkedList<soinfo, SoinfoListAllocator> soinfo_list_t;
+typedef LinkedList<android_namespace_t, NamespaceListAllocator> android_namespace_list_t;
+
+#endif  /* __LINKER_COMMON_TYPES_H */
diff --git a/libc/bionic/__memchr_chk.cpp b/linker/linker_globals.cpp
similarity index 73%
copy from libc/bionic/__memchr_chk.cpp
copy to linker/linker_globals.cpp
index d141c04..155ebf4 100644
--- a/libc/bionic/__memchr_chk.cpp
+++ b/linker/linker_globals.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 The Android Open Source Project
+ * Copyright (C) 2016 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,14 +26,25 @@
  * SUCH DAMAGE.
  */
 
-#undef _FORTIFY_SOURCE
-#include <string.h>
-#include "private/libc_logging.h"
 
-extern "C" void* __memchr_chk(const void* s, int c, size_t n, size_t buf_size) {
-  if (__predict_false(n > buf_size)) {
-    __fortify_chk_fail("memchr: prevented read past end of buffer", 0);
-  }
+#include "linker_globals.h"
+#include "linker_namespaces.h"
 
-  return memchr(s, c, n);
+int g_argc = 0;
+char** g_argv = nullptr;
+char** g_envp = nullptr;
+
+android_namespace_t g_default_namespace;
+
+std::unordered_map<uintptr_t, soinfo*> g_soinfo_handles_map;
+
+static char __linker_dl_err_buf[768];
+
+char* linker_get_error_buffer() {
+  return &__linker_dl_err_buf[0];
 }
+
+size_t linker_get_error_buffer_size() {
+  return sizeof(__linker_dl_err_buf);
+}
+
diff --git a/linker/linker_globals.h b/linker/linker_globals.h
new file mode 100644
index 0000000..b6f8a04
--- /dev/null
+++ b/linker/linker_globals.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#ifndef __LINKER_GLOBALS_H
+#define __LINKER_GLOBALS_H
+
+#include <link.h>
+#include <stddef.h>
+
+#include <unordered_map>
+
+#define DL_ERR(fmt, x...) \
+    do { \
+      __libc_format_buffer(linker_get_error_buffer(), linker_get_error_buffer_size(), fmt, ##x); \
+      /* If LD_DEBUG is set high enough, log every dlerror(3) message. */ \
+      LD_LOG(kLogErrors, "%s\n", linker_get_error_buffer()); \
+    } while (false)
+
+#define DL_WARN(fmt, x...) \
+    do { \
+      __libc_format_log(ANDROID_LOG_WARN, "linker", fmt, ##x); \
+      __libc_format_fd(2, "WARNING: linker: "); \
+      __libc_format_fd(2, fmt, ##x); \
+      __libc_format_fd(2, "\n"); \
+    } while (false)
+
+#define DL_ERR_AND_LOG(fmt, x...) \
+  do { \
+    DL_ERR(fmt, x); \
+    PRINT(fmt, x); \
+  } while (false)
+
+constexpr ElfW(Versym) kVersymNotNeeded = 0;
+constexpr ElfW(Versym) kVersymGlobal = 1;
+
+// These values are used to call constructors for .init_array && .preinit_array
+extern int g_argc;
+extern char** g_argv;
+extern char** g_envp;
+
+struct soinfo;
+struct android_namespace_t;
+
+extern android_namespace_t g_default_namespace;
+
+extern std::unordered_map<uintptr_t, soinfo*> g_soinfo_handles_map;
+
+// Error buffer "variable"
+char* linker_get_error_buffer();
+size_t linker_get_error_buffer_size();
+
+#endif  /* __LINKER_GLOBALS_H */
diff --git a/linker/linker_logger.cpp b/linker/linker_logger.cpp
new file mode 100644
index 0000000..a9d358a
--- /dev/null
+++ b/linker/linker_logger.cpp
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2016 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 <string.h>
+#include <sys/prctl.h>
+#include <sys/system_properties.h>
+#include <unistd.h>
+
+#include <string>
+#include <vector>
+
+#include "android-base/strings.h"
+#include "linker_logger.h"
+#include "private/libc_logging.h"
+
+LinkerLogger g_linker_logger;
+
+static const char* kSystemLdDebugProperty = "debug.ld.all";
+static const char* kLdDebugPropertyPrefix = "debug.ld.app.";
+
+static const char* kOptionErrors = "dlerror";
+static const char* kOptionDlopen = "dlopen";
+
+static std::string property_get(const char* name) {
+  char value[PROP_VALUE_MAX] = {};
+  __system_property_get(name, value);
+  return value;
+}
+
+static uint32_t ParseProperty(const std::string& value) {
+  if (value.empty()) {
+    return 0;
+  }
+
+  std::vector<std::string> options = android::base::Split(value, ",");
+
+  uint32_t flags = 0;
+
+  for (const auto& o : options) {
+    if (o == kOptionErrors) {
+      flags |= kLogErrors;
+    } else if (o == kOptionDlopen){
+      flags |= kLogDlopen;
+    } else {
+      __libc_format_log(ANDROID_LOG_WARN, "linker", "Unknown debug.ld option \"%s\", will ignore.", o.c_str());
+    }
+  }
+
+  return flags;
+}
+
+void LinkerLogger::ResetState() {
+  // the most likely scenario app is not debuggable and
+  // is running on user build - the logging is disabled.
+  if (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0) == 0) {
+    return;
+  }
+
+  flags_ = 0;
+  // check flag applied to all processes first
+  std::string value = property_get(kSystemLdDebugProperty);
+  flags_ |= ParseProperty(value);
+
+  // get process basename
+  std::string process_name = basename(g_argv[0]);
+
+  std::string property_name = std::string(kLdDebugPropertyPrefix) + process_name;
+
+  // Property names are limited to PROP_NAME_MAX.
+
+  if (property_name.size() >= PROP_NAME_MAX) {
+    size_t count = PROP_NAME_MAX - 1;
+    // remove trailing dots...
+    while (property_name[count-1] == '.') {
+      --count;
+    }
+
+    property_name = property_name.substr(0, count);
+  }
+  value = property_get(property_name.c_str());
+  flags_ |= ParseProperty(value);
+}
+
+void LinkerLogger::Log(uint32_t type, const char* format, ...) {
+  if ((flags_ & type) == 0) {
+    return;
+  }
+
+  va_list ap;
+  va_start(ap, format);
+  __libc_format_log_va_list(ANDROID_LOG_DEBUG, "linker", format, ap);
+  va_end(ap);
+}
+
diff --git a/libstdc++/include/climits b/linker/linker_logger.h
similarity index 67%
copy from libstdc++/include/climits
copy to linker/linker_logger.h
index df85cb9..0932471 100644
--- a/libstdc++/include/climits
+++ b/linker/linker_logger.h
@@ -1,6 +1,5 @@
-/* -*- c++ -*- */
 /*
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2016 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -27,13 +26,34 @@
  * SUCH DAMAGE.
  */
 
-#ifndef BIONIC_LIBSTDCPP_INCLUDE_CLIMITS__
-#define BIONIC_LIBSTDCPP_INCLUDE_CLIMITS__
+#ifndef _LINKER_LOGGER_H_
+#define _LINKER_LOGGER_H_
 
-/*
- * Standard C++ Library wrapper around the C limits.h header file.
- */
-
+#include <stdlib.h>
 #include <limits.h>
+#include "private/bionic_macros.h"
 
-#endif  // BIONIC_LIBSTDCPP_INCLUDE_CLIMITS__
+#define LD_LOG(type, x...) \
+  { \
+    g_linker_logger.Log(type, x); \
+  }
+
+constexpr const uint32_t kLogErrors = 1 << 0;
+constexpr const uint32_t kLogDlopen = 1 << 1;
+
+class LinkerLogger {
+ public:
+  LinkerLogger() : flags_(0) { }
+
+  void ResetState();
+  void Log(uint32_t type, const char* format, ...);
+ private:
+  uint32_t flags_;
+
+  DISALLOW_COPY_AND_ASSIGN(LinkerLogger);
+};
+
+extern LinkerLogger g_linker_logger;
+extern char** g_argv;
+
+#endif /* _LINKER_LOGGER_H_ */
diff --git a/linker/linker_mips.cpp b/linker/linker_mips.cpp
index 2d565d7..cd392dc 100644
--- a/linker/linker_mips.cpp
+++ b/linker/linker_mips.cpp
@@ -32,10 +32,12 @@
 
 #include "linker.h"
 #include "linker_debug.h"
+#include "linker_globals.h"
 #include "linker_phdr.h"
 #include "linker_relocs.h"
 #include "linker_reloc_iterators.h"
 #include "linker_sleb128.h"
+#include "linker_soinfo.h"
 
 template bool soinfo::relocate<plain_reloc_iterator>(const VersionTracker& version_tracker,
                                                      plain_reloc_iterator&& rel_iterator,
@@ -256,18 +258,10 @@
 
   // FP ABI-variant compatibility checks for MIPS o32 ABI
   if (abiflags == nullptr) {
-    // Old compilers and some translators don't emit the new abiflags section.
-    const char* filename = get_realpath();
-    size_t len = strlen(filename);
-    if (len > 4 && (strcmp(filename+len-4, ".dex") == 0 ||
-                    strcmp(filename+len-4, ".oat") == 0   )) {
-      // Assume dex2oat is compatible with target
-      mips_fpabi = MIPS_ABI_FP_XX;
-    } else {
-      // Old Android compilers used -mfp32 -mdouble-float -modd-spreg defaults,
-      //   ie FP32 aka DOUBLE, using FR=0 mode fpregs & odd single-prec fpregs
-      mips_fpabi = MIPS_ABI_FP_DOUBLE;
-    }
+    // Old compilers lack the new abiflags section.
+    // These compilers used -mfp32 -mdouble-float -modd-spreg defaults,
+    //   ie FP32 aka DOUBLE, using odd-numbered single-prec regs
+    mips_fpabi = MIPS_ABI_FP_DOUBLE;
   } else {
     mips_fpabi = abiflags->fp_abi;
     if ( (abiflags->flags1 & MIPS_AFL_FLAGS1_ODDSPREG)
diff --git a/libc/bionic/utimes.cpp b/linker/linker_namespaces.cpp
similarity index 69%
copy from libc/bionic/utimes.cpp
copy to linker/linker_namespaces.cpp
index 0b66e6c..675f324 100644
--- a/libc/bionic/utimes.cpp
+++ b/linker/linker_namespaces.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 The Android Open Source Project
+ * Copyright (C) 2016 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,22 +26,34 @@
  * SUCH DAMAGE.
  */
 
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/time.h>
+#include "linker_namespaces.h"
+#include "linker_utils.h"
 
-#include "private/bionic_time_conversions.h"
+#include <vector>
 
-int utimes(const char* path, const timeval tv[2]) {
-  timespec ts[2];
-  timespec* ts_ptr = NULL;
-  if (tv != NULL) {
-    if (!timespec_from_timeval(ts[0], tv[0]) || !timespec_from_timeval(ts[1], tv[1])) {
-      errno = EINVAL;
-      return -1;
-    }
-    ts_ptr = ts;
+bool android_namespace_t::is_accessible(const std::string& file) {
+  if (!is_isolated_) {
+    return true;
   }
-  return utimensat(AT_FDCWD, path, ts_ptr, 0);
+
+  for (const auto& dir : ld_library_paths_) {
+    if (file_is_in_dir(file, dir)) {
+      return true;
+    }
+  }
+
+  for (const auto& dir : default_library_paths_) {
+    if (file_is_in_dir(file, dir)) {
+      return true;
+    }
+  }
+
+  for (const auto& dir : permitted_paths_) {
+    if (file_is_under_dir(file, dir)) {
+      return true;
+    }
+  }
+
+  return false;
 }
+
diff --git a/linker/linker_namespaces.h b/linker/linker_namespaces.h
new file mode 100644
index 0000000..c1cee8e
--- /dev/null
+++ b/linker/linker_namespaces.h
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#ifndef __LINKER_NAMESPACES_H
+#define __LINKER_NAMESPACES_H
+
+#include "linker_common_types.h"
+
+#include <string>
+#include <vector>
+
+struct android_namespace_t {
+ public:
+  android_namespace_t() : name_(nullptr), is_isolated_(false) {}
+
+  const char* get_name() const { return name_; }
+  void set_name(const char* name) { name_ = name; }
+
+  bool is_isolated() const { return is_isolated_; }
+  void set_isolated(bool isolated) { is_isolated_ = isolated; }
+
+  const std::vector<std::string>& get_ld_library_paths() const {
+    return ld_library_paths_;
+  }
+  void set_ld_library_paths(std::vector<std::string>&& library_paths) {
+    ld_library_paths_ = library_paths;
+  }
+
+  const std::vector<std::string>& get_default_library_paths() const {
+    return default_library_paths_;
+  }
+  void set_default_library_paths(std::vector<std::string>&& library_paths) {
+    default_library_paths_ = library_paths;
+  }
+
+  const std::vector<std::string>& get_permitted_paths() const {
+    return permitted_paths_;
+  }
+  void set_permitted_paths(std::vector<std::string>&& permitted_paths) {
+    permitted_paths_ = permitted_paths;
+  }
+
+  void add_soinfo(soinfo* si) {
+    soinfo_list_.push_back(si);
+  }
+
+  void add_soinfos(const soinfo_list_t& soinfos) {
+    for (auto si : soinfos) {
+      add_soinfo(si);
+    }
+  }
+
+  void remove_soinfo(soinfo* si) {
+    soinfo_list_.remove_if([&](soinfo* candidate) {
+      return si == candidate;
+    });
+  }
+
+  const soinfo_list_t& soinfo_list() const { return soinfo_list_; }
+
+  // For isolated namespaces - checks if the file is on the search path;
+  // always returns true for not isolated namespace.
+  bool is_accessible(const std::string& path);
+
+ private:
+  const char* name_;
+  bool is_isolated_;
+  std::vector<std::string> ld_library_paths_;
+  std::vector<std::string> default_library_paths_;
+  std::vector<std::string> permitted_paths_;
+  soinfo_list_t soinfo_list_;
+
+  DISALLOW_COPY_AND_ASSIGN(android_namespace_t);
+};
+
+#endif  /* __LINKER_NAMESPACES_H */
diff --git a/linker/linker_phdr.cpp b/linker/linker_phdr.cpp
index 3b60460..c41f3a0 100644
--- a/linker/linker_phdr.cpp
+++ b/linker/linker_phdr.cpp
@@ -36,6 +36,7 @@
 #include <unistd.h>
 
 #include "linker.h"
+#include "linker_globals.h"
 #include "linker_debug.h"
 #include "linker_utils.h"
 
@@ -245,6 +246,17 @@
     return false;
   }
 
+  if (header_.e_shentsize != sizeof(ElfW(Shdr))) {
+    DL_ERR("\"%s\" has unsupported e_shentsize: 0x%x (expected 0x%zx)",
+           name_.c_str(), header_.e_shentsize, sizeof(ElfW(Shdr)));
+    return false;
+  }
+
+  if (header_.e_shstrndx == 0) {
+    DL_ERR("\"%s\" has invalid e_shstrndx", name_.c_str());
+    return false;
+  }
+
   return true;
 }
 
@@ -252,7 +264,12 @@
   off64_t range_start;
   off64_t range_end;
 
-  return safe_add(&range_start, file_offset_, offset) &&
+  // Only header can be located at the 0 offset... This function called to
+  // check DYNSYM and DYNAMIC sections and phdr/shdr - none of them can be
+  // at offset 0.
+
+  return offset > 0 &&
+         safe_add(&range_start, file_offset_, offset) &&
          safe_add(&range_end, range_start, size) &&
          (range_start < file_size_) &&
          (range_end <= file_size_) &&
@@ -331,6 +348,35 @@
     return false;
   }
 
+  // Make sure dynamic_shdr offset and size matches PT_DYNAMIC phdr
+  size_t pt_dynamic_offset = 0;
+  size_t pt_dynamic_filesz = 0;
+  for (size_t i = 0; i < phdr_num_; ++i) {
+    const ElfW(Phdr)* phdr = &phdr_table_[i];
+    if (phdr->p_type == PT_DYNAMIC) {
+      pt_dynamic_offset = phdr->p_offset;
+      pt_dynamic_filesz = phdr->p_filesz;
+    }
+  }
+
+  if (pt_dynamic_offset != dynamic_shdr->sh_offset) {
+    DL_ERR("\"%s\" .dynamic section has invalid offset: 0x%zx, "
+           "expected to match PT_DYNAMIC offset: 0x%zx",
+           name_.c_str(),
+           static_cast<size_t>(dynamic_shdr->sh_offset),
+           pt_dynamic_offset);
+    return false;
+  }
+
+  if (pt_dynamic_filesz != dynamic_shdr->sh_size) {
+    DL_ERR("\"%s\" .dynamic section has invalid size: 0x%zx, "
+           "expected to match PT_DYNAMIC filesz: 0x%zx",
+           name_.c_str(),
+           static_cast<size_t>(dynamic_shdr->sh_size),
+           pt_dynamic_filesz);
+    return false;
+  }
+
   if (dynamic_shdr->sh_link >= shdr_num_) {
     DL_ERR_AND_LOG("\"%s\" .dynamic section has invalid sh_link: %d",
                    name_.c_str(),
@@ -423,6 +469,40 @@
   return max_vaddr - min_vaddr;
 }
 
+// Reserve a virtual address range such that if it's limits were extended to the next 2**align
+// boundary, it would not overlap with any existing mappings.
+static void* ReserveAligned(void* hint, size_t size, size_t align) {
+  int mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS;
+  // Address hint is only used in Art for the image mapping, and it is pretty important. Don't mess
+  // with it.
+  // FIXME: try an aligned allocation and fall back to plain mmap() if the former does not provide a
+  // mapping at the requested address?
+  if (align == PAGE_SIZE || hint != nullptr) {
+    void* mmap_ptr = mmap(hint, size, PROT_NONE, mmap_flags, -1, 0);
+    if (mmap_ptr == MAP_FAILED) {
+      return nullptr;
+    }
+    return mmap_ptr;
+  }
+
+  // Allocate enough space so that the end of the desired region aligned up is still inside the
+  // mapping.
+  size_t mmap_size = align_up(size, align) + align - PAGE_SIZE;
+  uint8_t* mmap_ptr =
+      reinterpret_cast<uint8_t*>(mmap(nullptr, mmap_size, PROT_NONE, mmap_flags, -1, 0));
+  if (mmap_ptr == MAP_FAILED) {
+    return nullptr;
+  }
+
+  uint8_t* first = align_up(mmap_ptr, align);
+  uint8_t* last = align_down(mmap_ptr + mmap_size, align) - size;
+  size_t n = arc4random_uniform((last - first) / PAGE_SIZE + 1);
+  uint8_t* start = first + n * PAGE_SIZE;
+  munmap(mmap_ptr, start - mmap_ptr);
+  munmap(start + size, mmap_ptr + mmap_size - (start + size));
+  return start;
+}
+
 // Reserve a virtual address range big enough to hold all loadable
 // segments of a program header table. This is done by creating a
 // private anonymous mmap() with PROT_NONE.
@@ -464,9 +544,8 @@
              reserved_size - load_size_, load_size_, name_.c_str());
       return false;
     }
-    int mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS;
-    start = mmap(mmap_hint, load_size_, PROT_NONE, mmap_flags, -1, 0);
-    if (start == MAP_FAILED) {
+    start = ReserveAligned(mmap_hint, load_size_, kLibraryAlignment);
+    if (start == nullptr) {
       DL_ERR("couldn't reserve %zd bytes of address space for \"%s\"", load_size_, name_.c_str());
       return false;
     }
diff --git a/linker/linker_sleb128.h b/linker/linker_sleb128.h
index a34916f..c4df259 100644
--- a/linker/linker_sleb128.h
+++ b/linker/linker_sleb128.h
@@ -19,6 +19,8 @@
 
 #include <stdint.h>
 
+#include "linker_debug.h"
+
 // Helper classes for decoding LEB128, used in packed relocation data.
 // http://en.wikipedia.org/wiki/LEB128
 
diff --git a/linker/linker_soinfo.cpp b/linker/linker_soinfo.cpp
new file mode 100644
index 0000000..59bdc4d
--- /dev/null
+++ b/linker/linker_soinfo.cpp
@@ -0,0 +1,795 @@
+/*
+ * Copyright (C) 2016 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 "linker_soinfo.h"
+
+#include <dlfcn.h>
+#include <elf.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "linker_debug.h"
+#include "linker_globals.h"
+#include "linker_logger.h"
+#include "linker_utils.h"
+
+// TODO(dimitry): These functions are currently located in linker.cpp - find a better place for it
+bool find_verdef_version_index(const soinfo* si, const version_info* vi, ElfW(Versym)* versym);
+ElfW(Addr) call_ifunc_resolver(ElfW(Addr) resolver_addr);
+uint32_t get_application_target_sdk_version();
+
+soinfo::soinfo(android_namespace_t* ns, const char* realpath,
+               const struct stat* file_stat, off64_t file_offset,
+               int rtld_flags) {
+  memset(this, 0, sizeof(*this));
+
+  if (realpath != nullptr) {
+    realpath_ = realpath;
+  }
+
+  flags_ = FLAG_NEW_SOINFO;
+  version_ = SOINFO_VERSION;
+
+  if (file_stat != nullptr) {
+    this->st_dev_ = file_stat->st_dev;
+    this->st_ino_ = file_stat->st_ino;
+    this->file_offset_ = file_offset;
+  }
+
+  this->rtld_flags_ = rtld_flags;
+  this->primary_namespace_ = ns;
+}
+
+soinfo::~soinfo() {
+  g_soinfo_handles_map.erase(handle_);
+}
+
+void soinfo::set_dt_runpath(const char* path) {
+  if (!has_min_version(3)) {
+    return;
+  }
+
+  std::vector<std::string> runpaths;
+
+  split_path(path, ":", &runpaths);
+
+  std::string origin = dirname(get_realpath());
+  // FIXME: add $LIB and $PLATFORM.
+  std::pair<std::string, std::string> substs[] = {{"ORIGIN", origin}};
+  for (auto&& s : runpaths) {
+    size_t pos = 0;
+    while (pos < s.size()) {
+      pos = s.find("$", pos);
+      if (pos == std::string::npos) break;
+      for (const auto& subst : substs) {
+        const std::string& token = subst.first;
+        const std::string& replacement = subst.second;
+        if (s.substr(pos + 1, token.size()) == token) {
+          s.replace(pos, token.size() + 1, replacement);
+          // -1 to compensate for the ++pos below.
+          pos += replacement.size() - 1;
+          break;
+        } else if (s.substr(pos + 1, token.size() + 2) == "{" + token + "}") {
+          s.replace(pos, token.size() + 3, replacement);
+          pos += replacement.size() - 1;
+          break;
+        }
+      }
+      // Skip $ in case it did not match any of the known substitutions.
+      ++pos;
+    }
+  }
+
+  resolve_paths(runpaths, &dt_runpath_);
+}
+
+const ElfW(Versym)* soinfo::get_versym(size_t n) const {
+  if (has_min_version(2) && versym_ != nullptr) {
+    return versym_ + n;
+  }
+
+  return nullptr;
+}
+
+ElfW(Addr) soinfo::get_verneed_ptr() const {
+  if (has_min_version(2)) {
+    return verneed_ptr_;
+  }
+
+  return 0;
+}
+
+size_t soinfo::get_verneed_cnt() const {
+  if (has_min_version(2)) {
+    return verneed_cnt_;
+  }
+
+  return 0;
+}
+
+ElfW(Addr) soinfo::get_verdef_ptr() const {
+  if (has_min_version(2)) {
+    return verdef_ptr_;
+  }
+
+  return 0;
+}
+
+size_t soinfo::get_verdef_cnt() const {
+  if (has_min_version(2)) {
+    return verdef_cnt_;
+  }
+
+  return 0;
+}
+
+bool soinfo::find_symbol_by_name(SymbolName& symbol_name,
+                                 const version_info* vi,
+                                 const ElfW(Sym)** symbol) const {
+  uint32_t symbol_index;
+  bool success =
+      is_gnu_hash() ?
+      gnu_lookup(symbol_name, vi, &symbol_index) :
+      elf_lookup(symbol_name, vi, &symbol_index);
+
+  if (success) {
+    *symbol = symbol_index == 0 ? nullptr : symtab_ + symbol_index;
+  }
+
+  return success;
+}
+
+static bool is_symbol_global_and_defined(const soinfo* si, const ElfW(Sym)* s) {
+  if (ELF_ST_BIND(s->st_info) == STB_GLOBAL ||
+      ELF_ST_BIND(s->st_info) == STB_WEAK) {
+    return s->st_shndx != SHN_UNDEF;
+  } else if (ELF_ST_BIND(s->st_info) != STB_LOCAL) {
+    DL_WARN("unexpected ST_BIND value: %d for \"%s\" in \"%s\"",
+            ELF_ST_BIND(s->st_info), si->get_string(s->st_name), si->get_realpath());
+  }
+
+  return false;
+}
+
+static const ElfW(Versym) kVersymHiddenBit = 0x8000;
+
+static inline bool is_versym_hidden(const ElfW(Versym)* versym) {
+  // the symbol is hidden if bit 15 of versym is set.
+  return versym != nullptr && (*versym & kVersymHiddenBit) != 0;
+}
+
+static inline bool check_symbol_version(const ElfW(Versym) verneed,
+                                        const ElfW(Versym)* verdef) {
+  return verneed == kVersymNotNeeded ||
+      verdef == nullptr ||
+      verneed == (*verdef & ~kVersymHiddenBit);
+}
+
+bool soinfo::gnu_lookup(SymbolName& symbol_name,
+                        const version_info* vi,
+                        uint32_t* symbol_index) const {
+  uint32_t hash = symbol_name.gnu_hash();
+  uint32_t h2 = hash >> gnu_shift2_;
+
+  uint32_t bloom_mask_bits = sizeof(ElfW(Addr))*8;
+  uint32_t word_num = (hash / bloom_mask_bits) & gnu_maskwords_;
+  ElfW(Addr) bloom_word = gnu_bloom_filter_[word_num];
+
+  *symbol_index = 0;
+
+  TRACE_TYPE(LOOKUP, "SEARCH %s in %s@%p (gnu)",
+      symbol_name.get_name(), get_realpath(), reinterpret_cast<void*>(base));
+
+  // test against bloom filter
+  if ((1 & (bloom_word >> (hash % bloom_mask_bits)) & (bloom_word >> (h2 % bloom_mask_bits))) == 0) {
+    TRACE_TYPE(LOOKUP, "NOT FOUND %s in %s@%p",
+        symbol_name.get_name(), get_realpath(), reinterpret_cast<void*>(base));
+
+    return true;
+  }
+
+  // bloom test says "probably yes"...
+  uint32_t n = gnu_bucket_[hash % gnu_nbucket_];
+
+  if (n == 0) {
+    TRACE_TYPE(LOOKUP, "NOT FOUND %s in %s@%p",
+        symbol_name.get_name(), get_realpath(), reinterpret_cast<void*>(base));
+
+    return true;
+  }
+
+  // lookup versym for the version definition in this library
+  // note the difference between "version is not requested" (vi == nullptr)
+  // and "version not found". In the first case verneed is kVersymNotNeeded
+  // which implies that the default version can be accepted; the second case results in
+  // verneed = 1 (kVersymGlobal) and implies that we should ignore versioned symbols
+  // for this library and consider only *global* ones.
+  ElfW(Versym) verneed = 0;
+  if (!find_verdef_version_index(this, vi, &verneed)) {
+    return false;
+  }
+
+  do {
+    ElfW(Sym)* s = symtab_ + n;
+    const ElfW(Versym)* verdef = get_versym(n);
+    // skip hidden versions when verneed == kVersymNotNeeded (0)
+    if (verneed == kVersymNotNeeded && is_versym_hidden(verdef)) {
+        continue;
+    }
+    if (((gnu_chain_[n] ^ hash) >> 1) == 0 &&
+        check_symbol_version(verneed, verdef) &&
+        strcmp(get_string(s->st_name), symbol_name.get_name()) == 0 &&
+        is_symbol_global_and_defined(this, s)) {
+      TRACE_TYPE(LOOKUP, "FOUND %s in %s (%p) %zd",
+          symbol_name.get_name(), get_realpath(), reinterpret_cast<void*>(s->st_value),
+          static_cast<size_t>(s->st_size));
+      *symbol_index = n;
+      return true;
+    }
+  } while ((gnu_chain_[n++] & 1) == 0);
+
+  TRACE_TYPE(LOOKUP, "NOT FOUND %s in %s@%p",
+             symbol_name.get_name(), get_realpath(), reinterpret_cast<void*>(base));
+
+  return true;
+}
+
+bool soinfo::elf_lookup(SymbolName& symbol_name,
+                        const version_info* vi,
+                        uint32_t* symbol_index) const {
+  uint32_t hash = symbol_name.elf_hash();
+
+  TRACE_TYPE(LOOKUP, "SEARCH %s in %s@%p h=%x(elf) %zd",
+             symbol_name.get_name(), get_realpath(),
+             reinterpret_cast<void*>(base), hash, hash % nbucket_);
+
+  ElfW(Versym) verneed = 0;
+  if (!find_verdef_version_index(this, vi, &verneed)) {
+    return false;
+  }
+
+  for (uint32_t n = bucket_[hash % nbucket_]; n != 0; n = chain_[n]) {
+    ElfW(Sym)* s = symtab_ + n;
+    const ElfW(Versym)* verdef = get_versym(n);
+
+    // skip hidden versions when verneed == 0
+    if (verneed == kVersymNotNeeded && is_versym_hidden(verdef)) {
+        continue;
+    }
+
+    if (check_symbol_version(verneed, verdef) &&
+        strcmp(get_string(s->st_name), symbol_name.get_name()) == 0 &&
+        is_symbol_global_and_defined(this, s)) {
+      TRACE_TYPE(LOOKUP, "FOUND %s in %s (%p) %zd",
+                 symbol_name.get_name(), get_realpath(),
+                 reinterpret_cast<void*>(s->st_value),
+                 static_cast<size_t>(s->st_size));
+      *symbol_index = n;
+      return true;
+    }
+  }
+
+  TRACE_TYPE(LOOKUP, "NOT FOUND %s in %s@%p %x %zd",
+             symbol_name.get_name(), get_realpath(),
+             reinterpret_cast<void*>(base), hash, hash % nbucket_);
+
+  *symbol_index = 0;
+  return true;
+}
+
+ElfW(Sym)* soinfo::find_symbol_by_address(const void* addr) {
+  return is_gnu_hash() ? gnu_addr_lookup(addr) : elf_addr_lookup(addr);
+}
+
+static bool symbol_matches_soaddr(const ElfW(Sym)* sym, ElfW(Addr) soaddr) {
+  return sym->st_shndx != SHN_UNDEF &&
+      soaddr >= sym->st_value &&
+      soaddr < sym->st_value + sym->st_size;
+}
+
+ElfW(Sym)* soinfo::gnu_addr_lookup(const void* addr) {
+  ElfW(Addr) soaddr = reinterpret_cast<ElfW(Addr)>(addr) - load_bias;
+
+  for (size_t i = 0; i < gnu_nbucket_; ++i) {
+    uint32_t n = gnu_bucket_[i];
+
+    if (n == 0) {
+      continue;
+    }
+
+    do {
+      ElfW(Sym)* sym = symtab_ + n;
+      if (symbol_matches_soaddr(sym, soaddr)) {
+        return sym;
+      }
+    } while ((gnu_chain_[n++] & 1) == 0);
+  }
+
+  return nullptr;
+}
+
+ElfW(Sym)* soinfo::elf_addr_lookup(const void* addr) {
+  ElfW(Addr) soaddr = reinterpret_cast<ElfW(Addr)>(addr) - load_bias;
+
+  // Search the library's symbol table for any defined symbol which
+  // contains this address.
+  for (size_t i = 0; i < nchain_; ++i) {
+    ElfW(Sym)* sym = symtab_ + i;
+    if (symbol_matches_soaddr(sym, soaddr)) {
+      return sym;
+    }
+  }
+
+  return nullptr;
+}
+
+static void call_function(const char* function_name __unused,
+                          linker_ctor_function_t function,
+                          const char* realpath __unused) {
+  if (function == nullptr || reinterpret_cast<uintptr_t>(function) == static_cast<uintptr_t>(-1)) {
+    return;
+  }
+
+  TRACE("[ Calling c-tor %s @ %p for '%s' ]", function_name, function, realpath);
+  function(g_argc, g_argv, g_envp);
+  TRACE("[ Done calling c-tor %s @ %p for '%s' ]", function_name, function, realpath);
+}
+
+static void call_function(const char* function_name __unused,
+                          linker_dtor_function_t function,
+                          const char* realpath __unused) {
+  if (function == nullptr || reinterpret_cast<uintptr_t>(function) == static_cast<uintptr_t>(-1)) {
+    return;
+  }
+
+  TRACE("[ Calling d-tor %s @ %p for '%s' ]", function_name, function, realpath);
+  function();
+  TRACE("[ Done calling d-tor %s @ %p for '%s' ]", function_name, function, realpath);
+}
+
+template <typename F>
+static void call_array(const char* array_name __unused,
+                       F* functions,
+                       size_t count,
+                       bool reverse,
+                       const char* realpath) {
+  if (functions == nullptr) {
+    return;
+  }
+
+  TRACE("[ Calling %s (size %zd) @ %p for '%s' ]", array_name, count, functions, realpath);
+
+  int begin = reverse ? (count - 1) : 0;
+  int end = reverse ? -1 : count;
+  int step = reverse ? -1 : 1;
+
+  for (int i = begin; i != end; i += step) {
+    TRACE("[ %s[%d] == %p ]", array_name, i, functions[i]);
+    call_function("function", functions[i], realpath);
+  }
+
+  TRACE("[ Done calling %s for '%s' ]", array_name, realpath);
+}
+
+void soinfo::call_pre_init_constructors() {
+  // DT_PREINIT_ARRAY functions are called before any other constructors for executables,
+  // but ignored in a shared library.
+  call_array("DT_PREINIT_ARRAY", preinit_array_, preinit_array_count_, false, get_realpath());
+}
+
+void soinfo::call_constructors() {
+  if (constructors_called) {
+    return;
+  }
+
+  // We set constructors_called before actually calling the constructors, otherwise it doesn't
+  // protect against recursive constructor calls. One simple example of constructor recursion
+  // is the libc debug malloc, which is implemented in libc_malloc_debug_leak.so:
+  // 1. The program depends on libc, so libc's constructor is called here.
+  // 2. The libc constructor calls dlopen() to load libc_malloc_debug_leak.so.
+  // 3. dlopen() calls the constructors on the newly created
+  //    soinfo for libc_malloc_debug_leak.so.
+  // 4. The debug .so depends on libc, so CallConstructors is
+  //    called again with the libc soinfo. If it doesn't trigger the early-
+  //    out above, the libc constructor will be called again (recursively!).
+  constructors_called = true;
+
+  if (!is_main_executable() && preinit_array_ != nullptr) {
+    // The GNU dynamic linker silently ignores these, but we warn the developer.
+    PRINT("\"%s\": ignoring DT_PREINIT_ARRAY in shared library!", get_realpath());
+  }
+
+  get_children().for_each([] (soinfo* si) {
+    si->call_constructors();
+  });
+
+  TRACE("\"%s\": calling constructors", get_realpath());
+
+  // DT_INIT should be called before DT_INIT_ARRAY if both are present.
+  call_function("DT_INIT", init_func_, get_realpath());
+  call_array("DT_INIT_ARRAY", init_array_, init_array_count_, false, get_realpath());
+}
+
+void soinfo::call_destructors() {
+  if (!constructors_called) {
+    return;
+  }
+  TRACE("\"%s\": calling destructors", get_realpath());
+
+  // DT_FINI_ARRAY must be parsed in reverse order.
+  call_array("DT_FINI_ARRAY", fini_array_, fini_array_count_, true, get_realpath());
+
+  // DT_FINI should be called after DT_FINI_ARRAY if both are present.
+  call_function("DT_FINI", fini_func_, get_realpath());
+}
+
+void soinfo::add_child(soinfo* child) {
+  if (has_min_version(0)) {
+    child->parents_.push_back(this);
+    this->children_.push_back(child);
+  }
+}
+
+void soinfo::remove_all_links() {
+  if (!has_min_version(0)) {
+    return;
+  }
+
+  // 1. Untie connected soinfos from 'this'.
+  children_.for_each([&] (soinfo* child) {
+    child->parents_.remove_if([&] (const soinfo* parent) {
+      return parent == this;
+    });
+  });
+
+  parents_.for_each([&] (soinfo* parent) {
+    parent->children_.remove_if([&] (const soinfo* child) {
+      return child == this;
+    });
+  });
+
+  // 2. Remove from the primary namespace
+  primary_namespace_->remove_soinfo(this);
+  primary_namespace_ = nullptr;
+
+  // 3. Remove from secondary namespaces
+  secondary_namespaces_.for_each([&](android_namespace_t* ns) {
+    ns->remove_soinfo(this);
+  });
+
+
+  // 4. Once everything untied - clear local lists.
+  parents_.clear();
+  children_.clear();
+  secondary_namespaces_.clear();
+}
+
+dev_t soinfo::get_st_dev() const {
+  if (has_min_version(0)) {
+    return st_dev_;
+  }
+
+  return 0;
+};
+
+ino_t soinfo::get_st_ino() const {
+  if (has_min_version(0)) {
+    return st_ino_;
+  }
+
+  return 0;
+}
+
+off64_t soinfo::get_file_offset() const {
+  if (has_min_version(1)) {
+    return file_offset_;
+  }
+
+  return 0;
+}
+
+uint32_t soinfo::get_rtld_flags() const {
+  if (has_min_version(1)) {
+    return rtld_flags_;
+  }
+
+  return 0;
+}
+
+uint32_t soinfo::get_dt_flags_1() const {
+  if (has_min_version(1)) {
+    return dt_flags_1_;
+  }
+
+  return 0;
+}
+
+void soinfo::set_dt_flags_1(uint32_t dt_flags_1) {
+  if (has_min_version(1)) {
+    if ((dt_flags_1 & DF_1_GLOBAL) != 0) {
+      rtld_flags_ |= RTLD_GLOBAL;
+    }
+
+    if ((dt_flags_1 & DF_1_NODELETE) != 0) {
+      rtld_flags_ |= RTLD_NODELETE;
+    }
+
+    dt_flags_1_ = dt_flags_1;
+  }
+}
+
+void soinfo::set_nodelete() {
+  rtld_flags_ |= RTLD_NODELETE;
+}
+
+const char* soinfo::get_realpath() const {
+#if defined(__work_around_b_24465209__)
+  if (has_min_version(2)) {
+    return realpath_.c_str();
+  } else {
+    return old_name_;
+  }
+#else
+  return realpath_.c_str();
+#endif
+}
+
+void soinfo::set_soname(const char* soname) {
+#if defined(__work_around_b_24465209__)
+  if (has_min_version(2)) {
+    soname_ = soname;
+  }
+  strlcpy(old_name_, soname_, sizeof(old_name_));
+#else
+  soname_ = soname;
+#endif
+}
+
+const char* soinfo::get_soname() const {
+#if defined(__work_around_b_24465209__)
+  if (has_min_version(2)) {
+    return soname_;
+  } else {
+    return old_name_;
+  }
+#else
+  return soname_;
+#endif
+}
+
+// This is a return on get_children()/get_parents() if
+// 'this->flags' does not have FLAG_NEW_SOINFO set.
+static soinfo_list_t g_empty_list;
+
+soinfo_list_t& soinfo::get_children() {
+  if (has_min_version(0)) {
+    return children_;
+  }
+
+  return g_empty_list;
+}
+
+const soinfo_list_t& soinfo::get_children() const {
+  if (has_min_version(0)) {
+    return children_;
+  }
+
+  return g_empty_list;
+}
+
+soinfo_list_t& soinfo::get_parents() {
+  if (has_min_version(0)) {
+    return parents_;
+  }
+
+  return g_empty_list;
+}
+
+static std::vector<std::string> g_empty_runpath;
+
+const std::vector<std::string>& soinfo::get_dt_runpath() const {
+  if (has_min_version(3)) {
+    return dt_runpath_;
+  }
+
+  return g_empty_runpath;
+}
+
+android_namespace_t* soinfo::get_primary_namespace() {
+  if (has_min_version(3)) {
+    return primary_namespace_;
+  }
+
+  return &g_default_namespace;
+}
+
+void soinfo::add_secondary_namespace(android_namespace_t* secondary_ns) {
+  CHECK(has_min_version(3));
+  secondary_namespaces_.push_back(secondary_ns);
+}
+
+ElfW(Addr) soinfo::resolve_symbol_address(const ElfW(Sym)* s) const {
+  if (ELF_ST_TYPE(s->st_info) == STT_GNU_IFUNC) {
+    return call_ifunc_resolver(s->st_value + load_bias);
+  }
+
+  return static_cast<ElfW(Addr)>(s->st_value + load_bias);
+}
+
+const char* soinfo::get_string(ElfW(Word) index) const {
+  if (has_min_version(1) && (index >= strtab_size_)) {
+    __libc_fatal("%s: strtab out of bounds error; STRSZ=%zd, name=%d",
+        get_realpath(), strtab_size_, index);
+  }
+
+  return strtab_ + index;
+}
+
+bool soinfo::is_gnu_hash() const {
+  return (flags_ & FLAG_GNU_HASH) != 0;
+}
+
+bool soinfo::can_unload() const {
+  return !is_linked() || ((get_rtld_flags() & (RTLD_NODELETE | RTLD_GLOBAL)) == 0);
+}
+
+bool soinfo::is_linked() const {
+  return (flags_ & FLAG_LINKED) != 0;
+}
+
+bool soinfo::is_main_executable() const {
+  return (flags_ & FLAG_EXE) != 0;
+}
+
+bool soinfo::is_linker() const {
+  return (flags_ & FLAG_LINKER) != 0;
+}
+
+void soinfo::set_linked() {
+  flags_ |= FLAG_LINKED;
+}
+
+void soinfo::set_linker_flag() {
+  flags_ |= FLAG_LINKER;
+}
+
+void soinfo::set_main_executable() {
+  flags_ |= FLAG_EXE;
+}
+
+void soinfo::increment_ref_count() {
+  local_group_root_->ref_count_++;
+}
+
+size_t soinfo::decrement_ref_count() {
+  return --local_group_root_->ref_count_;
+}
+
+soinfo* soinfo::get_local_group_root() const {
+  return local_group_root_;
+}
+
+
+void soinfo::set_mapped_by_caller(bool mapped_by_caller) {
+  if (mapped_by_caller) {
+    flags_ |= FLAG_MAPPED_BY_CALLER;
+  } else {
+    flags_ &= ~FLAG_MAPPED_BY_CALLER;
+  }
+}
+
+bool soinfo::is_mapped_by_caller() const {
+  return (flags_ & FLAG_MAPPED_BY_CALLER) != 0;
+}
+
+// This function returns api-level at the time of
+// dlopen/load. Note that libraries opened by system
+// will always have 'current' api level.
+uint32_t soinfo::get_target_sdk_version() const {
+  if (!has_min_version(2)) {
+    return __ANDROID_API__;
+  }
+
+  return local_group_root_->target_sdk_version_;
+}
+
+uintptr_t soinfo::get_handle() const {
+  CHECK(has_min_version(3));
+  CHECK(handle_ != 0);
+  return handle_;
+}
+
+void* soinfo::to_handle() {
+  if (get_application_target_sdk_version() <= 23 || !has_min_version(3)) {
+    return this;
+  }
+
+  return reinterpret_cast<void*>(get_handle());
+}
+
+void soinfo::generate_handle() {
+  CHECK(has_min_version(3));
+  CHECK(handle_ == 0); // Make sure this is the first call
+
+  // Make sure the handle is unique and does not collide
+  // with special values which are RTLD_DEFAULT and RTLD_NEXT.
+  do {
+    arc4random_buf(&handle_, sizeof(handle_));
+    // the least significant bit for the handle is always 1
+    // making it easy to test the type of handle passed to
+    // dl* functions.
+    handle_ = handle_ | 1;
+  } while (handle_ == reinterpret_cast<uintptr_t>(RTLD_DEFAULT) ||
+           handle_ == reinterpret_cast<uintptr_t>(RTLD_NEXT) ||
+           g_soinfo_handles_map.find(handle_) != g_soinfo_handles_map.end());
+
+  g_soinfo_handles_map[handle_] = this;
+}
+
+// TODO(dimitry): Move SymbolName methods to a separate file.
+
+uint32_t calculate_elf_hash(const char* name) {
+  const uint8_t* name_bytes = reinterpret_cast<const uint8_t*>(name);
+  uint32_t h = 0, g;
+
+  while (*name_bytes) {
+    h = (h << 4) + *name_bytes++;
+    g = h & 0xf0000000;
+    h ^= g;
+    h ^= g >> 24;
+  }
+
+  return h;
+}
+
+uint32_t SymbolName::elf_hash() {
+  if (!has_elf_hash_) {
+    elf_hash_ = calculate_elf_hash(name_);
+    has_elf_hash_ = true;
+  }
+
+  return elf_hash_;
+}
+
+uint32_t SymbolName::gnu_hash() {
+  if (!has_gnu_hash_) {
+    uint32_t h = 5381;
+    const uint8_t* name = reinterpret_cast<const uint8_t*>(name_);
+    while (*name != 0) {
+      h += (h << 5) + *name++; // h*33 + c = h + h * 32 + c = h + h << 5 + c
+    }
+
+    gnu_hash_ =  h;
+    has_gnu_hash_ = true;
+  }
+
+  return gnu_hash_;
+}
+
+
diff --git a/linker/linker_soinfo.h b/linker/linker_soinfo.h
new file mode 100644
index 0000000..d7b584e
--- /dev/null
+++ b/linker/linker_soinfo.h
@@ -0,0 +1,345 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#ifndef __LINKER_SOINFO_H
+#define __LINKER_SOINFO_H
+
+#include <link.h>
+
+#include <string>
+
+#include "linker_namespaces.h"
+
+#define FLAG_LINKED           0x00000001
+#define FLAG_EXE              0x00000004 // The main executable
+#define FLAG_LINKER           0x00000010 // The linker itself
+#define FLAG_GNU_HASH         0x00000040 // uses gnu hash
+#define FLAG_MAPPED_BY_CALLER 0x00000080 // the map is reserved by the caller
+                                         // and should not be unmapped
+#define FLAG_NEW_SOINFO       0x40000000 // new soinfo format
+
+#define SOINFO_VERSION 3
+
+typedef void (*linker_dtor_function_t)();
+typedef void (*linker_ctor_function_t)(int, char**, char**);
+
+class SymbolName {
+ public:
+  explicit SymbolName(const char* name)
+      : name_(name), has_elf_hash_(false), has_gnu_hash_(false),
+        elf_hash_(0), gnu_hash_(0) { }
+
+  const char* get_name() {
+    return name_;
+  }
+
+  uint32_t elf_hash();
+  uint32_t gnu_hash();
+
+ private:
+  const char* name_;
+  bool has_elf_hash_;
+  bool has_gnu_hash_;
+  uint32_t elf_hash_;
+  uint32_t gnu_hash_;
+
+  DISALLOW_IMPLICIT_CONSTRUCTORS(SymbolName);
+};
+
+struct version_info {
+  constexpr version_info() : elf_hash(0), name(nullptr), target_si(nullptr) {}
+
+  uint32_t elf_hash;
+  const char* name;
+  const soinfo* target_si;
+};
+
+// TODO(dimitry): remove reference from soinfo member functions to this class.
+class VersionTracker;
+
+#if defined(__work_around_b_24465209__)
+#define SOINFO_NAME_LEN 128
+#endif
+
+struct soinfo {
+#if defined(__work_around_b_24465209__)
+ private:
+  char old_name_[SOINFO_NAME_LEN];
+#endif
+ public:
+  const ElfW(Phdr)* phdr;
+  size_t phnum;
+#if defined(__work_around_b_24465209__)
+  ElfW(Addr) unused0; // DO NOT USE, maintained for compatibility.
+#endif
+  ElfW(Addr) base;
+  size_t size;
+
+#if defined(__work_around_b_24465209__)
+  uint32_t unused1;  // DO NOT USE, maintained for compatibility.
+#endif
+
+  ElfW(Dyn)* dynamic;
+
+#if defined(__work_around_b_24465209__)
+  uint32_t unused2; // DO NOT USE, maintained for compatibility
+  uint32_t unused3; // DO NOT USE, maintained for compatibility
+#endif
+
+  soinfo* next;
+ private:
+  uint32_t flags_;
+
+  const char* strtab_;
+  ElfW(Sym)* symtab_;
+
+  size_t nbucket_;
+  size_t nchain_;
+  uint32_t* bucket_;
+  uint32_t* chain_;
+
+#if defined(__mips__) || !defined(__LP64__)
+  // This is only used by mips and mips64, but needs to be here for
+  // all 32-bit architectures to preserve binary compatibility.
+  ElfW(Addr)** plt_got_;
+#endif
+
+#if defined(USE_RELA)
+  ElfW(Rela)* plt_rela_;
+  size_t plt_rela_count_;
+
+  ElfW(Rela)* rela_;
+  size_t rela_count_;
+#else
+  ElfW(Rel)* plt_rel_;
+  size_t plt_rel_count_;
+
+  ElfW(Rel)* rel_;
+  size_t rel_count_;
+#endif
+
+  linker_ctor_function_t* preinit_array_;
+  size_t preinit_array_count_;
+
+  linker_ctor_function_t* init_array_;
+  size_t init_array_count_;
+  linker_dtor_function_t* fini_array_;
+  size_t fini_array_count_;
+
+  linker_ctor_function_t init_func_;
+  linker_dtor_function_t fini_func_;
+
+#if defined(__arm__)
+ public:
+  // ARM EABI section used for stack unwinding.
+  uint32_t* ARM_exidx;
+  size_t ARM_exidx_count;
+ private:
+#elif defined(__mips__)
+  uint32_t mips_symtabno_;
+  uint32_t mips_local_gotno_;
+  uint32_t mips_gotsym_;
+  bool mips_relocate_got(const VersionTracker& version_tracker,
+                         const soinfo_list_t& global_group,
+                         const soinfo_list_t& local_group);
+#if !defined(__LP64__)
+  bool mips_check_and_adjust_fp_modes();
+#endif
+#endif
+  size_t ref_count_;
+ public:
+  link_map link_map_head;
+
+  bool constructors_called;
+
+  // When you read a virtual address from the ELF file, add this
+  // value to get the corresponding address in the process' address space.
+  ElfW(Addr) load_bias;
+
+#if !defined(__LP64__)
+  bool has_text_relocations;
+#endif
+  bool has_DT_SYMBOLIC;
+
+ public:
+  soinfo(android_namespace_t* ns, const char* name, const struct stat* file_stat,
+         off64_t file_offset, int rtld_flags);
+  ~soinfo();
+
+  void call_constructors();
+  void call_destructors();
+  void call_pre_init_constructors();
+  bool prelink_image();
+  bool link_image(const soinfo_list_t& global_group, const soinfo_list_t& local_group,
+                  const android_dlextinfo* extinfo);
+  bool protect_relro();
+
+  void add_child(soinfo* child);
+  void remove_all_links();
+
+  ino_t get_st_ino() const;
+  dev_t get_st_dev() const;
+  off64_t get_file_offset() const;
+
+  uint32_t get_rtld_flags() const;
+  uint32_t get_dt_flags_1() const;
+  void set_dt_flags_1(uint32_t dt_flags_1);
+
+  soinfo_list_t& get_children();
+  const soinfo_list_t& get_children() const;
+
+  soinfo_list_t& get_parents();
+
+  bool find_symbol_by_name(SymbolName& symbol_name,
+                           const version_info* vi,
+                           const ElfW(Sym)** symbol) const;
+
+  ElfW(Sym)* find_symbol_by_address(const void* addr);
+  ElfW(Addr) resolve_symbol_address(const ElfW(Sym)* s) const;
+
+  const char* get_string(ElfW(Word) index) const;
+  bool can_unload() const;
+  bool is_gnu_hash() const;
+
+  bool inline has_min_version(uint32_t min_version __unused) const {
+#if defined(__work_around_b_24465209__)
+    return (flags_ & FLAG_NEW_SOINFO) != 0 && version_ >= min_version;
+#else
+    return true;
+#endif
+  }
+
+  bool is_linked() const;
+  bool is_linker() const;
+  bool is_main_executable() const;
+
+  void set_linked();
+  void set_linker_flag();
+  void set_main_executable();
+  void set_nodelete();
+
+  void increment_ref_count();
+  size_t decrement_ref_count();
+
+  soinfo* get_local_group_root() const;
+
+  void set_soname(const char* soname);
+  const char* get_soname() const;
+  const char* get_realpath() const;
+  const ElfW(Versym)* get_versym(size_t n) const;
+  ElfW(Addr) get_verneed_ptr() const;
+  size_t get_verneed_cnt() const;
+  ElfW(Addr) get_verdef_ptr() const;
+  size_t get_verdef_cnt() const;
+
+  uint32_t get_target_sdk_version() const;
+
+  void set_dt_runpath(const char *);
+  const std::vector<std::string>& get_dt_runpath() const;
+  android_namespace_t* get_primary_namespace();
+  void add_secondary_namespace(android_namespace_t* secondary_ns);
+
+  void set_mapped_by_caller(bool reserved_map);
+  bool is_mapped_by_caller() const;
+
+  uintptr_t get_handle() const;
+  void generate_handle();
+  void* to_handle();
+
+ private:
+  bool elf_lookup(SymbolName& symbol_name, const version_info* vi, uint32_t* symbol_index) const;
+  ElfW(Sym)* elf_addr_lookup(const void* addr);
+  bool gnu_lookup(SymbolName& symbol_name, const version_info* vi, uint32_t* symbol_index) const;
+  ElfW(Sym)* gnu_addr_lookup(const void* addr);
+
+  bool lookup_version_info(const VersionTracker& version_tracker, ElfW(Word) sym,
+                           const char* sym_name, const version_info** vi);
+
+  template<typename ElfRelIteratorT>
+  bool relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& rel_iterator,
+                const soinfo_list_t& global_group, const soinfo_list_t& local_group);
+
+ private:
+  // This part of the structure is only available
+  // when FLAG_NEW_SOINFO is set in this->flags.
+  uint32_t version_;
+
+  // version >= 0
+  dev_t st_dev_;
+  ino_t st_ino_;
+
+  // dependency graph
+  soinfo_list_t children_;
+  soinfo_list_t parents_;
+
+  // version >= 1
+  off64_t file_offset_;
+  uint32_t rtld_flags_;
+  uint32_t dt_flags_1_;
+  size_t strtab_size_;
+
+  // version >= 2
+
+  size_t gnu_nbucket_;
+  uint32_t* gnu_bucket_;
+  uint32_t* gnu_chain_;
+  uint32_t gnu_maskwords_;
+  uint32_t gnu_shift2_;
+  ElfW(Addr)* gnu_bloom_filter_;
+
+  soinfo* local_group_root_;
+
+  uint8_t* android_relocs_;
+  size_t android_relocs_size_;
+
+  const char* soname_;
+  std::string realpath_;
+
+  const ElfW(Versym)* versym_;
+
+  ElfW(Addr) verdef_ptr_;
+  size_t verdef_cnt_;
+
+  ElfW(Addr) verneed_ptr_;
+  size_t verneed_cnt_;
+
+  uint32_t target_sdk_version_;
+
+  // version >= 3
+  std::vector<std::string> dt_runpath_;
+  android_namespace_t* primary_namespace_;
+  android_namespace_list_t secondary_namespaces_;
+  uintptr_t handle_;
+
+  friend soinfo* get_libdl_info();
+};
+
+// This function is used by dlvsym() to calculate hash of sym_ver
+uint32_t calculate_elf_hash(const char* name);
+
+#endif  /* __LINKER_SOINFO_H */
diff --git a/linker/linker_utils.cpp b/linker/linker_utils.cpp
index fb070ee..e7447e4 100644
--- a/linker/linker_utils.cpp
+++ b/linker/linker_utils.cpp
@@ -15,7 +15,26 @@
  */
 
 #include "linker_utils.h"
+
 #include "linker_debug.h"
+#include "linker_globals.h"
+
+#include "android-base/strings.h"
+
+#include <sys/stat.h>
+#include <unistd.h>
+
+std::string dirname(const char* path) {
+  const char* last_slash = strrchr(path, '/');
+
+  if (last_slash == path) {
+    return "/";
+  } else if (last_slash == nullptr) {
+    return ".";
+  } else {
+    return std::string(path, last_slash - path);
+  }
+}
 
 bool normalize_path(const char* path, std::string* normalized_path) {
   // Input should be an absolute path
@@ -134,3 +153,52 @@
   return static_cast<size_t>(offset & (PAGE_SIZE-1));
 }
 
+void split_path(const char* path, const char* delimiters,
+                std::vector<std::string>* paths) {
+  if (path != nullptr && path[0] != 0) {
+    *paths = android::base::Split(path, delimiters);
+  }
+}
+
+void resolve_paths(std::vector<std::string>& paths,
+                   std::vector<std::string>* resolved_paths) {
+  resolved_paths->clear();
+  for (const auto& path : paths) {
+    char resolved_path[PATH_MAX];
+    const char* original_path = path.c_str();
+    if (realpath(original_path, resolved_path) != nullptr) {
+      struct stat s;
+      if (stat(resolved_path, &s) == 0) {
+        if (S_ISDIR(s.st_mode)) {
+          resolved_paths->push_back(resolved_path);
+        } else {
+          DL_WARN("Warning: \"%s\" is not a directory (excluding from path)", resolved_path);
+          continue;
+        }
+      } else {
+        DL_WARN("Warning: cannot stat file \"%s\": %s", resolved_path, strerror(errno));
+        continue;
+      }
+    } else {
+      std::string zip_path;
+      std::string entry_path;
+
+      std::string normalized_path;
+
+      if (!normalize_path(original_path, &normalized_path)) {
+        DL_WARN("Warning: unable to normalize \"%s\"", original_path);
+        continue;
+      }
+
+      if (parse_zip_path(normalized_path.c_str(), &zip_path, &entry_path)) {
+        if (realpath(zip_path.c_str(), resolved_path) == nullptr) {
+          DL_WARN("Warning: unable to resolve \"%s\": %s", zip_path.c_str(), strerror(errno));
+          continue;
+        }
+
+        resolved_paths->push_back(std::string(resolved_path) + kZipFileSeparator + entry_path);
+      }
+    }
+  }
+}
+
diff --git a/linker/linker_utils.h b/linker/linker_utils.h
index 987eabd..2e015a5 100644
--- a/linker/linker_utils.h
+++ b/linker/linker_utils.h
@@ -17,14 +17,25 @@
 #define __LINKER_UTILS_H
 
 #include <string>
+#include <vector>
 
 extern const char* const kZipFileSeparator;
 
-bool normalize_path(const char* path, std::string* normalized_path);
 bool file_is_in_dir(const std::string& file, const std::string& dir);
 bool file_is_under_dir(const std::string& file, const std::string& dir);
+bool normalize_path(const char* path, std::string* normalized_path);
 bool parse_zip_path(const char* input_path, std::string* zip_path, std::string* entry_path);
 
+// For every path element this function checks of it exists, and is a directory,
+// and normalizes it:
+// 1. For regular path it converts it to realpath()
+// 2. For path in a zip file it uses realpath on the zipfile
+//    normalizes entry name by calling normalize_path function.
+void resolve_paths(std::vector<std::string>& paths, std::vector<std::string>* resolved_paths);
+void split_path(const char* path, const char* delimiters, std::vector<std::string>* paths);
+
+std::string dirname(const char* path);
+
 off64_t page_start(off64_t offset);
 size_t page_offset(off64_t offset);
 bool safe_add(off64_t* out, off64_t a, size_t b);
diff --git a/linker/tests/Android.mk b/linker/tests/Android.mk
index a061877..d5b57f1 100644
--- a/linker/tests/Android.mk
+++ b/linker/tests/Android.mk
@@ -27,16 +27,19 @@
 LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../libc/
 
 LOCAL_SRC_FILES := \
+  linker_block_allocator_test.cpp \
   linker_globals.cpp \
   linked_list_test.cpp \
-  linker_block_allocator_test.cpp \
-  ../linker_block_allocator.cpp \
   linker_memory_allocator_test.cpp \
-  ../linker_allocator.cpp \
+  linker_sleb128_test.cpp \
   linker_utils_test.cpp \
+  ../linker_allocator.cpp \
+  ../linker_block_allocator.cpp \
   ../linker_utils.cpp
 
 # for __libc_fatal
 LOCAL_SRC_FILES += ../../libc/bionic/libc_logging.cpp
 
+LOCAL_STATIC_LIBRARIES += libbase
+
 include $(BUILD_NATIVE_TEST)
diff --git a/linker/tests/linker_sleb128_test.cpp b/linker/tests/linker_sleb128_test.cpp
new file mode 100644
index 0000000..4e29bca
--- /dev/null
+++ b/linker/tests/linker_sleb128_test.cpp
@@ -0,0 +1,98 @@
+/*
+ * 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.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+
+#include <gtest/gtest.h>
+
+#include "../linker_sleb128.h"
+
+TEST(linker_sleb128, smoke) {
+  std::vector<uint8_t> encoding;
+  // 624485
+  encoding.push_back(0xe5);
+  encoding.push_back(0x8e);
+  encoding.push_back(0x26);
+  // 0
+  encoding.push_back(0x00);
+  // 1
+  encoding.push_back(0x01);
+  // 63
+  encoding.push_back(0x3f);
+  // 64
+  encoding.push_back(0xc0);
+  encoding.push_back(0x00);
+  // -1
+  encoding.push_back(0x7f);
+  // -624485
+  encoding.push_back(0x9b);
+  encoding.push_back(0xf1);
+  encoding.push_back(0x59);
+  // 2147483647
+  encoding.push_back(0xff);
+  encoding.push_back(0xff);
+  encoding.push_back(0xff);
+  encoding.push_back(0xff);
+  encoding.push_back(0x07);
+  // -2147483648
+  encoding.push_back(0x80);
+  encoding.push_back(0x80);
+  encoding.push_back(0x80);
+  encoding.push_back(0x80);
+  encoding.push_back(0x78);
+#if defined(__LP64__)
+  // 9223372036854775807
+  encoding.push_back(0xff);
+  encoding.push_back(0xff);
+  encoding.push_back(0xff);
+  encoding.push_back(0xff);
+  encoding.push_back(0xff);
+  encoding.push_back(0xff);
+  encoding.push_back(0xff);
+  encoding.push_back(0xff);
+  encoding.push_back(0xff);
+  encoding.push_back(0x00);
+  // -9223372036854775808
+  encoding.push_back(0x80);
+  encoding.push_back(0x80);
+  encoding.push_back(0x80);
+  encoding.push_back(0x80);
+  encoding.push_back(0x80);
+  encoding.push_back(0x80);
+  encoding.push_back(0x80);
+  encoding.push_back(0x80);
+  encoding.push_back(0x80);
+  encoding.push_back(0x7f);
+#endif
+  sleb128_decoder decoder(&encoding[0], encoding.size());
+
+  EXPECT_EQ(624485U, decoder.pop_front());
+
+  EXPECT_EQ(0U, decoder.pop_front());
+  EXPECT_EQ(1U, decoder.pop_front());
+  EXPECT_EQ(63U, decoder.pop_front());
+  EXPECT_EQ(64U, decoder.pop_front());
+  EXPECT_EQ(static_cast<size_t>(-1), decoder.pop_front());
+  EXPECT_EQ(static_cast<size_t>(-624485), decoder.pop_front());
+  EXPECT_EQ(2147483647U, decoder.pop_front());
+  EXPECT_EQ(static_cast<size_t>(-2147483648), decoder.pop_front());
+#if defined(__LP64__)
+  EXPECT_EQ(9223372036854775807ULL, decoder.pop_front());
+  EXPECT_EQ(static_cast<uint64_t>(-9223372036854775807LL - 1), decoder.pop_front());
+#endif
+}
diff --git a/tests/Android.bp b/tests/Android.bp
new file mode 100644
index 0000000..8f937a3
--- /dev/null
+++ b/tests/Android.bp
@@ -0,0 +1,411 @@
+//
+// 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.
+//
+
+cc_defaults {
+    name: "bionic_tests_defaults",
+    host_supported: true,
+    target: {
+        darwin: {
+            enabled: false,
+        },
+    },
+    cflags: [
+        "-fstack-protector-all",
+        "-g",
+        "-Wall",
+        "-Wextra",
+        "-Wunused",
+        "-Werror",
+        "-fno-builtin",
+
+        // We want to test deprecated API too.
+        "-Wno-deprecated-declarations",
+
+        // For glibc.
+        "-D__STDC_LIMIT_MACROS",
+    ],
+    stl: "libc++",
+    sanitize: {
+        never: true,
+    },
+}
+
+// -----------------------------------------------------------------------------
+// All standard tests.
+// -----------------------------------------------------------------------------
+
+cc_test_library {
+    name: "libBionicStandardTests",
+    defaults: ["bionic_tests_defaults"],
+    srcs: [
+        "arpa_inet_test.cpp",
+        "assert_test.cpp",
+        "buffer_tests.cpp",
+        "bug_26110743_test.cpp",
+        "complex_test.cpp",
+        "ctype_test.cpp",
+        "dirent_test.cpp",
+        "error_test.cpp",
+        "eventfd_test.cpp",
+        "fcntl_test.cpp",
+        "fenv_test.cpp",
+        "ftw_test.cpp",
+        "getauxval_test.cpp",
+        "getcwd_test.cpp",
+        "grp_pwd_test.cpp",
+        "ifaddrs_test.cpp",
+        "inttypes_test.cpp",
+        "libc_logging_test.cpp",
+        "libgen_basename_test.cpp",
+        "libgen_test.cpp",
+        "locale_test.cpp",
+        "malloc_test.cpp",
+        "math_test.cpp",
+        "mntent_test.cpp",
+        "netdb_test.cpp",
+        "net_if_test.cpp",
+        "netinet_ether_test.cpp",
+        "netinet_in_test.cpp",
+        "netinet_udp_test.cpp",
+        "nl_types_test.cpp",
+        "pthread_test.cpp",
+        "pty_test.cpp",
+        "regex_test.cpp",
+        "resolv_test.cpp",
+        "sched_test.cpp",
+        "search_test.cpp",
+        "semaphore_test.cpp",
+        "setjmp_test.cpp",
+        "signal_test.cpp",
+        "stack_protector_test.cpp",
+        "stack_protector_test_helper.cpp",
+        "stack_unwinding_test.cpp",
+        "stdatomic_test.cpp",
+        "stdint_test.cpp",
+        "stdio_nofortify_test.cpp",
+        "stdio_test.cpp",
+        "stdio_ext_test.cpp",
+        "stdlib_test.cpp",
+        "string_nofortify_test.cpp",
+        "string_test.cpp",
+        "string_posix_strerror_r_test.cpp",
+        "strings_nofortify_test.cpp",
+        "strings_test.cpp",
+        "sstream_test.cpp",
+        "sys_epoll_test.cpp",
+        "sys_mman_test.cpp",
+        "sys_personality_test.cpp",
+        "sys_prctl_test.cpp",
+        "sys_procfs_test.cpp",
+        "sys_ptrace_test.cpp",
+        "sys_quota_test.cpp",
+        "sys_resource_test.cpp",
+        "sys_select_test.cpp",
+        "sys_sendfile_test.cpp",
+        "sys_socket_test.cpp",
+        "sys_stat_test.cpp",
+        "sys_statvfs_test.cpp",
+        "sys_syscall_test.cpp",
+        "sys_sysinfo_test.cpp",
+        "sys_sysmacros_test.cpp",
+        "sys_time_test.cpp",
+        "sys_timex_test.cpp",
+        "sys_types_test.cpp",
+        "sys_uio_test.cpp",
+        "sys_vfs_test.cpp",
+        "sys_xattr_test.cpp",
+        "system_properties_test.cpp",
+        "time_test.cpp",
+        "uchar_test.cpp",
+        "unistd_nofortify_test.cpp",
+        "unistd_test.cpp",
+        "utmp_test.cpp",
+        "wchar_test.cpp",
+        "wctype_test.cpp",
+    ],
+
+    include_dirs: [
+        "bionic/libc",
+        "external/tinyxml2",
+    ],
+
+    static_libs: ["libbase"],
+    host_ldlibs: ["-lrt"],
+}
+
+// -----------------------------------------------------------------------------
+// Fortify tests.
+// -----------------------------------------------------------------------------
+
+cc_defaults {
+    name: "bionic_fortify_tests_defaults",
+    cflags: [
+        "-Wno-error",
+        "-U_FORTIFY_SOURCE",
+    ],
+    srcs: ["fortify_test_main.cpp"],
+    target: {
+        host: {
+            clang_cflags: ["-D__clang__"],
+        },
+    },
+}
+
+cc_test_library {
+    name: "libfortify1-tests-gcc",
+    defaults: ["bionic_fortify_tests_defaults", "bionic_tests_defaults"],
+    clang: false,
+    cflags: [
+        "-D_FORTIFY_SOURCE=1",
+        "-DTEST_NAME=Fortify1_gcc"
+    ],
+}
+
+cc_test_library {
+    name: "libfortify2-tests-gcc",
+    defaults: ["bionic_fortify_tests_defaults", "bionic_tests_defaults"],
+    clang: false,
+    cflags: [
+        "-D_FORTIFY_SOURCE=2",
+        "-DTEST_NAME=Fortify2_gcc"
+    ],
+}
+
+cc_test_library {
+    name: "libfortify1-tests-clang",
+    defaults: ["bionic_fortify_tests_defaults", "bionic_tests_defaults"],
+    clang: true,
+    cflags: [
+        "-D_FORTIFY_SOURCE=1",
+        "-DTEST_NAME=Fortify1_clang"
+    ],
+}
+
+cc_test_library {
+    name: "libfortify2-tests-clang",
+    defaults: ["bionic_fortify_tests_defaults", "bionic_tests_defaults"],
+    clang: true,
+    cflags: [
+        "-D_FORTIFY_SOURCE=2",
+        "-DTEST_NAME=Fortify2_clang"
+    ],
+}
+
+// -----------------------------------------------------------------------------
+// Library of all tests (excluding the dynamic linker tests).
+// -----------------------------------------------------------------------------
+cc_test_library {
+    name: "libBionicTests",
+    defaults: ["bionic_tests_defaults"],
+    whole_static_libs: [
+        "libBionicStandardTests",
+        "libfortify1-tests-gcc",
+        "libfortify2-tests-gcc",
+        "libfortify1-tests-clang",
+        "libfortify2-tests-clang",
+    ],
+}
+
+// -----------------------------------------------------------------------------
+// Library of bionic customized gtest main function, with simplified output format.
+// -----------------------------------------------------------------------------
+cc_test_library {
+    name: "libBionicGtestMain",
+    defaults: ["bionic_tests_defaults"],
+    srcs: ["gtest_main.cpp"],
+    target: {
+        darwin: {
+            enabled: true,
+        },
+    },
+}
+
+// -----------------------------------------------------------------------------
+// Library of bionic customized gtest main function, with normal gtest output format,
+// which is needed by bionic cts test.
+// -----------------------------------------------------------------------------
+cc_test_library {
+    name: "libBionicCtsGtestMain",
+    defaults: ["bionic_tests_defaults"],
+    srcs: ["gtest_main.cpp"],
+    cppflags: ["-DUSING_GTEST_OUTPUT_FORMAT"],
+}
+
+// -----------------------------------------------------------------------------
+// Tests for the device using bionic's .so. Run with:
+//   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests32
+//   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests64
+//   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests-gcc32
+//   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests-gcc64
+// -----------------------------------------------------------------------------
+cc_defaults {
+    name: "bionic_unit_tests_defaults",
+    host_supported: false,
+
+    whole_static_libs: [
+        "libBionicTests",
+        "libBionicGtestMain",
+    ],
+
+    static_libs: [
+        "libtinyxml2",
+        "liblog",
+        "libbase",
+    ],
+
+    srcs: [
+        // TODO: Include __cxa_thread_atexit_test.cpp to glibc tests once it is upgraded (glibc 2.18+)
+        "atexit_test.cpp",
+        "dl_test.cpp",
+        "dlext_test.cpp",
+        "__cxa_thread_atexit_test.cpp",
+        "dlfcn_test.cpp",
+        "libdl_test.cpp",
+        "pthread_dlfcn_test.cpp",
+        "thread_local_test.cpp",
+    ],
+
+    conlyflags: [
+        "-fexceptions",
+        "-fnon-call-exceptions",
+    ],
+
+    ldflags: ["-Wl,--export-dynamic"],
+
+    include_dirs: ["bionic/libc"],
+
+    target: {
+        android: {
+            shared_libs: [
+                "libdl",
+                "libpagemap",
+                "libdl_preempt_test_1",
+                "libdl_preempt_test_2",
+                "libdl_test_df_1_global",
+            ],
+            static_libs: [
+                // The order of these libraries matters, do not shuffle them.
+                "libbase",
+                "libziparchive",
+                "libz",
+                "libutils",
+            ],
+        },
+    }
+}
+
+cc_test {
+    name: "bionic-unit-tests",
+    defaults: ["bionic_unit_tests_defaults", "bionic_tests_defaults"],
+    clang: true,
+}
+
+cc_test {
+    name: "bionic-unit-tests-gcc",
+    defaults: ["bionic_unit_tests_defaults", "bionic_tests_defaults"],
+    clang: false,
+}
+
+// -----------------------------------------------------------------------------
+// Tests for the device linked against bionic's static library. Run with:
+//   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static32
+//   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static64
+// -----------------------------------------------------------------------------
+cc_test {
+    name: "bionic-unit-tests-static",
+    defaults: ["bionic_tests_defaults"],
+    host_supported: false,
+
+    whole_static_libs: [
+        "libBionicTests",
+        "libBionicGtestMain",
+    ],
+
+    static_libs: [
+        "libm",
+        "libc",
+        "libc++_static",
+        "libdl",
+        "libtinyxml2",
+        "liblog",
+        "libbase",
+    ],
+
+    static_executable: true,
+    stl: "libc++_static",
+
+    // libc and libc++ both define std::nothrow. libc's is a private symbol, but this
+    // still causes issues when linking libc.a and libc++.a, since private isn't
+    // effective until it has been linked. To fix this, just allow multiple symbol
+    // definitions for the static tests.
+    ldflags: ["-Wl,--allow-multiple-definition"],
+}
+
+// -----------------------------------------------------------------------------
+// Tests to run on the host and linked against glibc. Run with:
+//   cd bionic/tests; mm bionic-unit-tests-glibc-run
+// -----------------------------------------------------------------------------
+
+cc_test_host {
+    name: "bionic-unit-tests-glibc",
+    defaults: ["bionic_tests_defaults"],
+
+    srcs: [
+        "atexit_test.cpp",
+        "dlfcn_test.cpp",
+        "dl_test.cpp",
+        "pthread_dlfcn_test.cpp",
+    ],
+
+    shared_libs: [
+        "libdl_preempt_test_1",
+        "libdl_preempt_test_2",
+
+        "libdl_test_df_1_global",
+    ],
+
+    whole_static_libs: [
+        "libBionicStandardTests",
+        "libBionicGtestMain",
+        "libfortify1-tests-gcc",
+        "libfortify2-tests-gcc",
+        "libfortify1-tests-clang",
+        "libfortify2-tests-clang",
+    ],
+
+    static_libs: [
+        "libbase",
+        "liblog",
+        "libcutils",
+    ],
+
+    host_ldlibs: [
+        "-lresolv",
+        "-lrt",
+        "-ldl",
+        "-lutil",
+    ],
+
+    include_dirs: ["bionic/libc"],
+
+    ldflags: ["-Wl,--export-dynamic"],
+
+    sanitize: {
+        never: false,
+    },
+}
+
+subdirs = ["libs"]
diff --git a/tests/Android.mk b/tests/Android.mk
index 956b76f..0da3b88 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -16,423 +16,14 @@
 
 LOCAL_PATH := $(call my-dir)
 
-# -----------------------------------------------------------------------------
-# Unit tests.
-# -----------------------------------------------------------------------------
-
 ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
 build_host := true
 else
 build_host := false
 endif
 
-common_additional_dependencies := $(LOCAL_PATH)/Android.mk $(LOCAL_PATH)/Android.build.mk
-
-# -----------------------------------------------------------------------------
-# All standard tests.
-# -----------------------------------------------------------------------------
-test_cflags = \
-    -fstack-protector-all \
-    -g \
-    -Wall -Wextra -Wunused \
-    -Werror \
-    -fno-builtin \
-
-test_cflags += -D__STDC_LIMIT_MACROS  # For glibc.
-
-test_cppflags := \
-
-libBionicStandardTests_src_files := \
-    arpa_inet_test.cpp \
-    buffer_tests.cpp \
-    bug_26110743_test.cpp \
-    complex_test.cpp \
-    ctype_test.cpp \
-    dirent_test.cpp \
-    error_test.cpp \
-    eventfd_test.cpp \
-    fcntl_test.cpp \
-    fenv_test.cpp \
-    ftw_test.cpp \
-    getauxval_test.cpp \
-    getcwd_test.cpp \
-    ifaddrs_test.cpp \
-    inttypes_test.cpp \
-    libc_logging_test.cpp \
-    libgen_basename_test.cpp \
-    libgen_test.cpp \
-    locale_test.cpp \
-    malloc_test.cpp \
-    math_test.cpp \
-    mntent_test.cpp \
-    netdb_test.cpp \
-    net_if_test.cpp \
-    netinet_in_test.cpp \
-    netinet_udp_test.cpp \
-    pthread_test.cpp \
-    pty_test.cpp \
-    regex_test.cpp \
-    sched_test.cpp \
-    search_test.cpp \
-    semaphore_test.cpp \
-    setjmp_test.cpp \
-    signal_test.cpp \
-    stack_protector_test.cpp \
-    stack_protector_test_helper.cpp \
-    stack_unwinding_test.cpp \
-    stdatomic_test.cpp \
-    stdint_test.cpp \
-    stdio_nofortify_test.cpp \
-    stdio_test.cpp \
-    stdio_ext_test.cpp \
-    stdlib_test.cpp \
-    string_nofortify_test.cpp \
-    string_test.cpp \
-    string_posix_strerror_r_test.cpp \
-    strings_nofortify_test.cpp \
-    strings_test.cpp \
-    stubs_test.cpp \
-    sstream_test.cpp \
-    sys_epoll_test.cpp \
-    sys_mman_test.cpp \
-    sys_personality_test.cpp \
-    sys_prctl_test.cpp \
-    sys_procfs_test.cpp \
-    sys_resource_test.cpp \
-    sys_select_test.cpp \
-    sys_sendfile_test.cpp \
-    sys_socket_test.cpp \
-    sys_stat_test.cpp \
-    sys_statvfs_test.cpp \
-    sys_syscall_test.cpp \
-    sys_sysinfo_test.cpp \
-    sys_sysmacros_test.cpp \
-    sys_time_test.cpp \
-    sys_timex_test.cpp \
-    sys_types_test.cpp \
-    sys_uio_test.cpp \
-    sys_vfs_test.cpp \
-    sys_xattr_test.cpp \
-    system_properties_test.cpp \
-    time_test.cpp \
-    uchar_test.cpp \
-    uniqueptr_test.cpp \
-    unistd_nofortify_test.cpp \
-    unistd_test.cpp \
-    utmp_test.cpp \
-    wchar_test.cpp \
-
-libBionicStandardTests_cflags := \
-    $(test_cflags) \
-
-libBionicStandardTests_cppflags := \
-    $(test_cppflags) \
-
-libBionicStandardTests_c_includes := \
-    bionic/libc \
-    external/tinyxml2 \
-
-libBionicStandardTests_static_libraries := \
-    libbase \
-
-libBionicStandardTests_ldlibs_host := \
-    -lrt \
-
-# Clang/llvm has incompatible long double (fp128) for x86_64.
-# https://llvm.org/bugs/show_bug.cgi?id=23897
-# This affects most of math_test.cpp.
-ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86_64))
-libBionicStandardTests_clang_target := false
-endif
-
-module := libBionicStandardTests
-module_tag := optional
-build_type := target
-build_target := STATIC_TEST_LIBRARY
-include $(LOCAL_PATH)/Android.build.mk
-build_type := host
-include $(LOCAL_PATH)/Android.build.mk
-
-# -----------------------------------------------------------------------------
-# Fortify tests.
-# -----------------------------------------------------------------------------
-$(foreach compiler,gcc clang, \
-  $(foreach test,1 2, \
-    $(eval fortify$(test)-tests-$(compiler)_cflags := \
-      $(test_cflags) \
-      -Wno-error \
-      -U_FORTIFY_SOURCE \
-      -D_FORTIFY_SOURCE=$(test) \
-      -DTEST_NAME=Fortify$(test)_$(compiler)); \
-    $(eval fortify$(test)-tests-$(compiler)_src_files := \
-      fortify_test_main.cpp); \
-    $(eval fortify_libs += fortify$(test)-tests-$(compiler)); \
-  ) \
-)
-
-fortify1-tests-gcc_clang_target := false
-module := fortify1-tests-gcc
-module_tag := optional
-build_type := target
-build_target := STATIC_TEST_LIBRARY
-include $(LOCAL_PATH)/Android.build.mk
-build_type := host
-include $(LOCAL_PATH)/Android.build.mk
-
-fortify2-tests-gcc_clang_target := false
-module := fortify2-tests-gcc
-module_tag := optional
-build_type := target
-build_target := STATIC_TEST_LIBRARY
-include $(LOCAL_PATH)/Android.build.mk
-build_type := host
-include $(LOCAL_PATH)/Android.build.mk
-
-fortify1-tests-clang_clang_target := true
-fortify1-tests-clang_cflags_host := -D__clang__
-
-module := fortify1-tests-clang
-module_tag := optional
-build_type := target
-build_target := STATIC_TEST_LIBRARY
-include $(LOCAL_PATH)/Android.build.mk
-build_type := host
-include $(LOCAL_PATH)/Android.build.mk
-
-fortify2-tests-clang_clang_target := true
-
-fortify2-tests-clang_cflags_host := -D__clang__
-
-module := fortify2-tests-clang
-module_tag := optional
-build_type := target
-build_target := STATIC_TEST_LIBRARY
-include $(LOCAL_PATH)/Android.build.mk
-build_type := host
-include $(LOCAL_PATH)/Android.build.mk
-
-# -----------------------------------------------------------------------------
-# Library of all tests (excluding the dynamic linker tests).
-# -----------------------------------------------------------------------------
-libBionicTests_whole_static_libraries := \
-    libBionicStandardTests \
-    $(fortify_libs) \
-
-module := libBionicTests
-module_tag := optional
-build_type := target
-build_target := STATIC_TEST_LIBRARY
-include $(LOCAL_PATH)/Android.build.mk
-build_type := host
-include $(LOCAL_PATH)/Android.build.mk
-
-# -----------------------------------------------------------------------------
-# Library of bionic customized gtest main function, with simplified output format.
-# -----------------------------------------------------------------------------
-libBionicGtestMain_src_files := gtest_main.cpp
-
-libBionicGtestMain_cflags := $(test_cflags)
-
-libBionicGtestMain_cppflags := $(test_cppflags)
-
-module := libBionicGtestMain
-module_tag := optional
-build_type := target
-build_target := STATIC_TEST_LIBRARY
-include $(LOCAL_PATH)/Android.build.mk
-build_type := host
-
-ifeq ($(HOST_OS),$(filter $(HOST_OS),linux darwin))
-saved_build_host := $(build_host)
-build_host := true
-include $(LOCAL_PATH)/Android.build.mk
-build_host := $(saved_build_host)
-endif
-
-# -----------------------------------------------------------------------------
-# Library of bionic customized gtest main function, with normal gtest output format,
-# which is needed by bionic cts test.
-# -----------------------------------------------------------------------------
-libBionicCtsGtestMain_src_files := gtest_main.cpp
-
-libBionicCtsGtestMain_cflags := $(test_cflags)
-
-libBionicCtsGtestMain_cppflags := $(test_cppflags) -DUSING_GTEST_OUTPUT_FORMAT \
-
-module := libBionicCtsGtestMain
-module_tag := optional
-build_type := target
-build_target := STATIC_TEST_LIBRARY
-include $(LOCAL_PATH)/Android.build.mk
-build_type := host
-include $(LOCAL_PATH)/Android.build.mk
-
-# -----------------------------------------------------------------------------
-# Tests for the device using bionic's .so. Run with:
-#   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests32
-#   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests64
-#   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests-gcc32
-#   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests-gcc64
-# -----------------------------------------------------------------------------
-common_bionic-unit-tests_whole_static_libraries := \
-    libBionicTests \
-    libBionicGtestMain \
-
-common_bionic-unit-tests_static_libraries := \
-    libtinyxml2 \
-    liblog \
-    libbase \
-
-# TODO: Include __cxa_thread_atexit_test.cpp to glibc tests once it is upgraded (glibc 2.18+)
-common_bionic-unit-tests_src_files := \
-    atexit_test.cpp \
-    dl_test.cpp \
-    dlext_test.cpp \
-    __cxa_thread_atexit_test.cpp \
-    dlfcn_test.cpp \
-    libdl_test.cpp \
-    pthread_dlfcn_test.cpp \
-    thread_local_test.cpp \
-
-common_bionic-unit-tests_cflags := $(test_cflags)
-
-common_bionic-unit-tests_conlyflags := \
-    -fexceptions \
-    -fnon-call-exceptions \
-
-common_bionic-unit-tests_cppflags := $(test_cppflags)
-
-common_bionic-unit-tests_ldflags := \
-    -Wl,--export-dynamic
-
-common_bionic-unit-tests_c_includes := \
-    bionic/libc \
-
-common_bionic-unit-tests_shared_libraries_target := \
-    libdl \
-    libpagemap \
-    libdl_preempt_test_1 \
-    libdl_preempt_test_2 \
-    libdl_test_df_1_global \
-
-# The order of these libraries matters, do not shuffle them.
-common_bionic-unit-tests_static_libraries_target := \
-    libbase \
-    libziparchive \
-    libz \
-    libutils \
-
-module_tag := optional
-build_type := target
-build_target := NATIVE_TEST
-
-module := bionic-unit-tests
-bionic-unit-tests_clang_target := true
-bionic-unit-tests_whole_static_libraries := $(common_bionic-unit-tests_whole_static_libraries)
-bionic-unit-tests_static_libraries := $(common_bionic-unit-tests_static_libraries)
-bionic-unit-tests_src_files := $(common_bionic-unit-tests_src_files)
-bionic-unit-tests_cflags := $(common_bionic-unit-tests_cflags)
-bionic-unit-tests_conlyflags := $(common_bionic-unit-tests_conlyflags)
-bionic-unit-tests_cppflags := $(common_bionic-unit-tests_cppflags)
-bionic-unit-tests_ldflags := $(common_bionic-unit-tests_ldflags)
-bionic-unit-tests_c_includes := $(common_bionic-unit-tests_c_includes)
-bionic-unit-tests_shared_libraries_target := $(common_bionic-unit-tests_shared_libraries_target)
-bionic-unit-tests_static_libraries_target := $(common_bionic-unit-tests_static_libraries_target)
-include $(LOCAL_PATH)/Android.build.mk
-
-module := bionic-unit-tests-gcc
-bionic-unit-tests-gcc_clang_target := false
-bionic-unit-tests-gcc_whole_static_libraries := $(common_bionic-unit-tests_whole_static_libraries)
-bionic-unit-tests-gcc_static_libraries := $(common_bionic-unit-tests_static_libraries)
-bionic-unit-tests-gcc_src_files := $(common_bionic-unit-tests_src_files)
-bionic-unit-tests-gcc_cflags := $(common_bionic-unit-tests_cflags)
-bionic-unit-tests-gcc_conlyflags := $(common_bionic-unit-tests_conlyflags)
-bionic-unit-tests-gcc_cppflags := $(common_bionic-unit-tests_cppflags)
-bionic-unit-tests-gcc_ldflags := $(common_bionic-unit-tests_ldflags)
-bionic-unit-tests-gcc_c_includes := $(common_bionic-unit-tests_c_includes)
-bionic-unit-tests-gcc_shared_libraries_target := $(common_bionic-unit-tests_shared_libraries_target)
-bionic-unit-tests-gcc_static_libraries_target := $(common_bionic-unit-tests_static_libraries_target)
-include $(LOCAL_PATH)/Android.build.mk
-
-# -----------------------------------------------------------------------------
-# Tests for the device linked against bionic's static library. Run with:
-#   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static32
-#   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static64
-# -----------------------------------------------------------------------------
-bionic-unit-tests-static_whole_static_libraries := \
-    libBionicTests \
-    libBionicGtestMain \
-
-bionic-unit-tests-static_static_libraries := \
-    libm \
-    libc \
-    libc++_static \
-    libdl \
-    libtinyxml2 \
-    liblog \
-    libbase \
-
-bionic-unit-tests-static_force_static_executable := true
-
-# libc and libc++ both define std::nothrow. libc's is a private symbol, but this
-# still causes issues when linking libc.a and libc++.a, since private isn't
-# effective until it has been linked. To fix this, just allow multiple symbol
-# definitions for the static tests.
-bionic-unit-tests-static_ldflags := -Wl,--allow-multiple-definition
-
-module := bionic-unit-tests-static
-module_tag := optional
-build_type := target
-build_target := NATIVE_TEST
-include $(LOCAL_PATH)/Android.build.mk
-
-# -----------------------------------------------------------------------------
-# Tests to run on the host and linked against glibc. Run with:
-#   cd bionic/tests; mm bionic-unit-tests-glibc-run
-# -----------------------------------------------------------------------------
-
 ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
 
-bionic-unit-tests-glibc_src_files := \
-    atexit_test.cpp \
-    dlfcn_test.cpp \
-    dl_test.cpp \
-    pthread_dlfcn_test.cpp \
-
-bionic-unit-tests-glibc_shared_libraries := \
-    libdl_preempt_test_1 \
-    libdl_preempt_test_2
-
-bionic-unit-tests-glibc_shared_libraries += libdl_test_df_1_global
-
-bionic-unit-tests-glibc_whole_static_libraries := \
-    libBionicStandardTests \
-    libBionicGtestMain \
-    $(fortify_libs) \
-
-bionic-unit-tests-glibc_static_libraries := \
-    libbase \
-    liblog \
-    libcutils \
-
-bionic-unit-tests-glibc_ldlibs := \
-    -lrt -ldl -lutil \
-
-bionic-unit-tests-glibc_c_includes := \
-    bionic/libc \
-
-bionic-unit-tests-glibc_cflags := $(test_cflags)
-bionic-unit-tests-glibc_cppflags := $(test_cppflags)
-bionic-unit-tests-glibc_ldflags := -Wl,--export-dynamic
-
-bionic-unit-tests-glibc_allow_asan := true
-
-module := bionic-unit-tests-glibc
-module_tag := optional
-build_type := host
-build_target := NATIVE_TEST
-include $(LOCAL_PATH)/Android.build.mk
-
 # -----------------------------------------------------------------------------
 # Compile time tests.
 # -----------------------------------------------------------------------------
@@ -480,52 +71,6 @@
 LOCAL_SRC_FILES :=
 include $(BUILD_STATIC_LIBRARY)
 
-# -----------------------------------------------------------------------------
-# Host glibc tests.
-# -----------------------------------------------------------------------------
-
-# gtest needs ANDROID_DATA/local/tmp for death test output.
-# Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
-# Use the current target out directory as ANDROID_DATA.
-# BIONIC_TEST_FLAGS is either empty or it comes from the user.
-.PHONY: bionic-unit-tests-glibc-run
-bionic-unit-tests-glibc-run: bionic-unit-tests-glibc
-	mkdir -p $(TARGET_OUT_DATA)/local/tmp
-	ANDROID_DATA=$(TARGET_OUT_DATA) \
-	ANDROID_ROOT=$(TARGET_OUT) \
-		$(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc64 $(BIONIC_TEST_FLAGS)
-
-# -----------------------------------------------------------------------------
-# Run the unit tests built against x86 bionic on an x86 host.
-# -----------------------------------------------------------------------------
-
-include $(LOCAL_PATH)/../build/run-on-host.mk
-
-ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
-
-TEST_TIMEOUT := 0
-
-# BIONIC_TEST_FLAGS is either empty or it comes from the user.
-.PHONY: bionic-unit-tests-run-on-host32
-bionic-unit-tests-run-on-host32: bionic-unit-tests bionic-prepare-run-on-host
-	ANDROID_DATA=$(TARGET_OUT_DATA) \
-	ANDROID_DNS_MODE=local \
-	ANDROID_ROOT=$(TARGET_OUT) \
-		timeout $(TEST_TIMEOUT) \
-		$(TARGET_OUT_DATA)/nativetest/bionic-unit-tests/bionic-unit-tests32 $(BIONIC_TEST_FLAGS)
-
-ifeq ($(TARGET_IS_64_BIT),true)
-# add target to run lp64 tests
-.PHONY: bionic-unit-tests-run-on-host64
-bionic-unit-tests-run-on-host64: bionic-unit-tests bionic-prepare-run-on-host
-	ANDROID_DATA=$(TARGET_OUT_DATA) \
-	ANDROID_DNS_MODE=local \
-	ANDROID_ROOT=$(TARGET_OUT) \
-		timeout $(TEST_TIMEOUT) \
-		$(TARGET_OUT_DATA)/nativetest64/bionic-unit-tests/bionic-unit-tests64 $(BIONIC_TEST_FLAGS)
-endif
-
-endif # x86 x86_64
 endif # linux-x86
 
 include $(call first-makefiles-under,$(LOCAL_PATH))
diff --git a/tests/ScopedSignalHandler.h b/tests/ScopedSignalHandler.h
index 3fb60a1..8998d0d 100644
--- a/tests/ScopedSignalHandler.h
+++ b/tests/ScopedSignalHandler.h
@@ -39,6 +39,10 @@
     sigaction(signal_number_, &action_, &old_action_);
   }
 
+  ScopedSignalHandler(int signal_number) : signal_number_(signal_number) {
+    sigaction(signal_number, nullptr, &old_action_);
+  }
+
   ~ScopedSignalHandler() {
     sigaction(signal_number_, &old_action_, NULL);
   }
@@ -49,4 +53,18 @@
   const int signal_number_;
 };
 
+class ScopedSignalMask {
+ public:
+  ScopedSignalMask() {
+    sigprocmask(SIG_SETMASK, nullptr, &old_mask_);
+  }
+
+  ~ScopedSignalMask() {
+    sigprocmask(SIG_SETMASK, &old_mask_, nullptr);
+  }
+
+ private:
+  sigset_t old_mask_;
+};
+
 #endif // _BIONIC_TESTS_SCOPED_SIGNAL_HANDLER_H
diff --git a/tests/__cxa_thread_atexit_test.cpp b/tests/__cxa_thread_atexit_test.cpp
index 1432968..e388f3b 100644
--- a/tests/__cxa_thread_atexit_test.cpp
+++ b/tests/__cxa_thread_atexit_test.cpp
@@ -35,12 +35,7 @@
   std::string message;
 };
 
-#if defined(__clang__) && defined(__aarch64__)
-// b/25642296, aarch64 clang compiled "thread_local" does not link.
-static ClassWithDtor class_with_dtor;
-#else
 static thread_local ClassWithDtor class_with_dtor;
-#endif
 
 static void* thread_nop(void* arg) {
   class_with_dtor.set_message(*static_cast<std::string*>(arg));
@@ -52,12 +47,7 @@
   pthread_t t;
   ASSERT_EQ(0, pthread_create(&t, nullptr, thread_nop, &msg));
   ASSERT_EQ(0, pthread_join(t, nullptr));
-#if defined(__clang__) && defined(__aarch64__)
-  GTEST_LOG_(INFO) << "Skipping test, b/25642296, "
-                   << "thread_local does not work with aarch64 clang/llvm.\n";
-#else
   ASSERT_EQ("dtor called.", class_with_dtor_output);
-#endif
 }
 
 class ClassWithDtorForMainThread {
@@ -74,13 +64,7 @@
 };
 
 static void thread_atexit_main() {
-#if defined(__clang__) && defined(__aarch64__)
-  static ClassWithDtorForMainThread class_with_dtor_for_main_thread;
-  GTEST_LOG_(INFO) << "Skipping test, b/25642296, "
-                   << "thread_local does not work with aarch64 clang/llvm.\n";
-#else
   static thread_local ClassWithDtorForMainThread class_with_dtor_for_main_thread;
-#endif
   class_with_dtor_for_main_thread.set_message("d-tor for main thread called.");
   exit(0);
 }
diff --git a/tests/assert_test.cpp b/tests/assert_test.cpp
new file mode 100644
index 0000000..9436151
--- /dev/null
+++ b/tests/assert_test.cpp
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+
+#include <gtest/gtest.h>
+
+#undef NDEBUG
+#include <assert.h>
+
+TEST(assert, assert_true) {
+  assert(true);
+}
+
+TEST(assert, assert_false) {
+  EXPECT_DEATH(assert(false),
+               "bionic/tests/assert_test.cpp:.*: "
+               "virtual void assert_assert_false_Test::TestBody\\(\\): "
+               "assertion \"false\" failed");
+}
+
+// Re-include <assert.h> with assertions disabled.
+#define NDEBUG
+#include <assert.h>
+
+TEST(assert, assert_true_NDEBUG) {
+  assert(true);
+}
+
+TEST(assert, assert_false_NDEBUG) {
+  assert(false);
+}
diff --git a/tests/complex_test.cpp b/tests/complex_test.cpp
index 47964f6..a8f6777 100644
--- a/tests/complex_test.cpp
+++ b/tests/complex_test.cpp
@@ -16,245 +16,305 @@
 
 #include <gtest/gtest.h>
 
+// This file is compiled against both glibc and bionic, and our complex.h
+// depends on bionic-specific macros, so hack around that.
+#include <sys/cdefs.h>
+#if !defined(__INTRODUCED_IN)
+#define __INTRODUCED_IN(x)
+#define __INTRODUCED_IN_32(x)
+#define __INTRODUCED_IN_64(x)
+#define __INTRODUCED_IN_FUTURE
+#endif
+
 // libc++ actively gets in the way of including <complex.h> from C++, so we
-// have to declare the complex math functions ourselves.
+// have to be naughty.
+#include <../libc/include/complex.h>
+
 // (libc++ also seems to have really bad implementations of its own that ignore
 // the intricacies of floating point math.)
 // http://llvm.org/bugs/show_bug.cgi?id=21504
 
-#include <math.h> // For M_PI.
+#include <math.h> // For M_PI_2/M_PI_2l.
 
-extern "C" double cabs(double _Complex);
+// Note that gtest doesn't support complex numbers, so the output from
+// assertion failures is misleading/useless (at best you'll only see the real
+// part).
+// TODO: find out why gtest doesn't use these; until then they're only useful
+// for manual printf^Woperator<< debugging.
+#include <iostream>
+std::ostream& operator<<(std::ostream& os, const double _Complex c) {
+  os << "(" << creal(c) << "," << cimag(c) << "i)";
+ return os;
+}
+std::ostream& operator<<(std::ostream& os, const float _Complex c) {
+  os << "(" << crealf(c) << "," << cimagf(c) << "i)";
+  return os;
+}
+std::ostream& operator<<(std::ostream& os, const long double _Complex c) {
+  os << "(" << creall(c) << "," << cimagl(c) << "i)";
+  return os;
+}
+
 TEST(complex, cabs) {
   ASSERT_EQ(0.0, cabs(0));
 }
 
-extern "C" float cabsf(float _Complex);
 TEST(complex, cabsf) {
   ASSERT_EQ(0.0, cabsf(0));
 }
 
-extern "C" long double cabsl(long double _Complex);
 TEST(complex, cabsl) {
   ASSERT_EQ(0.0, cabsl(0));
 }
 
-extern "C" double _Complex cacos(double _Complex);
 TEST(complex, cacos) {
-  ASSERT_EQ(M_PI/2.0, cacos(0.0));
+  ASSERT_EQ(M_PI_2, cacos(0.0));
 }
 
-extern "C" float _Complex cacosf(float _Complex);
 TEST(complex, cacosf) {
-  ASSERT_EQ(static_cast<float>(M_PI)/2.0f, cacosf(0.0));
+  ASSERT_EQ(static_cast<float>(M_PI_2), cacosf(0.0));
 }
 
-extern "C" double _Complex cacosh(double _Complex);
+TEST(complex, cacosl) {
+  ASSERT_EQ(M_PI_2l, cacosl(0.0));
+}
+
 TEST(complex, cacosh) {
   ASSERT_EQ(0.0, cacosh(1.0));
 }
 
-extern "C" float _Complex cacoshf(float _Complex);
+TEST(complex, cacoshl) {
+  ASSERT_EQ(0.0, cacoshl(1.0));
+}
+
 TEST(complex, cacoshf) {
   ASSERT_EQ(0.0, cacoshf(1.0));
 }
 
-extern "C" double carg(double _Complex);
 TEST(complex, carg) {
   ASSERT_EQ(0.0, carg(0));
 }
 
-extern "C" float cargf(float _Complex);
 TEST(complex, cargf) {
   ASSERT_EQ(0.0, cargf(0));
 }
 
-extern "C" long double cargl(long double _Complex);
 TEST(complex, cargl) {
   ASSERT_EQ(0.0, cargl(0));
 }
 
-extern "C" double _Complex casin(double _Complex);
 TEST(complex, casin) {
   ASSERT_EQ(0.0, casin(0));
 }
 
-extern "C" float _Complex casinf(float _Complex);
 TEST(complex, casinf) {
   ASSERT_EQ(0.0, casinf(0));
 }
 
-extern "C" double _Complex casinh(double _Complex);
+TEST(complex, casinl) {
+  ASSERT_EQ(0.0, casinl(0));
+}
+
 TEST(complex, casinh) {
   ASSERT_EQ(0.0, casinh(0));
 }
 
-extern "C" float _Complex casinhf(float _Complex);
 TEST(complex, casinhf) {
   ASSERT_EQ(0.0, casinhf(0));
 }
 
-extern "C" double _Complex catan(double _Complex);
+TEST(complex, casinhl) {
+  ASSERT_EQ(0.0, casinhl(0));
+}
+
 TEST(complex, catan) {
   ASSERT_EQ(0.0, catan(0));
 }
 
-extern "C" float _Complex catanf(float _Complex);
 TEST(complex, catanf) {
   ASSERT_EQ(0.0, catanf(0));
 }
 
-extern "C" double _Complex catanh(double _Complex);
+TEST(complex, catanl) {
+  ASSERT_EQ(0.0, catanl(0));
+}
+
 TEST(complex, catanh) {
   ASSERT_EQ(0.0, catanh(0));
 }
 
-extern "C" float _Complex catanhf(float _Complex);
 TEST(complex, catanhf) {
   ASSERT_EQ(0.0, catanhf(0));
 }
 
-extern "C" double _Complex ccos(double _Complex);
+TEST(complex, catanhl) {
+  ASSERT_EQ(0.0, catanhl(0));
+}
+
 TEST(complex, ccos) {
   ASSERT_EQ(1.0, ccos(0));
 }
 
-extern "C" float _Complex ccosf(float _Complex);
 TEST(complex, ccosf) {
   ASSERT_EQ(1.0, ccosf(0));
 }
 
-extern "C" double _Complex ccosh(double _Complex);
+TEST(complex, ccosl) {
+  ASSERT_EQ(1.0, ccosl(0));
+}
+
 TEST(complex, ccosh) {
   ASSERT_EQ(1.0, ccosh(0));
 }
 
-extern "C" float _Complex ccoshf(float _Complex);
 TEST(complex, ccoshf) {
   ASSERT_EQ(1.0, ccoshf(0));
 }
 
-extern "C" double _Complex cexp(double _Complex);
+TEST(complex, ccoshl) {
+  ASSERT_EQ(1.0, ccoshl(0));
+}
+
 TEST(complex, cexp) {
   ASSERT_EQ(1.0, cexp(0));
 }
 
-extern "C" float _Complex cexpf(float _Complex);
 TEST(complex, cexpf) {
   ASSERT_EQ(1.0, cexpf(0));
 }
 
-extern "C" double cimag(double _Complex);
+TEST(complex, cexpl) {
+  ASSERT_EQ(1.0, cexpl(0));
+}
+
 TEST(complex, cimag) {
   ASSERT_EQ(0.0, cimag(0));
 }
 
-extern "C" float cimagf(float _Complex);
 TEST(complex, cimagf) {
   ASSERT_EQ(0.0f, cimagf(0));
 }
 
-extern "C" long double cimagl(long double _Complex);
 TEST(complex, cimagl) {
   ASSERT_EQ(0.0, cimagl(0));
 }
 
-extern "C" double _Complex conj(double _Complex);
+TEST(complex, clog) {
+  ASSERT_EQ(0.0, clog(1.0));
+}
+
+TEST(complex, clogf) {
+  ASSERT_EQ(0.0f, clogf(1.0f));
+}
+
+TEST(complex, clogl) {
+  ASSERT_EQ(0.0L, clogl(1.0L));
+}
+
 TEST(complex, conj) {
   ASSERT_EQ(0.0, conj(0));
 }
 
-extern "C" float _Complex conjf(float _Complex);
 TEST(complex, conjf) {
   ASSERT_EQ(0.0f, conjf(0));
 }
 
-extern "C" long double _Complex conjl(long double _Complex);
 TEST(complex, conjl) {
   ASSERT_EQ(0.0, conjl(0));
 }
 
-extern "C" double _Complex cproj(double _Complex);
+TEST(complex, cpow) {
+  ASSERT_EQ(8.0, cpow(2.0, 3.0));
+}
+
+TEST(complex, cpowf) {
+  ASSERT_EQ(8.0f, cpowf(2.0f, 3.0f));
+}
+
+TEST(complex, cpowl) {
+  ASSERT_EQ(8.0L, cpowl(2.0L, 3.0L));
+}
+
 TEST(complex, cproj) {
   ASSERT_EQ(0.0, cproj(0));
 }
 
-extern "C" float _Complex cprojf(float _Complex);
 TEST(complex, cprojf) {
   ASSERT_EQ(0.0f, cprojf(0));
 }
 
-extern "C" long double _Complex cprojl(long double _Complex);
 TEST(complex, cprojl) {
   ASSERT_EQ(0.0, cprojl(0));
 }
 
-extern "C" double creal(double _Complex);
 TEST(complex, creal) {
-  ASSERT_EQ(0.0, creal(0));
+  ASSERT_EQ(2.0, creal(2.0 + 3.0I));
 }
 
-extern "C" float crealf(float _Complex);
 TEST(complex, crealf) {
-  ASSERT_EQ(0.0f, crealf(0));
+  ASSERT_EQ(2.0f, crealf(2.0f + 3.0fI));
 }
 
-extern "C" long double creall(long double _Complex);
 TEST(complex, creall) {
-  ASSERT_EQ(0.0, creall(0));
+  ASSERT_EQ(2.0, creall(2.0L + 3.0LI));
 }
 
-extern "C" double _Complex csin(double _Complex);
 TEST(complex, csin) {
   ASSERT_EQ(0.0, csin(0));
 }
 
-extern "C" float _Complex csinf(float _Complex);
 TEST(complex, csinf) {
   ASSERT_EQ(0.0, csinf(0));
 }
 
-extern "C" double _Complex csinh(double _Complex);
+TEST(complex, csinl) {
+  ASSERT_EQ(0.0, csinl(0));
+}
+
 TEST(complex, csinh) {
   ASSERT_EQ(0.0, csinh(0));
 }
 
-extern "C" float _Complex csinhf(float _Complex);
 TEST(complex, csinhf) {
   ASSERT_EQ(0.0, csinhf(0));
 }
 
-extern "C" double _Complex csqrt(double _Complex);
+TEST(complex, csinhl) {
+  ASSERT_EQ(0.0, csinhl(0));
+}
+
 TEST(complex, csqrt) {
   ASSERT_EQ(0.0, csqrt(0));
 }
 
-extern "C" float _Complex csqrtf(float _Complex);
 TEST(complex, csqrtf) {
   ASSERT_EQ(0.0f, csqrt(0));
 }
 
-extern "C" long double _Complex csqrtl(long double _Complex);
 TEST(complex, csqrtl) {
   ASSERT_EQ(0.0, csqrtl(0));
 }
 
-extern "C" double _Complex ctan(double _Complex);
 TEST(complex, ctan) {
   ASSERT_EQ(0.0, ctan(0));
 }
 
-extern "C" float _Complex ctanf(float _Complex);
 TEST(complex, ctanf) {
   ASSERT_EQ(0.0, ctanf(0));
 }
 
-extern "C" double _Complex ctanh(double _Complex);
+TEST(complex, ctanl) {
+  ASSERT_EQ(0.0, ctanl(0));
+}
+
 TEST(complex, ctanh) {
   ASSERT_EQ(0.0, ctanh(0));
 }
 
-extern "C" float _Complex ctanhf(float _Complex);
 TEST(complex, ctanhf) {
   ASSERT_EQ(0.0, ctanhf(0));
 }
+
+TEST(complex, ctanhl) {
+  ASSERT_EQ(0.0, ctanhl(0));
+}
diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp
index ee61d5f..c3230e7 100644
--- a/tests/dlext_test.cpp
+++ b/tests/dlext_test.cpp
@@ -37,7 +37,7 @@
 #include "dlext_private.h"
 
 #define ASSERT_DL_NOTNULL(ptr) \
-    ASSERT_TRUE(ptr != nullptr) << "dlerror: " << dlerror()
+    ASSERT_TRUE((ptr) != nullptr) << "dlerror: " << dlerror()
 
 #define ASSERT_DL_ZERO(i) \
     ASSERT_EQ(0, i) << "dlerror: " << dlerror()
@@ -52,7 +52,7 @@
 typedef int (*fn)(void);
 #define LIBNAME "libdlext_test.so"
 #define LIBNAME_NORELRO "libdlext_test_norelro.so"
-#define LIBSIZE 1024*1024 // how much address space to reserve for it
+constexpr auto LIBSIZE = 1024 * 1024; // how much address space to reserve for it
 
 #if defined(__LP64__)
 #define NATIVE_TESTS_PATH "/nativetest64"
@@ -628,7 +628,13 @@
 
   ASSERT_FALSE(android_init_namespaces(path.c_str(), nullptr));
   ASSERT_STREQ("android_init_namespaces failed: error initializing public namespace: "
-               "\"libnstest_public.so\" was not found in the default namespace", dlerror());
+               "a library with soname \"libnstest_public.so\" was not found in the "
+               "default namespace",
+               dlerror());
+
+  ASSERT_FALSE(android_init_namespaces("", nullptr));
+  ASSERT_STREQ("android_init_namespaces failed: error initializing public namespace: "
+               "the list of public libraries is empty.", dlerror());
 
   const std::string lib_path = std::string(getenv("ANDROID_DATA")) + NATIVE_TESTS_PATH;
 
diff --git a/tests/dlfcn_test.cpp b/tests/dlfcn_test.cpp
index f842c66..5bf5861 100644
--- a/tests/dlfcn_test.cpp
+++ b/tests/dlfcn_test.cpp
@@ -38,15 +38,24 @@
 }
 
 static int g_ctor_function_called = 0;
+static int g_ctor_argc = 0;
+static char** g_ctor_argv = reinterpret_cast<char**>(0xDEADBEEF);
+static char** g_ctor_envp = g_ctor_envp;
 
-extern "C" void ctor_function() __attribute__ ((constructor));
+extern "C" void ctor_function(int argc, char** argv, char** envp) __attribute__ ((constructor));
 
-extern "C" void ctor_function() {
+extern "C" void ctor_function(int argc, char** argv, char** envp) {
   g_ctor_function_called = 17;
+  g_ctor_argc = argc;
+  g_ctor_argv = argv;
+  g_ctor_envp = envp;
 }
 
 TEST(dlfcn, ctor_function_call) {
   ASSERT_EQ(17, g_ctor_function_called);
+  ASSERT_TRUE(g_ctor_argc = get_argc());
+  ASSERT_TRUE(g_ctor_argv = get_argv());
+  ASSERT_TRUE(g_ctor_envp = get_envp());
 }
 
 TEST(dlfcn, dlsym_in_executable) {
@@ -211,8 +220,8 @@
   dlclose(handle);
 }
 
-// ifuncs are only supported on intel and arm64 for now
-#if defined (__aarch64__) || defined(__i386__) || defined(__x86_64__)
+// mips doesn't support ifuncs
+#if !defined(__mips__)
 TEST(dlfcn, ifunc) {
   typedef const char* (*fn_ptr)();
 
@@ -256,6 +265,21 @@
   ASSERT_STREQ("true", is_ctor_called());
   dlclose(handle);
 }
+
+TEST(dlfcn, ifunc_ctor_call_rtld_lazy) {
+  typedef const char* (*fn_ptr)();
+
+  void* handle = dlopen("libtest_ifunc.so", RTLD_LAZY);
+  ASSERT_TRUE(handle != nullptr) << dlerror();
+  fn_ptr is_ctor_called =  reinterpret_cast<fn_ptr>(dlsym(handle, "is_ctor_called_irelative"));
+  ASSERT_TRUE(is_ctor_called != nullptr) << dlerror();
+  ASSERT_STREQ("false", is_ctor_called());
+
+  is_ctor_called =  reinterpret_cast<fn_ptr>(dlsym(handle, "is_ctor_called_jump_slot"));
+  ASSERT_TRUE(is_ctor_called != nullptr) << dlerror();
+  ASSERT_STREQ("true", is_ctor_called());
+  dlclose(handle);
+}
 #endif
 
 TEST(dlfcn, dlopen_check_relocation_dt_needed_order) {
diff --git a/tests/fcntl_test.cpp b/tests/fcntl_test.cpp
index 3fd0a8c..0798686 100644
--- a/tests/fcntl_test.cpp
+++ b/tests/fcntl_test.cpp
@@ -237,3 +237,26 @@
   ASSERT_STREQ(expected, buf1);
   ASSERT_STREQ(expected, buf2);
 }
+
+TEST(fcntl, readahead) {
+  // Just check that the function is available.
+  errno = 0;
+  ASSERT_EQ(-1, readahead(-1, 0, 123));
+  ASSERT_EQ(EBADF, errno);
+}
+
+TEST(fcntl, sync_file_range) {
+  // Just check that the function is available.
+  errno = 0;
+  ASSERT_EQ(-1, sync_file_range(-1, 0, 0, 0));
+  ASSERT_EQ(EBADF, errno);
+
+  TemporaryFile tf;
+  ASSERT_EQ(0, sync_file_range(tf.fd, 0, 0, 0));
+
+  // The arguments to the underlying system call are in a different order on 32-bit ARM.
+  // Check that the `flags` argument gets passed to the kernel correctly.
+  errno = 0;
+  ASSERT_EQ(-1, sync_file_range(tf.fd, 0, 0, ~0));
+  ASSERT_EQ(EINVAL, errno);
+}
diff --git a/tests/fortify_test.cpp b/tests/fortify_test.cpp
index 4ffd5f9..e1ff769 100644
--- a/tests/fortify_test.cpp
+++ b/tests/fortify_test.cpp
@@ -560,6 +560,12 @@
   ASSERT_FORTIFY(memcpy(bufb, bufa, n));
 }
 
+TEST_F(DEATHTEST, memset_fortified) {
+  char buf[10];
+  size_t n = atoi("11");
+  ASSERT_FORTIFY(memset(buf, 0, n));
+}
+
 TEST_F(DEATHTEST, stpncpy_fortified) {
   char bufa[15];
   char bufb[10];
diff --git a/tests/ftw_test.cpp b/tests/ftw_test.cpp
index b7e5bd5..ea494ba 100644
--- a/tests/ftw_test.cpp
+++ b/tests/ftw_test.cpp
@@ -16,6 +16,7 @@
 
 #include <ftw.h>
 
+#include <pwd.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/stat.h>
@@ -24,6 +25,7 @@
 
 #include "TemporaryFile.h"
 
+#include <android-base/stringprintf.h>
 #include <gtest/gtest.h>
 
 static void MakeTree(const char* root) {
@@ -39,7 +41,7 @@
   snprintf(path, sizeof(path), "%s/dangler", root);
   ASSERT_EQ(0, symlink("/does-not-exist", path));
   snprintf(path, sizeof(path), "%s/symlink", root);
-  ASSERT_EQ(0, symlink("sub2", path));
+  ASSERT_EQ(0, symlink("dir/sub", path));
 
   int fd;
   snprintf(path, sizeof(path), "%s/regular", root);
@@ -51,8 +53,21 @@
   ASSERT_TRUE(fpath != NULL);
   ASSERT_TRUE(sb != NULL);
 
+  // Was it a case where the struct stat we're given is meaningless?
+  if (tflag == FTW_NS || tflag == FTW_SLN) {
+    // If so, double-check that we really can't stat.
+    struct stat sb;
+    EXPECT_EQ(-1, stat(fpath, &sb));
+    return;
+  }
+
+  // Otherwise check that the struct stat matches the type flag.
   if (S_ISDIR(sb->st_mode)) {
-    EXPECT_TRUE(tflag == FTW_D || tflag == FTW_DNR || tflag == FTW_DP) << fpath;
+    if (access(fpath, R_OK) == 0) {
+      EXPECT_TRUE(tflag == FTW_D || tflag == FTW_DP) << fpath << ' ' << tflag;
+    } else {
+      EXPECT_EQ(FTW_DNR, tflag) << fpath;
+    }
   } else if (S_ISLNK(sb->st_mode)) {
     EXPECT_EQ(FTW_SL, tflag) << fpath;
   } else {
@@ -60,7 +75,7 @@
   }
 }
 
-void sanity_check_nftw(const char* fpath, const struct stat* sb, int tflag, struct FTW* ftwbuf) {
+void sanity_check_nftw(const char* fpath, const struct stat* sb, int tflag, FTW* ftwbuf) {
   sanity_check_ftw(fpath, sb, tflag);
   ASSERT_EQ('/', fpath[ftwbuf->base - 1]) << fpath;
 }
@@ -75,12 +90,12 @@
   return 0;
 }
 
-int check_nftw(const char* fpath, const struct stat* sb, int tflag, struct FTW* ftwbuf) {
+int check_nftw(const char* fpath, const struct stat* sb, int tflag, FTW* ftwbuf) {
   sanity_check_nftw(fpath, sb, tflag, ftwbuf);
   return 0;
 }
 
-int check_nftw64(const char* fpath, const struct stat64* sb, int tflag, struct FTW* ftwbuf) {
+int check_nftw64(const char* fpath, const struct stat64* sb, int tflag, FTW* ftwbuf) {
   sanity_check_nftw(fpath, reinterpret_cast<const struct stat*>(sb), tflag, ftwbuf);
   return 0;
 }
@@ -108,3 +123,33 @@
   MakeTree(root.dirname);
   ASSERT_EQ(0, nftw64(root.dirname, check_nftw64, 128, 0));
 }
+
+template <typename StatT>
+static int bug_28197840_ftw(const char* path, const StatT*, int flag) {
+  EXPECT_EQ(strstr(path, "unreadable") != nullptr ? FTW_DNR : FTW_D, flag) << path;
+  return 0;
+}
+
+template <typename StatT>
+static int bug_28197840_nftw(const char* path, const StatT* sb, int flag, FTW*) {
+  return bug_28197840_ftw(path, sb, flag);
+}
+
+TEST(ftw, bug_28197840) {
+  // Drop root for this test, because root can still read directories even if
+  // permissions would imply otherwise.
+  if (getuid() == 0) {
+    passwd* pwd = getpwnam("shell");
+    ASSERT_EQ(0, setuid(pwd->pw_uid));
+  }
+
+  TemporaryDir root;
+
+  std::string path = android::base::StringPrintf("%s/unreadable-directory", root.dirname);
+  ASSERT_EQ(0, mkdir(path.c_str(), 0000)) << path;
+
+  ASSERT_EQ(0, ftw(root.dirname, bug_28197840_ftw<struct stat>, 128));
+  ASSERT_EQ(0, ftw64(root.dirname, bug_28197840_ftw<struct stat64>, 128));
+  ASSERT_EQ(0, nftw(root.dirname, bug_28197840_nftw<struct stat>, 128, FTW_PHYS));
+  ASSERT_EQ(0, nftw64(root.dirname, bug_28197840_nftw<struct stat64>, 128, FTW_PHYS));
+}
diff --git a/tests/stubs_test.cpp b/tests/grp_pwd_test.cpp
similarity index 78%
rename from tests/stubs_test.cpp
rename to tests/grp_pwd_test.cpp
index c81ca58..a684780 100644
--- a/tests/stubs_test.cpp
+++ b/tests/grp_pwd_test.cpp
@@ -26,6 +26,10 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#include <bitset>
+
+#include <private/android_filesystem_config.h>
+
 enum uid_type_t {
   TYPE_SYSTEM,
   TYPE_APP
@@ -122,12 +126,20 @@
   check_get_passwd("radio", 1001, TYPE_SYSTEM);
 }
 
-TEST(getpwnam, oem_id_0) {
-  check_get_passwd("oem_0", 5000, TYPE_SYSTEM);
+TEST(getpwnam, oem_id_5000) {
+  check_get_passwd("oem_5000", 5000, TYPE_SYSTEM);
 }
 
-TEST(getpwnam, oem_id_999) {
-  check_get_passwd("oem_999", 5999, TYPE_SYSTEM);
+TEST(getpwnam, oem_id_5999) {
+  check_get_passwd("oem_5999", 5999, TYPE_SYSTEM);
+}
+
+TEST(getpwnam, oem_id_2900) {
+  check_get_passwd("oem_2900", 2900, TYPE_SYSTEM);
+}
+
+TEST(getpwnam, oem_id_2999) {
+  check_get_passwd("oem_2999", 2999, TYPE_SYSTEM);
 }
 
 TEST(getpwnam, app_id_nobody) {
@@ -171,6 +183,46 @@
   check_get_passwd("u1_i0", 199000, TYPE_APP);
 }
 
+TEST(getpwent, iterate) {
+  passwd* pwd;
+  std::bitset<10000> exist;
+  bool application = false;
+
+  exist.reset();
+
+  setpwent();
+  while ((pwd = getpwent()) != NULL) {
+    ASSERT_TRUE(NULL != pwd->pw_name);
+    ASSERT_EQ(pwd->pw_gid, pwd->pw_uid);
+    ASSERT_EQ(NULL, pwd->pw_passwd);
+#ifdef __LP64__
+    ASSERT_TRUE(NULL == pwd->pw_gecos);
+#endif
+    ASSERT_TRUE(NULL != pwd->pw_shell);
+    if (pwd->pw_uid >= exist.size()) {
+      ASSERT_STREQ("/data", pwd->pw_dir);
+      application = true;
+    } else {
+      ASSERT_STREQ("/", pwd->pw_dir);
+      ASSERT_FALSE(exist[pwd->pw_uid]);
+      exist[pwd->pw_uid] = true;
+    }
+  }
+  endpwent();
+
+  // Required content
+  for (size_t n = 0; n < android_id_count; ++n) {
+    ASSERT_TRUE(exist[android_ids[n].aid]);
+  }
+  for (size_t n = 2900; n < 2999; ++n) {
+    ASSERT_TRUE(exist[n]);
+  }
+  for (size_t n = 5000; n < 5999; ++n) {
+    ASSERT_TRUE(exist[n]);
+  }
+  ASSERT_TRUE(application);
+}
+
 static void check_group(const group* grp, const char* group_name, gid_t gid) {
   ASSERT_TRUE(grp != NULL);
   ASSERT_STREQ(group_name, grp->gr_name);
@@ -255,12 +307,20 @@
   check_get_group("radio", 1001);
 }
 
-TEST(getgrnam, oem_id_0) {
-  check_get_group("oem_0", 5000);
+TEST(getgrnam, oem_id_5000) {
+  check_get_group("oem_5000", 5000);
 }
 
-TEST(getgrnam, oem_id_999) {
-  check_get_group("oem_999", 5999);
+TEST(getgrnam, oem_id_5999) {
+  check_get_group("oem_5999", 5999);
+}
+
+TEST(getgrnam, oem_id_2900) {
+  check_get_group("oem_2900", 2900);
+}
+
+TEST(getgrnam, oem_id_2999) {
+  check_get_group("oem_2999", 2999);
 }
 
 TEST(getgrnam, app_id_nobody) {
@@ -357,3 +417,38 @@
   ASSERT_EQ(0, getgrnam_r("root", &grp_storage, buf, size, &grp));
   check_group(grp, "root", 0);
 }
+
+TEST(getgrent, iterate) {
+  group* grp;
+  std::bitset<10000> exist;
+  bool application = false;
+
+  exist.reset();
+
+  setgrent();
+  while ((grp = getgrent()) != NULL) {
+    ASSERT_TRUE(grp->gr_name != NULL);
+    ASSERT_TRUE(grp->gr_mem != NULL);
+    ASSERT_STREQ(grp->gr_name, grp->gr_mem[0]);
+    ASSERT_TRUE(grp->gr_mem[1] == NULL);
+    if (grp->gr_gid >= exist.size()) {
+      application = true;
+    } else {
+      ASSERT_FALSE(exist[grp->gr_gid]);
+      exist[grp->gr_gid] = true;
+    }
+  }
+  endgrent();
+
+  // Required content
+  for (size_t n = 0; n < android_id_count; ++n) {
+    ASSERT_TRUE(exist[android_ids[n].aid]);
+  }
+  for (size_t n = 2900; n < 2999; ++n) {
+    ASSERT_TRUE(exist[n]);
+  }
+  for (size_t n = 5000; n < 5999; ++n) {
+    ASSERT_TRUE(exist[n]);
+  }
+  ASSERT_TRUE(application);
+}
diff --git a/tests/gtest_main.cpp b/tests/gtest_main.cpp
index 2b58646..a08a2e1 100644
--- a/tests/gtest_main.cpp
+++ b/tests/gtest_main.cpp
@@ -47,11 +47,26 @@
 #endif
 
 static std::string g_executable_path;
+static int g_argc;
+static char** g_argv;
+static char** g_envp;
 
 const std::string& get_executable_path() {
   return g_executable_path;
 }
 
+int get_argc() {
+  return g_argc;
+}
+
+char** get_argv() {
+  return g_argv;
+}
+
+char** get_envp() {
+  return g_envp;
+}
+
 namespace testing {
 namespace internal {
 
@@ -1122,8 +1137,11 @@
   return std::string(path, path_len);
 }
 
-int main(int argc, char** argv) {
+int main(int argc, char** argv, char** envp) {
   g_executable_path = get_proc_self_exe();
+  g_argc = argc;
+  g_argv = argv;
+  g_envp = envp;
   std::vector<char*> arg_list;
   for (int i = 0; i < argc; ++i) {
     arg_list.push_back(argv[i]);
diff --git a/tests/libs/Android.bp b/tests/libs/Android.bp
new file mode 100644
index 0000000..0303138
--- /dev/null
+++ b/tests/libs/Android.bp
@@ -0,0 +1,443 @@
+//
+// 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.
+//
+
+cc_defaults {
+    name: "bionic_testlib_defaults",
+    host_supported: true,
+    sanitize: {
+        never: true,
+    },
+    target: {
+        darwin: {
+            enabled: false,
+        },
+    },
+}
+
+// -----------------------------------------------------------------------------
+// Library to test gnu-styled hash
+// -----------------------------------------------------------------------------
+cc_library {
+    name: "libgnu-hash-table-library",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlext_test_library.cpp"],
+    ldflags: ["-Wl,--hash-style=gnu"],
+    arch: {
+        mips: {
+            enabled: false,
+        },
+        mips64: {
+            enabled: false,
+        },
+    },
+}
+
+// -----------------------------------------------------------------------------
+// Library to test sysv-styled hash
+// -----------------------------------------------------------------------------
+cc_library {
+    name: "libsysv-hash-table-library",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlext_test_library.cpp"],
+    ldflags: ["-Wl,--hash-style=sysv"],
+}
+
+// -----------------------------------------------------------------------------
+// Library used by dlext tests - with GNU RELRO program header
+// -----------------------------------------------------------------------------
+// In Android.mk to support creating symlinks
+
+// -----------------------------------------------------------------------------
+// Library used by dlext tests - without GNU RELRO program header
+// -----------------------------------------------------------------------------
+cc_library {
+    name: "libdlext_test_norelro",
+    srcs: ["dlext_test_library.cpp"],
+    ldflags: ["-Wl,-z,norelro"],
+    shared_libs = ["libtest_simple"],
+}
+
+// -----------------------------------------------------------------------------
+// Library used by dlext tests - different name non-default location
+// -----------------------------------------------------------------------------
+// In Android.mk to support installing to /data
+
+// -----------------------------------------------------------------------------
+// Libraries used by dlext tests for open from a zip-file
+// -----------------------------------------------------------------------------
+// In Android.mk to support installing to /data
+
+// ----------------------------------------------------------------------------
+// Library with soname which does not match filename
+// ----------------------------------------------------------------------------
+// In Android.mk to support zipped and aligned tests
+
+// -----------------------------------------------------------------------------
+// Library used by dlext tests - zipped and aligned
+// -----------------------------------------------------------------------------
+// In Android.mk to support zipped and aligned tests
+
+// -----------------------------------------------------------------------------
+// Library used by dlfcn tests
+// -----------------------------------------------------------------------------
+cc_library {
+    name: "libtest_simple",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_testlib_simple.cpp"],
+}
+
+// -----------------------------------------------------------------------------
+// Library used by dlfcn nodelete tests
+// -----------------------------------------------------------------------------
+cc_library {
+    name: "libtest_nodelete_1",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_nodelete_1.cpp"],
+}
+
+// -----------------------------------------------------------------------------
+// Library used by dlfcn nodelete tests
+// -----------------------------------------------------------------------------
+cc_library {
+    name: "libtest_nodelete_2",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_nodelete_2.cpp"],
+}
+
+// -----------------------------------------------------------------------------
+// Library used by dlfcn nodelete tests
+// -----------------------------------------------------------------------------
+cc_library {
+    name: "libtest_nodelete_dt_flags_1",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_nodelete_dt_flags_1.cpp"],
+    ldflags: ["-Wl,-z,nodelete"],
+}
+
+// -----------------------------------------------------------------------------
+// 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 loop used by dlfcn tests
+//
+// libtest_with_dependency_loop -> a -> b -> c -> a
+// -----------------------------------------------------------------------------
+cc_library {
+    name: "libtest_with_dependency_loop",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_testlib_loopy_root.cpp"],
+    shared_libs: ["libtest_with_dependency_loop_a"],
+}
+
+// -----------------------------------------------------------------------------
+// libtest_with_dependency_loop_a.so
+// -----------------------------------------------------------------------------
+cc_library {
+    name: "libtest_with_dependency_loop_a",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_testlib_loopy_a.cpp"],
+    shared_libs: ["libtest_with_dependency_loop_b_tmp"],
+}
+
+// -----------------------------------------------------------------------------
+// libtest_with_dependency_loop_b.so
+//
+// this is temporary placeholder - will be removed
+// -----------------------------------------------------------------------------
+cc_library {
+    name: "libtest_with_dependency_loop_b_tmp",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_testlib_loopy_invalid.cpp"],
+    ldflags: ["-Wl,-soname=libtest_with_dependency_loop_b.so"],
+}
+
+// -----------------------------------------------------------------------------
+// libtest_with_dependency_loop_b.so
+// -----------------------------------------------------------------------------
+cc_library {
+    name: "libtest_with_dependency_loop_b",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_testlib_loopy_b.cpp"],
+    shared_libs: ["libtest_with_dependency_loop_c"],
+}
+
+// -----------------------------------------------------------------------------
+// libtest_with_dependency_loop_c.so
+// -----------------------------------------------------------------------------
+cc_library {
+    name: "libtest_with_dependency_loop_c",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_testlib_loopy_c.cpp"],
+    shared_libs: ["libtest_with_dependency_loop_a"],
+}
+
+// -----------------------------------------------------------------------------
+// libtest_relo_check_dt_needed_order.so
+// |
+// +-> libtest_relo_check_dt_needed_order_1.so
+// |
+// +-> libtest_relo_check_dt_needed_order_2.so
+// -----------------------------------------------------------------------------
+
+
+cc_library {
+    name: "libtest_relo_check_dt_needed_order",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_testlib_relo_check_dt_needed_order.cpp"],
+    shared_libs: [
+        "libtest_relo_check_dt_needed_order_1",
+        "libtest_relo_check_dt_needed_order_2",
+    ],
+}
+
+cc_library {
+    name: "libtest_relo_check_dt_needed_order_1",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_testlib_relo_check_dt_needed_order_1.cpp"],
+}
+
+cc_library {
+    name: "libtest_relo_check_dt_needed_order_2",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_testlib_relo_check_dt_needed_order_2.cpp"],
+}
+
+// -----------------------------------------------------------------------------
+// Library with dependency used by dlfcn tests
+// -----------------------------------------------------------------------------
+// In Android.mk to support dependency on libdlext_test
+
+// -----------------------------------------------------------------------------
+// Library used by ifunc tests
+// -----------------------------------------------------------------------------
+cc_library {
+    name: "libtest_ifunc",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_testlib_ifunc.c"],
+
+    // TODO(dimitry): clang does not support ifunc attribute
+    clang: false,
+    arch: {
+        mips: {
+            enabled: false,
+        },
+        mips64: {
+            enabled: false,
+        },
+    },
+}
+
+// -----------------------------------------------------------------------------
+// Library used by atexit tests
+// -----------------------------------------------------------------------------
+
+cc_library {
+    name: "libtest_atexit",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["atexit_testlib.cpp"],
+}
+
+// -----------------------------------------------------------------------------
+// This library is used by dl_load test to check symbol preempting
+// by main executable
+// -----------------------------------------------------------------------------
+cc_library {
+    name: "libdl_preempt_test_1",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dl_preempt_library_1.cpp"],
+}
+
+// -----------------------------------------------------------------------------
+// This library is used by dl_load test to check symbol preempting
+// by libdl_preempt_test_1.so
+// -----------------------------------------------------------------------------
+cc_library {
+    name: "libdl_preempt_test_2",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dl_preempt_library_2.cpp"],
+}
+
+// -----------------------------------------------------------------------------
+// Library with DF_1_GLOBAL
+// -----------------------------------------------------------------------------
+cc_library {
+    name: "libdl_test_df_1_global",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dl_df_1_global.cpp"],
+    ldflags: ["-Wl,-z,global"],
+
+    target: {
+        host: {
+            // TODO (dimitry): host ld.gold does not yet support -z global
+            // remove this line once it is updated.
+            ldflags: ["-fuse-ld=bfd"],
+        },
+    },
+}
+
+// -----------------------------------------------------------------------------
+// Library using symbol from libdl_test_df_1_global
+// -----------------------------------------------------------------------------
+cc_library {
+    name: "libtest_dlsym_df_1_global",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dl_df_1_use_global.cpp"],
+}
+
+// -----------------------------------------------------------------------------
+// Library with weak function
+// -----------------------------------------------------------------------------
+cc_library {
+    name: "libtest_dlsym_weak_func",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlsym_weak_function.cpp"],
+}
+
+// -----------------------------------------------------------------------------
+// Library to check RTLD_LOCAL with dlsym in 'this'
+// -----------------------------------------------------------------------------
+cc_library {
+    name: "libtest_dlsym_from_this",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlsym_from_this_symbol.cpp"],
+    shared_libs: ["libtest_dlsym_from_this_child"],
+
+    target: {
+        android: {
+            shared_libs: ["libdl"],
+        },
+    },
+}
+
+// -----------------------------------------------------------------------------
+cc_library {
+    name: "libtest_dlsym_from_this_child",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlsym_from_this_functions.cpp"],
+    shared_libs: ["libtest_dlsym_from_this_grandchild"],
+}
+
+// -----------------------------------------------------------------------------
+cc_library {
+    name: "libtest_dlsym_from_this_grandchild",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlsym_from_this_symbol2.cpp"],
+}
+
+// -----------------------------------------------------------------------------
+// Empty library
+// -----------------------------------------------------------------------------
+cc_library {
+    name: "libtest_empty",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["empty.cpp"],
+}
+
+// -----------------------------------------------------------------------------
+// Library with weak undefined function
+// -----------------------------------------------------------------------------
+cc_library {
+    name: "libtest_dlopen_weak_undefined_func",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_weak_undefined.cpp"],
+}
+
+// -----------------------------------------------------------------------------
+// Library with constructor that calls dlopen() b/7941716
+// -----------------------------------------------------------------------------
+cc_library {
+    name: "libtest_dlopen_from_ctor",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dlopen_testlib_dlopen_from_ctor.cpp"],
+    target: {
+        android: {
+            shared_libs: ["libdl"],
+        },
+    },
+}
+
+// -----------------------------------------------------------------------------
+// Library that depends on the library with constructor that calls dlopen() b/7941716
+// -----------------------------------------------------------------------------
+cc_library {
+    name: "libtest_dlopen_from_ctor_main",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["empty.cpp"],
+    shared_libs: ["libtest_dlopen_from_ctor"],
+}
+
+// -----------------------------------------------------------------------------
+// Tool to use to align the shared libraries in a zip file.
+// -----------------------------------------------------------------------------
+cc_binary_host {
+    name: "bionic_tests_zipalign",
+    srcs: ["bionic_tests_zipalign.cpp"],
+    cflags: [
+        "-Wall",
+        "-Werror",
+    ],
+
+    static_libs: [
+        "libziparchive",
+        "liblog",
+        "libbase",
+        "libz",
+        "libutils",
+    ],
+
+    target: {
+        windows: {
+            enabled: true,
+        },
+    },
+}
diff --git a/tests/libs/Android.mk b/tests/libs/Android.mk
index 506d6f2..aa70b86 100644
--- a/tests/libs/Android.mk
+++ b/tests/libs/Android.mk
@@ -33,34 +33,6 @@
     $(TEST_PATH)/Android.build.mk
 
 # -----------------------------------------------------------------------------
-# Library to test gnu-styled hash
-# -----------------------------------------------------------------------------
-ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),mips mips64))
-libgnu-hash-table-library_src_files := \
-    dlext_test_library.cpp \
-
-libgnu-hash-table-library_ldflags := \
-    -Wl,--hash-style=gnu \
-
-module := libgnu-hash-table-library
-module_tag := optional
-include $(LOCAL_PATH)/Android.build.testlib.mk
-endif
-
-# -----------------------------------------------------------------------------
-# Library to test sysv-styled hash
-# -----------------------------------------------------------------------------
-libsysv-hash-table-library_src_files := \
-    dlext_test_library.cpp \
-
-libsysv-hash-table-library_ldflags := \
-    -Wl,--hash-style=sysv \
-
-module := libsysv-hash-table-library
-module_tag := optional
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
 # Library used by dlext tests - with GNU RELRO program header
 # -----------------------------------------------------------------------------
 libdlext_test_src_files := \
@@ -96,23 +68,6 @@
     $(hide) cd $(dir $@) && ln -sf $(notdir $@) libdlext_test_v2.so
 
 # -----------------------------------------------------------------------------
-# Library used by dlext tests - without GNU RELRO program header
-# -----------------------------------------------------------------------------
-libdlext_test_norelro_src_files := \
-    dlext_test_library.cpp \
-
-libdlext_test_norelro_ldflags := \
-    -Wl,-z,norelro \
-
-libdlext_test_norelro_shared_libraries := libtest_simple
-
-module := libdlext_test_norelro
-module_tag := optional
-build_type := target
-build_target := SHARED_LIBRARY
-include $(TEST_PATH)/Android.build.mk
-
-# -----------------------------------------------------------------------------
 # Library used by dlext tests - different name non-default location
 # -----------------------------------------------------------------------------
 libdlext_test_fd_src_files := \
@@ -176,44 +131,6 @@
 endif
 
 # -----------------------------------------------------------------------------
-# Library used by dlfcn tests
-# -----------------------------------------------------------------------------
-libtest_simple_src_files := \
-    dlopen_testlib_simple.cpp
-
-module := libtest_simple
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# Library used by dlfcn nodelete tests
-# -----------------------------------------------------------------------------
-libtest_nodelete_1_src_files := \
-    dlopen_nodelete_1.cpp
-
-module := libtest_nodelete_1
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# Library used by dlfcn nodelete tests
-# -----------------------------------------------------------------------------
-libtest_nodelete_2_src_files := \
-    dlopen_nodelete_2.cpp
-
-module := libtest_nodelete_2
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# Library used by dlfcn nodelete tests
-# -----------------------------------------------------------------------------
-libtest_nodelete_dt_flags_1_src_files := \
-    dlopen_nodelete_dt_flags_1.cpp
-
-libtest_nodelete_dt_flags_1_ldflags := -Wl,-z,nodelete
-
-module := libtest_nodelete_dt_flags_1
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
 # Build test helper libraries for linker namespaces
 # -----------------------------------------------------------------------------
 include $(LOCAL_PATH)/Android.build.linker_namespaces.mk
@@ -254,82 +171,6 @@
 include $(LOCAL_PATH)/Android.build.pthread_atfork.mk
 
 # -----------------------------------------------------------------------------
-# Library with dependency loop used by dlfcn tests
-#
-# libtest_with_dependency_loop -> a -> b -> c -> a
-# -----------------------------------------------------------------------------
-libtest_with_dependency_loop_src_files := dlopen_testlib_loopy_root.cpp
-
-libtest_with_dependency_loop_shared_libraries := \
-    libtest_with_dependency_loop_a
-
-module := libtest_with_dependency_loop
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# libtest_with_dependency_loop_a.so
-# -----------------------------------------------------------------------------
-libtest_with_dependency_loop_a_src_files := dlopen_testlib_loopy_a.cpp
-
-libtest_with_dependency_loop_a_shared_libraries := \
-    libtest_with_dependency_loop_b_tmp
-
-module := libtest_with_dependency_loop_a
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# libtest_with_dependency_loop_b.so
-#
-# this is temporary placeholder - will be removed
-# -----------------------------------------------------------------------------
-libtest_with_dependency_loop_b_tmp_src_files := dlopen_testlib_loopy_invalid.cpp
-libtest_with_dependency_loop_b_tmp_ldflags := -Wl,-soname=libtest_with_dependency_loop_b.so
-
-module := libtest_with_dependency_loop_b_tmp
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# libtest_with_dependency_loop_b.so
-# -----------------------------------------------------------------------------
-libtest_with_dependency_loop_b_src_files := dlopen_testlib_loopy_b.cpp
-libtest_with_dependency_loop_b_shared_libraries := libtest_with_dependency_loop_c
-
-module := libtest_with_dependency_loop_b
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# libtest_with_dependency_loop_c.so
-# -----------------------------------------------------------------------------
-libtest_with_dependency_loop_c_src_files := dlopen_testlib_loopy_c.cpp
-
-libtest_with_dependency_loop_c_shared_libraries := \
-    libtest_with_dependency_loop_a
-
-module := libtest_with_dependency_loop_c
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# libtest_relo_check_dt_needed_order.so
-# |
-# +-> libtest_relo_check_dt_needed_order_1.so
-# |
-# +-> libtest_relo_check_dt_needed_order_2.so
-# -----------------------------------------------------------------------------
-libtest_relo_check_dt_needed_order_shared_libraries := \
-    libtest_relo_check_dt_needed_order_1 libtest_relo_check_dt_needed_order_2
-
-libtest_relo_check_dt_needed_order_src_files := dlopen_testlib_relo_check_dt_needed_order.cpp
-libtest_relo_check_dt_needed_order_1_src_files := dlopen_testlib_relo_check_dt_needed_order_1.cpp
-libtest_relo_check_dt_needed_order_2_src_files := dlopen_testlib_relo_check_dt_needed_order_2.cpp
-
-module := libtest_relo_check_dt_needed_order
-include $(LOCAL_PATH)/Android.build.testlib.mk
-module := libtest_relo_check_dt_needed_order_1
-include $(LOCAL_PATH)/Android.build.testlib.mk
-module := libtest_relo_check_dt_needed_order_2
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
 # Library with dependency used by dlfcn tests
 # -----------------------------------------------------------------------------
 libtest_with_dependency_src_files := \
@@ -339,165 +180,3 @@
 
 module := libtest_with_dependency
 include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# Library used by ifunc tests
-# -----------------------------------------------------------------------------
-libtest_ifunc_src_files := \
-    dlopen_testlib_ifunc.c
-
-libtest_ifunc_clang_host := false
-module := libtest_ifunc
-build_target := SHARED_LIBRARY
-
-build_type := host
-include $(TEST_PATH)/Android.build.mk
-
-ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm64 x86 x86_64))
-    ifeq ($(TARGET_ARCH),arm64)
-      libtest_ifunc_multilib := 64
-      # TODO: This is a workaround - remove it once gcc
-      # removes its Android ifunc checks
-      libtest_ifunc_cflags := -mglibc
-    endif
-
-    build_type := target
-    libtest_ifunc_clang_target := false
-    include $(TEST_PATH)/Android.build.mk
-endif
-
-# -----------------------------------------------------------------------------
-# Library used by atexit tests
-# -----------------------------------------------------------------------------
-
-libtest_atexit_src_files := \
-    atexit_testlib.cpp
-
-module := libtest_atexit
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# This library is used by dl_load test to check symbol preempting
-# by main executable
-# -----------------------------------------------------------------------------
-libdl_preempt_test_1_src_files := dl_preempt_library_1.cpp
-
-module := libdl_preempt_test_1
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# This library is used by dl_load test to check symbol preempting
-# by libdl_preempt_test_1.so
-# -----------------------------------------------------------------------------
-libdl_preempt_test_2_src_files := dl_preempt_library_2.cpp
-
-module := libdl_preempt_test_2
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# Library with DF_1_GLOBAL
-# -----------------------------------------------------------------------------
-libdl_test_df_1_global_src_files := dl_df_1_global.cpp
-libdl_test_df_1_global_ldflags := -Wl,-z,global
-
-# TODO (dimitry): host ld.gold does not yet support -z global
-# remove this line once it is updated.
-libdl_test_df_1_global_ldflags_host := -fuse-ld=bfd
-
-module := libdl_test_df_1_global
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# Library using symbol from libdl_test_df_1_global
-# -----------------------------------------------------------------------------
-libtest_dlsym_df_1_global_src_files := dl_df_1_use_global.cpp
-module := libtest_dlsym_df_1_global
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# Library with weak function
-# -----------------------------------------------------------------------------
-libtest_dlsym_weak_func_src_files := \
-    dlsym_weak_function.cpp
-
-module := libtest_dlsym_weak_func
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# Library to check RTLD_LOCAL with dlsym in 'this'
-# -----------------------------------------------------------------------------
-libtest_dlsym_from_this_src_files := dlsym_from_this_symbol.cpp
-
-libtest_dlsym_from_this_shared_libraries_target := libdl
-libtest_dlsym_from_this_shared_libraries := libtest_dlsym_from_this_child
-
-module := libtest_dlsym_from_this
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-libtest_dlsym_from_this_child_src_files := dlsym_from_this_functions.cpp
-
-libtest_dlsym_from_this_child_shared_libraries := libtest_dlsym_from_this_grandchild
-
-module := libtest_dlsym_from_this_child
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-libtest_dlsym_from_this_grandchild_src_files := dlsym_from_this_symbol2.cpp
-
-module := libtest_dlsym_from_this_grandchild
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# Empty library
-# -----------------------------------------------------------------------------
-libtest_empty_src_files := empty.cpp
-
-module := libtest_empty
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# Library with weak undefined function
-# -----------------------------------------------------------------------------
-libtest_dlopen_weak_undefined_func_src_files := \
-    dlopen_weak_undefined.cpp
-
-module := libtest_dlopen_weak_undefined_func
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# Library with constructor that calls dlopen() b/7941716
-# -----------------------------------------------------------------------------
-libtest_dlopen_from_ctor_src_files := \
-   dlopen_testlib_dlopen_from_ctor.cpp
-
-module := libtest_dlopen_from_ctor
-
-libtest_dlopen_from_ctor_shared_libraries_target := libdl
-
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# Library that depends on the library with constructor that calls dlopen() b/7941716
-# -----------------------------------------------------------------------------
-
-libtest_dlopen_from_ctor_main_src_files := empty.cpp
-libtest_dlopen_from_ctor_main_shared_libraries := libtest_dlopen_from_ctor
-
-module := libtest_dlopen_from_ctor_main
-include $(LOCAL_PATH)/Android.build.testlib.mk
-
-# -----------------------------------------------------------------------------
-# Tool to use to align the shared libraries in a zip file.
-# -----------------------------------------------------------------------------
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := bionic_tests_zipalign.cpp
-LOCAL_MODULE := bionic_tests_zipalign
-LOCAL_CFLAGS := -Wall -Werror
-
-LOCAL_STATIC_LIBRARIES := libziparchive-host liblog libbase libz libutils
-
-LOCAL_MODULE_HOST_OS := darwin linux windows
-
-include $(BUILD_HOST_EXECUTABLE)
diff --git a/tests/mntent_test.cpp b/tests/mntent_test.cpp
index a102849..3fb2f86 100644
--- a/tests/mntent_test.cpp
+++ b/tests/mntent_test.cpp
@@ -38,3 +38,20 @@
 
   ASSERT_EQ(1, endmntent(fp));
 }
+
+TEST(mntent, hasmntopt) {
+  // indices                  1  1
+  // of keys:      0    5   9 1  4
+  char mnt_opts[]{"aa=b,a=b,b,bb,c=d"};
+  struct mntent ent;
+  memset(&ent, 0, sizeof(ent));
+  ent.mnt_opts = mnt_opts;
+
+  EXPECT_EQ(mnt_opts, hasmntopt(&ent, "aa"));
+  EXPECT_EQ(mnt_opts + 5, hasmntopt(&ent, "a"));
+  EXPECT_EQ(mnt_opts + 9, hasmntopt(&ent, "b"));
+  EXPECT_EQ(mnt_opts + 11, hasmntopt(&ent, "bb"));
+  EXPECT_EQ(mnt_opts + 14, hasmntopt(&ent, "c"));
+  EXPECT_EQ(nullptr, hasmntopt(&ent, "d"));
+  EXPECT_EQ(nullptr, hasmntopt(&ent, "e"));
+}
diff --git a/tests/netinet_ether_test.cpp b/tests/netinet_ether_test.cpp
new file mode 100644
index 0000000..faa3db4
--- /dev/null
+++ b/tests/netinet_ether_test.cpp
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+
+#include <gtest/gtest.h>
+
+#include <netinet/ether.h>
+
+TEST(netinet_ether, ether_aton__ether_ntoa) {
+  ether_addr* a = ether_aton("12:34:56:78:9a:bc");
+  ASSERT_NE(nullptr, a);
+  ASSERT_EQ(0x12, a->ether_addr_octet[0]);
+  ASSERT_EQ(0x34, a->ether_addr_octet[1]);
+  ASSERT_EQ(0x56, a->ether_addr_octet[2]);
+  ASSERT_EQ(0x78, a->ether_addr_octet[3]);
+  ASSERT_EQ(0x9a, a->ether_addr_octet[4]);
+  ASSERT_EQ(0xbc, a->ether_addr_octet[5]);
+
+  ASSERT_STREQ("12:34:56:78:9a:bc", ether_ntoa(a));
+}
+
+TEST(netinet_ether, ether_aton_r__ether_ntoa_r) {
+  ether_addr addr;
+  memset(&addr, 0, sizeof(addr));
+  ether_addr* a = ether_aton_r("12:34:56:78:9a:bc", &addr);
+  ASSERT_EQ(&addr, a);
+  ASSERT_EQ(0x12, addr.ether_addr_octet[0]);
+  ASSERT_EQ(0x34, addr.ether_addr_octet[1]);
+  ASSERT_EQ(0x56, addr.ether_addr_octet[2]);
+  ASSERT_EQ(0x78, addr.ether_addr_octet[3]);
+  ASSERT_EQ(0x9a, addr.ether_addr_octet[4]);
+  ASSERT_EQ(0xbc, addr.ether_addr_octet[5]);
+
+  char buf[32];
+  memset(buf, 0, sizeof(buf));
+  char* p = ether_ntoa_r(&addr, buf);
+  ASSERT_EQ(buf, p);
+  ASSERT_STREQ("12:34:56:78:9a:bc", buf);
+}
diff --git a/tests/nl_types_test.cpp b/tests/nl_types_test.cpp
new file mode 100644
index 0000000..2e3995b
--- /dev/null
+++ b/tests/nl_types_test.cpp
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+#include <nl_types.h>
+
+#include <errno.h>
+#include <gtest/gtest.h>
+
+TEST(nl_types, smoke) {
+  nl_catd cat = catopen("/does/not/exist", NL_CAT_LOCALE);
+  ASSERT_EQ(reinterpret_cast<nl_catd>(-1), cat);
+
+  ASSERT_STREQ("hello, world!", catgets(cat, NL_SETD, 0, "hello, world!"));
+
+  errno = 0;
+  ASSERT_EQ(-1, catclose(cat));
+  ASSERT_EQ(EBADF, errno);
+}
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index 0313171..b0c95fe 100755
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -24,6 +24,7 @@
 #include <signal.h>
 #include <stdio.h>
 #include <sys/mman.h>
+#include <sys/prctl.h>
 #include <sys/syscall.h>
 #include <time.h>
 #include <unistd.h>
@@ -260,10 +261,10 @@
 }
 
 TEST(pthread, pthread_no_join_after_detach) {
-  SpinFunctionHelper spinhelper;
+  SpinFunctionHelper spin_helper;
 
   pthread_t t1;
-  ASSERT_EQ(0, pthread_create(&t1, NULL, spinhelper.GetFunction(), NULL));
+  ASSERT_EQ(0, pthread_create(&t1, NULL, spin_helper.GetFunction(), NULL));
 
   // After a pthread_detach...
   ASSERT_EQ(0, pthread_detach(t1));
@@ -274,10 +275,10 @@
 }
 
 TEST(pthread, pthread_no_op_detach_after_join) {
-  SpinFunctionHelper spinhelper;
+  SpinFunctionHelper spin_helper;
 
   pthread_t t1;
-  ASSERT_EQ(0, pthread_create(&t1, NULL, spinhelper.GetFunction(), NULL));
+  ASSERT_EQ(0, pthread_create(&t1, NULL, spin_helper.GetFunction(), NULL));
 
   // If thread 2 is already waiting to join thread 1...
   pthread_t t2;
@@ -292,7 +293,7 @@
 #endif
   AssertDetached(t1, false);
 
-  spinhelper.UnSpin();
+  spin_helper.UnSpin();
 
   // ...but t2's join on t1 still goes ahead (which we can tell because our join on t2 finishes).
   void* join_result;
@@ -396,32 +397,60 @@
   ASSERT_EQ(0, pthread_sigmask(SIG_SETMASK, &original_set, NULL));
 }
 
-TEST(pthread, pthread_setname_np__too_long) {
+static void test_pthread_setname_np__pthread_getname_np(pthread_t t) {
+  ASSERT_EQ(0, pthread_setname_np(t, "short"));
+  char name[32];
+  ASSERT_EQ(0, pthread_getname_np(t, name, sizeof(name)));
+  ASSERT_STREQ("short", name);
+
   // The limit is 15 characters --- the kernel's buffer is 16, but includes a NUL.
-  ASSERT_EQ(0, pthread_setname_np(pthread_self(), "123456789012345"));
-  ASSERT_EQ(ERANGE, pthread_setname_np(pthread_self(), "1234567890123456"));
+  ASSERT_EQ(0, pthread_setname_np(t, "123456789012345"));
+  ASSERT_EQ(0, pthread_getname_np(t, name, sizeof(name)));
+  ASSERT_STREQ("123456789012345", name);
+
+  ASSERT_EQ(ERANGE, pthread_setname_np(t, "1234567890123456"));
+
+  // The passed-in buffer should be at least 16 bytes.
+  ASSERT_EQ(0, pthread_getname_np(t, name, 16));
+  ASSERT_EQ(ERANGE, pthread_getname_np(t, name, 15));
 }
 
-TEST(pthread, pthread_setname_np__self) {
-  ASSERT_EQ(0, pthread_setname_np(pthread_self(), "short 1"));
+TEST(pthread, pthread_setname_np__pthread_getname_np__self) {
+  test_pthread_setname_np__pthread_getname_np(pthread_self());
 }
 
-TEST(pthread, pthread_setname_np__other) {
-  SpinFunctionHelper spinhelper;
+TEST(pthread, pthread_setname_np__pthread_getname_np__other) {
+  SpinFunctionHelper spin_helper;
 
-  pthread_t t1;
-  ASSERT_EQ(0, pthread_create(&t1, NULL, spinhelper.GetFunction(), NULL));
-  ASSERT_EQ(0, pthread_setname_np(t1, "short 2"));
-  spinhelper.UnSpin();
-  ASSERT_EQ(0, pthread_join(t1, nullptr));
+  pthread_t t;
+  ASSERT_EQ(0, pthread_create(&t, nullptr, spin_helper.GetFunction(), nullptr));
+  test_pthread_setname_np__pthread_getname_np(t);
+  spin_helper.UnSpin();
+  ASSERT_EQ(0, pthread_join(t, nullptr));
 }
 
-TEST(pthread, pthread_setname_np__no_such_thread) {
+// http://b/28051133: a kernel misfeature means that you can't change the
+// name of another thread if you've set PR_SET_DUMPABLE to 0.
+TEST(pthread, pthread_setname_np__pthread_getname_np__other_PR_SET_DUMPABLE) {
+  ASSERT_EQ(0, prctl(PR_SET_DUMPABLE, 0)) << strerror(errno);
+
+  SpinFunctionHelper spin_helper;
+
+  pthread_t t;
+  ASSERT_EQ(0, pthread_create(&t, nullptr, spin_helper.GetFunction(), nullptr));
+  test_pthread_setname_np__pthread_getname_np(t);
+  spin_helper.UnSpin();
+  ASSERT_EQ(0, pthread_join(t, nullptr));
+}
+
+TEST(pthread, pthread_setname_np__pthread_getname_np__no_such_thread) {
   pthread_t dead_thread;
   MakeDeadThread(dead_thread);
 
-  // Call pthread_setname_np after thread has already exited.
+  // Call pthread_getname_np and pthread_setname_np after the thread has already exited.
   ASSERT_EQ(ENOENT, pthread_setname_np(dead_thread, "short 3"));
+  char name[64];
+  ASSERT_EQ(ENOENT, pthread_getname_np(dead_thread, name, sizeof(name)));
 }
 
 TEST(pthread, pthread_kill__0) {
@@ -455,16 +484,16 @@
 }
 
 TEST(pthread, pthread_getcpuclockid__clock_gettime) {
-  SpinFunctionHelper spinhelper;
+  SpinFunctionHelper spin_helper;
 
   pthread_t t;
-  ASSERT_EQ(0, pthread_create(&t, NULL, spinhelper.GetFunction(), NULL));
+  ASSERT_EQ(0, pthread_create(&t, NULL, spin_helper.GetFunction(), NULL));
 
   clockid_t c;
   ASSERT_EQ(0, pthread_getcpuclockid(t, &c));
   timespec ts;
   ASSERT_EQ(0, clock_gettime(c, &ts));
-  spinhelper.UnSpin();
+  spin_helper.UnSpin();
   ASSERT_EQ(0, pthread_join(t, nullptr));
 }
 
@@ -509,10 +538,10 @@
 }
 
 TEST(pthread, pthread_join__multijoin) {
-  SpinFunctionHelper spinhelper;
+  SpinFunctionHelper spin_helper;
 
   pthread_t t1;
-  ASSERT_EQ(0, pthread_create(&t1, NULL, spinhelper.GetFunction(), NULL));
+  ASSERT_EQ(0, pthread_create(&t1, NULL, spin_helper.GetFunction(), NULL));
 
   pthread_t t2;
   ASSERT_EQ(0, pthread_create(&t2, NULL, JoinFn, reinterpret_cast<void*>(t1)));
@@ -522,7 +551,7 @@
   // Multiple joins to the same thread should fail.
   ASSERT_EQ(EINVAL, pthread_join(t1, NULL));
 
-  spinhelper.UnSpin();
+  spin_helper.UnSpin();
 
   // ...but t2's join on t1 still goes ahead (which we can tell because our join on t2 finishes).
   void* join_result;
@@ -897,7 +926,7 @@
   pthread_rwlock_t lock;
 
  public:
-  RwlockKindTestHelper(int kind_type) {
+  explicit RwlockKindTestHelper(int kind_type) {
     InitRwlock(kind_type);
   }
 
@@ -1318,7 +1347,8 @@
 
 struct GetStackSignalHandlerArg {
   volatile bool done;
-  void* signal_handler_sp;
+  void* signal_stack_base;
+  size_t signal_stack_size;
   void* main_stack_base;
   size_t main_stack_size;
 };
@@ -1334,9 +1364,17 @@
   void* stack_base;
   size_t stack_size;
   ASSERT_EQ(0, pthread_attr_getstack(&attr, &stack_base, &stack_size));
-  getstack_signal_handler_arg.signal_handler_sp = &attr;
-  getstack_signal_handler_arg.main_stack_base = stack_base;
-  getstack_signal_handler_arg.main_stack_size = stack_size;
+
+  // Verify if the stack used by the signal handler is the alternate stack just registered.
+  ASSERT_LE(getstack_signal_handler_arg.signal_stack_base, &attr);
+  ASSERT_LT(static_cast<void*>(&attr),
+            static_cast<char*>(getstack_signal_handler_arg.signal_stack_base) +
+            getstack_signal_handler_arg.signal_stack_size);
+
+  // Verify if the main thread's stack got in the signal handler is correct.
+  ASSERT_EQ(getstack_signal_handler_arg.main_stack_base, stack_base);
+  ASSERT_LE(getstack_signal_handler_arg.main_stack_size, stack_size);
+
   getstack_signal_handler_arg.done = true;
 }
 
@@ -1369,18 +1407,13 @@
 
   ScopedSignalHandler handler(SIGUSR1, getstack_signal_handler, SA_ONSTACK);
   getstack_signal_handler_arg.done = false;
+  getstack_signal_handler_arg.signal_stack_base = sig_stack;
+  getstack_signal_handler_arg.signal_stack_size = sig_stack_size;
+  getstack_signal_handler_arg.main_stack_base = main_stack_base;
+  getstack_signal_handler_arg.main_stack_size = main_stack_size;
   kill(getpid(), SIGUSR1);
   ASSERT_EQ(true, getstack_signal_handler_arg.done);
 
-  // Verify if the stack used by the signal handler is the alternate stack just registered.
-  ASSERT_LE(sig_stack, getstack_signal_handler_arg.signal_handler_sp);
-  ASSERT_GE(reinterpret_cast<char*>(sig_stack) + sig_stack_size,
-            getstack_signal_handler_arg.signal_handler_sp);
-
-  // Verify if the main thread's stack got in the signal handler is correct.
-  ASSERT_EQ(main_stack_base, getstack_signal_handler_arg.main_stack_base);
-  ASSERT_LE(main_stack_size, getstack_signal_handler_arg.main_stack_size);
-
   ASSERT_EQ(0, sigaltstack(&oss, nullptr));
   ASSERT_EQ(0, munmap(sig_stack, sig_stack_size));
 }
@@ -1510,7 +1543,7 @@
 struct PthreadMutex {
   pthread_mutex_t lock;
 
-  PthreadMutex(int mutex_type) {
+  explicit PthreadMutex(int mutex_type) {
     init(mutex_type);
   }
 
@@ -1611,7 +1644,7 @@
   }
 
  public:
-  MutexWakeupHelper(int mutex_type) : m(mutex_type) {
+  explicit MutexWakeupHelper(int mutex_type) : m(mutex_type) {
   }
 
   void test() {
@@ -1751,7 +1784,14 @@
 
 TEST(pthread, pthread_mutex_lock_null_32) {
 #if defined(__BIONIC__) && !defined(__LP64__)
-  ASSERT_EQ(EINVAL, pthread_mutex_lock(NULL));
+  // For LP32, the pthread lock/unlock functions allow a NULL mutex and return
+  // EINVAL in that case: http://b/19995172.
+  //
+  // We decorate the public defintion with _Nonnull so that people recompiling
+  // their code with get a warning and might fix their bug, but need to pass
+  // NULL here to test that we remain compatible.
+  pthread_mutex_t* null_value = nullptr;
+  ASSERT_EQ(EINVAL, pthread_mutex_lock(null_value));
 #else
   GTEST_LOG_(INFO) << "This test tests bionic implementation details on 32 bit devices.";
 #endif
@@ -1759,7 +1799,14 @@
 
 TEST(pthread, pthread_mutex_unlock_null_32) {
 #if defined(__BIONIC__) && !defined(__LP64__)
-  ASSERT_EQ(EINVAL, pthread_mutex_unlock(NULL));
+  // For LP32, the pthread lock/unlock functions allow a NULL mutex and return
+  // EINVAL in that case: http://b/19995172.
+  //
+  // We decorate the public defintion with _Nonnull so that people recompiling
+  // their code with get a warning and might fix their bug, but need to pass
+  // NULL here to test that we remain compatible.
+  pthread_mutex_t* null_value = nullptr;
+  ASSERT_EQ(EINVAL, pthread_mutex_unlock(null_value));
 #else
   GTEST_LOG_(INFO) << "This test tests bionic implementation details on 32 bit devices.";
 #endif
diff --git a/libc/bionic/__memchr_chk.cpp b/tests/resolv_test.cpp
similarity index 66%
copy from libc/bionic/__memchr_chk.cpp
copy to tests/resolv_test.cpp
index d141c04..08f9d90 100644
--- a/libc/bionic/__memchr_chk.cpp
+++ b/tests/resolv_test.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 The Android Open Source Project
+ * Copyright (C) 2016 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,14 +26,19 @@
  * SUCH DAMAGE.
  */
 
-#undef _FORTIFY_SOURCE
-#include <string.h>
-#include "private/libc_logging.h"
+#include <resolv.h>
 
-extern "C" void* __memchr_chk(const void* s, int c, size_t n, size_t buf_size) {
-  if (__predict_false(n > buf_size)) {
-    __fortify_chk_fail("memchr: prevented read past end of buffer", 0);
-  }
+#include <gtest/gtest.h>
 
-  return memchr(s, c, n);
+TEST(resolv, b64_pton_28035006) {
+  // Test data from https://groups.google.com/forum/#!topic/mailing.openbsd.tech/w3ACIlklJkI.
+  const char* data =
+      "p1v3+nehH3N3n+/OokzXpsyGF2VVpxIxkjSn3Mv/Sq74OE1iFuVU+K4bQImuVj"
+      "S55RB2fpCpbB8Nye7tzrt6h9YPP3yyJfqORDETGmIB4lveZXA4KDxx50F9rYrO"
+      "dFbTLyWfNBb/8Q2TnD72eY/3Y5P9qwtJwyDL25Tleic8G3g=";
+
+  // This buffer is exactly the right size, but old versions of the BSD code
+  // incorrectly required an extra byte. http://b/28035006.
+  uint8_t buf[128];
+  ASSERT_EQ(128, b64_pton(data, buf, sizeof(buf)));
 }
diff --git a/tests/run-on-host.sh b/tests/run-on-host.sh
new file mode 100755
index 0000000..c47bc4f
--- /dev/null
+++ b/tests/run-on-host.sh
@@ -0,0 +1,34 @@
+#!/bin/bash -e
+
+. $(dirname $0)/../build/run-on-host.sh
+
+if [ "$1" = glibc ]; then
+    m -j bionic-unit-tests-glibc
+    (
+        cd ${ANDROID_BUILD_TOP}
+        export ANDROID_DATA=${TARGET_OUT_DATA}
+        export ANDROID_ROOT=${TARGET_OUT}
+        ${HOST_OUT}/nativetest64/bionic-unit-tests-glibc/bionic-unit-tests-glibc $@
+    )
+    exit 0
+elif [ "$1" != 32 -a "$1" != 64 ]; then
+    echo "Usage: $0 [ 32 | 64 | glibc ] [gtest flags]"
+    exit 1
+fi
+
+if [ ${HOST_OS}-${HOST_ARCH} = linux-x86 -o ${HOST_OS}-${HOST_ARCH} = linux-x86_64 ]; then
+
+    prepare $1 bionic-unit-tests
+
+    if [ ${TARGET_ARCH} = x86 -o ${TARGET_ARCH} = x86_64 ]; then
+        (
+            cd ${ANDROID_BUILD_TOP}
+            export ANDROID_DATA=${TARGET_OUT_DATA}
+            export ANDROID_DNS_MODE=local
+            export ANDROID_ROOT=${TARGET_OUT}
+            ${NATIVETEST}/bionic-unit-tests/bionic-unit-tests $@
+        )
+    else
+        echo "$0 not supported on TARGET_ARCH=$TARGET_ARCH"
+    fi
+fi
diff --git a/tests/sched_test.cpp b/tests/sched_test.cpp
index caf4c65..a4cffc0 100644
--- a/tests/sched_test.cpp
+++ b/tests/sched_test.cpp
@@ -21,12 +21,12 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 
-#if defined(__BIONIC__)
 static int child_fn(void* i_ptr) {
   *reinterpret_cast<int*>(i_ptr) = 42;
   return 123;
 }
 
+#if defined(__BIONIC__)
 TEST(sched, clone) {
   void* child_stack[1024];
 
@@ -55,7 +55,15 @@
   // Check that our hand-written clone assembler sets errno correctly on failure.
   uintptr_t fake_child_stack[16];
   errno = 0;
-  ASSERT_EQ(-1, clone(NULL, &fake_child_stack[16], CLONE_THREAD, NULL));
+  // If CLONE_THREAD is set, CLONE_SIGHAND must be set too.
+  ASSERT_EQ(-1, clone(child_fn, &fake_child_stack[16], CLONE_THREAD, NULL));
+  ASSERT_EQ(EINVAL, errno);
+}
+
+TEST(sched, clone_null_child_stack) {
+  int i = 0;
+  errno = 0;
+  ASSERT_EQ(-1, clone(child_fn, nullptr, CLONE_VM, &i));
   ASSERT_EQ(EINVAL, errno);
 }
 
diff --git a/tests/search_test.cpp b/tests/search_test.cpp
index 3900c89..d368f9f 100644
--- a/tests/search_test.cpp
+++ b/tests/search_test.cpp
@@ -49,7 +49,7 @@
 }
 
 struct node {
-  node(const char* s) : s(strdup(s)) {}
+  explicit node(const char* s) : s(strdup(s)) {}
 
   char* s;
 };
@@ -115,7 +115,7 @@
 }
 
 struct pod_node {
-  pod_node(int i) : i(i) {}
+  explicit pod_node(int i) : i(i) {}
   int i;
 };
 
@@ -136,7 +136,7 @@
 }
 
 struct q_node {
-  q_node(int i) : i(i) {}
+  explicit q_node(int i) : i(i) {}
 
   q_node* next;
   q_node* prev;
diff --git a/tests/setjmp_test.cpp b/tests/setjmp_test.cpp
index b7e856f..bb01601 100644
--- a/tests/setjmp_test.cpp
+++ b/tests/setjmp_test.cpp
@@ -254,7 +254,7 @@
 
   if (value == 0) {
     // Flip a bit.
-    reinterpret_cast<long*>(jb)[0] ^= 1;
+    reinterpret_cast<long*>(jb)[1] ^= 1;
 
     EXPECT_DEATH(longjmp(jb, 1), "checksum mismatch");
   } else {
diff --git a/tests/signal_test.cpp b/tests/signal_test.cpp
index c5128ea..36ac690 100644
--- a/tests/signal_test.cpp
+++ b/tests/signal_test.cpp
@@ -422,3 +422,108 @@
 
 #endif
 #endif
+
+TEST(signal, sigignore_EINVAL) {
+  errno = 0;
+  ASSERT_EQ(-1, sigignore(99999));
+  ASSERT_EQ(EINVAL, errno);
+}
+
+TEST(signal, sigignore) {
+  errno = 0;
+  EXPECT_EQ(-1, sigignore(SIGKILL));
+  EXPECT_EQ(errno, EINVAL);
+
+  errno = 0;
+  EXPECT_EQ(-1, sigignore(SIGSTOP));
+  EXPECT_EQ(errno, EINVAL);
+
+  ScopedSignalHandler sigalrm{SIGALRM};
+  ASSERT_EQ(0, sigignore(SIGALRM));
+
+  struct sigaction sa;
+  ASSERT_EQ(0, sigaction(SIGALRM, nullptr, &sa));
+  EXPECT_EQ(SIG_IGN, sa.sa_handler);
+}
+
+TEST(signal, sighold_EINVAL) {
+  errno = 0;
+  ASSERT_EQ(-1, sighold(99999));
+  ASSERT_EQ(EINVAL, errno);
+}
+
+TEST(signal, sigpause_EINVAL) {
+  errno = 0;
+  ASSERT_EQ(-1, sigpause(99999));
+  ASSERT_EQ(EINVAL, errno);
+}
+
+TEST(signal, sigrelse_EINVAL) {
+  errno = 0;
+  ASSERT_EQ(-1, sigpause(99999));
+  ASSERT_EQ(EINVAL, errno);
+}
+
+TEST(signal, sighold_sigpause_sigrelse) {
+  static int sigalrm_handler_call_count;
+  auto sigalrm_handler = [](int) { sigalrm_handler_call_count++; };
+  ScopedSignalHandler sigalrm{SIGALRM, sigalrm_handler};
+  ScopedSignalMask mask;
+  sigset_t set;
+
+  // sighold(SIGALRM) should add SIGALRM to the signal mask ...
+  ASSERT_EQ(0, sighold(SIGALRM));
+  ASSERT_EQ(0, sigprocmask(SIG_SETMASK, 0, &set));
+  EXPECT_TRUE(sigismember(&set, SIGALRM));
+
+  // ... preventing our SIGALRM handler from running ...
+  raise(SIGALRM);
+  ASSERT_EQ(0, sigalrm_handler_call_count);
+  // ... until sigpause(SIGALRM) temporarily unblocks it.
+  ASSERT_EQ(-1, sigpause(SIGALRM));
+  ASSERT_EQ(EINTR, errno);
+  ASSERT_EQ(1, sigalrm_handler_call_count);
+
+  // But sigpause(SIGALRM) shouldn't permanently unblock SIGALRM.
+  ASSERT_EQ(0, sigprocmask(SIG_SETMASK, 0, &set));
+  EXPECT_TRUE(sigismember(&set, SIGALRM));
+
+  ASSERT_EQ(0, sigrelse(SIGALRM));
+  ASSERT_EQ(0, sigprocmask(SIG_SETMASK, 0, &set));
+  EXPECT_FALSE(sigismember(&set, SIGALRM));
+}
+
+TEST(signal, sigset_EINVAL) {
+  errno = 0;
+  ASSERT_EQ(SIG_ERR, sigset(99999, SIG_DFL));
+  ASSERT_EQ(EINVAL, errno);
+}
+
+TEST(signal, sigset) {
+  auto sigalrm_handler = [](int) { };
+  ScopedSignalHandler sigalrm{SIGALRM, sigalrm_handler};
+  ScopedSignalMask mask;
+
+  // block SIGALRM so the next sigset(SIGARLM) call will return SIG_HOLD
+  sigset_t sigalrm_set;
+  sigemptyset(&sigalrm_set);
+  sigaddset(&sigalrm_set, SIGALRM);
+  ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &sigalrm_set, nullptr));
+
+  sigset_t set;
+  ASSERT_EQ(SIG_HOLD, sigset(SIGALRM, sigalrm_handler));
+  ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &set));
+  EXPECT_FALSE(sigismember(&set, SIGALRM));
+
+  ASSERT_EQ(sigalrm_handler, sigset(SIGALRM, SIG_IGN));
+  ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &set));
+  EXPECT_FALSE(sigismember(&set, SIGALRM));
+
+  ASSERT_EQ(SIG_IGN, sigset(SIGALRM, SIG_DFL));
+  ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &set));
+  EXPECT_FALSE(sigismember(&set, SIGALRM));
+
+  ASSERT_EQ(SIG_DFL, sigset(SIGALRM, SIG_HOLD));
+  ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &set));
+  EXPECT_TRUE(sigismember(&set, SIGALRM));
+}
diff --git a/tests/stack_protector_test_helper.cpp b/tests/stack_protector_test_helper.cpp
index 53a5e05..3f15a12 100644
--- a/tests/stack_protector_test_helper.cpp
+++ b/tests/stack_protector_test_helper.cpp
@@ -22,10 +22,5 @@
   // Without volatile, the generic x86/x86-64 targets don't write to the stack.
   volatile char* p = buf;
   int size = static_cast<int>(sizeof(buf) + 1);
-#if __x86_64__
-  // The generic x86-64 target leaves an 8-byte gap between `buf` and the stack guard.
-  // We only need to corrupt one byte though.
-  size += 8;
-#endif
   while ((p - buf) < size) *p++ = '\0';
 }
diff --git a/tests/stdatomic_test.cpp b/tests/stdatomic_test.cpp
index eb030bf..22e0c50 100644
--- a/tests/stdatomic_test.cpp
+++ b/tests/stdatomic_test.cpp
@@ -66,8 +66,6 @@
 TEST(stdatomic, atomic_is_lock_free) {
   atomic_char small;
   ASSERT_TRUE(atomic_is_lock_free(&small));
-#if defined(__clang__) || __GNUC_PREREQ(4, 7)
-  // Otherwise stdatomic.h doesn't handle this.
   atomic_intmax_t big;
   // atomic_intmax_t(size = 64) is not lock free on mips32.
 #if defined(__mips__) && !defined(__LP64__)
@@ -75,7 +73,6 @@
 #else
   ASSERT_TRUE(atomic_is_lock_free(&big));
 #endif
-#endif
 }
 
 TEST(stdatomic, atomic_flag) {
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index 7e82612..8747dfc 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -37,6 +37,24 @@
 #define STDIO_TEST stdio
 #endif
 
+static void AssertFileIs(FILE* fp, const char* expected, bool is_fmemopen = false) {
+  rewind(fp);
+
+  char line[1024];
+  ASSERT_EQ(line, fgets(line, sizeof(line), fp));
+  ASSERT_STREQ(expected, line);
+
+  if (is_fmemopen) {
+    // fmemopen appends a trailing NUL byte, which probably shouldn't show up as an
+    // extra empty line, but does on every C library I tested...
+    ASSERT_EQ(line, fgets(line, sizeof(line), fp));
+    ASSERT_STREQ("", line);
+  }
+
+  // Make sure there isn't anything else in the file.
+  ASSERT_EQ(nullptr, fgets(line, sizeof(line), fp)) << "junk at end of file: " << line;
+}
+
 TEST(STDIO_TEST, flockfile_18208568_stderr) {
   // Check that we have a _recursive_ mutex for flockfile.
   flockfile(stderr);
@@ -69,13 +87,7 @@
   rc = fprintf(fp, "hello\n");
   ASSERT_EQ(rc, 6);
 
-  rewind(fp);
-
-  char buf[16];
-  char* s = fgets(buf, sizeof(buf), fp);
-  ASSERT_TRUE(s != NULL);
-  ASSERT_STREQ("hello\n", s);
-
+  AssertFileIs(fp, "hello\n");
   fclose(fp);
 }
 
@@ -95,11 +107,7 @@
   FILE* tfile = fdopen(tf.fd, "r");
   ASSERT_TRUE(tfile != NULL);
 
-  char buf[7];
-  ASSERT_EQ(buf, fgets(buf, sizeof(buf), tfile));
-  ASSERT_STREQ("hello\n", buf);
-  // Make sure there isn't anything else in the file.
-  ASSERT_EQ(NULL, fgets(buf, sizeof(buf), tfile));
+  AssertFileIs(tfile, "hello\n");
   fclose(tfile);
 }
 
@@ -568,6 +576,17 @@
   ASSERT_EQ(ENOMEM, errno);
 }
 
+TEST(STDIO_TEST, fprintf) {
+  TemporaryFile tf;
+
+  FILE* tfile = fdopen(tf.fd, "r+");
+  ASSERT_TRUE(tfile != nullptr);
+
+  ASSERT_EQ(7, fprintf(tfile, "%d %s", 123, "abc"));
+  AssertFileIs(tfile, "123 abc");
+  fclose(tfile);
+}
+
 TEST(STDIO_TEST, fprintf_failures_7229520) {
   // http://b/7229520
   FILE* fp;
@@ -806,13 +825,7 @@
 
   ASSERT_STREQ("<abc>\n", buf);
 
-  rewind(fp);
-
-  char line[16];
-  char* s = fgets(line, sizeof(line), fp);
-  ASSERT_TRUE(s != NULL);
-  ASSERT_STREQ("<abc>\n", s);
-
+  AssertFileIs(fp, "<abc>\n", true);
   fclose(fp);
 }
 
@@ -820,13 +833,7 @@
   FILE* fp = fmemopen(nullptr, 128, "r+");
   ASSERT_NE(EOF, fputs("xyz\n", fp));
 
-  rewind(fp);
-
-  char line[16];
-  char* s = fgets(line, sizeof(line), fp);
-  ASSERT_TRUE(s != NULL);
-  ASSERT_STREQ("xyz\n", s);
-
+  AssertFileIs(fp, "xyz\n", true);
   fclose(fp);
 }
 
@@ -1196,15 +1203,10 @@
   }
 
   for (size_t i = 0; i < 256; ++i) {
-    rewind(fps[i]);
-
-    char buf[BUFSIZ];
-    ASSERT_TRUE(fgets(buf, sizeof(buf), fps[i]) != nullptr);
-
     char expected[BUFSIZ];
     snprintf(expected, sizeof(expected), "hello %zu!\n", i);
-    ASSERT_STREQ(expected, buf);
 
+    AssertFileIs(fps[i], expected);
     fclose(fps[i]);
     delete tfs[i];
   }
@@ -1297,3 +1299,33 @@
 
   fclose(fp);
 }
+
+TEST(STDIO_TEST, ctermid) {
+  ASSERT_STREQ("/dev/tty", ctermid(nullptr));
+
+  char buf[L_ctermid] = {};
+  ASSERT_EQ(buf, ctermid(buf));
+  ASSERT_STREQ("/dev/tty", buf);
+}
+
+TEST(STDIO_TEST, remove) {
+  struct stat sb;
+
+  TemporaryFile tf;
+  ASSERT_EQ(0, remove(tf.filename));
+  ASSERT_EQ(-1, lstat(tf.filename, &sb));
+  ASSERT_EQ(ENOENT, errno);
+
+  TemporaryDir td;
+  ASSERT_EQ(0, remove(td.dirname));
+  ASSERT_EQ(-1, lstat(td.dirname, &sb));
+  ASSERT_EQ(ENOENT, errno);
+
+  errno = 0;
+  ASSERT_EQ(-1, remove(tf.filename));
+  ASSERT_EQ(ENOENT, errno);
+
+  errno = 0;
+  ASSERT_EQ(-1, remove(td.dirname));
+  ASSERT_EQ(ENOENT, errno);
+}
diff --git a/tests/stdlib_test.cpp b/tests/stdlib_test.cpp
index 6ae6cda..773230f 100644
--- a/tests/stdlib_test.cpp
+++ b/tests/stdlib_test.cpp
@@ -514,3 +514,49 @@
   strtoull("123", NULL, 37);
   ASSERT_EQ(EINVAL, errno);
 }
+
+TEST(stdlib, getsubopt) {
+  char* const tokens[] = {
+    const_cast<char*>("a"),
+    const_cast<char*>("b"),
+    const_cast<char*>("foo"),
+    nullptr
+  };
+  std::string input = "a,b,foo=bar,a,unknown";
+  char* subopts = &input[0];
+  char* value = nullptr;
+
+  ASSERT_EQ(0, getsubopt(&subopts, tokens, &value));
+  ASSERT_EQ(nullptr, value);
+  ASSERT_EQ(1, getsubopt(&subopts, tokens, &value));
+  ASSERT_EQ(nullptr, value);
+  ASSERT_EQ(2, getsubopt(&subopts, tokens, &value));
+  ASSERT_STREQ("bar", value);
+  ASSERT_EQ(0, getsubopt(&subopts, tokens, &value));
+  ASSERT_EQ(nullptr, value);
+
+  ASSERT_EQ(-1, getsubopt(&subopts, tokens, &value));
+}
+
+TEST(stdlib, mblen) {
+  // "If s is a null pointer, mblen() shall return a non-zero or 0 value, if character encodings,
+  // respectively, do or do not have state-dependent encodings." We're always UTF-8.
+  EXPECT_EQ(0, mblen(nullptr, 1));
+
+  ASSERT_STREQ("C.UTF-8", setlocale(LC_ALL, "C.UTF-8"));
+
+  // 1-byte UTF-8.
+  EXPECT_EQ(1, mblen("abcdef", 6));
+  // 2-byte UTF-8.
+  EXPECT_EQ(2, mblen("\xc2\xa2" "cdef", 6));
+  // 3-byte UTF-8.
+  EXPECT_EQ(3, mblen("\xe2\x82\xac" "def", 6));
+  // 4-byte UTF-8.
+  EXPECT_EQ(4, mblen("\xf0\xa4\xad\xa2" "ef", 6));
+
+  // Illegal over-long sequence.
+  ASSERT_EQ(-1, mblen("\xf0\x82\x82\xac" "ef", 6));
+
+  // "mblen() shall ... return 0 (if s points to the null byte)".
+  EXPECT_EQ(0, mblen("", 1));
+}
diff --git a/tests/string_posix_strerror_r_test.cpp b/tests/string_posix_strerror_r_test.cpp
index ae3b41a..596684b 100644
--- a/tests/string_posix_strerror_r_test.cpp
+++ b/tests/string_posix_strerror_r_test.cpp
@@ -20,7 +20,7 @@
 #if defined(__GLIBC__)
 
 // At the time of writing, libcxx -- which is dragged in by gtest -- assumes
-// declarations from glibc of things that aren't available without __USE_GNU.
+// declarations from glibc of things that aren't available without _GNU_SOURCE.
 // This means we can't even build this test (which is a problem because that
 // means it doesn't get included in CTS).
 // For glibc 2.15, the symbols in question are:
diff --git a/tests/string_test.cpp b/tests/string_test.cpp
index 4b2cca2..763d65c 100644
--- a/tests/string_test.cpp
+++ b/tests/string_test.cpp
@@ -40,10 +40,10 @@
 #define STRLCAT_SUPPORTED
 #endif
 
-#define KB 1024
-#define SMALL 1*KB
-#define MEDIUM 4*KB
-#define LARGE 64*KB
+constexpr auto KB = 1024;
+constexpr auto SMALL = 1 * KB;
+constexpr auto MEDIUM = 4 * KB;
+constexpr auto LARGE = 64 * KB;
 
 static int signum(int i) {
   if (i < 0) {
@@ -163,7 +163,7 @@
 template<class Character>
 class StringTestState {
  public:
-  StringTestState(size_t MAX_LEN) : MAX_LEN(MAX_LEN), align1_index_(0), align2_index_(0) {
+  explicit StringTestState(size_t MAX_LEN) : MAX_LEN(MAX_LEN), align1_index_(0), align2_index_(0) {
     int max_alignment = 64;
 
     // TODO: fix the tests to not sometimes use twice their specified "MAX_LEN".
diff --git a/tests/sys_epoll_test.cpp b/tests/sys_epoll_test.cpp
index 6e7a807..f6be4af 100644
--- a/tests/sys_epoll_test.cpp
+++ b/tests/sys_epoll_test.cpp
@@ -40,6 +40,12 @@
   ASSERT_EQ(0, epoll_pwait(epoll_fd, events, 1, 1, &ss));
 }
 
+TEST(sys_epoll, epoll_create_invalid_size) {
+  errno = 0;
+  ASSERT_EQ(-1, epoll_create(0));
+  ASSERT_EQ(EINVAL, errno);
+}
+
 TEST(sys_epoll, epoll_event_data) {
   int epoll_fd = epoll_create(1);
   ASSERT_NE(-1, epoll_fd) << strerror(errno);
diff --git a/tests/sys_ptrace_test.cpp b/tests/sys_ptrace_test.cpp
new file mode 100644
index 0000000..9071acf
--- /dev/null
+++ b/tests/sys_ptrace_test.cpp
@@ -0,0 +1,202 @@
+/*
+ * 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.
+ */
+
+#include <sys/ptrace.h>
+
+#include <elf.h>
+#include <sched.h>
+#include <sys/prctl.h>
+#include <sys/uio.h>
+#include <sys/user.h>
+#include <unistd.h>
+
+#include <gtest/gtest.h>
+
+// Host libc does not define this.
+#ifndef TRAP_HWBKPT
+#define TRAP_HWBKPT 4
+#endif
+
+template<typename T>
+static void __attribute__((noreturn)) fork_child(unsigned cpu, T &data) {
+  // Extra precaution: make sure we go away if anything happens to our parent.
+  if (prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0) == -1) {
+    perror("prctl(PR_SET_PDEATHSIG)");
+    _exit(1);
+  }
+
+  cpu_set_t cpus;
+  CPU_ZERO(&cpus);
+  CPU_SET(cpu, &cpus);
+  if (sched_setaffinity(0, sizeof cpus, &cpus) == -1) {
+    perror("sched_setaffinity");
+    _exit(2);
+  }
+  if (ptrace(PTRACE_TRACEME, 0, nullptr, nullptr) == -1) {
+    perror("ptrace(PTRACE_TRACEME)");
+    _exit(3);
+  }
+
+  raise(SIGSTOP); // Synchronize with the tracer, let it set the watchpoint.
+
+  data = 1; // Now trigger the watchpoint.
+
+  _exit(0);
+}
+
+class ChildGuard {
+ public:
+  explicit ChildGuard(pid_t pid) : pid(pid) {}
+
+  ~ChildGuard() {
+    kill(pid, SIGKILL);
+    int status;
+    waitpid(pid, &status, 0);
+  }
+
+ private:
+  pid_t pid;
+};
+
+static bool are_watchpoints_supported(pid_t child) {
+#if defined(__arm__)
+  long capabilities;
+  long result = ptrace(PTRACE_GETHBPREGS, child, 0, &capabilities);
+  if (result == -1) {
+    EXPECT_EQ(EIO, errno);
+    return false;
+  }
+  return ((capabilities >> 8) & 0xff) > 0;
+#elif defined(__aarch64__)
+  user_hwdebug_state dreg_state;
+  iovec iov;
+  iov.iov_base = &dreg_state;
+  iov.iov_len = sizeof(dreg_state);
+
+  long result = ptrace(PTRACE_GETREGSET, child, NT_ARM_HW_WATCH, &iov);
+  if (result == -1) {
+    EXPECT_EQ(EINVAL, errno);
+    return false;
+  }
+  return (dreg_state.dbg_info & 0xff) > 0;
+#elif defined(__i386__) || defined(__x86_64__)
+  // We assume watchpoints are always supported on x86.
+  (void) child;
+  return true;
+#else
+  // TODO: mips support.
+  (void) child;
+  return false;
+#endif
+}
+
+static void set_watchpoint(pid_t child, const void *address, size_t size) {
+#if defined(__arm__) || defined(__aarch64__)
+  const unsigned byte_mask = (1 << size) - 1;
+  const unsigned type = 2; // Write.
+  const unsigned enable = 1;
+  const unsigned control = byte_mask << 5 | type << 3 | enable;
+
+#ifdef __arm__
+  ASSERT_EQ(0, ptrace(PTRACE_SETHBPREGS, child, -1, &address)) << strerror(errno);
+  ASSERT_EQ(0, ptrace(PTRACE_SETHBPREGS, child, -2, &control)) << strerror(errno);
+#else // aarch64
+  user_hwdebug_state dreg_state;
+  memset(&dreg_state, 0, sizeof dreg_state);
+  dreg_state.dbg_regs[0].addr = reinterpret_cast<uintptr_t>(address);
+  dreg_state.dbg_regs[0].ctrl = control;
+
+  iovec iov;
+  iov.iov_base = &dreg_state;
+  iov.iov_len = offsetof(user_hwdebug_state, dbg_regs) + sizeof(dreg_state.dbg_regs[0]);
+
+  ASSERT_EQ(0, ptrace(PTRACE_SETREGSET, child, NT_ARM_HW_WATCH, &iov)) << strerror(errno);
+#endif
+#elif defined(__i386__) || defined(__x86_64__)
+  ASSERT_EQ(0, ptrace(PTRACE_POKEUSER, child, offsetof(user, u_debugreg[0]), address)) << strerror(errno);
+  errno = 0;
+  unsigned data = ptrace(PTRACE_PEEKUSER, child, offsetof(user, u_debugreg[7]), nullptr);
+  ASSERT_EQ(0, errno);
+
+  const unsigned size_flag = (size == 8) ? 2 : size - 1;
+  const unsigned enable = 1;
+  const unsigned type = 1; // Write.
+
+  const unsigned mask = 3 << 18 | 3 << 16 | 1;
+  const unsigned value = size_flag << 18 | type << 16 | enable;
+  data &= mask;
+  data |= value;
+  ASSERT_EQ(0, ptrace(PTRACE_POKEUSER, child, offsetof(user, u_debugreg[7]), data)) << strerror(errno);
+#else
+  (void) child;
+  (void) address;
+  (void) size;
+#endif
+}
+
+template<typename T>
+static void run_watchpoint_test_impl(unsigned cpu) {
+  alignas(8) T data = 0;
+
+  pid_t child = fork();
+  ASSERT_NE(-1, child) << strerror(errno);
+  if (child == 0) fork_child(cpu, data);
+
+  ChildGuard guard(child);
+
+  int status;
+  ASSERT_EQ(child, waitpid(child, &status, __WALL)) << strerror(errno);
+  ASSERT_TRUE(WIFSTOPPED(status)) << "Status was: " << status;
+  ASSERT_EQ(SIGSTOP, WSTOPSIG(status)) << "Status was: " << status;
+
+  if (!are_watchpoints_supported(child)) return;
+
+  set_watchpoint(child, &data, sizeof data);
+
+  ASSERT_EQ(0, ptrace(PTRACE_CONT, child, nullptr, nullptr)) << strerror(errno);
+  ASSERT_EQ(child, waitpid(child, &status, __WALL)) << strerror(errno);
+  ASSERT_TRUE(WIFSTOPPED(status)) << "Status was: " << status;
+  ASSERT_EQ(SIGTRAP, WSTOPSIG(status)) << "Status was: " << status;
+
+  siginfo_t siginfo;
+  ASSERT_EQ(0, ptrace(PTRACE_GETSIGINFO, child, nullptr, &siginfo)) << strerror(errno);
+  ASSERT_EQ(TRAP_HWBKPT, siginfo.si_code);
+#if defined(__arm__) || defined(__aarch64__)
+  ASSERT_EQ(&data, siginfo.si_addr);
+#endif
+}
+
+static void run_watchpoint_test(unsigned cpu) {
+  run_watchpoint_test_impl<uint8_t>(cpu);
+  run_watchpoint_test_impl<uint16_t>(cpu);
+  run_watchpoint_test_impl<uint32_t>(cpu);
+#if __LP64__
+  run_watchpoint_test_impl<uint64_t>(cpu);
+#endif
+}
+
+// Test watchpoint API. The test is considered successful if our watchpoints get hit OR the
+// system reports that watchpoint support is not present. We run the test for different
+// watchpoint sizes, while pinning the process to each cpu in turn, for better coverage.
+TEST(ptrace, watchpoint_stress) {
+  cpu_set_t available_cpus;
+  ASSERT_EQ(0, sched_getaffinity(0, sizeof available_cpus, &available_cpus));
+
+  for (size_t cpu = 0; cpu < CPU_SETSIZE; ++cpu) {
+    if (!CPU_ISSET(cpu, &available_cpus)) continue;
+    run_watchpoint_test(cpu);
+  }
+}
diff --git a/tests/sys_quota_test.cpp b/tests/sys_quota_test.cpp
new file mode 100644
index 0000000..e23207b
--- /dev/null
+++ b/tests/sys_quota_test.cpp
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+
+#include <sys/quota.h>
+
+#include <gtest/gtest.h>
+
+TEST(sys_quota, quotactl_dqblk) {
+  // We don't even have kernels with CONFIG_QUOTA enabled right now.
+  // This just tests that we can compile reasonable code.
+  dqblk current;
+  quotactl(QCMD(Q_GETQUOTA, USRQUOTA), "/", getuid(), reinterpret_cast<char*>(&current));
+}
+
+TEST(sys_quota, quotactl_dqinfo) {
+  // We don't even have kernels with CONFIG_QUOTA enabled right now.
+  // This just tests that we can compile reasonable code.
+  dqinfo current;
+  quotactl(QCMD(Q_GETINFO, USRQUOTA), "/", 0, reinterpret_cast<char*>(&current));
+}
diff --git a/tests/sys_syscall_test.cpp b/tests/sys_syscall_test.cpp
index 9c5e350..68a7167 100644
--- a/tests/sys_syscall_test.cpp
+++ b/tests/sys_syscall_test.cpp
@@ -21,3 +21,10 @@
 TEST(unistd, syscall) {
   ASSERT_EQ(getpid(), syscall(SYS_getpid));
 }
+
+// https://code.google.com/p/android/issues/detail?id=215853
+#if defined(__LP64__)
+  #if defined(SYS_mmap2)
+    #error SYS_mmap2 should not be defined for LP64
+  #endif
+#endif
diff --git a/tests/sys_time_test.cpp b/tests/sys_time_test.cpp
index 18fbe10..e041ba0 100644
--- a/tests/sys_time_test.cpp
+++ b/tests/sys_time_test.cpp
@@ -22,30 +22,113 @@
 
 #include "TemporaryFile.h"
 
-TEST(sys_time, utimes) {
-  timeval tv[2];
-  memset(&tv, 0, sizeof(tv));
+// http://b/11383777
+TEST(sys_time, utimes_nullptr) {
+  TemporaryFile tf;
+  ASSERT_EQ(0, utimes(tf.filename, nullptr));
+}
+
+TEST(sys_time, utimes_EINVAL) {
+  TemporaryFile tf;
+
+  timeval tv[2] = {};
 
   tv[0].tv_usec = -123;
-  ASSERT_EQ(-1, utimes("/", tv));
+  ASSERT_EQ(-1, utimes(tf.filename, tv));
   ASSERT_EQ(EINVAL, errno);
   tv[0].tv_usec = 1234567;
-  ASSERT_EQ(-1, utimes("/", tv));
+  ASSERT_EQ(-1, utimes(tf.filename, tv));
   ASSERT_EQ(EINVAL, errno);
+
   tv[0].tv_usec = 0;
 
   tv[1].tv_usec = -123;
-  ASSERT_EQ(-1, utimes("/", tv));
+  ASSERT_EQ(-1, utimes(tf.filename, tv));
   ASSERT_EQ(EINVAL, errno);
   tv[1].tv_usec = 1234567;
-  ASSERT_EQ(-1, utimes("/", tv));
+  ASSERT_EQ(-1, utimes(tf.filename, tv));
   ASSERT_EQ(EINVAL, errno);
 }
 
-// http://b/11383777
-TEST(sys_time, utimes_NULL) {
+TEST(sys_time, futimes_nullptr) {
   TemporaryFile tf;
-  ASSERT_EQ(0, utimes(tf.filename, NULL));
+  ASSERT_EQ(0, futimes(tf.fd, nullptr));
+}
+
+TEST(sys_time, futimes_EINVAL) {
+  TemporaryFile tf;
+
+  timeval tv[2] = {};
+
+  tv[0].tv_usec = -123;
+  ASSERT_EQ(-1, futimes(tf.fd, tv));
+  ASSERT_EQ(EINVAL, errno);
+  tv[0].tv_usec = 1234567;
+  ASSERT_EQ(-1, futimes(tf.fd, tv));
+  ASSERT_EQ(EINVAL, errno);
+
+  tv[0].tv_usec = 0;
+
+  tv[1].tv_usec = -123;
+  ASSERT_EQ(-1, futimes(tf.fd, tv));
+  ASSERT_EQ(EINVAL, errno);
+  tv[1].tv_usec = 1234567;
+  ASSERT_EQ(-1, futimes(tf.fd, tv));
+  ASSERT_EQ(EINVAL, errno);
+}
+
+TEST(sys_time, futimesat_nullptr) {
+  TemporaryFile tf;
+  ASSERT_EQ(0, futimesat(AT_FDCWD, tf.filename, nullptr));
+}
+
+TEST(sys_time, futimesat_EINVAL) {
+  TemporaryFile tf;
+
+  timeval tv[2] = {};
+
+  tv[0].tv_usec = -123;
+  ASSERT_EQ(-1, futimesat(AT_FDCWD, tf.filename, tv));
+  ASSERT_EQ(EINVAL, errno);
+  tv[0].tv_usec = 1234567;
+  ASSERT_EQ(-1, futimesat(AT_FDCWD, tf.filename, tv));
+  ASSERT_EQ(EINVAL, errno);
+
+  tv[0].tv_usec = 0;
+
+  tv[1].tv_usec = -123;
+  ASSERT_EQ(-1, futimesat(AT_FDCWD, tf.filename, tv));
+  ASSERT_EQ(EINVAL, errno);
+  tv[1].tv_usec = 1234567;
+  ASSERT_EQ(-1, futimesat(AT_FDCWD, tf.filename, tv));
+  ASSERT_EQ(EINVAL, errno);
+}
+
+TEST(sys_time, lutimes_nullptr) {
+  TemporaryFile tf;
+  ASSERT_EQ(0, lutimes(tf.filename, nullptr));
+}
+
+TEST(sys_time, lutimes_EINVAL) {
+  TemporaryFile tf;
+
+  timeval tv[2] = {};
+
+  tv[0].tv_usec = -123;
+  ASSERT_EQ(-1, lutimes(tf.filename, tv));
+  ASSERT_EQ(EINVAL, errno);
+  tv[0].tv_usec = 1234567;
+  ASSERT_EQ(-1, lutimes(tf.filename, tv));
+  ASSERT_EQ(EINVAL, errno);
+
+  tv[0].tv_usec = 0;
+
+  tv[1].tv_usec = -123;
+  ASSERT_EQ(-1, lutimes(tf.filename, tv));
+  ASSERT_EQ(EINVAL, errno);
+  tv[1].tv_usec = 1234567;
+  ASSERT_EQ(-1, lutimes(tf.filename, tv));
+  ASSERT_EQ(EINVAL, errno);
 }
 
 TEST(sys_time, gettimeofday) {
diff --git a/tests/time_test.cpp b/tests/time_test.cpp
index 6cdabd2..028a359 100644
--- a/tests/time_test.cpp
+++ b/tests/time_test.cpp
@@ -176,6 +176,27 @@
 #endif
 }
 
+TEST(time, strftime_l) {
+  locale_t cloc = newlocale(LC_ALL, "C.UTF-8", 0);
+  locale_t old_locale = uselocale(cloc);
+
+  setenv("TZ", "UTC", 1);
+
+  struct tm t;
+  memset(&t, 0, sizeof(tm));
+  t.tm_year = 200;
+  t.tm_mon = 2;
+  t.tm_mday = 10;
+
+  // Date and time as text.
+  char buf[64];
+  EXPECT_EQ(24U, strftime_l(buf, sizeof(buf), "%c", &t, cloc));
+  EXPECT_STREQ("Sun Mar 10 00:00:00 2100", buf);
+
+  uselocale(old_locale);
+  freelocale(cloc);
+}
+
 TEST(time, strptime) {
   setenv("TZ", "UTC", 1);
 
@@ -273,7 +294,7 @@
   }
 
  public:
-  Counter(void (*fn)(sigval_t)) : value(0), timer_valid(false) {
+  explicit Counter(void (*fn)(sigval_t)) : value(0), timer_valid(false) {
     memset(&se, 0, sizeof(se));
     se.sigev_notify = SIGEV_THREAD;
     se.sigev_notify_function = fn;
@@ -573,3 +594,10 @@
   timespec out;
   ASSERT_EQ(EINVAL, clock_nanosleep(-1, 0, &in, &out));
 }
+
+TEST(time, clock_nanosleep_thread_cputime_id) {
+  timespec in;
+  in.tv_sec = 1;
+  in.tv_nsec = 0;
+  ASSERT_EQ(EINVAL, clock_nanosleep(CLOCK_THREAD_CPUTIME_ID, 0, &in, nullptr));
+}
diff --git a/tests/uniqueptr_test.cpp b/tests/uniqueptr_test.cpp
deleted file mode 100644
index 4b6608a..0000000
--- a/tests/uniqueptr_test.cpp
+++ /dev/null
@@ -1,101 +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 <gtest/gtest.h>
-
-#include <private/UniquePtr.h>
-
-static int cCount = 0;
-struct C {
-  C() { ++cCount; }
-  ~C() { --cCount; }
-};
-
-static bool freed = false;
-struct Freer {
-  void operator() (int* p) {
-    ASSERT_EQ(123, *p);
-    free(p);
-    freed = true;
-  }
-};
-
-TEST(UniquePtr, smoke) {
-  //
-  // UniquePtr<T> tests...
-  //
-
-  // Can we free a single object?
-  {
-    UniquePtr<C> c(new C);
-    ASSERT_TRUE(cCount == 1);
-  }
-  ASSERT_TRUE(cCount == 0);
-  // Does release work?
-  C* rawC;
-  {
-      UniquePtr<C> c(new C);
-      ASSERT_TRUE(cCount == 1);
-      rawC = c.release();
-  }
-  ASSERT_TRUE(cCount == 1);
-  delete rawC;
-  // Does reset work?
-  {
-      UniquePtr<C> c(new C);
-      ASSERT_TRUE(cCount == 1);
-      c.reset(new C);
-      ASSERT_TRUE(cCount == 1);
-  }
-  ASSERT_TRUE(cCount == 0);
-
-  //
-  // UniquePtr<T[]> tests...
-  //
-
-  // Can we free an array?
-  {
-      UniquePtr<C[]> cs(new C[4]);
-      ASSERT_TRUE(cCount == 4);
-  }
-  ASSERT_TRUE(cCount == 0);
-  // Does release work?
-  {
-      UniquePtr<C[]> c(new C[4]);
-      ASSERT_TRUE(cCount == 4);
-      rawC = c.release();
-  }
-  ASSERT_TRUE(cCount == 4);
-  delete[] rawC;
-  // Does reset work?
-  {
-      UniquePtr<C[]> c(new C[4]);
-      ASSERT_TRUE(cCount == 4);
-      c.reset(new C[2]);
-      ASSERT_TRUE(cCount == 2);
-  }
-  ASSERT_TRUE(cCount == 0);
-
-  //
-  // Custom deleter tests...
-  //
-  ASSERT_TRUE(!freed);
-  {
-      UniquePtr<int, Freer> i(reinterpret_cast<int*>(malloc(sizeof(int))));
-      *i = 123;
-  }
-  ASSERT_TRUE(freed);
-}
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp
index ccf4dcc..3a87e88 100644
--- a/tests/unistd_test.cpp
+++ b/tests/unistd_test.cpp
@@ -25,6 +25,7 @@
 #include <fcntl.h>
 #include <limits.h>
 #include <stdint.h>
+#include <sys/capability.h>
 #include <sys/param.h>
 #include <sys/syscall.h>
 #include <sys/types.h>
@@ -57,14 +58,24 @@
 TEST(UNISTD_TEST, brk) {
   void* initial_break = get_brk();
 
-  // The kernel aligns the break to a page.
   void* new_break = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(initial_break) + 1);
-  ASSERT_EQ(0, brk(new_break));
-  ASSERT_GE(get_brk(), new_break);
+  int ret = brk(new_break);
+  if (ret == -1) {
+    ASSERT_EQ(errno, ENOMEM);
+  } else {
+    ASSERT_EQ(0, ret);
+    ASSERT_GE(get_brk(), new_break);
+  }
 
+  // Expand by a full page to force the mapping to expand
   new_break = page_align(reinterpret_cast<uintptr_t>(initial_break) + sysconf(_SC_PAGE_SIZE));
-  ASSERT_EQ(0, brk(new_break));
-  ASSERT_EQ(get_brk(), new_break);
+  ret = brk(new_break);
+  if (ret == -1) {
+    ASSERT_EQ(errno, ENOMEM);
+  } else {
+    ASSERT_EQ(0, ret);
+    ASSERT_EQ(get_brk(), new_break);
+  }
 }
 
 TEST(UNISTD_TEST, brk_ENOMEM) {
@@ -598,8 +609,8 @@
   EXPECT_GT(_POSIX_THREAD_DESTRUCTOR_ITERATIONS, 0);
   EXPECT_EQ(_POSIX_THREAD_KEYS_MAX, 128);
   EXPECT_EQ(_POSIX_VERSION, _POSIX_THREAD_PRIORITY_SCHEDULING);
-  EXPECT_EQ(_POSIX_VERSION, _POSIX_THREAD_PRIO_INHERIT);
-  EXPECT_EQ(_POSIX_VERSION, _POSIX_THREAD_PRIO_PROTECT);
+  EXPECT_EQ(-1, _POSIX_THREAD_PRIO_INHERIT);
+  EXPECT_EQ(-1, _POSIX_THREAD_PRIO_PROTECT);
   EXPECT_EQ(-1, _POSIX_THREAD_ROBUST_PRIO_PROTECT);
   EXPECT_EQ(_POSIX_VERSION, _POSIX_THREAD_SAFE_FUNCTIONS);
   EXPECT_EQ(-1, _POSIX_THREAD_SPORADIC_SERVER);
@@ -661,7 +672,7 @@
 #endif // defined(__BIONIC__)
 }
 
-#define VERIFY_SYSCONF_NOT_SUPPORT(name) VerifySysconf(name, #name, [](long v){return v == -1;})
+#define VERIFY_SYSCONF_UNSUPPORTED(name) VerifySysconf(name, #name, [](long v){return v == -1;})
 
 // sysconf() means unlimited when it returns -1 with errno unchanged.
 #define VERIFY_SYSCONF_POSITIVE(name) \
@@ -693,9 +704,9 @@
   VERIFY_SYSCONF_POSITIVE(_SC_OPEN_MAX);
   VERIFY_SYSCONF_POSITIVE(_SC_PASS_MAX);
   VERIFY_SYSCONF_POSIX_VERSION(_SC_2_C_BIND);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_2_FORT_DEV);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_2_FORT_RUN);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_2_UPE);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_2_FORT_DEV);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_2_FORT_RUN);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_2_UPE);
   VERIFY_SYSCONF_POSITIVE(_SC_JOB_CONTROL);
   VERIFY_SYSCONF_POSITIVE(_SC_SAVED_IDS);
   VERIFY_SYSCONF_POSIX_VERSION(_SC_VERSION);
@@ -742,20 +753,20 @@
   VERIFY_SYSCONF_POSIX_VERSION(_SC_THREAD_ATTR_STACKADDR);
   VERIFY_SYSCONF_POSIX_VERSION(_SC_THREAD_ATTR_STACKSIZE);
   VERIFY_SYSCONF_POSIX_VERSION(_SC_THREAD_PRIORITY_SCHEDULING);
-  VERIFY_SYSCONF_POSIX_VERSION(_SC_THREAD_PRIO_INHERIT);
-  VERIFY_SYSCONF_POSIX_VERSION(_SC_THREAD_PRIO_PROTECT);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_THREAD_PRIO_INHERIT);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_THREAD_PRIO_PROTECT);
   VERIFY_SYSCONF_POSIX_VERSION(_SC_THREAD_SAFE_FUNCTIONS);
   VERIFY_SYSCONF_POSITIVE(_SC_NPROCESSORS_CONF);
   VERIFY_SYSCONF_POSITIVE(_SC_NPROCESSORS_ONLN);
   VERIFY_SYSCONF_POSITIVE(_SC_PHYS_PAGES);
   VERIFY_SYSCONF_POSITIVE(_SC_AVPHYS_PAGES);
   VERIFY_SYSCONF_POSIX_VERSION(_SC_MONOTONIC_CLOCK);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_2_PBS);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_2_PBS_ACCOUNTING);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_2_PBS_CHECKPOINT);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_2_PBS_LOCATE);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_2_PBS_MESSAGE);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_2_PBS_TRACK);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_2_PBS);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_2_PBS_ACCOUNTING);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_2_PBS_CHECKPOINT);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_2_PBS_LOCATE);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_2_PBS_MESSAGE);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_2_PBS_TRACK);
   VERIFY_SYSCONF_POSIX_VERSION(_SC_CLOCK_SELECTION);
   VERIFY_SYSCONF_POSITIVE(_SC_HOST_NAME_MAX);
   VERIFY_SYSCONF_POSIX_VERSION(_SC_IPV6);
@@ -763,64 +774,64 @@
   VERIFY_SYSCONF_POSIX_VERSION(_SC_READER_WRITER_LOCKS);
   VERIFY_SYSCONF_POSITIVE(_SC_REGEXP);
   VERIFY_SYSCONF_POSITIVE(_SC_SHELL);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_SPORADIC_SERVER);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_SPORADIC_SERVER);
   VERIFY_SYSCONF_POSITIVE(_SC_SYMLOOP_MAX);
   VERIFY_SYSCONF_POSIX_VERSION(_SC_THREAD_CPUTIME);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_THREAD_SPORADIC_SERVER);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_THREAD_SPORADIC_SERVER);
   VERIFY_SYSCONF_POSIX_VERSION(_SC_TIMEOUTS);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_TRACE);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_TRACE_EVENT_FILTER);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_TRACE_EVENT_NAME_MAX);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_TRACE_INHERIT);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_TRACE_LOG);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_TRACE_NAME_MAX);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_TRACE_SYS_MAX);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_TRACE_USER_EVENT_MAX);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_TYPED_MEMORY_OBJECTS);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_XOPEN_STREAMS);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_TRACE);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_TRACE_EVENT_FILTER);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_TRACE_EVENT_NAME_MAX);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_TRACE_INHERIT);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_TRACE_LOG);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_TRACE_NAME_MAX);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_TRACE_SYS_MAX);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_TRACE_USER_EVENT_MAX);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_TYPED_MEMORY_OBJECTS);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_XOPEN_STREAMS);
 
 #if defined(__LP64__)
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_V7_ILP32_OFF32);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_V7_ILP32_OFFBIG);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_V7_ILP32_OFF32);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_V7_ILP32_OFFBIG);
   VERIFY_SYSCONF_POSITIVE(_SC_V7_LP64_OFF64);
   VERIFY_SYSCONF_POSITIVE(_SC_V7_LPBIG_OFFBIG);
 #else
   VERIFY_SYSCONF_POSITIVE(_SC_V7_ILP32_OFF32);
 #if defined(__BIONIC__)
   // bionic does not support 64 bits off_t type on 32bit machine.
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_V7_ILP32_OFFBIG);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_V7_ILP32_OFFBIG);
 #endif
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_V7_LP64_OFF64);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_V7_LPBIG_OFFBIG);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_V7_LP64_OFF64);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_V7_LPBIG_OFFBIG);
 #endif
 
 #if defined(__BIONIC__)
   // Tests can only run on bionic, as bionic and glibc have different support for these options.
   // Below options are not supported on bionic yet.
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_ASYNCHRONOUS_IO);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_BARRIERS);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_MESSAGE_PASSING);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_PRIORITIZED_IO);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_SHARED_MEMORY_OBJECTS);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_SPAWN);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_SPIN_LOCKS);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_THREAD_PROCESS_SHARED);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_THREAD_ROBUST_PRIO_INHERIT);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_THREAD_ROBUST_PRIO_PROTECT);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_ASYNCHRONOUS_IO);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_BARRIERS);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_MESSAGE_PASSING);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_PRIORITIZED_IO);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_SHARED_MEMORY_OBJECTS);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_SPAWN);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_SPIN_LOCKS);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_THREAD_PROCESS_SHARED);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_THREAD_ROBUST_PRIO_INHERIT);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_THREAD_ROBUST_PRIO_PROTECT);
 
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_2_C_DEV);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_2_CHAR_TERM);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_2_LOCALEDEF);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_2_SW_DEV);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_2_VERSION);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_2_C_DEV);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_2_CHAR_TERM);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_2_LOCALEDEF);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_2_SW_DEV);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_2_VERSION);
 
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_XOPEN_CRYPT);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_XOPEN_ENH_I18N);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_XOPEN_LEGACY);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_XOPEN_REALTIME);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_XOPEN_REALTIME_THREADS);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_XOPEN_SHM);
-  VERIFY_SYSCONF_NOT_SUPPORT(_SC_XOPEN_UUCP);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_XOPEN_CRYPT);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_XOPEN_ENH_I18N);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_XOPEN_LEGACY);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_XOPEN_REALTIME);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_XOPEN_REALTIME_THREADS);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_XOPEN_SHM);
+  VERIFY_SYSCONF_UNSUPPORTED(_SC_XOPEN_UUCP);
 #endif // defined(__BIONIC__)
 }
 
@@ -986,3 +997,46 @@
   ASSERT_EQ(file_size/2, lseek64(tf.fd, file_size/2, SEEK_SET));
   ASSERT_EQ(0, lockf64(tf.fd, F_TLOCK, file_size/2));
 }
+
+TEST(UNISTD_TEST, getdomainname) {
+  struct utsname u;
+  ASSERT_EQ(0, uname(&u));
+
+  char buf[sizeof(u.domainname)];
+  ASSERT_EQ(0, getdomainname(buf, sizeof(buf)));
+  EXPECT_STREQ(u.domainname, buf);
+
+#if defined(__BIONIC__)
+  // bionic and glibc have different behaviors when len is too small
+  ASSERT_EQ(-1, getdomainname(buf, strlen(u.domainname)));
+  EXPECT_EQ(EINVAL, errno);
+#endif
+}
+
+TEST(UNISTD_TEST, setdomainname) {
+  __user_cap_header_struct header;
+  memset(&header, 0, sizeof(header));
+  header.version = _LINUX_CAPABILITY_VERSION_3;
+
+  __user_cap_data_struct old_caps[_LINUX_CAPABILITY_U32S_3];
+  ASSERT_EQ(0, capget(&header, &old_caps[0]));
+
+  auto admin_idx = CAP_TO_INDEX(CAP_SYS_ADMIN);
+  auto admin_mask = CAP_TO_MASK(CAP_SYS_ADMIN);
+  bool has_admin = old_caps[admin_idx].effective & admin_mask;
+  if (has_admin) {
+    __user_cap_data_struct new_caps[_LINUX_CAPABILITY_U32S_3];
+    memcpy(new_caps, old_caps, sizeof(new_caps));
+    new_caps[admin_idx].effective &= ~admin_mask;
+
+    ASSERT_EQ(0, capset(&header, &new_caps[0])) << "failed to drop admin privileges";
+  }
+
+  const char* name = "newdomainname";
+  ASSERT_EQ(-1, setdomainname(name, strlen(name)));
+  ASSERT_EQ(EPERM, errno);
+
+  if (has_admin) {
+    ASSERT_EQ(0, capset(&header, &old_caps[0])) << "failed to restore admin privileges";
+  }
+}
diff --git a/tests/utils.h b/tests/utils.h
index f8e0039..08e8cea 100644
--- a/tests/utils.h
+++ b/tests/utils.h
@@ -122,4 +122,9 @@
 // The absolute path to the executable
 const std::string& get_executable_path();
 
+// Access to argc/argv/envp
+int get_argc();
+char** get_argv();
+char** get_envp();
+
 #endif
diff --git a/tests/wchar_test.cpp b/tests/wchar_test.cpp
index e86d56d..000dc98 100644
--- a/tests/wchar_test.cpp
+++ b/tests/wchar_test.cpp
@@ -22,7 +22,7 @@
 #include <stdint.h>
 #include <wchar.h>
 
-#define NUM_WCHARS(num_bytes) (num_bytes/sizeof(wchar_t))
+#define NUM_WCHARS(num_bytes) ((num_bytes)/sizeof(wchar_t))
 
 TEST(wchar, sizeof_wchar_t) {
   EXPECT_EQ(4U, sizeof(wchar_t));
diff --git a/tests/wctype_test.cpp b/tests/wctype_test.cpp
new file mode 100644
index 0000000..fe2e374
--- /dev/null
+++ b/tests/wctype_test.cpp
@@ -0,0 +1,199 @@
+/*
+ * 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.
+ */
+
+#include <wctype.h>
+
+#include <gtest/gtest.h>
+
+class UtfLocale {
+ public:
+  UtfLocale() : l(newlocale(LC_ALL, "C.UTF-8", 0)) {}
+  ~UtfLocale() { freelocale(l); }
+  locale_t l;
+};
+
+static void TestIsWideFn(int fn(wint_t),
+                         int fn_l(wint_t, locale_t),
+                         const wchar_t* trues,
+                         const wchar_t* falses) {
+  UtfLocale l;
+  for (const wchar_t* p = trues; *p; ++p) {
+    EXPECT_TRUE(fn(*p)) << *p;
+    EXPECT_TRUE(fn_l(*p, l.l)) << *p;
+  }
+  for (const wchar_t* p = falses; *p; ++p) {
+    EXPECT_FALSE(fn(*p)) << *p;
+    EXPECT_FALSE(fn_l(*p, l.l)) << *p;
+  }
+}
+
+TEST(wctype, iswalnum) {
+  TestIsWideFn(iswalnum, iswalnum_l, L"1aA", L"! \b");
+}
+
+TEST(wctype, iswalpha) {
+  TestIsWideFn(iswalpha, iswalpha_l, L"aA", L"1! \b");
+}
+
+TEST(wctype, iswblank) {
+  TestIsWideFn(iswblank, iswblank_l, L" \t", L"1aA!\b");
+}
+
+TEST(wctype, iswcntrl) {
+  TestIsWideFn(iswcntrl, iswcntrl_l, L"\b", L"1aA! ");
+}
+
+TEST(wctype, iswdigit) {
+  TestIsWideFn(iswdigit, iswdigit_l, L"1", L"aA! \b");
+}
+
+TEST(wctype, iswgraph) {
+  TestIsWideFn(iswgraph, iswgraph_l, L"1aA!", L" \b");
+}
+
+TEST(wctype, iswlower) {
+  TestIsWideFn(iswlower, iswlower_l, L"a", L"1A! \b");
+}
+
+TEST(wctype, iswprint) {
+  TestIsWideFn(iswprint, iswprint_l, L"1aA! ", L"\b");
+}
+
+TEST(wctype, iswpunct) {
+  TestIsWideFn(iswpunct, iswpunct_l, L"!", L"1aA \b");
+}
+
+TEST(wctype, iswspace) {
+  TestIsWideFn(iswspace, iswspace_l, L" \f\t", L"1aA!\b");
+}
+
+TEST(wctype, iswupper) {
+  TestIsWideFn(iswupper, iswupper_l, L"A", L"1a! \b");
+}
+
+TEST(wctype, iswxdigit) {
+  TestIsWideFn(iswxdigit, iswxdigit_l, L"01aA", L"xg! \b");
+}
+
+TEST(wctype, towlower) {
+  EXPECT_EQ(wint_t('!'), towlower(L'!'));
+  EXPECT_EQ(wint_t('a'), towlower(L'a'));
+  EXPECT_EQ(wint_t('a'), towlower(L'A'));
+}
+
+TEST(wctype, towlower_l) {
+  UtfLocale l;
+  EXPECT_EQ(wint_t('!'), towlower_l(L'!', l.l));
+  EXPECT_EQ(wint_t('a'), towlower_l(L'a', l.l));
+  EXPECT_EQ(wint_t('a'), towlower_l(L'A', l.l));
+}
+
+TEST(wctype, towupper) {
+  EXPECT_EQ(wint_t('!'), towupper(L'!'));
+  EXPECT_EQ(wint_t('A'), towupper(L'a'));
+  EXPECT_EQ(wint_t('A'), towupper(L'A'));
+}
+
+TEST(wctype, towupper_l) {
+  UtfLocale l;
+  EXPECT_EQ(wint_t('!'), towupper_l(L'!', l.l));
+  EXPECT_EQ(wint_t('A'), towupper_l(L'a', l.l));
+  EXPECT_EQ(wint_t('A'), towupper_l(L'A', l.l));
+}
+
+TEST(wctype, wctype) {
+  EXPECT_TRUE(wctype("alnum") != 0);
+  EXPECT_TRUE(wctype("alpha") != 0);
+  EXPECT_TRUE(wctype("blank") != 0);
+  EXPECT_TRUE(wctype("cntrl") != 0);
+  EXPECT_TRUE(wctype("digit") != 0);
+  EXPECT_TRUE(wctype("graph") != 0);
+  EXPECT_TRUE(wctype("lower") != 0);
+  EXPECT_TRUE(wctype("print") != 0);
+  EXPECT_TRUE(wctype("punct") != 0);
+  EXPECT_TRUE(wctype("space") != 0);
+  EXPECT_TRUE(wctype("upper") != 0);
+  EXPECT_TRUE(wctype("xdigit") != 0);
+
+  EXPECT_TRUE(wctype("monkeys") == 0);
+}
+
+TEST(wctype, wctype_l) {
+  UtfLocale l;
+  EXPECT_TRUE(wctype_l("alnum", l.l) != 0);
+  EXPECT_TRUE(wctype_l("alpha", l.l) != 0);
+  EXPECT_TRUE(wctype_l("blank", l.l) != 0);
+  EXPECT_TRUE(wctype_l("cntrl", l.l) != 0);
+  EXPECT_TRUE(wctype_l("digit", l.l) != 0);
+  EXPECT_TRUE(wctype_l("graph", l.l) != 0);
+  EXPECT_TRUE(wctype_l("lower", l.l) != 0);
+  EXPECT_TRUE(wctype_l("print", l.l) != 0);
+  EXPECT_TRUE(wctype_l("punct", l.l) != 0);
+  EXPECT_TRUE(wctype_l("space", l.l) != 0);
+  EXPECT_TRUE(wctype_l("upper", l.l) != 0);
+  EXPECT_TRUE(wctype_l("xdigit", l.l) != 0);
+
+  EXPECT_TRUE(wctype_l("monkeys", l.l) == 0);
+}
+
+TEST(wctype, iswctype) {
+  EXPECT_TRUE(iswctype(L'a', wctype("alnum")));
+  EXPECT_TRUE(iswctype(L'1', wctype("alnum")));
+  EXPECT_FALSE(iswctype(L' ', wctype("alnum")));
+
+  EXPECT_EQ(0, iswctype(WEOF, wctype("alnum")));
+}
+
+TEST(wctype, iswctype_l) {
+  UtfLocale l;
+  EXPECT_TRUE(iswctype_l(L'a', wctype_l("alnum", l.l), l.l));
+  EXPECT_TRUE(iswctype_l(L'1', wctype_l("alnum", l.l), l.l));
+  EXPECT_FALSE(iswctype_l(L' ', wctype_l("alnum", l.l), l.l));
+
+  EXPECT_EQ(0, iswctype_l(WEOF, wctype_l("alnum", l.l), l.l));
+}
+
+TEST(wctype, towctrans) {
+  EXPECT_TRUE(wctrans("tolower") != 0);
+  EXPECT_TRUE(wctrans("toupper") != 0);
+
+  EXPECT_TRUE(wctrans("monkeys") == 0);
+}
+
+TEST(wctype, towctrans_l) {
+  UtfLocale l;
+  EXPECT_TRUE(wctrans_l("tolower", l.l) != 0);
+  EXPECT_TRUE(wctrans_l("toupper", l.l) != 0);
+
+  EXPECT_TRUE(wctrans_l("monkeys", l.l) == 0);
+}
+
+TEST(wctype, wctrans) {
+  EXPECT_EQ(wint_t('a'), towctrans(L'A', wctrans("tolower")));
+  EXPECT_EQ(WEOF, towctrans(WEOF, wctrans("tolower")));
+
+  EXPECT_EQ(wint_t('A'), towctrans(L'a', wctrans("toupper")));
+  EXPECT_EQ(WEOF, towctrans(WEOF, wctrans("toupper")));
+}
+
+TEST(wctype, wctrans_l) {
+  UtfLocale l;
+  EXPECT_EQ(wint_t('a'), towctrans_l(L'A', wctrans_l("tolower", l.l), l.l));
+  EXPECT_EQ(WEOF, towctrans_l(WEOF, wctrans_l("tolower", l.l), l.l));
+
+  EXPECT_EQ(wint_t('A'), towctrans_l(L'a', wctrans_l("toupper", l.l), l.l));
+  EXPECT_EQ(WEOF, towctrans_l(WEOF, wctrans_l("toupper", l.l), l.l));
+}
diff --git a/tools/Android.bp b/tools/Android.bp
new file mode 100644
index 0000000..b44c296
--- /dev/null
+++ b/tools/Android.bp
@@ -0,0 +1 @@
+subdirs = ["*"]
diff --git a/tools/relocation_packer/Android.bp b/tools/relocation_packer/Android.bp
new file mode 100644
index 0000000..2907b31
--- /dev/null
+++ b/tools/relocation_packer/Android.bp
@@ -0,0 +1,84 @@
+//
+// 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.
+//
+
+cc_defaults {
+    name: "relocation_packer_flags",
+    cppflags: [
+        "-Wall",
+        "-Wextra",
+        "-Wunused",
+        "-Werror",
+        "-Wold-style-cast",
+    ],
+
+    target: {
+        darwin: {
+            enabled: false,
+        },
+    },
+}
+
+cc_library_host_static {
+    name: "lib_relocation_packer",
+    defaults: ["relocation_packer_flags"],
+    srcs: [
+        "src/debug.cc",
+        "src/delta_encoder.cc",
+        "src/elf_file.cc",
+        "src/packer.cc",
+        "src/sleb128.cc",
+    ],
+
+    static_libs: [
+        "libelf",
+        "libz",
+    ],
+}
+
+cc_binary_host {
+    name: "relocation_packer",
+    defaults: ["relocation_packer_flags"],
+
+    srcs: ["src/main.cc"],
+    static_libs: [
+        "lib_relocation_packer",
+        "libelf",
+        "libz",
+        "libbase",
+    ],
+
+    // Statically linking libc++ to make it work from prebuilts
+    stl: "libc++_static",
+}
+
+cc_test_host {
+    name: "relocation_packer_unit_tests",
+    defaults: ["relocation_packer_flags"],
+
+    srcs: [
+        "src/debug_unittest.cc",
+        "src/delta_encoder_unittest.cc",
+        "src/elf_file_unittest.cc",
+        "src/sleb128_unittest.cc",
+        "src/packer_unittest.cc",
+    ],
+
+    static_libs: [
+        "lib_relocation_packer",
+        "libelf",
+        "libz",
+    ],
+}
diff --git a/tools/relocation_packer/Android.mk b/tools/relocation_packer/Android.mk
index 2bf77b9..9905657 100644
--- a/tools/relocation_packer/Android.mk
+++ b/tools/relocation_packer/Android.mk
@@ -14,71 +14,9 @@
 # limitations under the License.
 #
 
-ifeq ($(HOST_OS),linux)
-common_cppflags := -Wall -Wextra -Wunused -Werror -Wold-style-cast
-
 LOCAL_PATH := $(call my-dir)
 
-include $(CLEAR_VARS)
-
-LOCAL_CPP_EXTENSION := .cc
-
-LOCAL_SRC_FILES := \
-  src/debug.cc \
-  src/delta_encoder.cc \
-  src/elf_file.cc \
-  src/packer.cc \
-  src/sleb128.cc \
-
-LOCAL_STATIC_LIBRARIES := libelf libz
-LOCAL_C_INCLUDES := external/elfutils/src/libelf
-LOCAL_MODULE := lib_relocation_packer
-
-LOCAL_CPPFLAGS := $(common_cppflags)
-
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
-include $(BUILD_HOST_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-
-LOCAL_CPP_EXTENSION := .cc
-
-LOCAL_SRC_FILES := src/main.cc
-LOCAL_STATIC_LIBRARIES := lib_relocation_packer libelf libz
-
-# Statically linking libc++ to make it work from prebuilts
-LOCAL_CXX_STL := libc++_static
-LOCAL_C_INCLUDES := external/elfutils/src/libelf libnativehelper/include
-
-LOCAL_MODULE := relocation_packer
-
-LOCAL_CPPFLAGS := $(common_cppflags)
-
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
-include $(BUILD_HOST_EXECUTABLE)
-
-include $(CLEAR_VARS)
-
-LOCAL_CPP_EXTENSION := .cc
-
-LOCAL_SRC_FILES := \
-  src/debug_unittest.cc \
-  src/delta_encoder_unittest.cc \
-  src/elf_file_unittest.cc \
-  src/sleb128_unittest.cc \
-  src/packer_unittest.cc \
-
-LOCAL_STATIC_LIBRARIES := lib_relocation_packer libelf libz
-LOCAL_C_INCLUDES := external/elfutils/src/libelf
-
-LOCAL_CPPFLAGS := $(common_cppflags)
-
-LOCAL_MODULE := relocation_packer_unit_tests
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
-include $(BUILD_HOST_NATIVE_TEST)
+ifeq ($(HOST_OS),linux)
 
 # $(1) library name
 define copy-test-library
diff --git a/tools/relocation_packer/src/debug.h b/tools/relocation_packer/src/debug.h
index 48be6c1..fdfb795 100644
--- a/tools/relocation_packer/src/debug.h
+++ b/tools/relocation_packer/src/debug.h
@@ -81,26 +81,29 @@
 
 // Make logging severities visible globally.
 typedef relocation_packer::Logger::Severity LogSeverity;
-using LogSeverity::INFO;
-using LogSeverity::WARNING;
-using LogSeverity::ERROR;
-using LogSeverity::FATAL;
 
 // LOG(severity) prints a message with the given severity, and aborts if
 // severity is FATAL.  LOG_IF(severity, predicate) does the same but only if
 // predicate is true.  INT_MIN is guaranteed to be less than or equal to
 // any verbosity level.
-#define LOG(severity) \
-    (relocation_packer::Logger(severity, INT_MIN, true).GetStream())
-#define LOG_IF(severity, predicate) \
-    (relocation_packer::Logger(severity, INT_MIN, (predicate)).GetStream())
+#define LOG(severity)                                                      \
+  (relocation_packer::Logger(relocation_packer::Logger::severity, INT_MIN, \
+                             true)                                         \
+       .GetStream())
+#define LOG_IF(severity, predicate)                                        \
+  (relocation_packer::Logger(relocation_packer::Logger::severity, INT_MIN, \
+                             (predicate))                                  \
+       .GetStream())
 
 // VLOG(level) prints its message as INFO if level is less than or equal to
 // the current verbosity level.
-#define VLOG(level) \
-    (relocation_packer::Logger(INFO, (level), true).GetStream())
-#define VLOG_IF(level, predicate) \
-    (relocation_packer::Logger(INFO, (level), (predicate)).GetStream())
+#define VLOG(level)                                                          \
+  (relocation_packer::Logger(relocation_packer::Logger::INFO, (level), true) \
+       .GetStream())
+#define VLOG_IF(level, predicate)                                      \
+  (relocation_packer::Logger(relocation_packer::Logger::INFO, (level), \
+                             (predicate))                              \
+       .GetStream())
 
 // CHECK(predicate) fails with a FATAL log message if predicate is false.
 #define CHECK(predicate) (LOG_IF(FATAL, !(predicate)) \
diff --git a/tools/relocation_packer/src/elf_file.cc b/tools/relocation_packer/src/elf_file.cc
index 014883d..96e6efd 100644
--- a/tools/relocation_packer/src/elf_file.cc
+++ b/tools/relocation_packer/src/elf_file.cc
@@ -552,11 +552,11 @@
               << " d_val adjusted to " << dynamic->d_un.d_val;
     }
 
-    // Special case: DT_MIPS_RLD_MAP2 stores the difference between dynamic
+    // Special case: DT_MIPS_RLD_MAP_REL stores the difference between dynamic
     // entry address and the address of the _r_debug (used by GDB)
     // since the dynamic section and target address are on the
     // different sides of the hole it needs to be adjusted accordingly
-    if (tag == DT_MIPS_RLD_MAP2) {
+    if (tag == DT_MIPS_RLD_MAP_REL) {
       dynamic->d_un.d_val += hole_size;
       VLOG(1) << "dynamic[" << i << "] " << dynamic->d_tag
               << " d_val adjusted to " << dynamic->d_un.d_val;
diff --git a/tools/relocation_packer/src/elf_traits.h b/tools/relocation_packer/src/elf_traits.h
index 1c938fa..3e282b2 100644
--- a/tools/relocation_packer/src/elf_traits.h
+++ b/tools/relocation_packer/src/elf_traits.h
@@ -10,8 +10,8 @@
 #include "elf.h"
 #include "libelf.h"
 
-#if !defined(DT_MIPS_RLD_MAP2)
-#define DT_MIPS_RLD_MAP2 0x70000035
+#if !defined(DT_MIPS_RLD_MAP_REL)
+#define DT_MIPS_RLD_MAP_REL 0x70000035
 #endif
 
 // ELF is a traits structure used to provide convenient aliases for
diff --git a/tools/relocation_packer/src/main.cc b/tools/relocation_packer/src/main.cc
index 8e9de6d..d0a0dd4 100644
--- a/tools/relocation_packer/src/main.cc
+++ b/tools/relocation_packer/src/main.cc
@@ -25,7 +25,7 @@
 #include "elf_traits.h"
 #include "libelf.h"
 
-#include "nativehelper/ScopedFd.h"
+#include <android-base/unique_fd.h>
 
 static void PrintUsage(const char* argv0) {
   std::string temporary = argv0;
@@ -94,7 +94,7 @@
   }
 
   const char* file = argv[argc - 1];
-  ScopedFd fd(open(file, O_RDWR));
+  android::base::unique_fd fd(open(file, O_RDWR));
   if (fd.get() == -1) {
     LOG(ERROR) << file << ": " << strerror(errno);
     return 1;
diff --git a/tools/versioner/Android.mk b/tools/versioner/Android.mk
new file mode 100644
index 0000000..3036300
--- /dev/null
+++ b/tools/versioner/Android.mk
@@ -0,0 +1,25 @@
+ifeq (true,$(FORCE_BUILD_LLVM_COMPONENTS))
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := versioner
+LOCAL_MODULE_HOST_OS := linux
+
+LOCAL_CLANG := true
+LOCAL_CFLAGS := -Wall -Wextra -Werror -Wno-unused-parameter
+LOCAL_CFLAGS += -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS
+LOCAL_CPPFLAGS := $(LOCAL_CFLAGS) -std=c++14 -fno-rtti
+
+LOCAL_SRC_FILES := \
+  src/versioner.cpp \
+  src/DeclarationDatabase.cpp \
+  src/SymbolDatabase.cpp \
+  src/Utils.cpp
+
+LOCAL_SHARED_LIBRARIES := libclang libLLVM
+
+include $(BUILD_HOST_EXECUTABLE)
+
+endif
diff --git a/tools/versioner/README.md b/tools/versioner/README.md
new file mode 100644
index 0000000..39b5128
--- /dev/null
+++ b/tools/versioner/README.md
@@ -0,0 +1,8 @@
+## versioner
+Use clang to verify the correctness of bionic's availability attributes against the NDK platform definitions.
+
+#### Build
+Build with `FORCE_BUILD_LLVM_COMPONENTS=true mma -j48`
+
+#### Use
+`versioner -p platforms current dependencies`
diff --git a/tools/versioner/current b/tools/versioner/current
new file mode 120000
index 0000000..234dfe7
--- /dev/null
+++ b/tools/versioner/current
@@ -0,0 +1 @@
+../../libc/include
\ No newline at end of file
diff --git a/tools/versioner/dependencies/arm/arch-arm b/tools/versioner/dependencies/arm/arch-arm
new file mode 120000
index 0000000..ed69f41
--- /dev/null
+++ b/tools/versioner/dependencies/arm/arch-arm
@@ -0,0 +1 @@
+../../../../libc/arch-arm/include
\ No newline at end of file
diff --git a/tools/versioner/dependencies/arm/kernel_uapi_asm-arm b/tools/versioner/dependencies/arm/kernel_uapi_asm-arm
new file mode 120000
index 0000000..fabed85
--- /dev/null
+++ b/tools/versioner/dependencies/arm/kernel_uapi_asm-arm
@@ -0,0 +1 @@
+../../../../libc/kernel/uapi/asm-arm
\ No newline at end of file
diff --git a/tools/versioner/dependencies/arm64/arch-arm64 b/tools/versioner/dependencies/arm64/arch-arm64
new file mode 120000
index 0000000..21a21d4
--- /dev/null
+++ b/tools/versioner/dependencies/arm64/arch-arm64
@@ -0,0 +1 @@
+../../../../libc/arch-arm64/include
\ No newline at end of file
diff --git a/tools/versioner/dependencies/arm64/kernel_uapi_asm-arm64 b/tools/versioner/dependencies/arm64/kernel_uapi_asm-arm64
new file mode 120000
index 0000000..16e74a3
--- /dev/null
+++ b/tools/versioner/dependencies/arm64/kernel_uapi_asm-arm64
@@ -0,0 +1 @@
+../../../../libc/kernel/uapi/asm-arm64
\ No newline at end of file
diff --git a/tools/versioner/dependencies/common/clang-builtins b/tools/versioner/dependencies/common/clang-builtins
new file mode 120000
index 0000000..fc27e65
--- /dev/null
+++ b/tools/versioner/dependencies/common/clang-builtins
@@ -0,0 +1 @@
+../../../../../external/clang/lib/Headers
\ No newline at end of file
diff --git a/tools/versioner/dependencies/common/kernel_android_uapi b/tools/versioner/dependencies/common/kernel_android_uapi
new file mode 120000
index 0000000..bcf6daa
--- /dev/null
+++ b/tools/versioner/dependencies/common/kernel_android_uapi
@@ -0,0 +1 @@
+../../../../libc/kernel/android/uapi
\ No newline at end of file
diff --git a/tools/versioner/dependencies/common/kernel_uapi b/tools/versioner/dependencies/common/kernel_uapi
new file mode 120000
index 0000000..2a915ef
--- /dev/null
+++ b/tools/versioner/dependencies/common/kernel_uapi
@@ -0,0 +1 @@
+../../../../libc/kernel/uapi
\ No newline at end of file
diff --git a/tools/versioner/dependencies/mips/arch-mips b/tools/versioner/dependencies/mips/arch-mips
new file mode 120000
index 0000000..7f2f104
--- /dev/null
+++ b/tools/versioner/dependencies/mips/arch-mips
@@ -0,0 +1 @@
+../../../../libc/arch-mips/include
\ No newline at end of file
diff --git a/tools/versioner/dependencies/mips/kernel_uapi_asm-mips b/tools/versioner/dependencies/mips/kernel_uapi_asm-mips
new file mode 120000
index 0000000..dcd1955
--- /dev/null
+++ b/tools/versioner/dependencies/mips/kernel_uapi_asm-mips
@@ -0,0 +1 @@
+../../../../libc/kernel/uapi/asm-mips
\ No newline at end of file
diff --git a/tools/versioner/dependencies/mips64/arch-mips64 b/tools/versioner/dependencies/mips64/arch-mips64
new file mode 120000
index 0000000..48cea72
--- /dev/null
+++ b/tools/versioner/dependencies/mips64/arch-mips64
@@ -0,0 +1 @@
+../../../../libc/arch-mips64/include
\ No newline at end of file
diff --git a/tools/versioner/dependencies/mips64/kernel_uapi_asm-mips b/tools/versioner/dependencies/mips64/kernel_uapi_asm-mips
new file mode 120000
index 0000000..dcd1955
--- /dev/null
+++ b/tools/versioner/dependencies/mips64/kernel_uapi_asm-mips
@@ -0,0 +1 @@
+../../../../libc/kernel/uapi/asm-mips
\ No newline at end of file
diff --git a/tools/versioner/dependencies/x86/arch-x86 b/tools/versioner/dependencies/x86/arch-x86
new file mode 120000
index 0000000..d0f016a
--- /dev/null
+++ b/tools/versioner/dependencies/x86/arch-x86
@@ -0,0 +1 @@
+../../../../libc/arch-x86/include
\ No newline at end of file
diff --git a/tools/versioner/dependencies/x86/kernel_uapi_asm-x86 b/tools/versioner/dependencies/x86/kernel_uapi_asm-x86
new file mode 120000
index 0000000..0efae62
--- /dev/null
+++ b/tools/versioner/dependencies/x86/kernel_uapi_asm-x86
@@ -0,0 +1 @@
+../../../../libc/kernel/uapi/asm-x86
\ No newline at end of file
diff --git a/tools/versioner/dependencies/x86_64/arch-x86_64 b/tools/versioner/dependencies/x86_64/arch-x86_64
new file mode 120000
index 0000000..deb647d
--- /dev/null
+++ b/tools/versioner/dependencies/x86_64/arch-x86_64
@@ -0,0 +1 @@
+../../../../libc/arch-x86_64/include
\ No newline at end of file
diff --git a/tools/versioner/dependencies/x86_64/kernel_uapi_asm-x86 b/tools/versioner/dependencies/x86_64/kernel_uapi_asm-x86
new file mode 120000
index 0000000..0efae62
--- /dev/null
+++ b/tools/versioner/dependencies/x86_64/kernel_uapi_asm-x86
@@ -0,0 +1 @@
+../../../../libc/kernel/uapi/asm-x86
\ No newline at end of file
diff --git a/tools/versioner/platforms b/tools/versioner/platforms
new file mode 120000
index 0000000..bcb7da8
--- /dev/null
+++ b/tools/versioner/platforms
@@ -0,0 +1 @@
+../../../development/ndk/platforms
\ No newline at end of file
diff --git a/tools/versioner/run_tests.py b/tools/versioner/run_tests.py
new file mode 100755
index 0000000..18b2aa9
--- /dev/null
+++ b/tools/versioner/run_tests.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+
+import os
+import subprocess
+import sys
+
+red = '\033[91m'
+green = '\033[92m'
+bold = '\033[1m'
+reset = '\033[0m'
+prefix_pass = bold + "[" + green + "PASS" + reset + bold + "]" + reset
+prefix_fail = bold + "[" + red + "FAIL" + reset + bold + "]" + reset
+
+
+def indent(text, spaces=4):
+    prefix = "    "
+    return "\n".join([prefix + line for line in text.split("\n")])
+
+
+def run_test(test_name, path):
+    os.chdir(path)
+    process = subprocess.Popen(
+        ["/bin/sh", "run.sh"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+    (output, _) = process.communicate()
+
+    if os.path.exists("expected_fail"):
+        with open("expected_fail") as f:
+            expected_output = f.read()
+            if not output.endswith(expected_output):
+                print("{} {}: expected output mismatch".format(
+                    prefix_fail, test_name))
+                print("")
+                print("  Expected:")
+                print(indent(expected_output))
+                print("  Actual:")
+                print(indent(output))
+                return False
+    elif process.returncode != 0:
+        print("{} {}: unexpected failure:".format(prefix_fail, test_name))
+        print("")
+        print(indent(output))
+        return False
+
+    print("{} {}".format(prefix_pass, test_name))
+    return True
+
+root_dir = os.path.dirname(os.path.realpath(__file__))
+test_dir = os.path.join(root_dir, "tests")
+tests = os.listdir(test_dir)
+
+success = True
+for test in sorted(tests):
+    if not run_test(test, os.path.join(test_dir, test)):
+        success = False
+
+sys.exit(0 if success else 1)
diff --git a/tools/versioner/src/DeclarationDatabase.cpp b/tools/versioner/src/DeclarationDatabase.cpp
new file mode 100644
index 0000000..9f02588
--- /dev/null
+++ b/tools/versioner/src/DeclarationDatabase.cpp
@@ -0,0 +1,179 @@
+/*
+ * Copyright 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.
+ */
+
+#include "DeclarationDatabase.h"
+
+#include <iostream>
+#include <map>
+#include <set>
+#include <string>
+
+#include <clang/AST/AST.h>
+#include <clang/AST/Attr.h>
+#include <clang/AST/Mangle.h>
+#include <clang/AST/RecursiveASTVisitor.h>
+#include <clang/Frontend/ASTUnit.h>
+#include <llvm/Support/raw_ostream.h>
+
+using namespace clang;
+
+class Visitor : public RecursiveASTVisitor<Visitor> {
+  HeaderDatabase& database;
+  SourceManager& src_manager;
+  std::unique_ptr<MangleContext> mangler;
+
+ public:
+  Visitor(HeaderDatabase& database, ASTContext& ctx)
+      : database(database), src_manager(ctx.getSourceManager()) {
+    mangler.reset(ItaniumMangleContext::create(ctx, ctx.getDiagnostics()));
+  }
+
+  std::string getDeclName(NamedDecl* decl) {
+    if (auto var_decl = dyn_cast<VarDecl>(decl)) {
+      if (!var_decl->isFileVarDecl()) {
+        return "<local var>";
+      }
+    }
+
+    if (mangler->shouldMangleDeclName(decl)) {
+      std::string mangled;
+      llvm::raw_string_ostream ss(mangled);
+      mangler->mangleName(decl, ss);
+      return mangled;
+    }
+
+    auto identifier = decl->getIdentifier();
+    if (!identifier) {
+      return "<error>";
+    }
+    return identifier->getName();
+  }
+
+  bool VisitDecl(Decl* decl) {
+    // Skip declarations inside of functions (function arguments, variable declarations inside of
+    // inline functions, etc).
+    if (decl->getParentFunctionOrMethod()) {
+      return true;
+    }
+
+    auto named_decl = dyn_cast<NamedDecl>(decl);
+    if (!named_decl) {
+      return true;
+    }
+
+    DeclarationType declaration_type;
+    std::string declaration_name = getDeclName(named_decl);
+    bool is_extern = named_decl->getFormalLinkage() == ExternalLinkage;
+    bool is_definition = false;
+
+    if (auto function_decl = dyn_cast<FunctionDecl>(decl)) {
+      declaration_type = DeclarationType::function;
+      is_definition = function_decl->isThisDeclarationADefinition();
+    } else if (auto var_decl = dyn_cast<VarDecl>(decl)) {
+      if (!var_decl->isFileVarDecl()) {
+        return true;
+      }
+
+      declaration_type = DeclarationType::variable;
+      switch (var_decl->isThisDeclarationADefinition()) {
+        case VarDecl::DeclarationOnly:
+          is_definition = false;
+          break;
+
+        case VarDecl::Definition:
+          is_definition = true;
+          break;
+
+        case VarDecl::TentativeDefinition:
+          // Forbid tentative definitions in headers.
+          fprintf(stderr, "ERROR: declaration '%s' is a tentative definition\n",
+                  declaration_name.c_str());
+          decl->dump();
+          abort();
+      }
+    } else {
+      // We only care about function and variable declarations.
+      return true;
+    }
+
+    if (decl->hasAttr<UnavailableAttr>()) {
+      // Skip declarations that exist only for compile-time diagnostics.
+      return true;
+    }
+
+    // Look for availability annotations.
+    DeclarationAvailability availability;
+    for (const AvailabilityAttr* attr : decl->specific_attrs<AvailabilityAttr>()) {
+      if (attr->getPlatform()->getName() != "android") {
+        fprintf(stderr, "skipping non-android platform %s\n",
+                attr->getPlatform()->getName().str().c_str());
+        continue;
+      }
+      if (attr->getIntroduced().getMajor() != 0) {
+        availability.introduced = attr->getIntroduced().getMajor();
+      }
+      if (attr->getDeprecated().getMajor() != 0) {
+        availability.deprecated = attr->getDeprecated().getMajor();
+      }
+      if (attr->getObsoleted().getMajor() != 0) {
+        availability.obsoleted = attr->getObsoleted().getMajor();
+      }
+    }
+
+    // Find or insert an entry for the declaration.
+    auto declaration_it = database.declarations.find(declaration_name);
+    if (declaration_it == database.declarations.end()) {
+      Declaration declaration = {.name = declaration_name };
+      bool inserted;
+      std::tie(declaration_it, inserted) =
+          database.declarations.insert({ declaration_name, declaration });
+    }
+
+    auto& declaration_locations = declaration_it->second.locations;
+    auto presumed_loc = src_manager.getPresumedLoc(decl->getLocation());
+    DeclarationLocation location = {
+      .filename = presumed_loc.getFilename(),
+      .line_number = presumed_loc.getLine(),
+      .column = presumed_loc.getColumn(),
+      .type = declaration_type,
+      .is_extern = is_extern,
+      .is_definition = is_definition,
+      .availability = availability,
+    };
+
+    // It's fine if the location is already there, we'll get an iterator to the existing element.
+    auto location_it = declaration_locations.begin();
+    bool inserted = false;
+    std::tie(location_it, inserted) = declaration_locations.insert(location);
+
+    // If we didn't insert, check to see if the availability attributes are identical.
+    if (!inserted) {
+      if (location_it->availability != availability) {
+        fprintf(stderr, "ERROR: availability attribute mismatch\n");
+        decl->dump();
+        abort();
+      }
+    }
+
+    return true;
+  }
+};
+
+void HeaderDatabase::parseAST(ASTUnit* ast) {
+  ASTContext& ctx = ast->getASTContext();
+  Visitor visitor(*this, ctx);
+  visitor.TraverseDecl(ctx.getTranslationUnitDecl());
+}
diff --git a/tools/versioner/src/DeclarationDatabase.h b/tools/versioner/src/DeclarationDatabase.h
new file mode 100644
index 0000000..2b462bd
--- /dev/null
+++ b/tools/versioner/src/DeclarationDatabase.h
@@ -0,0 +1,216 @@
+/*
+ * Copyright 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.
+ */
+
+#pragma once
+
+#include <iostream>
+#include <map>
+#include <set>
+#include <sstream>
+#include <string>
+#include <vector>
+
+#include <llvm/ADT/StringRef.h>
+
+#include "Utils.h"
+
+enum class DeclarationType {
+  function,
+  variable,
+  inconsistent,
+};
+
+static const char* declarationTypeName(DeclarationType type) {
+  switch (type) {
+    case DeclarationType::function:
+      return "function";
+    case DeclarationType::variable:
+      return "variable";
+    case DeclarationType::inconsistent:
+      return "inconsistent";
+  }
+}
+
+struct CompilationType {
+  std::string arch;
+  int api_level;
+
+ private:
+  auto tie() const {
+    return std::tie(arch, api_level);
+  }
+
+ public:
+  bool operator<(const CompilationType& other) const {
+    return tie() < other.tie();
+  }
+
+  bool operator==(const CompilationType& other) const {
+    return tie() == other.tie();
+  }
+
+  std::string describe() const {
+    return arch + "-" + std::to_string(api_level);
+  }
+};
+
+struct DeclarationAvailability {
+  int introduced = 0;
+  int deprecated = 0;
+  int obsoleted = 0;
+
+  void dump(std::ostream& out = std::cout) const {
+    out << describe();
+  }
+
+  bool empty() const {
+    return !(introduced || deprecated || obsoleted);
+  }
+
+  auto tie() const {
+    return std::tie(introduced, deprecated, obsoleted);
+  }
+
+  bool operator==(const DeclarationAvailability& rhs) const {
+    return this->tie() == rhs.tie();
+  }
+
+  bool operator!=(const DeclarationAvailability& rhs) const {
+    return !(*this == rhs);
+  }
+
+  std::string describe() const {
+    if (!(introduced || deprecated || obsoleted)) {
+      return "no availability";
+    }
+
+    std::stringstream out;
+    bool need_comma = false;
+    auto comma = [&out, &need_comma]() {
+      if (!need_comma) {
+        need_comma = true;
+        return;
+      }
+      out << ", ";
+    };
+
+    if (introduced != 0) {
+      comma();
+      out << "introduced = " << introduced;
+    }
+    if (deprecated != 0) {
+      comma();
+      out << "deprecated = " << deprecated;
+    }
+    if (obsoleted != 0) {
+      comma();
+      out << "obsoleted = " << obsoleted;
+    }
+
+    return out.str();
+  }
+};
+
+struct DeclarationLocation {
+  std::string filename;
+  unsigned line_number;
+  unsigned column;
+  DeclarationType type;
+  bool is_extern;
+  bool is_definition;
+  DeclarationAvailability availability;
+
+  auto tie() const {
+    return std::tie(filename, line_number, column, type, is_extern, is_definition);
+  }
+
+  bool operator<(const DeclarationLocation& other) const {
+    return tie() < other.tie();
+  }
+
+  bool operator==(const DeclarationLocation& other) const {
+    return tie() == other.tie();
+  }
+
+  void dump(const std::string& base_path = "", std::ostream& out = std::cout) const {
+    const char* var_type = declarationTypeName(type);
+    const char* declaration_type = is_definition ? "definition" : "declaration";
+    const char* linkage = is_extern ? "extern" : "static";
+
+    std::string stripped_path;
+    if (llvm::StringRef(filename).startswith(base_path)) {
+      stripped_path = filename.substr(base_path.size());
+    } else {
+      stripped_path = filename;
+    }
+
+    out << "        " << linkage << " " << var_type << " " << declaration_type << " @ "
+        << stripped_path << ":" << line_number << ":" << column;
+
+    out << "\t[";
+    availability.dump(out);
+    out << "]\n";
+  }
+};
+
+struct Declaration {
+  std::string name;
+  std::set<DeclarationLocation> locations;
+
+  bool hasDefinition() const {
+    for (const auto& location : locations) {
+      if (location.is_definition) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  DeclarationType type() const {
+    DeclarationType result = locations.begin()->type;
+    for (const DeclarationLocation& location : locations) {
+      if (location.type != result) {
+        result = DeclarationType::inconsistent;
+      }
+    }
+    return result;
+  }
+
+  void dump(const std::string& base_path = "", std::ostream& out = std::cout) const {
+    out << "    " << name << " declared in " << locations.size() << " locations:\n";
+    for (const DeclarationLocation& location : locations) {
+      location.dump(base_path, out);
+    }
+  }
+};
+
+namespace clang {
+class ASTUnit;
+}
+
+class HeaderDatabase {
+ public:
+  std::map<std::string, Declaration> declarations;
+
+  void parseAST(clang::ASTUnit* ast);
+
+  void dump(const std::string& base_path = "", std::ostream& out = std::cout) const {
+    out << "HeaderDatabase contains " << declarations.size() << " declarations:\n";
+    for (const auto& pair : declarations) {
+      pair.second.dump(base_path, out);
+    }
+  }
+};
diff --git a/tools/versioner/src/SymbolDatabase.cpp b/tools/versioner/src/SymbolDatabase.cpp
new file mode 100644
index 0000000..a35f045
--- /dev/null
+++ b/tools/versioner/src/SymbolDatabase.cpp
@@ -0,0 +1,155 @@
+/*
+ * Copyright 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.
+ */
+
+#include "SymbolDatabase.h"
+
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <fstream>
+#include <streambuf>
+#include <string>
+#include <unordered_set>
+
+#include <llvm/ADT/SmallVector.h>
+#include <llvm/ADT/StringRef.h>
+#include <llvm/Object/Binary.h>
+#include <llvm/Object/ELFObjectFile.h>
+
+#include "versioner.h"
+
+using namespace llvm;
+using namespace llvm::object;
+
+std::unordered_set<std::string> getSymbols(const std::string& filename) {
+  std::unordered_set<std::string> result;
+  auto binary = createBinary(filename);
+  if (std::error_code ec = binary.getError()) {
+    errx(1, "failed to open library at %s: %s\n", filename.c_str(), ec.message().c_str());
+  }
+
+  ELFObjectFileBase* elf = dyn_cast_or_null<ELFObjectFileBase>(binary.get().getBinary());
+  if (!elf) {
+    errx(1, "failed to parse %s as ELF", filename.c_str());
+  }
+
+  for (const ELFSymbolRef symbol : elf->getDynamicSymbolIterators()) {
+    ErrorOr<StringRef> symbol_name = symbol.getName();
+
+    if (std::error_code ec = binary.getError()) {
+      errx(1, "failed to get symbol name for symbol in %s: %s", filename.c_str(),
+           ec.message().c_str());
+    }
+
+    result.insert(symbol_name.get().str());
+  }
+
+  return result;
+}
+
+// The NDK platforms are built by copying the platform directories on top of
+// each other to build each successive API version. Thus, we need to walk
+// backwards to find each desired file.
+static std::string readPlatformFile(const CompilationType& type, llvm::StringRef platform_dir,
+                                    const std::string& filename, bool required) {
+  int api_level = type.api_level;
+  std::ifstream stream;
+  while (api_level >= arch_min_api[type.arch]) {
+    if (supported_levels.count(api_level) == 0) {
+      --api_level;
+      continue;
+    }
+
+    std::string path = std::string(platform_dir) + "/android-" + std::to_string(api_level) +
+                       "/arch-" + type.arch + "/symbols/" + filename;
+
+    stream = std::ifstream(path);
+    if (stream) {
+      return std::string(std::istreambuf_iterator<char>(stream), std::istreambuf_iterator<char>());
+    }
+
+    --api_level;
+  }
+
+  if (required) {
+    errx(1, "failed to find platform file '%s' for %s", filename.c_str(), type.describe().c_str());
+  }
+
+  return std::string();
+}
+
+static std::map<std::string, NdkSymbolType> parsePlatform(const CompilationType& type,
+                                                          const std::string& platform_dir) {
+  std::map<std::string, NdkSymbolType> result;
+  std::map<std::string, bool /*required*/> wanted_files = {
+    { "libc.so.functions.txt", true },
+    { "libc.so.variables.txt", false },
+    { "libdl.so.functions.txt", false },
+    { "libm.so.functions.txt", false },
+    { "libm.so.variables.txt", false },
+  };
+
+  for (const auto& pair : wanted_files) {
+    llvm::StringRef file = pair.first;
+    bool required = pair.second;
+    NdkSymbolType symbol_type;
+    if (file.endswith(".functions.txt")) {
+      symbol_type = NdkSymbolType::function;
+    } else if (file.endswith(".variables.txt")) {
+      symbol_type = NdkSymbolType::variable;
+    } else {
+      errx(1, "internal error: unexpected platform filename '%s'\n", file.str().c_str());
+    }
+
+    std::string platform_file = readPlatformFile(type, platform_dir, file, required);
+    if (platform_file.empty()) {
+      continue;
+    }
+
+    llvm::SmallVector<llvm::StringRef, 0> symbols;
+    llvm::StringRef(platform_file).split(symbols, "\n");
+
+    for (llvm::StringRef symbol_name : symbols) {
+      if (symbol_name.empty()) {
+        continue;
+      }
+
+      if (result.count(symbol_name) != 0) {
+        if (verbose) {
+          printf("duplicated symbol '%s' in '%s'\n", symbol_name.str().c_str(), file.str().c_str());
+        }
+      }
+
+      result[symbol_name] = symbol_type;
+    }
+  }
+
+  return result;
+}
+
+NdkSymbolDatabase parsePlatforms(const std::set<CompilationType>& types,
+                                 const std::string& platform_dir) {
+  std::map<std::string, std::map<CompilationType, NdkSymbolType>> result;
+  for (const CompilationType& type : types) {
+    std::map<std::string, NdkSymbolType> symbols = parsePlatform(type, platform_dir);
+    for (const auto& it : symbols) {
+      result[it.first][type] = it.second;
+    }
+  }
+
+  return result;
+}
diff --git a/tools/versioner/src/SymbolDatabase.h b/tools/versioner/src/SymbolDatabase.h
new file mode 100644
index 0000000..3f41b98
--- /dev/null
+++ b/tools/versioner/src/SymbolDatabase.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright 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.
+ */
+
+#pragma once
+
+#include <map>
+#include <set>
+#include <string>
+#include <unordered_set>
+
+#include "DeclarationDatabase.h"
+
+using LibrarySymbolDatabase = std::unordered_set<std::string>;
+std::unordered_set<std::string> getSymbols(const std::string& filename);
+
+enum class NdkSymbolType {
+  function,
+  variable,
+};
+
+using NdkSymbolDatabase = std::map<std::string, std::map<CompilationType, NdkSymbolType>>;
+NdkSymbolDatabase parsePlatforms(const std::set<CompilationType>& types,
+                                 const std::string& platform_dir);
diff --git a/tools/versioner/src/Utils.cpp b/tools/versioner/src/Utils.cpp
new file mode 100644
index 0000000..92cc9de
--- /dev/null
+++ b/tools/versioner/src/Utils.cpp
@@ -0,0 +1,56 @@
+/*
+ * Copyright 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.
+ */
+
+#include "Utils.h"
+
+#include <err.h>
+#include <fts.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <string>
+#include <vector>
+
+std::string getWorkingDir() {
+  char buf[PATH_MAX];
+  if (!getcwd(buf, sizeof(buf))) {
+    err(1, "getcwd failed");
+  }
+  return buf;
+}
+
+std::vector<std::string> collectFiles(const std::string& directory) {
+  std::vector<std::string> files;
+
+  char* dir_argv[2] = { const_cast<char*>(directory.c_str()), nullptr };
+  FTS* fts = fts_open(dir_argv, FTS_LOGICAL | FTS_NOCHDIR, nullptr);
+
+  if (!fts) {
+    err(1, "failed to open directory '%s'", directory.c_str());
+  }
+
+  FTSENT* ent;
+  while ((ent = fts_read(fts))) {
+    if (ent->fts_info & (FTS_D | FTS_DP)) {
+      continue;
+    }
+
+    files.push_back(ent->fts_path);
+  }
+
+  fts_close(fts);
+  return files;
+}
diff --git a/tools/versioner/src/Utils.h b/tools/versioner/src/Utils.h
new file mode 100644
index 0000000..f4845b8
--- /dev/null
+++ b/tools/versioner/src/Utils.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright 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.
+ */
+
+#pragma once
+
+#include <string>
+#include <vector>
+
+std::string getWorkingDir();
+std::vector<std::string> collectFiles(const std::string& directory);
+
+namespace std {
+static __attribute__((unused)) std::string to_string(const char* c) {
+  return c;
+}
+
+static __attribute__((unused)) const std::string& to_string(const std::string& str) {
+  return str;
+}
+}
+
+template <typename Collection>
+static std::string Join(Collection c, const std::string& delimiter = ", ") {
+  std::string result;
+  for (const auto& item : c) {
+    result.append(std::to_string(item));
+    result.append(delimiter);
+  }
+  if (!result.empty()) {
+    result.resize(result.length() - delimiter.length());
+  }
+  return result;
+}
diff --git a/tools/versioner/src/versioner.cpp b/tools/versioner/src/versioner.cpp
new file mode 100644
index 0000000..7238a8c
--- /dev/null
+++ b/tools/versioner/src/versioner.cpp
@@ -0,0 +1,686 @@
+/*
+ * Copyright 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.
+ */
+
+#include <dirent.h>
+#include <err.h>
+#include <limits.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <atomic>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <set>
+#include <sstream>
+#include <string>
+#include <thread>
+#include <unordered_map>
+#include <vector>
+
+#include <clang/Frontend/TextDiagnosticPrinter.h>
+#include <clang/Tooling/Tooling.h>
+#include <llvm/ADT/StringRef.h>
+
+#include "DeclarationDatabase.h"
+#include "SymbolDatabase.h"
+#include "Utils.h"
+#include "versioner.h"
+
+using namespace std::string_literals;
+using namespace clang;
+using namespace clang::tooling;
+
+bool verbose;
+
+class HeaderCompilationDatabase : public CompilationDatabase {
+  CompilationType type;
+  std::string cwd;
+  std::vector<std::string> headers;
+  std::vector<std::string> include_dirs;
+
+ public:
+  HeaderCompilationDatabase(CompilationType type, std::string cwd, std::vector<std::string> headers,
+                            std::vector<std::string> include_dirs)
+      : type(type),
+        cwd(std::move(cwd)),
+        headers(std::move(headers)),
+        include_dirs(std::move(include_dirs)) {
+  }
+
+  CompileCommand generateCompileCommand(const std::string& filename) const {
+    std::vector<std::string> command = { "clang-tool", filename, "-nostdlibinc" };
+    for (const auto& dir : include_dirs) {
+      command.push_back("-isystem");
+      command.push_back(dir);
+    }
+    command.push_back("-std=c11");
+    command.push_back("-DANDROID");
+    command.push_back("-D__ANDROID_API__="s + std::to_string(type.api_level));
+    command.push_back("-D_FORTIFY_SOURCE=2");
+    command.push_back("-D_GNU_SOURCE");
+    command.push_back("-Wno-unknown-attributes");
+    command.push_back("-target");
+    command.push_back(arch_targets[type.arch]);
+
+    return CompileCommand(cwd, filename, command);
+  }
+
+  std::vector<CompileCommand> getAllCompileCommands() const override {
+    std::vector<CompileCommand> commands;
+    for (const std::string& file : headers) {
+      commands.push_back(generateCompileCommand(file));
+    }
+    return commands;
+  }
+
+  std::vector<CompileCommand> getCompileCommands(StringRef file) const override {
+    std::vector<CompileCommand> commands;
+    commands.push_back(generateCompileCommand(file));
+    return commands;
+  }
+
+  std::vector<std::string> getAllFiles() const override {
+    return headers;
+  }
+};
+
+struct CompilationRequirements {
+  std::vector<std::string> headers;
+  std::vector<std::string> dependencies;
+};
+
+static CompilationRequirements collectRequirements(const std::string& arch,
+                                                   const std::string& header_dir,
+                                                   const std::string& dependency_dir) {
+  std::vector<std::string> headers = collectFiles(header_dir);
+
+  std::vector<std::string> dependencies = { header_dir };
+  if (!dependency_dir.empty()) {
+    auto collect_children = [&dependencies](const std::string& dir_path) {
+      DIR* dir = opendir(dir_path.c_str());
+      if (!dir) {
+        err(1, "failed to open dependency directory '%s'", dir_path.c_str());
+      }
+
+      struct dirent* dent;
+      while ((dent = readdir(dir))) {
+        if (dent->d_name[0] == '.') {
+          continue;
+        }
+
+        // TODO: Resolve symlinks.
+        std::string dependency = dir_path + "/" + dent->d_name;
+
+        struct stat st;
+        if (stat(dependency.c_str(), &st) != 0) {
+          err(1, "failed to stat dependency '%s'", dependency.c_str());
+        }
+
+        if (!S_ISDIR(st.st_mode)) {
+          errx(1, "'%s' is not a directory", dependency.c_str());
+        }
+
+        dependencies.push_back(dependency);
+      }
+
+      closedir(dir);
+    };
+
+    collect_children(dependency_dir + "/common");
+    collect_children(dependency_dir + "/" + arch);
+  }
+
+  auto new_end = std::remove_if(headers.begin(), headers.end(), [&arch](llvm::StringRef header) {
+    for (const auto& it : header_blacklist) {
+      if (it.second.find(arch) == it.second.end()) {
+        continue;
+      }
+
+      if (header.endswith("/" + it.first)) {
+        return true;
+      }
+    }
+    return false;
+  });
+
+  headers.erase(new_end, headers.end());
+
+  CompilationRequirements result = { .headers = headers, .dependencies = dependencies };
+  return result;
+}
+
+static std::set<CompilationType> generateCompilationTypes(
+    const std::set<std::string> selected_architectures, const std::set<int>& selected_levels) {
+  std::set<CompilationType> result;
+  for (const std::string& arch : selected_architectures) {
+    int min_api = arch_min_api[arch];
+    for (int api_level : selected_levels) {
+      if (api_level < min_api) {
+        continue;
+      }
+      CompilationType type = { .arch = arch, .api_level = api_level };
+      result.insert(type);
+    }
+  }
+  return result;
+}
+
+using DeclarationDatabase = std::map<std::string, std::map<CompilationType, Declaration>>;
+
+static DeclarationDatabase transposeHeaderDatabases(
+    const std::map<CompilationType, HeaderDatabase>& original) {
+  DeclarationDatabase result;
+  for (const auto& outer : original) {
+    const CompilationType& type = outer.first;
+    for (const auto& inner : outer.second.declarations) {
+      const std::string& symbol_name = inner.first;
+      result[symbol_name][type] = inner.second;
+    }
+  }
+  return result;
+}
+
+static DeclarationDatabase compileHeaders(const std::set<CompilationType>& types,
+                                          const std::string& header_dir,
+                                          const std::string& dependency_dir, bool* failed) {
+  constexpr size_t thread_count = 8;
+  size_t threads_created = 0;
+  std::mutex mutex;
+  std::vector<std::thread> threads(thread_count);
+
+  std::map<CompilationType, HeaderDatabase> header_databases;
+  std::unordered_map<std::string, CompilationRequirements> requirements;
+
+  std::string cwd = getWorkingDir();
+  bool errors = false;
+
+  for (const auto& type : types) {
+    if (requirements.count(type.arch) == 0) {
+      requirements[type.arch] = collectRequirements(type.arch, header_dir, dependency_dir);
+    }
+  }
+
+  for (const auto& type : types) {
+    size_t thread_id = threads_created++;
+    if (thread_id >= thread_count) {
+      thread_id = thread_id % thread_count;
+      threads[thread_id].join();
+    }
+
+    threads[thread_id] = std::thread(
+        [&](CompilationType type) {
+          const auto& req = requirements[type.arch];
+
+          HeaderDatabase database;
+          HeaderCompilationDatabase compilation_database(type, cwd, req.headers, req.dependencies);
+
+          ClangTool tool(compilation_database, req.headers);
+
+          clang::DiagnosticOptions diagnostic_options;
+          std::vector<std::unique_ptr<ASTUnit>> asts;
+          tool.buildASTs(asts);
+          for (const auto& ast : asts) {
+            clang::DiagnosticsEngine& diagnostics_engine = ast->getDiagnostics();
+            if (diagnostics_engine.getNumWarnings() || diagnostics_engine.hasErrorOccurred()) {
+              std::unique_lock<std::mutex> l(mutex);
+              errors = true;
+              printf("versioner: compilation failure for %s in %s\n", type.describe().c_str(),
+                     ast->getOriginalSourceFileName().str().c_str());
+            }
+
+            database.parseAST(ast.get());
+          }
+
+          std::unique_lock<std::mutex> l(mutex);
+          header_databases[type] = database;
+        },
+        type);
+  }
+
+  if (threads_created < thread_count) {
+    threads.resize(threads_created);
+  }
+
+  for (auto& thread : threads) {
+    thread.join();
+  }
+
+  if (errors) {
+    printf("versioner: compilation generated warnings or errors\n");
+    *failed = errors;
+  }
+
+  return transposeHeaderDatabases(header_databases);
+}
+
+static bool sanityCheck(const std::set<CompilationType>& types,
+                        const DeclarationDatabase& database) {
+  bool error = false;
+  std::string cwd = getWorkingDir() + "/";
+
+  for (auto outer : database) {
+    const std::string& symbol_name = outer.first;
+    CompilationType last_type;
+    DeclarationAvailability last_availability;
+
+    // Rely on std::set being sorted to loop through the types by architecture.
+    for (const CompilationType& type : types) {
+      auto inner = outer.second.find(type);
+      if (inner == outer.second.end()) {
+        // TODO: Check for holes.
+        continue;
+      }
+
+      const Declaration& declaration = inner->second;
+      bool found_availability = false;
+      bool availability_mismatch = false;
+      DeclarationAvailability current_availability;
+
+      // Ensure that all of the availability declarations for this symbol match.
+      for (const DeclarationLocation& location : declaration.locations) {
+        if (!found_availability) {
+          found_availability = true;
+          current_availability = location.availability;
+          continue;
+        }
+
+        if (current_availability != location.availability) {
+          availability_mismatch = true;
+          error = true;
+        }
+      }
+
+      if (availability_mismatch) {
+        printf("%s: availability mismatch for %s\n", symbol_name.c_str(), type.describe().c_str());
+        declaration.dump(cwd);
+      }
+
+      if (type.arch != last_type.arch) {
+        last_type = type;
+        last_availability = current_availability;
+        continue;
+      }
+
+      // Ensure that availability declarations are consistent across API levels for a given arch.
+      if (last_availability != current_availability) {
+        error = true;
+        printf("%s: availability mismatch between %s and %s: [%s] before, [%s] after\n",
+               symbol_name.c_str(), last_type.describe().c_str(), type.describe().c_str(),
+               last_availability.describe().c_str(), current_availability.describe().c_str());
+      }
+
+      // Ensure that at most one inline definition of a function exists.
+      std::set<DeclarationLocation> inline_definitions;
+
+      for (const DeclarationLocation& location : declaration.locations) {
+        if (location.is_definition) {
+          inline_definitions.insert(location);
+        }
+      }
+
+      if (inline_definitions.size() > 1) {
+        error = true;
+        printf("%s: multiple inline definitions found:\n", symbol_name.c_str());
+        for (const DeclarationLocation& location : declaration.locations) {
+          location.dump(cwd);
+        }
+      }
+
+      last_type = type;
+    }
+  }
+  return !error;
+}
+
+// Check that our symbol availability declarations match the actual NDK
+// platform symbol availability.
+static bool checkVersions(const std::set<CompilationType>& types,
+                          const DeclarationDatabase& declaration_database,
+                          const NdkSymbolDatabase& symbol_database) {
+  bool failed = false;
+
+  std::map<std::string, std::set<CompilationType>> arch_types;
+  for (const CompilationType& type : types) {
+    arch_types[type.arch].insert(type);
+  }
+
+  std::set<std::string> completely_unavailable;
+
+  for (const auto& outer : declaration_database) {
+    const std::string& symbol_name = outer.first;
+    const auto& compilations = outer.second;
+
+    auto platform_availability_it = symbol_database.find(symbol_name);
+    if (platform_availability_it == symbol_database.end()) {
+      completely_unavailable.insert(symbol_name);
+      continue;
+    }
+
+    const auto& platform_availability = platform_availability_it->second;
+    std::set<CompilationType> missing_symbol;
+    std::set<CompilationType> missing_decl;
+
+    for (const CompilationType& type : types) {
+      auto it = compilations.find(type);
+      if (it == compilations.end()) {
+        missing_decl.insert(type);
+        continue;
+      }
+
+      const Declaration& declaration = it->second;
+
+      // sanityCheck ensured that the availability declarations for a given arch match.
+      DeclarationAvailability availability = declaration.locations.begin()->availability;
+      int api_level = type.api_level;
+
+      int introduced = std::max(0, availability.introduced);
+      int obsoleted = availability.obsoleted == 0 ? INT_MAX : availability.obsoleted;
+      bool decl_available = api_level >= introduced && api_level < obsoleted;
+
+      auto symbol_availability_it = platform_availability.find(type);
+      bool symbol_available = symbol_availability_it != platform_availability.end();
+      if (decl_available) {
+        if (!symbol_available) {
+          // Ensure that either it exists in the platform, or an inline definition is visible.
+          if (!declaration.hasDefinition()) {
+            missing_symbol.insert(type);
+            continue;
+          }
+        } else {
+          // Ensure that symbols declared as functions/variables actually are.
+          switch (declaration.type()) {
+            case DeclarationType::inconsistent:
+              printf("%s: inconsistent declaration type\n", symbol_name.c_str());
+              declaration.dump();
+              exit(1);
+
+            case DeclarationType::variable:
+              if (symbol_availability_it->second != NdkSymbolType::variable) {
+                printf("%s: declared as variable, exists in platform as function\n",
+                       symbol_name.c_str());
+                failed = true;
+              }
+              break;
+
+            case DeclarationType::function:
+              if (symbol_availability_it->second != NdkSymbolType::function) {
+                printf("%s: declared as function, exists in platform as variable\n",
+                       symbol_name.c_str());
+                failed = true;
+              }
+              break;
+          }
+        }
+      } else {
+        // Ensure that it's not available in the platform.
+        if (symbol_availability_it != platform_availability.end()) {
+          printf("%s: symbol should be unavailable in %s (declared with availability %s)\n",
+                 symbol_name.c_str(), type.describe().c_str(), availability.describe().c_str());
+          failed = true;
+        }
+      }
+    }
+
+    // Allow declarations to be missing from an entire architecture.
+    for (const auto& arch_type : arch_types) {
+      const std::string& arch = arch_type.first;
+      bool found_all = true;
+      for (const auto& type : arch_type.second) {
+        if (missing_decl.find(type) == missing_decl.end()) {
+          found_all = false;
+          break;
+        }
+      }
+
+      if (!found_all) {
+        continue;
+      }
+
+      for (auto it = missing_decl.begin(); it != missing_decl.end();) {
+        if (it->arch == arch) {
+          it = missing_decl.erase(it);
+        } else {
+          ++it;
+        }
+      }
+    }
+
+    auto types_to_string = [](const std::set<CompilationType>& types) {
+      std::string result;
+      for (const CompilationType& type : types) {
+        result += type.describe();
+        result += ", ";
+      }
+      result.resize(result.length() - 2);
+      return result;
+    };
+
+    if (!missing_decl.empty()) {
+      printf("%s: declaration missing in %s\n", symbol_name.c_str(),
+             types_to_string(missing_decl).c_str());
+      failed = true;
+    }
+
+    if (!missing_symbol.empty()) {
+      printf("%s: declaration marked available but symbol missing in [%s]\n", symbol_name.c_str(),
+             types_to_string(missing_symbol).c_str());
+      failed = true;
+    }
+  }
+
+  for (const std::string& symbol_name : completely_unavailable) {
+    bool found_inline_definition = false;
+    bool future = false;
+
+    auto symbol_it = declaration_database.find(symbol_name);
+
+    // Ignore inline functions and functions that are tagged as __INTRODUCED_IN_FUTURE.
+    // Ensure that all of the declarations of that function satisfy that.
+    for (const auto& declaration_pair : symbol_it->second) {
+      const Declaration& declaration = declaration_pair.second;
+      DeclarationAvailability availability = declaration.locations.begin()->availability;
+
+      if (availability.introduced >= 10000) {
+        future = true;
+      }
+
+      if (declaration.hasDefinition()) {
+        found_inline_definition = true;
+      }
+    }
+
+    if (future || found_inline_definition) {
+      continue;
+    }
+
+    if (missing_symbol_whitelist.count(symbol_name) != 0) {
+      continue;
+    }
+
+    printf("%s: not available in any platform\n", symbol_name.c_str());
+    failed = true;
+  }
+
+  return !failed;
+}
+
+static void usage(bool help = false) {
+  fprintf(stderr, "Usage: versioner [OPTION]... [HEADER_PATH] [DEPS_PATH]\n");
+  if (!help) {
+    printf("Try 'versioner -h' for more information.\n");
+    exit(1);
+  } else {
+    fprintf(stderr, "Version headers at HEADER_PATH, with DEPS_PATH/ARCH/* on the include path\n");
+    fprintf(stderr, "Autodetects paths if HEADER_PATH and DEPS_PATH are not specified\n");
+    fprintf(stderr, "\n");
+    fprintf(stderr, "Target specification (defaults to all):\n");
+    fprintf(stderr, "  -a API_LEVEL\tbuild with specified API level (can be repeated)\n");
+    fprintf(stderr, "    \t\tvalid levels are %s\n", Join(supported_levels).c_str());
+    fprintf(stderr, "  -r ARCH\tbuild with specified architecture (can be repeated)\n");
+    fprintf(stderr, "    \t\tvalid architectures are %s\n", Join(supported_archs).c_str());
+    fprintf(stderr, "\n");
+    fprintf(stderr, "Validation:\n");
+    fprintf(stderr, "  -p PATH\tcompare against NDK platform at PATH\n");
+    fprintf(stderr, "  -v\t\tenable verbose warnings\n");
+    fprintf(stderr, "\n");
+    fprintf(stderr, "Miscellaneous:\n");
+    fprintf(stderr, "  -h\t\tdisplay this message\n");
+    exit(0);
+  }
+}
+
+int main(int argc, char** argv) {
+  std::string cwd = getWorkingDir() + "/";
+  bool default_args = true;
+  std::string platform_dir;
+  std::set<std::string> selected_architectures;
+  std::set<int> selected_levels;
+
+  int c;
+  while ((c = getopt(argc, argv, "a:r:p:vh")) != -1) {
+    default_args = false;
+    switch (c) {
+      case 'a': {
+        char* end;
+        int api_level = strtol(optarg, &end, 10);
+        if (end == optarg || strlen(end) > 0) {
+          usage();
+        }
+
+        if (supported_levels.count(api_level) == 0) {
+          errx(1, "unsupported API level %d", api_level);
+        }
+
+        selected_levels.insert(api_level);
+        break;
+      }
+
+      case 'r': {
+        if (supported_archs.count(optarg) == 0) {
+          errx(1, "unsupported architecture: %s", optarg);
+        }
+        selected_architectures.insert(optarg);
+        break;
+      }
+
+      case 'p': {
+        if (!platform_dir.empty()) {
+          usage();
+        }
+
+        platform_dir = optarg;
+
+        struct stat st;
+        if (stat(platform_dir.c_str(), &st) != 0) {
+          err(1, "failed to stat platform directory '%s'", platform_dir.c_str());
+        }
+        if (!S_ISDIR(st.st_mode)) {
+          errx(1, "'%s' is not a directory", optarg);
+        }
+        break;
+      }
+
+      case 'v':
+        verbose = true;
+        break;
+
+      case 'h':
+        usage(true);
+        break;
+
+      default:
+        usage();
+        break;
+    }
+  }
+
+  if (argc - optind > 2 || optind > argc) {
+    usage();
+  }
+
+  std::string header_dir;
+  std::string dependency_dir;
+
+  if (optind == argc) {
+    // Neither HEADER_PATH nor DEPS_PATH were specified, so try to figure them out.
+    const char* top = getenv("ANDROID_BUILD_TOP");
+    if (!top) {
+      fprintf(stderr, "versioner: failed to autodetect bionic paths. Is ANDROID_BUILD_TOP set?\n");
+      usage();
+    }
+
+    std::string versioner_dir = std::to_string(top) + "/bionic/tools/versioner";
+    header_dir = versioner_dir + "/current";
+    dependency_dir = versioner_dir + "/dependencies";
+    if (platform_dir.empty()) {
+      platform_dir = versioner_dir + "/platforms";
+    }
+  } else {
+    header_dir = argv[optind];
+
+    if (argc - optind == 2) {
+      dependency_dir = argv[optind + 1];
+    }
+  }
+
+  if (selected_levels.empty()) {
+    selected_levels = supported_levels;
+  }
+
+  if (selected_architectures.empty()) {
+    selected_architectures = supported_archs;
+  }
+
+
+  struct stat st;
+  if (stat(header_dir.c_str(), &st) != 0) {
+    err(1, "failed to stat '%s'", header_dir.c_str());
+  } else if (!S_ISDIR(st.st_mode)) {
+    errx(1, "'%s' is not a directory", header_dir.c_str());
+  }
+
+  std::set<CompilationType> compilation_types;
+  DeclarationDatabase declaration_database;
+  NdkSymbolDatabase symbol_database;
+
+  compilation_types = generateCompilationTypes(selected_architectures, selected_levels);
+
+  // Do this before compiling so that we can early exit if the platforms don't match what we
+  // expect.
+  if (!platform_dir.empty()) {
+    symbol_database = parsePlatforms(compilation_types, platform_dir);
+  }
+
+  bool failed = false;
+  declaration_database = compileHeaders(compilation_types, header_dir, dependency_dir, &failed);
+
+  if (!sanityCheck(compilation_types, declaration_database)) {
+    printf("versioner: sanity check failed\n");
+    failed = true;
+  }
+
+  if (!platform_dir.empty()) {
+    if (!checkVersions(compilation_types, declaration_database, symbol_database)) {
+      printf("versioner: version check failed\n");
+      failed = true;
+    }
+  }
+
+  return failed;
+}
diff --git a/tools/versioner/src/versioner.h b/tools/versioner/src/versioner.h
new file mode 100644
index 0000000..ced9b79
--- /dev/null
+++ b/tools/versioner/src/versioner.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright 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.
+ */
+
+#pragma once
+
+#include <map>
+#include <set>
+#include <string>
+#include <unordered_map>
+#include <unordered_set>
+
+extern bool verbose;
+
+static const std::set<std::string> supported_archs = {
+  "arm", "arm64", "mips", "mips64", "x86", "x86_64",
+};
+
+static std::unordered_map<std::string, std::string> arch_targets = {
+  { "arm", "arm-linux-androideabi" },
+  { "arm64", "aarch64-linux-android" },
+  { "mips", "mipsel-linux-android" },
+  { "mips64", "mips64el-linux-android" },
+  { "x86", "i686-linux-android" },
+  { "x86_64", "x86_64-linux-android" },
+};
+
+static const std::set<int> supported_levels = { 9, 12, 13, 14, 15, 16, 17, 18, 19, 21, 23, 24 };
+
+// Non-const for the convenience of being able to index with operator[].
+static std::map<std::string, int> arch_min_api = {
+  { "arm", 9 },
+  { "arm64", 21 },
+  { "mips", 9 },
+  { "mips64", 21 },
+  { "x86", 9 },
+  { "x86_64", 21 },
+};
+
+static const std::unordered_map<std::string, std::set<std::string>> header_blacklist = {
+  // Internal header.
+  { "sys/_system_properties.h", supported_archs },
+
+  // time64.h #errors when included on LP64 archs.
+  { "time64.h", { "arm64", "mips64", "x86_64" } },
+};
+
+static const std::unordered_set<std::string> missing_symbol_whitelist = {
+  // atexit comes from crtbegin.
+  "atexit",
+};
diff --git a/tools/versioner/tests/arch_specific/headers/foo.h b/tools/versioner/tests/arch_specific/headers/foo.h
new file mode 100644
index 0000000..34035b4
--- /dev/null
+++ b/tools/versioner/tests/arch_specific/headers/foo.h
@@ -0,0 +1,5 @@
+int foo();
+
+#if defined(__i386__)
+int bar();
+#endif
diff --git a/tools/versioner/tests/arch_specific/platforms/android-9/arch-arm/symbols/libc.so.functions.txt b/tools/versioner/tests/arch_specific/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
new file mode 100644
index 0000000..257cc56
--- /dev/null
+++ b/tools/versioner/tests/arch_specific/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
@@ -0,0 +1 @@
+foo
diff --git a/tools/versioner/tests/arch_specific/platforms/android-9/arch-x86/symbols/libc.so.functions.txt b/tools/versioner/tests/arch_specific/platforms/android-9/arch-x86/symbols/libc.so.functions.txt
new file mode 100644
index 0000000..3bd1f0e
--- /dev/null
+++ b/tools/versioner/tests/arch_specific/platforms/android-9/arch-x86/symbols/libc.so.functions.txt
@@ -0,0 +1,2 @@
+foo
+bar
diff --git a/tools/versioner/tests/arch_specific/run.sh b/tools/versioner/tests/arch_specific/run.sh
new file mode 100644
index 0000000..6d97fb0
--- /dev/null
+++ b/tools/versioner/tests/arch_specific/run.sh
@@ -0,0 +1 @@
+versioner headers -p platforms -r arm -r x86 -a 9
diff --git a/tools/versioner/tests/compilation_error/expected_fail b/tools/versioner/tests/compilation_error/expected_fail
new file mode 100644
index 0000000..62a643f
--- /dev/null
+++ b/tools/versioner/tests/compilation_error/expected_fail
@@ -0,0 +1,2 @@
+versioner: compilation failure for arm-9 in /android/aosp/bionic/tools/versioner/tests/compilation_error/headers/foo.h
+versioner: compilation generated warnings or errors
diff --git a/tools/versioner/tests/compilation_error/headers/foo.h b/tools/versioner/tests/compilation_error/headers/foo.h
new file mode 100644
index 0000000..c8c1473
--- /dev/null
+++ b/tools/versioner/tests/compilation_error/headers/foo.h
@@ -0,0 +1 @@
+#error foo
diff --git a/tools/versioner/tests/compilation_error/platforms/android-9/arch-arm/symbols/libc.so.functions.txt b/tools/versioner/tests/compilation_error/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
new file mode 100644
index 0000000..257cc56
--- /dev/null
+++ b/tools/versioner/tests/compilation_error/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
@@ -0,0 +1 @@
+foo
diff --git a/tools/versioner/tests/compilation_error/run.sh b/tools/versioner/tests/compilation_error/run.sh
new file mode 100644
index 0000000..8babb73
--- /dev/null
+++ b/tools/versioner/tests/compilation_error/run.sh
@@ -0,0 +1 @@
+versioner headers -p platforms -r arm -a 9
diff --git a/tools/versioner/tests/dependencies/dependencies/arm/archdep/archdep.h b/tools/versioner/tests/dependencies/dependencies/arm/archdep/archdep.h
new file mode 100644
index 0000000..2005972
--- /dev/null
+++ b/tools/versioner/tests/dependencies/dependencies/arm/archdep/archdep.h
@@ -0,0 +1 @@
+typedef int arm_t;
diff --git a/tools/versioner/tests/dependencies/dependencies/common/foo/foodep.h b/tools/versioner/tests/dependencies/dependencies/common/foo/foodep.h
new file mode 100644
index 0000000..9feeb6c
--- /dev/null
+++ b/tools/versioner/tests/dependencies/dependencies/common/foo/foodep.h
@@ -0,0 +1 @@
+typedef int foo_t;
diff --git a/tools/versioner/tests/dependencies/dependencies/x86/archdep/archdep.h b/tools/versioner/tests/dependencies/dependencies/x86/archdep/archdep.h
new file mode 100644
index 0000000..5cc7de2
--- /dev/null
+++ b/tools/versioner/tests/dependencies/dependencies/x86/archdep/archdep.h
@@ -0,0 +1 @@
+typedef int x86_t;
diff --git a/tools/versioner/tests/dependencies/headers/foo.h b/tools/versioner/tests/dependencies/headers/foo.h
new file mode 100644
index 0000000..4491f1c
--- /dev/null
+++ b/tools/versioner/tests/dependencies/headers/foo.h
@@ -0,0 +1,8 @@
+#include <archdep.h>
+#include <foodep.h>
+
+#if defined(__i386__)
+x86_t foo(foo_t);
+#elif defined(__arm__)
+arm_t foo(foo_t);
+#endif
diff --git a/tools/versioner/tests/dependencies/platforms/android-9/arch-arm/symbols/libc.so.functions.txt b/tools/versioner/tests/dependencies/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
new file mode 100644
index 0000000..257cc56
--- /dev/null
+++ b/tools/versioner/tests/dependencies/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
@@ -0,0 +1 @@
+foo
diff --git a/tools/versioner/tests/dependencies/platforms/android-9/arch-x86/symbols/libc.so.functions.txt b/tools/versioner/tests/dependencies/platforms/android-9/arch-x86/symbols/libc.so.functions.txt
new file mode 100644
index 0000000..257cc56
--- /dev/null
+++ b/tools/versioner/tests/dependencies/platforms/android-9/arch-x86/symbols/libc.so.functions.txt
@@ -0,0 +1 @@
+foo
diff --git a/tools/versioner/tests/dependencies/run.sh b/tools/versioner/tests/dependencies/run.sh
new file mode 100644
index 0000000..3a3dda8
--- /dev/null
+++ b/tools/versioner/tests/dependencies/run.sh
@@ -0,0 +1 @@
+versioner headers dependencies -p platforms -r arm -r x86 -a 9
diff --git a/tools/versioner/tests/errordecl/headers/foo.h b/tools/versioner/tests/errordecl/headers/foo.h
new file mode 100644
index 0000000..c466420
--- /dev/null
+++ b/tools/versioner/tests/errordecl/headers/foo.h
@@ -0,0 +1 @@
+int foo() __attribute__((unavailable));
diff --git a/libc/arch-arm64/cortex-a53/cortex-a53.mk b/tools/versioner/tests/errordecl/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
similarity index 100%
rename from libc/arch-arm64/cortex-a53/cortex-a53.mk
rename to tools/versioner/tests/errordecl/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
diff --git a/tools/versioner/tests/errordecl/run.sh b/tools/versioner/tests/errordecl/run.sh
new file mode 100644
index 0000000..0dea98f
--- /dev/null
+++ b/tools/versioner/tests/errordecl/run.sh
@@ -0,0 +1 @@
+versioner -v headers -p platforms -r arm -a 9
diff --git a/tools/versioner/tests/future/headers/foo.h b/tools/versioner/tests/future/headers/foo.h
new file mode 100644
index 0000000..b5113f4
--- /dev/null
+++ b/tools/versioner/tests/future/headers/foo.h
@@ -0,0 +1 @@
+int foo() __attribute__((availability(android, introduced = 10000)));
diff --git a/libc/arch-arm64/cortex-a53/cortex-a53.mk b/tools/versioner/tests/future/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
similarity index 100%
copy from libc/arch-arm64/cortex-a53/cortex-a53.mk
copy to tools/versioner/tests/future/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
diff --git a/tools/versioner/tests/future/run.sh b/tools/versioner/tests/future/run.sh
new file mode 100644
index 0000000..0dea98f
--- /dev/null
+++ b/tools/versioner/tests/future/run.sh
@@ -0,0 +1 @@
+versioner -v headers -p platforms -r arm -a 9
diff --git a/tools/versioner/tests/future_arch/headers/foo.h b/tools/versioner/tests/future_arch/headers/foo.h
new file mode 100644
index 0000000..6740975
--- /dev/null
+++ b/tools/versioner/tests/future_arch/headers/foo.h
@@ -0,0 +1,5 @@
+#if defined(__arm__)
+int foo() __attribute__((availability(android, introduced = 9)));
+#else
+int foo() __attribute__((availability(android, introduced = 10000)));
+#endif
diff --git a/tools/versioner/tests/future_arch/platforms/android-9/arch-arm/symbols/libc.so.functions.txt b/tools/versioner/tests/future_arch/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
new file mode 100644
index 0000000..257cc56
--- /dev/null
+++ b/tools/versioner/tests/future_arch/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
@@ -0,0 +1 @@
+foo
diff --git a/libc/arch-arm64/cortex-a53/cortex-a53.mk b/tools/versioner/tests/future_arch/platforms/android-9/arch-x86/symbols/libc.so.functions.txt
similarity index 100%
copy from libc/arch-arm64/cortex-a53/cortex-a53.mk
copy to tools/versioner/tests/future_arch/platforms/android-9/arch-x86/symbols/libc.so.functions.txt
diff --git a/tools/versioner/tests/future_arch/run.sh b/tools/versioner/tests/future_arch/run.sh
new file mode 100644
index 0000000..36846da
--- /dev/null
+++ b/tools/versioner/tests/future_arch/run.sh
@@ -0,0 +1 @@
+versioner -v headers -p platforms -r arm -r x86 -a 9
diff --git a/tools/versioner/tests/inline/headers/foo.h b/tools/versioner/tests/inline/headers/foo.h
new file mode 100644
index 0000000..7a48a72
--- /dev/null
+++ b/tools/versioner/tests/inline/headers/foo.h
@@ -0,0 +1,7 @@
+#if __ANDROID_API__ <= 9
+static int foo() __attribute__((availability(android, introduced = 9))) {
+  return 0;
+}
+#else
+int foo() __attribute__((availability(android, introduced = 9)));
+#endif
diff --git a/tools/versioner/tests/inline/platforms/android-12/arch-arm/symbols/libc.so.functions.txt b/tools/versioner/tests/inline/platforms/android-12/arch-arm/symbols/libc.so.functions.txt
new file mode 100644
index 0000000..257cc56
--- /dev/null
+++ b/tools/versioner/tests/inline/platforms/android-12/arch-arm/symbols/libc.so.functions.txt
@@ -0,0 +1 @@
+foo
diff --git a/libc/arch-arm64/cortex-a53/cortex-a53.mk b/tools/versioner/tests/inline/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
similarity index 100%
copy from libc/arch-arm64/cortex-a53/cortex-a53.mk
copy to tools/versioner/tests/inline/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
diff --git a/tools/versioner/tests/inline/run.sh b/tools/versioner/tests/inline/run.sh
new file mode 100644
index 0000000..914c55d
--- /dev/null
+++ b/tools/versioner/tests/inline/run.sh
@@ -0,0 +1 @@
+versioner headers -p platforms -r arm -a 9 -a 12
diff --git a/tools/versioner/tests/inline_unavailable/headers/foo.h b/tools/versioner/tests/inline_unavailable/headers/foo.h
new file mode 100644
index 0000000..6800dd0
--- /dev/null
+++ b/tools/versioner/tests/inline_unavailable/headers/foo.h
@@ -0,0 +1,3 @@
+static int foo() __attribute__((availability(android, introduced = 9))) {
+  return 0;
+}
diff --git a/libc/arch-arm64/cortex-a53/cortex-a53.mk b/tools/versioner/tests/inline_unavailable/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
similarity index 100%
copy from libc/arch-arm64/cortex-a53/cortex-a53.mk
copy to tools/versioner/tests/inline_unavailable/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
diff --git a/tools/versioner/tests/inline_unavailable/run.sh b/tools/versioner/tests/inline_unavailable/run.sh
new file mode 100644
index 0000000..0dea98f
--- /dev/null
+++ b/tools/versioner/tests/inline_unavailable/run.sh
@@ -0,0 +1 @@
+versioner -v headers -p platforms -r arm -a 9
diff --git a/tools/versioner/tests/inline_version_mismatch/expected_fail b/tools/versioner/tests/inline_version_mismatch/expected_fail
new file mode 100644
index 0000000..7f0709c
--- /dev/null
+++ b/tools/versioner/tests/inline_version_mismatch/expected_fail
@@ -0,0 +1,2 @@
+foo: availability mismatch between arm-9 and arm-12: [introduced = 9] before, [introduced = 10] after
+versioner: sanity check failed
diff --git a/tools/versioner/tests/inline_version_mismatch/headers/foo.h b/tools/versioner/tests/inline_version_mismatch/headers/foo.h
new file mode 100644
index 0000000..be7cc2c
--- /dev/null
+++ b/tools/versioner/tests/inline_version_mismatch/headers/foo.h
@@ -0,0 +1,7 @@
+#if __ANDROID_API__ <= 9
+static int foo() __attribute__((availability(android, introduced = 9))) {
+  return 0;
+}
+#else
+int foo() __attribute__((availability(android, introduced = 10)));
+#endif
diff --git a/tools/versioner/tests/inline_version_mismatch/platforms/android-12/arch-arm/symbols/libc.so.functions.txt b/tools/versioner/tests/inline_version_mismatch/platforms/android-12/arch-arm/symbols/libc.so.functions.txt
new file mode 100644
index 0000000..257cc56
--- /dev/null
+++ b/tools/versioner/tests/inline_version_mismatch/platforms/android-12/arch-arm/symbols/libc.so.functions.txt
@@ -0,0 +1 @@
+foo
diff --git a/libc/arch-arm64/cortex-a53/cortex-a53.mk b/tools/versioner/tests/inline_version_mismatch/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
similarity index 100%
copy from libc/arch-arm64/cortex-a53/cortex-a53.mk
copy to tools/versioner/tests/inline_version_mismatch/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
diff --git a/tools/versioner/tests/inline_version_mismatch/run.sh b/tools/versioner/tests/inline_version_mismatch/run.sh
new file mode 100644
index 0000000..914c55d
--- /dev/null
+++ b/tools/versioner/tests/inline_version_mismatch/run.sh
@@ -0,0 +1 @@
+versioner headers -p platforms -r arm -a 9 -a 12
diff --git a/tools/versioner/tests/missing_api/expected_fail b/tools/versioner/tests/missing_api/expected_fail
new file mode 100644
index 0000000..85c07f5
--- /dev/null
+++ b/tools/versioner/tests/missing_api/expected_fail
@@ -0,0 +1,2 @@
+foo: declaration marked available but symbol missing in [arm-12]
+versioner: version check failed
diff --git a/tools/versioner/tests/missing_api/headers/foo.h b/tools/versioner/tests/missing_api/headers/foo.h
new file mode 100644
index 0000000..2998c8e
--- /dev/null
+++ b/tools/versioner/tests/missing_api/headers/foo.h
@@ -0,0 +1 @@
+int foo() __attribute__((availability(android, introduced = 9)));
diff --git a/libc/arch-arm64/cortex-a53/cortex-a53.mk b/tools/versioner/tests/missing_api/platforms/android-12/arch-arm/symbols/libc.so.functions.txt
similarity index 100%
copy from libc/arch-arm64/cortex-a53/cortex-a53.mk
copy to tools/versioner/tests/missing_api/platforms/android-12/arch-arm/symbols/libc.so.functions.txt
diff --git a/tools/versioner/tests/missing_api/platforms/android-9/arch-arm/symbols/libc.so.functions.txt b/tools/versioner/tests/missing_api/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
new file mode 100644
index 0000000..257cc56
--- /dev/null
+++ b/tools/versioner/tests/missing_api/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
@@ -0,0 +1 @@
+foo
diff --git a/tools/versioner/tests/missing_api/run.sh b/tools/versioner/tests/missing_api/run.sh
new file mode 100644
index 0000000..914c55d
--- /dev/null
+++ b/tools/versioner/tests/missing_api/run.sh
@@ -0,0 +1 @@
+versioner headers -p platforms -r arm -a 9 -a 12
diff --git a/tools/versioner/tests/missing_arch/expected_fail b/tools/versioner/tests/missing_arch/expected_fail
new file mode 100644
index 0000000..56de9d9
--- /dev/null
+++ b/tools/versioner/tests/missing_arch/expected_fail
@@ -0,0 +1,2 @@
+foo: declaration marked available but symbol missing in [x86-9]
+versioner: version check failed
diff --git a/tools/versioner/tests/missing_arch/headers/foo.h b/tools/versioner/tests/missing_arch/headers/foo.h
new file mode 100644
index 0000000..5d5f8f0
--- /dev/null
+++ b/tools/versioner/tests/missing_arch/headers/foo.h
@@ -0,0 +1 @@
+int foo();
diff --git a/tools/versioner/tests/missing_arch/platforms/android-9/arch-arm/symbols/libc.so.functions.txt b/tools/versioner/tests/missing_arch/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
new file mode 100644
index 0000000..257cc56
--- /dev/null
+++ b/tools/versioner/tests/missing_arch/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
@@ -0,0 +1 @@
+foo
diff --git a/libc/arch-arm64/cortex-a53/cortex-a53.mk b/tools/versioner/tests/missing_arch/platforms/android-9/arch-x86/symbols/libc.so.functions.txt
similarity index 100%
copy from libc/arch-arm64/cortex-a53/cortex-a53.mk
copy to tools/versioner/tests/missing_arch/platforms/android-9/arch-x86/symbols/libc.so.functions.txt
diff --git a/tools/versioner/tests/missing_arch/run.sh b/tools/versioner/tests/missing_arch/run.sh
new file mode 100644
index 0000000..6d97fb0
--- /dev/null
+++ b/tools/versioner/tests/missing_arch/run.sh
@@ -0,0 +1 @@
+versioner headers -p platforms -r arm -r x86 -a 9
diff --git a/tools/versioner/tests/multiple_decl/headers/bar.h b/tools/versioner/tests/multiple_decl/headers/bar.h
new file mode 100644
index 0000000..95f0174
--- /dev/null
+++ b/tools/versioner/tests/multiple_decl/headers/bar.h
@@ -0,0 +1 @@
+int foo() __attribute__((availability(android, obsoleted = 12)));
diff --git a/tools/versioner/tests/multiple_decl/headers/foo.h b/tools/versioner/tests/multiple_decl/headers/foo.h
new file mode 100644
index 0000000..95f0174
--- /dev/null
+++ b/tools/versioner/tests/multiple_decl/headers/foo.h
@@ -0,0 +1 @@
+int foo() __attribute__((availability(android, obsoleted = 12)));
diff --git a/tools/versioner/tests/multiple_decl/platforms/android-9/arch-arm/symbols/libc.so.functions.txt b/tools/versioner/tests/multiple_decl/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
new file mode 100644
index 0000000..257cc56
--- /dev/null
+++ b/tools/versioner/tests/multiple_decl/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
@@ -0,0 +1 @@
+foo
diff --git a/tools/versioner/tests/multiple_decl/run.sh b/tools/versioner/tests/multiple_decl/run.sh
new file mode 100644
index 0000000..8babb73
--- /dev/null
+++ b/tools/versioner/tests/multiple_decl/run.sh
@@ -0,0 +1 @@
+versioner headers -p platforms -r arm -a 9
diff --git a/tools/versioner/tests/multiple_decl_mismatch/expected_fail b/tools/versioner/tests/multiple_decl_mismatch/expected_fail
new file mode 100644
index 0000000..6d0d209
--- /dev/null
+++ b/tools/versioner/tests/multiple_decl_mismatch/expected_fail
@@ -0,0 +1,5 @@
+foo: availability mismatch for arm-9
+    foo declared in 2 locations:
+        extern function declaration @ headers/bar.h:1:5	[obsoleted = 12]
+        extern function declaration @ headers/foo.h:1:5	[obsoleted = 9]
+versioner: sanity check failed
diff --git a/tools/versioner/tests/multiple_decl_mismatch/headers/bar.h b/tools/versioner/tests/multiple_decl_mismatch/headers/bar.h
new file mode 100644
index 0000000..95f0174
--- /dev/null
+++ b/tools/versioner/tests/multiple_decl_mismatch/headers/bar.h
@@ -0,0 +1 @@
+int foo() __attribute__((availability(android, obsoleted = 12)));
diff --git a/tools/versioner/tests/multiple_decl_mismatch/headers/foo.h b/tools/versioner/tests/multiple_decl_mismatch/headers/foo.h
new file mode 100644
index 0000000..9c81a89
--- /dev/null
+++ b/tools/versioner/tests/multiple_decl_mismatch/headers/foo.h
@@ -0,0 +1 @@
+int foo() __attribute__((availability(android, obsoleted = 9)));
diff --git a/tools/versioner/tests/multiple_decl_mismatch/platforms/android-9/arch-arm/symbols/libc.so.functions.txt b/tools/versioner/tests/multiple_decl_mismatch/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
new file mode 100644
index 0000000..257cc56
--- /dev/null
+++ b/tools/versioner/tests/multiple_decl_mismatch/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
@@ -0,0 +1 @@
+foo
diff --git a/tools/versioner/tests/multiple_decl_mismatch/run.sh b/tools/versioner/tests/multiple_decl_mismatch/run.sh
new file mode 100644
index 0000000..8babb73
--- /dev/null
+++ b/tools/versioner/tests/multiple_decl_mismatch/run.sh
@@ -0,0 +1 @@
+versioner headers -p platforms -r arm -a 9
diff --git a/tools/versioner/tests/obsoleted/headers/foo.h b/tools/versioner/tests/obsoleted/headers/foo.h
new file mode 100644
index 0000000..c190629
--- /dev/null
+++ b/tools/versioner/tests/obsoleted/headers/foo.h
@@ -0,0 +1 @@
+int foo() __attribute__((availability(android, introduced = 9, obsoleted = 11)));
diff --git a/libc/arch-arm64/cortex-a53/cortex-a53.mk b/tools/versioner/tests/obsoleted/platforms/android-12/arch-arm/symbols/libc.so.functions.txt
similarity index 100%
copy from libc/arch-arm64/cortex-a53/cortex-a53.mk
copy to tools/versioner/tests/obsoleted/platforms/android-12/arch-arm/symbols/libc.so.functions.txt
diff --git a/tools/versioner/tests/obsoleted/platforms/android-9/arch-arm/symbols/libc.so.functions.txt b/tools/versioner/tests/obsoleted/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
new file mode 100644
index 0000000..257cc56
--- /dev/null
+++ b/tools/versioner/tests/obsoleted/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
@@ -0,0 +1 @@
+foo
diff --git a/tools/versioner/tests/obsoleted/run.sh b/tools/versioner/tests/obsoleted/run.sh
new file mode 100644
index 0000000..914c55d
--- /dev/null
+++ b/tools/versioner/tests/obsoleted/run.sh
@@ -0,0 +1 @@
+versioner headers -p platforms -r arm -a 9 -a 12
diff --git a/tools/versioner/tests/smoke/headers/foo.h b/tools/versioner/tests/smoke/headers/foo.h
new file mode 100644
index 0000000..2998c8e
--- /dev/null
+++ b/tools/versioner/tests/smoke/headers/foo.h
@@ -0,0 +1 @@
+int foo() __attribute__((availability(android, introduced = 9)));
diff --git a/tools/versioner/tests/smoke/platforms/android-9/arch-arm/symbols/libc.so.functions.txt b/tools/versioner/tests/smoke/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
new file mode 100644
index 0000000..257cc56
--- /dev/null
+++ b/tools/versioner/tests/smoke/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
@@ -0,0 +1 @@
+foo
diff --git a/tools/versioner/tests/smoke/run.sh b/tools/versioner/tests/smoke/run.sh
new file mode 100644
index 0000000..8babb73
--- /dev/null
+++ b/tools/versioner/tests/smoke/run.sh
@@ -0,0 +1 @@
+versioner headers -p platforms -r arm -a 9
diff --git a/tools/versioner/tests/version_mismatch/expected_fail b/tools/versioner/tests/version_mismatch/expected_fail
new file mode 100644
index 0000000..7f0709c
--- /dev/null
+++ b/tools/versioner/tests/version_mismatch/expected_fail
@@ -0,0 +1,2 @@
+foo: availability mismatch between arm-9 and arm-12: [introduced = 9] before, [introduced = 10] after
+versioner: sanity check failed
diff --git a/tools/versioner/tests/version_mismatch/headers/foo.h b/tools/versioner/tests/version_mismatch/headers/foo.h
new file mode 100644
index 0000000..4d23417
--- /dev/null
+++ b/tools/versioner/tests/version_mismatch/headers/foo.h
@@ -0,0 +1,5 @@
+#if __ANDROID_API__ <= 9
+int foo() __attribute__((availability(android, introduced = 9)));
+#else
+int foo() __attribute__((availability(android, introduced = 10)));
+#endif
diff --git a/tools/versioner/tests/version_mismatch/platforms/android-12/arch-arm/symbols/libc.so.functions.txt b/tools/versioner/tests/version_mismatch/platforms/android-12/arch-arm/symbols/libc.so.functions.txt
new file mode 100644
index 0000000..257cc56
--- /dev/null
+++ b/tools/versioner/tests/version_mismatch/platforms/android-12/arch-arm/symbols/libc.so.functions.txt
@@ -0,0 +1 @@
+foo
diff --git a/tools/versioner/tests/version_mismatch/platforms/android-9/arch-arm/symbols/libc.so.functions.txt b/tools/versioner/tests/version_mismatch/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
new file mode 100644
index 0000000..257cc56
--- /dev/null
+++ b/tools/versioner/tests/version_mismatch/platforms/android-9/arch-arm/symbols/libc.so.functions.txt
@@ -0,0 +1 @@
+foo
diff --git a/tools/versioner/tests/version_mismatch/run.sh b/tools/versioner/tests/version_mismatch/run.sh
new file mode 100644
index 0000000..914c55d
--- /dev/null
+++ b/tools/versioner/tests/version_mismatch/run.sh
@@ -0,0 +1 @@
+versioner headers -p platforms -r arm -a 9 -a 12