Merge "Revert "Add benchmarks that run simple programs""
diff --git a/benchmarks/Android.bp b/benchmarks/Android.bp
index 370e040..f2ab32a 100644
--- a/benchmarks/Android.bp
+++ b/benchmarks/Android.bp
@@ -40,6 +40,7 @@
         "string_benchmark.cpp",
         "time_benchmark.cpp",
         "unistd_benchmark.cpp",
+        "wctype_benchmark.cpp",
     ],
     shared_libs: ["liblog"],
     static_libs: [
diff --git a/benchmarks/run-on-host.sh b/benchmarks/run-on-host.sh
index 0f2aefb..89112ae 100755
--- a/benchmarks/run-on-host.sh
+++ b/benchmarks/run-on-host.sh
@@ -8,7 +8,7 @@
         cd ${ANDROID_BUILD_TOP}
         export ANDROID_DATA=${TARGET_OUT_DATA}
         export ANDROID_ROOT=${TARGET_OUT}
-        ${HOST_OUT}/nativetest64/bionic-benchmarks-glibc/bionic-benchmarks-glibc $@
+        ${HOST_OUT}/benchmarktest64/bionic-benchmarks-glibc/bionic-benchmarks-glibc "$@"
     )
     exit 0
 elif [ "$1" != 32 -a "$1" != 64 ]; then
@@ -25,7 +25,7 @@
             cd ${ANDROID_BUILD_TOP}
             export ANDROID_DATA=${TARGET_OUT_DATA}
             export ANDROID_ROOT=${TARGET_OUT}
-            ${BENCHMARKS}/bionic-benchmarks/bionic-benchmarks $@
+            ${BENCHMARKS}/bionic-benchmarks/bionic-benchmarks "$@"
         )
     else
         echo "$0 not supported on TARGET_ARCH=$TARGET_ARCH"
diff --git a/benchmarks/wctype_benchmark.cpp b/benchmarks/wctype_benchmark.cpp
new file mode 100644
index 0000000..f030ddc
--- /dev/null
+++ b/benchmarks/wctype_benchmark.cpp
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <wctype.h>
+
+#include <benchmark/benchmark.h>
+#include "util.h"
+
+static void BM_wctype_towlower_ascii_y(benchmark::State& state) {
+  for (auto _ : state) {
+    towlower('X');
+  }
+}
+BIONIC_BENCHMARK(BM_wctype_towlower_ascii_y);
+
+static void BM_wctype_towlower_ascii_n(benchmark::State& state) {
+  for (auto _ : state) {
+    towlower('x');
+  }
+}
+BIONIC_BENCHMARK(BM_wctype_towlower_ascii_n);
+
+static void BM_wctype_towlower_unicode_y(benchmark::State& state) {
+  for (auto _ : state) {
+    towlower(0x0391);
+  }
+}
+BIONIC_BENCHMARK(BM_wctype_towlower_unicode_y);
+
+static void BM_wctype_towlower_unicode_n(benchmark::State& state) {
+  for (auto _ : state) {
+    towlower(0x03b1);
+  }
+}
+BIONIC_BENCHMARK(BM_wctype_towlower_unicode_n);
+
+static void BM_wctype_towupper_ascii_y(benchmark::State& state) {
+  for (auto _ : state) {
+    towupper('x');
+  }
+}
+BIONIC_BENCHMARK(BM_wctype_towupper_ascii_y);
+
+static void BM_wctype_towupper_ascii_n(benchmark::State& state) {
+  for (auto _ : state) {
+    towupper('X');
+  }
+}
+BIONIC_BENCHMARK(BM_wctype_towupper_ascii_n);
+
+static void BM_wctype_towupper_unicode_y(benchmark::State& state) {
+  for (auto _ : state) {
+    towupper(0x03b1);
+  }
+}
+BIONIC_BENCHMARK(BM_wctype_towupper_unicode_y);
+
+static void BM_wctype_towupper_unicode_n(benchmark::State& state) {
+  for (auto _ : state) {
+    towupper(0x0391);
+  }
+}
+BIONIC_BENCHMARK(BM_wctype_towupper_unicode_n);
diff --git a/build/run-on-host.sh b/build/run-on-host.sh
index 85539e2..0ca3b1e 100644
--- a/build/run-on-host.sh
+++ b/build/run-on-host.sh
@@ -1,18 +1,21 @@
-#!/bin/bash -e
+# source this script in bash
 
 source ${ANDROID_BUILD_TOP}/build/envsetup.sh
 
