commit:     35fa4d2f59a272a53e02f54b6c962217d8d67554
Author:     Jory Pratt <anarchy <AT> gentoo <DOT> org>
AuthorDate: Fri Jan 21 03:50:56 2022 +0000
Commit:     Jory Pratt <anarchy <AT> gentoo <DOT> org>
CommitDate: Fri Jan 21 03:50:56 2022 +0000
URL:        https://gitweb.gentoo.org/proj/musl.git/commit/?id=35fa4d2f

media-libs/mesa: backport patches for non glibc users

Package-Manager: Portage-3.0.28, Repoman-3.0.3
Signed-off-by: Jory Pratt <anarchy <AT> gentoo.org>

 media-libs/mesa/Manifest                           |   2 +-
 .../mesa-21.1.4-add-disable-tls-support.patch      |  42 -------
 media-libs/mesa/files/mesa-tls-2.patch             |  60 +++++++++
 media-libs/mesa/files/mesa-tls.patch               | 134 +++++++++++++++++++++
 .../{mesa-21.2.6.ebuild => mesa-21.3.4.ebuild}     |  30 ++---
 media-libs/mesa/metadata.xml                       |   2 -
 6 files changed, 204 insertions(+), 66 deletions(-)

diff --git a/media-libs/mesa/Manifest b/media-libs/mesa/Manifest
index 9cc0fbb3..6fdb1557 100644
--- a/media-libs/mesa/Manifest
+++ b/media-libs/mesa/Manifest
@@ -1 +1 @@
-DIST mesa-21.2.6.tar.xz 15868208 BLAKE2B 
aaa6447a2f5a472c2ee2b7d6b12effb79d02804684358fd233aa00bda945c66efa3850931cd9114c51ddd492033b9f66372380395540a11fe40229edfe7ee125
 SHA512 
e65d77e2609cba85bd2cdbd4ba2072729c1556a43defdd24a91e708e3223f84b23657e63a91b16c5729684ea12fe31f45bae88294c572e057f2981a5d6c0f5a0
+DIST mesa-21.3.4.tar.xz 16497248 BLAKE2B 
3fe2543bb6286a0d84a247785dbb4b5dd6df905eab748a89854589008d9db5aae6c52e473c58cff8d03694d46d3ce2a2680fddc8c978f898dc9bcdec02ca9b6b
 SHA512 
7aeea3dba0d39f4ac9f23c54aa0e6853d48000f50c4dd484618c28debe705cdd765ae8fafb5ddea0773976f7189849d9128be3f2282fea74394b59019cb786b9

diff --git a/media-libs/mesa/files/mesa-21.1.4-add-disable-tls-support.patch 
b/media-libs/mesa/files/mesa-21.1.4-add-disable-tls-support.patch
deleted file mode 100644
index 8e7089c9..00000000
--- a/media-libs/mesa/files/mesa-21.1.4-add-disable-tls-support.patch
+++ /dev/null
@@ -1,42 +0,0 @@
-From a9b290ecff1ed3fdfd95bae551ce47dea8fa13fb Mon Sep 17 00:00:00 2001
-From: Jory Pratt <[email protected]>
-Date: Tue, 6 Jul 2021 07:54:09 -0500
-Subject: [PATCH] Add disable glx support for musl
-
----
- meson.build       | 4 +++-
- meson_options.txt | 6 ++++++
- 2 files changed, 9 insertions(+), 1 deletion(-)
-
-diff --git a/meson.build b/meson.build
-index e1e94e7..b355f94 100644
---- a/meson.build
-+++ b/meson.build
-@@ -447,7 +447,9 @@ endif
- 
- # 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
-+with_use_elf_tls = get_option('use-elf-tls')
-+if with_use_elf_tls and
-+    (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))
-   pre_args += '-DUSE_ELF_TLS'
-diff --git a/meson_options.txt b/meson_options.txt
-index a7030ab..73bd28e 100644
---- a/meson_options.txt
-+++ b/meson_options.txt
-@@ -465,3 +465,9 @@ option(
-   value : true,
-   description : 'use msse2 flag for mingw x86. Default: true',
- )
-+option(
-+  'use-elf-tls',
-+  type : 'boolean',
-+  value : false,
-+  description : 'Build support for initial-exec TLS model'
-+)
--- 
-2.31.1
-

