Merge "Emit warnings when linking against imprecise math functions"
diff --git a/libc/Android.mk b/libc/Android.mk
index 3faa47f..44bf388 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -292,6 +292,7 @@
     upstream-netbsd/lib/libc/stdlib/ldiv.c \
     upstream-netbsd/lib/libc/stdlib/lldiv.c \
     upstream-netbsd/lib/libc/stdlib/lrand48.c \
+    upstream-netbsd/lib/libc/stdlib/lsearch.c \
     upstream-netbsd/lib/libc/stdlib/mrand48.c \
     upstream-netbsd/lib/libc/stdlib/nrand48.c \
     upstream-netbsd/lib/libc/stdlib/_rand48.c \
diff --git a/libc/arch-arm/include/machine/limits.h b/libc/arch-arm/include/machine/limits.h
deleted file mode 100644
index f9c04fa..0000000
--- a/libc/arch-arm/include/machine/limits.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*	$OpenBSD: limits.h,v 1.3 2006/01/06 22:48:46 millert Exp $	*/
-/*	$NetBSD: limits.h,v 1.4 2003/04/28 23:16:18 bjh21 Exp $	*/
-
-/*
- * Copyright (c) 1988 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	from: @(#)limits.h	7.2 (Berkeley) 6/28/90
- */
-
-#ifndef	_ARM32_LIMITS_H_
-#define	_ARM32_LIMITS_H_
-
-#include <sys/cdefs.h>
-
-#define	MB_LEN_MAX	1		/* no multibyte characters */
-
-#ifndef	SIZE_MAX
-#define	SIZE_MAX	UINT_MAX	/* max value for a size_t */
-#endif
-#ifndef SSIZE_MAX
-#define	SSIZE_MAX	INT_MAX		/* max value for a ssize_t */
-#endif
-
-#if __BSD_VISIBLE
-#define	SIZE_T_MAX	UINT_MAX	/* max value for a size_t (historic) */
-
-#define	UQUAD_MAX	0xffffffffffffffffULL		/* max unsigned quad */
-#define	QUAD_MAX	0x7fffffffffffffffLL		/* max signed quad */
-#define	QUAD_MIN	(-0x7fffffffffffffffLL-1)	/* min signed quad */
-
-#endif /* __BSD_VISIBLE */
-
-#define LONGLONG_BIT    64
-#define LONGLONG_MIN    (-9223372036854775807LL-1)
-#define LONGLONG_MAX    9223372036854775807LL
-#define ULONGLONG_MAX   18446744073709551615ULL
-
-#endif	/* _ARM32_LIMITS_H_ */
diff --git a/libc/arch-arm64/include/machine/limits.h b/libc/arch-arm64/include/machine/limits.h
deleted file mode 100644
index ecddb01..0000000
--- a/libc/arch-arm64/include/machine/limits.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*	$OpenBSD: limits.h,v 1.3 2006/01/06 22:48:46 millert Exp $	*/
-/*	$NetBSD: limits.h,v 1.4 2003/04/28 23:16:18 bjh21 Exp $	*/
-
-/*
- * Copyright (c) 1988 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	from: @(#)limits.h	7.2 (Berkeley) 6/28/90
- */
-
-#ifndef _AARCH64_LIMITS_H_
-#define _AARCH64_LIMITS_H_
-
-#include <sys/cdefs.h>
-
-#define	MB_LEN_MAX	1		/* no multibyte characters */
-
-#define	LONGLONG_BIT	64
-#define	LONGLONG_MIN	(-9223372036854775807LL-1)
-#define	LONGLONG_MAX	9223372036854775807LL
-#define	ULONGLONG_MAX	18446744073709551615ULL
-
-#ifndef	SIZE_MAX
-#define	SIZE_MAX	ULONGLONG_MAX	/* max value for a size_t */
-#endif
-#ifndef SSIZE_MAX
-#define	SSIZE_MAX	LONGLONG_MAX		/* max value for a ssize_t */
-#endif
-
-#if __BSD_VISIBLE
-#define	SIZE_T_MAX	ULONG_MAX	/* max value for a size_t (historic) */
-
-#define	UQUAD_MAX	0xffffffffffffffffULL		/* max unsigned quad */
-#define	QUAD_MAX	0x7fffffffffffffffLL		/* max signed quad */
-#define	QUAD_MIN	(-0x7fffffffffffffffLL-1)	/* min signed quad */
-
-#endif /* __BSD_VISIBLE */
-#endif /* _AARCH64_LIMITS_H_ */
diff --git a/libc/arch-mips/include/machine/limits.h b/libc/arch-mips/include/machine/limits.h
deleted file mode 100644
index 339444d..0000000
--- a/libc/arch-mips/include/machine/limits.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*	$OpenBSD: limits.h,v 1.5 2007/05/07 20:51:07 kettenis Exp $	*/
-
-/*
- * Copyright (c) 1988, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)limits.h	8.3 (Berkeley) 1/4/94
- */
-
-#ifndef _MIPS_LIMITS_H_
-#define _MIPS_LIMITS_H_
-
-#include <sys/cdefs.h>
-
-#define	MB_LEN_MAX	6		/* Allow 31 bit UTF2 */
-
-#ifndef	SIZE_MAX
-#define	SIZE_MAX	ULONG_MAX	/* max value for a size_t */
-#endif
-#define	SSIZE_MAX	LONG_MAX	/* max value for a ssize_t */
-
-#if __BSD_VISIBLE
-#define	SIZE_T_MAX	ULONG_MAX	/* max value for a size_t (historic) */
-
-/* Quads and longs are the same on mips64 */
-#define	UQUAD_MAX	(ULONG_MAX)	/* max value for a uquad_t */
-#define	QUAD_MAX	(LONG_MAX)	/* max value for a quad_t */
-#define	QUAD_MIN	(LONG_MIN)	/* min value for a quad_t */
-
-#endif /* __BSD_VISIBLE */
-
-
-#define LONGLONG_BIT    64
-#define LONGLONG_MIN    (-9223372036854775807LL-1)
-#define LONGLONG_MAX    9223372036854775807LL
-#define ULONGLONG_MAX   18446744073709551615ULL
-
-#endif /* !_MIPS_LIMITS_H_ */
diff --git a/libc/arch-mips64/include/machine/limits.h b/libc/arch-mips64/include/machine/limits.h
deleted file mode 100644
index 339444d..0000000
--- a/libc/arch-mips64/include/machine/limits.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*	$OpenBSD: limits.h,v 1.5 2007/05/07 20:51:07 kettenis Exp $	*/
-
-/*
- * Copyright (c) 1988, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)limits.h	8.3 (Berkeley) 1/4/94
- */
-
-#ifndef _MIPS_LIMITS_H_
-#define _MIPS_LIMITS_H_
-
-#include <sys/cdefs.h>
-
-#define	MB_LEN_MAX	6		/* Allow 31 bit UTF2 */
-
-#ifndef	SIZE_MAX
-#define	SIZE_MAX	ULONG_MAX	/* max value for a size_t */
-#endif
-#define	SSIZE_MAX	LONG_MAX	/* max value for a ssize_t */
-
-#if __BSD_VISIBLE
-#define	SIZE_T_MAX	ULONG_MAX	/* max value for a size_t (historic) */
-
-/* Quads and longs are the same on mips64 */
-#define	UQUAD_MAX	(ULONG_MAX)	/* max value for a uquad_t */
-#define	QUAD_MAX	(LONG_MAX)	/* max value for a quad_t */
-#define	QUAD_MIN	(LONG_MIN)	/* min value for a quad_t */
-
-#endif /* __BSD_VISIBLE */
-
-
-#define LONGLONG_BIT    64
-#define LONGLONG_MIN    (-9223372036854775807LL-1)
-#define LONGLONG_MAX    9223372036854775807LL
-#define ULONGLONG_MAX   18446744073709551615ULL
-
-#endif /* !_MIPS_LIMITS_H_ */
diff --git a/libc/arch-x86/include/machine/limits.h b/libc/arch-x86/include/machine/limits.h
deleted file mode 100644
index 86fd854..0000000
--- a/libc/arch-x86/include/machine/limits.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*	$OpenBSD: limits.h,v 1.11 2006/01/06 22:48:47 millert Exp $	*/
-/*	$NetBSD: limits.h,v 1.11 1995/12/21 01:08:59 mycroft Exp $	*/
-
-/*
- * Copyright (c) 1988 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)limits.h	7.2 (Berkeley) 6/28/90
- */
-
-#ifndef _MACHINE_LIMITS_H_
-#define _MACHINE_LIMITS_H_
-
-#include <sys/cdefs.h>
-
-#define	MB_LEN_MAX	1		/* no multibyte characters */
-
-#ifndef	SIZE_MAX
-#define	SIZE_MAX	UINT_MAX	/* max value for a size_t */
-#endif
-#ifndef SSIZE_MAX
-#define	SSIZE_MAX	INT_MAX		/* max value for a ssize_t */
-#endif
-
-#if __BSD_VISIBLE
-#define	SIZE_T_MAX	UINT_MAX	/* max value for a size_t (historic) */
-
-#define	UQUAD_MAX	0xffffffffffffffffULL		/* max unsigned quad */
-#define	QUAD_MAX	0x7fffffffffffffffLL		/* max signed quad */
-#define	QUAD_MIN	(-0x7fffffffffffffffLL-1)	/* min signed quad */
-
-#endif /* __BSD_VISIBLE */
-
-#define LONGLONG_BIT    64
-#define LONGLONG_MIN    (-9223372036854775807LL-1)
-#define LONGLONG_MAX    9223372036854775807LL
-#define ULONGLONG_MAX   18446744073709551615ULL
-
-#endif /* _MACHINE_LIMITS_H_ */
diff --git a/libc/arch-x86/string/cache.h b/libc/arch-x86/string/cache.h
index d9aff5c..9d0a563 100644
--- a/libc/arch-x86/string/cache.h
+++ b/libc/arch-x86/string/cache.h
@@ -28,8 +28,15 @@
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
+#if defined(__slm__)
+/* Values are optimized for Silvermont */
+#define SHARED_CACHE_SIZE	(1024*1024)			/* Silvermont L2 Cache */
+#define DATA_CACHE_SIZE		(24*1024)			/* Silvermont L1 Data Cache */
+#else
 /* Values are optimized for Atom */
 #define SHARED_CACHE_SIZE	(512*1024)			/* Atom L2 Cache */
 #define DATA_CACHE_SIZE		(24*1024)			/* Atom L1 Data Cache */
