This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Fix PR20425, multilib paths for -print-search-dirs
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 8 Dec 2005 23:02:58 +1030
- Subject: Fix PR20425, multilib paths for -print-search-dirs
This fixes a longstanding gcc/libtool complaint that the library search
path is wrong when using multilibs. I've modified gcc -print-search-dirs
to print the library search path out twice if multilibs are in force,
first with the appropriate multilib suffixes, then without. I also do
the same for LIBRARY_PATH_ENV. The fact that this just extends the list
of directories printed should ameliorate concerns that changing
-print-search-paths like this will break existing uses.
Bootstrapped etc. powerpc64-linux and powerpc-linux. OK for mainline?
PR driver/20425
* gcc.c (maybe_add_path): New function.
(build_search_list): Add do_multi param. Add search paths twice
for multilibs, first with multilib suffix then without.
(putenv_from_prefixes): Add do_multi param.
(main): Adjust build_search_list and putenv_from_prefixes calls
to give multilib paths for libraries.
Index: gcc/gcc.c
===================================================================
--- gcc/gcc.c (revision 108214)
+++ gcc/gcc.c (working copy)
@@ -287,8 +287,9 @@ static char *load_specs (const char *);
static void read_specs (const char *, int);
static void set_spec (const char *, const char *);
static struct compiler *lookup_compiler (const char *, size_t, const char *);
-static char *build_search_list (struct path_prefix *, const char *, int);
-static void putenv_from_prefixes (struct path_prefix *, const char *);
+static char *build_search_list (struct path_prefix *, const char *,
+ bool, bool);
+static void putenv_from_prefixes (struct path_prefix *, const char *, bool);
static int access_check (const char *, int);
static char *find_a_file (struct path_prefix *, const char *, int, int);
static void add_prefix (struct path_prefix *, const char *, const char *,
@@ -2357,6 +2358,27 @@ clear_failure_queue (void)
failure_delete_queue = 0;
}
+/* Helper for build_search_list. Adds concatentated str1 and str2 to
+ path currently being built. */
+
+static bool
+maybe_add_path (struct obstack *ob, bool first_time, bool check_dir_p,
+ const char *str1, size_t str1_len,
+ const char *str2, size_t str2_len)
+{
+ if (check_dir_p && !is_directory (str1, str2 ? str2 : "", 0))
+ return first_time;
+
+ if (!first_time)
+ obstack_1grow (ob, PATH_SEPARATOR);
+
+ obstack_grow (ob, str1, str1_len);
+ if (str2_len)
+ obstack_grow (ob, str2, str2_len);
+
+ return false;
+}
+
/* Build a list of search directories from PATHS.
PREFIX is a string to prepend to the list.
If CHECK_DIR_P is nonzero we ensure the directory exists.
@@ -2365,54 +2387,100 @@ clear_failure_queue (void)
static char *
build_search_list (struct path_prefix *paths, const char *prefix,
- int check_dir_p)
+ bool check_dir_p, bool do_multi)
{
- int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0;
- int just_suffix_len
- = (just_machine_suffix) ? strlen (just_machine_suffix) : 0;
- int first_time = TRUE;
- struct prefix_list *pprefix;
+ bool first_time = true;
+ struct prefix_list *pl;
+ char *multi_dir = NULL;
+ char *multi_os_dir = NULL;
+ char *multi_suffix;
+ char *just_multi_suffix;
+
+ multi_suffix = machine_suffix;
+ just_multi_suffix = just_machine_suffix;
+ if (do_multi && multilib_dir)
+ {
+ multi_dir = concat (multilib_dir, dir_separator_str, NULL);
+ multi_os_dir = concat (multilib_os_dir, dir_separator_str, NULL);
+ if (multi_suffix)
+ multi_suffix = concat (multi_suffix, multi_dir, NULL);
+ if (just_multi_suffix)
+ just_multi_suffix = concat (just_multi_suffix, multi_dir, NULL);
+ }
obstack_grow (&collect_obstack, prefix, strlen (prefix));
obstack_1grow (&collect_obstack, '=');
- for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next)
+ /* Add paths twice, first with multilibs (if enabled), then without. */
+ while (1)
{
- int len = strlen (pprefix->prefix);
-
- if (machine_suffix
- && (! check_dir_p
- || is_directory (pprefix->prefix, machine_suffix, 0)))
- {
- if (!first_time)
- obstack_1grow (&collect_obstack, PATH_SEPARATOR);
-
- first_time = FALSE;
- obstack_grow (&collect_obstack, pprefix->prefix, len);
- obstack_grow (&collect_obstack, machine_suffix, suffix_len);
+ size_t multi_dir_len = 0;
+ size_t multi_os_dir_len = 0;
+ size_t suffix_len = 0;
+ size_t just_suffix_len = 0;
+
+ if (multi_dir)
+ multi_dir_len = strlen (multi_dir);
+ if (multi_os_dir)
+ multi_os_dir_len = strlen (multi_os_dir);
+ if (multi_suffix)
+ suffix_len = strlen (multi_suffix);
+ if (just_multi_suffix)
+ just_suffix_len = strlen (just_multi_suffix);
+
+ for (pl = paths->plist; pl != 0; pl = pl->next)
+ {
+ int len = strlen (pl->prefix);
+ char *path;
+
+ if (multi_suffix)
+ first_time
+ = maybe_add_path (&collect_obstack, first_time, check_dir_p,
+ pl->prefix, len,
+ multi_suffix, suffix_len);
+
+ if (just_multi_suffix
+ && pl->require_machine_suffix == 2)
+ first_time
+ = maybe_add_path (&collect_obstack, first_time, check_dir_p,
+ pl->prefix, len,
+ just_multi_suffix, just_suffix_len);
+
+ if (!pl->require_machine_suffix)
+ {
+ char *this_multi;
+ size_t this_multi_len;
+ if (pl->os_multilib)
+ {
+ this_multi = multi_os_dir;
+ this_multi_len = multi_os_dir_len;
+ }
+ else
+ {
+ this_multi = multi_dir;
+ this_multi_len = multi_dir_len;
+ }
+ first_time
+ = maybe_add_path (&collect_obstack, first_time, false,
+ pl->prefix, len,
+ this_multi, this_multi_len);
+ }
}
-
- if (just_machine_suffix
- && pprefix->require_machine_suffix == 2
- && (! check_dir_p
- || is_directory (pprefix->prefix, just_machine_suffix, 0)))
+ if (multi_dir == NULL)
+ break;
+ free (multi_dir);
+ multi_dir = NULL;
+ free (multi_os_dir);
+ multi_os_dir = NULL;
+ if (multi_suffix)
{
- if (! first_time)
- obstack_1grow (&collect_obstack, PATH_SEPARATOR);
-
- first_time = FALSE;
- obstack_grow (&collect_obstack, pprefix->prefix, len);
- obstack_grow (&collect_obstack, just_machine_suffix,
- just_suffix_len);
+ free (multi_suffix);
+ multi_suffix = machine_suffix;
}
-
- if (! pprefix->require_machine_suffix)
+ if (just_multi_suffix)
{
- if (! first_time)
- obstack_1grow (&collect_obstack, PATH_SEPARATOR);
-
- first_time = FALSE;
- obstack_grow (&collect_obstack, pprefix->prefix, len);
+ free (just_multi_suffix);
+ just_multi_suffix = just_machine_suffix;
}
}
@@ -2424,9 +2492,10 @@ build_search_list (struct path_prefix *p
for collect. */
static void
-putenv_from_prefixes (struct path_prefix *paths, const char *env_var)
+putenv_from_prefixes (struct path_prefix *paths, const char *env_var,
+ bool do_multi)
{
- putenv (build_search_list (paths, env_var, 1));
+ putenv (build_search_list (paths, env_var, true, do_multi));
}
/* Check whether NAME can be accessed in MODE. This is like access,
@@ -6312,8 +6377,10 @@ main (int argc, char **argv)
if (print_search_dirs)
{
printf (_("install: %s%s\n"), standard_exec_prefix, machine_suffix);
- printf (_("programs: %s\n"), build_search_list (&exec_prefixes, "", 0));
- printf (_("libraries: %s\n"), build_search_list (&startfile_prefixes, "", 0));
+ printf (_("programs: %s\n"),
+ build_search_list (&exec_prefixes, "", false, false));
+ printf (_("libraries: %s\n"),
+ build_search_list (&startfile_prefixes, "", false, true));
return (0);
}
@@ -6636,8 +6703,8 @@ main (int argc, char **argv)
}
/* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
for collect. */
- putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH");
- putenv_from_prefixes (&startfile_prefixes, LIBRARY_PATH_ENV);
+ putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH", false);
+ putenv_from_prefixes (&startfile_prefixes, LIBRARY_PATH_ENV, true);
value = do_spec (link_command_spec);
if (value < 0)
--
Alan Modra
IBM OzLabs - Linux Technology Centre