2
0

host-cpu-c-abi.m4 22 KB

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