diff options
author | Jesse Natalie <jenatali@microsoft.com> | 2021-11-02 11:38:02 -0700 |
---|---|---|
committer | Marge Bot <emma+marge@anholt.net> | 2021-12-02 03:03:14 +0000 |
commit | c47fd3dc0062101b3e75a414b17d2765735f7424 (patch) | |
tree | 319d456168d2c892d85961fffde6fc368d59605a /meson.build | |
parent | 58aad3f403b87276ecd0d6752b30e0e2883663d4 (diff) |
windows: Use TLS context/dispatch with shared-glapi
However they have to be called via _glapi_get_dispatch/context. This
would be safe to do on any platform, but the extra indirection is only
necessary on Windows since TLS vars can't be exported from a DLL.
Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13634>
Diffstat (limited to 'meson.build')
-rw-r--r-- | meson.build | 73 |
1 files changed, 39 insertions, 34 deletions
diff --git a/meson.build b/meson.build index f5f0f7125bc..7d1a39e131e 100644 --- a/meson.build +++ b/meson.build @@ -508,44 +508,49 @@ foreach platform : _platforms pre_args += '-DHAVE_@0@_PLATFORM'.format(platform.to_upper()) endforeach -use_elf_tls = false -if not with_platform_windows or not with_shared_glapi - pre_args += '-DUSE_ELF_TLS' - use_elf_tls = true - - 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. - 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 +use_elf_tls = true +pre_args += '-DUSE_ELF_TLS' + +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. + 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 +if with_platform_windows and with_shared_glapi + # Windows doesn't support DLL exports/imports being TLS variables. When using shared + # glapi, libglapi.dll hosts the TLS, but other DLLs need to use them. Instead of falling + # all the way back to using globals and manual per-thread data, keep using TLS but just + # put accesses to it behind a function so the variable doesn't need to be exported. + pre_args += '-DUSE_TLS_BEHIND_FUNCTIONS' +endif + if with_glx != 'disabled' if not (with_platform_x11 and with_any_opengl) error('Cannot build GLX support without X11 platform support and at least one OpenGL API') |