Merge "Do not return with stack address in global variable."
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.mk b/Android.mk
deleted file mode 100644
index f86f065..0000000
--- a/Android.mk
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# 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))
diff --git a/libc/Android.mk b/libc/Android.mk
deleted file mode 100644
index 6bb6f43..0000000
--- a/libc/Android.mk
+++ /dev/null
@@ -1,1481 +0,0 @@
-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 \
-
-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/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 \
-    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/mblen.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/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 \
-    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/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 \
-    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/symlink.cpp \
-    bionic/sync_file_range.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/__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/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/base64.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/getsubopt.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 \
-    -Wno-deprecated-declarations \
-
-use_clang := true
-
-# 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.cpp
-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 \
-    -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
-
-# 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)
-
-# ========================================================
-# 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)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/libc/arch-arm/arm.mk b/libc/arch-arm/arm.mk
deleted file mode 100644
index 6c11169..0000000
--- a/libc/arch-arm/arm.mk
+++ /dev/null
@@ -1,62 +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 \
-
-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/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/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/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/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/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-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/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-mips/mips.mk b/libc/arch-mips/mips.mk
deleted file mode 100644
index b98d525..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/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 \
-
-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-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-x86/atom/atom.mk b/libc/arch-x86/atom/atom.mk
deleted file mode 100644
index 4de4185..0000000
--- a/libc/arch-x86/atom/atom.mk
+++ /dev/null
@@ -1,23 +0,0 @@
-libc_bionic_src_files_x86 += \
-    arch-x86/atom/string/sse2-memset-atom.S \
-    arch-x86/atom/string/sse2-strlen-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-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/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/x86.mk b/libc/arch-x86/x86.mk
deleted file mode 100644
index 2f63446..0000000
--- a/libc/arch-x86/x86.mk
+++ /dev/null
@@ -1,138 +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-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/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/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/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/android/legacy_signal_inlines.h b/libc/include/android/legacy_signal_inlines.h
index bf895da..edc6259 100644
--- a/libc/include/android/legacy_signal_inlines.h
+++ b/libc/include/android/legacy_signal_inlines.h
@@ -34,11 +34,12 @@
 #include <string.h>
 #include <sys/cdefs.h>
 
-#if __ANDROID_API__ < 21
 
 __BEGIN_DECLS
 
-extern sighandler_t bsd_signal(int signum, sighandler_t handler);
+extern sighandler_t bsd_signal(int signum, sighandler_t handler) __REMOVED_IN(21);
+
+#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. */
@@ -97,7 +98,8 @@
   return bsd_signal(s, f);
 }
 
+#endif /* __ANDROID_API__ < 21 */
+
 __END_DECLS
 
-#endif
 #endif /* _ANDROID_LEGACY_SIGNAL_INLINES_H_ */
diff --git a/libc/include/fcntl.h b/libc/include/fcntl.h
index c8030f1..ee4d5e2 100644
--- a/libc/include/fcntl.h
+++ b/libc/include/fcntl.h
@@ -87,13 +87,13 @@
 extern int posix_fallocate64(int, off64_t, off64_t) __INTRODUCED_IN(21);
 
 #if defined(__USE_GNU)
-ssize_t readahead(int, off64_t, size_t) __INTRODUCED_IN(21);
+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
 
-extern int __open_2(const char*, int) __INTRODUCED_IN(21);
+extern int __open_2(const char*, int) __INTRODUCED_IN(17);
 extern int __open_real(const char*, int, ...) __RENAME(open);
-extern int __openat_2(int, const char*, int) __INTRODUCED_IN(21);
+extern int __openat_2(int, const char*, int) __INTRODUCED_IN(17);
 extern 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");
diff --git a/libc/include/fenv.h b/libc/include/fenv.h
index e51f9b6..d4f6994 100644
--- a/libc/include/fenv.h
+++ b/libc/include/fenv.h
@@ -36,23 +36,27 @@
 __BEGIN_DECLS
 #pragma GCC visibility push(default)
 
