[v3,0/9] RISC-V: Implement TLS Descriptors.

Message ID 20231128085109.28422-1-ishitatsuyuki@gmail.com
Headers
Series RISC-V: Implement TLS Descriptors. |

Message

Tatsuyuki Ishi Nov. 28, 2023, 8:51 a.m. UTC
  This patchset implements TLS Descriptors (TLSDESC) for RISC-V targets, per
the specification (merged) at [1].

Tested on rv64gc for:
- No regression (& passing new tests) in binutils
- No regression in gcc
- No regression in glibc for subdirs=elf
With both -mtls-dialect=desc and trad.

This contribution is made on behalf of Blue Whale Systems, which has
copyright assignment on file with the FSF.

[1]: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/373

v2: Add changelogs and tests. Minor fixes described in patch messages.
v3: Add relaxation support. This fixes tst-tls1-static in glibc.

Tatsuyuki Ishi (9):
  RISC-V: Fix local GOT and reloc size calculation for TLS.
  RISC-V: Add TLSDESC reloc definitions.
  RISC-V: Add assembly support for TLSDESC.
  RISC-V: Define and use GOT entry size constants for TLS.
  RISC-V: Initial ld.bfd support for TLSDESC.
  RISC-V: Move STATIC_TLS handling into record_tls_type.
  RISC-V: Unify TLS handling in check_relocs.
  RISC-V: Add elf_link_hash_entry to relax_func args.
  RISC-V: Introduce TLSDESC relaxation.

 bfd/bfd-in2.h                              |   4 +
 bfd/elfnn-riscv.c                          | 341 ++++++++++++++++++---
 bfd/elfxx-riscv.c                          | 130 +++++++-
 bfd/libbfd.h                               |   4 +
 bfd/reloc.c                                |   8 +
 gas/config/tc-riscv.c                      |  18 +-
 gas/testsuite/gas/riscv/tlsdesc.d          |  22 ++
 gas/testsuite/gas/riscv/tlsdesc.s          |  24 ++
 include/elf/riscv.h                        |  21 +-
 include/opcode/riscv.h                     |   1 +
 ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp |   8 +
 ld/testsuite/ld-riscv-elf/tls.d            |  17 +
 ld/testsuite/ld-riscv-elf/tls.s            |  42 +++
 ld/testsuite/ld-riscv-elf/tlsbin.d         |   7 +
 ld/testsuite/ld-riscv-elf/tlslib.s         |   6 +
 opcodes/riscv-opc.c                        |   1 +
 16 files changed, 601 insertions(+), 53 deletions(-)
 create mode 100644 gas/testsuite/gas/riscv/tlsdesc.d
 create mode 100644 gas/testsuite/gas/riscv/tlsdesc.s
 create mode 100644 ld/testsuite/ld-riscv-elf/tls.d
 create mode 100644 ld/testsuite/ld-riscv-elf/tls.s
 create mode 100644 ld/testsuite/ld-riscv-elf/tlsbin.d
 create mode 100644 ld/testsuite/ld-riscv-elf/tlslib.s
  

Comments

Tatsuyuki Ishi Dec. 5, 2023, 4:44 p.m. UTC | #1
> On Nov 28, 2023, at 17:51, Tatsuyuki Ishi <ishitatsuyuki@gmail.com> wrote:
> 
> This patchset implements TLS Descriptors (TLSDESC) for RISC-V targets, per
> the specification (merged) at [1].
> 
> Tested on rv64gc for:
> - No regression (& passing new tests) in binutils
> - No regression in gcc
> - No regression in glibc for subdirs=elf
> With both -mtls-dialect=desc and trad.
> 
> This contribution is made on behalf of Blue Whale Systems, which has
> copyright assignment on file with the FSF.
> 
> [1]: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/373
> 
> v2: Add changelogs and tests. Minor fixes described in patch messages.
> v3: Add relaxation support. This fixes tst-tls1-static in glibc.

