mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] Fwd: mesa | Remove USE_ELF_TLS macro (!17213)
       [not found]     ` <note_1442291@gitlab.freedesktop.org>
@ 2022-06-25  3:36       ` 罗勇刚(Yonggang Luo)
  2022-06-25  4:47         ` Markus Wichmann
  0 siblings, 1 reply; 5+ messages in thread
From: 罗勇刚(Yonggang Luo) @ 2022-06-25  3:36 UTC (permalink / raw)
  To: mesa-dev, Musl

[-- Attachment #1: Type: text/plain, Size: 1251 bytes --]

---------- Forwarded message ---------
From: Zoltán Böszörményi (@zboszor) <gitlab@gitlab.freedesktop.org>
Date: Sat, Jun 25, 2022 at 12:09 AM
Subject: Re: mesa | Remove USE_ELF_TLS macro (!17213)
To: <luoyonggang@gmail.com>


Zoltán Böszörményi commented on a discussion on src/meson.build:

152 152

     libraries : libgl,

153 153

     libraries_private : gl_priv_libs,

154 154

     requires_private : gl_priv_reqs,

155

-    variables : ['glx_tls=@0@'.format(use_elf_tls ? 'yes' : 'no')],

155

+    variables : ['glx_tls=@0@'.format('yes')],

156 156

   )

I don't think it's a good idea to make ELF_TLS unconditionally true.

Yocto allows choosing the LIBC at least between GLIBC and MUSL, and Mesa
built with TLS crashes under MUSL.

See this patch:
https://git.openembedded.org/openembedded-core/tree/meta/recipes-graphics/mesa/files/0002-meson.build-make-TLS-ELF-optional.patch
and here TLS is only enabled for GLIBC:
https://git.openembedded.org/openembedded-core/tree/meta/recipes-graphics/mesa/mesa.inc#n92

So I am confused. What's the situation about ELF-TLS support in musl?
Is that still broken now?

--
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo

[-- Attachment #2: Type: text/html, Size: 1802 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [musl] Fwd: mesa | Remove USE_ELF_TLS macro (!17213)
  2022-06-25  3:36       ` [musl] Fwd: mesa | Remove USE_ELF_TLS macro (!17213) 罗勇刚(Yonggang Luo)
@ 2022-06-25  4:47         ` Markus Wichmann
  2022-06-25  5:25           ` 罗勇刚(Yonggang Luo)
  0 siblings, 1 reply; 5+ messages in thread
From: Markus Wichmann @ 2022-06-25  4:47 UTC (permalink / raw)
  To: musl; +Cc: mesa-dev

On Sat, Jun 25, 2022 at 11:36:09AM +0800, 罗勇刚(Yonggang Luo) wrote:
> So I am confused. What's the situation about ELF-TLS support in musl?
> Is that still broken now?

musl has always supported ELF-TLS anywhere except in libc itself. That
was also never the problem. The problem was that the mesa people select
the initial-exec TLS model explicitly, even though libGL ends up being
dlopen()ed quite often, and then you should be using the general-dynamic
model instead.

According to [1], Rich proposed dropping the initial-exec attribute and
replacing it with -mtls-dialect=gnu2 eight years ago. Has that happened
yet? If so, dlopen()ing libGL with musl ought to work.

Ciao,
Markus

[1] https://gitlab.freedesktop.org/mesa/mesa/-/issues/966

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [musl] Fwd: mesa | Remove USE_ELF_TLS macro (!17213)
  2022-06-25  4:47         ` Markus Wichmann
@ 2022-06-25  5:25           ` 罗勇刚(Yonggang Luo)
  2022-06-25  5:51             ` Fangrui Song
  2022-06-25  9:48             ` Szabolcs Nagy
  0 siblings, 2 replies; 5+ messages in thread
From: 罗勇刚(Yonggang Luo) @ 2022-06-25  5:25 UTC (permalink / raw)
  To: Musl; +Cc: mesa-dev

