From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from second.openwall.net (second.openwall.net [193.110.157.125]) by inbox.vuxu.org (Postfix) with SMTP id B1C2C23C94 for ; Mon, 22 Jan 2024 04:55:07 +0100 (CET) Received: (qmail 17639 invoked by uid 550); 22 Jan 2024 03:53:03 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 28374 invoked from network); 22 Jan 2024 03:36:53 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705894724; x=1706499524; darn=lists.openwall.com; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=rs9LaMlJ9L9natikOi8CP7DlLkOc/FL5xNJb30AIVso=; b=Q47Y6encYCMF++mtE2bXXGGjGpK5ovOHaXh2omyJ5Oj3C0iTAUswzR3LGT+AaQXjkY sRuJk3+EhhuHbEmuusIpjBTYTWtSSzliJGfjtZyhFsgkux0bnQm9XzQHATzMS4Wfb1p9 cVpDfkEhH8H7LYJmGQHlM0KHpzC8TzFvwWAAYOXm05RqKePVQ0Sk6Kuo33eaINnXJAaY BHoJxX4BagUexYWa6MG5NnHCKhvhQTNSY2vo1E18WZWnGOcVoBgtX/lWxz6weICmTKNX x92xF6wk+w9dTfdpoZb/kOXb5MYsfxNhBi/nY3PNyAlxY4ahXvGIAhF5SbPvI8z949+w 9qig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705894724; x=1706499524; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rs9LaMlJ9L9natikOi8CP7DlLkOc/FL5xNJb30AIVso=; b=bqzbOoLWAD8Lm1KmsgG3l9/I1MWtGXeHdoJCHPXXRzjoq9i/7jHYDgrIOyZ2wgc55+ 01f1Z0QJd7ZM+NH7ZEE55Blek7DmkgdHDlTya3rO4o/ctjTtQf50CfzDhG0B0BpK+kfZ 7S48MfXaHdpq3VZOsV9tiEiaTBk/oDd4acjkDm7KrAi6g+4seFmsZp7+vZ94Fiap1d6d QgBP7RNa6wm/8JpBzPXTyfNTeHdeX5DnwqBZF5qAmWLi5uRyLFF5El5hRIwDSOnBRr4f F/JI9WaGI/6MPfhusEYWQVi3ftBLXT0nVpY2R42TcRlIG64pDyTGql8T8dQXcQ2WgAIx RjGQ== X-Gm-Message-State: AOJu0Yy5vRFwh7a5qEy7cswxBuqFupbnnPqj30bqVtUtGdwKvRXIF0LB VvMsccNPBgt64AXQB+/YZRnH8um1a3gUoOptxG9bKIcaq8h3E2qC X-Google-Smtp-Source: AGHT+IFDzzXI4tkSPM0uIqFHw86lVOO5OkdNFPTkTrZ6hZMTLVuS7CWjOqbd2G+ic9K7Bq+eo4+SJA== X-Received: by 2002:a17:90a:46c7:b0:28e:3989:c49f with SMTP id x7-20020a17090a46c700b0028e3989c49fmr4524839pjg.1.1705894723707; Sun, 21 Jan 2024 19:38:43 -0800 (PST) From: Tatsuyuki Ishi Message-Id: <7BADA64C-F60D-49AC-9FCF-EF647B385208@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_61BB7227-592E-4570-8389-27C9B106356A" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.300.61.1.2\)) Date: Mon, 22 Jan 2024 12:38:30 +0900 In-Reply-To: Cc: musl@lists.openwall.com To: Fangrui Song References: <20230822173821.GW4163@brightrain.aerifal.cx> <20240121222831.GC4163@brightrain.aerifal.cx> X-Mailer: Apple Mail (2.3774.300.61.1.2) Subject: Re: [musl] Draft riscv64 TLSDESC implementation --Apple-Mail=_61BB7227-592E-4570-8389-27C9B106356A Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Jan 22, 2024, at 8:48, Fangrui Song wrote: >=20 > On Sun, Jan 21, 2024 at 2:28=E2=80=AFPM Rich Felker = wrote: >>=20 >> 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. >>>=20 >>> 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. >>>=20 >>> Rich >>=20 >>> .text >>> .global __tlsdesc_static >>> .hidden __tlsdesc_static >>> .type __tlsdesc_static,%function >>> __tlsdesc_static: >>> ld a0,8(a0) >>> jr t0 >>>=20 >>> .global __tlsdesc_dynamic >>> .hidden __tlsdesc_dynamic >>> .type __tlsdesc_dynamic,%function >>> __tlsdesc_dynamic: >>> add sp,sp,-8 >>> sd t1,(sp) >>> sd t2,8(sp) >>>=20 >>> ld t2,-8(tp) # t2=3Ddtv >>>=20 >>> ld a0,8(a0) # a0=3D&{modidx,off} >>> ld t1,8(a0) # t1=3Doff >>> ld a0,(a0) # a0=3Dmodidx >>> sll a0,a0,3 # a0=3D8*modidx >>>=20 >>> add a0,a0,t2 # a0=3Ddtv+8*modidx >>> ld a0,(a0) # a0=3Ddtv[modidx] >>> add a0,a0,t1 # a0=3Ddtv[modidx]+off >>> sub a0,a0,tp # a0=3Ddtv[modidx]+off-tp >>>=20 >>> ld t1,(sp) >>> ld t2,8(sp) >>> add sp,sp,8 >>> jr t0 >>=20 >> 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? >=20 > 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=E2=80=99m 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=E2=80=99ll 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-ishitatsuy= uki@gmail.com/ [3]: = https://inbox.sourceware.org/gcc-patches/20231205070152.38360-1-ishitatsuy= uki@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. >=20 > 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. --Apple-Mail=_61BB7227-592E-4570-8389-27C9B106356A Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
On Jan 22, 2024, = at 8:48, Fangrui Song <i@maskray.me> wrote:

On Sun, Jan 21, 2024 at = 2:28=E2=80=AFPM 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=3Ddtv

=      ld a0,8(a0)  # = a0=3D&{modidx,off}
     ld t1,8(a0) =  # t1=3Doff
     ld a0,(a0) =   # a0=3Dmodidx
     sll a0,a0,3 =  # a0=3D8*modidx

     add a0,a0,t2 = # a0=3Ddtv+8*modidx
     ld a0,(a0) =   # a0=3Ddtv[modidx]
     add = a0,a0,t1 # a0=3Ddtv[modidx]+off
     sub = a0,a0,tp # a0=3Ddtv[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=E2=80=99= 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=E2=80=99ll = 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.


Ta= tsuyuki.

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.

= --Apple-Mail=_61BB7227-592E-4570-8389-27C9B106356A--