Discussion:
host-cpu-c-abi update
(too old to reply)
Bruno Haible
2017-01-16 21:11:15 UTC
Permalink
Raw Message
The 'host-cpu-c-abi' module (which is used by GNU libffcall) does not know
about some ABIs that have appeared in the last few years. This fixes it.


2017-01-16 Bruno Haible <***@clisp.org>

host-cpu-c-abi: Add support for armhf, arm64, x32, s390x.
* m4/host-cpu-c-abi.m4 (gl_HOST_CPU_C_ABI): Require gl_C_ASM. On x86_64
systems, distinguish x86_64 and x32. On arm systems, distinguish arm,
armhf, arm64, and no longer distinguish arm and armel. On s390x systems,
distinguish s390 and s390x.
* modules/host-cpu-c-abi (Files): Add m4/asm-underscore.m4.
* NEWS: Mention the change regarding 'armel'.

diff --git a/NEWS b/NEWS
index 791bcaf..90ce1a2 100644
--- a/NEWS
+++ b/NEWS
@@ -42,6 +42,9 @@ User visible incompatible changes

Date Modules Changes

+2017-01-16 host-cpu-c-abi On ARM platforms, HOST_CPU_C_ABI is now set to
+ 'arm' or 'armhf' instead of 'armel'.
+
2017-01-15 localeinfo Change case_folded_counterparts's first arg's type
from wchar_t to wint_t, so it now accepts WEOF.

