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