Skip to content

Instantly share code, notes, and snippets.

@nh2
Created December 16, 2018 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nh2/b79f4c22d13ba45a497cc4b935cdfd75 to your computer and use it in GitHub Desktop.
Save nh2/b79f4c22d13ba45a497cc4b935cdfd75 to your computer and use it in GitHub Desktop.
How autoconf does some feature detection on cross compilation

Originally from #ghc on freenode, 2018-12-16:

Most of the checks seem to actually be no-ops for cross-compilation. E.g. checking for working strnlen is just hardcoded to "yes" on all targets but AIX (in similar other cases, it just prints "guessing yes").

For checking size of int *, it does a binary search as you say, and NOT invoke the compiled programs. It does it by generating a static array with known size, like arr[1 - 2 * (sizeof(int*) <= BINARY_SEARCH_VAR)], so that the static size is either [1] or [-1]. C compilers happen to complain about arrays of negative static size, so that's how it figures that out. See ac_fn_c_compute_int().

To see this, I use for compilation of GNU hello, the following added to configure.ac:

AC_CHECK_SIZEOF([int *])

and configure with:

CC=arm-linux-gnueabihf-gcc ./configure --build i686-pc-linux-gnu --host arm-linux-gnueabihf

and then look at config.log around checking size of int *, which shows some of the iterations of the binary search below.

Required packages for this ARM cross-compilation are on Ubuntu 16.04:

sudo apt-get install libc6-armel-cross libc6-dev-armel-cross binutils-arm-linux-gnueabi libncurses5-dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment