Merge "Allow device launched before Q to use legacy OEM AID value"
diff --git a/README.md b/README.md
index 5f78249..f81558a 100644
--- a/README.md
+++ b/README.md
@@ -193,10 +193,9 @@
 
 ## Updating tzdata
 
-This is fully automated (and these days handled by the libcore team, because
-they own icu, and that needs to be updated in sync with bionic):
-
-  1. Run update-tzdata.py in external/icu/tools/.
+This is handled by the libcore team, because they own icu, and that needs to be
+updated in sync with bionic). See
+[system/timezone/README.android](https://android.googlesource.com/platform/system/timezone/+/master/README.android).
 
 
 ## Verifying changes
diff --git a/benchmarks/run-on-host.sh b/benchmarks/run-on-host.sh
index af96b27..0f2aefb 100755
--- a/benchmarks/run-on-host.sh
+++ b/benchmarks/run-on-host.sh
@@ -25,7 +25,7 @@
             cd ${ANDROID_BUILD_TOP}
             export ANDROID_DATA=${TARGET_OUT_DATA}
             export ANDROID_ROOT=${TARGET_OUT}
-            ${NATIVETEST}/bionic-benchmarks/bionic-benchmarks $@
+            ${BENCHMARKS}/bionic-benchmarks/bionic-benchmarks $@
         )
     else
         echo "$0 not supported on TARGET_ARCH=$TARGET_ARCH"
diff --git a/build/run-on-host.sh b/build/run-on-host.sh
index c3a2751..85539e2 100644
--- a/build/run-on-host.sh
+++ b/build/run-on-host.sh
@@ -15,33 +15,36 @@
     BITS=$1
     shift
 
+    BENCHMARKS=${TARGET_OUT_DATA}/benchmarktest
     NATIVETEST=${TARGET_OUT_DATA}/nativetest
     if [ "${BITS}" = 64 ]; then
+        BENCHMARKS=${BENCHMARKS}64
         NATIVETEST=${NATIVETEST}64
     fi
 
-    if [ ${TARGET_ARCH} = arm -o ${TARGET_ARCH} = mips -o ${TARGET_ARCH} = x86 ]; then
-        LINKER=${TARGET_OUT_EXECUTABLES}/linker
-    else
-        LINKER="${TARGET_OUT_EXECUTABLES}/linker64 ${TARGET_OUT_EXECUTABLES}/linker"
-    fi
-
     if [ ${TARGET_ARCH} = x86 -o ${TARGET_ARCH} = x86_64 ]; then
-        m -j ${LINKER} ${TARGET_OUT}/etc/hosts ${TARGET_OUT_EXECUTABLES}/sh $@
+        m -j MODULES-IN-bionic MODULES-IN-external-icu MODULES-IN-external-mksh ${TARGET_OUT}/etc/hosts $@
 
         if [ ! -d /system ]; then
             echo "Attempting to create /system";
             sudo mkdir -p -m 0777 /system;
