From patchwork Mon Jun 17 14:46:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1948650 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DBlRzwiM; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4W2t5709lcz20Wg for ; Tue, 18 Jun 2024 00:47:06 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2A9C73861878 for ; Mon, 17 Jun 2024 14:47:05 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id AC4333858C50 for ; Mon, 17 Jun 2024 14:46:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AC4333858C50 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AC4333858C50 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718635608; cv=none; b=mWcNsGbmALPvzaGT1jmHNUvkl4xuZdaluaMVguVoFW+c+NzeITIMa1VRAUNseRuL/Qwex8sbqjtA20UAkIhCac0+Gdiwu4WNROXw32s/lWhZ2dmildqovE5cq+dvWc3lF37+ssA1yliYSn4NrQonoAMda7Xk4GWEiumJ2955NVA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718635608; c=relaxed/simple; bh=AWLr9VXbVTE7J6p/Y2NtRdln+Rw0NGSCY6dsiKHVqx4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=urVx9RBMCQcF2j1Tu8hUFyqRXq9e8jC/nXY3Yj65bXmTi940GSTboYQiT3mNn/mwtO+OnyuGwz6/SJC2gN/5RJo91fHByaoB/Xv9bkGrHEz+vSENoNxXboAYyFuH8qeD4Vls3lfxTJ2JituGAoLFSYQEs0M5sRhDlztJjA2ace0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718635605; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=6GwBKpnC+IOsvqzQCtJ56u7yYI/ewF2UK+VsvAz3MhU=; b=DBlRzwiMmoxJGolADg9/DaKF1GKHf/iuCSY+yxqonSUAsCVlzF4dBh9j58UDoAF9Siw+YX gIahtMz6/ha84AN0TZZqWHSm4diL6okxGcZjaSuV1jVtLvu1SyEIDfe6WCqeaKQdoi8Duj 6E6i6/Mi1COsGDkSkyByHu7162DOUTA= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-633-pWMGmgdYOkWkAgkYEJmrIQ-1; Mon, 17 Jun 2024 10:46:44 -0400 X-MC-Unique: pWMGmgdYOkWkAgkYEJmrIQ-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E29511944D46 for ; Mon, 17 Jun 2024 14:46:36 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.203]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8B2671977024 for ; Mon, 17 Jun 2024 14:46:34 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH v2] Linux: Call dl_hwcap_check earlier, before full auxiliary vector parse Date: Mon, 17 Jun 2024 16:46:32 +0200 Message-ID: <87y17339vb.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, 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 full parsing routine may need the memset function, which could require non-baseline ISA support. --- v2: Remove spurious braces from sysdeps/powerpc/powerpc64/le/dl-hwcap-check.h. sysdeps/generic/dl-hwcap-check.h | 5 ++++- sysdeps/powerpc/powerpc64/le/dl-hwcap-check.h | 22 ++++++++++++++++++---- sysdeps/s390/s390-64/dl-hwcap-check.h | 20 +++++++++++++++++--- sysdeps/unix/sysv/linux/dl-sysdep.c | 20 +++++++++++++------- 4 files changed, 52 insertions(+), 15 deletions(-) base-commit: 55eb99e9a9d840ba452b128be14d6529c2dde039 diff --git a/sysdeps/generic/dl-hwcap-check.h b/sysdeps/generic/dl-hwcap-check.h index 55efd129be..65dba6d1a0 100644 --- a/sysdeps/generic/dl-hwcap-check.h +++ b/sysdeps/generic/dl-hwcap-check.h @@ -22,7 +22,10 @@ static inline void dl_hwcap_check (void) { - /* The generic implementation does not perform any checks. */ + /* The generic implementation does not perform any checks. Specific + implementations may assume that GLRO(dl_auxv) has been + initialized (if it exists), but GLRO(dl_hwcap), GLRO(dl_hwcap2) + have not been set at this point. */ } #endif /* _DL_HWCAP_CHECK_H */ diff --git a/sysdeps/powerpc/powerpc64/le/dl-hwcap-check.h b/sysdeps/powerpc/powerpc64/le/dl-hwcap-check.h index 6d463f0511..d7b2a2ca4d 100644 --- a/sysdeps/powerpc/powerpc64/le/dl-hwcap-check.h +++ b/sysdeps/powerpc/powerpc64/le/dl-hwcap-check.h @@ -25,13 +25,27 @@ static inline void dl_hwcap_check (void) { +#if defined GCCMACRO_ARCH_PWR9 || defined GCCMACRO__FLOAT128_HARDWARE__ \ + || defined GCCMACRO_ARCH_PWR10 || defined GCCMACRO__PCREL__ \ + || defined GCCMACRO__MMA__ + /* Early auxiliary vector parsing, to avoid ISA dependencies in + later full parsing. */ + unsigned long int dl_hwcap2 = 0; + for (ElfW(auxv_t) *av = GLRO(dl_auxv); av->a_type != AT_NULL; av++) + if (av->a_type == AT_HWCAP2) + { + dl_hwcap2 = av->a_un.a_val; + break; + } +#endif + #ifdef GCCMACRO_ARCH_PWR9 - if ((GLRO (dl_hwcap2) & PPC_FEATURE2_ARCH_3_00) == 0) + if ((dl_hwcap2 & PPC_FEATURE2_ARCH_3_00) == 0) _dl_fatal_printf ("\ Fatal glibc error: CPU lacks ISA 3.00 support (POWER9 or later required)\n"); #endif #ifdef GCCMACRO__FLOAT128_HARDWARE__ - if ((GLRO (dl_hwcap2) & PPC_FEATURE2_HAS_IEEE128) == 0) + if ((dl_hwcap2 & PPC_FEATURE2_HAS_IEEE128) == 0) _dl_fatal_printf ("\ Fatal glibc error: CPU lacks float128 support (POWER 9 or later required)\n"); #endif @@ -39,12 +53,12 @@ Fatal glibc error: CPU lacks float128 support (POWER 9 or later required)\n"); running on POWER9 because there are faulting PCREL instructions before this point. */ #if defined GCCMACRO_ARCH_PWR10 || defined GCCMACRO__PCREL__ - if ((GLRO (dl_hwcap2) & PPC_FEATURE2_ARCH_3_1) == 0) + if ((dl_hwcap2 & PPC_FEATURE2_ARCH_3_1) == 0) _dl_fatal_printf ("\ Fatal glibc error: CPU lacks ISA 3.10 support (POWER10 or later required)\n"); #endif #ifdef GCCMACRO__MMA__ - if ((GLRO (dl_hwcap2) & PPC_FEATURE2_MMA) == 0) + if ((dl_hwcap2 & PPC_FEATURE2_MMA) == 0) _dl_fatal_printf ("\ Fatal glibc error: CPU lacks MMA support (POWER10 or later required)\n"); #endif diff --git a/sysdeps/s390/s390-64/dl-hwcap-check.h b/sysdeps/s390/s390-64/dl-hwcap-check.h index 6ad3242cc9..ee67ebf76e 100644 --- a/sysdeps/s390/s390-64/dl-hwcap-check.h +++ b/sysdeps/s390/s390-64/dl-hwcap-check.h @@ -26,16 +26,30 @@ static inline void dl_hwcap_check (void) { #if defined __ARCH__ +# if GCCMACRO__ARCH__ >= 12 + /* Early auxiliary vector parsing, to avoid ISA dependencies in + later full parsing. */ + unsigned long int dl_hwcap = 0; + { + for (ElfW(auxv_t) *av = GLRO(dl_auxv); av->a_type != AT_NULL; av++) + if (av->a_type == AT_HWCAP) + { + dl_hwcap = av->a_un.a_val; + break; + } + } +# endif + # if GCCMACRO__ARCH__ >= 14 - if (!(GLRO(dl_hwcap) & HWCAP_S390_VXRS_PDE2)) + if (!(dl_hwcap & HWCAP_S390_VXRS_PDE2)) _dl_fatal_printf ("\ Fatal glibc error: CPU lacks VXRS_PDE2 support (z16 or later required)\n"); # elif GCCMACRO__ARCH__ >= 13 - if (!(GLRO(dl_hwcap) & HWCAP_S390_VXRS_EXT2)) + if (!(dl_hwcap & HWCAP_S390_VXRS_EXT2)) _dl_fatal_printf ("\ Fatal glibc error: CPU lacks VXRS_EXT2 support (z15 or later required)\n"); # elif GCCMACRO__ARCH__ >= 12 - if (!(GLRO(dl_hwcap) & HWCAP_S390_VXE)) + if (!(dl_hwcap & HWCAP_S390_VXE)) _dl_fatal_printf ("\ Fatal glibc error: CPU lacks VXE support (z14 or later required)\n"); # endif diff --git a/sysdeps/unix/sysv/linux/dl-sysdep.c b/sysdeps/unix/sysv/linux/dl-sysdep.c index e1b14e9eb3..c54100c8a5 100644 --- a/sysdeps/unix/sysv/linux/dl-sysdep.c +++ b/sysdeps/unix/sysv/linux/dl-sysdep.c @@ -70,11 +70,10 @@ struct dl_main_arguments ElfW(Addr) user_entry; }; -/* Separate function, so that dl_main can be called without the large - array on the stack. */ +/* First part of argument parsing, up to and including GLRO(dl_auxv) + initialization. */ static void -_dl_sysdep_parse_arguments (void **start_argptr, - struct dl_main_arguments *args) +_dl_sysdep_parse_arguments_1 (void **start_argptr) { _dl_argc = (intptr_t) *start_argptr; _dl_argv = (char **) (start_argptr + 1); /* Necessary aliasing violation. */ @@ -86,7 +85,13 @@ _dl_sysdep_parse_arguments (void **start_argptr, GLRO(dl_auxv) = (ElfW(auxv_t) *) (tmp + 1); break; } +} +/* Separate function, so that dl_main can be called without the large + array on the stack. */ +static void __attribute__ ((noinline)) +_dl_sysdep_parse_arguments_2 (struct dl_main_arguments *args) +{ dl_parse_auxv_t auxv_values = { 0, }; _dl_parse_auxv (GLRO(dl_auxv), auxv_values); @@ -102,11 +107,12 @@ _dl_sysdep_start (void **start_argptr, { __libc_stack_end = DL_STACK_END (start_argptr); - struct dl_main_arguments dl_main_args; - _dl_sysdep_parse_arguments (start_argptr, &dl_main_args); - + _dl_sysdep_parse_arguments_1 (start_argptr); dl_hwcap_check (); + struct dl_main_arguments dl_main_args; + _dl_sysdep_parse_arguments_2 (&dl_main_args); + __tunables_init (_environ); /* Initialize DSO sorting algorithm after tunables. */