Merge "Fix linker crash on trying to unload main executable"
diff --git a/libc/Android.bp b/libc/Android.bp
index 9c521d1..416b1e5 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -70,16 +70,6 @@
     cppflags: [],
     include_dirs: ["external/jemalloc/include"],
 
-    arch: {
-        // b/25291096, Clang/llvm compiled libc.so for mips/mips64 failed to boot.
-        mips: {
-            clang: false,
-        },
-        mips64: {
-            clang: false,
-        },
-    },
-
     stl: "none",
     system_shared_libs: [],
     sanitize: {
@@ -1305,6 +1295,7 @@
         "bionic/lockf.cpp",
         "bionic/lstat.cpp",
         "bionic/malloc_info.cpp",
+        "bionic/mblen.cpp",
         "bionic/mbrtoc16.cpp",
         "bionic/mbrtoc32.cpp",
         "bionic/mbstate.cpp",
@@ -1692,7 +1683,9 @@
 
     // Leave the symbols in the shared library so that stack unwinders can produce
     // meaningful name resolution.
-    strip: "keep_symbols",
+    strip: {
+        keep_symbols: true,
+    },
 
     // WARNING: The only library libc.so should depend on is libdl.so!  If you add other libraries,
     // make sure to add -Wl,--exclude-libs=libgcc.a to the LOCAL_LDFLAGS for those libraries.  This
diff --git a/libc/Android.mk b/libc/Android.mk
index a8581ac..3fac083 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -1390,11 +1390,6 @@
 LOCAL_LDFLAGS_mips64 += -Wl,--version-script,$(LOCAL_PATH)/libc.mips64.map
 LOCAL_LDFLAGS_x86_64 += -Wl,--version-script,$(LOCAL_PATH)/libc.x86_64.map
 
-# We'd really like to do this for all architectures, but since this wasn't done
-# before, these symbols must continue to be exported on LP32 for binary
-# compatibility.
-LOCAL_LDFLAGS_64 := -Wl,--exclude-libs,libgcc.a
-
 # Unfortunately --exclude-libs clobbers our version script, so we have to
 # prevent the build system from using this flag.
 LOCAL_NO_EXCLUDE_LIBS := true
diff --git a/libc/bionic/fpclassify.cpp b/libc/bionic/fpclassify.cpp
index 21ff946..f8cea80 100644
--- a/libc/bionic/fpclassify.cpp
+++ b/libc/bionic/fpclassify.cpp
@@ -29,7 +29,8 @@
 #include <sys/types.h>
 
 #include <math.h>
-#include <machine/ieee.h>
+
+#include "private/bionic_ieee.h"
 
 // These aren't declared in our <math.h>.
 extern "C" int __isinf(double);
diff --git a/libc/bionic/ifaddrs.cpp b/libc/bionic/ifaddrs.cpp
index 408949c..f5b080c 100644
--- a/libc/bionic/ifaddrs.cpp
+++ b/libc/bionic/ifaddrs.cpp
@@ -59,7 +59,7 @@
   sockaddr_storage ifa_ifu;
   char name[IFNAMSIZ + 1];
 
-  ifaddrs_storage(ifaddrs** list) {
+  explicit ifaddrs_storage(ifaddrs** list) {
     memset(this, 0, sizeof(*this));
 
     // push_front onto `list`.
diff --git a/libc/bionic/libc_logging.cpp b/libc/bionic/libc_logging.cpp
index 6802944..517d047 100644
--- a/libc/bionic/libc_logging.cpp
+++ b/libc/bionic/libc_logging.cpp
@@ -107,7 +107,7 @@
 
 struct FdOutputStream {
  public:
-  FdOutputStream(int fd) : total(0), fd_(fd) {
+  explicit FdOutputStream(int fd) : total(0), fd_(fd) {
   }
 
   void Send(const char* data, int len) {
diff --git a/libc/bionic/locale.cpp b/libc/bionic/locale.cpp
index b42b440..f26a5f2 100644
--- a/libc/bionic/locale.cpp
+++ b/libc/bionic/locale.cpp
@@ -44,10 +44,10 @@
 struct __locale_t {
   size_t mb_cur_max;
 
-  __locale_t(size_t mb_cur_max) : mb_cur_max(mb_cur_max) {
+  explicit __locale_t(size_t mb_cur_max) : mb_cur_max(mb_cur_max) {
   }
 
-  __locale_t(const __locale_t* other) {
+  explicit __locale_t(const __locale_t* other) {
     if (other == LC_GLOBAL_LOCALE) {
       mb_cur_max = __bionic_current_locale_is_utf8 ? 4 : 1;
     } else {
diff --git a/libc/bionic/net_if.cpp b/libc/bionic/net_if.cpp
index f8d73bd..db9c9ea2 100644
--- a/libc/bionic/net_if.cpp
+++ b/libc/bionic/net_if.cpp
@@ -77,7 +77,7 @@
   if_list* next;
   struct if_nameindex data;
 
-  if_list(if_list** list) {
+  explicit if_list(if_list** list) {
     // push_front onto `list`.
     next = *list;
     *list = this;
diff --git a/libc/bionic/pthread_mutex.cpp b/libc/bionic/pthread_mutex.cpp
index 7d8e8a8..14e0ab0 100644
--- a/libc/bionic/pthread_mutex.cpp
+++ b/libc/bionic/pthread_mutex.cpp
@@ -502,6 +502,9 @@
 
 int pthread_mutex_lock(pthread_mutex_t* mutex_interface) {
 #if !defined(__LP64__)
+    // Some apps depend on being able to pass NULL as a mutex and get EINVAL
+    // back. Don't need to worry about it for LP64 since the ABI is brand new,
+    // but keep compatibility for LP32. http://b/19995172.
     if (mutex_interface == NULL) {
         return EINVAL;
     }
@@ -523,6 +526,9 @@
 
 int pthread_mutex_unlock(pthread_mutex_t* mutex_interface) {
 #if !defined(__LP64__)
+    // Some apps depend on being able to pass NULL as a mutex and get EINVAL
+    // back. Don't need to worry about it for LP64 since the ABI is brand new,
+    // but keep compatibility for LP32. http://b/19995172.
     if (mutex_interface == NULL) {
         return EINVAL;
     }
diff --git a/libc/bionic/system_properties.cpp b/libc/bionic/system_properties.cpp
index 9c992da..0f68431 100644
--- a/libc/bionic/system_properties.cpp
+++ b/libc/bionic/system_properties.cpp
@@ -192,7 +192,7 @@
     const uint32_t n;
     const prop_info *pi;
 
-    find_nth_cookie(uint32_t n) : count(0), n(n), pi(NULL) {
+    explicit find_nth_cookie(uint32_t n) : count(0), n(n), pi(NULL) {
     }
 };
 
diff --git a/libc/include/nsswitch.h b/libc/dns/include/nsswitch.h
similarity index 100%
rename from libc/include/nsswitch.h
rename to libc/dns/include/nsswitch.h
diff --git a/libc/dns/include/resolv_netid.h b/libc/dns/include/resolv_netid.h
index 266193a..7182ca6 100644
--- a/libc/dns/include/resolv_netid.h
+++ b/libc/dns/include/resolv_netid.h
@@ -101,9 +101,6 @@
 int android_getnameinfofornet(const struct sockaddr *, socklen_t, char *, size_t, char *, size_t, int, unsigned, unsigned) __LIBC_HIDDEN__;
 FILE* android_open_proxy(void) __LIBC_HIDDEN__;
 
-/* delete the cache associated with a certain network */
-extern void _resolv_delete_cache_for_net(unsigned netid);
-
 __END_DECLS
 
 #endif /* _RESOLV_NETID_H */
diff --git a/libc/dns/net/getnameinfo.c b/libc/dns/net/getnameinfo.c
index 893e982..abd1a66 100644
--- a/libc/dns/net/getnameinfo.c
+++ b/libc/dns/net/getnameinfo.c
@@ -54,7 +54,6 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <net/if.h>
-#include <net/if_ieee1394.h>
 #include <net/if_types.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
diff --git a/libc/include/android/legacy_sys_atomics_inlines.h b/libc/include/android/legacy_sys_atomics_inlines.h
deleted file mode 100644
index 3314e35..0000000
--- a/libc/include/android/legacy_sys_atomics_inlines.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef _ANDROID_LEGACY_SYS_ATOMICS_INLINES_H_
-#define _ANDROID_LEGACY_SYS_ATOMICS_INLINES_H_
-
-#include <sys/cdefs.h>
-
-#if __ANDROID_API__ < 21
-
-__BEGIN_DECLS
-
-/* Note: atomic operations that were exported by the C library didn't
- *       provide any memory barriers, which created potential issues on
- *       multi-core devices. We now define them as inlined calls to
- *       GCC sync builtins, which always provide a full barrier.
- *
- *       NOTE: The C library still exports atomic functions by the same
- *              name to ensure ABI stability for existing NDK machine code.
- *
- *       If you are an NDK developer, we encourage you to rebuild your
- *       unmodified sources against this header as soon as possible.
- */
-#define __ATOMIC_INLINE__ static __inline __attribute__((always_inline))
-
-__ATOMIC_INLINE__ int __atomic_cmpxchg(int old, int _new, volatile int *ptr) {
-  /* We must return 0 on success */
-  return __sync_val_compare_and_swap(ptr, old, _new) != old;
-}
-
-__ATOMIC_INLINE__ int __atomic_swap(int _new, volatile int *ptr) {
-  int prev;
-  do {
-    prev = *ptr;
-  } while (__sync_val_compare_and_swap(ptr, prev, _new) != prev);
-  return prev;
-}
-
-__ATOMIC_INLINE__ int __atomic_dec(volatile int *ptr) {
-  return __sync_fetch_and_sub(ptr, 1);
-}
-
-__ATOMIC_INLINE__ int __atomic_inc(volatile int *ptr) {
-  return __sync_fetch_and_add(ptr, 1);
-}
-
-__END_DECLS
-
-#endif
-#endif /* _ANDROID_LEGACY_SYS_ATOMICS_INLINES_H_ */
diff --git a/libc/include/sys/glibc-syscalls.h b/libc/include/bits/glibc-syscalls.h
similarity index 100%
rename from libc/include/sys/glibc-syscalls.h
rename to libc/include/bits/glibc-syscalls.h
diff --git a/libc/include/dlfcn.h b/libc/include/dlfcn.h
index 25a302f..5dc8350 100644
--- a/libc/include/dlfcn.h
+++ b/libc/include/dlfcn.h
@@ -46,8 +46,8 @@
 extern void* dlopen(const char*  filename, int flag);
 extern int dlclose(void*  handle);
 extern const char* dlerror(void);
-extern void* dlsym(void* handle, const char* symbol) __nonnull((2));
-extern void* dlvsym(void* handle, const char* symbol, const char* version) __nonnull((2, 3))
+extern void* dlsym(void* handle, const char* _Nonnull symbol);
+extern void* dlvsym(void* handle, const char* _Nonnull symbol, const char* _Nonnull version)
   __INTRODUCED_IN(24);
 extern int dladdr(const void* addr, Dl_info *info);
 
@@ -80,5 +80,3 @@
 __END_DECLS
 
 #endif /* __DLFCN_H */
-
-
diff --git a/libc/include/machine/endian.h b/libc/include/machine/endian.h
deleted file mode 100644
index ac89519..0000000
--- a/libc/include/machine/endian.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef _MACHINE_ENDIAN_H_
-#define _MACHINE_ENDIAN_H_
-
-/* This file is for BSD source compatibility only. Use <endian.h> or <sys/endian.h> instead. */
-#include <sys/endian.h>
-
-#endif /* _MACHINE_ENDIAN_H_ */
diff --git a/libc/include/net/if_ieee1394.h b/libc/include/net/if_ieee1394.h
deleted file mode 100644
index 2f8a7c3..0000000
--- a/libc/include/net/if_ieee1394.h
+++ /dev/null
@@ -1,129 +0,0 @@
-/*	$NetBSD: if_ieee1394.h,v 1.6 2005/12/10 23:21:38 elad Exp $	*/
-
-/*
- * Copyright (c) 2000 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Atsushi Onoe.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the NetBSD
- *	Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _NET_IF_IEEE1394_H_
-#define _NET_IF_IEEE1394_H_
-
-#include <sys/types.h>
-
-/* hardware address information for arp / nd */
-struct ieee1394_hwaddr {
-	u_int8_t	iha_uid[8];		/* node unique ID */
-	u_int8_t	iha_maxrec;		/* max_rec in the config ROM */
-	u_int8_t	iha_speed;		/* min of link/PHY speed */
-	u_int8_t	iha_offset[6];		/* unicast FIFO address */
-};
-
-/*
- * BPF wants to see one of these.
- */
-struct ieee1394_bpfhdr {
-	uint8_t		ibh_dhost[8];
-	uint8_t		ibh_shost[8];
-	uint16_t	ibh_type;
-};
-
-#ifdef _KERNEL
-
-/* pseudo header */
-struct ieee1394_header {
-	u_int8_t	ih_uid[8];		/* dst/src uid */
-	u_int8_t	ih_maxrec;		/* dst maxrec for tx */
-	u_int8_t	ih_speed;		/* speed */
-	u_int8_t	ih_offset[6];		/* dst offset */
-};
-
-/* unfragment encapsulation header */
-struct ieee1394_unfraghdr {
-	u_int16_t	iuh_ft;			/* fragment type == 0 */
-	u_int16_t	iuh_etype;		/* ether_type */
-};
-
-/* fragmented encapsulation header */
-struct ieee1394_fraghdr {
-	u_int16_t	ifh_ft_size;		/* fragment type, data size-1 */
-	u_int16_t	ifh_etype_off;		/* etype for first fragment */
-						/* offset for subseq frag */
-	u_int16_t	ifh_dgl;		/* datagram label */
-	u_int16_t	ifh_reserved;
-};
-
-#define	IEEE1394_FT_SUBSEQ	0x8000
-#define	IEEE1394_FT_MORE	0x4000
-
-#define	IEEE1394MTU		1500
-
-#define	IEEE1394_GASP_LEN	8		/* GASP header for Stream */
-#define	IEEE1394_ADDR_LEN	8
-#define	IEEE1394_CRC_LEN	4
-
-struct ieee1394_reass_pkt {
-	LIST_ENTRY(ieee1394_reass_pkt) rp_next;
-	struct mbuf	*rp_m;
-	u_int16_t	rp_size;
-	u_int16_t	rp_etype;
-	u_int16_t	rp_off;
-	u_int16_t	rp_dgl;
-	u_int16_t	rp_len;
-	u_int16_t	rp_ttl;
-};
-
-struct ieee1394_reassq {
-	LIST_ENTRY(ieee1394_reassq) rq_node;
-	LIST_HEAD(, ieee1394_reass_pkt) rq_pkt;
-	u_int32_t	fr_id;
-};
-
-struct ieee1394com {
-	struct ifnet	fc_if;
-	struct ieee1394_hwaddr ic_hwaddr;
-	u_int16_t	ic_dgl;
-	LIST_HEAD(, ieee1394_reassq) ic_reassq;
-};
-
-const char *ieee1394_sprintf(const u_int8_t *);
-void ieee1394_input(struct ifnet *, struct mbuf *, u_int16_t);
-void ieee1394_ifattach(struct ifnet *, const struct ieee1394_hwaddr *);
-void ieee1394_ifdetach(struct ifnet *);
-int  ieee1394_ioctl(struct ifnet *, u_long, caddr_t);
-struct mbuf * ieee1394_fragment(struct ifnet *, struct mbuf *, int, u_int16_t);
-void ieee1394_drain(struct ifnet *);
-void ieee1394_watchdog(struct ifnet *);
-#endif /* _KERNEL */
-
-#endif /* !_NET_IF_IEEE1394_H_ */
diff --git a/libc/include/pthread.h b/libc/include/pthread.h
index 2df9b74..fd8aa00 100644
--- a/libc/include/pthread.h
+++ b/libc/include/pthread.h
@@ -135,49 +135,51 @@
 
 int pthread_atfork(void (*)(void), void (*)(void), void (*)(void)) __INTRODUCED_IN(21);
 
-int pthread_attr_destroy(pthread_attr_t*) __nonnull((1));
-int pthread_attr_getdetachstate(const pthread_attr_t*, int*) __nonnull((1, 2));
-int pthread_attr_getguardsize(const pthread_attr_t*, size_t*) __nonnull((1, 2));
-int pthread_attr_getschedparam(const pthread_attr_t*, struct sched_param*) __nonnull((1, 2));
-int pthread_attr_getschedpolicy(const pthread_attr_t*, int*) __nonnull((1, 2));
-int pthread_attr_getscope(const pthread_attr_t*, int*) __nonnull((1, 2));
-int pthread_attr_getstack(const pthread_attr_t*, void**, size_t*) __nonnull((1, 2, 3));
-int pthread_attr_getstacksize(const pthread_attr_t*, size_t*) __nonnull((1, 2));
-int pthread_attr_init(pthread_attr_t*) __nonnull((1));
-int pthread_attr_setdetachstate(pthread_attr_t*, int) __nonnull((1));
-int pthread_attr_setguardsize(pthread_attr_t*, size_t) __nonnull((1));
-int pthread_attr_setschedparam(pthread_attr_t*, const struct sched_param*) __nonnull((1, 2));
-int pthread_attr_setschedpolicy(pthread_attr_t*, int) __nonnull((1));
-int pthread_attr_setscope(pthread_attr_t*, int) __nonnull((1));
-int pthread_attr_setstack(pthread_attr_t*, void*, size_t) __nonnull((1));
-int pthread_attr_setstacksize(pthread_attr_t*, size_t) __nonnull((1));
+int pthread_attr_destroy(pthread_attr_t* _Nonnull);
+int pthread_attr_getdetachstate(const pthread_attr_t* _Nonnull, int* _Nonnull);
+int pthread_attr_getguardsize(const pthread_attr_t* _Nonnull, size_t* _Nonnull);
+int pthread_attr_getschedparam(const pthread_attr_t* _Nonnull, struct sched_param* _Nonnull);
+int pthread_attr_getschedpolicy(const pthread_attr_t* _Nonnull, int* _Nonnull);
+int pthread_attr_getscope(const pthread_attr_t* _Nonnull, int* _Nonnull);
+int pthread_attr_getstack(const pthread_attr_t* _Nonnull, void** _Nonnull, size_t* _Nonnull);
+int pthread_attr_getstacksize(const pthread_attr_t* _Nonnull, size_t* _Nonnull);
+int pthread_attr_init(pthread_attr_t* _Nonnull);
+int pthread_attr_setdetachstate(pthread_attr_t* _Nonnull, int);
+int pthread_attr_setguardsize(pthread_attr_t* _Nonnull, size_t);
+int pthread_attr_setschedparam(pthread_attr_t* _Nonnull, const struct sched_param* _Nonnull);
+int pthread_attr_setschedpolicy(pthread_attr_t* _Nonnull, int);
+int pthread_attr_setscope(pthread_attr_t* _Nonnull, int);
+int pthread_attr_setstack(pthread_attr_t* _Nonnull, void*, size_t);
+int pthread_attr_setstacksize(pthread_attr_t* _Nonnull, size_t);
 
-int pthread_condattr_destroy(pthread_condattr_t*) __nonnull((1));
-int pthread_condattr_getclock(const pthread_condattr_t*, clockid_t*) __nonnull((1, 2))
+int pthread_condattr_destroy(pthread_condattr_t* _Nonnull);
+int pthread_condattr_getclock(const pthread_condattr_t* _Nonnull, clockid_t* _Nonnull)
   __INTRODUCED_IN(21);
-int pthread_condattr_getpshared(const pthread_condattr_t*, int*) __nonnull((1, 2));
-int pthread_condattr_init(pthread_condattr_t*) __nonnull((1));
-int pthread_condattr_setclock(pthread_condattr_t*, clockid_t) __nonnull((1)) __INTRODUCED_IN(21);
-int pthread_condattr_setpshared(pthread_condattr_t*, int) __nonnull((1));
+int pthread_condattr_getpshared(const pthread_condattr_t* _Nonnull, int* _Nonnull);
+int pthread_condattr_init(pthread_condattr_t* _Nonnull);
+int pthread_condattr_setclock(pthread_condattr_t* _Nonnull, clockid_t) __INTRODUCED_IN(21);
+int pthread_condattr_setpshared(pthread_condattr_t* _Nonnull, int);
 
-int pthread_cond_broadcast(pthread_cond_t*) __nonnull((1));
-int pthread_cond_destroy(pthread_cond_t*) __nonnull((1));
-int pthread_cond_init(pthread_cond_t*, const pthread_condattr_t*) __nonnull((1));
-int pthread_cond_signal(pthread_cond_t*) __nonnull((1));
-int pthread_cond_timedwait(pthread_cond_t*, pthread_mutex_t*, const struct timespec*) __nonnull((1, 2, 3));
-int pthread_cond_wait(pthread_cond_t*, pthread_mutex_t*) __nonnull((1, 2));
+int pthread_cond_broadcast(pthread_cond_t* _Nonnull);
+int pthread_cond_destroy(pthread_cond_t* _Nonnull);
+int pthread_cond_init(pthread_cond_t* _Nonnull, const pthread_condattr_t*);
+int pthread_cond_signal(pthread_cond_t* _Nonnull);
+int pthread_cond_timedwait(pthread_cond_t* _Nonnull, pthread_mutex_t* _Nonnull,
+                           const struct timespec* _Nonnull);
+int pthread_cond_wait(pthread_cond_t* _Nonnull, pthread_mutex_t* _Nonnull);
 
-int pthread_create(pthread_t*, pthread_attr_t const*, void *(*)(void*), void*) __nonnull((1, 3));
+int pthread_create(pthread_t* _Nonnull, pthread_attr_t const*,
+                   void* (* _Nonnull start_routine)(void*), void*);
 int pthread_detach(pthread_t);
 void pthread_exit(void*) __noreturn;
 
 int pthread_equal(pthread_t, pthread_t);
 
-int pthread_getattr_np(pthread_t, pthread_attr_t*) __nonnull((2));
+int pthread_getattr_np(pthread_t, pthread_attr_t* _Nonnull);
 
-int pthread_getcpuclockid(pthread_t, clockid_t*) __nonnull((2));
+int pthread_getcpuclockid(pthread_t, clockid_t* _Nonnull);
 
-int pthread_getschedparam(pthread_t, int*, struct sched_param*) __nonnull((2, 3));
+int pthread_getschedparam(pthread_t, int* _Nonnull, struct sched_param* _Nonnull);
 
 void* pthread_getspecific(pthread_key_t);
 
@@ -185,79 +187,71 @@
 
 int pthread_join(pthread_t, void**);
 
-int pthread_key_create(pthread_key_t*, void (*)(void*)) __nonnull((1));
+int pthread_key_create(pthread_key_t* _Nonnull, void (*)(void*));
 int pthread_key_delete(pthread_key_t);
 
-int pthread_mutexattr_destroy(pthread_mutexattr_t*) __nonnull((1));
-int pthread_mutexattr_getpshared(const pthread_mutexattr_t*, int*) __nonnull((1, 2));
-int pthread_mutexattr_gettype(const pthread_mutexattr_t*, int*) __nonnull((1, 2));
-int pthread_mutexattr_init(pthread_mutexattr_t*) __nonnull((1));
-int pthread_mutexattr_setpshared(pthread_mutexattr_t*, int) __nonnull((1));
-int pthread_mutexattr_settype(pthread_mutexattr_t*, int) __nonnull((1));
+int pthread_mutexattr_destroy(pthread_mutexattr_t* _Nonnull);
+int pthread_mutexattr_getpshared(const pthread_mutexattr_t* _Nonnull, int* _Nonnull);
+int pthread_mutexattr_gettype(const pthread_mutexattr_t* _Nonnull, int* _Nonnull);
+int pthread_mutexattr_init(pthread_mutexattr_t* _Nonnull);
+int pthread_mutexattr_setpshared(pthread_mutexattr_t* _Nonnull, int);
+int pthread_mutexattr_settype(pthread_mutexattr_t* _Nonnull, int);
 
-int pthread_mutex_destroy(pthread_mutex_t*) __nonnull((1));
-int pthread_mutex_init(pthread_mutex_t*, const pthread_mutexattr_t*) __nonnull((1));
-#if !defined(__LP64__)
-int pthread_mutex_lock(pthread_mutex_t*) /* __nonnull((1)) */;
-#else
-int pthread_mutex_lock(pthread_mutex_t*) __nonnull((1));
-#endif
-int pthread_mutex_timedlock(pthread_mutex_t*, const struct timespec*) __nonnull((1, 2))
+int pthread_mutex_destroy(pthread_mutex_t* _Nonnull);
+int pthread_mutex_init(pthread_mutex_t* _Nonnull, const pthread_mutexattr_t*);
+int pthread_mutex_lock(pthread_mutex_t* _Nonnull);
+int pthread_mutex_timedlock(pthread_mutex_t* _Nonnull, const struct timespec* _Nonnull)
   __INTRODUCED_IN(21);
-int pthread_mutex_trylock(pthread_mutex_t*) __nonnull((1));
-#if !defined(__LP4__)
-int pthread_mutex_unlock(pthread_mutex_t*) /* __nonnull((1)) */;
-#else
-int pthread_mutex_unlock(pthread_mutex_t*) __nonnull((1));
-#endif
+int pthread_mutex_trylock(pthread_mutex_t* _Nonnull);
+int pthread_mutex_unlock(pthread_mutex_t* _Nonnull);
 
-int pthread_once(pthread_once_t*, void (*)(void)) __nonnull((1, 2));
+int pthread_once(pthread_once_t* _Nonnull, void (* _Nonnull init_routine)(void));
 
-int pthread_rwlockattr_init(pthread_rwlockattr_t*) __nonnull((1));
-int pthread_rwlockattr_destroy(pthread_rwlockattr_t*) __nonnull((1));
-int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t*, int*) __nonnull((1, 2));
-int pthread_rwlockattr_setpshared(pthread_rwlockattr_t*, int) __nonnull((1));
-int pthread_rwlockattr_getkind_np(const pthread_rwlockattr_t*, int*) __nonnull((1, 2))
+int pthread_rwlockattr_init(pthread_rwlockattr_t* _Nonnull);
+int pthread_rwlockattr_destroy(pthread_rwlockattr_t* _Nonnull);
+int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t* _Nonnull, int* _Nonnull);
+int pthread_rwlockattr_setpshared(pthread_rwlockattr_t* _Nonnull, int);
+int pthread_rwlockattr_getkind_np(const pthread_rwlockattr_t* _Nonnull, int* _Nonnull)
   __INTRODUCED_IN(23);
-int pthread_rwlockattr_setkind_np(pthread_rwlockattr_t*, int) __nonnull((1)) __INTRODUCED_IN(23);
+int pthread_rwlockattr_setkind_np(pthread_rwlockattr_t* _Nonnull, int) __INTRODUCED_IN(23);
 
-int pthread_rwlock_destroy(pthread_rwlock_t*) __nonnull((1));
-int pthread_rwlock_init(pthread_rwlock_t*, const pthread_rwlockattr_t*) __nonnull((1));
-int pthread_rwlock_rdlock(pthread_rwlock_t*) __nonnull((1));
-int pthread_rwlock_timedrdlock(pthread_rwlock_t*, const struct timespec*) __nonnull((1, 2));
-int pthread_rwlock_timedwrlock(pthread_rwlock_t*, const struct timespec*) __nonnull((1, 2));
-int pthread_rwlock_tryrdlock(pthread_rwlock_t*) __nonnull((1));
-int pthread_rwlock_trywrlock(pthread_rwlock_t*) __nonnull((1));
-int pthread_rwlock_unlock(pthread_rwlock_t *) __nonnull((1));
-int pthread_rwlock_wrlock(pthread_rwlock_t*) __nonnull((1));
+int pthread_rwlock_destroy(pthread_rwlock_t* _Nonnull);
+int pthread_rwlock_init(pthread_rwlock_t* _Nonnull, const pthread_rwlockattr_t*);
+int pthread_rwlock_rdlock(pthread_rwlock_t* _Nonnull);
+int pthread_rwlock_timedrdlock(pthread_rwlock_t* _Nonnull, const struct timespec* _Nonnull);
+int pthread_rwlock_timedwrlock(pthread_rwlock_t* _Nonnull, const struct timespec* _Nonnull);
+int pthread_rwlock_tryrdlock(pthread_rwlock_t* _Nonnull);
+int pthread_rwlock_trywrlock(pthread_rwlock_t* _Nonnull);
+int pthread_rwlock_unlock(pthread_rwlock_t* _Nonnull);
+int pthread_rwlock_wrlock(pthread_rwlock_t* _Nonnull);
 
-int pthread_barrierattr_init(pthread_barrierattr_t* attr) __nonnull((1)) __INTRODUCED_IN(24);
-int pthread_barrierattr_destroy(pthread_barrierattr_t* attr) __nonnull((1)) __INTRODUCED_IN(24);
-int pthread_barrierattr_getpshared(pthread_barrierattr_t* attr, int* pshared) __nonnull((1, 2))
+int pthread_barrierattr_init(pthread_barrierattr_t* _Nonnull attr) __INTRODUCED_IN(24);
+int pthread_barrierattr_destroy(pthread_barrierattr_t* _Nonnull attr) __INTRODUCED_IN(24);
+int pthread_barrierattr_getpshared(pthread_barrierattr_t* _Nonnull attr, int* _Nonnull pshared)
   __INTRODUCED_IN(24);
-int pthread_barrierattr_setpshared(pthread_barrierattr_t* attr, int pshared) __nonnull((1))
+int pthread_barrierattr_setpshared(pthread_barrierattr_t* _Nonnull attr, int pshared)
   __INTRODUCED_IN(24);
 
-int pthread_barrier_init(pthread_barrier_t*, const pthread_barrierattr_t*, unsigned) __nonnull((1))
+int pthread_barrier_init(pthread_barrier_t* _Nonnull, const pthread_barrierattr_t*, unsigned)
   __INTRODUCED_IN(24);
-int pthread_barrier_destroy(pthread_barrier_t*) __nonnull((1)) __INTRODUCED_IN(24);
-int pthread_barrier_wait(pthread_barrier_t*) __nonnull((1)) __INTRODUCED_IN(24);
+int pthread_barrier_destroy(pthread_barrier_t* _Nonnull) __INTRODUCED_IN(24);
+int pthread_barrier_wait(pthread_barrier_t* _Nonnull) __INTRODUCED_IN(24);
 
-int pthread_spin_destroy(pthread_spinlock_t*) __nonnull((1)) __INTRODUCED_IN(24);
-int pthread_spin_init(pthread_spinlock_t*, int) __nonnull((1)) __INTRODUCED_IN(24);
-int pthread_spin_lock(pthread_spinlock_t*) __nonnull((1)) __INTRODUCED_IN(24);
-int pthread_spin_trylock(pthread_spinlock_t*) __nonnull((1)) __INTRODUCED_IN(24);
-int pthread_spin_unlock(pthread_spinlock_t*) __nonnull((1)) __INTRODUCED_IN(24);
+int pthread_spin_destroy(pthread_spinlock_t* _Nonnull) __INTRODUCED_IN(24);
+int pthread_spin_init(pthread_spinlock_t* _Nonnull, int) __INTRODUCED_IN(24);
+int pthread_spin_lock(pthread_spinlock_t* _Nonnull) __INTRODUCED_IN(24);
+int pthread_spin_trylock(pthread_spinlock_t* _Nonnull) __INTRODUCED_IN(24);
+int pthread_spin_unlock(pthread_spinlock_t* _Nonnull) __INTRODUCED_IN(24);
 
 pthread_t pthread_self(void) __pure2;
 
 #if defined(__USE_GNU)
-int pthread_getname_np(pthread_t, char*, size_t) __nonnull((2)) __INTRODUCED_IN_FUTURE;
+int pthread_getname_np(pthread_t, char* _Nonnull, size_t) __INTRODUCED_IN_FUTURE;
 #endif
 /* TODO: this should be __USE_GNU too. */
-int pthread_setname_np(pthread_t, const char*) __nonnull((2));
+int pthread_setname_np(pthread_t, const char* _Nonnull);
 
-int pthread_setschedparam(pthread_t, int, const struct sched_param*) __nonnull((3));
+int pthread_setschedparam(pthread_t, int, const struct sched_param* _Nonnull);
 
 int pthread_setspecific(pthread_key_t, const void*);
 
diff --git a/libc/include/signal.h b/libc/include/signal.h
index 4b5e4ac..d9f43de 100644
--- a/libc/include/signal.h
+++ b/libc/include/signal.h
@@ -120,10 +120,10 @@
 __BIONIC_LEGACY_INLINE int sigfillset(sigset_t*);
 __BIONIC_LEGACY_INLINE int sigismember(const sigset_t*, int);
 
-extern int sigpending(sigset_t*) __nonnull((1));
+extern int sigpending(sigset_t* _Nonnull);
 extern int sigprocmask(int, const sigset_t*, sigset_t*);
-extern int sigsuspend(const sigset_t*) __nonnull((1));
-extern int sigwait(const sigset_t*, int*) __nonnull((1, 2));
+extern int sigsuspend(const sigset_t* _Nonnull);
+extern int sigwait(const sigset_t* _Nonnull, int* _Nonnull);
 
 extern int sighold(int)
   __attribute__((deprecated("use sigprocmask() or pthread_sigmask() instead")))
diff --git a/libc/include/string.h b/libc/include/string.h
index 3f98af1..f39a86b 100644
--- a/libc/include/string.h
+++ b/libc/include/string.h
@@ -120,10 +120,10 @@
  */
 
 #if defined(__cplusplus)
-extern "C++" char* basename(char*) __RENAME(__gnu_basename) __nonnull((1));
-extern "C++" const char* basename(const char*) __RENAME(__gnu_basename) __nonnull((1));
+extern "C++" char* basename(char* _Nonnull) __RENAME(__gnu_basename);
+extern "C++" const char* basename(const char* _Nonnull) __RENAME(__gnu_basename);
 #else
-extern char* basename(const char*) __RENAME(__gnu_basename) __nonnull((1)) __INTRODUCED_IN(23);
+extern char* basename(const char* _Nonnull) __RENAME(__gnu_basename) __INTRODUCED_IN(23);
 #endif
 #endif
 
diff --git a/libc/include/sys/atomics.h b/libc/include/sys/atomics.h
deleted file mode 100644
index b9b2ba3..0000000
--- a/libc/include/sys/atomics.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef _SYS_ATOMICS_H_
-#define _SYS_ATOMICS_H_
-
-/*
- * These got proper out of line definitions in L. Putting the inline definitions
- * back for old targets brings us closer to being able to use one set of headers
- * for all API levels.
- *
- * The other inlines we put back went in to their appropriate headers, but the
- * sys/atomics.h header was removed, so we'll just add these somewhere we can be
- * sure they will be included.
- */
-#include <android/legacy_sys_atomics_inlines.h>
-
-#endif /* _SYS_ATOMICS_H_ */
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index 3fcf163..7b06967 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -159,6 +159,38 @@
 
 #define __nonnull(args) __attribute__((__nonnull__ args))
 
+/*
+ * _Nonnull is similar to the nonnull attribute in that it will instruct
+ * compilers to warn the user if it can prove that a null argument is being
+ * passed. Unlike the nonnull attribute, this annotation indicated that a value
+ * *should not* be null, not that it *cannot* be null, or even that the behavior
+ * is undefined. The important distinction is that the optimizer will perform
+ * surprising optimizations like the following:
+ *
+ *     void foo(void*) __attribute__(nonnull, 1);
+ *
+ *     int bar(int* p) {
+ *       foo(p);
+ *
+ *       // The following null check will be elided because nonnull attribute
+ *       // means that, since we call foo with p, p can be assumed to not be
+ *       // null. Thus this will crash if we are called with a null pointer.
+ *       if (src != NULL) {
+ *         return *p;
+ *       }
+ *       return 0;
+ *     }
+ *
+ *     int main() {
+ *       return bar(NULL);
+ *     }
+ *
+ * http://clang.llvm.org/docs/AttributeReference.html#nonnull
+ */
+#if !(defined(__clang__) && __has_feature(nullability))
+#define _Nonnull
+#endif
+
 #define __printflike(x, y) __attribute__((__format__(printf, x, y))) __nonnull((x))
 #define __scanflike(x, y) __attribute__((__format__(scanf, x, y))) __nonnull((x))
 
diff --git a/libc/include/sys/ioctl.h b/libc/include/sys/ioctl.h
index ed261f2..efbcb0c 100644
--- a/libc/include/sys/ioctl.h
+++ b/libc/include/sys/ioctl.h
@@ -37,7 +37,6 @@
 #include <linux/termios.h>
 #include <asm/ioctls.h>
 #include <asm/termbits.h>
-#include <sys/ioctl_compat.h>
 #include <linux/tty.h>
 
 #include <bits/ioctl.h>
diff --git a/libc/include/sys/ioctl_compat.h b/libc/include/sys/ioctl_compat.h
deleted file mode 100644
index d9ba4c7..0000000
--- a/libc/include/sys/ioctl_compat.h
+++ /dev/null
@@ -1,174 +0,0 @@
-/*	$NetBSD: ioctl_compat.h,v 1.15 2005/12/03 17:10:46 christos Exp $	*/
-
-/*
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- * (c) UNIX System Laboratories, Inc.
- * All or some portions of this file are derived from material licensed
- * to the University of California by American Telephone and Telegraph
- * Co. or Unix System Laboratories, Inc. and are reproduced herein with
- * the permission of UNIX System Laboratories, Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)ioctl_compat.h	8.4 (Berkeley) 1/21/94
- */
-
-#ifndef _SYS_IOCTL_COMPAT_H_
-#define	_SYS_IOCTL_COMPAT_H_
-
-/*#include <sys/ttychars.h>*/
-/*#include <sys/ttydev.h>*/
-
-#if !defined(__mips__)
-struct tchars {
-	char	t_intrc;	/* interrupt */
-	char	t_quitc;	/* quit */
-	char	t_startc;	/* start output */
-	char	t_stopc;	/* stop output */
-	char	t_eofc;		/* end-of-file */
-	char	t_brkc;		/* input delimiter (like nl) */
-};
-
-struct ltchars {
-	char	t_suspc;	/* stop process signal */
-	char	t_dsuspc;	/* delayed stop process signal */
-	char	t_rprntc;	/* reprint line */
-	char	t_flushc;	/* flush output (toggles) */
-	char	t_werasc;	/* word erase */
-	char	t_lnextc;	/* literal next character */
-};
-
-/*
- * Structure for TIOCGETP and TIOCSETP ioctls.
- */
-#ifndef _SGTTYB_
-#define	_SGTTYB_
-struct sgttyb {
-	char	sg_ispeed;		/* input speed */
-	char	sg_ospeed;		/* output speed */
-	char	sg_erase;		/* erase character */
-	char	sg_kill;		/* kill character */
-	short	sg_flags;		/* mode flags */
-};
-#endif
-#endif
-
-#ifdef USE_OLD_TTY
-# undef  TIOCGETD
-# define TIOCGETD	_IOR('t', 0, int)	/* get line discipline */
-# undef  TIOCSETD
-# define TIOCSETD	_IOW('t', 1, int)	/* set line discipline */
-#else
-# define OTIOCGETD	_IOR('t', 0, int)	/* get line discipline */
-# define OTIOCSETD	_IOW('t', 1, int)	/* set line discipline */
-#endif
-#define	TIOCHPCL	_IO('t', 2)		/* hang up on last close */
-#if !defined(__mips__)
-#define	TIOCGETP	_IOR('t', 8,struct sgttyb)/* get parameters -- gtty */
-#define	TIOCSETP	_IOW('t', 9,struct sgttyb)/* set parameters -- stty */
-#define	TIOCSETN	_IOW('t',10,struct sgttyb)/* as above, but no flushtty*/
-#endif
-#define	TIOCSETC	_IOW('t',17,struct tchars)/* set special characters */
-#define	TIOCGETC	_IOR('t',18,struct tchars)/* get special characters */
-#if 0
-/* BUG: a bunch of these conflict with #defines in asm/termbits.h */
-#define		TANDEM		0x00000001	/* send stopc on out q full */
-#define		CBREAK		0x00000002	/* half-cooked mode */
-#define		LCASE		0x00000004	/* simulate lower case */
-#define		ECHO		0x00000008	/* enable echoing */
-#define		CRMOD		0x00000010	/* map \r to \r\n on output */
-#define		RAW		0x00000020	/* no i/o processing */
-#define		ODDP		0x00000040	/* get/send odd parity */
-#define		EVENP		0x00000080	/* get/send even parity */
-#define		ANYP		0x000000c0	/* get any parity/send none */
-#define		NLDELAY		0x00000300	/* \n delay */
-#define			NL0	0x00000000
-#define			NL1	0x00000100	/* tty 37 */
-#define			NL2	0x00000200	/* vt05 */
-#define			NL3	0x00000300
-#define		TBDELAY		0x00000c00	/* horizontal tab delay */
-#define			TAB0	0x00000000
-#define			TAB1	0x00000400	/* tty 37 */
-#define			TAB2	0x00000800
-#define		XTABS		0x00000c00	/* expand tabs on output */
-#define		CRDELAY		0x00003000	/* \r delay */
-#define			CR0	0x00000000
-#define			CR1	0x00001000	/* tn 300 */
-#define			CR2	0x00002000	/* tty 37 */
-#define			CR3	0x00003000	/* concept 100 */
-#define		VTDELAY		0x00004000	/* vertical tab delay */
-#define			FF0	0x00000000
-#define			FF1	0x00004000	/* tty 37 */
-#define		BSDELAY		0x00008000	/* \b delay */
-#define			BS0	0x00000000
-#define			BS1	0x00008000
-#define		ALLDELAY	(NLDELAY|TBDELAY|CRDELAY|VTDELAY|BSDELAY)
-#define		CRTBS		0x00010000	/* do backspacing for crt */
-#define		PRTERA		0x00020000	/* \ ... / erase */
-#define		CRTERA		0x00040000	/* " \b " to wipe out char */
-#define		TILDE		0x00080000	/* hazeltine tilde kludge */
-#define		MDMBUF		0x00100000	/* DTR/DCD hardware flow control */
-#define		LITOUT		0x00200000	/* literal output */
-#define		TOSTOP		0x00400000	/* stop background jobs on output */
-#define		FLUSHO		0x00800000	/* output being flushed (state) */
-#define		NOHANG		0x01000000	/* (no-op) was no SIGHUP on carrier drop */
-#define		L001000		0x02000000
-#define		CRTKIL		0x04000000	/* kill line with " \b " */
-#define		PASS8		0x08000000
-#define		CTLECH		0x10000000	/* echo control chars as ^X */
-#define		PENDIN		0x20000000	/* re-echo input buffer at next read */
-#define		DECCTQ		0x40000000	/* only ^Q starts after ^S */
-#define		NOFLSH		0x80000000	/* don't flush output on signal */
-#endif
-#define	TIOCLBIS	_IOW('t', 127, int)	/* bis local mode bits */
-#define	TIOCLBIC	_IOW('t', 126, int)	/* bic local mode bits */
-#define	TIOCLSET	_IOW('t', 125, int)	/* set entire local mode word */
-#define	TIOCLGET	_IOR('t', 124, int)	/* get local modes */
-#define		LCRTBS		(CRTBS>>16)
-#define		LPRTERA		(PRTERA>>16)
-#define		LCRTERA		(CRTERA>>16)
-#define		LTILDE		(TILDE>>16)
-#define		LMDMBUF		(MDMBUF>>16)
-#define		LLITOUT		(LITOUT>>16)
-#define		LTOSTOP		(TOSTOP>>16)
-#define		LFLUSHO		(FLUSHO>>16)
-#define		LNOHANG		(NOHANG>>16)
-#define		LCRTKIL		(CRTKIL>>16)
-#define		LPASS8		(PASS8>>16)
-#define		LCTLECH		(CTLECH>>16)
-#define		LPENDIN		(PENDIN>>16)
-#define		LDECCTQ		(DECCTQ>>16)
-#define		LNOFLSH		(NOFLSH>>16)
-#if !defined(__mips__)
-#define	TIOCSLTC	_IOW('t',117,struct ltchars)/* set local special chars*/
-#define	TIOCGLTC	_IOR('t',116,struct ltchars)/* get local special chars*/
-#endif
-#define OTIOCCONS	_IO('t', 98)	/* for hp300 -- sans int arg */
-#define	OTTYDISC	0
-#define	NETLDISC	1
-#define	NTTYDISC	2
-
-#endif /* !_SYS_IOCTL_COMPAT_H_ */
diff --git a/libc/include/sys/signalfd.h b/libc/include/sys/signalfd.h
index 5b67822..084a528 100644
--- a/libc/include/sys/signalfd.h
+++ b/libc/include/sys/signalfd.h
@@ -35,7 +35,7 @@
 
 __BEGIN_DECLS
 
-extern int signalfd(int fd, const sigset_t* mask, int flags) __nonnull((2)) __INTRODUCED_IN(21);
+extern int signalfd(int fd, const sigset_t* _Nonnull mask, int flags) __INTRODUCED_IN(21);
 
 __END_DECLS
 
diff --git a/libc/include/sys/statvfs.h b/libc/include/sys/statvfs.h
index e12f069..1f00b9d 100644
--- a/libc/include/sys/statvfs.h
+++ b/libc/include/sys/statvfs.h
@@ -59,12 +59,12 @@
 #define ST_NODIRATIME  0x0800
 #define ST_RELATIME    0x1000
 
-extern int statvfs(const char* __restrict, struct statvfs* __restrict) __nonnull((1, 2))
+extern int statvfs(const char* __restrict _Nonnull, struct statvfs* __restrict _Nonnull)
   __INTRODUCED_IN(21);
-extern int statvfs64(const char* __restrict, struct statvfs64* __restrict) __nonnull((1, 2))
+extern int statvfs64(const char* __restrict _Nonnull, struct statvfs64* __restrict _Nonnull)
   __INTRODUCED_IN(21);
-extern int fstatvfs(int, struct statvfs*) __nonnull((2)) __INTRODUCED_IN(21);
-extern int fstatvfs64(int, struct statvfs64*) __nonnull((2)) __INTRODUCED_IN(21);
+extern int fstatvfs(int, struct statvfs* _Nonnull) __INTRODUCED_IN(21);
+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 b1f9295..fe14a30 100644
--- a/libc/include/sys/swap.h
+++ b/libc/include/sys/swap.h
@@ -38,8 +38,8 @@
 #define SWAP_FLAG_PRIO_MASK 0x7fff
 #define SWAP_FLAG_PRIO_SHIFT 0
 
-extern int swapon(const char*, int) __nonnull((1)) __INTRODUCED_IN(21);
-extern int swapoff(const char*) __nonnull((1)) __INTRODUCED_IN(21);
+extern int swapon(const char* _Nonnull, int) __INTRODUCED_IN(21);
+extern int swapoff(const char* _Nonnull) __INTRODUCED_IN(21);
 
 __END_DECLS
 
diff --git a/libc/include/sys/syscall.h b/libc/include/sys/syscall.h
index 21eaf33..87cddc9 100644
--- a/libc/include/sys/syscall.h
+++ b/libc/include/sys/syscall.h
@@ -30,7 +30,7 @@
 #define _SYS_SYSCALL_H_
 
 #include <asm/unistd.h> /* Linux kernel __NR_* names. */
-#include <sys/glibc-syscalls.h> /* glibc-compatible SYS_* aliases. */
+#include <bits/glibc-syscalls.h> /* glibc-compatible SYS_* aliases. */
 
 /* The syscall function itself is declared in <unistd.h>, not here. */
 
diff --git a/libc/include/sys/utime.h b/libc/include/sys/utime.h
deleted file mode 100644
index 9f8810e..0000000
--- a/libc/include/sys/utime.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#ifndef _SYS_UTIME_H_
-#define _SYS_UTIME_H_
-
-#include <linux/utime.h>
-
-#endif /* _SYS_UTIME_H_ */
diff --git a/libc/include/sys/vfs.h b/libc/include/sys/vfs.h
index 9f04b28..bf094dc 100644
--- a/libc/include/sys/vfs.h
+++ b/libc/include/sys/vfs.h
@@ -137,10 +137,10 @@
 #define XENIX_SUPER_MAGIC     0x012FF7B4
 #define XFS_SUPER_MAGIC       0x58465342
 
-extern int statfs(const char*, struct statfs*) __nonnull((1, 2));
-extern int statfs64(const char*, struct statfs64*) __nonnull((1, 2)) __INTRODUCED_IN(21);
-extern int fstatfs(int, struct statfs*) __nonnull((2));
-extern int fstatfs64(int, struct statfs64*) __nonnull((2)) __INTRODUCED_IN(21);
+extern int statfs(const char* _Nonnull, struct statfs* _Nonnull);
+extern int statfs64(const char* _Nonnull, struct statfs64* _Nonnull) __INTRODUCED_IN(21);
+extern int fstatfs(int, struct statfs* _Nonnull);
+extern int fstatfs64(int, struct statfs64* _Nonnull) __INTRODUCED_IN(21);
 
 __END_DECLS
 
diff --git a/libc/malloc_debug/Config.cpp b/libc/malloc_debug/Config.cpp
index cc60086..6220a23 100644
--- a/libc/malloc_debug/Config.cpp
+++ b/libc/malloc_debug/Config.cpp
@@ -84,7 +84,7 @@
 
 class PropertyParser {
  public:
-  PropertyParser(const char* property) : cur_(property) {}
+  explicit PropertyParser(const char* property) : cur_(property) {}
 
   bool Get(std::string* property, size_t* value, bool* value_set);
 
diff --git a/libc/malloc_debug/README.md b/libc/malloc_debug/README.md
index 3fc2305..d9eb782 100644
--- a/libc/malloc_debug/README.md
+++ b/libc/malloc_debug/README.md
@@ -8,22 +8,18 @@
 by adding a shim layer that replaces the normal allocation calls. The replaced
 calls are:
 
-<pre>
-malloc
-free
-calloc
-realloc
-posix_memalign
-memalign
-malloc_usable_size
-</pre>
+* `malloc`
+* `free`
+* `calloc`
+* `realloc`
+* `posix_memalign`
+* `memalign`
+* `malloc_usable_size`
 
 On 32 bit systems, these two deprecated functions are also replaced:
 
-<pre>
-pvalloc
-valloc
-</pre>
+* `pvalloc`
+* `valloc`
 
 Any errors detected by the library are reported in the log.
 
@@ -57,11 +53,9 @@
 
 Example error:
 
-<pre>
-04-10 12:00:45.621  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 SIZE 100 HAS A CORRUPTED FRONT GUARD
-04-10 12:00:45.622  7412  7412 E malloc_debug:   allocation[-32] = 0x00 (expected 0xaa)
-04-10 12:00:45.622  7412  7412 E malloc_debug:   allocation[-15] = 0x02 (expected 0xaa)
-</pre>
+    04-10 12:00:45.621  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 SIZE 100 HAS A CORRUPTED FRONT GUARD
+    04-10 12:00:45.622  7412  7412 E malloc_debug:   allocation[-32] = 0x00 (expected 0xaa)
+    04-10 12:00:45.622  7412  7412 E malloc_debug:   allocation[-15] = 0x02 (expected 0xaa)
 
 ### rear\_guard[=SIZE\_BYTES]
 Enables a small buffer placed after the allocated data. This is an attempt
@@ -79,11 +73,9 @@
 
 Example error:
 
-<pre>
-04-10 12:00:45.621  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 SIZE 100 HAS A CORRUPTED REAR GUARD
-04-10 12:00:45.622  7412  7412 E malloc_debug:   allocation[130] = 0xbf (expected 0xbb)
-04-10 12:00:45.622  7412  7412 E malloc_debug:   allocation[131] = 0x00 (expected 0xbb)
-</pre>
+    04-10 12:00:45.621  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 SIZE 100 HAS A CORRUPTED REAR GUARD
+    04-10 12:00:45.622  7412  7412 E malloc_debug:   allocation[130] = 0xbf (expected 0xbb)
+    04-10 12:00:45.622  7412  7412 E malloc_debug:   allocation[131] = 0x00 (expected 0xbb)
 
 ### guard[=SIZE\_BYTES]
 Enables both a front guard and a rear guard on all allocations.
@@ -173,25 +165,21 @@
 
 Example error:
 
-<pre>
-04-15 12:00:31.304  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 USED AFTER FREE
-04-15 12:00:31.305  7412  7412 E malloc_debug:   allocation[20] = 0xaf (expected 0xef)
-04-15 12:00:31.305  7412  7412 E malloc_debug:   allocation[99] = 0x12 (expected 0xef)
-04-15 12:00:31.305  7412  7412 E malloc_debug: Backtrace at time of free:
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
-</pre>
+    04-15 12:00:31.304  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 USED AFTER FREE
+    04-15 12:00:31.305  7412  7412 E malloc_debug:   allocation[20] = 0xaf (expected 0xef)
+    04-15 12:00:31.305  7412  7412 E malloc_debug:   allocation[99] = 0x12 (expected 0xef)
+    04-15 12:00:31.305  7412  7412 E malloc_debug: Backtrace at time of free:
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
 
 In addition, there is another type of error message that can occur if
 an allocation has a special header applied, and the header is corrupted
 before the verification occurs. This is the error message that will be found
 in the log:
 
-<pre>
-+++ ALLOCATION 0x12345678 HAS CORRUPTED HEADER TAG 0x1cc7dc00 AFTER FREE
-</pre>
+    04-15 12:00:31.604  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 HAS CORRUPTED HEADER TAG 0x1cc7dc00 AFTER FREE
 
 ### free\_track\_backtrace\_num\_frames[=MAX\_FRAMES]
 This option only has meaning if free\_track is set. It indicates how many
@@ -214,62 +202,54 @@
 
 Example leak error found in the log:
 
-<pre>
-04-15 12:35:33.304  7412  7412 E malloc_debug: +++ APP leaked block of size 100 at 0x2be3b0b0 (leak 1 of 2)
-04-15 12:35:33.304  7412  7412 E malloc_debug: Backtrace at time of allocation:
-04-15 12:35:33.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
-04-15 12:35:33.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
-04-15 12:35:33.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
-04-15 12:35:33.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
-04-15 12:35:33.305  7412  7412 E malloc_debug: +++ APP leaked block of size 24 at 0x7be32380 (leak 2 of 2)
-04-15 12:35:33.305  7412  7412 E malloc_debug: Backtrace at time of allocation:
-04-15 12:35:33.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
-04-15 12:35:33.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
-04-15 12:35:33.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
-04-15 12:35:33.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
-</pre>
+    04-15 12:35:33.304  7412  7412 E malloc_debug: +++ APP leaked block of size 100 at 0x2be3b0b0 (leak 1 of 2)
+    04-15 12:35:33.304  7412  7412 E malloc_debug: Backtrace at time of allocation:
+    04-15 12:35:33.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
+    04-15 12:35:33.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
+    04-15 12:35:33.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
+    04-15 12:35:33.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
+    04-15 12:35:33.305  7412  7412 E malloc_debug: +++ APP leaked block of size 24 at 0x7be32380 (leak 2 of 2)
+    04-15 12:35:33.305  7412  7412 E malloc_debug: Backtrace at time of allocation:
+    04-15 12:35:33.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
+    04-15 12:35:33.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
+    04-15 12:35:33.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
+    04-15 12:35:33.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
 
 Additional Errors
 -----------------
 There are a few other error messages that might appear in the log.
 
 ### Use After Free
-<pre>
-04-15 12:00:31.304  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 USED AFTER FREE (free)
-04-15 12:00:31.305  7412  7412 E malloc_debug: Backtrace of original free:
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
-04-15 12:00:31.305  7412  7412 E malloc_debug: Backtrace at time of failure:
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
-</pre>
+    04-15 12:00:31.304  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 USED AFTER FREE (free)
+    04-15 12:00:31.305  7412  7412 E malloc_debug: Backtrace of original free:
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug: Backtrace at time of failure:
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
 
 This indicates that code is attempting to free an already freed pointer. The
 name in parenthesis indicates that the application called the function
-<i>free</i> with the bad pointer.
+*free* with the bad pointer.
 
 For example, this message:
 
-<pre>
-04-15 12:00:31.304  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 USED AFTER FREE (realloc)
-</pre>
+    04-15 12:00:31.304  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 USED AFTER FREE (realloc)
 
-Would indicate that the application called the <i>realloc</i> function
+Would indicate that the application called the *realloc* function
 with an already freed pointer.
 
 ### Invalid Tag
-<pre>
-04-15 12:00:31.304  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 HAS INVALID TAG 1ee7d000 (malloc_usable_size)
-04-15 12:00:31.305  7412  7412 E malloc_debug: Backtrace at time of failure:
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
-</pre>
+    04-15 12:00:31.304  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 HAS INVALID TAG 1ee7d000 (malloc_usable_size)
+    04-15 12:00:31.305  7412  7412 E malloc_debug: Backtrace at time of failure:
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
 
 This indicates that a function (malloc\_usable\_size) was called with
 a pointer that is either not allocated memory, or that the memory of
@@ -282,36 +262,28 @@
 ========
 Enable backtrace tracking of all allocation for all processes:
 
-<pre>
-  adb shell stop
-  adb shell setprop libc.debug.malloc.options backtrace
-  adb shell start
-</pre>
+    adb shell stop
+    adb shell setprop libc.debug.malloc.options backtrace
+    adb shell start
 
 Enable backtrace tracking for a specific process (ls):
 
-<pre>
-  adb shell setprop libc.debug.malloc.options backtrace
-  adb shell setprop libc.debug.malloc.program ls
-  adb shell ls
-</pre>
+    adb shell setprop libc.debug.malloc.options backtrace
+    adb shell setprop libc.debug.malloc.program ls
+    adb shell ls
 
 Enable backtrace tracking for the zygote and zygote based processes:
 
-<pre>
-  adb shell stop
-  adb shell setprop libc.debug.malloc.program app_process
-  adb shell setprop libc.debug.malloc.options backtrace
-  adb shell start
-</pre>
+    adb shell stop
+    adb shell setprop libc.debug.malloc.program app_process
+    adb shell setprop libc.debug.malloc.options backtrace
+    adb shell start
 
 Enable multiple options (backtrace and guards):
 
-<pre>
-  adb shell stop
-  adb shell setprop libc.debug.malloc.options "\"backtrace guards\""
-  adb shell start
-</pre>
+    adb shell stop
+    adb shell setprop libc.debug.malloc.options "\"backtrace guards\""
+    adb shell start
 
 Enable malloc debug when multiple processes have the same name. This method
 can be used to enable malloc debug for only a very specific process if
@@ -321,10 +293,8 @@
 the setprop command will fail since the backtrace guards options will look
 like two arguments instead of one.
 
-<pre>
-  adb shell
-  # setprop libc.debug.malloc.env_enabled
-  # setprop libc.debug.malloc.options backtrace
-  # export LIBC_DEBUG_MALLOC_ENABLE 1
-  # ls
-</pre>
+    adb shell
+    # setprop libc.debug.malloc.env_enabled
+    # setprop libc.debug.malloc.options backtrace
+    # export LIBC_DEBUG_MALLOC_ENABLE 1
+    # ls
diff --git a/libc/malloc_debug/README_api.md b/libc/malloc_debug/README_api.md
index cd04c32..63ad42a 100644
--- a/libc/malloc_debug/README_api.md
+++ b/libc/malloc_debug/README_api.md
@@ -7,57 +7,47 @@
 
 The function to gather the data:
 
-<pre>
-<b>
-extern "C" void get_malloc_leak_info(uint8_t** info, size_t* overall_size, size_t* info_size, size_t* total_memory, size_t* backtrace_size);
-</b>
-</pre>
+`extern "C" void get_malloc_leak_info(uint8_t** info, size_t* overall_size, size_t* info_size, size_t* total_memory, size_t* backtrace_size);`
 
-<i>info</i> is set to a buffer allocated by the call that contains all of
+*info* is set to a buffer allocated by the call that contains all of
 the allocation information.
-<i>overall\_size</i> is set to the total size of the buffer returned. If this
-<i>info\_size</i>
+*overall\_size* is set to the total size of the buffer returned. If this
+*info\_size*
 value is zero, then there are no allocation being tracked.
-<i>total\_memory</i> is set to the sum of all allocation sizes that are live at
+*total\_memory* is set to the sum of all allocation sizes that are live at
 the point of the function call. This does not include the memory allocated
 by the malloc debug library itself.
-<i>backtrace\_size</i> is set to the maximum number of backtrace entries
+*backtrace\_size* is set to the maximum number of backtrace entries
 that are present for each allocation.
 
 In order to free the buffer allocated by the function, call:
 
-<pre>
-<b>
-extern "C" void free_malloc_leak_info(uint8_t* info);
-</b>
-</pre>
+`extern "C" void free_malloc_leak_info(uint8_t* info);`
 
 ### Format of info Buffer
-<pre>
-size_t size_of_original_allocation
-size_t num_backtrace_frames
-uintptr_t pc1
-uintptr_t pc2
-uintptr_t pc3
-.
-.
-.
-</pre>
+    size_t size_of_original_allocation
+    size_t num_backtrace_frames
+    uintptr_t pc1
+    uintptr_t pc2
+    uintptr_t pc3
+    .
+    .
+    .
 
-The number of <i>uintptr\_t</i> values is determined by the value
-<i>backtrace\_size</i> as returned by the original call to
-<i>get\_malloc\_leak\_info</i>. This value is not variable, it is the same
+The number of *uintptr\_t* values is determined by the value
+*backtrace\_size* as returned by the original call to
+*get\_malloc\_leak\_info*. This value is not variable, it is the same
 for all the returned data. The value
-<i>num\_backtrace\_frames</i> contains the real number of frames found. The
-extra frames are set to zero. Each <i>uintptr\_t</i> is a pc of the callstack.
+*num\_backtrace\_frames* contains the real number of frames found. The
+extra frames are set to zero. Each *uintptr\_t* is a pc of the callstack.
 The calls from within the malloc debug library are automatically removed.
 
-For 32 bit systems, <i>size\_t</i> and <i>uintptr\_t</i> are both 4 byte values.
+For 32 bit systems, *size\_t* and *uintptr\_t* are both 4 byte values.
 
-For 64 bit systems, <i>size\_t</i> and <i>uintptr\_t</i> are both 8 byte values.
+For 64 bit systems, *size\_t* and *uintptr\_t* are both 8 byte values.
 
-The total number of these structures returned in <i>info</i> is
-<i>overall\_size</i> divided by <i>info\_size</i>.
+The total number of these structures returned in *info* is
+*overall\_size* divided by *info\_size*.
 
 Note, the size value in each allocation data structure will have bit 31 set
 if this allocation was created by the Zygote process. This helps to distinguish
diff --git a/libc/include/machine/ieee.h b/libc/private/bionic_ieee.h
similarity index 100%
rename from libc/include/machine/ieee.h
rename to libc/private/bionic_ieee.h
diff --git a/libc/stdio/stdio.cpp b/libc/stdio/stdio.cpp
index 1c31a27..5df1bb9 100644
--- a/libc/stdio/stdio.cpp
+++ b/libc/stdio/stdio.cpp
@@ -90,7 +90,7 @@
 
 class ScopedFileLock {
  public:
-  ScopedFileLock(FILE* fp) : fp_(fp) {
+  explicit ScopedFileLock(FILE* fp) : fp_(fp) {
     FLOCKFILE(fp_);
   }
   ~ScopedFileLock() {
diff --git a/libc/tools/check-symbols-glibc.py b/libc/tools/check-symbols-glibc.py
index 43531c0..3185c81 100755
--- a/libc/tools/check-symbols-glibc.py
+++ b/libc/tools/check-symbols-glibc.py
@@ -108,15 +108,16 @@
   '__strlen_chk',
   '__strncpy_chk2',
   '__strrchr_chk',
-  '__umask_chk'
+  '__umask_chk',
   '__write_chk',
 ])
-# Some symbols are used to implement public macros.
+# Some symbols are used to implement public functions/macros.
 macro_stuff = set([
   '__assert2',
   '__errno',
   '__fe_dfl_env',
   '__get_h_errno',
+  '__gnu_strerror_r',
   '__fpclassifyd',
   '__isfinite',
   '__isfinitef',
@@ -132,7 +133,8 @@
 linux_stuff = set([
   'getauxval',
   'gettid',
-  'tgkill'
+  'pthread_gettid_np',
+  'tgkill',
 ])
 # Some standard stuff isn't yet in the versions of glibc we're using.
 std_stuff = set([
@@ -168,6 +170,7 @@
 libresolv_stuff = set([
   '__res_send_setqhook',
   '__res_send_setrhook',
+  '_resolv_delete_cache_for_net',
   '_resolv_flush_cache_for_net',
   '_resolv_set_nameservers_for_net',
   'dn_expand',
diff --git a/libc/tools/gensyscalls.py b/libc/tools/gensyscalls.py
index 04ccf39..de06a2f 100755
--- a/libc/tools/gensyscalls.py
+++ b/libc/tools/gensyscalls.py
@@ -570,7 +570,7 @@
 
     def gen_glibc_syscalls_h(self):
         # TODO: generate a separate file for each architecture, like glibc's bits/syscall.h.
-        glibc_syscalls_h_path = "include/sys/glibc-syscalls.h"
+        glibc_syscalls_h_path = "include/bits/glibc-syscalls.h"
         logging.info("generating " + glibc_syscalls_h_path)
         glibc_fp = create_file(glibc_syscalls_h_path)
         glibc_fp.write("/* %s */\n" % warning)
diff --git a/libc/upstream-freebsd/android/include/machine/endian.h b/libc/upstream-freebsd/android/include/machine/endian.h
new file mode 100644
index 0000000..2dc4d83
--- /dev/null
+++ b/libc/upstream-freebsd/android/include/machine/endian.h
@@ -0,0 +1 @@
+#include <endian.h>
diff --git a/libc/upstream-openbsd/android/include/machine/ieee.h b/libc/upstream-openbsd/android/include/machine/ieee.h
new file mode 100644
index 0000000..dac332a
--- /dev/null
+++ b/libc/upstream-openbsd/android/include/machine/ieee.h
@@ -0,0 +1 @@
+#include "private/bionic_ieee.h"
diff --git a/libm/Android.bp b/libm/Android.bp
index 27ea1c1..f3d2765 100644
--- a/libm/Android.bp
+++ b/libm/Android.bp
@@ -1,330 +1,285 @@
-// ANDROIDMK TRANSLATION ERROR: unsupported directive
+// ANDROIDMK TRANSLATION ERROR: unsupported conditional
 // ifneq ($(TARGET_USE_PRIVATE_LIBM),true)
 
 bionic_coverage = false
 
-libm_common_src_files = [
-    "upstream-freebsd/lib/msun/bsdsrc/b_exp.c",
-    "upstream-freebsd/lib/msun/bsdsrc/b_log.c",
-    "upstream-freebsd/lib/msun/bsdsrc/b_tgamma.c",
-    "upstream-freebsd/lib/msun/src/catrig.c",
-    "upstream-freebsd/lib/msun/src/catrigf.c",
-    "upstream-freebsd/lib/msun/src/e_acos.c",
-    "upstream-freebsd/lib/msun/src/e_acosf.c",
-    "upstream-freebsd/lib/msun/src/e_acosh.c",
-    "upstream-freebsd/lib/msun/src/e_acoshf.c",
-    "upstream-freebsd/lib/msun/src/e_asin.c",
-    "upstream-freebsd/lib/msun/src/e_asinf.c",
-    "upstream-freebsd/lib/msun/src/e_atan2.c",
-    "upstream-freebsd/lib/msun/src/e_atan2f.c",
-    "upstream-freebsd/lib/msun/src/e_atanh.c",
-    "upstream-freebsd/lib/msun/src/e_atanhf.c",
-    "upstream-freebsd/lib/msun/src/e_cosh.c",
-    "upstream-freebsd/lib/msun/src/e_coshf.c",
-    "upstream-freebsd/lib/msun/src/e_exp.c",
-    "upstream-freebsd/lib/msun/src/e_expf.c",
-    "upstream-freebsd/lib/msun/src/e_fmod.c",
-    "upstream-freebsd/lib/msun/src/e_fmodf.c",
-    "upstream-freebsd/lib/msun/src/e_gamma.c",
-    "upstream-freebsd/lib/msun/src/e_gammaf.c",
-    "upstream-freebsd/lib/msun/src/e_gammaf_r.c",
-    "upstream-freebsd/lib/msun/src/e_gamma_r.c",
-    "upstream-freebsd/lib/msun/src/e_hypot.c",
-    "upstream-freebsd/lib/msun/src/e_hypotf.c",
-    "upstream-freebsd/lib/msun/src/e_j0.c",
-    "upstream-freebsd/lib/msun/src/e_j0f.c",
-    "upstream-freebsd/lib/msun/src/e_j1.c",
-    "upstream-freebsd/lib/msun/src/e_j1f.c",
-    "upstream-freebsd/lib/msun/src/e_jn.c",
-    "upstream-freebsd/lib/msun/src/e_jnf.c",
-    "upstream-freebsd/lib/msun/src/e_lgamma.c",
-    "upstream-freebsd/lib/msun/src/e_lgammaf.c",
-    "upstream-freebsd/lib/msun/src/e_lgammaf_r.c",
-    "upstream-freebsd/lib/msun/src/e_lgamma_r.c",
-    "upstream-freebsd/lib/msun/src/e_log10.c",
-    "upstream-freebsd/lib/msun/src/e_log10f.c",
-    "upstream-freebsd/lib/msun/src/e_log2.c",
-    "upstream-freebsd/lib/msun/src/e_log2f.c",
-    "upstream-freebsd/lib/msun/src/e_log.c",
-    "upstream-freebsd/lib/msun/src/e_logf.c",
-    "upstream-freebsd/lib/msun/src/e_pow.c",
-    "upstream-freebsd/lib/msun/src/e_powf.c",
-    "upstream-freebsd/lib/msun/src/e_remainder.c",
-    "upstream-freebsd/lib/msun/src/e_remainderf.c",
-    "upstream-freebsd/lib/msun/src/e_rem_pio2.c",
-    "upstream-freebsd/lib/msun/src/e_rem_pio2f.c",
-    "upstream-freebsd/lib/msun/src/e_scalb.c",
-    "upstream-freebsd/lib/msun/src/e_scalbf.c",
-    "upstream-freebsd/lib/msun/src/e_sinh.c",
-    "upstream-freebsd/lib/msun/src/e_sinhf.c",
-    "upstream-freebsd/lib/msun/src/e_sqrt.c",
-    "upstream-freebsd/lib/msun/src/e_sqrtf.c",
-    "upstream-freebsd/lib/msun/src/imprecise.c",
-    "upstream-freebsd/lib/msun/src/k_cos.c",
-    "upstream-freebsd/lib/msun/src/k_cosf.c",
-    "upstream-freebsd/lib/msun/src/k_exp.c",
-    "upstream-freebsd/lib/msun/src/k_expf.c",
-    "upstream-freebsd/lib/msun/src/k_rem_pio2.c",
-    "upstream-freebsd/lib/msun/src/k_sin.c",
-    "upstream-freebsd/lib/msun/src/k_sinf.c",
-    "upstream-freebsd/lib/msun/src/k_tan.c",
-    "upstream-freebsd/lib/msun/src/k_tanf.c",
-    "upstream-freebsd/lib/msun/src/s_asinh.c",
-    "upstream-freebsd/lib/msun/src/s_asinhf.c",
-    "upstream-freebsd/lib/msun/src/s_atan.c",
-    "upstream-freebsd/lib/msun/src/s_atanf.c",
-    "upstream-freebsd/lib/msun/src/s_carg.c",
-    "upstream-freebsd/lib/msun/src/s_cargf.c",
-    "upstream-freebsd/lib/msun/src/s_cargl.c",
-    "upstream-freebsd/lib/msun/src/s_cbrt.c",
-    "upstream-freebsd/lib/msun/src/s_cbrtf.c",
-    "upstream-freebsd/lib/msun/src/s_ccosh.c",
-    "upstream-freebsd/lib/msun/src/s_ccoshf.c",
-    "upstream-freebsd/lib/msun/src/s_ceil.c",
-    "upstream-freebsd/lib/msun/src/s_ceilf.c",
-    "upstream-freebsd/lib/msun/src/s_cexp.c",
-    "upstream-freebsd/lib/msun/src/s_cexpf.c",
-    "upstream-freebsd/lib/msun/src/s_cimag.c",
-    "upstream-freebsd/lib/msun/src/s_cimagf.c",
-    "upstream-freebsd/lib/msun/src/s_cimagl.c",
-    "upstream-freebsd/lib/msun/src/s_conj.c",
-    "upstream-freebsd/lib/msun/src/s_conjf.c",
-    "upstream-freebsd/lib/msun/src/s_conjl.c",
-    "upstream-freebsd/lib/msun/src/s_copysign.c",
-    "upstream-freebsd/lib/msun/src/s_copysignf.c",
-    "upstream-freebsd/lib/msun/src/s_cos.c",
-    "upstream-freebsd/lib/msun/src/s_cosf.c",
-    "upstream-freebsd/lib/msun/src/s_cproj.c",
-    "upstream-freebsd/lib/msun/src/s_cprojf.c",
-    "upstream-freebsd/lib/msun/src/s_cprojl.c",
-    "upstream-freebsd/lib/msun/src/s_creal.c",
-    "upstream-freebsd/lib/msun/src/s_crealf.c",
-    "upstream-freebsd/lib/msun/src/s_creall.c",
-    "upstream-freebsd/lib/msun/src/s_csinh.c",
-    "upstream-freebsd/lib/msun/src/s_csinhf.c",
-    "upstream-freebsd/lib/msun/src/s_csqrt.c",
-    "upstream-freebsd/lib/msun/src/s_csqrtf.c",
-    "upstream-freebsd/lib/msun/src/s_csqrtl.c",
-    "upstream-freebsd/lib/msun/src/s_ctanh.c",
-    "upstream-freebsd/lib/msun/src/s_ctanhf.c",
-    "upstream-freebsd/lib/msun/src/s_erf.c",
-    "upstream-freebsd/lib/msun/src/s_erff.c",
-    "upstream-freebsd/lib/msun/src/s_exp2.c",
-    "upstream-freebsd/lib/msun/src/s_exp2f.c",
-    "upstream-freebsd/lib/msun/src/s_expm1.c",
-    "upstream-freebsd/lib/msun/src/s_expm1f.c",
-    "upstream-freebsd/lib/msun/src/s_fdim.c",
-    "upstream-freebsd/lib/msun/src/s_finite.c",
-    "upstream-freebsd/lib/msun/src/s_finitef.c",
-    "upstream-freebsd/lib/msun/src/s_floor.c",
-    "upstream-freebsd/lib/msun/src/s_floorf.c",
-    "upstream-freebsd/lib/msun/src/s_fma.c",
-    "upstream-freebsd/lib/msun/src/s_fmaf.c",
-    "upstream-freebsd/lib/msun/src/s_fmax.c",
-    "upstream-freebsd/lib/msun/src/s_fmaxf.c",
-    "upstream-freebsd/lib/msun/src/s_fmin.c",
-    "upstream-freebsd/lib/msun/src/s_fminf.c",
-    "upstream-freebsd/lib/msun/src/s_frexp.c",
-    "upstream-freebsd/lib/msun/src/s_frexpf.c",
-    "upstream-freebsd/lib/msun/src/s_ilogb.c",
-    "upstream-freebsd/lib/msun/src/s_ilogbf.c",
-    "upstream-freebsd/lib/msun/src/s_llrint.c",
-    "upstream-freebsd/lib/msun/src/s_llrintf.c",
-    "upstream-freebsd/lib/msun/src/s_llround.c",
-    "upstream-freebsd/lib/msun/src/s_llroundf.c",
-    "upstream-freebsd/lib/msun/src/s_log1p.c",
-    "upstream-freebsd/lib/msun/src/s_log1pf.c",
-    "upstream-freebsd/lib/msun/src/s_logb.c",
-    "upstream-freebsd/lib/msun/src/s_logbf.c",
-    "upstream-freebsd/lib/msun/src/s_lrint.c",
-    "upstream-freebsd/lib/msun/src/s_lrintf.c",
-    "upstream-freebsd/lib/msun/src/s_lround.c",
-    "upstream-freebsd/lib/msun/src/s_lroundf.c",
-    "upstream-freebsd/lib/msun/src/s_modf.c",
-    "upstream-freebsd/lib/msun/src/s_modff.c",
-    "upstream-freebsd/lib/msun/src/s_nan.c",
-    "upstream-freebsd/lib/msun/src/s_nearbyint.c",
-    "upstream-freebsd/lib/msun/src/s_nextafter.c",
-    "upstream-freebsd/lib/msun/src/s_nextafterf.c",
-    "upstream-freebsd/lib/msun/src/s_remquo.c",
-    "upstream-freebsd/lib/msun/src/s_remquof.c",
-    "upstream-freebsd/lib/msun/src/s_rint.c",
-    "upstream-freebsd/lib/msun/src/s_rintf.c",
-    "upstream-freebsd/lib/msun/src/s_round.c",
-    "upstream-freebsd/lib/msun/src/s_roundf.c",
-    "upstream-freebsd/lib/msun/src/s_scalbln.c",
-    "upstream-freebsd/lib/msun/src/s_scalbn.c",
-    "upstream-freebsd/lib/msun/src/s_scalbnf.c",
-    "upstream-freebsd/lib/msun/src/s_signgam.c",
-    "upstream-freebsd/lib/msun/src/s_significand.c",
-    "upstream-freebsd/lib/msun/src/s_significandf.c",
-    "upstream-freebsd/lib/msun/src/s_sin.c",
-    "upstream-freebsd/lib/msun/src/s_sinf.c",
-    "upstream-freebsd/lib/msun/src/s_tan.c",
-    "upstream-freebsd/lib/msun/src/s_tanf.c",
-    "upstream-freebsd/lib/msun/src/s_tanh.c",
-    "upstream-freebsd/lib/msun/src/s_tanhf.c",
-    "upstream-freebsd/lib/msun/src/s_tgammaf.c",
-    "upstream-freebsd/lib/msun/src/s_trunc.c",
-    "upstream-freebsd/lib/msun/src/s_truncf.c",
-    "upstream-freebsd/lib/msun/src/w_cabs.c",
-    "upstream-freebsd/lib/msun/src/w_cabsf.c",
-    "upstream-freebsd/lib/msun/src/w_cabsl.c",
-    "upstream-freebsd/lib/msun/src/w_drem.c",
-    "upstream-freebsd/lib/msun/src/w_dremf.c",
-
-    // The FreeBSD complex functions appear to be better, but they're incomplete.
-    // We take the FreeBSD implementations when they exist, but fill out the rest
-    // of <complex.h> from NetBSD...
-    "upstream-netbsd/lib/libm/complex/cacoshl.c",
-    "upstream-netbsd/lib/libm/complex/cacosl.c",
-    "upstream-netbsd/lib/libm/complex/casinhl.c",
-    "upstream-netbsd/lib/libm/complex/casinl.c",
-    "upstream-netbsd/lib/libm/complex/catanhl.c",
-    "upstream-netbsd/lib/libm/complex/catanl.c",
-    "upstream-netbsd/lib/libm/complex/ccoshl.c",
-    "upstream-netbsd/lib/libm/complex/ccosl.c",
-    "upstream-netbsd/lib/libm/complex/cephes_subrl.c",
-    "upstream-netbsd/lib/libm/complex/cexpl.c",
-    "upstream-netbsd/lib/libm/complex/clog.c",
-    "upstream-netbsd/lib/libm/complex/clogf.c",
-    "upstream-netbsd/lib/libm/complex/clogl.c",
-    "upstream-netbsd/lib/libm/complex/cpow.c",
-    "upstream-netbsd/lib/libm/complex/cpowf.c",
-    "upstream-netbsd/lib/libm/complex/cpowl.c",
-    "upstream-netbsd/lib/libm/complex/csinhl.c",
-    "upstream-netbsd/lib/libm/complex/csinl.c",
-    "upstream-netbsd/lib/libm/complex/ctanhl.c",
-    "upstream-netbsd/lib/libm/complex/ctanl.c",
-]
-
-libm_common_src_files += [
-    // TODO: this comes from from upstream's libc, not libm, but it's an
-    // implementation detail that should have hidden visibility, so it needs
-    // to be in whatever library the math code is in.
-    "digittoint.c",
-
-    // Functionality not in the BSDs.
-    "significandl.c",
-    "sincos.c",
-
-    // Modified versions of BSD code.
-    "signbit.c",
-
-    // Home-grown stuff.
-    "fabs.cpp",
-]
-
-libm_ld128_src_files = [
-    "upstream-freebsd/lib/msun/src/e_acosl.c",
-    "upstream-freebsd/lib/msun/src/e_acoshl.c",
-    "upstream-freebsd/lib/msun/src/e_asinl.c",
-    "upstream-freebsd/lib/msun/src/e_atan2l.c",
-    "upstream-freebsd/lib/msun/src/e_atanhl.c",
-    "upstream-freebsd/lib/msun/src/e_fmodl.c",
-    "upstream-freebsd/lib/msun/src/e_hypotl.c",
-    "upstream-freebsd/lib/msun/src/e_lgammal.c",
-    "upstream-freebsd/lib/msun/src/e_remainderl.c",
-    "upstream-freebsd/lib/msun/src/e_sqrtl.c",
-    "upstream-freebsd/lib/msun/src/s_asinhl.c",
-    "upstream-freebsd/lib/msun/src/s_atanl.c",
-    "upstream-freebsd/lib/msun/src/s_cbrtl.c",
-    "upstream-freebsd/lib/msun/src/s_ceill.c",
-    "upstream-freebsd/lib/msun/src/s_copysignl.c",
-    "upstream-freebsd/lib/msun/src/e_coshl.c",
-    "upstream-freebsd/lib/msun/src/s_cosl.c",
-    "upstream-freebsd/lib/msun/src/s_floorl.c",
-    "upstream-freebsd/lib/msun/src/s_fmal.c",
-    "upstream-freebsd/lib/msun/src/s_fmaxl.c",
-    "upstream-freebsd/lib/msun/src/s_fminl.c",
-    "upstream-freebsd/lib/msun/src/s_modfl.c",
-    "upstream-freebsd/lib/msun/src/s_frexpl.c",
-    "upstream-freebsd/lib/msun/src/s_ilogbl.c",
-    "upstream-freebsd/lib/msun/src/s_llrintl.c",
-    "upstream-freebsd/lib/msun/src/s_llroundl.c",
-    "upstream-freebsd/lib/msun/src/s_logbl.c",
-    "upstream-freebsd/lib/msun/src/s_lrintl.c",
-    "upstream-freebsd/lib/msun/src/s_lroundl.c",
-    "upstream-freebsd/lib/msun/src/s_nextafterl.c",
-    "upstream-freebsd/lib/msun/src/s_nexttoward.c",
-    "upstream-freebsd/lib/msun/src/s_nexttowardf.c",
-    "upstream-freebsd/lib/msun/src/s_remquol.c",
-    "upstream-freebsd/lib/msun/src/s_rintl.c",
-    "upstream-freebsd/lib/msun/src/s_roundl.c",
-    "upstream-freebsd/lib/msun/src/s_scalbnl.c",
-    "upstream-freebsd/lib/msun/src/e_sinhl.c",
-    "upstream-freebsd/lib/msun/src/s_sinl.c",
-    "upstream-freebsd/lib/msun/src/s_tanhl.c",
-    "upstream-freebsd/lib/msun/src/s_tanl.c",
-    "upstream-freebsd/lib/msun/src/s_truncl.c",
-]
-
-libm_ld128_src_files += [
-    "upstream-freebsd/lib/msun/ld128/invtrig.c",
-    "upstream-freebsd/lib/msun/ld128/e_lgammal_r.c",
-    "upstream-freebsd/lib/msun/ld128/k_cosl.c",
-    "upstream-freebsd/lib/msun/ld128/k_sinl.c",
-    "upstream-freebsd/lib/msun/ld128/k_tanl.c",
-    "upstream-freebsd/lib/msun/ld128/s_erfl.c",
-    "upstream-freebsd/lib/msun/ld128/s_exp2l.c",
-    "upstream-freebsd/lib/msun/ld128/s_expl.c",
-    "upstream-freebsd/lib/msun/ld128/s_logl.c",
-    "upstream-freebsd/lib/msun/ld128/s_nanl.c",
-]
-
-// TODO: re-enable i387/e_sqrtf.S for x86, and maybe others.
-
-libm_common_cflags = [
-    "-D__BIONIC_NO_MATH_INLINES",
-    "-DFLT_EVAL_METHOD=0",
-    "-include freebsd-compat.h",
-    "-Werror",
-    "-Wno-missing-braces",
-    "-Wno-parentheses",
-    "-Wno-sign-compare",
-    "-Wno-uninitialized",
-    "-Wno-unknown-pragmas",
-    "-fvisibility=hidden",
-]
-
-// Workaround the GCC "(long)fn -> lfn" optimization bug which will result in
-// self recursions for lrint, lrintf, and lrintl.
-// BUG: 14225968
-libm_common_cflags += [
-    "-fno-builtin-rint",
-    "-fno-builtin-rintf",
-    "-fno-builtin-rintl",
-]
-
-libm_common_local_includes = ["upstream-freebsd/lib/msun/src/"]
-
-libm_ld_local_includes = ["upstream-freebsd/lib/msun/ld128/"]
-
 //
 // libm.so and libm.a for target.
 //
 cc_library {
     name: "libm",
 
-    cflags: libm_common_cflags,
-    conlyflags: ["-std=gnu11"],
-    include_dirs: ["bionic/libc"],
-    local_include_dirs: libm_common_local_includes,
-    srcs: libm_common_src_files,
-    system_shared_libs: ["libc"],
+    srcs: [
+        "upstream-freebsd/lib/msun/bsdsrc/b_exp.c",
+        "upstream-freebsd/lib/msun/bsdsrc/b_log.c",
+        "upstream-freebsd/lib/msun/bsdsrc/b_tgamma.c",
+        "upstream-freebsd/lib/msun/src/catrig.c",
+        "upstream-freebsd/lib/msun/src/catrigf.c",
+        "upstream-freebsd/lib/msun/src/e_acos.c",
+        "upstream-freebsd/lib/msun/src/e_acosf.c",
+        "upstream-freebsd/lib/msun/src/e_acosh.c",
+        "upstream-freebsd/lib/msun/src/e_acoshf.c",
+        "upstream-freebsd/lib/msun/src/e_asin.c",
+        "upstream-freebsd/lib/msun/src/e_asinf.c",
+        "upstream-freebsd/lib/msun/src/e_atan2.c",
+        "upstream-freebsd/lib/msun/src/e_atan2f.c",
+        "upstream-freebsd/lib/msun/src/e_atanh.c",
+        "upstream-freebsd/lib/msun/src/e_atanhf.c",
+        "upstream-freebsd/lib/msun/src/e_cosh.c",
+        "upstream-freebsd/lib/msun/src/e_coshf.c",
+        "upstream-freebsd/lib/msun/src/e_exp.c",
+        "upstream-freebsd/lib/msun/src/e_expf.c",
+        "upstream-freebsd/lib/msun/src/e_fmod.c",
+        "upstream-freebsd/lib/msun/src/e_fmodf.c",
+        "upstream-freebsd/lib/msun/src/e_gamma.c",
+        "upstream-freebsd/lib/msun/src/e_gammaf.c",
+        "upstream-freebsd/lib/msun/src/e_gammaf_r.c",
+        "upstream-freebsd/lib/msun/src/e_gamma_r.c",
+        "upstream-freebsd/lib/msun/src/e_hypot.c",
+        "upstream-freebsd/lib/msun/src/e_hypotf.c",
+        "upstream-freebsd/lib/msun/src/e_j0.c",
+        "upstream-freebsd/lib/msun/src/e_j0f.c",
+        "upstream-freebsd/lib/msun/src/e_j1.c",
+        "upstream-freebsd/lib/msun/src/e_j1f.c",
+        "upstream-freebsd/lib/msun/src/e_jn.c",
+        "upstream-freebsd/lib/msun/src/e_jnf.c",
+        "upstream-freebsd/lib/msun/src/e_lgamma.c",
+        "upstream-freebsd/lib/msun/src/e_lgammaf.c",
+        "upstream-freebsd/lib/msun/src/e_lgammaf_r.c",
+        "upstream-freebsd/lib/msun/src/e_lgamma_r.c",
+        "upstream-freebsd/lib/msun/src/e_log10.c",
+        "upstream-freebsd/lib/msun/src/e_log10f.c",
+        "upstream-freebsd/lib/msun/src/e_log2.c",
+        "upstream-freebsd/lib/msun/src/e_log2f.c",
+        "upstream-freebsd/lib/msun/src/e_log.c",
+        "upstream-freebsd/lib/msun/src/e_logf.c",
+        "upstream-freebsd/lib/msun/src/e_pow.c",
+        "upstream-freebsd/lib/msun/src/e_powf.c",
+        "upstream-freebsd/lib/msun/src/e_remainder.c",
+        "upstream-freebsd/lib/msun/src/e_remainderf.c",
+        "upstream-freebsd/lib/msun/src/e_rem_pio2.c",
+        "upstream-freebsd/lib/msun/src/e_rem_pio2f.c",
+        "upstream-freebsd/lib/msun/src/e_scalb.c",
+        "upstream-freebsd/lib/msun/src/e_scalbf.c",
+        "upstream-freebsd/lib/msun/src/e_sinh.c",
+        "upstream-freebsd/lib/msun/src/e_sinhf.c",
+        "upstream-freebsd/lib/msun/src/e_sqrt.c",
+        "upstream-freebsd/lib/msun/src/e_sqrtf.c",
+        "upstream-freebsd/lib/msun/src/imprecise.c",
+        "upstream-freebsd/lib/msun/src/k_cos.c",
+        "upstream-freebsd/lib/msun/src/k_cosf.c",
+        "upstream-freebsd/lib/msun/src/k_exp.c",
+        "upstream-freebsd/lib/msun/src/k_expf.c",
+        "upstream-freebsd/lib/msun/src/k_rem_pio2.c",
+        "upstream-freebsd/lib/msun/src/k_sin.c",
+        "upstream-freebsd/lib/msun/src/k_sinf.c",
+        "upstream-freebsd/lib/msun/src/k_tan.c",
+        "upstream-freebsd/lib/msun/src/k_tanf.c",
+        "upstream-freebsd/lib/msun/src/s_asinh.c",
+        "upstream-freebsd/lib/msun/src/s_asinhf.c",
+        "upstream-freebsd/lib/msun/src/s_atan.c",
+        "upstream-freebsd/lib/msun/src/s_atanf.c",
+        "upstream-freebsd/lib/msun/src/s_carg.c",
+        "upstream-freebsd/lib/msun/src/s_cargf.c",
+        "upstream-freebsd/lib/msun/src/s_cargl.c",
+        "upstream-freebsd/lib/msun/src/s_cbrt.c",
+        "upstream-freebsd/lib/msun/src/s_cbrtf.c",
+        "upstream-freebsd/lib/msun/src/s_ccosh.c",
+        "upstream-freebsd/lib/msun/src/s_ccoshf.c",
+        "upstream-freebsd/lib/msun/src/s_ceil.c",
+        "upstream-freebsd/lib/msun/src/s_ceilf.c",
+        "upstream-freebsd/lib/msun/src/s_cexp.c",
+        "upstream-freebsd/lib/msun/src/s_cexpf.c",
+        "upstream-freebsd/lib/msun/src/s_cimag.c",
+        "upstream-freebsd/lib/msun/src/s_cimagf.c",
+        "upstream-freebsd/lib/msun/src/s_cimagl.c",
+        "upstream-freebsd/lib/msun/src/s_conj.c",
+        "upstream-freebsd/lib/msun/src/s_conjf.c",
+        "upstream-freebsd/lib/msun/src/s_conjl.c",
+        "upstream-freebsd/lib/msun/src/s_copysign.c",
+        "upstream-freebsd/lib/msun/src/s_copysignf.c",
+        "upstream-freebsd/lib/msun/src/s_cos.c",
+        "upstream-freebsd/lib/msun/src/s_cosf.c",
+        "upstream-freebsd/lib/msun/src/s_cproj.c",
+        "upstream-freebsd/lib/msun/src/s_cprojf.c",
+        "upstream-freebsd/lib/msun/src/s_cprojl.c",
+        "upstream-freebsd/lib/msun/src/s_creal.c",
+        "upstream-freebsd/lib/msun/src/s_crealf.c",
+        "upstream-freebsd/lib/msun/src/s_creall.c",
+        "upstream-freebsd/lib/msun/src/s_csinh.c",
+        "upstream-freebsd/lib/msun/src/s_csinhf.c",
+        "upstream-freebsd/lib/msun/src/s_csqrt.c",
+        "upstream-freebsd/lib/msun/src/s_csqrtf.c",
+        "upstream-freebsd/lib/msun/src/s_csqrtl.c",
+        "upstream-freebsd/lib/msun/src/s_ctanh.c",
+        "upstream-freebsd/lib/msun/src/s_ctanhf.c",
+        "upstream-freebsd/lib/msun/src/s_erf.c",
+        "upstream-freebsd/lib/msun/src/s_erff.c",
+        "upstream-freebsd/lib/msun/src/s_exp2.c",
+        "upstream-freebsd/lib/msun/src/s_exp2f.c",
+        "upstream-freebsd/lib/msun/src/s_expm1.c",
+        "upstream-freebsd/lib/msun/src/s_expm1f.c",
+        "upstream-freebsd/lib/msun/src/s_fdim.c",
+        "upstream-freebsd/lib/msun/src/s_finite.c",
+        "upstream-freebsd/lib/msun/src/s_finitef.c",
+        "upstream-freebsd/lib/msun/src/s_floor.c",
+        "upstream-freebsd/lib/msun/src/s_floorf.c",
+        "upstream-freebsd/lib/msun/src/s_fma.c",
+        "upstream-freebsd/lib/msun/src/s_fmaf.c",
+        "upstream-freebsd/lib/msun/src/s_fmax.c",
+        "upstream-freebsd/lib/msun/src/s_fmaxf.c",
+        "upstream-freebsd/lib/msun/src/s_fmin.c",
+        "upstream-freebsd/lib/msun/src/s_fminf.c",
+        "upstream-freebsd/lib/msun/src/s_frexp.c",
+        "upstream-freebsd/lib/msun/src/s_frexpf.c",
+        "upstream-freebsd/lib/msun/src/s_ilogb.c",
+        "upstream-freebsd/lib/msun/src/s_ilogbf.c",
+        "upstream-freebsd/lib/msun/src/s_llrint.c",
+        "upstream-freebsd/lib/msun/src/s_llrintf.c",
+        "upstream-freebsd/lib/msun/src/s_llround.c",
+        "upstream-freebsd/lib/msun/src/s_llroundf.c",
+        "upstream-freebsd/lib/msun/src/s_log1p.c",
+        "upstream-freebsd/lib/msun/src/s_log1pf.c",
+        "upstream-freebsd/lib/msun/src/s_logb.c",
+        "upstream-freebsd/lib/msun/src/s_logbf.c",
+        "upstream-freebsd/lib/msun/src/s_lrint.c",
+        "upstream-freebsd/lib/msun/src/s_lrintf.c",
+        "upstream-freebsd/lib/msun/src/s_lround.c",
+        "upstream-freebsd/lib/msun/src/s_lroundf.c",
+        "upstream-freebsd/lib/msun/src/s_modf.c",
+        "upstream-freebsd/lib/msun/src/s_modff.c",
+        "upstream-freebsd/lib/msun/src/s_nan.c",
+        "upstream-freebsd/lib/msun/src/s_nearbyint.c",
+        "upstream-freebsd/lib/msun/src/s_nextafter.c",
+        "upstream-freebsd/lib/msun/src/s_nextafterf.c",
+        "upstream-freebsd/lib/msun/src/s_remquo.c",
+        "upstream-freebsd/lib/msun/src/s_remquof.c",
+        "upstream-freebsd/lib/msun/src/s_rint.c",
+        "upstream-freebsd/lib/msun/src/s_rintf.c",
+        "upstream-freebsd/lib/msun/src/s_round.c",
+        "upstream-freebsd/lib/msun/src/s_roundf.c",
+        "upstream-freebsd/lib/msun/src/s_scalbln.c",
+        "upstream-freebsd/lib/msun/src/s_scalbn.c",
+        "upstream-freebsd/lib/msun/src/s_scalbnf.c",
+        "upstream-freebsd/lib/msun/src/s_signgam.c",
+        "upstream-freebsd/lib/msun/src/s_significand.c",
+        "upstream-freebsd/lib/msun/src/s_significandf.c",
+        "upstream-freebsd/lib/msun/src/s_sin.c",
+        "upstream-freebsd/lib/msun/src/s_sinf.c",
+        "upstream-freebsd/lib/msun/src/s_tan.c",
+        "upstream-freebsd/lib/msun/src/s_tanf.c",
+        "upstream-freebsd/lib/msun/src/s_tanh.c",
+        "upstream-freebsd/lib/msun/src/s_tanhf.c",
+        "upstream-freebsd/lib/msun/src/s_tgammaf.c",
+        "upstream-freebsd/lib/msun/src/s_trunc.c",
+        "upstream-freebsd/lib/msun/src/s_truncf.c",
+        "upstream-freebsd/lib/msun/src/w_cabs.c",
+        "upstream-freebsd/lib/msun/src/w_cabsf.c",
+        "upstream-freebsd/lib/msun/src/w_cabsl.c",
+        "upstream-freebsd/lib/msun/src/w_drem.c",
+        "upstream-freebsd/lib/msun/src/w_dremf.c",
 
-    native_coverage: bionic_coverage,
-    sanitize: {
-        never: true,
-    },
+        // The FreeBSD complex functions appear to be better, but they're incomplete.
+        // We take the FreeBSD implementations when they exist, but fill out the rest
+        // of <complex.h> from NetBSD...
+        "upstream-netbsd/lib/libm/complex/cacoshl.c",
+        "upstream-netbsd/lib/libm/complex/cacosl.c",
+        "upstream-netbsd/lib/libm/complex/casinhl.c",
+        "upstream-netbsd/lib/libm/complex/casinl.c",
+        "upstream-netbsd/lib/libm/complex/catanhl.c",
+        "upstream-netbsd/lib/libm/complex/catanl.c",
+        "upstream-netbsd/lib/libm/complex/ccoshl.c",
+        "upstream-netbsd/lib/libm/complex/ccosl.c",
+        "upstream-netbsd/lib/libm/complex/cephes_subrl.c",
+        "upstream-netbsd/lib/libm/complex/cexpl.c",
+        "upstream-netbsd/lib/libm/complex/clog.c",
+        "upstream-netbsd/lib/libm/complex/clogf.c",
+        "upstream-netbsd/lib/libm/complex/clogl.c",
+        "upstream-netbsd/lib/libm/complex/cpow.c",
+        "upstream-netbsd/lib/libm/complex/cpowf.c",
+        "upstream-netbsd/lib/libm/complex/cpowl.c",
+        "upstream-netbsd/lib/libm/complex/csinhl.c",
+        "upstream-netbsd/lib/libm/complex/csinl.c",
+        "upstream-netbsd/lib/libm/complex/ctanhl.c",
+        "upstream-netbsd/lib/libm/complex/ctanl.c",
+
+        // TODO: this comes from from upstream's libc, not libm, but it's an
+        // implementation detail that should have hidden visibility, so it needs
+        // to be in whatever library the math code is in.
+        "digittoint.c",
+
+        // Functionality not in the BSDs.
+        "significandl.c",
+        "sincos.c",
+
+        // Modified versions of BSD code.
+        "signbit.c",
+
+        // Home-grown stuff.
+        "fabs.cpp",
+    ],
 
     multilib: {
         lib32: {
             srcs: ["fake_long_double.c"],
         },
+
         lib64: {
-            srcs: libm_ld128_src_files,
-            local_include_dirs: libm_ld_local_includes,
+            srcs: [
+                "upstream-freebsd/lib/msun/src/e_acosl.c",
+                "upstream-freebsd/lib/msun/src/e_acoshl.c",
+                "upstream-freebsd/lib/msun/src/e_asinl.c",
+                "upstream-freebsd/lib/msun/src/e_atan2l.c",
+                "upstream-freebsd/lib/msun/src/e_atanhl.c",
+                "upstream-freebsd/lib/msun/src/e_fmodl.c",
+                "upstream-freebsd/lib/msun/src/e_hypotl.c",
+                "upstream-freebsd/lib/msun/src/e_lgammal.c",
+                "upstream-freebsd/lib/msun/src/e_remainderl.c",
+                "upstream-freebsd/lib/msun/src/e_sqrtl.c",
+                "upstream-freebsd/lib/msun/src/s_asinhl.c",
+                "upstream-freebsd/lib/msun/src/s_atanl.c",
+                "upstream-freebsd/lib/msun/src/s_cbrtl.c",
+                "upstream-freebsd/lib/msun/src/s_ceill.c",
+                "upstream-freebsd/lib/msun/src/s_copysignl.c",
+                "upstream-freebsd/lib/msun/src/e_coshl.c",
+                "upstream-freebsd/lib/msun/src/s_cosl.c",
+                "upstream-freebsd/lib/msun/src/s_floorl.c",
+                "upstream-freebsd/lib/msun/src/s_fmal.c",
+                "upstream-freebsd/lib/msun/src/s_fmaxl.c",
+                "upstream-freebsd/lib/msun/src/s_fminl.c",
+                "upstream-freebsd/lib/msun/src/s_modfl.c",
+                "upstream-freebsd/lib/msun/src/s_frexpl.c",
+                "upstream-freebsd/lib/msun/src/s_ilogbl.c",
+                "upstream-freebsd/lib/msun/src/s_llrintl.c",
+                "upstream-freebsd/lib/msun/src/s_llroundl.c",
+                "upstream-freebsd/lib/msun/src/s_logbl.c",
+                "upstream-freebsd/lib/msun/src/s_lrintl.c",
+                "upstream-freebsd/lib/msun/src/s_lroundl.c",
+                "upstream-freebsd/lib/msun/src/s_nextafterl.c",
+                "upstream-freebsd/lib/msun/src/s_nexttoward.c",
+                "upstream-freebsd/lib/msun/src/s_nexttowardf.c",
+                "upstream-freebsd/lib/msun/src/s_remquol.c",
+                "upstream-freebsd/lib/msun/src/s_rintl.c",
+                "upstream-freebsd/lib/msun/src/s_roundl.c",
+                "upstream-freebsd/lib/msun/src/s_scalbnl.c",
+                "upstream-freebsd/lib/msun/src/e_sinhl.c",
+                "upstream-freebsd/lib/msun/src/s_sinl.c",
+                "upstream-freebsd/lib/msun/src/s_tanhl.c",
+                "upstream-freebsd/lib/msun/src/s_tanl.c",
+                "upstream-freebsd/lib/msun/src/s_truncl.c",
+
+                "upstream-freebsd/lib/msun/ld128/invtrig.c",
+                "upstream-freebsd/lib/msun/ld128/e_lgammal_r.c",
+                "upstream-freebsd/lib/msun/ld128/k_cosl.c",
+                "upstream-freebsd/lib/msun/ld128/k_sinl.c",
+                "upstream-freebsd/lib/msun/ld128/k_tanl.c",
+                "upstream-freebsd/lib/msun/ld128/s_erfl.c",
+                "upstream-freebsd/lib/msun/ld128/s_exp2l.c",
+                "upstream-freebsd/lib/msun/ld128/s_expl.c",
+                "upstream-freebsd/lib/msun/ld128/s_logl.c",
+                "upstream-freebsd/lib/msun/ld128/s_nanl.c",
+            ],
+            local_include_dirs: ["upstream-freebsd/lib/msun/ld128/"],
             // We'd really like to do this for all architectures, but since this wasn't done
             // before, these symbols must continue to be exported on LP32 for binary
             // compatibility.
@@ -343,6 +298,7 @@
                     "arm/sqrt.S",
                     "arm/floor.S",
                 ],
+
                 exclude_srcs: [
                     "upstream-freebsd/lib/msun/src/e_sqrt.c",
                     "upstream-freebsd/lib/msun/src/e_sqrtf.c",
@@ -554,8 +510,41 @@
         },
     },
 
+    local_include_dirs: [
+        "upstream-freebsd/android/include/",
+        "upstream-freebsd/lib/msun/src/",
+    ],
+
+    cflags: [
+        "-D__BIONIC_NO_MATH_INLINES",
+        "-DFLT_EVAL_METHOD=0",
+        "-include freebsd-compat.h",
+        "-Werror",
+        "-Wno-missing-braces",
+        "-Wno-parentheses",
+        "-Wno-sign-compare",
+        "-Wno-uninitialized",
+        "-Wno-unknown-pragmas",
+        "-fvisibility=hidden",
+
+        // Workaround the GCC "(long)fn -> lfn" optimization bug which will result in
+        // self recursions for lrint, lrintf, and lrintl.
+        // BUG: 14225968
+        "-fno-builtin-rint",
+        "-fno-builtin-rintf",
+        "-fno-builtin-rintl",
+    ],
+    conlyflags: ["-std=gnu11"],
+
+    include_dirs: ["bionic/libc"],
+    system_shared_libs: ["libc"],
+
+    native_coverage: bionic_coverage,
+    sanitize: {
+        never: true,
+    },
     stl: "none",
 }
 
-// ANDROIDMK TRANSLATION ERROR: unsupported directive
+// ANDROIDMK TRANSLATION ERROR: endif from unsupported contitional
 // endif
diff --git a/libm/Android.mk b/libm/Android.mk
index 7200e5f..0070bd1 100644
--- a/libm/Android.mk
+++ b/libm/Android.mk
@@ -507,7 +507,10 @@
 
 LOCAL_C_INCLUDES_x86 += $(LOCAL_PATH)/i387
 
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/upstream-freebsd/lib/msun/src/
+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
@@ -575,10 +578,5 @@
 
 LOCAL_CXX_STL := none
 
-# We'd really like to do this for all architectures, but since this wasn't done
-# before, these symbols must continue to be exported on LP32 for binary
-# compatibility.
-LOCAL_LDFLAGS_64 := -Wl,--exclude-libs,libgcc.a
-
 include $(BUILD_SHARED_LIBRARY)
 endif
diff --git a/libm/upstream-freebsd/android/include/machine/endian.h b/libm/upstream-freebsd/android/include/machine/endian.h
new file mode 100644
index 0000000..2dc4d83
--- /dev/null
+++ b/libm/upstream-freebsd/android/include/machine/endian.h
@@ -0,0 +1 @@
+#include <endian.h>
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index 589cab4..52a3252 100755
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -926,7 +926,7 @@
   pthread_rwlock_t lock;
 
  public:
-  RwlockKindTestHelper(int kind_type) {
+  explicit RwlockKindTestHelper(int kind_type) {
     InitRwlock(kind_type);
   }
 
@@ -1539,7 +1539,7 @@
 struct PthreadMutex {
   pthread_mutex_t lock;
 
-  PthreadMutex(int mutex_type) {
+  explicit PthreadMutex(int mutex_type) {
     init(mutex_type);
   }
 
@@ -1640,7 +1640,7 @@
   }
 
  public:
-  MutexWakeupHelper(int mutex_type) : m(mutex_type) {
+  explicit MutexWakeupHelper(int mutex_type) : m(mutex_type) {
   }
 
   void test() {
@@ -1780,7 +1780,14 @@
 
 TEST(pthread, pthread_mutex_lock_null_32) {
 #if defined(__BIONIC__) && !defined(__LP64__)
-  ASSERT_EQ(EINVAL, pthread_mutex_lock(NULL));
+  // For LP32, the pthread lock/unlock functions allow a NULL mutex and return
+  // EINVAL in that case: http://b/19995172.
+  //
+  // We decorate the public defintion with _Nonnull so that people recompiling
+  // their code with get a warning and might fix their bug, but need to pass
+  // NULL here to test that we remain compatible.
+  pthread_mutex_t* null_value = nullptr;
+  ASSERT_EQ(EINVAL, pthread_mutex_lock(null_value));
 #else
   GTEST_LOG_(INFO) << "This test tests bionic implementation details on 32 bit devices.";
 #endif
@@ -1788,7 +1795,14 @@
 
 TEST(pthread, pthread_mutex_unlock_null_32) {
 #if defined(__BIONIC__) && !defined(__LP64__)
-  ASSERT_EQ(EINVAL, pthread_mutex_unlock(NULL));
+  // For LP32, the pthread lock/unlock functions allow a NULL mutex and return
+  // EINVAL in that case: http://b/19995172.
+  //
+  // We decorate the public defintion with _Nonnull so that people recompiling
+  // their code with get a warning and might fix their bug, but need to pass
+  // NULL here to test that we remain compatible.
+  pthread_mutex_t* null_value = nullptr;
+  ASSERT_EQ(EINVAL, pthread_mutex_unlock(null_value));
 #else
   GTEST_LOG_(INFO) << "This test tests bionic implementation details on 32 bit devices.";
 #endif
diff --git a/tests/search_test.cpp b/tests/search_test.cpp
index 3900c89..d368f9f 100644
--- a/tests/search_test.cpp
+++ b/tests/search_test.cpp
@@ -49,7 +49,7 @@
 }
 
 struct node {
-  node(const char* s) : s(strdup(s)) {}
+  explicit node(const char* s) : s(strdup(s)) {}
 
   char* s;
 };
@@ -115,7 +115,7 @@
 }
 
 struct pod_node {
-  pod_node(int i) : i(i) {}
+  explicit pod_node(int i) : i(i) {}
   int i;
 };
 
@@ -136,7 +136,7 @@
 }
 
 struct q_node {
-  q_node(int i) : i(i) {}
+  explicit q_node(int i) : i(i) {}
 
   q_node* next;
   q_node* prev;
diff --git a/tests/string_test.cpp b/tests/string_test.cpp
index 4b2cca2..2a9da10 100644
--- a/tests/string_test.cpp
+++ b/tests/string_test.cpp
@@ -163,7 +163,7 @@
 template<class Character>
 class StringTestState {
  public:
-  StringTestState(size_t MAX_LEN) : MAX_LEN(MAX_LEN), align1_index_(0), align2_index_(0) {
+  explicit StringTestState(size_t MAX_LEN) : MAX_LEN(MAX_LEN), align1_index_(0), align2_index_(0) {
     int max_alignment = 64;
 
     // TODO: fix the tests to not sometimes use twice their specified "MAX_LEN".
diff --git a/tests/sys_ptrace_test.cpp b/tests/sys_ptrace_test.cpp
index bd84d30..9071acf 100644
--- a/tests/sys_ptrace_test.cpp
+++ b/tests/sys_ptrace_test.cpp
@@ -59,7 +59,7 @@
 
 class ChildGuard {
  public:
-  ChildGuard(pid_t pid) : pid(pid) {}
+  explicit ChildGuard(pid_t pid) : pid(pid) {}
 
   ~ChildGuard() {
     kill(pid, SIGKILL);
diff --git a/tests/time_test.cpp b/tests/time_test.cpp
index b1f6364..10399c5 100644
--- a/tests/time_test.cpp
+++ b/tests/time_test.cpp
@@ -273,7 +273,7 @@
   }
 
  public:
-  Counter(void (*fn)(sigval_t)) : value(0), timer_valid(false) {
+  explicit Counter(void (*fn)(sigval_t)) : value(0), timer_valid(false) {
     memset(&se, 0, sizeof(se));
     se.sigev_notify = SIGEV_THREAD;
     se.sigev_notify_function = fn;
diff --git a/tools/relocation_packer/src/debug.h b/tools/relocation_packer/src/debug.h
index 48be6c1..fdfb795 100644
--- a/tools/relocation_packer/src/debug.h
+++ b/tools/relocation_packer/src/debug.h
@@ -81,26 +81,29 @@
 
 // Make logging severities visible globally.
 typedef relocation_packer::Logger::Severity LogSeverity;
-using LogSeverity::INFO;
-using LogSeverity::WARNING;
-using LogSeverity::ERROR;
-using LogSeverity::FATAL;
 
 // LOG(severity) prints a message with the given severity, and aborts if
 // severity is FATAL.  LOG_IF(severity, predicate) does the same but only if
 // predicate is true.  INT_MIN is guaranteed to be less than or equal to
 // any verbosity level.
-#define LOG(severity) \
-    (relocation_packer::Logger(severity, INT_MIN, true).GetStream())
-#define LOG_IF(severity, predicate) \
-    (relocation_packer::Logger(severity, INT_MIN, (predicate)).GetStream())
+#define LOG(severity)                                                      \
+  (relocation_packer::Logger(relocation_packer::Logger::severity, INT_MIN, \
+                             true)                                         \
+       .GetStream())
+#define LOG_IF(severity, predicate)                                        \
+  (relocation_packer::Logger(relocation_packer::Logger::severity, INT_MIN, \
+                             (predicate))                                  \
+       .GetStream())
 
 // VLOG(level) prints its message as INFO if level is less than or equal to
 // the current verbosity level.
-#define VLOG(level) \
-    (relocation_packer::Logger(INFO, (level), true).GetStream())
-#define VLOG_IF(level, predicate) \
-    (relocation_packer::Logger(INFO, (level), (predicate)).GetStream())
+#define VLOG(level)                                                          \
+  (relocation_packer::Logger(relocation_packer::Logger::INFO, (level), true) \
+       .GetStream())
+#define VLOG_IF(level, predicate)                                      \
+  (relocation_packer::Logger(relocation_packer::Logger::INFO, (level), \
+                             (predicate))                              \
+       .GetStream())
 
 // CHECK(predicate) fails with a FATAL log message if predicate is false.
 #define CHECK(predicate) (LOG_IF(FATAL, !(predicate)) \