Thread-local storage?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Thread-local storage?

Charles Lohr
I've been trying to find a way out of this for a bit now.  I'd like to carry over some optimizations to a TCC host compile, but, I'm stuck with using pthread_key_create and friends.  This is a bit of an annoying solution and not optimal... And potentially even rougher on Windows.

It looks like all the defines for the sections are in tccelf.h.  Is there any hidden handshake sort of way to mark data for a thread local section. .tbss?  I've tried __attribute__((section(".tbss"))) to no avail; it just sticks them into .bss.  Any ideas?

Charles

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: Thread-local storage?

Michael Matz-4
Hi,

On Tue, 3 Sep 2019, Charles Lohr wrote:

> I've been trying to find a way out of this for a bit now.  I'd like to
> carry over some optimizations to a TCC host compile, but, I'm stuck with
> using pthread_key_create and friends.  This is a bit of an annoying
> solution and not optimal... And potentially even rougher on Windows.
>
> It looks like all the defines for the sections are in tccelf.h.  Is
> there any hidden handshake sort of way to mark data for a thread local
> section. .tbss?  I've tried __attribute__((section(".tbss"))) to no
> avail; it just sticks them into .bss.  Any ideas?

The attribute works and puts the variable into the respective section just
fine.  The problem is rather that thread local storage has to be manage
quite differently and TCC is not doing that.

For instance, the .tbss section needs to be put into a different ELF
segment of TLS type, the section type itself needs to be TLS as well, and
then the code sequences to actually access the variables are completely
different.

So, yes, merely putting the variables into .tbss sections doesn't work,
and as of right now TCC doesn't support thread local storage.  I started
working on this a couple months ago, but got distracted.  Maybe one of
these days ... :)


Ciao,
Michael.

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: Thread-local storage?

Steffen Nurpmeso
Hello.

Michael Matz wrote in <[hidden email]>:
 |On Tue, 3 Sep 2019, Charles Lohr wrote:
 |
 |> I've been trying to find a way out of this for a bit now.  I'd like to
 |> carry over some optimizations to a TCC host compile, but, I'm stuck with
 |> using pthread_key_create and friends.  This is a bit of an annoying
 |> solution and not optimal... And potentially even rougher on Windows.
 |>
 |> It looks like all the defines for the sections are in tccelf.h.  Is
 |> there any hidden handshake sort of way to mark data for a thread local
 |> section. .tbss?  I've tried __attribute__((section(".tbss"))) to no
 |> avail; it just sticks them into .bss.  Any ideas?
 |
 |The attribute works and puts the variable into the respective section just
 |fine.  The problem is rather that thread local storage has to be manage
 |quite differently and TCC is not doing that.
 |
 |For instance, the .tbss section needs to be put into a different ELF
 |segment of TLS type, the section type itself needs to be TLS as well, and
 |then the code sequences to actually access the variables are completely
 |different.
 |
 |So, yes, merely putting the variables into .tbss sections doesn't work,
 |and as of right now TCC doesn't support thread local storage.  I started
 |working on this a couple months ago, but got distracted.  Maybe one of
 |these days ... :)

Since i know you are an expert here, may i ask if Ulrich Drepper's
"ELF Handling For Thread-Local Storage" version 0.20 still "the
document to know" regarding TLS?

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: Thread-local storage?

Michael Matz-4
Hi,

On Wed, 4 Sep 2019, Steffen Nurpmeso wrote:

> Since i know you are an expert here, may i ask if Ulrich Drepper's
> "ELF Handling For Thread-Local Storage" version 0.20 still "the
> document to know" regarding TLS?

Version 0.21, but yes.  Since then a couple new architectures came out
that aren't covered by that document (aarch64, risc-v, ppc64le come to
mind), but they all use one of the two models from therein, and are
usually described in their respective psABI documents.  But the basic
handling of all TLS on Linux is fairly similar on all these architectures
(also because these models are what gcc and glibc implements, and
therefore is the easiest path to success for new architectures).


Ciao,
Michael.

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: Thread-local storage?

Steffen Nurpmeso
Hello.

Michael Matz wrote in <[hidden email]>:
 |On Wed, 4 Sep 2019, Steffen Nurpmeso wrote:
 |> Since i know you are an expert here, may i ask if Ulrich Drepper's
 |> "ELF Handling For Thread-Local Storage" version 0.20 still "the
 |> document to know" regarding TLS?
 |
 |Version 0.21, but yes.  Since then a couple new architectures came out
 |that aren't covered by that document (aarch64, risc-v, ppc64le come to
 |mind), but they all use one of the two models from therein, and are
 |usually described in their respective psABI documents.  But the basic
 |handling of all TLS on Linux is fairly similar on all these architectures
 |(also because these models are what gcc and glibc implements, and
 |therefore is the easiest path to success for new architectures).

Thank you for the information.
Ciao,

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel