From patchwork Wed Feb 14 14:31:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evan Green X-Patchwork-Id: 85730 X-Patchwork-Delegate: palmer@dabbelt.com 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 DB6A63860002 for ; Wed, 14 Feb 2024 14:34:15 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id 5752E385E02E for ; Wed, 14 Feb 2024 14:32:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5752E385E02E 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 5752E385E02E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::431 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707921175; cv=none; b=Jd1i6QSoW34VdMW3T27cE/U8dJfBbZn9rF+W1p4KKgTlglGNfC2OFKrh6YTpUzX8jD8Kp9gpNpIiqx0Hh7VfGEypgltYBt1rMNLnmcpj/TlBJwTZ50mwFsnxATM4BZBmeiKTp6BfR8WCfCOrtuxd6ljds8nlmLjeU2umY3tpHuQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707921175; c=relaxed/simple; bh=3KEb2aY1qvkZ9DfZSgGgFnctwp76uRNqePMZFCzhuPg=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=JGbIVT70E/0K692OrjUXVpwDVw5FpPsrUuC4AQ7l1Ron0VdhEl89cR0XXQdhdhumYUmzpMV0YDv+56mwFO6f/g8DfizKfOyu0HHRy0yuInJ0Ffwe7P8PSHvzvez8nFK9nXHrWh7xgYOqj9Q82zp/Gd2dIKsu+4YPK8K9elOOEtI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-6e0f4e3bc59so1602128b3a.0 for ; Wed, 14 Feb 2024 06:32:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1707921171; x=1708525971; 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=wVONlSWH7rFsPXRa1lJYOvQx3bPsSIZvkL8AKiDA2+0=; b=BdDZNNgrKiWqKYVBwaif8QGL6MTdDX4P6oIlbmtMioAG2i0uwPjtHNzRmlTfPe4J+4 Zgtol9eOFBhDwtIi5jERYCG00j3cqyPpcVHMK0gw9K/4cTTPHbUz2B2UaThrSkEY8KNf jpWJ+utV/vjLCOAq60w8ajbE8lymfnngRWfNL/aCtm1GlwrbBxve+AHJTlUCtBz1I42h 3zNpoiAF6Mdci1OAf71taS7YQHOFyebgqMq3ycF+xco48VCX3M3lrBPzbXZ9fFEz9IcC cdeabvq83SUwQ4J1tZiyiBcmzv3cDys3NRqTDjjmtcE8H7EyTSPkrmI2O987UkjQXZQH 8E9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707921171; x=1708525971; 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=wVONlSWH7rFsPXRa1lJYOvQx3bPsSIZvkL8AKiDA2+0=; b=V8UceSuc+0wMJIh83UqjFebNyO8B9lv9QP7u9OL32Hs2wF9JatrAC8YSTmmnLDVFwi sWrWuYQo8phtI00nYHHQNHlScM1J6Z+CBm7Y3BaC6sllcanuK6defrFlsni8nNTQbepu W5kTVQ2Z7txBAxobqUkdyi3xa3e2Y3s4G3p1YZwXzBVx4Py4zK02umXfIBKZtXndgtJF p6or8r8mhaINEHIS8cohzv8eirdkjZtw2Qi3rv1zjIt90uDm2k6ahkJlFpv3bHmXt7Z5 WCfC5jWhBxH7aAC3n6YS40idpKDJN4uOOGhH8b0JAZnB2Gg6HF15wqSCIa+PXAwwIu6O YkyQ== X-Gm-Message-State: AOJu0YyJo59lJ52JqAnR+RsP3c62199QufRmywXXDwKgLutbBg1goZWg AvG6PQ1o5lEnmG8jYWZDCF/SlyFi6I1A8IKpopUriiy1zYihnAyofjM8zHr9XDuLZKR9CaIgDYt u X-Google-Smtp-Source: AGHT+IE24hI+x1icZ8FasjJYDDvmvSJt1idvSKA6956Tbvyef1T9tTXZkQzp3BdCb1s01q2vkrADDg== X-Received: by 2002:a05:6a20:6f90:b0:19e:304c:5b57 with SMTP id gv16-20020a056a206f9000b0019e304c5b57mr2851313pzb.60.1707921171505; Wed, 14 Feb 2024 06:32:51 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWfjwduNLixa8i1udwRoMBjPon/ZIuAzxKJXh1f7WsctmGtH5F9vORGw7e/sg5KAZ9cnMXAGs0YSKMoWURrec0r29XyCCWQKMpLf6Fc27scsWakB0VraSqM+I6KfNgpLa3v0TnFo6TzZETU4SvPz8KLuKMdHrmQm++wVHnOfH2v Received: from evan.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id k21-20020a635a55000000b005dc98d9114bsm1140255pgm.43.2024.02.14.06.32.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 06:32:51 -0800 (PST) From: Evan Green To: libc-alpha@sourceware.org Cc: vineetg@rivosinc.com, Florian Weimer , slewis@rivosinc.com, palmer@rivosinc.com, Evan Green Subject: [PATCH v12 4/7] riscv: Add __riscv_hwprobe pointer to ifunc calls Date: Wed, 14 Feb 2024 06:31:55 -0800 Message-Id: <20240214143159.2951158-5-evan@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240214143159.2951158-1-evan@rivosinc.com> References: <20240214143159.2951158-1-evan@rivosinc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 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() 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, to account for older glibcs that don't pass the function. Signed-off-by: Evan Green --- (no changes since v10) Changes in v10: - Hand in pointer to __riscv_hwprobe(), not vDSO function Changes in v7: - Remove __THROW from function pointer type, as it creates warnings together with __fortified_attr_access. sysdeps/riscv/dl-irel.h | 9 +++++---- sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h | 10 ++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/sysdeps/riscv/dl-irel.h b/sysdeps/riscv/dl-irel.h index e6ab51ccd4..61b3511c96 100644 --- a/sysdeps/riscv/dl-irel.h +++ b/sysdeps/riscv/dl-irel.h @@ -24,6 +24,7 @@ #include #include #include +#include #define ELF_MACHINE_IRELA 1 @@ -31,10 +32,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), __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 5592b9e100..34a2e3dbc2 100644 --- a/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h +++ b/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h @@ -69,6 +69,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 */