-int feclearexcept(int) __INTRODUCED_IN(21);
-int fegetexceptflag(fexcept_t*, int) __INTRODUCED_IN(21);
-int feraiseexcept(int) __INTRODUCED_IN(21);
-int fesetexceptflag(const fexcept_t*, int) __INTRODUCED_IN(21);
-int fetestexcept(int) __INTRODUCED_IN(21);
+// 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(21);
-int fesetround(int) __INTRODUCED_IN(21);
+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(21);
-int feholdexcept(fenv_t*) __INTRODUCED_IN(21);
-int fesetenv(const fenv_t*) __INTRODUCED_IN(21);
-int feupdateenv(const fenv_t*) __INTRODUCED_IN(21);
+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(21);
-int fedisableexcept(int) __INTRODUCED_IN(21);
-int fegetexcept(void) __INTRODUCED_IN(21);
+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
diff --git a/libc/include/ftw.h b/libc/include/ftw.h
index ebd59f5..ac901cc 100644
--- a/libc/include/ftw.h
+++ b/libc/include/ftw.h
@@ -54,9 +54,9 @@
 };
 
 __BEGIN_DECLS
-int ftw(const char*, int (*)(const char*, const struct stat*, int), int) __INTRODUCED_IN(21);
+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(21);
+  __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);
diff --git a/libc/include/inttypes.h b/libc/include/inttypes.h
index 4752c52..54b5ee2 100644
--- a/libc/include/inttypes.h
+++ b/libc/include/inttypes.h
@@ -254,8 +254,8 @@
 } imaxdiv_t;
 
 __BEGIN_DECLS
-intmax_t imaxabs(intmax_t) __pure2 __INTRODUCED_IN(21);
-imaxdiv_t imaxdiv(intmax_t, intmax_t) __pure2 __INTRODUCED_IN(21);
+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) __INTRODUCED_IN(21);
diff --git a/libc/include/malloc.h b/libc/include/malloc.h
index 02e2da7..8e6cef9 100644
--- a/libc/include/malloc.h
+++ b/libc/include/malloc.h
@@ -29,7 +29,7 @@
 extern void free(void* p);
 
 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) __INTRODUCED_IN(21);
+extern size_t malloc_usable_size(const void* p) __INTRODUCED_IN(17);
 
 #ifndef STRUCT_MALLINFO_DECLARED
 #define STRUCT_MALLINFO_DECLARED 1
diff --git a/libc/include/math.h b/libc/include/math.h
index 97539d7..eae1d3b 100644
--- a/libc/include/math.h
+++ b/libc/include/math.h
@@ -127,13 +127,6 @@
 #endif
 #endif /* __BSD_VISIBLE */
 
-/* scalbln, scalbnf, and scalblnl were unavailable on x86 until API level 18 */
-#if defined(__i386__)
-#define __INTRODUCED_IN_X86 __INTRODUCED_IN
-#else
-#define __INTRODUCED_IN_X86(x)
-#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
@@ -212,7 +205,10 @@
 double	logb(double);
 long	lrint(double);
 long	lround(double);
-double nan(const char*) __pure2 __INTRODUCED_IN(13);
+
+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 *);
@@ -243,8 +239,8 @@
 double	fmin(double, double) __pure2;
 double	nearbyint(double);
 double	round(double);
-double	scalbln(double, long);
-double scalbn(double, int) __INTRODUCED_IN_X86(18);
+double scalbln(double, long) __INTRODUCED_IN_X86(18);
+double scalbn(double, int);
 double	tgamma(double);
 double	trunc(double);
 #endif
@@ -310,7 +306,7 @@
 float	erfcf(float);
 float	hypotf(float, float);
 float	lgammaf(float);
-float tgammaf(float) __INTRODUCED_IN(13);
+float tgammaf(float) __INTRODUCED_IN_ARM(13) __INTRODUCED_IN_MIPS(13) __INTRODUCED_IN_X86(9);
 
 float	acoshf(float);
 float	asinhf(float);
@@ -322,14 +318,15 @@
 long long llroundf(float);
 long	lrintf(float);
 long	lroundf(float);
-float nanf(const char*) __pure2 __INTRODUCED_IN(13);
+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);
-float scalbnf(float, int) __INTRODUCED_IN_X86(18);
+float	scalblnf(float, long) __INTRODUCED_IN_X86(18);
+float scalbnf(float, int);
 float	truncf(float);
 
 float	fdimf(float, float);
@@ -421,8 +418,8 @@
 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);
