[PATCH] gcc: Fix sysroot relative paths for MinGW

Tadek Kijkowski tkijkowski@gmail.com
Sat Oct 8 10:26:00 GMT 2016


Prevent paths relative to sysroot directory from being transformed to Windows form with MSYS prefix.

Second attempt:
Moved most changes to x-mingw32. Only thing added to Makefile.in are new variables to ease overriding in included file.
Disabled overriding standard lib and include paths (with /mingw/lib and /mingw/include) in mingw32.h when TARGET_SYSTEM_ROOT is defined.

Side notes:

I've tested the patch together with patches from github.com/Alexpux/MINGW-packages. One of those patches disables overriding NATIVE_SYSTEM_HEADER_DIR in config scripts, so it's complement to this patch.

Target s-selftest in gcc fails on MinGW:
/home/tadek/gcc/gcc-build-mingw32-sysroot/./gcc/xgcc -B/home/tadek/gcc/gcc-build-mingw32-sysroot/./gcc/ -xc -S -c /dev/null -fself-test
cc1.exe: fatal error: input file 'nul.s' is the same as output file
It's enough to specify any output file, like '-o self-test-result.s' to fix the issue. Specifying '-o /dev/null' works as well, but I'm not sure if it's safe on all systems. It's a topic for separate patch.

Manual at "https://gcc.gnu.org/install/configure.html" does mention that path specified with|--with-native-system-header-dir is located within sysroot, but it fails 
to mention that the same applies to ||--with-local-prefix. Changelog: 2016-10-08 Tadek Kijkowski 
<tkijkowski@gmail.com> * gcc/Makefile.in, gcc/config/i386/x-mingw32: |Fix sysroot relative paths for MinGW
	* gcc/config/i386/mingw32.h: Disable overriding default library and include paths when sysroot is defined

Index: gcc/Makefile.in
===================================================================
--- gcc/Makefile.in	(revision 240805)
+++ gcc/Makefile.in	(working copy)
@@ -680,6 +680,15 @@
  exeext = @host_exeext@
  build_exeext = @build_exeext@
  
+
+# This allows overriding include paths in host specific Makefile
+# (config/i386/x-mingw32 overrides those variables and local_includedir).
+gplusplus_includedir = $(gcc_gxx_include_dir)
+gplusplus_tool_includedir = $(gcc_gxx_include_dir)/$(target_noncanonical)
+gplusplus_backward_includedir = $(gcc_gxx_include_dir)/backward
+native_system_includedir = $(NATIVE_SYSTEM_HEADER_DIR)
+
+
  # Directory in which to put man pages.
  mandir = @mandir@
  man1dir = $(mandir)/man1
@@ -2757,14 +2766,14 @@
  PREPROCESSOR_DEFINES = \
    -DGCC_INCLUDE_DIR=\"$(libsubdir)/include\" \
    -DFIXED_INCLUDE_DIR=\"$(libsubdir)/include-fixed\" \
-  -DGPLUSPLUS_INCLUDE_DIR=\"$(gcc_gxx_include_dir)\" \
+  -DGPLUSPLUS_INCLUDE_DIR=\"$(gplusplus_includedir)\" \
    -DGPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT=$(gcc_gxx_include_dir_add_sysroot) \
-  -DGPLUSPLUS_TOOL_INCLUDE_DIR=\"$(gcc_gxx_include_dir)/$(target_noncanonical)\" \
-  -DGPLUSPLUS_BACKWARD_INCLUDE_DIR=\"$(gcc_gxx_include_dir)/backward\" \
+  -DGPLUSPLUS_TOOL_INCLUDE_DIR=\"$(gplusplus_tool_includedir)\" \
+  -DGPLUSPLUS_BACKWARD_INCLUDE_DIR=\"$(gplusplus_backward_includedir)\" \
    -DLOCAL_INCLUDE_DIR=\"$(local_includedir)\" \
    -DCROSS_INCLUDE_DIR=\"$(CROSS_SYSTEM_HEADER_DIR)\" \
    -DTOOL_INCLUDE_DIR=\"$(gcc_tooldir)/include\" \
-  -DNATIVE_SYSTEM_HEADER_DIR=\"$(NATIVE_SYSTEM_HEADER_DIR)\" \
+  -DNATIVE_SYSTEM_HEADER_DIR=\"$(native_system_includedir)\" \
    -DPREFIX=\"$(prefix)/\" \
    -DSTANDARD_EXEC_PREFIX=\"$(libdir)/gcc/\" \
    @TARGET_SYSTEM_ROOT_DEFINE@
