From patchwork Sat Mar 6 15:23:18 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: 42360 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 A86D13890411; Sat, 6 Mar 2021 15:24:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A86D13890411 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1615044240; bh=7PKX0UryLKw+z2gdLi2oJRtYOeOEW/w80iVeeEnq3mo=; 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=MSj4MyK/uXTVhiHcTkbi6w99WOtLRk0BFS/FWLqFE0Nrz7+Q0u7eOjsRAWVPTF7y0 BjUqUpZ9YZQ1sxo8b7s8+3+o89kFQ9o6ujOrxo1Wss78cqnFjk4ovCRpey5NT6geZT cQgNifM9i5eNdRa6wH9u6CSE6/nFQXcejEn2Tp5s= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id 566CB386F030 for ; Sat, 6 Mar 2021 15:23:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 566CB386F030 Received: by mail-oi1-x22d.google.com with SMTP id w65so6048268oie.7 for ; Sat, 06 Mar 2021 07:23:55 -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=7PKX0UryLKw+z2gdLi2oJRtYOeOEW/w80iVeeEnq3mo=; b=os+LqHfvVvRJstVbdHbPyhRJv0bY1QVHuDZt4ywX/QSMkg3ITiLw3p0aqtIJy2JGOS FcyFrf3vNA6RMgFsntxqG6ndZFyWr3agsT0VK8s5mENYBnWwL39V+7Bvo5qMpqfFWbX2 XFgzCURfFtYyWVJ6fpfIerawn6nt1faooKrtIkawKVucPVKE9atV+gcmNeNSr0S6a3XO 7W8TnL735tFnXgDgUFlE5/YMSf4VcpHF5Bxm6SsDPjE0zNcmQ57vuaVyLAGxXv9mWfg5 YWgOjnzNq4TXkS5ulVAgycgcm+1ZYCRlqqfxSQreo4FynH7kXqlZRjCTFgw4wavYShmz 8Yng== X-Gm-Message-State: AOAM5304ML1I5V7WDYN8URCgnv38FPyLXyw8Pk/gUlmgdRIwFGEFAkBJ T7aEnzhjKS8XaxJL4sEKPnvHIm+gh+M7o1pfxKo= X-Google-Smtp-Source: ABdhPJx+mRy2D75/FzR6xi7p4EryIhKrecg3CA0AIQz1HNOptT5E7FHTMsBlrhZkkhrcn6sJl/oWoc8Y+UWHp7MROLM= X-Received: by 2002:aca:530e:: with SMTP id h14mr386758oib.79.1615044234759; Sat, 06 Mar 2021 07:23:54 -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> <87sg599yk1.fsf@oldenburg.str.redhat.com> In-Reply-To: <87sg599yk1.fsf@oldenburg.str.redhat.com> Date: Sat, 6 Mar 2021 07:23:18 -0800 Message-ID: Subject: [PATCH v5] x86: Set minimum x86-64 level marker [BZ #27318] To: Florian Weimer X-Spam-Status: No, score=-3034.9 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 Fri, Mar 5, 2021 at 11:43 AM Florian Weimer wrote: > > * H. J. Lu: > > > 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 < > +extern long double fmodl(long double x, long double y); > > +extern long double x, y; > > +long double > > +foo (void) > > +{ > > + return fmodl (x, y); > > +} > > +EOF > > + ISA_LEVEL_CPPFLAGS= > > + if AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS -Os -ffast-math -S -o - conftest.c) | grep -q " sahf"; then > > + ISA_LEVEL_CPPFLAGS=-DHAS_LAHF_SAHF > > + fi > > + cat > conftest.c < > +extern int x; > > +int > > +bar () > > +{ > > + return __builtin_bswap32 (x); > > +} > > +EOF > > + if AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS -O2 -S -o - conftest.c) | grep -q " movbe"; then > > + ISA_LEVEL_CPPFLAGS="$ISA_LEVEL_CPPFLAGS -DHAS_MOVBE" > > + fi > > Please check -fverbose-asm output, I expect it to be less brittle. Like > when new tunings result in GCC not selecting the relevant instructions. Fixed. > > +DEFAULT_ISA_LEVEL=(ISA_BASELINE | ISA_V2 | ISA_V3 | ISA_V4) > > I don't think it's necessary to set this as a part of a configure check. > Perhaps define macros for SAHF and MOVBE, and check them in > sysdeps/x86/isa-level.c? Fixed. > But I think there's another issue: If someone builds with an option like > mno-lzcnt, it will poke a hole into the ISA level, in the sense that V2 > and V4 are support, but not V3. I think this is wrong, it should always > be an increasing progression. Fixed. Here is the v5 patch. OK for master? Thanks. From 9ee9ba5872842d64cb5ecb95fe2bb182239201e6 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Tue, 2 Feb 2021 13:45:58 -0800 Subject: [PATCH v5] 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 Set the minimum, instead of maximum, x86-64 ISA level marker should have no impact on the glibc-hwcaps directory assignment logic in ldconfig nor ld.so. --- config.h.in | 6 ++++++ sysdeps/x86/configure | 28 ++++++++++++++++++++++++++++ sysdeps/x86/configure.ac | 16 ++++++++++++++++ sysdeps/x86/isa-level.c | 25 ++++++++++++++----------- 4 files changed, 64 insertions(+), 11 deletions(-) diff --git a/config.h.in b/config.h.in index 06ee8ae26a..f21bf04e47 100644 --- a/config.h.in +++ b/config.h.in @@ -275,4 +275,10 @@ /* Define if x86 ISA level should be included in shared libraries. */ #undef INCLUDE_X86_ISA_LEVEL +/* Define if -msahf is enabled by default on x86. */ +#undef HAVE_X86_LAHF_SAHF + +/* Define if -mmovbe is enabled by default on x86. */ +#undef HAVE_X86_MOVBE + #endif diff --git a/sysdeps/x86/configure b/sysdeps/x86/configure index 5e32dc62b3..ead1295c38 100644 --- a/sysdeps/x86/configure +++ b/sysdeps/x86/configure @@ -126,6 +126,8 @@ cat > conftest2.S <&5 (eval $ac_try) 2>&5 @@ -135,6 +137,24 @@ if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS -nostartfiles -nostdlib -r -o conftest c 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 "\-msahf"; then + libc_cv_have_x86_lahf_sahf=yes + fi + if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS -fverbose-asm -S -o - conftest.c' + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; } | grep -q "\-mmovbe"; then + libc_cv_have_x86_movbe=yes + fi fi fi rm -f conftest* @@ -144,6 +164,14 @@ $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 +fi +if test $libc_cv_have_x86_lahf_sahf = yes; then + $as_echo "#define HAVE_X86_LAHF_SAHF 1" >>confdefs.h + +fi +if test $libc_cv_have_x86_movbe = yes; then + $as_echo "#define HAVE_X86_MOVBE 1" >>confdefs.h + 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..bca97fdc2f 100644 --- a/sysdeps/x86/configure.ac +++ b/sysdeps/x86/configure.ac @@ -98,14 +98,30 @@ cat > conftest2.S < conftest.c <