Mesa (main): android: Fix ELF TLS support.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jun 2 03:46:02 UTC 2021


Module: Mesa
Branch: main
Commit: 0d8e431871b0eeb98a6fa8afba2d76e9ecbce822
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=0d8e431871b0eeb98a6fa8afba2d76e9ecbce822

Author: Eric Anholt <eric at anholt.net>
Date:   Wed Apr 21 13:58:58 2021 -0700

android: Fix ELF TLS support.

Android 29 introduced general-dynamic TLS variable support ("quick
function call to look up the location of the dynamically allocated
storage"), while Mesa on normal Linux has used initial-exec ("use some of
the startup-time fixed slots, hope for the best!").  Both would be better
options than falling all the way back to pthread_getspecific(), which is
the alternative we have pre-29.

Reviewed-by: Roman Stratiienko <r.stratiienko at gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10389>

---

 meson.build         | 12 ++++++++++--
 src/util/u_thread.h |  9 +++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/meson.build b/meson.build
index cfe011f0ca4..00bf9cc1456 100644
--- a/meson.build
+++ b/meson.build
@@ -48,6 +48,8 @@ pre_args = [
   '-DPACKAGE_VERSION="@0@"'.format(meson.project_version()),
   '-DPACKAGE_BUGREPORT="https://gitlab.freedesktop.org/mesa/mesa/-/issues"',
 ]
+c_args = []
+cpp_args = []
 
 with_vulkan_icd_dir = get_option('vulkan-icd-dir')
 with_tests = get_option('build-tests')
@@ -454,6 +456,14 @@ if (not ['freebsd', 'openbsd', 'haiku'].contains(host_machine.system()) and
     (not with_platform_windows or not with_shared_glapi))
   pre_args += '-DUSE_ELF_TLS'
   use_elf_tls = true
+
+  if with_platform_android
+    # By default the NDK compiler, at least, emits emutls references instead of
+    # ELF TLS, even when building targeting newer API levels.  Make it actually do
+    # ELF TLS instead.
+    c_args += '-fno-emulated-tls'
+    cpp_args += '-fno-emulated-tls'
+  endif
 endif
 
 if with_glx != 'disabled'
@@ -1013,10 +1023,8 @@ elif host_machine.system() == 'openbsd'
 endif
 
 # Check for generic C arguments
-c_args = []
 c_msvc_compat_args = []
 no_override_init_args = []
-cpp_args = []
 cpp_msvc_compat_args = []
 if cc.get_id() == 'msvc'
   foreach a : ['/wd4018',  # signed/unsigned mismatch
diff --git a/src/util/u_thread.h b/src/util/u_thread.h
index e79d91ddff8..67383aefe66 100644
--- a/src/util/u_thread.h
+++ b/src/util/u_thread.h
@@ -77,6 +77,15 @@
  */
 #ifdef _MSC_VER
 #define __THREAD_INITIAL_EXEC __declspec(thread)
+#elif defined(ANDROID)
+/* Android 29 gained ELF TLS support, but it doesn't support initial-exec and
+ * it will throw:
+ *
+ *     dlopen failed: TLS symbol "(null)" in dlopened
+ *     "/vendor/lib64/egl/libEGL_mesa.so" referenced from
+ *     "/vendor/lib64/egl/libEGL_mesa.so" using IE access model.
+ */
+#define __THREAD_INITIAL_EXEC __thread
 #else
 #define __THREAD_INITIAL_EXEC __thread __attribute__((tls_model("initial-exec")))
 #endif



More information about the mesa-commit mailing list