Index: gcc/config/i386/mingw32.h
===================================================================
--- gcc/config/i386/mingw32.h	(revision 240805)
+++ gcc/config/i386/mingw32.h	(working copy)
@@ -157,6 +161,8 @@
      fvtable-verify=std:vtv_end.o%s} \
    crtend.o%s"
  
+#if !defined(TARGET_SYSTEM_ROOT)
+
  /* Override startfile prefix defaults.  */
  #ifndef STANDARD_STARTFILE_PREFIX_1
  #define STANDARD_STARTFILE_PREFIX_1 "/mingw/lib/"
@@ -170,6 +176,8 @@
  #undef NATIVE_SYSTEM_HEADER_DIR
  #define NATIVE_SYSTEM_HEADER_DIR "/mingw/include"
  
+#endif /* !defined(TARGET_SYSTEM_ROOT) */
+
  /* Output STRING, a string representing a filename, to FILE.
     We canonicalize it to be in Unix format (backslashes are replaced
     forward slashes.  */
Index: gcc/config/i386/x-mingw32
===================================================================
--- gcc/config/i386/x-mingw32	(revision 240805)
+++ gcc/config/i386/x-mingw32	(working copy)
@@ -16,11 +16,45 @@
  # along with GCC; see the file COPYING3.  If not see
  # <http://www.gnu.org/licenses/>.
  #
+
+# MSYS will zealously translate all paths to Windows form, so /usr/include becomes c:/msysX/usr/include.
+# This is undesirable when TARGET_SYSTEM_ROOT is specified, so this function converts /usr/include to //usr\include,
+# which will become /usr/include again when passed to gcc.
+
+# This function takes two parameters: first parameter is include directory path, second parameter tells
+# if the path is relative to TARGET_SYSTEM_ROOT.
+# If TARGET_SYSTEM_ROOT is not configured, or
+#   this function always expands to the unmodified first parameter
+# if TARGET_SYSTEM_ROOT is configured, but second parameter is not 1,
+#   this function again expands to the unmodified first parameter
+# otherwise,
+#  it expands to a shell expression which will transform the first parameter as described above.
+ifneq ($(TARGET_SYSTEM_ROOT),)
+sysroot_relative_path = $(if $(filter 1,$(2)),`echo "$(1)" | tr '/' '\\\\' | sed 's|^\\\\|//|'`,$(1))
+else
+sysroot_relative_path = $(1)
+endif
+
+ifneq ($(TARGET_SYSTEM_ROOT),)
  #
+# Make sure that relative the path is not converted to absolute DOS style path
+#
+local_includedir = $(call sysroot_relative_path,$(local_prefix)/include,1)
+else
+#
  # Make local_includedir relative to EXEC_PREFIX
  #
  local_includedir=$(libsubdir)/$(unlibsubdir)/..`echo $(exec_prefix) | sed -e 's|^$(prefix)||' -e 's|/[^/]*|/..|g'`/include
+endif
  
+#
+# Make sure that relative path are not converted to absolute DOS style paths
+#
+gplusplus_includedir = $(call sysroot_relative_path,$(gcc_gxx_include_dir),$(gcc_gxx_include_dir_add_sysroot))
+gplusplus_tool_includedir = $(call sysroot_relative_path,$(gcc_gxx_include_dir)/$(target_noncanonical),$(gcc_gxx_include_dir_add_sysroot))
+gplusplus_backward_includedir = $(call sysroot_relative_path,$(gcc_gxx_include_dir)/backward,$(gcc_gxx_include_dir_add_sysroot))
+native_system_includedir = $(call sysroot_relative_path,$(NATIVE_SYSTEM_HEADER_DIR),1)
+
  # On MinGW, we use "%IA64d" to print 64-bit integers, and the format-checking
  # code does not handle that, so we have to disable checking here.
  WERROR_FLAGS += -Wno-format



More information about the Gcc-patches mailing list