+#endif
+
 #define SHARED_CACHE_SIZE_HALF	(SHARED_CACHE_SIZE / 2)
 #define DATA_CACHE_SIZE_HALF	(DATA_CACHE_SIZE / 2)
diff --git a/libc/arch-x86_64/include/machine/limits.h b/libc/arch-x86_64/include/machine/limits.h
deleted file mode 100644
index a8c4a88..0000000
--- a/libc/arch-x86_64/include/machine/limits.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*	$OpenBSD: limits.h,v 1.5 2009/11/27 19:54:35 guenther Exp $	*/
-
-/*
- * Copyright (c) 1988 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)limits.h	7.2 (Berkeley) 6/28/90
- */
-
-#ifndef	_MACHINE_LIMITS_H_
-#define	_MACHINE_LIMITS_H_
-
-#include <sys/cdefs.h>
-
-#if __POSIX_VISIBLE || __XPG_VISIBLE
-#ifndef	SIZE_MAX
-#define SIZE_MAX	ULONG_MAX	/* max value for a size_t */
-#endif
-#define SSIZE_MAX	LONG_MAX	/* max value for a ssize_t */
-#endif
-
-#if __BSD_VISIBLE
-#define	SIZE_T_MAX	ULONG_MAX	/* max value for a size_t (historic) */
-
-#define	UQUAD_MAX	0xffffffffffffffffULL		/* max unsigned quad */
-#define	QUAD_MAX	0x7fffffffffffffffLL		/* max signed quad */
-#define	QUAD_MIN	(-0x7fffffffffffffffLL-1)	/* min signed quad */
-
-#endif /* __BSD_VISIBLE */
-
-#endif /* _MACHINE_LIMITS_H_ */
diff --git a/libc/bionic/malloc_debug_common.cpp b/libc/bionic/malloc_debug_common.cpp
index 85f7791..4fa4b6e 100644
--- a/libc/bionic/malloc_debug_common.cpp
+++ b/libc/bionic/malloc_debug_common.cpp
@@ -379,7 +379,7 @@
             if (gMallocDebugBacklog == 0) {
                 gMallocDebugBacklog = BACKLOG_DEFAULT_LEN;
             }
-            so_name = "/system/lib/libc_malloc_debug_leak.so";
+            so_name = "libc_malloc_debug_leak.so";
             break;
         }
         case 20:
@@ -395,7 +395,7 @@
                           __progname);
                 return;
             }
-            so_name = "/system/lib/libc_malloc_debug_qemu.so";
+            so_name = "libc_malloc_debug_qemu.so";
             break;
         default:
             error_log("%s: Debug level %d is unknown\n", __progname, gMallocDebugLevel);
diff --git a/libc/bionic/posix_timers.cpp b/libc/bionic/posix_timers.cpp
index e9190b2..59933ec 100644
--- a/libc/bionic/posix_timers.cpp
+++ b/libc/bionic/posix_timers.cpp
@@ -63,7 +63,6 @@
   pthread_t callback_thread;
   void (*callback)(sigval_t);
   sigval_t callback_argument;
-  volatile int exiting;
 };
 
 static __kernel_timer_t to_kernel_timer_id(timer_t timer) {
@@ -90,8 +89,7 @@
       timer->callback(timer->callback_argument);
     } else if (si.si_code == SI_TKILL) {
       // This signal was sent because someone wants us to exit.
-      timer->exiting = 1;
-      __futex_wake(&timer->exiting, INT32_MAX);
+      free(timer);
       return NULL;
     }
   }
