From cc2dbb8ea5329b509d79eedb6c0cbb9a1903b5ad Mon Sep 17 00:00:00 2001 From: WANG Xuerui Date: Sat, 10 Aug 2024 18:38:47 +0800 Subject: [PATCH] meson: Additionally probe -mtls-dialect=desc for TLSDESC support Previously only `-mtls-dialect=gnu2` was probed, which was appropriate for arm, x86 and x86_64, but not for newer architectures such as aarch64, loongarch64 and riscv64 which all use `-mtls-dialect=desc` instead. Because the driver option is not consistent across architectures (and probably will not), try both variants and choose the first one working. While at it, rename "gnu2_*" variables to "tlsdesc_*" respectively, for clarity. Cc: mesa-stable Reviewed-by: Icenowy Zheng Reviewed-by: Yukari Chiba Reviewed-by: David Heidelberg Signed-off-by: WANG Xuerui Part-of: --- meson.build | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/meson.build b/meson.build index f716a9e8179..3d72bb56f25 100644 --- a/meson.build +++ b/meson.build @@ -502,22 +502,28 @@ if not have_mtls_dialect if meson.is_cross_build() and not meson.can_run_host_binaries() 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 and ( - # check for lld 13 bug: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5665 - host_machine.cpu_family() != 'x86_64' or - # get_linker_id misses LDFLAGS=-fuse-ld=lld: https://github.com/mesonbuild/meson/issues/6377 - #cc.get_linker_id() != 'ld.lld' or - cc.links('''int __thread x; int y; int main() { __asm__( - "leaq x@TLSDESC(%rip), %rax\n" - "movq y@GOTPCREL(%rip), %rdx\n" - "call *x@TLSCALL(%rax)\n"); }''', name: 'split TLSDESC') - ) - c_cpp_args += '-mtls-dialect=gnu2' - endif + # The way to specify the TLSDESC dialect is architecture-specific. + # We probe both because there is not a fallback guaranteed to work for all + # future architectures. + foreach tlsdesc_arg : ['-mtls-dialect=gnu2', '-mtls-dialect=desc'] + # -fpic to force dynamic tls, otherwise TLS relaxation defeats check + tlsdesc_test = cc.run('int __thread x; int main() { return x; }', + args: [tlsdesc_arg, '-fpic'], + name: tlsdesc_arg) + if tlsdesc_test.returncode() == 0 and ( + # check for lld 13 bug: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5665 + host_machine.cpu_family() != 'x86_64' or + # get_linker_id misses LDFLAGS=-fuse-ld=lld: https://github.com/mesonbuild/meson/issues/6377 + #cc.get_linker_id() != 'ld.lld' or + cc.links('''int __thread x; int y; int main() { __asm__( + "leaq x@TLSDESC(%rip), %rax\n" + "movq y@GOTPCREL(%rip), %rdx\n" + "call *x@TLSCALL(%rax)\n"); }''', name: 'split TLSDESC') + ) + c_cpp_args += tlsdesc_arg + break + endif + endforeach endif endif