From patchwork Tue Feb 27 22:56:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evan Green X-Patchwork-Id: 1905485 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.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=oIyzeU6M; 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 4TktFj18V0z23d3 for ; Wed, 28 Feb 2024 09:58:49 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 17BE4385828C for ; Tue, 27 Feb 2024 22:58:46 +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 0FC19385840A for ; Tue, 27 Feb 2024 22:57:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0FC19385840A 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 0FC19385840A 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=1709074625; cv=none; b=QE+4TEHLNXWGOHzBe5+DhSuqKOobyS46UxjRPP4kcxJ7ODJNoBWP8mWw+jJ67DbYZnp6TGZzkZ8+wnv6W/1xf1whCJSOqwRUO8DaWW9ACQ4Cxnd08N462M2auxq6hOKe7UTYL2SZ+cheZO4+8o5msLh//8+K13XJcAcaId8X1Io= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709074625; c=relaxed/simple; bh=3KEb2aY1qvkZ9DfZSgGgFnctwp76uRNqePMZFCzhuPg=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=M+Laf2eTFbAjmCVkTzmLu+/MFSyuwh5W2wIesbJOXipSC0whrDVg/JHFDFlhlkTBEFcHPMvA57OGxOCJLnw3asN9pG7wiIAfLb1170zZtsLu8CqlpfB45rLKhMSnjsp8BLksiBRWxS0aygSp58GZUSewRU+XjiukTum0r9+naiQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-6e459b39e2cso212998b3a.1 for ; Tue, 27 Feb 2024 14:57:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1709074622; x=1709679422; 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=oIyzeU6MEQa4tMs/JkfkEQy/x/1fLPkap7KTj4eI5nrl/PUZdrLqx5MH1h81N9rkYH MdHRHDsPK8cfW5j3qse+AbUCDX+6/EcCD0ZoPAuv1db6g81hj5KCenxlt/QieHyot/C3 v+f3g+yFnicE9zf3WuSMjUZKbaubzz1ifQ4lFnQoWbRvFGajlyQEC7EqBc3nv5zVHk0p AKiwV3ujMT2GrCIdHw+uiGyzN2x0Mpt5Oo0hZURlKuSB8JBQQmCuk6e61Wp9aOsh/f5n SxSiS1mU+22SPLjY9nneRHj0bT2hoREDm/zKX/QVZXpRrMbohE56N13lsc84w6JYo60e v7wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709074622; x=1709679422; 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=YAn5gtt2NKfYJlZaV82I9Q2JOhTkSUTM1kZeIFKcTa6RK39f4CoWxVfoplAOT/jrSb r7TwYtVxIAAJgwawt8OjVm8Rhnlo/aUIYIVX5yN6OwAraq6nCbU+fLI3ezkhopLV7wA8 HG1jhTnNFzeIEuYnq/gbq5IiF8sPdi3Hx7NoIQt3u5U8WLiUGpuzsjpdG+faRj+RyEoA MQ4IR0Mc0oJE5yVlR1i9+FpcIdvqGFHhFxzI9odg0WB8qC/v1qJ26ZOBWX6Le0lSarXD AYnerGhahIMTJZ5CNwAjw+GVrdezKAwrixzgW1GHYAFx75hcRC+7RiHi+Avs0FaGpsPA gJQg== X-Gm-Message-State: AOJu0YyZd90w0RpYfd9iHF8ughHpiCt4ykX4FOmrlA88/e3qooXbx54F MLh/lG6rN8vmXBai8wygJEHJUC1CItHfxhWYOkAufisQMzl7r53zWgFSDRMTH/JFptGct9n6oYp g X-Google-Smtp-Source: AGHT+IGw8/nH1GeXOnlfrmo5Q0Re3CzcwFQfz2HD4H6zZrRjT7pHzkwPRKGaoMKLwFrO19Kg94E/5w== X-Received: by 2002:a17:902:6544:b0:1dc:abe9:8270 with SMTP id d4-20020a170902654400b001dcabe98270mr708369pln.26.1709074621892; Tue, 27 Feb 2024 14:57:01 -0800 (PST) Received: from evan.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id li3-20020a170903294300b001dc90ac1cecsm2029225plb.284.2024.02.27.14.57.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 14:57:01 -0800 (PST) From: Evan Green To: libc-alpha@sourceware.org Cc: vineetg@rivosinc.com, slewis@rivosinc.com, Florian Weimer , palmer@rivosinc.com, Evan Green Subject: [PATCH v13 4/7] riscv: Add __riscv_hwprobe pointer to ifunc calls Date: Tue, 27 Feb 2024 14:56:40 -0800 Message-Id: <20240227225644.724901-5-evan@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240227225644.724901-1-evan@rivosinc.com> References: <20240227225644.724901-1-evan@rivosinc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 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+incoming=patchwork.ozlabs.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 */