Search code examples
cgccautotoolsautoconf

autoconf ignoring CFLAGS?


I'm building a package (vice 3.4) that uses GNU autoconf. Running ./configure fails with the following message:

checking size of time_t... 0
configure: error: can not figure type of time_t
error: Bad exit status from /var/tmp/rpm-tmp.wIgnPw (%build)

Examining config.log, this appears to be failing due to the following error:

/usr/bin/ld: /tmp/ccMTSdtB.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: nonrepresentable section on output
collect2: error: ld returned 1 exit status

I tried resolving this by adding -fPIC to the CFLAGS environment variable:

CFLAGS=-fPIC ./configure

But while this is clearly being used during other stages of ./configure...

configure:3657: checking whether the C compiler works
configure:3679: gcc -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE=1 -fPIC  -Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld conftest.c  >&5

It doesn't seem to be used in the feature tests related to time_t:

configure:9684: checking for time_t in time.h
configure:9700: gcc -c -g -O3 -Wall -Wformat -Wformat-signedness -Wshadow -Wpointer-arith -Wstrict-prototypes -Wuninitialized -Wunreachable-code -Wno-unused-parameter -Werror=implicit-function-declaration -Wfatal-errors  conftest.c >&5
[...]
configure:9753: checking size of time_t
configure:9758: gcc -o conftest -g -O3 -Wall -Wformat -Wformat-signedness -Wshadow -Wpointer-arith -Wstrict-prototypes -Wuninitialized -Wunreachable-code -Wno-unused-parameter -Werror=implicit-function-declaration -Wfatal-errors  -Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld conftest.c  >&5

Looking at configure.ac, the above code is generated from:

if test $bu_cv_decl_time_t_time_h = yes; then
  AC_CHECK_SIZEOF([time_t],[],[#include <time.h>])
else
  AC_CHECK_SIZEOF([time_t],[],[#include <sys/types.h>])
fi

I've been able to work around the problem by redefining CC instead:

CC="gcc -fPIC" ./configure

This works, but it's ugly (what if something wants to call gcc without -fPIC?). Is there a reason that AC_CHECK_SIZEOF is ignoring CFLAGS?


Solution

  • It looks like the suspicion I expressed in comments is confirmed. The VICE configure program intentionally substitutes its own choice of CFLAGS for the user's specified ones when it performs some of its checks, including the ones related to time_t. Thus, this is not a question of Autoconf ignoring your flags, but rather of VICE doing so.

    I reiterate that I think it's a more significant issue that configuration doesn't work out of the box for you in the first place. I suggest raising that as an issue against the project. Although I don't like that VICE is so cavalier about ignoring the user's CFLAGS, that's a separate matter, and one that I suspect wouldn't get much traction with the devs.