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 <uwu@icenowy.me>
Reviewed-by: Yukari Chiba <i@0x7f.cc>
Reviewed-by: David Heidelberg <david@ixit.cz>
Signed-off-by: WANG Xuerui <git@xen0n.name>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30599>
(cherry picked from commit cc2dbb8ea5)
This commit is contained in:
WANG Xuerui 2024-08-10 18:38:47 +08:00 committed by Eric Engestrom
parent 5a16eefb6a
commit 24d0e7eefe
2 changed files with 23 additions and 17 deletions

View File

@ -4,7 +4,7 @@
"description": "meson: Additionally probe -mtls-dialect=desc for TLSDESC support",
"nominated": true,
"nomination_type": 0,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null,
"notes": null

View File

@ -505,22 +505,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