@@ -99,46 +97,35 @@
 
 static void __timer_thread_stop(PosixTimer* timer) {
   pthread_kill(timer->callback_thread, TIMER_SIGNAL);
-
-  // If this is being called from within the callback thread, do nothing else.
-  if (pthread_self() != timer->callback_thread) {
-    // We can't pthread_join because POSIX says "the threads created in response to a timer
-    // expiration are created detached, or in an unspecified way if the thread attribute's
-    // detachstate is PTHREAD_CREATE_JOINABLE".
-    while (timer->exiting == 0) {
-      __futex_wait(&timer->exiting, 0, NULL);
-    }
-  }
 }
 
 // http://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_create.html
 int timer_create(clockid_t clock_id, sigevent* evp, timer_t* timer_id) {
-  PosixTimer* new_timer = reinterpret_cast<PosixTimer*>(malloc(sizeof(PosixTimer)));
-  if (new_timer == NULL) {
+  PosixTimer* timer = reinterpret_cast<PosixTimer*>(malloc(sizeof(PosixTimer)));
+  if (timer == NULL) {
     return -1;
   }
 
-  new_timer->sigev_notify = (evp == NULL) ? SIGEV_SIGNAL : evp->sigev_notify;
+  timer->sigev_notify = (evp == NULL) ? SIGEV_SIGNAL : evp->sigev_notify;
 
   // If not a SIGEV_THREAD timer, the kernel can handle it without our help.
-  if (new_timer->sigev_notify != SIGEV_THREAD) {
-    if (__timer_create(clock_id, evp, &new_timer->kernel_timer_id) == -1) {
-      free(new_timer);
+  if (timer->sigev_notify != SIGEV_THREAD) {
+    if (__timer_create(clock_id, evp, &timer->kernel_timer_id) == -1) {
+      free(timer);
       return -1;
     }
 
-    *timer_id = new_timer;
+    *timer_id = timer;
     return 0;
   }
 
   // Otherwise, this must be SIGEV_THREAD timer...
-  new_timer->callback = evp->sigev_notify_function;
-  new_timer->callback_argument = evp->sigev_value;
-  new_timer->exiting = 0;
+  timer->callback = evp->sigev_notify_function;
+  timer->callback_argument = evp->sigev_value;
 
   // Check arguments that the kernel doesn't care about but we do.
-  if (new_timer->callback == NULL) {
-    free(new_timer);
+  if (timer->callback == NULL) {
+    free(timer);
     errno = EINVAL;
     return -1;
   }
@@ -159,12 +146,12 @@
   kernel_sigset_t old_sigset;
   pthread_sigmask(SIG_BLOCK, sigset.get(), old_sigset.get());
 
-  int rc = pthread_create(&new_timer->callback_thread, &thread_attributes, __timer_thread_start, new_timer);
+  int rc = pthread_create(&timer->callback_thread, &thread_attributes, __timer_thread_start, timer);
 
   pthread_sigmask(SIG_SETMASK, old_sigset.get(), NULL);
 
   if (rc != 0) {
-    free(new_timer);
+    free(timer);
     errno = rc;
     return -1;
   }
@@ -172,20 +159,19 @@
   sigevent se = *evp;
   se.sigev_signo = TIMER_SIGNAL;
   se.sigev_notify = SIGEV_THREAD_ID;
-  se.sigev_notify_thread_id = __pthread_gettid(new_timer->callback_thread);
-  if (__timer_create(clock_id, &se, &new_timer->kernel_timer_id) == -1) {
-    __timer_thread_stop(new_timer);
-    free(new_timer);
+  se.sigev_notify_thread_id = __pthread_gettid(timer->callback_thread);
+  if (__timer_create(clock_id, &se, &timer->kernel_timer_id) == -1) {
+    __timer_thread_stop(timer);
     return -1;
   }
 
   // Give the thread a meaningful name.
   // It can't do this itself because the kernel timer isn't created until after it's running.
   char name[32];
-  snprintf(name, sizeof(name), "POSIX interval timer %d", to_kernel_timer_id(new_timer));
-  pthread_setname_np(new_timer->callback_thread, name);
+  snprintf(name, sizeof(name), "POSIX interval timer %d", to_kernel_timer_id(timer));
+  pthread_setname_np(timer->callback_thread, name);
 
-  *timer_id = new_timer;
+  *timer_id = timer;
   return 0;
 }
 
@@ -197,14 +183,14 @@
   }
 
   PosixTimer* timer = reinterpret_cast<PosixTimer*>(id);
-
-  // Make sure the timer's thread has exited before we free the timer data.
   if (timer->sigev_notify == SIGEV_THREAD) {
+    // Stopping the timer's thread frees the timer data when it's safe.
     __timer_thread_stop(timer);
+  } else {
+    // For timers without threads, we can just free right away.
+    free(timer);
   }
 
-  free(timer);
-
   return 0;
 }
 
diff --git a/libc/include/limits.h b/libc/include/limits.h
index 471d380..a70021a 100644
--- a/libc/include/limits.h
+++ b/libc/include/limits.h
@@ -105,6 +105,15 @@
 #define ULONG_LONG_MAX  ULLONG_MAX
 #endif
 
+/* BSD compatibility definitions. */
+#if __BSD_VISIBLE
+#define SIZE_T_MAX ULONG_MAX
+#endif /* __BSD_VISIBLE */
+
+#define SSIZE_MAX LONG_MAX
+
+#define MB_LEN_MAX 1 /* No multibyte characters. */
+
 /* New code should use sysconf(_SC_PAGE_SIZE) instead. */
 #ifndef PAGE_SIZE
 #define PAGE_SIZE 4096
diff --git a/libc/include/search.h b/libc/include/search.h
index 1301a08..b2c0e6b 100644
--- a/libc/include/search.h
+++ b/libc/include/search.h
@@ -10,29 +10,34 @@
 #define _SEARCH_H_
 
 #include <sys/cdefs.h>
+#include <sys/types.h>
 
-typedef	enum {
-	preorder,
-	postorder,
-	endorder,
-	leaf
+typedef enum {
+  preorder,
+  postorder,
+  endorder,
+  leaf
 } VISIT;
 
 #ifdef _SEARCH_PRIVATE
-typedef	struct node {
-	char         *key;
-	struct node  *llink, *rlink;
+typedef struct node {
+  char* key;
+  struct node* llink;
+  struct node* rlink;
 } node_t;
 #endif
 
 __BEGIN_DECLS
-void	*tdelete(const void * __restrict, void ** __restrict,
-	    int (*)(const void *, const void *));
-void	*tfind(const void *, void * const *,
-	    int (*)(const void *, const void *));
-void	*tsearch(const void *, void **, int (*)(const void *, const void *));
-void	 twalk(const void *, void (*)(const void *, VISIT, int));
-void	 tdestroy(void *, void (*)(void *));
+
+void* lfind(const void*, const void*, size_t*, size_t, int (*)(const void*, const void*));
+void* lsearch(const void*, void*, size_t*, size_t, int (*)(const void*, const void*));
+
+void* tdelete(const void* __restrict, void** __restrict, int (*)(const void*, const void*));
+void tdestroy(void*, void (*)(void*));
+void* tfind(const void*, void* const*, int (*)(const void*, const void*));
+void* tsearch(const void*, void**, int (*)(const void*, const void*));
+void twalk(const void*, void (*)(const void*, VISIT, int));
+
 __END_DECLS
 
 #endif /* !_SEARCH_H_ */
diff --git a/libc/include/sys/limits.h b/libc/include/sys/limits.h
index 36f73b2..c50eb10 100644
--- a/libc/include/sys/limits.h
+++ b/libc/include/sys/limits.h
@@ -31,9 +31,6 @@
 
 /* Common definitions for limits.h. */
 
-/* Legacy */
-#include <machine/limits.h>
-
 #define	CHAR_BIT	8		/* number of bits in a char */
 
 #define	SCHAR_MAX	0x7f		/* max value for a signed char */
diff --git a/libc/kernel/uapi/video/adf.h b/libc/kernel/uapi/video/adf.h
index 057ec46..fe23e01 100644
--- a/libc/kernel/uapi/video/adf.h
+++ b/libc/kernel/uapi/video/adf.h
@@ -62,7 +62,7 @@
 struct adf_vsync_event {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  struct adf_event base;
- __u64 timestamp;
+ __aligned_u64 timestamp;
 };
 struct adf_hotplug_event {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
@@ -77,12 +77,12 @@
  __u32 h;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 format;
- __s64 fd[ADF_MAX_PLANES];
+ __s32 fd[ADF_MAX_PLANES];
  __u32 offset[ADF_MAX_PLANES];
  __u32 pitch[ADF_MAX_PLANES];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u8 n_planes;
- __s64 acquire_fence;
+ __s32 acquire_fence;
 };
 #define ADF_MAX_BUFFERS (4096 / sizeof(struct adf_buffer_config))
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
@@ -94,7 +94,7 @@
  struct adf_buffer_config __user *bufs;
  size_t custom_data_size;
  void __user *custom_data;
- __s64 complete_fence;
+ __s32 complete_fence;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
 #define ADF_MAX_INTERFACES (4096 / sizeof(__u32))
@@ -103,7 +103,7 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u16 h;
  __u32 format;
- __s64 fd;
+ __s32 fd;
  __u32 offset;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  __u32 pitch;
@@ -111,7 +111,7 @@
 struct adf_simple_post_config {
  struct adf_buffer_config buf;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
- __s64 complete_fence;
+ __s32 complete_fence;
 };
 struct adf_attachment_config {
  __u32 overlay_engine;
@@ -161,18 +161,20 @@
 };
 #define ADF_MAX_SUPPORTED_FORMATS (4096 / sizeof(__u32))
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define ADF_SET_EVENT _IOW('D', 0, struct adf_set_event)
-#define ADF_BLANK _IOW('D', 1, __u8)
-#define ADF_POST_CONFIG _IOW('D', 2, struct adf_post_config)
-#define ADF_SET_MODE _IOW('D', 3, struct drm_mode_modeinfo)
+#define ADF_IOCTL_TYPE 'D'
+#define ADF_IOCTL_NR_CUSTOM 128
+#define ADF_SET_EVENT _IOW(ADF_IOCTL_TYPE, 0, struct adf_set_event)
+#define ADF_BLANK _IOW(ADF_IOCTL_TYPE, 1, __u8)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define ADF_GET_DEVICE_DATA _IOR('D', 4, struct adf_device_data)
-#define ADF_GET_INTERFACE_DATA _IOR('D', 5, struct adf_interface_data)
-#define ADF_GET_OVERLAY_ENGINE_DATA   _IOR('D', 6, struct adf_overlay_engine_data)
-#define ADF_SIMPLE_POST_CONFIG _IOW('D', 7, struct adf_simple_post_config)
+#define ADF_POST_CONFIG _IOW(ADF_IOCTL_TYPE, 2, struct adf_post_config)
+#define ADF_SET_MODE _IOW(ADF_IOCTL_TYPE, 3,   struct drm_mode_modeinfo)
+#define ADF_GET_DEVICE_DATA _IOR(ADF_IOCTL_TYPE, 4, struct adf_device_data)
+#define ADF_GET_INTERFACE_DATA _IOR(ADF_IOCTL_TYPE, 5,   struct adf_interface_data)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#define ADF_SIMPLE_BUFFER_ALLOC _IOW('D', 8, struct adf_simple_buffer_alloc)
-#define ADF_ATTACH _IOW('D', 9, struct adf_attachment_config)
-#define ADF_DETACH _IOW('D', 10, struct adf_attachment_config)
+#define ADF_GET_OVERLAY_ENGINE_DATA   _IOR(ADF_IOCTL_TYPE, 6,   struct adf_overlay_engine_data)
+#define ADF_SIMPLE_POST_CONFIG _IOW(ADF_IOCTL_TYPE, 7,   struct adf_simple_post_config)
+#define ADF_SIMPLE_BUFFER_ALLOC _IOW(ADF_IOCTL_TYPE, 8,   struct adf_simple_buffer_alloc)
+#define ADF_ATTACH _IOW(ADF_IOCTL_TYPE, 9,   struct adf_attachment_config)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ADF_DETACH _IOW(ADF_IOCTL_TYPE, 10,   struct adf_attachment_config)
 #endif
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/libc/upstream-netbsd/lib/libc/stdlib/lsearch.c b/libc/upstream-netbsd/lib/libc/stdlib/lsearch.c
new file mode 100644
index 0000000..e17130b
--- /dev/null
+++ b/libc/upstream-netbsd/lib/libc/stdlib/lsearch.c
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 1989, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Roger L. Snyder.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)lsearch.c	8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: lsearch.c,v 1.7 2012/06/25 22:32:45 abs Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <string.h>
+#include <search.h>
+
+typedef int (*cmp_fn_t)(const void *, const void *);
+static void *linear_base(const void *, void *, size_t *, size_t,
+			     cmp_fn_t, int);
+
+void *
+lsearch(const void *key, void *base, size_t *nelp, size_t width,
+    cmp_fn_t compar)
+{
+
+	_DIAGASSERT(key != NULL);
+	_DIAGASSERT(base != NULL);
+	_DIAGASSERT(compar != NULL);
+
+	return(linear_base(key, base, nelp, width, compar, 1));
+}
+
+void *
+lfind(const void *key, const void *base, size_t *nelp, size_t width,
+    cmp_fn_t compar)
+{
+
+	_DIAGASSERT(key != NULL);
+	_DIAGASSERT(base != NULL);
+	_DIAGASSERT(compar != NULL);
+
+	return(linear_base(key, __UNCONST(base), nelp, width, compar, 0));
+}
+
+static void *
+linear_base(const void *key, void *base, size_t *nelp, size_t width,
+	cmp_fn_t compar, int add_flag)
+{
+	char *element, *end;
+
+	_DIAGASSERT(key != NULL);
+	_DIAGASSERT(base != NULL);
+	_DIAGASSERT(compar != NULL);
+
+	end = (char *)base + *nelp * width;
+	for (element = (char *)base; element < end; element += width)
+		if (!compar(element, key))		/* key found */
+			return element;
+
+	if (!add_flag)					/* key not found */
+		return(NULL);
+
+	/*
+	 * The UNIX System User's Manual, 1986 edition claims that
+	 * a NULL pointer is returned by lsearch with errno set
+	 * appropriately, if there is not enough room in the table
+	 * to add a new item.  This can't be done as none of these
+	 * routines have any method of determining the size of the
+	 * table.  This comment isn't in the 1986-87 System V
+	 * manual.
+	 */
+	++*nelp;
+	memcpy(end, key, width);
+	return end;
+}
diff --git a/libc/zoneinfo/tzdata b/libc/zoneinfo/tzdata
index 8468e83..2178298 100644
--- a/libc/zoneinfo/tzdata
+++ b/libc/zoneinfo/tzdata
Binary files differ
diff --git a/linker/Android.mk b/linker/Android.mk
index c517a30..f0e6c13 100644
--- a/linker/Android.mk
+++ b/linker/Android.mk
@@ -1,6 +1,5 @@
-LOCAL_PATH:= $(call my-dir)
+LOCAL_PATH := $(call my-dir)
 
-LOCAL_PATH:= $(call my-dir)
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES:= \
diff --git a/tests/math_test.cpp b/tests/math_test.cpp
index c1a9f4f..7734018 100644
--- a/tests/math_test.cpp
+++ b/tests/math_test.cpp
@@ -104,7 +104,7 @@
 
   ASSERT_EQ(FP_NORMAL, fpclassify(1.0f));
   ASSERT_EQ(FP_NORMAL, fpclassify(1.0));
-  ASSERT_EQ(FP_NORMAL, fpclassify(1.0l));
+  ASSERT_EQ(FP_NORMAL, fpclassify(1.0L));
 
   ASSERT_EQ(FP_SUBNORMAL, fpclassify(float_subnormal()));
   ASSERT_EQ(FP_SUBNORMAL, fpclassify(double_subnormal()));
@@ -112,13 +112,13 @@
 
   ASSERT_EQ(FP_ZERO, fpclassify(0.0f));
   ASSERT_EQ(FP_ZERO, fpclassify(0.0));
-  ASSERT_EQ(FP_ZERO, fpclassify(0.0l));
+  ASSERT_EQ(FP_ZERO, fpclassify(0.0L));
 }
 
 TEST(math, isfinite) {
   ASSERT_TRUE(test_capture_isfinite(123.0f));
   ASSERT_TRUE(test_capture_isfinite(123.0));
-  ASSERT_TRUE(test_capture_isfinite(123.0l));
+  ASSERT_TRUE(test_capture_isfinite(123.0L));
   ASSERT_FALSE(test_capture_isfinite(HUGE_VALF));
   ASSERT_FALSE(test_capture_isfinite(HUGE_VAL));
   ASSERT_FALSE(test_capture_isfinite(HUGE_VALL));
@@ -127,7 +127,7 @@
 TEST(math, isinf) {
   ASSERT_FALSE(test_capture_isinf(123.0f));
   ASSERT_FALSE(test_capture_isinf(123.0));
-  ASSERT_FALSE(test_capture_isinf(123.0l));
+  ASSERT_FALSE(test_capture_isinf(123.0L));
   ASSERT_TRUE(test_capture_isinf(HUGE_VALF));
   ASSERT_TRUE(test_capture_isinf(HUGE_VAL));
   ASSERT_TRUE(test_capture_isinf(HUGE_VALL));
@@ -136,7 +136,7 @@
 TEST(math, isnan) {
   ASSERT_FALSE(test_capture_isnan(123.0f));
   ASSERT_FALSE(test_capture_isnan(123.0));
-  ASSERT_FALSE(test_capture_isnan(123.0l));
+  ASSERT_FALSE(test_capture_isnan(123.0L));
   ASSERT_TRUE(test_capture_isnan(nanf("")));
   ASSERT_TRUE(test_capture_isnan(nan("")));
   ASSERT_TRUE(test_capture_isnan(nanl("")));
@@ -145,7 +145,7 @@
 TEST(math, isnormal) {
   ASSERT_TRUE(isnormal(123.0f));
   ASSERT_TRUE(isnormal(123.0));
-  ASSERT_TRUE(isnormal(123.0l));
+  ASSERT_TRUE(isnormal(123.0L));
   ASSERT_FALSE(isnormal(float_subnormal()));
   ASSERT_FALSE(isnormal(double_subnormal()));
   ASSERT_FALSE(isnormal(ldouble_subnormal()));
@@ -155,15 +155,15 @@
 TEST(math, signbit) {
   ASSERT_EQ(0, test_capture_signbit(0.0f));
   ASSERT_EQ(0, test_capture_signbit(0.0));
-  ASSERT_EQ(0, test_capture_signbit(0.0l));
+  ASSERT_EQ(0, test_capture_signbit(0.0L));
 
   ASSERT_EQ(0, test_capture_signbit(1.0f));
   ASSERT_EQ(0, test_capture_signbit(1.0));
-  ASSERT_EQ(0, test_capture_signbit(1.0l));
+  ASSERT_EQ(0, test_capture_signbit(1.0L));
 
   ASSERT_NE(0, test_capture_signbit(-1.0f));
   ASSERT_NE(0, test_capture_signbit(-1.0));
-  ASSERT_NE(0, test_capture_signbit(-1.0l));
+  ASSERT_NE(0, test_capture_signbit(-1.0L));
 }
 
 TEST(math, __fpclassifyd) {
@@ -194,9 +194,9 @@
 #if defined(__BIONIC__)
   EXPECT_EQ(FP_INFINITE, __fpclassifyl(HUGE_VALL));
   EXPECT_EQ(FP_NAN, __fpclassifyl(nanl("")));
-  EXPECT_EQ(FP_NORMAL, __fpclassifyl(1.0l));
+  EXPECT_EQ(FP_NORMAL, __fpclassifyl(1.0L));
   EXPECT_EQ(FP_SUBNORMAL, __fpclassifyl(ldouble_subnormal()));
-  EXPECT_EQ(FP_ZERO, __fpclassifyl(0.0l));
+  EXPECT_EQ(FP_ZERO, __fpclassifyl(0.0L));
 #else // __BIONIC__
   GTEST_LOG_(INFO) << "This test does nothing.\n";
 #endif // __BIONIC__
@@ -227,7 +227,7 @@
 
 TEST(math, __isfinitel) {
 #if defined(__BIONIC__)
-  ASSERT_TRUE(__isfinitel(123.0l));
+  ASSERT_TRUE(__isfinitel(123.0L));
   ASSERT_FALSE(__isfinitel(HUGE_VALL));
 #else // __BIONIC__
   GTEST_LOG_(INFO) << "This test does nothing.\n";
@@ -245,7 +245,7 @@
 }
 
 TEST(math, __isinfl) {
-  ASSERT_FALSE(__isinfl(123.0l));
+  ASSERT_FALSE(__isinfl(123.0L));
   ASSERT_TRUE(__isinfl(HUGE_VALL));
 }
 
@@ -255,7 +255,7 @@
 }
 
 TEST(math, __isnanl) {
-  ASSERT_FALSE(__isnanl(123.0l));
+  ASSERT_FALSE(__isnanl(123.0L));
   ASSERT_TRUE(__isnanl(nanl("")));
 }
 
@@ -284,7 +284,7 @@
 
 TEST(math, __isnormall) {
 #if defined(__BIONIC__)
-  ASSERT_TRUE(__isnormall(123.0l));
+  ASSERT_TRUE(__isnormall(123.0L));
   ASSERT_FALSE(__isnormall(ldouble_subnormal()));
 #else // __BIONIC__
   GTEST_LOG_(INFO) << "This test does nothing.\n";
@@ -304,9 +304,9 @@
 }
 
 TEST(math, __signbitl) {
-  ASSERT_EQ(0l, __signbitl(0.0l));
-  ASSERT_EQ(0l, __signbitl(1.0l));
-  ASSERT_NE(0l, __signbitl(-1.0l));
+  ASSERT_EQ(0L, __signbitl(0.0L));
+  ASSERT_EQ(0L, __signbitl(1.0L));
+  ASSERT_NE(0L, __signbitl(-1.0L));
 }
 
 TEST(math, acos) {
@@ -318,7 +318,7 @@
 }
 
 TEST(math, acosl) {
-  ASSERT_DOUBLE_EQ(M_PI/2.0l, acosl(0.0l));
+  ASSERT_DOUBLE_EQ(M_PI/2.0L, acosl(0.0L));
 }
 
 TEST(math, asin) {
@@ -330,7 +330,7 @@
 }
 
 TEST(math, asinl) {
-  ASSERT_DOUBLE_EQ(0.0l, asinl(0.0l));
+  ASSERT_DOUBLE_EQ(0.0L, asinl(0.0L));
 }
 
 TEST(math, atan) {
@@ -342,7 +342,7 @@
 }
 
 TEST(math, atanl) {
-  ASSERT_DOUBLE_EQ(0.0l, atanl(0.0l));
+  ASSERT_DOUBLE_EQ(0.0L, atanl(0.0L));
 }
 
 TEST(math, atan2) {
@@ -354,7 +354,7 @@
 }
 
 TEST(math, atan2l) {
-  ASSERT_DOUBLE_EQ(0.0l, atan2l(0.0l, 0.0l));
+  ASSERT_DOUBLE_EQ(0.0L, atan2l(0.0L, 0.0L));
 }
 
 TEST(math, cos) {
@@ -366,11 +366,11 @@
 }
 
 TEST(math, cosl) {
-  ASSERT_DOUBLE_EQ(1.0l, cosl(0.0l));
+  ASSERT_DOUBLE_EQ(1.0L, cosl(0.0L));
 }
 
 TEST(math, sin) {
-  ASSERT_FLOAT_EQ(0.0, sin(0.0));
+  ASSERT_DOUBLE_EQ(0.0, sin(0.0));
 }
 
 TEST(math, sinf) {
@@ -378,7 +378,7 @@
 }
 
 TEST(math, sinl) {
-  ASSERT_DOUBLE_EQ(0.0l, sinl(0.0l));
+  ASSERT_DOUBLE_EQ(0.0L, sinl(0.0L));
 }
 
 TEST(math, tan) {
@@ -390,7 +390,7 @@
 }
 
 TEST(math, tanl) {
-  ASSERT_DOUBLE_EQ(0.0l, tanl(0.0l));
+  ASSERT_DOUBLE_EQ(0.0L, tanl(0.0L));
 }
 
 TEST(math, acosh) {
@@ -402,7 +402,7 @@
 }
 
 TEST(math, acoshl) {
-  ASSERT_DOUBLE_EQ(0.0l, acoshl(1.0l));
+  ASSERT_DOUBLE_EQ(0.0L, acoshl(1.0L));
 }
 
 TEST(math, asinh) {
@@ -414,7 +414,7 @@
 }
 
 TEST(math, asinhl) {
-  ASSERT_DOUBLE_EQ(0.0l, asinhl(0.0l));
+  ASSERT_DOUBLE_EQ(0.0L, asinhl(0.0L));
 }
 
 TEST(math, atanh) {
@@ -426,7 +426,7 @@
 }
 
 TEST(math, atanhl) {
-  ASSERT_DOUBLE_EQ(0.0l, atanhl(0.0l));
+  ASSERT_DOUBLE_EQ(0.0L, atanhl(0.0L));
 }
 
 TEST(math, cosh) {
@@ -438,7 +438,7 @@
 }
 
 TEST(math, coshl) {
-  ASSERT_DOUBLE_EQ(1.0l, coshl(0.0l));
+  ASSERT_DOUBLE_EQ(1.0L, coshl(0.0L));
 }
 
 TEST(math, sinh) {
@@ -450,7 +450,7 @@
 }
 
 TEST(math, sinhl) {
-  ASSERT_DOUBLE_EQ(0.0l, sinhl(0.0l));
+  ASSERT_DOUBLE_EQ(0.0L, sinhl(0.0L));
 }
 
 TEST(math, tanh) {
@@ -462,7 +462,7 @@
 }
 
 TEST(math, tanhl) {
-  ASSERT_DOUBLE_EQ(0.0l, tanhl(0.0l));
+  ASSERT_DOUBLE_EQ(0.0L, tanhl(0.0L));
 }
 
 TEST(math, log) {
@@ -474,7 +474,7 @@
 }
 
 TEST(math, logl) {
-  ASSERT_DOUBLE_EQ(1.0l, logl(M_E));
+  ASSERT_DOUBLE_EQ(1.0L, logl(M_E));
 }
 
 TEST(math, log2) {
@@ -486,7 +486,7 @@
 }
 
 TEST(math, log2l) {
-  ASSERT_DOUBLE_EQ(12.0l, log2l(4096.0l));
+  ASSERT_DOUBLE_EQ(12.0L, log2l(4096.0L));
 }
 
 TEST(math, log10) {
@@ -498,7 +498,7 @@
 }
 
 TEST(math, log10l) {
-  ASSERT_DOUBLE_EQ(3.0l, log10l(1000.0l));
+  ASSERT_DOUBLE_EQ(3.0L, log10l(1000.0L));
 }
 
 TEST(math, cbrt) {
@@ -510,7 +510,7 @@
 }
 
 TEST(math, cbrtl) {
-  ASSERT_DOUBLE_EQ(3.0l, cbrtl(27.0l));
+  ASSERT_DOUBLE_EQ(3.0L, cbrtl(27.0L));
 }
 
 TEST(math, sqrt) {
@@ -522,7 +522,7 @@
 }
 
 TEST(math, sqrtl) {
-  ASSERT_DOUBLE_EQ(2.0l, sqrtl(4.0l));
+  ASSERT_DOUBLE_EQ(2.0L, sqrtl(4.0L));
 }
 
 TEST(math, exp) {
@@ -536,8 +536,8 @@
 }
 
 TEST(math, expl) {
-  ASSERT_DOUBLE_EQ(1.0l, expl(0.0l));
-  ASSERT_DOUBLE_EQ(M_E, expl(1.0l));
+  ASSERT_DOUBLE_EQ(1.0L, expl(0.0L));
+  ASSERT_DOUBLE_EQ(M_E, expl(1.0L));
 }
 
 TEST(math, exp2) {
@@ -549,7 +549,7 @@
 }
 
 TEST(math, exp2l) {
-  ASSERT_DOUBLE_EQ(8.0l, exp2l(3.0l));
+  ASSERT_DOUBLE_EQ(8.0L, exp2l(3.0L));
 }
 
 TEST(math, expm1) {
@@ -561,7 +561,7 @@
 }
 
 TEST(math, expm1l) {
-  ASSERT_DOUBLE_EQ(M_E - 1.0l, expm1l(1.0l));
+  ASSERT_DOUBLE_EQ(M_E - 1.0L, expm1l(1.0L));
 }
 
 TEST(math, pow) {
@@ -579,10 +579,10 @@
 }
 
 TEST(math, powl) {
-  ASSERT_TRUE(__isnanl(powl(nanl(""), 3.0l)));
-  ASSERT_DOUBLE_EQ(1.0l, (powl(1.0l, nanl(""))));
-  ASSERT_TRUE(__isnanl(powl(2.0l, nanl(""))));
-  ASSERT_DOUBLE_EQ(8.0l, powl(2.0l, 3.0l));
+  ASSERT_TRUE(__isnanl(powl(nanl(""), 3.0L)));
+  ASSERT_DOUBLE_EQ(1.0L, (powl(1.0L, nanl(""))));
+  ASSERT_TRUE(__isnanl(powl(2.0L, nanl(""))));
+  ASSERT_DOUBLE_EQ(8.0L, powl(2.0L, 3.0L));
 }
 
 TEST(math, ceil) {
@@ -594,7 +594,7 @@
 }
 
 TEST(math, ceill) {
-  ASSERT_DOUBLE_EQ(1.0, ceill(0.9l));
+  ASSERT_DOUBLE_EQ(1.0L, ceill(0.9L));
 }
 
 TEST(math, floor) {
@@ -606,7 +606,7 @@
 }
 
 TEST(math, floorl) {
-  ASSERT_DOUBLE_EQ(1.0l, floorl(1.1l));
+  ASSERT_DOUBLE_EQ(1.0L, floorl(1.1L));
 }
 
 TEST(math, fabs) {
@@ -618,7 +618,7 @@
 }
 
 TEST(math, fabsl) {
-  ASSERT_DOUBLE_EQ(1.0l, fabsl(-1.0l));
+  ASSERT_DOUBLE_EQ(1.0L, fabsl(-1.0L));
 }
 
 TEST(math, ldexp) {
@@ -630,7 +630,7 @@
 }
 
 TEST(math, ldexpl) {
-  ASSERT_DOUBLE_EQ(16.0l, ldexpl(2.0l, 3.0));
+  ASSERT_DOUBLE_EQ(16.0L, ldexpl(2.0L, 3.0));
 }
 
 TEST(math, fmod) {
@@ -642,7 +642,7 @@
 }
 
 TEST(math, fmodl) {
-  ASSERT_DOUBLE_EQ(2.0l, fmodl(12.0l, 10.0l));
+  ASSERT_DOUBLE_EQ(2.0L, fmodl(12.0L, 10.0L));
 }
 
 TEST(math, remainder) {
@@ -654,7 +654,7 @@
 }
 
 TEST(math, remainderl) {
-  ASSERT_DOUBLE_EQ(2.0l, remainderl(12.0l, 10.0l));
+  ASSERT_DOUBLE_EQ(2.0L, remainderl(12.0L, 10.0L));
 }
 
 TEST(math, drem) {
@@ -678,9 +678,9 @@
 }
 
 TEST(math, fmaxl) {
-  ASSERT_DOUBLE_EQ(12.0l, fmaxl(12.0l, 10.0l));
-  ASSERT_DOUBLE_EQ(12.0l, fmaxl(12.0l, nanl("")));
-  ASSERT_DOUBLE_EQ(12.0l, fmaxl(nanl(""), 12.0l));
+  ASSERT_DOUBLE_EQ(12.0L, fmaxl(12.0L, 10.0L));
+  ASSERT_DOUBLE_EQ(12.0L, fmaxl(12.0L, nanl("")));
+  ASSERT_DOUBLE_EQ(12.0L, fmaxl(nanl(""), 12.0L));
 }
 
 TEST(math, fmin) {
@@ -696,9 +696,9 @@
 }
 
 TEST(math, fminl) {
-  ASSERT_DOUBLE_EQ(10.0l, fminl(12.0l, 10.0l));
-  ASSERT_DOUBLE_EQ(12.0l, fminl(12.0l, nanl("")));
-  ASSERT_DOUBLE_EQ(12.0l, fminl(nanl(""), 12.0l));
+  ASSERT_DOUBLE_EQ(10.0L, fminl(12.0L, 10.0L));
+  ASSERT_DOUBLE_EQ(12.0L, fminl(12.0L, nanl("")));
+  ASSERT_DOUBLE_EQ(12.0L, fminl(nanl(""), 12.0L));
 }
 
 TEST(math, fma) {
@@ -710,7 +710,7 @@
 }
 
 TEST(math, fmal) {
-  ASSERT_DOUBLE_EQ(10.0l, fmal(2.0l, 3.0l, 4.0l));
+  ASSERT_DOUBLE_EQ(10.0L, fmal(2.0L, 3.0L, 4.0L));
 }
 
 TEST(math, hypot) {
@@ -722,7 +722,7 @@
 }
 
 TEST(math, hypotl) {
-  ASSERT_DOUBLE_EQ(5.0l, hypotl(3.0l, 4.0l));
+  ASSERT_DOUBLE_EQ(5.0L, hypotl(3.0L, 4.0L));
 }
 
 TEST(math, erf) {
@@ -734,7 +734,7 @@
 }
 
 TEST(math, erfl) {
-  ASSERT_DOUBLE_EQ(0.84270079294971489l, erfl(1.0l));
+  ASSERT_DOUBLE_EQ(0.84270079294971489L, erfl(1.0L));
 }
 
 TEST(math, erfc) {
@@ -746,27 +746,27 @@
 }
 
 TEST(math, erfcl) {
-  ASSERT_DOUBLE_EQ(0.15729920705028513l, erfcl(1.0l));
+  ASSERT_DOUBLE_EQ(0.15729920705028513l, erfcl(1.0L));
 }
 
 TEST(math, lrint) {
   fesetround(FE_UPWARD); // lrint/lrintf/lrintl obey the rounding mode.
   ASSERT_EQ(1235, lrint(1234.01));
   ASSERT_EQ(1235, lrintf(1234.01f));
-  ASSERT_EQ(1235, lrintl(1234.01l));
+  ASSERT_EQ(1235, lrintl(1234.01L));
   fesetround(FE_TOWARDZERO); // lrint/lrintf/lrintl obey the rounding mode.
   ASSERT_EQ(1234, lrint(1234.01));
   ASSERT_EQ(1234, lrintf(1234.01f));
-  ASSERT_EQ(1234, lrintl(1234.01l));
+  ASSERT_EQ(1234, lrintl(1234.01L));
 
   fesetround(FE_UPWARD); // llrint/llrintf/llrintl obey the rounding mode.
   ASSERT_EQ(1235L, llrint(1234.01));
   ASSERT_EQ(1235L, llrintf(1234.01f));
-  ASSERT_EQ(1235L, llrintl(1234.01l));
+  ASSERT_EQ(1235L, llrintl(1234.01L));
   fesetround(FE_TOWARDZERO); // llrint/llrintf/llrintl obey the rounding mode.
   ASSERT_EQ(1234L, llrint(1234.01));
   ASSERT_EQ(1234L, llrintf(1234.01f));
-  ASSERT_EQ(1234L, llrintl(1234.01l));
+  ASSERT_EQ(1234L, llrintl(1234.01L));
 }
 
 TEST(math, rint) {
@@ -784,15 +784,15 @@
   ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) != 0);
 
   feclearexcept(FE_ALL_EXCEPT); // rint/rintf/rintl do set the FE_INEXACT flag.
-  ASSERT_EQ(1234.0, rintl(1234.0l));
+  ASSERT_EQ(1234.0, rintl(1234.0L));
   ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
-  ASSERT_EQ(1235.0, rintl(1234.01l));
+  ASSERT_EQ(1235.0, rintl(1234.01L));
   ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) != 0);
 
   fesetround(FE_TOWARDZERO); // rint/rintf obey the rounding mode.
   ASSERT_EQ(1234.0, rint(1234.01));
   ASSERT_EQ(1234.0f, rintf(1234.01f));
-  ASSERT_EQ(1234.0, rintl(1234.01l));
+  ASSERT_EQ(1234.0, rintl(1234.01L));
 }
 
 TEST(math, nearbyint) {
@@ -810,29 +810,29 @@
   ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
 
   feclearexcept(FE_ALL_EXCEPT); // nearbyint/nearbyintf/nearbyintl don't set the FE_INEXACT flag.
-  ASSERT_EQ(1234.0, nearbyintl(1234.0l));
+  ASSERT_EQ(1234.0, nearbyintl(1234.0L));
   ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
-  ASSERT_EQ(1235.0, nearbyintl(1234.01l));
+  ASSERT_EQ(1235.0, nearbyintl(1234.01L));
   ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
 
   fesetround(FE_TOWARDZERO); // nearbyint/nearbyintf/nearbyintl obey the rounding mode.
   ASSERT_EQ(1234.0, nearbyint(1234.01));
   ASSERT_EQ(1234.0f, nearbyintf(1234.01f));
-  ASSERT_EQ(1234.0, nearbyintl(1234.01l));
+  ASSERT_EQ(1234.0, nearbyintl(1234.01L));
 }
 
 TEST(math, lround) {
   fesetround(FE_UPWARD); // lround ignores the rounding mode.
   ASSERT_EQ(1234, lround(1234.01));
   ASSERT_EQ(1234, lroundf(1234.01f));
-  ASSERT_EQ(1234, lroundl(1234.01l));
+  ASSERT_EQ(1234, lroundl(1234.01L));
 }
 
 TEST(math, llround) {
   fesetround(FE_UPWARD); // llround ignores the rounding mode.
   ASSERT_EQ(1234L, llround(1234.01));
   ASSERT_EQ(1234L, llroundf(1234.01f));
-  ASSERT_EQ(1234L, llroundl(1234.01l));
+  ASSERT_EQ(1234L, llroundl(1234.01L));
 }
 
 TEST(math, ilogb) {
@@ -852,11 +852,11 @@
 }
 
 TEST(math, ilogbl) {
-  ASSERT_EQ(FP_ILOGB0, ilogbl(0.0l));
+  ASSERT_EQ(FP_ILOGB0, ilogbl(0.0L));
   ASSERT_EQ(FP_ILOGBNAN, ilogbl(nanl("")));
   ASSERT_EQ(INT_MAX, ilogbl(HUGE_VALL));
-  ASSERT_EQ(0l, ilogbl(1.0l));
-  ASSERT_EQ(3l, ilogbl(10.0l));
+  ASSERT_EQ(0L, ilogbl(1.0L));
+  ASSERT_EQ(3L, ilogbl(10.0L));
 }
 
 TEST(math, logb) {
@@ -876,11 +876,11 @@
 }
 
 TEST(math, logbl) {
-  ASSERT_EQ(-HUGE_VAL, logbl(0.0l));
+  ASSERT_EQ(-HUGE_VAL, logbl(0.0L));
   ASSERT_TRUE(isnan(logbl(nanl(""))));
   ASSERT_TRUE(isinf(logbl(HUGE_VALL)));
-  ASSERT_EQ(0.0l, logbl(1.0l));
-  ASSERT_EQ(3.0l, logbl(10.0l));
+  ASSERT_EQ(0.0L, logbl(1.0L));
+  ASSERT_EQ(3.0L, logbl(10.0L));
 }
 
 TEST(math, log1p) {
@@ -898,10 +898,10 @@
 }
 
 TEST(math, log1pl) {
-  ASSERT_EQ(-HUGE_VALL, log1pl(-1.0l));
+  ASSERT_EQ(-HUGE_VALL, log1pl(-1.0L));
   ASSERT_TRUE(isnan(log1pl(nanl(""))));
   ASSERT_TRUE(isinf(log1pl(HUGE_VALL)));
-  ASSERT_DOUBLE_EQ(1.0l, log1pl(M_E - 1.0l));
+  ASSERT_DOUBLE_EQ(1.0L, log1pl(M_E - 1.0L));
 }
 
 TEST(math, fdim) {
@@ -917,9 +917,9 @@
 }
 
 TEST(math, fdiml) {
-  ASSERT_DOUBLE_EQ(0.0l, fdiml(1.0l, 1.0l));
-  ASSERT_DOUBLE_EQ(1.0l, fdiml(2.0l, 1.0l));
-  ASSERT_DOUBLE_EQ(0.0l, fdiml(1.0l, 2.0l));
+  ASSERT_DOUBLE_EQ(0.0L, fdiml(1.0L, 1.0L));
+  ASSERT_DOUBLE_EQ(1.0L, fdiml(2.0L, 1.0L));
+  ASSERT_DOUBLE_EQ(0.0L, fdiml(1.0L, 2.0L));
 }
 
 TEST(math, round) {
@@ -944,10 +944,10 @@
 
 TEST(math, roundl) {
   fesetround(FE_TOWARDZERO); // roundl ignores the rounding mode and always rounds away from zero.
-  ASSERT_DOUBLE_EQ(1.0l, roundl(0.5l));
-  ASSERT_DOUBLE_EQ(-1.0l, roundl(-0.5l));
-  ASSERT_DOUBLE_EQ(0.0l, roundl(0.0l));
-  ASSERT_DOUBLE_EQ(-0.0l, roundl(-0.0l));
+  ASSERT_DOUBLE_EQ(1.0L, roundl(0.5L));
+  ASSERT_DOUBLE_EQ(-1.0L, roundl(-0.5L));
+  ASSERT_DOUBLE_EQ(0.0L, roundl(0.0L));
+  ASSERT_DOUBLE_EQ(-0.0L, roundl(-0.0L));
   ASSERT_TRUE(isnan(roundl(nanl(""))));
   ASSERT_DOUBLE_EQ(HUGE_VALL, roundl(HUGE_VALL));
 }
@@ -974,10 +974,10 @@
 
 TEST(math, truncl) {
   fesetround(FE_UPWARD); // truncl ignores the rounding mode and always rounds toward zero.
-  ASSERT_DOUBLE_EQ(1.0l, truncl(1.5l));
-  ASSERT_DOUBLE_EQ(-1.0l, truncl(-1.5l));
-  ASSERT_DOUBLE_EQ(0.0l, truncl(0.0l));
-  ASSERT_DOUBLE_EQ(-0.0l, truncl(-0.0l));
+  ASSERT_DOUBLE_EQ(1.0L, truncl(1.5L));
+  ASSERT_DOUBLE_EQ(-1.0L, truncl(-1.5L));
+  ASSERT_DOUBLE_EQ(0.0L, truncl(0.0L));
+  ASSERT_DOUBLE_EQ(-0.0L, truncl(-0.0L));
   ASSERT_TRUE(isnan(truncl(nan(""))));
   ASSERT_DOUBLE_EQ(HUGE_VALL, truncl(HUGE_VALL));
 }
@@ -995,12 +995,12 @@
 }
 
 TEST(math, nextafterl) {
-  ASSERT_DOUBLE_EQ(0.0l, nextafterl(0.0l, 0.0l));
+  ASSERT_DOUBLE_EQ(0.0L, nextafterl(0.0L, 0.0L));
   // Use a runtime value to accomodate the case when
   // sizeof(double) == sizeof(long double)
-  long double smallest_positive = ldexpl(1.0l, LDBL_MIN_EXP - LDBL_MANT_DIG);
-  ASSERT_DOUBLE_EQ(smallest_positive, nextafterl(0.0l, 1.0l));
-  ASSERT_DOUBLE_EQ(0.0l, nextafterl(0.0l, -1.0l));
+  long double smallest_positive = ldexpl(1.0L, LDBL_MIN_EXP - LDBL_MANT_DIG);
+  ASSERT_DOUBLE_EQ(smallest_positive, nextafterl(0.0L, 1.0L));
+  ASSERT_DOUBLE_EQ(0.0L, nextafterl(0.0L, -1.0L));
 }
 
 // TODO: nexttoward
@@ -1022,10 +1022,10 @@
 }
 
 TEST(math, copysignl) {
-  ASSERT_DOUBLE_EQ(0.0l, copysignl(0.0l, 1.0l));
-  ASSERT_DOUBLE_EQ(-0.0l, copysignl(0.0l, -1.0l));
-  ASSERT_DOUBLE_EQ(2.0l, copysignl(2.0l, 1.0l));
-  ASSERT_DOUBLE_EQ(-2.0l, copysignl(2.0l, -1.0l));
+  ASSERT_DOUBLE_EQ(0.0L, copysignl(0.0L, 1.0L));
+  ASSERT_DOUBLE_EQ(-0.0L, copysignl(0.0L, -1.0L));
+  ASSERT_DOUBLE_EQ(2.0L, copysignl(2.0L, 1.0L));
+  ASSERT_DOUBLE_EQ(-2.0L, copysignl(2.0L, -1.0L));
 }
 
 TEST(math, significand) {
@@ -1043,9 +1043,9 @@
 extern "C" long double significandl(long double); // BSD's <math.h> doesn't declare this.
 
 TEST(math, significandl) {
-  ASSERT_DOUBLE_EQ(0.0l, significandl(0.0l));
-  ASSERT_DOUBLE_EQ(1.2l, significandl(1.2l));
-  ASSERT_DOUBLE_EQ(1.5375l, significandl(12.3l));
+  ASSERT_DOUBLE_EQ(0.0L, significandl(0.0L));
+  ASSERT_DOUBLE_EQ(1.2L, significandl(1.2L));
+  ASSERT_DOUBLE_EQ(1.5375L, significandl(12.3L));
 }
 
 TEST(math, scalb) {
@@ -1065,7 +1065,7 @@
 }
 
 TEST(math, scalblnl) {
-  ASSERT_DOUBLE_EQ(12.0l, scalblnl(3.0l, 2L));
+  ASSERT_DOUBLE_EQ(12.0L, scalblnl(3.0L, 2L));
 }
 
 TEST(math, scalbn) {
@@ -1077,7 +1077,7 @@
 }
 
 TEST(math, scalbnl) {
-  ASSERT_DOUBLE_EQ(12.0l, scalbnl(3.0l, 2));
+  ASSERT_DOUBLE_EQ(12.0L, scalbnl(3.0L, 2));
 }
 
 TEST(math, gamma) {
@@ -1117,7 +1117,7 @@
 }
 
 TEST(math, lgammal) {
-  ASSERT_DOUBLE_EQ(logl(24.0l), lgammal(5.0l));
+  ASSERT_DOUBLE_EQ(logl(24.0L), lgammal(5.0L));
 }
 
 TEST(math, lgamma_r) {
@@ -1141,7 +1141,7 @@
 }
 
 TEST(math, tgammal) {
-  ASSERT_DOUBLE_EQ(24.0l, tgammal(5.0l));
+  ASSERT_DOUBLE_EQ(24.0L, tgammal(5.0L));
 }
 
 TEST(math, j0) {
@@ -1218,42 +1218,29 @@
 
 TEST(math, frexpl) {
   int exp;
-  long double ldr = frexpl(1024.0l, &exp);
-  ASSERT_DOUBLE_EQ(1024.0l, scalbnl(ldr, exp));
+  long double ldr = frexpl(1024.0L, &exp);
+  ASSERT_DOUBLE_EQ(1024.0L, scalbnl(ldr, exp));
 }
 
 TEST(math, modf) {
   double di;
-  double df = modf(123.456, &di);
+  double df = modf(123.75, &di);
   ASSERT_DOUBLE_EQ(123.0, di);
-  // ASSERT_DOUBLE uses more decimals than the double precision when performing
-  // the comparison which can result in false failures. And it seems that modf
-  // results are not 100% precise as expected but within the acceptable delta.
-  // Work around this by tweaking the expected value (taken) from the result of
-  // glibc modf).
-  ASSERT_DOUBLE_EQ(0.45600000000000307, df);
+  ASSERT_DOUBLE_EQ(0.75, df);
 }
 
 TEST(math, modff) {
   float fi;
-  float ff = modff(123.456f, &fi);
+  float ff = modff(123.75f, &fi);
   ASSERT_FLOAT_EQ(123.0f, fi);
-  // See modf comment on why we don't use 0.456f as an excepted value.
-  ASSERT_FLOAT_EQ(0.45600128f, ff);
+  ASSERT_FLOAT_EQ(0.75f, ff);
 }
 
 TEST(math, modfl) {
   long double ldi;
-  long double ldf = modfl(123.456l, &ldi);
-  ASSERT_DOUBLE_EQ(123.0l, ldi);
-  // See modf comment on why we don't use 0.456l as an excepted value when the
-  // modf == modfl. For LP64, where long double != double, modfl algorithm
-  // gives precise results and thus we don't need to tweak the expected value.
-#if defined(__LP64__) || !defined(__BIONIC__)
-  ASSERT_DOUBLE_EQ(0.456l, ldf);
-#else
-  ASSERT_DOUBLE_EQ(0.45600000000000307, ldf);
-#endif // __LP64__ || !__BIONIC__
+  long double ldf = modfl(123.75L, &ldi);
+  ASSERT_DOUBLE_EQ(123.0L, ldi);
+  ASSERT_DOUBLE_EQ(0.75L, ldf);
 }
 
 TEST(math, remquo) {
@@ -1272,9 +1259,9 @@
 
 TEST(math, remquol) {
   int q;
-  long double ld = remquol(13.0l, 4.0l, &q);
-  ASSERT_DOUBLE_EQ(3l, q);
-  ASSERT_DOUBLE_EQ(1.0l, ld);
+  long double ld = remquol(13.0L, 4.0L, &q);
+  ASSERT_DOUBLE_EQ(3L, q);
+  ASSERT_DOUBLE_EQ(1.0L, ld);
 }
 
 // https://code.google.com/p/android/issues/detail?id=6697
diff --git a/tests/sys_select_test.cpp b/tests/sys_select_test.cpp
index 4bb2d18..c1732ee 100644
--- a/tests/sys_select_test.cpp
+++ b/tests/sys_select_test.cpp
@@ -20,6 +20,8 @@
 #include <signal.h>
 #include <stdlib.h>
 #include <sys/select.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 
 TEST(sys_select, fd_set_smoke) {
   fd_set fds;
@@ -43,6 +45,32 @@
   EXPECT_FALSE(FD_ISSET(1, &fds));
 }
 
+#define DELAY_MSG "1234"
+
+static void DelayedWrite(int* pid, int* fd) {
+  int fds[2];
+  ASSERT_EQ(0, pipe(fds));
+
+  if ((*pid = fork()) == 0) {
+    close(fds[0]);
+    usleep(5000);
+    EXPECT_EQ(5, write(fds[1], DELAY_MSG, sizeof(DELAY_MSG)));
+    close(fds[1]);
+    exit(0);
+  }
+  ASSERT_LT(0, *pid);
+  close(fds[1]);
+
+  *fd = fds[0];
+}
+
+static void DelayedWriteCleanup(int pid, int fd) {
+  char buf[sizeof(DELAY_MSG)];
+  ASSERT_EQ(static_cast<ssize_t>(sizeof(DELAY_MSG)), read(fd, buf, sizeof(DELAY_MSG)));
+  ASSERT_STREQ(DELAY_MSG, buf);
+  ASSERT_EQ(pid, waitpid(pid, NULL, 0));
+}
+
 TEST(sys_select, select_smoke) {
   fd_set r;
   FD_ZERO(&r);
@@ -72,8 +100,17 @@
 
   // Valid timeout...
   tv.tv_sec = 1;
-  ASSERT_EQ(2, select(max, &r, &w, &e, &tv));
-  ASSERT_NE(0, tv.tv_usec); // ...which got updated.
+  int pid, fd;
+  DelayedWrite(&pid, &fd);
+
+  FD_ZERO(&r);
+  FD_SET(fd, &r);
+  ASSERT_EQ(1, select(fd+1, &r, NULL, NULL, &tv));
+  // Both tv_sec and tv_nsec should have been updated.
+  ASSERT_EQ(0, tv.tv_sec);
+  ASSERT_NE(0, tv.tv_usec);
+
+  DelayedWriteCleanup(pid, fd);
 }
 
 TEST(sys_select, pselect_smoke) {
@@ -109,6 +146,15 @@
 
   // Valid timeout...
   tv.tv_sec = 1;
-  ASSERT_EQ(2, pselect(max, &r, &w, &e, &tv, &ss));
-  ASSERT_EQ(0, tv.tv_nsec); // ...which did _not_ get updated.
+  int pid, fd;
+  DelayedWrite(&pid, &fd);
+
+  FD_ZERO(&r);
+  FD_SET(fd, &r);
+  ASSERT_EQ(1, pselect(fd+1, &r, NULL, NULL, &tv, NULL));
+  // Neither tv_sec nor tv_nsec should have been updated.
+  ASSERT_EQ(1, tv.tv_sec);
+  ASSERT_EQ(0, tv.tv_nsec);
+
+  DelayedWriteCleanup(pid, fd);
 }