Passing AM_CFLAGS to CC_FOR_BUILD compiler leads to errors when cross-compiling
Vlad Zakharov
Vladislav.Zakharov@synopsys.com
Wed Aug 17 11:03:00 GMT 2016
binutils@sourceware.org
Hi all,
I faced with an issue when I was cross-compiling binutils: build failed at configure step with the following error:
---------------------------------->8------------------------------------
cc1: error: unrecognized command line option "-Wstack-usage=262144"
---------------------------------->8------------------------------------
When cross-compiling we have different compilers in CC and CC_FOR_BUILD variables,
as CC_FOR_BUILD is compiler for host when CC is compiler for target.
But Makefile uses AM_CFLAGS to compile with CC_FOR_BUILD compiler, e. g. lines from binutils/Makefile.am 310:
---------------------------------->8------------------------------------
sysinfo.@OBJEXT@: sysinfo.c
if [ -r sysinfo.c ]; then \
$(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(NO_WERROR) sysinfo.c ; \
else \
$(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(NO_WERROR) $(srcdir)/sysinfo.c ; \
fi
---------------------------------->8------------------------------------
AM_FLAGS are set up as WARN_CFLAGS + ZLIBINC, line from binutils/Makefile.am 51:
---------------------------------->8------------------------------------
AM_CFLAGS = $(WARN_CFLAGS) $(ZLIBINC)
---------------------------------->8------------------------------------
While configure script verifies only CC compiler (CPP in fact but it is set to "$CC -E") to be compatible with
GCC_WARN_FLAGS, e.g. verifying to be compatible with "-Wstack-usage" option (binutils/configure: 11965):
---------------------------------->8------------------------------------
# Add -Wstack-usage if the compiler is a sufficiently recent version of GCC.
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
__GNUC__
_ACEOF
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
$EGREP "^[0-4]$" >/dev/null 2>&1; then :
else
GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Wstack-usage=262144"
fi
---------------------------------->8------------------------------------
Where $ac_cpp is '$CPP $CPPFLAGS'.
This behavior leads to unobvious errors: host compiler may doesn't have support of some options that are passed to both
host and target compilers. That exactly happened to me - I tried to cross-compile binutils-gdb for ARC. GCC - 6 is now
used for ARC, so "-Wstack-usage" option was added to WARN_CLFAGS and then to AM_CFLAGS. But I have rather old compiler,
installed on my host and it doesn't support "-Wstack-usage". So the failure occurred and I wasn't able to cross-compile
binutils on my host.
Of course updating GCC to newer version solves the issue and you can say that we should use up-to-date GCC version but I
still think that all described above is a real issue and is needed to be solved.
While debugging the problem I also found that some work had been already done: CCFLAGS and LDFLAGS were replaced with
CCFLAGS_FOR_BUILD and LDFLAGS_FOR_BUILD by the commit:
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=791f39718a26c3fbedbd1f6a90956ecdfe03340a
But AM_CLFAGS remained intact.
So solutions could be either to have WARN_CFLAGS_FOR_BUILD or AM_CLFLAGS_FOR_BUILD variable with corresponding options
and verify CC_FOR_BUILD to be compatible with such options or just not to use AM_FLAGS with CC_FOR_BUILD compiler at all
as AM_FLAGS seems to be compatible only with CC compiler.
Any ideas or suggestions?
--
Best regards,
Vlad Zakharov <vzakhar@synopsys.com>
More information about the Binutils
mailing list