diff --git a/media-libs/mesa/files/mesa-tls-2.patch 
b/media-libs/mesa/files/mesa-tls-2.patch
new file mode 100644
index 00000000..c849e27d
--- /dev/null
+++ b/media-libs/mesa/files/mesa-tls-2.patch
@@ -0,0 +1,60 @@
+From 60d95c5d0feef4e4b2820a26c4708aff10f5730d Mon Sep 17 00:00:00 2001
+From: "Alex Xu (Hello71)" <[email protected]>
+Date: Thu, 2 Sep 2021 12:19:53 -0400
+Subject: [PATCH] Auto-enable TLSDESC support
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+TLSDESC speeds up access to dynamic TLS. This is especially important
+for non-glibc targets, but is also helpful for non-initial-exec TLS
+variables.
+
+The entry asm does not support TLSDESC, but it only accesses
+initial-exec symbols, so it is not necessary to handle that separately.
+
+Acked-by: Tapani Pälli <[email protected]>
+Acked-by: Jesse Natalie <[email protected]>
+Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12722>
+---
+ meson.build | 24 ++++++++++++++++++++++++
+ 1 file changed, 24 insertions(+)
+
+diff --git a/meson.build b/meson.build
+index a7ace23677c..29f0c3f3912 100644
+--- a/meson.build
++++ b/meson.build
+@@ -520,6 +520,30 @@ if not with_platform_windows or not with_shared_glapi
+     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
+ endif
+ 
+ if with_glx != 'disabled'
+-- 
+GitLab
+