+            mkdir -p -m 0777 /system/bin;
+            mkdir -p -m 0777 /system/lib;
+            mkdir -p -m 0777 /system/lib64;
         fi
         (
             cd ${ANDROID_BUILD_TOP}
             mkdir -p ${TARGET_OUT_DATA}/local/tmp
-            ln -fs `realpath ${TARGET_OUT}/bin` /system/
+            for i in ${TARGET_OUT}/bin/bootstrap/* ${TARGET_OUT}/bin/*; do
+              ln -fs `realpath ${i}` /system/bin/
+            done
             ln -fs `realpath ${TARGET_OUT}/etc` /system/
-            ln -fs `realpath ${TARGET_OUT}/lib` /system/
-            if [ -d "${TARGET_OUT}/lib64" ]; then
-                ln -fs `realpath ${TARGET_OUT}/lib64` /system/;
-            fi
+            for i in ${TARGET_OUT}/lib/bootstrap/* ${TARGET_OUT}/lib/*; do
+              ln -fs `realpath ${i}` /system/lib/
+            done
+            for i in ${TARGET_OUT}/lib64/bootstrap/* ${TARGET_OUT}/lib64/*; do
+              ln -fs `realpath ${i}` /system/lib64/
+            done
         )
     fi
 }
diff --git a/libc/Android.bp b/libc/Android.bp
index 174783f..fa1eab6 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -1578,7 +1578,10 @@
         ],
     },
 
-    required: ["tzdata"],
+    required: [
+        "tzdata",
+        "tz_version", // Version metadata for tzdata to help debugging.
+    ],
 
     // Leave the symbols in the shared library so that stack unwinders can produce
     // meaningful name resolution.
diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp
index b229cda..1f099cf 100644
--- a/libc/bionic/libc_init_common.cpp
+++ b/libc/bionic/libc_init_common.cpp
@@ -232,6 +232,7 @@
     "LD_AOUT_LIBRARY_PATH",
     "LD_AOUT_PRELOAD",
     "LD_AUDIT",
+    "LD_CONFIG_FILE",
     "LD_DEBUG",
     "LD_DEBUG_OUTPUT",
     "LD_DYNAMIC_WEAK",
@@ -242,6 +243,7 @@
     "LD_SHOW_AUXV",
     "LD_USE_LOAD_BIAS",
     "LIBC_DEBUG_MALLOC_OPTIONS",
+    "LIBC_HOOKS_ENABLE",
     "LOCALDOMAIN",
     "LOCPATH",
     "MALLOC_CHECK_",
diff --git a/libc/bionic/pthread_getschedparam.cpp b/libc/bionic/pthread_getschedparam.cpp
index ed1853b..765287f 100644
--- a/libc/bionic/pthread_getschedparam.cpp
+++ b/libc/bionic/pthread_getschedparam.cpp
@@ -28,9 +28,11 @@
 
 #include <errno.h>
 
+#include "private/bionic_defs.h"
 #include "private/ErrnoRestorer.h"
 #include "pthread_internal.h"
 
+__BIONIC_WEAK_FOR_NATIVE_BRIDGE
 int pthread_getschedparam(pthread_t t, int* policy, sched_param* param) {
   ErrnoRestorer errno_restorer;
 
diff --git a/libc/bionic/pthread_setschedparam.cpp b/libc/bionic/pthread_setschedparam.cpp
index 8a02728..656fe32 100644
--- a/libc/bionic/pthread_setschedparam.cpp
+++ b/libc/bionic/pthread_setschedparam.cpp
@@ -30,9 +30,11 @@
 #include <pthread.h>
 #include <sched.h>
 
+#include "private/bionic_defs.h"
 #include "private/ErrnoRestorer.h"
 #include "pthread_internal.h"
 
+__BIONIC_WEAK_FOR_NATIVE_BRIDGE
 int pthread_setschedparam(pthread_t t, int policy, const sched_param* param) {
   ErrnoRestorer errno_restorer;
 
@@ -42,6 +44,7 @@
   return (sched_setscheduler(tid, policy, param) == -1) ? errno : 0;
 }
 
+__BIONIC_WEAK_FOR_NATIVE_BRIDGE
 int pthread_setschedprio(pthread_t t, int priority) {
   ErrnoRestorer errno_restorer;
 
diff --git a/libc/stdlib/atexit.c b/libc/stdlib/atexit.c
index bd6ac3d..692e0c0 100644
--- a/libc/stdlib/atexit.c
+++ b/libc/stdlib/atexit.c
@@ -186,7 +186,10 @@
 	}
 	_ATEXIT_UNLOCK();
 
-  fflush(NULL);
+	/* If called via exit(), flush output of all open files. */
+	if (dso == NULL) {
+		fflush(NULL);
+	}
 
   /* BEGIN android-changed: call __unregister_atfork if dso is not null */
   if (dso != NULL) {
diff --git a/tests/run-on-host.sh b/tests/run-on-host.sh
index c8a30f5..fe2c25a 100755
--- a/tests/run-on-host.sh
+++ b/tests/run-on-host.sh
@@ -20,6 +20,7 @@
 if [ ${HOST_OS}-${HOST_ARCH} = linux-x86 -o ${HOST_OS}-${HOST_ARCH} = linux-x86_64 ]; then
 
   prepare $1 bionic-unit-tests
+  shift
 
   if [ ${TARGET_ARCH} = x86 -o ${TARGET_ARCH} = x86_64 ]; then
     (