From patchwork Wed Mar 3 13:37:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 42208 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 DE1293957015; Wed, 3 Mar 2021 13:38:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DE1293957015 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1614778691; bh=wPIeiyqOcAgW38ZV2WKlM4gSpxyJMWth/AQ3voPK1Mw=; h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=oxVeRdkc0bmDd2lpeIpKOlB0R1XZTHhXLn9xlkooo9ljqKNeggrLxy1jfE/EmJNnE Aen5BjEtpwBufyrmcg589CReea0iOrXr/hq5vxHRsbXr6b/0p0ZApV9UnN4FfpUbfF W/mDpcQcfW+qmUxdOynaDiJcLgQyPMiW+r5RKppM= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id 3832238618D4 for ; Wed, 3 Mar 2021 13:38:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3832238618D4 Received: by mail-ot1-x335.google.com with SMTP id s3so23556233otg.5 for ; Wed, 03 Mar 2021 05:38:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wPIeiyqOcAgW38ZV2WKlM4gSpxyJMWth/AQ3voPK1Mw=; b=St9jpGfaEY2SZWLTJbMcH1+7ZH09lxScNGIqWUxOe71WZ5S1X+xxD+I8CL/e/Hmnhx jM2fX62HXyGIp/jmU7IcXb/ctKNz86z+MI8p8D3wUdMWLW6iLItmyy9Sa5gpyMfpr6Gv MU0wR35PG1d64jChT5Rbo2n+Jej5ABL5m01Tl5Tg6vMLbz5DX1geH3O2Qwh05bwQeb// +RV7EwnPdV2RcB1GP+0rvgrtb/eP8wl4UTt5pjzYDFP83qjF89i6Rdw43rb7wI4E0z8p a7/6ivocsgaHjZKEdvlXtAnsYLmTToOenUIpsTonvURNuGdWwyqKxavEVv3+Etd13K3N 27GQ== X-Gm-Message-State: AOAM533rhBEZBGdKJJesFRTxsQacXW00f8At3r3KNo5fjbWnfkl+kZ85 nbYuUtLEMoeI34m8dJKKMRbrmX1D7xQPmAaJai4= X-Google-Smtp-Source: ABdhPJzoECrDXU/94/fT5FbwWGlrbQMQyh8zbXmzAxfFVhDpAC0emVLx3I67uuEYJXH5DYbaoZ1lcp/1Fd2mfu+4baY= X-Received: by 2002:a05:6830:1098:: with SMTP id y24mr14611114oto.269.1614778685268; Wed, 03 Mar 2021 05:38:05 -0800 (PST) MIME-Version: 1.0 References: <20210202215112.1002416-1-hjl.tools@gmail.com> <87k0rom825.fsf@oldenburg.str.redhat.com> <6586609.jJDZkT8p0M@farino> <87k0rk8968.fsf@oldenburg.str.redhat.com> <87pn1a1tvb.fsf@oldenburg.str.redhat.com> <871rd875cp.fsf@oldenburg.str.redhat.com> <87im6k5hyn.fsf@oldenburg.str.redhat.com> <878s76eu2x.fsf@oldenburg.str.redhat.com> <87h7luda0m.fsf@oldenburg.str.redhat.com> In-Reply-To: Date: Wed, 3 Mar 2021 05:37:29 -0800 Message-ID: Subject: [PATCH v4] x86: Set minimum x86-64 level marker [BZ #27318] To: Florian Weimer X-Spam-Status: No, score=-3035.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: "H.J. Lu via Libc-alpha" , Joseph Myers Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" On Mon, Mar 1, 2021 at 11:09 AM H.J. Lu wrote: > > On Mon, Mar 1, 2021 at 10:05 AM Florian Weimer wrote: > > > > * H. J. Lu: > > > > >> I think we should do the following: (a) disable the build note > > >> generation in glibc, (b) backport --list-diagnostics or something > > >> similar. The second part will hopefully help with analyzing failures > > >> due to CPU support mismatches. > > > > > > My patch does (a). > > > > But not completely so, see the issue regarding post-v4 flags. > > It is the issue of "works on processors with the ISA level" since > we don't check if other ISA features are required. > > > > But I think the ISA level meaning should be changed from "works on > > > processors with the ISA level" to "require processors with the ISA > > > level to work". > > > > Hmm. Is this compatible with the glibc-hwcaps directory assignment > > logic in ldconfig? > > Given that we don't check the extra ISA features in the binary, this > is a logical change. Since the full ISA set used in an ELF binary is unknown to compiler, an x86-64 ISA level marker indicates the minimum, not maximum, ISA set required to run such an ELF binary. We never guarantee a library with an x86-64 ISA level v3 marker doesn't contain other ISAs beyond x86-64 ISA level v3, like AVX VNNI. We check the x86-64 ISA level marker for the minimum ISA set. Here is the updated patch. OK for master? From e238dc3db8bb6950f1671c9c0b2467386e8e798d Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Tue, 2 Feb 2021 13:45:58 -0800 Subject: [PATCH v4] x86: Set minimum x86-64 level marker [BZ #27318] Since the full ISA set used in an ELF binary is unknown to compiler, an x86-64 ISA level marker indicates the minimum, not maximum, ISA set required to run such an ELF binary. We never guarantee a library with an x86-64 ISA level v3 marker doesn't contain other ISAs beyond x86-64 ISA level v3, like AVX VNNI. We check the x86-64 ISA level marker for the minimum ISA set. Since -march=sandybridge enables only some ISAs in x86-64 ISA level v3, we should set the needed ISA marker to v2. Otherwise, libc is compiled with -march=sandybridge will fail to run on Sandy Bridge: $ ./elf/ld.so ./libc.so ./libc.so: (p) CPU ISA level is lower than required: needed: 7; got: 3 1. Disable x86-64 ISA level marker for 32-bit build. 2. Set minimum, instead of maximum, x86-64 ISA level marker. This should have no impact on the glibc-hwcaps directory assignment logic in ldconfig and ld.so. --- config.h.in | 3 ++ sysdeps/x86/configure | 88 +++++++++++++++++++++++++++++++++++++++- sysdeps/x86/configure.ac | 70 +++++++++++++++++++++++++++++++- sysdeps/x86/isa-level.c | 33 +-------------- 4 files changed, 160 insertions(+), 34 deletions(-) diff --git a/config.h.in b/config.h.in index 06ee8ae26a..3c9035c2f2 100644 --- a/config.h.in +++ b/config.h.in @@ -275,4 +275,7 @@ /* Define if x86 ISA level should be included in shared libraries. */ #undef INCLUDE_X86_ISA_LEVEL +/* The default x86 ISA level. */ +#define DEFAULT_ISA_LEVEL 0 + #endif diff --git a/sysdeps/x86/configure b/sysdeps/x86/configure index 5e32dc62b3..ffa10e2f45 100644 --- a/sysdeps/x86/configure +++ b/sysdeps/x86/configure @@ -134,7 +134,89 @@ if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS -nostartfiles -nostdlib -r -o conftest c test $ac_status = 0; }; }; then count=`LC_ALL=C $READELF -n conftest | grep NT_GNU_PROPERTY_TYPE_0 | wc -l` if test "$count" = 1; then - libc_cv_include_x86_isa_level=yes + cat > conftest.c <&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; } | grep -q " sahf"; then + ISA_LEVEL_CPPFLAGS=-DHAS_LAHF_SAHF + fi + cat > conftest.c <&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; } | grep -q " movbe"; then + ISA_LEVEL_CPPFLAGS="$ISA_LEVEL_CPPFLAGS -DHAS_MOVBE" + fi + cat > conftest.c <&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; then + eval `grep DEFAULT_ISA_LEVEL= conftest.i | sed -e "s/DEFAULT_ISA_LEVEL=\(.*\)/DEFAULT_ISA_LEVEL=\"\1\"/"` + libc_cv_include_x86_isa_level=yes + fi fi fi rm -f conftest* @@ -144,6 +226,10 @@ $as_echo "$libc_cv_include_x86_isa_level" >&6; } if test $libc_cv_include_x86_isa_level = yes; then $as_echo "#define INCLUDE_X86_ISA_LEVEL 1" >>confdefs.h + cat >>confdefs.h <<_ACEOF +#define DEFAULT_ISA_LEVEL $DEFAULT_ISA_LEVEL +_ACEOF + fi config_vars="$config_vars enable-x86-isa-level = $libc_cv_include_x86_isa_level" diff --git a/sysdeps/x86/configure.ac b/sysdeps/x86/configure.ac index f94088f377..866dd984df 100644 --- a/sysdeps/x86/configure.ac +++ b/sysdeps/x86/configure.ac @@ -101,11 +101,79 @@ libc_cv_include_x86_isa_level=no if AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS -nostartfiles -nostdlib -r -o conftest conftest1.S conftest2.S); then count=`LC_ALL=C $READELF -n conftest | grep NT_GNU_PROPERTY_TYPE_0 | wc -l` if test "$count" = 1; then - libc_cv_include_x86_isa_level=yes + cat > conftest.c < conftest.c < conftest.c <