summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/gcc.c170
1 files changed, 99 insertions, 71 deletions
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 08d7d59e1..6fd6a66d1 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -3531,6 +3531,9 @@ static void
process_command (unsigned int decoded_options_count,
struct cl_decoded_option *decoded_options)
{
+ const char * target_system_root_cached;
+ const char * target_system_root_specified;
+
const char *temp;
char *temp1;
const char *tooldir_prefix;
@@ -3619,6 +3622,80 @@ process_command (unsigned int decoded_options_count,
lang_specific_driver (&decoded_options, &decoded_options_count,
&added_libraries);
+ /* Process the options and store input files and switches in their
+ vectors. */
+
+ last_language_n_infiles = -1;
+
+ set_option_handlers (&handlers);
+
+ for (j = 1; j < decoded_options_count; j++)
+ {
+ switch (decoded_options[j].opt_index)
+ {
+ case OPT_S:
+ case OPT_c:
+ case OPT_E:
+ have_c = 1;
+ break;
+ }
+ if (have_c)
+ break;
+ }
+
+ for (j = 1; j < decoded_options_count; j++)
+ {
+ if (decoded_options[j].opt_index == OPT_SPECIAL_input_file)
+ {
+ const char *arg = decoded_options[j].arg;
+ const char *p = strrchr (arg, '@');
+ char *fname;
+ long offset;
+ int consumed;
+#ifdef HAVE_TARGET_OBJECT_SUFFIX
+ arg = convert_filename (arg, 0, access (arg, F_OK));
+#endif
+ /* For LTO static archive support we handle input file
+ specifications that are composed of a filename and
+ an offset like FNAME@OFFSET. */
+ if (p
+ && p != arg
+ && sscanf (p, "@%li%n", &offset, &consumed) >= 1
+ && strlen (p) == (unsigned int)consumed)
+ {
+ fname = (char *)xmalloc (p - arg + 1);
+ memcpy (fname, arg, p - arg);
+ fname[p - arg] = '\0';
+ /* Only accept non-stdin and existing FNAME parts, otherwise
+ try with the full name. */
+ if (strcmp (fname, "-") == 0 || access (fname, F_OK) < 0)
+ {
+ free (fname);
+ fname = xstrdup (arg);
+ }
+ }
+ else
+ fname = xstrdup (arg);
+
+ if (strcmp (fname, "-") != 0 && access (fname, F_OK) < 0)
+ perror_with_name (fname);
+ else
+ add_infile (arg, spec_lang);
+
+ free (fname);
+ continue;
+ }
+
+ /* adding sysroot relative search dirs must happen _after_ option parsing */
+ /* ... but we also wanted smooth cross-building for a new sysrooted target */
+
+ target_system_root_cached = target_system_root;
+
+ read_cmdline_option (&global_options, &global_options_set,
+ decoded_options + j, UNKNOWN_LOCATION,
+ CL_DRIVER, &handlers, global_dc);
+ }
+
if (gcc_exec_prefix)
{
int len = strlen (gcc_exec_prefix);
@@ -3641,8 +3718,28 @@ process_command (unsigned int decoded_options_count,
PREFIX_PRIORITY_LAST, 0, 0);
}
- add_sysrooted_prefix (&startfile_prefixes, "/lib/", "GCC",
- PREFIX_PRIORITY_LAST, 0, 0);
+ if (target_system_root_changed) {
+ add_sysrooted_prefix (&startfile_prefixes,
+ standard_startfile_prefix_1,
+ "GCC", PREFIX_PRIORITY_LAST, 0, 0);
+
+ add_sysrooted_prefix (&startfile_prefixes,
+ standard_startfile_prefix_2,
+ "GCC", PREFIX_PRIORITY_LAST, 0, 0);
+ }
+
+ if (target_system_root_changed) {
+ target_system_root_specified = target_system_root;
+ target_system_root = target_system_root_cached;
+
+ add_sysrooted_prefix (&startfile_prefixes,
+ "/lib/", "GCC", PREFIX_PRIORITY_LAST, 0, 0);
+
+ target_system_root = target_system_root_specified;
+ } else {
+ add_sysrooted_prefix (&startfile_prefixes,
+ "/lib/", "GCC", PREFIX_PRIORITY_LAST, 0, 0);
+ }
/* COMPILER_PATH and LIBRARY_PATH have values
that are lists of directory names with colons. */
@@ -3746,75 +3843,6 @@ process_command (unsigned int decoded_options_count,
}
}
- /* Process the options and store input files and switches in their
- vectors. */
-
- last_language_n_infiles = -1;
-
- set_option_handlers (&handlers);
-
- for (j = 1; j < decoded_options_count; j++)
- {
- switch (decoded_options[j].opt_index)
- {
- case OPT_S:
- case OPT_c:
- case OPT_E:
- have_c = 1;
- break;
- }
- if (have_c)
- break;
- }
-
- for (j = 1; j < decoded_options_count; j++)
- {
- if (decoded_options[j].opt_index == OPT_SPECIAL_input_file)
- {
- const char *arg = decoded_options[j].arg;
- const char *p = strrchr (arg, '@');
- char *fname;
- long offset;
- int consumed;
-#ifdef HAVE_TARGET_OBJECT_SUFFIX
- arg = convert_filename (arg, 0, access (arg, F_OK));
-#endif
- /* For LTO static archive support we handle input file
- specifications that are composed of a filename and
- an offset like FNAME@OFFSET. */
- if (p
- && p != arg
- && sscanf (p, "@%li%n", &offset, &consumed) >= 1
- && strlen (p) == (unsigned int)consumed)
- {
- fname = (char *)xmalloc (p - arg + 1);
- memcpy (fname, arg, p - arg);
- fname[p - arg] = '\0';
- /* Only accept non-stdin and existing FNAME parts, otherwise
- try with the full name. */
- if (strcmp (fname, "-") == 0 || access (fname, F_OK) < 0)
- {
- free (fname);
- fname = xstrdup (arg);
- }
- }
- else
- fname = xstrdup (arg);
-
- if (strcmp (fname, "-") != 0 && access (fname, F_OK) < 0)
- perror_with_name (fname);
- else
- add_infile (arg, spec_lang);
-
- free (fname);
- continue;
- }
-
- read_cmdline_option (&global_options, &global_options_set,
- decoded_options + j, UNKNOWN_LOCATION,
- CL_DRIVER, &handlers, global_dc);
- }
-
/* If -save-temps=obj and -o name, create the prefix to use for %b.
Otherwise just make -save-temps=obj the same as -save-temps=cwd. */
if (save_temps_flag == SAVE_TEMPS_OBJ && save_temps_prefix != NULL)