From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id C58B638582A4 for ; Wed, 2 Aug 2023 15:59:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C58B638582A4 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-686f25d045cso4857391b3a.0 for ; Wed, 02 Aug 2023 08:59:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1690991958; x=1691596758; 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=HVdHB9RS+mhMnuqPp0HKIsITd7TNpPWPC+rLUDp1blk=; b=RCmbY1N3jCLIvBi9hDXTpfEoK1G2c9aXGn1gm39g0ZIET1SIYuaJHHRaD5jHJY1BsB 4jK3RGn7OmllBUdZKWSKHAEmDQpA7/ta+OUrwoVeP4gIUO82Qsrq8KKmDO0PcFYZZMG4 Ztc4DvCUoRaSolur/uR9fR/T0f8AO6k4kfLLXf5SN2FrxYsG9WYEt+e3H/9HvOuHnh0z wDdV11nPM854A5SPgCp7QozVzV48z7UlbMV6JfQcHOP5J8PGLUIk362aFT+LIBxn/KTq Vv5NOURgFWTfCs9uHtm8BuEulWmgwuUxoROlX0yDDUj3v31Wtty7JnRWQhmbwKIy0u7J YNNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690991958; x=1691596758; 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=HVdHB9RS+mhMnuqPp0HKIsITd7TNpPWPC+rLUDp1blk=; b=apvm7N6Hz555sbRjTNEW8ZLAYbd6JzYoXl9sD742DrEuzYCcFnU9vpD8ipvHz9029L y+hTqM3m01LOA/vo63yc5qYq9UAZ+9fRsB9zYs96iabh7a115yLl8qFz1Qf4DSjNRVks FuAH0r213KbleCcTFMVSc8dDSYcDF3dUicsjt4RCgWALCBHAnZGO+IK2FRWoTKbf9YG4 UNCqMsDV/uK+BYWG2lJCYktHZJUy45G7+k3MBnQ1+nTyf+JtVqHDbPFir4+8IRJBtP8Z 7+KNMzm03lgthqd4Y/6BFAJy2PsNbH+cko5IFAt3kuFVYuXbpvq4/+WoDMtEWHAGs9ZP elnA== X-Gm-Message-State: ABy/qLZ/zXEJPaR2NErrDq76+Po9NwAu4yMWcV4YTO3IUtUCpFL3Oo/X 4aNLQKdKrDZ9Kkjv4K7170UCQI63II3O6PH2mlM= X-Google-Smtp-Source: APBJJlE0ghqb+AFkgLUZ5BBUSRtiW+/rZNPaKdxfxFY/LnR9TSXDPT8+oiDL7R+pmXnqZAs7J9k+1Q== X-Received: by 2002:a05:6a20:4299:b0:133:2fb2:917d with SMTP id o25-20020a056a20429900b001332fb2917dmr17607455pzj.5.1690991958386; Wed, 02 Aug 2023 08:59:18 -0700 (PDT) Received: from evan.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id i5-20020aa787c5000000b00682936d04ccsm11200091pfo.180.2023.08.02.08.59.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 08:59:18 -0700 (PDT) From: Evan Green To: libc-alpha@sourceware.org Cc: slewis@rivosinc.com, Florian Weimer , palmer@rivosinc.com, vineetg@rivosinc.com, Evan Green Subject: [PATCH v6 3/5] riscv: Add __riscv_hwprobe pointer to ifunc calls Date: Wed, 2 Aug 2023 08:59:01 -0700 Message-Id: <20230802155903.2552780-4-evan@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230802155903.2552780-1-evan@rivosinc.com> References: <20230802155903.2552780-1-evan@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: The new __riscv_hwprobe() function is designed to be used by ifunc selector functions. This presents a challenge for applications and libraries, as ifunc selectors are invoked before all relocations have been performed, so an external call to __riscv_hwprobe() from an ifunc selector won't work. To address this, pass a pointer to the __riscv_hwprobe() vDSO function into ifunc selectors as the second argument (alongside dl_hwcap, which was already being passed). Include a typedef as well for convenience, so that ifunc users don't have to go through contortions to call this routine. Users will need to remember to check the second argument for NULL, both to account for older glibcs that don't pass the function, and older kernels that don't have the vDSO pointer. Signed-off-by: Evan Green --- (no changes since v1) sysdeps/riscv/dl-irel.h | 8 ++++---- sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h | 10 ++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/sysdeps/riscv/dl-irel.h b/sysdeps/riscv/dl-irel.h index eaeec5467c..2147504458 100644 --- a/sysdeps/riscv/dl-irel.h +++ b/sysdeps/riscv/dl-irel.h @@ -31,10 +31,10 @@ static inline ElfW(Addr) __attribute ((always_inline)) elf_ifunc_invoke (ElfW(Addr) addr) { - /* The second argument is a void pointer to preserve the extension - fexibility. */ - return ((ElfW(Addr) (*) (uint64_t, void *)) (addr)) - (GLRO(dl_hwcap), NULL); + /* The third argument is a void pointer to preserve the extension + flexibility. */ + return ((ElfW(Addr) (*) (uint64_t, void *, void *)) (addr)) + (GLRO(dl_hwcap), GLRO(dl_vdso_riscv_hwprobe), NULL); } static inline void diff --git a/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h b/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h index 63372c5a94..1f02416bd8 100644 --- a/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h +++ b/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h @@ -67,6 +67,16 @@ extern int __riscv_hwprobe (struct riscv_hwprobe *__pairs, size_t __pair_count, __fortified_attr_access (__read_write__, 1, 2) __fortified_attr_access (__read_only__, 4, 3); +/* A pointer to the __riscv_hwprobe vDSO function is passed as the second + argument to ifunc selector routines. Include a function pointer type for + convenience in calling the function in those settings. */ +typedef int (*__riscv_hwprobe_t) (struct riscv_hwprobe *__pairs, size_t __pair_count, + size_t __cpu_count, unsigned long int *__cpus, + unsigned int __flags) + __THROW __nonnull ((1)) __wur + __fortified_attr_access (__read_write__, 1, 2) + __fortified_attr_access (__read_only__, 4, 3); + __END_DECLS #endif /* sys/hwprobe.h */ -- 2.34.1