[PATCH v2] elf: Drop elf/tls-macros.h in favor of __thread and tls_model attributes [BZ #28152] [BZ #28205]

Fāng-ruì Sòng maskray@google.com
Thu Aug 12 18:38:09 GMT 2021


On Thu, Aug 12, 2021 at 11:11 AM Szabolcs Nagy <szabolcs.nagy@arm.com> wrote:
>
> The 08/12/2021 10:55, Fangrui Song via Libc-alpha wrote:
> > elf/tls-macros.h was added for TLS testing when GCC did not support
> > __thread. __thread and tls_model attributes are mature now and have been
> > used by many newer tests.
> >
> > Also delete tst-tls2.c which tests .tls_common which is unused by modern
> > GCC and unsupported by Clang/LLD. .tls_common and .tbss definition are
> > almost identical after linking, so the runtime test doesn't add
> > additional coverage.  Assembler and linker tests should be on the
> > binutils side.
> >
> > When LLD 13.0.0 is allowed in configure.ac
> > (https://sourceware.org/pipermail/libc-alpha/2021-August/129866.html),
> > `make check` result is on par with glibc built with GNU ld.
> >
> > As a future clean-up, TLS_GD/TLS_LD/TLS_IE/TLS_IE macros can be removed from
> > sysdeps/*/tls-macros.h. We can add optional -mtls-dialect={gnu2,trad}
> > tests to ensure coverage.
> >
> > Tested on x86_64-linux-gnu and aarch64-linux-gnu.
>
> it seems tls-macros.h stuff is used by some target
> specific tests (on powerpc)
>
> ideally those would be updated too and all target
> tls-macros.h removed.
>
> (if you don't want to deal with powerpc then i
> think you need to keep tls-macros.h, the rest of
> the patch still makes aarch64 work with lld.)

Thanks for catching this.
I have updated sysdeps/powerpc/ tests in v3 and found a ppc64le
machine to test it.

> > diff --git a/elf/tst-tls1.c b/elf/tst-tls1.c
> > index c31da56ce9..81bd3468d5 100644
> > --- a/elf/tst-tls1.c
> > +++ b/elf/tst-tls1.c
> > @@ -4,10 +4,13 @@
> >  #include "tls-macros.h"
>
> is this still needed?

Yes, I still keep a TLS_GD reference.
Otherwise aarch64 would lose traditional TLS GD coverage.

After we add optional -mtls-dialect={gnu2,trad} tests to Makefile,
this can be removed without coverage degradation.

> >
> >
> > -/* Two common 'int' variables in TLS.  */
> > -COMMON_INT_DEF(foo);
> > -COMMON_INT_DEF(bar);
> > -
> > +__thread int foo, bar __attribute__ ((tls_model("local-exec")));
> > +extern __thread int foo_gd asm ("foo") __attribute__ ((tls_model("global-dynamic")));
> > +extern __thread int foo_ld asm ("foo") __attribute__ ((tls_model("local-dynamic")));
> > +extern __thread int foo_ie asm ("foo") __attribute__ ((tls_model("initial-exec")));
> > +extern __thread int bar_gd asm ("bar") __attribute__ ((tls_model("global-dynamic")));
> > +extern __thread int bar_ld asm ("bar") __attribute__ ((tls_model("local-dynamic")));
> > +extern __thread int bar_ie asm ("bar") __attribute__ ((tls_model("initial-exec")));
> >
> >  static int
> >  do_test (void)


More information about the Libc-alpha mailing list