1*eda14cbcSMatt Macy# host-cpu-c-abi.m4 serial 11 2*eda14cbcSMatt Macydnl Copyright (C) 2002-2019 Free Software Foundation, Inc. 3*eda14cbcSMatt Macydnl This file is free software; the Free Software Foundation 4*eda14cbcSMatt Macydnl gives unlimited permission to copy and/or distribute it, 5*eda14cbcSMatt Macydnl with or without modifications, as long as this notice is preserved. 6*eda14cbcSMatt Macy 7*eda14cbcSMatt Macydnl From Bruno Haible and Sam Steingold. 8*eda14cbcSMatt Macy 9*eda14cbcSMatt Macydnl Sets the HOST_CPU variable to the canonical name of the CPU. 10*eda14cbcSMatt Macydnl Sets the HOST_CPU_C_ABI variable to the canonical name of the CPU with its 11*eda14cbcSMatt Macydnl C language ABI (application binary interface). 12*eda14cbcSMatt Macydnl Also defines __${HOST_CPU}__ and __${HOST_CPU_C_ABI}__ as C macros in 13*eda14cbcSMatt Macydnl config.h. 14*eda14cbcSMatt Macydnl 15*eda14cbcSMatt Macydnl This canonical name can be used to select a particular assembly language 16*eda14cbcSMatt Macydnl source file that will interoperate with C code on the given host. 17*eda14cbcSMatt Macydnl 18*eda14cbcSMatt Macydnl For example: 19*eda14cbcSMatt Macydnl * 'i386' and 'sparc' are different canonical names, because code for i386 20*eda14cbcSMatt Macydnl will not run on SPARC CPUs and vice versa. They have different 21*eda14cbcSMatt Macydnl instruction sets. 22*eda14cbcSMatt Macydnl * 'sparc' and 'sparc64' are different canonical names, because code for 23*eda14cbcSMatt Macydnl 'sparc' and code for 'sparc64' cannot be linked together: 'sparc' code 24*eda14cbcSMatt Macydnl contains 32-bit instructions, whereas 'sparc64' code contains 64-bit 25*eda14cbcSMatt Macydnl instructions. A process on a SPARC CPU can be in 32-bit mode or in 64-bit 26*eda14cbcSMatt Macydnl mode, but not both. 27*eda14cbcSMatt Macydnl * 'mips' and 'mipsn32' are different canonical names, because they use 28*eda14cbcSMatt Macydnl different argument passing and return conventions for C functions, and 29*eda14cbcSMatt Macydnl although the instruction set of 'mips' is a large subset of the 30*eda14cbcSMatt Macydnl instruction set of 'mipsn32'. 31*eda14cbcSMatt Macydnl * 'mipsn32' and 'mips64' are different canonical names, because they use 32*eda14cbcSMatt Macydnl different sizes for the C types like 'int' and 'void *', and although 33*eda14cbcSMatt Macydnl the instruction sets of 'mipsn32' and 'mips64' are the same. 34*eda14cbcSMatt Macydnl * The same canonical name is used for different endiannesses. You can 35*eda14cbcSMatt Macydnl determine the endianness through preprocessor symbols: 36*eda14cbcSMatt Macydnl - 'arm': test __ARMEL__. 37*eda14cbcSMatt Macydnl - 'mips', 'mipsn32', 'mips64': test _MIPSEB vs. _MIPSEL. 38*eda14cbcSMatt Macydnl - 'powerpc64': test _BIG_ENDIAN vs. _LITTLE_ENDIAN. 39*eda14cbcSMatt Macydnl * The same name 'i386' is used for CPUs of type i386, i486, i586 40*eda14cbcSMatt Macydnl (Pentium), AMD K7, Pentium II, Pentium IV, etc., because 41*eda14cbcSMatt Macydnl - Instructions that do not exist on all of these CPUs (cmpxchg, 42*eda14cbcSMatt Macydnl MMX, SSE, SSE2, 3DNow! etc.) are not frequently used. If your 43*eda14cbcSMatt Macydnl assembly language source files use such instructions, you will 44*eda14cbcSMatt Macydnl need to make the distinction. 45*eda14cbcSMatt Macydnl - Speed of execution of the common instruction set is reasonable across 46*eda14cbcSMatt Macydnl the entire family of CPUs. If you have assembly language source files 47*eda14cbcSMatt Macydnl that are optimized for particular CPU types (like GNU gmp has), you 48*eda14cbcSMatt Macydnl will need to make the distinction. 49*eda14cbcSMatt Macydnl See <https://en.wikipedia.org/wiki/X86_instruction_listings>. 50*eda14cbcSMatt MacyAC_DEFUN([gl_HOST_CPU_C_ABI], 51*eda14cbcSMatt Macy[ 52*eda14cbcSMatt Macy AC_REQUIRE([AC_CANONICAL_HOST]) 53*eda14cbcSMatt Macy AC_REQUIRE([gl_C_ASM]) 54*eda14cbcSMatt Macy AC_CACHE_CHECK([host CPU and C ABI], [gl_cv_host_cpu_c_abi], 55*eda14cbcSMatt Macy [case "$host_cpu" in 56*eda14cbcSMatt Macy 57*eda14cbcSMatt Macychangequote(,)dnl 58*eda14cbcSMatt Macy i[4567]86 ) 59*eda14cbcSMatt Macychangequote([,])dnl 60*eda14cbcSMatt Macy gl_cv_host_cpu_c_abi=i386 61*eda14cbcSMatt Macy ;; 62*eda14cbcSMatt Macy 63*eda14cbcSMatt Macy x86_64 ) 64*eda14cbcSMatt Macy # On x86_64 systems, the C compiler may be generating code in one of 65*eda14cbcSMatt Macy # these ABIs: 66*eda14cbcSMatt Macy # - 64-bit instruction set, 64-bit pointers, 64-bit 'long': x86_64. 67*eda14cbcSMatt Macy # - 64-bit instruction set, 64-bit pointers, 32-bit 'long': x86_64 68*eda14cbcSMatt Macy # with native Windows (mingw, MSVC). 69*eda14cbcSMatt Macy # - 64-bit instruction set, 32-bit pointers, 32-bit 'long': x86_64-x32. 70*eda14cbcSMatt Macy # - 32-bit instruction set, 32-bit pointers, 32-bit 'long': i386. 71*eda14cbcSMatt Macy AC_COMPILE_IFELSE( 72*eda14cbcSMatt Macy [AC_LANG_SOURCE( 73*eda14cbcSMatt Macy [[#if (defined __x86_64__ || defined __amd64__ \ 74*eda14cbcSMatt Macy || defined _M_X64 || defined _M_AMD64) 75*eda14cbcSMatt Macy int ok; 76*eda14cbcSMatt Macy #else 77*eda14cbcSMatt Macy error fail 78*eda14cbcSMatt Macy #endif 79*eda14cbcSMatt Macy ]])], 80*eda14cbcSMatt Macy [AC_COMPILE_IFELSE( 81*eda14cbcSMatt Macy [AC_LANG_SOURCE( 82*eda14cbcSMatt Macy [[#if defined __ILP32__ || defined _ILP32 83*eda14cbcSMatt Macy int ok; 84*eda14cbcSMatt Macy #else 85*eda14cbcSMatt Macy error fail 86*eda14cbcSMatt Macy #endif 87*eda14cbcSMatt Macy ]])], 88*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi=x86_64-x32], 89*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi=x86_64])], 90*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi=i386]) 91*eda14cbcSMatt Macy ;; 92*eda14cbcSMatt Macy 93*eda14cbcSMatt Macychangequote(,)dnl 94*eda14cbcSMatt Macy alphaev[4-8] | alphaev56 | alphapca5[67] | alphaev6[78] ) 95*eda14cbcSMatt Macychangequote([,])dnl 96*eda14cbcSMatt Macy gl_cv_host_cpu_c_abi=alpha 97*eda14cbcSMatt Macy ;; 98*eda14cbcSMatt Macy 99*eda14cbcSMatt Macy arm* | aarch64 ) 100*eda14cbcSMatt Macy # Assume arm with EABI. 101*eda14cbcSMatt Macy # On arm64 systems, the C compiler may be generating code in one of 102*eda14cbcSMatt Macy # these ABIs: 103*eda14cbcSMatt Macy # - aarch64 instruction set, 64-bit pointers, 64-bit 'long': arm64. 104*eda14cbcSMatt Macy # - aarch64 instruction set, 32-bit pointers, 32-bit 'long': arm64-ilp32. 105*eda14cbcSMatt Macy # - 32-bit instruction set, 32-bit pointers, 32-bit 'long': arm or armhf. 106*eda14cbcSMatt Macy AC_COMPILE_IFELSE( 107*eda14cbcSMatt Macy [AC_LANG_SOURCE( 108*eda14cbcSMatt Macy [[#ifdef __aarch64__ 109*eda14cbcSMatt Macy int ok; 110*eda14cbcSMatt Macy #else 111*eda14cbcSMatt Macy error fail 112*eda14cbcSMatt Macy #endif 113*eda14cbcSMatt Macy ]])], 114*eda14cbcSMatt Macy [AC_COMPILE_IFELSE( 115*eda14cbcSMatt Macy [AC_LANG_SOURCE( 116*eda14cbcSMatt Macy [[#if defined __ILP32__ || defined _ILP32 117*eda14cbcSMatt Macy int ok; 118*eda14cbcSMatt Macy #else 119*eda14cbcSMatt Macy error fail 120*eda14cbcSMatt Macy #endif 121*eda14cbcSMatt Macy ]])], 122*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi=arm64-ilp32], 123*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi=arm64])], 124*eda14cbcSMatt Macy [# Don't distinguish little-endian and big-endian arm, since they 125*eda14cbcSMatt Macy # don't require different machine code for simple operations and 126*eda14cbcSMatt Macy # since the user can distinguish them through the preprocessor 127*eda14cbcSMatt Macy # defines __ARMEL__ vs. __ARMEB__. 128*eda14cbcSMatt Macy # But distinguish arm which passes floating-point arguments and 129*eda14cbcSMatt Macy # return values in integer registers (r0, r1, ...) - this is 130*eda14cbcSMatt Macy # gcc -mfloat-abi=soft or gcc -mfloat-abi=softfp - from arm which 131*eda14cbcSMatt Macy # passes them in float registers (s0, s1, ...) and double registers 132*eda14cbcSMatt Macy # (d0, d1, ...) - this is gcc -mfloat-abi=hard. GCC 4.6 or newer 133*eda14cbcSMatt Macy # sets the preprocessor defines __ARM_PCS (for the first case) and 134*eda14cbcSMatt Macy # __ARM_PCS_VFP (for the second case), but older GCC does not. 135*eda14cbcSMatt Macy echo 'double ddd; void func (double dd) { ddd = dd; }' > conftest.c 136*eda14cbcSMatt Macy # Look for a reference to the register d0 in the .s file. 137*eda14cbcSMatt Macy AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS $gl_c_asm_opt conftest.c) >/dev/null 2>&1 138*eda14cbcSMatt Macy if LC_ALL=C grep 'd0,' conftest.$gl_asmext >/dev/null; then 139*eda14cbcSMatt Macy gl_cv_host_cpu_c_abi=armhf 140*eda14cbcSMatt Macy else 141*eda14cbcSMatt Macy gl_cv_host_cpu_c_abi=arm 142*eda14cbcSMatt Macy fi 143*eda14cbcSMatt Macy rm -f conftest* 144*eda14cbcSMatt Macy ]) 145*eda14cbcSMatt Macy ;; 146*eda14cbcSMatt Macy 147*eda14cbcSMatt Macy hppa1.0 | hppa1.1 | hppa2.0* | hppa64 ) 148*eda14cbcSMatt Macy # On hppa, the C compiler may be generating 32-bit code or 64-bit 149*eda14cbcSMatt Macy # code. In the latter case, it defines _LP64 and __LP64__. 150*eda14cbcSMatt Macy AC_COMPILE_IFELSE( 151*eda14cbcSMatt Macy [AC_LANG_SOURCE( 152*eda14cbcSMatt Macy [[#ifdef __LP64__ 153*eda14cbcSMatt Macy int ok; 154*eda14cbcSMatt Macy #else 155*eda14cbcSMatt Macy error fail 156*eda14cbcSMatt Macy #endif 157*eda14cbcSMatt Macy ]])], 158*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi=hppa64], 159*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi=hppa]) 160*eda14cbcSMatt Macy ;; 161*eda14cbcSMatt Macy 162*eda14cbcSMatt Macy ia64* ) 163*eda14cbcSMatt Macy # On ia64 on HP-UX, the C compiler may be generating 64-bit code or 164*eda14cbcSMatt Macy # 32-bit code. In the latter case, it defines _ILP32. 165*eda14cbcSMatt Macy AC_COMPILE_IFELSE( 166*eda14cbcSMatt Macy [AC_LANG_SOURCE( 167*eda14cbcSMatt Macy [[#ifdef _ILP32 168*eda14cbcSMatt Macy int ok; 169*eda14cbcSMatt Macy #else 170*eda14cbcSMatt Macy error fail 171*eda14cbcSMatt Macy #endif 172*eda14cbcSMatt Macy ]])], 173*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi=ia64-ilp32], 174*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi=ia64]) 175*eda14cbcSMatt Macy ;; 176*eda14cbcSMatt Macy 177*eda14cbcSMatt Macy mips* ) 178*eda14cbcSMatt Macy # We should also check for (_MIPS_SZPTR == 64), but gcc keeps this 179*eda14cbcSMatt Macy # at 32. 180*eda14cbcSMatt Macy AC_COMPILE_IFELSE( 181*eda14cbcSMatt Macy [AC_LANG_SOURCE( 182*eda14cbcSMatt Macy [[#if defined _MIPS_SZLONG && (_MIPS_SZLONG == 64) 183*eda14cbcSMatt Macy int ok; 184*eda14cbcSMatt Macy #else 185*eda14cbcSMatt Macy error fail 186*eda14cbcSMatt Macy #endif 187*eda14cbcSMatt Macy ]])], 188*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi=mips64], 189*eda14cbcSMatt Macy [# In the n32 ABI, _ABIN32 is defined, _ABIO32 is not defined (but 190*eda14cbcSMatt Macy # may later get defined by <sgidefs.h>), and _MIPS_SIM == _ABIN32. 191*eda14cbcSMatt Macy # In the 32 ABI, _ABIO32 is defined, _ABIN32 is not defined (but 192*eda14cbcSMatt Macy # may later get defined by <sgidefs.h>), and _MIPS_SIM == _ABIO32. 193*eda14cbcSMatt Macy AC_COMPILE_IFELSE( 194*eda14cbcSMatt Macy [AC_LANG_SOURCE( 195*eda14cbcSMatt Macy [[#if (_MIPS_SIM == _ABIN32) 196*eda14cbcSMatt Macy int ok; 197*eda14cbcSMatt Macy #else 198*eda14cbcSMatt Macy error fail 199*eda14cbcSMatt Macy #endif 200*eda14cbcSMatt Macy ]])], 201*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi=mipsn32], 202*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi=mips])]) 203*eda14cbcSMatt Macy ;; 204*eda14cbcSMatt Macy 205*eda14cbcSMatt Macy powerpc* ) 206*eda14cbcSMatt Macy # Different ABIs are in use on AIX vs. Mac OS X vs. Linux,*BSD. 207*eda14cbcSMatt Macy # No need to distinguish them here; the caller may distinguish 208*eda14cbcSMatt Macy # them based on the OS. 209*eda14cbcSMatt Macy # On powerpc64 systems, the C compiler may still be generating 210*eda14cbcSMatt Macy # 32-bit code. And on powerpc-ibm-aix systems, the C compiler may 211*eda14cbcSMatt Macy # be generating 64-bit code. 212*eda14cbcSMatt Macy AC_COMPILE_IFELSE( 213*eda14cbcSMatt Macy [AC_LANG_SOURCE( 214*eda14cbcSMatt Macy [[#if defined __powerpc64__ || defined _ARCH_PPC64 215*eda14cbcSMatt Macy int ok; 216*eda14cbcSMatt Macy #else 217*eda14cbcSMatt Macy error fail 218*eda14cbcSMatt Macy #endif 219*eda14cbcSMatt Macy ]])], 220*eda14cbcSMatt Macy [# On powerpc64, there are two ABIs on Linux: The AIX compatible 221*eda14cbcSMatt Macy # one and the ELFv2 one. The latter defines _CALL_ELF=2. 222*eda14cbcSMatt Macy AC_COMPILE_IFELSE( 223*eda14cbcSMatt Macy [AC_LANG_SOURCE( 224*eda14cbcSMatt Macy [[#if defined _CALL_ELF && _CALL_ELF == 2 225*eda14cbcSMatt Macy int ok; 226*eda14cbcSMatt Macy #else 227*eda14cbcSMatt Macy error fail 228*eda14cbcSMatt Macy #endif 229*eda14cbcSMatt Macy ]])], 230*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi=powerpc64-elfv2], 231*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi=powerpc64]) 232*eda14cbcSMatt Macy ], 233*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi=powerpc]) 234*eda14cbcSMatt Macy ;; 235*eda14cbcSMatt Macy 236*eda14cbcSMatt Macy rs6000 ) 237*eda14cbcSMatt Macy gl_cv_host_cpu_c_abi=powerpc 238*eda14cbcSMatt Macy ;; 239*eda14cbcSMatt Macy 240*eda14cbcSMatt Macy riscv32 | riscv64 ) 241*eda14cbcSMatt Macy # There are 2 architectures (with variants): rv32* and rv64*. 242*eda14cbcSMatt Macy AC_COMPILE_IFELSE( 243*eda14cbcSMatt Macy [AC_LANG_SOURCE( 244*eda14cbcSMatt Macy [[#if __riscv_xlen == 64 245*eda14cbcSMatt Macy int ok; 246*eda14cbcSMatt Macy #else 247*eda14cbcSMatt Macy error fail 248*eda14cbcSMatt Macy #endif 249*eda14cbcSMatt Macy ]])], 250*eda14cbcSMatt Macy [cpu=riscv64], 251*eda14cbcSMatt Macy [cpu=riscv32]) 252*eda14cbcSMatt Macy # There are 6 ABIs: ilp32, ilp32f, ilp32d, lp64, lp64f, lp64d. 253*eda14cbcSMatt Macy # Size of 'long' and 'void *': 254*eda14cbcSMatt Macy AC_COMPILE_IFELSE( 255*eda14cbcSMatt Macy [AC_LANG_SOURCE( 256*eda14cbcSMatt Macy [[#if defined __LP64__ 257*eda14cbcSMatt Macy int ok; 258*eda14cbcSMatt Macy #else 259*eda14cbcSMatt Macy error fail 260*eda14cbcSMatt Macy #endif 261*eda14cbcSMatt Macy ]])], 262*eda14cbcSMatt Macy [main_abi=lp64], 263*eda14cbcSMatt Macy [main_abi=ilp32]) 264*eda14cbcSMatt Macy # Float ABIs: 265*eda14cbcSMatt Macy # __riscv_float_abi_double: 266*eda14cbcSMatt Macy # 'float' and 'double' are passed in floating-point registers. 267*eda14cbcSMatt Macy # __riscv_float_abi_single: 268*eda14cbcSMatt Macy # 'float' are passed in floating-point registers. 269*eda14cbcSMatt Macy # __riscv_float_abi_soft: 270*eda14cbcSMatt Macy # No values are passed in floating-point registers. 271*eda14cbcSMatt Macy AC_COMPILE_IFELSE( 272*eda14cbcSMatt Macy [AC_LANG_SOURCE( 273*eda14cbcSMatt Macy [[#if defined __riscv_float_abi_double 274*eda14cbcSMatt Macy int ok; 275*eda14cbcSMatt Macy #else 276*eda14cbcSMatt Macy error fail 277*eda14cbcSMatt Macy #endif 278*eda14cbcSMatt Macy ]])], 279*eda14cbcSMatt Macy [float_abi=d], 280*eda14cbcSMatt Macy [AC_COMPILE_IFELSE( 281*eda14cbcSMatt Macy [AC_LANG_SOURCE( 282*eda14cbcSMatt Macy [[#if defined __riscv_float_abi_single 283*eda14cbcSMatt Macy int ok; 284*eda14cbcSMatt Macy #else 285*eda14cbcSMatt Macy error fail 286*eda14cbcSMatt Macy #endif 287*eda14cbcSMatt Macy ]])], 288*eda14cbcSMatt Macy [float_abi=f], 289*eda14cbcSMatt Macy [float_abi='']) 290*eda14cbcSMatt Macy ]) 291*eda14cbcSMatt Macy gl_cv_host_cpu_c_abi="${cpu}-${main_abi}${float_abi}" 292*eda14cbcSMatt Macy ;; 293*eda14cbcSMatt Macy 294*eda14cbcSMatt Macy s390* ) 295*eda14cbcSMatt Macy # On s390x, the C compiler may be generating 64-bit (= s390x) code 296*eda14cbcSMatt Macy # or 31-bit (= s390) code. 297*eda14cbcSMatt Macy AC_COMPILE_IFELSE( 298*eda14cbcSMatt Macy [AC_LANG_SOURCE( 299*eda14cbcSMatt Macy [[#if defined __LP64__ || defined __s390x__ 300*eda14cbcSMatt Macy int ok; 301*eda14cbcSMatt Macy #else 302*eda14cbcSMatt Macy error fail 303*eda14cbcSMatt Macy #endif 304*eda14cbcSMatt Macy ]])], 305*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi=s390x], 306*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi=s390]) 307*eda14cbcSMatt Macy ;; 308*eda14cbcSMatt Macy 309*eda14cbcSMatt Macy sparc | sparc64 ) 310*eda14cbcSMatt Macy # UltraSPARCs running Linux have `uname -m` = "sparc64", but the 311*eda14cbcSMatt Macy # C compiler still generates 32-bit code. 312*eda14cbcSMatt Macy AC_COMPILE_IFELSE( 313*eda14cbcSMatt Macy [AC_LANG_SOURCE( 314*eda14cbcSMatt Macy [[#if defined __sparcv9 || defined __arch64__ 315*eda14cbcSMatt Macy int ok; 316*eda14cbcSMatt Macy #else 317*eda14cbcSMatt Macy error fail 318*eda14cbcSMatt Macy #endif 319*eda14cbcSMatt Macy ]])], 320*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi=sparc64], 321*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi=sparc]) 322*eda14cbcSMatt Macy ;; 323*eda14cbcSMatt Macy 324*eda14cbcSMatt Macy *) 325*eda14cbcSMatt Macy gl_cv_host_cpu_c_abi="$host_cpu" 326*eda14cbcSMatt Macy ;; 327*eda14cbcSMatt Macy esac 328*eda14cbcSMatt Macy ]) 329*eda14cbcSMatt Macy 330*eda14cbcSMatt Macy dnl In most cases, $HOST_CPU and $HOST_CPU_C_ABI are the same. 331*eda14cbcSMatt Macy HOST_CPU=`echo "$gl_cv_host_cpu_c_abi" | sed -e 's/-.*//'` 332*eda14cbcSMatt Macy HOST_CPU_C_ABI="$gl_cv_host_cpu_c_abi" 333*eda14cbcSMatt Macy AC_SUBST([HOST_CPU]) 334*eda14cbcSMatt Macy AC_SUBST([HOST_CPU_C_ABI]) 335*eda14cbcSMatt Macy 336*eda14cbcSMatt Macy # This was 337*eda14cbcSMatt Macy # AC_DEFINE_UNQUOTED([__${HOST_CPU}__]) 338*eda14cbcSMatt Macy # AC_DEFINE_UNQUOTED([__${HOST_CPU_C_ABI}__]) 339*eda14cbcSMatt Macy # earlier, but KAI C++ 3.2d doesn't like this. 340*eda14cbcSMatt Macy sed -e 's/-/_/g' >> confdefs.h <<EOF 341*eda14cbcSMatt Macy#ifndef __${HOST_CPU}__ 342*eda14cbcSMatt Macy#define __${HOST_CPU}__ 1 343*eda14cbcSMatt Macy#endif 344*eda14cbcSMatt Macy#ifndef __${HOST_CPU_C_ABI}__ 345*eda14cbcSMatt Macy#define __${HOST_CPU_C_ABI}__ 1 346*eda14cbcSMatt Macy#endif 347*eda14cbcSMatt MacyEOF 348*eda14cbcSMatt Macy AH_TOP([/* CPU and C ABI indicator */ 349*eda14cbcSMatt Macy#ifndef __i386__ 350*eda14cbcSMatt Macy#undef __i386__ 351*eda14cbcSMatt Macy#endif 352*eda14cbcSMatt Macy#ifndef __x86_64_x32__ 353*eda14cbcSMatt Macy#undef __x86_64_x32__ 354*eda14cbcSMatt Macy#endif 355*eda14cbcSMatt Macy#ifndef __x86_64__ 356*eda14cbcSMatt Macy#undef __x86_64__ 357*eda14cbcSMatt Macy#endif 358*eda14cbcSMatt Macy#ifndef __alpha__ 359*eda14cbcSMatt Macy#undef __alpha__ 360*eda14cbcSMatt Macy#endif 361*eda14cbcSMatt Macy#ifndef __arm__ 362*eda14cbcSMatt Macy#undef __arm__ 363*eda14cbcSMatt Macy#endif 364*eda14cbcSMatt Macy#ifndef __armhf__ 365*eda14cbcSMatt Macy#undef __armhf__ 366*eda14cbcSMatt Macy#endif 367*eda14cbcSMatt Macy#ifndef __arm64_ilp32__ 368*eda14cbcSMatt Macy#undef __arm64_ilp32__ 369*eda14cbcSMatt Macy#endif 370*eda14cbcSMatt Macy#ifndef __arm64__ 371*eda14cbcSMatt Macy#undef __arm64__ 372*eda14cbcSMatt Macy#endif 373*eda14cbcSMatt Macy#ifndef __hppa__ 374*eda14cbcSMatt Macy#undef __hppa__ 375*eda14cbcSMatt Macy#endif 376*eda14cbcSMatt Macy#ifndef __hppa64__ 377*eda14cbcSMatt Macy#undef __hppa64__ 378*eda14cbcSMatt Macy#endif 379*eda14cbcSMatt Macy#ifndef __ia64_ilp32__ 380*eda14cbcSMatt Macy#undef __ia64_ilp32__ 381*eda14cbcSMatt Macy#endif 382*eda14cbcSMatt Macy#ifndef __ia64__ 383*eda14cbcSMatt Macy#undef __ia64__ 384*eda14cbcSMatt Macy#endif 385*eda14cbcSMatt Macy#ifndef __m68k__ 386*eda14cbcSMatt Macy#undef __m68k__ 387*eda14cbcSMatt Macy#endif 388*eda14cbcSMatt Macy#ifndef __mips__ 389*eda14cbcSMatt Macy#undef __mips__ 390*eda14cbcSMatt Macy#endif 391*eda14cbcSMatt Macy#ifndef __mipsn32__ 392*eda14cbcSMatt Macy#undef __mipsn32__ 393*eda14cbcSMatt Macy#endif 394*eda14cbcSMatt Macy#ifndef __mips64__ 395*eda14cbcSMatt Macy#undef __mips64__ 396*eda14cbcSMatt Macy#endif 397*eda14cbcSMatt Macy#ifndef __powerpc__ 398*eda14cbcSMatt Macy#undef __powerpc__ 399*eda14cbcSMatt Macy#endif 400*eda14cbcSMatt Macy#ifndef __powerpc64__ 401*eda14cbcSMatt Macy#undef __powerpc64__ 402*eda14cbcSMatt Macy#endif 403*eda14cbcSMatt Macy#ifndef __powerpc64_elfv2__ 404*eda14cbcSMatt Macy#undef __powerpc64_elfv2__ 405*eda14cbcSMatt Macy#endif 406*eda14cbcSMatt Macy#ifndef __riscv32__ 407*eda14cbcSMatt Macy#undef __riscv32__ 408*eda14cbcSMatt Macy#endif 409*eda14cbcSMatt Macy#ifndef __riscv64__ 410*eda14cbcSMatt Macy#undef __riscv64__ 411*eda14cbcSMatt Macy#endif 412*eda14cbcSMatt Macy#ifndef __riscv32_ilp32__ 413*eda14cbcSMatt Macy#undef __riscv32_ilp32__ 414*eda14cbcSMatt Macy#endif 415*eda14cbcSMatt Macy#ifndef __riscv32_ilp32f__ 416*eda14cbcSMatt Macy#undef __riscv32_ilp32f__ 417*eda14cbcSMatt Macy#endif 418*eda14cbcSMatt Macy#ifndef __riscv32_ilp32d__ 419*eda14cbcSMatt Macy#undef __riscv32_ilp32d__ 420*eda14cbcSMatt Macy#endif 421*eda14cbcSMatt Macy#ifndef __riscv64_ilp32__ 422*eda14cbcSMatt Macy#undef __riscv64_ilp32__ 423*eda14cbcSMatt Macy#endif 424*eda14cbcSMatt Macy#ifndef __riscv64_ilp32f__ 425*eda14cbcSMatt Macy#undef __riscv64_ilp32f__ 426*eda14cbcSMatt Macy#endif 427*eda14cbcSMatt Macy#ifndef __riscv64_ilp32d__ 428*eda14cbcSMatt Macy#undef __riscv64_ilp32d__ 429*eda14cbcSMatt Macy#endif 430*eda14cbcSMatt Macy#ifndef __riscv64_lp64__ 431*eda14cbcSMatt Macy#undef __riscv64_lp64__ 432*eda14cbcSMatt Macy#endif 433*eda14cbcSMatt Macy#ifndef __riscv64_lp64f__ 434*eda14cbcSMatt Macy#undef __riscv64_lp64f__ 435*eda14cbcSMatt Macy#endif 436*eda14cbcSMatt Macy#ifndef __riscv64_lp64d__ 437*eda14cbcSMatt Macy#undef __riscv64_lp64d__ 438*eda14cbcSMatt Macy#endif 439*eda14cbcSMatt Macy#ifndef __s390__ 440*eda14cbcSMatt Macy#undef __s390__ 441*eda14cbcSMatt Macy#endif 442*eda14cbcSMatt Macy#ifndef __s390x__ 443*eda14cbcSMatt Macy#undef __s390x__ 444*eda14cbcSMatt Macy#endif 445*eda14cbcSMatt Macy#ifndef __sh__ 446*eda14cbcSMatt Macy#undef __sh__ 447*eda14cbcSMatt Macy#endif 448*eda14cbcSMatt Macy#ifndef __sparc__ 449*eda14cbcSMatt Macy#undef __sparc__ 450*eda14cbcSMatt Macy#endif 451*eda14cbcSMatt Macy#ifndef __sparc64__ 452*eda14cbcSMatt Macy#undef __sparc64__ 453*eda14cbcSMatt Macy#endif 454*eda14cbcSMatt Macy]) 455*eda14cbcSMatt Macy 456*eda14cbcSMatt Macy]) 457*eda14cbcSMatt Macy 458*eda14cbcSMatt Macy 459*eda14cbcSMatt Macydnl Sets the HOST_CPU_C_ABI_32BIT variable to 'yes' if the C language ABI 460*eda14cbcSMatt Macydnl (application binary interface) is a 32-bit one, or to 'no' otherwise. 461*eda14cbcSMatt Macydnl This is a simplified variant of gl_HOST_CPU_C_ABI. 462*eda14cbcSMatt MacyAC_DEFUN([gl_HOST_CPU_C_ABI_32BIT], 463*eda14cbcSMatt Macy[ 464*eda14cbcSMatt Macy AC_REQUIRE([AC_CANONICAL_HOST]) 465*eda14cbcSMatt Macy AC_CACHE_CHECK([32-bit host C ABI], [gl_cv_host_cpu_c_abi_32bit], 466*eda14cbcSMatt Macy [if test -n "$gl_cv_host_cpu_c_abi"; then 467*eda14cbcSMatt Macy case "$gl_cv_host_cpu_c_abi" in 468*eda14cbcSMatt Macy i386 | x86_64-x32 | arm | armhf | arm64-ilp32 | hppa | ia64-ilp32 | mips | mipsn32 | powerpc | riscv*-ilp32* | s390 | sparc) 469*eda14cbcSMatt Macy gl_cv_host_cpu_c_abi_32bit=yes ;; 470*eda14cbcSMatt Macy *) 471*eda14cbcSMatt Macy gl_cv_host_cpu_c_abi_32bit=no ;; 472*eda14cbcSMatt Macy esac 473*eda14cbcSMatt Macy else 474*eda14cbcSMatt Macy case "$host_cpu" in 475*eda14cbcSMatt Macy 476*eda14cbcSMatt Macychangequote(,)dnl 477*eda14cbcSMatt Macy i[4567]86 ) 478*eda14cbcSMatt Macychangequote([,])dnl 479*eda14cbcSMatt Macy gl_cv_host_cpu_c_abi_32bit=yes 480*eda14cbcSMatt Macy ;; 481*eda14cbcSMatt Macy 482*eda14cbcSMatt Macy x86_64 ) 483*eda14cbcSMatt Macy # On x86_64 systems, the C compiler may be generating code in one of 484*eda14cbcSMatt Macy # these ABIs: 485*eda14cbcSMatt Macy # - 64-bit instruction set, 64-bit pointers, 64-bit 'long': x86_64. 486*eda14cbcSMatt Macy # - 64-bit instruction set, 64-bit pointers, 32-bit 'long': x86_64 487*eda14cbcSMatt Macy # with native Windows (mingw, MSVC). 488*eda14cbcSMatt Macy # - 64-bit instruction set, 32-bit pointers, 32-bit 'long': x86_64-x32. 489*eda14cbcSMatt Macy # - 32-bit instruction set, 32-bit pointers, 32-bit 'long': i386. 490*eda14cbcSMatt Macy AC_COMPILE_IFELSE( 491*eda14cbcSMatt Macy [AC_LANG_SOURCE( 492*eda14cbcSMatt Macy [[#if (defined __x86_64__ || defined __amd64__ \ 493*eda14cbcSMatt Macy || defined _M_X64 || defined _M_AMD64) \ 494*eda14cbcSMatt Macy && !(defined __ILP32__ || defined _ILP32) 495*eda14cbcSMatt Macy int ok; 496*eda14cbcSMatt Macy #else 497*eda14cbcSMatt Macy error fail 498*eda14cbcSMatt Macy #endif 499*eda14cbcSMatt Macy ]])], 500*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi_32bit=no], 501*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi_32bit=yes]) 502*eda14cbcSMatt Macy ;; 503*eda14cbcSMatt Macy 504*eda14cbcSMatt Macy arm* | aarch64 ) 505*eda14cbcSMatt Macy # Assume arm with EABI. 506*eda14cbcSMatt Macy # On arm64 systems, the C compiler may be generating code in one of 507*eda14cbcSMatt Macy # these ABIs: 508*eda14cbcSMatt Macy # - aarch64 instruction set, 64-bit pointers, 64-bit 'long': arm64. 509*eda14cbcSMatt Macy # - aarch64 instruction set, 32-bit pointers, 32-bit 'long': arm64-ilp32. 510*eda14cbcSMatt Macy # - 32-bit instruction set, 32-bit pointers, 32-bit 'long': arm or armhf. 511*eda14cbcSMatt Macy AC_COMPILE_IFELSE( 512*eda14cbcSMatt Macy [AC_LANG_SOURCE( 513*eda14cbcSMatt Macy [[#if defined __aarch64__ && !(defined __ILP32__ || defined _ILP32) 514*eda14cbcSMatt Macy int ok; 515*eda14cbcSMatt Macy #else 516*eda14cbcSMatt Macy error fail 517*eda14cbcSMatt Macy #endif 518*eda14cbcSMatt Macy ]])], 519*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi_32bit=no], 520*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi_32bit=yes]) 521*eda14cbcSMatt Macy ;; 522*eda14cbcSMatt Macy 523*eda14cbcSMatt Macy hppa1.0 | hppa1.1 | hppa2.0* | hppa64 ) 524*eda14cbcSMatt Macy # On hppa, the C compiler may be generating 32-bit code or 64-bit 525*eda14cbcSMatt Macy # code. In the latter case, it defines _LP64 and __LP64__. 526*eda14cbcSMatt Macy AC_COMPILE_IFELSE( 527*eda14cbcSMatt Macy [AC_LANG_SOURCE( 528*eda14cbcSMatt Macy [[#ifdef __LP64__ 529*eda14cbcSMatt Macy int ok; 530*eda14cbcSMatt Macy #else 531*eda14cbcSMatt Macy error fail 532*eda14cbcSMatt Macy #endif 533*eda14cbcSMatt Macy ]])], 534*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi_32bit=no], 535*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi_32bit=yes]) 536*eda14cbcSMatt Macy ;; 537*eda14cbcSMatt Macy 538*eda14cbcSMatt Macy ia64* ) 539*eda14cbcSMatt Macy # On ia64 on HP-UX, the C compiler may be generating 64-bit code or 540*eda14cbcSMatt Macy # 32-bit code. In the latter case, it defines _ILP32. 541*eda14cbcSMatt Macy AC_COMPILE_IFELSE( 542*eda14cbcSMatt Macy [AC_LANG_SOURCE( 543*eda14cbcSMatt Macy [[#ifdef _ILP32 544*eda14cbcSMatt Macy int ok; 545*eda14cbcSMatt Macy #else 546*eda14cbcSMatt Macy error fail 547*eda14cbcSMatt Macy #endif 548*eda14cbcSMatt Macy ]])], 549*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi_32bit=yes], 550*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi_32bit=no]) 551*eda14cbcSMatt Macy ;; 552*eda14cbcSMatt Macy 553*eda14cbcSMatt Macy mips* ) 554*eda14cbcSMatt Macy # We should also check for (_MIPS_SZPTR == 64), but gcc keeps this 555*eda14cbcSMatt Macy # at 32. 556*eda14cbcSMatt Macy AC_COMPILE_IFELSE( 557*eda14cbcSMatt Macy [AC_LANG_SOURCE( 558*eda14cbcSMatt Macy [[#if defined _MIPS_SZLONG && (_MIPS_SZLONG == 64) 559*eda14cbcSMatt Macy int ok; 560*eda14cbcSMatt Macy #else 561*eda14cbcSMatt Macy error fail 562*eda14cbcSMatt Macy #endif 563*eda14cbcSMatt Macy ]])], 564*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi_32bit=no], 565*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi_32bit=yes]) 566*eda14cbcSMatt Macy ;; 567*eda14cbcSMatt Macy 568*eda14cbcSMatt Macy powerpc* ) 569*eda14cbcSMatt Macy # Different ABIs are in use on AIX vs. Mac OS X vs. Linux,*BSD. 570*eda14cbcSMatt Macy # No need to distinguish them here; the caller may distinguish 571*eda14cbcSMatt Macy # them based on the OS. 572*eda14cbcSMatt Macy # On powerpc64 systems, the C compiler may still be generating 573*eda14cbcSMatt Macy # 32-bit code. And on powerpc-ibm-aix systems, the C compiler may 574*eda14cbcSMatt Macy # be generating 64-bit code. 575*eda14cbcSMatt Macy AC_COMPILE_IFELSE( 576*eda14cbcSMatt Macy [AC_LANG_SOURCE( 577*eda14cbcSMatt Macy [[#if defined __powerpc64__ || defined _ARCH_PPC64 578*eda14cbcSMatt Macy int ok; 579*eda14cbcSMatt Macy #else 580*eda14cbcSMatt Macy error fail 581*eda14cbcSMatt Macy #endif 582*eda14cbcSMatt Macy ]])], 583*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi_32bit=no], 584*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi_32bit=yes]) 585*eda14cbcSMatt Macy ;; 586*eda14cbcSMatt Macy 587*eda14cbcSMatt Macy rs6000 ) 588*eda14cbcSMatt Macy gl_cv_host_cpu_c_abi_32bit=yes 589*eda14cbcSMatt Macy ;; 590*eda14cbcSMatt Macy 591*eda14cbcSMatt Macy riscv32 | riscv64 ) 592*eda14cbcSMatt Macy # There are 6 ABIs: ilp32, ilp32f, ilp32d, lp64, lp64f, lp64d. 593*eda14cbcSMatt Macy # Size of 'long' and 'void *': 594*eda14cbcSMatt Macy AC_COMPILE_IFELSE( 595*eda14cbcSMatt Macy [AC_LANG_SOURCE( 596*eda14cbcSMatt Macy [[#if defined __LP64__ 597*eda14cbcSMatt Macy int ok; 598*eda14cbcSMatt Macy #else 599*eda14cbcSMatt Macy error fail 600*eda14cbcSMatt Macy #endif 601*eda14cbcSMatt Macy ]])], 602*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi_32bit=no], 603*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi_32bit=yes]) 604*eda14cbcSMatt Macy ;; 605*eda14cbcSMatt Macy 606*eda14cbcSMatt Macy s390* ) 607*eda14cbcSMatt Macy # On s390x, the C compiler may be generating 64-bit (= s390x) code 608*eda14cbcSMatt Macy # or 31-bit (= s390) code. 609*eda14cbcSMatt Macy AC_COMPILE_IFELSE( 610*eda14cbcSMatt Macy [AC_LANG_SOURCE( 611*eda14cbcSMatt Macy [[#if defined __LP64__ || defined __s390x__ 612*eda14cbcSMatt Macy int ok; 613*eda14cbcSMatt Macy #else 614*eda14cbcSMatt Macy error fail 615*eda14cbcSMatt Macy #endif 616*eda14cbcSMatt Macy ]])], 617*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi_32bit=no], 618*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi_32bit=yes]) 619*eda14cbcSMatt Macy ;; 620*eda14cbcSMatt Macy 621*eda14cbcSMatt Macy sparc | sparc64 ) 622*eda14cbcSMatt Macy # UltraSPARCs running Linux have `uname -m` = "sparc64", but the 623*eda14cbcSMatt Macy # C compiler still generates 32-bit code. 624*eda14cbcSMatt Macy AC_COMPILE_IFELSE( 625*eda14cbcSMatt Macy [AC_LANG_SOURCE( 626*eda14cbcSMatt Macy [[#if defined __sparcv9 || defined __arch64__ 627*eda14cbcSMatt Macy int ok; 628*eda14cbcSMatt Macy #else 629*eda14cbcSMatt Macy error fail 630*eda14cbcSMatt Macy #endif 631*eda14cbcSMatt Macy ]])], 632*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi_32bit=no], 633*eda14cbcSMatt Macy [gl_cv_host_cpu_c_abi_32bit=yes]) 634*eda14cbcSMatt Macy ;; 635*eda14cbcSMatt Macy 636*eda14cbcSMatt Macy *) 637*eda14cbcSMatt Macy gl_cv_host_cpu_c_abi_32bit=no 638*eda14cbcSMatt Macy ;; 639*eda14cbcSMatt Macy esac 640*eda14cbcSMatt Macy fi 641*eda14cbcSMatt Macy ]) 642*eda14cbcSMatt Macy 643*eda14cbcSMatt Macy HOST_CPU_C_ABI_32BIT="$gl_cv_host_cpu_c_abi_32bit" 644*eda14cbcSMatt Macy]) 645