[oe] [RFC] gcc patch to avoid host include when compiling gcc-cross

Frans Meulenbroeks fransmeulenbroeks at gmail.com
Sat Jul 10 06:47:24 UTC 2010


2010/7/9 Khem Raj <raj.khem at gmail.com>:
> On Fri, Jul 9, 2010 at 4:57 AM, Frans Meulenbroeks
> <fransmeulenbroeks at gmail.com> wrote:
>> Since the introduction of linux-libc-headers-native my gcc-cross fails
>> to build (unless I avoid building linux-libc-headers-native by telling
>> that it is ASSUME_PROVIDED).
>>
>> Reason is that linux-libc-headers-native installs the host
>> asm/unistd.h in sysroots/i686-linux/usr/include/asm/unistd.h
>> My architecture (nios2) has a different unistd.h.
>>
>> Now gcc-cross compiles libgcc.a and adds among others $(GMPINC) to the
>> include path.
>> However this is a host path pointing to sysroots/i686-linux/usr/include.
>> This causes gcc-cross for nios2 to pick up the wrong unistd.h (causing
>> compilation of libgcc to fail).
>>
>> libgcc does not need GMP (at least not to my knowledge) and having a
>> host include when compiling target code does not seem like a good idea
>> either.
>> In order to fix this I've made a small patch to Makefile.in
>> This one creates a new var TARGET_INCLUDES which contains all includes
>> minus GMPINC.
>> THen INCLUDES is defined to $(TARGET_INCLUDES) $(GMPINC.) (to get the
>> original includes back.
>> And lastly the build rule for libgcc.a is modified to use
>> $(TARGET_INCLUDES) instead of  $(INCLUDES)
>>
>> Below is the patch I made. This is not yet a formal patch submission.
>> Instead this posting is made for a few reasons
>> - to create awareness and explain the issue
>
> The approach is ok. however it has to be applied to other libraries too
> and also the crt so its not limited to libgcc only.

crtstuff.c also needed this
libgcc2 has its own set of CFLAGS and does not use $(INCLUDES)
test-protoize-simple: uses INCLUDES, but that looks to me as host code
(not fully sure though)
libgcov does only depend on libgcc but has no rule

and there is this line:
ALL_CPPFLAGS = $(INCLUDES) $(CPPFLAGS) $(X_CPPFLAGS) $(T_CPPFLAGS)
As far as I can see it, this one is for host too (but it is part of
the rule .c.o)

I think the following patch suffices:
Index: gcc-4.1.2/gcc/Makefile.in
===================================================================
--- gcc-4.1.2.orig/gcc/Makefile.in
+++ gcc-4.1.2/gcc/Makefile.in
@@ -548,7 +548,7 @@ LIBGCC2_INCLUDES =
 TARGET_LIBGCC2_CFLAGS =

 # Options to use when compiling crtbegin/end.
-CRTSTUFF_CFLAGS = -O2 $(GCC_CFLAGS) $(INCLUDES) $(MULTILIB_CFLAGS) -g0 \
+CRTSTUFF_CFLAGS = -O2 $(GCC_CFLAGS) $(TARGET_INCLUDES) $(MULTILIB_CFLAGS) -g0 \
   -finhibit-size-directive -fno-inline-functions -fno-exceptions \
   -fno-zero-initialized-in-bss -fno-unit-at-a-time \
   $(INHIBIT_LIBC_CFLAGS)
@@ -845,9 +845,13 @@ BUILD_VARRAY = build/varray.o
 # -I$(@D) and -I$(srcdir)/$(@D) cause the subdirectory of the file
 # currently being compiled, in both source trees, to be examined as well.
 # libintl.h will be found in ../intl if we are using the included libintl.
-INCLUDES = -I. -I$(@D) -I$(srcdir) -I$(srcdir)/$(@D) \
+#
+# TARGET_INCLUDES is added to avoid that GMPINC (which points to the host
+# include dir) is used for compiling libgcc.a
+TARGET_INCLUDES = -I. -I$(@D) -I$(srcdir) -I$(srcdir)/$(@D) \
 	   -I$(srcdir)/../include @INCINTL@ \
-	   $(CPPINC) $(GMPINC)
+	   $(CPPINC)
+INCLUDES = $(TARGET_INCLUDES) $(GMPINC)

 .c.o:
 	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $< $(OUTPUT_OPTION)
@@ -1379,7 +1383,7 @@ libgcc.a: $(LIBGCC_DEPS)
 	$(MAKE) \
 	  CFLAGS="$(CFLAGS) $(WARN_CFLAGS)" \
 	  CONFIG_H="$(TCONFIG_H)" TM_H="$(TM_H)" \
-	  INCLUDES="$(INCLUDES)" \
+	  INCLUDES="$(TARGET_INCLUDES)" \
 	  MAKEOVERRIDES= \
 	  -f libgcc.mk all


>
>> - to get some feedback on the patch
>> - if there are suggestion for improvements or for better solutions I'd
>> like to know
>> - and last but not least: assuming the patch is ok, how are we going
>> to get it in.
>> I've tested this for gcc 4.1.2 (but there are 20 other gcc versions around :-( )
>
> We need to patch all used gcc versions 4.5 and 4.4 and 4.3

Well I can see if the patch applies , but I don't think I'm able to
test all the versions (let alone for all architectures)

Frans
>
>>
>> Enjoy! Frans.
>>
>> Index: gcc-4.1.2/gcc/Makefile.in
>> ===================================================================
>> --- gcc-4.1.2.orig/gcc/Makefile.in
>> +++ gcc-4.1.2/gcc/Makefile.in
>> @@ -845,9 +845,13 @@ BUILD_VARRAY = build/varray.o
>>  # -I$(@D) and -I$(srcdir)/$(@D) cause the subdirectory of the file
>>  # currently being compiled, in both source trees, to be examined as well.
>>  # libintl.h will be found in ../intl if we are using the included libintl.
>> -INCLUDES = -I. -I$(@D) -I$(srcdir) -I$(srcdir)/$(@D) \
>> +#
>> +# TARGET_INCLUDES is added to avoid that GMPINC (which points to the host
>> +# include dir) is used for compiling libgcc.a
>> +TARGET_INCLUDES = -I. -I$(@D) -I$(srcdir) -I$(srcdir)/$(@D) \
>>           -I$(srcdir)/../include @INCINTL@ \
>> -          $(CPPINC) $(GMPINC)
>> +          $(CPPINC)
>> +INCLUDES = $(TARGET_INCLUDES) $(GMPINC)
>>
>>  .c.o:
>>        $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $< $(OUTPUT_OPTION)
>> @@ -1379,7 +1383,7 @@ libgcc.a: $(LIBGCC_DEPS)
>>        $(MAKE) \
>>          CFLAGS="$(CFLAGS) $(WARN_CFLAGS)" \
>>          CONFIG_H="$(TCONFIG_H)" TM_H="$(TM_H)" \
>> -         INCLUDES="$(INCLUDES)" \
>> +         INCLUDES="$(TARGET_INCLUDES)" \
>>          MAKEOVERRIDES= \
>>          -f libgcc.mk all
>>
>> _______________________________________________
>> Openembedded-devel mailing list
>> Openembedded-devel at lists.openembedded.org
>> http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-devel
>>
>
> _______________________________________________
> Openembedded-devel mailing list
> Openembedded-devel at lists.openembedded.org
> http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-devel
>




More information about the Openembedded-devel mailing list