Merge "Erase elements in LinkedList::remove_if"
diff --git a/libc/bionic/libc_logging.cpp b/libc/bionic/libc_logging.cpp
index 5655526..49a3762 100644
--- a/libc/bionic/libc_logging.cpp
+++ b/libc/bionic/libc_logging.cpp
@@ -75,10 +75,12 @@
       len = strlen(data);
     }
 
+    total += len;
+
     while (len > 0) {
       int avail = end_ - pos_;
       if (avail == 0) {
-        break;
+        return;
       }
       if (avail > len) {
         avail = len;
@@ -87,11 +89,10 @@
       pos_ += avail;
       pos_[0] = '\0';
       len -= avail;
-      total += avail;
     }
   }
 
-  int total;
+  size_t total;
 
  private:
   char* buffer_;
@@ -109,18 +110,19 @@
       len = strlen(data);
     }
 
+    total += len;
+
     while (len > 0) {
       int rc = TEMP_FAILURE_RETRY(write(fd_, data, len));
       if (rc == -1) {
-        break;
+        return;
       }
       data += rc;
       len -= rc;
-      total += rc;
     }
   }
 
-  int total;
+  size_t total;
 
  private:
   int fd_;
diff --git a/libc/bionic/strerror_r.cpp b/libc/bionic/strerror_r.cpp
index 1e57cc0..d419fb1 100644
--- a/libc/bionic/strerror_r.cpp
+++ b/libc/bionic/strerror_r.cpp
@@ -1,11 +1,16 @@
 /* $OpenBSD: strerror_r.c,v 1.6 2005/08/08 08:05:37 espie Exp $ */
 /* Public Domain <marc@snafu.org> */
 
+// G++ automatically defines _GNU_SOURCE, which then means that <string.h>
+// gives us the GNU variant.
+#undef _GNU_SOURCE
+
+#include <string.h>
+
 #include <errno.h>
 #include <limits.h>
 #include <signal.h>
 #include <stdio.h>
-#include <string.h>
 
 #include "private/ErrnoRestorer.h"
 #include "private/libc_logging.h"
@@ -62,6 +67,12 @@
   return 0;
 }
 
