Message ID | 20240329061834.40019-1-ishitatsuyuki@gmail.com (mailing list archive) |
---|---|
Headers |
Return-Path: <libc-alpha-bounces+patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D7917385B532 for <patchwork@sourceware.org>; Fri, 29 Mar 2024 06:19:21 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 7AAD43858D20 for <libc-alpha@sourceware.org>; Fri, 29 Mar 2024 06:18:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7AAD43858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7AAD43858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::430 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711693136; cv=none; b=Ci6mhjU1Icj+MMSkcMiNA8ZwSR08TUEZQ5Jtm2Ry1o2K/e5BqY5VsJhD4aBk/2s2Jkd9lT5C2mns91J40bml4BceMqpBruVBrJCULztppUQqNHDnY7eEJeMSuTpI7WlP2Up+t8d01NU4PwI2wZ/hlxAkFA2O3J8N/cIJLEL0TUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711693136; c=relaxed/simple; bh=xPV7D7SpyhOoU0WDKT08OoCwyO8cBalrzz+BV9KuCto=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=p37kHsrdMw4hZ/SKp2dOSvBR0USg5DJGh+XUpVkcZZ+8iM7B+Rgy8zNTR2eLoYqUXFPaPaoesUCEMOf+JbZI1H7mwmAM3nLihjbd+AfqXxZNRzQP7SkGvmYJtw4Y2ag8TGMHOKOVSXVXueqVOqIco8M6mYDhLX+gfoAjKDx4B94= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6e6c38be762so179046b3a.1 for <libc-alpha@sourceware.org>; Thu, 28 Mar 2024 23:18:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711693124; x=1712297924; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Zx70sXG6JLMkoskPMAKXrNINOef3jqsOQAqnlJVYYcY=; b=HM7KtwACLNhW9P3ZQj2D56XkB20X/s6HU6PrKTKqJlXY6XnSEjF6wzKuZeeisckW7A rGNSRd+A5kmEQh7qZMTYsWTFfUp/PJzEVkvxb2tp7WiDTcHx8TXiMi5+NmwRD08JXRHJ sfVW3y3KoBKY/FbuvxbIDC1xilpddR2f/N75MT/nSmlYAFXz7iKvDj1WNg8VmG76NCnT Pcxo2o2M5j5w1deILIn53LWtoDwiuhYnj/jFiFrHfVp6K4ysyHkwH1u3u/0hJEUqJSvI oYWOjxqUbBvRr8pybFQqULatQUdPpdsR4fn9qG5E0Bh03xzTT7IFeSoCdQuHMO74iaCA Mbrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711693124; x=1712297924; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Zx70sXG6JLMkoskPMAKXrNINOef3jqsOQAqnlJVYYcY=; b=Wl2J5MqPlA4Cy+XEbzmWFRIZEKjDlSAJ4wEBPiotrzBqWCEQiv7RNM9/J03JWPhG6V 2tyW5xemr8+ZMCcP4/o4lmv5nzWXFB65Montb7ihVFWfX2+0/ETwdVIraKX7a9zcovwg mVsOss3QgT62y6IUs6s3I82j5/DSdVLOLAR8k0uWAtXuAhvDKDs9zL6SHfY0heFOmp7O jh47Xlgw6yQu+mpHmE1xKCk0fFf7riOVCmGNAaGV9JSurxr3Xu9FbBbbc0egkEVVRLSO SoSmclA8+Jf6p0MtsCtVE2U+UdZO1f5WczE5UGqD2B5dxK44vWZY45ok96NxVNXZpLnZ wHTg== X-Gm-Message-State: AOJu0YxdH9BOkRI2z3VqxA7dANPnqR6ihNjlRGINRbdH+i12wOCEWiIf 85DgSQCiW9gnEz2xhMZF4zlf95uqSkkBqT1EHf7094+nXJcvutT8 X-Google-Smtp-Source: AGHT+IH9eQXZKnHw58S+SPxclOfldA1kM9tU1Hfh0JG3Cp95f9m5yDFwLStPBZhDlgJLRDssBbQQXA== X-Received: by 2002:a05:6a20:3c86:b0:1a5:699f:289a with SMTP id b6-20020a056a203c8600b001a5699f289amr1294220pzj.6.1711693124310; Thu, 28 Mar 2024 23:18:44 -0700 (PDT) Received: from localhost (zz20184013906F627101.userreverse.dion.ne.jp. [111.98.113.1]) by smtp.gmail.com with ESMTPSA id lc13-20020a170902fa8d00b001e0c949124fsm2686664plb.309.2024.03.28.23.18.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 23:18:43 -0700 (PDT) From: Tatsuyuki Ishi <ishitatsuyuki@gmail.com> To: ishitatsuyuki@gmail.com Cc: libc-alpha@sourceware.org, rui314@gmail.com, ruiu@bluewhale.systems, schwab@linux-m68k.org, adhemerval.zanella@linaro.org, andrew@sifive.com, fweimer@redhat.com Subject: [PATCH v6 0/3] RISC-V: Implement TLS Descriptors. Date: Fri, 29 Mar 2024 15:18:31 +0900 Message-ID: <20240329061834.40019-1-ishitatsuyuki@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20230817181228.122674-2-ishitatsuyuki@gmail.com> References: <20230817181228.122674-2-ishitatsuyuki@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org |
Series |
RISC-V: Implement TLS Descriptors.
|
|
Message
Tatsuyuki Ishi
March 29, 2024, 6:18 a.m. UTC
This patchset implements TLS Descriptors (TLSDESC) for RISC-V targets, per the ratified specification at [1]. Partial support for TLSDESC is in binutils trunk. In [2] there is additional support for relaxation which is required to pass tst-tls1-static. GCC needs to be patched with [3]. Passes binutils and gcc tests for rv32gcv and rv64gcv. For glibc I only tested elf/ as other subsystems sometimes doesn't work well under qemu. This contribution is made on behalf of Blue Whale Systems, which has copyright assignment on file with the FSF. v2: Fix end-of-file newlines. v3: Fix segfaulting on the slow path of TLSDESC resolver. Fix handling of lazy relocations. v4: Fix compiler warnings. Fix fast path stack alignment pointed out by Andrew. Fix style issues pointed out by Adhemerval. Include 2 missing prerequisite commits. Update localplt list. v5: Add stubs for save/restore of vector registers. Add comments and reordered sections for readability in the TLSDESC assembly. Add clobber test sequence for tst-gnu2-tls2. v6: Fix R_RISCV_NUM. Elaborate on the include guard commit (thanks Fangrui). [1]: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/373 [2]: https://inbox.sourceware.org/binutils/20240220175556.304692-1-ishitatsuyuki@gmail.com/ [3]: https://inbox.sourceware.org/gcc-patches/20240329055239.29719-1-ishitatsuyuki@gmail.com/ Tatsuyuki Ishi (3): RISC-V: Add include guard for dl-tls.h. RISC-V: Add TLSDESC reloc definitions. RISC-V: Implement TLS Descriptors. elf/elf.h | 7 +- sysdeps/riscv/Makefile | 10 + sysdeps/riscv/dl-lookupcfg.h | 27 ++ sysdeps/riscv/dl-machine.h | 50 +++- sysdeps/riscv/dl-tls.h | 4 + sysdeps/riscv/dl-tlsdesc.S | 269 ++++++++++++++++++++ sysdeps/riscv/dl-tlsdesc.h | 48 ++++ sysdeps/riscv/linkmap.h | 1 + sysdeps/riscv/preconfigure | 1 + sysdeps/riscv/tlsdesc.c | 38 +++ sysdeps/riscv/tlsdesc.sym | 19 ++ sysdeps/riscv/tst-gnu2-tls2.c | 33 +++ sysdeps/unix/sysv/linux/riscv/localplt.data | 2 + 13 files changed, 507 insertions(+), 2 deletions(-) create mode 100644 sysdeps/riscv/dl-lookupcfg.h create mode 100644 sysdeps/riscv/dl-tlsdesc.S create mode 100644 sysdeps/riscv/dl-tlsdesc.h create mode 100644 sysdeps/riscv/tlsdesc.c create mode 100644 sysdeps/riscv/tlsdesc.sym create mode 100644 sysdeps/riscv/tst-gnu2-tls2.c
Comments
On Thu, 28 Mar 2024 23:18:31 PDT (-0700), ishitatsuyuki@gmail.com wrote: > This patchset implements TLS Descriptors (TLSDESC) for RISC-V targets, per > the ratified specification at [1]. > > Partial support for TLSDESC is in binutils trunk. In [2] there is > additional support for relaxation which is required to pass > tst-tls1-static. GCC needs to be patched with [3]. > > Passes binutils and gcc tests for rv32gcv and rv64gcv. For glibc I only > tested elf/ as other subsystems sometimes doesn't work well under qemu. > > This contribution is made on behalf of Blue Whale Systems, which has > copyright assignment on file with the FSF. > > v2: Fix end-of-file newlines. > v3: Fix segfaulting on the slow path of TLSDESC resolver. > Fix handling of lazy relocations. > v4: Fix compiler warnings. > Fix fast path stack alignment pointed out by Andrew. > Fix style issues pointed out by Adhemerval. > Include 2 missing prerequisite commits. > Update localplt list. > v5: Add stubs for save/restore of vector registers. > Add comments and reordered sections for readability in the TLSDESC assembly. > Add clobber test sequence for tst-gnu2-tls2. > v6: Fix R_RISCV_NUM. > Elaborate on the include guard commit (thanks Fangrui). > > [1]: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/373 > [2]: https://inbox.sourceware.org/binutils/20240220175556.304692-1-ishitatsuyuki@gmail.com/ > [3]: https://inbox.sourceware.org/gcc-patches/20240329055239.29719-1-ishitatsuyuki@gmail.com/ > > Tatsuyuki Ishi (3): > RISC-V: Add include guard for dl-tls.h. > RISC-V: Add TLSDESC reloc definitions. > RISC-V: Implement TLS Descriptors. > > elf/elf.h | 7 +- > sysdeps/riscv/Makefile | 10 + > sysdeps/riscv/dl-lookupcfg.h | 27 ++ > sysdeps/riscv/dl-machine.h | 50 +++- > sysdeps/riscv/dl-tls.h | 4 + > sysdeps/riscv/dl-tlsdesc.S | 269 ++++++++++++++++++++ > sysdeps/riscv/dl-tlsdesc.h | 48 ++++ > sysdeps/riscv/linkmap.h | 1 + > sysdeps/riscv/preconfigure | 1 + > sysdeps/riscv/tlsdesc.c | 38 +++ > sysdeps/riscv/tlsdesc.sym | 19 ++ > sysdeps/riscv/tst-gnu2-tls2.c | 33 +++ > sysdeps/unix/sysv/linux/riscv/localplt.data | 2 + > 13 files changed, 507 insertions(+), 2 deletions(-) > create mode 100644 sysdeps/riscv/dl-lookupcfg.h > create mode 100644 sysdeps/riscv/dl-tlsdesc.S > create mode 100644 sysdeps/riscv/dl-tlsdesc.h > create mode 100644 sysdeps/riscv/tlsdesc.c > create mode 100644 sysdeps/riscv/tlsdesc.sym > create mode 100644 sysdeps/riscv/tst-gnu2-tls2.c This generally LGTM, but IIUC we're waiting on a glibc-wide decision as to what the stable ABIs should be around TLS before moving forward.
On 30/04/24 14:05, Palmer Dabbelt wrote: > On Thu, 28 Mar 2024 23:18:31 PDT (-0700), ishitatsuyuki@gmail.com wrote: >> This patchset implements TLS Descriptors (TLSDESC) for RISC-V targets, per >> the ratified specification at [1]. >> >> Partial support for TLSDESC is in binutils trunk. In [2] there is >> additional support for relaxation which is required to pass >> tst-tls1-static. GCC needs to be patched with [3]. >> >> Passes binutils and gcc tests for rv32gcv and rv64gcv. For glibc I only >> tested elf/ as other subsystems sometimes doesn't work well under qemu. >> >> This contribution is made on behalf of Blue Whale Systems, which has >> copyright assignment on file with the FSF. >> >> v2: Fix end-of-file newlines. >> v3: Fix segfaulting on the slow path of TLSDESC resolver. >> Fix handling of lazy relocations. >> v4: Fix compiler warnings. >> Fix fast path stack alignment pointed out by Andrew. >> Fix style issues pointed out by Adhemerval. >> Include 2 missing prerequisite commits. >> Update localplt list. >> v5: Add stubs for save/restore of vector registers. >> Add comments and reordered sections for readability in the TLSDESC assembly. >> Add clobber test sequence for tst-gnu2-tls2. >> v6: Fix R_RISCV_NUM. >> Elaborate on the include guard commit (thanks Fangrui). >> >> [1]: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/373 >> [2]: https://inbox.sourceware.org/binutils/20240220175556.304692-1-ishitatsuyuki@gmail.com/ >> [3]: https://inbox.sourceware.org/gcc-patches/20240329055239.29719-1-ishitatsuyuki@gmail.com/ >> >> Tatsuyuki Ishi (3): >> RISC-V: Add include guard for dl-tls.h. >> RISC-V: Add TLSDESC reloc definitions. >> RISC-V: Implement TLS Descriptors. >> >> elf/elf.h | 7 +- >> sysdeps/riscv/Makefile | 10 + >> sysdeps/riscv/dl-lookupcfg.h | 27 ++ >> sysdeps/riscv/dl-machine.h | 50 +++- >> sysdeps/riscv/dl-tls.h | 4 + >> sysdeps/riscv/dl-tlsdesc.S | 269 ++++++++++++++++++++ >> sysdeps/riscv/dl-tlsdesc.h | 48 ++++ >> sysdeps/riscv/linkmap.h | 1 + >> sysdeps/riscv/preconfigure | 1 + >> sysdeps/riscv/tlsdesc.c | 38 +++ >> sysdeps/riscv/tlsdesc.sym | 19 ++ >> sysdeps/riscv/tst-gnu2-tls2.c | 33 +++ >> sysdeps/unix/sysv/linux/riscv/localplt.data | 2 + >> 13 files changed, 507 insertions(+), 2 deletions(-) >> create mode 100644 sysdeps/riscv/dl-lookupcfg.h >> create mode 100644 sysdeps/riscv/dl-tlsdesc.S >> create mode 100644 sysdeps/riscv/dl-tlsdesc.h >> create mode 100644 sysdeps/riscv/tlsdesc.c >> create mode 100644 sysdeps/riscv/tlsdesc.sym >> create mode 100644 sysdeps/riscv/tst-gnu2-tls2.c > > This generally LGTM, but IIUC we're waiting on a glibc-wide decision as to what the stable ABIs should be around TLS before moving forward. If I recall correctly, my latest remarks for this patch was: 1. Missing gcc/binutils upstream support (usually we wait the patches to be upstream on the required projects) 2. Call the internal __tls_get_addr on _dl_tlsdesc_dynamic to avoid the PLT call. 3. Decide how RISCV would like to handle different ABI constraint for the _dl_tlsdesc_dynamic, now that you are moving to support ifunc and thus allowing a more generic glibc build. You can either make the _dl_tlsdesc_dynamic with multiple ifunc variants (as x86 does), or check the chip support through the riscv_hwprobe on the function itself and only save/restore the support ABI register.
> On May 1, 2024, at 3:33, Adhemerval Zanella Netto <adhemerval.zanella@linaro.org> wrote: > > On 30/04/24 14:05, Palmer Dabbelt wrote: >> On Thu, 28 Mar 2024 23:18:31 PDT (-0700), ishitatsuyuki@gmail.com wrote: >>> This patchset implements TLS Descriptors (TLSDESC) for RISC-V targets, per >>> the ratified specification at [1]. >>> >>> Partial support for TLSDESC is in binutils trunk. In [2] there is >>> additional support for relaxation which is required to pass >>> tst-tls1-static. GCC needs to be patched with [3]. >>> >>> Passes binutils and gcc tests for rv32gcv and rv64gcv. For glibc I only >>> tested elf/ as other subsystems sometimes doesn't work well under qemu. >>> >>> This contribution is made on behalf of Blue Whale Systems, which has >>> copyright assignment on file with the FSF. >>> >>> v2: Fix end-of-file newlines. >>> v3: Fix segfaulting on the slow path of TLSDESC resolver. >>> Fix handling of lazy relocations. >>> v4: Fix compiler warnings. >>> Fix fast path stack alignment pointed out by Andrew. >>> Fix style issues pointed out by Adhemerval. >>> Include 2 missing prerequisite commits. >>> Update localplt list. >>> v5: Add stubs for save/restore of vector registers. >>> Add comments and reordered sections for readability in the TLSDESC assembly. >>> Add clobber test sequence for tst-gnu2-tls2. >>> v6: Fix R_RISCV_NUM. >>> Elaborate on the include guard commit (thanks Fangrui). >>> >>> [1]: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/373 >>> [2]: https://inbox.sourceware.org/binutils/20240220175556.304692-1-ishitatsuyuki@gmail.com/ >>> [3]: https://inbox.sourceware.org/gcc-patches/20240329055239.29719-1-ishitatsuyuki@gmail.com/ >>> >>> Tatsuyuki Ishi (3): >>> RISC-V: Add include guard for dl-tls.h. >>> RISC-V: Add TLSDESC reloc definitions. >>> RISC-V: Implement TLS Descriptors. >>> >>> elf/elf.h | 7 +- >>> sysdeps/riscv/Makefile | 10 + >>> sysdeps/riscv/dl-lookupcfg.h | 27 ++ >>> sysdeps/riscv/dl-machine.h | 50 +++- >>> sysdeps/riscv/dl-tls.h | 4 + >>> sysdeps/riscv/dl-tlsdesc.S | 269 ++++++++++++++++++++ >>> sysdeps/riscv/dl-tlsdesc.h | 48 ++++ >>> sysdeps/riscv/linkmap.h | 1 + >>> sysdeps/riscv/preconfigure | 1 + >>> sysdeps/riscv/tlsdesc.c | 38 +++ >>> sysdeps/riscv/tlsdesc.sym | 19 ++ >>> sysdeps/riscv/tst-gnu2-tls2.c | 33 +++ >>> sysdeps/unix/sysv/linux/riscv/localplt.data | 2 + >>> 13 files changed, 507 insertions(+), 2 deletions(-) >>> create mode 100644 sysdeps/riscv/dl-lookupcfg.h >>> create mode 100644 sysdeps/riscv/dl-tlsdesc.S >>> create mode 100644 sysdeps/riscv/dl-tlsdesc.h >>> create mode 100644 sysdeps/riscv/tlsdesc.c >>> create mode 100644 sysdeps/riscv/tlsdesc.sym >>> create mode 100644 sysdeps/riscv/tst-gnu2-tls2.c >> >> This generally LGTM, but IIUC we're waiting on a glibc-wide decision as to what the stable ABIs should be around TLS before moving forward. > > If I recall correctly, my latest remarks for this patch was: > > 1. Missing gcc/binutils upstream support (usually we wait the patches > to be upstream on the required projects) For a status update, binutils have partial TLSDESC support (without relaxation) committed and GCC have all the required patches committed. This means tst-tls-static-1 will still fail with upstream toolchain, though. > 2. Call the internal __tls_get_addr on _dl_tlsdesc_dynamic to avoid > the PLT call. This was a trivial change, and I will include it in the next version. > 3. Decide how RISCV would like to handle different ABI constraint for > the _dl_tlsdesc_dynamic, now that you are moving to support ifunc > and thus allowing a more generic glibc build. You can either make > the _dl_tlsdesc_dynamic with multiple ifunc variants (as x86 does), > or check the chip support through the riscv_hwprobe on the function > itself and only save/restore the support ABI register. Note that we don’t really have any of the cpu_features scaffolding in RISC-V, so going down the IFUNC route seems a lot more annoying. I’m working on adding a call to riscv_hwprobe in _dl_tlsdesc_dynamic. I need some more time to figure out how to configure user mode QEMU to test all the code paths. As for TLS ABI decision, it would be good if we decide on a calling convention, but shipping a stub that saves / restores all vector registers should also be OK (which is what the current revision do). Tatsuyuki