-long double scalbnl(long double, int) __INTRODUCED_IN_X86(18);
+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);
diff --git a/libc/include/pthread.h b/libc/include/pthread.h
index b4a48f0..3262bd1 100644
--- a/libc/include/pthread.h
+++ b/libc/include/pthread.h
@@ -133,7 +133,7 @@
 
 __BEGIN_DECLS
 
-int pthread_atfork(void (*)(void), void (*)(void), void (*)(void)) __INTRODUCED_IN(21);
+int pthread_atfork(void (*)(void), void (*)(void), void (*)(void)) __INTRODUCED_IN(12);
 
 int pthread_attr_destroy(pthread_attr_t* _Nonnull);
 int pthread_attr_getdetachstate(const pthread_attr_t* _Nonnull, int* _Nonnull);
diff --git a/libc/include/pwd.h b/libc/include/pwd.h
index b45780e..e881129 100644
--- a/libc/include/pwd.h
+++ b/libc/include/pwd.h
@@ -122,8 +122,8 @@
 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(21);
-int getpwuid_r(uid_t, struct passwd*, char*, size_t, struct passwd**) __INTRODUCED_IN(21);
+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/sched.h b/libc/include/sched.h
index a1f1dfa..7cb11a7 100644
--- a/libc/include/sched.h
+++ b/libc/include/sched.h
@@ -52,9 +52,10 @@
 
 #if defined(__USE_GNU)
 
-extern int clone(int (*)(void*), void*, int, void*, ...);
-extern int unshare(int) __INTRODUCED_IN(21);
-extern int sched_getcpu(void) __INTRODUCED_IN(21);
+extern int clone(int (*)(void*), void*, int, void*, ...) __INTRODUCED_IN_ARM(9)
+    __INTRODUCED_IN_MIPS(12) __INTRODUCED_IN_X86(17);
+extern int unshare(int) __INTRODUCED_IN(17);
+extern int sched_getcpu(void) __INTRODUCED_IN(12);
 extern int setns(int, int) __INTRODUCED_IN(21);
 
 #ifdef __LP64__
@@ -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) __INTRODUCED_IN(21);
-
-extern int sched_getaffinity(pid_t pid, size_t setsize, cpu_set_t* set) __INTRODUCED_IN(21);
+extern int sched_setaffinity(pid_t pid, size_t setsize, const cpu_set_t* set) __INTRODUCED_IN(12);
+extern 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) __INTRODUCED_IN(21);
-extern void __sched_cpufree(cpu_set_t* set) __INTRODUCED_IN(21);
+extern cpu_set_t* __sched_cpualloc(size_t count) __INTRODUCED_IN(12);
+extern 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) __INTRODUCED_IN(21);
+extern 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 1ac6d21..dc160e9 100644
--- a/libc/include/search.h
+++ b/libc/include/search.h
@@ -38,10 +38,10 @@
   __INTRODUCED_IN(21);
 
 void* tdelete(const void* __restrict, void** __restrict, int (*)(const void*, const void*))
-  __INTRODUCED_IN(21);
-void tdestroy(void*, void (*)(void*)) __INTRODUCED_IN(21);
-void* tfind(const void*, void* const*, int (*)(const void*, const void*)) __INTRODUCED_IN(21);
-void* tsearch(const void*, void**, int (*)(const void*, const void*)) __INTRODUCED_IN(21);
+  __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/signal.h b/libc/include/signal.h
index d9f43de..3905d86 100644
--- a/libc/include/signal.h
+++ b/libc/include/signal.h
@@ -144,8 +144,8 @@
 
 extern int sigaltstack(const stack_t*, stack_t*);
 
-extern void psiginfo(const siginfo_t*, const char*) __INTRODUCED_IN(21);
-extern void psignal(int, const char*) __INTRODUCED_IN(21);
+extern void psiginfo(const siginfo_t*, const char*) __INTRODUCED_IN(17);
+extern 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*);
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index 05f2d98..83ffc20 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -119,8 +119,8 @@
 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) __INTRODUCED_IN(21);
-ssize_t getline(char** __restrict, size_t* __restrict, FILE* __restrict) __INTRODUCED_IN(21);
+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, ...)
@@ -280,7 +280,7 @@
 #define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
 #endif /* __BSD_VISIBLE */
 