diff --git a/m4/host-cpu-c-abi.m4 b/m4/host-cpu-c-abi.m4
index 229cf07..e408f08 100644
--- a/m4/host-cpu-c-abi.m4
+++ b/m4/host-cpu-c-abi.m4
@@ -1,4 +1,4 @@
-# host-cpu-c-abi.m4 serial 1
+# host-cpu-c-abi.m4 serial 2
dnl Copyright (C) 2002-2017 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -46,6 +46,7 @@ dnl See <http://en.wikipedia.org/wiki/X86_instruction_listings>.
AC_DEFUN([gl_HOST_CPU_C_ABI],
[
AC_REQUIRE([AC_CANONICAL_HOST])
+ AC_REQUIRE([gl_C_ASM])
AC_CACHE_CHECK([host CPU and C ABI], [gl_cv_host_cpu_c_abi],
[case "$host_cpu" in

@@ -56,13 +57,23 @@ changequote([,])dnl
;;

x86_64 )
- # On x86_64 systems, the C compiler may still be generating
- # 32-bit code.
+ # On x86_64 systems, the C compiler may be generating code in one of
+ # these ABIs:
+ # - 64-bit instruction set, 64-bit pointers, 64-bit 'long': x86_64.
+ # - 64-bit instruction set, 64-bit pointers, 32-bit 'long': x86_64
+ # with native Windows (mingw, MSVC).
+ # - 64-bit instruction set, 32-bit pointers, 32-bit 'long': x32.
+ # - 32-bit instruction set, 32-bit pointers, 32-bit 'long': i386.
AC_EGREP_CPP([yes],
- [#if defined __LP64__ || defined __x86_64__ || defined __amd64__
+ [#if defined __x86_64__ || defined __amd64__ || defined _M_X64 || defined _M_AMD64
yes
#endif],
- [gl_cv_host_cpu_c_abi=x86_64],
+ [AC_EGREP_CPP([yes],
+ [#if defined __ILP32__ || defined _ILP32
+ yes
+ #endif],
+ [gl_cv_host_cpu_c_abi=x32],
+ [gl_cv_host_cpu_c_abi=x86_64])],
[gl_cv_host_cpu_c_abi=i386])
;;

@@ -73,12 +84,35 @@ changequote([,])dnl
;;

arm* )
+ # Assume arm with EABI.
+ # On arm64, the C compiler may be generating 64-bit (= aarch64) code
+ # or 32-bit (= arm) code.
AC_EGREP_CPP([yes],
- [#if defined __ARMEL__
+ [#if defined(__aarch64__) || defined(__ARM_64BIT_STATE) || defined(__ARM_PCS_AAPCS64)
yes
#endif],
- [gl_cv_host_cpu_c_abi=armel],
- [gl_cv_host_cpu_c_abi=arm])
+ [gl_cv_host_cpu_c_abi=arm64],
+ [# Don't distinguish little-endian and big-endian arm, since they
+ # don't require different machine code for simple operations and
+ # since the user can distinguish them through the preprocessot
+ # defines __ARMEL__ vs. __ARMEB__.
+ # But distinguish arm which passes floating-point arguments and
+ # return values in integer registers (r0, r1, ...) - this is
+ # gcc -mfloat-abi=soft or gcc -mfloat-abi=softfp - from arm which
+ # passes them in float registers (s0, s1, ...) and double registers
+ # (d0, d1, ...) - rhis is gcc -mfloat-abi=hard. GCC 4.6 or newer
+ # sets the preprocessor defines __ARM_PCS (for the first case) and
+ # __ARM_PCS_VFP (for the second case), but older GCC does not.
+ echo 'double ddd; void func (double dd) { ddd = dd; }' > conftest.c
+ # Look for a reference to the register d0 in the .s file.
+ AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS $gl_c_asm_opt conftest.c) >/dev/null 2>&1
+ if LC_ALL=C grep -E 'd0,' conftest.$gl_asmext >/dev/null; then
+ gl_cv_host_cpu_c_abi=armhf
+ else
+ gl_cv_host_cpu_c_abi=arm
+ fi
+ rm -f conftest*
+ ])
;;

hppa1.0 | hppa1.1 | hppa2.0* | hppa64 )
@@ -107,6 +141,9 @@ changequote([,])dnl
;;

powerpc64 )
+ # Different ABIs are in use on AIX vs. Mac OS X vs. Linux,*BSD.
+ # No need to distinguish them here; the caller may distinguish
+ # them based on the OS.
# On powerpc64 systems, the C compiler may still be generating
# 32-bit code.
AC_EGREP_CPP([yes],
@@ -121,7 +158,16 @@ changequote([,])dnl
gl_cv_host_cpu_c_abi=powerpc
;;

- # TODO: Distinguish s390 and s390x correctly.
+ s390* )
+ # On s390x, the C compiler may be generating 64-bit (= s390x) code
+ # or 31-bit (= s390) code.
+ AC_EGREP_CPP([yes],
+ [#if defined(__LP64__) || defined(__s390x__)
+ yes
+ #endif],
+ [gl_cv_host_cpu_c_abi=s390x],
+ [gl_cv_host_cpu_c_abi=s390])
+ ;;

sparc | sparc64 )
# UltraSPARCs running Linux have `uname -m` = "sparc64", but the
@@ -154,6 +200,9 @@ EOF
#ifndef __i386__
#undef __i386__
#endif
+#ifndef __x32__
+#undef __x32__
+#endif
#ifndef __x86_64__
#undef __x86_64__
#endif
@@ -163,8 +212,11 @@ EOF
#ifndef __arm__
#undef __arm__
#endif
-#ifndef __armel__
-#undef __armel__
+#ifndef __armhf__
+#undef __armhf__
+#endif
+#ifndef __arm64__
+#undef __arm64__
#endif
#ifndef __hppa__
#undef __hppa__
diff --git a/modules/host-cpu-c-abi b/modules/host-cpu-c-abi
index a9011c5..6c92cc4 100644
--- a/modules/host-cpu-c-abi
+++ b/modules/host-cpu-c-abi
@@ -3,6 +3,7 @@ Determine canonical name of CPU and C ABI.

Files:
m4/host-cpu-c-abi.m4
+m4/asm-underscore.m4

Depends-on:
Bruno Haible
2017-02-11 12:48:56 UTC
Permalink
Raw Message
One more update of this module, for the benefit of GNU libffcall:
- A more systematic handling of non-default ABIs (like x32 on x86_64).
- Fix for 64-bit compilation on AIX (config.guess says 'powerpc' when
in fact the CPU ISA is 'powerpc64').
- Fox for 32-bit compilation on arm64 (config.guess says 'aarch64' when
in fact the compiler supports produces 'arm' code).
- Also fix a long-standing TODO item: recognize hppa64.


2017-02-11 Bruno Haible <***@clisp.org>

host-cpu-c-abi: Support for 64-bit AIX, 32-bit armhf on arm64, hppa64.
* m4/host-cpu-c-abi.m4 (gl_HOST_CPU_C_ABI): Define also HOST_CPU.
For the x32 ABI on x86_64, set HOST_CPU_C_ABI to 'x86_64-x32' and define
both __x86_64__ and __x86_64_x32__. For the ELFv2 ABI on powerpc64,
define both __powerpc64__ and __powerpc64_elfv2__. Recognize 64-bit
compilation on AIX. Recognize 32-bit compilation on arm64/Linux.
Distinguish hppa64 from hppa.

diff --git a/m4/host-cpu-c-abi.m4 b/m4/host-cpu-c-abi.m4
index e408f08..1ec2f74 100644
--- a/m4/host-cpu-c-abi.m4
+++ b/m4/host-cpu-c-abi.m4
@@ -1,4 +1,4 @@
-# host-cpu-c-abi.m4 serial 2
+# host-cpu-c-abi.m4 serial 3
dnl Copyright (C) 2002-2017 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -6,9 +6,11 @@ dnl with or without modifications, as long as this notice is preserved.

dnl From Bruno Haible and Sam Steingold.

+dnl Sets the HOST_CPU variable to the canonical name of the CPU.
dnl Sets the HOST_CPU_C_ABI variable to the canonical name of the CPU with its
dnl C language ABI (application binary interface).
-dnl Also defines __${HOST_CPU_C_ABI}__ as a C macro in config.h.
+dnl Also defines __${HOST_CPU}__ and __${HOST_CPU_C_ABI}__ as C macros in
+dnl config.h.
dnl
dnl This canonical name can be used to select a particular assembly language
dnl source file that will interoperate with C code on the given host.
@@ -29,9 +31,11 @@ dnl instruction set of 'mipsn32'.
dnl * 'mipsn32' and 'mips64' are different canonical names, because they use
dnl different sizes for the C types like 'int' and 'void *', and although
dnl the instruction sets of 'mipsn32' and 'mips64' are the same.
-dnl * 'arm' and 'armel' are different canonical names, because they use
-dnl different memory ordering for the C types like 'int', and although
-dnl the instruction sets of 'arm' and 'armel' are the same.
+dnl * The same canonical name is used for different endiannesses. You can
+dnl determine the endianness through preprocessor symbols:
+dnl - 'arm': test __ARMEL__.
+dnl - 'mips', 'mipsn32', 'mips64': test _MIPSEB vs. _MIPSEL.
+dnl - 'powerpc64': test _BIG_ENDIAN vs. _LITTLE_ENDIAN.
dnl * The same name 'i386' is used for CPUs of type i386, i486, i586
dnl (Pentium), AMD K7, Pentium II, Pentium IV, etc., because
dnl - Instructions that do not exist on all of these CPUs (cmpxchg,
@@ -62,7 +66,7 @@ changequote([,])dnl
# - 64-bit instruction set, 64-bit pointers, 64-bit 'long': x86_64.
# - 64-bit instruction set, 64-bit pointers, 32-bit 'long': x86_64
# with native Windows (mingw, MSVC).
- # - 64-bit instruction set, 32-bit pointers, 32-bit 'long': x32.
+ # - 64-bit instruction set, 32-bit pointers, 32-bit 'long': x86_64-x32.
# - 32-bit instruction set, 32-bit pointers, 32-bit 'long': i386.
AC_EGREP_CPP([yes],
[#if defined __x86_64__ || defined __amd64__ || defined _M_X64 || defined _M_AMD64
@@ -72,7 +76,7 @@ changequote([,])dnl
[#if defined __ILP32__ || defined _ILP32
yes
#endif],
- [gl_cv_host_cpu_c_abi=x32],
+ [gl_cv_host_cpu_c_abi=x86_64-x32],
[gl_cv_host_cpu_c_abi=x86_64])],
[gl_cv_host_cpu_c_abi=i386])
;;
@@ -83,7 +87,7 @@ changequote([,])dnl
gl_cv_host_cpu_c_abi=alpha
;;

- arm* )
+ arm* | aarch64 )
# Assume arm with EABI.
# On arm64, the C compiler may be generating 64-bit (= aarch64) code
# or 32-bit (= arm) code.
@@ -116,8 +120,14 @@ changequote([,])dnl
;;

hppa1.0 | hppa1.1 | hppa2.0* | hppa64 )
- # TODO: Distinguish hppa and hppa64 correctly.
- gl_cv_host_cpu_c_abi=hppa
+ # On hppa, the C compiler may be generating 32-bit code or 64-bit
+ # code. In the latter case, it defines _LP64 and __LP64__.
+ AC_EGREP_CPP([yes],
+ [#if defined(__LP64__)
+ yes
+ #endif],
+ [gl_cv_host_cpu_c_abi=hppa64],
+ [gl_cv_host_cpu_c_abi=hppa])
;;

mips* )
@@ -140,17 +150,26 @@ changequote([,])dnl
[gl_cv_host_cpu_c_abi=mips])])
;;