Would anyone like to review this?  This is a prerequisite for the GCC-side
implementation to be useful (especially the gas part).

I can split up the series into bug fix / refactors and actual changes if
desired.

> Tatsuyuki Ishi (9):
>  RISC-V: Fix local GOT and reloc size calculation for TLS.
>  RISC-V: Add TLSDESC reloc definitions.
>  RISC-V: Add assembly support for TLSDESC.
>  RISC-V: Define and use GOT entry size constants for TLS.
>  RISC-V: Initial ld.bfd support for TLSDESC.
>  RISC-V: Move STATIC_TLS handling into record_tls_type.
>  RISC-V: Unify TLS handling in check_relocs.
>  RISC-V: Add elf_link_hash_entry to relax_func args.
>  RISC-V: Introduce TLSDESC relaxation.
> 
> bfd/bfd-in2.h                              |   4 +
> bfd/elfnn-riscv.c                          | 341 ++++++++++++++++++---
> bfd/elfxx-riscv.c                          | 130 +++++++-
> bfd/libbfd.h                               |   4 +
> bfd/reloc.c                                |   8 +
> gas/config/tc-riscv.c                      |  18 +-
> gas/testsuite/gas/riscv/tlsdesc.d          |  22 ++
> gas/testsuite/gas/riscv/tlsdesc.s          |  24 ++
> include/elf/riscv.h                        |  21 +-
> include/opcode/riscv.h                     |   1 +
> ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp |   8 +
> ld/testsuite/ld-riscv-elf/tls.d            |  17 +
> ld/testsuite/ld-riscv-elf/tls.s            |  42 +++
> ld/testsuite/ld-riscv-elf/tlsbin.d         |   7 +
> ld/testsuite/ld-riscv-elf/tlslib.s         |   6 +
> opcodes/riscv-opc.c                        |   1 +
> 16 files changed, 601 insertions(+), 53 deletions(-)
> create mode 100644 gas/testsuite/gas/riscv/tlsdesc.d
> create mode 100644 gas/testsuite/gas/riscv/tlsdesc.s
> create mode 100644 ld/testsuite/ld-riscv-elf/tls.d
> create mode 100644 ld/testsuite/ld-riscv-elf/tls.s
> create mode 100644 ld/testsuite/ld-riscv-elf/tlsbin.d
> create mode 100644 ld/testsuite/ld-riscv-elf/tlslib.s
> 
> -- 
> 2.43.0
>
  
Nelson Chu Dec. 6, 2023, 12:33 a.m. UTC | #2
Sorry that I don't familiar with the TLS stuff and TLS descriptor, so I
will need more time to figure these out if other maintainers are all busy.
Since there are other patches which are also being reviewed, if someone
thinks this is an urgent matter, please feel free to let us know, so we can
switch to see these first.

On Wed, Dec 6, 2023 at 12:44 AM Tatsuyuki Ishi <ishitatsuyuki@gmail.com>
wrote:

> > On Nov 28, 2023, at 17:51, Tatsuyuki Ishi <ishitatsuyuki@gmail.com>
> wrote:
> >
> > This patchset implements TLS Descriptors (TLSDESC) for RISC-V targets,
> per
> > the specification (merged) at [1].
> >
> > Tested on rv64gc for:
> > - No regression (& passing new tests) in binutils
> > - No regression in gcc
> > - No regression in glibc for subdirs=elf
> > With both -mtls-dialect=desc and trad.
> >
> > This contribution is made on behalf of Blue Whale Systems, which has
> > copyright assignment on file with the FSF.
> >
> > [1]: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/373
> >
> > v2: Add changelogs and tests. Minor fixes described in patch messages.
> > v3: Add relaxation support. This fixes tst-tls1-static in glibc.
>
> Would anyone like to review this?  This is a prerequisite for the GCC-side
> implementation to be useful (especially the gas part).
>

 For these huge features, gcc/binutils/glibc should be reviewed at the same
