From patchwork Thu Nov 30 18:32:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evan Green X-Patchwork-Id: 81046 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 A2CDA385DC29 for ; Thu, 30 Nov 2023 18:33:25 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 73B18385DC13 for ; Thu, 30 Nov 2023 18:32:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 73B18385DC13 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 73B18385DC13 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701369176; cv=none; b=xbm5KH4tNGCwR8ihdyOA/+LHlZcnLmY4CQSZML0e7ub7YOMRJC3tnB2PiSr0VCCh0FbgcdDwmorwaGimRuMvS7aMKB58WC0/+fatFjtd8pe8U5ggQoII8XOPANb+emnKXfg5irNe2ixykD+aWKm2PG8E1k1/a8FVZTfl9T06QeU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701369176; c=relaxed/simple; bh=k0qoV4sZV+f6eOmuwD87TJs6T5F/SEkcvPU0mNLa1Is=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Yr1jY4IWH7FpX7rfGKbKMvGYabEqfCNpA/v+ufjIbtPy/UegEZuKwr+nP5UgPPXNuZHRHSnA1eBAVtgfNqAzxw+8W6+m7AJwVmWxo+dDqO7GFBxamQJQnxN+20Nklj9ncrs5Bz88tn7DrznqrYeC7N51Ynf62ozg/9+rQXb1+40= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-6cbd24d9557so1089028b3a.1 for ; Thu, 30 Nov 2023 10:32:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1701369174; x=1701973974; 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=GUwAVLzxmk4oYzLKuvyk7oaHk08bVDBm+qjcAc1NUeM=; b=UdkzXmYDZyKQ+SkmBXS9opDe03TKdUvUDCV2+3n0ja/glPlzanSTZk+5qRgFeiNuCG ZOPF9A/mLiaT7KPNQy69yz3OpdXulGvoKlmpzE8xG2hWPFkbBLVeUj9Dp2KwWhpHMORq snfM2KTxzuPfJGiBuy1NncarOwORVnF/cZYUaYuMBs9KU65ENysorfergoEYTYut2HXF RUJzEoJizPRiW5jlhTWN3f+Mn9PQjAqqR58j8f2O0f+uweHJHAHYhN4KI2ta4Mp+l+ur 9QwYbGbIWFmCVqdYqpr8wO2X6U04t5j6Ia7KEkZg7YhXrhc+JdY7+c347vomjJAA+E3s 2flw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701369174; x=1701973974; 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=GUwAVLzxmk4oYzLKuvyk7oaHk08bVDBm+qjcAc1NUeM=; b=qjR92RaVnVsgDG6zNg0QuU9jLgDWu+BvyQUdzPMyWNxOOL9E1xMmVJNXpHsLeYWEMY NKPBBhyVnrI04uC2ZATeovFeDTlb/6bba40jxusalybM6ZEre0vkOQGTpJ+S4KCCb3OZ dr1E5/ZPlsoWe6gKFtZDlX8G+d62Xoo5Dl9MOVVBUMcy4Z59RWlgqjzu7L3KHmZTwzjo G2172NlHybUL0dTgX+s57mkq7RKyN4KPf60bbUu2bbyZNSUGuMTG9Rr5+iNYKz+ELF1U ToIckGZNfz6gkEb5V201Ze9ARt0i/CZPPvoBcFZtRH0jwF88g4fP/il1MyNzRrLpfrsl zBbw== X-Gm-Message-State: AOJu0YyeAEIITVt6h0aka5rpO9pA4YB6W+luGXzQT1JzWCBBQj9ubxLp R9A1WQl32ZKJpuADf2mCXwBnqXTLURfduLuReDM= X-Google-Smtp-Source: AGHT+IEfahLuCdYkaRS2jFGvNOND1X9izn8U3KKhpe46LGgUEF/U9i8O1zBd2s2BSk7aFDAV/amM8g== X-Received: by 2002:a05:6a20:5482:b0:18c:21aa:6a3f with SMTP id i2-20020a056a20548200b0018c21aa6a3fmr28917082pzk.8.1701369174082; Thu, 30 Nov 2023 10:32:54 -0800 (PST) Received: from evan.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id p3-20020a62ab03000000b0068fd026b496sm1512939pff.46.2023.11.30.10.32.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 10:32:53 -0800 (PST) From: Evan Green To: libc-alpha@sourceware.org Cc: Florian Weimer , palmer@rivosinc.com, vineetg@rivosinc.com, slewis@rivosinc.com, Evan Green Subject: [PATCH v9 3/6] riscv: Add __riscv_hwprobe pointer to ifunc calls Date: Thu, 30 Nov 2023 10:32:36 -0800 Message-Id: <20231130183239.598100-4-evan@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130183239.598100-1-evan@rivosinc.com> References: <20231130183239.598100-1-evan@rivosinc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 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 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 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 v7) 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 */