- powerpc64 )
+ powerpc* )
# Different ABIs are in use on AIX vs. Mac OS X vs. Linux,*BSD.
# No need to distinguish them here; the caller may distinguish
# them based on the OS.
# On powerpc64 systems, the C compiler may still be generating
- # 32-bit code.
+ # 32-bit code. And on powerpc-ibm-aix systems, the C compiler may
+ # be generating 64-bit code.
AC_EGREP_CPP([yes],
[#if defined __powerpc64__ || defined _ARCH_PPC64
yes
#endif],
- [gl_cv_host_cpu_c_abi=powerpc64],
+ [# On powerpc64, there are two ABIs on Linux: The AIX compatible
+ # one and the ELFv2 one. The latter defines _CALL_ELF=2.
+ AC_EGREP_CPP([yes],
+ [#if defined _CALL_ELF && _CALL_ELF == 2
+ yes
+ #endif],
+ [gl_cv_host_cpu_c_abi=powerpc64-elfv2],
+ [gl_cv_host_cpu_c_abi=powerpc64])
+ ],
[gl_cv_host_cpu_c_abi=powerpc])
;;

@@ -186,22 +205,30 @@ changequote([,])dnl
esac
])

+ dnl In most cases, $HOST_CPU and $HOST_CPU_C_ABI are the same.
+ HOST_CPU=`echo "$gl_cv_host_cpu_c_abi" | sed -e 's/-.*//'`
HOST_CPU_C_ABI="$gl_cv_host_cpu_c_abi"
+ AC_SUBST([HOST_CPU])
AC_SUBST([HOST_CPU_C_ABI])