+extern "C" char* __gnu_strerror_r(int error_number, char* buf, size_t buf_len) {
+  ErrnoRestorer errno_restorer; // The glibc strerror_r doesn't set errno if it truncates...
+  strerror_r(error_number, buf, buf_len);
+  return buf; // ...and just returns whatever fit.
+}
+
 extern "C" __LIBC_HIDDEN__ const char* __strsignal(int signal_number, char* buf, size_t buf_len) {
   const char* signal_name = __strsignal_lookup(signal_number);
   if (signal_name != NULL) {
diff --git a/libc/include/stdatomic.h b/libc/include/stdatomic.h
index 99ab536..3db25a7 100644
--- a/libc/include/stdatomic.h
+++ b/libc/include/stdatomic.h
@@ -32,8 +32,20 @@
 
 #include <sys/cdefs.h>
 
-#if defined(__cplusplus) && defined(_USING_LIBCXX) && \
-    (__has_feature(cxx_atomic) || _GNUC_VER >= 407)
+
+#if defined(__cplusplus) && defined(_USING_LIBCXX)
+# ifdef __clang__
+#  if __has_feature(cxx_atomic)
+#   define _STDATOMIC_HAVE_ATOMIC
+#  endif
+# else /* gcc */
+#  if __GNUC_PREREQ(4, 7)
+#   define _STDATOMIC_HAVE_ATOMIC
+#  endif
+# endif
+#endif
+
+#ifdef _STDATOMIC_HAVE_ATOMIC
 
 /* We have a usable C++ <atomic>; use it instead.  */
 
@@ -46,6 +58,7 @@
         /* included.  The definitions in <atomic> themselves see      */
         /* the old definition, as they should.                        */
         /* Client code sees the following definition.                 */
+
 #define _Atomic(t) std::atomic<t>
 
 using std::atomic_is_lock_free;
@@ -136,14 +149,24 @@
 # include <uchar.h>  /* For char16_t and char32_t.              */
 #endif
 
-#if __has_extension(c_atomic) || __has_extension(cxx_atomic)
-#define	__CLANG_ATOMICS
-#elif __GNUC_PREREQ__(4, 7)
-#define	__GNUC_ATOMICS
-#elif defined(__GNUC__)
-#define	__SYNC_ATOMICS
+#ifdef __clang__
+# if __has_extension(c_atomic) || __has_extension(cxx_atomic)
+#  define       __CLANG_ATOMICS
+# else
+#  error "stdatomic.h does not support your compiler"
+# endif
+# if __has_builtin(__sync_swap)
+#  define __HAS_BUILTIN_SYNC_SWAP
+# endif
 #else
-#error "stdatomic.h does not support your compiler"
+# if __GNUC_PREREQ(4, 7)
+#  define	__GNUC_ATOMICS
+# else
+#  define	__SYNC_ATOMICS
+#  ifdef __cplusplus
+#   define       __ATOMICS_AVOID_DOT_INIT
+#  endif
+# endif
 #endif
 
 /*
@@ -152,33 +175,53 @@
 
 #ifdef __GCC_ATOMIC_BOOL_LOCK_FREE
 #define	ATOMIC_BOOL_LOCK_FREE		__GCC_ATOMIC_BOOL_LOCK_FREE
+#elif defined(__SYNC_ATOMICS)
+#define	ATOMIC_BOOL_LOCK_FREE           2 /* For all modern platforms */
 #endif
 #ifdef __GCC_ATOMIC_CHAR_LOCK_FREE
 #define	ATOMIC_CHAR_LOCK_FREE		__GCC_ATOMIC_CHAR_LOCK_FREE
+#elif defined(__SYNC_ATOMICS)
+#define	ATOMIC_CHAR_LOCK_FREE           2
 #endif
 #ifdef __GCC_ATOMIC_CHAR16_T_LOCK_FREE
 #define	ATOMIC_CHAR16_T_LOCK_FREE	__GCC_ATOMIC_CHAR16_T_LOCK_FREE
+#elif defined(__SYNC_ATOMICS)
+#define	ATOMIC_CHAR16_T_LOCK_FREE       2
 #endif
 #ifdef __GCC_ATOMIC_CHAR32_T_LOCK_FREE
 #define	ATOMIC_CHAR32_T_LOCK_FREE	__GCC_ATOMIC_CHAR32_T_LOCK_FREE
+#elif defined(__SYNC_ATOMICS)
+#define	ATOMIC_CHAR32_T_LOCK_FREE       2
 #endif
 #ifdef __GCC_ATOMIC_WCHAR_T_LOCK_FREE
 #define	ATOMIC_WCHAR_T_LOCK_FREE	__GCC_ATOMIC_WCHAR_T_LOCK_FREE
+#elif defined(__SYNC_ATOMICS)
+#define	ATOMIC_WCHAR_T_LOCK_FREE        2
 #endif
 #ifdef __GCC_ATOMIC_SHORT_LOCK_FREE
 #define	ATOMIC_SHORT_LOCK_FREE		__GCC_ATOMIC_SHORT_LOCK_FREE
+#elif defined(__SYNC_ATOMICS)
+#define	ATOMIC_SHORT_LOCK_FREE          2
 #endif
 #ifdef __GCC_ATOMIC_INT_LOCK_FREE
 #define	ATOMIC_INT_LOCK_FREE		__GCC_ATOMIC_INT_LOCK_FREE
+#elif defined(__SYNC_ATOMICS)
+#define	ATOMIC_INT_LOCK_FREE            2
 #endif
 #ifdef __GCC_ATOMIC_LONG_LOCK_FREE
 #define	ATOMIC_LONG_LOCK_FREE		__GCC_ATOMIC_LONG_LOCK_FREE
+#elif defined(__SYNC_ATOMICS)
+#define	ATOMIC_LONG_LOCK_FREE           2
 #endif
 #ifdef __GCC_ATOMIC_LLONG_LOCK_FREE
 #define	ATOMIC_LLONG_LOCK_FREE		__GCC_ATOMIC_LLONG_LOCK_FREE
+#elif defined(__SYNC_ATOMICS)
+#define	ATOMIC_LLONG_LOCK_FREE          1 /* maybe */
 #endif
 #ifdef __GCC_ATOMIC_POINTER_LOCK_FREE
 #define	ATOMIC_POINTER_LOCK_FREE	__GCC_ATOMIC_POINTER_LOCK_FREE
+#elif defined(__SYNC_ATOMICS)
+#define	ATOMIC_POINTER_LOCK_FREE        2
 #endif
 
 /*
@@ -189,7 +232,11 @@
 #define	ATOMIC_VAR_INIT(value)		(value)
 #define	atomic_init(obj, value)		__c11_atomic_init(obj, value)
 #else
+#ifdef __ATOMICS_AVOID_DOT_INIT
+#define	ATOMIC_VAR_INIT(value)		{ value }
+#else
 #define	ATOMIC_VAR_INIT(value)		{ .__val = (value) }
+#endif
 #define	atomic_init(obj, value)		((void)((obj)->__val = (value)))
 #endif
 
@@ -289,7 +336,7 @@
  * 7.17.6 Atomic integer types.
  */
 
-#if !__has_extension(c_atomic) && !__has_extension(cxx_atomic)
+#ifndef __CLANG_ATOMICS
 /*
  * No native support for _Atomic(). Place object in structure to prevent
  * most forms of direct non-atomic access.
@@ -410,7 +457,7 @@
     desired, success, failure)						\
 	atomic_compare_exchange_strong_explicit(object, expected,	\
 		desired, success, failure)
-#if __has_builtin(__sync_swap)
+#ifdef __HAS_BUILTIN_SYNC_SWAP
 /* Clang provides a full-barrier atomic exchange - use it if available. */
 #define	atomic_exchange_explicit(object, desired, order)		\
 	((void)(order), __sync_swap(&(object)->__val, desired))
diff --git a/libc/include/string.h b/libc/include/string.h
index 0a1d653..b0643af 100644
--- a/libc/include/string.h
+++ b/libc/include/string.h
@@ -67,8 +67,12 @@
 extern char*  strtok(char* __restrict, const char* __restrict);
 extern char*  strtok_r(char* __restrict, const char* __restrict, char** __restrict);
 
-extern char*  strerror(int);
-extern int    strerror_r(int errnum, char *buf, size_t n);
+extern char* strerror(int);
+#if defined(__USE_GNU)
+extern char* strerror_r(int, char*, size_t) __RENAME(__gnu_strerror_r);
+#else /* POSIX */
+extern int strerror_r(int, char*, size_t);
+#endif
 
 extern size_t strnlen(const char *, size_t) __purefunc;
 extern char*  strncat(char* __restrict, const char* __restrict, size_t);
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index 79d8bca..b223afd 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -60,18 +60,18 @@
  * or later, for e.g. features that appeared in a particular version
  * of GNU C.  Usage:
  *
- *	#if __GNUC_PREREQ__(major, minor)
+ *	#if __GNUC_PREREQ(major, minor)
  *	...cool feature...
  *	#else
  *	...delete feature...
  *	#endif
  */
 #ifdef __GNUC__
-#define	__GNUC_PREREQ__(x, y)						\
+#define	__GNUC_PREREQ(x, y)						\
 	((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) ||			\
 	 (__GNUC__ > (x)))
 #else
-#define	__GNUC_PREREQ__(x, y)	0
+#define	__GNUC_PREREQ(x, y)	0
 #endif
 
 #include <sys/cdefs_elf.h>
@@ -163,7 +163,7 @@
  * GCC2 provides __extension__ to suppress warnings for various GNU C
  * language extensions under "-ansi -pedantic".
  */
-#if !__GNUC_PREREQ__(2, 0)
+#if !__GNUC_PREREQ(2, 0)
 #define	__extension__		/* delete __extension__ if non-gcc or gcc1 */
 #endif
 
@@ -175,7 +175,7 @@
  * these work for GNU C++ (modulo a slight glitch in the C++ grammar
  * in the distribution version of 2.5.5).
  */
-#if !__GNUC_PREREQ__(2, 5)
+#if !__GNUC_PREREQ(2, 5)
 #define	__attribute__(x)	/* delete __attribute__ if non-gcc or gcc1 */
 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
 #define	__dead		__volatile
@@ -189,7 +189,7 @@
 #define	__pure
 #endif
 
-#if __GNUC_PREREQ__(2, 7)
+#if __GNUC_PREREQ(2, 7)
 #define	__unused	__attribute__((__unused__))
 #else
 #define	__unused	/* delete */
@@ -197,13 +197,13 @@
 
 #define __pure2 __attribute__((__const__)) /* Android-added: used by FreeBSD libm */
 
-#if __GNUC_PREREQ__(3, 1)
+#if __GNUC_PREREQ(3, 1)
 #define	__used		__attribute__((__used__))
 #else
 #define	__used		/* delete */
 #endif
 
-#if __GNUC_PREREQ__(2, 7)
+#if __GNUC_PREREQ(2, 7)
 #define	__packed	__attribute__((__packed__))
 #define	__aligned(x)	__attribute__((__aligned__(x)))
 #define	__section(x)	__attribute__((__section__(x)))
@@ -217,11 +217,11 @@
 #define	__section(x)	error: no __section for this compiler
 #endif
 
-#if !__GNUC_PREREQ__(2, 8)
+#if !__GNUC_PREREQ(2, 8)
 #define	__extension__
 #endif
 
-#if __GNUC_PREREQ__(2, 8)
+#if __GNUC_PREREQ(2, 8)
 #define __statement(x)	__extension__(x)
 #elif defined(lint)
 #define __statement(x)	(0)
@@ -241,7 +241,7 @@
 #if defined(__STDC__VERSION__) && __STDC_VERSION__ >= 199901L
 #define	__restrict	restrict
 #else
-#if !__GNUC_PREREQ__(2, 92)
+#if !__GNUC_PREREQ(2, 92)
 #define	__restrict	/* delete __restrict when not supported */
 #endif
 #endif
@@ -251,9 +251,9 @@
  * in GCC 2.95.
  */
 #if !defined(__STDC_VERSION__) || !(__STDC_VERSION__ >= 199901L)
-#if __GNUC_PREREQ__(2, 6)
+#if __GNUC_PREREQ(2, 6)
 #define	__func__	__PRETTY_FUNCTION__
-#elif __GNUC_PREREQ__(2, 4)
+#elif __GNUC_PREREQ(2, 4)
 #define	__func__	__FUNCTION__
 #else
 #define	__func__	""
@@ -272,7 +272,7 @@
  * register values. This is gcc specific, the version is more or less
  * arbitrary, might work with older compilers.
  */
-#if __GNUC_PREREQ__(2, 95)
+#if __GNUC_PREREQ(2, 95)
 #define	__insn_barrier()	__asm __volatile("":::"memory")
 #else
 #define	__insn_barrier()	/* */
@@ -306,7 +306,7 @@
  *	  basic block reordering that this affects can often generate
  *	  larger code.
  */
-#if __GNUC_PREREQ__(2, 96)
+#if __GNUC_PREREQ(2, 96)
 #define	__predict_true(exp)	__builtin_expect((exp) != 0, 1)
 #define	__predict_false(exp)	__builtin_expect((exp) != 0, 0)
 #else
@@ -314,7 +314,7 @@
 #define	__predict_false(exp)	(exp)
 #endif
 
-#if __GNUC_PREREQ__(2, 96)
+#if __GNUC_PREREQ(2, 96)
 #define __noreturn    __attribute__((__noreturn__))
 #define __mallocfunc  __attribute__((malloc))
 #define __purefunc    __attribute__((pure))
@@ -324,19 +324,19 @@
 #define __purefunc
 #endif
 
-#if __GNUC_PREREQ__(3, 1)
+#if __GNUC_PREREQ(3, 1)
 #define __always_inline __attribute__((__always_inline__))
 #else
 #define __always_inline
 #endif
 
-#if __GNUC_PREREQ__(3, 4)
+#if __GNUC_PREREQ(3, 4)
 #define __wur __attribute__((__warn_unused_result__))
 #else
 #define __wur
 #endif
 
-#if __GNUC_PREREQ__(4, 3)
+#if __GNUC_PREREQ(4, 3)
 #define __errordecl(name, msg) extern void name(void) __attribute__((__error__(msg)))
 #define __warnattr(msg) __attribute__((__warning__(msg)))
 #else
diff --git a/libc/include/sys/cdefs_elf.h b/libc/include/sys/cdefs_elf.h
index 6bb0a57..a40a867 100644
--- a/libc/include/sys/cdefs_elf.h
+++ b/libc/include/sys/cdefs_elf.h
@@ -34,10 +34,6 @@
     __asm__(".global " #alias "\n" \
             #alias " = " #sym);
 
-#define __weak_alias(alias,sym) \
-    __asm__(".weak " #alias "\n" \
-            #alias " = " #sym);
-
 /* We use __warnattr instead of __warn_references.
  * TODO: remove this and put an empty definition in one of the upstream-* compatibility headers.
  */
diff --git a/libc/upstream-netbsd/android/include/namespace.h b/libc/upstream-netbsd/android/include/namespace.h
index 5df543c..630ea9b 100644
--- a/libc/upstream-netbsd/android/include/namespace.h
+++ b/libc/upstream-netbsd/android/include/namespace.h
@@ -17,11 +17,6 @@
 #ifndef _BIONIC_NETBSD_NAMESPACE_H_included
 #define _BIONIC_NETBSD_NAMESPACE_H_included
 
-// NetBSD uses __weak_alias on a lot of functions. We don't want that.
-#if defined(__weak_alias)
-#undef __weak_alias
-#endif
-
 __LIBC_HIDDEN__ int __res_enable_mt(void);
 __LIBC_HIDDEN__ int __res_disable_mt(void);
 
diff --git a/libc/upstream-openbsd/android/include/openbsd-compat.h b/libc/upstream-openbsd/android/include/openbsd-compat.h
index b9768e1..630094d 100644
--- a/libc/upstream-openbsd/android/include/openbsd-compat.h
+++ b/libc/upstream-openbsd/android/include/openbsd-compat.h
@@ -32,6 +32,9 @@
 #define _warn warn
 #define _warnx warnx
 
+/* Ignore all __weak_alias in OpenBSD. */
+#define __weak_alias(alias,sym)
+
 /* OpenBSD's <ctype.h> uses these names, which conflicted with stlport.
  * Additionally, we changed the numeric/digit type from N to D for libcxx.
  */
diff --git a/libm/include/math.h b/libm/include/math.h
index c51f3af..1fcc578 100644
--- a/libm/include/math.h
+++ b/libm/include/math.h
@@ -36,11 +36,11 @@
 	float		__uf;
 } __nan;
 
-#if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
+#if __GNUC_PREREQ(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
 #define	__MATH_BUILTIN_CONSTANTS
 #endif
 
-#if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER)
+#if __GNUC_PREREQ(3, 0) && !defined(__INTEL_COMPILER)
 #define	__MATH_BUILTIN_RELOPS
 #endif
 
diff --git a/linker/debugger.cpp b/linker/debugger.cpp
index c316151..6565985 100644
--- a/linker/debugger.cpp
+++ b/linker/debugger.cpp
@@ -162,12 +162,12 @@
     thread_name[MAX_TASK_NAME_LEN] = 0;
   }
 
-  // "info" will be NULL if the siginfo_t information was not available.
+  // "info" will be null if the siginfo_t information was not available.
   // Many signals don't have an address or a code.
   char code_desc[32]; // ", code -6"
   char addr_desc[32]; // ", fault addr 0x1234"
   addr_desc[0] = code_desc[0] = 0;
-  if (info != NULL) {
+  if (info != nullptr) {
     // For a rethrown signal, this si_code will be right and the one debuggerd shows will
     // always be SI_TKILL.
     __libc_format_buffer(code_desc, sizeof(code_desc), ", code %d", info->si_code);
@@ -198,7 +198,7 @@
   }
   bool result = (old_action.sa_flags & SA_SIGINFO) != 0;
 
-  if (sigaction(signum, &old_action, NULL) == -1) {
+  if (sigaction(signum, &old_action, nullptr) == -1) {
     __libc_format_log(ANDROID_LOG_WARN, "libc", "Restore failed in test for SA_SIGINFO: %s",
                       strerror(errno));
   }
@@ -230,7 +230,7 @@
   msg.action = DEBUGGER_ACTION_CRASH;
   msg.tid = gettid();
   msg.abort_msg_address = reinterpret_cast<uintptr_t>(g_abort_message);
-  msg.original_si_code = (info != NULL) ? info->si_code : 0;
+  msg.original_si_code = (info != nullptr) ? info->si_code : 0;
   int ret = TEMP_FAILURE_RETRY(write(s, &msg, sizeof(msg)));
   if (ret == sizeof(msg)) {
     char debuggerd_ack;
@@ -255,7 +255,7 @@
   // It's possible somebody cleared the SA_SIGINFO flag, which would mean
   // our "info" arg holds an undefined value.
   if (!have_siginfo(signal_number)) {
-    info = NULL;
+    info = nullptr;
   }
 
   log_signal_summary(signal_number, info);
@@ -296,14 +296,14 @@
   // Use the alternate signal stack if available so we can catch stack overflows.
   action.sa_flags |= SA_ONSTACK;
 
-  sigaction(SIGABRT, &action, NULL);
-  sigaction(SIGBUS, &action, NULL);
-  sigaction(SIGFPE, &action, NULL);
-  sigaction(SIGILL, &action, NULL);
-  sigaction(SIGPIPE, &action, NULL);
-  sigaction(SIGSEGV, &action, NULL);
+  sigaction(SIGABRT, &action, nullptr);
+  sigaction(SIGBUS, &action, nullptr);
+  sigaction(SIGFPE, &action, nullptr);
+  sigaction(SIGILL, &action, nullptr);
+  sigaction(SIGPIPE, &action, nullptr);
+  sigaction(SIGSEGV, &action, nullptr);
 #if defined(SIGSTKFLT)
-  sigaction(SIGSTKFLT, &action, NULL);
+  sigaction(SIGSTKFLT, &action, nullptr);
 #endif
-  sigaction(SIGTRAP, &action, NULL);
+  sigaction(SIGTRAP, &action, nullptr);
 }
diff --git a/linker/dlfcn.cpp b/linker/dlfcn.cpp
index e15f54d..38484d9 100644
--- a/linker/dlfcn.cpp
+++ b/linker/dlfcn.cpp
@@ -42,7 +42,7 @@
 static void __bionic_format_dlerror(const char* msg, const char* detail) {
   char* buffer = __get_thread()->dlerror_buffer;
   strlcpy(buffer, msg, __BIONIC_DLERROR_BUFFER_SIZE);
-  if (detail != NULL) {
+  if (detail != nullptr) {
     strlcat(buffer, ": ", __BIONIC_DLERROR_BUFFER_SIZE);
     strlcat(buffer, detail, __BIONIC_DLERROR_BUFFER_SIZE);
   }
@@ -51,7 +51,7 @@
 }
 
 const char* dlerror() {
-  const char* old_value = __bionic_set_dlerror(NULL);
+  const char* old_value = __bionic_set_dlerror(nullptr);
   return old_value;
 }
 
@@ -68,9 +68,9 @@
 static void* dlopen_ext(const char* filename, int flags, const android_dlextinfo* extinfo) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
   soinfo* result = do_dlopen(filename, flags, extinfo);
-  if (result == NULL) {
+  if (result == nullptr) {
     __bionic_format_dlerror("dlopen failed", linker_get_error_buffer());
-    return NULL;
+    return nullptr;
   }
   return result;
 }
@@ -80,33 +80,33 @@
 }
 
 void* dlopen(const char* filename, int flags) {
-  return dlopen_ext(filename, flags, NULL);
+  return dlopen_ext(filename, flags, nullptr);
 }
 
 void* dlsym(void* handle, const char* symbol) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
 
 #if !defined(__LP64__)
-  if (handle == NULL) {
-    __bionic_format_dlerror("dlsym library handle is null", NULL);
-    return NULL;
+  if (handle == nullptr) {
+    __bionic_format_dlerror("dlsym library handle is null", nullptr);
+    return nullptr;
   }
 #endif
 
-  if (symbol == NULL) {
-    __bionic_format_dlerror("dlsym symbol name is null", NULL);
-    return NULL;
+  if (symbol == nullptr) {
+    __bionic_format_dlerror("dlsym symbol name is null", nullptr);
+    return nullptr;
   }
 
-  soinfo* found = NULL;
-  ElfW(Sym)* sym = NULL;
+  soinfo* found = nullptr;
+  ElfW(Sym)* sym = nullptr;
   if (handle == RTLD_DEFAULT) {
-    sym = dlsym_linear_lookup(symbol, &found, NULL);
+    sym = dlsym_linear_lookup(symbol, &found, nullptr);
   } else if (handle == RTLD_NEXT) {
     void* caller_addr = __builtin_return_address(0);
     soinfo* si = find_containing_library(caller_addr);
 
-    sym = NULL;
+    sym = nullptr;
     if (si && si->next) {
       sym = dlsym_linear_lookup(symbol, &found, si->next);
     }
@@ -114,7 +114,7 @@
     sym = dlsym_handle_lookup(reinterpret_cast<soinfo*>(handle), &found, symbol);
   }
 
-  if (sym != NULL) {
+  if (sym != nullptr) {
     unsigned bind = ELF_ST_BIND(sym->st_info);
 
     if ((bind == STB_GLOBAL || bind == STB_WEAK) && sym->st_shndx != 0) {
@@ -122,10 +122,10 @@
     }
 
     __bionic_format_dlerror("symbol found but not global", symbol);
-    return NULL;
+    return nullptr;
   } else {
     __bionic_format_dlerror("undefined symbol", symbol);
-    return NULL;
+    return nullptr;
   }
 }
 
@@ -134,7 +134,7 @@
 
   // Determine if this address can be found in any library currently mapped.
   soinfo* si = find_containing_library(addr);
-  if (si == NULL) {
+  if (si == nullptr) {
     return 0;
   }
 
@@ -146,7 +146,7 @@
 
   // Determine if any symbol in the library contains the specified address.
   ElfW(Sym)* sym = dladdr_find_symbol(si, addr);
-  if (sym != NULL) {
+  if (sym != nullptr) {
     info->dli_sname = si->strtab + sym->st_name;
     info->dli_saddr = reinterpret_cast<void*>(si->load_bias + sym->st_value);
   }
@@ -164,7 +164,7 @@
 // name_offset: starting index of the name in libdl_info.strtab
 #define ELF32_SYM_INITIALIZER(name_offset, value, shndx) \
     { name_offset, \
-      reinterpret_cast<Elf32_Addr>(reinterpret_cast<void*>(value)), \
+      reinterpret_cast<Elf32_Addr>(value), \
       /* st_size */ 0, \
       (shndx == 0) ? 0 : (STB_GLOBAL << 4), \
       /* st_other */ 0, \
@@ -176,7 +176,7 @@
       (shndx == 0) ? 0 : (STB_GLOBAL << 4), \
       /* st_other */ 0, \
       shndx, \
-      reinterpret_cast<Elf64_Addr>(reinterpret_cast<void*>(value)), \
+      reinterpret_cast<Elf64_Addr>(value), \
       /* st_size */ 0, \
     }
 
@@ -199,7 +199,7 @@
   // This is actually the STH_UNDEF entry. Technically, it's
   // supposed to have st_name == 0, but instead, it points to an index
   // in the strtab with a \0 to make iterating through the symtab easier.
-  ELFW(SYM_INITIALIZER)(sizeof(ANDROID_LIBDL_STRTAB) - 1, NULL, 0),
+  ELFW(SYM_INITIALIZER)(sizeof(ANDROID_LIBDL_STRTAB) - 1, nullptr, 0),
   ELFW(SYM_INITIALIZER)(  0, &dlopen, 1),
   ELFW(SYM_INITIALIZER)(  7, &dlclose, 1),
   ELFW(SYM_INITIALIZER)( 15, &dlsym, 1),
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 3be2ec6..63c41c0 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -97,7 +97,7 @@
   "/vendor/lib",
   "/system/lib",
 #endif
-  NULL
+  nullptr
 };
 
 #define LDPATH_BUFSIZE (LDPATH_MAX*64)
@@ -116,7 +116,7 @@
 
 __LIBC_HIDDEN__ int g_ld_debug_verbosity;
 
-__LIBC_HIDDEN__ abort_msg_t* g_abort_message = NULL; // For debuggerd.
+__LIBC_HIDDEN__ abort_msg_t* g_abort_message = nullptr; // For debuggerd.
 
 enum RelocationKind {
     kRelocAbsolute = 0,
@@ -189,7 +189,7 @@
 extern "C" void __attribute__((noinline)) __attribute__((visibility("default"))) rtld_db_dlactivity();
 
 static pthread_mutex_t g__r_debug_mutex = PTHREAD_MUTEX_INITIALIZER;
-static r_debug _r_debug = {1, NULL, reinterpret_cast<uintptr_t>(&rtld_db_dlactivity), r_debug::RT_CONSISTENT, 0};
+static r_debug _r_debug = {1, nullptr, reinterpret_cast<uintptr_t>(&rtld_db_dlactivity), r_debug::RT_CONSISTENT, 0};
 static link_map* r_debug_tail = 0;
 
 static void insert_soinfo_into_debug_map(soinfo* info) {
@@ -288,7 +288,7 @@
 static soinfo* soinfo_alloc(const char* name, struct stat* file_stat) {
   if (strlen(name) >= SOINFO_NAME_LEN) {
     DL_ERR("library name \"%s\" too long", name);
-    return NULL;
+    return nullptr;
   }
 
   soinfo* si = new (g_soinfo_allocator.alloc()) soinfo(name, file_stat);
@@ -301,7 +301,7 @@
 }
 
 static void soinfo_free(soinfo* si) {
-    if (si == NULL) {
+    if (si == nullptr) {
         return;
     }
 
@@ -309,16 +309,16 @@
       munmap(reinterpret_cast<void*>(si->base), si->size);
     }
 
-    soinfo *prev = NULL, *trav;
+    soinfo *prev = nullptr, *trav;
 
     TRACE("name %s: freeing soinfo @ %p", si->name, si);
 
-    for (trav = solist; trav != NULL; trav = trav->next) {
+    for (trav = solist; trav != nullptr; trav = trav->next) {
         if (trav == si)
             break;
         prev = trav;
     }
-    if (trav == NULL) {
+    if (trav == nullptr) {
         /* si was not in solist */
         DL_ERR("name \"%s\" is not in solist!", si->name);
         return;
@@ -327,7 +327,7 @@
     // clear links to/from si
     si->remove_all_links();
 
-    /* prev will never be NULL, because the first entry in solist is
+    /* prev will never be null, because the first entry in solist is
        always the static libdl_info.
     */
     prev->next = si->next;
@@ -341,7 +341,7 @@
 
 static void parse_path(const char* path, const char* delimiters,
                        const char** array, char* buf, size_t buf_size, size_t max_count) {
-  if (path == NULL) {
+  if (path == nullptr) {
     return;
   }
 
@@ -358,9 +358,9 @@
   // Forget the last path if we had to truncate; this occurs if the 2nd to
   // last char isn't '\0' (i.e. wasn't originally a delimiter).
   if (i > 0 && len >= buf_size && buf[buf_size - 2] != '\0') {
-    array[i - 1] = NULL;
+    array[i - 1] = nullptr;
   } else {
-    array[i] = NULL;
+    array[i] = nullptr;
   }
 }
 
@@ -396,7 +396,7 @@
         }
     }
     *pcount = 0;
-    return NULL;
+    return nullptr;
 }
 
 #endif
@@ -405,7 +405,7 @@
  * loaded libraries. gcc_eh does the rest. */
 int dl_iterate_phdr(int (*cb)(dl_phdr_info* info, size_t size, void* data), void* data) {
     int rv = 0;
-    for (soinfo* si = solist; si != NULL; si = si->next) {
+    for (soinfo* si = solist; si != nullptr; si = si->next) {
         dl_phdr_info dl_info;
         dl_info.dlpi_addr = si->link_map_head.l_addr;
         dl_info.dlpi_name = si->link_map_head.l_name;
@@ -454,7 +454,7 @@
              name, si->name, reinterpret_cast<void*>(si->base), hash, hash % si->nbucket);
 
 
-  return NULL;
+  return nullptr;
 }
 
 soinfo::soinfo(const char* name, const struct stat* file_stat) {
@@ -464,7 +464,7 @@
   flags = FLAG_NEW_SOINFO;
   version = SOINFO_VERSION;
 
-  if (file_stat != NULL) {
+  if (file_stat != nullptr) {
     set_st_dev(file_stat->st_dev);
     set_st_ino(file_stat->st_ino);
   }
@@ -511,9 +511,9 @@
 
 static ElfW(Sym)* soinfo_do_lookup(soinfo* si, const char* name, soinfo** lsi, soinfo* needed[]) {
     unsigned elf_hash = elfhash(name);
-    ElfW(Sym)* s = NULL;
+    ElfW(Sym)* s = nullptr;
 
-    if (si != NULL && somain != NULL) {
+    if (si != nullptr && somain != nullptr) {
         /*
          * Local scope is executable scope. Just start looking into it right away
          * for the shortcut.
@@ -521,7 +521,7 @@
 
         if (si == somain) {
             s = soinfo_elf_lookup(si, elf_hash, name);
-            if (s != NULL) {
+            if (s != nullptr) {
                 *lsi = si;
                 goto done;
             }
@@ -538,7 +538,7 @@
                 DEBUG("%s: looking up %s in executable %s",
                       si->name, name, somain->name);
                 s = soinfo_elf_lookup(somain, elf_hash, name);
-                if (s != NULL) {
+                if (s != nullptr) {
                     *lsi = somain;
                     goto done;
                 }
@@ -555,7 +555,7 @@
              * Here we return the first definition found for simplicity.  */
 
             s = soinfo_elf_lookup(si, elf_hash, name);
-            if (s != NULL) {
+            if (s != nullptr) {
                 *lsi = si;
                 goto done;
             }
@@ -569,7 +569,7 @@
                 DEBUG("%s: looking up %s in executable %s after local scope",
                       si->name, name, somain->name);
                 s = soinfo_elf_lookup(somain, elf_hash, name);
-                if (s != NULL) {
+                if (s != nullptr) {
                     *lsi = somain;
                     goto done;
                 }
@@ -578,26 +578,26 @@
     }
 
     /* Next, look for it in the preloads list */
-    for (int i = 0; g_ld_preloads[i] != NULL; i++) {
+    for (int i = 0; g_ld_preloads[i] != nullptr; i++) {
         s = soinfo_elf_lookup(g_ld_preloads[i], elf_hash, name);
-        if (s != NULL) {
+        if (s != nullptr) {
             *lsi = g_ld_preloads[i];
             goto done;
         }
     }
 
-    for (int i = 0; needed[i] != NULL; i++) {
+    for (int i = 0; needed[i] != nullptr; i++) {
         DEBUG("%s: looking up %s in %s",
               si->name, name, needed[i]->name);
         s = soinfo_elf_lookup(needed[i], elf_hash, name);
-        if (s != NULL) {
+        if (s != nullptr) {
             *lsi = needed[i];
             goto done;
         }
     }
 
 done:
-    if (s != NULL) {
+    if (s != nullptr) {
         TRACE_TYPE(LOOKUP, "si %s sym %s s->st_value = %p, "
                    "found in %s, base = %p, load bias = %p",
                    si->name, name, reinterpret_cast<void*>(s->st_value),
@@ -606,7 +606,7 @@
         return s;
     }
 
-    return NULL;
+    return nullptr;
 }
 
 
@@ -661,20 +661,20 @@
 ElfW(Sym)* dlsym_linear_lookup(const char* name, soinfo** found, soinfo* start) {
   unsigned elf_hash = elfhash(name);
 
-  if (start == NULL) {
+  if (start == nullptr) {
     start = solist;
   }
 
-  ElfW(Sym)* s = NULL;
-  for (soinfo* si = start; (s == NULL) && (si != NULL); si = si->next) {
+  ElfW(Sym)* s = nullptr;
+  for (soinfo* si = start; (s == nullptr) && (si != nullptr); si = si->next) {
     s = soinfo_elf_lookup(si, elf_hash, name);
-    if (s != NULL) {
+    if (s != nullptr) {
       *found = si;
       break;
     }
   }
 
-  if (s != NULL) {
+  if (s != nullptr) {
     TRACE_TYPE(LOOKUP, "%s s->st_value = %p, found->base = %p",
                name, reinterpret_cast<void*>(s->st_value), reinterpret_cast<void*>((*found)->base));
   }
@@ -684,12 +684,12 @@
 
 soinfo* find_containing_library(const void* p) {
   ElfW(Addr) address = reinterpret_cast<ElfW(Addr)>(p);
-  for (soinfo* si = solist; si != NULL; si = si->next) {
+  for (soinfo* si = solist; si != nullptr; si = si->next) {
     if (address >= si->base && address - si->base < si->size) {
       return si;
     }
   }
-  return NULL;
+  return nullptr;
 }
 
 ElfW(Sym)* dladdr_find_symbol(soinfo* si, const void* addr) {
@@ -706,12 +706,12 @@
     }
   }
 
-  return NULL;
+  return nullptr;
 }
 
 static int open_library_on_path(const char* name, const char* const paths[]) {
   char buf[512];
-  for (size_t i = 0; paths[i] != NULL; ++i) {
+  for (size_t i = 0; paths[i] != nullptr; ++i) {
     int n = __libc_format_buffer(buf, sizeof(buf), "%s/%s", paths[i], name);
     if (n < 0 || n >= static_cast<int>(sizeof(buf))) {
       PRINT("Warning: ignoring very long library path: %s/%s", paths[i], name);
@@ -729,7 +729,7 @@
   TRACE("[ opening %s ]", name);
 
   // If the name contains a slash, we should attempt to open it directly and not search the paths.
-  if (strchr(name, '/') != NULL) {
+  if (strchr(name, '/') != nullptr) {
     int fd = TEMP_FAILURE_RETRY(open(name, O_RDONLY | O_CLOEXEC));
     if (fd != -1) {
       return fd;
@@ -752,14 +752,14 @@
     int fd = -1;
     ScopedFd file_guard(-1);
 
-    if (extinfo != NULL && (extinfo->flags & ANDROID_DLEXT_USE_LIBRARY_FD) != 0) {
+    if (extinfo != nullptr && (extinfo->flags & ANDROID_DLEXT_USE_LIBRARY_FD) != 0) {
       fd = extinfo->library_fd;
     } else {
       // Open the file.
       fd = open_library(name);
       if (fd == -1) {
         DL_ERR("library \"%s\" not found", name);
-        return NULL;
+        return nullptr;
       }
 
       file_guard.reset(fd);
@@ -770,12 +770,12 @@
     struct stat file_stat;
     if (TEMP_FAILURE_RETRY(fstat(fd, &file_stat)) != 0) {
       DL_ERR("unable to stat file for the library %s: %s", name, strerror(errno));
-      return NULL;
+      return nullptr;
     }
 
     // Check for symlink and other situations where
     // file can have different names.
-    for (soinfo* si = solist; si != NULL; si = si->next) {
+    for (soinfo* si = solist; si != nullptr; si = si->next) {
       if (si->get_st_dev() != 0 &&
           si->get_st_ino() != 0 &&
           si->get_st_dev() == file_stat.st_dev &&
@@ -786,17 +786,17 @@
     }
 
     if ((dlflags & RTLD_NOLOAD) != 0) {
-      return NULL;
+      return nullptr;
     }
 
     // Read the ELF header and load the segments.
     if (!elf_reader.Load(extinfo)) {
-        return NULL;
+        return nullptr;
     }
 
     soinfo* si = soinfo_alloc(SEARCH_NAME(name), &file_stat);
-    if (si == NULL) {
-        return NULL;
+    if (si == nullptr) {
+        return nullptr;
     }
     si->base = elf_reader.load_start();
     si->size = elf_reader.load_size();
@@ -811,7 +811,7 @@
 
     if (!soinfo_link_image(si, extinfo)) {
       soinfo_free(si);
-      return NULL;
+      return nullptr;
     }
 
     return si;
@@ -819,16 +819,16 @@
 
 static soinfo *find_loaded_library_by_name(const char* name) {
   const char* search_name = SEARCH_NAME(name);
-  for (soinfo* si = solist; si != NULL; si = si->next) {
+  for (soinfo* si = solist; si != nullptr; si = si->next) {
     if (!strcmp(search_name, si->name)) {
       return si;
     }
   }
-  return NULL;
+  return nullptr;
 }
 
 static soinfo* find_library_internal(const char* name, int dlflags, const android_dlextinfo* extinfo) {
-  if (name == NULL) {
+  if (name == nullptr) {
     return somain;
   }
 
@@ -836,14 +836,14 @@
 
   // Library might still be loaded, the accurate detection
   // of this fact is done by load_library
-  if (si == NULL) {
+  if (si == nullptr) {
     TRACE("[ '%s' has not been found by name.  Trying harder...]", name);
     si = load_library(name, dlflags, extinfo);
   }
 
-  if (si != NULL && (si->flags & FLAG_LINKED) == 0) {
+  if (si != nullptr && (si->flags & FLAG_LINKED) == 0) {
     DL_ERR("recursive link to \"%s\"", si->name);
-    return NULL;
+    return nullptr;
   }
 
   return si;
@@ -851,7 +851,7 @@
 
 static soinfo* find_library(const char* name, int dlflags, const android_dlextinfo* extinfo) {
   soinfo* si = find_library_internal(name, dlflags, extinfo);
-  if (si != NULL) {
+  if (si != nullptr) {
     si->ref_count++;
   }
   return si;
@@ -879,8 +879,8 @@
         if (d->d_tag == DT_NEEDED) {
           const char* library_name = si->strtab + d->d_un.d_val;
           TRACE("%s needs to unload %s", si->name, library_name);
-          soinfo* needed = find_library(library_name, RTLD_NOLOAD, NULL);
-          if (needed != NULL) {
+          soinfo* needed = find_library(library_name, RTLD_NOLOAD, nullptr);
+          if (needed != nullptr) {
             soinfo_unload(needed);
           } else {
             // Not found: for example if symlink was deleted between dlopen and dlclose
@@ -927,15 +927,15 @@
 soinfo* do_dlopen(const char* name, int flags, const android_dlextinfo* extinfo) {
   if ((flags & ~(RTLD_NOW|RTLD_LAZY|RTLD_LOCAL|RTLD_GLOBAL|RTLD_NOLOAD)) != 0) {
     DL_ERR("invalid flags to dlopen: %x", flags);
-    return NULL;
+    return nullptr;
   }
-  if (extinfo != NULL && ((extinfo->flags & ~(ANDROID_DLEXT_VALID_FLAG_BITS)) != 0)) {
+  if (extinfo != nullptr && ((extinfo->flags & ~(ANDROID_DLEXT_VALID_FLAG_BITS)) != 0)) {
     DL_ERR("invalid extended flags to android_dlopen_ext: %" PRIx64, extinfo->flags);
-    return NULL;
+    return nullptr;
   }
   protect_data(PROT_READ | PROT_WRITE);
   soinfo* si = find_library(name, flags, extinfo);
-  if (si != NULL) {
+  if (si != nullptr) {
     si->CallConstructors();
   }
   protect_data(PROT_READ);
@@ -958,7 +958,7 @@
     unsigned sym = ELFW(R_SYM)(rel->r_info);
     ElfW(Addr) reloc = static_cast<ElfW(Addr)>(rel->r_offset + si->load_bias);
     ElfW(Addr) sym_addr = 0;
-    const char* sym_name = NULL;
+    const char* sym_name = nullptr;
     sym_name = reinterpret_cast<const char*>(si->strtab + si->symtab[sym].st_name);
     s = soinfo_do_lookup(si, sym_name, &lsi, needed);
 
@@ -981,7 +981,7 @@
     unsigned sym = ELFW(R_SYM)(rela->r_info);
     ElfW(Addr) reloc = static_cast<ElfW(Addr)>(rela->r_offset + si->load_bias);
     ElfW(Addr) sym_addr = 0;
-    const char* sym_name = NULL;
+    const char* sym_name = nullptr;
     sym_name = reinterpret_cast<const char*>(si->strtab + si->symtab[sym].st_name);
     s = soinfo_do_lookup(si, sym_name, &lsi, needed);
 
@@ -1005,7 +1005,7 @@
     unsigned sym = ELFW(R_SYM)(rela->r_info);
     ElfW(Addr) reloc = static_cast<ElfW(Addr)>(rela->r_offset + si->load_bias);
     ElfW(Addr) sym_addr = 0;
-    const char* sym_name = NULL;
+    const char* sym_name = nullptr;
 
     DEBUG("Processing '%s' relocation at index %zd", si->name, idx);
     if (type == 0) { // R_*_NONE
@@ -1014,7 +1014,7 @@
     if (sym != 0) {
       sym_name = reinterpret_cast<const char*>(si->strtab + si->symtab[sym].st_name);
       s = soinfo_do_lookup(si, sym_name, &lsi, needed);
-      if (s == NULL) {
+      if (s == nullptr) {
         // We only allow an undefined symbol if this is a weak reference...
         s = &si->symtab[sym];
         if (ELF_ST_BIND(s->st_info) != STB_WEAK) {
@@ -1070,7 +1070,7 @@
       }
       count_relocation(kRelocSymbol);
     } else {
-      s = NULL;
+      s = nullptr;
     }
 
     switch (type) {
@@ -1274,7 +1274,7 @@
         unsigned sym = ELFW(R_SYM)(rel->r_info);
         ElfW(Addr) reloc = static_cast<ElfW(Addr)>(rel->r_offset + si->load_bias);
         ElfW(Addr) sym_addr = 0;
-        const char* sym_name = NULL;
+        const char* sym_name = nullptr;
 
         DEBUG("Processing '%s' relocation at index %zd", si->name, idx);
         if (type == 0) { // R_*_NONE
@@ -1283,7 +1283,7 @@
         if (sym != 0) {
             sym_name = reinterpret_cast<const char*>(si->strtab + si->symtab[sym].st_name);
             s = soinfo_do_lookup(si, sym_name, &lsi, needed);
-            if (s == NULL) {
+            if (s == nullptr) {
                 // We only allow an undefined symbol if this is a weak reference...
                 s = &si->symtab[sym];
                 if (ELF_ST_BIND(s->st_info) != STB_WEAK) {
@@ -1342,7 +1342,7 @@
             }
             count_relocation(kRelocSymbol);
         } else {
-            s = NULL;
+            s = nullptr;
         }
 
         switch (type) {
@@ -1467,7 +1467,7 @@
 #if defined(__mips__)
 static bool mips_relocate_got(soinfo* si, soinfo* needed[]) {
     ElfW(Addr)** got = si->plt_got;
-    if (got == NULL) {
+    if (got == nullptr) {
         return true;
     }
     unsigned local_gotno = si->mips_local_gotno;
@@ -1499,7 +1499,7 @@
         const char* sym_name = si->strtab + sym->st_name;
         soinfo* lsi;
         ElfW(Sym)* s = soinfo_do_lookup(si, sym_name, &lsi, needed);
-        if (s == NULL) {
+        if (s == nullptr) {
             // We only allow an undefined symbol if this is a weak reference.
             s = &symtab[g];
             if (ELF_ST_BIND(s->st_info) != STB_WEAK) {
@@ -1519,7 +1519,7 @@
 #endif
 
 void soinfo::CallArray(const char* array_name __unused, linker_function_t* functions, size_t count, bool reverse) {
-  if (functions == NULL) {
+  if (functions == nullptr) {
     return;
   }
 
@@ -1538,7 +1538,7 @@
 }
 
 void soinfo::CallFunction(const char* function_name __unused, linker_function_t function) {
-  if (function == NULL || reinterpret_cast<uintptr_t>(function) == static_cast<uintptr_t>(-1)) {
+  if (function == nullptr || reinterpret_cast<uintptr_t>(function) == static_cast<uintptr_t>(-1)) {
     return;
   }
 
@@ -1574,7 +1574,7 @@
   //    out above, the libc constructor will be called again (recursively!).
   constructors_called = true;
 
-  if ((flags & FLAG_EXE) == 0 && preinit_array != NULL) {
+  if ((flags & FLAG_EXE) == 0 && preinit_array != nullptr) {
     // The GNU dynamic linker silently ignores these, but we warn the developer.
     PRINT("\"%s\": ignoring %zd-entry DT_PREINIT_ARRAY in shared library!",
           name, preinit_array_count);
@@ -1770,7 +1770,7 @@
     ElfW(Word) dynamic_flags;
     phdr_table_get_dynamic_section(phdr, phnum, base, &si->dynamic,
                                    &dynamic_count, &dynamic_flags);
-    if (si->dynamic == NULL) {
+    if (si->dynamic == nullptr) {
         if (!relocating_linker) {
             DL_ERR("missing PT_DYNAMIC in \"%s\"", si->name);
         }
@@ -1988,9 +1988,9 @@
     if (si->flags & FLAG_EXE) {
         memset(g_ld_preloads, 0, sizeof(g_ld_preloads));
         size_t preload_count = 0;
-        for (size_t i = 0; g_ld_preload_names[i] != NULL; i++) {
-            soinfo* lsi = find_library(g_ld_preload_names[i], 0, NULL);
-            if (lsi != NULL) {
+        for (size_t i = 0; g_ld_preload_names[i] != nullptr; i++) {
+            soinfo* lsi = find_library(g_ld_preload_names[i], 0, nullptr);
+            if (lsi != nullptr) {
                 g_ld_preloads[preload_count++] = lsi;
             } else {
                 // As with glibc, failure to load an LD_PRELOAD library is just a warning.
@@ -2007,8 +2007,8 @@
         if (d->d_tag == DT_NEEDED) {
             const char* library_name = si->strtab + d->d_un.d_val;
             DEBUG("%s needs %s", si->name, library_name);
-            soinfo* lsi = find_library(library_name, 0, NULL);
-            if (lsi == NULL) {
+            soinfo* lsi = find_library(library_name, 0, nullptr);
+            if (lsi == nullptr) {
                 strlcpy(tmp_err_buf, linker_get_error_buffer(), sizeof(tmp_err_buf));
                 DL_ERR("could not load library \"%s\" needed by \"%s\"; caused by %s",
                        library_name, si->name, tmp_err_buf);
@@ -2019,7 +2019,7 @@
             *pneeded++ = lsi;
         }
     }
-    *pneeded = NULL;
+    *pneeded = nullptr;
 
 #if !defined(__LP64__)
     if (si->has_text_relocations) {
@@ -2036,26 +2036,26 @@
 #endif
 
 #if defined(USE_RELA)
-    if (si->plt_rela != NULL) {
+    if (si->plt_rela != nullptr) {
         DEBUG("[ relocating %s plt ]\n", si->name);
         if (soinfo_relocate(si, si->plt_rela, si->plt_rela_count, needed)) {
             return false;
         }
     }
-    if (si->rela != NULL) {
+    if (si->rela != nullptr) {
         DEBUG("[ relocating %s ]\n", si->name);
         if (soinfo_relocate(si, si->rela, si->rela_count, needed)) {
             return false;
         }
     }
 #else
-    if (si->plt_rel != NULL) {
+    if (si->plt_rel != nullptr) {
         DEBUG("[ relocating %s plt ]", si->name);
         if (soinfo_relocate(si, si->plt_rel, si->plt_rel_count, needed)) {
             return false;
         }
     }
-    if (si->rel != NULL) {
+    if (si->rel != nullptr) {
         DEBUG("[ relocating %s ]", si->name);
         if (soinfo_relocate(si, si->rel, si->rel_count, needed)) {
             return false;
@@ -2131,11 +2131,11 @@
 static void add_vdso(KernelArgumentBlock& args __unused) {
 #if defined(AT_SYSINFO_EHDR)
   ElfW(Ehdr)* ehdr_vdso = reinterpret_cast<ElfW(Ehdr)*>(args.getauxval(AT_SYSINFO_EHDR));
-  if (ehdr_vdso == NULL) {
+  if (ehdr_vdso == nullptr) {
     return;
   }
 
-  soinfo* si = soinfo_alloc("[vdso]", NULL);
+  soinfo* si = soinfo_alloc("[vdso]", nullptr);
 
   si->phdr = reinterpret_cast<ElfW(Phdr)*>(reinterpret_cast<char*>(ehdr_vdso) + ehdr_vdso->e_phoff);
   si->phnum = ehdr_vdso->e_phnum;
@@ -2143,7 +2143,7 @@
   si->size = phdr_table_get_load_size(si->phdr, si->phnum);
   si->load_bias = get_elf_exec_load_bias(ehdr_vdso);
 
-  soinfo_link_image(si, NULL);
+  soinfo_link_image(si, nullptr);
 #endif
 }
 
@@ -2176,7 +2176,7 @@
   ElfW(Ehdr)* elf_hdr = reinterpret_cast<ElfW(Ehdr)*>(linker_base);
   ElfW(Phdr)* phdr = reinterpret_cast<ElfW(Phdr)*>(linker_base + elf_hdr->e_phoff);
   phdr_table_get_dynamic_section(phdr, elf_hdr->e_phnum, linker_base,
-                                 &linker_soinfo_for_gdb.dynamic, NULL, NULL);
+                                 &linker_soinfo_for_gdb.dynamic, nullptr, nullptr);
   insert_soinfo_into_debug_map(&linker_soinfo_for_gdb);
 }
 
@@ -2204,14 +2204,14 @@
 
     // Get a few environment variables.
     const char* LD_DEBUG = linker_env_get("LD_DEBUG");
-    if (LD_DEBUG != NULL) {
+    if (LD_DEBUG != nullptr) {
       g_ld_debug_verbosity = atoi(LD_DEBUG);
     }
 
     // Normally, these are cleaned by linker_env_init, but the test
     // doesn't cost us anything.
-    const char* ldpath_env = NULL;
-    const char* ldpreload_env = NULL;
+    const char* ldpath_env = nullptr;
+    const char* ldpreload_env = nullptr;
     if (!get_AT_SECURE()) {
       ldpath_env = linker_env_get("LD_LIBRARY_PATH");
       ldpreload_env = linker_env_get("LD_PRELOAD");
@@ -2219,8 +2219,8 @@
 
     INFO("[ android linker & debugger ]");
 
-    soinfo* si = soinfo_alloc(args.argv[0], NULL);
-    if (si == NULL) {
+    soinfo* si = soinfo_alloc(args.argv[0], nullptr);
+    if (si == nullptr) {
         exit(EXIT_FAILURE);
     }
 
@@ -2230,8 +2230,8 @@
 
     map->l_addr = 0;
     map->l_name = args.argv[0];
-    map->l_prev = NULL;
-    map->l_next = NULL;
+    map->l_prev = nullptr;
+    map->l_next = nullptr;
 
     _r_debug.r_map = map;
     r_debug_tail = map;
@@ -2257,7 +2257,7 @@
         break;
       }
     }
-    si->dynamic = NULL;
+    si->dynamic = nullptr;
     si->ref_count = 1;
 
     ElfW(Ehdr)* elf_hdr = reinterpret_cast<ElfW(Ehdr)*>(si->base);
@@ -2272,7 +2272,7 @@
 
     somain = si;
 
-    if (!soinfo_link_image(si, NULL)) {
+    if (!soinfo_link_image(si, nullptr)) {
         __libc_format_fd(2, "CANNOT LINK EXECUTABLE: %s\n", linker_get_error_buffer());
         exit(EXIT_FAILURE);
     }
@@ -2281,7 +2281,7 @@
 
     si->CallPreInitConstructors();
 
-    for (size_t i = 0; g_ld_preloads[i] != NULL; ++i) {
+    for (size_t i = 0; g_ld_preloads[i] != nullptr; ++i) {
         g_ld_preloads[i]->CallConstructors();
     }
 
@@ -2294,7 +2294,7 @@
     si->CallConstructors();
 
 #if TIMING
-    gettimeofday(&t1, NULL);
+    gettimeofday(&t1, nullptr);
     PRINT("LINKER TIME: %s: %d microseconds", args.argv[0], (int) (
                (((long long)t1.tv_sec * 1000000LL) + (long long)t1.tv_usec) -
                (((long long)t0.tv_sec * 1000000LL) + (long long)t0.tv_usec)));
@@ -2395,12 +2395,12 @@
   linker_so.base = linker_addr;
   linker_so.size = phdr_table_get_load_size(phdr, elf_hdr->e_phnum);
   linker_so.load_bias = get_elf_exec_load_bias(elf_hdr);
-  linker_so.dynamic = NULL;
+  linker_so.dynamic = nullptr;
   linker_so.phdr = phdr;
   linker_so.phnum = elf_hdr->e_phnum;
   linker_so.flags |= FLAG_LINKER;
 
-  if (!soinfo_link_image(&linker_so, NULL)) {
+  if (!soinfo_link_image(&linker_so, nullptr)) {
     // It would be nice to print an error message, but if the linker
     // can't link itself, there's no guarantee that we'll be able to
     // call write() (because it involves a GOT reference). We may as
diff --git a/linker/linker_environ.cpp b/linker/linker_environ.cpp
index 846624b..daee56f 100644
--- a/linker/linker_environ.cpp
+++ b/linker/linker_environ.cpp
@@ -58,7 +58,7 @@
 
 // Check if the environment variable definition at 'envstr'
 // starts with '<name>=', and if so return the address of the
-// first character after the equal sign. Otherwise return NULL.
+// first character after the equal sign. Otherwise return null.
 static const char* env_match(const char* envstr, const char* name) {
   size_t i = 0;
 
@@ -70,7 +70,7 @@
     return envstr + i + 1;
   }
 
-  return NULL;
+  return nullptr;
 }
 
 static bool __is_valid_environment_variable(const char* name) {
@@ -78,7 +78,7 @@
   // as the maximum size for an env. variable definition.
   const int MAX_ENV_LEN = 32*4096;
 
-  if (name == NULL) {
+  if (name == nullptr) {
     return false;
   }
 
@@ -136,10 +136,10 @@
       "RES_OPTIONS",
       "TMPDIR",
       "TZDIR",
-      NULL
+      nullptr
   };
-  for (size_t i = 0; UNSAFE_VARIABLE_NAMES[i] != NULL; ++i) {
-    if (env_match(name, UNSAFE_VARIABLE_NAMES[i]) != NULL) {
+  for (size_t i = 0; UNSAFE_VARIABLE_NAMES[i] != nullptr; ++i) {
+    if (env_match(name, UNSAFE_VARIABLE_NAMES[i]) != nullptr) {
       return true;
     }
   }
@@ -149,7 +149,7 @@
 static void __sanitize_environment_variables() {
   char** src  = _envp;
   char** dst = _envp;
-  for (; src[0] != NULL; ++src) {
+  for (; src[0] != nullptr; ++src) {
     if (!__is_valid_environment_variable(src[0])) {
       continue;
     }
@@ -160,11 +160,11 @@
     dst[0] = src[0];
     ++dst;
   }
-  dst[0] = NULL;
+  dst[0] = nullptr;
 }
 
 void linker_env_init(KernelArgumentBlock& args) {
-  // Store environment pointer - can't be NULL.
+  // Store environment pointer - can't be null.
   _envp = args.envp;
 
   __init_AT_SECURE(args);
@@ -172,18 +172,18 @@
 }
 
 const char* linker_env_get(const char* name) {
-  if (name == NULL || name[0] == '\0') {
-    return NULL;
+  if (name == nullptr || name[0] == '\0') {
+    return nullptr;
   }
 
-  for (char** p = _envp; p[0] != NULL; ++p) {
+  for (char** p = _envp; p[0] != nullptr; ++p) {
     const char* val = env_match(p[0], name);
-    if (val != NULL) {
+    if (val != nullptr) {
       if (val[0] == '\0') {
-        return NULL; // Return NULL for empty strings.
+        return nullptr; // Return null for empty strings.
       }
       return val;
     }
   }
-  return NULL;
+  return nullptr;
 }
diff --git a/linker/linker_environ.h b/linker/linker_environ.h
index d3f54fd..0f6ac08 100644
--- a/linker/linker_environ.h
+++ b/linker/linker_environ.h
@@ -35,7 +35,7 @@
 extern void linker_env_init(KernelArgumentBlock& args);
 
 // Returns the value of environment variable 'name' if defined and not
-// empty, or NULL otherwise.
+// empty, or null otherwise.
 extern const char* linker_env_get(const char* name);
 
 // Returns the value of this program's AT_SECURE variable.
diff --git a/linker/linker_phdr.cpp b/linker/linker_phdr.cpp
index 0b99d20..1bbd577 100644
--- a/linker/linker_phdr.cpp
+++ b/linker/linker_phdr.cpp
@@ -121,13 +121,13 @@
 
 ElfReader::ElfReader(const char* name, int fd)
     : name_(name), fd_(fd),
-      phdr_num_(0), phdr_mmap_(NULL), phdr_table_(NULL), phdr_size_(0),
-      load_start_(NULL), load_size_(0), load_bias_(0),
-      loaded_phdr_(NULL) {
+      phdr_num_(0), phdr_mmap_(nullptr), phdr_table_(nullptr), phdr_size_(0),
+      load_start_(nullptr), load_size_(0), load_bias_(0),
+      loaded_phdr_(nullptr) {
 }
 
 ElfReader::~ElfReader() {
-  if (phdr_mmap_ != NULL) {
+  if (phdr_mmap_ != nullptr) {
     munmap(phdr_mmap_, phdr_size_);
   }
 }
@@ -225,7 +225,7 @@
 
   phdr_size_ = page_max - page_min;
 
-  void* mmap_result = mmap(NULL, phdr_size_, PROT_READ, MAP_PRIVATE, fd_, page_min);
+  void* mmap_result = mmap(nullptr, phdr_size_, PROT_READ, MAP_PRIVATE, fd_, page_min);
   if (mmap_result == MAP_FAILED) {
     DL_ERR("\"%s\" phdr mmap failed: %s", name_, strerror(errno));
     return false;
@@ -242,7 +242,7 @@
  * process' address space. If there are no loadable segments, 0 is
  * returned.
  *
- * If out_min_vaddr or out_max_vaddr are non-NULL, they will be
+ * If out_min_vaddr or out_max_vaddr are not null, they will be
  * set to the minimum and maximum addresses of pages to be reserved,
  * or 0 if there is nothing to load.
  */
@@ -276,10 +276,10 @@
   min_vaddr = PAGE_START(min_vaddr);
   max_vaddr = PAGE_END(max_vaddr);
 
-  if (out_min_vaddr != NULL) {
+  if (out_min_vaddr != nullptr) {
     *out_min_vaddr = min_vaddr;
   }
-  if (out_max_vaddr != NULL) {
+  if (out_max_vaddr != nullptr) {
     *out_max_vaddr = max_vaddr;
   }
   return max_vaddr - min_vaddr;
@@ -301,7 +301,7 @@
   size_t reserved_size = 0;
   bool reserved_hint = true;
 
-  if (extinfo != NULL) {
+  if (extinfo != nullptr) {
     if (extinfo->flags & ANDROID_DLEXT_RESERVED_ADDRESS) {
       reserved_size = extinfo->reserved_size;
       reserved_hint = false;
@@ -585,9 +585,9 @@
     return -1;
   }
   off_t file_size = file_stat.st_size;
-  void* temp_mapping = NULL;
+  void* temp_mapping = nullptr;
   if (file_size > 0) {
-    temp_mapping = mmap(NULL, file_size, PROT_READ, MAP_PRIVATE, fd, 0);
+    temp_mapping = mmap(nullptr, file_size, PROT_READ, MAP_PRIVATE, fd, 0);
     if (temp_mapping == MAP_FAILED) {
       return -1;
     }
@@ -667,7 +667,7 @@
  *   phdr_count  -> number of entries in tables
  *   load_bias   -> load bias
  * Output:
- *   arm_exidx       -> address of table in memory (NULL on failure).
+ *   arm_exidx       -> address of table in memory (null on failure).
  *   arm_exidx_count -> number of items in table (0 on failure).
  * Return:
  *   0 on error, -1 on failure (_no_ error code in errno)
@@ -687,21 +687,21 @@
     *arm_exidx_count = (unsigned)(phdr->p_memsz / 8);
     return 0;
   }
-  *arm_exidx = NULL;
+  *arm_exidx = nullptr;
   *arm_exidx_count = 0;
   return -1;
 }
 #endif
 
 /* Return the address and size of the ELF file's .dynamic section in memory,
- * or NULL if missing.
+ * or null if missing.
  *
  * Input:
  *   phdr_table  -> program header table
  *   phdr_count  -> number of entries in tables
  *   load_bias   -> load bias
  * Output:
- *   dynamic       -> address of table in memory (NULL on failure).
+ *   dynamic       -> address of table in memory (null on failure).
  *   dynamic_count -> number of items in table (0 on failure).
  *   dynamic_flags -> protection flags for section (unset on failure)
  * Return:
@@ -727,7 +727,7 @@
     }
     return;
   }
-  *dynamic = NULL;
+  *dynamic = nullptr;
   if (dynamic_count) {
     *dynamic_count = 0;
   }
diff --git a/linker/linker_phdr.h b/linker/linker_phdr.h
index 611f1a7..50708a0 100644
--- a/linker/linker_phdr.h
+++ b/linker/linker_phdr.h
@@ -81,7 +81,7 @@
 };
 
 size_t phdr_table_get_load_size(const ElfW(Phdr)* phdr_table, size_t phdr_count,
-                                ElfW(Addr)* min_vaddr = NULL, ElfW(Addr)* max_vaddr = NULL);
+                                ElfW(Addr)* min_vaddr = nullptr, ElfW(Addr)* max_vaddr = nullptr);
 
 int phdr_table_protect_segments(const ElfW(Phdr)* phdr_table, size_t phdr_count, ElfW(Addr) load_bias);
 
diff --git a/tests/Android.mk b/tests/Android.mk
index 5179bfa..26014ac 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -95,6 +95,7 @@
     stdio_ext_test.cpp \
     stdlib_test.cpp \
     string_test.cpp \
+    string_posix_strerror_r_test.cpp \
     strings_test.cpp \
     stubs_test.cpp \
     sstream_test.cpp \
diff --git a/tests/libc_logging_test.cpp b/tests/libc_logging_test.cpp
index 950161e..d4ceded 100644
--- a/tests/libc_logging_test.cpp
+++ b/tests/libc_logging_test.cpp
@@ -176,3 +176,15 @@
   GTEST_LOG_(INFO) << "This test does nothing.\n";
 #endif // __BIONIC__
 }
+
+TEST(libc_logging, buffer_overrun) {
+#if defined(__BIONIC__)
+  char buf[BUFSIZ];
+  ASSERT_EQ(11, __libc_format_buffer(buf, sizeof(buf), "hello %s", "world"));
+  EXPECT_STREQ("hello world", buf);
+  ASSERT_EQ(11, __libc_format_buffer(buf, 8, "hello %s", "world"));
+  EXPECT_STREQ("hello w", buf);
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
+}
diff --git a/tests/stdatomic_test.cpp b/tests/stdatomic_test.cpp
index 222bd9c..b7fb19b 100644
--- a/tests/stdatomic_test.cpp
+++ b/tests/stdatomic_test.cpp
@@ -63,14 +63,17 @@
 
 TEST(stdatomic, atomic_is_lock_free) {
   atomic_char small;
-  atomic_intmax_t big;
   ASSERT_TRUE(atomic_is_lock_free(&small));
+#if defined(__clang__) || __GNUC_PREREQ(4, 7)
+  // Otherwise stdatomic.h doesn't handle this.
+  atomic_intmax_t big;
   // atomic_intmax_t(size = 64) is not lock free on mips32.
 #if defined(__mips__) && !defined(__LP64__)
   ASSERT_FALSE(atomic_is_lock_free(&big));
 #else
   ASSERT_TRUE(atomic_is_lock_free(&big));
 #endif
+#endif
 }
 
 TEST(stdatomic, atomic_flag) {
diff --git a/tests/string_posix_strerror_r_test.cpp b/tests/string_posix_strerror_r_test.cpp
new file mode 100644
index 0000000..09cebfe
--- /dev/null
+++ b/tests/string_posix_strerror_r_test.cpp
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#undef _GNU_SOURCE
+
+// Old versions of glibc (like our current host prebuilt sysroot one) have
+// headers that don't work if you #undef _GNU_SOURCE, which makes it
+// impossible to build this test.
+#include <features.h>
+
+#if !defined(__GLIBC__)
+#include <string.h>
+
+#include <errno.h>
+#include <gtest/gtest.h>
+
+TEST(string, posix_strerror_r) {
+  char buf[256];
+
+  // Valid.
+  ASSERT_EQ(0, strerror_r(0, buf, sizeof(buf)));
+  ASSERT_STREQ("Success", buf);
+  ASSERT_EQ(0, strerror_r(1, buf, sizeof(buf)));
+  ASSERT_STREQ("Operation not permitted", buf);
+
+  // Invalid.
+  ASSERT_EQ(0, strerror_r(-1, buf, sizeof(buf)));
+  ASSERT_STREQ("Unknown error -1", buf);
+  ASSERT_EQ(0, strerror_r(1234, buf, sizeof(buf)));
+  ASSERT_STREQ("Unknown error 1234", buf);
+
+  // Buffer too small.
+  errno = 0;
+  memset(buf, 0, sizeof(buf));
+  ASSERT_EQ(-1, strerror_r(4567, buf, 2));
+  ASSERT_STREQ("U", buf);
+  // The POSIX strerror_r sets errno to ERANGE (the GNU one doesn't).
+  ASSERT_EQ(ERANGE, errno);
+}
+#else
+# if __GLIBC_PREREQ(2, 15)
+#  error this test should work now
+# endif
+#endif
diff --git a/tests/string_test.cpp b/tests/string_test.cpp
index a3c6abb..7db8e21 100644
--- a/tests/string_test.cpp
+++ b/tests/string_test.cpp
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#define _GNU_SOURCE 1
+
 #include <string.h>
 
 #include <errno.h>
@@ -72,28 +74,34 @@
 #endif // __BIONIC__
 }
 
-TEST(string, strerror_r) {
-#if defined(__BIONIC__) // glibc's strerror_r doesn't even have the same signature as the POSIX one.
+TEST(string, gnu_strerror_r) {
   char buf[256];
 
+  // Note that glibc doesn't necessarily write into the buffer.
+
   // Valid.
-  ASSERT_EQ(0, strerror_r(0, buf, sizeof(buf)));
+  ASSERT_STREQ("Success", strerror_r(0, buf, sizeof(buf)));
+#if defined(__BIONIC__)
   ASSERT_STREQ("Success", buf);
-  ASSERT_EQ(0, strerror_r(1, buf, sizeof(buf)));
+#endif
+  ASSERT_STREQ("Operation not permitted", strerror_r(1, buf, sizeof(buf)));
+#if defined(__BIONIC__)
   ASSERT_STREQ("Operation not permitted", buf);
+#endif
 
   // Invalid.
-  ASSERT_EQ(0, strerror_r(-1, buf, sizeof(buf)));
+  ASSERT_STREQ("Unknown error -1", strerror_r(-1, buf, sizeof(buf)));
   ASSERT_STREQ("Unknown error -1", buf);
-  ASSERT_EQ(0, strerror_r(1234, buf, sizeof(buf)));
+  ASSERT_STREQ("Unknown error 1234", strerror_r(1234, buf, sizeof(buf)));
   ASSERT_STREQ("Unknown error 1234", buf);
 
   // Buffer too small.
-  ASSERT_EQ(-1, strerror_r(0, buf, 2));
-  ASSERT_EQ(ERANGE, errno);
-#else // __BIONIC__
-  GTEST_LOG_(INFO) << "This test does nothing.\n";
-#endif // __BIONIC__
+  errno = 0;
+  memset(buf, 0, sizeof(buf));
+  ASSERT_EQ(buf, strerror_r(4567, buf, 2));
+  ASSERT_STREQ("U", buf);
+  // The GNU strerror_r doesn't set errno (the POSIX one sets it to ERANGE).
+  ASSERT_EQ(0, errno);
 }
 
 TEST(string, strsignal) {
diff --git a/tests/sys_socket_test.cpp b/tests/sys_socket_test.cpp
index 0bde024..38ef68a 100644
--- a/tests/sys_socket_test.cpp
+++ b/tests/sys_socket_test.cpp
@@ -23,13 +23,9 @@
 #include <fcntl.h>
 
 #if defined(__BIONIC__)
-  #define ACCEPT4_SUPPORTED 1
   #define RECVMMSG_SUPPORTED 1
   #define SENDMMSG_SUPPORTED 1
 #elif defined(__GLIBC_PREREQ)
-  #if __GLIBC_PREREQ(2, 9)
-    #define ACCEPT4_SUPPORTED 1
-  #endif
   #if __GLIBC_PREREQ(2, 12)
     #define RECVMMSG_SUPPORTED 1
   #endif
@@ -38,8 +34,6 @@
   #endif
 #endif
 
-#if defined(ACCEPT4_SUPPORTED) || defined(RECVMMSG_SUPPORTED) || defined(SENDMMSG_SUPPORTED)
-
 #define SOCK_PATH "test"
 
 static void* ConnectFn(void* data) {
@@ -105,18 +99,12 @@
 
   close(fd);
 }
-#endif
 
 TEST(sys_socket, accept4_error) {
-#if defined(ACCEPT4_SUPPORTED)
   ASSERT_EQ(-1, accept4(-1, NULL, NULL, 0));
   ASSERT_EQ(EBADF, errno);
-#else
-  GTEST_LOG_(INFO) << "This test does nothing.\n";
-#endif
 }
 
-#if defined(ACCEPT4_SUPPORTED)
 static void TestAccept4(struct sockaddr_un* addr, int fd) {
   socklen_t len = sizeof(*addr);
   int fd_acc = accept4(fd, reinterpret_cast<struct sockaddr*>(addr), &len, SOCK_CLOEXEC);
@@ -127,14 +115,9 @@
 
   close(fd_acc);
 }
-#endif
 
 TEST(sys_socket, accept4_smoke) {
-#if defined(ACCEPT4_SUPPORTED)
   RunTest(TestAccept4, NULL);
-#else
-  GTEST_LOG_(INFO) << "This test does nothing.\n";
-#endif
 }
 
 #if defined(RECVMMSG_SUPPORTED)