-extern char* __fgets_chk(char*, int, FILE*, size_t) __INTRODUCED_IN(21);
+extern char* __fgets_chk(char*, int, FILE*, size_t) __INTRODUCED_IN(17);
 extern 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");
diff --git a/libc/include/string.h b/libc/include/string.h
index f39a86b..b3ea9d6 100644
--- a/libc/include/string.h
+++ b/libc/include/string.h
@@ -54,7 +54,7 @@
 extern void*  memmem(const void *, size_t, const void *, size_t) __purefunc;
 
 extern char*  strchr(const char *, int) __purefunc;
-extern char* __strchr_chk(const char*, int, size_t) __INTRODUCED_IN(21);
+extern char* __strchr_chk(const char*, int, size_t) __INTRODUCED_IN(18);
 #if defined(__USE_GNU)
 #if defined(__cplusplus)
 extern "C++" char* strchrnul(char*, int) __RENAME(strchrnul) __purefunc;
@@ -65,10 +65,10 @@
 #endif
 
 extern char*  strrchr(const char *, int) __purefunc;
-extern char* __strrchr_chk(const char*, int, size_t) __INTRODUCED_IN(21);
+extern char* __strrchr_chk(const char*, int, size_t) __INTRODUCED_IN(18);
 
 extern size_t strlen(const char *) __purefunc;
-extern size_t __strlen_chk(const char*, size_t) __INTRODUCED_IN(21);
+extern size_t __strlen_chk(const char*, size_t) __INTRODUCED_IN(17);
 extern int    strcmp(const char *, const char *) __purefunc;
 extern char* stpcpy(char* __restrict, const char* __restrict) __INTRODUCED_IN(21);
 extern char*  strcpy(char* __restrict, const char* __restrict);
@@ -139,10 +139,10 @@
 extern char* __strncpy_chk2(char* __restrict, const char* __restrict, size_t, size_t, size_t)
   __INTRODUCED_IN(21);
 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) __INTRODUCED_IN(21);
+extern size_t __strlcpy_chk(char*, const char*, size_t, size_t) __INTRODUCED_IN(17);
 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)
-  __INTRODUCED_IN(21);
+  __INTRODUCED_IN(17);
 
 #if defined(__BIONIC_FORTIFY)
 
diff --git a/libc/include/strings.h b/libc/include/strings.h
index ca9f658..021e2b4 100644
--- a/libc/include/strings.h
+++ b/libc/include/strings.h
@@ -54,11 +54,7 @@
 #define bzero(b, len) (void)(__builtin_memset((b), '\0', (len)))
 #endif
 
-#if defined(__i386__)
-int ffs(int) __INTRODUCED_IN(21);
-#else
-int ffs(int);
-#endif
+int ffs(int) __INTRODUCED_IN_X86(18);
 
 __END_DECLS
 
diff --git a/libc/include/sys/auxv.h b/libc/include/sys/auxv.h
index 4611fcc..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) __INTRODUCED_IN(21);
+unsigned long int getauxval(unsigned long int type) __INTRODUCED_IN(18);
 
 __END_DECLS
 
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index 7b06967..fa03207 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -501,6 +501,24 @@
 #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__
 #define __size_mul_overflow(a, b, result) __builtin_umull_overflow(a, b, result)
diff --git a/libc/include/sys/mman.h b/libc/include/sys/mman.h
index af96eff..7a8aa89 100644
--- a/libc/include/sys/mman.h
+++ b/libc/include/sys/mman.h
@@ -61,8 +61,8 @@
 extern int mprotect(const void*, size_t, int);
 extern void* mremap(void*, size_t, size_t, int, ...);
 
-extern int mlockall(int) __INTRODUCED_IN(21);
-extern int munlockall(void) __INTRODUCED_IN(21);
+extern int mlockall(int) __INTRODUCED_IN(17);
+extern int munlockall(void) __INTRODUCED_IN(17);
 extern int mlock(const void*, size_t);
 extern int munlock(const void*, size_t);
 
diff --git a/libc/include/sys/personality.h b/libc/include/sys/personality.h
index 68ae77c..15a5e68 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) __INTRODUCED_IN(21);
+extern int personality(unsigned int persona) __INTRODUCED_IN(15);
 
 __END_DECLS
 
