https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82371
Bug ID: 82371
Summary: Cross-compiling GCC fails when build platform has
fread_unlocked but host platform doesn't
Product: gcc
Version: 5.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: bugs at rkjnsn dot net
Target Milestone: ---
Note: I encountered this on 5.4.0, but I took a quick peek at the trunk source
code and the error still seems to be present.
When attempting to cross-compile GCC for a host system that does not have
fread_unlocked on a build system that does, the build fails with the following
error:
gengtype-lex.o: In function `yy_get_next_buffer':
/path/to/gcc-build/gcc/../../gcc-5.4.0/gcc/gengtype-lex.c:2182: undefined
reference to `fread_unlocked'
The problem seems to stem from the fact that gcc/gengtype-lex.l needs to be
compiled for both the build and host platforms, but includes bconfig.h in both
cases. The include directives in gcc/gengtype-lex.l itself, however, are
properly guarded:
#ifdef HOST_GENERATOR_FILE
#include "config.h"
#define GENERATOR_FILE 1
#else
#include "bconfig.h"
#endif
After some digging I discovered that the problem appears to be in
gcc/Makefile.in:
# Generated source files for gengtype. Prepend inclusion of
# bconfig.h because AIX requires _LARGE_FILES to be defined before
# any system header is included.
gengtype-lex.c : gengtype-lex.l
-$(FLEX) $(FLEXFLAGS) -o$@ $< && { \
echo '#include "bconfig.h"' > [email protected]; \
cat $@ >> [email protected]; \
mv [email protected] $@; \
}
This causes the generated gcc/gengtype-lex.c to include bconfig.h regardless of
whether compiling for the build system or the host system, resulting in
HAVE_FREAD_UNLOCKED being defined when it shouldn't be (which leads to the
linker error).