PATCH: Correct path relocation logic

Mark Mitchell mark@codesourcery.com
Mon Mar 12 01:29:00 GMT 2007


This patch corrects the patch relocation performed in c-incpath.c.
The purpose of this logic is to adjust header file search paths when
the compiler installation is relocated.  However, this logic was only
checking for paths inside $prefix/lib/gcc, when, really, it should be
checking for paths inside $prefix.

Tested on x86_64-unknown-linux-gnu, with the usual tests, and by
looking at the output of -v for a relocated compiler.  Applied on the
mainline.

--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

2007-03-11  Mark Mitchell  <mark@codesourcery.com>

	* cppdefault.c (cpp_EXEC_PREFIX): New variable.
	* cppdefault.h (cpp_PREFIX): Document.
	(cpp_PREFIX_len): Likewise.
	(cpp_EXEC_PREFIX): New variable.
	* Makefile.in (PREPROCESSOR_DEFINES): Add STANDARD_EXEC_PREFIX.
	* c-incpath.c (add_standard_paths): Correct logic for relocating
	paths within prefix.

Index: cppdefault.c
===================================================================
--- cppdefault.c	(revision 122822)
+++ cppdefault.c	(working copy)
@@ -112,6 +112,7 @@ const size_t cpp_GCC_INCLUDE_DIR_len = 0
 /* The configured prefix.  */
 const char cpp_PREFIX[] = PREFIX;
 const size_t cpp_PREFIX_len = sizeof PREFIX - 1;
+const char cpp_EXEC_PREFIX[] = STANDARD_EXEC_PREFIX;
 
 /* This value is set by cpp_relocated at runtime */
 const char *gcc_exec_prefix;
Index: cppdefault.h
===================================================================
--- cppdefault.h	(revision 122822)
+++ cppdefault.h	(working copy)
@@ -52,8 +52,16 @@ extern const struct default_include cpp_
 extern const char cpp_GCC_INCLUDE_DIR[];
 extern const size_t cpp_GCC_INCLUDE_DIR_len;
 
+/* The configre-time prefix, i.e., the value supplied as the argument
+   to --prefix=.  */
 extern const char cpp_PREFIX[];
+/* The length of the configure-time prefix.  */
 extern const size_t cpp_PREFIX_len;
+/* The configure-time execution prefix.  This is typically the lib/gcc
+   subdirectory of cpp_PREFIX.  */
+extern const char cpp_EXEC_PREFIX[];
+/* The run-time execution prefix.  This is typically the lib/gcc
+   subdirectory of the actual installation.  */
 extern const char *gcc_exec_prefix;
 
 /* Return true if the toolchain is relocated.  */
Index: Makefile.in
===================================================================
--- Makefile.in	(revision 122822)
+++ Makefile.in	(working copy)
@@ -3210,6 +3210,7 @@ PREPROCESSOR_DEFINES = \
   -DCROSS_INCLUDE_DIR=\"$(CROSS_SYSTEM_HEADER_DIR)\" \
   -DTOOL_INCLUDE_DIR=\"$(gcc_tooldir)/include\" \
   -DPREFIX=\"$(prefix)\" \
+  -DSTANDARD_EXEC_PREFIX=\"$(libdir)/gcc\" \
   @TARGET_SYSTEM_ROOT_DEFINE@
 
 cppdefault.o: cppdefault.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
Index: c-incpath.c
===================================================================
--- c-incpath.c	(revision 122822)
+++ c-incpath.c	(working copy)
@@ -167,11 +167,26 @@ add_standard_paths (const char *sysroot,
 	  else if (!p->add_sysroot && relocated
 		   && strncmp (p->fname, cpp_PREFIX, cpp_PREFIX_len) == 0)
 	    {
-	      /* If the compiler is relocated, and this is a configured 
-		 prefix relative path, then we use gcc_exec_prefix instead 
-		 of the configured prefix.  */
-	      str = concat (gcc_exec_prefix, p->fname
-			      + cpp_PREFIX_len, NULL);
+ 	      static const char *relocated_prefix;
+	      /* If this path starts with the configure-time prefix, 
+		 but the compiler has been relocated, replace it 
+		 with the run-time prefix.  The run-time exec prefix
+		 is GCC_EXEC_PREFIX.  Compute the path from there back
+		 to the toplevel prefix.  */
+	      if (!relocated_prefix)
+		{
+		  char *dummy;
+		  /* Make relative prefix expects the first argument
+		     to be a program, not a directory.  */
+		  dummy = concat (gcc_exec_prefix, "dummy", NULL);
+		  relocated_prefix 
+		    = make_relative_prefix (dummy,
+					    cpp_EXEC_PREFIX,
+					    cpp_PREFIX);
+		}
+	      str = concat (relocated_prefix,
+			    p->fname + cpp_PREFIX_len, 
+			    NULL);
 	      str = update_path (str, p->component);
 	    }
 	  else



More information about the Gcc-patches mailing list