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 : 299630 : env_manager::init (bool can_restore, bool debug)
104 : : {
105 : 299630 : m_can_restore = can_restore;
106 : 299630 : m_debug = debug;
107 : 299630 : }
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 : 1497233 : env_manager::get (const char *name)
115 : : {
116 : 1497233 : const char *result = ::getenv (name);
117 : 1497233 : if (m_debug)
118 : 0 : fprintf (stderr, "env_manager::getenv (%s) -> %s\n", name, result);
119 : 1497233 : 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 : 1775283 : env_manager::xput (const char *string)
129 : : {
130 : 1775283 : if (m_debug)
131 : 0 : fprintf (stderr, "env_manager::xput (%s)\n", string);
132 : 1775283 : if (verbose_flag)
133 : 6058 : fnotice (stderr, "%s\n", string);
134 : :
135 : 1775283 : 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 : 1775283 : ::putenv (CONST_CAST (char *, string));
150 : 1775283 : }
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 : 28442815 : skip_whitespace (char *p)
1548 : : {
1549 : 65920963 : while (1)
1550 : : {
1551 : : /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1552 : : be considered whitespace. */
1553 : 65920963 : if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n')
1554 : 4772528 : return p + 1;
1555 : 61148435 : else if (*p == '\n' || *p == ' ' || *p == '\t')
1556 : 37360756 : p++;
1557 : 23787679 : else if (*p == '#')
1558 : : {
1559 : 3638343 : while (*p != '\n')
1560 : 3520951 : p++;
1561 : 117392 : 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 : 1062 : init_gcc_specs (struct obstack *obstack, const char *shared_name,
1825 : : const char *static_name, const char *eh_name)
1826 : : {
1827 : 1062 : char *buf;
1828 : :
1829 : : #if USE_LD_AS_NEEDED
1830 : 1062 : 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 : 1062 : obstack_grow (obstack, buf, strlen (buf));
1858 : 1062 : free (buf);
1859 : 1062 : }
1860 : : #endif /* ENABLE_SHARED_LIBGCC */
1861 : :
1862 : : /* Initialize the specs lookup routines. */
1863 : :
1864 : : static void
1865 : 1062 : init_spec (void)
1866 : : {
1867 : 1062 : struct spec_list *next = (struct spec_list *) 0;
1868 : 1062 : struct spec_list *sl = (struct spec_list *) 0;
1869 : 1062 : int i;
1870 : :
1871 : 1062 : if (specs)
1872 : : return; /* Already initialized. */
1873 : :
1874 : 1062 : if (verbose_flag)
1875 : 86 : fnotice (stderr, "Using built-in specs.\n");
1876 : :
1877 : : #ifdef EXTRA_SPECS
1878 : 1062 : extra_specs = XCNEWVEC (struct spec_list, ARRAY_SIZE (extra_specs_1));
1879 : :
1880 : 2124 : for (i = ARRAY_SIZE (extra_specs_1) - 1; i >= 0; i--)
1881 : : {
1882 : 1062 : sl = &extra_specs[i];
1883 : 1062 : sl->name = extra_specs_1[i].name;
1884 : 1062 : sl->ptr = extra_specs_1[i].ptr;
1885 : 1062 : sl->next = next;
1886 : 1062 : sl->name_len = strlen (sl->name);
1887 : 1062 : sl->ptr_spec = &sl->ptr;
1888 : 1062 : gcc_assert (sl->ptr_spec != NULL);
1889 : 1062 : sl->default_ptr = sl->ptr;
1890 : 1062 : next = sl;
1891 : : }
1892 : : #endif
1893 : :
1894 : 48852 : for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--)
1895 : : {
1896 : 47790 : sl = &static_specs[i];
1897 : 47790 : sl->next = next;
1898 : 47790 : 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 : 1062 : {
1930 : 1062 : const char *p = libgcc_spec;
1931 : 1062 : 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 : 2124 : while (*p)
1936 : : {
1937 : 1062 : if (in_sep && *p == '-' && startswith (p, "-lgcc"))
1938 : : {
1939 : 1062 : 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 : 1062 : p += 5;
1958 : 1062 : 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 : 1062 : obstack_1grow (&obstack, '\0');
1984 : 1062 : 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 : 1062 : 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 : 1062 : obstack_grow0 (&obstack, link_spec, strlen (link_spec));
2018 : 1062 : link_spec = XOBFINISH (&obstack, const char *);
2019 : : #endif
2020 : :
2021 : 1062 : 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 : 208190 : set_static_spec (const char **spec, const char *value, bool alloc_p)
2030 : : {
2031 : 208190 : struct spec_list *sl = NULL;
2032 : :
2033 : 7189287 : for (unsigned i = 0; i < ARRAY_SIZE (static_specs); i++)
2034 : : {
2035 : 7189287 : if (static_specs[i].ptr_spec == spec)
2036 : : {
2037 : 208190 : sl = static_specs + i;
2038 : 208190 : break;
2039 : : }
2040 : : }
2041 : :
2042 : 0 : gcc_assert (sl);
2043 : :
2044 : 208190 : if (sl->alloc_p)
2045 : : {
2046 : 208190 : const char *old = *spec;
2047 : 208190 : free (const_cast <char *> (old));
2048 : : }
2049 : :
2050 : 208190 : *spec = value;
2051 : 208190 : sl->alloc_p = alloc_p;
2052 : 208190 : }
2053 : :
2054 : : /* Update a static spec to a new string, taking ownership of that
2055 : : string's memory. */
2056 : 107584 : 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 : 100606 : 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 : 13769219 : set_spec (const char *name, const char *spec, bool user_p)
2075 : : {
2076 : 13769219 : struct spec_list *sl;
2077 : 13769219 : const char *old_spec;
2078 : 13769219 : int name_len = strlen (name);
2079 : 13769219 : int i;
2080 : :
2081 : : /* If this is the first call, initialize the statically allocated specs. */
2082 : 13769219 : if (!specs)
2083 : : {
2084 : : struct spec_list *next = (struct spec_list *) 0;
2085 : 13721018 : for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--)
2086 : : {
2087 : 13422735 : sl = &static_specs[i];
2088 : 13422735 : sl->next = next;
2089 : 13422735 : next = sl;
2090 : : }
2091 : 298283 : specs = sl;
2092 : : }
2093 : :
2094 : : /* See if the spec already exists. */
2095 : 324007436 : for (sl = specs; sl; sl = sl->next)
2096 : 323687954 : if (name_len == sl->name_len && !strcmp (sl->name, name))
2097 : : break;
2098 : :
2099 : 13769219 : if (!sl)
2100 : : {
2101 : : /* Not found - make it. */
2102 : 319482 : sl = XNEW (struct spec_list);
2103 : 319482 : sl->name = xstrdup (name);
2104 : 319482 : sl->name_len = name_len;
2105 : 319482 : sl->ptr_spec = &sl->ptr;
2106 : 319482 : sl->alloc_p = 0;
2107 : 319482 : *(sl->ptr_spec) = "";
2108 : 319482 : sl->next = specs;
2109 : 319482 : sl->default_ptr = NULL;
2110 : 319482 : specs = sl;
2111 : : }
2112 : :
2113 : 13769219 : old_spec = *(sl->ptr_spec);
2114 : 13769219 : *(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE ((unsigned char)spec[1]))
2115 : 1 : ? concat (old_spec, spec + 1, NULL)
2116 : 13769218 : : 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 : 13769219 : if (old_spec && sl->alloc_p)
2125 : 5896 : free (CONST_CAST (char *, old_spec));
2126 : :
2127 : 13769219 : sl->user_p = user_p;
2128 : 13769219 : sl->alloc_p = true;
2129 : 13769219 : }
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 : 2380571 : alloc_args (void)
2185 : : {
2186 : 2380571 : argbuf.create (10);
2187 : 2380571 : at_file_argbuf.create (10);
2188 : 2380571 : }
2189 : :
2190 : : /* Clear out the vector of arguments (after a command is executed). */
2191 : :
2192 : : static void
2193 : 5608337 : clear_args (void)
2194 : : {
2195 : 5608337 : argbuf.truncate (0);
2196 : 5608337 : at_file_argbuf.truncate (0);
2197 : 5608337 : }
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 : 20463687 : store_arg (const char *arg, int delete_always, int delete_failure)
2208 : : {
2209 : 20463687 : if (in_at_file)
2210 : 14231 : at_file_argbuf.safe_push (arg);
2211 : : else
2212 : 20449456 : argbuf.safe_push (arg);
2213 : :
2214 : 20463687 : if (delete_always || delete_failure)
2215 : : {
2216 : 525507 : const char *p;
2217 : : /* If the temporary file we should delete is specified as
2218 : : part of a joined argument extract the filename. */
2219 : 525507 : if (arg[0] == '-'
2220 : 525507 : && (p = strrchr (arg, '=')))
2221 : 91500 : arg = p + 1;
2222 : 525507 : record_temp_file (arg, delete_always, delete_failure);
2223 : : }
2224 : 20463687 : }
2225 : :
2226 : : /* Open a temporary @file into which subsequent arguments will be stored. */
2227 : :
2228 : : static void
2229 : 13193 : open_at_file (void)
2230 : : {
2231 : 13193 : if (in_at_file)
2232 : 0 : fatal_error (input_location, "cannot open nested response file");
2233 : : else
2234 : 13193 : in_at_file = true;
2235 : 13193 : }
2236 : :
2237 : : /* Create a temporary @file name. */
2238 : :
2239 : 13183 : static char *make_at_file (void)
2240 : : {
2241 : 13183 : static int fileno = 0;
2242 : 13183 : char filename[20];
2243 : 13183 : const char *base, *ext;
2244 : :
2245 : 13183 : if (!save_temps_flag)
2246 : 13145 : 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 : 13193 : close_at_file (void)
2267 : : {
2268 : 13193 : if (!in_at_file)
2269 : 0 : fatal_error (input_location, "cannot close nonexistent response file");
2270 : :
2271 : 13193 : in_at_file = false;
2272 : :
2273 : 13193 : const unsigned int n_args = at_file_argbuf.length ();
2274 : 13193 : if (n_args == 0)
2275 : : return;
2276 : :
2277 : 13183 : char **argv = XALLOCAVEC (char *, n_args + 1);
2278 : 13183 : char *temp_file = make_at_file ();
2279 : 13183 : char *at_argument = concat ("@", temp_file, NULL);
2280 : 13183 : FILE *f = fopen (temp_file, "w");
2281 : 13183 : int status;
2282 : 13183 : unsigned int i;
2283 : :
2284 : : /* Copy the strings over. */
2285 : 40597 : for (i = 0; i < n_args; i++)
2286 : 14231 : argv[i] = CONST_CAST (char *, at_file_argbuf[i]);
2287 : 13183 : argv[i] = NULL;
2288 : :
2289 : 13183 : at_file_argbuf.truncate (0);
2290 : :
2291 : 13183 : if (f == NULL)
2292 : 0 : fatal_error (input_location, "could not open temporary response file %s",
2293 : : temp_file);
2294 : :
2295 : 13183 : status = writeargv (argv, f);
2296 : :
2297 : 13183 : if (status)
2298 : 0 : fatal_error (input_location,
2299 : : "could not write to temporary response file %s",
2300 : : temp_file);
2301 : :
2302 : 13183 : status = fclose (f);
2303 : :
2304 : 13183 : if (status == EOF)
2305 : 0 : fatal_error (input_location, "could not close temporary response file %s",
2306 : : temp_file);
2307 : :
2308 : 13183 : store_arg (at_argument, 0, 0);
2309 : :
2310 : 13183 : 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 : 328918 : load_specs (const char *filename)
2319 : : {
2320 : 328918 : int desc;
2321 : 328918 : int readlen;
2322 : 328918 : struct stat statbuf;
2323 : 328918 : char *buffer;
2324 : 328918 : char *buffer_p;
2325 : 328918 : char *specs;
2326 : 328918 : char *specs_p;
2327 : :
2328 : 328918 : if (verbose_flag)
2329 : 1409 : fnotice (stderr, "Reading specs from %s\n", filename);
2330 : :
2331 : : /* Open and stat the file. */
2332 : 328918 : desc = open (filename, O_RDONLY, 0);
2333 : 328918 : 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 : 328917 : if (stat (filename, &statbuf) < 0)
2341 : 0 : goto failed;
2342 : :
2343 : : /* Read contents of file into BUFFER. */
2344 : 328917 : buffer = XNEWVEC (char, statbuf.st_size + 1);
2345 : 328917 : readlen = read (desc, buffer, (unsigned) statbuf.st_size);
2346 : 328917 : if (readlen < 0)
2347 : 0 : goto failed;
2348 : 328917 : buffer[readlen] = 0;
2349 : 328917 : close (desc);
2350 : :
2351 : 328917 : specs = XNEWVEC (char, readlen + 1);
2352 : 328917 : specs_p = specs;
2353 : 3016280438 : for (buffer_p = buffer; buffer_p && *buffer_p; buffer_p++)
2354 : : {
2355 : 3015951521 : int skip = 0;
2356 : 3015951521 : char c = *buffer_p;
2357 : 3015951521 : 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 : 3015951521 : *specs_p++ = c;
2368 : : }
2369 : 328917 : *specs_p = '\0';
2370 : :
2371 : 328917 : free (buffer);
2372 : 328917 : 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 : 328918 : read_specs (const char *filename, bool main_p, bool user_p)
2388 : : {
2389 : 328918 : char *buffer;
2390 : 328918 : char *p;
2391 : :
2392 : 328918 : buffer = load_specs (filename);
2393 : :
2394 : : /* Scan BUFFER for specs, putting them in the vector. */
2395 : 328918 : p = buffer;
2396 : 14396419 : while (1)
2397 : : {
2398 : 14396419 : char *suffix;
2399 : 14396419 : char *spec;
2400 : 14396419 : char *in, *out, *p1, *p2, *p3;
2401 : :
2402 : : /* Advance P in BUFFER to the next nonblank nocomment line. */
2403 : 14396419 : p = skip_whitespace (p);
2404 : 14396419 : 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 : 14067502 : if (*p == '%' && !main_p)
2411 : : {
2412 : 422120 : p1 = p;
2413 : 422120 : while (*p && *p != '\n')
2414 : 401014 : p++;
2415 : :
2416 : : /* Skip '\n'. */
2417 : 21106 : p++;
2418 : :
2419 : 21106 : if (startswith (p1, "%include")
2420 : 21106 : && (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 : 21106 : else if (startswith (p1, "%include_noerr")
2440 : 21106 : && (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 : 21106 : else if (startswith (p1, "%rename")
2463 : 21106 : && (p1[sizeof "%rename" - 1] == ' '
2464 : 0 : || p1[sizeof "%rename" - 1] == '\t'))
2465 : : {
2466 : 21106 : int name_len;
2467 : 21106 : struct spec_list *sl;
2468 : 21106 : struct spec_list *newsl;
2469 : :
2470 : : /* Get original name. */
2471 : 21106 : p1 += sizeof "%rename";
2472 : 21106 : while (*p1 == ' ' || *p1 == '\t')
2473 : 0 : p1++;
2474 : :
2475 : 21106 : 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 : 84424 : while (*p2 && !ISSPACE ((unsigned char) *p2))
2482 : 63318 : p2++;
2483 : :
2484 : 21106 : if (*p2 != ' ' && *p2 != '\t')
2485 : 0 : fatal_error (input_location,
2486 : : "specs %%rename syntax malformed after "
2487 : : "%td characters", p2 - buffer);
2488 : :
2489 : 21106 : name_len = p2 - p1;
2490 : 21106 : *p2++ = '\0';
2491 : 21106 : while (*p2 == ' ' || *p2 == '\t')
2492 : 0 : p2++;
2493 : :
2494 : 21106 : 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 : 168848 : while (*p3 && !ISSPACE ((unsigned char) *p3))
2502 : 147742 : p3++;
2503 : :
2504 : 21106 : if (p3 != p - 1)
2505 : 0 : fatal_error (input_location,
2506 : : "specs %%rename syntax malformed after "
2507 : : "%td characters", p3 - buffer);
2508 : 21106 : *p3 = '\0';
2509 : :
2510 : 422120 : for (sl = specs; sl; sl = sl->next)
2511 : 422120 : if (name_len == sl->name_len && !strcmp (sl->name, p1))
2512 : : break;
2513 : :
2514 : 21106 : if (!sl)
2515 : 0 : fatal_error (input_location,
2516 : : "specs %s spec was not found to be renamed", p1);
2517 : :
2518 : 21106 : if (strcmp (p1, p2) == 0)
2519 : 0 : continue;
2520 : :
2521 : 991982 : for (newsl = specs; newsl; newsl = newsl->next)
2522 : 970876 : 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 : 21106 : 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 : 21106 : set_spec (p2, *(sl->ptr_spec), user_p);
2537 : 21106 : if (sl->alloc_p)
2538 : 21106 : free (CONST_CAST (char *, *(sl->ptr_spec)));
2539 : :
2540 : 21106 : *(sl->ptr_spec) = "";
2541 : 21106 : sl->alloc_p = 0;
2542 : 21106 : continue;
2543 : 21106 : }
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 : 192862467 : while (*p1 && *p1 != ':' && *p1 != '\n')
2553 : 178816071 : p1++;
2554 : :
2555 : : /* The colon shouldn't be missing. */
2556 : 14046396 : 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 : 14046396 : while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t'))
2564 : 0 : p2--;
2565 : :
2566 : : /* Copy the suffix to a string. */
2567 : 14046396 : suffix = save_string (p, p2 - p);
2568 : : /* Find the next line. */
2569 : 14046396 : p = skip_whitespace (p1 + 1);
2570 : 14046396 : 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 : 2790941703 : while (*p1 && !(*p1 == '\n' && (p1[1] == '\n' || p1[1] == '\0')))
2578 : 2776895307 : p1++;
2579 : :
2580 : : /* Specs end at the blank line and do not include the newline. */
2581 : 14046396 : spec = save_string (p, p1 - p);
2582 : 14046396 : p = p1;
2583 : :
2584 : : /* Delete backslash-newline sequences from the spec. */
2585 : 14046396 : in = spec;
2586 : 14046396 : out = spec;
2587 : 2804988097 : while (*in != 0)
2588 : : {
2589 : 2776895305 : if (in[0] == '\\' && in[1] == '\n')
2590 : 2 : in += 2;
2591 : 2776895303 : else if (in[0] == '#')
2592 : 0 : while (*in && *in != '\n')
2593 : 0 : in++;
2594 : :
2595 : : else
2596 : 2776895303 : *out++ = *in++;
2597 : : }
2598 : 14046396 : *out = 0;
2599 : :
2600 : 14046396 : if (suffix[0] == '*')
2601 : : {
2602 : 14046396 : if (! strcmp (suffix, "*link_command"))
2603 : 298283 : link_command_spec = spec;
2604 : : else
2605 : : {
2606 : 13748113 : set_spec (suffix + 1, spec, user_p);
2607 : 13748113 : 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 : 14046396 : if (*suffix == 0)
2623 : 0 : link_command_spec = spec;
2624 : : }
2625 : :
2626 : 328917 : if (link_command_spec == 0)
2627 : 0 : fatal_error (input_location, "spec file has no spec for linking");
2628 : :
2629 : 328917 : XDELETEVEC (buffer);
2630 : 328917 : }
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 : 710722 : record_temp_file (const char *filename, int always_delete, int fail_delete)
2673 : : {
2674 : 710722 : char *const name = xstrdup (filename);
2675 : :
2676 : 710722 : if (always_delete)
2677 : : {
2678 : 535853 : struct temp_file *temp;
2679 : 929011 : for (temp = always_delete_queue; temp; temp = temp->next)
2680 : 559709 : if (! filename_cmp (name, temp->name))
2681 : : {
2682 : 166551 : free (name);
2683 : 166551 : goto already1;
2684 : : }
2685 : :
2686 : 369302 : temp = XNEW (struct temp_file);
2687 : 369302 : temp->next = always_delete_queue;
2688 : 369302 : temp->name = name;
2689 : 369302 : always_delete_queue = temp;
2690 : :
2691 : 710722 : already1:;
2692 : : }
2693 : :
2694 : 710722 : if (fail_delete)
2695 : : {
2696 : 285759 : struct temp_file *temp;
2697 : 290790 : for (temp = failure_delete_queue; temp; temp = temp->next)
2698 : 5120 : if (! filename_cmp (name, temp->name))
2699 : : {
2700 : 89 : free (name);
2701 : 89 : goto already2;
2702 : : }
2703 : :
2704 : 285670 : temp = XNEW (struct temp_file);
2705 : 285670 : temp->next = failure_delete_queue;
2706 : 285670 : temp->name = name;
2707 : 285670 : failure_delete_queue = temp;
2708 : :
2709 : 710722 : already2:;
2710 : : }
2711 : 710722 : }
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 : 392600 : delete_if_ordinary (const char *name)
2728 : : {
2729 : 392600 : 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 : 392600 : DELETE_IF_ORDINARY (name, st, verbose_flag);
2743 : 392600 : }
2744 : :
2745 : : static void
2746 : 584967 : delete_temp_files (void)
2747 : : {
2748 : 584967 : struct temp_file *temp;
2749 : :
2750 : 954269 : for (temp = always_delete_queue; temp; temp = temp->next)
2751 : 369302 : delete_if_ordinary (temp->name);
2752 : 584967 : always_delete_queue = 0;
2753 : 584967 : }
2754 : :
2755 : : /* Delete all the files to be deleted on error. */
2756 : :
2757 : : static void
2758 : 58592 : delete_failure_queue (void)
2759 : : {
2760 : 58592 : struct temp_file *temp;
2761 : :
2762 : 81890 : for (temp = failure_delete_queue; temp; temp = temp->next)
2763 : 23298 : delete_if_ordinary (temp->name);
2764 : 58592 : }
2765 : :
2766 : : static void
2767 : 546038 : clear_failure_queue (void)
2768 : : {
2769 : 546038 : failure_delete_queue = 0;
2770 : 546038 : }
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 : 2848357 : 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 : 2848357 : const char *multi_dir = NULL;
2794 : 2848357 : const char *multi_os_dir = NULL;
2795 : 2848357 : const char *multiarch_suffix = NULL;
2796 : : const char *multi_suffix;
2797 : : const char *just_multi_suffix;
2798 : 2848357 : char *path = NULL;
2799 : 2848357 : decltype (callback (nullptr)) ret = nullptr;
2800 : 2848357 : bool skip_multi_dir = false;
2801 : 2848357 : bool skip_multi_os_dir = false;
2802 : :
2803 : 2848357 : multi_suffix = machine_suffix;
2804 : 2848357 : just_multi_suffix = just_machine_suffix;
2805 : 2848357 : if (do_multi && multilib_dir && strcmp (multilib_dir, ".") != 0)
2806 : : {
2807 : 15828 : multi_dir = concat (multilib_dir, dir_separator_str, NULL);
2808 : 15828 : multi_suffix = concat (multi_suffix, multi_dir, NULL);
2809 : 15828 : just_multi_suffix = concat (just_multi_suffix, multi_dir, NULL);
2810 : : }
2811 : 1237973 : if (do_multi && multilib_os_dir && strcmp (multilib_os_dir, ".") != 0)
2812 : 938627 : multi_os_dir = concat (multilib_os_dir, dir_separator_str, NULL);
2813 : 2848357 : if (multiarch_dir)
2814 : 0 : multiarch_suffix = concat (multiarch_dir, dir_separator_str, NULL);
2815 : :
2816 : : while (1)
2817 : : {
2818 : 3274034 : size_t multi_dir_len = 0;
2819 : 3274034 : size_t multi_os_dir_len = 0;
2820 : 3274034 : size_t multiarch_len = 0;
2821 : : size_t suffix_len;
2822 : : size_t just_suffix_len;
2823 : : size_t len;
2824 : :
2825 : 3274034 : if (multi_dir)
2826 : 15828 : multi_dir_len = strlen (multi_dir);
2827 : 3274034 : if (multi_os_dir)
2828 : 938627 : multi_os_dir_len = strlen (multi_os_dir);
2829 : 3274034 : if (multiarch_suffix)
2830 : 0 : multiarch_len = strlen (multiarch_suffix);
2831 : 3274034 : suffix_len = strlen (multi_suffix);
2832 : 3274034 : just_suffix_len = strlen (just_multi_suffix);
2833 : :
2834 : 3274034 : if (path == NULL)
2835 : : {
2836 : 2848357 : len = paths->max_len + extra_space + 1;
2837 : 2848357 : len += MAX (MAX (suffix_len, multi_os_dir_len), multiarch_len);
2838 : 2848357 : path = XNEWVEC (char, len);
2839 : : }
2840 : :
2841 : 12825344 : for (pl = paths->plist; pl != 0; pl = pl->next)
2842 : : {
2843 : 11234373 : len = strlen (pl->prefix);
2844 : 11234373 : memcpy (path, pl->prefix, len);
2845 : :
2846 : : /* Look first in MACHINE/VERSION subdirectory. */
2847 : 11234373 : if (!skip_multi_dir)
2848 : : {
2849 : 8218710 : memcpy (path + len, multi_suffix, suffix_len + 1);
2850 : 8218710 : ret = callback (path);
2851 : 5288542 : 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 : 8218710 : && 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 : 8218710 : && !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 : 11234373 : if (!pl->require_machine_suffix
2878 : 17862764 : && !(pl->os_multilib ? skip_multi_os_dir : skip_multi_dir))
2879 : : {
2880 : : const char *this_multi;
2881 : : size_t this_multi_len;
2882 : :
2883 : 10045046 : if (pl->os_multilib)
2884 : : {
2885 : : this_multi = multi_os_dir;
2886 : : this_multi_len = multi_os_dir_len;
2887 : : }
2888 : : else
2889 : : {
2890 : 5439064 : this_multi = multi_dir;
2891 : 5439064 : this_multi_len = multi_dir_len;
2892 : : }
2893 : :
2894 : 10045046 : if (this_multi_len)
2895 : 2800037 : memcpy (path + len, this_multi, this_multi_len + 1);
2896 : : else
2897 : 7245009 : path[len] = '\0';
2898 : :
2899 : 10045046 : ret = callback (path);
2900 : 5951336 : if (ret)
2901 : : break;
2902 : : }
2903 : : }
2904 : 2507252 : if (pl)
2905 : : break;
2906 : :
2907 : 1590971 : 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 : 425677 : if (multi_dir)
2913 : : {
2914 : 10126 : free (CONST_CAST (char *, multi_dir));
2915 : 10126 : multi_dir = NULL;
2916 : 10126 : free (CONST_CAST (char *, multi_suffix));
2917 : 10126 : multi_suffix = machine_suffix;
2918 : 10126 : free (CONST_CAST (char *, just_multi_suffix));
2919 : 10126 : just_multi_suffix = just_machine_suffix;
2920 : : }
2921 : : else
2922 : : skip_multi_dir = true;
2923 : 425677 : if (multi_os_dir)
2924 : : {
2925 : 425677 : free (CONST_CAST (char *, multi_os_dir));
2926 : 425677 : multi_os_dir = NULL;
2927 : : }
2928 : : else
2929 : : skip_multi_os_dir = true;
2930 : : }
2931 : :
2932 : 2848357 : 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 : 2848357 : if (multi_os_dir)
2939 : 512950 : free (CONST_CAST (char *, multi_os_dir));
2940 : 2337169 : if (ret != path)
2941 : 1165294 : free (path);
2942 : 2848357 : 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 : 1775283 : xputenv (const char *string)
2949 : : {
2950 : 0 : env.xput (string);
2951 : 136504 : }
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 : 511188 : build_search_list (const struct path_prefix *paths, const char *prefix,
2963 : : bool check_dir, bool do_multi)
2964 : : {
2965 : 511188 : struct obstack *const ob = &collect_obstack;
2966 : 511188 : bool first_time = true;
2967 : :
2968 : 511188 : obstack_grow (&collect_obstack, prefix, strlen (prefix));
2969 : 511188 : obstack_1grow (&collect_obstack, '=');
2970 : :
2971 : : /* Callback adds path to obstack being built. */
2972 : 511188 : for_each_path (paths, do_multi, 0, [&](char *path) -> void*
2973 : : {
2974 : 7023878 : if (check_dir && !is_directory (path))
2975 : : return NULL;
2976 : :
2977 : 2585657 : if (!first_time)
2978 : 2075603 : obstack_1grow (ob, PATH_SEPARATOR);
2979 : :
2980 : 2585657 : obstack_grow (ob, path, strlen (path));
2981 : :
2982 : 2585657 : first_time = false;
2983 : 2585657 : return NULL;
2984 : : });
2985 : :
2986 : 511188 : obstack_1grow (&collect_obstack, '\0');
2987 : 511188 : 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 : 511132 : putenv_from_prefixes (const struct path_prefix *paths, const char *env_var,
2995 : : bool do_multi)
2996 : : {
2997 : 511132 : xputenv (build_search_list (paths, env_var, true, do_multi));
2998 : 511132 : }
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 : 7879164 : access_check (const char *name, int mode)
3005 : : {
3006 : 7879164 : if (mode == X_OK)
3007 : : {
3008 : 1521332 : struct stat st;
3009 : :
3010 : 1521332 : if (stat (name, &st) < 0
3011 : 1521332 : || S_ISDIR (st.st_mode))
3012 : 773324 : return -1;
3013 : : }
3014 : :
3015 : 7105840 : 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 : 1783035 : 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 : 1783035 : 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 : 1783034 : const char *suffix = (mode & X_OK) != 0 ? HOST_EXECUTABLE_SUFFIX : "";
3039 : 1783034 : const int name_len = strlen (name);
3040 : 1783034 : 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 : 1783034 : return for_each_path (pprefix, do_multi,
3047 : : name_len + suffix_len,
3048 : 1783034 : [=](char *path) -> char*
3049 : : {
3050 : 7879164 : size_t len = strlen (path);
3051 : :
3052 : 7879164 : memcpy (path + len, name, name_len);
3053 : 7879164 : len += name_len;
3054 : :
3055 : : /* Some systems have a suffix for executable files.
3056 : : So try appending that first. */
3057 : 7879164 : 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 : 7879164 : path[len] = '\0';
3065 : 7879164 : 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 : 754031 : 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 : 3906119 : 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 : 3906119 : struct prefix_list *pl, **prev;
3127 : 3906119 : int len;
3128 : :
3129 : 3906119 : for (prev = &pprefix->plist;
3130 : 12374705 : (*prev) != NULL && (*prev)->priority <= priority;
3131 : 8468586 : prev = &(*prev)->next)
3132 : : ;
3133 : :
3134 : : /* Keep track of the longest prefix. */
3135 : :
3136 : 3906119 : prefix = update_path (prefix, component);
3137 : 3906119 : len = strlen (prefix);
3138 : 3906119 : if (len > pprefix->max_len)
3139 : 2120538 : pprefix->max_len = len;
3140 : :
3141 : 3906119 : pl = XNEW (struct prefix_list);
3142 : 3906119 : pl->prefix = prefix;
3143 : 3906119 : pl->require_machine_suffix = require_machine_suffix;
3144 : 3906119 : pl->priority = priority;
3145 : 3906119 : pl->os_multilib = os_multilib;
3146 : :
3147 : : /* Insert after PREV. */
3148 : 3906119 : pl->next = (*prev);
3149 : 3906119 : (*prev) = pl;
3150 : 3906119 : }
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 : 598688 : 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 : 598688 : if (!IS_ABSOLUTE_PATH (prefix))
3161 : 0 : fatal_error (input_location, "system path %qs is not absolute", prefix);
3162 : :
3163 : 598688 : 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 : 598688 : add_prefix (pprefix, prefix, component, priority,
3186 : : require_machine_suffix, os_multilib);
3187 : 598688 : }
3188 : :
3189 : : /* Same as add_prefix, but prepending target_sysroot_hdrs_suffix to prefix. */
3190 : :
3191 : : static void
3192 : 30956 : 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 : 30956 : if (!IS_ABSOLUTE_PATH (prefix))
3198 : 0 : fatal_error (input_location, "system path %qs is not absolute", prefix);
3199 : :
3200 : 30956 : 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 : 30956 : add_prefix (pprefix, prefix, component, priority,
3223 : : require_machine_suffix, os_multilib);
3224 : 30956 : }
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 : 548073 : execute (void)
3235 : : {
3236 : 548073 : int i;
3237 : 548073 : int n_commands; /* # of command. */
3238 : 548073 : char *string;
3239 : 548073 : struct pex_obj *pex;
3240 : 548073 : struct command
3241 : : {
3242 : : const char *prog; /* program name. */
3243 : : const char **argv; /* vector of args. */
3244 : : };
3245 : 548073 : const char *arg;
3246 : :
3247 : 548073 : struct command *commands; /* each command buffer with above info. */
3248 : :
3249 : 548073 : gcc_assert (!processing_spec_function);
3250 : :
3251 : 548073 : 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 : 17355860 : for (n_commands = 1, i = 0; argbuf.iterate (i, &arg); i++)
3261 : 16807787 : if (strcmp (arg, "|") == 0)
3262 : 0 : n_commands++;
3263 : :
3264 : : /* Get storage for each command. */
3265 : 548073 : 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 : 548073 : argbuf.safe_push (0);
3272 : :
3273 : 548073 : commands[0].prog = argbuf[0]; /* first command. */
3274 : 548073 : commands[0].argv = argbuf.address ();
3275 : :
3276 : 548073 : if (!wrapper_string)
3277 : : {
3278 : 548073 : string = find_a_program(commands[0].prog);
3279 : 548073 : if (string)
3280 : 545444 : commands[0].argv[0] = string;
3281 : : }
3282 : :
3283 : 17903933 : for (n_commands = 1, i = 0; argbuf.iterate (i, &arg); i++)
3284 : 17355860 : 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 : 548073 : if (verbose_flag)
3302 : : {
3303 : : /* For help listings, put a blank line between sub-processes. */
3304 : 1407 : if (print_help_list)
3305 : 9 : fputc ('\n', stderr);
3306 : :
3307 : : /* Print each piped command as a separate line. */
3308 : 2814 : for (i = 0; i < n_commands; i++)
3309 : : {
3310 : 1407 : const char *const *j;
3311 : :
3312 : 1407 : if (verbose_only_flag)
3313 : : {
3314 : 18020 : for (j = commands[i].argv; *j; j++)
3315 : : {
3316 : : const char *p;
3317 : 430397 : for (p = *j; *p; ++p)
3318 : 415904 : if (!ISALNUM ((unsigned char) *p)
3319 : 98325 : && *p != '_' && *p != '/' && *p != '-' && *p != '.')
3320 : : break;
3321 : 16995 : if (*p || !*j)
3322 : : {
3323 : 2502 : fprintf (stderr, " \"");
3324 : 130122 : for (p = *j; *p; ++p)
3325 : : {
3326 : 127620 : if (*p == '"' || *p == '\\' || *p == '$')
3327 : 0 : fputc ('\\', stderr);
3328 : 127620 : fputc (*p, stderr);
3329 : : }
3330 : 2502 : fputc ('"', stderr);
3331 : : }
3332 : : /* If it's empty, print "". */
3333 : 14493 : else if (!**j)
3334 : 0 : fprintf (stderr, " \"\"");
3335 : : else
3336 : 14493 : 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 : 1407 : if (i + 1 != n_commands)
3349 : 0 : fprintf (stderr, " |");
3350 : 1407 : fprintf (stderr, "\n");
3351 : : }
3352 : 1407 : fflush (stderr);
3353 : 1407 : 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 : 1025 : execution_count++;
3360 : 1025 : 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 : 547048 : pex = pex_init (PEX_USE_PIPES | ((report_times || report_times_to_file)
3405 : : ? PEX_RECORD_TIMES : 0),
3406 : : progname, temp_filename);
3407 : 547048 : if (pex == NULL)
3408 : : fatal_error (input_location, "%<pex_init%> failed: %m");
3409 : :
3410 : 1094096 : for (i = 0; i < n_commands; i++)
3411 : : {
3412 : 547048 : const char *errmsg;
3413 : 547048 : int err;
3414 : 547048 : const char *string = commands[i].argv[0];
3415 : :
3416 : 547048 : errmsg = pex_run (pex,
3417 : 547048 : ((i + 1 == n_commands ? PEX_LAST : 0)
3418 : 547048 : | (string == commands[i].prog ? PEX_SEARCH : 0)),
3419 : : string, CONST_CAST (char **, commands[i].argv),
3420 : : NULL, NULL, &err);
3421 : 547048 : 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 : 547048 : if (i && string != commands[i].prog)
3431 : 0 : free (CONST_CAST (char *, string));
3432 : : }
3433 : :
3434 : 547048 : execution_count++;
3435 : :
3436 : : /* Wait for all the subprocesses to finish. */
3437 : :
3438 : 547048 : {
3439 : 547048 : int *statuses;
3440 : 547048 : struct pex_time *times = NULL;
3441 : 547048 : int ret_code = 0;
3442 : :
3443 : 547048 : statuses = XALLOCAVEC (int, n_commands);
3444 : 547048 : if (!pex_get_status (pex, n_commands, statuses))
3445 : 0 : fatal_error (input_location, "failed to get exit status: %m");
3446 : :
3447 : 547048 : 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 : 547048 : pex_free (pex);
3455 : :
3456 : 1094096 : for (i = 0; i < n_commands; ++i)
3457 : : {
3458 : 547048 : int status = statuses[i];
3459 : :
3460 : 547048 : 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 : 547048 : else if (WIFEXITED (status)
3506 : 547048 : && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
3507 : : {
3508 : : /* For ICEs in cc1, cc1obj, cc1plus see if it is
3509 : : reproducible or not. */
3510 : 29334 : const char *p;
3511 : 29334 : 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 : 29334 : && startswith (p + 1, "cc1"))
3516 : 0 : try_generate_repro (commands[0].argv);
3517 : 29334 : if (WEXITSTATUS (status) > greatest_status)
3518 : 21 : greatest_status = WEXITSTATUS (status);
3519 : : ret_code = -1;
3520 : : }
3521 : :
3522 : 547048 : 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 : 547048 : if (commands[0].argv[0] != commands[0].prog)
3575 : 544419 : 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 : : bool artificial;
3627 : : };
3628 : :
3629 : : /* Also a vector of input files specified. */
3630 : :
3631 : : static struct infile *infiles;
3632 : :
3633 : : int n_infiles;
3634 : :
3635 : : static int n_infiles_alloc;
3636 : :
3637 : : /* True if undefined environment variables encountered during spec processing
3638 : : are ok to ignore, typically when we're running for --help or --version. */
3639 : :
3640 : : static bool spec_undefvar_allowed;
3641 : :
3642 : : /* True if multiple input files are being compiled to a single
3643 : : assembly file. */
3644 : :
3645 : : static bool combine_inputs;
3646 : :
3647 : : /* This counts the number of libraries added by lang_specific_driver, so that
3648 : : we can tell if there were any user supplied any files or libraries. */
3649 : :
3650 : : static int added_libraries;
3651 : :
3652 : : /* And a vector of corresponding output files is made up later. */
3653 : :
3654 : : const char **outfiles;
3655 : :
3656 : : #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3657 : :
3658 : : /* Convert NAME to a new name if it is the standard suffix. DO_EXE
3659 : : is true if we should look for an executable suffix. DO_OBJ
3660 : : is true if we should look for an object suffix. */
3661 : :
3662 : : static const char *
3663 : : convert_filename (const char *name, int do_exe ATTRIBUTE_UNUSED,
3664 : : int do_obj ATTRIBUTE_UNUSED)
3665 : : {
3666 : : #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3667 : : int i;
3668 : : #endif
3669 : : int len;
3670 : :
3671 : : if (name == NULL)
3672 : : return NULL;
3673 : :
3674 : : len = strlen (name);
3675 : :
3676 : : #ifdef HAVE_TARGET_OBJECT_SUFFIX
3677 : : /* Convert x.o to x.obj if TARGET_OBJECT_SUFFIX is ".obj". */
3678 : : if (do_obj && len > 2
3679 : : && name[len - 2] == '.'
3680 : : && name[len - 1] == 'o')
3681 : : {
3682 : : obstack_grow (&obstack, name, len - 2);
3683 : : obstack_grow0 (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX));
3684 : : name = XOBFINISH (&obstack, const char *);
3685 : : }
3686 : : #endif
3687 : :
3688 : : #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3689 : : /* If there is no filetype, make it the executable suffix (which includes
3690 : : the "."). But don't get confused if we have just "-o". */
3691 : : if (! do_exe || TARGET_EXECUTABLE_SUFFIX[0] == 0 || not_actual_file_p (name))
3692 : : return name;
3693 : :
3694 : : for (i = len - 1; i >= 0; i--)
3695 : : if (IS_DIR_SEPARATOR (name[i]))
3696 : : break;
3697 : :
3698 : : for (i++; i < len; i++)
3699 : : if (name[i] == '.')
3700 : : return name;
3701 : :
3702 : : obstack_grow (&obstack, name, len);
3703 : : obstack_grow0 (&obstack, TARGET_EXECUTABLE_SUFFIX,
3704 : : strlen (TARGET_EXECUTABLE_SUFFIX));
3705 : : name = XOBFINISH (&obstack, const char *);
3706 : : #endif
3707 : :
3708 : : return name;
3709 : : }
3710 : : #endif
3711 : :
3712 : : /* Display the command line switches accepted by gcc. */
3713 : : static void
3714 : 4 : display_help (void)
3715 : : {
3716 : 4 : printf (_("Usage: %s [options] file...\n"), progname);
3717 : 4 : fputs (_("Options:\n"), stdout);
3718 : :
3719 : 4 : fputs (_(" -pass-exit-codes Exit with highest error code from a phase.\n"), stdout);
3720 : 4 : fputs (_(" --help Display this information.\n"), stdout);
3721 : 4 : fputs (_(" --target-help Display target specific command line options "
3722 : : "(including assembler and linker options).\n"), stdout);
3723 : 4 : fputs (_(" --help={common|optimizers|params|target|warnings|[^]{joined|separate|undocumented}}[,...].\n"), stdout);
3724 : 4 : fputs (_(" Display specific types of command line options.\n"), stdout);
3725 : 4 : if (! verbose_flag)
3726 : 1 : fputs (_(" (Use '-v --help' to display command line options of sub-processes).\n"), stdout);
3727 : 4 : fputs (_(" --version Display compiler version information.\n"), stdout);
3728 : 4 : fputs (_(" -dumpspecs Display all of the built in spec strings.\n"), stdout);
3729 : 4 : fputs (_(" -dumpversion Display the version of the compiler.\n"), stdout);
3730 : 4 : fputs (_(" -dumpmachine Display the compiler's target processor.\n"), stdout);
3731 : 4 : fputs (_(" -foffload=<targets> Specify offloading targets.\n"), stdout);
3732 : 4 : fputs (_(" -print-search-dirs Display the directories in the compiler's search path.\n"), stdout);
3733 : 4 : fputs (_(" -print-libgcc-file-name Display the name of the compiler's companion library.\n"), stdout);
3734 : 4 : fputs (_(" -print-file-name=<lib> Display the full path to library <lib>.\n"), stdout);
3735 : 4 : fputs (_(" -print-prog-name=<prog> Display the full path to compiler component <prog>.\n"), stdout);
3736 : 4 : fputs (_("\
3737 : : -print-multiarch Display the target's normalized GNU triplet, used as\n\
3738 : : a component in the library path.\n"), stdout);
3739 : 4 : fputs (_(" -print-multi-directory Display the root directory for versions of libgcc.\n"), stdout);
3740 : 4 : fputs (_("\
3741 : : -print-multi-lib Display the mapping between command line options and\n\
3742 : : multiple library search directories.\n"), stdout);
3743 : 4 : fputs (_(" -print-multi-os-directory Display the relative path to OS libraries.\n"), stdout);
3744 : 4 : fputs (_(" -print-sysroot Display the target libraries directory.\n"), stdout);
3745 : 4 : fputs (_(" -print-sysroot-headers-suffix Display the sysroot suffix used to find headers.\n"), stdout);
3746 : 4 : fputs (_(" -Wa,<options> Pass comma-separated <options> on to the assembler.\n"), stdout);
3747 : 4 : fputs (_(" -Wp,<options> Pass comma-separated <options> on to the preprocessor.\n"), stdout);
3748 : 4 : fputs (_(" -Wl,<options> Pass comma-separated <options> on to the linker.\n"), stdout);
3749 : 4 : fputs (_(" -Xassembler <arg> Pass <arg> on to the assembler.\n"), stdout);
3750 : 4 : fputs (_(" -Xpreprocessor <arg> Pass <arg> on to the preprocessor.\n"), stdout);
3751 : 4 : fputs (_(" -Xlinker <arg> Pass <arg> on to the linker.\n"), stdout);
3752 : 4 : fputs (_(" -save-temps Do not delete intermediate files.\n"), stdout);
3753 : 4 : fputs (_(" -save-temps=<arg> Do not delete intermediate files.\n"), stdout);
3754 : 4 : fputs (_("\
3755 : : -no-canonical-prefixes Do not canonicalize paths when building relative\n\
3756 : : prefixes to other gcc components.\n"), stdout);
3757 : 4 : fputs (_(" -pipe Use pipes rather than intermediate files.\n"), stdout);
3758 : 4 : fputs (_(" -time Time the execution of each subprocess.\n"), stdout);
3759 : 4 : fputs (_(" -specs=<file> Override built-in specs with the contents of <file>.\n"), stdout);
3760 : 4 : fputs (_(" -std=<standard> Assume that the input sources are for <standard>.\n"), stdout);
3761 : 4 : fputs (_("\
3762 : : --sysroot=<directory> Use <directory> as the root directory for headers\n\
3763 : : and libraries.\n"), stdout);
3764 : 4 : fputs (_(" -B <directory> Add <directory> to the compiler's search paths.\n"), stdout);
3765 : 4 : fputs (_(" -v Display the programs invoked by the compiler.\n"), stdout);
3766 : 4 : fputs (_(" -### Like -v but options quoted and commands not executed.\n"), stdout);
3767 : 4 : fputs (_(" -E Preprocess only; do not compile, assemble or link.\n"), stdout);
3768 : 4 : fputs (_(" -S Compile only; do not assemble or link.\n"), stdout);
3769 : 4 : fputs (_(" -c Compile and assemble, but do not link.\n"), stdout);
3770 : 4 : fputs (_(" -o <file> Place the output into <file>.\n"), stdout);
3771 : 4 : fputs (_(" -pie Create a dynamically linked position independent\n\
3772 : : executable.\n"), stdout);
3773 : 4 : fputs (_(" -shared Create a shared library.\n"), stdout);
3774 : 4 : fputs (_("\
3775 : : -x <language> Specify the language of the following input files.\n\
3776 : : Permissible languages include: c c++ assembler none\n\
3777 : : 'none' means revert to the default behavior of\n\
3778 : : guessing the language based on the file's extension.\n\
3779 : : "), stdout);
3780 : :
3781 : 4 : printf (_("\
3782 : : \nOptions starting with -g, -f, -m, -O, -W, or --param are automatically\n\
3783 : : passed on to the various sub-processes invoked by %s. In order to pass\n\
3784 : : other options on to these processes the -W<letter> options must be used.\n\
3785 : : "), progname);
3786 : :
3787 : : /* The rest of the options are displayed by invocations of the various
3788 : : sub-processes. */
3789 : 4 : }
3790 : :
3791 : : static void
3792 : 0 : add_preprocessor_option (const char *option, int len)
3793 : : {
3794 : 0 : preprocessor_options.safe_push (save_string (option, len));
3795 : 0 : }
3796 : :
3797 : : static void
3798 : 195 : add_assembler_option (const char *option, int len)
3799 : : {
3800 : 195 : assembler_options.safe_push (save_string (option, len));
3801 : 195 : }
3802 : :
3803 : : static void
3804 : 82 : add_linker_option (const char *option, int len)
3805 : : {
3806 : 82 : linker_options.safe_push (save_string (option, len));
3807 : 82 : }
3808 : :
3809 : : /* Allocate space for an input file in infiles. */
3810 : :
3811 : : static void
3812 : 890476 : alloc_infile (void)
3813 : : {
3814 : 890476 : if (n_infiles_alloc == 0)
3815 : : {
3816 : 299345 : n_infiles_alloc = 16;
3817 : 299345 : infiles = XNEWVEC (struct infile, n_infiles_alloc);
3818 : : }
3819 : 591131 : else if (n_infiles_alloc == n_infiles)
3820 : : {
3821 : 247 : n_infiles_alloc *= 2;
3822 : 247 : infiles = XRESIZEVEC (struct infile, infiles, n_infiles_alloc);
3823 : : }
3824 : 890476 : }
3825 : :
3826 : : /* Store an input file with the given NAME and LANGUAGE in
3827 : : infiles. */
3828 : :
3829 : : static void
3830 : 591132 : add_infile (const char *name, const char *language, bool art = false)
3831 : : {
3832 : 591132 : alloc_infile ();
3833 : 591132 : infiles[n_infiles].name = name;
3834 : 591132 : infiles[n_infiles].artificial = art;
3835 : 591132 : infiles[n_infiles++].language = language;
3836 : 591132 : }
3837 : :
3838 : : /* Allocate space for a switch in switches. */
3839 : :
3840 : : static void
3841 : 7645099 : alloc_switch (void)
3842 : : {
3843 : 7645099 : if (n_switches_alloc == 0)
3844 : : {
3845 : 299659 : n_switches_alloc = 16;
3846 : 299659 : switches = XNEWVEC (struct switchstr, n_switches_alloc);
3847 : : }
3848 : 7345440 : else if (n_switches_alloc == n_switches)
3849 : : {
3850 : 271119 : n_switches_alloc *= 2;
3851 : 271119 : switches = XRESIZEVEC (struct switchstr, switches, n_switches_alloc);
3852 : : }
3853 : 7645099 : }
3854 : :
3855 : : /* Save an option OPT with N_ARGS arguments in array ARGS, marking it
3856 : : as validated if VALIDATED and KNOWN if it is an internal switch. */
3857 : :
3858 : : static void
3859 : 6780311 : save_switch (const char *opt, size_t n_args, const char *const *args,
3860 : : bool validated, bool known)
3861 : : {
3862 : 6780311 : alloc_switch ();
3863 : 6780311 : switches[n_switches].part1 = opt + 1;
3864 : 6780311 : if (n_args == 0)
3865 : 5242879 : switches[n_switches].args = 0;
3866 : : else
3867 : : {
3868 : 1537432 : switches[n_switches].args = XNEWVEC (const char *, n_args + 1);
3869 : 1537432 : memcpy (switches[n_switches].args, args, n_args * sizeof (const char *));
3870 : 1537432 : switches[n_switches].args[n_args] = NULL;
3871 : : }
3872 : :
3873 : 6780311 : switches[n_switches].live_cond = 0;
3874 : 6780311 : switches[n_switches].validated = validated;
3875 : 6780311 : switches[n_switches].known = known;
3876 : 6780311 : switches[n_switches].ordering = 0;
3877 : 6780311 : n_switches++;
3878 : 6780311 : }
3879 : :
3880 : : /* Set the SOURCE_DATE_EPOCH environment variable to the current time if it is
3881 : : not set already. */
3882 : :
3883 : : static void
3884 : 619 : set_source_date_epoch_envvar ()
3885 : : {
3886 : : /* Array size is 21 = ceil(log_10(2^64)) + 1 to hold string representations
3887 : : of 64 bit integers. */
3888 : 619 : char source_date_epoch[21];
3889 : 619 : time_t tt;
3890 : :
3891 : 619 : errno = 0;
3892 : 619 : tt = time (NULL);
3893 : 619 : if (tt < (time_t) 0 || errno != 0)
3894 : 0 : tt = (time_t) 0;
3895 : :
3896 : 619 : snprintf (source_date_epoch, 21, "%llu", (unsigned long long) tt);
3897 : : /* Using setenv instead of xputenv because we want the variable to remain
3898 : : after finalizing so that it's still set in the second run when using
3899 : : -fcompare-debug. */
3900 : 619 : setenv ("SOURCE_DATE_EPOCH", source_date_epoch, 0);
3901 : 619 : }
3902 : :
3903 : : /* Handle an option DECODED that is unknown to the option-processing
3904 : : machinery. */
3905 : :
3906 : : static bool
3907 : 714 : driver_unknown_option_callback (const struct cl_decoded_option *decoded)
3908 : : {
3909 : 714 : const char *opt = decoded->arg;
3910 : 714 : if (opt[1] == 'W' && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-'
3911 : 93 : && !(decoded->errors & CL_ERR_NEGATIVE))
3912 : : {
3913 : : /* Leave unknown -Wno-* options for the compiler proper, to be
3914 : : diagnosed only if there are warnings. */
3915 : 91 : save_switch (decoded->canonical_option[0],
3916 : 91 : decoded->canonical_option_num_elements - 1,
3917 : : &decoded->canonical_option[1], false, true);
3918 : 91 : return false;
3919 : : }
3920 : 623 : if (decoded->opt_index == OPT_SPECIAL_unknown)
3921 : : {
3922 : : /* Give it a chance to define it a spec file. */
3923 : 623 : save_switch (decoded->canonical_option[0],
3924 : 623 : decoded->canonical_option_num_elements - 1,
3925 : : &decoded->canonical_option[1], false, false);
3926 : 623 : return false;
3927 : : }
3928 : : else
3929 : : return true;
3930 : : }
3931 : :
3932 : : /* Handle an option DECODED that is not marked as CL_DRIVER.
3933 : : LANG_MASK will always be CL_DRIVER. */
3934 : :
3935 : : static void
3936 : 4379649 : driver_wrong_lang_callback (const struct cl_decoded_option *decoded,
3937 : : unsigned int lang_mask ATTRIBUTE_UNUSED)
3938 : : {
3939 : : /* At this point, non-driver options are accepted (and expected to
3940 : : be passed down by specs) unless marked to be rejected by the
3941 : : driver. Options to be rejected by the driver but accepted by the
3942 : : compilers proper are treated just like completely unknown
3943 : : options. */
3944 : 4379649 : const struct cl_option *option = &cl_options[decoded->opt_index];
3945 : :
3946 : 4379649 : if (option->cl_reject_driver)
3947 : 0 : error ("unrecognized command-line option %qs",
3948 : 0 : decoded->orig_option_with_args_text);
3949 : : else
3950 : 4379649 : save_switch (decoded->canonical_option[0],
3951 : 4379649 : decoded->canonical_option_num_elements - 1,
3952 : : &decoded->canonical_option[1], false, true);
3953 : 4379649 : }
3954 : :
3955 : : static const char *spec_lang = 0;
3956 : : static int last_language_n_infiles;
3957 : :
3958 : :
3959 : : /* Check that GCC is configured to support the offload target. */
3960 : :
3961 : : static bool
3962 : 127 : check_offload_target_name (const char *target, ptrdiff_t len)
3963 : : {
3964 : 127 : const char *n, *c = OFFLOAD_TARGETS;
3965 : 254 : while (c)
3966 : : {
3967 : 127 : n = strchr (c, ',');
3968 : 127 : if (n == NULL)
3969 : 127 : n = strchr (c, '\0');
3970 : 127 : if (len == n - c && strncmp (target, c, n - c) == 0)
3971 : : break;
3972 : 127 : c = *n ? n + 1 : NULL;
3973 : : }
3974 : 127 : if (!c)
3975 : : {
3976 : 127 : auto_vec<const char*> candidates;
3977 : 127 : size_t olen = strlen (OFFLOAD_TARGETS) + 1;
3978 : 127 : char *cand = XALLOCAVEC (char, olen);
3979 : 127 : memcpy (cand, OFFLOAD_TARGETS, olen);
3980 : 127 : for (c = strtok (cand, ","); c; c = strtok (NULL, ","))
3981 : 0 : candidates.safe_push (c);
3982 : 127 : candidates.safe_push ("default");
3983 : 127 : candidates.safe_push ("disable");
3984 : :
3985 : 127 : char *target2 = XALLOCAVEC (char, len + 1);
3986 : 127 : memcpy (target2, target, len);
3987 : 127 : target2[len] = '\0';
3988 : :
3989 : 127 : error ("GCC is not configured to support %qs as %<-foffload=%> argument",
3990 : : target2);
3991 : :
3992 : 127 : char *s;
3993 : 127 : const char *hint = candidates_list_and_hint (target2, s, candidates);
3994 : 127 : if (hint)
3995 : 0 : inform (UNKNOWN_LOCATION,
3996 : : "valid %<-foffload=%> arguments are: %s; "
3997 : : "did you mean %qs?", s, hint);
3998 : : else
3999 : 127 : inform (UNKNOWN_LOCATION, "valid %<-foffload=%> arguments are: %s", s);
4000 : 127 : XDELETEVEC (s);
4001 : 127 : return false;
4002 : 127 : }
4003 : : return true;
4004 : : }
4005 : :
4006 : : /* Sanity check for -foffload-options. */
4007 : :
4008 : : static void
4009 : 27 : check_foffload_target_names (const char *arg)
4010 : : {
4011 : 27 : const char *cur, *next, *end;
4012 : : /* If option argument starts with '-' then no target is specified and we
4013 : : do not need to parse it. */
4014 : 27 : if (arg[0] == '-')
4015 : : return;
4016 : 0 : end = strchr (arg, '=');
4017 : 0 : if (end == NULL)
4018 : : {
4019 : 0 : error ("%<=%>options missing after %<-foffload-options=%>target");
4020 : 0 : return;
4021 : : }
4022 : :
4023 : : cur = arg;
4024 : 0 : while (cur < end)
4025 : : {
4026 : 0 : next = strchr (cur, ',');
4027 : 0 : if (next == NULL)
4028 : 0 : next = end;
4029 : 0 : next = (next > end) ? end : next;
4030 : :
4031 : : /* Retain non-supported targets after printing an error as those will not
4032 : : be processed; each enabled target only processes its triplet. */
4033 : 0 : check_offload_target_name (cur, next - cur);
4034 : 0 : cur = next + 1;
4035 : : }
4036 : : }
4037 : :
4038 : : /* Parse -foffload option argument. */
4039 : :
4040 : : static void
4041 : 2860 : handle_foffload_option (const char *arg)
4042 : : {
4043 : 2860 : const char *c, *cur, *n, *next, *end;
4044 : 2860 : char *target;
4045 : :
4046 : : /* If option argument starts with '-' then no target is specified and we
4047 : : do not need to parse it. */
4048 : 2860 : if (arg[0] == '-')
4049 : : return;
4050 : :
4051 : 2021 : end = strchr (arg, '=');
4052 : 2021 : if (end == NULL)
4053 : 2021 : end = strchr (arg, '\0');
4054 : 2021 : cur = arg;
4055 : :
4056 : 2021 : while (cur < end)
4057 : : {
4058 : 2021 : next = strchr (cur, ',');
4059 : 2021 : if (next == NULL)
4060 : 2021 : next = end;
4061 : 2021 : next = (next > end) ? end : next;
4062 : :
4063 : 2021 : target = XNEWVEC (char, next - cur + 1);
4064 : 2021 : memcpy (target, cur, next - cur);
4065 : 2021 : target[next - cur] = '\0';
4066 : :
4067 : : /* Reset offloading list and continue. */
4068 : 2021 : if (strcmp (target, "default") == 0)
4069 : : {
4070 : 0 : free (offload_targets);
4071 : 0 : offload_targets = NULL;
4072 : 0 : goto next_item;
4073 : : }
4074 : :
4075 : : /* If 'disable' is passed to the option, clean the list of
4076 : : offload targets and return, even if more targets follow.
4077 : : Likewise if GCC is not configured to support that offload target. */
4078 : 2021 : if (strcmp (target, "disable") == 0
4079 : 2021 : || !check_offload_target_name (target, next - cur))
4080 : : {
4081 : 2021 : free (offload_targets);
4082 : 2021 : offload_targets = xstrdup ("");
4083 : 2021 : return;
4084 : : }
4085 : :
4086 : 0 : if (!offload_targets)
4087 : : {
4088 : 0 : offload_targets = target;
4089 : 0 : target = NULL;
4090 : : }
4091 : : else
4092 : : {
4093 : : /* Check that the target hasn't already presented in the list. */
4094 : : c = offload_targets;
4095 : 0 : do
4096 : : {
4097 : 0 : n = strchr (c, ':');
4098 : 0 : if (n == NULL)
4099 : 0 : n = strchr (c, '\0');
4100 : :
4101 : 0 : if (next - cur == n - c && strncmp (c, target, n - c) == 0)
4102 : : break;
4103 : :
4104 : 0 : c = n + 1;
4105 : : }
4106 : 0 : while (*n);
4107 : :
4108 : : /* If duplicate is not found, append the target to the list. */
4109 : 0 : if (c > n)
4110 : : {
4111 : 0 : size_t offload_targets_len = strlen (offload_targets);
4112 : 0 : offload_targets
4113 : 0 : = XRESIZEVEC (char, offload_targets,
4114 : : offload_targets_len + 1 + next - cur + 1);
4115 : 0 : offload_targets[offload_targets_len++] = ':';
4116 : 0 : memcpy (offload_targets + offload_targets_len, target, next - cur + 1);
4117 : : }
4118 : : }
4119 : 0 : next_item:
4120 : 0 : cur = next + 1;
4121 : 0 : XDELETEVEC (target);
4122 : : }
4123 : : }
4124 : :
4125 : : /* Forward certain options to offloading compilation. */
4126 : :
4127 : : static void
4128 : 0 : forward_offload_option (size_t opt_index, const char *arg, bool validated)
4129 : : {
4130 : 0 : switch (opt_index)
4131 : : {
4132 : 0 : case OPT_l:
4133 : : /* Use a '_GCC_' prefix and standard name ('-l_GCC_m' irrespective of the
4134 : : host's 'MATH_LIBRARY', for example), so that the 'mkoffload's can tell
4135 : : this has been synthesized here, and translate/drop as necessary. */
4136 : : /* Note that certain libraries ('-lc', '-lgcc', '-lgomp', for example)
4137 : : are injected by default in offloading compilation, and therefore not
4138 : : forwarded here. */
4139 : : /* GCC libraries. */
4140 : 0 : if (/* '-lgfortran' */ strcmp (arg, "gfortran") == 0
4141 : 0 : || /* '-lstdc++' */ strcmp (arg, "stdc++") == 0)
4142 : 0 : save_switch (concat ("-foffload-options=-l_GCC_", arg, NULL),
4143 : : 0, NULL, validated, true);
4144 : : /* Other libraries. */
4145 : : else
4146 : : {
4147 : : /* The case will need special consideration where on the host
4148 : : '!need_math', but for offloading compilation still need
4149 : : '-foffload-options=-l_GCC_m'. The problem is that we don't get
4150 : : here anything like '-lm', because it's not synthesized in
4151 : : 'gcc/fortran/gfortranspec.cc:lang_specific_driver', for example.
4152 : : Generally synthesizing '-foffload-options=-l_GCC_m' etc. in the
4153 : : language specific drivers is non-trivial, needs very careful
4154 : : review of their options handling. However, this issue is not
4155 : : actually relevant for the current set of supported host/offloading
4156 : : configurations. */
4157 : 0 : int need_math = (MATH_LIBRARY[0] != '\0');
4158 : 0 : if (/* '-lm' */ (need_math && strcmp (arg, MATH_LIBRARY) == 0))
4159 : 0 : save_switch ("-foffload-options=-l_GCC_m",
4160 : : 0, NULL, validated, true);
4161 : : }
4162 : 0 : break;
4163 : 0 : default:
4164 : 0 : gcc_unreachable ();
4165 : : }
4166 : 0 : }
4167 : :
4168 : : /* Handle a driver option; arguments and return value as for
4169 : : handle_option. */
4170 : :
4171 : : static bool
4172 : 2739952 : driver_handle_option (struct gcc_options *opts,
4173 : : struct gcc_options *opts_set,
4174 : : const struct cl_decoded_option *decoded,
4175 : : unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
4176 : : location_t loc,
4177 : : const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED,
4178 : : diagnostics::context *dc,
4179 : : void (*) (void))
4180 : : {
4181 : 2739952 : size_t opt_index = decoded->opt_index;
4182 : 2739952 : const char *arg = decoded->arg;
4183 : 2739952 : const char *compare_debug_replacement_opt;
4184 : 2739952 : int value = decoded->value;
4185 : 2739952 : bool validated = false;
4186 : 2739952 : bool do_save = true;
4187 : :
4188 : 2739952 : gcc_assert (opts == &global_options);
4189 : 2739952 : gcc_assert (opts_set == &global_options_set);
4190 : 2739952 : gcc_assert (static_cast<diagnostics::kind> (kind)
4191 : : == diagnostics::kind::unspecified);
4192 : 2739952 : gcc_assert (loc == UNKNOWN_LOCATION);
4193 : 2739952 : gcc_assert (dc == global_dc);
4194 : :
4195 : 2739952 : switch (opt_index)
4196 : : {
4197 : 1 : case OPT_dumpspecs:
4198 : 1 : {
4199 : 1 : struct spec_list *sl;
4200 : 1 : init_spec ();
4201 : 47 : for (sl = specs; sl; sl = sl->next)
4202 : 46 : printf ("*%s:\n%s\n\n", sl->name, *(sl->ptr_spec));
4203 : 1 : if (link_command_spec)
4204 : 1 : printf ("*link_command:\n%s\n\n", link_command_spec);
4205 : 1 : exit (0);
4206 : : }
4207 : :
4208 : 280 : case OPT_dumpversion:
4209 : 280 : printf ("%s\n", spec_version);
4210 : 280 : exit (0);
4211 : :
4212 : 0 : case OPT_dumpmachine:
4213 : 0 : printf ("%s\n", spec_machine);
4214 : 0 : exit (0);
4215 : :
4216 : 0 : case OPT_dumpfullversion:
4217 : 0 : printf ("%s\n", BASEVER);
4218 : 0 : exit (0);
4219 : :
4220 : 78 : case OPT__version:
4221 : 78 : print_version = 1;
4222 : :
4223 : : /* CPP driver cannot obtain switch from cc1_options. */
4224 : 78 : if (is_cpp_driver)
4225 : 0 : add_preprocessor_option ("--version", strlen ("--version"));
4226 : 78 : add_assembler_option ("--version", strlen ("--version"));
4227 : 78 : add_linker_option ("--version", strlen ("--version"));
4228 : 78 : break;
4229 : :
4230 : 5 : case OPT__completion_:
4231 : 5 : validated = true;
4232 : 5 : completion = decoded->arg;
4233 : 5 : break;
4234 : :
4235 : 4 : case OPT__help:
4236 : 4 : print_help_list = 1;
4237 : :
4238 : : /* CPP driver cannot obtain switch from cc1_options. */
4239 : 4 : if (is_cpp_driver)
4240 : 0 : add_preprocessor_option ("--help", 6);
4241 : 4 : add_assembler_option ("--help", 6);
4242 : 4 : add_linker_option ("--help", 6);
4243 : 4 : break;
4244 : :
4245 : 99 : case OPT__help_:
4246 : 99 : print_subprocess_help = 2;
4247 : 99 : break;
4248 : :
4249 : 0 : case OPT__target_help:
4250 : 0 : print_subprocess_help = 1;
4251 : :
4252 : : /* CPP driver cannot obtain switch from cc1_options. */
4253 : 0 : if (is_cpp_driver)
4254 : 0 : add_preprocessor_option ("--target-help", 13);
4255 : 0 : add_assembler_option ("--target-help", 13);
4256 : 0 : add_linker_option ("--target-help", 13);
4257 : 0 : break;
4258 : :
4259 : : case OPT__no_sysroot_suffix:
4260 : : case OPT_pass_exit_codes:
4261 : : case OPT_print_search_dirs:
4262 : : case OPT_print_file_name_:
4263 : : case OPT_print_prog_name_:
4264 : : case OPT_print_multi_lib:
4265 : : case OPT_print_multi_directory:
4266 : : case OPT_print_sysroot:
4267 : : case OPT_print_multi_os_directory:
4268 : : case OPT_print_multiarch:
4269 : : case OPT_print_sysroot_headers_suffix:
4270 : : case OPT_time:
4271 : : case OPT_wrapper:
4272 : : /* These options set the variables specified in common.opt
4273 : : automatically, and do not need to be saved for spec
4274 : : processing. */
4275 : : do_save = false;
4276 : : break;
4277 : :
4278 : 392 : case OPT_print_libgcc_file_name:
4279 : 392 : print_file_name = "libgcc.a";
4280 : 392 : do_save = false;
4281 : 392 : break;
4282 : :
4283 : 0 : case OPT_fuse_ld_bfd:
4284 : 0 : use_ld = ".bfd";
4285 : 0 : break;
4286 : :
4287 : 0 : case OPT_fuse_ld_gold:
4288 : 0 : use_ld = ".gold";
4289 : 0 : break;
4290 : :
4291 : 0 : case OPT_fuse_ld_mold:
4292 : 0 : use_ld = ".mold";
4293 : 0 : break;
4294 : :
4295 : 0 : case OPT_fuse_ld_wild:
4296 : 0 : use_ld = ".wild";
4297 : 0 : break;
4298 : :
4299 : 0 : case OPT_fcompare_debug_second:
4300 : 0 : compare_debug_second = 1;
4301 : 0 : break;
4302 : :
4303 : 613 : case OPT_fcompare_debug:
4304 : 613 : switch (value)
4305 : : {
4306 : 0 : case 0:
4307 : 0 : compare_debug_replacement_opt = "-fcompare-debug=";
4308 : 0 : arg = "";
4309 : 0 : goto compare_debug_with_arg;
4310 : :
4311 : 613 : case 1:
4312 : 613 : compare_debug_replacement_opt = "-fcompare-debug=-gtoggle";
4313 : 613 : arg = "-gtoggle";
4314 : 613 : goto compare_debug_with_arg;
4315 : :
4316 : 0 : default:
4317 : 0 : gcc_unreachable ();
4318 : : }
4319 : 6 : break;
4320 : :
4321 : 6 : case OPT_fcompare_debug_:
4322 : 6 : compare_debug_replacement_opt = decoded->canonical_option[0];
4323 : 619 : compare_debug_with_arg:
4324 : 619 : gcc_assert (decoded->canonical_option_num_elements == 1);
4325 : 619 : gcc_assert (arg != NULL);
4326 : 619 : if (*arg)
4327 : 619 : compare_debug = 1;
4328 : : else
4329 : 0 : compare_debug = -1;
4330 : 619 : if (compare_debug < 0)
4331 : 0 : compare_debug_opt = NULL;
4332 : : else
4333 : 619 : compare_debug_opt = arg;
4334 : 619 : save_switch (compare_debug_replacement_opt, 0, NULL, validated, true);
4335 : 619 : set_source_date_epoch_envvar ();
4336 : 619 : return true;
4337 : :
4338 : 272434 : case OPT_fdiagnostics_color_:
4339 : 272434 : diagnostic_color_init (dc, value);
4340 : 272434 : break;
4341 : :
4342 : 265957 : case OPT_fdiagnostics_urls_:
4343 : 265957 : diagnostic_urls_init (dc, value);
4344 : 265957 : break;
4345 : :
4346 : 0 : case OPT_fdiagnostics_show_highlight_colors:
4347 : 0 : dc->set_show_highlight_colors (value);
4348 : 0 : break;
4349 : :
4350 : 0 : case OPT_fdiagnostics_format_:
4351 : 0 : {
4352 : 0 : const char *basename = (opts->x_dump_base_name ? opts->x_dump_base_name
4353 : : : opts->x_main_input_basename);
4354 : 0 : gcc_assert (dc);
4355 : 0 : diagnostics::output_format_init (*dc,
4356 : : opts->x_main_input_filename, basename,
4357 : : (enum diagnostics_output_format)value,
4358 : 0 : opts->x_flag_diagnostics_json_formatting);
4359 : 0 : break;
4360 : : }
4361 : :
4362 : 0 : case OPT_fdiagnostics_add_output_:
4363 : 0 : handle_OPT_fdiagnostics_add_output_ (*opts, *dc, arg, loc);
4364 : 0 : break;
4365 : :
4366 : 0 : case OPT_fdiagnostics_set_output_:
4367 : 0 : handle_OPT_fdiagnostics_set_output_ (*opts, *dc, arg, loc);
4368 : 0 : break;
4369 : :
4370 : 294447 : case OPT_fdiagnostics_text_art_charset_:
4371 : 294447 : dc->set_text_art_charset ((enum diagnostic_text_art_charset)value);
4372 : 294447 : break;
4373 : :
4374 : : case OPT_Wa_:
4375 : : {
4376 : : int prev, j;
4377 : : /* Pass the rest of this option to the assembler. */
4378 : :
4379 : : /* Split the argument at commas. */
4380 : : prev = 0;
4381 : 634 : for (j = 0; arg[j]; j++)
4382 : 586 : if (arg[j] == ',')
4383 : : {
4384 : 0 : add_assembler_option (arg + prev, j - prev);
4385 : 0 : prev = j + 1;
4386 : : }
4387 : :
4388 : : /* Record the part after the last comma. */
4389 : 48 : add_assembler_option (arg + prev, j - prev);
4390 : : }
4391 : 48 : do_save = false;
4392 : 48 : break;
4393 : :
4394 : : case OPT_Wp_:
4395 : : {
4396 : : int prev, j;
4397 : : /* Pass the rest of this option to the preprocessor. */
4398 : :
4399 : : /* Split the argument at commas. */
4400 : : prev = 0;
4401 : 0 : for (j = 0; arg[j]; j++)
4402 : 0 : if (arg[j] == ',')
4403 : : {
4404 : 0 : add_preprocessor_option (arg + prev, j - prev);
4405 : 0 : prev = j + 1;
4406 : : }
4407 : :
4408 : : /* Record the part after the last comma. */
4409 : 0 : add_preprocessor_option (arg + prev, j - prev);
4410 : : }
4411 : 0 : do_save = false;
4412 : 0 : break;
4413 : :
4414 : : case OPT_Wl_:
4415 : : {
4416 : : int prev, j;
4417 : : /* Split the argument at commas. */
4418 : : prev = 0;
4419 : 130326 : for (j = 0; arg[j]; j++)
4420 : 122466 : if (arg[j] == ',')
4421 : : {
4422 : 54 : add_infile (save_string (arg + prev, j - prev), "*");
4423 : 54 : prev = j + 1;
4424 : : }
4425 : : /* Record the part after the last comma. */
4426 : 7860 : add_infile (arg + prev, "*");
4427 : 7860 : if (strcmp (arg, "-z,lazy") == 0 || strcmp (arg, "-z,norelro") == 0)
4428 : 12 : avoid_linker_hardening_p = true;
4429 : : }
4430 : : do_save = false;
4431 : : break;
4432 : :
4433 : 12 : case OPT_z:
4434 : 12 : if (strcmp (arg, "lazy") == 0 || strcmp (arg, "norelro") == 0)
4435 : 12 : avoid_linker_hardening_p = true;
4436 : : break;
4437 : :
4438 : 0 : case OPT_Xlinker:
4439 : 0 : add_infile (arg, "*");
4440 : 0 : do_save = false;
4441 : 0 : break;
4442 : :
4443 : 0 : case OPT_Xpreprocessor:
4444 : 0 : add_preprocessor_option (arg, strlen (arg));
4445 : 0 : do_save = false;
4446 : 0 : break;
4447 : :
4448 : 65 : case OPT_Xassembler:
4449 : 65 : add_assembler_option (arg, strlen (arg));
4450 : 65 : do_save = false;
4451 : 65 : break;
4452 : :
4453 : 258802 : case OPT_l:
4454 : : /* POSIX allows separation of -l and the lib arg; canonicalize
4455 : : by concatenating -l with its arg */
4456 : 258802 : add_infile (concat ("-l", arg, NULL), "*");
4457 : :
4458 : : /* Forward to offloading compilation '-l[...]' flags for standard,
4459 : : well-known libraries. */
4460 : : /* Doing this processing here means that we don't get to see libraries
4461 : : injected via specs, such as '-lquadmath' injected via
4462 : : '[build]/[target]/libgfortran/libgfortran.spec'. However, this issue
4463 : : is not actually relevant for the current set of host/offloading
4464 : : configurations. */
4465 : 258802 : if (ENABLE_OFFLOADING)
4466 : : forward_offload_option (opt_index, arg, validated);
4467 : :
4468 : 258802 : do_save = false;
4469 : 258802 : break;
4470 : :
4471 : 265600 : case OPT_L:
4472 : : /* Similarly, canonicalize -L for linkers that may not accept
4473 : : separate arguments. */
4474 : 265600 : save_switch (concat ("-L", arg, NULL), 0, NULL, validated, true);
4475 : 265600 : return true;
4476 : :
4477 : 0 : case OPT_F:
4478 : : /* Likewise -F. */
4479 : 0 : save_switch (concat ("-F", arg, NULL), 0, NULL, validated, true);
4480 : 0 : return true;
4481 : :
4482 : 407 : case OPT_save_temps:
4483 : 407 : if (!save_temps_flag)
4484 : 401 : save_temps_flag = SAVE_TEMPS_DUMP;
4485 : : validated = true;
4486 : : break;
4487 : :
4488 : 58 : case OPT_save_temps_:
4489 : 58 : if (strcmp (arg, "cwd") == 0)
4490 : 29 : save_temps_flag = SAVE_TEMPS_CWD;
4491 : 29 : else if (strcmp (arg, "obj") == 0
4492 : 0 : || strcmp (arg, "object") == 0)
4493 : 29 : save_temps_flag = SAVE_TEMPS_OBJ;
4494 : : else
4495 : 0 : fatal_error (input_location, "%qs is an unknown %<-save-temps%> option",
4496 : 0 : decoded->orig_option_with_args_text);
4497 : 58 : save_temps_overrides_dumpdir = true;
4498 : 58 : break;
4499 : :
4500 : 22387 : case OPT_dumpdir:
4501 : 22387 : free (dumpdir);
4502 : 22387 : dumpdir = xstrdup (arg);
4503 : 22387 : save_temps_overrides_dumpdir = false;
4504 : 22387 : break;
4505 : :
4506 : 23819 : case OPT_dumpbase:
4507 : 23819 : free (dumpbase);
4508 : 23819 : dumpbase = xstrdup (arg);
4509 : 23819 : break;
4510 : :
4511 : 252 : case OPT_dumpbase_ext:
4512 : 252 : free (dumpbase_ext);
4513 : 252 : dumpbase_ext = xstrdup (arg);
4514 : 252 : break;
4515 : :
4516 : : case OPT_no_canonical_prefixes:
4517 : : /* Already handled as a special case, so ignored here. */
4518 : : do_save = false;
4519 : : break;
4520 : :
4521 : : case OPT_pipe:
4522 : : validated = true;
4523 : : /* These options set the variables specified in common.opt
4524 : : automatically, but do need to be saved for spec
4525 : : processing. */
4526 : : break;
4527 : :
4528 : 3 : case OPT_specs_:
4529 : 3 : {
4530 : 3 : struct user_specs *user = XNEW (struct user_specs);
4531 : :
4532 : 3 : user->next = (struct user_specs *) 0;
4533 : 3 : user->filename = arg;
4534 : 3 : if (user_specs_tail)
4535 : 0 : user_specs_tail->next = user;
4536 : : else
4537 : 3 : user_specs_head = user;
4538 : 3 : user_specs_tail = user;
4539 : : }
4540 : 3 : validated = true;
4541 : 3 : break;
4542 : :
4543 : 0 : case OPT__sysroot_:
4544 : 0 : target_system_root = arg;
4545 : 0 : target_system_root_changed = 1;
4546 : : /* Saving this option is useful to let self-specs decide to
4547 : : provide a default one. */
4548 : 0 : do_save = true;
4549 : 0 : validated = true;
4550 : 0 : break;
4551 : :
4552 : 0 : case OPT_time_:
4553 : 0 : if (report_times_to_file)
4554 : 0 : fclose (report_times_to_file);
4555 : 0 : report_times_to_file = fopen (arg, "a");
4556 : 0 : do_save = false;
4557 : 0 : break;
4558 : :
4559 : 9050 : case OPT_truncate:
4560 : 9050 : totruncate_file = arg;
4561 : 9050 : do_save = false;
4562 : 9050 : break;
4563 : :
4564 : 642 : case OPT____:
4565 : : /* "-###"
4566 : : This is similar to -v except that there is no execution
4567 : : of the commands and the echoed arguments are quoted. It
4568 : : is intended for use in shell scripts to capture the
4569 : : driver-generated command line. */
4570 : 642 : verbose_only_flag++;
4571 : 642 : verbose_flag = 1;
4572 : 642 : do_save = false;
4573 : 642 : break;
4574 : :
4575 : 492060 : case OPT_B:
4576 : 492060 : {
4577 : 492060 : size_t len = strlen (arg);
4578 : :
4579 : : /* Catch the case where the user has forgotten to append a
4580 : : directory separator to the path. Note, they may be using
4581 : : -B to add an executable name prefix, eg "i386-elf-", in
4582 : : order to distinguish between multiple installations of
4583 : : GCC in the same directory. Hence we must check to see
4584 : : if appending a directory separator actually makes a
4585 : : valid directory name. */
4586 : 492060 : if (!IS_DIR_SEPARATOR (arg[len - 1])
4587 : 492060 : && is_directory (arg))
4588 : : {
4589 : 98815 : char *tmp = XNEWVEC (char, len + 2);
4590 : 98815 : strcpy (tmp, arg);
4591 : 98815 : tmp[len] = DIR_SEPARATOR;
4592 : 98815 : tmp[++len] = 0;
4593 : 98815 : arg = tmp;
4594 : : }
4595 : :
4596 : 492060 : add_prefix (&exec_prefixes, arg, NULL,
4597 : : PREFIX_PRIORITY_B_OPT, 0, 0);
4598 : 492060 : add_prefix (&startfile_prefixes, arg, NULL,
4599 : : PREFIX_PRIORITY_B_OPT, 0, 0);
4600 : 492060 : add_prefix (&include_prefixes, arg, NULL,
4601 : : PREFIX_PRIORITY_B_OPT, 0, 0);
4602 : : }
4603 : 492060 : validated = true;
4604 : 492060 : break;
4605 : :
4606 : 2520 : case OPT_E:
4607 : 2520 : have_E = true;
4608 : 2520 : break;
4609 : :
4610 : 49993 : case OPT_x:
4611 : 49993 : spec_lang = arg;
4612 : 49993 : if (!strcmp (spec_lang, "none"))
4613 : : /* Suppress the warning if -xnone comes after the last input
4614 : : file, because alternate command interfaces like g++ might
4615 : : find it useful to place -xnone after each input file. */
4616 : 13044 : spec_lang = 0;
4617 : : else
4618 : 36949 : last_language_n_infiles = n_infiles;
4619 : : do_save = false;
4620 : : break;
4621 : :
4622 : 273414 : case OPT_o:
4623 : 273414 : have_o = 1;
4624 : : #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) || defined(HAVE_TARGET_OBJECT_SUFFIX)
4625 : : arg = convert_filename (arg, ! have_c, 0);
4626 : : #endif
4627 : 273414 : output_file = arg;
4628 : : /* On some systems, ld cannot handle "-o" without a space. So
4629 : : split the option from its argument. */
4630 : 273414 : save_switch ("-o", 1, &arg, validated, true);
4631 : 273414 : return true;
4632 : :
4633 : 2129 : case OPT_pie:
4634 : : #ifdef ENABLE_DEFAULT_PIE
4635 : : /* -pie is turned on by default. */
4636 : : validated = true;
4637 : : #endif
4638 : : /* FALLTHROUGH */
4639 : 2129 : case OPT_r:
4640 : 2129 : case OPT_shared:
4641 : 2129 : case OPT_no_pie:
4642 : 2129 : avoid_linker_hardening_p = true;
4643 : 2129 : break;
4644 : :
4645 : 102 : case OPT_static:
4646 : 102 : static_p = true;
4647 : 102 : break;
4648 : :
4649 : : case OPT_static_libgcc:
4650 : : case OPT_shared_libgcc:
4651 : : case OPT_static_libgfortran:
4652 : : case OPT_static_libquadmath:
4653 : : case OPT_static_libphobos:
4654 : : case OPT_static_libga68:
4655 : : case OPT_static_libgm2:
4656 : : case OPT_static_libstdc__:
4657 : : /* These are always valid; gcc.cc itself understands the first two
4658 : : gfortranspec.cc understands -static-libgfortran,
4659 : : libgfortran.spec handles -static-libquadmath,
4660 : : a68spec.cc understands -static-libga68,
4661 : : d-spec.cc understands -static-libphobos,
4662 : : gm2spec.cc understands -static-libgm2,
4663 : : and g++spec.cc understands -static-libstdc++. */
4664 : : validated = true;
4665 : : break;
4666 : :
4667 : 78 : case OPT_fwpa:
4668 : 78 : flag_wpa = "";
4669 : 78 : break;
4670 : :
4671 : 27 : case OPT_foffload_options_:
4672 : 27 : check_foffload_target_names (arg);
4673 : 27 : break;
4674 : :
4675 : 2860 : case OPT_foffload_:
4676 : 2860 : handle_foffload_option (arg);
4677 : 2860 : if (arg[0] == '-' || NULL != strchr (arg, '='))
4678 : 839 : save_switch (concat ("-foffload-options=", arg, NULL),
4679 : : 0, NULL, validated, true);
4680 : : do_save = false;
4681 : : break;
4682 : :
4683 : 0 : case OPT_gcodeview:
4684 : 0 : add_infile ("--pdb=", "*");
4685 : 0 : break;
4686 : :
4687 : : default:
4688 : : /* Various driver options need no special processing at this
4689 : : point, having been handled in a prescan above or being
4690 : : handled by specs. */
4691 : : break;
4692 : : }
4693 : :
4694 : 1645470 : if (do_save)
4695 : 1858171 : save_switch (decoded->canonical_option[0],
4696 : 1858171 : decoded->canonical_option_num_elements - 1,
4697 : : &decoded->canonical_option[1], validated, true);
4698 : : return true;
4699 : : }
4700 : :
4701 : : /* Return true if F2 is F1 followed by a single suffix, i.e., by a
4702 : : period and additional characters other than a period. */
4703 : :
4704 : : static inline bool
4705 : 85665 : adds_single_suffix_p (const char *f2, const char *f1)
4706 : : {
4707 : 85665 : size_t len = strlen (f1);
4708 : :
4709 : 85665 : return (strncmp (f1, f2, len) == 0
4710 : 77049 : && f2[len] == '.'
4711 : 162243 : && strchr (f2 + len + 1, '.') == NULL);
4712 : : }
4713 : :
4714 : : /* Put the driver's standard set of option handlers in *HANDLERS. */
4715 : :
4716 : : static void
4717 : 865070 : set_option_handlers (struct cl_option_handlers *handlers)
4718 : : {
4719 : 865070 : handlers->unknown_option_callback = driver_unknown_option_callback;
4720 : 865070 : handlers->wrong_lang_callback = driver_wrong_lang_callback;
4721 : 865070 : handlers->num_handlers = 3;
4722 : 865070 : handlers->handlers[0].handler = driver_handle_option;
4723 : 865070 : handlers->handlers[0].mask = CL_DRIVER;
4724 : 865070 : handlers->handlers[1].handler = common_handle_option;
4725 : 865070 : handlers->handlers[1].mask = CL_COMMON;
4726 : 865070 : handlers->handlers[2].handler = target_handle_option;
4727 : 865070 : handlers->handlers[2].mask = CL_TARGET;
4728 : 0 : }
4729 : :
4730 : :
4731 : : /* Return the index into infiles for the single non-library
4732 : : non-lto-wpa input file, -1 if there isn't any, or -2 if there is
4733 : : more than one. */
4734 : : static inline int
4735 : 152674 : single_input_file_index ()
4736 : : {
4737 : 152674 : int ret = -1;
4738 : :
4739 : 498689 : for (int i = 0; i < n_infiles; i++)
4740 : : {
4741 : 358559 : if (infiles[i].language
4742 : 251378 : && (infiles[i].language[0] == '*'
4743 : 49166 : || (flag_wpa
4744 : 18916 : && strcmp (infiles[i].language, "lto") == 0)))
4745 : 221128 : continue;
4746 : :
4747 : 137431 : if (ret != -1)
4748 : : return -2;
4749 : :
4750 : : ret = i;
4751 : : }
4752 : :
4753 : : return ret;
4754 : : }
4755 : :
4756 : : /* Create the vector `switches' and its contents.
4757 : : Store its length in `n_switches'. */
4758 : :
4759 : : static void
4760 : 299630 : process_command (unsigned int decoded_options_count,
4761 : : struct cl_decoded_option *decoded_options)
4762 : : {
4763 : 299630 : const char *temp;
4764 : 299630 : char *temp1;
4765 : 299630 : char *tooldir_prefix, *tooldir_prefix2;
4766 : 299630 : char *(*get_relative_prefix) (const char *, const char *,
4767 : : const char *) = NULL;
4768 : 299630 : struct cl_option_handlers handlers;
4769 : 299630 : unsigned int j;
4770 : :
4771 : 299630 : gcc_exec_prefix = env.get ("GCC_EXEC_PREFIX");
4772 : :
4773 : 299630 : n_switches = 0;
4774 : 299630 : n_infiles = 0;
4775 : 299630 : added_libraries = 0;
4776 : :
4777 : : /* Figure compiler version from version string. */
4778 : :
4779 : 299630 : compiler_version = temp1 = xstrdup (version_string);
4780 : :
4781 : 2097410 : for (; *temp1; ++temp1)
4782 : : {
4783 : 2097410 : if (*temp1 == ' ')
4784 : : {
4785 : 299630 : *temp1 = '\0';
4786 : 299630 : break;
4787 : : }
4788 : : }
4789 : :
4790 : : /* Handle any -no-canonical-prefixes flag early, to assign the function
4791 : : that builds relative prefixes. This function creates default search
4792 : : paths that are needed later in normal option handling. */
4793 : :
4794 : 6797353 : for (j = 1; j < decoded_options_count; j++)
4795 : : {
4796 : 6497723 : if (decoded_options[j].opt_index == OPT_no_canonical_prefixes)
4797 : : {
4798 : : get_relative_prefix = make_relative_prefix_ignore_links;
4799 : : break;
4800 : : }
4801 : : }
4802 : 299630 : if (! get_relative_prefix)
4803 : 299630 : get_relative_prefix = make_relative_prefix;
4804 : :
4805 : : /* Set up the default search paths. If there is no GCC_EXEC_PREFIX,
4806 : : see if we can create it from the pathname specified in
4807 : : decoded_options[0].arg. */
4808 : :
4809 : 299630 : gcc_libexec_prefix = standard_libexec_prefix;
4810 : : #ifndef VMS
4811 : : /* FIXME: make_relative_prefix doesn't yet work for VMS. */
4812 : 299630 : if (!gcc_exec_prefix)
4813 : : {
4814 : 28920 : gcc_exec_prefix = get_relative_prefix (decoded_options[0].arg,
4815 : : standard_bindir_prefix,
4816 : : standard_exec_prefix);
4817 : 28920 : gcc_libexec_prefix = get_relative_prefix (decoded_options[0].arg,
4818 : : standard_bindir_prefix,
4819 : : standard_libexec_prefix);
4820 : 28920 : if (gcc_exec_prefix)
4821 : 28920 : xputenv (concat ("GCC_EXEC_PREFIX=", gcc_exec_prefix, NULL));
4822 : : }
4823 : : else
4824 : : {
4825 : : /* make_relative_prefix requires a program name, but
4826 : : GCC_EXEC_PREFIX is typically a directory name with a trailing
4827 : : / (which is ignored by make_relative_prefix), so append a
4828 : : program name. */
4829 : 270710 : char *tmp_prefix = concat (gcc_exec_prefix, "gcc", NULL);
4830 : 270710 : gcc_libexec_prefix = get_relative_prefix (tmp_prefix,
4831 : : standard_exec_prefix,
4832 : : standard_libexec_prefix);
4833 : :
4834 : : /* The path is unrelocated, so fallback to the original setting. */
4835 : 270710 : if (!gcc_libexec_prefix)
4836 : 270364 : gcc_libexec_prefix = standard_libexec_prefix;
4837 : :
4838 : 270710 : free (tmp_prefix);
4839 : : }
4840 : : #else
4841 : : #endif
4842 : : /* From this point onward, gcc_exec_prefix is non-null if the toolchain
4843 : : is relocated. The toolchain was either relocated using GCC_EXEC_PREFIX
4844 : : or an automatically created GCC_EXEC_PREFIX from
4845 : : decoded_options[0].arg. */
4846 : :
4847 : : /* Do language-specific adjustment/addition of flags. */
4848 : 299630 : lang_specific_driver (&decoded_options, &decoded_options_count,
4849 : : &added_libraries);
4850 : :
4851 : 299626 : if (gcc_exec_prefix)
4852 : : {
4853 : 299626 : int len = strlen (gcc_exec_prefix);
4854 : :
4855 : 299626 : if (len > (int) sizeof ("/lib/gcc/") - 1
4856 : 299626 : && (IS_DIR_SEPARATOR (gcc_exec_prefix[len-1])))
4857 : : {
4858 : 299626 : temp = gcc_exec_prefix + len - sizeof ("/lib/gcc/") + 1;
4859 : 299626 : if (IS_DIR_SEPARATOR (*temp)
4860 : 299626 : && filename_ncmp (temp + 1, "lib", 3) == 0
4861 : 299626 : && IS_DIR_SEPARATOR (temp[4])
4862 : 599252 : && filename_ncmp (temp + 5, "gcc", 3) == 0)
4863 : 299626 : len -= sizeof ("/lib/gcc/") - 1;
4864 : : }
4865 : :
4866 : 299626 : set_std_prefix (gcc_exec_prefix, len);
4867 : 299626 : add_prefix (&exec_prefixes, gcc_libexec_prefix, "GCC",
4868 : : PREFIX_PRIORITY_LAST, 0, 0);
4869 : 299626 : add_prefix (&startfile_prefixes, gcc_exec_prefix, "GCC",
4870 : : PREFIX_PRIORITY_LAST, 0, 0);
4871 : : }
4872 : :
4873 : : /* COMPILER_PATH and LIBRARY_PATH have values
4874 : : that are lists of directory names with colons. */
4875 : :
4876 : 299626 : temp = env.get ("COMPILER_PATH");
4877 : 299626 : if (temp)
4878 : : {
4879 : 22223 : const char *startp, *endp;
4880 : 22223 : char *nstore = (char *) alloca (strlen (temp) + 3);
4881 : :
4882 : 22223 : startp = endp = temp;
4883 : 1994298 : while (1)
4884 : : {
4885 : 1994298 : if (*endp == PATH_SEPARATOR || *endp == 0)
4886 : : {
4887 : 35700 : strncpy (nstore, startp, endp - startp);
4888 : 35700 : if (endp == startp)
4889 : 0 : strcpy (nstore, concat (".", dir_separator_str, NULL));
4890 : 35700 : else if (!IS_DIR_SEPARATOR (endp[-1]))
4891 : : {
4892 : 0 : nstore[endp - startp] = DIR_SEPARATOR;
4893 : 0 : nstore[endp - startp + 1] = 0;
4894 : : }
4895 : : else
4896 : 35700 : nstore[endp - startp] = 0;
4897 : 35700 : add_prefix (&exec_prefixes, nstore, 0,
4898 : : PREFIX_PRIORITY_LAST, 0, 0);
4899 : 35700 : add_prefix (&include_prefixes, nstore, 0,
4900 : : PREFIX_PRIORITY_LAST, 0, 0);
4901 : 35700 : if (*endp == 0)
4902 : : break;
4903 : 13477 : endp = startp = endp + 1;
4904 : : }
4905 : : else
4906 : 1958598 : endp++;
4907 : : }
4908 : : }
4909 : :
4910 : 299626 : temp = env.get (LIBRARY_PATH_ENV);
4911 : 299626 : if (temp && *cross_compile == '0')
4912 : : {
4913 : 23576 : const char *startp, *endp;
4914 : 23576 : char *nstore = (char *) alloca (strlen (temp) + 3);
4915 : :
4916 : 23576 : startp = endp = temp;
4917 : 4061304 : while (1)
4918 : : {
4919 : 4061304 : if (*endp == PATH_SEPARATOR || *endp == 0)
4920 : : {
4921 : 169699 : strncpy (nstore, startp, endp - startp);
4922 : 169699 : if (endp == startp)
4923 : 0 : strcpy (nstore, concat (".", dir_separator_str, NULL));
4924 : 169699 : else if (!IS_DIR_SEPARATOR (endp[-1]))
4925 : : {
4926 : 1353 : nstore[endp - startp] = DIR_SEPARATOR;
4927 : 1353 : nstore[endp - startp + 1] = 0;
4928 : : }
4929 : : else
4930 : 168346 : nstore[endp - startp] = 0;
4931 : 169699 : add_prefix (&startfile_prefixes, nstore, NULL,
4932 : : PREFIX_PRIORITY_LAST, 0, 1);
4933 : 169699 : if (*endp == 0)
4934 : : break;
4935 : 146123 : endp = startp = endp + 1;
4936 : : }
4937 : : else
4938 : 3891605 : endp++;
4939 : : }
4940 : : }
4941 : :
4942 : : /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
4943 : 299626 : temp = env.get ("LPATH");
4944 : 299626 : if (temp && *cross_compile == '0')
4945 : : {
4946 : 0 : const char *startp, *endp;
4947 : 0 : char *nstore = (char *) alloca (strlen (temp) + 3);
4948 : :
4949 : 0 : startp = endp = temp;
4950 : 0 : while (1)
4951 : : {
4952 : 0 : if (*endp == PATH_SEPARATOR || *endp == 0)
4953 : : {
4954 : 0 : strncpy (nstore, startp, endp - startp);
4955 : 0 : if (endp == startp)
4956 : 0 : strcpy (nstore, concat (".", dir_separator_str, NULL));
4957 : 0 : else if (!IS_DIR_SEPARATOR (endp[-1]))
4958 : : {
4959 : 0 : nstore[endp - startp] = DIR_SEPARATOR;
4960 : 0 : nstore[endp - startp + 1] = 0;
4961 : : }
4962 : : else
4963 : 0 : nstore[endp - startp] = 0;
4964 : 0 : add_prefix (&startfile_prefixes, nstore, NULL,
4965 : : PREFIX_PRIORITY_LAST, 0, 1);
4966 : 0 : if (*endp == 0)
4967 : : break;
4968 : 0 : endp = startp = endp + 1;
4969 : : }
4970 : : else
4971 : 0 : endp++;
4972 : : }
4973 : : }
4974 : :
4975 : : /* Process the options and store input files and switches in their
4976 : : vectors. */
4977 : :
4978 : 299626 : last_language_n_infiles = -1;
4979 : :
4980 : 299626 : set_option_handlers (&handlers);
4981 : :
4982 : 5836101 : for (j = 1; j < decoded_options_count; j++)
4983 : : {
4984 : 5726044 : switch (decoded_options[j].opt_index)
4985 : : {
4986 : 189569 : case OPT_S:
4987 : 189569 : case OPT_c:
4988 : 189569 : case OPT_E:
4989 : 189569 : have_c = 1;
4990 : 189569 : break;
4991 : : }
4992 : 5726044 : if (have_c)
4993 : : break;
4994 : : }
4995 : :
4996 : 7177076 : for (j = 1; j < decoded_options_count; j++)
4997 : : {
4998 : 6877731 : if (decoded_options[j].opt_index == OPT_SPECIAL_input_file)
4999 : : {
5000 : 324070 : const char *arg = decoded_options[j].arg;
5001 : :
5002 : : #ifdef HAVE_TARGET_OBJECT_SUFFIX
5003 : : arg = convert_filename (arg, 0, access (arg, F_OK));
5004 : : #endif
5005 : 324070 : add_infile (arg, spec_lang,
5006 : 324070 : decoded_options[j].mask == CL_DRIVER);
5007 : :
5008 : 324070 : continue;
5009 : 324070 : }
5010 : :
5011 : 6553661 : read_cmdline_option (&global_options, &global_options_set,
5012 : : decoded_options + j, UNKNOWN_LOCATION,
5013 : : CL_DRIVER, &handlers, global_dc);
5014 : : }
5015 : :
5016 : : /* If the user didn't specify any, default to all configured offload
5017 : : targets. */
5018 : 299345 : if (ENABLE_OFFLOADING && offload_targets == NULL)
5019 : : {
5020 : : handle_foffload_option (OFFLOAD_TARGETS);
5021 : : #if OFFLOAD_DEFAULTED
5022 : : offload_targets_default = true;
5023 : : #endif
5024 : : }
5025 : :
5026 : : /* TODO: check if -static -pie works and maybe use it. */
5027 : 299345 : if (flag_hardened)
5028 : : {
5029 : 91 : if (!avoid_linker_hardening_p && !static_p)
5030 : : {
5031 : : #if defined HAVE_LD_PIE && defined LD_PIE_SPEC
5032 : 67 : save_switch (LD_PIE_SPEC, 0, NULL, /*validated=*/true, /*known=*/false);
5033 : : #endif
5034 : : /* These are passed straight down to collect2 so we have to break
5035 : : it up like this. */
5036 : 67 : if (HAVE_LD_NOW_SUPPORT)
5037 : : {
5038 : 67 : add_infile ("-z", "*");
5039 : 67 : add_infile ("now", "*");
5040 : : }
5041 : 67 : if (HAVE_LD_RELRO_SUPPORT)
5042 : : {
5043 : 67 : add_infile ("-z", "*");
5044 : 67 : add_infile ("relro", "*");
5045 : : }
5046 : : }
5047 : : /* We can't use OPT_Whardened yet. Sigh. */
5048 : : else
5049 : 24 : warning_at (UNKNOWN_LOCATION, 0,
5050 : : "linker hardening options not enabled by %<-fhardened%> "
5051 : : "because other link options were specified on the command "
5052 : : "line");
5053 : : }
5054 : :
5055 : : /* Handle -gtoggle as it would later in toplev.cc:process_options to
5056 : : make the debug-level-gt spec function work as expected. */
5057 : 299345 : if (flag_gtoggle)
5058 : : {
5059 : 4 : if (debug_info_level == DINFO_LEVEL_NONE)
5060 : 0 : debug_info_level = DINFO_LEVEL_NORMAL;
5061 : : else
5062 : 4 : debug_info_level = DINFO_LEVEL_NONE;
5063 : : }
5064 : :
5065 : 299345 : if (output_file
5066 : 273413 : && strcmp (output_file, "-") != 0
5067 : 273250 : && strcmp (output_file, HOST_BIT_BUCKET) != 0)
5068 : : {
5069 : : int i;
5070 : 810566 : for (i = 0; i < n_infiles; i++)
5071 : 260956 : if ((!infiles[i].language || infiles[i].language[0] != '*')
5072 : 566403 : && canonical_filename_eq (infiles[i].name, output_file))
5073 : 1 : fatal_error (input_location,
5074 : : "input file %qs is the same as output file",
5075 : : output_file);
5076 : : }
5077 : :
5078 : 299344 : if (output_file != NULL && output_file[0] == '\0')
5079 : 0 : fatal_error (input_location, "output filename may not be empty");
5080 : :
5081 : : /* -dumpdir and -save-temps=* both specify the location of aux/dump
5082 : : outputs; the one that appears last prevails. When compiling
5083 : : multiple sources, an explicit dumpbase (minus -ext) may be
5084 : : combined with an explicit or implicit dumpdir, whereas when
5085 : : linking, a specified or implied link output name (minus
5086 : : extension) may be combined with a prevailing -save-temps=* or an
5087 : : otherwise implied dumpdir, but not override a prevailing
5088 : : -dumpdir. Primary outputs (e.g., linker output when linking
5089 : : without -o, or .i, .s or .o outputs when processing multiple
5090 : : inputs with -E, -S or -c, respectively) are NOT affected by these
5091 : : -save-temps=/-dump* options, always landing in the current
5092 : : directory and with the same basename as the input when an output
5093 : : name is not given, but when they're intermediate outputs, they
5094 : : are named like other aux outputs, so the options affect their
5095 : : location and name.
5096 : :
5097 : : Here are some examples. There are several more in the
5098 : : documentation of -o and -dump*, and some quite exhaustive tests
5099 : : in gcc.misc-tests/outputs.exp.
5100 : :
5101 : : When compiling any number of sources, no -dump* nor
5102 : : -save-temps=*, all outputs in cwd without prefix:
5103 : :
5104 : : # gcc -c b.c -gsplit-dwarf
5105 : : -> cc1 [-dumpdir ./] -dumpbase b.c -dumpbase-ext .c # b.o b.dwo
5106 : :
5107 : : # gcc -c b.c d.c -gsplit-dwarf
5108 : : -> cc1 [-dumpdir ./] -dumpbase b.c -dumpbase-ext .c # b.o b.dwo
5109 : : && cc1 [-dumpdir ./] -dumpbase d.c -dumpbase-ext .c # d.o d.dwo
5110 : :
5111 : : When compiling and linking, no -dump* nor -save-temps=*, .o
5112 : : outputs are temporary, aux outputs land in the dir of the output,
5113 : : prefixed with the basename of the linker output:
5114 : :
5115 : : # gcc b.c d.c -o ab -gsplit-dwarf
5116 : : -> cc1 -dumpdir ab- -dumpbase b.c -dumpbase-ext .c # ab-b.dwo
5117 : : && cc1 -dumpdir ab- -dumpbase d.c -dumpbase-ext .c # ab-d.dwo
5118 : : && link ... -o ab
5119 : :
5120 : : # gcc b.c d.c [-o a.out] -gsplit-dwarf
5121 : : -> cc1 -dumpdir a- -dumpbase b.c -dumpbase-ext .c # a-b.dwo
5122 : : && cc1 -dumpdir a- -dumpbase d.c -dumpbase-ext .c # a-d.dwo
5123 : : && link ... [-o a.out]
5124 : :
5125 : : When compiling and linking, a prevailing -dumpdir fully overrides
5126 : : the prefix of aux outputs given by the output name:
5127 : :
5128 : : # gcc -dumpdir f b.c d.c -gsplit-dwarf [-o [dir/]whatever]
5129 : : -> cc1 -dumpdir f -dumpbase b.c -dumpbase-ext .c # fb.dwo
5130 : : && cc1 -dumpdir f -dumpbase d.c -dumpbase-ext .c # fd.dwo
5131 : : && link ... [-o whatever]
5132 : :
5133 : : When compiling multiple inputs, an explicit -dumpbase is combined
5134 : : with -dumpdir, affecting aux outputs, but not the .o outputs:
5135 : :
5136 : : # gcc -dumpdir f -dumpbase g- b.c d.c -gsplit-dwarf -c
5137 : : -> cc1 -dumpdir fg- -dumpbase b.c -dumpbase-ext .c # b.o fg-b.dwo
5138 : : && cc1 -dumpdir fg- -dumpbase d.c -dumpbase-ext .c # d.o fg-d.dwo
5139 : :
5140 : : When compiling and linking with -save-temps, the .o outputs that
5141 : : would have been temporary become aux outputs, so they get
5142 : : affected by -dump* flags:
5143 : :
5144 : : # gcc -dumpdir f -dumpbase g- -save-temps b.c d.c
5145 : : -> cc1 -dumpdir fg- -dumpbase b.c -dumpbase-ext .c # fg-b.o
5146 : : && cc1 -dumpdir fg- -dumpbase d.c -dumpbase-ext .c # fg-d.o
5147 : : && link
5148 : :
5149 : : If -save-temps=* prevails over -dumpdir, however, the explicit
5150 : : -dumpdir is discarded, as if it wasn't there. The basename of
5151 : : the implicit linker output, a.out or a.exe, becomes a- as the aux
5152 : : output prefix for all compilations:
5153 : :
5154 : : # gcc [-dumpdir f] -save-temps=cwd b.c d.c
5155 : : -> cc1 -dumpdir a- -dumpbase b.c -dumpbase-ext .c # a-b.o
5156 : : && cc1 -dumpdir a- -dumpbase d.c -dumpbase-ext .c # a-d.o
5157 : : && link
5158 : :
5159 : : A single -dumpbase, applying to multiple inputs, overrides the
5160 : : linker output name, implied or explicit, as the aux output prefix:
5161 : :
5162 : : # gcc [-dumpdir f] -dumpbase g- -save-temps=cwd b.c d.c
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
5166 : :
5167 : : # gcc [-dumpdir f] -dumpbase g- -save-temps=cwd b.c d.c -o dir/h.out
5168 : : -> cc1 -dumpdir g- -dumpbase b.c -dumpbase-ext .c # g-b.o
5169 : : && cc1 -dumpdir g- -dumpbase d.c -dumpbase-ext .c # g-d.o
5170 : : && link -o dir/h.out
5171 : :
5172 : : Now, if the linker output is NOT overridden as a prefix, but
5173 : : -save-temps=* overrides implicit or explicit -dumpdir, the
5174 : : effective dump dir combines the dir selected by the -save-temps=*
5175 : : option with the basename of the specified or implied link output:
5176 : :
5177 : : # gcc [-dumpdir f] -save-temps=cwd b.c d.c -o dir/h.out
5178 : : -> cc1 -dumpdir h- -dumpbase b.c -dumpbase-ext .c # h-b.o
5179 : : && cc1 -dumpdir h- -dumpbase d.c -dumpbase-ext .c # h-d.o
5180 : : && link -o dir/h.out
5181 : :
5182 : : # gcc [-dumpdir f] -save-temps=obj b.c d.c -o dir/h.out
5183 : : -> cc1 -dumpdir dir/h- -dumpbase b.c -dumpbase-ext .c # dir/h-b.o
5184 : : && cc1 -dumpdir dir/h- -dumpbase d.c -dumpbase-ext .c # dir/h-d.o
5185 : : && link -o dir/h.out
5186 : :
5187 : : But then again, a single -dumpbase applying to multiple inputs
5188 : : gets used instead of the linker output basename in the combined
5189 : : dumpdir:
5190 : :
5191 : : # gcc [-dumpdir f] -dumpbase g- -save-temps=obj b.c d.c -o dir/h.out
5192 : : -> cc1 -dumpdir dir/g- -dumpbase b.c -dumpbase-ext .c # dir/g-b.o
5193 : : && cc1 -dumpdir dir/g- -dumpbase d.c -dumpbase-ext .c # dir/g-d.o
5194 : : && link -o dir/h.out
5195 : :
5196 : : With a single input being compiled, the output basename does NOT
5197 : : affect the dumpdir prefix.
5198 : :
5199 : : # gcc -save-temps=obj b.c -gsplit-dwarf -c -o dir/b.o
5200 : : -> cc1 -dumpdir dir/ -dumpbase b.c -dumpbase-ext .c # dir/b.o dir/b.dwo
5201 : :
5202 : : but when compiling and linking even a single file, it does:
5203 : :
5204 : : # gcc -save-temps=obj b.c -o dir/h.out
5205 : : -> cc1 -dumpdir dir/h- -dumpbase b.c -dumpbase-ext .c # dir/h-b.o
5206 : :
5207 : : unless an explicit -dumpdir prevails:
5208 : :
5209 : : # gcc -save-temps[=obj] -dumpdir g- b.c -o dir/h.out
5210 : : -> cc1 -dumpdir g- -dumpbase b.c -dumpbase-ext .c # g-b.o
5211 : :
5212 : : */
5213 : :
5214 : 299344 : bool explicit_dumpdir = dumpdir;
5215 : :
5216 : 299292 : if ((!save_temps_overrides_dumpdir && explicit_dumpdir)
5217 : 576257 : || (output_file && not_actual_file_p (output_file)))
5218 : : {
5219 : : /* Do nothing. */
5220 : : }
5221 : :
5222 : : /* If -save-temps=obj and -o name, create the prefix to use for %b.
5223 : : Otherwise just make -save-temps=obj the same as -save-temps=cwd. */
5224 : 275388 : else if (save_temps_flag != SAVE_TEMPS_CWD && output_file != NULL)
5225 : : {
5226 : 257974 : free (dumpdir);
5227 : 257974 : dumpdir = NULL;
5228 : 257974 : temp = lbasename (output_file);
5229 : 257974 : if (temp != output_file)
5230 : 103431 : dumpdir = xstrndup (output_file,
5231 : 103431 : strlen (output_file) - strlen (temp));
5232 : : }
5233 : 17414 : else if (dumpdir)
5234 : : {
5235 : 5 : free (dumpdir);
5236 : 5 : dumpdir = NULL;
5237 : : }
5238 : :
5239 : 299344 : if (save_temps_flag)
5240 : 459 : save_temps_flag = SAVE_TEMPS_DUMP;
5241 : :
5242 : : /* If there is any pathname component in an explicit -dumpbase, it
5243 : : overrides dumpdir entirely, so discard it right away. Although
5244 : : the presence of an explicit -dumpdir matters for the driver, it
5245 : : shouldn't matter for other processes, that get all that's needed
5246 : : from the -dumpdir and -dumpbase always passed to them. */
5247 : 299344 : if (dumpdir && dumpbase && lbasename (dumpbase) != dumpbase)
5248 : : {
5249 : 22292 : free (dumpdir);
5250 : 22292 : dumpdir = NULL;
5251 : : }
5252 : :
5253 : : /* Check that dumpbase_ext matches the end of dumpbase, drop it
5254 : : otherwise. */
5255 : 299344 : if (dumpbase_ext && dumpbase && *dumpbase)
5256 : : {
5257 : 20 : int lendb = strlen (dumpbase);
5258 : 20 : int lendbx = strlen (dumpbase_ext);
5259 : :
5260 : : /* -dumpbase-ext must be a suffix proper; discard it if it
5261 : : matches all of -dumpbase, as that would make for an empty
5262 : : basename. */
5263 : 20 : if (lendbx >= lendb
5264 : 19 : || strcmp (dumpbase + lendb - lendbx, dumpbase_ext) != 0)
5265 : : {
5266 : 1 : free (dumpbase_ext);
5267 : 1 : dumpbase_ext = NULL;
5268 : : }
5269 : : }
5270 : :
5271 : : /* -dumpbase with multiple sources goes into dumpdir. With a single
5272 : : source, it does only if linking and if dumpdir was not explicitly
5273 : : specified. */
5274 : 23819 : if (dumpbase && *dumpbase
5275 : 321714 : && (single_input_file_index () == -2
5276 : 22086 : || (!have_c && !explicit_dumpdir)))
5277 : : {
5278 : 296 : char *prefix;
5279 : :
5280 : 296 : if (dumpbase_ext)
5281 : : /* We checked that they match above. */
5282 : 6 : dumpbase[strlen (dumpbase) - strlen (dumpbase_ext)] = '\0';
5283 : :
5284 : 296 : if (dumpdir)
5285 : 13 : prefix = concat (dumpdir, dumpbase, "-", NULL);
5286 : : else
5287 : 283 : prefix = concat (dumpbase, "-", NULL);
5288 : :
5289 : 296 : free (dumpdir);
5290 : 296 : free (dumpbase);
5291 : 296 : free (dumpbase_ext);
5292 : 296 : dumpbase = dumpbase_ext = NULL;
5293 : 296 : dumpdir = prefix;
5294 : 296 : dumpdir_trailing_dash_added = true;
5295 : : }
5296 : :
5297 : : /* If dumpbase was not brought into dumpdir but we're linking, bring
5298 : : output_file into dumpdir unless dumpdir was explicitly specified.
5299 : : The test for !explicit_dumpdir is further below, because we want
5300 : : to use the obase computation for a ghost outbase, passed to
5301 : : GCC_COLLECT_OPTIONS. */
5302 : 299048 : else if (!have_c && (!explicit_dumpdir || (dumpbase && !*dumpbase)))
5303 : : {
5304 : : /* If we get here, we know dumpbase was not specified, or it was
5305 : : specified as an empty string. If it was anything else, it
5306 : : would have combined with dumpdir above, because the condition
5307 : : for dumpbase to be used when present is broader than the
5308 : : condition that gets us here. */
5309 : 109674 : gcc_assert (!dumpbase || !*dumpbase);
5310 : :
5311 : 109674 : const char *obase;
5312 : 109674 : char *tofree = NULL;
5313 : 109674 : if (!output_file || not_actual_file_p (output_file))
5314 : : obase = "a";
5315 : : else
5316 : : {
5317 : 95660 : obase = lbasename (output_file);
5318 : 95660 : size_t blen = strlen (obase), xlen;
5319 : : /* Drop the suffix if it's dumpbase_ext, if given,
5320 : : otherwise .exe or the target executable suffix, or if the
5321 : : output was explicitly named a.out, but not otherwise. */
5322 : 95660 : if (dumpbase_ext
5323 : 95660 : ? (blen > (xlen = strlen (dumpbase_ext))
5324 : 223 : && strcmp ((temp = (obase + blen - xlen)),
5325 : : dumpbase_ext) == 0)
5326 : 95437 : : ((temp = strrchr (obase + 1, '.'))
5327 : 93583 : && (xlen = strlen (temp))
5328 : 189020 : && (strcmp (temp, ".exe") == 0
5329 : : #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
5330 : : || strcmp (temp, TARGET_EXECUTABLE_SUFFIX) == 0
5331 : : #endif
5332 : 9033 : || strcmp (obase, "a.out") == 0)))
5333 : : {
5334 : 84799 : tofree = xstrndup (obase, blen - xlen);
5335 : 84799 : obase = tofree;
5336 : : }
5337 : : }
5338 : :
5339 : : /* We wish to save this basename to the -dumpdir passed through
5340 : : GCC_COLLECT_OPTIONS within maybe_run_linker, for e.g. LTO,
5341 : : but we do NOT wish to add it to e.g. %b, so we keep
5342 : : outbase_length as zero. */
5343 : 109674 : gcc_assert (!outbase);
5344 : 109674 : outbase_length = 0;
5345 : :
5346 : : /* If we're building [dir1/]foo[.exe] out of a single input
5347 : : [dir2/]foo.c that shares the same basename, dump to
5348 : : [dir2/]foo.c.* rather than duplicating the basename into
5349 : : [dir2/]foo-foo.c.*. */
5350 : 109674 : int idxin;
5351 : 109674 : if (dumpbase
5352 : 109674 : || ((idxin = single_input_file_index ()) >= 0
5353 : 85665 : && adds_single_suffix_p (lbasename (infiles[idxin].name),
5354 : : obase)))
5355 : : {
5356 : 78022 : if (obase == tofree)
5357 : 76261 : outbase = tofree;
5358 : : else
5359 : : {
5360 : 1761 : outbase = xstrdup (obase);
5361 : 1761 : free (tofree);
5362 : : }
5363 : 109674 : obase = tofree = NULL;
5364 : : }
5365 : : else
5366 : : {
5367 : 31652 : if (dumpdir)
5368 : : {
5369 : 15262 : char *p = concat (dumpdir, obase, "-", NULL);
5370 : 15262 : free (dumpdir);
5371 : 15262 : dumpdir = p;
5372 : : }
5373 : : else
5374 : 16390 : dumpdir = concat (obase, "-", NULL);
5375 : :
5376 : 31652 : dumpdir_trailing_dash_added = true;
5377 : :
5378 : 31652 : free (tofree);
5379 : 31652 : obase = tofree = NULL;
5380 : : }
5381 : :
5382 : 109674 : if (!explicit_dumpdir || dumpbase)
5383 : : {
5384 : : /* Absent -dumpbase and present -dumpbase-ext have been applied
5385 : : to the linker output name, so compute fresh defaults for each
5386 : : compilation. */
5387 : 109674 : free (dumpbase_ext);
5388 : 109674 : dumpbase_ext = NULL;
5389 : : }
5390 : : }
5391 : :
5392 : : /* Now, if we're compiling, or if we haven't used the dumpbase
5393 : : above, then outbase (%B) is derived from dumpbase, if given, or
5394 : : from the output name, given or implied. We can't precompute
5395 : : implied output names, but that's ok, since they're derived from
5396 : : input names. Just make sure we skip this if dumpbase is the
5397 : : empty string: we want to use input names then, so don't set
5398 : : outbase. */
5399 : 299344 : if ((dumpbase || have_c)
5400 : 191035 : && !(dumpbase && !*dumpbase))
5401 : : {
5402 : 189586 : gcc_assert (!outbase);
5403 : :
5404 : 189586 : if (dumpbase)
5405 : : {
5406 : 22074 : gcc_assert (single_input_file_index () != -2);
5407 : : /* We do not want lbasename here; dumpbase with dirnames
5408 : : overrides dumpdir entirely, even if dumpdir is
5409 : : specified. */
5410 : 22074 : if (dumpbase_ext)
5411 : : /* We've already checked above that the suffix matches. */
5412 : 13 : outbase = xstrndup (dumpbase,
5413 : 13 : strlen (dumpbase) - strlen (dumpbase_ext));
5414 : : else
5415 : 22061 : outbase = xstrdup (dumpbase);
5416 : : }
5417 : 167512 : else if (output_file && !not_actual_file_p (output_file))
5418 : : {
5419 : 162551 : outbase = xstrdup (lbasename (output_file));
5420 : 162551 : char *p = strrchr (outbase + 1, '.');
5421 : 162551 : if (p)
5422 : 162551 : *p = '\0';
5423 : : }
5424 : :
5425 : 189586 : if (outbase)
5426 : 184625 : outbase_length = strlen (outbase);
5427 : : }
5428 : :
5429 : : /* If there is any pathname component in an explicit -dumpbase, do
5430 : : not use dumpdir, but retain it to pass it on to the compiler. */
5431 : 299344 : if (dumpdir)
5432 : 120191 : dumpdir_length = strlen (dumpdir);
5433 : : else
5434 : 179153 : dumpdir_length = 0;
5435 : :
5436 : : /* Check that dumpbase_ext, if still present, still matches the end
5437 : : of dumpbase, if present, and drop it otherwise. We only retained
5438 : : it above when dumpbase was absent to maybe use it to drop the
5439 : : extension from output_name before combining it with dumpdir. We
5440 : : won't deal with -dumpbase-ext when -dumpbase is not explicitly
5441 : : given, even if just to activate backward-compatible dumpbase:
5442 : : dropping it on the floor is correct, expected and documented
5443 : : behavior. Attempting to deal with a -dumpbase-ext that might
5444 : : match the end of some input filename, or of the combination of
5445 : : the output basename with the suffix of the input filename,
5446 : : possible with an intermediate .gk extension for -fcompare-debug,
5447 : : is just calling for trouble. */
5448 : 299344 : if (dumpbase_ext)
5449 : : {
5450 : 22 : if (!dumpbase || !*dumpbase)
5451 : : {
5452 : 9 : free (dumpbase_ext);
5453 : 9 : dumpbase_ext = NULL;
5454 : : }
5455 : : else
5456 : 13 : gcc_assert (strcmp (dumpbase + strlen (dumpbase)
5457 : : - strlen (dumpbase_ext), dumpbase_ext) == 0);
5458 : : }
5459 : :
5460 : 299344 : if (save_temps_flag && use_pipes)
5461 : : {
5462 : : /* -save-temps overrides -pipe, so that temp files are produced */
5463 : 0 : if (save_temps_flag)
5464 : 0 : warning (0, "%<-pipe%> ignored because %<-save-temps%> specified");
5465 : 0 : use_pipes = 0;
5466 : : }
5467 : :
5468 : 299344 : if (!compare_debug)
5469 : : {
5470 : 298725 : const char *gcd = env.get ("GCC_COMPARE_DEBUG");
5471 : :
5472 : 298725 : if (gcd && gcd[0] == '-')
5473 : : {
5474 : 0 : compare_debug = 2;
5475 : 0 : compare_debug_opt = gcd;
5476 : : }
5477 : 0 : else if (gcd && *gcd && strcmp (gcd, "0"))
5478 : : {
5479 : 0 : compare_debug = 3;
5480 : 0 : compare_debug_opt = "-gtoggle";
5481 : : }
5482 : : }
5483 : 619 : else if (compare_debug < 0)
5484 : : {
5485 : 0 : compare_debug = 0;
5486 : 0 : gcc_assert (!compare_debug_opt);
5487 : : }
5488 : :
5489 : : /* Set up the search paths. We add directories that we expect to
5490 : : contain GNU Toolchain components before directories specified by
5491 : : the machine description so that we will find GNU components (like
5492 : : the GNU assembler) before those of the host system. */
5493 : :
5494 : : /* If we don't know where the toolchain has been installed, use the
5495 : : configured-in locations. */
5496 : 299344 : if (!gcc_exec_prefix)
5497 : : {
5498 : : #ifndef OS2
5499 : 0 : add_prefix (&exec_prefixes, standard_libexec_prefix, "GCC",
5500 : : PREFIX_PRIORITY_LAST, 1, 0);
5501 : 0 : add_prefix (&exec_prefixes, standard_libexec_prefix, "BINUTILS",
5502 : : PREFIX_PRIORITY_LAST, 2, 0);
5503 : 0 : add_prefix (&exec_prefixes, standard_exec_prefix, "BINUTILS",
5504 : : PREFIX_PRIORITY_LAST, 2, 0);
5505 : : #endif
5506 : 0 : add_prefix (&startfile_prefixes, standard_exec_prefix, "BINUTILS",
5507 : : PREFIX_PRIORITY_LAST, 1, 0);
5508 : : }
5509 : :
5510 : 299344 : gcc_assert (!IS_ABSOLUTE_PATH (tooldir_base_prefix));
5511 : 299344 : tooldir_prefix2 = concat (tooldir_base_prefix, spec_machine,
5512 : : dir_separator_str, NULL);
5513 : :
5514 : : /* Look for tools relative to the location from which the driver is
5515 : : running, or, if that is not available, the configured prefix. */
5516 : 299344 : tooldir_prefix
5517 : 598688 : = concat (gcc_exec_prefix ? gcc_exec_prefix : standard_exec_prefix,
5518 : : spec_host_machine, dir_separator_str, spec_version,
5519 : : accel_dir_suffix, dir_separator_str, tooldir_prefix2, NULL);
5520 : 299344 : free (tooldir_prefix2);
5521 : :
5522 : 299344 : add_prefix (&exec_prefixes,
5523 : 299344 : concat (tooldir_prefix, "bin", dir_separator_str, NULL),
5524 : : "BINUTILS", PREFIX_PRIORITY_LAST, 0, 0);
5525 : 299344 : add_prefix (&startfile_prefixes,
5526 : 299344 : concat (tooldir_prefix, "lib", dir_separator_str, NULL),
5527 : : "BINUTILS", PREFIX_PRIORITY_LAST, 0, 1);
5528 : 299344 : free (tooldir_prefix);
5529 : :
5530 : : #if defined(TARGET_SYSTEM_ROOT_RELOCATABLE) && !defined(VMS)
5531 : : /* If the normal TARGET_SYSTEM_ROOT is inside of $exec_prefix,
5532 : : then consider it to relocate with the rest of the GCC installation
5533 : : if GCC_EXEC_PREFIX is set.
5534 : : ``make_relative_prefix'' is not compiled for VMS, so don't call it. */
5535 : : if (target_system_root && !target_system_root_changed && gcc_exec_prefix)
5536 : : {
5537 : : char *tmp_prefix = get_relative_prefix (decoded_options[0].arg,
5538 : : standard_bindir_prefix,
5539 : : target_system_root);
5540 : : if (tmp_prefix && access_check (tmp_prefix, F_OK) == 0)
5541 : : {
5542 : : target_system_root = tmp_prefix;
5543 : : target_system_root_changed = 1;
5544 : : }
5545 : : }
5546 : : #endif
5547 : :
5548 : : /* More prefixes are enabled in main, after we read the specs file
5549 : : and determine whether this is cross-compilation or not. */
5550 : :
5551 : 299344 : if (n_infiles != 0 && n_infiles == last_language_n_infiles && spec_lang != 0)
5552 : 0 : warning (0, "%<-x %s%> after last input file has no effect", spec_lang);
5553 : :
5554 : : /* Synthesize -fcompare-debug flag from the GCC_COMPARE_DEBUG
5555 : : environment variable. */
5556 : 299344 : if (compare_debug == 2 || compare_debug == 3)
5557 : : {
5558 : 0 : const char *opt = concat ("-fcompare-debug=", compare_debug_opt, NULL);
5559 : 0 : save_switch (opt, 0, NULL, false, true);
5560 : 0 : compare_debug = 1;
5561 : : }
5562 : :
5563 : : /* Ensure we only invoke each subprocess once. */
5564 : 299344 : if (n_infiles == 0
5565 : 7144 : && (print_subprocess_help || print_help_list || print_version))
5566 : : {
5567 : : /* Create a dummy input file, so that we can pass
5568 : : the help option on to the various sub-processes. */
5569 : 78 : add_infile ("help-dummy", "c");
5570 : : }
5571 : :
5572 : : /* Decide if undefined variable references are allowed in specs. */
5573 : :
5574 : : /* -v alone is safe. --version and --help alone or together are safe. Note
5575 : : that -v would make them unsafe, as they'd then be run for subprocesses as
5576 : : well, the location of which might depend on variables possibly coming
5577 : : from self-specs. Note also that the command name is counted in
5578 : : decoded_options_count. */
5579 : :
5580 : 299344 : unsigned help_version_count = 0;
5581 : :
5582 : 299344 : if (print_version)
5583 : 78 : help_version_count++;
5584 : :
5585 : 299344 : if (print_help_list)
5586 : 4 : help_version_count++;
5587 : :
5588 : 598688 : spec_undefvar_allowed =
5589 : 1493 : ((verbose_flag && decoded_options_count == 2)
5590 : 300769 : || help_version_count == decoded_options_count - 1);
5591 : :
5592 : 299344 : alloc_switch ();
5593 : 299344 : switches[n_switches].part1 = 0;
5594 : 299344 : alloc_infile ();
5595 : 299344 : infiles[n_infiles].name = 0;
5596 : 299344 : }
5597 : :
5598 : : /* Store switches not filtered out by %<S in spec in COLLECT_GCC_OPTIONS
5599 : : and place that in the environment. */
5600 : :
5601 : : static void
5602 : 828201 : set_collect_gcc_options (void)
5603 : : {
5604 : 828201 : int i;
5605 : 828201 : int first_time;
5606 : :
5607 : : /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
5608 : : the compiler. */
5609 : 828201 : obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
5610 : : sizeof ("COLLECT_GCC_OPTIONS=") - 1);
5611 : :
5612 : 828201 : first_time = true;
5613 : 20007355 : for (i = 0; (int) i < n_switches; i++)
5614 : : {
5615 : 19179154 : const char *const *args;
5616 : 19179154 : const char *p, *q;
5617 : 19179154 : if (!first_time)
5618 : 18350953 : obstack_grow (&collect_obstack, " ", 1);
5619 : :
5620 : 19179154 : first_time = false;
5621 : :
5622 : : /* Ignore elided switches. */
5623 : 19308721 : if ((switches[i].live_cond
5624 : 19179154 : & (SWITCH_IGNORE | SWITCH_KEEP_FOR_GCC))
5625 : : == SWITCH_IGNORE)
5626 : 129567 : continue;
5627 : :
5628 : 19049587 : obstack_grow (&collect_obstack, "'-", 2);
5629 : 19049587 : q = switches[i].part1;
5630 : 19049587 : while ((p = strchr (q, '\'')))
5631 : : {
5632 : 0 : obstack_grow (&collect_obstack, q, p - q);
5633 : 0 : obstack_grow (&collect_obstack, "'\\''", 4);
5634 : 0 : q = ++p;
5635 : : }
5636 : 19049587 : obstack_grow (&collect_obstack, q, strlen (q));
5637 : 19049587 : obstack_grow (&collect_obstack, "'", 1);
5638 : :
5639 : 23223815 : for (args = switches[i].args; args && *args; args++)
5640 : : {
5641 : 4174228 : obstack_grow (&collect_obstack, " '", 2);
5642 : 4174228 : q = *args;
5643 : 4174228 : while ((p = strchr (q, '\'')))
5644 : : {
5645 : 0 : obstack_grow (&collect_obstack, q, p - q);
5646 : 0 : obstack_grow (&collect_obstack, "'\\''", 4);
5647 : 0 : q = ++p;
5648 : : }
5649 : 4174228 : obstack_grow (&collect_obstack, q, strlen (q));
5650 : 4174228 : obstack_grow (&collect_obstack, "'", 1);
5651 : : }
5652 : : }
5653 : :
5654 : 828201 : if (dumpdir)
5655 : : {
5656 : 584950 : if (!first_time)
5657 : 584950 : obstack_grow (&collect_obstack, " ", 1);
5658 : 584950 : first_time = false;
5659 : :
5660 : 584950 : obstack_grow (&collect_obstack, "'-dumpdir' '", 12);
5661 : 584950 : const char *p, *q;
5662 : :
5663 : 584950 : q = dumpdir;
5664 : 584950 : while ((p = strchr (q, '\'')))
5665 : : {
5666 : 0 : obstack_grow (&collect_obstack, q, p - q);
5667 : 0 : obstack_grow (&collect_obstack, "'\\''", 4);
5668 : 0 : q = ++p;
5669 : : }
5670 : 584950 : obstack_grow (&collect_obstack, q, strlen (q));
5671 : :
5672 : 584950 : obstack_grow (&collect_obstack, "'", 1);
5673 : : }
5674 : :
5675 : 828201 : obstack_grow (&collect_obstack, "\0", 1);
5676 : 828201 : xputenv (XOBFINISH (&collect_obstack, char *));
5677 : 828201 : }
5678 : :
5679 : : /* Process a spec string, accumulating and running commands. */
5680 : :
5681 : : /* These variables describe the input file name.
5682 : : input_file_number is the index on outfiles of this file,
5683 : : so that the output file name can be stored for later use by %o.
5684 : : input_basename is the start of the part of the input file
5685 : : sans all directory names, and basename_length is the number
5686 : : of characters starting there excluding the suffix .c or whatever. */
5687 : :
5688 : : static const char *gcc_input_filename;
5689 : : static int input_file_number;
5690 : : size_t input_filename_length;
5691 : : static int basename_length;
5692 : : static int suffixed_basename_length;
5693 : : static const char *input_basename;
5694 : : static const char *input_suffix;
5695 : : #ifndef HOST_LACKS_INODE_NUMBERS
5696 : : static struct stat input_stat;
5697 : : #endif
5698 : : static int input_stat_set;
5699 : :
5700 : : /* The compiler used to process the current input file. */
5701 : : static struct compiler *input_file_compiler;
5702 : :
5703 : : /* These are variables used within do_spec and do_spec_1. */
5704 : :
5705 : : /* Nonzero if an arg has been started and not yet terminated
5706 : : (with space, tab or newline). */
5707 : : static int arg_going;
5708 : :
5709 : : /* Nonzero means %d or %g has been seen; the next arg to be terminated
5710 : : is a temporary file name. */
5711 : : static int delete_this_arg;
5712 : :
5713 : : /* Nonzero means %w has been seen; the next arg to be terminated
5714 : : is the output file name of this compilation. */
5715 : : static int this_is_output_file;
5716 : :
5717 : : /* Nonzero means %s has been seen; the next arg to be terminated
5718 : : is the name of a library file and we should try the standard
5719 : : search dirs for it. */
5720 : : static int this_is_library_file;
5721 : :
5722 : : /* Nonzero means %T has been seen; the next arg to be terminated
5723 : : is the name of a linker script and we should try all of the
5724 : : standard search dirs for it. If it is found insert a --script
5725 : : command line switch and then substitute the full path in place,
5726 : : otherwise generate an error message. */
5727 : : static int this_is_linker_script;
5728 : :
5729 : : /* Nonzero means that the input of this command is coming from a pipe. */
5730 : : static int input_from_pipe;
5731 : :
5732 : : /* Nonnull means substitute this for any suffix when outputting a switches
5733 : : arguments. */
5734 : : static const char *suffix_subst;
5735 : :
5736 : : /* If there is an argument being accumulated, terminate it and store it. */
5737 : :
5738 : : static void
5739 : 81882743 : end_going_arg (void)
5740 : : {
5741 : 81882743 : if (arg_going)
5742 : : {
5743 : 20080165 : const char *string;
5744 : :
5745 : 20080165 : obstack_1grow (&obstack, 0);
5746 : 20080165 : string = XOBFINISH (&obstack, const char *);
5747 : 20080165 : if (this_is_library_file)
5748 : 542126 : string = find_file (string);
5749 : 20080165 : if (this_is_linker_script)
5750 : : {
5751 : 0 : char * full_script_path = find_a_file (&startfile_prefixes, string, R_OK, true);
5752 : :
5753 : 0 : if (full_script_path == NULL)
5754 : : {
5755 : 0 : error ("unable to locate default linker script %qs in the library search paths", string);
5756 : : /* Script was not found on search path. */
5757 : 0 : return;
5758 : : }
5759 : 0 : store_arg ("--script", false, false);
5760 : 0 : string = full_script_path;
5761 : : }
5762 : 20080165 : store_arg (string, delete_this_arg, this_is_output_file);
5763 : 20080165 : if (this_is_output_file)
5764 : 100582 : outfiles[input_file_number] = string;
5765 : 20080165 : arg_going = 0;
5766 : : }
5767 : : }
5768 : :
5769 : :
5770 : : /* Parse the WRAPPER string which is a comma separated list of the command line
5771 : : and insert them into the beginning of argbuf. */
5772 : :
5773 : : static void
5774 : 0 : insert_wrapper (const char *wrapper)
5775 : : {
5776 : 0 : int n = 0;
5777 : 0 : int i;
5778 : 0 : char *buf = xstrdup (wrapper);
5779 : 0 : char *p = buf;
5780 : 0 : unsigned int old_length = argbuf.length ();
5781 : :
5782 : 0 : do
5783 : : {
5784 : 0 : n++;
5785 : 0 : while (*p == ',')
5786 : 0 : p++;
5787 : : }
5788 : 0 : while ((p = strchr (p, ',')) != NULL);
5789 : :
5790 : 0 : argbuf.safe_grow (old_length + n, true);
5791 : 0 : memmove (argbuf.address () + n,
5792 : 0 : argbuf.address (),
5793 : 0 : old_length * sizeof (const_char_p));
5794 : :
5795 : 0 : i = 0;
5796 : 0 : p = buf;
5797 : : do
5798 : : {
5799 : 0 : while (*p == ',')
5800 : : {
5801 : 0 : *p = 0;
5802 : 0 : p++;
5803 : : }
5804 : 0 : argbuf[i] = p;
5805 : 0 : i++;
5806 : : }
5807 : 0 : while ((p = strchr (p, ',')) != NULL);
5808 : 0 : gcc_assert (i == n);
5809 : 0 : }
5810 : :
5811 : : /* Process the spec SPEC and run the commands specified therein.
5812 : : Returns 0 if the spec is successfully processed; -1 if failed. */
5813 : :
5814 : : int
5815 : 568145 : do_spec (const char *spec)
5816 : : {
5817 : 568145 : int value;
5818 : :
5819 : 568145 : value = do_spec_2 (spec, NULL);
5820 : :
5821 : : /* Force out any unfinished command.
5822 : : If -pipe, this forces out the last command if it ended in `|'. */
5823 : 568145 : if (value == 0)
5824 : : {
5825 : 562400 : if (argbuf.length () > 0
5826 : 844672 : && !strcmp (argbuf.last (), "|"))
5827 : 0 : argbuf.pop ();
5828 : :
5829 : 562400 : set_collect_gcc_options ();
5830 : :
5831 : 562400 : if (argbuf.length () > 0)
5832 : 282272 : value = execute ();
5833 : : }
5834 : :
5835 : 568145 : return value;
5836 : : }
5837 : :
5838 : : /* Process the spec SPEC, with SOFT_MATCHED_PART designating the current value
5839 : : of a matched * pattern which may be re-injected by way of %*. */
5840 : :
5841 : : static int
5842 : 5347147 : do_spec_2 (const char *spec, const char *soft_matched_part)
5843 : : {
5844 : 5347147 : int result;
5845 : :
5846 : 5347147 : clear_args ();
5847 : 5347147 : arg_going = 0;
5848 : 5347147 : delete_this_arg = 0;
5849 : 5347147 : this_is_output_file = 0;
5850 : 5347147 : this_is_library_file = 0;
5851 : 5347147 : this_is_linker_script = 0;
5852 : 5347147 : input_from_pipe = 0;
5853 : 5347147 : suffix_subst = NULL;
5854 : :
5855 : 5347147 : result = do_spec_1 (spec, 0, soft_matched_part);
5856 : :
5857 : 5347147 : end_going_arg ();
5858 : :
5859 : 5347147 : return result;
5860 : : }
5861 : :
5862 : : /* Process the given spec string and add any new options to the end
5863 : : of the switches/n_switches array. */
5864 : :
5865 : : static void
5866 : 2994750 : do_option_spec (const char *name, const char *spec)
5867 : : {
5868 : 2994750 : unsigned int i, value_count, value_len;
5869 : 2994750 : const char *p, *q, *value;
5870 : 2994750 : char *tmp_spec, *tmp_spec_p;
5871 : :
5872 : 2994750 : if (configure_default_options[0].name == NULL)
5873 : : return;
5874 : :
5875 : 8085825 : for (i = 0; i < ARRAY_SIZE (configure_default_options); i++)
5876 : 5690025 : if (strcmp (configure_default_options[i].name, name) == 0)
5877 : : break;
5878 : 2994750 : if (i == ARRAY_SIZE (configure_default_options))
5879 : : return;
5880 : :
5881 : 598950 : value = configure_default_options[i].value;
5882 : 598950 : value_len = strlen (value);
5883 : :
5884 : : /* Compute the size of the final spec. */
5885 : 598950 : value_count = 0;
5886 : 598950 : p = spec;
5887 : 1197900 : while ((p = strstr (p, "%(VALUE)")) != NULL)
5888 : : {
5889 : 598950 : p ++;
5890 : 598950 : value_count ++;
5891 : : }
5892 : :
5893 : : /* Replace each %(VALUE) by the specified value. */
5894 : 598950 : tmp_spec = (char *) alloca (strlen (spec) + 1
5895 : : + value_count * (value_len - strlen ("%(VALUE)")));
5896 : 598950 : tmp_spec_p = tmp_spec;
5897 : 598950 : q = spec;
5898 : 1197900 : while ((p = strstr (q, "%(VALUE)")) != NULL)
5899 : : {
5900 : 598950 : memcpy (tmp_spec_p, q, p - q);
5901 : 598950 : tmp_spec_p = tmp_spec_p + (p - q);
5902 : 598950 : memcpy (tmp_spec_p, value, value_len);
5903 : 598950 : tmp_spec_p += value_len;
5904 : 598950 : q = p + strlen ("%(VALUE)");
5905 : : }
5906 : 598950 : strcpy (tmp_spec_p, q);
5907 : :
5908 : 598950 : do_self_spec (tmp_spec);
5909 : : }
5910 : :
5911 : : /* Process the given spec string and add any new options to the end
5912 : : of the switches/n_switches array. */
5913 : :
5914 : : static void
5915 : 2695595 : do_self_spec (const char *spec)
5916 : : {
5917 : 2695595 : int i;
5918 : :
5919 : 2695595 : do_spec_2 (spec, NULL);
5920 : 2695595 : do_spec_1 (" ", 0, NULL);
5921 : :
5922 : : /* Mark %<S switches processed by do_self_spec to be ignored permanently.
5923 : : do_self_specs adds the replacements to switches array, so it shouldn't
5924 : : be processed afterwards. */
5925 : 65483785 : for (i = 0; i < n_switches; i++)
5926 : 60092595 : if ((switches[i].live_cond & SWITCH_IGNORE))
5927 : 667 : switches[i].live_cond |= SWITCH_IGNORE_PERMANENTLY;
5928 : :
5929 : 2695595 : if (argbuf.length () > 0)
5930 : : {
5931 : 565444 : const char **argbuf_copy;
5932 : 565444 : struct cl_decoded_option *decoded_options;
5933 : 565444 : struct cl_option_handlers handlers;
5934 : 565444 : unsigned int decoded_options_count;
5935 : 565444 : unsigned int j;
5936 : :
5937 : : /* Create a copy of argbuf with a dummy argv[0] entry for
5938 : : decode_cmdline_options_to_array. */
5939 : 565444 : argbuf_copy = XNEWVEC (const char *,
5940 : : argbuf.length () + 1);
5941 : 565444 : argbuf_copy[0] = "";
5942 : 565444 : memcpy (argbuf_copy + 1, argbuf.address (),
5943 : 565444 : argbuf.length () * sizeof (const char *));
5944 : :
5945 : 1130888 : decode_cmdline_options_to_array (argbuf.length () + 1,
5946 : : argbuf_copy,
5947 : : CL_DRIVER, &decoded_options,
5948 : : &decoded_options_count);
5949 : 565444 : free (argbuf_copy);
5950 : :
5951 : 565444 : set_option_handlers (&handlers);
5952 : :
5953 : 1133364 : for (j = 1; j < decoded_options_count; j++)
5954 : : {
5955 : 567920 : switch (decoded_options[j].opt_index)
5956 : : {
5957 : 0 : case OPT_SPECIAL_input_file:
5958 : : /* Specs should only generate options, not input
5959 : : files. */
5960 : 0 : if (strcmp (decoded_options[j].arg, "-") != 0)
5961 : 0 : fatal_error (input_location,
5962 : : "switch %qs does not start with %<-%>",
5963 : : decoded_options[j].arg);
5964 : : else
5965 : 0 : fatal_error (input_location,
5966 : : "spec-generated switch is just %<-%>");
5967 : 1238 : break;
5968 : :
5969 : 1238 : case OPT_fcompare_debug_second:
5970 : 1238 : case OPT_fcompare_debug:
5971 : 1238 : case OPT_fcompare_debug_:
5972 : 1238 : case OPT_o:
5973 : : /* Avoid duplicate processing of some options from
5974 : : compare-debug specs; just save them here. */
5975 : 1238 : save_switch (decoded_options[j].canonical_option[0],
5976 : 1238 : (decoded_options[j].canonical_option_num_elements
5977 : : - 1),
5978 : 1238 : &decoded_options[j].canonical_option[1], false, true);
5979 : 1238 : break;
5980 : :
5981 : 566682 : default:
5982 : 566682 : read_cmdline_option (&global_options, &global_options_set,
5983 : : decoded_options + j, UNKNOWN_LOCATION,
5984 : : CL_DRIVER, &handlers, global_dc);
5985 : 566682 : break;
5986 : : }
5987 : : }
5988 : :
5989 : 565444 : free (decoded_options);
5990 : :
5991 : 565444 : alloc_switch ();
5992 : 565444 : switches[n_switches].part1 = 0;
5993 : : }
5994 : 2695595 : }
5995 : :
5996 : : /* Callback for processing %D and %I specs. */
5997 : :
5998 : : struct spec_path {
5999 : : const char *option;
6000 : : const char *append;
6001 : : size_t append_len;
6002 : : bool omit_relative;
6003 : : bool separate_options;
6004 : : bool realpaths;
6005 : :
6006 : : void *operator() (char *path);
6007 : : };
6008 : :
6009 : : void *
6010 : 3360714 : spec_path::operator() (char *path)
6011 : : {
6012 : 3360714 : size_t len = 0;
6013 : 3360714 : char save = 0;
6014 : :
6015 : : /* The path must exist; we want to resolve it to the realpath so that this
6016 : : can be embedded as a runpath. */
6017 : 3360714 : if (realpaths)
6018 : 0 : path = lrealpath (path);
6019 : :
6020 : : /* However, if we failed to resolve it - perhaps because there was a bogus
6021 : : -B option on the command line, then punt on this entry. */
6022 : 3360714 : if (!path)
6023 : : return NULL;
6024 : :
6025 : 3360714 : if (omit_relative && !IS_ABSOLUTE_PATH (path))
6026 : : return NULL;
6027 : :
6028 : 3360714 : if (append_len != 0)
6029 : : {
6030 : 1400252 : len = strlen (path);
6031 : 1400252 : memcpy (path + len, append, append_len + 1);
6032 : : }
6033 : :
6034 : 3360714 : if (!is_directory (path))
6035 : : return NULL;
6036 : :
6037 : 1259999 : do_spec_1 (option, 1, NULL);
6038 : 1259999 : if (separate_options)
6039 : 450392 : do_spec_1 (" ", 0, NULL);
6040 : :
6041 : 1259999 : if (append_len == 0)
6042 : : {
6043 : 809607 : len = strlen (path);
6044 : 809607 : save = path[len - 1];
6045 : 809607 : if (IS_DIR_SEPARATOR (path[len - 1]))
6046 : 809607 : path[len - 1] = '\0';
6047 : : }
6048 : :
6049 : 1259999 : do_spec_1 (path, 1, NULL);
6050 : 1259999 : do_spec_1 (" ", 0, NULL);
6051 : :
6052 : : /* Must not damage the original path. */
6053 : 1259999 : if (append_len == 0)
6054 : 809607 : path[len - 1] = save;
6055 : :
6056 : : return NULL;
6057 : : }
6058 : :
6059 : : /* True if we should compile INFILE. */
6060 : :
6061 : : static bool
6062 : 45211 : compile_input_file_p (struct infile *infile)
6063 : : {
6064 : 27860 : if ((!infile->language) || (infile->language[0] != '*'))
6065 : 40616 : if (infile->incompiler == input_file_compiler)
6066 : 0 : return true;
6067 : : return false;
6068 : : }
6069 : :
6070 : : /* Process each member of VEC as a spec. */
6071 : :
6072 : : static void
6073 : 470054 : do_specs_vec (vec<char_p> vec)
6074 : : {
6075 : 470172 : for (char *opt : vec)
6076 : : {
6077 : 70 : do_spec_1 (opt, 1, NULL);
6078 : : /* Make each accumulated option a separate argument. */
6079 : 70 : do_spec_1 (" ", 0, NULL);
6080 : : }
6081 : 470054 : }
6082 : :
6083 : : /* Add options passed via -Xassembler or -Wa to COLLECT_AS_OPTIONS. */
6084 : :
6085 : : static void
6086 : 299343 : putenv_COLLECT_AS_OPTIONS (vec<char_p> vec)
6087 : : {
6088 : 299343 : if (vec.is_empty ())
6089 : 299343 : return;
6090 : :
6091 : 103 : obstack_init (&collect_obstack);
6092 : 103 : obstack_grow (&collect_obstack, "COLLECT_AS_OPTIONS=",
6093 : : strlen ("COLLECT_AS_OPTIONS="));
6094 : :
6095 : 103 : char *opt;
6096 : 103 : unsigned ix;
6097 : :
6098 : 298 : FOR_EACH_VEC_ELT (vec, ix, opt)
6099 : : {
6100 : 195 : obstack_1grow (&collect_obstack, '\'');
6101 : 195 : obstack_grow (&collect_obstack, opt, strlen (opt));
6102 : 195 : obstack_1grow (&collect_obstack, '\'');
6103 : 195 : if (ix < vec.length () - 1)
6104 : 92 : obstack_1grow(&collect_obstack, ' ');
6105 : : }
6106 : :
6107 : 103 : obstack_1grow (&collect_obstack, '\0');
6108 : 103 : xputenv (XOBFINISH (&collect_obstack, char *));
6109 : : }
6110 : :
6111 : : /* Process the sub-spec SPEC as a portion of a larger spec.
6112 : : This is like processing a whole spec except that we do
6113 : : not initialize at the beginning and we do not supply a
6114 : : newline by default at the end.
6115 : : INSWITCH nonzero means don't process %-sequences in SPEC;
6116 : : in this case, % is treated as an ordinary character.
6117 : : This is used while substituting switches.
6118 : : INSWITCH nonzero also causes SPC not to terminate an argument.
6119 : :
6120 : : Value is zero unless a line was finished
6121 : : and the command on that line reported an error. */
6122 : :
6123 : : static int
6124 : 52893095 : do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part)
6125 : : {
6126 : 52893095 : const char *p = spec;
6127 : 52893095 : int c;
6128 : 52893095 : int i;
6129 : 52893095 : int value;
6130 : :
6131 : : /* If it's an empty string argument to a switch, keep it as is. */
6132 : 52893095 : if (inswitch && !*p)
6133 : 1 : arg_going = 1;
6134 : :
6135 : 542579117 : while ((c = *p++))
6136 : : /* If substituting a switch, treat all chars like letters.
6137 : : Otherwise, NL, SPC, TAB and % are special. */
6138 : 489734359 : switch (inswitch ? 'a' : c)
6139 : : {
6140 : 265801 : case '\n':
6141 : 265801 : end_going_arg ();
6142 : :
6143 : 265801 : if (argbuf.length () > 0
6144 : 531602 : && !strcmp (argbuf.last (), "|"))
6145 : : {
6146 : : /* A `|' before the newline means use a pipe here,
6147 : : but only if -pipe was specified.
6148 : : Otherwise, execute now and don't pass the `|' as an arg. */
6149 : 168893 : if (use_pipes)
6150 : : {
6151 : 0 : input_from_pipe = 1;
6152 : 0 : break;
6153 : : }
6154 : : else
6155 : 168893 : argbuf.pop ();
6156 : : }
6157 : :
6158 : 265801 : set_collect_gcc_options ();
6159 : :
6160 : 265801 : if (argbuf.length () > 0)
6161 : : {
6162 : 265801 : value = execute ();
6163 : 265801 : if (value)
6164 : : return value;
6165 : : }
6166 : : /* Reinitialize for a new command, and for a new argument. */
6167 : 260056 : clear_args ();
6168 : 260056 : arg_going = 0;
6169 : 260056 : delete_this_arg = 0;
6170 : 260056 : this_is_output_file = 0;
6171 : 260056 : this_is_library_file = 0;
6172 : 260056 : this_is_linker_script = 0;
6173 : 260056 : input_from_pipe = 0;
6174 : 260056 : break;
6175 : :
6176 : 168893 : case '|':
6177 : 168893 : end_going_arg ();
6178 : :
6179 : : /* Use pipe */
6180 : 168893 : obstack_1grow (&obstack, c);
6181 : 168893 : arg_going = 1;
6182 : 168893 : break;
6183 : :
6184 : 71400873 : case '\t':
6185 : 71400873 : case ' ':
6186 : 71400873 : end_going_arg ();
6187 : :
6188 : : /* Reinitialize for a new argument. */
6189 : 71400873 : delete_this_arg = 0;
6190 : 71400873 : this_is_output_file = 0;
6191 : 71400873 : this_is_library_file = 0;
6192 : 71400873 : this_is_linker_script = 0;
6193 : 71400873 : break;
6194 : :
6195 : 49523702 : case '%':
6196 : 49523702 : switch (c = *p++)
6197 : : {
6198 : 0 : case 0:
6199 : 0 : fatal_error (input_location, "spec %qs invalid", spec);
6200 : :
6201 : 3599 : case 'b':
6202 : : /* Don't use %b in the linker command. */
6203 : 3599 : gcc_assert (suffixed_basename_length);
6204 : 3599 : if (!this_is_output_file && dumpdir_length)
6205 : 689 : obstack_grow (&obstack, dumpdir, dumpdir_length);
6206 : 3599 : if (this_is_output_file || !outbase_length)
6207 : 3257 : obstack_grow (&obstack, input_basename, basename_length);
6208 : : else
6209 : 342 : obstack_grow (&obstack, outbase, outbase_length);
6210 : 3599 : if (compare_debug < 0)
6211 : 6 : obstack_grow (&obstack, ".gk", 3);
6212 : 3599 : arg_going = 1;
6213 : 3599 : break;
6214 : :
6215 : 10 : case 'B':
6216 : : /* Don't use %B in the linker command. */
6217 : 10 : gcc_assert (suffixed_basename_length);
6218 : 10 : if (!this_is_output_file && dumpdir_length)
6219 : 0 : obstack_grow (&obstack, dumpdir, dumpdir_length);
6220 : 10 : if (this_is_output_file || !outbase_length)
6221 : 5 : obstack_grow (&obstack, input_basename, basename_length);
6222 : : else
6223 : 5 : obstack_grow (&obstack, outbase, outbase_length);
6224 : 10 : if (compare_debug < 0)
6225 : 3 : obstack_grow (&obstack, ".gk", 3);
6226 : 10 : obstack_grow (&obstack, input_basename + basename_length,
6227 : : suffixed_basename_length - basename_length);
6228 : :
6229 : 10 : arg_going = 1;
6230 : 10 : break;
6231 : :
6232 : 98065 : case 'd':
6233 : 98065 : delete_this_arg = 2;
6234 : 98065 : break;
6235 : :
6236 : : /* Dump out the directories specified with LIBRARY_PATH,
6237 : : followed by the absolute directories
6238 : : that we search for startfiles. */
6239 : 105905 : case 'D':
6240 : 105905 : {
6241 : 105905 : struct spec_path info;
6242 : :
6243 : 105905 : info.option = "-L";
6244 : 105905 : info.append_len = 0;
6245 : : #ifdef RELATIVE_PREFIX_NOT_LINKDIR
6246 : : /* Used on systems which record the specified -L dirs
6247 : : and use them to search for dynamic linking.
6248 : : Relative directories always come from -B,
6249 : : and it is better not to use them for searching
6250 : : at run time. In particular, stage1 loses. */
6251 : : info.omit_relative = true;
6252 : : #else
6253 : 105905 : info.omit_relative = false;
6254 : : #endif
6255 : 105905 : info.separate_options = false;
6256 : 105905 : info.realpaths = false;
6257 : :
6258 : 105905 : for_each_path (&startfile_prefixes, true, 0, info);
6259 : : }
6260 : 105905 : break;
6261 : :
6262 : 0 : case 'P':
6263 : 0 : {
6264 : 0 : struct spec_path info;
6265 : :
6266 : 0 : info.option = RUNPATH_OPTION;
6267 : 0 : info.append_len = 0;
6268 : 0 : info.omit_relative = false;
6269 : 0 : info.separate_options = true;
6270 : : /* We want to embed the actual paths that have the libraries. */
6271 : 0 : info.realpaths = true;
6272 : :
6273 : 0 : for_each_path (&startfile_prefixes, true, 0, info);
6274 : : }
6275 : 0 : break;
6276 : :
6277 : : case 'e':
6278 : : /* %efoo means report an error with `foo' as error message
6279 : : and don't execute any more commands for this file. */
6280 : : {
6281 : : const char *q = p;
6282 : : char *buf;
6283 : 0 : while (*p != 0 && *p != '\n')
6284 : 0 : p++;
6285 : 0 : buf = (char *) alloca (p - q + 1);
6286 : 0 : strncpy (buf, q, p - q);
6287 : 0 : buf[p - q] = 0;
6288 : 0 : error ("%s", _(buf));
6289 : 0 : return -1;
6290 : : }
6291 : : break;
6292 : : case 'n':
6293 : : /* %nfoo means report a notice with `foo' on stderr. */
6294 : : {
6295 : : const char *q = p;
6296 : : char *buf;
6297 : 0 : while (*p != 0 && *p != '\n')
6298 : 0 : p++;
6299 : 0 : buf = (char *) alloca (p - q + 1);
6300 : 0 : strncpy (buf, q, p - q);
6301 : 0 : buf[p - q] = 0;
6302 : 0 : inform (UNKNOWN_LOCATION, "%s", _(buf));
6303 : 0 : if (*p)
6304 : 0 : p++;
6305 : : }
6306 : : break;
6307 : :
6308 : 882 : case 'j':
6309 : 882 : {
6310 : 882 : struct stat st;
6311 : :
6312 : : /* If save_temps_flag is off, and the HOST_BIT_BUCKET is
6313 : : defined, and it is not a directory, and it is
6314 : : writable, use it. Otherwise, treat this like any
6315 : : other temporary file. */
6316 : :
6317 : 882 : if ((!save_temps_flag)
6318 : 882 : && (stat (HOST_BIT_BUCKET, &st) == 0) && (!S_ISDIR (st.st_mode))
6319 : 1764 : && (access (HOST_BIT_BUCKET, W_OK) == 0))
6320 : : {
6321 : 882 : obstack_grow (&obstack, HOST_BIT_BUCKET,
6322 : : strlen (HOST_BIT_BUCKET));
6323 : 882 : delete_this_arg = 0;
6324 : 882 : arg_going = 1;
6325 : 882 : break;
6326 : : }
6327 : : }
6328 : 0 : goto create_temp_file;
6329 : 168893 : case '|':
6330 : 168893 : if (use_pipes)
6331 : : {
6332 : 0 : obstack_1grow (&obstack, '-');
6333 : 0 : delete_this_arg = 0;
6334 : 0 : arg_going = 1;
6335 : :
6336 : : /* consume suffix */
6337 : 0 : while (*p == '.' || ISALNUM ((unsigned char) *p))
6338 : 0 : p++;
6339 : 0 : if (p[0] == '%' && p[1] == 'O')
6340 : 0 : p += 2;
6341 : :
6342 : : break;
6343 : : }
6344 : 168893 : goto create_temp_file;
6345 : 163295 : case 'm':
6346 : 163295 : if (use_pipes)
6347 : : {
6348 : : /* consume suffix */
6349 : 0 : while (*p == '.' || ISALNUM ((unsigned char) *p))
6350 : 0 : p++;
6351 : 0 : if (p[0] == '%' && p[1] == 'O')
6352 : 0 : p += 2;
6353 : :
6354 : : break;
6355 : : }
6356 : 163295 : goto create_temp_file;
6357 : 523902 : case 'g':
6358 : 523902 : case 'u':
6359 : 523902 : case 'U':
6360 : 523902 : create_temp_file:
6361 : 523902 : {
6362 : 523902 : struct temp_name *t;
6363 : 523902 : int suffix_length;
6364 : 523902 : const char *suffix = p;
6365 : 523902 : char *saved_suffix = NULL;
6366 : :
6367 : 1560972 : while (*p == '.' || ISALNUM ((unsigned char) *p))
6368 : 1037070 : p++;
6369 : 523902 : suffix_length = p - suffix;
6370 : 523902 : if (p[0] == '%' && p[1] == 'O')
6371 : : {
6372 : 98281 : p += 2;
6373 : : /* We don't support extra suffix characters after %O. */
6374 : 98281 : if (*p == '.' || ISALNUM ((unsigned char) *p))
6375 : 0 : fatal_error (input_location,
6376 : : "spec %qs has invalid %<%%0%c%>", spec, *p);
6377 : 98281 : if (suffix_length == 0)
6378 : : suffix = TARGET_OBJECT_SUFFIX;
6379 : : else
6380 : : {
6381 : 0 : saved_suffix
6382 : 0 : = XNEWVEC (char, suffix_length
6383 : : + strlen (TARGET_OBJECT_SUFFIX) + 1);
6384 : 0 : strncpy (saved_suffix, suffix, suffix_length);
6385 : 0 : strcpy (saved_suffix + suffix_length,
6386 : : TARGET_OBJECT_SUFFIX);
6387 : : }
6388 : 98281 : suffix_length += strlen (TARGET_OBJECT_SUFFIX);
6389 : : }
6390 : :
6391 : 523902 : if (compare_debug < 0)
6392 : : {
6393 : 610 : suffix = concat (".gk", suffix, NULL);
6394 : 610 : suffix_length += 3;
6395 : : }
6396 : :
6397 : : /* If -save-temps was specified, use that for the
6398 : : temp file. */
6399 : 523902 : if (save_temps_flag)
6400 : : {
6401 : 1194 : char *tmp;
6402 : 1194 : bool adjusted_suffix = false;
6403 : 1194 : if (suffix_length
6404 : 1194 : && !outbase_length && !basename_length
6405 : 224 : && !dumpdir_trailing_dash_added)
6406 : : {
6407 : 20 : adjusted_suffix = true;
6408 : 20 : suffix++;
6409 : 20 : suffix_length--;
6410 : : }
6411 : 1194 : temp_filename_length
6412 : 1194 : = dumpdir_length + suffix_length + 1;
6413 : 1194 : if (outbase_length)
6414 : 72 : temp_filename_length += outbase_length;
6415 : : else
6416 : 1122 : temp_filename_length += basename_length;
6417 : 1194 : tmp = (char *) alloca (temp_filename_length);
6418 : 1194 : if (dumpdir_length)
6419 : 1036 : memcpy (tmp, dumpdir, dumpdir_length);
6420 : 1194 : if (outbase_length)
6421 : 72 : memcpy (tmp + dumpdir_length, outbase,
6422 : : outbase_length);
6423 : 1122 : else if (basename_length)
6424 : 898 : memcpy (tmp + dumpdir_length, input_basename,
6425 : : basename_length);
6426 : 1194 : memcpy (tmp + temp_filename_length - suffix_length - 1,
6427 : : suffix, suffix_length);
6428 : 1194 : if (adjusted_suffix)
6429 : : {
6430 : 20 : adjusted_suffix = false;
6431 : 20 : suffix--;
6432 : 20 : suffix_length++;
6433 : : }
6434 : 1194 : tmp[temp_filename_length - 1] = '\0';
6435 : 1194 : temp_filename = tmp;
6436 : :
6437 : 1194 : if (filename_cmp (temp_filename, gcc_input_filename) != 0)
6438 : : {
6439 : : #ifndef HOST_LACKS_INODE_NUMBERS
6440 : 1194 : struct stat st_temp;
6441 : :
6442 : : /* Note, set_input() resets input_stat_set to 0. */
6443 : 1194 : if (input_stat_set == 0)
6444 : : {
6445 : 557 : input_stat_set = stat (gcc_input_filename,
6446 : : &input_stat);
6447 : 557 : if (input_stat_set >= 0)
6448 : 557 : input_stat_set = 1;
6449 : : }
6450 : :
6451 : : /* If we have the stat for the gcc_input_filename
6452 : : and we can do the stat for the temp_filename
6453 : : then the they could still refer to the same
6454 : : file if st_dev/st_ino's are the same. */
6455 : 1194 : if (input_stat_set != 1
6456 : 1194 : || stat (temp_filename, &st_temp) < 0
6457 : 365 : || input_stat.st_dev != st_temp.st_dev
6458 : 1208 : || input_stat.st_ino != st_temp.st_ino)
6459 : : #else
6460 : : /* Just compare canonical pathnames. */
6461 : : char* input_realname = lrealpath (gcc_input_filename);
6462 : : char* temp_realname = lrealpath (temp_filename);
6463 : : bool files_differ = filename_cmp (input_realname, temp_realname);
6464 : : free (input_realname);
6465 : : free (temp_realname);
6466 : : if (files_differ)
6467 : : #endif
6468 : : {
6469 : 1194 : temp_filename
6470 : 1194 : = save_string (temp_filename,
6471 : : temp_filename_length - 1);
6472 : 1194 : obstack_grow (&obstack, temp_filename,
6473 : : temp_filename_length);
6474 : 1194 : arg_going = 1;
6475 : 1194 : delete_this_arg = 0;
6476 : 1194 : break;
6477 : : }
6478 : : }
6479 : : }
6480 : :
6481 : : /* See if we already have an association of %g/%u/%U and
6482 : : suffix. */
6483 : 894266 : for (t = temp_names; t; t = t->next)
6484 : 541863 : if (t->length == suffix_length
6485 : 362542 : && strncmp (t->suffix, suffix, suffix_length) == 0
6486 : 174253 : && t->unique == (c == 'u' || c == 'U' || c == 'j'))
6487 : : break;
6488 : :
6489 : : /* Make a new association if needed. %u and %j
6490 : : require one. */
6491 : 522708 : if (t == 0 || c == 'u' || c == 'j')
6492 : : {
6493 : 356157 : if (t == 0)
6494 : : {
6495 : 352403 : t = XNEW (struct temp_name);
6496 : 352403 : t->next = temp_names;
6497 : 352403 : temp_names = t;
6498 : : }
6499 : 356157 : t->length = suffix_length;
6500 : 356157 : if (saved_suffix)
6501 : : {
6502 : 0 : t->suffix = saved_suffix;
6503 : 0 : saved_suffix = NULL;
6504 : : }
6505 : : else
6506 : 356157 : t->suffix = save_string (suffix, suffix_length);
6507 : 356157 : t->unique = (c == 'u' || c == 'U' || c == 'j');
6508 : 356157 : temp_filename = make_temp_file (t->suffix);
6509 : 356157 : temp_filename_length = strlen (temp_filename);
6510 : 356157 : t->filename = temp_filename;
6511 : 356157 : t->filename_length = temp_filename_length;
6512 : : }
6513 : :
6514 : 522708 : free (saved_suffix);
6515 : :
6516 : 522708 : obstack_grow (&obstack, t->filename, t->filename_length);
6517 : 522708 : delete_this_arg = 1;
6518 : : }
6519 : 522708 : arg_going = 1;
6520 : 522708 : break;
6521 : :
6522 : 289547 : case 'i':
6523 : 289547 : if (combine_inputs)
6524 : : {
6525 : : /* We are going to expand `%i' into `@FILE', where FILE
6526 : : is a newly-created temporary filename. The filenames
6527 : : that would usually be expanded in place of %o will be
6528 : : written to the temporary file. */
6529 : 31452 : if (at_file_supplied)
6530 : 13172 : open_at_file ();
6531 : :
6532 : 76663 : for (i = 0; (int) i < n_infiles; i++)
6533 : 90422 : if (compile_input_file_p (&infiles[i]))
6534 : : {
6535 : 40554 : store_arg (infiles[i].name, 0, 0);
6536 : 40554 : infiles[i].compiled = true;
6537 : : }
6538 : :
6539 : 31452 : if (at_file_supplied)
6540 : 13172 : close_at_file ();
6541 : : }
6542 : : else
6543 : : {
6544 : 258095 : obstack_grow (&obstack, gcc_input_filename,
6545 : : input_filename_length);
6546 : 258095 : arg_going = 1;
6547 : : }
6548 : : break;
6549 : :
6550 : 224115 : case 'I':
6551 : 224115 : {
6552 : 224115 : struct spec_path info;
6553 : :
6554 : 224115 : if (multilib_dir)
6555 : : {
6556 : 5994 : do_spec_1 ("-imultilib", 1, NULL);
6557 : : /* Make this a separate argument. */
6558 : 5994 : do_spec_1 (" ", 0, NULL);
6559 : 5994 : do_spec_1 (multilib_dir, 1, NULL);
6560 : 5994 : do_spec_1 (" ", 0, NULL);
6561 : : }
6562 : :
6563 : 224115 : if (multiarch_dir)
6564 : : {
6565 : 0 : do_spec_1 ("-imultiarch", 1, NULL);
6566 : : /* Make this a separate argument. */
6567 : 0 : do_spec_1 (" ", 0, NULL);
6568 : 0 : do_spec_1 (multiarch_dir, 1, NULL);
6569 : 0 : do_spec_1 (" ", 0, NULL);
6570 : : }
6571 : :
6572 : 224115 : if (gcc_exec_prefix)
6573 : : {
6574 : 224115 : do_spec_1 ("-iprefix", 1, NULL);
6575 : : /* Make this a separate argument. */
6576 : 224115 : do_spec_1 (" ", 0, NULL);
6577 : 224115 : do_spec_1 (gcc_exec_prefix, 1, NULL);
6578 : 224115 : do_spec_1 (" ", 0, NULL);
6579 : : }
6580 : :
6581 : 224115 : if (target_system_root_changed ||
6582 : 224115 : (target_system_root && target_sysroot_hdrs_suffix))
6583 : : {
6584 : 0 : do_spec_1 ("-isysroot", 1, NULL);
6585 : : /* Make this a separate argument. */
6586 : 0 : do_spec_1 (" ", 0, NULL);
6587 : 0 : do_spec_1 (target_system_root, 1, NULL);
6588 : 0 : if (target_sysroot_hdrs_suffix)
6589 : 0 : do_spec_1 (target_sysroot_hdrs_suffix, 1, NULL);
6590 : 0 : do_spec_1 (" ", 0, NULL);
6591 : : }
6592 : :
6593 : 224115 : info.option = "-isystem";
6594 : 224115 : info.append = "include";
6595 : 224115 : info.append_len = strlen (info.append);
6596 : 224115 : info.omit_relative = false;
6597 : 224115 : info.separate_options = true;
6598 : 224115 : info.realpaths = false;
6599 : :
6600 : 224115 : for_each_path (&include_prefixes, false, info.append_len, info);
6601 : :
6602 : 224115 : info.append = "include-fixed";
6603 : 224115 : if (*sysroot_hdrs_suffix_spec)
6604 : 0 : info.append = concat (info.append, dir_separator_str,
6605 : : multilib_dir, NULL);
6606 : 224115 : else if (multiarch_dir)
6607 : : {
6608 : : /* For multiarch, search include-fixed/<multiarch-dir>
6609 : : before include-fixed. */
6610 : 0 : info.append = concat (info.append, dir_separator_str,
6611 : : multiarch_dir, NULL);
6612 : 0 : info.append_len = strlen (info.append);
6613 : 0 : for_each_path (&include_prefixes, false,
6614 : : info.append_len, info);
6615 : :
6616 : 0 : info.append = "include-fixed";
6617 : : }
6618 : 224115 : info.append_len = strlen (info.append);
6619 : 224115 : for_each_path (&include_prefixes, false, info.append_len, info);
6620 : : }
6621 : 224115 : break;
6622 : :
6623 : 96071 : case 'o':
6624 : : /* We are going to expand `%o' into `@FILE', where FILE
6625 : : is a newly-created temporary filename. The filenames
6626 : : that would usually be expanded in place of %o will be
6627 : : written to the temporary file. */
6628 : 96071 : if (at_file_supplied)
6629 : 6 : open_at_file ();
6630 : :
6631 : 425896 : for (i = 0; i < n_infiles + lang_specific_extra_outfiles; i++)
6632 : 329825 : if (outfiles[i])
6633 : 329785 : store_arg (outfiles[i], 0, 0);
6634 : :
6635 : 96071 : if (at_file_supplied)
6636 : 6 : close_at_file ();
6637 : : break;
6638 : :
6639 : 3917 : case 'O':
6640 : 3917 : obstack_grow (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX));
6641 : 3917 : arg_going = 1;
6642 : 3917 : break;
6643 : :
6644 : 542130 : case 's':
6645 : 542130 : this_is_library_file = 1;
6646 : 542130 : break;
6647 : :
6648 : 0 : case 'T':
6649 : 0 : this_is_linker_script = 1;
6650 : 0 : break;
6651 : :
6652 : 451 : case 'V':
6653 : 451 : outfiles[input_file_number] = NULL;
6654 : 451 : break;
6655 : :
6656 : 101040 : case 'w':
6657 : 101040 : this_is_output_file = 1;
6658 : 101040 : break;
6659 : :
6660 : 175210 : case 'W':
6661 : 175210 : {
6662 : 175210 : unsigned int cur_index = argbuf.length ();
6663 : : /* Handle the {...} following the %W. */
6664 : 175210 : if (*p != '{')
6665 : 0 : fatal_error (input_location,
6666 : : "spec %qs has invalid %<%%W%c%>", spec, *p);
6667 : 175210 : p = handle_braces (p + 1);
6668 : 175210 : if (p == 0)
6669 : : return -1;
6670 : 175210 : end_going_arg ();
6671 : : /* If any args were output, mark the last one for deletion
6672 : : on failure. */
6673 : 350420 : if (argbuf.length () != cur_index)
6674 : 172032 : record_temp_file (argbuf.last (), 0, 1);
6675 : : break;
6676 : : }
6677 : :
6678 : 304892 : case '@':
6679 : : /* Handle the {...} following the %@. */
6680 : 304892 : if (*p != '{')
6681 : 0 : fatal_error (input_location,
6682 : : "spec %qs has invalid %<%%@%c%>", spec, *p);
6683 : 304892 : if (at_file_supplied)
6684 : 15 : open_at_file ();
6685 : 304892 : p = handle_braces (p + 1);
6686 : 304892 : if (at_file_supplied)
6687 : 15 : close_at_file ();
6688 : 304892 : if (p == 0)
6689 : : return -1;
6690 : : break;
6691 : :
6692 : : /* %x{OPTION} records OPTION for %X to output. */
6693 : 0 : case 'x':
6694 : 0 : {
6695 : 0 : const char *p1 = p;
6696 : 0 : char *string;
6697 : :
6698 : : /* Skip past the option value and make a copy. */
6699 : 0 : if (*p != '{')
6700 : 0 : fatal_error (input_location,
6701 : : "spec %qs has invalid %<%%x%c%>", spec, *p);
6702 : 0 : while (*p++ != '}')
6703 : : ;
6704 : 0 : string = save_string (p1 + 1, p - p1 - 2);
6705 : :
6706 : : /* See if we already recorded this option. */
6707 : 0 : for (const char *opt : linker_options)
6708 : 0 : if (! strcmp (string, opt))
6709 : : {
6710 : 0 : free (string);
6711 : 0 : return 0;
6712 : : }
6713 : :
6714 : : /* This option is new; add it. */
6715 : 0 : add_linker_option (string, strlen (string));
6716 : 0 : free (string);
6717 : : }
6718 : 0 : break;
6719 : :
6720 : : /* Dump out the options accumulated previously using %x. */
6721 : 96071 : case 'X':
6722 : 96071 : do_specs_vec (linker_options);
6723 : 96071 : break;
6724 : :
6725 : : /* Dump out the options accumulated previously using -Wa,. */
6726 : 165162 : case 'Y':
6727 : 165162 : do_specs_vec (assembler_options);
6728 : 165162 : break;
6729 : :
6730 : : /* Dump out the options accumulated previously using -Wp,. */
6731 : 208821 : case 'Z':
6732 : 208821 : do_specs_vec (preprocessor_options);
6733 : 208821 : break;
6734 : :
6735 : : /* Here are digits and numbers that just process
6736 : : a certain constant string as a spec. */
6737 : :
6738 : 286474 : case '1':
6739 : 286474 : value = do_spec_1 (cc1_spec, 0, NULL);
6740 : 286474 : if (value != 0)
6741 : : return value;
6742 : : break;
6743 : :
6744 : 96925 : case '2':
6745 : 96925 : value = do_spec_1 (cc1plus_spec, 0, NULL);
6746 : 96925 : if (value != 0)
6747 : : return value;
6748 : : break;
6749 : :
6750 : 165162 : case 'a':
6751 : 165162 : value = do_spec_1 (asm_spec, 0, NULL);
6752 : 165162 : if (value != 0)
6753 : : return value;
6754 : : break;
6755 : :
6756 : 165162 : case 'A':
6757 : 165162 : value = do_spec_1 (asm_final_spec, 0, NULL);
6758 : 165162 : if (value != 0)
6759 : : return value;
6760 : : break;
6761 : :
6762 : 208821 : case 'C':
6763 : 208821 : {
6764 : 112022 : const char *const spec
6765 : 208821 : = (input_file_compiler->cpp_spec
6766 : 208821 : ? input_file_compiler->cpp_spec
6767 : : : cpp_spec);
6768 : 208821 : value = do_spec_1 (spec, 0, NULL);
6769 : 208821 : if (value != 0)
6770 : : return value;
6771 : : }
6772 : : break;
6773 : :
6774 : 95866 : case 'E':
6775 : 95866 : value = do_spec_1 (endfile_spec, 0, NULL);
6776 : 95866 : if (value != 0)
6777 : : return value;
6778 : : break;
6779 : :
6780 : 96071 : case 'l':
6781 : 96071 : value = do_spec_1 (link_spec, 0, NULL);
6782 : 96071 : if (value != 0)
6783 : : return value;
6784 : : break;
6785 : :
6786 : 186279 : case 'L':
6787 : 186279 : value = do_spec_1 (lib_spec, 0, NULL);
6788 : 186279 : if (value != 0)
6789 : : return value;
6790 : : break;
6791 : :
6792 : 0 : case 'M':
6793 : 0 : if (multilib_os_dir == NULL)
6794 : 0 : obstack_1grow (&obstack, '.');
6795 : : else
6796 : 0 : obstack_grow (&obstack, multilib_os_dir,
6797 : : strlen (multilib_os_dir));
6798 : : break;
6799 : :
6800 : 372362 : case 'G':
6801 : 372362 : value = do_spec_1 (libgcc_spec, 0, NULL);
6802 : 372362 : if (value != 0)
6803 : : return value;
6804 : : break;
6805 : :
6806 : 0 : case 'R':
6807 : : /* We assume there is a directory
6808 : : separator at the end of this string. */
6809 : 0 : if (target_system_root)
6810 : : {
6811 : 0 : obstack_grow (&obstack, target_system_root,
6812 : : strlen (target_system_root));
6813 : 0 : if (target_sysroot_suffix)
6814 : 0 : obstack_grow (&obstack, target_sysroot_suffix,
6815 : : strlen (target_sysroot_suffix));
6816 : : }
6817 : : break;
6818 : :
6819 : 95866 : case 'S':
6820 : 95866 : value = do_spec_1 (startfile_spec, 0, NULL);
6821 : 95866 : if (value != 0)
6822 : : return value;
6823 : : break;
6824 : :
6825 : : /* Here we define characters other than letters and digits. */
6826 : :
6827 : 40310146 : case '{':
6828 : 40310146 : p = handle_braces (p);
6829 : 40310146 : if (p == 0)
6830 : : return -1;
6831 : : break;
6832 : :
6833 : 439961 : case ':':
6834 : 439961 : p = handle_spec_function (p, NULL, soft_matched_part);
6835 : 439961 : if (p == 0)
6836 : : return -1;
6837 : : break;
6838 : :
6839 : 0 : case '%':
6840 : 0 : obstack_1grow (&obstack, '%');
6841 : 0 : break;
6842 : :
6843 : : case '.':
6844 : : {
6845 : : unsigned len = 0;
6846 : :
6847 : 11794 : while (p[len] && p[len] != ' ' && p[len] != '%')
6848 : 5915 : len++;
6849 : 5879 : suffix_subst = save_string (p - 1, len + 1);
6850 : 5879 : p += len;
6851 : : }
6852 : 5879 : break;
6853 : :
6854 : : /* Henceforth ignore the option(s) matching the pattern
6855 : : after the %<. */
6856 : 1472445 : case '<':
6857 : 1472445 : case '>':
6858 : 1472445 : {
6859 : 1472445 : unsigned len = 0;
6860 : 1472445 : int have_wildcard = 0;
6861 : 1472445 : int i;
6862 : 1472445 : int switch_option;
6863 : :
6864 : 1472445 : if (c == '>')
6865 : 1472445 : switch_option = SWITCH_IGNORE | SWITCH_KEEP_FOR_GCC;
6866 : : else
6867 : 1472423 : switch_option = SWITCH_IGNORE;
6868 : :
6869 : 17769855 : while (p[len] && p[len] != ' ' && p[len] != '\t')
6870 : 16297410 : len++;
6871 : :
6872 : 1472445 : if (p[len-1] == '*')
6873 : 15562 : have_wildcard = 1;
6874 : :
6875 : 35228781 : for (i = 0; i < n_switches; i++)
6876 : 33756336 : if (!strncmp (switches[i].part1, p, len - have_wildcard)
6877 : 49297 : && (have_wildcard || switches[i].part1[len] == '\0'))
6878 : : {
6879 : 49028 : switches[i].live_cond |= switch_option;
6880 : : /* User switch be validated from validate_all_switches.
6881 : : when the definition is seen from the spec file.
6882 : : If not defined anywhere, will be rejected. */
6883 : 49028 : if (switches[i].known)
6884 : 49028 : switches[i].validated = true;
6885 : : }
6886 : :
6887 : : p += len;
6888 : : }
6889 : : break;
6890 : :
6891 : 6802 : case '*':
6892 : 6802 : if (soft_matched_part)
6893 : : {
6894 : 6802 : if (soft_matched_part[0])
6895 : 359 : do_spec_1 (soft_matched_part, 1, NULL);
6896 : : /* Only insert a space after the substitution if it is at the
6897 : : end of the current sequence. So if:
6898 : :
6899 : : "%{foo=*:bar%*}%{foo=*:one%*two}"
6900 : :
6901 : : matches -foo=hello then it will produce:
6902 : :
6903 : : barhello onehellotwo
6904 : : */
6905 : 6802 : if (*p == 0 || *p == '}')
6906 : 6802 : do_spec_1 (" ", 0, NULL);
6907 : : }
6908 : : else
6909 : : /* Catch the case where a spec string contains something like
6910 : : '%{foo:%*}'. i.e. there is no * in the pattern on the left
6911 : : hand side of the :. */
6912 : 0 : error ("spec failure: %<%%*%> has not been initialized by pattern match");
6913 : : break;
6914 : :
6915 : : /* Process a string found as the value of a spec given by name.
6916 : : This feature allows individual machine descriptions
6917 : : to add and use their own specs. */
6918 : : case '(':
6919 : : {
6920 : 33462685 : const char *name = p;
6921 : : struct spec_list *sl;
6922 : : int len;
6923 : :
6924 : : /* The string after the S/P is the name of a spec that is to be
6925 : : processed. */
6926 : 33462685 : while (*p && *p != ')')
6927 : 30883003 : p++;
6928 : :
6929 : : /* See if it's in the list. */
6930 : 35421661 : for (len = p - name, sl = specs; sl; sl = sl->next)
6931 : 35421661 : if (sl->name_len == len && !strncmp (sl->name, name, len))
6932 : : {
6933 : 2579682 : name = *(sl->ptr_spec);
6934 : : #ifdef DEBUG_SPECS
6935 : : fnotice (stderr, "Processing spec (%s), which is '%s'\n",
6936 : : sl->name, name);
6937 : : #endif
6938 : 2579682 : break;
6939 : : }
6940 : :
6941 : 2579682 : if (sl)
6942 : : {
6943 : 2579682 : value = do_spec_1 (name, 0, NULL);
6944 : 2579682 : if (value != 0)
6945 : : return value;
6946 : : }
6947 : :
6948 : : /* Discard the closing paren. */
6949 : 2574084 : if (*p)
6950 : 2574084 : p++;
6951 : : }
6952 : : break;
6953 : :
6954 : 9 : case '"':
6955 : : /* End a previous argument, if there is one, then issue an
6956 : : empty argument. */
6957 : 9 : end_going_arg ();
6958 : 9 : arg_going = 1;
6959 : 9 : end_going_arg ();
6960 : 9 : break;
6961 : :
6962 : 0 : default:
6963 : 0 : error ("spec failure: unrecognized spec option %qc", c);
6964 : 0 : break;
6965 : : }
6966 : : break;
6967 : :
6968 : 0 : case '\\':
6969 : : /* Backslash: treat next character as ordinary. */
6970 : 0 : c = *p++;
6971 : :
6972 : : /* When adding more cases that previously matched default, make
6973 : : sure to adjust quote_spec_char_p as well. */
6974 : :
6975 : : /* Fall through. */
6976 : 368375090 : default:
6977 : : /* Ordinary character: put it into the current argument. */
6978 : 368375090 : obstack_1grow (&obstack, c);
6979 : 368375090 : arg_going = 1;
6980 : : }
6981 : :
6982 : : /* End of string. If we are processing a spec function, we need to
6983 : : end any pending argument. */
6984 : 52844758 : if (processing_spec_function)
6985 : 4524801 : end_going_arg ();
6986 : :
6987 : : return 0;
6988 : : }
6989 : :
6990 : : /* Look up a spec function. */
6991 : :
6992 : : static const struct spec_function *
6993 : 2080941 : lookup_spec_function (const char *name)
6994 : : {
6995 : 2080941 : const struct spec_function *sf;
6996 : :
6997 : 24905536 : for (sf = static_spec_functions; sf->name != NULL; sf++)
6998 : 24905536 : if (strcmp (sf->name, name) == 0)
6999 : : return sf;
7000 : :
7001 : : return NULL;
7002 : : }
7003 : :
7004 : : /* Evaluate a spec function. */
7005 : :
7006 : : static const char *
7007 : 2080941 : eval_spec_function (const char *func, const char *args,
7008 : : const char *soft_matched_part)
7009 : : {
7010 : 2080941 : const struct spec_function *sf;
7011 : 2080941 : const char *funcval;
7012 : :
7013 : : /* Saved spec processing context. */
7014 : 2080941 : vec<const_char_p> save_argbuf;
7015 : :
7016 : 2080941 : int save_arg_going;
7017 : 2080941 : int save_delete_this_arg;
7018 : 2080941 : int save_this_is_output_file;
7019 : 2080941 : int save_this_is_library_file;
7020 : 2080941 : int save_input_from_pipe;
7021 : 2080941 : int save_this_is_linker_script;
7022 : 2080941 : const char *save_suffix_subst;
7023 : :
7024 : 2080941 : int save_growing_size;
7025 : 2080941 : void *save_growing_value = NULL;
7026 : :
7027 : 2080941 : sf = lookup_spec_function (func);
7028 : 2080941 : if (sf == NULL)
7029 : 0 : fatal_error (input_location, "unknown spec function %qs", func);
7030 : :
7031 : : /* Push the spec processing context. */
7032 : 2080941 : save_argbuf = argbuf;
7033 : :
7034 : 2080941 : save_arg_going = arg_going;
7035 : 2080941 : save_delete_this_arg = delete_this_arg;
7036 : 2080941 : save_this_is_output_file = this_is_output_file;
7037 : 2080941 : save_this_is_library_file = this_is_library_file;
7038 : 2080941 : save_this_is_linker_script = this_is_linker_script;
7039 : 2080941 : save_input_from_pipe = input_from_pipe;
7040 : 2080941 : save_suffix_subst = suffix_subst;
7041 : :
7042 : : /* If we have some object growing now, finalize it so the args and function
7043 : : eval proceed from a cleared context. This is needed to prevent the first
7044 : : constructed arg from mistakenly including the growing value. We'll push
7045 : : this value back on the obstack once the function evaluation is done, to
7046 : : restore a consistent processing context for our caller. This is fine as
7047 : : the address of growing objects isn't guaranteed to remain stable until
7048 : : they are finalized, and we expect this situation to be rare enough for
7049 : : the extra copy not to be an issue. */
7050 : 2080941 : save_growing_size = obstack_object_size (&obstack);
7051 : 2080941 : if (save_growing_size > 0)
7052 : 42707 : save_growing_value = obstack_finish (&obstack);
7053 : :
7054 : : /* Create a new spec processing context, and build the function
7055 : : arguments. */
7056 : :
7057 : 2080941 : alloc_args ();
7058 : 2080941 : if (do_spec_2 (args, soft_matched_part) < 0)
7059 : 0 : fatal_error (input_location, "error in arguments to spec function %qs",
7060 : : func);
7061 : :
7062 : : /* argbuf_index is an index for the next argument to be inserted, and
7063 : : so contains the count of the args already inserted. */
7064 : :
7065 : 6242823 : funcval = (*sf->func) (argbuf.length (),
7066 : : argbuf.address ());
7067 : :
7068 : : /* Pop the spec processing context. */
7069 : 2080941 : argbuf.release ();
7070 : 2080941 : argbuf = save_argbuf;
7071 : :
7072 : 2080941 : arg_going = save_arg_going;
7073 : 2080941 : delete_this_arg = save_delete_this_arg;
7074 : 2080941 : this_is_output_file = save_this_is_output_file;
7075 : 2080941 : this_is_library_file = save_this_is_library_file;
7076 : 2080941 : this_is_linker_script = save_this_is_linker_script;
7077 : 2080941 : input_from_pipe = save_input_from_pipe;
7078 : 2080941 : suffix_subst = save_suffix_subst;
7079 : :
7080 : 2080941 : if (save_growing_size > 0)
7081 : 42707 : obstack_grow (&obstack, save_growing_value, save_growing_size);
7082 : :
7083 : 2080941 : return funcval;
7084 : : }
7085 : :
7086 : : /* Handle a spec function call of the form:
7087 : :
7088 : : %:function(args)
7089 : :
7090 : : ARGS is processed as a spec in a separate context and split into an
7091 : : argument vector in the normal fashion. The function returns a string
7092 : : containing a spec which we then process in the caller's context, or
7093 : : NULL if no processing is required.
7094 : :
7095 : : If RETVAL_NONNULL is not NULL, then store a bool whether function
7096 : : returned non-NULL.
7097 : :
7098 : : SOFT_MATCHED_PART holds the current value of a matched * pattern, which
7099 : : may be re-expanded with a %* as part of the function arguments. */
7100 : :
7101 : : static const char *
7102 : 2080941 : handle_spec_function (const char *p, bool *retval_nonnull,
7103 : : const char *soft_matched_part)
7104 : : {
7105 : 2080941 : char *func, *args;
7106 : 2080941 : const char *endp, *funcval;
7107 : 2080941 : int count;
7108 : :
7109 : 2080941 : processing_spec_function++;
7110 : :
7111 : : /* Get the function name. */
7112 : 19339864 : for (endp = p; *endp != '\0'; endp++)
7113 : : {
7114 : 19339864 : if (*endp == '(') /* ) */
7115 : : break;
7116 : : /* Only allow [A-Za-z0-9], -, and _ in function names. */
7117 : 17258923 : if (!ISALNUM (*endp) && !(*endp == '-' || *endp == '_'))
7118 : 0 : fatal_error (input_location, "malformed spec function name");
7119 : : }
7120 : 2080941 : if (*endp != '(') /* ) */
7121 : 0 : fatal_error (input_location, "no arguments for spec function");
7122 : 2080941 : func = save_string (p, endp - p);
7123 : 2080941 : p = ++endp;
7124 : :
7125 : : /* Get the arguments. */
7126 : 25302891 : for (count = 0; *endp != '\0'; endp++)
7127 : : {
7128 : : /* ( */
7129 : 25302891 : if (*endp == ')')
7130 : : {
7131 : 2171356 : if (count == 0)
7132 : : break;
7133 : 90415 : count--;
7134 : : }
7135 : 23131535 : else if (*endp == '(') /* ) */
7136 : 90415 : count++;
7137 : : }
7138 : : /* ( */
7139 : 2080941 : if (*endp != ')')
7140 : 0 : fatal_error (input_location, "malformed spec function arguments");
7141 : 2080941 : args = save_string (p, endp - p);
7142 : 2080941 : p = ++endp;
7143 : :
7144 : : /* p now points to just past the end of the spec function expression. */
7145 : :
7146 : 2080941 : funcval = eval_spec_function (func, args, soft_matched_part);
7147 : 2080941 : if (funcval != NULL && do_spec_1 (funcval, 0, NULL) < 0)
7148 : : p = NULL;
7149 : 2080941 : if (retval_nonnull)
7150 : 1640980 : *retval_nonnull = funcval != NULL;
7151 : :
7152 : 2080941 : free (func);
7153 : 2080941 : free (args);
7154 : :
7155 : 2080941 : processing_spec_function--;
7156 : :
7157 : 2080941 : return p;
7158 : : }
7159 : :
7160 : : /* Inline subroutine of handle_braces. Returns true if the current
7161 : : input suffix matches the atom bracketed by ATOM and END_ATOM. */
7162 : : static inline bool
7163 : 0 : input_suffix_matches (const char *atom, const char *end_atom)
7164 : : {
7165 : 0 : return (input_suffix
7166 : 0 : && !strncmp (input_suffix, atom, end_atom - atom)
7167 : 0 : && input_suffix[end_atom - atom] == '\0');
7168 : : }
7169 : :
7170 : : /* Subroutine of handle_braces. Returns true if the current
7171 : : input file's spec name matches the atom bracketed by ATOM and END_ATOM. */
7172 : : static bool
7173 : 0 : input_spec_matches (const char *atom, const char *end_atom)
7174 : : {
7175 : 0 : return (input_file_compiler
7176 : 0 : && input_file_compiler->suffix
7177 : 0 : && input_file_compiler->suffix[0] != '\0'
7178 : 0 : && !strncmp (input_file_compiler->suffix + 1, atom,
7179 : 0 : end_atom - atom)
7180 : 0 : && input_file_compiler->suffix[end_atom - atom + 1] == '\0');
7181 : : }
7182 : :
7183 : : /* Subroutine of handle_braces. Returns true if a switch
7184 : : matching the atom bracketed by ATOM and END_ATOM appeared on the
7185 : : command line. */
7186 : : static bool
7187 : 38740949 : switch_matches (const char *atom, const char *end_atom, int starred)
7188 : : {
7189 : 38740949 : int i;
7190 : 38740949 : int len = end_atom - atom;
7191 : 38740949 : int plen = starred ? len : -1;
7192 : :
7193 : 910119569 : for (i = 0; i < n_switches; i++)
7194 : 872754595 : if (!strncmp (switches[i].part1, atom, len)
7195 : 2321956 : && (starred || switches[i].part1[len] == '\0')
7196 : 874131187 : && check_live_switch (i, plen))
7197 : : return true;
7198 : :
7199 : : /* Check if a switch with separated form matching the atom.
7200 : : We check -D and -U switches. */
7201 : 871378621 : else if (switches[i].args != 0)
7202 : : {
7203 : 201192947 : if ((*switches[i].part1 == 'D' || *switches[i].part1 == 'U')
7204 : 8573331 : && *switches[i].part1 == atom[0])
7205 : : {
7206 : 1 : if (!strncmp (switches[i].args[0], &atom[1], len - 1)
7207 : 1 : && (starred || (switches[i].part1[1] == '\0'
7208 : 1 : && switches[i].args[0][len - 1] == '\0'))
7209 : 2 : && check_live_switch (i, (starred ? 1 : -1)))
7210 : : return true;
7211 : : }
7212 : : }
7213 : :
7214 : : return false;
7215 : : }
7216 : :
7217 : : /* Inline subroutine of handle_braces. Mark all of the switches which
7218 : : match ATOM (extends to END_ATOM; STARRED indicates whether there
7219 : : was a star after the atom) for later processing. */
7220 : : static inline void
7221 : 11251086 : mark_matching_switches (const char *atom, const char *end_atom, int starred)
7222 : : {
7223 : 11251086 : int i;
7224 : 11251086 : int len = end_atom - atom;
7225 : 11251086 : int plen = starred ? len : -1;
7226 : :
7227 : 268081891 : for (i = 0; i < n_switches; i++)
7228 : 256830805 : if (!strncmp (switches[i].part1, atom, len)
7229 : 6381304 : && (starred || switches[i].part1[len] == '\0')
7230 : 262993880 : && check_live_switch (i, plen))
7231 : 6114057 : switches[i].ordering = 1;
7232 : 11251086 : }
7233 : :
7234 : : /* Inline subroutine of handle_braces. Process all the currently
7235 : : marked switches through give_switch, and clear the marks. */
7236 : : static inline void
7237 : 9765201 : process_marked_switches (void)
7238 : : {
7239 : 9765201 : int i;
7240 : :
7241 : 232621669 : for (i = 0; i < n_switches; i++)
7242 : 222856468 : if (switches[i].ordering == 1)
7243 : : {
7244 : 6114057 : switches[i].ordering = 0;
7245 : 6114057 : give_switch (i, 0);
7246 : : }
7247 : 9765201 : }
7248 : :
7249 : : /* Handle a %{ ... } construct. P points just inside the leading {.
7250 : : Returns a pointer one past the end of the brace block, or 0
7251 : : if we call do_spec_1 and that returns -1. */
7252 : :
7253 : : static const char *
7254 : 40790248 : handle_braces (const char *p)
7255 : : {
7256 : 40790248 : const char *atom, *end_atom;
7257 : 40790248 : const char *d_atom = NULL, *d_end_atom = NULL;
7258 : 40790248 : char *esc_buf = NULL, *d_esc_buf = NULL;
7259 : 40790248 : int esc;
7260 : 40790248 : const char *orig = p;
7261 : :
7262 : 40790248 : bool a_is_suffix;
7263 : 40790248 : bool a_is_spectype;
7264 : 40790248 : bool a_is_starred;
7265 : 40790248 : bool a_is_negated;
7266 : 40790248 : bool a_matched;
7267 : :
7268 : 40790248 : bool a_must_be_last = false;
7269 : 40790248 : bool ordered_set = false;
7270 : 40790248 : bool disjunct_set = false;
7271 : 40790248 : bool disj_matched = false;
7272 : 40790248 : bool disj_starred = true;
7273 : 40790248 : bool n_way_choice = false;
7274 : 40790248 : bool n_way_matched = false;
7275 : :
7276 : : #define SKIP_WHITE() do { while (*p == ' ' || *p == '\t') p++; } while (0)
7277 : :
7278 : 54232902 : do
7279 : : {
7280 : 54232902 : if (a_must_be_last)
7281 : 0 : goto invalid;
7282 : :
7283 : : /* Scan one "atom" (S in the description above of %{}, possibly
7284 : : with '!', '.', '@', ',', or '*' modifiers). */
7285 : 54232902 : a_matched = false;
7286 : 54232902 : a_is_suffix = false;
7287 : 54232902 : a_is_starred = false;
7288 : 54232902 : a_is_negated = false;
7289 : 54232902 : a_is_spectype = false;
7290 : :
7291 : 61804206 : SKIP_WHITE ();
7292 : 54232902 : if (*p == '!')
7293 : 13101138 : p++, a_is_negated = true;
7294 : :
7295 : 54232902 : SKIP_WHITE ();
7296 : 54232902 : if (*p == '%' && p[1] == ':')
7297 : : {
7298 : 1640980 : atom = NULL;
7299 : 1640980 : end_atom = NULL;
7300 : 1640980 : p = handle_spec_function (p + 2, &a_matched, NULL);
7301 : : }
7302 : : else
7303 : : {
7304 : 52591922 : if (*p == '.')
7305 : 0 : p++, a_is_suffix = true;
7306 : 52591922 : else if (*p == ',')
7307 : 0 : p++, a_is_spectype = true;
7308 : :
7309 : 52591922 : atom = p;
7310 : 52591922 : esc = 0;
7311 : 52591922 : while (ISIDNUM (*p) || *p == '-' || *p == '+' || *p == '='
7312 : 396462825 : || *p == ',' || *p == '.' || *p == '@' || *p == '\\')
7313 : : {
7314 : 343870903 : if (*p == '\\')
7315 : : {
7316 : 0 : p++;
7317 : 0 : if (!*p)
7318 : 0 : fatal_error (input_location,
7319 : : "braced spec %qs ends in escape", orig);
7320 : 0 : esc++;
7321 : : }
7322 : 343870903 : p++;
7323 : : }
7324 : 52591922 : end_atom = p;
7325 : :
7326 : 52591922 : if (esc)
7327 : : {
7328 : 0 : const char *ap;
7329 : 0 : char *ep;
7330 : :
7331 : 0 : if (esc_buf && esc_buf != d_esc_buf)
7332 : 0 : free (esc_buf);
7333 : 0 : esc_buf = NULL;
7334 : 0 : ep = esc_buf = (char *) xmalloc (end_atom - atom - esc + 1);
7335 : 0 : for (ap = atom; ap != end_atom; ap++, ep++)
7336 : : {
7337 : 0 : if (*ap == '\\')
7338 : 0 : ap++;
7339 : 0 : *ep = *ap;
7340 : : }
7341 : 0 : *ep = '\0';
7342 : 0 : atom = esc_buf;
7343 : 0 : end_atom = ep;
7344 : : }
7345 : :
7346 : 52591922 : if (*p == '*')
7347 : 11843775 : p++, a_is_starred = 1;
7348 : : }
7349 : :
7350 : 54232902 : SKIP_WHITE ();
7351 : 54232902 : switch (*p)
7352 : : {
7353 : 11251086 : case '&': case '}':
7354 : : /* Substitute the switch(es) indicated by the current atom. */
7355 : 11251086 : ordered_set = true;
7356 : 11251086 : if (disjunct_set || n_way_choice || a_is_negated || a_is_suffix
7357 : 11251086 : || a_is_spectype || atom == end_atom)
7358 : 0 : goto invalid;
7359 : :
7360 : 11251086 : mark_matching_switches (atom, end_atom, a_is_starred);
7361 : :
7362 : 11251086 : if (*p == '}')
7363 : 9765201 : process_marked_switches ();
7364 : : break;
7365 : :
7366 : 42981816 : case '|': case ':':
7367 : : /* Substitute some text if the current atom appears as a switch
7368 : : or suffix. */
7369 : 42981816 : disjunct_set = true;
7370 : 42981816 : if (ordered_set)
7371 : 0 : goto invalid;
7372 : :
7373 : 42981816 : if (atom && atom == end_atom)
7374 : : {
7375 : 1778199 : if (!n_way_choice || disj_matched || *p == '|'
7376 : 1778199 : || a_is_negated || a_is_suffix || a_is_spectype
7377 : 1778199 : || a_is_starred)
7378 : 0 : goto invalid;
7379 : :
7380 : : /* An empty term may appear as the last choice of an
7381 : : N-way choice set; it means "otherwise". */
7382 : 1778199 : a_must_be_last = true;
7383 : 1778199 : disj_matched = !n_way_matched;
7384 : 1778199 : disj_starred = false;
7385 : : }
7386 : : else
7387 : : {
7388 : 41203617 : if ((a_is_suffix || a_is_spectype) && a_is_starred)
7389 : 0 : goto invalid;
7390 : :
7391 : 41203617 : if (!a_is_starred)
7392 : 35613561 : disj_starred = false;
7393 : :
7394 : : /* Don't bother testing this atom if we already have a
7395 : : match. */
7396 : 41203617 : if (!disj_matched && !n_way_matched)
7397 : : {
7398 : 40181969 : if (atom == NULL)
7399 : : /* a_matched is already set by handle_spec_function. */;
7400 : 38644874 : else if (a_is_suffix)
7401 : 0 : a_matched = input_suffix_matches (atom, end_atom);
7402 : 38644874 : else if (a_is_spectype)
7403 : 0 : a_matched = input_spec_matches (atom, end_atom);
7404 : : else
7405 : 38644874 : a_matched = switch_matches (atom, end_atom, a_is_starred);
7406 : :
7407 : 40181969 : if (a_matched != a_is_negated)
7408 : : {
7409 : 12972017 : disj_matched = true;
7410 : 12972017 : d_atom = atom;
7411 : 12972017 : d_end_atom = end_atom;
7412 : 12972017 : d_esc_buf = esc_buf;
7413 : : }
7414 : : }
7415 : : }
7416 : :
7417 : 42981816 : if (*p == ':')
7418 : : {
7419 : : /* Found the body, that is, the text to substitute if the
7420 : : current disjunction matches. */
7421 : 68079142 : p = process_brace_body (p + 1, d_atom, d_end_atom, disj_starred,
7422 : 34039571 : disj_matched && !n_way_matched);
7423 : 34039571 : if (p == 0)
7424 : 36994 : goto done;
7425 : :
7426 : : /* If we have an N-way choice, reset state for the next
7427 : : disjunction. */
7428 : 34002577 : if (*p == ';')
7429 : : {
7430 : 3014524 : n_way_choice = true;
7431 : 3014524 : n_way_matched |= disj_matched;
7432 : 3014524 : disj_matched = false;
7433 : 3014524 : disj_starred = true;
7434 : 3014524 : d_atom = d_end_atom = NULL;
7435 : : }
7436 : : }
7437 : : break;
7438 : :
7439 : 0 : default:
7440 : 0 : goto invalid;
7441 : : }
7442 : : }
7443 : 54195908 : while (*p++ != '}');
7444 : :
7445 : 40753254 : done:
7446 : 40790248 : if (d_esc_buf && d_esc_buf != esc_buf)
7447 : 0 : free (d_esc_buf);
7448 : 40790248 : if (esc_buf)
7449 : 0 : free (esc_buf);
7450 : :
7451 : 40790248 : return p;
7452 : :
7453 : 0 : invalid:
7454 : 0 : fatal_error (input_location, "braced spec %qs is invalid at %qc", orig, *p);
7455 : :
7456 : : #undef SKIP_WHITE
7457 : : }
7458 : :
7459 : : /* Subroutine of handle_braces. Scan and process a brace substitution body
7460 : : (X in the description of %{} syntax). P points one past the colon;
7461 : : ATOM and END_ATOM bracket the first atom which was found to be true
7462 : : (present) in the current disjunction; STARRED indicates whether all
7463 : : the atoms in the current disjunction were starred (for syntax validation);
7464 : : MATCHED indicates whether the disjunction matched or not, and therefore
7465 : : whether or not the body is to be processed through do_spec_1 or just
7466 : : skipped. Returns a pointer to the closing } or ;, or 0 if do_spec_1
7467 : : returns -1. */
7468 : :
7469 : : static const char *
7470 : 34039571 : process_brace_body (const char *p, const char *atom, const char *end_atom,
7471 : : int starred, int matched)
7472 : : {
7473 : 34039571 : const char *body, *end_body;
7474 : 34039571 : unsigned int nesting_level;
7475 : 34039571 : bool have_subst = false;
7476 : :
7477 : : /* Locate the closing } or ;, honoring nested braces.
7478 : : Trim trailing whitespace. */
7479 : 34039571 : body = p;
7480 : 34039571 : nesting_level = 1;
7481 : 11589175233 : for (;;)
7482 : : {
7483 : 5811607402 : if (*p == '{')
7484 : 171603750 : nesting_level++;
7485 : 5640003652 : else if (*p == '}')
7486 : : {
7487 : 202628797 : if (!--nesting_level)
7488 : : break;
7489 : : }
7490 : 5437374855 : else if (*p == ';' && nesting_level == 1)
7491 : : break;
7492 : 5434360331 : else if (*p == '%' && p[1] == '*' && nesting_level == 1)
7493 : : have_subst = true;
7494 : 5433572894 : else if (*p == '\0')
7495 : 0 : goto invalid;
7496 : 5777567831 : p++;
7497 : : }
7498 : :
7499 : : end_body = p;
7500 : 36823010 : while (end_body[-1] == ' ' || end_body[-1] == '\t')
7501 : 2783439 : end_body--;
7502 : :
7503 : 34039571 : if (have_subst && !starred)
7504 : 0 : goto invalid;
7505 : :
7506 : 34039571 : if (matched)
7507 : : {
7508 : : /* Copy the substitution body to permanent storage and execute it.
7509 : : If have_subst is false, this is a simple matter of running the
7510 : : body through do_spec_1... */
7511 : 13931444 : char *string = save_string (body, end_body - body);
7512 : 13931444 : if (!have_subst)
7513 : : {
7514 : 13924646 : if (do_spec_1 (string, 0, NULL) < 0)
7515 : : {
7516 : 36994 : free (string);
7517 : 36994 : return 0;
7518 : : }
7519 : : }
7520 : : else
7521 : : {
7522 : : /* ... but if have_subst is true, we have to process the
7523 : : body once for each matching switch, with %* set to the
7524 : : variant part of the switch. */
7525 : 6798 : unsigned int hard_match_len = end_atom - atom;
7526 : 6798 : int i;
7527 : :
7528 : 273134 : for (i = 0; i < n_switches; i++)
7529 : 266336 : if (!strncmp (switches[i].part1, atom, hard_match_len)
7530 : 266336 : && check_live_switch (i, hard_match_len))
7531 : : {
7532 : 6802 : if (do_spec_1 (string, 0,
7533 : : &switches[i].part1[hard_match_len]) < 0)
7534 : : {
7535 : 0 : free (string);
7536 : 0 : return 0;
7537 : : }
7538 : : /* Pass any arguments this switch has. */
7539 : 6802 : give_switch (i, 1);
7540 : 6802 : suffix_subst = NULL;
7541 : : }
7542 : : }
7543 : 13894450 : free (string);
7544 : : }
7545 : :
7546 : : return p;
7547 : :
7548 : 0 : invalid:
7549 : 0 : fatal_error (input_location, "braced spec body %qs is invalid", body);
7550 : : }
7551 : :
7552 : : /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
7553 : : on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
7554 : : spec, or -1 if either exact match or %* is used.
7555 : :
7556 : : A -O switch is obsoleted by a later -O switch. A -f, -g, -m, or -W switch
7557 : : whose value does not begin with "no-" is obsoleted by the same value
7558 : : with the "no-", similarly for a switch with the "no-" prefix. */
7559 : :
7560 : : static int
7561 : 7546470 : check_live_switch (int switchnum, int prefix_length)
7562 : : {
7563 : 7546470 : const char *name = switches[switchnum].part1;
7564 : 7546470 : int i;
7565 : :
7566 : : /* If we already processed this switch and determined if it was
7567 : : live or not, return our past determination. */
7568 : 7546470 : if (switches[switchnum].live_cond != 0)
7569 : 951164 : return ((switches[switchnum].live_cond & SWITCH_LIVE) != 0
7570 : 901546 : && (switches[switchnum].live_cond & SWITCH_FALSE) == 0
7571 : 1852710 : && (switches[switchnum].live_cond & SWITCH_IGNORE_PERMANENTLY)
7572 : 951164 : == 0);
7573 : :
7574 : : /* In the common case of {<at-most-one-letter>*}, a negating
7575 : : switch would always match, so ignore that case. We will just
7576 : : send the conflicting switches to the compiler phase. */
7577 : 6595306 : if (prefix_length >= 0 && prefix_length <= 1)
7578 : : return 1;
7579 : :
7580 : : /* Now search for duplicate in a manner that depends on the name. */
7581 : 888813 : switch (*name)
7582 : : {
7583 : 62 : case 'O':
7584 : 344 : for (i = switchnum + 1; i < n_switches; i++)
7585 : 287 : if (switches[i].part1[0] == 'O')
7586 : : {
7587 : 5 : switches[switchnum].validated = true;
7588 : 5 : switches[switchnum].live_cond = SWITCH_FALSE;
7589 : 5 : return 0;
7590 : : }
7591 : : break;
7592 : :
7593 : 289352 : case 'W': case 'f': case 'm': case 'g':
7594 : 289352 : if (startswith (name + 1, "no-"))
7595 : : {
7596 : : /* We have Xno-YYY, search for XYYY. */
7597 : 34958 : for (i = switchnum + 1; i < n_switches; i++)
7598 : 29384 : if (switches[i].part1[0] == name[0]
7599 : 5600 : && ! strcmp (&switches[i].part1[1], &name[4]))
7600 : : {
7601 : : /* --specs are validated with the validate_switches mechanism. */
7602 : 0 : if (switches[switchnum].known)
7603 : 0 : switches[switchnum].validated = true;
7604 : 0 : switches[switchnum].live_cond = SWITCH_FALSE;
7605 : 0 : return 0;
7606 : : }
7607 : : }
7608 : : else
7609 : : {
7610 : : /* We have XYYY, search for Xno-YYY. */
7611 : 2975318 : for (i = switchnum + 1; i < n_switches; i++)
7612 : 2691540 : if (switches[i].part1[0] == name[0]
7613 : 1633873 : && switches[i].part1[1] == 'n'
7614 : 205834 : && switches[i].part1[2] == 'o'
7615 : 205833 : && switches[i].part1[3] == '-'
7616 : 205803 : && !strcmp (&switches[i].part1[4], &name[1]))
7617 : : {
7618 : : /* --specs are validated with the validate_switches mechanism. */
7619 : 0 : if (switches[switchnum].known)
7620 : 0 : switches[switchnum].validated = true;
7621 : 0 : switches[switchnum].live_cond = SWITCH_FALSE;
7622 : 0 : return 0;
7623 : : }
7624 : : }
7625 : : break;
7626 : : }
7627 : :
7628 : : /* Otherwise the switch is live. */
7629 : 888808 : switches[switchnum].live_cond |= SWITCH_LIVE;
7630 : 888808 : return 1;
7631 : : }
7632 : :
7633 : : /* Pass a switch to the current accumulating command
7634 : : in the same form that we received it.
7635 : : SWITCHNUM identifies the switch; it is an index into
7636 : : the vector of switches gcc received, which is `switches'.
7637 : : This cannot fail since it never finishes a command line.
7638 : :
7639 : : If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */
7640 : :
7641 : : static void
7642 : 6120859 : give_switch (int switchnum, int omit_first_word)
7643 : : {
7644 : 6120859 : if ((switches[switchnum].live_cond & SWITCH_IGNORE) != 0)
7645 : : return;
7646 : :
7647 : 6120848 : if (!omit_first_word)
7648 : : {
7649 : 6114046 : do_spec_1 ("-", 0, NULL);
7650 : 6114046 : do_spec_1 (switches[switchnum].part1, 1, NULL);
7651 : : }
7652 : :
7653 : 6120848 : if (switches[switchnum].args != 0)
7654 : : {
7655 : : const char **p;
7656 : 2466914 : for (p = switches[switchnum].args; *p; p++)
7657 : : {
7658 : 1233457 : const char *arg = *p;
7659 : :
7660 : 1233457 : do_spec_1 (" ", 0, NULL);
7661 : 1233457 : if (suffix_subst)
7662 : : {
7663 : 5879 : unsigned length = strlen (arg);
7664 : 5879 : int dot = 0;
7665 : :
7666 : 11758 : while (length-- && !IS_DIR_SEPARATOR (arg[length]))
7667 : 11758 : if (arg[length] == '.')
7668 : : {
7669 : 5879 : (CONST_CAST (char *, arg))[length] = 0;
7670 : 5879 : dot = 1;
7671 : 5879 : break;
7672 : : }
7673 : 5879 : do_spec_1 (arg, 1, NULL);
7674 : 5879 : if (dot)
7675 : 5879 : (CONST_CAST (char *, arg))[length] = '.';
7676 : 5879 : do_spec_1 (suffix_subst, 1, NULL);
7677 : : }
7678 : : else
7679 : 1227578 : do_spec_1 (arg, 1, NULL);
7680 : : }
7681 : : }
7682 : :
7683 : 6120848 : do_spec_1 (" ", 0, NULL);
7684 : 6120848 : switches[switchnum].validated = true;
7685 : : }
7686 : :
7687 : : /* Print GCC configuration (e.g. version, thread model, target,
7688 : : configuration_arguments) to a given FILE. */
7689 : :
7690 : : static void
7691 : 1493 : print_configuration (FILE *file)
7692 : : {
7693 : 1493 : int n;
7694 : 1493 : const char *thrmod;
7695 : :
7696 : 1493 : fnotice (file, "Target: %s\n", spec_machine);
7697 : 1493 : fnotice (file, "Configured with: %s\n", configuration_arguments);
7698 : :
7699 : : #ifdef THREAD_MODEL_SPEC
7700 : : /* We could have defined THREAD_MODEL_SPEC to "%*" by default,
7701 : : but there's no point in doing all this processing just to get
7702 : : thread_model back. */
7703 : : obstack_init (&obstack);
7704 : : do_spec_1 (THREAD_MODEL_SPEC, 0, thread_model);
7705 : : obstack_1grow (&obstack, '\0');
7706 : : thrmod = XOBFINISH (&obstack, const char *);
7707 : : #else
7708 : 1493 : thrmod = thread_model;
7709 : : #endif
7710 : :
7711 : 1493 : fnotice (file, "Thread model: %s\n", thrmod);
7712 : 1493 : fnotice (file, "Supported LTO compression algorithms: zlib");
7713 : : #ifdef HAVE_ZSTD_H
7714 : 1493 : fnotice (file, " zstd");
7715 : : #endif
7716 : 1493 : fnotice (file, "\n");
7717 : :
7718 : : /* compiler_version is truncated at the first space when initialized
7719 : : from version string, so truncate version_string at the first space
7720 : : before comparing. */
7721 : 11944 : for (n = 0; version_string[n]; n++)
7722 : 10451 : if (version_string[n] == ' ')
7723 : : break;
7724 : :
7725 : 1493 : if (! strncmp (version_string, compiler_version, n)
7726 : 1493 : && compiler_version[n] == 0)
7727 : 1493 : fnotice (file, "gcc version %s %s\n", version_string,
7728 : : pkgversion_string);
7729 : : else
7730 : 0 : fnotice (file, "gcc driver version %s %sexecuting gcc version %s\n",
7731 : : version_string, pkgversion_string, compiler_version);
7732 : :
7733 : 1493 : }
7734 : :
7735 : : #define RETRY_ICE_ATTEMPTS 3
7736 : :
7737 : : /* Returns true if FILE1 and FILE2 contain equivalent data, 0 otherwise.
7738 : : If lines start with 0x followed by 1-16 lowercase hexadecimal digits
7739 : : followed by a space, ignore anything before that space. These are
7740 : : typically function addresses from libbacktrace and those can differ
7741 : : due to ASLR. */
7742 : :
7743 : : static bool
7744 : 0 : files_equal_p (char *file1, char *file2)
7745 : : {
7746 : 0 : FILE *f1 = fopen (file1, "rb");
7747 : 0 : FILE *f2 = fopen (file2, "rb");
7748 : 0 : char line1[256], line2[256];
7749 : :
7750 : 0 : bool line_start = true;
7751 : 0 : while (fgets (line1, sizeof (line1), f1))
7752 : : {
7753 : 0 : if (!fgets (line2, sizeof (line2), f2))
7754 : 0 : goto error;
7755 : 0 : char *p1 = line1, *p2 = line2;
7756 : 0 : if (line_start
7757 : 0 : && line1[0] == '0'
7758 : 0 : && line1[1] == 'x'
7759 : 0 : && line2[0] == '0'
7760 : 0 : && line2[1] == 'x')
7761 : : {
7762 : : int i, j;
7763 : 0 : for (i = 0; i < 16; ++i)
7764 : 0 : if (!ISXDIGIT (line1[2 + i]) || ISUPPER (line1[2 + i]))
7765 : : break;
7766 : 0 : for (j = 0; j < 16; ++j)
7767 : 0 : if (!ISXDIGIT (line2[2 + j]) || ISUPPER (line2[2 + j]))
7768 : : break;
7769 : 0 : if (i && line1[2 + i] == ' ' && j && line2[2 + j] == ' ')
7770 : : {
7771 : 0 : p1 = line1 + i + 3;
7772 : 0 : p2 = line2 + j + 3;
7773 : : }
7774 : : }
7775 : 0 : if (strcmp (p1, p2) != 0)
7776 : 0 : goto error;
7777 : 0 : line_start = strchr (line1, '\n') != NULL;
7778 : : }
7779 : 0 : if (fgets (line2, sizeof (line2), f2))
7780 : 0 : goto error;
7781 : :
7782 : 0 : fclose (f1);
7783 : 0 : fclose (f2);
7784 : 0 : return 1;
7785 : :
7786 : 0 : error:
7787 : 0 : fclose (f1);
7788 : 0 : fclose (f2);
7789 : 0 : return 0;
7790 : : }
7791 : :
7792 : : /* Check that compiler's output doesn't differ across runs.
7793 : : TEMP_STDOUT_FILES and TEMP_STDERR_FILES are arrays of files, containing
7794 : : stdout and stderr for each compiler run. Return true if all of
7795 : : TEMP_STDOUT_FILES and TEMP_STDERR_FILES are equivalent. */
7796 : :
7797 : : static bool
7798 : 0 : check_repro (char **temp_stdout_files, char **temp_stderr_files)
7799 : : {
7800 : 0 : int i;
7801 : 0 : for (i = 0; i < RETRY_ICE_ATTEMPTS - 2; ++i)
7802 : : {
7803 : 0 : if (!files_equal_p (temp_stdout_files[i], temp_stdout_files[i + 1])
7804 : 0 : || !files_equal_p (temp_stderr_files[i], temp_stderr_files[i + 1]))
7805 : : {
7806 : 0 : fnotice (stderr, "The bug is not reproducible, so it is"
7807 : : " likely a hardware or OS problem.\n");
7808 : 0 : break;
7809 : : }
7810 : : }
7811 : 0 : return i == RETRY_ICE_ATTEMPTS - 2;
7812 : : }
7813 : :
7814 : : enum attempt_status {
7815 : : ATTEMPT_STATUS_FAIL_TO_RUN,
7816 : : ATTEMPT_STATUS_SUCCESS,
7817 : : ATTEMPT_STATUS_ICE
7818 : : };
7819 : :
7820 : :
7821 : : /* Run compiler with arguments NEW_ARGV to reproduce the ICE, storing stdout
7822 : : to OUT_TEMP and stderr to ERR_TEMP. If APPEND is TRUE, append to OUT_TEMP
7823 : : and ERR_TEMP instead of truncating. If EMIT_SYSTEM_INFO is TRUE, also write
7824 : : GCC configuration into to ERR_TEMP. Return ATTEMPT_STATUS_FAIL_TO_RUN if
7825 : : compiler failed to run, ATTEMPT_STATUS_ICE if compiled ICE-ed and
7826 : : ATTEMPT_STATUS_SUCCESS otherwise. */
7827 : :
7828 : : static enum attempt_status
7829 : 0 : run_attempt (const char **new_argv, const char *out_temp,
7830 : : const char *err_temp, int emit_system_info, int append)
7831 : : {
7832 : :
7833 : 0 : if (emit_system_info)
7834 : : {
7835 : 0 : FILE *file_out = fopen (err_temp, "a");
7836 : 0 : print_configuration (file_out);
7837 : 0 : fputs ("\n", file_out);
7838 : 0 : fclose (file_out);
7839 : : }
7840 : :
7841 : 0 : int exit_status;
7842 : 0 : const char *errmsg;
7843 : 0 : struct pex_obj *pex;
7844 : 0 : int err;
7845 : 0 : int pex_flags = PEX_USE_PIPES | PEX_LAST;
7846 : 0 : enum attempt_status status = ATTEMPT_STATUS_FAIL_TO_RUN;
7847 : :
7848 : 0 : if (append)
7849 : 0 : pex_flags |= PEX_STDOUT_APPEND | PEX_STDERR_APPEND;
7850 : :
7851 : 0 : pex = pex_init (PEX_USE_PIPES, new_argv[0], NULL);
7852 : 0 : if (!pex)
7853 : : fatal_error (input_location, "%<pex_init%> failed: %m");
7854 : :
7855 : 0 : errmsg = pex_run (pex, pex_flags, new_argv[0],
7856 : 0 : CONST_CAST2 (char *const *, const char **, &new_argv[1]),
7857 : : out_temp, err_temp, &err);
7858 : 0 : if (errmsg != NULL)
7859 : : {
7860 : 0 : errno = err;
7861 : 0 : fatal_error (input_location,
7862 : : err ? G_ ("cannot execute %qs: %s: %m")
7863 : : : G_ ("cannot execute %qs: %s"),
7864 : : new_argv[0], errmsg);
7865 : : }
7866 : :
7867 : 0 : if (!pex_get_status (pex, 1, &exit_status))
7868 : 0 : goto out;
7869 : :
7870 : 0 : switch (WEXITSTATUS (exit_status))
7871 : : {
7872 : : case ICE_EXIT_CODE:
7873 : 0 : status = ATTEMPT_STATUS_ICE;
7874 : : break;
7875 : :
7876 : 0 : case SUCCESS_EXIT_CODE:
7877 : 0 : status = ATTEMPT_STATUS_SUCCESS;
7878 : 0 : break;
7879 : :
7880 : 0 : default:
7881 : 0 : ;
7882 : : }
7883 : :
7884 : 0 : out:
7885 : 0 : pex_free (pex);
7886 : 0 : return status;
7887 : : }
7888 : :
7889 : : /* This routine reads lines from IN file, adds C++ style comments
7890 : : at the begining of each line and writes result into OUT. */
7891 : :
7892 : : static void
7893 : 0 : insert_comments (const char *file_in, const char *file_out)
7894 : : {
7895 : 0 : FILE *in = fopen (file_in, "rb");
7896 : 0 : FILE *out = fopen (file_out, "wb");
7897 : 0 : char line[256];
7898 : :
7899 : 0 : bool add_comment = true;
7900 : 0 : while (fgets (line, sizeof (line), in))
7901 : : {
7902 : 0 : if (add_comment)
7903 : 0 : fputs ("// ", out);
7904 : 0 : fputs (line, out);
7905 : 0 : add_comment = strchr (line, '\n') != NULL;
7906 : : }
7907 : :
7908 : 0 : fclose (in);
7909 : 0 : fclose (out);
7910 : 0 : }
7911 : :
7912 : : /* This routine adds preprocessed source code into the given ERR_FILE.
7913 : : To do this, it adds "-E" to NEW_ARGV and execute RUN_ATTEMPT routine to
7914 : : add information in report file. RUN_ATTEMPT should return
7915 : : ATTEMPT_STATUS_SUCCESS, in other case we cannot generate the report. */
7916 : :
7917 : : static void
7918 : 0 : do_report_bug (const char **new_argv, const int nargs,
7919 : : char **out_file, char **err_file)
7920 : : {
7921 : 0 : int i, status;
7922 : 0 : int fd = open (*out_file, O_RDWR | O_APPEND);
7923 : 0 : if (fd < 0)
7924 : : return;
7925 : 0 : write (fd, "\n//", 3);
7926 : 0 : for (i = 0; i < nargs; i++)
7927 : : {
7928 : 0 : write (fd, " ", 1);
7929 : 0 : write (fd, new_argv[i], strlen (new_argv[i]));
7930 : : }
7931 : 0 : write (fd, "\n\n", 2);
7932 : 0 : close (fd);
7933 : 0 : new_argv[nargs] = "-E";
7934 : 0 : new_argv[nargs + 1] = NULL;
7935 : :
7936 : 0 : status = run_attempt (new_argv, *out_file, *err_file, 0, 1);
7937 : :
7938 : 0 : if (status == ATTEMPT_STATUS_SUCCESS)
7939 : : {
7940 : 0 : fnotice (stderr, "Preprocessed source stored into %s file,"
7941 : : " please attach this to your bugreport.\n", *out_file);
7942 : : /* Make sure it is not deleted. */
7943 : 0 : free (*out_file);
7944 : 0 : *out_file = NULL;
7945 : : }
7946 : : }
7947 : :
7948 : : /* Try to reproduce ICE. If bug is reproducible, generate report .err file
7949 : : containing GCC configuration, backtrace, compiler's command line options
7950 : : and preprocessed source code. */
7951 : :
7952 : : static void
7953 : 0 : try_generate_repro (const char **argv)
7954 : : {
7955 : 0 : int i, nargs, out_arg = -1, quiet = 0, attempt;
7956 : 0 : const char **new_argv;
7957 : 0 : char *temp_files[RETRY_ICE_ATTEMPTS * 2];
7958 : 0 : char **temp_stdout_files = &temp_files[0];
7959 : 0 : char **temp_stderr_files = &temp_files[RETRY_ICE_ATTEMPTS];
7960 : :
7961 : 0 : if (gcc_input_filename == NULL || ! strcmp (gcc_input_filename, "-"))
7962 : 0 : return;
7963 : :
7964 : 0 : for (nargs = 0; argv[nargs] != NULL; ++nargs)
7965 : : /* Only retry compiler ICEs, not preprocessor ones. */
7966 : 0 : if (! strcmp (argv[nargs], "-E"))
7967 : : return;
7968 : 0 : else if (argv[nargs][0] == '-' && argv[nargs][1] == 'o')
7969 : : {
7970 : 0 : if (out_arg == -1)
7971 : : out_arg = nargs;
7972 : : else
7973 : : return;
7974 : : }
7975 : : /* If the compiler is going to output any time information,
7976 : : it might varry between invocations. */
7977 : 0 : else if (! strcmp (argv[nargs], "-quiet"))
7978 : : quiet = 1;
7979 : 0 : else if (! strcmp (argv[nargs], "-ftime-report"))
7980 : : return;
7981 : :
7982 : 0 : if (out_arg == -1 || !quiet)
7983 : : return;
7984 : :
7985 : 0 : memset (temp_files, '\0', sizeof (temp_files));
7986 : 0 : new_argv = XALLOCAVEC (const char *, nargs + 4);
7987 : 0 : memcpy (new_argv, argv, (nargs + 1) * sizeof (const char *));
7988 : 0 : new_argv[nargs++] = "-frandom-seed=0";
7989 : 0 : new_argv[nargs++] = "-fdump-noaddr";
7990 : 0 : new_argv[nargs] = NULL;
7991 : 0 : if (new_argv[out_arg][2] == '\0')
7992 : 0 : new_argv[out_arg + 1] = "-";
7993 : : else
7994 : 0 : new_argv[out_arg] = "-o-";
7995 : :
7996 : : #ifdef HOST_HAS_PERSONALITY_ADDR_NO_RANDOMIZE
7997 : 0 : personality (personality (0xffffffffU) | ADDR_NO_RANDOMIZE);
7998 : : #endif
7999 : :
8000 : 0 : int status;
8001 : 0 : for (attempt = 0; attempt < RETRY_ICE_ATTEMPTS; ++attempt)
8002 : : {
8003 : 0 : int emit_system_info = 0;
8004 : 0 : int append = 0;
8005 : 0 : temp_stdout_files[attempt] = make_temp_file (".out");
8006 : 0 : temp_stderr_files[attempt] = make_temp_file (".err");
8007 : :
8008 : 0 : if (attempt == RETRY_ICE_ATTEMPTS - 1)
8009 : : {
8010 : 0 : append = 1;
8011 : 0 : emit_system_info = 1;
8012 : : }
8013 : :
8014 : 0 : status = run_attempt (new_argv, temp_stdout_files[attempt],
8015 : : temp_stderr_files[attempt], emit_system_info,
8016 : : append);
8017 : :
8018 : 0 : if (status != ATTEMPT_STATUS_ICE)
8019 : : {
8020 : 0 : fnotice (stderr, "The bug is not reproducible, so it is"
8021 : : " likely a hardware or OS problem.\n");
8022 : 0 : goto out;
8023 : : }
8024 : : }
8025 : :
8026 : 0 : if (!check_repro (temp_stdout_files, temp_stderr_files))
8027 : 0 : goto out;
8028 : :
8029 : 0 : {
8030 : : /* Insert commented out backtrace into report file. */
8031 : 0 : char **stderr_commented = &temp_stdout_files[RETRY_ICE_ATTEMPTS - 1];
8032 : 0 : insert_comments (temp_stderr_files[RETRY_ICE_ATTEMPTS - 1],
8033 : : *stderr_commented);
8034 : :
8035 : : /* In final attempt we append compiler options and preprocesssed code to last
8036 : : generated .out file with configuration and backtrace. */
8037 : 0 : char **err = &temp_stderr_files[RETRY_ICE_ATTEMPTS - 1];
8038 : 0 : do_report_bug (new_argv, nargs, stderr_commented, err);
8039 : : }
8040 : :
8041 : : out:
8042 : 0 : for (i = 0; i < RETRY_ICE_ATTEMPTS * 2; i++)
8043 : 0 : if (temp_files[i])
8044 : : {
8045 : 0 : unlink (temp_stdout_files[i]);
8046 : 0 : free (temp_stdout_files[i]);
8047 : : }
8048 : : }
8049 : :
8050 : : /* Search for a file named NAME trying various prefixes including the
8051 : : user's -B prefix and some standard ones.
8052 : : Return the absolute file name found. If nothing is found, return NAME. */
8053 : :
8054 : : static const char *
8055 : 546496 : find_file (const char *name)
8056 : : {
8057 : 546496 : char *newname = find_a_file (&startfile_prefixes, name, R_OK, true);
8058 : 546496 : return newname ? newname : name;
8059 : : }
8060 : :
8061 : : /* Determine whether a directory exists. */
8062 : :
8063 : : static int
8064 : 10485977 : is_directory (const char *path1)
8065 : : {
8066 : 10485977 : int len1;
8067 : 10485977 : char *path;
8068 : 10485977 : char *cp;
8069 : 10485977 : struct stat st;
8070 : :
8071 : : /* Ensure the string ends with "/.". The resulting path will be a
8072 : : directory even if the given path is a symbolic link. */
8073 : 10485977 : len1 = strlen (path1);
8074 : 10485977 : path = (char *) alloca (3 + len1);
8075 : 10485977 : memcpy (path, path1, len1);
8076 : 10485977 : cp = path + len1;
8077 : 10485977 : if (!IS_DIR_SEPARATOR (cp[-1]))
8078 : 1509862 : *cp++ = DIR_SEPARATOR;
8079 : 10485977 : *cp++ = '.';
8080 : 10485977 : *cp = '\0';
8081 : :
8082 : 10485977 : return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
8083 : : }
8084 : :
8085 : : /* Set up the various global variables to indicate that we're processing
8086 : : the input file named FILENAME. */
8087 : :
8088 : : void
8089 : 838589 : set_input (const char *filename)
8090 : : {
8091 : 838589 : const char *p;
8092 : :
8093 : 838589 : gcc_input_filename = filename;
8094 : 838589 : input_filename_length = strlen (gcc_input_filename);
8095 : 838589 : input_basename = lbasename (gcc_input_filename);
8096 : :
8097 : : /* Find a suffix starting with the last period,
8098 : : and set basename_length to exclude that suffix. */
8099 : 838589 : basename_length = strlen (input_basename);
8100 : 838589 : suffixed_basename_length = basename_length;
8101 : 838589 : p = input_basename + basename_length;
8102 : 3680927 : while (p != input_basename && *p != '.')
8103 : 2842338 : --p;
8104 : 838589 : if (*p == '.' && p != input_basename)
8105 : : {
8106 : 601568 : basename_length = p - input_basename;
8107 : 601568 : input_suffix = p + 1;
8108 : : }
8109 : : else
8110 : 237021 : input_suffix = "";
8111 : :
8112 : : /* If a spec for 'g', 'u', or 'U' is seen with -save-temps then
8113 : : we will need to do a stat on the gcc_input_filename. The
8114 : : INPUT_STAT_SET signals that the stat is needed. */
8115 : 838589 : input_stat_set = 0;
8116 : 838589 : }
8117 : :
8118 : : /* On fatal signals, delete all the temporary files. */
8119 : :
8120 : : static void
8121 : 0 : fatal_signal (int signum)
8122 : : {
8123 : 0 : signal (signum, SIG_DFL);
8124 : 0 : delete_failure_queue ();
8125 : 0 : delete_temp_files ();
8126 : : /* Get the same signal again, this time not handled,
8127 : : so its normal effect occurs. */
8128 : 0 : kill (getpid (), signum);
8129 : 0 : }
8130 : :
8131 : : /* Compare the contents of the two files named CMPFILE[0] and
8132 : : CMPFILE[1]. Return zero if they're identical, nonzero
8133 : : otherwise. */
8134 : :
8135 : : static int
8136 : 613 : compare_files (char *cmpfile[])
8137 : : {
8138 : 613 : int ret = 0;
8139 : 613 : FILE *temp[2] = { NULL, NULL };
8140 : 613 : int i;
8141 : :
8142 : : #if HAVE_MMAP_FILE
8143 : 613 : {
8144 : 613 : size_t length[2];
8145 : 613 : void *map[2] = { NULL, NULL };
8146 : :
8147 : 1839 : for (i = 0; i < 2; i++)
8148 : : {
8149 : 1226 : struct stat st;
8150 : :
8151 : 1226 : if (stat (cmpfile[i], &st) < 0 || !S_ISREG (st.st_mode))
8152 : : {
8153 : 0 : error ("%s: could not determine length of compare-debug file %s",
8154 : : gcc_input_filename, cmpfile[i]);
8155 : 0 : ret = 1;
8156 : 0 : break;
8157 : : }
8158 : :
8159 : 1226 : length[i] = st.st_size;
8160 : : }
8161 : :
8162 : 613 : if (!ret && length[0] != length[1])
8163 : : {
8164 : 31 : error ("%s: %<-fcompare-debug%> failure (length)", gcc_input_filename);
8165 : 31 : ret = 1;
8166 : : }
8167 : :
8168 : 31 : if (!ret)
8169 : 1684 : for (i = 0; i < 2; i++)
8170 : : {
8171 : 1133 : int fd = open (cmpfile[i], O_RDONLY);
8172 : 1133 : if (fd < 0)
8173 : : {
8174 : 0 : error ("%s: could not open compare-debug file %s",
8175 : : gcc_input_filename, cmpfile[i]);
8176 : 0 : ret = 1;
8177 : 0 : break;
8178 : : }
8179 : :
8180 : 1133 : map[i] = mmap (NULL, length[i], PROT_READ, MAP_PRIVATE, fd, 0);
8181 : 1133 : close (fd);
8182 : :
8183 : 1133 : if (map[i] == (void *) MAP_FAILED)
8184 : : {
8185 : : ret = -1;
8186 : : break;
8187 : : }
8188 : : }
8189 : :
8190 : 582 : if (!ret)
8191 : : {
8192 : 551 : if (memcmp (map[0], map[1], length[0]) != 0)
8193 : : {
8194 : 0 : error ("%s: %<-fcompare-debug%> failure", gcc_input_filename);
8195 : 0 : ret = 1;
8196 : : }
8197 : : }
8198 : :
8199 : 1839 : for (i = 0; i < 2; i++)
8200 : 1226 : if (map[i])
8201 : 1133 : munmap ((caddr_t) map[i], length[i]);
8202 : :
8203 : 613 : if (ret >= 0)
8204 : 582 : return ret;
8205 : :
8206 : 31 : ret = 0;
8207 : : }
8208 : : #endif
8209 : :
8210 : 93 : for (i = 0; i < 2; i++)
8211 : : {
8212 : 62 : temp[i] = fopen (cmpfile[i], "r");
8213 : 62 : if (!temp[i])
8214 : : {
8215 : 0 : error ("%s: could not open compare-debug file %s",
8216 : : gcc_input_filename, cmpfile[i]);
8217 : 0 : ret = 1;
8218 : 0 : break;
8219 : : }
8220 : : }
8221 : :
8222 : 31 : if (!ret && temp[0] && temp[1])
8223 : 31 : for (;;)
8224 : : {
8225 : 31 : int c0, c1;
8226 : 31 : c0 = fgetc (temp[0]);
8227 : 31 : c1 = fgetc (temp[1]);
8228 : :
8229 : 31 : if (c0 != c1)
8230 : : {
8231 : 0 : error ("%s: %<-fcompare-debug%> failure",
8232 : : gcc_input_filename);
8233 : 0 : ret = 1;
8234 : 0 : break;
8235 : : }
8236 : :
8237 : 31 : if (c0 == EOF)
8238 : : break;
8239 : : }
8240 : :
8241 : 93 : for (i = 1; i >= 0; i--)
8242 : : {
8243 : 62 : if (temp[i])
8244 : 62 : fclose (temp[i]);
8245 : : }
8246 : :
8247 : : return ret;
8248 : : }
8249 : :
8250 : 299630 : driver::driver (bool can_finalize, bool debug) :
8251 : 299630 : explicit_link_files (NULL),
8252 : 299630 : decoded_options (NULL)
8253 : : {
8254 : 299630 : env.init (can_finalize, debug);
8255 : 299630 : }
8256 : :
8257 : 299148 : driver::~driver ()
8258 : : {
8259 : 299148 : XDELETEVEC (explicit_link_files);
8260 : 299148 : XDELETEVEC (decoded_options);
8261 : 299148 : }
8262 : :
8263 : : /* driver::main is implemented as a series of driver:: method calls. */
8264 : :
8265 : : int
8266 : 299630 : driver::main (int argc, char **argv)
8267 : : {
8268 : 299630 : bool early_exit;
8269 : :
8270 : 299630 : set_progname (argv[0]);
8271 : 299630 : expand_at_files (&argc, &argv);
8272 : 299630 : decode_argv (argc, const_cast <const char **> (argv));
8273 : 299630 : global_initializations ();
8274 : 299630 : build_multilib_strings ();
8275 : 299630 : set_up_specs ();
8276 : 299343 : putenv_COLLECT_AS_OPTIONS (assembler_options);
8277 : 299343 : putenv_COLLECT_GCC (argv[0]);
8278 : 299343 : maybe_putenv_COLLECT_LTO_WRAPPER ();
8279 : 299343 : maybe_putenv_OFFLOAD_TARGETS ();
8280 : 299343 : handle_unrecognized_options ();
8281 : :
8282 : 299343 : if (completion)
8283 : : {
8284 : 5 : m_option_proposer.suggest_completion (completion);
8285 : 5 : return 0;
8286 : : }
8287 : :
8288 : 299338 : if (!maybe_print_and_exit ())
8289 : : return 0;
8290 : :
8291 : 286015 : early_exit = prepare_infiles ();
8292 : 285821 : if (early_exit)
8293 : 484 : return get_exit_code ();
8294 : :
8295 : 285337 : do_spec_on_infiles ();
8296 : 285337 : maybe_run_linker (argv[0]);
8297 : 285337 : final_actions ();
8298 : 285337 : return get_exit_code ();
8299 : : }
8300 : :
8301 : : /* Locate the final component of argv[0] after any leading path, and set
8302 : : the program name accordingly. */
8303 : :
8304 : : void
8305 : 299630 : driver::set_progname (const char *argv0) const
8306 : : {
8307 : 299630 : const char *p = argv0 + strlen (argv0);
8308 : 1653482 : while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
8309 : 1353852 : --p;
8310 : 299630 : progname = p;
8311 : :
8312 : 299630 : xmalloc_set_program_name (progname);
8313 : 299630 : }
8314 : :
8315 : : /* Expand any @ files within the command-line args,
8316 : : setting at_file_supplied if any were expanded. */
8317 : :
8318 : : void
8319 : 299630 : driver::expand_at_files (int *argc, char ***argv) const
8320 : : {
8321 : 299630 : char **old_argv = *argv;
8322 : :
8323 : 299630 : expandargv (argc, argv);
8324 : :
8325 : : /* Determine if any expansions were made. */
8326 : 299630 : if (*argv != old_argv)
8327 : 13178 : at_file_supplied = true;
8328 : 299630 : }
8329 : :
8330 : : /* Decode the command-line arguments from argc/argv into the
8331 : : decoded_options array. */
8332 : :
8333 : : void
8334 : 299630 : driver::decode_argv (int argc, const char **argv)
8335 : : {
8336 : 299630 : init_opts_obstack ();
8337 : 299630 : init_options_struct (&global_options, &global_options_set);
8338 : :
8339 : 299630 : decode_cmdline_options_to_array (argc, argv,
8340 : : CL_DRIVER,
8341 : : &decoded_options, &decoded_options_count);
8342 : 299630 : }
8343 : :
8344 : : /* Perform various initializations and setup. */
8345 : :
8346 : : void
8347 : 299630 : driver::global_initializations ()
8348 : : {
8349 : : /* Unlock the stdio streams. */
8350 : 299630 : unlock_std_streams ();
8351 : :
8352 : 299630 : gcc_init_libintl ();
8353 : :
8354 : 299630 : diagnostic_initialize (global_dc, 0);
8355 : 299630 : diagnostic_color_init (global_dc);
8356 : 299630 : diagnostic_urls_init (global_dc);
8357 : 299630 : global_dc->push_owned_urlifier (make_gcc_urlifier (0));
8358 : :
8359 : : #ifdef GCC_DRIVER_HOST_INITIALIZATION
8360 : : /* Perform host dependent initialization when needed. */
8361 : : GCC_DRIVER_HOST_INITIALIZATION;
8362 : : #endif
8363 : :
8364 : 299630 : if (atexit (delete_temp_files) != 0)
8365 : 0 : fatal_error (input_location, "atexit failed");
8366 : :
8367 : 299630 : if (signal (SIGINT, SIG_IGN) != SIG_IGN)
8368 : 299479 : signal (SIGINT, fatal_signal);
8369 : : #ifdef SIGHUP
8370 : 299630 : if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
8371 : 21195 : signal (SIGHUP, fatal_signal);
8372 : : #endif
8373 : 299630 : if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
8374 : 299630 : signal (SIGTERM, fatal_signal);
8375 : : #ifdef SIGPIPE
8376 : 299630 : if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
8377 : 299630 : signal (SIGPIPE, fatal_signal);
8378 : : #endif
8379 : : #ifdef SIGCHLD
8380 : : /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
8381 : : receive the signal. A different setting is inheritable */
8382 : 299630 : signal (SIGCHLD, SIG_DFL);
8383 : : #endif
8384 : :
8385 : : /* Parsing and gimplification sometimes need quite large stack.
8386 : : Increase stack size limits if possible. */
8387 : 299630 : stack_limit_increase (64 * 1024 * 1024);
8388 : :
8389 : : /* Allocate the argument vector. */
8390 : 299630 : alloc_args ();
8391 : :
8392 : 299630 : obstack_init (&obstack);
8393 : 299630 : }
8394 : :
8395 : : /* Build multilib_select, et. al from the separate lines that make up each
8396 : : multilib selection. */
8397 : :
8398 : : void
8399 : 299630 : driver::build_multilib_strings () const
8400 : : {
8401 : 299630 : {
8402 : 299630 : const char *p;
8403 : 299630 : const char *const *q = multilib_raw;
8404 : 299630 : int need_space;
8405 : :
8406 : 299630 : obstack_init (&multilib_obstack);
8407 : 299630 : while ((p = *q++) != (char *) 0)
8408 : 1198520 : obstack_grow (&multilib_obstack, p, strlen (p));
8409 : :
8410 : 299630 : obstack_1grow (&multilib_obstack, 0);
8411 : 299630 : multilib_select = XOBFINISH (&multilib_obstack, const char *);
8412 : :
8413 : 299630 : q = multilib_matches_raw;
8414 : 299630 : while ((p = *q++) != (char *) 0)
8415 : 898890 : obstack_grow (&multilib_obstack, p, strlen (p));
8416 : :
8417 : 299630 : obstack_1grow (&multilib_obstack, 0);
8418 : 299630 : multilib_matches = XOBFINISH (&multilib_obstack, const char *);
8419 : :
8420 : 299630 : q = multilib_exclusions_raw;
8421 : 299630 : while ((p = *q++) != (char *) 0)
8422 : 299630 : obstack_grow (&multilib_obstack, p, strlen (p));
8423 : :
8424 : 299630 : obstack_1grow (&multilib_obstack, 0);
8425 : 299630 : multilib_exclusions = XOBFINISH (&multilib_obstack, const char *);
8426 : :
8427 : 299630 : q = multilib_reuse_raw;
8428 : 299630 : while ((p = *q++) != (char *) 0)
8429 : 299630 : obstack_grow (&multilib_obstack, p, strlen (p));
8430 : :
8431 : 299630 : obstack_1grow (&multilib_obstack, 0);
8432 : 299630 : multilib_reuse = XOBFINISH (&multilib_obstack, const char *);
8433 : :
8434 : 299630 : need_space = false;
8435 : 599260 : for (size_t i = 0; i < ARRAY_SIZE (multilib_defaults_raw); i++)
8436 : : {
8437 : 299630 : if (need_space)
8438 : 0 : obstack_1grow (&multilib_obstack, ' ');
8439 : 299630 : obstack_grow (&multilib_obstack,
8440 : : multilib_defaults_raw[i],
8441 : : strlen (multilib_defaults_raw[i]));
8442 : 299630 : need_space = true;
8443 : : }
8444 : :
8445 : 299630 : obstack_1grow (&multilib_obstack, 0);
8446 : 299630 : multilib_defaults = XOBFINISH (&multilib_obstack, const char *);
8447 : : }
8448 : 299630 : }
8449 : :
8450 : : /* Set up the spec-handling machinery. */
8451 : :
8452 : : void
8453 : 299630 : driver::set_up_specs () const
8454 : : {
8455 : 299630 : const char *spec_machine_suffix;
8456 : 299630 : char *specs_file;
8457 : 299630 : size_t i;
8458 : :
8459 : : #ifdef INIT_ENVIRONMENT
8460 : : /* Set up any other necessary machine specific environment variables. */
8461 : : xputenv (INIT_ENVIRONMENT);
8462 : : #endif
8463 : :
8464 : : /* Make a table of what switches there are (switches, n_switches).
8465 : : Make a table of specified input files (infiles, n_infiles).
8466 : : Decode switches that are handled locally. */
8467 : :
8468 : 299630 : process_command (decoded_options_count, decoded_options);
8469 : :
8470 : : /* Initialize the vector of specs to just the default.
8471 : : This means one element containing 0s, as a terminator. */
8472 : :
8473 : 299344 : compilers = XNEWVAR (struct compiler, sizeof default_compilers);
8474 : 299344 : memcpy (compilers, default_compilers, sizeof default_compilers);
8475 : 299344 : n_compilers = n_default_compilers;
8476 : :
8477 : : /* Read specs from a file if there is one. */
8478 : :
8479 : 299344 : machine_suffix = concat (spec_host_machine, dir_separator_str, spec_version,
8480 : : accel_dir_suffix, dir_separator_str, NULL);
8481 : 299344 : just_machine_suffix = concat (spec_machine, dir_separator_str, NULL);
8482 : :
8483 : 299344 : specs_file = find_a_file (&startfile_prefixes, "specs", R_OK, true);
8484 : : /* Read the specs file unless it is a default one. */
8485 : 299344 : if (specs_file != 0 && strcmp (specs_file, "specs"))
8486 : 298283 : read_specs (specs_file, true, false);
8487 : : else
8488 : 1061 : init_spec ();
8489 : :
8490 : : #ifdef ACCEL_COMPILER
8491 : : spec_machine_suffix = machine_suffix;
8492 : : #else
8493 : 299344 : spec_machine_suffix = just_machine_suffix;
8494 : : #endif
8495 : :
8496 : 299344 : const char *exec_prefix
8497 : 299344 : = gcc_exec_prefix ? gcc_exec_prefix : standard_exec_prefix;
8498 : : /* We need to check standard_exec_prefix/spec_machine_suffix/specs
8499 : : for any override of as, ld and libraries. */
8500 : 299344 : specs_file = (char *) alloca (
8501 : : strlen (exec_prefix) + strlen (spec_machine_suffix) + sizeof ("specs"));
8502 : 299344 : strcpy (specs_file, exec_prefix);
8503 : 299344 : strcat (specs_file, spec_machine_suffix);
8504 : 299344 : strcat (specs_file, "specs");
8505 : 299344 : if (access (specs_file, R_OK) == 0)
8506 : 0 : read_specs (specs_file, true, false);
8507 : :
8508 : : /* Process any configure-time defaults specified for the command line
8509 : : options, via OPTION_DEFAULT_SPECS. */
8510 : 3292784 : for (i = 0; i < ARRAY_SIZE (option_default_specs); i++)
8511 : 2993440 : do_option_spec (option_default_specs[i].name,
8512 : 2993440 : option_default_specs[i].spec);
8513 : :
8514 : : /* Process DRIVER_SELF_SPECS, adding any new options to the end
8515 : : of the command line. */
8516 : :
8517 : 2095408 : for (i = 0; i < ARRAY_SIZE (driver_self_specs); i++)
8518 : 1796064 : do_self_spec (driver_self_specs[i]);
8519 : :
8520 : : /* If not cross-compiling, look for executables in the standard
8521 : : places. */
8522 : 299344 : if (*cross_compile == '0')
8523 : : {
8524 : 299344 : if (*md_exec_prefix)
8525 : : {
8526 : 0 : add_prefix (&exec_prefixes, md_exec_prefix, "GCC",
8527 : : PREFIX_PRIORITY_LAST, 0, 0);
8528 : : }
8529 : : }
8530 : :
8531 : : /* Process sysroot_suffix_spec. */
8532 : 299344 : if (*sysroot_suffix_spec != 0
8533 : 0 : && !no_sysroot_suffix
8534 : 299344 : && do_spec_2 (sysroot_suffix_spec, NULL) == 0)
8535 : : {
8536 : 0 : if (argbuf.length () > 1)
8537 : 0 : error ("spec failure: more than one argument to "
8538 : : "%<SYSROOT_SUFFIX_SPEC%>");
8539 : 0 : else if (argbuf.length () == 1)
8540 : 0 : target_sysroot_suffix = xstrdup (argbuf.last ());
8541 : : }
8542 : :
8543 : : #ifdef HAVE_LD_SYSROOT
8544 : : /* Pass the --sysroot option to the linker, if it supports that. If
8545 : : there is a sysroot_suffix_spec, it has already been processed by
8546 : : this point, so target_system_root really is the system root we
8547 : : should be using. */
8548 : 299344 : if (target_system_root)
8549 : : {
8550 : 0 : obstack_grow (&obstack, "%(sysroot_spec) ", strlen ("%(sysroot_spec) "));
8551 : 0 : obstack_grow0 (&obstack, link_spec, strlen (link_spec));
8552 : 0 : set_spec ("link", XOBFINISH (&obstack, const char *), false);
8553 : : }
8554 : : #endif
8555 : :
8556 : : /* Process sysroot_hdrs_suffix_spec. */
8557 : 299344 : if (*sysroot_hdrs_suffix_spec != 0
8558 : 0 : && !no_sysroot_suffix
8559 : 299344 : && do_spec_2 (sysroot_hdrs_suffix_spec, NULL) == 0)
8560 : : {
8561 : 0 : if (argbuf.length () > 1)
8562 : 0 : error ("spec failure: more than one argument "
8563 : : "to %<SYSROOT_HEADERS_SUFFIX_SPEC%>");
8564 : 0 : else if (argbuf.length () == 1)
8565 : 0 : target_sysroot_hdrs_suffix = xstrdup (argbuf.last ());
8566 : : }
8567 : :
8568 : : /* Look for startfiles in the standard places. */
8569 : 299344 : if (*startfile_prefix_spec != 0
8570 : 0 : && do_spec_2 (startfile_prefix_spec, NULL) == 0
8571 : 299344 : && do_spec_1 (" ", 0, NULL) == 0)
8572 : : {
8573 : 0 : for (const char *arg : argbuf)
8574 : 0 : add_sysrooted_prefix (&startfile_prefixes, arg, "BINUTILS",
8575 : : PREFIX_PRIORITY_LAST, 0, 1);
8576 : : }
8577 : : /* We should eventually get rid of all these and stick to
8578 : : startfile_prefix_spec exclusively. */
8579 : 299344 : else if (*cross_compile == '0' || target_system_root)
8580 : : {
8581 : 299344 : if (*md_startfile_prefix)
8582 : 0 : add_sysrooted_prefix (&startfile_prefixes, md_startfile_prefix,
8583 : : "GCC", PREFIX_PRIORITY_LAST, 0, 1);
8584 : :
8585 : 299344 : if (*md_startfile_prefix_1)
8586 : 0 : add_sysrooted_prefix (&startfile_prefixes, md_startfile_prefix_1,
8587 : : "GCC", PREFIX_PRIORITY_LAST, 0, 1);
8588 : :
8589 : : /* If standard_startfile_prefix is relative, base it on
8590 : : standard_exec_prefix. This lets us move the installed tree
8591 : : as a unit. If GCC_EXEC_PREFIX is defined, base
8592 : : standard_startfile_prefix on that as well.
8593 : :
8594 : : If the prefix is relative, only search it for native compilers;
8595 : : otherwise we will search a directory containing host libraries. */
8596 : 299344 : if (IS_ABSOLUTE_PATH (standard_startfile_prefix))
8597 : : add_sysrooted_prefix (&startfile_prefixes,
8598 : : standard_startfile_prefix, "BINUTILS",
8599 : : PREFIX_PRIORITY_LAST, 0, 1);
8600 : 299344 : else if (*cross_compile == '0')
8601 : : {
8602 : 299344 : add_prefix (&startfile_prefixes,
8603 : 598688 : concat (gcc_exec_prefix
8604 : : ? gcc_exec_prefix : standard_exec_prefix,
8605 : : machine_suffix,
8606 : : standard_startfile_prefix, NULL),
8607 : : NULL, PREFIX_PRIORITY_LAST, 0, 1);
8608 : : }
8609 : :
8610 : : /* Sysrooted prefixes are relocated because target_system_root is
8611 : : also relocated by gcc_exec_prefix. */
8612 : 299344 : if (*standard_startfile_prefix_1)
8613 : 299344 : add_sysrooted_prefix (&startfile_prefixes,
8614 : : standard_startfile_prefix_1, "BINUTILS",
8615 : : PREFIX_PRIORITY_LAST, 0, 1);
8616 : 299344 : if (*standard_startfile_prefix_2)
8617 : 299344 : add_sysrooted_prefix (&startfile_prefixes,
8618 : : standard_startfile_prefix_2, "BINUTILS",
8619 : : PREFIX_PRIORITY_LAST, 0, 1);
8620 : : }
8621 : :
8622 : : /* Process any user specified specs in the order given on the command
8623 : : line. */
8624 : 299346 : for (struct user_specs *uptr = user_specs_head; uptr; uptr = uptr->next)
8625 : : {
8626 : 3 : char *filename = find_a_file (&startfile_prefixes, uptr->filename,
8627 : : R_OK, true);
8628 : 3 : read_specs (filename ? filename : uptr->filename, false, true);
8629 : : }
8630 : :
8631 : : /* Process any user self specs. */
8632 : 299343 : {
8633 : 299343 : struct spec_list *sl;
8634 : 14069121 : for (sl = specs; sl; sl = sl->next)
8635 : 13769778 : if (sl->name_len == sizeof "self_spec" - 1
8636 : 2095401 : && !strcmp (sl->name, "self_spec"))
8637 : 299343 : do_self_spec (*sl->ptr_spec);
8638 : : }
8639 : :
8640 : 299343 : if (compare_debug)
8641 : : {
8642 : 619 : enum save_temps save;
8643 : :
8644 : 619 : if (!compare_debug_second)
8645 : : {
8646 : 619 : n_switches_debug_check[1] = n_switches;
8647 : 619 : n_switches_alloc_debug_check[1] = n_switches_alloc;
8648 : 619 : switches_debug_check[1] = XDUPVEC (struct switchstr, switches,
8649 : : n_switches_alloc);
8650 : :
8651 : 619 : do_self_spec ("%:compare-debug-self-opt()");
8652 : 619 : n_switches_debug_check[0] = n_switches;
8653 : 619 : n_switches_alloc_debug_check[0] = n_switches_alloc;
8654 : 619 : switches_debug_check[0] = switches;
8655 : :
8656 : 619 : n_switches = n_switches_debug_check[1];
8657 : 619 : n_switches_alloc = n_switches_alloc_debug_check[1];
8658 : 619 : switches = switches_debug_check[1];
8659 : : }
8660 : :
8661 : : /* Avoid crash when computing %j in this early. */
8662 : 619 : save = save_temps_flag;
8663 : 619 : save_temps_flag = SAVE_TEMPS_NONE;
8664 : :
8665 : 619 : compare_debug = -compare_debug;
8666 : 619 : do_self_spec ("%:compare-debug-self-opt()");
8667 : :
8668 : 619 : save_temps_flag = save;
8669 : :
8670 : 619 : if (!compare_debug_second)
8671 : : {
8672 : 619 : n_switches_debug_check[1] = n_switches;
8673 : 619 : n_switches_alloc_debug_check[1] = n_switches_alloc;
8674 : 619 : switches_debug_check[1] = switches;
8675 : 619 : compare_debug = -compare_debug;
8676 : 619 : n_switches = n_switches_debug_check[0];
8677 : 619 : n_switches_alloc = n_switches_debug_check[0];
8678 : 619 : switches = switches_debug_check[0];
8679 : : }
8680 : : }
8681 : :
8682 : :
8683 : : /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
8684 : 299343 : if (gcc_exec_prefix)
8685 : 299343 : gcc_exec_prefix = concat (gcc_exec_prefix, spec_host_machine,
8686 : : dir_separator_str, spec_version,
8687 : : accel_dir_suffix, dir_separator_str, NULL);
8688 : :
8689 : : /* Now we have the specs.
8690 : : Set the `valid' bits for switches that match anything in any spec. */
8691 : :
8692 : 299343 : validate_all_switches ();
8693 : :
8694 : : /* Now that we have the switches and the specs, set
8695 : : the subdirectory based on the options. */
8696 : 299343 : set_multilib_dir ();
8697 : 299343 : }
8698 : :
8699 : : /* Set up to remember the pathname of gcc and any options
8700 : : needed for collect. We use argv[0] instead of progname because
8701 : : we need the complete pathname. */
8702 : :
8703 : : void
8704 : 299343 : driver::putenv_COLLECT_GCC (const char *argv0) const
8705 : : {
8706 : 299343 : obstack_init (&collect_obstack);
8707 : 299343 : obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=") - 1);
8708 : 299343 : obstack_grow (&collect_obstack, argv0, strlen (argv0) + 1);
8709 : 299343 : xputenv (XOBFINISH (&collect_obstack, char *));
8710 : 299343 : }
8711 : :
8712 : : /* Set up to remember the pathname of the lto wrapper. */
8713 : :
8714 : : void
8715 : 299343 : driver::maybe_putenv_COLLECT_LTO_WRAPPER () const
8716 : : {
8717 : 299343 : char *lto_wrapper_file;
8718 : :
8719 : 299343 : if (have_c)
8720 : : lto_wrapper_file = NULL;
8721 : : else
8722 : 109775 : lto_wrapper_file = find_a_program ("lto-wrapper");
8723 : 109775 : if (lto_wrapper_file)
8724 : : {
8725 : 215168 : lto_wrapper_file = convert_white_space (lto_wrapper_file);
8726 : 107584 : set_static_spec_owned (<o_wrapper_spec, lto_wrapper_file);
8727 : 107584 : obstack_init (&collect_obstack);
8728 : 107584 : obstack_grow (&collect_obstack, "COLLECT_LTO_WRAPPER=",
8729 : : sizeof ("COLLECT_LTO_WRAPPER=") - 1);
8730 : 107584 : obstack_grow (&collect_obstack, lto_wrapper_spec,
8731 : : strlen (lto_wrapper_spec) + 1);
8732 : 107584 : xputenv (XOBFINISH (&collect_obstack, char *));
8733 : : }
8734 : :
8735 : 299343 : }
8736 : :
8737 : : /* Set up to remember the names of offload targets. */
8738 : :
8739 : : void
8740 : 299343 : driver::maybe_putenv_OFFLOAD_TARGETS () const
8741 : : {
8742 : 299343 : if (offload_targets && offload_targets[0] != '\0')
8743 : : {
8744 : 0 : obstack_grow (&collect_obstack, "OFFLOAD_TARGET_NAMES=",
8745 : : sizeof ("OFFLOAD_TARGET_NAMES=") - 1);
8746 : 0 : obstack_grow (&collect_obstack, offload_targets,
8747 : : strlen (offload_targets) + 1);
8748 : 0 : xputenv (XOBFINISH (&collect_obstack, char *));
8749 : : #if OFFLOAD_DEFAULTED
8750 : : if (offload_targets_default)
8751 : : xputenv ("OFFLOAD_TARGET_DEFAULT=1");
8752 : : #endif
8753 : : }
8754 : :
8755 : 299343 : free (offload_targets);
8756 : 299343 : offload_targets = NULL;
8757 : 299343 : }
8758 : :
8759 : : /* Reject switches that no pass was interested in. */
8760 : :
8761 : : void
8762 : 299343 : driver::handle_unrecognized_options ()
8763 : : {
8764 : 7074063 : for (size_t i = 0; (int) i < n_switches; i++)
8765 : 6774720 : if (! switches[i].validated)
8766 : : {
8767 : 623 : const char *hint = m_option_proposer.suggest_option (switches[i].part1);
8768 : 623 : if (hint)
8769 : 217 : error ("unrecognized command-line option %<-%s%>;"
8770 : : " did you mean %<-%s%>?",
8771 : 217 : switches[i].part1, hint);
8772 : : else
8773 : 406 : error ("unrecognized command-line option %<-%s%>",
8774 : 406 : switches[i].part1);
8775 : : }
8776 : 299343 : }
8777 : :
8778 : : /* Handle the various -print-* options, returning 0 if the driver
8779 : : should exit, or nonzero if the driver should continue. */
8780 : :
8781 : : int
8782 : 299338 : driver::maybe_print_and_exit () const
8783 : : {
8784 : 299338 : if (print_search_dirs)
8785 : : {
8786 : 56 : printf (_("install: %s%s\n"),
8787 : : gcc_exec_prefix ? gcc_exec_prefix : standard_exec_prefix,
8788 : 28 : gcc_exec_prefix ? "" : machine_suffix);
8789 : 28 : printf (_("programs: %s\n"),
8790 : : build_search_list (&exec_prefixes, "", false, false));
8791 : 28 : printf (_("libraries: %s\n"),
8792 : : build_search_list (&startfile_prefixes, "", false, true));
8793 : 28 : return (0);
8794 : : }
8795 : :
8796 : 299310 : if (print_file_name)
8797 : : {
8798 : 3970 : printf ("%s\n", find_file (print_file_name));
8799 : 3970 : return (0);
8800 : : }
8801 : :
8802 : 295340 : if (print_prog_name)
8803 : : {
8804 : 108 : if (use_ld != NULL && ! strcmp (print_prog_name, "ld"))
8805 : : {
8806 : : /* Append USE_LD to the default linker. */
8807 : : #ifdef DEFAULT_LINKER
8808 : : char *ld;
8809 : : # ifdef HAVE_HOST_EXECUTABLE_SUFFIX
8810 : : int len = (sizeof (DEFAULT_LINKER)
8811 : : - sizeof (HOST_EXECUTABLE_SUFFIX));
8812 : : ld = NULL;
8813 : : if (len > 0)
8814 : : {
8815 : : char *default_linker = xstrdup (DEFAULT_LINKER);
8816 : : /* Strip HOST_EXECUTABLE_SUFFIX if DEFAULT_LINKER contains
8817 : : HOST_EXECUTABLE_SUFFIX. */
8818 : : if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
8819 : : {
8820 : : default_linker[len] = '\0';
8821 : : ld = concat (default_linker, use_ld,
8822 : : HOST_EXECUTABLE_SUFFIX, NULL);
8823 : : }
8824 : : }
8825 : : if (ld == NULL)
8826 : : # endif
8827 : : ld = concat (DEFAULT_LINKER, use_ld, NULL);
8828 : : if (access (ld, X_OK) == 0)
8829 : : {
8830 : : printf ("%s\n", ld);
8831 : : return (0);
8832 : : }
8833 : : #endif
8834 : 0 : print_prog_name = concat (print_prog_name, use_ld, NULL);
8835 : : }
8836 : 108 : char *newname = find_a_program (print_prog_name);
8837 : 108 : printf ("%s\n", (newname ? newname : print_prog_name));
8838 : 108 : return (0);
8839 : : }
8840 : :
8841 : 295232 : if (print_multi_lib)
8842 : : {
8843 : 4442 : print_multilib_info ();
8844 : 4442 : return (0);
8845 : : }
8846 : :
8847 : 290790 : if (print_multi_directory)
8848 : : {
8849 : 3849 : if (multilib_dir == NULL)
8850 : 3824 : printf (".\n");
8851 : : else
8852 : 25 : printf ("%s\n", multilib_dir);
8853 : 3849 : return (0);
8854 : : }
8855 : :
8856 : 286941 : if (print_multiarch)
8857 : : {
8858 : 0 : if (multiarch_dir == NULL)
8859 : 0 : printf ("\n");
8860 : : else
8861 : 0 : printf ("%s\n", multiarch_dir);
8862 : 0 : return (0);
8863 : : }
8864 : :
8865 : 286941 : if (print_sysroot)
8866 : : {
8867 : 0 : if (target_system_root)
8868 : : {
8869 : 0 : if (target_sysroot_suffix)
8870 : 0 : printf ("%s%s\n", target_system_root, target_sysroot_suffix);
8871 : : else
8872 : 0 : printf ("%s\n", target_system_root);
8873 : : }
8874 : 0 : return (0);
8875 : : }
8876 : :
8877 : 286941 : if (print_multi_os_directory)
8878 : : {
8879 : 149 : if (multilib_os_dir == NULL)
8880 : 0 : printf (".\n");
8881 : : else
8882 : 149 : printf ("%s\n", multilib_os_dir);
8883 : 149 : return (0);
8884 : : }
8885 : :
8886 : 286792 : if (print_sysroot_headers_suffix)
8887 : : {
8888 : 1 : if (*sysroot_hdrs_suffix_spec)
8889 : : {
8890 : 0 : printf("%s\n", (target_sysroot_hdrs_suffix
8891 : : ? target_sysroot_hdrs_suffix
8892 : : : ""));
8893 : 0 : return (0);
8894 : : }
8895 : : else
8896 : : /* The error status indicates that only one set of fixed
8897 : : headers should be built. */
8898 : 1 : fatal_error (input_location,
8899 : : "not configured with sysroot headers suffix");
8900 : : }
8901 : :
8902 : 286791 : if (print_help_list)
8903 : : {
8904 : 4 : display_help ();
8905 : :
8906 : 4 : if (! verbose_flag)
8907 : : {
8908 : 1 : printf (_("\nFor bug reporting instructions, please see:\n"));
8909 : 1 : printf ("%s.\n", bug_report_url);
8910 : :
8911 : 1 : return (0);
8912 : : }
8913 : :
8914 : : /* We do not exit here. Instead we have created a fake input file
8915 : : called 'help-dummy' which needs to be compiled, and we pass this
8916 : : on the various sub-processes, along with the --help switch.
8917 : : Ensure their output appears after ours. */
8918 : 3 : fputc ('\n', stdout);
8919 : 3 : fflush (stdout);
8920 : : }
8921 : :
8922 : 286790 : if (print_version)
8923 : : {
8924 : 78 : printf (_("%s %s%s\n"), progname, pkgversion_string,
8925 : : version_string);
8926 : 78 : printf ("Copyright %s 2025 Free Software Foundation, Inc.\n",
8927 : : _("(C)"));
8928 : 78 : fputs (_("This is free software; see the source for copying conditions. There is NO\n\
8929 : : warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"),
8930 : : stdout);
8931 : 78 : if (! verbose_flag)
8932 : : return 0;
8933 : :
8934 : : /* We do not exit here. We use the same mechanism of --help to print
8935 : : the version of the sub-processes. */
8936 : 0 : fputc ('\n', stdout);
8937 : 0 : fflush (stdout);
8938 : : }
8939 : :
8940 : 286712 : if (verbose_flag)
8941 : : {
8942 : 1493 : print_configuration (stderr);
8943 : 1493 : if (n_infiles == 0)
8944 : : return (0);
8945 : : }
8946 : :
8947 : : return 1;
8948 : : }
8949 : :
8950 : : /* Figure out what to do with each input file.
8951 : : Return true if we need to exit early from "main", false otherwise. */
8952 : :
8953 : : bool
8954 : 286015 : driver::prepare_infiles ()
8955 : : {
8956 : 286015 : size_t i;
8957 : 286015 : int lang_n_infiles = 0;
8958 : :
8959 : 286015 : if (n_infiles == added_libraries)
8960 : 194 : fatal_error (input_location, "no input files");
8961 : :
8962 : 285821 : if (seen_error ())
8963 : : /* Early exit needed from main. */
8964 : : return true;
8965 : :
8966 : : /* Make a place to record the compiler output file names
8967 : : that correspond to the input files. */
8968 : :
8969 : 285337 : i = n_infiles;
8970 : 285337 : i += lang_specific_extra_outfiles;
8971 : 285337 : outfiles = XCNEWVEC (const char *, i);
8972 : :
8973 : : /* Record which files were specified explicitly as link input. */
8974 : :
8975 : 285337 : explicit_link_files = XCNEWVEC (char, n_infiles);
8976 : :
8977 : 285337 : combine_inputs = have_o || flag_wpa;
8978 : :
8979 : 840477 : for (i = 0; (int) i < n_infiles; i++)
8980 : : {
8981 : 555140 : const char *name = infiles[i].name;
8982 : 555140 : struct compiler *compiler = lookup_compiler (name,
8983 : : strlen (name),
8984 : : infiles[i].language);
8985 : :
8986 : 555140 : if (compiler && !(compiler->combinable))
8987 : 255208 : combine_inputs = false;
8988 : :
8989 : 555140 : if (lang_n_infiles > 0 && compiler != input_file_compiler
8990 : 248033 : && infiles[i].language && infiles[i].language[0] != '*')
8991 : 33 : infiles[i].incompiler = compiler;
8992 : 555107 : else if (infiles[i].artificial)
8993 : : /* Leave lang_n_infiles alone so files added by the driver don't
8994 : : interfere with -c -o. */
8995 : 3 : infiles[i].incompiler = compiler;
8996 : 555104 : else if (compiler)
8997 : : {
8998 : 296331 : lang_n_infiles++;
8999 : 296331 : input_file_compiler = compiler;
9000 : 296331 : infiles[i].incompiler = compiler;
9001 : : }
9002 : : else
9003 : : {
9004 : : /* Since there is no compiler for this input file, assume it is a
9005 : : linker file. */
9006 : 258773 : explicit_link_files[i] = 1;
9007 : 258773 : infiles[i].incompiler = NULL;
9008 : : }
9009 : 555140 : infiles[i].compiled = false;
9010 : 555140 : infiles[i].preprocessed = false;
9011 : : }
9012 : :
9013 : 285337 : if (!combine_inputs && have_c && have_o && lang_n_infiles > 1)
9014 : 0 : fatal_error (input_location,
9015 : : "cannot specify %<-o%> with %<-c%>, %<-S%> or %<-E%> "
9016 : : "with multiple files");
9017 : :
9018 : : /* No early exit needed from main; we can continue. */
9019 : : return false;
9020 : : }
9021 : :
9022 : : /* Run the spec machinery on each input file. */
9023 : :
9024 : : void
9025 : 285337 : driver::do_spec_on_infiles () const
9026 : : {
9027 : 285337 : size_t i;
9028 : :
9029 : 840477 : for (i = 0; (int) i < n_infiles; i++)
9030 : : {
9031 : 555140 : int this_file_error = 0;
9032 : :
9033 : : /* Tell do_spec what to substitute for %i. */
9034 : :
9035 : 555140 : input_file_number = i;
9036 : 555140 : set_input (infiles[i].name);
9037 : :
9038 : 555140 : if (infiles[i].compiled)
9039 : 9102 : continue;
9040 : :
9041 : : /* Use the same thing in %o, unless cp->spec says otherwise. */
9042 : :
9043 : 546038 : outfiles[i] = gcc_input_filename;
9044 : :
9045 : : /* Figure out which compiler from the file's suffix. */
9046 : :
9047 : 546038 : input_file_compiler
9048 : 546038 : = lookup_compiler (infiles[i].name, input_filename_length,
9049 : : infiles[i].language);
9050 : :
9051 : 546038 : if (input_file_compiler)
9052 : : {
9053 : : /* Ok, we found an applicable compiler. Run its spec. */
9054 : :
9055 : 287265 : if (input_file_compiler->spec[0] == '#')
9056 : : {
9057 : 0 : error ("%s: %s compiler not installed on this system",
9058 : : gcc_input_filename, &input_file_compiler->spec[1]);
9059 : 0 : this_file_error = 1;
9060 : : }
9061 : : else
9062 : : {
9063 : 287265 : int value;
9064 : :
9065 : 287265 : if (compare_debug)
9066 : : {
9067 : 617 : free (debug_check_temp_file[0]);
9068 : 617 : debug_check_temp_file[0] = NULL;
9069 : :
9070 : 617 : free (debug_check_temp_file[1]);
9071 : 617 : debug_check_temp_file[1] = NULL;
9072 : : }
9073 : :
9074 : 287265 : value = do_spec (input_file_compiler->spec);
9075 : 287265 : infiles[i].compiled = true;
9076 : 287265 : if (value < 0)
9077 : : this_file_error = 1;
9078 : 258072 : else if (compare_debug && debug_check_temp_file[0])
9079 : : {
9080 : 613 : if (verbose_flag)
9081 : 0 : inform (UNKNOWN_LOCATION,
9082 : : "recompiling with %<-fcompare-debug%>");
9083 : :
9084 : 613 : compare_debug = -compare_debug;
9085 : 613 : n_switches = n_switches_debug_check[1];
9086 : 613 : n_switches_alloc = n_switches_alloc_debug_check[1];
9087 : 613 : switches = switches_debug_check[1];
9088 : :
9089 : 613 : value = do_spec (input_file_compiler->spec);
9090 : :
9091 : 613 : compare_debug = -compare_debug;
9092 : 613 : n_switches = n_switches_debug_check[0];
9093 : 613 : n_switches_alloc = n_switches_alloc_debug_check[0];
9094 : 613 : switches = switches_debug_check[0];
9095 : :
9096 : 613 : if (value < 0)
9097 : : {
9098 : 2 : error ("during %<-fcompare-debug%> recompilation");
9099 : 2 : this_file_error = 1;
9100 : : }
9101 : :
9102 : 613 : gcc_assert (debug_check_temp_file[1]
9103 : : && filename_cmp (debug_check_temp_file[0],
9104 : : debug_check_temp_file[1]));
9105 : :
9106 : 613 : if (verbose_flag)
9107 : 0 : inform (UNKNOWN_LOCATION, "comparing final insns dumps");
9108 : :
9109 : 613 : if (compare_files (debug_check_temp_file))
9110 : 29224 : this_file_error = 1;
9111 : : }
9112 : :
9113 : 287265 : if (compare_debug)
9114 : : {
9115 : 617 : free (debug_check_temp_file[0]);
9116 : 617 : debug_check_temp_file[0] = NULL;
9117 : :
9118 : 617 : free (debug_check_temp_file[1]);
9119 : 617 : debug_check_temp_file[1] = NULL;
9120 : : }
9121 : : }
9122 : : }
9123 : :
9124 : : /* If this file's name does not contain a recognized suffix,
9125 : : record it as explicit linker input. */
9126 : :
9127 : : else
9128 : 258773 : explicit_link_files[i] = 1;
9129 : :
9130 : : /* Clear the delete-on-failure queue, deleting the files in it
9131 : : if this compilation failed. */
9132 : :
9133 : 546038 : if (this_file_error)
9134 : : {
9135 : 29224 : delete_failure_queue ();
9136 : 29224 : errorcount++;
9137 : : }
9138 : : /* If this compilation succeeded, don't delete those files later. */
9139 : 546038 : clear_failure_queue ();
9140 : : }
9141 : :
9142 : : /* Reset the input file name to the first compile/object file name, for use
9143 : : with %b in LINK_SPEC. We use the first input file that we can find
9144 : : a compiler to compile it instead of using infiles.language since for
9145 : : languages other than C we use aliases that we then lookup later. */
9146 : 285337 : if (n_infiles > 0)
9147 : : {
9148 : : int i;
9149 : :
9150 : 297509 : for (i = 0; i < n_infiles ; i++)
9151 : 295621 : if (infiles[i].incompiler
9152 : 12172 : || (infiles[i].language && infiles[i].language[0] != '*'))
9153 : : {
9154 : 283449 : set_input (infiles[i].name);
9155 : 283449 : break;
9156 : : }
9157 : : }
9158 : :
9159 : 285337 : if (!seen_error ())
9160 : : {
9161 : : /* Make sure INPUT_FILE_NUMBER points to first available open
9162 : : slot. */
9163 : 256113 : input_file_number = n_infiles;
9164 : 256113 : if (lang_specific_pre_link ())
9165 : 0 : errorcount++;
9166 : : }
9167 : 285337 : }
9168 : :
9169 : : /* If we have to run the linker, do it now. */
9170 : :
9171 : : void
9172 : 285337 : driver::maybe_run_linker (const char *argv0) const
9173 : : {
9174 : 285337 : size_t i;
9175 : 285337 : int linker_was_run = 0;
9176 : 285337 : int num_linker_inputs;
9177 : :
9178 : : /* Determine if there are any linker input files. */
9179 : 285337 : num_linker_inputs = 0;
9180 : 840477 : for (i = 0; (int) i < n_infiles; i++)
9181 : 555140 : if (explicit_link_files[i] || outfiles[i] != NULL)
9182 : 545587 : num_linker_inputs++;
9183 : :
9184 : : /* Arrange for temporary file names created during linking to take
9185 : : on names related with the linker output rather than with the
9186 : : inputs when appropriate. */
9187 : 285337 : if (outbase && *outbase)
9188 : : {
9189 : 262217 : if (dumpdir)
9190 : : {
9191 : 88338 : char *tofree = dumpdir;
9192 : 88338 : gcc_checking_assert (strlen (dumpdir) == dumpdir_length);
9193 : 88338 : dumpdir = concat (dumpdir, outbase, ".", NULL);
9194 : 88338 : free (tofree);
9195 : : }
9196 : : else
9197 : 173879 : dumpdir = concat (outbase, ".", NULL);
9198 : 262217 : dumpdir_length += strlen (outbase) + 1;
9199 : 262217 : dumpdir_trailing_dash_added = true;
9200 : 262217 : }
9201 : 23120 : else if (dumpdir_trailing_dash_added)
9202 : : {
9203 : 18182 : gcc_assert (dumpdir[dumpdir_length - 1] == '-');
9204 : 18182 : dumpdir[dumpdir_length - 1] = '.';
9205 : : }
9206 : :
9207 : 285337 : if (dumpdir_trailing_dash_added)
9208 : : {
9209 : 280399 : gcc_assert (dumpdir_length > 0);
9210 : 280399 : gcc_assert (dumpdir[dumpdir_length - 1] == '.');
9211 : 280399 : dumpdir_length--;
9212 : : }
9213 : :
9214 : 285337 : free (outbase);
9215 : 285337 : input_basename = outbase = NULL;
9216 : 285337 : outbase_length = suffixed_basename_length = basename_length = 0;
9217 : :
9218 : : /* Run ld to link all the compiler output files. */
9219 : :
9220 : 285337 : if (num_linker_inputs > 0 && !seen_error () && print_subprocess_help < 2)
9221 : : {
9222 : 255566 : int tmp = execution_count;
9223 : :
9224 : 255566 : detect_jobserver ();
9225 : :
9226 : 255566 : if (! have_c)
9227 : : {
9228 : : #if HAVE_LTO_PLUGIN > 0
9229 : : #if HAVE_LTO_PLUGIN == 2
9230 : 96075 : const char *fno_use_linker_plugin = "fno-use-linker-plugin";
9231 : : #else
9232 : : const char *fuse_linker_plugin = "fuse-linker-plugin";
9233 : : #endif
9234 : : #endif
9235 : :
9236 : : /* We'll use ld if we can't find collect2. */
9237 : 96075 : if (! strcmp (linker_name_spec, "collect2"))
9238 : : {
9239 : 96075 : char *s = find_a_program ("collect2");
9240 : 96075 : if (s == NULL)
9241 : 1129 : set_static_spec_shared (&linker_name_spec, "ld");
9242 : : }
9243 : :
9244 : : #if HAVE_LTO_PLUGIN > 0
9245 : : #if HAVE_LTO_PLUGIN == 2
9246 : 96075 : if (!switch_matches (fno_use_linker_plugin,
9247 : : fno_use_linker_plugin
9248 : : + strlen (fno_use_linker_plugin), 0))
9249 : : #else
9250 : : if (switch_matches (fuse_linker_plugin,
9251 : : fuse_linker_plugin
9252 : : + strlen (fuse_linker_plugin), 0))
9253 : : #endif
9254 : : {
9255 : 90617 : char *temp_spec = find_a_file (&exec_prefixes,
9256 : : LTOPLUGINSONAME, R_OK,
9257 : : false);
9258 : 90617 : if (!temp_spec)
9259 : 0 : fatal_error (input_location,
9260 : : "%<-fuse-linker-plugin%>, but %s not found",
9261 : : LTOPLUGINSONAME);
9262 : 90617 : linker_plugin_file_spec = convert_white_space (temp_spec);
9263 : : }
9264 : : #endif
9265 : 96075 : set_static_spec_shared (<o_gcc_spec, argv0);
9266 : : }
9267 : :
9268 : : /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
9269 : : for collect. */
9270 : 255566 : putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH", false);
9271 : 255566 : putenv_from_prefixes (&startfile_prefixes, LIBRARY_PATH_ENV, true);
9272 : :
9273 : 255566 : if (print_subprocess_help == 1)
9274 : : {
9275 : 0 : printf (_("\nLinker options\n==============\n\n"));
9276 : 0 : printf (_("Use \"-Wl,OPTION\" to pass \"OPTION\""
9277 : : " to the linker.\n\n"));
9278 : 0 : fflush (stdout);
9279 : : }
9280 : 255566 : int value = do_spec (link_command_spec);
9281 : 255566 : if (value < 0)
9282 : 139 : errorcount = 1;
9283 : 255566 : linker_was_run = (tmp != execution_count);
9284 : : }
9285 : :
9286 : : /* If options said don't run linker,
9287 : : complain about input files to be given to the linker. */
9288 : :
9289 : 285337 : if (! linker_was_run && !seen_error ())
9290 : 352642 : for (i = 0; (int) i < n_infiles; i++)
9291 : 192600 : if (explicit_link_files[i]
9292 : 23471 : && !(infiles[i].language && infiles[i].language[0] == '*'))
9293 : : {
9294 : 38 : warning (0, "%s: linker input file unused because linking not done",
9295 : 19 : outfiles[i]);
9296 : 19 : if (access (outfiles[i], F_OK) < 0)
9297 : : /* This is can be an indication the user specifed an errorneous
9298 : : separated option value, (or used the wrong prefix for an
9299 : : option). */
9300 : 7 : error ("%s: linker input file not found: %m", outfiles[i]);
9301 : : }
9302 : 285337 : }
9303 : :
9304 : : /* The end of "main". */
9305 : :
9306 : : void
9307 : 285337 : driver::final_actions () const
9308 : : {
9309 : : /* Delete some or all of the temporary files we made. */
9310 : :
9311 : 285337 : if (seen_error ())
9312 : 29368 : delete_failure_queue ();
9313 : 285337 : delete_temp_files ();
9314 : :
9315 : 285337 : if (totruncate_file != NULL && !seen_error ())
9316 : : /* Truncate file specified by -truncate.
9317 : : Used by lto-wrapper to reduce temporary disk-space usage. */
9318 : 9050 : truncate(totruncate_file, 0);
9319 : :
9320 : 285337 : if (print_help_list)
9321 : : {
9322 : 3 : printf (("\nFor bug reporting instructions, please see:\n"));
9323 : 3 : printf ("%s\n", bug_report_url);
9324 : : }
9325 : 285337 : }
9326 : :
9327 : : /* Detect whether jobserver is active and working. If not drop
9328 : : --jobserver-auth from MAKEFLAGS. */
9329 : :
9330 : : void
9331 : 255566 : driver::detect_jobserver () const
9332 : : {
9333 : 255566 : jobserver_info jinfo;
9334 : 255566 : if (!jinfo.is_active && !jinfo.skipped_makeflags.empty ())
9335 : 0 : xputenv (xstrdup (jinfo.skipped_makeflags.c_str ()));
9336 : 255566 : }
9337 : :
9338 : : /* Determine what the exit code of the driver should be. */
9339 : :
9340 : : int
9341 : 285821 : driver::get_exit_code () const
9342 : : {
9343 : 285821 : return (signal_count != 0 ? 2
9344 : 285821 : : seen_error () ? (pass_exit_codes ? greatest_status : 1)
9345 : 0 : : 0);
9346 : : }
9347 : :
9348 : : /* Find the proper compilation spec for the file name NAME,
9349 : : whose length is LENGTH. LANGUAGE is the specified language,
9350 : : or 0 if this file is to be passed to the linker. */
9351 : :
9352 : : static struct compiler *
9353 : 1101178 : lookup_compiler (const char *name, size_t length, const char *language)
9354 : : {
9355 : 1610043 : struct compiler *cp;
9356 : :
9357 : : /* If this was specified by the user to be a linker input, indicate that. */
9358 : 1610043 : if (language != 0 && language[0] == '*')
9359 : : return 0;
9360 : :
9361 : : /* Otherwise, look for the language, if one is spec'd. */
9362 : 1140463 : if (language != 0)
9363 : : {
9364 : 23271473 : for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
9365 : 23271473 : if (cp->suffix[0] == '@' && !strcmp (cp->suffix + 1, language))
9366 : : {
9367 : 583618 : if (name != NULL && strcmp (name, "-") == 0
9368 : 2080 : && (strcmp (cp->suffix, "@c-header") == 0
9369 : 2080 : || strcmp (cp->suffix, "@c++-header") == 0)
9370 : 0 : && !have_E)
9371 : 0 : fatal_error (input_location,
9372 : : "cannot use %<-%> as input filename for a "
9373 : : "precompiled header");
9374 : :
9375 : : return cp;
9376 : : }
9377 : :
9378 : 0 : error ("language %s not recognized", language);
9379 : 0 : return 0;
9380 : : }
9381 : :
9382 : : /* Look for a suffix. */
9383 : 31034813 : for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
9384 : : {
9385 : 30986847 : if (/* The suffix `-' matches only the file name `-'. */
9386 : 30986847 : (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
9387 : 30986833 : || (strlen (cp->suffix) < length
9388 : : /* See if the suffix matches the end of NAME. */
9389 : 30509316 : && !strcmp (cp->suffix,
9390 : 30509316 : name + length - strlen (cp->suffix))
9391 : : ))
9392 : : break;
9393 : : }
9394 : :
9395 : : #if defined (OS2) ||defined (HAVE_DOS_BASED_FILE_SYSTEM)
9396 : : /* Look again, but case-insensitively this time. */
9397 : : if (cp < compilers)
9398 : : for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
9399 : : {
9400 : : if (/* The suffix `-' matches only the file name `-'. */
9401 : : (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
9402 : : || (strlen (cp->suffix) < length
9403 : : /* See if the suffix matches the end of NAME. */
9404 : : && ((!strcmp (cp->suffix,
9405 : : name + length - strlen (cp->suffix))
9406 : : || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
9407 : : && !strcasecmp (cp->suffix,
9408 : : name + length - strlen (cp->suffix)))
9409 : : ))
9410 : : break;
9411 : : }
9412 : : #endif
9413 : :
9414 : 556845 : if (cp >= compilers)
9415 : : {
9416 : 508879 : if (cp->spec[0] != '@')
9417 : : /* A non-alias entry: return it. */
9418 : : return cp;
9419 : :
9420 : : /* An alias entry maps a suffix to a language.
9421 : : Search for the language; pass 0 for NAME and LENGTH
9422 : : to avoid infinite recursion if language not found. */
9423 : 508865 : return lookup_compiler (NULL, 0, cp->spec + 1);
9424 : : }
9425 : : return 0;
9426 : : }
9427 : :
9428 : : static char *
9429 : 46549679 : save_string (const char *s, int len)
9430 : : {
9431 : 46549679 : char *result = XNEWVEC (char, len + 1);
9432 : :
9433 : 46549679 : gcc_checking_assert (strlen (s) >= (unsigned int) len);
9434 : 46549679 : memcpy (result, s, len);
9435 : 46549679 : result[len] = 0;
9436 : 46549679 : return result;
9437 : : }
9438 : :
9439 : :
9440 : : static inline void
9441 : 46398165 : validate_switches_from_spec (const char *spec, bool user)
9442 : : {
9443 : 46398165 : const char *p = spec;
9444 : 46398165 : char c;
9445 : 572643162 : while ((c = *p++))
9446 : 479846832 : if (c == '%'
9447 : 479846832 : && (*p == '{'
9448 : 11375034 : || *p == '<'
9449 : 10477005 : || (*p == 'W' && *++p == '{')
9450 : 10477005 : || (*p == '@' && *++p == '{')))
9451 : : /* We have a switch spec. */
9452 : 46098824 : p = validate_switches (p + 1, user, *p == '{');
9453 : 46398165 : }
9454 : :
9455 : : static void
9456 : 299343 : validate_all_switches (void)
9457 : : {
9458 : 299343 : struct compiler *comp;
9459 : 299343 : struct spec_list *spec;
9460 : :
9461 : 32628387 : for (comp = compilers; comp->spec; comp++)
9462 : 32329044 : validate_switches_from_spec (comp->spec, false);
9463 : :
9464 : : /* Look through the linked list of specs read from the specs file. */
9465 : 14069121 : for (spec = specs; spec; spec = spec->next)
9466 : 13769778 : validate_switches_from_spec (*spec->ptr_spec, spec->user_p);
9467 : :
9468 : 299343 : validate_switches_from_spec (link_command_spec, false);
9469 : 299343 : }
9470 : :
9471 : : /* Look at the switch-name that comes after START and mark as valid
9472 : : all supplied switches that match it. If BRACED, handle other
9473 : : switches after '|' and '&', and specs after ':' until ';' or '}',
9474 : : going back for more switches after ';'. Without BRACED, handle
9475 : : only one atom. Return a pointer to whatever follows the handled
9476 : : items, after the closing brace if BRACED. */
9477 : :
9478 : : static const char *
9479 : 199362440 : validate_switches (const char *start, bool user_spec, bool braced)
9480 : : {
9481 : 199362440 : const char *p = start;
9482 : 257135639 : const char *atom;
9483 : 257135639 : size_t len;
9484 : 257135639 : int i;
9485 : 257135639 : bool suffix;
9486 : 257135639 : bool starred;
9487 : :
9488 : : #define SKIP_WHITE() do { while (*p == ' ' || *p == '\t') p++; } while (0)
9489 : :
9490 : 257135639 : next_member:
9491 : 257135639 : suffix = false;
9492 : 257135639 : starred = false;
9493 : :
9494 : 284076509 : SKIP_WHITE ();
9495 : :
9496 : 257135639 : if (*p == '!')
9497 : 79625239 : p++;
9498 : :
9499 : 257135639 : SKIP_WHITE ();
9500 : 257135639 : if (*p == '.' || *p == ',')
9501 : 0 : suffix = true, p++;
9502 : :
9503 : 257135639 : atom = p;
9504 : 257135639 : while (ISIDNUM (*p) || *p == '-' || *p == '+' || *p == '='
9505 : 1721521609 : || *p == ',' || *p == '.' || *p == '@')
9506 : 1464385970 : p++;
9507 : 257135639 : len = p - atom;
9508 : :
9509 : 257135639 : if (*p == '*')
9510 : 67950861 : starred = true, p++;
9511 : :
9512 : 258333011 : SKIP_WHITE ();
9513 : :
9514 : 257135639 : if (!suffix)
9515 : : {
9516 : : /* Mark all matching switches as valid. */
9517 : 6076620149 : for (i = 0; i < n_switches; i++)
9518 : 5819484510 : if (!strncmp (switches[i].part1, atom, len)
9519 : 484052892 : && (starred || switches[i].part1[len] == '\0')
9520 : 50353074 : && (switches[i].known || user_spec))
9521 : 50350464 : switches[i].validated = true;
9522 : : }
9523 : :
9524 : 257135639 : if (!braced)
9525 : : return p;
9526 : :
9527 : 255638924 : if (*p) p++;
9528 : 255638924 : if (*p && (p[-1] == '|' || p[-1] == '&'))
9529 : 39513276 : goto next_member;
9530 : :
9531 : 216125648 : if (*p && p[-1] == ':')
9532 : : {
9533 : 2919192932 : while (*p && *p != ';' && *p != '}')
9534 : : {
9535 : 2752458878 : if (*p == '%')
9536 : : {
9537 : 257434980 : p++;
9538 : 257434980 : if (*p == '{' || *p == '<')
9539 : 150569529 : p = validate_switches (p+1, user_spec, *p == '{');
9540 : 106865451 : else if (p[0] == 'W' && p[1] == '{')
9541 : 2394744 : p = validate_switches (p+2, user_spec, true);
9542 : 104470707 : else if (p[0] == '@' && p[1] == '{')
9543 : 299343 : p = validate_switches (p+2, user_spec, true);
9544 : : }
9545 : : else
9546 : 2495023898 : p++;
9547 : : }
9548 : :
9549 : 166734054 : if (*p) p++;
9550 : 166734054 : if (*p && p[-1] == ';')
9551 : 18259923 : goto next_member;
9552 : : }
9553 : :
9554 : : return p;
9555 : : #undef SKIP_WHITE
9556 : : }
9557 : :
9558 : : struct mdswitchstr
9559 : : {
9560 : : const char *str;
9561 : : int len;
9562 : : };
9563 : :
9564 : : static struct mdswitchstr *mdswitches;
9565 : : static int n_mdswitches;
9566 : :
9567 : : /* Check whether a particular argument was used. The first time we
9568 : : canonicalize the switches to keep only the ones we care about. */
9569 : :
9570 : : struct used_arg_t
9571 : : {
9572 : : public:
9573 : : int operator () (const char *p, int len);
9574 : : void finalize ();
9575 : :
9576 : : private:
9577 : : struct mswitchstr
9578 : : {
9579 : : const char *str;
9580 : : const char *replace;
9581 : : int len;
9582 : : int rep_len;
9583 : : };
9584 : :
9585 : : mswitchstr *mswitches;
9586 : : int n_mswitches;
9587 : :
9588 : : };
9589 : :
9590 : : used_arg_t used_arg;
9591 : :
9592 : : int
9593 : 1809449 : used_arg_t::operator () (const char *p, int len)
9594 : : {
9595 : 1809449 : int i, j;
9596 : :
9597 : 1809449 : if (!mswitches)
9598 : : {
9599 : 299343 : struct mswitchstr *matches;
9600 : 299343 : const char *q;
9601 : 299343 : int cnt = 0;
9602 : :
9603 : : /* Break multilib_matches into the component strings of string
9604 : : and replacement string. */
9605 : 5088831 : for (q = multilib_matches; *q != '\0'; q++)
9606 : 4789488 : if (*q == ';')
9607 : 598686 : cnt++;
9608 : :
9609 : 299343 : matches
9610 : 299343 : = (struct mswitchstr *) alloca ((sizeof (struct mswitchstr)) * cnt);
9611 : 299343 : i = 0;
9612 : 299343 : q = multilib_matches;
9613 : 898029 : while (*q != '\0')
9614 : : {
9615 : 598686 : matches[i].str = q;
9616 : 2394744 : while (*q != ' ')
9617 : : {
9618 : 1796058 : if (*q == '\0')
9619 : : {
9620 : 0 : invalid_matches:
9621 : 0 : fatal_error (input_location, "multilib spec %qs is invalid",
9622 : : multilib_matches);
9623 : : }
9624 : 1796058 : q++;
9625 : : }
9626 : 598686 : matches[i].len = q - matches[i].str;
9627 : :
9628 : 598686 : matches[i].replace = ++q;
9629 : 2394744 : while (*q != ';' && *q != '\0')
9630 : : {
9631 : 1796058 : if (*q == ' ')
9632 : 0 : goto invalid_matches;
9633 : 1796058 : q++;
9634 : : }
9635 : 598686 : matches[i].rep_len = q - matches[i].replace;
9636 : 598686 : i++;
9637 : 598686 : if (*q == ';')
9638 : 598686 : q++;
9639 : : }
9640 : :
9641 : : /* Now build a list of the replacement string for switches that we care
9642 : : about. Make sure we allocate at least one entry. This prevents
9643 : : xmalloc from calling fatal, and prevents us from re-executing this
9644 : : block of code. */
9645 : 299343 : mswitches
9646 : 598686 : = XNEWVEC (struct mswitchstr, n_mdswitches + (n_switches ? n_switches : 1));
9647 : 7074063 : for (i = 0; i < n_switches; i++)
9648 : 6774720 : if ((switches[i].live_cond & SWITCH_IGNORE) == 0)
9649 : : {
9650 : 6774714 : int xlen = strlen (switches[i].part1);
9651 : 20311354 : for (j = 0; j < cnt; j++)
9652 : 13546991 : if (xlen == matches[j].len
9653 : 19087 : && ! strncmp (switches[i].part1, matches[j].str, xlen))
9654 : : {
9655 : 10351 : mswitches[n_mswitches].str = matches[j].replace;
9656 : 10351 : mswitches[n_mswitches].len = matches[j].rep_len;
9657 : 10351 : mswitches[n_mswitches].replace = (char *) 0;
9658 : 10351 : mswitches[n_mswitches].rep_len = 0;
9659 : 10351 : n_mswitches++;
9660 : 10351 : break;
9661 : : }
9662 : : }
9663 : :
9664 : : /* Add MULTILIB_DEFAULTS switches too, as long as they were not present
9665 : : on the command line nor any options mutually incompatible with
9666 : : them. */
9667 : 598686 : for (i = 0; i < n_mdswitches; i++)
9668 : : {
9669 : 299343 : const char *r;
9670 : :
9671 : 598686 : for (q = multilib_options; *q != '\0'; *q && q++)
9672 : : {
9673 : 299343 : while (*q == ' ')
9674 : 0 : q++;
9675 : :
9676 : 299343 : r = q;
9677 : 299343 : while (strncmp (q, mdswitches[i].str, mdswitches[i].len) != 0
9678 : 299343 : || strchr (" /", q[mdswitches[i].len]) == NULL)
9679 : : {
9680 : 0 : while (*q != ' ' && *q != '/' && *q != '\0')
9681 : 0 : q++;
9682 : 0 : if (*q != '/')
9683 : : break;
9684 : 0 : q++;
9685 : : }
9686 : :
9687 : 299343 : if (*q != ' ' && *q != '\0')
9688 : : {
9689 : 596249 : while (*r != ' ' && *r != '\0')
9690 : : {
9691 : : q = r;
9692 : 2384996 : while (*q != ' ' && *q != '/' && *q != '\0')
9693 : 1788747 : q++;
9694 : :
9695 : 596249 : if (used_arg (r, q - r))
9696 : : break;
9697 : :
9698 : 585898 : if (*q != '/')
9699 : : {
9700 : 288992 : mswitches[n_mswitches].str = mdswitches[i].str;
9701 : 288992 : mswitches[n_mswitches].len = mdswitches[i].len;
9702 : 288992 : mswitches[n_mswitches].replace = (char *) 0;
9703 : 288992 : mswitches[n_mswitches].rep_len = 0;
9704 : 288992 : n_mswitches++;
9705 : 288992 : break;
9706 : : }
9707 : :
9708 : 296906 : r = q + 1;
9709 : : }
9710 : : break;
9711 : : }
9712 : : }
9713 : : }
9714 : : }
9715 : :
9716 : 2423963 : for (i = 0; i < n_mswitches; i++)
9717 : 1231465 : if (len == mswitches[i].len && ! strncmp (p, mswitches[i].str, len))
9718 : : return 1;
9719 : :
9720 : : return 0;
9721 : : }
9722 : :
9723 : 1134 : void used_arg_t::finalize ()
9724 : : {
9725 : 1134 : XDELETEVEC (mswitches);
9726 : 1134 : mswitches = NULL;
9727 : 1134 : n_mswitches = 0;
9728 : 1134 : }
9729 : :
9730 : :
9731 : : static int
9732 : 1230968 : default_arg (const char *p, int len)
9733 : : {
9734 : 1230968 : int i;
9735 : :
9736 : 1842010 : for (i = 0; i < n_mdswitches; i++)
9737 : 1230968 : if (len == mdswitches[i].len && ! strncmp (p, mdswitches[i].str, len))
9738 : : return 1;
9739 : :
9740 : : return 0;
9741 : : }
9742 : :
9743 : : /* Use multilib_dir as key to find corresponding multilib_os_dir and
9744 : : multiarch_dir. */
9745 : :
9746 : : static void
9747 : 0 : find_multilib_os_dir_by_multilib_dir (const char *multilib_dir,
9748 : : const char **p_multilib_os_dir,
9749 : : const char **p_multiarch_dir)
9750 : : {
9751 : 0 : const char *p = multilib_select;
9752 : 0 : unsigned int this_path_len;
9753 : 0 : const char *this_path;
9754 : 0 : int ok = 0;
9755 : :
9756 : 0 : while (*p != '\0')
9757 : : {
9758 : : /* Ignore newlines. */
9759 : 0 : if (*p == '\n')
9760 : : {
9761 : 0 : ++p;
9762 : 0 : continue;
9763 : : }
9764 : :
9765 : : /* Get the initial path. */
9766 : : this_path = p;
9767 : 0 : while (*p != ' ')
9768 : : {
9769 : 0 : if (*p == '\0')
9770 : : {
9771 : 0 : fatal_error (input_location, "multilib select %qs %qs is invalid",
9772 : : multilib_select, multilib_reuse);
9773 : : }
9774 : 0 : ++p;
9775 : : }
9776 : 0 : this_path_len = p - this_path;
9777 : :
9778 : 0 : ok = 0;
9779 : :
9780 : : /* Skip any arguments, we don't care at this stage. */
9781 : 0 : while (*++p != ';');
9782 : :
9783 : 0 : if (this_path_len != 1
9784 : 0 : || this_path[0] != '.')
9785 : : {
9786 : 0 : char *new_multilib_dir = XNEWVEC (char, this_path_len + 1);
9787 : 0 : char *q;
9788 : :
9789 : 0 : strncpy (new_multilib_dir, this_path, this_path_len);
9790 : 0 : new_multilib_dir[this_path_len] = '\0';
9791 : 0 : q = strchr (new_multilib_dir, ':');
9792 : 0 : if (q != NULL)
9793 : 0 : *q = '\0';
9794 : :
9795 : 0 : if (strcmp (new_multilib_dir, multilib_dir) == 0)
9796 : 0 : ok = 1;
9797 : : }
9798 : :
9799 : : /* Found matched multilib_dir, update multilib_os_dir and
9800 : : multiarch_dir. */
9801 : 0 : if (ok)
9802 : : {
9803 : 0 : const char *q = this_path, *end = this_path + this_path_len;
9804 : :
9805 : 0 : while (q < end && *q != ':')
9806 : 0 : q++;
9807 : 0 : if (q < end)
9808 : : {
9809 : 0 : const char *q2 = q + 1, *ml_end = end;
9810 : 0 : char *new_multilib_os_dir;
9811 : :
9812 : 0 : while (q2 < end && *q2 != ':')
9813 : 0 : q2++;
9814 : 0 : if (*q2 == ':')
9815 : 0 : ml_end = q2;
9816 : 0 : if (ml_end - q == 1)
9817 : 0 : *p_multilib_os_dir = xstrdup (".");
9818 : : else
9819 : : {
9820 : 0 : new_multilib_os_dir = XNEWVEC (char, ml_end - q);
9821 : 0 : memcpy (new_multilib_os_dir, q + 1, ml_end - q - 1);
9822 : 0 : new_multilib_os_dir[ml_end - q - 1] = '\0';
9823 : 0 : *p_multilib_os_dir = new_multilib_os_dir;
9824 : : }
9825 : :
9826 : 0 : if (q2 < end && *q2 == ':')
9827 : : {
9828 : 0 : char *new_multiarch_dir = XNEWVEC (char, end - q2);
9829 : 0 : memcpy (new_multiarch_dir, q2 + 1, end - q2 - 1);
9830 : 0 : new_multiarch_dir[end - q2 - 1] = '\0';
9831 : 0 : *p_multiarch_dir = new_multiarch_dir;
9832 : : }
9833 : : break;
9834 : : }
9835 : : }
9836 : 0 : ++p;
9837 : : }
9838 : 0 : }
9839 : :
9840 : : /* Work out the subdirectory to use based on the options. The format of
9841 : : multilib_select is a list of elements. Each element is a subdirectory
9842 : : name followed by a list of options followed by a semicolon. The format
9843 : : of multilib_exclusions is the same, but without the preceding
9844 : : directory. First gcc will check the exclusions, if none of the options
9845 : : beginning with an exclamation point are present, and all of the other
9846 : : options are present, then we will ignore this completely. Passing
9847 : : that, gcc will consider each multilib_select in turn using the same
9848 : : rules for matching the options. If a match is found, that subdirectory
9849 : : will be used.
9850 : : A subdirectory name is optionally followed by a colon and the corresponding
9851 : : multiarch name. */
9852 : :
9853 : : static void
9854 : 299343 : set_multilib_dir (void)
9855 : : {
9856 : 299343 : const char *p;
9857 : 299343 : unsigned int this_path_len;
9858 : 299343 : const char *this_path, *this_arg;
9859 : 299343 : const char *start, *end;
9860 : 299343 : int not_arg;
9861 : 299343 : int ok, ndfltok, first;
9862 : :
9863 : 299343 : n_mdswitches = 0;
9864 : 299343 : start = multilib_defaults;
9865 : 299343 : while (*start == ' ' || *start == '\t')
9866 : 0 : start++;
9867 : 598686 : while (*start != '\0')
9868 : : {
9869 : 299343 : n_mdswitches++;
9870 : 1197372 : while (*start != ' ' && *start != '\t' && *start != '\0')
9871 : 898029 : start++;
9872 : 299343 : while (*start == ' ' || *start == '\t')
9873 : 0 : start++;
9874 : : }
9875 : :
9876 : 299343 : if (n_mdswitches)
9877 : : {
9878 : 299343 : int i = 0;
9879 : :
9880 : 299343 : mdswitches = XNEWVEC (struct mdswitchstr, n_mdswitches);
9881 : 299343 : for (start = multilib_defaults; *start != '\0'; start = end + 1)
9882 : : {
9883 : 299343 : while (*start == ' ' || *start == '\t')
9884 : 0 : start++;
9885 : :
9886 : 299343 : if (*start == '\0')
9887 : : break;
9888 : :
9889 : 898029 : for (end = start + 1;
9890 : 898029 : *end != ' ' && *end != '\t' && *end != '\0'; end++)
9891 : : ;
9892 : :
9893 : 299343 : obstack_grow (&multilib_obstack, start, end - start);
9894 : 299343 : obstack_1grow (&multilib_obstack, 0);
9895 : 299343 : mdswitches[i].str = XOBFINISH (&multilib_obstack, const char *);
9896 : 299343 : mdswitches[i++].len = end - start;
9897 : :
9898 : 299343 : if (*end == '\0')
9899 : : break;
9900 : : }
9901 : : }
9902 : :
9903 : 299343 : p = multilib_exclusions;
9904 : 299343 : while (*p != '\0')
9905 : : {
9906 : : /* Ignore newlines. */
9907 : 0 : if (*p == '\n')
9908 : : {
9909 : 0 : ++p;
9910 : 0 : continue;
9911 : : }
9912 : :
9913 : : /* Check the arguments. */
9914 : : ok = 1;
9915 : 0 : while (*p != ';')
9916 : : {
9917 : 0 : if (*p == '\0')
9918 : : {
9919 : 0 : invalid_exclusions:
9920 : 0 : fatal_error (input_location, "multilib exclusions %qs is invalid",
9921 : : multilib_exclusions);
9922 : : }
9923 : :
9924 : 0 : if (! ok)
9925 : : {
9926 : 0 : ++p;
9927 : 0 : continue;
9928 : : }
9929 : :
9930 : 0 : this_arg = p;
9931 : 0 : while (*p != ' ' && *p != ';')
9932 : : {
9933 : 0 : if (*p == '\0')
9934 : 0 : goto invalid_exclusions;
9935 : 0 : ++p;
9936 : : }
9937 : :
9938 : 0 : if (*this_arg != '!')
9939 : : not_arg = 0;
9940 : : else
9941 : : {
9942 : 0 : not_arg = 1;
9943 : 0 : ++this_arg;
9944 : : }
9945 : :
9946 : 0 : ok = used_arg (this_arg, p - this_arg);
9947 : 0 : if (not_arg)
9948 : 0 : ok = ! ok;
9949 : :
9950 : 0 : if (*p == ' ')
9951 : 0 : ++p;
9952 : : }
9953 : :
9954 : 0 : if (ok)
9955 : : return;
9956 : :
9957 : 0 : ++p;
9958 : : }
9959 : :
9960 : 299343 : first = 1;
9961 : 299343 : p = multilib_select;
9962 : :
9963 : : /* Append multilib reuse rules if any. With those rules, we can reuse
9964 : : one multilib for certain different options sets. */
9965 : 299343 : if (strlen (multilib_reuse) > 0)
9966 : 0 : p = concat (p, multilib_reuse, NULL);
9967 : :
9968 : 606600 : while (*p != '\0')
9969 : : {
9970 : : /* Ignore newlines. */
9971 : 606600 : if (*p == '\n')
9972 : : {
9973 : 0 : ++p;
9974 : 0 : continue;
9975 : : }
9976 : :
9977 : : /* Get the initial path. */
9978 : : this_path = p;
9979 : 4269942 : while (*p != ' ')
9980 : : {
9981 : 3663342 : if (*p == '\0')
9982 : : {
9983 : 0 : invalid_select:
9984 : 0 : fatal_error (input_location, "multilib select %qs %qs is invalid",
9985 : : multilib_select, multilib_reuse);
9986 : : }
9987 : 3663342 : ++p;
9988 : : }
9989 : 606600 : this_path_len = p - this_path;
9990 : :
9991 : : /* Check the arguments. */
9992 : 606600 : ok = 1;
9993 : 606600 : ndfltok = 1;
9994 : 606600 : ++p;
9995 : 1819800 : while (*p != ';')
9996 : : {
9997 : 1213200 : if (*p == '\0')
9998 : 0 : goto invalid_select;
9999 : :
10000 : 1213200 : if (! ok)
10001 : : {
10002 : 0 : ++p;
10003 : 0 : continue;
10004 : : }
10005 : :
10006 : 5758743 : this_arg = p;
10007 : 5758743 : while (*p != ' ' && *p != ';')
10008 : : {
10009 : 4545543 : if (*p == '\0')
10010 : 0 : goto invalid_select;
10011 : 4545543 : ++p;
10012 : : }
10013 : :
10014 : 1213200 : if (*this_arg != '!')
10015 : : not_arg = 0;
10016 : : else
10017 : : {
10018 : 905943 : not_arg = 1;
10019 : 905943 : ++this_arg;
10020 : : }
10021 : :
10022 : : /* If this is a default argument, we can just ignore it.
10023 : : This is true even if this_arg begins with '!'. Beginning
10024 : : with '!' does not mean that this argument is necessarily
10025 : : inappropriate for this library: it merely means that
10026 : : there is a more specific library which uses this
10027 : : argument. If this argument is a default, we need not
10028 : : consider that more specific library. */
10029 : 1213200 : ok = used_arg (this_arg, p - this_arg);
10030 : 1213200 : if (not_arg)
10031 : 905943 : ok = ! ok;
10032 : :
10033 : 1213200 : if (! ok)
10034 : 315171 : ndfltok = 0;
10035 : :
10036 : 1213200 : if (default_arg (this_arg, p - this_arg))
10037 : 606600 : ok = 1;
10038 : :
10039 : 1213200 : if (*p == ' ')
10040 : 606600 : ++p;
10041 : : }
10042 : :
10043 : 606600 : if (ok && first)
10044 : : {
10045 : 299343 : if (this_path_len != 1
10046 : 291429 : || this_path[0] != '.')
10047 : : {
10048 : 7914 : char *new_multilib_dir = XNEWVEC (char, this_path_len + 1);
10049 : 7914 : char *q;
10050 : :
10051 : 7914 : strncpy (new_multilib_dir, this_path, this_path_len);
10052 : 7914 : new_multilib_dir[this_path_len] = '\0';
10053 : 7914 : q = strchr (new_multilib_dir, ':');
10054 : 7914 : if (q != NULL)
10055 : 7914 : *q = '\0';
10056 : 7914 : multilib_dir = new_multilib_dir;
10057 : : }
10058 : : first = 0;
10059 : : }
10060 : :
10061 : 606600 : if (ndfltok)
10062 : : {
10063 : 299343 : const char *q = this_path, *end = this_path + this_path_len;
10064 : :
10065 : 898029 : while (q < end && *q != ':')
10066 : 598686 : q++;
10067 : 299343 : if (q < end)
10068 : : {
10069 : 299343 : const char *q2 = q + 1, *ml_end = end;
10070 : 299343 : char *new_multilib_os_dir;
10071 : :
10072 : 2678259 : while (q2 < end && *q2 != ':')
10073 : 2378916 : q2++;
10074 : 299343 : if (*q2 == ':')
10075 : 0 : ml_end = q2;
10076 : 299343 : if (ml_end - q == 1)
10077 : 0 : multilib_os_dir = xstrdup (".");
10078 : : else
10079 : : {
10080 : 299343 : new_multilib_os_dir = XNEWVEC (char, ml_end - q);
10081 : 299343 : memcpy (new_multilib_os_dir, q + 1, ml_end - q - 1);
10082 : 299343 : new_multilib_os_dir[ml_end - q - 1] = '\0';
10083 : 299343 : multilib_os_dir = new_multilib_os_dir;
10084 : : }
10085 : :
10086 : 299343 : if (q2 < end && *q2 == ':')
10087 : : {
10088 : 0 : char *new_multiarch_dir = XNEWVEC (char, end - q2);
10089 : 0 : memcpy (new_multiarch_dir, q2 + 1, end - q2 - 1);
10090 : 0 : new_multiarch_dir[end - q2 - 1] = '\0';
10091 : 0 : multiarch_dir = new_multiarch_dir;
10092 : : }
10093 : : break;
10094 : : }
10095 : : }
10096 : :
10097 : 307257 : ++p;
10098 : : }
10099 : :
10100 : 598686 : multilib_dir =
10101 : 299343 : targetm_common.compute_multilib (
10102 : : switches,
10103 : : n_switches,
10104 : : multilib_dir,
10105 : : multilib_defaults,
10106 : : multilib_select,
10107 : : multilib_matches,
10108 : : multilib_exclusions,
10109 : : multilib_reuse);
10110 : :
10111 : 299343 : if (multilib_dir == NULL && multilib_os_dir != NULL
10112 : 291429 : && strcmp (multilib_os_dir, ".") == 0)
10113 : : {
10114 : 0 : free (CONST_CAST (char *, multilib_os_dir));
10115 : 0 : multilib_os_dir = NULL;
10116 : : }
10117 : 299343 : else if (multilib_dir != NULL && multilib_os_dir == NULL)
10118 : : {
10119 : : /* Give second chance to search matched multilib_os_dir again by matching
10120 : : the multilib_dir since some target may use TARGET_COMPUTE_MULTILIB
10121 : : hook rather than the builtin way. */
10122 : 0 : find_multilib_os_dir_by_multilib_dir (multilib_dir, &multilib_os_dir,
10123 : : &multiarch_dir);
10124 : :
10125 : 0 : if (multilib_os_dir == NULL)
10126 : 0 : multilib_os_dir = multilib_dir;
10127 : : }
10128 : : }
10129 : :
10130 : : /* Print out the multiple library subdirectory selection
10131 : : information. This prints out a series of lines. Each line looks
10132 : : like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
10133 : : required. Only the desired options are printed out, the negative
10134 : : matches. The options are print without a leading dash. There are
10135 : : no spaces to make it easy to use the information in the shell.
10136 : : Each subdirectory is printed only once. This assumes the ordering
10137 : : generated by the genmultilib script. Also, we leave out ones that match
10138 : : the exclusions. */
10139 : :
10140 : : static void
10141 : 4442 : print_multilib_info (void)
10142 : : {
10143 : 4442 : const char *p = multilib_select;
10144 : 4442 : const char *last_path = 0, *this_path;
10145 : 4442 : int skip;
10146 : 4442 : int not_arg;
10147 : 4442 : unsigned int last_path_len = 0;
10148 : :
10149 : 17768 : while (*p != '\0')
10150 : : {
10151 : 13326 : skip = 0;
10152 : : /* Ignore newlines. */
10153 : 13326 : if (*p == '\n')
10154 : : {
10155 : 0 : ++p;
10156 : 0 : continue;
10157 : : }
10158 : :
10159 : : /* Get the initial path. */
10160 : : this_path = p;
10161 : 106608 : while (*p != ' ')
10162 : : {
10163 : 93282 : if (*p == '\0')
10164 : : {
10165 : 0 : invalid_select:
10166 : 0 : fatal_error (input_location,
10167 : : "multilib select %qs is invalid", multilib_select);
10168 : : }
10169 : :
10170 : 93282 : ++p;
10171 : : }
10172 : :
10173 : : /* When --disable-multilib was used but target defines
10174 : : MULTILIB_OSDIRNAMES, entries starting with .: (and not starting
10175 : : with .:: for multiarch configurations) are there just to find
10176 : : multilib_os_dir, so skip them from output. */
10177 : 13326 : if (this_path[0] == '.' && this_path[1] == ':' && this_path[2] != ':')
10178 : 13326 : skip = 1;
10179 : :
10180 : : /* Check for matches with the multilib_exclusions. We don't bother
10181 : : with the '!' in either list. If any of the exclusion rules match
10182 : : all of its options with the select rule, we skip it. */
10183 : 13326 : {
10184 : 13326 : const char *e = multilib_exclusions;
10185 : 13326 : const char *this_arg;
10186 : :
10187 : 13326 : while (*e != '\0')
10188 : : {
10189 : 0 : int m = 1;
10190 : : /* Ignore newlines. */
10191 : 0 : if (*e == '\n')
10192 : : {
10193 : 0 : ++e;
10194 : 0 : continue;
10195 : : }
10196 : :
10197 : : /* Check the arguments. */
10198 : 0 : while (*e != ';')
10199 : : {
10200 : 0 : const char *q;
10201 : 0 : int mp = 0;
10202 : :
10203 : 0 : if (*e == '\0')
10204 : : {
10205 : 0 : invalid_exclusion:
10206 : 0 : fatal_error (input_location,
10207 : : "multilib exclusion %qs is invalid",
10208 : : multilib_exclusions);
10209 : : }
10210 : :
10211 : 0 : if (! m)
10212 : : {
10213 : 0 : ++e;
10214 : 0 : continue;
10215 : : }
10216 : :
10217 : : this_arg = e;
10218 : :
10219 : 0 : while (*e != ' ' && *e != ';')
10220 : : {
10221 : 0 : if (*e == '\0')
10222 : 0 : goto invalid_exclusion;
10223 : 0 : ++e;
10224 : : }
10225 : :
10226 : 0 : q = p + 1;
10227 : 0 : while (*q != ';')
10228 : : {
10229 : 0 : const char *arg;
10230 : 0 : int len = e - this_arg;
10231 : :
10232 : 0 : if (*q == '\0')
10233 : 0 : goto invalid_select;
10234 : :
10235 : : arg = q;
10236 : :
10237 : 0 : while (*q != ' ' && *q != ';')
10238 : : {
10239 : 0 : if (*q == '\0')
10240 : 0 : goto invalid_select;
10241 : 0 : ++q;
10242 : : }
10243 : :
10244 : 0 : if (! strncmp (arg, this_arg,
10245 : 0 : (len < q - arg) ? q - arg : len)
10246 : 0 : || default_arg (this_arg, e - this_arg))
10247 : : {
10248 : : mp = 1;
10249 : : break;
10250 : : }
10251 : :
10252 : 0 : if (*q == ' ')
10253 : 0 : ++q;
10254 : : }
10255 : :
10256 : 0 : if (! mp)
10257 : 0 : m = 0;
10258 : :
10259 : 0 : if (*e == ' ')
10260 : 0 : ++e;
10261 : : }
10262 : :
10263 : 0 : if (m)
10264 : : {
10265 : : skip = 1;
10266 : : break;
10267 : : }
10268 : :
10269 : 0 : if (*e != '\0')
10270 : 0 : ++e;
10271 : : }
10272 : : }
10273 : :
10274 : 13326 : if (! skip)
10275 : : {
10276 : : /* If this is a duplicate, skip it. */
10277 : 26652 : skip = (last_path != 0
10278 : 8884 : && (unsigned int) (p - this_path) == last_path_len
10279 : 13326 : && ! filename_ncmp (last_path, this_path, last_path_len));
10280 : :
10281 : 13326 : last_path = this_path;
10282 : 13326 : last_path_len = p - this_path;
10283 : : }
10284 : :
10285 : : /* If all required arguments are default arguments, and no default
10286 : : arguments appear in the ! argument list, then we can skip it.
10287 : : We will already have printed a directory identical to this one
10288 : : which does not require that default argument. */
10289 : 13326 : if (! skip)
10290 : : {
10291 : 13326 : const char *q;
10292 : 13326 : bool default_arg_ok = false;
10293 : :
10294 : 13326 : q = p + 1;
10295 : 22210 : while (*q != ';')
10296 : : {
10297 : 17768 : const char *arg;
10298 : :
10299 : 17768 : if (*q == '\0')
10300 : 0 : goto invalid_select;
10301 : :
10302 : 17768 : if (*q == '!')
10303 : : {
10304 : 13326 : not_arg = 1;
10305 : 13326 : q++;
10306 : : }
10307 : : else
10308 : : not_arg = 0;
10309 : 17768 : arg = q;
10310 : :
10311 : 71072 : while (*q != ' ' && *q != ';')
10312 : : {
10313 : 53304 : if (*q == '\0')
10314 : 0 : goto invalid_select;
10315 : 53304 : ++q;
10316 : : }
10317 : :
10318 : 17768 : if (default_arg (arg, q - arg))
10319 : : {
10320 : : /* Stop checking if any default arguments appeared in not
10321 : : list. */
10322 : 13326 : if (not_arg)
10323 : : {
10324 : : default_arg_ok = false;
10325 : : break;
10326 : : }
10327 : :
10328 : : default_arg_ok = true;
10329 : : }
10330 : 4442 : else if (!not_arg)
10331 : : {
10332 : : /* Stop checking if any required argument is not provided by
10333 : : default arguments. */
10334 : : default_arg_ok = false;
10335 : : break;
10336 : : }
10337 : :
10338 : 8884 : if (*q == ' ')
10339 : 4442 : ++q;
10340 : : }
10341 : :
10342 : : /* Make sure all default argument is OK for this multi-lib set. */
10343 : 13326 : if (default_arg_ok)
10344 : : skip = 1;
10345 : : else
10346 : : skip = 0;
10347 : : }
10348 : :
10349 : : if (! skip)
10350 : : {
10351 : : const char *p1;
10352 : :
10353 : 22210 : for (p1 = last_path; p1 < p && *p1 != ':'; p1++)
10354 : 13326 : putchar (*p1);
10355 : 8884 : putchar (';');
10356 : : }
10357 : :
10358 : 13326 : ++p;
10359 : 66630 : while (*p != ';')
10360 : : {
10361 : 53304 : int use_arg;
10362 : :
10363 : 53304 : if (*p == '\0')
10364 : 0 : goto invalid_select;
10365 : :
10366 : 53304 : if (skip)
10367 : : {
10368 : 35536 : ++p;
10369 : 35536 : continue;
10370 : : }
10371 : :
10372 : 17768 : use_arg = *p != '!';
10373 : :
10374 : 17768 : if (use_arg)
10375 : 4442 : putchar ('@');
10376 : :
10377 : 84398 : while (*p != ' ' && *p != ';')
10378 : : {
10379 : 66630 : if (*p == '\0')
10380 : 0 : goto invalid_select;
10381 : 66630 : if (use_arg)
10382 : 13326 : putchar (*p);
10383 : 66630 : ++p;
10384 : : }
10385 : :
10386 : 17768 : if (*p == ' ')
10387 : 8884 : ++p;
10388 : : }
10389 : :
10390 : 13326 : if (! skip)
10391 : : {
10392 : : /* If there are extra options, print them now. */
10393 : 8884 : if (multilib_extra && *multilib_extra)
10394 : : {
10395 : : int print_at = true;
10396 : : const char *q;
10397 : :
10398 : 0 : for (q = multilib_extra; *q != '\0'; q++)
10399 : : {
10400 : 0 : if (*q == ' ')
10401 : : print_at = true;
10402 : : else
10403 : : {
10404 : 0 : if (print_at)
10405 : 0 : putchar ('@');
10406 : 0 : putchar (*q);
10407 : 0 : print_at = false;
10408 : : }
10409 : : }
10410 : : }
10411 : :
10412 : 8884 : putchar ('\n');
10413 : : }
10414 : :
10415 : 13326 : ++p;
10416 : : }
10417 : 4442 : }
10418 : :
10419 : : /* getenv built-in spec function.
10420 : :
10421 : : Returns the value of the environment variable given by its first argument,
10422 : : concatenated with the second argument. If the variable is not defined, a
10423 : : fatal error is issued unless such undefs are internally allowed, in which
10424 : : case the variable name prefixed by a '/' is used as the variable value.
10425 : :
10426 : : The leading '/' allows using the result at a spot where a full path would
10427 : : normally be expected and when the actual value doesn't really matter since
10428 : : undef vars are allowed. */
10429 : :
10430 : : static const char *
10431 : 0 : getenv_spec_function (int argc, const char **argv)
10432 : : {
10433 : 0 : const char *value;
10434 : 0 : const char *varname;
10435 : :
10436 : 0 : char *result;
10437 : 0 : char *ptr;
10438 : 0 : size_t len;
10439 : :
10440 : 0 : if (argc != 2)
10441 : : return NULL;
10442 : :
10443 : 0 : varname = argv[0];
10444 : 0 : value = env.get (varname);
10445 : :
10446 : : /* If the variable isn't defined and this is allowed, craft our expected
10447 : : return value. Assume variable names used in specs strings don't contain
10448 : : any active spec character so don't need escaping. */
10449 : 0 : if (!value && spec_undefvar_allowed)
10450 : : {
10451 : 0 : result = XNEWVAR (char, strlen(varname) + 2);
10452 : 0 : sprintf (result, "/%s", varname);
10453 : 0 : return result;
10454 : : }
10455 : :
10456 : 0 : if (!value)
10457 : 0 : fatal_error (input_location,
10458 : : "environment variable %qs not defined", varname);
10459 : :
10460 : : /* We have to escape every character of the environment variable so
10461 : : they are not interpreted as active spec characters. A
10462 : : particularly painful case is when we are reading a variable
10463 : : holding a windows path complete with \ separators. */
10464 : 0 : len = strlen (value) * 2 + strlen (argv[1]) + 1;
10465 : 0 : result = XNEWVAR (char, len);
10466 : 0 : for (ptr = result; *value; ptr += 2)
10467 : : {
10468 : 0 : ptr[0] = '\\';
10469 : 0 : ptr[1] = *value++;
10470 : : }
10471 : :
10472 : 0 : strcpy (ptr, argv[1]);
10473 : :
10474 : 0 : return result;
10475 : : }
10476 : :
10477 : : /* if-exists built-in spec function.
10478 : :
10479 : : Checks to see if the file specified by the absolute pathname in
10480 : : ARGS exists. Returns that pathname if found.
10481 : :
10482 : : The usual use for this function is to check for a library file
10483 : : (whose name has been expanded with %s). */
10484 : :
10485 : : static const char *
10486 : 0 : if_exists_spec_function (int argc, const char **argv)
10487 : : {
10488 : : /* Must have only one argument. */
10489 : 0 : if (argc == 1 && IS_ABSOLUTE_PATH (argv[0]) && ! access (argv[0], R_OK))
10490 : 0 : return argv[0];
10491 : :
10492 : : return NULL;
10493 : : }
10494 : :
10495 : : /* if-exists-else built-in spec function.
10496 : :
10497 : : This is like if-exists, but takes an additional argument which
10498 : : is returned if the first argument does not exist. */
10499 : :
10500 : : static const char *
10501 : 0 : if_exists_else_spec_function (int argc, const char **argv)
10502 : : {
10503 : : /* Must have exactly two arguments. */
10504 : 0 : if (argc != 2)
10505 : : return NULL;
10506 : :
10507 : 0 : if (IS_ABSOLUTE_PATH (argv[0]) && ! access (argv[0], R_OK))
10508 : 0 : return argv[0];
10509 : :
10510 : 0 : return argv[1];
10511 : : }
10512 : :
10513 : : /* if-exists-then-else built-in spec function.
10514 : :
10515 : : Checks to see if the file specified by the absolute pathname in
10516 : : the first arg exists. Returns the second arg if so, otherwise returns
10517 : : the third arg if it is present. */
10518 : :
10519 : : static const char *
10520 : 0 : if_exists_then_else_spec_function (int argc, const char **argv)
10521 : : {
10522 : :
10523 : : /* Must have two or three arguments. */
10524 : 0 : if (argc != 2 && argc != 3)
10525 : : return NULL;
10526 : :
10527 : 0 : if (IS_ABSOLUTE_PATH (argv[0]) && ! access (argv[0], R_OK))
10528 : 0 : return argv[1];
10529 : :
10530 : 0 : if (argc == 3)
10531 : 0 : return argv[2];
10532 : :
10533 : : return NULL;
10534 : : }
10535 : :
10536 : : /* sanitize built-in spec function.
10537 : :
10538 : : This returns non-NULL, if sanitizing address, thread or
10539 : : any of the undefined behavior sanitizers. */
10540 : :
10541 : : static const char *
10542 : 862776 : sanitize_spec_function (int argc, const char **argv)
10543 : : {
10544 : 862776 : if (argc != 1)
10545 : : return NULL;
10546 : :
10547 : 862776 : if (strcmp (argv[0], "address") == 0)
10548 : 380750 : return (flag_sanitize & SANITIZE_USER_ADDRESS) ? "" : NULL;
10549 : 671048 : if (strcmp (argv[0], "hwaddress") == 0)
10550 : 383146 : return (flag_sanitize & SANITIZE_USER_HWADDRESS) ? "" : NULL;
10551 : 479320 : if (strcmp (argv[0], "kernel-address") == 0)
10552 : 0 : return (flag_sanitize & SANITIZE_KERNEL_ADDRESS) ? "" : NULL;
10553 : 479320 : if (strcmp (argv[0], "kernel-hwaddress") == 0)
10554 : 0 : return (flag_sanitize & SANITIZE_KERNEL_HWADDRESS) ? "" : NULL;
10555 : 479320 : if (strcmp (argv[0], "thread") == 0)
10556 : 382936 : return (flag_sanitize & SANITIZE_THREAD) ? "" : NULL;
10557 : 287592 : if (strcmp (argv[0], "undefined") == 0)
10558 : 95864 : return ((flag_sanitize
10559 : 95864 : & ~flag_sanitize_trap
10560 : 95864 : & (SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT)))
10561 : 189858 : ? "" : NULL;
10562 : 191728 : if (strcmp (argv[0], "leak") == 0)
10563 : 191728 : return ((flag_sanitize
10564 : 191728 : & (SANITIZE_ADDRESS | SANITIZE_LEAK | SANITIZE_THREAD))
10565 : 383456 : == SANITIZE_LEAK) ? "" : NULL;
10566 : : return NULL;
10567 : : }
10568 : :
10569 : : /* replace-outfile built-in spec function.
10570 : :
10571 : : This looks for the first argument in the outfiles array's name and
10572 : : replaces it with the second argument. */
10573 : :
10574 : : static const char *
10575 : 0 : replace_outfile_spec_function (int argc, const char **argv)
10576 : : {
10577 : 0 : int i;
10578 : : /* Must have exactly two arguments. */
10579 : 0 : if (argc != 2)
10580 : 0 : abort ();
10581 : :
10582 : 0 : for (i = 0; i < n_infiles; i++)
10583 : : {
10584 : 0 : if (outfiles[i] && !filename_cmp (outfiles[i], argv[0]))
10585 : 0 : outfiles[i] = xstrdup (argv[1]);
10586 : : }
10587 : 0 : return NULL;
10588 : : }
10589 : :
10590 : : /* remove-outfile built-in spec function.
10591 : : *
10592 : : * This looks for the first argument in the outfiles array's name and
10593 : : * removes it. */
10594 : :
10595 : : static const char *
10596 : 0 : remove_outfile_spec_function (int argc, const char **argv)
10597 : : {
10598 : 0 : int i;
10599 : : /* Must have exactly one argument. */
10600 : 0 : if (argc != 1)
10601 : 0 : abort ();
10602 : :
10603 : 0 : for (i = 0; i < n_infiles; i++)
10604 : : {
10605 : 0 : if (outfiles[i] && !filename_cmp (outfiles[i], argv[0]))
10606 : 0 : outfiles[i] = NULL;
10607 : : }
10608 : 0 : return NULL;
10609 : : }
10610 : :
10611 : : /* Given two version numbers, compares the two numbers.
10612 : : A version number must match the regular expression
10613 : : ([1-9][0-9]*|0)(\.([1-9][0-9]*|0))*
10614 : : */
10615 : : static int
10616 : 0 : compare_version_strings (const char *v1, const char *v2)
10617 : : {
10618 : 0 : int rresult;
10619 : 0 : regex_t r;
10620 : :
10621 : 0 : if (regcomp (&r, "^([1-9][0-9]*|0)(\\.([1-9][0-9]*|0))*$",
10622 : : REG_EXTENDED | REG_NOSUB) != 0)
10623 : 0 : abort ();
10624 : 0 : rresult = regexec (&r, v1, 0, NULL, 0);
10625 : 0 : if (rresult == REG_NOMATCH)
10626 : 0 : fatal_error (input_location, "invalid version number %qs", v1);
10627 : 0 : else if (rresult != 0)
10628 : 0 : abort ();
10629 : 0 : rresult = regexec (&r, v2, 0, NULL, 0);
10630 : 0 : if (rresult == REG_NOMATCH)
10631 : 0 : fatal_error (input_location, "invalid version number %qs", v2);
10632 : 0 : else if (rresult != 0)
10633 : 0 : abort ();
10634 : :
10635 : 0 : return strverscmp (v1, v2);
10636 : : }
10637 : :
10638 : :
10639 : : /* version_compare built-in spec function.
10640 : :
10641 : : This takes an argument of the following form:
10642 : :
10643 : : <comparison-op> <arg1> [<arg2>] <switch> <result>
10644 : :
10645 : : and produces "result" if the comparison evaluates to true,
10646 : : and nothing if it doesn't.
10647 : :
10648 : : The supported <comparison-op> values are:
10649 : :
10650 : : >= true if switch is a later (or same) version than arg1
10651 : : !> opposite of >=
10652 : : < true if switch is an earlier version than arg1
10653 : : !< opposite of <
10654 : : >< true if switch is arg1 or later, and earlier than arg2
10655 : : <> true if switch is earlier than arg1 or is arg2 or later
10656 : :
10657 : : If the switch is not present, the condition is false unless
10658 : : the first character of the <comparison-op> is '!'.
10659 : :
10660 : : For example,
10661 : : %:version-compare(>= 10.3 mmacosx-version-min= -lmx)
10662 : : adds -lmx if -mmacosx-version-min=10.3.9 was passed. */
10663 : :
10664 : : static const char *
10665 : 0 : version_compare_spec_function (int argc, const char **argv)
10666 : : {
10667 : 0 : int comp1, comp2;
10668 : 0 : size_t switch_len;
10669 : 0 : const char *switch_value = NULL;
10670 : 0 : int nargs = 1, i;
10671 : 0 : bool result;
10672 : :
10673 : 0 : if (argc < 3)
10674 : 0 : fatal_error (input_location, "too few arguments to %%:version-compare");
10675 : 0 : if (argv[0][0] == '\0')
10676 : 0 : abort ();
10677 : 0 : if ((argv[0][1] == '<' || argv[0][1] == '>') && argv[0][0] != '!')
10678 : 0 : nargs = 2;
10679 : 0 : if (argc != nargs + 3)
10680 : 0 : fatal_error (input_location, "too many arguments to %%:version-compare");
10681 : :
10682 : 0 : switch_len = strlen (argv[nargs + 1]);
10683 : 0 : for (i = 0; i < n_switches; i++)
10684 : 0 : if (!strncmp (switches[i].part1, argv[nargs + 1], switch_len)
10685 : 0 : && check_live_switch (i, switch_len))
10686 : 0 : switch_value = switches[i].part1 + switch_len;
10687 : :
10688 : 0 : if (switch_value == NULL)
10689 : : comp1 = comp2 = -1;
10690 : : else
10691 : : {
10692 : 0 : comp1 = compare_version_strings (switch_value, argv[1]);
10693 : 0 : if (nargs == 2)
10694 : 0 : comp2 = compare_version_strings (switch_value, argv[2]);
10695 : : else
10696 : : comp2 = -1; /* This value unused. */
10697 : : }
10698 : :
10699 : 0 : switch (argv[0][0] << 8 | argv[0][1])
10700 : : {
10701 : 0 : case '>' << 8 | '=':
10702 : 0 : result = comp1 >= 0;
10703 : 0 : break;
10704 : 0 : case '!' << 8 | '<':
10705 : 0 : result = comp1 >= 0 || switch_value == NULL;
10706 : 0 : break;
10707 : 0 : case '<' << 8:
10708 : 0 : result = comp1 < 0;
10709 : 0 : break;
10710 : 0 : case '!' << 8 | '>':
10711 : 0 : result = comp1 < 0 || switch_value == NULL;
10712 : 0 : break;
10713 : 0 : case '>' << 8 | '<':
10714 : 0 : result = comp1 >= 0 && comp2 < 0;
10715 : 0 : break;
10716 : 0 : case '<' << 8 | '>':
10717 : 0 : result = comp1 < 0 || comp2 >= 0;
10718 : 0 : break;
10719 : :
10720 : 0 : default:
10721 : 0 : fatal_error (input_location,
10722 : : "unknown operator %qs in %%:version-compare", argv[0]);
10723 : : }
10724 : 0 : if (! result)
10725 : : return NULL;
10726 : :
10727 : 0 : return argv[nargs + 2];
10728 : : }
10729 : :
10730 : : /* %:include builtin spec function. This differs from %include in that it
10731 : : can be nested inside a spec, and thus be conditionalized. It takes
10732 : : one argument, the filename, and looks for it in the startfile path.
10733 : : The result is always NULL, i.e. an empty expansion. */
10734 : :
10735 : : static const char *
10736 : 30632 : include_spec_function (int argc, const char **argv)
10737 : : {
10738 : 30632 : char *file;
10739 : :
10740 : 30632 : if (argc != 1)
10741 : 0 : abort ();
10742 : :
10743 : 30632 : file = find_a_file (&startfile_prefixes, argv[0], R_OK, true);
10744 : 30632 : read_specs (file ? file : argv[0], false, false);
10745 : :
10746 : 30632 : return NULL;
10747 : : }
10748 : :
10749 : : /* %:find-file spec function. This function replaces its argument by
10750 : : the file found through find_file, that is the -print-file-name gcc
10751 : : program option. */
10752 : : static const char *
10753 : 0 : find_file_spec_function (int argc, const char **argv)
10754 : : {
10755 : 0 : const char *file;
10756 : :
10757 : 0 : if (argc != 1)
10758 : 0 : abort ();
10759 : :
10760 : 0 : file = find_file (argv[0]);
10761 : 0 : return file;
10762 : : }
10763 : :
10764 : :
10765 : : /* %:find-plugindir spec function. This function replaces its argument
10766 : : by the -iplugindir=<dir> option. `dir' is found through find_file, that
10767 : : is the -print-file-name gcc program option. */
10768 : : static const char *
10769 : 400 : find_plugindir_spec_function (int argc, const char **argv ATTRIBUTE_UNUSED)
10770 : : {
10771 : 400 : const char *option;
10772 : :
10773 : 400 : if (argc != 0)
10774 : 0 : abort ();
10775 : :
10776 : 400 : option = concat ("-iplugindir=", find_file ("plugin"), NULL);
10777 : 400 : return option;
10778 : : }
10779 : :
10780 : :
10781 : : /* %:print-asm-header spec function. Print a banner to say that the
10782 : : following output is from the assembler. */
10783 : :
10784 : : static const char *
10785 : 0 : print_asm_header_spec_function (int arg ATTRIBUTE_UNUSED,
10786 : : const char **argv ATTRIBUTE_UNUSED)
10787 : : {
10788 : 0 : printf (_("Assembler options\n=================\n\n"));
10789 : 0 : printf (_("Use \"-Wa,OPTION\" to pass \"OPTION\" to the assembler.\n\n"));
10790 : 0 : fflush (stdout);
10791 : 0 : return NULL;
10792 : : }
10793 : :
10794 : : /* Get a random number for -frandom-seed */
10795 : :
10796 : : static unsigned HOST_WIDE_INT
10797 : 620 : get_random_number (void)
10798 : : {
10799 : 620 : unsigned HOST_WIDE_INT ret = 0;
10800 : 620 : int fd;
10801 : :
10802 : 620 : fd = open ("/dev/urandom", O_RDONLY);
10803 : 620 : if (fd >= 0)
10804 : : {
10805 : 620 : read (fd, &ret, sizeof (HOST_WIDE_INT));
10806 : 620 : close (fd);
10807 : 620 : if (ret)
10808 : : return ret;
10809 : : }
10810 : :
10811 : : /* Get some more or less random data. */
10812 : : #ifdef HAVE_GETTIMEOFDAY
10813 : 0 : {
10814 : 0 : struct timeval tv;
10815 : :
10816 : 0 : gettimeofday (&tv, NULL);
10817 : 0 : ret = tv.tv_sec * 1000 + tv.tv_usec / 1000;
10818 : : }
10819 : : #else
10820 : : {
10821 : : time_t now = time (NULL);
10822 : :
10823 : : if (now != (time_t)-1)
10824 : : ret = (unsigned) now;
10825 : : }
10826 : : #endif
10827 : :
10828 : 0 : return ret ^ getpid ();
10829 : : }
10830 : :
10831 : : /* %:compare-debug-dump-opt spec function. Save the last argument,
10832 : : expected to be the last -fdump-final-insns option, or generate a
10833 : : temporary. */
10834 : :
10835 : : static const char *
10836 : 1233 : compare_debug_dump_opt_spec_function (int arg,
10837 : : const char **argv ATTRIBUTE_UNUSED)
10838 : : {
10839 : 1233 : char *ret;
10840 : 1233 : char *name;
10841 : 1233 : int which;
10842 : 1233 : static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
10843 : :
10844 : 1233 : if (arg != 0)
10845 : 0 : fatal_error (input_location,
10846 : : "too many arguments to %%:compare-debug-dump-opt");
10847 : :
10848 : 1233 : do_spec_2 ("%{fdump-final-insns=*:%*}", NULL);
10849 : 1233 : do_spec_1 (" ", 0, NULL);
10850 : :
10851 : 1233 : if (argbuf.length () > 0
10852 : 1233 : && strcmp (argv[argbuf.length () - 1], ".") != 0)
10853 : : {
10854 : 0 : if (!compare_debug)
10855 : : return NULL;
10856 : :
10857 : 0 : name = xstrdup (argv[argbuf.length () - 1]);
10858 : 0 : ret = NULL;
10859 : : }
10860 : : else
10861 : : {
10862 : 1233 : if (argbuf.length () > 0)
10863 : 6 : do_spec_2 ("%B.gkd", NULL);
10864 : 1227 : else if (!compare_debug)
10865 : : return NULL;
10866 : : else
10867 : 1227 : do_spec_2 ("%{!save-temps*:%g.gkd}%{save-temps*:%B.gkd}", NULL);
10868 : :
10869 : 1233 : do_spec_1 (" ", 0, NULL);
10870 : :
10871 : 1233 : gcc_assert (argbuf.length () > 0);
10872 : :
10873 : 1233 : name = xstrdup (argbuf.last ());
10874 : :
10875 : 1233 : char *arg = quote_spec (xstrdup (name));
10876 : 1233 : ret = concat ("-fdump-final-insns=", arg, NULL);
10877 : 1233 : free (arg);
10878 : : }
10879 : :
10880 : 1233 : which = compare_debug < 0;
10881 : 1233 : debug_check_temp_file[which] = name;
10882 : :
10883 : 1233 : if (!which)
10884 : : {
10885 : 620 : unsigned HOST_WIDE_INT value = get_random_number ();
10886 : :
10887 : 620 : sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
10888 : : }
10889 : :
10890 : 1233 : if (*random_seed)
10891 : : {
10892 : 1233 : char *tmp = ret;
10893 : 1233 : ret = concat ("%{!frandom-seed=*:-frandom-seed=", random_seed, "} ",
10894 : : ret, NULL);
10895 : 1233 : free (tmp);
10896 : : }
10897 : :
10898 : 1233 : if (which)
10899 : 613 : *random_seed = 0;
10900 : :
10901 : : return ret;
10902 : : }
10903 : :
10904 : : /* %:compare-debug-self-opt spec function. Expands to the options
10905 : : that are to be passed in the second compilation of
10906 : : compare-debug. */
10907 : :
10908 : : static const char *
10909 : 1238 : compare_debug_self_opt_spec_function (int arg,
10910 : : const char **argv ATTRIBUTE_UNUSED)
10911 : : {
10912 : 1238 : if (arg != 0)
10913 : 0 : fatal_error (input_location,
10914 : : "too many arguments to %%:compare-debug-self-opt");
10915 : :
10916 : 1238 : if (compare_debug >= 0)
10917 : : return NULL;
10918 : :
10919 : 619 : return concat ("\
10920 : : %<o %<MD %<MMD %<MF* %<MG %<MP %<MQ* %<MT* \
10921 : : %<fdump-final-insns=* -w -S -o %j \
10922 : : %{!fcompare-debug-second:-fcompare-debug-second} \
10923 : 619 : ", compare_debug_opt, NULL);
10924 : : }
10925 : :
10926 : : /* %:pass-through-libs spec function. Finds all -l options and input
10927 : : file names in the lib spec passed to it, and makes a list of them
10928 : : prepended with the plugin option to cause them to be passed through
10929 : : to the final link after all the new object files have been added. */
10930 : :
10931 : : const char *
10932 : 90415 : pass_through_libs_spec_func (int argc, const char **argv)
10933 : : {
10934 : 90415 : char *prepended = xstrdup (" ");
10935 : 90415 : int n;
10936 : : /* Shlemiel the painter's algorithm. Innately horrible, but at least
10937 : : we know that there will never be more than a handful of strings to
10938 : : concat, and it's only once per run, so it's not worth optimising. */
10939 : 1228557 : for (n = 0; n < argc; n++)
10940 : : {
10941 : 1138142 : char *old = prepended;
10942 : : /* Anything that isn't an option is a full path to an output
10943 : : file; pass it through if it ends in '.a'. Among options,
10944 : : pass only -l. */
10945 : 1138142 : if (argv[n][0] == '-' && argv[n][1] == 'l')
10946 : : {
10947 : 590600 : const char *lopt = argv[n] + 2;
10948 : : /* Handle both joined and non-joined -l options. If for any
10949 : : reason there's a trailing -l with no joined or following
10950 : : arg just discard it. */
10951 : 590600 : if (!*lopt && ++n >= argc)
10952 : : break;
10953 : 590600 : else if (!*lopt)
10954 : 0 : lopt = argv[n];
10955 : 590600 : prepended = concat (prepended, "-plugin-opt=-pass-through=-l",
10956 : : lopt, " ", NULL);
10957 : 590600 : }
10958 : 547542 : else if (!strcmp (".a", argv[n] + strlen (argv[n]) - 2))
10959 : : {
10960 : 0 : prepended = concat (prepended, "-plugin-opt=-pass-through=",
10961 : : argv[n], " ", NULL);
10962 : : }
10963 : 1138142 : if (prepended != old)
10964 : 590600 : free (old);
10965 : : }
10966 : 90415 : return prepended;
10967 : : }
10968 : :
10969 : : static bool
10970 : 519361 : not_actual_file_p (const char *name)
10971 : : {
10972 : 519361 : return (strcmp (name, "-") == 0
10973 : 519361 : || strcmp (name, HOST_BIT_BUCKET) == 0);
10974 : : }
10975 : :
10976 : : /* %:dumps spec function. Take an optional argument that overrides
10977 : : the default extension for -dumpbase and -dumpbase-ext.
10978 : : Return -dumpdir, -dumpbase and -dumpbase-ext, if needed. */
10979 : : const char *
10980 : 285026 : dumps_spec_func (int argc, const char **argv ATTRIBUTE_UNUSED)
10981 : : {
10982 : 285026 : const char *ext = dumpbase_ext;
10983 : 285026 : char *p;
10984 : :
10985 : 285026 : char *args[3] = { NULL, NULL, NULL };
10986 : 285026 : int nargs = 0;
10987 : :
10988 : : /* Do not compute a default for -dumpbase-ext when -dumpbase was
10989 : : given explicitly. */
10990 : 285026 : if (dumpbase && *dumpbase && !ext)
10991 : 285026 : ext = "";
10992 : :
10993 : 285026 : if (argc == 1)
10994 : : {
10995 : : /* Do not override the explicitly-specified -dumpbase-ext with
10996 : : the specs-provided overrider. */
10997 : 0 : if (!ext)
10998 : 0 : ext = argv[0];
10999 : : }
11000 : 285026 : else if (argc != 0)
11001 : 0 : fatal_error (input_location, "too many arguments for %%:dumps");
11002 : :
11003 : 285026 : if (dumpdir)
11004 : : {
11005 : 105644 : p = quote_spec_arg (xstrdup (dumpdir));
11006 : 105644 : args[nargs++] = concat (" -dumpdir ", p, NULL);
11007 : 105644 : free (p);
11008 : : }
11009 : :
11010 : 285026 : if (!ext)
11011 : 262952 : ext = input_basename + basename_length;
11012 : :
11013 : : /* Use the precomputed outbase, or compute dumpbase from
11014 : : input_basename, just like %b would. */
11015 : 285026 : char *base;
11016 : :
11017 : 285026 : if (dumpbase && *dumpbase)
11018 : : {
11019 : 22074 : base = xstrdup (dumpbase);
11020 : 22074 : p = base + outbase_length;
11021 : 22074 : gcc_checking_assert (strncmp (base, outbase, outbase_length) == 0);
11022 : 22074 : gcc_checking_assert (strcmp (p, ext) == 0);
11023 : : }
11024 : 262952 : else if (outbase_length)
11025 : : {
11026 : 162268 : base = xstrndup (outbase, outbase_length);
11027 : 162268 : p = NULL;
11028 : : }
11029 : : else
11030 : : {
11031 : 100684 : base = xstrndup (input_basename, suffixed_basename_length);
11032 : 100684 : p = base + basename_length;
11033 : : }
11034 : :
11035 : 285026 : if (compare_debug < 0 || !p || strcmp (p, ext) != 0)
11036 : : {
11037 : 613 : if (p)
11038 : 9 : *p = '\0';
11039 : :
11040 : 162277 : const char *gk;
11041 : 162277 : if (compare_debug < 0)
11042 : : gk = ".gk";
11043 : : else
11044 : 161664 : gk = "";
11045 : :
11046 : 162277 : p = concat (base, gk, ext, NULL);
11047 : :
11048 : 162277 : free (base);
11049 : 162277 : base = p;
11050 : : }
11051 : :
11052 : 285026 : base = quote_spec_arg (base);
11053 : 285026 : args[nargs++] = concat (" -dumpbase ", base, NULL);
11054 : 285026 : free (base);
11055 : :
11056 : 285026 : if (*ext)
11057 : : {
11058 : 261910 : p = quote_spec_arg (xstrdup (ext));
11059 : 261910 : args[nargs++] = concat (" -dumpbase-ext ", p, NULL);
11060 : 261910 : free (p);
11061 : : }
11062 : :
11063 : 285026 : const char *ret = concat (args[0], args[1], args[2], NULL);
11064 : 1222632 : while (nargs > 0)
11065 : 652580 : free (args[--nargs]);
11066 : :
11067 : 285026 : return ret;
11068 : : }
11069 : :
11070 : : /* Returns "" if ARGV[ARGC - 2] is greater than ARGV[ARGC-1].
11071 : : Otherwise, return NULL. */
11072 : :
11073 : : static const char *
11074 : 395415 : greater_than_spec_func (int argc, const char **argv)
11075 : : {
11076 : 395415 : char *converted;
11077 : :
11078 : 395415 : if (argc == 1)
11079 : : return NULL;
11080 : :
11081 : 252 : gcc_assert (argc >= 2);
11082 : :
11083 : 252 : long arg = strtol (argv[argc - 2], &converted, 10);
11084 : 252 : gcc_assert (converted != argv[argc - 2]);
11085 : :
11086 : 252 : long lim = strtol (argv[argc - 1], &converted, 10);
11087 : 252 : gcc_assert (converted != argv[argc - 1]);
11088 : :
11089 : 252 : if (arg > lim)
11090 : : return "";
11091 : :
11092 : : return NULL;
11093 : : }
11094 : :
11095 : : /* Returns "" if debug_info_level is greater than ARGV[ARGC-1].
11096 : : Otherwise, return NULL. */
11097 : :
11098 : : static const char *
11099 : 253903 : debug_level_greater_than_spec_func (int argc, const char **argv)
11100 : : {
11101 : 253903 : char *converted;
11102 : :
11103 : 253903 : if (argc != 1)
11104 : 0 : fatal_error (input_location,
11105 : : "wrong number of arguments to %%:debug-level-gt");
11106 : :
11107 : 253903 : long arg = strtol (argv[0], &converted, 10);
11108 : 253903 : gcc_assert (converted != argv[0]);
11109 : :
11110 : 253903 : if (debug_info_level > arg)
11111 : 45531 : return "";
11112 : :
11113 : : return NULL;
11114 : : }
11115 : :
11116 : : /* Returns "" if dwarf_version is greater than ARGV[ARGC-1].
11117 : : Otherwise, return NULL. */
11118 : :
11119 : : static const char *
11120 : 128886 : dwarf_version_greater_than_spec_func (int argc, const char **argv)
11121 : : {
11122 : 128886 : char *converted;
11123 : :
11124 : 128886 : if (argc != 1)
11125 : 0 : fatal_error (input_location,
11126 : : "wrong number of arguments to %%:dwarf-version-gt");
11127 : :
11128 : 128886 : long arg = strtol (argv[0], &converted, 10);
11129 : 128886 : gcc_assert (converted != argv[0]);
11130 : :
11131 : 128886 : if (dwarf_version > arg)
11132 : 128015 : return "";
11133 : :
11134 : : return NULL;
11135 : : }
11136 : :
11137 : : static void
11138 : 34358 : path_prefix_reset (path_prefix *prefix)
11139 : : {
11140 : 34358 : struct prefix_list *iter, *next;
11141 : 34358 : iter = prefix->plist;
11142 : 136298 : while (iter)
11143 : : {
11144 : 101940 : next = iter->next;
11145 : 101940 : free (const_cast <char *> (iter->prefix));
11146 : 101940 : XDELETE (iter);
11147 : 101940 : iter = next;
11148 : : }
11149 : 34358 : prefix->plist = 0;
11150 : 34358 : prefix->max_len = 0;
11151 : 34358 : }
11152 : :
11153 : : /* The function takes 3 arguments: OPTION name, file name and location
11154 : : where we search for Fortran modules.
11155 : : When the FILE is found by find_file, return OPTION=path_to_file. */
11156 : :
11157 : : static const char *
11158 : 30956 : find_fortran_preinclude_file (int argc, const char **argv)
11159 : : {
11160 : 30956 : char *result = NULL;
11161 : 30956 : if (argc != 3)
11162 : : return NULL;
11163 : :
11164 : 30956 : struct path_prefix prefixes = { 0, 0, "preinclude" };
11165 : :
11166 : : /* Search first for 'finclude' folder location for a header file
11167 : : installed by the compiler (similar to omp_lib.h). */
11168 : 30956 : add_prefix (&prefixes, argv[2], NULL, 0, 0, 0);
11169 : : #ifdef TOOL_INCLUDE_DIR
11170 : : /* Then search: <prefix>/<target>/<include>/finclude */
11171 : 30956 : add_prefix (&prefixes, TOOL_INCLUDE_DIR "/finclude/",
11172 : : NULL, 0, 0, 0);
11173 : : #endif
11174 : : #ifdef NATIVE_SYSTEM_HEADER_DIR
11175 : : /* Then search: <sysroot>/usr/include/finclude/<multilib> */
11176 : 30956 : add_sysrooted_hdrs_prefix (&prefixes, NATIVE_SYSTEM_HEADER_DIR "/finclude/",
11177 : : NULL, 0, 0, 0);
11178 : : #endif
11179 : :
11180 : 30956 : const char *path = find_a_file (&include_prefixes, argv[1], R_OK, false);
11181 : 30956 : if (path != NULL)
11182 : 0 : result = concat (argv[0], path, NULL);
11183 : : else
11184 : : {
11185 : 30956 : path = find_a_file (&prefixes, argv[1], R_OK, false);
11186 : 30956 : if (path != NULL)
11187 : 30956 : result = concat (argv[0], path, NULL);
11188 : : }
11189 : :
11190 : 30956 : path_prefix_reset (&prefixes);
11191 : 30956 : return result;
11192 : : }
11193 : :
11194 : : /* The function takes any number of arguments and joins them together.
11195 : :
11196 : : This seems to be necessary to build "-fjoined=foo.b" from "-fseparate foo.a"
11197 : : with a %{fseparate*:-fjoined=%.b$*} rule without adding undesired spaces:
11198 : : when doing $* replacement we first replace $* with the rest of the switch
11199 : : (in this case ""), and then add any arguments as arguments after the result,
11200 : : resulting in "-fjoined= foo.b". Using this function with e.g.
11201 : : %{fseparate*:-fjoined=%:join(%.b$*)} gets multiple words as separate argv
11202 : : elements instead of separated by spaces, and we paste them together. */
11203 : :
11204 : : static const char *
11205 : 39 : join_spec_func (int argc, const char **argv)
11206 : : {
11207 : 39 : if (argc == 1)
11208 : 0 : return argv[0];
11209 : 117 : for (int i = 0; i < argc; ++i)
11210 : 78 : obstack_grow (&obstack, argv[i], strlen (argv[i]));
11211 : 39 : obstack_1grow (&obstack, '\0');
11212 : 39 : return XOBFINISH (&obstack, const char *);
11213 : : }
11214 : :
11215 : : /* If any character in ORIG fits QUOTE_P (_, P), reallocate the string
11216 : : so as to precede every one of them with a backslash. Return the
11217 : : original string or the reallocated one. */
11218 : :
11219 : : static inline char *
11220 : 852005 : quote_string (char *orig, bool (*quote_p)(char, void *), void *p)
11221 : : {
11222 : 852005 : int len, number_of_space = 0;
11223 : :
11224 : 19352090 : for (len = 0; orig[len]; len++)
11225 : 18500085 : if (quote_p (orig[len], p))
11226 : 0 : number_of_space++;
11227 : :
11228 : 852005 : if (number_of_space)
11229 : : {
11230 : 0 : char *new_spec = (char *) xmalloc (len + number_of_space + 1);
11231 : 0 : int j, k;
11232 : 0 : for (j = 0, k = 0; j <= len; j++, k++)
11233 : : {
11234 : 0 : if (quote_p (orig[j], p))
11235 : 0 : new_spec[k++] = '\\';
11236 : 0 : new_spec[k] = orig[j];
11237 : : }
11238 : 0 : free (orig);
11239 : 0 : return new_spec;
11240 : : }
11241 : : else
11242 : : return orig;
11243 : : }
11244 : :
11245 : : /* Return true iff C is any of the characters convert_white_space
11246 : : should quote. */
11247 : :
11248 : : static inline bool
11249 : 12252703 : whitespace_to_convert_p (char c, void *)
11250 : : {
11251 : 12252703 : return (c == ' ' || c == '\t');
11252 : : }
11253 : :
11254 : : /* Insert backslash before spaces in ORIG (usually a file path), to
11255 : : avoid being broken by spec parser.
11256 : :
11257 : : This function is needed as do_spec_1 treats white space (' ' and '\t')
11258 : : as the end of an argument. But in case of -plugin /usr/gcc install/xxx.so,
11259 : : the file name should be treated as a single argument rather than being
11260 : : broken into multiple. Solution is to insert '\\' before the space in a
11261 : : file name.
11262 : :
11263 : : This function converts and only converts all occurrence of ' '
11264 : : to '\\' + ' ' and '\t' to '\\' + '\t'. For example:
11265 : : "a b" -> "a\\ b"
11266 : : "a b" -> "a\\ \\ b"
11267 : : "a\tb" -> "a\\\tb"
11268 : : "a\\ b" -> "a\\\\ b"
11269 : :
11270 : : orig: input null-terminating string that was allocated by xalloc. The
11271 : : memory it points to might be freed in this function. Behavior undefined
11272 : : if ORIG wasn't xalloced or was freed already at entry.
11273 : :
11274 : : Return: ORIG if no conversion needed. Otherwise a newly allocated string
11275 : : that was converted from ORIG. */
11276 : :
11277 : : static char *
11278 : 198201 : convert_white_space (char *orig)
11279 : : {
11280 : 198201 : return quote_string (orig, whitespace_to_convert_p, NULL);
11281 : : }
11282 : :
11283 : : /* Return true iff C matches any of the spec active characters. */
11284 : : static inline bool
11285 : 6247382 : quote_spec_char_p (char c, void *)
11286 : : {
11287 : 6247382 : switch (c)
11288 : : {
11289 : : case ' ':
11290 : : case '\t':
11291 : : case '\n':
11292 : : case '|':
11293 : : case '%':
11294 : : case '\\':
11295 : : return true;
11296 : :
11297 : 6247382 : default:
11298 : 6247382 : return false;
11299 : : }
11300 : : }
11301 : :
11302 : : /* Like convert_white_space, but deactivate all active spec chars by
11303 : : quoting them. */
11304 : :
11305 : : static inline char *
11306 : 653804 : quote_spec (char *orig)
11307 : : {
11308 : 1233 : return quote_string (orig, quote_spec_char_p, NULL);
11309 : : }
11310 : :
11311 : : /* Like quote_spec, but also turn an empty string into the spec for an
11312 : : empty argument. */
11313 : :
11314 : : static inline char *
11315 : 652580 : quote_spec_arg (char *orig)
11316 : : {
11317 : 652580 : if (!*orig)
11318 : : {
11319 : 9 : free (orig);
11320 : 9 : return xstrdup ("%\"");
11321 : : }
11322 : :
11323 : 652571 : return quote_spec (orig);
11324 : : }
11325 : :
11326 : : /* Restore all state within gcc.cc to the initial state, so that the driver
11327 : : code can be safely re-run in-process.
11328 : :
11329 : : Many const char * variables are referenced by static specs (see
11330 : : INIT_STATIC_SPEC above). These variables are restored to their default
11331 : : values by a simple loop over the static specs.
11332 : :
11333 : : For other variables, we directly restore them all to their initial
11334 : : values (often implicitly 0).
11335 : :
11336 : : Free the various obstacks in this file, along with "opts_obstack"
11337 : : from opts.cc.
11338 : :
11339 : : This function also restores any environment variables that were changed. */
11340 : :
11341 : : void
11342 : 1134 : driver::finalize ()
11343 : : {
11344 : 1134 : env.restore ();
11345 : 1134 : diagnostic_finish (global_dc);
11346 : :
11347 : 1134 : is_cpp_driver = 0;
11348 : 1134 : at_file_supplied = 0;
11349 : 1134 : print_help_list = 0;
11350 : 1134 : print_version = 0;
11351 : 1134 : verbose_only_flag = 0;
11352 : 1134 : print_subprocess_help = 0;
11353 : 1134 : use_ld = NULL;
11354 : 1134 : report_times_to_file = NULL;
11355 : 1134 : target_system_root = DEFAULT_TARGET_SYSTEM_ROOT;
11356 : 1134 : target_system_root_changed = 0;
11357 : 1134 : target_sysroot_suffix = 0;
11358 : 1134 : target_sysroot_hdrs_suffix = 0;
11359 : 1134 : save_temps_flag = SAVE_TEMPS_NONE;
11360 : 1134 : save_temps_overrides_dumpdir = false;
11361 : 1134 : dumpdir_trailing_dash_added = false;
11362 : 1134 : free (dumpdir);
11363 : 1134 : free (dumpbase);
11364 : 1134 : free (dumpbase_ext);
11365 : 1134 : free (outbase);
11366 : 1134 : dumpdir = dumpbase = dumpbase_ext = outbase = NULL;
11367 : 1134 : dumpdir_length = outbase_length = 0;
11368 : 1134 : spec_machine = DEFAULT_TARGET_MACHINE;
11369 : 1134 : greatest_status = 1;
11370 : :
11371 : 1134 : obstack_free (&obstack, NULL);
11372 : 1134 : obstack_free (&opts_obstack, NULL); /* in opts.cc */
11373 : 1134 : obstack_free (&collect_obstack, NULL);
11374 : :
11375 : 1134 : link_command_spec = LINK_COMMAND_SPEC;
11376 : :
11377 : 1134 : obstack_free (&multilib_obstack, NULL);
11378 : :
11379 : 1134 : user_specs_head = NULL;
11380 : 1134 : user_specs_tail = NULL;
11381 : :
11382 : : /* Within the "compilers" vec, the fields "suffix" and "spec" were
11383 : : statically allocated for the default compilers, but dynamically
11384 : : allocated for additional compilers. Delete them for the latter. */
11385 : 1134 : for (int i = n_default_compilers; i < n_compilers; i++)
11386 : : {
11387 : 0 : free (const_cast <char *> (compilers[i].suffix));
11388 : 0 : free (const_cast <char *> (compilers[i].spec));
11389 : : }
11390 : 1134 : XDELETEVEC (compilers);
11391 : 1134 : compilers = NULL;
11392 : 1134 : n_compilers = 0;
11393 : :
11394 : 1134 : linker_options.truncate (0);
11395 : 1134 : assembler_options.truncate (0);
11396 : 1134 : preprocessor_options.truncate (0);
11397 : :
11398 : 1134 : path_prefix_reset (&exec_prefixes);
11399 : 1134 : path_prefix_reset (&startfile_prefixes);
11400 : 1134 : path_prefix_reset (&include_prefixes);
11401 : :
11402 : 1134 : machine_suffix = 0;
11403 : 1134 : just_machine_suffix = 0;
11404 : 1134 : gcc_exec_prefix = 0;
11405 : 1134 : gcc_libexec_prefix = 0;
11406 : 1134 : set_static_spec_shared (&md_exec_prefix, MD_EXEC_PREFIX);
11407 : 1134 : set_static_spec_shared (&md_startfile_prefix, MD_STARTFILE_PREFIX);
11408 : 1134 : set_static_spec_shared (&md_startfile_prefix_1, MD_STARTFILE_PREFIX_1);
11409 : 1134 : multilib_dir = 0;
11410 : 1134 : multilib_os_dir = 0;
11411 : 1134 : multiarch_dir = 0;
11412 : :
11413 : : /* Free any specs dynamically-allocated by set_spec.
11414 : : These will be at the head of the list, before the
11415 : : statically-allocated ones. */
11416 : 1134 : if (specs)
11417 : : {
11418 : 2268 : while (specs != static_specs)
11419 : : {
11420 : 1134 : spec_list *next = specs->next;
11421 : 1134 : free (const_cast <char *> (specs->name));
11422 : 1134 : XDELETE (specs);
11423 : 1134 : specs = next;
11424 : : }
11425 : 1134 : specs = 0;
11426 : : }
11427 : 52164 : for (unsigned i = 0; i < ARRAY_SIZE (static_specs); i++)
11428 : : {
11429 : 51030 : spec_list *sl = &static_specs[i];
11430 : 51030 : if (sl->alloc_p)
11431 : : {
11432 : 45370 : free (const_cast <char *> (*(sl->ptr_spec)));
11433 : 45370 : sl->alloc_p = false;
11434 : : }
11435 : 51030 : *(sl->ptr_spec) = sl->default_ptr;
11436 : : }
11437 : : #ifdef EXTRA_SPECS
11438 : 1134 : extra_specs = NULL;
11439 : : #endif
11440 : :
11441 : 1134 : processing_spec_function = 0;
11442 : :
11443 : 1134 : clear_args ();
11444 : :
11445 : 1134 : have_c = 0;
11446 : 1134 : have_o = 0;
11447 : :
11448 : 1134 : temp_names = NULL;
11449 : 1134 : execution_count = 0;
11450 : 1134 : signal_count = 0;
11451 : :
11452 : 1134 : temp_filename = NULL;
11453 : 1134 : temp_filename_length = 0;
11454 : 1134 : always_delete_queue = NULL;
11455 : 1134 : failure_delete_queue = NULL;
11456 : :
11457 : 1134 : XDELETEVEC (switches);
11458 : 1134 : switches = NULL;
11459 : 1134 : n_switches = 0;
11460 : 1134 : n_switches_alloc = 0;
11461 : :
11462 : 1134 : compare_debug = 0;
11463 : 1134 : compare_debug_second = 0;
11464 : 1134 : compare_debug_opt = NULL;
11465 : 3402 : for (int i = 0; i < 2; i++)
11466 : : {
11467 : 2268 : switches_debug_check[i] = NULL;
11468 : 2268 : n_switches_debug_check[i] = 0;
11469 : 2268 : n_switches_alloc_debug_check[i] = 0;
11470 : 2268 : debug_check_temp_file[i] = NULL;
11471 : : }
11472 : :
11473 : 1134 : XDELETEVEC (infiles);
11474 : 1134 : infiles = NULL;
11475 : 1134 : n_infiles = 0;
11476 : 1134 : n_infiles_alloc = 0;
11477 : :
11478 : 1134 : combine_inputs = false;
11479 : 1134 : added_libraries = 0;
11480 : 1134 : XDELETEVEC (outfiles);
11481 : 1134 : outfiles = NULL;
11482 : 1134 : spec_lang = 0;
11483 : 1134 : last_language_n_infiles = 0;
11484 : 1134 : gcc_input_filename = NULL;
11485 : 1134 : input_file_number = 0;
11486 : 1134 : input_filename_length = 0;
11487 : 1134 : basename_length = 0;
11488 : 1134 : suffixed_basename_length = 0;
11489 : 1134 : input_basename = NULL;
11490 : 1134 : input_suffix = NULL;
11491 : : /* We don't need to purge "input_stat", just to unset "input_stat_set". */
11492 : 1134 : input_stat_set = 0;
11493 : 1134 : input_file_compiler = NULL;
11494 : 1134 : arg_going = 0;
11495 : 1134 : delete_this_arg = 0;
11496 : 1134 : this_is_output_file = 0;
11497 : 1134 : this_is_library_file = 0;
11498 : 1134 : this_is_linker_script = 0;
11499 : 1134 : input_from_pipe = 0;
11500 : 1134 : suffix_subst = NULL;
11501 : :
11502 : 1134 : XDELETEVEC (mdswitches);
11503 : 1134 : mdswitches = NULL;
11504 : 1134 : n_mdswitches = 0;
11505 : :
11506 : 1134 : used_arg.finalize ();
11507 : 1134 : }
11508 : :
11509 : : /* PR jit/64810.
11510 : : Targets can provide configure-time default options in
11511 : : OPTION_DEFAULT_SPECS. The jit needs to access these, but
11512 : : they are expressed in the spec language.
11513 : :
11514 : : Run just enough of the driver to be able to expand these
11515 : : specs, and then call the callback CB on each
11516 : : such option. The options strings are *without* a leading
11517 : : '-' character e.g. ("march=x86-64"). Finally, clean up. */
11518 : :
11519 : : void
11520 : 131 : driver_get_configure_time_options (void (*cb) (const char *option,
11521 : : void *user_data),
11522 : : void *user_data)
11523 : : {
11524 : 131 : size_t i;
11525 : :
11526 : 131 : obstack_init (&obstack);
11527 : 131 : init_opts_obstack ();
11528 : 131 : n_switches = 0;
11529 : :
11530 : 1441 : for (i = 0; i < ARRAY_SIZE (option_default_specs); i++)
11531 : 1310 : do_option_spec (option_default_specs[i].name,
11532 : 1310 : option_default_specs[i].spec);
11533 : :
11534 : 393 : for (i = 0; (int) i < n_switches; i++)
11535 : : {
11536 : 262 : gcc_assert (switches[i].part1);
11537 : 262 : (*cb) (switches[i].part1, user_data);
11538 : : }
11539 : :
11540 : 131 : obstack_free (&opts_obstack, NULL);
11541 : 131 : obstack_free (&obstack, NULL);
11542 : 131 : n_switches = 0;
11543 : 131 : }
|