- # This was AC_DEFINE_UNQUOTED([__${gl_cv_host_cpu_c_abi}__]) earlier,
- # but KAI C++ 3.2d doesn't like this.
- cat >> confdefs.h <<EOF
-#ifndef __${gl_cv_host_cpu_c_abi}__
-#define __${gl_cv_host_cpu_c_abi}__ 1
+ # This was
+ # AC_DEFINE_UNQUOTED([__${HOST_CPU}__])
+ # AC_DEFINE_UNQUOTED([__${HOST_CPU_C_ABI}__])
+ # earlier, but KAI C++ 3.2d doesn't like this.
+ sed -e 's/-/_/g' >> confdefs.h <<EOF
+#ifndef __${HOST_CPU}__
+#define __${HOST_CPU}__ 1
+#endif
+#ifndef __${HOST_CPU_C_ABI}__
+#define __${HOST_CPU_C_ABI}__ 1
#endif
EOF
AH_TOP([/* CPU and C ABI indicator */
#ifndef __i386__
#undef __i386__
#endif
-#ifndef __x32__
-#undef __x32__
+#ifndef __x86_64_x32__
+#undef __x86_64_x32__
#endif
#ifndef __x86_64__
#undef __x86_64__
@@ -245,6 +272,9 @@ EOF
#ifndef __powerpc64__
#undef __powerpc64__
#endif
+#ifndef __powerpc64_elfv2__
+#undef __powerpc64_elfv2__
+#endif
#ifndef __s390__
#undef __s390__
#endif

Loading...