public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix fixincludes for canadian cross builds
@ 2017-02-06 18:44 Bernd Edlinger
  2017-02-18  1:07 ` Bruce Korb
  0 siblings, 1 reply; 16+ messages in thread
From: Bernd Edlinger @ 2017-02-06 18:44 UTC (permalink / raw)
  To: gcc-patches, Bruce Korb, Richard Biener

[-- Attachment #1: Type: text/plain, Size: 1168 bytes --]

Hi,

I noticed that there is a subtle problem with build!=host
configurations.

That is, the fixinclude machinery is using the path that would
work on the target system to find the headers that need to be
fixed, but the build machine can have different header files than
the target machine, even if th are at the same location.  This can 
theoretically cause a mis-compilation of the target libraries.

However the mkheaders script works on the target, and would fix it up,
but the target libraries are not rebuilt, and they may have used the
wrong fixed headers.

To fix this inconsistency I would like to introduce a new make
variable BUILD_SYSTEM_HEADER_DIR that is identical to SYSTEM_HEADER_DIR
if build==host and which is CROSS_SYSTEM_HEADER_DIR for canadian cross
configs.

Only mkheaders.conf uses SYSTEM_HEADER_DIR because it runs on the
host system, all other places should use BUILD_SYSTEM_HEADER_DIR.

I tested this change with different arm-linux-gnueabihf cross
compilers, and verified that mkheaders still works on the host system.

Bootstrapped and reg-tested on x86_64-pc-linux-gnu.
Is it OK for trunk?


Thanks
Bernd.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch-build-headers.diff --]
[-- Type: text/x-patch; name="patch-build-headers.diff", Size: 2930 bytes --]

2017-02-06  Bernd Edlinger  <bernd.edlinger@hotmail.de>

        * Makefile.in (BUILD_SYSTEM_HEADER_DIR): New make variabe.
	(LIMITS_H_TEST, if_multiarch, stmp-fixinc): Use BUILD_SYSTEM_HEADER_DIR
	instead of SYSTEM_HEADER_DIR.

Index: gcc/Makefile.in
===================================================================
--- gcc/Makefile.in	(revision 245184)
+++ gcc/Makefile.in	(working copy)
@@ -517,11 +517,18 @@
 # macro is also used in a double-quoted context.
 SYSTEM_HEADER_DIR = `echo @SYSTEM_HEADER_DIR@ | sed -e :a -e 's,[^/]*/\.\.\/,,' -e ta`
 
+# Path to the system headers on the build machine
+ifeq ($(build),$(host))
+BUILD_SYSTEM_HEADER_DIR = $(SYSTEM_HEADER_DIR)
+else
+BUILD_SYSTEM_HEADER_DIR = `echo $(CROSS_SYSTEM_HEADER_DIR) | sed -e :a -e 's,[^/]*/\.\.\/,,' -e ta`
+endif
+
 # Control whether to run fixincludes.
 STMP_FIXINC = @STMP_FIXINC@
 
 # Test to see whether <limits.h> exists in the system header files.
-LIMITS_H_TEST = [ -f $(SYSTEM_HEADER_DIR)/limits.h ]
+LIMITS_H_TEST = [ -f $(BUILD_SYSTEM_HEADER_DIR)/limits.h ]
 
 # Directory for prefix to system directories, for
 # each of $(system_prefix)/usr/include, $(system_prefix)/usr/lib, etc.
@@ -572,7 +579,7 @@
 else
   ifeq ($(enable_multiarch),auto)
     # SYSTEM_HEADER_DIR is makefile syntax, cannot be evaluated in configure.ac
-    if_multiarch = $(if $(wildcard $(shell echo $(SYSTEM_HEADER_DIR))/../../usr/lib/*/crti.o),$(1))
+    if_multiarch = $(if $(wildcard $(shell echo $(BUILD_SYSTEM_HEADER_DIR))/../../usr/lib/*/crti.o),$(1))
   else
     if_multiarch =
   endif
@@ -2990,11 +2997,11 @@
 	    sysroot_headers_suffix=`echo $${ml} | sed -e 's/;.*$$//'`; \
 	    multi_dir=`echo $${ml} | sed -e 's/^[^;]*;//'`; \
 	    fix_dir=include-fixed$${multi_dir}; \
-	    if ! $(inhibit_libc) && test ! -d ${SYSTEM_HEADER_DIR}; then \
+	    if ! $(inhibit_libc) && test ! -d ${BUILD_SYSTEM_HEADER_DIR}; then \
 	      echo The directory that should contain system headers does not exist: >&2 ; \
-	      echo "  ${SYSTEM_HEADER_DIR}" >&2 ; \
+	      echo "  ${BUILD_SYSTEM_HEADER_DIR}" >&2 ; \
 	      tooldir_sysinc=`echo "${gcc_tooldir}/sys-include" | sed -e :a -e "s,[^/]*/\.\.\/,," -e ta`; \
-	      if test "x${SYSTEM_HEADER_DIR}" = "x$${tooldir_sysinc}"; \
+	      if test "x${BUILD_SYSTEM_HEADER_DIR}" = "x$${tooldir_sysinc}"; \
 	      then sleep 1; else exit 1; fi; \
 	    fi; \
 	    $(mkinstalldirs) $${fix_dir}; \
@@ -3005,7 +3012,7 @@
 	      export TARGET_MACHINE srcdir SHELL MACRO_LIST && \
 	      cd $(build_objdir)/fixincludes && \
 	      $(SHELL) ./fixinc.sh "$${gcc_dir}/$${fix_dir}" \
-	        $(SYSTEM_HEADER_DIR) $(OTHER_FIXINCLUDES_DIRS) ); \
+	        $(BUILD_SYSTEM_HEADER_DIR) $(OTHER_FIXINCLUDES_DIRS) ); \
 	    rm -f $${fix_dir}/syslimits.h; \
 	    if [ -f $${fix_dir}/limits.h ]; then \
 	      mv $${fix_dir}/limits.h $${fix_dir}/syslimits.h; \

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2017-04-28 18:59 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-06 18:44 [PATCH] Fix fixincludes for canadian cross builds Bernd Edlinger
2017-02-18  1:07 ` Bruce Korb
2017-02-18 11:39   ` Bernd Edlinger
2017-02-20 18:18     ` Bruce Korb
2017-04-12 15:59       ` Yvan Roux
2017-04-12 16:22         ` Bruce Korb
2017-04-14  4:18         ` Bernd Edlinger
2017-04-14  8:24           ` Yvan Roux
2017-04-14 10:37             ` Bernd Edlinger
2017-04-14 11:20               ` Yvan Roux
2017-04-18 18:29               ` Bernd Edlinger
2017-04-19  7:56                 ` Yvan Roux
2017-04-20 20:29                   ` [PATCH] Fix fixincludes for canadian cross builds - next try Bernd Edlinger
2017-04-20 20:35                     ` Matthew Fortune
2017-04-21 10:41                     ` Yvan Roux
2017-04-28 19:13                     ` Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).