From patchwork Wed Jan 10 20:51:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evan Green X-Patchwork-Id: 1885171 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=xbkhVKF6; 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 4T9KlS4HqFz1yPm for ; Thu, 11 Jan 2024 07:53:40 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 843843861032 for ; Wed, 10 Jan 2024 20:53:38 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) by sourceware.org (Postfix) with ESMTPS id D3163385E032 for ; Wed, 10 Jan 2024 20:52:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D3163385E032 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 D3163385E032 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704919926; cv=none; b=syvhB/cOCSz6mFtZ46L0CCpoSP3Q19EMQ8WoFHlIm8EU1AbTpUtKR3daqo/TyKu9eCZiBEfSaBHiAxwn7qmOul8IpjUdUnCxNa/bzpxZbj5rGORNP3I3wDWjmIqvO8iYN2XufmbQBD8ABTJ4FgHouPKTHKajzAJRN9aIhvwBVTY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704919926; c=relaxed/simple; bh=3KEb2aY1qvkZ9DfZSgGgFnctwp76uRNqePMZFCzhuPg=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=gp6fm7cdaVGDmkzeUPgmfgBVUQ1lsk7NFRKfxUWzdztPs+xsn2yWtagOQ1N9Zp9IC6Ug5tltk1URDxbWkg8R9XRHkcIpEACcB8xb3fmrCsK1nXTFyrjxusw6mZBJAxEDOhNTCJTTL3ecg3O12MGCIU1UBDZ+lzJShB3zQ7dQNvU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x130.google.com with SMTP id e9e14a558f8ab-3606f57e08aso21011315ab.3 for ; Wed, 10 Jan 2024 12:52:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1704919920; x=1705524720; 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=xbkhVKF60UbkIgLuUlY3nZU7Y0yjCojPAX/ueCnCWC4n3ERyYSWcJy3AfPnv0z3Pwb h+fMp2yctWCKjPbLjOY7S9gJmg4pcSDvfWtT3Q+9pi2P+/Z0VPjq92T6G/HpniXS4sqT /vUNE93TGVMeVGtylHUN6zIRCZWzcSeEaF4AfArvTntHn7l4d6/TcsedELsyXM8n2zaG zHO19kmPNuuLE1ML1owWG8POYlMdFaTjr3Vacbso6e8cKy3/acrXxx1KwbELdP+10avA 5Xj94KtGhiQ0js6AnzFc12iD6o6oqquA2/HK1flzwDMXf/04Z4lKuAGTyatbfJ4N6eIb HYnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704919920; x=1705524720; 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=DJoH9/aVB8pt3gHjIIcG7bV/BotHrCGsRGZSHsEAPSw0G6kL1ut0rHLdIzHNYkUc8g vBco36qImr/tGyzU5X62qxqKpHneSkimz1JVYJ98B+o6DjdeYyB8P04Dgsn+9ZVO7/CQ gzrdZCe4VLx9FbsdUnSVCPymEDKXZ61a3JQIh68cu1L2NWnkArma2nqatNyl9Wwfjnyp gobjZPU8dSqKIxcC3h3y/ySWu8ldWsobkX3pi/Q8+6llGIZzV5bsiHvqQpj5pr22F37Q c/85BzBzDOZwmRcuvTCP5BmkE0GCaFLJ4FinIglNc1aX3AF+KSxsnnJRSEv7tUmZkfbf +QIQ== X-Gm-Message-State: AOJu0YyY6BlaVskWYmxUekHHdBGyAblrFetpu70WN6d9+Ay8QB8+j2mM 7mqpsdPQHQhC0ubt1dcqvbwZQp/Pys4uqG8IiJTzPgVeizU= X-Google-Smtp-Source: AGHT+IEnJCIpLtYE9y3i7yb9LnSYYfR4x8nmELZ3/ZjZI+yT7LkqwIgkCnagt/aHBKTiGCXfdx1W8Q== X-Received: by 2002:a92:cf4e:0:b0:35f:d1ed:d189 with SMTP id c14-20020a92cf4e000000b0035fd1edd189mr117401ilr.58.1704919920023; Wed, 10 Jan 2024 12:52:00 -0800 (PST) Received: from evan.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id y4-20020a92c984000000b0035ff9825323sm1452018iln.30.2024.01.10.12.51.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 12:51:59 -0800 (PST) From: Evan Green To: libc-alpha@sourceware.org Cc: palmer@rivosinc.com, vineetg@rivosinc.com, slewis@rivosinc.com, Florian Weimer , Evan Green Subject: [PATCH v11 4/7] riscv: Add __riscv_hwprobe pointer to ifunc calls Date: Wed, 10 Jan 2024 12:51:37 -0800 Message-Id: <20240110205140.754849-5-evan@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240110205140.754849-1-evan@rivosinc.com> References: <20240110205140.754849-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+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 */