From patchwork Wed Oct 16 15:16:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Jeanson X-Patchwork-Id: 99014 Return-Path: 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 977BF3857C68 for ; Wed, 16 Oct 2024 15:16:50 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from smtpout.efficios.com (smtpout.efficios.com [IPv6:2607:5300:203:b2ee::31e5]) by sourceware.org (Postfix) with ESMTPS id 8F57A3858D20 for ; Wed, 16 Oct 2024 15:16:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8F57A3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8F57A3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:5300:203:b2ee::31e5 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729091784; cv=none; b=rNQ5Z4JAgWO5Gr+Ab/VsiOgWfFyqReCqVeaMeuP8AQsaAS8B4z4Cv9dTqUogKMk2Xf/Ny7HX847wRjqmGkH0eB5gYSoYwWrt253BAWxokeZTH9kdoD5O0E0EySWHMQiwMdu8tT5lqVXozHD3bcLt5ohatMmIZNt/DH29daEyeQA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729091784; c=relaxed/simple; bh=/zl3uhjow6ebIsY7ONEqb49Xv9aeUVJH6A2y876ZQso=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=OWLUlzNt0q0gDIr/HUgfiin/NOI0BF5oTglk4trzDEqv0n9RhM2VUhjgEdXMl2k1ZAUdVT8gtqQcdmvVCoVLZXocGy8dYJgkf/kgcelJi9C8mArxGjfG6lXwdwQWugJ/MAvOVNEEdJCN4QCAtBMz6DRwR8wcKsAT6Vwj+CXQCos= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1729091776; bh=/zl3uhjow6ebIsY7ONEqb49Xv9aeUVJH6A2y876ZQso=; h=From:To:Cc:Subject:Date:From; b=rXJyaMFUif15hiT6LBSiU+KwXl6FPeYj0L3MVurfeq2l3xkmUylb4xOsh8brp1n98 T9DCq0oNpcVCPdr+Vy6ATyk4rs0GoGT+JhMUHMPsbd68lvOvrXh45hQToF552JyU21 +2y0kM/hY7PvIGBPx65UNJtqHCu6cFQPQShr+onOlRj4YOv4l4CRLeSPqkOAwB8l+m C0KMlEGkGvseoAXu4Ps2OiM8N3+0WqpQCYI8bTXj2Il0aqSxj4ohu8/p6d3DOO1e/k /aeiDv1/1ritNTbSNBk64p1VVXvUN42YcCjcVPaV4GHkj6zBP5cBs8yQTuXhPt4Q2V r9n8Or0MfF3qw== Received: from mj-deb12-aarch64-glibc.internal.efficios.com (96-127-217-162.qc.cable.ebox.net [96.127.217.162]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4XTF0w0FXjzGGp; Wed, 16 Oct 2024 11:16:16 -0400 (EDT) From: Michael Jeanson To: libc-alpha@sourceware.org Cc: Michael Jeanson , Florian Weimer , Palmer Dabbelt , Darius Rad , Jeff Law Subject: [PATCH v4] nptl: Add for RISC-V Date: Wed, 16 Oct 2024 11:16:10 -0400 Message-Id: <20241016151610.1317813-1-mjeanson@efficios.com> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org This will be required by the rseq extensible ABI implementation on all Linux architectures exposing the '__rseq_size' and '__rseq_offset' symbols to set the initial value of the 'cpu_id' field which can be used by applications to test if rseq is available and registered. As long as the symbols are exposed it is valid for an application to perform this test even if rseq is not yet implemented in libc for this architecture. A cleaner solution for the fallback code would be to use a global 'register' variable, unfortunatly 'tls.h' a non-installed header already defines '__thread_self' for the 'tp' register and GCC doesn't accept multiple global register variables for the same register. Signed-off-by: Michael Jeanson Reviewed-by: Palmer Dabbelt Acked-by: Palmer Dabbelt --- Changes since v3: - Revert to inline asm for the fallback code Changes since v2: - The 'register' variable has to be global to generate the correct asm - Reuse '__thread_self' from 'tls.h' Changes since v1: - Use __glibc_has_builtin instead of GCC version check - Use 'register' variable instead of inline asm --- Cc: Florian Weimer Cc: Palmer Dabbelt Cc: Darius Rad Cc: Jeff Law --- sysdeps/riscv/nptl/thread_pointer.h | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 sysdeps/riscv/nptl/thread_pointer.h diff --git a/sysdeps/riscv/nptl/thread_pointer.h b/sysdeps/riscv/nptl/thread_pointer.h new file mode 100644 index 0000000000..d5dc76c2e2 --- /dev/null +++ b/sysdeps/riscv/nptl/thread_pointer.h @@ -0,0 +1,40 @@ +/* __thread_pointer definition. riscv version. + Copyright (C) 2021-2024 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#ifndef _SYS_THREAD_POINTER_H +#define _SYS_THREAD_POINTER_H + +#include + +#if __glibc_has_builtin (__builtin_thread_pointer) +static inline void * +__thread_pointer (void) +{ + return __builtin_thread_pointer (); +} +#else +static inline void * +__thread_pointer (void) +{ + void *__thread_register; + __asm__ ("mv %0, tp" : "=r" (__thread_register)); + return __thread_register; +} +#endif + +#endif /* _SYS_THREAD_POINTER_H */