mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Tatsuyuki Ishi <ishitatsuyuki@gmail.com>
To: Fangrui Song <i@maskray.me>
Cc: musl@lists.openwall.com
Subject: Re: [musl] Draft riscv64 TLSDESC implementation
Date: Mon, 22 Jan 2024 12:38:30 +0900	[thread overview]
Message-ID: <7BADA64C-F60D-49AC-9FCF-EF647B385208@gmail.com> (raw)
In-Reply-To: <DS7PR12MB576582CD9FF325AAE6FA8B0CCB762@DS7PR12MB5765.namprd12.prod.outlook.com>

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

> On Jan 22, 2024, at 8:48, Fangrui Song <i@maskray.me> wrote:
> 
> On Sun, Jan 21, 2024 at 2:28 PM Rich Felker <dalias@libc.org> wrote:
>> 
>> On Tue, Aug 22, 2023 at 01:38:21PM -0400, Rich Felker wrote:
>>> The psABI work is not finalized, but based on the current status of
>>> https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/373, I think
>>> the attached is a valid (but untested) implementation of TLSDESC for
>>> riscv64. Actually activating it requires also adding the relocation
>>> type macro to riscv64/reloc.h.
>>> 
>>> If any rv folks could look it over and make sure I haven't made any
>>> stupid asm errors or missed any obvious optimizations, that would help
>>> to quickly get this merged when the psABI is finalized.
>>> 
>>> Rich
>> 
>>> .text
>>> .global __tlsdesc_static
>>> .hidden __tlsdesc_static
>>> .type __tlsdesc_static,%function
>>> __tlsdesc_static:
>>>      ld a0,8(a0)
>>>      jr t0
>>> 
>>> .global __tlsdesc_dynamic
>>> .hidden __tlsdesc_dynamic
>>> .type __tlsdesc_dynamic,%function
>>> __tlsdesc_dynamic:
>>>      add sp,sp,-8
>>>      sd t1,(sp)
>>>      sd t2,8(sp)
>>> 
>>>      ld t2,-8(tp) # t2=dtv
>>> 
>>>      ld a0,8(a0)  # a0=&{modidx,off}
>>>      ld t1,8(a0)  # t1=off
>>>      ld a0,(a0)   # a0=modidx
>>>      sll a0,a0,3  # a0=8*modidx
>>> 
>>>      add a0,a0,t2 # a0=dtv+8*modidx
>>>      ld a0,(a0)   # a0=dtv[modidx]
>>>      add a0,a0,t1 # a0=dtv[modidx]+off
>>>      sub a0,a0,tp # a0=dtv[modidx]+off-tp
>>> 
>>>      ld t1,(sp)
>>>      ld t2,8(sp)
>>>      add sp,sp,8
>>>      jr t0
>> 
>> Any feedback on this? Offhand, it looks like adjusting sp by 8 is
>> wrong and that should be 16. Anything else? Does anyone have recent
>> enough tooling to test this?
> 
> Tatsuyuki, do you have links to the latest version of
> gcc/binutils/glibc patches?

The latest revisions are at [1,2,3]. I have plans to do a revision on binutils for more tests, and glibc for supporting saving vector registers, but I’m occupied with other priorities until the end of January.

> Downloading patches from these mailing lists is probably a large
> hurdle for many users, so having the relevant repositories online may
> help.

I’ll also link my GitHub repositories containing the same code at [4,5,6]. Right now they have some WIP commits (planned for sending in newer revisions) added on top, but they should still work fine.

[1]: https://inbox.sourceware.org/binutils/20231128085109.28422-1-ishitatsuyuki@gmail.com/
[2]: https://inbox.sourceware.org/libc-alpha/20230914084033.222120-1-ishitatsuyuki@gmail.com/
[3]: https://inbox.sourceware.org/gcc-patches/20231205070152.38360-1-ishitatsuyuki@gmail.com/
[4]: https://github.com/ishitatsuyuki/binutils/tree/rv-tlsdesc
[5]: https://github.com/ishitatsuyuki/glibc/tree/rv-tlsdesc/
[6]: https://github.com/ishitatsuyuki/gcc/tree/rv-tlsdesc/

Tatsuyuki.

> mold has implemented RISC-V TLSDESC.
> 
> On the LLVM side, I have reviewed
> https://github.com/llvm/llvm-project/pull/66915 and am waiting for it
> to land, before I can check the lld status.


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

      parent reply	other threads:[~2024-01-22  3:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-22 17:38 Rich Felker
2024-01-21 22:28 ` Rich Felker
2024-01-21 23:48   ` Fangrui Song
2024-01-22  0:03     ` Rich Felker
2024-01-22  3:41       ` Tatsuyuki Ishi
2024-01-23  8:52         ` Fangrui Song
2024-01-23 13:26           ` Rich Felker
2024-01-25  6:48             ` Fangrui Song
     [not found]             ` <CAN30aBFHo2NmDknvhVUyWOvXuhvFZBvrzO6vm1PqEB7e2P9NTg@mail.gmail.com>
2024-01-27  0:11               ` Fangrui Song
     [not found]   ` <DS7PR12MB576582CD9FF325AAE6FA8B0CCB762@DS7PR12MB5765.namprd12.prod.outlook.com>
2024-01-22  3:38     ` Tatsuyuki Ishi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7BADA64C-F60D-49AC-9FCF-EF647B385208@gmail.com \
    --to=ishitatsuyuki@gmail.com \
    --cc=i@maskray.me \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public 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).