Branch data Line data Source code
1 : : /* Compiler driver program that can handle many languages.
2 : : Copyright (C) 1987-2025 Free Software Foundation, Inc.
3 : :
4 : : This file is part of GCC.
5 : :
6 : : GCC is free software; you can redistribute it and/or modify it under
7 : : the terms of the GNU General Public License as published by the Free
8 : : Software Foundation; either version 3, or (at your option) any later
9 : : version.
10 : :
11 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 : : for more details.
15 : :
16 : : You should have received a copy of the GNU General Public License
17 : : along with GCC; see the file COPYING3. If not see
18 : : <http://www.gnu.org/licenses/>. */
19 : :
20 : : /* This program is the user interface to the C compiler and possibly to
21 : : other compilers. It is used because compilation is a complicated procedure
22 : : which involves running several programs and passing temporary files between
23 : : them, forwarding the users switches to those programs selectively,
24 : : and deleting the temporary files at the end.
25 : :
26 : : CC recognizes how to compile each input file by suffixes in the file names.
27 : : Once it knows which kind of compilation to perform, the procedure for
28 : : compilation is specified by a string called a "spec". */
29 : :
30 : : #define INCLUDE_STRING
31 : : #include "config.h"
32 : : #include "system.h"
33 : : #ifdef HOST_HAS_PERSONALITY_ADDR_NO_RANDOMIZE
34 : : #include <sys/personality.h>
35 : : #endif
36 : : #include "coretypes.h"
37 : : #include "multilib.h" /* before tm.h */
38 : : #include "tm.h"
39 : : #include "xregex.h"
40 : : #include "obstack.h"
41 : : #include "intl.h"
42 : : #include "prefix.h"
43 : : #include "opt-suggestions.h"
44 : : #include "gcc.h"
45 : : #include "diagnostic.h"
46 : : #include "diagnostic-format.h"
47 : : #include "pretty-print-urlifier.h"
48 : : #include "flags.h"
49 : : #include "opts.h"
50 : : #include "filenames.h"
51 : : #include "spellcheck.h"
52 : : #include "opts-jobserver.h"
53 : : #include "common/common-target.h"
54 : : #include "gcc-urlifier.h"
55 : : #include "opts-diagnostic.h"
56 : :
57 : : #ifndef MATH_LIBRARY
58 : : #define MATH_LIBRARY "m"
59 : : #endif
60 : :
61 : :
62 : : /* Manage the manipulation of env vars.
63 : :
64 : : We poison "getenv" and "putenv", so that all enviroment-handling is
65 : : done through this class. Note that poisoning happens in the
66 : : preprocessor at the identifier level, and doesn't distinguish between
67 : : env.getenv ();
68 : : and
69 : : getenv ();
70 : : Hence we need to use "get" for the accessor method, not "getenv". */
71 : :
72 : : struct env_manager
73 : : {
74 : : public:
75 : : void init (bool can_restore, bool debug);
76 : : const char *get (const char *name);
77 : : void xput (const char *string);
78 : : void restore ();
79 : :
80 : : private:
81 : : bool m_can_restore;
82 : : bool m_debug;
83 : : struct kv
84 : : {
85 : : char *m_key;
86 : : char *m_value;
87 : : };
88 : : vec<kv> m_keys;
89 : :
90 : : };
91 : :
92 : : /* The singleton instance of class env_manager. */
93 : :
94 : : static env_manager env;
95 : :
96 : : /* Initializer for class env_manager.
97 : :
98 : : We can't do this as a constructor since we have a statically
99 : : allocated instance ("env" above). */
100 : :
101 : : void
102 : 287780 : env_manager::init (bool can_restore, bool debug)
103 : : {
104 : 287780 : m_can_restore = can_restore;
105 : 287780 : m_debug = debug;
106 : 287780 : }
107 : :
108 : : /* Get the value of NAME within the environment. Essentially
109 : : a wrapper for ::getenv, but adding logging, and the possibility
110 : : of caching results. */
111 : :
112 : : const char *
113 : 1437980 : env_manager::get (const char *name)
114 : : {
115 : 1437980 : const char *result = ::getenv (name);
116 : 1437980 : if (m_debug)
117 : 0 : fprintf (stderr, "env_manager::getenv (%s) -> %s\n", name, result);
118 : 1437980 : return result;
119 : : }
120 : :
121 : : /* Put the given KEY=VALUE entry STRING into the environment.
122 : : If the env_manager was initialized with CAN_RESTORE set, then
123 : : also record the old value of KEY within the environment, so that it
124 : : can be later restored. */
125 : :
126 : : void
127 : 1702992 : env_manager::xput (const char *string)
128 : : {
129 : 1702992 : if (m_debug)
130 : 0 : fprintf (stderr, "env_manager::xput (%s)\n", string);
131 : 1702992 : if (verbose_flag)
132 : 5783 : fnotice (stderr, "%s\n", string);
133 : :
134 : 1702992 : if (m_can_restore)
135 : : {
136 : 6559 : char *equals = strchr (const_cast <char *> (string), '=');
137 : 6559 : gcc_assert (equals);
138 : :
139 : 6559 : struct kv kv;
140 : 6559 : kv.m_key = xstrndup (string, equals - string);
141 : 6559 : const char *cur_value = ::getenv (kv.m_key);
142 : 6559 : if (m_debug)
143 : 0 : fprintf (stderr, "saving old value: %s\n",cur_value);
144 : 6559 : kv.m_value = cur_value ? xstrdup (cur_value) : NULL;
145 : 6559 : m_keys.safe_push (kv);
146 : : }
147 : :
148 : 1702992 : ::putenv (CONST_CAST (char *, string));
149 : 1702992 : }
150 : :
151 : : /* Undo any xputenv changes made since last restore.
152 : : Can only be called if the env_manager was initialized with
153 : : CAN_RESTORE enabled. */
154 : :
155 : : void
156 : 1094 : env_manager::restore ()
157 : : {
158 : 1094 : unsigned int i;
159 : 1094 : struct kv *item;
160 : :
161 : 1094 : gcc_assert (m_can_restore);
162 : :
163 : 8747 : FOR_EACH_VEC_ELT_REVERSE (m_keys, i, item)
164 : : {
165 : 6559 : if (m_debug)
166 : 0 : printf ("restoring saved key: %s value: %s\n", item->m_key, item->m_value);
167 : 6559 : if (item->m_value)
168 : 3277 : ::setenv (item->m_key, item->m_value, 1);
169 : : else
170 : 3282 : ::unsetenv (item->m_key);
171 : 6559 : free (item->m_key);
172 : 6559 : free (item->m_value);
173 : : }
174 : :
175 : 1094 : m_keys.truncate (0);
176 : 1094 : }
177 : :
178 : : /* Forbid other uses of getenv and putenv. */
179 : : #if (GCC_VERSION >= 3000)
180 : : #pragma GCC poison getenv putenv
181 : : #endif
182 : :
183 : :
184 : :
185 : : /* By default there is no special suffix for target executables. */
186 : : #ifdef TARGET_EXECUTABLE_SUFFIX
187 : : #define HAVE_TARGET_EXECUTABLE_SUFFIX
188 : : #else
189 : : #define TARGET_EXECUTABLE_SUFFIX ""
190 : : #endif
191 : :
192 : : /* By default there is no special suffix for host executables. */
193 : : #ifdef HOST_EXECUTABLE_SUFFIX
194 : : #define HAVE_HOST_EXECUTABLE_SUFFIX
195 : : #else
196 : : #define HOST_EXECUTABLE_SUFFIX ""
197 : : #endif
198 : :
199 : : /* By default, the suffix for target object files is ".o". */
200 : : #ifdef TARGET_OBJECT_SUFFIX
201 : : #define HAVE_TARGET_OBJECT_SUFFIX
202 : : #else
203 : : #define TARGET_OBJECT_SUFFIX ".o"
204 : : #endif
205 : :
206 : : static const char dir_separator_str[] = { DIR_SEPARATOR, 0 };
207 : :
208 : : /* Most every one is fine with LIBRARY_PATH. For some, it conflicts. */
209 : : #ifndef LIBRARY_PATH_ENV
210 : : #define LIBRARY_PATH_ENV "LIBRARY_PATH"
211 : : #endif
212 : :
213 : : /* If a stage of compilation returns an exit status >= 1,
214 : : compilation of that file ceases. */
215 : :
216 : : #define MIN_FATAL_STATUS 1
217 : :
218 : : /* Flag set by cppspec.cc to 1. */
219 : : int is_cpp_driver;
220 : :
221 : : /* Flag set to nonzero if an @file argument has been supplied to gcc. */
222 : : static bool at_file_supplied;
223 : :
224 : : /* Definition of string containing the arguments given to configure. */
225 : : #include "configargs.h"
226 : :
227 : : /* Flag saying to print the command line options understood by gcc and its
228 : : sub-processes. */
229 : :
230 : : static int print_help_list;
231 : :
232 : : /* Flag saying to print the version of gcc and its sub-processes. */
233 : :
234 : : static int print_version;
235 : :
236 : : /* Flag that stores string prefix for which we provide bash completion. */
237 : :
238 : : static const char *completion = NULL;
239 : :
240 : : /* Flag indicating whether we should ONLY print the command and
241 : : arguments (like verbose_flag) without executing the command.
242 : : Displayed arguments are quoted so that the generated command
243 : : line is suitable for execution. This is intended for use in
244 : : shell scripts to capture the driver-generated command line. */
245 : : static int verbose_only_flag;
246 : :
247 : : /* Flag indicating how to print command line options of sub-processes. */
248 : :
249 : : static int print_subprocess_help;
250 : :
251 : : /* Linker suffix passed to -fuse-ld=... */
252 : : static const char *use_ld;
253 : :
254 : : /* Whether we should report subprocess execution times to a file. */
255 : :
256 : : FILE *report_times_to_file = NULL;
257 : :
258 : : /* Nonzero means place this string before uses of /, so that include
259 : : and library files can be found in an alternate location. */
260 : :
261 : : #ifdef TARGET_SYSTEM_ROOT
262 : : #define DEFAULT_TARGET_SYSTEM_ROOT (TARGET_SYSTEM_ROOT)
263 : : #else
264 : : #define DEFAULT_TARGET_SYSTEM_ROOT (0)
265 : : #endif
266 : : static const char *target_system_root = DEFAULT_TARGET_SYSTEM_ROOT;
267 : :
268 : : /* Nonzero means pass the updated target_system_root to the compiler. */
269 : :
270 : : static int target_system_root_changed;
271 : :
272 : : /* Nonzero means append this string to target_system_root. */
273 : :
274 : : static const char *target_sysroot_suffix = 0;
275 : :
276 : : /* Nonzero means append this string to target_system_root for headers. */
277 : :
278 : : static const char *target_sysroot_hdrs_suffix = 0;
279 : :
280 : : /* Nonzero means write "temp" files in source directory
281 : : and use the source file's name in them, and don't delete them. */
282 : :
283 : : static enum save_temps {
284 : : SAVE_TEMPS_NONE, /* no -save-temps */
285 : : SAVE_TEMPS_CWD, /* -save-temps in current directory */
286 : : SAVE_TEMPS_DUMP, /* -save-temps in dumpdir */
287 : : SAVE_TEMPS_OBJ /* -save-temps in object directory */
288 : : } save_temps_flag;
289 : :
290 : : /* Set this iff the dumppfx implied by a -save-temps=* option is to
291 : : override a -dumpdir option, if any. */
292 : : static bool save_temps_overrides_dumpdir = false;
293 : :
294 : : /* -dumpdir, -dumpbase and -dumpbase-ext flags passed in, possibly
295 : : rearranged as they are to be passed down, e.g., dumpbase and
296 : : dumpbase_ext may be cleared if integrated with dumpdir or
297 : : dropped. */
298 : : static char *dumpdir, *dumpbase, *dumpbase_ext;
299 : :
300 : : /* Usually the length of the string in dumpdir. However, during
301 : : linking, it may be shortened to omit a driver-added trailing dash,
302 : : by then replaced with a trailing period, that is still to be passed
303 : : to sub-processes in -dumpdir, but not to be generally used in spec
304 : : filename expansions. See maybe_run_linker. */
305 : : static size_t dumpdir_length = 0;
306 : :
307 : : /* Set if the last character in dumpdir is (or was) a dash that the
308 : : driver added to dumpdir after dumpbase or linker output name. */
309 : : static bool dumpdir_trailing_dash_added = false;
310 : :
311 : : /* True if -r, -shared, -pie, -no-pie, -z lazy, or -z norelro were
312 : : specified on the command line, and therefore -fhardened should not
313 : : add -z now/relro. */
314 : : static bool avoid_linker_hardening_p;
315 : :
316 : : /* True if -static was specified on the command line. */
317 : : static bool static_p;
318 : :
319 : : /* Basename of dump and aux outputs, computed from dumpbase (given or
320 : : derived from output name), to override input_basename in non-%w %b
321 : : et al. */
322 : : static char *outbase;
323 : : static size_t outbase_length = 0;
324 : :
325 : : /* The compiler version. */
326 : :
327 : : static const char *compiler_version;
328 : :
329 : : /* The target version. */
330 : :
331 : : static const char *const spec_version = DEFAULT_TARGET_VERSION;
332 : :
333 : : /* The target machine. */
334 : :
335 : : static const char *spec_machine = DEFAULT_TARGET_MACHINE;
336 : : static const char *spec_host_machine = DEFAULT_REAL_TARGET_MACHINE;
337 : :
338 : : /* List of offload targets. Separated by colon. Empty string for
339 : : -foffload=disable. */
340 : :
341 : : static char *offload_targets = NULL;
342 : :
343 : : #if OFFLOAD_DEFAULTED
344 : : /* Set to true if -foffload has not been used and offload_targets
345 : : is set to the configured in default. */
346 : : static bool offload_targets_default;
347 : : #endif
348 : :
349 : : /* Nonzero if cross-compiling.
350 : : When -b is used, the value comes from the `specs' file. */
351 : :
352 : : #ifdef CROSS_DIRECTORY_STRUCTURE
353 : : static const char *cross_compile = "1";
354 : : #else
355 : : static const char *cross_compile = "0";
356 : : #endif
357 : :
358 : : /* Greatest exit code of sub-processes that has been encountered up to
359 : : now. */
360 : : static int greatest_status = 1;
361 : :
362 : : /* This is the obstack which we use to allocate many strings. */
363 : :
364 : : static struct obstack obstack;
365 : :
366 : : /* This is the obstack to build an environment variable to pass to
367 : : collect2 that describes all of the relevant switches of what to
368 : : pass the compiler in building the list of pointers to constructors
369 : : and destructors. */
370 : :
371 : : static struct obstack collect_obstack;
372 : :
373 : : /* Forward declaration for prototypes. */
374 : : struct path_prefix;
375 : : struct prefix_list;
376 : :
377 : : static void init_spec (void);
378 : : static void store_arg (const char *, int, int);
379 : : static void insert_wrapper (const char *);
380 : : static char *load_specs (const char *);
381 : : static void read_specs (const char *, bool, bool);
382 : : static void set_spec (const char *, const char *, bool);
383 : : static struct compiler *lookup_compiler (const char *, size_t, const char *);
384 : : static char *build_search_list (const struct path_prefix *, const char *,
385 : : bool, bool);
386 : : static void xputenv (const char *);
387 : : static void putenv_from_prefixes (const struct path_prefix *, const char *,
388 : : bool);
389 : : static int access_check (const char *, int);
390 : : static char *find_a_file (const struct path_prefix *, const char *, int, bool);
391 : : static char *find_a_program (const char *);
392 : : static void add_prefix (struct path_prefix *, const char *, const char *,
393 : : int, int, int);
394 : : static void add_sysrooted_prefix (struct path_prefix *, const char *,
395 : : const char *, int, int, int);
396 : : static char *skip_whitespace (char *);
397 : : static void delete_if_ordinary (const char *);
398 : : static void delete_temp_files (void);
399 : : static void delete_failure_queue (void);
400 : : static void clear_failure_queue (void);
401 : : static int check_live_switch (int, int);
402 : : static const char *handle_braces (const char *);
403 : : static inline bool input_suffix_matches (const char *, const char *);
404 : : static inline bool switch_matches (const char *, const char *, int);
405 : : static inline void mark_matching_switches (const char *, const char *, int);
406 : : static inline void process_marked_switches (void);
407 : : static const char *process_brace_body (const char *, const char *, const char *, int, int);
408 : : static const struct spec_function *lookup_spec_function (const char *);
409 : : static const char *eval_spec_function (const char *, const char *, const char *);
410 : : static const char *handle_spec_function (const char *, bool *, const char *);
411 : : static char *save_string (const char *, int);
412 : : static void set_collect_gcc_options (void);
413 : : static int do_spec_1 (const char *, int, const char *);
414 : : static int do_spec_2 (const char *, const char *);
415 : : static void do_option_spec (const char *, const char *);
416 : : static void do_self_spec (const char *);
417 : : static const char *find_file (const char *);
418 : : static int is_directory (const char *);
419 : : static const char *validate_switches (const char *, bool, bool);
420 : : static void validate_all_switches (void);
421 : : static inline void validate_switches_from_spec (const char *, bool);
422 : : static void give_switch (int, int);
423 : : static int default_arg (const char *, int);
424 : : static void set_multilib_dir (void);
425 : : static void print_multilib_info (void);
426 : : static void display_help (void);
427 : : static void add_preprocessor_option (const char *, int);
428 : : static void add_assembler_option (const char *, int);
429 : : static void add_linker_option (const char *, int);
430 : : static void process_command (unsigned int, struct cl_decoded_option *);
431 : : static int execute (void);
432 : : static void alloc_args (void);
433 : : static void clear_args (void);
434 : : static void fatal_signal (int);
435 : : #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC)
436 : : static void init_gcc_specs (struct obstack *, const char *, const char *,
437 : : const char *);
438 : : #endif
439 : : #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
440 : : static const char *convert_filename (const char *, int, int);
441 : : #endif
442 : :
443 : : static void try_generate_repro (const char **argv);
444 : : static const char *getenv_spec_function (int, const char **);
445 : : static const char *if_exists_spec_function (int, const char **);
446 : : static const char *if_exists_else_spec_function (int, const char **);
447 : : static const char *if_exists_then_else_spec_function (int, const char **);
448 : : static const char *sanitize_spec_function (int, const char **);
449 : : static const char *replace_outfile_spec_function (int, const char **);
450 : : static const char *remove_outfile_spec_function (int, const char **);
451 : : static const char *version_compare_spec_function (int, const char **);
452 : : static const char *include_spec_function (int, const char **);
453 : : static const char *find_file_spec_function (int, const char **);
454 : : static const char *find_plugindir_spec_function (int, const char **);
455 : : static const char *print_asm_header_spec_function (int, const char **);
456 : : static const char *compare_debug_dump_opt_spec_function (int, const char **);
457 : : static const char *compare_debug_self_opt_spec_function (int, const char **);
458 : : static const char *pass_through_libs_spec_func (int, const char **);
459 : : static const char *dumps_spec_func (int, const char **);
460 : : static const char *greater_than_spec_func (int, const char **);
461 : : static const char *debug_level_greater_than_spec_func (int, const char **);
462 : : static const char *dwarf_version_greater_than_spec_func (int, const char **);
463 : : static const char *find_fortran_preinclude_file (int, const char **);
464 : : static const char *join_spec_func (int, const char **);
465 : : static char *convert_white_space (char *);
466 : : static char *quote_spec (char *);
467 : : static char *quote_spec_arg (char *);
468 : : static bool not_actual_file_p (const char *);
469 : :
470 : :
471 : : /* The Specs Language
472 : :
473 : : Specs are strings containing lines, each of which (if not blank)
474 : : is made up of a program name, and arguments separated by spaces.
475 : : The program name must be exact and start from root, since no path
476 : : is searched and it is unreliable to depend on the current working directory.
477 : : Redirection of input or output is not supported; the subprograms must
478 : : accept filenames saying what files to read and write.
479 : :
480 : : In addition, the specs can contain %-sequences to substitute variable text
481 : : or for conditional text. Here is a table of all defined %-sequences.
482 : : Note that spaces are not generated automatically around the results of
483 : : expanding these sequences; therefore, you can concatenate them together
484 : : or with constant text in a single argument.
485 : :
486 : : %% substitute one % into the program name or argument.
487 : : %" substitute an empty argument.
488 : : %i substitute the name of the input file being processed.
489 : : %b substitute the basename for outputs related with the input file
490 : : being processed. This is often a substring of the input file name,
491 : : up to (and not including) the last period but, unless %w is active,
492 : : it is affected by the directory selected by -save-temps=*, by
493 : : -dumpdir, and, in case of multiple compilations, even by -dumpbase
494 : : and -dumpbase-ext and, in case of linking, by the linker output
495 : : name. When %w is active, it derives the main output name only from
496 : : the input file base name; when it is not, it names aux/dump output
497 : : file.
498 : : %B same as %b, but include the input file suffix (text after the last
499 : : period).
500 : : %gSUFFIX
501 : : substitute a file name that has suffix SUFFIX and is chosen
502 : : once per compilation, and mark the argument a la %d. To reduce
503 : : exposure to denial-of-service attacks, the file name is now
504 : : chosen in a way that is hard to predict even when previously
505 : : chosen file names are known. For example, `%g.s ... %g.o ... %g.s'
506 : : might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches
507 : : the regexp "[.0-9A-Za-z]*%O"; "%O" is treated exactly as if it
508 : : had been pre-processed. Previously, %g was simply substituted
509 : : with a file name chosen once per compilation, without regard
510 : : to any appended suffix (which was therefore treated just like
511 : : ordinary text), making such attacks more likely to succeed.
512 : : %|SUFFIX
513 : : like %g, but if -pipe is in effect, expands simply to "-".
514 : : %mSUFFIX
515 : : like %g, but if -pipe is in effect, expands to nothing. (We have both
516 : : %| and %m to accommodate differences between system assemblers; see
517 : : the AS_NEEDS_DASH_FOR_PIPED_INPUT target macro.)
518 : : %uSUFFIX
519 : : like %g, but generates a new temporary file name even if %uSUFFIX
520 : : was already seen.
521 : : %USUFFIX
522 : : substitutes the last file name generated with %uSUFFIX, generating a
523 : : new one if there is no such last file name. In the absence of any
524 : : %uSUFFIX, this is just like %gSUFFIX, except they don't share
525 : : the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s'
526 : : would involve the generation of two distinct file names, one
527 : : for each `%g.s' and another for each `%U.s'. Previously, %U was
528 : : simply substituted with a file name chosen for the previous %u,
529 : : without regard to any appended suffix.
530 : : %jSUFFIX
531 : : substitutes the name of the HOST_BIT_BUCKET, if any, and if it is
532 : : writable, and if save-temps is off; otherwise, substitute the name
533 : : of a temporary file, just like %u. This temporary file is not
534 : : meant for communication between processes, but rather as a junk
535 : : disposal mechanism.
536 : : %.SUFFIX
537 : : substitutes .SUFFIX for the suffixes of a matched switch's args when
538 : : it is subsequently output with %*. SUFFIX is terminated by the next
539 : : space or %.
540 : : %d marks the argument containing or following the %d as a
541 : : temporary file name, so that file will be deleted if GCC exits
542 : : successfully. Unlike %g, this contributes no text to the argument.
543 : : %w marks the argument containing or following the %w as the
544 : : "output file" of this compilation. This puts the argument
545 : : into the sequence of arguments that %o will substitute later.
546 : : %V indicates that this compilation produces no "output file".
547 : : %W{...}
548 : : like %{...} but marks the last argument supplied within as a file
549 : : to be deleted on failure.
550 : : %@{...}
551 : : like %{...} but puts the result into a FILE and substitutes @FILE
552 : : if an @file argument has been supplied.
553 : : %o substitutes the names of all the output files, with spaces
554 : : automatically placed around them. You should write spaces
555 : : around the %o as well or the results are undefined.
556 : : %o is for use in the specs for running the linker.
557 : : Input files whose names have no recognized suffix are not compiled
558 : : at all, but they are included among the output files, so they will
559 : : be linked.
560 : : %O substitutes the suffix for object files. Note that this is
561 : : handled specially when it immediately follows %g, %u, or %U
562 : : (with or without a suffix argument) because of the need for
563 : : those to form complete file names. The handling is such that
564 : : %O is treated exactly as if it had already been substituted,
565 : : except that %g, %u, and %U do not currently support additional
566 : : SUFFIX characters following %O as they would following, for
567 : : example, `.o'.
568 : : %I Substitute any of -iprefix (made from GCC_EXEC_PREFIX), -isysroot
569 : : (made from TARGET_SYSTEM_ROOT), -isystem (made from COMPILER_PATH
570 : : and -B options) and -imultilib as necessary.
571 : : %s current argument is the name of a library or startup file of some sort.
572 : : Search for that file in a standard list of directories
573 : : and substitute the full name found.
574 : : %T current argument is the name of a linker script.
575 : : Search for that file in the current list of directories to scan for
576 : : libraries. If the file is located, insert a --script option into the
577 : : command line followed by the full path name found. If the file is
578 : : not found then generate an error message.
579 : : Note: the current working directory is not searched.
580 : : %eSTR Print STR as an error message. STR is terminated by a newline.
581 : : Use this when inconsistent options are detected.
582 : : %nSTR Print STR as a notice. STR is terminated by a newline.
583 : : %x{OPTION} Accumulate an option for %X.
584 : : %X Output the accumulated linker options specified by compilations.
585 : : %Y Output the accumulated assembler options specified by compilations.
586 : : %Z Output the accumulated preprocessor options specified by compilations.
587 : : %a process ASM_SPEC as a spec.
588 : : This allows config.h to specify part of the spec for running as.
589 : : %A process ASM_FINAL_SPEC as a spec. A capital A is actually
590 : : used here. This can be used to run a post-processor after the
591 : : assembler has done its job.
592 : : %D Dump out a -L option for each directory in startfile_prefixes.
593 : : If multilib_dir is set, extra entries are generated with it affixed.
594 : : %l process LINK_SPEC as a spec.
595 : : %L process LIB_SPEC as a spec.
596 : : %M Output multilib_os_dir.
597 : : %P Output a RUNPATH_OPTION for each directory in startfile_prefixes.
598 : : %G process LIBGCC_SPEC as a spec.
599 : : %R Output the concatenation of target_system_root and
600 : : target_sysroot_suffix.
601 : : %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
602 : : %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
603 : : %C process CPP_SPEC as a spec.
604 : : %1 process CC1_SPEC as a spec.
605 : : %2 process CC1PLUS_SPEC as a spec.
606 : : %* substitute the variable part of a matched option. (See below.)
607 : : Note that each comma in the substituted string is replaced by
608 : : a single space. A space is appended after the last substition
609 : : unless there is more text in current sequence.
610 : : %<S remove all occurrences of -S from the command line.
611 : : Note - this command is position dependent. % commands in the
612 : : spec string before this one will see -S, % commands in the
613 : : spec string after this one will not.
614 : : %>S Similar to "%<S", but keep it in the GCC command line.
615 : : %<S* remove all occurrences of all switches beginning with -S from the
616 : : command line.
617 : : %:function(args)
618 : : Call the named function FUNCTION, passing it ARGS. ARGS is
619 : : first processed as a nested spec string, then split into an
620 : : argument vector in the usual fashion. The function returns
621 : : a string which is processed as if it had appeared literally
622 : : as part of the current spec.
623 : : %{S} substitutes the -S switch, if that switch was given to GCC.
624 : : If that switch was not specified, this substitutes nothing.
625 : : Here S is a metasyntactic variable.
626 : : %{S*} substitutes all the switches specified to GCC whose names start
627 : : with -S. This is used for -o, -I, etc; switches that take
628 : : arguments. GCC considers `-o foo' as being one switch whose
629 : : name starts with `o'. %{o*} would substitute this text,
630 : : including the space; thus, two arguments would be generated.
631 : : %{S*&T*} likewise, but preserve order of S and T options (the order
632 : : of S and T in the spec is not significant). Can be any number
633 : : of ampersand-separated variables; for each the wild card is
634 : : optional. Useful for CPP as %{D*&U*&A*}.
635 : :
636 : : %{S:X} substitutes X, if the -S switch was given to GCC.
637 : : %{!S:X} substitutes X, if the -S switch was NOT given to GCC.
638 : : %{S*:X} substitutes X if one or more switches whose names start
639 : : with -S was given to GCC. Normally X is substituted only
640 : : once, no matter how many such switches appeared. However,
641 : : if %* appears somewhere in X, then X will be substituted
642 : : once for each matching switch, with the %* replaced by the
643 : : part of that switch that matched the '*'. A space will be
644 : : appended after the last substition unless there is more
645 : : text in current sequence.
646 : : %{.S:X} substitutes X, if processing a file with suffix S.
647 : : %{!.S:X} substitutes X, if NOT processing a file with suffix S.
648 : : %{,S:X} substitutes X, if processing a file which will use spec S.
649 : : %{!,S:X} substitutes X, if NOT processing a file which will use spec S.
650 : :
651 : : %{S|T:X} substitutes X if either -S or -T was given to GCC. This may be
652 : : combined with '!', '.', ',', and '*' as above binding stronger
653 : : than the OR.
654 : : If %* appears in X, all of the alternatives must be starred, and
655 : : only the first matching alternative is substituted.
656 : : %{%:function(args):X}
657 : : Call function named FUNCTION with args ARGS. If the function
658 : : returns non-NULL, then X is substituted, if it returns
659 : : NULL, it isn't substituted.
660 : : %{S:X; if S was given to GCC, substitutes X;
661 : : T:Y; else if T was given to GCC, substitutes Y;
662 : : :D} else substitutes D. There can be as many clauses as you need.
663 : : This may be combined with '.', '!', ',', '|', and '*' as above.
664 : :
665 : : %(Spec) processes a specification defined in a specs file as *Spec:
666 : :
667 : : The switch matching text S in a %{S}, %{S:X}, or similar construct can use
668 : : a backslash to ignore the special meaning of the character following it,
669 : : thus allowing literal matching of a character that is otherwise specially
670 : : treated. For example, %{std=iso9899\:1999:X} substitutes X if the
671 : : -std=iso9899:1999 option is given.
672 : :
673 : : The conditional text X in a %{S:X} or similar construct may contain
674 : : other nested % constructs or spaces, or even newlines. They are
675 : : processed as usual, as described above. Trailing white space in X is
676 : : ignored. White space may also appear anywhere on the left side of the
677 : : colon in these constructs, except between . or * and the corresponding
678 : : word.
679 : :
680 : : The -O, -f, -g, -m, and -W switches are handled specifically in these
681 : : constructs. If another value of -O or the negated form of a -f, -m, or
682 : : -W switch is found later in the command line, the earlier switch
683 : : value is ignored, except with {S*} where S is just one letter; this
684 : : passes all matching options.
685 : :
686 : : The character | at the beginning of the predicate text is used to indicate
687 : : that a command should be piped to the following command, but only if -pipe
688 : : is specified.
689 : :
690 : : Note that it is built into GCC which switches take arguments and which
691 : : do not. You might think it would be useful to generalize this to
692 : : allow each compiler's spec to say which switches take arguments. But
693 : : this cannot be done in a consistent fashion. GCC cannot even decide
694 : : which input files have been specified without knowing which switches
695 : : take arguments, and it must know which input files to compile in order
696 : : to tell which compilers to run.
697 : :
698 : : GCC also knows implicitly that arguments starting in `-l' are to be
699 : : treated as compiler output files, and passed to the linker in their
700 : : proper position among the other output files. */
701 : :
702 : : /* Define the macros used for specs %a, %l, %L, %S, %C, %1. */
703 : :
704 : : /* config.h can define ASM_SPEC to provide extra args to the assembler
705 : : or extra switch-translations. */
706 : : #ifndef ASM_SPEC
707 : : #define ASM_SPEC ""
708 : : #endif
709 : :
710 : : /* config.h can define ASM_FINAL_SPEC to run a post processor after
711 : : the assembler has run. */
712 : : #ifndef ASM_FINAL_SPEC
713 : : #define ASM_FINAL_SPEC \
714 : : "%{gsplit-dwarf: \n\
715 : : objcopy --extract-dwo \
716 : : %{c:%{o*:%*}%{!o*:%w%b%O}}%{!c:%U%O} \
717 : : %b.dwo \n\
718 : : objcopy --strip-dwo \
719 : : %{c:%{o*:%*}%{!o*:%w%b%O}}%{!c:%U%O} \
720 : : }"
721 : : #endif
722 : :
723 : : /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
724 : : or extra switch-translations. */
725 : : #ifndef CPP_SPEC
726 : : #define CPP_SPEC ""
727 : : #endif
728 : :
729 : : /* Operating systems can define OS_CC1_SPEC to provide extra args to cc1 and
730 : : cc1plus or extra switch-translations. The OS_CC1_SPEC is appended
731 : : to CC1_SPEC in the initialization of cc1_spec. */
732 : : #ifndef OS_CC1_SPEC
733 : : #define OS_CC1_SPEC ""
734 : : #endif
735 : :
736 : : /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
737 : : or extra switch-translations. */
738 : : #ifndef CC1_SPEC
739 : : #define CC1_SPEC ""
740 : : #endif
741 : :
742 : : /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
743 : : or extra switch-translations. */
744 : : #ifndef CC1PLUS_SPEC
745 : : #define CC1PLUS_SPEC ""
746 : : #endif
747 : :
748 : : /* config.h can define LINK_SPEC to provide extra args to the linker
749 : : or extra switch-translations. */
750 : : #ifndef LINK_SPEC
751 : : #define LINK_SPEC ""
752 : : #endif
753 : :
754 : : /* config.h can define LIB_SPEC to override the default libraries. */
755 : : #ifndef LIB_SPEC
756 : : #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
757 : : #endif
758 : :
759 : : /* When using -fsplit-stack we need to wrap pthread_create, in order
760 : : to initialize the stack guard. We always use wrapping, rather than
761 : : shared library ordering, and we keep the wrapper function in
762 : : libgcc. This is not yet a real spec, though it could become one;
763 : : it is currently just stuffed into LINK_SPEC. FIXME: This wrapping
764 : : only works with GNU ld and gold. */
765 : : #ifdef HAVE_GOLD_NON_DEFAULT_SPLIT_STACK
766 : : #define STACK_SPLIT_SPEC " %{fsplit-stack: -fuse-ld=gold --wrap=pthread_create}"
767 : : #else
768 : : #define STACK_SPLIT_SPEC " %{fsplit-stack: --wrap=pthread_create}"
769 : : #endif
770 : :
771 : : #ifndef LIBASAN_SPEC
772 : : #define STATIC_LIBASAN_LIBS \
773 : : " %{static-libasan|static:%:include(libsanitizer.spec)%(link_libasan)}"
774 : : #ifdef LIBASAN_EARLY_SPEC
775 : : #define LIBASAN_SPEC STATIC_LIBASAN_LIBS
776 : : #elif defined(HAVE_LD_STATIC_DYNAMIC)
777 : : #define LIBASAN_SPEC "%{static-libasan:" LD_STATIC_OPTION \
778 : : "} -lasan %{static-libasan:" LD_DYNAMIC_OPTION "}" \
779 : : STATIC_LIBASAN_LIBS
780 : : #else
781 : : #define LIBASAN_SPEC "-lasan" STATIC_LIBASAN_LIBS
782 : : #endif
783 : : #endif
784 : :
785 : : #ifndef LIBASAN_EARLY_SPEC
786 : : #define LIBASAN_EARLY_SPEC ""
787 : : #endif
788 : :
789 : : #ifndef LIBHWASAN_SPEC
790 : : #define STATIC_LIBHWASAN_LIBS \
791 : : " %{static-libhwasan|static:%:include(libsanitizer.spec)%(link_libhwasan)}"
792 : : #ifdef LIBHWASAN_EARLY_SPEC
793 : : #define LIBHWASAN_SPEC STATIC_LIBHWASAN_LIBS
794 : : #elif defined(HAVE_LD_STATIC_DYNAMIC)
795 : : #define LIBHWASAN_SPEC "%{static-libhwasan:" LD_STATIC_OPTION \
796 : : "} -lhwasan %{static-libhwasan:" LD_DYNAMIC_OPTION "}" \
797 : : STATIC_LIBHWASAN_LIBS
798 : : #else
799 : : #define LIBHWASAN_SPEC "-lhwasan" STATIC_LIBHWASAN_LIBS
800 : : #endif
801 : : #endif
802 : :
803 : : #ifndef LIBHWASAN_EARLY_SPEC
804 : : #define LIBHWASAN_EARLY_SPEC ""
805 : : #endif
806 : :
807 : : #ifndef LIBTSAN_SPEC
808 : : #define STATIC_LIBTSAN_LIBS \
809 : : " %{static-libtsan|static:%:include(libsanitizer.spec)%(link_libtsan)}"
810 : : #ifdef LIBTSAN_EARLY_SPEC
811 : : #define LIBTSAN_SPEC STATIC_LIBTSAN_LIBS
812 : : #elif defined(HAVE_LD_STATIC_DYNAMIC)
813 : : #define LIBTSAN_SPEC "%{static-libtsan:" LD_STATIC_OPTION \
814 : : "} -ltsan %{static-libtsan:" LD_DYNAMIC_OPTION "}" \
815 : : STATIC_LIBTSAN_LIBS
816 : : #else
817 : : #define LIBTSAN_SPEC "-ltsan" STATIC_LIBTSAN_LIBS
818 : : #endif
819 : : #endif
820 : :
821 : : #ifndef LIBTSAN_EARLY_SPEC
822 : : #define LIBTSAN_EARLY_SPEC ""
823 : : #endif
824 : :
825 : : #ifndef LIBLSAN_SPEC
826 : : #define STATIC_LIBLSAN_LIBS \
827 : : " %{static-liblsan|static:%:include(libsanitizer.spec)%(link_liblsan)}"
828 : : #ifdef LIBLSAN_EARLY_SPEC
829 : : #define LIBLSAN_SPEC STATIC_LIBLSAN_LIBS
830 : : #elif defined(HAVE_LD_STATIC_DYNAMIC)
831 : : #define LIBLSAN_SPEC "%{static-liblsan:" LD_STATIC_OPTION \
832 : : "} -llsan %{static-liblsan:" LD_DYNAMIC_OPTION "}" \
833 : : STATIC_LIBLSAN_LIBS
834 : : #else
835 : : #define LIBLSAN_SPEC "-llsan" STATIC_LIBLSAN_LIBS
836 : : #endif
837 : : #endif
838 : :
839 : : #ifndef LIBLSAN_EARLY_SPEC
840 : : #define LIBLSAN_EARLY_SPEC ""
841 : : #endif
842 : :
843 : : #ifndef LIBUBSAN_SPEC
844 : : #define STATIC_LIBUBSAN_LIBS \
845 : : " %{static-libubsan|static:%:include(libsanitizer.spec)%(link_libubsan)}"
846 : : #ifdef HAVE_LD_STATIC_DYNAMIC
847 : : #define LIBUBSAN_SPEC "%{static-libubsan:" LD_STATIC_OPTION \
848 : : "} -lubsan %{static-libubsan:" LD_DYNAMIC_OPTION "}" \
849 : : STATIC_LIBUBSAN_LIBS
850 : : #else
851 : : #define LIBUBSAN_SPEC "-lubsan" STATIC_LIBUBSAN_LIBS
852 : : #endif
853 : : #endif
854 : :
855 : : /* Linker options for compressed debug sections. */
856 : : #if HAVE_LD_COMPRESS_DEBUG == 0
857 : : /* No linker support. */
858 : : #define LINK_COMPRESS_DEBUG_SPEC \
859 : : " %{gz*:%e-gz is not supported in this configuration} "
860 : : #elif HAVE_LD_COMPRESS_DEBUG == 1
861 : : /* ELF gABI style. */
862 : : #define LINK_COMPRESS_DEBUG_SPEC \
863 : : " %{gz|gz=zlib:" LD_COMPRESS_DEBUG_OPTION "=zlib}" \
864 : : " %{gz=none:" LD_COMPRESS_DEBUG_OPTION "=none}" \
865 : : " %{gz=zstd:%e-gz=zstd is not supported in this configuration} " \
866 : : " %{gz=zlib-gnu:}" /* Ignore silently zlib-gnu option value. */
867 : : #elif HAVE_LD_COMPRESS_DEBUG == 2
868 : : /* ELF gABI style and ZSTD. */
869 : : #define LINK_COMPRESS_DEBUG_SPEC \
870 : : " %{gz|gz=zlib:" LD_COMPRESS_DEBUG_OPTION "=zlib}" \
871 : : " %{gz=none:" LD_COMPRESS_DEBUG_OPTION "=none}" \
872 : : " %{gz=zstd:" LD_COMPRESS_DEBUG_OPTION "=zstd}" \
873 : : " %{gz=zlib-gnu:}" /* Ignore silently zlib-gnu option value. */
874 : : #else
875 : : #error Unknown value for HAVE_LD_COMPRESS_DEBUG.
876 : : #endif
877 : :
878 : : /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
879 : : included. */
880 : : #ifndef LIBGCC_SPEC
881 : : #if defined(REAL_LIBGCC_SPEC)
882 : : #define LIBGCC_SPEC REAL_LIBGCC_SPEC
883 : : #elif defined(LINK_LIBGCC_SPECIAL_1)
884 : : /* Have gcc do the search for libgcc.a. */
885 : : #define LIBGCC_SPEC "libgcc.a%s"
886 : : #else
887 : : #define LIBGCC_SPEC "-lgcc"
888 : : #endif
889 : : #endif
890 : :
891 : : /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
892 : : #ifndef STARTFILE_SPEC
893 : : #define STARTFILE_SPEC \
894 : : "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
895 : : #endif
896 : :
897 : : /* config.h can define ENDFILE_SPEC to override the default crtn files. */
898 : : #ifndef ENDFILE_SPEC
899 : : #define ENDFILE_SPEC ""
900 : : #endif
901 : :
902 : : #ifndef LINKER_NAME
903 : : #define LINKER_NAME "collect2"
904 : : #endif
905 : :
906 : : #ifdef HAVE_AS_DEBUG_PREFIX_MAP
907 : : #define ASM_MAP " %{ffile-prefix-map=*:--debug-prefix-map %*} %{fdebug-prefix-map=*:--debug-prefix-map %*}"
908 : : #else
909 : : #define ASM_MAP ""
910 : : #endif
911 : :
912 : : /* Assembler options for compressed debug sections. */
913 : : #if HAVE_LD_COMPRESS_DEBUG == 0
914 : : /* Reject if the linker cannot write compressed debug sections. */
915 : : #define ASM_COMPRESS_DEBUG_SPEC \
916 : : " %{gz*:%e-gz is not supported in this configuration} "
917 : : #else /* HAVE_LD_COMPRESS_DEBUG >= 1 */
918 : : #if HAVE_AS_COMPRESS_DEBUG == 0
919 : : /* No assembler support. Ignore silently. */
920 : : #define ASM_COMPRESS_DEBUG_SPEC \
921 : : " %{gz*:} "
922 : : #elif HAVE_AS_COMPRESS_DEBUG == 1
923 : : /* ELF gABI style. */
924 : : #define ASM_COMPRESS_DEBUG_SPEC \
925 : : " %{gz|gz=zlib:" AS_COMPRESS_DEBUG_OPTION "=zlib}" \
926 : : " %{gz=none:" AS_COMPRESS_DEBUG_OPTION "=none}" \
927 : : " %{gz=zlib-gnu:}" /* Ignore silently zlib-gnu option value. */
928 : : #elif HAVE_AS_COMPRESS_DEBUG == 2
929 : : /* ELF gABI style and ZSTD. */
930 : : #define ASM_COMPRESS_DEBUG_SPEC \
931 : : " %{gz|gz=zlib:" AS_COMPRESS_DEBUG_OPTION "=zlib}" \
932 : : " %{gz=none:" AS_COMPRESS_DEBUG_OPTION "=none}" \
933 : : " %{gz=zstd:" AS_COMPRESS_DEBUG_OPTION "=zstd}" \
934 : : " %{gz=zlib-gnu:}" /* Ignore silently zlib-gnu option value. */
935 : : #else
936 : : #error Unknown value for HAVE_AS_COMPRESS_DEBUG.
937 : : #endif
938 : : #endif /* HAVE_LD_COMPRESS_DEBUG >= 1 */
939 : :
940 : : /* Define ASM_DEBUG_SPEC to be a spec suitable for translating '-g'
941 : : to the assembler, when compiling assembly sources only. */
942 : : #ifndef ASM_DEBUG_SPEC
943 : : # if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG)
944 : : /* If --gdwarf-N is supported and as can handle even compiler generated
945 : : .debug_line with it, supply --gdwarf-N in ASM_DEBUG_OPTION_SPEC rather
946 : : than in ASM_DEBUG_SPEC, so that it applies to both .s and .c etc.
947 : : compilations. */
948 : : # define ASM_DEBUG_DWARF_OPTION ""
949 : : # elif defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && !defined(HAVE_LD_BROKEN_PE_DWARF5)
950 : : # define ASM_DEBUG_DWARF_OPTION "%{%:dwarf-version-gt(4):--gdwarf-5;" \
951 : : "%:dwarf-version-gt(3):--gdwarf-4;" \
952 : : "%:dwarf-version-gt(2):--gdwarf-3;" \
953 : : ":--gdwarf2}"
954 : : # else
955 : : # define ASM_DEBUG_DWARF_OPTION "--gdwarf2"
956 : : # endif
957 : : # if defined(DWARF2_DEBUGGING_INFO) && defined(HAVE_AS_GDWARF2_DEBUG_FLAG)
958 : : # define ASM_DEBUG_SPEC "%{g*:%{%:debug-level-gt(0):" \
959 : : ASM_DEBUG_DWARF_OPTION "}}" ASM_MAP
960 : : # endif
961 : : # endif
962 : : #ifndef ASM_DEBUG_SPEC
963 : : # define ASM_DEBUG_SPEC ""
964 : : #endif
965 : :
966 : : /* Define ASM_DEBUG_OPTION_SPEC to be a spec suitable for translating '-g'
967 : : to the assembler when compiling all sources. */
968 : : #ifndef ASM_DEBUG_OPTION_SPEC
969 : : # if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG)
970 : : # define ASM_DEBUG_OPTION_DWARF_OPT \
971 : : "%{%:dwarf-version-gt(4):--gdwarf-5 ;" \
972 : : "%:dwarf-version-gt(3):--gdwarf-4 ;" \
973 : : "%:dwarf-version-gt(2):--gdwarf-3 ;" \
974 : : ":--gdwarf2 }"
975 : : # if defined(DWARF2_DEBUGGING_INFO)
976 : : # define ASM_DEBUG_OPTION_SPEC "%{g*:%{%:debug-level-gt(0):" \
977 : : ASM_DEBUG_OPTION_DWARF_OPT "}}"
978 : : # endif
979 : : # endif
980 : : #endif
981 : : #ifndef ASM_DEBUG_OPTION_SPEC
982 : : # define ASM_DEBUG_OPTION_SPEC ""
983 : : #endif
984 : :
985 : : /* Here is the spec for running the linker, after compiling all files. */
986 : :
987 : : /* This is overridable by the target in case they need to specify the
988 : : -lgcc and -lc order specially, yet not require them to override all
989 : : of LINK_COMMAND_SPEC. */
990 : : #ifndef LINK_GCC_C_SEQUENCE_SPEC
991 : : #define LINK_GCC_C_SEQUENCE_SPEC "%G %{!nolibc:%L %G}"
992 : : #endif
993 : :
994 : : #ifndef LINK_SSP_SPEC
995 : : #ifdef TARGET_LIBC_PROVIDES_SSP
996 : : #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \
997 : : "|fstack-protector-strong|fstack-protector-explicit:}"
998 : : #else
999 : : #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \
1000 : : "|fstack-protector-strong|fstack-protector-explicit" \
1001 : : ":-lssp_nonshared -lssp}"
1002 : : #endif
1003 : : #endif
1004 : :
1005 : : #ifdef ENABLE_DEFAULT_PIE
1006 : : #define PIE_SPEC "!no-pie"
1007 : : #define NO_FPIE1_SPEC "fno-pie"
1008 : : #define FPIE1_SPEC NO_FPIE1_SPEC ":;"
1009 : : #define NO_FPIE2_SPEC "fno-PIE"
1010 : : #define FPIE2_SPEC NO_FPIE2_SPEC ":;"
1011 : : #define NO_FPIE_SPEC NO_FPIE1_SPEC "|" NO_FPIE2_SPEC
1012 : : #define FPIE_SPEC NO_FPIE_SPEC ":;"
1013 : : #define NO_FPIC1_SPEC "fno-pic"
1014 : : #define FPIC1_SPEC NO_FPIC1_SPEC ":;"
1015 : : #define NO_FPIC2_SPEC "fno-PIC"
1016 : : #define FPIC2_SPEC NO_FPIC2_SPEC ":;"
1017 : : #define NO_FPIC_SPEC NO_FPIC1_SPEC "|" NO_FPIC2_SPEC
1018 : : #define FPIC_SPEC NO_FPIC_SPEC ":;"
1019 : : #define NO_FPIE1_AND_FPIC1_SPEC NO_FPIE1_SPEC "|" NO_FPIC1_SPEC
1020 : : #define FPIE1_OR_FPIC1_SPEC NO_FPIE1_AND_FPIC1_SPEC ":;"
1021 : : #define NO_FPIE2_AND_FPIC2_SPEC NO_FPIE2_SPEC "|" NO_FPIC2_SPEC
1022 : : #define FPIE2_OR_FPIC2_SPEC NO_FPIE2_AND_FPIC2_SPEC ":;"
1023 : : #define NO_FPIE_AND_FPIC_SPEC NO_FPIE_SPEC "|" NO_FPIC_SPEC
1024 : : #define FPIE_OR_FPIC_SPEC NO_FPIE_AND_FPIC_SPEC ":;"
1025 : : #else
1026 : : #define PIE_SPEC "pie"
1027 : : #define FPIE1_SPEC "fpie"
1028 : : #define NO_FPIE1_SPEC FPIE1_SPEC ":;"
1029 : : #define FPIE2_SPEC "fPIE"
1030 : : #define NO_FPIE2_SPEC FPIE2_SPEC ":;"
1031 : : #define FPIE_SPEC FPIE1_SPEC "|" FPIE2_SPEC
1032 : : #define NO_FPIE_SPEC FPIE_SPEC ":;"
1033 : : #define FPIC1_SPEC "fpic"
1034 : : #define NO_FPIC1_SPEC FPIC1_SPEC ":;"
1035 : : #define FPIC2_SPEC "fPIC"
1036 : : #define NO_FPIC2_SPEC FPIC2_SPEC ":;"
1037 : : #define FPIC_SPEC FPIC1_SPEC "|" FPIC2_SPEC
1038 : : #define NO_FPIC_SPEC FPIC_SPEC ":;"
1039 : : #define FPIE1_OR_FPIC1_SPEC FPIE1_SPEC "|" FPIC1_SPEC
1040 : : #define NO_FPIE1_AND_FPIC1_SPEC FPIE1_OR_FPIC1_SPEC ":;"
1041 : : #define FPIE2_OR_FPIC2_SPEC FPIE2_SPEC "|" FPIC2_SPEC
1042 : : #define NO_FPIE2_AND_FPIC2_SPEC FPIE1_OR_FPIC2_SPEC ":;"
1043 : : #define FPIE_OR_FPIC_SPEC FPIE_SPEC "|" FPIC_SPEC
1044 : : #define NO_FPIE_AND_FPIC_SPEC FPIE_OR_FPIC_SPEC ":;"
1045 : : #endif
1046 : :
1047 : : #ifndef LINK_PIE_SPEC
1048 : : #ifdef HAVE_LD_PIE
1049 : : #ifndef LD_PIE_SPEC
1050 : : #define LD_PIE_SPEC "-pie"
1051 : : #endif
1052 : : #else
1053 : : #define LD_PIE_SPEC ""
1054 : : #endif
1055 : : #define LINK_PIE_SPEC "%{static|shared|r:;" PIE_SPEC ":" LD_PIE_SPEC "} "
1056 : : #endif
1057 : :
1058 : : #ifndef LINK_BUILDID_SPEC
1059 : : # if defined(HAVE_LD_BUILDID) && defined(ENABLE_LD_BUILDID)
1060 : : # define LINK_BUILDID_SPEC "%{!r:--build-id} "
1061 : : # endif
1062 : : #endif
1063 : :
1064 : : #ifndef LTO_PLUGIN_SPEC
1065 : : #define LTO_PLUGIN_SPEC ""
1066 : : #endif
1067 : :
1068 : : /* Conditional to test whether the LTO plugin is used or not.
1069 : : FIXME: For slim LTO we will need to enable plugin unconditionally. This
1070 : : still cause problems with PLUGIN_LD != LD and when plugin is built but
1071 : : not useable. For GCC 4.6 we don't support slim LTO and thus we can enable
1072 : : plugin only when LTO is enabled. We still honor explicit
1073 : : -fuse-linker-plugin if the linker used understands -plugin. */
1074 : :
1075 : : /* The linker has some plugin support. */
1076 : : #if HAVE_LTO_PLUGIN > 0
1077 : : /* The linker used has full plugin support, use LTO plugin by default. */
1078 : : #if HAVE_LTO_PLUGIN == 2
1079 : : #define PLUGIN_COND "!fno-use-linker-plugin:%{!fno-lto"
1080 : : #define PLUGIN_COND_CLOSE "}"
1081 : : #else
1082 : : /* The linker used has limited plugin support, use LTO plugin with explicit
1083 : : -fuse-linker-plugin. */
1084 : : #define PLUGIN_COND "fuse-linker-plugin"
1085 : : #define PLUGIN_COND_CLOSE ""
1086 : : #endif
1087 : : #define LINK_PLUGIN_SPEC \
1088 : : "%{" PLUGIN_COND": \
1089 : : -plugin %(linker_plugin_file) \
1090 : : -plugin-opt=%(lto_wrapper) \
1091 : : -plugin-opt=-fresolution=%u.res \
1092 : : " LTO_PLUGIN_SPEC "\
1093 : : %{flinker-output=*:-plugin-opt=-linker-output-known} \
1094 : : %{!nostdlib:%{!nodefaultlibs:%:pass-through-libs(%(link_gcc_c_sequence))}} \
1095 : : }" PLUGIN_COND_CLOSE
1096 : : #else
1097 : : /* The linker used doesn't support -plugin, reject -fuse-linker-plugin. */
1098 : : #define LINK_PLUGIN_SPEC "%{fuse-linker-plugin:\
1099 : : %e-fuse-linker-plugin is not supported in this configuration}"
1100 : : #endif
1101 : :
1102 : : /* Linker command line options for -fsanitize= early on the command line. */
1103 : : #ifndef SANITIZER_EARLY_SPEC
1104 : : #define SANITIZER_EARLY_SPEC "\
1105 : : %{!nostdlib:%{!r:%{!nodefaultlibs:%{%:sanitize(address):" LIBASAN_EARLY_SPEC "} \
1106 : : %{%:sanitize(hwaddress):" LIBHWASAN_EARLY_SPEC "} \
1107 : : %{%:sanitize(thread):" LIBTSAN_EARLY_SPEC "} \
1108 : : %{%:sanitize(leak):" LIBLSAN_EARLY_SPEC "}}}}"
1109 : : #endif
1110 : :
1111 : : /* Linker command line options for -fsanitize= late on the command line. */
1112 : : #ifndef SANITIZER_SPEC
1113 : : #define SANITIZER_SPEC "\
1114 : : %{!nostdlib:%{!r:%{!nodefaultlibs:%{%:sanitize(address):" LIBASAN_SPEC "\
1115 : : %{static:%ecannot specify -static with -fsanitize=address}}\
1116 : : %{%:sanitize(hwaddress):" LIBHWASAN_SPEC "\
1117 : : %{static:%ecannot specify -static with -fsanitize=hwaddress}}\
1118 : : %{%:sanitize(thread):" LIBTSAN_SPEC "\
1119 : : %{static:%ecannot specify -static with -fsanitize=thread}}\
1120 : : %{%:sanitize(undefined):" LIBUBSAN_SPEC "}\
1121 : : %{%:sanitize(leak):" LIBLSAN_SPEC "}}}}"
1122 : : #endif
1123 : :
1124 : : #ifndef POST_LINK_SPEC
1125 : : #define POST_LINK_SPEC ""
1126 : : #endif
1127 : :
1128 : : /* This is the spec to use, once the code for creating the vtable
1129 : : verification runtime library, libvtv.so, has been created. Currently
1130 : : the vtable verification runtime functions are in libstdc++, so we use
1131 : : the spec just below this one. */
1132 : : #ifndef VTABLE_VERIFICATION_SPEC
1133 : : #if ENABLE_VTABLE_VERIFY
1134 : : #define VTABLE_VERIFICATION_SPEC "\
1135 : : %{!nostdlib:%{!r:%{fvtable-verify=std: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end}\
1136 : : %{fvtable-verify=preinit: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end}}}"
1137 : : #else
1138 : : #define VTABLE_VERIFICATION_SPEC "\
1139 : : %{fvtable-verify=none:} \
1140 : : %{fvtable-verify=std: \
1141 : : %e-fvtable-verify=std is not supported in this configuration} \
1142 : : %{fvtable-verify=preinit: \
1143 : : %e-fvtable-verify=preinit is not supported in this configuration}"
1144 : : #endif
1145 : : #endif
1146 : :
1147 : : /* -u* was put back because both BSD and SysV seem to support it. */
1148 : : /* %{static|no-pie|static-pie:} simply prevents an error message:
1149 : : 1. If the target machine doesn't handle -static.
1150 : : 2. If PIE isn't enabled by default.
1151 : : 3. If the target machine doesn't handle -static-pie.
1152 : : */
1153 : : /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
1154 : : scripts which exist in user specified directories, or in standard
1155 : : directories. */
1156 : : /* We pass any -flto flags on to the linker, which is expected
1157 : : to understand them. In practice, this means it had better be collect2. */
1158 : : /* %{e*} includes -export-dynamic; see comment in common.opt. */
1159 : : #ifndef LINK_COMMAND_SPEC
1160 : : #define LINK_COMMAND_SPEC "\
1161 : : %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
1162 : : %(linker) " \
1163 : : LINK_PLUGIN_SPEC \
1164 : : "%{flto|flto=*:%<fcompare-debug*} \
1165 : : %{flto} %{fno-lto} %{flto=*} %l " LINK_PIE_SPEC \
1166 : : "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \
1167 : : "%X %{o*} %{e*} %{N} %{n} %{r}\
1168 : : %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \
1169 : : %{static|no-pie|static-pie:} %@{L*} %(link_libgcc) " \
1170 : : VTABLE_VERIFICATION_SPEC " " SANITIZER_EARLY_SPEC " %o "" \
1171 : : %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\
1172 : : %:include(libgomp.spec)%(link_gomp)}\
1173 : : %{fgnu-tm:%:include(libitm.spec)%(link_itm)}\
1174 : : " STACK_SPLIT_SPEC "\
1175 : : %{fprofile-arcs|fcondition-coverage|fpath-coverage|fprofile-generate*|coverage:-lgcov} " SANITIZER_SPEC " \
1176 : : %{!nostdlib:%{!r:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}}\
1177 : : %{!nostdlib:%{!r:%{!nostartfiles:%E}}} %{T*} \n%(post_link) }}}}}}"
1178 : : #endif
1179 : :
1180 : : #ifndef LINK_LIBGCC_SPEC
1181 : : /* Generate -L options for startfile prefix list. */
1182 : : # define LINK_LIBGCC_SPEC "%D"
1183 : : #endif
1184 : :
1185 : : #ifndef STARTFILE_PREFIX_SPEC
1186 : : # define STARTFILE_PREFIX_SPEC ""
1187 : : #endif
1188 : :
1189 : : #ifndef SYSROOT_SPEC
1190 : : # define SYSROOT_SPEC "--sysroot=%R"
1191 : : #endif
1192 : :
1193 : : #ifndef SYSROOT_SUFFIX_SPEC
1194 : : # define SYSROOT_SUFFIX_SPEC ""
1195 : : #endif
1196 : :
1197 : : #ifndef SYSROOT_HEADERS_SUFFIX_SPEC
1198 : : # define SYSROOT_HEADERS_SUFFIX_SPEC ""
1199 : : #endif
1200 : :
1201 : : #ifndef RUNPATH_OPTION
1202 : : # define RUNPATH_OPTION "-rpath"
1203 : : #endif
1204 : :
1205 : : static const char *asm_debug = ASM_DEBUG_SPEC;
1206 : : static const char *asm_debug_option = ASM_DEBUG_OPTION_SPEC;
1207 : : static const char *cpp_spec = CPP_SPEC;
1208 : : static const char *cc1_spec = CC1_SPEC OS_CC1_SPEC;
1209 : : static const char *cc1plus_spec = CC1PLUS_SPEC;
1210 : : static const char *link_gcc_c_sequence_spec = LINK_GCC_C_SEQUENCE_SPEC;
1211 : : static const char *link_ssp_spec = LINK_SSP_SPEC;
1212 : : static const char *asm_spec = ASM_SPEC;
1213 : : static const char *asm_final_spec = ASM_FINAL_SPEC;
1214 : : static const char *link_spec = LINK_SPEC;
1215 : : static const char *lib_spec = LIB_SPEC;
1216 : : static const char *link_gomp_spec = "";
1217 : : static const char *libgcc_spec = LIBGCC_SPEC;
1218 : : static const char *endfile_spec = ENDFILE_SPEC;
1219 : : static const char *startfile_spec = STARTFILE_SPEC;
1220 : : static const char *linker_name_spec = LINKER_NAME;
1221 : : static const char *linker_plugin_file_spec = "";
1222 : : static const char *lto_wrapper_spec = "";
1223 : : static const char *lto_gcc_spec = "";
1224 : : static const char *post_link_spec = POST_LINK_SPEC;
1225 : : static const char *link_command_spec = LINK_COMMAND_SPEC;
1226 : : static const char *link_libgcc_spec = LINK_LIBGCC_SPEC;
1227 : : static const char *startfile_prefix_spec = STARTFILE_PREFIX_SPEC;
1228 : : static const char *sysroot_spec = SYSROOT_SPEC;
1229 : : static const char *sysroot_suffix_spec = SYSROOT_SUFFIX_SPEC;
1230 : : static const char *sysroot_hdrs_suffix_spec = SYSROOT_HEADERS_SUFFIX_SPEC;
1231 : : static const char *self_spec = "";
1232 : :
1233 : : /* Standard options to cpp, cc1, and as, to reduce duplication in specs.
1234 : : There should be no need to override these in target dependent files,
1235 : : but we need to copy them to the specs file so that newer versions
1236 : : of the GCC driver can correctly drive older tool chains with the
1237 : : appropriate -B options. */
1238 : :
1239 : : /* When cpplib handles traditional preprocessing, get rid of this, and
1240 : : call cc1 (or cc1obj in objc/lang-specs.h) from the main specs so
1241 : : that we default the front end language better. */
1242 : : static const char *trad_capable_cpp =
1243 : : "cc1 -E %{traditional|traditional-cpp:-traditional-cpp}";
1244 : :
1245 : : /* We don't wrap .d files in %W{} since a missing .d file, and
1246 : : therefore no dependency entry, confuses make into thinking a .o
1247 : : file that happens to exist is up-to-date. */
1248 : : static const char *cpp_unique_options =
1249 : : "%{!Q:-quiet} %{nostdinc*} %{C} %{CC} %{v} %@{I*&F*} %{P} %I\
1250 : : %{MD:-MD %{!o:%b.d}%{o*:%.d%*}}\
1251 : : %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}}\
1252 : : %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\
1253 : : %{Mmodules} %{Mno-modules}\
1254 : : %{!E:%{!M:%{!MM:%{!MT:%{!MQ:%{MD|MMD:%{o*:-MQ %*}}}}}}}\
1255 : : %{remap} %{%:debug-level-gt(2):-dD}\
1256 : : %{!iplugindir*:%{fplugin*:%:find-plugindir()}}\
1257 : : %{H} %C %{D*&U*&A*} %{i*} %Z %i\
1258 : : %{E|M|MM:%W{o*}} %{-embed*}\
1259 : : %{fdeps-format=*:%{!fdeps-file=*:-fdeps-file=%:join(%{!o:%b.ddi}%{o*:%.ddi%*})}}\
1260 : : %{fdeps-format=*:%{!fdeps-target=*:-fdeps-target=%:join(%{!o:%b.o}%{o*:%.o%*})}}";
1261 : :
1262 : : /* This contains cpp options which are common with cc1_options and are passed
1263 : : only when preprocessing only to avoid duplication. We pass the cc1 spec
1264 : : options to the preprocessor so that it the cc1 spec may manipulate
1265 : : options used to set target flags. Those special target flags settings may
1266 : : in turn cause preprocessor symbols to be defined specially. */
1267 : : static const char *cpp_options =
1268 : : "%(cpp_unique_options) %1 %{m*} %{std*&ansi&trigraphs} %{W*&pedantic*} %{w}\
1269 : : %{f*} %{g*:%{%:debug-level-gt(0):%{g*}\
1270 : : %{!fno-working-directory:-fworking-directory}}} %{O*}\
1271 : : %{undef} %{save-temps*:-fpch-preprocess}";
1272 : :
1273 : : /* Pass -d* flags, possibly modifying -dumpdir, -dumpbase et al.
1274 : :
1275 : : Make it easy for a language to override the argument for the
1276 : : %:dumps specs function call. */
1277 : : #define DUMPS_OPTIONS(EXTS) \
1278 : : "%<dumpdir %<dumpbase %<dumpbase-ext %{d*} %:dumps(" EXTS ")"
1279 : :
1280 : : /* This contains cpp options which are not passed when the preprocessor
1281 : : output will be used by another program. */
1282 : : static const char *cpp_debug_options = DUMPS_OPTIONS ("");
1283 : :
1284 : : /* NB: This is shared amongst all front-ends, except for Ada. */
1285 : : static const char *cc1_options =
1286 : : "%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
1287 : : %{!iplugindir*:%{fplugin*:%:find-plugindir()}}\
1288 : : %1 %{!Q:-quiet} %(cpp_debug_options) %{m*} %{aux-info*}\
1289 : : %{g*} %{O*} %{W*&pedantic*} %{w} %{std*&ansi&trigraphs}\
1290 : : %{v:-version} %{pg:-p} %{p} %{f*} %{undef}\
1291 : : %{Qn:-fno-ident} %{Qy:} %{-help:--help}\
1292 : : %{-target-help:--target-help}\
1293 : : %{-version:--version}\
1294 : : %{-help=*:--help=%*}\
1295 : : %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %w%b.s}}}\
1296 : : %{fsyntax-only:-o %j} %{-param*}\
1297 : : %{coverage:-fprofile-arcs -ftest-coverage}\
1298 : : %{fprofile-arcs|fcondition-coverage|fpath-coverage|fprofile-generate*|coverage:\
1299 : : %{!fprofile-update=single:\
1300 : : %{pthread:-fprofile-update=prefer-atomic}}}";
1301 : :
1302 : : static const char *asm_options =
1303 : : "%{-target-help:%:print-asm-header()} "
1304 : : #if HAVE_GNU_AS
1305 : : /* If GNU AS is used, then convert -w (no warnings), -I, and -v
1306 : : to the assembler equivalents. */
1307 : : "%{v} %{w:-W} %{I*} "
1308 : : #endif
1309 : : "%(asm_debug_option)"
1310 : : ASM_COMPRESS_DEBUG_SPEC
1311 : : "%a %Y %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}";
1312 : :
1313 : : static const char *invoke_as =
1314 : : #ifdef AS_NEEDS_DASH_FOR_PIPED_INPUT
1315 : : "%{!fwpa*:\
1316 : : %{fcompare-debug=*|fdump-final-insns=*:%:compare-debug-dump-opt()}\
1317 : : %{!S:-o %|.s |\n as %(asm_options) %|.s %A }\
1318 : : }";
1319 : : #else
1320 : : "%{!fwpa*:\
1321 : : %{fcompare-debug=*|fdump-final-insns=*:%:compare-debug-dump-opt()}\
1322 : : %{!S:-o %|.s |\n as %(asm_options) %m.s %A }\
1323 : : }";
1324 : : #endif
1325 : :
1326 : : /* Some compilers have limits on line lengths, and the multilib_select
1327 : : and/or multilib_matches strings can be very long, so we build them at
1328 : : run time. */
1329 : : static struct obstack multilib_obstack;
1330 : : static const char *multilib_select;
1331 : : static const char *multilib_matches;
1332 : : static const char *multilib_defaults;
1333 : : static const char *multilib_exclusions;
1334 : : static const char *multilib_reuse;
1335 : :
1336 : : /* Check whether a particular argument is a default argument. */
1337 : :
1338 : : #ifndef MULTILIB_DEFAULTS
1339 : : #define MULTILIB_DEFAULTS { "" }
1340 : : #endif
1341 : :
1342 : : static const char *const multilib_defaults_raw[] = MULTILIB_DEFAULTS;
1343 : :
1344 : : #ifndef DRIVER_SELF_SPECS
1345 : : #define DRIVER_SELF_SPECS ""
1346 : : #endif
1347 : :
1348 : : /* Linking to libgomp implies pthreads. This is particularly important
1349 : : for targets that use different start files and suchlike. */
1350 : : #ifndef GOMP_SELF_SPECS
1351 : : #define GOMP_SELF_SPECS \
1352 : : "%{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1): " \
1353 : : "-pthread}"
1354 : : #endif
1355 : :
1356 : : /* Likewise for -fgnu-tm. */
1357 : : #ifndef GTM_SELF_SPECS
1358 : : #define GTM_SELF_SPECS "%{fgnu-tm: -pthread}"
1359 : : #endif
1360 : :
1361 : : static const char *const driver_self_specs[] = {
1362 : : "%{fdump-final-insns:-fdump-final-insns=.} %<fdump-final-insns",
1363 : : DRIVER_SELF_SPECS, CONFIGURE_SPECS, GOMP_SELF_SPECS, GTM_SELF_SPECS,
1364 : : /* This discards -fmultiflags at the end of self specs processing in the
1365 : : driver, so that it is effectively Ignored, without actually marking it as
1366 : : Ignored, which would get it discarded before self specs could remap it. */
1367 : : "%<fmultiflags"
1368 : : };
1369 : :
1370 : : #ifndef OPTION_DEFAULT_SPECS
1371 : : #define OPTION_DEFAULT_SPECS { "", "" }
1372 : : #endif
1373 : :
1374 : : struct default_spec
1375 : : {
1376 : : const char *name;
1377 : : const char *spec;
1378 : : };
1379 : :
1380 : : static const struct default_spec
1381 : : option_default_specs[] = { OPTION_DEFAULT_SPECS };
1382 : :
1383 : : struct user_specs
1384 : : {
1385 : : struct user_specs *next;
1386 : : const char *filename;
1387 : : };
1388 : :
1389 : : static struct user_specs *user_specs_head, *user_specs_tail;
1390 : :
1391 : :
1392 : : /* Record the mapping from file suffixes for compilation specs. */
1393 : :
1394 : : struct compiler
1395 : : {
1396 : : const char *suffix; /* Use this compiler for input files
1397 : : whose names end in this suffix. */
1398 : :
1399 : : const char *spec; /* To use this compiler, run this spec. */
1400 : :
1401 : : const char *cpp_spec; /* If non-NULL, substitute this spec
1402 : : for `%C', rather than the usual
1403 : : cpp_spec. */
1404 : : int combinable; /* If nonzero, compiler can deal with
1405 : : multiple source files at once (IMA). */
1406 : : int needs_preprocessing; /* If nonzero, source files need to
1407 : : be run through a preprocessor. */
1408 : : };
1409 : :
1410 : : /* Pointer to a vector of `struct compiler' that gives the spec for
1411 : : compiling a file, based on its suffix.
1412 : : A file that does not end in any of these suffixes will be passed
1413 : : unchanged to the loader and nothing else will be done to it.
1414 : :
1415 : : An entry containing two 0s is used to terminate the vector.
1416 : :
1417 : : If multiple entries match a file, the last matching one is used. */
1418 : :
1419 : : static struct compiler *compilers;
1420 : :
1421 : : /* Number of entries in `compilers', not counting the null terminator. */
1422 : :
1423 : : static int n_compilers;
1424 : :
1425 : : /* The default list of file name suffixes and their compilation specs. */
1426 : :
1427 : : static const struct compiler default_compilers[] =
1428 : : {
1429 : : /* Add lists of suffixes of known languages here. If those languages
1430 : : were not present when we built the driver, we will hit these copies
1431 : : and be given a more meaningful error than "file not used since
1432 : : linking is not done". */
1433 : : {".m", "#Objective-C", 0, 0, 0}, {".mi", "#Objective-C", 0, 0, 0},
1434 : : {".mm", "#Objective-C++", 0, 0, 0}, {".M", "#Objective-C++", 0, 0, 0},
1435 : : {".mii", "#Objective-C++", 0, 0, 0},
1436 : : {".cc", "#C++", 0, 0, 0}, {".cxx", "#C++", 0, 0, 0},
1437 : : {".cpp", "#C++", 0, 0, 0}, {".cp", "#C++", 0, 0, 0},
1438 : : {".c++", "#C++", 0, 0, 0}, {".C", "#C++", 0, 0, 0},
1439 : : {".CPP", "#C++", 0, 0, 0}, {".ii", "#C++", 0, 0, 0},
1440 : : {".ads", "#Ada", 0, 0, 0}, {".adb", "#Ada", 0, 0, 0},
1441 : : {".f", "#Fortran", 0, 0, 0}, {".F", "#Fortran", 0, 0, 0},
1442 : : {".for", "#Fortran", 0, 0, 0}, {".FOR", "#Fortran", 0, 0, 0},
1443 : : {".ftn", "#Fortran", 0, 0, 0}, {".FTN", "#Fortran", 0, 0, 0},
1444 : : {".fpp", "#Fortran", 0, 0, 0}, {".FPP", "#Fortran", 0, 0, 0},
1445 : : {".f90", "#Fortran", 0, 0, 0}, {".F90", "#Fortran", 0, 0, 0},
1446 : : {".f95", "#Fortran", 0, 0, 0}, {".F95", "#Fortran", 0, 0, 0},
1447 : : {".f03", "#Fortran", 0, 0, 0}, {".F03", "#Fortran", 0, 0, 0},
1448 : : {".f08", "#Fortran", 0, 0, 0}, {".F08", "#Fortran", 0, 0, 0},
1449 : : {".r", "#Ratfor", 0, 0, 0},
1450 : : {".go", "#Go", 0, 1, 0},
1451 : : {".d", "#D", 0, 1, 0}, {".dd", "#D", 0, 1, 0}, {".di", "#D", 0, 1, 0},
1452 : : {".mod", "#Modula-2", 0, 0, 0}, {".m2i", "#Modula-2", 0, 0, 0},
1453 : : /* Next come the entries for C. */
1454 : : {".c", "@c", 0, 0, 1},
1455 : : {"@c",
1456 : : /* cc1 has an integrated ISO C preprocessor. We should invoke the
1457 : : external preprocessor if -save-temps is given. */
1458 : : "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\
1459 : : %{!E:%{!M:%{!MM:\
1460 : : %{traditional:\
1461 : : %eGNU C no longer supports -traditional without -E}\
1462 : : %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \
1463 : : %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\
1464 : : cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \
1465 : : %(cc1_options)}\
1466 : : %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\
1467 : : cc1 %(cpp_unique_options) %(cc1_options)}}}\
1468 : : %{!fsyntax-only:%(invoke_as)}}}}", 0, 0, 1},
1469 : : {"-",
1470 : : "%{!E:%e-E or -x required when input is from standard input}\
1471 : : %(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)", 0, 0, 0},
1472 : : {".h", "@c-header", 0, 0, 0},
1473 : : {"@c-header",
1474 : : /* cc1 has an integrated ISO C preprocessor. We should invoke the
1475 : : external preprocessor if -save-temps is given. */
1476 : : "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\
1477 : : %{!E:%{!M:%{!MM:\
1478 : : %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \
1479 : : %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\
1480 : : cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \
1481 : : %(cc1_options)\
1482 : : %{!fsyntax-only:%{!S:-o %g.s} \
1483 : : %{!fdump-ada-spec*:%{!o*:--output-pch %w%i.gch}\
1484 : : %W{o*:--output-pch %w%*}}%{!S:%V}}}\
1485 : : %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\
1486 : : cc1 %(cpp_unique_options) %(cc1_options)\
1487 : : %{!fsyntax-only:%{!S:-o %g.s} \
1488 : : %{!fdump-ada-spec*:%{!o*:--output-pch %w%i.gch}\
1489 : : %W{o*:--output-pch %w%*}}%{!S:%V}}}}}}}}", 0, 0, 0},
1490 : : {".i", "@cpp-output", 0, 0, 0},
1491 : : {"@cpp-output",
1492 : : "%{!M:%{!MM:%{!E:cc1 -fpreprocessed %i %(cc1_options) %{!fsyntax-only:%(invoke_as)}}}}", 0, 0, 0},
1493 : : {".s", "@assembler", 0, 0, 0},
1494 : : {"@assembler",
1495 : : "%{!M:%{!MM:%{!E:%{!S:as %(asm_debug) %(asm_options) %i %A }}}}", 0, 0, 0},
1496 : : {".sx", "@assembler-with-cpp", 0, 0, 0},
1497 : : {".S", "@assembler-with-cpp", 0, 0, 0},
1498 : : {"@assembler-with-cpp",
1499 : : #ifdef AS_NEEDS_DASH_FOR_PIPED_INPUT
1500 : : "%(trad_capable_cpp) -lang-asm %(cpp_options) -fno-directives-only\
1501 : : %{E|M|MM:%(cpp_debug_options)}\
1502 : : %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\
1503 : : as %(asm_debug) %(asm_options) %|.s %A }}}}"
1504 : : #else
1505 : : "%(trad_capable_cpp) -lang-asm %(cpp_options) -fno-directives-only\
1506 : : %{E|M|MM:%(cpp_debug_options)}\
1507 : : %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\
1508 : : as %(asm_debug) %(asm_options) %m.s %A }}}}"
1509 : : #endif
1510 : : , 0, 0, 0},
1511 : :
1512 : : #include "specs.h"
1513 : : /* Mark end of table. */
1514 : : {0, 0, 0, 0, 0}
1515 : : };
1516 : :
1517 : : /* Number of elements in default_compilers, not counting the terminator. */
1518 : :
1519 : : static const int n_default_compilers = ARRAY_SIZE (default_compilers) - 1;
1520 : :
1521 : : typedef char *char_p; /* For DEF_VEC_P. */
1522 : :
1523 : : /* A vector of options to give to the linker.
1524 : : These options are accumulated by %x,
1525 : : and substituted into the linker command with %X. */
1526 : : static vec<char_p> linker_options;
1527 : :
1528 : : /* A vector of options to give to the assembler.
1529 : : These options are accumulated by -Wa,
1530 : : and substituted into the assembler command with %Y. */
1531 : : static vec<char_p> assembler_options;
1532 : :
1533 : : /* A vector of options to give to the preprocessor.
1534 : : These options are accumulated by -Wp,
1535 : : and substituted into the preprocessor command with %Z. */
1536 : : static vec<char_p> preprocessor_options;
1537 : :
1538 : : static char *
1539 : 27330524 : skip_whitespace (char *p)
1540 : : {
1541 : 63344335 : while (1)
1542 : : {
1543 : : /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1544 : : be considered whitespace. */
1545 : 63344335 : if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n')
1546 : 4585504 : return p + 1;
1547 : 58758831 : else if (*p == '\n' || *p == ' ' || *p == '\t')
1548 : 35898327 : p++;
1549 : 22860504 : else if (*p == '#')
1550 : : {
1551 : 3571106 : while (*p != '\n')
1552 : 3455622 : p++;
1553 : 115484 : p++;
1554 : : }
1555 : : else
1556 : : break;
1557 : : }
1558 : :
1559 : : return p;
1560 : : }
1561 : : /* Structures to keep track of prefixes to try when looking for files. */
1562 : :
1563 : : struct prefix_list
1564 : : {
1565 : : const char *prefix; /* String to prepend to the path. */
1566 : : struct prefix_list *next; /* Next in linked list. */
1567 : : int require_machine_suffix; /* Don't use without machine_suffix. */
1568 : : /* 2 means try both machine_suffix and just_machine_suffix. */
1569 : : int priority; /* Sort key - priority within list. */
1570 : : int os_multilib; /* 1 if OS multilib scheme should be used,
1571 : : 0 for GCC multilib scheme. */
1572 : : };
1573 : :
1574 : : struct path_prefix
1575 : : {
1576 : : struct prefix_list *plist; /* List of prefixes to try */
1577 : : int max_len; /* Max length of a prefix in PLIST */
1578 : : const char *name; /* Name of this list (used in config stuff) */
1579 : : };
1580 : :
1581 : : /* List of prefixes to try when looking for executables. */
1582 : :
1583 : : static struct path_prefix exec_prefixes = { 0, 0, "exec" };
1584 : :
1585 : : /* List of prefixes to try when looking for startup (crt0) files. */
1586 : :
1587 : : static struct path_prefix startfile_prefixes = { 0, 0, "startfile" };
1588 : :
1589 : : /* List of prefixes to try when looking for include files. */
1590 : :
1591 : : static struct path_prefix include_prefixes = { 0, 0, "include" };
1592 : :
1593 : : /* Suffix to attach to directories searched for commands.
1594 : : This looks like `MACHINE/VERSION/'. */
1595 : :
1596 : : static const char *machine_suffix = 0;
1597 : :
1598 : : /* Suffix to attach to directories searched for commands.
1599 : : This is just `MACHINE/'. */
1600 : :
1601 : : static const char *just_machine_suffix = 0;
1602 : :
1603 : : /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1604 : :
1605 : : static const char *gcc_exec_prefix;
1606 : :
1607 : : /* Adjusted value of standard_libexec_prefix. */
1608 : :
1609 : : static const char *gcc_libexec_prefix;
1610 : :
1611 : : /* Default prefixes to attach to command names. */
1612 : :
1613 : : #ifndef STANDARD_STARTFILE_PREFIX_1
1614 : : #define STANDARD_STARTFILE_PREFIX_1 "/lib/"
1615 : : #endif
1616 : : #ifndef STANDARD_STARTFILE_PREFIX_2
1617 : : #define STANDARD_STARTFILE_PREFIX_2 "/usr/lib/"
1618 : : #endif
1619 : :
1620 : : #ifdef CROSS_DIRECTORY_STRUCTURE /* Don't use these prefixes for a cross compiler. */
1621 : : #undef MD_EXEC_PREFIX
1622 : : #undef MD_STARTFILE_PREFIX
1623 : : #undef MD_STARTFILE_PREFIX_1
1624 : : #endif
1625 : :
1626 : : /* If no prefixes defined, use the null string, which will disable them. */
1627 : : #ifndef MD_EXEC_PREFIX
1628 : : #define MD_EXEC_PREFIX ""
1629 : : #endif
1630 : : #ifndef MD_STARTFILE_PREFIX
1631 : : #define MD_STARTFILE_PREFIX ""
1632 : : #endif
1633 : : #ifndef MD_STARTFILE_PREFIX_1
1634 : : #define MD_STARTFILE_PREFIX_1 ""
1635 : : #endif
1636 : :
1637 : : /* These directories are locations set at configure-time based on the
1638 : : --prefix option provided to configure. Their initializers are
1639 : : defined in Makefile.in. These paths are not *directly* used when
1640 : : gcc_exec_prefix is set because, in that case, we know where the
1641 : : compiler has been installed, and use paths relative to that
1642 : : location instead. */
1643 : : static const char *const standard_exec_prefix = STANDARD_EXEC_PREFIX;
1644 : : static const char *const standard_libexec_prefix = STANDARD_LIBEXEC_PREFIX;
1645 : : static const char *const standard_bindir_prefix = STANDARD_BINDIR_PREFIX;
1646 : : static const char *const standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
1647 : :
1648 : : /* For native compilers, these are well-known paths containing
1649 : : components that may be provided by the system. For cross
1650 : : compilers, these paths are not used. */
1651 : : static const char *md_exec_prefix = MD_EXEC_PREFIX;
1652 : : static const char *md_startfile_prefix = MD_STARTFILE_PREFIX;
1653 : : static const char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
1654 : : static const char *const standard_startfile_prefix_1
1655 : : = STANDARD_STARTFILE_PREFIX_1;
1656 : : static const char *const standard_startfile_prefix_2
1657 : : = STANDARD_STARTFILE_PREFIX_2;
1658 : :
1659 : : /* A relative path to be used in finding the location of tools
1660 : : relative to the driver. */
1661 : : static const char *const tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
1662 : :
1663 : : /* A prefix to be used when this is an accelerator compiler. */
1664 : : static const char *const accel_dir_suffix = ACCEL_DIR_SUFFIX;
1665 : :
1666 : : /* Subdirectory to use for locating libraries. Set by
1667 : : set_multilib_dir based on the compilation options. */
1668 : :
1669 : : static const char *multilib_dir;
1670 : :
1671 : : /* Subdirectory to use for locating libraries in OS conventions. Set by
1672 : : set_multilib_dir based on the compilation options. */
1673 : :
1674 : : static const char *multilib_os_dir;
1675 : :
1676 : : /* Subdirectory to use for locating libraries in multiarch conventions. Set by
1677 : : set_multilib_dir based on the compilation options. */
1678 : :
1679 : : static const char *multiarch_dir;
1680 : :
1681 : : /* Structure to keep track of the specs that have been defined so far.
1682 : : These are accessed using %(specname) in a compiler or link
1683 : : spec. */
1684 : :
1685 : : struct spec_list
1686 : : {
1687 : : /* The following 2 fields must be first */
1688 : : /* to allow EXTRA_SPECS to be initialized */
1689 : : const char *name; /* name of the spec. */
1690 : : const char *ptr; /* available ptr if no static pointer */
1691 : :
1692 : : /* The following fields are not initialized */
1693 : : /* by EXTRA_SPECS */
1694 : : const char **ptr_spec; /* pointer to the spec itself. */
1695 : : struct spec_list *next; /* Next spec in linked list. */
1696 : : int name_len; /* length of the name */
1697 : : bool user_p; /* whether string come from file spec. */
1698 : : bool alloc_p; /* whether string was allocated */
1699 : : const char *default_ptr; /* The default value of *ptr_spec. */
1700 : : };
1701 : :
1702 : : #define INIT_STATIC_SPEC(NAME,PTR) \
1703 : : { NAME, NULL, PTR, (struct spec_list *) 0, sizeof (NAME) - 1, false, false, \
1704 : : *PTR }
1705 : :
1706 : : /* List of statically defined specs. */
1707 : : static struct spec_list static_specs[] =
1708 : : {
1709 : : INIT_STATIC_SPEC ("asm", &asm_spec),
1710 : : INIT_STATIC_SPEC ("asm_debug", &asm_debug),
1711 : : INIT_STATIC_SPEC ("asm_debug_option", &asm_debug_option),
1712 : : INIT_STATIC_SPEC ("asm_final", &asm_final_spec),
1713 : : INIT_STATIC_SPEC ("asm_options", &asm_options),
1714 : : INIT_STATIC_SPEC ("invoke_as", &invoke_as),
1715 : : INIT_STATIC_SPEC ("cpp", &cpp_spec),
1716 : : INIT_STATIC_SPEC ("cpp_options", &cpp_options),
1717 : : INIT_STATIC_SPEC ("cpp_debug_options", &cpp_debug_options),
1718 : : INIT_STATIC_SPEC ("cpp_unique_options", &cpp_unique_options),
1719 : : INIT_STATIC_SPEC ("trad_capable_cpp", &trad_capable_cpp),
1720 : : INIT_STATIC_SPEC ("cc1", &cc1_spec),
1721 : : INIT_STATIC_SPEC ("cc1_options", &cc1_options),
1722 : : INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec),
1723 : : INIT_STATIC_SPEC ("link_gcc_c_sequence", &link_gcc_c_sequence_spec),
1724 : : INIT_STATIC_SPEC ("link_ssp", &link_ssp_spec),
1725 : : INIT_STATIC_SPEC ("endfile", &endfile_spec),
1726 : : INIT_STATIC_SPEC ("link", &link_spec),
1727 : : INIT_STATIC_SPEC ("lib", &lib_spec),
1728 : : INIT_STATIC_SPEC ("link_gomp", &link_gomp_spec),
1729 : : INIT_STATIC_SPEC ("libgcc", &libgcc_spec),
1730 : : INIT_STATIC_SPEC ("startfile", &startfile_spec),
1731 : : INIT_STATIC_SPEC ("cross_compile", &cross_compile),
1732 : : INIT_STATIC_SPEC ("version", &compiler_version),
1733 : : INIT_STATIC_SPEC ("multilib", &multilib_select),
1734 : : INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults),
1735 : : INIT_STATIC_SPEC ("multilib_extra", &multilib_extra),
1736 : : INIT_STATIC_SPEC ("multilib_matches", &multilib_matches),
1737 : : INIT_STATIC_SPEC ("multilib_exclusions", &multilib_exclusions),
1738 : : INIT_STATIC_SPEC ("multilib_options", &multilib_options),
1739 : : INIT_STATIC_SPEC ("multilib_reuse", &multilib_reuse),
1740 : : INIT_STATIC_SPEC ("linker", &linker_name_spec),
1741 : : INIT_STATIC_SPEC ("linker_plugin_file", &linker_plugin_file_spec),
1742 : : INIT_STATIC_SPEC ("lto_wrapper", <o_wrapper_spec),
1743 : : INIT_STATIC_SPEC ("lto_gcc", <o_gcc_spec),
1744 : : INIT_STATIC_SPEC ("post_link", &post_link_spec),
1745 : : INIT_STATIC_SPEC ("link_libgcc", &link_libgcc_spec),
1746 : : INIT_STATIC_SPEC ("md_exec_prefix", &md_exec_prefix),
1747 : : INIT_STATIC_SPEC ("md_startfile_prefix", &md_startfile_prefix),
1748 : : INIT_STATIC_SPEC ("md_startfile_prefix_1", &md_startfile_prefix_1),
1749 : : INIT_STATIC_SPEC ("startfile_prefix_spec", &startfile_prefix_spec),
1750 : : INIT_STATIC_SPEC ("sysroot_spec", &sysroot_spec),
1751 : : INIT_STATIC_SPEC ("sysroot_suffix_spec", &sysroot_suffix_spec),
1752 : : INIT_STATIC_SPEC ("sysroot_hdrs_suffix_spec", &sysroot_hdrs_suffix_spec),
1753 : : INIT_STATIC_SPEC ("self_spec", &self_spec),
1754 : : };
1755 : :
1756 : : #ifdef EXTRA_SPECS /* additional specs needed */
1757 : : /* Structure to keep track of just the first two args of a spec_list.
1758 : : That is all that the EXTRA_SPECS macro gives us. */
1759 : : struct spec_list_1
1760 : : {
1761 : : const char *const name;
1762 : : const char *const ptr;
1763 : : };
1764 : :
1765 : : static const struct spec_list_1 extra_specs_1[] = { EXTRA_SPECS };
1766 : : static struct spec_list *extra_specs = (struct spec_list *) 0;
1767 : : #endif
1768 : :
1769 : : /* List of dynamically allocates specs that have been defined so far. */
1770 : :
1771 : : static struct spec_list *specs = (struct spec_list *) 0;
1772 : :
1773 : : /* List of static spec functions. */
1774 : :
1775 : : static const struct spec_function static_spec_functions[] =
1776 : : {
1777 : : { "getenv", getenv_spec_function },
1778 : : { "if-exists", if_exists_spec_function },
1779 : : { "if-exists-else", if_exists_else_spec_function },
1780 : : { "if-exists-then-else", if_exists_then_else_spec_function },
1781 : : { "sanitize", sanitize_spec_function },
1782 : : { "replace-outfile", replace_outfile_spec_function },
1783 : : { "remove-outfile", remove_outfile_spec_function },
1784 : : { "version-compare", version_compare_spec_function },
1785 : : { "include", include_spec_function },
1786 : : { "find-file", find_file_spec_function },
1787 : : { "find-plugindir", find_plugindir_spec_function },
1788 : : { "print-asm-header", print_asm_header_spec_function },
1789 : : { "compare-debug-dump-opt", compare_debug_dump_opt_spec_function },
1790 : : { "compare-debug-self-opt", compare_debug_self_opt_spec_function },
1791 : : { "pass-through-libs", pass_through_libs_spec_func },
1792 : : { "dumps", dumps_spec_func },
1793 : : { "gt", greater_than_spec_func },
1794 : : { "debug-level-gt", debug_level_greater_than_spec_func },
1795 : : { "dwarf-version-gt", dwarf_version_greater_than_spec_func },
1796 : : { "fortran-preinclude-file", find_fortran_preinclude_file},
1797 : : { "join", join_spec_func},
1798 : : #ifdef EXTRA_SPEC_FUNCTIONS
1799 : : EXTRA_SPEC_FUNCTIONS
1800 : : #endif
1801 : : { 0, 0 }
1802 : : };
1803 : :
1804 : : static int processing_spec_function;
1805 : :
1806 : : /* Add appropriate libgcc specs to OBSTACK, taking into account
1807 : : various permutations of -shared-libgcc, -shared, and such. */
1808 : :
1809 : : #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC)
1810 : :
1811 : : #ifndef USE_LD_AS_NEEDED
1812 : : #define USE_LD_AS_NEEDED 0
1813 : : #endif
1814 : :
1815 : : static void
1816 : 901 : init_gcc_specs (struct obstack *obstack, const char *shared_name,
1817 : : const char *static_name, const char *eh_name)
1818 : : {
1819 : 901 : char *buf;
1820 : :
1821 : : #if USE_LD_AS_NEEDED
1822 : 901 : buf = concat ("%{static|static-libgcc|static-pie:", static_name, " ", eh_name, "}"
1823 : : "%{!static:%{!static-libgcc:%{!static-pie:"
1824 : : "%{!shared-libgcc:",
1825 : : static_name, " " LD_AS_NEEDED_OPTION " ",
1826 : : shared_name, " " LD_NO_AS_NEEDED_OPTION
1827 : : "}"
1828 : : "%{shared-libgcc:",
1829 : : shared_name, "%{!shared: ", static_name, "}"
1830 : : "}}"
1831 : : #else
1832 : : buf = concat ("%{static|static-libgcc:", static_name, " ", eh_name, "}"
1833 : : "%{!static:%{!static-libgcc:"
1834 : : "%{!shared:"
1835 : : "%{!shared-libgcc:", static_name, " ", eh_name, "}"
1836 : : "%{shared-libgcc:", shared_name, " ", static_name, "}"
1837 : : "}"
1838 : : #ifdef LINK_EH_SPEC
1839 : : "%{shared:"
1840 : : "%{shared-libgcc:", shared_name, "}"
1841 : : "%{!shared-libgcc:", static_name, "}"
1842 : : "}"
1843 : : #else
1844 : : "%{shared:", shared_name, "}"
1845 : : #endif
1846 : : #endif
1847 : : "}}", NULL);
1848 : :
1849 : 901 : obstack_grow (obstack, buf, strlen (buf));
1850 : 901 : free (buf);
1851 : 901 : }
1852 : : #endif /* ENABLE_SHARED_LIBGCC */
1853 : :
1854 : : /* Initialize the specs lookup routines. */
1855 : :
1856 : : static void
1857 : 901 : init_spec (void)
1858 : : {
1859 : 901 : struct spec_list *next = (struct spec_list *) 0;
1860 : 901 : struct spec_list *sl = (struct spec_list *) 0;
1861 : 901 : int i;
1862 : :
1863 : 901 : if (specs)
1864 : : return; /* Already initialized. */
1865 : :
1866 : 901 : if (verbose_flag)
1867 : 61 : fnotice (stderr, "Using built-in specs.\n");
1868 : :
1869 : : #ifdef EXTRA_SPECS
1870 : 901 : extra_specs = XCNEWVEC (struct spec_list, ARRAY_SIZE (extra_specs_1));
1871 : :
1872 : 1802 : for (i = ARRAY_SIZE (extra_specs_1) - 1; i >= 0; i--)
1873 : : {
1874 : 901 : sl = &extra_specs[i];
1875 : 901 : sl->name = extra_specs_1[i].name;
1876 : 901 : sl->ptr = extra_specs_1[i].ptr;
1877 : 901 : sl->next = next;
1878 : 901 : sl->name_len = strlen (sl->name);
1879 : 901 : sl->ptr_spec = &sl->ptr;
1880 : 901 : gcc_assert (sl->ptr_spec != NULL);
1881 : 901 : sl->default_ptr = sl->ptr;
1882 : 901 : next = sl;
1883 : : }
1884 : : #endif
1885 : :
1886 : 41446 : for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--)
1887 : : {
1888 : 40545 : sl = &static_specs[i];
1889 : 40545 : sl->next = next;
1890 : 40545 : next = sl;
1891 : : }
1892 : :
1893 : : #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC)
1894 : : /* ??? If neither -shared-libgcc nor --static-libgcc was
1895 : : seen, then we should be making an educated guess. Some proposed
1896 : : heuristics for ELF include:
1897 : :
1898 : : (1) If "-Wl,--export-dynamic", then it's a fair bet that the
1899 : : program will be doing dynamic loading, which will likely
1900 : : need the shared libgcc.
1901 : :
1902 : : (2) If "-ldl", then it's also a fair bet that we're doing
1903 : : dynamic loading.
1904 : :
1905 : : (3) For each ET_DYN we're linking against (either through -lfoo
1906 : : or /some/path/foo.so), check to see whether it or one of
1907 : : its dependencies depends on a shared libgcc.
1908 : :
1909 : : (4) If "-shared"
1910 : :
1911 : : If the runtime is fixed to look for program headers instead
1912 : : of calling __register_frame_info at all, for each object,
1913 : : use the shared libgcc if any EH symbol referenced.
1914 : :
1915 : : If crtstuff is fixed to not invoke __register_frame_info
1916 : : automatically, for each object, use the shared libgcc if
1917 : : any non-empty unwind section found.
1918 : :
1919 : : Doing any of this probably requires invoking an external program to
1920 : : do the actual object file scanning. */
1921 : 901 : {
1922 : 901 : const char *p = libgcc_spec;
1923 : 901 : int in_sep = 1;
1924 : :
1925 : : /* Transform the extant libgcc_spec into one that uses the shared libgcc
1926 : : when given the proper command line arguments. */
1927 : 1802 : while (*p)
1928 : : {
1929 : 901 : if (in_sep && *p == '-' && startswith (p, "-lgcc"))
1930 : : {
1931 : 901 : init_gcc_specs (&obstack,
1932 : : "-lgcc_s"
1933 : : #ifdef USE_LIBUNWIND_EXCEPTIONS
1934 : : " -lunwind"
1935 : : #endif
1936 : : ,
1937 : : "-lgcc",
1938 : : "-lgcc_eh"
1939 : : #ifdef USE_LIBUNWIND_EXCEPTIONS
1940 : : # ifdef HAVE_LD_STATIC_DYNAMIC
1941 : : " %{!static:%{!static-pie:" LD_STATIC_OPTION "}} -lunwind"
1942 : : " %{!static:%{!static-pie:" LD_DYNAMIC_OPTION "}}"
1943 : : # else
1944 : : " -lunwind"
1945 : : # endif
1946 : : #endif
1947 : : );
1948 : :
1949 : 901 : p += 5;
1950 : 901 : in_sep = 0;
1951 : : }
1952 : 0 : else if (in_sep && *p == 'l' && startswith (p, "libgcc.a%s"))
1953 : : {
1954 : : /* Ug. We don't know shared library extensions. Hope that
1955 : : systems that use this form don't do shared libraries. */
1956 : 0 : init_gcc_specs (&obstack,
1957 : : "-lgcc_s",
1958 : : "libgcc.a%s",
1959 : : "libgcc_eh.a%s"
1960 : : #ifdef USE_LIBUNWIND_EXCEPTIONS
1961 : : " -lunwind"
1962 : : #endif
1963 : : );
1964 : 0 : p += 10;
1965 : 0 : in_sep = 0;
1966 : : }
1967 : : else
1968 : : {
1969 : 0 : obstack_1grow (&obstack, *p);
1970 : 0 : in_sep = (*p == ' ');
1971 : 0 : p += 1;
1972 : : }
1973 : : }
1974 : :
1975 : 901 : obstack_1grow (&obstack, '\0');
1976 : 901 : libgcc_spec = XOBFINISH (&obstack, const char *);
1977 : : }
1978 : : #endif
1979 : : #ifdef USE_AS_TRADITIONAL_FORMAT
1980 : : /* Prepend "--traditional-format" to whatever asm_spec we had before. */
1981 : : {
1982 : : static const char tf[] = "--traditional-format ";
1983 : : obstack_grow (&obstack, tf, sizeof (tf) - 1);
1984 : : obstack_grow0 (&obstack, asm_spec, strlen (asm_spec));
1985 : : asm_spec = XOBFINISH (&obstack, const char *);
1986 : : }
1987 : : #endif
1988 : :
1989 : : #if defined LINK_EH_SPEC || defined LINK_BUILDID_SPEC || \
1990 : : defined LINKER_HASH_STYLE
1991 : : # ifdef LINK_BUILDID_SPEC
1992 : : /* Prepend LINK_BUILDID_SPEC to whatever link_spec we had before. */
1993 : : obstack_grow (&obstack, LINK_BUILDID_SPEC, sizeof (LINK_BUILDID_SPEC) - 1);
1994 : : # endif
1995 : : # ifdef LINK_EH_SPEC
1996 : : /* Prepend LINK_EH_SPEC to whatever link_spec we had before. */
1997 : 901 : obstack_grow (&obstack, LINK_EH_SPEC, sizeof (LINK_EH_SPEC) - 1);
1998 : : # endif
1999 : : # ifdef LINKER_HASH_STYLE
2000 : : /* Prepend --hash-style=LINKER_HASH_STYLE to whatever link_spec we had
2001 : : before. */
2002 : : {
2003 : : static const char hash_style[] = "--hash-style=";
2004 : : obstack_grow (&obstack, hash_style, sizeof (hash_style) - 1);
2005 : : obstack_grow (&obstack, LINKER_HASH_STYLE, sizeof (LINKER_HASH_STYLE) - 1);
2006 : : obstack_1grow (&obstack, ' ');
2007 : : }
2008 : : # endif
2009 : 901 : obstack_grow0 (&obstack, link_spec, strlen (link_spec));
2010 : 901 : link_spec = XOBFINISH (&obstack, const char *);
2011 : : #endif
2012 : :
2013 : 901 : specs = sl;
2014 : : }
2015 : :
2016 : : /* Update the entry for SPEC in the static_specs table to point to VALUE,
2017 : : ensuring that we free the previous value if necessary. Set alloc_p for the
2018 : : entry to ALLOC_P: this determines whether we take ownership of VALUE (i.e.
2019 : : whether we need to free it later on). */
2020 : : static void
2021 : 201566 : set_static_spec (const char **spec, const char *value, bool alloc_p)
2022 : : {
2023 : 201566 : struct spec_list *sl = NULL;
2024 : :
2025 : 6959991 : for (unsigned i = 0; i < ARRAY_SIZE (static_specs); i++)
2026 : : {
2027 : 6959991 : if (static_specs[i].ptr_spec == spec)
2028 : : {
2029 : 201566 : sl = static_specs + i;
2030 : 201566 : break;
2031 : : }
2032 : : }
2033 : :
2034 : 0 : gcc_assert (sl);
2035 : :
2036 : 201566 : if (sl->alloc_p)
2037 : : {
2038 : 201566 : const char *old = *spec;
2039 : 201566 : free (const_cast <char *> (old));
2040 : : }
2041 : :
2042 : 201566 : *spec = value;
2043 : 201566 : sl->alloc_p = alloc_p;
2044 : 201566 : }
2045 : :
2046 : : /* Update a static spec to a new string, taking ownership of that
2047 : : string's memory. */
2048 : 104680 : static void set_static_spec_owned (const char **spec, const char *val)
2049 : : {
2050 : 0 : return set_static_spec (spec, val, true);
2051 : : }
2052 : :
2053 : : /* Update a static spec to point to a new value, but don't take
2054 : : ownership of (i.e. don't free) that string. */
2055 : 96886 : static void set_static_spec_shared (const char **spec, const char *val)
2056 : : {
2057 : 0 : return set_static_spec (spec, val, false);
2058 : : }
2059 : :
2060 : :
2061 : : /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
2062 : : removed; If the spec starts with a + then SPEC is added to the end of the
2063 : : current spec. */
2064 : :
2065 : : static void
2066 : 13230722 : set_spec (const char *name, const char *spec, bool user_p)
2067 : : {
2068 : 13230722 : struct spec_list *sl;
2069 : 13230722 : const char *old_spec;
2070 : 13230722 : int name_len = strlen (name);
2071 : 13230722 : int i;
2072 : :
2073 : : /* If this is the first call, initialize the statically allocated specs. */
2074 : 13230722 : if (!specs)
2075 : : {
2076 : : struct spec_list *next = (struct spec_list *) 0;
2077 : 13183324 : for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--)
2078 : : {
2079 : 12896730 : sl = &static_specs[i];
2080 : 12896730 : sl->next = next;
2081 : 12896730 : next = sl;
2082 : : }
2083 : 286594 : specs = sl;
2084 : : }
2085 : :
2086 : : /* See if the spec already exists. */
2087 : 311346912 : for (sl = specs; sl; sl = sl->next)
2088 : 311039421 : if (name_len == sl->name_len && !strcmp (sl->name, name))
2089 : : break;
2090 : :
2091 : 13230722 : if (!sl)
2092 : : {
2093 : : /* Not found - make it. */
2094 : 307491 : sl = XNEW (struct spec_list);
2095 : 307491 : sl->name = xstrdup (name);
2096 : 307491 : sl->name_len = name_len;
2097 : 307491 : sl->ptr_spec = &sl->ptr;
2098 : 307491 : sl->alloc_p = 0;
2099 : 307491 : *(sl->ptr_spec) = "";
2100 : 307491 : sl->next = specs;
2101 : 307491 : sl->default_ptr = NULL;
2102 : 307491 : specs = sl;
2103 : : }
2104 : :
2105 : 13230722 : old_spec = *(sl->ptr_spec);
2106 : 13230722 : *(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE ((unsigned char)spec[1]))
2107 : 1 : ? concat (old_spec, spec + 1, NULL)
2108 : 13230721 : : xstrdup (spec));
2109 : :
2110 : : #ifdef DEBUG_SPECS
2111 : : if (verbose_flag)
2112 : : fnotice (stderr, "Setting spec %s to '%s'\n\n", name, *(sl->ptr_spec));
2113 : : #endif
2114 : :
2115 : : /* Free the old spec. */
2116 : 13230722 : if (old_spec && sl->alloc_p)
2117 : 5697 : free (CONST_CAST (char *, old_spec));
2118 : :
2119 : 13230722 : sl->user_p = user_p;
2120 : 13230722 : sl->alloc_p = true;
2121 : 13230722 : }
2122 : :
2123 : : /* Accumulate a command (program name and args), and run it. */
2124 : :
2125 : : typedef const char *const_char_p; /* For DEF_VEC_P. */
2126 : :
2127 : : /* Vector of pointers to arguments in the current line of specifications. */
2128 : : static vec<const_char_p> argbuf;
2129 : :
2130 : : /* Likewise, but for the current @file. */
2131 : : static vec<const_char_p> at_file_argbuf;
2132 : :
2133 : : /* Whether an @file is currently open. */
2134 : : static bool in_at_file = false;
2135 : :
2136 : : /* Were the options -c, -S or -E passed. */
2137 : : static int have_c = 0;
2138 : :
2139 : : /* Was the option -o passed. */
2140 : : static int have_o = 0;
2141 : :
2142 : : /* Was the option -E passed. */
2143 : : static int have_E = 0;
2144 : :
2145 : : /* Pointer to output file name passed in with -o. */
2146 : : static const char *output_file = 0;
2147 : :
2148 : : /* Pointer to input file name passed in with -truncate.
2149 : : This file should be truncated after linking. */
2150 : : static const char *totruncate_file = 0;
2151 : :
2152 : : /* This is the list of suffixes and codes (%g/%u/%U/%j) and the associated
2153 : : temp file. If the HOST_BIT_BUCKET is used for %j, no entry is made for
2154 : : it here. */
2155 : :
2156 : : static struct temp_name {
2157 : : const char *suffix; /* suffix associated with the code. */
2158 : : int length; /* strlen (suffix). */
2159 : : int unique; /* Indicates whether %g or %u/%U was used. */
2160 : : const char *filename; /* associated filename. */
2161 : : int filename_length; /* strlen (filename). */
2162 : : struct temp_name *next;
2163 : : } *temp_names;
2164 : :
2165 : : /* Number of commands executed so far. */
2166 : :
2167 : : static int execution_count;
2168 : :
2169 : : /* Number of commands that exited with a signal. */
2170 : :
2171 : : static int signal_count;
2172 : :
2173 : : /* Allocate the argument vector. */
2174 : :
2175 : : static void
2176 : 2291273 : alloc_args (void)
2177 : : {
2178 : 2291273 : argbuf.create (10);
2179 : 2291273 : at_file_argbuf.create (10);
2180 : 2291273 : }
2181 : :
2182 : : /* Clear out the vector of arguments (after a command is executed). */
2183 : :
2184 : : static void
2185 : 5389438 : clear_args (void)
2186 : : {
2187 : 5389438 : argbuf.truncate (0);
2188 : 5389438 : at_file_argbuf.truncate (0);
2189 : 5389438 : }
2190 : :
2191 : : /* Add one argument to the vector at the end.
2192 : : This is done when a space is seen or at the end of the line.
2193 : : If DELETE_ALWAYS is nonzero, the arg is a filename
2194 : : and the file should be deleted eventually.
2195 : : If DELETE_FAILURE is nonzero, the arg is a filename
2196 : : and the file should be deleted if this compilation fails. */
2197 : :
2198 : : static void
2199 : 18614340 : store_arg (const char *arg, int delete_always, int delete_failure)
2200 : : {
2201 : 18614340 : if (in_at_file)
2202 : 12871 : at_file_argbuf.safe_push (arg);
2203 : : else
2204 : 18601469 : argbuf.safe_push (arg);
2205 : :
2206 : 18614340 : if (delete_always || delete_failure)
2207 : : {
2208 : 502950 : const char *p;
2209 : : /* If the temporary file we should delete is specified as
2210 : : part of a joined argument extract the filename. */
2211 : 502950 : if (arg[0] == '-'
2212 : 502950 : && (p = strrchr (arg, '=')))
2213 : 88089 : arg = p + 1;
2214 : 502950 : record_temp_file (arg, delete_always, delete_failure);
2215 : : }
2216 : 18614340 : }
2217 : :
2218 : : /* Open a temporary @file into which subsequent arguments will be stored. */
2219 : :
2220 : : static void
2221 : 11845 : open_at_file (void)
2222 : : {
2223 : 11845 : if (in_at_file)
2224 : 0 : fatal_error (input_location, "cannot open nested response file");
2225 : : else
2226 : 11845 : in_at_file = true;
2227 : 11845 : }
2228 : :
2229 : : /* Create a temporary @file name. */
2230 : :
2231 : 11835 : static char *make_at_file (void)
2232 : : {
2233 : 11835 : static int fileno = 0;
2234 : 11835 : char filename[20];
2235 : 11835 : const char *base, *ext;
2236 : :
2237 : 11835 : if (!save_temps_flag)
2238 : 11797 : return make_temp_file ("");
2239 : :
2240 : 38 : base = dumpbase;
2241 : 38 : if (!(base && *base))
2242 : 11 : base = dumpdir;
2243 : 38 : if (!(base && *base))
2244 : 0 : base = "a";
2245 : :
2246 : 38 : sprintf (filename, ".args.%d", fileno++);
2247 : 38 : ext = filename;
2248 : :
2249 : 38 : if (base == dumpdir && dumpdir_trailing_dash_added)
2250 : 38 : ext++;
2251 : :
2252 : 38 : return concat (base, ext, NULL);
2253 : : }
2254 : :
2255 : : /* Close the temporary @file and add @file to the argument list. */
2256 : :
2257 : : static void
2258 : 11845 : close_at_file (void)
2259 : : {
2260 : 11845 : if (!in_at_file)
2261 : 0 : fatal_error (input_location, "cannot close nonexistent response file");
2262 : :
2263 : 11845 : in_at_file = false;
2264 : :
2265 : 11845 : const unsigned int n_args = at_file_argbuf.length ();
2266 : 11845 : if (n_args == 0)
2267 : : return;
2268 : :
2269 : 11835 : char **argv = XALLOCAVEC (char *, n_args + 1);
2270 : 11835 : char *temp_file = make_at_file ();
2271 : 11835 : char *at_argument = concat ("@", temp_file, NULL);
2272 : 11835 : FILE *f = fopen (temp_file, "w");
2273 : 11835 : int status;
2274 : 11835 : unsigned int i;
2275 : :
2276 : : /* Copy the strings over. */
2277 : 36541 : for (i = 0; i < n_args; i++)
2278 : 12871 : argv[i] = CONST_CAST (char *, at_file_argbuf[i]);
2279 : 11835 : argv[i] = NULL;
2280 : :
2281 : 11835 : at_file_argbuf.truncate (0);
2282 : :
2283 : 11835 : if (f == NULL)
2284 : 0 : fatal_error (input_location, "could not open temporary response file %s",
2285 : : temp_file);
2286 : :
2287 : 11835 : status = writeargv (argv, f);
2288 : :
2289 : 11835 : if (status)
2290 : 0 : fatal_error (input_location,
2291 : : "could not write to temporary response file %s",
2292 : : temp_file);
2293 : :
2294 : 11835 : status = fclose (f);
2295 : :
2296 : 11835 : if (status == EOF)
2297 : 0 : fatal_error (input_location, "could not close temporary response file %s",
2298 : : temp_file);
2299 : :
2300 : 11835 : store_arg (at_argument, 0, 0);
2301 : :
2302 : 11835 : record_temp_file (temp_file, !save_temps_flag, !save_temps_flag);
2303 : : }
2304 : :
2305 : : /* Load specs from a file name named FILENAME, replacing occurrences of
2306 : : various different types of line-endings, \r\n, \n\r and just \r, with
2307 : : a single \n. */
2308 : :
2309 : : static char *
2310 : 316697 : load_specs (const char *filename)
2311 : : {
2312 : 316697 : int desc;
2313 : 316697 : int readlen;
2314 : 316697 : struct stat statbuf;
2315 : 316697 : char *buffer;
2316 : 316697 : char *buffer_p;
2317 : 316697 : char *specs;
2318 : 316697 : char *specs_p;
2319 : :
2320 : 316697 : if (verbose_flag)
2321 : 1299 : fnotice (stderr, "Reading specs from %s\n", filename);
2322 : :
2323 : : /* Open and stat the file. */
2324 : 316697 : desc = open (filename, O_RDONLY, 0);
2325 : 316697 : if (desc < 0)
2326 : : {
2327 : 1 : failed:
2328 : : /* This leaves DESC open, but the OS will save us. */
2329 : 1 : fatal_error (input_location, "cannot read spec file %qs: %m", filename);
2330 : : }
2331 : :
2332 : 316696 : if (stat (filename, &statbuf) < 0)
2333 : 0 : goto failed;
2334 : :
2335 : : /* Read contents of file into BUFFER. */
2336 : 316696 : buffer = XNEWVEC (char, statbuf.st_size + 1);
2337 : 316696 : readlen = read (desc, buffer, (unsigned) statbuf.st_size);
2338 : 316696 : if (readlen < 0)
2339 : 0 : goto failed;
2340 : 316696 : buffer[readlen] = 0;
2341 : 316696 : close (desc);
2342 : :
2343 : 316696 : specs = XNEWVEC (char, readlen + 1);
2344 : 316696 : specs_p = specs;
2345 : 2878457012 : for (buffer_p = buffer; buffer_p && *buffer_p; buffer_p++)
2346 : : {
2347 : 2878140316 : int skip = 0;
2348 : 2878140316 : char c = *buffer_p;
2349 : 2878140316 : if (c == '\r')
2350 : : {
2351 : 0 : if (buffer_p > buffer && *(buffer_p - 1) == '\n') /* \n\r */
2352 : : skip = 1;
2353 : 0 : else if (*(buffer_p + 1) == '\n') /* \r\n */
2354 : : skip = 1;
2355 : : else /* \r */
2356 : : c = '\n';
2357 : : }
2358 : : if (! skip)
2359 : 2878140316 : *specs_p++ = c;
2360 : : }
2361 : 316696 : *specs_p = '\0';
2362 : :
2363 : 316696 : free (buffer);
2364 : 316696 : return (specs);
2365 : : }
2366 : :
2367 : : /* Read compilation specs from a file named FILENAME,
2368 : : replacing the default ones.
2369 : :
2370 : : A suffix which starts with `*' is a definition for
2371 : : one of the machine-specific sub-specs. The "suffix" should be
2372 : : *asm, *cc1, *cpp, *link, *startfile, etc.
2373 : : The corresponding spec is stored in asm_spec, etc.,
2374 : : rather than in the `compilers' vector.
2375 : :
2376 : : Anything invalid in the file is a fatal error. */
2377 : :
2378 : : static void
2379 : 316697 : read_specs (const char *filename, bool main_p, bool user_p)
2380 : : {
2381 : 316697 : char *buffer;
2382 : 316697 : char *p;
2383 : :
2384 : 316697 : buffer = load_specs (filename);
2385 : :
2386 : : /* Scan BUFFER for specs, putting them in the vector. */
2387 : 316697 : p = buffer;
2388 : 13834012 : while (1)
2389 : : {
2390 : 13834012 : char *suffix;
2391 : 13834012 : char *spec;
2392 : 13834012 : char *in, *out, *p1, *p2, *p3;
2393 : :
2394 : : /* Advance P in BUFFER to the next nonblank nocomment line. */
2395 : 13834012 : p = skip_whitespace (p);
2396 : 13834012 : if (*p == 0)
2397 : : break;
2398 : :
2399 : : /* Is this a special command that starts with '%'? */
2400 : : /* Don't allow this for the main specs file, since it would
2401 : : encourage people to overwrite it. */
2402 : 13517316 : if (*p == '%' && !main_p)
2403 : : {
2404 : 416080 : p1 = p;
2405 : 416080 : while (*p && *p != '\n')
2406 : 395276 : p++;
2407 : :
2408 : : /* Skip '\n'. */
2409 : 20804 : p++;
2410 : :
2411 : 20804 : if (startswith (p1, "%include")
2412 : 20804 : && (p1[sizeof "%include" - 1] == ' '
2413 : 0 : || p1[sizeof "%include" - 1] == '\t'))
2414 : : {
2415 : 0 : char *new_filename;
2416 : :
2417 : 0 : p1 += sizeof ("%include");
2418 : 0 : while (*p1 == ' ' || *p1 == '\t')
2419 : 0 : p1++;
2420 : :
2421 : 0 : if (*p1++ != '<' || p[-2] != '>')
2422 : 0 : fatal_error (input_location,
2423 : : "specs %%include syntax malformed after "
2424 : 0 : "%td characters", p1 - buffer + 1);
2425 : :
2426 : 0 : p[-2] = '\0';
2427 : 0 : new_filename = find_a_file (&startfile_prefixes, p1, R_OK, true);
2428 : 0 : read_specs (new_filename ? new_filename : p1, false, user_p);
2429 : 0 : continue;
2430 : 0 : }
2431 : 20804 : else if (startswith (p1, "%include_noerr")
2432 : 20804 : && (p1[sizeof "%include_noerr" - 1] == ' '
2433 : 0 : || p1[sizeof "%include_noerr" - 1] == '\t'))
2434 : : {
2435 : 0 : char *new_filename;
2436 : :
2437 : 0 : p1 += sizeof "%include_noerr";
2438 : 0 : while (*p1 == ' ' || *p1 == '\t')
2439 : 0 : p1++;
2440 : :
2441 : 0 : if (*p1++ != '<' || p[-2] != '>')
2442 : 0 : fatal_error (input_location,
2443 : : "specs %%include syntax malformed after "
2444 : 0 : "%td characters", p1 - buffer + 1);
2445 : :
2446 : 0 : p[-2] = '\0';
2447 : 0 : new_filename = find_a_file (&startfile_prefixes, p1, R_OK, true);
2448 : 0 : if (new_filename)
2449 : 0 : read_specs (new_filename, false, user_p);
2450 : 0 : else if (verbose_flag)
2451 : 0 : fnotice (stderr, "could not find specs file %s\n", p1);
2452 : 0 : continue;
2453 : 0 : }
2454 : 20804 : else if (startswith (p1, "%rename")
2455 : 20804 : && (p1[sizeof "%rename" - 1] == ' '
2456 : 0 : || p1[sizeof "%rename" - 1] == '\t'))
2457 : : {
2458 : 20804 : int name_len;
2459 : 20804 : struct spec_list *sl;
2460 : 20804 : struct spec_list *newsl;
2461 : :
2462 : : /* Get original name. */
2463 : 20804 : p1 += sizeof "%rename";
2464 : 20804 : while (*p1 == ' ' || *p1 == '\t')
2465 : 0 : p1++;
2466 : :
2467 : 20804 : if (! ISALPHA ((unsigned char) *p1))
2468 : 0 : fatal_error (input_location,
2469 : : "specs %%rename syntax malformed after "
2470 : : "%td characters", p1 - buffer);
2471 : :
2472 : : p2 = p1;
2473 : 83216 : while (*p2 && !ISSPACE ((unsigned char) *p2))
2474 : 62412 : p2++;
2475 : :
2476 : 20804 : if (*p2 != ' ' && *p2 != '\t')
2477 : 0 : fatal_error (input_location,
2478 : : "specs %%rename syntax malformed after "
2479 : : "%td characters", p2 - buffer);
2480 : :
2481 : 20804 : name_len = p2 - p1;
2482 : 20804 : *p2++ = '\0';
2483 : 20804 : while (*p2 == ' ' || *p2 == '\t')
2484 : 0 : p2++;
2485 : :
2486 : 20804 : if (! ISALPHA ((unsigned char) *p2))
2487 : 0 : fatal_error (input_location,
2488 : : "specs %%rename syntax malformed after "
2489 : : "%td characters", p2 - buffer);
2490 : :
2491 : : /* Get new spec name. */
2492 : : p3 = p2;
2493 : 166432 : while (*p3 && !ISSPACE ((unsigned char) *p3))
2494 : 145628 : p3++;
2495 : :
2496 : 20804 : if (p3 != p - 1)
2497 : 0 : fatal_error (input_location,
2498 : : "specs %%rename syntax malformed after "
2499 : : "%td characters", p3 - buffer);
2500 : 20804 : *p3 = '\0';
2501 : :
2502 : 416080 : for (sl = specs; sl; sl = sl->next)
2503 : 416080 : if (name_len == sl->name_len && !strcmp (sl->name, p1))
2504 : : break;
2505 : :
2506 : 20804 : if (!sl)
2507 : 0 : fatal_error (input_location,
2508 : : "specs %s spec was not found to be renamed", p1);
2509 : :
2510 : 20804 : if (strcmp (p1, p2) == 0)
2511 : 0 : continue;
2512 : :
2513 : 977788 : for (newsl = specs; newsl; newsl = newsl->next)
2514 : 956984 : if (strcmp (newsl->name, p2) == 0)
2515 : 0 : fatal_error (input_location,
2516 : : "%s: attempt to rename spec %qs to "
2517 : : "already defined spec %qs",
2518 : : filename, p1, p2);
2519 : :
2520 : 20804 : if (verbose_flag)
2521 : : {
2522 : 0 : fnotice (stderr, "rename spec %s to %s\n", p1, p2);
2523 : : #ifdef DEBUG_SPECS
2524 : : fnotice (stderr, "spec is '%s'\n\n", *(sl->ptr_spec));
2525 : : #endif
2526 : : }
2527 : :
2528 : 20804 : set_spec (p2, *(sl->ptr_spec), user_p);
2529 : 20804 : if (sl->alloc_p)
2530 : 20804 : free (CONST_CAST (char *, *(sl->ptr_spec)));
2531 : :
2532 : 20804 : *(sl->ptr_spec) = "";
2533 : 20804 : sl->alloc_p = 0;
2534 : 20804 : continue;
2535 : 20804 : }
2536 : : else
2537 : 0 : fatal_error (input_location,
2538 : : "specs unknown %% command after %td characters",
2539 : : p1 - buffer);
2540 : : }
2541 : :
2542 : : /* Find the colon that should end the suffix. */
2543 : : p1 = p;
2544 : 185307674 : while (*p1 && *p1 != ':' && *p1 != '\n')
2545 : 171811162 : p1++;
2546 : :
2547 : : /* The colon shouldn't be missing. */
2548 : 13496512 : if (*p1 != ':')
2549 : 0 : fatal_error (input_location,
2550 : : "specs file malformed after %td characters",
2551 : : p1 - buffer);
2552 : :
2553 : : /* Skip back over trailing whitespace. */
2554 : : p2 = p1;
2555 : 13496512 : while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t'))
2556 : 0 : p2--;
2557 : :
2558 : : /* Copy the suffix to a string. */
2559 : 13496512 : suffix = save_string (p, p2 - p);
2560 : : /* Find the next line. */
2561 : 13496512 : p = skip_whitespace (p1 + 1);
2562 : 13496512 : if (p[1] == 0)
2563 : 0 : fatal_error (input_location,
2564 : : "specs file malformed after %td characters",
2565 : : p - buffer);
2566 : :
2567 : : p1 = p;
2568 : : /* Find next blank line or end of string. */
2569 : 2661858137 : while (*p1 && !(*p1 == '\n' && (p1[1] == '\n' || p1[1] == '\0')))
2570 : 2648361625 : p1++;
2571 : :
2572 : : /* Specs end at the blank line and do not include the newline. */
2573 : 13496512 : spec = save_string (p, p1 - p);
2574 : 13496512 : p = p1;
2575 : :
2576 : : /* Delete backslash-newline sequences from the spec. */
2577 : 13496512 : in = spec;
2578 : 13496512 : out = spec;
2579 : 2675354647 : while (*in != 0)
2580 : : {
2581 : 2648361623 : if (in[0] == '\\' && in[1] == '\n')
2582 : 2 : in += 2;
2583 : 2648361621 : else if (in[0] == '#')
2584 : 0 : while (*in && *in != '\n')
2585 : 0 : in++;
2586 : :
2587 : : else
2588 : 2648361621 : *out++ = *in++;
2589 : : }
2590 : 13496512 : *out = 0;
2591 : :
2592 : 13496512 : if (suffix[0] == '*')
2593 : : {
2594 : 13496512 : if (! strcmp (suffix, "*link_command"))
2595 : 286594 : link_command_spec = spec;
2596 : : else
2597 : : {
2598 : 13209918 : set_spec (suffix + 1, spec, user_p);
2599 : 13209918 : free (spec);
2600 : : }
2601 : : }
2602 : : else
2603 : : {
2604 : : /* Add this pair to the vector. */
2605 : 0 : compilers
2606 : 0 : = XRESIZEVEC (struct compiler, compilers, n_compilers + 2);
2607 : :
2608 : 0 : compilers[n_compilers].suffix = suffix;
2609 : 0 : compilers[n_compilers].spec = spec;
2610 : 0 : n_compilers++;
2611 : 0 : memset (&compilers[n_compilers], 0, sizeof compilers[n_compilers]);
2612 : : }
2613 : :
2614 : 13496512 : if (*suffix == 0)
2615 : 0 : link_command_spec = spec;
2616 : : }
2617 : :
2618 : 316696 : if (link_command_spec == 0)
2619 : 0 : fatal_error (input_location, "spec file has no spec for linking");
2620 : :
2621 : 316696 : XDELETEVEC (buffer);
2622 : 316696 : }
2623 : :
2624 : : /* Record the names of temporary files we tell compilers to write,
2625 : : and delete them at the end of the run. */
2626 : :
2627 : : /* This is the common prefix we use to make temp file names.
2628 : : It is chosen once for each run of this program.
2629 : : It is substituted into a spec by %g or %j.
2630 : : Thus, all temp file names contain this prefix.
2631 : : In practice, all temp file names start with this prefix.
2632 : :
2633 : : This prefix comes from the envvar TMPDIR if it is defined;
2634 : : otherwise, from the P_tmpdir macro if that is defined;
2635 : : otherwise, in /usr/tmp or /tmp;
2636 : : or finally the current directory if all else fails. */
2637 : :
2638 : : static const char *temp_filename;
2639 : :
2640 : : /* Length of the prefix. */
2641 : :
2642 : : static int temp_filename_length;
2643 : :
2644 : : /* Define the list of temporary files to delete. */
2645 : :
2646 : : struct temp_file
2647 : : {
2648 : : const char *name;
2649 : : struct temp_file *next;
2650 : : };
2651 : :
2652 : : /* Queue of files to delete on success or failure of compilation. */
2653 : : static struct temp_file *always_delete_queue;
2654 : : /* Queue of files to delete on failure of compilation. */
2655 : : static struct temp_file *failure_delete_queue;
2656 : :
2657 : : /* Record FILENAME as a file to be deleted automatically.
2658 : : ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
2659 : : otherwise delete it in any case.
2660 : : FAIL_DELETE nonzero means delete it if a compilation step fails;
2661 : : otherwise delete it in any case. */
2662 : :
2663 : : void
2664 : 680104 : record_temp_file (const char *filename, int always_delete, int fail_delete)
2665 : : {
2666 : 680104 : char *const name = xstrdup (filename);
2667 : :
2668 : 680104 : if (always_delete)
2669 : : {
2670 : 511961 : struct temp_file *temp;
2671 : 890904 : for (temp = always_delete_queue; temp; temp = temp->next)
2672 : 537968 : if (! filename_cmp (name, temp->name))
2673 : : {
2674 : 159025 : free (name);
2675 : 159025 : goto already1;
2676 : : }
2677 : :
2678 : 352936 : temp = XNEW (struct temp_file);
2679 : 352936 : temp->next = always_delete_queue;
2680 : 352936 : temp->name = name;
2681 : 352936 : always_delete_queue = temp;
2682 : :
2683 : 680104 : already1:;
2684 : : }
2685 : :
2686 : 680104 : if (fail_delete)
2687 : : {
2688 : 274054 : struct temp_file *temp;
2689 : 278988 : for (temp = failure_delete_queue; temp; temp = temp->next)
2690 : 5023 : if (! filename_cmp (name, temp->name))
2691 : : {
2692 : 89 : free (name);
2693 : 89 : goto already2;
2694 : : }
2695 : :
2696 : 273965 : temp = XNEW (struct temp_file);
2697 : 273965 : temp->next = failure_delete_queue;
2698 : 273965 : temp->name = name;
2699 : 273965 : failure_delete_queue = temp;
2700 : :
2701 : 680104 : already2:;
2702 : : }
2703 : 680104 : }
2704 : :
2705 : : /* Delete all the temporary files whose names we previously recorded. */
2706 : :
2707 : : #ifndef DELETE_IF_ORDINARY
2708 : : #define DELETE_IF_ORDINARY(NAME,ST,VERBOSE_FLAG) \
2709 : : do \
2710 : : { \
2711 : : if (stat (NAME, &ST) >= 0 && S_ISREG (ST.st_mode)) \
2712 : : if (unlink (NAME) < 0) \
2713 : : if (VERBOSE_FLAG) \
2714 : : error ("%s: %m", (NAME)); \
2715 : : } while (0)
2716 : : #endif
2717 : :
2718 : : static void
2719 : 375810 : delete_if_ordinary (const char *name)
2720 : : {
2721 : 375810 : struct stat st;
2722 : : #ifdef DEBUG
2723 : : int i, c;
2724 : :
2725 : : printf ("Delete %s? (y or n) ", name);
2726 : : fflush (stdout);
2727 : : i = getchar ();
2728 : : if (i != '\n')
2729 : : while ((c = getchar ()) != '\n' && c != EOF)
2730 : : ;
2731 : :
2732 : : if (i == 'y' || i == 'Y')
2733 : : #endif /* DEBUG */
2734 : 375810 : DELETE_IF_ORDINARY (name, st, verbose_flag);
2735 : 375810 : }
2736 : :
2737 : : static void
2738 : 560912 : delete_temp_files (void)
2739 : : {
2740 : 560912 : struct temp_file *temp;
2741 : :
2742 : 913848 : for (temp = always_delete_queue; temp; temp = temp->next)
2743 : 352936 : delete_if_ordinary (temp->name);
2744 : 560912 : always_delete_queue = 0;
2745 : 560912 : }
2746 : :
2747 : : /* Delete all the files to be deleted on error. */
2748 : :
2749 : : static void
2750 : 56559 : delete_failure_queue (void)
2751 : : {
2752 : 56559 : struct temp_file *temp;
2753 : :
2754 : 79433 : for (temp = failure_delete_queue; temp; temp = temp->next)
2755 : 22874 : delete_if_ordinary (temp->name);
2756 : 56559 : }
2757 : :
2758 : : static void
2759 : 526494 : clear_failure_queue (void)
2760 : : {
2761 : 526494 : failure_delete_queue = 0;
2762 : 526494 : }
2763 : :
2764 : : /* Call CALLBACK for each path in PATHS, breaking out early if CALLBACK
2765 : : returns non-NULL.
2766 : : If DO_MULTI is true iterate over the paths twice, first with multilib
2767 : : suffix then without, otherwise iterate over the paths once without
2768 : : adding a multilib suffix. When DO_MULTI is true, some attempt is made
2769 : : to avoid visiting the same path twice, but we could do better. For
2770 : : instance, /usr/lib/../lib is considered different from /usr/lib.
2771 : : At least EXTRA_SPACE chars past the end of the path passed to
2772 : : CALLBACK are available for use by the callback.
2773 : : CALLBACK_INFO allows extra parameters to be passed to CALLBACK.
2774 : :
2775 : : Returns the value returned by CALLBACK. */
2776 : :
2777 : : static void *
2778 : 2738542 : for_each_path (const struct path_prefix *paths,
2779 : : bool do_multi,
2780 : : size_t extra_space,
2781 : : void *(*callback) (char *, void *),
2782 : : void *callback_info)
2783 : : {
2784 : 2738542 : struct prefix_list *pl;
2785 : 2738542 : const char *multi_dir = NULL;
2786 : 2738542 : const char *multi_os_dir = NULL;
2787 : 2738542 : const char *multiarch_suffix = NULL;
2788 : 2738542 : const char *multi_suffix;
2789 : 2738542 : const char *just_multi_suffix;
2790 : 2738542 : char *path = NULL;
2791 : 2738542 : void *ret = NULL;
2792 : 2738542 : bool skip_multi_dir = false;
2793 : 2738542 : bool skip_multi_os_dir = false;
2794 : :
2795 : 2738542 : multi_suffix = machine_suffix;
2796 : 2738542 : just_multi_suffix = just_machine_suffix;
2797 : 2738542 : if (do_multi && multilib_dir && strcmp (multilib_dir, ".") != 0)
2798 : : {
2799 : 15756 : multi_dir = concat (multilib_dir, dir_separator_str, NULL);
2800 : 15756 : multi_suffix = concat (multi_suffix, multi_dir, NULL);
2801 : 15756 : just_multi_suffix = concat (just_multi_suffix, multi_dir, NULL);
2802 : : }
2803 : 1192840 : if (do_multi && multilib_os_dir && strcmp (multilib_os_dir, ".") != 0)
2804 : 905344 : multi_os_dir = concat (multilib_os_dir, dir_separator_str, NULL);
2805 : 2738542 : if (multiarch_dir)
2806 : 0 : multiarch_suffix = concat (multiarch_dir, dir_separator_str, NULL);
2807 : :
2808 : 3149084 : while (1)
2809 : : {
2810 : 3149084 : size_t multi_dir_len = 0;
2811 : 3149084 : size_t multi_os_dir_len = 0;
2812 : 3149084 : size_t multiarch_len = 0;
2813 : 3149084 : size_t suffix_len;
2814 : 3149084 : size_t just_suffix_len;
2815 : 3149084 : size_t len;
2816 : :
2817 : 3149084 : if (multi_dir)
2818 : 15756 : multi_dir_len = strlen (multi_dir);
2819 : 3149084 : if (multi_os_dir)
2820 : 905344 : multi_os_dir_len = strlen (multi_os_dir);
2821 : 3149084 : if (multiarch_suffix)
2822 : 0 : multiarch_len = strlen (multiarch_suffix);
2823 : 3149084 : suffix_len = strlen (multi_suffix);
2824 : 3149084 : just_suffix_len = strlen (just_multi_suffix);
2825 : :
2826 : 3149084 : if (path == NULL)
2827 : : {
2828 : 2738542 : len = paths->max_len + extra_space + 1;
2829 : 2738542 : len += MAX (MAX (suffix_len, multi_os_dir_len), multiarch_len);
2830 : 2738542 : path = XNEWVEC (char, len);
2831 : : }
2832 : :
2833 : 12335760 : for (pl = paths->plist; pl != 0; pl = pl->next)
2834 : : {
2835 : 10806297 : len = strlen (pl->prefix);
2836 : 10806297 : memcpy (path, pl->prefix, len);
2837 : :
2838 : : /* Look first in MACHINE/VERSION subdirectory. */
2839 : 10806297 : if (!skip_multi_dir)
2840 : : {
2841 : 7909666 : memcpy (path + len, multi_suffix, suffix_len + 1);
2842 : 7909666 : ret = callback (path, callback_info);
2843 : 7909666 : if (ret)
2844 : : break;
2845 : : }
2846 : :
2847 : : /* Some paths are tried with just the machine (ie. target)
2848 : : subdir. This is used for finding as, ld, etc. */
2849 : 7909666 : if (!skip_multi_dir
2850 : 7909666 : && pl->require_machine_suffix == 2)
2851 : : {
2852 : 0 : memcpy (path + len, just_multi_suffix, just_suffix_len + 1);
2853 : 0 : ret = callback (path, callback_info);
2854 : 0 : if (ret)
2855 : : break;
2856 : : }
2857 : :
2858 : : /* Now try the multiarch path. */
2859 : 7909666 : if (!skip_multi_dir
2860 : 7909666 : && !pl->require_machine_suffix && multiarch_dir)
2861 : : {
2862 : 0 : memcpy (path + len, multiarch_suffix, multiarch_len + 1);
2863 : 0 : ret = callback (path, callback_info);
2864 : 0 : if (ret)
2865 : : break;
2866 : : }
2867 : :
2868 : : /* Now try the base path. */
2869 : 10806297 : if (!pl->require_machine_suffix
2870 : 17198143 : && !(pl->os_multilib ? skip_multi_os_dir : skip_multi_dir))
2871 : : {
2872 : 9656664 : const char *this_multi;
2873 : 9656664 : size_t this_multi_len;
2874 : :
2875 : 9656664 : if (pl->os_multilib)
2876 : : {
2877 : : this_multi = multi_os_dir;
2878 : : this_multi_len = multi_os_dir_len;
2879 : : }
2880 : : else
2881 : : {
2882 : 5242213 : this_multi = multi_dir;
2883 : 5242213 : this_multi_len = multi_dir_len;
2884 : : }
2885 : :
2886 : 9656664 : if (this_multi_len)
2887 : 2688008 : memcpy (path + len, this_multi, this_multi_len + 1);
2888 : : else
2889 : 6968656 : path[len] = '\0';
2890 : :
2891 : 9656664 : ret = callback (path, callback_info);
2892 : 9656664 : if (ret)
2893 : : break;
2894 : : }
2895 : : }
2896 : 3149084 : if (pl)
2897 : : break;
2898 : :
2899 : 1529463 : if (multi_dir == NULL && multi_os_dir == NULL)
2900 : : break;
2901 : :
2902 : : /* Run through the paths again, this time without multilibs.
2903 : : Don't repeat any we have already seen. */
2904 : 410542 : if (multi_dir)
2905 : : {
2906 : 10073 : free (CONST_CAST (char *, multi_dir));
2907 : 10073 : multi_dir = NULL;
2908 : 10073 : free (CONST_CAST (char *, multi_suffix));
2909 : 10073 : multi_suffix = machine_suffix;
2910 : 10073 : free (CONST_CAST (char *, just_multi_suffix));
2911 : 10073 : just_multi_suffix = just_machine_suffix;
2912 : : }
2913 : : else
2914 : : skip_multi_dir = true;
2915 : 410542 : if (multi_os_dir)
2916 : : {
2917 : 410542 : free (CONST_CAST (char *, multi_os_dir));
2918 : 410542 : multi_os_dir = NULL;
2919 : : }
2920 : : else
2921 : : skip_multi_os_dir = true;
2922 : : }
2923 : :
2924 : 2738542 : if (multi_dir)
2925 : : {
2926 : 5683 : free (CONST_CAST (char *, multi_dir));
2927 : 5683 : free (CONST_CAST (char *, multi_suffix));
2928 : 5683 : free (CONST_CAST (char *, just_multi_suffix));
2929 : : }
2930 : 2738542 : if (multi_os_dir)
2931 : 494802 : free (CONST_CAST (char *, multi_os_dir));
2932 : 2738542 : if (ret != path)
2933 : 1118921 : free (path);
2934 : 2738542 : return ret;
2935 : : }
2936 : :
2937 : : /* Callback for build_search_list. Adds path to obstack being built. */
2938 : :
2939 : : struct add_to_obstack_info {
2940 : : struct obstack *ob;
2941 : : bool check_dir;
2942 : : bool first_time;
2943 : : };
2944 : :
2945 : : static void *
2946 : 6691202 : add_to_obstack (char *path, void *data)
2947 : : {
2948 : 6691202 : struct add_to_obstack_info *info = (struct add_to_obstack_info *) data;
2949 : :
2950 : 6691202 : if (info->check_dir && !is_directory (path))
2951 : : return NULL;
2952 : :
2953 : 2450615 : if (!info->first_time)
2954 : 1962775 : obstack_1grow (info->ob, PATH_SEPARATOR);
2955 : :
2956 : 2450615 : obstack_grow (info->ob, path, strlen (path));
2957 : :
2958 : 2450615 : info->first_time = false;
2959 : 2450615 : return NULL;
2960 : : }
2961 : :
2962 : : /* Add or change the value of an environment variable, outputting the
2963 : : change to standard error if in verbose mode. */
2964 : : static void
2965 : 1702992 : xputenv (const char *string)
2966 : : {
2967 : 0 : env.xput (string);
2968 : 133094 : }
2969 : :
2970 : : /* Build a list of search directories from PATHS.
2971 : : PREFIX is a string to prepend to the list.
2972 : : If CHECK_DIR_P is true we ensure the directory exists.
2973 : : If DO_MULTI is true, multilib paths are output first, then
2974 : : non-multilib paths.
2975 : : This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
2976 : : It is also used by the --print-search-dirs flag. */
2977 : :
2978 : : static char *
2979 : 488934 : build_search_list (const struct path_prefix *paths, const char *prefix,
2980 : : bool check_dir, bool do_multi)
2981 : : {
2982 : 488934 : struct add_to_obstack_info info;
2983 : :
2984 : 488934 : info.ob = &collect_obstack;
2985 : 488934 : info.check_dir = check_dir;
2986 : 488934 : info.first_time = true;
2987 : :
2988 : 488934 : obstack_grow (&collect_obstack, prefix, strlen (prefix));
2989 : 488934 : obstack_1grow (&collect_obstack, '=');
2990 : :
2991 : 488934 : for_each_path (paths, do_multi, 0, add_to_obstack, &info);
2992 : :
2993 : 488934 : obstack_1grow (&collect_obstack, '\0');
2994 : 488934 : return XOBFINISH (&collect_obstack, char *);
2995 : : }
2996 : :
2997 : : /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
2998 : : for collect. */
2999 : :
3000 : : static void
3001 : 488878 : putenv_from_prefixes (const struct path_prefix *paths, const char *env_var,
3002 : : bool do_multi)
3003 : : {
3004 : 488878 : xputenv (build_search_list (paths, env_var, true, do_multi));
3005 : 488878 : }
3006 : :
3007 : : /* Check whether NAME can be accessed in MODE. This is like access,
3008 : : except that it never considers directories to be executable. */
3009 : :
3010 : : static int
3011 : 7625178 : access_check (const char *name, int mode)
3012 : : {
3013 : 7625178 : if (mode == X_OK)
3014 : : {
3015 : 1460730 : struct stat st;
3016 : :
3017 : 1460730 : if (stat (name, &st) < 0
3018 : 1460730 : || S_ISDIR (st.st_mode))
3019 : 742377 : return -1;
3020 : : }
3021 : :
3022 : 6882801 : return access (name, mode);
3023 : : }
3024 : :
3025 : : /* Callback for find_a_file. Appends the file name to the directory
3026 : : path. If the resulting file exists in the right mode, return the
3027 : : full pathname to the file. */
3028 : :
3029 : : struct file_at_path_info {
3030 : : const char *name;
3031 : : const char *suffix;
3032 : : int name_len;
3033 : : int suffix_len;
3034 : : int mode;
3035 : : };
3036 : :
3037 : : static void *
3038 : 7625178 : file_at_path (char *path, void *data)
3039 : : {
3040 : 7625178 : struct file_at_path_info *info = (struct file_at_path_info *) data;
3041 : 7625178 : size_t len = strlen (path);
3042 : :
3043 : 7625178 : memcpy (path + len, info->name, info->name_len);
3044 : 7625178 : len += info->name_len;
3045 : :
3046 : : /* Some systems have a suffix for executable files.
3047 : : So try appending that first. */
3048 : 7625178 : if (info->suffix_len)
3049 : : {
3050 : 0 : memcpy (path + len, info->suffix, info->suffix_len + 1);
3051 : 0 : if (access_check (path, info->mode) == 0)
3052 : : return path;
3053 : : }
3054 : :
3055 : 7625178 : path[len] = '\0';
3056 : 7625178 : if (access_check (path, info->mode) == 0)
3057 : : return path;
3058 : :
3059 : : return NULL;
3060 : : }
3061 : :
3062 : : /* Search for NAME using the prefix list PREFIXES. MODE is passed to
3063 : : access to check permissions. If DO_MULTI is true, search multilib
3064 : : paths then non-multilib paths, otherwise do not search multilib paths.
3065 : : Return 0 if not found, otherwise return its name, allocated with malloc. */
3066 : :
3067 : : static char *
3068 : 1717760 : find_a_file (const struct path_prefix *pprefix, const char *name, int mode,
3069 : : bool do_multi)
3070 : : {
3071 : 1717760 : struct file_at_path_info info;
3072 : :
3073 : : /* Find the filename in question (special case for absolute paths). */
3074 : :
3075 : 1717760 : if (IS_ABSOLUTE_PATH (name))
3076 : : {
3077 : 1 : if (access (name, mode) == 0)
3078 : 1 : return xstrdup (name);
3079 : :
3080 : : return NULL;
3081 : : }
3082 : :
3083 : 1717759 : info.name = name;
3084 : 1717759 : info.suffix = (mode & X_OK) != 0 ? HOST_EXECUTABLE_SUFFIX : "";
3085 : 1717759 : info.name_len = strlen (info.name);
3086 : 1717759 : info.suffix_len = strlen (info.suffix);
3087 : 1717759 : info.mode = mode;
3088 : :
3089 : 1717759 : return (char*) for_each_path (pprefix, do_multi,
3090 : : info.name_len + info.suffix_len,
3091 : 1717759 : file_at_path, &info);
3092 : : }
3093 : :
3094 : : /* Specialization of find_a_file for programs that also takes into account
3095 : : configure-specified default programs. */
3096 : :
3097 : : static char*
3098 : 724054 : find_a_program (const char *name)
3099 : : {
3100 : : /* Do not search if default matches query. */
3101 : :
3102 : : #ifdef DEFAULT_ASSEMBLER
3103 : : if (! strcmp (name, "as") && access (DEFAULT_ASSEMBLER, X_OK) == 0)
3104 : : return xstrdup (DEFAULT_ASSEMBLER);
3105 : : #endif
3106 : :
3107 : : #ifdef DEFAULT_LINKER
3108 : : if (! strcmp (name, "ld") && access (DEFAULT_LINKER, X_OK) == 0)
3109 : : return xstrdup (DEFAULT_LINKER);
3110 : : #endif
3111 : :
3112 : : #ifdef DEFAULT_DSYMUTIL
3113 : : if (! strcmp (name, "dsymutil") && access (DEFAULT_DSYMUTIL, X_OK) == 0)
3114 : : return xstrdup (DEFAULT_DSYMUTIL);
3115 : : #endif
3116 : :
3117 : 0 : return find_a_file (&exec_prefixes, name, X_OK, false);
3118 : : }
3119 : :
3120 : : /* Ranking of prefixes in the sort list. -B prefixes are put before
3121 : : all others. */
3122 : :
3123 : : enum path_prefix_priority
3124 : : {
3125 : : PREFIX_PRIORITY_B_OPT,
3126 : : PREFIX_PRIORITY_LAST
3127 : : };
3128 : :
3129 : : /* Add an entry for PREFIX in PLIST. The PLIST is kept in ascending
3130 : : order according to PRIORITY. Within each PRIORITY, new entries are
3131 : : appended.
3132 : :
3133 : : If WARN is nonzero, we will warn if no file is found
3134 : : through this prefix. WARN should point to an int
3135 : : which will be set to 1 if this entry is used.
3136 : :
3137 : : COMPONENT is the value to be passed to update_path.
3138 : :
3139 : : REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
3140 : : the complete value of machine_suffix.
3141 : : 2 means try both machine_suffix and just_machine_suffix. */
3142 : :
3143 : : static void
3144 : 3742227 : add_prefix (struct path_prefix *pprefix, const char *prefix,
3145 : : const char *component, /* enum prefix_priority */ int priority,
3146 : : int require_machine_suffix, int os_multilib)
3147 : : {
3148 : 3742227 : struct prefix_list *pl, **prev;
3149 : 3742227 : int len;
3150 : :
3151 : 3742227 : for (prev = &pprefix->plist;
3152 : 11782577 : (*prev) != NULL && (*prev)->priority <= priority;
3153 : 8040350 : prev = &(*prev)->next)
3154 : : ;
3155 : :
3156 : : /* Keep track of the longest prefix. */
3157 : :
3158 : 3742227 : prefix = update_path (prefix, component);
3159 : 3742227 : len = strlen (prefix);
3160 : 3742227 : if (len > pprefix->max_len)
3161 : 2029520 : pprefix->max_len = len;
3162 : :
3163 : 3742227 : pl = XNEW (struct prefix_list);
3164 : 3742227 : pl->prefix = prefix;
3165 : 3742227 : pl->require_machine_suffix = require_machine_suffix;
3166 : 3742227 : pl->priority = priority;
3167 : 3742227 : pl->os_multilib = os_multilib;
3168 : :
3169 : : /* Insert after PREV. */
3170 : 3742227 : pl->next = (*prev);
3171 : 3742227 : (*prev) = pl;
3172 : 3742227 : }
3173 : :
3174 : : /* Same as add_prefix, but prepending target_system_root to prefix. */
3175 : : /* The target_system_root prefix has been relocated by gcc_exec_prefix. */
3176 : : static void
3177 : 574988 : add_sysrooted_prefix (struct path_prefix *pprefix, const char *prefix,
3178 : : const char *component,
3179 : : /* enum prefix_priority */ int priority,
3180 : : int require_machine_suffix, int os_multilib)
3181 : : {
3182 : 574988 : if (!IS_ABSOLUTE_PATH (prefix))
3183 : 0 : fatal_error (input_location, "system path %qs is not absolute", prefix);
3184 : :
3185 : 574988 : if (target_system_root)
3186 : : {
3187 : 0 : char *sysroot_no_trailing_dir_separator = xstrdup (target_system_root);
3188 : 0 : size_t sysroot_len = strlen (target_system_root);
3189 : :
3190 : 0 : if (sysroot_len > 0
3191 : 0 : && target_system_root[sysroot_len - 1] == DIR_SEPARATOR)
3192 : 0 : sysroot_no_trailing_dir_separator[sysroot_len - 1] = '\0';
3193 : :
3194 : 0 : if (target_sysroot_suffix)
3195 : 0 : prefix = concat (sysroot_no_trailing_dir_separator,
3196 : : target_sysroot_suffix, prefix, NULL);
3197 : : else
3198 : 0 : prefix = concat (sysroot_no_trailing_dir_separator, prefix, NULL);
3199 : :
3200 : 0 : free (sysroot_no_trailing_dir_separator);
3201 : :
3202 : : /* We have to override this because GCC's notion of sysroot
3203 : : moves along with GCC. */
3204 : 0 : component = "GCC";
3205 : : }
3206 : :
3207 : 574988 : add_prefix (pprefix, prefix, component, priority,
3208 : : require_machine_suffix, os_multilib);
3209 : 574988 : }
3210 : :
3211 : : /* Same as add_prefix, but prepending target_sysroot_hdrs_suffix to prefix. */
3212 : :
3213 : : static void
3214 : 30506 : add_sysrooted_hdrs_prefix (struct path_prefix *pprefix, const char *prefix,
3215 : : const char *component,
3216 : : /* enum prefix_priority */ int priority,
3217 : : int require_machine_suffix, int os_multilib)
3218 : : {
3219 : 30506 : if (!IS_ABSOLUTE_PATH (prefix))
3220 : 0 : fatal_error (input_location, "system path %qs is not absolute", prefix);
3221 : :
3222 : 30506 : if (target_system_root)
3223 : : {
3224 : 0 : char *sysroot_no_trailing_dir_separator = xstrdup (target_system_root);
3225 : 0 : size_t sysroot_len = strlen (target_system_root);
3226 : :
3227 : 0 : if (sysroot_len > 0
3228 : 0 : && target_system_root[sysroot_len - 1] == DIR_SEPARATOR)
3229 : 0 : sysroot_no_trailing_dir_separator[sysroot_len - 1] = '\0';
3230 : :
3231 : 0 : if (target_sysroot_hdrs_suffix)
3232 : 0 : prefix = concat (sysroot_no_trailing_dir_separator,
3233 : : target_sysroot_hdrs_suffix, prefix, NULL);
3234 : : else
3235 : 0 : prefix = concat (sysroot_no_trailing_dir_separator, prefix, NULL);
3236 : :
3237 : 0 : free (sysroot_no_trailing_dir_separator);
3238 : :
3239 : : /* We have to override this because GCC's notion of sysroot
3240 : : moves along with GCC. */
3241 : 0 : component = "GCC";
3242 : : }
3243 : :
3244 : 30506 : add_prefix (pprefix, prefix, component, priority,
3245 : : require_machine_suffix, os_multilib);
3246 : 30506 : }
3247 : :
3248 : :
3249 : : /* Execute the command specified by the arguments on the current line of spec.
3250 : : When using pipes, this includes several piped-together commands
3251 : : with `|' between them.
3252 : :
3253 : : Return 0 if successful, -1 if failed. */
3254 : :
3255 : : static int
3256 : 524763 : execute (void)
3257 : : {
3258 : 524763 : int i;
3259 : 524763 : int n_commands; /* # of command. */
3260 : 524763 : char *string;
3261 : 524763 : struct pex_obj *pex;
3262 : 524763 : struct command
3263 : : {
3264 : : const char *prog; /* program name. */
3265 : : const char **argv; /* vector of args. */
3266 : : };
3267 : 524763 : const char *arg;
3268 : :
3269 : 524763 : struct command *commands; /* each command buffer with above info. */
3270 : :
3271 : 524763 : gcc_assert (!processing_spec_function);
3272 : :
3273 : 524763 : if (wrapper_string)
3274 : : {
3275 : 0 : string = find_a_program (argbuf[0]);
3276 : 0 : if (string)
3277 : 0 : argbuf[0] = string;
3278 : 0 : insert_wrapper (wrapper_string);
3279 : : }
3280 : :
3281 : : /* Count # of piped commands. */
3282 : 15967597 : for (n_commands = 1, i = 0; argbuf.iterate (i, &arg); i++)
3283 : 15442834 : if (strcmp (arg, "|") == 0)
3284 : 0 : n_commands++;
3285 : :
3286 : : /* Get storage for each command. */
3287 : 524763 : commands = XALLOCAVEC (struct command, n_commands);
3288 : :
3289 : : /* Split argbuf into its separate piped processes,
3290 : : and record info about each one.
3291 : : Also search for the programs that are to be run. */
3292 : :
3293 : 524763 : argbuf.safe_push (0);
3294 : :
3295 : 524763 : commands[0].prog = argbuf[0]; /* first command. */
3296 : 524763 : commands[0].argv = argbuf.address ();
3297 : :
3298 : 524763 : if (!wrapper_string)
3299 : : {
3300 : 524763 : string = find_a_program(commands[0].prog);
3301 : 524763 : if (string)
3302 : 522214 : commands[0].argv[0] = string;
3303 : : }
3304 : :
3305 : 16492360 : for (n_commands = 1, i = 0; argbuf.iterate (i, &arg); i++)
3306 : 15967597 : if (arg && strcmp (arg, "|") == 0)
3307 : : { /* each command. */
3308 : : #if defined (__MSDOS__) || defined (OS2) || defined (VMS)
3309 : : fatal_error (input_location, "%<-pipe%> not supported");
3310 : : #endif
3311 : 0 : argbuf[i] = 0; /* Termination of command args. */
3312 : 0 : commands[n_commands].prog = argbuf[i + 1];
3313 : 0 : commands[n_commands].argv
3314 : 0 : = &(argbuf.address ())[i + 1];
3315 : 0 : string = find_a_program(commands[n_commands].prog);
3316 : 0 : if (string)
3317 : 0 : commands[n_commands].argv[0] = string;
3318 : 0 : n_commands++;
3319 : : }
3320 : :
3321 : : /* If -v, print what we are about to do, and maybe query. */
3322 : :
3323 : 524763 : if (verbose_flag)
3324 : : {
3325 : : /* For help listings, put a blank line between sub-processes. */
3326 : 1391 : if (print_help_list)
3327 : 9 : fputc ('\n', stderr);
3328 : :
3329 : : /* Print each piped command as a separate line. */
3330 : 2782 : for (i = 0; i < n_commands; i++)
3331 : : {
3332 : 1391 : const char *const *j;
3333 : :
3334 : 1391 : if (verbose_only_flag)
3335 : : {
3336 : 17868 : for (j = commands[i].argv; *j; j++)
3337 : : {
3338 : : const char *p;
3339 : 427425 : for (p = *j; *p; ++p)
3340 : 413056 : if (!ISALNUM ((unsigned char) *p)
3341 : 97638 : && *p != '_' && *p != '/' && *p != '-' && *p != '.')
3342 : : break;
3343 : 16853 : if (*p || !*j)
3344 : : {
3345 : 2484 : fprintf (stderr, " \"");
3346 : 129355 : for (p = *j; *p; ++p)
3347 : : {
3348 : 126871 : if (*p == '"' || *p == '\\' || *p == '$')
3349 : 0 : fputc ('\\', stderr);
3350 : 126871 : fputc (*p, stderr);
3351 : : }
3352 : 2484 : fputc ('"', stderr);
3353 : : }
3354 : : /* If it's empty, print "". */
3355 : 14369 : else if (!**j)
3356 : 0 : fprintf (stderr, " \"\"");
3357 : : else
3358 : 14369 : fprintf (stderr, " %s", *j);
3359 : : }
3360 : : }
3361 : : else
3362 : 10564 : for (j = commands[i].argv; *j; j++)
3363 : : /* If it's empty, print "". */
3364 : 10188 : if (!**j)
3365 : 0 : fprintf (stderr, " \"\"");
3366 : : else
3367 : 10188 : fprintf (stderr, " %s", *j);
3368 : :
3369 : : /* Print a pipe symbol after all but the last command. */
3370 : 1391 : if (i + 1 != n_commands)
3371 : 0 : fprintf (stderr, " |");
3372 : 1391 : fprintf (stderr, "\n");
3373 : : }
3374 : 1391 : fflush (stderr);
3375 : 1391 : if (verbose_only_flag != 0)
3376 : : {
3377 : : /* verbose_only_flag should act as if the spec was
3378 : : executed, so increment execution_count before
3379 : : returning. This prevents spurious warnings about
3380 : : unused linker input files, etc. */
3381 : 1015 : execution_count++;
3382 : 1015 : return 0;
3383 : : }
3384 : : #ifdef DEBUG
3385 : : fnotice (stderr, "\nGo ahead? (y or n) ");
3386 : : fflush (stderr);
3387 : : i = getchar ();
3388 : : if (i != '\n')
3389 : : while (getchar () != '\n')
3390 : : ;
3391 : :
3392 : : if (i != 'y' && i != 'Y')
3393 : : return 0;
3394 : : #endif /* DEBUG */
3395 : : }
3396 : :
3397 : : #ifdef ENABLE_VALGRIND_CHECKING
3398 : : /* Run the each command through valgrind. To simplify prepending the
3399 : : path to valgrind and the option "-q" (for quiet operation unless
3400 : : something triggers), we allocate a separate argv array. */
3401 : :
3402 : : for (i = 0; i < n_commands; i++)
3403 : : {
3404 : : const char **argv;
3405 : : int argc;
3406 : : int j;
3407 : :
3408 : : for (argc = 0; commands[i].argv[argc] != NULL; argc++)
3409 : : ;
3410 : :
3411 : : argv = XALLOCAVEC (const char *, argc + 3);
3412 : :
3413 : : argv[0] = VALGRIND_PATH;
3414 : : argv[1] = "-q";
3415 : : for (j = 2; j < argc + 2; j++)
3416 : : argv[j] = commands[i].argv[j - 2];
3417 : : argv[j] = NULL;
3418 : :
3419 : : commands[i].argv = argv;
3420 : : commands[i].prog = argv[0];
3421 : : }
3422 : : #endif
3423 : :
3424 : : /* Run each piped subprocess. */
3425 : :
3426 : 523748 : pex = pex_init (PEX_USE_PIPES | ((report_times || report_times_to_file)
3427 : : ? PEX_RECORD_TIMES : 0),
3428 : : progname, temp_filename);
3429 : 523748 : if (pex == NULL)
3430 : : fatal_error (input_location, "%<pex_init%> failed: %m");
3431 : :
3432 : 1047496 : for (i = 0; i < n_commands; i++)
3433 : : {
3434 : 523748 : const char *errmsg;
3435 : 523748 : int err;
3436 : 523748 : const char *string = commands[i].argv[0];
3437 : :
3438 : 523748 : errmsg = pex_run (pex,
3439 : 523748 : ((i + 1 == n_commands ? PEX_LAST : 0)
3440 : 523748 : | (string == commands[i].prog ? PEX_SEARCH : 0)),
3441 : : string, CONST_CAST (char **, commands[i].argv),
3442 : : NULL, NULL, &err);
3443 : 523748 : if (errmsg != NULL)
3444 : : {
3445 : 0 : errno = err;
3446 : 0 : fatal_error (input_location,
3447 : : err ? G_("cannot execute %qs: %s: %m")
3448 : : : G_("cannot execute %qs: %s"),
3449 : : string, errmsg);
3450 : : }
3451 : :
3452 : 523748 : if (i && string != commands[i].prog)
3453 : 0 : free (CONST_CAST (char *, string));
3454 : : }
3455 : :
3456 : 523748 : execution_count++;
3457 : :
3458 : : /* Wait for all the subprocesses to finish. */
3459 : :
3460 : 523748 : {
3461 : 523748 : int *statuses;
3462 : 523748 : struct pex_time *times = NULL;
3463 : 523748 : int ret_code = 0;
3464 : :
3465 : 523748 : statuses = XALLOCAVEC (int, n_commands);
3466 : 523748 : if (!pex_get_status (pex, n_commands, statuses))
3467 : 0 : fatal_error (input_location, "failed to get exit status: %m");
3468 : :
3469 : 523748 : if (report_times || report_times_to_file)
3470 : : {
3471 : 0 : times = XALLOCAVEC (struct pex_time, n_commands);
3472 : 0 : if (!pex_get_times (pex, n_commands, times))
3473 : 0 : fatal_error (input_location, "failed to get process times: %m");
3474 : : }
3475 : :
3476 : 523748 : pex_free (pex);
3477 : :
3478 : 1047496 : for (i = 0; i < n_commands; ++i)
3479 : : {
3480 : 523748 : int status = statuses[i];
3481 : :
3482 : 523748 : if (WIFSIGNALED (status))
3483 : 0 : switch (WTERMSIG (status))
3484 : : {
3485 : 0 : case SIGINT:
3486 : 0 : case SIGTERM:
3487 : : /* SIGQUIT and SIGKILL are not available on MinGW. */
3488 : : #ifdef SIGQUIT
3489 : 0 : case SIGQUIT:
3490 : : #endif
3491 : : #ifdef SIGKILL
3492 : 0 : case SIGKILL:
3493 : : #endif
3494 : : /* The user (or environment) did something to the
3495 : : inferior. Making this an ICE confuses the user into
3496 : : thinking there's a compiler bug. Much more likely is
3497 : : the user or OOM killer nuked it. */
3498 : 0 : fatal_error (input_location,
3499 : : "%s signal terminated program %s",
3500 : : strsignal (WTERMSIG (status)),
3501 : 0 : commands[i].prog);
3502 : 0 : break;
3503 : :
3504 : : #ifdef SIGPIPE
3505 : 0 : case SIGPIPE:
3506 : : /* SIGPIPE is a special case. It happens in -pipe mode
3507 : : when the compiler dies before the preprocessor is
3508 : : done, or the assembler dies before the compiler is
3509 : : done. There's generally been an error already, and
3510 : : this is just fallout. So don't generate another
3511 : : error unless we would otherwise have succeeded. */
3512 : 0 : if (signal_count || greatest_status >= MIN_FATAL_STATUS)
3513 : : {
3514 : 0 : signal_count++;
3515 : 0 : ret_code = -1;
3516 : 0 : break;
3517 : : }
3518 : : #endif
3519 : : /* FALLTHROUGH */
3520 : :
3521 : 0 : default:
3522 : : /* The inferior failed to catch the signal. */
3523 : 0 : internal_error_no_backtrace ("%s signal terminated program %s",
3524 : : strsignal (WTERMSIG (status)),
3525 : 0 : commands[i].prog);
3526 : : }
3527 : 523748 : else if (WIFEXITED (status)
3528 : 523748 : && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
3529 : : {
3530 : : /* For ICEs in cc1, cc1obj, cc1plus see if it is
3531 : : reproducible or not. */
3532 : 28330 : const char *p;
3533 : 28330 : if (flag_report_bug
3534 : 0 : && WEXITSTATUS (status) == ICE_EXIT_CODE
3535 : 0 : && i == 0
3536 : 0 : && (p = strrchr (commands[0].argv[0], DIR_SEPARATOR))
3537 : 28330 : && startswith (p + 1, "cc1"))
3538 : 0 : try_generate_repro (commands[0].argv);
3539 : 28330 : if (WEXITSTATUS (status) > greatest_status)
3540 : 23 : greatest_status = WEXITSTATUS (status);
3541 : : ret_code = -1;
3542 : : }
3543 : :
3544 : 523748 : if (report_times || report_times_to_file)
3545 : : {
3546 : 0 : struct pex_time *pt = ×[i];
3547 : 0 : double ut, st;
3548 : :
3549 : 0 : ut = ((double) pt->user_seconds
3550 : 0 : + (double) pt->user_microseconds / 1.0e6);
3551 : 0 : st = ((double) pt->system_seconds
3552 : 0 : + (double) pt->system_microseconds / 1.0e6);
3553 : :
3554 : 0 : if (ut + st != 0)
3555 : : {
3556 : 0 : if (report_times)
3557 : 0 : fnotice (stderr, "# %s %.2f %.2f\n",
3558 : 0 : commands[i].prog, ut, st);
3559 : :
3560 : 0 : if (report_times_to_file)
3561 : : {
3562 : 0 : int c = 0;
3563 : 0 : const char *const *j;
3564 : :
3565 : 0 : fprintf (report_times_to_file, "%g %g", ut, st);
3566 : :
3567 : 0 : for (j = &commands[i].prog; *j; j = &commands[i].argv[++c])
3568 : : {
3569 : : const char *p;
3570 : 0 : for (p = *j; *p; ++p)
3571 : 0 : if (*p == '"' || *p == '\\' || *p == '$'
3572 : 0 : || ISSPACE (*p))
3573 : : break;
3574 : :
3575 : 0 : if (*p)
3576 : : {
3577 : 0 : fprintf (report_times_to_file, " \"");
3578 : 0 : for (p = *j; *p; ++p)
3579 : : {
3580 : 0 : if (*p == '"' || *p == '\\' || *p == '$')
3581 : 0 : fputc ('\\', report_times_to_file);
3582 : 0 : fputc (*p, report_times_to_file);
3583 : : }
3584 : 0 : fputc ('"', report_times_to_file);
3585 : : }
3586 : : else
3587 : 0 : fprintf (report_times_to_file, " %s", *j);
3588 : : }
3589 : :
3590 : 0 : fputc ('\n', report_times_to_file);
3591 : : }
3592 : : }
3593 : : }
3594 : : }
3595 : :
3596 : 523748 : if (commands[0].argv[0] != commands[0].prog)
3597 : 521199 : free (CONST_CAST (char *, commands[0].argv[0]));
3598 : :
3599 : : return ret_code;
3600 : : }
3601 : : }
3602 : :
3603 : : static struct switchstr *switches;
3604 : :
3605 : : static int n_switches;
3606 : :
3607 : : static int n_switches_alloc;
3608 : :
3609 : : /* Set to zero if -fcompare-debug is disabled, positive if it's
3610 : : enabled and we're running the first compilation, negative if it's
3611 : : enabled and we're running the second compilation. For most of the
3612 : : time, it's in the range -1..1, but it can be temporarily set to 2
3613 : : or 3 to indicate that the -fcompare-debug flags didn't come from
3614 : : the command-line, but rather from the GCC_COMPARE_DEBUG environment
3615 : : variable, until a synthesized -fcompare-debug flag is added to the
3616 : : command line. */
3617 : : int compare_debug;
3618 : :
3619 : : /* Set to nonzero if we've seen the -fcompare-debug-second flag. */
3620 : : int compare_debug_second;
3621 : :
3622 : : /* Set to the flags that should be passed to the second compilation in
3623 : : a -fcompare-debug compilation. */
3624 : : const char *compare_debug_opt;
3625 : :
3626 : : static struct switchstr *switches_debug_check[2];
3627 : :
3628 : : static int n_switches_debug_check[2];
3629 : :
3630 : : static int n_switches_alloc_debug_check[2];
3631 : :
3632 : : static char *debug_check_temp_file[2];
3633 : :
3634 : : /* Language is one of three things:
3635 : :
3636 : : 1) The name of a real programming language.
3637 : : 2) NULL, indicating that no one has figured out
3638 : : what it is yet.
3639 : : 3) '*', indicating that the file should be passed
3640 : : to the linker. */
3641 : : struct infile
3642 : : {
3643 : : const char *name;
3644 : : const char *language;
3645 : : struct compiler *incompiler;
3646 : : bool compiled;
3647 : : bool preprocessed;
3648 : : };
3649 : :
3650 : : /* Also a vector of input files specified. */
3651 : :
3652 : : static struct infile *infiles;
3653 : :
3654 : : int n_infiles;
3655 : :
3656 : : static int n_infiles_alloc;
3657 : :
3658 : : /* True if undefined environment variables encountered during spec processing
3659 : : are ok to ignore, typically when we're running for --help or --version. */
3660 : :
3661 : : static bool spec_undefvar_allowed;
3662 : :
3663 : : /* True if multiple input files are being compiled to a single
3664 : : assembly file. */
3665 : :
3666 : : static bool combine_inputs;
3667 : :
3668 : : /* This counts the number of libraries added by lang_specific_driver, so that
3669 : : we can tell if there were any user supplied any files or libraries. */
3670 : :
3671 : : static int added_libraries;
3672 : :
3673 : : /* And a vector of corresponding output files is made up later. */
3674 : :
3675 : : const char **outfiles;
3676 : :
3677 : : #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3678 : :
3679 : : /* Convert NAME to a new name if it is the standard suffix. DO_EXE
3680 : : is true if we should look for an executable suffix. DO_OBJ
3681 : : is true if we should look for an object suffix. */
3682 : :
3683 : : static const char *
3684 : : convert_filename (const char *name, int do_exe ATTRIBUTE_UNUSED,
3685 : : int do_obj ATTRIBUTE_UNUSED)
3686 : : {
3687 : : #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3688 : : int i;
3689 : : #endif
3690 : : int len;
3691 : :
3692 : : if (name == NULL)
3693 : : return NULL;
3694 : :
3695 : : len = strlen (name);
3696 : :
3697 : : #ifdef HAVE_TARGET_OBJECT_SUFFIX
3698 : : /* Convert x.o to x.obj if TARGET_OBJECT_SUFFIX is ".obj". */
3699 : : if (do_obj && len > 2
3700 : : && name[len - 2] == '.'
3701 : : && name[len - 1] == 'o')
3702 : : {
3703 : : obstack_grow (&obstack, name, len - 2);
3704 : : obstack_grow0 (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX));
3705 : : name = XOBFINISH (&obstack, const char *);
3706 : : }
3707 : : #endif
3708 : :
3709 : : #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3710 : : /* If there is no filetype, make it the executable suffix (which includes
3711 : : the "."). But don't get confused if we have just "-o". */
3712 : : if (! do_exe || TARGET_EXECUTABLE_SUFFIX[0] == 0 || not_actual_file_p (name))
3713 : : return name;
3714 : :
3715 : : for (i = len - 1; i >= 0; i--)
3716 : : if (IS_DIR_SEPARATOR (name[i]))
3717 : : break;
3718 : :
3719 : : for (i++; i < len; i++)
3720 : : if (name[i] == '.')
3721 : : return name;
3722 : :
3723 : : obstack_grow (&obstack, name, len);
3724 : : obstack_grow0 (&obstack, TARGET_EXECUTABLE_SUFFIX,
3725 : : strlen (TARGET_EXECUTABLE_SUFFIX));
3726 : : name = XOBFINISH (&obstack, const char *);
3727 : : #endif
3728 : :
3729 : : return name;
3730 : : }
3731 : : #endif
3732 : :
3733 : : /* Display the command line switches accepted by gcc. */
3734 : : static void
3735 : 4 : display_help (void)
3736 : : {
3737 : 4 : printf (_("Usage: %s [options] file...\n"), progname);
3738 : 4 : fputs (_("Options:\n"), stdout);
3739 : :
3740 : 4 : fputs (_(" -pass-exit-codes Exit with highest error code from a phase.\n"), stdout);
3741 : 4 : fputs (_(" --help Display this information.\n"), stdout);
3742 : 4 : fputs (_(" --target-help Display target specific command line options "
3743 : : "(including assembler and linker options).\n"), stdout);
3744 : 4 : fputs (_(" --help={common|optimizers|params|target|warnings|[^]{joined|separate|undocumented}}[,...].\n"), stdout);
3745 : 4 : fputs (_(" Display specific types of command line options.\n"), stdout);
3746 : 4 : if (! verbose_flag)
3747 : 1 : fputs (_(" (Use '-v --help' to display command line options of sub-processes).\n"), stdout);
3748 : 4 : fputs (_(" --version Display compiler version information.\n"), stdout);
3749 : 4 : fputs (_(" -dumpspecs Display all of the built in spec strings.\n"), stdout);
3750 : 4 : fputs (_(" -dumpversion Display the version of the compiler.\n"), stdout);
3751 : 4 : fputs (_(" -dumpmachine Display the compiler's target processor.\n"), stdout);
3752 : 4 : fputs (_(" -foffload=<targets> Specify offloading targets.\n"), stdout);
3753 : 4 : fputs (_(" -print-search-dirs Display the directories in the compiler's search path.\n"), stdout);
3754 : 4 : fputs (_(" -print-libgcc-file-name Display the name of the compiler's companion library.\n"), stdout);
3755 : 4 : fputs (_(" -print-file-name=<lib> Display the full path to library <lib>.\n"), stdout);
3756 : 4 : fputs (_(" -print-prog-name=<prog> Display the full path to compiler component <prog>.\n"), stdout);
3757 : 4 : fputs (_("\
3758 : : -print-multiarch Display the target's normalized GNU triplet, used as\n\
3759 : : a component in the library path.\n"), stdout);
3760 : 4 : fputs (_(" -print-multi-directory Display the root directory for versions of libgcc.\n"), stdout);
3761 : 4 : fputs (_("\
3762 : : -print-multi-lib Display the mapping between command line options and\n\
3763 : : multiple library search directories.\n"), stdout);
3764 : 4 : fputs (_(" -print-multi-os-directory Display the relative path to OS libraries.\n"), stdout);
3765 : 4 : fputs (_(" -print-sysroot Display the target libraries directory.\n"), stdout);
3766 : 4 : fputs (_(" -print-sysroot-headers-suffix Display the sysroot suffix used to find headers.\n"), stdout);
3767 : 4 : fputs (_(" -Wa,<options> Pass comma-separated <options> on to the assembler.\n"), stdout);
3768 : 4 : fputs (_(" -Wp,<options> Pass comma-separated <options> on to the preprocessor.\n"), stdout);
3769 : 4 : fputs (_(" -Wl,<options> Pass comma-separated <options> on to the linker.\n"), stdout);
3770 : 4 : fputs (_(" -Xassembler <arg> Pass <arg> on to the assembler.\n"), stdout);
3771 : 4 : fputs (_(" -Xpreprocessor <arg> Pass <arg> on to the preprocessor.\n"), stdout);
3772 : 4 : fputs (_(" -Xlinker <arg> Pass <arg> on to the linker.\n"), stdout);
3773 : 4 : fputs (_(" -save-temps Do not delete intermediate files.\n"), stdout);
3774 : 4 : fputs (_(" -save-temps=<arg> Do not delete intermediate files.\n"), stdout);
3775 : 4 : fputs (_("\
3776 : : -no-canonical-prefixes Do not canonicalize paths when building relative\n\
3777 : : prefixes to other gcc components.\n"), stdout);
3778 : 4 : fputs (_(" -pipe Use pipes rather than intermediate files.\n"), stdout);
3779 : 4 : fputs (_(" -time Time the execution of each subprocess.\n"), stdout);
3780 : 4 : fputs (_(" -specs=<file> Override built-in specs with the contents of <file>.\n"), stdout);
3781 : 4 : fputs (_(" -std=<standard> Assume that the input sources are for <standard>.\n"), stdout);
3782 : 4 : fputs (_("\
3783 : : --sysroot=<directory> Use <directory> as the root directory for headers\n\
3784 : : and libraries.\n"), stdout);
3785 : 4 : fputs (_(" -B <directory> Add <directory> to the compiler's search paths.\n"), stdout);
3786 : 4 : fputs (_(" -v Display the programs invoked by the compiler.\n"), stdout);
3787 : 4 : fputs (_(" -### Like -v but options quoted and commands not executed.\n"), stdout);
3788 : 4 : fputs (_(" -E Preprocess only; do not compile, assemble or link.\n"), stdout);
3789 : 4 : fputs (_(" -S Compile only; do not assemble or link.\n"), stdout);
3790 : 4 : fputs (_(" -c Compile and assemble, but do not link.\n"), stdout);
3791 : 4 : fputs (_(" -o <file> Place the output into <file>.\n"), stdout);
3792 : 4 : fputs (_(" -pie Create a dynamically linked position independent\n\
3793 : : executable.\n"), stdout);
3794 : 4 : fputs (_(" -shared Create a shared library.\n"), stdout);
3795 : 4 : fputs (_("\
3796 : : -x <language> Specify the language of the following input files.\n\
3797 : : Permissible languages include: c c++ assembler none\n\
3798 : : 'none' means revert to the default behavior of\n\
3799 : : guessing the language based on the file's extension.\n\
3800 : : "), stdout);
3801 : :
3802 : 4 : printf (_("\
3803 : : \nOptions starting with -g, -f, -m, -O, -W, or --param are automatically\n\
3804 : : passed on to the various sub-processes invoked by %s. In order to pass\n\
3805 : : other options on to these processes the -W<letter> options must be used.\n\
3806 : : "), progname);
3807 : :
3808 : : /* The rest of the options are displayed by invocations of the various
3809 : : sub-processes. */
3810 : 4 : }
3811 : :
3812 : : static void
3813 : 0 : add_preprocessor_option (const char *option, int len)
3814 : : {
3815 : 0 : preprocessor_options.safe_push (save_string (option, len));
3816 : 0 : }
3817 : :
3818 : : static void
3819 : 183 : add_assembler_option (const char *option, int len)
3820 : : {
3821 : 183 : assembler_options.safe_push (save_string (option, len));
3822 : 183 : }
3823 : :
3824 : : static void
3825 : 82 : add_linker_option (const char *option, int len)
3826 : : {
3827 : 82 : linker_options.safe_push (save_string (option, len));
3828 : 82 : }
3829 : :
3830 : : /* Allocate space for an input file in infiles. */
3831 : :
3832 : : static void
3833 : 853703 : alloc_infile (void)
3834 : : {
3835 : 853703 : if (n_infiles_alloc == 0)
3836 : : {
3837 : 287495 : n_infiles_alloc = 16;
3838 : 287495 : infiles = XNEWVEC (struct infile, n_infiles_alloc);
3839 : : }
3840 : 566208 : else if (n_infiles_alloc == n_infiles)
3841 : : {
3842 : 245 : n_infiles_alloc *= 2;
3843 : 245 : infiles = XRESIZEVEC (struct infile, infiles, n_infiles_alloc);
3844 : : }
3845 : 853703 : }
3846 : :
3847 : : /* Store an input file with the given NAME and LANGUAGE in
3848 : : infiles. */
3849 : :
3850 : : static void
3851 : 566209 : add_infile (const char *name, const char *language)
3852 : : {
3853 : 566209 : alloc_infile ();
3854 : 566209 : infiles[n_infiles].name = name;
3855 : 566209 : infiles[n_infiles++].language = language;
3856 : 566209 : }
3857 : :
3858 : : /* Allocate space for a switch in switches. */
3859 : :
3860 : : static void
3861 : 7062934 : alloc_switch (void)
3862 : : {
3863 : 7062934 : if (n_switches_alloc == 0)
3864 : : {
3865 : 287808 : n_switches_alloc = 16;
3866 : 287808 : switches = XNEWVEC (struct switchstr, n_switches_alloc);
3867 : : }
3868 : 6775126 : else if (n_switches_alloc == n_switches)
3869 : : {
3870 : 243339 : n_switches_alloc *= 2;
3871 : 243339 : switches = XRESIZEVEC (struct switchstr, switches, n_switches_alloc);
3872 : : }
3873 : 7062934 : }
3874 : :
3875 : : /* Save an option OPT with N_ARGS arguments in array ARGS, marking it
3876 : : as validated if VALIDATED and KNOWN if it is an internal switch. */
3877 : :
3878 : : static void
3879 : 6228380 : save_switch (const char *opt, size_t n_args, const char *const *args,
3880 : : bool validated, bool known)
3881 : : {
3882 : 6228380 : alloc_switch ();
3883 : 6228380 : switches[n_switches].part1 = opt + 1;
3884 : 6228380 : if (n_args == 0)
3885 : 4745104 : switches[n_switches].args = 0;
3886 : : else
3887 : : {
3888 : 1483276 : switches[n_switches].args = XNEWVEC (const char *, n_args + 1);
3889 : 1483276 : memcpy (switches[n_switches].args, args, n_args * sizeof (const char *));
3890 : 1483276 : switches[n_switches].args[n_args] = NULL;
3891 : : }
3892 : :
3893 : 6228380 : switches[n_switches].live_cond = 0;
3894 : 6228380 : switches[n_switches].validated = validated;
3895 : 6228380 : switches[n_switches].known = known;
3896 : 6228380 : switches[n_switches].ordering = 0;
3897 : 6228380 : n_switches++;
3898 : 6228380 : }
3899 : :
3900 : : /* Set the SOURCE_DATE_EPOCH environment variable to the current time if it is
3901 : : not set already. */
3902 : :
3903 : : static void
3904 : 622 : set_source_date_epoch_envvar ()
3905 : : {
3906 : : /* Array size is 21 = ceil(log_10(2^64)) + 1 to hold string representations
3907 : : of 64 bit integers. */
3908 : 622 : char source_date_epoch[21];
3909 : 622 : time_t tt;
3910 : :
3911 : 622 : errno = 0;
3912 : 622 : tt = time (NULL);
3913 : 622 : if (tt < (time_t) 0 || errno != 0)
3914 : 0 : tt = (time_t) 0;
3915 : :
3916 : 622 : snprintf (source_date_epoch, 21, "%llu", (unsigned long long) tt);
3917 : : /* Using setenv instead of xputenv because we want the variable to remain
3918 : : after finalizing so that it's still set in the second run when using
3919 : : -fcompare-debug. */
3920 : 622 : setenv ("SOURCE_DATE_EPOCH", source_date_epoch, 0);
3921 : 622 : }
3922 : :
3923 : : /* Handle an option DECODED that is unknown to the option-processing
3924 : : machinery. */
3925 : :
3926 : : static bool
3927 : 572 : driver_unknown_option_callback (const struct cl_decoded_option *decoded)
3928 : : {
3929 : 572 : const char *opt = decoded->arg;
3930 : 572 : if (opt[1] == 'W' && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-'
3931 : 93 : && !(decoded->errors & CL_ERR_NEGATIVE))
3932 : : {
3933 : : /* Leave unknown -Wno-* options for the compiler proper, to be
3934 : : diagnosed only if there are warnings. */
3935 : 91 : save_switch (decoded->canonical_option[0],
3936 : 91 : decoded->canonical_option_num_elements - 1,
3937 : : &decoded->canonical_option[1], false, true);
3938 : 91 : return false;
3939 : : }
3940 : 481 : if (decoded->opt_index == OPT_SPECIAL_unknown)
3941 : : {
3942 : : /* Give it a chance to define it a spec file. */
3943 : 481 : save_switch (decoded->canonical_option[0],
3944 : 481 : decoded->canonical_option_num_elements - 1,
3945 : : &decoded->canonical_option[1], false, false);
3946 : 481 : return false;
3947 : : }
3948 : : else
3949 : : return true;
3950 : : }
3951 : :
3952 : : /* Handle an option DECODED that is not marked as CL_DRIVER.
3953 : : LANG_MASK will always be CL_DRIVER. */
3954 : :
3955 : : static void
3956 : 3925711 : driver_wrong_lang_callback (const struct cl_decoded_option *decoded,
3957 : : unsigned int lang_mask ATTRIBUTE_UNUSED)
3958 : : {
3959 : : /* At this point, non-driver options are accepted (and expected to
3960 : : be passed down by specs) unless marked to be rejected by the
3961 : : driver. Options to be rejected by the driver but accepted by the
3962 : : compilers proper are treated just like completely unknown
3963 : : options. */
3964 : 3925711 : const struct cl_option *option = &cl_options[decoded->opt_index];
3965 : :
3966 : 3925711 : if (option->cl_reject_driver)
3967 : 0 : error ("unrecognized command-line option %qs",
3968 : 0 : decoded->orig_option_with_args_text);
3969 : : else
3970 : 3925711 : save_switch (decoded->canonical_option[0],
3971 : 3925711 : decoded->canonical_option_num_elements - 1,
3972 : : &decoded->canonical_option[1], false, true);
3973 : 3925711 : }
3974 : :
3975 : : static const char *spec_lang = 0;
3976 : : static int last_language_n_infiles;
3977 : :
3978 : :
3979 : : /* Check that GCC is configured to support the offload target. */
3980 : :
3981 : : static bool
3982 : 103 : check_offload_target_name (const char *target, ptrdiff_t len)
3983 : : {
3984 : 103 : const char *n, *c = OFFLOAD_TARGETS;
3985 : 206 : while (c)
3986 : : {
3987 : 103 : n = strchr (c, ',');
3988 : 103 : if (n == NULL)
3989 : 103 : n = strchr (c, '\0');
3990 : 103 : if (len == n - c && strncmp (target, c, n - c) == 0)
3991 : : break;
3992 : 103 : c = *n ? n + 1 : NULL;
3993 : : }
3994 : 103 : if (!c)
3995 : : {
3996 : 103 : auto_vec<const char*> candidates;
3997 : 103 : size_t olen = strlen (OFFLOAD_TARGETS) + 1;
3998 : 103 : char *cand = XALLOCAVEC (char, olen);
3999 : 103 : memcpy (cand, OFFLOAD_TARGETS, olen);
4000 : 103 : for (c = strtok (cand, ","); c; c = strtok (NULL, ","))
4001 : 0 : candidates.safe_push (c);
4002 : 103 : candidates.safe_push ("default");
4003 : 103 : candidates.safe_push ("disable");
4004 : :
4005 : 103 : char *target2 = XALLOCAVEC (char, len + 1);
4006 : 103 : memcpy (target2, target, len);
4007 : 103 : target2[len] = '\0';
4008 : :
4009 : 103 : error ("GCC is not configured to support %qs as %<-foffload=%> argument",
4010 : : target2);
4011 : :
4012 : 103 : char *s;
4013 : 103 : const char *hint = candidates_list_and_hint (target2, s, candidates);
4014 : 103 : if (hint)
4015 : 0 : inform (UNKNOWN_LOCATION,
4016 : : "valid %<-foffload=%> arguments are: %s; "
4017 : : "did you mean %qs?", s, hint);
4018 : : else
4019 : 103 : inform (UNKNOWN_LOCATION, "valid %<-foffload=%> arguments are: %s", s);
4020 : 103 : XDELETEVEC (s);
4021 : 103 : return false;
4022 : 103 : }
4023 : : return true;
4024 : : }
4025 : :
4026 : : /* Sanity check for -foffload-options. */
4027 : :
4028 : : static void
4029 : 27 : check_foffload_target_names (const char *arg)
4030 : : {
4031 : 27 : const char *cur, *next, *end;
4032 : : /* If option argument starts with '-' then no target is specified and we
4033 : : do not need to parse it. */
4034 : 27 : if (arg[0] == '-')
4035 : : return;
4036 : 0 : end = strchr (arg, '=');
4037 : 0 : if (end == NULL)
4038 : : {
4039 : 0 : error ("%<=%>options missing after %<-foffload-options=%>target");
4040 : 0 : return;
4041 : : }
4042 : :
4043 : : cur = arg;
4044 : 0 : while (cur < end)
4045 : : {
4046 : 0 : next = strchr (cur, ',');
4047 : 0 : if (next == NULL)
4048 : 0 : next = end;
4049 : 0 : next = (next > end) ? end : next;
4050 : :
4051 : : /* Retain non-supported targets after printing an error as those will not
4052 : : be processed; each enabled target only processes its triplet. */
4053 : 0 : check_offload_target_name (cur, next - cur);
4054 : 0 : cur = next + 1;
4055 : : }
4056 : : }
4057 : :
4058 : : /* Parse -foffload option argument. */
4059 : :
4060 : : static void
4061 : 2811 : handle_foffload_option (const char *arg)
4062 : : {
4063 : 2811 : const char *c, *cur, *n, *next, *end;
4064 : 2811 : char *target;
4065 : :
4066 : : /* If option argument starts with '-' then no target is specified and we
4067 : : do not need to parse it. */
4068 : 2811 : if (arg[0] == '-')
4069 : : return;
4070 : :
4071 : 1972 : end = strchr (arg, '=');
4072 : 1972 : if (end == NULL)
4073 : 1972 : end = strchr (arg, '\0');
4074 : 1972 : cur = arg;
4075 : :
4076 : 1972 : while (cur < end)
4077 : : {
4078 : 1972 : next = strchr (cur, ',');
4079 : 1972 : if (next == NULL)
4080 : 1972 : next = end;
4081 : 1972 : next = (next > end) ? end : next;
4082 : :
4083 : 1972 : target = XNEWVEC (char, next - cur + 1);
4084 : 1972 : memcpy (target, cur, next - cur);
4085 : 1972 : target[next - cur] = '\0';
4086 : :
4087 : : /* Reset offloading list and continue. */
4088 : 1972 : if (strcmp (target, "default") == 0)
4089 : : {
4090 : 0 : free (offload_targets);
4091 : 0 : offload_targets = NULL;
4092 : 0 : goto next_item;
4093 : : }
4094 : :
4095 : : /* If 'disable' is passed to the option, clean the list of
4096 : : offload targets and return, even if more targets follow.
4097 : : Likewise if GCC is not configured to support that offload target. */
4098 : 1972 : if (strcmp (target, "disable") == 0
4099 : 1972 : || !check_offload_target_name (target, next - cur))
4100 : : {
4101 : 1972 : free (offload_targets);
4102 : 1972 : offload_targets = xstrdup ("");
4103 : 1972 : return;
4104 : : }
4105 : :
4106 : 0 : if (!offload_targets)
4107 : : {
4108 : 0 : offload_targets = target;
4109 : 0 : target = NULL;
4110 : : }
4111 : : else
4112 : : {
4113 : : /* Check that the target hasn't already presented in the list. */
4114 : : c = offload_targets;
4115 : 0 : do
4116 : : {
4117 : 0 : n = strchr (c, ':');
4118 : 0 : if (n == NULL)
4119 : 0 : n = strchr (c, '\0');
4120 : :
4121 : 0 : if (next - cur == n - c && strncmp (c, target, n - c) == 0)
4122 : : break;
4123 : :
4124 : 0 : c = n + 1;
4125 : : }
4126 : 0 : while (*n);
4127 : :
4128 : : /* If duplicate is not found, append the target to the list. */
4129 : 0 : if (c > n)
4130 : : {
4131 : 0 : size_t offload_targets_len = strlen (offload_targets);
4132 : 0 : offload_targets
4133 : 0 : = XRESIZEVEC (char, offload_targets,
4134 : : offload_targets_len + 1 + next - cur + 1);
4135 : 0 : offload_targets[offload_targets_len++] = ':';
4136 : 0 : memcpy (offload_targets + offload_targets_len, target, next - cur + 1);
4137 : : }
4138 : : }
4139 : 0 : next_item:
4140 : 0 : cur = next + 1;
4141 : 0 : XDELETEVEC (target);
4142 : : }
4143 : : }
4144 : :
4145 : : /* Forward certain options to offloading compilation. */
4146 : :
4147 : : static void
4148 : 0 : forward_offload_option (size_t opt_index, const char *arg, bool validated)
4149 : : {
4150 : 0 : switch (opt_index)
4151 : : {
4152 : 0 : case OPT_l:
4153 : : /* Use a '_GCC_' prefix and standard name ('-l_GCC_m' irrespective of the
4154 : : host's 'MATH_LIBRARY', for example), so that the 'mkoffload's can tell
4155 : : this has been synthesized here, and translate/drop as necessary. */
4156 : : /* Note that certain libraries ('-lc', '-lgcc', '-lgomp', for example)
4157 : : are injected by default in offloading compilation, and therefore not
4158 : : forwarded here. */
4159 : : /* GCC libraries. */
4160 : 0 : if (/* '-lgfortran' */ strcmp (arg, "gfortran") == 0
4161 : 0 : || /* '-lstdc++' */ strcmp (arg, "stdc++") == 0)
4162 : 0 : save_switch (concat ("-foffload-options=-l_GCC_", arg, NULL),
4163 : : 0, NULL, validated, true);
4164 : : /* Other libraries. */
4165 : : else
4166 : : {
4167 : : /* The case will need special consideration where on the host
4168 : : '!need_math', but for offloading compilation still need
4169 : : '-foffload-options=-l_GCC_m'. The problem is that we don't get
4170 : : here anything like '-lm', because it's not synthesized in
4171 : : 'gcc/fortran/gfortranspec.cc:lang_specific_driver', for example.
4172 : : Generally synthesizing '-foffload-options=-l_GCC_m' etc. in the
4173 : : language specific drivers is non-trivial, needs very careful
4174 : : review of their options handling. However, this issue is not
4175 : : actually relevant for the current set of supported host/offloading
4176 : : configurations. */
4177 : 0 : int need_math = (MATH_LIBRARY[0] != '\0');
4178 : 0 : if (/* '-lm' */ (need_math && strcmp (arg, MATH_LIBRARY) == 0))
4179 : 0 : save_switch ("-foffload-options=-l_GCC_m",
4180 : : 0, NULL, validated, true);
4181 : : }
4182 : 0 : break;
4183 : 0 : default:
4184 : 0 : gcc_unreachable ();
4185 : : }
4186 : 0 : }
4187 : :
4188 : : /* Handle a driver option; arguments and return value as for
4189 : : handle_option. */
4190 : :
4191 : : static bool
4192 : 2627150 : driver_handle_option (struct gcc_options *opts,
4193 : : struct gcc_options *opts_set,
4194 : : const struct cl_decoded_option *decoded,
4195 : : unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
4196 : : location_t loc,
4197 : : const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED,
4198 : : diagnostic_context *dc,
4199 : : void (*) (void))
4200 : : {
4201 : 2627150 : size_t opt_index = decoded->opt_index;
4202 : 2627150 : const char *arg = decoded->arg;
4203 : 2627150 : const char *compare_debug_replacement_opt;
4204 : 2627150 : int value = decoded->value;
4205 : 2627150 : bool validated = false;
4206 : 2627150 : bool do_save = true;
4207 : :
4208 : 2627150 : gcc_assert (opts == &global_options);
4209 : 2627150 : gcc_assert (opts_set == &global_options_set);
4210 : 2627150 : gcc_assert (kind == DK_UNSPECIFIED);
4211 : 2627150 : gcc_assert (loc == UNKNOWN_LOCATION);
4212 : 2627150 : gcc_assert (dc == global_dc);
4213 : :
4214 : 2627150 : switch (opt_index)
4215 : : {
4216 : 1 : case OPT_dumpspecs:
4217 : 1 : {
4218 : 1 : struct spec_list *sl;
4219 : 1 : init_spec ();
4220 : 47 : for (sl = specs; sl; sl = sl->next)
4221 : 46 : printf ("*%s:\n%s\n\n", sl->name, *(sl->ptr_spec));
4222 : 1 : if (link_command_spec)
4223 : 1 : printf ("*link_command:\n%s\n\n", link_command_spec);
4224 : 1 : exit (0);
4225 : : }
4226 : :
4227 : 280 : case OPT_dumpversion:
4228 : 280 : printf ("%s\n", spec_version);
4229 : 280 : exit (0);
4230 : :
4231 : 0 : case OPT_dumpmachine:
4232 : 0 : printf ("%s\n", spec_machine);
4233 : 0 : exit (0);
4234 : :
4235 : 0 : case OPT_dumpfullversion:
4236 : 0 : printf ("%s\n", BASEVER);
4237 : 0 : exit (0);
4238 : :
4239 : 78 : case OPT__version:
4240 : 78 : print_version = 1;
4241 : :
4242 : : /* CPP driver cannot obtain switch from cc1_options. */
4243 : 78 : if (is_cpp_driver)
4244 : 0 : add_preprocessor_option ("--version", strlen ("--version"));
4245 : 78 : add_assembler_option ("--version", strlen ("--version"));
4246 : 78 : add_linker_option ("--version", strlen ("--version"));
4247 : 78 : break;
4248 : :
4249 : 5 : case OPT__completion_:
4250 : 5 : validated = true;
4251 : 5 : completion = decoded->arg;
4252 : 5 : break;
4253 : :
4254 : 4 : case OPT__help:
4255 : 4 : print_help_list = 1;
4256 : :
4257 : : /* CPP driver cannot obtain switch from cc1_options. */
4258 : 4 : if (is_cpp_driver)
4259 : 0 : add_preprocessor_option ("--help", 6);
4260 : 4 : add_assembler_option ("--help", 6);
4261 : 4 : add_linker_option ("--help", 6);
4262 : 4 : break;
4263 : :
4264 : 64 : case OPT__help_:
4265 : 64 : print_subprocess_help = 2;
4266 : 64 : break;
4267 : :
4268 : 0 : case OPT__target_help:
4269 : 0 : print_subprocess_help = 1;
4270 : :
4271 : : /* CPP driver cannot obtain switch from cc1_options. */
4272 : 0 : if (is_cpp_driver)
4273 : 0 : add_preprocessor_option ("--target-help", 13);
4274 : 0 : add_assembler_option ("--target-help", 13);
4275 : 0 : add_linker_option ("--target-help", 13);
4276 : 0 : break;
4277 : :
4278 : : case OPT__no_sysroot_suffix:
4279 : : case OPT_pass_exit_codes:
4280 : : case OPT_print_search_dirs:
4281 : : case OPT_print_file_name_:
4282 : : case OPT_print_prog_name_:
4283 : : case OPT_print_multi_lib:
4284 : : case OPT_print_multi_directory:
4285 : : case OPT_print_sysroot:
4286 : : case OPT_print_multi_os_directory:
4287 : : case OPT_print_multiarch:
4288 : : case OPT_print_sysroot_headers_suffix:
4289 : : case OPT_time:
4290 : : case OPT_wrapper:
4291 : : /* These options set the variables specified in common.opt
4292 : : automatically, and do not need to be saved for spec
4293 : : processing. */
4294 : : do_save = false;
4295 : : break;
4296 : :
4297 : 392 : case OPT_print_libgcc_file_name:
4298 : 392 : print_file_name = "libgcc.a";
4299 : 392 : do_save = false;
4300 : 392 : break;
4301 : :
4302 : 0 : case OPT_fuse_ld_bfd:
4303 : 0 : use_ld = ".bfd";
4304 : 0 : break;
4305 : :
4306 : 0 : case OPT_fuse_ld_gold:
4307 : 0 : use_ld = ".gold";
4308 : 0 : break;
4309 : :
4310 : 0 : case OPT_fuse_ld_mold:
4311 : 0 : use_ld = ".mold";
4312 : 0 : break;
4313 : :
4314 : 0 : case OPT_fcompare_debug_second:
4315 : 0 : compare_debug_second = 1;
4316 : 0 : break;
4317 : :
4318 : 616 : case OPT_fcompare_debug:
4319 : 616 : switch (value)
4320 : : {
4321 : 0 : case 0:
4322 : 0 : compare_debug_replacement_opt = "-fcompare-debug=";
4323 : 0 : arg = "";
4324 : 0 : goto compare_debug_with_arg;
4325 : :
4326 : 616 : case 1:
4327 : 616 : compare_debug_replacement_opt = "-fcompare-debug=-gtoggle";
4328 : 616 : arg = "-gtoggle";
4329 : 616 : goto compare_debug_with_arg;
4330 : :
4331 : 0 : default:
4332 : 0 : gcc_unreachable ();
4333 : : }
4334 : 6 : break;
4335 : :
4336 : 6 : case OPT_fcompare_debug_:
4337 : 6 : compare_debug_replacement_opt = decoded->canonical_option[0];
4338 : 622 : compare_debug_with_arg:
4339 : 622 : gcc_assert (decoded->canonical_option_num_elements == 1);
4340 : 622 : gcc_assert (arg != NULL);
4341 : 622 : if (*arg)
4342 : 622 : compare_debug = 1;
4343 : : else
4344 : 0 : compare_debug = -1;
4345 : 622 : if (compare_debug < 0)
4346 : 0 : compare_debug_opt = NULL;
4347 : : else
4348 : 622 : compare_debug_opt = arg;
4349 : 622 : save_switch (compare_debug_replacement_opt, 0, NULL, validated, true);
4350 : 622 : set_source_date_epoch_envvar ();
4351 : 622 : return true;
4352 : :
4353 : 259195 : case OPT_fdiagnostics_color_:
4354 : 259195 : diagnostic_color_init (dc, value);
4355 : 259195 : break;
4356 : :
4357 : 253666 : case OPT_fdiagnostics_urls_:
4358 : 253666 : diagnostic_urls_init (dc, value);
4359 : 253666 : break;
4360 : :
4361 : 0 : case OPT_fdiagnostics_show_highlight_colors:
4362 : 0 : dc->set_show_highlight_colors (value);
4363 : 0 : break;
4364 : :
4365 : 0 : case OPT_fdiagnostics_format_:
4366 : 0 : {
4367 : 0 : const char *basename = (opts->x_dump_base_name ? opts->x_dump_base_name
4368 : : : opts->x_main_input_basename);
4369 : 0 : gcc_assert (dc);
4370 : 0 : diagnostic_output_format_init (*dc,
4371 : : opts->x_main_input_filename, basename,
4372 : : (enum diagnostics_output_format)value,
4373 : 0 : opts->x_flag_diagnostics_json_formatting);
4374 : 0 : break;
4375 : : }
4376 : :
4377 : 0 : case OPT_fdiagnostics_add_output_:
4378 : 0 : handle_OPT_fdiagnostics_add_output_ (*opts, *dc, arg, loc);
4379 : 0 : break;
4380 : :
4381 : 0 : case OPT_fdiagnostics_set_output_:
4382 : 0 : handle_OPT_fdiagnostics_set_output_ (*opts, *dc, arg, loc);
4383 : 0 : break;
4384 : :
4385 : 281722 : case OPT_fdiagnostics_text_art_charset_:
4386 : 281722 : dc->set_text_art_charset ((enum diagnostic_text_art_charset)value);
4387 : 281722 : break;
4388 : :
4389 : : case OPT_Wa_:
4390 : : {
4391 : : int prev, j;
4392 : : /* Pass the rest of this option to the assembler. */
4393 : :
4394 : : /* Split the argument at commas. */
4395 : : prev = 0;
4396 : 466 : for (j = 0; arg[j]; j++)
4397 : 430 : if (arg[j] == ',')
4398 : : {
4399 : 0 : add_assembler_option (arg + prev, j - prev);
4400 : 0 : prev = j + 1;
4401 : : }
4402 : :
4403 : : /* Record the part after the last comma. */
4404 : 36 : add_assembler_option (arg + prev, j - prev);
4405 : : }
4406 : 36 : do_save = false;
4407 : 36 : break;
4408 : :
4409 : : case OPT_Wp_:
4410 : : {
4411 : : int prev, j;
4412 : : /* Pass the rest of this option to the preprocessor. */
4413 : :
4414 : : /* Split the argument at commas. */
4415 : : prev = 0;
4416 : 0 : for (j = 0; arg[j]; j++)
4417 : 0 : if (arg[j] == ',')
4418 : : {
4419 : 0 : add_preprocessor_option (arg + prev, j - prev);
4420 : 0 : prev = j + 1;
4421 : : }
4422 : :
4423 : : /* Record the part after the last comma. */
4424 : 0 : add_preprocessor_option (arg + prev, j - prev);
4425 : : }
4426 : 0 : do_save = false;
4427 : 0 : break;
4428 : :
4429 : : case OPT_Wl_:
4430 : : {
4431 : : int prev, j;
4432 : : /* Split the argument at commas. */
4433 : : prev = 0;
4434 : 127038 : for (j = 0; arg[j]; j++)
4435 : 119412 : if (arg[j] == ',')
4436 : : {
4437 : 42 : add_infile (save_string (arg + prev, j - prev), "*");
4438 : 42 : prev = j + 1;
4439 : : }
4440 : : /* Record the part after the last comma. */
4441 : 7626 : add_infile (arg + prev, "*");
4442 : 7626 : if (strcmp (arg, "-z,lazy") == 0 || strcmp (arg, "-z,norelro") == 0)
4443 : 12 : avoid_linker_hardening_p = true;
4444 : : }
4445 : : do_save = false;
4446 : : break;
4447 : :
4448 : 12 : case OPT_z:
4449 : 12 : if (strcmp (arg, "lazy") == 0 || strcmp (arg, "norelro") == 0)
4450 : 12 : avoid_linker_hardening_p = true;
4451 : : break;
4452 : :
4453 : 0 : case OPT_Xlinker:
4454 : 0 : add_infile (arg, "*");
4455 : 0 : do_save = false;
4456 : 0 : break;
4457 : :
4458 : 0 : case OPT_Xpreprocessor:
4459 : 0 : add_preprocessor_option (arg, strlen (arg));
4460 : 0 : do_save = false;
4461 : 0 : break;
4462 : :
4463 : 65 : case OPT_Xassembler:
4464 : 65 : add_assembler_option (arg, strlen (arg));
4465 : 65 : do_save = false;
4466 : 65 : break;
4467 : :
4468 : 247606 : case OPT_l:
4469 : : /* POSIX allows separation of -l and the lib arg; canonicalize
4470 : : by concatenating -l with its arg */
4471 : 247606 : add_infile (concat ("-l", arg, NULL), "*");
4472 : :
4473 : : /* Forward to offloading compilation '-l[...]' flags for standard,
4474 : : well-known libraries. */
4475 : : /* Doing this processing here means that we don't get to see libraries
4476 : : injected via specs, such as '-lquadmath' injected via
4477 : : '[build]/[target]/libgfortran/libgfortran.spec'. However, this issue
4478 : : is not actually relevant for the current set of host/offloading
4479 : : configurations. */
4480 : 247606 : if (ENABLE_OFFLOADING)
4481 : : forward_offload_option (opt_index, arg, validated);
4482 : :
4483 : 247606 : do_save = false;
4484 : 247606 : break;
4485 : :
4486 : 259026 : case OPT_L:
4487 : : /* Similarly, canonicalize -L for linkers that may not accept
4488 : : separate arguments. */
4489 : 259026 : save_switch (concat ("-L", arg, NULL), 0, NULL, validated, true);
4490 : 259026 : return true;
4491 : :
4492 : 0 : case OPT_F:
4493 : : /* Likewise -F. */
4494 : 0 : save_switch (concat ("-F", arg, NULL), 0, NULL, validated, true);
4495 : 0 : return true;
4496 : :
4497 : 403 : case OPT_save_temps:
4498 : 403 : if (!save_temps_flag)
4499 : 397 : save_temps_flag = SAVE_TEMPS_DUMP;
4500 : : validated = true;
4501 : : break;
4502 : :
4503 : 58 : case OPT_save_temps_:
4504 : 58 : if (strcmp (arg, "cwd") == 0)
4505 : 29 : save_temps_flag = SAVE_TEMPS_CWD;
4506 : 29 : else if (strcmp (arg, "obj") == 0
4507 : 0 : || strcmp (arg, "object") == 0)
4508 : 29 : save_temps_flag = SAVE_TEMPS_OBJ;
4509 : : else
4510 : 0 : fatal_error (input_location, "%qs is an unknown %<-save-temps%> option",
4511 : 0 : decoded->orig_option_with_args_text);
4512 : 58 : save_temps_overrides_dumpdir = true;
4513 : 58 : break;
4514 : :
4515 : 19764 : case OPT_dumpdir:
4516 : 19764 : free (dumpdir);
4517 : 19764 : dumpdir = xstrdup (arg);
4518 : 19764 : save_temps_overrides_dumpdir = false;
4519 : 19764 : break;
4520 : :
4521 : 21187 : case OPT_dumpbase:
4522 : 21187 : free (dumpbase);
4523 : 21187 : dumpbase = xstrdup (arg);
4524 : 21187 : break;
4525 : :
4526 : 250 : case OPT_dumpbase_ext:
4527 : 250 : free (dumpbase_ext);
4528 : 250 : dumpbase_ext = xstrdup (arg);
4529 : 250 : break;
4530 : :
4531 : : case OPT_no_canonical_prefixes:
4532 : : /* Already handled as a special case, so ignored here. */
4533 : : do_save = false;
4534 : : break;
4535 : :
4536 : : case OPT_pipe:
4537 : : validated = true;
4538 : : /* These options set the variables specified in common.opt
4539 : : automatically, but do need to be saved for spec
4540 : : processing. */
4541 : : break;
4542 : :
4543 : 3 : case OPT_specs_:
4544 : 3 : {
4545 : 3 : struct user_specs *user = XNEW (struct user_specs);
4546 : :
4547 : 3 : user->next = (struct user_specs *) 0;
4548 : 3 : user->filename = arg;
4549 : 3 : if (user_specs_tail)
4550 : 0 : user_specs_tail->next = user;
4551 : : else
4552 : 3 : user_specs_head = user;
4553 : 3 : user_specs_tail = user;
4554 : : }
4555 : 3 : validated = true;
4556 : 3 : break;
4557 : :
4558 : 0 : case OPT__sysroot_:
4559 : 0 : target_system_root = arg;
4560 : 0 : target_system_root_changed = 1;
4561 : : /* Saving this option is useful to let self-specs decide to
4562 : : provide a default one. */
4563 : 0 : do_save = true;
4564 : 0 : validated = true;
4565 : 0 : break;
4566 : :
4567 : 0 : case OPT_time_:
4568 : 0 : if (report_times_to_file)
4569 : 0 : fclose (report_times_to_file);
4570 : 0 : report_times_to_file = fopen (arg, "a");
4571 : 0 : do_save = false;
4572 : 0 : break;
4573 : :
4574 : 7775 : case OPT_truncate:
4575 : 7775 : totruncate_file = arg;
4576 : 7775 : do_save = false;
4577 : 7775 : break;
4578 : :
4579 : 637 : case OPT____:
4580 : : /* "-###"
4581 : : This is similar to -v except that there is no execution
4582 : : of the commands and the echoed arguments are quoted. It
4583 : : is intended for use in shell scripts to capture the
4584 : : driver-generated command line. */
4585 : 637 : verbose_only_flag++;
4586 : 637 : verbose_flag = 1;
4587 : 637 : do_save = false;
4588 : 637 : break;
4589 : :
4590 : 474222 : case OPT_B:
4591 : 474222 : {
4592 : 474222 : size_t len = strlen (arg);
4593 : :
4594 : : /* Catch the case where the user has forgotten to append a
4595 : : directory separator to the path. Note, they may be using
4596 : : -B to add an executable name prefix, eg "i386-elf-", in
4597 : : order to distinguish between multiple installations of
4598 : : GCC in the same directory. Hence we must check to see
4599 : : if appending a directory separator actually makes a
4600 : : valid directory name. */
4601 : 474222 : if (!IS_DIR_SEPARATOR (arg[len - 1])
4602 : 474222 : && is_directory (arg))
4603 : : {
4604 : 93818 : char *tmp = XNEWVEC (char, len + 2);
4605 : 93818 : strcpy (tmp, arg);
4606 : 93818 : tmp[len] = DIR_SEPARATOR;
4607 : 93818 : tmp[++len] = 0;
4608 : 93818 : arg = tmp;
4609 : : }
4610 : :
4611 : 474222 : add_prefix (&exec_prefixes, arg, NULL,
4612 : : PREFIX_PRIORITY_B_OPT, 0, 0);
4613 : 474222 : add_prefix (&startfile_prefixes, arg, NULL,
4614 : : PREFIX_PRIORITY_B_OPT, 0, 0);
4615 : 474222 : add_prefix (&include_prefixes, arg, NULL,
4616 : : PREFIX_PRIORITY_B_OPT, 0, 0);
4617 : : }
4618 : 474222 : validated = true;
4619 : 474222 : break;
4620 : :
4621 : 2302 : case OPT_E:
4622 : 2302 : have_E = true;
4623 : 2302 : break;
4624 : :
4625 : 47201 : case OPT_x:
4626 : 47201 : spec_lang = arg;
4627 : 47201 : if (!strcmp (spec_lang, "none"))
4628 : : /* Suppress the warning if -xnone comes after the last input
4629 : : file, because alternate command interfaces like g++ might
4630 : : find it useful to place -xnone after each input file. */
4631 : 12976 : spec_lang = 0;
4632 : : else
4633 : 34225 : last_language_n_infiles = n_infiles;
4634 : : do_save = false;
4635 : : break;
4636 : :
4637 : 262315 : case OPT_o:
4638 : 262315 : have_o = 1;
4639 : : #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) || defined(HAVE_TARGET_OBJECT_SUFFIX)
4640 : : arg = convert_filename (arg, ! have_c, 0);
4641 : : #endif
4642 : 262315 : output_file = arg;
4643 : : /* On some systems, ld cannot handle "-o" without a space. So
4644 : : split the option from its argument. */
4645 : 262315 : save_switch ("-o", 1, &arg, validated, true);
4646 : 262315 : return true;
4647 : :
4648 : 2052 : case OPT_pie:
4649 : : #ifdef ENABLE_DEFAULT_PIE
4650 : : /* -pie is turned on by default. */
4651 : : validated = true;
4652 : : #endif
4653 : : /* FALLTHROUGH */
4654 : 2052 : case OPT_r:
4655 : 2052 : case OPT_shared:
4656 : 2052 : case OPT_no_pie:
4657 : 2052 : avoid_linker_hardening_p = true;
4658 : 2052 : break;
4659 : :
4660 : 102 : case OPT_static:
4661 : 102 : static_p = true;
4662 : 102 : break;
4663 : :
4664 : : case OPT_static_libgcc:
4665 : : case OPT_shared_libgcc:
4666 : : case OPT_static_libgfortran:
4667 : : case OPT_static_libquadmath:
4668 : : case OPT_static_libphobos:
4669 : : case OPT_static_libgm2:
4670 : : case OPT_static_libstdc__:
4671 : : /* These are always valid; gcc.cc itself understands the first two
4672 : : gfortranspec.cc understands -static-libgfortran,
4673 : : libgfortran.spec handles -static-libquadmath,
4674 : : d-spec.cc understands -static-libphobos,
4675 : : gm2spec.cc understands -static-libgm2,
4676 : : and g++spec.cc understands -static-libstdc++. */
4677 : : validated = true;
4678 : : break;
4679 : :
4680 : 78 : case OPT_fwpa:
4681 : 78 : flag_wpa = "";
4682 : 78 : break;
4683 : :
4684 : 27 : case OPT_foffload_options_:
4685 : 27 : check_foffload_target_names (arg);
4686 : 27 : break;
4687 : :
4688 : 2811 : case OPT_foffload_:
4689 : 2811 : handle_foffload_option (arg);
4690 : 2811 : if (arg[0] == '-' || NULL != strchr (arg, '='))
4691 : 839 : save_switch (concat ("-foffload-options=", arg, NULL),
4692 : : 0, NULL, validated, true);
4693 : : do_save = false;
4694 : : break;
4695 : :
4696 : 0 : case OPT_gcodeview:
4697 : 0 : add_infile ("--pdb=", "*");
4698 : 0 : break;
4699 : :
4700 : : default:
4701 : : /* Various driver options need no special processing at this
4702 : : point, having been handled in a prescan above or being
4703 : : handled by specs. */
4704 : : break;
4705 : : }
4706 : :
4707 : 1571302 : if (do_save)
4708 : 1777984 : save_switch (decoded->canonical_option[0],
4709 : 1777984 : decoded->canonical_option_num_elements - 1,
4710 : : &decoded->canonical_option[1], validated, true);
4711 : : return true;
4712 : : }
4713 : :
4714 : : /* Return true if F2 is F1 followed by a single suffix, i.e., by a
4715 : : period and additional characters other than a period. */
4716 : :
4717 : : static inline bool
4718 : 81948 : adds_single_suffix_p (const char *f2, const char *f1)
4719 : : {
4720 : 81948 : size_t len = strlen (f1);
4721 : :
4722 : 81948 : return (strncmp (f1, f2, len) == 0
4723 : 73913 : && f2[len] == '.'
4724 : 155404 : && strchr (f2 + len + 1, '.') == NULL);
4725 : : }
4726 : :
4727 : : /* Put the driver's standard set of option handlers in *HANDLERS. */
4728 : :
4729 : : static void
4730 : 834836 : set_option_handlers (struct cl_option_handlers *handlers)
4731 : : {
4732 : 834836 : handlers->unknown_option_callback = driver_unknown_option_callback;
4733 : 834836 : handlers->wrong_lang_callback = driver_wrong_lang_callback;
4734 : 834836 : handlers->num_handlers = 3;
4735 : 834836 : handlers->handlers[0].handler = driver_handle_option;
4736 : 834836 : handlers->handlers[0].mask = CL_DRIVER;
4737 : 834836 : handlers->handlers[1].handler = common_handle_option;
4738 : 834836 : handlers->handlers[1].mask = CL_COMMON;
4739 : 834836 : handlers->handlers[2].handler = target_handle_option;
4740 : 834836 : handlers->handlers[2].mask = CL_TARGET;
4741 : 0 : }
4742 : :
4743 : :
4744 : : /* Return the index into infiles for the single non-library
4745 : : non-lto-wpa input file, -1 if there isn't any, or -2 if there is
4746 : : more than one. */
4747 : : static inline int
4748 : 144333 : single_input_file_index ()
4749 : : {
4750 : 144333 : int ret = -1;
4751 : :
4752 : 471916 : for (int i = 0; i < n_infiles; i++)
4753 : : {
4754 : 339780 : if (infiles[i].language
4755 : 237093 : && (infiles[i].language[0] == '*'
4756 : 43985 : || (flag_wpa
4757 : 16400 : && strcmp (infiles[i].language, "lto") == 0)))
4758 : 209508 : continue;
4759 : :
4760 : 130272 : if (ret != -1)
4761 : : return -2;
4762 : :
4763 : : ret = i;
4764 : : }
4765 : :
4766 : : return ret;
4767 : : }
4768 : :
4769 : : /* Create the vector `switches' and its contents.
4770 : : Store its length in `n_switches'. */
4771 : :
4772 : : static void
4773 : 287780 : process_command (unsigned int decoded_options_count,
4774 : : struct cl_decoded_option *decoded_options)
4775 : : {
4776 : 287780 : const char *temp;
4777 : 287780 : char *temp1;
4778 : 287780 : char *tooldir_prefix, *tooldir_prefix2;
4779 : 287780 : char *(*get_relative_prefix) (const char *, const char *,
4780 : : const char *) = NULL;
4781 : 287780 : struct cl_option_handlers handlers;
4782 : 287780 : unsigned int j;
4783 : :
4784 : 287780 : gcc_exec_prefix = env.get ("GCC_EXEC_PREFIX");
4785 : :
4786 : 287780 : n_switches = 0;
4787 : 287780 : n_infiles = 0;
4788 : 287780 : added_libraries = 0;
4789 : :
4790 : : /* Figure compiler version from version string. */
4791 : :
4792 : 287780 : compiler_version = temp1 = xstrdup (version_string);
4793 : :
4794 : 2014460 : for (; *temp1; ++temp1)
4795 : : {
4796 : 2014460 : if (*temp1 == ' ')
4797 : : {
4798 : 287780 : *temp1 = '\0';
4799 : 287780 : break;
4800 : : }
4801 : : }
4802 : :
4803 : : /* Handle any -no-canonical-prefixes flag early, to assign the function
4804 : : that builds relative prefixes. This function creates default search
4805 : : paths that are needed later in normal option handling. */
4806 : :
4807 : 6237498 : for (j = 1; j < decoded_options_count; j++)
4808 : : {
4809 : 5949718 : if (decoded_options[j].opt_index == OPT_no_canonical_prefixes)
4810 : : {
4811 : : get_relative_prefix = make_relative_prefix_ignore_links;
4812 : : break;
4813 : : }
4814 : : }
4815 : 287780 : if (! get_relative_prefix)
4816 : 287780 : get_relative_prefix = make_relative_prefix;
4817 : :
4818 : : /* Set up the default search paths. If there is no GCC_EXEC_PREFIX,
4819 : : see if we can create it from the pathname specified in
4820 : : decoded_options[0].arg. */
4821 : :
4822 : 287780 : gcc_libexec_prefix = standard_libexec_prefix;
4823 : : #ifndef VMS
4824 : : /* FIXME: make_relative_prefix doesn't yet work for VMS. */
4825 : 287780 : if (!gcc_exec_prefix)
4826 : : {
4827 : 28414 : gcc_exec_prefix = get_relative_prefix (decoded_options[0].arg,
4828 : : standard_bindir_prefix,
4829 : : standard_exec_prefix);
4830 : 28414 : gcc_libexec_prefix = get_relative_prefix (decoded_options[0].arg,
4831 : : standard_bindir_prefix,
4832 : : standard_libexec_prefix);
4833 : 28414 : if (gcc_exec_prefix)
4834 : 28414 : xputenv (concat ("GCC_EXEC_PREFIX=", gcc_exec_prefix, NULL));
4835 : : }
4836 : : else
4837 : : {
4838 : : /* make_relative_prefix requires a program name, but
4839 : : GCC_EXEC_PREFIX is typically a directory name with a trailing
4840 : : / (which is ignored by make_relative_prefix), so append a
4841 : : program name. */
4842 : 259366 : char *tmp_prefix = concat (gcc_exec_prefix, "gcc", NULL);
4843 : 259366 : gcc_libexec_prefix = get_relative_prefix (tmp_prefix,
4844 : : standard_exec_prefix,
4845 : : standard_libexec_prefix);
4846 : :
4847 : : /* The path is unrelocated, so fallback to the original setting. */
4848 : 259366 : if (!gcc_libexec_prefix)
4849 : 259021 : gcc_libexec_prefix = standard_libexec_prefix;
4850 : :
4851 : 259366 : free (tmp_prefix);
4852 : : }
4853 : : #else
4854 : : #endif
4855 : : /* From this point onward, gcc_exec_prefix is non-null if the toolchain
4856 : : is relocated. The toolchain was either relocated using GCC_EXEC_PREFIX
4857 : : or an automatically created GCC_EXEC_PREFIX from
4858 : : decoded_options[0].arg. */
4859 : :
4860 : : /* Do language-specific adjustment/addition of flags. */
4861 : 287780 : lang_specific_driver (&decoded_options, &decoded_options_count,
4862 : : &added_libraries);
4863 : :
4864 : 287776 : if (gcc_exec_prefix)
4865 : : {
4866 : 287776 : int len = strlen (gcc_exec_prefix);
4867 : :
4868 : 287776 : if (len > (int) sizeof ("/lib/gcc/") - 1
4869 : 287776 : && (IS_DIR_SEPARATOR (gcc_exec_prefix[len-1])))
4870 : : {
4871 : 287776 : temp = gcc_exec_prefix + len - sizeof ("/lib/gcc/") + 1;
4872 : 287776 : if (IS_DIR_SEPARATOR (*temp)
4873 : 287776 : && filename_ncmp (temp + 1, "lib", 3) == 0
4874 : 287776 : && IS_DIR_SEPARATOR (temp[4])
4875 : 575552 : && filename_ncmp (temp + 5, "gcc", 3) == 0)
4876 : 287776 : len -= sizeof ("/lib/gcc/") - 1;
4877 : : }
4878 : :
4879 : 287776 : set_std_prefix (gcc_exec_prefix, len);
4880 : 287776 : add_prefix (&exec_prefixes, gcc_libexec_prefix, "GCC",
4881 : : PREFIX_PRIORITY_LAST, 0, 0);
4882 : 287776 : add_prefix (&startfile_prefixes, gcc_exec_prefix, "GCC",
4883 : : PREFIX_PRIORITY_LAST, 0, 0);
4884 : : }
4885 : :
4886 : : /* COMPILER_PATH and LIBRARY_PATH have values
4887 : : that are lists of directory names with colons. */
4888 : :
4889 : 287776 : temp = env.get ("COMPILER_PATH");
4890 : 287776 : if (temp)
4891 : : {
4892 : 19600 : const char *startp, *endp;
4893 : 19600 : char *nstore = (char *) alloca (strlen (temp) + 3);
4894 : :
4895 : 19600 : startp = endp = temp;
4896 : 1824885 : while (1)
4897 : : {
4898 : 1824885 : if (*endp == PATH_SEPARATOR || *endp == 0)
4899 : : {
4900 : 32266 : strncpy (nstore, startp, endp - startp);
4901 : 32266 : if (endp == startp)
4902 : 0 : strcpy (nstore, concat (".", dir_separator_str, NULL));
4903 : 32266 : else if (!IS_DIR_SEPARATOR (endp[-1]))
4904 : : {
4905 : 0 : nstore[endp - startp] = DIR_SEPARATOR;
4906 : 0 : nstore[endp - startp + 1] = 0;
4907 : : }
4908 : : else
4909 : 32266 : nstore[endp - startp] = 0;
4910 : 32266 : add_prefix (&exec_prefixes, nstore, 0,
4911 : : PREFIX_PRIORITY_LAST, 0, 0);
4912 : 32266 : add_prefix (&include_prefixes, nstore, 0,
4913 : : PREFIX_PRIORITY_LAST, 0, 0);
4914 : 32266 : if (*endp == 0)
4915 : : break;
4916 : 12666 : endp = startp = endp + 1;
4917 : : }
4918 : : else
4919 : 1792619 : endp++;
4920 : : }
4921 : : }
4922 : :
4923 : 287776 : temp = env.get (LIBRARY_PATH_ENV);
4924 : 287776 : if (temp && *cross_compile == '0')
4925 : : {
4926 : 20913 : const char *startp, *endp;
4927 : 20913 : char *nstore = (char *) alloca (strlen (temp) + 3);
4928 : :
4929 : 20913 : startp = endp = temp;
4930 : 3651679 : while (1)
4931 : : {
4932 : 3651679 : if (*endp == PATH_SEPARATOR || *endp == 0)
4933 : : {
4934 : 150489 : strncpy (nstore, startp, endp - startp);
4935 : 150489 : if (endp == startp)
4936 : 0 : strcpy (nstore, concat (".", dir_separator_str, NULL));
4937 : 150489 : else if (!IS_DIR_SEPARATOR (endp[-1]))
4938 : : {
4939 : 1313 : nstore[endp - startp] = DIR_SEPARATOR;
4940 : 1313 : nstore[endp - startp + 1] = 0;
4941 : : }
4942 : : else
4943 : 149176 : nstore[endp - startp] = 0;
4944 : 150489 : add_prefix (&startfile_prefixes, nstore, NULL,
4945 : : PREFIX_PRIORITY_LAST, 0, 1);
4946 : 150489 : if (*endp == 0)
4947 : : break;
4948 : 129576 : endp = startp = endp + 1;
4949 : : }
4950 : : else
4951 : 3501190 : endp++;
4952 : : }
4953 : : }
4954 : :
4955 : : /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
4956 : 287776 : temp = env.get ("LPATH");
4957 : 287776 : if (temp && *cross_compile == '0')
4958 : : {
4959 : 0 : const char *startp, *endp;
4960 : 0 : char *nstore = (char *) alloca (strlen (temp) + 3);
4961 : :
4962 : 0 : startp = endp = temp;
4963 : 0 : while (1)
4964 : : {
4965 : 0 : if (*endp == PATH_SEPARATOR || *endp == 0)
4966 : : {
4967 : 0 : strncpy (nstore, startp, endp - startp);
4968 : 0 : if (endp == startp)
4969 : 0 : strcpy (nstore, concat (".", dir_separator_str, NULL));
4970 : 0 : else if (!IS_DIR_SEPARATOR (endp[-1]))
4971 : : {
4972 : 0 : nstore[endp - startp] = DIR_SEPARATOR;
4973 : 0 : nstore[endp - startp + 1] = 0;
4974 : : }
4975 : : else
4976 : 0 : nstore[endp - startp] = 0;
4977 : 0 : add_prefix (&startfile_prefixes, nstore, NULL,
4978 : : PREFIX_PRIORITY_LAST, 0, 1);
4979 : 0 : if (*endp == 0)
4980 : : break;
4981 : 0 : endp = startp = endp + 1;
4982 : : }
4983 : : else
4984 : 0 : endp++;
4985 : : }
4986 : : }
4987 : :
4988 : : /* Process the options and store input files and switches in their
4989 : : vectors. */
4990 : :
4991 : 287776 : last_language_n_infiles = -1;
4992 : :
4993 : 287776 : set_option_handlers (&handlers);
4994 : :
4995 : 5370652 : for (j = 1; j < decoded_options_count; j++)
4996 : : {
4997 : 5263700 : switch (decoded_options[j].opt_index)
4998 : : {
4999 : 180824 : case OPT_S:
5000 : 180824 : case OPT_c:
5001 : 180824 : case OPT_E:
5002 : 180824 : have_c = 1;
5003 : 180824 : break;
5004 : : }
5005 : 5263700 : if (have_c)
5006 : : break;
5007 : : }
5008 : :
5009 : 6603238 : for (j = 1; j < decoded_options_count; j++)
5010 : : {
5011 : 6315743 : if (decoded_options[j].opt_index == OPT_SPECIAL_input_file)
5012 : : {
5013 : 310589 : const char *arg = decoded_options[j].arg;
5014 : :
5015 : : #ifdef HAVE_TARGET_OBJECT_SUFFIX
5016 : : arg = convert_filename (arg, 0, access (arg, F_OK));
5017 : : #endif
5018 : 310589 : add_infile (arg, spec_lang);
5019 : :
5020 : 310589 : continue;
5021 : 310589 : }
5022 : :
5023 : 6005154 : read_cmdline_option (&global_options, &global_options_set,
5024 : : decoded_options + j, UNKNOWN_LOCATION,
5025 : : CL_DRIVER, &handlers, global_dc);
5026 : : }
5027 : :
5028 : : /* If the user didn't specify any, default to all configured offload
5029 : : targets. */
5030 : 287495 : if (ENABLE_OFFLOADING && offload_targets == NULL)
5031 : : {
5032 : : handle_foffload_option (OFFLOAD_TARGETS);
5033 : : #if OFFLOAD_DEFAULTED
5034 : : offload_targets_default = true;
5035 : : #endif
5036 : : }
5037 : :
5038 : : /* TODO: check if -static -pie works and maybe use it. */
5039 : 287495 : if (flag_hardened)
5040 : : {
5041 : 91 : if (!avoid_linker_hardening_p && !static_p)
5042 : : {
5043 : : #if defined HAVE_LD_PIE && defined LD_PIE_SPEC
5044 : 67 : save_switch (LD_PIE_SPEC, 0, NULL, /*validated=*/true, /*known=*/false);
5045 : : #endif
5046 : : /* These are passed straight down to collect2 so we have to break
5047 : : it up like this. */
5048 : 67 : if (HAVE_LD_NOW_SUPPORT)
5049 : : {
5050 : 67 : add_infile ("-z", "*");
5051 : 67 : add_infile ("now", "*");
5052 : : }
5053 : 67 : if (HAVE_LD_RELRO_SUPPORT)
5054 : : {
5055 : 67 : add_infile ("-z", "*");
5056 : 67 : add_infile ("relro", "*");
5057 : : }
5058 : : }
5059 : : /* We can't use OPT_Whardened yet. Sigh. */
5060 : : else
5061 : 24 : warning_at (UNKNOWN_LOCATION, 0,
5062 : : "linker hardening options not enabled by %<-fhardened%> "
5063 : : "because other link options were specified on the command "
5064 : : "line");
5065 : : }
5066 : :
5067 : : /* Handle -gtoggle as it would later in toplev.cc:process_options to
5068 : : make the debug-level-gt spec function work as expected. */
5069 : 287495 : if (flag_gtoggle)
5070 : : {
5071 : 4 : if (debug_info_level == DINFO_LEVEL_NONE)
5072 : 0 : debug_info_level = DINFO_LEVEL_NORMAL;
5073 : : else
5074 : 4 : debug_info_level = DINFO_LEVEL_NONE;
5075 : : }
5076 : :
5077 : 287495 : if (output_file
5078 : 262314 : && strcmp (output_file, "-") != 0
5079 : 262151 : && strcmp (output_file, HOST_BIT_BUCKET) != 0)
5080 : : {
5081 : : int i;
5082 : 781194 : for (i = 0; i < n_infiles; i++)
5083 : 252750 : if ((!infiles[i].language || infiles[i].language[0] != '*')
5084 : 546527 : && canonical_filename_eq (infiles[i].name, output_file))
5085 : 1 : fatal_error (input_location,
5086 : : "input file %qs is the same as output file",
5087 : : output_file);
5088 : : }
5089 : :
5090 : 287494 : if (output_file != NULL && output_file[0] == '\0')
5091 : 0 : fatal_error (input_location, "output filename may not be empty");
5092 : :
5093 : : /* -dumpdir and -save-temps=* both specify the location of aux/dump
5094 : : outputs; the one that appears last prevails. When compiling
5095 : : multiple sources, an explicit dumpbase (minus -ext) may be
5096 : : combined with an explicit or implicit dumpdir, whereas when
5097 : : linking, a specified or implied link output name (minus
5098 : : extension) may be combined with a prevailing -save-temps=* or an
5099 : : otherwise implied dumpdir, but not override a prevailing
5100 : : -dumpdir. Primary outputs (e.g., linker output when linking
5101 : : without -o, or .i, .s or .o outputs when processing multiple
5102 : : inputs with -E, -S or -c, respectively) are NOT affected by these
5103 : : -save-temps=/-dump* options, always landing in the current
5104 : : directory and with the same basename as the input when an output
5105 : : name is not given, but when they're intermediate outputs, they
5106 : : are named like other aux outputs, so the options affect their
5107 : : location and name.
5108 : :
5109 : : Here are some examples. There are several more in the
5110 : : documentation of -o and -dump*, and some quite exhaustive tests
5111 : : in gcc.misc-tests/outputs.exp.
5112 : :
5113 : : When compiling any number of sources, no -dump* nor
5114 : : -save-temps=*, all outputs in cwd without prefix:
5115 : :
5116 : : # gcc -c b.c -gsplit-dwarf
5117 : : -> cc1 [-dumpdir ./] -dumpbase b.c -dumpbase-ext .c # b.o b.dwo
5118 : :
5119 : : # gcc -c b.c d.c -gsplit-dwarf
5120 : : -> cc1 [-dumpdir ./] -dumpbase b.c -dumpbase-ext .c # b.o b.dwo
5121 : : && cc1 [-dumpdir ./] -dumpbase d.c -dumpbase-ext .c # d.o d.dwo
5122 : :
5123 : : When compiling and linking, no -dump* nor -save-temps=*, .o
5124 : : outputs are temporary, aux outputs land in the dir of the output,
5125 : : prefixed with the basename of the linker output:
5126 : :
5127 : : # gcc b.c d.c -o ab -gsplit-dwarf
5128 : : -> cc1 -dumpdir ab- -dumpbase b.c -dumpbase-ext .c # ab-b.dwo
5129 : : && cc1 -dumpdir ab- -dumpbase d.c -dumpbase-ext .c # ab-d.dwo
5130 : : && link ... -o ab
5131 : :
5132 : : # gcc b.c d.c [-o a.out] -gsplit-dwarf
5133 : : -> cc1 -dumpdir a- -dumpbase b.c -dumpbase-ext .c # a-b.dwo
5134 : : && cc1 -dumpdir a- -dumpbase d.c -dumpbase-ext .c # a-d.dwo
5135 : : && link ... [-o a.out]
5136 : :
5137 : : When compiling and linking, a prevailing -dumpdir fully overrides
5138 : : the prefix of aux outputs given by the output name:
5139 : :
5140 : : # gcc -dumpdir f b.c d.c -gsplit-dwarf [-o [dir/]whatever]
5141 : : -> cc1 -dumpdir f -dumpbase b.c -dumpbase-ext .c # fb.dwo
5142 : : && cc1 -dumpdir f -dumpbase d.c -dumpbase-ext .c # fd.dwo
5143 : : && link ... [-o whatever]
5144 : :
5145 : : When compiling multiple inputs, an explicit -dumpbase is combined
5146 : : with -dumpdir, affecting aux outputs, but not the .o outputs:
5147 : :
5148 : : # gcc -dumpdir f -dumpbase g- b.c d.c -gsplit-dwarf -c
5149 : : -> cc1 -dumpdir fg- -dumpbase b.c -dumpbase-ext .c # b.o fg-b.dwo
5150 : : && cc1 -dumpdir fg- -dumpbase d.c -dumpbase-ext .c # d.o fg-d.dwo
5151 : :
5152 : : When compiling and linking with -save-temps, the .o outputs that
5153 : : would have been temporary become aux outputs, so they get
5154 : : affected by -dump* flags:
5155 : :
5156 : : # gcc -dumpdir f -dumpbase g- -save-temps b.c d.c
5157 : : -> cc1 -dumpdir fg- -dumpbase b.c -dumpbase-ext .c # fg-b.o
5158 : : && cc1 -dumpdir fg- -dumpbase d.c -dumpbase-ext .c # fg-d.o
5159 : : && link
5160 : :
5161 : : If -save-temps=* prevails over -dumpdir, however, the explicit
5162 : : -dumpdir is discarded, as if it wasn't there. The basename of
5163 : : the implicit linker output, a.out or a.exe, becomes a- as the aux
5164 : : output prefix for all compilations:
5165 : :
5166 : : # gcc [-dumpdir f] -save-temps=cwd b.c d.c
5167 : : -> cc1 -dumpdir a- -dumpbase b.c -dumpbase-ext .c # a-b.o
5168 : : && cc1 -dumpdir a- -dumpbase d.c -dumpbase-ext .c # a-d.o
5169 : : && link
5170 : :
5171 : : A single -dumpbase, applying to multiple inputs, overrides the
5172 : : linker output name, implied or explicit, as the aux output prefix:
5173 : :
5174 : : # gcc [-dumpdir f] -dumpbase g- -save-temps=cwd b.c d.c
5175 : : -> cc1 -dumpdir g- -dumpbase b.c -dumpbase-ext .c # g-b.o
5176 : : && cc1 -dumpdir g- -dumpbase d.c -dumpbase-ext .c # g-d.o
5177 : : && link
5178 : :
5179 : : # gcc [-dumpdir f] -dumpbase g- -save-temps=cwd b.c d.c -o dir/h.out
5180 : : -> cc1 -dumpdir g- -dumpbase b.c -dumpbase-ext .c # g-b.o
5181 : : && cc1 -dumpdir g- -dumpbase d.c -dumpbase-ext .c # g-d.o
5182 : : && link -o dir/h.out
5183 : :
5184 : : Now, if the linker output is NOT overridden as a prefix, but
5185 : : -save-temps=* overrides implicit or explicit -dumpdir, the
5186 : : effective dump dir combines the dir selected by the -save-temps=*
5187 : : option with the basename of the specified or implied link output:
5188 : :
5189 : : # gcc [-dumpdir f] -save-temps=cwd b.c d.c -o dir/h.out
5190 : : -> cc1 -dumpdir h- -dumpbase b.c -dumpbase-ext .c # h-b.o
5191 : : && cc1 -dumpdir h- -dumpbase d.c -dumpbase-ext .c # h-d.o
5192 : : && link -o dir/h.out
5193 : :
5194 : : # gcc [-dumpdir f] -save-temps=obj b.c d.c -o dir/h.out
5195 : : -> cc1 -dumpdir dir/h- -dumpbase b.c -dumpbase-ext .c # dir/h-b.o
5196 : : && cc1 -dumpdir dir/h- -dumpbase d.c -dumpbase-ext .c # dir/h-d.o
5197 : : && link -o dir/h.out
5198 : :
5199 : : But then again, a single -dumpbase applying to multiple inputs
5200 : : gets used instead of the linker output basename in the combined
5201 : : dumpdir:
5202 : :
5203 : : # gcc [-dumpdir f] -dumpbase g- -save-temps=obj b.c d.c -o dir/h.out
5204 : : -> cc1 -dumpdir dir/g- -dumpbase b.c -dumpbase-ext .c # dir/g-b.o
5205 : : && cc1 -dumpdir dir/g- -dumpbase d.c -dumpbase-ext .c # dir/g-d.o
5206 : : && link -o dir/h.out
5207 : :
5208 : : With a single input being compiled, the output basename does NOT
5209 : : affect the dumpdir prefix.
5210 : :
5211 : : # gcc -save-temps=obj b.c -gsplit-dwarf -c -o dir/b.o
5212 : : -> cc1 -dumpdir dir/ -dumpbase b.c -dumpbase-ext .c # dir/b.o dir/b.dwo
5213 : :
5214 : : but when compiling and linking even a single file, it does:
5215 : :
5216 : : # gcc -save-temps=obj b.c -o dir/h.out
5217 : : -> cc1 -dumpdir dir/h- -dumpbase b.c -dumpbase-ext .c # dir/h-b.o
5218 : :
5219 : : unless an explicit -dumpdir prevails:
5220 : :
5221 : : # gcc -save-temps[=obj] -dumpdir g- b.c -o dir/h.out
5222 : : -> cc1 -dumpdir g- -dumpbase b.c -dumpbase-ext .c # g-b.o
5223 : :
5224 : : */
5225 : :
5226 : 287494 : bool explicit_dumpdir = dumpdir;
5227 : :
5228 : 287442 : if ((!save_temps_overrides_dumpdir && explicit_dumpdir)
5229 : 555180 : || (output_file && not_actual_file_p (output_file)))
5230 : : {
5231 : : /* Do nothing. */
5232 : : }
5233 : :
5234 : : /* If -save-temps=obj and -o name, create the prefix to use for %b.
5235 : : Otherwise just make -save-temps=obj the same as -save-temps=cwd. */
5236 : 266242 : else if (save_temps_flag != SAVE_TEMPS_CWD && output_file != NULL)
5237 : : {
5238 : 248379 : free (dumpdir);
5239 : 248379 : dumpdir = NULL;
5240 : 248379 : temp = lbasename (output_file);
5241 : 248379 : if (temp != output_file)
5242 : 101290 : dumpdir = xstrndup (output_file,
5243 : 101290 : strlen (output_file) - strlen (temp));
5244 : : }
5245 : 17863 : else if (dumpdir)
5246 : : {
5247 : 5 : free (dumpdir);
5248 : 5 : dumpdir = NULL;
5249 : : }
5250 : :
5251 : 287494 : if (save_temps_flag)
5252 : 455 : save_temps_flag = SAVE_TEMPS_DUMP;
5253 : :
5254 : : /* If there is any pathname component in an explicit -dumpbase, it
5255 : : overrides dumpdir entirely, so discard it right away. Although
5256 : : the presence of an explicit -dumpdir matters for the driver, it
5257 : : shouldn't matter for other processes, that get all that's needed
5258 : : from the -dumpdir and -dumpbase always passed to them. */
5259 : 287494 : if (dumpdir && dumpbase && lbasename (dumpbase) != dumpbase)
5260 : : {
5261 : 19669 : free (dumpdir);
5262 : 19669 : dumpdir = NULL;
5263 : : }
5264 : :
5265 : : /* Check that dumpbase_ext matches the end of dumpbase, drop it
5266 : : otherwise. */
5267 : 287494 : if (dumpbase_ext && dumpbase && *dumpbase)
5268 : : {
5269 : 20 : int lendb = strlen (dumpbase);
5270 : 20 : int lendbx = strlen (dumpbase_ext);
5271 : :
5272 : : /* -dumpbase-ext must be a suffix proper; discard it if it
5273 : : matches all of -dumpbase, as that would make for an empty
5274 : : basename. */
5275 : 20 : if (lendbx >= lendb
5276 : 19 : || strcmp (dumpbase + lendb - lendbx, dumpbase_ext) != 0)
5277 : : {
5278 : 1 : free (dumpbase_ext);
5279 : 1 : dumpbase_ext = NULL;
5280 : : }
5281 : : }
5282 : :
5283 : : /* -dumpbase with multiple sources goes into dumpdir. With a single
5284 : : source, it does only if linking and if dumpdir was not explicitly
5285 : : specified. */
5286 : 21187 : if (dumpbase && *dumpbase
5287 : 307241 : && (single_input_file_index () == -2
5288 : 19464 : || (!have_c && !explicit_dumpdir)))
5289 : : {
5290 : 295 : char *prefix;
5291 : :
5292 : 295 : if (dumpbase_ext)
5293 : : /* We checked that they match above. */
5294 : 6 : dumpbase[strlen (dumpbase) - strlen (dumpbase_ext)] = '\0';
5295 : :
5296 : 295 : if (dumpdir)
5297 : 13 : prefix = concat (dumpdir, dumpbase, "-", NULL);
5298 : : else
5299 : 282 : prefix = concat (dumpbase, "-", NULL);
5300 : :
5301 : 295 : free (dumpdir);
5302 : 295 : free (dumpbase);
5303 : 295 : free (dumpbase_ext);
5304 : 295 : dumpbase = dumpbase_ext = NULL;
5305 : 295 : dumpdir = prefix;
5306 : 295 : dumpdir_trailing_dash_added = true;
5307 : : }
5308 : :
5309 : : /* If dumpbase was not brought into dumpdir but we're linking, bring
5310 : : output_file into dumpdir unless dumpdir was explicitly specified.
5311 : : The test for !explicit_dumpdir is further below, because we want
5312 : : to use the obase computation for a ghost outbase, passed to
5313 : : GCC_COLLECT_OPTIONS. */
5314 : 287199 : else if (!have_c && (!explicit_dumpdir || (dumpbase && !*dumpbase)))
5315 : : {
5316 : : /* If we get here, we know dumpbase was not specified, or it was
5317 : : specified as an empty string. If it was anything else, it
5318 : : would have combined with dumpdir above, because the condition
5319 : : for dumpbase to be used when present is broader than the
5320 : : condition that gets us here. */
5321 : 106569 : gcc_assert (!dumpbase || !*dumpbase);
5322 : :
5323 : 106569 : const char *obase;
5324 : 106569 : char *tofree = NULL;
5325 : 106569 : if (!output_file || not_actual_file_p (output_file))
5326 : : obase = "a";
5327 : : else
5328 : : {
5329 : 92067 : obase = lbasename (output_file);
5330 : 92067 : size_t blen = strlen (obase), xlen;
5331 : : /* Drop the suffix if it's dumpbase_ext, if given,
5332 : : otherwise .exe or the target executable suffix, or if the
5333 : : output was explicitly named a.out, but not otherwise. */
5334 : 92067 : if (dumpbase_ext
5335 : 92067 : ? (blen > (xlen = strlen (dumpbase_ext))
5336 : 221 : && strcmp ((temp = (obase + blen - xlen)),
5337 : : dumpbase_ext) == 0)
5338 : 91846 : : ((temp = strrchr (obase + 1, '.'))
5339 : 89994 : && (xlen = strlen (temp))
5340 : 181840 : && (strcmp (temp, ".exe") == 0
5341 : : #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
5342 : : || strcmp (temp, TARGET_EXECUTABLE_SUFFIX) == 0
5343 : : #endif
5344 : 8798 : || strcmp (obase, "a.out") == 0)))
5345 : : {
5346 : 81443 : tofree = xstrndup (obase, blen - xlen);
5347 : 81443 : obase = tofree;
5348 : : }
5349 : : }
5350 : :
5351 : : /* We wish to save this basename to the -dumpdir passed through
5352 : : GCC_COLLECT_OPTIONS within maybe_run_linker, for e.g. LTO,
5353 : : but we do NOT wish to add it to e.g. %b, so we keep
5354 : : outbase_length as zero. */
5355 : 106569 : gcc_assert (!outbase);
5356 : 106569 : outbase_length = 0;
5357 : :
5358 : : /* If we're building [dir1/]foo[.exe] out of a single input
5359 : : [dir2/]foo.c that shares the same basename, dump to
5360 : : [dir2/]foo.c.* rather than duplicating the basename into
5361 : : [dir2/]foo-foo.c.*. */
5362 : 106569 : int idxin;
5363 : 106569 : if (dumpbase
5364 : 106569 : || ((idxin = single_input_file_index ()) >= 0
5365 : 81948 : && adds_single_suffix_p (lbasename (infiles[idxin].name),
5366 : : obase)))
5367 : : {
5368 : 74891 : if (obase == tofree)
5369 : 73132 : outbase = tofree;
5370 : : else
5371 : : {
5372 : 1759 : outbase = xstrdup (obase);
5373 : 1759 : free (tofree);
5374 : : }
5375 : 106569 : obase = tofree = NULL;
5376 : : }
5377 : : else
5378 : : {
5379 : 31678 : if (dumpdir)
5380 : : {
5381 : 14913 : char *p = concat (dumpdir, obase, "-", NULL);
5382 : 14913 : free (dumpdir);
5383 : 14913 : dumpdir = p;
5384 : : }
5385 : : else
5386 : 16765 : dumpdir = concat (obase, "-", NULL);
5387 : :
5388 : 31678 : dumpdir_trailing_dash_added = true;
5389 : :
5390 : 31678 : free (tofree);
5391 : 31678 : obase = tofree = NULL;
5392 : : }
5393 : :
5394 : 106569 : if (!explicit_dumpdir || dumpbase)
5395 : : {
5396 : : /* Absent -dumpbase and present -dumpbase-ext have been applied
5397 : : to the linker output name, so compute fresh defaults for each
5398 : : compilation. */
5399 : 106569 : free (dumpbase_ext);
5400 : 106569 : dumpbase_ext = NULL;
5401 : : }
5402 : : }
5403 : :
5404 : : /* Now, if we're compiling, or if we haven't used the dumpbase
5405 : : above, then outbase (%B) is derived from dumpbase, if given, or
5406 : : from the output name, given or implied. We can't precompute
5407 : : implied output names, but that's ok, since they're derived from
5408 : : input names. Just make sure we skip this if dumpbase is the
5409 : : empty string: we want to use input names then, so don't set
5410 : : outbase. */
5411 : 287494 : if ((dumpbase || have_c)
5412 : 182281 : && !(dumpbase && !*dumpbase))
5413 : : {
5414 : 180841 : gcc_assert (!outbase);
5415 : :
5416 : 180841 : if (dumpbase)
5417 : : {
5418 : 19452 : gcc_assert (single_input_file_index () != -2);
5419 : : /* We do not want lbasename here; dumpbase with dirnames
5420 : : overrides dumpdir entirely, even if dumpdir is
5421 : : specified. */
5422 : 19452 : if (dumpbase_ext)
5423 : : /* We've already checked above that the suffix matches. */
5424 : 13 : outbase = xstrndup (dumpbase,
5425 : 13 : strlen (dumpbase) - strlen (dumpbase_ext));
5426 : : else
5427 : 19439 : outbase = xstrdup (dumpbase);
5428 : : }
5429 : 161389 : else if (output_file && !not_actual_file_p (output_file))
5430 : : {
5431 : 156548 : outbase = xstrdup (lbasename (output_file));
5432 : 156548 : char *p = strrchr (outbase + 1, '.');
5433 : 156548 : if (p)
5434 : 156548 : *p = '\0';
5435 : : }
5436 : :
5437 : 180841 : if (outbase)
5438 : 176000 : outbase_length = strlen (outbase);
5439 : : }
5440 : :
5441 : : /* If there is any pathname component in an explicit -dumpbase, do
5442 : : not use dumpdir, but retain it to pass it on to the compiler. */
5443 : 287494 : if (dumpdir)
5444 : 118424 : dumpdir_length = strlen (dumpdir);
5445 : : else
5446 : 169070 : dumpdir_length = 0;
5447 : :
5448 : : /* Check that dumpbase_ext, if still present, still matches the end
5449 : : of dumpbase, if present, and drop it otherwise. We only retained
5450 : : it above when dumpbase was absent to maybe use it to drop the
5451 : : extension from output_name before combining it with dumpdir. We
5452 : : won't deal with -dumpbase-ext when -dumpbase is not explicitly
5453 : : given, even if just to activate backward-compatible dumpbase:
5454 : : dropping it on the floor is correct, expected and documented
5455 : : behavior. Attempting to deal with a -dumpbase-ext that might
5456 : : match the end of some input filename, or of the combination of
5457 : : the output basename with the suffix of the input filename,
5458 : : possible with an intermediate .gk extension for -fcompare-debug,
5459 : : is just calling for trouble. */
5460 : 287494 : if (dumpbase_ext)
5461 : : {
5462 : 22 : if (!dumpbase || !*dumpbase)
5463 : : {
5464 : 9 : free (dumpbase_ext);
5465 : 9 : dumpbase_ext = NULL;
5466 : : }
5467 : : else
5468 : 13 : gcc_assert (strcmp (dumpbase + strlen (dumpbase)
5469 : : - strlen (dumpbase_ext), dumpbase_ext) == 0);
5470 : : }
5471 : :
5472 : 287494 : if (save_temps_flag && use_pipes)
5473 : : {
5474 : : /* -save-temps overrides -pipe, so that temp files are produced */
5475 : 0 : if (save_temps_flag)
5476 : 0 : warning (0, "%<-pipe%> ignored because %<-save-temps%> specified");
5477 : 0 : use_pipes = 0;
5478 : : }
5479 : :
5480 : 287494 : if (!compare_debug)
5481 : : {
5482 : 286872 : const char *gcd = env.get ("GCC_COMPARE_DEBUG");
5483 : :
5484 : 286872 : if (gcd && gcd[0] == '-')
5485 : : {
5486 : 0 : compare_debug = 2;
5487 : 0 : compare_debug_opt = gcd;
5488 : : }
5489 : 0 : else if (gcd && *gcd && strcmp (gcd, "0"))
5490 : : {
5491 : 0 : compare_debug = 3;
5492 : 0 : compare_debug_opt = "-gtoggle";
5493 : : }
5494 : : }
5495 : 622 : else if (compare_debug < 0)
5496 : : {
5497 : 0 : compare_debug = 0;
5498 : 0 : gcc_assert (!compare_debug_opt);
5499 : : }
5500 : :
5501 : : /* Set up the search paths. We add directories that we expect to
5502 : : contain GNU Toolchain components before directories specified by
5503 : : the machine description so that we will find GNU components (like
5504 : : the GNU assembler) before those of the host system. */
5505 : :
5506 : : /* If we don't know where the toolchain has been installed, use the
5507 : : configured-in locations. */
5508 : 287494 : if (!gcc_exec_prefix)
5509 : : {
5510 : : #ifndef OS2
5511 : 0 : add_prefix (&exec_prefixes, standard_libexec_prefix, "GCC",
5512 : : PREFIX_PRIORITY_LAST, 1, 0);
5513 : 0 : add_prefix (&exec_prefixes, standard_libexec_prefix, "BINUTILS",
5514 : : PREFIX_PRIORITY_LAST, 2, 0);
5515 : 0 : add_prefix (&exec_prefixes, standard_exec_prefix, "BINUTILS",
5516 : : PREFIX_PRIORITY_LAST, 2, 0);
5517 : : #endif
5518 : 0 : add_prefix (&startfile_prefixes, standard_exec_prefix, "BINUTILS",
5519 : : PREFIX_PRIORITY_LAST, 1, 0);
5520 : : }
5521 : :
5522 : 287494 : gcc_assert (!IS_ABSOLUTE_PATH (tooldir_base_prefix));
5523 : 287494 : tooldir_prefix2 = concat (tooldir_base_prefix, spec_machine,
5524 : : dir_separator_str, NULL);
5525 : :
5526 : : /* Look for tools relative to the location from which the driver is
5527 : : running, or, if that is not available, the configured prefix. */
5528 : 287494 : tooldir_prefix
5529 : 574988 : = concat (gcc_exec_prefix ? gcc_exec_prefix : standard_exec_prefix,
5530 : : spec_host_machine, dir_separator_str, spec_version,
5531 : : accel_dir_suffix, dir_separator_str, tooldir_prefix2, NULL);
5532 : 287494 : free (tooldir_prefix2);
5533 : :
5534 : 287494 : add_prefix (&exec_prefixes,
5535 : 287494 : concat (tooldir_prefix, "bin", dir_separator_str, NULL),
5536 : : "BINUTILS", PREFIX_PRIORITY_LAST, 0, 0);
5537 : 287494 : add_prefix (&startfile_prefixes,
5538 : 287494 : concat (tooldir_prefix, "lib", dir_separator_str, NULL),
5539 : : "BINUTILS", PREFIX_PRIORITY_LAST, 0, 1);
5540 : 287494 : free (tooldir_prefix);
5541 : :
5542 : : #if defined(TARGET_SYSTEM_ROOT_RELOCATABLE) && !defined(VMS)
5543 : : /* If the normal TARGET_SYSTEM_ROOT is inside of $exec_prefix,
5544 : : then consider it to relocate with the rest of the GCC installation
5545 : : if GCC_EXEC_PREFIX is set.
5546 : : ``make_relative_prefix'' is not compiled for VMS, so don't call it. */
5547 : : if (target_system_root && !target_system_root_changed && gcc_exec_prefix)
5548 : : {
5549 : : char *tmp_prefix = get_relative_prefix (decoded_options[0].arg,
5550 : : standard_bindir_prefix,
5551 : : target_system_root);
5552 : : if (tmp_prefix && access_check (tmp_prefix, F_OK) == 0)
5553 : : {
5554 : : target_system_root = tmp_prefix;
5555 : : target_system_root_changed = 1;
5556 : : }
5557 : : }
5558 : : #endif
5559 : :
5560 : : /* More prefixes are enabled in main, after we read the specs file
5561 : : and determine whether this is cross-compilation or not. */
5562 : :
5563 : 287494 : if (n_infiles != 0 && n_infiles == last_language_n_infiles && spec_lang != 0)
5564 : 0 : warning (0, "%<-x %s%> after last input file has no effect", spec_lang);
5565 : :
5566 : : /* Synthesize -fcompare-debug flag from the GCC_COMPARE_DEBUG
5567 : : environment variable. */
5568 : 287494 : if (compare_debug == 2 || compare_debug == 3)
5569 : : {
5570 : 0 : const char *opt = concat ("-fcompare-debug=", compare_debug_opt, NULL);
5571 : 0 : save_switch (opt, 0, NULL, false, true);
5572 : 0 : compare_debug = 1;
5573 : : }
5574 : :
5575 : : /* Ensure we only invoke each subprocess once. */
5576 : 287494 : if (n_infiles == 0
5577 : 8582 : && (print_subprocess_help || print_help_list || print_version))
5578 : : {
5579 : : /* Create a dummy input file, so that we can pass
5580 : : the help option on to the various sub-processes. */
5581 : 78 : add_infile ("help-dummy", "c");
5582 : : }
5583 : :
5584 : : /* Decide if undefined variable references are allowed in specs. */
5585 : :
5586 : : /* -v alone is safe. --version and --help alone or together are safe. Note
5587 : : that -v would make them unsafe, as they'd then be run for subprocesses as
5588 : : well, the location of which might depend on variables possibly coming
5589 : : from self-specs. Note also that the command name is counted in
5590 : : decoded_options_count. */
5591 : :
5592 : 287494 : unsigned help_version_count = 0;
5593 : :
5594 : 287494 : if (print_version)
5595 : 78 : help_version_count++;
5596 : :
5597 : 287494 : if (print_help_list)
5598 : 4 : help_version_count++;
5599 : :
5600 : 574988 : spec_undefvar_allowed =
5601 : 1358 : ((verbose_flag && decoded_options_count == 2)
5602 : 288819 : || help_version_count == decoded_options_count - 1);
5603 : :
5604 : 287494 : alloc_switch ();
5605 : 287494 : switches[n_switches].part1 = 0;
5606 : 287494 : alloc_infile ();
5607 : 287494 : infiles[n_infiles].name = 0;
5608 : 287494 : }
5609 : :
5610 : : /* Store switches not filtered out by %<S in spec in COLLECT_GCC_OPTIONS
5611 : : and place that in the environment. */
5612 : :
5613 : : static void
5614 : 793436 : set_collect_gcc_options (void)
5615 : : {
5616 : 793436 : int i;
5617 : 793436 : int first_time;
5618 : :
5619 : : /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
5620 : : the compiler. */
5621 : 793436 : obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
5622 : : sizeof ("COLLECT_GCC_OPTIONS=") - 1);
5623 : :
5624 : 793436 : first_time = true;
5625 : 18452017 : for (i = 0; (int) i < n_switches; i++)
5626 : : {
5627 : 17658581 : const char *const *args;
5628 : 17658581 : const char *p, *q;
5629 : 17658581 : if (!first_time)
5630 : 16865145 : obstack_grow (&collect_obstack, " ", 1);
5631 : :
5632 : 17658581 : first_time = false;
5633 : :
5634 : : /* Ignore elided switches. */
5635 : 17774842 : if ((switches[i].live_cond
5636 : 17658581 : & (SWITCH_IGNORE | SWITCH_KEEP_FOR_GCC))
5637 : : == SWITCH_IGNORE)
5638 : 116261 : continue;
5639 : :
5640 : 17542320 : obstack_grow (&collect_obstack, "'-", 2);
5641 : 17542320 : q = switches[i].part1;
5642 : 17542320 : while ((p = strchr (q, '\'')))
5643 : : {
5644 : 0 : obstack_grow (&collect_obstack, q, p - q);
5645 : 0 : obstack_grow (&collect_obstack, "'\\''", 4);
5646 : 0 : q = ++p;
5647 : : }
5648 : 17542320 : obstack_grow (&collect_obstack, q, strlen (q));
5649 : 17542320 : obstack_grow (&collect_obstack, "'", 1);
5650 : :
5651 : 21582995 : for (args = switches[i].args; args && *args; args++)
5652 : : {
5653 : 4040675 : obstack_grow (&collect_obstack, " '", 2);
5654 : 4040675 : q = *args;
5655 : 4040675 : while ((p = strchr (q, '\'')))
5656 : : {
5657 : 0 : obstack_grow (&collect_obstack, q, p - q);
5658 : 0 : obstack_grow (&collect_obstack, "'\\''", 4);
5659 : 0 : q = ++p;
5660 : : }
5661 : 4040675 : obstack_grow (&collect_obstack, q, strlen (q));
5662 : 4040675 : obstack_grow (&collect_obstack, "'", 1);
5663 : : }
5664 : : }
5665 : :
5666 : 793436 : if (dumpdir)
5667 : : {
5668 : 565650 : if (!first_time)
5669 : 565650 : obstack_grow (&collect_obstack, " ", 1);
5670 : 565650 : first_time = false;
5671 : :
5672 : 565650 : obstack_grow (&collect_obstack, "'-dumpdir' '", 12);
5673 : 565650 : const char *p, *q;
5674 : :
5675 : 565650 : q = dumpdir;
5676 : 565650 : while ((p = strchr (q, '\'')))
5677 : : {
5678 : 0 : obstack_grow (&collect_obstack, q, p - q);
5679 : 0 : obstack_grow (&collect_obstack, "'\\''", 4);
5680 : 0 : q = ++p;
5681 : : }
5682 : 565650 : obstack_grow (&collect_obstack, q, strlen (q));
5683 : :
5684 : 565650 : obstack_grow (&collect_obstack, "'", 1);
5685 : : }
5686 : :
5687 : 793436 : obstack_grow (&collect_obstack, "\0", 1);
5688 : 793436 : xputenv (XOBFINISH (&collect_obstack, char *));
5689 : 793436 : }
5690 : :
5691 : : /* Process a spec string, accumulating and running commands. */
5692 : :
5693 : : /* These variables describe the input file name.
5694 : : input_file_number is the index on outfiles of this file,
5695 : : so that the output file name can be stored for later use by %o.
5696 : : input_basename is the start of the part of the input file
5697 : : sans all directory names, and basename_length is the number
5698 : : of characters starting there excluding the suffix .c or whatever. */
5699 : :
5700 : : static const char *gcc_input_filename;
5701 : : static int input_file_number;
5702 : : size_t input_filename_length;
5703 : : static int basename_length;
5704 : : static int suffixed_basename_length;
5705 : : static const char *input_basename;
5706 : : static const char *input_suffix;
5707 : : #ifndef HOST_LACKS_INODE_NUMBERS
5708 : : static struct stat input_stat;
5709 : : #endif
5710 : : static int input_stat_set;
5711 : :
5712 : : /* The compiler used to process the current input file. */
5713 : : static struct compiler *input_file_compiler;
5714 : :
5715 : : /* These are variables used within do_spec and do_spec_1. */
5716 : :
5717 : : /* Nonzero if an arg has been started and not yet terminated
5718 : : (with space, tab or newline). */
5719 : : static int arg_going;
5720 : :
5721 : : /* Nonzero means %d or %g has been seen; the next arg to be terminated
5722 : : is a temporary file name. */
5723 : : static int delete_this_arg;
5724 : :
5725 : : /* Nonzero means %w has been seen; the next arg to be terminated
5726 : : is the output file name of this compilation. */
5727 : : static int this_is_output_file;
5728 : :
5729 : : /* Nonzero means %s has been seen; the next arg to be terminated
5730 : : is the name of a library file and we should try the standard
5731 : : search dirs for it. */
5732 : : static int this_is_library_file;
5733 : :
5734 : : /* Nonzero means %T has been seen; the next arg to be terminated
5735 : : is the name of a linker script and we should try all of the
5736 : : standard search dirs for it. If it is found insert a --script
5737 : : command line switch and then substitute the full path in place,
5738 : : otherwise generate an error message. */
5739 : : static int this_is_linker_script;
5740 : :
5741 : : /* Nonzero means that the input of this command is coming from a pipe. */
5742 : : static int input_from_pipe;
5743 : :
5744 : : /* Nonnull means substitute this for any suffix when outputting a switches
5745 : : arguments. */
5746 : : static const char *suffix_subst;
5747 : :
5748 : : /* If there is an argument being accumulated, terminate it and store it. */
5749 : :
5750 : : static void
5751 : 77486742 : end_going_arg (void)
5752 : : {
5753 : 77486742 : if (arg_going)
5754 : : {
5755 : 18243802 : const char *string;
5756 : :
5757 : 18243802 : obstack_1grow (&obstack, 0);
5758 : 18243802 : string = XOBFINISH (&obstack, const char *);
5759 : 18243802 : if (this_is_library_file)
5760 : 523297 : string = find_file (string);
5761 : 18243802 : if (this_is_linker_script)
5762 : : {
5763 : 0 : char * full_script_path = find_a_file (&startfile_prefixes, string, R_OK, true);
5764 : :
5765 : 0 : if (full_script_path == NULL)
5766 : : {
5767 : 0 : error ("unable to locate default linker script %qs in the library search paths", string);
5768 : : /* Script was not found on search path. */
5769 : 0 : return;
5770 : : }
5771 : 0 : store_arg ("--script", false, false);
5772 : 0 : string = full_script_path;
5773 : : }
5774 : 18243802 : store_arg (string, delete_this_arg, this_is_output_file);
5775 : 18243802 : if (this_is_output_file)
5776 : 96938 : outfiles[input_file_number] = string;
5777 : 18243802 : arg_going = 0;
5778 : : }
5779 : : }
5780 : :
5781 : :
5782 : : /* Parse the WRAPPER string which is a comma separated list of the command line
5783 : : and insert them into the beginning of argbuf. */
5784 : :
5785 : : static void
5786 : 0 : insert_wrapper (const char *wrapper)
5787 : : {
5788 : 0 : int n = 0;
5789 : 0 : int i;
5790 : 0 : char *buf = xstrdup (wrapper);
5791 : 0 : char *p = buf;
5792 : 0 : unsigned int old_length = argbuf.length ();
5793 : :
5794 : 0 : do
5795 : : {
5796 : 0 : n++;
5797 : 0 : while (*p == ',')
5798 : 0 : p++;
5799 : : }
5800 : 0 : while ((p = strchr (p, ',')) != NULL);
5801 : :
5802 : 0 : argbuf.safe_grow (old_length + n, true);
5803 : 0 : memmove (argbuf.address () + n,
5804 : 0 : argbuf.address (),
5805 : 0 : old_length * sizeof (const_char_p));
5806 : :
5807 : 0 : i = 0;
5808 : 0 : p = buf;
5809 : : do
5810 : : {
5811 : 0 : while (*p == ',')
5812 : : {
5813 : 0 : *p = 0;
5814 : 0 : p++;
5815 : : }
5816 : 0 : argbuf[i] = p;
5817 : 0 : i++;
5818 : : }
5819 : 0 : while ((p = strchr (p, ',')) != NULL);
5820 : 0 : gcc_assert (i == n);
5821 : 0 : }
5822 : :
5823 : : /* Process the spec SPEC and run the commands specified therein.
5824 : : Returns 0 if the spec is successfully processed; -1 if failed. */
5825 : :
5826 : : int
5827 : 544440 : do_spec (const char *spec)
5828 : : {
5829 : 544440 : int value;
5830 : :
5831 : 544440 : value = do_spec_2 (spec, NULL);
5832 : :
5833 : : /* Force out any unfinished command.
5834 : : If -pipe, this forces out the last command if it ended in `|'. */
5835 : 544440 : if (value == 0)
5836 : : {
5837 : 539185 : if (argbuf.length () > 0
5838 : 809697 : && !strcmp (argbuf.last (), "|"))
5839 : 0 : argbuf.pop ();
5840 : :
5841 : 539185 : set_collect_gcc_options ();
5842 : :
5843 : 539185 : if (argbuf.length () > 0)
5844 : 270512 : value = execute ();
5845 : : }
5846 : :
5847 : 544440 : return value;
5848 : : }
5849 : :
5850 : : /* Process the spec SPEC, with SOFT_MATCHED_PART designating the current value
5851 : : of a matched * pattern which may be re-injected by way of %*. */
5852 : :
5853 : : static int
5854 : 5139348 : do_spec_2 (const char *spec, const char *soft_matched_part)
5855 : : {
5856 : 5139348 : int result;
5857 : :
5858 : 5139348 : clear_args ();
5859 : 5139348 : arg_going = 0;
5860 : 5139348 : delete_this_arg = 0;
5861 : 5139348 : this_is_output_file = 0;
5862 : 5139348 : this_is_library_file = 0;
5863 : 5139348 : this_is_linker_script = 0;
5864 : 5139348 : input_from_pipe = 0;
5865 : 5139348 : suffix_subst = NULL;
5866 : :
5867 : 5139348 : result = do_spec_1 (spec, 0, soft_matched_part);
5868 : :
5869 : 5139348 : end_going_arg ();
5870 : :
5871 : 5139348 : return result;
5872 : : }
5873 : :
5874 : : /* Process the given spec string and add any new options to the end
5875 : : of the switches/n_switches array. */
5876 : :
5877 : : static void
5878 : 2588562 : do_option_spec (const char *name, const char *spec)
5879 : : {
5880 : 2588562 : unsigned int i, value_count, value_len;
5881 : 2588562 : const char *p, *q, *value;
5882 : 2588562 : char *tmp_spec, *tmp_spec_p;
5883 : :
5884 : 2588562 : if (configure_default_options[0].name == NULL)
5885 : : return;
5886 : :
5887 : 6902832 : for (i = 0; i < ARRAY_SIZE (configure_default_options); i++)
5888 : 4889506 : if (strcmp (configure_default_options[i].name, name) == 0)
5889 : : break;
5890 : 2588562 : if (i == ARRAY_SIZE (configure_default_options))
5891 : : return;
5892 : :
5893 : 575236 : value = configure_default_options[i].value;
5894 : 575236 : value_len = strlen (value);
5895 : :
5896 : : /* Compute the size of the final spec. */
5897 : 575236 : value_count = 0;
5898 : 575236 : p = spec;
5899 : 1150472 : while ((p = strstr (p, "%(VALUE)")) != NULL)
5900 : : {
5901 : 575236 : p ++;
5902 : 575236 : value_count ++;
5903 : : }
5904 : :
5905 : : /* Replace each %(VALUE) by the specified value. */
5906 : 575236 : tmp_spec = (char *) alloca (strlen (spec) + 1
5907 : : + value_count * (value_len - strlen ("%(VALUE)")));
5908 : 575236 : tmp_spec_p = tmp_spec;
5909 : 575236 : q = spec;
5910 : 1150472 : while ((p = strstr (q, "%(VALUE)")) != NULL)
5911 : : {
5912 : 575236 : memcpy (tmp_spec_p, q, p - q);
5913 : 575236 : tmp_spec_p = tmp_spec_p + (p - q);
5914 : 575236 : memcpy (tmp_spec_p, value, value_len);
5915 : 575236 : tmp_spec_p += value_len;
5916 : 575236 : q = p + strlen ("%(VALUE)");
5917 : : }
5918 : 575236 : strcpy (tmp_spec_p, q);
5919 : :
5920 : 575236 : do_self_spec (tmp_spec);
5921 : : }
5922 : :
5923 : : /* Process the given spec string and add any new options to the end
5924 : : of the switches/n_switches array. */
5925 : :
5926 : : static void
5927 : 2588937 : do_self_spec (const char *spec)
5928 : : {
5929 : 2588937 : int i;
5930 : :
5931 : 2588937 : do_spec_2 (spec, NULL);
5932 : 2588937 : do_spec_1 (" ", 0, NULL);
5933 : :
5934 : : /* Mark %<S switches processed by do_self_spec to be ignored permanently.
5935 : : do_self_specs adds the replacements to switches array, so it shouldn't
5936 : : be processed afterwards. */
5937 : 60332439 : for (i = 0; i < n_switches; i++)
5938 : 55154565 : if ((switches[i].live_cond & SWITCH_IGNORE))
5939 : 670 : switches[i].live_cond |= SWITCH_IGNORE_PERMANENTLY;
5940 : :
5941 : 2588937 : if (argbuf.length () > 0)
5942 : : {
5943 : 547060 : const char **argbuf_copy;
5944 : 547060 : struct cl_decoded_option *decoded_options;
5945 : 547060 : struct cl_option_handlers handlers;
5946 : 547060 : unsigned int decoded_options_count;
5947 : 547060 : unsigned int j;
5948 : :
5949 : : /* Create a copy of argbuf with a dummy argv[0] entry for
5950 : : decode_cmdline_options_to_array. */
5951 : 547060 : argbuf_copy = XNEWVEC (const char *,
5952 : : argbuf.length () + 1);
5953 : 547060 : argbuf_copy[0] = "";
5954 : 547060 : memcpy (argbuf_copy + 1, argbuf.address (),
5955 : 547060 : argbuf.length () * sizeof (const char *));
5956 : :
5957 : 1094120 : decode_cmdline_options_to_array (argbuf.length () + 1,
5958 : : argbuf_copy,
5959 : : CL_DRIVER, &decoded_options,
5960 : : &decoded_options_count);
5961 : 547060 : free (argbuf_copy);
5962 : :
5963 : 547060 : set_option_handlers (&handlers);
5964 : :
5965 : 1096608 : for (j = 1; j < decoded_options_count; j++)
5966 : : {
5967 : 549548 : switch (decoded_options[j].opt_index)
5968 : : {
5969 : 0 : case OPT_SPECIAL_input_file:
5970 : : /* Specs should only generate options, not input
5971 : : files. */
5972 : 0 : if (strcmp (decoded_options[j].arg, "-") != 0)
5973 : 0 : fatal_error (input_location,
5974 : : "switch %qs does not start with %<-%>",
5975 : : decoded_options[j].arg);
5976 : : else
5977 : 0 : fatal_error (input_location,
5978 : : "spec-generated switch is just %<-%>");
5979 : 1244 : break;
5980 : :
5981 : 1244 : case OPT_fcompare_debug_second:
5982 : 1244 : case OPT_fcompare_debug:
5983 : 1244 : case OPT_fcompare_debug_:
5984 : 1244 : case OPT_o:
5985 : : /* Avoid duplicate processing of some options from
5986 : : compare-debug specs; just save them here. */
5987 : 1244 : save_switch (decoded_options[j].canonical_option[0],
5988 : 1244 : (decoded_options[j].canonical_option_num_elements
5989 : : - 1),
5990 : 1244 : &decoded_options[j].canonical_option[1], false, true);
5991 : 1244 : break;
5992 : :
5993 : 548304 : default:
5994 : 548304 : read_cmdline_option (&global_options, &global_options_set,
5995 : : decoded_options + j, UNKNOWN_LOCATION,
5996 : : CL_DRIVER, &handlers, global_dc);
5997 : 548304 : break;
5998 : : }
5999 : : }
6000 : :
6001 : 547060 : free (decoded_options);
6002 : :
6003 : 547060 : alloc_switch ();
6004 : 547060 : switches[n_switches].part1 = 0;
6005 : : }
6006 : 2588937 : }
6007 : :
6008 : : /* Callback for processing %D and %I specs. */
6009 : :
6010 : : struct spec_path_info {
6011 : : const char *option;
6012 : : const char *append;
6013 : : size_t append_len;
6014 : : bool omit_relative;
6015 : : bool separate_options;
6016 : : bool realpaths;
6017 : : };
6018 : :
6019 : : static void *
6020 : 3249950 : spec_path (char *path, void *data)
6021 : : {
6022 : 3249950 : struct spec_path_info *info = (struct spec_path_info *) data;
6023 : 3249950 : size_t len = 0;
6024 : 3249950 : char save = 0;
6025 : :
6026 : : /* The path must exist; we want to resolve it to the realpath so that this
6027 : : can be embedded as a runpath. */
6028 : 3249950 : if (info->realpaths)
6029 : 0 : path = lrealpath (path);
6030 : :
6031 : : /* However, if we failed to resolve it - perhaps because there was a bogus
6032 : : -B option on the command line, then punt on this entry. */
6033 : 3249950 : if (!path)
6034 : : return NULL;
6035 : :
6036 : 3249950 : if (info->omit_relative && !IS_ABSOLUTE_PATH (path))
6037 : : return NULL;
6038 : :
6039 : 3249950 : if (info->append_len != 0)
6040 : : {
6041 : 1343780 : len = strlen (path);
6042 : 1343780 : memcpy (path + len, info->append, info->append_len + 1);
6043 : : }
6044 : :
6045 : 3249950 : if (!is_directory (path))
6046 : : return NULL;
6047 : :
6048 : 1217622 : do_spec_1 (info->option, 1, NULL);
6049 : 1217622 : if (info->separate_options)
6050 : 431137 : do_spec_1 (" ", 0, NULL);
6051 : :
6052 : 1217622 : if (info->append_len == 0)
6053 : : {
6054 : 786485 : len = strlen (path);
6055 : 786485 : save = path[len - 1];
6056 : 786485 : if (IS_DIR_SEPARATOR (path[len - 1]))
6057 : 786485 : path[len - 1] = '\0';
6058 : : }
6059 : :
6060 : 1217622 : do_spec_1 (path, 1, NULL);
6061 : 1217622 : do_spec_1 (" ", 0, NULL);
6062 : :
6063 : : /* Must not damage the original path. */
6064 : 1217622 : if (info->append_len == 0)
6065 : 786485 : path[len - 1] = save;
6066 : :
6067 : : return NULL;
6068 : : }
6069 : :
6070 : : /* True if we should compile INFILE. */
6071 : :
6072 : : static bool
6073 : 42743 : compile_input_file_p (struct infile *infile)
6074 : : {
6075 : 24857 : if ((!infile->language) || (infile->language[0] != '*'))
6076 : 38516 : if (infile->incompiler == input_file_compiler)
6077 : 0 : return true;
6078 : : return false;
6079 : : }
6080 : :
6081 : : /* Process each member of VEC as a spec. */
6082 : :
6083 : : static void
6084 : 450025 : do_specs_vec (vec<char_p> vec)
6085 : : {
6086 : 450107 : for (char *opt : vec)
6087 : : {
6088 : 58 : do_spec_1 (opt, 1, NULL);
6089 : : /* Make each accumulated option a separate argument. */
6090 : 58 : do_spec_1 (" ", 0, NULL);
6091 : : }
6092 : 450025 : }
6093 : :
6094 : : /* Add options passed via -Xassembler or -Wa to COLLECT_AS_OPTIONS. */
6095 : :
6096 : : static void
6097 : 287493 : putenv_COLLECT_AS_OPTIONS (vec<char_p> vec)
6098 : : {
6099 : 287493 : if (vec.is_empty ())
6100 : 287493 : return;
6101 : :
6102 : 91 : obstack_init (&collect_obstack);
6103 : 91 : obstack_grow (&collect_obstack, "COLLECT_AS_OPTIONS=",
6104 : : strlen ("COLLECT_AS_OPTIONS="));
6105 : :
6106 : 91 : char *opt;
6107 : 91 : unsigned ix;
6108 : :
6109 : 274 : FOR_EACH_VEC_ELT (vec, ix, opt)
6110 : : {
6111 : 183 : obstack_1grow (&collect_obstack, '\'');
6112 : 183 : obstack_grow (&collect_obstack, opt, strlen (opt));
6113 : 183 : obstack_1grow (&collect_obstack, '\'');
6114 : 183 : if (ix < vec.length () - 1)
6115 : 92 : obstack_1grow(&collect_obstack, ' ');
6116 : : }
6117 : :
6118 : 91 : obstack_1grow (&collect_obstack, '\0');
6119 : 91 : xputenv (XOBFINISH (&collect_obstack, char *));
6120 : : }
6121 : :
6122 : : /* Process the sub-spec SPEC as a portion of a larger spec.
6123 : : This is like processing a whole spec except that we do
6124 : : not initialize at the beginning and we do not supply a
6125 : : newline by default at the end.
6126 : : INSWITCH nonzero means don't process %-sequences in SPEC;
6127 : : in this case, % is treated as an ordinary character.
6128 : : This is used while substituting switches.
6129 : : INSWITCH nonzero also causes SPC not to terminate an argument.
6130 : :
6131 : : Value is zero unless a line was finished
6132 : : and the command on that line reported an error. */
6133 : :
6134 : : static int
6135 : 49874711 : do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part)
6136 : : {
6137 : 49874711 : const char *p = spec;
6138 : 49874711 : int c;
6139 : 49874711 : int i;
6140 : 49874711 : int value;
6141 : :
6142 : : /* If it's an empty string argument to a switch, keep it as is. */
6143 : 49874711 : if (inswitch && !*p)
6144 : 1 : arg_going = 1;
6145 : :
6146 : 501886177 : while ((c = *p++))
6147 : : /* If substituting a switch, treat all chars like letters.
6148 : : Otherwise, NL, SPC, TAB and % are special. */
6149 : 452055901 : switch (inswitch ? 'a' : c)
6150 : : {
6151 : 254251 : case '\n':
6152 : 254251 : end_going_arg ();
6153 : :
6154 : 254251 : if (argbuf.length () > 0
6155 : 508502 : && !strcmp (argbuf.last (), "|"))
6156 : : {
6157 : : /* A `|' before the newline means use a pipe here,
6158 : : but only if -pipe was specified.
6159 : : Otherwise, execute now and don't pass the `|' as an arg. */
6160 : 160907 : if (use_pipes)
6161 : : {
6162 : 0 : input_from_pipe = 1;
6163 : 0 : break;
6164 : : }
6165 : : else
6166 : 160907 : argbuf.pop ();
6167 : : }
6168 : :
6169 : 254251 : set_collect_gcc_options ();
6170 : :
6171 : 254251 : if (argbuf.length () > 0)
6172 : : {
6173 : 254251 : value = execute ();
6174 : 254251 : if (value)
6175 : : return value;
6176 : : }
6177 : : /* Reinitialize for a new command, and for a new argument. */
6178 : 248996 : clear_args ();
6179 : 248996 : arg_going = 0;
6180 : 248996 : delete_this_arg = 0;
6181 : 248996 : this_is_output_file = 0;
6182 : 248996 : this_is_library_file = 0;
6183 : 248996 : this_is_linker_script = 0;
6184 : 248996 : input_from_pipe = 0;
6185 : 248996 : break;
6186 : :
6187 : 160907 : case '|':
6188 : 160907 : end_going_arg ();
6189 : :
6190 : : /* Use pipe */
6191 : 160907 : obstack_1grow (&obstack, c);
6192 : 160907 : arg_going = 1;
6193 : 160907 : break;
6194 : :
6195 : 67491829 : case '\t':
6196 : 67491829 : case ' ':
6197 : 67491829 : end_going_arg ();
6198 : :
6199 : : /* Reinitialize for a new argument. */
6200 : 67491829 : delete_this_arg = 0;
6201 : 67491829 : this_is_output_file = 0;
6202 : 67491829 : this_is_library_file = 0;
6203 : 67491829 : this_is_linker_script = 0;
6204 : 67491829 : break;
6205 : :
6206 : 47360980 : case '%':
6207 : 47360980 : switch (c = *p++)
6208 : : {
6209 : 0 : case 0:
6210 : 0 : fatal_error (input_location, "spec %qs invalid", spec);
6211 : :
6212 : 3582 : case 'b':
6213 : : /* Don't use %b in the linker command. */
6214 : 3582 : gcc_assert (suffixed_basename_length);
6215 : 3582 : if (!this_is_output_file && dumpdir_length)
6216 : 681 : obstack_grow (&obstack, dumpdir, dumpdir_length);
6217 : 3582 : if (this_is_output_file || !outbase_length)
6218 : 3240 : obstack_grow (&obstack, input_basename, basename_length);
6219 : : else
6220 : 342 : obstack_grow (&obstack, outbase, outbase_length);
6221 : 3582 : if (compare_debug < 0)
6222 : 6 : obstack_grow (&obstack, ".gk", 3);
6223 : 3582 : arg_going = 1;
6224 : 3582 : break;
6225 : :
6226 : 10 : case 'B':
6227 : : /* Don't use %B in the linker command. */
6228 : 10 : gcc_assert (suffixed_basename_length);
6229 : 10 : if (!this_is_output_file && dumpdir_length)
6230 : 0 : obstack_grow (&obstack, dumpdir, dumpdir_length);
6231 : 10 : if (this_is_output_file || !outbase_length)
6232 : 5 : obstack_grow (&obstack, input_basename, basename_length);
6233 : : else
6234 : 5 : obstack_grow (&obstack, outbase, outbase_length);
6235 : 10 : if (compare_debug < 0)
6236 : 3 : obstack_grow (&obstack, ".gk", 3);
6237 : 10 : obstack_grow (&obstack, input_basename + basename_length,
6238 : : suffixed_basename_length - basename_length);
6239 : :
6240 : 10 : arg_going = 1;
6241 : 10 : break;
6242 : :
6243 : 94430 : case 'd':
6244 : 94430 : delete_this_arg = 2;
6245 : 94430 : break;
6246 : :
6247 : : /* Dump out the directories specified with LIBRARY_PATH,
6248 : : followed by the absolute directories
6249 : : that we search for startfiles. */
6250 : 102877 : case 'D':
6251 : 102877 : {
6252 : 102877 : struct spec_path_info info;
6253 : :
6254 : 102877 : info.option = "-L";
6255 : 102877 : info.append_len = 0;
6256 : : #ifdef RELATIVE_PREFIX_NOT_LINKDIR
6257 : : /* Used on systems which record the specified -L dirs
6258 : : and use them to search for dynamic linking.
6259 : : Relative directories always come from -B,
6260 : : and it is better not to use them for searching
6261 : : at run time. In particular, stage1 loses. */
6262 : : info.omit_relative = true;
6263 : : #else
6264 : 102877 : info.omit_relative = false;
6265 : : #endif
6266 : 102877 : info.separate_options = false;
6267 : 102877 : info.realpaths = false;
6268 : :
6269 : 102877 : for_each_path (&startfile_prefixes, true, 0, spec_path, &info);
6270 : : }
6271 : 102877 : break;
6272 : :
6273 : 0 : case 'P':
6274 : 0 : {
6275 : 0 : struct spec_path_info info;
6276 : :
6277 : 0 : info.option = RUNPATH_OPTION;
6278 : 0 : info.append_len = 0;
6279 : 0 : info.omit_relative = false;
6280 : 0 : info.separate_options = true;
6281 : : /* We want to embed the actual paths that have the libraries. */
6282 : 0 : info.realpaths = true;
6283 : :
6284 : 0 : for_each_path (&startfile_prefixes, true, 0, spec_path, &info);
6285 : : }
6286 : 0 : break;
6287 : :
6288 : : case 'e':
6289 : : /* %efoo means report an error with `foo' as error message
6290 : : and don't execute any more commands for this file. */
6291 : : {
6292 : : const char *q = p;
6293 : : char *buf;
6294 : 0 : while (*p != 0 && *p != '\n')
6295 : 0 : p++;
6296 : 0 : buf = (char *) alloca (p - q + 1);
6297 : 0 : strncpy (buf, q, p - q);
6298 : 0 : buf[p - q] = 0;
6299 : 0 : error ("%s", _(buf));
6300 : 0 : return -1;
6301 : : }
6302 : : break;
6303 : : case 'n':
6304 : : /* %nfoo means report a notice with `foo' on stderr. */
6305 : : {
6306 : : const char *q = p;
6307 : : char *buf;
6308 : 0 : while (*p != 0 && *p != '\n')
6309 : 0 : p++;
6310 : 0 : buf = (char *) alloca (p - q + 1);
6311 : 0 : strncpy (buf, q, p - q);
6312 : 0 : buf[p - q] = 0;
6313 : 0 : inform (UNKNOWN_LOCATION, "%s", _(buf));
6314 : 0 : if (*p)
6315 : 0 : p++;
6316 : : }
6317 : : break;
6318 : :
6319 : 758 : case 'j':
6320 : 758 : {
6321 : 758 : struct stat st;
6322 : :
6323 : : /* If save_temps_flag is off, and the HOST_BIT_BUCKET is
6324 : : defined, and it is not a directory, and it is
6325 : : writable, use it. Otherwise, treat this like any
6326 : : other temporary file. */
6327 : :
6328 : 758 : if ((!save_temps_flag)
6329 : 758 : && (stat (HOST_BIT_BUCKET, &st) == 0) && (!S_ISDIR (st.st_mode))
6330 : 1516 : && (access (HOST_BIT_BUCKET, W_OK) == 0))
6331 : : {
6332 : 758 : obstack_grow (&obstack, HOST_BIT_BUCKET,
6333 : : strlen (HOST_BIT_BUCKET));
6334 : 758 : delete_this_arg = 0;
6335 : 758 : arg_going = 1;
6336 : 758 : break;
6337 : : }
6338 : : }
6339 : 0 : goto create_temp_file;
6340 : 160907 : case '|':
6341 : 160907 : if (use_pipes)
6342 : : {
6343 : 0 : obstack_1grow (&obstack, '-');
6344 : 0 : delete_this_arg = 0;
6345 : 0 : arg_going = 1;
6346 : :
6347 : : /* consume suffix */
6348 : 0 : while (*p == '.' || ISALNUM ((unsigned char) *p))
6349 : 0 : p++;
6350 : 0 : if (p[0] == '%' && p[1] == 'O')
6351 : 0 : p += 2;
6352 : :
6353 : : break;
6354 : : }
6355 : 160907 : goto create_temp_file;
6356 : 155794 : case 'm':
6357 : 155794 : if (use_pipes)
6358 : : {
6359 : : /* consume suffix */
6360 : 0 : while (*p == '.' || ISALNUM ((unsigned char) *p))
6361 : 0 : p++;
6362 : 0 : if (p[0] == '%' && p[1] == 'O')
6363 : 0 : p += 2;
6364 : :
6365 : : break;
6366 : : }
6367 : 155794 : goto create_temp_file;
6368 : 501342 : case 'g':
6369 : 501342 : case 'u':
6370 : 501342 : case 'U':
6371 : 501342 : create_temp_file:
6372 : 501342 : {
6373 : 501342 : struct temp_name *t;
6374 : 501342 : int suffix_length;
6375 : 501342 : const char *suffix = p;
6376 : 501342 : char *saved_suffix = NULL;
6377 : :
6378 : 1493744 : while (*p == '.' || ISALNUM ((unsigned char) *p))
6379 : 992402 : p++;
6380 : 501342 : suffix_length = p - suffix;
6381 : 501342 : if (p[0] == '%' && p[1] == 'O')
6382 : : {
6383 : 94646 : p += 2;
6384 : : /* We don't support extra suffix characters after %O. */
6385 : 94646 : if (*p == '.' || ISALNUM ((unsigned char) *p))
6386 : 0 : fatal_error (input_location,
6387 : : "spec %qs has invalid %<%%0%c%>", spec, *p);
6388 : 94646 : if (suffix_length == 0)
6389 : : suffix = TARGET_OBJECT_SUFFIX;
6390 : : else
6391 : : {
6392 : 0 : saved_suffix
6393 : 0 : = XNEWVEC (char, suffix_length
6394 : : + strlen (TARGET_OBJECT_SUFFIX) + 1);
6395 : 0 : strncpy (saved_suffix, suffix, suffix_length);
6396 : 0 : strcpy (saved_suffix + suffix_length,
6397 : : TARGET_OBJECT_SUFFIX);
6398 : : }
6399 : 94646 : suffix_length += strlen (TARGET_OBJECT_SUFFIX);
6400 : : }
6401 : :
6402 : 501342 : if (compare_debug < 0)
6403 : : {
6404 : 613 : suffix = concat (".gk", suffix, NULL);
6405 : 613 : suffix_length += 3;
6406 : : }
6407 : :
6408 : : /* If -save-temps was specified, use that for the
6409 : : temp file. */
6410 : 501342 : if (save_temps_flag)
6411 : : {
6412 : 1178 : char *tmp;
6413 : 1178 : bool adjusted_suffix = false;
6414 : 1178 : if (suffix_length
6415 : 1178 : && !outbase_length && !basename_length
6416 : 220 : && !dumpdir_trailing_dash_added)
6417 : : {
6418 : 20 : adjusted_suffix = true;
6419 : 20 : suffix++;
6420 : 20 : suffix_length--;
6421 : : }
6422 : 1178 : temp_filename_length
6423 : 1178 : = dumpdir_length + suffix_length + 1;
6424 : 1178 : if (outbase_length)
6425 : 72 : temp_filename_length += outbase_length;
6426 : : else
6427 : 1106 : temp_filename_length += basename_length;
6428 : 1178 : tmp = (char *) alloca (temp_filename_length);
6429 : 1178 : if (dumpdir_length)
6430 : 1020 : memcpy (tmp, dumpdir, dumpdir_length);
6431 : 1178 : if (outbase_length)
6432 : 72 : memcpy (tmp + dumpdir_length, outbase,
6433 : : outbase_length);
6434 : 1106 : else if (basename_length)
6435 : 886 : memcpy (tmp + dumpdir_length, input_basename,
6436 : : basename_length);
6437 : 1178 : memcpy (tmp + temp_filename_length - suffix_length - 1,
6438 : : suffix, suffix_length);
6439 : 1178 : if (adjusted_suffix)
6440 : : {
6441 : 20 : adjusted_suffix = false;
6442 : 20 : suffix--;
6443 : 20 : suffix_length++;
6444 : : }
6445 : 1178 : tmp[temp_filename_length - 1] = '\0';
6446 : 1178 : temp_filename = tmp;
6447 : :
6448 : 1178 : if (filename_cmp (temp_filename, gcc_input_filename) != 0)
6449 : : {
6450 : : #ifndef HOST_LACKS_INODE_NUMBERS
6451 : 1178 : struct stat st_temp;
6452 : :
6453 : : /* Note, set_input() resets input_stat_set to 0. */
6454 : 1178 : if (input_stat_set == 0)
6455 : : {
6456 : 549 : input_stat_set = stat (gcc_input_filename,
6457 : : &input_stat);
6458 : 549 : if (input_stat_set >= 0)
6459 : 549 : input_stat_set = 1;
6460 : : }
6461 : :
6462 : : /* If we have the stat for the gcc_input_filename
6463 : : and we can do the stat for the temp_filename
6464 : : then the they could still refer to the same
6465 : : file if st_dev/st_ino's are the same. */
6466 : 1178 : if (input_stat_set != 1
6467 : 1178 : || stat (temp_filename, &st_temp) < 0
6468 : 361 : || input_stat.st_dev != st_temp.st_dev
6469 : 1192 : || input_stat.st_ino != st_temp.st_ino)
6470 : : #else
6471 : : /* Just compare canonical pathnames. */
6472 : : char* input_realname = lrealpath (gcc_input_filename);
6473 : : char* temp_realname = lrealpath (temp_filename);
6474 : : bool files_differ = filename_cmp (input_realname, temp_realname);
6475 : : free (input_realname);
6476 : : free (temp_realname);
6477 : : if (files_differ)
6478 : : #endif
6479 : : {
6480 : 1178 : temp_filename
6481 : 1178 : = save_string (temp_filename,
6482 : : temp_filename_length - 1);
6483 : 1178 : obstack_grow (&obstack, temp_filename,
6484 : : temp_filename_length);
6485 : 1178 : arg_going = 1;
6486 : 1178 : delete_this_arg = 0;
6487 : 1178 : break;
6488 : : }
6489 : : }
6490 : : }
6491 : :
6492 : : /* See if we already have an association of %g/%u/%U and
6493 : : suffix. */
6494 : 857792 : for (t = temp_names; t; t = t->next)
6495 : 520362 : if (t->length == suffix_length
6496 : 347847 : && strncmp (t->suffix, suffix, suffix_length) == 0
6497 : 166637 : && t->unique == (c == 'u' || c == 'U' || c == 'j'))
6498 : : break;
6499 : :
6500 : : /* Make a new association if needed. %u and %j
6501 : : require one. */
6502 : 500164 : if (t == 0 || c == 'u' || c == 'j')
6503 : : {
6504 : 341139 : if (t == 0)
6505 : : {
6506 : 337430 : t = XNEW (struct temp_name);
6507 : 337430 : t->next = temp_names;
6508 : 337430 : temp_names = t;
6509 : : }
6510 : 341139 : t->length = suffix_length;
6511 : 341139 : if (saved_suffix)
6512 : : {
6513 : 0 : t->suffix = saved_suffix;
6514 : 0 : saved_suffix = NULL;
6515 : : }
6516 : : else
6517 : 341139 : t->suffix = save_string (suffix, suffix_length);
6518 : 341139 : t->unique = (c == 'u' || c == 'U' || c == 'j');
6519 : 341139 : temp_filename = make_temp_file (t->suffix);
6520 : 341139 : temp_filename_length = strlen (temp_filename);
6521 : 341139 : t->filename = temp_filename;
6522 : 341139 : t->filename_length = temp_filename_length;
6523 : : }
6524 : :
6525 : 500164 : free (saved_suffix);
6526 : :
6527 : 500164 : obstack_grow (&obstack, t->filename, t->filename_length);
6528 : 500164 : delete_this_arg = 1;
6529 : : }
6530 : 500164 : arg_going = 1;
6531 : 500164 : break;
6532 : :
6533 : 277295 : case 'i':
6534 : 277295 : if (combine_inputs)
6535 : : {
6536 : : /* We are going to expand `%i' into `@FILE', where FILE
6537 : : is a newly-created temporary filename. The filenames
6538 : : that would usually be expanded in place of %o will be
6539 : : written to the temporary file. */
6540 : 29364 : if (at_file_supplied)
6541 : 11824 : open_at_file ();
6542 : :
6543 : 72107 : for (i = 0; (int) i < n_infiles; i++)
6544 : 85486 : if (compile_input_file_p (&infiles[i]))
6545 : : {
6546 : 38454 : store_arg (infiles[i].name, 0, 0);
6547 : 38454 : infiles[i].compiled = true;
6548 : : }
6549 : :
6550 : 29364 : if (at_file_supplied)
6551 : 11824 : close_at_file ();
6552 : : }
6553 : : else
6554 : : {
6555 : 247931 : obstack_grow (&obstack, gcc_input_filename,
6556 : : input_filename_length);
6557 : 247931 : arg_going = 1;
6558 : : }
6559 : : break;
6560 : :
6561 : 214486 : case 'I':
6562 : 214486 : {
6563 : 214486 : struct spec_path_info info;
6564 : :
6565 : 214486 : if (multilib_dir)
6566 : : {
6567 : 5943 : do_spec_1 ("-imultilib", 1, NULL);
6568 : : /* Make this a separate argument. */
6569 : 5943 : do_spec_1 (" ", 0, NULL);
6570 : 5943 : do_spec_1 (multilib_dir, 1, NULL);
6571 : 5943 : do_spec_1 (" ", 0, NULL);
6572 : : }
6573 : :
6574 : 214486 : if (multiarch_dir)
6575 : : {
6576 : 0 : do_spec_1 ("-imultiarch", 1, NULL);
6577 : : /* Make this a separate argument. */
6578 : 0 : do_spec_1 (" ", 0, NULL);
6579 : 0 : do_spec_1 (multiarch_dir, 1, NULL);
6580 : 0 : do_spec_1 (" ", 0, NULL);
6581 : : }
6582 : :
6583 : 214486 : if (gcc_exec_prefix)
6584 : : {
6585 : 214486 : do_spec_1 ("-iprefix", 1, NULL);
6586 : : /* Make this a separate argument. */
6587 : 214486 : do_spec_1 (" ", 0, NULL);
6588 : 214486 : do_spec_1 (gcc_exec_prefix, 1, NULL);
6589 : 214486 : do_spec_1 (" ", 0, NULL);
6590 : : }
6591 : :
6592 : 214486 : if (target_system_root_changed ||
6593 : 214486 : (target_system_root && target_sysroot_hdrs_suffix))
6594 : : {
6595 : 0 : do_spec_1 ("-isysroot", 1, NULL);
6596 : : /* Make this a separate argument. */
6597 : 0 : do_spec_1 (" ", 0, NULL);
6598 : 0 : do_spec_1 (target_system_root, 1, NULL);
6599 : 0 : if (target_sysroot_hdrs_suffix)
6600 : 0 : do_spec_1 (target_sysroot_hdrs_suffix, 1, NULL);
6601 : 0 : do_spec_1 (" ", 0, NULL);
6602 : : }
6603 : :
6604 : 214486 : info.option = "-isystem";
6605 : 214486 : info.append = "include";
6606 : 214486 : info.append_len = strlen (info.append);
6607 : 214486 : info.omit_relative = false;
6608 : 214486 : info.separate_options = true;
6609 : 214486 : info.realpaths = false;
6610 : :
6611 : 214486 : for_each_path (&include_prefixes, false, info.append_len,
6612 : : spec_path, &info);
6613 : :
6614 : 214486 : info.append = "include-fixed";
6615 : 214486 : if (*sysroot_hdrs_suffix_spec)
6616 : 0 : info.append = concat (info.append, dir_separator_str,
6617 : : multilib_dir, NULL);
6618 : 214486 : else if (multiarch_dir)
6619 : : {
6620 : : /* For multiarch, search include-fixed/<multiarch-dir>
6621 : : before include-fixed. */
6622 : 0 : info.append = concat (info.append, dir_separator_str,
6623 : : multiarch_dir, NULL);
6624 : 0 : info.append_len = strlen (info.append);
6625 : 0 : for_each_path (&include_prefixes, false, info.append_len,
6626 : : spec_path, &info);
6627 : :
6628 : 0 : info.append = "include-fixed";
6629 : : }
6630 : 214486 : info.append_len = strlen (info.append);
6631 : 214486 : for_each_path (&include_prefixes, false, info.append_len,
6632 : : spec_path, &info);
6633 : : }
6634 : 214486 : break;
6635 : :
6636 : 92511 : case 'o':
6637 : : /* We are going to expand `%o' into `@FILE', where FILE
6638 : : is a newly-created temporary filename. The filenames
6639 : : that would usually be expanded in place of %o will be
6640 : : written to the temporary file. */
6641 : 92511 : if (at_file_supplied)
6642 : 6 : open_at_file ();
6643 : :
6644 : 412800 : for (i = 0; i < n_infiles + lang_specific_extra_outfiles; i++)
6645 : 320289 : if (outfiles[i])
6646 : 320249 : store_arg (outfiles[i], 0, 0);
6647 : :
6648 : 92511 : if (at_file_supplied)
6649 : 6 : close_at_file ();
6650 : : break;
6651 : :
6652 : 3710 : case 'O':
6653 : 3710 : obstack_grow (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX));
6654 : 3710 : arg_going = 1;
6655 : 3710 : break;
6656 : :
6657 : 523301 : case 's':
6658 : 523301 : this_is_library_file = 1;
6659 : 523301 : break;
6660 : :
6661 : 0 : case 'T':
6662 : 0 : this_is_linker_script = 1;
6663 : 0 : break;
6664 : :
6665 : 422 : case 'V':
6666 : 422 : outfiles[input_file_number] = NULL;
6667 : 422 : break;
6668 : :
6669 : 97367 : case 'w':
6670 : 97367 : this_is_output_file = 1;
6671 : 97367 : break;
6672 : :
6673 : 168460 : case 'W':
6674 : 168460 : {
6675 : 168460 : unsigned int cur_index = argbuf.length ();
6676 : : /* Handle the {...} following the %W. */
6677 : 168460 : if (*p != '{')
6678 : 0 : fatal_error (input_location,
6679 : : "spec %qs has invalid %<%%W%c%>", spec, *p);
6680 : 168460 : p = handle_braces (p + 1);
6681 : 168460 : if (p == 0)
6682 : : return -1;
6683 : 168460 : end_going_arg ();
6684 : : /* If any args were output, mark the last one for deletion
6685 : : on failure. */
6686 : 336920 : if (argbuf.length () != cur_index)
6687 : 165319 : record_temp_file (argbuf.last (), 0, 1);
6688 : : break;
6689 : : }
6690 : :
6691 : 292433 : case '@':
6692 : : /* Handle the {...} following the %@. */
6693 : 292433 : if (*p != '{')
6694 : 0 : fatal_error (input_location,
6695 : : "spec %qs has invalid %<%%@%c%>", spec, *p);
6696 : 292433 : if (at_file_supplied)
6697 : 15 : open_at_file ();
6698 : 292433 : p = handle_braces (p + 1);
6699 : 292433 : if (at_file_supplied)
6700 : 15 : close_at_file ();
6701 : 292433 : if (p == 0)
6702 : : return -1;
6703 : : break;
6704 : :
6705 : : /* %x{OPTION} records OPTION for %X to output. */
6706 : 0 : case 'x':
6707 : 0 : {
6708 : 0 : const char *p1 = p;
6709 : 0 : char *string;
6710 : :
6711 : : /* Skip past the option value and make a copy. */
6712 : 0 : if (*p != '{')
6713 : 0 : fatal_error (input_location,
6714 : : "spec %qs has invalid %<%%x%c%>", spec, *p);
6715 : 0 : while (*p++ != '}')
6716 : : ;
6717 : 0 : string = save_string (p1 + 1, p - p1 - 2);
6718 : :
6719 : : /* See if we already recorded this option. */
6720 : 0 : for (const char *opt : linker_options)
6721 : 0 : if (! strcmp (string, opt))
6722 : : {
6723 : 0 : free (string);
6724 : 0 : return 0;
6725 : : }
6726 : :
6727 : : /* This option is new; add it. */
6728 : 0 : add_linker_option (string, strlen (string));
6729 : 0 : free (string);
6730 : : }
6731 : 0 : break;
6732 : :
6733 : : /* Dump out the options accumulated previously using %x. */
6734 : 92511 : case 'X':
6735 : 92511 : do_specs_vec (linker_options);
6736 : 92511 : break;
6737 : :
6738 : : /* Dump out the options accumulated previously using -Wa,. */
6739 : 157592 : case 'Y':
6740 : 157592 : do_specs_vec (assembler_options);
6741 : 157592 : break;
6742 : :
6743 : : /* Dump out the options accumulated previously using -Wp,. */
6744 : 199922 : case 'Z':
6745 : 199922 : do_specs_vec (preprocessor_options);
6746 : 199922 : break;
6747 : :
6748 : : /* Here are digits and numbers that just process
6749 : : a certain constant string as a spec. */
6750 : :
6751 : 274294 : case '1':
6752 : 274294 : value = do_spec_1 (cc1_spec, 0, NULL);
6753 : 274294 : if (value != 0)
6754 : : return value;
6755 : : break;
6756 : :
6757 : 94130 : case '2':
6758 : 94130 : value = do_spec_1 (cc1plus_spec, 0, NULL);
6759 : 94130 : if (value != 0)
6760 : : return value;
6761 : : break;
6762 : :
6763 : 157592 : case 'a':
6764 : 157592 : value = do_spec_1 (asm_spec, 0, NULL);
6765 : 157592 : if (value != 0)
6766 : : return value;
6767 : : break;
6768 : :
6769 : 157592 : case 'A':
6770 : 157592 : value = do_spec_1 (asm_final_spec, 0, NULL);
6771 : 157592 : if (value != 0)
6772 : : return value;
6773 : : break;
6774 : :
6775 : 199922 : case 'C':
6776 : 199922 : {
6777 : 399844 : const char *const spec
6778 : 199922 : = (input_file_compiler->cpp_spec
6779 : 199922 : ? input_file_compiler->cpp_spec
6780 : : : cpp_spec);
6781 : 199922 : value = do_spec_1 (spec, 0, NULL);
6782 : 199922 : if (value != 0)
6783 : : return value;
6784 : : }
6785 : : break;
6786 : :
6787 : 92306 : case 'E':
6788 : 92306 : value = do_spec_1 (endfile_spec, 0, NULL);
6789 : 92306 : if (value != 0)
6790 : : return value;
6791 : : break;
6792 : :
6793 : 92511 : case 'l':
6794 : 92511 : value = do_spec_1 (link_spec, 0, NULL);
6795 : 92511 : if (value != 0)
6796 : : return value;
6797 : : break;
6798 : :
6799 : 179299 : case 'L':
6800 : 179299 : value = do_spec_1 (lib_spec, 0, NULL);
6801 : 179299 : if (value != 0)
6802 : : return value;
6803 : : break;
6804 : :
6805 : 0 : case 'M':
6806 : 0 : if (multilib_os_dir == NULL)
6807 : 0 : obstack_1grow (&obstack, '.');
6808 : : else
6809 : 0 : obstack_grow (&obstack, multilib_os_dir,
6810 : : strlen (multilib_os_dir));
6811 : : break;
6812 : :
6813 : 358402 : case 'G':
6814 : 358402 : value = do_spec_1 (libgcc_spec, 0, NULL);
6815 : 358402 : if (value != 0)
6816 : : return value;
6817 : : break;
6818 : :
6819 : 0 : case 'R':
6820 : : /* We assume there is a directory
6821 : : separator at the end of this string. */
6822 : 0 : if (target_system_root)
6823 : : {
6824 : 0 : obstack_grow (&obstack, target_system_root,
6825 : : strlen (target_system_root));
6826 : 0 : if (target_sysroot_suffix)
6827 : 0 : obstack_grow (&obstack, target_sysroot_suffix,
6828 : : strlen (target_sysroot_suffix));
6829 : : }
6830 : : break;
6831 : :
6832 : 92306 : case 'S':
6833 : 92306 : value = do_spec_1 (startfile_spec, 0, NULL);
6834 : 92306 : if (value != 0)
6835 : : return value;
6836 : : break;
6837 : :
6838 : : /* Here we define characters other than letters and digits. */
6839 : :
6840 : 38517148 : case '{':
6841 : 38517148 : p = handle_braces (p);
6842 : 38517148 : if (p == 0)
6843 : : return -1;
6844 : : break;
6845 : :
6846 : 423377 : case ':':
6847 : 423377 : p = handle_spec_function (p, NULL, soft_matched_part);
6848 : 423377 : if (p == 0)
6849 : : return -1;
6850 : : break;
6851 : :
6852 : 0 : case '%':
6853 : 0 : obstack_1grow (&obstack, '%');
6854 : 0 : break;
6855 : :
6856 : : case '.':
6857 : : {
6858 : : unsigned len = 0;
6859 : :
6860 : 11778 : while (p[len] && p[len] != ' ' && p[len] != '%')
6861 : 5907 : len++;
6862 : 5871 : suffix_subst = save_string (p - 1, len + 1);
6863 : 5871 : p += len;
6864 : : }
6865 : 5871 : break;
6866 : :
6867 : : /* Henceforth ignore the option(s) matching the pattern
6868 : : after the %<. */
6869 : 1410902 : case '<':
6870 : 1410902 : case '>':
6871 : 1410902 : {
6872 : 1410902 : unsigned len = 0;
6873 : 1410902 : int have_wildcard = 0;
6874 : 1410902 : int i;
6875 : 1410902 : int switch_option;
6876 : :
6877 : 1410902 : if (c == '>')
6878 : 1410902 : switch_option = SWITCH_IGNORE | SWITCH_KEEP_FOR_GCC;
6879 : : else
6880 : 1410880 : switch_option = SWITCH_IGNORE;
6881 : :
6882 : 17027726 : while (p[len] && p[len] != ' ' && p[len] != '\t')
6883 : 15616824 : len++;
6884 : :
6885 : 1410902 : if (p[len-1] == '*')
6886 : 14229 : have_wildcard = 1;
6887 : :
6888 : 32415069 : for (i = 0; i < n_switches; i++)
6889 : 31004167 : if (!strncmp (switches[i].part1, p, len - have_wildcard)
6890 : 44030 : && (have_wildcard || switches[i].part1[len] == '\0'))
6891 : : {
6892 : 43763 : switches[i].live_cond |= switch_option;
6893 : : /* User switch be validated from validate_all_switches.
6894 : : when the definition is seen from the spec file.
6895 : : If not defined anywhere, will be rejected. */
6896 : 43763 : if (switches[i].known)
6897 : 43763 : switches[i].validated = true;
6898 : : }
6899 : :
6900 : : p += len;
6901 : : }
6902 : : break;
6903 : :
6904 : 6729 : case '*':
6905 : 6729 : if (soft_matched_part)
6906 : : {
6907 : 6729 : if (soft_matched_part[0])
6908 : 323 : do_spec_1 (soft_matched_part, 1, NULL);
6909 : : /* Only insert a space after the substitution if it is at the
6910 : : end of the current sequence. So if:
6911 : :
6912 : : "%{foo=*:bar%*}%{foo=*:one%*two}"
6913 : :
6914 : : matches -foo=hello then it will produce:
6915 : :
6916 : : barhello onehellotwo
6917 : : */
6918 : 6729 : if (*p == 0 || *p == '}')
6919 : 6729 : do_spec_1 (" ", 0, NULL);
6920 : : }
6921 : : else
6922 : : /* Catch the case where a spec string contains something like
6923 : : '%{foo:%*}'. i.e. there is no * in the pattern on the left
6924 : : hand side of the :. */
6925 : 0 : error ("spec failure: %<%%*%> has not been initialized by pattern match");
6926 : : break;
6927 : :
6928 : : /* Process a string found as the value of a spec given by name.
6929 : : This feature allows individual machine descriptions
6930 : : to add and use their own specs. */
6931 : : case '(':
6932 : : {
6933 : 32093457 : const char *name = p;
6934 : : struct spec_list *sl;
6935 : : int len;
6936 : :
6937 : : /* The string after the S/P is the name of a spec that is to be
6938 : : processed. */
6939 : 32093457 : while (*p && *p != ')')
6940 : 29617876 : p++;
6941 : :
6942 : : /* See if it's in the list. */
6943 : 34039668 : for (len = p - name, sl = specs; sl; sl = sl->next)
6944 : 34039668 : if (sl->name_len == len && !strncmp (sl->name, name, len))
6945 : : {
6946 : 2475581 : name = *(sl->ptr_spec);
6947 : : #ifdef DEBUG_SPECS
6948 : : fnotice (stderr, "Processing spec (%s), which is '%s'\n",
6949 : : sl->name, name);
6950 : : #endif
6951 : 2475581 : break;
6952 : : }
6953 : :
6954 : 2475581 : if (sl)
6955 : : {
6956 : 2475581 : value = do_spec_1 (name, 0, NULL);
6957 : 2475581 : if (value != 0)
6958 : : return value;
6959 : : }
6960 : :
6961 : : /* Discard the closing paren. */
6962 : 2470468 : if (*p)
6963 : 2470468 : p++;
6964 : : }
6965 : : break;
6966 : :
6967 : 9 : case '"':
6968 : : /* End a previous argument, if there is one, then issue an
6969 : : empty argument. */
6970 : 9 : end_going_arg ();
6971 : 9 : arg_going = 1;
6972 : 9 : end_going_arg ();
6973 : 9 : break;
6974 : :
6975 : 0 : default:
6976 : 0 : error ("spec failure: unrecognized spec option %qc", c);
6977 : 0 : break;
6978 : : }
6979 : : break;
6980 : :
6981 : 0 : case '\\':
6982 : : /* Backslash: treat next character as ordinary. */
6983 : 0 : c = *p++;
6984 : :
6985 : : /* When adding more cases that previously matched default, make
6986 : : sure to adjust quote_spec_char_p as well. */
6987 : :
6988 : : /* Fall through. */
6989 : 336787934 : default:
6990 : : /* Ordinary character: put it into the current argument. */
6991 : 336787934 : obstack_1grow (&obstack, c);
6992 : 336787934 : arg_going = 1;
6993 : : }
6994 : :
6995 : : /* End of string. If we are processing a spec function, we need to
6996 : : end any pending argument. */
6997 : 49830276 : if (processing_spec_function)
6998 : 4271929 : end_going_arg ();
6999 : :
7000 : : return 0;
7001 : : }
7002 : :
7003 : : /* Look up a spec function. */
7004 : :
7005 : : static const struct spec_function *
7006 : 2003493 : lookup_spec_function (const char *name)
7007 : : {
7008 : 2003493 : const struct spec_function *sf;
7009 : :
7010 : 23978667 : for (sf = static_spec_functions; sf->name != NULL; sf++)
7011 : 23978667 : if (strcmp (sf->name, name) == 0)
7012 : : return sf;
7013 : :
7014 : : return NULL;
7015 : : }
7016 : :
7017 : : /* Evaluate a spec function. */
7018 : :
7019 : : static const char *
7020 : 2003493 : eval_spec_function (const char *func, const char *args,
7021 : : const char *soft_matched_part)
7022 : : {
7023 : 2003493 : const struct spec_function *sf;
7024 : 2003493 : const char *funcval;
7025 : :
7026 : : /* Saved spec processing context. */
7027 : 2003493 : vec<const_char_p> save_argbuf;
7028 : :
7029 : 2003493 : int save_arg_going;
7030 : 2003493 : int save_delete_this_arg;
7031 : 2003493 : int save_this_is_output_file;
7032 : 2003493 : int save_this_is_library_file;
7033 : 2003493 : int save_input_from_pipe;
7034 : 2003493 : int save_this_is_linker_script;
7035 : 2003493 : const char *save_suffix_subst;
7036 : :
7037 : 2003493 : int save_growing_size;
7038 : 2003493 : void *save_growing_value = NULL;
7039 : :
7040 : 2003493 : sf = lookup_spec_function (func);
7041 : 2003493 : if (sf == NULL)
7042 : 0 : fatal_error (input_location, "unknown spec function %qs", func);
7043 : :
7044 : : /* Push the spec processing context. */
7045 : 2003493 : save_argbuf = argbuf;
7046 : :
7047 : 2003493 : save_arg_going = arg_going;
7048 : 2003493 : save_delete_this_arg = delete_this_arg;
7049 : 2003493 : save_this_is_output_file = this_is_output_file;
7050 : 2003493 : save_this_is_library_file = this_is_library_file;
7051 : 2003493 : save_this_is_linker_script = this_is_linker_script;
7052 : 2003493 : save_input_from_pipe = input_from_pipe;
7053 : 2003493 : save_suffix_subst = suffix_subst;
7054 : :
7055 : : /* If we have some object growing now, finalize it so the args and function
7056 : : eval proceed from a cleared context. This is needed to prevent the first
7057 : : constructed arg from mistakenly including the growing value. We'll push
7058 : : this value back on the obstack once the function evaluation is done, to
7059 : : restore a consistent processing context for our caller. This is fine as
7060 : : the address of growing objects isn't guaranteed to remain stable until
7061 : : they are finalized, and we expect this situation to be rare enough for
7062 : : the extra copy not to be an issue. */
7063 : 2003493 : save_growing_size = obstack_object_size (&obstack);
7064 : 2003493 : if (save_growing_size > 0)
7065 : 41603 : save_growing_value = obstack_finish (&obstack);
7066 : :
7067 : : /* Create a new spec processing context, and build the function
7068 : : arguments. */
7069 : :
7070 : 2003493 : alloc_args ();
7071 : 2003493 : if (do_spec_2 (args, soft_matched_part) < 0)
7072 : 0 : fatal_error (input_location, "error in arguments to spec function %qs",
7073 : : func);
7074 : :
7075 : : /* argbuf_index is an index for the next argument to be inserted, and
7076 : : so contains the count of the args already inserted. */
7077 : :
7078 : 6010479 : funcval = (*sf->func) (argbuf.length (),
7079 : : argbuf.address ());
7080 : :
7081 : : /* Pop the spec processing context. */
7082 : 2003493 : argbuf.release ();
7083 : 2003493 : argbuf = save_argbuf;
7084 : :
7085 : 2003493 : arg_going = save_arg_going;
7086 : 2003493 : delete_this_arg = save_delete_this_arg;
7087 : 2003493 : this_is_output_file = save_this_is_output_file;
7088 : 2003493 : this_is_library_file = save_this_is_library_file;
7089 : 2003493 : this_is_linker_script = save_this_is_linker_script;
7090 : 2003493 : input_from_pipe = save_input_from_pipe;
7091 : 2003493 : suffix_subst = save_suffix_subst;
7092 : :
7093 : 2003493 : if (save_growing_size > 0)
7094 : 41603 : obstack_grow (&obstack, save_growing_value, save_growing_size);
7095 : :
7096 : 2003493 : return funcval;
7097 : : }
7098 : :
7099 : : /* Handle a spec function call of the form:
7100 : :
7101 : : %:function(args)
7102 : :
7103 : : ARGS is processed as a spec in a separate context and split into an
7104 : : argument vector in the normal fashion. The function returns a string
7105 : : containing a spec which we then process in the caller's context, or
7106 : : NULL if no processing is required.
7107 : :
7108 : : If RETVAL_NONNULL is not NULL, then store a bool whether function
7109 : : returned non-NULL.
7110 : :
7111 : : SOFT_MATCHED_PART holds the current value of a matched * pattern, which
7112 : : may be re-expanded with a %* as part of the function arguments. */
7113 : :
7114 : : static const char *
7115 : 2003493 : handle_spec_function (const char *p, bool *retval_nonnull,
7116 : : const char *soft_matched_part)
7117 : : {
7118 : 2003493 : char *func, *args;
7119 : 2003493 : const char *endp, *funcval;
7120 : 2003493 : int count;
7121 : :
7122 : 2003493 : processing_spec_function++;
7123 : :
7124 : : /* Get the function name. */
7125 : 18647765 : for (endp = p; *endp != '\0'; endp++)
7126 : : {
7127 : 18647765 : if (*endp == '(') /* ) */
7128 : : break;
7129 : : /* Only allow [A-Za-z0-9], -, and _ in function names. */
7130 : 16644272 : if (!ISALNUM (*endp) && !(*endp == '-' || *endp == '_'))
7131 : 0 : fatal_error (input_location, "malformed spec function name");
7132 : : }
7133 : 2003493 : if (*endp != '(') /* ) */
7134 : 0 : fatal_error (input_location, "no arguments for spec function");
7135 : 2003493 : func = save_string (p, endp - p);
7136 : 2003493 : p = ++endp;
7137 : :
7138 : : /* Get the arguments. */
7139 : 24381783 : for (count = 0; *endp != '\0'; endp++)
7140 : : {
7141 : : /* ( */
7142 : 24381783 : if (*endp == ')')
7143 : : {
7144 : 2090488 : if (count == 0)
7145 : : break;
7146 : 86995 : count--;
7147 : : }
7148 : 22291295 : else if (*endp == '(') /* ) */
7149 : 86995 : count++;
7150 : : }
7151 : : /* ( */
7152 : 2003493 : if (*endp != ')')
7153 : 0 : fatal_error (input_location, "malformed spec function arguments");
7154 : 2003493 : args = save_string (p, endp - p);
7155 : 2003493 : p = ++endp;
7156 : :
7157 : : /* p now points to just past the end of the spec function expression. */
7158 : :
7159 : 2003493 : funcval = eval_spec_function (func, args, soft_matched_part);
7160 : 2003493 : if (funcval != NULL && do_spec_1 (funcval, 0, NULL) < 0)
7161 : : p = NULL;
7162 : 2003493 : if (retval_nonnull)
7163 : 1580116 : *retval_nonnull = funcval != NULL;
7164 : :
7165 : 2003493 : free (func);
7166 : 2003493 : free (args);
7167 : :
7168 : 2003493 : processing_spec_function--;
7169 : :
7170 : 2003493 : return p;
7171 : : }
7172 : :
7173 : : /* Inline subroutine of handle_braces. Returns true if the current
7174 : : input suffix matches the atom bracketed by ATOM and END_ATOM. */
7175 : : static inline bool
7176 : 0 : input_suffix_matches (const char *atom, const char *end_atom)
7177 : : {
7178 : 0 : return (input_suffix
7179 : 0 : && !strncmp (input_suffix, atom, end_atom - atom)
7180 : 0 : && input_suffix[end_atom - atom] == '\0');
7181 : : }
7182 : :
7183 : : /* Subroutine of handle_braces. Returns true if the current
7184 : : input file's spec name matches the atom bracketed by ATOM and END_ATOM. */
7185 : : static bool
7186 : 0 : input_spec_matches (const char *atom, const char *end_atom)
7187 : : {
7188 : 0 : return (input_file_compiler
7189 : 0 : && input_file_compiler->suffix
7190 : 0 : && input_file_compiler->suffix[0] != '\0'
7191 : 0 : && !strncmp (input_file_compiler->suffix + 1, atom,
7192 : 0 : end_atom - atom)
7193 : 0 : && input_file_compiler->suffix[end_atom - atom + 1] == '\0');
7194 : : }
7195 : :
7196 : : /* Subroutine of handle_braces. Returns true if a switch
7197 : : matching the atom bracketed by ATOM and END_ATOM appeared on the
7198 : : command line. */
7199 : : static bool
7200 : 37024792 : switch_matches (const char *atom, const char *end_atom, int starred)
7201 : : {
7202 : 37024792 : int i;
7203 : 37024792 : int len = end_atom - atom;
7204 : 37024792 : int plen = starred ? len : -1;
7205 : :
7206 : 836285575 : for (i = 0; i < n_switches; i++)
7207 : 800586150 : if (!strncmp (switches[i].part1, atom, len)
7208 : 2252232 : && (starred || switches[i].part1[len] == '\0')
7209 : 801912137 : && check_live_switch (i, plen))
7210 : : return true;
7211 : :
7212 : : /* Check if a switch with separated form matching the atom.
7213 : : We check -D and -U switches. */
7214 : 799260784 : else if (switches[i].args != 0)
7215 : : {
7216 : 193961997 : if ((*switches[i].part1 == 'D' || *switches[i].part1 == 'U')
7217 : 8301188 : && *switches[i].part1 == atom[0])
7218 : : {
7219 : 1 : if (!strncmp (switches[i].args[0], &atom[1], len - 1)
7220 : 1 : && (starred || (switches[i].part1[1] == '\0'
7221 : 1 : && switches[i].args[0][len - 1] == '\0'))
7222 : 2 : && check_live_switch (i, (starred ? 1 : -1)))
7223 : : return true;
7224 : : }
7225 : : }
7226 : :
7227 : : return false;
7228 : : }
7229 : :
7230 : : /* Inline subroutine of handle_braces. Mark all of the switches which
7231 : : match ATOM (extends to END_ATOM; STARRED indicates whether there
7232 : : was a star after the atom) for later processing. */
7233 : : static inline void
7234 : 10784767 : mark_matching_switches (const char *atom, const char *end_atom, int starred)
7235 : : {
7236 : 10784767 : int i;
7237 : 10784767 : int len = end_atom - atom;
7238 : 10784767 : int plen = starred ? len : -1;
7239 : :
7240 : 247142867 : for (i = 0; i < n_switches; i++)
7241 : 236358100 : if (!strncmp (switches[i].part1, atom, len)
7242 : 5856818 : && (starred || switches[i].part1[len] == '\0')
7243 : 242001534 : && check_live_switch (i, plen))
7244 : 5599681 : switches[i].ordering = 1;
7245 : 10784767 : }
7246 : :
7247 : : /* Inline subroutine of handle_braces. Process all the currently
7248 : : marked switches through give_switch, and clear the marks. */
7249 : : static inline void
7250 : 9362119 : process_marked_switches (void)
7251 : : {
7252 : 9362119 : int i;
7253 : :
7254 : 214496498 : for (i = 0; i < n_switches; i++)
7255 : 205134379 : if (switches[i].ordering == 1)
7256 : : {
7257 : 5599681 : switches[i].ordering = 0;
7258 : 5599681 : give_switch (i, 0);
7259 : : }
7260 : 9362119 : }
7261 : :
7262 : : /* Handle a %{ ... } construct. P points just inside the leading {.
7263 : : Returns a pointer one past the end of the brace block, or 0
7264 : : if we call do_spec_1 and that returns -1. */
7265 : :
7266 : : static const char *
7267 : 38978041 : handle_braces (const char *p)
7268 : : {
7269 : 38978041 : const char *atom, *end_atom;
7270 : 38978041 : const char *d_atom = NULL, *d_end_atom = NULL;
7271 : 38978041 : char *esc_buf = NULL, *d_esc_buf = NULL;
7272 : 38978041 : int esc;
7273 : 38978041 : const char *orig = p;
7274 : :
7275 : 38978041 : bool a_is_suffix;
7276 : 38978041 : bool a_is_spectype;
7277 : 38978041 : bool a_is_starred;
7278 : 38978041 : bool a_is_negated;
7279 : 38978041 : bool a_matched;
7280 : :
7281 : 38978041 : bool a_must_be_last = false;
7282 : 38978041 : bool ordered_set = false;
7283 : 38978041 : bool disjunct_set = false;
7284 : 38978041 : bool disj_matched = false;
7285 : 38978041 : bool disj_starred = true;
7286 : 38978041 : bool n_way_choice = false;
7287 : 38978041 : bool n_way_matched = false;
7288 : :
7289 : : #define SKIP_WHITE() do { while (*p == ' ' || *p == '\t') p++; } while (0)
7290 : :
7291 : 51888301 : do
7292 : : {
7293 : 51888301 : if (a_must_be_last)
7294 : 0 : goto invalid;
7295 : :
7296 : : /* Scan one "atom" (S in the description above of %{}, possibly
7297 : : with '!', '.', '@', ',', or '*' modifiers). */
7298 : 51888301 : a_matched = false;
7299 : 51888301 : a_is_suffix = false;
7300 : 51888301 : a_is_starred = false;
7301 : 51888301 : a_is_negated = false;
7302 : 51888301 : a_is_spectype = false;
7303 : :
7304 : 59177473 : SKIP_WHITE ();
7305 : 51888301 : if (*p == '!')
7306 : 12415316 : p++, a_is_negated = true;
7307 : :
7308 : 51888301 : SKIP_WHITE ();
7309 : 51888301 : if (*p == '%' && p[1] == ':')
7310 : : {
7311 : 1580116 : atom = NULL;
7312 : 1580116 : end_atom = NULL;
7313 : 1580116 : p = handle_spec_function (p + 2, &a_matched, NULL);
7314 : : }
7315 : : else
7316 : : {
7317 : 50308185 : if (*p == '.')
7318 : 0 : p++, a_is_suffix = true;
7319 : 50308185 : else if (*p == ',')
7320 : 0 : p++, a_is_spectype = true;
7321 : :
7322 : 50308185 : atom = p;
7323 : 50308185 : esc = 0;
7324 : 50308185 : while (ISIDNUM (*p) || *p == '-' || *p == '+' || *p == '='
7325 : 377338838 : || *p == ',' || *p == '.' || *p == '@' || *p == '\\')
7326 : : {
7327 : 327030653 : if (*p == '\\')
7328 : : {
7329 : 0 : p++;
7330 : 0 : if (!*p)
7331 : 0 : fatal_error (input_location,
7332 : : "braced spec %qs ends in escape", orig);
7333 : 0 : esc++;
7334 : : }
7335 : 327030653 : p++;
7336 : : }
7337 : 50308185 : end_atom = p;
7338 : :
7339 : 50308185 : if (esc)
7340 : : {
7341 : 0 : const char *ap;
7342 : 0 : char *ep;
7343 : :
7344 : 0 : if (esc_buf && esc_buf != d_esc_buf)
7345 : 0 : free (esc_buf);
7346 : 0 : esc_buf = NULL;
7347 : 0 : ep = esc_buf = (char *) xmalloc (end_atom - atom - esc + 1);
7348 : 0 : for (ap = atom; ap != end_atom; ap++, ep++)
7349 : : {
7350 : 0 : if (*ap == '\\')
7351 : 0 : ap++;
7352 : 0 : *ep = *ap;
7353 : : }
7354 : 0 : *ep = '\0';
7355 : 0 : atom = esc_buf;
7356 : 0 : end_atom = ep;
7357 : : }
7358 : :
7359 : 50308185 : if (*p == '*')
7360 : 11363616 : p++, a_is_starred = 1;
7361 : : }
7362 : :
7363 : 51888301 : SKIP_WHITE ();
7364 : 51888301 : switch (*p)
7365 : : {
7366 : 10784767 : case '&': case '}':
7367 : : /* Substitute the switch(es) indicated by the current atom. */
7368 : 10784767 : ordered_set = true;
7369 : 10784767 : if (disjunct_set || n_way_choice || a_is_negated || a_is_suffix
7370 : 10784767 : || a_is_spectype || atom == end_atom)
7371 : 0 : goto invalid;
7372 : :
7373 : 10784767 : mark_matching_switches (atom, end_atom, a_is_starred);
7374 : :
7375 : 10784767 : if (*p == '}')
7376 : 9362119 : process_marked_switches ();
7377 : : break;
7378 : :
7379 : 41103534 : case '|': case ':':
7380 : : /* Substitute some text if the current atom appears as a switch
7381 : : or suffix. */
7382 : 41103534 : disjunct_set = true;
7383 : 41103534 : if (ordered_set)
7384 : 0 : goto invalid;
7385 : :
7386 : 41103534 : if (atom && atom == end_atom)
7387 : : {
7388 : 1710236 : if (!n_way_choice || disj_matched || *p == '|'
7389 : 1710236 : || a_is_negated || a_is_suffix || a_is_spectype
7390 : 1710236 : || a_is_starred)
7391 : 0 : goto invalid;
7392 : :
7393 : : /* An empty term may appear as the last choice of an
7394 : : N-way choice set; it means "otherwise". */
7395 : 1710236 : a_must_be_last = true;
7396 : 1710236 : disj_matched = !n_way_matched;
7397 : 1710236 : disj_starred = false;
7398 : : }
7399 : : else
7400 : : {
7401 : 39393298 : if ((a_is_suffix || a_is_spectype) && a_is_starred)
7402 : 0 : goto invalid;
7403 : :
7404 : 39393298 : if (!a_is_starred)
7405 : 34025648 : disj_starred = false;
7406 : :
7407 : : /* Don't bother testing this atom if we already have a
7408 : : match. */
7409 : 39393298 : if (!disj_matched && !n_way_matched)
7410 : : {
7411 : 38411511 : if (atom == NULL)
7412 : : /* a_matched is already set by handle_spec_function. */;
7413 : 36932277 : else if (a_is_suffix)
7414 : 0 : a_matched = input_suffix_matches (atom, end_atom);
7415 : 36932277 : else if (a_is_spectype)
7416 : 0 : a_matched = input_spec_matches (atom, end_atom);
7417 : : else
7418 : 36932277 : a_matched = switch_matches (atom, end_atom, a_is_starred);
7419 : :
7420 : 38411511 : if (a_matched != a_is_negated)
7421 : : {
7422 : 12299999 : disj_matched = true;
7423 : 12299999 : d_atom = atom;
7424 : 12299999 : d_end_atom = end_atom;
7425 : 12299999 : d_esc_buf = esc_buf;
7426 : : }
7427 : : }
7428 : : }
7429 : :
7430 : 41103534 : if (*p == ':')
7431 : : {
7432 : : /* Found the body, that is, the text to substitute if the
7433 : : current disjunction matches. */
7434 : 65035110 : p = process_brace_body (p + 1, d_atom, d_end_atom, disj_starred,
7435 : 32517555 : disj_matched && !n_way_matched);
7436 : 32517555 : if (p == 0)
7437 : 34067 : goto done;
7438 : :
7439 : : /* If we have an N-way choice, reset state for the next
7440 : : disjunction. */
7441 : 32483488 : if (*p == ';')
7442 : : {
7443 : 2901633 : n_way_choice = true;
7444 : 2901633 : n_way_matched |= disj_matched;
7445 : 2901633 : disj_matched = false;
7446 : 2901633 : disj_starred = true;
7447 : 2901633 : d_atom = d_end_atom = NULL;
7448 : : }
7449 : : }
7450 : : break;
7451 : :
7452 : 0 : default:
7453 : 0 : goto invalid;
7454 : : }
7455 : : }
7456 : 51854234 : while (*p++ != '}');
7457 : :
7458 : 38943974 : done:
7459 : 38978041 : if (d_esc_buf && d_esc_buf != esc_buf)
7460 : 0 : free (d_esc_buf);
7461 : 38978041 : if (esc_buf)
7462 : 0 : free (esc_buf);
7463 : :
7464 : 38978041 : return p;
7465 : :
7466 : 0 : invalid:
7467 : 0 : fatal_error (input_location, "braced spec %qs is invalid at %qc", orig, *p);
7468 : :
7469 : : #undef SKIP_WHITE
7470 : : }
7471 : :
7472 : : /* Subroutine of handle_braces. Scan and process a brace substitution body
7473 : : (X in the description of %{} syntax). P points one past the colon;
7474 : : ATOM and END_ATOM bracket the first atom which was found to be true
7475 : : (present) in the current disjunction; STARRED indicates whether all
7476 : : the atoms in the current disjunction were starred (for syntax validation);
7477 : : MATCHED indicates whether the disjunction matched or not, and therefore
7478 : : whether or not the body is to be processed through do_spec_1 or just
7479 : : skipped. Returns a pointer to the closing } or ;, or 0 if do_spec_1
7480 : : returns -1. */
7481 : :
7482 : : static const char *
7483 : 32517555 : process_brace_body (const char *p, const char *atom, const char *end_atom,
7484 : : int starred, int matched)
7485 : : {
7486 : 32517555 : const char *body, *end_body;
7487 : 32517555 : unsigned int nesting_level;
7488 : 32517555 : bool have_subst = false;
7489 : :
7490 : : /* Locate the closing } or ;, honoring nested braces.
7491 : : Trim trailing whitespace. */
7492 : 32517555 : body = p;
7493 : 32517555 : nesting_level = 1;
7494 : 11107757583 : for (;;)
7495 : : {
7496 : 5570137569 : if (*p == '{')
7497 : 164897593 : nesting_level++;
7498 : 5405239976 : else if (*p == '}')
7499 : : {
7500 : 194513515 : if (!--nesting_level)
7501 : : break;
7502 : : }
7503 : 5210726461 : else if (*p == ';' && nesting_level == 1)
7504 : : break;
7505 : 5207824828 : else if (*p == '%' && p[1] == '*' && nesting_level == 1)
7506 : : have_subst = true;
7507 : 5207068489 : else if (*p == '\0')
7508 : 0 : goto invalid;
7509 : 5537620014 : p++;
7510 : : }
7511 : :
7512 : : end_body = p;
7513 : 35188719 : while (end_body[-1] == ' ' || end_body[-1] == '\t')
7514 : 2671164 : end_body--;
7515 : :
7516 : 32517555 : if (have_subst && !starred)
7517 : 0 : goto invalid;
7518 : :
7519 : 32517555 : if (matched)
7520 : : {
7521 : : /* Copy the substitution body to permanent storage and execute it.
7522 : : If have_subst is false, this is a simple matter of running the
7523 : : body through do_spec_1... */
7524 : 13222735 : char *string = save_string (body, end_body - body);
7525 : 13222735 : if (!have_subst)
7526 : : {
7527 : 13216010 : if (do_spec_1 (string, 0, NULL) < 0)
7528 : : {
7529 : 34067 : free (string);
7530 : 34067 : return 0;
7531 : : }
7532 : : }
7533 : : else
7534 : : {
7535 : : /* ... but if have_subst is true, we have to process the
7536 : : body once for each matching switch, with %* set to the
7537 : : variant part of the switch. */
7538 : 6725 : unsigned int hard_match_len = end_atom - atom;
7539 : 6725 : int i;
7540 : :
7541 : 269678 : for (i = 0; i < n_switches; i++)
7542 : 262953 : if (!strncmp (switches[i].part1, atom, hard_match_len)
7543 : 262953 : && check_live_switch (i, hard_match_len))
7544 : : {
7545 : 6729 : if (do_spec_1 (string, 0,
7546 : : &switches[i].part1[hard_match_len]) < 0)
7547 : : {
7548 : 0 : free (string);
7549 : 0 : return 0;
7550 : : }
7551 : : /* Pass any arguments this switch has. */
7552 : 6729 : give_switch (i, 1);
7553 : 6729 : suffix_subst = NULL;
7554 : : }
7555 : : }
7556 : 13188668 : free (string);
7557 : : }
7558 : :
7559 : : return p;
7560 : :
7561 : 0 : invalid:
7562 : 0 : fatal_error (input_location, "braced spec body %qs is invalid", body);
7563 : : }
7564 : :
7565 : : /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
7566 : : on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
7567 : : spec, or -1 if either exact match or %* is used.
7568 : :
7569 : : A -O switch is obsoleted by a later -O switch. A -f, -g, -m, or -W switch
7570 : : whose value does not begin with "no-" is obsoleted by the same value
7571 : : with the "no-", similarly for a switch with the "no-" prefix. */
7572 : :
7573 : : static int
7574 : 6976151 : check_live_switch (int switchnum, int prefix_length)
7575 : : {
7576 : 6976151 : const char *name = switches[switchnum].part1;
7577 : 6976151 : int i;
7578 : :
7579 : : /* If we already processed this switch and determined if it was
7580 : : live or not, return our past determination. */
7581 : 6976151 : if (switches[switchnum].live_cond != 0)
7582 : 914130 : return ((switches[switchnum].live_cond & SWITCH_LIVE) != 0
7583 : : && (switches[switchnum].live_cond & SWITCH_FALSE) == 0
7584 : 914130 : && (switches[switchnum].live_cond & SWITCH_IGNORE_PERMANENTLY)
7585 : 914130 : == 0);
7586 : :
7587 : : /* In the common case of {<at-most-one-letter>*}, a negating
7588 : : switch would always match, so ignore that case. We will just
7589 : : send the conflicting switches to the compiler phase. */
7590 : 6062021 : if (prefix_length >= 0 && prefix_length <= 1)
7591 : : return 1;
7592 : :
7593 : : /* Now search for duplicate in a manner that depends on the name. */
7594 : 852151 : switch (*name)
7595 : : {
7596 : 62 : case 'O':
7597 : 344 : for (i = switchnum + 1; i < n_switches; i++)
7598 : 287 : if (switches[i].part1[0] == 'O')
7599 : : {
7600 : 5 : switches[switchnum].validated = true;
7601 : 5 : switches[switchnum].live_cond = SWITCH_FALSE;
7602 : 5 : return 0;
7603 : : }
7604 : : break;
7605 : :
7606 : 271047 : case 'W': case 'f': case 'm': case 'g':
7607 : 271047 : if (startswith (name + 1, "no-"))
7608 : : {
7609 : : /* We have Xno-YYY, search for XYYY. */
7610 : 33831 : for (i = switchnum + 1; i < n_switches; i++)
7611 : 28478 : if (switches[i].part1[0] == name[0]
7612 : 5457 : && ! strcmp (&switches[i].part1[1], &name[4]))
7613 : : {
7614 : : /* --specs are validated with the validate_switches mechanism. */
7615 : 0 : if (switches[switchnum].known)
7616 : 0 : switches[switchnum].validated = true;
7617 : 0 : switches[switchnum].live_cond = SWITCH_FALSE;
7618 : 0 : return 0;
7619 : : }
7620 : : }
7621 : : else
7622 : : {
7623 : : /* We have XYYY, search for Xno-YYY. */
7624 : 2811946 : for (i = switchnum + 1; i < n_switches; i++)
7625 : 2546252 : if (switches[i].part1[0] == name[0]
7626 : 1552999 : && switches[i].part1[1] == 'n'
7627 : 195129 : && switches[i].part1[2] == 'o'
7628 : 195128 : && switches[i].part1[3] == '-'
7629 : 195098 : && !strcmp (&switches[i].part1[4], &name[1]))
7630 : : {
7631 : : /* --specs are validated with the validate_switches mechanism. */
7632 : 0 : if (switches[switchnum].known)
7633 : 0 : switches[switchnum].validated = true;
7634 : 0 : switches[switchnum].live_cond = SWITCH_FALSE;
7635 : 0 : return 0;
7636 : : }
7637 : : }
7638 : : break;
7639 : : }
7640 : :
7641 : : /* Otherwise the switch is live. */
7642 : 852146 : switches[switchnum].live_cond |= SWITCH_LIVE;
7643 : 852146 : return 1;
7644 : : }
7645 : :
7646 : : /* Pass a switch to the current accumulating command
7647 : : in the same form that we received it.
7648 : : SWITCHNUM identifies the switch; it is an index into
7649 : : the vector of switches gcc received, which is `switches'.
7650 : : This cannot fail since it never finishes a command line.
7651 : :
7652 : : If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */
7653 : :
7654 : : static void
7655 : 5606410 : give_switch (int switchnum, int omit_first_word)
7656 : : {
7657 : 5606410 : if ((switches[switchnum].live_cond & SWITCH_IGNORE) != 0)
7658 : : return;
7659 : :
7660 : 5606399 : if (!omit_first_word)
7661 : : {
7662 : 5599670 : do_spec_1 ("-", 0, NULL);
7663 : 5599670 : do_spec_1 (switches[switchnum].part1, 1, NULL);
7664 : : }
7665 : :
7666 : 5606399 : if (switches[switchnum].args != 0)
7667 : : {
7668 : : const char **p;
7669 : 2395930 : for (p = switches[switchnum].args; *p; p++)
7670 : : {
7671 : 1197965 : const char *arg = *p;
7672 : :
7673 : 1197965 : do_spec_1 (" ", 0, NULL);
7674 : 1197965 : if (suffix_subst)
7675 : : {
7676 : 5871 : unsigned length = strlen (arg);
7677 : 5871 : int dot = 0;
7678 : :
7679 : 11742 : while (length-- && !IS_DIR_SEPARATOR (arg[length]))
7680 : 11742 : if (arg[length] == '.')
7681 : : {
7682 : 5871 : (CONST_CAST (char *, arg))[length] = 0;
7683 : 5871 : dot = 1;
7684 : 5871 : break;
7685 : : }
7686 : 5871 : do_spec_1 (arg, 1, NULL);
7687 : 5871 : if (dot)
7688 : 5871 : (CONST_CAST (char *, arg))[length] = '.';
7689 : 5871 : do_spec_1 (suffix_subst, 1, NULL);
7690 : : }
7691 : : else
7692 : 1192094 : do_spec_1 (arg, 1, NULL);
7693 : : }
7694 : : }
7695 : :
7696 : 5606399 : do_spec_1 (" ", 0, NULL);
7697 : 5606399 : switches[switchnum].validated = true;
7698 : : }
7699 : :
7700 : : /* Print GCC configuration (e.g. version, thread model, target,
7701 : : configuration_arguments) to a given FILE. */
7702 : :
7703 : : static void
7704 : 1358 : print_configuration (FILE *file)
7705 : : {
7706 : 1358 : int n;
7707 : 1358 : const char *thrmod;
7708 : :
7709 : 1358 : fnotice (file, "Target: %s\n", spec_machine);
7710 : 1358 : fnotice (file, "Configured with: %s\n", configuration_arguments);
7711 : :
7712 : : #ifdef THREAD_MODEL_SPEC
7713 : : /* We could have defined THREAD_MODEL_SPEC to "%*" by default,
7714 : : but there's no point in doing all this processing just to get
7715 : : thread_model back. */
7716 : : obstack_init (&obstack);
7717 : : do_spec_1 (THREAD_MODEL_SPEC, 0, thread_model);
7718 : : obstack_1grow (&obstack, '\0');
7719 : : thrmod = XOBFINISH (&obstack, const char *);
7720 : : #else
7721 : 1358 : thrmod = thread_model;
7722 : : #endif
7723 : :
7724 : 1358 : fnotice (file, "Thread model: %s\n", thrmod);
7725 : 1358 : fnotice (file, "Supported LTO compression algorithms: zlib");
7726 : : #ifdef HAVE_ZSTD_H
7727 : 1358 : fnotice (file, " zstd");
7728 : : #endif
7729 : 1358 : fnotice (file, "\n");
7730 : :
7731 : : /* compiler_version is truncated at the first space when initialized
7732 : : from version string, so truncate version_string at the first space
7733 : : before comparing. */
7734 : 10864 : for (n = 0; version_string[n]; n++)
7735 : 9506 : if (version_string[n] == ' ')
7736 : : break;
7737 : :
7738 : 1358 : if (! strncmp (version_string, compiler_version, n)
7739 : 1358 : && compiler_version[n] == 0)
7740 : 1358 : fnotice (file, "gcc version %s %s\n", version_string,
7741 : : pkgversion_string);
7742 : : else
7743 : 0 : fnotice (file, "gcc driver version %s %sexecuting gcc version %s\n",
7744 : : version_string, pkgversion_string, compiler_version);
7745 : :
7746 : 1358 : }
7747 : :
7748 : : #define RETRY_ICE_ATTEMPTS 3
7749 : :
7750 : : /* Returns true if FILE1 and FILE2 contain equivalent data, 0 otherwise.
7751 : : If lines start with 0x followed by 1-16 lowercase hexadecimal digits
7752 : : followed by a space, ignore anything before that space. These are
7753 : : typically function addresses from libbacktrace and those can differ
7754 : : due to ASLR. */
7755 : :
7756 : : static bool
7757 : 0 : files_equal_p (char *file1, char *file2)
7758 : : {
7759 : 0 : FILE *f1 = fopen (file1, "rb");
7760 : 0 : FILE *f2 = fopen (file2, "rb");
7761 : 0 : char line1[256], line2[256];
7762 : :
7763 : 0 : bool line_start = true;
7764 : 0 : while (fgets (line1, sizeof (line1), f1))
7765 : : {
7766 : 0 : if (!fgets (line2, sizeof (line2), f2))
7767 : 0 : goto error;
7768 : 0 : char *p1 = line1, *p2 = line2;
7769 : 0 : if (line_start
7770 : 0 : && line1[0] == '0'
7771 : 0 : && line1[1] == 'x'
7772 : 0 : && line2[0] == '0'
7773 : 0 : && line2[1] == 'x')
7774 : : {
7775 : : int i, j;
7776 : 0 : for (i = 0; i < 16; ++i)
7777 : 0 : if (!ISXDIGIT (line1[2 + i]) || ISUPPER (line1[2 + i]))
7778 : : break;
7779 : 0 : for (j = 0; j < 16; ++j)
7780 : 0 : if (!ISXDIGIT (line2[2 + j]) || ISUPPER (line2[2 + j]))
7781 : : break;
7782 : 0 : if (i && line1[2 + i] == ' ' && j && line2[2 + j] == ' ')
7783 : : {
7784 : 0 : p1 = line1 + i + 3;
7785 : 0 : p2 = line2 + j + 3;
7786 : : }
7787 : : }
7788 : 0 : if (strcmp (p1, p2) != 0)
7789 : 0 : goto error;
7790 : 0 : line_start = strchr (line1, '\n') != NULL;
7791 : : }
7792 : 0 : if (fgets (line2, sizeof (line2), f2))
7793 : 0 : goto error;
7794 : :
7795 : 0 : fclose (f1);
7796 : 0 : fclose (f2);
7797 : 0 : return 1;
7798 : :
7799 : 0 : error:
7800 : 0 : fclose (f1);
7801 : 0 : fclose (f2);
7802 : 0 : return 0;
7803 : : }
7804 : :
7805 : : /* Check that compiler's output doesn't differ across runs.
7806 : : TEMP_STDOUT_FILES and TEMP_STDERR_FILES are arrays of files, containing
7807 : : stdout and stderr for each compiler run. Return true if all of
7808 : : TEMP_STDOUT_FILES and TEMP_STDERR_FILES are equivalent. */
7809 : :
7810 : : static bool
7811 : 0 : check_repro (char **temp_stdout_files, char **temp_stderr_files)
7812 : : {
7813 : 0 : int i;
7814 : 0 : for (i = 0; i < RETRY_ICE_ATTEMPTS - 2; ++i)
7815 : : {
7816 : 0 : if (!files_equal_p (temp_stdout_files[i], temp_stdout_files[i + 1])
7817 : 0 : || !files_equal_p (temp_stderr_files[i], temp_stderr_files[i + 1]))
7818 : : {
7819 : 0 : fnotice (stderr, "The bug is not reproducible, so it is"
7820 : : " likely a hardware or OS problem.\n");
7821 : 0 : break;
7822 : : }
7823 : : }
7824 : 0 : return i == RETRY_ICE_ATTEMPTS - 2;
7825 : : }
7826 : :
7827 : : enum attempt_status {
7828 : : ATTEMPT_STATUS_FAIL_TO_RUN,
7829 : : ATTEMPT_STATUS_SUCCESS,
7830 : : ATTEMPT_STATUS_ICE
7831 : : };
7832 : :
7833 : :
7834 : : /* Run compiler with arguments NEW_ARGV to reproduce the ICE, storing stdout
7835 : : to OUT_TEMP and stderr to ERR_TEMP. If APPEND is TRUE, append to OUT_TEMP
7836 : : and ERR_TEMP instead of truncating. If EMIT_SYSTEM_INFO is TRUE, also write
7837 : : GCC configuration into to ERR_TEMP. Return ATTEMPT_STATUS_FAIL_TO_RUN if
7838 : : compiler failed to run, ATTEMPT_STATUS_ICE if compiled ICE-ed and
7839 : : ATTEMPT_STATUS_SUCCESS otherwise. */
7840 : :
7841 : : static enum attempt_status
7842 : 0 : run_attempt (const char **new_argv, const char *out_temp,
7843 : : const char *err_temp, int emit_system_info, int append)
7844 : : {
7845 : :
7846 : 0 : if (emit_system_info)
7847 : : {
7848 : 0 : FILE *file_out = fopen (err_temp, "a");
7849 : 0 : print_configuration (file_out);
7850 : 0 : fputs ("\n", file_out);
7851 : 0 : fclose (file_out);
7852 : : }
7853 : :
7854 : 0 : int exit_status;
7855 : 0 : const char *errmsg;
7856 : 0 : struct pex_obj *pex;
7857 : 0 : int err;
7858 : 0 : int pex_flags = PEX_USE_PIPES | PEX_LAST;
7859 : 0 : enum attempt_status status = ATTEMPT_STATUS_FAIL_TO_RUN;
7860 : :
7861 : 0 : if (append)
7862 : 0 : pex_flags |= PEX_STDOUT_APPEND | PEX_STDERR_APPEND;
7863 : :
7864 : 0 : pex = pex_init (PEX_USE_PIPES, new_argv[0], NULL);
7865 : 0 : if (!pex)
7866 : : fatal_error (input_location, "%<pex_init%> failed: %m");
7867 : :
7868 : 0 : errmsg = pex_run (pex, pex_flags, new_argv[0],
7869 : 0 : CONST_CAST2 (char *const *, const char **, &new_argv[1]),
7870 : : out_temp, err_temp, &err);
7871 : 0 : if (errmsg != NULL)
7872 : : {
7873 : 0 : errno = err;
7874 : 0 : fatal_error (input_location,
7875 : : err ? G_ ("cannot execute %qs: %s: %m")
7876 : : : G_ ("cannot execute %qs: %s"),
7877 : : new_argv[0], errmsg);
7878 : : }
7879 : :
7880 : 0 : if (!pex_get_status (pex, 1, &exit_status))
7881 : 0 : goto out;
7882 : :
7883 : 0 : switch (WEXITSTATUS (exit_status))
7884 : : {
7885 : : case ICE_EXIT_CODE:
7886 : 0 : status = ATTEMPT_STATUS_ICE;
7887 : : break;
7888 : :
7889 : 0 : case SUCCESS_EXIT_CODE:
7890 : 0 : status = ATTEMPT_STATUS_SUCCESS;
7891 : 0 : break;
7892 : :
7893 : 0 : default:
7894 : 0 : ;
7895 : : }
7896 : :
7897 : 0 : out:
7898 : 0 : pex_free (pex);
7899 : 0 : return status;
7900 : : }
7901 : :
7902 : : /* This routine reads lines from IN file, adds C++ style comments
7903 : : at the begining of each line and writes result into OUT. */
7904 : :
7905 : : static void
7906 : 0 : insert_comments (const char *file_in, const char *file_out)
7907 : : {
7908 : 0 : FILE *in = fopen (file_in, "rb");
7909 : 0 : FILE *out = fopen (file_out, "wb");
7910 : 0 : char line[256];
7911 : :
7912 : 0 : bool add_comment = true;
7913 : 0 : while (fgets (line, sizeof (line), in))
7914 : : {
7915 : 0 : if (add_comment)
7916 : 0 : fputs ("// ", out);
7917 : 0 : fputs (line, out);
7918 : 0 : add_comment = strchr (line, '\n') != NULL;
7919 : : }
7920 : :
7921 : 0 : fclose (in);
7922 : 0 : fclose (out);
7923 : 0 : }
7924 : :
7925 : : /* This routine adds preprocessed source code into the given ERR_FILE.
7926 : : To do this, it adds "-E" to NEW_ARGV and execute RUN_ATTEMPT routine to
7927 : : add information in report file. RUN_ATTEMPT should return
7928 : : ATTEMPT_STATUS_SUCCESS, in other case we cannot generate the report. */
7929 : :
7930 : : static void
7931 : 0 : do_report_bug (const char **new_argv, const int nargs,
7932 : : char **out_file, char **err_file)
7933 : : {
7934 : 0 : int i, status;
7935 : 0 : int fd = open (*out_file, O_RDWR | O_APPEND);
7936 : 0 : if (fd < 0)
7937 : : return;
7938 : 0 : write (fd, "\n//", 3);
7939 : 0 : for (i = 0; i < nargs; i++)
7940 : : {
7941 : 0 : write (fd, " ", 1);
7942 : 0 : write (fd, new_argv[i], strlen (new_argv[i]));
7943 : : }
7944 : 0 : write (fd, "\n\n", 2);
7945 : 0 : close (fd);
7946 : 0 : new_argv[nargs] = "-E";
7947 : 0 : new_argv[nargs + 1] = NULL;
7948 : :
7949 : 0 : status = run_attempt (new_argv, *out_file, *err_file, 0, 1);
7950 : :
7951 : 0 : if (status == ATTEMPT_STATUS_SUCCESS)
7952 : : {
7953 : 0 : fnotice (stderr, "Preprocessed source stored into %s file,"
7954 : : " please attach this to your bugreport.\n", *out_file);
7955 : : /* Make sure it is not deleted. */
7956 : 0 : free (*out_file);
7957 : 0 : *out_file = NULL;
7958 : : }
7959 : : }
7960 : :
7961 : : /* Try to reproduce ICE. If bug is reproducible, generate report .err file
7962 : : containing GCC configuration, backtrace, compiler's command line options
7963 : : and preprocessed source code. */
7964 : :
7965 : : static void
7966 : 0 : try_generate_repro (const char **argv)
7967 : : {
7968 : 0 : int i, nargs, out_arg = -1, quiet = 0, attempt;
7969 : 0 : const char **new_argv;
7970 : 0 : char *temp_files[RETRY_ICE_ATTEMPTS * 2];
7971 : 0 : char **temp_stdout_files = &temp_files[0];
7972 : 0 : char **temp_stderr_files = &temp_files[RETRY_ICE_ATTEMPTS];
7973 : :
7974 : 0 : if (gcc_input_filename == NULL || ! strcmp (gcc_input_filename, "-"))
7975 : 0 : return;
7976 : :
7977 : 0 : for (nargs = 0; argv[nargs] != NULL; ++nargs)
7978 : : /* Only retry compiler ICEs, not preprocessor ones. */
7979 : 0 : if (! strcmp (argv[nargs], "-E"))
7980 : : return;
7981 : 0 : else if (argv[nargs][0] == '-' && argv[nargs][1] == 'o')
7982 : : {
7983 : 0 : if (out_arg == -1)
7984 : : out_arg = nargs;
7985 : : else
7986 : : return;
7987 : : }
7988 : : /* If the compiler is going to output any time information,
7989 : : it might varry between invocations. */
7990 : 0 : else if (! strcmp (argv[nargs], "-quiet"))
7991 : : quiet = 1;
7992 : 0 : else if (! strcmp (argv[nargs], "-ftime-report"))
7993 : : return;
7994 : :
7995 : 0 : if (out_arg == -1 || !quiet)
7996 : : return;
7997 : :
7998 : 0 : memset (temp_files, '\0', sizeof (temp_files));
7999 : 0 : new_argv = XALLOCAVEC (const char *, nargs + 4);
8000 : 0 : memcpy (new_argv, argv, (nargs + 1) * sizeof (const char *));
8001 : 0 : new_argv[nargs++] = "-frandom-seed=0";
8002 : 0 : new_argv[nargs++] = "-fdump-noaddr";
8003 : 0 : new_argv[nargs] = NULL;
8004 : 0 : if (new_argv[out_arg][2] == '\0')
8005 : 0 : new_argv[out_arg + 1] = "-";
8006 : : else
8007 : 0 : new_argv[out_arg] = "-o-";
8008 : :
8009 : : #ifdef HOST_HAS_PERSONALITY_ADDR_NO_RANDOMIZE
8010 : 0 : personality (personality (0xffffffffU) | ADDR_NO_RANDOMIZE);
8011 : : #endif
8012 : :
8013 : 0 : int status;
8014 : 0 : for (attempt = 0; attempt < RETRY_ICE_ATTEMPTS; ++attempt)
8015 : : {
8016 : 0 : int emit_system_info = 0;
8017 : 0 : int append = 0;
8018 : 0 : temp_stdout_files[attempt] = make_temp_file (".out");
8019 : 0 : temp_stderr_files[attempt] = make_temp_file (".err");
8020 : :
8021 : 0 : if (attempt == RETRY_ICE_ATTEMPTS - 1)
8022 : : {
8023 : 0 : append = 1;
8024 : 0 : emit_system_info = 1;
8025 : : }
8026 : :
8027 : 0 : status = run_attempt (new_argv, temp_stdout_files[attempt],
8028 : : temp_stderr_files[attempt], emit_system_info,
8029 : : append);
8030 : :
8031 : 0 : if (status != ATTEMPT_STATUS_ICE)
8032 : : {
8033 : 0 : fnotice (stderr, "The bug is not reproducible, so it is"
8034 : : " likely a hardware or OS problem.\n");
8035 : 0 : goto out;
8036 : : }
8037 : : }
8038 : :
8039 : 0 : if (!check_repro (temp_stdout_files, temp_stderr_files))
8040 : 0 : goto out;
8041 : :
8042 : 0 : {
8043 : : /* Insert commented out backtrace into report file. */
8044 : 0 : char **stderr_commented = &temp_stdout_files[RETRY_ICE_ATTEMPTS - 1];
8045 : 0 : insert_comments (temp_stderr_files[RETRY_ICE_ATTEMPTS - 1],
8046 : : *stderr_commented);
8047 : :
8048 : : /* In final attempt we append compiler options and preprocesssed code to last
8049 : : generated .out file with configuration and backtrace. */
8050 : 0 : char **err = &temp_stderr_files[RETRY_ICE_ATTEMPTS - 1];
8051 : 0 : do_report_bug (new_argv, nargs, stderr_commented, err);
8052 : : }
8053 : :
8054 : : out:
8055 : 0 : for (i = 0; i < RETRY_ICE_ATTEMPTS * 2; i++)
8056 : 0 : if (temp_files[i])
8057 : : {
8058 : 0 : unlink (temp_stdout_files[i]);
8059 : 0 : free (temp_stdout_files[i]);
8060 : : }
8061 : : }
8062 : :
8063 : : /* Search for a file named NAME trying various prefixes including the
8064 : : user's -B prefix and some standard ones.
8065 : : Return the absolute file name found. If nothing is found, return NAME. */
8066 : :
8067 : : static const char *
8068 : 527900 : find_file (const char *name)
8069 : : {
8070 : 527900 : char *newname = find_a_file (&startfile_prefixes, name, R_OK, true);
8071 : 527900 : return newname ? newname : name;
8072 : : }
8073 : :
8074 : : /* Determine whether a directory exists. */
8075 : :
8076 : : static int
8077 : 10037514 : is_directory (const char *path1)
8078 : : {
8079 : 10037514 : int len1;
8080 : 10037514 : char *path;
8081 : 10037514 : char *cp;
8082 : 10037514 : struct stat st;
8083 : :
8084 : : /* Ensure the string ends with "/.". The resulting path will be a
8085 : : directory even if the given path is a symbolic link. */
8086 : 10037514 : len1 = strlen (path1);
8087 : 10037514 : path = (char *) alloca (3 + len1);
8088 : 10037514 : memcpy (path, path1, len1);
8089 : 10037514 : cp = path + len1;
8090 : 10037514 : if (!IS_DIR_SEPARATOR (cp[-1]))
8091 : 1448316 : *cp++ = DIR_SEPARATOR;
8092 : 10037514 : *cp++ = '.';
8093 : 10037514 : *cp = '\0';
8094 : :
8095 : 10037514 : return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
8096 : : }
8097 : :
8098 : : /* Set up the various global variables to indicate that we're processing
8099 : : the input file named FILENAME. */
8100 : :
8101 : : void
8102 : 806833 : set_input (const char *filename)
8103 : : {
8104 : 806833 : const char *p;
8105 : :
8106 : 806833 : gcc_input_filename = filename;
8107 : 806833 : input_filename_length = strlen (gcc_input_filename);
8108 : 806833 : input_basename = lbasename (gcc_input_filename);
8109 : :
8110 : : /* Find a suffix starting with the last period,
8111 : : and set basename_length to exclude that suffix. */
8112 : 806833 : basename_length = strlen (input_basename);
8113 : 806833 : suffixed_basename_length = basename_length;
8114 : 806833 : p = input_basename + basename_length;
8115 : 3559646 : while (p != input_basename && *p != '.')
8116 : 2752813 : --p;
8117 : 806833 : if (*p == '.' && p != input_basename)
8118 : : {
8119 : 576509 : basename_length = p - input_basename;
8120 : 576509 : input_suffix = p + 1;
8121 : : }
8122 : : else
8123 : 230324 : input_suffix = "";
8124 : :
8125 : : /* If a spec for 'g', 'u', or 'U' is seen with -save-temps then
8126 : : we will need to do a stat on the gcc_input_filename. The
8127 : : INPUT_STAT_SET signals that the stat is needed. */
8128 : 806833 : input_stat_set = 0;
8129 : 806833 : }
8130 : :
8131 : : /* On fatal signals, delete all the temporary files. */
8132 : :
8133 : : static void
8134 : 0 : fatal_signal (int signum)
8135 : : {
8136 : 0 : signal (signum, SIG_DFL);
8137 : 0 : delete_failure_queue ();
8138 : 0 : delete_temp_files ();
8139 : : /* Get the same signal again, this time not handled,
8140 : : so its normal effect occurs. */
8141 : 0 : kill (getpid (), signum);
8142 : 0 : }
8143 : :
8144 : : /* Compare the contents of the two files named CMPFILE[0] and
8145 : : CMPFILE[1]. Return zero if they're identical, nonzero
8146 : : otherwise. */
8147 : :
8148 : : static int
8149 : 616 : compare_files (char *cmpfile[])
8150 : : {
8151 : 616 : int ret = 0;
8152 : 616 : FILE *temp[2] = { NULL, NULL };
8153 : 616 : int i;
8154 : :
8155 : : #if HAVE_MMAP_FILE
8156 : 616 : {
8157 : 616 : size_t length[2];
8158 : 616 : void *map[2] = { NULL, NULL };
8159 : :
8160 : 1848 : for (i = 0; i < 2; i++)
8161 : : {
8162 : 1232 : struct stat st;
8163 : :
8164 : 1232 : if (stat (cmpfile[i], &st) < 0 || !S_ISREG (st.st_mode))
8165 : : {
8166 : 0 : error ("%s: could not determine length of compare-debug file %s",
8167 : : gcc_input_filename, cmpfile[i]);
8168 : 0 : ret = 1;
8169 : 0 : break;
8170 : : }
8171 : :
8172 : 1232 : length[i] = st.st_size;
8173 : : }
8174 : :
8175 : 616 : if (!ret && length[0] != length[1])
8176 : : {
8177 : 17 : error ("%s: %<-fcompare-debug%> failure (length)", gcc_input_filename);
8178 : 17 : ret = 1;
8179 : : }
8180 : :
8181 : 17 : if (!ret)
8182 : 1735 : for (i = 0; i < 2; i++)
8183 : : {
8184 : 1167 : int fd = open (cmpfile[i], O_RDONLY);
8185 : 1167 : if (fd < 0)
8186 : : {
8187 : 0 : error ("%s: could not open compare-debug file %s",
8188 : : gcc_input_filename, cmpfile[i]);
8189 : 0 : ret = 1;
8190 : 0 : break;
8191 : : }
8192 : :
8193 : 1167 : map[i] = mmap (NULL, length[i], PROT_READ, MAP_PRIVATE, fd, 0);
8194 : 1167 : close (fd);
8195 : :
8196 : 1167 : if (map[i] == (void *) MAP_FAILED)
8197 : : {
8198 : : ret = -1;
8199 : : break;
8200 : : }
8201 : : }
8202 : :
8203 : 599 : if (!ret)
8204 : : {
8205 : 568 : if (memcmp (map[0], map[1], length[0]) != 0)
8206 : : {
8207 : 0 : error ("%s: %<-fcompare-debug%> failure", gcc_input_filename);
8208 : 0 : ret = 1;
8209 : : }
8210 : : }
8211 : :
8212 : 1848 : for (i = 0; i < 2; i++)
8213 : 1232 : if (map[i])
8214 : 1167 : munmap ((caddr_t) map[i], length[i]);
8215 : :
8216 : 616 : if (ret >= 0)
8217 : 585 : return ret;
8218 : :
8219 : 31 : ret = 0;
8220 : : }
8221 : : #endif
8222 : :
8223 : 93 : for (i = 0; i < 2; i++)
8224 : : {
8225 : 62 : temp[i] = fopen (cmpfile[i], "r");
8226 : 62 : if (!temp[i])
8227 : : {
8228 : 0 : error ("%s: could not open compare-debug file %s",
8229 : : gcc_input_filename, cmpfile[i]);
8230 : 0 : ret = 1;
8231 : 0 : break;
8232 : : }
8233 : : }
8234 : :
8235 : 31 : if (!ret && temp[0] && temp[1])
8236 : 31 : for (;;)
8237 : : {
8238 : 31 : int c0, c1;
8239 : 31 : c0 = fgetc (temp[0]);
8240 : 31 : c1 = fgetc (temp[1]);
8241 : :
8242 : 31 : if (c0 != c1)
8243 : : {
8244 : 0 : error ("%s: %<-fcompare-debug%> failure",
8245 : : gcc_input_filename);
8246 : 0 : ret = 1;
8247 : 0 : break;
8248 : : }
8249 : :
8250 : 31 : if (c0 == EOF)
8251 : : break;
8252 : : }
8253 : :
8254 : 93 : for (i = 1; i >= 0; i--)
8255 : : {
8256 : 62 : if (temp[i])
8257 : 62 : fclose (temp[i]);
8258 : : }
8259 : :
8260 : : return ret;
8261 : : }
8262 : :
8263 : 287780 : driver::driver (bool can_finalize, bool debug) :
8264 : 287780 : explicit_link_files (NULL),
8265 : 287780 : decoded_options (NULL)
8266 : : {
8267 : 287780 : env.init (can_finalize, debug);
8268 : 287780 : }
8269 : :
8270 : 287298 : driver::~driver ()
8271 : : {
8272 : 287298 : XDELETEVEC (explicit_link_files);
8273 : 287298 : XDELETEVEC (decoded_options);
8274 : 287298 : }
8275 : :
8276 : : /* driver::main is implemented as a series of driver:: method calls. */
8277 : :
8278 : : int
8279 : 287780 : driver::main (int argc, char **argv)
8280 : : {
8281 : 287780 : bool early_exit;
8282 : :
8283 : 287780 : set_progname (argv[0]);
8284 : 287780 : expand_at_files (&argc, &argv);
8285 : 287780 : decode_argv (argc, const_cast <const char **> (argv));
8286 : 287780 : global_initializations ();
8287 : 287780 : build_multilib_strings ();
8288 : 287780 : set_up_specs ();
8289 : 287493 : putenv_COLLECT_AS_OPTIONS (assembler_options);
8290 : 287493 : putenv_COLLECT_GCC (argv[0]);
8291 : 287493 : maybe_putenv_COLLECT_LTO_WRAPPER ();
8292 : 287493 : maybe_putenv_OFFLOAD_TARGETS ();
8293 : 287493 : handle_unrecognized_options ();
8294 : :
8295 : 287493 : if (completion)
8296 : : {
8297 : 5 : m_option_proposer.suggest_completion (completion);
8298 : 5 : return 0;
8299 : : }
8300 : :
8301 : 287488 : if (!maybe_print_and_exit ())
8302 : : return 0;
8303 : :
8304 : 273675 : early_exit = prepare_infiles ();
8305 : 273481 : if (early_exit)
8306 : 349 : return get_exit_code ();
8307 : :
8308 : 273132 : do_spec_on_infiles ();
8309 : 273132 : maybe_run_linker (argv[0]);
8310 : 273132 : final_actions ();
8311 : 273132 : return get_exit_code ();
8312 : : }
8313 : :
8314 : : /* Locate the final component of argv[0] after any leading path, and set
8315 : : the program name accordingly. */
8316 : :
8317 : : void
8318 : 287780 : driver::set_progname (const char *argv0) const
8319 : : {
8320 : 287780 : const char *p = argv0 + strlen (argv0);
8321 : 1593280 : while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
8322 : 1305500 : --p;
8323 : 287780 : progname = p;
8324 : :
8325 : 287780 : xmalloc_set_program_name (progname);
8326 : 287780 : }
8327 : :
8328 : : /* Expand any @ files within the command-line args,
8329 : : setting at_file_supplied if any were expanded. */
8330 : :
8331 : : void
8332 : 287780 : driver::expand_at_files (int *argc, char ***argv) const
8333 : : {
8334 : 287780 : char **old_argv = *argv;
8335 : :
8336 : 287780 : expandargv (argc, argv);
8337 : :
8338 : : /* Determine if any expansions were made. */
8339 : 287780 : if (*argv != old_argv)
8340 : 11830 : at_file_supplied = true;
8341 : 287780 : }
8342 : :
8343 : : /* Decode the command-line arguments from argc/argv into the
8344 : : decoded_options array. */
8345 : :
8346 : : void
8347 : 287780 : driver::decode_argv (int argc, const char **argv)
8348 : : {
8349 : 287780 : init_opts_obstack ();
8350 : 287780 : init_options_struct (&global_options, &global_options_set);
8351 : :
8352 : 287780 : decode_cmdline_options_to_array (argc, argv,
8353 : : CL_DRIVER,
8354 : : &decoded_options, &decoded_options_count);
8355 : 287780 : }
8356 : :
8357 : : /* Perform various initializations and setup. */
8358 : :
8359 : : void
8360 : 287780 : driver::global_initializations ()
8361 : : {
8362 : : /* Unlock the stdio streams. */
8363 : 287780 : unlock_std_streams ();
8364 : :
8365 : 287780 : gcc_init_libintl ();
8366 : :
8367 : 287780 : diagnostic_initialize (global_dc, 0);
8368 : 287780 : diagnostic_color_init (global_dc);
8369 : 287780 : diagnostic_urls_init (global_dc);
8370 : 287780 : global_dc->push_owned_urlifier (make_gcc_urlifier (0));
8371 : :
8372 : : #ifdef GCC_DRIVER_HOST_INITIALIZATION
8373 : : /* Perform host dependent initialization when needed. */
8374 : : GCC_DRIVER_HOST_INITIALIZATION;
8375 : : #endif
8376 : :
8377 : 287780 : if (atexit (delete_temp_files) != 0)
8378 : 0 : fatal_error (input_location, "atexit failed");
8379 : :
8380 : 287780 : if (signal (SIGINT, SIG_IGN) != SIG_IGN)
8381 : 287629 : signal (SIGINT, fatal_signal);
8382 : : #ifdef SIGHUP
8383 : 287780 : if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
8384 : 20916 : signal (SIGHUP, fatal_signal);
8385 : : #endif
8386 : 287780 : if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
8387 : 287780 : signal (SIGTERM, fatal_signal);
8388 : : #ifdef SIGPIPE
8389 : 287780 : if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
8390 : 287780 : signal (SIGPIPE, fatal_signal);
8391 : : #endif
8392 : : #ifdef SIGCHLD
8393 : : /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
8394 : : receive the signal. A different setting is inheritable */
8395 : 287780 : signal (SIGCHLD, SIG_DFL);
8396 : : #endif
8397 : :
8398 : : /* Parsing and gimplification sometimes need quite large stack.
8399 : : Increase stack size limits if possible. */
8400 : 287780 : stack_limit_increase (64 * 1024 * 1024);
8401 : :
8402 : : /* Allocate the argument vector. */
8403 : 287780 : alloc_args ();
8404 : :
8405 : 287780 : obstack_init (&obstack);
8406 : 287780 : }
8407 : :
8408 : : /* Build multilib_select, et. al from the separate lines that make up each
8409 : : multilib selection. */
8410 : :
8411 : : void
8412 : 287780 : driver::build_multilib_strings () const
8413 : : {
8414 : 287780 : {
8415 : 287780 : const char *p;
8416 : 287780 : const char *const *q = multilib_raw;
8417 : 287780 : int need_space;
8418 : :
8419 : 287780 : obstack_init (&multilib_obstack);
8420 : 287780 : while ((p = *q++) != (char *) 0)
8421 : 1151120 : obstack_grow (&multilib_obstack, p, strlen (p));
8422 : :
8423 : 287780 : obstack_1grow (&multilib_obstack, 0);
8424 : 287780 : multilib_select = XOBFINISH (&multilib_obstack, const char *);
8425 : :
8426 : 287780 : q = multilib_matches_raw;
8427 : 287780 : while ((p = *q++) != (char *) 0)
8428 : 863340 : obstack_grow (&multilib_obstack, p, strlen (p));
8429 : :
8430 : 287780 : obstack_1grow (&multilib_obstack, 0);
8431 : 287780 : multilib_matches = XOBFINISH (&multilib_obstack, const char *);
8432 : :
8433 : 287780 : q = multilib_exclusions_raw;
8434 : 287780 : while ((p = *q++) != (char *) 0)
8435 : 287780 : obstack_grow (&multilib_obstack, p, strlen (p));
8436 : :
8437 : 287780 : obstack_1grow (&multilib_obstack, 0);
8438 : 287780 : multilib_exclusions = XOBFINISH (&multilib_obstack, const char *);
8439 : :
8440 : 287780 : q = multilib_reuse_raw;
8441 : 287780 : while ((p = *q++) != (char *) 0)
8442 : 287780 : obstack_grow (&multilib_obstack, p, strlen (p));
8443 : :
8444 : 287780 : obstack_1grow (&multilib_obstack, 0);
8445 : 287780 : multilib_reuse = XOBFINISH (&multilib_obstack, const char *);
8446 : :
8447 : 287780 : need_space = false;
8448 : 575560 : for (size_t i = 0; i < ARRAY_SIZE (multilib_defaults_raw); i++)
8449 : : {
8450 : 287780 : if (need_space)
8451 : 0 : obstack_1grow (&multilib_obstack, ' ');
8452 : 287780 : obstack_grow (&multilib_obstack,
8453 : : multilib_defaults_raw[i],
8454 : : strlen (multilib_defaults_raw[i]));
8455 : 287780 : need_space = true;
8456 : : }
8457 : :
8458 : 287780 : obstack_1grow (&multilib_obstack, 0);
8459 : 287780 : multilib_defaults = XOBFINISH (&multilib_obstack, const char *);
8460 : : }
8461 : 287780 : }
8462 : :
8463 : : /* Set up the spec-handling machinery. */
8464 : :
8465 : : void
8466 : 287780 : driver::set_up_specs () const
8467 : : {
8468 : 287780 : const char *spec_machine_suffix;
8469 : 287780 : char *specs_file;
8470 : 287780 : size_t i;
8471 : :
8472 : : #ifdef INIT_ENVIRONMENT
8473 : : /* Set up any other necessary machine specific environment variables. */
8474 : : xputenv (INIT_ENVIRONMENT);
8475 : : #endif
8476 : :
8477 : : /* Make a table of what switches there are (switches, n_switches).
8478 : : Make a table of specified input files (infiles, n_infiles).
8479 : : Decode switches that are handled locally. */
8480 : :
8481 : 287780 : process_command (decoded_options_count, decoded_options);
8482 : :
8483 : : /* Initialize the vector of specs to just the default.
8484 : : This means one element containing 0s, as a terminator. */
8485 : :
8486 : 287494 : compilers = XNEWVAR (struct compiler, sizeof default_compilers);
8487 : 287494 : memcpy (compilers, default_compilers, sizeof default_compilers);
8488 : 287494 : n_compilers = n_default_compilers;
8489 : :
8490 : : /* Read specs from a file if there is one. */
8491 : :
8492 : 287494 : machine_suffix = concat (spec_host_machine, dir_separator_str, spec_version,
8493 : : accel_dir_suffix, dir_separator_str, NULL);
8494 : 287494 : just_machine_suffix = concat (spec_machine, dir_separator_str, NULL);
8495 : :
8496 : 287494 : specs_file = find_a_file (&startfile_prefixes, "specs", R_OK, true);
8497 : : /* Read the specs file unless it is a default one. */
8498 : 287494 : if (specs_file != 0 && strcmp (specs_file, "specs"))
8499 : 286594 : read_specs (specs_file, true, false);
8500 : : else
8501 : 900 : init_spec ();
8502 : :
8503 : : #ifdef ACCEL_COMPILER
8504 : : spec_machine_suffix = machine_suffix;
8505 : : #else
8506 : 287494 : spec_machine_suffix = just_machine_suffix;
8507 : : #endif
8508 : :
8509 : : /* We need to check standard_exec_prefix/spec_machine_suffix/specs
8510 : : for any override of as, ld and libraries. */
8511 : 287494 : specs_file = (char *) alloca (strlen (standard_exec_prefix)
8512 : : + strlen (spec_machine_suffix) + sizeof ("specs"));
8513 : 287494 : strcpy (specs_file, standard_exec_prefix);
8514 : 287494 : strcat (specs_file, spec_machine_suffix);
8515 : 287494 : strcat (specs_file, "specs");
8516 : 287494 : if (access (specs_file, R_OK) == 0)
8517 : 0 : read_specs (specs_file, true, false);
8518 : :
8519 : : /* Process any configure-time defaults specified for the command line
8520 : : options, via OPTION_DEFAULT_SPECS. */
8521 : 2874940 : for (i = 0; i < ARRAY_SIZE (option_default_specs); i++)
8522 : 2587446 : do_option_spec (option_default_specs[i].name,
8523 : 2587446 : option_default_specs[i].spec);
8524 : :
8525 : : /* Process DRIVER_SELF_SPECS, adding any new options to the end
8526 : : of the command line. */
8527 : :
8528 : 2012458 : for (i = 0; i < ARRAY_SIZE (driver_self_specs); i++)
8529 : 1724964 : do_self_spec (driver_self_specs[i]);
8530 : :
8531 : : /* If not cross-compiling, look for executables in the standard
8532 : : places. */
8533 : 287494 : if (*cross_compile == '0')
8534 : : {
8535 : 287494 : if (*md_exec_prefix)
8536 : : {
8537 : 0 : add_prefix (&exec_prefixes, md_exec_prefix, "GCC",
8538 : : PREFIX_PRIORITY_LAST, 0, 0);
8539 : : }
8540 : : }
8541 : :
8542 : : /* Process sysroot_suffix_spec. */
8543 : 287494 : if (*sysroot_suffix_spec != 0
8544 : 0 : && !no_sysroot_suffix
8545 : 287494 : && do_spec_2 (sysroot_suffix_spec, NULL) == 0)
8546 : : {
8547 : 0 : if (argbuf.length () > 1)
8548 : 0 : error ("spec failure: more than one argument to "
8549 : : "%<SYSROOT_SUFFIX_SPEC%>");
8550 : 0 : else if (argbuf.length () == 1)
8551 : 0 : target_sysroot_suffix = xstrdup (argbuf.last ());
8552 : : }
8553 : :
8554 : : #ifdef HAVE_LD_SYSROOT
8555 : : /* Pass the --sysroot option to the linker, if it supports that. If
8556 : : there is a sysroot_suffix_spec, it has already been processed by
8557 : : this point, so target_system_root really is the system root we
8558 : : should be using. */
8559 : 287494 : if (target_system_root)
8560 : : {
8561 : 0 : obstack_grow (&obstack, "%(sysroot_spec) ", strlen ("%(sysroot_spec) "));
8562 : 0 : obstack_grow0 (&obstack, link_spec, strlen (link_spec));
8563 : 0 : set_spec ("link", XOBFINISH (&obstack, const char *), false);
8564 : : }
8565 : : #endif
8566 : :
8567 : : /* Process sysroot_hdrs_suffix_spec. */
8568 : 287494 : if (*sysroot_hdrs_suffix_spec != 0
8569 : 0 : && !no_sysroot_suffix
8570 : 287494 : && do_spec_2 (sysroot_hdrs_suffix_spec, NULL) == 0)
8571 : : {
8572 : 0 : if (argbuf.length () > 1)
8573 : 0 : error ("spec failure: more than one argument "
8574 : : "to %<SYSROOT_HEADERS_SUFFIX_SPEC%>");
8575 : 0 : else if (argbuf.length () == 1)
8576 : 0 : target_sysroot_hdrs_suffix = xstrdup (argbuf.last ());
8577 : : }
8578 : :
8579 : : /* Look for startfiles in the standard places. */
8580 : 287494 : if (*startfile_prefix_spec != 0
8581 : 0 : && do_spec_2 (startfile_prefix_spec, NULL) == 0
8582 : 287494 : && do_spec_1 (" ", 0, NULL) == 0)
8583 : : {
8584 : 0 : for (const char *arg : argbuf)
8585 : 0 : add_sysrooted_prefix (&startfile_prefixes, arg, "BINUTILS",
8586 : : PREFIX_PRIORITY_LAST, 0, 1);
8587 : : }
8588 : : /* We should eventually get rid of all these and stick to
8589 : : startfile_prefix_spec exclusively. */
8590 : 287494 : else if (*cross_compile == '0' || target_system_root)
8591 : : {
8592 : 287494 : if (*md_startfile_prefix)
8593 : 0 : add_sysrooted_prefix (&startfile_prefixes, md_startfile_prefix,
8594 : : "GCC", PREFIX_PRIORITY_LAST, 0, 1);
8595 : :
8596 : 287494 : if (*md_startfile_prefix_1)
8597 : 0 : add_sysrooted_prefix (&startfile_prefixes, md_startfile_prefix_1,
8598 : : "GCC", PREFIX_PRIORITY_LAST, 0, 1);
8599 : :
8600 : : /* If standard_startfile_prefix is relative, base it on
8601 : : standard_exec_prefix. This lets us move the installed tree
8602 : : as a unit. If GCC_EXEC_PREFIX is defined, base
8603 : : standard_startfile_prefix on that as well.
8604 : :
8605 : : If the prefix is relative, only search it for native compilers;
8606 : : otherwise we will search a directory containing host libraries. */
8607 : 287494 : if (IS_ABSOLUTE_PATH (standard_startfile_prefix))
8608 : : add_sysrooted_prefix (&startfile_prefixes,
8609 : : standard_startfile_prefix, "BINUTILS",
8610 : : PREFIX_PRIORITY_LAST, 0, 1);
8611 : 287494 : else if (*cross_compile == '0')
8612 : : {
8613 : 287494 : add_prefix (&startfile_prefixes,
8614 : 574988 : concat (gcc_exec_prefix
8615 : : ? gcc_exec_prefix : standard_exec_prefix,
8616 : : machine_suffix,
8617 : : standard_startfile_prefix, NULL),
8618 : : NULL, PREFIX_PRIORITY_LAST, 0, 1);
8619 : : }
8620 : :
8621 : : /* Sysrooted prefixes are relocated because target_system_root is
8622 : : also relocated by gcc_exec_prefix. */
8623 : 287494 : if (*standard_startfile_prefix_1)
8624 : 287494 : add_sysrooted_prefix (&startfile_prefixes,
8625 : : standard_startfile_prefix_1, "BINUTILS",
8626 : : PREFIX_PRIORITY_LAST, 0, 1);
8627 : 287494 : if (*standard_startfile_prefix_2)
8628 : 287494 : add_sysrooted_prefix (&startfile_prefixes,
8629 : : standard_startfile_prefix_2, "BINUTILS",
8630 : : PREFIX_PRIORITY_LAST, 0, 1);
8631 : : }
8632 : :
8633 : : /* Process any user specified specs in the order given on the command
8634 : : line. */
8635 : 287496 : for (struct user_specs *uptr = user_specs_head; uptr; uptr = uptr->next)
8636 : : {
8637 : 3 : char *filename = find_a_file (&startfile_prefixes, uptr->filename,
8638 : : R_OK, true);
8639 : 3 : read_specs (filename ? filename : uptr->filename, false, true);
8640 : : }
8641 : :
8642 : : /* Process any user self specs. */
8643 : 287493 : {
8644 : 287493 : struct spec_list *sl;
8645 : 13512171 : for (sl = specs; sl; sl = sl->next)
8646 : 13224678 : if (sl->name_len == sizeof "self_spec" - 1
8647 : 2012451 : && !strcmp (sl->name, "self_spec"))
8648 : 287493 : do_self_spec (*sl->ptr_spec);
8649 : : }
8650 : :
8651 : 287493 : if (compare_debug)
8652 : : {
8653 : 622 : enum save_temps save;
8654 : :
8655 : 622 : if (!compare_debug_second)
8656 : : {
8657 : 622 : n_switches_debug_check[1] = n_switches;
8658 : 622 : n_switches_alloc_debug_check[1] = n_switches_alloc;
8659 : 622 : switches_debug_check[1] = XDUPVEC (struct switchstr, switches,
8660 : : n_switches_alloc);
8661 : :
8662 : 622 : do_self_spec ("%:compare-debug-self-opt()");
8663 : 622 : n_switches_debug_check[0] = n_switches;
8664 : 622 : n_switches_alloc_debug_check[0] = n_switches_alloc;
8665 : 622 : switches_debug_check[0] = switches;
8666 : :
8667 : 622 : n_switches = n_switches_debug_check[1];
8668 : 622 : n_switches_alloc = n_switches_alloc_debug_check[1];
8669 : 622 : switches = switches_debug_check[1];
8670 : : }
8671 : :
8672 : : /* Avoid crash when computing %j in this early. */
8673 : 622 : save = save_temps_flag;
8674 : 622 : save_temps_flag = SAVE_TEMPS_NONE;
8675 : :
8676 : 622 : compare_debug = -compare_debug;
8677 : 622 : do_self_spec ("%:compare-debug-self-opt()");
8678 : :
8679 : 622 : save_temps_flag = save;
8680 : :
8681 : 622 : if (!compare_debug_second)
8682 : : {
8683 : 622 : n_switches_debug_check[1] = n_switches;
8684 : 622 : n_switches_alloc_debug_check[1] = n_switches_alloc;
8685 : 622 : switches_debug_check[1] = switches;
8686 : 622 : compare_debug = -compare_debug;
8687 : 622 : n_switches = n_switches_debug_check[0];
8688 : 622 : n_switches_alloc = n_switches_debug_check[0];
8689 : 622 : switches = switches_debug_check[0];
8690 : : }
8691 : : }
8692 : :
8693 : :
8694 : : /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
8695 : 287493 : if (gcc_exec_prefix)
8696 : 287493 : gcc_exec_prefix = concat (gcc_exec_prefix, spec_host_machine,
8697 : : dir_separator_str, spec_version,
8698 : : accel_dir_suffix, dir_separator_str, NULL);
8699 : :
8700 : : /* Now we have the specs.
8701 : : Set the `valid' bits for switches that match anything in any spec. */
8702 : :
8703 : 287493 : validate_all_switches ();
8704 : :
8705 : : /* Now that we have the switches and the specs, set
8706 : : the subdirectory based on the options. */
8707 : 287493 : set_multilib_dir ();
8708 : 287493 : }
8709 : :
8710 : : /* Set up to remember the pathname of gcc and any options
8711 : : needed for collect. We use argv[0] instead of progname because
8712 : : we need the complete pathname. */
8713 : :
8714 : : void
8715 : 287493 : driver::putenv_COLLECT_GCC (const char *argv0) const
8716 : : {
8717 : 287493 : obstack_init (&collect_obstack);
8718 : 287493 : obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=") - 1);
8719 : 287493 : obstack_grow (&collect_obstack, argv0, strlen (argv0) + 1);
8720 : 287493 : xputenv (XOBFINISH (&collect_obstack, char *));
8721 : 287493 : }
8722 : :
8723 : : /* Set up to remember the pathname of the lto wrapper. */
8724 : :
8725 : : void
8726 : 287493 : driver::maybe_putenv_COLLECT_LTO_WRAPPER () const
8727 : : {
8728 : 287493 : char *lto_wrapper_file;
8729 : :
8730 : 287493 : if (have_c)
8731 : : lto_wrapper_file = NULL;
8732 : : else
8733 : 106670 : lto_wrapper_file = find_a_program ("lto-wrapper");
8734 : 106670 : if (lto_wrapper_file)
8735 : : {
8736 : 209360 : lto_wrapper_file = convert_white_space (lto_wrapper_file);
8737 : 104680 : set_static_spec_owned (<o_wrapper_spec, lto_wrapper_file);
8738 : 104680 : obstack_init (&collect_obstack);
8739 : 104680 : obstack_grow (&collect_obstack, "COLLECT_LTO_WRAPPER=",
8740 : : sizeof ("COLLECT_LTO_WRAPPER=") - 1);
8741 : 104680 : obstack_grow (&collect_obstack, lto_wrapper_spec,
8742 : : strlen (lto_wrapper_spec) + 1);
8743 : 104680 : xputenv (XOBFINISH (&collect_obstack, char *));
8744 : : }
8745 : :
8746 : 287493 : }
8747 : :
8748 : : /* Set up to remember the names of offload targets. */
8749 : :
8750 : : void
8751 : 287493 : driver::maybe_putenv_OFFLOAD_TARGETS () const
8752 : : {
8753 : 287493 : if (offload_targets && offload_targets[0] != '\0')
8754 : : {
8755 : 0 : obstack_grow (&collect_obstack, "OFFLOAD_TARGET_NAMES=",
8756 : : sizeof ("OFFLOAD_TARGET_NAMES=") - 1);
8757 : 0 : obstack_grow (&collect_obstack, offload_targets,
8758 : : strlen (offload_targets) + 1);
8759 : 0 : xputenv (XOBFINISH (&collect_obstack, char *));
8760 : : #if OFFLOAD_DEFAULTED
8761 : : if (offload_targets_default)
8762 : : xputenv ("OFFLOAD_TARGET_DEFAULT=1");
8763 : : #endif
8764 : : }
8765 : :
8766 : 287493 : free (offload_targets);
8767 : 287493 : offload_targets = NULL;
8768 : 287493 : }
8769 : :
8770 : : /* Reject switches that no pass was interested in. */
8771 : :
8772 : : void
8773 : 287493 : driver::handle_unrecognized_options ()
8774 : : {
8775 : 6510283 : for (size_t i = 0; (int) i < n_switches; i++)
8776 : 6222790 : if (! switches[i].validated)
8777 : : {
8778 : 481 : const char *hint = m_option_proposer.suggest_option (switches[i].part1);
8779 : 481 : if (hint)
8780 : 214 : error ("unrecognized command-line option %<-%s%>;"
8781 : : " did you mean %<-%s%>?",
8782 : 214 : switches[i].part1, hint);
8783 : : else
8784 : 267 : error ("unrecognized command-line option %<-%s%>",
8785 : 267 : switches[i].part1);
8786 : : }
8787 : 287493 : }
8788 : :
8789 : : /* Handle the various -print-* options, returning 0 if the driver
8790 : : should exit, or nonzero if the driver should continue. */
8791 : :
8792 : : int
8793 : 287488 : driver::maybe_print_and_exit () const
8794 : : {
8795 : 287488 : if (print_search_dirs)
8796 : : {
8797 : 56 : printf (_("install: %s%s\n"),
8798 : : gcc_exec_prefix ? gcc_exec_prefix : standard_exec_prefix,
8799 : 28 : gcc_exec_prefix ? "" : machine_suffix);
8800 : 28 : printf (_("programs: %s\n"),
8801 : : build_search_list (&exec_prefixes, "", false, false));
8802 : 28 : printf (_("libraries: %s\n"),
8803 : : build_search_list (&startfile_prefixes, "", false, true));
8804 : 28 : return (0);
8805 : : }
8806 : :
8807 : 287460 : if (print_file_name)
8808 : : {
8809 : 4222 : printf ("%s\n", find_file (print_file_name));
8810 : 4222 : return (0);
8811 : : }
8812 : :
8813 : 283238 : if (print_prog_name)
8814 : : {
8815 : 106 : if (use_ld != NULL && ! strcmp (print_prog_name, "ld"))
8816 : : {
8817 : : /* Append USE_LD to the default linker. */
8818 : : #ifdef DEFAULT_LINKER
8819 : : char *ld;
8820 : : # ifdef HAVE_HOST_EXECUTABLE_SUFFIX
8821 : : int len = (sizeof (DEFAULT_LINKER)
8822 : : - sizeof (HOST_EXECUTABLE_SUFFIX));
8823 : : ld = NULL;
8824 : : if (len > 0)
8825 : : {
8826 : : char *default_linker = xstrdup (DEFAULT_LINKER);
8827 : : /* Strip HOST_EXECUTABLE_SUFFIX if DEFAULT_LINKER contains
8828 : : HOST_EXECUTABLE_SUFFIX. */
8829 : : if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
8830 : : {
8831 : : default_linker[len] = '\0';
8832 : : ld = concat (default_linker, use_ld,
8833 : : HOST_EXECUTABLE_SUFFIX, NULL);
8834 : : }
8835 : : }
8836 : : if (ld == NULL)
8837 : : # endif
8838 : : ld = concat (DEFAULT_LINKER, use_ld, NULL);
8839 : : if (access (ld, X_OK) == 0)
8840 : : {
8841 : : printf ("%s\n", ld);
8842 : : return (0);
8843 : : }
8844 : : #endif
8845 : 0 : print_prog_name = concat (print_prog_name, use_ld, NULL);
8846 : : }
8847 : 106 : char *newname = find_a_program (print_prog_name);
8848 : 106 : printf ("%s\n", (newname ? newname : print_prog_name));
8849 : 106 : return (0);
8850 : : }
8851 : :
8852 : 283132 : if (print_multi_lib)
8853 : : {
8854 : 4586 : print_multilib_info ();
8855 : 4586 : return (0);
8856 : : }
8857 : :
8858 : 278546 : if (print_multi_directory)
8859 : : {
8860 : 4073 : if (multilib_dir == NULL)
8861 : 4048 : printf (".\n");
8862 : : else
8863 : 25 : printf ("%s\n", multilib_dir);
8864 : 4073 : return (0);
8865 : : }
8866 : :
8867 : 274473 : if (print_multiarch)
8868 : : {
8869 : 0 : if (multiarch_dir == NULL)
8870 : 0 : printf ("\n");
8871 : : else
8872 : 0 : printf ("%s\n", multiarch_dir);
8873 : 0 : return (0);
8874 : : }
8875 : :
8876 : 274473 : if (print_sysroot)
8877 : : {
8878 : 0 : if (target_system_root)
8879 : : {
8880 : 0 : if (target_sysroot_suffix)
8881 : 0 : printf ("%s%s\n", target_system_root, target_sysroot_suffix);
8882 : : else
8883 : 0 : printf ("%s\n", target_system_root);
8884 : : }
8885 : 0 : return (0);
8886 : : }
8887 : :
8888 : 274473 : if (print_multi_os_directory)
8889 : : {
8890 : 149 : if (multilib_os_dir == NULL)
8891 : 0 : printf (".\n");
8892 : : else
8893 : 149 : printf ("%s\n", multilib_os_dir);
8894 : 149 : return (0);
8895 : : }
8896 : :
8897 : 274324 : if (print_sysroot_headers_suffix)
8898 : : {
8899 : 1 : if (*sysroot_hdrs_suffix_spec)
8900 : : {
8901 : 0 : printf("%s\n", (target_sysroot_hdrs_suffix
8902 : : ? target_sysroot_hdrs_suffix
8903 : : : ""));
8904 : 0 : return (0);
8905 : : }
8906 : : else
8907 : : /* The error status indicates that only one set of fixed
8908 : : headers should be built. */
8909 : 1 : fatal_error (input_location,
8910 : : "not configured with sysroot headers suffix");
8911 : : }
8912 : :
8913 : 274323 : if (print_help_list)
8914 : : {
8915 : 4 : display_help ();
8916 : :
8917 : 4 : if (! verbose_flag)
8918 : : {
8919 : 1 : printf (_("\nFor bug reporting instructions, please see:\n"));
8920 : 1 : printf ("%s.\n", bug_report_url);
8921 : :
8922 : 1 : return (0);
8923 : : }
8924 : :
8925 : : /* We do not exit here. Instead we have created a fake input file
8926 : : called 'help-dummy' which needs to be compiled, and we pass this
8927 : : on the various sub-processes, along with the --help switch.
8928 : : Ensure their output appears after ours. */
8929 : 3 : fputc ('\n', stdout);
8930 : 3 : fflush (stdout);
8931 : : }
8932 : :
8933 : 274322 : if (print_version)
8934 : : {
8935 : 78 : printf (_("%s %s%s\n"), progname, pkgversion_string,
8936 : : version_string);
8937 : 78 : printf ("Copyright %s 2025 Free Software Foundation, Inc.\n",
8938 : : _("(C)"));
8939 : 78 : fputs (_("This is free software; see the source for copying conditions. There is NO\n\
8940 : : warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"),
8941 : : stdout);
8942 : 78 : if (! verbose_flag)
8943 : : return 0;
8944 : :
8945 : : /* We do not exit here. We use the same mechanism of --help to print
8946 : : the version of the sub-processes. */
8947 : 0 : fputc ('\n', stdout);
8948 : 0 : fflush (stdout);
8949 : : }
8950 : :
8951 : 274244 : if (verbose_flag)
8952 : : {
8953 : 1358 : print_configuration (stderr);
8954 : 1358 : if (n_infiles == 0)
8955 : : return (0);
8956 : : }
8957 : :
8958 : : return 1;
8959 : : }
8960 : :
8961 : : /* Figure out what to do with each input file.
8962 : : Return true if we need to exit early from "main", false otherwise. */
8963 : :
8964 : : bool
8965 : 273675 : driver::prepare_infiles ()
8966 : : {
8967 : 273675 : size_t i;
8968 : 273675 : int lang_n_infiles = 0;
8969 : :
8970 : 273675 : if (n_infiles == added_libraries)
8971 : 194 : fatal_error (input_location, "no input files");
8972 : :
8973 : 273481 : if (seen_error ())
8974 : : /* Early exit needed from main. */
8975 : : return true;
8976 : :
8977 : : /* Make a place to record the compiler output file names
8978 : : that correspond to the input files. */
8979 : :
8980 : 273132 : i = n_infiles;
8981 : 273132 : i += lang_specific_extra_outfiles;
8982 : 273132 : outfiles = XCNEWVEC (const char *, i);
8983 : :
8984 : : /* Record which files were specified explicitly as link input. */
8985 : :
8986 : 273132 : explicit_link_files = XCNEWVEC (char, n_infiles);
8987 : :
8988 : 273132 : combine_inputs = have_o || flag_wpa;
8989 : :
8990 : 808716 : for (i = 0; (int) i < n_infiles; i++)
8991 : : {
8992 : 535584 : const char *name = infiles[i].name;
8993 : 535584 : struct compiler *compiler = lookup_compiler (name,
8994 : : strlen (name),
8995 : : infiles[i].language);
8996 : :
8997 : 535584 : if (compiler && !(compiler->combinable))
8998 : 245051 : combine_inputs = false;
8999 : :
9000 : 535584 : if (lang_n_infiles > 0 && compiler != input_file_compiler
9001 : 240821 : && infiles[i].language && infiles[i].language[0] != '*')
9002 : 33 : infiles[i].incompiler = compiler;
9003 : 535551 : else if (compiler)
9004 : : {
9005 : 284074 : lang_n_infiles++;
9006 : 284074 : input_file_compiler = compiler;
9007 : 284074 : infiles[i].incompiler = compiler;
9008 : : }
9009 : : else
9010 : : {
9011 : : /* Since there is no compiler for this input file, assume it is a
9012 : : linker file. */
9013 : 251477 : explicit_link_files[i] = 1;
9014 : 251477 : infiles[i].incompiler = NULL;
9015 : : }
9016 : 535584 : infiles[i].compiled = false;
9017 : 535584 : infiles[i].preprocessed = false;
9018 : : }
9019 : :
9020 : 273132 : if (!combine_inputs && have_c && have_o && lang_n_infiles > 1)
9021 : 0 : fatal_error (input_location,
9022 : : "cannot specify %<-o%> with %<-c%>, %<-S%> or %<-E%> "
9023 : : "with multiple files");
9024 : :
9025 : : /* No early exit needed from main; we can continue. */
9026 : : return false;
9027 : : }
9028 : :
9029 : : /* Run the spec machinery on each input file. */
9030 : :
9031 : : void
9032 : 273132 : driver::do_spec_on_infiles () const
9033 : : {
9034 : 273132 : size_t i;
9035 : :
9036 : 808716 : for (i = 0; (int) i < n_infiles; i++)
9037 : : {
9038 : 535584 : int this_file_error = 0;
9039 : :
9040 : : /* Tell do_spec what to substitute for %i. */
9041 : :
9042 : 535584 : input_file_number = i;
9043 : 535584 : set_input (infiles[i].name);
9044 : :
9045 : 535584 : if (infiles[i].compiled)
9046 : 9090 : continue;
9047 : :
9048 : : /* Use the same thing in %o, unless cp->spec says otherwise. */
9049 : :
9050 : 526494 : outfiles[i] = gcc_input_filename;
9051 : :
9052 : : /* Figure out which compiler from the file's suffix. */
9053 : :
9054 : 526494 : input_file_compiler
9055 : 526494 : = lookup_compiler (infiles[i].name, input_filename_length,
9056 : : infiles[i].language);
9057 : :
9058 : 526494 : if (input_file_compiler)
9059 : : {
9060 : : /* Ok, we found an applicable compiler. Run its spec. */
9061 : :
9062 : 275017 : if (input_file_compiler->spec[0] == '#')
9063 : : {
9064 : 0 : error ("%s: %s compiler not installed on this system",
9065 : : gcc_input_filename, &input_file_compiler->spec[1]);
9066 : 0 : this_file_error = 1;
9067 : : }
9068 : : else
9069 : : {
9070 : 275017 : int value;
9071 : :
9072 : 275017 : if (compare_debug)
9073 : : {
9074 : 620 : free (debug_check_temp_file[0]);
9075 : 620 : debug_check_temp_file[0] = NULL;
9076 : :
9077 : 620 : free (debug_check_temp_file[1]);
9078 : 620 : debug_check_temp_file[1] = NULL;
9079 : : }
9080 : :
9081 : 275017 : value = do_spec (input_file_compiler->spec);
9082 : 275017 : infiles[i].compiled = true;
9083 : 275017 : if (value < 0)
9084 : : this_file_error = 1;
9085 : 246824 : else if (compare_debug && debug_check_temp_file[0])
9086 : : {
9087 : 616 : if (verbose_flag)
9088 : 0 : inform (UNKNOWN_LOCATION,
9089 : : "recompiling with %<-fcompare-debug%>");
9090 : :
9091 : 616 : compare_debug = -compare_debug;
9092 : 616 : n_switches = n_switches_debug_check[1];
9093 : 616 : n_switches_alloc = n_switches_alloc_debug_check[1];
9094 : 616 : switches = switches_debug_check[1];
9095 : :
9096 : 616 : value = do_spec (input_file_compiler->spec);
9097 : :
9098 : 616 : compare_debug = -compare_debug;
9099 : 616 : n_switches = n_switches_debug_check[0];
9100 : 616 : n_switches_alloc = n_switches_alloc_debug_check[0];
9101 : 616 : switches = switches_debug_check[0];
9102 : :
9103 : 616 : if (value < 0)
9104 : : {
9105 : 3 : error ("during %<-fcompare-debug%> recompilation");
9106 : 3 : this_file_error = 1;
9107 : : }
9108 : :
9109 : 616 : gcc_assert (debug_check_temp_file[1]
9110 : : && filename_cmp (debug_check_temp_file[0],
9111 : : debug_check_temp_file[1]));
9112 : :
9113 : 616 : if (verbose_flag)
9114 : 0 : inform (UNKNOWN_LOCATION, "comparing final insns dumps");
9115 : :
9116 : 616 : if (compare_files (debug_check_temp_file))
9117 : 28210 : this_file_error = 1;
9118 : : }
9119 : :
9120 : 275017 : if (compare_debug)
9121 : : {
9122 : 620 : free (debug_check_temp_file[0]);
9123 : 620 : debug_check_temp_file[0] = NULL;
9124 : :
9125 : 620 : free (debug_check_temp_file[1]);
9126 : 620 : debug_check_temp_file[1] = NULL;
9127 : : }
9128 : : }
9129 : : }
9130 : :
9131 : : /* If this file's name does not contain a recognized suffix,
9132 : : record it as explicit linker input. */
9133 : :
9134 : : else
9135 : 251477 : explicit_link_files[i] = 1;
9136 : :
9137 : : /* Clear the delete-on-failure queue, deleting the files in it
9138 : : if this compilation failed. */
9139 : :
9140 : 526494 : if (this_file_error)
9141 : : {
9142 : 28210 : delete_failure_queue ();
9143 : 28210 : errorcount++;
9144 : : }
9145 : : /* If this compilation succeeded, don't delete those files later. */
9146 : 526494 : clear_failure_queue ();
9147 : : }
9148 : :
9149 : : /* Reset the input file name to the first compile/object file name, for use
9150 : : with %b in LINK_SPEC. We use the first input file that we can find
9151 : : a compiler to compile it instead of using infiles.language since for
9152 : : languages other than C we use aliases that we then lookup later. */
9153 : 273132 : if (n_infiles > 0)
9154 : : {
9155 : : int i;
9156 : :
9157 : 285219 : for (i = 0; i < n_infiles ; i++)
9158 : 283336 : if (infiles[i].incompiler
9159 : 12087 : || (infiles[i].language && infiles[i].language[0] != '*'))
9160 : : {
9161 : 271249 : set_input (infiles[i].name);
9162 : 271249 : break;
9163 : : }
9164 : : }
9165 : :
9166 : 273132 : if (!seen_error ())
9167 : : {
9168 : : /* Make sure INPUT_FILE_NUMBER points to first available open
9169 : : slot. */
9170 : 244922 : input_file_number = n_infiles;
9171 : 244922 : if (lang_specific_pre_link ())
9172 : 0 : errorcount++;
9173 : : }
9174 : 273132 : }
9175 : :
9176 : : /* If we have to run the linker, do it now. */
9177 : :
9178 : : void
9179 : 273132 : driver::maybe_run_linker (const char *argv0) const
9180 : : {
9181 : 273132 : size_t i;
9182 : 273132 : int linker_was_run = 0;
9183 : 273132 : int num_linker_inputs;
9184 : :
9185 : : /* Determine if there are any linker input files. */
9186 : 273132 : num_linker_inputs = 0;
9187 : 808716 : for (i = 0; (int) i < n_infiles; i++)
9188 : 535584 : if (explicit_link_files[i] || outfiles[i] != NULL)
9189 : 526072 : num_linker_inputs++;
9190 : :
9191 : : /* Arrange for temporary file names created during linking to take
9192 : : on names related with the linker output rather than with the
9193 : : inputs when appropriate. */
9194 : 273132 : if (outbase && *outbase)
9195 : : {
9196 : 250596 : if (dumpdir)
9197 : : {
9198 : 86545 : char *tofree = dumpdir;
9199 : 86545 : gcc_checking_assert (strlen (dumpdir) == dumpdir_length);
9200 : 86545 : dumpdir = concat (dumpdir, outbase, ".", NULL);
9201 : 86545 : free (tofree);
9202 : : }
9203 : : else
9204 : 164051 : dumpdir = concat (outbase, ".", NULL);
9205 : 250596 : dumpdir_length += strlen (outbase) + 1;
9206 : 250596 : dumpdir_trailing_dash_added = true;
9207 : 250596 : }
9208 : 22536 : else if (dumpdir_trailing_dash_added)
9209 : : {
9210 : 17718 : gcc_assert (dumpdir[dumpdir_length - 1] == '-');
9211 : 17718 : dumpdir[dumpdir_length - 1] = '.';
9212 : : }
9213 : :
9214 : 273132 : if (dumpdir_trailing_dash_added)
9215 : : {
9216 : 268314 : gcc_assert (dumpdir_length > 0);
9217 : 268314 : gcc_assert (dumpdir[dumpdir_length - 1] == '.');
9218 : 268314 : dumpdir_length--;
9219 : : }
9220 : :
9221 : 273132 : free (outbase);
9222 : 273132 : input_basename = outbase = NULL;
9223 : 273132 : outbase_length = suffixed_basename_length = basename_length = 0;
9224 : :
9225 : : /* Run ld to link all the compiler output files. */
9226 : :
9227 : 273132 : if (num_linker_inputs > 0 && !seen_error () && print_subprocess_help < 2)
9228 : : {
9229 : 244439 : int tmp = execution_count;
9230 : :
9231 : 244439 : detect_jobserver ();
9232 : :
9233 : 244439 : if (! have_c)
9234 : : {
9235 : : #if HAVE_LTO_PLUGIN > 0
9236 : : #if HAVE_LTO_PLUGIN == 2
9237 : 92515 : const char *fno_use_linker_plugin = "fno-use-linker-plugin";
9238 : : #else
9239 : : const char *fuse_linker_plugin = "fuse-linker-plugin";
9240 : : #endif
9241 : : #endif
9242 : :
9243 : : /* We'll use ld if we can't find collect2. */
9244 : 92515 : if (! strcmp (linker_name_spec, "collect2"))
9245 : : {
9246 : 92515 : char *s = find_a_program ("collect2");
9247 : 92515 : if (s == NULL)
9248 : 1089 : set_static_spec_shared (&linker_name_spec, "ld");
9249 : : }
9250 : :
9251 : : #if HAVE_LTO_PLUGIN > 0
9252 : : #if HAVE_LTO_PLUGIN == 2
9253 : 92515 : if (!switch_matches (fno_use_linker_plugin,
9254 : : fno_use_linker_plugin
9255 : : + strlen (fno_use_linker_plugin), 0))
9256 : : #else
9257 : : if (switch_matches (fuse_linker_plugin,
9258 : : fuse_linker_plugin
9259 : : + strlen (fuse_linker_plugin), 0))
9260 : : #endif
9261 : : {
9262 : 87197 : char *temp_spec = find_a_file (&exec_prefixes,
9263 : : LTOPLUGINSONAME, R_OK,
9264 : : false);
9265 : 87197 : if (!temp_spec)
9266 : 0 : fatal_error (input_location,
9267 : : "%<-fuse-linker-plugin%>, but %s not found",
9268 : : LTOPLUGINSONAME);
9269 : 87197 : linker_plugin_file_spec = convert_white_space (temp_spec);
9270 : : }
9271 : : #endif
9272 : 92515 : set_static_spec_shared (<o_gcc_spec, argv0);
9273 : : }
9274 : :
9275 : : /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
9276 : : for collect. */
9277 : 244439 : putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH", false);
9278 : 244439 : putenv_from_prefixes (&startfile_prefixes, LIBRARY_PATH_ENV, true);
9279 : :
9280 : 244439 : if (print_subprocess_help == 1)
9281 : : {
9282 : 0 : printf (_("\nLinker options\n==============\n\n"));
9283 : 0 : printf (_("Use \"-Wl,OPTION\" to pass \"OPTION\""
9284 : : " to the linker.\n\n"));
9285 : 0 : fflush (stdout);
9286 : : }
9287 : 244439 : int value = do_spec (link_command_spec);
9288 : 244439 : if (value < 0)
9289 : 134 : errorcount = 1;
9290 : 244439 : linker_was_run = (tmp != execution_count);
9291 : : }
9292 : :
9293 : : /* If options said don't run linker,
9294 : : complain about input files to be given to the linker. */
9295 : :
9296 : 273132 : if (! linker_was_run && !seen_error ())
9297 : 336311 : for (i = 0; (int) i < n_infiles; i++)
9298 : 183900 : if (explicit_link_files[i]
9299 : 22417 : && !(infiles[i].language && infiles[i].language[0] == '*'))
9300 : : {
9301 : 38 : warning (0, "%s: linker input file unused because linking not done",
9302 : 19 : outfiles[i]);
9303 : 19 : if (access (outfiles[i], F_OK) < 0)
9304 : : /* This is can be an indication the user specifed an errorneous
9305 : : separated option value, (or used the wrong prefix for an
9306 : : option). */
9307 : 7 : error ("%s: linker input file not found: %m", outfiles[i]);
9308 : : }
9309 : 273132 : }
9310 : :
9311 : : /* The end of "main". */
9312 : :
9313 : : void
9314 : 273132 : driver::final_actions () const
9315 : : {
9316 : : /* Delete some or all of the temporary files we made. */
9317 : :
9318 : 273132 : if (seen_error ())
9319 : 28349 : delete_failure_queue ();
9320 : 273132 : delete_temp_files ();
9321 : :
9322 : 273132 : if (totruncate_file != NULL && !seen_error ())
9323 : : /* Truncate file specified by -truncate.
9324 : : Used by lto-wrapper to reduce temporary disk-space usage. */
9325 : 7775 : truncate(totruncate_file, 0);
9326 : :
9327 : 273132 : if (print_help_list)
9328 : : {
9329 : 3 : printf (("\nFor bug reporting instructions, please see:\n"));
9330 : 3 : printf ("%s\n", bug_report_url);
9331 : : }
9332 : 273132 : }
9333 : :
9334 : : /* Detect whether jobserver is active and working. If not drop
9335 : : --jobserver-auth from MAKEFLAGS. */
9336 : :
9337 : : void
9338 : 244439 : driver::detect_jobserver () const
9339 : : {
9340 : 244439 : jobserver_info jinfo;
9341 : 244439 : if (!jinfo.is_active && !jinfo.skipped_makeflags.empty ())
9342 : 0 : xputenv (xstrdup (jinfo.skipped_makeflags.c_str ()));
9343 : 244439 : }
9344 : :
9345 : : /* Determine what the exit code of the driver should be. */
9346 : :
9347 : : int
9348 : 273481 : driver::get_exit_code () const
9349 : : {
9350 : 273481 : return (signal_count != 0 ? 2
9351 : 273481 : : seen_error () ? (pass_exit_codes ? greatest_status : 1)
9352 : 273481 : : 0);
9353 : : }
9354 : :
9355 : : /* Find the proper compilation spec for the file name NAME,
9356 : : whose length is LENGTH. LANGUAGE is the specified language,
9357 : : or 0 if this file is to be passed to the linker. */
9358 : :
9359 : : static struct compiler *
9360 : 1062078 : lookup_compiler (const char *name, size_t length, const char *language)
9361 : : {
9362 : 1551897 : struct compiler *cp;
9363 : :
9364 : : /* If this was specified by the user to be a linker input, indicate that. */
9365 : 1551897 : if (language != 0 && language[0] == '*')
9366 : : return 0;
9367 : :
9368 : : /* Otherwise, look for the language, if one is spec'd. */
9369 : 1095693 : if (language != 0)
9370 : : {
9371 : 21965179 : for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
9372 : 21965179 : if (cp->suffix[0] == '@' && !strcmp (cp->suffix + 1, language))
9373 : : {
9374 : 559110 : if (name != NULL && strcmp (name, "-") == 0
9375 : 2070 : && (strcmp (cp->suffix, "@c-header") == 0
9376 : 2070 : || strcmp (cp->suffix, "@c++-header") == 0)
9377 : 0 : && !have_E)
9378 : 0 : fatal_error (input_location,
9379 : : "cannot use %<-%> as input filename for a "
9380 : : "precompiled header");
9381 : :
9382 : : return cp;
9383 : : }
9384 : :
9385 : 0 : error ("language %s not recognized", language);
9386 : 0 : return 0;
9387 : : }
9388 : :
9389 : : /* Look for a suffix. */
9390 : 29309435 : for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
9391 : : {
9392 : 29262685 : if (/* The suffix `-' matches only the file name `-'. */
9393 : 29262685 : (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
9394 : 29262671 : || (strlen (cp->suffix) < length
9395 : : /* See if the suffix matches the end of NAME. */
9396 : 28877910 : && !strcmp (cp->suffix,
9397 : 28877910 : name + length - strlen (cp->suffix))
9398 : : ))
9399 : : break;
9400 : : }
9401 : :
9402 : : #if defined (OS2) ||defined (HAVE_DOS_BASED_FILE_SYSTEM)
9403 : : /* Look again, but case-insensitively this time. */
9404 : : if (cp < compilers)
9405 : : for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
9406 : : {
9407 : : if (/* The suffix `-' matches only the file name `-'. */
9408 : : (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
9409 : : || (strlen (cp->suffix) < length
9410 : : /* See if the suffix matches the end of NAME. */
9411 : : && ((!strcmp (cp->suffix,
9412 : : name + length - strlen (cp->suffix))
9413 : : || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
9414 : : && !strcasecmp (cp->suffix,
9415 : : name + length - strlen (cp->suffix)))
9416 : : ))
9417 : : break;
9418 : : }
9419 : : #endif
9420 : :
9421 : 536583 : if (cp >= compilers)
9422 : : {
9423 : 489833 : if (cp->spec[0] != '@')
9424 : : /* A non-alias entry: return it. */
9425 : : return cp;
9426 : :
9427 : : /* An alias entry maps a suffix to a language.
9428 : : Search for the language; pass 0 for NAME and LENGTH
9429 : : to avoid infinite recursion if language not found. */
9430 : 489819 : return lookup_compiler (NULL, 0, cp->spec + 1);
9431 : : }
9432 : : return 0;
9433 : : }
9434 : :
9435 : : static char *
9436 : 44571240 : save_string (const char *s, int len)
9437 : : {
9438 : 44571240 : char *result = XNEWVEC (char, len + 1);
9439 : :
9440 : 44571240 : gcc_checking_assert (strlen (s) >= (unsigned int) len);
9441 : 44571240 : memcpy (result, s, len);
9442 : 44571240 : result[len] = 0;
9443 : 44571240 : return result;
9444 : : }
9445 : :
9446 : :
9447 : : static inline void
9448 : 44273922 : validate_switches_from_spec (const char *spec, bool user)
9449 : : {
9450 : 44273922 : const char *p = spec;
9451 : 44273922 : char c;
9452 : 548824140 : while ((c = *p++))
9453 : 460276296 : if (c == '%'
9454 : 460276296 : && (*p == '{'
9455 : 10924734 : || *p == '<'
9456 : 10062255 : || (*p == 'W' && *++p == '{')
9457 : 10062255 : || (*p == '@' && *++p == '{')))
9458 : : /* We have a switch spec. */
9459 : 43698938 : p = validate_switches (p + 1, user, *p == '{');
9460 : 44273922 : }
9461 : :
9462 : : static void
9463 : 287493 : validate_all_switches (void)
9464 : : {
9465 : 287493 : struct compiler *comp;
9466 : 287493 : struct spec_list *spec;
9467 : :
9468 : 31049244 : for (comp = compilers; comp->spec; comp++)
9469 : 30761751 : validate_switches_from_spec (comp->spec, false);
9470 : :
9471 : : /* Look through the linked list of specs read from the specs file. */
9472 : 13512171 : for (spec = specs; spec; spec = spec->next)
9473 : 13224678 : validate_switches_from_spec (*spec->ptr_spec, spec->user_p);
9474 : :
9475 : 287493 : validate_switches_from_spec (link_command_spec, false);
9476 : 287493 : }
9477 : :
9478 : : /* Look at the switch-name that comes after START and mark as valid
9479 : : all supplied switches that match it. If BRACED, handle other
9480 : : switches after '|' and '&', and specs after ':' until ';' or '}',
9481 : : going back for more switches after ';'. Without BRACED, handle
9482 : : only one atom. Return a pointer to whatever follows the handled
9483 : : items, after the closing brace if BRACED. */
9484 : :
9485 : : static const char *
9486 : 186582959 : validate_switches (const char *start, bool user_spec, bool braced)
9487 : : {
9488 : 186582959 : const char *p = start;
9489 : 240919136 : const char *atom;
9490 : 240919136 : size_t len;
9491 : 240919136 : int i;
9492 : 240919136 : bool suffix;
9493 : 240919136 : bool starred;
9494 : :
9495 : : #define SKIP_WHITE() do { while (*p == ' ' || *p == '\t') p++; } while (0)
9496 : :
9497 : 240919136 : next_member:
9498 : 240919136 : suffix = false;
9499 : 240919136 : starred = false;
9500 : :
9501 : 266793506 : SKIP_WHITE ();
9502 : :
9503 : 240919136 : if (*p == '!')
9504 : 73310716 : p++;
9505 : :
9506 : 240919136 : SKIP_WHITE ();
9507 : 240919136 : if (*p == '.' || *p == ',')
9508 : 0 : suffix = true, p++;
9509 : :
9510 : 240919136 : atom = p;
9511 : 240919136 : while (ISIDNUM (*p) || *p == '-' || *p == '+' || *p == '='
9512 : 1594436194 : || *p == ',' || *p == '.' || *p == '@')
9513 : 1353517058 : p++;
9514 : 240919136 : len = p - atom;
9515 : :
9516 : 240919136 : if (*p == '*')
9517 : 63248460 : starred = true, p++;
9518 : :
9519 : 242069108 : SKIP_WHITE ();
9520 : :
9521 : 240919136 : if (!suffix)
9522 : : {
9523 : : /* Mark all matching switches as valid. */
9524 : 5455617184 : for (i = 0; i < n_switches; i++)
9525 : 5214698048 : if (!strncmp (switches[i].part1, atom, len)
9526 : 445283828 : && (starred || switches[i].part1[len] == '\0')
9527 : 46534577 : && (switches[i].known || user_spec))
9528 : 46532819 : switches[i].validated = true;
9529 : : }
9530 : :
9531 : 240919136 : if (!braced)
9532 : : return p;
9533 : :
9534 : 239481671 : if (*p) p++;
9535 : 239481671 : if (*p && (p[-1] == '|' || p[-1] == '&'))
9536 : 36799104 : goto next_member;
9537 : :
9538 : 202682567 : if (*p && p[-1] == ':')
9539 : : {
9540 : 2693234420 : while (*p && *p != ';' && *p != '}')
9541 : : {
9542 : 2537988197 : if (*p == '%')
9543 : : {
9544 : 238619190 : p++;
9545 : 238619190 : if (*p == '{' || *p == '<')
9546 : 140296584 : p = validate_switches (p+1, user_spec, *p == '{');
9547 : 98322606 : else if (p[0] == 'W' && p[1] == '{')
9548 : 2299944 : p = validate_switches (p+2, user_spec, true);
9549 : 96022662 : else if (p[0] == '@' && p[1] == '{')
9550 : 287493 : p = validate_switches (p+2, user_spec, true);
9551 : : }
9552 : : else
9553 : 2299369007 : p++;
9554 : : }
9555 : :
9556 : 155246223 : if (*p) p++;
9557 : 155246223 : if (*p && p[-1] == ';')
9558 : 17537073 : goto next_member;
9559 : : }
9560 : :
9561 : : return p;
9562 : : #undef SKIP_WHITE
9563 : : }
9564 : :
9565 : : struct mdswitchstr
9566 : : {
9567 : : const char *str;
9568 : : int len;
9569 : : };
9570 : :
9571 : : static struct mdswitchstr *mdswitches;
9572 : : static int n_mdswitches;
9573 : :
9574 : : /* Check whether a particular argument was used. The first time we
9575 : : canonicalize the switches to keep only the ones we care about. */
9576 : :
9577 : : struct used_arg_t
9578 : : {
9579 : : public:
9580 : : int operator () (const char *p, int len);
9581 : : void finalize ();
9582 : :
9583 : : private:
9584 : : struct mswitchstr
9585 : : {
9586 : : const char *str;
9587 : : const char *replace;
9588 : : int len;
9589 : : int rep_len;
9590 : : };
9591 : :
9592 : : mswitchstr *mswitches;
9593 : : int n_mswitches;
9594 : :
9595 : : };
9596 : :
9597 : : used_arg_t used_arg;
9598 : :
9599 : : int
9600 : 1738289 : used_arg_t::operator () (const char *p, int len)
9601 : : {
9602 : 1738289 : int i, j;
9603 : :
9604 : 1738289 : if (!mswitches)
9605 : : {
9606 : 287493 : struct mswitchstr *matches;
9607 : 287493 : const char *q;
9608 : 287493 : int cnt = 0;
9609 : :
9610 : : /* Break multilib_matches into the component strings of string
9611 : : and replacement string. */
9612 : 4887381 : for (q = multilib_matches; *q != '\0'; q++)
9613 : 4599888 : if (*q == ';')
9614 : 574986 : cnt++;
9615 : :
9616 : 287493 : matches
9617 : 287493 : = (struct mswitchstr *) alloca ((sizeof (struct mswitchstr)) * cnt);
9618 : 287493 : i = 0;
9619 : 287493 : q = multilib_matches;
9620 : 862479 : while (*q != '\0')
9621 : : {
9622 : 574986 : matches[i].str = q;
9623 : 2299944 : while (*q != ' ')
9624 : : {
9625 : 1724958 : if (*q == '\0')
9626 : : {
9627 : 0 : invalid_matches:
9628 : 0 : fatal_error (input_location, "multilib spec %qs is invalid",
9629 : : multilib_matches);
9630 : : }
9631 : 1724958 : q++;
9632 : : }
9633 : 574986 : matches[i].len = q - matches[i].str;
9634 : :
9635 : 574986 : matches[i].replace = ++q;
9636 : 2299944 : while (*q != ';' && *q != '\0')
9637 : : {
9638 : 1724958 : if (*q == ' ')
9639 : 0 : goto invalid_matches;
9640 : 1724958 : q++;
9641 : : }
9642 : 574986 : matches[i].rep_len = q - matches[i].replace;
9643 : 574986 : i++;
9644 : 574986 : if (*q == ';')
9645 : 574986 : q++;
9646 : : }
9647 : :
9648 : : /* Now build a list of the replacement string for switches that we care
9649 : : about. Make sure we allocate at least one entry. This prevents
9650 : : xmalloc from calling fatal, and prevents us from re-executing this
9651 : : block of code. */
9652 : 287493 : mswitches
9653 : 574986 : = XNEWVEC (struct mswitchstr, n_mdswitches + (n_switches ? n_switches : 1));
9654 : 6510283 : for (i = 0; i < n_switches; i++)
9655 : 6222790 : if ((switches[i].live_cond & SWITCH_IGNORE) == 0)
9656 : : {
9657 : 6222784 : int xlen = strlen (switches[i].part1);
9658 : 18655699 : for (j = 0; j < cnt; j++)
9659 : 12443173 : if (xlen == matches[j].len
9660 : 18943 : && ! strncmp (switches[i].part1, matches[j].str, xlen))
9661 : : {
9662 : 10258 : mswitches[n_mswitches].str = matches[j].replace;
9663 : 10258 : mswitches[n_mswitches].len = matches[j].rep_len;
9664 : 10258 : mswitches[n_mswitches].replace = (char *) 0;
9665 : 10258 : mswitches[n_mswitches].rep_len = 0;
9666 : 10258 : n_mswitches++;
9667 : 10258 : break;
9668 : : }
9669 : : }
9670 : :
9671 : : /* Add MULTILIB_DEFAULTS switches too, as long as they were not present
9672 : : on the command line nor any options mutually incompatible with
9673 : : them. */
9674 : 574986 : for (i = 0; i < n_mdswitches; i++)
9675 : : {
9676 : 287493 : const char *r;
9677 : :
9678 : 574986 : for (q = multilib_options; *q != '\0'; *q && q++)
9679 : : {
9680 : 287493 : while (*q == ' ')
9681 : 0 : q++;
9682 : :
9683 : 287493 : r = q;
9684 : 287493 : while (strncmp (q, mdswitches[i].str, mdswitches[i].len) != 0
9685 : 287493 : || strchr (" /", q[mdswitches[i].len]) == NULL)
9686 : : {
9687 : 0 : while (*q != ' ' && *q != '/' && *q != '\0')
9688 : 0 : q++;
9689 : 0 : if (*q != '/')
9690 : : break;
9691 : 0 : q++;
9692 : : }
9693 : :
9694 : 287493 : if (*q != ' ' && *q != '\0')
9695 : : {
9696 : 572591 : while (*r != ' ' && *r != '\0')
9697 : : {
9698 : : q = r;
9699 : 2290364 : while (*q != ' ' && *q != '/' && *q != '\0')
9700 : 1717773 : q++;
9701 : :
9702 : 572591 : if (used_arg (r, q - r))
9703 : : break;
9704 : :
9705 : 562333 : if (*q != '/')
9706 : : {
9707 : 277235 : mswitches[n_mswitches].str = mdswitches[i].str;
9708 : 277235 : mswitches[n_mswitches].len = mdswitches[i].len;
9709 : 277235 : mswitches[n_mswitches].replace = (char *) 0;
9710 : 277235 : mswitches[n_mswitches].rep_len = 0;
9711 : 277235 : n_mswitches++;
9712 : 277235 : break;
9713 : : }
9714 : :
9715 : 285098 : r = q + 1;
9716 : : }
9717 : : break;
9718 : : }
9719 : : }
9720 : : }
9721 : : }
9722 : :
9723 : 2329001 : for (i = 0; i < n_mswitches; i++)
9724 : 1183819 : if (len == mswitches[i].len && ! strncmp (p, mswitches[i].str, len))
9725 : : return 1;
9726 : :
9727 : : return 0;
9728 : : }
9729 : :
9730 : 1094 : void used_arg_t::finalize ()
9731 : : {
9732 : 1094 : XDELETEVEC (mswitches);
9733 : 1094 : mswitches = NULL;
9734 : 1094 : n_mswitches = 0;
9735 : 1094 : }
9736 : :
9737 : :
9738 : : static int
9739 : 1184042 : default_arg (const char *p, int len)
9740 : : {
9741 : 1184042 : int i;
9742 : :
9743 : 1771477 : for (i = 0; i < n_mdswitches; i++)
9744 : 1184042 : if (len == mdswitches[i].len && ! strncmp (p, mdswitches[i].str, len))
9745 : : return 1;
9746 : :
9747 : : return 0;
9748 : : }
9749 : :
9750 : : /* Work out the subdirectory to use based on the options. The format of
9751 : : multilib_select is a list of elements. Each element is a subdirectory
9752 : : name followed by a list of options followed by a semicolon. The format
9753 : : of multilib_exclusions is the same, but without the preceding
9754 : : directory. First gcc will check the exclusions, if none of the options
9755 : : beginning with an exclamation point are present, and all of the other
9756 : : options are present, then we will ignore this completely. Passing
9757 : : that, gcc will consider each multilib_select in turn using the same
9758 : : rules for matching the options. If a match is found, that subdirectory
9759 : : will be used.
9760 : : A subdirectory name is optionally followed by a colon and the corresponding
9761 : : multiarch name. */
9762 : :
9763 : : static void
9764 : 287493 : set_multilib_dir (void)
9765 : : {
9766 : 287493 : const char *p;
9767 : 287493 : unsigned int this_path_len;
9768 : 287493 : const char *this_path, *this_arg;
9769 : 287493 : const char *start, *end;
9770 : 287493 : int not_arg;
9771 : 287493 : int ok, ndfltok, first;
9772 : :
9773 : 287493 : n_mdswitches = 0;
9774 : 287493 : start = multilib_defaults;
9775 : 287493 : while (*start == ' ' || *start == '\t')
9776 : 0 : start++;
9777 : 574986 : while (*start != '\0')
9778 : : {
9779 : 287493 : n_mdswitches++;
9780 : 1149972 : while (*start != ' ' && *start != '\t' && *start != '\0')
9781 : 862479 : start++;
9782 : 287493 : while (*start == ' ' || *start == '\t')
9783 : 0 : start++;
9784 : : }
9785 : :
9786 : 287493 : if (n_mdswitches)
9787 : : {
9788 : 287493 : int i = 0;
9789 : :
9790 : 287493 : mdswitches = XNEWVEC (struct mdswitchstr, n_mdswitches);
9791 : 287493 : for (start = multilib_defaults; *start != '\0'; start = end + 1)
9792 : : {
9793 : 287493 : while (*start == ' ' || *start == '\t')
9794 : 0 : start++;
9795 : :
9796 : 287493 : if (*start == '\0')
9797 : : break;
9798 : :
9799 : 862479 : for (end = start + 1;
9800 : 862479 : *end != ' ' && *end != '\t' && *end != '\0'; end++)
9801 : : ;
9802 : :
9803 : 287493 : obstack_grow (&multilib_obstack, start, end - start);
9804 : 287493 : obstack_1grow (&multilib_obstack, 0);
9805 : 287493 : mdswitches[i].str = XOBFINISH (&multilib_obstack, const char *);
9806 : 287493 : mdswitches[i++].len = end - start;
9807 : :
9808 : 287493 : if (*end == '\0')
9809 : : break;
9810 : : }
9811 : : }
9812 : :
9813 : 287493 : p = multilib_exclusions;
9814 : 287493 : while (*p != '\0')
9815 : : {
9816 : : /* Ignore newlines. */
9817 : 0 : if (*p == '\n')
9818 : : {
9819 : 0 : ++p;
9820 : 0 : continue;
9821 : : }
9822 : :
9823 : : /* Check the arguments. */
9824 : : ok = 1;
9825 : 0 : while (*p != ';')
9826 : : {
9827 : 0 : if (*p == '\0')
9828 : : {
9829 : 0 : invalid_exclusions:
9830 : 0 : fatal_error (input_location, "multilib exclusions %qs is invalid",
9831 : : multilib_exclusions);
9832 : : }
9833 : :
9834 : 0 : if (! ok)
9835 : : {
9836 : 0 : ++p;
9837 : 0 : continue;
9838 : : }
9839 : :
9840 : 0 : this_arg = p;
9841 : 0 : while (*p != ' ' && *p != ';')
9842 : : {
9843 : 0 : if (*p == '\0')
9844 : 0 : goto invalid_exclusions;
9845 : 0 : ++p;
9846 : : }
9847 : :
9848 : 0 : if (*this_arg != '!')
9849 : : not_arg = 0;
9850 : : else
9851 : : {
9852 : 0 : not_arg = 1;
9853 : 0 : ++this_arg;
9854 : : }
9855 : :
9856 : 0 : ok = used_arg (this_arg, p - this_arg);
9857 : 0 : if (not_arg)
9858 : 0 : ok = ! ok;
9859 : :
9860 : 0 : if (*p == ' ')
9861 : 0 : ++p;
9862 : : }
9863 : :
9864 : 0 : if (ok)
9865 : : return;
9866 : :
9867 : 0 : ++p;
9868 : : }
9869 : :
9870 : 287493 : first = 1;
9871 : 287493 : p = multilib_select;
9872 : :
9873 : : /* Append multilib reuse rules if any. With those rules, we can reuse
9874 : : one multilib for certain different options sets. */
9875 : 287493 : if (strlen (multilib_reuse) > 0)
9876 : 0 : p = concat (p, multilib_reuse, NULL);
9877 : :
9878 : 582849 : while (*p != '\0')
9879 : : {
9880 : : /* Ignore newlines. */
9881 : 582849 : if (*p == '\n')
9882 : : {
9883 : 0 : ++p;
9884 : 0 : continue;
9885 : : }
9886 : :
9887 : : /* Get the initial path. */
9888 : : this_path = p;
9889 : 4103532 : while (*p != ' ')
9890 : : {
9891 : 3520683 : if (*p == '\0')
9892 : : {
9893 : 0 : invalid_select:
9894 : 0 : fatal_error (input_location, "multilib select %qs %qs is invalid",
9895 : : multilib_select, multilib_reuse);
9896 : : }
9897 : 3520683 : ++p;
9898 : : }
9899 : 582849 : this_path_len = p - this_path;
9900 : :
9901 : : /* Check the arguments. */
9902 : 582849 : ok = 1;
9903 : 582849 : ndfltok = 1;
9904 : 582849 : ++p;
9905 : 1748547 : while (*p != ';')
9906 : : {
9907 : 1165698 : if (*p == '\0')
9908 : 0 : goto invalid_select;
9909 : :
9910 : 1165698 : if (! ok)
9911 : : {
9912 : 0 : ++p;
9913 : 0 : continue;
9914 : : }
9915 : :
9916 : 5533134 : this_arg = p;
9917 : 5533134 : while (*p != ' ' && *p != ';')
9918 : : {
9919 : 4367436 : if (*p == '\0')
9920 : 0 : goto invalid_select;
9921 : 4367436 : ++p;
9922 : : }
9923 : :
9924 : 1165698 : if (*this_arg != '!')
9925 : : not_arg = 0;
9926 : : else
9927 : : {
9928 : 870342 : not_arg = 1;
9929 : 870342 : ++this_arg;
9930 : : }
9931 : :
9932 : : /* If this is a default argument, we can just ignore it.
9933 : : This is true even if this_arg begins with '!'. Beginning
9934 : : with '!' does not mean that this argument is necessarily
9935 : : inappropriate for this library: it merely means that
9936 : : there is a more specific library which uses this
9937 : : argument. If this argument is a default, we need not
9938 : : consider that more specific library. */
9939 : 1165698 : ok = used_arg (this_arg, p - this_arg);
9940 : 1165698 : if (not_arg)
9941 : 870342 : ok = ! ok;
9942 : :
9943 : 1165698 : if (! ok)
9944 : 303219 : ndfltok = 0;
9945 : :
9946 : 1165698 : if (default_arg (this_arg, p - this_arg))
9947 : 582849 : ok = 1;
9948 : :
9949 : 1165698 : if (*p == ' ')
9950 : 582849 : ++p;
9951 : : }
9952 : :
9953 : 582849 : if (ok && first)
9954 : : {
9955 : 287493 : if (this_path_len != 1
9956 : 279630 : || this_path[0] != '.')
9957 : : {
9958 : 7863 : char *new_multilib_dir = XNEWVEC (char, this_path_len + 1);
9959 : 7863 : char *q;
9960 : :
9961 : 7863 : strncpy (new_multilib_dir, this_path, this_path_len);
9962 : 7863 : new_multilib_dir[this_path_len] = '\0';
9963 : 7863 : q = strchr (new_multilib_dir, ':');
9964 : 7863 : if (q != NULL)
9965 : 7863 : *q = '\0';
9966 : 7863 : multilib_dir = new_multilib_dir;
9967 : : }
9968 : : first = 0;
9969 : : }
9970 : :
9971 : 582849 : if (ndfltok)
9972 : : {
9973 : 287493 : const char *q = this_path, *end = this_path + this_path_len;
9974 : :
9975 : 862479 : while (q < end && *q != ':')
9976 : 574986 : q++;
9977 : 287493 : if (q < end)
9978 : : {
9979 : 287493 : const char *q2 = q + 1, *ml_end = end;
9980 : 287493 : char *new_multilib_os_dir;
9981 : :
9982 : 2571711 : while (q2 < end && *q2 != ':')
9983 : 2284218 : q2++;
9984 : 287493 : if (*q2 == ':')
9985 : 0 : ml_end = q2;
9986 : 287493 : if (ml_end - q == 1)
9987 : 0 : multilib_os_dir = xstrdup (".");
9988 : : else
9989 : : {
9990 : 287493 : new_multilib_os_dir = XNEWVEC (char, ml_end - q);
9991 : 287493 : memcpy (new_multilib_os_dir, q + 1, ml_end - q - 1);
9992 : 287493 : new_multilib_os_dir[ml_end - q - 1] = '\0';
9993 : 287493 : multilib_os_dir = new_multilib_os_dir;
9994 : : }
9995 : :
9996 : 287493 : if (q2 < end && *q2 == ':')
9997 : : {
9998 : 0 : char *new_multiarch_dir = XNEWVEC (char, end - q2);
9999 : 0 : memcpy (new_multiarch_dir, q2 + 1, end - q2 - 1);
10000 : 0 : new_multiarch_dir[end - q2 - 1] = '\0';
10001 : 0 : multiarch_dir = new_multiarch_dir;
10002 : : }
10003 : : break;
10004 : : }
10005 : : }
10006 : :
10007 : 295356 : ++p;
10008 : : }
10009 : :
10010 : 574986 : multilib_dir =
10011 : 287493 : targetm_common.compute_multilib (
10012 : : switches,
10013 : : n_switches,
10014 : : multilib_dir,
10015 : : multilib_defaults,
10016 : : multilib_select,
10017 : : multilib_matches,
10018 : : multilib_exclusions,
10019 : : multilib_reuse);
10020 : :
10021 : 287493 : if (multilib_dir == NULL && multilib_os_dir != NULL
10022 : 279630 : && strcmp (multilib_os_dir, ".") == 0)
10023 : : {
10024 : 0 : free (CONST_CAST (char *, multilib_os_dir));
10025 : 0 : multilib_os_dir = NULL;
10026 : : }
10027 : 287493 : else if (multilib_dir != NULL && multilib_os_dir == NULL)
10028 : 0 : multilib_os_dir = multilib_dir;
10029 : : }
10030 : :
10031 : : /* Print out the multiple library subdirectory selection
10032 : : information. This prints out a series of lines. Each line looks
10033 : : like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
10034 : : required. Only the desired options are printed out, the negative
10035 : : matches. The options are print without a leading dash. There are
10036 : : no spaces to make it easy to use the information in the shell.
10037 : : Each subdirectory is printed only once. This assumes the ordering
10038 : : generated by the genmultilib script. Also, we leave out ones that match
10039 : : the exclusions. */
10040 : :
10041 : : static void
10042 : 4586 : print_multilib_info (void)
10043 : : {
10044 : 4586 : const char *p = multilib_select;
10045 : 4586 : const char *last_path = 0, *this_path;
10046 : 4586 : int skip;
10047 : 4586 : int not_arg;
10048 : 4586 : unsigned int last_path_len = 0;
10049 : :
10050 : 18344 : while (*p != '\0')
10051 : : {
10052 : 13758 : skip = 0;
10053 : : /* Ignore newlines. */
10054 : 13758 : if (*p == '\n')
10055 : : {
10056 : 0 : ++p;
10057 : 0 : continue;
10058 : : }
10059 : :
10060 : : /* Get the initial path. */
10061 : : this_path = p;
10062 : 110064 : while (*p != ' ')
10063 : : {
10064 : 96306 : if (*p == '\0')
10065 : : {
10066 : 0 : invalid_select:
10067 : 0 : fatal_error (input_location,
10068 : : "multilib select %qs is invalid", multilib_select);
10069 : : }
10070 : :
10071 : 96306 : ++p;
10072 : : }
10073 : :
10074 : : /* When --disable-multilib was used but target defines
10075 : : MULTILIB_OSDIRNAMES, entries starting with .: (and not starting
10076 : : with .:: for multiarch configurations) are there just to find
10077 : : multilib_os_dir, so skip them from output. */
10078 : 13758 : if (this_path[0] == '.' && this_path[1] == ':' && this_path[2] != ':')
10079 : 13758 : skip = 1;
10080 : :
10081 : : /* Check for matches with the multilib_exclusions. We don't bother
10082 : : with the '!' in either list. If any of the exclusion rules match
10083 : : all of its options with the select rule, we skip it. */
10084 : 13758 : {
10085 : 13758 : const char *e = multilib_exclusions;
10086 : 13758 : const char *this_arg;
10087 : :
10088 : 13758 : while (*e != '\0')
10089 : : {
10090 : 0 : int m = 1;
10091 : : /* Ignore newlines. */
10092 : 0 : if (*e == '\n')
10093 : : {
10094 : 0 : ++e;
10095 : 0 : continue;
10096 : : }
10097 : :
10098 : : /* Check the arguments. */
10099 : 0 : while (*e != ';')
10100 : : {
10101 : 0 : const char *q;
10102 : 0 : int mp = 0;
10103 : :
10104 : 0 : if (*e == '\0')
10105 : : {
10106 : 0 : invalid_exclusion:
10107 : 0 : fatal_error (input_location,
10108 : : "multilib exclusion %qs is invalid",
10109 : : multilib_exclusions);
10110 : : }
10111 : :
10112 : 0 : if (! m)
10113 : : {
10114 : 0 : ++e;
10115 : 0 : continue;
10116 : : }
10117 : :
10118 : : this_arg = e;
10119 : :
10120 : 0 : while (*e != ' ' && *e != ';')
10121 : : {
10122 : 0 : if (*e == '\0')
10123 : 0 : goto invalid_exclusion;
10124 : 0 : ++e;
10125 : : }
10126 : :
10127 : 0 : q = p + 1;
10128 : 0 : while (*q != ';')
10129 : : {
10130 : 0 : const char *arg;
10131 : 0 : int len = e - this_arg;
10132 : :
10133 : 0 : if (*q == '\0')
10134 : 0 : goto invalid_select;
10135 : :
10136 : : arg = q;
10137 : :
10138 : 0 : while (*q != ' ' && *q != ';')
10139 : : {
10140 : 0 : if (*q == '\0')
10141 : 0 : goto invalid_select;
10142 : 0 : ++q;
10143 : : }
10144 : :
10145 : 0 : if (! strncmp (arg, this_arg,
10146 : 0 : (len < q - arg) ? q - arg : len)
10147 : 0 : || default_arg (this_arg, e - this_arg))
10148 : : {
10149 : : mp = 1;
10150 : : break;
10151 : : }
10152 : :
10153 : 0 : if (*q == ' ')
10154 : 0 : ++q;
10155 : : }
10156 : :
10157 : 0 : if (! mp)
10158 : 0 : m = 0;
10159 : :
10160 : 0 : if (*e == ' ')
10161 : 0 : ++e;
10162 : : }
10163 : :
10164 : 0 : if (m)
10165 : : {
10166 : : skip = 1;
10167 : : break;
10168 : : }
10169 : :
10170 : 0 : if (*e != '\0')
10171 : 0 : ++e;
10172 : : }
10173 : : }
10174 : :
10175 : 13758 : if (! skip)
10176 : : {
10177 : : /* If this is a duplicate, skip it. */
10178 : 27516 : skip = (last_path != 0
10179 : 9172 : && (unsigned int) (p - this_path) == last_path_len
10180 : 13758 : && ! filename_ncmp (last_path, this_path, last_path_len));
10181 : :
10182 : 13758 : last_path = this_path;
10183 : 13758 : last_path_len = p - this_path;
10184 : : }
10185 : :
10186 : : /* If all required arguments are default arguments, and no default
10187 : : arguments appear in the ! argument list, then we can skip it.
10188 : : We will already have printed a directory identical to this one
10189 : : which does not require that default argument. */
10190 : 13758 : if (! skip)
10191 : : {
10192 : 13758 : const char *q;
10193 : 13758 : bool default_arg_ok = false;
10194 : :
10195 : 13758 : q = p + 1;
10196 : 22930 : while (*q != ';')
10197 : : {
10198 : 18344 : const char *arg;
10199 : :
10200 : 18344 : if (*q == '\0')
10201 : 0 : goto invalid_select;
10202 : :
10203 : 18344 : if (*q == '!')
10204 : : {
10205 : 13758 : not_arg = 1;
10206 : 13758 : q++;
10207 : : }
10208 : : else
10209 : : not_arg = 0;
10210 : 18344 : arg = q;
10211 : :
10212 : 73376 : while (*q != ' ' && *q != ';')
10213 : : {
10214 : 55032 : if (*q == '\0')
10215 : 0 : goto invalid_select;
10216 : 55032 : ++q;
10217 : : }
10218 : :
10219 : 18344 : if (default_arg (arg, q - arg))
10220 : : {
10221 : : /* Stop checking if any default arguments appeared in not
10222 : : list. */
10223 : 13758 : if (not_arg)
10224 : : {
10225 : : default_arg_ok = false;
10226 : : break;
10227 : : }
10228 : :
10229 : : default_arg_ok = true;
10230 : : }
10231 : 4586 : else if (!not_arg)
10232 : : {
10233 : : /* Stop checking if any required argument is not provided by
10234 : : default arguments. */
10235 : : default_arg_ok = false;
10236 : : break;
10237 : : }
10238 : :
10239 : 9172 : if (*q == ' ')
10240 : 4586 : ++q;
10241 : : }
10242 : :
10243 : : /* Make sure all default argument is OK for this multi-lib set. */
10244 : 13758 : if (default_arg_ok)
10245 : : skip = 1;
10246 : : else
10247 : : skip = 0;
10248 : : }
10249 : :
10250 : : if (! skip)
10251 : : {
10252 : : const char *p1;
10253 : :
10254 : 22930 : for (p1 = last_path; p1 < p && *p1 != ':'; p1++)
10255 : 13758 : putchar (*p1);
10256 : 9172 : putchar (';');
10257 : : }
10258 : :
10259 : 13758 : ++p;
10260 : 68790 : while (*p != ';')
10261 : : {
10262 : 55032 : int use_arg;
10263 : :
10264 : 55032 : if (*p == '\0')
10265 : 0 : goto invalid_select;
10266 : :
10267 : 55032 : if (skip)
10268 : : {
10269 : 36688 : ++p;
10270 : 36688 : continue;
10271 : : }
10272 : :
10273 : 18344 : use_arg = *p != '!';
10274 : :
10275 : 18344 : if (use_arg)
10276 : 4586 : putchar ('@');
10277 : :
10278 : 87134 : while (*p != ' ' && *p != ';')
10279 : : {
10280 : 68790 : if (*p == '\0')
10281 : 0 : goto invalid_select;
10282 : 68790 : if (use_arg)
10283 : 13758 : putchar (*p);
10284 : 68790 : ++p;
10285 : : }
10286 : :
10287 : 18344 : if (*p == ' ')
10288 : 9172 : ++p;
10289 : : }
10290 : :
10291 : 13758 : if (! skip)
10292 : : {
10293 : : /* If there are extra options, print them now. */
10294 : 9172 : if (multilib_extra && *multilib_extra)
10295 : : {
10296 : : int print_at = true;
10297 : : const char *q;
10298 : :
10299 : 0 : for (q = multilib_extra; *q != '\0'; q++)
10300 : : {
10301 : 0 : if (*q == ' ')
10302 : : print_at = true;
10303 : : else
10304 : : {
10305 : 0 : if (print_at)
10306 : 0 : putchar ('@');
10307 : 0 : putchar (*q);
10308 : 0 : print_at = false;
10309 : : }
10310 : : }
10311 : : }
10312 : :
10313 : 9172 : putchar ('\n');
10314 : : }
10315 : :
10316 : 13758 : ++p;
10317 : : }
10318 : 4586 : }
10319 : :
10320 : : /* getenv built-in spec function.
10321 : :
10322 : : Returns the value of the environment variable given by its first argument,
10323 : : concatenated with the second argument. If the variable is not defined, a
10324 : : fatal error is issued unless such undefs are internally allowed, in which
10325 : : case the variable name prefixed by a '/' is used as the variable value.
10326 : :
10327 : : The leading '/' allows using the result at a spot where a full path would
10328 : : normally be expected and when the actual value doesn't really matter since
10329 : : undef vars are allowed. */
10330 : :
10331 : : static const char *
10332 : 0 : getenv_spec_function (int argc, const char **argv)
10333 : : {
10334 : 0 : const char *value;
10335 : 0 : const char *varname;
10336 : :
10337 : 0 : char *result;
10338 : 0 : char *ptr;
10339 : 0 : size_t len;
10340 : :
10341 : 0 : if (argc != 2)
10342 : : return NULL;
10343 : :
10344 : 0 : varname = argv[0];
10345 : 0 : value = env.get (varname);
10346 : :
10347 : : /* If the variable isn't defined and this is allowed, craft our expected
10348 : : return value. Assume variable names used in specs strings don't contain
10349 : : any active spec character so don't need escaping. */
10350 : 0 : if (!value && spec_undefvar_allowed)
10351 : : {
10352 : 0 : result = XNEWVAR (char, strlen(varname) + 2);
10353 : 0 : sprintf (result, "/%s", varname);
10354 : 0 : return result;
10355 : : }
10356 : :
10357 : 0 : if (!value)
10358 : 0 : fatal_error (input_location,
10359 : : "environment variable %qs not defined", varname);
10360 : :
10361 : : /* We have to escape every character of the environment variable so
10362 : : they are not interpreted as active spec characters. A
10363 : : particularly painful case is when we are reading a variable
10364 : : holding a windows path complete with \ separators. */
10365 : 0 : len = strlen (value) * 2 + strlen (argv[1]) + 1;
10366 : 0 : result = XNEWVAR (char, len);
10367 : 0 : for (ptr = result; *value; ptr += 2)
10368 : : {
10369 : 0 : ptr[0] = '\\';
10370 : 0 : ptr[1] = *value++;
10371 : : }
10372 : :
10373 : 0 : strcpy (ptr, argv[1]);
10374 : :
10375 : 0 : return result;
10376 : : }
10377 : :
10378 : : /* if-exists built-in spec function.
10379 : :
10380 : : Checks to see if the file specified by the absolute pathname in
10381 : : ARGS exists. Returns that pathname if found.
10382 : :
10383 : : The usual use for this function is to check for a library file
10384 : : (whose name has been expanded with %s). */
10385 : :
10386 : : static const char *
10387 : 0 : if_exists_spec_function (int argc, const char **argv)
10388 : : {
10389 : : /* Must have only one argument. */
10390 : 0 : if (argc == 1 && IS_ABSOLUTE_PATH (argv[0]) && ! access (argv[0], R_OK))
10391 : 0 : return argv[0];
10392 : :
10393 : : return NULL;
10394 : : }
10395 : :
10396 : : /* if-exists-else built-in spec function.
10397 : :
10398 : : This is like if-exists, but takes an additional argument which
10399 : : is returned if the first argument does not exist. */
10400 : :
10401 : : static const char *
10402 : 0 : if_exists_else_spec_function (int argc, const char **argv)
10403 : : {
10404 : : /* Must have exactly two arguments. */
10405 : 0 : if (argc != 2)
10406 : : return NULL;
10407 : :
10408 : 0 : if (IS_ABSOLUTE_PATH (argv[0]) && ! access (argv[0], R_OK))
10409 : 0 : return argv[0];
10410 : :
10411 : 0 : return argv[1];
10412 : : }
10413 : :
10414 : : /* if-exists-then-else built-in spec function.
10415 : :
10416 : : Checks to see if the file specified by the absolute pathname in
10417 : : the first arg exists. Returns the second arg if so, otherwise returns
10418 : : the third arg if it is present. */
10419 : :
10420 : : static const char *
10421 : 0 : if_exists_then_else_spec_function (int argc, const char **argv)
10422 : : {
10423 : :
10424 : : /* Must have two or three arguments. */
10425 : 0 : if (argc != 2 && argc != 3)
10426 : : return NULL;
10427 : :
10428 : 0 : if (IS_ABSOLUTE_PATH (argv[0]) && ! access (argv[0], R_OK))
10429 : 0 : return argv[1];
10430 : :
10431 : 0 : if (argc == 3)
10432 : 0 : return argv[2];
10433 : :
10434 : : return NULL;
10435 : : }
10436 : :
10437 : : /* sanitize built-in spec function.
10438 : :
10439 : : This returns non-NULL, if sanitizing address, thread or
10440 : : any of the undefined behavior sanitizers. */
10441 : :
10442 : : static const char *
10443 : 830736 : sanitize_spec_function (int argc, const char **argv)
10444 : : {
10445 : 830736 : if (argc != 1)
10446 : : return NULL;
10447 : :
10448 : 830736 : if (strcmp (argv[0], "address") == 0)
10449 : 366696 : return (flag_sanitize & SANITIZE_USER_ADDRESS) ? "" : NULL;
10450 : 646128 : if (strcmp (argv[0], "hwaddress") == 0)
10451 : 369012 : return (flag_sanitize & SANITIZE_USER_HWADDRESS) ? "" : NULL;
10452 : 461520 : if (strcmp (argv[0], "kernel-address") == 0)
10453 : 0 : return (flag_sanitize & SANITIZE_KERNEL_ADDRESS) ? "" : NULL;
10454 : 461520 : if (strcmp (argv[0], "kernel-hwaddress") == 0)
10455 : 0 : return (flag_sanitize & SANITIZE_KERNEL_HWADDRESS) ? "" : NULL;
10456 : 461520 : if (strcmp (argv[0], "thread") == 0)
10457 : 368800 : return (flag_sanitize & SANITIZE_THREAD) ? "" : NULL;
10458 : 276912 : if (strcmp (argv[0], "undefined") == 0)
10459 : 92304 : return ((flag_sanitize
10460 : 92304 : & ~flag_sanitize_trap
10461 : 92304 : & (SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT)))
10462 : 182834 : ? "" : NULL;
10463 : 184608 : if (strcmp (argv[0], "leak") == 0)
10464 : 184608 : return ((flag_sanitize
10465 : 184608 : & (SANITIZE_ADDRESS | SANITIZE_LEAK | SANITIZE_THREAD))
10466 : 369216 : == SANITIZE_LEAK) ? "" : NULL;
10467 : : return NULL;
10468 : : }
10469 : :
10470 : : /* replace-outfile built-in spec function.
10471 : :
10472 : : This looks for the first argument in the outfiles array's name and
10473 : : replaces it with the second argument. */
10474 : :
10475 : : static const char *
10476 : 0 : replace_outfile_spec_function (int argc, const char **argv)
10477 : : {
10478 : 0 : int i;
10479 : : /* Must have exactly two arguments. */
10480 : 0 : if (argc != 2)
10481 : 0 : abort ();
10482 : :
10483 : 0 : for (i = 0; i < n_infiles; i++)
10484 : : {
10485 : 0 : if (outfiles[i] && !filename_cmp (outfiles[i], argv[0]))
10486 : 0 : outfiles[i] = xstrdup (argv[1]);
10487 : : }
10488 : 0 : return NULL;
10489 : : }
10490 : :
10491 : : /* remove-outfile built-in spec function.
10492 : : *
10493 : : * This looks for the first argument in the outfiles array's name and
10494 : : * removes it. */
10495 : :
10496 : : static const char *
10497 : 0 : remove_outfile_spec_function (int argc, const char **argv)
10498 : : {
10499 : 0 : int i;
10500 : : /* Must have exactly one argument. */
10501 : 0 : if (argc != 1)
10502 : 0 : abort ();
10503 : :
10504 : 0 : for (i = 0; i < n_infiles; i++)
10505 : : {
10506 : 0 : if (outfiles[i] && !filename_cmp (outfiles[i], argv[0]))
10507 : 0 : outfiles[i] = NULL;
10508 : : }
10509 : 0 : return NULL;
10510 : : }
10511 : :
10512 : : /* Given two version numbers, compares the two numbers.
10513 : : A version number must match the regular expression
10514 : : ([1-9][0-9]*|0)(\.([1-9][0-9]*|0))*
10515 : : */
10516 : : static int
10517 : 0 : compare_version_strings (const char *v1, const char *v2)
10518 : : {
10519 : 0 : int rresult;
10520 : 0 : regex_t r;
10521 : :
10522 : 0 : if (regcomp (&r, "^([1-9][0-9]*|0)(\\.([1-9][0-9]*|0))*$",
10523 : : REG_EXTENDED | REG_NOSUB) != 0)
10524 : 0 : abort ();
10525 : 0 : rresult = regexec (&r, v1, 0, NULL, 0);
10526 : 0 : if (rresult == REG_NOMATCH)
10527 : 0 : fatal_error (input_location, "invalid version number %qs", v1);
10528 : 0 : else if (rresult != 0)
10529 : 0 : abort ();
10530 : 0 : rresult = regexec (&r, v2, 0, NULL, 0);
10531 : 0 : if (rresult == REG_NOMATCH)
10532 : 0 : fatal_error (input_location, "invalid version number %qs", v2);
10533 : 0 : else if (rresult != 0)
10534 : 0 : abort ();
10535 : :
10536 : 0 : return strverscmp (v1, v2);
10537 : : }
10538 : :
10539 : :
10540 : : /* version_compare built-in spec function.
10541 : :
10542 : : This takes an argument of the following form:
10543 : :
10544 : : <comparison-op> <arg1> [<arg2>] <switch> <result>
10545 : :
10546 : : and produces "result" if the comparison evaluates to true,
10547 : : and nothing if it doesn't.
10548 : :
10549 : : The supported <comparison-op> values are:
10550 : :
10551 : : >= true if switch is a later (or same) version than arg1
10552 : : !> opposite of >=
10553 : : < true if switch is an earlier version than arg1
10554 : : !< opposite of <
10555 : : >< true if switch is arg1 or later, and earlier than arg2
10556 : : <> true if switch is earlier than arg1 or is arg2 or later
10557 : :
10558 : : If the switch is not present, the condition is false unless
10559 : : the first character of the <comparison-op> is '!'.
10560 : :
10561 : : For example,
10562 : : %:version-compare(>= 10.3 mmacosx-version-min= -lmx)
10563 : : adds -lmx if -mmacosx-version-min=10.3.9 was passed. */
10564 : :
10565 : : static const char *
10566 : 0 : version_compare_spec_function (int argc, const char **argv)
10567 : : {
10568 : 0 : int comp1, comp2;
10569 : 0 : size_t switch_len;
10570 : 0 : const char *switch_value = NULL;
10571 : 0 : int nargs = 1, i;
10572 : 0 : bool result;
10573 : :
10574 : 0 : if (argc < 3)
10575 : 0 : fatal_error (input_location, "too few arguments to %%:version-compare");
10576 : 0 : if (argv[0][0] == '\0')
10577 : 0 : abort ();
10578 : 0 : if ((argv[0][1] == '<' || argv[0][1] == '>') && argv[0][0] != '!')
10579 : 0 : nargs = 2;
10580 : 0 : if (argc != nargs + 3)
10581 : 0 : fatal_error (input_location, "too many arguments to %%:version-compare");
10582 : :
10583 : 0 : switch_len = strlen (argv[nargs + 1]);
10584 : 0 : for (i = 0; i < n_switches; i++)
10585 : 0 : if (!strncmp (switches[i].part1, argv[nargs + 1], switch_len)
10586 : 0 : && check_live_switch (i, switch_len))
10587 : 0 : switch_value = switches[i].part1 + switch_len;
10588 : :
10589 : 0 : if (switch_value == NULL)
10590 : : comp1 = comp2 = -1;
10591 : : else
10592 : : {
10593 : 0 : comp1 = compare_version_strings (switch_value, argv[1]);
10594 : 0 : if (nargs == 2)
10595 : 0 : comp2 = compare_version_strings (switch_value, argv[2]);
10596 : : else
10597 : : comp2 = -1; /* This value unused. */
10598 : : }
10599 : :
10600 : 0 : switch (argv[0][0] << 8 | argv[0][1])
10601 : : {
10602 : 0 : case '>' << 8 | '=':
10603 : 0 : result = comp1 >= 0;
10604 : 0 : break;
10605 : 0 : case '!' << 8 | '<':
10606 : 0 : result = comp1 >= 0 || switch_value == NULL;
10607 : 0 : break;
10608 : 0 : case '<' << 8:
10609 : 0 : result = comp1 < 0;
10610 : 0 : break;
10611 : 0 : case '!' << 8 | '>':
10612 : 0 : result = comp1 < 0 || switch_value == NULL;
10613 : 0 : break;
10614 : 0 : case '>' << 8 | '<':
10615 : 0 : result = comp1 >= 0 && comp2 < 0;
10616 : 0 : break;
10617 : 0 : case '<' << 8 | '>':
10618 : 0 : result = comp1 < 0 || comp2 >= 0;
10619 : 0 : break;
10620 : :
10621 : 0 : default:
10622 : 0 : fatal_error (input_location,
10623 : : "unknown operator %qs in %%:version-compare", argv[0]);
10624 : : }
10625 : 0 : if (! result)
10626 : : return NULL;
10627 : :
10628 : 0 : return argv[nargs + 2];
10629 : : }
10630 : :
10631 : : /* %:include builtin spec function. This differs from %include in that it
10632 : : can be nested inside a spec, and thus be conditionalized. It takes
10633 : : one argument, the filename, and looks for it in the startfile path.
10634 : : The result is always NULL, i.e. an empty expansion. */
10635 : :
10636 : : static const char *
10637 : 30100 : include_spec_function (int argc, const char **argv)
10638 : : {
10639 : 30100 : char *file;
10640 : :
10641 : 30100 : if (argc != 1)
10642 : 0 : abort ();
10643 : :
10644 : 30100 : file = find_a_file (&startfile_prefixes, argv[0], R_OK, true);
10645 : 30100 : read_specs (file ? file : argv[0], false, false);
10646 : :
10647 : 30100 : return NULL;
10648 : : }
10649 : :
10650 : : /* %:find-file spec function. This function replaces its argument by
10651 : : the file found through find_file, that is the -print-file-name gcc
10652 : : program option. */
10653 : : static const char *
10654 : 0 : find_file_spec_function (int argc, const char **argv)
10655 : : {
10656 : 0 : const char *file;
10657 : :
10658 : 0 : if (argc != 1)
10659 : 0 : abort ();
10660 : :
10661 : 0 : file = find_file (argv[0]);
10662 : 0 : return file;
10663 : : }
10664 : :
10665 : :
10666 : : /* %:find-plugindir spec function. This function replaces its argument
10667 : : by the -iplugindir=<dir> option. `dir' is found through find_file, that
10668 : : is the -print-file-name gcc program option. */
10669 : : static const char *
10670 : 381 : find_plugindir_spec_function (int argc, const char **argv ATTRIBUTE_UNUSED)
10671 : : {
10672 : 381 : const char *option;
10673 : :
10674 : 381 : if (argc != 0)
10675 : 0 : abort ();
10676 : :
10677 : 381 : option = concat ("-iplugindir=", find_file ("plugin"), NULL);
10678 : 381 : return option;
10679 : : }
10680 : :
10681 : :
10682 : : /* %:print-asm-header spec function. Print a banner to say that the
10683 : : following output is from the assembler. */
10684 : :
10685 : : static const char *
10686 : 0 : print_asm_header_spec_function (int arg ATTRIBUTE_UNUSED,
10687 : : const char **argv ATTRIBUTE_UNUSED)
10688 : : {
10689 : 0 : printf (_("Assembler options\n=================\n\n"));
10690 : 0 : printf (_("Use \"-Wa,OPTION\" to pass \"OPTION\" to the assembler.\n\n"));
10691 : 0 : fflush (stdout);
10692 : 0 : return NULL;
10693 : : }
10694 : :
10695 : : /* Get a random number for -frandom-seed */
10696 : :
10697 : : static unsigned HOST_WIDE_INT
10698 : 623 : get_random_number (void)
10699 : : {
10700 : 623 : unsigned HOST_WIDE_INT ret = 0;
10701 : 623 : int fd;
10702 : :
10703 : 623 : fd = open ("/dev/urandom", O_RDONLY);
10704 : 623 : if (fd >= 0)
10705 : : {
10706 : 623 : read (fd, &ret, sizeof (HOST_WIDE_INT));
10707 : 623 : close (fd);
10708 : 623 : if (ret)
10709 : : return ret;
10710 : : }
10711 : :
10712 : : /* Get some more or less random data. */
10713 : : #ifdef HAVE_GETTIMEOFDAY
10714 : 0 : {
10715 : 0 : struct timeval tv;
10716 : :
10717 : 0 : gettimeofday (&tv, NULL);
10718 : 0 : ret = tv.tv_sec * 1000 + tv.tv_usec / 1000;
10719 : : }
10720 : : #else
10721 : : {
10722 : : time_t now = time (NULL);
10723 : :
10724 : : if (now != (time_t)-1)
10725 : : ret = (unsigned) now;
10726 : : }
10727 : : #endif
10728 : :
10729 : 0 : return ret ^ getpid ();
10730 : : }
10731 : :
10732 : : /* %:compare-debug-dump-opt spec function. Save the last argument,
10733 : : expected to be the last -fdump-final-insns option, or generate a
10734 : : temporary. */
10735 : :
10736 : : static const char *
10737 : 1239 : compare_debug_dump_opt_spec_function (int arg,
10738 : : const char **argv ATTRIBUTE_UNUSED)
10739 : : {
10740 : 1239 : char *ret;
10741 : 1239 : char *name;
10742 : 1239 : int which;
10743 : 1239 : static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
10744 : :
10745 : 1239 : if (arg != 0)
10746 : 0 : fatal_error (input_location,
10747 : : "too many arguments to %%:compare-debug-dump-opt");
10748 : :
10749 : 1239 : do_spec_2 ("%{fdump-final-insns=*:%*}", NULL);
10750 : 1239 : do_spec_1 (" ", 0, NULL);
10751 : :
10752 : 1239 : if (argbuf.length () > 0
10753 : 1239 : && strcmp (argv[argbuf.length () - 1], ".") != 0)
10754 : : {
10755 : 0 : if (!compare_debug)
10756 : : return NULL;
10757 : :
10758 : 0 : name = xstrdup (argv[argbuf.length () - 1]);
10759 : 0 : ret = NULL;
10760 : : }
10761 : : else
10762 : : {
10763 : 1239 : if (argbuf.length () > 0)
10764 : 6 : do_spec_2 ("%B.gkd", NULL);
10765 : 1233 : else if (!compare_debug)
10766 : : return NULL;
10767 : : else
10768 : 1233 : do_spec_2 ("%{!save-temps*:%g.gkd}%{save-temps*:%B.gkd}", NULL);
10769 : :
10770 : 1239 : do_spec_1 (" ", 0, NULL);
10771 : :
10772 : 1239 : gcc_assert (argbuf.length () > 0);
10773 : :
10774 : 1239 : name = xstrdup (argbuf.last ());
10775 : :
10776 : 1239 : char *arg = quote_spec (xstrdup (name));
10777 : 1239 : ret = concat ("-fdump-final-insns=", arg, NULL);
10778 : 1239 : free (arg);
10779 : : }
10780 : :
10781 : 1239 : which = compare_debug < 0;
10782 : 1239 : debug_check_temp_file[which] = name;
10783 : :
10784 : 1239 : if (!which)
10785 : : {
10786 : 623 : unsigned HOST_WIDE_INT value = get_random_number ();
10787 : :
10788 : 623 : sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
10789 : : }
10790 : :
10791 : 1239 : if (*random_seed)
10792 : : {
10793 : 1239 : char *tmp = ret;
10794 : 1239 : ret = concat ("%{!frandom-seed=*:-frandom-seed=", random_seed, "} ",
10795 : : ret, NULL);
10796 : 1239 : free (tmp);
10797 : : }
10798 : :
10799 : 1239 : if (which)
10800 : 616 : *random_seed = 0;
10801 : :
10802 : : return ret;
10803 : : }
10804 : :
10805 : : /* %:compare-debug-self-opt spec function. Expands to the options
10806 : : that are to be passed in the second compilation of
10807 : : compare-debug. */
10808 : :
10809 : : static const char *
10810 : 1244 : compare_debug_self_opt_spec_function (int arg,
10811 : : const char **argv ATTRIBUTE_UNUSED)
10812 : : {
10813 : 1244 : if (arg != 0)
10814 : 0 : fatal_error (input_location,
10815 : : "too many arguments to %%:compare-debug-self-opt");
10816 : :
10817 : 1244 : if (compare_debug >= 0)
10818 : : return NULL;
10819 : :
10820 : 622 : return concat ("\
10821 : : %<o %<MD %<MMD %<MF* %<MG %<MP %<MQ* %<MT* \
10822 : : %<fdump-final-insns=* -w -S -o %j \
10823 : : %{!fcompare-debug-second:-fcompare-debug-second} \
10824 : 622 : ", compare_debug_opt, NULL);
10825 : : }
10826 : :
10827 : : /* %:pass-through-libs spec function. Finds all -l options and input
10828 : : file names in the lib spec passed to it, and makes a list of them
10829 : : prepended with the plugin option to cause them to be passed through
10830 : : to the final link after all the new object files have been added. */
10831 : :
10832 : : const char *
10833 : 86995 : pass_through_libs_spec_func (int argc, const char **argv)
10834 : : {
10835 : 86995 : char *prepended = xstrdup (" ");
10836 : 86995 : int n;
10837 : : /* Shlemiel the painter's algorithm. Innately horrible, but at least
10838 : : we know that there will never be more than a handful of strings to
10839 : : concat, and it's only once per run, so it's not worth optimising. */
10840 : 831199 : for (n = 0; n < argc; n++)
10841 : : {
10842 : 744204 : char *old = prepended;
10843 : : /* Anything that isn't an option is a full path to an output
10844 : : file; pass it through if it ends in '.a'. Among options,
10845 : : pass only -l. */
10846 : 744204 : if (argv[n][0] == '-' && argv[n][1] == 'l')
10847 : : {
10848 : 482446 : const char *lopt = argv[n] + 2;
10849 : : /* Handle both joined and non-joined -l options. If for any
10850 : : reason there's a trailing -l with no joined or following
10851 : : arg just discard it. */
10852 : 482446 : if (!*lopt && ++n >= argc)
10853 : : break;
10854 : 482446 : else if (!*lopt)
10855 : 0 : lopt = argv[n];
10856 : 482446 : prepended = concat (prepended, "-plugin-opt=-pass-through=-l",
10857 : : lopt, " ", NULL);
10858 : 482446 : }
10859 : 261758 : else if (!strcmp (".a", argv[n] + strlen (argv[n]) - 2))
10860 : : {
10861 : 0 : prepended = concat (prepended, "-plugin-opt=-pass-through=",
10862 : : argv[n], " ", NULL);
10863 : : }
10864 : 744204 : if (prepended != old)
10865 : 482446 : free (old);
10866 : : }
10867 : 86995 : return prepended;
10868 : : }
10869 : :
10870 : : static bool
10871 : 500008 : not_actual_file_p (const char *name)
10872 : : {
10873 : 500008 : return (strcmp (name, "-") == 0
10874 : 500008 : || strcmp (name, HOST_BIT_BUCKET) == 0);
10875 : : }
10876 : :
10877 : : /* %:dumps spec function. Take an optional argument that overrides
10878 : : the default extension for -dumpbase and -dumpbase-ext.
10879 : : Return -dumpdir, -dumpbase and -dumpbase-ext, if needed. */
10880 : : const char *
10881 : 272851 : dumps_spec_func (int argc, const char **argv ATTRIBUTE_UNUSED)
10882 : : {
10883 : 272851 : const char *ext = dumpbase_ext;
10884 : 272851 : char *p;
10885 : :
10886 : 272851 : char *args[3] = { NULL, NULL, NULL };
10887 : 272851 : int nargs = 0;
10888 : :
10889 : : /* Do not compute a default for -dumpbase-ext when -dumpbase was
10890 : : given explicitly. */
10891 : 272851 : if (dumpbase && *dumpbase && !ext)
10892 : 272851 : ext = "";
10893 : :
10894 : 272851 : if (argc == 1)
10895 : : {
10896 : : /* Do not override the explicitly-specified -dumpbase-ext with
10897 : : the specs-provided overrider. */
10898 : 0 : if (!ext)
10899 : 0 : ext = argv[0];
10900 : : }
10901 : 272851 : else if (argc != 0)
10902 : 0 : fatal_error (input_location, "too many arguments for %%:dumps");
10903 : :
10904 : 272851 : if (dumpdir)
10905 : : {
10906 : 103417 : p = quote_spec_arg (xstrdup (dumpdir));
10907 : 103417 : args[nargs++] = concat (" -dumpdir ", p, NULL);
10908 : 103417 : free (p);
10909 : : }
10910 : :
10911 : 272851 : if (!ext)
10912 : 253399 : ext = input_basename + basename_length;
10913 : :
10914 : : /* Use the precomputed outbase, or compute dumpbase from
10915 : : input_basename, just like %b would. */
10916 : 272851 : char *base;
10917 : :
10918 : 272851 : if (dumpbase && *dumpbase)
10919 : : {
10920 : 19452 : base = xstrdup (dumpbase);
10921 : 19452 : p = base + outbase_length;
10922 : 19452 : gcc_checking_assert (strncmp (base, outbase, outbase_length) == 0);
10923 : 19452 : gcc_checking_assert (strcmp (p, ext) == 0);
10924 : : }
10925 : 253399 : else if (outbase_length)
10926 : : {
10927 : 156401 : base = xstrndup (outbase, outbase_length);
10928 : 156401 : p = NULL;
10929 : : }
10930 : : else
10931 : : {
10932 : 96998 : base = xstrndup (input_basename, suffixed_basename_length);
10933 : 96998 : p = base + basename_length;
10934 : : }
10935 : :
10936 : 272851 : if (compare_debug < 0 || !p || strcmp (p, ext) != 0)
10937 : : {
10938 : 616 : if (p)
10939 : 9 : *p = '\0';
10940 : :
10941 : 156410 : const char *gk;
10942 : 156410 : if (compare_debug < 0)
10943 : : gk = ".gk";
10944 : : else
10945 : 155794 : gk = "";
10946 : :
10947 : 156410 : p = concat (base, gk, ext, NULL);
10948 : :
10949 : 156410 : free (base);
10950 : 156410 : base = p;
10951 : : }
10952 : :
10953 : 272851 : base = quote_spec_arg (base);
10954 : 272851 : args[nargs++] = concat (" -dumpbase ", base, NULL);
10955 : 272851 : free (base);
10956 : :
10957 : 272851 : if (*ext)
10958 : : {
10959 : 252362 : p = quote_spec_arg (xstrdup (ext));
10960 : 252362 : args[nargs++] = concat (" -dumpbase-ext ", p, NULL);
10961 : 252362 : free (p);
10962 : : }
10963 : :
10964 : 272851 : const char *ret = concat (args[0], args[1], args[2], NULL);
10965 : 1174332 : while (nargs > 0)
10966 : 628630 : free (args[--nargs]);
10967 : :
10968 : 272851 : return ret;
10969 : : }
10970 : :
10971 : : /* Returns "" if ARGV[ARGC - 2] is greater than ARGV[ARGC-1].
10972 : : Otherwise, return NULL. */
10973 : :
10974 : : static const char *
10975 : 380005 : greater_than_spec_func (int argc, const char **argv)
10976 : : {
10977 : 380005 : char *converted;
10978 : :
10979 : 380005 : if (argc == 1)
10980 : : return NULL;
10981 : :
10982 : 251 : gcc_assert (argc >= 2);
10983 : :
10984 : 251 : long arg = strtol (argv[argc - 2], &converted, 10);
10985 : 251 : gcc_assert (converted != argv[argc - 2]);
10986 : :
10987 : 251 : long lim = strtol (argv[argc - 1], &converted, 10);
10988 : 251 : gcc_assert (converted != argv[argc - 1]);
10989 : :
10990 : 251 : if (arg > lim)
10991 : : return "";
10992 : :
10993 : : return NULL;
10994 : : }
10995 : :
10996 : : /* Returns "" if debug_info_level is greater than ARGV[ARGC-1].
10997 : : Otherwise, return NULL. */
10998 : :
10999 : : static const char *
11000 : 243801 : debug_level_greater_than_spec_func (int argc, const char **argv)
11001 : : {
11002 : 243801 : char *converted;
11003 : :
11004 : 243801 : if (argc != 1)
11005 : 0 : fatal_error (input_location,
11006 : : "wrong number of arguments to %%:debug-level-gt");
11007 : :
11008 : 243801 : long arg = strtol (argv[0], &converted, 10);
11009 : 243801 : gcc_assert (converted != argv[0]);
11010 : :
11011 : 243801 : if (debug_info_level > arg)
11012 : 44328 : return "";
11013 : :
11014 : : return NULL;
11015 : : }
11016 : :
11017 : : /* Returns "" if dwarf_version is greater than ARGV[ARGC-1].
11018 : : Otherwise, return NULL. */
11019 : :
11020 : : static const char *
11021 : 125574 : dwarf_version_greater_than_spec_func (int argc, const char **argv)
11022 : : {
11023 : 125574 : char *converted;
11024 : :
11025 : 125574 : if (argc != 1)
11026 : 0 : fatal_error (input_location,
11027 : : "wrong number of arguments to %%:dwarf-version-gt");
11028 : :
11029 : 125574 : long arg = strtol (argv[0], &converted, 10);
11030 : 125574 : gcc_assert (converted != argv[0]);
11031 : :
11032 : 125574 : if (dwarf_version > arg)
11033 : 124703 : return "";
11034 : :
11035 : : return NULL;
11036 : : }
11037 : :
11038 : : static void
11039 : 33788 : path_prefix_reset (path_prefix *prefix)
11040 : : {
11041 : 33788 : struct prefix_list *iter, *next;
11042 : 33788 : iter = prefix->plist;
11043 : 134058 : while (iter)
11044 : : {
11045 : 100270 : next = iter->next;
11046 : 100270 : free (const_cast <char *> (iter->prefix));
11047 : 100270 : XDELETE (iter);
11048 : 100270 : iter = next;
11049 : : }
11050 : 33788 : prefix->plist = 0;
11051 : 33788 : prefix->max_len = 0;
11052 : 33788 : }
11053 : :
11054 : : /* The function takes 3 arguments: OPTION name, file name and location
11055 : : where we search for Fortran modules.
11056 : : When the FILE is found by find_file, return OPTION=path_to_file. */
11057 : :
11058 : : static const char *
11059 : 30506 : find_fortran_preinclude_file (int argc, const char **argv)
11060 : : {
11061 : 30506 : char *result = NULL;
11062 : 30506 : if (argc != 3)
11063 : : return NULL;
11064 : :
11065 : 30506 : struct path_prefix prefixes = { 0, 0, "preinclude" };
11066 : :
11067 : : /* Search first for 'finclude' folder location for a header file
11068 : : installed by the compiler (similar to omp_lib.h). */
11069 : 30506 : add_prefix (&prefixes, argv[2], NULL, 0, 0, 0);
11070 : : #ifdef TOOL_INCLUDE_DIR
11071 : : /* Then search: <prefix>/<target>/<include>/finclude */
11072 : 30506 : add_prefix (&prefixes, TOOL_INCLUDE_DIR "/finclude/",
11073 : : NULL, 0, 0, 0);
11074 : : #endif
11075 : : #ifdef NATIVE_SYSTEM_HEADER_DIR
11076 : : /* Then search: <sysroot>/usr/include/finclude/<multilib> */
11077 : 30506 : add_sysrooted_hdrs_prefix (&prefixes, NATIVE_SYSTEM_HEADER_DIR "/finclude/",
11078 : : NULL, 0, 0, 0);
11079 : : #endif
11080 : :
11081 : 30506 : const char *path = find_a_file (&include_prefixes, argv[1], R_OK, false);
11082 : 30506 : if (path != NULL)
11083 : 0 : result = concat (argv[0], path, NULL);
11084 : : else
11085 : : {
11086 : 30506 : path = find_a_file (&prefixes, argv[1], R_OK, false);
11087 : 30506 : if (path != NULL)
11088 : 30506 : result = concat (argv[0], path, NULL);
11089 : : }
11090 : :
11091 : 30506 : path_prefix_reset (&prefixes);
11092 : 30506 : return result;
11093 : : }
11094 : :
11095 : : /* The function takes any number of arguments and joins them together.
11096 : :
11097 : : This seems to be necessary to build "-fjoined=foo.b" from "-fseparate foo.a"
11098 : : with a %{fseparate*:-fjoined=%.b$*} rule without adding undesired spaces:
11099 : : when doing $* replacement we first replace $* with the rest of the switch
11100 : : (in this case ""), and then add any arguments as arguments after the result,
11101 : : resulting in "-fjoined= foo.b". Using this function with e.g.
11102 : : %{fseparate*:-fjoined=%:join(%.b$*)} gets multiple words as separate argv
11103 : : elements instead of separated by spaces, and we paste them together. */
11104 : :
11105 : : static const char *
11106 : 39 : join_spec_func (int argc, const char **argv)
11107 : : {
11108 : 39 : if (argc == 1)
11109 : 0 : return argv[0];
11110 : 117 : for (int i = 0; i < argc; ++i)
11111 : 78 : obstack_grow (&obstack, argv[i], strlen (argv[i]));
11112 : 39 : obstack_1grow (&obstack, '\0');
11113 : 39 : return XOBFINISH (&obstack, const char *);
11114 : : }
11115 : :
11116 : : /* If any character in ORIG fits QUOTE_P (_, P), reallocate the string
11117 : : so as to precede every one of them with a backslash. Return the
11118 : : original string or the reallocated one. */
11119 : :
11120 : : static inline char *
11121 : 821737 : quote_string (char *orig, bool (*quote_p)(char, void *), void *p)
11122 : : {
11123 : 821737 : int len, number_of_space = 0;
11124 : :
11125 : 18713751 : for (len = 0; orig[len]; len++)
11126 : 17892014 : if (quote_p (orig[len], p))
11127 : 0 : number_of_space++;
11128 : :
11129 : 821737 : if (number_of_space)
11130 : : {
11131 : 0 : char *new_spec = (char *) xmalloc (len + number_of_space + 1);
11132 : 0 : int j, k;
11133 : 0 : for (j = 0, k = 0; j <= len; j++, k++)
11134 : : {
11135 : 0 : if (quote_p (orig[j], p))
11136 : 0 : new_spec[k++] = '\\';
11137 : 0 : new_spec[k] = orig[j];
11138 : : }
11139 : 0 : free (orig);
11140 : 0 : return new_spec;
11141 : : }
11142 : : else
11143 : : return orig;
11144 : : }
11145 : :
11146 : : /* Return true iff C is any of the characters convert_white_space
11147 : : should quote. */
11148 : :
11149 : : static inline bool
11150 : 11925785 : whitespace_to_convert_p (char c, void *)
11151 : : {
11152 : 11925785 : return (c == ' ' || c == '\t');
11153 : : }
11154 : :
11155 : : /* Insert backslash before spaces in ORIG (usually a file path), to
11156 : : avoid being broken by spec parser.
11157 : :
11158 : : This function is needed as do_spec_1 treats white space (' ' and '\t')
11159 : : as the end of an argument. But in case of -plugin /usr/gcc install/xxx.so,
11160 : : the file name should be treated as a single argument rather than being
11161 : : broken into multiple. Solution is to insert '\\' before the space in a
11162 : : file name.
11163 : :
11164 : : This function converts and only converts all occurrence of ' '
11165 : : to '\\' + ' ' and '\t' to '\\' + '\t'. For example:
11166 : : "a b" -> "a\\ b"
11167 : : "a b" -> "a\\ \\ b"
11168 : : "a\tb" -> "a\\\tb"
11169 : : "a\\ b" -> "a\\\\ b"
11170 : :
11171 : : orig: input null-terminating string that was allocated by xalloc. The
11172 : : memory it points to might be freed in this function. Behavior undefined
11173 : : if ORIG wasn't xalloced or was freed already at entry.
11174 : :
11175 : : Return: ORIG if no conversion needed. Otherwise a newly allocated string
11176 : : that was converted from ORIG. */
11177 : :
11178 : : static char *
11179 : 191877 : convert_white_space (char *orig)
11180 : : {
11181 : 191877 : return quote_string (orig, whitespace_to_convert_p, NULL);
11182 : : }
11183 : :
11184 : : /* Return true iff C matches any of the spec active characters. */
11185 : : static inline bool
11186 : 5966229 : quote_spec_char_p (char c, void *)
11187 : : {
11188 : 5966229 : switch (c)
11189 : : {
11190 : : case ' ':
11191 : : case '\t':
11192 : : case '\n':
11193 : : case '|':
11194 : : case '%':
11195 : : case '\\':
11196 : : return true;
11197 : :
11198 : 5966229 : default:
11199 : 5966229 : return false;
11200 : : }
11201 : : }
11202 : :
11203 : : /* Like convert_white_space, but deactivate all active spec chars by
11204 : : quoting them. */
11205 : :
11206 : : static inline char *
11207 : 629860 : quote_spec (char *orig)
11208 : : {
11209 : 1239 : return quote_string (orig, quote_spec_char_p, NULL);
11210 : : }
11211 : :
11212 : : /* Like quote_spec, but also turn an empty string into the spec for an
11213 : : empty argument. */
11214 : :
11215 : : static inline char *
11216 : 628630 : quote_spec_arg (char *orig)
11217 : : {
11218 : 628630 : if (!*orig)
11219 : : {
11220 : 9 : free (orig);
11221 : 9 : return xstrdup ("%\"");
11222 : : }
11223 : :
11224 : 628621 : return quote_spec (orig);
11225 : : }
11226 : :
11227 : : /* Restore all state within gcc.cc to the initial state, so that the driver
11228 : : code can be safely re-run in-process.
11229 : :
11230 : : Many const char * variables are referenced by static specs (see
11231 : : INIT_STATIC_SPEC above). These variables are restored to their default
11232 : : values by a simple loop over the static specs.
11233 : :
11234 : : For other variables, we directly restore them all to their initial
11235 : : values (often implicitly 0).
11236 : :
11237 : : Free the various obstacks in this file, along with "opts_obstack"
11238 : : from opts.cc.
11239 : :
11240 : : This function also restores any environment variables that were changed. */
11241 : :
11242 : : void
11243 : 1094 : driver::finalize ()
11244 : : {
11245 : 1094 : env.restore ();
11246 : 1094 : diagnostic_finish (global_dc);
11247 : :
11248 : 1094 : is_cpp_driver = 0;
11249 : 1094 : at_file_supplied = 0;
11250 : 1094 : print_help_list = 0;
11251 : 1094 : print_version = 0;
11252 : 1094 : verbose_only_flag = 0;
11253 : 1094 : print_subprocess_help = 0;
11254 : 1094 : use_ld = NULL;
11255 : 1094 : report_times_to_file = NULL;
11256 : 1094 : target_system_root = DEFAULT_TARGET_SYSTEM_ROOT;
11257 : 1094 : target_system_root_changed = 0;
11258 : 1094 : target_sysroot_suffix = 0;
11259 : 1094 : target_sysroot_hdrs_suffix = 0;
11260 : 1094 : save_temps_flag = SAVE_TEMPS_NONE;
11261 : 1094 : save_temps_overrides_dumpdir = false;
11262 : 1094 : dumpdir_trailing_dash_added = false;
11263 : 1094 : free (dumpdir);
11264 : 1094 : free (dumpbase);
11265 : 1094 : free (dumpbase_ext);
11266 : 1094 : free (outbase);
11267 : 1094 : dumpdir = dumpbase = dumpbase_ext = outbase = NULL;
11268 : 1094 : dumpdir_length = outbase_length = 0;
11269 : 1094 : spec_machine = DEFAULT_TARGET_MACHINE;
11270 : 1094 : greatest_status = 1;
11271 : :
11272 : 1094 : obstack_free (&obstack, NULL);
11273 : 1094 : obstack_free (&opts_obstack, NULL); /* in opts.cc */
11274 : 1094 : obstack_free (&collect_obstack, NULL);
11275 : :
11276 : 1094 : link_command_spec = LINK_COMMAND_SPEC;
11277 : :
11278 : 1094 : obstack_free (&multilib_obstack, NULL);
11279 : :
11280 : 1094 : user_specs_head = NULL;
11281 : 1094 : user_specs_tail = NULL;
11282 : :
11283 : : /* Within the "compilers" vec, the fields "suffix" and "spec" were
11284 : : statically allocated for the default compilers, but dynamically
11285 : : allocated for additional compilers. Delete them for the latter. */
11286 : 1094 : for (int i = n_default_compilers; i < n_compilers; i++)
11287 : : {
11288 : 0 : free (const_cast <char *> (compilers[i].suffix));
11289 : 0 : free (const_cast <char *> (compilers[i].spec));
11290 : : }
11291 : 1094 : XDELETEVEC (compilers);
11292 : 1094 : compilers = NULL;
11293 : 1094 : n_compilers = 0;
11294 : :
11295 : 1094 : linker_options.truncate (0);
11296 : 1094 : assembler_options.truncate (0);
11297 : 1094 : preprocessor_options.truncate (0);
11298 : :
11299 : 1094 : path_prefix_reset (&exec_prefixes);
11300 : 1094 : path_prefix_reset (&startfile_prefixes);
11301 : 1094 : path_prefix_reset (&include_prefixes);
11302 : :
11303 : 1094 : machine_suffix = 0;
11304 : 1094 : just_machine_suffix = 0;
11305 : 1094 : gcc_exec_prefix = 0;
11306 : 1094 : gcc_libexec_prefix = 0;
11307 : 1094 : set_static_spec_shared (&md_exec_prefix, MD_EXEC_PREFIX);
11308 : 1094 : set_static_spec_shared (&md_startfile_prefix, MD_STARTFILE_PREFIX);
11309 : 1094 : set_static_spec_shared (&md_startfile_prefix_1, MD_STARTFILE_PREFIX_1);
11310 : 1094 : multilib_dir = 0;
11311 : 1094 : multilib_os_dir = 0;
11312 : 1094 : multiarch_dir = 0;
11313 : :
11314 : : /* Free any specs dynamically-allocated by set_spec.
11315 : : These will be at the head of the list, before the
11316 : : statically-allocated ones. */
11317 : 1094 : if (specs)
11318 : : {
11319 : 2188 : while (specs != static_specs)
11320 : : {
11321 : 1094 : spec_list *next = specs->next;
11322 : 1094 : free (const_cast <char *> (specs->name));
11323 : 1094 : XDELETE (specs);
11324 : 1094 : specs = next;
11325 : : }
11326 : 1094 : specs = 0;
11327 : : }
11328 : 50324 : for (unsigned i = 0; i < ARRAY_SIZE (static_specs); i++)
11329 : : {
11330 : 49230 : spec_list *sl = &static_specs[i];
11331 : 49230 : if (sl->alloc_p)
11332 : : {
11333 : 43770 : free (const_cast <char *> (*(sl->ptr_spec)));
11334 : 43770 : sl->alloc_p = false;
11335 : : }
11336 : 49230 : *(sl->ptr_spec) = sl->default_ptr;
11337 : : }
11338 : : #ifdef EXTRA_SPECS
11339 : 1094 : extra_specs = NULL;
11340 : : #endif
11341 : :
11342 : 1094 : processing_spec_function = 0;
11343 : :
11344 : 1094 : clear_args ();
11345 : :
11346 : 1094 : have_c = 0;
11347 : 1094 : have_o = 0;
11348 : :
11349 : 1094 : temp_names = NULL;
11350 : 1094 : execution_count = 0;
11351 : 1094 : signal_count = 0;
11352 : :
11353 : 1094 : temp_filename = NULL;
11354 : 1094 : temp_filename_length = 0;
11355 : 1094 : always_delete_queue = NULL;
11356 : 1094 : failure_delete_queue = NULL;
11357 : :
11358 : 1094 : XDELETEVEC (switches);
11359 : 1094 : switches = NULL;
11360 : 1094 : n_switches = 0;
11361 : 1094 : n_switches_alloc = 0;
11362 : :
11363 : 1094 : compare_debug = 0;
11364 : 1094 : compare_debug_second = 0;
11365 : 1094 : compare_debug_opt = NULL;
11366 : 3282 : for (int i = 0; i < 2; i++)
11367 : : {
11368 : 2188 : switches_debug_check[i] = NULL;
11369 : 2188 : n_switches_debug_check[i] = 0;
11370 : 2188 : n_switches_alloc_debug_check[i] = 0;
11371 : 2188 : debug_check_temp_file[i] = NULL;
11372 : : }
11373 : :
11374 : 1094 : XDELETEVEC (infiles);
11375 : 1094 : infiles = NULL;
11376 : 1094 : n_infiles = 0;
11377 : 1094 : n_infiles_alloc = 0;
11378 : :
11379 : 1094 : combine_inputs = false;
11380 : 1094 : added_libraries = 0;
11381 : 1094 : XDELETEVEC (outfiles);
11382 : 1094 : outfiles = NULL;
11383 : 1094 : spec_lang = 0;
11384 : 1094 : last_language_n_infiles = 0;
11385 : 1094 : gcc_input_filename = NULL;
11386 : 1094 : input_file_number = 0;
11387 : 1094 : input_filename_length = 0;
11388 : 1094 : basename_length = 0;
11389 : 1094 : suffixed_basename_length = 0;
11390 : 1094 : input_basename = NULL;
11391 : 1094 : input_suffix = NULL;
11392 : : /* We don't need to purge "input_stat", just to unset "input_stat_set". */
11393 : 1094 : input_stat_set = 0;
11394 : 1094 : input_file_compiler = NULL;
11395 : 1094 : arg_going = 0;
11396 : 1094 : delete_this_arg = 0;
11397 : 1094 : this_is_output_file = 0;
11398 : 1094 : this_is_library_file = 0;
11399 : 1094 : this_is_linker_script = 0;
11400 : 1094 : input_from_pipe = 0;
11401 : 1094 : suffix_subst = NULL;
11402 : :
11403 : 1094 : XDELETEVEC (mdswitches);
11404 : 1094 : mdswitches = NULL;
11405 : 1094 : n_mdswitches = 0;
11406 : :
11407 : 1094 : used_arg.finalize ();
11408 : 1094 : }
11409 : :
11410 : : /* PR jit/64810.
11411 : : Targets can provide configure-time default options in
11412 : : OPTION_DEFAULT_SPECS. The jit needs to access these, but
11413 : : they are expressed in the spec language.
11414 : :
11415 : : Run just enough of the driver to be able to expand these
11416 : : specs, and then call the callback CB on each
11417 : : such option. The options strings are *without* a leading
11418 : : '-' character e.g. ("march=x86-64"). Finally, clean up. */
11419 : :
11420 : : void
11421 : 124 : driver_get_configure_time_options (void (*cb) (const char *option,
11422 : : void *user_data),
11423 : : void *user_data)
11424 : : {
11425 : 124 : size_t i;
11426 : :
11427 : 124 : obstack_init (&obstack);
11428 : 124 : init_opts_obstack ();
11429 : 124 : n_switches = 0;
11430 : :
11431 : 1240 : for (i = 0; i < ARRAY_SIZE (option_default_specs); i++)
11432 : 1116 : do_option_spec (option_default_specs[i].name,
11433 : 1116 : option_default_specs[i].spec);
11434 : :
11435 : 372 : for (i = 0; (int) i < n_switches; i++)
11436 : : {
11437 : 248 : gcc_assert (switches[i].part1);
11438 : 248 : (*cb) (switches[i].part1, user_data);
11439 : : }
11440 : :
11441 : 124 : obstack_free (&opts_obstack, NULL);
11442 : 124 : obstack_free (&obstack, NULL);
11443 : 124 : n_switches = 0;
11444 : 124 : }
|