better default SYSTEM_HEADER_DIR when cross-compiling gcc

Mike Frysinger vapier@gentoo.org
Sun Apr 30 08:04:00 GMT 2006


when cross-compiling gcc (build != host && host == target), the default 
SYSTEM_HEADER_DIR is set to NATIVE_SYSTEM_HEADER_DIR which 
is /usr/include ... then when fixincludes runs, it pulls headers 
from /usr/include for use in generation of the compiler

for example, using a configure such as:
../configure --build=x86_64-pc-linux-gnu --host=mips64el-unknown-linux-gnu --enable-languages=c

will run fixincludes like so:
(TARGET_MACHINE='mips64el-unknown-linux-gnu'; srcdir=`cd ../../gcc; 
${PWDCMD-pwd}`; \
      SHELL='/bin/sh'; MACRO_LIST=`${PWDCMD-pwd}`/macro_list ; \
      export TARGET_MACHINE srcdir SHELL MACRO_LIST && \
      cd ../build-x86_64-pc-linux-gnu/fixincludes && \
      /bin/sh ./fixinc.sh ../../gcc/include \
        /usr/include  )
Fixing headers into /home/vapier/gcc-4.1.0/build/gcc/include for 
mips64el-unknown-linux-gnu target
No forbidden identifiers defined by this target
Finding directories and links to directories
 Searching /usr/include/.

depending on the headers in /usr/include, the issue may not even be noticed as 
most things are "generic" ... but on a multilib Gentoo system, 
the /usr/include headers from glibc are scrubbed such that any non-native 
arch that includes them will not have things properly defined ... so the gcc 
cross-compile ends in a failure such as:
mips64el-unknown-linux-gnu-gcc  -O2  -O2 -g -O2   -DIN_GCC    -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition  -isystem ./include  -fPIC -g -DHAVE_GTHR_DEFAULT -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED  -I. -I. -I../../gcc -I../../gcc/. -I../../gcc/../include -I../../gcc/../libcpp/include  -DL_eprintf -fvisibility=hidden -DHIDE_EXPORTS -c ../../gcc/libgcc2.c -o 
libgcc/./_eprintf.o
../../gcc/libgcc2.c: In function '__eprintf':
../../gcc/libgcc2.c:1799: warning: implicit declaration of function 'fprintf'
../../gcc/libgcc2.c:1799: warning: incompatible implicit declaration of 
built-in function 'fprintf'
../../gcc/libgcc2.c:1799: error: 'stderr' undeclared (first use in this 
function)
../../gcc/libgcc2.c:1799: error: (Each undeclared identifier is reported only 
once
../../gcc/libgcc2.c:1799: error: for each function it appears in.)
../../gcc/libgcc2.c:1800: warning: implicit declaration of function 'fflush'
make[3]: *** [libgcc/./_eprintf.o] Error 1

in this case, a vanilla stdio.h defines stderr properly without any 
arch-specific cruft ... but not on Gentoo because we do enjoy being so 
difficult ;).  so one way to reproduce this issue for a mips target would be 
to tweak the /usr/include/stdio.h with this:
#ifdef __mips__
# error oops
#endif
and watch it die

the attached patch changes the default SYSTEM_HEADER_DIR setting from 
NATIVE_SYSTEM_HEADER_DIR to CROSS_SYSTEM_HEADER_DIR when host != build
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcc-default-cross-headers.patch
Type: text/x-diff
Size: 474 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20060430/b3a10795/attachment.bin>


More information about the Gcc-patches mailing list