Branch data Line data Source code
1 : : /* Compiler driver program that can handle many languages.
2 : : Copyright (C) 1987-2025 Free Software Foundation, Inc.
3 : :
4 : : This file is part of GCC.
5 : :
6 : : GCC is free software; you can redistribute it and/or modify it under
7 : : the terms of the GNU General Public License as published by the Free
8 : : Software Foundation; either version 3, or (at your option) any later
9 : : version.
10 : :
11 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 : : for more details.
15 : :
16 : : You should have received a copy of the GNU General Public License
17 : : along with GCC; see the file COPYING3. If not see
18 : : <http://www.gnu.org/licenses/>. */
19 : :
20 : : /* This program is the user interface to the C compiler and possibly to
21 : : other compilers. It is used because compilation is a complicated procedure
22 : : which involves running several programs and passing temporary files between
23 : : them, forwarding the users switches to those programs selectively,
24 : : and deleting the temporary files at the end.
25 : :
26 : : CC recognizes how to compile each input file by suffixes in the file names.
27 : : Once it knows which kind of compilation to perform, the procedure for
28 : : compilation is specified by a string called a "spec". */
29 : :
30 : : #define INCLUDE_STRING
31 : : #include "config.h"
32 : : #include "system.h"
33 : : #ifdef HOST_HAS_PERSONALITY_ADDR_NO_RANDOMIZE
34 : : #include <sys/personality.h>
35 : : #endif
36 : : #include "coretypes.h"
37 : : #include "multilib.h" /* before tm.h */
38 : : #include "tm.h"
39 : : #include "xregex.h"
40 : : #include "obstack.h"
41 : : #include "intl.h"
42 : : #include "prefix.h"
43 : : #include "opt-suggestions.h"
44 : : #include "gcc.h"
45 : : #include "diagnostic.h"
46 : : #include "diagnostic-format.h"
47 : : #include "pretty-print-urlifier.h"
48 : : #include "flags.h"
49 : : #include "opts.h"
50 : : #include "filenames.h"
51 : : #include "spellcheck.h"
52 : : #include "opts-jobserver.h"
53 : : #include "common/common-target.h"
54 : : #include "gcc-urlifier.h"
55 : : #include "opts-diagnostic.h"
56 : :
57 : : #ifndef MATH_LIBRARY
58 : : #define MATH_LIBRARY "m"
59 : : #endif
60 : :
61 : :
62 : : /* Manage the manipulation of env vars.
63 : :
64 : : We poison "getenv" and "putenv", so that all enviroment-handling is
65 : : done through this class. Note that poisoning happens in the
66 : : preprocessor at the identifier level, and doesn't distinguish between
67 : : env.getenv ();
68 : : and
69 : : getenv ();
70 : : Hence we need to use "get" for the accessor method, not "getenv". */
71 : :
72 : : struct env_manager
73 : : {
74 : : public:
75 : : void init (bool can_restore, bool debug);
76 : : const char *get (const char *name);
77 : : void xput (const char *string);
78 : : void restore ();
79 : :
80 : : private:
81 : : bool m_can_restore;
82 : : bool m_debug;
83 : : struct kv
84 : : {
85 : : char *m_key;
86 : : char *m_value;
87 : : };
88 : : vec<kv> m_keys;
89 : :
90 : : };
91 : :
92 : : /* The singleton instance of class env_manager. */
93 : :
94 : : static env_manager env;
95 : :
96 : : /* Initializer for class env_manager.
97 : :
98 : : We can't do this as a constructor since we have a statically
99 : : allocated instance ("env" above). */
100 : :
101 : : void
102 : 296263 : env_manager::init (bool can_restore, bool debug)
103 : : {
104 : 296263 : m_can_restore = can_restore;
105 : 296263 : m_debug = debug;
106 : 296263 : }
107 : :
108 : : /* Get the value of NAME within the environment. Essentially
109 : : a wrapper for ::getenv, but adding logging, and the possibility
110 : : of caching results. */
111 : :
112 : : const char *
113 : 1480395 : env_manager::get (const char *name)
114 : : {
115 : 1480395 : const char *result = ::getenv (name);
116 : 1480395 : if (m_debug)
117 : 0 : fprintf (stderr, "env_manager::getenv (%s) -> %s\n", name, result);
118 : 1480395 : return result;
119 : : }
120 : :
121 : : /* Put the given KEY=VALUE entry STRING into the environment.
122 : : If the env_manager was initialized with CAN_RESTORE set, then
123 : : also record the old value of KEY within the environment, so that it
124 : : can be later restored. */
125 : :
126 : : void
127 : 1750473 : env_manager::xput (const char *string)
128 : : {
129 : 1750473 : if (m_debug)
130 : 0 : fprintf (stderr, "env_manager::xput (%s)\n", string);
131 : 1750473 : if (verbose_flag)
132 : 5950 : fnotice (stderr, "%s\n", string);
133 : :
134 : 1750473 : if (m_can_restore)
135 : : {
136 : 6559 : char *equals = strchr (const_cast <char *> (string), '=');
137 : 6559 : gcc_assert (equals);
138 : :
139 : 6559 : struct kv kv;
140 : 6559 : kv.m_key = xstrndup (string, equals - string);
141 : 6559 : const char *cur_value = ::getenv (kv.m_key);
142 : 6559 : if (m_debug)
143 : 0 : fprintf (stderr, "saving old value: %s\n",cur_value);
144 : 6559 : kv.m_value = cur_value ? xstrdup (cur_value) : NULL;
145 : 6559 : m_keys.safe_push (kv);
146 : : }
147 : :
148 : 1750473 : ::putenv (CONST_CAST (char *, string));
149 : 1750473 : }
150 : :
151 : : /* Undo any xputenv changes made since last restore.
152 : : Can only be called if the env_manager was initialized with
153 : : CAN_RESTORE enabled. */
154 : :
155 : : void
156 : 1094 : env_manager::restore ()
157 : : {
158 : 1094 : unsigned int i;
159 : 1094 : struct kv *item;
160 : :
161 : 1094 : gcc_assert (m_can_restore);
162 : :
163 : 8747 : FOR_EACH_VEC_ELT_REVERSE (m_keys, i, item)
164 : : {
165 : 6559 : if (m_debug)
166 : 0 : printf ("restoring saved key: %s value: %s\n", item->m_key, item->m_value);
167 : 6559 : if (item->m_value)
168 : 3277 : ::setenv (item->m_key, item->m_value, 1);
169 : : else
170 : 3282 : ::unsetenv (item->m_key);
171 : 6559 : free (item->m_key);
172 : 6559 : free (item->m_value);
173 : : }
174 : :
175 : 1094 : m_keys.truncate (0);
176 : 1094 : }
177 : :
178 : : /* Forbid other uses of getenv and putenv. */
179 : : #if (GCC_VERSION >= 3000)
180 : : #pragma GCC poison getenv putenv
181 : : #endif
182 : :
183 : :
184 : :
185 : : /* By default there is no special suffix for target executables. */
186 : : #ifdef TARGET_EXECUTABLE_SUFFIX
187 : : #define HAVE_TARGET_EXECUTABLE_SUFFIX
188 : : #else
189 : : #define TARGET_EXECUTABLE_SUFFIX ""
190 : : #endif
191 : :
192 : : /* By default there is no special suffix for host executables. */
193 : : #ifdef HOST_EXECUTABLE_SUFFIX
194 : : #define HAVE_HOST_EXECUTABLE_SUFFIX
195 : : #else
196 : : #define HOST_EXECUTABLE_SUFFIX ""
197 : : #endif
198 : :
199 : : /* By default, the suffix for target object files is ".o". */
200 : : #ifdef TARGET_OBJECT_SUFFIX
201 : : #define HAVE_TARGET_OBJECT_SUFFIX
202 : : #else
203 : : #define TARGET_OBJECT_SUFFIX ".o"
204 : : #endif
205 : :
206 : : static const char dir_separator_str[] = { DIR_SEPARATOR, 0 };
207 : :
208 : : /* Most every one is fine with LIBRARY_PATH. For some, it conflicts. */
209 : : #ifndef LIBRARY_PATH_ENV
210 : : #define LIBRARY_PATH_ENV "LIBRARY_PATH"
211 : : #endif
212 : :
213 : : /* If a stage of compilation returns an exit status >= 1,
214 : : compilation of that file ceases. */
215 : :
216 : : #define MIN_FATAL_STATUS 1
217 : :
218 : : /* Flag set by cppspec.cc to 1. */
219 : : int is_cpp_driver;
220 : :
221 : : /* Flag set to nonzero if an @file argument has been supplied to gcc. */
222 : : static bool at_file_supplied;
223 : :
224 : : /* Definition of string containing the arguments given to configure. */
225 : : #include "configargs.h"
226 : :
227 : : /* Flag saying to print the command line options understood by gcc and its
228 : : sub-processes. */
229 : :
230 : : static int print_help_list;
231 : :
232 : : /* Flag saying to print the version of gcc and its sub-processes. */
233 : :
234 : : static int print_version;
235 : :
236 : : /* Flag that stores string prefix for which we provide bash completion. */
237 : :
238 : : static const char *completion = NULL;
239 : :
240 : : /* Flag indicating whether we should ONLY print the command and
241 : : arguments (like verbose_flag) without executing the command.
242 : : Displayed arguments are quoted so that the generated command
243 : : line is suitable for execution. This is intended for use in
244 : : shell scripts to capture the driver-generated command line. */
245 : : static int verbose_only_flag;
246 : :
247 : : /* Flag indicating how to print command line options of sub-processes. */
248 : :
249 : : static int print_subprocess_help;
250 : :
251 : : /* Linker suffix passed to -fuse-ld=... */
252 : : static const char *use_ld;
253 : :
254 : : /* Whether we should report subprocess execution times to a file. */
255 : :
256 : : FILE *report_times_to_file = NULL;
257 : :
258 : : /* Nonzero means place this string before uses of /, so that include
259 : : and library files can be found in an alternate location. */
260 : :
261 : : #ifdef TARGET_SYSTEM_ROOT
262 : : #define DEFAULT_TARGET_SYSTEM_ROOT (TARGET_SYSTEM_ROOT)
263 : : #else
264 : : #define DEFAULT_TARGET_SYSTEM_ROOT (0)
265 : : #endif
266 : : static const char *target_system_root = DEFAULT_TARGET_SYSTEM_ROOT;
267 : :
268 : : /* Nonzero means pass the updated target_system_root to the compiler. */
269 : :
270 : : static int target_system_root_changed;
271 : :
272 : : /* Nonzero means append this string to target_system_root. */
273 : :
274 : : static const char *target_sysroot_suffix = 0;
275 : :
276 : : /* Nonzero means append this string to target_system_root for headers. */
277 : :
278 : : static const char *target_sysroot_hdrs_suffix = 0;
279 : :
280 : : /* Nonzero means write "temp" files in source directory
281 : : and use the source file's name in them, and don't delete them. */
282 : :
283 : : static enum save_temps {
284 : : SAVE_TEMPS_NONE, /* no -save-temps */
285 : : SAVE_TEMPS_CWD, /* -save-temps in current directory */
286 : : SAVE_TEMPS_DUMP, /* -save-temps in dumpdir */
287 : : SAVE_TEMPS_OBJ /* -save-temps in object directory */
288 : : } save_temps_flag;
289 : :
290 : : /* Set this iff the dumppfx implied by a -save-temps=* option is to
291 : : override a -dumpdir option, if any. */
292 : : static bool save_temps_overrides_dumpdir = false;
293 : :
294 : : /* -dumpdir, -dumpbase and -dumpbase-ext flags passed in, possibly
295 : : rearranged as they are to be passed down, e.g., dumpbase and
296 : : dumpbase_ext may be cleared if integrated with dumpdir or
297 : : dropped. */
298 : : static char *dumpdir, *dumpbase, *dumpbase_ext;
299 : :
300 : : /* Usually the length of the string in dumpdir. However, during
301 : : linking, it may be shortened to omit a driver-added trailing dash,
302 : : by then replaced with a trailing period, that is still to be passed
303 : : to sub-processes in -dumpdir, but not to be generally used in spec
304 : : filename expansions. See maybe_run_linker. */
305 : : static size_t dumpdir_length = 0;
306 : :
307 : : /* Set if the last character in dumpdir is (or was) a dash that the
308 : : driver added to dumpdir after dumpbase or linker output name. */
309 : : static bool dumpdir_trailing_dash_added = false;
310 : :
311 : : /* True if -r, -shared, -pie, -no-pie, -z lazy, or -z norelro were
312 : : specified on the command line, and therefore -fhardened should not
313 : : add -z now/relro. */
314 : : static bool avoid_linker_hardening_p;
315 : :
316 : : /* True if -static was specified on the command line. */
317 : : static bool static_p;
318 : :
319 : : /* Basename of dump and aux outputs, computed from dumpbase (given or
320 : : derived from output name), to override input_basename in non-%w %b
321 : : et al. */
322 : : static char *outbase;
323 : : static size_t outbase_length = 0;
324 : :
325 : : /* The compiler version. */
326 : :
327 : : static const char *compiler_version;
328 : :
329 : : /* The target version. */
330 : :
331 : : static const char *const spec_version = DEFAULT_TARGET_VERSION;
332 : :
333 : : /* The target machine. */
334 : :
335 : : static const char *spec_machine = DEFAULT_TARGET_MACHINE;
336 : : static const char *spec_host_machine = DEFAULT_REAL_TARGET_MACHINE;
337 : :
338 : : /* List of offload targets. Separated by colon. Empty string for
339 : : -foffload=disable. */
340 : :
341 : : static char *offload_targets = NULL;
342 : :
343 : : #if OFFLOAD_DEFAULTED
344 : : /* Set to true if -foffload has not been used and offload_targets
345 : : is set to the configured in default. */
346 : : static bool offload_targets_default;
347 : : #endif
348 : :
349 : : /* Nonzero if cross-compiling.
350 : : When -b is used, the value comes from the `specs' file. */
351 : :
352 : : #ifdef CROSS_DIRECTORY_STRUCTURE
353 : : static const char *cross_compile = "1";
354 : : #else
355 : : static const char *cross_compile = "0";
356 : : #endif
357 : :
358 : : /* Greatest exit code of sub-processes that has been encountered up to
359 : : now. */
360 : : static int greatest_status = 1;
361 : :
362 : : /* This is the obstack which we use to allocate many strings. */
363 : :
364 : : static struct obstack obstack;
365 : :
366 : : /* This is the obstack to build an environment variable to pass to
367 : : collect2 that describes all of the relevant switches of what to
368 : : pass the compiler in building the list of pointers to constructors
369 : : and destructors. */
370 : :
371 : : static struct obstack collect_obstack;
372 : :
373 : : /* Forward declaration for prototypes. */
374 : : struct path_prefix;
375 : : struct prefix_list;
376 : :
377 : : static void init_spec (void);
378 : : static void store_arg (const char *, int, int);
379 : : static void insert_wrapper (const char *);
380 : : static char *load_specs (const char *);
381 : : static void read_specs (const char *, bool, bool);
382 : : static void set_spec (const char *, const char *, bool);
383 : : static struct compiler *lookup_compiler (const char *, size_t, const char *);
384 : : static char *build_search_list (const struct path_prefix *, const char *,
385 : : bool, bool);
386 : : static void xputenv (const char *);
387 : : static void putenv_from_prefixes (const struct path_prefix *, const char *,
388 : : bool);
389 : : static int access_check (const char *, int);
390 : : static char *find_a_file (const struct path_prefix *, const char *, int, bool);
391 : : static char *find_a_program (const char *);
392 : : static void add_prefix (struct path_prefix *, const char *, const char *,
393 : : int, int, int);
394 : : static void add_sysrooted_prefix (struct path_prefix *, const char *,
395 : : const char *, int, int, int);
396 : : static char *skip_whitespace (char *);
397 : : static void delete_if_ordinary (const char *);
398 : : static void delete_temp_files (void);
399 : : static void delete_failure_queue (void);
400 : : static void clear_failure_queue (void);
401 : : static int check_live_switch (int, int);
402 : : static const char *handle_braces (const char *);
403 : : static inline bool input_suffix_matches (const char *, const char *);
404 : : static inline bool switch_matches (const char *, const char *, int);
405 : : static inline void mark_matching_switches (const char *, const char *, int);
406 : : static inline void process_marked_switches (void);
407 : : static const char *process_brace_body (const char *, const char *, const char *, int, int);
408 : : static const struct spec_function *lookup_spec_function (const char *);
409 : : static const char *eval_spec_function (const char *, const char *, const char *);
410 : : static const char *handle_spec_function (const char *, bool *, const char *);
411 : : static char *save_string (const char *, int);
412 : : static void set_collect_gcc_options (void);
413 : : static int do_spec_1 (const char *, int, const char *);
414 : : static int do_spec_2 (const char *, const char *);
415 : : static void do_option_spec (const char *, const char *);
416 : : static void do_self_spec (const char *);
417 : : static const char *find_file (const char *);
418 : : static int is_directory (const char *);
419 : : static const char *validate_switches (const char *, bool, bool);
420 : : static void validate_all_switches (void);
421 : : static inline void validate_switches_from_spec (const char *, bool);
422 : : static void give_switch (int, int);
423 : : static int default_arg (const char *, int);
424 : : static void set_multilib_dir (void);
425 : : static void print_multilib_info (void);
426 : : static void display_help (void);
427 : : static void add_preprocessor_option (const char *, int);
428 : : static void add_assembler_option (const char *, int);
429 : : static void add_linker_option (const char *, int);
430 : : static void process_command (unsigned int, struct cl_decoded_option *);
431 : : static int execute (void);
432 : : static void alloc_args (void);
433 : : static void clear_args (void);
434 : : static void fatal_signal (int);
435 : : #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC)
436 : : static void init_gcc_specs (struct obstack *, const char *, const char *,
437 : : const char *);
438 : : #endif
439 : : #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
440 : : static const char *convert_filename (const char *, int, int);
441 : : #endif
442 : :
443 : : static void try_generate_repro (const char **argv);
444 : : static const char *getenv_spec_function (int, const char **);
445 : : static const char *if_exists_spec_function (int, const char **);
446 : : static const char *if_exists_else_spec_function (int, const char **);
447 : : static const char *if_exists_then_else_spec_function (int, const char **);
448 : : static const char *sanitize_spec_function (int, const char **);
449 : : static const char *replace_outfile_spec_function (int, const char **);
450 : : static const char *remove_outfile_spec_function (int, const char **);
451 : : static const char *version_compare_spec_function (int, const char **);
452 : : static const char *include_spec_function (int, const char **);
453 : : static const char *find_file_spec_function (int, const char **);
454 : : static const char *find_plugindir_spec_function (int, const char **);
455 : : static const char *print_asm_header_spec_function (int, const char **);
456 : : static const char *compare_debug_dump_opt_spec_function (int, const char **);
457 : : static const char *compare_debug_self_opt_spec_function (int, const char **);
458 : : static const char *pass_through_libs_spec_func (int, const char **);
459 : : static const char *dumps_spec_func (int, const char **);
460 : : static const char *greater_than_spec_func (int, const char **);
461 : : static const char *debug_level_greater_than_spec_func (int, const char **);
462 : : static const char *dwarf_version_greater_than_spec_func (int, const char **);
463 : : static const char *find_fortran_preinclude_file (int, const char **);
464 : : static const char *join_spec_func (int, const char **);
465 : : static char *convert_white_space (char *);
466 : : static char *quote_spec (char *);
467 : : static char *quote_spec_arg (char *);
468 : : static bool not_actual_file_p (const char *);
469 : :
470 : :
471 : : /* The Specs Language
472 : :
473 : : Specs are strings containing lines, each of which (if not blank)
474 : : is made up of a program name, and arguments separated by spaces.
475 : : The program name must be exact and start from root, since no path
476 : : is searched and it is unreliable to depend on the current working directory.
477 : : Redirection of input or output is not supported; the subprograms must
478 : : accept filenames saying what files to read and write.
479 : :
480 : : In addition, the specs can contain %-sequences to substitute variable text
481 : : or for conditional text. Here is a table of all defined %-sequences.
482 : : Note that spaces are not generated automatically around the results of
483 : : expanding these sequences; therefore, you can concatenate them together
484 : : or with constant text in a single argument.
485 : :
486 : : %% substitute one % into the program name or argument.
487 : : %" substitute an empty argument.
488 : : %i substitute the name of the input file being processed.
489 : : %b substitute the basename for outputs related with the input file
490 : : being processed. This is often a substring of the input file name,
491 : : up to (and not including) the last period but, unless %w is active,
492 : : it is affected by the directory selected by -save-temps=*, by
493 : : -dumpdir, and, in case of multiple compilations, even by -dumpbase
494 : : and -dumpbase-ext and, in case of linking, by the linker output
495 : : name. When %w is active, it derives the main output name only from
496 : : the input file base name; when it is not, it names aux/dump output
497 : : file.
498 : : %B same as %b, but include the input file suffix (text after the last
499 : : period).
500 : : %gSUFFIX
501 : : substitute a file name that has suffix SUFFIX and is chosen
502 : : once per compilation, and mark the argument a la %d. To reduce
503 : : exposure to denial-of-service attacks, the file name is now
504 : : chosen in a way that is hard to predict even when previously
505 : : chosen file names are known. For example, `%g.s ... %g.o ... %g.s'
506 : : might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches
507 : : the regexp "[.0-9A-Za-z]*%O"; "%O" is treated exactly as if it
508 : : had been pre-processed. Previously, %g was simply substituted
509 : : with a file name chosen once per compilation, without regard
510 : : to any appended suffix (which was therefore treated just like
511 : : ordinary text), making such attacks more likely to succeed.
512 : : %|SUFFIX
513 : : like %g, but if -pipe is in effect, expands simply to "-".
514 : : %mSUFFIX
515 : : like %g, but if -pipe is in effect, expands to nothing. (We have both
516 : : %| and %m to accommodate differences between system assemblers; see
517 : : the AS_NEEDS_DASH_FOR_PIPED_INPUT target macro.)
518 : : %uSUFFIX
519 : : like %g, but generates a new temporary file name even if %uSUFFIX
520 : : was already seen.
521 : : %USUFFIX
522 : : substitutes the last file name generated with %uSUFFIX, generating a
523 : : new one if there is no such last file name. In the absence of any
524 : : %uSUFFIX, this is just like %gSUFFIX, except they don't share
525 : : the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s'
526 : : would involve the generation of two distinct file names, one
527 : : for each `%g.s' and another for each `%U.s'. Previously, %U was
528 : : simply substituted with a file name chosen for the previous %u,
529 : : without regard to any appended suffix.
530 : : %jSUFFIX
531 : : substitutes the name of the HOST_BIT_BUCKET, if any, and if it is
532 : : writable, and if save-temps is off; otherwise, substitute the name
533 : : of a temporary file, just like %u. This temporary file is not
534 : : meant for communication between processes, but rather as a junk
535 : : disposal mechanism.
536 : : %.SUFFIX
537 : : substitutes .SUFFIX for the suffixes of a matched switch's args when
538 : : it is subsequently output with %*. SUFFIX is terminated by the next
539 : : space or %.
540 : : %d marks the argument containing or following the %d as a
541 : : temporary file name, so that file will be deleted if GCC exits
542 : : successfully. Unlike %g, this contributes no text to the argument.
543 : : %w marks the argument containing or following the %w as the
544 : : "output file" of this compilation. This puts the argument
545 : : into the sequence of arguments that %o will substitute later.
546 : : %V indicates that this compilation produces no "output file".
547 : : %W{...}
548 : : like %{...} but marks the last argument supplied within as a file
549 : : to be deleted on failure.
550 : : %@{...}
551 : : like %{...} but puts the result into a FILE and substitutes @FILE
552 : : if an @file argument has been supplied.
553 : : %o substitutes the names of all the output files, with spaces
554 : : automatically placed around them. You should write spaces
555 : : around the %o as well or the results are undefined.
556 : : %o is for use in the specs for running the linker.
557 : : Input files whose names have no recognized suffix are not compiled
558 : : at all, but they are included among the output files, so they will
559 : : be linked.
560 : : %O substitutes the suffix for object files. Note that this is
561 : : handled specially when it immediately follows %g, %u, or %U
562 : : (with or without a suffix argument) because of the need for
563 : : those to form complete file names. The handling is such that
564 : : %O is treated exactly as if it had already been substituted,
565 : : except that %g, %u, and %U do not currently support additional
566 : : SUFFIX characters following %O as they would following, for
567 : : example, `.o'.
568 : : %I Substitute any of -iprefix (made from GCC_EXEC_PREFIX), -isysroot
569 : : (made from TARGET_SYSTEM_ROOT), -isystem (made from COMPILER_PATH
570 : : and -B options) and -imultilib as necessary.
571 : : %s current argument is the name of a library or startup file of some sort.
572 : : Search for that file in a standard list of directories
573 : : and substitute the full name found.
574 : : %T current argument is the name of a linker script.
575 : : Search for that file in the current list of directories to scan for
576 : : libraries. If the file is located, insert a --script option into the
577 : : command line followed by the full path name found. If the file is
578 : : not found then generate an error message.
579 : : Note: the current working directory is not searched.
580 : : %eSTR Print STR as an error message. STR is terminated by a newline.
581 : : Use this when inconsistent options are detected.
582 : : %nSTR Print STR as a notice. STR is terminated by a newline.
583 : : %x{OPTION} Accumulate an option for %X.
584 : : %X Output the accumulated linker options specified by compilations.
585 : : %Y Output the accumulated assembler options specified by compilations.
586 : : %Z Output the accumulated preprocessor options specified by compilations.
587 : : %a process ASM_SPEC as a spec.
588 : : This allows config.h to specify part of the spec for running as.
589 : : %A process ASM_FINAL_SPEC as a spec. A capital A is actually
590 : : used here. This can be used to run a post-processor after the
591 : : assembler has done its job.
592 : : %D Dump out a -L option for each directory in startfile_prefixes.
593 : : If multilib_dir is set, extra entries are generated with it affixed.
594 : : %l process LINK_SPEC as a spec.
595 : : %L process LIB_SPEC as a spec.
596 : : %M Output multilib_os_dir.
597 : : %P Output a RUNPATH_OPTION for each directory in startfile_prefixes.
598 : : %G process LIBGCC_SPEC as a spec.
599 : : %R Output the concatenation of target_system_root and
600 : : target_sysroot_suffix.
601 : : %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
602 : : %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
603 : : %C process CPP_SPEC as a spec.
604 : : %1 process CC1_SPEC as a spec.
605 : : %2 process CC1PLUS_SPEC as a spec.
606 : : %* substitute the variable part of a matched option. (See below.)
607 : : Note that each comma in the substituted string is replaced by
608 : : a single space. A space is appended after the last substition
609 : : unless there is more text in current sequence.
610 : : %<S remove all occurrences of -S from the command line.
611 : : Note - this command is position dependent. % commands in the
612 : : spec string before this one will see -S, % commands in the
613 : : spec string after this one will not.
614 : : %>S Similar to "%<S", but keep it in the GCC command line.
615 : : %<S* remove all occurrences of all switches beginning with -S from the
616 : : command line.
617 : : %:function(args)
618 : : Call the named function FUNCTION, passing it ARGS. ARGS is
619 : : first processed as a nested spec string, then split into an
620 : : argument vector in the usual fashion. The function returns
621 : : a string which is processed as if it had appeared literally
622 : : as part of the current spec.
623 : : %{S} substitutes the -S switch, if that switch was given to GCC.
624 : : If that switch was not specified, this substitutes nothing.
625 : : Here S is a metasyntactic variable.
626 : : %{S*} substitutes all the switches specified to GCC whose names start
627 : : with -S. This is used for -o, -I, etc; switches that take
628 : : arguments. GCC considers `-o foo' as being one switch whose
629 : : name starts with `o'. %{o*} would substitute this text,
630 : : including the space; thus, two arguments would be generated.
631 : : %{S*&T*} likewise, but preserve order of S and T options (the order
632 : : of S and T in the spec is not significant). Can be any number
633 : : of ampersand-separated variables; for each the wild card is
634 : : optional. Useful for CPP as %{D*&U*&A*}.
635 : :
636 : : %{S:X} substitutes X, if the -S switch was given to GCC.
637 : : %{!S:X} substitutes X, if the -S switch was NOT given to GCC.
638 : : %{S*:X} substitutes X if one or more switches whose names start
639 : : with -S was given to GCC. Normally X is substituted only
640 : : once, no matter how many such switches appeared. However,
641 : : if %* appears somewhere in X, then X will be substituted
642 : : once for each matching switch, with the %* replaced by the
643 : : part of that switch that matched the '*'. A space will be
644 : : appended after the last substition unless there is more
645 : : text in current sequence.
646 : : %{.S:X} substitutes X, if processing a file with suffix S.
647 : : %{!.S:X} substitutes X, if NOT processing a file with suffix S.
648 : : %{,S:X} substitutes X, if processing a file which will use spec S.
649 : : %{!,S:X} substitutes X, if NOT processing a file which will use spec S.
650 : :
651 : : %{S|T:X} substitutes X if either -S or -T was given to GCC. This may be
652 : : combined with '!', '.', ',', and '*' as above binding stronger
653 : : than the OR.
654 : : If %* appears in X, all of the alternatives must be starred, and
655 : : only the first matching alternative is substituted.
656 : : %{%:function(args):X}
657 : : Call function named FUNCTION with args ARGS. If the function
658 : : returns non-NULL, then X is substituted, if it returns
659 : : NULL, it isn't substituted.
660 : : %{S:X; if S was given to GCC, substitutes X;
661 : : T:Y; else if T was given to GCC, substitutes Y;
662 : : :D} else substitutes D. There can be as many clauses as you need.
663 : : This may be combined with '.', '!', ',', '|', and '*' as above.
664 : :
665 : : %(Spec) processes a specification defined in a specs file as *Spec:
666 : :
667 : : The switch matching text S in a %{S}, %{S:X}, or similar construct can use
668 : : a backslash to ignore the special meaning of the character following it,
669 : : thus allowing literal matching of a character that is otherwise specially
670 : : treated. For example, %{std=iso9899\:1999:X} substitutes X if the
671 : : -std=iso9899:1999 option is given.
672 : :
673 : : The conditional text X in a %{S:X} or similar construct may contain
674 : : other nested % constructs or spaces, or even newlines. They are
675 : : processed as usual, as described above. Trailing white space in X is
676 : : ignored. White space may also appear anywhere on the left side of the
677 : : colon in these constructs, except between . or * and the corresponding
678 : : word.
679 : :
680 : : The -O, -f, -g, -m, and -W switches are handled specifically in these
681 : : constructs. If another value of -O or the negated form of a -f, -m, or
682 : : -W switch is found later in the command line, the earlier switch
683 : : value is ignored, except with {S*} where S is just one letter; this
684 : : passes all matching options.
685 : :
686 : : The character | at the beginning of the predicate text is used to indicate
687 : : that a command should be piped to the following command, but only if -pipe
688 : : is specified.
689 : :
690 : : Note that it is built into GCC which switches take arguments and which
691 : : do not. You might think it would be useful to generalize this to
692 : : allow each compiler's spec to say which switches take arguments. But
693 : : this cannot be done in a consistent fashion. GCC cannot even decide
694 : : which input files have been specified without knowing which switches
695 : : take arguments, and it must know which input files to compile in order
696 : : to tell which compilers to run.
697 : :
698 : : GCC also knows implicitly that arguments starting in `-l' are to be
699 : : treated as compiler output files, and passed to the linker in their
700 : : proper position among the other output files. */
701 : :
702 : : /* Define the macros used for specs %a, %l, %L, %S, %C, %1. */
703 : :
704 : : /* config.h can define ASM_SPEC to provide extra args to the assembler
705 : : or extra switch-translations. */
706 : : #ifndef ASM_SPEC
707 : : #define ASM_SPEC ""
708 : : #endif
709 : :
710 : : /* config.h can define ASM_FINAL_SPEC to run a post processor after
711 : : the assembler has run. */
712 : : #ifndef ASM_FINAL_SPEC
713 : : #define ASM_FINAL_SPEC \
714 : : "%{gsplit-dwarf: \n\
715 : : objcopy --extract-dwo \
716 : : %{c:%{o*:%*}%{!o*:%w%b%O}}%{!c:%U%O} \
717 : : %b.dwo \n\
718 : : objcopy --strip-dwo \
719 : : %{c:%{o*:%*}%{!o*:%w%b%O}}%{!c:%U%O} \
720 : : }"
721 : : #endif
722 : :
723 : : /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
724 : : or extra switch-translations. */
725 : : #ifndef CPP_SPEC
726 : : #define CPP_SPEC ""
727 : : #endif
728 : :
729 : : /* Operating systems can define OS_CC1_SPEC to provide extra args to cc1 and
730 : : cc1plus or extra switch-translations. The OS_CC1_SPEC is appended
731 : : to CC1_SPEC in the initialization of cc1_spec. */
732 : : #ifndef OS_CC1_SPEC
733 : : #define OS_CC1_SPEC ""
734 : : #endif
735 : :
736 : : /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
737 : : or extra switch-translations. */
738 : : #ifndef CC1_SPEC
739 : : #define CC1_SPEC ""
740 : : #endif
741 : :
742 : : /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
743 : : or extra switch-translations. */
744 : : #ifndef CC1PLUS_SPEC
745 : : #define CC1PLUS_SPEC ""
746 : : #endif
747 : :
748 : : /* config.h can define LINK_SPEC to provide extra args to the linker
749 : : or extra switch-translations. */
750 : : #ifndef LINK_SPEC
751 : : #define LINK_SPEC ""
752 : : #endif
753 : :
754 : : /* config.h can define LIB_SPEC to override the default libraries. */
755 : : #ifndef LIB_SPEC
756 : : #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
757 : : #endif
758 : :
759 : : /* When using -fsplit-stack we need to wrap pthread_create, in order
760 : : to initialize the stack guard. We always use wrapping, rather than
761 : : shared library ordering, and we keep the wrapper function in
762 : : libgcc. This is not yet a real spec, though it could become one;
763 : : it is currently just stuffed into LINK_SPEC. FIXME: This wrapping
764 : : only works with GNU ld and gold. */
765 : : #ifdef HAVE_GOLD_NON_DEFAULT_SPLIT_STACK
766 : : #define STACK_SPLIT_SPEC " %{fsplit-stack: -fuse-ld=gold --wrap=pthread_create}"
767 : : #else
768 : : #define STACK_SPLIT_SPEC " %{fsplit-stack: --wrap=pthread_create}"
769 : : #endif
770 : :
771 : : #ifndef LIBASAN_SPEC
772 : : #define STATIC_LIBASAN_LIBS \
773 : : " %{static-libasan|static:%:include(libsanitizer.spec)%(link_libasan)}"
774 : : #ifdef LIBASAN_EARLY_SPEC
775 : : #define LIBASAN_SPEC STATIC_LIBASAN_LIBS
776 : : #elif defined(HAVE_LD_STATIC_DYNAMIC)
777 : : #define LIBASAN_SPEC "%{static-libasan:" LD_STATIC_OPTION \
778 : : "} -lasan %{static-libasan:" LD_DYNAMIC_OPTION "}" \
779 : : STATIC_LIBASAN_LIBS
780 : : #else
781 : : #define LIBASAN_SPEC "-lasan" STATIC_LIBASAN_LIBS
782 : : #endif
783 : : #endif
784 : :
785 : : #ifndef LIBASAN_EARLY_SPEC
786 : : #define LIBASAN_EARLY_SPEC ""
787 : : #endif
788 : :
789 : : #ifndef LIBHWASAN_SPEC
790 : : #define STATIC_LIBHWASAN_LIBS \
791 : : " %{static-libhwasan|static:%:include(libsanitizer.spec)%(link_libhwasan)}"
792 : : #ifdef LIBHWASAN_EARLY_SPEC
793 : : #define LIBHWASAN_SPEC STATIC_LIBHWASAN_LIBS
794 : : #elif defined(HAVE_LD_STATIC_DYNAMIC)
795 : : #define LIBHWASAN_SPEC "%{static-libhwasan:" LD_STATIC_OPTION \
796 : : "} -lhwasan %{static-libhwasan:" LD_DYNAMIC_OPTION "}" \
797 : : STATIC_LIBHWASAN_LIBS
798 : : #else
799 : : #define LIBHWASAN_SPEC "-lhwasan" STATIC_LIBHWASAN_LIBS
800 : : #endif
801 : : #endif
802 : :
803 : : #ifndef LIBHWASAN_EARLY_SPEC
804 : : #define LIBHWASAN_EARLY_SPEC ""
805 : : #endif
806 : :
807 : : #ifndef LIBTSAN_SPEC
808 : : #define STATIC_LIBTSAN_LIBS \
809 : : " %{static-libtsan|static:%:include(libsanitizer.spec)%(link_libtsan)}"
810 : : #ifdef LIBTSAN_EARLY_SPEC
811 : : #define LIBTSAN_SPEC STATIC_LIBTSAN_LIBS
812 : : #elif defined(HAVE_LD_STATIC_DYNAMIC)
813 : : #define LIBTSAN_SPEC "%{static-libtsan:" LD_STATIC_OPTION \
814 : : "} -ltsan %{static-libtsan:" LD_DYNAMIC_OPTION "}" \
815 : : STATIC_LIBTSAN_LIBS
816 : : #else
817 : : #define LIBTSAN_SPEC "-ltsan" STATIC_LIBTSAN_LIBS
818 : : #endif
819 : : #endif
820 : :
821 : : #ifndef LIBTSAN_EARLY_SPEC
822 : : #define LIBTSAN_EARLY_SPEC ""
823 : : #endif
824 : :
825 : : #ifndef LIBLSAN_SPEC
826 : : #define STATIC_LIBLSAN_LIBS \
827 : : " %{static-liblsan|static:%:include(libsanitizer.spec)%(link_liblsan)}"
828 : : #ifdef LIBLSAN_EARLY_SPEC
829 : : #define LIBLSAN_SPEC STATIC_LIBLSAN_LIBS
830 : : #elif defined(HAVE_LD_STATIC_DYNAMIC)
831 : : #define LIBLSAN_SPEC "%{static-liblsan:" LD_STATIC_OPTION \
832 : : "} -llsan %{static-liblsan:" LD_DYNAMIC_OPTION "}" \
833 : : STATIC_LIBLSAN_LIBS
834 : : #else
835 : : #define LIBLSAN_SPEC "-llsan" STATIC_LIBLSAN_LIBS
836 : : #endif
837 : : #endif
838 : :
839 : : #ifndef LIBLSAN_EARLY_SPEC
840 : : #define LIBLSAN_EARLY_SPEC ""
841 : : #endif
842 : :
843 : : #ifndef LIBUBSAN_SPEC
844 : : #define STATIC_LIBUBSAN_LIBS \
845 : : " %{static-libubsan|static:%:include(libsanitizer.spec)%(link_libubsan)}"
846 : : #ifdef HAVE_LD_STATIC_DYNAMIC
847 : : #define LIBUBSAN_SPEC "%{static-libubsan:" LD_STATIC_OPTION \
848 : : "} -lubsan %{static-libubsan:" LD_DYNAMIC_OPTION "}" \
849 : : STATIC_LIBUBSAN_LIBS
850 : : #else
851 : : #define LIBUBSAN_SPEC "-lubsan" STATIC_LIBUBSAN_LIBS
852 : : #endif
853 : : #endif
854 : :
855 : : /* Linker options for compressed debug sections. */
856 : : #if HAVE_LD_COMPRESS_DEBUG == 0
857 : : /* No linker support. */
858 : : #define LINK_COMPRESS_DEBUG_SPEC \
859 : : " %{gz*:%e-gz is not supported in this configuration} "
860 : : #elif HAVE_LD_COMPRESS_DEBUG == 1
861 : : /* ELF gABI style. */
862 : : #define LINK_COMPRESS_DEBUG_SPEC \
863 : : " %{gz|gz=zlib:" LD_COMPRESS_DEBUG_OPTION "=zlib}" \
864 : : " %{gz=none:" LD_COMPRESS_DEBUG_OPTION "=none}" \
865 : : " %{gz=zstd:%e-gz=zstd is not supported in this configuration} " \
866 : : " %{gz=zlib-gnu:}" /* Ignore silently zlib-gnu option value. */
867 : : #elif HAVE_LD_COMPRESS_DEBUG == 2
868 : : /* ELF gABI style and ZSTD. */
869 : : #define LINK_COMPRESS_DEBUG_SPEC \
870 : : " %{gz|gz=zlib:" LD_COMPRESS_DEBUG_OPTION "=zlib}" \
871 : : " %{gz=none:" LD_COMPRESS_DEBUG_OPTION "=none}" \
872 : : " %{gz=zstd:" LD_COMPRESS_DEBUG_OPTION "=zstd}" \
873 : : " %{gz=zlib-gnu:}" /* Ignore silently zlib-gnu option value. */
874 : : #else
875 : : #error Unknown value for HAVE_LD_COMPRESS_DEBUG.
876 : : #endif
877 : :
878 : : /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
879 : : included. */
880 : : #ifndef LIBGCC_SPEC
881 : : #if defined(REAL_LIBGCC_SPEC)
882 : : #define LIBGCC_SPEC REAL_LIBGCC_SPEC
883 : : #elif defined(LINK_LIBGCC_SPECIAL_1)
884 : : /* Have gcc do the search for libgcc.a. */
885 : : #define LIBGCC_SPEC "libgcc.a%s"
886 : : #else
887 : : #define LIBGCC_SPEC "-lgcc"
888 : : #endif
889 : : #endif
890 : :
891 : : /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
892 : : #ifndef STARTFILE_SPEC
893 : : #define STARTFILE_SPEC \
894 : : "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
895 : : #endif
896 : :
897 : : /* config.h can define ENDFILE_SPEC to override the default crtn files. */
898 : : #ifndef ENDFILE_SPEC
899 : : #define ENDFILE_SPEC ""
900 : : #endif
901 : :
902 : : #ifndef LINKER_NAME
903 : : #define LINKER_NAME "collect2"
904 : : #endif
905 : :
906 : : #ifdef HAVE_AS_DEBUG_PREFIX_MAP
907 : : #define ASM_MAP " %{ffile-prefix-map=*:--debug-prefix-map %*} %{fdebug-prefix-map=*:--debug-prefix-map %*}"
908 : : #else
909 : : #define ASM_MAP ""
910 : : #endif
911 : :
912 : : /* Assembler options for compressed debug sections. */
913 : : #if HAVE_LD_COMPRESS_DEBUG == 0
914 : : /* Reject if the linker cannot write compressed debug sections. */
915 : : #define ASM_COMPRESS_DEBUG_SPEC \
916 : : " %{gz*:%e-gz is not supported in this configuration} "
917 : : #else /* HAVE_LD_COMPRESS_DEBUG >= 1 */
918 : : #if HAVE_AS_COMPRESS_DEBUG == 0
919 : : /* No assembler support. Ignore silently. */
920 : : #define ASM_COMPRESS_DEBUG_SPEC \
921 : : " %{gz*:} "
922 : : #elif HAVE_AS_COMPRESS_DEBUG == 1
923 : : /* ELF gABI style. */
924 : : #define ASM_COMPRESS_DEBUG_SPEC \
925 : : " %{gz|gz=zlib:" AS_COMPRESS_DEBUG_OPTION "=zlib}" \
926 : : " %{gz=none:" AS_COMPRESS_DEBUG_OPTION "=none}" \
927 : : " %{gz=zlib-gnu:}" /* Ignore silently zlib-gnu option value. */
928 : : #elif HAVE_AS_COMPRESS_DEBUG == 2
929 : : /* ELF gABI style and ZSTD. */
930 : : #define ASM_COMPRESS_DEBUG_SPEC \
931 : : " %{gz|gz=zlib:" AS_COMPRESS_DEBUG_OPTION "=zlib}" \
932 : : " %{gz=none:" AS_COMPRESS_DEBUG_OPTION "=none}" \
933 : : " %{gz=zstd:" AS_COMPRESS_DEBUG_OPTION "=zstd}" \
934 : : " %{gz=zlib-gnu:}" /* Ignore silently zlib-gnu option value. */
935 : : #else
936 : : #error Unknown value for HAVE_AS_COMPRESS_DEBUG.
937 : : #endif
938 : : #endif /* HAVE_LD_COMPRESS_DEBUG >= 1 */
939 : :
940 : : /* Define ASM_DEBUG_SPEC to be a spec suitable for translating '-g'
941 : : to the assembler, when compiling assembly sources only. */
942 : : #ifndef ASM_DEBUG_SPEC
943 : : # if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG)
944 : : /* If --gdwarf-N is supported and as can handle even compiler generated
945 : : .debug_line with it, supply --gdwarf-N in ASM_DEBUG_OPTION_SPEC rather
946 : : than in ASM_DEBUG_SPEC, so that it applies to both .s and .c etc.
947 : : compilations. */
948 : : # define ASM_DEBUG_DWARF_OPTION ""
949 : : # elif defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && !defined(HAVE_LD_BROKEN_PE_DWARF5)
950 : : # define ASM_DEBUG_DWARF_OPTION "%{%:dwarf-version-gt(4):--gdwarf-5;" \
951 : : "%:dwarf-version-gt(3):--gdwarf-4;" \
952 : : "%:dwarf-version-gt(2):--gdwarf-3;" \
953 : : ":--gdwarf2}"
954 : : # else
955 : : # define ASM_DEBUG_DWARF_OPTION "--gdwarf2"
956 : : # endif
957 : : # if defined(DWARF2_DEBUGGING_INFO) && defined(HAVE_AS_GDWARF2_DEBUG_FLAG)
958 : : # define ASM_DEBUG_SPEC "%{g*:%{%:debug-level-gt(0):" \
959 : : ASM_DEBUG_DWARF_OPTION "}}" ASM_MAP
960 : : # endif
961 : : # endif
962 : : #ifndef ASM_DEBUG_SPEC
963 : : # define ASM_DEBUG_SPEC ""
964 : : #endif
965 : :
966 : : /* Define ASM_DEBUG_OPTION_SPEC to be a spec suitable for translating '-g'
967 : : to the assembler when compiling all sources. */
968 : : #ifndef ASM_DEBUG_OPTION_SPEC
969 : : # if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG)
970 : : # define ASM_DEBUG_OPTION_DWARF_OPT \
971 : : "%{%:dwarf-version-gt(4):--gdwarf-5 ;" \
972 : : "%:dwarf-version-gt(3):--gdwarf-4 ;" \
973 : : "%:dwarf-version-gt(2):--gdwarf-3 ;" \
974 : : ":--gdwarf2 }"
975 : : # if defined(DWARF2_DEBUGGING_INFO)
976 : : # define ASM_DEBUG_OPTION_SPEC "%{g*:%{%:debug-level-gt(0):" \
977 : : ASM_DEBUG_OPTION_DWARF_OPT "}}"
978 : : # endif
979 : : # endif
980 : : #endif
981 : : #ifndef ASM_DEBUG_OPTION_SPEC
982 : : # define ASM_DEBUG_OPTION_SPEC ""
983 : : #endif
984 : :
985 : : /* Here is the spec for running the linker, after compiling all files. */
986 : :
987 : : /* This is overridable by the target in case they need to specify the
988 : : -lgcc and -lc order specially, yet not require them to override all
989 : : of LINK_COMMAND_SPEC. */
990 : : #ifndef LINK_GCC_C_SEQUENCE_SPEC
991 : : #define LINK_GCC_C_SEQUENCE_SPEC "%G %{!nolibc:%L %G}"
992 : : #endif
993 : :
994 : : #ifndef LINK_SSP_SPEC
995 : : #ifdef TARGET_LIBC_PROVIDES_SSP
996 : : #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \
997 : : "|fstack-protector-strong|fstack-protector-explicit:}"
998 : : #else
999 : : #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \
1000 : : "|fstack-protector-strong|fstack-protector-explicit" \
1001 : : ":-lssp_nonshared -lssp}"
1002 : : #endif
1003 : : #endif
1004 : :
1005 : : #ifdef ENABLE_DEFAULT_PIE
1006 : : #define PIE_SPEC "!no-pie"
1007 : : #define NO_FPIE1_SPEC "fno-pie"
1008 : : #define FPIE1_SPEC NO_FPIE1_SPEC ":;"
1009 : : #define NO_FPIE2_SPEC "fno-PIE"
1010 : : #define FPIE2_SPEC NO_FPIE2_SPEC ":;"
1011 : : #define NO_FPIE_SPEC NO_FPIE1_SPEC "|" NO_FPIE2_SPEC
1012 : : #define FPIE_SPEC NO_FPIE_SPEC ":;"
1013 : : #define NO_FPIC1_SPEC "fno-pic"
1014 : : #define FPIC1_SPEC NO_FPIC1_SPEC ":;"
1015 : : #define NO_FPIC2_SPEC "fno-PIC"
1016 : : #define FPIC2_SPEC NO_FPIC2_SPEC ":;"
1017 : : #define NO_FPIC_SPEC NO_FPIC1_SPEC "|" NO_FPIC2_SPEC
1018 : : #define FPIC_SPEC NO_FPIC_SPEC ":;"
1019 : : #define NO_FPIE1_AND_FPIC1_SPEC NO_FPIE1_SPEC "|" NO_FPIC1_SPEC
1020 : : #define FPIE1_OR_FPIC1_SPEC NO_FPIE1_AND_FPIC1_SPEC ":;"
1021 : : #define NO_FPIE2_AND_FPIC2_SPEC NO_FPIE2_SPEC "|" NO_FPIC2_SPEC
1022 : : #define FPIE2_OR_FPIC2_SPEC NO_FPIE2_AND_FPIC2_SPEC ":;"
1023 : : #define NO_FPIE_AND_FPIC_SPEC NO_FPIE_SPEC "|" NO_FPIC_SPEC
1024 : : #define FPIE_OR_FPIC_SPEC NO_FPIE_AND_FPIC_SPEC ":;"
1025 : : #else
1026 : : #define PIE_SPEC "pie"
1027 : : #define FPIE1_SPEC "fpie"
1028 : : #define NO_FPIE1_SPEC FPIE1_SPEC ":;"
1029 : : #define FPIE2_SPEC "fPIE"
1030 : : #define NO_FPIE2_SPEC FPIE2_SPEC ":;"
1031 : : #define FPIE_SPEC FPIE1_SPEC "|" FPIE2_SPEC
1032 : : #define NO_FPIE_SPEC FPIE_SPEC ":;"
1033 : : #define FPIC1_SPEC "fpic"
1034 : : #define NO_FPIC1_SPEC FPIC1_SPEC ":;"
1035 : : #define FPIC2_SPEC "fPIC"
1036 : : #define NO_FPIC2_SPEC FPIC2_SPEC ":;"
1037 : : #define FPIC_SPEC FPIC1_SPEC "|" FPIC2_SPEC
1038 : : #define NO_FPIC_SPEC FPIC_SPEC ":;"
1039 : : #define FPIE1_OR_FPIC1_SPEC FPIE1_SPEC "|" FPIC1_SPEC
1040 : : #define NO_FPIE1_AND_FPIC1_SPEC FPIE1_OR_FPIC1_SPEC ":;"
1041 : : #define FPIE2_OR_FPIC2_SPEC FPIE2_SPEC "|" FPIC2_SPEC
1042 : : #define NO_FPIE2_AND_FPIC2_SPEC FPIE1_OR_FPIC2_SPEC ":;"
1043 : : #define FPIE_OR_FPIC_SPEC FPIE_SPEC "|" FPIC_SPEC
1044 : : #define NO_FPIE_AND_FPIC_SPEC FPIE_OR_FPIC_SPEC ":;"
1045 : : #endif
1046 : :
1047 : : #ifndef LINK_PIE_SPEC
1048 : : #ifdef HAVE_LD_PIE
1049 : : #ifndef LD_PIE_SPEC
1050 : : #define LD_PIE_SPEC "-pie"
1051 : : #endif
1052 : : #else
1053 : : #define LD_PIE_SPEC ""
1054 : : #endif
1055 : : #define LINK_PIE_SPEC "%{static|shared|r:;" PIE_SPEC ":" LD_PIE_SPEC "} "
1056 : : #endif
1057 : :
1058 : : #ifndef LINK_BUILDID_SPEC
1059 : : # if defined(HAVE_LD_BUILDID) && defined(ENABLE_LD_BUILDID)
1060 : : # define LINK_BUILDID_SPEC "%{!r:--build-id} "
1061 : : # endif
1062 : : #endif
1063 : :
1064 : : #ifndef LTO_PLUGIN_SPEC
1065 : : #define LTO_PLUGIN_SPEC ""
1066 : : #endif
1067 : :
1068 : : /* Conditional to test whether the LTO plugin is used or not.
1069 : : FIXME: For slim LTO we will need to enable plugin unconditionally. This
1070 : : still cause problems with PLUGIN_LD != LD and when plugin is built but
1071 : : not useable. For GCC 4.6 we don't support slim LTO and thus we can enable
1072 : : plugin only when LTO is enabled. We still honor explicit
1073 : : -fuse-linker-plugin if the linker used understands -plugin. */
1074 : :
1075 : : /* The linker has some plugin support. */
1076 : : #if HAVE_LTO_PLUGIN > 0
1077 : : /* The linker used has full plugin support, use LTO plugin by default. */
1078 : : #if HAVE_LTO_PLUGIN == 2
1079 : : #define PLUGIN_COND "!fno-use-linker-plugin:%{!fno-lto"
1080 : : #define PLUGIN_COND_CLOSE "}"
1081 : : #else
1082 : : /* The linker used has limited plugin support, use LTO plugin with explicit
1083 : : -fuse-linker-plugin. */
1084 : : #define PLUGIN_COND "fuse-linker-plugin"
1085 : : #define PLUGIN_COND_CLOSE ""
1086 : : #endif
1087 : : #define LINK_PLUGIN_SPEC \
1088 : : "%{" PLUGIN_COND": \
1089 : : -plugin %(linker_plugin_file) \
1090 : : -plugin-opt=%(lto_wrapper) \
1091 : : -plugin-opt=-fresolution=%u.res \
1092 : : " LTO_PLUGIN_SPEC "\
1093 : : %{flinker-output=*:-plugin-opt=-linker-output-known} \
1094 : : %{!nostdlib:%{!nodefaultlibs:%:pass-through-libs(%(link_gcc_c_sequence))}} \
1095 : : }" PLUGIN_COND_CLOSE
1096 : : #else
1097 : : /* The linker used doesn't support -plugin, reject -fuse-linker-plugin. */
1098 : : #define LINK_PLUGIN_SPEC "%{fuse-linker-plugin:\
1099 : : %e-fuse-linker-plugin is not supported in this configuration}"
1100 : : #endif
1101 : :
1102 : : /* Linker command line options for -fsanitize= early on the command line. */
1103 : : #ifndef SANITIZER_EARLY_SPEC
1104 : : #define SANITIZER_EARLY_SPEC "\
1105 : : %{!nostdlib:%{!r:%{!nodefaultlibs:%{%:sanitize(address):" LIBASAN_EARLY_SPEC "} \
1106 : : %{%:sanitize(hwaddress):" LIBHWASAN_EARLY_SPEC "} \
1107 : : %{%:sanitize(thread):" LIBTSAN_EARLY_SPEC "} \
1108 : : %{%:sanitize(leak):" LIBLSAN_EARLY_SPEC "}}}}"
1109 : : #endif
1110 : :
1111 : : /* Linker command line options for -fsanitize= late on the command line. */
1112 : : #ifndef SANITIZER_SPEC
1113 : : #define SANITIZER_SPEC "\
1114 : : %{!nostdlib:%{!r:%{!nodefaultlibs:%{%:sanitize(address):" LIBASAN_SPEC "\
1115 : : %{static:%ecannot specify -static with -fsanitize=address}}\
1116 : : %{%:sanitize(hwaddress):" LIBHWASAN_SPEC "\
1117 : : %{static:%ecannot specify -static with -fsanitize=hwaddress}}\
1118 : : %{%:sanitize(thread):" LIBTSAN_SPEC "\
1119 : : %{static:%ecannot specify -static with -fsanitize=thread}}\
1120 : : %{%:sanitize(undefined):" LIBUBSAN_SPEC "}\
1121 : : %{%:sanitize(leak):" LIBLSAN_SPEC "}}}}"
1122 : : #endif
1123 : :
1124 : : #ifndef POST_LINK_SPEC
1125 : : #define POST_LINK_SPEC ""
1126 : : #endif
1127 : :
1128 : : /* This is the spec to use, once the code for creating the vtable
1129 : : verification runtime library, libvtv.so, has been created. Currently
1130 : : the vtable verification runtime functions are in libstdc++, so we use
1131 : : the spec just below this one. */
1132 : : #ifndef VTABLE_VERIFICATION_SPEC
1133 : : #if ENABLE_VTABLE_VERIFY
1134 : : #define VTABLE_VERIFICATION_SPEC "\
1135 : : %{!nostdlib:%{!r:%{fvtable-verify=std: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end}\
1136 : : %{fvtable-verify=preinit: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end}}}"
1137 : : #else
1138 : : #define VTABLE_VERIFICATION_SPEC "\
1139 : : %{fvtable-verify=none:} \
1140 : : %{fvtable-verify=std: \
1141 : : %e-fvtable-verify=std is not supported in this configuration} \
1142 : : %{fvtable-verify=preinit: \
1143 : : %e-fvtable-verify=preinit is not supported in this configuration}"
1144 : : #endif
1145 : : #endif
1146 : :
1147 : : /* -u* was put back because both BSD and SysV seem to support it. */
1148 : : /* %{static|no-pie|static-pie:} simply prevents an error message:
1149 : : 1. If the target machine doesn't handle -static.
1150 : : 2. If PIE isn't enabled by default.
1151 : : 3. If the target machine doesn't handle -static-pie.
1152 : : */
1153 : : /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
1154 : : scripts which exist in user specified directories, or in standard
1155 : : directories. */
1156 : : /* We pass any -flto flags on to the linker, which is expected
1157 : : to understand them. In practice, this means it had better be collect2. */
1158 : : /* %{e*} includes -export-dynamic; see comment in common.opt. */
1159 : : #ifndef LINK_COMMAND_SPEC
1160 : : #define LINK_COMMAND_SPEC "\
1161 : : %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
1162 : : %(linker) " \
1163 : : LINK_PLUGIN_SPEC \
1164 : : "%{flto|flto=*:%<fcompare-debug*} \
1165 : : %{flto} %{fno-lto} %{flto=*} %l " LINK_PIE_SPEC \
1166 : : "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \
1167 : : "%X %{o*} %{e*} %{N} %{n} %{r}\
1168 : : %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \
1169 : : %{static|no-pie|static-pie:} %@{L*} %(link_libgcc) " \
1170 : : VTABLE_VERIFICATION_SPEC " " SANITIZER_EARLY_SPEC " %o "" \
1171 : : %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\
1172 : : %:include(libgomp.spec)%(link_gomp)}\
1173 : : %{fgnu-tm:%:include(libitm.spec)%(link_itm)}\
1174 : : " STACK_SPLIT_SPEC "\
1175 : : %{fprofile-arcs|fcondition-coverage|fpath-coverage|fprofile-generate*|coverage:-lgcov} " SANITIZER_SPEC " \
1176 : : %{!nostdlib:%{!r:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}}\
1177 : : %{!nostdlib:%{!r:%{!nostartfiles:%E}}} %{T*} \n%(post_link) }}}}}}"
1178 : : #endif
1179 : :
1180 : : #ifndef LINK_LIBGCC_SPEC
1181 : : /* Generate -L options for startfile prefix list. */
1182 : : # define LINK_LIBGCC_SPEC "%D"
1183 : : #endif
1184 : :
1185 : : #ifndef STARTFILE_PREFIX_SPEC
1186 : : # define STARTFILE_PREFIX_SPEC ""
1187 : : #endif
1188 : :
1189 : : #ifndef SYSROOT_SPEC
1190 : : # define SYSROOT_SPEC "--sysroot=%R"
1191 : : #endif
1192 : :
1193 : : #ifndef SYSROOT_SUFFIX_SPEC
1194 : : # define SYSROOT_SUFFIX_SPEC ""
1195 : : #endif
1196 : :
1197 : : #ifndef SYSROOT_HEADERS_SUFFIX_SPEC
1198 : : # define SYSROOT_HEADERS_SUFFIX_SPEC ""
1199 : : #endif
1200 : :
1201 : : #ifndef RUNPATH_OPTION
1202 : : # define RUNPATH_OPTION "-rpath"
1203 : : #endif
1204 : :
1205 : : static const char *asm_debug = ASM_DEBUG_SPEC;
1206 : : static const char *asm_debug_option = ASM_DEBUG_OPTION_SPEC;
1207 : : static const char *cpp_spec = CPP_SPEC;
1208 : : static const char *cc1_spec = CC1_SPEC OS_CC1_SPEC;
1209 : : static const char *cc1plus_spec = CC1PLUS_SPEC;
1210 : : static const char *link_gcc_c_sequence_spec = LINK_GCC_C_SEQUENCE_SPEC;
1211 : : static const char *link_ssp_spec = LINK_SSP_SPEC;
1212 : : static const char *asm_spec = ASM_SPEC;
1213 : : static const char *asm_final_spec = ASM_FINAL_SPEC;
1214 : : static const char *link_spec = LINK_SPEC;
1215 : : static const char *lib_spec = LIB_SPEC;
1216 : : static const char *link_gomp_spec = "";
1217 : : static const char *libgcc_spec = LIBGCC_SPEC;
1218 : : static const char *endfile_spec = ENDFILE_SPEC;
1219 : : static const char *startfile_spec = STARTFILE_SPEC;
1220 : : static const char *linker_name_spec = LINKER_NAME;
1221 : : static const char *linker_plugin_file_spec = "";
1222 : : static const char *lto_wrapper_spec = "";
1223 : : static const char *lto_gcc_spec = "";
1224 : : static const char *post_link_spec = POST_LINK_SPEC;
1225 : : static const char *link_command_spec = LINK_COMMAND_SPEC;
1226 : : static const char *link_libgcc_spec = LINK_LIBGCC_SPEC;
1227 : : static const char *startfile_prefix_spec = STARTFILE_PREFIX_SPEC;
1228 : : static const char *sysroot_spec = SYSROOT_SPEC;
1229 : : static const char *sysroot_suffix_spec = SYSROOT_SUFFIX_SPEC;
1230 : : static const char *sysroot_hdrs_suffix_spec = SYSROOT_HEADERS_SUFFIX_SPEC;
1231 : : static const char *self_spec = "";
1232 : :
1233 : : /* Standard options to cpp, cc1, and as, to reduce duplication in specs.
1234 : : There should be no need to override these in target dependent files,
1235 : : but we need to copy them to the specs file so that newer versions
1236 : : of the GCC driver can correctly drive older tool chains with the
1237 : : appropriate -B options. */
1238 : :
1239 : : /* When cpplib handles traditional preprocessing, get rid of this, and
1240 : : call cc1 (or cc1obj in objc/lang-specs.h) from the main specs so
1241 : : that we default the front end language better. */
1242 : : static const char *trad_capable_cpp =
1243 : : "cc1 -E %{traditional|traditional-cpp:-traditional-cpp}";
1244 : :
1245 : : /* We don't wrap .d files in %W{} since a missing .d file, and
1246 : : therefore no dependency entry, confuses make into thinking a .o
1247 : : file that happens to exist is up-to-date. */
1248 : : static const char *cpp_unique_options =
1249 : : "%{!Q:-quiet} %{nostdinc*} %{C} %{CC} %{v} %@{I*&F*} %{P} %I\
1250 : : %{MD:-MD %{!o:%b.d}%{o*:%.d%*}}\
1251 : : %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}}\
1252 : : %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\
1253 : : %{Mmodules} %{Mno-modules}\
1254 : : %{!E:%{!M:%{!MM:%{!MT:%{!MQ:%{MD|MMD:%{o*:-MQ %*}}}}}}}\
1255 : : %{remap} %{%:debug-level-gt(2):-dD}\
1256 : : %{!iplugindir*:%{fplugin*:%:find-plugindir()}}\
1257 : : %{H} %C %{D*&U*&A*} %{i*} %Z %i\
1258 : : %{E|M|MM:%W{o*}} %{-embed*}\
1259 : : %{fdeps-format=*:%{!fdeps-file=*:-fdeps-file=%:join(%{!o:%b.ddi}%{o*:%.ddi%*})}}\
1260 : : %{fdeps-format=*:%{!fdeps-target=*:-fdeps-target=%:join(%{!o:%b.o}%{o*:%.o%*})}}";
1261 : :
1262 : : /* This contains cpp options which are common with cc1_options and are passed
1263 : : only when preprocessing only to avoid duplication. We pass the cc1 spec
1264 : : options to the preprocessor so that it the cc1 spec may manipulate
1265 : : options used to set target flags. Those special target flags settings may
1266 : : in turn cause preprocessor symbols to be defined specially. */
1267 : : static const char *cpp_options =
1268 : : "%(cpp_unique_options) %1 %{m*} %{std*&ansi&trigraphs} %{W*&pedantic*} %{w}\
1269 : : %{f*} %{g*:%{%:debug-level-gt(0):%{g*}\
1270 : : %{!fno-working-directory:-fworking-directory}}} %{O*}\
1271 : : %{undef} %{save-temps*:-fpch-preprocess}";
1272 : :
1273 : : /* Pass -d* flags, possibly modifying -dumpdir, -dumpbase et al.
1274 : :
1275 : : Make it easy for a language to override the argument for the
1276 : : %:dumps specs function call. */
1277 : : #define DUMPS_OPTIONS(EXTS) \
1278 : : "%<dumpdir %<dumpbase %<dumpbase-ext %{d*} %:dumps(" EXTS ")"
1279 : :
1280 : : /* This contains cpp options which are not passed when the preprocessor
1281 : : output will be used by another program. */
1282 : : static const char *cpp_debug_options = DUMPS_OPTIONS ("");
1283 : :
1284 : : /* NB: This is shared amongst all front-ends, except for Ada. */
1285 : : static const char *cc1_options =
1286 : : "%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
1287 : : %{!iplugindir*:%{fplugin*:%:find-plugindir()}}\
1288 : : %1 %{!Q:-quiet} %(cpp_debug_options) %{m*} %{aux-info*}\
1289 : : %{g*} %{O*} %{W*&pedantic*} %{w} %{std*&ansi&trigraphs}\
1290 : : %{v:-version} %{pg:-p} %{p} %{f*} %{undef}\
1291 : : %{Qn:-fno-ident} %{Qy:} %{-help:--help}\
1292 : : %{-target-help:--target-help}\
1293 : : %{-version:--version}\
1294 : : %{-help=*:--help=%*}\
1295 : : %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %w%b.s}}}\
1296 : : %{fsyntax-only:-o %j} %{-param*}\
1297 : : %{coverage:-fprofile-arcs -ftest-coverage}\
1298 : : %{fprofile-arcs|fcondition-coverage|fpath-coverage|fprofile-generate*|coverage:\
1299 : : %{!fprofile-update=single:\
1300 : : %{pthread:-fprofile-update=prefer-atomic}}}";
1301 : :
1302 : : static const char *asm_options =
1303 : : "%{-target-help:%:print-asm-header()} "
1304 : : #if HAVE_GNU_AS
1305 : : /* If GNU AS is used, then convert -w (no warnings), -I, and -v
1306 : : to the assembler equivalents. */
1307 : : "%{v} %{w:-W} %{I*} "
1308 : : #endif
1309 : : "%(asm_debug_option)"
1310 : : ASM_COMPRESS_DEBUG_SPEC
1311 : : "%a %Y %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}";
1312 : :
1313 : : static const char *invoke_as =
1314 : : #ifdef AS_NEEDS_DASH_FOR_PIPED_INPUT
1315 : : "%{!fwpa*:\
1316 : : %{fcompare-debug=*|fdump-final-insns=*:%:compare-debug-dump-opt()}\
1317 : : %{!S:-o %|.s |\n as %(asm_options) %|.s %A }\
1318 : : }";
1319 : : #else
1320 : : "%{!fwpa*:\
1321 : : %{fcompare-debug=*|fdump-final-insns=*:%:compare-debug-dump-opt()}\
1322 : : %{!S:-o %|.s |\n as %(asm_options) %m.s %A }\
1323 : : }";
1324 : : #endif
1325 : :
1326 : : /* Some compilers have limits on line lengths, and the multilib_select
1327 : : and/or multilib_matches strings can be very long, so we build them at
1328 : : run time. */
1329 : : static struct obstack multilib_obstack;
1330 : : static const char *multilib_select;
1331 : : static const char *multilib_matches;
1332 : : static const char *multilib_defaults;
1333 : : static const char *multilib_exclusions;
1334 : : static const char *multilib_reuse;
1335 : :
1336 : : /* Check whether a particular argument is a default argument. */
1337 : :
1338 : : #ifndef MULTILIB_DEFAULTS
1339 : : #define MULTILIB_DEFAULTS { "" }
1340 : : #endif
1341 : :
1342 : : static const char *const multilib_defaults_raw[] = MULTILIB_DEFAULTS;
1343 : :
1344 : : #ifndef DRIVER_SELF_SPECS
1345 : : #define DRIVER_SELF_SPECS ""
1346 : : #endif
1347 : :
1348 : : /* Linking to libgomp implies pthreads. This is particularly important
1349 : : for targets that use different start files and suchlike. */
1350 : : #ifndef GOMP_SELF_SPECS
1351 : : #define GOMP_SELF_SPECS \
1352 : : "%{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1): " \
1353 : : "-pthread}"
1354 : : #endif
1355 : :
1356 : : /* Likewise for -fgnu-tm. */
1357 : : #ifndef GTM_SELF_SPECS
1358 : : #define GTM_SELF_SPECS "%{fgnu-tm: -pthread}"
1359 : : #endif
1360 : :
1361 : : static const char *const driver_self_specs[] = {
1362 : : "%{fdump-final-insns:-fdump-final-insns=.} %<fdump-final-insns",
1363 : : DRIVER_SELF_SPECS, CONFIGURE_SPECS, GOMP_SELF_SPECS, GTM_SELF_SPECS,
1364 : : /* This discards -fmultiflags at the end of self specs processing in the
1365 : : driver, so that it is effectively Ignored, without actually marking it as
1366 : : Ignored, which would get it discarded before self specs could remap it. */
1367 : : "%<fmultiflags"
1368 : : };
1369 : :
1370 : : #ifndef OPTION_DEFAULT_SPECS
1371 : : #define OPTION_DEFAULT_SPECS { "", "" }
1372 : : #endif
1373 : :
1374 : : struct default_spec
1375 : : {
1376 : : const char *name;
1377 : : const char *spec;
1378 : : };
1379 : :
1380 : : static const struct default_spec
1381 : : option_default_specs[] = { OPTION_DEFAULT_SPECS };
1382 : :
1383 : : struct user_specs
1384 : : {
1385 : : struct user_specs *next;
1386 : : const char *filename;
1387 : : };
1388 : :
1389 : : static struct user_specs *user_specs_head, *user_specs_tail;
1390 : :
1391 : :
1392 : : /* Record the mapping from file suffixes for compilation specs. */
1393 : :
1394 : : struct compiler
1395 : : {
1396 : : const char *suffix; /* Use this compiler for input files
1397 : : whose names end in this suffix. */
1398 : :
1399 : : const char *spec; /* To use this compiler, run this spec. */
1400 : :
1401 : : const char *cpp_spec; /* If non-NULL, substitute this spec
1402 : : for `%C', rather than the usual
1403 : : cpp_spec. */
1404 : : int combinable; /* If nonzero, compiler can deal with
1405 : : multiple source files at once (IMA). */
1406 : : int needs_preprocessing; /* If nonzero, source files need to
1407 : : be run through a preprocessor. */
1408 : : };
1409 : :
1410 : : /* Pointer to a vector of `struct compiler' that gives the spec for
1411 : : compiling a file, based on its suffix.
1412 : : A file that does not end in any of these suffixes will be passed
1413 : : unchanged to the loader and nothing else will be done to it.
1414 : :
1415 : : An entry containing two 0s is used to terminate the vector.
1416 : :
1417 : : If multiple entries match a file, the last matching one is used. */
1418 : :
1419 : : static struct compiler *compilers;
1420 : :
1421 : : /* Number of entries in `compilers', not counting the null terminator. */
1422 : :
1423 : : static int n_compilers;
1424 : :
1425 : : /* The default list of file name suffixes and their compilation specs. */
1426 : :
1427 : : static const struct compiler default_compilers[] =
1428 : : {
1429 : : /* Add lists of suffixes of known languages here. If those languages
1430 : : were not present when we built the driver, we will hit these copies
1431 : : and be given a more meaningful error than "file not used since
1432 : : linking is not done". */
1433 : : {".m", "#Objective-C", 0, 0, 0}, {".mi", "#Objective-C", 0, 0, 0},
1434 : : {".mm", "#Objective-C++", 0, 0, 0}, {".M", "#Objective-C++", 0, 0, 0},
1435 : : {".mii", "#Objective-C++", 0, 0, 0},
1436 : : {".cc", "#C++", 0, 0, 0}, {".cxx", "#C++", 0, 0, 0},
1437 : : {".cpp", "#C++", 0, 0, 0}, {".cp", "#C++", 0, 0, 0},
1438 : : {".c++", "#C++", 0, 0, 0}, {".C", "#C++", 0, 0, 0},
1439 : : {".CPP", "#C++", 0, 0, 0}, {".ii", "#C++", 0, 0, 0},
1440 : : {".ads", "#Ada", 0, 0, 0}, {".adb", "#Ada", 0, 0, 0},
1441 : : {".f", "#Fortran", 0, 0, 0}, {".F", "#Fortran", 0, 0, 0},
1442 : : {".for", "#Fortran", 0, 0, 0}, {".FOR", "#Fortran", 0, 0, 0},
1443 : : {".ftn", "#Fortran", 0, 0, 0}, {".FTN", "#Fortran", 0, 0, 0},
1444 : : {".fpp", "#Fortran", 0, 0, 0}, {".FPP", "#Fortran", 0, 0, 0},
1445 : : {".f90", "#Fortran", 0, 0, 0}, {".F90", "#Fortran", 0, 0, 0},
1446 : : {".f95", "#Fortran", 0, 0, 0}, {".F95", "#Fortran", 0, 0, 0},
1447 : : {".f03", "#Fortran", 0, 0, 0}, {".F03", "#Fortran", 0, 0, 0},
1448 : : {".f08", "#Fortran", 0, 0, 0}, {".F08", "#Fortran", 0, 0, 0},
1449 : : {".r", "#Ratfor", 0, 0, 0},
1450 : : {".go", "#Go", 0, 1, 0},
1451 : : {".d", "#D", 0, 1, 0}, {".dd", "#D", 0, 1, 0}, {".di", "#D", 0, 1, 0},
1452 : : {".mod", "#Modula-2", 0, 0, 0}, {".m2i", "#Modula-2", 0, 0, 0},
1453 : : /* Next come the entries for C. */
1454 : : {".c", "@c", 0, 0, 1},
1455 : : {"@c",
1456 : : /* cc1 has an integrated ISO C preprocessor. We should invoke the
1457 : : external preprocessor if -save-temps is given. */
1458 : : "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\
1459 : : %{!E:%{!M:%{!MM:\
1460 : : %{traditional:\
1461 : : %eGNU C no longer supports -traditional without -E}\
1462 : : %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \
1463 : : %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\
1464 : : cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \
1465 : : %(cc1_options)}\
1466 : : %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\
1467 : : cc1 %(cpp_unique_options) %(cc1_options)}}}\
1468 : : %{!fsyntax-only:%(invoke_as)}}}}", 0, 0, 1},
1469 : : {"-",
1470 : : "%{!E:%e-E or -x required when input is from standard input}\
1471 : : %(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)", 0, 0, 0},
1472 : : {".h", "@c-header", 0, 0, 0},
1473 : : {"@c-header",
1474 : : /* cc1 has an integrated ISO C preprocessor. We should invoke the
1475 : : external preprocessor if -save-temps is given. */
1476 : : "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\
1477 : : %{!E:%{!M:%{!MM:\
1478 : : %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \
1479 : : %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\
1480 : : cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \
1481 : : %(cc1_options)\
1482 : : %{!fsyntax-only:%{!S:-o %g.s} \
1483 : : %{!fdump-ada-spec*:%{!o*:--output-pch %w%i.gch}\
1484 : : %W{o*:--output-pch %w%*}}%{!S:%V}}}\
1485 : : %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\
1486 : : cc1 %(cpp_unique_options) %(cc1_options)\
1487 : : %{!fsyntax-only:%{!S:-o %g.s} \
1488 : : %{!fdump-ada-spec*:%{!o*:--output-pch %w%i.gch}\
1489 : : %W{o*:--output-pch %w%*}}%{!S:%V}}}}}}}}", 0, 0, 0},
1490 : : {".i", "@cpp-output", 0, 0, 0},
1491 : : {"@cpp-output",
1492 : : "%{!M:%{!MM:%{!E:cc1 -fpreprocessed %i %(cc1_options) %{!fsyntax-only:%(invoke_as)}}}}", 0, 0, 0},
1493 : : {".s", "@assembler", 0, 0, 0},
1494 : : {"@assembler",
1495 : : "%{!M:%{!MM:%{!E:%{!S:as %(asm_debug) %(asm_options) %i %A }}}}", 0, 0, 0},
1496 : : {".sx", "@assembler-with-cpp", 0, 0, 0},
1497 : : {".S", "@assembler-with-cpp", 0, 0, 0},
1498 : : {"@assembler-with-cpp",
1499 : : #ifdef AS_NEEDS_DASH_FOR_PIPED_INPUT
1500 : : "%(trad_capable_cpp) -lang-asm %(cpp_options) -fno-directives-only\
1501 : : %{E|M|MM:%(cpp_debug_options)}\
1502 : : %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\
1503 : : as %(asm_debug) %(asm_options) %|.s %A }}}}"
1504 : : #else
1505 : : "%(trad_capable_cpp) -lang-asm %(cpp_options) -fno-directives-only\
1506 : : %{E|M|MM:%(cpp_debug_options)}\
1507 : : %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\
1508 : : as %(asm_debug) %(asm_options) %m.s %A }}}}"
1509 : : #endif
1510 : : , 0, 0, 0},
1511 : :
1512 : : #include "specs.h"
1513 : : /* Mark end of table. */
1514 : : {0, 0, 0, 0, 0}
1515 : : };
1516 : :
1517 : : /* Number of elements in default_compilers, not counting the terminator. */
1518 : :
1519 : : static const int n_default_compilers = ARRAY_SIZE (default_compilers) - 1;
1520 : :
1521 : : typedef char *char_p; /* For DEF_VEC_P. */
1522 : :
1523 : : /* A vector of options to give to the linker.
1524 : : These options are accumulated by %x,
1525 : : and substituted into the linker command with %X. */
1526 : : static vec<char_p> linker_options;
1527 : :
1528 : : /* A vector of options to give to the assembler.
1529 : : These options are accumulated by -Wa,
1530 : : and substituted into the assembler command with %Y. */
1531 : : static vec<char_p> assembler_options;
1532 : :
1533 : : /* A vector of options to give to the preprocessor.
1534 : : These options are accumulated by -Wp,
1535 : : and substituted into the preprocessor command with %Z. */
1536 : : static vec<char_p> preprocessor_options;
1537 : :
1538 : : static char *
1539 : 28118817 : skip_whitespace (char *p)
1540 : : {
1541 : 65169976 : while (1)
1542 : : {
1543 : : /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1544 : : be considered whitespace. */
1545 : 65169976 : if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n')
1546 : 4718176 : return p + 1;
1547 : 60451800 : else if (*p == '\n' || *p == ' ' || *p == '\t')
1548 : 36935205 : p++;
1549 : 23516595 : else if (*p == '#')
1550 : : {
1551 : 3593276 : while (*p != '\n')
1552 : 3477322 : p++;
1553 : 115954 : p++;
1554 : : }
1555 : : else
1556 : : break;
1557 : : }
1558 : :
1559 : : return p;
1560 : : }
1561 : : /* Structures to keep track of prefixes to try when looking for files. */
1562 : :
1563 : : struct prefix_list
1564 : : {
1565 : : const char *prefix; /* String to prepend to the path. */
1566 : : struct prefix_list *next; /* Next in linked list. */
1567 : : int require_machine_suffix; /* Don't use without machine_suffix. */
1568 : : /* 2 means try both machine_suffix and just_machine_suffix. */
1569 : : int priority; /* Sort key - priority within list. */
1570 : : int os_multilib; /* 1 if OS multilib scheme should be used,
1571 : : 0 for GCC multilib scheme. */
1572 : : };
1573 : :
1574 : : struct path_prefix
1575 : : {
1576 : : struct prefix_list *plist; /* List of prefixes to try */
1577 : : int max_len; /* Max length of a prefix in PLIST */
1578 : : const char *name; /* Name of this list (used in config stuff) */
1579 : : };
1580 : :
1581 : : /* List of prefixes to try when looking for executables. */
1582 : :
1583 : : static struct path_prefix exec_prefixes = { 0, 0, "exec" };
1584 : :
1585 : : /* List of prefixes to try when looking for startup (crt0) files. */
1586 : :
1587 : : static struct path_prefix startfile_prefixes = { 0, 0, "startfile" };
1588 : :
1589 : : /* List of prefixes to try when looking for include files. */
1590 : :
1591 : : static struct path_prefix include_prefixes = { 0, 0, "include" };
1592 : :
1593 : : /* Suffix to attach to directories searched for commands.
1594 : : This looks like `MACHINE/VERSION/'. */
1595 : :
1596 : : static const char *machine_suffix = 0;
1597 : :
1598 : : /* Suffix to attach to directories searched for commands.
1599 : : This is just `MACHINE/'. */
1600 : :
1601 : : static const char *just_machine_suffix = 0;
1602 : :
1603 : : /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1604 : :
1605 : : static const char *gcc_exec_prefix;
1606 : :
1607 : : /* Adjusted value of standard_libexec_prefix. */
1608 : :
1609 : : static const char *gcc_libexec_prefix;
1610 : :
1611 : : /* Default prefixes to attach to command names. */
1612 : :
1613 : : #ifndef STANDARD_STARTFILE_PREFIX_1
1614 : : #define STANDARD_STARTFILE_PREFIX_1 "/lib/"
1615 : : #endif
1616 : : #ifndef STANDARD_STARTFILE_PREFIX_2
1617 : : #define STANDARD_STARTFILE_PREFIX_2 "/usr/lib/"
1618 : : #endif
1619 : :
1620 : : #ifdef CROSS_DIRECTORY_STRUCTURE /* Don't use these prefixes for a cross compiler. */
1621 : : #undef MD_EXEC_PREFIX
1622 : : #undef MD_STARTFILE_PREFIX
1623 : : #undef MD_STARTFILE_PREFIX_1
1624 : : #endif
1625 : :
1626 : : /* If no prefixes defined, use the null string, which will disable them. */
1627 : : #ifndef MD_EXEC_PREFIX
1628 : : #define MD_EXEC_PREFIX ""
1629 : : #endif
1630 : : #ifndef MD_STARTFILE_PREFIX
1631 : : #define MD_STARTFILE_PREFIX ""
1632 : : #endif
1633 : : #ifndef MD_STARTFILE_PREFIX_1
1634 : : #define MD_STARTFILE_PREFIX_1 ""
1635 : : #endif
1636 : :
1637 : : /* These directories are locations set at configure-time based on the
1638 : : --prefix option provided to configure. Their initializers are
1639 : : defined in Makefile.in. These paths are not *directly* used when
1640 : : gcc_exec_prefix is set because, in that case, we know where the
1641 : : compiler has been installed, and use paths relative to that
1642 : : location instead. */
1643 : : static const char *const standard_exec_prefix = STANDARD_EXEC_PREFIX;
1644 : : static const char *const standard_libexec_prefix = STANDARD_LIBEXEC_PREFIX;
1645 : : static const char *const standard_bindir_prefix = STANDARD_BINDIR_PREFIX;
1646 : : static const char *const standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
1647 : :
1648 : : /* For native compilers, these are well-known paths containing
1649 : : components that may be provided by the system. For cross
1650 : : compilers, these paths are not used. */
1651 : : static const char *md_exec_prefix = MD_EXEC_PREFIX;
1652 : : static const char *md_startfile_prefix = MD_STARTFILE_PREFIX;
1653 : : static const char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
1654 : : static const char *const standard_startfile_prefix_1
1655 : : = STANDARD_STARTFILE_PREFIX_1;
1656 : : static const char *const standard_startfile_prefix_2
1657 : : = STANDARD_STARTFILE_PREFIX_2;
1658 : :
1659 : : /* A relative path to be used in finding the location of tools
1660 : : relative to the driver. */
1661 : : static const char *const tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
1662 : :
1663 : : /* A prefix to be used when this is an accelerator compiler. */
1664 : : static const char *const accel_dir_suffix = ACCEL_DIR_SUFFIX;
1665 : :
1666 : : /* Subdirectory to use for locating libraries. Set by
1667 : : set_multilib_dir based on the compilation options. */
1668 : :
1669 : : static const char *multilib_dir;
1670 : :
1671 : : /* Subdirectory to use for locating libraries in OS conventions. Set by
1672 : : set_multilib_dir based on the compilation options. */
1673 : :
1674 : : static const char *multilib_os_dir;
1675 : :
1676 : : /* Subdirectory to use for locating libraries in multiarch conventions. Set by
1677 : : set_multilib_dir based on the compilation options. */
1678 : :
1679 : : static const char *multiarch_dir;
1680 : :
1681 : : /* Structure to keep track of the specs that have been defined so far.
1682 : : These are accessed using %(specname) in a compiler or link
1683 : : spec. */
1684 : :
1685 : : struct spec_list
1686 : : {
1687 : : /* The following 2 fields must be first */
1688 : : /* to allow EXTRA_SPECS to be initialized */
1689 : : const char *name; /* name of the spec. */
1690 : : const char *ptr; /* available ptr if no static pointer */
1691 : :
1692 : : /* The following fields are not initialized */
1693 : : /* by EXTRA_SPECS */
1694 : : const char **ptr_spec; /* pointer to the spec itself. */
1695 : : struct spec_list *next; /* Next spec in linked list. */
1696 : : int name_len; /* length of the name */
1697 : : bool user_p; /* whether string come from file spec. */
1698 : : bool alloc_p; /* whether string was allocated */
1699 : : const char *default_ptr; /* The default value of *ptr_spec. */
1700 : : };
1701 : :
1702 : : #define INIT_STATIC_SPEC(NAME,PTR) \
1703 : : { NAME, NULL, PTR, (struct spec_list *) 0, sizeof (NAME) - 1, false, false, \
1704 : : *PTR }
1705 : :
1706 : : /* List of statically defined specs. */
1707 : : static struct spec_list static_specs[] =
1708 : : {
1709 : : INIT_STATIC_SPEC ("asm", &asm_spec),
1710 : : INIT_STATIC_SPEC ("asm_debug", &asm_debug),
1711 : : INIT_STATIC_SPEC ("asm_debug_option", &asm_debug_option),
1712 : : INIT_STATIC_SPEC ("asm_final", &asm_final_spec),
1713 : : INIT_STATIC_SPEC ("asm_options", &asm_options),
1714 : : INIT_STATIC_SPEC ("invoke_as", &invoke_as),
1715 : : INIT_STATIC_SPEC ("cpp", &cpp_spec),
1716 : : INIT_STATIC_SPEC ("cpp_options", &cpp_options),
1717 : : INIT_STATIC_SPEC ("cpp_debug_options", &cpp_debug_options),
1718 : : INIT_STATIC_SPEC ("cpp_unique_options", &cpp_unique_options),
1719 : : INIT_STATIC_SPEC ("trad_capable_cpp", &trad_capable_cpp),
1720 : : INIT_STATIC_SPEC ("cc1", &cc1_spec),
1721 : : INIT_STATIC_SPEC ("cc1_options", &cc1_options),
1722 : : INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec),
1723 : : INIT_STATIC_SPEC ("link_gcc_c_sequence", &link_gcc_c_sequence_spec),
1724 : : INIT_STATIC_SPEC ("link_ssp", &link_ssp_spec),
1725 : : INIT_STATIC_SPEC ("endfile", &endfile_spec),
1726 : : INIT_STATIC_SPEC ("link", &link_spec),
1727 : : INIT_STATIC_SPEC ("lib", &lib_spec),
1728 : : INIT_STATIC_SPEC ("link_gomp", &link_gomp_spec),
1729 : : INIT_STATIC_SPEC ("libgcc", &libgcc_spec),
1730 : : INIT_STATIC_SPEC ("startfile", &startfile_spec),
1731 : : INIT_STATIC_SPEC ("cross_compile", &cross_compile),
1732 : : INIT_STATIC_SPEC ("version", &compiler_version),
1733 : : INIT_STATIC_SPEC ("multilib", &multilib_select),
1734 : : INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults),
1735 : : INIT_STATIC_SPEC ("multilib_extra", &multilib_extra),
1736 : : INIT_STATIC_SPEC ("multilib_matches", &multilib_matches),
1737 : : INIT_STATIC_SPEC ("multilib_exclusions", &multilib_exclusions),
1738 : : INIT_STATIC_SPEC ("multilib_options", &multilib_options),
1739 : : INIT_STATIC_SPEC ("multilib_reuse", &multilib_reuse),
1740 : : INIT_STATIC_SPEC ("linker", &linker_name_spec),
1741 : : INIT_STATIC_SPEC ("linker_plugin_file", &linker_plugin_file_spec),
1742 : : INIT_STATIC_SPEC ("lto_wrapper", <o_wrapper_spec),
1743 : : INIT_STATIC_SPEC ("lto_gcc", <o_gcc_spec),
1744 : : INIT_STATIC_SPEC ("post_link", &post_link_spec),
1745 : : INIT_STATIC_SPEC ("link_libgcc", &link_libgcc_spec),
1746 : : INIT_STATIC_SPEC ("md_exec_prefix", &md_exec_prefix),
1747 : : INIT_STATIC_SPEC ("md_startfile_prefix", &md_startfile_prefix),
1748 : : INIT_STATIC_SPEC ("md_startfile_prefix_1", &md_startfile_prefix_1),
1749 : : INIT_STATIC_SPEC ("startfile_prefix_spec", &startfile_prefix_spec),
1750 : : INIT_STATIC_SPEC ("sysroot_spec", &sysroot_spec),
1751 : : INIT_STATIC_SPEC ("sysroot_suffix_spec", &sysroot_suffix_spec),
1752 : : INIT_STATIC_SPEC ("sysroot_hdrs_suffix_spec", &sysroot_hdrs_suffix_spec),
1753 : : INIT_STATIC_SPEC ("self_spec", &self_spec),
1754 : : };
1755 : :
1756 : : #ifdef EXTRA_SPECS /* additional specs needed */
1757 : : /* Structure to keep track of just the first two args of a spec_list.
1758 : : That is all that the EXTRA_SPECS macro gives us. */
1759 : : struct spec_list_1
1760 : : {
1761 : : const char *const name;
1762 : : const char *const ptr;
1763 : : };
1764 : :
1765 : : static const struct spec_list_1 extra_specs_1[] = { EXTRA_SPECS };
1766 : : static struct spec_list *extra_specs = (struct spec_list *) 0;
1767 : : #endif
1768 : :
1769 : : /* List of dynamically allocates specs that have been defined so far. */
1770 : :
1771 : : static struct spec_list *specs = (struct spec_list *) 0;
1772 : :
1773 : : /* List of static spec functions. */
1774 : :
1775 : : static const struct spec_function static_spec_functions[] =
1776 : : {
1777 : : { "getenv", getenv_spec_function },
1778 : : { "if-exists", if_exists_spec_function },
1779 : : { "if-exists-else", if_exists_else_spec_function },
1780 : : { "if-exists-then-else", if_exists_then_else_spec_function },
1781 : : { "sanitize", sanitize_spec_function },
1782 : : { "replace-outfile", replace_outfile_spec_function },
1783 : : { "remove-outfile", remove_outfile_spec_function },
1784 : : { "version-compare", version_compare_spec_function },
1785 : : { "include", include_spec_function },
1786 : : { "find-file", find_file_spec_function },
1787 : : { "find-plugindir", find_plugindir_spec_function },
1788 : : { "print-asm-header", print_asm_header_spec_function },
1789 : : { "compare-debug-dump-opt", compare_debug_dump_opt_spec_function },
1790 : : { "compare-debug-self-opt", compare_debug_self_opt_spec_function },
1791 : : { "pass-through-libs", pass_through_libs_spec_func },
1792 : : { "dumps", dumps_spec_func },
1793 : : { "gt", greater_than_spec_func },
1794 : : { "debug-level-gt", debug_level_greater_than_spec_func },
1795 : : { "dwarf-version-gt", dwarf_version_greater_than_spec_func },
1796 : : { "fortran-preinclude-file", find_fortran_preinclude_file},
1797 : : { "join", join_spec_func},
1798 : : #ifdef EXTRA_SPEC_FUNCTIONS
1799 : : EXTRA_SPEC_FUNCTIONS
1800 : : #endif
1801 : : { 0, 0 }
1802 : : };
1803 : :
1804 : : static int processing_spec_function;
1805 : :
1806 : : /* Add appropriate libgcc specs to OBSTACK, taking into account
1807 : : various permutations of -shared-libgcc, -shared, and such. */
1808 : :
1809 : : #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC)
1810 : :
1811 : : #ifndef USE_LD_AS_NEEDED
1812 : : #define USE_LD_AS_NEEDED 0
1813 : : #endif
1814 : :
1815 : : static void
1816 : 1092 : init_gcc_specs (struct obstack *obstack, const char *shared_name,
1817 : : const char *static_name, const char *eh_name)
1818 : : {
1819 : 1092 : char *buf;
1820 : :
1821 : : #if USE_LD_AS_NEEDED
1822 : 1092 : buf = concat ("%{static|static-libgcc|static-pie:", static_name, " ", eh_name, "}"
1823 : : "%{!static:%{!static-libgcc:%{!static-pie:"
1824 : : "%{!shared-libgcc:",
1825 : : static_name, " " LD_AS_NEEDED_OPTION " ",
1826 : : shared_name, " " LD_NO_AS_NEEDED_OPTION
1827 : : "}"
1828 : : "%{shared-libgcc:",
1829 : : shared_name, "%{!shared: ", static_name, "}"
1830 : : "}}"
1831 : : #else
1832 : : buf = concat ("%{static|static-libgcc:", static_name, " ", eh_name, "}"
1833 : : "%{!static:%{!static-libgcc:"
1834 : : "%{!shared:"
1835 : : "%{!shared-libgcc:", static_name, " ", eh_name, "}"
1836 : : "%{shared-libgcc:", shared_name, " ", static_name, "}"
1837 : : "}"
1838 : : #ifdef LINK_EH_SPEC
1839 : : "%{shared:"
1840 : : "%{shared-libgcc:", shared_name, "}"
1841 : : "%{!shared-libgcc:", static_name, "}"
1842 : : "}"
1843 : : #else
1844 : : "%{shared:", shared_name, "}"
1845 : : #endif
1846 : : #endif
1847 : : "}}", NULL);
1848 : :
1849 : 1092 : obstack_grow (obstack, buf, strlen (buf));
1850 : 1092 : free (buf);
1851 : 1092 : }
1852 : : #endif /* ENABLE_SHARED_LIBGCC */
1853 : :
1854 : : /* Initialize the specs lookup routines. */
1855 : :
1856 : : static void
1857 : 1092 : init_spec (void)
1858 : : {
1859 : 1092 : struct spec_list *next = (struct spec_list *) 0;
1860 : 1092 : struct spec_list *sl = (struct spec_list *) 0;
1861 : 1092 : int i;
1862 : :
1863 : 1092 : if (specs)
1864 : : return; /* Already initialized. */
1865 : :
1866 : 1092 : if (verbose_flag)
1867 : 98 : fnotice (stderr, "Using built-in specs.\n");
1868 : :
1869 : : #ifdef EXTRA_SPECS
1870 : 1092 : extra_specs = XCNEWVEC (struct spec_list, ARRAY_SIZE (extra_specs_1));
1871 : :
1872 : 2184 : for (i = ARRAY_SIZE (extra_specs_1) - 1; i >= 0; i--)
1873 : : {
1874 : 1092 : sl = &extra_specs[i];
1875 : 1092 : sl->name = extra_specs_1[i].name;
1876 : 1092 : sl->ptr = extra_specs_1[i].ptr;
1877 : 1092 : sl->next = next;
1878 : 1092 : sl->name_len = strlen (sl->name);
1879 : 1092 : sl->ptr_spec = &sl->ptr;
1880 : 1092 : gcc_assert (sl->ptr_spec != NULL);
1881 : 1092 : sl->default_ptr = sl->ptr;
1882 : 1092 : next = sl;
1883 : : }
1884 : : #endif
1885 : :
1886 : 50232 : for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--)
1887 : : {
1888 : 49140 : sl = &static_specs[i];
1889 : 49140 : sl->next = next;
1890 : 49140 : next = sl;
1891 : : }
1892 : :
1893 : : #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC)
1894 : : /* ??? If neither -shared-libgcc nor --static-libgcc was
1895 : : seen, then we should be making an educated guess. Some proposed
1896 : : heuristics for ELF include:
1897 : :
1898 : : (1) If "-Wl,--export-dynamic", then it's a fair bet that the
1899 : : program will be doing dynamic loading, which will likely
1900 : : need the shared libgcc.
1901 : :
1902 : : (2) If "-ldl", then it's also a fair bet that we're doing
1903 : : dynamic loading.
1904 : :
1905 : : (3) For each ET_DYN we're linking against (either through -lfoo
1906 : : or /some/path/foo.so), check to see whether it or one of
1907 : : its dependencies depends on a shared libgcc.
1908 : :
1909 : : (4) If "-shared"
1910 : :
1911 : : If the runtime is fixed to look for program headers instead
1912 : : of calling __register_frame_info at all, for each object,
1913 : : use the shared libgcc if any EH symbol referenced.
1914 : :
1915 : : If crtstuff is fixed to not invoke __register_frame_info
1916 : : automatically, for each object, use the shared libgcc if
1917 : : any non-empty unwind section found.
1918 : :
1919 : : Doing any of this probably requires invoking an external program to
1920 : : do the actual object file scanning. */
1921 : 1092 : {
1922 : 1092 : const char *p = libgcc_spec;
1923 : 1092 : int in_sep = 1;
1924 : :
1925 : : /* Transform the extant libgcc_spec into one that uses the shared libgcc
1926 : : when given the proper command line arguments. */
1927 : 2184 : while (*p)
1928 : : {
1929 : 1092 : if (in_sep && *p == '-' && startswith (p, "-lgcc"))
1930 : : {
1931 : 1092 : init_gcc_specs (&obstack,
1932 : : "-lgcc_s"
1933 : : #ifdef USE_LIBUNWIND_EXCEPTIONS
1934 : : " -lunwind"
1935 : : #endif
1936 : : ,
1937 : : "-lgcc",
1938 : : "-lgcc_eh"
1939 : : #ifdef USE_LIBUNWIND_EXCEPTIONS
1940 : : # ifdef HAVE_LD_STATIC_DYNAMIC
1941 : : " %{!static:%{!static-pie:" LD_STATIC_OPTION "}} -lunwind"
1942 : : " %{!static:%{!static-pie:" LD_DYNAMIC_OPTION "}}"
1943 : : # else
1944 : : " -lunwind"
1945 : : # endif
1946 : : #endif
1947 : : );
1948 : :
1949 : 1092 : p += 5;
1950 : 1092 : in_sep = 0;
1951 : : }
1952 : 0 : else if (in_sep && *p == 'l' && startswith (p, "libgcc.a%s"))
1953 : : {
1954 : : /* Ug. We don't know shared library extensions. Hope that
1955 : : systems that use this form don't do shared libraries. */
1956 : 0 : init_gcc_specs (&obstack,
1957 : : "-lgcc_s",
1958 : : "libgcc.a%s",
1959 : : "libgcc_eh.a%s"
1960 : : #ifdef USE_LIBUNWIND_EXCEPTIONS
1961 : : " -lunwind"
1962 : : #endif
1963 : : );
1964 : 0 : p += 10;
1965 : 0 : in_sep = 0;
1966 : : }
1967 : : else
1968 : : {
1969 : 0 : obstack_1grow (&obstack, *p);
1970 : 0 : in_sep = (*p == ' ');
1971 : 0 : p += 1;
1972 : : }
1973 : : }
1974 : :
1975 : 1092 : obstack_1grow (&obstack, '\0');
1976 : 1092 : libgcc_spec = XOBFINISH (&obstack, const char *);
1977 : : }
1978 : : #endif
1979 : : #ifdef USE_AS_TRADITIONAL_FORMAT
1980 : : /* Prepend "--traditional-format" to whatever asm_spec we had before. */
1981 : : {
1982 : : static const char tf[] = "--traditional-format ";
1983 : : obstack_grow (&obstack, tf, sizeof (tf) - 1);
1984 : : obstack_grow0 (&obstack, asm_spec, strlen (asm_spec));
1985 : : asm_spec = XOBFINISH (&obstack, const char *);
1986 : : }
1987 : : #endif
1988 : :
1989 : : #if defined LINK_EH_SPEC || defined LINK_BUILDID_SPEC || \
1990 : : defined LINKER_HASH_STYLE
1991 : : # ifdef LINK_BUILDID_SPEC
1992 : : /* Prepend LINK_BUILDID_SPEC to whatever link_spec we had before. */
1993 : : obstack_grow (&obstack, LINK_BUILDID_SPEC, sizeof (LINK_BUILDID_SPEC) - 1);
1994 : : # endif
1995 : : # ifdef LINK_EH_SPEC
1996 : : /* Prepend LINK_EH_SPEC to whatever link_spec we had before. */
1997 : 1092 : obstack_grow (&obstack, LINK_EH_SPEC, sizeof (LINK_EH_SPEC) - 1);
1998 : : # endif
1999 : : # ifdef LINKER_HASH_STYLE
2000 : : /* Prepend --hash-style=LINKER_HASH_STYLE to whatever link_spec we had
2001 : : before. */
2002 : : {
2003 : : static const char hash_style[] = "--hash-style=";
2004 : : obstack_grow (&obstack, hash_style, sizeof (hash_style) - 1);
2005 : : obstack_grow (&obstack, LINKER_HASH_STYLE, sizeof (LINKER_HASH_STYLE) - 1);
2006 : : obstack_1grow (&obstack, ' ');
2007 : : }
2008 : : # endif
2009 : 1092 : obstack_grow0 (&obstack, link_spec, strlen (link_spec));
2010 : 1092 : link_spec = XOBFINISH (&obstack, const char *);
2011 : : #endif
2012 : :
2013 : 1092 : specs = sl;
2014 : : }
2015 : :
2016 : : /* Update the entry for SPEC in the static_specs table to point to VALUE,
2017 : : ensuring that we free the previous value if necessary. Set alloc_p for the
2018 : : entry to ALLOC_P: this determines whether we take ownership of VALUE (i.e.
2019 : : whether we need to free it later on). */
2020 : : static void
2021 : 206025 : set_static_spec (const char **spec, const char *value, bool alloc_p)
2022 : : {
2023 : 206025 : struct spec_list *sl = NULL;
2024 : :
2025 : 7113608 : for (unsigned i = 0; i < ARRAY_SIZE (static_specs); i++)
2026 : : {
2027 : 7113608 : if (static_specs[i].ptr_spec == spec)
2028 : : {
2029 : 206025 : sl = static_specs + i;
2030 : 206025 : break;
2031 : : }
2032 : : }
2033 : :
2034 : 0 : gcc_assert (sl);
2035 : :
2036 : 206025 : if (sl->alloc_p)
2037 : : {
2038 : 206025 : const char *old = *spec;
2039 : 206025 : free (const_cast <char *> (old));
2040 : : }
2041 : :
2042 : 206025 : *spec = value;
2043 : 206025 : sl->alloc_p = alloc_p;
2044 : 206025 : }
2045 : :
2046 : : /* Update a static spec to a new string, taking ownership of that
2047 : : string's memory. */
2048 : 107128 : static void set_static_spec_owned (const char **spec, const char *val)
2049 : : {
2050 : 0 : return set_static_spec (spec, val, true);
2051 : : }
2052 : :
2053 : : /* Update a static spec to point to a new value, but don't take
2054 : : ownership of (i.e. don't free) that string. */
2055 : 98897 : static void set_static_spec_shared (const char **spec, const char *val)
2056 : : {
2057 : 0 : return set_static_spec (spec, val, false);
2058 : : }
2059 : :
2060 : :
2061 : : /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
2062 : : removed; If the spec starts with a + then SPEC is added to the end of the
2063 : : current spec. */
2064 : :
2065 : : static void
2066 : 13612366 : set_spec (const char *name, const char *spec, bool user_p)
2067 : : {
2068 : 13612366 : struct spec_list *sl;
2069 : 13612366 : const char *old_spec;
2070 : 13612366 : int name_len = strlen (name);
2071 : 13612366 : int i;
2072 : :
2073 : : /* If this is the first call, initialize the statically allocated specs. */
2074 : 13612366 : if (!specs)
2075 : : {
2076 : : struct spec_list *next = (struct spec_list *) 0;
2077 : 13564756 : for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--)
2078 : : {
2079 : 13269870 : sl = &static_specs[i];
2080 : 13269870 : sl->next = next;
2081 : 13269870 : next = sl;
2082 : : }
2083 : 294886 : specs = sl;
2084 : : }
2085 : :
2086 : : /* See if the spec already exists. */
2087 : 320316212 : for (sl = specs; sl; sl = sl->next)
2088 : 320000383 : if (name_len == sl->name_len && !strcmp (sl->name, name))
2089 : : break;
2090 : :
2091 : 13612366 : if (!sl)
2092 : : {
2093 : : /* Not found - make it. */
2094 : 315829 : sl = XNEW (struct spec_list);
2095 : 315829 : sl->name = xstrdup (name);
2096 : 315829 : sl->name_len = name_len;
2097 : 315829 : sl->ptr_spec = &sl->ptr;
2098 : 315829 : sl->alloc_p = 0;
2099 : 315829 : *(sl->ptr_spec) = "";
2100 : 315829 : sl->next = specs;
2101 : 315829 : sl->default_ptr = NULL;
2102 : 315829 : specs = sl;
2103 : : }
2104 : :
2105 : 13612366 : old_spec = *(sl->ptr_spec);
2106 : 13612366 : *(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE ((unsigned char)spec[1]))
2107 : 1 : ? concat (old_spec, spec + 1, NULL)
2108 : 13612365 : : xstrdup (spec));
2109 : :
2110 : : #ifdef DEBUG_SPECS
2111 : : if (verbose_flag)
2112 : : fnotice (stderr, "Setting spec %s to '%s'\n\n", name, *(sl->ptr_spec));
2113 : : #endif
2114 : :
2115 : : /* Free the old spec. */
2116 : 13612366 : if (old_spec && sl->alloc_p)
2117 : 5817 : free (CONST_CAST (char *, old_spec));
2118 : :
2119 : 13612366 : sl->user_p = user_p;
2120 : 13612366 : sl->alloc_p = true;
2121 : 13612366 : }
2122 : :
2123 : : /* Accumulate a command (program name and args), and run it. */
2124 : :
2125 : : typedef const char *const_char_p; /* For DEF_VEC_P. */
2126 : :
2127 : : /* Vector of pointers to arguments in the current line of specifications. */
2128 : : static vec<const_char_p> argbuf;
2129 : :
2130 : : /* Likewise, but for the current @file. */
2131 : : static vec<const_char_p> at_file_argbuf;
2132 : :
2133 : : /* Whether an @file is currently open. */
2134 : : static bool in_at_file = false;
2135 : :
2136 : : /* Were the options -c, -S or -E passed. */
2137 : : static int have_c = 0;
2138 : :
2139 : : /* Was the option -o passed. */
2140 : : static int have_o = 0;
2141 : :
2142 : : /* Was the option -E passed. */
2143 : : static int have_E = 0;
2144 : :
2145 : : /* Pointer to output file name passed in with -o. */
2146 : : static const char *output_file = 0;
2147 : :
2148 : : /* Pointer to input file name passed in with -truncate.
2149 : : This file should be truncated after linking. */
2150 : : static const char *totruncate_file = 0;
2151 : :
2152 : : /* This is the list of suffixes and codes (%g/%u/%U/%j) and the associated
2153 : : temp file. If the HOST_BIT_BUCKET is used for %j, no entry is made for
2154 : : it here. */
2155 : :
2156 : : static struct temp_name {
2157 : : const char *suffix; /* suffix associated with the code. */
2158 : : int length; /* strlen (suffix). */
2159 : : int unique; /* Indicates whether %g or %u/%U was used. */
2160 : : const char *filename; /* associated filename. */
2161 : : int filename_length; /* strlen (filename). */
2162 : : struct temp_name *next;
2163 : : } *temp_names;
2164 : :
2165 : : /* Number of commands executed so far. */
2166 : :
2167 : : static int execution_count;
2168 : :
2169 : : /* Number of commands that exited with a signal. */
2170 : :
2171 : : static int signal_count;
2172 : :
2173 : : /* Allocate the argument vector. */
2174 : :
2175 : : static void
2176 : 2345892 : alloc_args (void)
2177 : : {
2178 : 2345892 : argbuf.create (10);
2179 : 2345892 : at_file_argbuf.create (10);
2180 : 2345892 : }
2181 : :
2182 : : /* Clear out the vector of arguments (after a command is executed). */
2183 : :
2184 : : static void
2185 : 5534029 : clear_args (void)
2186 : : {
2187 : 5534029 : argbuf.truncate (0);
2188 : 5534029 : at_file_argbuf.truncate (0);
2189 : 5534029 : }
2190 : :
2191 : : /* Add one argument to the vector at the end.
2192 : : This is done when a space is seen or at the end of the line.
2193 : : If DELETE_ALWAYS is nonzero, the arg is a filename
2194 : : and the file should be deleted eventually.
2195 : : If DELETE_FAILURE is nonzero, the arg is a filename
2196 : : and the file should be deleted if this compilation fails. */
2197 : :
2198 : : static void
2199 : 19052595 : store_arg (const char *arg, int delete_always, int delete_failure)
2200 : : {
2201 : 19052595 : if (in_at_file)
2202 : 14027 : at_file_argbuf.safe_push (arg);
2203 : : else
2204 : 19038568 : argbuf.safe_push (arg);
2205 : :
2206 : 19052595 : if (delete_always || delete_failure)
2207 : : {
2208 : 517753 : const char *p;
2209 : : /* If the temporary file we should delete is specified as
2210 : : part of a joined argument extract the filename. */
2211 : 517753 : if (arg[0] == '-'
2212 : 517753 : && (p = strrchr (arg, '=')))
2213 : 90087 : arg = p + 1;
2214 : 517753 : record_temp_file (arg, delete_always, delete_failure);
2215 : : }
2216 : 19052595 : }
2217 : :
2218 : : /* Open a temporary @file into which subsequent arguments will be stored. */
2219 : :
2220 : : static void
2221 : 12997 : open_at_file (void)
2222 : : {
2223 : 12997 : if (in_at_file)
2224 : 0 : fatal_error (input_location, "cannot open nested response file");
2225 : : else
2226 : 12997 : in_at_file = true;
2227 : 12997 : }
2228 : :
2229 : : /* Create a temporary @file name. */
2230 : :
2231 : 12987 : static char *make_at_file (void)
2232 : : {
2233 : 12987 : static int fileno = 0;
2234 : 12987 : char filename[20];
2235 : 12987 : const char *base, *ext;
2236 : :
2237 : 12987 : if (!save_temps_flag)
2238 : 12949 : return make_temp_file ("");
2239 : :
2240 : 38 : base = dumpbase;
2241 : 38 : if (!(base && *base))
2242 : 11 : base = dumpdir;
2243 : 38 : if (!(base && *base))
2244 : 0 : base = "a";
2245 : :
2246 : 38 : sprintf (filename, ".args.%d", fileno++);
2247 : 38 : ext = filename;
2248 : :
2249 : 38 : if (base == dumpdir && dumpdir_trailing_dash_added)
2250 : 38 : ext++;
2251 : :
2252 : 38 : return concat (base, ext, NULL);
2253 : : }
2254 : :
2255 : : /* Close the temporary @file and add @file to the argument list. */
2256 : :
2257 : : static void
2258 : 12997 : close_at_file (void)
2259 : : {
2260 : 12997 : if (!in_at_file)
2261 : 0 : fatal_error (input_location, "cannot close nonexistent response file");
2262 : :
2263 : 12997 : in_at_file = false;
2264 : :
2265 : 12997 : const unsigned int n_args = at_file_argbuf.length ();
2266 : 12997 : if (n_args == 0)
2267 : : return;
2268 : :
2269 : 12987 : char **argv = XALLOCAVEC (char *, n_args + 1);
2270 : 12987 : char *temp_file = make_at_file ();
2271 : 12987 : char *at_argument = concat ("@", temp_file, NULL);
2272 : 12987 : FILE *f = fopen (temp_file, "w");
2273 : 12987 : int status;
2274 : 12987 : unsigned int i;
2275 : :
2276 : : /* Copy the strings over. */
2277 : 40001 : for (i = 0; i < n_args; i++)
2278 : 14027 : argv[i] = CONST_CAST (char *, at_file_argbuf[i]);
2279 : 12987 : argv[i] = NULL;
2280 : :
2281 : 12987 : at_file_argbuf.truncate (0);
2282 : :
2283 : 12987 : if (f == NULL)
2284 : 0 : fatal_error (input_location, "could not open temporary response file %s",
2285 : : temp_file);
2286 : :
2287 : 12987 : status = writeargv (argv, f);
2288 : :
2289 : 12987 : if (status)
2290 : 0 : fatal_error (input_location,
2291 : : "could not write to temporary response file %s",
2292 : : temp_file);
2293 : :
2294 : 12987 : status = fclose (f);
2295 : :
2296 : 12987 : if (status == EOF)
2297 : 0 : fatal_error (input_location, "could not close temporary response file %s",
2298 : : temp_file);
2299 : :
2300 : 12987 : store_arg (at_argument, 0, 0);
2301 : :
2302 : 12987 : record_temp_file (temp_file, !save_temps_flag, !save_temps_flag);
2303 : : }
2304 : :
2305 : : /* Load specs from a file name named FILENAME, replacing occurrences of
2306 : : various different types of line-endings, \r\n, \n\r and just \r, with
2307 : : a single \n. */
2308 : :
2309 : : static char *
2310 : 325164 : load_specs (const char *filename)
2311 : : {
2312 : 325164 : int desc;
2313 : 325164 : int readlen;
2314 : 325164 : struct stat statbuf;
2315 : 325164 : char *buffer;
2316 : 325164 : char *buffer_p;
2317 : 325164 : char *specs;
2318 : 325164 : char *specs_p;
2319 : :
2320 : 325164 : if (verbose_flag)
2321 : 1358 : fnotice (stderr, "Reading specs from %s\n", filename);
2322 : :
2323 : : /* Open and stat the file. */
2324 : 325164 : desc = open (filename, O_RDONLY, 0);
2325 : 325164 : if (desc < 0)
2326 : : {
2327 : 1 : failed:
2328 : : /* This leaves DESC open, but the OS will save us. */
2329 : 1 : fatal_error (input_location, "cannot read spec file %qs: %m", filename);
2330 : : }
2331 : :
2332 : 325163 : if (stat (filename, &statbuf) < 0)
2333 : 0 : goto failed;
2334 : :
2335 : : /* Read contents of file into BUFFER. */
2336 : 325163 : buffer = XNEWVEC (char, statbuf.st_size + 1);
2337 : 325163 : readlen = read (desc, buffer, (unsigned) statbuf.st_size);
2338 : 325163 : if (readlen < 0)
2339 : 0 : goto failed;
2340 : 325163 : buffer[readlen] = 0;
2341 : 325163 : close (desc);
2342 : :
2343 : 325163 : specs = XNEWVEC (char, readlen + 1);
2344 : 325163 : specs_p = specs;
2345 : 2961576095 : for (buffer_p = buffer; buffer_p && *buffer_p; buffer_p++)
2346 : : {
2347 : 2961250932 : int skip = 0;
2348 : 2961250932 : char c = *buffer_p;
2349 : 2961250932 : if (c == '\r')
2350 : : {
2351 : 0 : if (buffer_p > buffer && *(buffer_p - 1) == '\n') /* \n\r */
2352 : : skip = 1;
2353 : 0 : else if (*(buffer_p + 1) == '\n') /* \r\n */
2354 : : skip = 1;
2355 : : else /* \r */
2356 : : c = '\n';
2357 : : }
2358 : : if (! skip)
2359 : 2961250932 : *specs_p++ = c;
2360 : : }
2361 : 325163 : *specs_p = '\0';
2362 : :
2363 : 325163 : free (buffer);
2364 : 325163 : return (specs);
2365 : : }
2366 : :
2367 : : /* Read compilation specs from a file named FILENAME,
2368 : : replacing the default ones.
2369 : :
2370 : : A suffix which starts with `*' is a definition for
2371 : : one of the machine-specific sub-specs. The "suffix" should be
2372 : : *asm, *cc1, *cpp, *link, *startfile, etc.
2373 : : The corresponding spec is stored in asm_spec, etc.,
2374 : : rather than in the `compilers' vector.
2375 : :
2376 : : Anything invalid in the file is a fatal error. */
2377 : :
2378 : : static void
2379 : 325164 : read_specs (const char *filename, bool main_p, bool user_p)
2380 : : {
2381 : 325164 : char *buffer;
2382 : 325164 : char *p;
2383 : :
2384 : 325164 : buffer = load_specs (filename);
2385 : :
2386 : : /* Scan BUFFER for specs, putting them in the vector. */
2387 : 325164 : p = buffer;
2388 : 14232415 : while (1)
2389 : : {
2390 : 14232415 : char *suffix;
2391 : 14232415 : char *spec;
2392 : 14232415 : char *in, *out, *p1, *p2, *p3;
2393 : :
2394 : : /* Advance P in BUFFER to the next nonblank nocomment line. */
2395 : 14232415 : p = skip_whitespace (p);
2396 : 14232415 : if (*p == 0)
2397 : : break;
2398 : :
2399 : : /* Is this a special command that starts with '%'? */
2400 : : /* Don't allow this for the main specs file, since it would
2401 : : encourage people to overwrite it. */
2402 : 13907252 : if (*p == '%' && !main_p)
2403 : : {
2404 : 417000 : p1 = p;
2405 : 417000 : while (*p && *p != '\n')
2406 : 396150 : p++;
2407 : :
2408 : : /* Skip '\n'. */
2409 : 20850 : p++;
2410 : :
2411 : 20850 : if (startswith (p1, "%include")
2412 : 20850 : && (p1[sizeof "%include" - 1] == ' '
2413 : 0 : || p1[sizeof "%include" - 1] == '\t'))
2414 : : {
2415 : 0 : char *new_filename;
2416 : :
2417 : 0 : p1 += sizeof ("%include");
2418 : 0 : while (*p1 == ' ' || *p1 == '\t')
2419 : 0 : p1++;
2420 : :
2421 : 0 : if (*p1++ != '<' || p[-2] != '>')
2422 : 0 : fatal_error (input_location,
2423 : : "specs %%include syntax malformed after "
2424 : 0 : "%td characters", p1 - buffer + 1);
2425 : :
2426 : 0 : p[-2] = '\0';
2427 : 0 : new_filename = find_a_file (&startfile_prefixes, p1, R_OK, true);
2428 : 0 : read_specs (new_filename ? new_filename : p1, false, user_p);
2429 : 0 : continue;
2430 : 0 : }
2431 : 20850 : else if (startswith (p1, "%include_noerr")
2432 : 20850 : && (p1[sizeof "%include_noerr" - 1] == ' '
2433 : 0 : || p1[sizeof "%include_noerr" - 1] == '\t'))
2434 : : {
2435 : 0 : char *new_filename;
2436 : :
2437 : 0 : p1 += sizeof "%include_noerr";
2438 : 0 : while (*p1 == ' ' || *p1 == '\t')
2439 : 0 : p1++;
2440 : :
2441 : 0 : if (*p1++ != '<' || p[-2] != '>')
2442 : 0 : fatal_error (input_location,
2443 : : "specs %%include syntax malformed after "
2444 : 0 : "%td characters", p1 - buffer + 1);
2445 : :
2446 : 0 : p[-2] = '\0';
2447 : 0 : new_filename = find_a_file (&startfile_prefixes, p1, R_OK, true);
2448 : 0 : if (new_filename)
2449 : 0 : read_specs (new_filename, false, user_p);
2450 : 0 : else if (verbose_flag)
2451 : 0 : fnotice (stderr, "could not find specs file %s\n", p1);
2452 : 0 : continue;
2453 : 0 : }
2454 : 20850 : else if (startswith (p1, "%rename")
2455 : 20850 : && (p1[sizeof "%rename" - 1] == ' '
2456 : 0 : || p1[sizeof "%rename" - 1] == '\t'))
2457 : : {
2458 : 20850 : int name_len;
2459 : 20850 : struct spec_list *sl;
2460 : 20850 : struct spec_list *newsl;
2461 : :
2462 : : /* Get original name. */
2463 : 20850 : p1 += sizeof "%rename";
2464 : 20850 : while (*p1 == ' ' || *p1 == '\t')
2465 : 0 : p1++;
2466 : :
2467 : 20850 : if (! ISALPHA ((unsigned char) *p1))
2468 : 0 : fatal_error (input_location,
2469 : : "specs %%rename syntax malformed after "
2470 : : "%td characters", p1 - buffer);
2471 : :
2472 : : p2 = p1;
2473 : 83400 : while (*p2 && !ISSPACE ((unsigned char) *p2))
2474 : 62550 : p2++;
2475 : :
2476 : 20850 : if (*p2 != ' ' && *p2 != '\t')
2477 : 0 : fatal_error (input_location,
2478 : : "specs %%rename syntax malformed after "
2479 : : "%td characters", p2 - buffer);
2480 : :
2481 : 20850 : name_len = p2 - p1;
2482 : 20850 : *p2++ = '\0';
2483 : 20850 : while (*p2 == ' ' || *p2 == '\t')
2484 : 0 : p2++;
2485 : :
2486 : 20850 : if (! ISALPHA ((unsigned char) *p2))
2487 : 0 : fatal_error (input_location,
2488 : : "specs %%rename syntax malformed after "
2489 : : "%td characters", p2 - buffer);
2490 : :
2491 : : /* Get new spec name. */
2492 : : p3 = p2;
2493 : 166800 : while (*p3 && !ISSPACE ((unsigned char) *p3))
2494 : 145950 : p3++;
2495 : :
2496 : 20850 : if (p3 != p - 1)
2497 : 0 : fatal_error (input_location,
2498 : : "specs %%rename syntax malformed after "
2499 : : "%td characters", p3 - buffer);
2500 : 20850 : *p3 = '\0';
2501 : :
2502 : 417000 : for (sl = specs; sl; sl = sl->next)
2503 : 417000 : if (name_len == sl->name_len && !strcmp (sl->name, p1))
2504 : : break;
2505 : :
2506 : 20850 : if (!sl)
2507 : 0 : fatal_error (input_location,
2508 : : "specs %s spec was not found to be renamed", p1);
2509 : :
2510 : 20850 : if (strcmp (p1, p2) == 0)
2511 : 0 : continue;
2512 : :
2513 : 979950 : for (newsl = specs; newsl; newsl = newsl->next)
2514 : 959100 : if (strcmp (newsl->name, p2) == 0)
2515 : 0 : fatal_error (input_location,
2516 : : "%s: attempt to rename spec %qs to "
2517 : : "already defined spec %qs",
2518 : : filename, p1, p2);
2519 : :
2520 : 20850 : if (verbose_flag)
2521 : : {
2522 : 0 : fnotice (stderr, "rename spec %s to %s\n", p1, p2);
2523 : : #ifdef DEBUG_SPECS
2524 : : fnotice (stderr, "spec is '%s'\n\n", *(sl->ptr_spec));
2525 : : #endif
2526 : : }
2527 : :
2528 : 20850 : set_spec (p2, *(sl->ptr_spec), user_p);
2529 : 20850 : if (sl->alloc_p)
2530 : 20850 : free (CONST_CAST (char *, *(sl->ptr_spec)));
2531 : :
2532 : 20850 : *(sl->ptr_spec) = "";
2533 : 20850 : sl->alloc_p = 0;
2534 : 20850 : continue;
2535 : 20850 : }
2536 : : else
2537 : 0 : fatal_error (input_location,
2538 : : "specs unknown %% command after %td characters",
2539 : : p1 - buffer);
2540 : : }
2541 : :
2542 : : /* Find the colon that should end the suffix. */
2543 : : p1 = p;
2544 : 190665856 : while (*p1 && *p1 != ':' && *p1 != '\n')
2545 : 176779454 : p1++;
2546 : :
2547 : : /* The colon shouldn't be missing. */
2548 : 13886402 : if (*p1 != ':')
2549 : 0 : fatal_error (input_location,
2550 : : "specs file malformed after %td characters",
2551 : : p1 - buffer);
2552 : :
2553 : : /* Skip back over trailing whitespace. */
2554 : : p2 = p1;
2555 : 13886402 : while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t'))
2556 : 0 : p2--;
2557 : :
2558 : : /* Copy the suffix to a string. */
2559 : 13886402 : suffix = save_string (p, p2 - p);
2560 : : /* Find the next line. */
2561 : 13886402 : p = skip_whitespace (p1 + 1);
2562 : 13886402 : if (p[1] == 0)
2563 : 0 : fatal_error (input_location,
2564 : : "specs file malformed after %td characters",
2565 : : p - buffer);
2566 : :
2567 : : p1 = p;
2568 : : /* Find next blank line or end of string. */
2569 : 2738807821 : while (*p1 && !(*p1 == '\n' && (p1[1] == '\n' || p1[1] == '\0')))
2570 : 2724921419 : p1++;
2571 : :
2572 : : /* Specs end at the blank line and do not include the newline. */
2573 : 13886402 : spec = save_string (p, p1 - p);
2574 : 13886402 : p = p1;
2575 : :
2576 : : /* Delete backslash-newline sequences from the spec. */
2577 : 13886402 : in = spec;
2578 : 13886402 : out = spec;
2579 : 2752694221 : while (*in != 0)
2580 : : {
2581 : 2724921417 : if (in[0] == '\\' && in[1] == '\n')
2582 : 2 : in += 2;
2583 : 2724921415 : else if (in[0] == '#')
2584 : 0 : while (*in && *in != '\n')
2585 : 0 : in++;
2586 : :
2587 : : else
2588 : 2724921415 : *out++ = *in++;
2589 : : }
2590 : 13886402 : *out = 0;
2591 : :
2592 : 13886402 : if (suffix[0] == '*')
2593 : : {
2594 : 13886402 : if (! strcmp (suffix, "*link_command"))
2595 : 294886 : link_command_spec = spec;
2596 : : else
2597 : : {
2598 : 13591516 : set_spec (suffix + 1, spec, user_p);
2599 : 13591516 : free (spec);
2600 : : }
2601 : : }
2602 : : else
2603 : : {
2604 : : /* Add this pair to the vector. */
2605 : 0 : compilers
2606 : 0 : = XRESIZEVEC (struct compiler, compilers, n_compilers + 2);
2607 : :
2608 : 0 : compilers[n_compilers].suffix = suffix;
2609 : 0 : compilers[n_compilers].spec = spec;
2610 : 0 : n_compilers++;
2611 : 0 : memset (&compilers[n_compilers], 0, sizeof compilers[n_compilers]);
2612 : : }
2613 : :
2614 : 13886402 : if (*suffix == 0)
2615 : 0 : link_command_spec = spec;
2616 : : }
2617 : :
2618 : 325163 : if (link_command_spec == 0)
2619 : 0 : fatal_error (input_location, "spec file has no spec for linking");
2620 : :
2621 : 325163 : XDELETEVEC (buffer);
2622 : 325163 : }
2623 : :
2624 : : /* Record the names of temporary files we tell compilers to write,
2625 : : and delete them at the end of the run. */
2626 : :
2627 : : /* This is the common prefix we use to make temp file names.
2628 : : It is chosen once for each run of this program.
2629 : : It is substituted into a spec by %g or %j.
2630 : : Thus, all temp file names contain this prefix.
2631 : : In practice, all temp file names start with this prefix.
2632 : :
2633 : : This prefix comes from the envvar TMPDIR if it is defined;
2634 : : otherwise, from the P_tmpdir macro if that is defined;
2635 : : otherwise, in /usr/tmp or /tmp;
2636 : : or finally the current directory if all else fails. */
2637 : :
2638 : : static const char *temp_filename;
2639 : :
2640 : : /* Length of the prefix. */
2641 : :
2642 : : static int temp_filename_length;
2643 : :
2644 : : /* Define the list of temporary files to delete. */
2645 : :
2646 : : struct temp_file
2647 : : {
2648 : : const char *name;
2649 : : struct temp_file *next;
2650 : : };
2651 : :
2652 : : /* Queue of files to delete on success or failure of compilation. */
2653 : : static struct temp_file *always_delete_queue;
2654 : : /* Queue of files to delete on failure of compilation. */
2655 : : static struct temp_file *failure_delete_queue;
2656 : :
2657 : : /* Record FILENAME as a file to be deleted automatically.
2658 : : ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
2659 : : otherwise delete it in any case.
2660 : : FAIL_DELETE nonzero means delete it if a compilation step fails;
2661 : : otherwise delete it in any case. */
2662 : :
2663 : : void
2664 : 700145 : record_temp_file (const char *filename, int always_delete, int fail_delete)
2665 : : {
2666 : 700145 : char *const name = xstrdup (filename);
2667 : :
2668 : 700145 : if (always_delete)
2669 : : {
2670 : 527917 : struct temp_file *temp;
2671 : 915099 : for (temp = always_delete_queue; temp; temp = temp->next)
2672 : 551374 : if (! filename_cmp (name, temp->name))
2673 : : {
2674 : 164192 : free (name);
2675 : 164192 : goto already1;
2676 : : }
2677 : :
2678 : 363725 : temp = XNEW (struct temp_file);
2679 : 363725 : temp->next = always_delete_queue;
2680 : 363725 : temp->name = name;
2681 : 363725 : always_delete_queue = temp;
2682 : :
2683 : 700145 : already1:;
2684 : : }
2685 : :
2686 : 700145 : if (fail_delete)
2687 : : {
2688 : 281360 : struct temp_file *temp;
2689 : 286306 : for (temp = failure_delete_queue; temp; temp = temp->next)
2690 : 5035 : if (! filename_cmp (name, temp->name))
2691 : : {
2692 : 89 : free (name);
2693 : 89 : goto already2;
2694 : : }
2695 : :
2696 : 281271 : temp = XNEW (struct temp_file);
2697 : 281271 : temp->next = failure_delete_queue;
2698 : 281271 : temp->name = name;
2699 : 281271 : failure_delete_queue = temp;
2700 : :
2701 : 700145 : already2:;
2702 : : }
2703 : 700145 : }
2704 : :
2705 : : /* Delete all the temporary files whose names we previously recorded. */
2706 : :
2707 : : #ifndef DELETE_IF_ORDINARY
2708 : : #define DELETE_IF_ORDINARY(NAME,ST,VERBOSE_FLAG) \
2709 : : do \
2710 : : { \
2711 : : if (stat (NAME, &ST) >= 0 && S_ISREG (ST.st_mode)) \
2712 : : if (unlink (NAME) < 0) \
2713 : : if (VERBOSE_FLAG) \
2714 : : error ("%s: %m", (NAME)); \
2715 : : } while (0)
2716 : : #endif
2717 : :
2718 : : static void
2719 : 386770 : delete_if_ordinary (const char *name)
2720 : : {
2721 : 386770 : struct stat st;
2722 : : #ifdef DEBUG
2723 : : int i, c;
2724 : :
2725 : : printf ("Delete %s? (y or n) ", name);
2726 : : fflush (stdout);
2727 : : i = getchar ();
2728 : : if (i != '\n')
2729 : : while ((c = getchar ()) != '\n' && c != EOF)
2730 : : ;
2731 : :
2732 : : if (i == 'y' || i == 'Y')
2733 : : #endif /* DEBUG */
2734 : 386770 : DELETE_IF_ORDINARY (name, st, verbose_flag);
2735 : 386770 : }
2736 : :
2737 : : static void
2738 : 577211 : delete_temp_files (void)
2739 : : {
2740 : 577211 : struct temp_file *temp;
2741 : :
2742 : 940936 : for (temp = always_delete_queue; temp; temp = temp->next)
2743 : 363725 : delete_if_ordinary (temp->name);
2744 : 577211 : always_delete_queue = 0;
2745 : 577211 : }
2746 : :
2747 : : /* Delete all the files to be deleted on error. */
2748 : :
2749 : : static void
2750 : 57947 : delete_failure_queue (void)
2751 : : {
2752 : 57947 : struct temp_file *temp;
2753 : :
2754 : 80992 : for (temp = failure_delete_queue; temp; temp = temp->next)
2755 : 23045 : delete_if_ordinary (temp->name);
2756 : 57947 : }
2757 : :
2758 : : static void
2759 : 537369 : clear_failure_queue (void)
2760 : : {
2761 : 537369 : failure_delete_queue = 0;
2762 : 537369 : }
2763 : :
2764 : : /* Call CALLBACK for each path in PATHS, breaking out early if CALLBACK
2765 : : returns non-NULL.
2766 : : If DO_MULTI is true iterate over the paths twice, first with multilib
2767 : : suffix then without, otherwise iterate over the paths once without
2768 : : adding a multilib suffix. When DO_MULTI is true, some attempt is made
2769 : : to avoid visiting the same path twice, but we could do better. For
2770 : : instance, /usr/lib/../lib is considered different from /usr/lib.
2771 : : At least EXTRA_SPACE chars past the end of the path passed to
2772 : : CALLBACK are available for use by the callback.
2773 : : CALLBACK_INFO allows extra parameters to be passed to CALLBACK.
2774 : :
2775 : : Returns the value returned by CALLBACK. */
2776 : :
2777 : : static void *
2778 : 2806548 : for_each_path (const struct path_prefix *paths,
2779 : : bool do_multi,
2780 : : size_t extra_space,
2781 : : void *(*callback) (char *, void *),
2782 : : void *callback_info)
2783 : : {
2784 : 2806548 : struct prefix_list *pl;
2785 : 2806548 : const char *multi_dir = NULL;
2786 : 2806548 : const char *multi_os_dir = NULL;
2787 : 2806548 : const char *multiarch_suffix = NULL;
2788 : 2806548 : const char *multi_suffix;
2789 : 2806548 : const char *just_multi_suffix;
2790 : 2806548 : char *path = NULL;
2791 : 2806548 : void *ret = NULL;
2792 : 2806548 : bool skip_multi_dir = false;
2793 : 2806548 : bool skip_multi_os_dir = false;
2794 : :
2795 : 2806548 : multi_suffix = machine_suffix;
2796 : 2806548 : just_multi_suffix = just_machine_suffix;
2797 : 2806548 : if (do_multi && multilib_dir && strcmp (multilib_dir, ".") != 0)
2798 : : {
2799 : 15773 : multi_dir = concat (multilib_dir, dir_separator_str, NULL);
2800 : 15773 : multi_suffix = concat (multi_suffix, multi_dir, NULL);
2801 : 15773 : just_multi_suffix = concat (just_multi_suffix, multi_dir, NULL);
2802 : : }
2803 : 1221076 : if (do_multi && multilib_os_dir && strcmp (multilib_os_dir, ".") != 0)
2804 : 925097 : multi_os_dir = concat (multilib_os_dir, dir_separator_str, NULL);
2805 : 2806548 : if (multiarch_dir)
2806 : 0 : multiarch_suffix = concat (multiarch_dir, dir_separator_str, NULL);
2807 : :
2808 : 3226291 : while (1)
2809 : : {
2810 : 3226291 : size_t multi_dir_len = 0;
2811 : 3226291 : size_t multi_os_dir_len = 0;
2812 : 3226291 : size_t multiarch_len = 0;
2813 : 3226291 : size_t suffix_len;
2814 : 3226291 : size_t just_suffix_len;
2815 : 3226291 : size_t len;
2816 : :
2817 : 3226291 : if (multi_dir)
2818 : 15773 : multi_dir_len = strlen (multi_dir);
2819 : 3226291 : if (multi_os_dir)
2820 : 925097 : multi_os_dir_len = strlen (multi_os_dir);
2821 : 3226291 : if (multiarch_suffix)
2822 : 0 : multiarch_len = strlen (multiarch_suffix);
2823 : 3226291 : suffix_len = strlen (multi_suffix);
2824 : 3226291 : just_suffix_len = strlen (just_multi_suffix);
2825 : :
2826 : 3226291 : if (path == NULL)
2827 : : {
2828 : 2806548 : len = paths->max_len + extra_space + 1;
2829 : 2806548 : len += MAX (MAX (suffix_len, multi_os_dir_len), multiarch_len);
2830 : 2806548 : path = XNEWVEC (char, len);
2831 : : }
2832 : :
2833 : 12641799 : for (pl = paths->plist; pl != 0; pl = pl->next)
2834 : : {
2835 : 11075497 : len = strlen (pl->prefix);
2836 : 11075497 : memcpy (path, pl->prefix, len);
2837 : :
2838 : : /* Look first in MACHINE/VERSION subdirectory. */
2839 : 11075497 : if (!skip_multi_dir)
2840 : : {
2841 : 8101470 : memcpy (path + len, multi_suffix, suffix_len + 1);
2842 : 8101470 : ret = callback (path, callback_info);
2843 : 8101470 : if (ret)
2844 : : break;
2845 : : }
2846 : :
2847 : : /* Some paths are tried with just the machine (ie. target)
2848 : : subdir. This is used for finding as, ld, etc. */
2849 : 8101470 : if (!skip_multi_dir
2850 : 8101470 : && pl->require_machine_suffix == 2)
2851 : : {
2852 : 0 : memcpy (path + len, just_multi_suffix, just_suffix_len + 1);
2853 : 0 : ret = callback (path, callback_info);
2854 : 0 : if (ret)
2855 : : break;
2856 : : }
2857 : :
2858 : : /* Now try the multiarch path. */
2859 : 8101470 : if (!skip_multi_dir
2860 : 8101470 : && !pl->require_machine_suffix && multiarch_dir)
2861 : : {
2862 : 0 : memcpy (path + len, multiarch_suffix, multiarch_len + 1);
2863 : 0 : ret = callback (path, callback_info);
2864 : 0 : if (ret)
2865 : : break;
2866 : : }
2867 : :
2868 : : /* Now try the base path. */
2869 : 11075497 : if (!pl->require_machine_suffix
2870 : 17610505 : && !(pl->os_multilib ? skip_multi_os_dir : skip_multi_dir))
2871 : : {
2872 : 9902306 : const char *this_multi;
2873 : 9902306 : size_t this_multi_len;
2874 : :
2875 : 9902306 : if (pl->os_multilib)
2876 : : {
2877 : : this_multi = multi_os_dir;
2878 : : this_multi_len = multi_os_dir_len;
2879 : : }
2880 : : else
2881 : : {
2882 : 5361817 : this_multi = multi_dir;
2883 : 5361817 : this_multi_len = multi_dir_len;
2884 : : }
2885 : :
2886 : 9902306 : if (this_multi_len)
2887 : 2760016 : memcpy (path + len, this_multi, this_multi_len + 1);
2888 : : else
2889 : 7142290 : path[len] = '\0';
2890 : :
2891 : 9902306 : ret = callback (path, callback_info);
2892 : 9902306 : if (ret)
2893 : : break;
2894 : : }
2895 : : }
2896 : 3226291 : if (pl)
2897 : : break;
2898 : :
2899 : 1566302 : if (multi_dir == NULL && multi_os_dir == NULL)
2900 : : break;
2901 : :
2902 : : /* Run through the paths again, this time without multilibs.
2903 : : Don't repeat any we have already seen. */
2904 : 419743 : if (multi_dir)
2905 : : {
2906 : 10085 : free (CONST_CAST (char *, multi_dir));
2907 : 10085 : multi_dir = NULL;
2908 : 10085 : free (CONST_CAST (char *, multi_suffix));
2909 : 10085 : multi_suffix = machine_suffix;
2910 : 10085 : free (CONST_CAST (char *, just_multi_suffix));
2911 : 10085 : just_multi_suffix = just_machine_suffix;
2912 : : }
2913 : : else
2914 : : skip_multi_dir = true;
2915 : 419743 : if (multi_os_dir)
2916 : : {
2917 : 419743 : free (CONST_CAST (char *, multi_os_dir));
2918 : 419743 : multi_os_dir = NULL;
2919 : : }
2920 : : else
2921 : : skip_multi_os_dir = true;
2922 : : }
2923 : :
2924 : 2806548 : if (multi_dir)
2925 : : {
2926 : 5688 : free (CONST_CAST (char *, multi_dir));
2927 : 5688 : free (CONST_CAST (char *, multi_suffix));
2928 : 5688 : free (CONST_CAST (char *, just_multi_suffix));
2929 : : }
2930 : 2806548 : if (multi_os_dir)
2931 : 505354 : free (CONST_CAST (char *, multi_os_dir));
2932 : 2806548 : if (ret != path)
2933 : 1146559 : free (path);
2934 : 2806548 : return ret;
2935 : : }
2936 : :
2937 : : /* Callback for build_search_list. Adds path to obstack being built. */
2938 : :
2939 : : struct add_to_obstack_info {
2940 : : struct obstack *ob;
2941 : : bool check_dir;
2942 : : bool first_time;
2943 : : };
2944 : :
2945 : : static void *
2946 : 6917736 : add_to_obstack (char *path, void *data)
2947 : : {
2948 : 6917736 : struct add_to_obstack_info *info = (struct add_to_obstack_info *) data;
2949 : :
2950 : 6917736 : if (info->check_dir && !is_directory (path))
2951 : : return NULL;
2952 : :
2953 : 2546714 : if (!info->first_time)
2954 : 2044768 : obstack_1grow (info->ob, PATH_SEPARATOR);
2955 : :
2956 : 2546714 : obstack_grow (info->ob, path, strlen (path));
2957 : :
2958 : 2546714 : info->first_time = false;
2959 : 2546714 : return NULL;
2960 : : }
2961 : :
2962 : : /* Add or change the value of an environment variable, outputting the
2963 : : change to standard error if in verbose mode. */
2964 : : static void
2965 : 1750473 : xputenv (const char *string)
2966 : : {
2967 : 0 : env.xput (string);
2968 : 135878 : }
2969 : :
2970 : : /* Build a list of search directories from PATHS.
2971 : : PREFIX is a string to prepend to the list.
2972 : : If CHECK_DIR_P is true we ensure the directory exists.
2973 : : If DO_MULTI is true, multilib paths are output first, then
2974 : : non-multilib paths.
2975 : : This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
2976 : : It is also used by the --print-search-dirs flag. */
2977 : :
2978 : : static char *
2979 : 503040 : build_search_list (const struct path_prefix *paths, const char *prefix,
2980 : : bool check_dir, bool do_multi)
2981 : : {
2982 : 503040 : struct add_to_obstack_info info;
2983 : :
2984 : 503040 : info.ob = &collect_obstack;
2985 : 503040 : info.check_dir = check_dir;
2986 : 503040 : info.first_time = true;
2987 : :
2988 : 503040 : obstack_grow (&collect_obstack, prefix, strlen (prefix));
2989 : 503040 : obstack_1grow (&collect_obstack, '=');
2990 : :
2991 : 503040 : for_each_path (paths, do_multi, 0, add_to_obstack, &info);
2992 : :
2993 : 503040 : obstack_1grow (&collect_obstack, '\0');
2994 : 503040 : return XOBFINISH (&collect_obstack, char *);
2995 : : }
2996 : :
2997 : : /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
2998 : : for collect. */
2999 : :
3000 : : static void
3001 : 502984 : putenv_from_prefixes (const struct path_prefix *paths, const char *env_var,
3002 : : bool do_multi)
3003 : : {
3004 : 502984 : xputenv (build_search_list (paths, env_var, true, do_multi));
3005 : 502984 : }
3006 : :
3007 : : /* Check whether NAME can be accessed in MODE. This is like access,
3008 : : except that it never considers directories to be executable. */
3009 : :
3010 : : static int
3011 : 7769620 : access_check (const char *name, int mode)
3012 : : {
3013 : 7769620 : if (mode == X_OK)
3014 : : {
3015 : 1500412 : struct stat st;
3016 : :
3017 : 1500412 : if (stat (name, &st) < 0
3018 : 1500412 : || S_ISDIR (st.st_mode))
3019 : 762600 : return -1;
3020 : : }
3021 : :
3022 : 7007020 : return access (name, mode);
3023 : : }
3024 : :
3025 : : /* Callback for find_a_file. Appends the file name to the directory
3026 : : path. If the resulting file exists in the right mode, return the
3027 : : full pathname to the file. */
3028 : :
3029 : : struct file_at_path_info {
3030 : : const char *name;
3031 : : const char *suffix;
3032 : : int name_len;
3033 : : int suffix_len;
3034 : : int mode;
3035 : : };
3036 : :
3037 : : static void *
3038 : 7769620 : file_at_path (char *path, void *data)
3039 : : {
3040 : 7769620 : struct file_at_path_info *info = (struct file_at_path_info *) data;
3041 : 7769620 : size_t len = strlen (path);
3042 : :
3043 : 7769620 : memcpy (path + len, info->name, info->name_len);
3044 : 7769620 : len += info->name_len;
3045 : :
3046 : : /* Some systems have a suffix for executable files.
3047 : : So try appending that first. */
3048 : 7769620 : if (info->suffix_len)
3049 : : {
3050 : 0 : memcpy (path + len, info->suffix, info->suffix_len + 1);
3051 : 0 : if (access_check (path, info->mode) == 0)
3052 : : return path;
3053 : : }
3054 : :
3055 : 7769620 : path[len] = '\0';
3056 : 7769620 : if (access_check (path, info->mode) == 0)
3057 : : return path;
3058 : :
3059 : : return NULL;
3060 : : }
3061 : :
3062 : : /* Search for NAME using the prefix list PREFIXES. MODE is passed to
3063 : : access to check permissions. If DO_MULTI is true, search multilib
3064 : : paths then non-multilib paths, otherwise do not search multilib paths.
3065 : : Return 0 if not found, otherwise return its name, allocated with malloc. */
3066 : :
3067 : : static char *
3068 : 1758708 : find_a_file (const struct path_prefix *pprefix, const char *name, int mode,
3069 : : bool do_multi)
3070 : : {
3071 : 1758708 : struct file_at_path_info info;
3072 : :
3073 : : /* Find the filename in question (special case for absolute paths). */
3074 : :
3075 : 1758708 : if (IS_ABSOLUTE_PATH (name))
3076 : : {
3077 : 1 : if (access (name, mode) == 0)
3078 : 1 : return xstrdup (name);
3079 : :
3080 : : return NULL;
3081 : : }
3082 : :
3083 : 1758707 : info.name = name;
3084 : 1758707 : info.suffix = (mode & X_OK) != 0 ? HOST_EXECUTABLE_SUFFIX : "";
3085 : 1758707 : info.name_len = strlen (info.name);
3086 : 1758707 : info.suffix_len = strlen (info.suffix);
3087 : 1758707 : info.mode = mode;
3088 : :
3089 : 1758707 : return (char*) for_each_path (pprefix, do_multi,
3090 : : info.name_len + info.suffix_len,
3091 : 1758707 : file_at_path, &info);
3092 : : }
3093 : :
3094 : : /* Specialization of find_a_file for programs that also takes into account
3095 : : configure-specified default programs. */
3096 : :
3097 : : static char*
3098 : 743704 : find_a_program (const char *name)
3099 : : {
3100 : : /* Do not search if default matches query. */
3101 : :
3102 : : #ifdef DEFAULT_ASSEMBLER
3103 : : if (! strcmp (name, "as") && access (DEFAULT_ASSEMBLER, X_OK) == 0)
3104 : : return xstrdup (DEFAULT_ASSEMBLER);
3105 : : #endif
3106 : :
3107 : : #ifdef DEFAULT_LINKER
3108 : : if (! strcmp (name, "ld") && access (DEFAULT_LINKER, X_OK) == 0)
3109 : : return xstrdup (DEFAULT_LINKER);
3110 : : #endif
3111 : :
3112 : : #ifdef DEFAULT_DSYMUTIL
3113 : : if (! strcmp (name, "dsymutil") && access (DEFAULT_DSYMUTIL, X_OK) == 0)
3114 : : return xstrdup (DEFAULT_DSYMUTIL);
3115 : : #endif
3116 : :
3117 : 0 : return find_a_file (&exec_prefixes, name, X_OK, false);
3118 : : }
3119 : :
3120 : : /* Ranking of prefixes in the sort list. -B prefixes are put before
3121 : : all others. */
3122 : :
3123 : : enum path_prefix_priority
3124 : : {
3125 : : PREFIX_PRIORITY_B_OPT,
3126 : : PREFIX_PRIORITY_LAST
3127 : : };
3128 : :
3129 : : /* Add an entry for PREFIX in PLIST. The PLIST is kept in ascending
3130 : : order according to PRIORITY. Within each PRIORITY, new entries are
3131 : : appended.
3132 : :
3133 : : If WARN is nonzero, we will warn if no file is found
3134 : : through this prefix. WARN should point to an int
3135 : : which will be set to 1 if this entry is used.
3136 : :
3137 : : COMPONENT is the value to be passed to update_path.
3138 : :
3139 : : REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
3140 : : the complete value of machine_suffix.
3141 : : 2 means try both machine_suffix and just_machine_suffix. */
3142 : :
3143 : : static void
3144 : 3860933 : add_prefix (struct path_prefix *pprefix, const char *prefix,
3145 : : const char *component, /* enum prefix_priority */ int priority,
3146 : : int require_machine_suffix, int os_multilib)
3147 : : {
3148 : 3860933 : struct prefix_list *pl, **prev;
3149 : 3860933 : int len;
3150 : :
3151 : 3860933 : for (prev = &pprefix->plist;
3152 : 12230382 : (*prev) != NULL && (*prev)->priority <= priority;
3153 : 8369449 : prev = &(*prev)->next)
3154 : : ;
3155 : :
3156 : : /* Keep track of the longest prefix. */
3157 : :
3158 : 3860933 : prefix = update_path (prefix, component);
3159 : 3860933 : len = strlen (prefix);
3160 : 3860933 : if (len > pprefix->max_len)
3161 : 2091842 : pprefix->max_len = len;
3162 : :
3163 : 3860933 : pl = XNEW (struct prefix_list);
3164 : 3860933 : pl->prefix = prefix;
3165 : 3860933 : pl->require_machine_suffix = require_machine_suffix;
3166 : 3860933 : pl->priority = priority;
3167 : 3860933 : pl->os_multilib = os_multilib;
3168 : :
3169 : : /* Insert after PREV. */
3170 : 3860933 : pl->next = (*prev);
3171 : 3860933 : (*prev) = pl;
3172 : 3860933 : }
3173 : :
3174 : : /* Same as add_prefix, but prepending target_system_root to prefix. */
3175 : : /* The target_system_root prefix has been relocated by gcc_exec_prefix. */
3176 : : static void
3177 : 591954 : add_sysrooted_prefix (struct path_prefix *pprefix, const char *prefix,
3178 : : const char *component,
3179 : : /* enum prefix_priority */ int priority,
3180 : : int require_machine_suffix, int os_multilib)
3181 : : {
3182 : 591954 : if (!IS_ABSOLUTE_PATH (prefix))
3183 : 0 : fatal_error (input_location, "system path %qs is not absolute", prefix);
3184 : :
3185 : 591954 : if (target_system_root)
3186 : : {
3187 : 0 : char *sysroot_no_trailing_dir_separator = xstrdup (target_system_root);
3188 : 0 : size_t sysroot_len = strlen (target_system_root);
3189 : :
3190 : 0 : if (sysroot_len > 0
3191 : 0 : && target_system_root[sysroot_len - 1] == DIR_SEPARATOR)
3192 : 0 : sysroot_no_trailing_dir_separator[sysroot_len - 1] = '\0';
3193 : :
3194 : 0 : if (target_sysroot_suffix)
3195 : 0 : prefix = concat (sysroot_no_trailing_dir_separator,
3196 : : target_sysroot_suffix, prefix, NULL);
3197 : : else
3198 : 0 : prefix = concat (sysroot_no_trailing_dir_separator, prefix, NULL);
3199 : :
3200 : 0 : free (sysroot_no_trailing_dir_separator);
3201 : :
3202 : : /* We have to override this because GCC's notion of sysroot
3203 : : moves along with GCC. */
3204 : 0 : component = "GCC";
3205 : : }
3206 : :
3207 : 591954 : add_prefix (pprefix, prefix, component, priority,
3208 : : require_machine_suffix, os_multilib);
3209 : 591954 : }
3210 : :
3211 : : /* Same as add_prefix, but prepending target_sysroot_hdrs_suffix to prefix. */
3212 : :
3213 : : static void
3214 : 30572 : add_sysrooted_hdrs_prefix (struct path_prefix *pprefix, const char *prefix,
3215 : : const char *component,
3216 : : /* enum prefix_priority */ int priority,
3217 : : int require_machine_suffix, int os_multilib)
3218 : : {
3219 : 30572 : if (!IS_ABSOLUTE_PATH (prefix))
3220 : 0 : fatal_error (input_location, "system path %qs is not absolute", prefix);
3221 : :
3222 : 30572 : if (target_system_root)
3223 : : {
3224 : 0 : char *sysroot_no_trailing_dir_separator = xstrdup (target_system_root);
3225 : 0 : size_t sysroot_len = strlen (target_system_root);
3226 : :
3227 : 0 : if (sysroot_len > 0
3228 : 0 : && target_system_root[sysroot_len - 1] == DIR_SEPARATOR)
3229 : 0 : sysroot_no_trailing_dir_separator[sysroot_len - 1] = '\0';
3230 : :
3231 : 0 : if (target_sysroot_hdrs_suffix)
3232 : 0 : prefix = concat (sysroot_no_trailing_dir_separator,
3233 : : target_sysroot_hdrs_suffix, prefix, NULL);
3234 : : else
3235 : 0 : prefix = concat (sysroot_no_trailing_dir_separator, prefix, NULL);
3236 : :
3237 : 0 : free (sysroot_no_trailing_dir_separator);
3238 : :
3239 : : /* We have to override this because GCC's notion of sysroot
3240 : : moves along with GCC. */
3241 : 0 : component = "GCC";
3242 : : }
3243 : :
3244 : 30572 : add_prefix (pprefix, prefix, component, priority,
3245 : : require_machine_suffix, os_multilib);
3246 : 30572 : }
3247 : :
3248 : :
3249 : : /* Execute the command specified by the arguments on the current line of spec.
3250 : : When using pipes, this includes several piped-together commands
3251 : : with `|' between them.
3252 : :
3253 : : Return 0 if successful, -1 if failed. */
3254 : :
3255 : : static int
3256 : 539763 : execute (void)
3257 : : {
3258 : 539763 : int i;
3259 : 539763 : int n_commands; /* # of command. */
3260 : 539763 : char *string;
3261 : 539763 : struct pex_obj *pex;
3262 : 539763 : struct command
3263 : : {
3264 : : const char *prog; /* program name. */
3265 : : const char **argv; /* vector of args. */
3266 : : };
3267 : 539763 : const char *arg;
3268 : :
3269 : 539763 : struct command *commands; /* each command buffer with above info. */
3270 : :
3271 : 539763 : gcc_assert (!processing_spec_function);
3272 : :
3273 : 539763 : if (wrapper_string)
3274 : : {
3275 : 0 : string = find_a_program (argbuf[0]);
3276 : 0 : if (string)
3277 : 0 : argbuf[0] = string;
3278 : 0 : insert_wrapper (wrapper_string);
3279 : : }
3280 : :
3281 : : /* Count # of piped commands. */
3282 : 16344122 : for (n_commands = 1, i = 0; argbuf.iterate (i, &arg); i++)
3283 : 15804359 : if (strcmp (arg, "|") == 0)
3284 : 0 : n_commands++;
3285 : :
3286 : : /* Get storage for each command. */
3287 : 539763 : commands = XALLOCAVEC (struct command, n_commands);
3288 : :
3289 : : /* Split argbuf into its separate piped processes,
3290 : : and record info about each one.
3291 : : Also search for the programs that are to be run. */
3292 : :
3293 : 539763 : argbuf.safe_push (0);
3294 : :
3295 : 539763 : commands[0].prog = argbuf[0]; /* first command. */
3296 : 539763 : commands[0].argv = argbuf.address ();
3297 : :
3298 : 539763 : if (!wrapper_string)
3299 : : {
3300 : 539763 : string = find_a_program(commands[0].prog);
3301 : 539763 : if (string)
3302 : 537214 : commands[0].argv[0] = string;
3303 : : }
3304 : :
3305 : 16883885 : for (n_commands = 1, i = 0; argbuf.iterate (i, &arg); i++)
3306 : 16344122 : if (arg && strcmp (arg, "|") == 0)
3307 : : { /* each command. */
3308 : : #if defined (__MSDOS__) || defined (OS2) || defined (VMS)
3309 : : fatal_error (input_location, "%<-pipe%> not supported");
3310 : : #endif
3311 : 0 : argbuf[i] = 0; /* Termination of command args. */
3312 : 0 : commands[n_commands].prog = argbuf[i + 1];
3313 : 0 : commands[n_commands].argv
3314 : 0 : = &(argbuf.address ())[i + 1];
3315 : 0 : string = find_a_program(commands[n_commands].prog);
3316 : 0 : if (string)
3317 : 0 : commands[n_commands].argv[0] = string;
3318 : 0 : n_commands++;
3319 : : }
3320 : :
3321 : : /* If -v, print what we are about to do, and maybe query. */
3322 : :
3323 : 539763 : if (verbose_flag)
3324 : : {
3325 : : /* For help listings, put a blank line between sub-processes. */
3326 : 1397 : if (print_help_list)
3327 : 9 : fputc ('\n', stderr);
3328 : :
3329 : : /* Print each piped command as a separate line. */
3330 : 2794 : for (i = 0; i < n_commands; i++)
3331 : : {
3332 : 1397 : const char *const *j;
3333 : :
3334 : 1397 : if (verbose_only_flag)
3335 : : {
3336 : 17964 : for (j = commands[i].argv; *j; j++)
3337 : : {
3338 : : const char *p;
3339 : 429507 : for (p = *j; *p; ++p)
3340 : 415060 : if (!ISALNUM ((unsigned char) *p)
3341 : 98127 : && *p != '_' && *p != '/' && *p != '-' && *p != '.')
3342 : : break;
3343 : 16943 : if (*p || !*j)
3344 : : {
3345 : 2496 : fprintf (stderr, " \"");
3346 : 129994 : for (p = *j; *p; ++p)
3347 : : {
3348 : 127498 : if (*p == '"' || *p == '\\' || *p == '$')
3349 : 0 : fputc ('\\', stderr);
3350 : 127498 : fputc (*p, stderr);
3351 : : }
3352 : 2496 : fputc ('"', stderr);
3353 : : }
3354 : : /* If it's empty, print "". */
3355 : 14447 : else if (!**j)
3356 : 0 : fprintf (stderr, " \"\"");
3357 : : else
3358 : 14447 : fprintf (stderr, " %s", *j);
3359 : : }
3360 : : }
3361 : : else
3362 : 10564 : for (j = commands[i].argv; *j; j++)
3363 : : /* If it's empty, print "". */
3364 : 10188 : if (!**j)
3365 : 0 : fprintf (stderr, " \"\"");
3366 : : else
3367 : 10188 : fprintf (stderr, " %s", *j);
3368 : :
3369 : : /* Print a pipe symbol after all but the last command. */
3370 : 1397 : if (i + 1 != n_commands)
3371 : 0 : fprintf (stderr, " |");
3372 : 1397 : fprintf (stderr, "\n");
3373 : : }
3374 : 1397 : fflush (stderr);
3375 : 1397 : if (verbose_only_flag != 0)
3376 : : {
3377 : : /* verbose_only_flag should act as if the spec was
3378 : : executed, so increment execution_count before
3379 : : returning. This prevents spurious warnings about
3380 : : unused linker input files, etc. */
3381 : 1021 : execution_count++;
3382 : 1021 : return 0;
3383 : : }
3384 : : #ifdef DEBUG
3385 : : fnotice (stderr, "\nGo ahead? (y or n) ");
3386 : : fflush (stderr);
3387 : : i = getchar ();
3388 : : if (i != '\n')
3389 : : while (getchar () != '\n')
3390 : : ;
3391 : :
3392 : : if (i != 'y' && i != 'Y')
3393 : : return 0;
3394 : : #endif /* DEBUG */
3395 : : }
3396 : :
3397 : : #ifdef ENABLE_VALGRIND_CHECKING
3398 : : /* Run the each command through valgrind. To simplify prepending the
3399 : : path to valgrind and the option "-q" (for quiet operation unless
3400 : : something triggers), we allocate a separate argv array. */
3401 : :
3402 : : for (i = 0; i < n_commands; i++)
3403 : : {
3404 : : const char **argv;
3405 : : int argc;
3406 : : int j;
3407 : :
3408 : : for (argc = 0; commands[i].argv[argc] != NULL; argc++)
3409 : : ;
3410 : :
3411 : : argv = XALLOCAVEC (const char *, argc + 3);
3412 : :
3413 : : argv[0] = VALGRIND_PATH;
3414 : : argv[1] = "-q";
3415 : : for (j = 2; j < argc + 2; j++)
3416 : : argv[j] = commands[i].argv[j - 2];
3417 : : argv[j] = NULL;
3418 : :
3419 : : commands[i].argv = argv;
3420 : : commands[i].prog = argv[0];
3421 : : }
3422 : : #endif
3423 : :
3424 : : /* Run each piped subprocess. */
3425 : :
3426 : 538742 : pex = pex_init (PEX_USE_PIPES | ((report_times || report_times_to_file)
3427 : : ? PEX_RECORD_TIMES : 0),
3428 : : progname, temp_filename);
3429 : 538742 : if (pex == NULL)
3430 : : fatal_error (input_location, "%<pex_init%> failed: %m");
3431 : :
3432 : 1077484 : for (i = 0; i < n_commands; i++)
3433 : : {
3434 : 538742 : const char *errmsg;
3435 : 538742 : int err;
3436 : 538742 : const char *string = commands[i].argv[0];
3437 : :
3438 : 538742 : errmsg = pex_run (pex,
3439 : 538742 : ((i + 1 == n_commands ? PEX_LAST : 0)
3440 : 538742 : | (string == commands[i].prog ? PEX_SEARCH : 0)),
3441 : : string, CONST_CAST (char **, commands[i].argv),
3442 : : NULL, NULL, &err);
3443 : 538742 : if (errmsg != NULL)
3444 : : {
3445 : 0 : errno = err;
3446 : 0 : fatal_error (input_location,
3447 : : err ? G_("cannot execute %qs: %s: %m")
3448 : : : G_("cannot execute %qs: %s"),
3449 : : string, errmsg);
3450 : : }
3451 : :
3452 : 538742 : if (i && string != commands[i].prog)
3453 : 0 : free (CONST_CAST (char *, string));
3454 : : }
3455 : :
3456 : 538742 : execution_count++;
3457 : :
3458 : : /* Wait for all the subprocesses to finish. */
3459 : :
3460 : 538742 : {
3461 : 538742 : int *statuses;
3462 : 538742 : struct pex_time *times = NULL;
3463 : 538742 : int ret_code = 0;
3464 : :
3465 : 538742 : statuses = XALLOCAVEC (int, n_commands);
3466 : 538742 : if (!pex_get_status (pex, n_commands, statuses))
3467 : 0 : fatal_error (input_location, "failed to get exit status: %m");
3468 : :
3469 : 538742 : if (report_times || report_times_to_file)
3470 : : {
3471 : 0 : times = XALLOCAVEC (struct pex_time, n_commands);
3472 : 0 : if (!pex_get_times (pex, n_commands, times))
3473 : 0 : fatal_error (input_location, "failed to get process times: %m");
3474 : : }
3475 : :
3476 : 538742 : pex_free (pex);
3477 : :
3478 : 1077484 : for (i = 0; i < n_commands; ++i)
3479 : : {
3480 : 538742 : int status = statuses[i];
3481 : :
3482 : 538742 : if (WIFSIGNALED (status))
3483 : 0 : switch (WTERMSIG (status))
3484 : : {
3485 : 0 : case SIGINT:
3486 : 0 : case SIGTERM:
3487 : : /* SIGQUIT and SIGKILL are not available on MinGW. */
3488 : : #ifdef SIGQUIT
3489 : 0 : case SIGQUIT:
3490 : : #endif
3491 : : #ifdef SIGKILL
3492 : 0 : case SIGKILL:
3493 : : #endif
3494 : : /* The user (or environment) did something to the
3495 : : inferior. Making this an ICE confuses the user into
3496 : : thinking there's a compiler bug. Much more likely is
3497 : : the user or OOM killer nuked it. */
3498 : 0 : fatal_error (input_location,
3499 : : "%s signal terminated program %s",
3500 : : strsignal (WTERMSIG (status)),
3501 : 0 : commands[i].prog);
3502 : 0 : break;
3503 : :
3504 : : #ifdef SIGPIPE
3505 : 0 : case SIGPIPE:
3506 : : /* SIGPIPE is a special case. It happens in -pipe mode
3507 : : when the compiler dies before the preprocessor is
3508 : : done, or the assembler dies before the compiler is
3509 : : done. There's generally been an error already, and
3510 : : this is just fallout. So don't generate another
3511 : : error unless we would otherwise have succeeded. */
3512 : 0 : if (signal_count || greatest_status >= MIN_FATAL_STATUS)
3513 : : {
3514 : 0 : signal_count++;
3515 : 0 : ret_code = -1;
3516 : 0 : break;
3517 : : }
3518 : : #endif
3519 : : /* FALLTHROUGH */
3520 : :
3521 : 0 : default:
3522 : : /* The inferior failed to catch the signal. */
3523 : 0 : internal_error_no_backtrace ("%s signal terminated program %s",
3524 : : strsignal (WTERMSIG (status)),
3525 : 0 : commands[i].prog);
3526 : : }
3527 : 538742 : else if (WIFEXITED (status)
3528 : 538742 : && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
3529 : : {
3530 : : /* For ICEs in cc1, cc1obj, cc1plus see if it is
3531 : : reproducible or not. */
3532 : 29024 : const char *p;
3533 : 29024 : if (flag_report_bug
3534 : 0 : && WEXITSTATUS (status) == ICE_EXIT_CODE
3535 : 0 : && i == 0
3536 : 0 : && (p = strrchr (commands[0].argv[0], DIR_SEPARATOR))
3537 : 29024 : && startswith (p + 1, "cc1"))
3538 : 0 : try_generate_repro (commands[0].argv);
3539 : 29024 : if (WEXITSTATUS (status) > greatest_status)
3540 : 23 : greatest_status = WEXITSTATUS (status);
3541 : : ret_code = -1;
3542 : : }
3543 : :
3544 : 538742 : if (report_times || report_times_to_file)
3545 : : {
3546 : 0 : struct pex_time *pt = ×[i];
3547 : 0 : double ut, st;
3548 : :
3549 : 0 : ut = ((double) pt->user_seconds
3550 : 0 : + (double) pt->user_microseconds / 1.0e6);
3551 : 0 : st = ((double) pt->system_seconds
3552 : 0 : + (double) pt->system_microseconds / 1.0e6);
3553 : :
3554 : 0 : if (ut + st != 0)
3555 : : {
3556 : 0 : if (report_times)
3557 : 0 : fnotice (stderr, "# %s %.2f %.2f\n",
3558 : 0 : commands[i].prog, ut, st);
3559 : :
3560 : 0 : if (report_times_to_file)
3561 : : {
3562 : 0 : int c = 0;
3563 : 0 : const char *const *j;
3564 : :
3565 : 0 : fprintf (report_times_to_file, "%g %g", ut, st);
3566 : :
3567 : 0 : for (j = &commands[i].prog; *j; j = &commands[i].argv[++c])
3568 : : {
3569 : : const char *p;
3570 : 0 : for (p = *j; *p; ++p)
3571 : 0 : if (*p == '"' || *p == '\\' || *p == '$'
3572 : 0 : || ISSPACE (*p))
3573 : : break;
3574 : :
3575 : 0 : if (*p)
3576 : : {
3577 : 0 : fprintf (report_times_to_file, " \"");
3578 : 0 : for (p = *j; *p; ++p)
3579 : : {
3580 : 0 : if (*p == '"' || *p == '\\' || *p == '$')
3581 : 0 : fputc ('\\', report_times_to_file);
3582 : 0 : fputc (*p, report_times_to_file);
3583 : : }
3584 : 0 : fputc ('"', report_times_to_file);
3585 : : }
3586 : : else
3587 : 0 : fprintf (report_times_to_file, " %s", *j);
3588 : : }
3589 : :
3590 : 0 : fputc ('\n', report_times_to_file);
3591 : : }
3592 : : }
3593 : : }
3594 : : }
3595 : :
3596 : 538742 : if (commands[0].argv[0] != commands[0].prog)
3597 : 536193 : free (CONST_CAST (char *, commands[0].argv[0]));
3598 : :
3599 : : return ret_code;
3600 : : }
3601 : : }
3602 : :
3603 : : static struct switchstr *switches;
3604 : :
3605 : : static int n_switches;
3606 : :
3607 : : static int n_switches_alloc;
3608 : :
3609 : : /* Set to zero if -fcompare-debug is disabled, positive if it's
3610 : : enabled and we're running the first compilation, negative if it's
3611 : : enabled and we're running the second compilation. For most of the
3612 : : time, it's in the range -1..1, but it can be temporarily set to 2
3613 : : or 3 to indicate that the -fcompare-debug flags didn't come from
3614 : : the command-line, but rather from the GCC_COMPARE_DEBUG environment
3615 : : variable, until a synthesized -fcompare-debug flag is added to the
3616 : : command line. */
3617 : : int compare_debug;
3618 : :
3619 : : /* Set to nonzero if we've seen the -fcompare-debug-second flag. */
3620 : : int compare_debug_second;
3621 : :
3622 : : /* Set to the flags that should be passed to the second compilation in
3623 : : a -fcompare-debug compilation. */
3624 : : const char *compare_debug_opt;
3625 : :
3626 : : static struct switchstr *switches_debug_check[2];
3627 : :
3628 : : static int n_switches_debug_check[2];
3629 : :
3630 : : static int n_switches_alloc_debug_check[2];
3631 : :
3632 : : static char *debug_check_temp_file[2];
3633 : :
3634 : : /* Language is one of three things:
3635 : :
3636 : : 1) The name of a real programming language.
3637 : : 2) NULL, indicating that no one has figured out
3638 : : what it is yet.
3639 : : 3) '*', indicating that the file should be passed
3640 : : to the linker. */
3641 : : struct infile
3642 : : {
3643 : : const char *name;
3644 : : const char *language;
3645 : : struct compiler *incompiler;
3646 : : bool compiled;
3647 : : bool preprocessed;
3648 : : };
3649 : :
3650 : : /* Also a vector of input files specified. */
3651 : :
3652 : : static struct infile *infiles;
3653 : :
3654 : : int n_infiles;
3655 : :
3656 : : static int n_infiles_alloc;
3657 : :
3658 : : /* True if undefined environment variables encountered during spec processing
3659 : : are ok to ignore, typically when we're running for --help or --version. */
3660 : :
3661 : : static bool spec_undefvar_allowed;
3662 : :
3663 : : /* True if multiple input files are being compiled to a single
3664 : : assembly file. */
3665 : :
3666 : : static bool combine_inputs;
3667 : :
3668 : : /* This counts the number of libraries added by lang_specific_driver, so that
3669 : : we can tell if there were any user supplied any files or libraries. */
3670 : :
3671 : : static int added_libraries;
3672 : :
3673 : : /* And a vector of corresponding output files is made up later. */
3674 : :
3675 : : const char **outfiles;
3676 : :
3677 : : #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3678 : :
3679 : : /* Convert NAME to a new name if it is the standard suffix. DO_EXE
3680 : : is true if we should look for an executable suffix. DO_OBJ
3681 : : is true if we should look for an object suffix. */
3682 : :
3683 : : static const char *
3684 : : convert_filename (const char *name, int do_exe ATTRIBUTE_UNUSED,
3685 : : int do_obj ATTRIBUTE_UNUSED)
3686 : : {
3687 : : #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3688 : : int i;
3689 : : #endif
3690 : : int len;
3691 : :
3692 : : if (name == NULL)
3693 : : return NULL;
3694 : :
3695 : : len = strlen (name);
3696 : :
3697 : : #ifdef HAVE_TARGET_OBJECT_SUFFIX
3698 : : /* Convert x.o to x.obj if TARGET_OBJECT_SUFFIX is ".obj". */
3699 : : if (do_obj && len > 2
3700 : : && name[len - 2] == '.'
3701 : : && name[len - 1] == 'o')
3702 : : {
3703 : : obstack_grow (&obstack, name, len - 2);
3704 : : obstack_grow0 (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX));
3705 : : name = XOBFINISH (&obstack, const char *);
3706 : : }
3707 : : #endif
3708 : :
3709 : : #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3710 : : /* If there is no filetype, make it the executable suffix (which includes
3711 : : the "."). But don't get confused if we have just "-o". */
3712 : : if (! do_exe || TARGET_EXECUTABLE_SUFFIX[0] == 0 || not_actual_file_p (name))
3713 : : return name;
3714 : :
3715 : : for (i = len - 1; i >= 0; i--)
3716 : : if (IS_DIR_SEPARATOR (name[i]))
3717 : : break;
3718 : :
3719 : : for (i++; i < len; i++)
3720 : : if (name[i] == '.')
3721 : : return name;
3722 : :
3723 : : obstack_grow (&obstack, name, len);
3724 : : obstack_grow0 (&obstack, TARGET_EXECUTABLE_SUFFIX,
3725 : : strlen (TARGET_EXECUTABLE_SUFFIX));
3726 : : name = XOBFINISH (&obstack, const char *);
3727 : : #endif
3728 : :
3729 : : return name;
3730 : : }
3731 : : #endif
3732 : :
3733 : : /* Display the command line switches accepted by gcc. */
3734 : : static void
3735 : 4 : display_help (void)
3736 : : {
3737 : 4 : printf (_("Usage: %s [options] file...\n"), progname);
3738 : 4 : fputs (_("Options:\n"), stdout);
3739 : :
3740 : 4 : fputs (_(" -pass-exit-codes Exit with highest error code from a phase.\n"), stdout);
3741 : 4 : fputs (_(" --help Display this information.\n"), stdout);
3742 : 4 : fputs (_(" --target-help Display target specific command line options "
3743 : : "(including assembler and linker options).\n"), stdout);
3744 : 4 : fputs (_(" --help={common|optimizers|params|target|warnings|[^]{joined|separate|undocumented}}[,...].\n"), stdout);
3745 : 4 : fputs (_(" Display specific types of command line options.\n"), stdout);
3746 : 4 : if (! verbose_flag)
3747 : 1 : fputs (_(" (Use '-v --help' to display command line options of sub-processes).\n"), stdout);
3748 : 4 : fputs (_(" --version Display compiler version information.\n"), stdout);
3749 : 4 : fputs (_(" -dumpspecs Display all of the built in spec strings.\n"), stdout);
3750 : 4 : fputs (_(" -dumpversion Display the version of the compiler.\n"), stdout);
3751 : 4 : fputs (_(" -dumpmachine Display the compiler's target processor.\n"), stdout);
3752 : 4 : fputs (_(" -foffload=<targets> Specify offloading targets.\n"), stdout);
3753 : 4 : fputs (_(" -print-search-dirs Display the directories in the compiler's search path.\n"), stdout);
3754 : 4 : fputs (_(" -print-libgcc-file-name Display the name of the compiler's companion library.\n"), stdout);
3755 : 4 : fputs (_(" -print-file-name=<lib> Display the full path to library <lib>.\n"), stdout);
3756 : 4 : fputs (_(" -print-prog-name=<prog> Display the full path to compiler component <prog>.\n"), stdout);
3757 : 4 : fputs (_("\
3758 : : -print-multiarch Display the target's normalized GNU triplet, used as\n\
3759 : : a component in the library path.\n"), stdout);
3760 : 4 : fputs (_(" -print-multi-directory Display the root directory for versions of libgcc.\n"), stdout);
3761 : 4 : fputs (_("\
3762 : : -print-multi-lib Display the mapping between command line options and\n\
3763 : : multiple library search directories.\n"), stdout);
3764 : 4 : fputs (_(" -print-multi-os-directory Display the relative path to OS libraries.\n"), stdout);
3765 : 4 : fputs (_(" -print-sysroot Display the target libraries directory.\n"), stdout);
3766 : 4 : fputs (_(" -print-sysroot-headers-suffix Display the sysroot suffix used to find headers.\n"), stdout);
3767 : 4 : fputs (_(" -Wa,<options> Pass comma-separated <options> on to the assembler.\n"), stdout);
3768 : 4 : fputs (_(" -Wp,<options> Pass comma-separated <options> on to the preprocessor.\n"), stdout);
3769 : 4 : fputs (_(" -Wl,<options> Pass comma-separated <options> on to the linker.\n"), stdout);
3770 : 4 : fputs (_(" -Xassembler <arg> Pass <arg> on to the assembler.\n"), stdout);
3771 : 4 : fputs (_(" -Xpreprocessor <arg> Pass <arg> on to the preprocessor.\n"), stdout);
3772 : 4 : fputs (_(" -Xlinker <arg> Pass <arg> on to the linker.\n"), stdout);
3773 : 4 : fputs (_(" -save-temps Do not delete intermediate files.\n"), stdout);
3774 : 4 : fputs (_(" -save-temps=<arg> Do not delete intermediate files.\n"), stdout);
3775 : 4 : fputs (_("\
3776 : : -no-canonical-prefixes Do not canonicalize paths when building relative\n\
3777 : : prefixes to other gcc components.\n"), stdout);
3778 : 4 : fputs (_(" -pipe Use pipes rather than intermediate files.\n"), stdout);
3779 : 4 : fputs (_(" -time Time the execution of each subprocess.\n"), stdout);
3780 : 4 : fputs (_(" -specs=<file> Override built-in specs with the contents of <file>.\n"), stdout);
3781 : 4 : fputs (_(" -std=<standard> Assume that the input sources are for <standard>.\n"), stdout);
3782 : 4 : fputs (_("\
3783 : : --sysroot=<directory> Use <directory> as the root directory for headers\n\
3784 : : and libraries.\n"), stdout);
3785 : 4 : fputs (_(" -B <directory> Add <directory> to the compiler's search paths.\n"), stdout);
3786 : 4 : fputs (_(" -v Display the programs invoked by the compiler.\n"), stdout);
3787 : 4 : fputs (_(" -### Like -v but options quoted and commands not executed.\n"), stdout);
3788 : 4 : fputs (_(" -E Preprocess only; do not compile, assemble or link.\n"), stdout);
3789 : 4 : fputs (_(" -S Compile only; do not assemble or link.\n"), stdout);
3790 : 4 : fputs (_(" -c Compile and assemble, but do not link.\n"), stdout);
3791 : 4 : fputs (_(" -o <file> Place the output into <file>.\n"), stdout);
3792 : 4 : fputs (_(" -pie Create a dynamically linked position independent\n\
3793 : : executable.\n"), stdout);
3794 : 4 : fputs (_(" -shared Create a shared library.\n"), stdout);
3795 : 4 : fputs (_("\
3796 : : -x <language> Specify the language of the following input files.\n\
3797 : : Permissible languages include: c c++ assembler none\n\
3798 : : 'none' means revert to the default behavior of\n\
3799 : : guessing the language based on the file's extension.\n\
3800 : : "), stdout);
3801 : :
3802 : 4 : printf (_("\
3803 : : \nOptions starting with -g, -f, -m, -O, -W, or --param are automatically\n\
3804 : : passed on to the various sub-processes invoked by %s. In order to pass\n\
3805 : : other options on to these processes the -W<letter> options must be used.\n\
3806 : : "), progname);
3807 : :
3808 : : /* The rest of the options are displayed by invocations of the various
3809 : : sub-processes. */
3810 : 4 : }
3811 : :
3812 : : static void
3813 : 0 : add_preprocessor_option (const char *option, int len)
3814 : : {
3815 : 0 : preprocessor_options.safe_push (save_string (option, len));
3816 : 0 : }
3817 : :
3818 : : static void
3819 : 183 : add_assembler_option (const char *option, int len)
3820 : : {
3821 : 183 : assembler_options.safe_push (save_string (option, len));
3822 : 183 : }
3823 : :
3824 : : static void
3825 : 82 : add_linker_option (const char *option, int len)
3826 : : {
3827 : 82 : linker_options.safe_push (save_string (option, len));
3828 : 82 : }
3829 : :
3830 : : /* Allocate space for an input file in infiles. */
3831 : :
3832 : : static void
3833 : 873662 : alloc_infile (void)
3834 : : {
3835 : 873662 : if (n_infiles_alloc == 0)
3836 : : {
3837 : 295978 : n_infiles_alloc = 16;
3838 : 295978 : infiles = XNEWVEC (struct infile, n_infiles_alloc);
3839 : : }
3840 : 577684 : else if (n_infiles_alloc == n_infiles)
3841 : : {
3842 : 245 : n_infiles_alloc *= 2;
3843 : 245 : infiles = XRESIZEVEC (struct infile, infiles, n_infiles_alloc);
3844 : : }
3845 : 873662 : }
3846 : :
3847 : : /* Store an input file with the given NAME and LANGUAGE in
3848 : : infiles. */
3849 : :
3850 : : static void
3851 : 577685 : add_infile (const char *name, const char *language)
3852 : : {
3853 : 577685 : alloc_infile ();
3854 : 577685 : infiles[n_infiles].name = name;
3855 : 577685 : infiles[n_infiles++].language = language;
3856 : 577685 : }
3857 : :
3858 : : /* Allocate space for a switch in switches. */
3859 : :
3860 : : static void
3861 : 7250343 : alloc_switch (void)
3862 : : {
3863 : 7250343 : if (n_switches_alloc == 0)
3864 : : {
3865 : 296291 : n_switches_alloc = 16;
3866 : 296291 : switches = XNEWVEC (struct switchstr, n_switches_alloc);
3867 : : }
3868 : 6954052 : else if (n_switches_alloc == n_switches)
3869 : : {
3870 : 247877 : n_switches_alloc *= 2;
3871 : 247877 : switches = XRESIZEVEC (struct switchstr, switches, n_switches_alloc);
3872 : : }
3873 : 7250343 : }
3874 : :
3875 : : /* Save an option OPT with N_ARGS arguments in array ARGS, marking it
3876 : : as validated if VALIDATED and KNOWN if it is an internal switch. */
3877 : :
3878 : : static void
3879 : 6394551 : save_switch (const char *opt, size_t n_args, const char *const *args,
3880 : : bool validated, bool known)
3881 : : {
3882 : 6394551 : alloc_switch ();
3883 : 6394551 : switches[n_switches].part1 = opt + 1;
3884 : 6394551 : if (n_args == 0)
3885 : 4881389 : switches[n_switches].args = 0;
3886 : : else
3887 : : {
3888 : 1513162 : switches[n_switches].args = XNEWVEC (const char *, n_args + 1);
3889 : 1513162 : memcpy (switches[n_switches].args, args, n_args * sizeof (const char *));
3890 : 1513162 : switches[n_switches].args[n_args] = NULL;
3891 : : }
3892 : :
3893 : 6394551 : switches[n_switches].live_cond = 0;
3894 : 6394551 : switches[n_switches].validated = validated;
3895 : 6394551 : switches[n_switches].known = known;
3896 : 6394551 : switches[n_switches].ordering = 0;
3897 : 6394551 : n_switches++;
3898 : 6394551 : }
3899 : :
3900 : : /* Set the SOURCE_DATE_EPOCH environment variable to the current time if it is
3901 : : not set already. */
3902 : :
3903 : : static void
3904 : 622 : set_source_date_epoch_envvar ()
3905 : : {
3906 : : /* Array size is 21 = ceil(log_10(2^64)) + 1 to hold string representations
3907 : : of 64 bit integers. */
3908 : 622 : char source_date_epoch[21];
3909 : 622 : time_t tt;
3910 : :
3911 : 622 : errno = 0;
3912 : 622 : tt = time (NULL);
3913 : 622 : if (tt < (time_t) 0 || errno != 0)
3914 : 0 : tt = (time_t) 0;
3915 : :
3916 : 622 : snprintf (source_date_epoch, 21, "%llu", (unsigned long long) tt);
3917 : : /* Using setenv instead of xputenv because we want the variable to remain
3918 : : after finalizing so that it's still set in the second run when using
3919 : : -fcompare-debug. */
3920 : 622 : setenv ("SOURCE_DATE_EPOCH", source_date_epoch, 0);
3921 : 622 : }
3922 : :
3923 : : /* Handle an option DECODED that is unknown to the option-processing
3924 : : machinery. */
3925 : :
3926 : : static bool
3927 : 605 : driver_unknown_option_callback (const struct cl_decoded_option *decoded)
3928 : : {
3929 : 605 : const char *opt = decoded->arg;
3930 : 605 : if (opt[1] == 'W' && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-'
3931 : 93 : && !(decoded->errors & CL_ERR_NEGATIVE))
3932 : : {
3933 : : /* Leave unknown -Wno-* options for the compiler proper, to be
3934 : : diagnosed only if there are warnings. */
3935 : 91 : save_switch (decoded->canonical_option[0],
3936 : 91 : decoded->canonical_option_num_elements - 1,
3937 : : &decoded->canonical_option[1], false, true);
3938 : 91 : return false;
3939 : : }
3940 : 514 : if (decoded->opt_index == OPT_SPECIAL_unknown)
3941 : : {
3942 : : /* Give it a chance to define it a spec file. */
3943 : 514 : save_switch (decoded->canonical_option[0],
3944 : 514 : decoded->canonical_option_num_elements - 1,
3945 : : &decoded->canonical_option[1], false, false);
3946 : 514 : return false;
3947 : : }
3948 : : else
3949 : : return true;
3950 : : }
3951 : :
3952 : : /* Handle an option DECODED that is not marked as CL_DRIVER.
3953 : : LANG_MASK will always be CL_DRIVER. */
3954 : :
3955 : : static void
3956 : 4030805 : driver_wrong_lang_callback (const struct cl_decoded_option *decoded,
3957 : : unsigned int lang_mask ATTRIBUTE_UNUSED)
3958 : : {
3959 : : /* At this point, non-driver options are accepted (and expected to
3960 : : be passed down by specs) unless marked to be rejected by the
3961 : : driver. Options to be rejected by the driver but accepted by the
3962 : : compilers proper are treated just like completely unknown
3963 : : options. */
3964 : 4030805 : const struct cl_option *option = &cl_options[decoded->opt_index];
3965 : :
3966 : 4030805 : if (option->cl_reject_driver)
3967 : 0 : error ("unrecognized command-line option %qs",
3968 : 0 : decoded->orig_option_with_args_text);
3969 : : else
3970 : 4030805 : save_switch (decoded->canonical_option[0],
3971 : 4030805 : decoded->canonical_option_num_elements - 1,
3972 : : &decoded->canonical_option[1], false, true);
3973 : 4030805 : }
3974 : :
3975 : : static const char *spec_lang = 0;
3976 : : static int last_language_n_infiles;
3977 : :
3978 : :
3979 : : /* Check that GCC is configured to support the offload target. */
3980 : :
3981 : : static bool
3982 : 139 : check_offload_target_name (const char *target, ptrdiff_t len)
3983 : : {
3984 : 139 : const char *n, *c = OFFLOAD_TARGETS;
3985 : 278 : while (c)
3986 : : {
3987 : 139 : n = strchr (c, ',');
3988 : 139 : if (n == NULL)
3989 : 139 : n = strchr (c, '\0');
3990 : 139 : if (len == n - c && strncmp (target, c, n - c) == 0)
3991 : : break;
3992 : 139 : c = *n ? n + 1 : NULL;
3993 : : }
3994 : 139 : if (!c)
3995 : : {
3996 : 139 : auto_vec<const char*> candidates;
3997 : 139 : size_t olen = strlen (OFFLOAD_TARGETS) + 1;
3998 : 139 : char *cand = XALLOCAVEC (char, olen);
3999 : 139 : memcpy (cand, OFFLOAD_TARGETS, olen);
4000 : 139 : for (c = strtok (cand, ","); c; c = strtok (NULL, ","))
4001 : 0 : candidates.safe_push (c);
4002 : 139 : candidates.safe_push ("default");
4003 : 139 : candidates.safe_push ("disable");
4004 : :
4005 : 139 : char *target2 = XALLOCAVEC (char, len + 1);
4006 : 139 : memcpy (target2, target, len);
4007 : 139 : target2[len] = '\0';
4008 : :
4009 : 139 : error ("GCC is not configured to support %qs as %<-foffload=%> argument",
4010 : : target2);
4011 : :
4012 : 139 : char *s;
4013 : 139 : const char *hint = candidates_list_and_hint (target2, s, candidates);
4014 : 139 : if (hint)
4015 : 0 : inform (UNKNOWN_LOCATION,
4016 : : "valid %<-foffload=%> arguments are: %s; "
4017 : : "did you mean %qs?", s, hint);
4018 : : else
4019 : 139 : inform (UNKNOWN_LOCATION, "valid %<-foffload=%> arguments are: %s", s);
4020 : 139 : XDELETEVEC (s);
4021 : 139 : return false;
4022 : 139 : }
4023 : : return true;
4024 : : }
4025 : :
4026 : : /* Sanity check for -foffload-options. */
4027 : :
4028 : : static void
4029 : 27 : check_foffload_target_names (const char *arg)
4030 : : {
4031 : 27 : const char *cur, *next, *end;
4032 : : /* If option argument starts with '-' then no target is specified and we
4033 : : do not need to parse it. */
4034 : 27 : if (arg[0] == '-')
4035 : : return;
4036 : 0 : end = strchr (arg, '=');
4037 : 0 : if (end == NULL)
4038 : : {
4039 : 0 : error ("%<=%>options missing after %<-foffload-options=%>target");
4040 : 0 : return;
4041 : : }
4042 : :
4043 : : cur = arg;
4044 : 0 : while (cur < end)
4045 : : {
4046 : 0 : next = strchr (cur, ',');
4047 : 0 : if (next == NULL)
4048 : 0 : next = end;
4049 : 0 : next = (next > end) ? end : next;
4050 : :
4051 : : /* Retain non-supported targets after printing an error as those will not
4052 : : be processed; each enabled target only processes its triplet. */
4053 : 0 : check_offload_target_name (cur, next - cur);
4054 : 0 : cur = next + 1;
4055 : : }
4056 : : }
4057 : :
4058 : : /* Parse -foffload option argument. */
4059 : :
4060 : : static void
4061 : 2852 : handle_foffload_option (const char *arg)
4062 : : {
4063 : 2852 : const char *c, *cur, *n, *next, *end;
4064 : 2852 : char *target;
4065 : :
4066 : : /* If option argument starts with '-' then no target is specified and we
4067 : : do not need to parse it. */
4068 : 2852 : if (arg[0] == '-')
4069 : : return;
4070 : :
4071 : 2013 : end = strchr (arg, '=');
4072 : 2013 : if (end == NULL)
4073 : 2013 : end = strchr (arg, '\0');
4074 : 2013 : cur = arg;
4075 : :
4076 : 2013 : while (cur < end)
4077 : : {
4078 : 2013 : next = strchr (cur, ',');
4079 : 2013 : if (next == NULL)
4080 : 2013 : next = end;
4081 : 2013 : next = (next > end) ? end : next;
4082 : :
4083 : 2013 : target = XNEWVEC (char, next - cur + 1);
4084 : 2013 : memcpy (target, cur, next - cur);
4085 : 2013 : target[next - cur] = '\0';
4086 : :
4087 : : /* Reset offloading list and continue. */
4088 : 2013 : if (strcmp (target, "default") == 0)
4089 : : {
4090 : 0 : free (offload_targets);
4091 : 0 : offload_targets = NULL;
4092 : 0 : goto next_item;
4093 : : }
4094 : :
4095 : : /* If 'disable' is passed to the option, clean the list of
4096 : : offload targets and return, even if more targets follow.
4097 : : Likewise if GCC is not configured to support that offload target. */
4098 : 2013 : if (strcmp (target, "disable") == 0
4099 : 2013 : || !check_offload_target_name (target, next - cur))
4100 : : {
4101 : 2013 : free (offload_targets);
4102 : 2013 : offload_targets = xstrdup ("");
4103 : 2013 : return;
4104 : : }
4105 : :
4106 : 0 : if (!offload_targets)
4107 : : {
4108 : 0 : offload_targets = target;
4109 : 0 : target = NULL;
4110 : : }
4111 : : else
4112 : : {
4113 : : /* Check that the target hasn't already presented in the list. */
4114 : : c = offload_targets;
4115 : 0 : do
4116 : : {
4117 : 0 : n = strchr (c, ':');
4118 : 0 : if (n == NULL)
4119 : 0 : n = strchr (c, '\0');
4120 : :
4121 : 0 : if (next - cur == n - c && strncmp (c, target, n - c) == 0)
4122 : : break;
4123 : :
4124 : 0 : c = n + 1;
4125 : : }
4126 : 0 : while (*n);
4127 : :
4128 : : /* If duplicate is not found, append the target to the list. */
4129 : 0 : if (c > n)
4130 : : {
4131 : 0 : size_t offload_targets_len = strlen (offload_targets);
4132 : 0 : offload_targets
4133 : 0 : = XRESIZEVEC (char, offload_targets,
4134 : : offload_targets_len + 1 + next - cur + 1);
4135 : 0 : offload_targets[offload_targets_len++] = ':';
4136 : 0 : memcpy (offload_targets + offload_targets_len, target, next - cur + 1);
4137 : : }
4138 : : }
4139 : 0 : next_item:
4140 : 0 : cur = next + 1;
4141 : 0 : XDELETEVEC (target);
4142 : : }
4143 : : }
4144 : :
4145 : : /* Forward certain options to offloading compilation. */
4146 : :
4147 : : static void
4148 : 0 : forward_offload_option (size_t opt_index, const char *arg, bool validated)
4149 : : {
4150 : 0 : switch (opt_index)
4151 : : {
4152 : 0 : case OPT_l:
4153 : : /* Use a '_GCC_' prefix and standard name ('-l_GCC_m' irrespective of the
4154 : : host's 'MATH_LIBRARY', for example), so that the 'mkoffload's can tell
4155 : : this has been synthesized here, and translate/drop as necessary. */
4156 : : /* Note that certain libraries ('-lc', '-lgcc', '-lgomp', for example)
4157 : : are injected by default in offloading compilation, and therefore not
4158 : : forwarded here. */
4159 : : /* GCC libraries. */
4160 : 0 : if (/* '-lgfortran' */ strcmp (arg, "gfortran") == 0
4161 : 0 : || /* '-lstdc++' */ strcmp (arg, "stdc++") == 0)
4162 : 0 : save_switch (concat ("-foffload-options=-l_GCC_", arg, NULL),
4163 : : 0, NULL, validated, true);
4164 : : /* Other libraries. */
4165 : : else
4166 : : {
4167 : : /* The case will need special consideration where on the host
4168 : : '!need_math', but for offloading compilation still need
4169 : : '-foffload-options=-l_GCC_m'. The problem is that we don't get
4170 : : here anything like '-lm', because it's not synthesized in
4171 : : 'gcc/fortran/gfortranspec.cc:lang_specific_driver', for example.
4172 : : Generally synthesizing '-foffload-options=-l_GCC_m' etc. in the
4173 : : language specific drivers is non-trivial, needs very careful
4174 : : review of their options handling. However, this issue is not
4175 : : actually relevant for the current set of supported host/offloading
4176 : : configurations. */
4177 : 0 : int need_math = (MATH_LIBRARY[0] != '\0');
4178 : 0 : if (/* '-lm' */ (need_math && strcmp (arg, MATH_LIBRARY) == 0))
4179 : 0 : save_switch ("-foffload-options=-l_GCC_m",
4180 : : 0, NULL, validated, true);
4181 : : }
4182 : 0 : break;
4183 : 0 : default:
4184 : 0 : gcc_unreachable ();
4185 : : }
4186 : 0 : }
4187 : :
4188 : : /* Handle a driver option; arguments and return value as for
4189 : : handle_option. */
4190 : :
4191 : : static bool
4192 : 2695877 : driver_handle_option (struct gcc_options *opts,
4193 : : struct gcc_options *opts_set,
4194 : : const struct cl_decoded_option *decoded,
4195 : : unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
4196 : : location_t loc,
4197 : : const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED,
4198 : : diagnostic_context *dc,
4199 : : void (*) (void))
4200 : : {
4201 : 2695877 : size_t opt_index = decoded->opt_index;
4202 : 2695877 : const char *arg = decoded->arg;
4203 : 2695877 : const char *compare_debug_replacement_opt;
4204 : 2695877 : int value = decoded->value;
4205 : 2695877 : bool validated = false;
4206 : 2695877 : bool do_save = true;
4207 : :
4208 : 2695877 : gcc_assert (opts == &global_options);
4209 : 2695877 : gcc_assert (opts_set == &global_options_set);
4210 : 2695877 : gcc_assert (kind == DK_UNSPECIFIED);
4211 : 2695877 : gcc_assert (loc == UNKNOWN_LOCATION);
4212 : 2695877 : gcc_assert (dc == global_dc);
4213 : :
4214 : 2695877 : switch (opt_index)
4215 : : {
4216 : 1 : case OPT_dumpspecs:
4217 : 1 : {
4218 : 1 : struct spec_list *sl;
4219 : 1 : init_spec ();
4220 : 47 : for (sl = specs; sl; sl = sl->next)
4221 : 46 : printf ("*%s:\n%s\n\n", sl->name, *(sl->ptr_spec));
4222 : 1 : if (link_command_spec)
4223 : 1 : printf ("*link_command:\n%s\n\n", link_command_spec);
4224 : 1 : exit (0);
4225 : : }
4226 : :
4227 : 280 : case OPT_dumpversion:
4228 : 280 : printf ("%s\n", spec_version);
4229 : 280 : exit (0);
4230 : :
4231 : 0 : case OPT_dumpmachine:
4232 : 0 : printf ("%s\n", spec_machine);
4233 : 0 : exit (0);
4234 : :
4235 : 0 : case OPT_dumpfullversion:
4236 : 0 : printf ("%s\n", BASEVER);
4237 : 0 : exit (0);
4238 : :
4239 : 78 : case OPT__version:
4240 : 78 : print_version = 1;
4241 : :
4242 : : /* CPP driver cannot obtain switch from cc1_options. */
4243 : 78 : if (is_cpp_driver)
4244 : 0 : add_preprocessor_option ("--version", strlen ("--version"));
4245 : 78 : add_assembler_option ("--version", strlen ("--version"));
4246 : 78 : add_linker_option ("--version", strlen ("--version"));
4247 : 78 : break;
4248 : :
4249 : 5 : case OPT__completion_:
4250 : 5 : validated = true;
4251 : 5 : completion = decoded->arg;
4252 : 5 : break;
4253 : :
4254 : 4 : case OPT__help:
4255 : 4 : print_help_list = 1;
4256 : :
4257 : : /* CPP driver cannot obtain switch from cc1_options. */
4258 : 4 : if (is_cpp_driver)
4259 : 0 : add_preprocessor_option ("--help", 6);
4260 : 4 : add_assembler_option ("--help", 6);
4261 : 4 : add_linker_option ("--help", 6);
4262 : 4 : break;
4263 : :
4264 : 98 : case OPT__help_:
4265 : 98 : print_subprocess_help = 2;
4266 : 98 : break;
4267 : :
4268 : 0 : case OPT__target_help:
4269 : 0 : print_subprocess_help = 1;
4270 : :
4271 : : /* CPP driver cannot obtain switch from cc1_options. */
4272 : 0 : if (is_cpp_driver)
4273 : 0 : add_preprocessor_option ("--target-help", 13);
4274 : 0 : add_assembler_option ("--target-help", 13);
4275 : 0 : add_linker_option ("--target-help", 13);
4276 : 0 : break;
4277 : :
4278 : : case OPT__no_sysroot_suffix:
4279 : : case OPT_pass_exit_codes:
4280 : : case OPT_print_search_dirs:
4281 : : case OPT_print_file_name_:
4282 : : case OPT_print_prog_name_:
4283 : : case OPT_print_multi_lib:
4284 : : case OPT_print_multi_directory:
4285 : : case OPT_print_sysroot:
4286 : : case OPT_print_multi_os_directory:
4287 : : case OPT_print_multiarch:
4288 : : case OPT_print_sysroot_headers_suffix:
4289 : : case OPT_time:
4290 : : case OPT_wrapper:
4291 : : /* These options set the variables specified in common.opt
4292 : : automatically, and do not need to be saved for spec
4293 : : processing. */
4294 : : do_save = false;
4295 : : break;
4296 : :
4297 : 392 : case OPT_print_libgcc_file_name:
4298 : 392 : print_file_name = "libgcc.a";
4299 : 392 : do_save = false;
4300 : 392 : break;
4301 : :
4302 : 0 : case OPT_fuse_ld_bfd:
4303 : 0 : use_ld = ".bfd";
4304 : 0 : break;
4305 : :
4306 : 0 : case OPT_fuse_ld_gold:
4307 : 0 : use_ld = ".gold";
4308 : 0 : break;
4309 : :
4310 : 0 : case OPT_fuse_ld_mold:
4311 : 0 : use_ld = ".mold";
4312 : 0 : break;
4313 : :
4314 : 0 : case OPT_fcompare_debug_second:
4315 : 0 : compare_debug_second = 1;
4316 : 0 : break;
4317 : :
4318 : 616 : case OPT_fcompare_debug:
4319 : 616 : switch (value)
4320 : : {
4321 : 0 : case 0:
4322 : 0 : compare_debug_replacement_opt = "-fcompare-debug=";
4323 : 0 : arg = "";
4324 : 0 : goto compare_debug_with_arg;
4325 : :
4326 : 616 : case 1:
4327 : 616 : compare_debug_replacement_opt = "-fcompare-debug=-gtoggle";
4328 : 616 : arg = "-gtoggle";
4329 : 616 : goto compare_debug_with_arg;
4330 : :
4331 : 0 : default:
4332 : 0 : gcc_unreachable ();
4333 : : }
4334 : 6 : break;
4335 : :
4336 : 6 : case OPT_fcompare_debug_:
4337 : 6 : compare_debug_replacement_opt = decoded->canonical_option[0];
4338 : 622 : compare_debug_with_arg:
4339 : 622 : gcc_assert (decoded->canonical_option_num_elements == 1);
4340 : 622 : gcc_assert (arg != NULL);
4341 : 622 : if (*arg)
4342 : 622 : compare_debug = 1;
4343 : : else
4344 : 0 : compare_debug = -1;
4345 : 622 : if (compare_debug < 0)
4346 : 0 : compare_debug_opt = NULL;
4347 : : else
4348 : 622 : compare_debug_opt = arg;
4349 : 622 : save_switch (compare_debug_replacement_opt, 0, NULL, validated, true);
4350 : 622 : set_source_date_epoch_envvar ();
4351 : 622 : return true;
4352 : :
4353 : 267205 : case OPT_fdiagnostics_color_:
4354 : 267205 : diagnostic_color_init (dc, value);
4355 : 267205 : break;
4356 : :
4357 : 261580 : case OPT_fdiagnostics_urls_:
4358 : 261580 : diagnostic_urls_init (dc, value);
4359 : 261580 : break;
4360 : :
4361 : 0 : case OPT_fdiagnostics_show_highlight_colors:
4362 : 0 : dc->set_show_highlight_colors (value);
4363 : 0 : break;
4364 : :
4365 : 0 : case OPT_fdiagnostics_format_:
4366 : 0 : {
4367 : 0 : const char *basename = (opts->x_dump_base_name ? opts->x_dump_base_name
4368 : : : opts->x_main_input_basename);
4369 : 0 : gcc_assert (dc);
4370 : 0 : diagnostic_output_format_init (*dc,
4371 : : opts->x_main_input_filename, basename,
4372 : : (enum diagnostics_output_format)value,
4373 : 0 : opts->x_flag_diagnostics_json_formatting);
4374 : 0 : break;
4375 : : }
4376 : :
4377 : 0 : case OPT_fdiagnostics_add_output_:
4378 : 0 : handle_OPT_fdiagnostics_add_output_ (*opts, *dc, arg, loc);
4379 : 0 : break;
4380 : :
4381 : 0 : case OPT_fdiagnostics_set_output_:
4382 : 0 : handle_OPT_fdiagnostics_set_output_ (*opts, *dc, arg, loc);
4383 : 0 : break;
4384 : :
4385 : 289703 : case OPT_fdiagnostics_text_art_charset_:
4386 : 289703 : dc->set_text_art_charset ((enum diagnostic_text_art_charset)value);
4387 : 289703 : break;
4388 : :
4389 : : case OPT_Wa_:
4390 : : {
4391 : : int prev, j;
4392 : : /* Pass the rest of this option to the assembler. */
4393 : :
4394 : : /* Split the argument at commas. */
4395 : : prev = 0;
4396 : 466 : for (j = 0; arg[j]; j++)
4397 : 430 : if (arg[j] == ',')
4398 : : {
4399 : 0 : add_assembler_option (arg + prev, j - prev);
4400 : 0 : prev = j + 1;
4401 : : }
4402 : :
4403 : : /* Record the part after the last comma. */
4404 : 36 : add_assembler_option (arg + prev, j - prev);
4405 : : }
4406 : 36 : do_save = false;
4407 : 36 : break;
4408 : :
4409 : : case OPT_Wp_:
4410 : : {
4411 : : int prev, j;
4412 : : /* Pass the rest of this option to the preprocessor. */
4413 : :
4414 : : /* Split the argument at commas. */
4415 : : prev = 0;
4416 : 0 : for (j = 0; arg[j]; j++)
4417 : 0 : if (arg[j] == ',')
4418 : : {
4419 : 0 : add_preprocessor_option (arg + prev, j - prev);
4420 : 0 : prev = j + 1;
4421 : : }
4422 : :
4423 : : /* Record the part after the last comma. */
4424 : 0 : add_preprocessor_option (arg + prev, j - prev);
4425 : : }
4426 : 0 : do_save = false;
4427 : 0 : break;
4428 : :
4429 : : case OPT_Wl_:
4430 : : {
4431 : : int prev, j;
4432 : : /* Split the argument at commas. */
4433 : : prev = 0;
4434 : 128060 : for (j = 0; arg[j]; j++)
4435 : 120361 : if (arg[j] == ',')
4436 : : {
4437 : 42 : add_infile (save_string (arg + prev, j - prev), "*");
4438 : 42 : prev = j + 1;
4439 : : }
4440 : : /* Record the part after the last comma. */
4441 : 7699 : add_infile (arg + prev, "*");
4442 : 7699 : if (strcmp (arg, "-z,lazy") == 0 || strcmp (arg, "-z,norelro") == 0)
4443 : 12 : avoid_linker_hardening_p = true;
4444 : : }
4445 : : do_save = false;
4446 : : break;
4447 : :
4448 : 12 : case OPT_z:
4449 : 12 : if (strcmp (arg, "lazy") == 0 || strcmp (arg, "norelro") == 0)
4450 : 12 : avoid_linker_hardening_p = true;
4451 : : break;
4452 : :
4453 : 0 : case OPT_Xlinker:
4454 : 0 : add_infile (arg, "*");
4455 : 0 : do_save = false;
4456 : 0 : break;
4457 : :
4458 : 0 : case OPT_Xpreprocessor:
4459 : 0 : add_preprocessor_option (arg, strlen (arg));
4460 : 0 : do_save = false;
4461 : 0 : break;
4462 : :
4463 : 65 : case OPT_Xassembler:
4464 : 65 : add_assembler_option (arg, strlen (arg));
4465 : 65 : do_save = false;
4466 : 65 : break;
4467 : :
4468 : 250881 : case OPT_l:
4469 : : /* POSIX allows separation of -l and the lib arg; canonicalize
4470 : : by concatenating -l with its arg */
4471 : 250881 : add_infile (concat ("-l", arg, NULL), "*");
4472 : :
4473 : : /* Forward to offloading compilation '-l[...]' flags for standard,
4474 : : well-known libraries. */
4475 : : /* Doing this processing here means that we don't get to see libraries
4476 : : injected via specs, such as '-lquadmath' injected via
4477 : : '[build]/[target]/libgfortran/libgfortran.spec'. However, this issue
4478 : : is not actually relevant for the current set of host/offloading
4479 : : configurations. */
4480 : 250881 : if (ENABLE_OFFLOADING)
4481 : : forward_offload_option (opt_index, arg, validated);
4482 : :
4483 : 250881 : do_save = false;
4484 : 250881 : break;
4485 : :
4486 : 260983 : case OPT_L:
4487 : : /* Similarly, canonicalize -L for linkers that may not accept
4488 : : separate arguments. */
4489 : 260983 : save_switch (concat ("-L", arg, NULL), 0, NULL, validated, true);
4490 : 260983 : return true;
4491 : :
4492 : 0 : case OPT_F:
4493 : : /* Likewise -F. */
4494 : 0 : save_switch (concat ("-F", arg, NULL), 0, NULL, validated, true);
4495 : 0 : return true;
4496 : :
4497 : 403 : case OPT_save_temps:
4498 : 403 : if (!save_temps_flag)
4499 : 397 : save_temps_flag = SAVE_TEMPS_DUMP;
4500 : : validated = true;
4501 : : break;
4502 : :
4503 : 58 : case OPT_save_temps_:
4504 : 58 : if (strcmp (arg, "cwd") == 0)
4505 : 29 : save_temps_flag = SAVE_TEMPS_CWD;
4506 : 29 : else if (strcmp (arg, "obj") == 0
4507 : 0 : || strcmp (arg, "object") == 0)
4508 : 29 : save_temps_flag = SAVE_TEMPS_OBJ;
4509 : : else
4510 : 0 : fatal_error (input_location, "%qs is an unknown %<-save-temps%> option",
4511 : 0 : decoded->orig_option_with_args_text);
4512 : 58 : save_temps_overrides_dumpdir = true;
4513 : 58 : break;
4514 : :
4515 : 22056 : case OPT_dumpdir:
4516 : 22056 : free (dumpdir);
4517 : 22056 : dumpdir = xstrdup (arg);
4518 : 22056 : save_temps_overrides_dumpdir = false;
4519 : 22056 : break;
4520 : :
4521 : 23479 : case OPT_dumpbase:
4522 : 23479 : free (dumpbase);
4523 : 23479 : dumpbase = xstrdup (arg);
4524 : 23479 : break;
4525 : :
4526 : 250 : case OPT_dumpbase_ext:
4527 : 250 : free (dumpbase_ext);
4528 : 250 : dumpbase_ext = xstrdup (arg);
4529 : 250 : break;
4530 : :
4531 : : case OPT_no_canonical_prefixes:
4532 : : /* Already handled as a special case, so ignored here. */
4533 : : do_save = false;
4534 : : break;
4535 : :
4536 : : case OPT_pipe:
4537 : : validated = true;
4538 : : /* These options set the variables specified in common.opt
4539 : : automatically, but do need to be saved for spec
4540 : : processing. */
4541 : : break;
4542 : :
4543 : 3 : case OPT_specs_:
4544 : 3 : {
4545 : 3 : struct user_specs *user = XNEW (struct user_specs);
4546 : :
4547 : 3 : user->next = (struct user_specs *) 0;
4548 : 3 : user->filename = arg;
4549 : 3 : if (user_specs_tail)
4550 : 0 : user_specs_tail->next = user;
4551 : : else
4552 : 3 : user_specs_head = user;
4553 : 3 : user_specs_tail = user;
4554 : : }
4555 : 3 : validated = true;
4556 : 3 : break;
4557 : :
4558 : 0 : case OPT__sysroot_:
4559 : 0 : target_system_root = arg;
4560 : 0 : target_system_root_changed = 1;
4561 : : /* Saving this option is useful to let self-specs decide to
4562 : : provide a default one. */
4563 : 0 : do_save = true;
4564 : 0 : validated = true;
4565 : 0 : break;
4566 : :
4567 : 0 : case OPT_time_:
4568 : 0 : if (report_times_to_file)
4569 : 0 : fclose (report_times_to_file);
4570 : 0 : report_times_to_file = fopen (arg, "a");
4571 : 0 : do_save = false;
4572 : 0 : break;
4573 : :
4574 : 8915 : case OPT_truncate:
4575 : 8915 : totruncate_file = arg;
4576 : 8915 : do_save = false;
4577 : 8915 : break;
4578 : :
4579 : 640 : case OPT____:
4580 : : /* "-###"
4581 : : This is similar to -v except that there is no execution
4582 : : of the commands and the echoed arguments are quoted. It
4583 : : is intended for use in shell scripts to capture the
4584 : : driver-generated command line. */
4585 : 640 : verbose_only_flag++;
4586 : 640 : verbose_flag = 1;
4587 : 640 : do_save = false;
4588 : 640 : break;
4589 : :
4590 : 486017 : case OPT_B:
4591 : 486017 : {
4592 : 486017 : size_t len = strlen (arg);
4593 : :
4594 : : /* Catch the case where the user has forgotten to append a
4595 : : directory separator to the path. Note, they may be using
4596 : : -B to add an executable name prefix, eg "i386-elf-", in
4597 : : order to distinguish between multiple installations of
4598 : : GCC in the same directory. Hence we must check to see
4599 : : if appending a directory separator actually makes a
4600 : : valid directory name. */
4601 : 486017 : if (!IS_DIR_SEPARATOR (arg[len - 1])
4602 : 486017 : && is_directory (arg))
4603 : : {
4604 : 95940 : char *tmp = XNEWVEC (char, len + 2);
4605 : 95940 : strcpy (tmp, arg);
4606 : 95940 : tmp[len] = DIR_SEPARATOR;
4607 : 95940 : tmp[++len] = 0;
4608 : 95940 : arg = tmp;
4609 : : }
4610 : :
4611 : 486017 : add_prefix (&exec_prefixes, arg, NULL,
4612 : : PREFIX_PRIORITY_B_OPT, 0, 0);
4613 : 486017 : add_prefix (&startfile_prefixes, arg, NULL,
4614 : : PREFIX_PRIORITY_B_OPT, 0, 0);
4615 : 486017 : add_prefix (&include_prefixes, arg, NULL,
4616 : : PREFIX_PRIORITY_B_OPT, 0, 0);
4617 : : }
4618 : 486017 : validated = true;
4619 : 486017 : break;
4620 : :
4621 : 2325 : case OPT_E:
4622 : 2325 : have_E = true;
4623 : 2325 : break;
4624 : :
4625 : 49847 : case OPT_x:
4626 : 49847 : spec_lang = arg;
4627 : 49847 : if (!strcmp (spec_lang, "none"))
4628 : : /* Suppress the warning if -xnone comes after the last input
4629 : : file, because alternate command interfaces like g++ might
4630 : : find it useful to place -xnone after each input file. */
4631 : 13133 : spec_lang = 0;
4632 : : else
4633 : 36714 : last_language_n_infiles = n_infiles;
4634 : : do_save = false;
4635 : : break;
4636 : :
4637 : 269061 : case OPT_o:
4638 : 269061 : have_o = 1;
4639 : : #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) || defined(HAVE_TARGET_OBJECT_SUFFIX)
4640 : : arg = convert_filename (arg, ! have_c, 0);
4641 : : #endif
4642 : 269061 : output_file = arg;
4643 : : /* On some systems, ld cannot handle "-o" without a space. So
4644 : : split the option from its argument. */
4645 : 269061 : save_switch ("-o", 1, &arg, validated, true);
4646 : 269061 : return true;
4647 : :
4648 : 2060 : case OPT_pie:
4649 : : #ifdef ENABLE_DEFAULT_PIE
4650 : : /* -pie is turned on by default. */
4651 : : validated = true;
4652 : : #endif
4653 : : /* FALLTHROUGH */
4654 : 2060 : case OPT_r:
4655 : 2060 : case OPT_shared:
4656 : 2060 : case OPT_no_pie:
4657 : 2060 : avoid_linker_hardening_p = true;
4658 : 2060 : break;
4659 : :
4660 : 103 : case OPT_static:
4661 : 103 : static_p = true;
4662 : 103 : break;
4663 : :
4664 : : case OPT_static_libgcc:
4665 : : case OPT_shared_libgcc:
4666 : : case OPT_static_libgfortran:
4667 : : case OPT_static_libquadmath:
4668 : : case OPT_static_libphobos:
4669 : : case OPT_static_libgm2:
4670 : : case OPT_static_libstdc__:
4671 : : /* These are always valid; gcc.cc itself understands the first two
4672 : : gfortranspec.cc understands -static-libgfortran,
4673 : : libgfortran.spec handles -static-libquadmath,
4674 : : d-spec.cc understands -static-libphobos,
4675 : : gm2spec.cc understands -static-libgm2,
4676 : : and g++spec.cc understands -static-libstdc++. */
4677 : : validated = true;
4678 : : break;
4679 : :
4680 : 78 : case OPT_fwpa:
4681 : 78 : flag_wpa = "";
4682 : 78 : break;
4683 : :
4684 : 27 : case OPT_foffload_options_:
4685 : 27 : check_foffload_target_names (arg);
4686 : 27 : break;
4687 : :
4688 : 2852 : case OPT_foffload_:
4689 : 2852 : handle_foffload_option (arg);
4690 : 2852 : if (arg[0] == '-' || NULL != strchr (arg, '='))
4691 : 839 : save_switch (concat ("-foffload-options=", arg, NULL),
4692 : : 0, NULL, validated, true);
4693 : : do_save = false;
4694 : : break;
4695 : :
4696 : 0 : case OPT_gcodeview:
4697 : 0 : add_infile ("--pdb=", "*");
4698 : 0 : break;
4699 : :
4700 : : default:
4701 : : /* Various driver options need no special processing at this
4702 : : point, having been handled in a prescan above or being
4703 : : handled by specs. */
4704 : : break;
4705 : : }
4706 : :
4707 : 1616070 : if (do_save)
4708 : 1830325 : save_switch (decoded->canonical_option[0],
4709 : 1830325 : decoded->canonical_option_num_elements - 1,
4710 : : &decoded->canonical_option[1], validated, true);
4711 : : return true;
4712 : : }
4713 : :
4714 : : /* Return true if F2 is F1 followed by a single suffix, i.e., by a
4715 : : period and additional characters other than a period. */
4716 : :
4717 : : static inline bool
4718 : 83930 : adds_single_suffix_p (const char *f2, const char *f1)
4719 : : {
4720 : 83930 : size_t len = strlen (f1);
4721 : :
4722 : 83930 : return (strncmp (f1, f2, len) == 0
4723 : 75805 : && f2[len] == '.'
4724 : 159278 : && strchr (f2 + len + 1, '.') == NULL);
4725 : : }
4726 : :
4727 : : /* Put the driver's standard set of option handlers in *HANDLERS. */
4728 : :
4729 : : static void
4730 : 856074 : set_option_handlers (struct cl_option_handlers *handlers)
4731 : : {
4732 : 856074 : handlers->unknown_option_callback = driver_unknown_option_callback;
4733 : 856074 : handlers->wrong_lang_callback = driver_wrong_lang_callback;
4734 : 856074 : handlers->num_handlers = 3;
4735 : 856074 : handlers->handlers[0].handler = driver_handle_option;
4736 : 856074 : handlers->handlers[0].mask = CL_DRIVER;
4737 : 856074 : handlers->handlers[1].handler = common_handle_option;
4738 : 856074 : handlers->handlers[1].mask = CL_COMMON;
4739 : 856074 : handlers->handlers[2].handler = target_handle_option;
4740 : 856074 : handlers->handlers[2].mask = CL_TARGET;
4741 : 0 : }
4742 : :
4743 : :
4744 : : /* Return the index into infiles for the single non-library
4745 : : non-lto-wpa input file, -1 if there isn't any, or -2 if there is
4746 : : more than one. */
4747 : : static inline int
4748 : 151555 : single_input_file_index ()
4749 : : {
4750 : 151555 : int ret = -1;
4751 : :
4752 : 488527 : for (int i = 0; i < n_infiles; i++)
4753 : : {
4754 : 349277 : if (infiles[i].language
4755 : 244453 : && (infiles[i].language[0] == '*'
4756 : 48632 : || (flag_wpa
4757 : 18684 : && strcmp (infiles[i].language, "lto") == 0)))
4758 : 214505 : continue;
4759 : :
4760 : 134772 : if (ret != -1)
4761 : : return -2;
4762 : :
4763 : : ret = i;
4764 : : }
4765 : :
4766 : : return ret;
4767 : : }
4768 : :
4769 : : /* Create the vector `switches' and its contents.
4770 : : Store its length in `n_switches'. */
4771 : :
4772 : : static void
4773 : 296263 : process_command (unsigned int decoded_options_count,
4774 : : struct cl_decoded_option *decoded_options)
4775 : : {
4776 : 296263 : const char *temp;
4777 : 296263 : char *temp1;
4778 : 296263 : char *tooldir_prefix, *tooldir_prefix2;
4779 : 296263 : char *(*get_relative_prefix) (const char *, const char *,
4780 : : const char *) = NULL;
4781 : 296263 : struct cl_option_handlers handlers;
4782 : 296263 : unsigned int j;
4783 : :
4784 : 296263 : gcc_exec_prefix = env.get ("GCC_EXEC_PREFIX");
4785 : :
4786 : 296263 : n_switches = 0;
4787 : 296263 : n_infiles = 0;
4788 : 296263 : added_libraries = 0;
4789 : :
4790 : : /* Figure compiler version from version string. */
4791 : :
4792 : 296263 : compiler_version = temp1 = xstrdup (version_string);
4793 : :
4794 : 2073841 : for (; *temp1; ++temp1)
4795 : : {
4796 : 2073841 : if (*temp1 == ' ')
4797 : : {
4798 : 296263 : *temp1 = '\0';
4799 : 296263 : break;
4800 : : }
4801 : : }
4802 : :
4803 : : /* Handle any -no-canonical-prefixes flag early, to assign the function
4804 : : that builds relative prefixes. This function creates default search
4805 : : paths that are needed later in normal option handling. */
4806 : :
4807 : 6411700 : for (j = 1; j < decoded_options_count; j++)
4808 : : {
4809 : 6115437 : if (decoded_options[j].opt_index == OPT_no_canonical_prefixes)
4810 : : {
4811 : : get_relative_prefix = make_relative_prefix_ignore_links;
4812 : : break;
4813 : : }
4814 : : }
4815 : 296263 : if (! get_relative_prefix)
4816 : 296263 : get_relative_prefix = make_relative_prefix;
4817 : :
4818 : : /* Set up the default search paths. If there is no GCC_EXEC_PREFIX,
4819 : : see if we can create it from the pathname specified in
4820 : : decoded_options[0].arg. */
4821 : :
4822 : 296263 : gcc_libexec_prefix = standard_libexec_prefix;
4823 : : #ifndef VMS
4824 : : /* FIXME: make_relative_prefix doesn't yet work for VMS. */
4825 : 296263 : if (!gcc_exec_prefix)
4826 : : {
4827 : 28750 : gcc_exec_prefix = get_relative_prefix (decoded_options[0].arg,
4828 : : standard_bindir_prefix,
4829 : : standard_exec_prefix);
4830 : 28750 : gcc_libexec_prefix = get_relative_prefix (decoded_options[0].arg,
4831 : : standard_bindir_prefix,
4832 : : standard_libexec_prefix);
4833 : 28750 : if (gcc_exec_prefix)
4834 : 28750 : xputenv (concat ("GCC_EXEC_PREFIX=", gcc_exec_prefix, NULL));
4835 : : }
4836 : : else
4837 : : {
4838 : : /* make_relative_prefix requires a program name, but
4839 : : GCC_EXEC_PREFIX is typically a directory name with a trailing
4840 : : / (which is ignored by make_relative_prefix), so append a
4841 : : program name. */
4842 : 267513 : char *tmp_prefix = concat (gcc_exec_prefix, "gcc", NULL);
4843 : 267513 : gcc_libexec_prefix = get_relative_prefix (tmp_prefix,
4844 : : standard_exec_prefix,
4845 : : standard_libexec_prefix);
4846 : :
4847 : : /* The path is unrelocated, so fallback to the original setting. */
4848 : 267513 : if (!gcc_libexec_prefix)
4849 : 267168 : gcc_libexec_prefix = standard_libexec_prefix;
4850 : :
4851 : 267513 : free (tmp_prefix);
4852 : : }
4853 : : #else
4854 : : #endif
4855 : : /* From this point onward, gcc_exec_prefix is non-null if the toolchain
4856 : : is relocated. The toolchain was either relocated using GCC_EXEC_PREFIX
4857 : : or an automatically created GCC_EXEC_PREFIX from
4858 : : decoded_options[0].arg. */
4859 : :
4860 : : /* Do language-specific adjustment/addition of flags. */
4861 : 296263 : lang_specific_driver (&decoded_options, &decoded_options_count,
4862 : : &added_libraries);
4863 : :
4864 : 296259 : if (gcc_exec_prefix)
4865 : : {
4866 : 296259 : int len = strlen (gcc_exec_prefix);
4867 : :
4868 : 296259 : if (len > (int) sizeof ("/lib/gcc/") - 1
4869 : 296259 : && (IS_DIR_SEPARATOR (gcc_exec_prefix[len-1])))
4870 : : {
4871 : 296259 : temp = gcc_exec_prefix + len - sizeof ("/lib/gcc/") + 1;
4872 : 296259 : if (IS_DIR_SEPARATOR (*temp)
4873 : 296259 : && filename_ncmp (temp + 1, "lib", 3) == 0
4874 : 296259 : && IS_DIR_SEPARATOR (temp[4])
4875 : 592518 : && filename_ncmp (temp + 5, "gcc", 3) == 0)
4876 : 296259 : len -= sizeof ("/lib/gcc/") - 1;
4877 : : }
4878 : :
4879 : 296259 : set_std_prefix (gcc_exec_prefix, len);
4880 : 296259 : add_prefix (&exec_prefixes, gcc_libexec_prefix, "GCC",
4881 : : PREFIX_PRIORITY_LAST, 0, 0);
4882 : 296259 : add_prefix (&startfile_prefixes, gcc_exec_prefix, "GCC",
4883 : : PREFIX_PRIORITY_LAST, 0, 0);
4884 : : }
4885 : :
4886 : : /* COMPILER_PATH and LIBRARY_PATH have values
4887 : : that are lists of directory names with colons. */
4888 : :
4889 : 296259 : temp = env.get ("COMPILER_PATH");
4890 : 296259 : if (temp)
4891 : : {
4892 : 21892 : const char *startp, *endp;
4893 : 21892 : char *nstore = (char *) alloca (strlen (temp) + 3);
4894 : :
4895 : 21892 : startp = endp = temp;
4896 : 1997120 : while (1)
4897 : : {
4898 : 1997120 : if (*endp == PATH_SEPARATOR || *endp == 0)
4899 : : {
4900 : 35596 : strncpy (nstore, startp, endp - startp);
4901 : 35596 : if (endp == startp)
4902 : 0 : strcpy (nstore, concat (".", dir_separator_str, NULL));
4903 : 35596 : else if (!IS_DIR_SEPARATOR (endp[-1]))
4904 : : {
4905 : 0 : nstore[endp - startp] = DIR_SEPARATOR;
4906 : 0 : nstore[endp - startp + 1] = 0;
4907 : : }
4908 : : else
4909 : 35596 : nstore[endp - startp] = 0;
4910 : 35596 : add_prefix (&exec_prefixes, nstore, 0,
4911 : : PREFIX_PRIORITY_LAST, 0, 0);
4912 : 35596 : add_prefix (&include_prefixes, nstore, 0,
4913 : : PREFIX_PRIORITY_LAST, 0, 0);
4914 : 35596 : if (*endp == 0)
4915 : : break;
4916 : 13704 : endp = startp = endp + 1;
4917 : : }
4918 : : else
4919 : 1961524 : endp++;
4920 : : }
4921 : : }
4922 : :
4923 : 296259 : temp = env.get (LIBRARY_PATH_ENV);
4924 : 296259 : if (temp && *cross_compile == '0')
4925 : : {
4926 : 23205 : const char *startp, *endp;
4927 : 23205 : char *nstore = (char *) alloca (strlen (temp) + 3);
4928 : :
4929 : 23205 : startp = endp = temp;
4930 : 4032486 : while (1)
4931 : : {
4932 : 4032486 : if (*endp == PATH_SEPARATOR || *endp == 0)
4933 : : {
4934 : 167571 : strncpy (nstore, startp, endp - startp);
4935 : 167571 : if (endp == startp)
4936 : 0 : strcpy (nstore, concat (".", dir_separator_str, NULL));
4937 : 167571 : else if (!IS_DIR_SEPARATOR (endp[-1]))
4938 : : {
4939 : 1313 : nstore[endp - startp] = DIR_SEPARATOR;
4940 : 1313 : nstore[endp - startp + 1] = 0;
4941 : : }
4942 : : else
4943 : 166258 : nstore[endp - startp] = 0;
4944 : 167571 : add_prefix (&startfile_prefixes, nstore, NULL,
4945 : : PREFIX_PRIORITY_LAST, 0, 1);
4946 : 167571 : if (*endp == 0)
4947 : : break;
4948 : 144366 : endp = startp = endp + 1;
4949 : : }
4950 : : else
4951 : 3864915 : endp++;
4952 : : }
4953 : : }
4954 : :
4955 : : /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
4956 : 296259 : temp = env.get ("LPATH");
4957 : 296259 : if (temp && *cross_compile == '0')
4958 : : {
4959 : 0 : const char *startp, *endp;
4960 : 0 : char *nstore = (char *) alloca (strlen (temp) + 3);
4961 : :
4962 : 0 : startp = endp = temp;
4963 : 0 : while (1)
4964 : : {
4965 : 0 : if (*endp == PATH_SEPARATOR || *endp == 0)
4966 : : {
4967 : 0 : strncpy (nstore, startp, endp - startp);
4968 : 0 : if (endp == startp)
4969 : 0 : strcpy (nstore, concat (".", dir_separator_str, NULL));
4970 : 0 : else if (!IS_DIR_SEPARATOR (endp[-1]))
4971 : : {
4972 : 0 : nstore[endp - startp] = DIR_SEPARATOR;
4973 : 0 : nstore[endp - startp + 1] = 0;
4974 : : }
4975 : : else
4976 : 0 : nstore[endp - startp] = 0;
4977 : 0 : add_prefix (&startfile_prefixes, nstore, NULL,
4978 : : PREFIX_PRIORITY_LAST, 0, 1);
4979 : 0 : if (*endp == 0)
4980 : : break;
4981 : 0 : endp = startp = endp + 1;
4982 : : }
4983 : : else
4984 : 0 : endp++;
4985 : : }
4986 : : }
4987 : :
4988 : : /* Process the options and store input files and switches in their
4989 : : vectors. */
4990 : :
4991 : 296259 : last_language_n_infiles = -1;
4992 : :
4993 : 296259 : set_option_handlers (&handlers);
4994 : :
4995 : 5485930 : for (j = 1; j < decoded_options_count; j++)
4996 : : {
4997 : 5376339 : switch (decoded_options[j].opt_index)
4998 : : {
4999 : 186668 : case OPT_S:
5000 : 186668 : case OPT_c:
5001 : 186668 : case OPT_E:
5002 : 186668 : have_c = 1;
5003 : 186668 : break;
5004 : : }
5005 : 5376339 : if (have_c)
5006 : : break;
5007 : : }
5008 : :
5009 : 6780948 : for (j = 1; j < decoded_options_count; j++)
5010 : : {
5011 : 6484970 : if (decoded_options[j].opt_index == OPT_SPECIAL_input_file)
5012 : : {
5013 : 318717 : const char *arg = decoded_options[j].arg;
5014 : :
5015 : : #ifdef HAVE_TARGET_OBJECT_SUFFIX
5016 : : arg = convert_filename (arg, 0, access (arg, F_OK));
5017 : : #endif
5018 : 318717 : add_infile (arg, spec_lang);
5019 : :
5020 : 318717 : continue;
5021 : 318717 : }
5022 : :
5023 : 6166253 : read_cmdline_option (&global_options, &global_options_set,
5024 : : decoded_options + j, UNKNOWN_LOCATION,
5025 : : CL_DRIVER, &handlers, global_dc);
5026 : : }
5027 : :
5028 : : /* If the user didn't specify any, default to all configured offload
5029 : : targets. */
5030 : 295978 : if (ENABLE_OFFLOADING && offload_targets == NULL)
5031 : : {
5032 : : handle_foffload_option (OFFLOAD_TARGETS);
5033 : : #if OFFLOAD_DEFAULTED
5034 : : offload_targets_default = true;
5035 : : #endif
5036 : : }
5037 : :
5038 : : /* TODO: check if -static -pie works and maybe use it. */
5039 : 295978 : if (flag_hardened)
5040 : : {
5041 : 91 : if (!avoid_linker_hardening_p && !static_p)
5042 : : {
5043 : : #if defined HAVE_LD_PIE && defined LD_PIE_SPEC
5044 : 67 : save_switch (LD_PIE_SPEC, 0, NULL, /*validated=*/true, /*known=*/false);
5045 : : #endif
5046 : : /* These are passed straight down to collect2 so we have to break
5047 : : it up like this. */
5048 : 67 : if (HAVE_LD_NOW_SUPPORT)
5049 : : {
5050 : 67 : add_infile ("-z", "*");
5051 : 67 : add_infile ("now", "*");
5052 : : }
5053 : 67 : if (HAVE_LD_RELRO_SUPPORT)
5054 : : {
5055 : 67 : add_infile ("-z", "*");
5056 : 67 : add_infile ("relro", "*");
5057 : : }
5058 : : }
5059 : : /* We can't use OPT_Whardened yet. Sigh. */
5060 : : else
5061 : 24 : warning_at (UNKNOWN_LOCATION, 0,
5062 : : "linker hardening options not enabled by %<-fhardened%> "
5063 : : "because other link options were specified on the command "
5064 : : "line");
5065 : : }
5066 : :
5067 : : /* Handle -gtoggle as it would later in toplev.cc:process_options to
5068 : : make the debug-level-gt spec function work as expected. */
5069 : 295978 : if (flag_gtoggle)
5070 : : {
5071 : 4 : if (debug_info_level == DINFO_LEVEL_NONE)
5072 : 0 : debug_info_level = DINFO_LEVEL_NORMAL;
5073 : : else
5074 : 4 : debug_info_level = DINFO_LEVEL_NONE;
5075 : : }
5076 : :
5077 : 295978 : if (output_file
5078 : 269060 : && strcmp (output_file, "-") != 0
5079 : 268897 : && strcmp (output_file, HOST_BIT_BUCKET) != 0)
5080 : : {
5081 : : int i;
5082 : 797701 : for (i = 0; i < n_infiles; i++)
5083 : 256958 : if ((!infiles[i].language || infiles[i].language[0] != '*')
5084 : 557653 : && canonical_filename_eq (infiles[i].name, output_file))
5085 : 1 : fatal_error (input_location,
5086 : : "input file %qs is the same as output file",
5087 : : output_file);
5088 : : }
5089 : :
5090 : 295977 : if (output_file != NULL && output_file[0] == '\0')
5091 : 0 : fatal_error (input_location, "output filename may not be empty");
5092 : :
5093 : : /* -dumpdir and -save-temps=* both specify the location of aux/dump
5094 : : outputs; the one that appears last prevails. When compiling
5095 : : multiple sources, an explicit dumpbase (minus -ext) may be
5096 : : combined with an explicit or implicit dumpdir, whereas when
5097 : : linking, a specified or implied link output name (minus
5098 : : extension) may be combined with a prevailing -save-temps=* or an
5099 : : otherwise implied dumpdir, but not override a prevailing
5100 : : -dumpdir. Primary outputs (e.g., linker output when linking
5101 : : without -o, or .i, .s or .o outputs when processing multiple
5102 : : inputs with -E, -S or -c, respectively) are NOT affected by these
5103 : : -save-temps=/-dump* options, always landing in the current
5104 : : directory and with the same basename as the input when an output
5105 : : name is not given, but when they're intermediate outputs, they
5106 : : are named like other aux outputs, so the options affect their
5107 : : location and name.
5108 : :
5109 : : Here are some examples. There are several more in the
5110 : : documentation of -o and -dump*, and some quite exhaustive tests
5111 : : in gcc.misc-tests/outputs.exp.
5112 : :
5113 : : When compiling any number of sources, no -dump* nor
5114 : : -save-temps=*, all outputs in cwd without prefix:
5115 : :
5116 : : # gcc -c b.c -gsplit-dwarf
5117 : : -> cc1 [-dumpdir ./] -dumpbase b.c -dumpbase-ext .c # b.o b.dwo
5118 : :
5119 : : # gcc -c b.c d.c -gsplit-dwarf
5120 : : -> cc1 [-dumpdir ./] -dumpbase b.c -dumpbase-ext .c # b.o b.dwo
5121 : : && cc1 [-dumpdir ./] -dumpbase d.c -dumpbase-ext .c # d.o d.dwo
5122 : :
5123 : : When compiling and linking, no -dump* nor -save-temps=*, .o
5124 : : outputs are temporary, aux outputs land in the dir of the output,
5125 : : prefixed with the basename of the linker output:
5126 : :
5127 : : # gcc b.c d.c -o ab -gsplit-dwarf
5128 : : -> cc1 -dumpdir ab- -dumpbase b.c -dumpbase-ext .c # ab-b.dwo
5129 : : && cc1 -dumpdir ab- -dumpbase d.c -dumpbase-ext .c # ab-d.dwo
5130 : : && link ... -o ab
5131 : :
5132 : : # gcc b.c d.c [-o a.out] -gsplit-dwarf
5133 : : -> cc1 -dumpdir a- -dumpbase b.c -dumpbase-ext .c # a-b.dwo
5134 : : && cc1 -dumpdir a- -dumpbase d.c -dumpbase-ext .c # a-d.dwo
5135 : : && link ... [-o a.out]
5136 : :
5137 : : When compiling and linking, a prevailing -dumpdir fully overrides
5138 : : the prefix of aux outputs given by the output name:
5139 : :
5140 : : # gcc -dumpdir f b.c d.c -gsplit-dwarf [-o [dir/]whatever]
5141 : : -> cc1 -dumpdir f -dumpbase b.c -dumpbase-ext .c # fb.dwo
5142 : : && cc1 -dumpdir f -dumpbase d.c -dumpbase-ext .c # fd.dwo
5143 : : && link ... [-o whatever]
5144 : :
5145 : : When compiling multiple inputs, an explicit -dumpbase is combined
5146 : : with -dumpdir, affecting aux outputs, but not the .o outputs:
5147 : :
5148 : : # gcc -dumpdir f -dumpbase g- b.c d.c -gsplit-dwarf -c
5149 : : -> cc1 -dumpdir fg- -dumpbase b.c -dumpbase-ext .c # b.o fg-b.dwo
5150 : : && cc1 -dumpdir fg- -dumpbase d.c -dumpbase-ext .c # d.o fg-d.dwo
5151 : :
5152 : : When compiling and linking with -save-temps, the .o outputs that
5153 : : would have been temporary become aux outputs, so they get
5154 : : affected by -dump* flags:
5155 : :
5156 : : # gcc -dumpdir f -dumpbase g- -save-temps b.c d.c
5157 : : -> cc1 -dumpdir fg- -dumpbase b.c -dumpbase-ext .c # fg-b.o
5158 : : && cc1 -dumpdir fg- -dumpbase d.c -dumpbase-ext .c # fg-d.o
5159 : : && link
5160 : :
5161 : : If -save-temps=* prevails over -dumpdir, however, the explicit
5162 : : -dumpdir is discarded, as if it wasn't there. The basename of
5163 : : the implicit linker output, a.out or a.exe, becomes a- as the aux
5164 : : output prefix for all compilations:
5165 : :
5166 : : # gcc [-dumpdir f] -save-temps=cwd b.c d.c
5167 : : -> cc1 -dumpdir a- -dumpbase b.c -dumpbase-ext .c # a-b.o
5168 : : && cc1 -dumpdir a- -dumpbase d.c -dumpbase-ext .c # a-d.o
5169 : : && link
5170 : :
5171 : : A single -dumpbase, applying to multiple inputs, overrides the
5172 : : linker output name, implied or explicit, as the aux output prefix:
5173 : :
5174 : : # gcc [-dumpdir f] -dumpbase g- -save-temps=cwd b.c d.c
5175 : : -> cc1 -dumpdir g- -dumpbase b.c -dumpbase-ext .c # g-b.o
5176 : : && cc1 -dumpdir g- -dumpbase d.c -dumpbase-ext .c # g-d.o
5177 : : && link
5178 : :
5179 : : # gcc [-dumpdir f] -dumpbase g- -save-temps=cwd b.c d.c -o dir/h.out
5180 : : -> cc1 -dumpdir g- -dumpbase b.c -dumpbase-ext .c # g-b.o
5181 : : && cc1 -dumpdir g- -dumpbase d.c -dumpbase-ext .c # g-d.o
5182 : : && link -o dir/h.out
5183 : :
5184 : : Now, if the linker output is NOT overridden as a prefix, but
5185 : : -save-temps=* overrides implicit or explicit -dumpdir, the
5186 : : effective dump dir combines the dir selected by the -save-temps=*
5187 : : option with the basename of the specified or implied link output:
5188 : :
5189 : : # gcc [-dumpdir f] -save-temps=cwd b.c d.c -o dir/h.out
5190 : : -> cc1 -dumpdir h- -dumpbase b.c -dumpbase-ext .c # h-b.o
5191 : : && cc1 -dumpdir h- -dumpbase d.c -dumpbase-ext .c # h-d.o
5192 : : && link -o dir/h.out
5193 : :
5194 : : # gcc [-dumpdir f] -save-temps=obj b.c d.c -o dir/h.out
5195 : : -> cc1 -dumpdir dir/h- -dumpbase b.c -dumpbase-ext .c # dir/h-b.o
5196 : : && cc1 -dumpdir dir/h- -dumpbase d.c -dumpbase-ext .c # dir/h-d.o
5197 : : && link -o dir/h.out
5198 : :
5199 : : But then again, a single -dumpbase applying to multiple inputs
5200 : : gets used instead of the linker output basename in the combined
5201 : : dumpdir:
5202 : :
5203 : : # gcc [-dumpdir f] -dumpbase g- -save-temps=obj b.c d.c -o dir/h.out
5204 : : -> cc1 -dumpdir dir/g- -dumpbase b.c -dumpbase-ext .c # dir/g-b.o
5205 : : && cc1 -dumpdir dir/g- -dumpbase d.c -dumpbase-ext .c # dir/g-d.o
5206 : : && link -o dir/h.out
5207 : :
5208 : : With a single input being compiled, the output basename does NOT
5209 : : affect the dumpdir prefix.
5210 : :
5211 : : # gcc -save-temps=obj b.c -gsplit-dwarf -c -o dir/b.o
5212 : : -> cc1 -dumpdir dir/ -dumpbase b.c -dumpbase-ext .c # dir/b.o dir/b.dwo
5213 : :
5214 : : but when compiling and linking even a single file, it does:
5215 : :
5216 : : # gcc -save-temps=obj b.c -o dir/h.out
5217 : : -> cc1 -dumpdir dir/h- -dumpbase b.c -dumpbase-ext .c # dir/h-b.o
5218 : :
5219 : : unless an explicit -dumpdir prevails:
5220 : :
5221 : : # gcc -save-temps[=obj] -dumpdir g- b.c -o dir/h.out
5222 : : -> cc1 -dumpdir g- -dumpbase b.c -dumpbase-ext .c # g-b.o
5223 : :
5224 : : */
5225 : :
5226 : 295977 : bool explicit_dumpdir = dumpdir;
5227 : :
5228 : 295925 : if ((!save_temps_overrides_dumpdir && explicit_dumpdir)
5229 : 569854 : || (output_file && not_actual_file_p (output_file)))
5230 : : {
5231 : : /* Do nothing. */
5232 : : }
5233 : :
5234 : : /* If -save-temps=obj and -o name, create the prefix to use for %b.
5235 : : Otherwise just make -save-temps=obj the same as -save-temps=cwd. */
5236 : 272414 : else if (save_temps_flag != SAVE_TEMPS_CWD && output_file != NULL)
5237 : : {
5238 : 253956 : free (dumpdir);
5239 : 253956 : dumpdir = NULL;
5240 : 253956 : temp = lbasename (output_file);
5241 : 253956 : if (temp != output_file)
5242 : 101701 : dumpdir = xstrndup (output_file,
5243 : 101701 : strlen (output_file) - strlen (temp));
5244 : : }
5245 : 18458 : else if (dumpdir)
5246 : : {
5247 : 5 : free (dumpdir);
5248 : 5 : dumpdir = NULL;
5249 : : }
5250 : :
5251 : 295977 : if (save_temps_flag)
5252 : 455 : save_temps_flag = SAVE_TEMPS_DUMP;
5253 : :
5254 : : /* If there is any pathname component in an explicit -dumpbase, it
5255 : : overrides dumpdir entirely, so discard it right away. Although
5256 : : the presence of an explicit -dumpdir matters for the driver, it
5257 : : shouldn't matter for other processes, that get all that's needed
5258 : : from the -dumpdir and -dumpbase always passed to them. */
5259 : 295977 : if (dumpdir && dumpbase && lbasename (dumpbase) != dumpbase)
5260 : : {
5261 : 21961 : free (dumpdir);
5262 : 21961 : dumpdir = NULL;
5263 : : }
5264 : :
5265 : : /* Check that dumpbase_ext matches the end of dumpbase, drop it
5266 : : otherwise. */
5267 : 295977 : if (dumpbase_ext && dumpbase && *dumpbase)
5268 : : {
5269 : 20 : int lendb = strlen (dumpbase);
5270 : 20 : int lendbx = strlen (dumpbase_ext);
5271 : :
5272 : : /* -dumpbase-ext must be a suffix proper; discard it if it
5273 : : matches all of -dumpbase, as that would make for an empty
5274 : : basename. */
5275 : 20 : if (lendbx >= lendb
5276 : 19 : || strcmp (dumpbase + lendb - lendbx, dumpbase_ext) != 0)
5277 : : {
5278 : 1 : free (dumpbase_ext);
5279 : 1 : dumpbase_ext = NULL;
5280 : : }
5281 : : }
5282 : :
5283 : : /* -dumpbase with multiple sources goes into dumpdir. With a single
5284 : : source, it does only if linking and if dumpdir was not explicitly
5285 : : specified. */
5286 : 23479 : if (dumpbase && *dumpbase
5287 : 318016 : && (single_input_file_index () == -2
5288 : 21755 : || (!have_c && !explicit_dumpdir)))
5289 : : {
5290 : 296 : char *prefix;
5291 : :
5292 : 296 : if (dumpbase_ext)
5293 : : /* We checked that they match above. */
5294 : 6 : dumpbase[strlen (dumpbase) - strlen (dumpbase_ext)] = '\0';
5295 : :
5296 : 296 : if (dumpdir)
5297 : 13 : prefix = concat (dumpdir, dumpbase, "-", NULL);
5298 : : else
5299 : 283 : prefix = concat (dumpbase, "-", NULL);
5300 : :
5301 : 296 : free (dumpdir);
5302 : 296 : free (dumpbase);
5303 : 296 : free (dumpbase_ext);
5304 : 296 : dumpbase = dumpbase_ext = NULL;
5305 : 296 : dumpdir = prefix;
5306 : 296 : dumpdir_trailing_dash_added = true;
5307 : : }
5308 : :
5309 : : /* If dumpbase was not brought into dumpdir but we're linking, bring
5310 : : output_file into dumpdir unless dumpdir was explicitly specified.
5311 : : The test for !explicit_dumpdir is further below, because we want
5312 : : to use the obase computation for a ghost outbase, passed to
5313 : : GCC_COLLECT_OPTIONS. */
5314 : 295681 : else if (!have_c && (!explicit_dumpdir || (dumpbase && !*dumpbase)))
5315 : : {
5316 : : /* If we get here, we know dumpbase was not specified, or it was
5317 : : specified as an empty string. If it was anything else, it
5318 : : would have combined with dumpdir above, because the condition
5319 : : for dumpbase to be used when present is broader than the
5320 : : condition that gets us here. */
5321 : 109208 : gcc_assert (!dumpbase || !*dumpbase);
5322 : :
5323 : 109208 : const char *obase;
5324 : 109208 : char *tofree = NULL;
5325 : 109208 : if (!output_file || not_actual_file_p (output_file))
5326 : : obase = "a";
5327 : : else
5328 : : {
5329 : 94106 : obase = lbasename (output_file);
5330 : 94106 : size_t blen = strlen (obase), xlen;
5331 : : /* Drop the suffix if it's dumpbase_ext, if given,
5332 : : otherwise .exe or the target executable suffix, or if the
5333 : : output was explicitly named a.out, but not otherwise. */
5334 : 94106 : if (dumpbase_ext
5335 : 94106 : ? (blen > (xlen = strlen (dumpbase_ext))
5336 : 221 : && strcmp ((temp = (obase + blen - xlen)),
5337 : : dumpbase_ext) == 0)
5338 : 93885 : : ((temp = strrchr (obase + 1, '.'))
5339 : 92033 : && (xlen = strlen (temp))
5340 : 185918 : && (strcmp (temp, ".exe") == 0
5341 : : #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
5342 : : || strcmp (temp, TARGET_EXECUTABLE_SUFFIX) == 0
5343 : : #endif
5344 : 8878 : || strcmp (obase, "a.out") == 0)))
5345 : : {
5346 : 83402 : tofree = xstrndup (obase, blen - xlen);
5347 : 83402 : obase = tofree;
5348 : : }
5349 : : }
5350 : :
5351 : : /* We wish to save this basename to the -dumpdir passed through
5352 : : GCC_COLLECT_OPTIONS within maybe_run_linker, for e.g. LTO,
5353 : : but we do NOT wish to add it to e.g. %b, so we keep
5354 : : outbase_length as zero. */
5355 : 109208 : gcc_assert (!outbase);
5356 : 109208 : outbase_length = 0;
5357 : :
5358 : : /* If we're building [dir1/]foo[.exe] out of a single input
5359 : : [dir2/]foo.c that shares the same basename, dump to
5360 : : [dir2/]foo.c.* rather than duplicating the basename into
5361 : : [dir2/]foo-foo.c.*. */
5362 : 109208 : int idxin;
5363 : 109208 : if (dumpbase
5364 : 109208 : || ((idxin = single_input_file_index ()) >= 0
5365 : 83930 : && adds_single_suffix_p (lbasename (infiles[idxin].name),
5366 : : obase)))
5367 : : {
5368 : 76783 : if (obase == tofree)
5369 : 75024 : outbase = tofree;
5370 : : else
5371 : : {
5372 : 1759 : outbase = xstrdup (obase);
5373 : 1759 : free (tofree);
5374 : : }
5375 : 109208 : obase = tofree = NULL;
5376 : : }
5377 : : else
5378 : : {
5379 : 32425 : if (dumpdir)
5380 : : {
5381 : 15005 : char *p = concat (dumpdir, obase, "-", NULL);
5382 : 15005 : free (dumpdir);
5383 : 15005 : dumpdir = p;
5384 : : }
5385 : : else
5386 : 17420 : dumpdir = concat (obase, "-", NULL);
5387 : :
5388 : 32425 : dumpdir_trailing_dash_added = true;
5389 : :
5390 : 32425 : free (tofree);
5391 : 32425 : obase = tofree = NULL;
5392 : : }
5393 : :
5394 : 109208 : if (!explicit_dumpdir || dumpbase)
5395 : : {
5396 : : /* Absent -dumpbase and present -dumpbase-ext have been applied
5397 : : to the linker output name, so compute fresh defaults for each
5398 : : compilation. */
5399 : 109208 : free (dumpbase_ext);
5400 : 109208 : dumpbase_ext = NULL;
5401 : : }
5402 : : }
5403 : :
5404 : : /* Now, if we're compiling, or if we haven't used the dumpbase
5405 : : above, then outbase (%B) is derived from dumpbase, if given, or
5406 : : from the output name, given or implied. We can't precompute
5407 : : implied output names, but that's ok, since they're derived from
5408 : : input names. Just make sure we skip this if dumpbase is the
5409 : : empty string: we want to use input names then, so don't set
5410 : : outbase. */
5411 : 295977 : if ((dumpbase || have_c)
5412 : 188125 : && !(dumpbase && !*dumpbase))
5413 : : {
5414 : 186685 : gcc_assert (!outbase);
5415 : :
5416 : 186685 : if (dumpbase)
5417 : : {
5418 : 21743 : gcc_assert (single_input_file_index () != -2);
5419 : : /* We do not want lbasename here; dumpbase with dirnames
5420 : : overrides dumpdir entirely, even if dumpdir is
5421 : : specified. */
5422 : 21743 : if (dumpbase_ext)
5423 : : /* We've already checked above that the suffix matches. */
5424 : 13 : outbase = xstrndup (dumpbase,
5425 : 13 : strlen (dumpbase) - strlen (dumpbase_ext));
5426 : : else
5427 : 21730 : outbase = xstrdup (dumpbase);
5428 : : }
5429 : 164942 : else if (output_file && !not_actual_file_p (output_file))
5430 : : {
5431 : 160087 : outbase = xstrdup (lbasename (output_file));
5432 : 160087 : char *p = strrchr (outbase + 1, '.');
5433 : 160087 : if (p)
5434 : 160087 : *p = '\0';
5435 : : }
5436 : :
5437 : 186685 : if (outbase)
5438 : 181830 : outbase_length = strlen (outbase);
5439 : : }
5440 : :
5441 : : /* If there is any pathname component in an explicit -dumpbase, do
5442 : : not use dumpdir, but retain it to pass it on to the compiler. */
5443 : 295977 : if (dumpdir)
5444 : 119491 : dumpdir_length = strlen (dumpdir);
5445 : : else
5446 : 176486 : dumpdir_length = 0;
5447 : :
5448 : : /* Check that dumpbase_ext, if still present, still matches the end
5449 : : of dumpbase, if present, and drop it otherwise. We only retained
5450 : : it above when dumpbase was absent to maybe use it to drop the
5451 : : extension from output_name before combining it with dumpdir. We
5452 : : won't deal with -dumpbase-ext when -dumpbase is not explicitly
5453 : : given, even if just to activate backward-compatible dumpbase:
5454 : : dropping it on the floor is correct, expected and documented
5455 : : behavior. Attempting to deal with a -dumpbase-ext that might
5456 : : match the end of some input filename, or of the combination of
5457 : : the output basename with the suffix of the input filename,
5458 : : possible with an intermediate .gk extension for -fcompare-debug,
5459 : : is just calling for trouble. */
5460 : 295977 : if (dumpbase_ext)
5461 : : {
5462 : 22 : if (!dumpbase || !*dumpbase)
5463 : : {
5464 : 9 : free (dumpbase_ext);
5465 : 9 : dumpbase_ext = NULL;
5466 : : }
5467 : : else
5468 : 13 : gcc_assert (strcmp (dumpbase + strlen (dumpbase)
5469 : : - strlen (dumpbase_ext), dumpbase_ext) == 0);
5470 : : }
5471 : :
5472 : 295977 : if (save_temps_flag && use_pipes)
5473 : : {
5474 : : /* -save-temps overrides -pipe, so that temp files are produced */
5475 : 0 : if (save_temps_flag)
5476 : 0 : warning (0, "%<-pipe%> ignored because %<-save-temps%> specified");
5477 : 0 : use_pipes = 0;
5478 : : }
5479 : :
5480 : 295977 : if (!compare_debug)
5481 : : {
5482 : 295355 : const char *gcd = env.get ("GCC_COMPARE_DEBUG");
5483 : :
5484 : 295355 : if (gcd && gcd[0] == '-')
5485 : : {
5486 : 0 : compare_debug = 2;
5487 : 0 : compare_debug_opt = gcd;
5488 : : }
5489 : 0 : else if (gcd && *gcd && strcmp (gcd, "0"))
5490 : : {
5491 : 0 : compare_debug = 3;
5492 : 0 : compare_debug_opt = "-gtoggle";
5493 : : }
5494 : : }
5495 : 622 : else if (compare_debug < 0)
5496 : : {
5497 : 0 : compare_debug = 0;
5498 : 0 : gcc_assert (!compare_debug_opt);
5499 : : }
5500 : :
5501 : : /* Set up the search paths. We add directories that we expect to
5502 : : contain GNU Toolchain components before directories specified by
5503 : : the machine description so that we will find GNU components (like
5504 : : the GNU assembler) before those of the host system. */
5505 : :
5506 : : /* If we don't know where the toolchain has been installed, use the
5507 : : configured-in locations. */
5508 : 295977 : if (!gcc_exec_prefix)
5509 : : {
5510 : : #ifndef OS2
5511 : 0 : add_prefix (&exec_prefixes, standard_libexec_prefix, "GCC",
5512 : : PREFIX_PRIORITY_LAST, 1, 0);
5513 : 0 : add_prefix (&exec_prefixes, standard_libexec_prefix, "BINUTILS",
5514 : : PREFIX_PRIORITY_LAST, 2, 0);
5515 : 0 : add_prefix (&exec_prefixes, standard_exec_prefix, "BINUTILS",
5516 : : PREFIX_PRIORITY_LAST, 2, 0);
5517 : : #endif
5518 : 0 : add_prefix (&startfile_prefixes, standard_exec_prefix, "BINUTILS",
5519 : : PREFIX_PRIORITY_LAST, 1, 0);
5520 : : }
5521 : :
5522 : 295977 : gcc_assert (!IS_ABSOLUTE_PATH (tooldir_base_prefix));
5523 : 295977 : tooldir_prefix2 = concat (tooldir_base_prefix, spec_machine,
5524 : : dir_separator_str, NULL);
5525 : :
5526 : : /* Look for tools relative to the location from which the driver is
5527 : : running, or, if that is not available, the configured prefix. */
5528 : 295977 : tooldir_prefix
5529 : 591954 : = concat (gcc_exec_prefix ? gcc_exec_prefix : standard_exec_prefix,
5530 : : spec_host_machine, dir_separator_str, spec_version,
5531 : : accel_dir_suffix, dir_separator_str, tooldir_prefix2, NULL);
5532 : 295977 : free (tooldir_prefix2);
5533 : :
5534 : 295977 : add_prefix (&exec_prefixes,
5535 : 295977 : concat (tooldir_prefix, "bin", dir_separator_str, NULL),
5536 : : "BINUTILS", PREFIX_PRIORITY_LAST, 0, 0);
5537 : 295977 : add_prefix (&startfile_prefixes,
5538 : 295977 : concat (tooldir_prefix, "lib", dir_separator_str, NULL),
5539 : : "BINUTILS", PREFIX_PRIORITY_LAST, 0, 1);
5540 : 295977 : free (tooldir_prefix);
5541 : :
5542 : : #if defined(TARGET_SYSTEM_ROOT_RELOCATABLE) && !defined(VMS)
5543 : : /* If the normal TARGET_SYSTEM_ROOT is inside of $exec_prefix,
5544 : : then consider it to relocate with the rest of the GCC installation
5545 : : if GCC_EXEC_PREFIX is set.
5546 : : ``make_relative_prefix'' is not compiled for VMS, so don't call it. */
5547 : : if (target_system_root && !target_system_root_changed && gcc_exec_prefix)
5548 : : {
5549 : : char *tmp_prefix = get_relative_prefix (decoded_options[0].arg,
5550 : : standard_bindir_prefix,
5551 : : target_system_root);
5552 : : if (tmp_prefix && access_check (tmp_prefix, F_OK) == 0)
5553 : : {
5554 : : target_system_root = tmp_prefix;
5555 : : target_system_root_changed = 1;
5556 : : }
5557 : : }
5558 : : #endif
5559 : :
5560 : : /* More prefixes are enabled in main, after we read the specs file
5561 : : and determine whether this is cross-compilation or not. */
5562 : :
5563 : 295977 : if (n_infiles != 0 && n_infiles == last_language_n_infiles && spec_lang != 0)
5564 : 0 : warning (0, "%<-x %s%> after last input file has no effect", spec_lang);
5565 : :
5566 : : /* Synthesize -fcompare-debug flag from the GCC_COMPARE_DEBUG
5567 : : environment variable. */
5568 : 295977 : if (compare_debug == 2 || compare_debug == 3)
5569 : : {
5570 : 0 : const char *opt = concat ("-fcompare-debug=", compare_debug_opt, NULL);
5571 : 0 : save_switch (opt, 0, NULL, false, true);
5572 : 0 : compare_debug = 1;
5573 : : }
5574 : :
5575 : : /* Ensure we only invoke each subprocess once. */
5576 : 295977 : if (n_infiles == 0
5577 : 9084 : && (print_subprocess_help || print_help_list || print_version))
5578 : : {
5579 : : /* Create a dummy input file, so that we can pass
5580 : : the help option on to the various sub-processes. */
5581 : 78 : add_infile ("help-dummy", "c");
5582 : : }
5583 : :
5584 : : /* Decide if undefined variable references are allowed in specs. */
5585 : :
5586 : : /* -v alone is safe. --version and --help alone or together are safe. Note
5587 : : that -v would make them unsafe, as they'd then be run for subprocesses as
5588 : : well, the location of which might depend on variables possibly coming
5589 : : from self-specs. Note also that the command name is counted in
5590 : : decoded_options_count. */
5591 : :
5592 : 295977 : unsigned help_version_count = 0;
5593 : :
5594 : 295977 : if (print_version)
5595 : 78 : help_version_count++;
5596 : :
5597 : 295977 : if (print_help_list)
5598 : 4 : help_version_count++;
5599 : :
5600 : 591954 : spec_undefvar_allowed =
5601 : 1454 : ((verbose_flag && decoded_options_count == 2)
5602 : 297364 : || help_version_count == decoded_options_count - 1);
5603 : :
5604 : 295977 : alloc_switch ();
5605 : 295977 : switches[n_switches].part1 = 0;
5606 : 295977 : alloc_infile ();
5607 : 295977 : infiles[n_infiles].name = 0;
5608 : 295977 : }
5609 : :
5610 : : /* Store switches not filtered out by %<S in spec in COLLECT_GCC_OPTIONS
5611 : : and place that in the environment. */
5612 : :
5613 : : static void
5614 : 815544 : set_collect_gcc_options (void)
5615 : : {
5616 : 815544 : int i;
5617 : 815544 : int first_time;
5618 : :
5619 : : /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
5620 : : the compiler. */
5621 : 815544 : obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
5622 : : sizeof ("COLLECT_GCC_OPTIONS=") - 1);
5623 : :
5624 : 815544 : first_time = true;
5625 : 18921909 : for (i = 0; (int) i < n_switches; i++)
5626 : : {
5627 : 18106365 : const char *const *args;
5628 : 18106365 : const char *p, *q;
5629 : 18106365 : if (!first_time)
5630 : 17290821 : obstack_grow (&collect_obstack, " ", 1);
5631 : :
5632 : 18106365 : first_time = false;
5633 : :
5634 : : /* Ignore elided switches. */
5635 : 18234098 : if ((switches[i].live_cond
5636 : 18106365 : & (SWITCH_IGNORE | SWITCH_KEEP_FOR_GCC))
5637 : : == SWITCH_IGNORE)
5638 : 127733 : continue;
5639 : :
5640 : 17978632 : obstack_grow (&collect_obstack, "'-", 2);
5641 : 17978632 : q = switches[i].part1;
5642 : 17978632 : while ((p = strchr (q, '\'')))
5643 : : {
5644 : 0 : obstack_grow (&collect_obstack, q, p - q);
5645 : 0 : obstack_grow (&collect_obstack, "'\\''", 4);
5646 : 0 : q = ++p;
5647 : : }
5648 : 17978632 : obstack_grow (&collect_obstack, q, strlen (q));
5649 : 17978632 : obstack_grow (&collect_obstack, "'", 1);
5650 : :
5651 : 22088928 : for (args = switches[i].args; args && *args; args++)
5652 : : {
5653 : 4110296 : obstack_grow (&collect_obstack, " '", 2);
5654 : 4110296 : q = *args;
5655 : 4110296 : while ((p = strchr (q, '\'')))
5656 : : {
5657 : 0 : obstack_grow (&collect_obstack, q, p - q);
5658 : 0 : obstack_grow (&collect_obstack, "'\\''", 4);
5659 : 0 : q = ++p;
5660 : : }
5661 : 4110296 : obstack_grow (&collect_obstack, q, strlen (q));
5662 : 4110296 : obstack_grow (&collect_obstack, "'", 1);
5663 : : }
5664 : : }
5665 : :
5666 : 815544 : if (dumpdir)
5667 : : {
5668 : 575670 : if (!first_time)
5669 : 575670 : obstack_grow (&collect_obstack, " ", 1);
5670 : 575670 : first_time = false;
5671 : :
5672 : 575670 : obstack_grow (&collect_obstack, "'-dumpdir' '", 12);
5673 : 575670 : const char *p, *q;
5674 : :
5675 : 575670 : q = dumpdir;
5676 : 575670 : while ((p = strchr (q, '\'')))
5677 : : {
5678 : 0 : obstack_grow (&collect_obstack, q, p - q);
5679 : 0 : obstack_grow (&collect_obstack, "'\\''", 4);
5680 : 0 : q = ++p;
5681 : : }
5682 : 575670 : obstack_grow (&collect_obstack, q, strlen (q));
5683 : :
5684 : 575670 : obstack_grow (&collect_obstack, "'", 1);
5685 : : }
5686 : :
5687 : 815544 : obstack_grow (&collect_obstack, "\0", 1);
5688 : 815544 : xputenv (XOBFINISH (&collect_obstack, char *));
5689 : 815544 : }
5690 : :
5691 : : /* Process a spec string, accumulating and running commands. */
5692 : :
5693 : : /* These variables describe the input file name.
5694 : : input_file_number is the index on outfiles of this file,
5695 : : so that the output file name can be stored for later use by %o.
5696 : : input_basename is the start of the part of the input file
5697 : : sans all directory names, and basename_length is the number
5698 : : of characters starting there excluding the suffix .c or whatever. */
5699 : :
5700 : : static const char *gcc_input_filename;
5701 : : static int input_file_number;
5702 : : size_t input_filename_length;
5703 : : static int basename_length;
5704 : : static int suffixed_basename_length;
5705 : : static const char *input_basename;
5706 : : static const char *input_suffix;
5707 : : #ifndef HOST_LACKS_INODE_NUMBERS
5708 : : static struct stat input_stat;
5709 : : #endif
5710 : : static int input_stat_set;
5711 : :
5712 : : /* The compiler used to process the current input file. */
5713 : : static struct compiler *input_file_compiler;
5714 : :
5715 : : /* These are variables used within do_spec and do_spec_1. */
5716 : :
5717 : : /* Nonzero if an arg has been started and not yet terminated
5718 : : (with space, tab or newline). */
5719 : : static int arg_going;
5720 : :
5721 : : /* Nonzero means %d or %g has been seen; the next arg to be terminated
5722 : : is a temporary file name. */
5723 : : static int delete_this_arg;
5724 : :
5725 : : /* Nonzero means %w has been seen; the next arg to be terminated
5726 : : is the output file name of this compilation. */
5727 : : static int this_is_output_file;
5728 : :
5729 : : /* Nonzero means %s has been seen; the next arg to be terminated
5730 : : is the name of a library file and we should try the standard
5731 : : search dirs for it. */
5732 : : static int this_is_library_file;
5733 : :
5734 : : /* Nonzero means %T has been seen; the next arg to be terminated
5735 : : is the name of a linker script and we should try all of the
5736 : : standard search dirs for it. If it is found insert a --script
5737 : : command line switch and then substitute the full path in place,
5738 : : otherwise generate an error message. */
5739 : : static int this_is_linker_script;
5740 : :
5741 : : /* Nonzero means that the input of this command is coming from a pipe. */
5742 : : static int input_from_pipe;
5743 : :
5744 : : /* Nonnull means substitute this for any suffix when outputting a switches
5745 : : arguments. */
5746 : : static const char *suffix_subst;
5747 : :
5748 : : /* If there is an argument being accumulated, terminate it and store it. */
5749 : :
5750 : : static void
5751 : 79428645 : end_going_arg (void)
5752 : : {
5753 : 79428645 : if (arg_going)
5754 : : {
5755 : 18673917 : const char *string;
5756 : :
5757 : 18673917 : obstack_1grow (&obstack, 0);
5758 : 18673917 : string = XOBFINISH (&obstack, const char *);
5759 : 18673917 : if (this_is_library_file)
5760 : 533686 : string = find_file (string);
5761 : 18673917 : if (this_is_linker_script)
5762 : : {
5763 : 0 : char * full_script_path = find_a_file (&startfile_prefixes, string, R_OK, true);
5764 : :
5765 : 0 : if (full_script_path == NULL)
5766 : : {
5767 : 0 : error ("unable to locate default linker script %qs in the library search paths", string);
5768 : : /* Script was not found on search path. */
5769 : 0 : return;
5770 : : }
5771 : 0 : store_arg ("--script", false, false);
5772 : 0 : string = full_script_path;
5773 : : }
5774 : 18673917 : store_arg (string, delete_this_arg, this_is_output_file);
5775 : 18673917 : if (this_is_output_file)
5776 : 99006 : outfiles[input_file_number] = string;
5777 : 18673917 : arg_going = 0;
5778 : : }
5779 : : }
5780 : :
5781 : :
5782 : : /* Parse the WRAPPER string which is a comma separated list of the command line
5783 : : and insert them into the beginning of argbuf. */
5784 : :
5785 : : static void
5786 : 0 : insert_wrapper (const char *wrapper)
5787 : : {
5788 : 0 : int n = 0;
5789 : 0 : int i;
5790 : 0 : char *buf = xstrdup (wrapper);
5791 : 0 : char *p = buf;
5792 : 0 : unsigned int old_length = argbuf.length ();
5793 : :
5794 : 0 : do
5795 : : {
5796 : 0 : n++;
5797 : 0 : while (*p == ',')
5798 : 0 : p++;
5799 : : }
5800 : 0 : while ((p = strchr (p, ',')) != NULL);
5801 : :
5802 : 0 : argbuf.safe_grow (old_length + n, true);
5803 : 0 : memmove (argbuf.address () + n,
5804 : 0 : argbuf.address (),
5805 : 0 : old_length * sizeof (const_char_p));
5806 : :
5807 : 0 : i = 0;
5808 : 0 : p = buf;
5809 : : do
5810 : : {
5811 : 0 : while (*p == ',')
5812 : : {
5813 : 0 : *p = 0;
5814 : 0 : p++;
5815 : : }
5816 : 0 : argbuf[i] = p;
5817 : 0 : i++;
5818 : : }
5819 : 0 : while ((p = strchr (p, ',')) != NULL);
5820 : 0 : gcc_assert (i == n);
5821 : 0 : }
5822 : :
5823 : : /* Process the spec SPEC and run the commands specified therein.
5824 : : Returns 0 if the spec is successfully processed; -1 if failed. */
5825 : :
5826 : : int
5827 : 559388 : do_spec (const char *spec)
5828 : : {
5829 : 559388 : int value;
5830 : :
5831 : 559388 : value = do_spec_2 (spec, NULL);
5832 : :
5833 : : /* Force out any unfinished command.
5834 : : If -pipe, this forces out the last command if it ended in `|'. */
5835 : 559388 : if (value == 0)
5836 : : {
5837 : 553729 : if (argbuf.length () > 0
5838 : 831677 : && !strcmp (argbuf.last (), "|"))
5839 : 0 : argbuf.pop ();
5840 : :
5841 : 553729 : set_collect_gcc_options ();
5842 : :
5843 : 553729 : if (argbuf.length () > 0)
5844 : 277948 : value = execute ();
5845 : : }
5846 : :
5847 : 559388 : return value;
5848 : : }
5849 : :
5850 : : /* Process the spec SPEC, with SOFT_MATCHED_PART designating the current value
5851 : : of a matched * pattern which may be re-injected by way of %*. */
5852 : :
5853 : : static int
5854 : 5276779 : do_spec_2 (const char *spec, const char *soft_matched_part)
5855 : : {
5856 : 5276779 : int result;
5857 : :
5858 : 5276779 : clear_args ();
5859 : 5276779 : arg_going = 0;
5860 : 5276779 : delete_this_arg = 0;
5861 : 5276779 : this_is_output_file = 0;
5862 : 5276779 : this_is_library_file = 0;
5863 : 5276779 : this_is_linker_script = 0;
5864 : 5276779 : input_from_pipe = 0;
5865 : 5276779 : suffix_subst = NULL;
5866 : :
5867 : 5276779 : result = do_spec_1 (spec, 0, soft_matched_part);
5868 : :
5869 : 5276779 : end_going_arg ();
5870 : :
5871 : 5276779 : return result;
5872 : : }
5873 : :
5874 : : /* Process the given spec string and add any new options to the end
5875 : : of the switches/n_switches array. */
5876 : :
5877 : : static void
5878 : 2664909 : do_option_spec (const char *name, const char *spec)
5879 : : {
5880 : 2664909 : unsigned int i, value_count, value_len;
5881 : 2664909 : const char *p, *q, *value;
5882 : 2664909 : char *tmp_spec, *tmp_spec_p;
5883 : :
5884 : 2664909 : if (configure_default_options[0].name == NULL)
5885 : : return;
5886 : :
5887 : 7106424 : for (i = 0; i < ARRAY_SIZE (configure_default_options); i++)
5888 : 5033717 : if (strcmp (configure_default_options[i].name, name) == 0)
5889 : : break;
5890 : 2664909 : if (i == ARRAY_SIZE (configure_default_options))
5891 : : return;
5892 : :
5893 : 592202 : value = configure_default_options[i].value;
5894 : 592202 : value_len = strlen (value);
5895 : :
5896 : : /* Compute the size of the final spec. */
5897 : 592202 : value_count = 0;
5898 : 592202 : p = spec;
5899 : 1184404 : while ((p = strstr (p, "%(VALUE)")) != NULL)
5900 : : {
5901 : 592202 : p ++;
5902 : 592202 : value_count ++;
5903 : : }
5904 : :
5905 : : /* Replace each %(VALUE) by the specified value. */
5906 : 592202 : tmp_spec = (char *) alloca (strlen (spec) + 1
5907 : : + value_count * (value_len - strlen ("%(VALUE)")));
5908 : 592202 : tmp_spec_p = tmp_spec;
5909 : 592202 : q = spec;
5910 : 1184404 : while ((p = strstr (q, "%(VALUE)")) != NULL)
5911 : : {
5912 : 592202 : memcpy (tmp_spec_p, q, p - q);
5913 : 592202 : tmp_spec_p = tmp_spec_p + (p - q);
5914 : 592202 : memcpy (tmp_spec_p, value, value_len);
5915 : 592202 : tmp_spec_p += value_len;
5916 : 592202 : q = p + strlen ("%(VALUE)");
5917 : : }
5918 : 592202 : strcpy (tmp_spec_p, q);
5919 : :
5920 : 592202 : do_self_spec (tmp_spec);
5921 : : }
5922 : :
5923 : : /* Process the given spec string and add any new options to the end
5924 : : of the switches/n_switches array. */
5925 : :
5926 : : static void
5927 : 2665284 : do_self_spec (const char *spec)
5928 : : {
5929 : 2665284 : int i;
5930 : :
5931 : 2665284 : do_spec_2 (spec, NULL);
5932 : 2665284 : do_spec_1 (" ", 0, NULL);
5933 : :
5934 : : /* Mark %<S switches processed by do_self_spec to be ignored permanently.
5935 : : do_self_specs adds the replacements to switches array, so it shouldn't
5936 : : be processed afterwards. */
5937 : 61959917 : for (i = 0; i < n_switches; i++)
5938 : 56629349 : if ((switches[i].live_cond & SWITCH_IGNORE))
5939 : 670 : switches[i].live_cond |= SWITCH_IGNORE_PERMANENTLY;
5940 : :
5941 : 2665284 : if (argbuf.length () > 0)
5942 : : {
5943 : 559815 : const char **argbuf_copy;
5944 : 559815 : struct cl_decoded_option *decoded_options;
5945 : 559815 : struct cl_option_handlers handlers;
5946 : 559815 : unsigned int decoded_options_count;
5947 : 559815 : unsigned int j;
5948 : :
5949 : : /* Create a copy of argbuf with a dummy argv[0] entry for
5950 : : decode_cmdline_options_to_array. */
5951 : 559815 : argbuf_copy = XNEWVEC (const char *,
5952 : : argbuf.length () + 1);
5953 : 559815 : argbuf_copy[0] = "";
5954 : 559815 : memcpy (argbuf_copy + 1, argbuf.address (),
5955 : 559815 : argbuf.length () * sizeof (const char *));
5956 : :
5957 : 1119630 : decode_cmdline_options_to_array (argbuf.length () + 1,
5958 : : argbuf_copy,
5959 : : CL_DRIVER, &decoded_options,
5960 : : &decoded_options_count);
5961 : 559815 : free (argbuf_copy);
5962 : :
5963 : 559815 : set_option_handlers (&handlers);
5964 : :
5965 : 1122118 : for (j = 1; j < decoded_options_count; j++)
5966 : : {
5967 : 562303 : switch (decoded_options[j].opt_index)
5968 : : {
5969 : 0 : case OPT_SPECIAL_input_file:
5970 : : /* Specs should only generate options, not input
5971 : : files. */
5972 : 0 : if (strcmp (decoded_options[j].arg, "-") != 0)
5973 : 0 : fatal_error (input_location,
5974 : : "switch %qs does not start with %<-%>",
5975 : : decoded_options[j].arg);
5976 : : else
5977 : 0 : fatal_error (input_location,
5978 : : "spec-generated switch is just %<-%>");
5979 : 1244 : break;
5980 : :
5981 : 1244 : case OPT_fcompare_debug_second:
5982 : 1244 : case OPT_fcompare_debug:
5983 : 1244 : case OPT_fcompare_debug_:
5984 : 1244 : case OPT_o:
5985 : : /* Avoid duplicate processing of some options from
5986 : : compare-debug specs; just save them here. */
5987 : 1244 : save_switch (decoded_options[j].canonical_option[0],
5988 : 1244 : (decoded_options[j].canonical_option_num_elements
5989 : : - 1),
5990 : 1244 : &decoded_options[j].canonical_option[1], false, true);
5991 : 1244 : break;
5992 : :
5993 : 561059 : default:
5994 : 561059 : read_cmdline_option (&global_options, &global_options_set,
5995 : : decoded_options + j, UNKNOWN_LOCATION,
5996 : : CL_DRIVER, &handlers, global_dc);
5997 : 561059 : break;
5998 : : }
5999 : : }
6000 : :
6001 : 559815 : free (decoded_options);
6002 : :
6003 : 559815 : alloc_switch ();
6004 : 559815 : switches[n_switches].part1 = 0;
6005 : : }
6006 : 2665284 : }
6007 : :
6008 : : /* Callback for processing %D and %I specs. */
6009 : :
6010 : : struct spec_path_info {
6011 : : const char *option;
6012 : : const char *append;
6013 : : size_t append_len;
6014 : : bool omit_relative;
6015 : : bool separate_options;
6016 : : bool realpaths;
6017 : : };
6018 : :
6019 : : static void *
6020 : 3316420 : spec_path (char *path, void *data)
6021 : : {
6022 : 3316420 : struct spec_path_info *info = (struct spec_path_info *) data;
6023 : 3316420 : size_t len = 0;
6024 : 3316420 : char save = 0;
6025 : :
6026 : : /* The path must exist; we want to resolve it to the realpath so that this
6027 : : can be embedded as a runpath. */
6028 : 3316420 : if (info->realpaths)
6029 : 0 : path = lrealpath (path);
6030 : :
6031 : : /* However, if we failed to resolve it - perhaps because there was a bogus
6032 : : -B option on the command line, then punt on this entry. */
6033 : 3316420 : if (!path)
6034 : : return NULL;
6035 : :
6036 : 3316420 : if (info->omit_relative && !IS_ABSOLUTE_PATH (path))
6037 : : return NULL;
6038 : :
6039 : 3316420 : if (info->append_len != 0)
6040 : : {
6041 : 1374604 : len = strlen (path);
6042 : 1374604 : memcpy (path + len, info->append, info->append_len + 1);
6043 : : }
6044 : :
6045 : 3316420 : if (!is_directory (path))
6046 : : return NULL;
6047 : :
6048 : 1243929 : do_spec_1 (info->option, 1, NULL);
6049 : 1243929 : if (info->separate_options)
6050 : 442074 : do_spec_1 (" ", 0, NULL);
6051 : :
6052 : 1243929 : if (info->append_len == 0)
6053 : : {
6054 : 801855 : len = strlen (path);
6055 : 801855 : save = path[len - 1];
6056 : 801855 : if (IS_DIR_SEPARATOR (path[len - 1]))
6057 : 801855 : path[len - 1] = '\0';
6058 : : }
6059 : :
6060 : 1243929 : do_spec_1 (path, 1, NULL);
6061 : 1243929 : do_spec_1 (" ", 0, NULL);
6062 : :
6063 : : /* Must not damage the original path. */
6064 : 1243929 : if (info->append_len == 0)
6065 : 801855 : path[len - 1] = save;
6066 : :
6067 : : return NULL;
6068 : : }
6069 : :
6070 : : /* True if we should compile INFILE. */
6071 : :
6072 : : static bool
6073 : 45041 : compile_input_file_p (struct infile *infile)
6074 : : {
6075 : 27153 : if ((!infile->language) || (infile->language[0] != '*'))
6076 : 40814 : if (infile->incompiler == input_file_compiler)
6077 : 0 : return true;
6078 : : return false;
6079 : : }
6080 : :
6081 : : /* Process each member of VEC as a spec. */
6082 : :
6083 : : static void
6084 : 462494 : do_specs_vec (vec<char_p> vec)
6085 : : {
6086 : 462576 : for (char *opt : vec)
6087 : : {
6088 : 58 : do_spec_1 (opt, 1, NULL);
6089 : : /* Make each accumulated option a separate argument. */
6090 : 58 : do_spec_1 (" ", 0, NULL);
6091 : : }
6092 : 462494 : }
6093 : :
6094 : : /* Add options passed via -Xassembler or -Wa to COLLECT_AS_OPTIONS. */
6095 : :
6096 : : static void
6097 : 295976 : putenv_COLLECT_AS_OPTIONS (vec<char_p> vec)
6098 : : {
6099 : 295976 : if (vec.is_empty ())
6100 : 295976 : return;
6101 : :
6102 : 91 : obstack_init (&collect_obstack);
6103 : 91 : obstack_grow (&collect_obstack, "COLLECT_AS_OPTIONS=",
6104 : : strlen ("COLLECT_AS_OPTIONS="));
6105 : :
6106 : 91 : char *opt;
6107 : 91 : unsigned ix;
6108 : :
6109 : 274 : FOR_EACH_VEC_ELT (vec, ix, opt)
6110 : : {
6111 : 183 : obstack_1grow (&collect_obstack, '\'');
6112 : 183 : obstack_grow (&collect_obstack, opt, strlen (opt));
6113 : 183 : obstack_1grow (&collect_obstack, '\'');
6114 : 183 : if (ix < vec.length () - 1)
6115 : 92 : obstack_1grow(&collect_obstack, ' ');
6116 : : }
6117 : :
6118 : 91 : obstack_1grow (&collect_obstack, '\0');
6119 : 91 : xputenv (XOBFINISH (&collect_obstack, char *));
6120 : : }
6121 : :
6122 : : /* Process the sub-spec SPEC as a portion of a larger spec.
6123 : : This is like processing a whole spec except that we do
6124 : : not initialize at the beginning and we do not supply a
6125 : : newline by default at the end.
6126 : : INSWITCH nonzero means don't process %-sequences in SPEC;
6127 : : in this case, % is treated as an ordinary character.
6128 : : This is used while substituting switches.
6129 : : INSWITCH nonzero also causes SPC not to terminate an argument.
6130 : :
6131 : : Value is zero unless a line was finished
6132 : : and the command on that line reported an error. */
6133 : :
6134 : : static int
6135 : 51084440 : do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part)
6136 : : {
6137 : 51084440 : const char *p = spec;
6138 : 51084440 : int c;
6139 : 51084440 : int i;
6140 : 51084440 : int value;
6141 : :
6142 : : /* If it's an empty string argument to a switch, keep it as is. */
6143 : 51084440 : if (inswitch && !*p)
6144 : 1 : arg_going = 1;
6145 : :
6146 : 513077455 : while ((c = *p++))
6147 : : /* If substituting a switch, treat all chars like letters.
6148 : : Otherwise, NL, SPC, TAB and % are special. */
6149 : 462040683 : switch (inswitch ? 'a' : c)
6150 : : {
6151 : 261815 : case '\n':
6152 : 261815 : end_going_arg ();
6153 : :
6154 : 261815 : if (argbuf.length () > 0
6155 : 523630 : && !strcmp (argbuf.last (), "|"))
6156 : : {
6157 : : /* A `|' before the newline means use a pipe here,
6158 : : but only if -pipe was specified.
6159 : : Otherwise, execute now and don't pass the `|' as an arg. */
6160 : 166460 : if (use_pipes)
6161 : : {
6162 : 0 : input_from_pipe = 1;
6163 : 0 : break;
6164 : : }
6165 : : else
6166 : 166460 : argbuf.pop ();
6167 : : }
6168 : :
6169 : 261815 : set_collect_gcc_options ();
6170 : :
6171 : 261815 : if (argbuf.length () > 0)
6172 : : {
6173 : 261815 : value = execute ();
6174 : 261815 : if (value)
6175 : : return value;
6176 : : }
6177 : : /* Reinitialize for a new command, and for a new argument. */
6178 : 256156 : clear_args ();
6179 : 256156 : arg_going = 0;
6180 : 256156 : delete_this_arg = 0;
6181 : 256156 : this_is_output_file = 0;
6182 : 256156 : this_is_library_file = 0;
6183 : 256156 : this_is_linker_script = 0;
6184 : 256156 : input_from_pipe = 0;
6185 : 256156 : break;
6186 : :
6187 : 166460 : case '|':
6188 : 166460 : end_going_arg ();
6189 : :
6190 : : /* Use pipe */
6191 : 166460 : obstack_1grow (&obstack, c);
6192 : 166460 : arg_going = 1;
6193 : 166460 : break;
6194 : :
6195 : 69183850 : case '\t':
6196 : 69183850 : case ' ':
6197 : 69183850 : end_going_arg ();
6198 : :
6199 : : /* Reinitialize for a new argument. */
6200 : 69183850 : delete_this_arg = 0;
6201 : 69183850 : this_is_output_file = 0;
6202 : 69183850 : this_is_library_file = 0;
6203 : 69183850 : this_is_linker_script = 0;
6204 : 69183850 : break;
6205 : :
6206 : 48569907 : case '%':
6207 : 48569907 : switch (c = *p++)
6208 : : {
6209 : 0 : case 0:
6210 : 0 : fatal_error (input_location, "spec %qs invalid", spec);
6211 : :
6212 : 3581 : case 'b':
6213 : : /* Don't use %b in the linker command. */
6214 : 3581 : gcc_assert (suffixed_basename_length);
6215 : 3581 : if (!this_is_output_file && dumpdir_length)
6216 : 681 : obstack_grow (&obstack, dumpdir, dumpdir_length);
6217 : 3581 : if (this_is_output_file || !outbase_length)
6218 : 3239 : obstack_grow (&obstack, input_basename, basename_length);
6219 : : else
6220 : 342 : obstack_grow (&obstack, outbase, outbase_length);
6221 : 3581 : if (compare_debug < 0)
6222 : 6 : obstack_grow (&obstack, ".gk", 3);
6223 : 3581 : arg_going = 1;
6224 : 3581 : break;
6225 : :
6226 : 10 : case 'B':
6227 : : /* Don't use %B in the linker command. */
6228 : 10 : gcc_assert (suffixed_basename_length);
6229 : 10 : if (!this_is_output_file && dumpdir_length)
6230 : 0 : obstack_grow (&obstack, dumpdir, dumpdir_length);
6231 : 10 : if (this_is_output_file || !outbase_length)
6232 : 5 : obstack_grow (&obstack, input_basename, basename_length);
6233 : : else
6234 : 5 : obstack_grow (&obstack, outbase, outbase_length);
6235 : 10 : if (compare_debug < 0)
6236 : 3 : obstack_grow (&obstack, ".gk", 3);
6237 : 10 : obstack_grow (&obstack, input_basename + basename_length,
6238 : : suffixed_basename_length - basename_length);
6239 : :
6240 : 10 : arg_going = 1;
6241 : 10 : break;
6242 : :
6243 : 96499 : case 'd':
6244 : 96499 : delete_this_arg = 2;
6245 : 96499 : break;
6246 : :
6247 : : /* Dump out the directories specified with LIBRARY_PATH,
6248 : : followed by the absolute directories
6249 : : that we search for startfiles. */
6250 : 104893 : case 'D':
6251 : 104893 : {
6252 : 104893 : struct spec_path_info info;
6253 : :
6254 : 104893 : info.option = "-L";
6255 : 104893 : info.append_len = 0;
6256 : : #ifdef RELATIVE_PREFIX_NOT_LINKDIR
6257 : : /* Used on systems which record the specified -L dirs
6258 : : and use them to search for dynamic linking.
6259 : : Relative directories always come from -B,
6260 : : and it is better not to use them for searching
6261 : : at run time. In particular, stage1 loses. */
6262 : : info.omit_relative = true;
6263 : : #else
6264 : 104893 : info.omit_relative = false;
6265 : : #endif
6266 : 104893 : info.separate_options = false;
6267 : 104893 : info.realpaths = false;
6268 : :
6269 : 104893 : for_each_path (&startfile_prefixes, true, 0, spec_path, &info);
6270 : : }
6271 : 104893 : break;
6272 : :
6273 : 0 : case 'P':
6274 : 0 : {
6275 : 0 : struct spec_path_info info;
6276 : :
6277 : 0 : info.option = RUNPATH_OPTION;
6278 : 0 : info.append_len = 0;
6279 : 0 : info.omit_relative = false;
6280 : 0 : info.separate_options = true;
6281 : : /* We want to embed the actual paths that have the libraries. */
6282 : 0 : info.realpaths = true;
6283 : :
6284 : 0 : for_each_path (&startfile_prefixes, true, 0, spec_path, &info);
6285 : : }
6286 : 0 : break;
6287 : :
6288 : : case 'e':
6289 : : /* %efoo means report an error with `foo' as error message
6290 : : and don't execute any more commands for this file. */
6291 : : {
6292 : : const char *q = p;
6293 : : char *buf;
6294 : 0 : while (*p != 0 && *p != '\n')
6295 : 0 : p++;
6296 : 0 : buf = (char *) alloca (p - q + 1);
6297 : 0 : strncpy (buf, q, p - q);
6298 : 0 : buf[p - q] = 0;
6299 : 0 : error ("%s", _(buf));
6300 : 0 : return -1;
6301 : : }
6302 : : break;
6303 : : case 'n':
6304 : : /* %nfoo means report a notice with `foo' on stderr. */
6305 : : {
6306 : : const char *q = p;
6307 : : char *buf;
6308 : 0 : while (*p != 0 && *p != '\n')
6309 : 0 : p++;
6310 : 0 : buf = (char *) alloca (p - q + 1);
6311 : 0 : strncpy (buf, q, p - q);
6312 : 0 : buf[p - q] = 0;
6313 : 0 : inform (UNKNOWN_LOCATION, "%s", _(buf));
6314 : 0 : if (*p)
6315 : 0 : p++;
6316 : : }
6317 : : break;
6318 : :
6319 : 902 : case 'j':
6320 : 902 : {
6321 : 902 : struct stat st;
6322 : :
6323 : : /* If save_temps_flag is off, and the HOST_BIT_BUCKET is
6324 : : defined, and it is not a directory, and it is
6325 : : writable, use it. Otherwise, treat this like any
6326 : : other temporary file. */
6327 : :
6328 : 902 : if ((!save_temps_flag)
6329 : 902 : && (stat (HOST_BIT_BUCKET, &st) == 0) && (!S_ISDIR (st.st_mode))
6330 : 1804 : && (access (HOST_BIT_BUCKET, W_OK) == 0))
6331 : : {
6332 : 902 : obstack_grow (&obstack, HOST_BIT_BUCKET,
6333 : : strlen (HOST_BIT_BUCKET));
6334 : 902 : delete_this_arg = 0;
6335 : 902 : arg_going = 1;
6336 : 902 : break;
6337 : : }
6338 : : }
6339 : 0 : goto create_temp_file;
6340 : 166460 : case '|':
6341 : 166460 : if (use_pipes)
6342 : : {
6343 : 0 : obstack_1grow (&obstack, '-');
6344 : 0 : delete_this_arg = 0;
6345 : 0 : arg_going = 1;
6346 : :
6347 : : /* consume suffix */
6348 : 0 : while (*p == '.' || ISALNUM ((unsigned char) *p))
6349 : 0 : p++;
6350 : 0 : if (p[0] == '%' && p[1] == 'O')
6351 : 0 : p += 2;
6352 : :
6353 : : break;
6354 : : }
6355 : 166460 : goto create_temp_file;
6356 : 160943 : case 'm':
6357 : 160943 : if (use_pipes)
6358 : : {
6359 : : /* consume suffix */
6360 : 0 : while (*p == '.' || ISALNUM ((unsigned char) *p))
6361 : 0 : p++;
6362 : 0 : if (p[0] == '%' && p[1] == 'O')
6363 : 0 : p += 2;
6364 : :
6365 : : break;
6366 : : }
6367 : 160943 : goto create_temp_file;
6368 : 516146 : case 'g':
6369 : 516146 : case 'u':
6370 : 516146 : case 'U':
6371 : 516146 : create_temp_file:
6372 : 516146 : {
6373 : 516146 : struct temp_name *t;
6374 : 516146 : int suffix_length;
6375 : 516146 : const char *suffix = p;
6376 : 516146 : char *saved_suffix = NULL;
6377 : :
6378 : 1538014 : while (*p == '.' || ISALNUM ((unsigned char) *p))
6379 : 1021868 : p++;
6380 : 516146 : suffix_length = p - suffix;
6381 : 516146 : if (p[0] == '%' && p[1] == 'O')
6382 : : {
6383 : 96715 : p += 2;
6384 : : /* We don't support extra suffix characters after %O. */
6385 : 96715 : if (*p == '.' || ISALNUM ((unsigned char) *p))
6386 : 0 : fatal_error (input_location,
6387 : : "spec %qs has invalid %<%%0%c%>", spec, *p);
6388 : 96715 : if (suffix_length == 0)
6389 : : suffix = TARGET_OBJECT_SUFFIX;
6390 : : else
6391 : : {
6392 : 0 : saved_suffix
6393 : 0 : = XNEWVEC (char, suffix_length
6394 : : + strlen (TARGET_OBJECT_SUFFIX) + 1);
6395 : 0 : strncpy (saved_suffix, suffix, suffix_length);
6396 : 0 : strcpy (saved_suffix + suffix_length,
6397 : : TARGET_OBJECT_SUFFIX);
6398 : : }
6399 : 96715 : suffix_length += strlen (TARGET_OBJECT_SUFFIX);
6400 : : }
6401 : :
6402 : 516146 : if (compare_debug < 0)
6403 : : {
6404 : 613 : suffix = concat (".gk", suffix, NULL);
6405 : 613 : suffix_length += 3;
6406 : : }
6407 : :
6408 : : /* If -save-temps was specified, use that for the
6409 : : temp file. */
6410 : 516146 : if (save_temps_flag)
6411 : : {
6412 : 1178 : char *tmp;
6413 : 1178 : bool adjusted_suffix = false;
6414 : 1178 : if (suffix_length
6415 : 1178 : && !outbase_length && !basename_length
6416 : 220 : && !dumpdir_trailing_dash_added)
6417 : : {
6418 : 20 : adjusted_suffix = true;
6419 : 20 : suffix++;
6420 : 20 : suffix_length--;
6421 : : }
6422 : 1178 : temp_filename_length
6423 : 1178 : = dumpdir_length + suffix_length + 1;
6424 : 1178 : if (outbase_length)
6425 : 72 : temp_filename_length += outbase_length;
6426 : : else
6427 : 1106 : temp_filename_length += basename_length;
6428 : 1178 : tmp = (char *) alloca (temp_filename_length);
6429 : 1178 : if (dumpdir_length)
6430 : 1020 : memcpy (tmp, dumpdir, dumpdir_length);
6431 : 1178 : if (outbase_length)
6432 : 72 : memcpy (tmp + dumpdir_length, outbase,
6433 : : outbase_length);
6434 : 1106 : else if (basename_length)
6435 : 886 : memcpy (tmp + dumpdir_length, input_basename,
6436 : : basename_length);
6437 : 1178 : memcpy (tmp + temp_filename_length - suffix_length - 1,
6438 : : suffix, suffix_length);
6439 : 1178 : if (adjusted_suffix)
6440 : : {
6441 : 20 : adjusted_suffix = false;
6442 : 20 : suffix--;
6443 : 20 : suffix_length++;
6444 : : }
6445 : 1178 : tmp[temp_filename_length - 1] = '\0';
6446 : 1178 : temp_filename = tmp;
6447 : :
6448 : 1178 : if (filename_cmp (temp_filename, gcc_input_filename) != 0)
6449 : : {
6450 : : #ifndef HOST_LACKS_INODE_NUMBERS
6451 : 1178 : struct stat st_temp;
6452 : :
6453 : : /* Note, set_input() resets input_stat_set to 0. */
6454 : 1178 : if (input_stat_set == 0)
6455 : : {
6456 : 549 : input_stat_set = stat (gcc_input_filename,
6457 : : &input_stat);
6458 : 549 : if (input_stat_set >= 0)
6459 : 549 : input_stat_set = 1;
6460 : : }
6461 : :
6462 : : /* If we have the stat for the gcc_input_filename
6463 : : and we can do the stat for the temp_filename
6464 : : then the they could still refer to the same
6465 : : file if st_dev/st_ino's are the same. */
6466 : 1178 : if (input_stat_set != 1
6467 : 1178 : || stat (temp_filename, &st_temp) < 0
6468 : 361 : || input_stat.st_dev != st_temp.st_dev
6469 : 1192 : || input_stat.st_ino != st_temp.st_ino)
6470 : : #else
6471 : : /* Just compare canonical pathnames. */
6472 : : char* input_realname = lrealpath (gcc_input_filename);
6473 : : char* temp_realname = lrealpath (temp_filename);
6474 : : bool files_differ = filename_cmp (input_realname, temp_realname);
6475 : : free (input_realname);
6476 : : free (temp_realname);
6477 : : if (files_differ)
6478 : : #endif
6479 : : {
6480 : 1178 : temp_filename
6481 : 1178 : = save_string (temp_filename,
6482 : : temp_filename_length - 1);
6483 : 1178 : obstack_grow (&obstack, temp_filename,
6484 : : temp_filename_length);
6485 : 1178 : arg_going = 1;
6486 : 1178 : delete_this_arg = 0;
6487 : 1178 : break;
6488 : : }
6489 : : }
6490 : : }
6491 : :
6492 : : /* See if we already have an association of %g/%u/%U and
6493 : : suffix. */
6494 : 880711 : for (t = temp_names; t; t = t->next)
6495 : 533668 : if (t->length == suffix_length
6496 : 357158 : && strncmp (t->suffix, suffix, suffix_length) == 0
6497 : 171852 : && t->unique == (c == 'u' || c == 'U' || c == 'j'))
6498 : : break;
6499 : :
6500 : : /* Make a new association if needed. %u and %j
6501 : : require one. */
6502 : 514968 : if (t == 0 || c == 'u' || c == 'j')
6503 : : {
6504 : 350776 : if (t == 0)
6505 : : {
6506 : 347043 : t = XNEW (struct temp_name);
6507 : 347043 : t->next = temp_names;
6508 : 347043 : temp_names = t;
6509 : : }
6510 : 350776 : t->length = suffix_length;
6511 : 350776 : if (saved_suffix)
6512 : : {
6513 : 0 : t->suffix = saved_suffix;
6514 : 0 : saved_suffix = NULL;
6515 : : }
6516 : : else
6517 : 350776 : t->suffix = save_string (suffix, suffix_length);
6518 : 350776 : t->unique = (c == 'u' || c == 'U' || c == 'j');
6519 : 350776 : temp_filename = make_temp_file (t->suffix);
6520 : 350776 : temp_filename_length = strlen (temp_filename);
6521 : 350776 : t->filename = temp_filename;
6522 : 350776 : t->filename_length = temp_filename_length;
6523 : : }
6524 : :
6525 : 514968 : free (saved_suffix);
6526 : :
6527 : 514968 : obstack_grow (&obstack, t->filename, t->filename_length);
6528 : 514968 : delete_this_arg = 1;
6529 : : }
6530 : 514968 : arg_going = 1;
6531 : 514968 : break;
6532 : :
6533 : 285146 : case 'i':
6534 : 285146 : if (combine_inputs)
6535 : : {
6536 : : /* We are going to expand `%i' into `@FILE', where FILE
6537 : : is a newly-created temporary filename. The filenames
6538 : : that would usually be expanded in place of %o will be
6539 : : written to the temporary file. */
6540 : 31658 : if (at_file_supplied)
6541 : 12976 : open_at_file ();
6542 : :
6543 : 76699 : for (i = 0; (int) i < n_infiles; i++)
6544 : 90082 : if (compile_input_file_p (&infiles[i]))
6545 : : {
6546 : 40752 : store_arg (infiles[i].name, 0, 0);
6547 : 40752 : infiles[i].compiled = true;
6548 : : }
6549 : :
6550 : 31658 : if (at_file_supplied)
6551 : 12976 : close_at_file ();
6552 : : }
6553 : : else
6554 : : {
6555 : 253488 : obstack_grow (&obstack, gcc_input_filename,
6556 : : input_filename_length);
6557 : 253488 : arg_going = 1;
6558 : : }
6559 : : break;
6560 : :
6561 : 219954 : case 'I':
6562 : 219954 : {
6563 : 219954 : struct spec_path_info info;
6564 : :
6565 : 219954 : if (multilib_dir)
6566 : : {
6567 : 5953 : do_spec_1 ("-imultilib", 1, NULL);
6568 : : /* Make this a separate argument. */
6569 : 5953 : do_spec_1 (" ", 0, NULL);
6570 : 5953 : do_spec_1 (multilib_dir, 1, NULL);
6571 : 5953 : do_spec_1 (" ", 0, NULL);
6572 : : }
6573 : :
6574 : 219954 : if (multiarch_dir)
6575 : : {
6576 : 0 : do_spec_1 ("-imultiarch", 1, NULL);
6577 : : /* Make this a separate argument. */
6578 : 0 : do_spec_1 (" ", 0, NULL);
6579 : 0 : do_spec_1 (multiarch_dir, 1, NULL);
6580 : 0 : do_spec_1 (" ", 0, NULL);
6581 : : }
6582 : :
6583 : 219954 : if (gcc_exec_prefix)
6584 : : {
6585 : 219954 : do_spec_1 ("-iprefix", 1, NULL);
6586 : : /* Make this a separate argument. */
6587 : 219954 : do_spec_1 (" ", 0, NULL);
6588 : 219954 : do_spec_1 (gcc_exec_prefix, 1, NULL);
6589 : 219954 : do_spec_1 (" ", 0, NULL);
6590 : : }
6591 : :
6592 : 219954 : if (target_system_root_changed ||
6593 : 219954 : (target_system_root && target_sysroot_hdrs_suffix))
6594 : : {
6595 : 0 : do_spec_1 ("-isysroot", 1, NULL);
6596 : : /* Make this a separate argument. */
6597 : 0 : do_spec_1 (" ", 0, NULL);
6598 : 0 : do_spec_1 (target_system_root, 1, NULL);
6599 : 0 : if (target_sysroot_hdrs_suffix)
6600 : 0 : do_spec_1 (target_sysroot_hdrs_suffix, 1, NULL);
6601 : 0 : do_spec_1 (" ", 0, NULL);
6602 : : }
6603 : :
6604 : 219954 : info.option = "-isystem";
6605 : 219954 : info.append = "include";
6606 : 219954 : info.append_len = strlen (info.append);
6607 : 219954 : info.omit_relative = false;
6608 : 219954 : info.separate_options = true;
6609 : 219954 : info.realpaths = false;
6610 : :
6611 : 219954 : for_each_path (&include_prefixes, false, info.append_len,
6612 : : spec_path, &info);
6613 : :
6614 : 219954 : info.append = "include-fixed";
6615 : 219954 : if (*sysroot_hdrs_suffix_spec)
6616 : 0 : info.append = concat (info.append, dir_separator_str,
6617 : : multilib_dir, NULL);
6618 : 219954 : else if (multiarch_dir)
6619 : : {
6620 : : /* For multiarch, search include-fixed/<multiarch-dir>
6621 : : before include-fixed. */
6622 : 0 : info.append = concat (info.append, dir_separator_str,
6623 : : multiarch_dir, NULL);
6624 : 0 : info.append_len = strlen (info.append);
6625 : 0 : for_each_path (&include_prefixes, false, info.append_len,
6626 : : spec_path, &info);
6627 : :
6628 : 0 : info.append = "include-fixed";
6629 : : }
6630 : 219954 : info.append_len = strlen (info.append);
6631 : 219954 : for_each_path (&include_prefixes, false, info.append_len,
6632 : : spec_path, &info);
6633 : : }
6634 : 219954 : break;
6635 : :
6636 : 94522 : case 'o':
6637 : : /* We are going to expand `%o' into `@FILE', where FILE
6638 : : is a newly-created temporary filename. The filenames
6639 : : that would usually be expanded in place of %o will be
6640 : : written to the temporary file. */
6641 : 94522 : if (at_file_supplied)
6642 : 6 : open_at_file ();
6643 : :
6644 : 419501 : for (i = 0; i < n_infiles + lang_specific_extra_outfiles; i++)
6645 : 324979 : if (outfiles[i])
6646 : 324939 : store_arg (outfiles[i], 0, 0);
6647 : :
6648 : 94522 : if (at_file_supplied)
6649 : 6 : close_at_file ();
6650 : : break;
6651 : :
6652 : 3918 : case 'O':
6653 : 3918 : obstack_grow (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX));
6654 : 3918 : arg_going = 1;
6655 : 3918 : break;
6656 : :
6657 : 533690 : case 's':
6658 : 533690 : this_is_library_file = 1;
6659 : 533690 : break;
6660 : :
6661 : 0 : case 'T':
6662 : 0 : this_is_linker_script = 1;
6663 : 0 : break;
6664 : :
6665 : 457 : case 'V':
6666 : 457 : outfiles[input_file_number] = NULL;
6667 : 457 : break;
6668 : :
6669 : 99470 : case 'w':
6670 : 99470 : this_is_output_file = 1;
6671 : 99470 : break;
6672 : :
6673 : 172543 : case 'W':
6674 : 172543 : {
6675 : 172543 : unsigned int cur_index = argbuf.length ();
6676 : : /* Handle the {...} following the %W. */
6677 : 172543 : if (*p != '{')
6678 : 0 : fatal_error (input_location,
6679 : : "spec %qs has invalid %<%%W%c%>", spec, *p);
6680 : 172543 : p = handle_braces (p + 1);
6681 : 172543 : if (p == 0)
6682 : : return -1;
6683 : 172543 : end_going_arg ();
6684 : : /* If any args were output, mark the last one for deletion
6685 : : on failure. */
6686 : 345086 : if (argbuf.length () != cur_index)
6687 : 169405 : record_temp_file (argbuf.last (), 0, 1);
6688 : : break;
6689 : : }
6690 : :
6691 : 299744 : case '@':
6692 : : /* Handle the {...} following the %@. */
6693 : 299744 : if (*p != '{')
6694 : 0 : fatal_error (input_location,
6695 : : "spec %qs has invalid %<%%@%c%>", spec, *p);
6696 : 299744 : if (at_file_supplied)
6697 : 15 : open_at_file ();
6698 : 299744 : p = handle_braces (p + 1);
6699 : 299744 : if (at_file_supplied)
6700 : 15 : close_at_file ();
6701 : 299744 : if (p == 0)
6702 : : return -1;
6703 : : break;
6704 : :
6705 : : /* %x{OPTION} records OPTION for %X to output. */
6706 : 0 : case 'x':
6707 : 0 : {
6708 : 0 : const char *p1 = p;
6709 : 0 : char *string;
6710 : :
6711 : : /* Skip past the option value and make a copy. */
6712 : 0 : if (*p != '{')
6713 : 0 : fatal_error (input_location,
6714 : : "spec %qs has invalid %<%%x%c%>", spec, *p);
6715 : 0 : while (*p++ != '}')
6716 : : ;
6717 : 0 : string = save_string (p1 + 1, p - p1 - 2);
6718 : :
6719 : : /* See if we already recorded this option. */
6720 : 0 : for (const char *opt : linker_options)
6721 : 0 : if (! strcmp (string, opt))
6722 : : {
6723 : 0 : free (string);
6724 : 0 : return 0;
6725 : : }
6726 : :
6727 : : /* This option is new; add it. */
6728 : 0 : add_linker_option (string, strlen (string));
6729 : 0 : free (string);
6730 : : }
6731 : 0 : break;
6732 : :
6733 : : /* Dump out the options accumulated previously using %x. */
6734 : 94522 : case 'X':
6735 : 94522 : do_specs_vec (linker_options);
6736 : 94522 : break;
6737 : :
6738 : : /* Dump out the options accumulated previously using -Wa,. */
6739 : 162750 : case 'Y':
6740 : 162750 : do_specs_vec (assembler_options);
6741 : 162750 : break;
6742 : :
6743 : : /* Dump out the options accumulated previously using -Wp,. */
6744 : 205222 : case 'Z':
6745 : 205222 : do_specs_vec (preprocessor_options);
6746 : 205222 : break;
6747 : :
6748 : : /* Here are digits and numbers that just process
6749 : : a certain constant string as a spec. */
6750 : :
6751 : 282125 : case '1':
6752 : 282125 : value = do_spec_1 (cc1_spec, 0, NULL);
6753 : 282125 : if (value != 0)
6754 : : return value;
6755 : : break;
6756 : :
6757 : 95120 : case '2':
6758 : 95120 : value = do_spec_1 (cc1plus_spec, 0, NULL);
6759 : 95120 : if (value != 0)
6760 : : return value;
6761 : : break;
6762 : :
6763 : 162750 : case 'a':
6764 : 162750 : value = do_spec_1 (asm_spec, 0, NULL);
6765 : 162750 : if (value != 0)
6766 : : return value;
6767 : : break;
6768 : :
6769 : 162750 : case 'A':
6770 : 162750 : value = do_spec_1 (asm_final_spec, 0, NULL);
6771 : 162750 : if (value != 0)
6772 : : return value;
6773 : : break;
6774 : :
6775 : 205222 : case 'C':
6776 : 205222 : {
6777 : 110228 : const char *const spec
6778 : 205222 : = (input_file_compiler->cpp_spec
6779 : 205222 : ? input_file_compiler->cpp_spec
6780 : : : cpp_spec);
6781 : 205222 : value = do_spec_1 (spec, 0, NULL);
6782 : 205222 : if (value != 0)
6783 : : return value;
6784 : : }
6785 : : break;
6786 : :
6787 : 94317 : case 'E':
6788 : 94317 : value = do_spec_1 (endfile_spec, 0, NULL);
6789 : 94317 : if (value != 0)
6790 : : return value;
6791 : : break;
6792 : :
6793 : 94522 : case 'l':
6794 : 94522 : value = do_spec_1 (link_spec, 0, NULL);
6795 : 94522 : if (value != 0)
6796 : : return value;
6797 : : break;
6798 : :
6799 : 183309 : case 'L':
6800 : 183309 : value = do_spec_1 (lib_spec, 0, NULL);
6801 : 183309 : if (value != 0)
6802 : : return value;
6803 : : break;
6804 : :
6805 : 0 : case 'M':
6806 : 0 : if (multilib_os_dir == NULL)
6807 : 0 : obstack_1grow (&obstack, '.');
6808 : : else
6809 : 0 : obstack_grow (&obstack, multilib_os_dir,
6810 : : strlen (multilib_os_dir));
6811 : : break;
6812 : :
6813 : 366420 : case 'G':
6814 : 366420 : value = do_spec_1 (libgcc_spec, 0, NULL);
6815 : 366420 : if (value != 0)
6816 : : return value;
6817 : : break;
6818 : :
6819 : 0 : case 'R':
6820 : : /* We assume there is a directory
6821 : : separator at the end of this string. */
6822 : 0 : if (target_system_root)
6823 : : {
6824 : 0 : obstack_grow (&obstack, target_system_root,
6825 : : strlen (target_system_root));
6826 : 0 : if (target_sysroot_suffix)
6827 : 0 : obstack_grow (&obstack, target_sysroot_suffix,
6828 : : strlen (target_sysroot_suffix));
6829 : : }
6830 : : break;
6831 : :
6832 : 94317 : case 'S':
6833 : 94317 : value = do_spec_1 (startfile_spec, 0, NULL);
6834 : 94317 : if (value != 0)
6835 : : return value;
6836 : : break;
6837 : :
6838 : : /* Here we define characters other than letters and digits. */
6839 : :
6840 : 39496880 : case '{':
6841 : 39496880 : p = handle_braces (p);
6842 : 39496880 : if (p == 0)
6843 : : return -1;
6844 : : break;
6845 : :
6846 : 433449 : case ':':
6847 : 433449 : p = handle_spec_function (p, NULL, soft_matched_part);
6848 : 433449 : if (p == 0)
6849 : : return -1;
6850 : : break;
6851 : :
6852 : 0 : case '%':
6853 : 0 : obstack_1grow (&obstack, '%');
6854 : 0 : break;
6855 : :
6856 : : case '.':
6857 : : {
6858 : : unsigned len = 0;
6859 : :
6860 : 11778 : while (p[len] && p[len] != ' ' && p[len] != '%')
6861 : 5907 : len++;
6862 : 5871 : suffix_subst = save_string (p - 1, len + 1);
6863 : 5871 : p += len;
6864 : : }
6865 : 5871 : break;
6866 : :
6867 : : /* Henceforth ignore the option(s) matching the pattern
6868 : : after the %<. */
6869 : 1452507 : case '<':
6870 : 1452507 : case '>':
6871 : 1452507 : {
6872 : 1452507 : unsigned len = 0;
6873 : 1452507 : int have_wildcard = 0;
6874 : 1452507 : int i;
6875 : 1452507 : int switch_option;
6876 : :
6877 : 1452507 : if (c == '>')
6878 : 1452507 : switch_option = SWITCH_IGNORE | SWITCH_KEEP_FOR_GCC;
6879 : : else
6880 : 1452485 : switch_option = SWITCH_IGNORE;
6881 : :
6882 : 17535518 : while (p[len] && p[len] != ' ' && p[len] != '\t')
6883 : 16083011 : len++;
6884 : :
6885 : 1452507 : if (p[len-1] == '*')
6886 : 15381 : have_wildcard = 1;
6887 : :
6888 : 33290389 : for (i = 0; i < n_switches; i++)
6889 : 31837882 : if (!strncmp (switches[i].part1, p, len - have_wildcard)
6890 : 48614 : && (have_wildcard || switches[i].part1[len] == '\0'))
6891 : : {
6892 : 48347 : switches[i].live_cond |= switch_option;
6893 : : /* User switch be validated from validate_all_switches.
6894 : : when the definition is seen from the spec file.
6895 : : If not defined anywhere, will be rejected. */
6896 : 48347 : if (switches[i].known)
6897 : 48347 : switches[i].validated = true;
6898 : : }
6899 : :
6900 : : p += len;
6901 : : }
6902 : : break;
6903 : :
6904 : 6798 : case '*':
6905 : 6798 : if (soft_matched_part)
6906 : : {
6907 : 6798 : if (soft_matched_part[0])
6908 : 357 : do_spec_1 (soft_matched_part, 1, NULL);
6909 : : /* Only insert a space after the substitution if it is at the
6910 : : end of the current sequence. So if:
6911 : :
6912 : : "%{foo=*:bar%*}%{foo=*:one%*two}"
6913 : :
6914 : : matches -foo=hello then it will produce:
6915 : :
6916 : : barhello onehellotwo
6917 : : */
6918 : 6798 : if (*p == 0 || *p == '}')
6919 : 6798 : do_spec_1 (" ", 0, NULL);
6920 : : }
6921 : : else
6922 : : /* Catch the case where a spec string contains something like
6923 : : '%{foo:%*}'. i.e. there is no * in the pattern on the left
6924 : : hand side of the :. */
6925 : 0 : error ("spec failure: %<%%*%> has not been initialized by pattern match");
6926 : : break;
6927 : :
6928 : : /* Process a string found as the value of a spec given by name.
6929 : : This feature allows individual machine descriptions
6930 : : to add and use their own specs. */
6931 : : case '(':
6932 : : {
6933 : 32942080 : const char *name = p;
6934 : : struct spec_list *sl;
6935 : : int len;
6936 : :
6937 : : /* The string after the S/P is the name of a spec that is to be
6938 : : processed. */
6939 : 32942080 : while (*p && *p != ')')
6940 : 30402508 : p++;
6941 : :
6942 : : /* See if it's in the list. */
6943 : 34862922 : for (len = p - name, sl = specs; sl; sl = sl->next)
6944 : 34862922 : if (sl->name_len == len && !strncmp (sl->name, name, len))
6945 : : {
6946 : 2539572 : name = *(sl->ptr_spec);
6947 : : #ifdef DEBUG_SPECS
6948 : : fnotice (stderr, "Processing spec (%s), which is '%s'\n",
6949 : : sl->name, name);
6950 : : #endif
6951 : 2539572 : break;
6952 : : }
6953 : :
6954 : 2539572 : if (sl)
6955 : : {
6956 : 2539572 : value = do_spec_1 (name, 0, NULL);
6957 : 2539572 : if (value != 0)
6958 : : return value;
6959 : : }
6960 : :
6961 : : /* Discard the closing paren. */
6962 : 2534055 : if (*p)
6963 : 2534055 : p++;
6964 : : }
6965 : : break;
6966 : :
6967 : 9 : case '"':
6968 : : /* End a previous argument, if there is one, then issue an
6969 : : empty argument. */
6970 : 9 : end_going_arg ();
6971 : 9 : arg_going = 1;
6972 : 9 : end_going_arg ();
6973 : 9 : break;
6974 : :
6975 : 0 : default:
6976 : 0 : error ("spec failure: unrecognized spec option %qc", c);
6977 : 0 : break;
6978 : : }
6979 : : break;
6980 : :
6981 : 0 : case '\\':
6982 : : /* Backslash: treat next character as ordinary. */
6983 : 0 : c = *p++;
6984 : :
6985 : : /* When adding more cases that previously matched default, make
6986 : : sure to adjust quote_spec_char_p as well. */
6987 : :
6988 : : /* Fall through. */
6989 : 343858651 : default:
6990 : : /* Ordinary character: put it into the current argument. */
6991 : 343858651 : obstack_1grow (&obstack, c);
6992 : 343858651 : arg_going = 1;
6993 : : }
6994 : :
6995 : : /* End of string. If we are processing a spec function, we need to
6996 : : end any pending argument. */
6997 : 51036772 : if (processing_spec_function)
6998 : 4367180 : end_going_arg ();
6999 : :
7000 : : return 0;
7001 : : }
7002 : :
7003 : : /* Look up a spec function. */
7004 : :
7005 : : static const struct spec_function *
7006 : 2049629 : lookup_spec_function (const char *name)
7007 : : {
7008 : 2049629 : const struct spec_function *sf;
7009 : :
7010 : 24541832 : for (sf = static_spec_functions; sf->name != NULL; sf++)
7011 : 24541832 : if (strcmp (sf->name, name) == 0)
7012 : : return sf;
7013 : :
7014 : : return NULL;
7015 : : }
7016 : :
7017 : : /* Evaluate a spec function. */
7018 : :
7019 : : static const char *
7020 : 2049629 : eval_spec_function (const char *func, const char *args,
7021 : : const char *soft_matched_part)
7022 : : {
7023 : 2049629 : const struct spec_function *sf;
7024 : 2049629 : const char *funcval;
7025 : :
7026 : : /* Saved spec processing context. */
7027 : 2049629 : vec<const_char_p> save_argbuf;
7028 : :
7029 : 2049629 : int save_arg_going;
7030 : 2049629 : int save_delete_this_arg;
7031 : 2049629 : int save_this_is_output_file;
7032 : 2049629 : int save_this_is_library_file;
7033 : 2049629 : int save_input_from_pipe;
7034 : 2049629 : int save_this_is_linker_script;
7035 : 2049629 : const char *save_suffix_subst;
7036 : :
7037 : 2049629 : int save_growing_size;
7038 : 2049629 : void *save_growing_value = NULL;
7039 : :
7040 : 2049629 : sf = lookup_spec_function (func);
7041 : 2049629 : if (sf == NULL)
7042 : 0 : fatal_error (input_location, "unknown spec function %qs", func);
7043 : :
7044 : : /* Push the spec processing context. */
7045 : 2049629 : save_argbuf = argbuf;
7046 : :
7047 : 2049629 : save_arg_going = arg_going;
7048 : 2049629 : save_delete_this_arg = delete_this_arg;
7049 : 2049629 : save_this_is_output_file = this_is_output_file;
7050 : 2049629 : save_this_is_library_file = this_is_library_file;
7051 : 2049629 : save_this_is_linker_script = this_is_linker_script;
7052 : 2049629 : save_input_from_pipe = input_from_pipe;
7053 : 2049629 : save_suffix_subst = suffix_subst;
7054 : :
7055 : : /* If we have some object growing now, finalize it so the args and function
7056 : : eval proceed from a cleared context. This is needed to prevent the first
7057 : : constructed arg from mistakenly including the growing value. We'll push
7058 : : this value back on the obstack once the function evaluation is done, to
7059 : : restore a consistent processing context for our caller. This is fine as
7060 : : the address of growing objects isn't guaranteed to remain stable until
7061 : : they are finalized, and we expect this situation to be rare enough for
7062 : : the extra copy not to be an issue. */
7063 : 2049629 : save_growing_size = obstack_object_size (&obstack);
7064 : 2049629 : if (save_growing_size > 0)
7065 : 42142 : save_growing_value = obstack_finish (&obstack);
7066 : :
7067 : : /* Create a new spec processing context, and build the function
7068 : : arguments. */
7069 : :
7070 : 2049629 : alloc_args ();
7071 : 2049629 : if (do_spec_2 (args, soft_matched_part) < 0)
7072 : 0 : fatal_error (input_location, "error in arguments to spec function %qs",
7073 : : func);
7074 : :
7075 : : /* argbuf_index is an index for the next argument to be inserted, and
7076 : : so contains the count of the args already inserted. */
7077 : :
7078 : 6148887 : funcval = (*sf->func) (argbuf.length (),
7079 : : argbuf.address ());
7080 : :
7081 : : /* Pop the spec processing context. */
7082 : 2049629 : argbuf.release ();
7083 : 2049629 : argbuf = save_argbuf;
7084 : :
7085 : 2049629 : arg_going = save_arg_going;
7086 : 2049629 : delete_this_arg = save_delete_this_arg;
7087 : 2049629 : this_is_output_file = save_this_is_output_file;
7088 : 2049629 : this_is_library_file = save_this_is_library_file;
7089 : 2049629 : this_is_linker_script = save_this_is_linker_script;
7090 : 2049629 : input_from_pipe = save_input_from_pipe;
7091 : 2049629 : suffix_subst = save_suffix_subst;
7092 : :
7093 : 2049629 : if (save_growing_size > 0)
7094 : 42142 : obstack_grow (&obstack, save_growing_value, save_growing_size);
7095 : :
7096 : 2049629 : return funcval;
7097 : : }
7098 : :
7099 : : /* Handle a spec function call of the form:
7100 : :
7101 : : %:function(args)
7102 : :
7103 : : ARGS is processed as a spec in a separate context and split into an
7104 : : argument vector in the normal fashion. The function returns a string
7105 : : containing a spec which we then process in the caller's context, or
7106 : : NULL if no processing is required.
7107 : :
7108 : : If RETVAL_NONNULL is not NULL, then store a bool whether function
7109 : : returned non-NULL.
7110 : :
7111 : : SOFT_MATCHED_PART holds the current value of a matched * pattern, which
7112 : : may be re-expanded with a %* as part of the function arguments. */
7113 : :
7114 : : static const char *
7115 : 2049629 : handle_spec_function (const char *p, bool *retval_nonnull,
7116 : : const char *soft_matched_part)
7117 : : {
7118 : 2049629 : char *func, *args;
7119 : 2049629 : const char *endp, *funcval;
7120 : 2049629 : int count;
7121 : :
7122 : 2049629 : processing_spec_function++;
7123 : :
7124 : : /* Get the function name. */
7125 : 19043422 : for (endp = p; *endp != '\0'; endp++)
7126 : : {
7127 : 19043422 : if (*endp == '(') /* ) */
7128 : : break;
7129 : : /* Only allow [A-Za-z0-9], -, and _ in function names. */
7130 : 16993793 : if (!ISALNUM (*endp) && !(*endp == '-' || *endp == '_'))
7131 : 0 : fatal_error (input_location, "malformed spec function name");
7132 : : }
7133 : 2049629 : if (*endp != '(') /* ) */
7134 : 0 : fatal_error (input_location, "no arguments for spec function");
7135 : 2049629 : func = save_string (p, endp - p);
7136 : 2049629 : p = ++endp;
7137 : :
7138 : : /* Get the arguments. */
7139 : 24953829 : for (count = 0; *endp != '\0'; endp++)
7140 : : {
7141 : : /* ( */
7142 : 24953829 : if (*endp == ')')
7143 : : {
7144 : 2138623 : if (count == 0)
7145 : : break;
7146 : 88994 : count--;
7147 : : }
7148 : 22815206 : else if (*endp == '(') /* ) */
7149 : 88994 : count++;
7150 : : }
7151 : : /* ( */
7152 : 2049629 : if (*endp != ')')
7153 : 0 : fatal_error (input_location, "malformed spec function arguments");
7154 : 2049629 : args = save_string (p, endp - p);
7155 : 2049629 : p = ++endp;
7156 : :
7157 : : /* p now points to just past the end of the spec function expression. */
7158 : :
7159 : 2049629 : funcval = eval_spec_function (func, args, soft_matched_part);
7160 : 2049629 : if (funcval != NULL && do_spec_1 (funcval, 0, NULL) < 0)
7161 : : p = NULL;
7162 : 2049629 : if (retval_nonnull)
7163 : 1616180 : *retval_nonnull = funcval != NULL;
7164 : :
7165 : 2049629 : free (func);
7166 : 2049629 : free (args);
7167 : :
7168 : 2049629 : processing_spec_function--;
7169 : :
7170 : 2049629 : return p;
7171 : : }
7172 : :
7173 : : /* Inline subroutine of handle_braces. Returns true if the current
7174 : : input suffix matches the atom bracketed by ATOM and END_ATOM. */
7175 : : static inline bool
7176 : 0 : input_suffix_matches (const char *atom, const char *end_atom)
7177 : : {
7178 : 0 : return (input_suffix
7179 : 0 : && !strncmp (input_suffix, atom, end_atom - atom)
7180 : 0 : && input_suffix[end_atom - atom] == '\0');
7181 : : }
7182 : :
7183 : : /* Subroutine of handle_braces. Returns true if the current
7184 : : input file's spec name matches the atom bracketed by ATOM and END_ATOM. */
7185 : : static bool
7186 : 0 : input_spec_matches (const char *atom, const char *end_atom)
7187 : : {
7188 : 0 : return (input_file_compiler
7189 : 0 : && input_file_compiler->suffix
7190 : 0 : && input_file_compiler->suffix[0] != '\0'
7191 : 0 : && !strncmp (input_file_compiler->suffix + 1, atom,
7192 : 0 : end_atom - atom)
7193 : 0 : && input_file_compiler->suffix[end_atom - atom + 1] == '\0');
7194 : : }
7195 : :
7196 : : /* Subroutine of handle_braces. Returns true if a switch
7197 : : matching the atom bracketed by ATOM and END_ATOM appeared on the
7198 : : command line. */
7199 : : static bool
7200 : 37955435 : switch_matches (const char *atom, const char *end_atom, int starred)
7201 : : {
7202 : 37955435 : int i;
7203 : 37955435 : int len = end_atom - atom;
7204 : 37955435 : int plen = starred ? len : -1;
7205 : :
7206 : 855416238 : for (i = 0; i < n_switches; i++)
7207 : 818814907 : if (!strncmp (switches[i].part1, atom, len)
7208 : 2285577 : && (starred || switches[i].part1[len] == '\0')
7209 : 820169631 : && check_live_switch (i, plen))
7210 : : return true;
7211 : :
7212 : : /* Check if a switch with separated form matching the atom.
7213 : : We check -D and -U switches. */
7214 : 817460804 : else if (switches[i].args != 0)
7215 : : {
7216 : 197312000 : if ((*switches[i].part1 == 'D' || *switches[i].part1 == 'U')
7217 : 8379720 : && *switches[i].part1 == atom[0])
7218 : : {
7219 : 1 : if (!strncmp (switches[i].args[0], &atom[1], len - 1)
7220 : 1 : && (starred || (switches[i].part1[1] == '\0'
7221 : 1 : && switches[i].args[0][len - 1] == '\0'))
7222 : 2 : && check_live_switch (i, (starred ? 1 : -1)))
7223 : : return true;
7224 : : }
7225 : : }
7226 : :
7227 : : return false;
7228 : : }
7229 : :
7230 : : /* Inline subroutine of handle_braces. Mark all of the switches which
7231 : : match ATOM (extends to END_ATOM; STARRED indicates whether there
7232 : : was a star after the atom) for later processing. */
7233 : : static inline void
7234 : 11069772 : mark_matching_switches (const char *atom, const char *end_atom, int starred)
7235 : : {
7236 : 11069772 : int i;
7237 : 11069772 : int len = end_atom - atom;
7238 : 11069772 : int plen = starred ? len : -1;
7239 : :
7240 : 253113865 : for (i = 0; i < n_switches; i++)
7241 : 242044093 : if (!strncmp (switches[i].part1, atom, len)
7242 : 6005072 : && (starred || switches[i].part1[len] == '\0')
7243 : 247834145 : && check_live_switch (i, plen))
7244 : 5741715 : switches[i].ordering = 1;
7245 : 11069772 : }
7246 : :
7247 : : /* Inline subroutine of handle_braces. Process all the currently
7248 : : marked switches through give_switch, and clear the marks. */
7249 : : static inline void
7250 : 9607731 : process_marked_switches (void)
7251 : : {
7252 : 9607731 : int i;
7253 : :
7254 : 219637054 : for (i = 0; i < n_switches; i++)
7255 : 210029323 : if (switches[i].ordering == 1)
7256 : : {
7257 : 5741715 : switches[i].ordering = 0;
7258 : 5741715 : give_switch (i, 0);
7259 : : }
7260 : 9607731 : }
7261 : :
7262 : : /* Handle a %{ ... } construct. P points just inside the leading {.
7263 : : Returns a pointer one past the end of the brace block, or 0
7264 : : if we call do_spec_1 and that returns -1. */
7265 : :
7266 : : static const char *
7267 : 39969167 : handle_braces (const char *p)
7268 : : {
7269 : 39969167 : const char *atom, *end_atom;
7270 : 39969167 : const char *d_atom = NULL, *d_end_atom = NULL;
7271 : 39969167 : char *esc_buf = NULL, *d_esc_buf = NULL;
7272 : 39969167 : int esc;
7273 : 39969167 : const char *orig = p;
7274 : :
7275 : 39969167 : bool a_is_suffix;
7276 : 39969167 : bool a_is_spectype;
7277 : 39969167 : bool a_is_starred;
7278 : 39969167 : bool a_is_negated;
7279 : 39969167 : bool a_matched;
7280 : :
7281 : 39969167 : bool a_must_be_last = false;
7282 : 39969167 : bool ordered_set = false;
7283 : 39969167 : bool disjunct_set = false;
7284 : 39969167 : bool disj_matched = false;
7285 : 39969167 : bool disj_starred = true;
7286 : 39969167 : bool n_way_choice = false;
7287 : 39969167 : bool n_way_matched = false;
7288 : :
7289 : : #define SKIP_WHITE() do { while (*p == ' ' || *p == '\t') p++; } while (0)
7290 : :
7291 : 53199624 : do
7292 : : {
7293 : 53199624 : if (a_must_be_last)
7294 : 0 : goto invalid;
7295 : :
7296 : : /* Scan one "atom" (S in the description above of %{}, possibly
7297 : : with '!', '.', '@', ',', or '*' modifiers). */
7298 : 53199624 : a_matched = false;
7299 : 53199624 : a_is_suffix = false;
7300 : 53199624 : a_is_starred = false;
7301 : 53199624 : a_is_negated = false;
7302 : 53199624 : a_is_spectype = false;
7303 : :
7304 : 60646722 : SKIP_WHITE ();
7305 : 53199624 : if (*p == '!')
7306 : 12713393 : p++, a_is_negated = true;
7307 : :
7308 : 53199624 : SKIP_WHITE ();
7309 : 53199624 : if (*p == '%' && p[1] == ':')
7310 : : {
7311 : 1616180 : atom = NULL;
7312 : 1616180 : end_atom = NULL;
7313 : 1616180 : p = handle_spec_function (p + 2, &a_matched, NULL);
7314 : : }
7315 : : else
7316 : : {
7317 : 51583444 : if (*p == '.')
7318 : 0 : p++, a_is_suffix = true;
7319 : 51583444 : else if (*p == ',')
7320 : 0 : p++, a_is_spectype = true;
7321 : :
7322 : 51583444 : atom = p;
7323 : 51583444 : esc = 0;
7324 : 51583444 : while (ISIDNUM (*p) || *p == '-' || *p == '+' || *p == '='
7325 : 386837344 : || *p == ',' || *p == '.' || *p == '@' || *p == '\\')
7326 : : {
7327 : 335253900 : if (*p == '\\')
7328 : : {
7329 : 0 : p++;
7330 : 0 : if (!*p)
7331 : 0 : fatal_error (input_location,
7332 : : "braced spec %qs ends in escape", orig);
7333 : 0 : esc++;
7334 : : }
7335 : 335253900 : p++;
7336 : : }
7337 : 51583444 : end_atom = p;
7338 : :
7339 : 51583444 : if (esc)
7340 : : {
7341 : 0 : const char *ap;
7342 : 0 : char *ep;
7343 : :
7344 : 0 : if (esc_buf && esc_buf != d_esc_buf)
7345 : 0 : free (esc_buf);
7346 : 0 : esc_buf = NULL;
7347 : 0 : ep = esc_buf = (char *) xmalloc (end_atom - atom - esc + 1);
7348 : 0 : for (ap = atom; ap != end_atom; ap++, ep++)
7349 : : {
7350 : 0 : if (*ap == '\\')
7351 : 0 : ap++;
7352 : 0 : *ep = *ap;
7353 : : }
7354 : 0 : *ep = '\0';
7355 : 0 : atom = esc_buf;
7356 : 0 : end_atom = ep;
7357 : : }
7358 : :
7359 : 51583444 : if (*p == '*')
7360 : 11663981 : p++, a_is_starred = 1;
7361 : : }
7362 : :
7363 : 53199624 : SKIP_WHITE ();
7364 : 53199624 : switch (*p)
7365 : : {
7366 : 11069772 : case '&': case '}':
7367 : : /* Substitute the switch(es) indicated by the current atom. */
7368 : 11069772 : ordered_set = true;
7369 : 11069772 : if (disjunct_set || n_way_choice || a_is_negated || a_is_suffix
7370 : 11069772 : || a_is_spectype || atom == end_atom)
7371 : 0 : goto invalid;
7372 : :
7373 : 11069772 : mark_matching_switches (atom, end_atom, a_is_starred);
7374 : :
7375 : 11069772 : if (*p == '}')
7376 : 9607731 : process_marked_switches ();
7377 : : break;
7378 : :
7379 : 42129852 : case '|': case ':':
7380 : : /* Substitute some text if the current atom appears as a switch
7381 : : or suffix. */
7382 : 42129852 : disjunct_set = true;
7383 : 42129852 : if (ordered_set)
7384 : 0 : goto invalid;
7385 : :
7386 : 42129852 : if (atom && atom == end_atom)
7387 : : {
7388 : 1750176 : if (!n_way_choice || disj_matched || *p == '|'
7389 : 1750176 : || a_is_negated || a_is_suffix || a_is_spectype
7390 : 1750176 : || a_is_starred)
7391 : 0 : goto invalid;
7392 : :
7393 : : /* An empty term may appear as the last choice of an
7394 : : N-way choice set; it means "otherwise". */
7395 : 1750176 : a_must_be_last = true;
7396 : 1750176 : disj_matched = !n_way_matched;
7397 : 1750176 : disj_starred = false;
7398 : : }
7399 : : else
7400 : : {
7401 : 40379676 : if ((a_is_suffix || a_is_spectype) && a_is_starred)
7402 : 0 : goto invalid;
7403 : :
7404 : 40379676 : if (!a_is_starred)
7405 : 34870308 : disj_starred = false;
7406 : :
7407 : : /* Don't bother testing this atom if we already have a
7408 : : match. */
7409 : 40379676 : if (!disj_matched && !n_way_matched)
7410 : : {
7411 : 39374693 : if (atom == NULL)
7412 : : /* a_matched is already set by handle_spec_function. */;
7413 : 37860909 : else if (a_is_suffix)
7414 : 0 : a_matched = input_suffix_matches (atom, end_atom);
7415 : 37860909 : else if (a_is_spectype)
7416 : 0 : a_matched = input_spec_matches (atom, end_atom);
7417 : : else
7418 : 37860909 : a_matched = switch_matches (atom, end_atom, a_is_starred);
7419 : :
7420 : 39374693 : if (a_matched != a_is_negated)
7421 : : {
7422 : 12587871 : disj_matched = true;
7423 : 12587871 : d_atom = atom;
7424 : 12587871 : d_end_atom = end_atom;
7425 : 12587871 : d_esc_buf = esc_buf;
7426 : : }
7427 : : }
7428 : : }
7429 : :
7430 : 42129852 : if (*p == ':')
7431 : : {
7432 : : /* Found the body, that is, the text to substitute if the
7433 : : current disjunction matches. */
7434 : 66656434 : p = process_brace_body (p + 1, d_atom, d_end_atom, disj_starred,
7435 : 33328217 : disj_matched && !n_way_matched);
7436 : 33328217 : if (p == 0)
7437 : 36492 : goto done;
7438 : :
7439 : : /* If we have an N-way choice, reset state for the next
7440 : : disjunction. */
7441 : 33291725 : if (*p == ';')
7442 : : {
7443 : 2966781 : n_way_choice = true;
7444 : 2966781 : n_way_matched |= disj_matched;
7445 : 2966781 : disj_matched = false;
7446 : 2966781 : disj_starred = true;
7447 : 2966781 : d_atom = d_end_atom = NULL;
7448 : : }
7449 : : }
7450 : : break;
7451 : :
7452 : 0 : default:
7453 : 0 : goto invalid;
7454 : : }
7455 : : }
7456 : 53163132 : while (*p++ != '}');
7457 : :
7458 : 39932675 : done:
7459 : 39969167 : if (d_esc_buf && d_esc_buf != esc_buf)
7460 : 0 : free (d_esc_buf);
7461 : 39969167 : if (esc_buf)
7462 : 0 : free (esc_buf);
7463 : :
7464 : 39969167 : return p;
7465 : :
7466 : 0 : invalid:
7467 : 0 : fatal_error (input_location, "braced spec %qs is invalid at %qc", orig, *p);
7468 : :
7469 : : #undef SKIP_WHITE
7470 : : }
7471 : :
7472 : : /* Subroutine of handle_braces. Scan and process a brace substitution body
7473 : : (X in the description of %{} syntax). P points one past the colon;
7474 : : ATOM and END_ATOM bracket the first atom which was found to be true
7475 : : (present) in the current disjunction; STARRED indicates whether all
7476 : : the atoms in the current disjunction were starred (for syntax validation);
7477 : : MATCHED indicates whether the disjunction matched or not, and therefore
7478 : : whether or not the body is to be processed through do_spec_1 or just
7479 : : skipped. Returns a pointer to the closing } or ;, or 0 if do_spec_1
7480 : : returns -1. */
7481 : :
7482 : : static const char *
7483 : 33328217 : process_brace_body (const char *p, const char *atom, const char *end_atom,
7484 : : int starred, int matched)
7485 : : {
7486 : 33328217 : const char *body, *end_body;
7487 : 33328217 : unsigned int nesting_level;
7488 : 33328217 : bool have_subst = false;
7489 : :
7490 : : /* Locate the closing } or ;, honoring nested braces.
7491 : : Trim trailing whitespace. */
7492 : 33328217 : body = p;
7493 : 33328217 : nesting_level = 1;
7494 : 11356169493 : for (;;)
7495 : : {
7496 : 5694748855 : if (*p == '{')
7497 : 168564778 : nesting_level++;
7498 : 5526184077 : else if (*p == '}')
7499 : : {
7500 : 198926214 : if (!--nesting_level)
7501 : : break;
7502 : : }
7503 : 5327257863 : else if (*p == ';' && nesting_level == 1)
7504 : : break;
7505 : 5324291082 : else if (*p == '%' && p[1] == '*' && nesting_level == 1)
7506 : : have_subst = true;
7507 : 5323514375 : else if (*p == '\0')
7508 : 0 : goto invalid;
7509 : 5661420638 : p++;
7510 : : }
7511 : :
7512 : : end_body = p;
7513 : 36067277 : while (end_body[-1] == ' ' || end_body[-1] == '\t')
7514 : 2739060 : end_body--;
7515 : :
7516 : 33328217 : if (have_subst && !starred)
7517 : 0 : goto invalid;
7518 : :
7519 : 33328217 : if (matched)
7520 : : {
7521 : : /* Copy the substitution body to permanent storage and execute it.
7522 : : If have_subst is false, this is a simple matter of running the
7523 : : body through do_spec_1... */
7524 : 13532002 : char *string = save_string (body, end_body - body);
7525 : 13532002 : if (!have_subst)
7526 : : {
7527 : 13525208 : if (do_spec_1 (string, 0, NULL) < 0)
7528 : : {
7529 : 36492 : free (string);
7530 : 36492 : return 0;
7531 : : }
7532 : : }
7533 : : else
7534 : : {
7535 : : /* ... but if have_subst is true, we have to process the
7536 : : body once for each matching switch, with %* set to the
7537 : : variant part of the switch. */
7538 : 6794 : unsigned int hard_match_len = end_atom - atom;
7539 : 6794 : int i;
7540 : :
7541 : 270653 : for (i = 0; i < n_switches; i++)
7542 : 263859 : if (!strncmp (switches[i].part1, atom, hard_match_len)
7543 : 263859 : && check_live_switch (i, hard_match_len))
7544 : : {
7545 : 6798 : if (do_spec_1 (string, 0,
7546 : : &switches[i].part1[hard_match_len]) < 0)
7547 : : {
7548 : 0 : free (string);
7549 : 0 : return 0;
7550 : : }
7551 : : /* Pass any arguments this switch has. */
7552 : 6798 : give_switch (i, 1);
7553 : 6798 : suffix_subst = NULL;
7554 : : }
7555 : : }
7556 : 13495510 : free (string);
7557 : : }
7558 : :
7559 : : return p;
7560 : :
7561 : 0 : invalid:
7562 : 0 : fatal_error (input_location, "braced spec body %qs is invalid", body);
7563 : : }
7564 : :
7565 : : /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
7566 : : on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
7567 : : spec, or -1 if either exact match or %* is used.
7568 : :
7569 : : A -O switch is obsoleted by a later -O switch. A -f, -g, -m, or -W switch
7570 : : whose value does not begin with "no-" is obsoleted by the same value
7571 : : with the "no-", similarly for a switch with the "no-" prefix. */
7572 : :
7573 : : static int
7574 : 7151575 : check_live_switch (int switchnum, int prefix_length)
7575 : : {
7576 : 7151575 : const char *name = switches[switchnum].part1;
7577 : 7151575 : int i;
7578 : :
7579 : : /* If we already processed this switch and determined if it was
7580 : : live or not, return our past determination. */
7581 : 7151575 : if (switches[switchnum].live_cond != 0)
7582 : 935676 : return ((switches[switchnum].live_cond & SWITCH_LIVE) != 0
7583 : 886736 : && (switches[switchnum].live_cond & SWITCH_FALSE) == 0
7584 : 1822412 : && (switches[switchnum].live_cond & SWITCH_IGNORE_PERMANENTLY)
7585 : 935676 : == 0);
7586 : :
7587 : : /* In the common case of {<at-most-one-letter>*}, a negating
7588 : : switch would always match, so ignore that case. We will just
7589 : : send the conflicting switches to the compiler phase. */
7590 : 6215899 : if (prefix_length >= 0 && prefix_length <= 1)
7591 : : return 1;
7592 : :
7593 : : /* Now search for duplicate in a manner that depends on the name. */
7594 : 870469 : switch (*name)
7595 : : {
7596 : 62 : case 'O':
7597 : 344 : for (i = switchnum + 1; i < n_switches; i++)
7598 : 287 : if (switches[i].part1[0] == 'O')
7599 : : {
7600 : 5 : switches[switchnum].validated = true;
7601 : 5 : switches[switchnum].live_cond = SWITCH_FALSE;
7602 : 5 : return 0;
7603 : : }
7604 : : break;
7605 : :
7606 : 280608 : case 'W': case 'f': case 'm': case 'g':
7607 : 280608 : if (startswith (name + 1, "no-"))
7608 : : {
7609 : : /* We have Xno-YYY, search for XYYY. */
7610 : 33978 : for (i = switchnum + 1; i < n_switches; i++)
7611 : 28613 : if (switches[i].part1[0] == name[0]
7612 : 5483 : && ! strcmp (&switches[i].part1[1], &name[4]))
7613 : : {
7614 : : /* --specs are validated with the validate_switches mechanism. */
7615 : 0 : if (switches[switchnum].known)
7616 : 0 : switches[switchnum].validated = true;
7617 : 0 : switches[switchnum].live_cond = SWITCH_FALSE;
7618 : 0 : return 0;
7619 : : }
7620 : : }
7621 : : else
7622 : : {
7623 : : /* We have XYYY, search for Xno-YYY. */
7624 : 2881545 : for (i = switchnum + 1; i < n_switches; i++)
7625 : 2606302 : if (switches[i].part1[0] == name[0]
7626 : 1576338 : && switches[i].part1[1] == 'n'
7627 : 197261 : && switches[i].part1[2] == 'o'
7628 : 197260 : && switches[i].part1[3] == '-'
7629 : 197230 : && !strcmp (&switches[i].part1[4], &name[1]))
7630 : : {
7631 : : /* --specs are validated with the validate_switches mechanism. */
7632 : 0 : if (switches[switchnum].known)
7633 : 0 : switches[switchnum].validated = true;
7634 : 0 : switches[switchnum].live_cond = SWITCH_FALSE;
7635 : 0 : return 0;
7636 : : }
7637 : : }
7638 : : break;
7639 : : }
7640 : :
7641 : : /* Otherwise the switch is live. */
7642 : 870464 : switches[switchnum].live_cond |= SWITCH_LIVE;
7643 : 870464 : return 1;
7644 : : }
7645 : :
7646 : : /* Pass a switch to the current accumulating command
7647 : : in the same form that we received it.
7648 : : SWITCHNUM identifies the switch; it is an index into
7649 : : the vector of switches gcc received, which is `switches'.
7650 : : This cannot fail since it never finishes a command line.
7651 : :
7652 : : If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */
7653 : :
7654 : : static void
7655 : 5748513 : give_switch (int switchnum, int omit_first_word)
7656 : : {
7657 : 5748513 : if ((switches[switchnum].live_cond & SWITCH_IGNORE) != 0)
7658 : : return;
7659 : :
7660 : 5748502 : if (!omit_first_word)
7661 : : {
7662 : 5741704 : do_spec_1 ("-", 0, NULL);
7663 : 5741704 : do_spec_1 (switches[switchnum].part1, 1, NULL);
7664 : : }
7665 : :
7666 : 5748502 : if (switches[switchnum].args != 0)
7667 : : {
7668 : : const char **p;
7669 : 2425560 : for (p = switches[switchnum].args; *p; p++)
7670 : : {
7671 : 1212780 : const char *arg = *p;
7672 : :
7673 : 1212780 : do_spec_1 (" ", 0, NULL);
7674 : 1212780 : if (suffix_subst)
7675 : : {
7676 : 5871 : unsigned length = strlen (arg);
7677 : 5871 : int dot = 0;
7678 : :
7679 : 11742 : while (length-- && !IS_DIR_SEPARATOR (arg[length]))
7680 : 11742 : if (arg[length] == '.')
7681 : : {
7682 : 5871 : (CONST_CAST (char *, arg))[length] = 0;
7683 : 5871 : dot = 1;
7684 : 5871 : break;
7685 : : }
7686 : 5871 : do_spec_1 (arg, 1, NULL);
7687 : 5871 : if (dot)
7688 : 5871 : (CONST_CAST (char *, arg))[length] = '.';
7689 : 5871 : do_spec_1 (suffix_subst, 1, NULL);
7690 : : }
7691 : : else
7692 : 1206909 : do_spec_1 (arg, 1, NULL);
7693 : : }
7694 : : }
7695 : :
7696 : 5748502 : do_spec_1 (" ", 0, NULL);
7697 : 5748502 : switches[switchnum].validated = true;
7698 : : }
7699 : :
7700 : : /* Print GCC configuration (e.g. version, thread model, target,
7701 : : configuration_arguments) to a given FILE. */
7702 : :
7703 : : static void
7704 : 1454 : print_configuration (FILE *file)
7705 : : {
7706 : 1454 : int n;
7707 : 1454 : const char *thrmod;
7708 : :
7709 : 1454 : fnotice (file, "Target: %s\n", spec_machine);
7710 : 1454 : fnotice (file, "Configured with: %s\n", configuration_arguments);
7711 : :
7712 : : #ifdef THREAD_MODEL_SPEC
7713 : : /* We could have defined THREAD_MODEL_SPEC to "%*" by default,
7714 : : but there's no point in doing all this processing just to get
7715 : : thread_model back. */
7716 : : obstack_init (&obstack);
7717 : : do_spec_1 (THREAD_MODEL_SPEC, 0, thread_model);
7718 : : obstack_1grow (&obstack, '\0');
7719 : : thrmod = XOBFINISH (&obstack, const char *);
7720 : : #else
7721 : 1454 : thrmod = thread_model;
7722 : : #endif
7723 : :
7724 : 1454 : fnotice (file, "Thread model: %s\n", thrmod);
7725 : 1454 : fnotice (file, "Supported LTO compression algorithms: zlib");
7726 : : #ifdef HAVE_ZSTD_H
7727 : 1454 : fnotice (file, " zstd");
7728 : : #endif
7729 : 1454 : fnotice (file, "\n");
7730 : :
7731 : : /* compiler_version is truncated at the first space when initialized
7732 : : from version string, so truncate version_string at the first space
7733 : : before comparing. */
7734 : 11632 : for (n = 0; version_string[n]; n++)
7735 : 10178 : if (version_string[n] == ' ')
7736 : : break;
7737 : :
7738 : 1454 : if (! strncmp (version_string, compiler_version, n)
7739 : 1454 : && compiler_version[n] == 0)
7740 : 1454 : fnotice (file, "gcc version %s %s\n", version_string,
7741 : : pkgversion_string);
7742 : : else
7743 : 0 : fnotice (file, "gcc driver version %s %sexecuting gcc version %s\n",
7744 : : version_string, pkgversion_string, compiler_version);
7745 : :
7746 : 1454 : }
7747 : :
7748 : : #define RETRY_ICE_ATTEMPTS 3
7749 : :
7750 : : /* Returns true if FILE1 and FILE2 contain equivalent data, 0 otherwise.
7751 : : If lines start with 0x followed by 1-16 lowercase hexadecimal digits
7752 : : followed by a space, ignore anything before that space. These are
7753 : : typically function addresses from libbacktrace and those can differ
7754 : : due to ASLR. */
7755 : :
7756 : : static bool
7757 : 0 : files_equal_p (char *file1, char *file2)
7758 : : {
7759 : 0 : FILE *f1 = fopen (file1, "rb");
7760 : 0 : FILE *f2 = fopen (file2, "rb");
7761 : 0 : char line1[256], line2[256];
7762 : :
7763 : 0 : bool line_start = true;
7764 : 0 : while (fgets (line1, sizeof (line1), f1))
7765 : : {
7766 : 0 : if (!fgets (line2, sizeof (line2), f2))
7767 : 0 : goto error;
7768 : 0 : char *p1 = line1, *p2 = line2;
7769 : 0 : if (line_start
7770 : 0 : && line1[0] == '0'
7771 : 0 : && line1[1] == 'x'
7772 : 0 : && line2[0] == '0'
7773 : 0 : && line2[1] == 'x')
7774 : : {
7775 : : int i, j;
7776 : 0 : for (i = 0; i < 16; ++i)
7777 : 0 : if (!ISXDIGIT (line1[2 + i]) || ISUPPER (line1[2 + i]))
7778 : : break;
7779 : 0 : for (j = 0; j < 16; ++j)
7780 : 0 : if (!ISXDIGIT (line2[2 + j]) || ISUPPER (line2[2 + j]))
7781 : : break;
7782 : 0 : if (i && line1[2 + i] == ' ' && j && line2[2 + j] == ' ')
7783 : : {
7784 : 0 : p1 = line1 + i + 3;
7785 : 0 : p2 = line2 + j + 3;
7786 : : }
7787 : : }
7788 : 0 : if (strcmp (p1, p2) != 0)
7789 : 0 : goto error;
7790 : 0 : line_start = strchr (line1, '\n') != NULL;
7791 : : }
7792 : 0 : if (fgets (line2, sizeof (line2), f2))
7793 : 0 : goto error;
7794 : :
7795 : 0 : fclose (f1);
7796 : 0 : fclose (f2);
7797 : 0 : return 1;
7798 : :
7799 : 0 : error:
7800 : 0 : fclose (f1);
7801 : 0 : fclose (f2);
7802 : 0 : return 0;
7803 : : }
7804 : :
7805 : : /* Check that compiler's output doesn't differ across runs.
7806 : : TEMP_STDOUT_FILES and TEMP_STDERR_FILES are arrays of files, containing
7807 : : stdout and stderr for each compiler run. Return true if all of
7808 : : TEMP_STDOUT_FILES and TEMP_STDERR_FILES are equivalent. */
7809 : :
7810 : : static bool
7811 : 0 : check_repro (char **temp_stdout_files, char **temp_stderr_files)
7812 : : {
7813 : 0 : int i;
7814 : 0 : for (i = 0; i < RETRY_ICE_ATTEMPTS - 2; ++i)
7815 : : {
7816 : 0 : if (!files_equal_p (temp_stdout_files[i], temp_stdout_files[i + 1])
7817 : 0 : || !files_equal_p (temp_stderr_files[i], temp_stderr_files[i + 1]))
7818 : : {
7819 : 0 : fnotice (stderr, "The bug is not reproducible, so it is"
7820 : : " likely a hardware or OS problem.\n");
7821 : 0 : break;
7822 : : }
7823 : : }
7824 : 0 : return i == RETRY_ICE_ATTEMPTS - 2;
7825 : : }
7826 : :
7827 : : enum attempt_status {
7828 : : ATTEMPT_STATUS_FAIL_TO_RUN,
7829 : : ATTEMPT_STATUS_SUCCESS,
7830 : : ATTEMPT_STATUS_ICE
7831 : : };
7832 : :
7833 : :
7834 : : /* Run compiler with arguments NEW_ARGV to reproduce the ICE, storing stdout
7835 : : to OUT_TEMP and stderr to ERR_TEMP. If APPEND is TRUE, append to OUT_TEMP
7836 : : and ERR_TEMP instead of truncating. If EMIT_SYSTEM_INFO is TRUE, also write
7837 : : GCC configuration into to ERR_TEMP. Return ATTEMPT_STATUS_FAIL_TO_RUN if
7838 : : compiler failed to run, ATTEMPT_STATUS_ICE if compiled ICE-ed and
7839 : : ATTEMPT_STATUS_SUCCESS otherwise. */
7840 : :
7841 : : static enum attempt_status
7842 : 0 : run_attempt (const char **new_argv, const char *out_temp,
7843 : : const char *err_temp, int emit_system_info, int append)
7844 : : {
7845 : :
7846 : 0 : if (emit_system_info)
7847 : : {
7848 : 0 : FILE *file_out = fopen (err_temp, "a");
7849 : 0 : print_configuration (file_out);
7850 : 0 : fputs ("\n", file_out);
7851 : 0 : fclose (file_out);
7852 : : }
7853 : :
7854 : 0 : int exit_status;
7855 : 0 : const char *errmsg;
7856 : 0 : struct pex_obj *pex;
7857 : 0 : int err;
7858 : 0 : int pex_flags = PEX_USE_PIPES | PEX_LAST;
7859 : 0 : enum attempt_status status = ATTEMPT_STATUS_FAIL_TO_RUN;
7860 : :
7861 : 0 : if (append)
7862 : 0 : pex_flags |= PEX_STDOUT_APPEND | PEX_STDERR_APPEND;
7863 : :
7864 : 0 : pex = pex_init (PEX_USE_PIPES, new_argv[0], NULL);
7865 : 0 : if (!pex)
7866 : : fatal_error (input_location, "%<pex_init%> failed: %m");
7867 : :
7868 : 0 : errmsg = pex_run (pex, pex_flags, new_argv[0],
7869 : 0 : CONST_CAST2 (char *const *, const char **, &new_argv[1]),
7870 : : out_temp, err_temp, &err);
7871 : 0 : if (errmsg != NULL)
7872 : : {
7873 : 0 : errno = err;
7874 : 0 : fatal_error (input_location,
7875 : : err ? G_ ("cannot execute %qs: %s: %m")
7876 : : : G_ ("cannot execute %qs: %s"),
7877 : : new_argv[0], errmsg);
7878 : : }
7879 : :
7880 : 0 : if (!pex_get_status (pex, 1, &exit_status))
7881 : 0 : goto out;
7882 : :
7883 : 0 : switch (WEXITSTATUS (exit_status))
7884 : : {
7885 : : case ICE_EXIT_CODE:
7886 : 0 : status = ATTEMPT_STATUS_ICE;
7887 : : break;
7888 : :
7889 : 0 : case SUCCESS_EXIT_CODE:
7890 : 0 : status = ATTEMPT_STATUS_SUCCESS;
7891 : 0 : break;
7892 : :
7893 : 0 : default:
7894 : 0 : ;
7895 : : }
7896 : :
7897 : 0 : out:
7898 : 0 : pex_free (pex);
7899 : 0 : return status;
7900 : : }
7901 : :
7902 : : /* This routine reads lines from IN file, adds C++ style comments
7903 : : at the begining of each line and writes result into OUT. */
7904 : :
7905 : : static void
7906 : 0 : insert_comments (const char *file_in, const char *file_out)
7907 : : {
7908 : 0 : FILE *in = fopen (file_in, "rb");
7909 : 0 : FILE *out = fopen (file_out, "wb");
7910 : 0 : char line[256];
7911 : :
7912 : 0 : bool add_comment = true;
7913 : 0 : while (fgets (line, sizeof (line), in))
7914 : : {
7915 : 0 : if (add_comment)
7916 : 0 : fputs ("// ", out);
7917 : 0 : fputs (line, out);
7918 : 0 : add_comment = strchr (line, '\n') != NULL;
7919 : : }
7920 : :
7921 : 0 : fclose (in);
7922 : 0 : fclose (out);
7923 : 0 : }
7924 : :
7925 : : /* This routine adds preprocessed source code into the given ERR_FILE.
7926 : : To do this, it adds "-E" to NEW_ARGV and execute RUN_ATTEMPT routine to
7927 : : add information in report file. RUN_ATTEMPT should return
7928 : : ATTEMPT_STATUS_SUCCESS, in other case we cannot generate the report. */
7929 : :
7930 : : static void
7931 : 0 : do_report_bug (const char **new_argv, const int nargs,
7932 : : char **out_file, char **err_file)
7933 : : {
7934 : 0 : int i, status;
7935 : 0 : int fd = open (*out_file, O_RDWR | O_APPEND);
7936 : 0 : if (fd < 0)
7937 : : return;
7938 : 0 : write (fd, "\n//", 3);
7939 : 0 : for (i = 0; i < nargs; i++)
7940 : : {
7941 : 0 : write (fd, " ", 1);
7942 : 0 : write (fd, new_argv[i], strlen (new_argv[i]));
7943 : : }
7944 : 0 : write (fd, "\n\n", 2);
7945 : 0 : close (fd);
7946 : 0 : new_argv[nargs] = "-E";
7947 : 0 : new_argv[nargs + 1] = NULL;
7948 : :
7949 : 0 : status = run_attempt (new_argv, *out_file, *err_file, 0, 1);
7950 : :
7951 : 0 : if (status == ATTEMPT_STATUS_SUCCESS)
7952 : : {
7953 : 0 : fnotice (stderr, "Preprocessed source stored into %s file,"
7954 : : " please attach this to your bugreport.\n", *out_file);
7955 : : /* Make sure it is not deleted. */
7956 : 0 : free (*out_file);
7957 : 0 : *out_file = NULL;
7958 : : }
7959 : : }
7960 : :
7961 : : /* Try to reproduce ICE. If bug is reproducible, generate report .err file
7962 : : containing GCC configuration, backtrace, compiler's command line options
7963 : : and preprocessed source code. */
7964 : :
7965 : : static void
7966 : 0 : try_generate_repro (const char **argv)
7967 : : {
7968 : 0 : int i, nargs, out_arg = -1, quiet = 0, attempt;
7969 : 0 : const char **new_argv;
7970 : 0 : char *temp_files[RETRY_ICE_ATTEMPTS * 2];
7971 : 0 : char **temp_stdout_files = &temp_files[0];
7972 : 0 : char **temp_stderr_files = &temp_files[RETRY_ICE_ATTEMPTS];
7973 : :
7974 : 0 : if (gcc_input_filename == NULL || ! strcmp (gcc_input_filename, "-"))
7975 : 0 : return;
7976 : :
7977 : 0 : for (nargs = 0; argv[nargs] != NULL; ++nargs)
7978 : : /* Only retry compiler ICEs, not preprocessor ones. */
7979 : 0 : if (! strcmp (argv[nargs], "-E"))
7980 : : return;
7981 : 0 : else if (argv[nargs][0] == '-' && argv[nargs][1] == 'o')
7982 : : {
7983 : 0 : if (out_arg == -1)
7984 : : out_arg = nargs;
7985 : : else
7986 : : return;
7987 : : }
7988 : : /* If the compiler is going to output any time information,
7989 : : it might varry between invocations. */
7990 : 0 : else if (! strcmp (argv[nargs], "-quiet"))
7991 : : quiet = 1;
7992 : 0 : else if (! strcmp (argv[nargs], "-ftime-report"))
7993 : : return;
7994 : :
7995 : 0 : if (out_arg == -1 || !quiet)
7996 : : return;
7997 : :
7998 : 0 : memset (temp_files, '\0', sizeof (temp_files));
7999 : 0 : new_argv = XALLOCAVEC (const char *, nargs + 4);
8000 : 0 : memcpy (new_argv, argv, (nargs + 1) * sizeof (const char *));
8001 : 0 : new_argv[nargs++] = "-frandom-seed=0";
8002 : 0 : new_argv[nargs++] = "-fdump-noaddr";
8003 : 0 : new_argv[nargs] = NULL;
8004 : 0 : if (new_argv[out_arg][2] == '\0')
8005 : 0 : new_argv[out_arg + 1] = "-";
8006 : : else
8007 : 0 : new_argv[out_arg] = "-o-";
8008 : :
8009 : : #ifdef HOST_HAS_PERSONALITY_ADDR_NO_RANDOMIZE
8010 : 0 : personality (personality (0xffffffffU) | ADDR_NO_RANDOMIZE);
8011 : : #endif
8012 : :
8013 : 0 : int status;
8014 : 0 : for (attempt = 0; attempt < RETRY_ICE_ATTEMPTS; ++attempt)
8015 : : {
8016 : 0 : int emit_system_info = 0;
8017 : 0 : int append = 0;
8018 : 0 : temp_stdout_files[attempt] = make_temp_file (".out");
8019 : 0 : temp_stderr_files[attempt] = make_temp_file (".err");
8020 : :
8021 : 0 : if (attempt == RETRY_ICE_ATTEMPTS - 1)
8022 : : {
8023 : 0 : append = 1;
8024 : 0 : emit_system_info = 1;
8025 : : }
8026 : :
8027 : 0 : status = run_attempt (new_argv, temp_stdout_files[attempt],
8028 : : temp_stderr_files[attempt], emit_system_info,
8029 : : append);
8030 : :
8031 : 0 : if (status != ATTEMPT_STATUS_ICE)
8032 : : {
8033 : 0 : fnotice (stderr, "The bug is not reproducible, so it is"
8034 : : " likely a hardware or OS problem.\n");
8035 : 0 : goto out;
8036 : : }
8037 : : }
8038 : :
8039 : 0 : if (!check_repro (temp_stdout_files, temp_stderr_files))
8040 : 0 : goto out;
8041 : :
8042 : 0 : {
8043 : : /* Insert commented out backtrace into report file. */
8044 : 0 : char **stderr_commented = &temp_stdout_files[RETRY_ICE_ATTEMPTS - 1];
8045 : 0 : insert_comments (temp_stderr_files[RETRY_ICE_ATTEMPTS - 1],
8046 : : *stderr_commented);
8047 : :
8048 : : /* In final attempt we append compiler options and preprocesssed code to last
8049 : : generated .out file with configuration and backtrace. */
8050 : 0 : char **err = &temp_stderr_files[RETRY_ICE_ATTEMPTS - 1];
8051 : 0 : do_report_bug (new_argv, nargs, stderr_commented, err);
8052 : : }
8053 : :
8054 : : out:
8055 : 0 : for (i = 0; i < RETRY_ICE_ATTEMPTS * 2; i++)
8056 : 0 : if (temp_files[i])
8057 : : {
8058 : 0 : unlink (temp_stdout_files[i]);
8059 : 0 : free (temp_stdout_files[i]);
8060 : : }
8061 : : }
8062 : :
8063 : : /* Search for a file named NAME trying various prefixes including the
8064 : : user's -B prefix and some standard ones.
8065 : : Return the absolute file name found. If nothing is found, return NAME. */
8066 : :
8067 : : static const char *
8068 : 538409 : find_file (const char *name)
8069 : : {
8070 : 538409 : char *newname = find_a_file (&startfile_prefixes, name, R_OK, true);
8071 : 538409 : return newname ? newname : name;
8072 : : }
8073 : :
8074 : : /* Determine whether a directory exists. */
8075 : :
8076 : : static int
8077 : 10332640 : is_directory (const char *path1)
8078 : : {
8079 : 10332640 : int len1;
8080 : 10332640 : char *path;
8081 : 10332640 : char *cp;
8082 : 10332640 : struct stat st;
8083 : :
8084 : : /* Ensure the string ends with "/.". The resulting path will be a
8085 : : directory even if the given path is a symbolic link. */
8086 : 10332640 : len1 = strlen (path1);
8087 : 10332640 : path = (char *) alloca (3 + len1);
8088 : 10332640 : memcpy (path, path1, len1);
8089 : 10332640 : cp = path + len1;
8090 : 10332640 : if (!IS_DIR_SEPARATOR (cp[-1]))
8091 : 1481265 : *cp++ = DIR_SEPARATOR;
8092 : 10332640 : *cp++ = '.';
8093 : 10332640 : *cp = '\0';
8094 : :
8095 : 10332640 : return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
8096 : : }
8097 : :
8098 : : /* Set up the various global variables to indicate that we're processing
8099 : : the input file named FILENAME. */
8100 : :
8101 : : void
8102 : 825528 : set_input (const char *filename)
8103 : : {
8104 : 825528 : const char *p;
8105 : :
8106 : 825528 : gcc_input_filename = filename;
8107 : 825528 : input_filename_length = strlen (gcc_input_filename);
8108 : 825528 : input_basename = lbasename (gcc_input_filename);
8109 : :
8110 : : /* Find a suffix starting with the last period,
8111 : : and set basename_length to exclude that suffix. */
8112 : 825528 : basename_length = strlen (input_basename);
8113 : 825528 : suffixed_basename_length = basename_length;
8114 : 825528 : p = input_basename + basename_length;
8115 : 3623900 : while (p != input_basename && *p != '.')
8116 : 2798372 : --p;
8117 : 825528 : if (*p == '.' && p != input_basename)
8118 : : {
8119 : 592332 : basename_length = p - input_basename;
8120 : 592332 : input_suffix = p + 1;
8121 : : }
8122 : : else
8123 : 233196 : input_suffix = "";
8124 : :
8125 : : /* If a spec for 'g', 'u', or 'U' is seen with -save-temps then
8126 : : we will need to do a stat on the gcc_input_filename. The
8127 : : INPUT_STAT_SET signals that the stat is needed. */
8128 : 825528 : input_stat_set = 0;
8129 : 825528 : }
8130 : :
8131 : : /* On fatal signals, delete all the temporary files. */
8132 : :
8133 : : static void
8134 : 0 : fatal_signal (int signum)
8135 : : {
8136 : 0 : signal (signum, SIG_DFL);
8137 : 0 : delete_failure_queue ();
8138 : 0 : delete_temp_files ();
8139 : : /* Get the same signal again, this time not handled,
8140 : : so its normal effect occurs. */
8141 : 0 : kill (getpid (), signum);
8142 : 0 : }
8143 : :
8144 : : /* Compare the contents of the two files named CMPFILE[0] and
8145 : : CMPFILE[1]. Return zero if they're identical, nonzero
8146 : : otherwise. */
8147 : :
8148 : : static int
8149 : 616 : compare_files (char *cmpfile[])
8150 : : {
8151 : 616 : int ret = 0;
8152 : 616 : FILE *temp[2] = { NULL, NULL };
8153 : 616 : int i;
8154 : :
8155 : : #if HAVE_MMAP_FILE
8156 : 616 : {
8157 : 616 : size_t length[2];
8158 : 616 : void *map[2] = { NULL, NULL };
8159 : :
8160 : 1848 : for (i = 0; i < 2; i++)
8161 : : {
8162 : 1232 : struct stat st;
8163 : :
8164 : 1232 : if (stat (cmpfile[i], &st) < 0 || !S_ISREG (st.st_mode))
8165 : : {
8166 : 0 : error ("%s: could not determine length of compare-debug file %s",
8167 : : gcc_input_filename, cmpfile[i]);
8168 : 0 : ret = 1;
8169 : 0 : break;
8170 : : }
8171 : :
8172 : 1232 : length[i] = st.st_size;
8173 : : }
8174 : :
8175 : 616 : if (!ret && length[0] != length[1])
8176 : : {
8177 : 17 : error ("%s: %<-fcompare-debug%> failure (length)", gcc_input_filename);
8178 : 17 : ret = 1;
8179 : : }
8180 : :
8181 : 17 : if (!ret)
8182 : 1735 : for (i = 0; i < 2; i++)
8183 : : {
8184 : 1167 : int fd = open (cmpfile[i], O_RDONLY);
8185 : 1167 : if (fd < 0)
8186 : : {
8187 : 0 : error ("%s: could not open compare-debug file %s",
8188 : : gcc_input_filename, cmpfile[i]);
8189 : 0 : ret = 1;
8190 : 0 : break;
8191 : : }
8192 : :
8193 : 1167 : map[i] = mmap (NULL, length[i], PROT_READ, MAP_PRIVATE, fd, 0);
8194 : 1167 : close (fd);
8195 : :
8196 : 1167 : if (map[i] == (void *) MAP_FAILED)
8197 : : {
8198 : : ret = -1;
8199 : : break;
8200 : : }
8201 : : }
8202 : :
8203 : 599 : if (!ret)
8204 : : {
8205 : 568 : if (memcmp (map[0], map[1], length[0]) != 0)
8206 : : {
8207 : 0 : error ("%s: %<-fcompare-debug%> failure", gcc_input_filename);
8208 : 0 : ret = 1;
8209 : : }
8210 : : }
8211 : :
8212 : 1848 : for (i = 0; i < 2; i++)
8213 : 1232 : if (map[i])
8214 : 1167 : munmap ((caddr_t) map[i], length[i]);
8215 : :
8216 : 616 : if (ret >= 0)
8217 : 585 : return ret;
8218 : :
8219 : 31 : ret = 0;
8220 : : }
8221 : : #endif
8222 : :
8223 : 93 : for (i = 0; i < 2; i++)
8224 : : {
8225 : 62 : temp[i] = fopen (cmpfile[i], "r");
8226 : 62 : if (!temp[i])
8227 : : {
8228 : 0 : error ("%s: could not open compare-debug file %s",
8229 : : gcc_input_filename, cmpfile[i]);
8230 : 0 : ret = 1;
8231 : 0 : break;
8232 : : }
8233 : : }
8234 : :
8235 : 31 : if (!ret && temp[0] && temp[1])
8236 : 31 : for (;;)
8237 : : {
8238 : 31 : int c0, c1;
8239 : 31 : c0 = fgetc (temp[0]);
8240 : 31 : c1 = fgetc (temp[1]);
8241 : :
8242 : 31 : if (c0 != c1)
8243 : : {
8244 : 0 : error ("%s: %<-fcompare-debug%> failure",
8245 : : gcc_input_filename);
8246 : 0 : ret = 1;
8247 : 0 : break;
8248 : : }
8249 : :
8250 : 31 : if (c0 == EOF)
8251 : : break;
8252 : : }
8253 : :
8254 : 93 : for (i = 1; i >= 0; i--)
8255 : : {
8256 : 62 : if (temp[i])
8257 : 62 : fclose (temp[i]);
8258 : : }
8259 : :
8260 : : return ret;
8261 : : }
8262 : :
8263 : 296263 : driver::driver (bool can_finalize, bool debug) :
8264 : 296263 : explicit_link_files (NULL),
8265 : 296263 : decoded_options (NULL)
8266 : : {
8267 : 296263 : env.init (can_finalize, debug);
8268 : 296263 : }
8269 : :
8270 : 295781 : driver::~driver ()
8271 : : {
8272 : 295781 : XDELETEVEC (explicit_link_files);
8273 : 295781 : XDELETEVEC (decoded_options);
8274 : 295781 : }
8275 : :
8276 : : /* driver::main is implemented as a series of driver:: method calls. */
8277 : :
8278 : : int
8279 : 296263 : driver::main (int argc, char **argv)
8280 : : {
8281 : 296263 : bool early_exit;
8282 : :
8283 : 296263 : set_progname (argv[0]);
8284 : 296263 : expand_at_files (&argc, &argv);
8285 : 296263 : decode_argv (argc, const_cast <const char **> (argv));
8286 : 296263 : global_initializations ();
8287 : 296263 : build_multilib_strings ();
8288 : 296263 : set_up_specs ();
8289 : 295976 : putenv_COLLECT_AS_OPTIONS (assembler_options);
8290 : 295976 : putenv_COLLECT_GCC (argv[0]);
8291 : 295976 : maybe_putenv_COLLECT_LTO_WRAPPER ();
8292 : 295976 : maybe_putenv_OFFLOAD_TARGETS ();
8293 : 295976 : handle_unrecognized_options ();
8294 : :
8295 : 295976 : if (completion)
8296 : : {
8297 : 5 : m_option_proposer.suggest_completion (completion);
8298 : 5 : return 0;
8299 : : }
8300 : :
8301 : 295971 : if (!maybe_print_and_exit ())
8302 : : return 0;
8303 : :
8304 : 281560 : early_exit = prepare_infiles ();
8305 : 281366 : if (early_exit)
8306 : 418 : return get_exit_code ();
8307 : :
8308 : 280948 : do_spec_on_infiles ();
8309 : 280948 : maybe_run_linker (argv[0]);
8310 : 280948 : final_actions ();
8311 : 280948 : return get_exit_code ();
8312 : : }
8313 : :
8314 : : /* Locate the final component of argv[0] after any leading path, and set
8315 : : the program name accordingly. */
8316 : :
8317 : : void
8318 : 296263 : driver::set_progname (const char *argv0) const
8319 : : {
8320 : 296263 : const char *p = argv0 + strlen (argv0);
8321 : 1635863 : while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
8322 : 1339600 : --p;
8323 : 296263 : progname = p;
8324 : :
8325 : 296263 : xmalloc_set_program_name (progname);
8326 : 296263 : }
8327 : :
8328 : : /* Expand any @ files within the command-line args,
8329 : : setting at_file_supplied if any were expanded. */
8330 : :
8331 : : void
8332 : 296263 : driver::expand_at_files (int *argc, char ***argv) const
8333 : : {
8334 : 296263 : char **old_argv = *argv;
8335 : :
8336 : 296263 : expandargv (argc, argv);
8337 : :
8338 : : /* Determine if any expansions were made. */
8339 : 296263 : if (*argv != old_argv)
8340 : 12982 : at_file_supplied = true;
8341 : 296263 : }
8342 : :
8343 : : /* Decode the command-line arguments from argc/argv into the
8344 : : decoded_options array. */
8345 : :
8346 : : void
8347 : 296263 : driver::decode_argv (int argc, const char **argv)
8348 : : {
8349 : 296263 : init_opts_obstack ();
8350 : 296263 : init_options_struct (&global_options, &global_options_set);
8351 : :
8352 : 296263 : decode_cmdline_options_to_array (argc, argv,
8353 : : CL_DRIVER,
8354 : : &decoded_options, &decoded_options_count);
8355 : 296263 : }
8356 : :
8357 : : /* Perform various initializations and setup. */
8358 : :
8359 : : void
8360 : 296263 : driver::global_initializations ()
8361 : : {
8362 : : /* Unlock the stdio streams. */
8363 : 296263 : unlock_std_streams ();
8364 : :
8365 : 296263 : gcc_init_libintl ();
8366 : :
8367 : 296263 : diagnostic_initialize (global_dc, 0);
8368 : 296263 : diagnostic_color_init (global_dc);
8369 : 296263 : diagnostic_urls_init (global_dc);
8370 : 296263 : global_dc->push_owned_urlifier (make_gcc_urlifier (0));
8371 : :
8372 : : #ifdef GCC_DRIVER_HOST_INITIALIZATION
8373 : : /* Perform host dependent initialization when needed. */
8374 : : GCC_DRIVER_HOST_INITIALIZATION;
8375 : : #endif
8376 : :
8377 : 296263 : if (atexit (delete_temp_files) != 0)
8378 : 0 : fatal_error (input_location, "atexit failed");
8379 : :
8380 : 296263 : if (signal (SIGINT, SIG_IGN) != SIG_IGN)
8381 : 296112 : signal (SIGINT, fatal_signal);
8382 : : #ifdef SIGHUP
8383 : 296263 : if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
8384 : 21097 : signal (SIGHUP, fatal_signal);
8385 : : #endif
8386 : 296263 : if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
8387 : 296263 : signal (SIGTERM, fatal_signal);
8388 : : #ifdef SIGPIPE
8389 : 296263 : if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
8390 : 296263 : signal (SIGPIPE, fatal_signal);
8391 : : #endif
8392 : : #ifdef SIGCHLD
8393 : : /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
8394 : : receive the signal. A different setting is inheritable */
8395 : 296263 : signal (SIGCHLD, SIG_DFL);
8396 : : #endif
8397 : :
8398 : : /* Parsing and gimplification sometimes need quite large stack.
8399 : : Increase stack size limits if possible. */
8400 : 296263 : stack_limit_increase (64 * 1024 * 1024);
8401 : :
8402 : : /* Allocate the argument vector. */
8403 : 296263 : alloc_args ();
8404 : :
8405 : 296263 : obstack_init (&obstack);
8406 : 296263 : }
8407 : :
8408 : : /* Build multilib_select, et. al from the separate lines that make up each
8409 : : multilib selection. */
8410 : :
8411 : : void
8412 : 296263 : driver::build_multilib_strings () const
8413 : : {
8414 : 296263 : {
8415 : 296263 : const char *p;
8416 : 296263 : const char *const *q = multilib_raw;
8417 : 296263 : int need_space;
8418 : :
8419 : 296263 : obstack_init (&multilib_obstack);
8420 : 296263 : while ((p = *q++) != (char *) 0)
8421 : 1185052 : obstack_grow (&multilib_obstack, p, strlen (p));
8422 : :
8423 : 296263 : obstack_1grow (&multilib_obstack, 0);
8424 : 296263 : multilib_select = XOBFINISH (&multilib_obstack, const char *);
8425 : :
8426 : 296263 : q = multilib_matches_raw;
8427 : 296263 : while ((p = *q++) != (char *) 0)
8428 : 888789 : obstack_grow (&multilib_obstack, p, strlen (p));
8429 : :
8430 : 296263 : obstack_1grow (&multilib_obstack, 0);
8431 : 296263 : multilib_matches = XOBFINISH (&multilib_obstack, const char *);
8432 : :
8433 : 296263 : q = multilib_exclusions_raw;
8434 : 296263 : while ((p = *q++) != (char *) 0)
8435 : 296263 : obstack_grow (&multilib_obstack, p, strlen (p));
8436 : :
8437 : 296263 : obstack_1grow (&multilib_obstack, 0);
8438 : 296263 : multilib_exclusions = XOBFINISH (&multilib_obstack, const char *);
8439 : :
8440 : 296263 : q = multilib_reuse_raw;
8441 : 296263 : while ((p = *q++) != (char *) 0)
8442 : 296263 : obstack_grow (&multilib_obstack, p, strlen (p));
8443 : :
8444 : 296263 : obstack_1grow (&multilib_obstack, 0);
8445 : 296263 : multilib_reuse = XOBFINISH (&multilib_obstack, const char *);
8446 : :
8447 : 296263 : need_space = false;
8448 : 592526 : for (size_t i = 0; i < ARRAY_SIZE (multilib_defaults_raw); i++)
8449 : : {
8450 : 296263 : if (need_space)
8451 : 0 : obstack_1grow (&multilib_obstack, ' ');
8452 : 296263 : obstack_grow (&multilib_obstack,
8453 : : multilib_defaults_raw[i],
8454 : : strlen (multilib_defaults_raw[i]));
8455 : 296263 : need_space = true;
8456 : : }
8457 : :
8458 : 296263 : obstack_1grow (&multilib_obstack, 0);
8459 : 296263 : multilib_defaults = XOBFINISH (&multilib_obstack, const char *);
8460 : : }
8461 : 296263 : }
8462 : :
8463 : : /* Set up the spec-handling machinery. */
8464 : :
8465 : : void
8466 : 296263 : driver::set_up_specs () const
8467 : : {
8468 : 296263 : const char *spec_machine_suffix;
8469 : 296263 : char *specs_file;
8470 : 296263 : size_t i;
8471 : :
8472 : : #ifdef INIT_ENVIRONMENT
8473 : : /* Set up any other necessary machine specific environment variables. */
8474 : : xputenv (INIT_ENVIRONMENT);
8475 : : #endif
8476 : :
8477 : : /* Make a table of what switches there are (switches, n_switches).
8478 : : Make a table of specified input files (infiles, n_infiles).
8479 : : Decode switches that are handled locally. */
8480 : :
8481 : 296263 : process_command (decoded_options_count, decoded_options);
8482 : :
8483 : : /* Initialize the vector of specs to just the default.
8484 : : This means one element containing 0s, as a terminator. */
8485 : :
8486 : 295977 : compilers = XNEWVAR (struct compiler, sizeof default_compilers);
8487 : 295977 : memcpy (compilers, default_compilers, sizeof default_compilers);
8488 : 295977 : n_compilers = n_default_compilers;
8489 : :
8490 : : /* Read specs from a file if there is one. */
8491 : :
8492 : 295977 : machine_suffix = concat (spec_host_machine, dir_separator_str, spec_version,
8493 : : accel_dir_suffix, dir_separator_str, NULL);
8494 : 295977 : just_machine_suffix = concat (spec_machine, dir_separator_str, NULL);
8495 : :
8496 : 295977 : specs_file = find_a_file (&startfile_prefixes, "specs", R_OK, true);
8497 : : /* Read the specs file unless it is a default one. */
8498 : 295977 : if (specs_file != 0 && strcmp (specs_file, "specs"))
8499 : 294886 : read_specs (specs_file, true, false);
8500 : : else
8501 : 1091 : init_spec ();
8502 : :
8503 : : #ifdef ACCEL_COMPILER
8504 : : spec_machine_suffix = machine_suffix;
8505 : : #else
8506 : 295977 : spec_machine_suffix = just_machine_suffix;
8507 : : #endif
8508 : :
8509 : 295977 : const char *exec_prefix
8510 : 295977 : = gcc_exec_prefix ? gcc_exec_prefix : standard_exec_prefix;
8511 : : /* We need to check standard_exec_prefix/spec_machine_suffix/specs
8512 : : for any override of as, ld and libraries. */
8513 : 295977 : specs_file = (char *) alloca (
8514 : : strlen (exec_prefix) + strlen (spec_machine_suffix) + sizeof ("specs"));
8515 : 295977 : strcpy (specs_file, exec_prefix);
8516 : 295977 : strcat (specs_file, spec_machine_suffix);
8517 : 295977 : strcat (specs_file, "specs");
8518 : 295977 : if (access (specs_file, R_OK) == 0)
8519 : 0 : read_specs (specs_file, true, false);
8520 : :
8521 : : /* Process any configure-time defaults specified for the command line
8522 : : options, via OPTION_DEFAULT_SPECS. */
8523 : 2959770 : for (i = 0; i < ARRAY_SIZE (option_default_specs); i++)
8524 : 2663793 : do_option_spec (option_default_specs[i].name,
8525 : 2663793 : option_default_specs[i].spec);
8526 : :
8527 : : /* Process DRIVER_SELF_SPECS, adding any new options to the end
8528 : : of the command line. */
8529 : :
8530 : 2071839 : for (i = 0; i < ARRAY_SIZE (driver_self_specs); i++)
8531 : 1775862 : do_self_spec (driver_self_specs[i]);
8532 : :
8533 : : /* If not cross-compiling, look for executables in the standard
8534 : : places. */
8535 : 295977 : if (*cross_compile == '0')
8536 : : {
8537 : 295977 : if (*md_exec_prefix)
8538 : : {
8539 : 0 : add_prefix (&exec_prefixes, md_exec_prefix, "GCC",
8540 : : PREFIX_PRIORITY_LAST, 0, 0);
8541 : : }
8542 : : }
8543 : :
8544 : : /* Process sysroot_suffix_spec. */
8545 : 295977 : if (*sysroot_suffix_spec != 0
8546 : 0 : && !no_sysroot_suffix
8547 : 295977 : && do_spec_2 (sysroot_suffix_spec, NULL) == 0)
8548 : : {
8549 : 0 : if (argbuf.length () > 1)
8550 : 0 : error ("spec failure: more than one argument to "
8551 : : "%<SYSROOT_SUFFIX_SPEC%>");
8552 : 0 : else if (argbuf.length () == 1)
8553 : 0 : target_sysroot_suffix = xstrdup (argbuf.last ());
8554 : : }
8555 : :
8556 : : #ifdef HAVE_LD_SYSROOT
8557 : : /* Pass the --sysroot option to the linker, if it supports that. If
8558 : : there is a sysroot_suffix_spec, it has already been processed by
8559 : : this point, so target_system_root really is the system root we
8560 : : should be using. */
8561 : 295977 : if (target_system_root)
8562 : : {
8563 : 0 : obstack_grow (&obstack, "%(sysroot_spec) ", strlen ("%(sysroot_spec) "));
8564 : 0 : obstack_grow0 (&obstack, link_spec, strlen (link_spec));
8565 : 0 : set_spec ("link", XOBFINISH (&obstack, const char *), false);
8566 : : }
8567 : : #endif
8568 : :
8569 : : /* Process sysroot_hdrs_suffix_spec. */
8570 : 295977 : if (*sysroot_hdrs_suffix_spec != 0
8571 : 0 : && !no_sysroot_suffix
8572 : 295977 : && do_spec_2 (sysroot_hdrs_suffix_spec, NULL) == 0)
8573 : : {
8574 : 0 : if (argbuf.length () > 1)
8575 : 0 : error ("spec failure: more than one argument "
8576 : : "to %<SYSROOT_HEADERS_SUFFIX_SPEC%>");
8577 : 0 : else if (argbuf.length () == 1)
8578 : 0 : target_sysroot_hdrs_suffix = xstrdup (argbuf.last ());
8579 : : }
8580 : :
8581 : : /* Look for startfiles in the standard places. */
8582 : 295977 : if (*startfile_prefix_spec != 0
8583 : 0 : && do_spec_2 (startfile_prefix_spec, NULL) == 0
8584 : 295977 : && do_spec_1 (" ", 0, NULL) == 0)
8585 : : {
8586 : 0 : for (const char *arg : argbuf)
8587 : 0 : add_sysrooted_prefix (&startfile_prefixes, arg, "BINUTILS",
8588 : : PREFIX_PRIORITY_LAST, 0, 1);
8589 : : }
8590 : : /* We should eventually get rid of all these and stick to
8591 : : startfile_prefix_spec exclusively. */
8592 : 295977 : else if (*cross_compile == '0' || target_system_root)
8593 : : {
8594 : 295977 : if (*md_startfile_prefix)
8595 : 0 : add_sysrooted_prefix (&startfile_prefixes, md_startfile_prefix,
8596 : : "GCC", PREFIX_PRIORITY_LAST, 0, 1);
8597 : :
8598 : 295977 : if (*md_startfile_prefix_1)
8599 : 0 : add_sysrooted_prefix (&startfile_prefixes, md_startfile_prefix_1,
8600 : : "GCC", PREFIX_PRIORITY_LAST, 0, 1);
8601 : :
8602 : : /* If standard_startfile_prefix is relative, base it on
8603 : : standard_exec_prefix. This lets us move the installed tree
8604 : : as a unit. If GCC_EXEC_PREFIX is defined, base
8605 : : standard_startfile_prefix on that as well.
8606 : :
8607 : : If the prefix is relative, only search it for native compilers;
8608 : : otherwise we will search a directory containing host libraries. */
8609 : 295977 : if (IS_ABSOLUTE_PATH (standard_startfile_prefix))
8610 : : add_sysrooted_prefix (&startfile_prefixes,
8611 : : standard_startfile_prefix, "BINUTILS",
8612 : : PREFIX_PRIORITY_LAST, 0, 1);
8613 : 295977 : else if (*cross_compile == '0')
8614 : : {
8615 : 295977 : add_prefix (&startfile_prefixes,
8616 : 591954 : concat (gcc_exec_prefix
8617 : : ? gcc_exec_prefix : standard_exec_prefix,
8618 : : machine_suffix,
8619 : : standard_startfile_prefix, NULL),
8620 : : NULL, PREFIX_PRIORITY_LAST, 0, 1);
8621 : : }
8622 : :
8623 : : /* Sysrooted prefixes are relocated because target_system_root is
8624 : : also relocated by gcc_exec_prefix. */
8625 : 295977 : if (*standard_startfile_prefix_1)
8626 : 295977 : add_sysrooted_prefix (&startfile_prefixes,
8627 : : standard_startfile_prefix_1, "BINUTILS",
8628 : : PREFIX_PRIORITY_LAST, 0, 1);
8629 : 295977 : if (*standard_startfile_prefix_2)
8630 : 295977 : add_sysrooted_prefix (&startfile_prefixes,
8631 : : standard_startfile_prefix_2, "BINUTILS",
8632 : : PREFIX_PRIORITY_LAST, 0, 1);
8633 : : }
8634 : :
8635 : : /* Process any user specified specs in the order given on the command
8636 : : line. */
8637 : 295979 : for (struct user_specs *uptr = user_specs_head; uptr; uptr = uptr->next)
8638 : : {
8639 : 3 : char *filename = find_a_file (&startfile_prefixes, uptr->filename,
8640 : : R_OK, true);
8641 : 3 : read_specs (filename ? filename : uptr->filename, false, true);
8642 : : }
8643 : :
8644 : : /* Process any user self specs. */
8645 : 295976 : {
8646 : 295976 : struct spec_list *sl;
8647 : 13910872 : for (sl = specs; sl; sl = sl->next)
8648 : 13614896 : if (sl->name_len == sizeof "self_spec" - 1
8649 : 2071832 : && !strcmp (sl->name, "self_spec"))
8650 : 295976 : do_self_spec (*sl->ptr_spec);
8651 : : }
8652 : :
8653 : 295976 : if (compare_debug)
8654 : : {
8655 : 622 : enum save_temps save;
8656 : :
8657 : 622 : if (!compare_debug_second)
8658 : : {
8659 : 622 : n_switches_debug_check[1] = n_switches;
8660 : 622 : n_switches_alloc_debug_check[1] = n_switches_alloc;
8661 : 622 : switches_debug_check[1] = XDUPVEC (struct switchstr, switches,
8662 : : n_switches_alloc);
8663 : :
8664 : 622 : do_self_spec ("%:compare-debug-self-opt()");
8665 : 622 : n_switches_debug_check[0] = n_switches;
8666 : 622 : n_switches_alloc_debug_check[0] = n_switches_alloc;
8667 : 622 : switches_debug_check[0] = switches;
8668 : :
8669 : 622 : n_switches = n_switches_debug_check[1];
8670 : 622 : n_switches_alloc = n_switches_alloc_debug_check[1];
8671 : 622 : switches = switches_debug_check[1];
8672 : : }
8673 : :
8674 : : /* Avoid crash when computing %j in this early. */
8675 : 622 : save = save_temps_flag;
8676 : 622 : save_temps_flag = SAVE_TEMPS_NONE;
8677 : :
8678 : 622 : compare_debug = -compare_debug;
8679 : 622 : do_self_spec ("%:compare-debug-self-opt()");
8680 : :
8681 : 622 : save_temps_flag = save;
8682 : :
8683 : 622 : if (!compare_debug_second)
8684 : : {
8685 : 622 : n_switches_debug_check[1] = n_switches;
8686 : 622 : n_switches_alloc_debug_check[1] = n_switches_alloc;
8687 : 622 : switches_debug_check[1] = switches;
8688 : 622 : compare_debug = -compare_debug;
8689 : 622 : n_switches = n_switches_debug_check[0];
8690 : 622 : n_switches_alloc = n_switches_debug_check[0];
8691 : 622 : switches = switches_debug_check[0];
8692 : : }
8693 : : }
8694 : :
8695 : :
8696 : : /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
8697 : 295976 : if (gcc_exec_prefix)
8698 : 295976 : gcc_exec_prefix = concat (gcc_exec_prefix, spec_host_machine,
8699 : : dir_separator_str, spec_version,
8700 : : accel_dir_suffix, dir_separator_str, NULL);
8701 : :
8702 : : /* Now we have the specs.
8703 : : Set the `valid' bits for switches that match anything in any spec. */
8704 : :
8705 : 295976 : validate_all_switches ();
8706 : :
8707 : : /* Now that we have the switches and the specs, set
8708 : : the subdirectory based on the options. */
8709 : 295976 : set_multilib_dir ();
8710 : 295976 : }
8711 : :
8712 : : /* Set up to remember the pathname of gcc and any options
8713 : : needed for collect. We use argv[0] instead of progname because
8714 : : we need the complete pathname. */
8715 : :
8716 : : void
8717 : 295976 : driver::putenv_COLLECT_GCC (const char *argv0) const
8718 : : {
8719 : 295976 : obstack_init (&collect_obstack);
8720 : 295976 : obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=") - 1);
8721 : 295976 : obstack_grow (&collect_obstack, argv0, strlen (argv0) + 1);
8722 : 295976 : xputenv (XOBFINISH (&collect_obstack, char *));
8723 : 295976 : }
8724 : :
8725 : : /* Set up to remember the pathname of the lto wrapper. */
8726 : :
8727 : : void
8728 : 295976 : driver::maybe_putenv_COLLECT_LTO_WRAPPER () const
8729 : : {
8730 : 295976 : char *lto_wrapper_file;
8731 : :
8732 : 295976 : if (have_c)
8733 : : lto_wrapper_file = NULL;
8734 : : else
8735 : 109309 : lto_wrapper_file = find_a_program ("lto-wrapper");
8736 : 109309 : if (lto_wrapper_file)
8737 : : {
8738 : 214256 : lto_wrapper_file = convert_white_space (lto_wrapper_file);
8739 : 107128 : set_static_spec_owned (<o_wrapper_spec, lto_wrapper_file);
8740 : 107128 : obstack_init (&collect_obstack);
8741 : 107128 : obstack_grow (&collect_obstack, "COLLECT_LTO_WRAPPER=",
8742 : : sizeof ("COLLECT_LTO_WRAPPER=") - 1);
8743 : 107128 : obstack_grow (&collect_obstack, lto_wrapper_spec,
8744 : : strlen (lto_wrapper_spec) + 1);
8745 : 107128 : xputenv (XOBFINISH (&collect_obstack, char *));
8746 : : }
8747 : :
8748 : 295976 : }
8749 : :
8750 : : /* Set up to remember the names of offload targets. */
8751 : :
8752 : : void
8753 : 295976 : driver::maybe_putenv_OFFLOAD_TARGETS () const
8754 : : {
8755 : 295976 : if (offload_targets && offload_targets[0] != '\0')
8756 : : {
8757 : 0 : obstack_grow (&collect_obstack, "OFFLOAD_TARGET_NAMES=",
8758 : : sizeof ("OFFLOAD_TARGET_NAMES=") - 1);
8759 : 0 : obstack_grow (&collect_obstack, offload_targets,
8760 : : strlen (offload_targets) + 1);
8761 : 0 : xputenv (XOBFINISH (&collect_obstack, char *));
8762 : : #if OFFLOAD_DEFAULTED
8763 : : if (offload_targets_default)
8764 : : xputenv ("OFFLOAD_TARGET_DEFAULT=1");
8765 : : #endif
8766 : : }
8767 : :
8768 : 295976 : free (offload_targets);
8769 : 295976 : offload_targets = NULL;
8770 : 295976 : }
8771 : :
8772 : : /* Reject switches that no pass was interested in. */
8773 : :
8774 : : void
8775 : 295976 : driver::handle_unrecognized_options ()
8776 : : {
8777 : 6684937 : for (size_t i = 0; (int) i < n_switches; i++)
8778 : 6388961 : if (! switches[i].validated)
8779 : : {
8780 : 514 : const char *hint = m_option_proposer.suggest_option (switches[i].part1);
8781 : 514 : if (hint)
8782 : 214 : error ("unrecognized command-line option %<-%s%>;"
8783 : : " did you mean %<-%s%>?",
8784 : 214 : switches[i].part1, hint);
8785 : : else
8786 : 300 : error ("unrecognized command-line option %<-%s%>",
8787 : 300 : switches[i].part1);
8788 : : }
8789 : 295976 : }
8790 : :
8791 : : /* Handle the various -print-* options, returning 0 if the driver
8792 : : should exit, or nonzero if the driver should continue. */
8793 : :
8794 : : int
8795 : 295971 : driver::maybe_print_and_exit () const
8796 : : {
8797 : 295971 : if (print_search_dirs)
8798 : : {
8799 : 56 : printf (_("install: %s%s\n"),
8800 : : gcc_exec_prefix ? gcc_exec_prefix : standard_exec_prefix,
8801 : 28 : gcc_exec_prefix ? "" : machine_suffix);
8802 : 28 : printf (_("programs: %s\n"),
8803 : : build_search_list (&exec_prefixes, "", false, false));
8804 : 28 : printf (_("libraries: %s\n"),
8805 : : build_search_list (&startfile_prefixes, "", false, true));
8806 : 28 : return (0);
8807 : : }
8808 : :
8809 : 295943 : if (print_file_name)
8810 : : {
8811 : 4339 : printf ("%s\n", find_file (print_file_name));
8812 : 4339 : return (0);
8813 : : }
8814 : :
8815 : 291604 : if (print_prog_name)
8816 : : {
8817 : 106 : if (use_ld != NULL && ! strcmp (print_prog_name, "ld"))
8818 : : {
8819 : : /* Append USE_LD to the default linker. */
8820 : : #ifdef DEFAULT_LINKER
8821 : : char *ld;
8822 : : # ifdef HAVE_HOST_EXECUTABLE_SUFFIX
8823 : : int len = (sizeof (DEFAULT_LINKER)
8824 : : - sizeof (HOST_EXECUTABLE_SUFFIX));
8825 : : ld = NULL;
8826 : : if (len > 0)
8827 : : {
8828 : : char *default_linker = xstrdup (DEFAULT_LINKER);
8829 : : /* Strip HOST_EXECUTABLE_SUFFIX if DEFAULT_LINKER contains
8830 : : HOST_EXECUTABLE_SUFFIX. */
8831 : : if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
8832 : : {
8833 : : default_linker[len] = '\0';
8834 : : ld = concat (default_linker, use_ld,
8835 : : HOST_EXECUTABLE_SUFFIX, NULL);
8836 : : }
8837 : : }
8838 : : if (ld == NULL)
8839 : : # endif
8840 : : ld = concat (DEFAULT_LINKER, use_ld, NULL);
8841 : : if (access (ld, X_OK) == 0)
8842 : : {
8843 : : printf ("%s\n", ld);
8844 : : return (0);
8845 : : }
8846 : : #endif
8847 : 0 : print_prog_name = concat (print_prog_name, use_ld, NULL);
8848 : : }
8849 : 106 : char *newname = find_a_program (print_prog_name);
8850 : 106 : printf ("%s\n", (newname ? newname : print_prog_name));
8851 : 106 : return (0);
8852 : : }
8853 : :
8854 : 291498 : if (print_multi_lib)
8855 : : {
8856 : 4811 : print_multilib_info ();
8857 : 4811 : return (0);
8858 : : }
8859 : :
8860 : 286687 : if (print_multi_directory)
8861 : : {
8862 : 4236 : if (multilib_dir == NULL)
8863 : 4211 : printf (".\n");
8864 : : else
8865 : 25 : printf ("%s\n", multilib_dir);
8866 : 4236 : return (0);
8867 : : }
8868 : :
8869 : 282451 : if (print_multiarch)
8870 : : {
8871 : 0 : if (multiarch_dir == NULL)
8872 : 0 : printf ("\n");
8873 : : else
8874 : 0 : printf ("%s\n", multiarch_dir);
8875 : 0 : return (0);
8876 : : }
8877 : :
8878 : 282451 : if (print_sysroot)
8879 : : {
8880 : 0 : if (target_system_root)
8881 : : {
8882 : 0 : if (target_sysroot_suffix)
8883 : 0 : printf ("%s%s\n", target_system_root, target_sysroot_suffix);
8884 : : else
8885 : 0 : printf ("%s\n", target_system_root);
8886 : : }
8887 : 0 : return (0);
8888 : : }
8889 : :
8890 : 282451 : if (print_multi_os_directory)
8891 : : {
8892 : 149 : if (multilib_os_dir == NULL)
8893 : 0 : printf (".\n");
8894 : : else
8895 : 149 : printf ("%s\n", multilib_os_dir);
8896 : 149 : return (0);
8897 : : }
8898 : :
8899 : 282302 : if (print_sysroot_headers_suffix)
8900 : : {
8901 : 1 : if (*sysroot_hdrs_suffix_spec)
8902 : : {
8903 : 0 : printf("%s\n", (target_sysroot_hdrs_suffix
8904 : : ? target_sysroot_hdrs_suffix
8905 : : : ""));
8906 : 0 : return (0);
8907 : : }
8908 : : else
8909 : : /* The error status indicates that only one set of fixed
8910 : : headers should be built. */
8911 : 1 : fatal_error (input_location,
8912 : : "not configured with sysroot headers suffix");
8913 : : }
8914 : :
8915 : 282301 : if (print_help_list)
8916 : : {
8917 : 4 : display_help ();
8918 : :
8919 : 4 : if (! verbose_flag)
8920 : : {
8921 : 1 : printf (_("\nFor bug reporting instructions, please see:\n"));
8922 : 1 : printf ("%s.\n", bug_report_url);
8923 : :
8924 : 1 : return (0);
8925 : : }
8926 : :
8927 : : /* We do not exit here. Instead we have created a fake input file
8928 : : called 'help-dummy' which needs to be compiled, and we pass this
8929 : : on the various sub-processes, along with the --help switch.
8930 : : Ensure their output appears after ours. */
8931 : 3 : fputc ('\n', stdout);
8932 : 3 : fflush (stdout);
8933 : : }
8934 : :
8935 : 282300 : if (print_version)
8936 : : {
8937 : 78 : printf (_("%s %s%s\n"), progname, pkgversion_string,
8938 : : version_string);
8939 : 78 : printf ("Copyright %s 2025 Free Software Foundation, Inc.\n",
8940 : : _("(C)"));
8941 : 78 : fputs (_("This is free software; see the source for copying conditions. There is NO\n\
8942 : : warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"),
8943 : : stdout);
8944 : 78 : if (! verbose_flag)
8945 : : return 0;
8946 : :
8947 : : /* We do not exit here. We use the same mechanism of --help to print
8948 : : the version of the sub-processes. */
8949 : 0 : fputc ('\n', stdout);
8950 : 0 : fflush (stdout);
8951 : : }
8952 : :
8953 : 282222 : if (verbose_flag)
8954 : : {
8955 : 1454 : print_configuration (stderr);
8956 : 1454 : if (n_infiles == 0)
8957 : : return (0);
8958 : : }
8959 : :
8960 : : return 1;
8961 : : }
8962 : :
8963 : : /* Figure out what to do with each input file.
8964 : : Return true if we need to exit early from "main", false otherwise. */
8965 : :
8966 : : bool
8967 : 281560 : driver::prepare_infiles ()
8968 : : {
8969 : 281560 : size_t i;
8970 : 281560 : int lang_n_infiles = 0;
8971 : :
8972 : 281560 : if (n_infiles == added_libraries)
8973 : 194 : fatal_error (input_location, "no input files");
8974 : :
8975 : 281366 : if (seen_error ())
8976 : : /* Early exit needed from main. */
8977 : : return true;
8978 : :
8979 : : /* Make a place to record the compiler output file names
8980 : : that correspond to the input files. */
8981 : :
8982 : 280948 : i = n_infiles;
8983 : 280948 : i += lang_specific_extra_outfiles;
8984 : 280948 : outfiles = XCNEWVEC (const char *, i);
8985 : :
8986 : : /* Record which files were specified explicitly as link input. */
8987 : :
8988 : 280948 : explicit_link_files = XCNEWVEC (char, n_infiles);
8989 : :
8990 : 280948 : combine_inputs = have_o || flag_wpa;
8991 : :
8992 : 827411 : for (i = 0; (int) i < n_infiles; i++)
8993 : : {
8994 : 546463 : const char *name = infiles[i].name;
8995 : 546463 : struct compiler *compiler = lookup_compiler (name,
8996 : : strlen (name),
8997 : : infiles[i].language);
8998 : :
8999 : 546463 : if (compiler && !(compiler->combinable))
9000 : 250594 : combine_inputs = false;
9001 : :
9002 : 546463 : if (lang_n_infiles > 0 && compiler != input_file_compiler
9003 : 243810 : && infiles[i].language && infiles[i].language[0] != '*')
9004 : 33 : infiles[i].incompiler = compiler;
9005 : 546430 : else if (compiler)
9006 : : {
9007 : 291918 : lang_n_infiles++;
9008 : 291918 : input_file_compiler = compiler;
9009 : 291918 : infiles[i].incompiler = compiler;
9010 : : }
9011 : : else
9012 : : {
9013 : : /* Since there is no compiler for this input file, assume it is a
9014 : : linker file. */
9015 : 254512 : explicit_link_files[i] = 1;
9016 : 254512 : infiles[i].incompiler = NULL;
9017 : : }
9018 : 546463 : infiles[i].compiled = false;
9019 : 546463 : infiles[i].preprocessed = false;
9020 : : }
9021 : :
9022 : 280948 : if (!combine_inputs && have_c && have_o && lang_n_infiles > 1)
9023 : 0 : fatal_error (input_location,
9024 : : "cannot specify %<-o%> with %<-c%>, %<-S%> or %<-E%> "
9025 : : "with multiple files");
9026 : :
9027 : : /* No early exit needed from main; we can continue. */
9028 : : return false;
9029 : : }
9030 : :
9031 : : /* Run the spec machinery on each input file. */
9032 : :
9033 : : void
9034 : 280948 : driver::do_spec_on_infiles () const
9035 : : {
9036 : 280948 : size_t i;
9037 : :
9038 : 827411 : for (i = 0; (int) i < n_infiles; i++)
9039 : : {
9040 : 546463 : int this_file_error = 0;
9041 : :
9042 : : /* Tell do_spec what to substitute for %i. */
9043 : :
9044 : 546463 : input_file_number = i;
9045 : 546463 : set_input (infiles[i].name);
9046 : :
9047 : 546463 : if (infiles[i].compiled)
9048 : 9094 : continue;
9049 : :
9050 : : /* Use the same thing in %o, unless cp->spec says otherwise. */
9051 : :
9052 : 537369 : outfiles[i] = gcc_input_filename;
9053 : :
9054 : : /* Figure out which compiler from the file's suffix. */
9055 : :
9056 : 537369 : input_file_compiler
9057 : 537369 : = lookup_compiler (infiles[i].name, input_filename_length,
9058 : : infiles[i].language);
9059 : :
9060 : 537369 : if (input_file_compiler)
9061 : : {
9062 : : /* Ok, we found an applicable compiler. Run its spec. */
9063 : :
9064 : 282857 : if (input_file_compiler->spec[0] == '#')
9065 : : {
9066 : 0 : error ("%s: %s compiler not installed on this system",
9067 : : gcc_input_filename, &input_file_compiler->spec[1]);
9068 : 0 : this_file_error = 1;
9069 : : }
9070 : : else
9071 : : {
9072 : 282857 : int value;
9073 : :
9074 : 282857 : if (compare_debug)
9075 : : {
9076 : 620 : free (debug_check_temp_file[0]);
9077 : 620 : debug_check_temp_file[0] = NULL;
9078 : :
9079 : 620 : free (debug_check_temp_file[1]);
9080 : 620 : debug_check_temp_file[1] = NULL;
9081 : : }
9082 : :
9083 : 282857 : value = do_spec (input_file_compiler->spec);
9084 : 282857 : infiles[i].compiled = true;
9085 : 282857 : if (value < 0)
9086 : : this_file_error = 1;
9087 : 253970 : else if (compare_debug && debug_check_temp_file[0])
9088 : : {
9089 : 616 : if (verbose_flag)
9090 : 0 : inform (UNKNOWN_LOCATION,
9091 : : "recompiling with %<-fcompare-debug%>");
9092 : :
9093 : 616 : compare_debug = -compare_debug;
9094 : 616 : n_switches = n_switches_debug_check[1];
9095 : 616 : n_switches_alloc = n_switches_alloc_debug_check[1];
9096 : 616 : switches = switches_debug_check[1];
9097 : :
9098 : 616 : value = do_spec (input_file_compiler->spec);
9099 : :
9100 : 616 : compare_debug = -compare_debug;
9101 : 616 : n_switches = n_switches_debug_check[0];
9102 : 616 : n_switches_alloc = n_switches_alloc_debug_check[0];
9103 : 616 : switches = switches_debug_check[0];
9104 : :
9105 : 616 : if (value < 0)
9106 : : {
9107 : 3 : error ("during %<-fcompare-debug%> recompilation");
9108 : 3 : this_file_error = 1;
9109 : : }
9110 : :
9111 : 616 : gcc_assert (debug_check_temp_file[1]
9112 : : && filename_cmp (debug_check_temp_file[0],
9113 : : debug_check_temp_file[1]));
9114 : :
9115 : 616 : if (verbose_flag)
9116 : 0 : inform (UNKNOWN_LOCATION, "comparing final insns dumps");
9117 : :
9118 : 616 : if (compare_files (debug_check_temp_file))
9119 : 28904 : this_file_error = 1;
9120 : : }
9121 : :
9122 : 282857 : if (compare_debug)
9123 : : {
9124 : 620 : free (debug_check_temp_file[0]);
9125 : 620 : debug_check_temp_file[0] = NULL;
9126 : :
9127 : 620 : free (debug_check_temp_file[1]);
9128 : 620 : debug_check_temp_file[1] = NULL;
9129 : : }
9130 : : }
9131 : : }
9132 : :
9133 : : /* If this file's name does not contain a recognized suffix,
9134 : : record it as explicit linker input. */
9135 : :
9136 : : else
9137 : 254512 : explicit_link_files[i] = 1;
9138 : :
9139 : : /* Clear the delete-on-failure queue, deleting the files in it
9140 : : if this compilation failed. */
9141 : :
9142 : 537369 : if (this_file_error)
9143 : : {
9144 : 28904 : delete_failure_queue ();
9145 : 28904 : errorcount++;
9146 : : }
9147 : : /* If this compilation succeeded, don't delete those files later. */
9148 : 537369 : clear_failure_queue ();
9149 : : }
9150 : :
9151 : : /* Reset the input file name to the first compile/object file name, for use
9152 : : with %b in LINK_SPEC. We use the first input file that we can find
9153 : : a compiler to compile it instead of using infiles.language since for
9154 : : languages other than C we use aliases that we then lookup later. */
9155 : 280948 : if (n_infiles > 0)
9156 : : {
9157 : : int i;
9158 : :
9159 : 293081 : for (i = 0; i < n_infiles ; i++)
9160 : 291198 : if (infiles[i].incompiler
9161 : 12133 : || (infiles[i].language && infiles[i].language[0] != '*'))
9162 : : {
9163 : 279065 : set_input (infiles[i].name);
9164 : 279065 : break;
9165 : : }
9166 : : }
9167 : :
9168 : 280948 : if (!seen_error ())
9169 : : {
9170 : : /* Make sure INPUT_FILE_NUMBER points to first available open
9171 : : slot. */
9172 : 252044 : input_file_number = n_infiles;
9173 : 252044 : if (lang_specific_pre_link ())
9174 : 0 : errorcount++;
9175 : : }
9176 : 280948 : }
9177 : :
9178 : : /* If we have to run the linker, do it now. */
9179 : :
9180 : : void
9181 : 280948 : driver::maybe_run_linker (const char *argv0) const
9182 : : {
9183 : 280948 : size_t i;
9184 : 280948 : int linker_was_run = 0;
9185 : 280948 : int num_linker_inputs;
9186 : :
9187 : : /* Determine if there are any linker input files. */
9188 : 280948 : num_linker_inputs = 0;
9189 : 827411 : for (i = 0; (int) i < n_infiles; i++)
9190 : 546463 : if (explicit_link_files[i] || outfiles[i] != NULL)
9191 : 536912 : num_linker_inputs++;
9192 : :
9193 : : /* Arrange for temporary file names created during linking to take
9194 : : on names related with the linker output rather than with the
9195 : : inputs when appropriate. */
9196 : 280948 : if (outbase && *outbase)
9197 : : {
9198 : 258249 : if (dumpdir)
9199 : : {
9200 : 86865 : char *tofree = dumpdir;
9201 : 86865 : gcc_checking_assert (strlen (dumpdir) == dumpdir_length);
9202 : 86865 : dumpdir = concat (dumpdir, outbase, ".", NULL);
9203 : 86865 : free (tofree);
9204 : : }
9205 : : else
9206 : 171384 : dumpdir = concat (outbase, ".", NULL);
9207 : 258249 : dumpdir_length += strlen (outbase) + 1;
9208 : 258249 : dumpdir_trailing_dash_added = true;
9209 : 258249 : }
9210 : 22699 : else if (dumpdir_trailing_dash_added)
9211 : : {
9212 : 17867 : gcc_assert (dumpdir[dumpdir_length - 1] == '-');
9213 : 17867 : dumpdir[dumpdir_length - 1] = '.';
9214 : : }
9215 : :
9216 : 280948 : if (dumpdir_trailing_dash_added)
9217 : : {
9218 : 276116 : gcc_assert (dumpdir_length > 0);
9219 : 276116 : gcc_assert (dumpdir[dumpdir_length - 1] == '.');
9220 : 276116 : dumpdir_length--;
9221 : : }
9222 : :
9223 : 280948 : free (outbase);
9224 : 280948 : input_basename = outbase = NULL;
9225 : 280948 : outbase_length = suffixed_basename_length = basename_length = 0;
9226 : :
9227 : : /* Run ld to link all the compiler output files. */
9228 : :
9229 : 280948 : if (num_linker_inputs > 0 && !seen_error () && print_subprocess_help < 2)
9230 : : {
9231 : 251492 : int tmp = execution_count;
9232 : :
9233 : 251492 : detect_jobserver ();
9234 : :
9235 : 251492 : if (! have_c)
9236 : : {
9237 : : #if HAVE_LTO_PLUGIN > 0
9238 : : #if HAVE_LTO_PLUGIN == 2
9239 : 94526 : const char *fno_use_linker_plugin = "fno-use-linker-plugin";
9240 : : #else
9241 : : const char *fuse_linker_plugin = "fuse-linker-plugin";
9242 : : #endif
9243 : : #endif
9244 : :
9245 : : /* We'll use ld if we can't find collect2. */
9246 : 94526 : if (! strcmp (linker_name_spec, "collect2"))
9247 : : {
9248 : 94526 : char *s = find_a_program ("collect2");
9249 : 94526 : if (s == NULL)
9250 : 1089 : set_static_spec_shared (&linker_name_spec, "ld");
9251 : : }
9252 : :
9253 : : #if HAVE_LTO_PLUGIN > 0
9254 : : #if HAVE_LTO_PLUGIN == 2
9255 : 94526 : if (!switch_matches (fno_use_linker_plugin,
9256 : : fno_use_linker_plugin
9257 : : + strlen (fno_use_linker_plugin), 0))
9258 : : #else
9259 : : if (switch_matches (fuse_linker_plugin,
9260 : : fuse_linker_plugin
9261 : : + strlen (fuse_linker_plugin), 0))
9262 : : #endif
9263 : : {
9264 : 89196 : char *temp_spec = find_a_file (&exec_prefixes,
9265 : : LTOPLUGINSONAME, R_OK,
9266 : : false);
9267 : 89196 : if (!temp_spec)
9268 : 0 : fatal_error (input_location,
9269 : : "%<-fuse-linker-plugin%>, but %s not found",
9270 : : LTOPLUGINSONAME);
9271 : 89196 : linker_plugin_file_spec = convert_white_space (temp_spec);
9272 : : }
9273 : : #endif
9274 : 94526 : set_static_spec_shared (<o_gcc_spec, argv0);
9275 : : }
9276 : :
9277 : : /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
9278 : : for collect. */
9279 : 251492 : putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH", false);
9280 : 251492 : putenv_from_prefixes (&startfile_prefixes, LIBRARY_PATH_ENV, true);
9281 : :
9282 : 251492 : if (print_subprocess_help == 1)
9283 : : {
9284 : 0 : printf (_("\nLinker options\n==============\n\n"));
9285 : 0 : printf (_("Use \"-Wl,OPTION\" to pass \"OPTION\""
9286 : : " to the linker.\n\n"));
9287 : 0 : fflush (stdout);
9288 : : }
9289 : 251492 : int value = do_spec (link_command_spec);
9290 : 251492 : if (value < 0)
9291 : 134 : errorcount = 1;
9292 : 251492 : linker_was_run = (tmp != execution_count);
9293 : : }
9294 : :
9295 : : /* If options said don't run linker,
9296 : : complain about input files to be given to the linker. */
9297 : :
9298 : 280948 : if (! linker_was_run && !seen_error ())
9299 : 346797 : for (i = 0; (int) i < n_infiles; i++)
9300 : 189275 : if (explicit_link_files[i]
9301 : 22677 : && !(infiles[i].language && infiles[i].language[0] == '*'))
9302 : : {
9303 : 38 : warning (0, "%s: linker input file unused because linking not done",
9304 : 19 : outfiles[i]);
9305 : 19 : if (access (outfiles[i], F_OK) < 0)
9306 : : /* This is can be an indication the user specifed an errorneous
9307 : : separated option value, (or used the wrong prefix for an
9308 : : option). */
9309 : 7 : error ("%s: linker input file not found: %m", outfiles[i]);
9310 : : }
9311 : 280948 : }
9312 : :
9313 : : /* The end of "main". */
9314 : :
9315 : : void
9316 : 280948 : driver::final_actions () const
9317 : : {
9318 : : /* Delete some or all of the temporary files we made. */
9319 : :
9320 : 280948 : if (seen_error ())
9321 : 29043 : delete_failure_queue ();
9322 : 280948 : delete_temp_files ();
9323 : :
9324 : 280948 : if (totruncate_file != NULL && !seen_error ())
9325 : : /* Truncate file specified by -truncate.
9326 : : Used by lto-wrapper to reduce temporary disk-space usage. */
9327 : 8915 : truncate(totruncate_file, 0);
9328 : :
9329 : 280948 : if (print_help_list)
9330 : : {
9331 : 3 : printf (("\nFor bug reporting instructions, please see:\n"));
9332 : 3 : printf ("%s\n", bug_report_url);
9333 : : }
9334 : 280948 : }
9335 : :
9336 : : /* Detect whether jobserver is active and working. If not drop
9337 : : --jobserver-auth from MAKEFLAGS. */
9338 : :
9339 : : void
9340 : 251492 : driver::detect_jobserver () const
9341 : : {
9342 : 251492 : jobserver_info jinfo;
9343 : 251492 : if (!jinfo.is_active && !jinfo.skipped_makeflags.empty ())
9344 : 0 : xputenv (xstrdup (jinfo.skipped_makeflags.c_str ()));
9345 : 251492 : }
9346 : :
9347 : : /* Determine what the exit code of the driver should be. */
9348 : :
9349 : : int
9350 : 281366 : driver::get_exit_code () const
9351 : : {
9352 : 281366 : return (signal_count != 0 ? 2
9353 : 281366 : : seen_error () ? (pass_exit_codes ? greatest_status : 1)
9354 : 0 : : 0);
9355 : : }
9356 : :
9357 : : /* Find the proper compilation spec for the file name NAME,
9358 : : whose length is LENGTH. LANGUAGE is the specified language,
9359 : : or 0 if this file is to be passed to the linker. */
9360 : :
9361 : : static struct compiler *
9362 : 1083832 : lookup_compiler (const char *name, size_t length, const char *language)
9363 : : {
9364 : 1584355 : struct compiler *cp;
9365 : :
9366 : : /* If this was specified by the user to be a linker input, indicate that. */
9367 : 1584355 : if (language != 0 && language[0] == '*')
9368 : : return 0;
9369 : :
9370 : : /* Otherwise, look for the language, if one is spec'd. */
9371 : 1122415 : if (language != 0)
9372 : : {
9373 : 22653373 : for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
9374 : 22653373 : if (cp->suffix[0] == '@' && !strcmp (cp->suffix + 1, language))
9375 : : {
9376 : 574794 : if (name != NULL && strcmp (name, "-") == 0
9377 : 2076 : && (strcmp (cp->suffix, "@c-header") == 0
9378 : 2076 : || strcmp (cp->suffix, "@c++-header") == 0)
9379 : 0 : && !have_E)
9380 : 0 : fatal_error (input_location,
9381 : : "cannot use %<-%> as input filename for a "
9382 : : "precompiled header");
9383 : :
9384 : : return cp;
9385 : : }
9386 : :
9387 : 0 : error ("language %s not recognized", language);
9388 : 0 : return 0;
9389 : : }
9390 : :
9391 : : /* Look for a suffix. */
9392 : 30028103 : for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
9393 : : {
9394 : 29981019 : if (/* The suffix `-' matches only the file name `-'. */
9395 : 29981019 : (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
9396 : 29981005 : || (strlen (cp->suffix) < length
9397 : : /* See if the suffix matches the end of NAME. */
9398 : 29559716 : && !strcmp (cp->suffix,
9399 : 29559716 : name + length - strlen (cp->suffix))
9400 : : ))
9401 : : break;
9402 : : }
9403 : :
9404 : : #if defined (OS2) ||defined (HAVE_DOS_BASED_FILE_SYSTEM)
9405 : : /* Look again, but case-insensitively this time. */
9406 : : if (cp < compilers)
9407 : : for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
9408 : : {
9409 : : if (/* The suffix `-' matches only the file name `-'. */
9410 : : (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
9411 : : || (strlen (cp->suffix) < length
9412 : : /* See if the suffix matches the end of NAME. */
9413 : : && ((!strcmp (cp->suffix,
9414 : : name + length - strlen (cp->suffix))
9415 : : || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
9416 : : && !strcasecmp (cp->suffix,
9417 : : name + length - strlen (cp->suffix)))
9418 : : ))
9419 : : break;
9420 : : }
9421 : : #endif
9422 : :
9423 : 547621 : if (cp >= compilers)
9424 : : {
9425 : 500537 : if (cp->spec[0] != '@')
9426 : : /* A non-alias entry: return it. */
9427 : : return cp;
9428 : :
9429 : : /* An alias entry maps a suffix to a language.
9430 : : Search for the language; pass 0 for NAME and LENGTH
9431 : : to avoid infinite recursion if language not found. */
9432 : 500523 : return lookup_compiler (NULL, 0, cp->spec + 1);
9433 : : }
9434 : : return 0;
9435 : : }
9436 : :
9437 : : static char *
9438 : 45762196 : save_string (const char *s, int len)
9439 : : {
9440 : 45762196 : char *result = XNEWVEC (char, len + 1);
9441 : :
9442 : 45762196 : gcc_checking_assert (strlen (s) >= (unsigned int) len);
9443 : 45762196 : memcpy (result, s, len);
9444 : 45762196 : result[len] = 0;
9445 : 45762196 : return result;
9446 : : }
9447 : :
9448 : :
9449 : : static inline void
9450 : 45580304 : validate_switches_from_spec (const char *spec, bool user)
9451 : : {
9452 : 45580304 : const char *p = spec;
9453 : 45580304 : char c;
9454 : 565018187 : while ((c = *p++))
9455 : 473857579 : if (c == '%'
9456 : 473857579 : && (*p == '{'
9457 : 11247088 : || *p == '<'
9458 : 10359160 : || (*p == 'W' && *++p == '{')
9459 : 10359160 : || (*p == '@' && *++p == '{')))
9460 : : /* We have a switch spec. */
9461 : 44988354 : p = validate_switches (p + 1, user, *p == '{');
9462 : 45580304 : }
9463 : :
9464 : : static void
9465 : 295976 : validate_all_switches (void)
9466 : : {
9467 : 295976 : struct compiler *comp;
9468 : 295976 : struct spec_list *spec;
9469 : :
9470 : 31965408 : for (comp = compilers; comp->spec; comp++)
9471 : 31669432 : validate_switches_from_spec (comp->spec, false);
9472 : :
9473 : : /* Look through the linked list of specs read from the specs file. */
9474 : 13910872 : for (spec = specs; spec; spec = spec->next)
9475 : 13614896 : validate_switches_from_spec (*spec->ptr_spec, spec->user_p);
9476 : :
9477 : 295976 : validate_switches_from_spec (link_command_spec, false);
9478 : 295976 : }
9479 : :
9480 : : /* Look at the switch-name that comes after START and mark as valid
9481 : : all supplied switches that match it. If BRACED, handle other
9482 : : switches after '|' and '&', and specs after ':' until ';' or '}',
9483 : : going back for more switches after ';'. Without BRACED, handle
9484 : : only one atom. Return a pointer to whatever follows the handled
9485 : : items, after the closing brace if BRACED. */
9486 : :
9487 : : static const char *
9488 : 192088426 : validate_switches (const char *start, bool user_spec, bool braced)
9489 : : {
9490 : 192088426 : const char *p = start;
9491 : 248027890 : const char *atom;
9492 : 248027890 : size_t len;
9493 : 248027890 : int i;
9494 : 248027890 : bool suffix;
9495 : 248027890 : bool starred;
9496 : :
9497 : : #define SKIP_WHITE() do { while (*p == ' ' || *p == '\t') p++; } while (0)
9498 : :
9499 : 248027890 : next_member:
9500 : 248027890 : suffix = false;
9501 : 248027890 : starred = false;
9502 : :
9503 : 274665730 : SKIP_WHITE ();
9504 : :
9505 : 248027890 : if (*p == '!')
9506 : 75473881 : p++;
9507 : :
9508 : 248027890 : SKIP_WHITE ();
9509 : 248027890 : if (*p == '.' || *p == ',')
9510 : 0 : suffix = true, p++;
9511 : :
9512 : 248027890 : atom = p;
9513 : 248027890 : while (ISIDNUM (*p) || *p == '-' || *p == '+' || *p == '='
9514 : 1641482912 : || *p == ',' || *p == '.' || *p == '@')
9515 : 1393455022 : p++;
9516 : 248027890 : len = p - atom;
9517 : :
9518 : 248027890 : if (*p == '*')
9519 : 65114720 : starred = true, p++;
9520 : :
9521 : 249211794 : SKIP_WHITE ();
9522 : :
9523 : 248027890 : if (!suffix)
9524 : : {
9525 : : /* Mark all matching switches as valid. */
9526 : 5601977236 : for (i = 0; i < n_switches; i++)
9527 : 5353949346 : if (!strncmp (switches[i].part1, atom, len)
9528 : 457011315 : && (starred || switches[i].part1[len] == '\0')
9529 : 47731068 : && (switches[i].known || user_spec))
9530 : 47729112 : switches[i].validated = true;
9531 : : }
9532 : :
9533 : 248027890 : if (!braced)
9534 : : return p;
9535 : :
9536 : 246548010 : if (*p) p++;
9537 : 246548010 : if (*p && (p[-1] == '|' || p[-1] == '&'))
9538 : 37884928 : goto next_member;
9539 : :
9540 : 208663082 : if (*p && p[-1] == ':')
9541 : : {
9542 : 2772703164 : while (*p && *p != ';' && *p != '}')
9543 : : {
9544 : 2612876121 : if (*p == '%')
9545 : : {
9546 : 245660080 : p++;
9547 : 245660080 : if (*p == '{' || *p == '<')
9548 : 144436288 : p = validate_switches (p+1, user_spec, *p == '{');
9549 : 101223792 : else if (p[0] == 'W' && p[1] == '{')
9550 : 2367808 : p = validate_switches (p+2, user_spec, true);
9551 : 98855984 : else if (p[0] == '@' && p[1] == '{')
9552 : 295976 : p = validate_switches (p+2, user_spec, true);
9553 : : }
9554 : : else
9555 : 2367216041 : p++;
9556 : : }
9557 : :
9558 : 159827043 : if (*p) p++;
9559 : 159827043 : if (*p && p[-1] == ';')
9560 : 18054536 : goto next_member;
9561 : : }
9562 : :
9563 : : return p;
9564 : : #undef SKIP_WHITE
9565 : : }
9566 : :
9567 : : struct mdswitchstr
9568 : : {
9569 : : const char *str;
9570 : : int len;
9571 : : };
9572 : :
9573 : : static struct mdswitchstr *mdswitches;
9574 : : static int n_mdswitches;
9575 : :
9576 : : /* Check whether a particular argument was used. The first time we
9577 : : canonicalize the switches to keep only the ones we care about. */
9578 : :
9579 : : struct used_arg_t
9580 : : {
9581 : : public:
9582 : : int operator () (const char *p, int len);
9583 : : void finalize ();
9584 : :
9585 : : private:
9586 : : struct mswitchstr
9587 : : {
9588 : : const char *str;
9589 : : const char *replace;
9590 : : int len;
9591 : : int rep_len;
9592 : : };
9593 : :
9594 : : mswitchstr *mswitches;
9595 : : int n_mswitches;
9596 : :
9597 : : };
9598 : :
9599 : : used_arg_t used_arg;
9600 : :
9601 : : int
9602 : 1789203 : used_arg_t::operator () (const char *p, int len)
9603 : : {
9604 : 1789203 : int i, j;
9605 : :
9606 : 1789203 : if (!mswitches)
9607 : : {
9608 : 295976 : struct mswitchstr *matches;
9609 : 295976 : const char *q;
9610 : 295976 : int cnt = 0;
9611 : :
9612 : : /* Break multilib_matches into the component strings of string
9613 : : and replacement string. */
9614 : 5031592 : for (q = multilib_matches; *q != '\0'; q++)
9615 : 4735616 : if (*q == ';')
9616 : 591952 : cnt++;
9617 : :
9618 : 295976 : matches
9619 : 295976 : = (struct mswitchstr *) alloca ((sizeof (struct mswitchstr)) * cnt);
9620 : 295976 : i = 0;
9621 : 295976 : q = multilib_matches;
9622 : 887928 : while (*q != '\0')
9623 : : {
9624 : 591952 : matches[i].str = q;
9625 : 2367808 : while (*q != ' ')
9626 : : {
9627 : 1775856 : if (*q == '\0')
9628 : : {
9629 : 0 : invalid_matches:
9630 : 0 : fatal_error (input_location, "multilib spec %qs is invalid",
9631 : : multilib_matches);
9632 : : }
9633 : 1775856 : q++;
9634 : : }
9635 : 591952 : matches[i].len = q - matches[i].str;
9636 : :
9637 : 591952 : matches[i].replace = ++q;
9638 : 2367808 : while (*q != ';' && *q != '\0')
9639 : : {
9640 : 1775856 : if (*q == ' ')
9641 : 0 : goto invalid_matches;
9642 : 1775856 : q++;
9643 : : }
9644 : 591952 : matches[i].rep_len = q - matches[i].replace;
9645 : 591952 : i++;
9646 : 591952 : if (*q == ';')
9647 : 591952 : q++;
9648 : : }
9649 : :
9650 : : /* Now build a list of the replacement string for switches that we care
9651 : : about. Make sure we allocate at least one entry. This prevents
9652 : : xmalloc from calling fatal, and prevents us from re-executing this
9653 : : block of code. */
9654 : 295976 : mswitches
9655 : 591952 : = XNEWVEC (struct mswitchstr, n_mdswitches + (n_switches ? n_switches : 1));
9656 : 6684937 : for (i = 0; i < n_switches; i++)
9657 : 6388961 : if ((switches[i].live_cond & SWITCH_IGNORE) == 0)
9658 : : {
9659 : 6388955 : int xlen = strlen (switches[i].part1);
9660 : 19154194 : for (j = 0; j < cnt; j++)
9661 : 12775511 : if (xlen == matches[j].len
9662 : 18965 : && ! strncmp (switches[i].part1, matches[j].str, xlen))
9663 : : {
9664 : 10272 : mswitches[n_mswitches].str = matches[j].replace;
9665 : 10272 : mswitches[n_mswitches].len = matches[j].rep_len;
9666 : 10272 : mswitches[n_mswitches].replace = (char *) 0;
9667 : 10272 : mswitches[n_mswitches].rep_len = 0;
9668 : 10272 : n_mswitches++;
9669 : 10272 : break;
9670 : : }
9671 : : }
9672 : :
9673 : : /* Add MULTILIB_DEFAULTS switches too, as long as they were not present
9674 : : on the command line nor any options mutually incompatible with
9675 : : them. */
9676 : 591952 : for (i = 0; i < n_mdswitches; i++)
9677 : : {
9678 : 295976 : const char *r;
9679 : :
9680 : 591952 : for (q = multilib_options; *q != '\0'; *q && q++)
9681 : : {
9682 : 295976 : while (*q == ' ')
9683 : 0 : q++;
9684 : :
9685 : 295976 : r = q;
9686 : 295976 : while (strncmp (q, mdswitches[i].str, mdswitches[i].len) != 0
9687 : 295976 : || strchr (" /", q[mdswitches[i].len]) == NULL)
9688 : : {
9689 : 0 : while (*q != ' ' && *q != '/' && *q != '\0')
9690 : 0 : q++;
9691 : 0 : if (*q != '/')
9692 : : break;
9693 : 0 : q++;
9694 : : }
9695 : :
9696 : 295976 : if (*q != ' ' && *q != '\0')
9697 : : {
9698 : 589553 : while (*r != ' ' && *r != '\0')
9699 : : {
9700 : : q = r;
9701 : 2358212 : while (*q != ' ' && *q != '/' && *q != '\0')
9702 : 1768659 : q++;
9703 : :
9704 : 589553 : if (used_arg (r, q - r))
9705 : : break;
9706 : :
9707 : 579281 : if (*q != '/')
9708 : : {
9709 : 285704 : mswitches[n_mswitches].str = mdswitches[i].str;
9710 : 285704 : mswitches[n_mswitches].len = mdswitches[i].len;
9711 : 285704 : mswitches[n_mswitches].replace = (char *) 0;
9712 : 285704 : mswitches[n_mswitches].rep_len = 0;
9713 : 285704 : n_mswitches++;
9714 : 285704 : break;
9715 : : }
9716 : :
9717 : 293577 : r = q + 1;
9718 : : }
9719 : : break;
9720 : : }
9721 : : }
9722 : : }
9723 : : }
9724 : :
9725 : 2396901 : for (i = 0; i < n_mswitches; i++)
9726 : 1217795 : if (len == mswitches[i].len && ! strncmp (p, mswitches[i].str, len))
9727 : : return 1;
9728 : :
9729 : : return 0;
9730 : : }
9731 : :
9732 : 1094 : void used_arg_t::finalize ()
9733 : : {
9734 : 1094 : XDELETEVEC (mswitches);
9735 : 1094 : mswitches = NULL;
9736 : 1094 : n_mswitches = 0;
9737 : 1094 : }
9738 : :
9739 : :
9740 : : static int
9741 : 1218894 : default_arg (const char *p, int len)
9742 : : {
9743 : 1218894 : int i;
9744 : :
9745 : 1823530 : for (i = 0; i < n_mdswitches; i++)
9746 : 1218894 : if (len == mdswitches[i].len && ! strncmp (p, mdswitches[i].str, len))
9747 : : return 1;
9748 : :
9749 : : return 0;
9750 : : }
9751 : :
9752 : : /* Use multilib_dir as key to find corresponding multilib_os_dir and
9753 : : multiarch_dir. */
9754 : :
9755 : : static void
9756 : 0 : find_multilib_os_dir_by_multilib_dir (const char *multilib_dir,
9757 : : const char **p_multilib_os_dir,
9758 : : const char **p_multiarch_dir)
9759 : : {
9760 : 0 : const char *p = multilib_select;
9761 : 0 : unsigned int this_path_len;
9762 : 0 : const char *this_path;
9763 : 0 : int ok = 0;
9764 : :
9765 : 0 : while (*p != '\0')
9766 : : {
9767 : : /* Ignore newlines. */
9768 : 0 : if (*p == '\n')
9769 : : {
9770 : 0 : ++p;
9771 : 0 : continue;
9772 : : }
9773 : :
9774 : : /* Get the initial path. */
9775 : : this_path = p;
9776 : 0 : while (*p != ' ')
9777 : : {
9778 : 0 : if (*p == '\0')
9779 : : {
9780 : 0 : fatal_error (input_location, "multilib select %qs %qs is invalid",
9781 : : multilib_select, multilib_reuse);
9782 : : }
9783 : 0 : ++p;
9784 : : }
9785 : 0 : this_path_len = p - this_path;
9786 : :
9787 : 0 : ok = 0;
9788 : :
9789 : : /* Skip any arguments, we don't care at this stage. */
9790 : 0 : while (*++p != ';');
9791 : :
9792 : 0 : if (this_path_len != 1
9793 : 0 : || this_path[0] != '.')
9794 : : {
9795 : 0 : char *new_multilib_dir = XNEWVEC (char, this_path_len + 1);
9796 : 0 : char *q;
9797 : :
9798 : 0 : strncpy (new_multilib_dir, this_path, this_path_len);
9799 : 0 : new_multilib_dir[this_path_len] = '\0';
9800 : 0 : q = strchr (new_multilib_dir, ':');
9801 : 0 : if (q != NULL)
9802 : 0 : *q = '\0';
9803 : :
9804 : 0 : if (strcmp (new_multilib_dir, multilib_dir) == 0)
9805 : 0 : ok = 1;
9806 : : }
9807 : :
9808 : : /* Found matched multilib_dir, update multilib_os_dir and
9809 : : multiarch_dir. */
9810 : 0 : if (ok)
9811 : : {
9812 : 0 : const char *q = this_path, *end = this_path + this_path_len;
9813 : :
9814 : 0 : while (q < end && *q != ':')
9815 : 0 : q++;
9816 : 0 : if (q < end)
9817 : : {
9818 : 0 : const char *q2 = q + 1, *ml_end = end;
9819 : 0 : char *new_multilib_os_dir;
9820 : :
9821 : 0 : while (q2 < end && *q2 != ':')
9822 : 0 : q2++;
9823 : 0 : if (*q2 == ':')
9824 : 0 : ml_end = q2;
9825 : 0 : if (ml_end - q == 1)
9826 : 0 : *p_multilib_os_dir = xstrdup (".");
9827 : : else
9828 : : {
9829 : 0 : new_multilib_os_dir = XNEWVEC (char, ml_end - q);
9830 : 0 : memcpy (new_multilib_os_dir, q + 1, ml_end - q - 1);
9831 : 0 : new_multilib_os_dir[ml_end - q - 1] = '\0';
9832 : 0 : *p_multilib_os_dir = new_multilib_os_dir;
9833 : : }
9834 : :
9835 : 0 : if (q2 < end && *q2 == ':')
9836 : : {
9837 : 0 : char *new_multiarch_dir = XNEWVEC (char, end - q2);
9838 : 0 : memcpy (new_multiarch_dir, q2 + 1, end - q2 - 1);
9839 : 0 : new_multiarch_dir[end - q2 - 1] = '\0';
9840 : 0 : *p_multiarch_dir = new_multiarch_dir;
9841 : : }
9842 : : break;
9843 : : }
9844 : : }
9845 : 0 : ++p;
9846 : : }
9847 : 0 : }
9848 : :
9849 : : /* Work out the subdirectory to use based on the options. The format of
9850 : : multilib_select is a list of elements. Each element is a subdirectory
9851 : : name followed by a list of options followed by a semicolon. The format
9852 : : of multilib_exclusions is the same, but without the preceding
9853 : : directory. First gcc will check the exclusions, if none of the options
9854 : : beginning with an exclamation point are present, and all of the other
9855 : : options are present, then we will ignore this completely. Passing
9856 : : that, gcc will consider each multilib_select in turn using the same
9857 : : rules for matching the options. If a match is found, that subdirectory
9858 : : will be used.
9859 : : A subdirectory name is optionally followed by a colon and the corresponding
9860 : : multiarch name. */
9861 : :
9862 : : static void
9863 : 295976 : set_multilib_dir (void)
9864 : : {
9865 : 295976 : const char *p;
9866 : 295976 : unsigned int this_path_len;
9867 : 295976 : const char *this_path, *this_arg;
9868 : 295976 : const char *start, *end;
9869 : 295976 : int not_arg;
9870 : 295976 : int ok, ndfltok, first;
9871 : :
9872 : 295976 : n_mdswitches = 0;
9873 : 295976 : start = multilib_defaults;
9874 : 295976 : while (*start == ' ' || *start == '\t')
9875 : 0 : start++;
9876 : 591952 : while (*start != '\0')
9877 : : {
9878 : 295976 : n_mdswitches++;
9879 : 1183904 : while (*start != ' ' && *start != '\t' && *start != '\0')
9880 : 887928 : start++;
9881 : 295976 : while (*start == ' ' || *start == '\t')
9882 : 0 : start++;
9883 : : }
9884 : :
9885 : 295976 : if (n_mdswitches)
9886 : : {
9887 : 295976 : int i = 0;
9888 : :
9889 : 295976 : mdswitches = XNEWVEC (struct mdswitchstr, n_mdswitches);
9890 : 295976 : for (start = multilib_defaults; *start != '\0'; start = end + 1)
9891 : : {
9892 : 295976 : while (*start == ' ' || *start == '\t')
9893 : 0 : start++;
9894 : :
9895 : 295976 : if (*start == '\0')
9896 : : break;
9897 : :
9898 : 887928 : for (end = start + 1;
9899 : 887928 : *end != ' ' && *end != '\t' && *end != '\0'; end++)
9900 : : ;
9901 : :
9902 : 295976 : obstack_grow (&multilib_obstack, start, end - start);
9903 : 295976 : obstack_1grow (&multilib_obstack, 0);
9904 : 295976 : mdswitches[i].str = XOBFINISH (&multilib_obstack, const char *);
9905 : 295976 : mdswitches[i++].len = end - start;
9906 : :
9907 : 295976 : if (*end == '\0')
9908 : : break;
9909 : : }
9910 : : }
9911 : :
9912 : 295976 : p = multilib_exclusions;
9913 : 295976 : while (*p != '\0')
9914 : : {
9915 : : /* Ignore newlines. */
9916 : 0 : if (*p == '\n')
9917 : : {
9918 : 0 : ++p;
9919 : 0 : continue;
9920 : : }
9921 : :
9922 : : /* Check the arguments. */
9923 : : ok = 1;
9924 : 0 : while (*p != ';')
9925 : : {
9926 : 0 : if (*p == '\0')
9927 : : {
9928 : 0 : invalid_exclusions:
9929 : 0 : fatal_error (input_location, "multilib exclusions %qs is invalid",
9930 : : multilib_exclusions);
9931 : : }
9932 : :
9933 : 0 : if (! ok)
9934 : : {
9935 : 0 : ++p;
9936 : 0 : continue;
9937 : : }
9938 : :
9939 : 0 : this_arg = p;
9940 : 0 : while (*p != ' ' && *p != ';')
9941 : : {
9942 : 0 : if (*p == '\0')
9943 : 0 : goto invalid_exclusions;
9944 : 0 : ++p;
9945 : : }
9946 : :
9947 : 0 : if (*this_arg != '!')
9948 : : not_arg = 0;
9949 : : else
9950 : : {
9951 : 0 : not_arg = 1;
9952 : 0 : ++this_arg;
9953 : : }
9954 : :
9955 : 0 : ok = used_arg (this_arg, p - this_arg);
9956 : 0 : if (not_arg)
9957 : 0 : ok = ! ok;
9958 : :
9959 : 0 : if (*p == ' ')
9960 : 0 : ++p;
9961 : : }
9962 : :
9963 : 0 : if (ok)
9964 : : return;
9965 : :
9966 : 0 : ++p;
9967 : : }
9968 : :
9969 : 295976 : first = 1;
9970 : 295976 : p = multilib_select;
9971 : :
9972 : : /* Append multilib reuse rules if any. With those rules, we can reuse
9973 : : one multilib for certain different options sets. */
9974 : 295976 : if (strlen (multilib_reuse) > 0)
9975 : 0 : p = concat (p, multilib_reuse, NULL);
9976 : :
9977 : 599825 : while (*p != '\0')
9978 : : {
9979 : : /* Ignore newlines. */
9980 : 599825 : if (*p == '\n')
9981 : : {
9982 : 0 : ++p;
9983 : 0 : continue;
9984 : : }
9985 : :
9986 : : /* Get the initial path. */
9987 : : this_path = p;
9988 : 4222394 : while (*p != ' ')
9989 : : {
9990 : 3622569 : if (*p == '\0')
9991 : : {
9992 : 0 : invalid_select:
9993 : 0 : fatal_error (input_location, "multilib select %qs %qs is invalid",
9994 : : multilib_select, multilib_reuse);
9995 : : }
9996 : 3622569 : ++p;
9997 : : }
9998 : 599825 : this_path_len = p - this_path;
9999 : :
10000 : : /* Check the arguments. */
10001 : 599825 : ok = 1;
10002 : 599825 : ndfltok = 1;
10003 : 599825 : ++p;
10004 : 1799475 : while (*p != ';')
10005 : : {
10006 : 1199650 : if (*p == '\0')
10007 : 0 : goto invalid_select;
10008 : :
10009 : 1199650 : if (! ok)
10010 : : {
10011 : 0 : ++p;
10012 : 0 : continue;
10013 : : }
10014 : :
10015 : 5694401 : this_arg = p;
10016 : 5694401 : while (*p != ' ' && *p != ';')
10017 : : {
10018 : 4494751 : if (*p == '\0')
10019 : 0 : goto invalid_select;
10020 : 4494751 : ++p;
10021 : : }
10022 : :
10023 : 1199650 : if (*this_arg != '!')
10024 : : not_arg = 0;
10025 : : else
10026 : : {
10027 : 895801 : not_arg = 1;
10028 : 895801 : ++this_arg;
10029 : : }
10030 : :
10031 : : /* If this is a default argument, we can just ignore it.
10032 : : This is true even if this_arg begins with '!'. Beginning
10033 : : with '!' does not mean that this argument is necessarily
10034 : : inappropriate for this library: it merely means that
10035 : : there is a more specific library which uses this
10036 : : argument. If this argument is a default, we need not
10037 : : consider that more specific library. */
10038 : 1199650 : ok = used_arg (this_arg, p - this_arg);
10039 : 1199650 : if (not_arg)
10040 : 895801 : ok = ! ok;
10041 : :
10042 : 1199650 : if (! ok)
10043 : 311722 : ndfltok = 0;
10044 : :
10045 : 1199650 : if (default_arg (this_arg, p - this_arg))
10046 : 599825 : ok = 1;
10047 : :
10048 : 1199650 : if (*p == ' ')
10049 : 599825 : ++p;
10050 : : }
10051 : :
10052 : 599825 : if (ok && first)
10053 : : {
10054 : 295976 : if (this_path_len != 1
10055 : 288103 : || this_path[0] != '.')
10056 : : {
10057 : 7873 : char *new_multilib_dir = XNEWVEC (char, this_path_len + 1);
10058 : 7873 : char *q;
10059 : :
10060 : 7873 : strncpy (new_multilib_dir, this_path, this_path_len);
10061 : 7873 : new_multilib_dir[this_path_len] = '\0';
10062 : 7873 : q = strchr (new_multilib_dir, ':');
10063 : 7873 : if (q != NULL)
10064 : 7873 : *q = '\0';
10065 : 7873 : multilib_dir = new_multilib_dir;
10066 : : }
10067 : : first = 0;
10068 : : }
10069 : :
10070 : 599825 : if (ndfltok)
10071 : : {
10072 : 295976 : const char *q = this_path, *end = this_path + this_path_len;
10073 : :
10074 : 887928 : while (q < end && *q != ':')
10075 : 591952 : q++;
10076 : 295976 : if (q < end)
10077 : : {
10078 : 295976 : const char *q2 = q + 1, *ml_end = end;
10079 : 295976 : char *new_multilib_os_dir;
10080 : :
10081 : 2648038 : while (q2 < end && *q2 != ':')
10082 : 2352062 : q2++;
10083 : 295976 : if (*q2 == ':')
10084 : 0 : ml_end = q2;
10085 : 295976 : if (ml_end - q == 1)
10086 : 0 : multilib_os_dir = xstrdup (".");
10087 : : else
10088 : : {
10089 : 295976 : new_multilib_os_dir = XNEWVEC (char, ml_end - q);
10090 : 295976 : memcpy (new_multilib_os_dir, q + 1, ml_end - q - 1);
10091 : 295976 : new_multilib_os_dir[ml_end - q - 1] = '\0';
10092 : 295976 : multilib_os_dir = new_multilib_os_dir;
10093 : : }
10094 : :
10095 : 295976 : if (q2 < end && *q2 == ':')
10096 : : {
10097 : 0 : char *new_multiarch_dir = XNEWVEC (char, end - q2);
10098 : 0 : memcpy (new_multiarch_dir, q2 + 1, end - q2 - 1);
10099 : 0 : new_multiarch_dir[end - q2 - 1] = '\0';
10100 : 0 : multiarch_dir = new_multiarch_dir;
10101 : : }
10102 : : break;
10103 : : }
10104 : : }
10105 : :
10106 : 303849 : ++p;
10107 : : }
10108 : :
10109 : 591952 : multilib_dir =
10110 : 295976 : targetm_common.compute_multilib (
10111 : : switches,
10112 : : n_switches,
10113 : : multilib_dir,
10114 : : multilib_defaults,
10115 : : multilib_select,
10116 : : multilib_matches,
10117 : : multilib_exclusions,
10118 : : multilib_reuse);
10119 : :
10120 : 295976 : if (multilib_dir == NULL && multilib_os_dir != NULL
10121 : 288103 : && strcmp (multilib_os_dir, ".") == 0)
10122 : : {
10123 : 0 : free (CONST_CAST (char *, multilib_os_dir));
10124 : 0 : multilib_os_dir = NULL;
10125 : : }
10126 : 295976 : else if (multilib_dir != NULL && multilib_os_dir == NULL)
10127 : : {
10128 : : /* Give second chance to search matched multilib_os_dir again by matching
10129 : : the multilib_dir since some target may use TARGET_COMPUTE_MULTILIB
10130 : : hook rather than the builtin way. */
10131 : 0 : find_multilib_os_dir_by_multilib_dir (multilib_dir, &multilib_os_dir,
10132 : : &multiarch_dir);
10133 : :
10134 : 0 : if (multilib_os_dir == NULL)
10135 : 0 : multilib_os_dir = multilib_dir;
10136 : : }
10137 : : }
10138 : :
10139 : : /* Print out the multiple library subdirectory selection
10140 : : information. This prints out a series of lines. Each line looks
10141 : : like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
10142 : : required. Only the desired options are printed out, the negative
10143 : : matches. The options are print without a leading dash. There are
10144 : : no spaces to make it easy to use the information in the shell.
10145 : : Each subdirectory is printed only once. This assumes the ordering
10146 : : generated by the genmultilib script. Also, we leave out ones that match
10147 : : the exclusions. */
10148 : :
10149 : : static void
10150 : 4811 : print_multilib_info (void)
10151 : : {
10152 : 4811 : const char *p = multilib_select;
10153 : 4811 : const char *last_path = 0, *this_path;
10154 : 4811 : int skip;
10155 : 4811 : int not_arg;
10156 : 4811 : unsigned int last_path_len = 0;
10157 : :
10158 : 19244 : while (*p != '\0')
10159 : : {
10160 : 14433 : skip = 0;
10161 : : /* Ignore newlines. */
10162 : 14433 : if (*p == '\n')
10163 : : {
10164 : 0 : ++p;
10165 : 0 : continue;
10166 : : }
10167 : :
10168 : : /* Get the initial path. */
10169 : : this_path = p;
10170 : 115464 : while (*p != ' ')
10171 : : {
10172 : 101031 : if (*p == '\0')
10173 : : {
10174 : 0 : invalid_select:
10175 : 0 : fatal_error (input_location,
10176 : : "multilib select %qs is invalid", multilib_select);
10177 : : }
10178 : :
10179 : 101031 : ++p;
10180 : : }
10181 : :
10182 : : /* When --disable-multilib was used but target defines
10183 : : MULTILIB_OSDIRNAMES, entries starting with .: (and not starting
10184 : : with .:: for multiarch configurations) are there just to find
10185 : : multilib_os_dir, so skip them from output. */
10186 : 14433 : if (this_path[0] == '.' && this_path[1] == ':' && this_path[2] != ':')
10187 : 14433 : skip = 1;
10188 : :
10189 : : /* Check for matches with the multilib_exclusions. We don't bother
10190 : : with the '!' in either list. If any of the exclusion rules match
10191 : : all of its options with the select rule, we skip it. */
10192 : 14433 : {
10193 : 14433 : const char *e = multilib_exclusions;
10194 : 14433 : const char *this_arg;
10195 : :
10196 : 14433 : while (*e != '\0')
10197 : : {
10198 : 0 : int m = 1;
10199 : : /* Ignore newlines. */
10200 : 0 : if (*e == '\n')
10201 : : {
10202 : 0 : ++e;
10203 : 0 : continue;
10204 : : }
10205 : :
10206 : : /* Check the arguments. */
10207 : 0 : while (*e != ';')
10208 : : {
10209 : 0 : const char *q;
10210 : 0 : int mp = 0;
10211 : :
10212 : 0 : if (*e == '\0')
10213 : : {
10214 : 0 : invalid_exclusion:
10215 : 0 : fatal_error (input_location,
10216 : : "multilib exclusion %qs is invalid",
10217 : : multilib_exclusions);
10218 : : }
10219 : :
10220 : 0 : if (! m)
10221 : : {
10222 : 0 : ++e;
10223 : 0 : continue;
10224 : : }
10225 : :
10226 : : this_arg = e;
10227 : :
10228 : 0 : while (*e != ' ' && *e != ';')
10229 : : {
10230 : 0 : if (*e == '\0')
10231 : 0 : goto invalid_exclusion;
10232 : 0 : ++e;
10233 : : }
10234 : :
10235 : 0 : q = p + 1;
10236 : 0 : while (*q != ';')
10237 : : {
10238 : 0 : const char *arg;
10239 : 0 : int len = e - this_arg;
10240 : :
10241 : 0 : if (*q == '\0')
10242 : 0 : goto invalid_select;
10243 : :
10244 : : arg = q;
10245 : :
10246 : 0 : while (*q != ' ' && *q != ';')
10247 : : {
10248 : 0 : if (*q == '\0')
10249 : 0 : goto invalid_select;
10250 : 0 : ++q;
10251 : : }
10252 : :
10253 : 0 : if (! strncmp (arg, this_arg,
10254 : 0 : (len < q - arg) ? q - arg : len)
10255 : 0 : || default_arg (this_arg, e - this_arg))
10256 : : {
10257 : : mp = 1;
10258 : : break;
10259 : : }
10260 : :
10261 : 0 : if (*q == ' ')
10262 : 0 : ++q;
10263 : : }
10264 : :
10265 : 0 : if (! mp)
10266 : 0 : m = 0;
10267 : :
10268 : 0 : if (*e == ' ')
10269 : 0 : ++e;
10270 : : }
10271 : :
10272 : 0 : if (m)
10273 : : {
10274 : : skip = 1;
10275 : : break;
10276 : : }
10277 : :
10278 : 0 : if (*e != '\0')
10279 : 0 : ++e;
10280 : : }
10281 : : }
10282 : :
10283 : 14433 : if (! skip)
10284 : : {
10285 : : /* If this is a duplicate, skip it. */
10286 : 28866 : skip = (last_path != 0
10287 : 9622 : && (unsigned int) (p - this_path) == last_path_len
10288 : 14433 : && ! filename_ncmp (last_path, this_path, last_path_len));
10289 : :
10290 : 14433 : last_path = this_path;
10291 : 14433 : last_path_len = p - this_path;
10292 : : }
10293 : :
10294 : : /* If all required arguments are default arguments, and no default
10295 : : arguments appear in the ! argument list, then we can skip it.
10296 : : We will already have printed a directory identical to this one
10297 : : which does not require that default argument. */
10298 : 14433 : if (! skip)
10299 : : {
10300 : 14433 : const char *q;
10301 : 14433 : bool default_arg_ok = false;
10302 : :
10303 : 14433 : q = p + 1;
10304 : 24055 : while (*q != ';')
10305 : : {
10306 : 19244 : const char *arg;
10307 : :
10308 : 19244 : if (*q == '\0')
10309 : 0 : goto invalid_select;
10310 : :
10311 : 19244 : if (*q == '!')
10312 : : {
10313 : 14433 : not_arg = 1;
10314 : 14433 : q++;
10315 : : }
10316 : : else
10317 : : not_arg = 0;
10318 : 19244 : arg = q;
10319 : :
10320 : 76976 : while (*q != ' ' && *q != ';')
10321 : : {
10322 : 57732 : if (*q == '\0')
10323 : 0 : goto invalid_select;
10324 : 57732 : ++q;
10325 : : }
10326 : :
10327 : 19244 : if (default_arg (arg, q - arg))
10328 : : {
10329 : : /* Stop checking if any default arguments appeared in not
10330 : : list. */
10331 : 14433 : if (not_arg)
10332 : : {
10333 : : default_arg_ok = false;
10334 : : break;
10335 : : }
10336 : :
10337 : : default_arg_ok = true;
10338 : : }
10339 : 4811 : else if (!not_arg)
10340 : : {
10341 : : /* Stop checking if any required argument is not provided by
10342 : : default arguments. */
10343 : : default_arg_ok = false;
10344 : : break;
10345 : : }
10346 : :
10347 : 9622 : if (*q == ' ')
10348 : 4811 : ++q;
10349 : : }
10350 : :
10351 : : /* Make sure all default argument is OK for this multi-lib set. */
10352 : 14433 : if (default_arg_ok)
10353 : : skip = 1;
10354 : : else
10355 : : skip = 0;
10356 : : }
10357 : :
10358 : : if (! skip)
10359 : : {
10360 : : const char *p1;
10361 : :
10362 : 24055 : for (p1 = last_path; p1 < p && *p1 != ':'; p1++)
10363 : 14433 : putchar (*p1);
10364 : 9622 : putchar (';');
10365 : : }
10366 : :
10367 : 14433 : ++p;
10368 : 72165 : while (*p != ';')
10369 : : {
10370 : 57732 : int use_arg;
10371 : :
10372 : 57732 : if (*p == '\0')
10373 : 0 : goto invalid_select;
10374 : :
10375 : 57732 : if (skip)
10376 : : {
10377 : 38488 : ++p;
10378 : 38488 : continue;
10379 : : }
10380 : :
10381 : 19244 : use_arg = *p != '!';
10382 : :
10383 : 19244 : if (use_arg)
10384 : 4811 : putchar ('@');
10385 : :
10386 : 91409 : while (*p != ' ' && *p != ';')
10387 : : {
10388 : 72165 : if (*p == '\0')
10389 : 0 : goto invalid_select;
10390 : 72165 : if (use_arg)
10391 : 14433 : putchar (*p);
10392 : 72165 : ++p;
10393 : : }
10394 : :
10395 : 19244 : if (*p == ' ')
10396 : 9622 : ++p;
10397 : : }
10398 : :
10399 : 14433 : if (! skip)
10400 : : {
10401 : : /* If there are extra options, print them now. */
10402 : 9622 : if (multilib_extra && *multilib_extra)
10403 : : {
10404 : : int print_at = true;
10405 : : const char *q;
10406 : :
10407 : 0 : for (q = multilib_extra; *q != '\0'; q++)
10408 : : {
10409 : 0 : if (*q == ' ')
10410 : : print_at = true;
10411 : : else
10412 : : {
10413 : 0 : if (print_at)
10414 : 0 : putchar ('@');
10415 : 0 : putchar (*q);
10416 : 0 : print_at = false;
10417 : : }
10418 : : }
10419 : : }
10420 : :
10421 : 9622 : putchar ('\n');
10422 : : }
10423 : :
10424 : 14433 : ++p;
10425 : : }
10426 : 4811 : }
10427 : :
10428 : : /* getenv built-in spec function.
10429 : :
10430 : : Returns the value of the environment variable given by its first argument,
10431 : : concatenated with the second argument. If the variable is not defined, a
10432 : : fatal error is issued unless such undefs are internally allowed, in which
10433 : : case the variable name prefixed by a '/' is used as the variable value.
10434 : :
10435 : : The leading '/' allows using the result at a spot where a full path would
10436 : : normally be expected and when the actual value doesn't really matter since
10437 : : undef vars are allowed. */
10438 : :
10439 : : static const char *
10440 : 0 : getenv_spec_function (int argc, const char **argv)
10441 : : {
10442 : 0 : const char *value;
10443 : 0 : const char *varname;
10444 : :
10445 : 0 : char *result;
10446 : 0 : char *ptr;
10447 : 0 : size_t len;
10448 : :
10449 : 0 : if (argc != 2)
10450 : : return NULL;
10451 : :
10452 : 0 : varname = argv[0];
10453 : 0 : value = env.get (varname);
10454 : :
10455 : : /* If the variable isn't defined and this is allowed, craft our expected
10456 : : return value. Assume variable names used in specs strings don't contain
10457 : : any active spec character so don't need escaping. */
10458 : 0 : if (!value && spec_undefvar_allowed)
10459 : : {
10460 : 0 : result = XNEWVAR (char, strlen(varname) + 2);
10461 : 0 : sprintf (result, "/%s", varname);
10462 : 0 : return result;
10463 : : }
10464 : :
10465 : 0 : if (!value)
10466 : 0 : fatal_error (input_location,
10467 : : "environment variable %qs not defined", varname);
10468 : :
10469 : : /* We have to escape every character of the environment variable so
10470 : : they are not interpreted as active spec characters. A
10471 : : particularly painful case is when we are reading a variable
10472 : : holding a windows path complete with \ separators. */
10473 : 0 : len = strlen (value) * 2 + strlen (argv[1]) + 1;
10474 : 0 : result = XNEWVAR (char, len);
10475 : 0 : for (ptr = result; *value; ptr += 2)
10476 : : {
10477 : 0 : ptr[0] = '\\';
10478 : 0 : ptr[1] = *value++;
10479 : : }
10480 : :
10481 : 0 : strcpy (ptr, argv[1]);
10482 : :
10483 : 0 : return result;
10484 : : }
10485 : :
10486 : : /* if-exists built-in spec function.
10487 : :
10488 : : Checks to see if the file specified by the absolute pathname in
10489 : : ARGS exists. Returns that pathname if found.
10490 : :
10491 : : The usual use for this function is to check for a library file
10492 : : (whose name has been expanded with %s). */
10493 : :
10494 : : static const char *
10495 : 0 : if_exists_spec_function (int argc, const char **argv)
10496 : : {
10497 : : /* Must have only one argument. */
10498 : 0 : if (argc == 1 && IS_ABSOLUTE_PATH (argv[0]) && ! access (argv[0], R_OK))
10499 : 0 : return argv[0];
10500 : :
10501 : : return NULL;
10502 : : }
10503 : :
10504 : : /* if-exists-else built-in spec function.
10505 : :
10506 : : This is like if-exists, but takes an additional argument which
10507 : : is returned if the first argument does not exist. */
10508 : :
10509 : : static const char *
10510 : 0 : if_exists_else_spec_function (int argc, const char **argv)
10511 : : {
10512 : : /* Must have exactly two arguments. */
10513 : 0 : if (argc != 2)
10514 : : return NULL;
10515 : :
10516 : 0 : if (IS_ABSOLUTE_PATH (argv[0]) && ! access (argv[0], R_OK))
10517 : 0 : return argv[0];
10518 : :
10519 : 0 : return argv[1];
10520 : : }
10521 : :
10522 : : /* if-exists-then-else built-in spec function.
10523 : :
10524 : : Checks to see if the file specified by the absolute pathname in
10525 : : the first arg exists. Returns the second arg if so, otherwise returns
10526 : : the third arg if it is present. */
10527 : :
10528 : : static const char *
10529 : 0 : if_exists_then_else_spec_function (int argc, const char **argv)
10530 : : {
10531 : :
10532 : : /* Must have two or three arguments. */
10533 : 0 : if (argc != 2 && argc != 3)
10534 : : return NULL;
10535 : :
10536 : 0 : if (IS_ABSOLUTE_PATH (argv[0]) && ! access (argv[0], R_OK))
10537 : 0 : return argv[1];
10538 : :
10539 : 0 : if (argc == 3)
10540 : 0 : return argv[2];
10541 : :
10542 : : return NULL;
10543 : : }
10544 : :
10545 : : /* sanitize built-in spec function.
10546 : :
10547 : : This returns non-NULL, if sanitizing address, thread or
10548 : : any of the undefined behavior sanitizers. */
10549 : :
10550 : : static const char *
10551 : 848835 : sanitize_spec_function (int argc, const char **argv)
10552 : : {
10553 : 848835 : if (argc != 1)
10554 : : return NULL;
10555 : :
10556 : 848835 : if (strcmp (argv[0], "address") == 0)
10557 : 374600 : return (flag_sanitize & SANITIZE_USER_ADDRESS) ? "" : NULL;
10558 : 660205 : if (strcmp (argv[0], "hwaddress") == 0)
10559 : 376918 : return (flag_sanitize & SANITIZE_USER_HWADDRESS) ? "" : NULL;
10560 : 471575 : if (strcmp (argv[0], "kernel-address") == 0)
10561 : 0 : return (flag_sanitize & SANITIZE_KERNEL_ADDRESS) ? "" : NULL;
10562 : 471575 : if (strcmp (argv[0], "kernel-hwaddress") == 0)
10563 : 0 : return (flag_sanitize & SANITIZE_KERNEL_HWADDRESS) ? "" : NULL;
10564 : 471575 : if (strcmp (argv[0], "thread") == 0)
10565 : 376704 : return (flag_sanitize & SANITIZE_THREAD) ? "" : NULL;
10566 : 282945 : if (strcmp (argv[0], "undefined") == 0)
10567 : 94315 : return ((flag_sanitize
10568 : 94315 : & ~flag_sanitize_trap
10569 : 94315 : & (SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT)))
10570 : 186821 : ? "" : NULL;
10571 : 188630 : if (strcmp (argv[0], "leak") == 0)
10572 : 188630 : return ((flag_sanitize
10573 : 188630 : & (SANITIZE_ADDRESS | SANITIZE_LEAK | SANITIZE_THREAD))
10574 : 377260 : == SANITIZE_LEAK) ? "" : NULL;
10575 : : return NULL;
10576 : : }
10577 : :
10578 : : /* replace-outfile built-in spec function.
10579 : :
10580 : : This looks for the first argument in the outfiles array's name and
10581 : : replaces it with the second argument. */
10582 : :
10583 : : static const char *
10584 : 0 : replace_outfile_spec_function (int argc, const char **argv)
10585 : : {
10586 : 0 : int i;
10587 : : /* Must have exactly two arguments. */
10588 : 0 : if (argc != 2)
10589 : 0 : abort ();
10590 : :
10591 : 0 : for (i = 0; i < n_infiles; i++)
10592 : : {
10593 : 0 : if (outfiles[i] && !filename_cmp (outfiles[i], argv[0]))
10594 : 0 : outfiles[i] = xstrdup (argv[1]);
10595 : : }
10596 : 0 : return NULL;
10597 : : }
10598 : :
10599 : : /* remove-outfile built-in spec function.
10600 : : *
10601 : : * This looks for the first argument in the outfiles array's name and
10602 : : * removes it. */
10603 : :
10604 : : static const char *
10605 : 0 : remove_outfile_spec_function (int argc, const char **argv)
10606 : : {
10607 : 0 : int i;
10608 : : /* Must have exactly one argument. */
10609 : 0 : if (argc != 1)
10610 : 0 : abort ();
10611 : :
10612 : 0 : for (i = 0; i < n_infiles; i++)
10613 : : {
10614 : 0 : if (outfiles[i] && !filename_cmp (outfiles[i], argv[0]))
10615 : 0 : outfiles[i] = NULL;
10616 : : }
10617 : 0 : return NULL;
10618 : : }
10619 : :
10620 : : /* Given two version numbers, compares the two numbers.
10621 : : A version number must match the regular expression
10622 : : ([1-9][0-9]*|0)(\.([1-9][0-9]*|0))*
10623 : : */
10624 : : static int
10625 : 0 : compare_version_strings (const char *v1, const char *v2)
10626 : : {
10627 : 0 : int rresult;
10628 : 0 : regex_t r;
10629 : :
10630 : 0 : if (regcomp (&r, "^([1-9][0-9]*|0)(\\.([1-9][0-9]*|0))*$",
10631 : : REG_EXTENDED | REG_NOSUB) != 0)
10632 : 0 : abort ();
10633 : 0 : rresult = regexec (&r, v1, 0, NULL, 0);
10634 : 0 : if (rresult == REG_NOMATCH)
10635 : 0 : fatal_error (input_location, "invalid version number %qs", v1);
10636 : 0 : else if (rresult != 0)
10637 : 0 : abort ();
10638 : 0 : rresult = regexec (&r, v2, 0, NULL, 0);
10639 : 0 : if (rresult == REG_NOMATCH)
10640 : 0 : fatal_error (input_location, "invalid version number %qs", v2);
10641 : 0 : else if (rresult != 0)
10642 : 0 : abort ();
10643 : :
10644 : 0 : return strverscmp (v1, v2);
10645 : : }
10646 : :
10647 : :
10648 : : /* version_compare built-in spec function.
10649 : :
10650 : : This takes an argument of the following form:
10651 : :
10652 : : <comparison-op> <arg1> [<arg2>] <switch> <result>
10653 : :
10654 : : and produces "result" if the comparison evaluates to true,
10655 : : and nothing if it doesn't.
10656 : :
10657 : : The supported <comparison-op> values are:
10658 : :
10659 : : >= true if switch is a later (or same) version than arg1
10660 : : !> opposite of >=
10661 : : < true if switch is an earlier version than arg1
10662 : : !< opposite of <
10663 : : >< true if switch is arg1 or later, and earlier than arg2
10664 : : <> true if switch is earlier than arg1 or is arg2 or later
10665 : :
10666 : : If the switch is not present, the condition is false unless
10667 : : the first character of the <comparison-op> is '!'.
10668 : :
10669 : : For example,
10670 : : %:version-compare(>= 10.3 mmacosx-version-min= -lmx)
10671 : : adds -lmx if -mmacosx-version-min=10.3.9 was passed. */
10672 : :
10673 : : static const char *
10674 : 0 : version_compare_spec_function (int argc, const char **argv)
10675 : : {
10676 : 0 : int comp1, comp2;
10677 : 0 : size_t switch_len;
10678 : 0 : const char *switch_value = NULL;
10679 : 0 : int nargs = 1, i;
10680 : 0 : bool result;
10681 : :
10682 : 0 : if (argc < 3)
10683 : 0 : fatal_error (input_location, "too few arguments to %%:version-compare");
10684 : 0 : if (argv[0][0] == '\0')
10685 : 0 : abort ();
10686 : 0 : if ((argv[0][1] == '<' || argv[0][1] == '>') && argv[0][0] != '!')
10687 : 0 : nargs = 2;
10688 : 0 : if (argc != nargs + 3)
10689 : 0 : fatal_error (input_location, "too many arguments to %%:version-compare");
10690 : :
10691 : 0 : switch_len = strlen (argv[nargs + 1]);
10692 : 0 : for (i = 0; i < n_switches; i++)
10693 : 0 : if (!strncmp (switches[i].part1, argv[nargs + 1], switch_len)
10694 : 0 : && check_live_switch (i, switch_len))
10695 : 0 : switch_value = switches[i].part1 + switch_len;
10696 : :
10697 : 0 : if (switch_value == NULL)
10698 : : comp1 = comp2 = -1;
10699 : : else
10700 : : {
10701 : 0 : comp1 = compare_version_strings (switch_value, argv[1]);
10702 : 0 : if (nargs == 2)
10703 : 0 : comp2 = compare_version_strings (switch_value, argv[2]);
10704 : : else
10705 : : comp2 = -1; /* This value unused. */
10706 : : }
10707 : :
10708 : 0 : switch (argv[0][0] << 8 | argv[0][1])
10709 : : {
10710 : 0 : case '>' << 8 | '=':
10711 : 0 : result = comp1 >= 0;
10712 : 0 : break;
10713 : 0 : case '!' << 8 | '<':
10714 : 0 : result = comp1 >= 0 || switch_value == NULL;
10715 : 0 : break;
10716 : 0 : case '<' << 8:
10717 : 0 : result = comp1 < 0;
10718 : 0 : break;
10719 : 0 : case '!' << 8 | '>':
10720 : 0 : result = comp1 < 0 || switch_value == NULL;
10721 : 0 : break;
10722 : 0 : case '>' << 8 | '<':
10723 : 0 : result = comp1 >= 0 && comp2 < 0;
10724 : 0 : break;
10725 : 0 : case '<' << 8 | '>':
10726 : 0 : result = comp1 < 0 || comp2 >= 0;
10727 : 0 : break;
10728 : :
10729 : 0 : default:
10730 : 0 : fatal_error (input_location,
10731 : : "unknown operator %qs in %%:version-compare", argv[0]);
10732 : : }
10733 : 0 : if (! result)
10734 : : return NULL;
10735 : :
10736 : 0 : return argv[nargs + 2];
10737 : : }
10738 : :
10739 : : /* %:include builtin spec function. This differs from %include in that it
10740 : : can be nested inside a spec, and thus be conditionalized. It takes
10741 : : one argument, the filename, and looks for it in the startfile path.
10742 : : The result is always NULL, i.e. an empty expansion. */
10743 : :
10744 : : static const char *
10745 : 30275 : include_spec_function (int argc, const char **argv)
10746 : : {
10747 : 30275 : char *file;
10748 : :
10749 : 30275 : if (argc != 1)
10750 : 0 : abort ();
10751 : :
10752 : 30275 : file = find_a_file (&startfile_prefixes, argv[0], R_OK, true);
10753 : 30275 : read_specs (file ? file : argv[0], false, false);
10754 : :
10755 : 30275 : return NULL;
10756 : : }
10757 : :
10758 : : /* %:find-file spec function. This function replaces its argument by
10759 : : the file found through find_file, that is the -print-file-name gcc
10760 : : program option. */
10761 : : static const char *
10762 : 0 : find_file_spec_function (int argc, const char **argv)
10763 : : {
10764 : 0 : const char *file;
10765 : :
10766 : 0 : if (argc != 1)
10767 : 0 : abort ();
10768 : :
10769 : 0 : file = find_file (argv[0]);
10770 : 0 : return file;
10771 : : }
10772 : :
10773 : :
10774 : : /* %:find-plugindir spec function. This function replaces its argument
10775 : : by the -iplugindir=<dir> option. `dir' is found through find_file, that
10776 : : is the -print-file-name gcc program option. */
10777 : : static const char *
10778 : 384 : find_plugindir_spec_function (int argc, const char **argv ATTRIBUTE_UNUSED)
10779 : : {
10780 : 384 : const char *option;
10781 : :
10782 : 384 : if (argc != 0)
10783 : 0 : abort ();
10784 : :
10785 : 384 : option = concat ("-iplugindir=", find_file ("plugin"), NULL);
10786 : 384 : return option;
10787 : : }
10788 : :
10789 : :
10790 : : /* %:print-asm-header spec function. Print a banner to say that the
10791 : : following output is from the assembler. */
10792 : :
10793 : : static const char *
10794 : 0 : print_asm_header_spec_function (int arg ATTRIBUTE_UNUSED,
10795 : : const char **argv ATTRIBUTE_UNUSED)
10796 : : {
10797 : 0 : printf (_("Assembler options\n=================\n\n"));
10798 : 0 : printf (_("Use \"-Wa,OPTION\" to pass \"OPTION\" to the assembler.\n\n"));
10799 : 0 : fflush (stdout);
10800 : 0 : return NULL;
10801 : : }
10802 : :
10803 : : /* Get a random number for -frandom-seed */
10804 : :
10805 : : static unsigned HOST_WIDE_INT
10806 : 623 : get_random_number (void)
10807 : : {
10808 : 623 : unsigned HOST_WIDE_INT ret = 0;
10809 : 623 : int fd;
10810 : :
10811 : 623 : fd = open ("/dev/urandom", O_RDONLY);
10812 : 623 : if (fd >= 0)
10813 : : {
10814 : 623 : read (fd, &ret, sizeof (HOST_WIDE_INT));
10815 : 623 : close (fd);
10816 : 623 : if (ret)
10817 : : return ret;
10818 : : }
10819 : :
10820 : : /* Get some more or less random data. */
10821 : : #ifdef HAVE_GETTIMEOFDAY
10822 : 0 : {
10823 : 0 : struct timeval tv;
10824 : :
10825 : 0 : gettimeofday (&tv, NULL);
10826 : 0 : ret = tv.tv_sec * 1000 + tv.tv_usec / 1000;
10827 : : }
10828 : : #else
10829 : : {
10830 : : time_t now = time (NULL);
10831 : :
10832 : : if (now != (time_t)-1)
10833 : : ret = (unsigned) now;
10834 : : }
10835 : : #endif
10836 : :
10837 : 0 : return ret ^ getpid ();
10838 : : }
10839 : :
10840 : : /* %:compare-debug-dump-opt spec function. Save the last argument,
10841 : : expected to be the last -fdump-final-insns option, or generate a
10842 : : temporary. */
10843 : :
10844 : : static const char *
10845 : 1239 : compare_debug_dump_opt_spec_function (int arg,
10846 : : const char **argv ATTRIBUTE_UNUSED)
10847 : : {
10848 : 1239 : char *ret;
10849 : 1239 : char *name;
10850 : 1239 : int which;
10851 : 1239 : static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
10852 : :
10853 : 1239 : if (arg != 0)
10854 : 0 : fatal_error (input_location,
10855 : : "too many arguments to %%:compare-debug-dump-opt");
10856 : :
10857 : 1239 : do_spec_2 ("%{fdump-final-insns=*:%*}", NULL);
10858 : 1239 : do_spec_1 (" ", 0, NULL);
10859 : :
10860 : 1239 : if (argbuf.length () > 0
10861 : 1239 : && strcmp (argv[argbuf.length () - 1], ".") != 0)
10862 : : {
10863 : 0 : if (!compare_debug)
10864 : : return NULL;
10865 : :
10866 : 0 : name = xstrdup (argv[argbuf.length () - 1]);
10867 : 0 : ret = NULL;
10868 : : }
10869 : : else
10870 : : {
10871 : 1239 : if (argbuf.length () > 0)
10872 : 6 : do_spec_2 ("%B.gkd", NULL);
10873 : 1233 : else if (!compare_debug)
10874 : : return NULL;
10875 : : else
10876 : 1233 : do_spec_2 ("%{!save-temps*:%g.gkd}%{save-temps*:%B.gkd}", NULL);
10877 : :
10878 : 1239 : do_spec_1 (" ", 0, NULL);
10879 : :
10880 : 1239 : gcc_assert (argbuf.length () > 0);
10881 : :
10882 : 1239 : name = xstrdup (argbuf.last ());
10883 : :
10884 : 1239 : char *arg = quote_spec (xstrdup (name));
10885 : 1239 : ret = concat ("-fdump-final-insns=", arg, NULL);
10886 : 1239 : free (arg);
10887 : : }
10888 : :
10889 : 1239 : which = compare_debug < 0;
10890 : 1239 : debug_check_temp_file[which] = name;
10891 : :
10892 : 1239 : if (!which)
10893 : : {
10894 : 623 : unsigned HOST_WIDE_INT value = get_random_number ();
10895 : :
10896 : 623 : sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
10897 : : }
10898 : :
10899 : 1239 : if (*random_seed)
10900 : : {
10901 : 1239 : char *tmp = ret;
10902 : 1239 : ret = concat ("%{!frandom-seed=*:-frandom-seed=", random_seed, "} ",
10903 : : ret, NULL);
10904 : 1239 : free (tmp);
10905 : : }
10906 : :
10907 : 1239 : if (which)
10908 : 616 : *random_seed = 0;
10909 : :
10910 : : return ret;
10911 : : }
10912 : :
10913 : : /* %:compare-debug-self-opt spec function. Expands to the options
10914 : : that are to be passed in the second compilation of
10915 : : compare-debug. */
10916 : :
10917 : : static const char *
10918 : 1244 : compare_debug_self_opt_spec_function (int arg,
10919 : : const char **argv ATTRIBUTE_UNUSED)
10920 : : {
10921 : 1244 : if (arg != 0)
10922 : 0 : fatal_error (input_location,
10923 : : "too many arguments to %%:compare-debug-self-opt");
10924 : :
10925 : 1244 : if (compare_debug >= 0)
10926 : : return NULL;
10927 : :
10928 : 622 : return concat ("\
10929 : : %<o %<MD %<MMD %<MF* %<MG %<MP %<MQ* %<MT* \
10930 : : %<fdump-final-insns=* -w -S -o %j \
10931 : : %{!fcompare-debug-second:-fcompare-debug-second} \
10932 : 622 : ", compare_debug_opt, NULL);
10933 : : }
10934 : :
10935 : : /* %:pass-through-libs spec function. Finds all -l options and input
10936 : : file names in the lib spec passed to it, and makes a list of them
10937 : : prepended with the plugin option to cause them to be passed through
10938 : : to the final link after all the new object files have been added. */
10939 : :
10940 : : const char *
10941 : 88994 : pass_through_libs_spec_func (int argc, const char **argv)
10942 : : {
10943 : 88994 : char *prepended = xstrdup (" ");
10944 : 88994 : int n;
10945 : : /* Shlemiel the painter's algorithm. Innately horrible, but at least
10946 : : we know that there will never be more than a handful of strings to
10947 : : concat, and it's only once per run, so it's not worth optimising. */
10948 : 854027 : for (n = 0; n < argc; n++)
10949 : : {
10950 : 765033 : char *old = prepended;
10951 : : /* Anything that isn't an option is a full path to an output
10952 : : file; pass it through if it ends in '.a'. Among options,
10953 : : pass only -l. */
10954 : 765033 : if (argv[n][0] == '-' && argv[n][1] == 'l')
10955 : : {
10956 : 492633 : const char *lopt = argv[n] + 2;
10957 : : /* Handle both joined and non-joined -l options. If for any
10958 : : reason there's a trailing -l with no joined or following
10959 : : arg just discard it. */
10960 : 492633 : if (!*lopt && ++n >= argc)
10961 : : break;
10962 : 492633 : else if (!*lopt)
10963 : 0 : lopt = argv[n];
10964 : 492633 : prepended = concat (prepended, "-plugin-opt=-pass-through=-l",
10965 : : lopt, " ", NULL);
10966 : 492633 : }
10967 : 272400 : else if (!strcmp (".a", argv[n] + strlen (argv[n]) - 2))
10968 : : {
10969 : 0 : prepended = concat (prepended, "-plugin-opt=-pass-through=",
10970 : : argv[n], " ", NULL);
10971 : : }
10972 : 765033 : if (prepended != old)
10973 : 492633 : free (old);
10974 : : }
10975 : 88994 : return prepended;
10976 : : }
10977 : :
10978 : : static bool
10979 : 511201 : not_actual_file_p (const char *name)
10980 : : {
10981 : 511201 : return (strcmp (name, "-") == 0
10982 : 511201 : || strcmp (name, HOST_BIT_BUCKET) == 0);
10983 : : }
10984 : :
10985 : : /* %:dumps spec function. Take an optional argument that overrides
10986 : : the default extension for -dumpbase and -dumpbase-ext.
10987 : : Return -dumpdir, -dumpbase and -dumpbase-ext, if needed. */
10988 : : const char *
10989 : 280680 : dumps_spec_func (int argc, const char **argv ATTRIBUTE_UNUSED)
10990 : : {
10991 : 280680 : const char *ext = dumpbase_ext;
10992 : 280680 : char *p;
10993 : :
10994 : 280680 : char *args[3] = { NULL, NULL, NULL };
10995 : 280680 : int nargs = 0;
10996 : :
10997 : : /* Do not compute a default for -dumpbase-ext when -dumpbase was
10998 : : given explicitly. */
10999 : 280680 : if (dumpbase && *dumpbase && !ext)
11000 : 280680 : ext = "";
11001 : :
11002 : 280680 : if (argc == 1)
11003 : : {
11004 : : /* Do not override the explicitly-specified -dumpbase-ext with
11005 : : the specs-provided overrider. */
11006 : 0 : if (!ext)
11007 : 0 : ext = argv[0];
11008 : : }
11009 : 280680 : else if (argc != 0)
11010 : 0 : fatal_error (input_location, "too many arguments for %%:dumps");
11011 : :
11012 : 280680 : if (dumpdir)
11013 : : {
11014 : 103899 : p = quote_spec_arg (xstrdup (dumpdir));
11015 : 103899 : args[nargs++] = concat (" -dumpdir ", p, NULL);
11016 : 103899 : free (p);
11017 : : }
11018 : :
11019 : 280680 : if (!ext)
11020 : 258937 : ext = input_basename + basename_length;
11021 : :
11022 : : /* Use the precomputed outbase, or compute dumpbase from
11023 : : input_basename, just like %b would. */
11024 : 280680 : char *base;
11025 : :
11026 : 280680 : if (dumpbase && *dumpbase)
11027 : : {
11028 : 21743 : base = xstrdup (dumpbase);
11029 : 21743 : p = base + outbase_length;
11030 : 21743 : gcc_checking_assert (strncmp (base, outbase, outbase_length) == 0);
11031 : 21743 : gcc_checking_assert (strcmp (p, ext) == 0);
11032 : : }
11033 : 258937 : else if (outbase_length)
11034 : : {
11035 : 159869 : base = xstrndup (outbase, outbase_length);
11036 : 159869 : p = NULL;
11037 : : }
11038 : : else
11039 : : {
11040 : 99068 : base = xstrndup (input_basename, suffixed_basename_length);
11041 : 99068 : p = base + basename_length;
11042 : : }
11043 : :
11044 : 280680 : if (compare_debug < 0 || !p || strcmp (p, ext) != 0)
11045 : : {
11046 : 616 : if (p)
11047 : 9 : *p = '\0';
11048 : :
11049 : 159878 : const char *gk;
11050 : 159878 : if (compare_debug < 0)
11051 : : gk = ".gk";
11052 : : else
11053 : 159262 : gk = "";
11054 : :
11055 : 159878 : p = concat (base, gk, ext, NULL);
11056 : :
11057 : 159878 : free (base);
11058 : 159878 : base = p;
11059 : : }
11060 : :
11061 : 280680 : base = quote_spec_arg (base);
11062 : 280680 : args[nargs++] = concat (" -dumpbase ", base, NULL);
11063 : 280680 : free (base);
11064 : :
11065 : 280680 : if (*ext)
11066 : : {
11067 : 257897 : p = quote_spec_arg (xstrdup (ext));
11068 : 257897 : args[nargs++] = concat (" -dumpbase-ext ", p, NULL);
11069 : 257897 : free (p);
11070 : : }
11071 : :
11072 : 280680 : const char *ret = concat (args[0], args[1], args[2], NULL);
11073 : 1203836 : while (nargs > 0)
11074 : 642476 : free (args[--nargs]);
11075 : :
11076 : 280680 : return ret;
11077 : : }
11078 : :
11079 : : /* Returns "" if ARGV[ARGC - 2] is greater than ARGV[ARGC-1].
11080 : : Otherwise, return NULL. */
11081 : :
11082 : : static const char *
11083 : 390499 : greater_than_spec_func (int argc, const char **argv)
11084 : : {
11085 : 390499 : char *converted;
11086 : :
11087 : 390499 : if (argc == 1)
11088 : : return NULL;
11089 : :
11090 : 251 : gcc_assert (argc >= 2);
11091 : :
11092 : 251 : long arg = strtol (argv[argc - 2], &converted, 10);
11093 : 251 : gcc_assert (converted != argv[argc - 2]);
11094 : :
11095 : 251 : long lim = strtol (argv[argc - 1], &converted, 10);
11096 : 251 : gcc_assert (converted != argv[argc - 1]);
11097 : :
11098 : 251 : if (arg > lim)
11099 : : return "";
11100 : :
11101 : : return NULL;
11102 : : }
11103 : :
11104 : : /* Returns "" if debug_info_level is greater than ARGV[ARGC-1].
11105 : : Otherwise, return NULL. */
11106 : :
11107 : : static const char *
11108 : 249655 : debug_level_greater_than_spec_func (int argc, const char **argv)
11109 : : {
11110 : 249655 : char *converted;
11111 : :
11112 : 249655 : if (argc != 1)
11113 : 0 : fatal_error (input_location,
11114 : : "wrong number of arguments to %%:debug-level-gt");
11115 : :
11116 : 249655 : long arg = strtol (argv[0], &converted, 10);
11117 : 249655 : gcc_assert (converted != argv[0]);
11118 : :
11119 : 249655 : if (debug_info_level > arg)
11120 : 44882 : return "";
11121 : :
11122 : : return NULL;
11123 : : }
11124 : :
11125 : : /* Returns "" if dwarf_version is greater than ARGV[ARGC-1].
11126 : : Otherwise, return NULL. */
11127 : :
11128 : : static const char *
11129 : 127191 : dwarf_version_greater_than_spec_func (int argc, const char **argv)
11130 : : {
11131 : 127191 : char *converted;
11132 : :
11133 : 127191 : if (argc != 1)
11134 : 0 : fatal_error (input_location,
11135 : : "wrong number of arguments to %%:dwarf-version-gt");
11136 : :
11137 : 127191 : long arg = strtol (argv[0], &converted, 10);
11138 : 127191 : gcc_assert (converted != argv[0]);
11139 : :
11140 : 127191 : if (dwarf_version > arg)
11141 : 126320 : return "";
11142 : :
11143 : : return NULL;
11144 : : }
11145 : :
11146 : : static void
11147 : 33854 : path_prefix_reset (path_prefix *prefix)
11148 : : {
11149 : 33854 : struct prefix_list *iter, *next;
11150 : 33854 : iter = prefix->plist;
11151 : 134322 : while (iter)
11152 : : {
11153 : 100468 : next = iter->next;
11154 : 100468 : free (const_cast <char *> (iter->prefix));
11155 : 100468 : XDELETE (iter);
11156 : 100468 : iter = next;
11157 : : }
11158 : 33854 : prefix->plist = 0;
11159 : 33854 : prefix->max_len = 0;
11160 : 33854 : }
11161 : :
11162 : : /* The function takes 3 arguments: OPTION name, file name and location
11163 : : where we search for Fortran modules.
11164 : : When the FILE is found by find_file, return OPTION=path_to_file. */
11165 : :
11166 : : static const char *
11167 : 30572 : find_fortran_preinclude_file (int argc, const char **argv)
11168 : : {
11169 : 30572 : char *result = NULL;
11170 : 30572 : if (argc != 3)
11171 : : return NULL;
11172 : :
11173 : 30572 : struct path_prefix prefixes = { 0, 0, "preinclude" };
11174 : :
11175 : : /* Search first for 'finclude' folder location for a header file
11176 : : installed by the compiler (similar to omp_lib.h). */
11177 : 30572 : add_prefix (&prefixes, argv[2], NULL, 0, 0, 0);
11178 : : #ifdef TOOL_INCLUDE_DIR
11179 : : /* Then search: <prefix>/<target>/<include>/finclude */
11180 : 30572 : add_prefix (&prefixes, TOOL_INCLUDE_DIR "/finclude/",
11181 : : NULL, 0, 0, 0);
11182 : : #endif
11183 : : #ifdef NATIVE_SYSTEM_HEADER_DIR
11184 : : /* Then search: <sysroot>/usr/include/finclude/<multilib> */
11185 : 30572 : add_sysrooted_hdrs_prefix (&prefixes, NATIVE_SYSTEM_HEADER_DIR "/finclude/",
11186 : : NULL, 0, 0, 0);
11187 : : #endif
11188 : :
11189 : 30572 : const char *path = find_a_file (&include_prefixes, argv[1], R_OK, false);
11190 : 30572 : if (path != NULL)
11191 : 0 : result = concat (argv[0], path, NULL);
11192 : : else
11193 : : {
11194 : 30572 : path = find_a_file (&prefixes, argv[1], R_OK, false);
11195 : 30572 : if (path != NULL)
11196 : 30572 : result = concat (argv[0], path, NULL);
11197 : : }
11198 : :
11199 : 30572 : path_prefix_reset (&prefixes);
11200 : 30572 : return result;
11201 : : }
11202 : :
11203 : : /* The function takes any number of arguments and joins them together.
11204 : :
11205 : : This seems to be necessary to build "-fjoined=foo.b" from "-fseparate foo.a"
11206 : : with a %{fseparate*:-fjoined=%.b$*} rule without adding undesired spaces:
11207 : : when doing $* replacement we first replace $* with the rest of the switch
11208 : : (in this case ""), and then add any arguments as arguments after the result,
11209 : : resulting in "-fjoined= foo.b". Using this function with e.g.
11210 : : %{fseparate*:-fjoined=%:join(%.b$*)} gets multiple words as separate argv
11211 : : elements instead of separated by spaces, and we paste them together. */
11212 : :
11213 : : static const char *
11214 : 39 : join_spec_func (int argc, const char **argv)
11215 : : {
11216 : 39 : if (argc == 1)
11217 : 0 : return argv[0];
11218 : 117 : for (int i = 0; i < argc; ++i)
11219 : 78 : obstack_grow (&obstack, argv[i], strlen (argv[i]));
11220 : 39 : obstack_1grow (&obstack, '\0');
11221 : 39 : return XOBFINISH (&obstack, const char *);
11222 : : }
11223 : :
11224 : : /* If any character in ORIG fits QUOTE_P (_, P), reallocate the string
11225 : : so as to precede every one of them with a backslash. Return the
11226 : : original string or the reallocated one. */
11227 : :
11228 : : static inline char *
11229 : 840030 : quote_string (char *orig, bool (*quote_p)(char, void *), void *p)
11230 : : {
11231 : 840030 : int len, number_of_space = 0;
11232 : :
11233 : 19155310 : for (len = 0; orig[len]; len++)
11234 : 18315280 : if (quote_p (orig[len], p))
11235 : 0 : number_of_space++;
11236 : :
11237 : 840030 : if (number_of_space)
11238 : : {
11239 : 0 : char *new_spec = (char *) xmalloc (len + number_of_space + 1);
11240 : 0 : int j, k;
11241 : 0 : for (j = 0, k = 0; j <= len; j++, k++)
11242 : : {
11243 : 0 : if (quote_p (orig[j], p))
11244 : 0 : new_spec[k++] = '\\';
11245 : 0 : new_spec[k] = orig[j];
11246 : : }
11247 : 0 : free (orig);
11248 : 0 : return new_spec;
11249 : : }
11250 : : else
11251 : : return orig;
11252 : : }
11253 : :
11254 : : /* Return true iff C is any of the characters convert_white_space
11255 : : should quote. */
11256 : :
11257 : : static inline bool
11258 : 12165540 : whitespace_to_convert_p (char c, void *)
11259 : : {
11260 : 12165540 : return (c == ' ' || c == '\t');
11261 : : }
11262 : :
11263 : : /* Insert backslash before spaces in ORIG (usually a file path), to
11264 : : avoid being broken by spec parser.
11265 : :
11266 : : This function is needed as do_spec_1 treats white space (' ' and '\t')
11267 : : as the end of an argument. But in case of -plugin /usr/gcc install/xxx.so,
11268 : : the file name should be treated as a single argument rather than being
11269 : : broken into multiple. Solution is to insert '\\' before the space in a
11270 : : file name.
11271 : :
11272 : : This function converts and only converts all occurrence of ' '
11273 : : to '\\' + ' ' and '\t' to '\\' + '\t'. For example:
11274 : : "a b" -> "a\\ b"
11275 : : "a b" -> "a\\ \\ b"
11276 : : "a\tb" -> "a\\\tb"
11277 : : "a\\ b" -> "a\\\\ b"
11278 : :
11279 : : orig: input null-terminating string that was allocated by xalloc. The
11280 : : memory it points to might be freed in this function. Behavior undefined
11281 : : if ORIG wasn't xalloced or was freed already at entry.
11282 : :
11283 : : Return: ORIG if no conversion needed. Otherwise a newly allocated string
11284 : : that was converted from ORIG. */
11285 : :
11286 : : static char *
11287 : 196324 : convert_white_space (char *orig)
11288 : : {
11289 : 196324 : return quote_string (orig, whitespace_to_convert_p, NULL);
11290 : : }
11291 : :
11292 : : /* Return true iff C matches any of the spec active characters. */
11293 : : static inline bool
11294 : 6149740 : quote_spec_char_p (char c, void *)
11295 : : {
11296 : 6149740 : switch (c)
11297 : : {
11298 : : case ' ':
11299 : : case '\t':
11300 : : case '\n':
11301 : : case '|':
11302 : : case '%':
11303 : : case '\\':
11304 : : return true;
11305 : :
11306 : 6149740 : default:
11307 : 6149740 : return false;
11308 : : }
11309 : : }
11310 : :
11311 : : /* Like convert_white_space, but deactivate all active spec chars by
11312 : : quoting them. */
11313 : :
11314 : : static inline char *
11315 : 643706 : quote_spec (char *orig)
11316 : : {
11317 : 1239 : return quote_string (orig, quote_spec_char_p, NULL);
11318 : : }
11319 : :
11320 : : /* Like quote_spec, but also turn an empty string into the spec for an
11321 : : empty argument. */
11322 : :
11323 : : static inline char *
11324 : 642476 : quote_spec_arg (char *orig)
11325 : : {
11326 : 642476 : if (!*orig)
11327 : : {
11328 : 9 : free (orig);
11329 : 9 : return xstrdup ("%\"");
11330 : : }
11331 : :
11332 : 642467 : return quote_spec (orig);
11333 : : }
11334 : :
11335 : : /* Restore all state within gcc.cc to the initial state, so that the driver
11336 : : code can be safely re-run in-process.
11337 : :
11338 : : Many const char * variables are referenced by static specs (see
11339 : : INIT_STATIC_SPEC above). These variables are restored to their default
11340 : : values by a simple loop over the static specs.
11341 : :
11342 : : For other variables, we directly restore them all to their initial
11343 : : values (often implicitly 0).
11344 : :
11345 : : Free the various obstacks in this file, along with "opts_obstack"
11346 : : from opts.cc.
11347 : :
11348 : : This function also restores any environment variables that were changed. */
11349 : :
11350 : : void
11351 : 1094 : driver::finalize ()
11352 : : {
11353 : 1094 : env.restore ();
11354 : 1094 : diagnostic_finish (global_dc);
11355 : :
11356 : 1094 : is_cpp_driver = 0;
11357 : 1094 : at_file_supplied = 0;
11358 : 1094 : print_help_list = 0;
11359 : 1094 : print_version = 0;
11360 : 1094 : verbose_only_flag = 0;
11361 : 1094 : print_subprocess_help = 0;
11362 : 1094 : use_ld = NULL;
11363 : 1094 : report_times_to_file = NULL;
11364 : 1094 : target_system_root = DEFAULT_TARGET_SYSTEM_ROOT;
11365 : 1094 : target_system_root_changed = 0;
11366 : 1094 : target_sysroot_suffix = 0;
11367 : 1094 : target_sysroot_hdrs_suffix = 0;
11368 : 1094 : save_temps_flag = SAVE_TEMPS_NONE;
11369 : 1094 : save_temps_overrides_dumpdir = false;
11370 : 1094 : dumpdir_trailing_dash_added = false;
11371 : 1094 : free (dumpdir);
11372 : 1094 : free (dumpbase);
11373 : 1094 : free (dumpbase_ext);
11374 : 1094 : free (outbase);
11375 : 1094 : dumpdir = dumpbase = dumpbase_ext = outbase = NULL;
11376 : 1094 : dumpdir_length = outbase_length = 0;
11377 : 1094 : spec_machine = DEFAULT_TARGET_MACHINE;
11378 : 1094 : greatest_status = 1;
11379 : :
11380 : 1094 : obstack_free (&obstack, NULL);
11381 : 1094 : obstack_free (&opts_obstack, NULL); /* in opts.cc */
11382 : 1094 : obstack_free (&collect_obstack, NULL);
11383 : :
11384 : 1094 : link_command_spec = LINK_COMMAND_SPEC;
11385 : :
11386 : 1094 : obstack_free (&multilib_obstack, NULL);
11387 : :
11388 : 1094 : user_specs_head = NULL;
11389 : 1094 : user_specs_tail = NULL;
11390 : :
11391 : : /* Within the "compilers" vec, the fields "suffix" and "spec" were
11392 : : statically allocated for the default compilers, but dynamically
11393 : : allocated for additional compilers. Delete them for the latter. */
11394 : 1094 : for (int i = n_default_compilers; i < n_compilers; i++)
11395 : : {
11396 : 0 : free (const_cast <char *> (compilers[i].suffix));
11397 : 0 : free (const_cast <char *> (compilers[i].spec));
11398 : : }
11399 : 1094 : XDELETEVEC (compilers);
11400 : 1094 : compilers = NULL;
11401 : 1094 : n_compilers = 0;
11402 : :
11403 : 1094 : linker_options.truncate (0);
11404 : 1094 : assembler_options.truncate (0);
11405 : 1094 : preprocessor_options.truncate (0);
11406 : :
11407 : 1094 : path_prefix_reset (&exec_prefixes);
11408 : 1094 : path_prefix_reset (&startfile_prefixes);
11409 : 1094 : path_prefix_reset (&include_prefixes);
11410 : :
11411 : 1094 : machine_suffix = 0;
11412 : 1094 : just_machine_suffix = 0;
11413 : 1094 : gcc_exec_prefix = 0;
11414 : 1094 : gcc_libexec_prefix = 0;
11415 : 1094 : set_static_spec_shared (&md_exec_prefix, MD_EXEC_PREFIX);
11416 : 1094 : set_static_spec_shared (&md_startfile_prefix, MD_STARTFILE_PREFIX);
11417 : 1094 : set_static_spec_shared (&md_startfile_prefix_1, MD_STARTFILE_PREFIX_1);
11418 : 1094 : multilib_dir = 0;
11419 : 1094 : multilib_os_dir = 0;
11420 : 1094 : multiarch_dir = 0;
11421 : :
11422 : : /* Free any specs dynamically-allocated by set_spec.
11423 : : These will be at the head of the list, before the
11424 : : statically-allocated ones. */
11425 : 1094 : if (specs)
11426 : : {
11427 : 2188 : while (specs != static_specs)
11428 : : {
11429 : 1094 : spec_list *next = specs->next;
11430 : 1094 : free (const_cast <char *> (specs->name));
11431 : 1094 : XDELETE (specs);
11432 : 1094 : specs = next;
11433 : : }
11434 : 1094 : specs = 0;
11435 : : }
11436 : 50324 : for (unsigned i = 0; i < ARRAY_SIZE (static_specs); i++)
11437 : : {
11438 : 49230 : spec_list *sl = &static_specs[i];
11439 : 49230 : if (sl->alloc_p)
11440 : : {
11441 : 43770 : free (const_cast <char *> (*(sl->ptr_spec)));
11442 : 43770 : sl->alloc_p = false;
11443 : : }
11444 : 49230 : *(sl->ptr_spec) = sl->default_ptr;
11445 : : }
11446 : : #ifdef EXTRA_SPECS
11447 : 1094 : extra_specs = NULL;
11448 : : #endif
11449 : :
11450 : 1094 : processing_spec_function = 0;
11451 : :
11452 : 1094 : clear_args ();
11453 : :
11454 : 1094 : have_c = 0;
11455 : 1094 : have_o = 0;
11456 : :
11457 : 1094 : temp_names = NULL;
11458 : 1094 : execution_count = 0;
11459 : 1094 : signal_count = 0;
11460 : :
11461 : 1094 : temp_filename = NULL;
11462 : 1094 : temp_filename_length = 0;
11463 : 1094 : always_delete_queue = NULL;
11464 : 1094 : failure_delete_queue = NULL;
11465 : :
11466 : 1094 : XDELETEVEC (switches);
11467 : 1094 : switches = NULL;
11468 : 1094 : n_switches = 0;
11469 : 1094 : n_switches_alloc = 0;
11470 : :
11471 : 1094 : compare_debug = 0;
11472 : 1094 : compare_debug_second = 0;
11473 : 1094 : compare_debug_opt = NULL;
11474 : 3282 : for (int i = 0; i < 2; i++)
11475 : : {
11476 : 2188 : switches_debug_check[i] = NULL;
11477 : 2188 : n_switches_debug_check[i] = 0;
11478 : 2188 : n_switches_alloc_debug_check[i] = 0;
11479 : 2188 : debug_check_temp_file[i] = NULL;
11480 : : }
11481 : :
11482 : 1094 : XDELETEVEC (infiles);
11483 : 1094 : infiles = NULL;
11484 : 1094 : n_infiles = 0;
11485 : 1094 : n_infiles_alloc = 0;
11486 : :
11487 : 1094 : combine_inputs = false;
11488 : 1094 : added_libraries = 0;
11489 : 1094 : XDELETEVEC (outfiles);
11490 : 1094 : outfiles = NULL;
11491 : 1094 : spec_lang = 0;
11492 : 1094 : last_language_n_infiles = 0;
11493 : 1094 : gcc_input_filename = NULL;
11494 : 1094 : input_file_number = 0;
11495 : 1094 : input_filename_length = 0;
11496 : 1094 : basename_length = 0;
11497 : 1094 : suffixed_basename_length = 0;
11498 : 1094 : input_basename = NULL;
11499 : 1094 : input_suffix = NULL;
11500 : : /* We don't need to purge "input_stat", just to unset "input_stat_set". */
11501 : 1094 : input_stat_set = 0;
11502 : 1094 : input_file_compiler = NULL;
11503 : 1094 : arg_going = 0;
11504 : 1094 : delete_this_arg = 0;
11505 : 1094 : this_is_output_file = 0;
11506 : 1094 : this_is_library_file = 0;
11507 : 1094 : this_is_linker_script = 0;
11508 : 1094 : input_from_pipe = 0;
11509 : 1094 : suffix_subst = NULL;
11510 : :
11511 : 1094 : XDELETEVEC (mdswitches);
11512 : 1094 : mdswitches = NULL;
11513 : 1094 : n_mdswitches = 0;
11514 : :
11515 : 1094 : used_arg.finalize ();
11516 : 1094 : }
11517 : :
11518 : : /* PR jit/64810.
11519 : : Targets can provide configure-time default options in
11520 : : OPTION_DEFAULT_SPECS. The jit needs to access these, but
11521 : : they are expressed in the spec language.
11522 : :
11523 : : Run just enough of the driver to be able to expand these
11524 : : specs, and then call the callback CB on each
11525 : : such option. The options strings are *without* a leading
11526 : : '-' character e.g. ("march=x86-64"). Finally, clean up. */
11527 : :
11528 : : void
11529 : 124 : driver_get_configure_time_options (void (*cb) (const char *option,
11530 : : void *user_data),
11531 : : void *user_data)
11532 : : {
11533 : 124 : size_t i;
11534 : :
11535 : 124 : obstack_init (&obstack);
11536 : 124 : init_opts_obstack ();
11537 : 124 : n_switches = 0;
11538 : :
11539 : 1240 : for (i = 0; i < ARRAY_SIZE (option_default_specs); i++)
11540 : 1116 : do_option_spec (option_default_specs[i].name,
11541 : 1116 : option_default_specs[i].spec);
11542 : :
11543 : 372 : for (i = 0; (int) i < n_switches; i++)
11544 : : {
11545 : 248 : gcc_assert (switches[i].part1);
11546 : 248 : (*cb) (switches[i].part1, user_data);
11547 : : }
11548 : :
11549 : 124 : obstack_free (&opts_obstack, NULL);
11550 : 124 : obstack_free (&obstack, NULL);
11551 : 124 : n_switches = 0;
11552 : 124 : }
|