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 : : #define INCLUDE_VECTOR
32 : : #include "config.h"
33 : : #include "system.h"
34 : : #ifdef HOST_HAS_PERSONALITY_ADDR_NO_RANDOMIZE
35 : : #include <sys/personality.h>
36 : : #endif
37 : : #include "coretypes.h"
38 : : #include "multilib.h" /* before tm.h */
39 : : #include "tm.h"
40 : : #include "xregex.h"
41 : : #include "obstack.h"
42 : : #include "intl.h"
43 : : #include "prefix.h"
44 : : #include "opt-suggestions.h"
45 : : #include "gcc.h"
46 : : #include "diagnostic.h"
47 : : #include "diagnostics/sink.h"
48 : : #include "pretty-print-urlifier.h"
49 : : #include "flags.h"
50 : : #include "opts.h"
51 : : #include "filenames.h"
52 : : #include "spellcheck.h"
53 : : #include "opts-jobserver.h"
54 : : #include "common/common-target.h"
55 : : #include "gcc-urlifier.h"
56 : : #include "opts-diagnostic.h"
57 : :
58 : : #ifndef MATH_LIBRARY
59 : : #define MATH_LIBRARY "m"
60 : : #endif
61 : :
62 : :
63 : : /* Manage the manipulation of env vars.
64 : :
65 : : We poison "getenv" and "putenv", so that all enviroment-handling is
66 : : done through this class. Note that poisoning happens in the
67 : : preprocessor at the identifier level, and doesn't distinguish between
68 : : env.getenv ();
69 : : and
70 : : getenv ();
71 : : Hence we need to use "get" for the accessor method, not "getenv". */
72 : :
73 : : struct env_manager
74 : : {
75 : : public:
76 : : void init (bool can_restore, bool debug);
77 : : const char *get (const char *name);
78 : : void xput (const char *string);
79 : : void restore ();
80 : :
81 : : private:
82 : : bool m_can_restore;
83 : : bool m_debug;
84 : : struct kv
85 : : {
86 : : char *m_key;
87 : : char *m_value;
88 : : };
89 : : vec<kv> m_keys;
90 : :
91 : : };
92 : :
93 : : /* The singleton instance of class env_manager. */
94 : :
95 : : static env_manager env;
96 : :
97 : : /* Initializer for class env_manager.
98 : :
99 : : We can't do this as a constructor since we have a statically
100 : : allocated instance ("env" above). */
101 : :
102 : : void
103 : 298436 : env_manager::init (bool can_restore, bool debug)
104 : : {
105 : 298436 : m_can_restore = can_restore;
106 : 298436 : m_debug = debug;
107 : 298436 : }
108 : :
109 : : /* Get the value of NAME within the environment. Essentially
110 : : a wrapper for ::getenv, but adding logging, and the possibility
111 : : of caching results. */
112 : :
113 : : const char *
114 : 1491263 : env_manager::get (const char *name)
115 : : {
116 : 1491263 : const char *result = ::getenv (name);
117 : 1491263 : if (m_debug)
118 : 0 : fprintf (stderr, "env_manager::getenv (%s) -> %s\n", name, result);
119 : 1491263 : return result;
120 : : }
121 : :
122 : : /* Put the given KEY=VALUE entry STRING into the environment.
123 : : If the env_manager was initialized with CAN_RESTORE set, then
124 : : also record the old value of KEY within the environment, so that it
125 : : can be later restored. */
126 : :
127 : : void
128 : 1770461 : env_manager::xput (const char *string)
129 : : {
130 : 1770461 : if (m_debug)
131 : 0 : fprintf (stderr, "env_manager::xput (%s)\n", string);
132 : 1770461 : if (verbose_flag)
133 : 5993 : fnotice (stderr, "%s\n", string);
134 : :
135 : 1770461 : if (m_can_restore)
136 : : {
137 : 6799 : char *equals = strchr (const_cast <char *> (string), '=');
138 : 6799 : gcc_assert (equals);
139 : :
140 : 6799 : struct kv kv;
141 : 6799 : kv.m_key = xstrndup (string, equals - string);
142 : 6799 : const char *cur_value = ::getenv (kv.m_key);
143 : 6799 : if (m_debug)
144 : 0 : fprintf (stderr, "saving old value: %s\n",cur_value);
145 : 6799 : kv.m_value = cur_value ? xstrdup (cur_value) : NULL;
146 : 6799 : m_keys.safe_push (kv);
147 : : }
148 : :
149 : 1770461 : ::putenv (CONST_CAST (char *, string));
150 : 1770461 : }
151 : :
152 : : /* Undo any xputenv changes made since last restore.
153 : : Can only be called if the env_manager was initialized with
154 : : CAN_RESTORE enabled. */
155 : :
156 : : void
157 : 1134 : env_manager::restore ()
158 : : {
159 : 1134 : unsigned int i;
160 : 1134 : struct kv *item;
161 : :
162 : 1134 : gcc_assert (m_can_restore);
163 : :
164 : 9067 : FOR_EACH_VEC_ELT_REVERSE (m_keys, i, item)
165 : : {
166 : 6799 : if (m_debug)
167 : 0 : printf ("restoring saved key: %s value: %s\n", item->m_key, item->m_value);
168 : 6799 : if (item->m_value)
169 : 3397 : ::setenv (item->m_key, item->m_value, 1);
170 : : else
171 : 3402 : ::unsetenv (item->m_key);
172 : 6799 : free (item->m_key);
173 : 6799 : free (item->m_value);
174 : : }
175 : :
176 : 1134 : m_keys.truncate (0);
177 : 1134 : }
178 : :
179 : : /* Forbid other uses of getenv and putenv. */
180 : : #if (GCC_VERSION >= 3000)
181 : : #pragma GCC poison getenv putenv
182 : : #endif
183 : :
184 : :
185 : :
186 : : /* By default there is no special suffix for target executables. */
187 : : #ifdef TARGET_EXECUTABLE_SUFFIX
188 : : #define HAVE_TARGET_EXECUTABLE_SUFFIX
189 : : #else
190 : : #define TARGET_EXECUTABLE_SUFFIX ""
191 : : #endif
192 : :
193 : : /* By default there is no special suffix for host executables. */
194 : : #ifdef HOST_EXECUTABLE_SUFFIX
195 : : #define HAVE_HOST_EXECUTABLE_SUFFIX
196 : : #else
197 : : #define HOST_EXECUTABLE_SUFFIX ""
198 : : #endif
199 : :
200 : : /* By default, the suffix for target object files is ".o". */
201 : : #ifdef TARGET_OBJECT_SUFFIX
202 : : #define HAVE_TARGET_OBJECT_SUFFIX
203 : : #else
204 : : #define TARGET_OBJECT_SUFFIX ".o"
205 : : #endif
206 : :
207 : : static const char dir_separator_str[] = { DIR_SEPARATOR, 0 };
208 : :
209 : : /* Most every one is fine with LIBRARY_PATH. For some, it conflicts. */
210 : : #ifndef LIBRARY_PATH_ENV
211 : : #define LIBRARY_PATH_ENV "LIBRARY_PATH"
212 : : #endif
213 : :
214 : : /* If a stage of compilation returns an exit status >= 1,
215 : : compilation of that file ceases. */
216 : :
217 : : #define MIN_FATAL_STATUS 1
218 : :
219 : : /* Flag set by cppspec.cc to 1. */
220 : : int is_cpp_driver;
221 : :
222 : : /* Flag set to nonzero if an @file argument has been supplied to gcc. */
223 : : static bool at_file_supplied;
224 : :
225 : : /* Definition of string containing the arguments given to configure. */
226 : : #include "configargs.h"
227 : :
228 : : /* Flag saying to print the command line options understood by gcc and its
229 : : sub-processes. */
230 : :
231 : : static int print_help_list;
232 : :
233 : : /* Flag saying to print the version of gcc and its sub-processes. */
234 : :
235 : : static int print_version;
236 : :
237 : : /* Flag that stores string prefix for which we provide bash completion. */
238 : :
239 : : static const char *completion = NULL;
240 : :
241 : : /* Flag indicating whether we should ONLY print the command and
242 : : arguments (like verbose_flag) without executing the command.
243 : : Displayed arguments are quoted so that the generated command
244 : : line is suitable for execution. This is intended for use in
245 : : shell scripts to capture the driver-generated command line. */
246 : : static int verbose_only_flag;
247 : :
248 : : /* Flag indicating how to print command line options of sub-processes. */
249 : :
250 : : static int print_subprocess_help;
251 : :
252 : : /* Linker suffix passed to -fuse-ld=... */
253 : : static const char *use_ld;
254 : :
255 : : /* Whether we should report subprocess execution times to a file. */
256 : :
257 : : FILE *report_times_to_file = NULL;
258 : :
259 : : /* Nonzero means place this string before uses of /, so that include
260 : : and library files can be found in an alternate location. */
261 : :
262 : : #ifdef TARGET_SYSTEM_ROOT
263 : : #define DEFAULT_TARGET_SYSTEM_ROOT (TARGET_SYSTEM_ROOT)
264 : : #else
265 : : #define DEFAULT_TARGET_SYSTEM_ROOT (0)
266 : : #endif
267 : : static const char *target_system_root = DEFAULT_TARGET_SYSTEM_ROOT;
268 : :
269 : : /* Nonzero means pass the updated target_system_root to the compiler. */
270 : :
271 : : static int target_system_root_changed;
272 : :
273 : : /* Nonzero means append this string to target_system_root. */
274 : :
275 : : static const char *target_sysroot_suffix = 0;
276 : :
277 : : /* Nonzero means append this string to target_system_root for headers. */
278 : :
279 : : static const char *target_sysroot_hdrs_suffix = 0;
280 : :
281 : : /* Nonzero means write "temp" files in source directory
282 : : and use the source file's name in them, and don't delete them. */
283 : :
284 : : static enum save_temps {
285 : : SAVE_TEMPS_NONE, /* no -save-temps */
286 : : SAVE_TEMPS_CWD, /* -save-temps in current directory */
287 : : SAVE_TEMPS_DUMP, /* -save-temps in dumpdir */
288 : : SAVE_TEMPS_OBJ /* -save-temps in object directory */
289 : : } save_temps_flag;
290 : :
291 : : /* Set this iff the dumppfx implied by a -save-temps=* option is to
292 : : override a -dumpdir option, if any. */
293 : : static bool save_temps_overrides_dumpdir = false;
294 : :
295 : : /* -dumpdir, -dumpbase and -dumpbase-ext flags passed in, possibly
296 : : rearranged as they are to be passed down, e.g., dumpbase and
297 : : dumpbase_ext may be cleared if integrated with dumpdir or
298 : : dropped. */
299 : : static char *dumpdir, *dumpbase, *dumpbase_ext;
300 : :
301 : : /* Usually the length of the string in dumpdir. However, during
302 : : linking, it may be shortened to omit a driver-added trailing dash,
303 : : by then replaced with a trailing period, that is still to be passed
304 : : to sub-processes in -dumpdir, but not to be generally used in spec
305 : : filename expansions. See maybe_run_linker. */
306 : : static size_t dumpdir_length = 0;
307 : :
308 : : /* Set if the last character in dumpdir is (or was) a dash that the
309 : : driver added to dumpdir after dumpbase or linker output name. */
310 : : static bool dumpdir_trailing_dash_added = false;
311 : :
312 : : /* True if -r, -shared, -pie, -no-pie, -z lazy, or -z norelro were
313 : : specified on the command line, and therefore -fhardened should not
314 : : add -z now/relro. */
315 : : static bool avoid_linker_hardening_p;
316 : :
317 : : /* True if -static was specified on the command line. */
318 : : static bool static_p;
319 : :
320 : : /* Basename of dump and aux outputs, computed from dumpbase (given or
321 : : derived from output name), to override input_basename in non-%w %b
322 : : et al. */
323 : : static char *outbase;
324 : : static size_t outbase_length = 0;
325 : :
326 : : /* The compiler version. */
327 : :
328 : : static const char *compiler_version;
329 : :
330 : : /* The target version. */
331 : :
332 : : static const char *const spec_version = DEFAULT_TARGET_VERSION;
333 : :
334 : : /* The target machine. */
335 : :
336 : : static const char *spec_machine = DEFAULT_TARGET_MACHINE;
337 : : static const char *spec_host_machine = DEFAULT_REAL_TARGET_MACHINE;
338 : :
339 : : /* List of offload targets. Separated by colon. Empty string for
340 : : -foffload=disable. */
341 : :
342 : : static char *offload_targets = NULL;
343 : :
344 : : #if OFFLOAD_DEFAULTED
345 : : /* Set to true if -foffload has not been used and offload_targets
346 : : is set to the configured in default. */
347 : : static bool offload_targets_default;
348 : : #endif
349 : :
350 : : /* Nonzero if cross-compiling.
351 : : When -b is used, the value comes from the `specs' file. */
352 : :
353 : : #ifdef CROSS_DIRECTORY_STRUCTURE
354 : : static const char *cross_compile = "1";
355 : : #else
356 : : static const char *cross_compile = "0";
357 : : #endif
358 : :
359 : : /* Greatest exit code of sub-processes that has been encountered up to
360 : : now. */
361 : : static int greatest_status = 1;
362 : :
363 : : /* This is the obstack which we use to allocate many strings. */
364 : :
365 : : static struct obstack obstack;
366 : :
367 : : /* This is the obstack to build an environment variable to pass to
368 : : collect2 that describes all of the relevant switches of what to
369 : : pass the compiler in building the list of pointers to constructors
370 : : and destructors. */
371 : :
372 : : static struct obstack collect_obstack;
373 : :
374 : : /* Forward declaration for prototypes. */
375 : : struct path_prefix;
376 : : struct prefix_list;
377 : :
378 : : static void init_spec (void);
379 : : static void store_arg (const char *, int, int);
380 : : static void insert_wrapper (const char *);
381 : : static char *load_specs (const char *);
382 : : static void read_specs (const char *, bool, bool);
383 : : static void set_spec (const char *, const char *, bool);
384 : : static struct compiler *lookup_compiler (const char *, size_t, const char *);
385 : : static char *build_search_list (const struct path_prefix *, const char *,
386 : : bool, bool);
387 : : static void xputenv (const char *);
388 : : static void putenv_from_prefixes (const struct path_prefix *, const char *,
389 : : bool);
390 : : static int access_check (const char *, int);
391 : : static char *find_a_file (const struct path_prefix *, const char *, int, bool);
392 : : static char *find_a_program (const char *);
393 : : static void add_prefix (struct path_prefix *, const char *, const char *,
394 : : int, int, int);
395 : : static void add_sysrooted_prefix (struct path_prefix *, const char *,
396 : : const char *, int, int, int);
397 : : static char *skip_whitespace (char *);
398 : : static void delete_if_ordinary (const char *);
399 : : static void delete_temp_files (void);
400 : : static void delete_failure_queue (void);
401 : : static void clear_failure_queue (void);
402 : : static int check_live_switch (int, int);
403 : : static const char *handle_braces (const char *);
404 : : static inline bool input_suffix_matches (const char *, const char *);
405 : : static inline bool switch_matches (const char *, const char *, int);
406 : : static inline void mark_matching_switches (const char *, const char *, int);
407 : : static inline void process_marked_switches (void);
408 : : static const char *process_brace_body (const char *, const char *, const char *, int, int);
409 : : static const struct spec_function *lookup_spec_function (const char *);
410 : : static const char *eval_spec_function (const char *, const char *, const char *);
411 : : static const char *handle_spec_function (const char *, bool *, const char *);
412 : : static char *save_string (const char *, int);
413 : : static void set_collect_gcc_options (void);
414 : : static int do_spec_1 (const char *, int, const char *);
415 : : static int do_spec_2 (const char *, const char *);
416 : : static void do_option_spec (const char *, const char *);
417 : : static void do_self_spec (const char *);
418 : : static const char *find_file (const char *);
419 : : static int is_directory (const char *);
420 : : static const char *validate_switches (const char *, bool, bool);
421 : : static void validate_all_switches (void);
422 : : static inline void validate_switches_from_spec (const char *, bool);
423 : : static void give_switch (int, int);
424 : : static int default_arg (const char *, int);
425 : : static void set_multilib_dir (void);
426 : : static void print_multilib_info (void);
427 : : static void display_help (void);
428 : : static void add_preprocessor_option (const char *, int);
429 : : static void add_assembler_option (const char *, int);
430 : : static void add_linker_option (const char *, int);
431 : : static void process_command (unsigned int, struct cl_decoded_option *);
432 : : static int execute (void);
433 : : static void alloc_args (void);
434 : : static void clear_args (void);
435 : : static void fatal_signal (int);
436 : : #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC)
437 : : static void init_gcc_specs (struct obstack *, const char *, const char *,
438 : : const char *);
439 : : #endif
440 : : #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
441 : : static const char *convert_filename (const char *, int, int);
442 : : #endif
443 : :
444 : : static void try_generate_repro (const char **argv);
445 : : static const char *getenv_spec_function (int, const char **);
446 : : static const char *if_exists_spec_function (int, const char **);
447 : : static const char *if_exists_else_spec_function (int, const char **);
448 : : static const char *if_exists_then_else_spec_function (int, const char **);
449 : : static const char *sanitize_spec_function (int, const char **);
450 : : static const char *replace_outfile_spec_function (int, const char **);
451 : : static const char *remove_outfile_spec_function (int, const char **);
452 : : static const char *version_compare_spec_function (int, const char **);
453 : : static const char *include_spec_function (int, const char **);
454 : : static const char *find_file_spec_function (int, const char **);
455 : : static const char *find_plugindir_spec_function (int, const char **);
456 : : static const char *print_asm_header_spec_function (int, const char **);
457 : : static const char *compare_debug_dump_opt_spec_function (int, const char **);
458 : : static const char *compare_debug_self_opt_spec_function (int, const char **);
459 : : static const char *pass_through_libs_spec_func (int, const char **);
460 : : static const char *dumps_spec_func (int, const char **);
461 : : static const char *greater_than_spec_func (int, const char **);
462 : : static const char *debug_level_greater_than_spec_func (int, const char **);
463 : : static const char *dwarf_version_greater_than_spec_func (int, const char **);
464 : : static const char *find_fortran_preinclude_file (int, const char **);
465 : : static const char *join_spec_func (int, const char **);
466 : : static char *convert_white_space (char *);
467 : : static char *quote_spec (char *);
468 : : static char *quote_spec_arg (char *);
469 : : static bool not_actual_file_p (const char *);
470 : :
471 : :
472 : : /* The Specs Language
473 : :
474 : : Specs are strings containing lines, each of which (if not blank)
475 : : is made up of a program name, and arguments separated by spaces.
476 : : The program name must be exact and start from root, since no path
477 : : is searched and it is unreliable to depend on the current working directory.
478 : : Redirection of input or output is not supported; the subprograms must
479 : : accept filenames saying what files to read and write.
480 : :
481 : : In addition, the specs can contain %-sequences to substitute variable text
482 : : or for conditional text. Here is a table of all defined %-sequences.
483 : : Note that spaces are not generated automatically around the results of
484 : : expanding these sequences; therefore, you can concatenate them together
485 : : or with constant text in a single argument.
486 : :
487 : : %% substitute one % into the program name or argument.
488 : : %" substitute an empty argument.
489 : : %i substitute the name of the input file being processed.
490 : : %b substitute the basename for outputs related with the input file
491 : : being processed. This is often a substring of the input file name,
492 : : up to (and not including) the last period but, unless %w is active,
493 : : it is affected by the directory selected by -save-temps=*, by
494 : : -dumpdir, and, in case of multiple compilations, even by -dumpbase
495 : : and -dumpbase-ext and, in case of linking, by the linker output
496 : : name. When %w is active, it derives the main output name only from
497 : : the input file base name; when it is not, it names aux/dump output
498 : : file.
499 : : %B same as %b, but include the input file suffix (text after the last
500 : : period).
501 : : %gSUFFIX
502 : : substitute a file name that has suffix SUFFIX and is chosen
503 : : once per compilation, and mark the argument a la %d. To reduce
504 : : exposure to denial-of-service attacks, the file name is now
505 : : chosen in a way that is hard to predict even when previously
506 : : chosen file names are known. For example, `%g.s ... %g.o ... %g.s'
507 : : might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches
508 : : the regexp "[.0-9A-Za-z]*%O"; "%O" is treated exactly as if it
509 : : had been pre-processed. Previously, %g was simply substituted
510 : : with a file name chosen once per compilation, without regard
511 : : to any appended suffix (which was therefore treated just like
512 : : ordinary text), making such attacks more likely to succeed.
513 : : %|SUFFIX
514 : : like %g, but if -pipe is in effect, expands simply to "-".
515 : : %mSUFFIX
516 : : like %g, but if -pipe is in effect, expands to nothing. (We have both
517 : : %| and %m to accommodate differences between system assemblers; see
518 : : the AS_NEEDS_DASH_FOR_PIPED_INPUT target macro.)
519 : : %uSUFFIX
520 : : like %g, but generates a new temporary file name even if %uSUFFIX
521 : : was already seen.
522 : : %USUFFIX
523 : : substitutes the last file name generated with %uSUFFIX, generating a
524 : : new one if there is no such last file name. In the absence of any
525 : : %uSUFFIX, this is just like %gSUFFIX, except they don't share
526 : : the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s'
527 : : would involve the generation of two distinct file names, one
528 : : for each `%g.s' and another for each `%U.s'. Previously, %U was
529 : : simply substituted with a file name chosen for the previous %u,
530 : : without regard to any appended suffix.
531 : : %jSUFFIX
532 : : substitutes the name of the HOST_BIT_BUCKET, if any, and if it is
533 : : writable, and if save-temps is off; otherwise, substitute the name
534 : : of a temporary file, just like %u. This temporary file is not
535 : : meant for communication between processes, but rather as a junk
536 : : disposal mechanism.
537 : : %.SUFFIX
538 : : substitutes .SUFFIX for the suffixes of a matched switch's args when
539 : : it is subsequently output with %*. SUFFIX is terminated by the next
540 : : space or %.
541 : : %d marks the argument containing or following the %d as a
542 : : temporary file name, so that file will be deleted if GCC exits
543 : : successfully. Unlike %g, this contributes no text to the argument.
544 : : %w marks the argument containing or following the %w as the
545 : : "output file" of this compilation. This puts the argument
546 : : into the sequence of arguments that %o will substitute later.
547 : : %V indicates that this compilation produces no "output file".
548 : : %W{...}
549 : : like %{...} but marks the last argument supplied within as a file
550 : : to be deleted on failure.
551 : : %@{...}
552 : : like %{...} but puts the result into a FILE and substitutes @FILE
553 : : if an @file argument has been supplied.
554 : : %o substitutes the names of all the output files, with spaces
555 : : automatically placed around them. You should write spaces
556 : : around the %o as well or the results are undefined.
557 : : %o is for use in the specs for running the linker.
558 : : Input files whose names have no recognized suffix are not compiled
559 : : at all, but they are included among the output files, so they will
560 : : be linked.
561 : : %O substitutes the suffix for object files. Note that this is
562 : : handled specially when it immediately follows %g, %u, or %U
563 : : (with or without a suffix argument) because of the need for
564 : : those to form complete file names. The handling is such that
565 : : %O is treated exactly as if it had already been substituted,
566 : : except that %g, %u, and %U do not currently support additional
567 : : SUFFIX characters following %O as they would following, for
568 : : example, `.o'.
569 : : %I Substitute any of -iprefix (made from GCC_EXEC_PREFIX), -isysroot
570 : : (made from TARGET_SYSTEM_ROOT), -isystem (made from COMPILER_PATH
571 : : and -B options) and -imultilib as necessary.
572 : : %s current argument is the name of a library or startup file of some sort.
573 : : Search for that file in a standard list of directories
574 : : and substitute the full name found.
575 : : %T current argument is the name of a linker script.
576 : : Search for that file in the current list of directories to scan for
577 : : libraries. If the file is located, insert a --script option into the
578 : : command line followed by the full path name found. If the file is
579 : : not found then generate an error message.
580 : : Note: the current working directory is not searched.
581 : : %eSTR Print STR as an error message. STR is terminated by a newline.
582 : : Use this when inconsistent options are detected.
583 : : %nSTR Print STR as a notice. STR is terminated by a newline.
584 : : %x{OPTION} Accumulate an option for %X.
585 : : %X Output the accumulated linker options specified by compilations.
586 : : %Y Output the accumulated assembler options specified by compilations.
587 : : %Z Output the accumulated preprocessor options specified by compilations.
588 : : %a process ASM_SPEC as a spec.
589 : : This allows config.h to specify part of the spec for running as.
590 : : %A process ASM_FINAL_SPEC as a spec. A capital A is actually
591 : : used here. This can be used to run a post-processor after the
592 : : assembler has done its job.
593 : : %D Dump out a -L option for each directory in startfile_prefixes.
594 : : If multilib_dir is set, extra entries are generated with it affixed.
595 : : %l process LINK_SPEC as a spec.
596 : : %L process LIB_SPEC as a spec.
597 : : %M Output multilib_os_dir.
598 : : %P Output a RUNPATH_OPTION for each directory in startfile_prefixes.
599 : : %G process LIBGCC_SPEC as a spec.
600 : : %R Output the concatenation of target_system_root and
601 : : target_sysroot_suffix.
602 : : %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
603 : : %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
604 : : %C process CPP_SPEC as a spec.
605 : : %1 process CC1_SPEC as a spec.
606 : : %2 process CC1PLUS_SPEC as a spec.
607 : : %* substitute the variable part of a matched option. (See below.)
608 : : Note that each comma in the substituted string is replaced by
609 : : a single space. A space is appended after the last substition
610 : : unless there is more text in current sequence.
611 : : %<S remove all occurrences of -S from the command line.
612 : : Note - this command is position dependent. % commands in the
613 : : spec string before this one will see -S, % commands in the
614 : : spec string after this one will not.
615 : : %>S Similar to "%<S", but keep it in the GCC command line.
616 : : %<S* remove all occurrences of all switches beginning with -S from the
617 : : command line.
618 : : %:function(args)
619 : : Call the named function FUNCTION, passing it ARGS. ARGS is
620 : : first processed as a nested spec string, then split into an
621 : : argument vector in the usual fashion. The function returns
622 : : a string which is processed as if it had appeared literally
623 : : as part of the current spec.
624 : : %{S} substitutes the -S switch, if that switch was given to GCC.
625 : : If that switch was not specified, this substitutes nothing.
626 : : Here S is a metasyntactic variable.
627 : : %{S*} substitutes all the switches specified to GCC whose names start
628 : : with -S. This is used for -o, -I, etc; switches that take
629 : : arguments. GCC considers `-o foo' as being one switch whose
630 : : name starts with `o'. %{o*} would substitute this text,
631 : : including the space; thus, two arguments would be generated.
632 : : %{S*&T*} likewise, but preserve order of S and T options (the order
633 : : of S and T in the spec is not significant). Can be any number
634 : : of ampersand-separated variables; for each the wild card is
635 : : optional. Useful for CPP as %{D*&U*&A*}.
636 : :
637 : : %{S:X} substitutes X, if the -S switch was given to GCC.
638 : : %{!S:X} substitutes X, if the -S switch was NOT given to GCC.
639 : : %{S*:X} substitutes X if one or more switches whose names start
640 : : with -S was given to GCC. Normally X is substituted only
641 : : once, no matter how many such switches appeared. However,
642 : : if %* appears somewhere in X, then X will be substituted
643 : : once for each matching switch, with the %* replaced by the
644 : : part of that switch that matched the '*'. A space will be
645 : : appended after the last substition unless there is more
646 : : text in current sequence.
647 : : %{.S:X} substitutes X, if processing a file with suffix S.
648 : : %{!.S:X} substitutes X, if NOT processing a file with suffix S.
649 : : %{,S:X} substitutes X, if processing a file which will use spec S.
650 : : %{!,S:X} substitutes X, if NOT processing a file which will use spec S.
651 : :
652 : : %{S|T:X} substitutes X if either -S or -T was given to GCC. This may be
653 : : combined with '!', '.', ',', and '*' as above binding stronger
654 : : than the OR.
655 : : If %* appears in X, all of the alternatives must be starred, and
656 : : only the first matching alternative is substituted.
657 : : %{%:function(args):X}
658 : : Call function named FUNCTION with args ARGS. If the function
659 : : returns non-NULL, then X is substituted, if it returns
660 : : NULL, it isn't substituted.
661 : : %{S:X; if S was given to GCC, substitutes X;
662 : : T:Y; else if T was given to GCC, substitutes Y;
663 : : :D} else substitutes D. There can be as many clauses as you need.
664 : : This may be combined with '.', '!', ',', '|', and '*' as above.
665 : :
666 : : %(Spec) processes a specification defined in a specs file as *Spec:
667 : :
668 : : The switch matching text S in a %{S}, %{S:X}, or similar construct can use
669 : : a backslash to ignore the special meaning of the character following it,
670 : : thus allowing literal matching of a character that is otherwise specially
671 : : treated. For example, %{std=iso9899\:1999:X} substitutes X if the
672 : : -std=iso9899:1999 option is given.
673 : :
674 : : The conditional text X in a %{S:X} or similar construct may contain
675 : : other nested % constructs or spaces, or even newlines. They are
676 : : processed as usual, as described above. Trailing white space in X is
677 : : ignored. White space may also appear anywhere on the left side of the
678 : : colon in these constructs, except between . or * and the corresponding
679 : : word.
680 : :
681 : : The -O, -f, -g, -m, and -W switches are handled specifically in these
682 : : constructs. If another value of -O or the negated form of a -f, -m, or
683 : : -W switch is found later in the command line, the earlier switch
684 : : value is ignored, except with {S*} where S is just one letter; this
685 : : passes all matching options.
686 : :
687 : : The character | at the beginning of the predicate text is used to indicate
688 : : that a command should be piped to the following command, but only if -pipe
689 : : is specified.
690 : :
691 : : Note that it is built into GCC which switches take arguments and which
692 : : do not. You might think it would be useful to generalize this to
693 : : allow each compiler's spec to say which switches take arguments. But
694 : : this cannot be done in a consistent fashion. GCC cannot even decide
695 : : which input files have been specified without knowing which switches
696 : : take arguments, and it must know which input files to compile in order
697 : : to tell which compilers to run.
698 : :
699 : : GCC also knows implicitly that arguments starting in `-l' are to be
700 : : treated as compiler output files, and passed to the linker in their
701 : : proper position among the other output files. */
702 : :
703 : : /* Define the macros used for specs %a, %l, %L, %S, %C, %1. */
704 : :
705 : : /* config.h can define ASM_SPEC to provide extra args to the assembler
706 : : or extra switch-translations. */
707 : : #ifndef ASM_SPEC
708 : : #define ASM_SPEC ""
709 : : #endif
710 : :
711 : : /* config.h can define ASM_FINAL_SPEC to run a post processor after
712 : : the assembler has run. */
713 : : #ifndef ASM_FINAL_SPEC
714 : : #define ASM_FINAL_SPEC \
715 : : "%{gsplit-dwarf: \n\
716 : : objcopy --extract-dwo \
717 : : %{c:%{o*:%*}%{!o*:%w%b%O}}%{!c:%U%O} \
718 : : %b.dwo \n\
719 : : objcopy --strip-dwo \
720 : : %{c:%{o*:%*}%{!o*:%w%b%O}}%{!c:%U%O} \
721 : : }"
722 : : #endif
723 : :
724 : : /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
725 : : or extra switch-translations. */
726 : : #ifndef CPP_SPEC
727 : : #define CPP_SPEC ""
728 : : #endif
729 : :
730 : : /* Operating systems can define OS_CC1_SPEC to provide extra args to cc1 and
731 : : cc1plus or extra switch-translations. The OS_CC1_SPEC is appended
732 : : to CC1_SPEC in the initialization of cc1_spec. */
733 : : #ifndef OS_CC1_SPEC
734 : : #define OS_CC1_SPEC ""
735 : : #endif
736 : :
737 : : /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
738 : : or extra switch-translations. */
739 : : #ifndef CC1_SPEC
740 : : #define CC1_SPEC ""
741 : : #endif
742 : :
743 : : /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
744 : : or extra switch-translations. */
745 : : #ifndef CC1PLUS_SPEC
746 : : #define CC1PLUS_SPEC ""
747 : : #endif
748 : :
749 : : /* config.h can define LINK_SPEC to provide extra args to the linker
750 : : or extra switch-translations. */
751 : : #ifndef LINK_SPEC
752 : : #define LINK_SPEC ""
753 : : #endif
754 : :
755 : : /* config.h can define LIB_SPEC to override the default libraries. */
756 : : #ifndef LIB_SPEC
757 : : #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
758 : : #endif
759 : :
760 : : /* When using -fsplit-stack we need to wrap pthread_create, in order
761 : : to initialize the stack guard. We always use wrapping, rather than
762 : : shared library ordering, and we keep the wrapper function in
763 : : libgcc. This is not yet a real spec, though it could become one;
764 : : it is currently just stuffed into LINK_SPEC. FIXME: This wrapping
765 : : only works with GNU ld and gold. */
766 : : #ifdef HAVE_GOLD_NON_DEFAULT_SPLIT_STACK
767 : : #define STACK_SPLIT_SPEC " %{fsplit-stack: -fuse-ld=gold --wrap=pthread_create}"
768 : : #else
769 : : #define STACK_SPLIT_SPEC " %{fsplit-stack: --wrap=pthread_create}"
770 : : #endif
771 : :
772 : : #ifndef LIBASAN_SPEC
773 : : #define STATIC_LIBASAN_LIBS \
774 : : " %{static-libasan|static:%:include(libsanitizer.spec)%(link_libasan)}"
775 : : #ifdef LIBASAN_EARLY_SPEC
776 : : #define LIBASAN_SPEC STATIC_LIBASAN_LIBS
777 : : #elif defined(HAVE_LD_STATIC_DYNAMIC)
778 : : #define LIBASAN_SPEC "%{static-libasan:" LD_STATIC_OPTION \
779 : : "} -lasan %{static-libasan:" LD_DYNAMIC_OPTION "}" \
780 : : STATIC_LIBASAN_LIBS
781 : : #else
782 : : #define LIBASAN_SPEC "-lasan" STATIC_LIBASAN_LIBS
783 : : #endif
784 : : #endif
785 : :
786 : : #ifndef LIBASAN_EARLY_SPEC
787 : : #define LIBASAN_EARLY_SPEC ""
788 : : #endif
789 : :
790 : : #ifndef LIBHWASAN_SPEC
791 : : #define STATIC_LIBHWASAN_LIBS \
792 : : " %{static-libhwasan|static:%:include(libsanitizer.spec)%(link_libhwasan)}"
793 : : #ifdef LIBHWASAN_EARLY_SPEC
794 : : #define LIBHWASAN_SPEC STATIC_LIBHWASAN_LIBS
795 : : #elif defined(HAVE_LD_STATIC_DYNAMIC)
796 : : #define LIBHWASAN_SPEC "%{static-libhwasan:" LD_STATIC_OPTION \
797 : : "} -lhwasan %{static-libhwasan:" LD_DYNAMIC_OPTION "}" \
798 : : STATIC_LIBHWASAN_LIBS
799 : : #else
800 : : #define LIBHWASAN_SPEC "-lhwasan" STATIC_LIBHWASAN_LIBS
801 : : #endif
802 : : #endif
803 : :
804 : : #ifndef LIBHWASAN_EARLY_SPEC
805 : : #define LIBHWASAN_EARLY_SPEC ""
806 : : #endif
807 : :
808 : : #ifndef LIBTSAN_SPEC
809 : : #define STATIC_LIBTSAN_LIBS \
810 : : " %{static-libtsan|static:%:include(libsanitizer.spec)%(link_libtsan)}"
811 : : #ifdef LIBTSAN_EARLY_SPEC
812 : : #define LIBTSAN_SPEC STATIC_LIBTSAN_LIBS
813 : : #elif defined(HAVE_LD_STATIC_DYNAMIC)
814 : : #define LIBTSAN_SPEC "%{static-libtsan:" LD_STATIC_OPTION \
815 : : "} -ltsan %{static-libtsan:" LD_DYNAMIC_OPTION "}" \
816 : : STATIC_LIBTSAN_LIBS
817 : : #else
818 : : #define LIBTSAN_SPEC "-ltsan" STATIC_LIBTSAN_LIBS
819 : : #endif
820 : : #endif
821 : :
822 : : #ifndef LIBTSAN_EARLY_SPEC
823 : : #define LIBTSAN_EARLY_SPEC ""
824 : : #endif
825 : :
826 : : #ifndef LIBLSAN_SPEC
827 : : #define STATIC_LIBLSAN_LIBS \
828 : : " %{static-liblsan|static:%:include(libsanitizer.spec)%(link_liblsan)}"
829 : : #ifdef LIBLSAN_EARLY_SPEC
830 : : #define LIBLSAN_SPEC STATIC_LIBLSAN_LIBS
831 : : #elif defined(HAVE_LD_STATIC_DYNAMIC)
832 : : #define LIBLSAN_SPEC "%{static-liblsan:" LD_STATIC_OPTION \
833 : : "} -llsan %{static-liblsan:" LD_DYNAMIC_OPTION "}" \
834 : : STATIC_LIBLSAN_LIBS
835 : : #else
836 : : #define LIBLSAN_SPEC "-llsan" STATIC_LIBLSAN_LIBS
837 : : #endif
838 : : #endif
839 : :
840 : : #ifndef LIBLSAN_EARLY_SPEC
841 : : #define LIBLSAN_EARLY_SPEC ""
842 : : #endif
843 : :
844 : : #ifndef LIBUBSAN_SPEC
845 : : #define STATIC_LIBUBSAN_LIBS \
846 : : " %{static-libubsan|static:%:include(libsanitizer.spec)%(link_libubsan)}"
847 : : #ifdef HAVE_LD_STATIC_DYNAMIC
848 : : #define LIBUBSAN_SPEC "%{static-libubsan:" LD_STATIC_OPTION \
849 : : "} -lubsan %{static-libubsan:" LD_DYNAMIC_OPTION "}" \
850 : : STATIC_LIBUBSAN_LIBS
851 : : #else
852 : : #define LIBUBSAN_SPEC "-lubsan" STATIC_LIBUBSAN_LIBS
853 : : #endif
854 : : #endif
855 : :
856 : : /* Linker options for compressed debug sections. */
857 : : #if HAVE_LD_COMPRESS_DEBUG == 0
858 : : /* No linker support. */
859 : : #define LINK_COMPRESS_DEBUG_SPEC \
860 : : " %{gz*:%e-gz is not supported in this configuration} "
861 : : #elif HAVE_LD_COMPRESS_DEBUG == 1
862 : : /* ELF gABI style. */
863 : : #define LINK_COMPRESS_DEBUG_SPEC \
864 : : " %{gz|gz=zlib:" LD_COMPRESS_DEBUG_OPTION "=zlib}" \
865 : : " %{gz=none:" LD_COMPRESS_DEBUG_OPTION "=none}" \
866 : : " %{gz=zstd:%e-gz=zstd is not supported in this configuration} " \
867 : : " %{gz=zlib-gnu:}" /* Ignore silently zlib-gnu option value. */
868 : : #elif HAVE_LD_COMPRESS_DEBUG == 2
869 : : /* ELF gABI style and ZSTD. */
870 : : #define LINK_COMPRESS_DEBUG_SPEC \
871 : : " %{gz|gz=zlib:" LD_COMPRESS_DEBUG_OPTION "=zlib}" \
872 : : " %{gz=none:" LD_COMPRESS_DEBUG_OPTION "=none}" \
873 : : " %{gz=zstd:" LD_COMPRESS_DEBUG_OPTION "=zstd}" \
874 : : " %{gz=zlib-gnu:}" /* Ignore silently zlib-gnu option value. */
875 : : #else
876 : : #error Unknown value for HAVE_LD_COMPRESS_DEBUG.
877 : : #endif
878 : :
879 : : /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
880 : : included. */
881 : : #ifndef LIBGCC_SPEC
882 : : #if defined(REAL_LIBGCC_SPEC)
883 : : #define LIBGCC_SPEC REAL_LIBGCC_SPEC
884 : : #elif defined(LINK_LIBGCC_SPECIAL_1)
885 : : /* Have gcc do the search for libgcc.a. */
886 : : #define LIBGCC_SPEC "libgcc.a%s"
887 : : #else
888 : : #define LIBGCC_SPEC "-lgcc"
889 : : #endif
890 : : #endif
891 : :
892 : : /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
893 : : #ifndef STARTFILE_SPEC
894 : : #define STARTFILE_SPEC \
895 : : "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
896 : : #endif
897 : :
898 : : /* config.h can define ENDFILE_SPEC to override the default crtn files. */
899 : : #ifndef ENDFILE_SPEC
900 : : #define ENDFILE_SPEC ""
901 : : #endif
902 : :
903 : : #ifndef LINKER_NAME
904 : : #define LINKER_NAME "collect2"
905 : : #endif
906 : :
907 : : #ifdef HAVE_AS_DEBUG_PREFIX_MAP
908 : : #define ASM_MAP " %{ffile-prefix-map=*:--debug-prefix-map %*} %{fdebug-prefix-map=*:--debug-prefix-map %*}"
909 : : #else
910 : : #define ASM_MAP ""
911 : : #endif
912 : :
913 : : /* Assembler options for compressed debug sections. */
914 : : #if HAVE_LD_COMPRESS_DEBUG == 0
915 : : /* Reject if the linker cannot write compressed debug sections. */
916 : : #define ASM_COMPRESS_DEBUG_SPEC \
917 : : " %{gz*:%e-gz is not supported in this configuration} "
918 : : #else /* HAVE_LD_COMPRESS_DEBUG >= 1 */
919 : : #if HAVE_AS_COMPRESS_DEBUG == 0
920 : : /* No assembler support. Ignore silently. */
921 : : #define ASM_COMPRESS_DEBUG_SPEC \
922 : : " %{gz*:} "
923 : : #elif HAVE_AS_COMPRESS_DEBUG == 1
924 : : /* ELF gABI style. */
925 : : #define ASM_COMPRESS_DEBUG_SPEC \
926 : : " %{gz|gz=zlib:" AS_COMPRESS_DEBUG_OPTION "=zlib}" \
927 : : " %{gz=none:" AS_COMPRESS_DEBUG_OPTION "=none}" \
928 : : " %{gz=zlib-gnu:}" /* Ignore silently zlib-gnu option value. */
929 : : #elif HAVE_AS_COMPRESS_DEBUG == 2
930 : : /* ELF gABI style and ZSTD. */
931 : : #define ASM_COMPRESS_DEBUG_SPEC \
932 : : " %{gz|gz=zlib:" AS_COMPRESS_DEBUG_OPTION "=zlib}" \
933 : : " %{gz=none:" AS_COMPRESS_DEBUG_OPTION "=none}" \
934 : : " %{gz=zstd:" AS_COMPRESS_DEBUG_OPTION "=zstd}" \
935 : : " %{gz=zlib-gnu:}" /* Ignore silently zlib-gnu option value. */
936 : : #else
937 : : #error Unknown value for HAVE_AS_COMPRESS_DEBUG.
938 : : #endif
939 : : #endif /* HAVE_LD_COMPRESS_DEBUG >= 1 */
940 : :
941 : : /* Define ASM_DEBUG_SPEC to be a spec suitable for translating '-g'
942 : : to the assembler, when compiling assembly sources only. */
943 : : #ifndef ASM_DEBUG_SPEC
944 : : # if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG)
945 : : /* If --gdwarf-N is supported and as can handle even compiler generated
946 : : .debug_line with it, supply --gdwarf-N in ASM_DEBUG_OPTION_SPEC rather
947 : : than in ASM_DEBUG_SPEC, so that it applies to both .s and .c etc.
948 : : compilations. */
949 : : # define ASM_DEBUG_DWARF_OPTION ""
950 : : # elif defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && !defined(HAVE_LD_BROKEN_PE_DWARF5)
951 : : # define ASM_DEBUG_DWARF_OPTION "%{%:dwarf-version-gt(4):--gdwarf-5;" \
952 : : "%:dwarf-version-gt(3):--gdwarf-4;" \
953 : : "%:dwarf-version-gt(2):--gdwarf-3;" \
954 : : ":--gdwarf2}"
955 : : # else
956 : : # define ASM_DEBUG_DWARF_OPTION "--gdwarf2"
957 : : # endif
958 : : # if defined(DWARF2_DEBUGGING_INFO) && defined(HAVE_AS_GDWARF2_DEBUG_FLAG)
959 : : # define ASM_DEBUG_SPEC "%{g*:%{%:debug-level-gt(0):" \
960 : : ASM_DEBUG_DWARF_OPTION "}}" ASM_MAP
961 : : # endif
962 : : # endif
963 : : #ifndef ASM_DEBUG_SPEC
964 : : # define ASM_DEBUG_SPEC ""
965 : : #endif
966 : :
967 : : /* Define ASM_DEBUG_OPTION_SPEC to be a spec suitable for translating '-g'
968 : : to the assembler when compiling all sources. */
969 : : #ifndef ASM_DEBUG_OPTION_SPEC
970 : : # if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG)
971 : : # define ASM_DEBUG_OPTION_DWARF_OPT \
972 : : "%{%:dwarf-version-gt(4):--gdwarf-5 ;" \
973 : : "%:dwarf-version-gt(3):--gdwarf-4 ;" \
974 : : "%:dwarf-version-gt(2):--gdwarf-3 ;" \
975 : : ":--gdwarf2 }"
976 : : # if defined(DWARF2_DEBUGGING_INFO)
977 : : # define ASM_DEBUG_OPTION_SPEC "%{g*:%{%:debug-level-gt(0):" \
978 : : ASM_DEBUG_OPTION_DWARF_OPT "}}"
979 : : # endif
980 : : # endif
981 : : #endif
982 : : #ifndef ASM_DEBUG_OPTION_SPEC
983 : : # define ASM_DEBUG_OPTION_SPEC ""
984 : : #endif
985 : :
986 : : /* Here is the spec for running the linker, after compiling all files. */
987 : :
988 : : #if defined(TARGET_PROVIDES_LIBATOMIC) && defined(USE_LD_AS_NEEDED)
989 : : #define LINK_LIBATOMIC_SPEC "%{!fno-link-libatomic:" LD_AS_NEEDED_OPTION \
990 : : " -latomic " LD_NO_AS_NEEDED_OPTION "} "
991 : : #else
992 : : #define LINK_LIBATOMIC_SPEC ""
993 : : #endif
994 : :
995 : : /* This is overridable by the target in case they need to specify the
996 : : -lgcc and -lc order specially, yet not require them to override all
997 : : of LINK_COMMAND_SPEC. */
998 : : #ifndef LINK_GCC_C_SEQUENCE_SPEC
999 : : #define LINK_GCC_C_SEQUENCE_SPEC "%G %{!nolibc:%L %G}"
1000 : : #endif
1001 : :
1002 : : #ifndef LINK_SSP_SPEC
1003 : : #ifdef TARGET_LIBC_PROVIDES_SSP
1004 : : #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \
1005 : : "|fstack-protector-strong|fstack-protector-explicit:}"
1006 : : #else
1007 : : #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \
1008 : : "|fstack-protector-strong|fstack-protector-explicit" \
1009 : : ":-lssp_nonshared -lssp}"
1010 : : #endif
1011 : : #endif
1012 : :
1013 : : #ifdef ENABLE_DEFAULT_PIE
1014 : : #define PIE_SPEC "!no-pie"
1015 : : #define NO_FPIE1_SPEC "fno-pie"
1016 : : #define FPIE1_SPEC NO_FPIE1_SPEC ":;"
1017 : : #define NO_FPIE2_SPEC "fno-PIE"
1018 : : #define FPIE2_SPEC NO_FPIE2_SPEC ":;"
1019 : : #define NO_FPIE_SPEC NO_FPIE1_SPEC "|" NO_FPIE2_SPEC
1020 : : #define FPIE_SPEC NO_FPIE_SPEC ":;"
1021 : : #define NO_FPIC1_SPEC "fno-pic"
1022 : : #define FPIC1_SPEC NO_FPIC1_SPEC ":;"
1023 : : #define NO_FPIC2_SPEC "fno-PIC"
1024 : : #define FPIC2_SPEC NO_FPIC2_SPEC ":;"
1025 : : #define NO_FPIC_SPEC NO_FPIC1_SPEC "|" NO_FPIC2_SPEC
1026 : : #define FPIC_SPEC NO_FPIC_SPEC ":;"
1027 : : #define NO_FPIE1_AND_FPIC1_SPEC NO_FPIE1_SPEC "|" NO_FPIC1_SPEC
1028 : : #define FPIE1_OR_FPIC1_SPEC NO_FPIE1_AND_FPIC1_SPEC ":;"
1029 : : #define NO_FPIE2_AND_FPIC2_SPEC NO_FPIE2_SPEC "|" NO_FPIC2_SPEC
1030 : : #define FPIE2_OR_FPIC2_SPEC NO_FPIE2_AND_FPIC2_SPEC ":;"
1031 : : #define NO_FPIE_AND_FPIC_SPEC NO_FPIE_SPEC "|" NO_FPIC_SPEC
1032 : : #define FPIE_OR_FPIC_SPEC NO_FPIE_AND_FPIC_SPEC ":;"
1033 : : #else
1034 : : #define PIE_SPEC "pie"
1035 : : #define FPIE1_SPEC "fpie"
1036 : : #define NO_FPIE1_SPEC FPIE1_SPEC ":;"
1037 : : #define FPIE2_SPEC "fPIE"
1038 : : #define NO_FPIE2_SPEC FPIE2_SPEC ":;"
1039 : : #define FPIE_SPEC FPIE1_SPEC "|" FPIE2_SPEC
1040 : : #define NO_FPIE_SPEC FPIE_SPEC ":;"
1041 : : #define FPIC1_SPEC "fpic"
1042 : : #define NO_FPIC1_SPEC FPIC1_SPEC ":;"
1043 : : #define FPIC2_SPEC "fPIC"
1044 : : #define NO_FPIC2_SPEC FPIC2_SPEC ":;"
1045 : : #define FPIC_SPEC FPIC1_SPEC "|" FPIC2_SPEC
1046 : : #define NO_FPIC_SPEC FPIC_SPEC ":;"
1047 : : #define FPIE1_OR_FPIC1_SPEC FPIE1_SPEC "|" FPIC1_SPEC
1048 : : #define NO_FPIE1_AND_FPIC1_SPEC FPIE1_OR_FPIC1_SPEC ":;"
1049 : : #define FPIE2_OR_FPIC2_SPEC FPIE2_SPEC "|" FPIC2_SPEC
1050 : : #define NO_FPIE2_AND_FPIC2_SPEC FPIE1_OR_FPIC2_SPEC ":;"
1051 : : #define FPIE_OR_FPIC_SPEC FPIE_SPEC "|" FPIC_SPEC
1052 : : #define NO_FPIE_AND_FPIC_SPEC FPIE_OR_FPIC_SPEC ":;"
1053 : : #endif
1054 : :
1055 : : #ifndef LINK_PIE_SPEC
1056 : : #ifdef HAVE_LD_PIE
1057 : : #ifndef LD_PIE_SPEC
1058 : : #define LD_PIE_SPEC "-pie"
1059 : : #endif
1060 : : #else
1061 : : #define LD_PIE_SPEC ""
1062 : : #endif
1063 : : #define LINK_PIE_SPEC "%{static|shared|r:;" PIE_SPEC ":" LD_PIE_SPEC "} "
1064 : : #endif
1065 : :
1066 : : #ifndef LINK_BUILDID_SPEC
1067 : : # if defined(HAVE_LD_BUILDID) && defined(ENABLE_LD_BUILDID)
1068 : : # define LINK_BUILDID_SPEC "%{!r:--build-id} "
1069 : : # endif
1070 : : #endif
1071 : :
1072 : : #ifndef LTO_PLUGIN_SPEC
1073 : : #define LTO_PLUGIN_SPEC ""
1074 : : #endif
1075 : :
1076 : : /* Conditional to test whether the LTO plugin is used or not.
1077 : : FIXME: For slim LTO we will need to enable plugin unconditionally. This
1078 : : still cause problems with PLUGIN_LD != LD and when plugin is built but
1079 : : not useable. For GCC 4.6 we don't support slim LTO and thus we can enable
1080 : : plugin only when LTO is enabled. We still honor explicit
1081 : : -fuse-linker-plugin if the linker used understands -plugin. */
1082 : :
1083 : : /* The linker has some plugin support. */
1084 : : #if HAVE_LTO_PLUGIN > 0
1085 : : /* The linker used has full plugin support, use LTO plugin by default. */
1086 : : #if HAVE_LTO_PLUGIN == 2
1087 : : #define PLUGIN_COND "!fno-use-linker-plugin:%{!fno-lto"
1088 : : #define PLUGIN_COND_CLOSE "}"
1089 : : #else
1090 : : /* The linker used has limited plugin support, use LTO plugin with explicit
1091 : : -fuse-linker-plugin. */
1092 : : #define PLUGIN_COND "fuse-linker-plugin"
1093 : : #define PLUGIN_COND_CLOSE ""
1094 : : #endif
1095 : : #define LINK_PLUGIN_SPEC \
1096 : : "%{" PLUGIN_COND": \
1097 : : -plugin %(linker_plugin_file) \
1098 : : -plugin-opt=%(lto_wrapper) \
1099 : : -plugin-opt=-fresolution=%u.res \
1100 : : " LTO_PLUGIN_SPEC "\
1101 : : %{flinker-output=*:-plugin-opt=-linker-output-known} \
1102 : : %{!nostdlib:%{!nodefaultlibs:%:pass-through-libs(%(link_gcc_c_sequence))}} \
1103 : : }" PLUGIN_COND_CLOSE
1104 : : #else
1105 : : /* The linker used doesn't support -plugin, reject -fuse-linker-plugin. */
1106 : : #define LINK_PLUGIN_SPEC "%{fuse-linker-plugin:\
1107 : : %e-fuse-linker-plugin is not supported in this configuration}"
1108 : : #endif
1109 : :
1110 : : /* Linker command line options for -fsanitize= early on the command line. */
1111 : : #ifndef SANITIZER_EARLY_SPEC
1112 : : #define SANITIZER_EARLY_SPEC "\
1113 : : %{!nostdlib:%{!r:%{!nodefaultlibs:%{%:sanitize(address):" LIBASAN_EARLY_SPEC "} \
1114 : : %{%:sanitize(hwaddress):" LIBHWASAN_EARLY_SPEC "} \
1115 : : %{%:sanitize(thread):" LIBTSAN_EARLY_SPEC "} \
1116 : : %{%:sanitize(leak):" LIBLSAN_EARLY_SPEC "}}}}"
1117 : : #endif
1118 : :
1119 : : /* Linker command line options for -fsanitize= late on the command line. */
1120 : : #ifndef SANITIZER_SPEC
1121 : : #define SANITIZER_SPEC "\
1122 : : %{!nostdlib:%{!r:%{!nodefaultlibs:%{%:sanitize(address):" LIBASAN_SPEC "\
1123 : : %{static:%ecannot specify -static with -fsanitize=address}}\
1124 : : %{%:sanitize(hwaddress):" LIBHWASAN_SPEC "\
1125 : : %{static:%ecannot specify -static with -fsanitize=hwaddress}}\
1126 : : %{%:sanitize(thread):" LIBTSAN_SPEC "\
1127 : : %{static:%ecannot specify -static with -fsanitize=thread}}\
1128 : : %{%:sanitize(undefined):" LIBUBSAN_SPEC "}\
1129 : : %{%:sanitize(leak):" LIBLSAN_SPEC "}}}}"
1130 : : #endif
1131 : :
1132 : : #ifndef POST_LINK_SPEC
1133 : : #define POST_LINK_SPEC ""
1134 : : #endif
1135 : :
1136 : : /* This is the spec to use, once the code for creating the vtable
1137 : : verification runtime library, libvtv.so, has been created. Currently
1138 : : the vtable verification runtime functions are in libstdc++, so we use
1139 : : the spec just below this one. */
1140 : : #ifndef VTABLE_VERIFICATION_SPEC
1141 : : #if ENABLE_VTABLE_VERIFY
1142 : : #define VTABLE_VERIFICATION_SPEC "\
1143 : : %{!nostdlib:%{!r:%{fvtable-verify=std: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end}\
1144 : : %{fvtable-verify=preinit: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end}}}"
1145 : : #else
1146 : : #define VTABLE_VERIFICATION_SPEC "\
1147 : : %{fvtable-verify=none:} \
1148 : : %{fvtable-verify=std: \
1149 : : %e-fvtable-verify=std is not supported in this configuration} \
1150 : : %{fvtable-verify=preinit: \
1151 : : %e-fvtable-verify=preinit is not supported in this configuration}"
1152 : : #endif
1153 : : #endif
1154 : :
1155 : : /* -u* was put back because both BSD and SysV seem to support it. */
1156 : : /* %{static|no-pie|static-pie:} simply prevents an error message:
1157 : : 1. If the target machine doesn't handle -static.
1158 : : 2. If PIE isn't enabled by default.
1159 : : 3. If the target machine doesn't handle -static-pie.
1160 : : */
1161 : : /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
1162 : : scripts which exist in user specified directories, or in standard
1163 : : directories. */
1164 : : /* We pass any -flto flags on to the linker, which is expected
1165 : : to understand them. In practice, this means it had better be collect2. */
1166 : : /* %{e*} includes -export-dynamic; see comment in common.opt. */
1167 : : #ifndef LINK_COMMAND_SPEC
1168 : : #define LINK_COMMAND_SPEC "\
1169 : : %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
1170 : : %(linker) " \
1171 : : LINK_PLUGIN_SPEC \
1172 : : "%{flto|flto=*:%<fcompare-debug*} \
1173 : : %{flto} %{fno-lto} %{flto=*} %l " LINK_PIE_SPEC \
1174 : : "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \
1175 : : "%X %{o*} %{e*} %{N} %{n} %{r}\
1176 : : %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \
1177 : : %{static|no-pie|static-pie:} %@{L*} %(link_libgcc) " \
1178 : : VTABLE_VERIFICATION_SPEC " " SANITIZER_EARLY_SPEC " %o "" \
1179 : : %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\
1180 : : %:include(libgomp.spec)%(link_gomp)}\
1181 : : %{fgnu-tm:%:include(libitm.spec)%(link_itm)}\
1182 : : " STACK_SPLIT_SPEC "\
1183 : : %{fprofile-arcs|fcondition-coverage|fpath-coverage|fprofile-generate*|coverage:-lgcov} " SANITIZER_SPEC " \
1184 : : %{!nostdlib:%{!r:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}}\
1185 : : %{!nostdlib:%{!r:%{!nostartfiles:%E}}} %{T*} \n%(post_link) }}}}}}"
1186 : : #endif
1187 : :
1188 : : #ifndef LINK_LIBGCC_SPEC
1189 : : /* Generate -L options for startfile prefix list. */
1190 : : # define LINK_LIBGCC_SPEC "%D"
1191 : : #endif
1192 : :
1193 : : #ifndef STARTFILE_PREFIX_SPEC
1194 : : # define STARTFILE_PREFIX_SPEC ""
1195 : : #endif
1196 : :
1197 : : #ifndef SYSROOT_SPEC
1198 : : # define SYSROOT_SPEC "--sysroot=%R"
1199 : : #endif
1200 : :
1201 : : #ifndef SYSROOT_SUFFIX_SPEC
1202 : : # define SYSROOT_SUFFIX_SPEC ""
1203 : : #endif
1204 : :
1205 : : #ifndef SYSROOT_HEADERS_SUFFIX_SPEC
1206 : : # define SYSROOT_HEADERS_SUFFIX_SPEC ""
1207 : : #endif
1208 : :
1209 : : #ifndef RUNPATH_OPTION
1210 : : # define RUNPATH_OPTION "-rpath"
1211 : : #endif
1212 : :
1213 : : static const char *asm_debug = ASM_DEBUG_SPEC;
1214 : : static const char *asm_debug_option = ASM_DEBUG_OPTION_SPEC;
1215 : : static const char *cpp_spec = CPP_SPEC;
1216 : : static const char *cc1_spec = CC1_SPEC OS_CC1_SPEC;
1217 : : static const char *cc1plus_spec = CC1PLUS_SPEC;
1218 : : static const char *link_gcc_c_sequence_spec = LINK_GCC_C_SEQUENCE_SPEC;
1219 : : static const char *link_ssp_spec = LINK_SSP_SPEC;
1220 : : static const char *asm_spec = ASM_SPEC;
1221 : : static const char *asm_final_spec = ASM_FINAL_SPEC;
1222 : : static const char *link_spec = LINK_SPEC;
1223 : : static const char *lib_spec = LIB_SPEC;
1224 : : static const char *link_gomp_spec = "";
1225 : : static const char *libgcc_spec = LIBGCC_SPEC;
1226 : : static const char *endfile_spec = ENDFILE_SPEC;
1227 : : static const char *startfile_spec = STARTFILE_SPEC;
1228 : : static const char *linker_name_spec = LINKER_NAME;
1229 : : static const char *linker_plugin_file_spec = "";
1230 : : static const char *lto_wrapper_spec = "";
1231 : : static const char *lto_gcc_spec = "";
1232 : : static const char *post_link_spec = POST_LINK_SPEC;
1233 : : static const char *link_command_spec = LINK_COMMAND_SPEC;
1234 : : static const char *link_libgcc_spec = LINK_LIBGCC_SPEC;
1235 : : static const char *startfile_prefix_spec = STARTFILE_PREFIX_SPEC;
1236 : : static const char *sysroot_spec = SYSROOT_SPEC;
1237 : : static const char *sysroot_suffix_spec = SYSROOT_SUFFIX_SPEC;
1238 : : static const char *sysroot_hdrs_suffix_spec = SYSROOT_HEADERS_SUFFIX_SPEC;
1239 : : static const char *self_spec = "";
1240 : :
1241 : : /* Standard options to cpp, cc1, and as, to reduce duplication in specs.
1242 : : There should be no need to override these in target dependent files,
1243 : : but we need to copy them to the specs file so that newer versions
1244 : : of the GCC driver can correctly drive older tool chains with the
1245 : : appropriate -B options. */
1246 : :
1247 : : /* When cpplib handles traditional preprocessing, get rid of this, and
1248 : : call cc1 (or cc1obj in objc/lang-specs.h) from the main specs so
1249 : : that we default the front end language better. */
1250 : : static const char *trad_capable_cpp =
1251 : : "cc1 -E %{traditional|traditional-cpp:-traditional-cpp}";
1252 : :
1253 : : /* We don't wrap .d files in %W{} since a missing .d file, and
1254 : : therefore no dependency entry, confuses make into thinking a .o
1255 : : file that happens to exist is up-to-date. */
1256 : : static const char *cpp_unique_options =
1257 : : "%{!Q:-quiet} %{nostdinc*} %{C} %{CC} %{v} %@{I*&F*} %{P} %I\
1258 : : %{MD:-MD %{!o:%b.d}%{o*:%.d%*}}\
1259 : : %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}}\
1260 : : %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\
1261 : : %{Mmodules} %{Mno-modules}\
1262 : : %{!E:%{!M:%{!MM:%{!MT:%{!MQ:%{MD|MMD:%{o*:-MQ %*}}}}}}}\
1263 : : %{remap} %{%:debug-level-gt(2):-dD}\
1264 : : %{!iplugindir*:%{fplugin*:%:find-plugindir()}}\
1265 : : %{H} %C %{D*&U*&A*} %{i*} %Z %i\
1266 : : %{E|M|MM:%W{o*}} %{-embed*}\
1267 : : %{fdeps-format=*:%{!fdeps-file=*:-fdeps-file=%:join(%{!o:%b.ddi}%{o*:%.ddi%*})}}\
1268 : : %{fdeps-format=*:%{!fdeps-target=*:-fdeps-target=%:join(%{!o:%b.o}%{o*:%.o%*})}}";
1269 : :
1270 : : /* This contains cpp options which are common with cc1_options and are passed
1271 : : only when preprocessing only to avoid duplication. We pass the cc1 spec
1272 : : options to the preprocessor so that it the cc1 spec may manipulate
1273 : : options used to set target flags. Those special target flags settings may
1274 : : in turn cause preprocessor symbols to be defined specially. */
1275 : : static const char *cpp_options =
1276 : : "%(cpp_unique_options) %1 %{m*} %{std*&ansi&trigraphs} %{W*&pedantic*} %{w}\
1277 : : %{f*} %{g*:%{%:debug-level-gt(0):%{g*}\
1278 : : %{!fno-working-directory:-fworking-directory}}} %{O*}\
1279 : : %{undef} %{save-temps*:-fpch-preprocess}";
1280 : :
1281 : : /* Pass -d* flags, possibly modifying -dumpdir, -dumpbase et al.
1282 : :
1283 : : Make it easy for a language to override the argument for the
1284 : : %:dumps specs function call. */
1285 : : #define DUMPS_OPTIONS(EXTS) \
1286 : : "%<dumpdir %<dumpbase %<dumpbase-ext %{d*} %:dumps(" EXTS ")"
1287 : :
1288 : : /* This contains cpp options which are not passed when the preprocessor
1289 : : output will be used by another program. */
1290 : : static const char *cpp_debug_options = DUMPS_OPTIONS ("");
1291 : :
1292 : : /* NB: This is shared amongst all front-ends, except for Ada. */
1293 : : static const char *cc1_options =
1294 : : "%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
1295 : : %{!iplugindir*:%{fplugin*:%:find-plugindir()}}\
1296 : : %1 %{!Q:-quiet} %(cpp_debug_options) %{m*} %{aux-info*}\
1297 : : %{g*} %{O*} %{W*&pedantic*} %{w} %{std*&ansi&trigraphs}\
1298 : : %{v:-version} %{pg:-p} %{p} %{f*} %{undef}\
1299 : : %{Qn:-fno-ident} %{Qy:} %{-help:--help}\
1300 : : %{-target-help:--target-help}\
1301 : : %{-version:--version}\
1302 : : %{-help=*:--help=%*}\
1303 : : %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %w%b.s}}}\
1304 : : %{fsyntax-only:-o %j} %{-param*}\
1305 : : %{coverage:-fprofile-arcs -ftest-coverage}\
1306 : : %{fprofile-arcs|fcondition-coverage|fpath-coverage|fprofile-generate*|coverage:\
1307 : : %{!fprofile-update=single:\
1308 : : %{pthread:-fprofile-update=prefer-atomic}}}";
1309 : :
1310 : : static const char *asm_options =
1311 : : "%{-target-help:%:print-asm-header()} "
1312 : : #if HAVE_GNU_AS
1313 : : /* If GNU AS is used, then convert -w (no warnings), -I, and -v
1314 : : to the assembler equivalents. */
1315 : : "%{v} %{w:-W} %{I*} "
1316 : : #endif
1317 : : "%(asm_debug_option)"
1318 : : ASM_COMPRESS_DEBUG_SPEC
1319 : : "%a %Y %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}";
1320 : :
1321 : : static const char *invoke_as =
1322 : : #ifdef AS_NEEDS_DASH_FOR_PIPED_INPUT
1323 : : "%{!fwpa*:\
1324 : : %{fcompare-debug=*|fdump-final-insns=*:%:compare-debug-dump-opt()}\
1325 : : %{!S:-o %|.s |\n as %(asm_options) %|.s %A }\
1326 : : }";
1327 : : #else
1328 : : "%{!fwpa*:\
1329 : : %{fcompare-debug=*|fdump-final-insns=*:%:compare-debug-dump-opt()}\
1330 : : %{!S:-o %|.s |\n as %(asm_options) %m.s %A }\
1331 : : }";
1332 : : #endif
1333 : :
1334 : : /* Some compilers have limits on line lengths, and the multilib_select
1335 : : and/or multilib_matches strings can be very long, so we build them at
1336 : : run time. */
1337 : : static struct obstack multilib_obstack;
1338 : : static const char *multilib_select;
1339 : : static const char *multilib_matches;
1340 : : static const char *multilib_defaults;
1341 : : static const char *multilib_exclusions;
1342 : : static const char *multilib_reuse;
1343 : :
1344 : : /* Check whether a particular argument is a default argument. */
1345 : :
1346 : : #ifndef MULTILIB_DEFAULTS
1347 : : #define MULTILIB_DEFAULTS { "" }
1348 : : #endif
1349 : :
1350 : : static const char *const multilib_defaults_raw[] = MULTILIB_DEFAULTS;
1351 : :
1352 : : #ifndef DRIVER_SELF_SPECS
1353 : : #define DRIVER_SELF_SPECS ""
1354 : : #endif
1355 : :
1356 : : /* Linking to libgomp implies pthreads. This is particularly important
1357 : : for targets that use different start files and suchlike. */
1358 : : #ifndef GOMP_SELF_SPECS
1359 : : #define GOMP_SELF_SPECS \
1360 : : "%{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1): " \
1361 : : "-pthread}"
1362 : : #endif
1363 : :
1364 : : /* Likewise for -fgnu-tm. */
1365 : : #ifndef GTM_SELF_SPECS
1366 : : #define GTM_SELF_SPECS "%{fgnu-tm: -pthread}"
1367 : : #endif
1368 : :
1369 : : static const char *const driver_self_specs[] = {
1370 : : "%{fdump-final-insns:-fdump-final-insns=.} %<fdump-final-insns",
1371 : : DRIVER_SELF_SPECS, CONFIGURE_SPECS, GOMP_SELF_SPECS, GTM_SELF_SPECS,
1372 : : /* This discards -fmultiflags at the end of self specs processing in the
1373 : : driver, so that it is effectively Ignored, without actually marking it as
1374 : : Ignored, which would get it discarded before self specs could remap it. */
1375 : : "%<fmultiflags"
1376 : : };
1377 : :
1378 : : #ifndef OPTION_DEFAULT_SPECS
1379 : : #define OPTION_DEFAULT_SPECS { "", "" }
1380 : : #endif
1381 : :
1382 : : struct default_spec
1383 : : {
1384 : : const char *name;
1385 : : const char *spec;
1386 : : };
1387 : :
1388 : : static const struct default_spec
1389 : : option_default_specs[] = { OPTION_DEFAULT_SPECS };
1390 : :
1391 : : struct user_specs
1392 : : {
1393 : : struct user_specs *next;
1394 : : const char *filename;
1395 : : };
1396 : :
1397 : : static struct user_specs *user_specs_head, *user_specs_tail;
1398 : :
1399 : :
1400 : : /* Record the mapping from file suffixes for compilation specs. */
1401 : :
1402 : : struct compiler
1403 : : {
1404 : : const char *suffix; /* Use this compiler for input files
1405 : : whose names end in this suffix. */
1406 : :
1407 : : const char *spec; /* To use this compiler, run this spec. */
1408 : :
1409 : : const char *cpp_spec; /* If non-NULL, substitute this spec
1410 : : for `%C', rather than the usual
1411 : : cpp_spec. */
1412 : : int combinable; /* If nonzero, compiler can deal with
1413 : : multiple source files at once (IMA). */
1414 : : int needs_preprocessing; /* If nonzero, source files need to
1415 : : be run through a preprocessor. */
1416 : : };
1417 : :
1418 : : /* Pointer to a vector of `struct compiler' that gives the spec for
1419 : : compiling a file, based on its suffix.
1420 : : A file that does not end in any of these suffixes will be passed
1421 : : unchanged to the loader and nothing else will be done to it.
1422 : :
1423 : : An entry containing two 0s is used to terminate the vector.
1424 : :
1425 : : If multiple entries match a file, the last matching one is used. */
1426 : :
1427 : : static struct compiler *compilers;
1428 : :
1429 : : /* Number of entries in `compilers', not counting the null terminator. */
1430 : :
1431 : : static int n_compilers;
1432 : :
1433 : : /* The default list of file name suffixes and their compilation specs. */
1434 : :
1435 : : static const struct compiler default_compilers[] =
1436 : : {
1437 : : /* Add lists of suffixes of known languages here. If those languages
1438 : : were not present when we built the driver, we will hit these copies
1439 : : and be given a more meaningful error than "file not used since
1440 : : linking is not done". */
1441 : : {".m", "#Objective-C", 0, 0, 0}, {".mi", "#Objective-C", 0, 0, 0},
1442 : : {".mm", "#Objective-C++", 0, 0, 0}, {".M", "#Objective-C++", 0, 0, 0},
1443 : : {".mii", "#Objective-C++", 0, 0, 0},
1444 : : {".cc", "#C++", 0, 0, 0}, {".cxx", "#C++", 0, 0, 0},
1445 : : {".cpp", "#C++", 0, 0, 0}, {".cp", "#C++", 0, 0, 0},
1446 : : {".c++", "#C++", 0, 0, 0}, {".C", "#C++", 0, 0, 0},
1447 : : {".CPP", "#C++", 0, 0, 0}, {".ii", "#C++", 0, 0, 0},
1448 : : {".ads", "#Ada", 0, 0, 0}, {".adb", "#Ada", 0, 0, 0},
1449 : : {".f", "#Fortran", 0, 0, 0}, {".F", "#Fortran", 0, 0, 0},
1450 : : {".for", "#Fortran", 0, 0, 0}, {".FOR", "#Fortran", 0, 0, 0},
1451 : : {".ftn", "#Fortran", 0, 0, 0}, {".FTN", "#Fortran", 0, 0, 0},
1452 : : {".fpp", "#Fortran", 0, 0, 0}, {".FPP", "#Fortran", 0, 0, 0},
1453 : : {".f90", "#Fortran", 0, 0, 0}, {".F90", "#Fortran", 0, 0, 0},
1454 : : {".f95", "#Fortran", 0, 0, 0}, {".F95", "#Fortran", 0, 0, 0},
1455 : : {".f03", "#Fortran", 0, 0, 0}, {".F03", "#Fortran", 0, 0, 0},
1456 : : {".f08", "#Fortran", 0, 0, 0}, {".F08", "#Fortran", 0, 0, 0},
1457 : : {".r", "#Ratfor", 0, 0, 0},
1458 : : {".go", "#Go", 0, 1, 0},
1459 : : {".d", "#D", 0, 1, 0}, {".dd", "#D", 0, 1, 0}, {".di", "#D", 0, 1, 0},
1460 : : {".mod", "#Modula-2", 0, 0, 0}, {".m2i", "#Modula-2", 0, 0, 0},
1461 : : /* Next come the entries for C. */
1462 : : {".c", "@c", 0, 0, 1},
1463 : : {"@c",
1464 : : /* cc1 has an integrated ISO C preprocessor. We should invoke the
1465 : : external preprocessor if -save-temps is given. */
1466 : : "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\
1467 : : %{!E:%{!M:%{!MM:\
1468 : : %{traditional:\
1469 : : %eGNU C no longer supports -traditional without -E}\
1470 : : %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \
1471 : : %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\
1472 : : cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \
1473 : : %(cc1_options)}\
1474 : : %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\
1475 : : cc1 %(cpp_unique_options) %(cc1_options)}}}\
1476 : : %{!fsyntax-only:%(invoke_as)}}}}", 0, 0, 1},
1477 : : {"-",
1478 : : "%{!E:%e-E or -x required when input is from standard input}\
1479 : : %(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)", 0, 0, 0},
1480 : : {".h", "@c-header", 0, 0, 0},
1481 : : {"@c-header",
1482 : : /* cc1 has an integrated ISO C preprocessor. We should invoke the
1483 : : external preprocessor if -save-temps is given. */
1484 : : "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\
1485 : : %{!E:%{!M:%{!MM:\
1486 : : %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \
1487 : : %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\
1488 : : cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \
1489 : : %(cc1_options)\
1490 : : %{!fsyntax-only:%{!S:-o %g.s} \
1491 : : %{!fdump-ada-spec*:%{!o*:--output-pch %w%i.gch}\
1492 : : %W{o*:--output-pch %w%*}}%{!S:%V}}}\
1493 : : %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\
1494 : : cc1 %(cpp_unique_options) %(cc1_options)\
1495 : : %{!fsyntax-only:%{!S:-o %g.s} \
1496 : : %{!fdump-ada-spec*:%{!o*:--output-pch %w%i.gch}\
1497 : : %W{o*:--output-pch %w%*}}%{!S:%V}}}}}}}}", 0, 0, 0},
1498 : : {".i", "@cpp-output", 0, 0, 0},
1499 : : {"@cpp-output",
1500 : : "%{!M:%{!MM:%{!E:cc1 -fpreprocessed %i %(cc1_options) %{!fsyntax-only:%(invoke_as)}}}}", 0, 0, 0},
1501 : : {".s", "@assembler", 0, 0, 0},
1502 : : {"@assembler",
1503 : : "%{!M:%{!MM:%{!E:%{!S:as %(asm_debug) %(asm_options) %i %A }}}}", 0, 0, 0},
1504 : : {".sx", "@assembler-with-cpp", 0, 0, 0},
1505 : : {".S", "@assembler-with-cpp", 0, 0, 0},
1506 : : {"@assembler-with-cpp",
1507 : : #ifdef AS_NEEDS_DASH_FOR_PIPED_INPUT
1508 : : "%(trad_capable_cpp) -lang-asm %(cpp_options) -fno-directives-only\
1509 : : %{E|M|MM:%(cpp_debug_options)}\
1510 : : %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\
1511 : : as %(asm_debug) %(asm_options) %|.s %A }}}}"
1512 : : #else
1513 : : "%(trad_capable_cpp) -lang-asm %(cpp_options) -fno-directives-only\
1514 : : %{E|M|MM:%(cpp_debug_options)}\
1515 : : %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\
1516 : : as %(asm_debug) %(asm_options) %m.s %A }}}}"
1517 : : #endif
1518 : : , 0, 0, 0},
1519 : :
1520 : : #include "specs.h"
1521 : : /* Mark end of table. */
1522 : : {0, 0, 0, 0, 0}
1523 : : };
1524 : :
1525 : : /* Number of elements in default_compilers, not counting the terminator. */
1526 : :
1527 : : static const int n_default_compilers = ARRAY_SIZE (default_compilers) - 1;
1528 : :
1529 : : typedef char *char_p; /* For DEF_VEC_P. */
1530 : :
1531 : : /* A vector of options to give to the linker.
1532 : : These options are accumulated by %x,
1533 : : and substituted into the linker command with %X. */
1534 : : static vec<char_p> linker_options;
1535 : :
1536 : : /* A vector of options to give to the assembler.
1537 : : These options are accumulated by -Wa,
1538 : : and substituted into the assembler command with %Y. */
1539 : : static vec<char_p> assembler_options;
1540 : :
1541 : : /* A vector of options to give to the preprocessor.
1542 : : These options are accumulated by -Wp,
1543 : : and substituted into the preprocessor command with %Z. */
1544 : : static vec<char_p> preprocessor_options;
1545 : :
1546 : : static char *
1547 : 28324078 : skip_whitespace (char *p)
1548 : : {
1549 : 65646391 : while (1)
1550 : : {
1551 : : /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1552 : : be considered whitespace. */
1553 : 65646391 : if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n')
1554 : 4752448 : return p + 1;
1555 : 60893943 : else if (*p == '\n' || *p == ' ' || *p == '\t')
1556 : 37204259 : p++;
1557 : 23689684 : else if (*p == '#')
1558 : : {
1559 : 3654321 : while (*p != '\n')
1560 : 3536267 : p++;
1561 : 118054 : p++;
1562 : : }
1563 : : else
1564 : : break;
1565 : : }
1566 : :
1567 : : return p;
1568 : : }
1569 : : /* Structures to keep track of prefixes to try when looking for files. */
1570 : :
1571 : : struct prefix_list
1572 : : {
1573 : : const char *prefix; /* String to prepend to the path. */
1574 : : struct prefix_list *next; /* Next in linked list. */
1575 : : int require_machine_suffix; /* Don't use without machine_suffix. */
1576 : : /* 2 means try both machine_suffix and just_machine_suffix. */
1577 : : int priority; /* Sort key - priority within list. */
1578 : : int os_multilib; /* 1 if OS multilib scheme should be used,
1579 : : 0 for GCC multilib scheme. */
1580 : : };
1581 : :
1582 : : struct path_prefix
1583 : : {
1584 : : struct prefix_list *plist; /* List of prefixes to try */
1585 : : int max_len; /* Max length of a prefix in PLIST */
1586 : : const char *name; /* Name of this list (used in config stuff) */
1587 : : };
1588 : :
1589 : : /* List of prefixes to try when looking for executables. */
1590 : :
1591 : : static struct path_prefix exec_prefixes = { 0, 0, "exec" };
1592 : :
1593 : : /* List of prefixes to try when looking for startup (crt0) files. */
1594 : :
1595 : : static struct path_prefix startfile_prefixes = { 0, 0, "startfile" };
1596 : :
1597 : : /* List of prefixes to try when looking for include files. */
1598 : :
1599 : : static struct path_prefix include_prefixes = { 0, 0, "include" };
1600 : :
1601 : : /* Suffix to attach to directories searched for commands.
1602 : : This looks like `MACHINE/VERSION/'. */
1603 : :
1604 : : static const char *machine_suffix = 0;
1605 : :
1606 : : /* Suffix to attach to directories searched for commands.
1607 : : This is just `MACHINE/'. */
1608 : :
1609 : : static const char *just_machine_suffix = 0;
1610 : :
1611 : : /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1612 : :
1613 : : static const char *gcc_exec_prefix;
1614 : :
1615 : : /* Adjusted value of standard_libexec_prefix. */
1616 : :
1617 : : static const char *gcc_libexec_prefix;
1618 : :
1619 : : /* Default prefixes to attach to command names. */
1620 : :
1621 : : #ifndef STANDARD_STARTFILE_PREFIX_1
1622 : : #define STANDARD_STARTFILE_PREFIX_1 "/lib/"
1623 : : #endif
1624 : : #ifndef STANDARD_STARTFILE_PREFIX_2
1625 : : #define STANDARD_STARTFILE_PREFIX_2 "/usr/lib/"
1626 : : #endif
1627 : :
1628 : : #ifdef CROSS_DIRECTORY_STRUCTURE /* Don't use these prefixes for a cross compiler. */
1629 : : #undef MD_EXEC_PREFIX
1630 : : #undef MD_STARTFILE_PREFIX
1631 : : #undef MD_STARTFILE_PREFIX_1
1632 : : #endif
1633 : :
1634 : : /* If no prefixes defined, use the null string, which will disable them. */
1635 : : #ifndef MD_EXEC_PREFIX
1636 : : #define MD_EXEC_PREFIX ""
1637 : : #endif
1638 : : #ifndef MD_STARTFILE_PREFIX
1639 : : #define MD_STARTFILE_PREFIX ""
1640 : : #endif
1641 : : #ifndef MD_STARTFILE_PREFIX_1
1642 : : #define MD_STARTFILE_PREFIX_1 ""
1643 : : #endif
1644 : :
1645 : : /* These directories are locations set at configure-time based on the
1646 : : --prefix option provided to configure. Their initializers are
1647 : : defined in Makefile.in. These paths are not *directly* used when
1648 : : gcc_exec_prefix is set because, in that case, we know where the
1649 : : compiler has been installed, and use paths relative to that
1650 : : location instead. */
1651 : : static const char *const standard_exec_prefix = STANDARD_EXEC_PREFIX;
1652 : : static const char *const standard_libexec_prefix = STANDARD_LIBEXEC_PREFIX;
1653 : : static const char *const standard_bindir_prefix = STANDARD_BINDIR_PREFIX;
1654 : : static const char *const standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
1655 : :
1656 : : /* For native compilers, these are well-known paths containing
1657 : : components that may be provided by the system. For cross
1658 : : compilers, these paths are not used. */
1659 : : static const char *md_exec_prefix = MD_EXEC_PREFIX;
1660 : : static const char *md_startfile_prefix = MD_STARTFILE_PREFIX;
1661 : : static const char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
1662 : : static const char *const standard_startfile_prefix_1
1663 : : = STANDARD_STARTFILE_PREFIX_1;
1664 : : static const char *const standard_startfile_prefix_2
1665 : : = STANDARD_STARTFILE_PREFIX_2;
1666 : :
1667 : : /* A relative path to be used in finding the location of tools
1668 : : relative to the driver. */
1669 : : static const char *const tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
1670 : :
1671 : : /* A prefix to be used when this is an accelerator compiler. */
1672 : : static const char *const accel_dir_suffix = ACCEL_DIR_SUFFIX;
1673 : :
1674 : : /* Subdirectory to use for locating libraries. Set by
1675 : : set_multilib_dir based on the compilation options. */
1676 : :
1677 : : static const char *multilib_dir;
1678 : :
1679 : : /* Subdirectory to use for locating libraries in OS conventions. Set by
1680 : : set_multilib_dir based on the compilation options. */
1681 : :
1682 : : static const char *multilib_os_dir;
1683 : :
1684 : : /* Subdirectory to use for locating libraries in multiarch conventions. Set by
1685 : : set_multilib_dir based on the compilation options. */
1686 : :
1687 : : static const char *multiarch_dir;
1688 : :
1689 : : /* Structure to keep track of the specs that have been defined so far.
1690 : : These are accessed using %(specname) in a compiler or link
1691 : : spec. */
1692 : :
1693 : : struct spec_list
1694 : : {
1695 : : /* The following 2 fields must be first */
1696 : : /* to allow EXTRA_SPECS to be initialized */
1697 : : const char *name; /* name of the spec. */
1698 : : const char *ptr; /* available ptr if no static pointer */
1699 : :
1700 : : /* The following fields are not initialized */
1701 : : /* by EXTRA_SPECS */
1702 : : const char **ptr_spec; /* pointer to the spec itself. */
1703 : : struct spec_list *next; /* Next spec in linked list. */
1704 : : int name_len; /* length of the name */
1705 : : bool user_p; /* whether string come from file spec. */
1706 : : bool alloc_p; /* whether string was allocated */
1707 : : const char *default_ptr; /* The default value of *ptr_spec. */
1708 : : };
1709 : :
1710 : : #define INIT_STATIC_SPEC(NAME,PTR) \
1711 : : { NAME, NULL, PTR, (struct spec_list *) 0, sizeof (NAME) - 1, false, false, \
1712 : : *PTR }
1713 : :
1714 : : /* List of statically defined specs. */
1715 : : static struct spec_list static_specs[] =
1716 : : {
1717 : : INIT_STATIC_SPEC ("asm", &asm_spec),
1718 : : INIT_STATIC_SPEC ("asm_debug", &asm_debug),
1719 : : INIT_STATIC_SPEC ("asm_debug_option", &asm_debug_option),
1720 : : INIT_STATIC_SPEC ("asm_final", &asm_final_spec),
1721 : : INIT_STATIC_SPEC ("asm_options", &asm_options),
1722 : : INIT_STATIC_SPEC ("invoke_as", &invoke_as),
1723 : : INIT_STATIC_SPEC ("cpp", &cpp_spec),
1724 : : INIT_STATIC_SPEC ("cpp_options", &cpp_options),
1725 : : INIT_STATIC_SPEC ("cpp_debug_options", &cpp_debug_options),
1726 : : INIT_STATIC_SPEC ("cpp_unique_options", &cpp_unique_options),
1727 : : INIT_STATIC_SPEC ("trad_capable_cpp", &trad_capable_cpp),
1728 : : INIT_STATIC_SPEC ("cc1", &cc1_spec),
1729 : : INIT_STATIC_SPEC ("cc1_options", &cc1_options),
1730 : : INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec),
1731 : : INIT_STATIC_SPEC ("link_gcc_c_sequence", &link_gcc_c_sequence_spec),
1732 : : INIT_STATIC_SPEC ("link_ssp", &link_ssp_spec),
1733 : : INIT_STATIC_SPEC ("endfile", &endfile_spec),
1734 : : INIT_STATIC_SPEC ("link", &link_spec),
1735 : : INIT_STATIC_SPEC ("lib", &lib_spec),
1736 : : INIT_STATIC_SPEC ("link_gomp", &link_gomp_spec),
1737 : : INIT_STATIC_SPEC ("libgcc", &libgcc_spec),
1738 : : INIT_STATIC_SPEC ("startfile", &startfile_spec),
1739 : : INIT_STATIC_SPEC ("cross_compile", &cross_compile),
1740 : : INIT_STATIC_SPEC ("version", &compiler_version),
1741 : : INIT_STATIC_SPEC ("multilib", &multilib_select),
1742 : : INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults),
1743 : : INIT_STATIC_SPEC ("multilib_extra", &multilib_extra),
1744 : : INIT_STATIC_SPEC ("multilib_matches", &multilib_matches),
1745 : : INIT_STATIC_SPEC ("multilib_exclusions", &multilib_exclusions),
1746 : : INIT_STATIC_SPEC ("multilib_options", &multilib_options),
1747 : : INIT_STATIC_SPEC ("multilib_reuse", &multilib_reuse),
1748 : : INIT_STATIC_SPEC ("linker", &linker_name_spec),
1749 : : INIT_STATIC_SPEC ("linker_plugin_file", &linker_plugin_file_spec),
1750 : : INIT_STATIC_SPEC ("lto_wrapper", <o_wrapper_spec),
1751 : : INIT_STATIC_SPEC ("lto_gcc", <o_gcc_spec),
1752 : : INIT_STATIC_SPEC ("post_link", &post_link_spec),
1753 : : INIT_STATIC_SPEC ("link_libgcc", &link_libgcc_spec),
1754 : : INIT_STATIC_SPEC ("md_exec_prefix", &md_exec_prefix),
1755 : : INIT_STATIC_SPEC ("md_startfile_prefix", &md_startfile_prefix),
1756 : : INIT_STATIC_SPEC ("md_startfile_prefix_1", &md_startfile_prefix_1),
1757 : : INIT_STATIC_SPEC ("startfile_prefix_spec", &startfile_prefix_spec),
1758 : : INIT_STATIC_SPEC ("sysroot_spec", &sysroot_spec),
1759 : : INIT_STATIC_SPEC ("sysroot_suffix_spec", &sysroot_suffix_spec),
1760 : : INIT_STATIC_SPEC ("sysroot_hdrs_suffix_spec", &sysroot_hdrs_suffix_spec),
1761 : : INIT_STATIC_SPEC ("self_spec", &self_spec),
1762 : : };
1763 : :
1764 : : #ifdef EXTRA_SPECS /* additional specs needed */
1765 : : /* Structure to keep track of just the first two args of a spec_list.
1766 : : That is all that the EXTRA_SPECS macro gives us. */
1767 : : struct spec_list_1
1768 : : {
1769 : : const char *const name;
1770 : : const char *const ptr;
1771 : : };
1772 : :
1773 : : static const struct spec_list_1 extra_specs_1[] = { EXTRA_SPECS };
1774 : : static struct spec_list *extra_specs = (struct spec_list *) 0;
1775 : : #endif
1776 : :
1777 : : /* List of dynamically allocates specs that have been defined so far. */
1778 : :
1779 : : static struct spec_list *specs = (struct spec_list *) 0;
1780 : :
1781 : : /* List of static spec functions. */
1782 : :
1783 : : static const struct spec_function static_spec_functions[] =
1784 : : {
1785 : : { "getenv", getenv_spec_function },
1786 : : { "if-exists", if_exists_spec_function },
1787 : : { "if-exists-else", if_exists_else_spec_function },
1788 : : { "if-exists-then-else", if_exists_then_else_spec_function },
1789 : : { "sanitize", sanitize_spec_function },
1790 : : { "replace-outfile", replace_outfile_spec_function },
1791 : : { "remove-outfile", remove_outfile_spec_function },
1792 : : { "version-compare", version_compare_spec_function },
1793 : : { "include", include_spec_function },
1794 : : { "find-file", find_file_spec_function },
1795 : : { "find-plugindir", find_plugindir_spec_function },
1796 : : { "print-asm-header", print_asm_header_spec_function },
1797 : : { "compare-debug-dump-opt", compare_debug_dump_opt_spec_function },
1798 : : { "compare-debug-self-opt", compare_debug_self_opt_spec_function },
1799 : : { "pass-through-libs", pass_through_libs_spec_func },
1800 : : { "dumps", dumps_spec_func },
1801 : : { "gt", greater_than_spec_func },
1802 : : { "debug-level-gt", debug_level_greater_than_spec_func },
1803 : : { "dwarf-version-gt", dwarf_version_greater_than_spec_func },
1804 : : { "fortran-preinclude-file", find_fortran_preinclude_file},
1805 : : { "join", join_spec_func},
1806 : : #ifdef EXTRA_SPEC_FUNCTIONS
1807 : : EXTRA_SPEC_FUNCTIONS
1808 : : #endif
1809 : : { 0, 0 }
1810 : : };
1811 : :
1812 : : static int processing_spec_function;
1813 : :
1814 : : /* Add appropriate libgcc specs to OBSTACK, taking into account
1815 : : various permutations of -shared-libgcc, -shared, and such. */
1816 : :
1817 : : #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC)
1818 : :
1819 : : #ifndef USE_LD_AS_NEEDED
1820 : : #define USE_LD_AS_NEEDED 0
1821 : : #endif
1822 : :
1823 : : static void
1824 : 1123 : init_gcc_specs (struct obstack *obstack, const char *shared_name,
1825 : : const char *static_name, const char *eh_name)
1826 : : {
1827 : 1123 : char *buf;
1828 : :
1829 : : #if USE_LD_AS_NEEDED
1830 : 1123 : buf = concat ("%{static|static-libgcc|static-pie:", static_name, " ", eh_name, "}"
1831 : : "%{!static:%{!static-libgcc:%{!static-pie:"
1832 : : "%{!shared-libgcc:",
1833 : : static_name, " " LD_AS_NEEDED_OPTION " ",
1834 : : shared_name, " " LD_NO_AS_NEEDED_OPTION
1835 : : "}"
1836 : : "%{shared-libgcc:",
1837 : : shared_name, "%{!shared: ", static_name, "}"
1838 : : "}}"
1839 : : #else
1840 : : buf = concat ("%{static|static-libgcc:", static_name, " ", eh_name, "}"
1841 : : "%{!static:%{!static-libgcc:"
1842 : : "%{!shared:"
1843 : : "%{!shared-libgcc:", static_name, " ", eh_name, "}"
1844 : : "%{shared-libgcc:", shared_name, " ", static_name, "}"
1845 : : "}"
1846 : : #ifdef LINK_EH_SPEC
1847 : : "%{shared:"
1848 : : "%{shared-libgcc:", shared_name, "}"
1849 : : "%{!shared-libgcc:", static_name, "}"
1850 : : "}"
1851 : : #else
1852 : : "%{shared:", shared_name, "}"
1853 : : #endif
1854 : : #endif
1855 : : "}}", NULL);
1856 : :
1857 : 1123 : obstack_grow (obstack, buf, strlen (buf));
1858 : 1123 : free (buf);
1859 : 1123 : }
1860 : : #endif /* ENABLE_SHARED_LIBGCC */
1861 : :
1862 : : /* Initialize the specs lookup routines. */
1863 : :
1864 : : static void
1865 : 1123 : init_spec (void)
1866 : : {
1867 : 1123 : struct spec_list *next = (struct spec_list *) 0;
1868 : 1123 : struct spec_list *sl = (struct spec_list *) 0;
1869 : 1123 : int i;
1870 : :
1871 : 1123 : if (specs)
1872 : : return; /* Already initialized. */
1873 : :
1874 : 1123 : if (verbose_flag)
1875 : 95 : fnotice (stderr, "Using built-in specs.\n");
1876 : :
1877 : : #ifdef EXTRA_SPECS
1878 : 1123 : extra_specs = XCNEWVEC (struct spec_list, ARRAY_SIZE (extra_specs_1));
1879 : :
1880 : 2246 : for (i = ARRAY_SIZE (extra_specs_1) - 1; i >= 0; i--)
1881 : : {
1882 : 1123 : sl = &extra_specs[i];
1883 : 1123 : sl->name = extra_specs_1[i].name;
1884 : 1123 : sl->ptr = extra_specs_1[i].ptr;
1885 : 1123 : sl->next = next;
1886 : 1123 : sl->name_len = strlen (sl->name);
1887 : 1123 : sl->ptr_spec = &sl->ptr;
1888 : 1123 : gcc_assert (sl->ptr_spec != NULL);
1889 : 1123 : sl->default_ptr = sl->ptr;
1890 : 1123 : next = sl;
1891 : : }
1892 : : #endif
1893 : :
1894 : 51658 : for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--)
1895 : : {
1896 : 50535 : sl = &static_specs[i];
1897 : 50535 : sl->next = next;
1898 : 50535 : next = sl;
1899 : : }
1900 : :
1901 : : #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC)
1902 : : /* ??? If neither -shared-libgcc nor --static-libgcc was
1903 : : seen, then we should be making an educated guess. Some proposed
1904 : : heuristics for ELF include:
1905 : :
1906 : : (1) If "-Wl,--export-dynamic", then it's a fair bet that the
1907 : : program will be doing dynamic loading, which will likely
1908 : : need the shared libgcc.
1909 : :
1910 : : (2) If "-ldl", then it's also a fair bet that we're doing
1911 : : dynamic loading.
1912 : :
1913 : : (3) For each ET_DYN we're linking against (either through -lfoo
1914 : : or /some/path/foo.so), check to see whether it or one of
1915 : : its dependencies depends on a shared libgcc.
1916 : :
1917 : : (4) If "-shared"
1918 : :
1919 : : If the runtime is fixed to look for program headers instead
1920 : : of calling __register_frame_info at all, for each object,
1921 : : use the shared libgcc if any EH symbol referenced.
1922 : :
1923 : : If crtstuff is fixed to not invoke __register_frame_info
1924 : : automatically, for each object, use the shared libgcc if
1925 : : any non-empty unwind section found.
1926 : :
1927 : : Doing any of this probably requires invoking an external program to
1928 : : do the actual object file scanning. */
1929 : 1123 : {
1930 : 1123 : const char *p = libgcc_spec;
1931 : 1123 : int in_sep = 1;
1932 : :
1933 : : /* Transform the extant libgcc_spec into one that uses the shared libgcc
1934 : : when given the proper command line arguments. */
1935 : 2246 : while (*p)
1936 : : {
1937 : 1123 : if (in_sep && *p == '-' && startswith (p, "-lgcc"))
1938 : : {
1939 : 1123 : init_gcc_specs (&obstack,
1940 : : "-lgcc_s"
1941 : : #ifdef USE_LIBUNWIND_EXCEPTIONS
1942 : : " -lunwind"
1943 : : #endif
1944 : : ,
1945 : : "-lgcc",
1946 : : "-lgcc_eh"
1947 : : #ifdef USE_LIBUNWIND_EXCEPTIONS
1948 : : # ifdef HAVE_LD_STATIC_DYNAMIC
1949 : : " %{!static:%{!static-pie:" LD_STATIC_OPTION "}} -lunwind"
1950 : : " %{!static:%{!static-pie:" LD_DYNAMIC_OPTION "}}"
1951 : : # else
1952 : : " -lunwind"
1953 : : # endif
1954 : : #endif
1955 : : );
1956 : :
1957 : 1123 : p += 5;
1958 : 1123 : in_sep = 0;
1959 : : }
1960 : 0 : else if (in_sep && *p == 'l' && startswith (p, "libgcc.a%s"))
1961 : : {
1962 : : /* Ug. We don't know shared library extensions. Hope that
1963 : : systems that use this form don't do shared libraries. */
1964 : 0 : init_gcc_specs (&obstack,
1965 : : "-lgcc_s",
1966 : : "libgcc.a%s",
1967 : : "libgcc_eh.a%s"
1968 : : #ifdef USE_LIBUNWIND_EXCEPTIONS
1969 : : " -lunwind"
1970 : : #endif
1971 : : );
1972 : 0 : p += 10;
1973 : 0 : in_sep = 0;
1974 : : }
1975 : : else
1976 : : {
1977 : 0 : obstack_1grow (&obstack, *p);
1978 : 0 : in_sep = (*p == ' ');
1979 : 0 : p += 1;
1980 : : }
1981 : : }
1982 : :
1983 : 1123 : obstack_1grow (&obstack, '\0');
1984 : 1123 : libgcc_spec = XOBFINISH (&obstack, const char *);
1985 : : }
1986 : : #endif
1987 : : #ifdef USE_AS_TRADITIONAL_FORMAT
1988 : : /* Prepend "--traditional-format" to whatever asm_spec we had before. */
1989 : : {
1990 : : static const char tf[] = "--traditional-format ";
1991 : : obstack_grow (&obstack, tf, sizeof (tf) - 1);
1992 : : obstack_grow0 (&obstack, asm_spec, strlen (asm_spec));
1993 : : asm_spec = XOBFINISH (&obstack, const char *);
1994 : : }
1995 : : #endif
1996 : :
1997 : : #if defined LINK_EH_SPEC || defined LINK_BUILDID_SPEC || \
1998 : : defined LINKER_HASH_STYLE
1999 : : # ifdef LINK_BUILDID_SPEC
2000 : : /* Prepend LINK_BUILDID_SPEC to whatever link_spec we had before. */
2001 : : obstack_grow (&obstack, LINK_BUILDID_SPEC, sizeof (LINK_BUILDID_SPEC) - 1);
2002 : : # endif
2003 : : # ifdef LINK_EH_SPEC
2004 : : /* Prepend LINK_EH_SPEC to whatever link_spec we had before. */
2005 : 1123 : obstack_grow (&obstack, LINK_EH_SPEC, sizeof (LINK_EH_SPEC) - 1);
2006 : : # endif
2007 : : # ifdef LINKER_HASH_STYLE
2008 : : /* Prepend --hash-style=LINKER_HASH_STYLE to whatever link_spec we had
2009 : : before. */
2010 : : {
2011 : : static const char hash_style[] = "--hash-style=";
2012 : : obstack_grow (&obstack, hash_style, sizeof (hash_style) - 1);
2013 : : obstack_grow (&obstack, LINKER_HASH_STYLE, sizeof (LINKER_HASH_STYLE) - 1);
2014 : : obstack_1grow (&obstack, ' ');
2015 : : }
2016 : : # endif
2017 : 1123 : obstack_grow0 (&obstack, link_spec, strlen (link_spec));
2018 : 1123 : link_spec = XOBFINISH (&obstack, const char *);
2019 : : #endif
2020 : :
2021 : 1123 : specs = sl;
2022 : : }
2023 : :
2024 : : /* Update the entry for SPEC in the static_specs table to point to VALUE,
2025 : : ensuring that we free the previous value if necessary. Set alloc_p for the
2026 : : entry to ALLOC_P: this determines whether we take ownership of VALUE (i.e.
2027 : : whether we need to free it later on). */
2028 : : static void
2029 : 207663 : set_static_spec (const char **spec, const char *value, bool alloc_p)
2030 : : {
2031 : 207663 : struct spec_list *sl = NULL;
2032 : :
2033 : 7171374 : for (unsigned i = 0; i < ARRAY_SIZE (static_specs); i++)
2034 : : {
2035 : 7171374 : if (static_specs[i].ptr_spec == spec)
2036 : : {
2037 : 207663 : sl = static_specs + i;
2038 : 207663 : break;
2039 : : }
2040 : : }
2041 : :
2042 : 0 : gcc_assert (sl);
2043 : :
2044 : 207663 : if (sl->alloc_p)
2045 : : {
2046 : 207663 : const char *old = *spec;
2047 : 207663 : free (const_cast <char *> (old));
2048 : : }
2049 : :
2050 : 207663 : *spec = value;
2051 : 207663 : sl->alloc_p = alloc_p;
2052 : 207663 : }
2053 : :
2054 : : /* Update a static spec to a new string, taking ownership of that
2055 : : string's memory. */
2056 : 107052 : static void set_static_spec_owned (const char **spec, const char *val)
2057 : : {
2058 : 0 : return set_static_spec (spec, val, true);
2059 : : }
2060 : :
2061 : : /* Update a static spec to point to a new value, but don't take
2062 : : ownership of (i.e. don't free) that string. */
2063 : 100611 : static void set_static_spec_shared (const char **spec, const char *val)
2064 : : {
2065 : 0 : return set_static_spec (spec, val, false);
2066 : : }
2067 : :
2068 : :
2069 : : /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
2070 : : removed; If the spec starts with a + then SPEC is added to the end of the
2071 : : current spec. */
2072 : :
2073 : : static void
2074 : 13711749 : set_spec (const char *name, const char *spec, bool user_p)
2075 : : {
2076 : 13711749 : struct spec_list *sl;
2077 : 13711749 : const char *old_spec;
2078 : 13711749 : int name_len = strlen (name);
2079 : 13711749 : int i;
2080 : :
2081 : : /* If this is the first call, initialize the statically allocated specs. */
2082 : 13711749 : if (!specs)
2083 : : {
2084 : : struct spec_list *next = (struct spec_list *) 0;
2085 : 13663288 : for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--)
2086 : : {
2087 : 13366260 : sl = &static_specs[i];
2088 : 13366260 : sl->next = next;
2089 : 13366260 : next = sl;
2090 : : }
2091 : 297028 : specs = sl;
2092 : : }
2093 : :
2094 : : /* See if the spec already exists. */
2095 : 322659933 : for (sl = specs; sl; sl = sl->next)
2096 : 322341564 : if (name_len == sl->name_len && !strcmp (sl->name, name))
2097 : : break;
2098 : :
2099 : 13711749 : if (!sl)
2100 : : {
2101 : : /* Not found - make it. */
2102 : 318369 : sl = XNEW (struct spec_list);
2103 : 318369 : sl->name = xstrdup (name);
2104 : 318369 : sl->name_len = name_len;
2105 : 318369 : sl->ptr_spec = &sl->ptr;
2106 : 318369 : sl->alloc_p = 0;
2107 : 318369 : *(sl->ptr_spec) = "";
2108 : 318369 : sl->next = specs;
2109 : 318369 : sl->default_ptr = NULL;
2110 : 318369 : specs = sl;
2111 : : }
2112 : :
2113 : 13711749 : old_spec = *(sl->ptr_spec);
2114 : 13711749 : *(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE ((unsigned char)spec[1]))
2115 : 1 : ? concat (old_spec, spec + 1, NULL)
2116 : 13711748 : : xstrdup (spec));
2117 : :
2118 : : #ifdef DEBUG_SPECS
2119 : : if (verbose_flag)
2120 : : fnotice (stderr, "Setting spec %s to '%s'\n\n", name, *(sl->ptr_spec));
2121 : : #endif
2122 : :
2123 : : /* Free the old spec. */
2124 : 13711749 : if (old_spec && sl->alloc_p)
2125 : 5872 : free (CONST_CAST (char *, old_spec));
2126 : :
2127 : 13711749 : sl->user_p = user_p;
2128 : 13711749 : sl->alloc_p = true;
2129 : 13711749 : }
2130 : :
2131 : : /* Accumulate a command (program name and args), and run it. */
2132 : :
2133 : : typedef const char *const_char_p; /* For DEF_VEC_P. */
2134 : :
2135 : : /* Vector of pointers to arguments in the current line of specifications. */
2136 : : static vec<const_char_p> argbuf;
2137 : :
2138 : : /* Likewise, but for the current @file. */
2139 : : static vec<const_char_p> at_file_argbuf;
2140 : :
2141 : : /* Whether an @file is currently open. */
2142 : : static bool in_at_file = false;
2143 : :
2144 : : /* Were the options -c, -S or -E passed. */
2145 : : static int have_c = 0;
2146 : :
2147 : : /* Was the option -o passed. */
2148 : : static int have_o = 0;
2149 : :
2150 : : /* Was the option -E passed. */
2151 : : static int have_E = 0;
2152 : :
2153 : : /* Pointer to output file name passed in with -o. */
2154 : : static const char *output_file = 0;
2155 : :
2156 : : /* Pointer to input file name passed in with -truncate.
2157 : : This file should be truncated after linking. */
2158 : : static const char *totruncate_file = 0;
2159 : :
2160 : : /* This is the list of suffixes and codes (%g/%u/%U/%j) and the associated
2161 : : temp file. If the HOST_BIT_BUCKET is used for %j, no entry is made for
2162 : : it here. */
2163 : :
2164 : : static struct temp_name {
2165 : : const char *suffix; /* suffix associated with the code. */
2166 : : int length; /* strlen (suffix). */
2167 : : int unique; /* Indicates whether %g or %u/%U was used. */
2168 : : const char *filename; /* associated filename. */
2169 : : int filename_length; /* strlen (filename). */
2170 : : struct temp_name *next;
2171 : : } *temp_names;
2172 : :
2173 : : /* Number of commands executed so far. */
2174 : :
2175 : : static int execution_count;
2176 : :
2177 : : /* Number of commands that exited with a signal. */
2178 : :
2179 : : static int signal_count;
2180 : :
2181 : : /* Allocate the argument vector. */
2182 : :
2183 : : static void
2184 : 2376927 : alloc_args (void)
2185 : : {
2186 : 2376927 : argbuf.create (10);
2187 : 2376927 : at_file_argbuf.create (10);
2188 : 2376927 : }
2189 : :
2190 : : /* Clear out the vector of arguments (after a command is executed). */
2191 : :
2192 : : static void
2193 : 5593374 : clear_args (void)
2194 : : {
2195 : 5593374 : argbuf.truncate (0);
2196 : 5593374 : at_file_argbuf.truncate (0);
2197 : 5593374 : }
2198 : :
2199 : : /* Add one argument to the vector at the end.
2200 : : This is done when a space is seen or at the end of the line.
2201 : : If DELETE_ALWAYS is nonzero, the arg is a filename
2202 : : and the file should be deleted eventually.
2203 : : If DELETE_FAILURE is nonzero, the arg is a filename
2204 : : and the file should be deleted if this compilation fails. */
2205 : :
2206 : : static void
2207 : 20416780 : store_arg (const char *arg, int delete_always, int delete_failure)
2208 : : {
2209 : 20416780 : if (in_at_file)
2210 : 14303 : at_file_argbuf.safe_push (arg);
2211 : : else
2212 : 20402477 : argbuf.safe_push (arg);
2213 : :
2214 : 20416780 : if (delete_always || delete_failure)
2215 : : {
2216 : 524513 : const char *p;
2217 : : /* If the temporary file we should delete is specified as
2218 : : part of a joined argument extract the filename. */
2219 : 524513 : if (arg[0] == '-'
2220 : 524513 : && (p = strrchr (arg, '=')))
2221 : 91510 : arg = p + 1;
2222 : 524513 : record_temp_file (arg, delete_always, delete_failure);
2223 : : }
2224 : 20416780 : }
2225 : :
2226 : : /* Open a temporary @file into which subsequent arguments will be stored. */
2227 : :
2228 : : static void
2229 : 13266 : open_at_file (void)
2230 : : {
2231 : 13266 : if (in_at_file)
2232 : 0 : fatal_error (input_location, "cannot open nested response file");
2233 : : else
2234 : 13266 : in_at_file = true;
2235 : 13266 : }
2236 : :
2237 : : /* Create a temporary @file name. */
2238 : :
2239 : 13256 : static char *make_at_file (void)
2240 : : {
2241 : 13256 : static int fileno = 0;
2242 : 13256 : char filename[20];
2243 : 13256 : const char *base, *ext;
2244 : :
2245 : 13256 : if (!save_temps_flag)
2246 : 13218 : return make_temp_file ("");
2247 : :
2248 : 38 : base = dumpbase;
2249 : 38 : if (!(base && *base))
2250 : 11 : base = dumpdir;
2251 : 38 : if (!(base && *base))
2252 : 0 : base = "a";
2253 : :
2254 : 38 : sprintf (filename, ".args.%d", fileno++);
2255 : 38 : ext = filename;
2256 : :
2257 : 38 : if (base == dumpdir && dumpdir_trailing_dash_added)
2258 : 38 : ext++;
2259 : :
2260 : 38 : return concat (base, ext, NULL);
2261 : : }
2262 : :
2263 : : /* Close the temporary @file and add @file to the argument list. */
2264 : :
2265 : : static void
2266 : 13266 : close_at_file (void)
2267 : : {
2268 : 13266 : if (!in_at_file)
2269 : 0 : fatal_error (input_location, "cannot close nonexistent response file");
2270 : :
2271 : 13266 : in_at_file = false;
2272 : :
2273 : 13266 : const unsigned int n_args = at_file_argbuf.length ();
2274 : 13266 : if (n_args == 0)
2275 : : return;
2276 : :
2277 : 13256 : char **argv = XALLOCAVEC (char *, n_args + 1);
2278 : 13256 : char *temp_file = make_at_file ();
2279 : 13256 : char *at_argument = concat ("@", temp_file, NULL);
2280 : 13256 : FILE *f = fopen (temp_file, "w");
2281 : 13256 : int status;
2282 : 13256 : unsigned int i;
2283 : :
2284 : : /* Copy the strings over. */
2285 : 40815 : for (i = 0; i < n_args; i++)
2286 : 14303 : argv[i] = CONST_CAST (char *, at_file_argbuf[i]);
2287 : 13256 : argv[i] = NULL;
2288 : :
2289 : 13256 : at_file_argbuf.truncate (0);
2290 : :
2291 : 13256 : if (f == NULL)
2292 : 0 : fatal_error (input_location, "could not open temporary response file %s",
2293 : : temp_file);
2294 : :
2295 : 13256 : status = writeargv (argv, f);
2296 : :
2297 : 13256 : if (status)
2298 : 0 : fatal_error (input_location,
2299 : : "could not write to temporary response file %s",
2300 : : temp_file);
2301 : :
2302 : 13256 : status = fclose (f);
2303 : :
2304 : 13256 : if (status == EOF)
2305 : 0 : fatal_error (input_location, "could not close temporary response file %s",
2306 : : temp_file);
2307 : :
2308 : 13256 : store_arg (at_argument, 0, 0);
2309 : :
2310 : 13256 : record_temp_file (temp_file, !save_temps_flag, !save_temps_flag);
2311 : : }
2312 : :
2313 : : /* Load specs from a file name named FILENAME, replacing occurrences of
2314 : : various different types of line-endings, \r\n, \n\r and just \r, with
2315 : : a single \n. */
2316 : :
2317 : : static char *
2318 : 327773 : load_specs (const char *filename)
2319 : : {
2320 : 327773 : int desc;
2321 : 327773 : int readlen;
2322 : 327773 : struct stat statbuf;
2323 : 327773 : char *buffer;
2324 : 327773 : char *buffer_p;
2325 : 327773 : char *specs;
2326 : 327773 : char *specs_p;
2327 : :
2328 : 327773 : if (verbose_flag)
2329 : 1378 : fnotice (stderr, "Reading specs from %s\n", filename);
2330 : :
2331 : : /* Open and stat the file. */
2332 : 327773 : desc = open (filename, O_RDONLY, 0);
2333 : 327773 : if (desc < 0)
2334 : : {
2335 : 1 : failed:
2336 : : /* This leaves DESC open, but the OS will save us. */
2337 : 1 : fatal_error (input_location, "cannot read spec file %qs: %m", filename);
2338 : : }
2339 : :
2340 : 327772 : if (stat (filename, &statbuf) < 0)
2341 : 0 : goto failed;
2342 : :
2343 : : /* Read contents of file into BUFFER. */
2344 : 327772 : buffer = XNEWVEC (char, statbuf.st_size + 1);
2345 : 327772 : readlen = read (desc, buffer, (unsigned) statbuf.st_size);
2346 : 327772 : if (readlen < 0)
2347 : 0 : goto failed;
2348 : 327772 : buffer[readlen] = 0;
2349 : 327772 : close (desc);
2350 : :
2351 : 327772 : specs = XNEWVEC (char, readlen + 1);
2352 : 327772 : specs_p = specs;
2353 : 3003654273 : for (buffer_p = buffer; buffer_p && *buffer_p; buffer_p++)
2354 : : {
2355 : 3003326501 : int skip = 0;
2356 : 3003326501 : char c = *buffer_p;
2357 : 3003326501 : if (c == '\r')
2358 : : {
2359 : 0 : if (buffer_p > buffer && *(buffer_p - 1) == '\n') /* \n\r */
2360 : : skip = 1;
2361 : 0 : else if (*(buffer_p + 1) == '\n') /* \r\n */
2362 : : skip = 1;
2363 : : else /* \r */
2364 : : c = '\n';
2365 : : }
2366 : : if (! skip)
2367 : 3003326501 : *specs_p++ = c;
2368 : : }
2369 : 327772 : *specs_p = '\0';
2370 : :
2371 : 327772 : free (buffer);
2372 : 327772 : return (specs);
2373 : : }
2374 : :
2375 : : /* Read compilation specs from a file named FILENAME,
2376 : : replacing the default ones.
2377 : :
2378 : : A suffix which starts with `*' is a definition for
2379 : : one of the machine-specific sub-specs. The "suffix" should be
2380 : : *asm, *cc1, *cpp, *link, *startfile, etc.
2381 : : The corresponding spec is stored in asm_spec, etc.,
2382 : : rather than in the `compilers' vector.
2383 : :
2384 : : Anything invalid in the file is a fatal error. */
2385 : :
2386 : : static void
2387 : 327773 : read_specs (const char *filename, bool main_p, bool user_p)
2388 : : {
2389 : 327773 : char *buffer;
2390 : 327773 : char *p;
2391 : :
2392 : 327773 : buffer = load_specs (filename);
2393 : :
2394 : : /* Scan BUFFER for specs, putting them in the vector. */
2395 : 327773 : p = buffer;
2396 : 14336549 : while (1)
2397 : : {
2398 : 14336549 : char *suffix;
2399 : 14336549 : char *spec;
2400 : 14336549 : char *in, *out, *p1, *p2, *p3;
2401 : :
2402 : : /* Advance P in BUFFER to the next nonblank nocomment line. */
2403 : 14336549 : p = skip_whitespace (p);
2404 : 14336549 : if (*p == 0)
2405 : : break;
2406 : :
2407 : : /* Is this a special command that starts with '%'? */
2408 : : /* Don't allow this for the main specs file, since it would
2409 : : encourage people to overwrite it. */
2410 : 14008777 : if (*p == '%' && !main_p)
2411 : : {
2412 : 424960 : p1 = p;
2413 : 424960 : while (*p && *p != '\n')
2414 : 403712 : p++;
2415 : :
2416 : : /* Skip '\n'. */
2417 : 21248 : p++;
2418 : :
2419 : 21248 : if (startswith (p1, "%include")
2420 : 21248 : && (p1[sizeof "%include" - 1] == ' '
2421 : 0 : || p1[sizeof "%include" - 1] == '\t'))
2422 : : {
2423 : 0 : char *new_filename;
2424 : :
2425 : 0 : p1 += sizeof ("%include");
2426 : 0 : while (*p1 == ' ' || *p1 == '\t')
2427 : 0 : p1++;
2428 : :
2429 : 0 : if (*p1++ != '<' || p[-2] != '>')
2430 : 0 : fatal_error (input_location,
2431 : : "specs %%include syntax malformed after "
2432 : 0 : "%td characters", p1 - buffer + 1);
2433 : :
2434 : 0 : p[-2] = '\0';
2435 : 0 : new_filename = find_a_file (&startfile_prefixes, p1, R_OK, true);
2436 : 0 : read_specs (new_filename ? new_filename : p1, false, user_p);
2437 : 0 : continue;
2438 : 0 : }
2439 : 21248 : else if (startswith (p1, "%include_noerr")
2440 : 21248 : && (p1[sizeof "%include_noerr" - 1] == ' '
2441 : 0 : || p1[sizeof "%include_noerr" - 1] == '\t'))
2442 : : {
2443 : 0 : char *new_filename;
2444 : :
2445 : 0 : p1 += sizeof "%include_noerr";
2446 : 0 : while (*p1 == ' ' || *p1 == '\t')
2447 : 0 : p1++;
2448 : :
2449 : 0 : if (*p1++ != '<' || p[-2] != '>')
2450 : 0 : fatal_error (input_location,
2451 : : "specs %%include syntax malformed after "
2452 : 0 : "%td characters", p1 - buffer + 1);
2453 : :
2454 : 0 : p[-2] = '\0';
2455 : 0 : new_filename = find_a_file (&startfile_prefixes, p1, R_OK, true);
2456 : 0 : if (new_filename)
2457 : 0 : read_specs (new_filename, false, user_p);
2458 : 0 : else if (verbose_flag)
2459 : 0 : fnotice (stderr, "could not find specs file %s\n", p1);
2460 : 0 : continue;
2461 : 0 : }
2462 : 21248 : else if (startswith (p1, "%rename")
2463 : 21248 : && (p1[sizeof "%rename" - 1] == ' '
2464 : 0 : || p1[sizeof "%rename" - 1] == '\t'))
2465 : : {
2466 : 21248 : int name_len;
2467 : 21248 : struct spec_list *sl;
2468 : 21248 : struct spec_list *newsl;
2469 : :
2470 : : /* Get original name. */
2471 : 21248 : p1 += sizeof "%rename";
2472 : 21248 : while (*p1 == ' ' || *p1 == '\t')
2473 : 0 : p1++;
2474 : :
2475 : 21248 : if (! ISALPHA ((unsigned char) *p1))
2476 : 0 : fatal_error (input_location,
2477 : : "specs %%rename syntax malformed after "
2478 : : "%td characters", p1 - buffer);
2479 : :
2480 : : p2 = p1;
2481 : 84992 : while (*p2 && !ISSPACE ((unsigned char) *p2))
2482 : 63744 : p2++;
2483 : :
2484 : 21248 : if (*p2 != ' ' && *p2 != '\t')
2485 : 0 : fatal_error (input_location,
2486 : : "specs %%rename syntax malformed after "
2487 : : "%td characters", p2 - buffer);
2488 : :
2489 : 21248 : name_len = p2 - p1;
2490 : 21248 : *p2++ = '\0';
2491 : 21248 : while (*p2 == ' ' || *p2 == '\t')
2492 : 0 : p2++;
2493 : :
2494 : 21248 : if (! ISALPHA ((unsigned char) *p2))
2495 : 0 : fatal_error (input_location,
2496 : : "specs %%rename syntax malformed after "
2497 : : "%td characters", p2 - buffer);
2498 : :
2499 : : /* Get new spec name. */
2500 : : p3 = p2;
2501 : 169984 : while (*p3 && !ISSPACE ((unsigned char) *p3))
2502 : 148736 : p3++;
2503 : :
2504 : 21248 : if (p3 != p - 1)
2505 : 0 : fatal_error (input_location,
2506 : : "specs %%rename syntax malformed after "
2507 : : "%td characters", p3 - buffer);
2508 : 21248 : *p3 = '\0';
2509 : :
2510 : 424960 : for (sl = specs; sl; sl = sl->next)
2511 : 424960 : if (name_len == sl->name_len && !strcmp (sl->name, p1))
2512 : : break;
2513 : :
2514 : 21248 : if (!sl)
2515 : 0 : fatal_error (input_location,
2516 : : "specs %s spec was not found to be renamed", p1);
2517 : :
2518 : 21248 : if (strcmp (p1, p2) == 0)
2519 : 0 : continue;
2520 : :
2521 : 998656 : for (newsl = specs; newsl; newsl = newsl->next)
2522 : 977408 : if (strcmp (newsl->name, p2) == 0)
2523 : 0 : fatal_error (input_location,
2524 : : "%s: attempt to rename spec %qs to "
2525 : : "already defined spec %qs",
2526 : : filename, p1, p2);
2527 : :
2528 : 21248 : if (verbose_flag)
2529 : : {
2530 : 0 : fnotice (stderr, "rename spec %s to %s\n", p1, p2);
2531 : : #ifdef DEBUG_SPECS
2532 : : fnotice (stderr, "spec is '%s'\n\n", *(sl->ptr_spec));
2533 : : #endif
2534 : : }
2535 : :
2536 : 21248 : set_spec (p2, *(sl->ptr_spec), user_p);
2537 : 21248 : if (sl->alloc_p)
2538 : 21248 : free (CONST_CAST (char *, *(sl->ptr_spec)));
2539 : :
2540 : 21248 : *(sl->ptr_spec) = "";
2541 : 21248 : sl->alloc_p = 0;
2542 : 21248 : continue;
2543 : 21248 : }
2544 : : else
2545 : 0 : fatal_error (input_location,
2546 : : "specs unknown %% command after %td characters",
2547 : : p1 - buffer);
2548 : : }
2549 : :
2550 : : /* Find the colon that should end the suffix. */
2551 : : p1 = p;
2552 : 192052183 : while (*p1 && *p1 != ':' && *p1 != '\n')
2553 : 178064654 : p1++;
2554 : :
2555 : : /* The colon shouldn't be missing. */
2556 : 13987529 : if (*p1 != ':')
2557 : 0 : fatal_error (input_location,
2558 : : "specs file malformed after %td characters",
2559 : : p1 - buffer);
2560 : :
2561 : : /* Skip back over trailing whitespace. */
2562 : : p2 = p1;
2563 : 13987529 : while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t'))
2564 : 0 : p2--;
2565 : :
2566 : : /* Copy the suffix to a string. */
2567 : 13987529 : suffix = save_string (p, p2 - p);
2568 : : /* Find the next line. */
2569 : 13987529 : p = skip_whitespace (p1 + 1);
2570 : 13987529 : if (p[1] == 0)
2571 : 0 : fatal_error (input_location,
2572 : : "specs file malformed after %td characters",
2573 : : p - buffer);
2574 : :
2575 : : p1 = p;
2576 : : /* Find next blank line or end of string. */
2577 : 2779225859 : while (*p1 && !(*p1 == '\n' && (p1[1] == '\n' || p1[1] == '\0')))
2578 : 2765238330 : p1++;
2579 : :
2580 : : /* Specs end at the blank line and do not include the newline. */
2581 : 13987529 : spec = save_string (p, p1 - p);
2582 : 13987529 : p = p1;
2583 : :
2584 : : /* Delete backslash-newline sequences from the spec. */
2585 : 13987529 : in = spec;
2586 : 13987529 : out = spec;
2587 : 2793213386 : while (*in != 0)
2588 : : {
2589 : 2765238328 : if (in[0] == '\\' && in[1] == '\n')
2590 : 2 : in += 2;
2591 : 2765238326 : else if (in[0] == '#')
2592 : 0 : while (*in && *in != '\n')
2593 : 0 : in++;
2594 : :
2595 : : else
2596 : 2765238326 : *out++ = *in++;
2597 : : }
2598 : 13987529 : *out = 0;
2599 : :
2600 : 13987529 : if (suffix[0] == '*')
2601 : : {
2602 : 13987529 : if (! strcmp (suffix, "*link_command"))
2603 : 297028 : link_command_spec = spec;
2604 : : else
2605 : : {
2606 : 13690501 : set_spec (suffix + 1, spec, user_p);
2607 : 13690501 : free (spec);
2608 : : }
2609 : : }
2610 : : else
2611 : : {
2612 : : /* Add this pair to the vector. */
2613 : 0 : compilers
2614 : 0 : = XRESIZEVEC (struct compiler, compilers, n_compilers + 2);
2615 : :
2616 : 0 : compilers[n_compilers].suffix = suffix;
2617 : 0 : compilers[n_compilers].spec = spec;
2618 : 0 : n_compilers++;
2619 : 0 : memset (&compilers[n_compilers], 0, sizeof compilers[n_compilers]);
2620 : : }
2621 : :
2622 : 13987529 : if (*suffix == 0)
2623 : 0 : link_command_spec = spec;
2624 : : }
2625 : :
2626 : 327772 : if (link_command_spec == 0)
2627 : 0 : fatal_error (input_location, "spec file has no spec for linking");
2628 : :
2629 : 327772 : XDELETEVEC (buffer);
2630 : 327772 : }
2631 : :
2632 : : /* Record the names of temporary files we tell compilers to write,
2633 : : and delete them at the end of the run. */
2634 : :
2635 : : /* This is the common prefix we use to make temp file names.
2636 : : It is chosen once for each run of this program.
2637 : : It is substituted into a spec by %g or %j.
2638 : : Thus, all temp file names contain this prefix.
2639 : : In practice, all temp file names start with this prefix.
2640 : :
2641 : : This prefix comes from the envvar TMPDIR if it is defined;
2642 : : otherwise, from the P_tmpdir macro if that is defined;
2643 : : otherwise, in /usr/tmp or /tmp;
2644 : : or finally the current directory if all else fails. */
2645 : :
2646 : : static const char *temp_filename;
2647 : :
2648 : : /* Length of the prefix. */
2649 : :
2650 : : static int temp_filename_length;
2651 : :
2652 : : /* Define the list of temporary files to delete. */
2653 : :
2654 : : struct temp_file
2655 : : {
2656 : : const char *name;
2657 : : struct temp_file *next;
2658 : : };
2659 : :
2660 : : /* Queue of files to delete on success or failure of compilation. */
2661 : : static struct temp_file *always_delete_queue;
2662 : : /* Queue of files to delete on failure of compilation. */
2663 : : static struct temp_file *failure_delete_queue;
2664 : :
2665 : : /* Record FILENAME as a file to be deleted automatically.
2666 : : ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
2667 : : otherwise delete it in any case.
2668 : : FAIL_DELETE nonzero means delete it if a compilation step fails;
2669 : : otherwise delete it in any case. */
2670 : :
2671 : : void
2672 : 708973 : record_temp_file (const char *filename, int always_delete, int fail_delete)
2673 : : {
2674 : 708973 : char *const name = xstrdup (filename);
2675 : :
2676 : 708973 : if (always_delete)
2677 : : {
2678 : 534935 : struct temp_file *temp;
2679 : 928083 : for (temp = always_delete_queue; temp; temp = temp->next)
2680 : 559183 : if (! filename_cmp (name, temp->name))
2681 : : {
2682 : 166035 : free (name);
2683 : 166035 : goto already1;
2684 : : }
2685 : :
2686 : 368900 : temp = XNEW (struct temp_file);
2687 : 368900 : temp->next = always_delete_queue;
2688 : 368900 : temp->name = name;
2689 : 368900 : always_delete_queue = temp;
2690 : :
2691 : 708973 : already1:;
2692 : : }
2693 : :
2694 : 708973 : if (fail_delete)
2695 : : {
2696 : 285000 : struct temp_file *temp;
2697 : 290027 : for (temp = failure_delete_queue; temp; temp = temp->next)
2698 : 5116 : if (! filename_cmp (name, temp->name))
2699 : : {
2700 : 89 : free (name);
2701 : 89 : goto already2;
2702 : : }
2703 : :
2704 : 284911 : temp = XNEW (struct temp_file);
2705 : 284911 : temp->next = failure_delete_queue;
2706 : 284911 : temp->name = name;
2707 : 284911 : failure_delete_queue = temp;
2708 : :
2709 : 708973 : already2:;
2710 : : }
2711 : 708973 : }
2712 : :
2713 : : /* Delete all the temporary files whose names we previously recorded. */
2714 : :
2715 : : #ifndef DELETE_IF_ORDINARY
2716 : : #define DELETE_IF_ORDINARY(NAME,ST,VERBOSE_FLAG) \
2717 : : do \
2718 : : { \
2719 : : if (stat (NAME, &ST) >= 0 && S_ISREG (ST.st_mode)) \
2720 : : if (unlink (NAME) < 0) \
2721 : : if (VERBOSE_FLAG) \
2722 : : error ("%s: %m", (NAME)); \
2723 : : } while (0)
2724 : : #endif
2725 : :
2726 : : static void
2727 : 392113 : delete_if_ordinary (const char *name)
2728 : : {
2729 : 392113 : struct stat st;
2730 : : #ifdef DEBUG
2731 : : int i, c;
2732 : :
2733 : : printf ("Delete %s? (y or n) ", name);
2734 : : fflush (stdout);
2735 : : i = getchar ();
2736 : : if (i != '\n')
2737 : : while ((c = getchar ()) != '\n' && c != EOF)
2738 : : ;
2739 : :
2740 : : if (i == 'y' || i == 'Y')
2741 : : #endif /* DEBUG */
2742 : 392113 : DELETE_IF_ORDINARY (name, st, verbose_flag);
2743 : 392113 : }
2744 : :
2745 : : static void
2746 : 583046 : delete_temp_files (void)
2747 : : {
2748 : 583046 : struct temp_file *temp;
2749 : :
2750 : 951946 : for (temp = always_delete_queue; temp; temp = temp->next)
2751 : 368900 : delete_if_ordinary (temp->name);
2752 : 583046 : always_delete_queue = 0;
2753 : 583046 : }
2754 : :
2755 : : /* Delete all the files to be deleted on error. */
2756 : :
2757 : : static void
2758 : 58463 : delete_failure_queue (void)
2759 : : {
2760 : 58463 : struct temp_file *temp;
2761 : :
2762 : 81676 : for (temp = failure_delete_queue; temp; temp = temp->next)
2763 : 23213 : delete_if_ordinary (temp->name);
2764 : 58463 : }
2765 : :
2766 : : static void
2767 : 544469 : clear_failure_queue (void)
2768 : : {
2769 : 544469 : failure_delete_queue = 0;
2770 : 544469 : }
2771 : :
2772 : : /* Call CALLBACK for each path in PATHS, breaking out early if CALLBACK
2773 : : returns non-NULL.
2774 : : If DO_MULTI is true iterate over the paths twice, first with multilib
2775 : : suffix then without, otherwise iterate over the paths once without
2776 : : adding a multilib suffix. When DO_MULTI is true, some attempt is made
2777 : : to avoid visiting the same path twice, but we could do better. For
2778 : : instance, /usr/lib/../lib is considered different from /usr/lib.
2779 : : At least EXTRA_SPACE chars past the end of the path passed to
2780 : : CALLBACK are available for use by the callback.
2781 : : CALLBACK_INFO allows extra parameters to be passed to CALLBACK.
2782 : :
2783 : : Returns the value returned by CALLBACK. */
2784 : :
2785 : : template<typename fun>
2786 : : auto *
2787 : 2842314 : for_each_path (const struct path_prefix *paths,
2788 : : bool do_multi,
2789 : : size_t extra_space,
2790 : : fun && callback)
2791 : : {
2792 : : struct prefix_list *pl;
2793 : 2842314 : const char *multi_dir = NULL;
2794 : 2842314 : const char *multi_os_dir = NULL;
2795 : 2842314 : const char *multiarch_suffix = NULL;
2796 : : const char *multi_suffix;
2797 : : const char *just_multi_suffix;
2798 : 2842314 : char *path = NULL;
2799 : 2842314 : decltype (callback (nullptr)) ret = nullptr;
2800 : 2842314 : bool skip_multi_dir = false;
2801 : 2842314 : bool skip_multi_os_dir = false;
2802 : :
2803 : 2842314 : multi_suffix = machine_suffix;
2804 : 2842314 : just_multi_suffix = just_machine_suffix;
2805 : 2842314 : if (do_multi && multilib_dir && strcmp (multilib_dir, ".") != 0)
2806 : : {
2807 : 15826 : multi_dir = concat (multilib_dir, dir_separator_str, NULL);
2808 : 15826 : multi_suffix = concat (multi_suffix, multi_dir, NULL);
2809 : 15826 : just_multi_suffix = concat (just_multi_suffix, multi_dir, NULL);
2810 : : }
2811 : 1236020 : if (do_multi && multilib_os_dir && strcmp (multilib_os_dir, ".") != 0)
2812 : 937868 : multi_os_dir = concat (multilib_os_dir, dir_separator_str, NULL);
2813 : 2842314 : if (multiarch_dir)
2814 : 0 : multiarch_suffix = concat (multiarch_dir, dir_separator_str, NULL);
2815 : :
2816 : : while (1)
2817 : : {
2818 : 3267251 : size_t multi_dir_len = 0;
2819 : 3267251 : size_t multi_os_dir_len = 0;
2820 : 3267251 : size_t multiarch_len = 0;
2821 : : size_t suffix_len;
2822 : : size_t just_suffix_len;
2823 : : size_t len;
2824 : :
2825 : 3267251 : if (multi_dir)
2826 : 15826 : multi_dir_len = strlen (multi_dir);
2827 : 3267251 : if (multi_os_dir)
2828 : 937868 : multi_os_dir_len = strlen (multi_os_dir);
2829 : 3267251 : if (multiarch_suffix)
2830 : 0 : multiarch_len = strlen (multiarch_suffix);
2831 : 3267251 : suffix_len = strlen (multi_suffix);
2832 : 3267251 : just_suffix_len = strlen (just_multi_suffix);
2833 : :
2834 : 3267251 : if (path == NULL)
2835 : : {
2836 : 2842314 : len = paths->max_len + extra_space + 1;
2837 : 2842314 : len += MAX (MAX (suffix_len, multi_os_dir_len), multiarch_len);
2838 : 2842314 : path = XNEWVEC (char, len);
2839 : : }
2840 : :
2841 : 12811306 : for (pl = paths->plist; pl != 0; pl = pl->next)
2842 : : {
2843 : 11224054 : len = strlen (pl->prefix);
2844 : 11224054 : memcpy (path, pl->prefix, len);
2845 : :
2846 : : /* Look first in MACHINE/VERSION subdirectory. */
2847 : 11224054 : if (!skip_multi_dir)
2848 : : {
2849 : 8211016 : memcpy (path + len, multi_suffix, suffix_len + 1);
2850 : 8211016 : ret = callback (path);
2851 : 5284122 : if (ret)
2852 : : break;
2853 : : }
2854 : :
2855 : : /* Some paths are tried with just the machine (ie. target)
2856 : : subdir. This is used for finding as, ld, etc. */
2857 : : if (!skip_multi_dir
2858 : 8211016 : && pl->require_machine_suffix == 2)
2859 : : {
2860 : 0 : memcpy (path + len, just_multi_suffix, just_suffix_len + 1);
2861 : 0 : ret = callback (path);
2862 : 0 : if (ret)
2863 : : break;
2864 : : }
2865 : :
2866 : : /* Now try the multiarch path. */
2867 : : if (!skip_multi_dir
2868 : 8211016 : && !pl->require_machine_suffix && multiarch_dir)
2869 : : {
2870 : 0 : memcpy (path + len, multiarch_suffix, multiarch_len + 1);
2871 : 0 : ret = callback (path);
2872 : 0 : if (ret)
2873 : : break;
2874 : : }
2875 : :
2876 : : /* Now try the base path. */
2877 : 11224054 : if (!pl->require_machine_suffix
2878 : 17845052 : && !(pl->os_multilib ? skip_multi_os_dir : skip_multi_dir))
2879 : : {
2880 : : const char *this_multi;
2881 : : size_t this_multi_len;
2882 : :
2883 : 10035844 : if (pl->os_multilib)
2884 : : {
2885 : : this_multi = multi_os_dir;
2886 : : this_multi_len = multi_os_dir_len;
2887 : : }
2888 : : else
2889 : : {
2890 : 5432788 : this_multi = multi_dir;
2891 : 5432788 : this_multi_len = multi_dir_len;
2892 : : }
2893 : :
2894 : 10035844 : if (this_multi_len)
2895 : 2798562 : memcpy (path + len, this_multi, this_multi_len + 1);
2896 : : else
2897 : 7237282 : path[len] = '\0';
2898 : :
2899 : 10035844 : ret = callback (path);
2900 : 5946604 : if (ret)
2901 : : break;
2902 : : }
2903 : : }
2904 : 2502455 : if (pl)
2905 : : break;
2906 : :
2907 : 1587252 : if (multi_dir == NULL && multi_os_dir == NULL)
2908 : : break;
2909 : :
2910 : : /* Run through the paths again, this time without multilibs.
2911 : : Don't repeat any we have already seen. */
2912 : 424937 : if (multi_dir)
2913 : : {
2914 : 10124 : free (CONST_CAST (char *, multi_dir));
2915 : 10124 : multi_dir = NULL;
2916 : 10124 : free (CONST_CAST (char *, multi_suffix));
2917 : 10124 : multi_suffix = machine_suffix;
2918 : 10124 : free (CONST_CAST (char *, just_multi_suffix));
2919 : 10124 : just_multi_suffix = just_machine_suffix;
2920 : : }
2921 : : else
2922 : : skip_multi_dir = true;
2923 : 424937 : if (multi_os_dir)
2924 : : {
2925 : 424937 : free (CONST_CAST (char *, multi_os_dir));
2926 : 424937 : multi_os_dir = NULL;
2927 : : }
2928 : : else
2929 : : skip_multi_os_dir = true;
2930 : : }
2931 : :
2932 : 2842314 : if (multi_dir)
2933 : : {
2934 : 5702 : free (CONST_CAST (char *, multi_dir));
2935 : 5702 : free (CONST_CAST (char *, multi_suffix));
2936 : 5702 : free (CONST_CAST (char *, just_multi_suffix));
2937 : : }
2938 : 2842314 : if (multi_os_dir)
2939 : 512931 : free (CONST_CAST (char *, multi_os_dir));
2940 : 2332450 : if (ret != path)
2941 : 1162315 : free (path);
2942 : 2842314 : return ret;
2943 : : }
2944 : :
2945 : : /* Add or change the value of an environment variable, outputting the
2946 : : change to standard error if in verbose mode. */
2947 : : static void
2948 : 1770461 : xputenv (const char *string)
2949 : : {
2950 : 0 : env.xput (string);
2951 : 135967 : }
2952 : :
2953 : : /* Build a list of search directories from PATHS.
2954 : : PREFIX is a string to prepend to the list.
2955 : : If CHECK_DIR_P is true we ensure the directory exists.
2956 : : If DO_MULTI is true, multilib paths are output first, then
2957 : : non-multilib paths.
2958 : : This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
2959 : : It is also used by the --print-search-dirs flag. */
2960 : :
2961 : : static char *
2962 : 509864 : build_search_list (const struct path_prefix *paths, const char *prefix,
2963 : : bool check_dir, bool do_multi)
2964 : : {
2965 : 509864 : struct obstack *const ob = &collect_obstack;
2966 : 509864 : bool first_time = true;
2967 : :
2968 : 509864 : obstack_grow (&collect_obstack, prefix, strlen (prefix));
2969 : 509864 : obstack_1grow (&collect_obstack, '=');
2970 : :
2971 : : /* Callback adds path to obstack being built. */
2972 : 509864 : for_each_path (paths, do_multi, 0, [&](char *path) -> void*
2973 : : {
2974 : 7016134 : if (check_dir && !is_directory (path))
2975 : : return NULL;
2976 : :
2977 : 2584369 : if (!first_time)
2978 : 2075639 : obstack_1grow (ob, PATH_SEPARATOR);
2979 : :
2980 : 2584369 : obstack_grow (ob, path, strlen (path));
2981 : :
2982 : 2584369 : first_time = false;
2983 : 2584369 : return NULL;
2984 : : });
2985 : :
2986 : 509864 : obstack_1grow (&collect_obstack, '\0');
2987 : 509864 : return XOBFINISH (&collect_obstack, char *);
2988 : : }
2989 : :
2990 : : /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
2991 : : for collect. */
2992 : :
2993 : : static void
2994 : 509808 : putenv_from_prefixes (const struct path_prefix *paths, const char *env_var,
2995 : : bool do_multi)
2996 : : {
2997 : 509808 : xputenv (build_search_list (paths, env_var, true, do_multi));
2998 : 509808 : }
2999 : :
3000 : : /* Check whether NAME can be accessed in MODE. This is like access,
3001 : : except that it never considers directories to be executable. */
3002 : :
3003 : : static int
3004 : 7873218 : access_check (const char *name, int mode)
3005 : : {
3006 : 7873218 : if (mode == X_OK)
3007 : : {
3008 : 1518032 : struct stat st;
3009 : :
3010 : 1518032 : if (stat (name, &st) < 0
3011 : 1518032 : || S_ISDIR (st.st_mode))
3012 : 771792 : return -1;
3013 : : }
3014 : :
3015 : 7101426 : return access (name, mode);
3016 : : }
3017 : :
3018 : :
3019 : : /* Search for NAME using the prefix list PREFIXES. MODE is passed to
3020 : : access to check permissions. If DO_MULTI is true, search multilib
3021 : : paths then non-multilib paths, otherwise do not search multilib paths.
3022 : : Return 0 if not found, otherwise return its name, allocated with malloc. */
3023 : :
3024 : : static char *
3025 : 1779996 : find_a_file (const struct path_prefix *pprefix, const char *name, int mode,
3026 : : bool do_multi)
3027 : : {
3028 : : /* Find the filename in question (special case for absolute paths). */
3029 : :
3030 : 1779996 : if (IS_ABSOLUTE_PATH (name))
3031 : : {
3032 : 1 : if (access (name, mode) == 0)
3033 : 1 : return xstrdup (name);
3034 : :
3035 : : return NULL;
3036 : : }
3037 : :
3038 : 1779995 : const char *suffix = (mode & X_OK) != 0 ? HOST_EXECUTABLE_SUFFIX : "";
3039 : 1779995 : const int name_len = strlen (name);
3040 : 1779995 : const int suffix_len = strlen (suffix);
3041 : :
3042 : :
3043 : : /* Callback appends the file name to the directory path. If the
3044 : : resulting file exists in the right mode, return the full pathname
3045 : : to the file. */
3046 : 1779995 : return for_each_path (pprefix, do_multi,
3047 : : name_len + suffix_len,
3048 : 1779995 : [=](char *path) -> char*
3049 : : {
3050 : 7873218 : size_t len = strlen (path);
3051 : :
3052 : 7873218 : memcpy (path + len, name, name_len);
3053 : 7873218 : len += name_len;
3054 : :
3055 : : /* Some systems have a suffix for executable files.
3056 : : So try appending that first. */
3057 : 7873218 : if (suffix_len)
3058 : : {
3059 : 0 : memcpy (path + len, suffix, suffix_len + 1);
3060 : 0 : if (access_check (path, mode) == 0)
3061 : : return path;
3062 : : }
3063 : :
3064 : 7873218 : path[len] = '\0';
3065 : 7873218 : if (access_check (path, mode) == 0)
3066 : : return path;
3067 : :
3068 : : return NULL;
3069 : : });
3070 : : }
3071 : :
3072 : : /* Specialization of find_a_file for programs that also takes into account
3073 : : configure-specified default programs. */
3074 : :
3075 : : static char*
3076 : 752323 : find_a_program (const char *name)
3077 : : {
3078 : : /* Do not search if default matches query. */
3079 : :
3080 : : #ifdef DEFAULT_ASSEMBLER
3081 : : if (! strcmp (name, "as") && access (DEFAULT_ASSEMBLER, X_OK) == 0)
3082 : : return xstrdup (DEFAULT_ASSEMBLER);
3083 : : #endif
3084 : :
3085 : : #ifdef DEFAULT_LINKER
3086 : : if (! strcmp (name, "ld") && access (DEFAULT_LINKER, X_OK) == 0)
3087 : : return xstrdup (DEFAULT_LINKER);
3088 : : #endif
3089 : :
3090 : : #ifdef DEFAULT_DSYMUTIL
3091 : : if (! strcmp (name, "dsymutil") && access (DEFAULT_DSYMUTIL, X_OK) == 0)
3092 : : return xstrdup (DEFAULT_DSYMUTIL);
3093 : : #endif
3094 : :
3095 : 0 : return find_a_file (&exec_prefixes, name, X_OK, false);
3096 : : }
3097 : :
3098 : : /* Ranking of prefixes in the sort list. -B prefixes are put before
3099 : : all others. */
3100 : :
3101 : : enum path_prefix_priority
3102 : : {
3103 : : PREFIX_PRIORITY_B_OPT,
3104 : : PREFIX_PRIORITY_LAST
3105 : : };
3106 : :
3107 : : /* Add an entry for PREFIX in PLIST. The PLIST is kept in ascending
3108 : : order according to PRIORITY. Within each PRIORITY, new entries are
3109 : : appended.
3110 : :
3111 : : If WARN is nonzero, we will warn if no file is found
3112 : : through this prefix. WARN should point to an int
3113 : : which will be set to 1 if this entry is used.
3114 : :
3115 : : COMPONENT is the value to be passed to update_path.
3116 : :
3117 : : REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
3118 : : the complete value of machine_suffix.
3119 : : 2 means try both machine_suffix and just_machine_suffix. */
3120 : :
3121 : : static void
3122 : 3898103 : add_prefix (struct path_prefix *pprefix, const char *prefix,
3123 : : const char *component, /* enum prefix_priority */ int priority,
3124 : : int require_machine_suffix, int os_multilib)
3125 : : {
3126 : 3898103 : struct prefix_list *pl, **prev;
3127 : 3898103 : int len;
3128 : :
3129 : 3898103 : for (prev = &pprefix->plist;
3130 : 12367502 : (*prev) != NULL && (*prev)->priority <= priority;
3131 : 8469399 : prev = &(*prev)->next)
3132 : : ;
3133 : :
3134 : : /* Keep track of the longest prefix. */
3135 : :
3136 : 3898103 : prefix = update_path (prefix, component);
3137 : 3898103 : len = strlen (prefix);
3138 : 3898103 : if (len > pprefix->max_len)
3139 : 2111685 : pprefix->max_len = len;
3140 : :
3141 : 3898103 : pl = XNEW (struct prefix_list);
3142 : 3898103 : pl->prefix = prefix;
3143 : 3898103 : pl->require_machine_suffix = require_machine_suffix;
3144 : 3898103 : pl->priority = priority;
3145 : 3898103 : pl->os_multilib = os_multilib;
3146 : :
3147 : : /* Insert after PREV. */
3148 : 3898103 : pl->next = (*prev);
3149 : 3898103 : (*prev) = pl;
3150 : 3898103 : }
3151 : :
3152 : : /* Same as add_prefix, but prepending target_system_root to prefix. */
3153 : : /* The target_system_root prefix has been relocated by gcc_exec_prefix. */
3154 : : static void
3155 : 596300 : add_sysrooted_prefix (struct path_prefix *pprefix, const char *prefix,
3156 : : const char *component,
3157 : : /* enum prefix_priority */ int priority,
3158 : : int require_machine_suffix, int os_multilib)
3159 : : {
3160 : 596300 : if (!IS_ABSOLUTE_PATH (prefix))
3161 : 0 : fatal_error (input_location, "system path %qs is not absolute", prefix);
3162 : :
3163 : 596300 : if (target_system_root)
3164 : : {
3165 : 0 : char *sysroot_no_trailing_dir_separator = xstrdup (target_system_root);
3166 : 0 : size_t sysroot_len = strlen (target_system_root);
3167 : :
3168 : 0 : if (sysroot_len > 0
3169 : 0 : && target_system_root[sysroot_len - 1] == DIR_SEPARATOR)
3170 : 0 : sysroot_no_trailing_dir_separator[sysroot_len - 1] = '\0';
3171 : :
3172 : 0 : if (target_sysroot_suffix)
3173 : 0 : prefix = concat (sysroot_no_trailing_dir_separator,
3174 : : target_sysroot_suffix, prefix, NULL);
3175 : : else
3176 : 0 : prefix = concat (sysroot_no_trailing_dir_separator, prefix, NULL);
3177 : :
3178 : 0 : free (sysroot_no_trailing_dir_separator);
3179 : :
3180 : : /* We have to override this because GCC's notion of sysroot
3181 : : moves along with GCC. */
3182 : 0 : component = "GCC";
3183 : : }
3184 : :
3185 : 596300 : add_prefix (pprefix, prefix, component, priority,
3186 : : require_machine_suffix, os_multilib);
3187 : 596300 : }
3188 : :
3189 : : /* Same as add_prefix, but prepending target_sysroot_hdrs_suffix to prefix. */
3190 : :
3191 : : static void
3192 : 30924 : add_sysrooted_hdrs_prefix (struct path_prefix *pprefix, const char *prefix,
3193 : : const char *component,
3194 : : /* enum prefix_priority */ int priority,
3195 : : int require_machine_suffix, int os_multilib)
3196 : : {
3197 : 30924 : if (!IS_ABSOLUTE_PATH (prefix))
3198 : 0 : fatal_error (input_location, "system path %qs is not absolute", prefix);
3199 : :
3200 : 30924 : if (target_system_root)
3201 : : {
3202 : 0 : char *sysroot_no_trailing_dir_separator = xstrdup (target_system_root);
3203 : 0 : size_t sysroot_len = strlen (target_system_root);
3204 : :
3205 : 0 : if (sysroot_len > 0
3206 : 0 : && target_system_root[sysroot_len - 1] == DIR_SEPARATOR)
3207 : 0 : sysroot_no_trailing_dir_separator[sysroot_len - 1] = '\0';
3208 : :
3209 : 0 : if (target_sysroot_hdrs_suffix)
3210 : 0 : prefix = concat (sysroot_no_trailing_dir_separator,
3211 : : target_sysroot_hdrs_suffix, prefix, NULL);
3212 : : else
3213 : 0 : prefix = concat (sysroot_no_trailing_dir_separator, prefix, NULL);
3214 : :
3215 : 0 : free (sysroot_no_trailing_dir_separator);
3216 : :
3217 : : /* We have to override this because GCC's notion of sysroot
3218 : : moves along with GCC. */
3219 : 0 : component = "GCC";
3220 : : }
3221 : :
3222 : 30924 : add_prefix (pprefix, prefix, component, priority,
3223 : : require_machine_suffix, os_multilib);
3224 : 30924 : }
3225 : :
3226 : :
3227 : : /* Execute the command specified by the arguments on the current line of spec.
3228 : : When using pipes, this includes several piped-together commands
3229 : : with `|' between them.
3230 : :
3231 : : Return 0 if successful, -1 if failed. */
3232 : :
3233 : : static int
3234 : 546833 : execute (void)
3235 : : {
3236 : 546833 : int i;
3237 : 546833 : int n_commands; /* # of command. */
3238 : 546833 : char *string;
3239 : 546833 : struct pex_obj *pex;
3240 : 546833 : struct command
3241 : : {
3242 : : const char *prog; /* program name. */
3243 : : const char **argv; /* vector of args. */
3244 : : };
3245 : 546833 : const char *arg;
3246 : :
3247 : 546833 : struct command *commands; /* each command buffer with above info. */
3248 : :
3249 : 546833 : gcc_assert (!processing_spec_function);
3250 : :
3251 : 546833 : if (wrapper_string)
3252 : : {
3253 : 0 : string = find_a_program (argbuf[0]);
3254 : 0 : if (string)
3255 : 0 : argbuf[0] = string;
3256 : 0 : insert_wrapper (wrapper_string);
3257 : : }
3258 : :
3259 : : /* Count # of piped commands. */
3260 : 17312923 : for (n_commands = 1, i = 0; argbuf.iterate (i, &arg); i++)
3261 : 16766090 : if (strcmp (arg, "|") == 0)
3262 : 0 : n_commands++;
3263 : :
3264 : : /* Get storage for each command. */
3265 : 546833 : commands = XALLOCAVEC (struct command, n_commands);
3266 : :
3267 : : /* Split argbuf into its separate piped processes,
3268 : : and record info about each one.
3269 : : Also search for the programs that are to be run. */
3270 : :
3271 : 546833 : argbuf.safe_push (0);
3272 : :
3273 : 546833 : commands[0].prog = argbuf[0]; /* first command. */
3274 : 546833 : commands[0].argv = argbuf.address ();
3275 : :
3276 : 546833 : if (!wrapper_string)
3277 : : {
3278 : 546833 : string = find_a_program(commands[0].prog);
3279 : 546833 : if (string)
3280 : 544204 : commands[0].argv[0] = string;
3281 : : }
3282 : :
3283 : 17859756 : for (n_commands = 1, i = 0; argbuf.iterate (i, &arg); i++)
3284 : 17312923 : if (arg && strcmp (arg, "|") == 0)
3285 : : { /* each command. */
3286 : : #if defined (__MSDOS__) || defined (OS2) || defined (VMS)
3287 : : fatal_error (input_location, "%<-pipe%> not supported");
3288 : : #endif
3289 : 0 : argbuf[i] = 0; /* Termination of command args. */
3290 : 0 : commands[n_commands].prog = argbuf[i + 1];
3291 : 0 : commands[n_commands].argv
3292 : 0 : = &(argbuf.address ())[i + 1];
3293 : 0 : string = find_a_program(commands[n_commands].prog);
3294 : 0 : if (string)
3295 : 0 : commands[n_commands].argv[0] = string;
3296 : 0 : n_commands++;
3297 : : }
3298 : :
3299 : : /* If -v, print what we are about to do, and maybe query. */
3300 : :
3301 : 546833 : if (verbose_flag)
3302 : : {
3303 : : /* For help listings, put a blank line between sub-processes. */
3304 : 1401 : if (print_help_list)
3305 : 9 : fputc ('\n', stderr);
3306 : :
3307 : : /* Print each piped command as a separate line. */
3308 : 2802 : for (i = 0; i < n_commands; i++)
3309 : : {
3310 : 1401 : const char *const *j;
3311 : :
3312 : 1401 : if (verbose_only_flag)
3313 : : {
3314 : 17942 : for (j = commands[i].argv; *j; j++)
3315 : : {
3316 : : const char *p;
3317 : 428393 : for (p = *j; *p; ++p)
3318 : 413964 : if (!ISALNUM ((unsigned char) *p)
3319 : 97982 : && *p != '_' && *p != '/' && *p != '-' && *p != '.')
3320 : : break;
3321 : 16923 : if (*p || !*j)
3322 : : {
3323 : 2494 : fprintf (stderr, " \"");
3324 : 129851 : for (p = *j; *p; ++p)
3325 : : {
3326 : 127357 : if (*p == '"' || *p == '\\' || *p == '$')
3327 : 0 : fputc ('\\', stderr);
3328 : 127357 : fputc (*p, stderr);
3329 : : }
3330 : 2494 : fputc ('"', stderr);
3331 : : }
3332 : : /* If it's empty, print "". */
3333 : 14429 : else if (!**j)
3334 : 0 : fprintf (stderr, " \"\"");
3335 : : else
3336 : 14429 : fprintf (stderr, " %s", *j);
3337 : : }
3338 : : }
3339 : : else
3340 : 11579 : for (j = commands[i].argv; *j; j++)
3341 : : /* If it's empty, print "". */
3342 : 11197 : if (!**j)
3343 : 0 : fprintf (stderr, " \"\"");
3344 : : else
3345 : 11197 : fprintf (stderr, " %s", *j);
3346 : :
3347 : : /* Print a pipe symbol after all but the last command. */
3348 : 1401 : if (i + 1 != n_commands)
3349 : 0 : fprintf (stderr, " |");
3350 : 1401 : fprintf (stderr, "\n");
3351 : : }
3352 : 1401 : fflush (stderr);
3353 : 1401 : if (verbose_only_flag != 0)
3354 : : {
3355 : : /* verbose_only_flag should act as if the spec was
3356 : : executed, so increment execution_count before
3357 : : returning. This prevents spurious warnings about
3358 : : unused linker input files, etc. */
3359 : 1019 : execution_count++;
3360 : 1019 : return 0;
3361 : : }
3362 : : #ifdef DEBUG
3363 : : fnotice (stderr, "\nGo ahead? (y or n) ");
3364 : : fflush (stderr);
3365 : : i = getchar ();
3366 : : if (i != '\n')
3367 : : while (getchar () != '\n')
3368 : : ;
3369 : :
3370 : : if (i != 'y' && i != 'Y')
3371 : : return 0;
3372 : : #endif /* DEBUG */
3373 : : }
3374 : :
3375 : : #ifdef ENABLE_VALGRIND_CHECKING
3376 : : /* Run the each command through valgrind. To simplify prepending the
3377 : : path to valgrind and the option "-q" (for quiet operation unless
3378 : : something triggers), we allocate a separate argv array. */
3379 : :
3380 : : for (i = 0; i < n_commands; i++)
3381 : : {
3382 : : const char **argv;
3383 : : int argc;
3384 : : int j;
3385 : :
3386 : : for (argc = 0; commands[i].argv[argc] != NULL; argc++)
3387 : : ;
3388 : :
3389 : : argv = XALLOCAVEC (const char *, argc + 3);
3390 : :
3391 : : argv[0] = VALGRIND_PATH;
3392 : : argv[1] = "-q";
3393 : : for (j = 2; j < argc + 2; j++)
3394 : : argv[j] = commands[i].argv[j - 2];
3395 : : argv[j] = NULL;
3396 : :
3397 : : commands[i].argv = argv;
3398 : : commands[i].prog = argv[0];
3399 : : }
3400 : : #endif
3401 : :
3402 : : /* Run each piped subprocess. */
3403 : :
3404 : 545814 : pex = pex_init (PEX_USE_PIPES | ((report_times || report_times_to_file)
3405 : : ? PEX_RECORD_TIMES : 0),
3406 : : progname, temp_filename);
3407 : 545814 : if (pex == NULL)
3408 : : fatal_error (input_location, "%<pex_init%> failed: %m");
3409 : :
3410 : 1091628 : for (i = 0; i < n_commands; i++)
3411 : : {
3412 : 545814 : const char *errmsg;
3413 : 545814 : int err;
3414 : 545814 : const char *string = commands[i].argv[0];
3415 : :
3416 : 545814 : errmsg = pex_run (pex,
3417 : 545814 : ((i + 1 == n_commands ? PEX_LAST : 0)
3418 : 545814 : | (string == commands[i].prog ? PEX_SEARCH : 0)),
3419 : : string, CONST_CAST (char **, commands[i].argv),
3420 : : NULL, NULL, &err);
3421 : 545814 : if (errmsg != NULL)
3422 : : {
3423 : 0 : errno = err;
3424 : 0 : fatal_error (input_location,
3425 : : err ? G_("cannot execute %qs: %s: %m")
3426 : : : G_("cannot execute %qs: %s"),
3427 : : string, errmsg);
3428 : : }
3429 : :
3430 : 545814 : if (i && string != commands[i].prog)
3431 : 0 : free (CONST_CAST (char *, string));
3432 : : }
3433 : :
3434 : 545814 : execution_count++;
3435 : :
3436 : : /* Wait for all the subprocesses to finish. */
3437 : :
3438 : 545814 : {
3439 : 545814 : int *statuses;
3440 : 545814 : struct pex_time *times = NULL;
3441 : 545814 : int ret_code = 0;
3442 : :
3443 : 545814 : statuses = XALLOCAVEC (int, n_commands);
3444 : 545814 : if (!pex_get_status (pex, n_commands, statuses))
3445 : 0 : fatal_error (input_location, "failed to get exit status: %m");
3446 : :
3447 : 545814 : if (report_times || report_times_to_file)
3448 : : {
3449 : 0 : times = XALLOCAVEC (struct pex_time, n_commands);
3450 : 0 : if (!pex_get_times (pex, n_commands, times))
3451 : 0 : fatal_error (input_location, "failed to get process times: %m");
3452 : : }
3453 : :
3454 : 545814 : pex_free (pex);
3455 : :
3456 : 1091628 : for (i = 0; i < n_commands; ++i)
3457 : : {
3458 : 545814 : int status = statuses[i];
3459 : :
3460 : 545814 : if (WIFSIGNALED (status))
3461 : 0 : switch (WTERMSIG (status))
3462 : : {
3463 : 0 : case SIGINT:
3464 : 0 : case SIGTERM:
3465 : : /* SIGQUIT and SIGKILL are not available on MinGW. */
3466 : : #ifdef SIGQUIT
3467 : 0 : case SIGQUIT:
3468 : : #endif
3469 : : #ifdef SIGKILL
3470 : 0 : case SIGKILL:
3471 : : #endif
3472 : : /* The user (or environment) did something to the
3473 : : inferior. Making this an ICE confuses the user into
3474 : : thinking there's a compiler bug. Much more likely is
3475 : : the user or OOM killer nuked it. */
3476 : 0 : fatal_error (input_location,
3477 : : "%s signal terminated program %s",
3478 : : strsignal (WTERMSIG (status)),
3479 : 0 : commands[i].prog);
3480 : 0 : break;
3481 : :
3482 : : #ifdef SIGPIPE
3483 : 0 : case SIGPIPE:
3484 : : /* SIGPIPE is a special case. It happens in -pipe mode
3485 : : when the compiler dies before the preprocessor is
3486 : : done, or the assembler dies before the compiler is
3487 : : done. There's generally been an error already, and
3488 : : this is just fallout. So don't generate another
3489 : : error unless we would otherwise have succeeded. */
3490 : 0 : if (signal_count || greatest_status >= MIN_FATAL_STATUS)
3491 : : {
3492 : 0 : signal_count++;
3493 : 0 : ret_code = -1;
3494 : 0 : break;
3495 : : }
3496 : : #endif
3497 : : /* FALLTHROUGH */
3498 : :
3499 : 0 : default:
3500 : : /* The inferior failed to catch the signal. */
3501 : 0 : internal_error_no_backtrace ("%s signal terminated program %s",
3502 : : strsignal (WTERMSIG (status)),
3503 : 0 : commands[i].prog);
3504 : : }
3505 : 545814 : else if (WIFEXITED (status)
3506 : 545814 : && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
3507 : : {
3508 : : /* For ICEs in cc1, cc1obj, cc1plus see if it is
3509 : : reproducible or not. */
3510 : 29269 : const char *p;
3511 : 29269 : if (flag_report_bug
3512 : 0 : && WEXITSTATUS (status) == ICE_EXIT_CODE
3513 : 0 : && i == 0
3514 : 0 : && (p = strrchr (commands[0].argv[0], DIR_SEPARATOR))
3515 : 29269 : && startswith (p + 1, "cc1"))
3516 : 0 : try_generate_repro (commands[0].argv);
3517 : 29269 : if (WEXITSTATUS (status) > greatest_status)
3518 : 21 : greatest_status = WEXITSTATUS (status);
3519 : : ret_code = -1;
3520 : : }
3521 : :
3522 : 545814 : if (report_times || report_times_to_file)
3523 : : {
3524 : 0 : struct pex_time *pt = ×[i];
3525 : 0 : double ut, st;
3526 : :
3527 : 0 : ut = ((double) pt->user_seconds
3528 : 0 : + (double) pt->user_microseconds / 1.0e6);
3529 : 0 : st = ((double) pt->system_seconds
3530 : 0 : + (double) pt->system_microseconds / 1.0e6);
3531 : :
3532 : 0 : if (ut + st != 0)
3533 : : {
3534 : 0 : if (report_times)
3535 : 0 : fnotice (stderr, "# %s %.2f %.2f\n",
3536 : 0 : commands[i].prog, ut, st);
3537 : :
3538 : 0 : if (report_times_to_file)
3539 : : {
3540 : 0 : int c = 0;
3541 : 0 : const char *const *j;
3542 : :
3543 : 0 : fprintf (report_times_to_file, "%g %g", ut, st);
3544 : :
3545 : 0 : for (j = &commands[i].prog; *j; j = &commands[i].argv[++c])
3546 : : {
3547 : : const char *p;
3548 : 0 : for (p = *j; *p; ++p)
3549 : 0 : if (*p == '"' || *p == '\\' || *p == '$'
3550 : 0 : || ISSPACE (*p))
3551 : : break;
3552 : :
3553 : 0 : if (*p)
3554 : : {
3555 : 0 : fprintf (report_times_to_file, " \"");
3556 : 0 : for (p = *j; *p; ++p)
3557 : : {
3558 : 0 : if (*p == '"' || *p == '\\' || *p == '$')
3559 : 0 : fputc ('\\', report_times_to_file);
3560 : 0 : fputc (*p, report_times_to_file);
3561 : : }
3562 : 0 : fputc ('"', report_times_to_file);
3563 : : }
3564 : : else
3565 : 0 : fprintf (report_times_to_file, " %s", *j);
3566 : : }
3567 : :
3568 : 0 : fputc ('\n', report_times_to_file);
3569 : : }
3570 : : }
3571 : : }
3572 : : }
3573 : :
3574 : 545814 : if (commands[0].argv[0] != commands[0].prog)
3575 : 543185 : free (CONST_CAST (char *, commands[0].argv[0]));
3576 : :
3577 : : return ret_code;
3578 : : }
3579 : : }
3580 : :
3581 : : static struct switchstr *switches;
3582 : :
3583 : : static int n_switches;
3584 : :
3585 : : static int n_switches_alloc;
3586 : :
3587 : : /* Set to zero if -fcompare-debug is disabled, positive if it's
3588 : : enabled and we're running the first compilation, negative if it's
3589 : : enabled and we're running the second compilation. For most of the
3590 : : time, it's in the range -1..1, but it can be temporarily set to 2
3591 : : or 3 to indicate that the -fcompare-debug flags didn't come from
3592 : : the command-line, but rather from the GCC_COMPARE_DEBUG environment
3593 : : variable, until a synthesized -fcompare-debug flag is added to the
3594 : : command line. */
3595 : : int compare_debug;
3596 : :
3597 : : /* Set to nonzero if we've seen the -fcompare-debug-second flag. */
3598 : : int compare_debug_second;
3599 : :
3600 : : /* Set to the flags that should be passed to the second compilation in
3601 : : a -fcompare-debug compilation. */
3602 : : const char *compare_debug_opt;
3603 : :
3604 : : static struct switchstr *switches_debug_check[2];
3605 : :
3606 : : static int n_switches_debug_check[2];
3607 : :
3608 : : static int n_switches_alloc_debug_check[2];
3609 : :
3610 : : static char *debug_check_temp_file[2];
3611 : :
3612 : : /* Language is one of three things:
3613 : :
3614 : : 1) The name of a real programming language.
3615 : : 2) NULL, indicating that no one has figured out
3616 : : what it is yet.
3617 : : 3) '*', indicating that the file should be passed
3618 : : to the linker. */
3619 : : struct infile
3620 : : {
3621 : : const char *name;
3622 : : const char *language;
3623 : : struct compiler *incompiler;
3624 : : bool compiled;
3625 : : bool preprocessed;
3626 : : };
3627 : :
3628 : : /* Also a vector of input files specified. */
3629 : :
3630 : : static struct infile *infiles;
3631 : :
3632 : : int n_infiles;
3633 : :
3634 : : static int n_infiles_alloc;
3635 : :
3636 : : /* True if undefined environment variables encountered during spec processing
3637 : : are ok to ignore, typically when we're running for --help or --version. */
3638 : :
3639 : : static bool spec_undefvar_allowed;
3640 : :
3641 : : /* True if multiple input files are being compiled to a single
3642 : : assembly file. */
3643 : :
3644 : : static bool combine_inputs;
3645 : :
3646 : : /* This counts the number of libraries added by lang_specific_driver, so that
3647 : : we can tell if there were any user supplied any files or libraries. */
3648 : :
3649 : : static int added_libraries;
3650 : :
3651 : : /* And a vector of corresponding output files is made up later. */
3652 : :
3653 : : const char **outfiles;
3654 : :
3655 : : #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3656 : :
3657 : : /* Convert NAME to a new name if it is the standard suffix. DO_EXE
3658 : : is true if we should look for an executable suffix. DO_OBJ
3659 : : is true if we should look for an object suffix. */
3660 : :
3661 : : static const char *
3662 : : convert_filename (const char *name, int do_exe ATTRIBUTE_UNUSED,
3663 : : int do_obj ATTRIBUTE_UNUSED)
3664 : : {
3665 : : #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3666 : : int i;
3667 : : #endif
3668 : : int len;
3669 : :
3670 : : if (name == NULL)
3671 : : return NULL;
3672 : :
3673 : : len = strlen (name);
3674 : :
3675 : : #ifdef HAVE_TARGET_OBJECT_SUFFIX
3676 : : /* Convert x.o to x.obj if TARGET_OBJECT_SUFFIX is ".obj". */
3677 : : if (do_obj && len > 2
3678 : : && name[len - 2] == '.'
3679 : : && name[len - 1] == 'o')
3680 : : {
3681 : : obstack_grow (&obstack, name, len - 2);
3682 : : obstack_grow0 (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX));
3683 : : name = XOBFINISH (&obstack, const char *);
3684 : : }
3685 : : #endif
3686 : :
3687 : : #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3688 : : /* If there is no filetype, make it the executable suffix (which includes
3689 : : the "."). But don't get confused if we have just "-o". */
3690 : : if (! do_exe || TARGET_EXECUTABLE_SUFFIX[0] == 0 || not_actual_file_p (name))
3691 : : return name;
3692 : :
3693 : : for (i = len - 1; i >= 0; i--)
3694 : : if (IS_DIR_SEPARATOR (name[i]))
3695 : : break;
3696 : :
3697 : : for (i++; i < len; i++)
3698 : : if (name[i] == '.')
3699 : : return name;
3700 : :
3701 : : obstack_grow (&obstack, name, len);
3702 : : obstack_grow0 (&obstack, TARGET_EXECUTABLE_SUFFIX,
3703 : : strlen (TARGET_EXECUTABLE_SUFFIX));
3704 : : name = XOBFINISH (&obstack, const char *);
3705 : : #endif
3706 : :
3707 : : return name;
3708 : : }
3709 : : #endif
3710 : :
3711 : : /* Display the command line switches accepted by gcc. */
3712 : : static void
3713 : 4 : display_help (void)
3714 : : {
3715 : 4 : printf (_("Usage: %s [options] file...\n"), progname);
3716 : 4 : fputs (_("Options:\n"), stdout);
3717 : :
3718 : 4 : fputs (_(" -pass-exit-codes Exit with highest error code from a phase.\n"), stdout);
3719 : 4 : fputs (_(" --help Display this information.\n"), stdout);
3720 : 4 : fputs (_(" --target-help Display target specific command line options "
3721 : : "(including assembler and linker options).\n"), stdout);
3722 : 4 : fputs (_(" --help={common|optimizers|params|target|warnings|[^]{joined|separate|undocumented}}[,...].\n"), stdout);
3723 : 4 : fputs (_(" Display specific types of command line options.\n"), stdout);
3724 : 4 : if (! verbose_flag)
3725 : 1 : fputs (_(" (Use '-v --help' to display command line options of sub-processes).\n"), stdout);
3726 : 4 : fputs (_(" --version Display compiler version information.\n"), stdout);
3727 : 4 : fputs (_(" -dumpspecs Display all of the built in spec strings.\n"), stdout);
3728 : 4 : fputs (_(" -dumpversion Display the version of the compiler.\n"), stdout);
3729 : 4 : fputs (_(" -dumpmachine Display the compiler's target processor.\n"), stdout);
3730 : 4 : fputs (_(" -foffload=<targets> Specify offloading targets.\n"), stdout);
3731 : 4 : fputs (_(" -print-search-dirs Display the directories in the compiler's search path.\n"), stdout);
3732 : 4 : fputs (_(" -print-libgcc-file-name Display the name of the compiler's companion library.\n"), stdout);
3733 : 4 : fputs (_(" -print-file-name=<lib> Display the full path to library <lib>.\n"), stdout);
3734 : 4 : fputs (_(" -print-prog-name=<prog> Display the full path to compiler component <prog>.\n"), stdout);
3735 : 4 : fputs (_("\
3736 : : -print-multiarch Display the target's normalized GNU triplet, used as\n\
3737 : : a component in the library path.\n"), stdout);
3738 : 4 : fputs (_(" -print-multi-directory Display the root directory for versions of libgcc.\n"), stdout);
3739 : 4 : fputs (_("\
3740 : : -print-multi-lib Display the mapping between command line options and\n\
3741 : : multiple library search directories.\n"), stdout);
3742 : 4 : fputs (_(" -print-multi-os-directory Display the relative path to OS libraries.\n"), stdout);
3743 : 4 : fputs (_(" -print-sysroot Display the target libraries directory.\n"), stdout);
3744 : 4 : fputs (_(" -print-sysroot-headers-suffix Display the sysroot suffix used to find headers.\n"), stdout);
3745 : 4 : fputs (_(" -Wa,<options> Pass comma-separated <options> on to the assembler.\n"), stdout);
3746 : 4 : fputs (_(" -Wp,<options> Pass comma-separated <options> on to the preprocessor.\n"), stdout);
3747 : 4 : fputs (_(" -Wl,<options> Pass comma-separated <options> on to the linker.\n"), stdout);
3748 : 4 : fputs (_(" -Xassembler <arg> Pass <arg> on to the assembler.\n"), stdout);
3749 : 4 : fputs (_(" -Xpreprocessor <arg> Pass <arg> on to the preprocessor.\n"), stdout);
3750 : 4 : fputs (_(" -Xlinker <arg> Pass <arg> on to the linker.\n"), stdout);
3751 : 4 : fputs (_(" -save-temps Do not delete intermediate files.\n"), stdout);
3752 : 4 : fputs (_(" -save-temps=<arg> Do not delete intermediate files.\n"), stdout);
3753 : 4 : fputs (_("\
3754 : : -no-canonical-prefixes Do not canonicalize paths when building relative\n\
3755 : : prefixes to other gcc components.\n"), stdout);
3756 : 4 : fputs (_(" -pipe Use pipes rather than intermediate files.\n"), stdout);
3757 : 4 : fputs (_(" -time Time the execution of each subprocess.\n"), stdout);
3758 : 4 : fputs (_(" -specs=<file> Override built-in specs with the contents of <file>.\n"), stdout);
3759 : 4 : fputs (_(" -std=<standard> Assume that the input sources are for <standard>.\n"), stdout);
3760 : 4 : fputs (_("\
3761 : : --sysroot=<directory> Use <directory> as the root directory for headers\n\
3762 : : and libraries.\n"), stdout);
3763 : 4 : fputs (_(" -B <directory> Add <directory> to the compiler's search paths.\n"), stdout);
3764 : 4 : fputs (_(" -v Display the programs invoked by the compiler.\n"), stdout);
3765 : 4 : fputs (_(" -### Like -v but options quoted and commands not executed.\n"), stdout);
3766 : 4 : fputs (_(" -E Preprocess only; do not compile, assemble or link.\n"), stdout);
3767 : 4 : fputs (_(" -S Compile only; do not assemble or link.\n"), stdout);
3768 : 4 : fputs (_(" -c Compile and assemble, but do not link.\n"), stdout);
3769 : 4 : fputs (_(" -o <file> Place the output into <file>.\n"), stdout);
3770 : 4 : fputs (_(" -pie Create a dynamically linked position independent\n\
3771 : : executable.\n"), stdout);
3772 : 4 : fputs (_(" -shared Create a shared library.\n"), stdout);
3773 : 4 : fputs (_("\
3774 : : -x <language> Specify the language of the following input files.\n\
3775 : : Permissible languages include: c c++ assembler none\n\
3776 : : 'none' means revert to the default behavior of\n\
3777 : : guessing the language based on the file's extension.\n\
3778 : : "), stdout);
3779 : :
3780 : 4 : printf (_("\
3781 : : \nOptions starting with -g, -f, -m, -O, -W, or --param are automatically\n\
3782 : : passed on to the various sub-processes invoked by %s. In order to pass\n\
3783 : : other options on to these processes the -W<letter> options must be used.\n\
3784 : : "), progname);
3785 : :
3786 : : /* The rest of the options are displayed by invocations of the various
3787 : : sub-processes. */
3788 : 4 : }
3789 : :
3790 : : static void
3791 : 0 : add_preprocessor_option (const char *option, int len)
3792 : : {
3793 : 0 : preprocessor_options.safe_push (save_string (option, len));
3794 : 0 : }
3795 : :
3796 : : static void
3797 : 195 : add_assembler_option (const char *option, int len)
3798 : : {
3799 : 195 : assembler_options.safe_push (save_string (option, len));
3800 : 195 : }
3801 : :
3802 : : static void
3803 : 82 : add_linker_option (const char *option, int len)
3804 : : {
3805 : 82 : linker_options.safe_push (save_string (option, len));
3806 : 82 : }
3807 : :
3808 : : /* Allocate space for an input file in infiles. */
3809 : :
3810 : : static void
3811 : 879894 : alloc_infile (void)
3812 : : {
3813 : 879894 : if (n_infiles_alloc == 0)
3814 : : {
3815 : 298151 : n_infiles_alloc = 16;
3816 : 298151 : infiles = XNEWVEC (struct infile, n_infiles_alloc);
3817 : : }
3818 : 581743 : else if (n_infiles_alloc == n_infiles)
3819 : : {
3820 : 247 : n_infiles_alloc *= 2;
3821 : 247 : infiles = XRESIZEVEC (struct infile, infiles, n_infiles_alloc);
3822 : : }
3823 : 879894 : }
3824 : :
3825 : : /* Store an input file with the given NAME and LANGUAGE in
3826 : : infiles. */
3827 : :
3828 : : static void
3829 : 581744 : add_infile (const char *name, const char *language)
3830 : : {
3831 : 581744 : alloc_infile ();
3832 : 581744 : infiles[n_infiles].name = name;
3833 : 581744 : infiles[n_infiles++].language = language;
3834 : 581744 : }
3835 : :
3836 : : /* Allocate space for a switch in switches. */
3837 : :
3838 : : static void
3839 : 7597083 : alloc_switch (void)
3840 : : {
3841 : 7597083 : if (n_switches_alloc == 0)
3842 : : {
3843 : 298465 : n_switches_alloc = 16;
3844 : 298465 : switches = XNEWVEC (struct switchstr, n_switches_alloc);
3845 : : }
3846 : 7298618 : else if (n_switches_alloc == n_switches)
3847 : : {
3848 : 269764 : n_switches_alloc *= 2;
3849 : 269764 : switches = XRESIZEVEC (struct switchstr, switches, n_switches_alloc);
3850 : : }
3851 : 7597083 : }
3852 : :
3853 : : /* Save an option OPT with N_ARGS arguments in array ARGS, marking it
3854 : : as validated if VALIDATED and KNOWN if it is an internal switch. */
3855 : :
3856 : : static void
3857 : 6736305 : save_switch (const char *opt, size_t n_args, const char *const *args,
3858 : : bool validated, bool known)
3859 : : {
3860 : 6736305 : alloc_switch ();
3861 : 6736305 : switches[n_switches].part1 = opt + 1;
3862 : 6736305 : if (n_args == 0)
3863 : 5201749 : switches[n_switches].args = 0;
3864 : : else
3865 : : {
3866 : 1534556 : switches[n_switches].args = XNEWVEC (const char *, n_args + 1);
3867 : 1534556 : memcpy (switches[n_switches].args, args, n_args * sizeof (const char *));
3868 : 1534556 : switches[n_switches].args[n_args] = NULL;
3869 : : }
3870 : :
3871 : 6736305 : switches[n_switches].live_cond = 0;
3872 : 6736305 : switches[n_switches].validated = validated;
3873 : 6736305 : switches[n_switches].known = known;
3874 : 6736305 : switches[n_switches].ordering = 0;
3875 : 6736305 : n_switches++;
3876 : 6736305 : }
3877 : :
3878 : : /* Set the SOURCE_DATE_EPOCH environment variable to the current time if it is
3879 : : not set already. */
3880 : :
3881 : : static void
3882 : 619 : set_source_date_epoch_envvar ()
3883 : : {
3884 : : /* Array size is 21 = ceil(log_10(2^64)) + 1 to hold string representations
3885 : : of 64 bit integers. */
3886 : 619 : char source_date_epoch[21];
3887 : 619 : time_t tt;
3888 : :
3889 : 619 : errno = 0;
3890 : 619 : tt = time (NULL);
3891 : 619 : if (tt < (time_t) 0 || errno != 0)
3892 : 0 : tt = (time_t) 0;
3893 : :
3894 : 619 : snprintf (source_date_epoch, 21, "%llu", (unsigned long long) tt);
3895 : : /* Using setenv instead of xputenv because we want the variable to remain
3896 : : after finalizing so that it's still set in the second run when using
3897 : : -fcompare-debug. */
3898 : 619 : setenv ("SOURCE_DATE_EPOCH", source_date_epoch, 0);
3899 : 619 : }
3900 : :
3901 : : /* Handle an option DECODED that is unknown to the option-processing
3902 : : machinery. */
3903 : :
3904 : : static bool
3905 : 699 : driver_unknown_option_callback (const struct cl_decoded_option *decoded)
3906 : : {
3907 : 699 : const char *opt = decoded->arg;
3908 : 699 : if (opt[1] == 'W' && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-'
3909 : 93 : && !(decoded->errors & CL_ERR_NEGATIVE))
3910 : : {
3911 : : /* Leave unknown -Wno-* options for the compiler proper, to be
3912 : : diagnosed only if there are warnings. */
3913 : 91 : save_switch (decoded->canonical_option[0],
3914 : 91 : decoded->canonical_option_num_elements - 1,
3915 : : &decoded->canonical_option[1], false, true);
3916 : 91 : return false;
3917 : : }
3918 : 608 : if (decoded->opt_index == OPT_SPECIAL_unknown)
3919 : : {
3920 : : /* Give it a chance to define it a spec file. */
3921 : 608 : save_switch (decoded->canonical_option[0],
3922 : 608 : decoded->canonical_option_num_elements - 1,
3923 : : &decoded->canonical_option[1], false, false);
3924 : 608 : return false;
3925 : : }
3926 : : else
3927 : : return true;
3928 : : }
3929 : :
3930 : : /* Handle an option DECODED that is not marked as CL_DRIVER.
3931 : : LANG_MASK will always be CL_DRIVER. */
3932 : :
3933 : : static void
3934 : 4343673 : driver_wrong_lang_callback (const struct cl_decoded_option *decoded,
3935 : : unsigned int lang_mask ATTRIBUTE_UNUSED)
3936 : : {
3937 : : /* At this point, non-driver options are accepted (and expected to
3938 : : be passed down by specs) unless marked to be rejected by the
3939 : : driver. Options to be rejected by the driver but accepted by the
3940 : : compilers proper are treated just like completely unknown
3941 : : options. */
3942 : 4343673 : const struct cl_option *option = &cl_options[decoded->opt_index];
3943 : :
3944 : 4343673 : if (option->cl_reject_driver)
3945 : 0 : error ("unrecognized command-line option %qs",
3946 : 0 : decoded->orig_option_with_args_text);
3947 : : else
3948 : 4343673 : save_switch (decoded->canonical_option[0],
3949 : 4343673 : decoded->canonical_option_num_elements - 1,
3950 : : &decoded->canonical_option[1], false, true);
3951 : 4343673 : }
3952 : :
3953 : : static const char *spec_lang = 0;
3954 : : static int last_language_n_infiles;
3955 : :
3956 : :
3957 : : /* Check that GCC is configured to support the offload target. */
3958 : :
3959 : : static bool
3960 : 136 : check_offload_target_name (const char *target, ptrdiff_t len)
3961 : : {
3962 : 136 : const char *n, *c = OFFLOAD_TARGETS;
3963 : 272 : while (c)
3964 : : {
3965 : 136 : n = strchr (c, ',');
3966 : 136 : if (n == NULL)
3967 : 136 : n = strchr (c, '\0');
3968 : 136 : if (len == n - c && strncmp (target, c, n - c) == 0)
3969 : : break;
3970 : 136 : c = *n ? n + 1 : NULL;
3971 : : }
3972 : 136 : if (!c)
3973 : : {
3974 : 136 : auto_vec<const char*> candidates;
3975 : 136 : size_t olen = strlen (OFFLOAD_TARGETS) + 1;
3976 : 136 : char *cand = XALLOCAVEC (char, olen);
3977 : 136 : memcpy (cand, OFFLOAD_TARGETS, olen);
3978 : 136 : for (c = strtok (cand, ","); c; c = strtok (NULL, ","))
3979 : 0 : candidates.safe_push (c);
3980 : 136 : candidates.safe_push ("default");
3981 : 136 : candidates.safe_push ("disable");
3982 : :
3983 : 136 : char *target2 = XALLOCAVEC (char, len + 1);
3984 : 136 : memcpy (target2, target, len);
3985 : 136 : target2[len] = '\0';
3986 : :
3987 : 136 : error ("GCC is not configured to support %qs as %<-foffload=%> argument",
3988 : : target2);
3989 : :
3990 : 136 : char *s;
3991 : 136 : const char *hint = candidates_list_and_hint (target2, s, candidates);
3992 : 136 : if (hint)
3993 : 0 : inform (UNKNOWN_LOCATION,
3994 : : "valid %<-foffload=%> arguments are: %s; "
3995 : : "did you mean %qs?", s, hint);
3996 : : else
3997 : 136 : inform (UNKNOWN_LOCATION, "valid %<-foffload=%> arguments are: %s", s);
3998 : 136 : XDELETEVEC (s);
3999 : 136 : return false;
4000 : 136 : }
4001 : : return true;
4002 : : }
4003 : :
4004 : : /* Sanity check for -foffload-options. */
4005 : :
4006 : : static void
4007 : 27 : check_foffload_target_names (const char *arg)
4008 : : {
4009 : 27 : const char *cur, *next, *end;
4010 : : /* If option argument starts with '-' then no target is specified and we
4011 : : do not need to parse it. */
4012 : 27 : if (arg[0] == '-')
4013 : : return;
4014 : 0 : end = strchr (arg, '=');
4015 : 0 : if (end == NULL)
4016 : : {
4017 : 0 : error ("%<=%>options missing after %<-foffload-options=%>target");
4018 : 0 : return;
4019 : : }
4020 : :
4021 : : cur = arg;
4022 : 0 : while (cur < end)
4023 : : {
4024 : 0 : next = strchr (cur, ',');
4025 : 0 : if (next == NULL)
4026 : 0 : next = end;
4027 : 0 : next = (next > end) ? end : next;
4028 : :
4029 : : /* Retain non-supported targets after printing an error as those will not
4030 : : be processed; each enabled target only processes its triplet. */
4031 : 0 : check_offload_target_name (cur, next - cur);
4032 : 0 : cur = next + 1;
4033 : : }
4034 : : }
4035 : :
4036 : : /* Parse -foffload option argument. */
4037 : :
4038 : : static void
4039 : 2857 : handle_foffload_option (const char *arg)
4040 : : {
4041 : 2857 : const char *c, *cur, *n, *next, *end;
4042 : 2857 : char *target;
4043 : :
4044 : : /* If option argument starts with '-' then no target is specified and we
4045 : : do not need to parse it. */
4046 : 2857 : if (arg[0] == '-')
4047 : : return;
4048 : :
4049 : 2018 : end = strchr (arg, '=');
4050 : 2018 : if (end == NULL)
4051 : 2018 : end = strchr (arg, '\0');
4052 : 2018 : cur = arg;
4053 : :
4054 : 2018 : while (cur < end)
4055 : : {
4056 : 2018 : next = strchr (cur, ',');
4057 : 2018 : if (next == NULL)
4058 : 2018 : next = end;
4059 : 2018 : next = (next > end) ? end : next;
4060 : :
4061 : 2018 : target = XNEWVEC (char, next - cur + 1);
4062 : 2018 : memcpy (target, cur, next - cur);
4063 : 2018 : target[next - cur] = '\0';
4064 : :
4065 : : /* Reset offloading list and continue. */
4066 : 2018 : if (strcmp (target, "default") == 0)
4067 : : {
4068 : 0 : free (offload_targets);
4069 : 0 : offload_targets = NULL;
4070 : 0 : goto next_item;
4071 : : }
4072 : :
4073 : : /* If 'disable' is passed to the option, clean the list of
4074 : : offload targets and return, even if more targets follow.
4075 : : Likewise if GCC is not configured to support that offload target. */
4076 : 2018 : if (strcmp (target, "disable") == 0
4077 : 2018 : || !check_offload_target_name (target, next - cur))
4078 : : {
4079 : 2018 : free (offload_targets);
4080 : 2018 : offload_targets = xstrdup ("");
4081 : 2018 : return;
4082 : : }
4083 : :
4084 : 0 : if (!offload_targets)
4085 : : {
4086 : 0 : offload_targets = target;
4087 : 0 : target = NULL;
4088 : : }
4089 : : else
4090 : : {
4091 : : /* Check that the target hasn't already presented in the list. */
4092 : : c = offload_targets;
4093 : 0 : do
4094 : : {
4095 : 0 : n = strchr (c, ':');
4096 : 0 : if (n == NULL)
4097 : 0 : n = strchr (c, '\0');
4098 : :
4099 : 0 : if (next - cur == n - c && strncmp (c, target, n - c) == 0)
4100 : : break;
4101 : :
4102 : 0 : c = n + 1;
4103 : : }
4104 : 0 : while (*n);
4105 : :
4106 : : /* If duplicate is not found, append the target to the list. */
4107 : 0 : if (c > n)
4108 : : {
4109 : 0 : size_t offload_targets_len = strlen (offload_targets);
4110 : 0 : offload_targets
4111 : 0 : = XRESIZEVEC (char, offload_targets,
4112 : : offload_targets_len + 1 + next - cur + 1);
4113 : 0 : offload_targets[offload_targets_len++] = ':';
4114 : 0 : memcpy (offload_targets + offload_targets_len, target, next - cur + 1);
4115 : : }
4116 : : }
4117 : 0 : next_item:
4118 : 0 : cur = next + 1;
4119 : 0 : XDELETEVEC (target);
4120 : : }
4121 : : }
4122 : :
4123 : : /* Forward certain options to offloading compilation. */
4124 : :
4125 : : static void
4126 : 0 : forward_offload_option (size_t opt_index, const char *arg, bool validated)
4127 : : {
4128 : 0 : switch (opt_index)
4129 : : {
4130 : 0 : case OPT_l:
4131 : : /* Use a '_GCC_' prefix and standard name ('-l_GCC_m' irrespective of the
4132 : : host's 'MATH_LIBRARY', for example), so that the 'mkoffload's can tell
4133 : : this has been synthesized here, and translate/drop as necessary. */
4134 : : /* Note that certain libraries ('-lc', '-lgcc', '-lgomp', for example)
4135 : : are injected by default in offloading compilation, and therefore not
4136 : : forwarded here. */
4137 : : /* GCC libraries. */
4138 : 0 : if (/* '-lgfortran' */ strcmp (arg, "gfortran") == 0
4139 : 0 : || /* '-lstdc++' */ strcmp (arg, "stdc++") == 0)
4140 : 0 : save_switch (concat ("-foffload-options=-l_GCC_", arg, NULL),
4141 : : 0, NULL, validated, true);
4142 : : /* Other libraries. */
4143 : : else
4144 : : {
4145 : : /* The case will need special consideration where on the host
4146 : : '!need_math', but for offloading compilation still need
4147 : : '-foffload-options=-l_GCC_m'. The problem is that we don't get
4148 : : here anything like '-lm', because it's not synthesized in
4149 : : 'gcc/fortran/gfortranspec.cc:lang_specific_driver', for example.
4150 : : Generally synthesizing '-foffload-options=-l_GCC_m' etc. in the
4151 : : language specific drivers is non-trivial, needs very careful
4152 : : review of their options handling. However, this issue is not
4153 : : actually relevant for the current set of supported host/offloading
4154 : : configurations. */
4155 : 0 : int need_math = (MATH_LIBRARY[0] != '\0');
4156 : 0 : if (/* '-lm' */ (need_math && strcmp (arg, MATH_LIBRARY) == 0))
4157 : 0 : save_switch ("-foffload-options=-l_GCC_m",
4158 : : 0, NULL, validated, true);
4159 : : }
4160 : 0 : break;
4161 : 0 : default:
4162 : 0 : gcc_unreachable ();
4163 : : }
4164 : 0 : }
4165 : :
4166 : : /* Handle a driver option; arguments and return value as for
4167 : : handle_option. */
4168 : :
4169 : : static bool
4170 : 2723933 : driver_handle_option (struct gcc_options *opts,
4171 : : struct gcc_options *opts_set,
4172 : : const struct cl_decoded_option *decoded,
4173 : : unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
4174 : : location_t loc,
4175 : : const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED,
4176 : : diagnostics::context *dc,
4177 : : void (*) (void))
4178 : : {
4179 : 2723933 : size_t opt_index = decoded->opt_index;
4180 : 2723933 : const char *arg = decoded->arg;
4181 : 2723933 : const char *compare_debug_replacement_opt;
4182 : 2723933 : int value = decoded->value;
4183 : 2723933 : bool validated = false;
4184 : 2723933 : bool do_save = true;
4185 : :
4186 : 2723933 : gcc_assert (opts == &global_options);
4187 : 2723933 : gcc_assert (opts_set == &global_options_set);
4188 : 2723933 : gcc_assert (static_cast<diagnostics::kind> (kind)
4189 : : == diagnostics::kind::unspecified);
4190 : 2723933 : gcc_assert (loc == UNKNOWN_LOCATION);
4191 : 2723933 : gcc_assert (dc == global_dc);
4192 : :
4193 : 2723933 : switch (opt_index)
4194 : : {
4195 : 1 : case OPT_dumpspecs:
4196 : 1 : {
4197 : 1 : struct spec_list *sl;
4198 : 1 : init_spec ();
4199 : 47 : for (sl = specs; sl; sl = sl->next)
4200 : 46 : printf ("*%s:\n%s\n\n", sl->name, *(sl->ptr_spec));
4201 : 1 : if (link_command_spec)
4202 : 1 : printf ("*link_command:\n%s\n\n", link_command_spec);
4203 : 1 : exit (0);
4204 : : }
4205 : :
4206 : 280 : case OPT_dumpversion:
4207 : 280 : printf ("%s\n", spec_version);
4208 : 280 : exit (0);
4209 : :
4210 : 0 : case OPT_dumpmachine:
4211 : 0 : printf ("%s\n", spec_machine);
4212 : 0 : exit (0);
4213 : :
4214 : 0 : case OPT_dumpfullversion:
4215 : 0 : printf ("%s\n", BASEVER);
4216 : 0 : exit (0);
4217 : :
4218 : 78 : case OPT__version:
4219 : 78 : print_version = 1;
4220 : :
4221 : : /* CPP driver cannot obtain switch from cc1_options. */
4222 : 78 : if (is_cpp_driver)
4223 : 0 : add_preprocessor_option ("--version", strlen ("--version"));
4224 : 78 : add_assembler_option ("--version", strlen ("--version"));
4225 : 78 : add_linker_option ("--version", strlen ("--version"));
4226 : 78 : break;
4227 : :
4228 : 5 : case OPT__completion_:
4229 : 5 : validated = true;
4230 : 5 : completion = decoded->arg;
4231 : 5 : break;
4232 : :
4233 : 4 : case OPT__help:
4234 : 4 : print_help_list = 1;
4235 : :
4236 : : /* CPP driver cannot obtain switch from cc1_options. */
4237 : 4 : if (is_cpp_driver)
4238 : 0 : add_preprocessor_option ("--help", 6);
4239 : 4 : add_assembler_option ("--help", 6);
4240 : 4 : add_linker_option ("--help", 6);
4241 : 4 : break;
4242 : :
4243 : 97 : case OPT__help_:
4244 : 97 : print_subprocess_help = 2;
4245 : 97 : break;
4246 : :
4247 : 0 : case OPT__target_help:
4248 : 0 : print_subprocess_help = 1;
4249 : :
4250 : : /* CPP driver cannot obtain switch from cc1_options. */
4251 : 0 : if (is_cpp_driver)
4252 : 0 : add_preprocessor_option ("--target-help", 13);
4253 : 0 : add_assembler_option ("--target-help", 13);
4254 : 0 : add_linker_option ("--target-help", 13);
4255 : 0 : break;
4256 : :
4257 : : case OPT__no_sysroot_suffix:
4258 : : case OPT_pass_exit_codes:
4259 : : case OPT_print_search_dirs:
4260 : : case OPT_print_file_name_:
4261 : : case OPT_print_prog_name_:
4262 : : case OPT_print_multi_lib:
4263 : : case OPT_print_multi_directory:
4264 : : case OPT_print_sysroot:
4265 : : case OPT_print_multi_os_directory:
4266 : : case OPT_print_multiarch:
4267 : : case OPT_print_sysroot_headers_suffix:
4268 : : case OPT_time:
4269 : : case OPT_wrapper:
4270 : : /* These options set the variables specified in common.opt
4271 : : automatically, and do not need to be saved for spec
4272 : : processing. */
4273 : : do_save = false;
4274 : : break;
4275 : :
4276 : 392 : case OPT_print_libgcc_file_name:
4277 : 392 : print_file_name = "libgcc.a";
4278 : 392 : do_save = false;
4279 : 392 : break;
4280 : :
4281 : 0 : case OPT_fuse_ld_bfd:
4282 : 0 : use_ld = ".bfd";
4283 : 0 : break;
4284 : :
4285 : 0 : case OPT_fuse_ld_gold:
4286 : 0 : use_ld = ".gold";
4287 : 0 : break;
4288 : :
4289 : 0 : case OPT_fuse_ld_mold:
4290 : 0 : use_ld = ".mold";
4291 : 0 : break;
4292 : :
4293 : 0 : case OPT_fuse_ld_wild:
4294 : 0 : use_ld = ".wild";
4295 : 0 : break;
4296 : :
4297 : 0 : case OPT_fcompare_debug_second:
4298 : 0 : compare_debug_second = 1;
4299 : 0 : break;
4300 : :
4301 : 613 : case OPT_fcompare_debug:
4302 : 613 : switch (value)
4303 : : {
4304 : 0 : case 0:
4305 : 0 : compare_debug_replacement_opt = "-fcompare-debug=";
4306 : 0 : arg = "";
4307 : 0 : goto compare_debug_with_arg;
4308 : :
4309 : 613 : case 1:
4310 : 613 : compare_debug_replacement_opt = "-fcompare-debug=-gtoggle";
4311 : 613 : arg = "-gtoggle";
4312 : 613 : goto compare_debug_with_arg;
4313 : :
4314 : 0 : default:
4315 : 0 : gcc_unreachable ();
4316 : : }
4317 : 6 : break;
4318 : :
4319 : 6 : case OPT_fcompare_debug_:
4320 : 6 : compare_debug_replacement_opt = decoded->canonical_option[0];
4321 : 619 : compare_debug_with_arg:
4322 : 619 : gcc_assert (decoded->canonical_option_num_elements == 1);
4323 : 619 : gcc_assert (arg != NULL);
4324 : 619 : if (*arg)
4325 : 619 : compare_debug = 1;
4326 : : else
4327 : 0 : compare_debug = -1;
4328 : 619 : if (compare_debug < 0)
4329 : 0 : compare_debug_opt = NULL;
4330 : : else
4331 : 619 : compare_debug_opt = arg;
4332 : 619 : save_switch (compare_debug_replacement_opt, 0, NULL, validated, true);
4333 : 619 : set_source_date_epoch_envvar ();
4334 : 619 : return true;
4335 : :
4336 : 270294 : case OPT_fdiagnostics_color_:
4337 : 270294 : diagnostic_color_init (dc, value);
4338 : 270294 : break;
4339 : :
4340 : 265233 : case OPT_fdiagnostics_urls_:
4341 : 265233 : diagnostic_urls_init (dc, value);
4342 : 265233 : break;
4343 : :
4344 : 0 : case OPT_fdiagnostics_show_highlight_colors:
4345 : 0 : dc->set_show_highlight_colors (value);
4346 : 0 : break;
4347 : :
4348 : 0 : case OPT_fdiagnostics_format_:
4349 : 0 : {
4350 : 0 : const char *basename = (opts->x_dump_base_name ? opts->x_dump_base_name
4351 : : : opts->x_main_input_basename);
4352 : 0 : gcc_assert (dc);
4353 : 0 : diagnostics::output_format_init (*dc,
4354 : : opts->x_main_input_filename, basename,
4355 : : (enum diagnostics_output_format)value,
4356 : 0 : opts->x_flag_diagnostics_json_formatting);
4357 : 0 : break;
4358 : : }
4359 : :
4360 : 0 : case OPT_fdiagnostics_add_output_:
4361 : 0 : handle_OPT_fdiagnostics_add_output_ (*opts, *dc, arg, loc);
4362 : 0 : break;
4363 : :
4364 : 0 : case OPT_fdiagnostics_set_output_:
4365 : 0 : handle_OPT_fdiagnostics_set_output_ (*opts, *dc, arg, loc);
4366 : 0 : break;
4367 : :
4368 : 294152 : case OPT_fdiagnostics_text_art_charset_:
4369 : 294152 : dc->set_text_art_charset ((enum diagnostic_text_art_charset)value);
4370 : 294152 : break;
4371 : :
4372 : : case OPT_Wa_:
4373 : : {
4374 : : int prev, j;
4375 : : /* Pass the rest of this option to the assembler. */
4376 : :
4377 : : /* Split the argument at commas. */
4378 : : prev = 0;
4379 : 634 : for (j = 0; arg[j]; j++)
4380 : 586 : if (arg[j] == ',')
4381 : : {
4382 : 0 : add_assembler_option (arg + prev, j - prev);
4383 : 0 : prev = j + 1;
4384 : : }
4385 : :
4386 : : /* Record the part after the last comma. */
4387 : 48 : add_assembler_option (arg + prev, j - prev);
4388 : : }
4389 : 48 : do_save = false;
4390 : 48 : break;
4391 : :
4392 : : case OPT_Wp_:
4393 : : {
4394 : : int prev, j;
4395 : : /* Pass the rest of this option to the preprocessor. */
4396 : :
4397 : : /* Split the argument at commas. */
4398 : : prev = 0;
4399 : 0 : for (j = 0; arg[j]; j++)
4400 : 0 : if (arg[j] == ',')
4401 : : {
4402 : 0 : add_preprocessor_option (arg + prev, j - prev);
4403 : 0 : prev = j + 1;
4404 : : }
4405 : :
4406 : : /* Record the part after the last comma. */
4407 : 0 : add_preprocessor_option (arg + prev, j - prev);
4408 : : }
4409 : 0 : do_save = false;
4410 : 0 : break;
4411 : :
4412 : : case OPT_Wl_:
4413 : : {
4414 : : int prev, j;
4415 : : /* Split the argument at commas. */
4416 : : prev = 0;
4417 : 129976 : for (j = 0; arg[j]; j++)
4418 : 122141 : if (arg[j] == ',')
4419 : : {
4420 : 54 : add_infile (save_string (arg + prev, j - prev), "*");
4421 : 54 : prev = j + 1;
4422 : : }
4423 : : /* Record the part after the last comma. */
4424 : 7835 : add_infile (arg + prev, "*");
4425 : 7835 : if (strcmp (arg, "-z,lazy") == 0 || strcmp (arg, "-z,norelro") == 0)
4426 : 12 : avoid_linker_hardening_p = true;
4427 : : }
4428 : : do_save = false;
4429 : : break;
4430 : :
4431 : 12 : case OPT_z:
4432 : 12 : if (strcmp (arg, "lazy") == 0 || strcmp (arg, "norelro") == 0)
4433 : 12 : avoid_linker_hardening_p = true;
4434 : : break;
4435 : :
4436 : 0 : case OPT_Xlinker:
4437 : 0 : add_infile (arg, "*");
4438 : 0 : do_save = false;
4439 : 0 : break;
4440 : :
4441 : 0 : case OPT_Xpreprocessor:
4442 : 0 : add_preprocessor_option (arg, strlen (arg));
4443 : 0 : do_save = false;
4444 : 0 : break;
4445 : :
4446 : 65 : case OPT_Xassembler:
4447 : 65 : add_assembler_option (arg, strlen (arg));
4448 : 65 : do_save = false;
4449 : 65 : break;
4450 : :
4451 : 250910 : case OPT_l:
4452 : : /* POSIX allows separation of -l and the lib arg; canonicalize
4453 : : by concatenating -l with its arg */
4454 : 250910 : add_infile (concat ("-l", arg, NULL), "*");
4455 : :
4456 : : /* Forward to offloading compilation '-l[...]' flags for standard,
4457 : : well-known libraries. */
4458 : : /* Doing this processing here means that we don't get to see libraries
4459 : : injected via specs, such as '-lquadmath' injected via
4460 : : '[build]/[target]/libgfortran/libgfortran.spec'. However, this issue
4461 : : is not actually relevant for the current set of host/offloading
4462 : : configurations. */
4463 : 250910 : if (ENABLE_OFFLOADING)
4464 : : forward_offload_option (opt_index, arg, validated);
4465 : :
4466 : 250910 : do_save = false;
4467 : 250910 : break;
4468 : :
4469 : 263893 : case OPT_L:
4470 : : /* Similarly, canonicalize -L for linkers that may not accept
4471 : : separate arguments. */
4472 : 263893 : save_switch (concat ("-L", arg, NULL), 0, NULL, validated, true);
4473 : 263893 : return true;
4474 : :
4475 : 0 : case OPT_F:
4476 : : /* Likewise -F. */
4477 : 0 : save_switch (concat ("-F", arg, NULL), 0, NULL, validated, true);
4478 : 0 : return true;
4479 : :
4480 : 407 : case OPT_save_temps:
4481 : 407 : if (!save_temps_flag)
4482 : 401 : save_temps_flag = SAVE_TEMPS_DUMP;
4483 : : validated = true;
4484 : : break;
4485 : :
4486 : 58 : case OPT_save_temps_:
4487 : 58 : if (strcmp (arg, "cwd") == 0)
4488 : 29 : save_temps_flag = SAVE_TEMPS_CWD;
4489 : 29 : else if (strcmp (arg, "obj") == 0
4490 : 0 : || strcmp (arg, "object") == 0)
4491 : 29 : save_temps_flag = SAVE_TEMPS_OBJ;
4492 : : else
4493 : 0 : fatal_error (input_location, "%qs is an unknown %<-save-temps%> option",
4494 : 0 : decoded->orig_option_with_args_text);
4495 : 58 : save_temps_overrides_dumpdir = true;
4496 : 58 : break;
4497 : :
4498 : 22537 : case OPT_dumpdir:
4499 : 22537 : free (dumpdir);
4500 : 22537 : dumpdir = xstrdup (arg);
4501 : 22537 : save_temps_overrides_dumpdir = false;
4502 : 22537 : break;
4503 : :
4504 : 23966 : case OPT_dumpbase:
4505 : 23966 : free (dumpbase);
4506 : 23966 : dumpbase = xstrdup (arg);
4507 : 23966 : break;
4508 : :
4509 : 252 : case OPT_dumpbase_ext:
4510 : 252 : free (dumpbase_ext);
4511 : 252 : dumpbase_ext = xstrdup (arg);
4512 : 252 : break;
4513 : :
4514 : : case OPT_no_canonical_prefixes:
4515 : : /* Already handled as a special case, so ignored here. */
4516 : : do_save = false;
4517 : : break;
4518 : :
4519 : : case OPT_pipe:
4520 : : validated = true;
4521 : : /* These options set the variables specified in common.opt
4522 : : automatically, but do need to be saved for spec
4523 : : processing. */
4524 : : break;
4525 : :
4526 : 3 : case OPT_specs_:
4527 : 3 : {
4528 : 3 : struct user_specs *user = XNEW (struct user_specs);
4529 : :
4530 : 3 : user->next = (struct user_specs *) 0;
4531 : 3 : user->filename = arg;
4532 : 3 : if (user_specs_tail)
4533 : 0 : user_specs_tail->next = user;
4534 : : else
4535 : 3 : user_specs_head = user;
4536 : 3 : user_specs_tail = user;
4537 : : }
4538 : 3 : validated = true;
4539 : 3 : break;
4540 : :
4541 : 0 : case OPT__sysroot_:
4542 : 0 : target_system_root = arg;
4543 : 0 : target_system_root_changed = 1;
4544 : : /* Saving this option is useful to let self-specs decide to
4545 : : provide a default one. */
4546 : 0 : do_save = true;
4547 : 0 : validated = true;
4548 : 0 : break;
4549 : :
4550 : 0 : case OPT_time_:
4551 : 0 : if (report_times_to_file)
4552 : 0 : fclose (report_times_to_file);
4553 : 0 : report_times_to_file = fopen (arg, "a");
4554 : 0 : do_save = false;
4555 : 0 : break;
4556 : :
4557 : 9127 : case OPT_truncate:
4558 : 9127 : totruncate_file = arg;
4559 : 9127 : do_save = false;
4560 : 9127 : break;
4561 : :
4562 : 639 : case OPT____:
4563 : : /* "-###"
4564 : : This is similar to -v except that there is no execution
4565 : : of the commands and the echoed arguments are quoted. It
4566 : : is intended for use in shell scripts to capture the
4567 : : driver-generated command line. */
4568 : 639 : verbose_only_flag++;
4569 : 639 : verbose_flag = 1;
4570 : 639 : do_save = false;
4571 : 639 : break;
4572 : :
4573 : 491362 : case OPT_B:
4574 : 491362 : {
4575 : 491362 : size_t len = strlen (arg);
4576 : :
4577 : : /* Catch the case where the user has forgotten to append a
4578 : : directory separator to the path. Note, they may be using
4579 : : -B to add an executable name prefix, eg "i386-elf-", in
4580 : : order to distinguish between multiple installations of
4581 : : GCC in the same directory. Hence we must check to see
4582 : : if appending a directory separator actually makes a
4583 : : valid directory name. */
4584 : 491362 : if (!IS_DIR_SEPARATOR (arg[len - 1])
4585 : 491362 : && is_directory (arg))
4586 : : {
4587 : 96636 : char *tmp = XNEWVEC (char, len + 2);
4588 : 96636 : strcpy (tmp, arg);
4589 : 96636 : tmp[len] = DIR_SEPARATOR;
4590 : 96636 : tmp[++len] = 0;
4591 : 96636 : arg = tmp;
4592 : : }
4593 : :
4594 : 491362 : add_prefix (&exec_prefixes, arg, NULL,
4595 : : PREFIX_PRIORITY_B_OPT, 0, 0);
4596 : 491362 : add_prefix (&startfile_prefixes, arg, NULL,
4597 : : PREFIX_PRIORITY_B_OPT, 0, 0);
4598 : 491362 : add_prefix (&include_prefixes, arg, NULL,
4599 : : PREFIX_PRIORITY_B_OPT, 0, 0);
4600 : : }
4601 : 491362 : validated = true;
4602 : 491362 : break;
4603 : :
4604 : 2509 : case OPT_E:
4605 : 2509 : have_E = true;
4606 : 2509 : break;
4607 : :
4608 : 50289 : case OPT_x:
4609 : 50289 : spec_lang = arg;
4610 : 50289 : if (!strcmp (spec_lang, "none"))
4611 : : /* Suppress the warning if -xnone comes after the last input
4612 : : file, because alternate command interfaces like g++ might
4613 : : find it useful to place -xnone after each input file. */
4614 : 13119 : spec_lang = 0;
4615 : : else
4616 : 37170 : last_language_n_infiles = n_infiles;
4617 : : do_save = false;
4618 : : break;
4619 : :
4620 : 272622 : case OPT_o:
4621 : 272622 : have_o = 1;
4622 : : #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) || defined(HAVE_TARGET_OBJECT_SUFFIX)
4623 : : arg = convert_filename (arg, ! have_c, 0);
4624 : : #endif
4625 : 272622 : output_file = arg;
4626 : : /* On some systems, ld cannot handle "-o" without a space. So
4627 : : split the option from its argument. */
4628 : 272622 : save_switch ("-o", 1, &arg, validated, true);
4629 : 272622 : return true;
4630 : :
4631 : 2128 : case OPT_pie:
4632 : : #ifdef ENABLE_DEFAULT_PIE
4633 : : /* -pie is turned on by default. */
4634 : : validated = true;
4635 : : #endif
4636 : : /* FALLTHROUGH */
4637 : 2128 : case OPT_r:
4638 : 2128 : case OPT_shared:
4639 : 2128 : case OPT_no_pie:
4640 : 2128 : avoid_linker_hardening_p = true;
4641 : 2128 : break;
4642 : :
4643 : 101 : case OPT_static:
4644 : 101 : static_p = true;
4645 : 101 : break;
4646 : :
4647 : : case OPT_static_libgcc:
4648 : : case OPT_shared_libgcc:
4649 : : case OPT_static_libgfortran:
4650 : : case OPT_static_libquadmath:
4651 : : case OPT_static_libphobos:
4652 : : case OPT_static_libgm2:
4653 : : case OPT_static_libstdc__:
4654 : : /* These are always valid; gcc.cc itself understands the first two
4655 : : gfortranspec.cc understands -static-libgfortran,
4656 : : libgfortran.spec handles -static-libquadmath,
4657 : : d-spec.cc understands -static-libphobos,
4658 : : gm2spec.cc understands -static-libgm2,
4659 : : and g++spec.cc understands -static-libstdc++. */
4660 : : validated = true;
4661 : : break;
4662 : :
4663 : 78 : case OPT_fwpa:
4664 : 78 : flag_wpa = "";
4665 : 78 : break;
4666 : :
4667 : 27 : case OPT_foffload_options_:
4668 : 27 : check_foffload_target_names (arg);
4669 : 27 : break;
4670 : :
4671 : 2857 : case OPT_foffload_:
4672 : 2857 : handle_foffload_option (arg);
4673 : 2857 : if (arg[0] == '-' || NULL != strchr (arg, '='))
4674 : 839 : save_switch (concat ("-foffload-options=", arg, NULL),
4675 : : 0, NULL, validated, true);
4676 : : do_save = false;
4677 : : break;
4678 : :
4679 : 0 : case OPT_gcodeview:
4680 : 0 : add_infile ("--pdb=", "*");
4681 : 0 : break;
4682 : :
4683 : : default:
4684 : : /* Various driver options need no special processing at this
4685 : : point, having been handled in a prescan above or being
4686 : : handled by specs. */
4687 : : break;
4688 : : }
4689 : :
4690 : 1634077 : if (do_save)
4691 : 1852655 : save_switch (decoded->canonical_option[0],
4692 : 1852655 : decoded->canonical_option_num_elements - 1,
4693 : : &decoded->canonical_option[1], validated, true);
4694 : : return true;
4695 : : }
4696 : :
4697 : : /* Return true if F2 is F1 followed by a single suffix, i.e., by a
4698 : : period and additional characters other than a period. */
4699 : :
4700 : : static inline bool
4701 : 84981 : adds_single_suffix_p (const char *f2, const char *f1)
4702 : : {
4703 : 84981 : size_t len = strlen (f1);
4704 : :
4705 : 84981 : return (strncmp (f1, f2, len) == 0
4706 : 77085 : && f2[len] == '.'
4707 : 161595 : && strchr (f2 + len + 1, '.') == NULL);
4708 : : }
4709 : :
4710 : : /* Put the driver's standard set of option handlers in *HANDLERS. */
4711 : :
4712 : : static void
4713 : 861060 : set_option_handlers (struct cl_option_handlers *handlers)
4714 : : {
4715 : 861060 : handlers->unknown_option_callback = driver_unknown_option_callback;
4716 : 861060 : handlers->wrong_lang_callback = driver_wrong_lang_callback;
4717 : 861060 : handlers->num_handlers = 3;
4718 : 861060 : handlers->handlers[0].handler = driver_handle_option;
4719 : 861060 : handlers->handlers[0].mask = CL_DRIVER;
4720 : 861060 : handlers->handlers[1].handler = common_handle_option;
4721 : 861060 : handlers->handlers[1].mask = CL_COMMON;
4722 : 861060 : handlers->handlers[2].handler = target_handle_option;
4723 : 861060 : handlers->handlers[2].mask = CL_TARGET;
4724 : 0 : }
4725 : :
4726 : :
4727 : : /* Return the index into infiles for the single non-library
4728 : : non-lto-wpa input file, -1 if there isn't any, or -2 if there is
4729 : : more than one. */
4730 : : static inline int
4731 : 152506 : single_input_file_index ()
4732 : : {
4733 : 152506 : int ret = -1;
4734 : :
4735 : 491468 : for (int i = 0; i < n_infiles; i++)
4736 : : {
4737 : 351481 : if (infiles[i].language
4738 : 245091 : && (infiles[i].language[0] == '*'
4739 : 49521 : || (flag_wpa
4740 : 19068 : && strcmp (infiles[i].language, "lto") == 0)))
4741 : 214638 : continue;
4742 : :
4743 : 136843 : if (ret != -1)
4744 : : return -2;
4745 : :
4746 : : ret = i;
4747 : : }
4748 : :
4749 : : return ret;
4750 : : }
4751 : :
4752 : : /* Create the vector `switches' and its contents.
4753 : : Store its length in `n_switches'. */
4754 : :
4755 : : static void
4756 : 298436 : process_command (unsigned int decoded_options_count,
4757 : : struct cl_decoded_option *decoded_options)
4758 : : {
4759 : 298436 : const char *temp;
4760 : 298436 : char *temp1;
4761 : 298436 : char *tooldir_prefix, *tooldir_prefix2;
4762 : 298436 : char *(*get_relative_prefix) (const char *, const char *,
4763 : : const char *) = NULL;
4764 : 298436 : struct cl_option_handlers handlers;
4765 : 298436 : unsigned int j;
4766 : :
4767 : 298436 : gcc_exec_prefix = env.get ("GCC_EXEC_PREFIX");
4768 : :
4769 : 298436 : n_switches = 0;
4770 : 298436 : n_infiles = 0;
4771 : 298436 : added_libraries = 0;
4772 : :
4773 : : /* Figure compiler version from version string. */
4774 : :
4775 : 298436 : compiler_version = temp1 = xstrdup (version_string);
4776 : :
4777 : 2089052 : for (; *temp1; ++temp1)
4778 : : {
4779 : 2089052 : if (*temp1 == ' ')
4780 : : {
4781 : 298436 : *temp1 = '\0';
4782 : 298436 : break;
4783 : : }
4784 : : }
4785 : :
4786 : : /* Handle any -no-canonical-prefixes flag early, to assign the function
4787 : : that builds relative prefixes. This function creates default search
4788 : : paths that are needed later in normal option handling. */
4789 : :
4790 : 6759844 : for (j = 1; j < decoded_options_count; j++)
4791 : : {
4792 : 6461408 : if (decoded_options[j].opt_index == OPT_no_canonical_prefixes)
4793 : : {
4794 : : get_relative_prefix = make_relative_prefix_ignore_links;
4795 : : break;
4796 : : }
4797 : : }
4798 : 298436 : if (! get_relative_prefix)
4799 : 298436 : get_relative_prefix = make_relative_prefix;
4800 : :
4801 : : /* Set up the default search paths. If there is no GCC_EXEC_PREFIX,
4802 : : see if we can create it from the pathname specified in
4803 : : decoded_options[0].arg. */
4804 : :
4805 : 298436 : gcc_libexec_prefix = standard_libexec_prefix;
4806 : : #ifndef VMS
4807 : : /* FIXME: make_relative_prefix doesn't yet work for VMS. */
4808 : 298436 : if (!gcc_exec_prefix)
4809 : : {
4810 : 28915 : gcc_exec_prefix = get_relative_prefix (decoded_options[0].arg,
4811 : : standard_bindir_prefix,
4812 : : standard_exec_prefix);
4813 : 28915 : gcc_libexec_prefix = get_relative_prefix (decoded_options[0].arg,
4814 : : standard_bindir_prefix,
4815 : : standard_libexec_prefix);
4816 : 28915 : if (gcc_exec_prefix)
4817 : 28915 : xputenv (concat ("GCC_EXEC_PREFIX=", gcc_exec_prefix, NULL));
4818 : : }
4819 : : else
4820 : : {
4821 : : /* make_relative_prefix requires a program name, but
4822 : : GCC_EXEC_PREFIX is typically a directory name with a trailing
4823 : : / (which is ignored by make_relative_prefix), so append a
4824 : : program name. */
4825 : 269521 : char *tmp_prefix = concat (gcc_exec_prefix, "gcc", NULL);
4826 : 269521 : gcc_libexec_prefix = get_relative_prefix (tmp_prefix,
4827 : : standard_exec_prefix,
4828 : : standard_libexec_prefix);
4829 : :
4830 : : /* The path is unrelocated, so fallback to the original setting. */
4831 : 269521 : if (!gcc_libexec_prefix)
4832 : 269175 : gcc_libexec_prefix = standard_libexec_prefix;
4833 : :
4834 : 269521 : free (tmp_prefix);
4835 : : }
4836 : : #else
4837 : : #endif
4838 : : /* From this point onward, gcc_exec_prefix is non-null if the toolchain
4839 : : is relocated. The toolchain was either relocated using GCC_EXEC_PREFIX
4840 : : or an automatically created GCC_EXEC_PREFIX from
4841 : : decoded_options[0].arg. */
4842 : :
4843 : : /* Do language-specific adjustment/addition of flags. */
4844 : 298436 : lang_specific_driver (&decoded_options, &decoded_options_count,
4845 : : &added_libraries);
4846 : :
4847 : 298432 : if (gcc_exec_prefix)
4848 : : {
4849 : 298432 : int len = strlen (gcc_exec_prefix);
4850 : :
4851 : 298432 : if (len > (int) sizeof ("/lib/gcc/") - 1
4852 : 298432 : && (IS_DIR_SEPARATOR (gcc_exec_prefix[len-1])))
4853 : : {
4854 : 298432 : temp = gcc_exec_prefix + len - sizeof ("/lib/gcc/") + 1;
4855 : 298432 : if (IS_DIR_SEPARATOR (*temp)
4856 : 298432 : && filename_ncmp (temp + 1, "lib", 3) == 0
4857 : 298432 : && IS_DIR_SEPARATOR (temp[4])
4858 : 596864 : && filename_ncmp (temp + 5, "gcc", 3) == 0)
4859 : 298432 : len -= sizeof ("/lib/gcc/") - 1;
4860 : : }
4861 : :
4862 : 298432 : set_std_prefix (gcc_exec_prefix, len);
4863 : 298432 : add_prefix (&exec_prefixes, gcc_libexec_prefix, "GCC",
4864 : : PREFIX_PRIORITY_LAST, 0, 0);
4865 : 298432 : add_prefix (&startfile_prefixes, gcc_exec_prefix, "GCC",
4866 : : PREFIX_PRIORITY_LAST, 0, 0);
4867 : : }
4868 : :
4869 : : /* COMPILER_PATH and LIBRARY_PATH have values
4870 : : that are lists of directory names with colons. */
4871 : :
4872 : 298432 : temp = env.get ("COMPILER_PATH");
4873 : 298432 : if (temp)
4874 : : {
4875 : 22373 : const char *startp, *endp;
4876 : 22373 : char *nstore = (char *) alloca (strlen (temp) + 3);
4877 : :
4878 : 22373 : startp = endp = temp;
4879 : 2036809 : while (1)
4880 : : {
4881 : 2036809 : if (*endp == PATH_SEPARATOR || *endp == 0)
4882 : : {
4883 : 36244 : strncpy (nstore, startp, endp - startp);
4884 : 36244 : if (endp == startp)
4885 : 0 : strcpy (nstore, concat (".", dir_separator_str, NULL));
4886 : 36244 : else if (!IS_DIR_SEPARATOR (endp[-1]))
4887 : : {
4888 : 0 : nstore[endp - startp] = DIR_SEPARATOR;
4889 : 0 : nstore[endp - startp + 1] = 0;
4890 : : }
4891 : : else
4892 : 36244 : nstore[endp - startp] = 0;
4893 : 36244 : add_prefix (&exec_prefixes, nstore, 0,
4894 : : PREFIX_PRIORITY_LAST, 0, 0);
4895 : 36244 : add_prefix (&include_prefixes, nstore, 0,
4896 : : PREFIX_PRIORITY_LAST, 0, 0);
4897 : 36244 : if (*endp == 0)
4898 : : break;
4899 : 13871 : endp = startp = endp + 1;
4900 : : }
4901 : : else
4902 : 2000565 : endp++;
4903 : : }
4904 : : }
4905 : :
4906 : 298432 : temp = env.get (LIBRARY_PATH_ENV);
4907 : 298432 : if (temp && *cross_compile == '0')
4908 : : {
4909 : 23726 : const char *startp, *endp;
4910 : 23726 : char *nstore = (char *) alloca (strlen (temp) + 3);
4911 : :
4912 : 23726 : startp = endp = temp;
4913 : 4117465 : while (1)
4914 : : {
4915 : 4117465 : if (*endp == PATH_SEPARATOR || *endp == 0)
4916 : : {
4917 : 171143 : strncpy (nstore, startp, endp - startp);
4918 : 171143 : if (endp == startp)
4919 : 0 : strcpy (nstore, concat (".", dir_separator_str, NULL));
4920 : 171143 : else if (!IS_DIR_SEPARATOR (endp[-1]))
4921 : : {
4922 : 1353 : nstore[endp - startp] = DIR_SEPARATOR;
4923 : 1353 : nstore[endp - startp + 1] = 0;
4924 : : }
4925 : : else
4926 : 169790 : nstore[endp - startp] = 0;
4927 : 171143 : add_prefix (&startfile_prefixes, nstore, NULL,
4928 : : PREFIX_PRIORITY_LAST, 0, 1);
4929 : 171143 : if (*endp == 0)
4930 : : break;
4931 : 147417 : endp = startp = endp + 1;
4932 : : }
4933 : : else
4934 : 3946322 : endp++;
4935 : : }
4936 : : }
4937 : :
4938 : : /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
4939 : 298432 : temp = env.get ("LPATH");
4940 : 298432 : if (temp && *cross_compile == '0')
4941 : : {
4942 : 0 : const char *startp, *endp;
4943 : 0 : char *nstore = (char *) alloca (strlen (temp) + 3);
4944 : :
4945 : 0 : startp = endp = temp;
4946 : 0 : while (1)
4947 : : {
4948 : 0 : if (*endp == PATH_SEPARATOR || *endp == 0)
4949 : : {
4950 : 0 : strncpy (nstore, startp, endp - startp);
4951 : 0 : if (endp == startp)
4952 : 0 : strcpy (nstore, concat (".", dir_separator_str, NULL));
4953 : 0 : else if (!IS_DIR_SEPARATOR (endp[-1]))
4954 : : {
4955 : 0 : nstore[endp - startp] = DIR_SEPARATOR;
4956 : 0 : nstore[endp - startp + 1] = 0;
4957 : : }
4958 : : else
4959 : 0 : nstore[endp - startp] = 0;
4960 : 0 : add_prefix (&startfile_prefixes, nstore, NULL,
4961 : : PREFIX_PRIORITY_LAST, 0, 1);
4962 : 0 : if (*endp == 0)
4963 : : break;
4964 : 0 : endp = startp = endp + 1;
4965 : : }
4966 : : else
4967 : 0 : endp++;
4968 : : }
4969 : : }
4970 : :
4971 : : /* Process the options and store input files and switches in their
4972 : : vectors. */
4973 : :
4974 : 298432 : last_language_n_infiles = -1;
4975 : :
4976 : 298432 : set_option_handlers (&handlers);
4977 : :
4978 : 5790972 : for (j = 1; j < decoded_options_count; j++)
4979 : : {
4980 : 5681386 : switch (decoded_options[j].opt_index)
4981 : : {
4982 : 188846 : case OPT_S:
4983 : 188846 : case OPT_c:
4984 : 188846 : case OPT_E:
4985 : 188846 : have_c = 1;
4986 : 188846 : break;
4987 : : }
4988 : 5681386 : if (have_c)
4989 : : break;
4990 : : }
4991 : :
4992 : 7125217 : for (j = 1; j < decoded_options_count; j++)
4993 : : {
4994 : 6827066 : if (decoded_options[j].opt_index == OPT_SPECIAL_input_file)
4995 : : {
4996 : 322599 : const char *arg = decoded_options[j].arg;
4997 : :
4998 : : #ifdef HAVE_TARGET_OBJECT_SUFFIX
4999 : : arg = convert_filename (arg, 0, access (arg, F_OK));
5000 : : #endif
5001 : 322599 : add_infile (arg, spec_lang);
5002 : :
5003 : 322599 : continue;
5004 : 322599 : }
5005 : :
5006 : 6504467 : read_cmdline_option (&global_options, &global_options_set,
5007 : : decoded_options + j, UNKNOWN_LOCATION,
5008 : : CL_DRIVER, &handlers, global_dc);
5009 : : }
5010 : :
5011 : : /* If the user didn't specify any, default to all configured offload
5012 : : targets. */
5013 : 298151 : if (ENABLE_OFFLOADING && offload_targets == NULL)
5014 : : {
5015 : : handle_foffload_option (OFFLOAD_TARGETS);
5016 : : #if OFFLOAD_DEFAULTED
5017 : : offload_targets_default = true;
5018 : : #endif
5019 : : }
5020 : :
5021 : : /* TODO: check if -static -pie works and maybe use it. */
5022 : 298151 : if (flag_hardened)
5023 : : {
5024 : 91 : if (!avoid_linker_hardening_p && !static_p)
5025 : : {
5026 : : #if defined HAVE_LD_PIE && defined LD_PIE_SPEC
5027 : 67 : save_switch (LD_PIE_SPEC, 0, NULL, /*validated=*/true, /*known=*/false);
5028 : : #endif
5029 : : /* These are passed straight down to collect2 so we have to break
5030 : : it up like this. */
5031 : 67 : if (HAVE_LD_NOW_SUPPORT)
5032 : : {
5033 : 67 : add_infile ("-z", "*");
5034 : 67 : add_infile ("now", "*");
5035 : : }
5036 : 67 : if (HAVE_LD_RELRO_SUPPORT)
5037 : : {
5038 : 67 : add_infile ("-z", "*");
5039 : 67 : add_infile ("relro", "*");
5040 : : }
5041 : : }
5042 : : /* We can't use OPT_Whardened yet. Sigh. */
5043 : : else
5044 : 24 : warning_at (UNKNOWN_LOCATION, 0,
5045 : : "linker hardening options not enabled by %<-fhardened%> "
5046 : : "because other link options were specified on the command "
5047 : : "line");
5048 : : }
5049 : :
5050 : : /* Handle -gtoggle as it would later in toplev.cc:process_options to
5051 : : make the debug-level-gt spec function work as expected. */
5052 : 298151 : if (flag_gtoggle)
5053 : : {
5054 : 4 : if (debug_info_level == DINFO_LEVEL_NONE)
5055 : 0 : debug_info_level = DINFO_LEVEL_NORMAL;
5056 : : else
5057 : 4 : debug_info_level = DINFO_LEVEL_NONE;
5058 : : }
5059 : :
5060 : 298151 : if (output_file
5061 : 272621 : && strcmp (output_file, "-") != 0
5062 : 272458 : && strcmp (output_file, HOST_BIT_BUCKET) != 0)
5063 : : {
5064 : : int i;
5065 : 808124 : for (i = 0; i < n_infiles; i++)
5066 : 260280 : if ((!infiles[i].language || infiles[i].language[0] != '*')
5067 : 564899 : && canonical_filename_eq (infiles[i].name, output_file))
5068 : 1 : fatal_error (input_location,
5069 : : "input file %qs is the same as output file",
5070 : : output_file);
5071 : : }
5072 : :
5073 : 298150 : if (output_file != NULL && output_file[0] == '\0')
5074 : 0 : fatal_error (input_location, "output filename may not be empty");
5075 : :
5076 : : /* -dumpdir and -save-temps=* both specify the location of aux/dump
5077 : : outputs; the one that appears last prevails. When compiling
5078 : : multiple sources, an explicit dumpbase (minus -ext) may be
5079 : : combined with an explicit or implicit dumpdir, whereas when
5080 : : linking, a specified or implied link output name (minus
5081 : : extension) may be combined with a prevailing -save-temps=* or an
5082 : : otherwise implied dumpdir, but not override a prevailing
5083 : : -dumpdir. Primary outputs (e.g., linker output when linking
5084 : : without -o, or .i, .s or .o outputs when processing multiple
5085 : : inputs with -E, -S or -c, respectively) are NOT affected by these
5086 : : -save-temps=/-dump* options, always landing in the current
5087 : : directory and with the same basename as the input when an output
5088 : : name is not given, but when they're intermediate outputs, they
5089 : : are named like other aux outputs, so the options affect their
5090 : : location and name.
5091 : :
5092 : : Here are some examples. There are several more in the
5093 : : documentation of -o and -dump*, and some quite exhaustive tests
5094 : : in gcc.misc-tests/outputs.exp.
5095 : :
5096 : : When compiling any number of sources, no -dump* nor
5097 : : -save-temps=*, all outputs in cwd without prefix:
5098 : :
5099 : : # gcc -c b.c -gsplit-dwarf
5100 : : -> cc1 [-dumpdir ./] -dumpbase b.c -dumpbase-ext .c # b.o b.dwo
5101 : :
5102 : : # gcc -c b.c d.c -gsplit-dwarf
5103 : : -> cc1 [-dumpdir ./] -dumpbase b.c -dumpbase-ext .c # b.o b.dwo
5104 : : && cc1 [-dumpdir ./] -dumpbase d.c -dumpbase-ext .c # d.o d.dwo
5105 : :
5106 : : When compiling and linking, no -dump* nor -save-temps=*, .o
5107 : : outputs are temporary, aux outputs land in the dir of the output,
5108 : : prefixed with the basename of the linker output:
5109 : :
5110 : : # gcc b.c d.c -o ab -gsplit-dwarf
5111 : : -> cc1 -dumpdir ab- -dumpbase b.c -dumpbase-ext .c # ab-b.dwo
5112 : : && cc1 -dumpdir ab- -dumpbase d.c -dumpbase-ext .c # ab-d.dwo
5113 : : && link ... -o ab
5114 : :
5115 : : # gcc b.c d.c [-o a.out] -gsplit-dwarf
5116 : : -> cc1 -dumpdir a- -dumpbase b.c -dumpbase-ext .c # a-b.dwo
5117 : : && cc1 -dumpdir a- -dumpbase d.c -dumpbase-ext .c # a-d.dwo
5118 : : && link ... [-o a.out]
5119 : :
5120 : : When compiling and linking, a prevailing -dumpdir fully overrides
5121 : : the prefix of aux outputs given by the output name:
5122 : :
5123 : : # gcc -dumpdir f b.c d.c -gsplit-dwarf [-o [dir/]whatever]
5124 : : -> cc1 -dumpdir f -dumpbase b.c -dumpbase-ext .c # fb.dwo
5125 : : && cc1 -dumpdir f -dumpbase d.c -dumpbase-ext .c # fd.dwo
5126 : : && link ... [-o whatever]
5127 : :
5128 : : When compiling multiple inputs, an explicit -dumpbase is combined
5129 : : with -dumpdir, affecting aux outputs, but not the .o outputs:
5130 : :
5131 : : # gcc -dumpdir f -dumpbase g- b.c d.c -gsplit-dwarf -c
5132 : : -> cc1 -dumpdir fg- -dumpbase b.c -dumpbase-ext .c # b.o fg-b.dwo
5133 : : && cc1 -dumpdir fg- -dumpbase d.c -dumpbase-ext .c # d.o fg-d.dwo
5134 : :
5135 : : When compiling and linking with -save-temps, the .o outputs that
5136 : : would have been temporary become aux outputs, so they get
5137 : : affected by -dump* flags:
5138 : :
5139 : : # gcc -dumpdir f -dumpbase g- -save-temps b.c d.c
5140 : : -> cc1 -dumpdir fg- -dumpbase b.c -dumpbase-ext .c # fg-b.o
5141 : : && cc1 -dumpdir fg- -dumpbase d.c -dumpbase-ext .c # fg-d.o
5142 : : && link
5143 : :
5144 : : If -save-temps=* prevails over -dumpdir, however, the explicit
5145 : : -dumpdir is discarded, as if it wasn't there. The basename of
5146 : : the implicit linker output, a.out or a.exe, becomes a- as the aux
5147 : : output prefix for all compilations:
5148 : :
5149 : : # gcc [-dumpdir f] -save-temps=cwd b.c d.c
5150 : : -> cc1 -dumpdir a- -dumpbase b.c -dumpbase-ext .c # a-b.o
5151 : : && cc1 -dumpdir a- -dumpbase d.c -dumpbase-ext .c # a-d.o
5152 : : && link
5153 : :
5154 : : A single -dumpbase, applying to multiple inputs, overrides the
5155 : : linker output name, implied or explicit, as the aux output prefix:
5156 : :
5157 : : # gcc [-dumpdir f] -dumpbase g- -save-temps=cwd b.c d.c
5158 : : -> cc1 -dumpdir g- -dumpbase b.c -dumpbase-ext .c # g-b.o
5159 : : && cc1 -dumpdir g- -dumpbase d.c -dumpbase-ext .c # g-d.o
5160 : : && link
5161 : :
5162 : : # gcc [-dumpdir f] -dumpbase g- -save-temps=cwd b.c d.c -o dir/h.out
5163 : : -> cc1 -dumpdir g- -dumpbase b.c -dumpbase-ext .c # g-b.o
5164 : : && cc1 -dumpdir g- -dumpbase d.c -dumpbase-ext .c # g-d.o
5165 : : && link -o dir/h.out
5166 : :
5167 : : Now, if the linker output is NOT overridden as a prefix, but
5168 : : -save-temps=* overrides implicit or explicit -dumpdir, the
5169 : : effective dump dir combines the dir selected by the -save-temps=*
5170 : : option with the basename of the specified or implied link output:
5171 : :
5172 : : # gcc [-dumpdir f] -save-temps=cwd b.c d.c -o dir/h.out
5173 : : -> cc1 -dumpdir h- -dumpbase b.c -dumpbase-ext .c # h-b.o
5174 : : && cc1 -dumpdir h- -dumpbase d.c -dumpbase-ext .c # h-d.o
5175 : : && link -o dir/h.out
5176 : :
5177 : : # gcc [-dumpdir f] -save-temps=obj b.c d.c -o dir/h.out
5178 : : -> cc1 -dumpdir dir/h- -dumpbase b.c -dumpbase-ext .c # dir/h-b.o
5179 : : && cc1 -dumpdir dir/h- -dumpbase d.c -dumpbase-ext .c # dir/h-d.o
5180 : : && link -o dir/h.out
5181 : :
5182 : : But then again, a single -dumpbase applying to multiple inputs
5183 : : gets used instead of the linker output basename in the combined
5184 : : dumpdir:
5185 : :
5186 : : # gcc [-dumpdir f] -dumpbase g- -save-temps=obj b.c d.c -o dir/h.out
5187 : : -> cc1 -dumpdir dir/g- -dumpbase b.c -dumpbase-ext .c # dir/g-b.o
5188 : : && cc1 -dumpdir dir/g- -dumpbase d.c -dumpbase-ext .c # dir/g-d.o
5189 : : && link -o dir/h.out
5190 : :
5191 : : With a single input being compiled, the output basename does NOT
5192 : : affect the dumpdir prefix.
5193 : :
5194 : : # gcc -save-temps=obj b.c -gsplit-dwarf -c -o dir/b.o
5195 : : -> cc1 -dumpdir dir/ -dumpbase b.c -dumpbase-ext .c # dir/b.o dir/b.dwo
5196 : :
5197 : : but when compiling and linking even a single file, it does:
5198 : :
5199 : : # gcc -save-temps=obj b.c -o dir/h.out
5200 : : -> cc1 -dumpdir dir/h- -dumpbase b.c -dumpbase-ext .c # dir/h-b.o
5201 : :
5202 : : unless an explicit -dumpdir prevails:
5203 : :
5204 : : # gcc -save-temps[=obj] -dumpdir g- b.c -o dir/h.out
5205 : : -> cc1 -dumpdir g- -dumpbase b.c -dumpbase-ext .c # g-b.o
5206 : :
5207 : : */
5208 : :
5209 : 298150 : bool explicit_dumpdir = dumpdir;
5210 : :
5211 : 298098 : if ((!save_temps_overrides_dumpdir && explicit_dumpdir)
5212 : 573719 : || (output_file && not_actual_file_p (output_file)))
5213 : : {
5214 : : /* Do nothing. */
5215 : : }
5216 : :
5217 : : /* If -save-temps=obj and -o name, create the prefix to use for %b.
5218 : : Otherwise just make -save-temps=obj the same as -save-temps=cwd. */
5219 : 274047 : else if (save_temps_flag != SAVE_TEMPS_CWD && output_file != NULL)
5220 : : {
5221 : 257109 : free (dumpdir);
5222 : 257109 : dumpdir = NULL;
5223 : 257109 : temp = lbasename (output_file);
5224 : 257109 : if (temp != output_file)
5225 : 103311 : dumpdir = xstrndup (output_file,
5226 : 103311 : strlen (output_file) - strlen (temp));
5227 : : }
5228 : 16938 : else if (dumpdir)
5229 : : {
5230 : 5 : free (dumpdir);
5231 : 5 : dumpdir = NULL;
5232 : : }
5233 : :
5234 : 298150 : if (save_temps_flag)
5235 : 459 : save_temps_flag = SAVE_TEMPS_DUMP;
5236 : :
5237 : : /* If there is any pathname component in an explicit -dumpbase, it
5238 : : overrides dumpdir entirely, so discard it right away. Although
5239 : : the presence of an explicit -dumpdir matters for the driver, it
5240 : : shouldn't matter for other processes, that get all that's needed
5241 : : from the -dumpdir and -dumpbase always passed to them. */
5242 : 298150 : if (dumpdir && dumpbase && lbasename (dumpbase) != dumpbase)
5243 : : {
5244 : 22442 : free (dumpdir);
5245 : 22442 : dumpdir = NULL;
5246 : : }
5247 : :
5248 : : /* Check that dumpbase_ext matches the end of dumpbase, drop it
5249 : : otherwise. */
5250 : 298150 : if (dumpbase_ext && dumpbase && *dumpbase)
5251 : : {
5252 : 20 : int lendb = strlen (dumpbase);
5253 : 20 : int lendbx = strlen (dumpbase_ext);
5254 : :
5255 : : /* -dumpbase-ext must be a suffix proper; discard it if it
5256 : : matches all of -dumpbase, as that would make for an empty
5257 : : basename. */
5258 : 20 : if (lendbx >= lendb
5259 : 19 : || strcmp (dumpbase + lendb - lendbx, dumpbase_ext) != 0)
5260 : : {
5261 : 1 : free (dumpbase_ext);
5262 : 1 : dumpbase_ext = NULL;
5263 : : }
5264 : : }
5265 : :
5266 : : /* -dumpbase with multiple sources goes into dumpdir. With a single
5267 : : source, it does only if linking and if dumpdir was not explicitly
5268 : : specified. */
5269 : 23966 : if (dumpbase && *dumpbase
5270 : 320670 : && (single_input_file_index () == -2
5271 : 22236 : || (!have_c && !explicit_dumpdir)))
5272 : : {
5273 : 296 : char *prefix;
5274 : :
5275 : 296 : if (dumpbase_ext)
5276 : : /* We checked that they match above. */
5277 : 6 : dumpbase[strlen (dumpbase) - strlen (dumpbase_ext)] = '\0';
5278 : :
5279 : 296 : if (dumpdir)
5280 : 13 : prefix = concat (dumpdir, dumpbase, "-", NULL);
5281 : : else
5282 : 283 : prefix = concat (dumpbase, "-", NULL);
5283 : :
5284 : 296 : free (dumpdir);
5285 : 296 : free (dumpbase);
5286 : 296 : free (dumpbase_ext);
5287 : 296 : dumpbase = dumpbase_ext = NULL;
5288 : 296 : dumpdir = prefix;
5289 : 296 : dumpdir_trailing_dash_added = true;
5290 : : }
5291 : :
5292 : : /* If dumpbase was not brought into dumpdir but we're linking, bring
5293 : : output_file into dumpdir unless dumpdir was explicitly specified.
5294 : : The test for !explicit_dumpdir is further below, because we want
5295 : : to use the obase computation for a ghost outbase, passed to
5296 : : GCC_COLLECT_OPTIONS. */
5297 : 297854 : else if (!have_c && (!explicit_dumpdir || (dumpbase && !*dumpbase)))
5298 : : {
5299 : : /* If we get here, we know dumpbase was not specified, or it was
5300 : : specified as an empty string. If it was anything else, it
5301 : : would have combined with dumpdir above, because the condition
5302 : : for dumpbase to be used when present is broader than the
5303 : : condition that gets us here. */
5304 : 109203 : gcc_assert (!dumpbase || !*dumpbase);
5305 : :
5306 : 109203 : const char *obase;
5307 : 109203 : char *tofree = NULL;
5308 : 109203 : if (!output_file || not_actual_file_p (output_file))
5309 : : obase = "a";
5310 : : else
5311 : : {
5312 : 95658 : obase = lbasename (output_file);
5313 : 95658 : size_t blen = strlen (obase), xlen;
5314 : : /* Drop the suffix if it's dumpbase_ext, if given,
5315 : : otherwise .exe or the target executable suffix, or if the
5316 : : output was explicitly named a.out, but not otherwise. */
5317 : 95658 : if (dumpbase_ext
5318 : 95658 : ? (blen > (xlen = strlen (dumpbase_ext))
5319 : 223 : && strcmp ((temp = (obase + blen - xlen)),
5320 : : dumpbase_ext) == 0)
5321 : 95435 : : ((temp = strrchr (obase + 1, '.'))
5322 : 93581 : && (xlen = strlen (temp))
5323 : 189016 : && (strcmp (temp, ".exe") == 0
5324 : : #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
5325 : : || strcmp (temp, TARGET_EXECUTABLE_SUFFIX) == 0
5326 : : #endif
5327 : 9027 : || strcmp (obase, "a.out") == 0)))
5328 : : {
5329 : 84803 : tofree = xstrndup (obase, blen - xlen);
5330 : 84803 : obase = tofree;
5331 : : }
5332 : : }
5333 : :
5334 : : /* We wish to save this basename to the -dumpdir passed through
5335 : : GCC_COLLECT_OPTIONS within maybe_run_linker, for e.g. LTO,
5336 : : but we do NOT wish to add it to e.g. %b, so we keep
5337 : : outbase_length as zero. */
5338 : 109203 : gcc_assert (!outbase);
5339 : 109203 : outbase_length = 0;
5340 : :
5341 : : /* If we're building [dir1/]foo[.exe] out of a single input
5342 : : [dir2/]foo.c that shares the same basename, dump to
5343 : : [dir2/]foo.c.* rather than duplicating the basename into
5344 : : [dir2/]foo-foo.c.*. */
5345 : 109203 : int idxin;
5346 : 109203 : if (dumpbase
5347 : 109203 : || ((idxin = single_input_file_index ()) >= 0
5348 : 84981 : && adds_single_suffix_p (lbasename (infiles[idxin].name),
5349 : : obase)))
5350 : : {
5351 : 78055 : if (obase == tofree)
5352 : 76294 : outbase = tofree;
5353 : : else
5354 : : {
5355 : 1761 : outbase = xstrdup (obase);
5356 : 1761 : free (tofree);
5357 : : }
5358 : 109203 : obase = tofree = NULL;
5359 : : }
5360 : : else
5361 : : {
5362 : 31148 : if (dumpdir)
5363 : : {
5364 : 15233 : char *p = concat (dumpdir, obase, "-", NULL);
5365 : 15233 : free (dumpdir);
5366 : 15233 : dumpdir = p;
5367 : : }
5368 : : else
5369 : 15915 : dumpdir = concat (obase, "-", NULL);
5370 : :
5371 : 31148 : dumpdir_trailing_dash_added = true;
5372 : :
5373 : 31148 : free (tofree);
5374 : 31148 : obase = tofree = NULL;
5375 : : }
5376 : :
5377 : 109203 : if (!explicit_dumpdir || dumpbase)
5378 : : {
5379 : : /* Absent -dumpbase and present -dumpbase-ext have been applied
5380 : : to the linker output name, so compute fresh defaults for each
5381 : : compilation. */
5382 : 109203 : free (dumpbase_ext);
5383 : 109203 : dumpbase_ext = NULL;
5384 : : }
5385 : : }
5386 : :
5387 : : /* Now, if we're compiling, or if we haven't used the dumpbase
5388 : : above, then outbase (%B) is derived from dumpbase, if given, or
5389 : : from the output name, given or implied. We can't precompute
5390 : : implied output names, but that's ok, since they're derived from
5391 : : input names. Just make sure we skip this if dumpbase is the
5392 : : empty string: we want to use input names then, so don't set
5393 : : outbase. */
5394 : 298150 : if ((dumpbase || have_c)
5395 : 190309 : && !(dumpbase && !*dumpbase))
5396 : : {
5397 : 188863 : gcc_assert (!outbase);
5398 : :
5399 : 188863 : if (dumpbase)
5400 : : {
5401 : 22224 : gcc_assert (single_input_file_index () != -2);
5402 : : /* We do not want lbasename here; dumpbase with dirnames
5403 : : overrides dumpdir entirely, even if dumpdir is
5404 : : specified. */
5405 : 22224 : if (dumpbase_ext)
5406 : : /* We've already checked above that the suffix matches. */
5407 : 13 : outbase = xstrndup (dumpbase,
5408 : 13 : strlen (dumpbase) - strlen (dumpbase_ext));
5409 : : else
5410 : 22211 : outbase = xstrdup (dumpbase);
5411 : : }
5412 : 166639 : else if (output_file && !not_actual_file_p (output_file))
5413 : : {
5414 : 161688 : outbase = xstrdup (lbasename (output_file));
5415 : 161688 : char *p = strrchr (outbase + 1, '.');
5416 : 161688 : if (p)
5417 : 161688 : *p = '\0';
5418 : : }
5419 : :
5420 : 188863 : if (outbase)
5421 : 183912 : outbase_length = strlen (outbase);
5422 : : }
5423 : :
5424 : : /* If there is any pathname component in an explicit -dumpbase, do
5425 : : not use dumpdir, but retain it to pass it on to the compiler. */
5426 : 298150 : if (dumpdir)
5427 : 119596 : dumpdir_length = strlen (dumpdir);
5428 : : else
5429 : 178554 : dumpdir_length = 0;
5430 : :
5431 : : /* Check that dumpbase_ext, if still present, still matches the end
5432 : : of dumpbase, if present, and drop it otherwise. We only retained
5433 : : it above when dumpbase was absent to maybe use it to drop the
5434 : : extension from output_name before combining it with dumpdir. We
5435 : : won't deal with -dumpbase-ext when -dumpbase is not explicitly
5436 : : given, even if just to activate backward-compatible dumpbase:
5437 : : dropping it on the floor is correct, expected and documented
5438 : : behavior. Attempting to deal with a -dumpbase-ext that might
5439 : : match the end of some input filename, or of the combination of
5440 : : the output basename with the suffix of the input filename,
5441 : : possible with an intermediate .gk extension for -fcompare-debug,
5442 : : is just calling for trouble. */
5443 : 298150 : if (dumpbase_ext)
5444 : : {
5445 : 22 : if (!dumpbase || !*dumpbase)
5446 : : {
5447 : 9 : free (dumpbase_ext);
5448 : 9 : dumpbase_ext = NULL;
5449 : : }
5450 : : else
5451 : 13 : gcc_assert (strcmp (dumpbase + strlen (dumpbase)
5452 : : - strlen (dumpbase_ext), dumpbase_ext) == 0);
5453 : : }
5454 : :
5455 : 298150 : if (save_temps_flag && use_pipes)
5456 : : {
5457 : : /* -save-temps overrides -pipe, so that temp files are produced */
5458 : 0 : if (save_temps_flag)
5459 : 0 : warning (0, "%<-pipe%> ignored because %<-save-temps%> specified");
5460 : 0 : use_pipes = 0;
5461 : : }
5462 : :
5463 : 298150 : if (!compare_debug)
5464 : : {
5465 : 297531 : const char *gcd = env.get ("GCC_COMPARE_DEBUG");
5466 : :
5467 : 297531 : if (gcd && gcd[0] == '-')
5468 : : {
5469 : 0 : compare_debug = 2;
5470 : 0 : compare_debug_opt = gcd;
5471 : : }
5472 : 0 : else if (gcd && *gcd && strcmp (gcd, "0"))
5473 : : {
5474 : 0 : compare_debug = 3;
5475 : 0 : compare_debug_opt = "-gtoggle";
5476 : : }
5477 : : }
5478 : 619 : else if (compare_debug < 0)
5479 : : {
5480 : 0 : compare_debug = 0;
5481 : 0 : gcc_assert (!compare_debug_opt);
5482 : : }
5483 : :
5484 : : /* Set up the search paths. We add directories that we expect to
5485 : : contain GNU Toolchain components before directories specified by
5486 : : the machine description so that we will find GNU components (like
5487 : : the GNU assembler) before those of the host system. */
5488 : :
5489 : : /* If we don't know where the toolchain has been installed, use the
5490 : : configured-in locations. */
5491 : 298150 : if (!gcc_exec_prefix)
5492 : : {
5493 : : #ifndef OS2
5494 : 0 : add_prefix (&exec_prefixes, standard_libexec_prefix, "GCC",
5495 : : PREFIX_PRIORITY_LAST, 1, 0);
5496 : 0 : add_prefix (&exec_prefixes, standard_libexec_prefix, "BINUTILS",
5497 : : PREFIX_PRIORITY_LAST, 2, 0);
5498 : 0 : add_prefix (&exec_prefixes, standard_exec_prefix, "BINUTILS",
5499 : : PREFIX_PRIORITY_LAST, 2, 0);
5500 : : #endif
5501 : 0 : add_prefix (&startfile_prefixes, standard_exec_prefix, "BINUTILS",
5502 : : PREFIX_PRIORITY_LAST, 1, 0);
5503 : : }
5504 : :
5505 : 298150 : gcc_assert (!IS_ABSOLUTE_PATH (tooldir_base_prefix));
5506 : 298150 : tooldir_prefix2 = concat (tooldir_base_prefix, spec_machine,
5507 : : dir_separator_str, NULL);
5508 : :
5509 : : /* Look for tools relative to the location from which the driver is
5510 : : running, or, if that is not available, the configured prefix. */
5511 : 298150 : tooldir_prefix
5512 : 596300 : = concat (gcc_exec_prefix ? gcc_exec_prefix : standard_exec_prefix,
5513 : : spec_host_machine, dir_separator_str, spec_version,
5514 : : accel_dir_suffix, dir_separator_str, tooldir_prefix2, NULL);
5515 : 298150 : free (tooldir_prefix2);
5516 : :
5517 : 298150 : add_prefix (&exec_prefixes,
5518 : 298150 : concat (tooldir_prefix, "bin", dir_separator_str, NULL),
5519 : : "BINUTILS", PREFIX_PRIORITY_LAST, 0, 0);
5520 : 298150 : add_prefix (&startfile_prefixes,
5521 : 298150 : concat (tooldir_prefix, "lib", dir_separator_str, NULL),
5522 : : "BINUTILS", PREFIX_PRIORITY_LAST, 0, 1);
5523 : 298150 : free (tooldir_prefix);
5524 : :
5525 : : #if defined(TARGET_SYSTEM_ROOT_RELOCATABLE) && !defined(VMS)
5526 : : /* If the normal TARGET_SYSTEM_ROOT is inside of $exec_prefix,
5527 : : then consider it to relocate with the rest of the GCC installation
5528 : : if GCC_EXEC_PREFIX is set.
5529 : : ``make_relative_prefix'' is not compiled for VMS, so don't call it. */
5530 : : if (target_system_root && !target_system_root_changed && gcc_exec_prefix)
5531 : : {
5532 : : char *tmp_prefix = get_relative_prefix (decoded_options[0].arg,
5533 : : standard_bindir_prefix,
5534 : : target_system_root);
5535 : : if (tmp_prefix && access_check (tmp_prefix, F_OK) == 0)
5536 : : {
5537 : : target_system_root = tmp_prefix;
5538 : : target_system_root_changed = 1;
5539 : : }
5540 : : }
5541 : : #endif
5542 : :
5543 : : /* More prefixes are enabled in main, after we read the specs file
5544 : : and determine whether this is cross-compilation or not. */
5545 : :
5546 : 298150 : if (n_infiles != 0 && n_infiles == last_language_n_infiles && spec_lang != 0)
5547 : 0 : warning (0, "%<-x %s%> after last input file has no effect", spec_lang);
5548 : :
5549 : : /* Synthesize -fcompare-debug flag from the GCC_COMPARE_DEBUG
5550 : : environment variable. */
5551 : 298150 : if (compare_debug == 2 || compare_debug == 3)
5552 : : {
5553 : 0 : const char *opt = concat ("-fcompare-debug=", compare_debug_opt, NULL);
5554 : 0 : save_switch (opt, 0, NULL, false, true);
5555 : 0 : compare_debug = 1;
5556 : : }
5557 : :
5558 : : /* Ensure we only invoke each subprocess once. */
5559 : 298150 : if (n_infiles == 0
5560 : 8087 : && (print_subprocess_help || print_help_list || print_version))
5561 : : {
5562 : : /* Create a dummy input file, so that we can pass
5563 : : the help option on to the various sub-processes. */
5564 : 78 : add_infile ("help-dummy", "c");
5565 : : }
5566 : :
5567 : : /* Decide if undefined variable references are allowed in specs. */
5568 : :
5569 : : /* -v alone is safe. --version and --help alone or together are safe. Note
5570 : : that -v would make them unsafe, as they'd then be run for subprocesses as
5571 : : well, the location of which might depend on variables possibly coming
5572 : : from self-specs. Note also that the command name is counted in
5573 : : decoded_options_count. */
5574 : :
5575 : 298150 : unsigned help_version_count = 0;
5576 : :
5577 : 298150 : if (print_version)
5578 : 78 : help_version_count++;
5579 : :
5580 : 298150 : if (print_help_list)
5581 : 4 : help_version_count++;
5582 : :
5583 : 596300 : spec_undefvar_allowed =
5584 : 1471 : ((verbose_flag && decoded_options_count == 2)
5585 : 299551 : || help_version_count == decoded_options_count - 1);
5586 : :
5587 : 298150 : alloc_switch ();
5588 : 298150 : switches[n_switches].part1 = 0;
5589 : 298150 : alloc_infile ();
5590 : 298150 : infiles[n_infiles].name = 0;
5591 : 298150 : }
5592 : :
5593 : : /* Store switches not filtered out by %<S in spec in COLLECT_GCC_OPTIONS
5594 : : and place that in the environment. */
5595 : :
5596 : : static void
5597 : 826434 : set_collect_gcc_options (void)
5598 : : {
5599 : 826434 : int i;
5600 : 826434 : int first_time;
5601 : :
5602 : : /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
5603 : : the compiler. */
5604 : 826434 : obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
5605 : : sizeof ("COLLECT_GCC_OPTIONS=") - 1);
5606 : :
5607 : 826434 : first_time = true;
5608 : 19956435 : for (i = 0; (int) i < n_switches; i++)
5609 : : {
5610 : 19130001 : const char *const *args;
5611 : 19130001 : const char *p, *q;
5612 : 19130001 : if (!first_time)
5613 : 18303567 : obstack_grow (&collect_obstack, " ", 1);
5614 : :
5615 : 19130001 : first_time = false;
5616 : :
5617 : : /* Ignore elided switches. */
5618 : 19260292 : if ((switches[i].live_cond
5619 : 19130001 : & (SWITCH_IGNORE | SWITCH_KEEP_FOR_GCC))
5620 : : == SWITCH_IGNORE)
5621 : 130291 : continue;
5622 : :
5623 : 18999710 : obstack_grow (&collect_obstack, "'-", 2);
5624 : 18999710 : q = switches[i].part1;
5625 : 18999710 : while ((p = strchr (q, '\'')))
5626 : : {
5627 : 0 : obstack_grow (&collect_obstack, q, p - q);
5628 : 0 : obstack_grow (&collect_obstack, "'\\''", 4);
5629 : 0 : q = ++p;
5630 : : }
5631 : 18999710 : obstack_grow (&collect_obstack, q, strlen (q));
5632 : 18999710 : obstack_grow (&collect_obstack, "'", 1);
5633 : :
5634 : 23167999 : for (args = switches[i].args; args && *args; args++)
5635 : : {
5636 : 4168289 : obstack_grow (&collect_obstack, " '", 2);
5637 : 4168289 : q = *args;
5638 : 4168289 : while ((p = strchr (q, '\'')))
5639 : : {
5640 : 0 : obstack_grow (&collect_obstack, q, p - q);
5641 : 0 : obstack_grow (&collect_obstack, "'\\''", 4);
5642 : 0 : q = ++p;
5643 : : }
5644 : 4168289 : obstack_grow (&collect_obstack, q, strlen (q));
5645 : 4168289 : obstack_grow (&collect_obstack, "'", 1);
5646 : : }
5647 : : }
5648 : :
5649 : 826434 : if (dumpdir)
5650 : : {
5651 : 584025 : if (!first_time)
5652 : 584025 : obstack_grow (&collect_obstack, " ", 1);
5653 : 584025 : first_time = false;
5654 : :
5655 : 584025 : obstack_grow (&collect_obstack, "'-dumpdir' '", 12);
5656 : 584025 : const char *p, *q;
5657 : :
5658 : 584025 : q = dumpdir;
5659 : 584025 : while ((p = strchr (q, '\'')))
5660 : : {
5661 : 0 : obstack_grow (&collect_obstack, q, p - q);
5662 : 0 : obstack_grow (&collect_obstack, "'\\''", 4);
5663 : 0 : q = ++p;
5664 : : }
5665 : 584025 : obstack_grow (&collect_obstack, q, strlen (q));
5666 : :
5667 : 584025 : obstack_grow (&collect_obstack, "'", 1);
5668 : : }
5669 : :
5670 : 826434 : obstack_grow (&collect_obstack, "\0", 1);
5671 : 826434 : xputenv (XOBFINISH (&collect_obstack, char *));
5672 : 826434 : }
5673 : :
5674 : : /* Process a spec string, accumulating and running commands. */
5675 : :
5676 : : /* These variables describe the input file name.
5677 : : input_file_number is the index on outfiles of this file,
5678 : : so that the output file name can be stored for later use by %o.
5679 : : input_basename is the start of the part of the input file
5680 : : sans all directory names, and basename_length is the number
5681 : : of characters starting there excluding the suffix .c or whatever. */
5682 : :
5683 : : static const char *gcc_input_filename;
5684 : : static int input_file_number;
5685 : : size_t input_filename_length;
5686 : : static int basename_length;
5687 : : static int suffixed_basename_length;
5688 : : static const char *input_basename;
5689 : : static const char *input_suffix;
5690 : : #ifndef HOST_LACKS_INODE_NUMBERS
5691 : : static struct stat input_stat;
5692 : : #endif
5693 : : static int input_stat_set;
5694 : :
5695 : : /* The compiler used to process the current input file. */
5696 : : static struct compiler *input_file_compiler;
5697 : :
5698 : : /* These are variables used within do_spec and do_spec_1. */
5699 : :
5700 : : /* Nonzero if an arg has been started and not yet terminated
5701 : : (with space, tab or newline). */
5702 : : static int arg_going;
5703 : :
5704 : : /* Nonzero means %d or %g has been seen; the next arg to be terminated
5705 : : is a temporary file name. */
5706 : : static int delete_this_arg;
5707 : :
5708 : : /* Nonzero means %w has been seen; the next arg to be terminated
5709 : : is the output file name of this compilation. */
5710 : : static int this_is_output_file;
5711 : :
5712 : : /* Nonzero means %s has been seen; the next arg to be terminated
5713 : : is the name of a library file and we should try the standard
5714 : : search dirs for it. */
5715 : : static int this_is_library_file;
5716 : :
5717 : : /* Nonzero means %T has been seen; the next arg to be terminated
5718 : : is the name of a linker script and we should try all of the
5719 : : standard search dirs for it. If it is found insert a --script
5720 : : command line switch and then substitute the full path in place,
5721 : : otherwise generate an error message. */
5722 : : static int this_is_linker_script;
5723 : :
5724 : : /* Nonzero means that the input of this command is coming from a pipe. */
5725 : : static int input_from_pipe;
5726 : :
5727 : : /* Nonnull means substitute this for any suffix when outputting a switches
5728 : : arguments. */
5729 : : static const char *suffix_subst;
5730 : :
5731 : : /* If there is an argument being accumulated, terminate it and store it. */
5732 : :
5733 : : static void
5734 : 81742595 : end_going_arg (void)
5735 : : {
5736 : 81742595 : if (arg_going)
5737 : : {
5738 : 20032694 : const char *string;
5739 : :
5740 : 20032694 : obstack_1grow (&obstack, 0);
5741 : 20032694 : string = XOBFINISH (&obstack, const char *);
5742 : 20032694 : if (this_is_library_file)
5743 : 542101 : string = find_file (string);
5744 : 20032694 : if (this_is_linker_script)
5745 : : {
5746 : 0 : char * full_script_path = find_a_file (&startfile_prefixes, string, R_OK, true);
5747 : :
5748 : 0 : if (full_script_path == NULL)
5749 : : {
5750 : 0 : error ("unable to locate default linker script %qs in the library search paths", string);
5751 : : /* Script was not found on search path. */
5752 : 0 : return;
5753 : : }
5754 : 0 : store_arg ("--script", false, false);
5755 : 0 : string = full_script_path;
5756 : : }
5757 : 20032694 : store_arg (string, delete_this_arg, this_is_output_file);
5758 : 20032694 : if (this_is_output_file)
5759 : 100578 : outfiles[input_file_number] = string;
5760 : 20032694 : arg_going = 0;
5761 : : }
5762 : : }
5763 : :
5764 : :
5765 : : /* Parse the WRAPPER string which is a comma separated list of the command line
5766 : : and insert them into the beginning of argbuf. */
5767 : :
5768 : : static void
5769 : 0 : insert_wrapper (const char *wrapper)
5770 : : {
5771 : 0 : int n = 0;
5772 : 0 : int i;
5773 : 0 : char *buf = xstrdup (wrapper);
5774 : 0 : char *p = buf;
5775 : 0 : unsigned int old_length = argbuf.length ();
5776 : :
5777 : 0 : do
5778 : : {
5779 : 0 : n++;
5780 : 0 : while (*p == ',')
5781 : 0 : p++;
5782 : : }
5783 : 0 : while ((p = strchr (p, ',')) != NULL);
5784 : :
5785 : 0 : argbuf.safe_grow (old_length + n, true);
5786 : 0 : memmove (argbuf.address () + n,
5787 : 0 : argbuf.address (),
5788 : 0 : old_length * sizeof (const_char_p));
5789 : :
5790 : 0 : i = 0;
5791 : 0 : p = buf;
5792 : : do
5793 : : {
5794 : 0 : while (*p == ',')
5795 : : {
5796 : 0 : *p = 0;
5797 : 0 : p++;
5798 : : }
5799 : 0 : argbuf[i] = p;
5800 : 0 : i++;
5801 : : }
5802 : 0 : while ((p = strchr (p, ',')) != NULL);
5803 : 0 : gcc_assert (i == n);
5804 : 0 : }
5805 : :
5806 : : /* Process the spec SPEC and run the commands specified therein.
5807 : : Returns 0 if the spec is successfully processed; -1 if failed. */
5808 : :
5809 : : int
5810 : 566883 : do_spec (const char *spec)
5811 : : {
5812 : 566883 : int value;
5813 : :
5814 : 566883 : value = do_spec_2 (spec, NULL);
5815 : :
5816 : : /* Force out any unfinished command.
5817 : : If -pipe, this forces out the last command if it ended in `|'. */
5818 : 566883 : if (value == 0)
5819 : : {
5820 : 561118 : if (argbuf.length () > 0
5821 : 842635 : && !strcmp (argbuf.last (), "|"))
5822 : 0 : argbuf.pop ();
5823 : :
5824 : 561118 : set_collect_gcc_options ();
5825 : :
5826 : 561118 : if (argbuf.length () > 0)
5827 : 281517 : value = execute ();
5828 : : }
5829 : :
5830 : 566883 : return value;
5831 : : }
5832 : :
5833 : : /* Process the spec SPEC, with SOFT_MATCHED_PART designating the current value
5834 : : of a matched * pattern which may be re-injected by way of %*. */
5835 : :
5836 : : static int
5837 : 5332689 : do_spec_2 (const char *spec, const char *soft_matched_part)
5838 : : {
5839 : 5332689 : int result;
5840 : :
5841 : 5332689 : clear_args ();
5842 : 5332689 : arg_going = 0;
5843 : 5332689 : delete_this_arg = 0;
5844 : 5332689 : this_is_output_file = 0;
5845 : 5332689 : this_is_library_file = 0;
5846 : 5332689 : this_is_linker_script = 0;
5847 : 5332689 : input_from_pipe = 0;
5848 : 5332689 : suffix_subst = NULL;
5849 : :
5850 : 5332689 : result = do_spec_1 (spec, 0, soft_matched_part);
5851 : :
5852 : 5332689 : end_going_arg ();
5853 : :
5854 : 5332689 : return result;
5855 : : }
5856 : :
5857 : : /* Process the given spec string and add any new options to the end
5858 : : of the switches/n_switches array. */
5859 : :
5860 : : static void
5861 : 2982810 : do_option_spec (const char *name, const char *spec)
5862 : : {
5863 : 2982810 : unsigned int i, value_count, value_len;
5864 : 2982810 : const char *p, *q, *value;
5865 : 2982810 : char *tmp_spec, *tmp_spec_p;
5866 : :
5867 : 2982810 : if (configure_default_options[0].name == NULL)
5868 : : return;
5869 : :
5870 : 8053587 : for (i = 0; i < ARRAY_SIZE (configure_default_options); i++)
5871 : 5667339 : if (strcmp (configure_default_options[i].name, name) == 0)
5872 : : break;
5873 : 2982810 : if (i == ARRAY_SIZE (configure_default_options))
5874 : : return;
5875 : :
5876 : 596562 : value = configure_default_options[i].value;
5877 : 596562 : value_len = strlen (value);
5878 : :
5879 : : /* Compute the size of the final spec. */
5880 : 596562 : value_count = 0;
5881 : 596562 : p = spec;
5882 : 1193124 : while ((p = strstr (p, "%(VALUE)")) != NULL)
5883 : : {
5884 : 596562 : p ++;
5885 : 596562 : value_count ++;
5886 : : }
5887 : :
5888 : : /* Replace each %(VALUE) by the specified value. */
5889 : 596562 : tmp_spec = (char *) alloca (strlen (spec) + 1
5890 : : + value_count * (value_len - strlen ("%(VALUE)")));
5891 : 596562 : tmp_spec_p = tmp_spec;
5892 : 596562 : q = spec;
5893 : 1193124 : while ((p = strstr (q, "%(VALUE)")) != NULL)
5894 : : {
5895 : 596562 : memcpy (tmp_spec_p, q, p - q);
5896 : 596562 : tmp_spec_p = tmp_spec_p + (p - q);
5897 : 596562 : memcpy (tmp_spec_p, value, value_len);
5898 : 596562 : tmp_spec_p += value_len;
5899 : 596562 : q = p + strlen ("%(VALUE)");
5900 : : }
5901 : 596562 : strcpy (tmp_spec_p, q);
5902 : :
5903 : 596562 : do_self_spec (tmp_spec);
5904 : : }
5905 : :
5906 : : /* Process the given spec string and add any new options to the end
5907 : : of the switches/n_switches array. */
5908 : :
5909 : : static void
5910 : 2684849 : do_self_spec (const char *spec)
5911 : : {
5912 : 2684849 : int i;
5913 : :
5914 : 2684849 : do_spec_2 (spec, NULL);
5915 : 2684849 : do_spec_1 (" ", 0, NULL);
5916 : :
5917 : : /* Mark %<S switches processed by do_self_spec to be ignored permanently.
5918 : : do_self_specs adds the replacements to switches array, so it shouldn't
5919 : : be processed afterwards. */
5920 : 65071166 : for (i = 0; i < n_switches; i++)
5921 : 59701468 : if ((switches[i].live_cond & SWITCH_IGNORE))
5922 : 667 : switches[i].live_cond |= SWITCH_IGNORE_PERMANENTLY;
5923 : :
5924 : 2684849 : if (argbuf.length () > 0)
5925 : : {
5926 : 562628 : const char **argbuf_copy;
5927 : 562628 : struct cl_decoded_option *decoded_options;
5928 : 562628 : struct cl_option_handlers handlers;
5929 : 562628 : unsigned int decoded_options_count;
5930 : 562628 : unsigned int j;
5931 : :
5932 : : /* Create a copy of argbuf with a dummy argv[0] entry for
5933 : : decode_cmdline_options_to_array. */
5934 : 562628 : argbuf_copy = XNEWVEC (const char *,
5935 : : argbuf.length () + 1);
5936 : 562628 : argbuf_copy[0] = "";
5937 : 562628 : memcpy (argbuf_copy + 1, argbuf.address (),
5938 : 562628 : argbuf.length () * sizeof (const char *));
5939 : :
5940 : 1125256 : decode_cmdline_options_to_array (argbuf.length () + 1,
5941 : : argbuf_copy,
5942 : : CL_DRIVER, &decoded_options,
5943 : : &decoded_options_count);
5944 : 562628 : free (argbuf_copy);
5945 : :
5946 : 562628 : set_option_handlers (&handlers);
5947 : :
5948 : 1127732 : for (j = 1; j < decoded_options_count; j++)
5949 : : {
5950 : 565104 : switch (decoded_options[j].opt_index)
5951 : : {
5952 : 0 : case OPT_SPECIAL_input_file:
5953 : : /* Specs should only generate options, not input
5954 : : files. */
5955 : 0 : if (strcmp (decoded_options[j].arg, "-") != 0)
5956 : 0 : fatal_error (input_location,
5957 : : "switch %qs does not start with %<-%>",
5958 : : decoded_options[j].arg);
5959 : : else
5960 : 0 : fatal_error (input_location,
5961 : : "spec-generated switch is just %<-%>");
5962 : 1238 : break;
5963 : :
5964 : 1238 : case OPT_fcompare_debug_second:
5965 : 1238 : case OPT_fcompare_debug:
5966 : 1238 : case OPT_fcompare_debug_:
5967 : 1238 : case OPT_o:
5968 : : /* Avoid duplicate processing of some options from
5969 : : compare-debug specs; just save them here. */
5970 : 1238 : save_switch (decoded_options[j].canonical_option[0],
5971 : 1238 : (decoded_options[j].canonical_option_num_elements
5972 : : - 1),
5973 : 1238 : &decoded_options[j].canonical_option[1], false, true);
5974 : 1238 : break;
5975 : :
5976 : 563866 : default:
5977 : 563866 : read_cmdline_option (&global_options, &global_options_set,
5978 : : decoded_options + j, UNKNOWN_LOCATION,
5979 : : CL_DRIVER, &handlers, global_dc);
5980 : 563866 : break;
5981 : : }
5982 : : }
5983 : :
5984 : 562628 : free (decoded_options);
5985 : :
5986 : 562628 : alloc_switch ();
5987 : 562628 : switches[n_switches].part1 = 0;
5988 : : }
5989 : 2684849 : }
5990 : :
5991 : : /* Callback for processing %D and %I specs. */
5992 : :
5993 : : struct spec_path {
5994 : : const char *option;
5995 : : const char *append;
5996 : : size_t append_len;
5997 : : bool omit_relative;
5998 : : bool separate_options;
5999 : : bool realpaths;
6000 : :
6001 : : void *operator() (char *path);
6002 : : };
6003 : :
6004 : : void *
6005 : 3357508 : spec_path::operator() (char *path)
6006 : : {
6007 : 3357508 : size_t len = 0;
6008 : 3357508 : char save = 0;
6009 : :
6010 : : /* The path must exist; we want to resolve it to the realpath so that this
6011 : : can be embedded as a runpath. */
6012 : 3357508 : if (realpaths)
6013 : 0 : path = lrealpath (path);
6014 : :
6015 : : /* However, if we failed to resolve it - perhaps because there was a bogus
6016 : : -B option on the command line, then punt on this entry. */
6017 : 3357508 : if (!path)
6018 : : return NULL;
6019 : :
6020 : 3357508 : if (omit_relative && !IS_ABSOLUTE_PATH (path))
6021 : : return NULL;
6022 : :
6023 : 3357508 : if (append_len != 0)
6024 : : {
6025 : 1396988 : len = strlen (path);
6026 : 1396988 : memcpy (path + len, append, append_len + 1);
6027 : : }
6028 : :
6029 : 3357508 : if (!is_directory (path))
6030 : : return NULL;
6031 : :
6032 : 1258693 : do_spec_1 (option, 1, NULL);
6033 : 1258693 : if (separate_options)
6034 : 448931 : do_spec_1 (" ", 0, NULL);
6035 : :
6036 : 1258693 : if (append_len == 0)
6037 : : {
6038 : 809762 : len = strlen (path);
6039 : 809762 : save = path[len - 1];
6040 : 809762 : if (IS_DIR_SEPARATOR (path[len - 1]))
6041 : 809762 : path[len - 1] = '\0';
6042 : : }
6043 : :
6044 : 1258693 : do_spec_1 (path, 1, NULL);
6045 : 1258693 : do_spec_1 (" ", 0, NULL);
6046 : :
6047 : : /* Must not damage the original path. */
6048 : 1258693 : if (append_len == 0)
6049 : 809762 : path[len - 1] = save;
6050 : :
6051 : : return NULL;
6052 : : }
6053 : :
6054 : : /* True if we should compile INFILE. */
6055 : :
6056 : : static bool
6057 : 45335 : compile_input_file_p (struct infile *infile)
6058 : : {
6059 : 28002 : if ((!infile->language) || (infile->language[0] != '*'))
6060 : 40747 : if (infile->incompiler == input_file_compiler)
6061 : 0 : return true;
6062 : : return false;
6063 : : }
6064 : :
6065 : : /* Process each member of VEC as a spec. */
6066 : :
6067 : : static void
6068 : 469307 : do_specs_vec (vec<char_p> vec)
6069 : : {
6070 : 469425 : for (char *opt : vec)
6071 : : {
6072 : 70 : do_spec_1 (opt, 1, NULL);
6073 : : /* Make each accumulated option a separate argument. */
6074 : 70 : do_spec_1 (" ", 0, NULL);
6075 : : }
6076 : 469307 : }
6077 : :
6078 : : /* Add options passed via -Xassembler or -Wa to COLLECT_AS_OPTIONS. */
6079 : :
6080 : : static void
6081 : 298149 : putenv_COLLECT_AS_OPTIONS (vec<char_p> vec)
6082 : : {
6083 : 298149 : if (vec.is_empty ())
6084 : 298149 : return;
6085 : :
6086 : 103 : obstack_init (&collect_obstack);
6087 : 103 : obstack_grow (&collect_obstack, "COLLECT_AS_OPTIONS=",
6088 : : strlen ("COLLECT_AS_OPTIONS="));
6089 : :
6090 : 103 : char *opt;
6091 : 103 : unsigned ix;
6092 : :
6093 : 298 : FOR_EACH_VEC_ELT (vec, ix, opt)
6094 : : {
6095 : 195 : obstack_1grow (&collect_obstack, '\'');
6096 : 195 : obstack_grow (&collect_obstack, opt, strlen (opt));
6097 : 195 : obstack_1grow (&collect_obstack, '\'');
6098 : 195 : if (ix < vec.length () - 1)
6099 : 92 : obstack_1grow(&collect_obstack, ' ');
6100 : : }
6101 : :
6102 : 103 : obstack_1grow (&collect_obstack, '\0');
6103 : 103 : xputenv (XOBFINISH (&collect_obstack, char *));
6104 : : }
6105 : :
6106 : : /* Process the sub-spec SPEC as a portion of a larger spec.
6107 : : This is like processing a whole spec except that we do
6108 : : not initialize at the beginning and we do not supply a
6109 : : newline by default at the end.
6110 : : INSWITCH nonzero means don't process %-sequences in SPEC;
6111 : : in this case, % is treated as an ordinary character.
6112 : : This is used while substituting switches.
6113 : : INSWITCH nonzero also causes SPC not to terminate an argument.
6114 : :
6115 : : Value is zero unless a line was finished
6116 : : and the command on that line reported an error. */
6117 : :
6118 : : static int
6119 : 52750337 : do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part)
6120 : : {
6121 : 52750337 : const char *p = spec;
6122 : 52750337 : int c;
6123 : 52750337 : int i;
6124 : 52750337 : int value;
6125 : :
6126 : : /* If it's an empty string argument to a switch, keep it as is. */
6127 : 52750337 : if (inswitch && !*p)
6128 : 1 : arg_going = 1;
6129 : :
6130 : 541043221 : while ((c = *p++))
6131 : : /* If substituting a switch, treat all chars like letters.
6132 : : Otherwise, NL, SPC, TAB and % are special. */
6133 : 488341394 : switch (inswitch ? 'a' : c)
6134 : : {
6135 : 265316 : case '\n':
6136 : 265316 : end_going_arg ();
6137 : :
6138 : 265316 : if (argbuf.length () > 0
6139 : 530632 : && !strcmp (argbuf.last (), "|"))
6140 : : {
6141 : : /* A `|' before the newline means use a pipe here,
6142 : : but only if -pipe was specified.
6143 : : Otherwise, execute now and don't pass the `|' as an arg. */
6144 : 168403 : if (use_pipes)
6145 : : {
6146 : 0 : input_from_pipe = 1;
6147 : 0 : break;
6148 : : }
6149 : : else
6150 : 168403 : argbuf.pop ();
6151 : : }
6152 : :
6153 : 265316 : set_collect_gcc_options ();
6154 : :
6155 : 265316 : if (argbuf.length () > 0)
6156 : : {
6157 : 265316 : value = execute ();
6158 : 265316 : if (value)
6159 : : return value;
6160 : : }
6161 : : /* Reinitialize for a new command, and for a new argument. */
6162 : 259551 : clear_args ();
6163 : 259551 : arg_going = 0;
6164 : 259551 : delete_this_arg = 0;
6165 : 259551 : this_is_output_file = 0;
6166 : 259551 : this_is_library_file = 0;
6167 : 259551 : this_is_linker_script = 0;
6168 : 259551 : input_from_pipe = 0;
6169 : 259551 : break;
6170 : :
6171 : 168403 : case '|':
6172 : 168403 : end_going_arg ();
6173 : :
6174 : : /* Use pipe */
6175 : 168403 : obstack_1grow (&obstack, c);
6176 : 168403 : arg_going = 1;
6177 : 168403 : break;
6178 : :
6179 : 71279964 : case '\t':
6180 : 71279964 : case ' ':
6181 : 71279964 : end_going_arg ();
6182 : :
6183 : : /* Reinitialize for a new argument. */
6184 : 71279964 : delete_this_arg = 0;
6185 : 71279964 : this_is_output_file = 0;
6186 : 71279964 : this_is_library_file = 0;
6187 : 71279964 : this_is_linker_script = 0;
6188 : 71279964 : break;
6189 : :
6190 : 49443273 : case '%':
6191 : 49443273 : switch (c = *p++)
6192 : : {
6193 : 0 : case 0:
6194 : 0 : fatal_error (input_location, "spec %qs invalid", spec);
6195 : :
6196 : 3596 : case 'b':
6197 : : /* Don't use %b in the linker command. */
6198 : 3596 : gcc_assert (suffixed_basename_length);
6199 : 3596 : if (!this_is_output_file && dumpdir_length)
6200 : 689 : obstack_grow (&obstack, dumpdir, dumpdir_length);
6201 : 3596 : if (this_is_output_file || !outbase_length)
6202 : 3254 : obstack_grow (&obstack, input_basename, basename_length);
6203 : : else
6204 : 342 : obstack_grow (&obstack, outbase, outbase_length);
6205 : 3596 : if (compare_debug < 0)
6206 : 6 : obstack_grow (&obstack, ".gk", 3);
6207 : 3596 : arg_going = 1;
6208 : 3596 : break;
6209 : :
6210 : 10 : case 'B':
6211 : : /* Don't use %B in the linker command. */
6212 : 10 : gcc_assert (suffixed_basename_length);
6213 : 10 : if (!this_is_output_file && dumpdir_length)
6214 : 0 : obstack_grow (&obstack, dumpdir, dumpdir_length);
6215 : 10 : if (this_is_output_file || !outbase_length)
6216 : 5 : obstack_grow (&obstack, input_basename, basename_length);
6217 : : else
6218 : 5 : obstack_grow (&obstack, outbase, outbase_length);
6219 : 10 : if (compare_debug < 0)
6220 : 3 : obstack_grow (&obstack, ".gk", 3);
6221 : 10 : obstack_grow (&obstack, input_basename + basename_length,
6222 : : suffixed_basename_length - basename_length);
6223 : :
6224 : 10 : arg_going = 1;
6225 : 10 : break;
6226 : :
6227 : 98064 : case 'd':
6228 : 98064 : delete_this_arg = 2;
6229 : 98064 : break;
6230 : :
6231 : : /* Dump out the directories specified with LIBRARY_PATH,
6232 : : followed by the absolute directories
6233 : : that we search for startfiles. */
6234 : 105891 : case 'D':
6235 : 105891 : {
6236 : 105891 : struct spec_path info;
6237 : :
6238 : 105891 : info.option = "-L";
6239 : 105891 : info.append_len = 0;
6240 : : #ifdef RELATIVE_PREFIX_NOT_LINKDIR
6241 : : /* Used on systems which record the specified -L dirs
6242 : : and use them to search for dynamic linking.
6243 : : Relative directories always come from -B,
6244 : : and it is better not to use them for searching
6245 : : at run time. In particular, stage1 loses. */
6246 : : info.omit_relative = true;
6247 : : #else
6248 : 105891 : info.omit_relative = false;
6249 : : #endif
6250 : 105891 : info.separate_options = false;
6251 : 105891 : info.realpaths = false;
6252 : :
6253 : 105891 : for_each_path (&startfile_prefixes, true, 0, info);
6254 : : }
6255 : 105891 : break;
6256 : :
6257 : 0 : case 'P':
6258 : 0 : {
6259 : 0 : struct spec_path info;
6260 : :
6261 : 0 : info.option = RUNPATH_OPTION;
6262 : 0 : info.append_len = 0;
6263 : 0 : info.omit_relative = false;
6264 : 0 : info.separate_options = true;
6265 : : /* We want to embed the actual paths that have the libraries. */
6266 : 0 : info.realpaths = true;
6267 : :
6268 : 0 : for_each_path (&startfile_prefixes, true, 0, info);
6269 : : }
6270 : 0 : break;
6271 : :
6272 : : case 'e':
6273 : : /* %efoo means report an error with `foo' as error message
6274 : : and don't execute any more commands for this file. */
6275 : : {
6276 : : const char *q = p;
6277 : : char *buf;
6278 : 0 : while (*p != 0 && *p != '\n')
6279 : 0 : p++;
6280 : 0 : buf = (char *) alloca (p - q + 1);
6281 : 0 : strncpy (buf, q, p - q);
6282 : 0 : buf[p - q] = 0;
6283 : 0 : error ("%s", _(buf));
6284 : 0 : return -1;
6285 : : }
6286 : : break;
6287 : : case 'n':
6288 : : /* %nfoo means report a notice with `foo' on stderr. */
6289 : : {
6290 : : const char *q = p;
6291 : : char *buf;
6292 : 0 : while (*p != 0 && *p != '\n')
6293 : 0 : p++;
6294 : 0 : buf = (char *) alloca (p - q + 1);
6295 : 0 : strncpy (buf, q, p - q);
6296 : 0 : buf[p - q] = 0;
6297 : 0 : inform (UNKNOWN_LOCATION, "%s", _(buf));
6298 : 0 : if (*p)
6299 : 0 : p++;
6300 : : }
6301 : : break;
6302 : :
6303 : 882 : case 'j':
6304 : 882 : {
6305 : 882 : struct stat st;
6306 : :
6307 : : /* If save_temps_flag is off, and the HOST_BIT_BUCKET is
6308 : : defined, and it is not a directory, and it is
6309 : : writable, use it. Otherwise, treat this like any
6310 : : other temporary file. */
6311 : :
6312 : 882 : if ((!save_temps_flag)
6313 : 882 : && (stat (HOST_BIT_BUCKET, &st) == 0) && (!S_ISDIR (st.st_mode))
6314 : 1764 : && (access (HOST_BIT_BUCKET, W_OK) == 0))
6315 : : {
6316 : 882 : obstack_grow (&obstack, HOST_BIT_BUCKET,
6317 : : strlen (HOST_BIT_BUCKET));
6318 : 882 : delete_this_arg = 0;
6319 : 882 : arg_going = 1;
6320 : 882 : break;
6321 : : }
6322 : : }
6323 : 0 : goto create_temp_file;
6324 : 168403 : case '|':
6325 : 168403 : if (use_pipes)
6326 : : {
6327 : 0 : obstack_1grow (&obstack, '-');
6328 : 0 : delete_this_arg = 0;
6329 : 0 : arg_going = 1;
6330 : :
6331 : : /* consume suffix */
6332 : 0 : while (*p == '.' || ISALNUM ((unsigned char) *p))
6333 : 0 : p++;
6334 : 0 : if (p[0] == '%' && p[1] == 'O')
6335 : 0 : p += 2;
6336 : :
6337 : : break;
6338 : : }
6339 : 168403 : goto create_temp_file;
6340 : 162784 : case 'm':
6341 : 162784 : if (use_pipes)
6342 : : {
6343 : : /* consume suffix */
6344 : 0 : while (*p == '.' || ISALNUM ((unsigned char) *p))
6345 : 0 : p++;
6346 : 0 : if (p[0] == '%' && p[1] == 'O')
6347 : 0 : p += 2;
6348 : :
6349 : : break;
6350 : : }
6351 : 162784 : goto create_temp_file;
6352 : 522911 : case 'g':
6353 : 522911 : case 'u':
6354 : 522911 : case 'U':
6355 : 522911 : create_temp_file:
6356 : 522911 : {
6357 : 522911 : struct temp_name *t;
6358 : 522911 : int suffix_length;
6359 : 522911 : const char *suffix = p;
6360 : 522911 : char *saved_suffix = NULL;
6361 : :
6362 : 1558021 : while (*p == '.' || ISALNUM ((unsigned char) *p))
6363 : 1035110 : p++;
6364 : 522911 : suffix_length = p - suffix;
6365 : 522911 : if (p[0] == '%' && p[1] == 'O')
6366 : : {
6367 : 98280 : p += 2;
6368 : : /* We don't support extra suffix characters after %O. */
6369 : 98280 : if (*p == '.' || ISALNUM ((unsigned char) *p))
6370 : 0 : fatal_error (input_location,
6371 : : "spec %qs has invalid %<%%0%c%>", spec, *p);
6372 : 98280 : if (suffix_length == 0)
6373 : : suffix = TARGET_OBJECT_SUFFIX;
6374 : : else
6375 : : {
6376 : 0 : saved_suffix
6377 : 0 : = XNEWVEC (char, suffix_length
6378 : : + strlen (TARGET_OBJECT_SUFFIX) + 1);
6379 : 0 : strncpy (saved_suffix, suffix, suffix_length);
6380 : 0 : strcpy (saved_suffix + suffix_length,
6381 : : TARGET_OBJECT_SUFFIX);
6382 : : }
6383 : 98280 : suffix_length += strlen (TARGET_OBJECT_SUFFIX);
6384 : : }
6385 : :
6386 : 522911 : if (compare_debug < 0)
6387 : : {
6388 : 610 : suffix = concat (".gk", suffix, NULL);
6389 : 610 : suffix_length += 3;
6390 : : }
6391 : :
6392 : : /* If -save-temps was specified, use that for the
6393 : : temp file. */
6394 : 522911 : if (save_temps_flag)
6395 : : {
6396 : 1194 : char *tmp;
6397 : 1194 : bool adjusted_suffix = false;
6398 : 1194 : if (suffix_length
6399 : 1194 : && !outbase_length && !basename_length
6400 : 224 : && !dumpdir_trailing_dash_added)
6401 : : {
6402 : 20 : adjusted_suffix = true;
6403 : 20 : suffix++;
6404 : 20 : suffix_length--;
6405 : : }
6406 : 1194 : temp_filename_length
6407 : 1194 : = dumpdir_length + suffix_length + 1;
6408 : 1194 : if (outbase_length)
6409 : 72 : temp_filename_length += outbase_length;
6410 : : else
6411 : 1122 : temp_filename_length += basename_length;
6412 : 1194 : tmp = (char *) alloca (temp_filename_length);
6413 : 1194 : if (dumpdir_length)
6414 : 1036 : memcpy (tmp, dumpdir, dumpdir_length);
6415 : 1194 : if (outbase_length)
6416 : 72 : memcpy (tmp + dumpdir_length, outbase,
6417 : : outbase_length);
6418 : 1122 : else if (basename_length)
6419 : 898 : memcpy (tmp + dumpdir_length, input_basename,
6420 : : basename_length);
6421 : 1194 : memcpy (tmp + temp_filename_length - suffix_length - 1,
6422 : : suffix, suffix_length);
6423 : 1194 : if (adjusted_suffix)
6424 : : {
6425 : 20 : adjusted_suffix = false;
6426 : 20 : suffix--;
6427 : 20 : suffix_length++;
6428 : : }
6429 : 1194 : tmp[temp_filename_length - 1] = '\0';
6430 : 1194 : temp_filename = tmp;
6431 : :
6432 : 1194 : if (filename_cmp (temp_filename, gcc_input_filename) != 0)
6433 : : {
6434 : : #ifndef HOST_LACKS_INODE_NUMBERS
6435 : 1194 : struct stat st_temp;
6436 : :
6437 : : /* Note, set_input() resets input_stat_set to 0. */
6438 : 1194 : if (input_stat_set == 0)
6439 : : {
6440 : 557 : input_stat_set = stat (gcc_input_filename,
6441 : : &input_stat);
6442 : 557 : if (input_stat_set >= 0)
6443 : 557 : input_stat_set = 1;
6444 : : }
6445 : :
6446 : : /* If we have the stat for the gcc_input_filename
6447 : : and we can do the stat for the temp_filename
6448 : : then the they could still refer to the same
6449 : : file if st_dev/st_ino's are the same. */
6450 : 1194 : if (input_stat_set != 1
6451 : 1194 : || stat (temp_filename, &st_temp) < 0
6452 : 365 : || input_stat.st_dev != st_temp.st_dev
6453 : 1208 : || input_stat.st_ino != st_temp.st_ino)
6454 : : #else
6455 : : /* Just compare canonical pathnames. */
6456 : : char* input_realname = lrealpath (gcc_input_filename);
6457 : : char* temp_realname = lrealpath (temp_filename);
6458 : : bool files_differ = filename_cmp (input_realname, temp_realname);
6459 : : free (input_realname);
6460 : : free (temp_realname);
6461 : : if (files_differ)
6462 : : #endif
6463 : : {
6464 : 1194 : temp_filename
6465 : 1194 : = save_string (temp_filename,
6466 : : temp_filename_length - 1);
6467 : 1194 : obstack_grow (&obstack, temp_filename,
6468 : : temp_filename_length);
6469 : 1194 : arg_going = 1;
6470 : 1194 : delete_this_arg = 0;
6471 : 1194 : break;
6472 : : }
6473 : : }
6474 : : }
6475 : :
6476 : : /* See if we already have an association of %g/%u/%U and
6477 : : suffix. */
6478 : 893295 : for (t = temp_names; t; t = t->next)
6479 : 541362 : if (t->length == suffix_length
6480 : 362019 : && strncmp (t->suffix, suffix, suffix_length) == 0
6481 : 173727 : && t->unique == (c == 'u' || c == 'U' || c == 'j'))
6482 : : break;
6483 : :
6484 : : /* Make a new association if needed. %u and %j
6485 : : require one. */
6486 : 521717 : if (t == 0 || c == 'u' || c == 'j')
6487 : : {
6488 : 355682 : if (t == 0)
6489 : : {
6490 : 351933 : t = XNEW (struct temp_name);
6491 : 351933 : t->next = temp_names;
6492 : 351933 : temp_names = t;
6493 : : }
6494 : 355682 : t->length = suffix_length;
6495 : 355682 : if (saved_suffix)
6496 : : {
6497 : 0 : t->suffix = saved_suffix;
6498 : 0 : saved_suffix = NULL;
6499 : : }
6500 : : else
6501 : 355682 : t->suffix = save_string (suffix, suffix_length);
6502 : 355682 : t->unique = (c == 'u' || c == 'U' || c == 'j');
6503 : 355682 : temp_filename = make_temp_file (t->suffix);
6504 : 355682 : temp_filename_length = strlen (temp_filename);
6505 : 355682 : t->filename = temp_filename;
6506 : 355682 : t->filename_length = temp_filename_length;
6507 : : }
6508 : :
6509 : 521717 : free (saved_suffix);
6510 : :
6511 : 521717 : obstack_grow (&obstack, t->filename, t->filename_length);
6512 : 521717 : delete_this_arg = 1;
6513 : : }
6514 : 521717 : arg_going = 1;
6515 : 521717 : break;
6516 : :
6517 : 288813 : case 'i':
6518 : 288813 : if (combine_inputs)
6519 : : {
6520 : : /* We are going to expand `%i' into `@FILE', where FILE
6521 : : is a newly-created temporary filename. The filenames
6522 : : that would usually be expanded in place of %o will be
6523 : : written to the temporary file. */
6524 : 31584 : if (at_file_supplied)
6525 : 13245 : open_at_file ();
6526 : :
6527 : 76919 : for (i = 0; (int) i < n_infiles; i++)
6528 : 90670 : if (compile_input_file_p (&infiles[i]))
6529 : : {
6530 : 40685 : store_arg (infiles[i].name, 0, 0);
6531 : 40685 : infiles[i].compiled = true;
6532 : : }
6533 : :
6534 : 31584 : if (at_file_supplied)
6535 : 13245 : close_at_file ();
6536 : : }
6537 : : else
6538 : : {
6539 : 257229 : obstack_grow (&obstack, gcc_input_filename,
6540 : : input_filename_length);
6541 : 257229 : arg_going = 1;
6542 : : }
6543 : : break;
6544 : :
6545 : 223282 : case 'I':
6546 : 223282 : {
6547 : 223282 : struct spec_path info;
6548 : :
6549 : 223282 : if (multilib_dir)
6550 : : {
6551 : 5992 : do_spec_1 ("-imultilib", 1, NULL);
6552 : : /* Make this a separate argument. */
6553 : 5992 : do_spec_1 (" ", 0, NULL);
6554 : 5992 : do_spec_1 (multilib_dir, 1, NULL);
6555 : 5992 : do_spec_1 (" ", 0, NULL);
6556 : : }
6557 : :
6558 : 223282 : if (multiarch_dir)
6559 : : {
6560 : 0 : do_spec_1 ("-imultiarch", 1, NULL);
6561 : : /* Make this a separate argument. */
6562 : 0 : do_spec_1 (" ", 0, NULL);
6563 : 0 : do_spec_1 (multiarch_dir, 1, NULL);
6564 : 0 : do_spec_1 (" ", 0, NULL);
6565 : : }
6566 : :
6567 : 223282 : if (gcc_exec_prefix)
6568 : : {
6569 : 223282 : do_spec_1 ("-iprefix", 1, NULL);
6570 : : /* Make this a separate argument. */
6571 : 223282 : do_spec_1 (" ", 0, NULL);
6572 : 223282 : do_spec_1 (gcc_exec_prefix, 1, NULL);
6573 : 223282 : do_spec_1 (" ", 0, NULL);
6574 : : }
6575 : :
6576 : 223282 : if (target_system_root_changed ||
6577 : 223282 : (target_system_root && target_sysroot_hdrs_suffix))
6578 : : {
6579 : 0 : do_spec_1 ("-isysroot", 1, NULL);
6580 : : /* Make this a separate argument. */
6581 : 0 : do_spec_1 (" ", 0, NULL);
6582 : 0 : do_spec_1 (target_system_root, 1, NULL);
6583 : 0 : if (target_sysroot_hdrs_suffix)
6584 : 0 : do_spec_1 (target_sysroot_hdrs_suffix, 1, NULL);
6585 : 0 : do_spec_1 (" ", 0, NULL);
6586 : : }
6587 : :
6588 : 223282 : info.option = "-isystem";
6589 : 223282 : info.append = "include";
6590 : 223282 : info.append_len = strlen (info.append);
6591 : 223282 : info.omit_relative = false;
6592 : 223282 : info.separate_options = true;
6593 : 223282 : info.realpaths = false;
6594 : :
6595 : 223282 : for_each_path (&include_prefixes, false, info.append_len, info);
6596 : :
6597 : 223282 : info.append = "include-fixed";
6598 : 223282 : if (*sysroot_hdrs_suffix_spec)
6599 : 0 : info.append = concat (info.append, dir_separator_str,
6600 : : multilib_dir, NULL);
6601 : 223282 : else if (multiarch_dir)
6602 : : {
6603 : : /* For multiarch, search include-fixed/<multiarch-dir>
6604 : : before include-fixed. */
6605 : 0 : info.append = concat (info.append, dir_separator_str,
6606 : : multiarch_dir, NULL);
6607 : 0 : info.append_len = strlen (info.append);
6608 : 0 : for_each_path (&include_prefixes, false,
6609 : : info.append_len, info);
6610 : :
6611 : 0 : info.append = "include-fixed";
6612 : : }
6613 : 223282 : info.append_len = strlen (info.append);
6614 : 223282 : for_each_path (&include_prefixes, false, info.append_len, info);
6615 : : }
6616 : 223282 : break;
6617 : :
6618 : 96076 : case 'o':
6619 : : /* We are going to expand `%o' into `@FILE', where FILE
6620 : : is a newly-created temporary filename. The filenames
6621 : : that would usually be expanded in place of %o will be
6622 : : written to the temporary file. */
6623 : 96076 : if (at_file_supplied)
6624 : 6 : open_at_file ();
6625 : :
6626 : 426261 : for (i = 0; i < n_infiles + lang_specific_extra_outfiles; i++)
6627 : 330185 : if (outfiles[i])
6628 : 330145 : store_arg (outfiles[i], 0, 0);
6629 : :
6630 : 96076 : if (at_file_supplied)
6631 : 6 : close_at_file ();
6632 : : break;
6633 : :
6634 : 3930 : case 'O':
6635 : 3930 : obstack_grow (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX));
6636 : 3930 : arg_going = 1;
6637 : 3930 : break;
6638 : :
6639 : 542105 : case 's':
6640 : 542105 : this_is_library_file = 1;
6641 : 542105 : break;
6642 : :
6643 : 0 : case 'T':
6644 : 0 : this_is_linker_script = 1;
6645 : 0 : break;
6646 : :
6647 : 452 : case 'V':
6648 : 452 : outfiles[input_file_number] = NULL;
6649 : 452 : break;
6650 : :
6651 : 101037 : case 'w':
6652 : 101037 : this_is_output_file = 1;
6653 : 101037 : break;
6654 : :
6655 : 174379 : case 'W':
6656 : 174379 : {
6657 : 174379 : unsigned int cur_index = argbuf.length ();
6658 : : /* Handle the {...} following the %W. */
6659 : 174379 : if (*p != '{')
6660 : 0 : fatal_error (input_location,
6661 : : "spec %qs has invalid %<%%W%c%>", spec, *p);
6662 : 174379 : p = handle_braces (p + 1);
6663 : 174379 : if (p == 0)
6664 : : return -1;
6665 : 174379 : end_going_arg ();
6666 : : /* If any args were output, mark the last one for deletion
6667 : : on failure. */
6668 : 348758 : if (argbuf.length () != cur_index)
6669 : 171204 : record_temp_file (argbuf.last (), 0, 1);
6670 : : break;
6671 : : }
6672 : :
6673 : 304656 : case '@':
6674 : : /* Handle the {...} following the %@. */
6675 : 304656 : if (*p != '{')
6676 : 0 : fatal_error (input_location,
6677 : : "spec %qs has invalid %<%%@%c%>", spec, *p);
6678 : 304656 : if (at_file_supplied)
6679 : 15 : open_at_file ();
6680 : 304656 : p = handle_braces (p + 1);
6681 : 304656 : if (at_file_supplied)
6682 : 15 : close_at_file ();
6683 : 304656 : if (p == 0)
6684 : : return -1;
6685 : : break;
6686 : :
6687 : : /* %x{OPTION} records OPTION for %X to output. */
6688 : 0 : case 'x':
6689 : 0 : {
6690 : 0 : const char *p1 = p;
6691 : 0 : char *string;
6692 : :
6693 : : /* Skip past the option value and make a copy. */
6694 : 0 : if (*p != '{')
6695 : 0 : fatal_error (input_location,
6696 : : "spec %qs has invalid %<%%x%c%>", spec, *p);
6697 : 0 : while (*p++ != '}')
6698 : : ;
6699 : 0 : string = save_string (p1 + 1, p - p1 - 2);
6700 : :
6701 : : /* See if we already recorded this option. */
6702 : 0 : for (const char *opt : linker_options)
6703 : 0 : if (! strcmp (string, opt))
6704 : : {
6705 : 0 : free (string);
6706 : 0 : return 0;
6707 : : }
6708 : :
6709 : : /* This option is new; add it. */
6710 : 0 : add_linker_option (string, strlen (string));
6711 : 0 : free (string);
6712 : : }
6713 : 0 : break;
6714 : :
6715 : : /* Dump out the options accumulated previously using %x. */
6716 : 96076 : case 'X':
6717 : 96076 : do_specs_vec (linker_options);
6718 : 96076 : break;
6719 : :
6720 : : /* Dump out the options accumulated previously using -Wa,. */
6721 : 164651 : case 'Y':
6722 : 164651 : do_specs_vec (assembler_options);
6723 : 164651 : break;
6724 : :
6725 : : /* Dump out the options accumulated previously using -Wp,. */
6726 : 208580 : case 'Z':
6727 : 208580 : do_specs_vec (preprocessor_options);
6728 : 208580 : break;
6729 : :
6730 : : /* Here are digits and numbers that just process
6731 : : a certain constant string as a spec. */
6732 : :
6733 : 285740 : case '1':
6734 : 285740 : value = do_spec_1 (cc1_spec, 0, NULL);
6735 : 285740 : if (value != 0)
6736 : : return value;
6737 : : break;
6738 : :
6739 : 96720 : case '2':
6740 : 96720 : value = do_spec_1 (cc1plus_spec, 0, NULL);
6741 : 96720 : if (value != 0)
6742 : : return value;
6743 : : break;
6744 : :
6745 : 164651 : case 'a':
6746 : 164651 : value = do_spec_1 (asm_spec, 0, NULL);
6747 : 164651 : if (value != 0)
6748 : : return value;
6749 : : break;
6750 : :
6751 : 164651 : case 'A':
6752 : 164651 : value = do_spec_1 (asm_final_spec, 0, NULL);
6753 : 164651 : if (value != 0)
6754 : : return value;
6755 : : break;
6756 : :
6757 : 208580 : case 'C':
6758 : 208580 : {
6759 : 111986 : const char *const spec
6760 : 208580 : = (input_file_compiler->cpp_spec
6761 : 208580 : ? input_file_compiler->cpp_spec
6762 : : : cpp_spec);
6763 : 208580 : value = do_spec_1 (spec, 0, NULL);
6764 : 208580 : if (value != 0)
6765 : : return value;
6766 : : }
6767 : : break;
6768 : :
6769 : 95870 : case 'E':
6770 : 95870 : value = do_spec_1 (endfile_spec, 0, NULL);
6771 : 95870 : if (value != 0)
6772 : : return value;
6773 : : break;
6774 : :
6775 : 96076 : case 'l':
6776 : 96076 : value = do_spec_1 (link_spec, 0, NULL);
6777 : 96076 : if (value != 0)
6778 : : return value;
6779 : : break;
6780 : :
6781 : 186292 : case 'L':
6782 : 186292 : value = do_spec_1 (lib_spec, 0, NULL);
6783 : 186292 : if (value != 0)
6784 : : return value;
6785 : : break;
6786 : :
6787 : 0 : case 'M':
6788 : 0 : if (multilib_os_dir == NULL)
6789 : 0 : obstack_1grow (&obstack, '.');
6790 : : else
6791 : 0 : obstack_grow (&obstack, multilib_os_dir,
6792 : : strlen (multilib_os_dir));
6793 : : break;
6794 : :
6795 : 372390 : case 'G':
6796 : 372390 : value = do_spec_1 (libgcc_spec, 0, NULL);
6797 : 372390 : if (value != 0)
6798 : : return value;
6799 : : break;
6800 : :
6801 : 0 : case 'R':
6802 : : /* We assume there is a directory
6803 : : separator at the end of this string. */
6804 : 0 : if (target_system_root)
6805 : : {
6806 : 0 : obstack_grow (&obstack, target_system_root,
6807 : : strlen (target_system_root));
6808 : 0 : if (target_sysroot_suffix)
6809 : 0 : obstack_grow (&obstack, target_sysroot_suffix,
6810 : : strlen (target_sysroot_suffix));
6811 : : }
6812 : : break;
6813 : :
6814 : 95870 : case 'S':
6815 : 95870 : value = do_spec_1 (startfile_spec, 0, NULL);
6816 : 95870 : if (value != 0)
6817 : : return value;
6818 : : break;
6819 : :
6820 : : /* Here we define characters other than letters and digits. */
6821 : :
6822 : 40245509 : case '{':
6823 : 40245509 : p = handle_braces (p);
6824 : 40245509 : if (p == 0)
6825 : : return -1;
6826 : : break;
6827 : :
6828 : 439314 : case ':':
6829 : 439314 : p = handle_spec_function (p, NULL, soft_matched_part);
6830 : 439314 : if (p == 0)
6831 : : return -1;
6832 : : break;
6833 : :
6834 : 0 : case '%':
6835 : 0 : obstack_1grow (&obstack, '%');
6836 : 0 : break;
6837 : :
6838 : : case '.':
6839 : : {
6840 : : unsigned len = 0;
6841 : :
6842 : 11794 : while (p[len] && p[len] != ' ' && p[len] != '%')
6843 : 5915 : len++;
6844 : 5879 : suffix_subst = save_string (p - 1, len + 1);
6845 : 5879 : p += len;
6846 : : }
6847 : 5879 : break;
6848 : :
6849 : : /* Henceforth ignore the option(s) matching the pattern
6850 : : after the %<. */
6851 : 1467928 : case '<':
6852 : 1467928 : case '>':
6853 : 1467928 : {
6854 : 1467928 : unsigned len = 0;
6855 : 1467928 : int have_wildcard = 0;
6856 : 1467928 : int i;
6857 : 1467928 : int switch_option;
6858 : :
6859 : 1467928 : if (c == '>')
6860 : 1467928 : switch_option = SWITCH_IGNORE | SWITCH_KEEP_FOR_GCC;
6861 : : else
6862 : 1467906 : switch_option = SWITCH_IGNORE;
6863 : :
6864 : 17713183 : while (p[len] && p[len] != ' ' && p[len] != '\t')
6865 : 16245255 : len++;
6866 : :
6867 : 1467928 : if (p[len-1] == '*')
6868 : 15635 : have_wildcard = 1;
6869 : :
6870 : 35079756 : for (i = 0; i < n_switches; i++)
6871 : 33611828 : if (!strncmp (switches[i].part1, p, len - have_wildcard)
6872 : 49589 : && (have_wildcard || switches[i].part1[len] == '\0'))
6873 : : {
6874 : 49320 : switches[i].live_cond |= switch_option;
6875 : : /* User switch be validated from validate_all_switches.
6876 : : when the definition is seen from the spec file.
6877 : : If not defined anywhere, will be rejected. */
6878 : 49320 : if (switches[i].known)
6879 : 49320 : switches[i].validated = true;
6880 : : }
6881 : :
6882 : : p += len;
6883 : : }
6884 : : break;
6885 : :
6886 : 6801 : case '*':
6887 : 6801 : if (soft_matched_part)
6888 : : {
6889 : 6801 : if (soft_matched_part[0])
6890 : 357 : do_spec_1 (soft_matched_part, 1, NULL);
6891 : : /* Only insert a space after the substitution if it is at the
6892 : : end of the current sequence. So if:
6893 : :
6894 : : "%{foo=*:bar%*}%{foo=*:one%*two}"
6895 : :
6896 : : matches -foo=hello then it will produce:
6897 : :
6898 : : barhello onehellotwo
6899 : : */
6900 : 6801 : if (*p == 0 || *p == '}')
6901 : 6801 : do_spec_1 (" ", 0, NULL);
6902 : : }
6903 : : else
6904 : : /* Catch the case where a spec string contains something like
6905 : : '%{foo:%*}'. i.e. there is no * in the pattern on the left
6906 : : hand side of the :. */
6907 : 0 : error ("spec failure: %<%%*%> has not been initialized by pattern match");
6908 : : break;
6909 : :
6910 : : /* Process a string found as the value of a spec given by name.
6911 : : This feature allows individual machine descriptions
6912 : : to add and use their own specs. */
6913 : : case '(':
6914 : : {
6915 : 33410138 : const char *name = p;
6916 : : struct spec_list *sl;
6917 : : int len;
6918 : :
6919 : : /* The string after the S/P is the name of a spec that is to be
6920 : : processed. */
6921 : 33410138 : while (*p && *p != ')')
6922 : 30834536 : p++;
6923 : :
6924 : : /* See if it's in the list. */
6925 : 35391363 : for (len = p - name, sl = specs; sl; sl = sl->next)
6926 : 35391363 : if (sl->name_len == len && !strncmp (sl->name, name, len))
6927 : : {
6928 : 2575602 : name = *(sl->ptr_spec);
6929 : : #ifdef DEBUG_SPECS
6930 : : fnotice (stderr, "Processing spec (%s), which is '%s'\n",
6931 : : sl->name, name);
6932 : : #endif
6933 : 2575602 : break;
6934 : : }
6935 : :
6936 : 2575602 : if (sl)
6937 : : {
6938 : 2575602 : value = do_spec_1 (name, 0, NULL);
6939 : 2575602 : if (value != 0)
6940 : : return value;
6941 : : }
6942 : :
6943 : : /* Discard the closing paren. */
6944 : 2569983 : if (*p)
6945 : 2569983 : p++;
6946 : : }
6947 : : break;
6948 : :
6949 : 9 : case '"':
6950 : : /* End a previous argument, if there is one, then issue an
6951 : : empty argument. */
6952 : 9 : end_going_arg ();
6953 : 9 : arg_going = 1;
6954 : 9 : end_going_arg ();
6955 : 9 : break;
6956 : :
6957 : 0 : default:
6958 : 0 : error ("spec failure: unrecognized spec option %qc", c);
6959 : 0 : break;
6960 : : }
6961 : : break;
6962 : :
6963 : 0 : case '\\':
6964 : : /* Backslash: treat next character as ordinary. */
6965 : 0 : c = *p++;
6966 : :
6967 : : /* When adding more cases that previously matched default, make
6968 : : sure to adjust quote_spec_char_p as well. */
6969 : :
6970 : : /* Fall through. */
6971 : 367184438 : default:
6972 : : /* Ordinary character: put it into the current argument. */
6973 : 367184438 : obstack_1grow (&obstack, c);
6974 : 367184438 : arg_going = 1;
6975 : : }
6976 : :
6977 : : /* End of string. If we are processing a spec function, we need to
6978 : : end any pending argument. */
6979 : 52701827 : if (processing_spec_function)
6980 : 4521826 : end_going_arg ();
6981 : :
6982 : : return 0;
6983 : : }
6984 : :
6985 : : /* Look up a spec function. */
6986 : :
6987 : : static const struct spec_function *
6988 : 2078491 : lookup_spec_function (const char *name)
6989 : : {
6990 : 2078491 : const struct spec_function *sf;
6991 : :
6992 : 24862247 : for (sf = static_spec_functions; sf->name != NULL; sf++)
6993 : 24862247 : if (strcmp (sf->name, name) == 0)
6994 : : return sf;
6995 : :
6996 : : return NULL;
6997 : : }
6998 : :
6999 : : /* Evaluate a spec function. */
7000 : :
7001 : : static const char *
7002 : 2078491 : eval_spec_function (const char *func, const char *args,
7003 : : const char *soft_matched_part)
7004 : : {
7005 : 2078491 : const struct spec_function *sf;
7006 : 2078491 : const char *funcval;
7007 : :
7008 : : /* Saved spec processing context. */
7009 : 2078491 : vec<const_char_p> save_argbuf;
7010 : :
7011 : 2078491 : int save_arg_going;
7012 : 2078491 : int save_delete_this_arg;
7013 : 2078491 : int save_this_is_output_file;
7014 : 2078491 : int save_this_is_library_file;
7015 : 2078491 : int save_input_from_pipe;
7016 : 2078491 : int save_this_is_linker_script;
7017 : 2078491 : const char *save_suffix_subst;
7018 : :
7019 : 2078491 : int save_growing_size;
7020 : 2078491 : void *save_growing_value = NULL;
7021 : :
7022 : 2078491 : sf = lookup_spec_function (func);
7023 : 2078491 : if (sf == NULL)
7024 : 0 : fatal_error (input_location, "unknown spec function %qs", func);
7025 : :
7026 : : /* Push the spec processing context. */
7027 : 2078491 : save_argbuf = argbuf;
7028 : :
7029 : 2078491 : save_arg_going = arg_going;
7030 : 2078491 : save_delete_this_arg = delete_this_arg;
7031 : 2078491 : save_this_is_output_file = this_is_output_file;
7032 : 2078491 : save_this_is_library_file = this_is_library_file;
7033 : 2078491 : save_this_is_linker_script = this_is_linker_script;
7034 : 2078491 : save_input_from_pipe = input_from_pipe;
7035 : 2078491 : save_suffix_subst = suffix_subst;
7036 : :
7037 : : /* If we have some object growing now, finalize it so the args and function
7038 : : eval proceed from a cleared context. This is needed to prevent the first
7039 : : constructed arg from mistakenly including the growing value. We'll push
7040 : : this value back on the obstack once the function evaluation is done, to
7041 : : restore a consistent processing context for our caller. This is fine as
7042 : : the address of growing objects isn't guaranteed to remain stable until
7043 : : they are finalized, and we expect this situation to be rare enough for
7044 : : the extra copy not to be an issue. */
7045 : 2078491 : save_growing_size = obstack_object_size (&obstack);
7046 : 2078491 : if (save_growing_size > 0)
7047 : 42608 : save_growing_value = obstack_finish (&obstack);
7048 : :
7049 : : /* Create a new spec processing context, and build the function
7050 : : arguments. */
7051 : :
7052 : 2078491 : alloc_args ();
7053 : 2078491 : if (do_spec_2 (args, soft_matched_part) < 0)
7054 : 0 : fatal_error (input_location, "error in arguments to spec function %qs",
7055 : : func);
7056 : :
7057 : : /* argbuf_index is an index for the next argument to be inserted, and
7058 : : so contains the count of the args already inserted. */
7059 : :
7060 : 6235473 : funcval = (*sf->func) (argbuf.length (),
7061 : : argbuf.address ());
7062 : :
7063 : : /* Pop the spec processing context. */
7064 : 2078491 : argbuf.release ();
7065 : 2078491 : argbuf = save_argbuf;
7066 : :
7067 : 2078491 : arg_going = save_arg_going;
7068 : 2078491 : delete_this_arg = save_delete_this_arg;
7069 : 2078491 : this_is_output_file = save_this_is_output_file;
7070 : 2078491 : this_is_library_file = save_this_is_library_file;
7071 : 2078491 : this_is_linker_script = save_this_is_linker_script;
7072 : 2078491 : input_from_pipe = save_input_from_pipe;
7073 : 2078491 : suffix_subst = save_suffix_subst;
7074 : :
7075 : 2078491 : if (save_growing_size > 0)
7076 : 42608 : obstack_grow (&obstack, save_growing_value, save_growing_size);
7077 : :
7078 : 2078491 : return funcval;
7079 : : }
7080 : :
7081 : : /* Handle a spec function call of the form:
7082 : :
7083 : : %:function(args)
7084 : :
7085 : : ARGS is processed as a spec in a separate context and split into an
7086 : : argument vector in the normal fashion. The function returns a string
7087 : : containing a spec which we then process in the caller's context, or
7088 : : NULL if no processing is required.
7089 : :
7090 : : If RETVAL_NONNULL is not NULL, then store a bool whether function
7091 : : returned non-NULL.
7092 : :
7093 : : SOFT_MATCHED_PART holds the current value of a matched * pattern, which
7094 : : may be re-expanded with a %* as part of the function arguments. */
7095 : :
7096 : : static const char *
7097 : 2078491 : handle_spec_function (const char *p, bool *retval_nonnull,
7098 : : const char *soft_matched_part)
7099 : : {
7100 : 2078491 : char *func, *args;
7101 : 2078491 : const char *endp, *funcval;
7102 : 2078491 : int count;
7103 : :
7104 : 2078491 : processing_spec_function++;
7105 : :
7106 : : /* Get the function name. */
7107 : 19322147 : for (endp = p; *endp != '\0'; endp++)
7108 : : {
7109 : 19322147 : if (*endp == '(') /* ) */
7110 : : break;
7111 : : /* Only allow [A-Za-z0-9], -, and _ in function names. */
7112 : 17243656 : if (!ISALNUM (*endp) && !(*endp == '-' || *endp == '_'))
7113 : 0 : fatal_error (input_location, "malformed spec function name");
7114 : : }
7115 : 2078491 : if (*endp != '(') /* ) */
7116 : 0 : fatal_error (input_location, "no arguments for spec function");
7117 : 2078491 : func = save_string (p, endp - p);
7118 : 2078491 : p = ++endp;
7119 : :
7120 : : /* Get the arguments. */
7121 : 25261316 : for (count = 0; *endp != '\0'; endp++)
7122 : : {
7123 : : /* ( */
7124 : 25261316 : if (*endp == ')')
7125 : : {
7126 : 2168915 : if (count == 0)
7127 : : break;
7128 : 90424 : count--;
7129 : : }
7130 : 23092401 : else if (*endp == '(') /* ) */
7131 : 90424 : count++;
7132 : : }
7133 : : /* ( */
7134 : 2078491 : if (*endp != ')')
7135 : 0 : fatal_error (input_location, "malformed spec function arguments");
7136 : 2078491 : args = save_string (p, endp - p);
7137 : 2078491 : p = ++endp;
7138 : :
7139 : : /* p now points to just past the end of the spec function expression. */
7140 : :
7141 : 2078491 : funcval = eval_spec_function (func, args, soft_matched_part);
7142 : 2078491 : if (funcval != NULL && do_spec_1 (funcval, 0, NULL) < 0)
7143 : : p = NULL;
7144 : 2078491 : if (retval_nonnull)
7145 : 1639177 : *retval_nonnull = funcval != NULL;
7146 : :
7147 : 2078491 : free (func);
7148 : 2078491 : free (args);
7149 : :
7150 : 2078491 : processing_spec_function--;
7151 : :
7152 : 2078491 : return p;
7153 : : }
7154 : :
7155 : : /* Inline subroutine of handle_braces. Returns true if the current
7156 : : input suffix matches the atom bracketed by ATOM and END_ATOM. */
7157 : : static inline bool
7158 : 0 : input_suffix_matches (const char *atom, const char *end_atom)
7159 : : {
7160 : 0 : return (input_suffix
7161 : 0 : && !strncmp (input_suffix, atom, end_atom - atom)
7162 : 0 : && input_suffix[end_atom - atom] == '\0');
7163 : : }
7164 : :
7165 : : /* Subroutine of handle_braces. Returns true if the current
7166 : : input file's spec name matches the atom bracketed by ATOM and END_ATOM. */
7167 : : static bool
7168 : 0 : input_spec_matches (const char *atom, const char *end_atom)
7169 : : {
7170 : 0 : return (input_file_compiler
7171 : 0 : && input_file_compiler->suffix
7172 : 0 : && input_file_compiler->suffix[0] != '\0'
7173 : 0 : && !strncmp (input_file_compiler->suffix + 1, atom,
7174 : 0 : end_atom - atom)
7175 : 0 : && input_file_compiler->suffix[end_atom - atom + 1] == '\0');
7176 : : }
7177 : :
7178 : : /* Subroutine of handle_braces. Returns true if a switch
7179 : : matching the atom bracketed by ATOM and END_ATOM appeared on the
7180 : : command line. */
7181 : : static bool
7182 : 38682916 : switch_matches (const char *atom, const char *end_atom, int starred)
7183 : : {
7184 : 38682916 : int i;
7185 : 38682916 : int len = end_atom - atom;
7186 : 38682916 : int plen = starred ? len : -1;
7187 : :
7188 : 908491786 : for (i = 0; i < n_switches; i++)
7189 : 871182700 : if (!strncmp (switches[i].part1, atom, len)
7190 : 2321536 : && (starred || switches[i].part1[len] == '\0')
7191 : 872557147 : && check_live_switch (i, plen))
7192 : : return true;
7193 : :
7194 : : /* Check if a switch with separated form matching the atom.
7195 : : We check -D and -U switches. */
7196 : 869808871 : else if (switches[i].args != 0)
7197 : : {
7198 : 200994088 : if ((*switches[i].part1 == 'D' || *switches[i].part1 == 'U')
7199 : 8548423 : && *switches[i].part1 == atom[0])
7200 : : {
7201 : 1 : if (!strncmp (switches[i].args[0], &atom[1], len - 1)
7202 : 1 : && (starred || (switches[i].part1[1] == '\0'
7203 : 1 : && switches[i].args[0][len - 1] == '\0'))
7204 : 2 : && check_live_switch (i, (starred ? 1 : -1)))
7205 : : return true;
7206 : : }
7207 : : }
7208 : :
7209 : : return false;
7210 : : }
7211 : :
7212 : : /* Inline subroutine of handle_braces. Mark all of the switches which
7213 : : match ATOM (extends to END_ATOM; STARRED indicates whether there
7214 : : was a star after the atom) for later processing. */
7215 : : static inline void
7216 : 11229660 : mark_matching_switches (const char *atom, const char *end_atom, int starred)
7217 : : {
7218 : 11229660 : int i;
7219 : 11229660 : int len = end_atom - atom;
7220 : 11229660 : int plen = starred ? len : -1;
7221 : :
7222 : 267485751 : for (i = 0; i < n_switches; i++)
7223 : 256256091 : if (!strncmp (switches[i].part1, atom, len)
7224 : 6355703 : && (starred || switches[i].part1[len] == '\0')
7225 : 262393809 : && check_live_switch (i, plen))
7226 : 6088408 : switches[i].ordering = 1;
7227 : 11229660 : }
7228 : :
7229 : : /* Inline subroutine of handle_braces. Process all the currently
7230 : : marked switches through give_switch, and clear the marks. */
7231 : : static inline void
7232 : 9746700 : process_marked_switches (void)
7233 : : {
7234 : 9746700 : int i;
7235 : :
7236 : 232106040 : for (i = 0; i < n_switches; i++)
7237 : 222359340 : if (switches[i].ordering == 1)
7238 : : {
7239 : 6088408 : switches[i].ordering = 0;
7240 : 6088408 : give_switch (i, 0);
7241 : : }
7242 : 9746700 : }
7243 : :
7244 : : /* Handle a %{ ... } construct. P points just inside the leading {.
7245 : : Returns a pointer one past the end of the brace block, or 0
7246 : : if we call do_spec_1 and that returns -1. */
7247 : :
7248 : : static const char *
7249 : 40724544 : handle_braces (const char *p)
7250 : : {
7251 : 40724544 : const char *atom, *end_atom;
7252 : 40724544 : const char *d_atom = NULL, *d_end_atom = NULL;
7253 : 40724544 : char *esc_buf = NULL, *d_esc_buf = NULL;
7254 : 40724544 : int esc;
7255 : 40724544 : const char *orig = p;
7256 : :
7257 : 40724544 : bool a_is_suffix;
7258 : 40724544 : bool a_is_spectype;
7259 : 40724544 : bool a_is_starred;
7260 : 40724544 : bool a_is_negated;
7261 : 40724544 : bool a_matched;
7262 : :
7263 : 40724544 : bool a_must_be_last = false;
7264 : 40724544 : bool ordered_set = false;
7265 : 40724544 : bool disjunct_set = false;
7266 : 40724544 : bool disj_matched = false;
7267 : 40724544 : bool disj_starred = true;
7268 : 40724544 : bool n_way_choice = false;
7269 : 40724544 : bool n_way_matched = false;
7270 : :
7271 : : #define SKIP_WHITE() do { while (*p == ' ' || *p == '\t') p++; } while (0)
7272 : :
7273 : 54149051 : do
7274 : : {
7275 : 54149051 : if (a_must_be_last)
7276 : 0 : goto invalid;
7277 : :
7278 : : /* Scan one "atom" (S in the description above of %{}, possibly
7279 : : with '!', '.', '@', ',', or '*' modifiers). */
7280 : 54149051 : a_matched = false;
7281 : 54149051 : a_is_suffix = false;
7282 : 54149051 : a_is_starred = false;
7283 : 54149051 : a_is_negated = false;
7284 : 54149051 : a_is_spectype = false;
7285 : :
7286 : 61717127 : SKIP_WHITE ();
7287 : 54149051 : if (*p == '!')
7288 : 13083425 : p++, a_is_negated = true;
7289 : :
7290 : 54149051 : SKIP_WHITE ();
7291 : 54149051 : if (*p == '%' && p[1] == ':')
7292 : : {
7293 : 1639177 : atom = NULL;
7294 : 1639177 : end_atom = NULL;
7295 : 1639177 : p = handle_spec_function (p + 2, &a_matched, NULL);
7296 : : }
7297 : : else
7298 : : {
7299 : 52509874 : if (*p == '.')
7300 : 0 : p++, a_is_suffix = true;
7301 : 52509874 : else if (*p == ',')
7302 : 0 : p++, a_is_spectype = true;
7303 : :
7304 : 52509874 : atom = p;
7305 : 52509874 : esc = 0;
7306 : 52509874 : while (ISIDNUM (*p) || *p == '-' || *p == '+' || *p == '='
7307 : 395922486 : || *p == ',' || *p == '.' || *p == '@' || *p == '\\')
7308 : : {
7309 : 343412612 : if (*p == '\\')
7310 : : {
7311 : 0 : p++;
7312 : 0 : if (!*p)
7313 : 0 : fatal_error (input_location,
7314 : : "braced spec %qs ends in escape", orig);
7315 : 0 : esc++;
7316 : : }
7317 : 343412612 : p++;
7318 : : }
7319 : 52509874 : end_atom = p;
7320 : :
7321 : 52509874 : if (esc)
7322 : : {
7323 : 0 : const char *ap;
7324 : 0 : char *ep;
7325 : :
7326 : 0 : if (esc_buf && esc_buf != d_esc_buf)
7327 : 0 : free (esc_buf);
7328 : 0 : esc_buf = NULL;
7329 : 0 : ep = esc_buf = (char *) xmalloc (end_atom - atom - esc + 1);
7330 : 0 : for (ap = atom; ap != end_atom; ap++, ep++)
7331 : : {
7332 : 0 : if (*ap == '\\')
7333 : 0 : ap++;
7334 : 0 : *ep = *ap;
7335 : : }
7336 : 0 : *ep = '\0';
7337 : 0 : atom = esc_buf;
7338 : 0 : end_atom = ep;
7339 : : }
7340 : :
7341 : 52509874 : if (*p == '*')
7342 : 11816133 : p++, a_is_starred = 1;
7343 : : }
7344 : :
7345 : 54149051 : SKIP_WHITE ();
7346 : 54149051 : switch (*p)
7347 : : {
7348 : 11229660 : case '&': case '}':
7349 : : /* Substitute the switch(es) indicated by the current atom. */
7350 : 11229660 : ordered_set = true;
7351 : 11229660 : if (disjunct_set || n_way_choice || a_is_negated || a_is_suffix
7352 : 11229660 : || a_is_spectype || atom == end_atom)
7353 : 0 : goto invalid;
7354 : :
7355 : 11229660 : mark_matching_switches (atom, end_atom, a_is_starred);
7356 : :
7357 : 11229660 : if (*p == '}')
7358 : 9746700 : process_marked_switches ();
7359 : : break;
7360 : :
7361 : 42919391 : case '|': case ':':
7362 : : /* Substitute some text if the current atom appears as a switch
7363 : : or suffix. */
7364 : 42919391 : disjunct_set = true;
7365 : 42919391 : if (ordered_set)
7366 : 0 : goto invalid;
7367 : :
7368 : 42919391 : if (atom && atom == end_atom)
7369 : : {
7370 : 1776316 : if (!n_way_choice || disj_matched || *p == '|'
7371 : 1776316 : || a_is_negated || a_is_suffix || a_is_spectype
7372 : 1776316 : || a_is_starred)
7373 : 0 : goto invalid;
7374 : :
7375 : : /* An empty term may appear as the last choice of an
7376 : : N-way choice set; it means "otherwise". */
7377 : 1776316 : a_must_be_last = true;
7378 : 1776316 : disj_matched = !n_way_matched;
7379 : 1776316 : disj_starred = false;
7380 : : }
7381 : : else
7382 : : {
7383 : 41143075 : if ((a_is_suffix || a_is_spectype) && a_is_starred)
7384 : 0 : goto invalid;
7385 : :
7386 : 41143075 : if (!a_is_starred)
7387 : 35567436 : disj_starred = false;
7388 : :
7389 : : /* Don't bother testing this atom if we already have a
7390 : : match. */
7391 : 41143075 : if (!disj_matched && !n_way_matched)
7392 : : {
7393 : 40122507 : if (atom == NULL)
7394 : : /* a_matched is already set by handle_spec_function. */;
7395 : 38586836 : else if (a_is_suffix)
7396 : 0 : a_matched = input_suffix_matches (atom, end_atom);
7397 : 38586836 : else if (a_is_spectype)
7398 : 0 : a_matched = input_spec_matches (atom, end_atom);
7399 : : else
7400 : 38586836 : a_matched = switch_matches (atom, end_atom, a_is_starred);
7401 : :
7402 : 40122507 : if (a_matched != a_is_negated)
7403 : : {
7404 : 12954852 : disj_matched = true;
7405 : 12954852 : d_atom = atom;
7406 : 12954852 : d_end_atom = end_atom;
7407 : 12954852 : d_esc_buf = esc_buf;
7408 : : }
7409 : : }
7410 : : }
7411 : :
7412 : 42919391 : if (*p == ':')
7413 : : {
7414 : : /* Found the body, that is, the text to substitute if the
7415 : : current disjunction matches. */
7416 : 67980676 : p = process_brace_body (p + 1, d_atom, d_end_atom, disj_starred,
7417 : 33990338 : disj_matched && !n_way_matched);
7418 : 33990338 : if (p == 0)
7419 : 37126 : goto done;
7420 : :
7421 : : /* If we have an N-way choice, reset state for the next
7422 : : disjunction. */
7423 : 33953212 : if (*p == ';')
7424 : : {
7425 : 3012494 : n_way_choice = true;
7426 : 3012494 : n_way_matched |= disj_matched;
7427 : 3012494 : disj_matched = false;
7428 : 3012494 : disj_starred = true;
7429 : 3012494 : d_atom = d_end_atom = NULL;
7430 : : }
7431 : : }
7432 : : break;
7433 : :
7434 : 0 : default:
7435 : 0 : goto invalid;
7436 : : }
7437 : : }
7438 : 54111925 : while (*p++ != '}');
7439 : :
7440 : 40687418 : done:
7441 : 40724544 : if (d_esc_buf && d_esc_buf != esc_buf)
7442 : 0 : free (d_esc_buf);
7443 : 40724544 : if (esc_buf)
7444 : 0 : free (esc_buf);
7445 : :
7446 : 40724544 : return p;
7447 : :
7448 : 0 : invalid:
7449 : 0 : fatal_error (input_location, "braced spec %qs is invalid at %qc", orig, *p);
7450 : :
7451 : : #undef SKIP_WHITE
7452 : : }
7453 : :
7454 : : /* Subroutine of handle_braces. Scan and process a brace substitution body
7455 : : (X in the description of %{} syntax). P points one past the colon;
7456 : : ATOM and END_ATOM bracket the first atom which was found to be true
7457 : : (present) in the current disjunction; STARRED indicates whether all
7458 : : the atoms in the current disjunction were starred (for syntax validation);
7459 : : MATCHED indicates whether the disjunction matched or not, and therefore
7460 : : whether or not the body is to be processed through do_spec_1 or just
7461 : : skipped. Returns a pointer to the closing } or ;, or 0 if do_spec_1
7462 : : returns -1. */
7463 : :
7464 : : static const char *
7465 : 33990338 : process_brace_body (const char *p, const char *atom, const char *end_atom,
7466 : : int starred, int matched)
7467 : : {
7468 : 33990338 : const char *body, *end_body;
7469 : 33990338 : unsigned int nesting_level;
7470 : 33990338 : bool have_subst = false;
7471 : :
7472 : : /* Locate the closing } or ;, honoring nested braces.
7473 : : Trim trailing whitespace. */
7474 : 33990338 : body = p;
7475 : 33990338 : nesting_level = 1;
7476 : 11571379448 : for (;;)
7477 : : {
7478 : 5802684893 : if (*p == '{')
7479 : 171292354 : nesting_level++;
7480 : 5631392539 : else if (*p == '}')
7481 : : {
7482 : 202270198 : if (!--nesting_level)
7483 : : break;
7484 : : }
7485 : 5429122341 : else if (*p == ';' && nesting_level == 1)
7486 : : break;
7487 : 5426109847 : else if (*p == '%' && p[1] == '*' && nesting_level == 1)
7488 : : have_subst = true;
7489 : 5425324316 : else if (*p == '\0')
7490 : 0 : goto invalid;
7491 : 5768694555 : p++;
7492 : : }
7493 : :
7494 : : end_body = p;
7495 : 36763684 : while (end_body[-1] == ' ' || end_body[-1] == '\t')
7496 : 2773346 : end_body--;
7497 : :
7498 : 33990338 : if (have_subst && !starred)
7499 : 0 : goto invalid;
7500 : :
7501 : 33990338 : if (matched)
7502 : : {
7503 : : /* Copy the substitution body to permanent storage and execute it.
7504 : : If have_subst is false, this is a simple matter of running the
7505 : : body through do_spec_1... */
7506 : 13913209 : char *string = save_string (body, end_body - body);
7507 : 13913209 : if (!have_subst)
7508 : : {
7509 : 13906412 : if (do_spec_1 (string, 0, NULL) < 0)
7510 : : {
7511 : 37126 : free (string);
7512 : 37126 : return 0;
7513 : : }
7514 : : }
7515 : : else
7516 : : {
7517 : : /* ... but if have_subst is true, we have to process the
7518 : : body once for each matching switch, with %* set to the
7519 : : variant part of the switch. */
7520 : 6797 : unsigned int hard_match_len = end_atom - atom;
7521 : 6797 : int i;
7522 : :
7523 : 273146 : for (i = 0; i < n_switches; i++)
7524 : 266349 : if (!strncmp (switches[i].part1, atom, hard_match_len)
7525 : 266349 : && check_live_switch (i, hard_match_len))
7526 : : {
7527 : 6801 : if (do_spec_1 (string, 0,
7528 : : &switches[i].part1[hard_match_len]) < 0)
7529 : : {
7530 : 0 : free (string);
7531 : 0 : return 0;
7532 : : }
7533 : : /* Pass any arguments this switch has. */
7534 : 6801 : give_switch (i, 1);
7535 : 6801 : suffix_subst = NULL;
7536 : : }
7537 : : }
7538 : 13876083 : free (string);
7539 : : }
7540 : :
7541 : : return p;
7542 : :
7543 : 0 : invalid:
7544 : 0 : fatal_error (input_location, "braced spec body %qs is invalid", body);
7545 : : }
7546 : :
7547 : : /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
7548 : : on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
7549 : : spec, or -1 if either exact match or %* is used.
7550 : :
7551 : : A -O switch is obsoleted by a later -O switch. A -f, -g, -m, or -W switch
7552 : : whose value does not begin with "no-" is obsoleted by the same value
7553 : : with the "no-", similarly for a switch with the "no-" prefix. */
7554 : :
7555 : : static int
7556 : 7518967 : check_live_switch (int switchnum, int prefix_length)
7557 : : {
7558 : 7518967 : const char *name = switches[switchnum].part1;
7559 : 7518967 : int i;
7560 : :
7561 : : /* If we already processed this switch and determined if it was
7562 : : live or not, return our past determination. */
7563 : 7518967 : if (switches[switchnum].live_cond != 0)
7564 : 950309 : return ((switches[switchnum].live_cond & SWITCH_LIVE) != 0
7565 : 900399 : && (switches[switchnum].live_cond & SWITCH_FALSE) == 0
7566 : 1850708 : && (switches[switchnum].live_cond & SWITCH_IGNORE_PERMANENTLY)
7567 : 950309 : == 0);
7568 : :
7569 : : /* In the common case of {<at-most-one-letter>*}, a negating
7570 : : switch would always match, so ignore that case. We will just
7571 : : send the conflicting switches to the compiler phase. */
7572 : 6568658 : if (prefix_length >= 0 && prefix_length <= 1)
7573 : : return 1;
7574 : :
7575 : : /* Now search for duplicate in a manner that depends on the name. */
7576 : 880844 : switch (*name)
7577 : : {
7578 : 62 : case 'O':
7579 : 344 : for (i = switchnum + 1; i < n_switches; i++)
7580 : 287 : if (switches[i].part1[0] == 'O')
7581 : : {
7582 : 5 : switches[switchnum].validated = true;
7583 : 5 : switches[switchnum].live_cond = SWITCH_FALSE;
7584 : 5 : return 0;
7585 : : }
7586 : : break;
7587 : :
7588 : 282981 : case 'W': case 'f': case 'm': case 'g':
7589 : 282981 : if (startswith (name + 1, "no-"))
7590 : : {
7591 : : /* We have Xno-YYY, search for XYYY. */
7592 : 34923 : for (i = switchnum + 1; i < n_switches; i++)
7593 : 29354 : if (switches[i].part1[0] == name[0]
7594 : 5595 : && ! strcmp (&switches[i].part1[1], &name[4]))
7595 : : {
7596 : : /* --specs are validated with the validate_switches mechanism. */
7597 : 0 : if (switches[switchnum].known)
7598 : 0 : switches[switchnum].validated = true;
7599 : 0 : switches[switchnum].live_cond = SWITCH_FALSE;
7600 : 0 : return 0;
7601 : : }
7602 : : }
7603 : : else
7604 : : {
7605 : : /* We have XYYY, search for Xno-YYY. */
7606 : 2903475 : for (i = switchnum + 1; i < n_switches; i++)
7607 : 2626063 : if (switches[i].part1[0] == name[0]
7608 : 1586659 : && switches[i].part1[1] == 'n'
7609 : 199161 : && switches[i].part1[2] == 'o'
7610 : 199160 : && switches[i].part1[3] == '-'
7611 : 199130 : && !strcmp (&switches[i].part1[4], &name[1]))
7612 : : {
7613 : : /* --specs are validated with the validate_switches mechanism. */
7614 : 0 : if (switches[switchnum].known)
7615 : 0 : switches[switchnum].validated = true;
7616 : 0 : switches[switchnum].live_cond = SWITCH_FALSE;
7617 : 0 : return 0;
7618 : : }
7619 : : }
7620 : : break;
7621 : : }
7622 : :
7623 : : /* Otherwise the switch is live. */
7624 : 880839 : switches[switchnum].live_cond |= SWITCH_LIVE;
7625 : 880839 : return 1;
7626 : : }
7627 : :
7628 : : /* Pass a switch to the current accumulating command
7629 : : in the same form that we received it.
7630 : : SWITCHNUM identifies the switch; it is an index into
7631 : : the vector of switches gcc received, which is `switches'.
7632 : : This cannot fail since it never finishes a command line.
7633 : :
7634 : : If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */
7635 : :
7636 : : static void
7637 : 6095209 : give_switch (int switchnum, int omit_first_word)
7638 : : {
7639 : 6095209 : if ((switches[switchnum].live_cond & SWITCH_IGNORE) != 0)
7640 : : return;
7641 : :
7642 : 6095198 : if (!omit_first_word)
7643 : : {
7644 : 6088397 : do_spec_1 ("-", 0, NULL);
7645 : 6088397 : do_spec_1 (switches[switchnum].part1, 1, NULL);
7646 : : }
7647 : :
7648 : 6095198 : if (switches[switchnum].args != 0)
7649 : : {
7650 : : const char **p;
7651 : 2460622 : for (p = switches[switchnum].args; *p; p++)
7652 : : {
7653 : 1230311 : const char *arg = *p;
7654 : :
7655 : 1230311 : do_spec_1 (" ", 0, NULL);
7656 : 1230311 : if (suffix_subst)
7657 : : {
7658 : 5879 : unsigned length = strlen (arg);
7659 : 5879 : int dot = 0;
7660 : :
7661 : 11758 : while (length-- && !IS_DIR_SEPARATOR (arg[length]))
7662 : 11758 : if (arg[length] == '.')
7663 : : {
7664 : 5879 : (CONST_CAST (char *, arg))[length] = 0;
7665 : 5879 : dot = 1;
7666 : 5879 : break;
7667 : : }
7668 : 5879 : do_spec_1 (arg, 1, NULL);
7669 : 5879 : if (dot)
7670 : 5879 : (CONST_CAST (char *, arg))[length] = '.';
7671 : 5879 : do_spec_1 (suffix_subst, 1, NULL);
7672 : : }
7673 : : else
7674 : 1224432 : do_spec_1 (arg, 1, NULL);
7675 : : }
7676 : : }
7677 : :
7678 : 6095198 : do_spec_1 (" ", 0, NULL);
7679 : 6095198 : switches[switchnum].validated = true;
7680 : : }
7681 : :
7682 : : /* Print GCC configuration (e.g. version, thread model, target,
7683 : : configuration_arguments) to a given FILE. */
7684 : :
7685 : : static void
7686 : 1471 : print_configuration (FILE *file)
7687 : : {
7688 : 1471 : int n;
7689 : 1471 : const char *thrmod;
7690 : :
7691 : 1471 : fnotice (file, "Target: %s\n", spec_machine);
7692 : 1471 : fnotice (file, "Configured with: %s\n", configuration_arguments);
7693 : :
7694 : : #ifdef THREAD_MODEL_SPEC
7695 : : /* We could have defined THREAD_MODEL_SPEC to "%*" by default,
7696 : : but there's no point in doing all this processing just to get
7697 : : thread_model back. */
7698 : : obstack_init (&obstack);
7699 : : do_spec_1 (THREAD_MODEL_SPEC, 0, thread_model);
7700 : : obstack_1grow (&obstack, '\0');
7701 : : thrmod = XOBFINISH (&obstack, const char *);
7702 : : #else
7703 : 1471 : thrmod = thread_model;
7704 : : #endif
7705 : :
7706 : 1471 : fnotice (file, "Thread model: %s\n", thrmod);
7707 : 1471 : fnotice (file, "Supported LTO compression algorithms: zlib");
7708 : : #ifdef HAVE_ZSTD_H
7709 : 1471 : fnotice (file, " zstd");
7710 : : #endif
7711 : 1471 : fnotice (file, "\n");
7712 : :
7713 : : /* compiler_version is truncated at the first space when initialized
7714 : : from version string, so truncate version_string at the first space
7715 : : before comparing. */
7716 : 11768 : for (n = 0; version_string[n]; n++)
7717 : 10297 : if (version_string[n] == ' ')
7718 : : break;
7719 : :
7720 : 1471 : if (! strncmp (version_string, compiler_version, n)
7721 : 1471 : && compiler_version[n] == 0)
7722 : 1471 : fnotice (file, "gcc version %s %s\n", version_string,
7723 : : pkgversion_string);
7724 : : else
7725 : 0 : fnotice (file, "gcc driver version %s %sexecuting gcc version %s\n",
7726 : : version_string, pkgversion_string, compiler_version);
7727 : :
7728 : 1471 : }
7729 : :
7730 : : #define RETRY_ICE_ATTEMPTS 3
7731 : :
7732 : : /* Returns true if FILE1 and FILE2 contain equivalent data, 0 otherwise.
7733 : : If lines start with 0x followed by 1-16 lowercase hexadecimal digits
7734 : : followed by a space, ignore anything before that space. These are
7735 : : typically function addresses from libbacktrace and those can differ
7736 : : due to ASLR. */
7737 : :
7738 : : static bool
7739 : 0 : files_equal_p (char *file1, char *file2)
7740 : : {
7741 : 0 : FILE *f1 = fopen (file1, "rb");
7742 : 0 : FILE *f2 = fopen (file2, "rb");
7743 : 0 : char line1[256], line2[256];
7744 : :
7745 : 0 : bool line_start = true;
7746 : 0 : while (fgets (line1, sizeof (line1), f1))
7747 : : {
7748 : 0 : if (!fgets (line2, sizeof (line2), f2))
7749 : 0 : goto error;
7750 : 0 : char *p1 = line1, *p2 = line2;
7751 : 0 : if (line_start
7752 : 0 : && line1[0] == '0'
7753 : 0 : && line1[1] == 'x'
7754 : 0 : && line2[0] == '0'
7755 : 0 : && line2[1] == 'x')
7756 : : {
7757 : : int i, j;
7758 : 0 : for (i = 0; i < 16; ++i)
7759 : 0 : if (!ISXDIGIT (line1[2 + i]) || ISUPPER (line1[2 + i]))
7760 : : break;
7761 : 0 : for (j = 0; j < 16; ++j)
7762 : 0 : if (!ISXDIGIT (line2[2 + j]) || ISUPPER (line2[2 + j]))
7763 : : break;
7764 : 0 : if (i && line1[2 + i] == ' ' && j && line2[2 + j] == ' ')
7765 : : {
7766 : 0 : p1 = line1 + i + 3;
7767 : 0 : p2 = line2 + j + 3;
7768 : : }
7769 : : }
7770 : 0 : if (strcmp (p1, p2) != 0)
7771 : 0 : goto error;
7772 : 0 : line_start = strchr (line1, '\n') != NULL;
7773 : : }
7774 : 0 : if (fgets (line2, sizeof (line2), f2))
7775 : 0 : goto error;
7776 : :
7777 : 0 : fclose (f1);
7778 : 0 : fclose (f2);
7779 : 0 : return 1;
7780 : :
7781 : 0 : error:
7782 : 0 : fclose (f1);
7783 : 0 : fclose (f2);
7784 : 0 : return 0;
7785 : : }
7786 : :
7787 : : /* Check that compiler's output doesn't differ across runs.
7788 : : TEMP_STDOUT_FILES and TEMP_STDERR_FILES are arrays of files, containing
7789 : : stdout and stderr for each compiler run. Return true if all of
7790 : : TEMP_STDOUT_FILES and TEMP_STDERR_FILES are equivalent. */
7791 : :
7792 : : static bool
7793 : 0 : check_repro (char **temp_stdout_files, char **temp_stderr_files)
7794 : : {
7795 : 0 : int i;
7796 : 0 : for (i = 0; i < RETRY_ICE_ATTEMPTS - 2; ++i)
7797 : : {
7798 : 0 : if (!files_equal_p (temp_stdout_files[i], temp_stdout_files[i + 1])
7799 : 0 : || !files_equal_p (temp_stderr_files[i], temp_stderr_files[i + 1]))
7800 : : {
7801 : 0 : fnotice (stderr, "The bug is not reproducible, so it is"
7802 : : " likely a hardware or OS problem.\n");
7803 : 0 : break;
7804 : : }
7805 : : }
7806 : 0 : return i == RETRY_ICE_ATTEMPTS - 2;
7807 : : }
7808 : :
7809 : : enum attempt_status {
7810 : : ATTEMPT_STATUS_FAIL_TO_RUN,
7811 : : ATTEMPT_STATUS_SUCCESS,
7812 : : ATTEMPT_STATUS_ICE
7813 : : };
7814 : :
7815 : :
7816 : : /* Run compiler with arguments NEW_ARGV to reproduce the ICE, storing stdout
7817 : : to OUT_TEMP and stderr to ERR_TEMP. If APPEND is TRUE, append to OUT_TEMP
7818 : : and ERR_TEMP instead of truncating. If EMIT_SYSTEM_INFO is TRUE, also write
7819 : : GCC configuration into to ERR_TEMP. Return ATTEMPT_STATUS_FAIL_TO_RUN if
7820 : : compiler failed to run, ATTEMPT_STATUS_ICE if compiled ICE-ed and
7821 : : ATTEMPT_STATUS_SUCCESS otherwise. */
7822 : :
7823 : : static enum attempt_status
7824 : 0 : run_attempt (const char **new_argv, const char *out_temp,
7825 : : const char *err_temp, int emit_system_info, int append)
7826 : : {
7827 : :
7828 : 0 : if (emit_system_info)
7829 : : {
7830 : 0 : FILE *file_out = fopen (err_temp, "a");
7831 : 0 : print_configuration (file_out);
7832 : 0 : fputs ("\n", file_out);
7833 : 0 : fclose (file_out);
7834 : : }
7835 : :
7836 : 0 : int exit_status;
7837 : 0 : const char *errmsg;
7838 : 0 : struct pex_obj *pex;
7839 : 0 : int err;
7840 : 0 : int pex_flags = PEX_USE_PIPES | PEX_LAST;
7841 : 0 : enum attempt_status status = ATTEMPT_STATUS_FAIL_TO_RUN;
7842 : :
7843 : 0 : if (append)
7844 : 0 : pex_flags |= PEX_STDOUT_APPEND | PEX_STDERR_APPEND;
7845 : :
7846 : 0 : pex = pex_init (PEX_USE_PIPES, new_argv[0], NULL);
7847 : 0 : if (!pex)
7848 : : fatal_error (input_location, "%<pex_init%> failed: %m");
7849 : :
7850 : 0 : errmsg = pex_run (pex, pex_flags, new_argv[0],
7851 : 0 : CONST_CAST2 (char *const *, const char **, &new_argv[1]),
7852 : : out_temp, err_temp, &err);
7853 : 0 : if (errmsg != NULL)
7854 : : {
7855 : 0 : errno = err;
7856 : 0 : fatal_error (input_location,
7857 : : err ? G_ ("cannot execute %qs: %s: %m")
7858 : : : G_ ("cannot execute %qs: %s"),
7859 : : new_argv[0], errmsg);
7860 : : }
7861 : :
7862 : 0 : if (!pex_get_status (pex, 1, &exit_status))
7863 : 0 : goto out;
7864 : :
7865 : 0 : switch (WEXITSTATUS (exit_status))
7866 : : {
7867 : : case ICE_EXIT_CODE:
7868 : 0 : status = ATTEMPT_STATUS_ICE;
7869 : : break;
7870 : :
7871 : 0 : case SUCCESS_EXIT_CODE:
7872 : 0 : status = ATTEMPT_STATUS_SUCCESS;
7873 : 0 : break;
7874 : :
7875 : 0 : default:
7876 : 0 : ;
7877 : : }
7878 : :
7879 : 0 : out:
7880 : 0 : pex_free (pex);
7881 : 0 : return status;
7882 : : }
7883 : :
7884 : : /* This routine reads lines from IN file, adds C++ style comments
7885 : : at the begining of each line and writes result into OUT. */
7886 : :
7887 : : static void
7888 : 0 : insert_comments (const char *file_in, const char *file_out)
7889 : : {
7890 : 0 : FILE *in = fopen (file_in, "rb");
7891 : 0 : FILE *out = fopen (file_out, "wb");
7892 : 0 : char line[256];
7893 : :
7894 : 0 : bool add_comment = true;
7895 : 0 : while (fgets (line, sizeof (line), in))
7896 : : {
7897 : 0 : if (add_comment)
7898 : 0 : fputs ("// ", out);
7899 : 0 : fputs (line, out);
7900 : 0 : add_comment = strchr (line, '\n') != NULL;
7901 : : }
7902 : :
7903 : 0 : fclose (in);
7904 : 0 : fclose (out);
7905 : 0 : }
7906 : :
7907 : : /* This routine adds preprocessed source code into the given ERR_FILE.
7908 : : To do this, it adds "-E" to NEW_ARGV and execute RUN_ATTEMPT routine to
7909 : : add information in report file. RUN_ATTEMPT should return
7910 : : ATTEMPT_STATUS_SUCCESS, in other case we cannot generate the report. */
7911 : :
7912 : : static void
7913 : 0 : do_report_bug (const char **new_argv, const int nargs,
7914 : : char **out_file, char **err_file)
7915 : : {
7916 : 0 : int i, status;
7917 : 0 : int fd = open (*out_file, O_RDWR | O_APPEND);
7918 : 0 : if (fd < 0)
7919 : : return;
7920 : 0 : write (fd, "\n//", 3);
7921 : 0 : for (i = 0; i < nargs; i++)
7922 : : {
7923 : 0 : write (fd, " ", 1);
7924 : 0 : write (fd, new_argv[i], strlen (new_argv[i]));
7925 : : }
7926 : 0 : write (fd, "\n\n", 2);
7927 : 0 : close (fd);
7928 : 0 : new_argv[nargs] = "-E";
7929 : 0 : new_argv[nargs + 1] = NULL;
7930 : :
7931 : 0 : status = run_attempt (new_argv, *out_file, *err_file, 0, 1);
7932 : :
7933 : 0 : if (status == ATTEMPT_STATUS_SUCCESS)
7934 : : {
7935 : 0 : fnotice (stderr, "Preprocessed source stored into %s file,"
7936 : : " please attach this to your bugreport.\n", *out_file);
7937 : : /* Make sure it is not deleted. */
7938 : 0 : free (*out_file);
7939 : 0 : *out_file = NULL;
7940 : : }
7941 : : }
7942 : :
7943 : : /* Try to reproduce ICE. If bug is reproducible, generate report .err file
7944 : : containing GCC configuration, backtrace, compiler's command line options
7945 : : and preprocessed source code. */
7946 : :
7947 : : static void
7948 : 0 : try_generate_repro (const char **argv)
7949 : : {
7950 : 0 : int i, nargs, out_arg = -1, quiet = 0, attempt;
7951 : 0 : const char **new_argv;
7952 : 0 : char *temp_files[RETRY_ICE_ATTEMPTS * 2];
7953 : 0 : char **temp_stdout_files = &temp_files[0];
7954 : 0 : char **temp_stderr_files = &temp_files[RETRY_ICE_ATTEMPTS];
7955 : :
7956 : 0 : if (gcc_input_filename == NULL || ! strcmp (gcc_input_filename, "-"))
7957 : 0 : return;
7958 : :
7959 : 0 : for (nargs = 0; argv[nargs] != NULL; ++nargs)
7960 : : /* Only retry compiler ICEs, not preprocessor ones. */
7961 : 0 : if (! strcmp (argv[nargs], "-E"))
7962 : : return;
7963 : 0 : else if (argv[nargs][0] == '-' && argv[nargs][1] == 'o')
7964 : : {
7965 : 0 : if (out_arg == -1)
7966 : : out_arg = nargs;
7967 : : else
7968 : : return;
7969 : : }
7970 : : /* If the compiler is going to output any time information,
7971 : : it might varry between invocations. */
7972 : 0 : else if (! strcmp (argv[nargs], "-quiet"))
7973 : : quiet = 1;
7974 : 0 : else if (! strcmp (argv[nargs], "-ftime-report"))
7975 : : return;
7976 : :
7977 : 0 : if (out_arg == -1 || !quiet)
7978 : : return;
7979 : :
7980 : 0 : memset (temp_files, '\0', sizeof (temp_files));
7981 : 0 : new_argv = XALLOCAVEC (const char *, nargs + 4);
7982 : 0 : memcpy (new_argv, argv, (nargs + 1) * sizeof (const char *));
7983 : 0 : new_argv[nargs++] = "-frandom-seed=0";
7984 : 0 : new_argv[nargs++] = "-fdump-noaddr";
7985 : 0 : new_argv[nargs] = NULL;
7986 : 0 : if (new_argv[out_arg][2] == '\0')
7987 : 0 : new_argv[out_arg + 1] = "-";
7988 : : else
7989 : 0 : new_argv[out_arg] = "-o-";
7990 : :
7991 : : #ifdef HOST_HAS_PERSONALITY_ADDR_NO_RANDOMIZE
7992 : 0 : personality (personality (0xffffffffU) | ADDR_NO_RANDOMIZE);
7993 : : #endif
7994 : :
7995 : 0 : int status;
7996 : 0 : for (attempt = 0; attempt < RETRY_ICE_ATTEMPTS; ++attempt)
7997 : : {
7998 : 0 : int emit_system_info = 0;
7999 : 0 : int append = 0;
8000 : 0 : temp_stdout_files[attempt] = make_temp_file (".out");
8001 : 0 : temp_stderr_files[attempt] = make_temp_file (".err");
8002 : :
8003 : 0 : if (attempt == RETRY_ICE_ATTEMPTS - 1)
8004 : : {
8005 : 0 : append = 1;
8006 : 0 : emit_system_info = 1;
8007 : : }
8008 : :
8009 : 0 : status = run_attempt (new_argv, temp_stdout_files[attempt],
8010 : : temp_stderr_files[attempt], emit_system_info,
8011 : : append);
8012 : :
8013 : 0 : if (status != ATTEMPT_STATUS_ICE)
8014 : : {
8015 : 0 : fnotice (stderr, "The bug is not reproducible, so it is"
8016 : : " likely a hardware or OS problem.\n");
8017 : 0 : goto out;
8018 : : }
8019 : : }
8020 : :
8021 : 0 : if (!check_repro (temp_stdout_files, temp_stderr_files))
8022 : 0 : goto out;
8023 : :
8024 : 0 : {
8025 : : /* Insert commented out backtrace into report file. */
8026 : 0 : char **stderr_commented = &temp_stdout_files[RETRY_ICE_ATTEMPTS - 1];
8027 : 0 : insert_comments (temp_stderr_files[RETRY_ICE_ATTEMPTS - 1],
8028 : : *stderr_commented);
8029 : :
8030 : : /* In final attempt we append compiler options and preprocesssed code to last
8031 : : generated .out file with configuration and backtrace. */
8032 : 0 : char **err = &temp_stderr_files[RETRY_ICE_ATTEMPTS - 1];
8033 : 0 : do_report_bug (new_argv, nargs, stderr_commented, err);
8034 : : }
8035 : :
8036 : : out:
8037 : 0 : for (i = 0; i < RETRY_ICE_ATTEMPTS * 2; i++)
8038 : 0 : if (temp_files[i])
8039 : : {
8040 : 0 : unlink (temp_stdout_files[i]);
8041 : 0 : free (temp_stdout_files[i]);
8042 : : }
8043 : : }
8044 : :
8045 : : /* Search for a file named NAME trying various prefixes including the
8046 : : user's -B prefix and some standard ones.
8047 : : Return the absolute file name found. If nothing is found, return NAME. */
8048 : :
8049 : : static const char *
8050 : 546303 : find_file (const char *name)
8051 : : {
8052 : 546303 : char *newname = find_a_file (&startfile_prefixes, name, R_OK, true);
8053 : 546303 : return newname ? newname : name;
8054 : : }
8055 : :
8056 : : /* Determine whether a directory exists. */
8057 : :
8058 : : static int
8059 : 10472848 : is_directory (const char *path1)
8060 : : {
8061 : 10472848 : int len1;
8062 : 10472848 : char *path;
8063 : 10472848 : char *cp;
8064 : 10472848 : struct stat st;
8065 : :
8066 : : /* Ensure the string ends with "/.". The resulting path will be a
8067 : : directory even if the given path is a symbolic link. */
8068 : 10472848 : len1 = strlen (path1);
8069 : 10472848 : path = (char *) alloca (3 + len1);
8070 : 10472848 : memcpy (path, path1, len1);
8071 : 10472848 : cp = path + len1;
8072 : 10472848 : if (!IS_DIR_SEPARATOR (cp[-1]))
8073 : 1504419 : *cp++ = DIR_SEPARATOR;
8074 : 10472848 : *cp++ = '.';
8075 : 10472848 : *cp = '\0';
8076 : :
8077 : 10472848 : return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
8078 : : }
8079 : :
8080 : : /* Set up the various global variables to indicate that we're processing
8081 : : the input file named FILENAME. */
8082 : :
8083 : : void
8084 : 836293 : set_input (const char *filename)
8085 : : {
8086 : 836293 : const char *p;
8087 : :
8088 : 836293 : gcc_input_filename = filename;
8089 : 836293 : input_filename_length = strlen (gcc_input_filename);
8090 : 836293 : input_basename = lbasename (gcc_input_filename);
8091 : :
8092 : : /* Find a suffix starting with the last period,
8093 : : and set basename_length to exclude that suffix. */
8094 : 836293 : basename_length = strlen (input_basename);
8095 : 836293 : suffixed_basename_length = basename_length;
8096 : 836293 : p = input_basename + basename_length;
8097 : 3668715 : while (p != input_basename && *p != '.')
8098 : 2832422 : --p;
8099 : 836293 : if (*p == '.' && p != input_basename)
8100 : : {
8101 : 600086 : basename_length = p - input_basename;
8102 : 600086 : input_suffix = p + 1;
8103 : : }
8104 : : else
8105 : 236207 : input_suffix = "";
8106 : :
8107 : : /* If a spec for 'g', 'u', or 'U' is seen with -save-temps then
8108 : : we will need to do a stat on the gcc_input_filename. The
8109 : : INPUT_STAT_SET signals that the stat is needed. */
8110 : 836293 : input_stat_set = 0;
8111 : 836293 : }
8112 : :
8113 : : /* On fatal signals, delete all the temporary files. */
8114 : :
8115 : : static void
8116 : 0 : fatal_signal (int signum)
8117 : : {
8118 : 0 : signal (signum, SIG_DFL);
8119 : 0 : delete_failure_queue ();
8120 : 0 : delete_temp_files ();
8121 : : /* Get the same signal again, this time not handled,
8122 : : so its normal effect occurs. */
8123 : 0 : kill (getpid (), signum);
8124 : 0 : }
8125 : :
8126 : : /* Compare the contents of the two files named CMPFILE[0] and
8127 : : CMPFILE[1]. Return zero if they're identical, nonzero
8128 : : otherwise. */
8129 : :
8130 : : static int
8131 : 613 : compare_files (char *cmpfile[])
8132 : : {
8133 : 613 : int ret = 0;
8134 : 613 : FILE *temp[2] = { NULL, NULL };
8135 : 613 : int i;
8136 : :
8137 : : #if HAVE_MMAP_FILE
8138 : 613 : {
8139 : 613 : size_t length[2];
8140 : 613 : void *map[2] = { NULL, NULL };
8141 : :
8142 : 1839 : for (i = 0; i < 2; i++)
8143 : : {
8144 : 1226 : struct stat st;
8145 : :
8146 : 1226 : if (stat (cmpfile[i], &st) < 0 || !S_ISREG (st.st_mode))
8147 : : {
8148 : 0 : error ("%s: could not determine length of compare-debug file %s",
8149 : : gcc_input_filename, cmpfile[i]);
8150 : 0 : ret = 1;
8151 : 0 : break;
8152 : : }
8153 : :
8154 : 1226 : length[i] = st.st_size;
8155 : : }
8156 : :
8157 : 613 : if (!ret && length[0] != length[1])
8158 : : {
8159 : 31 : error ("%s: %<-fcompare-debug%> failure (length)", gcc_input_filename);
8160 : 31 : ret = 1;
8161 : : }
8162 : :
8163 : 31 : if (!ret)
8164 : 1684 : for (i = 0; i < 2; i++)
8165 : : {
8166 : 1133 : int fd = open (cmpfile[i], O_RDONLY);
8167 : 1133 : if (fd < 0)
8168 : : {
8169 : 0 : error ("%s: could not open compare-debug file %s",
8170 : : gcc_input_filename, cmpfile[i]);
8171 : 0 : ret = 1;
8172 : 0 : break;
8173 : : }
8174 : :
8175 : 1133 : map[i] = mmap (NULL, length[i], PROT_READ, MAP_PRIVATE, fd, 0);
8176 : 1133 : close (fd);
8177 : :
8178 : 1133 : if (map[i] == (void *) MAP_FAILED)
8179 : : {
8180 : : ret = -1;
8181 : : break;
8182 : : }
8183 : : }
8184 : :
8185 : 582 : if (!ret)
8186 : : {
8187 : 551 : if (memcmp (map[0], map[1], length[0]) != 0)
8188 : : {
8189 : 0 : error ("%s: %<-fcompare-debug%> failure", gcc_input_filename);
8190 : 0 : ret = 1;
8191 : : }
8192 : : }
8193 : :
8194 : 1839 : for (i = 0; i < 2; i++)
8195 : 1226 : if (map[i])
8196 : 1133 : munmap ((caddr_t) map[i], length[i]);
8197 : :
8198 : 613 : if (ret >= 0)
8199 : 582 : return ret;
8200 : :
8201 : 31 : ret = 0;
8202 : : }
8203 : : #endif
8204 : :
8205 : 93 : for (i = 0; i < 2; i++)
8206 : : {
8207 : 62 : temp[i] = fopen (cmpfile[i], "r");
8208 : 62 : if (!temp[i])
8209 : : {
8210 : 0 : error ("%s: could not open compare-debug file %s",
8211 : : gcc_input_filename, cmpfile[i]);
8212 : 0 : ret = 1;
8213 : 0 : break;
8214 : : }
8215 : : }
8216 : :
8217 : 31 : if (!ret && temp[0] && temp[1])
8218 : 31 : for (;;)
8219 : : {
8220 : 31 : int c0, c1;
8221 : 31 : c0 = fgetc (temp[0]);
8222 : 31 : c1 = fgetc (temp[1]);
8223 : :
8224 : 31 : if (c0 != c1)
8225 : : {
8226 : 0 : error ("%s: %<-fcompare-debug%> failure",
8227 : : gcc_input_filename);
8228 : 0 : ret = 1;
8229 : 0 : break;
8230 : : }
8231 : :
8232 : 31 : if (c0 == EOF)
8233 : : break;
8234 : : }
8235 : :
8236 : 93 : for (i = 1; i >= 0; i--)
8237 : : {
8238 : 62 : if (temp[i])
8239 : 62 : fclose (temp[i]);
8240 : : }
8241 : :
8242 : : return ret;
8243 : : }
8244 : :
8245 : 298436 : driver::driver (bool can_finalize, bool debug) :
8246 : 298436 : explicit_link_files (NULL),
8247 : 298436 : decoded_options (NULL)
8248 : : {
8249 : 298436 : env.init (can_finalize, debug);
8250 : 298436 : }
8251 : :
8252 : 297954 : driver::~driver ()
8253 : : {
8254 : 297954 : XDELETEVEC (explicit_link_files);
8255 : 297954 : XDELETEVEC (decoded_options);
8256 : 297954 : }
8257 : :
8258 : : /* driver::main is implemented as a series of driver:: method calls. */
8259 : :
8260 : : int
8261 : 298436 : driver::main (int argc, char **argv)
8262 : : {
8263 : 298436 : bool early_exit;
8264 : :
8265 : 298436 : set_progname (argv[0]);
8266 : 298436 : expand_at_files (&argc, &argv);
8267 : 298436 : decode_argv (argc, const_cast <const char **> (argv));
8268 : 298436 : global_initializations ();
8269 : 298436 : build_multilib_strings ();
8270 : 298436 : set_up_specs ();
8271 : 298149 : putenv_COLLECT_AS_OPTIONS (assembler_options);
8272 : 298149 : putenv_COLLECT_GCC (argv[0]);
8273 : 298149 : maybe_putenv_COLLECT_LTO_WRAPPER ();
8274 : 298149 : maybe_putenv_OFFLOAD_TARGETS ();
8275 : 298149 : handle_unrecognized_options ();
8276 : :
8277 : 298149 : if (completion)
8278 : : {
8279 : 5 : m_option_proposer.suggest_completion (completion);
8280 : 5 : return 0;
8281 : : }
8282 : :
8283 : 298144 : if (!maybe_print_and_exit ())
8284 : : return 0;
8285 : :
8286 : 285294 : early_exit = prepare_infiles ();
8287 : 285100 : if (early_exit)
8288 : 490 : return get_exit_code ();
8289 : :
8290 : 284610 : do_spec_on_infiles ();
8291 : 284610 : maybe_run_linker (argv[0]);
8292 : 284610 : final_actions ();
8293 : 284610 : return get_exit_code ();
8294 : : }
8295 : :
8296 : : /* Locate the final component of argv[0] after any leading path, and set
8297 : : the program name accordingly. */
8298 : :
8299 : : void
8300 : 298436 : driver::set_progname (const char *argv0) const
8301 : : {
8302 : 298436 : const char *p = argv0 + strlen (argv0);
8303 : 1652395 : while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
8304 : 1353959 : --p;
8305 : 298436 : progname = p;
8306 : :
8307 : 298436 : xmalloc_set_program_name (progname);
8308 : 298436 : }
8309 : :
8310 : : /* Expand any @ files within the command-line args,
8311 : : setting at_file_supplied if any were expanded. */
8312 : :
8313 : : void
8314 : 298436 : driver::expand_at_files (int *argc, char ***argv) const
8315 : : {
8316 : 298436 : char **old_argv = *argv;
8317 : :
8318 : 298436 : expandargv (argc, argv);
8319 : :
8320 : : /* Determine if any expansions were made. */
8321 : 298436 : if (*argv != old_argv)
8322 : 13251 : at_file_supplied = true;
8323 : 298436 : }
8324 : :
8325 : : /* Decode the command-line arguments from argc/argv into the
8326 : : decoded_options array. */
8327 : :
8328 : : void
8329 : 298436 : driver::decode_argv (int argc, const char **argv)
8330 : : {
8331 : 298436 : init_opts_obstack ();
8332 : 298436 : init_options_struct (&global_options, &global_options_set);
8333 : :
8334 : 298436 : decode_cmdline_options_to_array (argc, argv,
8335 : : CL_DRIVER,
8336 : : &decoded_options, &decoded_options_count);
8337 : 298436 : }
8338 : :
8339 : : /* Perform various initializations and setup. */
8340 : :
8341 : : void
8342 : 298436 : driver::global_initializations ()
8343 : : {
8344 : : /* Unlock the stdio streams. */
8345 : 298436 : unlock_std_streams ();
8346 : :
8347 : 298436 : gcc_init_libintl ();
8348 : :
8349 : 298436 : diagnostic_initialize (global_dc, 0);
8350 : 298436 : diagnostic_color_init (global_dc);
8351 : 298436 : diagnostic_urls_init (global_dc);
8352 : 298436 : global_dc->push_owned_urlifier (make_gcc_urlifier (0));
8353 : :
8354 : : #ifdef GCC_DRIVER_HOST_INITIALIZATION
8355 : : /* Perform host dependent initialization when needed. */
8356 : : GCC_DRIVER_HOST_INITIALIZATION;
8357 : : #endif
8358 : :
8359 : 298436 : if (atexit (delete_temp_files) != 0)
8360 : 0 : fatal_error (input_location, "atexit failed");
8361 : :
8362 : 298436 : if (signal (SIGINT, SIG_IGN) != SIG_IGN)
8363 : 298285 : signal (SIGINT, fatal_signal);
8364 : : #ifdef SIGHUP
8365 : 298436 : if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
8366 : 21242 : signal (SIGHUP, fatal_signal);
8367 : : #endif
8368 : 298436 : if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
8369 : 298436 : signal (SIGTERM, fatal_signal);
8370 : : #ifdef SIGPIPE
8371 : 298436 : if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
8372 : 298436 : signal (SIGPIPE, fatal_signal);
8373 : : #endif
8374 : : #ifdef SIGCHLD
8375 : : /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
8376 : : receive the signal. A different setting is inheritable */
8377 : 298436 : signal (SIGCHLD, SIG_DFL);
8378 : : #endif
8379 : :
8380 : : /* Parsing and gimplification sometimes need quite large stack.
8381 : : Increase stack size limits if possible. */
8382 : 298436 : stack_limit_increase (64 * 1024 * 1024);
8383 : :
8384 : : /* Allocate the argument vector. */
8385 : 298436 : alloc_args ();
8386 : :
8387 : 298436 : obstack_init (&obstack);
8388 : 298436 : }
8389 : :
8390 : : /* Build multilib_select, et. al from the separate lines that make up each
8391 : : multilib selection. */
8392 : :
8393 : : void
8394 : 298436 : driver::build_multilib_strings () const
8395 : : {
8396 : 298436 : {
8397 : 298436 : const char *p;
8398 : 298436 : const char *const *q = multilib_raw;
8399 : 298436 : int need_space;
8400 : :
8401 : 298436 : obstack_init (&multilib_obstack);
8402 : 298436 : while ((p = *q++) != (char *) 0)
8403 : 1193744 : obstack_grow (&multilib_obstack, p, strlen (p));
8404 : :
8405 : 298436 : obstack_1grow (&multilib_obstack, 0);
8406 : 298436 : multilib_select = XOBFINISH (&multilib_obstack, const char *);
8407 : :
8408 : 298436 : q = multilib_matches_raw;
8409 : 298436 : while ((p = *q++) != (char *) 0)
8410 : 895308 : obstack_grow (&multilib_obstack, p, strlen (p));
8411 : :
8412 : 298436 : obstack_1grow (&multilib_obstack, 0);
8413 : 298436 : multilib_matches = XOBFINISH (&multilib_obstack, const char *);
8414 : :
8415 : 298436 : q = multilib_exclusions_raw;
8416 : 298436 : while ((p = *q++) != (char *) 0)
8417 : 298436 : obstack_grow (&multilib_obstack, p, strlen (p));
8418 : :
8419 : 298436 : obstack_1grow (&multilib_obstack, 0);
8420 : 298436 : multilib_exclusions = XOBFINISH (&multilib_obstack, const char *);
8421 : :
8422 : 298436 : q = multilib_reuse_raw;
8423 : 298436 : while ((p = *q++) != (char *) 0)
8424 : 298436 : obstack_grow (&multilib_obstack, p, strlen (p));
8425 : :
8426 : 298436 : obstack_1grow (&multilib_obstack, 0);
8427 : 298436 : multilib_reuse = XOBFINISH (&multilib_obstack, const char *);
8428 : :
8429 : 298436 : need_space = false;
8430 : 596872 : for (size_t i = 0; i < ARRAY_SIZE (multilib_defaults_raw); i++)
8431 : : {
8432 : 298436 : if (need_space)
8433 : 0 : obstack_1grow (&multilib_obstack, ' ');
8434 : 298436 : obstack_grow (&multilib_obstack,
8435 : : multilib_defaults_raw[i],
8436 : : strlen (multilib_defaults_raw[i]));
8437 : 298436 : need_space = true;
8438 : : }
8439 : :
8440 : 298436 : obstack_1grow (&multilib_obstack, 0);
8441 : 298436 : multilib_defaults = XOBFINISH (&multilib_obstack, const char *);
8442 : : }
8443 : 298436 : }
8444 : :
8445 : : /* Set up the spec-handling machinery. */
8446 : :
8447 : : void
8448 : 298436 : driver::set_up_specs () const
8449 : : {
8450 : 298436 : const char *spec_machine_suffix;
8451 : 298436 : char *specs_file;
8452 : 298436 : size_t i;
8453 : :
8454 : : #ifdef INIT_ENVIRONMENT
8455 : : /* Set up any other necessary machine specific environment variables. */
8456 : : xputenv (INIT_ENVIRONMENT);
8457 : : #endif
8458 : :
8459 : : /* Make a table of what switches there are (switches, n_switches).
8460 : : Make a table of specified input files (infiles, n_infiles).
8461 : : Decode switches that are handled locally. */
8462 : :
8463 : 298436 : process_command (decoded_options_count, decoded_options);
8464 : :
8465 : : /* Initialize the vector of specs to just the default.
8466 : : This means one element containing 0s, as a terminator. */
8467 : :
8468 : 298150 : compilers = XNEWVAR (struct compiler, sizeof default_compilers);
8469 : 298150 : memcpy (compilers, default_compilers, sizeof default_compilers);
8470 : 298150 : n_compilers = n_default_compilers;
8471 : :
8472 : : /* Read specs from a file if there is one. */
8473 : :
8474 : 298150 : machine_suffix = concat (spec_host_machine, dir_separator_str, spec_version,
8475 : : accel_dir_suffix, dir_separator_str, NULL);
8476 : 298150 : just_machine_suffix = concat (spec_machine, dir_separator_str, NULL);
8477 : :
8478 : 298150 : specs_file = find_a_file (&startfile_prefixes, "specs", R_OK, true);
8479 : : /* Read the specs file unless it is a default one. */
8480 : 298150 : if (specs_file != 0 && strcmp (specs_file, "specs"))
8481 : 297028 : read_specs (specs_file, true, false);
8482 : : else
8483 : 1122 : init_spec ();
8484 : :
8485 : : #ifdef ACCEL_COMPILER
8486 : : spec_machine_suffix = machine_suffix;
8487 : : #else
8488 : 298150 : spec_machine_suffix = just_machine_suffix;
8489 : : #endif
8490 : :
8491 : 298150 : const char *exec_prefix
8492 : 298150 : = gcc_exec_prefix ? gcc_exec_prefix : standard_exec_prefix;
8493 : : /* We need to check standard_exec_prefix/spec_machine_suffix/specs
8494 : : for any override of as, ld and libraries. */
8495 : 298150 : specs_file = (char *) alloca (
8496 : : strlen (exec_prefix) + strlen (spec_machine_suffix) + sizeof ("specs"));
8497 : 298150 : strcpy (specs_file, exec_prefix);
8498 : 298150 : strcat (specs_file, spec_machine_suffix);
8499 : 298150 : strcat (specs_file, "specs");
8500 : 298150 : if (access (specs_file, R_OK) == 0)
8501 : 0 : read_specs (specs_file, true, false);
8502 : :
8503 : : /* Process any configure-time defaults specified for the command line
8504 : : options, via OPTION_DEFAULT_SPECS. */
8505 : 3279650 : for (i = 0; i < ARRAY_SIZE (option_default_specs); i++)
8506 : 2981500 : do_option_spec (option_default_specs[i].name,
8507 : 2981500 : option_default_specs[i].spec);
8508 : :
8509 : : /* Process DRIVER_SELF_SPECS, adding any new options to the end
8510 : : of the command line. */
8511 : :
8512 : 2087050 : for (i = 0; i < ARRAY_SIZE (driver_self_specs); i++)
8513 : 1788900 : do_self_spec (driver_self_specs[i]);
8514 : :
8515 : : /* If not cross-compiling, look for executables in the standard
8516 : : places. */
8517 : 298150 : if (*cross_compile == '0')
8518 : : {
8519 : 298150 : if (*md_exec_prefix)
8520 : : {
8521 : 0 : add_prefix (&exec_prefixes, md_exec_prefix, "GCC",
8522 : : PREFIX_PRIORITY_LAST, 0, 0);
8523 : : }
8524 : : }
8525 : :
8526 : : /* Process sysroot_suffix_spec. */
8527 : 298150 : if (*sysroot_suffix_spec != 0
8528 : 0 : && !no_sysroot_suffix
8529 : 298150 : && do_spec_2 (sysroot_suffix_spec, NULL) == 0)
8530 : : {
8531 : 0 : if (argbuf.length () > 1)
8532 : 0 : error ("spec failure: more than one argument to "
8533 : : "%<SYSROOT_SUFFIX_SPEC%>");
8534 : 0 : else if (argbuf.length () == 1)
8535 : 0 : target_sysroot_suffix = xstrdup (argbuf.last ());
8536 : : }
8537 : :
8538 : : #ifdef HAVE_LD_SYSROOT
8539 : : /* Pass the --sysroot option to the linker, if it supports that. If
8540 : : there is a sysroot_suffix_spec, it has already been processed by
8541 : : this point, so target_system_root really is the system root we
8542 : : should be using. */
8543 : 298150 : if (target_system_root)
8544 : : {
8545 : 0 : obstack_grow (&obstack, "%(sysroot_spec) ", strlen ("%(sysroot_spec) "));
8546 : 0 : obstack_grow0 (&obstack, link_spec, strlen (link_spec));
8547 : 0 : set_spec ("link", XOBFINISH (&obstack, const char *), false);
8548 : : }
8549 : : #endif
8550 : :
8551 : : /* Process sysroot_hdrs_suffix_spec. */
8552 : 298150 : if (*sysroot_hdrs_suffix_spec != 0
8553 : 0 : && !no_sysroot_suffix
8554 : 298150 : && do_spec_2 (sysroot_hdrs_suffix_spec, NULL) == 0)
8555 : : {
8556 : 0 : if (argbuf.length () > 1)
8557 : 0 : error ("spec failure: more than one argument "
8558 : : "to %<SYSROOT_HEADERS_SUFFIX_SPEC%>");
8559 : 0 : else if (argbuf.length () == 1)
8560 : 0 : target_sysroot_hdrs_suffix = xstrdup (argbuf.last ());
8561 : : }
8562 : :
8563 : : /* Look for startfiles in the standard places. */
8564 : 298150 : if (*startfile_prefix_spec != 0
8565 : 0 : && do_spec_2 (startfile_prefix_spec, NULL) == 0
8566 : 298150 : && do_spec_1 (" ", 0, NULL) == 0)
8567 : : {
8568 : 0 : for (const char *arg : argbuf)
8569 : 0 : add_sysrooted_prefix (&startfile_prefixes, arg, "BINUTILS",
8570 : : PREFIX_PRIORITY_LAST, 0, 1);
8571 : : }
8572 : : /* We should eventually get rid of all these and stick to
8573 : : startfile_prefix_spec exclusively. */
8574 : 298150 : else if (*cross_compile == '0' || target_system_root)
8575 : : {
8576 : 298150 : if (*md_startfile_prefix)
8577 : 0 : add_sysrooted_prefix (&startfile_prefixes, md_startfile_prefix,
8578 : : "GCC", PREFIX_PRIORITY_LAST, 0, 1);
8579 : :
8580 : 298150 : if (*md_startfile_prefix_1)
8581 : 0 : add_sysrooted_prefix (&startfile_prefixes, md_startfile_prefix_1,
8582 : : "GCC", PREFIX_PRIORITY_LAST, 0, 1);
8583 : :
8584 : : /* If standard_startfile_prefix is relative, base it on
8585 : : standard_exec_prefix. This lets us move the installed tree
8586 : : as a unit. If GCC_EXEC_PREFIX is defined, base
8587 : : standard_startfile_prefix on that as well.
8588 : :
8589 : : If the prefix is relative, only search it for native compilers;
8590 : : otherwise we will search a directory containing host libraries. */
8591 : 298150 : if (IS_ABSOLUTE_PATH (standard_startfile_prefix))
8592 : : add_sysrooted_prefix (&startfile_prefixes,
8593 : : standard_startfile_prefix, "BINUTILS",
8594 : : PREFIX_PRIORITY_LAST, 0, 1);
8595 : 298150 : else if (*cross_compile == '0')
8596 : : {
8597 : 298150 : add_prefix (&startfile_prefixes,
8598 : 596300 : concat (gcc_exec_prefix
8599 : : ? gcc_exec_prefix : standard_exec_prefix,
8600 : : machine_suffix,
8601 : : standard_startfile_prefix, NULL),
8602 : : NULL, PREFIX_PRIORITY_LAST, 0, 1);
8603 : : }
8604 : :
8605 : : /* Sysrooted prefixes are relocated because target_system_root is
8606 : : also relocated by gcc_exec_prefix. */
8607 : 298150 : if (*standard_startfile_prefix_1)
8608 : 298150 : add_sysrooted_prefix (&startfile_prefixes,
8609 : : standard_startfile_prefix_1, "BINUTILS",
8610 : : PREFIX_PRIORITY_LAST, 0, 1);
8611 : 298150 : if (*standard_startfile_prefix_2)
8612 : 298150 : add_sysrooted_prefix (&startfile_prefixes,
8613 : : standard_startfile_prefix_2, "BINUTILS",
8614 : : PREFIX_PRIORITY_LAST, 0, 1);
8615 : : }
8616 : :
8617 : : /* Process any user specified specs in the order given on the command
8618 : : line. */
8619 : 298152 : for (struct user_specs *uptr = user_specs_head; uptr; uptr = uptr->next)
8620 : : {
8621 : 3 : char *filename = find_a_file (&startfile_prefixes, uptr->filename,
8622 : : R_OK, true);
8623 : 3 : read_specs (filename ? filename : uptr->filename, false, true);
8624 : : }
8625 : :
8626 : : /* Process any user self specs. */
8627 : 298149 : {
8628 : 298149 : struct spec_list *sl;
8629 : 14013003 : for (sl = specs; sl; sl = sl->next)
8630 : 13714854 : if (sl->name_len == sizeof "self_spec" - 1
8631 : 2087043 : && !strcmp (sl->name, "self_spec"))
8632 : 298149 : do_self_spec (*sl->ptr_spec);
8633 : : }
8634 : :
8635 : 298149 : if (compare_debug)
8636 : : {
8637 : 619 : enum save_temps save;
8638 : :
8639 : 619 : if (!compare_debug_second)
8640 : : {
8641 : 619 : n_switches_debug_check[1] = n_switches;
8642 : 619 : n_switches_alloc_debug_check[1] = n_switches_alloc;
8643 : 619 : switches_debug_check[1] = XDUPVEC (struct switchstr, switches,
8644 : : n_switches_alloc);
8645 : :
8646 : 619 : do_self_spec ("%:compare-debug-self-opt()");
8647 : 619 : n_switches_debug_check[0] = n_switches;
8648 : 619 : n_switches_alloc_debug_check[0] = n_switches_alloc;
8649 : 619 : switches_debug_check[0] = switches;
8650 : :
8651 : 619 : n_switches = n_switches_debug_check[1];
8652 : 619 : n_switches_alloc = n_switches_alloc_debug_check[1];
8653 : 619 : switches = switches_debug_check[1];
8654 : : }
8655 : :
8656 : : /* Avoid crash when computing %j in this early. */
8657 : 619 : save = save_temps_flag;
8658 : 619 : save_temps_flag = SAVE_TEMPS_NONE;
8659 : :
8660 : 619 : compare_debug = -compare_debug;
8661 : 619 : do_self_spec ("%:compare-debug-self-opt()");
8662 : :
8663 : 619 : save_temps_flag = save;
8664 : :
8665 : 619 : if (!compare_debug_second)
8666 : : {
8667 : 619 : n_switches_debug_check[1] = n_switches;
8668 : 619 : n_switches_alloc_debug_check[1] = n_switches_alloc;
8669 : 619 : switches_debug_check[1] = switches;
8670 : 619 : compare_debug = -compare_debug;
8671 : 619 : n_switches = n_switches_debug_check[0];
8672 : 619 : n_switches_alloc = n_switches_debug_check[0];
8673 : 619 : switches = switches_debug_check[0];
8674 : : }
8675 : : }
8676 : :
8677 : :
8678 : : /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
8679 : 298149 : if (gcc_exec_prefix)
8680 : 298149 : gcc_exec_prefix = concat (gcc_exec_prefix, spec_host_machine,
8681 : : dir_separator_str, spec_version,
8682 : : accel_dir_suffix, dir_separator_str, NULL);
8683 : :
8684 : : /* Now we have the specs.
8685 : : Set the `valid' bits for switches that match anything in any spec. */
8686 : :
8687 : 298149 : validate_all_switches ();
8688 : :
8689 : : /* Now that we have the switches and the specs, set
8690 : : the subdirectory based on the options. */
8691 : 298149 : set_multilib_dir ();
8692 : 298149 : }
8693 : :
8694 : : /* Set up to remember the pathname of gcc and any options
8695 : : needed for collect. We use argv[0] instead of progname because
8696 : : we need the complete pathname. */
8697 : :
8698 : : void
8699 : 298149 : driver::putenv_COLLECT_GCC (const char *argv0) const
8700 : : {
8701 : 298149 : obstack_init (&collect_obstack);
8702 : 298149 : obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=") - 1);
8703 : 298149 : obstack_grow (&collect_obstack, argv0, strlen (argv0) + 1);
8704 : 298149 : xputenv (XOBFINISH (&collect_obstack, char *));
8705 : 298149 : }
8706 : :
8707 : : /* Set up to remember the pathname of the lto wrapper. */
8708 : :
8709 : : void
8710 : 298149 : driver::maybe_putenv_COLLECT_LTO_WRAPPER () const
8711 : : {
8712 : 298149 : char *lto_wrapper_file;
8713 : :
8714 : 298149 : if (have_c)
8715 : : lto_wrapper_file = NULL;
8716 : : else
8717 : 109304 : lto_wrapper_file = find_a_program ("lto-wrapper");
8718 : 109304 : if (lto_wrapper_file)
8719 : : {
8720 : 214104 : lto_wrapper_file = convert_white_space (lto_wrapper_file);
8721 : 107052 : set_static_spec_owned (<o_wrapper_spec, lto_wrapper_file);
8722 : 107052 : obstack_init (&collect_obstack);
8723 : 107052 : obstack_grow (&collect_obstack, "COLLECT_LTO_WRAPPER=",
8724 : : sizeof ("COLLECT_LTO_WRAPPER=") - 1);
8725 : 107052 : obstack_grow (&collect_obstack, lto_wrapper_spec,
8726 : : strlen (lto_wrapper_spec) + 1);
8727 : 107052 : xputenv (XOBFINISH (&collect_obstack, char *));
8728 : : }
8729 : :
8730 : 298149 : }
8731 : :
8732 : : /* Set up to remember the names of offload targets. */
8733 : :
8734 : : void
8735 : 298149 : driver::maybe_putenv_OFFLOAD_TARGETS () const
8736 : : {
8737 : 298149 : if (offload_targets && offload_targets[0] != '\0')
8738 : : {
8739 : 0 : obstack_grow (&collect_obstack, "OFFLOAD_TARGET_NAMES=",
8740 : : sizeof ("OFFLOAD_TARGET_NAMES=") - 1);
8741 : 0 : obstack_grow (&collect_obstack, offload_targets,
8742 : : strlen (offload_targets) + 1);
8743 : 0 : xputenv (XOBFINISH (&collect_obstack, char *));
8744 : : #if OFFLOAD_DEFAULTED
8745 : : if (offload_targets_default)
8746 : : xputenv ("OFFLOAD_TARGET_DEFAULT=1");
8747 : : #endif
8748 : : }
8749 : :
8750 : 298149 : free (offload_targets);
8751 : 298149 : offload_targets = NULL;
8752 : 298149 : }
8753 : :
8754 : : /* Reject switches that no pass was interested in. */
8755 : :
8756 : : void
8757 : 298149 : driver::handle_unrecognized_options ()
8758 : : {
8759 : 7028863 : for (size_t i = 0; (int) i < n_switches; i++)
8760 : 6730714 : if (! switches[i].validated)
8761 : : {
8762 : 608 : const char *hint = m_option_proposer.suggest_option (switches[i].part1);
8763 : 608 : if (hint)
8764 : 211 : error ("unrecognized command-line option %<-%s%>;"
8765 : : " did you mean %<-%s%>?",
8766 : 211 : switches[i].part1, hint);
8767 : : else
8768 : 397 : error ("unrecognized command-line option %<-%s%>",
8769 : 397 : switches[i].part1);
8770 : : }
8771 : 298149 : }
8772 : :
8773 : : /* Handle the various -print-* options, returning 0 if the driver
8774 : : should exit, or nonzero if the driver should continue. */
8775 : :
8776 : : int
8777 : 298144 : driver::maybe_print_and_exit () const
8778 : : {
8779 : 298144 : if (print_search_dirs)
8780 : : {
8781 : 56 : printf (_("install: %s%s\n"),
8782 : : gcc_exec_prefix ? gcc_exec_prefix : standard_exec_prefix,
8783 : 28 : gcc_exec_prefix ? "" : machine_suffix);
8784 : 28 : printf (_("programs: %s\n"),
8785 : : build_search_list (&exec_prefixes, "", false, false));
8786 : 28 : printf (_("libraries: %s\n"),
8787 : : build_search_list (&startfile_prefixes, "", false, true));
8788 : 28 : return (0);
8789 : : }
8790 : :
8791 : 298116 : if (print_file_name)
8792 : : {
8793 : 3802 : printf ("%s\n", find_file (print_file_name));
8794 : 3802 : return (0);
8795 : : }
8796 : :
8797 : 294314 : if (print_prog_name)
8798 : : {
8799 : 106 : if (use_ld != NULL && ! strcmp (print_prog_name, "ld"))
8800 : : {
8801 : : /* Append USE_LD to the default linker. */
8802 : : #ifdef DEFAULT_LINKER
8803 : : char *ld;
8804 : : # ifdef HAVE_HOST_EXECUTABLE_SUFFIX
8805 : : int len = (sizeof (DEFAULT_LINKER)
8806 : : - sizeof (HOST_EXECUTABLE_SUFFIX));
8807 : : ld = NULL;
8808 : : if (len > 0)
8809 : : {
8810 : : char *default_linker = xstrdup (DEFAULT_LINKER);
8811 : : /* Strip HOST_EXECUTABLE_SUFFIX if DEFAULT_LINKER contains
8812 : : HOST_EXECUTABLE_SUFFIX. */
8813 : : if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
8814 : : {
8815 : : default_linker[len] = '\0';
8816 : : ld = concat (default_linker, use_ld,
8817 : : HOST_EXECUTABLE_SUFFIX, NULL);
8818 : : }
8819 : : }
8820 : : if (ld == NULL)
8821 : : # endif
8822 : : ld = concat (DEFAULT_LINKER, use_ld, NULL);
8823 : : if (access (ld, X_OK) == 0)
8824 : : {
8825 : : printf ("%s\n", ld);
8826 : : return (0);
8827 : : }
8828 : : #endif
8829 : 0 : print_prog_name = concat (print_prog_name, use_ld, NULL);
8830 : : }
8831 : 106 : char *newname = find_a_program (print_prog_name);
8832 : 106 : printf ("%s\n", (newname ? newname : print_prog_name));
8833 : 106 : return (0);
8834 : : }
8835 : :
8836 : 294208 : if (print_multi_lib)
8837 : : {
8838 : 4306 : print_multilib_info ();
8839 : 4306 : return (0);
8840 : : }
8841 : :
8842 : 289902 : if (print_multi_directory)
8843 : : {
8844 : 3701 : if (multilib_dir == NULL)
8845 : 3676 : printf (".\n");
8846 : : else
8847 : 25 : printf ("%s\n", multilib_dir);
8848 : 3701 : return (0);
8849 : : }
8850 : :
8851 : 286201 : if (print_multiarch)
8852 : : {
8853 : 0 : if (multiarch_dir == NULL)
8854 : 0 : printf ("\n");
8855 : : else
8856 : 0 : printf ("%s\n", multiarch_dir);
8857 : 0 : return (0);
8858 : : }
8859 : :
8860 : 286201 : if (print_sysroot)
8861 : : {
8862 : 0 : if (target_system_root)
8863 : : {
8864 : 0 : if (target_sysroot_suffix)
8865 : 0 : printf ("%s%s\n", target_system_root, target_sysroot_suffix);
8866 : : else
8867 : 0 : printf ("%s\n", target_system_root);
8868 : : }
8869 : 0 : return (0);
8870 : : }
8871 : :
8872 : 286201 : if (print_multi_os_directory)
8873 : : {
8874 : 149 : if (multilib_os_dir == NULL)
8875 : 0 : printf (".\n");
8876 : : else
8877 : 149 : printf ("%s\n", multilib_os_dir);
8878 : 149 : return (0);
8879 : : }
8880 : :
8881 : 286052 : if (print_sysroot_headers_suffix)
8882 : : {
8883 : 1 : if (*sysroot_hdrs_suffix_spec)
8884 : : {
8885 : 0 : printf("%s\n", (target_sysroot_hdrs_suffix
8886 : : ? target_sysroot_hdrs_suffix
8887 : : : ""));
8888 : 0 : return (0);
8889 : : }
8890 : : else
8891 : : /* The error status indicates that only one set of fixed
8892 : : headers should be built. */
8893 : 1 : fatal_error (input_location,
8894 : : "not configured with sysroot headers suffix");
8895 : : }
8896 : :
8897 : 286051 : if (print_help_list)
8898 : : {
8899 : 4 : display_help ();
8900 : :
8901 : 4 : if (! verbose_flag)
8902 : : {
8903 : 1 : printf (_("\nFor bug reporting instructions, please see:\n"));
8904 : 1 : printf ("%s.\n", bug_report_url);
8905 : :
8906 : 1 : return (0);
8907 : : }
8908 : :
8909 : : /* We do not exit here. Instead we have created a fake input file
8910 : : called 'help-dummy' which needs to be compiled, and we pass this
8911 : : on the various sub-processes, along with the --help switch.
8912 : : Ensure their output appears after ours. */
8913 : 3 : fputc ('\n', stdout);
8914 : 3 : fflush (stdout);
8915 : : }
8916 : :
8917 : 286050 : if (print_version)
8918 : : {
8919 : 78 : printf (_("%s %s%s\n"), progname, pkgversion_string,
8920 : : version_string);
8921 : 78 : printf ("Copyright %s 2025 Free Software Foundation, Inc.\n",
8922 : : _("(C)"));
8923 : 78 : fputs (_("This is free software; see the source for copying conditions. There is NO\n\
8924 : : warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"),
8925 : : stdout);
8926 : 78 : if (! verbose_flag)
8927 : : return 0;
8928 : :
8929 : : /* We do not exit here. We use the same mechanism of --help to print
8930 : : the version of the sub-processes. */
8931 : 0 : fputc ('\n', stdout);
8932 : 0 : fflush (stdout);
8933 : : }
8934 : :
8935 : 285972 : if (verbose_flag)
8936 : : {
8937 : 1471 : print_configuration (stderr);
8938 : 1471 : if (n_infiles == 0)
8939 : : return (0);
8940 : : }
8941 : :
8942 : : return 1;
8943 : : }
8944 : :
8945 : : /* Figure out what to do with each input file.
8946 : : Return true if we need to exit early from "main", false otherwise. */
8947 : :
8948 : : bool
8949 : 285294 : driver::prepare_infiles ()
8950 : : {
8951 : 285294 : size_t i;
8952 : 285294 : int lang_n_infiles = 0;
8953 : :
8954 : 285294 : if (n_infiles == added_libraries)
8955 : 194 : fatal_error (input_location, "no input files");
8956 : :
8957 : 285100 : if (seen_error ())
8958 : : /* Early exit needed from main. */
8959 : : return true;
8960 : :
8961 : : /* Make a place to record the compiler output file names
8962 : : that correspond to the input files. */
8963 : :
8964 : 284610 : i = n_infiles;
8965 : 284610 : i += lang_specific_extra_outfiles;
8966 : 284610 : outfiles = XCNEWVEC (const char *, i);
8967 : :
8968 : : /* Record which files were specified explicitly as link input. */
8969 : :
8970 : 284610 : explicit_link_files = XCNEWVEC (char, n_infiles);
8971 : :
8972 : 284610 : combine_inputs = have_o || flag_wpa;
8973 : :
8974 : 838180 : for (i = 0; (int) i < n_infiles; i++)
8975 : : {
8976 : 553570 : const char *name = infiles[i].name;
8977 : 553570 : struct compiler *compiler = lookup_compiler (name,
8978 : : strlen (name),
8979 : : infiles[i].language);
8980 : :
8981 : 553570 : if (compiler && !(compiler->combinable))
8982 : 254343 : combine_inputs = false;
8983 : :
8984 : 553570 : if (lang_n_infiles > 0 && compiler != input_file_compiler
8985 : 247205 : && infiles[i].language && infiles[i].language[0] != '*')
8986 : 33 : infiles[i].incompiler = compiler;
8987 : 553537 : else if (compiler)
8988 : : {
8989 : 295599 : lang_n_infiles++;
8990 : 295599 : input_file_compiler = compiler;
8991 : 295599 : infiles[i].incompiler = compiler;
8992 : : }
8993 : : else
8994 : : {
8995 : : /* Since there is no compiler for this input file, assume it is a
8996 : : linker file. */
8997 : 257938 : explicit_link_files[i] = 1;
8998 : 257938 : infiles[i].incompiler = NULL;
8999 : : }
9000 : 553570 : infiles[i].compiled = false;
9001 : 553570 : infiles[i].preprocessed = false;
9002 : : }
9003 : :
9004 : 284610 : if (!combine_inputs && have_c && have_o && lang_n_infiles > 1)
9005 : 0 : fatal_error (input_location,
9006 : : "cannot specify %<-o%> with %<-c%>, %<-S%> or %<-E%> "
9007 : : "with multiple files");
9008 : :
9009 : : /* No early exit needed from main; we can continue. */
9010 : : return false;
9011 : : }
9012 : :
9013 : : /* Run the spec machinery on each input file. */
9014 : :
9015 : : void
9016 : 284610 : driver::do_spec_on_infiles () const
9017 : : {
9018 : 284610 : size_t i;
9019 : :
9020 : 838180 : for (i = 0; (int) i < n_infiles; i++)
9021 : : {
9022 : 553570 : int this_file_error = 0;
9023 : :
9024 : : /* Tell do_spec what to substitute for %i. */
9025 : :
9026 : 553570 : input_file_number = i;
9027 : 553570 : set_input (infiles[i].name);
9028 : :
9029 : 553570 : if (infiles[i].compiled)
9030 : 9101 : continue;
9031 : :
9032 : : /* Use the same thing in %o, unless cp->spec says otherwise. */
9033 : :
9034 : 544469 : outfiles[i] = gcc_input_filename;
9035 : :
9036 : : /* Figure out which compiler from the file's suffix. */
9037 : :
9038 : 544469 : input_file_compiler
9039 : 544469 : = lookup_compiler (infiles[i].name, input_filename_length,
9040 : : infiles[i].language);
9041 : :
9042 : 544469 : if (input_file_compiler)
9043 : : {
9044 : : /* Ok, we found an applicable compiler. Run its spec. */
9045 : :
9046 : 286531 : if (input_file_compiler->spec[0] == '#')
9047 : : {
9048 : 0 : error ("%s: %s compiler not installed on this system",
9049 : : gcc_input_filename, &input_file_compiler->spec[1]);
9050 : 0 : this_file_error = 1;
9051 : : }
9052 : : else
9053 : : {
9054 : 286531 : int value;
9055 : :
9056 : 286531 : if (compare_debug)
9057 : : {
9058 : 617 : free (debug_check_temp_file[0]);
9059 : 617 : debug_check_temp_file[0] = NULL;
9060 : :
9061 : 617 : free (debug_check_temp_file[1]);
9062 : 617 : debug_check_temp_file[1] = NULL;
9063 : : }
9064 : :
9065 : 286531 : value = do_spec (input_file_compiler->spec);
9066 : 286531 : infiles[i].compiled = true;
9067 : 286531 : if (value < 0)
9068 : : this_file_error = 1;
9069 : 257402 : else if (compare_debug && debug_check_temp_file[0])
9070 : : {
9071 : 613 : if (verbose_flag)
9072 : 0 : inform (UNKNOWN_LOCATION,
9073 : : "recompiling with %<-fcompare-debug%>");
9074 : :
9075 : 613 : compare_debug = -compare_debug;
9076 : 613 : n_switches = n_switches_debug_check[1];
9077 : 613 : n_switches_alloc = n_switches_alloc_debug_check[1];
9078 : 613 : switches = switches_debug_check[1];
9079 : :
9080 : 613 : value = do_spec (input_file_compiler->spec);
9081 : :
9082 : 613 : compare_debug = -compare_debug;
9083 : 613 : n_switches = n_switches_debug_check[0];
9084 : 613 : n_switches_alloc = n_switches_alloc_debug_check[0];
9085 : 613 : switches = switches_debug_check[0];
9086 : :
9087 : 613 : if (value < 0)
9088 : : {
9089 : 2 : error ("during %<-fcompare-debug%> recompilation");
9090 : 2 : this_file_error = 1;
9091 : : }
9092 : :
9093 : 613 : gcc_assert (debug_check_temp_file[1]
9094 : : && filename_cmp (debug_check_temp_file[0],
9095 : : debug_check_temp_file[1]));
9096 : :
9097 : 613 : if (verbose_flag)
9098 : 0 : inform (UNKNOWN_LOCATION, "comparing final insns dumps");
9099 : :
9100 : 613 : if (compare_files (debug_check_temp_file))
9101 : 29160 : this_file_error = 1;
9102 : : }
9103 : :
9104 : 286531 : if (compare_debug)
9105 : : {
9106 : 617 : free (debug_check_temp_file[0]);
9107 : 617 : debug_check_temp_file[0] = NULL;
9108 : :
9109 : 617 : free (debug_check_temp_file[1]);
9110 : 617 : debug_check_temp_file[1] = NULL;
9111 : : }
9112 : : }
9113 : : }
9114 : :
9115 : : /* If this file's name does not contain a recognized suffix,
9116 : : record it as explicit linker input. */
9117 : :
9118 : : else
9119 : 257938 : explicit_link_files[i] = 1;
9120 : :
9121 : : /* Clear the delete-on-failure queue, deleting the files in it
9122 : : if this compilation failed. */
9123 : :
9124 : 544469 : if (this_file_error)
9125 : : {
9126 : 29160 : delete_failure_queue ();
9127 : 29160 : errorcount++;
9128 : : }
9129 : : /* If this compilation succeeded, don't delete those files later. */
9130 : 544469 : clear_failure_queue ();
9131 : : }
9132 : :
9133 : : /* Reset the input file name to the first compile/object file name, for use
9134 : : with %b in LINK_SPEC. We use the first input file that we can find
9135 : : a compiler to compile it instead of using infiles.language since for
9136 : : languages other than C we use aliases that we then lookup later. */
9137 : 284610 : if (n_infiles > 0)
9138 : : {
9139 : : int i;
9140 : :
9141 : 296775 : for (i = 0; i < n_infiles ; i++)
9142 : 294888 : if (infiles[i].incompiler
9143 : 12165 : || (infiles[i].language && infiles[i].language[0] != '*'))
9144 : : {
9145 : 282723 : set_input (infiles[i].name);
9146 : 282723 : break;
9147 : : }
9148 : : }
9149 : :
9150 : 284610 : if (!seen_error ())
9151 : : {
9152 : : /* Make sure INPUT_FILE_NUMBER points to first available open
9153 : : slot. */
9154 : 255450 : input_file_number = n_infiles;
9155 : 255450 : if (lang_specific_pre_link ())
9156 : 0 : errorcount++;
9157 : : }
9158 : 284610 : }
9159 : :
9160 : : /* If we have to run the linker, do it now. */
9161 : :
9162 : : void
9163 : 284610 : driver::maybe_run_linker (const char *argv0) const
9164 : : {
9165 : 284610 : size_t i;
9166 : 284610 : int linker_was_run = 0;
9167 : 284610 : int num_linker_inputs;
9168 : :
9169 : : /* Determine if there are any linker input files. */
9170 : 284610 : num_linker_inputs = 0;
9171 : 838180 : for (i = 0; (int) i < n_infiles; i++)
9172 : 553570 : if (explicit_link_files[i] || outfiles[i] != NULL)
9173 : 544017 : num_linker_inputs++;
9174 : :
9175 : : /* Arrange for temporary file names created during linking to take
9176 : : on names related with the linker output rather than with the
9177 : : inputs when appropriate. */
9178 : 284610 : if (outbase && *outbase)
9179 : : {
9180 : 261531 : if (dumpdir)
9181 : : {
9182 : 88247 : char *tofree = dumpdir;
9183 : 88247 : gcc_checking_assert (strlen (dumpdir) == dumpdir_length);
9184 : 88247 : dumpdir = concat (dumpdir, outbase, ".", NULL);
9185 : 88247 : free (tofree);
9186 : : }
9187 : : else
9188 : 173284 : dumpdir = concat (outbase, ".", NULL);
9189 : 261531 : dumpdir_length += strlen (outbase) + 1;
9190 : 261531 : dumpdir_trailing_dash_added = true;
9191 : 261531 : }
9192 : 23079 : else if (dumpdir_trailing_dash_added)
9193 : : {
9194 : 18151 : gcc_assert (dumpdir[dumpdir_length - 1] == '-');
9195 : 18151 : dumpdir[dumpdir_length - 1] = '.';
9196 : : }
9197 : :
9198 : 284610 : if (dumpdir_trailing_dash_added)
9199 : : {
9200 : 279682 : gcc_assert (dumpdir_length > 0);
9201 : 279682 : gcc_assert (dumpdir[dumpdir_length - 1] == '.');
9202 : 279682 : dumpdir_length--;
9203 : : }
9204 : :
9205 : 284610 : free (outbase);
9206 : 284610 : input_basename = outbase = NULL;
9207 : 284610 : outbase_length = suffixed_basename_length = basename_length = 0;
9208 : :
9209 : : /* Run ld to link all the compiler output files. */
9210 : :
9211 : 284610 : if (num_linker_inputs > 0 && !seen_error () && print_subprocess_help < 2)
9212 : : {
9213 : 254904 : int tmp = execution_count;
9214 : :
9215 : 254904 : detect_jobserver ();
9216 : :
9217 : 254904 : if (! have_c)
9218 : : {
9219 : : #if HAVE_LTO_PLUGIN > 0
9220 : : #if HAVE_LTO_PLUGIN == 2
9221 : 96080 : const char *fno_use_linker_plugin = "fno-use-linker-plugin";
9222 : : #else
9223 : : const char *fuse_linker_plugin = "fuse-linker-plugin";
9224 : : #endif
9225 : : #endif
9226 : :
9227 : : /* We'll use ld if we can't find collect2. */
9228 : 96080 : if (! strcmp (linker_name_spec, "collect2"))
9229 : : {
9230 : 96080 : char *s = find_a_program ("collect2");
9231 : 96080 : if (s == NULL)
9232 : 1129 : set_static_spec_shared (&linker_name_spec, "ld");
9233 : : }
9234 : :
9235 : : #if HAVE_LTO_PLUGIN > 0
9236 : : #if HAVE_LTO_PLUGIN == 2
9237 : 96080 : if (!switch_matches (fno_use_linker_plugin,
9238 : : fno_use_linker_plugin
9239 : : + strlen (fno_use_linker_plugin), 0))
9240 : : #else
9241 : : if (switch_matches (fuse_linker_plugin,
9242 : : fuse_linker_plugin
9243 : : + strlen (fuse_linker_plugin), 0))
9244 : : #endif
9245 : : {
9246 : 90627 : char *temp_spec = find_a_file (&exec_prefixes,
9247 : : LTOPLUGINSONAME, R_OK,
9248 : : false);
9249 : 90627 : if (!temp_spec)
9250 : 0 : fatal_error (input_location,
9251 : : "%<-fuse-linker-plugin%>, but %s not found",
9252 : : LTOPLUGINSONAME);
9253 : 90627 : linker_plugin_file_spec = convert_white_space (temp_spec);
9254 : : }
9255 : : #endif
9256 : 96080 : set_static_spec_shared (<o_gcc_spec, argv0);
9257 : : }
9258 : :
9259 : : /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
9260 : : for collect. */
9261 : 254904 : putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH", false);
9262 : 254904 : putenv_from_prefixes (&startfile_prefixes, LIBRARY_PATH_ENV, true);
9263 : :
9264 : 254904 : if (print_subprocess_help == 1)
9265 : : {
9266 : 0 : printf (_("\nLinker options\n==============\n\n"));
9267 : 0 : printf (_("Use \"-Wl,OPTION\" to pass \"OPTION\""
9268 : : " to the linker.\n\n"));
9269 : 0 : fflush (stdout);
9270 : : }
9271 : 254904 : int value = do_spec (link_command_spec);
9272 : 254904 : if (value < 0)
9273 : 138 : errorcount = 1;
9274 : 254904 : linker_was_run = (tmp != execution_count);
9275 : : }
9276 : :
9277 : : /* If options said don't run linker,
9278 : : complain about input files to be given to the linker. */
9279 : :
9280 : 284610 : if (! linker_was_run && !seen_error ())
9281 : 350114 : for (i = 0; (int) i < n_infiles; i++)
9282 : 190740 : if (explicit_link_files[i]
9283 : 22283 : && !(infiles[i].language && infiles[i].language[0] == '*'))
9284 : : {
9285 : 38 : warning (0, "%s: linker input file unused because linking not done",
9286 : 19 : outfiles[i]);
9287 : 19 : if (access (outfiles[i], F_OK) < 0)
9288 : : /* This is can be an indication the user specifed an errorneous
9289 : : separated option value, (or used the wrong prefix for an
9290 : : option). */
9291 : 7 : error ("%s: linker input file not found: %m", outfiles[i]);
9292 : : }
9293 : 284610 : }
9294 : :
9295 : : /* The end of "main". */
9296 : :
9297 : : void
9298 : 284610 : driver::final_actions () const
9299 : : {
9300 : : /* Delete some or all of the temporary files we made. */
9301 : :
9302 : 284610 : if (seen_error ())
9303 : 29303 : delete_failure_queue ();
9304 : 284610 : delete_temp_files ();
9305 : :
9306 : 284610 : if (totruncate_file != NULL && !seen_error ())
9307 : : /* Truncate file specified by -truncate.
9308 : : Used by lto-wrapper to reduce temporary disk-space usage. */
9309 : 9127 : truncate(totruncate_file, 0);
9310 : :
9311 : 284610 : if (print_help_list)
9312 : : {
9313 : 3 : printf (("\nFor bug reporting instructions, please see:\n"));
9314 : 3 : printf ("%s\n", bug_report_url);
9315 : : }
9316 : 284610 : }
9317 : :
9318 : : /* Detect whether jobserver is active and working. If not drop
9319 : : --jobserver-auth from MAKEFLAGS. */
9320 : :
9321 : : void
9322 : 254904 : driver::detect_jobserver () const
9323 : : {
9324 : 254904 : jobserver_info jinfo;
9325 : 254904 : if (!jinfo.is_active && !jinfo.skipped_makeflags.empty ())
9326 : 0 : xputenv (xstrdup (jinfo.skipped_makeflags.c_str ()));
9327 : 254904 : }
9328 : :
9329 : : /* Determine what the exit code of the driver should be. */
9330 : :
9331 : : int
9332 : 285100 : driver::get_exit_code () const
9333 : : {
9334 : 285100 : return (signal_count != 0 ? 2
9335 : 285100 : : seen_error () ? (pass_exit_codes ? greatest_status : 1)
9336 : 0 : : 0);
9337 : : }
9338 : :
9339 : : /* Find the proper compilation spec for the file name NAME,
9340 : : whose length is LENGTH. LANGUAGE is the specified language,
9341 : : or 0 if this file is to be passed to the linker. */
9342 : :
9343 : : static struct compiler *
9344 : 1098039 : lookup_compiler (const char *name, size_t length, const char *language)
9345 : : {
9346 : 1604996 : struct compiler *cp;
9347 : :
9348 : : /* If this was specified by the user to be a linker input, indicate that. */
9349 : 1604996 : if (language != 0 && language[0] == '*')
9350 : : return 0;
9351 : :
9352 : : /* Otherwise, look for the language, if one is spec'd. */
9353 : 1137034 : if (language != 0)
9354 : : {
9355 : 23022292 : for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
9356 : 23022292 : if (cp->suffix[0] == '@' && !strcmp (cp->suffix + 1, language))
9357 : : {
9358 : 582149 : if (name != NULL && strcmp (name, "-") == 0
9359 : 2074 : && (strcmp (cp->suffix, "@c-header") == 0
9360 : 2074 : || strcmp (cp->suffix, "@c++-header") == 0)
9361 : 0 : && !have_E)
9362 : 0 : fatal_error (input_location,
9363 : : "cannot use %<-%> as input filename for a "
9364 : : "precompiled header");
9365 : :
9366 : : return cp;
9367 : : }
9368 : :
9369 : 0 : error ("language %s not recognized", language);
9370 : 0 : return 0;
9371 : : }
9372 : :
9373 : : /* Look for a suffix. */
9374 : 30550297 : for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
9375 : : {
9376 : 30502383 : if (/* The suffix `-' matches only the file name `-'. */
9377 : 30502383 : (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
9378 : 30502369 : || (strlen (cp->suffix) < length
9379 : : /* See if the suffix matches the end of NAME. */
9380 : 30080102 : && !strcmp (cp->suffix,
9381 : 30080102 : name + length - strlen (cp->suffix))
9382 : : ))
9383 : : break;
9384 : : }
9385 : :
9386 : : #if defined (OS2) ||defined (HAVE_DOS_BASED_FILE_SYSTEM)
9387 : : /* Look again, but case-insensitively this time. */
9388 : : if (cp < compilers)
9389 : : for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
9390 : : {
9391 : : if (/* The suffix `-' matches only the file name `-'. */
9392 : : (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
9393 : : || (strlen (cp->suffix) < length
9394 : : /* See if the suffix matches the end of NAME. */
9395 : : && ((!strcmp (cp->suffix,
9396 : : name + length - strlen (cp->suffix))
9397 : : || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
9398 : : && !strcasecmp (cp->suffix,
9399 : : name + length - strlen (cp->suffix)))
9400 : : ))
9401 : : break;
9402 : : }
9403 : : #endif
9404 : :
9405 : 554885 : if (cp >= compilers)
9406 : : {
9407 : 506971 : if (cp->spec[0] != '@')
9408 : : /* A non-alias entry: return it. */
9409 : : return cp;
9410 : :
9411 : : /* An alias entry maps a suffix to a language.
9412 : : Search for the language; pass 0 for NAME and LENGTH
9413 : : to avoid infinite recursion if language not found. */
9414 : 506957 : return lookup_compiler (NULL, 0, cp->spec + 1);
9415 : : }
9416 : : return 0;
9417 : : }
9418 : :
9419 : : static char *
9420 : 46408335 : save_string (const char *s, int len)
9421 : : {
9422 : 46408335 : char *result = XNEWVEC (char, len + 1);
9423 : :
9424 : 46408335 : gcc_checking_assert (strlen (s) >= (unsigned int) len);
9425 : 46408335 : memcpy (result, s, len);
9426 : 46408335 : result[len] = 0;
9427 : 46408335 : return result;
9428 : : }
9429 : :
9430 : :
9431 : : static inline void
9432 : 45914946 : validate_switches_from_spec (const char *spec, bool user)
9433 : : {
9434 : 45914946 : const char *p = spec;
9435 : 45914946 : char c;
9436 : 569166444 : while ((c = *p++))
9437 : 477336552 : if (c == '%'
9438 : 477336552 : && (*p == '{'
9439 : 11329662 : || *p == '<'
9440 : 10435215 : || (*p == 'W' && *++p == '{')
9441 : 10435215 : || (*p == '@' && *++p == '{')))
9442 : : /* We have a switch spec. */
9443 : 45318650 : p = validate_switches (p + 1, user, *p == '{');
9444 : 45914946 : }
9445 : :
9446 : : static void
9447 : 298149 : validate_all_switches (void)
9448 : : {
9449 : 298149 : struct compiler *comp;
9450 : 298149 : struct spec_list *spec;
9451 : :
9452 : 32200092 : for (comp = compilers; comp->spec; comp++)
9453 : 31901943 : validate_switches_from_spec (comp->spec, false);
9454 : :
9455 : : /* Look through the linked list of specs read from the specs file. */
9456 : 14013003 : for (spec = specs; spec; spec = spec->next)
9457 : 13714854 : validate_switches_from_spec (*spec->ptr_spec, spec->user_p);
9458 : :
9459 : 298149 : validate_switches_from_spec (link_command_spec, false);
9460 : 298149 : }
9461 : :
9462 : : /* Look at the switch-name that comes after START and mark as valid
9463 : : all supplied switches that match it. If BRACED, handle other
9464 : : switches after '|' and '&', and specs after ':' until ';' or '}',
9465 : : going back for more switches after ';'. Without BRACED, handle
9466 : : only one atom. Return a pointer to whatever follows the handled
9467 : : items, after the closing brace if BRACED. */
9468 : :
9469 : : static const char *
9470 : 193796852 : validate_switches (const char *start, bool user_spec, bool braced)
9471 : : {
9472 : 193796852 : const char *p = start;
9473 : 250147013 : const char *atom;
9474 : 250147013 : size_t len;
9475 : 250147013 : int i;
9476 : 250147013 : bool suffix;
9477 : 250147013 : bool starred;
9478 : :
9479 : : #define SKIP_WHITE() do { while (*p == ' ' || *p == '\t') p++; } while (0)
9480 : :
9481 : 250147013 : next_member:
9482 : 250147013 : suffix = false;
9483 : 250147013 : starred = false;
9484 : :
9485 : 276980423 : SKIP_WHITE ();
9486 : :
9487 : 250147013 : if (*p == '!')
9488 : 76326145 : p++;
9489 : :
9490 : 250147013 : SKIP_WHITE ();
9491 : 250147013 : if (*p == '.' || *p == ',')
9492 : 0 : suffix = true, p++;
9493 : :
9494 : 250147013 : atom = p;
9495 : 250147013 : while (ISIDNUM (*p) || *p == '-' || *p == '+' || *p == '='
9496 : 1659199201 : || *p == ',' || *p == '.' || *p == '@')
9497 : 1409052188 : p++;
9498 : 250147013 : len = p - atom;
9499 : :
9500 : 250147013 : if (*p == '*')
9501 : 65592780 : starred = true, p++;
9502 : :
9503 : 251339609 : SKIP_WHITE ();
9504 : :
9505 : 250147013 : if (!suffix)
9506 : : {
9507 : : /* Mark all matching switches as valid. */
9508 : 5897216089 : for (i = 0; i < n_switches; i++)
9509 : 5647069076 : if (!strncmp (switches[i].part1, atom, len)
9510 : 480750699 : && (starred || switches[i].part1[len] == '\0')
9511 : 49905300 : && (switches[i].known || user_spec))
9512 : 49902780 : switches[i].validated = true;
9513 : : }
9514 : :
9515 : 250147013 : if (!braced)
9516 : : return p;
9517 : :
9518 : 248656268 : if (*p) p++;
9519 : 248656268 : if (*p && (p[-1] == '|' || p[-1] == '&'))
9520 : 38163072 : goto next_member;
9521 : :
9522 : 210493196 : if (*p && p[-1] == ':')
9523 : : {
9524 : 2807370980 : while (*p && *p != ';' && *p != '}')
9525 : : {
9526 : 2646072368 : if (*p == '%')
9527 : : {
9528 : 247761819 : p++;
9529 : 247761819 : if (*p == '{' || *p == '<')
9530 : 145794861 : p = validate_switches (p+1, user_spec, *p == '{');
9531 : 101966958 : else if (p[0] == 'W' && p[1] == '{')
9532 : 2385192 : p = validate_switches (p+2, user_spec, true);
9533 : 99581766 : else if (p[0] == '@' && p[1] == '{')
9534 : 298149 : p = validate_switches (p+2, user_spec, true);
9535 : : }
9536 : : else
9537 : 2398310549 : p++;
9538 : : }
9539 : :
9540 : 161298612 : if (*p) p++;
9541 : 161298612 : if (*p && p[-1] == ';')
9542 : 18187089 : goto next_member;
9543 : : }
9544 : :
9545 : : return p;
9546 : : #undef SKIP_WHITE
9547 : : }
9548 : :
9549 : : struct mdswitchstr
9550 : : {
9551 : : const char *str;
9552 : : int len;
9553 : : };
9554 : :
9555 : : static struct mdswitchstr *mdswitches;
9556 : : static int n_mdswitches;
9557 : :
9558 : : /* Check whether a particular argument was used. The first time we
9559 : : canonicalize the switches to keep only the ones we care about. */
9560 : :
9561 : : struct used_arg_t
9562 : : {
9563 : : public:
9564 : : int operator () (const char *p, int len);
9565 : : void finalize ();
9566 : :
9567 : : private:
9568 : : struct mswitchstr
9569 : : {
9570 : : const char *str;
9571 : : const char *replace;
9572 : : int len;
9573 : : int rep_len;
9574 : : };
9575 : :
9576 : : mswitchstr *mswitches;
9577 : : int n_mswitches;
9578 : :
9579 : : };
9580 : :
9581 : : used_arg_t used_arg;
9582 : :
9583 : : int
9584 : 1802283 : used_arg_t::operator () (const char *p, int len)
9585 : : {
9586 : 1802283 : int i, j;
9587 : :
9588 : 1802283 : if (!mswitches)
9589 : : {
9590 : 298149 : struct mswitchstr *matches;
9591 : 298149 : const char *q;
9592 : 298149 : int cnt = 0;
9593 : :
9594 : : /* Break multilib_matches into the component strings of string
9595 : : and replacement string. */
9596 : 5068533 : for (q = multilib_matches; *q != '\0'; q++)
9597 : 4770384 : if (*q == ';')
9598 : 596298 : cnt++;
9599 : :
9600 : 298149 : matches
9601 : 298149 : = (struct mswitchstr *) alloca ((sizeof (struct mswitchstr)) * cnt);
9602 : 298149 : i = 0;
9603 : 298149 : q = multilib_matches;
9604 : 894447 : while (*q != '\0')
9605 : : {
9606 : 596298 : matches[i].str = q;
9607 : 2385192 : while (*q != ' ')
9608 : : {
9609 : 1788894 : if (*q == '\0')
9610 : : {
9611 : 0 : invalid_matches:
9612 : 0 : fatal_error (input_location, "multilib spec %qs is invalid",
9613 : : multilib_matches);
9614 : : }
9615 : 1788894 : q++;
9616 : : }
9617 : 596298 : matches[i].len = q - matches[i].str;
9618 : :
9619 : 596298 : matches[i].replace = ++q;
9620 : 2385192 : while (*q != ';' && *q != '\0')
9621 : : {
9622 : 1788894 : if (*q == ' ')
9623 : 0 : goto invalid_matches;
9624 : 1788894 : q++;
9625 : : }
9626 : 596298 : matches[i].rep_len = q - matches[i].replace;
9627 : 596298 : i++;
9628 : 596298 : if (*q == ';')
9629 : 596298 : q++;
9630 : : }
9631 : :
9632 : : /* Now build a list of the replacement string for switches that we care
9633 : : about. Make sure we allocate at least one entry. This prevents
9634 : : xmalloc from calling fatal, and prevents us from re-executing this
9635 : : block of code. */
9636 : 298149 : mswitches
9637 : 596298 : = XNEWVEC (struct mswitchstr, n_mdswitches + (n_switches ? n_switches : 1));
9638 : 7028863 : for (i = 0; i < n_switches; i++)
9639 : 6730714 : if ((switches[i].live_cond & SWITCH_IGNORE) == 0)
9640 : : {
9641 : 6730708 : int xlen = strlen (switches[i].part1);
9642 : 20179342 : for (j = 0; j < cnt; j++)
9643 : 13458981 : if (xlen == matches[j].len
9644 : 19079 : && ! strncmp (switches[i].part1, matches[j].str, xlen))
9645 : : {
9646 : 10347 : mswitches[n_mswitches].str = matches[j].replace;
9647 : 10347 : mswitches[n_mswitches].len = matches[j].rep_len;
9648 : 10347 : mswitches[n_mswitches].replace = (char *) 0;
9649 : 10347 : mswitches[n_mswitches].rep_len = 0;
9650 : 10347 : n_mswitches++;
9651 : 10347 : break;
9652 : : }
9653 : : }
9654 : :
9655 : : /* Add MULTILIB_DEFAULTS switches too, as long as they were not present
9656 : : on the command line nor any options mutually incompatible with
9657 : : them. */
9658 : 596298 : for (i = 0; i < n_mdswitches; i++)
9659 : : {
9660 : 298149 : const char *r;
9661 : :
9662 : 596298 : for (q = multilib_options; *q != '\0'; *q && q++)
9663 : : {
9664 : 298149 : while (*q == ' ')
9665 : 0 : q++;
9666 : :
9667 : 298149 : r = q;
9668 : 298149 : while (strncmp (q, mdswitches[i].str, mdswitches[i].len) != 0
9669 : 298149 : || strchr (" /", q[mdswitches[i].len]) == NULL)
9670 : : {
9671 : 0 : while (*q != ' ' && *q != '/' && *q != '\0')
9672 : 0 : q++;
9673 : 0 : if (*q != '/')
9674 : : break;
9675 : 0 : q++;
9676 : : }
9677 : :
9678 : 298149 : if (*q != ' ' && *q != '\0')
9679 : : {
9680 : 593863 : while (*r != ' ' && *r != '\0')
9681 : : {
9682 : : q = r;
9683 : 2375452 : while (*q != ' ' && *q != '/' && *q != '\0')
9684 : 1781589 : q++;
9685 : :
9686 : 593863 : if (used_arg (r, q - r))
9687 : : break;
9688 : :
9689 : 583516 : if (*q != '/')
9690 : : {
9691 : 287802 : mswitches[n_mswitches].str = mdswitches[i].str;
9692 : 287802 : mswitches[n_mswitches].len = mdswitches[i].len;
9693 : 287802 : mswitches[n_mswitches].replace = (char *) 0;
9694 : 287802 : mswitches[n_mswitches].rep_len = 0;
9695 : 287802 : n_mswitches++;
9696 : 287802 : break;
9697 : : }
9698 : :
9699 : 295714 : r = q + 1;
9700 : : }
9701 : : break;
9702 : : }
9703 : : }
9704 : : }
9705 : : }
9706 : :
9707 : 2414405 : for (i = 0; i < n_mswitches; i++)
9708 : 1226679 : if (len == mswitches[i].len && ! strncmp (p, mswitches[i].str, len))
9709 : : return 1;
9710 : :
9711 : : return 0;
9712 : : }
9713 : :
9714 : 1134 : void used_arg_t::finalize ()
9715 : : {
9716 : 1134 : XDELETEVEC (mswitches);
9717 : 1134 : mswitches = NULL;
9718 : 1134 : n_mswitches = 0;
9719 : 1134 : }
9720 : :
9721 : :
9722 : : static int
9723 : 1225644 : default_arg (const char *p, int len)
9724 : : {
9725 : 1225644 : int i;
9726 : :
9727 : 1834160 : for (i = 0; i < n_mdswitches; i++)
9728 : 1225644 : if (len == mdswitches[i].len && ! strncmp (p, mdswitches[i].str, len))
9729 : : return 1;
9730 : :
9731 : : return 0;
9732 : : }
9733 : :
9734 : : /* Use multilib_dir as key to find corresponding multilib_os_dir and
9735 : : multiarch_dir. */
9736 : :
9737 : : static void
9738 : 0 : find_multilib_os_dir_by_multilib_dir (const char *multilib_dir,
9739 : : const char **p_multilib_os_dir,
9740 : : const char **p_multiarch_dir)
9741 : : {
9742 : 0 : const char *p = multilib_select;
9743 : 0 : unsigned int this_path_len;
9744 : 0 : const char *this_path;
9745 : 0 : int ok = 0;
9746 : :
9747 : 0 : while (*p != '\0')
9748 : : {
9749 : : /* Ignore newlines. */
9750 : 0 : if (*p == '\n')
9751 : : {
9752 : 0 : ++p;
9753 : 0 : continue;
9754 : : }
9755 : :
9756 : : /* Get the initial path. */
9757 : : this_path = p;
9758 : 0 : while (*p != ' ')
9759 : : {
9760 : 0 : if (*p == '\0')
9761 : : {
9762 : 0 : fatal_error (input_location, "multilib select %qs %qs is invalid",
9763 : : multilib_select, multilib_reuse);
9764 : : }
9765 : 0 : ++p;
9766 : : }
9767 : 0 : this_path_len = p - this_path;
9768 : :
9769 : 0 : ok = 0;
9770 : :
9771 : : /* Skip any arguments, we don't care at this stage. */
9772 : 0 : while (*++p != ';');
9773 : :
9774 : 0 : if (this_path_len != 1
9775 : 0 : || this_path[0] != '.')
9776 : : {
9777 : 0 : char *new_multilib_dir = XNEWVEC (char, this_path_len + 1);
9778 : 0 : char *q;
9779 : :
9780 : 0 : strncpy (new_multilib_dir, this_path, this_path_len);
9781 : 0 : new_multilib_dir[this_path_len] = '\0';
9782 : 0 : q = strchr (new_multilib_dir, ':');
9783 : 0 : if (q != NULL)
9784 : 0 : *q = '\0';
9785 : :
9786 : 0 : if (strcmp (new_multilib_dir, multilib_dir) == 0)
9787 : 0 : ok = 1;
9788 : : }
9789 : :
9790 : : /* Found matched multilib_dir, update multilib_os_dir and
9791 : : multiarch_dir. */
9792 : 0 : if (ok)
9793 : : {
9794 : 0 : const char *q = this_path, *end = this_path + this_path_len;
9795 : :
9796 : 0 : while (q < end && *q != ':')
9797 : 0 : q++;
9798 : 0 : if (q < end)
9799 : : {
9800 : 0 : const char *q2 = q + 1, *ml_end = end;
9801 : 0 : char *new_multilib_os_dir;
9802 : :
9803 : 0 : while (q2 < end && *q2 != ':')
9804 : 0 : q2++;
9805 : 0 : if (*q2 == ':')
9806 : 0 : ml_end = q2;
9807 : 0 : if (ml_end - q == 1)
9808 : 0 : *p_multilib_os_dir = xstrdup (".");
9809 : : else
9810 : : {
9811 : 0 : new_multilib_os_dir = XNEWVEC (char, ml_end - q);
9812 : 0 : memcpy (new_multilib_os_dir, q + 1, ml_end - q - 1);
9813 : 0 : new_multilib_os_dir[ml_end - q - 1] = '\0';
9814 : 0 : *p_multilib_os_dir = new_multilib_os_dir;
9815 : : }
9816 : :
9817 : 0 : if (q2 < end && *q2 == ':')
9818 : : {
9819 : 0 : char *new_multiarch_dir = XNEWVEC (char, end - q2);
9820 : 0 : memcpy (new_multiarch_dir, q2 + 1, end - q2 - 1);
9821 : 0 : new_multiarch_dir[end - q2 - 1] = '\0';
9822 : 0 : *p_multiarch_dir = new_multiarch_dir;
9823 : : }
9824 : : break;
9825 : : }
9826 : : }
9827 : 0 : ++p;
9828 : : }
9829 : 0 : }
9830 : :
9831 : : /* Work out the subdirectory to use based on the options. The format of
9832 : : multilib_select is a list of elements. Each element is a subdirectory
9833 : : name followed by a list of options followed by a semicolon. The format
9834 : : of multilib_exclusions is the same, but without the preceding
9835 : : directory. First gcc will check the exclusions, if none of the options
9836 : : beginning with an exclamation point are present, and all of the other
9837 : : options are present, then we will ignore this completely. Passing
9838 : : that, gcc will consider each multilib_select in turn using the same
9839 : : rules for matching the options. If a match is found, that subdirectory
9840 : : will be used.
9841 : : A subdirectory name is optionally followed by a colon and the corresponding
9842 : : multiarch name. */
9843 : :
9844 : : static void
9845 : 298149 : set_multilib_dir (void)
9846 : : {
9847 : 298149 : const char *p;
9848 : 298149 : unsigned int this_path_len;
9849 : 298149 : const char *this_path, *this_arg;
9850 : 298149 : const char *start, *end;
9851 : 298149 : int not_arg;
9852 : 298149 : int ok, ndfltok, first;
9853 : :
9854 : 298149 : n_mdswitches = 0;
9855 : 298149 : start = multilib_defaults;
9856 : 298149 : while (*start == ' ' || *start == '\t')
9857 : 0 : start++;
9858 : 596298 : while (*start != '\0')
9859 : : {
9860 : 298149 : n_mdswitches++;
9861 : 1192596 : while (*start != ' ' && *start != '\t' && *start != '\0')
9862 : 894447 : start++;
9863 : 298149 : while (*start == ' ' || *start == '\t')
9864 : 0 : start++;
9865 : : }
9866 : :
9867 : 298149 : if (n_mdswitches)
9868 : : {
9869 : 298149 : int i = 0;
9870 : :
9871 : 298149 : mdswitches = XNEWVEC (struct mdswitchstr, n_mdswitches);
9872 : 298149 : for (start = multilib_defaults; *start != '\0'; start = end + 1)
9873 : : {
9874 : 298149 : while (*start == ' ' || *start == '\t')
9875 : 0 : start++;
9876 : :
9877 : 298149 : if (*start == '\0')
9878 : : break;
9879 : :
9880 : 894447 : for (end = start + 1;
9881 : 894447 : *end != ' ' && *end != '\t' && *end != '\0'; end++)
9882 : : ;
9883 : :
9884 : 298149 : obstack_grow (&multilib_obstack, start, end - start);
9885 : 298149 : obstack_1grow (&multilib_obstack, 0);
9886 : 298149 : mdswitches[i].str = XOBFINISH (&multilib_obstack, const char *);
9887 : 298149 : mdswitches[i++].len = end - start;
9888 : :
9889 : 298149 : if (*end == '\0')
9890 : : break;
9891 : : }
9892 : : }
9893 : :
9894 : 298149 : p = multilib_exclusions;
9895 : 298149 : while (*p != '\0')
9896 : : {
9897 : : /* Ignore newlines. */
9898 : 0 : if (*p == '\n')
9899 : : {
9900 : 0 : ++p;
9901 : 0 : continue;
9902 : : }
9903 : :
9904 : : /* Check the arguments. */
9905 : : ok = 1;
9906 : 0 : while (*p != ';')
9907 : : {
9908 : 0 : if (*p == '\0')
9909 : : {
9910 : 0 : invalid_exclusions:
9911 : 0 : fatal_error (input_location, "multilib exclusions %qs is invalid",
9912 : : multilib_exclusions);
9913 : : }
9914 : :
9915 : 0 : if (! ok)
9916 : : {
9917 : 0 : ++p;
9918 : 0 : continue;
9919 : : }
9920 : :
9921 : 0 : this_arg = p;
9922 : 0 : while (*p != ' ' && *p != ';')
9923 : : {
9924 : 0 : if (*p == '\0')
9925 : 0 : goto invalid_exclusions;
9926 : 0 : ++p;
9927 : : }
9928 : :
9929 : 0 : if (*this_arg != '!')
9930 : : not_arg = 0;
9931 : : else
9932 : : {
9933 : 0 : not_arg = 1;
9934 : 0 : ++this_arg;
9935 : : }
9936 : :
9937 : 0 : ok = used_arg (this_arg, p - this_arg);
9938 : 0 : if (not_arg)
9939 : 0 : ok = ! ok;
9940 : :
9941 : 0 : if (*p == ' ')
9942 : 0 : ++p;
9943 : : }
9944 : :
9945 : 0 : if (ok)
9946 : : return;
9947 : :
9948 : 0 : ++p;
9949 : : }
9950 : :
9951 : 298149 : first = 1;
9952 : 298149 : p = multilib_select;
9953 : :
9954 : : /* Append multilib reuse rules if any. With those rules, we can reuse
9955 : : one multilib for certain different options sets. */
9956 : 298149 : if (strlen (multilib_reuse) > 0)
9957 : 0 : p = concat (p, multilib_reuse, NULL);
9958 : :
9959 : 604210 : while (*p != '\0')
9960 : : {
9961 : : /* Ignore newlines. */
9962 : 604210 : if (*p == '\n')
9963 : : {
9964 : 0 : ++p;
9965 : 0 : continue;
9966 : : }
9967 : :
9968 : : /* Get the initial path. */
9969 : : this_path = p;
9970 : 4253206 : while (*p != ' ')
9971 : : {
9972 : 3648996 : if (*p == '\0')
9973 : : {
9974 : 0 : invalid_select:
9975 : 0 : fatal_error (input_location, "multilib select %qs %qs is invalid",
9976 : : multilib_select, multilib_reuse);
9977 : : }
9978 : 3648996 : ++p;
9979 : : }
9980 : 604210 : this_path_len = p - this_path;
9981 : :
9982 : : /* Check the arguments. */
9983 : 604210 : ok = 1;
9984 : 604210 : ndfltok = 1;
9985 : 604210 : ++p;
9986 : 1812630 : while (*p != ';')
9987 : : {
9988 : 1208420 : if (*p == '\0')
9989 : 0 : goto invalid_select;
9990 : :
9991 : 1208420 : if (! ok)
9992 : : {
9993 : 0 : ++p;
9994 : 0 : continue;
9995 : : }
9996 : :
9997 : 5736039 : this_arg = p;
9998 : 5736039 : while (*p != ' ' && *p != ';')
9999 : : {
10000 : 4527619 : if (*p == '\0')
10001 : 0 : goto invalid_select;
10002 : 4527619 : ++p;
10003 : : }
10004 : :
10005 : 1208420 : if (*this_arg != '!')
10006 : : not_arg = 0;
10007 : : else
10008 : : {
10009 : 902359 : not_arg = 1;
10010 : 902359 : ++this_arg;
10011 : : }
10012 : :
10013 : : /* If this is a default argument, we can just ignore it.
10014 : : This is true even if this_arg begins with '!'. Beginning
10015 : : with '!' does not mean that this argument is necessarily
10016 : : inappropriate for this library: it merely means that
10017 : : there is a more specific library which uses this
10018 : : argument. If this argument is a default, we need not
10019 : : consider that more specific library. */
10020 : 1208420 : ok = used_arg (this_arg, p - this_arg);
10021 : 1208420 : if (not_arg)
10022 : 902359 : ok = ! ok;
10023 : :
10024 : 1208420 : if (! ok)
10025 : 313973 : ndfltok = 0;
10026 : :
10027 : 1208420 : if (default_arg (this_arg, p - this_arg))
10028 : 604210 : ok = 1;
10029 : :
10030 : 1208420 : if (*p == ' ')
10031 : 604210 : ++p;
10032 : : }
10033 : :
10034 : 604210 : if (ok && first)
10035 : : {
10036 : 298149 : if (this_path_len != 1
10037 : 290237 : || this_path[0] != '.')
10038 : : {
10039 : 7912 : char *new_multilib_dir = XNEWVEC (char, this_path_len + 1);
10040 : 7912 : char *q;
10041 : :
10042 : 7912 : strncpy (new_multilib_dir, this_path, this_path_len);
10043 : 7912 : new_multilib_dir[this_path_len] = '\0';
10044 : 7912 : q = strchr (new_multilib_dir, ':');
10045 : 7912 : if (q != NULL)
10046 : 7912 : *q = '\0';
10047 : 7912 : multilib_dir = new_multilib_dir;
10048 : : }
10049 : : first = 0;
10050 : : }
10051 : :
10052 : 604210 : if (ndfltok)
10053 : : {
10054 : 298149 : const char *q = this_path, *end = this_path + this_path_len;
10055 : :
10056 : 894447 : while (q < end && *q != ':')
10057 : 596298 : q++;
10058 : 298149 : if (q < end)
10059 : : {
10060 : 298149 : const char *q2 = q + 1, *ml_end = end;
10061 : 298149 : char *new_multilib_os_dir;
10062 : :
10063 : 2667517 : while (q2 < end && *q2 != ':')
10064 : 2369368 : q2++;
10065 : 298149 : if (*q2 == ':')
10066 : 0 : ml_end = q2;
10067 : 298149 : if (ml_end - q == 1)
10068 : 0 : multilib_os_dir = xstrdup (".");
10069 : : else
10070 : : {
10071 : 298149 : new_multilib_os_dir = XNEWVEC (char, ml_end - q);
10072 : 298149 : memcpy (new_multilib_os_dir, q + 1, ml_end - q - 1);
10073 : 298149 : new_multilib_os_dir[ml_end - q - 1] = '\0';
10074 : 298149 : multilib_os_dir = new_multilib_os_dir;
10075 : : }
10076 : :
10077 : 298149 : if (q2 < end && *q2 == ':')
10078 : : {
10079 : 0 : char *new_multiarch_dir = XNEWVEC (char, end - q2);
10080 : 0 : memcpy (new_multiarch_dir, q2 + 1, end - q2 - 1);
10081 : 0 : new_multiarch_dir[end - q2 - 1] = '\0';
10082 : 0 : multiarch_dir = new_multiarch_dir;
10083 : : }
10084 : : break;
10085 : : }
10086 : : }
10087 : :
10088 : 306061 : ++p;
10089 : : }
10090 : :
10091 : 596298 : multilib_dir =
10092 : 298149 : targetm_common.compute_multilib (
10093 : : switches,
10094 : : n_switches,
10095 : : multilib_dir,
10096 : : multilib_defaults,
10097 : : multilib_select,
10098 : : multilib_matches,
10099 : : multilib_exclusions,
10100 : : multilib_reuse);
10101 : :
10102 : 298149 : if (multilib_dir == NULL && multilib_os_dir != NULL
10103 : 290237 : && strcmp (multilib_os_dir, ".") == 0)
10104 : : {
10105 : 0 : free (CONST_CAST (char *, multilib_os_dir));
10106 : 0 : multilib_os_dir = NULL;
10107 : : }
10108 : 298149 : else if (multilib_dir != NULL && multilib_os_dir == NULL)
10109 : : {
10110 : : /* Give second chance to search matched multilib_os_dir again by matching
10111 : : the multilib_dir since some target may use TARGET_COMPUTE_MULTILIB
10112 : : hook rather than the builtin way. */
10113 : 0 : find_multilib_os_dir_by_multilib_dir (multilib_dir, &multilib_os_dir,
10114 : : &multiarch_dir);
10115 : :
10116 : 0 : if (multilib_os_dir == NULL)
10117 : 0 : multilib_os_dir = multilib_dir;
10118 : : }
10119 : : }
10120 : :
10121 : : /* Print out the multiple library subdirectory selection
10122 : : information. This prints out a series of lines. Each line looks
10123 : : like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
10124 : : required. Only the desired options are printed out, the negative
10125 : : matches. The options are print without a leading dash. There are
10126 : : no spaces to make it easy to use the information in the shell.
10127 : : Each subdirectory is printed only once. This assumes the ordering
10128 : : generated by the genmultilib script. Also, we leave out ones that match
10129 : : the exclusions. */
10130 : :
10131 : : static void
10132 : 4306 : print_multilib_info (void)
10133 : : {
10134 : 4306 : const char *p = multilib_select;
10135 : 4306 : const char *last_path = 0, *this_path;
10136 : 4306 : int skip;
10137 : 4306 : int not_arg;
10138 : 4306 : unsigned int last_path_len = 0;
10139 : :
10140 : 17224 : while (*p != '\0')
10141 : : {
10142 : 12918 : skip = 0;
10143 : : /* Ignore newlines. */
10144 : 12918 : if (*p == '\n')
10145 : : {
10146 : 0 : ++p;
10147 : 0 : continue;
10148 : : }
10149 : :
10150 : : /* Get the initial path. */
10151 : : this_path = p;
10152 : 103344 : while (*p != ' ')
10153 : : {
10154 : 90426 : if (*p == '\0')
10155 : : {
10156 : 0 : invalid_select:
10157 : 0 : fatal_error (input_location,
10158 : : "multilib select %qs is invalid", multilib_select);
10159 : : }
10160 : :
10161 : 90426 : ++p;
10162 : : }
10163 : :
10164 : : /* When --disable-multilib was used but target defines
10165 : : MULTILIB_OSDIRNAMES, entries starting with .: (and not starting
10166 : : with .:: for multiarch configurations) are there just to find
10167 : : multilib_os_dir, so skip them from output. */
10168 : 12918 : if (this_path[0] == '.' && this_path[1] == ':' && this_path[2] != ':')
10169 : 12918 : skip = 1;
10170 : :
10171 : : /* Check for matches with the multilib_exclusions. We don't bother
10172 : : with the '!' in either list. If any of the exclusion rules match
10173 : : all of its options with the select rule, we skip it. */
10174 : 12918 : {
10175 : 12918 : const char *e = multilib_exclusions;
10176 : 12918 : const char *this_arg;
10177 : :
10178 : 12918 : while (*e != '\0')
10179 : : {
10180 : 0 : int m = 1;
10181 : : /* Ignore newlines. */
10182 : 0 : if (*e == '\n')
10183 : : {
10184 : 0 : ++e;
10185 : 0 : continue;
10186 : : }
10187 : :
10188 : : /* Check the arguments. */
10189 : 0 : while (*e != ';')
10190 : : {
10191 : 0 : const char *q;
10192 : 0 : int mp = 0;
10193 : :
10194 : 0 : if (*e == '\0')
10195 : : {
10196 : 0 : invalid_exclusion:
10197 : 0 : fatal_error (input_location,
10198 : : "multilib exclusion %qs is invalid",
10199 : : multilib_exclusions);
10200 : : }
10201 : :
10202 : 0 : if (! m)
10203 : : {
10204 : 0 : ++e;
10205 : 0 : continue;
10206 : : }
10207 : :
10208 : : this_arg = e;
10209 : :
10210 : 0 : while (*e != ' ' && *e != ';')
10211 : : {
10212 : 0 : if (*e == '\0')
10213 : 0 : goto invalid_exclusion;
10214 : 0 : ++e;
10215 : : }
10216 : :
10217 : 0 : q = p + 1;
10218 : 0 : while (*q != ';')
10219 : : {
10220 : 0 : const char *arg;
10221 : 0 : int len = e - this_arg;
10222 : :
10223 : 0 : if (*q == '\0')
10224 : 0 : goto invalid_select;
10225 : :
10226 : : arg = q;
10227 : :
10228 : 0 : while (*q != ' ' && *q != ';')
10229 : : {
10230 : 0 : if (*q == '\0')
10231 : 0 : goto invalid_select;
10232 : 0 : ++q;
10233 : : }
10234 : :
10235 : 0 : if (! strncmp (arg, this_arg,
10236 : 0 : (len < q - arg) ? q - arg : len)
10237 : 0 : || default_arg (this_arg, e - this_arg))
10238 : : {
10239 : : mp = 1;
10240 : : break;
10241 : : }
10242 : :
10243 : 0 : if (*q == ' ')
10244 : 0 : ++q;
10245 : : }
10246 : :
10247 : 0 : if (! mp)
10248 : 0 : m = 0;
10249 : :
10250 : 0 : if (*e == ' ')
10251 : 0 : ++e;
10252 : : }
10253 : :
10254 : 0 : if (m)
10255 : : {
10256 : : skip = 1;
10257 : : break;
10258 : : }
10259 : :
10260 : 0 : if (*e != '\0')
10261 : 0 : ++e;
10262 : : }
10263 : : }
10264 : :
10265 : 12918 : if (! skip)
10266 : : {
10267 : : /* If this is a duplicate, skip it. */
10268 : 25836 : skip = (last_path != 0
10269 : 8612 : && (unsigned int) (p - this_path) == last_path_len
10270 : 12918 : && ! filename_ncmp (last_path, this_path, last_path_len));
10271 : :
10272 : 12918 : last_path = this_path;
10273 : 12918 : last_path_len = p - this_path;
10274 : : }
10275 : :
10276 : : /* If all required arguments are default arguments, and no default
10277 : : arguments appear in the ! argument list, then we can skip it.
10278 : : We will already have printed a directory identical to this one
10279 : : which does not require that default argument. */
10280 : 12918 : if (! skip)
10281 : : {
10282 : 12918 : const char *q;
10283 : 12918 : bool default_arg_ok = false;
10284 : :
10285 : 12918 : q = p + 1;
10286 : 21530 : while (*q != ';')
10287 : : {
10288 : 17224 : const char *arg;
10289 : :
10290 : 17224 : if (*q == '\0')
10291 : 0 : goto invalid_select;
10292 : :
10293 : 17224 : if (*q == '!')
10294 : : {
10295 : 12918 : not_arg = 1;
10296 : 12918 : q++;
10297 : : }
10298 : : else
10299 : : not_arg = 0;
10300 : 17224 : arg = q;
10301 : :
10302 : 68896 : while (*q != ' ' && *q != ';')
10303 : : {
10304 : 51672 : if (*q == '\0')
10305 : 0 : goto invalid_select;
10306 : 51672 : ++q;
10307 : : }
10308 : :
10309 : 17224 : if (default_arg (arg, q - arg))
10310 : : {
10311 : : /* Stop checking if any default arguments appeared in not
10312 : : list. */
10313 : 12918 : if (not_arg)
10314 : : {
10315 : : default_arg_ok = false;
10316 : : break;
10317 : : }
10318 : :
10319 : : default_arg_ok = true;
10320 : : }
10321 : 4306 : else if (!not_arg)
10322 : : {
10323 : : /* Stop checking if any required argument is not provided by
10324 : : default arguments. */
10325 : : default_arg_ok = false;
10326 : : break;
10327 : : }
10328 : :
10329 : 8612 : if (*q == ' ')
10330 : 4306 : ++q;
10331 : : }
10332 : :
10333 : : /* Make sure all default argument is OK for this multi-lib set. */
10334 : 12918 : if (default_arg_ok)
10335 : : skip = 1;
10336 : : else
10337 : : skip = 0;
10338 : : }
10339 : :
10340 : : if (! skip)
10341 : : {
10342 : : const char *p1;
10343 : :
10344 : 21530 : for (p1 = last_path; p1 < p && *p1 != ':'; p1++)
10345 : 12918 : putchar (*p1);
10346 : 8612 : putchar (';');
10347 : : }
10348 : :
10349 : 12918 : ++p;
10350 : 64590 : while (*p != ';')
10351 : : {
10352 : 51672 : int use_arg;
10353 : :
10354 : 51672 : if (*p == '\0')
10355 : 0 : goto invalid_select;
10356 : :
10357 : 51672 : if (skip)
10358 : : {
10359 : 34448 : ++p;
10360 : 34448 : continue;
10361 : : }
10362 : :
10363 : 17224 : use_arg = *p != '!';
10364 : :
10365 : 17224 : if (use_arg)
10366 : 4306 : putchar ('@');
10367 : :
10368 : 81814 : while (*p != ' ' && *p != ';')
10369 : : {
10370 : 64590 : if (*p == '\0')
10371 : 0 : goto invalid_select;
10372 : 64590 : if (use_arg)
10373 : 12918 : putchar (*p);
10374 : 64590 : ++p;
10375 : : }
10376 : :
10377 : 17224 : if (*p == ' ')
10378 : 8612 : ++p;
10379 : : }
10380 : :
10381 : 12918 : if (! skip)
10382 : : {
10383 : : /* If there are extra options, print them now. */
10384 : 8612 : if (multilib_extra && *multilib_extra)
10385 : : {
10386 : : int print_at = true;
10387 : : const char *q;
10388 : :
10389 : 0 : for (q = multilib_extra; *q != '\0'; q++)
10390 : : {
10391 : 0 : if (*q == ' ')
10392 : : print_at = true;
10393 : : else
10394 : : {
10395 : 0 : if (print_at)
10396 : 0 : putchar ('@');
10397 : 0 : putchar (*q);
10398 : 0 : print_at = false;
10399 : : }
10400 : : }
10401 : : }
10402 : :
10403 : 8612 : putchar ('\n');
10404 : : }
10405 : :
10406 : 12918 : ++p;
10407 : : }
10408 : 4306 : }
10409 : :
10410 : : /* getenv built-in spec function.
10411 : :
10412 : : Returns the value of the environment variable given by its first argument,
10413 : : concatenated with the second argument. If the variable is not defined, a
10414 : : fatal error is issued unless such undefs are internally allowed, in which
10415 : : case the variable name prefixed by a '/' is used as the variable value.
10416 : :
10417 : : The leading '/' allows using the result at a spot where a full path would
10418 : : normally be expected and when the actual value doesn't really matter since
10419 : : undef vars are allowed. */
10420 : :
10421 : : static const char *
10422 : 0 : getenv_spec_function (int argc, const char **argv)
10423 : : {
10424 : 0 : const char *value;
10425 : 0 : const char *varname;
10426 : :
10427 : 0 : char *result;
10428 : 0 : char *ptr;
10429 : 0 : size_t len;
10430 : :
10431 : 0 : if (argc != 2)
10432 : : return NULL;
10433 : :
10434 : 0 : varname = argv[0];
10435 : 0 : value = env.get (varname);
10436 : :
10437 : : /* If the variable isn't defined and this is allowed, craft our expected
10438 : : return value. Assume variable names used in specs strings don't contain
10439 : : any active spec character so don't need escaping. */
10440 : 0 : if (!value && spec_undefvar_allowed)
10441 : : {
10442 : 0 : result = XNEWVAR (char, strlen(varname) + 2);
10443 : 0 : sprintf (result, "/%s", varname);
10444 : 0 : return result;
10445 : : }
10446 : :
10447 : 0 : if (!value)
10448 : 0 : fatal_error (input_location,
10449 : : "environment variable %qs not defined", varname);
10450 : :
10451 : : /* We have to escape every character of the environment variable so
10452 : : they are not interpreted as active spec characters. A
10453 : : particularly painful case is when we are reading a variable
10454 : : holding a windows path complete with \ separators. */
10455 : 0 : len = strlen (value) * 2 + strlen (argv[1]) + 1;
10456 : 0 : result = XNEWVAR (char, len);
10457 : 0 : for (ptr = result; *value; ptr += 2)
10458 : : {
10459 : 0 : ptr[0] = '\\';
10460 : 0 : ptr[1] = *value++;
10461 : : }
10462 : :
10463 : 0 : strcpy (ptr, argv[1]);
10464 : :
10465 : 0 : return result;
10466 : : }
10467 : :
10468 : : /* if-exists built-in spec function.
10469 : :
10470 : : Checks to see if the file specified by the absolute pathname in
10471 : : ARGS exists. Returns that pathname if found.
10472 : :
10473 : : The usual use for this function is to check for a library file
10474 : : (whose name has been expanded with %s). */
10475 : :
10476 : : static const char *
10477 : 0 : if_exists_spec_function (int argc, const char **argv)
10478 : : {
10479 : : /* Must have only one argument. */
10480 : 0 : if (argc == 1 && IS_ABSOLUTE_PATH (argv[0]) && ! access (argv[0], R_OK))
10481 : 0 : return argv[0];
10482 : :
10483 : : return NULL;
10484 : : }
10485 : :
10486 : : /* if-exists-else built-in spec function.
10487 : :
10488 : : This is like if-exists, but takes an additional argument which
10489 : : is returned if the first argument does not exist. */
10490 : :
10491 : : static const char *
10492 : 0 : if_exists_else_spec_function (int argc, const char **argv)
10493 : : {
10494 : : /* Must have exactly two arguments. */
10495 : 0 : if (argc != 2)
10496 : : return NULL;
10497 : :
10498 : 0 : if (IS_ABSOLUTE_PATH (argv[0]) && ! access (argv[0], R_OK))
10499 : 0 : return argv[0];
10500 : :
10501 : 0 : return argv[1];
10502 : : }
10503 : :
10504 : : /* if-exists-then-else built-in spec function.
10505 : :
10506 : : Checks to see if the file specified by the absolute pathname in
10507 : : the first arg exists. Returns the second arg if so, otherwise returns
10508 : : the third arg if it is present. */
10509 : :
10510 : : static const char *
10511 : 0 : if_exists_then_else_spec_function (int argc, const char **argv)
10512 : : {
10513 : :
10514 : : /* Must have two or three arguments. */
10515 : 0 : if (argc != 2 && argc != 3)
10516 : : return NULL;
10517 : :
10518 : 0 : if (IS_ABSOLUTE_PATH (argv[0]) && ! access (argv[0], R_OK))
10519 : 0 : return argv[1];
10520 : :
10521 : 0 : if (argc == 3)
10522 : 0 : return argv[2];
10523 : :
10524 : : return NULL;
10525 : : }
10526 : :
10527 : : /* sanitize built-in spec function.
10528 : :
10529 : : This returns non-NULL, if sanitizing address, thread or
10530 : : any of the undefined behavior sanitizers. */
10531 : :
10532 : : static const char *
10533 : 862812 : sanitize_spec_function (int argc, const char **argv)
10534 : : {
10535 : 862812 : if (argc != 1)
10536 : : return NULL;
10537 : :
10538 : 862812 : if (strcmp (argv[0], "address") == 0)
10539 : 380746 : return (flag_sanitize & SANITIZE_USER_ADDRESS) ? "" : NULL;
10540 : 671076 : if (strcmp (argv[0], "hwaddress") == 0)
10541 : 383154 : return (flag_sanitize & SANITIZE_USER_HWADDRESS) ? "" : NULL;
10542 : 479340 : if (strcmp (argv[0], "kernel-address") == 0)
10543 : 0 : return (flag_sanitize & SANITIZE_KERNEL_ADDRESS) ? "" : NULL;
10544 : 479340 : if (strcmp (argv[0], "kernel-hwaddress") == 0)
10545 : 0 : return (flag_sanitize & SANITIZE_KERNEL_HWADDRESS) ? "" : NULL;
10546 : 479340 : if (strcmp (argv[0], "thread") == 0)
10547 : 382948 : return (flag_sanitize & SANITIZE_THREAD) ? "" : NULL;
10548 : 287604 : if (strcmp (argv[0], "undefined") == 0)
10549 : 95868 : return ((flag_sanitize
10550 : 95868 : & ~flag_sanitize_trap
10551 : 95868 : & (SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT)))
10552 : 189861 : ? "" : NULL;
10553 : 191736 : if (strcmp (argv[0], "leak") == 0)
10554 : 191736 : return ((flag_sanitize
10555 : 191736 : & (SANITIZE_ADDRESS | SANITIZE_LEAK | SANITIZE_THREAD))
10556 : 383472 : == SANITIZE_LEAK) ? "" : NULL;
10557 : : return NULL;
10558 : : }
10559 : :
10560 : : /* replace-outfile built-in spec function.
10561 : :
10562 : : This looks for the first argument in the outfiles array's name and
10563 : : replaces it with the second argument. */
10564 : :
10565 : : static const char *
10566 : 0 : replace_outfile_spec_function (int argc, const char **argv)
10567 : : {
10568 : 0 : int i;
10569 : : /* Must have exactly two arguments. */
10570 : 0 : if (argc != 2)
10571 : 0 : abort ();
10572 : :
10573 : 0 : for (i = 0; i < n_infiles; i++)
10574 : : {
10575 : 0 : if (outfiles[i] && !filename_cmp (outfiles[i], argv[0]))
10576 : 0 : outfiles[i] = xstrdup (argv[1]);
10577 : : }
10578 : 0 : return NULL;
10579 : : }
10580 : :
10581 : : /* remove-outfile built-in spec function.
10582 : : *
10583 : : * This looks for the first argument in the outfiles array's name and
10584 : : * removes it. */
10585 : :
10586 : : static const char *
10587 : 0 : remove_outfile_spec_function (int argc, const char **argv)
10588 : : {
10589 : 0 : int i;
10590 : : /* Must have exactly one argument. */
10591 : 0 : if (argc != 1)
10592 : 0 : abort ();
10593 : :
10594 : 0 : for (i = 0; i < n_infiles; i++)
10595 : : {
10596 : 0 : if (outfiles[i] && !filename_cmp (outfiles[i], argv[0]))
10597 : 0 : outfiles[i] = NULL;
10598 : : }
10599 : 0 : return NULL;
10600 : : }
10601 : :
10602 : : /* Given two version numbers, compares the two numbers.
10603 : : A version number must match the regular expression
10604 : : ([1-9][0-9]*|0)(\.([1-9][0-9]*|0))*
10605 : : */
10606 : : static int
10607 : 0 : compare_version_strings (const char *v1, const char *v2)
10608 : : {
10609 : 0 : int rresult;
10610 : 0 : regex_t r;
10611 : :
10612 : 0 : if (regcomp (&r, "^([1-9][0-9]*|0)(\\.([1-9][0-9]*|0))*$",
10613 : : REG_EXTENDED | REG_NOSUB) != 0)
10614 : 0 : abort ();
10615 : 0 : rresult = regexec (&r, v1, 0, NULL, 0);
10616 : 0 : if (rresult == REG_NOMATCH)
10617 : 0 : fatal_error (input_location, "invalid version number %qs", v1);
10618 : 0 : else if (rresult != 0)
10619 : 0 : abort ();
10620 : 0 : rresult = regexec (&r, v2, 0, NULL, 0);
10621 : 0 : if (rresult == REG_NOMATCH)
10622 : 0 : fatal_error (input_location, "invalid version number %qs", v2);
10623 : 0 : else if (rresult != 0)
10624 : 0 : abort ();
10625 : :
10626 : 0 : return strverscmp (v1, v2);
10627 : : }
10628 : :
10629 : :
10630 : : /* version_compare built-in spec function.
10631 : :
10632 : : This takes an argument of the following form:
10633 : :
10634 : : <comparison-op> <arg1> [<arg2>] <switch> <result>
10635 : :
10636 : : and produces "result" if the comparison evaluates to true,
10637 : : and nothing if it doesn't.
10638 : :
10639 : : The supported <comparison-op> values are:
10640 : :
10641 : : >= true if switch is a later (or same) version than arg1
10642 : : !> opposite of >=
10643 : : < true if switch is an earlier version than arg1
10644 : : !< opposite of <
10645 : : >< true if switch is arg1 or later, and earlier than arg2
10646 : : <> true if switch is earlier than arg1 or is arg2 or later
10647 : :
10648 : : If the switch is not present, the condition is false unless
10649 : : the first character of the <comparison-op> is '!'.
10650 : :
10651 : : For example,
10652 : : %:version-compare(>= 10.3 mmacosx-version-min= -lmx)
10653 : : adds -lmx if -mmacosx-version-min=10.3.9 was passed. */
10654 : :
10655 : : static const char *
10656 : 0 : version_compare_spec_function (int argc, const char **argv)
10657 : : {
10658 : 0 : int comp1, comp2;
10659 : 0 : size_t switch_len;
10660 : 0 : const char *switch_value = NULL;
10661 : 0 : int nargs = 1, i;
10662 : 0 : bool result;
10663 : :
10664 : 0 : if (argc < 3)
10665 : 0 : fatal_error (input_location, "too few arguments to %%:version-compare");
10666 : 0 : if (argv[0][0] == '\0')
10667 : 0 : abort ();
10668 : 0 : if ((argv[0][1] == '<' || argv[0][1] == '>') && argv[0][0] != '!')
10669 : 0 : nargs = 2;
10670 : 0 : if (argc != nargs + 3)
10671 : 0 : fatal_error (input_location, "too many arguments to %%:version-compare");
10672 : :
10673 : 0 : switch_len = strlen (argv[nargs + 1]);
10674 : 0 : for (i = 0; i < n_switches; i++)
10675 : 0 : if (!strncmp (switches[i].part1, argv[nargs + 1], switch_len)
10676 : 0 : && check_live_switch (i, switch_len))
10677 : 0 : switch_value = switches[i].part1 + switch_len;
10678 : :
10679 : 0 : if (switch_value == NULL)
10680 : : comp1 = comp2 = -1;
10681 : : else
10682 : : {
10683 : 0 : comp1 = compare_version_strings (switch_value, argv[1]);
10684 : 0 : if (nargs == 2)
10685 : 0 : comp2 = compare_version_strings (switch_value, argv[2]);
10686 : : else
10687 : : comp2 = -1; /* This value unused. */
10688 : : }
10689 : :
10690 : 0 : switch (argv[0][0] << 8 | argv[0][1])
10691 : : {
10692 : 0 : case '>' << 8 | '=':
10693 : 0 : result = comp1 >= 0;
10694 : 0 : break;
10695 : 0 : case '!' << 8 | '<':
10696 : 0 : result = comp1 >= 0 || switch_value == NULL;
10697 : 0 : break;
10698 : 0 : case '<' << 8:
10699 : 0 : result = comp1 < 0;
10700 : 0 : break;
10701 : 0 : case '!' << 8 | '>':
10702 : 0 : result = comp1 < 0 || switch_value == NULL;
10703 : 0 : break;
10704 : 0 : case '>' << 8 | '<':
10705 : 0 : result = comp1 >= 0 && comp2 < 0;
10706 : 0 : break;
10707 : 0 : case '<' << 8 | '>':
10708 : 0 : result = comp1 < 0 || comp2 >= 0;
10709 : 0 : break;
10710 : :
10711 : 0 : default:
10712 : 0 : fatal_error (input_location,
10713 : : "unknown operator %qs in %%:version-compare", argv[0]);
10714 : : }
10715 : 0 : if (! result)
10716 : : return NULL;
10717 : :
10718 : 0 : return argv[nargs + 2];
10719 : : }
10720 : :
10721 : : /* %:include builtin spec function. This differs from %include in that it
10722 : : can be nested inside a spec, and thus be conditionalized. It takes
10723 : : one argument, the filename, and looks for it in the startfile path.
10724 : : The result is always NULL, i.e. an empty expansion. */
10725 : :
10726 : : static const char *
10727 : 30742 : include_spec_function (int argc, const char **argv)
10728 : : {
10729 : 30742 : char *file;
10730 : :
10731 : 30742 : if (argc != 1)
10732 : 0 : abort ();
10733 : :
10734 : 30742 : file = find_a_file (&startfile_prefixes, argv[0], R_OK, true);
10735 : 30742 : read_specs (file ? file : argv[0], false, false);
10736 : :
10737 : 30742 : return NULL;
10738 : : }
10739 : :
10740 : : /* %:find-file spec function. This function replaces its argument by
10741 : : the file found through find_file, that is the -print-file-name gcc
10742 : : program option. */
10743 : : static const char *
10744 : 0 : find_file_spec_function (int argc, const char **argv)
10745 : : {
10746 : 0 : const char *file;
10747 : :
10748 : 0 : if (argc != 1)
10749 : 0 : abort ();
10750 : :
10751 : 0 : file = find_file (argv[0]);
10752 : 0 : return file;
10753 : : }
10754 : :
10755 : :
10756 : : /* %:find-plugindir spec function. This function replaces its argument
10757 : : by the -iplugindir=<dir> option. `dir' is found through find_file, that
10758 : : is the -print-file-name gcc program option. */
10759 : : static const char *
10760 : 400 : find_plugindir_spec_function (int argc, const char **argv ATTRIBUTE_UNUSED)
10761 : : {
10762 : 400 : const char *option;
10763 : :
10764 : 400 : if (argc != 0)
10765 : 0 : abort ();
10766 : :
10767 : 400 : option = concat ("-iplugindir=", find_file ("plugin"), NULL);
10768 : 400 : return option;
10769 : : }
10770 : :
10771 : :
10772 : : /* %:print-asm-header spec function. Print a banner to say that the
10773 : : following output is from the assembler. */
10774 : :
10775 : : static const char *
10776 : 0 : print_asm_header_spec_function (int arg ATTRIBUTE_UNUSED,
10777 : : const char **argv ATTRIBUTE_UNUSED)
10778 : : {
10779 : 0 : printf (_("Assembler options\n=================\n\n"));
10780 : 0 : printf (_("Use \"-Wa,OPTION\" to pass \"OPTION\" to the assembler.\n\n"));
10781 : 0 : fflush (stdout);
10782 : 0 : return NULL;
10783 : : }
10784 : :
10785 : : /* Get a random number for -frandom-seed */
10786 : :
10787 : : static unsigned HOST_WIDE_INT
10788 : 620 : get_random_number (void)
10789 : : {
10790 : 620 : unsigned HOST_WIDE_INT ret = 0;
10791 : 620 : int fd;
10792 : :
10793 : 620 : fd = open ("/dev/urandom", O_RDONLY);
10794 : 620 : if (fd >= 0)
10795 : : {
10796 : 620 : read (fd, &ret, sizeof (HOST_WIDE_INT));
10797 : 620 : close (fd);
10798 : 620 : if (ret)
10799 : : return ret;
10800 : : }
10801 : :
10802 : : /* Get some more or less random data. */
10803 : : #ifdef HAVE_GETTIMEOFDAY
10804 : 0 : {
10805 : 0 : struct timeval tv;
10806 : :
10807 : 0 : gettimeofday (&tv, NULL);
10808 : 0 : ret = tv.tv_sec * 1000 + tv.tv_usec / 1000;
10809 : : }
10810 : : #else
10811 : : {
10812 : : time_t now = time (NULL);
10813 : :
10814 : : if (now != (time_t)-1)
10815 : : ret = (unsigned) now;
10816 : : }
10817 : : #endif
10818 : :
10819 : 0 : return ret ^ getpid ();
10820 : : }
10821 : :
10822 : : /* %:compare-debug-dump-opt spec function. Save the last argument,
10823 : : expected to be the last -fdump-final-insns option, or generate a
10824 : : temporary. */
10825 : :
10826 : : static const char *
10827 : 1233 : compare_debug_dump_opt_spec_function (int arg,
10828 : : const char **argv ATTRIBUTE_UNUSED)
10829 : : {
10830 : 1233 : char *ret;
10831 : 1233 : char *name;
10832 : 1233 : int which;
10833 : 1233 : static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
10834 : :
10835 : 1233 : if (arg != 0)
10836 : 0 : fatal_error (input_location,
10837 : : "too many arguments to %%:compare-debug-dump-opt");
10838 : :
10839 : 1233 : do_spec_2 ("%{fdump-final-insns=*:%*}", NULL);
10840 : 1233 : do_spec_1 (" ", 0, NULL);
10841 : :
10842 : 1233 : if (argbuf.length () > 0
10843 : 1233 : && strcmp (argv[argbuf.length () - 1], ".") != 0)
10844 : : {
10845 : 0 : if (!compare_debug)
10846 : : return NULL;
10847 : :
10848 : 0 : name = xstrdup (argv[argbuf.length () - 1]);
10849 : 0 : ret = NULL;
10850 : : }
10851 : : else
10852 : : {
10853 : 1233 : if (argbuf.length () > 0)
10854 : 6 : do_spec_2 ("%B.gkd", NULL);
10855 : 1227 : else if (!compare_debug)
10856 : : return NULL;
10857 : : else
10858 : 1227 : do_spec_2 ("%{!save-temps*:%g.gkd}%{save-temps*:%B.gkd}", NULL);
10859 : :
10860 : 1233 : do_spec_1 (" ", 0, NULL);
10861 : :
10862 : 1233 : gcc_assert (argbuf.length () > 0);
10863 : :
10864 : 1233 : name = xstrdup (argbuf.last ());
10865 : :
10866 : 1233 : char *arg = quote_spec (xstrdup (name));
10867 : 1233 : ret = concat ("-fdump-final-insns=", arg, NULL);
10868 : 1233 : free (arg);
10869 : : }
10870 : :
10871 : 1233 : which = compare_debug < 0;
10872 : 1233 : debug_check_temp_file[which] = name;
10873 : :
10874 : 1233 : if (!which)
10875 : : {
10876 : 620 : unsigned HOST_WIDE_INT value = get_random_number ();
10877 : :
10878 : 620 : sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
10879 : : }
10880 : :
10881 : 1233 : if (*random_seed)
10882 : : {
10883 : 1233 : char *tmp = ret;
10884 : 1233 : ret = concat ("%{!frandom-seed=*:-frandom-seed=", random_seed, "} ",
10885 : : ret, NULL);
10886 : 1233 : free (tmp);
10887 : : }
10888 : :
10889 : 1233 : if (which)
10890 : 613 : *random_seed = 0;
10891 : :
10892 : : return ret;
10893 : : }
10894 : :
10895 : : /* %:compare-debug-self-opt spec function. Expands to the options
10896 : : that are to be passed in the second compilation of
10897 : : compare-debug. */
10898 : :
10899 : : static const char *
10900 : 1238 : compare_debug_self_opt_spec_function (int arg,
10901 : : const char **argv ATTRIBUTE_UNUSED)
10902 : : {
10903 : 1238 : if (arg != 0)
10904 : 0 : fatal_error (input_location,
10905 : : "too many arguments to %%:compare-debug-self-opt");
10906 : :
10907 : 1238 : if (compare_debug >= 0)
10908 : : return NULL;
10909 : :
10910 : 619 : return concat ("\
10911 : : %<o %<MD %<MMD %<MF* %<MG %<MP %<MQ* %<MT* \
10912 : : %<fdump-final-insns=* -w -S -o %j \
10913 : : %{!fcompare-debug-second:-fcompare-debug-second} \
10914 : 619 : ", compare_debug_opt, NULL);
10915 : : }
10916 : :
10917 : : /* %:pass-through-libs spec function. Finds all -l options and input
10918 : : file names in the lib spec passed to it, and makes a list of them
10919 : : prepended with the plugin option to cause them to be passed through
10920 : : to the final link after all the new object files have been added. */
10921 : :
10922 : : const char *
10923 : 90424 : pass_through_libs_spec_func (int argc, const char **argv)
10924 : : {
10925 : 90424 : char *prepended = xstrdup (" ");
10926 : 90424 : int n;
10927 : : /* Shlemiel the painter's algorithm. Innately horrible, but at least
10928 : : we know that there will never be more than a handful of strings to
10929 : : concat, and it's only once per run, so it's not worth optimising. */
10930 : 1228379 : for (n = 0; n < argc; n++)
10931 : : {
10932 : 1137955 : char *old = prepended;
10933 : : /* Anything that isn't an option is a full path to an output
10934 : : file; pass it through if it ends in '.a'. Among options,
10935 : : pass only -l. */
10936 : 1137955 : if (argv[n][0] == '-' && argv[n][1] == 'l')
10937 : : {
10938 : 590926 : const char *lopt = argv[n] + 2;
10939 : : /* Handle both joined and non-joined -l options. If for any
10940 : : reason there's a trailing -l with no joined or following
10941 : : arg just discard it. */
10942 : 590926 : if (!*lopt && ++n >= argc)
10943 : : break;
10944 : 590926 : else if (!*lopt)
10945 : 0 : lopt = argv[n];
10946 : 590926 : prepended = concat (prepended, "-plugin-opt=-pass-through=-l",
10947 : : lopt, " ", NULL);
10948 : 590926 : }
10949 : 547029 : else if (!strcmp (".a", argv[n] + strlen (argv[n]) - 2))
10950 : : {
10951 : 0 : prepended = concat (prepended, "-plugin-opt=-pass-through=",
10952 : : argv[n], " ", NULL);
10953 : : }
10954 : 1137955 : if (prepended != old)
10955 : 590926 : free (old);
10956 : : }
10957 : 90424 : return prepended;
10958 : : }
10959 : :
10960 : : static bool
10961 : 517625 : not_actual_file_p (const char *name)
10962 : : {
10963 : 517625 : return (strcmp (name, "-") == 0
10964 : 517625 : || strcmp (name, HOST_BIT_BUCKET) == 0);
10965 : : }
10966 : :
10967 : : /* %:dumps spec function. Take an optional argument that overrides
10968 : : the default extension for -dumpbase and -dumpbase-ext.
10969 : : Return -dumpdir, -dumpbase and -dumpbase-ext, if needed. */
10970 : : const char *
10971 : 284292 : dumps_spec_func (int argc, const char **argv ATTRIBUTE_UNUSED)
10972 : : {
10973 : 284292 : const char *ext = dumpbase_ext;
10974 : 284292 : char *p;
10975 : :
10976 : 284292 : char *args[3] = { NULL, NULL, NULL };
10977 : 284292 : int nargs = 0;
10978 : :
10979 : : /* Do not compute a default for -dumpbase-ext when -dumpbase was
10980 : : given explicitly. */
10981 : 284292 : if (dumpbase && *dumpbase && !ext)
10982 : 284292 : ext = "";
10983 : :
10984 : 284292 : if (argc == 1)
10985 : : {
10986 : : /* Do not override the explicitly-specified -dumpbase-ext with
10987 : : the specs-provided overrider. */
10988 : 0 : if (!ext)
10989 : 0 : ext = argv[0];
10990 : : }
10991 : 284292 : else if (argc != 0)
10992 : 0 : fatal_error (input_location, "too many arguments for %%:dumps");
10993 : :
10994 : 284292 : if (dumpdir)
10995 : : {
10996 : 105519 : p = quote_spec_arg (xstrdup (dumpdir));
10997 : 105519 : args[nargs++] = concat (" -dumpdir ", p, NULL);
10998 : 105519 : free (p);
10999 : : }
11000 : :
11001 : 284292 : if (!ext)
11002 : 262068 : ext = input_basename + basename_length;
11003 : :
11004 : : /* Use the precomputed outbase, or compute dumpbase from
11005 : : input_basename, just like %b would. */
11006 : 284292 : char *base;
11007 : :
11008 : 284292 : if (dumpbase && *dumpbase)
11009 : : {
11010 : 22224 : base = xstrdup (dumpbase);
11011 : 22224 : p = base + outbase_length;
11012 : 22224 : gcc_checking_assert (strncmp (base, outbase, outbase_length) == 0);
11013 : 22224 : gcc_checking_assert (strcmp (p, ext) == 0);
11014 : : }
11015 : 262068 : else if (outbase_length)
11016 : : {
11017 : 161397 : base = xstrndup (outbase, outbase_length);
11018 : 161397 : p = NULL;
11019 : : }
11020 : : else
11021 : : {
11022 : 100671 : base = xstrndup (input_basename, suffixed_basename_length);
11023 : 100671 : p = base + basename_length;
11024 : : }
11025 : :
11026 : 284292 : if (compare_debug < 0 || !p || strcmp (p, ext) != 0)
11027 : : {
11028 : 613 : if (p)
11029 : 9 : *p = '\0';
11030 : :
11031 : 161406 : const char *gk;
11032 : 161406 : if (compare_debug < 0)
11033 : : gk = ".gk";
11034 : : else
11035 : 160793 : gk = "";
11036 : :
11037 : 161406 : p = concat (base, gk, ext, NULL);
11038 : :
11039 : 161406 : free (base);
11040 : 161406 : base = p;
11041 : : }
11042 : :
11043 : 284292 : base = quote_spec_arg (base);
11044 : 284292 : args[nargs++] = concat (" -dumpbase ", base, NULL);
11045 : 284292 : free (base);
11046 : :
11047 : 284292 : if (*ext)
11048 : : {
11049 : 261029 : p = quote_spec_arg (xstrdup (ext));
11050 : 261029 : args[nargs++] = concat (" -dumpbase-ext ", p, NULL);
11051 : 261029 : free (p);
11052 : : }
11053 : :
11054 : 284292 : const char *ret = concat (args[0], args[1], args[2], NULL);
11055 : 1219424 : while (nargs > 0)
11056 : 650840 : free (args[--nargs]);
11057 : :
11058 : 284292 : return ret;
11059 : : }
11060 : :
11061 : : /* Returns "" if ARGV[ARGC - 2] is greater than ARGV[ARGC-1].
11062 : : Otherwise, return NULL. */
11063 : :
11064 : : static const char *
11065 : 394226 : greater_than_spec_func (int argc, const char **argv)
11066 : : {
11067 : 394226 : char *converted;
11068 : :
11069 : 394226 : if (argc == 1)
11070 : : return NULL;
11071 : :
11072 : 252 : gcc_assert (argc >= 2);
11073 : :
11074 : 252 : long arg = strtol (argv[argc - 2], &converted, 10);
11075 : 252 : gcc_assert (converted != argv[argc - 2]);
11076 : :
11077 : 252 : long lim = strtol (argv[argc - 1], &converted, 10);
11078 : 252 : gcc_assert (converted != argv[argc - 1]);
11079 : :
11080 : 252 : if (arg > lim)
11081 : : return "";
11082 : :
11083 : : return NULL;
11084 : : }
11085 : :
11086 : : /* Returns "" if debug_info_level is greater than ARGV[ARGC-1].
11087 : : Otherwise, return NULL. */
11088 : :
11089 : : static const char *
11090 : 253550 : debug_level_greater_than_spec_func (int argc, const char **argv)
11091 : : {
11092 : 253550 : char *converted;
11093 : :
11094 : 253550 : if (argc != 1)
11095 : 0 : fatal_error (input_location,
11096 : : "wrong number of arguments to %%:debug-level-gt");
11097 : :
11098 : 253550 : long arg = strtol (argv[0], &converted, 10);
11099 : 253550 : gcc_assert (converted != argv[0]);
11100 : :
11101 : 253550 : if (debug_info_level > arg)
11102 : 45419 : return "";
11103 : :
11104 : : return NULL;
11105 : : }
11106 : :
11107 : : /* Returns "" if dwarf_version is greater than ARGV[ARGC-1].
11108 : : Otherwise, return NULL. */
11109 : :
11110 : : static const char *
11111 : 128589 : dwarf_version_greater_than_spec_func (int argc, const char **argv)
11112 : : {
11113 : 128589 : char *converted;
11114 : :
11115 : 128589 : if (argc != 1)
11116 : 0 : fatal_error (input_location,
11117 : : "wrong number of arguments to %%:dwarf-version-gt");
11118 : :
11119 : 128589 : long arg = strtol (argv[0], &converted, 10);
11120 : 128589 : gcc_assert (converted != argv[0]);
11121 : :
11122 : 128589 : if (dwarf_version > arg)
11123 : 127718 : return "";
11124 : :
11125 : : return NULL;
11126 : : }
11127 : :
11128 : : static void
11129 : 34326 : path_prefix_reset (path_prefix *prefix)
11130 : : {
11131 : 34326 : struct prefix_list *iter, *next;
11132 : 34326 : iter = prefix->plist;
11133 : 136170 : while (iter)
11134 : : {
11135 : 101844 : next = iter->next;
11136 : 101844 : free (const_cast <char *> (iter->prefix));
11137 : 101844 : XDELETE (iter);
11138 : 101844 : iter = next;
11139 : : }
11140 : 34326 : prefix->plist = 0;
11141 : 34326 : prefix->max_len = 0;
11142 : 34326 : }
11143 : :
11144 : : /* The function takes 3 arguments: OPTION name, file name and location
11145 : : where we search for Fortran modules.
11146 : : When the FILE is found by find_file, return OPTION=path_to_file. */
11147 : :
11148 : : static const char *
11149 : 30924 : find_fortran_preinclude_file (int argc, const char **argv)
11150 : : {
11151 : 30924 : char *result = NULL;
11152 : 30924 : if (argc != 3)
11153 : : return NULL;
11154 : :
11155 : 30924 : struct path_prefix prefixes = { 0, 0, "preinclude" };
11156 : :
11157 : : /* Search first for 'finclude' folder location for a header file
11158 : : installed by the compiler (similar to omp_lib.h). */
11159 : 30924 : add_prefix (&prefixes, argv[2], NULL, 0, 0, 0);
11160 : : #ifdef TOOL_INCLUDE_DIR
11161 : : /* Then search: <prefix>/<target>/<include>/finclude */
11162 : 30924 : add_prefix (&prefixes, TOOL_INCLUDE_DIR "/finclude/",
11163 : : NULL, 0, 0, 0);
11164 : : #endif
11165 : : #ifdef NATIVE_SYSTEM_HEADER_DIR
11166 : : /* Then search: <sysroot>/usr/include/finclude/<multilib> */
11167 : 30924 : add_sysrooted_hdrs_prefix (&prefixes, NATIVE_SYSTEM_HEADER_DIR "/finclude/",
11168 : : NULL, 0, 0, 0);
11169 : : #endif
11170 : :
11171 : 30924 : const char *path = find_a_file (&include_prefixes, argv[1], R_OK, false);
11172 : 30924 : if (path != NULL)
11173 : 0 : result = concat (argv[0], path, NULL);
11174 : : else
11175 : : {
11176 : 30924 : path = find_a_file (&prefixes, argv[1], R_OK, false);
11177 : 30924 : if (path != NULL)
11178 : 30924 : result = concat (argv[0], path, NULL);
11179 : : }
11180 : :
11181 : 30924 : path_prefix_reset (&prefixes);
11182 : 30924 : return result;
11183 : : }
11184 : :
11185 : : /* The function takes any number of arguments and joins them together.
11186 : :
11187 : : This seems to be necessary to build "-fjoined=foo.b" from "-fseparate foo.a"
11188 : : with a %{fseparate*:-fjoined=%.b$*} rule without adding undesired spaces:
11189 : : when doing $* replacement we first replace $* with the rest of the switch
11190 : : (in this case ""), and then add any arguments as arguments after the result,
11191 : : resulting in "-fjoined= foo.b". Using this function with e.g.
11192 : : %{fseparate*:-fjoined=%:join(%.b$*)} gets multiple words as separate argv
11193 : : elements instead of separated by spaces, and we paste them together. */
11194 : :
11195 : : static const char *
11196 : 39 : join_spec_func (int argc, const char **argv)
11197 : : {
11198 : 39 : if (argc == 1)
11199 : 0 : return argv[0];
11200 : 117 : for (int i = 0; i < argc; ++i)
11201 : 78 : obstack_grow (&obstack, argv[i], strlen (argv[i]));
11202 : 39 : obstack_1grow (&obstack, '\0');
11203 : 39 : return XOBFINISH (&obstack, const char *);
11204 : : }
11205 : :
11206 : : /* If any character in ORIG fits QUOTE_P (_, P), reallocate the string
11207 : : so as to precede every one of them with a backslash. Return the
11208 : : original string or the reallocated one. */
11209 : :
11210 : : static inline char *
11211 : 849743 : quote_string (char *orig, bool (*quote_p)(char, void *), void *p)
11212 : : {
11213 : 849743 : int len, number_of_space = 0;
11214 : :
11215 : 19356219 : for (len = 0; orig[len]; len++)
11216 : 18506476 : if (quote_p (orig[len], p))
11217 : 0 : number_of_space++;
11218 : :
11219 : 849743 : if (number_of_space)
11220 : : {
11221 : 0 : char *new_spec = (char *) xmalloc (len + number_of_space + 1);
11222 : 0 : int j, k;
11223 : 0 : for (j = 0, k = 0; j <= len; j++, k++)
11224 : : {
11225 : 0 : if (quote_p (orig[j], p))
11226 : 0 : new_spec[k++] = '\\';
11227 : 0 : new_spec[k] = orig[j];
11228 : : }
11229 : 0 : free (orig);
11230 : 0 : return new_spec;
11231 : : }
11232 : : else
11233 : : return orig;
11234 : : }
11235 : :
11236 : : /* Return true iff C is any of the characters convert_white_space
11237 : : should quote. */
11238 : :
11239 : : static inline bool
11240 : 12262259 : whitespace_to_convert_p (char c, void *)
11241 : : {
11242 : 12262259 : return (c == ' ' || c == '\t');
11243 : : }
11244 : :
11245 : : /* Insert backslash before spaces in ORIG (usually a file path), to
11246 : : avoid being broken by spec parser.
11247 : :
11248 : : This function is needed as do_spec_1 treats white space (' ' and '\t')
11249 : : as the end of an argument. But in case of -plugin /usr/gcc install/xxx.so,
11250 : : the file name should be treated as a single argument rather than being
11251 : : broken into multiple. Solution is to insert '\\' before the space in a
11252 : : file name.
11253 : :
11254 : : This function converts and only converts all occurrence of ' '
11255 : : to '\\' + ' ' and '\t' to '\\' + '\t'. For example:
11256 : : "a b" -> "a\\ b"
11257 : : "a b" -> "a\\ \\ b"
11258 : : "a\tb" -> "a\\\tb"
11259 : : "a\\ b" -> "a\\\\ b"
11260 : :
11261 : : orig: input null-terminating string that was allocated by xalloc. The
11262 : : memory it points to might be freed in this function. Behavior undefined
11263 : : if ORIG wasn't xalloced or was freed already at entry.
11264 : :
11265 : : Return: ORIG if no conversion needed. Otherwise a newly allocated string
11266 : : that was converted from ORIG. */
11267 : :
11268 : : static char *
11269 : 197679 : convert_white_space (char *orig)
11270 : : {
11271 : 197679 : return quote_string (orig, whitespace_to_convert_p, NULL);
11272 : : }
11273 : :
11274 : : /* Return true iff C matches any of the spec active characters. */
11275 : : static inline bool
11276 : 6244217 : quote_spec_char_p (char c, void *)
11277 : : {
11278 : 6244217 : switch (c)
11279 : : {
11280 : : case ' ':
11281 : : case '\t':
11282 : : case '\n':
11283 : : case '|':
11284 : : case '%':
11285 : : case '\\':
11286 : : return true;
11287 : :
11288 : 6244217 : default:
11289 : 6244217 : return false;
11290 : : }
11291 : : }
11292 : :
11293 : : /* Like convert_white_space, but deactivate all active spec chars by
11294 : : quoting them. */
11295 : :
11296 : : static inline char *
11297 : 652064 : quote_spec (char *orig)
11298 : : {
11299 : 1233 : return quote_string (orig, quote_spec_char_p, NULL);
11300 : : }
11301 : :
11302 : : /* Like quote_spec, but also turn an empty string into the spec for an
11303 : : empty argument. */
11304 : :
11305 : : static inline char *
11306 : 650840 : quote_spec_arg (char *orig)
11307 : : {
11308 : 650840 : if (!*orig)
11309 : : {
11310 : 9 : free (orig);
11311 : 9 : return xstrdup ("%\"");
11312 : : }
11313 : :
11314 : 650831 : return quote_spec (orig);
11315 : : }
11316 : :
11317 : : /* Restore all state within gcc.cc to the initial state, so that the driver
11318 : : code can be safely re-run in-process.
11319 : :
11320 : : Many const char * variables are referenced by static specs (see
11321 : : INIT_STATIC_SPEC above). These variables are restored to their default
11322 : : values by a simple loop over the static specs.
11323 : :
11324 : : For other variables, we directly restore them all to their initial
11325 : : values (often implicitly 0).
11326 : :
11327 : : Free the various obstacks in this file, along with "opts_obstack"
11328 : : from opts.cc.
11329 : :
11330 : : This function also restores any environment variables that were changed. */
11331 : :
11332 : : void
11333 : 1134 : driver::finalize ()
11334 : : {
11335 : 1134 : env.restore ();
11336 : 1134 : diagnostic_finish (global_dc);
11337 : :
11338 : 1134 : is_cpp_driver = 0;
11339 : 1134 : at_file_supplied = 0;
11340 : 1134 : print_help_list = 0;
11341 : 1134 : print_version = 0;
11342 : 1134 : verbose_only_flag = 0;
11343 : 1134 : print_subprocess_help = 0;
11344 : 1134 : use_ld = NULL;
11345 : 1134 : report_times_to_file = NULL;
11346 : 1134 : target_system_root = DEFAULT_TARGET_SYSTEM_ROOT;
11347 : 1134 : target_system_root_changed = 0;
11348 : 1134 : target_sysroot_suffix = 0;
11349 : 1134 : target_sysroot_hdrs_suffix = 0;
11350 : 1134 : save_temps_flag = SAVE_TEMPS_NONE;
11351 : 1134 : save_temps_overrides_dumpdir = false;
11352 : 1134 : dumpdir_trailing_dash_added = false;
11353 : 1134 : free (dumpdir);
11354 : 1134 : free (dumpbase);
11355 : 1134 : free (dumpbase_ext);
11356 : 1134 : free (outbase);
11357 : 1134 : dumpdir = dumpbase = dumpbase_ext = outbase = NULL;
11358 : 1134 : dumpdir_length = outbase_length = 0;
11359 : 1134 : spec_machine = DEFAULT_TARGET_MACHINE;
11360 : 1134 : greatest_status = 1;
11361 : :
11362 : 1134 : obstack_free (&obstack, NULL);
11363 : 1134 : obstack_free (&opts_obstack, NULL); /* in opts.cc */
11364 : 1134 : obstack_free (&collect_obstack, NULL);
11365 : :
11366 : 1134 : link_command_spec = LINK_COMMAND_SPEC;
11367 : :
11368 : 1134 : obstack_free (&multilib_obstack, NULL);
11369 : :
11370 : 1134 : user_specs_head = NULL;
11371 : 1134 : user_specs_tail = NULL;
11372 : :
11373 : : /* Within the "compilers" vec, the fields "suffix" and "spec" were
11374 : : statically allocated for the default compilers, but dynamically
11375 : : allocated for additional compilers. Delete them for the latter. */
11376 : 1134 : for (int i = n_default_compilers; i < n_compilers; i++)
11377 : : {
11378 : 0 : free (const_cast <char *> (compilers[i].suffix));
11379 : 0 : free (const_cast <char *> (compilers[i].spec));
11380 : : }
11381 : 1134 : XDELETEVEC (compilers);
11382 : 1134 : compilers = NULL;
11383 : 1134 : n_compilers = 0;
11384 : :
11385 : 1134 : linker_options.truncate (0);
11386 : 1134 : assembler_options.truncate (0);
11387 : 1134 : preprocessor_options.truncate (0);
11388 : :
11389 : 1134 : path_prefix_reset (&exec_prefixes);
11390 : 1134 : path_prefix_reset (&startfile_prefixes);
11391 : 1134 : path_prefix_reset (&include_prefixes);
11392 : :
11393 : 1134 : machine_suffix = 0;
11394 : 1134 : just_machine_suffix = 0;
11395 : 1134 : gcc_exec_prefix = 0;
11396 : 1134 : gcc_libexec_prefix = 0;
11397 : 1134 : set_static_spec_shared (&md_exec_prefix, MD_EXEC_PREFIX);
11398 : 1134 : set_static_spec_shared (&md_startfile_prefix, MD_STARTFILE_PREFIX);
11399 : 1134 : set_static_spec_shared (&md_startfile_prefix_1, MD_STARTFILE_PREFIX_1);
11400 : 1134 : multilib_dir = 0;
11401 : 1134 : multilib_os_dir = 0;
11402 : 1134 : multiarch_dir = 0;
11403 : :
11404 : : /* Free any specs dynamically-allocated by set_spec.
11405 : : These will be at the head of the list, before the
11406 : : statically-allocated ones. */
11407 : 1134 : if (specs)
11408 : : {
11409 : 2268 : while (specs != static_specs)
11410 : : {
11411 : 1134 : spec_list *next = specs->next;
11412 : 1134 : free (const_cast <char *> (specs->name));
11413 : 1134 : XDELETE (specs);
11414 : 1134 : specs = next;
11415 : : }
11416 : 1134 : specs = 0;
11417 : : }
11418 : 52164 : for (unsigned i = 0; i < ARRAY_SIZE (static_specs); i++)
11419 : : {
11420 : 51030 : spec_list *sl = &static_specs[i];
11421 : 51030 : if (sl->alloc_p)
11422 : : {
11423 : 45370 : free (const_cast <char *> (*(sl->ptr_spec)));
11424 : 45370 : sl->alloc_p = false;
11425 : : }
11426 : 51030 : *(sl->ptr_spec) = sl->default_ptr;
11427 : : }
11428 : : #ifdef EXTRA_SPECS
11429 : 1134 : extra_specs = NULL;
11430 : : #endif
11431 : :
11432 : 1134 : processing_spec_function = 0;
11433 : :
11434 : 1134 : clear_args ();
11435 : :
11436 : 1134 : have_c = 0;
11437 : 1134 : have_o = 0;
11438 : :
11439 : 1134 : temp_names = NULL;
11440 : 1134 : execution_count = 0;
11441 : 1134 : signal_count = 0;
11442 : :
11443 : 1134 : temp_filename = NULL;
11444 : 1134 : temp_filename_length = 0;
11445 : 1134 : always_delete_queue = NULL;
11446 : 1134 : failure_delete_queue = NULL;
11447 : :
11448 : 1134 : XDELETEVEC (switches);
11449 : 1134 : switches = NULL;
11450 : 1134 : n_switches = 0;
11451 : 1134 : n_switches_alloc = 0;
11452 : :
11453 : 1134 : compare_debug = 0;
11454 : 1134 : compare_debug_second = 0;
11455 : 1134 : compare_debug_opt = NULL;
11456 : 3402 : for (int i = 0; i < 2; i++)
11457 : : {
11458 : 2268 : switches_debug_check[i] = NULL;
11459 : 2268 : n_switches_debug_check[i] = 0;
11460 : 2268 : n_switches_alloc_debug_check[i] = 0;
11461 : 2268 : debug_check_temp_file[i] = NULL;
11462 : : }
11463 : :
11464 : 1134 : XDELETEVEC (infiles);
11465 : 1134 : infiles = NULL;
11466 : 1134 : n_infiles = 0;
11467 : 1134 : n_infiles_alloc = 0;
11468 : :
11469 : 1134 : combine_inputs = false;
11470 : 1134 : added_libraries = 0;
11471 : 1134 : XDELETEVEC (outfiles);
11472 : 1134 : outfiles = NULL;
11473 : 1134 : spec_lang = 0;
11474 : 1134 : last_language_n_infiles = 0;
11475 : 1134 : gcc_input_filename = NULL;
11476 : 1134 : input_file_number = 0;
11477 : 1134 : input_filename_length = 0;
11478 : 1134 : basename_length = 0;
11479 : 1134 : suffixed_basename_length = 0;
11480 : 1134 : input_basename = NULL;
11481 : 1134 : input_suffix = NULL;
11482 : : /* We don't need to purge "input_stat", just to unset "input_stat_set". */
11483 : 1134 : input_stat_set = 0;
11484 : 1134 : input_file_compiler = NULL;
11485 : 1134 : arg_going = 0;
11486 : 1134 : delete_this_arg = 0;
11487 : 1134 : this_is_output_file = 0;
11488 : 1134 : this_is_library_file = 0;
11489 : 1134 : this_is_linker_script = 0;
11490 : 1134 : input_from_pipe = 0;
11491 : 1134 : suffix_subst = NULL;
11492 : :
11493 : 1134 : XDELETEVEC (mdswitches);
11494 : 1134 : mdswitches = NULL;
11495 : 1134 : n_mdswitches = 0;
11496 : :
11497 : 1134 : used_arg.finalize ();
11498 : 1134 : }
11499 : :
11500 : : /* PR jit/64810.
11501 : : Targets can provide configure-time default options in
11502 : : OPTION_DEFAULT_SPECS. The jit needs to access these, but
11503 : : they are expressed in the spec language.
11504 : :
11505 : : Run just enough of the driver to be able to expand these
11506 : : specs, and then call the callback CB on each
11507 : : such option. The options strings are *without* a leading
11508 : : '-' character e.g. ("march=x86-64"). Finally, clean up. */
11509 : :
11510 : : void
11511 : 131 : driver_get_configure_time_options (void (*cb) (const char *option,
11512 : : void *user_data),
11513 : : void *user_data)
11514 : : {
11515 : 131 : size_t i;
11516 : :
11517 : 131 : obstack_init (&obstack);
11518 : 131 : init_opts_obstack ();
11519 : 131 : n_switches = 0;
11520 : :
11521 : 1441 : for (i = 0; i < ARRAY_SIZE (option_default_specs); i++)
11522 : 1310 : do_option_spec (option_default_specs[i].name,
11523 : 1310 : option_default_specs[i].spec);
11524 : :
11525 : 393 : for (i = 0; (int) i < n_switches; i++)
11526 : : {
11527 : 262 : gcc_assert (switches[i].part1);
11528 : 262 : (*cb) (switches[i].part1, user_data);
11529 : : }
11530 : :
11531 : 131 : obstack_free (&opts_obstack, NULL);
11532 : 131 : obstack_free (&obstack, NULL);
11533 : 131 : n_switches = 0;
11534 : 131 : }
|