From patchwork Wed Aug 23 22:31:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evan Green X-Patchwork-Id: 1825011 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20221208.gappssmtp.com header.i=@rivosinc-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=bFqpsVPp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RWLYk1Ny6z1yNm for ; Thu, 24 Aug 2023 08:32:10 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3ED2B3851145 for ; Wed, 23 Aug 2023 22:32:08 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by sourceware.org (Postfix) with ESMTPS id 7784E3853D3C for ; Wed, 23 Aug 2023 22:31:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7784E3853D3C 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-pl1-x633.google.com with SMTP id d9443c01a7336-1c09673b006so15326655ad.1 for ; Wed, 23 Aug 2023 15:31:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1692829897; x=1693434697; 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=tcFpzT8/0+zuHQr8jRQPh8DN1RQyeYpMkBX8bsq0IHs=; b=bFqpsVPpR0cR1a8lB1qiKiEuWhyrStgvhzFlTVEZBHvDWYhWwa9cTwtaC9X5b7Dd2V ioVBEeTe3nVO0wWrsVp8mrV1pFIIYFlgfwlXEkwPb0L+gh9WnvOD6UNiIHZWOe0ck47Z xKVt0G/Vc82xfDvWZIoBcfHcjjl0gsBCjFzsfMpVmwRYJs2wgawrfyzguY5bRoEZNs8O ysqhNGrgqYXf0jN9Tac0nIor448d9QjIBFfagINmDE9BTKfCdnXCP5M9lzgbztjrl8sZ f9pCpT5JjKR5VLIuhjQVUrdgB+MPSrj61fWpjuSoIW15UKh4iCG7tqIZaGGRMJyu5Uvp 35BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692829897; x=1693434697; 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=tcFpzT8/0+zuHQr8jRQPh8DN1RQyeYpMkBX8bsq0IHs=; b=aOuWZrm+9JvqKp3hhFFKW5+hbuQ6AiDG8byWS1AkRq+dYtAFrRz752Sf1s4WZdZpgy vdxDlY2Quz03QaIxN0O8bhAnSlPoIUMiOsxT4f0l/391uQdu0El0YZxYcqFuV2jUKb80 G0oDnKonsi4AepVYtWriQWlq3WmDGbLb3Qya+/UpDwW5bQxRwWoGYqy9JUJB3fhfgueC lWLpir++LiqM+rUSUmD2D+ka/FQiEc7lW75E6GuEoVWj/+N262dxVlDnT6mCDD0/deeX h+tj+7r/FEVCueNn7QQ75fxFEy5jWcnE4vY51keOfsrR6dZzPZzzbOlS+b4C7EI113+Y OlRw== X-Gm-Message-State: AOJu0YydfHDQoYE56G4z7qxLMWEuLy0Is9oy8mitFqtafYnN/VtWTKOR 5C494Y0p5aOjf553cOiClfwSK3pYYFz3dG9/BKw= X-Google-Smtp-Source: AGHT+IHRoFaCnuXTOcsKb1cfXdeZCVgT5C6d0Q6kaqRqE1MAlVmBjOW1bY0yFnIo9wAovgOEdGH9Bw== X-Received: by 2002:a17:903:120b:b0:1b8:6850:c3c4 with SMTP id l11-20020a170903120b00b001b86850c3c4mr13661010plh.22.1692829896879; Wed, 23 Aug 2023 15:31:36 -0700 (PDT) Received: from evan.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id i1-20020a17090332c100b001bbf7fd354csm11335150plr.213.2023.08.23.15.31.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 15:31:36 -0700 (PDT) From: Evan Green To: libc-alpha@sourceware.org Cc: vineetg@rivosinc.com, palmer@rivosinc.com, Florian Weimer , slewis@rivosinc.com, Evan Green Subject: [PATCH v7 3/6] riscv: Add __riscv_hwprobe pointer to ifunc calls Date: Wed, 23 Aug 2023 15:31:12 -0700 Message-Id: <20230823223116.645225-4-evan@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230823223116.645225-1-evan@rivosinc.com> References: <20230823223116.645225-1-evan@rivosinc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, 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.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" 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 --- Changes in v7: - Remove __THROW from function pointer type, as it creates warnings together with __fortified_attr_access. 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 aa189a4818..fd3be5a411 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) + __nonnull ((1)) __wur + __fortified_attr_access (__read_write__, 1, 2) + __fortified_attr_access (__read_only__, 4, 3); + __END_DECLS #endif /* sys/hwprobe.h */