Merge "Remove <sys/atomics.h>."
diff --git a/libc/Android.bp b/libc/Android.bp
index 9c521d1..416b1e5 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -70,16 +70,6 @@
     cppflags: [],
     include_dirs: ["external/jemalloc/include"],
 
-    arch: {
-        // b/25291096, Clang/llvm compiled libc.so for mips/mips64 failed to boot.
-        mips: {
-            clang: false,
-        },
-        mips64: {
-            clang: false,
-        },
-    },
-
     stl: "none",
     system_shared_libs: [],
     sanitize: {
@@ -1305,6 +1295,7 @@
         "bionic/lockf.cpp",
         "bionic/lstat.cpp",
         "bionic/malloc_info.cpp",
+        "bionic/mblen.cpp",
         "bionic/mbrtoc16.cpp",
         "bionic/mbrtoc32.cpp",
         "bionic/mbstate.cpp",
@@ -1692,7 +1683,9 @@
 
     // Leave the symbols in the shared library so that stack unwinders can produce
     // meaningful name resolution.
-    strip: "keep_symbols",
+    strip: {
+        keep_symbols: true,
+    },
 
     // WARNING: The only library libc.so should depend on is libdl.so!  If you add other libraries,
     // make sure to add -Wl,--exclude-libs=libgcc.a to the LOCAL_LDFLAGS for those libraries.  This
diff --git a/libc/bionic/ifaddrs.cpp b/libc/bionic/ifaddrs.cpp
index 408949c..f5b080c 100644
--- a/libc/bionic/ifaddrs.cpp
+++ b/libc/bionic/ifaddrs.cpp
@@ -59,7 +59,7 @@
   sockaddr_storage ifa_ifu;
   char name[IFNAMSIZ + 1];
 
-  ifaddrs_storage(ifaddrs** list) {
+  explicit ifaddrs_storage(ifaddrs** list) {
     memset(this, 0, sizeof(*this));
 
     // push_front onto `list`.
diff --git a/libc/bionic/libc_logging.cpp b/libc/bionic/libc_logging.cpp
index 6802944..517d047 100644
--- a/libc/bionic/libc_logging.cpp
+++ b/libc/bionic/libc_logging.cpp
@@ -107,7 +107,7 @@
 
 struct FdOutputStream {
  public:
-  FdOutputStream(int fd) : total(0), fd_(fd) {
+  explicit FdOutputStream(int fd) : total(0), fd_(fd) {
   }
 
   void Send(const char* data, int len) {
diff --git a/libc/bionic/locale.cpp b/libc/bionic/locale.cpp
index b42b440..f26a5f2 100644
--- a/libc/bionic/locale.cpp
+++ b/libc/bionic/locale.cpp
@@ -44,10 +44,10 @@
 struct __locale_t {
   size_t mb_cur_max;
 
-  __locale_t(size_t mb_cur_max) : mb_cur_max(mb_cur_max) {
+  explicit __locale_t(size_t mb_cur_max) : mb_cur_max(mb_cur_max) {
   }
 
-  __locale_t(const __locale_t* other) {
+  explicit __locale_t(const __locale_t* other) {
     if (other == LC_GLOBAL_LOCALE) {
       mb_cur_max = __bionic_current_locale_is_utf8 ? 4 : 1;
     } else {
diff --git a/libc/bionic/net_if.cpp b/libc/bionic/net_if.cpp
index f8d73bd..db9c9ea2 100644
--- a/libc/bionic/net_if.cpp
+++ b/libc/bionic/net_if.cpp
@@ -77,7 +77,7 @@
   if_list* next;
   struct if_nameindex data;
 
-  if_list(if_list** list) {
+  explicit if_list(if_list** list) {
     // push_front onto `list`.
     next = *list;
     *list = this;
diff --git a/libc/bionic/system_properties.cpp b/libc/bionic/system_properties.cpp
index 9c992da..0f68431 100644
--- a/libc/bionic/system_properties.cpp
+++ b/libc/bionic/system_properties.cpp
@@ -192,7 +192,7 @@
     const uint32_t n;
     const prop_info *pi;
 
-    find_nth_cookie(uint32_t n) : count(0), n(n), pi(NULL) {
+    explicit find_nth_cookie(uint32_t n) : count(0), n(n), pi(NULL) {
     }
 };
 
diff --git a/libc/include/machine/endian.h b/libc/include/machine/endian.h
deleted file mode 100644
index ac89519..0000000
--- a/libc/include/machine/endian.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef _MACHINE_ENDIAN_H_
-#define _MACHINE_ENDIAN_H_
-
-/* This file is for BSD source compatibility only. Use <endian.h> or <sys/endian.h> instead. */
-#include <sys/endian.h>
-
-#endif /* _MACHINE_ENDIAN_H_ */
diff --git a/libc/malloc_debug/Config.cpp b/libc/malloc_debug/Config.cpp
index cc60086..6220a23 100644
--- a/libc/malloc_debug/Config.cpp
+++ b/libc/malloc_debug/Config.cpp
@@ -84,7 +84,7 @@
 
 class PropertyParser {
  public:
-  PropertyParser(const char* property) : cur_(property) {}
+  explicit PropertyParser(const char* property) : cur_(property) {}
 
   bool Get(std::string* property, size_t* value, bool* value_set);
 
diff --git a/libc/malloc_debug/README.md b/libc/malloc_debug/README.md
index 3fc2305..d9eb782 100644
--- a/libc/malloc_debug/README.md
+++ b/libc/malloc_debug/README.md
@@ -8,22 +8,18 @@
 by adding a shim layer that replaces the normal allocation calls. The replaced
 calls are:
 
-<pre>
-malloc
-free
-calloc
-realloc
-posix_memalign
-memalign
-malloc_usable_size
-</pre>
+* `malloc`
+* `free`
+* `calloc`
+* `realloc`
+* `posix_memalign`
+* `memalign`
+* `malloc_usable_size`
 
 On 32 bit systems, these two deprecated functions are also replaced:
 
-<pre>
-pvalloc
-valloc
-</pre>
+* `pvalloc`
+* `valloc`
 
 Any errors detected by the library are reported in the log.
 
@@ -57,11 +53,9 @@
 
 Example error:
 
-<pre>
-04-10 12:00:45.621  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 SIZE 100 HAS A CORRUPTED FRONT GUARD
-04-10 12:00:45.622  7412  7412 E malloc_debug:   allocation[-32] = 0x00 (expected 0xaa)
-04-10 12:00:45.622  7412  7412 E malloc_debug:   allocation[-15] = 0x02 (expected 0xaa)
-</pre>
+    04-10 12:00:45.621  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 SIZE 100 HAS A CORRUPTED FRONT GUARD
+    04-10 12:00:45.622  7412  7412 E malloc_debug:   allocation[-32] = 0x00 (expected 0xaa)
+    04-10 12:00:45.622  7412  7412 E malloc_debug:   allocation[-15] = 0x02 (expected 0xaa)
 
 ### rear\_guard[=SIZE\_BYTES]
 Enables a small buffer placed after the allocated data. This is an attempt
@@ -79,11 +73,9 @@
 
 Example error:
 
-<pre>
-04-10 12:00:45.621  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 SIZE 100 HAS A CORRUPTED REAR GUARD
-04-10 12:00:45.622  7412  7412 E malloc_debug:   allocation[130] = 0xbf (expected 0xbb)
-04-10 12:00:45.622  7412  7412 E malloc_debug:   allocation[131] = 0x00 (expected 0xbb)
-</pre>
+    04-10 12:00:45.621  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 SIZE 100 HAS A CORRUPTED REAR GUARD
+    04-10 12:00:45.622  7412  7412 E malloc_debug:   allocation[130] = 0xbf (expected 0xbb)
+    04-10 12:00:45.622  7412  7412 E malloc_debug:   allocation[131] = 0x00 (expected 0xbb)
 
 ### guard[=SIZE\_BYTES]
 Enables both a front guard and a rear guard on all allocations.
@@ -173,25 +165,21 @@
 
 Example error:
 
-<pre>
-04-15 12:00:31.304  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 USED AFTER FREE
-04-15 12:00:31.305  7412  7412 E malloc_debug:   allocation[20] = 0xaf (expected 0xef)
-04-15 12:00:31.305  7412  7412 E malloc_debug:   allocation[99] = 0x12 (expected 0xef)
-04-15 12:00:31.305  7412  7412 E malloc_debug: Backtrace at time of free:
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
-</pre>
+    04-15 12:00:31.304  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 USED AFTER FREE
+    04-15 12:00:31.305  7412  7412 E malloc_debug:   allocation[20] = 0xaf (expected 0xef)
+    04-15 12:00:31.305  7412  7412 E malloc_debug:   allocation[99] = 0x12 (expected 0xef)
+    04-15 12:00:31.305  7412  7412 E malloc_debug: Backtrace at time of free:
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
 
 In addition, there is another type of error message that can occur if
 an allocation has a special header applied, and the header is corrupted
 before the verification occurs. This is the error message that will be found
 in the log:
 
-<pre>
-+++ ALLOCATION 0x12345678 HAS CORRUPTED HEADER TAG 0x1cc7dc00 AFTER FREE
-</pre>
+    04-15 12:00:31.604  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 HAS CORRUPTED HEADER TAG 0x1cc7dc00 AFTER FREE
 
 ### free\_track\_backtrace\_num\_frames[=MAX\_FRAMES]
 This option only has meaning if free\_track is set. It indicates how many
@@ -214,62 +202,54 @@
 
 Example leak error found in the log:
 
-<pre>
-04-15 12:35:33.304  7412  7412 E malloc_debug: +++ APP leaked block of size 100 at 0x2be3b0b0 (leak 1 of 2)
-04-15 12:35:33.304  7412  7412 E malloc_debug: Backtrace at time of allocation:
-04-15 12:35:33.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
-04-15 12:35:33.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
-04-15 12:35:33.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
-04-15 12:35:33.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
-04-15 12:35:33.305  7412  7412 E malloc_debug: +++ APP leaked block of size 24 at 0x7be32380 (leak 2 of 2)
-04-15 12:35:33.305  7412  7412 E malloc_debug: Backtrace at time of allocation:
-04-15 12:35:33.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
-04-15 12:35:33.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
-04-15 12:35:33.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
-04-15 12:35:33.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
-</pre>
+    04-15 12:35:33.304  7412  7412 E malloc_debug: +++ APP leaked block of size 100 at 0x2be3b0b0 (leak 1 of 2)
+    04-15 12:35:33.304  7412  7412 E malloc_debug: Backtrace at time of allocation:
+    04-15 12:35:33.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
+    04-15 12:35:33.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
+    04-15 12:35:33.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
+    04-15 12:35:33.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
+    04-15 12:35:33.305  7412  7412 E malloc_debug: +++ APP leaked block of size 24 at 0x7be32380 (leak 2 of 2)
+    04-15 12:35:33.305  7412  7412 E malloc_debug: Backtrace at time of allocation:
+    04-15 12:35:33.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
+    04-15 12:35:33.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
+    04-15 12:35:33.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
+    04-15 12:35:33.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
 
 Additional Errors
 -----------------
 There are a few other error messages that might appear in the log.
 
 ### Use After Free
-<pre>
-04-15 12:00:31.304  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 USED AFTER FREE (free)
-04-15 12:00:31.305  7412  7412 E malloc_debug: Backtrace of original free:
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
-04-15 12:00:31.305  7412  7412 E malloc_debug: Backtrace at time of failure:
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
-</pre>
+    04-15 12:00:31.304  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 USED AFTER FREE (free)
+    04-15 12:00:31.305  7412  7412 E malloc_debug: Backtrace of original free:
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug: Backtrace at time of failure:
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
 
 This indicates that code is attempting to free an already freed pointer. The
 name in parenthesis indicates that the application called the function
-<i>free</i> with the bad pointer.
+*free* with the bad pointer.
 
 For example, this message:
 
-<pre>
-04-15 12:00:31.304  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 USED AFTER FREE (realloc)
-</pre>
+    04-15 12:00:31.304  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 USED AFTER FREE (realloc)
 
-Would indicate that the application called the <i>realloc</i> function
+Would indicate that the application called the *realloc* function
 with an already freed pointer.
 
 ### Invalid Tag
-<pre>
-04-15 12:00:31.304  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 HAS INVALID TAG 1ee7d000 (malloc_usable_size)
-04-15 12:00:31.305  7412  7412 E malloc_debug: Backtrace at time of failure:
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
-04-15 12:00:31.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
-</pre>
+    04-15 12:00:31.304  7412  7412 E malloc_debug: +++ ALLOCATION 0x12345678 HAS INVALID TAG 1ee7d000 (malloc_usable_size)
+    04-15 12:00:31.305  7412  7412 E malloc_debug: Backtrace at time of failure:
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #00  pc 00029310  /system/lib/libc.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #01  pc 00021438  /system/lib/libc.so (newlocale+160)
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #02  pc 000a9e38  /system/lib/libc++.so
+    04-15 12:00:31.305  7412  7412 E malloc_debug:           #03  pc 000a28a8  /system/lib/libc++.so
 
 This indicates that a function (malloc\_usable\_size) was called with
 a pointer that is either not allocated memory, or that the memory of
@@ -282,36 +262,28 @@
 ========
 Enable backtrace tracking of all allocation for all processes:
 
-<pre>
-  adb shell stop
-  adb shell setprop libc.debug.malloc.options backtrace
-  adb shell start
-</pre>
+    adb shell stop
+    adb shell setprop libc.debug.malloc.options backtrace
+    adb shell start
 
 Enable backtrace tracking for a specific process (ls):
 
-<pre>
-  adb shell setprop libc.debug.malloc.options backtrace
-  adb shell setprop libc.debug.malloc.program ls
-  adb shell ls
-</pre>
+    adb shell setprop libc.debug.malloc.options backtrace
+    adb shell setprop libc.debug.malloc.program ls
+    adb shell ls
 
 Enable backtrace tracking for the zygote and zygote based processes:
 
-<pre>
-  adb shell stop
-  adb shell setprop libc.debug.malloc.program app_process
-  adb shell setprop libc.debug.malloc.options backtrace
-  adb shell start
-</pre>
+    adb shell stop
+    adb shell setprop libc.debug.malloc.program app_process
+    adb shell setprop libc.debug.malloc.options backtrace
+    adb shell start
 
 Enable multiple options (backtrace and guards):
 
-<pre>
-  adb shell stop
-  adb shell setprop libc.debug.malloc.options "\"backtrace guards\""
-  adb shell start
-</pre>
+    adb shell stop
+    adb shell setprop libc.debug.malloc.options "\"backtrace guards\""
+    adb shell start
 
 Enable malloc debug when multiple processes have the same name. This method
 can be used to enable malloc debug for only a very specific process if
@@ -321,10 +293,8 @@
 the setprop command will fail since the backtrace guards options will look
 like two arguments instead of one.
 
-<pre>
-  adb shell
-  # setprop libc.debug.malloc.env_enabled
-  # setprop libc.debug.malloc.options backtrace
-  # export LIBC_DEBUG_MALLOC_ENABLE 1
-  # ls
-</pre>
+    adb shell
+    # setprop libc.debug.malloc.env_enabled
+    # setprop libc.debug.malloc.options backtrace
+    # export LIBC_DEBUG_MALLOC_ENABLE 1
+    # ls
diff --git a/libc/malloc_debug/README_api.md b/libc/malloc_debug/README_api.md
index cd04c32..63ad42a 100644
--- a/libc/malloc_debug/README_api.md
+++ b/libc/malloc_debug/README_api.md
@@ -7,57 +7,47 @@
 
 The function to gather the data:
 
-<pre>
-<b>
-extern "C" void get_malloc_leak_info(uint8_t** info, size_t* overall_size, size_t* info_size, size_t* total_memory, size_t* backtrace_size);
-</b>
-</pre>
+`extern "C" void get_malloc_leak_info(uint8_t** info, size_t* overall_size, size_t* info_size, size_t* total_memory, size_t* backtrace_size);`
 
-<i>info</i> is set to a buffer allocated by the call that contains all of
+*info* is set to a buffer allocated by the call that contains all of
 the allocation information.
-<i>overall\_size</i> is set to the total size of the buffer returned. If this
-<i>info\_size</i>
+*overall\_size* is set to the total size of the buffer returned. If this
+*info\_size*
 value is zero, then there are no allocation being tracked.
-<i>total\_memory</i> is set to the sum of all allocation sizes that are live at
+*total\_memory* is set to the sum of all allocation sizes that are live at
 the point of the function call. This does not include the memory allocated
 by the malloc debug library itself.
-<i>backtrace\_size</i> is set to the maximum number of backtrace entries
+*backtrace\_size* is set to the maximum number of backtrace entries
 that are present for each allocation.
 
 In order to free the buffer allocated by the function, call:
 
-<pre>
-<b>
-extern "C" void free_malloc_leak_info(uint8_t* info);
-</b>
-</pre>
+`extern "C" void free_malloc_leak_info(uint8_t* info);`
 
 ### Format of info Buffer
-<pre>
-size_t size_of_original_allocation
-size_t num_backtrace_frames
-uintptr_t pc1
-uintptr_t pc2
-uintptr_t pc3
-.
-.
-.
-</pre>
+    size_t size_of_original_allocation
+    size_t num_backtrace_frames
+    uintptr_t pc1
+    uintptr_t pc2
+    uintptr_t pc3
+    .
+    .
+    .
 
-The number of <i>uintptr\_t</i> values is determined by the value
-<i>backtrace\_size</i> as returned by the original call to
-<i>get\_malloc\_leak\_info</i>. This value is not variable, it is the same
+The number of *uintptr\_t* values is determined by the value
+*backtrace\_size* as returned by the original call to
+*get\_malloc\_leak\_info*. This value is not variable, it is the same
 for all the returned data. The value
-<i>num\_backtrace\_frames</i> contains the real number of frames found. The
-extra frames are set to zero. Each <i>uintptr\_t</i> is a pc of the callstack.
+*num\_backtrace\_frames* contains the real number of frames found. The
+extra frames are set to zero. Each *uintptr\_t* is a pc of the callstack.
 The calls from within the malloc debug library are automatically removed.
 
-For 32 bit systems, <i>size\_t</i> and <i>uintptr\_t</i> are both 4 byte values.
+For 32 bit systems, *size\_t* and *uintptr\_t* are both 4 byte values.
 
-For 64 bit systems, <i>size\_t</i> and <i>uintptr\_t</i> are both 8 byte values.
+For 64 bit systems, *size\_t* and *uintptr\_t* are both 8 byte values.
 
-The total number of these structures returned in <i>info</i> is
-<i>overall\_size</i> divided by <i>info\_size</i>.
+The total number of these structures returned in *info* is
+*overall\_size* divided by *info\_size*.
 
 Note, the size value in each allocation data structure will have bit 31 set
 if this allocation was created by the Zygote process. This helps to distinguish
diff --git a/libc/stdio/stdio.cpp b/libc/stdio/stdio.cpp
index 1c31a27..5df1bb9 100644
--- a/libc/stdio/stdio.cpp
+++ b/libc/stdio/stdio.cpp
@@ -90,7 +90,7 @@
 
 class ScopedFileLock {
  public:
-  ScopedFileLock(FILE* fp) : fp_(fp) {
+  explicit ScopedFileLock(FILE* fp) : fp_(fp) {
     FLOCKFILE(fp_);
   }
   ~ScopedFileLock() {
diff --git a/libc/upstream-freebsd/android/include/machine/endian.h b/libc/upstream-freebsd/android/include/machine/endian.h
new file mode 100644
index 0000000..2dc4d83
--- /dev/null
+++ b/libc/upstream-freebsd/android/include/machine/endian.h
@@ -0,0 +1 @@
+#include <endian.h>
diff --git a/libm/Android.bp b/libm/Android.bp
index 27ea1c1..f3d2765 100644
--- a/libm/Android.bp
+++ b/libm/Android.bp
@@ -1,330 +1,285 @@
-// ANDROIDMK TRANSLATION ERROR: unsupported directive
+// ANDROIDMK TRANSLATION ERROR: unsupported conditional
 // ifneq ($(TARGET_USE_PRIVATE_LIBM),true)
 
 bionic_coverage = false
 
-libm_common_src_files = [
-    "upstream-freebsd/lib/msun/bsdsrc/b_exp.c",
-    "upstream-freebsd/lib/msun/bsdsrc/b_log.c",
-    "upstream-freebsd/lib/msun/bsdsrc/b_tgamma.c",
-    "upstream-freebsd/lib/msun/src/catrig.c",
-    "upstream-freebsd/lib/msun/src/catrigf.c",
-    "upstream-freebsd/lib/msun/src/e_acos.c",
-    "upstream-freebsd/lib/msun/src/e_acosf.c",
-    "upstream-freebsd/lib/msun/src/e_acosh.c",
-    "upstream-freebsd/lib/msun/src/e_acoshf.c",
-    "upstream-freebsd/lib/msun/src/e_asin.c",
-    "upstream-freebsd/lib/msun/src/e_asinf.c",
-    "upstream-freebsd/lib/msun/src/e_atan2.c",
-    "upstream-freebsd/lib/msun/src/e_atan2f.c",
-    "upstream-freebsd/lib/msun/src/e_atanh.c",
-    "upstream-freebsd/lib/msun/src/e_atanhf.c",
-    "upstream-freebsd/lib/msun/src/e_cosh.c",
-    "upstream-freebsd/lib/msun/src/e_coshf.c",
-    "upstream-freebsd/lib/msun/src/e_exp.c",
-    "upstream-freebsd/lib/msun/src/e_expf.c",
-    "upstream-freebsd/lib/msun/src/e_fmod.c",
-    "upstream-freebsd/lib/msun/src/e_fmodf.c",
-    "upstream-freebsd/lib/msun/src/e_gamma.c",
-    "upstream-freebsd/lib/msun/src/e_gammaf.c",
-    "upstream-freebsd/lib/msun/src/e_gammaf_r.c",
-    "upstream-freebsd/lib/msun/src/e_gamma_r.c",
-    "upstream-freebsd/lib/msun/src/e_hypot.c",
-    "upstream-freebsd/lib/msun/src/e_hypotf.c",
-    "upstream-freebsd/lib/msun/src/e_j0.c",
-    "upstream-freebsd/lib/msun/src/e_j0f.c",
-    "upstream-freebsd/lib/msun/src/e_j1.c",
-    "upstream-freebsd/lib/msun/src/e_j1f.c",
-    "upstream-freebsd/lib/msun/src/e_jn.c",
-    "upstream-freebsd/lib/msun/src/e_jnf.c",
-    "upstream-freebsd/lib/msun/src/e_lgamma.c",
-    "upstream-freebsd/lib/msun/src/e_lgammaf.c",
-    "upstream-freebsd/lib/msun/src/e_lgammaf_r.c",
-    "upstream-freebsd/lib/msun/src/e_lgamma_r.c",
-    "upstream-freebsd/lib/msun/src/e_log10.c",
-    "upstream-freebsd/lib/msun/src/e_log10f.c",
-    "upstream-freebsd/lib/msun/src/e_log2.c",
-    "upstream-freebsd/lib/msun/src/e_log2f.c",
-    "upstream-freebsd/lib/msun/src/e_log.c",
-    "upstream-freebsd/lib/msun/src/e_logf.c",
-    "upstream-freebsd/lib/msun/src/e_pow.c",
-    "upstream-freebsd/lib/msun/src/e_powf.c",
-    "upstream-freebsd/lib/msun/src/e_remainder.c",
-    "upstream-freebsd/lib/msun/src/e_remainderf.c",
-    "upstream-freebsd/lib/msun/src/e_rem_pio2.c",
-    "upstream-freebsd/lib/msun/src/e_rem_pio2f.c",
-    "upstream-freebsd/lib/msun/src/e_scalb.c",
-    "upstream-freebsd/lib/msun/src/e_scalbf.c",
-    "upstream-freebsd/lib/msun/src/e_sinh.c",
-    "upstream-freebsd/lib/msun/src/e_sinhf.c",
-    "upstream-freebsd/lib/msun/src/e_sqrt.c",
-    "upstream-freebsd/lib/msun/src/e_sqrtf.c",
-    "upstream-freebsd/lib/msun/src/imprecise.c",
-    "upstream-freebsd/lib/msun/src/k_cos.c",
-    "upstream-freebsd/lib/msun/src/k_cosf.c",
-    "upstream-freebsd/lib/msun/src/k_exp.c",
-    "upstream-freebsd/lib/msun/src/k_expf.c",
-    "upstream-freebsd/lib/msun/src/k_rem_pio2.c",
-    "upstream-freebsd/lib/msun/src/k_sin.c",
-    "upstream-freebsd/lib/msun/src/k_sinf.c",
-    "upstream-freebsd/lib/msun/src/k_tan.c",
-    "upstream-freebsd/lib/msun/src/k_tanf.c",
-    "upstream-freebsd/lib/msun/src/s_asinh.c",
-    "upstream-freebsd/lib/msun/src/s_asinhf.c",
-    "upstream-freebsd/lib/msun/src/s_atan.c",
-    "upstream-freebsd/lib/msun/src/s_atanf.c",
-    "upstream-freebsd/lib/msun/src/s_carg.c",
-    "upstream-freebsd/lib/msun/src/s_cargf.c",
-    "upstream-freebsd/lib/msun/src/s_cargl.c",
-    "upstream-freebsd/lib/msun/src/s_cbrt.c",
-    "upstream-freebsd/lib/msun/src/s_cbrtf.c",
-    "upstream-freebsd/lib/msun/src/s_ccosh.c",
-    "upstream-freebsd/lib/msun/src/s_ccoshf.c",
-    "upstream-freebsd/lib/msun/src/s_ceil.c",
-    "upstream-freebsd/lib/msun/src/s_ceilf.c",
-    "upstream-freebsd/lib/msun/src/s_cexp.c",
-    "upstream-freebsd/lib/msun/src/s_cexpf.c",
-    "upstream-freebsd/lib/msun/src/s_cimag.c",
-    "upstream-freebsd/lib/msun/src/s_cimagf.c",
-    "upstream-freebsd/lib/msun/src/s_cimagl.c",
-    "upstream-freebsd/lib/msun/src/s_conj.c",
-    "upstream-freebsd/lib/msun/src/s_conjf.c",
-    "upstream-freebsd/lib/msun/src/s_conjl.c",
-    "upstream-freebsd/lib/msun/src/s_copysign.c",
-    "upstream-freebsd/lib/msun/src/s_copysignf.c",
-    "upstream-freebsd/lib/msun/src/s_cos.c",
-    "upstream-freebsd/lib/msun/src/s_cosf.c",
-    "upstream-freebsd/lib/msun/src/s_cproj.c",
-    "upstream-freebsd/lib/msun/src/s_cprojf.c",
-    "upstream-freebsd/lib/msun/src/s_cprojl.c",
-    "upstream-freebsd/lib/msun/src/s_creal.c",
-    "upstream-freebsd/lib/msun/src/s_crealf.c",
-    "upstream-freebsd/lib/msun/src/s_creall.c",
-    "upstream-freebsd/lib/msun/src/s_csinh.c",
-    "upstream-freebsd/lib/msun/src/s_csinhf.c",
-    "upstream-freebsd/lib/msun/src/s_csqrt.c",
-    "upstream-freebsd/lib/msun/src/s_csqrtf.c",
-    "upstream-freebsd/lib/msun/src/s_csqrtl.c",
-    "upstream-freebsd/lib/msun/src/s_ctanh.c",
-    "upstream-freebsd/lib/msun/src/s_ctanhf.c",
-    "upstream-freebsd/lib/msun/src/s_erf.c",
-    "upstream-freebsd/lib/msun/src/s_erff.c",
-    "upstream-freebsd/lib/msun/src/s_exp2.c",
-    "upstream-freebsd/lib/msun/src/s_exp2f.c",
-    "upstream-freebsd/lib/msun/src/s_expm1.c",
-    "upstream-freebsd/lib/msun/src/s_expm1f.c",
-    "upstream-freebsd/lib/msun/src/s_fdim.c",
-    "upstream-freebsd/lib/msun/src/s_finite.c",
-    "upstream-freebsd/lib/msun/src/s_finitef.c",
-    "upstream-freebsd/lib/msun/src/s_floor.c",
-    "upstream-freebsd/lib/msun/src/s_floorf.c",
-    "upstream-freebsd/lib/msun/src/s_fma.c",
-    "upstream-freebsd/lib/msun/src/s_fmaf.c",
-    "upstream-freebsd/lib/msun/src/s_fmax.c",
-    "upstream-freebsd/lib/msun/src/s_fmaxf.c",
-    "upstream-freebsd/lib/msun/src/s_fmin.c",
-    "upstream-freebsd/lib/msun/src/s_fminf.c",
-    "upstream-freebsd/lib/msun/src/s_frexp.c",
-    "upstream-freebsd/lib/msun/src/s_frexpf.c",
-    "upstream-freebsd/lib/msun/src/s_ilogb.c",
-    "upstream-freebsd/lib/msun/src/s_ilogbf.c",
-    "upstream-freebsd/lib/msun/src/s_llrint.c",
-    "upstream-freebsd/lib/msun/src/s_llrintf.c",
-    "upstream-freebsd/lib/msun/src/s_llround.c",
-    "upstream-freebsd/lib/msun/src/s_llroundf.c",
-    "upstream-freebsd/lib/msun/src/s_log1p.c",
-    "upstream-freebsd/lib/msun/src/s_log1pf.c",
-    "upstream-freebsd/lib/msun/src/s_logb.c",
-    "upstream-freebsd/lib/msun/src/s_logbf.c",
-    "upstream-freebsd/lib/msun/src/s_lrint.c",
-    "upstream-freebsd/lib/msun/src/s_lrintf.c",
-    "upstream-freebsd/lib/msun/src/s_lround.c",
-    "upstream-freebsd/lib/msun/src/s_lroundf.c",
-    "upstream-freebsd/lib/msun/src/s_modf.c",
-    "upstream-freebsd/lib/msun/src/s_modff.c",
-    "upstream-freebsd/lib/msun/src/s_nan.c",
-    "upstream-freebsd/lib/msun/src/s_nearbyint.c",
-    "upstream-freebsd/lib/msun/src/s_nextafter.c",
-    "upstream-freebsd/lib/msun/src/s_nextafterf.c",
-    "upstream-freebsd/lib/msun/src/s_remquo.c",
-    "upstream-freebsd/lib/msun/src/s_remquof.c",
-    "upstream-freebsd/lib/msun/src/s_rint.c",
-    "upstream-freebsd/lib/msun/src/s_rintf.c",
-    "upstream-freebsd/lib/msun/src/s_round.c",
-    "upstream-freebsd/lib/msun/src/s_roundf.c",
-    "upstream-freebsd/lib/msun/src/s_scalbln.c",
-    "upstream-freebsd/lib/msun/src/s_scalbn.c",
-    "upstream-freebsd/lib/msun/src/s_scalbnf.c",
-    "upstream-freebsd/lib/msun/src/s_signgam.c",
-    "upstream-freebsd/lib/msun/src/s_significand.c",
-    "upstream-freebsd/lib/msun/src/s_significandf.c",
-    "upstream-freebsd/lib/msun/src/s_sin.c",
-    "upstream-freebsd/lib/msun/src/s_sinf.c",
-    "upstream-freebsd/lib/msun/src/s_tan.c",
-    "upstream-freebsd/lib/msun/src/s_tanf.c",
-    "upstream-freebsd/lib/msun/src/s_tanh.c",
-    "upstream-freebsd/lib/msun/src/s_tanhf.c",
-    "upstream-freebsd/lib/msun/src/s_tgammaf.c",
-    "upstream-freebsd/lib/msun/src/s_trunc.c",
-    "upstream-freebsd/lib/msun/src/s_truncf.c",
-    "upstream-freebsd/lib/msun/src/w_cabs.c",
-    "upstream-freebsd/lib/msun/src/w_cabsf.c",
-    "upstream-freebsd/lib/msun/src/w_cabsl.c",
-    "upstream-freebsd/lib/msun/src/w_drem.c",
-    "upstream-freebsd/lib/msun/src/w_dremf.c",
-
-    // The FreeBSD complex functions appear to be better, but they're incomplete.
-    // We take the FreeBSD implementations when they exist, but fill out the rest
-    // of <complex.h> from NetBSD...
-    "upstream-netbsd/lib/libm/complex/cacoshl.c",
-    "upstream-netbsd/lib/libm/complex/cacosl.c",
-    "upstream-netbsd/lib/libm/complex/casinhl.c",
-    "upstream-netbsd/lib/libm/complex/casinl.c",
-    "upstream-netbsd/lib/libm/complex/catanhl.c",
-    "upstream-netbsd/lib/libm/complex/catanl.c",
-    "upstream-netbsd/lib/libm/complex/ccoshl.c",
-    "upstream-netbsd/lib/libm/complex/ccosl.c",
-    "upstream-netbsd/lib/libm/complex/cephes_subrl.c",
-    "upstream-netbsd/lib/libm/complex/cexpl.c",
-    "upstream-netbsd/lib/libm/complex/clog.c",
-    "upstream-netbsd/lib/libm/complex/clogf.c",
-    "upstream-netbsd/lib/libm/complex/clogl.c",
-    "upstream-netbsd/lib/libm/complex/cpow.c",
-    "upstream-netbsd/lib/libm/complex/cpowf.c",
-    "upstream-netbsd/lib/libm/complex/cpowl.c",
-    "upstream-netbsd/lib/libm/complex/csinhl.c",
-    "upstream-netbsd/lib/libm/complex/csinl.c",
-    "upstream-netbsd/lib/libm/complex/ctanhl.c",
-    "upstream-netbsd/lib/libm/complex/ctanl.c",
-]
-
-libm_common_src_files += [
-    // TODO: this comes from from upstream's libc, not libm, but it's an
-    // implementation detail that should have hidden visibility, so it needs
-    // to be in whatever library the math code is in.
-    "digittoint.c",
-
-    // Functionality not in the BSDs.
-    "significandl.c",
-    "sincos.c",
-
-    // Modified versions of BSD code.
-    "signbit.c",
-
-    // Home-grown stuff.
-    "fabs.cpp",
-]
-
-libm_ld128_src_files = [
-    "upstream-freebsd/lib/msun/src/e_acosl.c",
-    "upstream-freebsd/lib/msun/src/e_acoshl.c",
-    "upstream-freebsd/lib/msun/src/e_asinl.c",
-    "upstream-freebsd/lib/msun/src/e_atan2l.c",
-    "upstream-freebsd/lib/msun/src/e_atanhl.c",
-    "upstream-freebsd/lib/msun/src/e_fmodl.c",
-    "upstream-freebsd/lib/msun/src/e_hypotl.c",
-    "upstream-freebsd/lib/msun/src/e_lgammal.c",
-    "upstream-freebsd/lib/msun/src/e_remainderl.c",
-    "upstream-freebsd/lib/msun/src/e_sqrtl.c",
-    "upstream-freebsd/lib/msun/src/s_asinhl.c",
-    "upstream-freebsd/lib/msun/src/s_atanl.c",
-    "upstream-freebsd/lib/msun/src/s_cbrtl.c",
-    "upstream-freebsd/lib/msun/src/s_ceill.c",
-    "upstream-freebsd/lib/msun/src/s_copysignl.c",
-    "upstream-freebsd/lib/msun/src/e_coshl.c",
-    "upstream-freebsd/lib/msun/src/s_cosl.c",
-    "upstream-freebsd/lib/msun/src/s_floorl.c",
-    "upstream-freebsd/lib/msun/src/s_fmal.c",
-    "upstream-freebsd/lib/msun/src/s_fmaxl.c",
-    "upstream-freebsd/lib/msun/src/s_fminl.c",
-    "upstream-freebsd/lib/msun/src/s_modfl.c",
-    "upstream-freebsd/lib/msun/src/s_frexpl.c",
-    "upstream-freebsd/lib/msun/src/s_ilogbl.c",
-    "upstream-freebsd/lib/msun/src/s_llrintl.c",
-    "upstream-freebsd/lib/msun/src/s_llroundl.c",
-    "upstream-freebsd/lib/msun/src/s_logbl.c",
-    "upstream-freebsd/lib/msun/src/s_lrintl.c",
-    "upstream-freebsd/lib/msun/src/s_lroundl.c",
-    "upstream-freebsd/lib/msun/src/s_nextafterl.c",
-    "upstream-freebsd/lib/msun/src/s_nexttoward.c",
-    "upstream-freebsd/lib/msun/src/s_nexttowardf.c",
-    "upstream-freebsd/lib/msun/src/s_remquol.c",
-    "upstream-freebsd/lib/msun/src/s_rintl.c",
-    "upstream-freebsd/lib/msun/src/s_roundl.c",
-    "upstream-freebsd/lib/msun/src/s_scalbnl.c",
-    "upstream-freebsd/lib/msun/src/e_sinhl.c",
-    "upstream-freebsd/lib/msun/src/s_sinl.c",
-    "upstream-freebsd/lib/msun/src/s_tanhl.c",
-    "upstream-freebsd/lib/msun/src/s_tanl.c",
-    "upstream-freebsd/lib/msun/src/s_truncl.c",
-]
-
-libm_ld128_src_files += [
-    "upstream-freebsd/lib/msun/ld128/invtrig.c",
-    "upstream-freebsd/lib/msun/ld128/e_lgammal_r.c",
-    "upstream-freebsd/lib/msun/ld128/k_cosl.c",
-    "upstream-freebsd/lib/msun/ld128/k_sinl.c",
-    "upstream-freebsd/lib/msun/ld128/k_tanl.c",
-    "upstream-freebsd/lib/msun/ld128/s_erfl.c",
-    "upstream-freebsd/lib/msun/ld128/s_exp2l.c",
-    "upstream-freebsd/lib/msun/ld128/s_expl.c",
-    "upstream-freebsd/lib/msun/ld128/s_logl.c",
-    "upstream-freebsd/lib/msun/ld128/s_nanl.c",
-]
-
-// TODO: re-enable i387/e_sqrtf.S for x86, and maybe others.
-
-libm_common_cflags = [
-    "-D__BIONIC_NO_MATH_INLINES",
-    "-DFLT_EVAL_METHOD=0",
-    "-include freebsd-compat.h",
-    "-Werror",
-    "-Wno-missing-braces",
-    "-Wno-parentheses",
-    "-Wno-sign-compare",
-    "-Wno-uninitialized",
-    "-Wno-unknown-pragmas",
-    "-fvisibility=hidden",
-]
-
-// Workaround the GCC "(long)fn -> lfn" optimization bug which will result in
-// self recursions for lrint, lrintf, and lrintl.
-// BUG: 14225968
-libm_common_cflags += [
-    "-fno-builtin-rint",
-    "-fno-builtin-rintf",
-    "-fno-builtin-rintl",
-]
-
-libm_common_local_includes = ["upstream-freebsd/lib/msun/src/"]
-
-libm_ld_local_includes = ["upstream-freebsd/lib/msun/ld128/"]
-
 //
 // libm.so and libm.a for target.
 //
 cc_library {
     name: "libm",
 
-    cflags: libm_common_cflags,
-    conlyflags: ["-std=gnu11"],
-    include_dirs: ["bionic/libc"],
-    local_include_dirs: libm_common_local_includes,
-    srcs: libm_common_src_files,
-    system_shared_libs: ["libc"],
+    srcs: [
+        "upstream-freebsd/lib/msun/bsdsrc/b_exp.c",
+        "upstream-freebsd/lib/msun/bsdsrc/b_log.c",
+        "upstream-freebsd/lib/msun/bsdsrc/b_tgamma.c",
+        "upstream-freebsd/lib/msun/src/catrig.c",
+        "upstream-freebsd/lib/msun/src/catrigf.c",
+        "upstream-freebsd/lib/msun/src/e_acos.c",
+        "upstream-freebsd/lib/msun/src/e_acosf.c",
+        "upstream-freebsd/lib/msun/src/e_acosh.c",
+        "upstream-freebsd/lib/msun/src/e_acoshf.c",
+        "upstream-freebsd/lib/msun/src/e_asin.c",
+        "upstream-freebsd/lib/msun/src/e_asinf.c",
+        "upstream-freebsd/lib/msun/src/e_atan2.c",
+        "upstream-freebsd/lib/msun/src/e_atan2f.c",
+        "upstream-freebsd/lib/msun/src/e_atanh.c",
+        "upstream-freebsd/lib/msun/src/e_atanhf.c",
+        "upstream-freebsd/lib/msun/src/e_cosh.c",
+        "upstream-freebsd/lib/msun/src/e_coshf.c",
+        "upstream-freebsd/lib/msun/src/e_exp.c",
+        "upstream-freebsd/lib/msun/src/e_expf.c",
+        "upstream-freebsd/lib/msun/src/e_fmod.c",
+        "upstream-freebsd/lib/msun/src/e_fmodf.c",
+        "upstream-freebsd/lib/msun/src/e_gamma.c",
+        "upstream-freebsd/lib/msun/src/e_gammaf.c",
+        "upstream-freebsd/lib/msun/src/e_gammaf_r.c",
+        "upstream-freebsd/lib/msun/src/e_gamma_r.c",
+        "upstream-freebsd/lib/msun/src/e_hypot.c",
+        "upstream-freebsd/lib/msun/src/e_hypotf.c",
+        "upstream-freebsd/lib/msun/src/e_j0.c",
+        "upstream-freebsd/lib/msun/src/e_j0f.c",
+        "upstream-freebsd/lib/msun/src/e_j1.c",
+        "upstream-freebsd/lib/msun/src/e_j1f.c",
+        "upstream-freebsd/lib/msun/src/e_jn.c",
+        "upstream-freebsd/lib/msun/src/e_jnf.c",
+        "upstream-freebsd/lib/msun/src/e_lgamma.c",
+        "upstream-freebsd/lib/msun/src/e_lgammaf.c",
+        "upstream-freebsd/lib/msun/src/e_lgammaf_r.c",
+        "upstream-freebsd/lib/msun/src/e_lgamma_r.c",
+        "upstream-freebsd/lib/msun/src/e_log10.c",
+        "upstream-freebsd/lib/msun/src/e_log10f.c",
+        "upstream-freebsd/lib/msun/src/e_log2.c",
+        "upstream-freebsd/lib/msun/src/e_log2f.c",
+        "upstream-freebsd/lib/msun/src/e_log.c",
+        "upstream-freebsd/lib/msun/src/e_logf.c",
+        "upstream-freebsd/lib/msun/src/e_pow.c",
+        "upstream-freebsd/lib/msun/src/e_powf.c",
+        "upstream-freebsd/lib/msun/src/e_remainder.c",
+        "upstream-freebsd/lib/msun/src/e_remainderf.c",
+        "upstream-freebsd/lib/msun/src/e_rem_pio2.c",
+        "upstream-freebsd/lib/msun/src/e_rem_pio2f.c",
+        "upstream-freebsd/lib/msun/src/e_scalb.c",
+        "upstream-freebsd/lib/msun/src/e_scalbf.c",
+        "upstream-freebsd/lib/msun/src/e_sinh.c",
+        "upstream-freebsd/lib/msun/src/e_sinhf.c",
+        "upstream-freebsd/lib/msun/src/e_sqrt.c",
+        "upstream-freebsd/lib/msun/src/e_sqrtf.c",
+        "upstream-freebsd/lib/msun/src/imprecise.c",
+        "upstream-freebsd/lib/msun/src/k_cos.c",
+        "upstream-freebsd/lib/msun/src/k_cosf.c",
+        "upstream-freebsd/lib/msun/src/k_exp.c",
+        "upstream-freebsd/lib/msun/src/k_expf.c",
+        "upstream-freebsd/lib/msun/src/k_rem_pio2.c",
+        "upstream-freebsd/lib/msun/src/k_sin.c",
+        "upstream-freebsd/lib/msun/src/k_sinf.c",
+        "upstream-freebsd/lib/msun/src/k_tan.c",
+        "upstream-freebsd/lib/msun/src/k_tanf.c",
+        "upstream-freebsd/lib/msun/src/s_asinh.c",
+        "upstream-freebsd/lib/msun/src/s_asinhf.c",
+        "upstream-freebsd/lib/msun/src/s_atan.c",
+        "upstream-freebsd/lib/msun/src/s_atanf.c",
+        "upstream-freebsd/lib/msun/src/s_carg.c",
+        "upstream-freebsd/lib/msun/src/s_cargf.c",
+        "upstream-freebsd/lib/msun/src/s_cargl.c",
+        "upstream-freebsd/lib/msun/src/s_cbrt.c",
+        "upstream-freebsd/lib/msun/src/s_cbrtf.c",
+        "upstream-freebsd/lib/msun/src/s_ccosh.c",
+        "upstream-freebsd/lib/msun/src/s_ccoshf.c",
+        "upstream-freebsd/lib/msun/src/s_ceil.c",
+        "upstream-freebsd/lib/msun/src/s_ceilf.c",
+        "upstream-freebsd/lib/msun/src/s_cexp.c",
+        "upstream-freebsd/lib/msun/src/s_cexpf.c",
+        "upstream-freebsd/lib/msun/src/s_cimag.c",
+        "upstream-freebsd/lib/msun/src/s_cimagf.c",
+        "upstream-freebsd/lib/msun/src/s_cimagl.c",
+        "upstream-freebsd/lib/msun/src/s_conj.c",
+        "upstream-freebsd/lib/msun/src/s_conjf.c",
+        "upstream-freebsd/lib/msun/src/s_conjl.c",
+        "upstream-freebsd/lib/msun/src/s_copysign.c",
+        "upstream-freebsd/lib/msun/src/s_copysignf.c",
+        "upstream-freebsd/lib/msun/src/s_cos.c",
+        "upstream-freebsd/lib/msun/src/s_cosf.c",
+        "upstream-freebsd/lib/msun/src/s_cproj.c",
+        "upstream-freebsd/lib/msun/src/s_cprojf.c",
+        "upstream-freebsd/lib/msun/src/s_cprojl.c",
+        "upstream-freebsd/lib/msun/src/s_creal.c",
+        "upstream-freebsd/lib/msun/src/s_crealf.c",
+        "upstream-freebsd/lib/msun/src/s_creall.c",
+        "upstream-freebsd/lib/msun/src/s_csinh.c",
+        "upstream-freebsd/lib/msun/src/s_csinhf.c",
+        "upstream-freebsd/lib/msun/src/s_csqrt.c",
+        "upstream-freebsd/lib/msun/src/s_csqrtf.c",
+        "upstream-freebsd/lib/msun/src/s_csqrtl.c",
+        "upstream-freebsd/lib/msun/src/s_ctanh.c",
+        "upstream-freebsd/lib/msun/src/s_ctanhf.c",
+        "upstream-freebsd/lib/msun/src/s_erf.c",
+        "upstream-freebsd/lib/msun/src/s_erff.c",
+        "upstream-freebsd/lib/msun/src/s_exp2.c",
+        "upstream-freebsd/lib/msun/src/s_exp2f.c",
+        "upstream-freebsd/lib/msun/src/s_expm1.c",
+        "upstream-freebsd/lib/msun/src/s_expm1f.c",
+        "upstream-freebsd/lib/msun/src/s_fdim.c",
+        "upstream-freebsd/lib/msun/src/s_finite.c",
+        "upstream-freebsd/lib/msun/src/s_finitef.c",
+        "upstream-freebsd/lib/msun/src/s_floor.c",
+        "upstream-freebsd/lib/msun/src/s_floorf.c",
+        "upstream-freebsd/lib/msun/src/s_fma.c",
+        "upstream-freebsd/lib/msun/src/s_fmaf.c",
+        "upstream-freebsd/lib/msun/src/s_fmax.c",
+        "upstream-freebsd/lib/msun/src/s_fmaxf.c",
+        "upstream-freebsd/lib/msun/src/s_fmin.c",
+        "upstream-freebsd/lib/msun/src/s_fminf.c",
+        "upstream-freebsd/lib/msun/src/s_frexp.c",
+        "upstream-freebsd/lib/msun/src/s_frexpf.c",
+        "upstream-freebsd/lib/msun/src/s_ilogb.c",
+        "upstream-freebsd/lib/msun/src/s_ilogbf.c",
+        "upstream-freebsd/lib/msun/src/s_llrint.c",
+        "upstream-freebsd/lib/msun/src/s_llrintf.c",
+        "upstream-freebsd/lib/msun/src/s_llround.c",
+        "upstream-freebsd/lib/msun/src/s_llroundf.c",
+        "upstream-freebsd/lib/msun/src/s_log1p.c",
+        "upstream-freebsd/lib/msun/src/s_log1pf.c",
+        "upstream-freebsd/lib/msun/src/s_logb.c",
+        "upstream-freebsd/lib/msun/src/s_logbf.c",
+        "upstream-freebsd/lib/msun/src/s_lrint.c",
+        "upstream-freebsd/lib/msun/src/s_lrintf.c",
+        "upstream-freebsd/lib/msun/src/s_lround.c",
+        "upstream-freebsd/lib/msun/src/s_lroundf.c",
+        "upstream-freebsd/lib/msun/src/s_modf.c",
+        "upstream-freebsd/lib/msun/src/s_modff.c",
+        "upstream-freebsd/lib/msun/src/s_nan.c",
+        "upstream-freebsd/lib/msun/src/s_nearbyint.c",
+        "upstream-freebsd/lib/msun/src/s_nextafter.c",
+        "upstream-freebsd/lib/msun/src/s_nextafterf.c",
+        "upstream-freebsd/lib/msun/src/s_remquo.c",
+        "upstream-freebsd/lib/msun/src/s_remquof.c",
+        "upstream-freebsd/lib/msun/src/s_rint.c",
+        "upstream-freebsd/lib/msun/src/s_rintf.c",
+        "upstream-freebsd/lib/msun/src/s_round.c",
+        "upstream-freebsd/lib/msun/src/s_roundf.c",
+        "upstream-freebsd/lib/msun/src/s_scalbln.c",
+        "upstream-freebsd/lib/msun/src/s_scalbn.c",
+        "upstream-freebsd/lib/msun/src/s_scalbnf.c",
+        "upstream-freebsd/lib/msun/src/s_signgam.c",
+        "upstream-freebsd/lib/msun/src/s_significand.c",
+        "upstream-freebsd/lib/msun/src/s_significandf.c",
+        "upstream-freebsd/lib/msun/src/s_sin.c",
+        "upstream-freebsd/lib/msun/src/s_sinf.c",
+        "upstream-freebsd/lib/msun/src/s_tan.c",
+        "upstream-freebsd/lib/msun/src/s_tanf.c",
+        "upstream-freebsd/lib/msun/src/s_tanh.c",
+        "upstream-freebsd/lib/msun/src/s_tanhf.c",
+        "upstream-freebsd/lib/msun/src/s_tgammaf.c",
+        "upstream-freebsd/lib/msun/src/s_trunc.c",
+        "upstream-freebsd/lib/msun/src/s_truncf.c",
+        "upstream-freebsd/lib/msun/src/w_cabs.c",
+        "upstream-freebsd/lib/msun/src/w_cabsf.c",
+        "upstream-freebsd/lib/msun/src/w_cabsl.c",
+        "upstream-freebsd/lib/msun/src/w_drem.c",
+        "upstream-freebsd/lib/msun/src/w_dremf.c",
 
-    native_coverage: bionic_coverage,
-    sanitize: {
-        never: true,
-    },
+        // The FreeBSD complex functions appear to be better, but they're incomplete.
+        // We take the FreeBSD implementations when they exist, but fill out the rest
+        // of <complex.h> from NetBSD...
+        "upstream-netbsd/lib/libm/complex/cacoshl.c",
+        "upstream-netbsd/lib/libm/complex/cacosl.c",
+        "upstream-netbsd/lib/libm/complex/casinhl.c",
+        "upstream-netbsd/lib/libm/complex/casinl.c",
+        "upstream-netbsd/lib/libm/complex/catanhl.c",
+        "upstream-netbsd/lib/libm/complex/catanl.c",
+        "upstream-netbsd/lib/libm/complex/ccoshl.c",
+        "upstream-netbsd/lib/libm/complex/ccosl.c",
+        "upstream-netbsd/lib/libm/complex/cephes_subrl.c",
+        "upstream-netbsd/lib/libm/complex/cexpl.c",
+        "upstream-netbsd/lib/libm/complex/clog.c",
+        "upstream-netbsd/lib/libm/complex/clogf.c",
+        "upstream-netbsd/lib/libm/complex/clogl.c",
+        "upstream-netbsd/lib/libm/complex/cpow.c",
+        "upstream-netbsd/lib/libm/complex/cpowf.c",
+        "upstream-netbsd/lib/libm/complex/cpowl.c",
+        "upstream-netbsd/lib/libm/complex/csinhl.c",
+        "upstream-netbsd/lib/libm/complex/csinl.c",
+        "upstream-netbsd/lib/libm/complex/ctanhl.c",
+        "upstream-netbsd/lib/libm/complex/ctanl.c",
+
+        // TODO: this comes from from upstream's libc, not libm, but it's an
+        // implementation detail that should have hidden visibility, so it needs
+        // to be in whatever library the math code is in.
+        "digittoint.c",
+
+        // Functionality not in the BSDs.
+        "significandl.c",
+        "sincos.c",
+
+        // Modified versions of BSD code.
+        "signbit.c",
+
+        // Home-grown stuff.
+        "fabs.cpp",
+    ],
 
     multilib: {
         lib32: {
             srcs: ["fake_long_double.c"],
         },
+
         lib64: {
-            srcs: libm_ld128_src_files,
-            local_include_dirs: libm_ld_local_includes,
+            srcs: [
+                "upstream-freebsd/lib/msun/src/e_acosl.c",
+                "upstream-freebsd/lib/msun/src/e_acoshl.c",
+                "upstream-freebsd/lib/msun/src/e_asinl.c",
+                "upstream-freebsd/lib/msun/src/e_atan2l.c",
+                "upstream-freebsd/lib/msun/src/e_atanhl.c",
+                "upstream-freebsd/lib/msun/src/e_fmodl.c",
+                "upstream-freebsd/lib/msun/src/e_hypotl.c",
+                "upstream-freebsd/lib/msun/src/e_lgammal.c",
+                "upstream-freebsd/lib/msun/src/e_remainderl.c",
+                "upstream-freebsd/lib/msun/src/e_sqrtl.c",
+                "upstream-freebsd/lib/msun/src/s_asinhl.c",
+                "upstream-freebsd/lib/msun/src/s_atanl.c",
+                "upstream-freebsd/lib/msun/src/s_cbrtl.c",
+                "upstream-freebsd/lib/msun/src/s_ceill.c",
+                "upstream-freebsd/lib/msun/src/s_copysignl.c",
+                "upstream-freebsd/lib/msun/src/e_coshl.c",
+                "upstream-freebsd/lib/msun/src/s_cosl.c",
+                "upstream-freebsd/lib/msun/src/s_floorl.c",
+                "upstream-freebsd/lib/msun/src/s_fmal.c",
+                "upstream-freebsd/lib/msun/src/s_fmaxl.c",
+                "upstream-freebsd/lib/msun/src/s_fminl.c",
+                "upstream-freebsd/lib/msun/src/s_modfl.c",
+                "upstream-freebsd/lib/msun/src/s_frexpl.c",
+                "upstream-freebsd/lib/msun/src/s_ilogbl.c",
+                "upstream-freebsd/lib/msun/src/s_llrintl.c",
+                "upstream-freebsd/lib/msun/src/s_llroundl.c",
+                "upstream-freebsd/lib/msun/src/s_logbl.c",
+                "upstream-freebsd/lib/msun/src/s_lrintl.c",
+                "upstream-freebsd/lib/msun/src/s_lroundl.c",
+                "upstream-freebsd/lib/msun/src/s_nextafterl.c",
+                "upstream-freebsd/lib/msun/src/s_nexttoward.c",
+                "upstream-freebsd/lib/msun/src/s_nexttowardf.c",
+                "upstream-freebsd/lib/msun/src/s_remquol.c",
+                "upstream-freebsd/lib/msun/src/s_rintl.c",
+                "upstream-freebsd/lib/msun/src/s_roundl.c",
+                "upstream-freebsd/lib/msun/src/s_scalbnl.c",
+                "upstream-freebsd/lib/msun/src/e_sinhl.c",
+                "upstream-freebsd/lib/msun/src/s_sinl.c",
+                "upstream-freebsd/lib/msun/src/s_tanhl.c",
+                "upstream-freebsd/lib/msun/src/s_tanl.c",
+                "upstream-freebsd/lib/msun/src/s_truncl.c",
+
+                "upstream-freebsd/lib/msun/ld128/invtrig.c",
+                "upstream-freebsd/lib/msun/ld128/e_lgammal_r.c",
+                "upstream-freebsd/lib/msun/ld128/k_cosl.c",
+                "upstream-freebsd/lib/msun/ld128/k_sinl.c",
+                "upstream-freebsd/lib/msun/ld128/k_tanl.c",
+                "upstream-freebsd/lib/msun/ld128/s_erfl.c",
+                "upstream-freebsd/lib/msun/ld128/s_exp2l.c",
+                "upstream-freebsd/lib/msun/ld128/s_expl.c",
+                "upstream-freebsd/lib/msun/ld128/s_logl.c",
+                "upstream-freebsd/lib/msun/ld128/s_nanl.c",
+            ],
+            local_include_dirs: ["upstream-freebsd/lib/msun/ld128/"],
             // We'd really like to do this for all architectures, but since this wasn't done
             // before, these symbols must continue to be exported on LP32 for binary
             // compatibility.
@@ -343,6 +298,7 @@
                     "arm/sqrt.S",
                     "arm/floor.S",
                 ],
+
                 exclude_srcs: [
                     "upstream-freebsd/lib/msun/src/e_sqrt.c",
                     "upstream-freebsd/lib/msun/src/e_sqrtf.c",
@@ -554,8 +510,41 @@
         },
     },
 
+    local_include_dirs: [
+        "upstream-freebsd/android/include/",
+        "upstream-freebsd/lib/msun/src/",
+    ],
+
+    cflags: [
+        "-D__BIONIC_NO_MATH_INLINES",
+        "-DFLT_EVAL_METHOD=0",
+        "-include freebsd-compat.h",
+        "-Werror",
+        "-Wno-missing-braces",
+        "-Wno-parentheses",
+        "-Wno-sign-compare",
+        "-Wno-uninitialized",
+        "-Wno-unknown-pragmas",
+        "-fvisibility=hidden",
+
+        // Workaround the GCC "(long)fn -> lfn" optimization bug which will result in
+        // self recursions for lrint, lrintf, and lrintl.
+        // BUG: 14225968
+        "-fno-builtin-rint",
+        "-fno-builtin-rintf",
+        "-fno-builtin-rintl",
+    ],
+    conlyflags: ["-std=gnu11"],
+
+    include_dirs: ["bionic/libc"],
+    system_shared_libs: ["libc"],
+
+    native_coverage: bionic_coverage,
+    sanitize: {
+        never: true,
+    },
     stl: "none",
 }
 
-// ANDROIDMK TRANSLATION ERROR: unsupported directive
+// ANDROIDMK TRANSLATION ERROR: endif from unsupported contitional
 // endif
diff --git a/libm/Android.mk b/libm/Android.mk
index 7200e5f..b07e426 100644
--- a/libm/Android.mk
+++ b/libm/Android.mk
@@ -507,7 +507,10 @@
 
 LOCAL_C_INCLUDES_x86 += $(LOCAL_PATH)/i387
 
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/upstream-freebsd/lib/msun/src/
+LOCAL_C_INCLUDES += \
+    $(LOCAL_PATH)/upstream-freebsd/android/include/ \
+    $(LOCAL_PATH)/upstream-freebsd/lib/msun/src/ \
+
 LOCAL_C_INCLUDES_64 += $(LOCAL_PATH)/upstream-freebsd/lib/msun/ld128/
 
 LOCAL_ARM_MODE := arm
diff --git a/libm/upstream-freebsd/android/include/machine/endian.h b/libm/upstream-freebsd/android/include/machine/endian.h
new file mode 100644
index 0000000..2dc4d83
--- /dev/null
+++ b/libm/upstream-freebsd/android/include/machine/endian.h
@@ -0,0 +1 @@
+#include <endian.h>
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index 589cab4..d9b2523 100755
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -926,7 +926,7 @@
   pthread_rwlock_t lock;
 
  public:
-  RwlockKindTestHelper(int kind_type) {
+  explicit RwlockKindTestHelper(int kind_type) {
     InitRwlock(kind_type);
   }
 
@@ -1539,7 +1539,7 @@
 struct PthreadMutex {
   pthread_mutex_t lock;
 
-  PthreadMutex(int mutex_type) {
+  explicit PthreadMutex(int mutex_type) {
     init(mutex_type);
   }
 
@@ -1640,7 +1640,7 @@
   }
 
  public:
-  MutexWakeupHelper(int mutex_type) : m(mutex_type) {
+  explicit MutexWakeupHelper(int mutex_type) : m(mutex_type) {
   }
 
   void test() {
diff --git a/tests/search_test.cpp b/tests/search_test.cpp
index 3900c89..d368f9f 100644
--- a/tests/search_test.cpp
+++ b/tests/search_test.cpp
@@ -49,7 +49,7 @@
 }
 
 struct node {
-  node(const char* s) : s(strdup(s)) {}
+  explicit node(const char* s) : s(strdup(s)) {}
 
   char* s;
 };
@@ -115,7 +115,7 @@
 }
 
 struct pod_node {
-  pod_node(int i) : i(i) {}
+  explicit pod_node(int i) : i(i) {}
   int i;
 };
 
@@ -136,7 +136,7 @@
 }
 
 struct q_node {
-  q_node(int i) : i(i) {}
+  explicit q_node(int i) : i(i) {}
 
   q_node* next;
   q_node* prev;
diff --git a/tests/string_test.cpp b/tests/string_test.cpp
index 4b2cca2..2a9da10 100644
--- a/tests/string_test.cpp
+++ b/tests/string_test.cpp
@@ -163,7 +163,7 @@
 template<class Character>
 class StringTestState {
  public:
-  StringTestState(size_t MAX_LEN) : MAX_LEN(MAX_LEN), align1_index_(0), align2_index_(0) {
+  explicit StringTestState(size_t MAX_LEN) : MAX_LEN(MAX_LEN), align1_index_(0), align2_index_(0) {
     int max_alignment = 64;
 
     // TODO: fix the tests to not sometimes use twice their specified "MAX_LEN".
diff --git a/tests/sys_ptrace_test.cpp b/tests/sys_ptrace_test.cpp
index bd84d30..9071acf 100644
--- a/tests/sys_ptrace_test.cpp
+++ b/tests/sys_ptrace_test.cpp
@@ -59,7 +59,7 @@
 
 class ChildGuard {
  public:
-  ChildGuard(pid_t pid) : pid(pid) {}
+  explicit ChildGuard(pid_t pid) : pid(pid) {}
 
   ~ChildGuard() {
     kill(pid, SIGKILL);
diff --git a/tests/time_test.cpp b/tests/time_test.cpp
index b1f6364..10399c5 100644
--- a/tests/time_test.cpp
+++ b/tests/time_test.cpp
@@ -273,7 +273,7 @@
   }
 
  public:
-  Counter(void (*fn)(sigval_t)) : value(0), timer_valid(false) {
+  explicit Counter(void (*fn)(sigval_t)) : value(0), timer_valid(false) {
     memset(&se, 0, sizeof(se));
     se.sigev_notify = SIGEV_THREAD;
     se.sigev_notify_function = fn;