Use initial-exec TLS for glibc only, enable TLS elsewhere

It is not portable to use initial-exec TLS in dlopened libraries. glibc
and FreeBSD allocate extra memory for extra initial-exec variables
specifically for libGL, but other libcs including musl do not.

Keep initial-exec disabled on FreeBSD since it is apparently broken for
some reason:

https://gitlab.freedesktop.org/mesa/mesa/-/issues/966#note_394512
81dbdb15d5

Enable TLS on OpenBSD and Haiku based on the u_thread.h comment that
emutls is better than pthread_getspecific, which seems plausible given
that emutls has strictly more information to work with.

Fixes #966.

Acked-by: Tapani Pälli <tapani.palli@intel.com>
Acked-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12722>
This commit is contained in:
Alex Xu (Hello71)
2021-09-02 11:58:32 -04:00
parent df005c2a65
commit 8570a2a280
3 changed files with 22 additions and 29 deletions

View File

@@ -508,15 +508,12 @@ foreach platform : _platforms
pre_args += '-DHAVE_@0@_PLATFORM'.format(platform.to_upper())
endforeach
# Android uses emutls for versions <= P/28. For USE_ELF_TLS we need ELF TLS.
use_elf_tls = false
if (not ['freebsd', 'openbsd', 'haiku'].contains(host_machine.system()) and
(not with_platform_android or get_option('platform-sdk-version') >= 29) and
(not with_platform_windows or not with_shared_glapi))
if not with_platform_windows or not with_shared_glapi
pre_args += '-DUSE_ELF_TLS'
use_elf_tls = true
if with_platform_android
if with_platform_android and get_option('platform-sdk-version') >= 29
# 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.