diff --git a/libc/include/sys/signalfd.h b/libc/include/sys/signalfd.h
index 084a528..41036b0 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* _Nonnull mask, int flags) __INTRODUCED_IN(21);
+extern int signalfd(int fd, const sigset_t* _Nonnull mask, int flags) __INTRODUCED_IN(18);
 
 __END_DECLS
 
diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h
index 46eec96..f26a492 100644
--- a/libc/include/sys/stat.h
+++ b/libc/include/sys/stat.h
@@ -157,7 +157,7 @@
 extern int mknod(const char*, mode_t, dev_t);
 extern mode_t umask(mode_t);
 
-extern mode_t __umask_chk(mode_t) __INTRODUCED_IN(21);
+extern mode_t __umask_chk(mode_t) __INTRODUCED_IN(18);
 extern mode_t __umask_real(mode_t) __RENAME(umask);
 __errordecl(__umask_invalid_mode, "umask called with invalid mode");
 
diff --git a/libc/include/sys/statvfs.h b/libc/include/sys/statvfs.h
index 1f00b9d..f6b9803 100644
--- a/libc/include/sys/statvfs.h
+++ b/libc/include/sys/statvfs.h
@@ -60,10 +60,10 @@
 #define ST_RELATIME    0x1000
 
 extern int statvfs(const char* __restrict _Nonnull, struct statvfs* __restrict _Nonnull)
-  __INTRODUCED_IN(21);
+  __INTRODUCED_IN(19);
 extern int statvfs64(const char* __restrict _Nonnull, struct statvfs64* __restrict _Nonnull)
   __INTRODUCED_IN(21);
-extern int fstatvfs(int, struct statvfs* _Nonnull) __INTRODUCED_IN(21);
+extern int fstatvfs(int, struct statvfs* _Nonnull) __INTRODUCED_IN(19);
 extern 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 fe14a30..2d99df8 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* _Nonnull, int) __INTRODUCED_IN(21);
-extern int swapoff(const char* _Nonnull) __INTRODUCED_IN(21);
+extern int swapon(const char* _Nonnull, int) __INTRODUCED_IN(19);
+extern int swapoff(const char* _Nonnull) __INTRODUCED_IN(19);
 
 __END_DECLS
 
diff --git a/libc/include/sys/system_properties.h b/libc/include/sys/system_properties.h
index 99a6e59..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) __INTRODUCED_IN(21);
+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 
@@ -94,7 +94,7 @@
 ** not a bug.
 */
 int __system_property_foreach(void (*propfn)(const prop_info* pi, void* cookie), void* cookie)
-  __INTRODUCED_IN(21);
+  __INTRODUCED_IN(19);
 
 __END_DECLS
 
diff --git a/libc/include/sys/timerfd.h b/libc/include/sys/timerfd.h
index a189742..8311f08 100644
--- a/libc/include/sys/timerfd.h
+++ b/libc/include/sys/timerfd.h
@@ -41,10 +41,10 @@
 #define TFD_CLOEXEC O_CLOEXEC
 #define TFD_NONBLOCK O_NONBLOCK
 
-extern int timerfd_create(clockid_t, int) __INTRODUCED_IN(21);
+extern int timerfd_create(clockid_t, int) __INTRODUCED_IN(19);
 extern int timerfd_settime(int, int, const struct itimerspec*, struct itimerspec*)
-  __INTRODUCED_IN(21);
-extern int timerfd_gettime(int, struct itimerspec*) __INTRODUCED_IN(21);
+  __INTRODUCED_IN(19);
+extern int timerfd_gettime(int, struct itimerspec*) __INTRODUCED_IN(19);
 
 __END_DECLS
 
diff --git a/libc/include/sys/wait.h b/libc/include/sys/wait.h
index aba20e5..e0afabc 100644
--- a/libc/include/sys/wait.h
+++ b/libc/include/sys/wait.h
@@ -51,7 +51,7 @@
 
 extern pid_t  wait(int *);
 extern pid_t  waitpid(pid_t, int *, int);
-extern pid_t wait4(pid_t, int*, int, struct rusage*) __INTRODUCED_IN(19);
+extern 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
diff --git a/libc/include/sys/xattr.h b/libc/include/sys/xattr.h
index 070913f..63605c5 100644
--- a/libc/include/sys/xattr.h
+++ b/libc/include/sys/xattr.h
@@ -36,25 +36,25 @@
 #define XATTR_REPLACE 2
 
 extern int fsetxattr(int fd, const char* name, const void* value, size_t size, int flags)
