Mesa (main): Auto-enable TLSDESC support

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat Nov 20 18:20:07 UTC 2021


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

Author: Alex Xu (Hello71) <alex_y_xu at yahoo.ca>
Date:   Thu Sep  2 12:19:53 2021 -0400

Auto-enable TLSDESC support

TLSDESC speeds up access to dynamic TLS. This is especially important
for non-glibc targets, but is also helpful for non-initial-exec TLS
variables.

The entry asm does not support TLSDESC, but it only accesses
initial-exec symbols, so it is not necessary to handle that separately.

Acked-by: Tapani Pälli <tapani.palli at intel.com>
Acked-by: Jesse Natalie <jenatali at microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12722>

---

 meson.build | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/meson.build b/meson.build
index a7ace23677c..29f0c3f3912 100644
--- a/meson.build
+++ b/meson.build
@@ -520,6 +520,30 @@ if not with_platform_windows or not with_shared_glapi
     c_args += '-fno-emulated-tls'
     cpp_args += '-fno-emulated-tls'
   endif
+
+  # -mtls-dialect=gnu2 speeds up non-initial-exec TLS significantly but requires
+  # full toolchain (including libc) support.
+  have_mtls_dialect = false
+  foreach c_arg : get_option('c_args')
+    if c_arg.startswith('-mtls-dialect=')
+      have_mtls_dialect = true
+      break
+    endif
+  endforeach
+  if not have_mtls_dialect
+    # need .run to check libc support. meson aborts when calling .run when
+    # cross-compiling, but because this is just an optimization we can skip it
+    if meson.is_cross_build()
+      warning('cannot auto-detect -mtls-dialect when cross-compiling, using compiler default')
+    else
+      # -fpic to force dynamic tls, otherwise TLS relaxation defeats check
+      gnu2_test = cc.run('int __thread x; int main() { return x; }', args: ['-mtls-dialect=gnu2', '-fpic'], name: '-mtls-dialect=gnu2')
+      if gnu2_test.returncode() == 0
+        c_args += '-mtls-dialect=gnu2'
+        cpp_args += '-mtls-dialect=gnu2'
+      endif
+    endif
+  endif
 endif
 
 if with_glx != 'disabled'



More information about the mesa-commit mailing list