[-- Attachment #1: Type: text/plain, Size: 1339 bytes --]

On Sat, Jun 25, 2022 at 12:47 PM Markus Wichmann <nullplan@gmx.net> wrote:
>
> On Sat, Jun 25, 2022 at 11:36:09AM +0800, 罗勇刚(Yonggang Luo) wrote:
> > So I am confused. What's the situation about ELF-TLS support in musl?
> > Is that still broken now?
>
> musl has always supported ELF-TLS anywhere except in libc itself. That
> was also never the problem. The problem was that the mesa people select
> the initial-exec TLS model explicitly, even though libGL ends up being
> dlopen()ed quite often, and then you should be using the general-dynamic
> model instead.

My question is does musl support ELS-TLS when using dl-open.



>
> According to [1], Rich proposed dropping the initial-exec attribute and
> replacing it with -mtls-dialect=gnu2 eight years ago. Has that happened
> yet? If so, dlopen()ing libGL with musl ought to work.

`initial-exec` are only specified for  __GLIBC__, If musl  not predefined
macro ` __GLIBC__`
```
#if defined(__GLIBC__)
#define __THREAD_INITIAL_EXEC thread_local
__attribute__((tls_model("initial-exec")))
#define REALLY_INITIAL_EXEC
#else
#define __THREAD_INITIAL_EXEC thread_local
#endif
```


>
> Ciao,
> Markus
>
> [1] https://gitlab.freedesktop.org/mesa/mesa/-/issues/966



--
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo

[-- Attachment #2: Type: text/html, Size: 1720 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [musl] Fwd: mesa | Remove USE_ELF_TLS macro (!17213)
  2022-06-25  5:25           ` 罗勇刚(Yonggang Luo)
@ 2022-06-25  5:51             ` Fangrui Song
  2022-06-25  9:48             ` Szabolcs Nagy
  1 sibling, 0 replies; 5+ messages in thread
From: Fangrui Song @ 2022-06-25  5:51 UTC (permalink / raw)
  To: musl; +Cc: mesa-dev

On 2022-06-25, 罗勇刚(Yonggang Luo) wrote:
>On Sat, Jun 25, 2022 at 12:47 PM Markus Wichmann <nullplan@gmx.net> wrote:
>>
>> On Sat, Jun 25, 2022 at 11:36:09AM +0800, 罗勇刚(Yonggang Luo) wrote:
>> > So I am confused. What's the situation about ELF-TLS support in musl?
>> > Is that still broken now?
>>
>> musl has always supported ELF-TLS anywhere except in libc itself. That
>> was also never the problem. The problem was that the mesa people select
>> the initial-exec TLS model explicitly, even though libGL ends up being
>> dlopen()ed quite often, and then you should be using the general-dynamic
>> model instead.
>
>My question is does musl support ELS-TLS when using dl-open.

It is supported.

For shared objects using the initial-exec TLS model, they must be at load time (DT_NEEDED),
not via dlopen.
See https://maskray.me/blog/2021-02-14-all-about-thread-local-storage
for background.

>
>>
>> According to [1], Rich proposed dropping the initial-exec attribute and
>> replacing it with -mtls-dialect=gnu2 eight years ago. Has that happened
>> yet? If so, dlopen()ing libGL with musl ought to work.
>
>`initial-exec` are only specified for  __GLIBC__, If musl  not predefined
>macro ` __GLIBC__`
>```
>#if defined(__GLIBC__)
>#define __THREAD_INITIAL_EXEC thread_local
>__attribute__((tls_model("initial-exec")))
>#define REALLY_INITIAL_EXEC
>#else
>#define __THREAD_INITIAL_EXEC thread_local
>#endif
>```

On x86, you may enable (currently GCC only) -mtls-dialect=gnu2 to get
performance boost. It's just a tiny bit slower than initial-exec.

I added x86-32 TLSDESC and mixed TLS GD/TLSDESC support to lld 14 after
I saw the -mtls-dialect=gnu2 build system improvement in mesa :)

>
>>
>> Ciao,
>> Markus
>>
>> [1] https://gitlab.freedesktop.org/mesa/mesa/-/issues/966
>
>
>
>--
>         此致
>礼
>罗勇刚
>Yours
>    sincerely,
>Yonggang Luo

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [musl] Fwd: mesa | Remove USE_ELF_TLS macro (!17213)
  2022-06-25  5:25           ` 罗勇刚(Yonggang Luo)
  2022-06-25  5:51             ` Fangrui Song
@ 2022-06-25  9:48             ` Szabolcs Nagy
  1 sibling, 0 replies; 5+ messages in thread
From: Szabolcs Nagy @ 2022-06-25  9:48 UTC (permalink / raw)
  To: 罗勇刚(Yonggang Luo); +Cc: Musl, mesa-dev

* 罗勇刚(Yonggang Luo) <luoyonggang@gmail.com> [2022-06-25 13:25:31 +0800]:
> On Sat, Jun 25, 2022 at 12:47 PM Markus Wichmann <nullplan@gmx.net> wrote:
> >
> > On Sat, Jun 25, 2022 at 11:36:09AM +0800, 罗勇刚(Yonggang Luo) wrote:
> > > So I am confused. What's the situation about ELF-TLS support in musl?
> > > Is that still broken now?
> >
> > musl has always supported ELF-TLS anywhere except in libc itself. That
> > was also never the problem. The problem was that the mesa people select
> > the initial-exec TLS model explicitly, even though libGL ends up being
> > dlopen()ed quite often, and then you should be using the general-dynamic
> > model instead.
> 
> My question is does musl support ELS-TLS when using dl-open.
> 

musl supports ELF TLS with or without dlopen.

if something crashes that's most likely a bug in mesa.

> 
> >
> > According to [1], Rich proposed dropping the initial-exec attribute and
> > replacing it with -mtls-dialect=gnu2 eight years ago. Has that happened
> > yet? If so, dlopen()ing libGL with musl ought to work.
> 
> `initial-exec` are only specified for  __GLIBC__, If musl  not predefined
> macro ` __GLIBC__`


note: initial-exec tls is wrong for both glibc and musl.

(glibc reserves initial tls for ld_audit and dlmopen namespaces, it's
not there for mesa. i.e. this only happens to work because it's
unlikely that a process uses all the glibc features for which static
tls is reserved, but if that happens then mesa will fail to load.)

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-06-25  9:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <merge_request_66288@gitlab.freedesktop.org>
     [not found] ` <note_1441630@gitlab.freedesktop.org>
     [not found]   ` <note_1442039@gitlab.freedesktop.org>
     [not found]     ` <note_1442291@gitlab.freedesktop.org>
2022-06-25  3:36       ` [musl] Fwd: mesa | Remove USE_ELF_TLS macro (!17213) 罗勇刚(Yonggang Luo)
2022-06-25  4:47         ` Markus Wichmann
2022-06-25  5:25           ` 罗勇刚(Yonggang Luo)
2022-06-25  5:51             ` Fangrui Song
2022-06-25  9:48             ` Szabolcs Nagy

Code repositories for project(s) associated with this inbox:

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).