time, since all the stuff should be bound and tested together, so
"prerequisite" shouldn't apply here ;)

Thanks
Nelson


>
> I can split up the series into bug fix / refactors and actual changes if
> desired.
>
> > Tatsuyuki Ishi (9):
> >  RISC-V: Fix local GOT and reloc size calculation for TLS.
> >  RISC-V: Add TLSDESC reloc definitions.
> >  RISC-V: Add assembly support for TLSDESC.
> >  RISC-V: Define and use GOT entry size constants for TLS.
> >  RISC-V: Initial ld.bfd support for TLSDESC.
> >  RISC-V: Move STATIC_TLS handling into record_tls_type.
> >  RISC-V: Unify TLS handling in check_relocs.
> >  RISC-V: Add elf_link_hash_entry to relax_func args.
> >  RISC-V: Introduce TLSDESC relaxation.
> >
> > bfd/bfd-in2.h                              |   4 +
> > bfd/elfnn-riscv.c                          | 341 ++++++++++++++++++---
> > bfd/elfxx-riscv.c                          | 130 +++++++-
> > bfd/libbfd.h                               |   4 +
> > bfd/reloc.c                                |   8 +
> > gas/config/tc-riscv.c                      |  18 +-
> > gas/testsuite/gas/riscv/tlsdesc.d          |  22 ++
> > gas/testsuite/gas/riscv/tlsdesc.s          |  24 ++
> > include/elf/riscv.h                        |  21 +-
> > include/opcode/riscv.h                     |   1 +
> > ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp |   8 +
> > ld/testsuite/ld-riscv-elf/tls.d            |  17 +
> > ld/testsuite/ld-riscv-elf/tls.s            |  42 +++
> > ld/testsuite/ld-riscv-elf/tlsbin.d         |   7 +
> > ld/testsuite/ld-riscv-elf/tlslib.s         |   6 +
> > opcodes/riscv-opc.c                        |   1 +
> > 16 files changed, 601 insertions(+), 53 deletions(-)
> > create mode 100644 gas/testsuite/gas/riscv/tlsdesc.d
> > create mode 100644 gas/testsuite/gas/riscv/tlsdesc.s
> > create mode 100644 ld/testsuite/ld-riscv-elf/tls.d
> > create mode 100644 ld/testsuite/ld-riscv-elf/tls.s
> > create mode 100644 ld/testsuite/ld-riscv-elf/tlsbin.d
> > create mode 100644 ld/testsuite/ld-riscv-elf/tlslib.s
> >
> > --
> > 2.43.0
> >
>
>
  
Fangrui Song Dec. 7, 2023, 3:35 a.m. UTC | #3
On Tue, Dec 5, 2023 at 4:33 PM Nelson Chu <nelson@rivosinc.com> wrote:
>
> Sorry that I don't familiar with the TLS stuff and TLS descriptor, so I will need more time to figure these out if other maintainers are all busy.  Since there are other patches which are also being reviewed, if someone thinks this is an urgent matter, please feel free to let us know, so we can switch to see these first.

I know that Android wants TLSDESC and having TLSDESC in gcc/binutils
helps check LLVM feature parity...
If we have TLSDESC earlier, an OS with a new RISC-V port can make
TLSDESC part of the baseline ABI...

