diff mbox

PR bootstrap/65176: config.guess failed to guess machine with 64-bit kernel and 32-bit user space

Message ID 20150223171743.GA32755@intel.com
State New
Headers show

Commit Message

H.J. Lu Feb. 23, 2015, 5:17 p.m. UTC
32-bit and x32 user-space environments may be running under Linux/x86-64
kernel.  Using "uname -m" isn't sufficient to properly detect the
canonical system name for 32-bit and x32 user-space environments.  This
patch checks if compiler is configured for 64-bit, 32-bit or x32 objects
under Linux/x86-64 kernel.

Tested with 64-bit, 32-bit and x32 user-space environments under
Linux/x86-64 kernel.  I am not sure if this will ever be accepted in
upstream since the config.guess maintainer doesn't want to add a new
use of set_cc_for_build to config.guess.  set_cc_for_build is used for
Linux:

case "${UNAME_SYSTEM}" in
Linux|GNU|GNU/*)
        # If the system lacks a compiler, then just pick glibc.
        # We could probably try harder.
        LIBC=gnu

        eval $set_cc_for_build
        cat <<-EOF > $dummy.c
        #include <features.h>
        #if defined(__UCLIBC__)
        LIBC=uclibc
        #elif defined(__dietlibc__)
        LIBC=dietlibc
        #else
        LIBC=gnu
        #endif
        EOF
        eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC' | sed 's, ,,g'`
        ;;

Adding another use for Linux/x86-64 solves this issue.  I'd like to see
this fixed in gcc, binutils and glibc even if it won't be fixed in
upstream.

Thanks.

H.J.
---
	PR bootstrap/65176
	* config.guess (x86_64:Linux:*:*): Check if compiler is configured
	for 64-bit, 32-bit or x32 objects.
---
 config.guess | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

Comments

Jakub Jelinek Feb. 23, 2015, 5:40 p.m. UTC | #1
On Mon, Feb 23, 2015 at 09:17:43AM -0800, H.J. Lu wrote:
> 32-bit and x32 user-space environments may be running under Linux/x86-64
> kernel.  Using "uname -m" isn't sufficient to properly detect the
> canonical system name for 32-bit and x32 user-space environments.  This
> patch checks if compiler is configured for 64-bit, 32-bit or x32 objects
> under Linux/x86-64 kernel.
> 
> Tested with 64-bit, 32-bit and x32 user-space environments under
> Linux/x86-64 kernel.  I am not sure if this will ever be accepted in
> upstream since the config.guess maintainer doesn't want to add a new
> use of set_cc_for_build to config.guess.  set_cc_for_build is used for
> Linux:

Ugh, isn't this what setarch is meant for?

	Jakub
Joseph Myers Feb. 23, 2015, 5:44 p.m. UTC | #2
On Mon, 23 Feb 2015, H.J. Lu wrote:

> Tested with 64-bit, 32-bit and x32 user-space environments under
> Linux/x86-64 kernel.  I am not sure if this will ever be accepted in
> upstream since the config.guess maintainer doesn't want to add a new
> use of set_cc_for_build to config.guess.  set_cc_for_build is used for
> Linux:

Well, we don't want any local changes to config.* in GCC / binutils-gdb / 
glibc - those files should remain as files that only get updated by 
verbatim copying from config.git.

In glibc, sysdeps/x86_64/preconfigure.ac already checks for x32.  I think 
it would be fine to combine sysdeps/i386/preconfigure and 
sysdeps/x86_64/preconfigure.ac into a single sysdeps/x86/preconfigure.ac 
that allows both i?86 and x86_64 triplets to be used for all three ABIs, 
determining the correct machine and base_machine settings based on how the 
compiler behaves.
H.J. Lu Feb. 23, 2015, 5:49 p.m. UTC | #3
On Mon, Feb 23, 2015 at 9:40 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Mon, Feb 23, 2015 at 09:17:43AM -0800, H.J. Lu wrote:
>> 32-bit and x32 user-space environments may be running under Linux/x86-64
>> kernel.  Using "uname -m" isn't sufficient to properly detect the
>> canonical system name for 32-bit and x32 user-space environments.  This
>> patch checks if compiler is configured for 64-bit, 32-bit or x32 objects
>> under Linux/x86-64 kernel.
>>
>> Tested with 64-bit, 32-bit and x32 user-space environments under
>> Linux/x86-64 kernel.  I am not sure if this will ever be accepted in
>> upstream since the config.guess maintainer doesn't want to add a new
>> use of set_cc_for_build to config.guess.  set_cc_for_build is used for
>> Linux:
>
> Ugh, isn't this what setarch is meant for?
>

It doesn't cover x32.
Jakub Jelinek Feb. 23, 2015, 5:52 p.m. UTC | #4
On Mon, Feb 23, 2015 at 09:49:43AM -0800, H.J. Lu wrote:
> On Mon, Feb 23, 2015 at 9:40 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> > On Mon, Feb 23, 2015 at 09:17:43AM -0800, H.J. Lu wrote:
> >> 32-bit and x32 user-space environments may be running under Linux/x86-64
> >> kernel.  Using "uname -m" isn't sufficient to properly detect the
> >> canonical system name for 32-bit and x32 user-space environments.  This
> >> patch checks if compiler is configured for 64-bit, 32-bit or x32 objects
> >> under Linux/x86-64 kernel.
> >>
> >> Tested with 64-bit, 32-bit and x32 user-space environments under
> >> Linux/x86-64 kernel.  I am not sure if this will ever be accepted in
> >> upstream since the config.guess maintainer doesn't want to add a new
> >> use of set_cc_for_build to config.guess.  set_cc_for_build is used for
> >> Linux:
> >
> > Ugh, isn't this what setarch is meant for?
> >
> 
> It doesn't cover x32.

So extend it for x32?
I mean, this is the way various other Linux arches work (e.g. powerpc*, s390*,
sparc*, etc.), you are trying to do something different and again for x86
only.

	Jakub
H.J. Lu Feb. 23, 2015, 5:58 p.m. UTC | #5
On Mon, Feb 23, 2015 at 9:52 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Mon, Feb 23, 2015 at 09:49:43AM -0800, H.J. Lu wrote:
>> On Mon, Feb 23, 2015 at 9:40 AM, Jakub Jelinek <jakub@redhat.com> wrote:
>> > On Mon, Feb 23, 2015 at 09:17:43AM -0800, H.J. Lu wrote:
>> >> 32-bit and x32 user-space environments may be running under Linux/x86-64
>> >> kernel.  Using "uname -m" isn't sufficient to properly detect the
>> >> canonical system name for 32-bit and x32 user-space environments.  This
>> >> patch checks if compiler is configured for 64-bit, 32-bit or x32 objects
>> >> under Linux/x86-64 kernel.
>> >>
>> >> Tested with 64-bit, 32-bit and x32 user-space environments under
>> >> Linux/x86-64 kernel.  I am not sure if this will ever be accepted in
>> >> upstream since the config.guess maintainer doesn't want to add a new
>> >> use of set_cc_for_build to config.guess.  set_cc_for_build is used for
>> >> Linux:
>> >
>> > Ugh, isn't this what setarch is meant for?
>> >
>>
>> It doesn't cover x32.
>
> So extend it for x32?

How could it be extended to x32?

> I mean, this is the way various other Linux arches work (e.g. powerpc*, s390*,
> sparc*, etc.), you are trying to do something different and again for x86
> only.
>
>         Jakub
diff mbox

Patch

diff --git a/config.guess b/config.guess
index dbfb978..e5a2d41 100755
--- a/config.guess
+++ b/config.guess
@@ -1021,7 +1021,26 @@  EOF
 	echo ${UNAME_MACHINE}-dec-linux-${LIBC}
 	exit ;;
     x86_64:Linux:*:*)
-	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	eval $set_cc_for_build
+	LINUX_MACHINE="i686"
+	LINUX_LIBC=${LIBC}
+	# If there is a compiler, see if it is configured for 64-bit,
+	# 32-bit or x32 objects.
+	if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
+	    if (echo '#ifdef __x86_64__'; echo IS_64BIT_ARCH; echo '#endif') | \
+		(CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
+		grep IS_64BIT_ARCH >/dev/null
+	    then
+	      LINUX_MACHINE="x86_64"
+	      if (echo '#ifdef __ILP32__'; echo IS_X32; echo '#endif') | \
+		  (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
+		   grep IS_X32 >/dev/null
+	      then
+		LINUX_LIBC=gnux32
+	      fi
+	    fi
+	fi
+	echo ${LINUX_MACHINE}-unknown-linux-${LINUX_LIBC}
 	exit ;;
     xtensa*:Linux:*:*)
 	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}