[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: config.guess returns bogus triple on Linux/x86_64 bi-arch system
From: |
Dmitry V. Levin |
Subject: |
Re: config.guess returns bogus triple on Linux/x86_64 bi-arch system |
Date: |
Sun, 8 May 2022 20:59:36 +0300 |
On Sun, May 08, 2022 at 07:25:34PM +0200, Bruno Haible wrote:
> On Linux/x86_64, there are three ABIs that the kernel understands directly
> (without qemu user):
> - 64-bit, as produced by "gcc -m64",
> - 32-bit (i686 code), as produced by "gcc -m32",
> - 64-bit instructions with 32-bit pointers, as produced by "gcc -mx32".
>
> The patch from 2020-06-15 "* config.guess (x86_64:Linux:*:*): Detect x32 ABI."
> <https://lists.gnu.org/archive/html/config-patches/2020-06/msg00005.html>
> added support for recognizing the third case (x32 ABI).
>
> But it broke the second case (32-bit ABI), when a GCC version 9 or higher is
> used.
> $ CC="gcc-version 8.5.0 -m32" ./config.guess
> x86_64-pc-linux-gnu
> $ CC="gcc-version 9.4.0 -m32" ./config.guess
> x86_64-pc-linux-gnux32
> $ CC="gcc-version 10.3.0 -m32" ./config.guess
> x86_64-pc-linux-gnux32
> $ CC="gcc-version 11.3.0 -m32" ./config.guess
> x86_64-pc-linux-gnux32
> $ CC="gcc-version 12.1.0 -m32" ./config.guess
> x86_64-pc-linux-gnux32
>
> The reason is that the code tests for the __ILP32__ preprocessor symbol,
> and this preprocessor symbol is defined also in the 32-bit ABI for GCC ≥ 9.
> See:
>
> $ : | gcc-version 8.5.0 -m64 -E -dM - | grep '\(LP\|__.*86.* 1\)'
> #define __x86_64 1
> #define __LP64__ 1
> #define __x86_64__ 1
> #define _LP64 1
> $ : | gcc-version 9.4.0 -m64 -E -dM - | grep '\(LP\|__.*86.* 1\)'
> #define __x86_64 1
> #define __LP64__ 1
> #define __x86_64__ 1
> #define _LP64 1
>
> $ : | gcc-version 8.5.0 -m32 -E -dM - | grep '\(LP\|__.*86.* 1\)'
> #define __i386 1
> #define __i386__ 1
> $ : | gcc-version 9.4.0 -m32 -E -dM - | grep '\(LP\|__.*86.* 1\)'
> #define __i386 1
> #define __i386__ 1
> #define __ILP32__ 1
> #define _ILP32 1
>
> $ : | gcc-version 8.5.0 -mx32 -E -dM - | grep '\(LP\|__.*86.* 1\)'
> #define __x86_64 1
> #define __x86_64__ 1
> #define __ILP32__ 1
> #define _ILP32 1
> $ : | gcc-version 9.4.0 -mx32 -E -dM - | grep '\(LP\|__.*86.* 1\)'
> #define __x86_64 1
> #define __x86_64__ 1
> #define __ILP32__ 1
> #define _ILP32 1
>
> The config.guess of GCC 12.1.0 includes this change, and as a
> consequence, I can no longer build 32-bit binaries of GCC without
> specifying --build and --host options — something that worked in
> the past.
>
> Find here a patch that changes the output in the 32-bit ABI case
> from
>
> $ CC="gcc-version 8.5.0 -m32" ./config.guess
> x86_64-pc-linux-gnu
> $ CC="gcc-version 9.4.0 -m32" ./config.guess
> x86_64-pc-linux-gnux32
>
> to
>
> $ CC="gcc-version 8.5.0 -m32" ./config.guess
> i686-pc-linux-gnu
> $ CC="gcc-version 9.4.0 -m32" ./config.guess
> i686-pc-linux-gnu
>
> This is similar to what config.guess already does for Linux/mips and Darwin.
> It also fixes the problem I reported for CC="tcc" in
> <https://lists.gnu.org/archive/html/config-patches/2021-03/msg00000.html>.
> From 8de7981fd45505acfd4aa266290a5ec54a119ef3 Mon Sep 17 00:00:00 2001
> From: Bruno Haible <bruno@clisp.org>
> Date: Sun, 8 May 2022 19:08:08 +0200
> Subject: [PATCH 1/2] config.guess (x86_64:Linux:*:*): Detect 32-bit ABI.
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
>
> * config.guess (x86_64:Linux:*:*): Test for the 32-bit ABI. Don't assume that
> __ILP32__ is a certain indicator for the x32 ABI; for GCC ≥ 9 it no longer is.
> ---
> config.guess | 18 +++++++++++++-----
> 1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/config.guess b/config.guess
> index 7f76b62..f953bc9 100755
> --- a/config.guess
> +++ b/config.guess
> @@ -4,7 +4,7 @@
>
> # shellcheck disable=SC2006,SC2268 # see below for rationale
>
> -timestamp='2022-01-09'
> +timestamp='2022-05-08'
>
> # This file is free software; you can redistribute it and/or modify it
> # under the terms of the GNU General Public License as published by
> @@ -1151,16 +1151,24 @@ EOF
> ;;
> x86_64:Linux:*:*)
> set_cc_for_build
> + CPU=$UNAME_MACHINE
> LIBCABI=$LIBC
> if test "$CC_FOR_BUILD" != no_compiler_found; then
> - if (echo '#ifdef __ILP32__'; echo IS_X32; echo '#endif') | \
> + if (echo '#ifdef __i386__'; echo IS_X86; echo '#endif') | \
> (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
> - grep IS_X32 >/dev/null
> + grep IS_X86 >/dev/null
> then
> - LIBCABI=${LIBC}x32
> + CPU=i686
> + else
> + if (echo '#ifdef __ILP32__'; echo IS_X32; echo '#endif') | \
> + (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
> + grep IS_X32 >/dev/null
> + then
> + LIBCABI=${LIBC}x32
> + fi
> fi
> fi
> - GUESS=$UNAME_MACHINE-pc-linux-$LIBCABI
> + GUESS=$CPU-pc-linux-$LIBCABI
> ;;
> xtensa*:Linux:*:*)
> GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
Thanks, I agree with this approach in general, but could you rewrite the
test to invoke the compiler just once, please? You can use cc_set_libc
and cc_set_vars cases as examples.
--
ldv