-  __INTRODUCED_IN(21);
+  __INTRODUCED_IN(16);
 extern int setxattr(const char* path, const char* name, const void* value, size_t size, int flags)
-  __INTRODUCED_IN(21);
+  __INTRODUCED_IN(16);
 extern int lsetxattr(const char* path, const char* name, const void* value, size_t size, int flags)
-  __INTRODUCED_IN(21);
+  __INTRODUCED_IN(16);
 
-extern ssize_t fgetxattr(int fd, const char* name, void* value, size_t size) __INTRODUCED_IN(21);
+extern ssize_t fgetxattr(int fd, const char* name, void* value, size_t size) __INTRODUCED_IN(16);
 extern ssize_t getxattr(const char* path, const char* name, void* value, size_t size)
-  __INTRODUCED_IN(21);
+  __INTRODUCED_IN(16);
 extern ssize_t lgetxattr(const char* path, const char* name, void* value, size_t size)
-  __INTRODUCED_IN(21);
+  __INTRODUCED_IN(16);
 
-extern ssize_t listxattr(const char* path, char* list, size_t size) __INTRODUCED_IN(21);
-extern ssize_t llistxattr(const char* path, char* list, size_t size) __INTRODUCED_IN(21);
-extern ssize_t flistxattr(int fd, char* list, size_t size) __INTRODUCED_IN(21);
+extern ssize_t listxattr(const char* path, char* list, size_t size) __INTRODUCED_IN(16);
+extern ssize_t llistxattr(const char* path, char* list, size_t size) __INTRODUCED_IN(16);
+extern ssize_t flistxattr(int fd, char* list, size_t size) __INTRODUCED_IN(16);
 
-extern int removexattr(const char* path, const char* name) __INTRODUCED_IN(21);
-extern int lremovexattr(const char* path, const char* name) __INTRODUCED_IN(21);
-extern int fremovexattr(int fd, const char* name) __INTRODUCED_IN(21);
+extern int removexattr(const char* path, const char* name) __INTRODUCED_IN(16);
+extern int lremovexattr(const char* path, const char* name) __INTRODUCED_IN(16);
+extern int fremovexattr(int fd, const char* name) __INTRODUCED_IN(16);
 
 __END_DECLS
 
diff --git a/libc/include/time.h b/libc/include/time.h
index 039608b..ef4ac2f 100644
--- a/libc/include/time.h
+++ b/libc/include/time.h
@@ -100,8 +100,8 @@
 extern int timer_getoverrun(timer_t) __LIBC_ABI_PUBLIC__;
 
 /* Non-standard extensions that are in the BSDs and glibc. */
-extern time_t timelocal(struct tm*) __LIBC_ABI_PUBLIC__ __INTRODUCED_IN(21);
-extern time_t timegm(struct tm*) __LIBC_ABI_PUBLIC__ __INTRODUCED_IN(21);
+extern time_t timelocal(struct tm*) __LIBC_ABI_PUBLIC__ __INTRODUCED_IN(12);
+extern time_t timegm(struct tm*) __LIBC_ABI_PUBLIC__ __INTRODUCED_IN(12);
 
 __END_DECLS
 
diff --git a/libc/include/unistd.h b/libc/include/unistd.h
index 6b5ef76..7deca95 100644
--- a/libc/include/unistd.h
+++ b/libc/include/unistd.h
@@ -90,7 +90,7 @@
 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  getsid(pid_t __pid) __INTRODUCED_IN(17);
 extern pid_t  setsid(void);
 
 extern int execv(const char* __path, char* const* __argv);
@@ -127,7 +127,7 @@
 
 extern int access(const char* __path, int __mode);
 extern int faccessat(int __dirfd, const char* __path, int __mode, int __flags)
-  __INTRODUCED_IN(21);
+  __INTRODUCED_IN(16);
 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);
@@ -204,7 +204,6 @@
 int gethostname(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);
 
@@ -286,7 +285,7 @@
 extern 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);
