This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RFA: Fix driver/29931
- From: Joern RENNECKE <joern dot rennecke at st dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 22 Nov 2006 14:46:39 +0000
- Subject: RFA: Fix driver/29931
I have updated the patch for current mainline.
bootstrapped & regression tested on i686-pc-linux-gnu .
:ADDPATCH driver:
gcc:
2006-11-21 Andrew Stubbs <andrew.stubbs@st.com>
J"orn Rennecke <joern.rennecke@st.com>
* gcc.c (process_command): Try to set gcc_exec_prefix with
make_relative_prefix_ignore_links before resolving to
make_relative_prefix.
If gcc_exec_prefix has been pre-set, use
make_relative_prefix_ignore_links to calculate gcc_libexec_prefix.
(main): Initialize machine_suffix and just_machine_suffix before
first call to process_command.
include:
2006-05-03 Andrew Stubbs <andrew.stubbs@st.com>
J"orn Rennecke <joern.rennecke@st.com>
* libiberty.h (make_relative_prefix_ignore_links): Declare.
libiberty:
2006-05-03 Andrew Stubbs <andrew.stubbs@st.com>
J"orn Rennecke <joern.rennecke@st.com>
* make-relative-prefix.c (make_relative_prefix_1): New function,
broken out of make_relative_prefix. Make link resolution dependent
on new parameter.
(make_relative_prefix): Use make_relative_prefix_1.
(make_relative_prefix_ignore_links): New function.
Index: gcc/gcc.c
===================================================================
/usr/bin/diff -p -d -F^( -u -L gcc/gcc.c (revision 119055) -L gcc/gcc.c (working copy) gcc/.svn/text-base/gcc.c.svn-base gcc/gcc.c
--- gcc/gcc.c (revision 119055)
+++ gcc/gcc.c (working copy)
@@ -3375,11 +3375,38 @@ 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);
+ /* argv[0] may be a soft link. In this case it may be correct to ignore it and treat it
+ as the real thing, or we may have to follow the link and find the real installation.
+ We decide which to do based on whether we can find the target directory (its name
+ is in spec_machine) without following the links.
+ If so then assume ALL the files have been linked. In this case it would be the wrong
+ thing to try and be clever, because the user may be pasting the installation
+ together with links. Some simple package managers do do this. */
+ char *temp;
+ gcc_libexec_prefix = make_relative_prefix_ignore_links (argv[0],
+ standard_bindir_prefix,
+ standard_libexec_prefix);
+ if (gcc_libexec_prefix)
+ add_prefix (&exec_prefixes, gcc_libexec_prefix, "GCC",
+ PREFIX_PRIORITY_LAST, 0, 0);
+ if ((temp = find_a_file (&exec_prefixes, spec_machine, R_OK, 0)) == NULL)
+ {
+ /* the directory was not found so follow the links and hope that solves the problem. */
+ 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);
+ }
+ else
+ {
+ /* the directory was found so ignore the links and assume the headers/libraries/programs
+ are all linked from the same place as required. */
+ free(temp);
+ gcc_exec_prefix = make_relative_prefix_ignore_links (argv[0], standard_bindir_prefix,
+ standard_exec_prefix);
+ }
+
if (gcc_exec_prefix)
putenv (concat ("GCC_EXEC_PREFIX=", gcc_exec_prefix, NULL));
}
@@ -3390,9 +3417,11 @@ 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);
+ /* Assume the user knew what they were doing when they set
+ GCC_EXEC_PREFIX so ignore any soft links. */
+ gcc_libexec_prefix = make_relative_prefix_ignore_links (tmp_prefix,
+ standard_exec_prefix,
+ standard_libexec_prefix);
/* The path is unrelocated, so fallback to the original setting. */
if (!gcc_libexec_prefix)
@@ -6192,6 +6221,10 @@ main (int argc, char **argv)
putenv (INIT_ENVIRONMENT);
#endif
+ machine_suffix = concat (spec_machine, dir_separator_str,
+ spec_version, dir_separator_str, NULL);
+ just_machine_suffix = concat (spec_machine, dir_separator_str, NULL);
+
/* Make a table of what switches there are (switches, n_switches).
Make a table of specified input files (infiles, n_infiles).
Decode switches that are handled locally. */
@@ -6207,10 +6240,6 @@ main (int argc, char **argv)
/* Read specs from a file if there is one. */
- machine_suffix = concat (spec_machine, dir_separator_str,
- spec_version, dir_separator_str, NULL);
- just_machine_suffix = concat (spec_machine, dir_separator_str, NULL);
-
specs_file = find_a_file (&startfile_prefixes, "specs", R_OK, true);
/* Read the specs file unless it is a default one. */
if (specs_file != 0 && strcmp (specs_file, "specs"))
Index: include/libiberty.h
===================================================================
/usr/bin/diff -p -d -F^( -u -L include/libiberty.h (revision 119055) -L include/libiberty.h (working copy) include/.svn/text-base/libiberty.h.svn-base include/libiberty.h
--- include/libiberty.h (revision 119055)
+++ include/libiberty.h (working copy)
@@ -197,6 +197,13 @@ extern long get_run_time (void);
extern char *make_relative_prefix (const char *, const char *,
const char *) ATTRIBUTE_MALLOC;
+/* Generate a relocated path to some installation directory without
+ attempting to follow any soft links. Allocates
+ return value using malloc. */
+
+extern char *make_relative_prefix_ignore_links (const char *, const char *,
+ const char *) ATTRIBUTE_MALLOC;
+
/* Choose a temporary directory to use for scratch files. */
extern char *choose_temp_base (void) ATTRIBUTE_MALLOC;
Index: libiberty/make-relative-prefix.c
===================================================================
/usr/bin/diff -p -d -F^( -u -L libiberty/make-relative-prefix.c (revision 119055) -L libiberty/make-relative-prefix.c (working copy) libiberty/.svn/text-base/make-relative-prefix.c.svn-base libiberty/make-relative-prefix.c
--- libiberty/make-relative-prefix.c (revision 119055)
+++ libiberty/make-relative-prefix.c (working copy)
@@ -1,6 +1,6 @@
/* Relative (relocatable) prefix support.
Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
- 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+ 1999, 2000, 2001, 2002, 2006 Free Software Foundation, Inc.
This file is part of libiberty.
@@ -217,9 +217,9 @@ free_split_directories (char **dirs)
If no relative prefix can be found, return NULL. */
-char *
-make_relative_prefix (const char *progname,
- const char *bin_prefix, const char *prefix)
+static char *
+make_relative_prefix_1 (const char *progname, const char *bin_prefix,
+ const char *prefix, const int resolve_links)
{
char **prog_dirs, **bin_dirs, **prefix_dirs;
int prog_num, bin_num, prefix_num;
@@ -289,9 +289,14 @@ make_relative_prefix (const char *progna
}
}
- full_progname = lrealpath (progname);
- if (full_progname == NULL)
- return NULL;
+ if ( resolve_links )
+ {
+ full_progname = lrealpath (progname);
+ if (full_progname == NULL)
+ return NULL;
+ }
+ else
+ full_progname = strdup(progname);
prog_dirs = split_directories (full_progname, &prog_num);
bin_dirs = split_directories (bin_prefix, &bin_num);
@@ -387,3 +392,33 @@ make_relative_prefix (const char *progna
return ret;
}
+
+
+/* Do the full job, including symlink resolution.
+ This path will find files installed in the same place as the
+ program even when a soft link has been made to the program
+ from somwhere else. */
+
+char *
+make_relative_prefix (progname, bin_prefix, prefix)
+ const char *progname;
+ const char *bin_prefix;
+ const char *prefix;
+{
+ return make_relative_prefix_1 (progname, bin_prefix, prefix, 1);
+}
+
+/* Make the relative pathname without attempting to resolve any links.
+ '..' etc may also be left in the pathname.
+ This will find the files the user meant the program to find if the
+ installation is patched together with soft links. */
+
+char *
+make_relative_prefix_ignore_links (progname, bin_prefix, prefix)
+ const char *progname;
+ const char *bin_prefix;
+ const char *prefix;
+{
+ return make_relative_prefix_1 (progname, bin_prefix, prefix, 0);
+}
+