2024/12/20: Old configure scripts with new compilers

Bootstrapping is a way get a well-defined environment independent of the system you're starting from. When using bootstrapping for this purpose (and not doing bootstrapping as a way to establish trust in the running binaries), the starting point is usually "any C compiler from host" as that is something available almost everywhere.

The first thing you then build is gcc 4.7.4, the last gcc still written in C. In other words, you use a pretty recent C compiler to build a quite old one; in particular, you're running quite old configure scripts. In the configure script of its dependency gmp one of the tests is trying to find out how to link the math library. It is done by calling $CC_FOR_BUILD conftest.c -lm on the the file conftest.c with the following contents.


int
main ()
{
  exit(0);
}
double d;
double
foo ()
{
  return log (d);
}

Of course, this fails on sufficiently new compilers on some distros. Not because -lm would be the wrong way to link libm, nor because libm wouldn't provide the log function. No, it fails because the implicit declaration of log is nowadays considered an error by default (in some setups). But failure is failure and the configure script takes the wrong path with respect to libm which leads to a linker error later in the build. Of course, there is a flag to disable that compiler behaviour, but the test is run with just the compiler without CFLAGS, as the configure script earlier found out that just the compiler without flags is enough to compile the canonical "return 0;" program.

The solution hence was to use a wrapper script around the compiler (the diff is not well formatted, the actual insertion starts at new line 150) calling it with the desired flags and make that the CC to use.