> On Wed, Dec 6, 2023 at 12:44 AM Tatsuyuki Ishi <ishitatsuyuki@gmail.com> wrote:
>>
>> > On Nov 28, 2023, at 17:51, Tatsuyuki Ishi <ishitatsuyuki@gmail.com> wrote:
>> >
>> > This patchset implements TLS Descriptors (TLSDESC) for RISC-V targets, per
>> > the specification (merged) at [1].
>> >
>> > Tested on rv64gc for:
>> > - No regression (& passing new tests) in binutils
>> > - No regression in gcc
>> > - No regression in glibc for subdirs=elf
>> > With both -mtls-dialect=desc and trad.
>> >
>> > This contribution is made on behalf of Blue Whale Systems, which has
>> > copyright assignment on file with the FSF.
>> >
>> > [1]: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/373
>> >
>> > v2: Add changelogs and tests. Minor fixes described in patch messages.
>> > v3: Add relaxation support. This fixes tst-tls1-static in glibc.
>>
>> Would anyone like to review this?  This is a prerequisite for the GCC-side
>> implementation to be useful (especially the gas part).
>
>
>  For these huge features, gcc/binutils/glibc should be reviewed at the same time, since all the stuff should be bound and tested together, so "prerequisite" shouldn't apply here ;)
>
> Thanks
> Nelson

Agreed. I wonder whether Wei can find someone to test
gcc/binutils/glibc patches... and some packages using TLS (e.g.
https://codesearch.debian.net/search?q=__thread&literal=1).

>>
>>
>> I can split up the series into bug fix / refactors and actual changes if
>> desired.
>>
>> > Tatsuyuki Ishi (9):
>> >  RISC-V: Fix local GOT and reloc size calculation for TLS.
>> >  RISC-V: Add TLSDESC reloc definitions.
>> >  RISC-V: Add assembly support for TLSDESC.
>> >  RISC-V: Define and use GOT entry size constants for TLS.
>> >  RISC-V: Initial ld.bfd support for TLSDESC.
>> >  RISC-V: Move STATIC_TLS handling into record_tls_type.
>> >  RISC-V: Unify TLS handling in check_relocs.
>> >  RISC-V: Add elf_link_hash_entry to relax_func args.
>> >  RISC-V: Introduce TLSDESC relaxation.
>> >
>> > bfd/bfd-in2.h                              |   4 +
>> > bfd/elfnn-riscv.c                          | 341 ++++++++++++++++++---
>> > bfd/elfxx-riscv.c                          | 130 +++++++-
>> > bfd/libbfd.h                               |   4 +
>> > bfd/reloc.c                                |   8 +
>> > gas/config/tc-riscv.c                      |  18 +-
>> > gas/testsuite/gas/riscv/tlsdesc.d          |  22 ++
>> > gas/testsuite/gas/riscv/tlsdesc.s          |  24 ++
>> > include/elf/riscv.h                        |  21 +-
>> > include/opcode/riscv.h                     |   1 +
>> > ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp |   8 +
>> > ld/testsuite/ld-riscv-elf/tls.d            |  17 +
>> > ld/testsuite/ld-riscv-elf/tls.s            |  42 +++
>> > ld/testsuite/ld-riscv-elf/tlsbin.d         |   7 +
>> > ld/testsuite/ld-riscv-elf/tlslib.s         |   6 +
>> > opcodes/riscv-opc.c                        |   1 +
>> > 16 files changed, 601 insertions(+), 53 deletions(-)
>> > create mode 100644 gas/testsuite/gas/riscv/tlsdesc.d
>> > create mode 100644 gas/testsuite/gas/riscv/tlsdesc.s
>> > create mode 100644 ld/testsuite/ld-riscv-elf/tls.d
>> > create mode 100644 ld/testsuite/ld-riscv-elf/tls.s
>> > create mode 100644 ld/testsuite/ld-riscv-elf/tlsbin.d
>> > create mode 100644 ld/testsuite/ld-riscv-elf/tlslib.s
>> >
>> > --
>> > 2.43.0
>> >
>>
  
Palmer Dabbelt Dec. 13, 2023, 12:27 a.m. UTC | #4
On Wed, 06 Dec 2023 19:35:00 PST (-0800), i@maskray.me wrote:
> On Tue, Dec 5, 2023 at 4:33 PM Nelson Chu <nelson@rivosinc.com> wrote:
>>
>> Sorry that I don't familiar with the TLS stuff and TLS descriptor, so I will need more time to figure these out if other maintainers are all busy.  Since there are other patches which are also being reviewed, if someone thinks this is an urgent matter, please feel free to let us know, so we can switch to see these first.
>
> I know that Android wants TLSDESC and having TLSDESC in gcc/binutils
> helps check LLVM feature parity...
> If we have TLSDESC earlier, an OS with a new RISC-V port can make
> TLSDESC part of the baseline ABI...
>
>> On Wed, Dec 6, 2023 at 12:44 AM Tatsuyuki Ishi <ishitatsuyuki@gmail.com> wrote:
>>>
>>> > On Nov 28, 2023, at 17:51, Tatsuyuki Ishi <ishitatsuyuki@gmail.com> wrote:
>>> >
>>> > This patchset implements TLS Descriptors (TLSDESC) for RISC-V targets, per
>>> > the specification (merged) at [1].
>>> >
>>> > Tested on rv64gc for:
>>> > - No regression (& passing new tests) in binutils
>>> > - No regression in gcc
>>> > - No regression in glibc for subdirs=elf
>>> > With both -mtls-dialect=desc and trad.
>>> >
>>> > This contribution is made on behalf of Blue Whale Systems, which has
>>> > copyright assignment on file with the FSF.
>>> >
>>> > [1]: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/373
>>> >
>>> > v2: Add changelogs and tests. Minor fixes described in patch messages.
>>> > v3: Add relaxation support. This fixes tst-tls1-static in glibc.
>>>
>>> Would anyone like to review this?  This is a prerequisite for the GCC-side
>>> implementation to be useful (especially the gas part).
>>
>>
>>  For these huge features, gcc/binutils/glibc should be reviewed at the same time, since all the stuff should be bound and tested together, so "prerequisite" shouldn't apply here ;)

Ya, I agree.  It's super hard to review stuff like this without seeing 
all the code, doubly so now that the psABI has turned into a wasteland 
for discussions.

>>
>> Thanks
>> Nelson
>
> Agreed. I wonder whether Wei can find someone to test
> gcc/binutils/glibc patches... and some packages using TLS (e.g.
> https://codesearch.debian.net/search?q=__thread&literal=1).

Do you guys have a pointer to the glibc code?  I can't find it, but I'm 
happy to poke it (or maybe find someone else who to poke it...).

>
>>>
>>>
>>> I can split up the series into bug fix / refactors and actual changes if
>>> desired.
>>>
>>> > Tatsuyuki Ishi (9):
>>> >  RISC-V: Fix local GOT and reloc size calculation for TLS.
>>> >  RISC-V: Add TLSDESC reloc definitions.
>>> >  RISC-V: Add assembly support for TLSDESC.
>>> >  RISC-V: Define and use GOT entry size constants for TLS.
>>> >  RISC-V: Initial ld.bfd support for TLSDESC.
>>> >  RISC-V: Move STATIC_TLS handling into record_tls_type.
>>> >  RISC-V: Unify TLS handling in check_relocs.
>>> >  RISC-V: Add elf_link_hash_entry to relax_func args.
>>> >  RISC-V: Introduce TLSDESC relaxation.
>>> >
>>> > bfd/bfd-in2.h                              |   4 +
>>> > bfd/elfnn-riscv.c                          | 341 ++++++++++++++++++---
>>> > bfd/elfxx-riscv.c                          | 130 +++++++-
>>> > bfd/libbfd.h                               |   4 +
>>> > bfd/reloc.c                                |   8 +
>>> > gas/config/tc-riscv.c                      |  18 +-
>>> > gas/testsuite/gas/riscv/tlsdesc.d          |  22 ++
>>> > gas/testsuite/gas/riscv/tlsdesc.s          |  24 ++
>>> > include/elf/riscv.h                        |  21 +-
>>> > include/opcode/riscv.h                     |   1 +
>>> > ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp |   8 +
>>> > ld/testsuite/ld-riscv-elf/tls.d            |  17 +
>>> > ld/testsuite/ld-riscv-elf/tls.s            |  42 +++
>>> > ld/testsuite/ld-riscv-elf/tlsbin.d         |   7 +
>>> > ld/testsuite/ld-riscv-elf/tlslib.s         |   6 +
>>> > opcodes/riscv-opc.c                        |   1 +
>>> > 16 files changed, 601 insertions(+), 53 deletions(-)
>>> > create mode 100644 gas/testsuite/gas/riscv/tlsdesc.d
>>> > create mode 100644 gas/testsuite/gas/riscv/tlsdesc.s
>>> > create mode 100644 ld/testsuite/ld-riscv-elf/tls.d
>>> > create mode 100644 ld/testsuite/ld-riscv-elf/tls.s
>>> > create mode 100644 ld/testsuite/ld-riscv-elf/tlsbin.d
>>> > create mode 100644 ld/testsuite/ld-riscv-elf/tlslib.s
>>> >
>>> > --
>>> > 2.43.0
>>> >
>>>
  
Tatsuyuki Ishi Dec. 13, 2023, 1:53 a.m. UTC | #5
> On Dec 13, 2023, at 9:27, Palmer Dabbelt <palmer@dabbelt.com> wrote:
> 
> On Wed, 06 Dec 2023 19:35:00 PST (-0800), i@maskray.me wrote:
>> On Tue, Dec 5, 2023 at 4:33 PM Nelson Chu <nelson@rivosinc.com> wrote:
>>> 
>>> Sorry that I don't familiar with the TLS stuff and TLS descriptor, so I will need more time to figure these out if other maintainers are all busy.  Since there are other patches which are also being reviewed, if someone thinks this is an urgent matter, please feel free to let us know, so we can switch to see these first.
>> 
>> I know that Android wants TLSDESC and having TLSDESC in gcc/binutils
>> helps check LLVM feature parity...
>> If we have TLSDESC earlier, an OS with a new RISC-V port can make
>> TLSDESC part of the baseline ABI...
>> 
>>> On Wed, Dec 6, 2023 at 12:44 AM Tatsuyuki Ishi <ishitatsuyuki@gmail.com> wrote:
>>>> 
>>>> > On Nov 28, 2023, at 17:51, Tatsuyuki Ishi <ishitatsuyuki@gmail.com> wrote:
>>>> >
>>>> > This patchset implements TLS Descriptors (TLSDESC) for RISC-V targets, per
>>>> > the specification (merged) at [1].
>>>> >
>>>> > Tested on rv64gc for:
>>>> > - No regression (& passing new tests) in binutils
>>>> > - No regression in gcc
>>>> > - No regression in glibc for subdirs=elf
>>>> > With both -mtls-dialect=desc and trad.
>>>> >
>>>> > This contribution is made on behalf of Blue Whale Systems, which has
>>>> > copyright assignment on file with the FSF.
>>>> >
>>>> > [1]: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/373
>>>> >
>>>> > v2: Add changelogs and tests. Minor fixes described in patch messages.
>>>> > v3: Add relaxation support. This fixes tst-tls1-static in glibc.
>>>> 
>>>> Would anyone like to review this?  This is a prerequisite for the GCC-side
>>>> implementation to be useful (especially the gas part).
>>> 
>>> 
>>> For these huge features, gcc/binutils/glibc should be reviewed at the same time, since all the stuff should be bound and tested together, so "prerequisite" shouldn't apply here ;)
> 
> Ya, I agree.  It's super hard to review stuff like this without seeing all the code, doubly so now that the psABI has turned into a wasteland for discussions.
> 
>>> 
>>> Thanks
>>> Nelson
>> 
>> Agreed. I wonder whether Wei can find someone to test
>> gcc/binutils/glibc patches... and some packages using TLS (e.g.
>> https://codesearch.debian.net/search?q=__thread&literal=1).
> 
> Do you guys have a pointer to the glibc code?  I can't find it, but I'm happy to poke it (or maybe find someone else who to poke it...).

Hi,
The glibc and gcc patches are available at [1] and [2] respectively.
For glibc, I still need to implement save/restore stubs for vector ABI, but apart from that it should be functional.

[1]: https://inbox.sourceware.org/libc-alpha/20230914084033.222120-1-ishitatsuyuki@gmail.com/
[2]: https://inbox.sourceware.org/gcc-patches/20231205070152.38360-1-ishitatsuyuki@gmail.com/

Tatsuyuki.

>> 
>>>> 
>>>> 
>>>> I can split up the series into bug fix / refactors and actual changes if
>>>> desired.
>>>> 
>>>> > Tatsuyuki Ishi (9):
>>>> >  RISC-V: Fix local GOT and reloc size calculation for TLS.
>>>> >  RISC-V: Add TLSDESC reloc definitions.
>>>> >  RISC-V: Add assembly support for TLSDESC.
>>>> >  RISC-V: Define and use GOT entry size constants for TLS.
>>>> >  RISC-V: Initial ld.bfd support for TLSDESC.
>>>> >  RISC-V: Move STATIC_TLS handling into record_tls_type.
>>>> >  RISC-V: Unify TLS handling in check_relocs.
>>>> >  RISC-V: Add elf_link_hash_entry to relax_func args.
>>>> >  RISC-V: Introduce TLSDESC relaxation.
>>>> >
>>>> > bfd/bfd-in2.h                              |   4 +
>>>> > bfd/elfnn-riscv.c                          | 341 ++++++++++++++++++---
>>>> > bfd/elfxx-riscv.c                          | 130 +++++++-
>>>> > bfd/libbfd.h                               |   4 +
>>>> > bfd/reloc.c                                |   8 +
>>>> > gas/config/tc-riscv.c                      |  18 +-
>>>> > gas/testsuite/gas/riscv/tlsdesc.d          |  22 ++
>>>> > gas/testsuite/gas/riscv/tlsdesc.s          |  24 ++
>>>> > include/elf/riscv.h                        |  21 +-
>>>> > include/opcode/riscv.h                     |   1 +
>>>> > ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp |   8 +
>>>> > ld/testsuite/ld-riscv-elf/tls.d            |  17 +
>>>> > ld/testsuite/ld-riscv-elf/tls.s            |  42 +++
>>>> > ld/testsuite/ld-riscv-elf/tlsbin.d         |   7 +
>>>> > ld/testsuite/ld-riscv-elf/tlslib.s         |   6 +
>>>> > opcodes/riscv-opc.c                        |   1 +
>>>> > 16 files changed, 601 insertions(+), 53 deletions(-)
>>>> > create mode 100644 gas/testsuite/gas/riscv/tlsdesc.d
>>>> > create mode 100644 gas/testsuite/gas/riscv/tlsdesc.s
>>>> > create mode 100644 ld/testsuite/ld-riscv-elf/tls.d
>>>> > create mode 100644 ld/testsuite/ld-riscv-elf/tls.s
>>>> > create mode 100644 ld/testsuite/ld-riscv-elf/tlsbin.d
>>>> > create mode 100644 ld/testsuite/ld-riscv-elf/tlslib.s
>>>> >
>>>> > --
>>>> > 2.43.0
>>>> >
>>>>
  
Fangrui Song Jan. 27, 2024, 12:57 a.m. UTC | #6
On Tue, Dec 12, 2023 at 5:53 PM Tatsuyuki Ishi <ishitatsuyuki@gmail.com> wrote:
>
> On Dec 13, 2023, at 9:27, Palmer Dabbelt <palmer@dabbelt.com> wrote:
>
> On Wed, 06 Dec 2023 19:35:00 PST (-0800), i@maskray.me wrote:
>
> On Tue, Dec 5, 2023 at 4:33 PM Nelson Chu <nelson@rivosinc.com> wrote:
>
>
> Sorry that I don't familiar with the TLS stuff and TLS descriptor, so I will need more time to figure these out if other maintainers are all busy.  Since there are other patches which are also being reviewed, if someone thinks this is an urgent matter, please feel free to let us know, so we can switch to see these first.
>
>
> I know that Android wants TLSDESC and having TLSDESC in gcc/binutils
> helps check LLVM feature parity...
> If we have TLSDESC earlier, an OS with a new RISC-V port can make
> TLSDESC part of the baseline ABI...
>
> On Wed, Dec 6, 2023 at 12:44 AM Tatsuyuki Ishi <ishitatsuyuki@gmail.com> wrote:
>
>
> > On Nov 28, 2023, at 17:51, Tatsuyuki Ishi <ishitatsuyuki@gmail.com> wrote:
> >
> > This patchset implements TLS Descriptors (TLSDESC) for RISC-V targets, per
> > the specification (merged) at [1].
> >
> > Tested on rv64gc for:
> > - No regression (& passing new tests) in binutils
> > - No regression in gcc
> > - No regression in glibc for subdirs=elf
> > With both -mtls-dialect=desc and trad.
> >
> > This contribution is made on behalf of Blue Whale Systems, which has
> > copyright assignment on file with the FSF.
> >
> > [1]: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/373
> >
> > v2: Add changelogs and tests. Minor fixes described in patch messages.
> > v3: Add relaxation support. This fixes tst-tls1-static in glibc.
>
> Would anyone like to review this?  This is a prerequisite for the GCC-side
> implementation to be useful (especially the gas part).
>
>
>
> For these huge features, gcc/binutils/glibc should be reviewed at the same time, since all the stuff should be bound and tested together, so "prerequisite" shouldn't apply here ;)
>
>
> Ya, I agree.  It's super hard to review stuff like this without seeing all the code, doubly so now that the psABI has turned into a wasteland for discussions.
>
>
> Thanks
> Nelson
>
>
> Agreed. I wonder whether Wei can find someone to test
> gcc/binutils/glibc patches... and some packages using TLS (e.g.
> https://codesearch.debian.net/search?q=__thread&literal=1).
>
>
> Do you guys have a pointer to the glibc code?  I can't find it, but I'm happy to poke it (or maybe find someone else who to poke it...).
>
>
> Hi,
> The glibc and gcc patches are available at [1] and [2] respectively.
> For glibc, I still need to implement save/restore stubs for vector ABI, but apart from that it should be functional.
>
> [1]: https://inbox.sourceware.org/libc-alpha/20230914084033.222120-1-ishitatsuyuki@gmail.com/
> [2]: https://inbox.sourceware.org/gcc-patches/20231205070152.38360-1-ishitatsuyuki@gmail.com/
>
> Tatsuyuki.
>
>
>
>
> I can split up the series into bug fix / refactors and actual changes if
> desired.

On the LLVM side, the RISC-V TLSDESC work (LLVM, Clang, lld) has been
completed today.
(I will frequently update
https://maskray.me/blog/2024-01-23-riscv-tlsdesc-works to track the
status.)
I filed cherry-pick requests into the upcoming 18.1 release.

We postponed the LLVM change to add R_RISCV_RELAX when relaxation is
in effect. That one will not go to the 18.x releases for safety.

If the gas patch is to add one R_RISCV_RELAX to each of the 4 instructions.
Perhaps it can be adjusted to add just one per
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/421 ?

I haven't checked, but for the ld patch, you probably want to consider
TLSDESC to LE/IE optimization regardless of R_RISCV_RELAX.
TLSDESC to LE optimization is essential if a libc doesn't implement
R_RISCV_TLSDESC in its resolocation resolver for a statically linkeded
executable.

It seems that musl will merge the RISC-V TLSDESC patch soon
(https://www.openwall.com/lists/musl/2024/01/27/1 , CCed Tatsuyuki
there).
So even if glibc will take some time to be ready, we will still have a
testable libc :)