diff --git a/media-libs/mesa/files/mesa-tls.patch 
b/media-libs/mesa/files/mesa-tls.patch
new file mode 100644
index 00000000..f445c934
--- /dev/null
+++ b/media-libs/mesa/files/mesa-tls.patch
@@ -0,0 +1,134 @@
+From 8570a2a280587a1e43ac11ad46ad62dfdd6c7b39 Mon Sep 17 00:00:00 2001
+From: "Alex Xu (Hello71)" <[email protected]>
+Date: Thu, 2 Sep 2021 11:58:32 -0400
+Subject: [PATCH] Use initial-exec TLS for glibc only, enable TLS elsewhere
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+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
+https://github.com/jbeich/mesa/commit/81dbdb15d55054242eded0eb2f32621d583c1aaf
+
+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 <[email protected]>
+Acked-by: Jesse Natalie <[email protected]>
+Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12722>
+---
+ meson.build         |  7 ++-----
+ src/mapi/entry.c    | 28 ++++++++++++++--------------
+ src/util/u_thread.h | 16 ++++++----------
+ 3 files changed, 22 insertions(+), 29 deletions(-)
+
+diff --git a/meson.build b/meson.build
+index cf2b5f4b939..a7ace23677c 100644
+--- a/meson.build
++++ b/meson.build
+@@ -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.
+diff --git a/src/mapi/entry.c b/src/mapi/entry.c
+index 7ff3c8f8c8c..b120eae31a1 100644
+--- a/src/mapi/entry.c
++++ b/src/mapi/entry.c
+@@ -31,6 +31,7 @@
+ #include "entry.h"
+ #include "u_current.h"
+ #include "util/u_endian.h"
++#include "util/u_thread.h"
+ 
+ #define _U_STRINGIFY(x) #x
+ #define U_STRINGIFY(x) _U_STRINGIFY(x)
+@@ -45,20 +46,19 @@
+ #define ENTRY_CURRENT_TABLE_GET U_STRINGIFY(u_current_get_table_internal)
+ #endif
+ 
+-#if defined(USE_X86_ASM) && defined(__GNUC__)
+-#   ifdef USE_ELF_TLS
+-#      include "entry_x86_tls.h"
+-#   else                 
+-#      include "entry_x86_tsd.h"
+-#   endif
+-#elif defined(USE_X86_64_ASM) && defined(__GNUC__) && defined(USE_ELF_TLS)
+-#   include "entry_x86-64_tls.h"
+-#elif defined(USE_PPC64LE_ASM) && defined(__GNUC__) && UTIL_ARCH_LITTLE_ENDIAN
+-#   ifdef USE_ELF_TLS
+-#      include "entry_ppc64le_tls.h"
+-#   else
+-#      include "entry_ppc64le_tsd.h"
+-#   endif
++/* REALLY_INITIAL_EXEC implies USE_ELF_TLS and __GNUC__ */
++/* Use TSD stubs for non-IE ELF TLS even though first access is slower because
++ * future accesses will be patched */
++#if defined(USE_X86_ASM) && defined(REALLY_INITIAL_EXEC)
++#include "entry_x86_tls.h"
++#elif defined(USE_X86_ASM) && !defined(GLX_X86_READONLY_TEXT) && 
defined(__GNUC__)
++#include "entry_x86_tsd.h"
++#elif defined(USE_X86_64_ASM) && defined(REALLY_INITIAL_EXEC)
++#include "entry_x86-64_tls.h"
++#elif defined(USE_PPC64LE_ASM) && UTIL_ARCH_LITTLE_ENDIAN && 
defined(REALLY_INITIAL_EXEC)
++#include "entry_ppc64le_tls.h"
++#elif defined(USE_PPC64LE_ASM) && UTIL_ARCH_LITTLE_ENDIAN && defined(__GNUC__)
++#include "entry_ppc64le_tsd.h"
+ #else
+ 
+ static inline const struct _glapi_table *
+diff --git a/src/util/u_thread.h b/src/util/u_thread.h
+index 0fb474f32ba..a4215452d35 100644
+--- a/src/util/u_thread.h
++++ b/src/util/u_thread.h
+@@ -75,19 +75,15 @@
+  * still want to use normal TLS (which involves a function call, but not the
+  * expensive pthread_getspecific() or its equivalent).
+  */
++#ifdef USE_ELF_TLS
+ #ifdef _MSC_VER
+ #define __THREAD_INITIAL_EXEC __declspec(thread)
+-#elif defined(ANDROID)
+-/* Android 29 gained ELF TLS support, but it doesn't support initial-exec and
+- * it will throw:
+- *
+- *     dlopen failed: TLS symbol "(null)" in dlopened
+- *     "/vendor/lib64/egl/libEGL_mesa.so" referenced from
+- *     "/vendor/lib64/egl/libEGL_mesa.so" using IE access model.
+- */
+-#define __THREAD_INITIAL_EXEC __thread
+-#else
++#elif defined(__GLIBC__)
+ #define __THREAD_INITIAL_EXEC __thread 
__attribute__((tls_model("initial-exec")))
++#define REALLY_INITIAL_EXEC
++#else
++#define __THREAD_INITIAL_EXEC __thread
++#endif
+ #endif
+ 
+ static inline int
+-- 
+GitLab
+

diff --git a/media-libs/mesa/mesa-21.2.6.ebuild 
b/media-libs/mesa/mesa-21.3.4.ebuild
similarity index 96%
rename from media-libs/mesa/mesa-21.2.6.ebuild
rename to media-libs/mesa/mesa-21.3.4.ebuild
index dfa0eb93..ec0dad18 100644
--- a/media-libs/mesa/mesa-21.2.6.ebuild
+++ b/media-libs/mesa/mesa-21.3.4.ebuild
@@ -17,7 +17,7 @@ if [[ ${PV} == 9999 ]]; then
        inherit git-r3
 else
        SRC_URI="https://archive.mesa3d.org/${MY_P}.tar.xz";
-       KEYWORDS="amd64 arm arm64 ~mips ppc ppc64 x86"
+       KEYWORDS="amd64 arm arm64 ~mips ~ppc ~ppc64 x86"
 fi
 
 LICENSE="MIT"
@@ -33,18 +33,15 @@ for card in ${VIDEO_CARDS}; do
 done
 
 IUSE="${IUSE_VIDEO_CARDS}
