From patchwork Fri Sep 1 23:52:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evan Green X-Patchwork-Id: 75171 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 CAC2A3853D27 for ; Fri, 1 Sep 2023 23:53:08 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id 4E903385771E for ; Fri, 1 Sep 2023 23:52:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4E903385771E 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-x634.google.com with SMTP id d9443c01a7336-1bdca7cc28dso21057025ad.1 for ; Fri, 01 Sep 2023 16:52:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1693612356; x=1694217156; 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=KWoDGBVgh2ahuP7fU4rbIG6QYkztzd+CDqY8ewdbGdjDSsYYgm+Muj3ZU85mnr8Sgy 811siAlXajH7G2uI8csJM/uaHoatWs1P9+kyL0ao5QihOWagOgQb/eg2O4Cf3qFQGx4v 7KxsYYB2KjGIPAbx01CHq3fL08rkUpA3dVmb7iP5ywwAsotoH3keDfprgueAhPZWlz3h FF9VGk407cX3Nl/JciIXHWh6grxgBE6ucllhOaJSA87kNmIDt4SpoZSxU8AU9y30fEqA wDrc8LqhHeBUMWHlx6iykQbT3WsnhFngh++n3QxkWZlYEt33UdDNAswqug4iVKwhF//p rNvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693612356; x=1694217156; 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=VXcQezsP/RShezoqRpfEYtxe8xqPTrOeWIK4CLN8Z0NXMXJleS+rKKMFqi9Wy0ZPU8 6P6ms3U7WX2cb00Puv/IEt+smtEiBNAivVrrUe2R8e2Eh1cdX77w4/GbKzXMcS8PSCOd bMRz8K+kQEsC9nx6UiA3LxJUule9eP4UoPUAQigm/Q+6uOMl7e5an79rsXv7WQDLNab6 FSUENg8MTXXTderyc+8MD2pglMjgTu2t8xs3hgu/XVg4m2y4lOt0OJUWOQOPE4YlClxQ 47WhGSsWzGeMDag0EZYi3AKZaJiXFdAKSRxonkY9q2ECbPmY4Q07ZoPKCGRNzF8HpH6/ Du6g== X-Gm-Message-State: AOJu0Yx22fo76WHweGDK2hOtUSLhaH0+TNwYGYoMZDrdIcqjRcHKVjuc dy3B9KjftV1jGKytXl8gZBx/aTIgEPF207kVc8Q= X-Google-Smtp-Source: AGHT+IH4aSlbDsl5Xe95QSGb/BUw/lXjLVP9JjwIz5XWZxuzrwyHiF9ftgAdC58jo67c6pR/n7nmlA== X-Received: by 2002:a17:903:32c1:b0:1c2:1443:d62 with SMTP id i1-20020a17090332c100b001c214430d62mr4771731plr.20.1693612355875; Fri, 01 Sep 2023 16:52:35 -0700 (PDT) Received: from evan.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id c13-20020a170902d48d00b001bee782a1desm3499551plg.181.2023.09.01.16.52.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 16:52:35 -0700 (PDT) From: Evan Green To: libc-alpha@sourceware.org Subject: [PATCH v8 3/6] riscv: Add __riscv_hwprobe pointer to ifunc calls Date: Fri, 1 Sep 2023 16:52:21 -0700 Message-Id: <20230901235224.3304592-4-evan@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230901235224.3304592-1-evan@rivosinc.com> References: <20230901235224.3304592-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 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: , Cc: Florian Weimer , Evan Green , vineetg@rivosinc.com Errors-To: libc-alpha-bounces+patchwork=sourceware.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 --- (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 */