[PATCH] Turn off prefix canonicalization

Simon Baldwin simonb@google.com
Thu Jul 2 14:22:00 GMT 2009


This patch exposes a feature of libiberty that is needed if gcc is installed
as a pure "symlink farm".  It allows the user to suppress calls to realpath()
on prefixes generated relative to argv[0] in the gcc driver.

Without the patch, prefixes generated by gcc held in a symlink farm will
not be accurate, and compilations fail.  This can be worked around with copious
use of -B, -isystem, -L, GCC_EXEC_PREFIX, PATH, and so on, but only in a very
inelegant and difficult manner.

Tested with full bootstrap on x86_64, and confirmed no testsuite regressions.
Verified man, info, and pdf doc.  Okay for mainline?  Thanks.


gcc/ChangeLog
2009-07-02  Simon Baldwin  <simonb@google.com>

	* gcc.c (option_map): New flag -no-canonical-prefixes.
	* (display_help): Print help text for new flag.
	* (process_command): Move options translation and language specifics
	and handle new flag early.  Use it to set a function pointer to a
	prefix builder.  Replace make_relative_prefix calls with calls to
	the function pointed to.  Ignore new flag in regular options handling.
	* doc/invoke.texi (Overall Options): Documented -no-canonical-prefixes.


Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi	(revision 149169)
+++ gcc/doc/invoke.texi	(working copy)
@@ -161,7 +161,8 @@ in the following sections.
 @table @emph
 @item Overall Options
 @xref{Overall Options,,Options Controlling the Kind of Output}.