-       +classic cpu_flags_x86_sse2 d3d9 debug +egl +gallium +gbm gles1 +gles2 
+llvm
+       +classic cpu_flags_x86_sse2 d3d9 debug +gallium gles1 +gles2 +llvm
        lm-sensors opencl osmesa selinux test unwind vaapi valgrind vdpau vulkan
        vulkan-overlay wayland +X xa xvmc zink +zstd"
 
 REQUIRED_USE="
        d3d9?   ( || ( video_cards_iris video_cards_r300 video_cards_r600 
video_cards_radeonsi video_cards_nouveau video_cards_vmware ) )
-       gles1?  ( egl )
-       gles2?  ( egl )
        osmesa? ( gallium )
        vulkan? ( video_cards_radeonsi? ( llvm ) )
        vulkan-overlay? ( vulkan )
-       wayland? ( egl gbm )
        video_cards_crocus? ( gallium )
        video_cards_freedreno?  ( gallium )
        video_cards_intel?  ( classic )
@@ -64,7 +61,7 @@ REQUIRED_USE="
        video_cards_v3d? ( gallium )
        video_cards_vc4? ( gallium )
        video_cards_virgl? ( gallium )
-       video_cards_vivante? ( gallium gbm )
+       video_cards_vivante? ( gallium )
        video_cards_vmware? ( gallium )
        xa? ( X )
        xvmc? ( X )
@@ -224,7 +221,7 @@ BDEPEND="
        sys-devel/flex
        virtual/pkgconfig
        $(python_gen_any_dep ">=dev-python/mako-0.8.0[\${PYTHON_USEDEP}]")
-       wayland? ( dev-util/wayland-scanner[${MULTILIB_USEDEP}] )
+       wayland? ( dev-util/wayland-scanner )
 "
 
 S="${WORKDIR}/${MY_P}"
@@ -241,7 +238,8 @@ x86? (
 )"
 
 PATCHES=(
-       "${FILESDIR}"/${PN}-21.1.4-add-disable-tls-support.patch
+       "${FILESDIR}"/mesa-tls.patch
+       "${FILESDIR}"/mesa-tls-2.patch
 )
 
 llvm_check_deps() {
@@ -388,17 +386,6 @@ multilib_src_configure() {
        use wayland && platforms+=",wayland"
        emesonargs+=(-Dplatforms=${platforms#,})
 
-       if use X || use egl; then
-               emesonargs+=(-Dglvnd=true)
-       else
-               emesonargs+=(-Dglvnd=false)
-       fi
-
-       # Disable glx tls support on musl
-       if use elibc_musl; then
-               emesonargs+=( -Duse-elf-tls=false )
-       fi
-
        if use gallium; then
                emesonargs+=(
                        $(meson_feature llvm)
@@ -521,8 +508,9 @@ multilib_src_configure() {
                -Dglx=$(usex X dri disabled)
                -Dshared-glapi=enabled
                -Ddri3=enabled
-               $(meson_feature egl)
-               $(meson_feature gbm)
+               -Degl=true
+               -Dgbm=true
+               -Dglvnd=true
                $(meson_feature gles1)
                $(meson_feature gles2)
                $(meson_use osmesa)

diff --git a/media-libs/mesa/metadata.xml b/media-libs/mesa/metadata.xml
index 2b18aba1..b181eed2 100644
--- a/media-libs/mesa/metadata.xml
+++ b/media-libs/mesa/metadata.xml
@@ -8,9 +8,7 @@
        <use>
                <flag name="classic">Build drivers based on the classic 
architecture.</flag>
                <flag name="d3d9">Enable Direct 3D9 API through Nine state 
tracker. Can be used together with patched wine.</flag>
-               <flag name="egl">Enable EGL support.</flag>
                <flag name="gallium">Build drivers based on Gallium3D, the new 
architecture for 3D graphics drivers.</flag>
-               <flag name="gbm">Enable the Graphics Buffer Manager for EGL on 
KMS.</flag>
                <flag name="gles1">Enable GLESv1 support.</flag>
                <flag name="gles2">Enable GLESv2 support.</flag>
                <flag name="llvm">Enable LLVM backend for Gallium3D.</flag>

Reply via email to