ART: Extend bionic TLS use to host bionic
Use __BIONIC__ instead of ART_TARGET_ANDROID for bionic TLS usage.
Bug: 138329277
Test: m test-art-host
Test: art/test/testrunner/run_build_test_target.py art-linux-bionic-x64
Change-Id: I7dc605c6700323303d9c9503d3aecc4fddef8d45
diff --git a/build/Android.bp b/build/Android.bp
index dd17a7c..9fec80c 100644
--- a/build/Android.bp
+++ b/build/Android.bp
@@ -132,6 +132,13 @@
"-Wmissing-noreturn",
],
},
+ linux_bionic: {
+ header_libs: [
+ // We optimize Thread::Current() with a direct TLS access. This requires access to a
+ // private Bionic header.
+ "bionic_libc_private_headers",
+ ],
+ },
darwin: {
enabled: false,
},
diff --git a/runtime/thread-current-inl.h b/runtime/thread-current-inl.h
index 9241b1f..787ec5b 100644
--- a/runtime/thread-current-inl.h
+++ b/runtime/thread-current-inl.h
@@ -19,7 +19,7 @@
#include "thread.h"
-#ifdef ART_TARGET_ANDROID
+#ifdef __BIONIC__
#include <bionic_tls.h> // Access to our own TLS slot.
#endif
@@ -33,7 +33,7 @@
if (!is_started_) {
return nullptr;
} else {
-#ifdef ART_TARGET_ANDROID
+#ifdef __BIONIC__
void* thread = __get_tls()[TLS_SLOT_ART_THREAD_SELF];
#else
void* thread = pthread_getspecific(Thread::pthread_key_self_);
diff --git a/runtime/thread.cc b/runtime/thread.cc
index 463023a..53450ba 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -933,7 +933,7 @@
interpreter::InitInterpreterTls(this);
}
-#ifdef ART_TARGET_ANDROID
+#ifdef __BIONIC__
__get_tls()[TLS_SLOT_ART_THREAD_SELF] = this;
#else
CHECK_PTHREAD_CALL(pthread_setspecific, (Thread::pthread_key_self_, this), "attach self");
@@ -2187,7 +2187,7 @@
LOG(WARNING) << "Native thread exiting without having called DetachCurrentThread (maybe it's "
"going to use a pthread_key_create destructor?): " << *self;
CHECK(is_started_);
-#ifdef ART_TARGET_ANDROID
+#ifdef __BIONIC__
__get_tls()[TLS_SLOT_ART_THREAD_SELF] = self;
#else
CHECK_PTHREAD_CALL(pthread_setspecific, (Thread::pthread_key_self_, self), "reattach self");
diff --git a/runtime/thread_list.cc b/runtime/thread_list.cc
index ed6b2c9..c971183 100644
--- a/runtime/thread_list.cc
+++ b/runtime/thread_list.cc
@@ -1481,7 +1481,7 @@
// Clear the TLS data, so that the underlying native thread is recognizably detached.
// (It may wish to reattach later.)
-#ifdef ART_TARGET_ANDROID
+#ifdef __BIONIC__
__get_tls()[TLS_SLOT_ART_THREAD_SELF] = nullptr;
#else
CHECK_PTHREAD_CALL(pthread_setspecific, (Thread::pthread_key_self_, nullptr), "detach self");