-@gccoptlist{-c  -S  -E  -o @var{file}  -combine  -pipe  -pass-exit-codes  @gol
+@gccoptlist{-c  -S  -E  -o @var{file}  -combine  -no-canonical-prefixes  @gol
+-pipe  -pass-exit-codes  @gol
 -x @var{language}  -v  -###  --help@r{[}=@var{class}@r{[},@dots{}@r{]]}  --target-help  @gol
 --version -wrapper@@@var{file} -fplugin=@var{file} -fplugin-arg-@var{name}=@var{arg}}
 
@@ -1301,6 +1302,12 @@ gcc -c -Q -O2 --help=optimizers > /tmp/O
 diff /tmp/O2-opts /tmp/O3-opts | grep enabled
 @end smallexample
 
+@item -no-canonical-prefixes
+@opindex no-canonical-prefixes
+Do not expand any symbolic links, resolve references to @samp{/../}
+or @samp{/./}, or make the path absolute when generating a relative
+prefix.
+
 @item --version
 @opindex version
 Display the version number and copyrights of the invoked GCC@.
Index: gcc/gcc.c
===================================================================
--- gcc/gcc.c	(revision 149169)
+++ gcc/gcc.c	(working copy)
@@ -1180,6 +1180,7 @@ static const struct option_map option_ma
    {"--library-directory", "-L", "a"},
    {"--machine", "-m", "aj"},
    {"--machine-", "-m", "*j"},
+   {"--no-canonical-prefixes", "-no-canonical-prefixes", 0},
    {"--no-integrated-cpp", "-no-integrated-cpp", 0},
    {"--no-line-commands", "-P", 0},
    {"--no-precompiled-includes", "-noprecomp", 0},
@@ -3370,6 +3371,9 @@ display_help (void)
   fputs (_("  -combine                 Pass multiple source files to compiler at once\n"), stdout);
   fputs (_("  -save-temps              Do not delete intermediate files\n"), stdout);
   fputs (_("  -save-temps=<arg>        Do not delete intermediate files\n"), stdout);
+  fputs (_("\
+  -no-canonical-prefixes   Do not canonicalize paths when building relative\n\
+                           prefixes to other gcc components\n"), stdout);
   fputs (_("  -pipe                    Use pipes rather than intermediate files\n"), stdout);
   fputs (_("  -time                    Time the execution of each subprocess\n"), stdout);
   fputs (_("  -specs=<file>            Override built-in specs with the contents of <file>\n"), stdout);
@@ -3462,6 +3466,8 @@ process_command (int argc, const char **
   unsigned int j;
 #endif
   const char *tooldir_prefix;
+  char *(*get_relative_prefix) (const char *, const char *,
+				const char *) = NULL;
 
   GET_ENVIRONMENT (gcc_exec_prefix, "GCC_EXEC_PREFIX");
 
@@ -3557,6 +3563,32 @@ process_command (int argc, const char **
       exit (status);
     }
 
+  /* Convert new-style -- options to old-style.  */
+  translate_options (&argc,
+		     CONST_CAST2 (const char *const **, const char ***,
+				  &argv));
+
+  /* Do language-specific adjustment/addition of flags.  */
+  lang_specific_driver (&argc,
+			CONST_CAST2 (const char *const **, const char ***,
+				     &argv),
+			&added_libraries);
+
+  /* Handle any -no-canonical-prefixes flag early, to assign the function
+     that builds relative prefixes.  This function creates default search
+     paths that are needed later in normal option handling.  */
+
+  for (i = 1; i < argc; i++)
+    {
+      if (! strcmp (argv[i], "-no-canonical-prefixes"))
+	{
+	  get_relative_prefix = make_relative_prefix_ignore_links;
+	  break;
+	}
+    }
+  if (! get_relative_prefix)
+    get_relative_prefix = make_relative_prefix;
+
   /* Set up the default search paths.  If there is no GCC_EXEC_PREFIX,
      see if we can create it from the pathname specified in argv[0].  */
 
@@ -3565,11 +3597,12 @@ process_command (int argc, const char **
   /* FIXME: make_relative_prefix doesn't yet work for VMS.  */
   if (!gcc_exec_prefix)
     {
-      gcc_exec_prefix = make_relative_prefix (argv[0], standard_bindir_prefix,
-					      standard_exec_prefix);
-      gcc_libexec_prefix = make_relative_prefix (argv[0],
-						 standard_bindir_prefix,
-						 standard_libexec_prefix);
+      gcc_exec_prefix = get_relative_prefix (argv[0],
+					     standard_bindir_prefix,
+					     standard_exec_prefix);
+      gcc_libexec_prefix = get_relative_prefix (argv[0],
+					     standard_bindir_prefix,
+					     standard_libexec_prefix);
       if (gcc_exec_prefix)
 	xputenv (concat ("GCC_EXEC_PREFIX=", gcc_exec_prefix, NULL));
     }
@@ -3580,9 +3613,9 @@ process_command (int argc, const char **
 	 / (which is ignored by make_relative_prefix), so append a
 	 program name.  */
       char *tmp_prefix = concat (gcc_exec_prefix, "gcc", NULL);
-      gcc_libexec_prefix = make_relative_prefix (tmp_prefix,
-						 standard_exec_prefix,
-						 standard_libexec_prefix);
+      gcc_libexec_prefix = get_relative_prefix (tmp_prefix,
+						standard_exec_prefix,
+						standard_libexec_prefix);
 
       /* The path is unrelocated, so fallback to the original setting.  */
       if (!gcc_libexec_prefix)
@@ -3720,17 +3753,6 @@ process_command (int argc, const char **
 	}
     }
 
-  /* Convert new-style -- options to old-style.  */
-  translate_options (&argc,
-		     CONST_CAST2 (const char *const **, const char ***,
-				  &argv));
-
-  /* Do language-specific adjustment/addition of flags.  */
-  lang_specific_driver (&argc,
-			CONST_CAST2 (const char *const **, const char ***,
-				     &argv),
-			&added_libraries);
-
   /* Scan argv twice.  Here, the first time, just count how many switches
      there will be in their vector, and how many input files in theirs.
      Here we also parse the switches that cc itself uses (e.g. -v).  */
@@ -3958,6 +3980,9 @@ process_command (int argc, const char **
 	  else
 	    fatal ("'%s' is an unknown -save-temps option", argv[i]);
 	}
+      else if (strcmp (argv[i], "-no-canonical-prefixes") == 0)
+	/* Already handled as a special case, so ignored here.  */
+	;
       else if (strcmp (argv[i], "-combine") == 0)
 	{
 	  combine_flag = 1;
@@ -4305,9 +4330,9 @@ process_command (int argc, const char **
      ``make_relative_prefix'' is not compiled for VMS, so don't call it.  */
   if (target_system_root && gcc_exec_prefix)
     {
-      char *tmp_prefix = make_relative_prefix (argv[0],
-					       standard_bindir_prefix,
-					       target_system_root);
+      char *tmp_prefix = get_relative_prefix (argv[0],
+					      standard_bindir_prefix,
+					      target_system_root);
       if (tmp_prefix && access_check (tmp_prefix, F_OK) == 0)
 	{
 	  target_system_root = tmp_prefix;
@@ -4349,6 +4374,8 @@ process_command (int argc, const char **
 	;
       else if (! strncmp (argv[i], "-Wp,", 4))
 	;
+      else if (! strcmp (argv[i], "-no-canonical-prefixes"))
+	;
       else if (! strcmp (argv[i], "-pass-exit-codes"))
 	;
       else if (! strcmp (argv[i], "-print-search-dirs"))



More information about the Gcc-patches mailing list