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=-3.1 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, 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 13FEF216E4 for ; Mon, 22 Jan 2024 01:03:48 +0100 (CET) Received: (qmail 9982 invoked by uid 550); 22 Jan 2024 00:01:45 -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 9947 invoked from network); 22 Jan 2024 00:01:44 -0000 Date: Sun, 21 Jan 2024 19:03:50 -0500 From: Rich Felker To: Fangrui Song Cc: musl@lists.openwall.com, Tatsuyuki Ishi Message-ID: <20240122000348.GD4163@brightrain.aerifal.cx> References: <20230822173821.GW4163@brightrain.aerifal.cx> <20240121222831.GC4163@brightrain.aerifal.cx> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="RyOXVFQXzAE23HDB" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] Draft riscv64 TLSDESC implementation --RyOXVFQXzAE23HDB Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Sun, Jan 21, 2024 at 03:48:55PM -0800, Fangrui Song wrote: > On Sun, Jan 21, 2024 at 2:28 PM Rich Felker 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? > Downloading patches from these mailing lists is probably a large > hurdle for many users, so having the relevant repositories online may > help. > > 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. To test this, drop it in src/ldso/riscv64/tlsdesc.s, and add to arch/riscv64/reloc.h: #define REL_TLSDESC R_RISCV_TLSDESC or whatever the reloc name is (I don't think it's in elf.h yet so you probably need to either add it there too or just hard-code the number for testing). Updated version with the sp bugfix attached. Rich --RyOXVFQXzAE23HDB Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="tlsdesc.s" .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,-16 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,16 jr t0 --RyOXVFQXzAE23HDB--