From 94ea1327d8643c1a66aa615fbcdbd69f26080fca Mon Sep 17 00:00:00 2001 From: Kyle Brenneman Date: Mon, 13 Sep 2021 16:45:47 -0600 Subject: [PATCH 1/3] meson: Change the 'tls' option to be boolean. Change the 'tls' option to be a boolean value instead of a feature. This still allows manually disabling TLS in builds that would otherwise support it, but it shouldn't be affected by meson's --auto-features option. --- .gitlab-ci.yml | 6 +++--- meson.build | 7 +++++-- meson_options.txt | 5 +++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bde630d..6fba5a6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -84,7 +84,7 @@ build-x86_64-tsd-meson: extends: - .build-check-meson variables: - CONFIGURE_OPTIONS: -Dtls=disabled + CONFIGURE_OPTIONS: -Dtls=false build-i386-tsd: extends: @@ -96,7 +96,7 @@ build-i386-tsd-meson: extends: - .build-check-meson variables: - CONFIGURE_OPTIONS: -Dtls=disabled --cross-file .gitlab-ci/i686-linux-gnu + CONFIGURE_OPTIONS: -Dtls=false --cross-file .gitlab-ci/i686-linux-gnu build-pure-c-tls: extends: @@ -120,4 +120,4 @@ build-pure-c-tld-meson: extends: - .build-check-meson variables: - CONFIGURE_OPTIONS: -Dasm=disabled -Dtls=disabled + CONFIGURE_OPTIONS: -Dasm=disabled -Dtls=false diff --git a/meson.build b/meson.build index 7d8ac0a..f38744f 100644 --- a/meson.build +++ b/meson.build @@ -114,14 +114,17 @@ if cc.compiles('typeof(int *);', name : 'typeof') endif with_tls = get_option('tls') -if with_tls.auto() +if with_tls + # Use a __thread variable if possible, even if we can't use the TLS assembly + # stubs, because it's still faster than calling pthread_getspecific. have_tls = cc.compiles( '__thread int foo;', name : '__thread', ) else - have_tls = with_tls.enabled() + have_tls = false endif +message('Using TLS variable for dispatch table: @0@'.format(have_tls)) if have_tls add_project_arguments('-DGLDISPATCH_USE_TLS', language : ['c']) diff --git a/meson_options.txt b/meson_options.txt index 7a1d419..bc5ec07 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -60,8 +60,9 @@ option( ) option( 'tls', - type : 'feature', - description : 'Use Thread Local Storage.' + type : 'boolean', + value : true, + description : 'Use Thread Local Storage (if supported).' ) option( 'dispatch-page-size', From 79b012c645ec392b7d7b0b32c6595cc7a9166706 Mon Sep 17 00:00:00 2001 From: Kyle Brenneman Date: Mon, 13 Sep 2021 17:05:21 -0600 Subject: [PATCH 2/3] meson: Add an option to use the TSD dispatch stubs. Add a 'dispatch-tls' option. Setting the option to false will force it to use the TSD dispatch stubs for builds that would otherwise support the TLS stubs. This is mostly for test coverage, to make it easier to test builds that use the __thread variable (u_current_tls.c), but still use the TSD dispatch stubs. --- meson.build | 10 +++++++++- meson_options.txt | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index f38744f..a25c771 100644 --- a/meson.build +++ b/meson.build @@ -136,7 +136,15 @@ if use_asm # FreeBSD and glibc). on other platforms we use TSD stubs to allow calling # extension functions unknown at compile time. # https://gitlab.freedesktop.org/glvnd/libglvnd/-/merge_requests/249 - thread_type = have_tls and (host_machine.system() == 'freebsd' or cc.has_header_symbol('features.h', '__GLIBC__')) ? 'tls' : 'tsd' + thread_type = 'tsd' + if get_option('dispatch-tls') + if have_tls + if host_machine.system() == 'freebsd' or cc.has_header_symbol('features.h', '__GLIBC__') + thread_type = 'tls' + endif + endif + endif + if host_machine.cpu_family().startswith('x86') gl_dispatch_type = '@0@_@1@'.format( host_machine.cpu_family(), diff --git a/meson_options.txt b/meson_options.txt index bc5ec07..c4b7bc1 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -64,6 +64,12 @@ option( value : true, description : 'Use Thread Local Storage (if supported).' ) +option( + 'dispatch-tls', + type : 'boolean', + value : true, + description : 'Use TLS-based stubs in libGLdispatch (if supported).' +) option( 'dispatch-page-size', type : 'integer', From 4de6e6734b7d6ac7239ef187426c9e3c22bb2bce Mon Sep 17 00:00:00 2001 From: Kyle Brenneman Date: Mon, 13 Sep 2021 17:14:57 -0600 Subject: [PATCH 3/3] CI: Test builds with TSD stubs and TLS variables Add builds to the CI script that use the TSD dispatch stubs, but use the TLS variable in u_current_tls.c for the dispatch table. That's the combination you'd get with musl or other non-glibc systems. --- .gitlab-ci.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6fba5a6..7080f5a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -86,6 +86,12 @@ build-x86_64-tsd-meson: variables: CONFIGURE_OPTIONS: -Dtls=false +build-x86_64-tsd-tls-meson: + extends: + - .build-check-meson + variables: + CONFIGURE_OPTIONS: -Ddispatch-tls=false + build-i386-tsd: extends: - .build-check-at @@ -98,6 +104,12 @@ build-i386-tsd-meson: variables: CONFIGURE_OPTIONS: -Dtls=false --cross-file .gitlab-ci/i686-linux-gnu +build-i386-tsd-tls-meson: + extends: + - .build-check-meson + variables: + CONFIGURE_OPTIONS: -Ddispatch-tls=false --cross-file .gitlab-ci/i686-linux-gnu + build-pure-c-tls: extends: - .build-check-at