From patchwork Tue Feb 9 00:29:35 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: 41978 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 092333874C1F; Tue, 9 Feb 2021 00:30:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 092333874C1F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1612830617; bh=+IgfYARIZkjmDvS0wbMuWnkXgkoY5jR2YL+I0IkyCYg=; 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=w8P2vdphu83WSXFD7ZCyiABS8JpG9YYGWaY+1XqYs8anRWI+aBB2NJrUmuFA4h1gv 81J9mk9lgcdBFadsyK37WFGJ2VBjXlwkl9omUCGSfjHx5NeLqFBTQ2bKZqpnz2eA06 eHn3h3S8As4OH5iYhw1jLp32D/joJfl84aIkgeYI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id 132E83857820 for ; Tue, 9 Feb 2021 00:30:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 132E83857820 Received: by mail-ot1-x332.google.com with SMTP id 100so9276628otg.3 for ; Mon, 08 Feb 2021 16:30:12 -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=+IgfYARIZkjmDvS0wbMuWnkXgkoY5jR2YL+I0IkyCYg=; b=nhtzwwjNm8lhaLXW7e44m7664hNqxbr4aPJ1mclqGqBLicdh8PpUlRG/n21nUvoqiQ QnkvWvm7V5xTajJq2ma+J8vao3Tjni6klg0WSlVmxjvnCypstjNimQ1JAyDaWjTiXu5o nCjwO7q1sJUCazF2S8Q39/fmG0woofOKmSoDFyFGCYWxr+K/VxrJ9ay9D182A8dsl/+4 /zZ5blt4MMJM32E9YpFFKcFtAeYOnXdXlP/tU6+bs4l9OKJGH3Xbry82OGvT2/a4U28z akFfveO9z9wdXQg5rx+Y+xa7bQkXj445NynGZIQL+Ok4XcIeLZADLQHsv+cmEU8rJuKX dR0g== X-Gm-Message-State: AOAM5329RN1Tlhjf5A7oAWI7ZpxAOc3E3nuv89wNHd6nK5W5JVRd1Css U4cvFoL/fc8wfPxH6gkabhtdCoi5kqjJxAK2g/E= X-Google-Smtp-Source: ABdhPJxqnA7S+NhwWhIMVPcTSdTMUGRxwDkdf4qenOYqRJWE6FxUS/advDXUxmjk94bhXfm8OdcIZGQbn0nIQCxPFSs= X-Received: by 2002:a9d:1717:: with SMTP id i23mr14565128ota.179.1612830611490; Mon, 08 Feb 2021 16:30:11 -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> In-Reply-To: Date: Mon, 8 Feb 2021 16:29:35 -0800 Message-ID: Subject: [PATCH v3] x86: Disable x86-64 level marker [BZ #27318] To: Florian Weimer X-Spam-Status: No, score=-3036.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, Feb 8, 2021 at 8:09 AM H.J. Lu wrote: > > On Mon, Feb 8, 2021 at 7:06 AM Florian Weimer wrote: > > > > * H. J. Lu via Libc-alpha: > > > > > It is used to check if INCLUDE_X86_ISA_LEVEL should be defined in > > > config.h. INCLUDE_X86_ISA_LEVEL is defined only if GCC enables > > > the full ISAs of a level without any ISAs of the higher ISA levels. Since > > > I want to support GCC older than GCC 11, || is used to detect any > > > ISAs in a level and !|| is used to check if any ISAs are missing. > > > > But isn't && the right construct anyway? As in, if GCC was built to > > include *all* feature flags for a specific level, require that level at > > run time? > > isa-level.c serves 2 purposes: > > 1. Add ISA level marker (|| path) when INCLUDE_X86_ISA_LEVEL is defined. > "# error" path will never be hit. > 2. Used by sysdeps/x86/configure.ac to check if INCLUDE_X86_ISA_LEVEL > should be defined. If any ISAs (!|| path) are missing, INCLUDE_X86_ISA_LEVEL > won't be defined. > > Since GCC 10 doesn't define __LAHF_SAHF__, __MOVBE__ nor __XSAVE__, > "&&" doesn't work for GCC 10. However, I can move ISAs check to > sysdeps/x86/configure.ac and define INCLUDE_X86_ISA_LEVEL to This patch does it. > #define INCLUDE_X86_ISA_LEVEL GNU_PROPERTY_X86_ISA_1_XXX > > > >> Are ISA levels really defined for 32-bit? > > > > > > 32-bit can just use the same x86-64 ISA level. > > > > At least it requires figuring out the baseline level between i386 and > > x86-64-v2, probably based on what GCC's -march=x86-64 option does with > > -m32. > > > > Yes, we can make the minimum i386 ISAs for glibc as i386 baseline. > Since i386 is legacy, this patch disables x86-64 ISA level marker for 32-bit build. Here is the v3 patch. Changes from v2: 1. Disable x86-64 ISA level marker for 32-bit build. 2. Disable x86-64 ISA level marker for -march=XXX if its ISA set isn't a complete subnet of a ISA level. From 432402b377b9ded33fd294cb2f819be139161472 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Tue, 2 Feb 2021 13:45:58 -0800 Subject: [PATCH v3] x86: Disable x86-64 level marker [BZ #27318] Since -march=sandybridge enables some ISAs in x86-64 ISA level v3, the v3 marker is set on libc.so. We couldn't set the needed ISA marker to v2 since this libc won't run on all v2 machines. Technically, the v3 marker is correct. But the resulting libc.so won't run on Sandybrigde, which isn't a v3 machine, even when libc is compiled with -march=sandybridge: $ ./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. Disable x86-64 ISA level marker for -march=XXX if its ISA set isn't a complete subnet of a ISA level. --- config.h.in | 3 + sysdeps/x86/configure | 119 ++++++++++++++++++++++++++++++++++++++- sysdeps/x86/configure.ac | 101 ++++++++++++++++++++++++++++++++- sysdeps/x86/isa-level.c | 33 +---------- 4 files changed, 222 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..3812ba288e 100644 --- a/sysdeps/x86/configure +++ b/sysdeps/x86/configure @@ -134,7 +134,120 @@ 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=-D__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 -D__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 +257,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..39d307a6d1 100644 --- a/sysdeps/x86/configure.ac +++ b/sysdeps/x86/configure.ac @@ -101,11 +101,110 @@ 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 <