+extern ssize_t __readlinkat_real(int dirfd, const char*, char*, size_t) __RENAME(readlinkat) __INTRODUCED_IN(21);
 
 extern int getdomainname(char*, size_t) __INTRODUCED_IN_FUTURE;
 extern int setdomainname(const char*, size_t) __INTRODUCED_IN_FUTURE;
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/libm/Android.mk b/libm/Android.mk
deleted file mode 100644
index 0070bd1..0000000
--- a/libm/Android.mk
+++ /dev/null
@@ -1,582 +0,0 @@
-ifneq ($(TARGET_USE_PRIVATE_LIBM),true)
-LOCAL_PATH:= $(call my-dir)
-
-bionic_coverage := false
-
-# -----------------------------------------------------------------------------
-# 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 \
-
-# 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...
-LOCAL_SRC_FILES += \
-    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 \
-
-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/android/include/ \
-    $(LOCAL_PATH)/upstream-freebsd/lib/msun/src/ \
-
-LOCAL_C_INCLUDES_64 += $(LOCAL_PATH)/upstream-freebsd/lib/msun/ld128/
-
-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_CONLYFLAGS := \
-    -std=gnu11 \
-
-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_SYSTEM_SHARED_LIBRARIES := libc
-LOCAL_WHOLE_STATIC_LIBRARIES := libm
-
-LOCAL_NATIVE_COVERAGE := $(bionic_coverage)
-LOCAL_SANITIZE := never
-
-LOCAL_CXX_STL := none
-
-include $(BUILD_SHARED_LIBRARY)
-endif
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_common b/tools/versioner/dependencies/common/kernel_common
new file mode 120000
index 0000000..1ea6a74
--- /dev/null
+++ b/tools/versioner/dependencies/common/kernel_common
@@ -0,0 +1 @@
+../../../../libc/kernel/common
\ 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 100644
index 0000000..f5a31f2
--- /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.PIPE)
+    (output, error) = process.communicate()
+
+    if os.path.exists("expected_fail"):
+        with open("expected_fail") as f:
+            expected_output = f.read()
+            if output != 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..057e416
--- /dev/null
+++ b/tools/versioner/src/DeclarationDatabase.h
@@ -0,0 +1,211 @@
+/*
+ * 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 <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 {
+    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;
+    }
+  }
+
+  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 {
+    return std::string("[") + std::to_string(introduced) + "," + std::to_string(deprecated) + "," +
+           std::to_string(obsoleted) + "]";
+  }
+};
+
+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();
+  }
+};
+
+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) {
+      const char* var_type = declarationTypeName(location.type);
+      const char* declaration_type = location.is_definition ? "definition" : "declaration";
+      const char* linkage = location.is_extern ? "extern" : "static";
+
+      std::string filename;
+      if (llvm::StringRef(location.filename).startswith(base_path)) {
+        filename = location.filename.substr(base_path.size());
+      } else {
+        filename = location.filename;
+      }
+
+      out << "        " << linkage << " " << var_type << " " << declaration_type << " @ "
+          << filename << ":" << location.line_number << ":" << location.column;
+
+      if (!location.availability.empty()) {
+        out << "\t[";
+        location.availability.dump(out);
+        out << "]";
+      } else {
+        out << "\t[no availability]";
+      }
+
+      out << "\n";
+    }
+  }
+};
+
+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..1612ed0
--- /dev/null
+++ b/tools/versioner/src/versioner.cpp
@@ -0,0 +1,601 @@
+/*
+ * 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;
+  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;
+
+      // Make sure 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(getWorkingDir() + "/");
+      }
+
+      if (type.arch != last_type.arch) {
+        last_type = type;
+        last_availability = current_availability;
+        continue;
+      }
+
+      // Make sure 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());
+      }
+
+      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);
+  }
+
+  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()) {
+      // This currently has lots of false positives (__INTRODUCED_IN_FUTURE, __errordecl, functions
+      // that come from crtbegin, etc.). Only print them with verbose, because of this.
+      if (verbose) {
+        printf("%s: not available in any platform\n", symbol_name.c_str());
+      }
+      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) {
+          // Make sure that either it exists in the platform, or an inline definition is visible.
+          if (!declaration.hasDefinition()) {
+            missing_symbol.insert(type);
+            continue;
+          }
+        } else {
+          // Make sure 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 {
+        // Make sure 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;
+    }
+  }
+
+  return !failed;
+}
+
+static void usage() {
+  fprintf(stderr, "Usage: versioner [OPTION]... HEADER_PATH [DEPS_PATH]\n");
+  fprintf(stderr, "Version headers at HEADER_PATH, with DEPS_PATH/ARCH/* on the include path\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, "  -d\t\tdump symbol availability in libraries\n");
+  fprintf(stderr, "  -v\t\tenable verbose warnings\n");
+  exit(1);
+}
+
+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:n:duv")) != -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;
+
+      default:
+        usage();
+        break;
+    }
+  }
+
+  if (argc - optind > 2 || optind >= argc) {
+    usage();
+  }
+
+  if (selected_levels.empty()) {
+    selected_levels = supported_levels;
+  }
+
+  if (selected_architectures.empty()) {
+    selected_architectures = supported_archs;
+  }
+
+  std::string dependencies = (argc - optind == 2) ? argv[optind + 1] : "";
+  const char* header_dir = argv[optind];
+
+  struct stat st;
+  if (stat(header_dir, &st) != 0) {
+    err(1, "failed to stat '%s'", header_dir);
+  } else if (!S_ISDIR(st.st_mode)) {
+    errx(1, "'%s' is not a directory", header_dir);
+  }
+
+  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, dependencies, &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..95635bb
--- /dev/null
+++ b/tools/versioner/src/versioner.h
@@ -0,0 +1,57 @@
+/*
+ * 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>
+
+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" } },
+};
diff --git a/tools/versioner/tests/arch_specific/dependencies/common/foo/foodep.h b/tools/versioner/tests/arch_specific/dependencies/common/foo/foodep.h
new file mode 100644
index 0000000..9feeb6c
--- /dev/null
+++ b/tools/versioner/tests/arch_specific/dependencies/common/foo/foodep.h
@@ -0,0 +1 @@
+typedef int foo_t;
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..3a3dda8
--- /dev/null
+++ b/tools/versioner/tests/arch_specific/run.sh
@@ -0,0 +1 @@
+versioner headers dependencies -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..d26ab70
--- /dev/null
+++ b/tools/versioner/tests/compilation_error/run.sh
@@ -0,0 +1 @@
+versioner headers dependencies -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/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%
rename from libc/arch-arm64/cortex-a53/cortex-a53.mk
rename 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..0277123
--- /dev/null
+++ b/tools/versioner/tests/inline/run.sh
@@ -0,0 +1 @@
+versioner headers dependencies -p platforms -r arm -a 9 -a 12
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..2894499
--- /dev/null
+++ b/tools/versioner/tests/inline_version_mismatch/expected_fail
@@ -0,0 +1,2 @@
+foo: availability mismatch between arm-9 and arm-12: [9,0,0] before, [10,0,0] 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..0277123
--- /dev/null
+++ b/tools/versioner/tests/inline_version_mismatch/run.sh
@@ -0,0 +1 @@
+versioner headers dependencies -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..0277123
--- /dev/null
+++ b/tools/versioner/tests/missing_api/run.sh
@@ -0,0 +1 @@
+versioner headers dependencies -p platforms -r arm -a 9 -a 12
diff --git a/tools/versioner/tests/missing_arch/dependencies/common/foo/foodep.h b/tools/versioner/tests/missing_arch/dependencies/common/foo/foodep.h
new file mode 100644
index 0000000..9feeb6c
--- /dev/null
+++ b/tools/versioner/tests/missing_arch/dependencies/common/foo/foodep.h
@@ -0,0 +1 @@
+typedef int foo_t;
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..3a3dda8
--- /dev/null
+++ b/tools/versioner/tests/missing_arch/run.sh
@@ -0,0 +1 @@
+versioner headers dependencies -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..d26ab70
--- /dev/null
+++ b/tools/versioner/tests/multiple_decl/run.sh
@@ -0,0 +1 @@
+versioner headers dependencies -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..d26ab70
--- /dev/null
+++ b/tools/versioner/tests/multiple_decl_mismatch/run.sh
@@ -0,0 +1 @@
+versioner headers dependencies -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..0277123
--- /dev/null
+++ b/tools/versioner/tests/obsoleted/run.sh
@@ -0,0 +1 @@
+versioner headers dependencies -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..d26ab70
--- /dev/null
+++ b/tools/versioner/tests/smoke/run.sh
@@ -0,0 +1 @@
+versioner headers dependencies -p platforms -r arm -a 9