-TARGET_ARCH=$(get_build_var TARGET_ARCH)
-TARGET_OUT=$(get_build_var TARGET_OUT)
-TARGET_OUT_EXECUTABLES=$(get_build_var TARGET_OUT_EXECUTABLES)
-TARGET_OUT_DATA=$(get_build_var TARGET_OUT_DATA)
-HOST_OS=$(get_build_var HOST_OS)
-HOST_ARCH=$(get_build_var HOST_ARCH)
-HOST_OUT=$(get_build_var HOST_OUT)
+# See envsetup.sh for an example of using --dumpvars-mode to set shell variables.
+eval "$(cd ${ANDROID_BUILD_TOP}; build/soong/soong_ui.bash --dumpvars-mode --vars="\
+    TARGET_ARCH \
+    TARGET_OUT \
+    TARGET_OUT_EXECUTABLES \
+    TARGET_OUT_DATA \
+    HOST_OS \
+    HOST_ARCH \
+    HOST_OUT \
+    ")"
 
 function prepare()
 {
-    BITS=$1
+    local BITS=$1
     shift
 
     BENCHMARKS=${TARGET_OUT_DATA}/benchmarktest
@@ -23,27 +26,36 @@
     fi
 
     if [ ${TARGET_ARCH} = x86 -o ${TARGET_ARCH} = x86_64 ]; then
-        m -j MODULES-IN-bionic MODULES-IN-external-icu MODULES-IN-external-mksh ${TARGET_OUT}/etc/hosts $@
+        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;
+            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
         (
+            function make_link() {
+                dir=$1
+                tgt=$2
+                name=`basename ${tgt}`
+                src=$dir/$name
+                if [ -e $tgt ]; then
+                    ln -sfT `realpath ${tgt}` $src
+                fi
+            }
             cd ${ANDROID_BUILD_TOP}
             mkdir -p ${TARGET_OUT_DATA}/local/tmp
             for i in ${TARGET_OUT}/bin/bootstrap/* ${TARGET_OUT}/bin/*; do
-              ln -fs `realpath ${i}` /system/bin/
+                make_link /system/bin ${i}
             done
             ln -fs `realpath ${TARGET_OUT}/etc` /system/
             for i in ${TARGET_OUT}/lib/bootstrap/* ${TARGET_OUT}/lib/*; do
-              ln -fs `realpath ${i}` /system/lib/
+                make_link /system/lib ${i}
             done
             for i in ${TARGET_OUT}/lib64/bootstrap/* ${TARGET_OUT}/lib64/*; do
-              ln -fs `realpath ${i}` /system/lib64/
+                make_link /system/lib64 ${i}
             done
         )
     fi
diff --git a/libc/bionic/pthread_getcpuclockid.cpp b/libc/bionic/pthread_getcpuclockid.cpp
index 0b35998..6d1884e 100644
--- a/libc/bionic/pthread_getcpuclockid.cpp
+++ b/libc/bionic/pthread_getcpuclockid.cpp
@@ -28,8 +28,10 @@
 
 #include <errno.h>
 
+#include "private/bionic_defs.h"
 #include "pthread_internal.h"
 
+__BIONIC_WEAK_FOR_NATIVE_BRIDGE
 int pthread_getcpuclockid(pthread_t t, clockid_t* clockid) {
   pid_t tid = __pthread_internal_gettid(t, "pthread_getcpuclockid");
   if (tid == -1) return ESRCH;
diff --git a/libc/bionic/pthread_kill.cpp b/libc/bionic/pthread_kill.cpp
index 8b38f4c..cada9c2 100644
--- a/libc/bionic/pthread_kill.cpp
+++ b/libc/bionic/pthread_kill.cpp
@@ -29,9 +29,11 @@
 #include <errno.h>
 #include <unistd.h>
 
+#include "private/bionic_defs.h"
 #include "private/ErrnoRestorer.h"
 #include "pthread_internal.h"
 
+__BIONIC_WEAK_FOR_NATIVE_BRIDGE
 int pthread_kill(pthread_t t, int sig) {
   ErrnoRestorer errno_restorer;
 
diff --git a/libc/bionic/pthread_setname_np.cpp b/libc/bionic/pthread_setname_np.cpp
index f673983..5236e4d 100644
--- a/libc/bionic/pthread_setname_np.cpp
+++ b/libc/bionic/pthread_setname_np.cpp
@@ -36,6 +36,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#include "private/bionic_defs.h"
 #include "private/ErrnoRestorer.h"
 #include "pthread_internal.h"
 
@@ -49,6 +50,7 @@
   return open(comm_name, O_CLOEXEC | flags);
 }
 
+__BIONIC_WEAK_FOR_NATIVE_BRIDGE
 int pthread_getname_np(pthread_t t, char* buf, size_t buf_size) {
   ErrnoRestorer errno_restorer;
 
@@ -80,6 +82,7 @@
   return 0;
 }
 
+__BIONIC_WEAK_FOR_NATIVE_BRIDGE
 int pthread_setname_np(pthread_t t, const char* thread_name) {
   ErrnoRestorer errno_restorer;
 
diff --git a/libc/bionic/pthread_sigqueue.cpp b/libc/bionic/pthread_sigqueue.cpp
index 5d13ed5..93c349e 100644
--- a/libc/bionic/pthread_sigqueue.cpp
+++ b/libc/bionic/pthread_sigqueue.cpp
@@ -32,9 +32,11 @@
 #include <sys/syscall.h>
 #include <unistd.h>
 
+#include "private/bionic_defs.h"
 #include "private/ErrnoRestorer.h"
 #include "pthread_internal.h"
 
+__BIONIC_WEAK_FOR_NATIVE_BRIDGE
 int pthread_sigqueue(pthread_t t, int sig, const union sigval value) {
   ErrnoRestorer errno_restorer;
 
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 9aa6480..37a3189 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -204,7 +204,6 @@
     "libsqlite.so",
     "libui.so",
     "libutils.so",
-    "libvorbisidec.so",
     nullptr
   };
 
@@ -4191,6 +4190,19 @@
     return kLdConfigVndkLiteFilePath;
   }
 
+  // Use generated linker config if flag is set
+  // TODO(b/138920271) Do not check property once it is confirmed as stable
+  // TODO(b/139638519) This file should also cover legacy or vndk-lite config
+  if (android::base::GetProperty("ro.vndk.version", "") != "" &&
+      android::base::GetBoolProperty("sys.linker.use_generated_config", true)) {
+    if (file_exists(kLdGeneratedConfigFilePath)) {
+      return kLdGeneratedConfigFilePath;
+    } else {
+      DL_WARN("Warning: failed to find generated linker configuration from \"%s\"",
+              kLdGeneratedConfigFilePath);
+    }
+  }
+
   std::string ld_config_file_vndk = kLdConfigFilePath;
   size_t insert_pos = ld_config_file_vndk.find_last_of('.');
   if (insert_pos == std::string::npos) {
@@ -4210,13 +4222,6 @@
   }
 #endif
 
-  // Use generated linker config if flag is set
-  // TODO(b/138920271) Do not check property once it is confirmed as stable
-  if (android::base::GetBoolProperty("sys.linker.use_generated_config", false) &&
-      file_exists(kLdGeneratedConfigFilePath)) {
-    return kLdGeneratedConfigFilePath;
-  }
-
   std::string path = get_ld_config_file_apex_path(executable_path);
   if (!path.empty()) {
     if (file_exists(path.c_str())) {