Merge "Find tzdata in the runtime module before /system"
diff --git a/libc/Android.bp b/libc/Android.bp
index c34cd85..0098d07 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -1478,6 +1478,39 @@
     name: "libc_malloc",
 }
 
+filegroup {
+    name: "libc_sources_shared",
+    srcs: [
+        "arch-common/bionic/crtbegin_so.c",
+        "arch-common/bionic/crtbrand.S",
+        "bionic/icu.cpp",
+        "bionic/malloc_common.cpp",
+        "bionic/NetdClient.cpp",
+        "arch-common/bionic/crtend_so.S",
+    ],
+}
+
+filegroup {
+    name: "libc_sources_static",
+    srcs: [
+        "bionic/dl_iterate_phdr_static.cpp",
+        "bionic/malloc_common.cpp",
+    ],
+}
+
+filegroup {
+    name: "libc_sources_shared_arm",
+    srcs: [
+        "arch-arm/bionic/exidx_dynamic.c",
+        "arch-arm/bionic/atexit_legacy.c",
+    ],
+}
+
+filegroup {
+    name: "libc_sources_static_arm",
+    srcs: [ "arch-arm/bionic/exidx_static.c" ],
+}
+
 // ========================================================
 // libc.a + libc.so
 // ========================================================
@@ -1492,10 +1525,7 @@
         },
     },
     static: {
-        srcs: [
-            "bionic/dl_iterate_phdr_static.cpp",
-            "bionic/malloc_common.cpp",
-        ],
+        srcs: [ ":libc_sources_static" ],
         cflags: ["-DLIBC_STATIC"],
         whole_static_libs: [
             "libc_init_static",
@@ -1503,14 +1533,7 @@
         ],
     },
     shared: {
-        srcs: [
-            "arch-common/bionic/crtbegin_so.c",
-            "arch-common/bionic/crtbrand.S",
-            "bionic/icu.cpp",
-            "bionic/malloc_common.cpp",
-            "bionic/NetdClient.cpp",
-            "arch-common/bionic/crtend_so.S",
-        ],
+        srcs: [ ":libc_sources_shared" ],
         whole_static_libs: [
             "libc_init_dynamic",
             "libc_common_shared",
@@ -1556,17 +1579,12 @@
             version_script: "libc.arm.map",
 
             shared: {
-                srcs: [
-                    "arch-arm/bionic/exidx_dynamic.c",
-
-                    // special for arm
-                    "arch-arm/bionic/atexit_legacy.c",
-                ],
+                srcs: [":libc_sources_shared_arm"],
                 // special for arm
                 cflags: ["-DCRT_LEGACY_WORKAROUND"],
             },
             static: {
-                srcs: ["arch-arm/bionic/exidx_static.c"],
+                srcs: [":libc_sources_static_arm"],
             },
         },
         arm64: {
diff --git a/libc/bionic/pthread_internal.h b/libc/bionic/pthread_internal.h
index 5a5318d..2ebd2b4 100644
--- a/libc/bionic/pthread_internal.h
+++ b/libc/bionic/pthread_internal.h
@@ -139,6 +139,7 @@
    * The dynamic linker implements dlerror(3), which makes it hard for us to implement this
    * per-thread buffer by simply using malloc(3) and free(3).
    */
+  char* current_dlerror;
 #define __BIONIC_DLERROR_BUFFER_SIZE 512
   char dlerror_buffer[__BIONIC_DLERROR_BUFFER_SIZE];
 
diff --git a/libc/include/paths.h b/libc/include/paths.h
index dc1c523..b5b8610 100644
--- a/libc/include/paths.h
+++ b/libc/include/paths.h
@@ -47,7 +47,7 @@
 #define _PATH_CONSOLE "/dev/console"
 
 /** Default shell search path. */
-#define _PATH_DEFPATH "/sbin:/system/sbin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin"
+#define _PATH_DEFPATH "/sbin:/system/sbin:/apex/com.android.runtime/bin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin"
 
 /** Path to the directory containing device files. */
 #define _PATH_DEV "/dev/"
diff --git a/libc/private/bionic_tls.h b/libc/private/bionic_tls.h
index 80dc9bc..36e3d7b 100644
--- a/libc/private/bionic_tls.h
+++ b/libc/private/bionic_tls.h
@@ -64,14 +64,15 @@
   TLS_SLOT_OPENGL = 4,
 
   TLS_SLOT_STACK_GUARD = 5, // GCC requires this specific slot for x86.
-  TLS_SLOT_DLERROR,
+
+  // TLS slot 6 was used for dlerror but is now free.
 
   // Fast storage for Thread::Current() in ART.
-  TLS_SLOT_ART_THREAD_SELF,
+  TLS_SLOT_ART_THREAD_SELF = 7,
 
   // Lets TSAN avoid using pthread_getspecific for finding the current thread
   // state.
-  TLS_SLOT_TSAN,
+  TLS_SLOT_TSAN = 8,
 
   BIONIC_TLS_SLOTS // Must come last!
 };
diff --git a/linker/dlfcn.cpp b/linker/dlfcn.cpp
index 5ae7b9b..5a47272 100644
--- a/linker/dlfcn.cpp
+++ b/linker/dlfcn.cpp
@@ -96,10 +96,9 @@
 static pthread_mutex_t g_dl_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
 
 static char* __bionic_set_dlerror(char* new_value) {
-  char** dlerror_slot = &reinterpret_cast<char**>(__get_tls())[TLS_SLOT_DLERROR];
+  char* old_value = __get_thread()->current_dlerror;
+  __get_thread()->current_dlerror = new_value;
 
-  char* old_value = *dlerror_slot;
-  *dlerror_slot = new_value;
   if (new_value != nullptr) LD_LOG(kLogErrors, "dlerror set to \"%s\"", new_value);
   return old_value;
 }