1 | /* Compiler driver program that can handle many languages. |
2 | Copyright (C) 1987-2023 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 | #include "coretypes.h" |
34 | #include "multilib.h" /* before tm.h */ |
35 | #include "tm.h" |
36 | #include "xregex.h" |
37 | #include "obstack.h" |
38 | #include "intl.h" |
39 | #include "prefix.h" |
40 | #include "opt-suggestions.h" |
41 | #include "gcc.h" |
42 | #include "diagnostic.h" |
43 | #include "flags.h" |
44 | #include "opts.h" |
45 | #include "filenames.h" |
46 | #include "spellcheck.h" |
47 | #include "opts-jobserver.h" |
48 | #include "common/common-target.h" |
49 | |
50 | |
51 | |
52 | /* Manage the manipulation of env vars. |
53 | |
54 | We poison "getenv" and "putenv", so that all enviroment-handling is |
55 | done through this class. Note that poisoning happens in the |
56 | preprocessor at the identifier level, and doesn't distinguish between |
57 | env.getenv (); |
58 | and |
59 | getenv (); |
60 | Hence we need to use "get" for the accessor method, not "getenv". */ |
61 | |
62 | struct env_manager |
63 | { |
64 | public: |
65 | void init (bool can_restore, bool debug); |
66 | const char *get (const char *name); |
67 | void xput (const char *string); |
68 | void restore (); |
69 | |
70 | private: |
71 | bool m_can_restore; |
72 | bool m_debug; |
73 | struct kv |
74 | { |
75 | char *m_key; |
76 | char *m_value; |
77 | }; |
78 | vec<kv> m_keys; |
79 | |
80 | }; |
81 | |
82 | /* The singleton instance of class env_manager. */ |
83 | |
84 | static env_manager env; |
85 | |
86 | /* Initializer for class env_manager. |
87 | |
88 | We can't do this as a constructor since we have a statically |
89 | allocated instance ("env" above). */ |
90 | |
91 | void |
92 | env_manager::init (bool can_restore, bool debug) |
93 | { |
94 | m_can_restore = can_restore; |
95 | m_debug = debug; |
96 | } |
97 | |
98 | /* Get the value of NAME within the environment. Essentially |
99 | a wrapper for ::getenv, but adding logging, and the possibility |
100 | of caching results. */ |
101 | |
102 | const char * |
103 | env_manager::get (const char *name) |
104 | { |
105 | const char *result = ::getenv (name: name); |
106 | if (m_debug) |
107 | fprintf (stderr, format: "env_manager::getenv (%s) -> %s\n" , name, result); |
108 | return result; |
109 | } |
110 | |
111 | /* Put the given KEY=VALUE entry STRING into the environment. |
112 | If the env_manager was initialized with CAN_RESTORE set, then |
113 | also record the old value of KEY within the environment, so that it |
114 | can be later restored. */ |
115 | |
116 | void |
117 | env_manager::xput (const char *string) |
118 | { |
119 | if (m_debug) |
120 | fprintf (stderr, format: "env_manager::xput (%s)\n" , string); |
121 | if (verbose_flag) |
122 | fnotice (stderr, "%s\n" , string); |
123 | |
124 | if (m_can_restore) |
125 | { |
126 | char *equals = strchr (s: const_cast <char *> (string), c: '='); |
127 | gcc_assert (equals); |
128 | |
129 | struct kv kv; |
130 | kv.m_key = xstrndup (string, equals - string); |
131 | const char *cur_value = ::getenv (name: kv.m_key); |
132 | if (m_debug) |
133 | fprintf (stderr, format: "saving old value: %s\n" ,cur_value); |
134 | kv.m_value = cur_value ? xstrdup (cur_value) : NULL; |
135 | m_keys.safe_push (kv); |
136 | } |
137 | |
138 | ::putenv (CONST_CAST (char *, string)); |
139 | } |
140 | |
141 | /* Undo any xputenv changes made since last restore. |
142 | Can only be called if the env_manager was initialized with |
143 | CAN_RESTORE enabled. */ |
144 | |
145 | void |
146 | env_manager::restore () |
147 | { |
148 | unsigned int i; |
149 | struct kv *item; |
150 | |
151 | gcc_assert (m_can_restore); |
152 | |
153 | FOR_EACH_VEC_ELT_REVERSE (m_keys, i, item) |
154 | { |
155 | if (m_debug) |
156 | printf (format: "restoring saved key: %s value: %s\n" , item->m_key, item->m_value); |
157 | if (item->m_value) |
158 | ::setenv (name: item->m_key, value: item->m_value, replace: 1); |
159 | else |
160 | ::unsetenv (name: item->m_key); |
161 | free (ptr: item->m_key); |
162 | free (ptr: item->m_value); |
163 | } |
164 | |
165 | m_keys.truncate (0); |
166 | } |
167 | |
168 | /* Forbid other uses of getenv and putenv. */ |
169 | #if (GCC_VERSION >= 3000) |
170 | #pragma GCC poison getenv putenv |
171 | #endif |
172 | |
173 | |
174 | |
175 | /* By default there is no special suffix for target executables. */ |
176 | #ifdef TARGET_EXECUTABLE_SUFFIX |
177 | #define HAVE_TARGET_EXECUTABLE_SUFFIX |
178 | #else |
179 | #define TARGET_EXECUTABLE_SUFFIX "" |
180 | #endif |
181 | |
182 | /* By default there is no special suffix for host executables. */ |
183 | #ifdef HOST_EXECUTABLE_SUFFIX |
184 | #define HAVE_HOST_EXECUTABLE_SUFFIX |
185 | #else |
186 | #define HOST_EXECUTABLE_SUFFIX "" |
187 | #endif |
188 | |
189 | /* By default, the suffix for target object files is ".o". */ |
190 | #ifdef TARGET_OBJECT_SUFFIX |
191 | #define HAVE_TARGET_OBJECT_SUFFIX |
192 | #else |
193 | #define TARGET_OBJECT_SUFFIX ".o" |
194 | #endif |
195 | |
196 | static const char dir_separator_str[] = { DIR_SEPARATOR, 0 }; |
197 | |
198 | /* Most every one is fine with LIBRARY_PATH. For some, it conflicts. */ |
199 | #ifndef LIBRARY_PATH_ENV |
200 | #define LIBRARY_PATH_ENV "LIBRARY_PATH" |
201 | #endif |
202 | |
203 | /* If a stage of compilation returns an exit status >= 1, |
204 | compilation of that file ceases. */ |
205 | |
206 | #define MIN_FATAL_STATUS 1 |
207 | |
208 | /* Flag set by cppspec.cc to 1. */ |
209 | int is_cpp_driver; |
210 | |
211 | /* Flag set to nonzero if an @file argument has been supplied to gcc. */ |
212 | static bool at_file_supplied; |
213 | |
214 | /* Definition of string containing the arguments given to configure. */ |
215 | #include "configargs.h" |
216 | |
217 | /* Flag saying to print the command line options understood by gcc and its |
218 | sub-processes. */ |
219 | |
220 | static int print_help_list; |
221 | |
222 | /* Flag saying to print the version of gcc and its sub-processes. */ |
223 | |
224 | static int print_version; |
225 | |
226 | /* Flag that stores string prefix for which we provide bash completion. */ |
227 | |
228 | static const char *completion = NULL; |
229 | |
230 | /* Flag indicating whether we should ONLY print the command and |
231 | arguments (like verbose_flag) without executing the command. |
232 | Displayed arguments are quoted so that the generated command |
233 | line is suitable for execution. This is intended for use in |
234 | shell scripts to capture the driver-generated command line. */ |
235 | static int verbose_only_flag; |
236 | |
237 | /* Flag indicating how to print command line options of sub-processes. */ |
238 | |
239 | static int print_subprocess_help; |
240 | |
241 | /* Linker suffix passed to -fuse-ld=... */ |
242 | static const char *use_ld; |
243 | |
244 | /* Whether we should report subprocess execution times to a file. */ |
245 | |
246 | FILE *report_times_to_file = NULL; |
247 | |
248 | /* Nonzero means place this string before uses of /, so that include |
249 | and library files can be found in an alternate location. */ |
250 | |
251 | #ifdef TARGET_SYSTEM_ROOT |
252 | #define DEFAULT_TARGET_SYSTEM_ROOT (TARGET_SYSTEM_ROOT) |
253 | #else |
254 | #define DEFAULT_TARGET_SYSTEM_ROOT (0) |
255 | #endif |
256 | static const char *target_system_root = DEFAULT_TARGET_SYSTEM_ROOT; |
257 | |
258 | /* Nonzero means pass the updated target_system_root to the compiler. */ |
259 | |
260 | static int target_system_root_changed; |
261 | |
262 | /* Nonzero means append this string to target_system_root. */ |
263 | |
264 | static const char *target_sysroot_suffix = 0; |
265 | |
266 | /* Nonzero means append this string to target_system_root for headers. */ |
267 | |
268 | static const char *target_sysroot_hdrs_suffix = 0; |
269 | |
270 | /* Nonzero means write "temp" files in source directory |
271 | and use the source file's name in them, and don't delete them. */ |
272 | |
273 | static enum save_temps { |
274 | SAVE_TEMPS_NONE, /* no -save-temps */ |
275 | SAVE_TEMPS_CWD, /* -save-temps in current directory */ |
276 | SAVE_TEMPS_DUMP, /* -save-temps in dumpdir */ |
277 | SAVE_TEMPS_OBJ /* -save-temps in object directory */ |
278 | } save_temps_flag; |
279 | |
280 | /* Set this iff the dumppfx implied by a -save-temps=* option is to |
281 | override a -dumpdir option, if any. */ |
282 | static bool save_temps_overrides_dumpdir = false; |
283 | |
284 | /* -dumpdir, -dumpbase and -dumpbase-ext flags passed in, possibly |
285 | rearranged as they are to be passed down, e.g., dumpbase and |
286 | dumpbase_ext may be cleared if integrated with dumpdir or |
287 | dropped. */ |
288 | static char *dumpdir, *dumpbase, *dumpbase_ext; |
289 | |
290 | /* Usually the length of the string in dumpdir. However, during |
291 | linking, it may be shortened to omit a driver-added trailing dash, |
292 | by then replaced with a trailing period, that is still to be passed |
293 | to sub-processes in -dumpdir, but not to be generally used in spec |
294 | filename expansions. See maybe_run_linker. */ |
295 | static size_t dumpdir_length = 0; |
296 | |
297 | /* Set if the last character in dumpdir is (or was) a dash that the |
298 | driver added to dumpdir after dumpbase or linker output name. */ |
299 | static bool dumpdir_trailing_dash_added = false; |
300 | |
301 | /* Basename of dump and aux outputs, computed from dumpbase (given or |
302 | derived from output name), to override input_basename in non-%w %b |
303 | et al. */ |
304 | static char *outbase; |
305 | static size_t outbase_length = 0; |
306 | |
307 | /* The compiler version. */ |
308 | |
309 | static const char *compiler_version; |
310 | |
311 | /* The target version. */ |
312 | |
313 | static const char *const spec_version = DEFAULT_TARGET_VERSION; |
314 | |
315 | /* The target machine. */ |
316 | |
317 | static const char *spec_machine = DEFAULT_TARGET_MACHINE; |
318 | static const char *spec_host_machine = DEFAULT_REAL_TARGET_MACHINE; |
319 | |
320 | /* List of offload targets. Separated by colon. Empty string for |
321 | -foffload=disable. */ |
322 | |
323 | static char *offload_targets = NULL; |
324 | |
325 | #if OFFLOAD_DEFAULTED |
326 | /* Set to true if -foffload has not been used and offload_targets |
327 | is set to the configured in default. */ |
328 | static bool offload_targets_default; |
329 | #endif |
330 | |
331 | /* Nonzero if cross-compiling. |
332 | When -b is used, the value comes from the `specs' file. */ |
333 | |
334 | #ifdef CROSS_DIRECTORY_STRUCTURE |
335 | static const char *cross_compile = "1" ; |
336 | #else |
337 | static const char *cross_compile = "0" ; |
338 | #endif |
339 | |
340 | /* Greatest exit code of sub-processes that has been encountered up to |
341 | now. */ |
342 | static int greatest_status = 1; |
343 | |
344 | /* This is the obstack which we use to allocate many strings. */ |
345 | |
346 | static struct obstack obstack; |
347 | |
348 | /* This is the obstack to build an environment variable to pass to |
349 | collect2 that describes all of the relevant switches of what to |
350 | pass the compiler in building the list of pointers to constructors |
351 | and destructors. */ |
352 | |
353 | static struct obstack collect_obstack; |
354 | |
355 | /* Forward declaration for prototypes. */ |
356 | struct path_prefix; |
357 | struct prefix_list; |
358 | |
359 | static void init_spec (void); |
360 | static void store_arg (const char *, int, int); |
361 | static void insert_wrapper (const char *); |
362 | static char *load_specs (const char *); |
363 | static void read_specs (const char *, bool, bool); |
364 | static void set_spec (const char *, const char *, bool); |
365 | static struct compiler *lookup_compiler (const char *, size_t, const char *); |
366 | static char *build_search_list (const struct path_prefix *, const char *, |
367 | bool, bool); |
368 | static void xputenv (const char *); |
369 | static void putenv_from_prefixes (const struct path_prefix *, const char *, |
370 | bool); |
371 | static int access_check (const char *, int); |
372 | static char *find_a_file (const struct path_prefix *, const char *, int, bool); |
373 | static char *find_a_program (const char *); |
374 | static void add_prefix (struct path_prefix *, const char *, const char *, |
375 | int, int, int); |
376 | static void add_sysrooted_prefix (struct path_prefix *, const char *, |
377 | const char *, int, int, int); |
378 | static char *skip_whitespace (char *); |
379 | static void delete_if_ordinary (const char *); |
380 | static void delete_temp_files (void); |
381 | static void delete_failure_queue (void); |
382 | static void clear_failure_queue (void); |
383 | static int check_live_switch (int, int); |
384 | static const char *handle_braces (const char *); |
385 | static inline bool input_suffix_matches (const char *, const char *); |
386 | static inline bool switch_matches (const char *, const char *, int); |
387 | static inline void mark_matching_switches (const char *, const char *, int); |
388 | static inline void process_marked_switches (void); |
389 | static const char *process_brace_body (const char *, const char *, const char *, int, int); |
390 | static const struct spec_function *lookup_spec_function (const char *); |
391 | static const char *eval_spec_function (const char *, const char *, const char *); |
392 | static const char *handle_spec_function (const char *, bool *, const char *); |
393 | static char *save_string (const char *, int); |
394 | static void set_collect_gcc_options (void); |
395 | static int do_spec_1 (const char *, int, const char *); |
396 | static int do_spec_2 (const char *, const char *); |
397 | static void do_option_spec (const char *, const char *); |
398 | static void do_self_spec (const char *); |
399 | static const char *find_file (const char *); |
400 | static int is_directory (const char *, bool); |
401 | static const char *validate_switches (const char *, bool, bool); |
402 | static void validate_all_switches (void); |
403 | static inline void validate_switches_from_spec (const char *, bool); |
404 | static void give_switch (int, int); |
405 | static int default_arg (const char *, int); |
406 | static void set_multilib_dir (void); |
407 | static void print_multilib_info (void); |
408 | static void display_help (void); |
409 | static void add_preprocessor_option (const char *, int); |
410 | static void add_assembler_option (const char *, int); |
411 | static void add_linker_option (const char *, int); |
412 | static void process_command (unsigned int, struct cl_decoded_option *); |
413 | static int execute (void); |
414 | static void alloc_args (void); |
415 | static void clear_args (void); |
416 | static void fatal_signal (int); |
417 | #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC) |
418 | static void init_gcc_specs (struct obstack *, const char *, const char *, |
419 | const char *); |
420 | #endif |
421 | #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX) |
422 | static const char *convert_filename (const char *, int, int); |
423 | #endif |
424 | |
425 | static void try_generate_repro (const char **argv); |
426 | static const char *getenv_spec_function (int, const char **); |
427 | static const char *if_exists_spec_function (int, const char **); |
428 | static const char *if_exists_else_spec_function (int, const char **); |
429 | static const char *if_exists_then_else_spec_function (int, const char **); |
430 | static const char *sanitize_spec_function (int, const char **); |
431 | static const char *replace_outfile_spec_function (int, const char **); |
432 | static const char *remove_outfile_spec_function (int, const char **); |
433 | static const char *version_compare_spec_function (int, const char **); |
434 | static const char *include_spec_function (int, const char **); |
435 | static const char *find_file_spec_function (int, const char **); |
436 | static const char *find_plugindir_spec_function (int, const char **); |
437 | static const char *print_asm_header_spec_function (int, const char **); |
438 | static const char *compare_debug_dump_opt_spec_function (int, const char **); |
439 | static const char *compare_debug_self_opt_spec_function (int, const char **); |
440 | static const char *pass_through_libs_spec_func (int, const char **); |
441 | static const char *dumps_spec_func (int, const char **); |
442 | static const char *greater_than_spec_func (int, const char **); |
443 | static const char *debug_level_greater_than_spec_func (int, const char **); |
444 | static const char *dwarf_version_greater_than_spec_func (int, const char **); |
445 | static const char *find_fortran_preinclude_file (int, const char **); |
446 | static char *convert_white_space (char *); |
447 | static char *quote_spec (char *); |
448 | static char *quote_spec_arg (char *); |
449 | static bool not_actual_file_p (const char *); |
450 | |
451 | |
452 | /* The Specs Language |
453 | |
454 | Specs are strings containing lines, each of which (if not blank) |
455 | is made up of a program name, and arguments separated by spaces. |
456 | The program name must be exact and start from root, since no path |
457 | is searched and it is unreliable to depend on the current working directory. |
458 | Redirection of input or output is not supported; the subprograms must |
459 | accept filenames saying what files to read and write. |
460 | |
461 | In addition, the specs can contain %-sequences to substitute variable text |
462 | or for conditional text. Here is a table of all defined %-sequences. |
463 | Note that spaces are not generated automatically around the results of |
464 | expanding these sequences; therefore, you can concatenate them together |
465 | or with constant text in a single argument. |
466 | |
467 | %% substitute one % into the program name or argument. |
468 | %" substitute an empty argument. |
469 | %i substitute the name of the input file being processed. |
470 | %b substitute the basename for outputs related with the input file |
471 | being processed. This is often a substring of the input file name, |
472 | up to (and not including) the last period but, unless %w is active, |
473 | it is affected by the directory selected by -save-temps=*, by |
474 | -dumpdir, and, in case of multiple compilations, even by -dumpbase |
475 | and -dumpbase-ext and, in case of linking, by the linker output |
476 | name. When %w is active, it derives the main output name only from |
477 | the input file base name; when it is not, it names aux/dump output |
478 | file. |
479 | %B same as %b, but include the input file suffix (text after the last |
480 | period). |
481 | %gSUFFIX |
482 | substitute a file name that has suffix SUFFIX and is chosen |
483 | once per compilation, and mark the argument a la %d. To reduce |
484 | exposure to denial-of-service attacks, the file name is now |
485 | chosen in a way that is hard to predict even when previously |
486 | chosen file names are known. For example, `%g.s ... %g.o ... %g.s' |
487 | might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches |
488 | the regexp "[.0-9A-Za-z]*%O"; "%O" is treated exactly as if it |
489 | had been pre-processed. Previously, %g was simply substituted |
490 | with a file name chosen once per compilation, without regard |
491 | to any appended suffix (which was therefore treated just like |
492 | ordinary text), making such attacks more likely to succeed. |
493 | %|SUFFIX |
494 | like %g, but if -pipe is in effect, expands simply to "-". |
495 | %mSUFFIX |
496 | like %g, but if -pipe is in effect, expands to nothing. (We have both |
497 | %| and %m to accommodate differences between system assemblers; see |
498 | the AS_NEEDS_DASH_FOR_PIPED_INPUT target macro.) |
499 | %uSUFFIX |
500 | like %g, but generates a new temporary file name even if %uSUFFIX |
501 | was already seen. |
502 | %USUFFIX |
503 | substitutes the last file name generated with %uSUFFIX, generating a |
504 | new one if there is no such last file name. In the absence of any |
505 | %uSUFFIX, this is just like %gSUFFIX, except they don't share |
506 | the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s' |
507 | would involve the generation of two distinct file names, one |
508 | for each `%g.s' and another for each `%U.s'. Previously, %U was |
509 | simply substituted with a file name chosen for the previous %u, |
510 | without regard to any appended suffix. |
511 | %jSUFFIX |
512 | substitutes the name of the HOST_BIT_BUCKET, if any, and if it is |
513 | writable, and if save-temps is off; otherwise, substitute the name |
514 | of a temporary file, just like %u. This temporary file is not |
515 | meant for communication between processes, but rather as a junk |
516 | disposal mechanism. |
517 | %.SUFFIX |
518 | substitutes .SUFFIX for the suffixes of a matched switch's args when |
519 | it is subsequently output with %*. SUFFIX is terminated by the next |
520 | space or %. |
521 | %d marks the argument containing or following the %d as a |
522 | temporary file name, so that file will be deleted if GCC exits |
523 | successfully. Unlike %g, this contributes no text to the argument. |
524 | %w marks the argument containing or following the %w as the |
525 | "output file" of this compilation. This puts the argument |
526 | into the sequence of arguments that %o will substitute later. |
527 | %V indicates that this compilation produces no "output file". |
528 | %W{...} |
529 | like %{...} but marks the last argument supplied within as a file |
530 | to be deleted on failure. |
531 | %@{...} |
532 | like %{...} but puts the result into a FILE and substitutes @FILE |
533 | if an @file argument has been supplied. |
534 | %o substitutes the names of all the output files, with spaces |
535 | automatically placed around them. You should write spaces |
536 | around the %o as well or the results are undefined. |
537 | %o is for use in the specs for running the linker. |
538 | Input files whose names have no recognized suffix are not compiled |
539 | at all, but they are included among the output files, so they will |
540 | be linked. |
541 | %O substitutes the suffix for object files. Note that this is |
542 | handled specially when it immediately follows %g, %u, or %U |
543 | (with or without a suffix argument) because of the need for |
544 | those to form complete file names. The handling is such that |
545 | %O is treated exactly as if it had already been substituted, |
546 | except that %g, %u, and %U do not currently support additional |
547 | SUFFIX characters following %O as they would following, for |
548 | example, `.o'. |
549 | %I Substitute any of -iprefix (made from GCC_EXEC_PREFIX), -isysroot |
550 | (made from TARGET_SYSTEM_ROOT), -isystem (made from COMPILER_PATH |
551 | and -B options) and -imultilib as necessary. |
552 | %s current argument is the name of a library or startup file of some sort. |
553 | Search for that file in a standard list of directories |
554 | and substitute the full name found. |
555 | %T current argument is the name of a linker script. |
556 | Search for that file in the current list of directories to scan for |
557 | libraries. If the file is located, insert a --script option into the |
558 | command line followed by the full path name found. If the file is |
559 | not found then generate an error message. |
560 | Note: the current working directory is not searched. |
561 | %eSTR Print STR as an error message. STR is terminated by a newline. |
562 | Use this when inconsistent options are detected. |
563 | %nSTR Print STR as a notice. STR is terminated by a newline. |
564 | %x{OPTION} Accumulate an option for %X. |
565 | %X Output the accumulated linker options specified by compilations. |
566 | %Y Output the accumulated assembler options specified by compilations. |
567 | %Z Output the accumulated preprocessor options specified by compilations. |
568 | %a process ASM_SPEC as a spec. |
569 | This allows config.h to specify part of the spec for running as. |
570 | %A process ASM_FINAL_SPEC as a spec. A capital A is actually |
571 | used here. This can be used to run a post-processor after the |
572 | assembler has done its job. |
573 | %D Dump out a -L option for each directory in startfile_prefixes. |
574 | If multilib_dir is set, extra entries are generated with it affixed. |
575 | %l process LINK_SPEC as a spec. |
576 | %L process LIB_SPEC as a spec. |
577 | %M Output multilib_os_dir. |
578 | %G process LIBGCC_SPEC as a spec. |
579 | %R Output the concatenation of target_system_root and |
580 | target_sysroot_suffix. |
581 | %S process STARTFILE_SPEC as a spec. A capital S is actually used here. |
582 | %E process ENDFILE_SPEC as a spec. A capital E is actually used here. |
583 | %C process CPP_SPEC as a spec. |
584 | %1 process CC1_SPEC as a spec. |
585 | %2 process CC1PLUS_SPEC as a spec. |
586 | %* substitute the variable part of a matched option. (See below.) |
587 | Note that each comma in the substituted string is replaced by |
588 | a single space. A space is appended after the last substition |
589 | unless there is more text in current sequence. |
590 | %<S remove all occurrences of -S from the command line. |
591 | Note - this command is position dependent. % commands in the |
592 | spec string before this one will see -S, % commands in the |
593 | spec string after this one will not. |
594 | %>S Similar to "%<S", but keep it in the GCC command line. |
595 | %<S* remove all occurrences of all switches beginning with -S from the |
596 | command line. |
597 | %:function(args) |
598 | Call the named function FUNCTION, passing it ARGS. ARGS is |
599 | first processed as a nested spec string, then split into an |
600 | argument vector in the usual fashion. The function returns |
601 | a string which is processed as if it had appeared literally |
602 | as part of the current spec. |
603 | %{S} substitutes the -S switch, if that switch was given to GCC. |
604 | If that switch was not specified, this substitutes nothing. |
605 | Here S is a metasyntactic variable. |
606 | %{S*} substitutes all the switches specified to GCC whose names start |
607 | with -S. This is used for -o, -I, etc; switches that take |
608 | arguments. GCC considers `-o foo' as being one switch whose |
609 | name starts with `o'. %{o*} would substitute this text, |
610 | including the space; thus, two arguments would be generated. |
611 | %{S*&T*} likewise, but preserve order of S and T options (the order |
612 | of S and T in the spec is not significant). Can be any number |
613 | of ampersand-separated variables; for each the wild card is |
614 | optional. Useful for CPP as %{D*&U*&A*}. |
615 | |
616 | %{S:X} substitutes X, if the -S switch was given to GCC. |
617 | %{!S:X} substitutes X, if the -S switch was NOT given to GCC. |
618 | %{S*:X} substitutes X if one or more switches whose names start |
619 | with -S was given to GCC. Normally X is substituted only |
620 | once, no matter how many such switches appeared. However, |
621 | if %* appears somewhere in X, then X will be substituted |
622 | once for each matching switch, with the %* replaced by the |
623 | part of that switch that matched the '*'. A space will be |
624 | appended after the last substition unless there is more |
625 | text in current sequence. |
626 | %{.S:X} substitutes X, if processing a file with suffix S. |
627 | %{!.S:X} substitutes X, if NOT processing a file with suffix S. |
628 | %{,S:X} substitutes X, if processing a file which will use spec S. |
629 | %{!,S:X} substitutes X, if NOT processing a file which will use spec S. |
630 | |
631 | %{S|T:X} substitutes X if either -S or -T was given to GCC. This may be |
632 | combined with '!', '.', ',', and '*' as above binding stronger |
633 | than the OR. |
634 | If %* appears in X, all of the alternatives must be starred, and |
635 | only the first matching alternative is substituted. |
636 | %{%:function(args):X} |
637 | Call function named FUNCTION with args ARGS. If the function |
638 | returns non-NULL, then X is substituted, if it returns |
639 | NULL, it isn't substituted. |
640 | %{S:X; if S was given to GCC, substitutes X; |
641 | T:Y; else if T was given to GCC, substitutes Y; |
642 | :D} else substitutes D. There can be as many clauses as you need. |
643 | This may be combined with '.', '!', ',', '|', and '*' as above. |
644 | |
645 | %(Spec) processes a specification defined in a specs file as *Spec: |
646 | |
647 | The switch matching text S in a %{S}, %{S:X}, or similar construct can use |
648 | a backslash to ignore the special meaning of the character following it, |
649 | thus allowing literal matching of a character that is otherwise specially |
650 | treated. For example, %{std=iso9899\:1999:X} substitutes X if the |
651 | -std=iso9899:1999 option is given. |
652 | |
653 | The conditional text X in a %{S:X} or similar construct may contain |
654 | other nested % constructs or spaces, or even newlines. They are |
655 | processed as usual, as described above. Trailing white space in X is |
656 | ignored. White space may also appear anywhere on the left side of the |
657 | colon in these constructs, except between . or * and the corresponding |
658 | word. |
659 | |
660 | The -O, -f, -g, -m, and -W switches are handled specifically in these |
661 | constructs. If another value of -O or the negated form of a -f, -m, or |
662 | -W switch is found later in the command line, the earlier switch |
663 | value is ignored, except with {S*} where S is just one letter; this |
664 | passes all matching options. |
665 | |
666 | The character | at the beginning of the predicate text is used to indicate |
667 | that a command should be piped to the following command, but only if -pipe |
668 | is specified. |
669 | |
670 | Note that it is built into GCC which switches take arguments and which |
671 | do not. You might think it would be useful to generalize this to |
672 | allow each compiler's spec to say which switches take arguments. But |
673 | this cannot be done in a consistent fashion. GCC cannot even decide |
674 | which input files have been specified without knowing which switches |
675 | take arguments, and it must know which input files to compile in order |
676 | to tell which compilers to run. |
677 | |
678 | GCC also knows implicitly that arguments starting in `-l' are to be |
679 | treated as compiler output files, and passed to the linker in their |
680 | proper position among the other output files. */ |
681 | |
682 | /* Define the macros used for specs %a, %l, %L, %S, %C, %1. */ |
683 | |
684 | /* config.h can define ASM_SPEC to provide extra args to the assembler |
685 | or extra switch-translations. */ |
686 | #ifndef ASM_SPEC |
687 | #define ASM_SPEC "" |
688 | #endif |
689 | |
690 | /* config.h can define ASM_FINAL_SPEC to run a post processor after |
691 | the assembler has run. */ |
692 | #ifndef ASM_FINAL_SPEC |
693 | #define ASM_FINAL_SPEC \ |
694 | "%{gsplit-dwarf: \n\ |
695 | objcopy --extract-dwo \ |
696 | %{c:%{o*:%*}%{!o*:%w%b%O}}%{!c:%U%O} \ |
697 | %b.dwo \n\ |
698 | objcopy --strip-dwo \ |
699 | %{c:%{o*:%*}%{!o*:%w%b%O}}%{!c:%U%O} \ |
700 | }" |
701 | #endif |
702 | |
703 | /* config.h can define CPP_SPEC to provide extra args to the C preprocessor |
704 | or extra switch-translations. */ |
705 | #ifndef CPP_SPEC |
706 | #define CPP_SPEC "" |
707 | #endif |
708 | |
709 | /* Operating systems can define OS_CC1_SPEC to provide extra args to cc1 and |
710 | cc1plus or extra switch-translations. The OS_CC1_SPEC is appended |
711 | to CC1_SPEC in the initialization of cc1_spec. */ |
712 | #ifndef OS_CC1_SPEC |
713 | #define OS_CC1_SPEC "" |
714 | #endif |
715 | |
716 | /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus |
717 | or extra switch-translations. */ |
718 | #ifndef CC1_SPEC |
719 | #define CC1_SPEC "" |
720 | #endif |
721 | |
722 | /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus |
723 | or extra switch-translations. */ |
724 | #ifndef CC1PLUS_SPEC |
725 | #define CC1PLUS_SPEC "" |
726 | #endif |
727 | |
728 | /* config.h can define LINK_SPEC to provide extra args to the linker |
729 | or extra switch-translations. */ |
730 | #ifndef LINK_SPEC |
731 | #define LINK_SPEC "" |
732 | #endif |
733 | |
734 | /* config.h can define LIB_SPEC to override the default libraries. */ |
735 | #ifndef LIB_SPEC |
736 | #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}" |
737 | #endif |
738 | |
739 | /* When using -fsplit-stack we need to wrap pthread_create, in order |
740 | to initialize the stack guard. We always use wrapping, rather than |
741 | shared library ordering, and we keep the wrapper function in |
742 | libgcc. This is not yet a real spec, though it could become one; |
743 | it is currently just stuffed into LINK_SPEC. FIXME: This wrapping |
744 | only works with GNU ld and gold. */ |
745 | #ifdef HAVE_GOLD_NON_DEFAULT_SPLIT_STACK |
746 | #define STACK_SPLIT_SPEC " %{fsplit-stack: -fuse-ld=gold --wrap=pthread_create}" |
747 | #else |
748 | #define STACK_SPLIT_SPEC " %{fsplit-stack: --wrap=pthread_create}" |
749 | #endif |
750 | |
751 | #ifndef LIBASAN_SPEC |
752 | #define STATIC_LIBASAN_LIBS \ |
753 | " %{static-libasan|static:%:include(libsanitizer.spec)%(link_libasan)}" |
754 | #ifdef LIBASAN_EARLY_SPEC |
755 | #define LIBASAN_SPEC STATIC_LIBASAN_LIBS |
756 | #elif defined(HAVE_LD_STATIC_DYNAMIC) |
757 | #define LIBASAN_SPEC "%{static-libasan:" LD_STATIC_OPTION \ |
758 | "} -lasan %{static-libasan:" LD_DYNAMIC_OPTION "}" \ |
759 | STATIC_LIBASAN_LIBS |
760 | #else |
761 | #define LIBASAN_SPEC "-lasan" STATIC_LIBASAN_LIBS |
762 | #endif |
763 | #endif |
764 | |
765 | #ifndef LIBASAN_EARLY_SPEC |
766 | #define LIBASAN_EARLY_SPEC "" |
767 | #endif |
768 | |
769 | #ifndef LIBHWASAN_SPEC |
770 | #define STATIC_LIBHWASAN_LIBS \ |
771 | " %{static-libhwasan|static:%:include(libsanitizer.spec)%(link_libhwasan)}" |
772 | #ifdef LIBHWASAN_EARLY_SPEC |
773 | #define LIBHWASAN_SPEC STATIC_LIBHWASAN_LIBS |
774 | #elif defined(HAVE_LD_STATIC_DYNAMIC) |
775 | #define LIBHWASAN_SPEC "%{static-libhwasan:" LD_STATIC_OPTION \ |
776 | "} -lhwasan %{static-libhwasan:" LD_DYNAMIC_OPTION "}" \ |
777 | STATIC_LIBHWASAN_LIBS |
778 | #else |
779 | #define LIBHWASAN_SPEC "-lhwasan" STATIC_LIBHWASAN_LIBS |
780 | #endif |
781 | #endif |
782 | |
783 | #ifndef LIBHWASAN_EARLY_SPEC |
784 | #define LIBHWASAN_EARLY_SPEC "" |
785 | #endif |
786 | |
787 | #ifndef LIBTSAN_SPEC |
788 | #define STATIC_LIBTSAN_LIBS \ |
789 | " %{static-libtsan|static:%:include(libsanitizer.spec)%(link_libtsan)}" |
790 | #ifdef LIBTSAN_EARLY_SPEC |
791 | #define LIBTSAN_SPEC STATIC_LIBTSAN_LIBS |
792 | #elif defined(HAVE_LD_STATIC_DYNAMIC) |
793 | #define LIBTSAN_SPEC "%{static-libtsan:" LD_STATIC_OPTION \ |
794 | "} -ltsan %{static-libtsan:" LD_DYNAMIC_OPTION "}" \ |
795 | STATIC_LIBTSAN_LIBS |
796 | #else |
797 | #define LIBTSAN_SPEC "-ltsan" STATIC_LIBTSAN_LIBS |
798 | #endif |
799 | #endif |
800 | |
801 | #ifndef LIBTSAN_EARLY_SPEC |
802 | #define LIBTSAN_EARLY_SPEC "" |
803 | #endif |
804 | |
805 | #ifndef LIBLSAN_SPEC |
806 | #define STATIC_LIBLSAN_LIBS \ |
807 | " %{static-liblsan|static:%:include(libsanitizer.spec)%(link_liblsan)}" |
808 | #ifdef LIBLSAN_EARLY_SPEC |
809 | #define LIBLSAN_SPEC STATIC_LIBLSAN_LIBS |
810 | #elif defined(HAVE_LD_STATIC_DYNAMIC) |
811 | #define LIBLSAN_SPEC "%{static-liblsan:" LD_STATIC_OPTION \ |
812 | "} -llsan %{static-liblsan:" LD_DYNAMIC_OPTION "}" \ |
813 | STATIC_LIBLSAN_LIBS |
814 | #else |
815 | #define LIBLSAN_SPEC "-llsan" STATIC_LIBLSAN_LIBS |
816 | #endif |
817 | #endif |
818 | |
819 | #ifndef LIBLSAN_EARLY_SPEC |
820 | #define LIBLSAN_EARLY_SPEC "" |
821 | #endif |
822 | |
823 | #ifndef LIBUBSAN_SPEC |
824 | #define STATIC_LIBUBSAN_LIBS \ |
825 | " %{static-libubsan|static:%:include(libsanitizer.spec)%(link_libubsan)}" |
826 | #ifdef HAVE_LD_STATIC_DYNAMIC |
827 | #define LIBUBSAN_SPEC "%{static-libubsan:" LD_STATIC_OPTION \ |
828 | "} -lubsan %{static-libubsan:" LD_DYNAMIC_OPTION "}" \ |
829 | STATIC_LIBUBSAN_LIBS |
830 | #else |
831 | #define LIBUBSAN_SPEC "-lubsan" STATIC_LIBUBSAN_LIBS |
832 | #endif |
833 | #endif |
834 | |
835 | /* Linker options for compressed debug sections. */ |
836 | #if HAVE_LD_COMPRESS_DEBUG == 0 |
837 | /* No linker support. */ |
838 | #define LINK_COMPRESS_DEBUG_SPEC \ |
839 | " %{gz*:%e-gz is not supported in this configuration} " |
840 | #elif HAVE_LD_COMPRESS_DEBUG == 1 |
841 | /* ELF gABI style. */ |
842 | #define LINK_COMPRESS_DEBUG_SPEC \ |
843 | " %{gz|gz=zlib:" LD_COMPRESS_DEBUG_OPTION "=zlib}" \ |
844 | " %{gz=none:" LD_COMPRESS_DEBUG_OPTION "=none}" \ |
845 | " %{gz=zstd:%e-gz=zstd is not supported in this configuration} " \ |
846 | " %{gz=zlib-gnu:}" /* Ignore silently zlib-gnu option value. */ |
847 | #elif HAVE_LD_COMPRESS_DEBUG == 2 |
848 | /* ELF gABI style and ZSTD. */ |
849 | #define LINK_COMPRESS_DEBUG_SPEC \ |
850 | " %{gz|gz=zlib:" LD_COMPRESS_DEBUG_OPTION "=zlib}" \ |
851 | " %{gz=none:" LD_COMPRESS_DEBUG_OPTION "=none}" \ |
852 | " %{gz=zstd:" LD_COMPRESS_DEBUG_OPTION "=zstd}" \ |
853 | " %{gz=zlib-gnu:}" /* Ignore silently zlib-gnu option value. */ |
854 | #else |
855 | #error Unknown value for HAVE_LD_COMPRESS_DEBUG. |
856 | #endif |
857 | |
858 | /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is |
859 | included. */ |
860 | #ifndef LIBGCC_SPEC |
861 | #if defined(REAL_LIBGCC_SPEC) |
862 | #define LIBGCC_SPEC REAL_LIBGCC_SPEC |
863 | #elif defined(LINK_LIBGCC_SPECIAL_1) |
864 | /* Have gcc do the search for libgcc.a. */ |
865 | #define LIBGCC_SPEC "libgcc.a%s" |
866 | #else |
867 | #define LIBGCC_SPEC "-lgcc" |
868 | #endif |
869 | #endif |
870 | |
871 | /* config.h can define STARTFILE_SPEC to override the default crt0 files. */ |
872 | #ifndef STARTFILE_SPEC |
873 | #define STARTFILE_SPEC \ |
874 | "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}" |
875 | #endif |
876 | |
877 | /* config.h can define ENDFILE_SPEC to override the default crtn files. */ |
878 | #ifndef ENDFILE_SPEC |
879 | #define ENDFILE_SPEC "" |
880 | #endif |
881 | |
882 | #ifndef LINKER_NAME |
883 | #define LINKER_NAME "collect2" |
884 | #endif |
885 | |
886 | #ifdef HAVE_AS_DEBUG_PREFIX_MAP |
887 | #define ASM_MAP " %{ffile-prefix-map=*:--debug-prefix-map %*} %{fdebug-prefix-map=*:--debug-prefix-map %*}" |
888 | #else |
889 | #define ASM_MAP "" |
890 | #endif |
891 | |
892 | /* Assembler options for compressed debug sections. */ |
893 | #if HAVE_LD_COMPRESS_DEBUG == 0 |
894 | /* Reject if the linker cannot write compressed debug sections. */ |
895 | #define ASM_COMPRESS_DEBUG_SPEC \ |
896 | " %{gz*:%e-gz is not supported in this configuration} " |
897 | #else /* HAVE_LD_COMPRESS_DEBUG >= 1 */ |
898 | #if HAVE_AS_COMPRESS_DEBUG == 0 |
899 | /* No assembler support. Ignore silently. */ |
900 | #define ASM_COMPRESS_DEBUG_SPEC \ |
901 | " %{gz*:} " |
902 | #elif HAVE_AS_COMPRESS_DEBUG == 1 |
903 | /* ELF gABI style. */ |
904 | #define ASM_COMPRESS_DEBUG_SPEC \ |
905 | " %{gz|gz=zlib:" AS_COMPRESS_DEBUG_OPTION "=zlib}" \ |
906 | " %{gz=none:" AS_COMPRESS_DEBUG_OPTION "=none}" \ |
907 | " %{gz=zlib-gnu:}" /* Ignore silently zlib-gnu option value. */ |
908 | #elif HAVE_AS_COMPRESS_DEBUG == 2 |
909 | /* ELF gABI style and ZSTD. */ |
910 | #define ASM_COMPRESS_DEBUG_SPEC \ |
911 | " %{gz|gz=zlib:" AS_COMPRESS_DEBUG_OPTION "=zlib}" \ |
912 | " %{gz=none:" AS_COMPRESS_DEBUG_OPTION "=none}" \ |
913 | " %{gz=zstd:" AS_COMPRESS_DEBUG_OPTION "=zstd}" \ |
914 | " %{gz=zlib-gnu:}" /* Ignore silently zlib-gnu option value. */ |
915 | #else |
916 | #error Unknown value for HAVE_AS_COMPRESS_DEBUG. |
917 | #endif |
918 | #endif /* HAVE_LD_COMPRESS_DEBUG >= 1 */ |
919 | |
920 | /* Define ASM_DEBUG_SPEC to be a spec suitable for translating '-g' |
921 | to the assembler, when compiling assembly sources only. */ |
922 | #ifndef ASM_DEBUG_SPEC |
923 | # if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG) |
924 | /* If --gdwarf-N is supported and as can handle even compiler generated |
925 | .debug_line with it, supply --gdwarf-N in ASM_DEBUG_OPTION_SPEC rather |
926 | than in ASM_DEBUG_SPEC, so that it applies to both .s and .c etc. |
927 | compilations. */ |
928 | # define ASM_DEBUG_DWARF_OPTION "" |
929 | # elif defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && !defined(HAVE_LD_BROKEN_PE_DWARF5) |
930 | # define ASM_DEBUG_DWARF_OPTION "%{%:dwarf-version-gt(4):--gdwarf-5;" \ |
931 | "%:dwarf-version-gt(3):--gdwarf-4;" \ |
932 | "%:dwarf-version-gt(2):--gdwarf-3;" \ |
933 | ":--gdwarf2}" |
934 | # else |
935 | # define ASM_DEBUG_DWARF_OPTION "--gdwarf2" |
936 | # endif |
937 | # if defined(DWARF2_DEBUGGING_INFO) && defined(HAVE_AS_GDWARF2_DEBUG_FLAG) |
938 | # define ASM_DEBUG_SPEC "%{g*:%{%:debug-level-gt(0):" \ |
939 | ASM_DEBUG_DWARF_OPTION "}}" ASM_MAP |
940 | # endif |
941 | # endif |
942 | #ifndef ASM_DEBUG_SPEC |
943 | # define ASM_DEBUG_SPEC "" |
944 | #endif |
945 | |
946 | /* Define ASM_DEBUG_OPTION_SPEC to be a spec suitable for translating '-g' |
947 | to the assembler when compiling all sources. */ |
948 | #ifndef ASM_DEBUG_OPTION_SPEC |
949 | # if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG) |
950 | # define ASM_DEBUG_OPTION_DWARF_OPT \ |
951 | "%{%:dwarf-version-gt(4):--gdwarf-5 ;" \ |
952 | "%:dwarf-version-gt(3):--gdwarf-4 ;" \ |
953 | "%:dwarf-version-gt(2):--gdwarf-3 ;" \ |
954 | ":--gdwarf2 }" |
955 | # if defined(DWARF2_DEBUGGING_INFO) |
956 | # define ASM_DEBUG_OPTION_SPEC "%{g*:%{%:debug-level-gt(0):" \ |
957 | ASM_DEBUG_OPTION_DWARF_OPT "}}" |
958 | # endif |
959 | # endif |
960 | #endif |
961 | #ifndef ASM_DEBUG_OPTION_SPEC |
962 | # define ASM_DEBUG_OPTION_SPEC "" |
963 | #endif |
964 | |
965 | /* Here is the spec for running the linker, after compiling all files. */ |
966 | |
967 | /* This is overridable by the target in case they need to specify the |
968 | -lgcc and -lc order specially, yet not require them to override all |
969 | of LINK_COMMAND_SPEC. */ |
970 | #ifndef LINK_GCC_C_SEQUENCE_SPEC |
971 | #define LINK_GCC_C_SEQUENCE_SPEC "%G %{!nolibc:%L %G}" |
972 | #endif |
973 | |
974 | #ifndef LINK_SSP_SPEC |
975 | #ifdef TARGET_LIBC_PROVIDES_SSP |
976 | #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \ |
977 | "|fstack-protector-strong|fstack-protector-explicit:}" |
978 | #else |
979 | #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \ |
980 | "|fstack-protector-strong|fstack-protector-explicit" \ |
981 | ":-lssp_nonshared -lssp}" |
982 | #endif |
983 | #endif |
984 | |
985 | #ifdef ENABLE_DEFAULT_PIE |
986 | #define PIE_SPEC "!no-pie" |
987 | #define NO_FPIE1_SPEC "fno-pie" |
988 | #define FPIE1_SPEC NO_FPIE1_SPEC ":;" |
989 | #define NO_FPIE2_SPEC "fno-PIE" |
990 | #define FPIE2_SPEC NO_FPIE2_SPEC ":;" |
991 | #define NO_FPIE_SPEC NO_FPIE1_SPEC "|" NO_FPIE2_SPEC |
992 | #define FPIE_SPEC NO_FPIE_SPEC ":;" |
993 | #define NO_FPIC1_SPEC "fno-pic" |
994 | #define FPIC1_SPEC NO_FPIC1_SPEC ":;" |
995 | #define NO_FPIC2_SPEC "fno-PIC" |
996 | #define FPIC2_SPEC NO_FPIC2_SPEC ":;" |
997 | #define NO_FPIC_SPEC NO_FPIC1_SPEC "|" NO_FPIC2_SPEC |
998 | #define FPIC_SPEC NO_FPIC_SPEC ":;" |
999 | #define NO_FPIE1_AND_FPIC1_SPEC NO_FPIE1_SPEC "|" NO_FPIC1_SPEC |
1000 | #define FPIE1_OR_FPIC1_SPEC NO_FPIE1_AND_FPIC1_SPEC ":;" |
1001 | #define NO_FPIE2_AND_FPIC2_SPEC NO_FPIE2_SPEC "|" NO_FPIC2_SPEC |
1002 | #define FPIE2_OR_FPIC2_SPEC NO_FPIE2_AND_FPIC2_SPEC ":;" |
1003 | #define NO_FPIE_AND_FPIC_SPEC NO_FPIE_SPEC "|" NO_FPIC_SPEC |
1004 | #define FPIE_OR_FPIC_SPEC NO_FPIE_AND_FPIC_SPEC ":;" |
1005 | #else |
1006 | #define PIE_SPEC "pie" |
1007 | #define FPIE1_SPEC "fpie" |
1008 | #define NO_FPIE1_SPEC FPIE1_SPEC ":;" |
1009 | #define FPIE2_SPEC "fPIE" |
1010 | #define NO_FPIE2_SPEC FPIE2_SPEC ":;" |
1011 | #define FPIE_SPEC FPIE1_SPEC "|" FPIE2_SPEC |
1012 | #define NO_FPIE_SPEC FPIE_SPEC ":;" |
1013 | #define FPIC1_SPEC "fpic" |
1014 | #define NO_FPIC1_SPEC FPIC1_SPEC ":;" |
1015 | #define FPIC2_SPEC "fPIC" |
1016 | #define NO_FPIC2_SPEC FPIC2_SPEC ":;" |
1017 | #define FPIC_SPEC FPIC1_SPEC "|" FPIC2_SPEC |
1018 | #define NO_FPIC_SPEC FPIC_SPEC ":;" |
1019 | #define FPIE1_OR_FPIC1_SPEC FPIE1_SPEC "|" FPIC1_SPEC |
1020 | #define NO_FPIE1_AND_FPIC1_SPEC FPIE1_OR_FPIC1_SPEC ":;" |
1021 | #define FPIE2_OR_FPIC2_SPEC FPIE2_SPEC "|" FPIC2_SPEC |
1022 | #define NO_FPIE2_AND_FPIC2_SPEC FPIE1_OR_FPIC2_SPEC ":;" |
1023 | #define FPIE_OR_FPIC_SPEC FPIE_SPEC "|" FPIC_SPEC |
1024 | #define NO_FPIE_AND_FPIC_SPEC FPIE_OR_FPIC_SPEC ":;" |
1025 | #endif |
1026 | |
1027 | #ifndef LINK_PIE_SPEC |
1028 | #ifdef HAVE_LD_PIE |
1029 | #ifndef LD_PIE_SPEC |
1030 | #define LD_PIE_SPEC "-pie" |
1031 | #endif |
1032 | #else |
1033 | #define LD_PIE_SPEC "" |
1034 | #endif |
1035 | #define LINK_PIE_SPEC "%{static|shared|r:;" PIE_SPEC ":" LD_PIE_SPEC "} " |
1036 | #endif |
1037 | |
1038 | #ifndef LINK_BUILDID_SPEC |
1039 | # if defined(HAVE_LD_BUILDID) && defined(ENABLE_LD_BUILDID) |
1040 | # define LINK_BUILDID_SPEC "%{!r:--build-id} " |
1041 | # endif |
1042 | #endif |
1043 | |
1044 | #ifndef LTO_PLUGIN_SPEC |
1045 | #define LTO_PLUGIN_SPEC "" |
1046 | #endif |
1047 | |
1048 | /* Conditional to test whether the LTO plugin is used or not. |
1049 | FIXME: For slim LTO we will need to enable plugin unconditionally. This |
1050 | still cause problems with PLUGIN_LD != LD and when plugin is built but |
1051 | not useable. For GCC 4.6 we don't support slim LTO and thus we can enable |
1052 | plugin only when LTO is enabled. We still honor explicit |
1053 | -fuse-linker-plugin if the linker used understands -plugin. */ |
1054 | |
1055 | /* The linker has some plugin support. */ |
1056 | #if HAVE_LTO_PLUGIN > 0 |
1057 | /* The linker used has full plugin support, use LTO plugin by default. */ |
1058 | #if HAVE_LTO_PLUGIN == 2 |
1059 | #define PLUGIN_COND "!fno-use-linker-plugin:%{!fno-lto" |
1060 | #define PLUGIN_COND_CLOSE "}" |
1061 | #else |
1062 | /* The linker used has limited plugin support, use LTO plugin with explicit |
1063 | -fuse-linker-plugin. */ |
1064 | #define PLUGIN_COND "fuse-linker-plugin" |
1065 | #define PLUGIN_COND_CLOSE "" |
1066 | #endif |
1067 | #define LINK_PLUGIN_SPEC \ |
1068 | "%{" PLUGIN_COND": \ |
1069 | -plugin %(linker_plugin_file) \ |
1070 | -plugin-opt=%(lto_wrapper) \ |
1071 | -plugin-opt=-fresolution=%u.res \ |
1072 | " LTO_PLUGIN_SPEC "\ |
1073 | %{flinker-output=*:-plugin-opt=-linker-output-known} \ |
1074 | %{!nostdlib:%{!nodefaultlibs:%:pass-through-libs(%(link_gcc_c_sequence))}} \ |
1075 | }" PLUGIN_COND_CLOSE |
1076 | #else |
1077 | /* The linker used doesn't support -plugin, reject -fuse-linker-plugin. */ |
1078 | #define LINK_PLUGIN_SPEC "%{fuse-linker-plugin:\ |
1079 | %e-fuse-linker-plugin is not supported in this configuration}" |
1080 | #endif |
1081 | |
1082 | /* Linker command line options for -fsanitize= early on the command line. */ |
1083 | #ifndef SANITIZER_EARLY_SPEC |
1084 | #define SANITIZER_EARLY_SPEC "\ |
1085 | %{!nostdlib:%{!r:%{!nodefaultlibs:%{%:sanitize(address):" LIBASAN_EARLY_SPEC "} \ |
1086 | %{%:sanitize(hwaddress):" LIBHWASAN_EARLY_SPEC "} \ |
1087 | %{%:sanitize(thread):" LIBTSAN_EARLY_SPEC "} \ |
1088 | %{%:sanitize(leak):" LIBLSAN_EARLY_SPEC "}}}}" |
1089 | #endif |
1090 | |
1091 | /* Linker command line options for -fsanitize= late on the command line. */ |
1092 | #ifndef SANITIZER_SPEC |
1093 | #define SANITIZER_SPEC "\ |
1094 | %{!nostdlib:%{!r:%{!nodefaultlibs:%{%:sanitize(address):" LIBASAN_SPEC "\ |
1095 | %{static:%ecannot specify -static with -fsanitize=address}}\ |
1096 | %{%:sanitize(hwaddress):" LIBHWASAN_SPEC "\ |
1097 | %{static:%ecannot specify -static with -fsanitize=hwaddress}}\ |
1098 | %{%:sanitize(thread):" LIBTSAN_SPEC "\ |
1099 | %{static:%ecannot specify -static with -fsanitize=thread}}\ |
1100 | %{%:sanitize(undefined):" LIBUBSAN_SPEC "}\ |
1101 | %{%:sanitize(leak):" LIBLSAN_SPEC "}}}}" |
1102 | #endif |
1103 | |
1104 | #ifndef POST_LINK_SPEC |
1105 | #define POST_LINK_SPEC "" |
1106 | #endif |
1107 | |
1108 | /* This is the spec to use, once the code for creating the vtable |
1109 | verification runtime library, libvtv.so, has been created. Currently |
1110 | the vtable verification runtime functions are in libstdc++, so we use |
1111 | the spec just below this one. */ |
1112 | #ifndef VTABLE_VERIFICATION_SPEC |
1113 | #if ENABLE_VTABLE_VERIFY |
1114 | #define VTABLE_VERIFICATION_SPEC "\ |
1115 | %{!nostdlib:%{!r:%{fvtable-verify=std: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end}\ |
1116 | %{fvtable-verify=preinit: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end}}}" |
1117 | #else |
1118 | #define VTABLE_VERIFICATION_SPEC "\ |
1119 | %{fvtable-verify=none:} \ |
1120 | %{fvtable-verify=std: \ |
1121 | %e-fvtable-verify=std is not supported in this configuration} \ |
1122 | %{fvtable-verify=preinit: \ |
1123 | %e-fvtable-verify=preinit is not supported in this configuration}" |
1124 | #endif |
1125 | #endif |
1126 | |
1127 | /* -u* was put back because both BSD and SysV seem to support it. */ |
1128 | /* %{static|no-pie|static-pie:} simply prevents an error message: |
1129 | 1. If the target machine doesn't handle -static. |
1130 | 2. If PIE isn't enabled by default. |
1131 | 3. If the target machine doesn't handle -static-pie. |
1132 | */ |
1133 | /* We want %{T*} after %{L*} and %D so that it can be used to specify linker |
1134 | scripts which exist in user specified directories, or in standard |
1135 | directories. */ |
1136 | /* We pass any -flto flags on to the linker, which is expected |
1137 | to understand them. In practice, this means it had better be collect2. */ |
1138 | /* %{e*} includes -export-dynamic; see comment in common.opt. */ |
1139 | #ifndef LINK_COMMAND_SPEC |
1140 | #define LINK_COMMAND_SPEC "\ |
1141 | %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\ |
1142 | %(linker) " \ |
1143 | LINK_PLUGIN_SPEC \ |
1144 | "%{flto|flto=*:%<fcompare-debug*} \ |
1145 | %{flto} %{fno-lto} %{flto=*} %l " LINK_PIE_SPEC \ |
1146 | "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \ |
1147 | "%X %{o*} %{e*} %{N} %{n} %{r}\ |
1148 | %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \ |
1149 | %{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) " \ |
1150 | VTABLE_VERIFICATION_SPEC " " SANITIZER_EARLY_SPEC " %o "" \ |
1151 | %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\ |
1152 | %:include(libgomp.spec)%(link_gomp)}\ |
1153 | %{fgnu-tm:%:include(libitm.spec)%(link_itm)}\ |
1154 | %(mflib) " STACK_SPLIT_SPEC "\ |
1155 | %{fprofile-arcs|fprofile-generate*|coverage:-lgcov} " SANITIZER_SPEC " \ |
1156 | %{!nostdlib:%{!r:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}}\ |
1157 | %{!nostdlib:%{!r:%{!nostartfiles:%E}}} %{T*} \n%(post_link) }}}}}}" |
1158 | #endif |
1159 | |
1160 | #ifndef LINK_LIBGCC_SPEC |
1161 | /* Generate -L options for startfile prefix list. */ |
1162 | # define LINK_LIBGCC_SPEC "%D" |
1163 | #endif |
1164 | |
1165 | #ifndef STARTFILE_PREFIX_SPEC |
1166 | # define STARTFILE_PREFIX_SPEC "" |
1167 | #endif |
1168 | |
1169 | #ifndef SYSROOT_SPEC |
1170 | # define SYSROOT_SPEC "--sysroot=%R" |
1171 | #endif |
1172 | |
1173 | #ifndef SYSROOT_SUFFIX_SPEC |
1174 | # define SYSROOT_SUFFIX_SPEC "" |
1175 | #endif |
1176 | |
1177 | #ifndef SYSROOT_HEADERS_SUFFIX_SPEC |
1178 | # define "" |
1179 | #endif |
1180 | |
1181 | static const char *asm_debug = ASM_DEBUG_SPEC; |
1182 | static const char *asm_debug_option = ASM_DEBUG_OPTION_SPEC; |
1183 | static const char *cpp_spec = CPP_SPEC; |
1184 | static const char *cc1_spec = CC1_SPEC OS_CC1_SPEC; |
1185 | static const char *cc1plus_spec = CC1PLUS_SPEC; |
1186 | static const char *link_gcc_c_sequence_spec = LINK_GCC_C_SEQUENCE_SPEC; |
1187 | static const char *link_ssp_spec = LINK_SSP_SPEC; |
1188 | static const char *asm_spec = ASM_SPEC; |
1189 | static const char *asm_final_spec = ASM_FINAL_SPEC; |
1190 | static const char *link_spec = LINK_SPEC; |
1191 | static const char *lib_spec = LIB_SPEC; |
1192 | static const char *link_gomp_spec = "" ; |
1193 | static const char *libgcc_spec = LIBGCC_SPEC; |
1194 | static const char *endfile_spec = ENDFILE_SPEC; |
1195 | static const char *startfile_spec = STARTFILE_SPEC; |
1196 | static const char *linker_name_spec = LINKER_NAME; |
1197 | static const char *linker_plugin_file_spec = "" ; |
1198 | static const char *lto_wrapper_spec = "" ; |
1199 | static const char *lto_gcc_spec = "" ; |
1200 | static const char *post_link_spec = POST_LINK_SPEC; |
1201 | static const char *link_command_spec = LINK_COMMAND_SPEC; |
1202 | static const char *link_libgcc_spec = LINK_LIBGCC_SPEC; |
1203 | static const char *startfile_prefix_spec = STARTFILE_PREFIX_SPEC; |
1204 | static const char *sysroot_spec = SYSROOT_SPEC; |
1205 | static const char *sysroot_suffix_spec = SYSROOT_SUFFIX_SPEC; |
1206 | static const char *sysroot_hdrs_suffix_spec = SYSROOT_HEADERS_SUFFIX_SPEC; |
1207 | static const char *self_spec = "" ; |
1208 | |
1209 | /* Standard options to cpp, cc1, and as, to reduce duplication in specs. |
1210 | There should be no need to override these in target dependent files, |
1211 | but we need to copy them to the specs file so that newer versions |
1212 | of the GCC driver can correctly drive older tool chains with the |
1213 | appropriate -B options. */ |
1214 | |
1215 | /* When cpplib handles traditional preprocessing, get rid of this, and |
1216 | call cc1 (or cc1obj in objc/lang-specs.h) from the main specs so |
1217 | that we default the front end language better. */ |
1218 | static const char *trad_capable_cpp = |
1219 | "cc1 -E %{traditional|traditional-cpp:-traditional-cpp}" ; |
1220 | |
1221 | /* We don't wrap .d files in %W{} since a missing .d file, and |
1222 | therefore no dependency entry, confuses make into thinking a .o |
1223 | file that happens to exist is up-to-date. */ |
1224 | static const char *cpp_unique_options = |
1225 | "%{!Q:-quiet} %{nostdinc*} %{C} %{CC} %{v} %@{I*&F*} %{P} %I\ |
1226 | %{MD:-MD %{!o:%b.d}%{o*:%.d%*}}\ |
1227 | %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}}\ |
1228 | %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\ |
1229 | %{Mmodules} %{Mno-modules}\ |
1230 | %{!E:%{!M:%{!MM:%{!MT:%{!MQ:%{MD|MMD:%{o*:-MQ %*}}}}}}}\ |
1231 | %{remap} %{%:debug-level-gt(2):-dD}\ |
1232 | %{!iplugindir*:%{fplugin*:%:find-plugindir()}}\ |
1233 | %{H} %C %{D*&U*&A*} %{i*} %Z %i\ |
1234 | %{E|M|MM:%W{o*}}" ; |
1235 | |
1236 | /* This contains cpp options which are common with cc1_options and are passed |
1237 | only when preprocessing only to avoid duplication. We pass the cc1 spec |
1238 | options to the preprocessor so that it the cc1 spec may manipulate |
1239 | options used to set target flags. Those special target flags settings may |
1240 | in turn cause preprocessor symbols to be defined specially. */ |
1241 | static const char *cpp_options = |
1242 | "%(cpp_unique_options) %1 %{m*} %{std*&ansi&trigraphs} %{W*&pedantic*} %{w}\ |
1243 | %{f*} %{g*:%{%:debug-level-gt(0):%{g*}\ |
1244 | %{!fno-working-directory:-fworking-directory}}} %{O*}\ |
1245 | %{undef} %{save-temps*:-fpch-preprocess}" ; |
1246 | |
1247 | /* Pass -d* flags, possibly modifying -dumpdir, -dumpbase et al. |
1248 | |
1249 | Make it easy for a language to override the argument for the |
1250 | %:dumps specs function call. */ |
1251 | #define DUMPS_OPTIONS(EXTS) \ |
1252 | "%<dumpdir %<dumpbase %<dumpbase-ext %{d*} %:dumps(" EXTS ")" |
1253 | |
1254 | /* This contains cpp options which are not passed when the preprocessor |
1255 | output will be used by another program. */ |
1256 | static const char *cpp_debug_options = DUMPS_OPTIONS ("" ); |
1257 | |
1258 | /* NB: This is shared amongst all front-ends, except for Ada. */ |
1259 | static const char *cc1_options = |
1260 | "%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\ |
1261 | %{!iplugindir*:%{fplugin*:%:find-plugindir()}}\ |
1262 | %1 %{!Q:-quiet} %(cpp_debug_options) %{m*} %{aux-info*}\ |
1263 | %{g*} %{O*} %{W*&pedantic*} %{w} %{std*&ansi&trigraphs}\ |
1264 | %{v:-version} %{pg:-p} %{p} %{f*} %{undef}\ |
1265 | %{Qn:-fno-ident} %{Qy:} %{-help:--help}\ |
1266 | %{-target-help:--target-help}\ |
1267 | %{-version:--version}\ |
1268 | %{-help=*:--help=%*}\ |
1269 | %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %w%b.s}}}\ |
1270 | %{fsyntax-only:-o %j} %{-param*}\ |
1271 | %{coverage:-fprofile-arcs -ftest-coverage}\ |
1272 | %{fprofile-arcs|fprofile-generate*|coverage:\ |
1273 | %{!fprofile-update=single:\ |
1274 | %{pthread:-fprofile-update=prefer-atomic}}}" ; |
1275 | |
1276 | static const char *asm_options = |
1277 | "%{-target-help:%:print-asm-header()} " |
1278 | #if HAVE_GNU_AS |
1279 | /* If GNU AS is used, then convert -w (no warnings), -I, and -v |
1280 | to the assembler equivalents. */ |
1281 | "%{v} %{w:-W} %{I*} " |
1282 | #endif |
1283 | "%(asm_debug_option)" |
1284 | ASM_COMPRESS_DEBUG_SPEC |
1285 | "%a %Y %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}" ; |
1286 | |
1287 | static const char *invoke_as = |
1288 | #ifdef AS_NEEDS_DASH_FOR_PIPED_INPUT |
1289 | "%{!fwpa*:\ |
1290 | %{fcompare-debug=*|fdump-final-insns=*:%:compare-debug-dump-opt()}\ |
1291 | %{!S:-o %|.s |\n as %(asm_options) %|.s %A }\ |
1292 | }" ; |
1293 | #else |
1294 | "%{!fwpa*:\ |
1295 | %{fcompare-debug=*|fdump-final-insns=*:%:compare-debug-dump-opt()}\ |
1296 | %{!S:-o %|.s |\n as %(asm_options) %m.s %A }\ |
1297 | }" ; |
1298 | #endif |
1299 | |
1300 | /* Some compilers have limits on line lengths, and the multilib_select |
1301 | and/or multilib_matches strings can be very long, so we build them at |
1302 | run time. */ |
1303 | static struct obstack multilib_obstack; |
1304 | static const char *multilib_select; |
1305 | static const char *multilib_matches; |
1306 | static const char *multilib_defaults; |
1307 | static const char *multilib_exclusions; |
1308 | static const char *multilib_reuse; |
1309 | |
1310 | /* Check whether a particular argument is a default argument. */ |
1311 | |
1312 | #ifndef MULTILIB_DEFAULTS |
1313 | #define MULTILIB_DEFAULTS { "" } |
1314 | #endif |
1315 | |
1316 | static const char *const multilib_defaults_raw[] = MULTILIB_DEFAULTS; |
1317 | |
1318 | #ifndef DRIVER_SELF_SPECS |
1319 | #define DRIVER_SELF_SPECS "" |
1320 | #endif |
1321 | |
1322 | /* Linking to libgomp implies pthreads. This is particularly important |
1323 | for targets that use different start files and suchlike. */ |
1324 | #ifndef GOMP_SELF_SPECS |
1325 | #define GOMP_SELF_SPECS \ |
1326 | "%{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1): " \ |
1327 | "-pthread}" |
1328 | #endif |
1329 | |
1330 | /* Likewise for -fgnu-tm. */ |
1331 | #ifndef GTM_SELF_SPECS |
1332 | #define GTM_SELF_SPECS "%{fgnu-tm: -pthread}" |
1333 | #endif |
1334 | |
1335 | static const char *const driver_self_specs[] = { |
1336 | "%{fdump-final-insns:-fdump-final-insns=.} %<fdump-final-insns" , |
1337 | DRIVER_SELF_SPECS, CONFIGURE_SPECS, GOMP_SELF_SPECS, GTM_SELF_SPECS, |
1338 | /* This discards -fmultiflags at the end of self specs processing in the |
1339 | driver, so that it is effectively Ignored, without actually marking it as |
1340 | Ignored, which would get it discarded before self specs could remap it. */ |
1341 | "%<fmultiflags" |
1342 | }; |
1343 | |
1344 | #ifndef OPTION_DEFAULT_SPECS |
1345 | #define OPTION_DEFAULT_SPECS { "", "" } |
1346 | #endif |
1347 | |
1348 | struct default_spec |
1349 | { |
1350 | const char *name; |
1351 | const char *spec; |
1352 | }; |
1353 | |
1354 | static const struct default_spec |
1355 | option_default_specs[] = { OPTION_DEFAULT_SPECS }; |
1356 | |
1357 | struct user_specs |
1358 | { |
1359 | struct user_specs *next; |
1360 | const char *filename; |
1361 | }; |
1362 | |
1363 | static struct user_specs *user_specs_head, *user_specs_tail; |
1364 | |
1365 | |
1366 | /* Record the mapping from file suffixes for compilation specs. */ |
1367 | |
1368 | struct compiler |
1369 | { |
1370 | const char *suffix; /* Use this compiler for input files |
1371 | whose names end in this suffix. */ |
1372 | |
1373 | const char *spec; /* To use this compiler, run this spec. */ |
1374 | |
1375 | const char *cpp_spec; /* If non-NULL, substitute this spec |
1376 | for `%C', rather than the usual |
1377 | cpp_spec. */ |
1378 | int combinable; /* If nonzero, compiler can deal with |
1379 | multiple source files at once (IMA). */ |
1380 | int needs_preprocessing; /* If nonzero, source files need to |
1381 | be run through a preprocessor. */ |
1382 | }; |
1383 | |
1384 | /* Pointer to a vector of `struct compiler' that gives the spec for |
1385 | compiling a file, based on its suffix. |
1386 | A file that does not end in any of these suffixes will be passed |
1387 | unchanged to the loader and nothing else will be done to it. |
1388 | |
1389 | An entry containing two 0s is used to terminate the vector. |
1390 | |
1391 | If multiple entries match a file, the last matching one is used. */ |
1392 | |
1393 | static struct compiler *compilers; |
1394 | |
1395 | /* Number of entries in `compilers', not counting the null terminator. */ |
1396 | |
1397 | static int n_compilers; |
1398 | |
1399 | /* The default list of file name suffixes and their compilation specs. */ |
1400 | |
1401 | static const struct compiler default_compilers[] = |
1402 | { |
1403 | /* Add lists of suffixes of known languages here. If those languages |
1404 | were not present when we built the driver, we will hit these copies |
1405 | and be given a more meaningful error than "file not used since |
1406 | linking is not done". */ |
1407 | {.suffix: ".m" , .spec: "#Objective-C" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".mi" , .spec: "#Objective-C" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1408 | {.suffix: ".mm" , .spec: "#Objective-C++" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".M" , .spec: "#Objective-C++" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1409 | {.suffix: ".mii" , .spec: "#Objective-C++" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1410 | {.suffix: ".cc" , .spec: "#C++" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".cxx" , .spec: "#C++" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1411 | {.suffix: ".cpp" , .spec: "#C++" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".cp" , .spec: "#C++" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1412 | {.suffix: ".c++" , .spec: "#C++" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".C" , .spec: "#C++" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1413 | {.suffix: ".CPP" , .spec: "#C++" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".ii" , .spec: "#C++" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1414 | {.suffix: ".ads" , .spec: "#Ada" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".adb" , .spec: "#Ada" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1415 | {.suffix: ".f" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".F" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1416 | {.suffix: ".for" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".FOR" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1417 | {.suffix: ".ftn" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".FTN" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1418 | {.suffix: ".fpp" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".FPP" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1419 | {.suffix: ".f90" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".F90" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1420 | {.suffix: ".f95" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".F95" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1421 | {.suffix: ".f03" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".F03" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1422 | {.suffix: ".f08" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".F08" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1423 | {.suffix: ".r" , .spec: "#Ratfor" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1424 | {.suffix: ".go" , .spec: "#Go" , .cpp_spec: 0, .combinable: 1, .needs_preprocessing: 0}, |
1425 | {.suffix: ".d" , .spec: "#D" , .cpp_spec: 0, .combinable: 1, .needs_preprocessing: 0}, {.suffix: ".dd" , .spec: "#D" , .cpp_spec: 0, .combinable: 1, .needs_preprocessing: 0}, {.suffix: ".di" , .spec: "#D" , .cpp_spec: 0, .combinable: 1, .needs_preprocessing: 0}, |
1426 | {.suffix: ".mod" , .spec: "#Modula-2" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".m2i" , .spec: "#Modula-2" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1427 | /* Next come the entries for C. */ |
1428 | {.suffix: ".c" , .spec: "@c" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 1}, |
1429 | {.suffix: "@c" , |
1430 | /* cc1 has an integrated ISO C preprocessor. We should invoke the |
1431 | external preprocessor if -save-temps is given. */ |
1432 | .spec: "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\ |
1433 | %{!E:%{!M:%{!MM:\ |
1434 | %{traditional:\ |
1435 | %eGNU C no longer supports -traditional without -E}\ |
1436 | %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \ |
1437 | %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\ |
1438 | cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \ |
1439 | %(cc1_options)}\ |
1440 | %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\ |
1441 | cc1 %(cpp_unique_options) %(cc1_options)}}}\ |
1442 | %{!fsyntax-only:%(invoke_as)}}}}" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 1}, |
1443 | {.suffix: "-" , |
1444 | .spec: "%{!E:%e-E or -x required when input is from standard input}\ |
1445 | %(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1446 | {.suffix: ".h" , .spec: "@c-header" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1447 | {.suffix: "@c-header" , |
1448 | /* cc1 has an integrated ISO C preprocessor. We should invoke the |
1449 | external preprocessor if -save-temps is given. */ |
1450 | .spec: "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\ |
1451 | %{!E:%{!M:%{!MM:\ |
1452 | %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \ |
1453 | %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\ |
1454 | cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \ |
1455 | %(cc1_options)\ |
1456 | %{!fsyntax-only:%{!S:-o %g.s} \ |
1457 | %{!fdump-ada-spec*:%{!o*:--output-pch %i.gch}\ |
1458 | %W{o*:--output-pch %*}}%V}}\ |
1459 | %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\ |
1460 | cc1 %(cpp_unique_options) %(cc1_options)\ |
1461 | %{!fsyntax-only:%{!S:-o %g.s} \ |
1462 | %{!fdump-ada-spec*:%{!o*:--output-pch %i.gch}\ |
1463 | %W{o*:--output-pch %*}}%V}}}}}}}" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1464 | {.suffix: ".i" , .spec: "@cpp-output" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1465 | {.suffix: "@cpp-output" , |
1466 | .spec: "%{!M:%{!MM:%{!E:cc1 -fpreprocessed %i %(cc1_options) %{!fsyntax-only:%(invoke_as)}}}}" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1467 | {.suffix: ".s" , .spec: "@assembler" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1468 | {.suffix: "@assembler" , |
1469 | .spec: "%{!M:%{!MM:%{!E:%{!S:as %(asm_debug) %(asm_options) %i %A }}}}" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1470 | {.suffix: ".sx" , .spec: "@assembler-with-cpp" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1471 | {.suffix: ".S" , .spec: "@assembler-with-cpp" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1472 | {.suffix: "@assembler-with-cpp" , |
1473 | #ifdef AS_NEEDS_DASH_FOR_PIPED_INPUT |
1474 | "%(trad_capable_cpp) -lang-asm %(cpp_options) -fno-directives-only\ |
1475 | %{E|M|MM:%(cpp_debug_options)}\ |
1476 | %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\ |
1477 | as %(asm_debug) %(asm_options) %|.s %A }}}}" |
1478 | #else |
1479 | .spec: "%(trad_capable_cpp) -lang-asm %(cpp_options) -fno-directives-only\ |
1480 | %{E|M|MM:%(cpp_debug_options)}\ |
1481 | %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\ |
1482 | as %(asm_debug) %(asm_options) %m.s %A }}}}" |
1483 | #endif |
1484 | , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
1485 | |
1486 | #include "specs.h" |
1487 | /* Mark end of table. */ |
1488 | {.suffix: 0, .spec: 0, .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0} |
1489 | }; |
1490 | |
1491 | /* Number of elements in default_compilers, not counting the terminator. */ |
1492 | |
1493 | static const int n_default_compilers = ARRAY_SIZE (default_compilers) - 1; |
1494 | |
1495 | typedef char *char_p; /* For DEF_VEC_P. */ |
1496 | |
1497 | /* A vector of options to give to the linker. |
1498 | These options are accumulated by %x, |
1499 | and substituted into the linker command with %X. */ |
1500 | static vec<char_p> linker_options; |
1501 | |
1502 | /* A vector of options to give to the assembler. |
1503 | These options are accumulated by -Wa, |
1504 | and substituted into the assembler command with %Y. */ |
1505 | static vec<char_p> assembler_options; |
1506 | |
1507 | /* A vector of options to give to the preprocessor. |
1508 | These options are accumulated by -Wp, |
1509 | and substituted into the preprocessor command with %Z. */ |
1510 | static vec<char_p> preprocessor_options; |
1511 | |
1512 | static char * |
1513 | skip_whitespace (char *p) |
1514 | { |
1515 | while (1) |
1516 | { |
1517 | /* A fully-blank line is a delimiter in the SPEC file and shouldn't |
1518 | be considered whitespace. */ |
1519 | if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n') |
1520 | return p + 1; |
1521 | else if (*p == '\n' || *p == ' ' || *p == '\t') |
1522 | p++; |
1523 | else if (*p == '#') |
1524 | { |
1525 | while (*p != '\n') |
1526 | p++; |
1527 | p++; |
1528 | } |
1529 | else |
1530 | break; |
1531 | } |
1532 | |
1533 | return p; |
1534 | } |
1535 | /* Structures to keep track of prefixes to try when looking for files. */ |
1536 | |
1537 | struct prefix_list |
1538 | { |
1539 | const char *prefix; /* String to prepend to the path. */ |
1540 | struct prefix_list *next; /* Next in linked list. */ |
1541 | int require_machine_suffix; /* Don't use without machine_suffix. */ |
1542 | /* 2 means try both machine_suffix and just_machine_suffix. */ |
1543 | int priority; /* Sort key - priority within list. */ |
1544 | int os_multilib; /* 1 if OS multilib scheme should be used, |
1545 | 0 for GCC multilib scheme. */ |
1546 | }; |
1547 | |
1548 | struct path_prefix |
1549 | { |
1550 | struct prefix_list *plist; /* List of prefixes to try */ |
1551 | int max_len; /* Max length of a prefix in PLIST */ |
1552 | const char *name; /* Name of this list (used in config stuff) */ |
1553 | }; |
1554 | |
1555 | /* List of prefixes to try when looking for executables. */ |
1556 | |
1557 | static struct path_prefix exec_prefixes = { .plist: 0, .max_len: 0, .name: "exec" }; |
1558 | |
1559 | /* List of prefixes to try when looking for startup (crt0) files. */ |
1560 | |
1561 | static struct path_prefix startfile_prefixes = { .plist: 0, .max_len: 0, .name: "startfile" }; |
1562 | |
1563 | /* List of prefixes to try when looking for include files. */ |
1564 | |
1565 | static struct path_prefix include_prefixes = { .plist: 0, .max_len: 0, .name: "include" }; |
1566 | |
1567 | /* Suffix to attach to directories searched for commands. |
1568 | This looks like `MACHINE/VERSION/'. */ |
1569 | |
1570 | static const char *machine_suffix = 0; |
1571 | |
1572 | /* Suffix to attach to directories searched for commands. |
1573 | This is just `MACHINE/'. */ |
1574 | |
1575 | static const char *just_machine_suffix = 0; |
1576 | |
1577 | /* Adjusted value of GCC_EXEC_PREFIX envvar. */ |
1578 | |
1579 | static const char *gcc_exec_prefix; |
1580 | |
1581 | /* Adjusted value of standard_libexec_prefix. */ |
1582 | |
1583 | static const char *gcc_libexec_prefix; |
1584 | |
1585 | /* Default prefixes to attach to command names. */ |
1586 | |
1587 | #ifndef STANDARD_STARTFILE_PREFIX_1 |
1588 | #define STANDARD_STARTFILE_PREFIX_1 "/lib/" |
1589 | #endif |
1590 | #ifndef STANDARD_STARTFILE_PREFIX_2 |
1591 | #define STANDARD_STARTFILE_PREFIX_2 "/usr/lib/" |
1592 | #endif |
1593 | |
1594 | #ifdef CROSS_DIRECTORY_STRUCTURE /* Don't use these prefixes for a cross compiler. */ |
1595 | #undef MD_EXEC_PREFIX |
1596 | #undef MD_STARTFILE_PREFIX |
1597 | #undef MD_STARTFILE_PREFIX_1 |
1598 | #endif |
1599 | |
1600 | /* If no prefixes defined, use the null string, which will disable them. */ |
1601 | #ifndef MD_EXEC_PREFIX |
1602 | #define MD_EXEC_PREFIX "" |
1603 | #endif |
1604 | #ifndef MD_STARTFILE_PREFIX |
1605 | #define MD_STARTFILE_PREFIX "" |
1606 | #endif |
1607 | #ifndef MD_STARTFILE_PREFIX_1 |
1608 | #define MD_STARTFILE_PREFIX_1 "" |
1609 | #endif |
1610 | |
1611 | /* These directories are locations set at configure-time based on the |
1612 | --prefix option provided to configure. Their initializers are |
1613 | defined in Makefile.in. These paths are not *directly* used when |
1614 | gcc_exec_prefix is set because, in that case, we know where the |
1615 | compiler has been installed, and use paths relative to that |
1616 | location instead. */ |
1617 | static const char *const standard_exec_prefix = STANDARD_EXEC_PREFIX; |
1618 | static const char *const standard_libexec_prefix = STANDARD_LIBEXEC_PREFIX; |
1619 | static const char *const standard_bindir_prefix = STANDARD_BINDIR_PREFIX; |
1620 | static const char *const standard_startfile_prefix = STANDARD_STARTFILE_PREFIX; |
1621 | |
1622 | /* For native compilers, these are well-known paths containing |
1623 | components that may be provided by the system. For cross |
1624 | compilers, these paths are not used. */ |
1625 | static const char *md_exec_prefix = MD_EXEC_PREFIX; |
1626 | static const char *md_startfile_prefix = MD_STARTFILE_PREFIX; |
1627 | static const char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1; |
1628 | static const char *const standard_startfile_prefix_1 |
1629 | = STANDARD_STARTFILE_PREFIX_1; |
1630 | static const char *const standard_startfile_prefix_2 |
1631 | = STANDARD_STARTFILE_PREFIX_2; |
1632 | |
1633 | /* A relative path to be used in finding the location of tools |
1634 | relative to the driver. */ |
1635 | static const char *const tooldir_base_prefix = TOOLDIR_BASE_PREFIX; |
1636 | |
1637 | /* A prefix to be used when this is an accelerator compiler. */ |
1638 | static const char *const accel_dir_suffix = ACCEL_DIR_SUFFIX; |
1639 | |
1640 | /* Subdirectory to use for locating libraries. Set by |
1641 | set_multilib_dir based on the compilation options. */ |
1642 | |
1643 | static const char *multilib_dir; |
1644 | |
1645 | /* Subdirectory to use for locating libraries in OS conventions. Set by |
1646 | set_multilib_dir based on the compilation options. */ |
1647 | |
1648 | static const char *multilib_os_dir; |
1649 | |
1650 | /* Subdirectory to use for locating libraries in multiarch conventions. Set by |
1651 | set_multilib_dir based on the compilation options. */ |
1652 | |
1653 | static const char *multiarch_dir; |
1654 | |
1655 | /* Structure to keep track of the specs that have been defined so far. |
1656 | These are accessed using %(specname) in a compiler or link |
1657 | spec. */ |
1658 | |
1659 | struct spec_list |
1660 | { |
1661 | /* The following 2 fields must be first */ |
1662 | /* to allow EXTRA_SPECS to be initialized */ |
1663 | const char *name; /* name of the spec. */ |
1664 | const char *ptr; /* available ptr if no static pointer */ |
1665 | |
1666 | /* The following fields are not initialized */ |
1667 | /* by EXTRA_SPECS */ |
1668 | const char **ptr_spec; /* pointer to the spec itself. */ |
1669 | struct spec_list *next; /* Next spec in linked list. */ |
1670 | int name_len; /* length of the name */ |
1671 | bool user_p; /* whether string come from file spec. */ |
1672 | bool alloc_p; /* whether string was allocated */ |
1673 | const char *default_ptr; /* The default value of *ptr_spec. */ |
1674 | }; |
1675 | |
1676 | #define INIT_STATIC_SPEC(NAME,PTR) \ |
1677 | { NAME, NULL, PTR, (struct spec_list *) 0, sizeof (NAME) - 1, false, false, \ |
1678 | *PTR } |
1679 | |
1680 | /* List of statically defined specs. */ |
1681 | static struct spec_list static_specs[] = |
1682 | { |
1683 | INIT_STATIC_SPEC ("asm" , &asm_spec), |
1684 | INIT_STATIC_SPEC ("asm_debug" , &asm_debug), |
1685 | INIT_STATIC_SPEC ("asm_debug_option" , &asm_debug_option), |
1686 | INIT_STATIC_SPEC ("asm_final" , &asm_final_spec), |
1687 | INIT_STATIC_SPEC ("asm_options" , &asm_options), |
1688 | INIT_STATIC_SPEC ("invoke_as" , &invoke_as), |
1689 | INIT_STATIC_SPEC ("cpp" , &cpp_spec), |
1690 | INIT_STATIC_SPEC ("cpp_options" , &cpp_options), |
1691 | INIT_STATIC_SPEC ("cpp_debug_options" , &cpp_debug_options), |
1692 | INIT_STATIC_SPEC ("cpp_unique_options" , &cpp_unique_options), |
1693 | INIT_STATIC_SPEC ("trad_capable_cpp" , &trad_capable_cpp), |
1694 | INIT_STATIC_SPEC ("cc1" , &cc1_spec), |
1695 | INIT_STATIC_SPEC ("cc1_options" , &cc1_options), |
1696 | INIT_STATIC_SPEC ("cc1plus" , &cc1plus_spec), |
1697 | INIT_STATIC_SPEC ("link_gcc_c_sequence" , &link_gcc_c_sequence_spec), |
1698 | INIT_STATIC_SPEC ("link_ssp" , &link_ssp_spec), |
1699 | INIT_STATIC_SPEC ("endfile" , &endfile_spec), |
1700 | INIT_STATIC_SPEC ("link" , &link_spec), |
1701 | INIT_STATIC_SPEC ("lib" , &lib_spec), |
1702 | INIT_STATIC_SPEC ("link_gomp" , &link_gomp_spec), |
1703 | INIT_STATIC_SPEC ("libgcc" , &libgcc_spec), |
1704 | INIT_STATIC_SPEC ("startfile" , &startfile_spec), |
1705 | INIT_STATIC_SPEC ("cross_compile" , &cross_compile), |
1706 | INIT_STATIC_SPEC ("version" , &compiler_version), |
1707 | INIT_STATIC_SPEC ("multilib" , &multilib_select), |
1708 | INIT_STATIC_SPEC ("multilib_defaults" , &multilib_defaults), |
1709 | INIT_STATIC_SPEC ("multilib_extra" , &multilib_extra), |
1710 | INIT_STATIC_SPEC ("multilib_matches" , &multilib_matches), |
1711 | INIT_STATIC_SPEC ("multilib_exclusions" , &multilib_exclusions), |
1712 | INIT_STATIC_SPEC ("multilib_options" , &multilib_options), |
1713 | INIT_STATIC_SPEC ("multilib_reuse" , &multilib_reuse), |
1714 | INIT_STATIC_SPEC ("linker" , &linker_name_spec), |
1715 | INIT_STATIC_SPEC ("linker_plugin_file" , &linker_plugin_file_spec), |
1716 | INIT_STATIC_SPEC ("lto_wrapper" , <o_wrapper_spec), |
1717 | INIT_STATIC_SPEC ("lto_gcc" , <o_gcc_spec), |
1718 | INIT_STATIC_SPEC ("post_link" , &post_link_spec), |
1719 | INIT_STATIC_SPEC ("link_libgcc" , &link_libgcc_spec), |
1720 | INIT_STATIC_SPEC ("md_exec_prefix" , &md_exec_prefix), |
1721 | INIT_STATIC_SPEC ("md_startfile_prefix" , &md_startfile_prefix), |
1722 | INIT_STATIC_SPEC ("md_startfile_prefix_1" , &md_startfile_prefix_1), |
1723 | INIT_STATIC_SPEC ("startfile_prefix_spec" , &startfile_prefix_spec), |
1724 | INIT_STATIC_SPEC ("sysroot_spec" , &sysroot_spec), |
1725 | INIT_STATIC_SPEC ("sysroot_suffix_spec" , &sysroot_suffix_spec), |
1726 | INIT_STATIC_SPEC ("sysroot_hdrs_suffix_spec" , &sysroot_hdrs_suffix_spec), |
1727 | INIT_STATIC_SPEC ("self_spec" , &self_spec), |
1728 | }; |
1729 | |
1730 | #ifdef EXTRA_SPECS /* additional specs needed */ |
1731 | /* Structure to keep track of just the first two args of a spec_list. |
1732 | That is all that the EXTRA_SPECS macro gives us. */ |
1733 | struct spec_list_1 |
1734 | { |
1735 | const char *const name; |
1736 | const char *const ptr; |
1737 | }; |
1738 | |
1739 | static const struct spec_list_1 [] = { EXTRA_SPECS }; |
1740 | static struct spec_list * = (struct spec_list *) 0; |
1741 | #endif |
1742 | |
1743 | /* List of dynamically allocates specs that have been defined so far. */ |
1744 | |
1745 | static struct spec_list *specs = (struct spec_list *) 0; |
1746 | |
1747 | /* List of static spec functions. */ |
1748 | |
1749 | static const struct spec_function static_spec_functions[] = |
1750 | { |
1751 | { .name: "getenv" , .func: getenv_spec_function }, |
1752 | { .name: "if-exists" , .func: if_exists_spec_function }, |
1753 | { .name: "if-exists-else" , .func: if_exists_else_spec_function }, |
1754 | { .name: "if-exists-then-else" , .func: if_exists_then_else_spec_function }, |
1755 | { .name: "sanitize" , .func: sanitize_spec_function }, |
1756 | { .name: "replace-outfile" , .func: replace_outfile_spec_function }, |
1757 | { .name: "remove-outfile" , .func: remove_outfile_spec_function }, |
1758 | { .name: "version-compare" , .func: version_compare_spec_function }, |
1759 | { .name: "include" , .func: include_spec_function }, |
1760 | { .name: "find-file" , .func: find_file_spec_function }, |
1761 | { .name: "find-plugindir" , .func: find_plugindir_spec_function }, |
1762 | { .name: "print-asm-header" , .func: print_asm_header_spec_function }, |
1763 | { .name: "compare-debug-dump-opt" , .func: compare_debug_dump_opt_spec_function }, |
1764 | { .name: "compare-debug-self-opt" , .func: compare_debug_self_opt_spec_function }, |
1765 | { .name: "pass-through-libs" , .func: pass_through_libs_spec_func }, |
1766 | { .name: "dumps" , .func: dumps_spec_func }, |
1767 | { .name: "gt" , .func: greater_than_spec_func }, |
1768 | { .name: "debug-level-gt" , .func: debug_level_greater_than_spec_func }, |
1769 | { .name: "dwarf-version-gt" , .func: dwarf_version_greater_than_spec_func }, |
1770 | { .name: "fortran-preinclude-file" , .func: find_fortran_preinclude_file}, |
1771 | #ifdef EXTRA_SPEC_FUNCTIONS |
1772 | EXTRA_SPEC_FUNCTIONS |
1773 | #endif |
1774 | { .name: 0, .func: 0 } |
1775 | }; |
1776 | |
1777 | static int processing_spec_function; |
1778 | |
1779 | /* Add appropriate libgcc specs to OBSTACK, taking into account |
1780 | various permutations of -shared-libgcc, -shared, and such. */ |
1781 | |
1782 | #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC) |
1783 | |
1784 | #ifndef USE_LD_AS_NEEDED |
1785 | #define USE_LD_AS_NEEDED 0 |
1786 | #endif |
1787 | |
1788 | static void |
1789 | init_gcc_specs (struct obstack *obstack, const char *shared_name, |
1790 | const char *static_name, const char *eh_name) |
1791 | { |
1792 | char *buf; |
1793 | |
1794 | #if USE_LD_AS_NEEDED |
1795 | buf = concat ("%{static|static-libgcc|static-pie:" , static_name, " " , eh_name, "}" |
1796 | "%{!static:%{!static-libgcc:%{!static-pie:" |
1797 | "%{!shared-libgcc:" , |
1798 | static_name, " " LD_AS_NEEDED_OPTION " " , |
1799 | shared_name, " " LD_NO_AS_NEEDED_OPTION |
1800 | "}" |
1801 | "%{shared-libgcc:" , |
1802 | shared_name, "%{!shared: " , static_name, "}" |
1803 | "}}" |
1804 | #else |
1805 | buf = concat ("%{static|static-libgcc:" , static_name, " " , eh_name, "}" |
1806 | "%{!static:%{!static-libgcc:" |
1807 | "%{!shared:" |
1808 | "%{!shared-libgcc:" , static_name, " " , eh_name, "}" |
1809 | "%{shared-libgcc:" , shared_name, " " , static_name, "}" |
1810 | "}" |
1811 | #ifdef LINK_EH_SPEC |
1812 | "%{shared:" |
1813 | "%{shared-libgcc:" , shared_name, "}" |
1814 | "%{!shared-libgcc:" , static_name, "}" |
1815 | "}" |
1816 | #else |
1817 | "%{shared:" , shared_name, "}" |
1818 | #endif |
1819 | #endif |
1820 | "}}" , NULL); |
1821 | |
1822 | obstack_grow (obstack, buf, strlen (buf)); |
1823 | free (ptr: buf); |
1824 | } |
1825 | #endif /* ENABLE_SHARED_LIBGCC */ |
1826 | |
1827 | /* Initialize the specs lookup routines. */ |
1828 | |
1829 | static void |
1830 | init_spec (void) |
1831 | { |
1832 | struct spec_list *next = (struct spec_list *) 0; |
1833 | struct spec_list *sl = (struct spec_list *) 0; |
1834 | int i; |
1835 | |
1836 | if (specs) |
1837 | return; /* Already initialized. */ |
1838 | |
1839 | if (verbose_flag) |
1840 | fnotice (stderr, "Using built-in specs.\n" ); |
1841 | |
1842 | #ifdef EXTRA_SPECS |
1843 | extra_specs = XCNEWVEC (struct spec_list, ARRAY_SIZE (extra_specs_1)); |
1844 | |
1845 | for (i = ARRAY_SIZE (extra_specs_1) - 1; i >= 0; i--) |
1846 | { |
1847 | sl = &extra_specs[i]; |
1848 | sl->name = extra_specs_1[i].name; |
1849 | sl->ptr = extra_specs_1[i].ptr; |
1850 | sl->next = next; |
1851 | sl->name_len = strlen (s: sl->name); |
1852 | sl->ptr_spec = &sl->ptr; |
1853 | gcc_assert (sl->ptr_spec != NULL); |
1854 | sl->default_ptr = sl->ptr; |
1855 | next = sl; |
1856 | } |
1857 | #endif |
1858 | |
1859 | for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--) |
1860 | { |
1861 | sl = &static_specs[i]; |
1862 | sl->next = next; |
1863 | next = sl; |
1864 | } |
1865 | |
1866 | #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC) |
1867 | /* ??? If neither -shared-libgcc nor --static-libgcc was |
1868 | seen, then we should be making an educated guess. Some proposed |
1869 | heuristics for ELF include: |
1870 | |
1871 | (1) If "-Wl,--export-dynamic", then it's a fair bet that the |
1872 | program will be doing dynamic loading, which will likely |
1873 | need the shared libgcc. |
1874 | |
1875 | (2) If "-ldl", then it's also a fair bet that we're doing |
1876 | dynamic loading. |
1877 | |
1878 | (3) For each ET_DYN we're linking against (either through -lfoo |
1879 | or /some/path/foo.so), check to see whether it or one of |
1880 | its dependencies depends on a shared libgcc. |
1881 | |
1882 | (4) If "-shared" |
1883 | |
1884 | If the runtime is fixed to look for program headers instead |
1885 | of calling __register_frame_info at all, for each object, |
1886 | use the shared libgcc if any EH symbol referenced. |
1887 | |
1888 | If crtstuff is fixed to not invoke __register_frame_info |
1889 | automatically, for each object, use the shared libgcc if |
1890 | any non-empty unwind section found. |
1891 | |
1892 | Doing any of this probably requires invoking an external program to |
1893 | do the actual object file scanning. */ |
1894 | { |
1895 | const char *p = libgcc_spec; |
1896 | int in_sep = 1; |
1897 | |
1898 | /* Transform the extant libgcc_spec into one that uses the shared libgcc |
1899 | when given the proper command line arguments. */ |
1900 | while (*p) |
1901 | { |
1902 | if (in_sep && *p == '-' && startswith (str: p, prefix: "-lgcc" )) |
1903 | { |
1904 | init_gcc_specs (obstack: &obstack, |
1905 | shared_name: "-lgcc_s" |
1906 | #ifdef USE_LIBUNWIND_EXCEPTIONS |
1907 | " -lunwind" |
1908 | #endif |
1909 | , |
1910 | static_name: "-lgcc" , |
1911 | eh_name: "-lgcc_eh" |
1912 | #ifdef USE_LIBUNWIND_EXCEPTIONS |
1913 | # ifdef HAVE_LD_STATIC_DYNAMIC |
1914 | " %{!static:%{!static-pie:" LD_STATIC_OPTION "}} -lunwind" |
1915 | " %{!static:%{!static-pie:" LD_DYNAMIC_OPTION "}}" |
1916 | # else |
1917 | " -lunwind" |
1918 | # endif |
1919 | #endif |
1920 | ); |
1921 | |
1922 | p += 5; |
1923 | in_sep = 0; |
1924 | } |
1925 | else if (in_sep && *p == 'l' && startswith (str: p, prefix: "libgcc.a%s" )) |
1926 | { |
1927 | /* Ug. We don't know shared library extensions. Hope that |
1928 | systems that use this form don't do shared libraries. */ |
1929 | init_gcc_specs (obstack: &obstack, |
1930 | shared_name: "-lgcc_s" , |
1931 | static_name: "libgcc.a%s" , |
1932 | eh_name: "libgcc_eh.a%s" |
1933 | #ifdef USE_LIBUNWIND_EXCEPTIONS |
1934 | " -lunwind" |
1935 | #endif |
1936 | ); |
1937 | p += 10; |
1938 | in_sep = 0; |
1939 | } |
1940 | else |
1941 | { |
1942 | obstack_1grow (&obstack, *p); |
1943 | in_sep = (*p == ' '); |
1944 | p += 1; |
1945 | } |
1946 | } |
1947 | |
1948 | obstack_1grow (&obstack, '\0'); |
1949 | libgcc_spec = XOBFINISH (&obstack, const char *); |
1950 | } |
1951 | #endif |
1952 | #ifdef USE_AS_TRADITIONAL_FORMAT |
1953 | /* Prepend "--traditional-format" to whatever asm_spec we had before. */ |
1954 | { |
1955 | static const char tf[] = "--traditional-format " ; |
1956 | obstack_grow (&obstack, tf, sizeof (tf) - 1); |
1957 | obstack_grow0 (&obstack, asm_spec, strlen (asm_spec)); |
1958 | asm_spec = XOBFINISH (&obstack, const char *); |
1959 | } |
1960 | #endif |
1961 | |
1962 | #if defined LINK_EH_SPEC || defined LINK_BUILDID_SPEC || \ |
1963 | defined LINKER_HASH_STYLE |
1964 | # ifdef LINK_BUILDID_SPEC |
1965 | /* Prepend LINK_BUILDID_SPEC to whatever link_spec we had before. */ |
1966 | obstack_grow (&obstack, LINK_BUILDID_SPEC, sizeof (LINK_BUILDID_SPEC) - 1); |
1967 | # endif |
1968 | # ifdef LINK_EH_SPEC |
1969 | /* Prepend LINK_EH_SPEC to whatever link_spec we had before. */ |
1970 | obstack_grow (&obstack, LINK_EH_SPEC, sizeof (LINK_EH_SPEC) - 1); |
1971 | # endif |
1972 | # ifdef LINKER_HASH_STYLE |
1973 | /* Prepend --hash-style=LINKER_HASH_STYLE to whatever link_spec we had |
1974 | before. */ |
1975 | { |
1976 | static const char hash_style[] = "--hash-style=" ; |
1977 | obstack_grow (&obstack, hash_style, sizeof (hash_style) - 1); |
1978 | obstack_grow (&obstack, LINKER_HASH_STYLE, sizeof (LINKER_HASH_STYLE) - 1); |
1979 | obstack_1grow (&obstack, ' '); |
1980 | } |
1981 | # endif |
1982 | obstack_grow0 (&obstack, link_spec, strlen (link_spec)); |
1983 | link_spec = XOBFINISH (&obstack, const char *); |
1984 | #endif |
1985 | |
1986 | specs = sl; |
1987 | } |
1988 | |
1989 | /* Update the entry for SPEC in the static_specs table to point to VALUE, |
1990 | ensuring that we free the previous value if necessary. Set alloc_p for the |
1991 | entry to ALLOC_P: this determines whether we take ownership of VALUE (i.e. |
1992 | whether we need to free it later on). */ |
1993 | static void |
1994 | set_static_spec (const char **spec, const char *value, bool alloc_p) |
1995 | { |
1996 | struct spec_list *sl = NULL; |
1997 | |
1998 | for (unsigned i = 0; i < ARRAY_SIZE (static_specs); i++) |
1999 | { |
2000 | if (static_specs[i].ptr_spec == spec) |
2001 | { |
2002 | sl = static_specs + i; |
2003 | break; |
2004 | } |
2005 | } |
2006 | |
2007 | gcc_assert (sl); |
2008 | |
2009 | if (sl->alloc_p) |
2010 | { |
2011 | const char *old = *spec; |
2012 | free (ptr: const_cast <char *> (old)); |
2013 | } |
2014 | |
2015 | *spec = value; |
2016 | sl->alloc_p = alloc_p; |
2017 | } |
2018 | |
2019 | /* Update a static spec to a new string, taking ownership of that |
2020 | string's memory. */ |
2021 | static void set_static_spec_owned (const char **spec, const char *val) |
2022 | { |
2023 | return set_static_spec (spec, value: val, alloc_p: true); |
2024 | } |
2025 | |
2026 | /* Update a static spec to point to a new value, but don't take |
2027 | ownership of (i.e. don't free) that string. */ |
2028 | static void set_static_spec_shared (const char **spec, const char *val) |
2029 | { |
2030 | return set_static_spec (spec, value: val, alloc_p: false); |
2031 | } |
2032 | |
2033 | |
2034 | /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is |
2035 | removed; If the spec starts with a + then SPEC is added to the end of the |
2036 | current spec. */ |
2037 | |
2038 | static void |
2039 | set_spec (const char *name, const char *spec, bool user_p) |
2040 | { |
2041 | struct spec_list *sl; |
2042 | const char *old_spec; |
2043 | int name_len = strlen (s: name); |
2044 | int i; |
2045 | |
2046 | /* If this is the first call, initialize the statically allocated specs. */ |
2047 | if (!specs) |
2048 | { |
2049 | struct spec_list *next = (struct spec_list *) 0; |
2050 | for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--) |
2051 | { |
2052 | sl = &static_specs[i]; |
2053 | sl->next = next; |
2054 | next = sl; |
2055 | } |
2056 | specs = sl; |
2057 | } |
2058 | |
2059 | /* See if the spec already exists. */ |
2060 | for (sl = specs; sl; sl = sl->next) |
2061 | if (name_len == sl->name_len && !strcmp (s1: sl->name, s2: name)) |
2062 | break; |
2063 | |
2064 | if (!sl) |
2065 | { |
2066 | /* Not found - make it. */ |
2067 | sl = XNEW (struct spec_list); |
2068 | sl->name = xstrdup (name); |
2069 | sl->name_len = name_len; |
2070 | sl->ptr_spec = &sl->ptr; |
2071 | sl->alloc_p = 0; |
2072 | *(sl->ptr_spec) = "" ; |
2073 | sl->next = specs; |
2074 | sl->default_ptr = NULL; |
2075 | specs = sl; |
2076 | } |
2077 | |
2078 | old_spec = *(sl->ptr_spec); |
2079 | *(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE ((unsigned char)spec[1])) |
2080 | ? concat (old_spec, spec + 1, NULL) |
2081 | : xstrdup (spec)); |
2082 | |
2083 | #ifdef DEBUG_SPECS |
2084 | if (verbose_flag) |
2085 | fnotice (stderr, "Setting spec %s to '%s'\n\n" , name, *(sl->ptr_spec)); |
2086 | #endif |
2087 | |
2088 | /* Free the old spec. */ |
2089 | if (old_spec && sl->alloc_p) |
2090 | free (CONST_CAST (char *, old_spec)); |
2091 | |
2092 | sl->user_p = user_p; |
2093 | sl->alloc_p = true; |
2094 | } |
2095 | |
2096 | /* Accumulate a command (program name and args), and run it. */ |
2097 | |
2098 | typedef const char *const_char_p; /* For DEF_VEC_P. */ |
2099 | |
2100 | /* Vector of pointers to arguments in the current line of specifications. */ |
2101 | static vec<const_char_p> argbuf; |
2102 | |
2103 | /* Likewise, but for the current @file. */ |
2104 | static vec<const_char_p> at_file_argbuf; |
2105 | |
2106 | /* Whether an @file is currently open. */ |
2107 | static bool in_at_file = false; |
2108 | |
2109 | /* Were the options -c, -S or -E passed. */ |
2110 | static int have_c = 0; |
2111 | |
2112 | /* Was the option -o passed. */ |
2113 | static int have_o = 0; |
2114 | |
2115 | /* Was the option -E passed. */ |
2116 | static int have_E = 0; |
2117 | |
2118 | /* Pointer to output file name passed in with -o. */ |
2119 | static const char *output_file = 0; |
2120 | |
2121 | /* This is the list of suffixes and codes (%g/%u/%U/%j) and the associated |
2122 | temp file. If the HOST_BIT_BUCKET is used for %j, no entry is made for |
2123 | it here. */ |
2124 | |
2125 | static struct temp_name { |
2126 | const char *suffix; /* suffix associated with the code. */ |
2127 | int length; /* strlen (suffix). */ |
2128 | int unique; /* Indicates whether %g or %u/%U was used. */ |
2129 | const char *filename; /* associated filename. */ |
2130 | int filename_length; /* strlen (filename). */ |
2131 | struct temp_name *next; |
2132 | } *temp_names; |
2133 | |
2134 | /* Number of commands executed so far. */ |
2135 | |
2136 | static int execution_count; |
2137 | |
2138 | /* Number of commands that exited with a signal. */ |
2139 | |
2140 | static int signal_count; |
2141 | |
2142 | /* Allocate the argument vector. */ |
2143 | |
2144 | static void |
2145 | alloc_args (void) |
2146 | { |
2147 | argbuf.create (nelems: 10); |
2148 | at_file_argbuf.create (nelems: 10); |
2149 | } |
2150 | |
2151 | /* Clear out the vector of arguments (after a command is executed). */ |
2152 | |
2153 | static void |
2154 | clear_args (void) |
2155 | { |
2156 | argbuf.truncate (0); |
2157 | at_file_argbuf.truncate (0); |
2158 | } |
2159 | |
2160 | /* Add one argument to the vector at the end. |
2161 | This is done when a space is seen or at the end of the line. |
2162 | If DELETE_ALWAYS is nonzero, the arg is a filename |
2163 | and the file should be deleted eventually. |
2164 | If DELETE_FAILURE is nonzero, the arg is a filename |
2165 | and the file should be deleted if this compilation fails. */ |
2166 | |
2167 | static void |
2168 | store_arg (const char *arg, int delete_always, int delete_failure) |
2169 | { |
2170 | if (in_at_file) |
2171 | at_file_argbuf.safe_push (arg); |
2172 | else |
2173 | argbuf.safe_push (arg); |
2174 | |
2175 | if (delete_always || delete_failure) |
2176 | { |
2177 | const char *p; |
2178 | /* If the temporary file we should delete is specified as |
2179 | part of a joined argument extract the filename. */ |
2180 | if (arg[0] == '-' |
2181 | && (p = strrchr (s: arg, c: '='))) |
2182 | arg = p + 1; |
2183 | record_temp_file (arg, delete_always, delete_failure); |
2184 | } |
2185 | } |
2186 | |
2187 | /* Open a temporary @file into which subsequent arguments will be stored. */ |
2188 | |
2189 | static void |
2190 | open_at_file (void) |
2191 | { |
2192 | if (in_at_file) |
2193 | fatal_error (input_location, "cannot open nested response file" ); |
2194 | else |
2195 | in_at_file = true; |
2196 | } |
2197 | |
2198 | /* Create a temporary @file name. */ |
2199 | |
2200 | static char *make_at_file (void) |
2201 | { |
2202 | static int fileno = 0; |
2203 | char filename[20]; |
2204 | const char *base, *ext; |
2205 | |
2206 | if (!save_temps_flag) |
2207 | return make_temp_file ("" ); |
2208 | |
2209 | base = dumpbase; |
2210 | if (!(base && *base)) |
2211 | base = dumpdir; |
2212 | if (!(base && *base)) |
2213 | base = "a" ; |
2214 | |
2215 | sprintf (s: filename, format: ".args.%d" , fileno++); |
2216 | ext = filename; |
2217 | |
2218 | if (base == dumpdir && dumpdir_trailing_dash_added) |
2219 | ext++; |
2220 | |
2221 | return concat (base, ext, NULL); |
2222 | } |
2223 | |
2224 | /* Close the temporary @file and add @file to the argument list. */ |
2225 | |
2226 | static void |
2227 | close_at_file (void) |
2228 | { |
2229 | if (!in_at_file) |
2230 | fatal_error (input_location, "cannot close nonexistent response file" ); |
2231 | |
2232 | in_at_file = false; |
2233 | |
2234 | const unsigned int n_args = at_file_argbuf.length (); |
2235 | if (n_args == 0) |
2236 | return; |
2237 | |
2238 | char **argv = XALLOCAVEC (char *, n_args + 1); |
2239 | char *temp_file = make_at_file (); |
2240 | char *at_argument = concat ("@" , temp_file, NULL); |
2241 | FILE *f = fopen (filename: temp_file, modes: "w" ); |
2242 | int status; |
2243 | unsigned int i; |
2244 | |
2245 | /* Copy the strings over. */ |
2246 | for (i = 0; i < n_args; i++) |
2247 | argv[i] = CONST_CAST (char *, at_file_argbuf[i]); |
2248 | argv[i] = NULL; |
2249 | |
2250 | at_file_argbuf.truncate (0); |
2251 | |
2252 | if (f == NULL) |
2253 | fatal_error (input_location, "could not open temporary response file %s" , |
2254 | temp_file); |
2255 | |
2256 | status = writeargv (argv, f); |
2257 | |
2258 | if (status) |
2259 | fatal_error (input_location, |
2260 | "could not write to temporary response file %s" , |
2261 | temp_file); |
2262 | |
2263 | status = fclose (stream: f); |
2264 | |
2265 | if (status == EOF) |
2266 | fatal_error (input_location, "could not close temporary response file %s" , |
2267 | temp_file); |
2268 | |
2269 | store_arg (arg: at_argument, delete_always: 0, delete_failure: 0); |
2270 | |
2271 | record_temp_file (temp_file, !save_temps_flag, !save_temps_flag); |
2272 | } |
2273 | |
2274 | /* Load specs from a file name named FILENAME, replacing occurrences of |
2275 | various different types of line-endings, \r\n, \n\r and just \r, with |
2276 | a single \n. */ |
2277 | |
2278 | static char * |
2279 | load_specs (const char *filename) |
2280 | { |
2281 | int desc; |
2282 | int readlen; |
2283 | struct stat statbuf; |
2284 | char *buffer; |
2285 | char *buffer_p; |
2286 | char *specs; |
2287 | char *specs_p; |
2288 | |
2289 | if (verbose_flag) |
2290 | fnotice (stderr, "Reading specs from %s\n" , filename); |
2291 | |
2292 | /* Open and stat the file. */ |
2293 | desc = open (file: filename, O_RDONLY, 0); |
2294 | if (desc < 0) |
2295 | { |
2296 | failed: |
2297 | /* This leaves DESC open, but the OS will save us. */ |
2298 | fatal_error (input_location, "cannot read spec file %qs: %m" , filename); |
2299 | } |
2300 | |
2301 | if (stat (path: filename, statbuf: &statbuf) < 0) |
2302 | goto failed; |
2303 | |
2304 | /* Read contents of file into BUFFER. */ |
2305 | buffer = XNEWVEC (char, statbuf.st_size + 1); |
2306 | readlen = read (fd: desc, buf: buffer, nbytes: (unsigned) statbuf.st_size); |
2307 | if (readlen < 0) |
2308 | goto failed; |
2309 | buffer[readlen] = 0; |
2310 | close (fd: desc); |
2311 | |
2312 | specs = XNEWVEC (char, readlen + 1); |
2313 | specs_p = specs; |
2314 | for (buffer_p = buffer; buffer_p && *buffer_p; buffer_p++) |
2315 | { |
2316 | int skip = 0; |
2317 | char c = *buffer_p; |
2318 | if (c == '\r') |
2319 | { |
2320 | if (buffer_p > buffer && *(buffer_p - 1) == '\n') /* \n\r */ |
2321 | skip = 1; |
2322 | else if (*(buffer_p + 1) == '\n') /* \r\n */ |
2323 | skip = 1; |
2324 | else /* \r */ |
2325 | c = '\n'; |
2326 | } |
2327 | if (! skip) |
2328 | *specs_p++ = c; |
2329 | } |
2330 | *specs_p = '\0'; |
2331 | |
2332 | free (ptr: buffer); |
2333 | return (specs); |
2334 | } |
2335 | |
2336 | /* Read compilation specs from a file named FILENAME, |
2337 | replacing the default ones. |
2338 | |
2339 | A suffix which starts with `*' is a definition for |
2340 | one of the machine-specific sub-specs. The "suffix" should be |
2341 | *asm, *cc1, *cpp, *link, *startfile, etc. |
2342 | The corresponding spec is stored in asm_spec, etc., |
2343 | rather than in the `compilers' vector. |
2344 | |
2345 | Anything invalid in the file is a fatal error. */ |
2346 | |
2347 | static void |
2348 | read_specs (const char *filename, bool main_p, bool user_p) |
2349 | { |
2350 | char *buffer; |
2351 | char *p; |
2352 | |
2353 | buffer = load_specs (filename); |
2354 | |
2355 | /* Scan BUFFER for specs, putting them in the vector. */ |
2356 | p = buffer; |
2357 | while (1) |
2358 | { |
2359 | char *suffix; |
2360 | char *spec; |
2361 | char *in, *out, *p1, *p2, *p3; |
2362 | |
2363 | /* Advance P in BUFFER to the next nonblank nocomment line. */ |
2364 | p = skip_whitespace (p); |
2365 | if (*p == 0) |
2366 | break; |
2367 | |
2368 | /* Is this a special command that starts with '%'? */ |
2369 | /* Don't allow this for the main specs file, since it would |
2370 | encourage people to overwrite it. */ |
2371 | if (*p == '%' && !main_p) |
2372 | { |
2373 | p1 = p; |
2374 | while (*p && *p != '\n') |
2375 | p++; |
2376 | |
2377 | /* Skip '\n'. */ |
2378 | p++; |
2379 | |
2380 | if (startswith (str: p1, prefix: "%include" ) |
2381 | && (p1[sizeof "%include" - 1] == ' ' |
2382 | || p1[sizeof "%include" - 1] == '\t')) |
2383 | { |
2384 | char *new_filename; |
2385 | |
2386 | p1 += sizeof ("%include" ); |
2387 | while (*p1 == ' ' || *p1 == '\t') |
2388 | p1++; |
2389 | |
2390 | if (*p1++ != '<' || p[-2] != '>') |
2391 | fatal_error (input_location, |
2392 | "specs %%include syntax malformed after " |
2393 | "%ld characters" , |
2394 | (long) (p1 - buffer + 1)); |
2395 | |
2396 | p[-2] = '\0'; |
2397 | new_filename = find_a_file (&startfile_prefixes, p1, R_OK, true); |
2398 | read_specs (filename: new_filename ? new_filename : p1, main_p: false, user_p); |
2399 | continue; |
2400 | } |
2401 | else if (startswith (str: p1, prefix: "%include_noerr" ) |
2402 | && (p1[sizeof "%include_noerr" - 1] == ' ' |
2403 | || p1[sizeof "%include_noerr" - 1] == '\t')) |
2404 | { |
2405 | char *new_filename; |
2406 | |
2407 | p1 += sizeof "%include_noerr" ; |
2408 | while (*p1 == ' ' || *p1 == '\t') |
2409 | p1++; |
2410 | |
2411 | if (*p1++ != '<' || p[-2] != '>') |
2412 | fatal_error (input_location, |
2413 | "specs %%include syntax malformed after " |
2414 | "%ld characters" , |
2415 | (long) (p1 - buffer + 1)); |
2416 | |
2417 | p[-2] = '\0'; |
2418 | new_filename = find_a_file (&startfile_prefixes, p1, R_OK, true); |
2419 | if (new_filename) |
2420 | read_specs (filename: new_filename, main_p: false, user_p); |
2421 | else if (verbose_flag) |
2422 | fnotice (stderr, "could not find specs file %s\n" , p1); |
2423 | continue; |
2424 | } |
2425 | else if (startswith (str: p1, prefix: "%rename" ) |
2426 | && (p1[sizeof "%rename" - 1] == ' ' |
2427 | || p1[sizeof "%rename" - 1] == '\t')) |
2428 | { |
2429 | int name_len; |
2430 | struct spec_list *sl; |
2431 | struct spec_list *newsl; |
2432 | |
2433 | /* Get original name. */ |
2434 | p1 += sizeof "%rename" ; |
2435 | while (*p1 == ' ' || *p1 == '\t') |
2436 | p1++; |
2437 | |
2438 | if (! ISALPHA ((unsigned char) *p1)) |
2439 | fatal_error (input_location, |
2440 | "specs %%rename syntax malformed after " |
2441 | "%ld characters" , |
2442 | (long) (p1 - buffer)); |
2443 | |
2444 | p2 = p1; |
2445 | while (*p2 && !ISSPACE ((unsigned char) *p2)) |
2446 | p2++; |
2447 | |
2448 | if (*p2 != ' ' && *p2 != '\t') |
2449 | fatal_error (input_location, |
2450 | "specs %%rename syntax malformed after " |
2451 | "%ld characters" , |
2452 | (long) (p2 - buffer)); |
2453 | |
2454 | name_len = p2 - p1; |
2455 | *p2++ = '\0'; |
2456 | while (*p2 == ' ' || *p2 == '\t') |
2457 | p2++; |
2458 | |
2459 | if (! ISALPHA ((unsigned char) *p2)) |
2460 | fatal_error (input_location, |
2461 | "specs %%rename syntax malformed after " |
2462 | "%ld characters" , |
2463 | (long) (p2 - buffer)); |
2464 | |
2465 | /* Get new spec name. */ |
2466 | p3 = p2; |
2467 | while (*p3 && !ISSPACE ((unsigned char) *p3)) |
2468 | p3++; |
2469 | |
2470 | if (p3 != p - 1) |
2471 | fatal_error (input_location, |
2472 | "specs %%rename syntax malformed after " |
2473 | "%ld characters" , |
2474 | (long) (p3 - buffer)); |
2475 | *p3 = '\0'; |
2476 | |
2477 | for (sl = specs; sl; sl = sl->next) |
2478 | if (name_len == sl->name_len && !strcmp (s1: sl->name, s2: p1)) |
2479 | break; |
2480 | |
2481 | if (!sl) |
2482 | fatal_error (input_location, |
2483 | "specs %s spec was not found to be renamed" , p1); |
2484 | |
2485 | if (strcmp (s1: p1, s2: p2) == 0) |
2486 | continue; |
2487 | |
2488 | for (newsl = specs; newsl; newsl = newsl->next) |
2489 | if (strcmp (s1: newsl->name, s2: p2) == 0) |
2490 | fatal_error (input_location, |
2491 | "%s: attempt to rename spec %qs to " |
2492 | "already defined spec %qs" , |
2493 | filename, p1, p2); |
2494 | |
2495 | if (verbose_flag) |
2496 | { |
2497 | fnotice (stderr, "rename spec %s to %s\n" , p1, p2); |
2498 | #ifdef DEBUG_SPECS |
2499 | fnotice (stderr, "spec is '%s'\n\n" , *(sl->ptr_spec)); |
2500 | #endif |
2501 | } |
2502 | |
2503 | set_spec (name: p2, spec: *(sl->ptr_spec), user_p); |
2504 | if (sl->alloc_p) |
2505 | free (CONST_CAST (char *, *(sl->ptr_spec))); |
2506 | |
2507 | *(sl->ptr_spec) = "" ; |
2508 | sl->alloc_p = 0; |
2509 | continue; |
2510 | } |
2511 | else |
2512 | fatal_error (input_location, |
2513 | "specs unknown %% command after %ld characters" , |
2514 | (long) (p1 - buffer)); |
2515 | } |
2516 | |
2517 | /* Find the colon that should end the suffix. */ |
2518 | p1 = p; |
2519 | while (*p1 && *p1 != ':' && *p1 != '\n') |
2520 | p1++; |
2521 | |
2522 | /* The colon shouldn't be missing. */ |
2523 | if (*p1 != ':') |
2524 | fatal_error (input_location, |
2525 | "specs file malformed after %ld characters" , |
2526 | (long) (p1 - buffer)); |
2527 | |
2528 | /* Skip back over trailing whitespace. */ |
2529 | p2 = p1; |
2530 | while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t')) |
2531 | p2--; |
2532 | |
2533 | /* Copy the suffix to a string. */ |
2534 | suffix = save_string (p, p2 - p); |
2535 | /* Find the next line. */ |
2536 | p = skip_whitespace (p: p1 + 1); |
2537 | if (p[1] == 0) |
2538 | fatal_error (input_location, |
2539 | "specs file malformed after %ld characters" , |
2540 | (long) (p - buffer)); |
2541 | |
2542 | p1 = p; |
2543 | /* Find next blank line or end of string. */ |
2544 | while (*p1 && !(*p1 == '\n' && (p1[1] == '\n' || p1[1] == '\0'))) |
2545 | p1++; |
2546 | |
2547 | /* Specs end at the blank line and do not include the newline. */ |
2548 | spec = save_string (p, p1 - p); |
2549 | p = p1; |
2550 | |
2551 | /* Delete backslash-newline sequences from the spec. */ |
2552 | in = spec; |
2553 | out = spec; |
2554 | while (*in != 0) |
2555 | { |
2556 | if (in[0] == '\\' && in[1] == '\n') |
2557 | in += 2; |
2558 | else if (in[0] == '#') |
2559 | while (*in && *in != '\n') |
2560 | in++; |
2561 | |
2562 | else |
2563 | *out++ = *in++; |
2564 | } |
2565 | *out = 0; |
2566 | |
2567 | if (suffix[0] == '*') |
2568 | { |
2569 | if (! strcmp (s1: suffix, s2: "*link_command" )) |
2570 | link_command_spec = spec; |
2571 | else |
2572 | { |
2573 | set_spec (name: suffix + 1, spec, user_p); |
2574 | free (ptr: spec); |
2575 | } |
2576 | } |
2577 | else |
2578 | { |
2579 | /* Add this pair to the vector. */ |
2580 | compilers |
2581 | = XRESIZEVEC (struct compiler, compilers, n_compilers + 2); |
2582 | |
2583 | compilers[n_compilers].suffix = suffix; |
2584 | compilers[n_compilers].spec = spec; |
2585 | n_compilers++; |
2586 | memset (s: &compilers[n_compilers], c: 0, n: sizeof compilers[n_compilers]); |
2587 | } |
2588 | |
2589 | if (*suffix == 0) |
2590 | link_command_spec = spec; |
2591 | } |
2592 | |
2593 | if (link_command_spec == 0) |
2594 | fatal_error (input_location, "spec file has no spec for linking" ); |
2595 | |
2596 | XDELETEVEC (buffer); |
2597 | } |
2598 | |
2599 | /* Record the names of temporary files we tell compilers to write, |
2600 | and delete them at the end of the run. */ |
2601 | |
2602 | /* This is the common prefix we use to make temp file names. |
2603 | It is chosen once for each run of this program. |
2604 | It is substituted into a spec by %g or %j. |
2605 | Thus, all temp file names contain this prefix. |
2606 | In practice, all temp file names start with this prefix. |
2607 | |
2608 | This prefix comes from the envvar TMPDIR if it is defined; |
2609 | otherwise, from the P_tmpdir macro if that is defined; |
2610 | otherwise, in /usr/tmp or /tmp; |
2611 | or finally the current directory if all else fails. */ |
2612 | |
2613 | static const char *temp_filename; |
2614 | |
2615 | /* Length of the prefix. */ |
2616 | |
2617 | static int temp_filename_length; |
2618 | |
2619 | /* Define the list of temporary files to delete. */ |
2620 | |
2621 | struct temp_file |
2622 | { |
2623 | const char *name; |
2624 | struct temp_file *next; |
2625 | }; |
2626 | |
2627 | /* Queue of files to delete on success or failure of compilation. */ |
2628 | static struct temp_file *always_delete_queue; |
2629 | /* Queue of files to delete on failure of compilation. */ |
2630 | static struct temp_file *failure_delete_queue; |
2631 | |
2632 | /* Record FILENAME as a file to be deleted automatically. |
2633 | ALWAYS_DELETE nonzero means delete it if all compilation succeeds; |
2634 | otherwise delete it in any case. |
2635 | FAIL_DELETE nonzero means delete it if a compilation step fails; |
2636 | otherwise delete it in any case. */ |
2637 | |
2638 | void |
2639 | record_temp_file (const char *filename, int always_delete, int fail_delete) |
2640 | { |
2641 | char *const name = xstrdup (filename); |
2642 | |
2643 | if (always_delete) |
2644 | { |
2645 | struct temp_file *temp; |
2646 | for (temp = always_delete_queue; temp; temp = temp->next) |
2647 | if (! filename_cmp (s1: name, s2: temp->name)) |
2648 | { |
2649 | free (ptr: name); |
2650 | goto already1; |
2651 | } |
2652 | |
2653 | temp = XNEW (struct temp_file); |
2654 | temp->next = always_delete_queue; |
2655 | temp->name = name; |
2656 | always_delete_queue = temp; |
2657 | |
2658 | already1:; |
2659 | } |
2660 | |
2661 | if (fail_delete) |
2662 | { |
2663 | struct temp_file *temp; |
2664 | for (temp = failure_delete_queue; temp; temp = temp->next) |
2665 | if (! filename_cmp (s1: name, s2: temp->name)) |
2666 | { |
2667 | free (ptr: name); |
2668 | goto already2; |
2669 | } |
2670 | |
2671 | temp = XNEW (struct temp_file); |
2672 | temp->next = failure_delete_queue; |
2673 | temp->name = name; |
2674 | failure_delete_queue = temp; |
2675 | |
2676 | already2:; |
2677 | } |
2678 | } |
2679 | |
2680 | /* Delete all the temporary files whose names we previously recorded. */ |
2681 | |
2682 | #ifndef DELETE_IF_ORDINARY |
2683 | #define DELETE_IF_ORDINARY(NAME,ST,VERBOSE_FLAG) \ |
2684 | do \ |
2685 | { \ |
2686 | if (stat (NAME, &ST) >= 0 && S_ISREG (ST.st_mode)) \ |
2687 | if (unlink (NAME) < 0) \ |
2688 | if (VERBOSE_FLAG) \ |
2689 | error ("%s: %m", (NAME)); \ |
2690 | } while (0) |
2691 | #endif |
2692 | |
2693 | static void |
2694 | delete_if_ordinary (const char *name) |
2695 | { |
2696 | struct stat st; |
2697 | #ifdef DEBUG |
2698 | int i, c; |
2699 | |
2700 | printf ("Delete %s? (y or n) " , name); |
2701 | fflush (stdout); |
2702 | i = getchar (); |
2703 | if (i != '\n') |
2704 | while ((c = getchar ()) != '\n' && c != EOF) |
2705 | ; |
2706 | |
2707 | if (i == 'y' || i == 'Y') |
2708 | #endif /* DEBUG */ |
2709 | DELETE_IF_ORDINARY (name, st, verbose_flag); |
2710 | } |
2711 | |
2712 | static void |
2713 | delete_temp_files (void) |
2714 | { |
2715 | struct temp_file *temp; |
2716 | |
2717 | for (temp = always_delete_queue; temp; temp = temp->next) |
2718 | delete_if_ordinary (name: temp->name); |
2719 | always_delete_queue = 0; |
2720 | } |
2721 | |
2722 | /* Delete all the files to be deleted on error. */ |
2723 | |
2724 | static void |
2725 | delete_failure_queue (void) |
2726 | { |
2727 | struct temp_file *temp; |
2728 | |
2729 | for (temp = failure_delete_queue; temp; temp = temp->next) |
2730 | delete_if_ordinary (name: temp->name); |
2731 | } |
2732 | |
2733 | static void |
2734 | clear_failure_queue (void) |
2735 | { |
2736 | failure_delete_queue = 0; |
2737 | } |
2738 | |
2739 | /* Call CALLBACK for each path in PATHS, breaking out early if CALLBACK |
2740 | returns non-NULL. |
2741 | If DO_MULTI is true iterate over the paths twice, first with multilib |
2742 | suffix then without, otherwise iterate over the paths once without |
2743 | adding a multilib suffix. When DO_MULTI is true, some attempt is made |
2744 | to avoid visiting the same path twice, but we could do better. For |
2745 | instance, /usr/lib/../lib is considered different from /usr/lib. |
2746 | At least EXTRA_SPACE chars past the end of the path passed to |
2747 | CALLBACK are available for use by the callback. |
2748 | CALLBACK_INFO allows extra parameters to be passed to CALLBACK. |
2749 | |
2750 | Returns the value returned by CALLBACK. */ |
2751 | |
2752 | static void * |
2753 | for_each_path (const struct path_prefix *paths, |
2754 | bool do_multi, |
2755 | size_t , |
2756 | void *(*callback) (char *, void *), |
2757 | void *callback_info) |
2758 | { |
2759 | struct prefix_list *pl; |
2760 | const char *multi_dir = NULL; |
2761 | const char *multi_os_dir = NULL; |
2762 | const char *multiarch_suffix = NULL; |
2763 | const char *multi_suffix; |
2764 | const char *just_multi_suffix; |
2765 | char *path = NULL; |
2766 | void *ret = NULL; |
2767 | bool skip_multi_dir = false; |
2768 | bool skip_multi_os_dir = false; |
2769 | |
2770 | multi_suffix = machine_suffix; |
2771 | just_multi_suffix = just_machine_suffix; |
2772 | if (do_multi && multilib_dir && strcmp (s1: multilib_dir, s2: "." ) != 0) |
2773 | { |
2774 | multi_dir = concat (multilib_dir, dir_separator_str, NULL); |
2775 | multi_suffix = concat (multi_suffix, multi_dir, NULL); |
2776 | just_multi_suffix = concat (just_multi_suffix, multi_dir, NULL); |
2777 | } |
2778 | if (do_multi && multilib_os_dir && strcmp (s1: multilib_os_dir, s2: "." ) != 0) |
2779 | multi_os_dir = concat (multilib_os_dir, dir_separator_str, NULL); |
2780 | if (multiarch_dir) |
2781 | multiarch_suffix = concat (multiarch_dir, dir_separator_str, NULL); |
2782 | |
2783 | while (1) |
2784 | { |
2785 | size_t multi_dir_len = 0; |
2786 | size_t multi_os_dir_len = 0; |
2787 | size_t multiarch_len = 0; |
2788 | size_t suffix_len; |
2789 | size_t just_suffix_len; |
2790 | size_t len; |
2791 | |
2792 | if (multi_dir) |
2793 | multi_dir_len = strlen (s: multi_dir); |
2794 | if (multi_os_dir) |
2795 | multi_os_dir_len = strlen (s: multi_os_dir); |
2796 | if (multiarch_suffix) |
2797 | multiarch_len = strlen (s: multiarch_suffix); |
2798 | suffix_len = strlen (s: multi_suffix); |
2799 | just_suffix_len = strlen (s: just_multi_suffix); |
2800 | |
2801 | if (path == NULL) |
2802 | { |
2803 | len = paths->max_len + extra_space + 1; |
2804 | len += MAX (MAX (suffix_len, multi_os_dir_len), multiarch_len); |
2805 | path = XNEWVEC (char, len); |
2806 | } |
2807 | |
2808 | for (pl = paths->plist; pl != 0; pl = pl->next) |
2809 | { |
2810 | len = strlen (s: pl->prefix); |
2811 | memcpy (dest: path, src: pl->prefix, n: len); |
2812 | |
2813 | /* Look first in MACHINE/VERSION subdirectory. */ |
2814 | if (!skip_multi_dir) |
2815 | { |
2816 | memcpy (dest: path + len, src: multi_suffix, n: suffix_len + 1); |
2817 | ret = callback (path, callback_info); |
2818 | if (ret) |
2819 | break; |
2820 | } |
2821 | |
2822 | /* Some paths are tried with just the machine (ie. target) |
2823 | subdir. This is used for finding as, ld, etc. */ |
2824 | if (!skip_multi_dir |
2825 | && pl->require_machine_suffix == 2) |
2826 | { |
2827 | memcpy (dest: path + len, src: just_multi_suffix, n: just_suffix_len + 1); |
2828 | ret = callback (path, callback_info); |
2829 | if (ret) |
2830 | break; |
2831 | } |
2832 | |
2833 | /* Now try the multiarch path. */ |
2834 | if (!skip_multi_dir |
2835 | && !pl->require_machine_suffix && multiarch_dir) |
2836 | { |
2837 | memcpy (dest: path + len, src: multiarch_suffix, n: multiarch_len + 1); |
2838 | ret = callback (path, callback_info); |
2839 | if (ret) |
2840 | break; |
2841 | } |
2842 | |
2843 | /* Now try the base path. */ |
2844 | if (!pl->require_machine_suffix |
2845 | && !(pl->os_multilib ? skip_multi_os_dir : skip_multi_dir)) |
2846 | { |
2847 | const char *this_multi; |
2848 | size_t this_multi_len; |
2849 | |
2850 | if (pl->os_multilib) |
2851 | { |
2852 | this_multi = multi_os_dir; |
2853 | this_multi_len = multi_os_dir_len; |
2854 | } |
2855 | else |
2856 | { |
2857 | this_multi = multi_dir; |
2858 | this_multi_len = multi_dir_len; |
2859 | } |
2860 | |
2861 | if (this_multi_len) |
2862 | memcpy (dest: path + len, src: this_multi, n: this_multi_len + 1); |
2863 | else |
2864 | path[len] = '\0'; |
2865 | |
2866 | ret = callback (path, callback_info); |
2867 | if (ret) |
2868 | break; |
2869 | } |
2870 | } |
2871 | if (pl) |
2872 | break; |
2873 | |
2874 | if (multi_dir == NULL && multi_os_dir == NULL) |
2875 | break; |
2876 | |
2877 | /* Run through the paths again, this time without multilibs. |
2878 | Don't repeat any we have already seen. */ |
2879 | if (multi_dir) |
2880 | { |
2881 | free (CONST_CAST (char *, multi_dir)); |
2882 | multi_dir = NULL; |
2883 | free (CONST_CAST (char *, multi_suffix)); |
2884 | multi_suffix = machine_suffix; |
2885 | free (CONST_CAST (char *, just_multi_suffix)); |
2886 | just_multi_suffix = just_machine_suffix; |
2887 | } |
2888 | else |
2889 | skip_multi_dir = true; |
2890 | if (multi_os_dir) |
2891 | { |
2892 | free (CONST_CAST (char *, multi_os_dir)); |
2893 | multi_os_dir = NULL; |
2894 | } |
2895 | else |
2896 | skip_multi_os_dir = true; |
2897 | } |
2898 | |
2899 | if (multi_dir) |
2900 | { |
2901 | free (CONST_CAST (char *, multi_dir)); |
2902 | free (CONST_CAST (char *, multi_suffix)); |
2903 | free (CONST_CAST (char *, just_multi_suffix)); |
2904 | } |
2905 | if (multi_os_dir) |
2906 | free (CONST_CAST (char *, multi_os_dir)); |
2907 | if (ret != path) |
2908 | free (ptr: path); |
2909 | return ret; |
2910 | } |
2911 | |
2912 | /* Callback for build_search_list. Adds path to obstack being built. */ |
2913 | |
2914 | struct add_to_obstack_info { |
2915 | struct obstack *ob; |
2916 | bool check_dir; |
2917 | bool first_time; |
2918 | }; |
2919 | |
2920 | static void * |
2921 | add_to_obstack (char *path, void *data) |
2922 | { |
2923 | struct add_to_obstack_info *info = (struct add_to_obstack_info *) data; |
2924 | |
2925 | if (info->check_dir && !is_directory (path, false)) |
2926 | return NULL; |
2927 | |
2928 | if (!info->first_time) |
2929 | obstack_1grow (info->ob, PATH_SEPARATOR); |
2930 | |
2931 | obstack_grow (info->ob, path, strlen (path)); |
2932 | |
2933 | info->first_time = false; |
2934 | return NULL; |
2935 | } |
2936 | |
2937 | /* Add or change the value of an environment variable, outputting the |
2938 | change to standard error if in verbose mode. */ |
2939 | static void |
2940 | xputenv (const char *string) |
2941 | { |
2942 | env.xput (string); |
2943 | } |
2944 | |
2945 | /* Build a list of search directories from PATHS. |
2946 | PREFIX is a string to prepend to the list. |
2947 | If CHECK_DIR_P is true we ensure the directory exists. |
2948 | If DO_MULTI is true, multilib paths are output first, then |
2949 | non-multilib paths. |
2950 | This is used mostly by putenv_from_prefixes so we use `collect_obstack'. |
2951 | It is also used by the --print-search-dirs flag. */ |
2952 | |
2953 | static char * |
2954 | build_search_list (const struct path_prefix *paths, const char *prefix, |
2955 | bool check_dir, bool do_multi) |
2956 | { |
2957 | struct add_to_obstack_info info; |
2958 | |
2959 | info.ob = &collect_obstack; |
2960 | info.check_dir = check_dir; |
2961 | info.first_time = true; |
2962 | |
2963 | obstack_grow (&collect_obstack, prefix, strlen (prefix)); |
2964 | obstack_1grow (&collect_obstack, '='); |
2965 | |
2966 | for_each_path (paths, do_multi, extra_space: 0, callback: add_to_obstack, callback_info: &info); |
2967 | |
2968 | obstack_1grow (&collect_obstack, '\0'); |
2969 | return XOBFINISH (&collect_obstack, char *); |
2970 | } |
2971 | |
2972 | /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables |
2973 | for collect. */ |
2974 | |
2975 | static void |
2976 | putenv_from_prefixes (const struct path_prefix *paths, const char *env_var, |
2977 | bool do_multi) |
2978 | { |
2979 | xputenv (string: build_search_list (paths, prefix: env_var, check_dir: true, do_multi)); |
2980 | } |
2981 | |
2982 | /* Check whether NAME can be accessed in MODE. This is like access, |
2983 | except that it never considers directories to be executable. */ |
2984 | |
2985 | static int |
2986 | access_check (const char *name, int mode) |
2987 | { |
2988 | if (mode == X_OK) |
2989 | { |
2990 | struct stat st; |
2991 | |
2992 | if (stat (path: name, statbuf: &st) < 0 |
2993 | || S_ISDIR (st.st_mode)) |
2994 | return -1; |
2995 | } |
2996 | |
2997 | return access (name: name, type: mode); |
2998 | } |
2999 | |
3000 | /* Callback for find_a_file. Appends the file name to the directory |
3001 | path. If the resulting file exists in the right mode, return the |
3002 | full pathname to the file. */ |
3003 | |
3004 | struct file_at_path_info { |
3005 | const char *name; |
3006 | const char *suffix; |
3007 | int name_len; |
3008 | int suffix_len; |
3009 | int mode; |
3010 | }; |
3011 | |
3012 | static void * |
3013 | file_at_path (char *path, void *data) |
3014 | { |
3015 | struct file_at_path_info *info = (struct file_at_path_info *) data; |
3016 | size_t len = strlen (s: path); |
3017 | |
3018 | memcpy (dest: path + len, src: info->name, n: info->name_len); |
3019 | len += info->name_len; |
3020 | |
3021 | /* Some systems have a suffix for executable files. |
3022 | So try appending that first. */ |
3023 | if (info->suffix_len) |
3024 | { |
3025 | memcpy (dest: path + len, src: info->suffix, n: info->suffix_len + 1); |
3026 | if (access_check (name: path, mode: info->mode) == 0) |
3027 | return path; |
3028 | } |
3029 | |
3030 | path[len] = '\0'; |
3031 | if (access_check (name: path, mode: info->mode) == 0) |
3032 | return path; |
3033 | |
3034 | return NULL; |
3035 | } |
3036 | |
3037 | /* Search for NAME using the prefix list PREFIXES. MODE is passed to |
3038 | access to check permissions. If DO_MULTI is true, search multilib |
3039 | paths then non-multilib paths, otherwise do not search multilib paths. |
3040 | Return 0 if not found, otherwise return its name, allocated with malloc. */ |
3041 | |
3042 | static char * |
3043 | find_a_file (const struct path_prefix *pprefix, const char *name, int mode, |
3044 | bool do_multi) |
3045 | { |
3046 | struct file_at_path_info info; |
3047 | |
3048 | /* Find the filename in question (special case for absolute paths). */ |
3049 | |
3050 | if (IS_ABSOLUTE_PATH (name)) |
3051 | { |
3052 | if (access (name: name, type: mode) == 0) |
3053 | return xstrdup (name); |
3054 | |
3055 | return NULL; |
3056 | } |
3057 | |
3058 | info.name = name; |
3059 | info.suffix = (mode & X_OK) != 0 ? HOST_EXECUTABLE_SUFFIX : "" ; |
3060 | info.name_len = strlen (s: info.name); |
3061 | info.suffix_len = strlen (s: info.suffix); |
3062 | info.mode = mode; |
3063 | |
3064 | return (char*) for_each_path (paths: pprefix, do_multi, |
3065 | extra_space: info.name_len + info.suffix_len, |
3066 | callback: file_at_path, callback_info: &info); |
3067 | } |
3068 | |
3069 | /* Specialization of find_a_file for programs that also takes into account |
3070 | configure-specified default programs. */ |
3071 | |
3072 | static char* |
3073 | find_a_program (const char *name) |
3074 | { |
3075 | /* Do not search if default matches query. */ |
3076 | |
3077 | #ifdef DEFAULT_ASSEMBLER |
3078 | if (! strcmp (name, "as" ) && access (DEFAULT_ASSEMBLER, X_OK) == 0) |
3079 | return xstrdup (DEFAULT_ASSEMBLER); |
3080 | #endif |
3081 | |
3082 | #ifdef DEFAULT_LINKER |
3083 | if (! strcmp (name, "ld" ) && access (DEFAULT_LINKER, X_OK) == 0) |
3084 | return xstrdup (DEFAULT_LINKER); |
3085 | #endif |
3086 | |
3087 | #ifdef DEFAULT_DSYMUTIL |
3088 | if (! strcmp (name, "dsymutil" ) && access (DEFAULT_DSYMUTIL, X_OK) == 0) |
3089 | return xstrdup (DEFAULT_DSYMUTIL); |
3090 | #endif |
3091 | |
3092 | return find_a_file (pprefix: &exec_prefixes, name, X_OK, do_multi: false); |
3093 | } |
3094 | |
3095 | /* Ranking of prefixes in the sort list. -B prefixes are put before |
3096 | all others. */ |
3097 | |
3098 | enum path_prefix_priority |
3099 | { |
3100 | PREFIX_PRIORITY_B_OPT, |
3101 | PREFIX_PRIORITY_LAST |
3102 | }; |
3103 | |
3104 | /* Add an entry for PREFIX in PLIST. The PLIST is kept in ascending |
3105 | order according to PRIORITY. Within each PRIORITY, new entries are |
3106 | appended. |
3107 | |
3108 | If WARN is nonzero, we will warn if no file is found |
3109 | through this prefix. WARN should point to an int |
3110 | which will be set to 1 if this entry is used. |
3111 | |
3112 | COMPONENT is the value to be passed to update_path. |
3113 | |
3114 | REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without |
3115 | the complete value of machine_suffix. |
3116 | 2 means try both machine_suffix and just_machine_suffix. */ |
3117 | |
3118 | static void |
3119 | add_prefix (struct path_prefix *pprefix, const char *prefix, |
3120 | const char *component, /* enum prefix_priority */ int priority, |
3121 | int require_machine_suffix, int os_multilib) |
3122 | { |
3123 | struct prefix_list *pl, **prev; |
3124 | int len; |
3125 | |
3126 | for (prev = &pprefix->plist; |
3127 | (*prev) != NULL && (*prev)->priority <= priority; |
3128 | prev = &(*prev)->next) |
3129 | ; |
3130 | |
3131 | /* Keep track of the longest prefix. */ |
3132 | |
3133 | prefix = update_path (path: prefix, key: component); |
3134 | len = strlen (s: prefix); |
3135 | if (len > pprefix->max_len) |
3136 | pprefix->max_len = len; |
3137 | |
3138 | pl = XNEW (struct prefix_list); |
3139 | pl->prefix = prefix; |
3140 | pl->require_machine_suffix = require_machine_suffix; |
3141 | pl->priority = priority; |
3142 | pl->os_multilib = os_multilib; |
3143 | |
3144 | /* Insert after PREV. */ |
3145 | pl->next = (*prev); |
3146 | (*prev) = pl; |
3147 | } |
3148 | |
3149 | /* Same as add_prefix, but prepending target_system_root to prefix. */ |
3150 | /* The target_system_root prefix has been relocated by gcc_exec_prefix. */ |
3151 | static void |
3152 | add_sysrooted_prefix (struct path_prefix *pprefix, const char *prefix, |
3153 | const char *component, |
3154 | /* enum prefix_priority */ int priority, |
3155 | int require_machine_suffix, int os_multilib) |
3156 | { |
3157 | if (!IS_ABSOLUTE_PATH (prefix)) |
3158 | fatal_error (input_location, "system path %qs is not absolute" , prefix); |
3159 | |
3160 | if (target_system_root) |
3161 | { |
3162 | char *sysroot_no_trailing_dir_separator = xstrdup (target_system_root); |
3163 | size_t sysroot_len = strlen (s: target_system_root); |
3164 | |
3165 | if (sysroot_len > 0 |
3166 | && target_system_root[sysroot_len - 1] == DIR_SEPARATOR) |
3167 | sysroot_no_trailing_dir_separator[sysroot_len - 1] = '\0'; |
3168 | |
3169 | if (target_sysroot_suffix) |
3170 | prefix = concat (sysroot_no_trailing_dir_separator, |
3171 | target_sysroot_suffix, prefix, NULL); |
3172 | else |
3173 | prefix = concat (sysroot_no_trailing_dir_separator, prefix, NULL); |
3174 | |
3175 | free (ptr: sysroot_no_trailing_dir_separator); |
3176 | |
3177 | /* We have to override this because GCC's notion of sysroot |
3178 | moves along with GCC. */ |
3179 | component = "GCC" ; |
3180 | } |
3181 | |
3182 | add_prefix (pprefix, prefix, component, priority, |
3183 | require_machine_suffix, os_multilib); |
3184 | } |
3185 | |
3186 | /* Same as add_prefix, but prepending target_sysroot_hdrs_suffix to prefix. */ |
3187 | |
3188 | static void |
3189 | add_sysrooted_hdrs_prefix (struct path_prefix *pprefix, const char *prefix, |
3190 | const char *component, |
3191 | /* enum prefix_priority */ int priority, |
3192 | int require_machine_suffix, int os_multilib) |
3193 | { |
3194 | if (!IS_ABSOLUTE_PATH (prefix)) |
3195 | fatal_error (input_location, "system path %qs is not absolute" , prefix); |
3196 | |
3197 | if (target_system_root) |
3198 | { |
3199 | char *sysroot_no_trailing_dir_separator = xstrdup (target_system_root); |
3200 | size_t sysroot_len = strlen (s: target_system_root); |
3201 | |
3202 | if (sysroot_len > 0 |
3203 | && target_system_root[sysroot_len - 1] == DIR_SEPARATOR) |
3204 | sysroot_no_trailing_dir_separator[sysroot_len - 1] = '\0'; |
3205 | |
3206 | if (target_sysroot_hdrs_suffix) |
3207 | prefix = concat (sysroot_no_trailing_dir_separator, |
3208 | target_sysroot_hdrs_suffix, prefix, NULL); |
3209 | else |
3210 | prefix = concat (sysroot_no_trailing_dir_separator, prefix, NULL); |
3211 | |
3212 | free (ptr: sysroot_no_trailing_dir_separator); |
3213 | |
3214 | /* We have to override this because GCC's notion of sysroot |
3215 | moves along with GCC. */ |
3216 | component = "GCC" ; |
3217 | } |
3218 | |
3219 | add_prefix (pprefix, prefix, component, priority, |
3220 | require_machine_suffix, os_multilib); |
3221 | } |
3222 | |
3223 | |
3224 | /* Execute the command specified by the arguments on the current line of spec. |
3225 | When using pipes, this includes several piped-together commands |
3226 | with `|' between them. |
3227 | |
3228 | Return 0 if successful, -1 if failed. */ |
3229 | |
3230 | static int |
3231 | execute (void) |
3232 | { |
3233 | int i; |
3234 | int n_commands; /* # of command. */ |
3235 | char *string; |
3236 | struct pex_obj *pex; |
3237 | struct command |
3238 | { |
3239 | const char *prog; /* program name. */ |
3240 | const char **argv; /* vector of args. */ |
3241 | }; |
3242 | const char *arg; |
3243 | |
3244 | struct command *commands; /* each command buffer with above info. */ |
3245 | |
3246 | gcc_assert (!processing_spec_function); |
3247 | |
3248 | if (wrapper_string) |
3249 | { |
3250 | string = find_a_program (name: argbuf[0]); |
3251 | if (string) |
3252 | argbuf[0] = string; |
3253 | insert_wrapper (wrapper_string); |
3254 | } |
3255 | |
3256 | /* Count # of piped commands. */ |
3257 | for (n_commands = 1, i = 0; argbuf.iterate (ix: i, p: &arg); i++) |
3258 | if (strcmp (s1: arg, s2: "|" ) == 0) |
3259 | n_commands++; |
3260 | |
3261 | /* Get storage for each command. */ |
3262 | commands = XALLOCAVEC (struct command, n_commands); |
3263 | |
3264 | /* Split argbuf into its separate piped processes, |
3265 | and record info about each one. |
3266 | Also search for the programs that are to be run. */ |
3267 | |
3268 | argbuf.safe_push (0); |
3269 | |
3270 | commands[0].prog = argbuf[0]; /* first command. */ |
3271 | commands[0].argv = argbuf.address (); |
3272 | |
3273 | if (!wrapper_string) |
3274 | { |
3275 | string = find_a_program(name: commands[0].prog); |
3276 | if (string) |
3277 | commands[0].argv[0] = string; |
3278 | } |
3279 | |
3280 | for (n_commands = 1, i = 0; argbuf.iterate (ix: i, p: &arg); i++) |
3281 | if (arg && strcmp (s1: arg, s2: "|" ) == 0) |
3282 | { /* each command. */ |
3283 | #if defined (__MSDOS__) || defined (OS2) || defined (VMS) |
3284 | fatal_error (input_location, "%<-pipe%> not supported" ); |
3285 | #endif |
3286 | argbuf[i] = 0; /* Termination of command args. */ |
3287 | commands[n_commands].prog = argbuf[i + 1]; |
3288 | commands[n_commands].argv |
3289 | = &(argbuf.address ())[i + 1]; |
3290 | string = find_a_program(name: commands[n_commands].prog); |
3291 | if (string) |
3292 | commands[n_commands].argv[0] = string; |
3293 | n_commands++; |
3294 | } |
3295 | |
3296 | /* If -v, print what we are about to do, and maybe query. */ |
3297 | |
3298 | if (verbose_flag) |
3299 | { |
3300 | /* For help listings, put a blank line between sub-processes. */ |
3301 | if (print_help_list) |
3302 | fputc (c: '\n', stderr); |
3303 | |
3304 | /* Print each piped command as a separate line. */ |
3305 | for (i = 0; i < n_commands; i++) |
3306 | { |
3307 | const char *const *j; |
3308 | |
3309 | if (verbose_only_flag) |
3310 | { |
3311 | for (j = commands[i].argv; *j; j++) |
3312 | { |
3313 | const char *p; |
3314 | for (p = *j; *p; ++p) |
3315 | if (!ISALNUM ((unsigned char) *p) |
3316 | && *p != '_' && *p != '/' && *p != '-' && *p != '.') |
3317 | break; |
3318 | if (*p || !*j) |
3319 | { |
3320 | fprintf (stderr, format: " \"" ); |
3321 | for (p = *j; *p; ++p) |
3322 | { |
3323 | if (*p == '"' || *p == '\\' || *p == '$') |
3324 | fputc (c: '\\', stderr); |
3325 | fputc (c: *p, stderr); |
3326 | } |
3327 | fputc (c: '"', stderr); |
3328 | } |
3329 | /* If it's empty, print "". */ |
3330 | else if (!**j) |
3331 | fprintf (stderr, format: " \"\"" ); |
3332 | else |
3333 | fprintf (stderr, format: " %s" , *j); |
3334 | } |
3335 | } |
3336 | else |
3337 | for (j = commands[i].argv; *j; j++) |
3338 | /* If it's empty, print "". */ |
3339 | if (!**j) |
3340 | fprintf (stderr, format: " \"\"" ); |
3341 | else |
3342 | fprintf (stderr, format: " %s" , *j); |
3343 | |
3344 | /* Print a pipe symbol after all but the last command. */ |
3345 | if (i + 1 != n_commands) |
3346 | fprintf (stderr, format: " |" ); |
3347 | fprintf (stderr, format: "\n" ); |
3348 | } |
3349 | fflush (stderr); |
3350 | if (verbose_only_flag != 0) |
3351 | { |
3352 | /* verbose_only_flag should act as if the spec was |
3353 | executed, so increment execution_count before |
3354 | returning. This prevents spurious warnings about |
3355 | unused linker input files, etc. */ |
3356 | execution_count++; |
3357 | return 0; |
3358 | } |
3359 | #ifdef DEBUG |
3360 | fnotice (stderr, "\nGo ahead? (y or n) " ); |
3361 | fflush (stderr); |
3362 | i = getchar (); |
3363 | if (i != '\n') |
3364 | while (getchar () != '\n') |
3365 | ; |
3366 | |
3367 | if (i != 'y' && i != 'Y') |
3368 | return 0; |
3369 | #endif /* DEBUG */ |
3370 | } |
3371 | |
3372 | #ifdef ENABLE_VALGRIND_CHECKING |
3373 | /* Run the each command through valgrind. To simplify prepending the |
3374 | path to valgrind and the option "-q" (for quiet operation unless |
3375 | something triggers), we allocate a separate argv array. */ |
3376 | |
3377 | for (i = 0; i < n_commands; i++) |
3378 | { |
3379 | const char **argv; |
3380 | int argc; |
3381 | int j; |
3382 | |
3383 | for (argc = 0; commands[i].argv[argc] != NULL; argc++) |
3384 | ; |
3385 | |
3386 | argv = XALLOCAVEC (const char *, argc + 3); |
3387 | |
3388 | argv[0] = VALGRIND_PATH; |
3389 | argv[1] = "-q" ; |
3390 | for (j = 2; j < argc + 2; j++) |
3391 | argv[j] = commands[i].argv[j - 2]; |
3392 | argv[j] = NULL; |
3393 | |
3394 | commands[i].argv = argv; |
3395 | commands[i].prog = argv[0]; |
3396 | } |
3397 | #endif |
3398 | |
3399 | /* Run each piped subprocess. */ |
3400 | |
3401 | pex = pex_init (PEX_USE_PIPES | ((report_times || report_times_to_file) |
3402 | ? PEX_RECORD_TIMES : 0), |
3403 | pname: progname, tempbase: temp_filename); |
3404 | if (pex == NULL) |
3405 | fatal_error (input_location, "%<pex_init%> failed: %m" ); |
3406 | |
3407 | for (i = 0; i < n_commands; i++) |
3408 | { |
3409 | const char *errmsg; |
3410 | int err; |
3411 | const char *string = commands[i].argv[0]; |
3412 | |
3413 | errmsg = pex_run (obj: pex, |
3414 | flags: ((i + 1 == n_commands ? PEX_LAST : 0) |
3415 | | (string == commands[i].prog ? PEX_SEARCH : 0)), |
3416 | executable: string, CONST_CAST (char **, commands[i].argv), |
3417 | NULL, NULL, err: &err); |
3418 | if (errmsg != NULL) |
3419 | { |
3420 | errno = err; |
3421 | fatal_error (input_location, |
3422 | err ? G_("cannot execute %qs: %s: %m" ) |
3423 | : G_("cannot execute %qs: %s" ), |
3424 | string, errmsg); |
3425 | } |
3426 | |
3427 | if (i && string != commands[i].prog) |
3428 | free (CONST_CAST (char *, string)); |
3429 | } |
3430 | |
3431 | execution_count++; |
3432 | |
3433 | /* Wait for all the subprocesses to finish. */ |
3434 | |
3435 | { |
3436 | int *statuses; |
3437 | struct pex_time *times = NULL; |
3438 | int ret_code = 0; |
3439 | |
3440 | statuses = XALLOCAVEC (int, n_commands); |
3441 | if (!pex_get_status (pex, count: n_commands, vector: statuses)) |
3442 | fatal_error (input_location, "failed to get exit status: %m" ); |
3443 | |
3444 | if (report_times || report_times_to_file) |
3445 | { |
3446 | times = XALLOCAVEC (struct pex_time, n_commands); |
3447 | if (!pex_get_times (pex, count: n_commands, vector: times)) |
3448 | fatal_error (input_location, "failed to get process times: %m" ); |
3449 | } |
3450 | |
3451 | pex_free (pex); |
3452 | |
3453 | for (i = 0; i < n_commands; ++i) |
3454 | { |
3455 | int status = statuses[i]; |
3456 | |
3457 | if (WIFSIGNALED (status)) |
3458 | switch (WTERMSIG (status)) |
3459 | { |
3460 | case SIGINT: |
3461 | case SIGTERM: |
3462 | /* SIGQUIT and SIGKILL are not available on MinGW. */ |
3463 | #ifdef SIGQUIT |
3464 | case SIGQUIT: |
3465 | #endif |
3466 | #ifdef SIGKILL |
3467 | case SIGKILL: |
3468 | #endif |
3469 | /* The user (or environment) did something to the |
3470 | inferior. Making this an ICE confuses the user into |
3471 | thinking there's a compiler bug. Much more likely is |
3472 | the user or OOM killer nuked it. */ |
3473 | fatal_error (input_location, |
3474 | "%s signal terminated program %s" , |
3475 | strsignal (WTERMSIG (status)), |
3476 | commands[i].prog); |
3477 | break; |
3478 | |
3479 | #ifdef SIGPIPE |
3480 | case SIGPIPE: |
3481 | /* SIGPIPE is a special case. It happens in -pipe mode |
3482 | when the compiler dies before the preprocessor is |
3483 | done, or the assembler dies before the compiler is |
3484 | done. There's generally been an error already, and |
3485 | this is just fallout. So don't generate another |
3486 | error unless we would otherwise have succeeded. */ |
3487 | if (signal_count || greatest_status >= MIN_FATAL_STATUS) |
3488 | { |
3489 | signal_count++; |
3490 | ret_code = -1; |
3491 | break; |
3492 | } |
3493 | #endif |
3494 | /* FALLTHROUGH */ |
3495 | |
3496 | default: |
3497 | /* The inferior failed to catch the signal. */ |
3498 | internal_error_no_backtrace ("%s signal terminated program %s" , |
3499 | strsignal (WTERMSIG (status)), |
3500 | commands[i].prog); |
3501 | } |
3502 | else if (WIFEXITED (status) |
3503 | && WEXITSTATUS (status) >= MIN_FATAL_STATUS) |
3504 | { |
3505 | /* For ICEs in cc1, cc1obj, cc1plus see if it is |
3506 | reproducible or not. */ |
3507 | const char *p; |
3508 | if (flag_report_bug |
3509 | && WEXITSTATUS (status) == ICE_EXIT_CODE |
3510 | && i == 0 |
3511 | && (p = strrchr (s: commands[0].argv[0], DIR_SEPARATOR)) |
3512 | && startswith (str: p + 1, prefix: "cc1" )) |
3513 | try_generate_repro (argv: commands[0].argv); |
3514 | if (WEXITSTATUS (status) > greatest_status) |
3515 | greatest_status = WEXITSTATUS (status); |
3516 | ret_code = -1; |
3517 | } |
3518 | |
3519 | if (report_times || report_times_to_file) |
3520 | { |
3521 | struct pex_time *pt = ×[i]; |
3522 | double ut, st; |
3523 | |
3524 | ut = ((double) pt->user_seconds |
3525 | + (double) pt->user_microseconds / 1.0e6); |
3526 | st = ((double) pt->system_seconds |
3527 | + (double) pt->system_microseconds / 1.0e6); |
3528 | |
3529 | if (ut + st != 0) |
3530 | { |
3531 | if (report_times) |
3532 | fnotice (stderr, "# %s %.2f %.2f\n" , |
3533 | commands[i].prog, ut, st); |
3534 | |
3535 | if (report_times_to_file) |
3536 | { |
3537 | int c = 0; |
3538 | const char *const *j; |
3539 | |
3540 | fprintf (stream: report_times_to_file, format: "%g %g" , ut, st); |
3541 | |
3542 | for (j = &commands[i].prog; *j; j = &commands[i].argv[++c]) |
3543 | { |
3544 | const char *p; |
3545 | for (p = *j; *p; ++p) |
3546 | if (*p == '"' || *p == '\\' || *p == '$' |
3547 | || ISSPACE (*p)) |
3548 | break; |
3549 | |
3550 | if (*p) |
3551 | { |
3552 | fprintf (stream: report_times_to_file, format: " \"" ); |
3553 | for (p = *j; *p; ++p) |
3554 | { |
3555 | if (*p == '"' || *p == '\\' || *p == '$') |
3556 | fputc (c: '\\', stream: report_times_to_file); |
3557 | fputc (c: *p, stream: report_times_to_file); |
3558 | } |
3559 | fputc (c: '"', stream: report_times_to_file); |
3560 | } |
3561 | else |
3562 | fprintf (stream: report_times_to_file, format: " %s" , *j); |
3563 | } |
3564 | |
3565 | fputc (c: '\n', stream: report_times_to_file); |
3566 | } |
3567 | } |
3568 | } |
3569 | } |
3570 | |
3571 | if (commands[0].argv[0] != commands[0].prog) |
3572 | free (CONST_CAST (char *, commands[0].argv[0])); |
3573 | |
3574 | return ret_code; |
3575 | } |
3576 | } |
3577 | |
3578 | static struct switchstr *switches; |
3579 | |
3580 | static int n_switches; |
3581 | |
3582 | static int n_switches_alloc; |
3583 | |
3584 | /* Set to zero if -fcompare-debug is disabled, positive if it's |
3585 | enabled and we're running the first compilation, negative if it's |
3586 | enabled and we're running the second compilation. For most of the |
3587 | time, it's in the range -1..1, but it can be temporarily set to 2 |
3588 | or 3 to indicate that the -fcompare-debug flags didn't come from |
3589 | the command-line, but rather from the GCC_COMPARE_DEBUG environment |
3590 | variable, until a synthesized -fcompare-debug flag is added to the |
3591 | command line. */ |
3592 | int compare_debug; |
3593 | |
3594 | /* Set to nonzero if we've seen the -fcompare-debug-second flag. */ |
3595 | int compare_debug_second; |
3596 | |
3597 | /* Set to the flags that should be passed to the second compilation in |
3598 | a -fcompare-debug compilation. */ |
3599 | const char *compare_debug_opt; |
3600 | |
3601 | static struct switchstr *switches_debug_check[2]; |
3602 | |
3603 | static int n_switches_debug_check[2]; |
3604 | |
3605 | static int n_switches_alloc_debug_check[2]; |
3606 | |
3607 | static char *debug_check_temp_file[2]; |
3608 | |
3609 | /* Language is one of three things: |
3610 | |
3611 | 1) The name of a real programming language. |
3612 | 2) NULL, indicating that no one has figured out |
3613 | what it is yet. |
3614 | 3) '*', indicating that the file should be passed |
3615 | to the linker. */ |
3616 | struct infile |
3617 | { |
3618 | const char *name; |
3619 | const char *language; |
3620 | struct compiler *incompiler; |
3621 | bool compiled; |
3622 | bool preprocessed; |
3623 | }; |
3624 | |
3625 | /* Also a vector of input files specified. */ |
3626 | |
3627 | static struct infile *infiles; |
3628 | |
3629 | int n_infiles; |
3630 | |
3631 | static int n_infiles_alloc; |
3632 | |
3633 | /* True if undefined environment variables encountered during spec processing |
3634 | are ok to ignore, typically when we're running for --help or --version. */ |
3635 | |
3636 | static bool spec_undefvar_allowed; |
3637 | |
3638 | /* True if multiple input files are being compiled to a single |
3639 | assembly file. */ |
3640 | |
3641 | static bool combine_inputs; |
3642 | |
3643 | /* This counts the number of libraries added by lang_specific_driver, so that |
3644 | we can tell if there were any user supplied any files or libraries. */ |
3645 | |
3646 | static int added_libraries; |
3647 | |
3648 | /* And a vector of corresponding output files is made up later. */ |
3649 | |
3650 | const char **outfiles; |
3651 | |
3652 | #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX) |
3653 | |
3654 | /* Convert NAME to a new name if it is the standard suffix. DO_EXE |
3655 | is true if we should look for an executable suffix. DO_OBJ |
3656 | is true if we should look for an object suffix. */ |
3657 | |
3658 | static const char * |
3659 | convert_filename (const char *name, int do_exe ATTRIBUTE_UNUSED, |
3660 | int do_obj ATTRIBUTE_UNUSED) |
3661 | { |
3662 | #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) |
3663 | int i; |
3664 | #endif |
3665 | int len; |
3666 | |
3667 | if (name == NULL) |
3668 | return NULL; |
3669 | |
3670 | len = strlen (name); |
3671 | |
3672 | #ifdef HAVE_TARGET_OBJECT_SUFFIX |
3673 | /* Convert x.o to x.obj if TARGET_OBJECT_SUFFIX is ".obj". */ |
3674 | if (do_obj && len > 2 |
3675 | && name[len - 2] == '.' |
3676 | && name[len - 1] == 'o') |
3677 | { |
3678 | obstack_grow (&obstack, name, len - 2); |
3679 | obstack_grow0 (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX)); |
3680 | name = XOBFINISH (&obstack, const char *); |
3681 | } |
3682 | #endif |
3683 | |
3684 | #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) |
3685 | /* If there is no filetype, make it the executable suffix (which includes |
3686 | the "."). But don't get confused if we have just "-o". */ |
3687 | if (! do_exe || TARGET_EXECUTABLE_SUFFIX[0] == 0 || not_actual_file_p (name)) |
3688 | return name; |
3689 | |
3690 | for (i = len - 1; i >= 0; i--) |
3691 | if (IS_DIR_SEPARATOR (name[i])) |
3692 | break; |
3693 | |
3694 | for (i++; i < len; i++) |
3695 | if (name[i] == '.') |
3696 | return name; |
3697 | |
3698 | obstack_grow (&obstack, name, len); |
3699 | obstack_grow0 (&obstack, TARGET_EXECUTABLE_SUFFIX, |
3700 | strlen (TARGET_EXECUTABLE_SUFFIX)); |
3701 | name = XOBFINISH (&obstack, const char *); |
3702 | #endif |
3703 | |
3704 | return name; |
3705 | } |
3706 | #endif |
3707 | |
3708 | /* Display the command line switches accepted by gcc. */ |
3709 | static void |
3710 | display_help (void) |
3711 | { |
3712 | printf (_("Usage: %s [options] file...\n" ), progname); |
3713 | fputs (_("Options:\n" ), stdout); |
3714 | |
3715 | fputs (_(" -pass-exit-codes Exit with highest error code from a phase.\n" ), stdout); |
3716 | fputs (_(" --help Display this information.\n" ), stdout); |
3717 | fputs (_(" --target-help Display target specific command line options " |
3718 | "(including assembler and linker options).\n" ), stdout); |
3719 | fputs (_(" --help={common|optimizers|params|target|warnings|[^]{joined|separate|undocumented}}[,...].\n" ), stdout); |
3720 | fputs (_(" Display specific types of command line options.\n" ), stdout); |
3721 | if (! verbose_flag) |
3722 | fputs (_(" (Use '-v --help' to display command line options of sub-processes).\n" ), stdout); |
3723 | fputs (_(" --version Display compiler version information.\n" ), stdout); |
3724 | fputs (_(" -dumpspecs Display all of the built in spec strings.\n" ), stdout); |
3725 | fputs (_(" -dumpversion Display the version of the compiler.\n" ), stdout); |
3726 | fputs (_(" -dumpmachine Display the compiler's target processor.\n" ), stdout); |
3727 | fputs (_(" -foffload=<targets> Specify offloading targets.\n" ), stdout); |
3728 | fputs (_(" -print-search-dirs Display the directories in the compiler's search path.\n" ), stdout); |
3729 | fputs (_(" -print-libgcc-file-name Display the name of the compiler's companion library.\n" ), stdout); |
3730 | fputs (_(" -print-file-name=<lib> Display the full path to library <lib>.\n" ), stdout); |
3731 | fputs (_(" -print-prog-name=<prog> Display the full path to compiler component <prog>.\n" ), stdout); |
3732 | fputs (_("\ |
3733 | -print-multiarch Display the target's normalized GNU triplet, used as\n\ |
3734 | a component in the library path.\n" ), stdout); |
3735 | fputs (_(" -print-multi-directory Display the root directory for versions of libgcc.\n" ), stdout); |
3736 | fputs (_("\ |
3737 | -print-multi-lib Display the mapping between command line options and\n\ |
3738 | multiple library search directories.\n" ), stdout); |
3739 | fputs (_(" -print-multi-os-directory Display the relative path to OS libraries.\n" ), stdout); |
3740 | fputs (_(" -print-sysroot Display the target libraries directory.\n" ), stdout); |
3741 | fputs (_(" -print-sysroot-headers-suffix Display the sysroot suffix used to find headers.\n" ), stdout); |
3742 | fputs (_(" -Wa,<options> Pass comma-separated <options> on to the assembler.\n" ), stdout); |
3743 | fputs (_(" -Wp,<options> Pass comma-separated <options> on to the preprocessor.\n" ), stdout); |
3744 | fputs (_(" -Wl,<options> Pass comma-separated <options> on to the linker.\n" ), stdout); |
3745 | fputs (_(" -Xassembler <arg> Pass <arg> on to the assembler.\n" ), stdout); |
3746 | fputs (_(" -Xpreprocessor <arg> Pass <arg> on to the preprocessor.\n" ), stdout); |
3747 | fputs (_(" -Xlinker <arg> Pass <arg> on to the linker.\n" ), stdout); |
3748 | fputs (_(" -save-temps Do not delete intermediate files.\n" ), stdout); |
3749 | fputs (_(" -save-temps=<arg> Do not delete intermediate files.\n" ), stdout); |
3750 | fputs (_("\ |
3751 | -no-canonical-prefixes Do not canonicalize paths when building relative\n\ |
3752 | prefixes to other gcc components.\n" ), stdout); |
3753 | fputs (_(" -pipe Use pipes rather than intermediate files.\n" ), stdout); |
3754 | fputs (_(" -time Time the execution of each subprocess.\n" ), stdout); |
3755 | fputs (_(" -specs=<file> Override built-in specs with the contents of <file>.\n" ), stdout); |
3756 | fputs (_(" -std=<standard> Assume that the input sources are for <standard>.\n" ), stdout); |
3757 | fputs (_("\ |
3758 | --sysroot=<directory> Use <directory> as the root directory for headers\n\ |
3759 | and libraries.\n" ), stdout); |
3760 | fputs (_(" -B <directory> Add <directory> to the compiler's search paths.\n" ), stdout); |
3761 | fputs (_(" -v Display the programs invoked by the compiler.\n" ), stdout); |
3762 | fputs (_(" -### Like -v but options quoted and commands not executed.\n" ), stdout); |
3763 | fputs (_(" -E Preprocess only; do not compile, assemble or link.\n" ), stdout); |
3764 | fputs (_(" -S Compile only; do not assemble or link.\n" ), stdout); |
3765 | fputs (_(" -c Compile and assemble, but do not link.\n" ), stdout); |
3766 | fputs (_(" -o <file> Place the output into <file>.\n" ), stdout); |
3767 | fputs (_(" -pie Create a dynamically linked position independent\n\ |
3768 | executable.\n" ), stdout); |
3769 | fputs (_(" -shared Create a shared library.\n" ), stdout); |
3770 | fputs (_("\ |
3771 | -x <language> Specify the language of the following input files.\n\ |
3772 | Permissible languages include: c c++ assembler none\n\ |
3773 | 'none' means revert to the default behavior of\n\ |
3774 | guessing the language based on the file's extension.\n\ |
3775 | " ), stdout); |
3776 | |
3777 | printf (_("\ |
3778 | \nOptions starting with -g, -f, -m, -O, -W, or --param are automatically\n\ |
3779 | passed on to the various sub-processes invoked by %s. In order to pass\n\ |
3780 | other options on to these processes the -W<letter> options must be used.\n\ |
3781 | " ), progname); |
3782 | |
3783 | /* The rest of the options are displayed by invocations of the various |
3784 | sub-processes. */ |
3785 | } |
3786 | |
3787 | static void |
3788 | add_preprocessor_option (const char *option, int len) |
3789 | { |
3790 | preprocessor_options.safe_push (save_string (option, len)); |
3791 | } |
3792 | |
3793 | static void |
3794 | add_assembler_option (const char *option, int len) |
3795 | { |
3796 | assembler_options.safe_push (save_string (option, len)); |
3797 | } |
3798 | |
3799 | static void |
3800 | add_linker_option (const char *option, int len) |
3801 | { |
3802 | linker_options.safe_push (save_string (option, len)); |
3803 | } |
3804 | |
3805 | /* Allocate space for an input file in infiles. */ |
3806 | |
3807 | static void |
3808 | alloc_infile (void) |
3809 | { |
3810 | if (n_infiles_alloc == 0) |
3811 | { |
3812 | n_infiles_alloc = 16; |
3813 | infiles = XNEWVEC (struct infile, n_infiles_alloc); |
3814 | } |
3815 | else if (n_infiles_alloc == n_infiles) |
3816 | { |
3817 | n_infiles_alloc *= 2; |
3818 | infiles = XRESIZEVEC (struct infile, infiles, n_infiles_alloc); |
3819 | } |
3820 | } |
3821 | |
3822 | /* Store an input file with the given NAME and LANGUAGE in |
3823 | infiles. */ |
3824 | |
3825 | static void |
3826 | add_infile (const char *name, const char *language) |
3827 | { |
3828 | alloc_infile (); |
3829 | infiles[n_infiles].name = name; |
3830 | infiles[n_infiles++].language = language; |
3831 | } |
3832 | |
3833 | /* Allocate space for a switch in switches. */ |
3834 | |
3835 | static void |
3836 | alloc_switch (void) |
3837 | { |
3838 | if (n_switches_alloc == 0) |
3839 | { |
3840 | n_switches_alloc = 16; |
3841 | switches = XNEWVEC (struct switchstr, n_switches_alloc); |
3842 | } |
3843 | else if (n_switches_alloc == n_switches) |
3844 | { |
3845 | n_switches_alloc *= 2; |
3846 | switches = XRESIZEVEC (struct switchstr, switches, n_switches_alloc); |
3847 | } |
3848 | } |
3849 | |
3850 | /* Save an option OPT with N_ARGS arguments in array ARGS, marking it |
3851 | as validated if VALIDATED and KNOWN if it is an internal switch. */ |
3852 | |
3853 | static void |
3854 | save_switch (const char *opt, size_t n_args, const char *const *args, |
3855 | bool validated, bool known) |
3856 | { |
3857 | alloc_switch (); |
3858 | switches[n_switches].part1 = opt + 1; |
3859 | if (n_args == 0) |
3860 | switches[n_switches].args = 0; |
3861 | else |
3862 | { |
3863 | switches[n_switches].args = XNEWVEC (const char *, n_args + 1); |
3864 | memcpy (dest: switches[n_switches].args, src: args, n: n_args * sizeof (const char *)); |
3865 | switches[n_switches].args[n_args] = NULL; |
3866 | } |
3867 | |
3868 | switches[n_switches].live_cond = 0; |
3869 | switches[n_switches].validated = validated; |
3870 | switches[n_switches].known = known; |
3871 | switches[n_switches].ordering = 0; |
3872 | n_switches++; |
3873 | } |
3874 | |
3875 | /* Set the SOURCE_DATE_EPOCH environment variable to the current time if it is |
3876 | not set already. */ |
3877 | |
3878 | static void |
3879 | set_source_date_epoch_envvar () |
3880 | { |
3881 | /* Array size is 21 = ceil(log_10(2^64)) + 1 to hold string representations |
3882 | of 64 bit integers. */ |
3883 | char source_date_epoch[21]; |
3884 | time_t tt; |
3885 | |
3886 | errno = 0; |
3887 | tt = time (NULL); |
3888 | if (tt < (time_t) 0 || errno != 0) |
3889 | tt = (time_t) 0; |
3890 | |
3891 | snprintf (s: source_date_epoch, maxlen: 21, format: "%llu" , (unsigned long long) tt); |
3892 | /* Using setenv instead of xputenv because we want the variable to remain |
3893 | after finalizing so that it's still set in the second run when using |
3894 | -fcompare-debug. */ |
3895 | setenv (name: "SOURCE_DATE_EPOCH" , value: source_date_epoch, replace: 0); |
3896 | } |
3897 | |
3898 | /* Handle an option DECODED that is unknown to the option-processing |
3899 | machinery. */ |
3900 | |
3901 | static bool |
3902 | driver_unknown_option_callback (const struct cl_decoded_option *decoded) |
3903 | { |
3904 | const char *opt = decoded->arg; |
3905 | if (opt[1] == 'W' && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-' |
3906 | && !(decoded->errors & CL_ERR_NEGATIVE)) |
3907 | { |
3908 | /* Leave unknown -Wno-* options for the compiler proper, to be |
3909 | diagnosed only if there are warnings. */ |
3910 | save_switch (opt: decoded->canonical_option[0], |
3911 | n_args: decoded->canonical_option_num_elements - 1, |
3912 | args: &decoded->canonical_option[1], validated: false, known: true); |
3913 | return false; |
3914 | } |
3915 | if (decoded->opt_index == OPT_SPECIAL_unknown) |
3916 | { |
3917 | /* Give it a chance to define it a spec file. */ |
3918 | save_switch (opt: decoded->canonical_option[0], |
3919 | n_args: decoded->canonical_option_num_elements - 1, |
3920 | args: &decoded->canonical_option[1], validated: false, known: false); |
3921 | return false; |
3922 | } |
3923 | else |
3924 | return true; |
3925 | } |
3926 | |
3927 | /* Handle an option DECODED that is not marked as CL_DRIVER. |
3928 | LANG_MASK will always be CL_DRIVER. */ |
3929 | |
3930 | static void |
3931 | driver_wrong_lang_callback (const struct cl_decoded_option *decoded, |
3932 | unsigned int lang_mask ATTRIBUTE_UNUSED) |
3933 | { |
3934 | /* At this point, non-driver options are accepted (and expected to |
3935 | be passed down by specs) unless marked to be rejected by the |
3936 | driver. Options to be rejected by the driver but accepted by the |
3937 | compilers proper are treated just like completely unknown |
3938 | options. */ |
3939 | const struct cl_option *option = &cl_options[decoded->opt_index]; |
3940 | |
3941 | if (option->cl_reject_driver) |
3942 | error ("unrecognized command-line option %qs" , |
3943 | decoded->orig_option_with_args_text); |
3944 | else |
3945 | save_switch (opt: decoded->canonical_option[0], |
3946 | n_args: decoded->canonical_option_num_elements - 1, |
3947 | args: &decoded->canonical_option[1], validated: false, known: true); |
3948 | } |
3949 | |
3950 | static const char *spec_lang = 0; |
3951 | static int last_language_n_infiles; |
3952 | |
3953 | |
3954 | /* Check that GCC is configured to support the offload target. */ |
3955 | |
3956 | static bool |
3957 | check_offload_target_name (const char *target, ptrdiff_t len) |
3958 | { |
3959 | const char *n, *c = OFFLOAD_TARGETS; |
3960 | while (c) |
3961 | { |
3962 | n = strchr (s: c, c: ','); |
3963 | if (n == NULL) |
3964 | n = strchr (s: c, c: '\0'); |
3965 | if (len == n - c && strncmp (s1: target, s2: c, n: n - c) == 0) |
3966 | break; |
3967 | c = *n ? n + 1 : NULL; |
3968 | } |
3969 | if (!c) |
3970 | { |
3971 | auto_vec<const char*> candidates; |
3972 | size_t olen = strlen (OFFLOAD_TARGETS) + 1; |
3973 | char *cand = XALLOCAVEC (char, olen); |
3974 | memcpy (dest: cand, OFFLOAD_TARGETS, n: olen); |
3975 | for (c = strtok (s: cand, delim: "," ); c; c = strtok (NULL, delim: "," )) |
3976 | candidates.safe_push (c); |
3977 | candidates.safe_push ("default" ); |
3978 | candidates.safe_push ("disable" ); |
3979 | |
3980 | char *target2 = XALLOCAVEC (char, len + 1); |
3981 | memcpy (dest: target2, src: target, n: len); |
3982 | target2[len] = '\0'; |
3983 | |
3984 | error ("GCC is not configured to support %qs as %<-foffload=%> argument" , |
3985 | target2); |
3986 | |
3987 | char *s; |
3988 | const char *hint = candidates_list_and_hint (arg: target2, str&: s, candidates); |
3989 | if (hint) |
3990 | inform (UNKNOWN_LOCATION, |
3991 | "valid %<-foffload=%> arguments are: %s; " |
3992 | "did you mean %qs?" , s, hint); |
3993 | else |
3994 | inform (UNKNOWN_LOCATION, "valid %<-foffload=%> arguments are: %s" , s); |
3995 | XDELETEVEC (s); |
3996 | return false; |
3997 | } |
3998 | return true; |
3999 | } |
4000 | |
4001 | /* Sanity check for -foffload-options. */ |
4002 | |
4003 | static void |
4004 | check_foffload_target_names (const char *arg) |
4005 | { |
4006 | const char *cur, *next, *end; |
4007 | /* If option argument starts with '-' then no target is specified and we |
4008 | do not need to parse it. */ |
4009 | if (arg[0] == '-') |
4010 | return; |
4011 | end = strchr (s: arg, c: '='); |
4012 | if (end == NULL) |
4013 | { |
4014 | error ("%<=%>options missing after %<-foffload-options=%>target" ); |
4015 | return; |
4016 | } |
4017 | |
4018 | cur = arg; |
4019 | while (cur < end) |
4020 | { |
4021 | next = strchr (s: cur, c: ','); |
4022 | if (next == NULL) |
4023 | next = end; |
4024 | next = (next > end) ? end : next; |
4025 | |
4026 | /* Retain non-supported targets after printing an error as those will not |
4027 | be processed; each enabled target only processes its triplet. */ |
4028 | check_offload_target_name (target: cur, len: next - cur); |
4029 | cur = next + 1; |
4030 | } |
4031 | } |
4032 | |
4033 | /* Parse -foffload option argument. */ |
4034 | |
4035 | static void |
4036 | handle_foffload_option (const char *arg) |
4037 | { |
4038 | const char *c, *cur, *n, *next, *end; |
4039 | char *target; |
4040 | |
4041 | /* If option argument starts with '-' then no target is specified and we |
4042 | do not need to parse it. */ |
4043 | if (arg[0] == '-') |
4044 | return; |
4045 | |
4046 | end = strchr (s: arg, c: '='); |
4047 | if (end == NULL) |
4048 | end = strchr (s: arg, c: '\0'); |
4049 | cur = arg; |
4050 | |
4051 | while (cur < end) |
4052 | { |
4053 | next = strchr (s: cur, c: ','); |
4054 | if (next == NULL) |
4055 | next = end; |
4056 | next = (next > end) ? end : next; |
4057 | |
4058 | target = XNEWVEC (char, next - cur + 1); |
4059 | memcpy (dest: target, src: cur, n: next - cur); |
4060 | target[next - cur] = '\0'; |
4061 | |
4062 | /* Reset offloading list and continue. */ |
4063 | if (strcmp (s1: target, s2: "default" ) == 0) |
4064 | { |
4065 | free (ptr: offload_targets); |
4066 | offload_targets = NULL; |
4067 | goto next_item; |
4068 | } |
4069 | |
4070 | /* If 'disable' is passed to the option, clean the list of |
4071 | offload targets and return, even if more targets follow. |
4072 | Likewise if GCC is not configured to support that offload target. */ |
4073 | if (strcmp (s1: target, s2: "disable" ) == 0 |
4074 | || !check_offload_target_name (target, len: next - cur)) |
4075 | { |
4076 | free (ptr: offload_targets); |
4077 | offload_targets = xstrdup ("" ); |
4078 | return; |
4079 | } |
4080 | |
4081 | if (!offload_targets) |
4082 | { |
4083 | offload_targets = target; |
4084 | target = NULL; |
4085 | } |
4086 | else |
4087 | { |
4088 | /* Check that the target hasn't already presented in the list. */ |
4089 | c = offload_targets; |
4090 | do |
4091 | { |
4092 | n = strchr (s: c, c: ':'); |
4093 | if (n == NULL) |
4094 | n = strchr (s: c, c: '\0'); |
4095 | |
4096 | if (next - cur == n - c && strncmp (s1: c, s2: target, n: n - c) == 0) |
4097 | break; |
4098 | |
4099 | c = n + 1; |
4100 | } |
4101 | while (*n); |
4102 | |
4103 | /* If duplicate is not found, append the target to the list. */ |
4104 | if (c > n) |
4105 | { |
4106 | size_t offload_targets_len = strlen (s: offload_targets); |
4107 | offload_targets |
4108 | = XRESIZEVEC (char, offload_targets, |
4109 | offload_targets_len + 1 + next - cur + 1); |
4110 | offload_targets[offload_targets_len++] = ':'; |
4111 | memcpy (dest: offload_targets + offload_targets_len, src: target, n: next - cur + 1); |
4112 | } |
4113 | } |
4114 | next_item: |
4115 | cur = next + 1; |
4116 | XDELETEVEC (target); |
4117 | } |
4118 | } |
4119 | |
4120 | /* Handle a driver option; arguments and return value as for |
4121 | handle_option. */ |
4122 | |
4123 | static bool |
4124 | driver_handle_option (struct gcc_options *opts, |
4125 | struct gcc_options *opts_set, |
4126 | const struct cl_decoded_option *decoded, |
4127 | unsigned int lang_mask ATTRIBUTE_UNUSED, int kind, |
4128 | location_t loc, |
4129 | const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED, |
4130 | diagnostic_context *dc, |
4131 | void (*) (void)) |
4132 | { |
4133 | size_t opt_index = decoded->opt_index; |
4134 | const char *arg = decoded->arg; |
4135 | const char *compare_debug_replacement_opt; |
4136 | int value = decoded->value; |
4137 | bool validated = false; |
4138 | bool do_save = true; |
4139 | |
4140 | gcc_assert (opts == &global_options); |
4141 | gcc_assert (opts_set == &global_options_set); |
4142 | gcc_assert (kind == DK_UNSPECIFIED); |
4143 | gcc_assert (loc == UNKNOWN_LOCATION); |
4144 | gcc_assert (dc == global_dc); |
4145 | |
4146 | switch (opt_index) |
4147 | { |
4148 | case OPT_dumpspecs: |
4149 | { |
4150 | struct spec_list *sl; |
4151 | init_spec (); |
4152 | for (sl = specs; sl; sl = sl->next) |
4153 | printf (format: "*%s:\n%s\n\n" , sl->name, *(sl->ptr_spec)); |
4154 | if (link_command_spec) |
4155 | printf (format: "*link_command:\n%s\n\n" , link_command_spec); |
4156 | exit (status: 0); |
4157 | } |
4158 | |
4159 | case OPT_dumpversion: |
4160 | printf (format: "%s\n" , spec_version); |
4161 | exit (status: 0); |
4162 | |
4163 | case OPT_dumpmachine: |
4164 | printf (format: "%s\n" , spec_machine); |
4165 | exit (status: 0); |
4166 | |
4167 | case OPT_dumpfullversion: |
4168 | printf ("%s\n" , BASEVER); |
4169 | exit (status: 0); |
4170 | |
4171 | case OPT__version: |
4172 | print_version = 1; |
4173 | |
4174 | /* CPP driver cannot obtain switch from cc1_options. */ |
4175 | if (is_cpp_driver) |
4176 | add_preprocessor_option (option: "--version" , len: strlen (s: "--version" )); |
4177 | add_assembler_option (option: "--version" , len: strlen (s: "--version" )); |
4178 | add_linker_option (option: "--version" , len: strlen (s: "--version" )); |
4179 | break; |
4180 | |
4181 | case OPT__completion_: |
4182 | validated = true; |
4183 | completion = decoded->arg; |
4184 | break; |
4185 | |
4186 | case OPT__help: |
4187 | print_help_list = 1; |
4188 | |
4189 | /* CPP driver cannot obtain switch from cc1_options. */ |
4190 | if (is_cpp_driver) |
4191 | add_preprocessor_option (option: "--help" , len: 6); |
4192 | add_assembler_option (option: "--help" , len: 6); |
4193 | add_linker_option (option: "--help" , len: 6); |
4194 | break; |
4195 | |
4196 | case OPT__help_: |
4197 | print_subprocess_help = 2; |
4198 | break; |
4199 | |
4200 | case OPT__target_help: |
4201 | print_subprocess_help = 1; |
4202 | |
4203 | /* CPP driver cannot obtain switch from cc1_options. */ |
4204 | if (is_cpp_driver) |
4205 | add_preprocessor_option (option: "--target-help" , len: 13); |
4206 | add_assembler_option (option: "--target-help" , len: 13); |
4207 | add_linker_option (option: "--target-help" , len: 13); |
4208 | break; |
4209 | |
4210 | case OPT__no_sysroot_suffix: |
4211 | case OPT_pass_exit_codes: |
4212 | case OPT_print_search_dirs: |
4213 | case OPT_print_file_name_: |
4214 | case OPT_print_prog_name_: |
4215 | case OPT_print_multi_lib: |
4216 | case OPT_print_multi_directory: |
4217 | case OPT_print_sysroot: |
4218 | case OPT_print_multi_os_directory: |
4219 | case OPT_print_multiarch: |
4220 | case OPT_print_sysroot_headers_suffix: |
4221 | case OPT_time: |
4222 | case OPT_wrapper: |
4223 | /* These options set the variables specified in common.opt |
4224 | automatically, and do not need to be saved for spec |
4225 | processing. */ |
4226 | do_save = false; |
4227 | break; |
4228 | |
4229 | case OPT_print_libgcc_file_name: |
4230 | print_file_name = "libgcc.a" ; |
4231 | do_save = false; |
4232 | break; |
4233 | |
4234 | case OPT_fuse_ld_bfd: |
4235 | use_ld = ".bfd" ; |
4236 | break; |
4237 | |
4238 | case OPT_fuse_ld_gold: |
4239 | use_ld = ".gold" ; |
4240 | break; |
4241 | |
4242 | case OPT_fuse_ld_mold: |
4243 | use_ld = ".mold" ; |
4244 | break; |
4245 | |
4246 | case OPT_fcompare_debug_second: |
4247 | compare_debug_second = 1; |
4248 | break; |
4249 | |
4250 | case OPT_fcompare_debug: |
4251 | switch (value) |
4252 | { |
4253 | case 0: |
4254 | compare_debug_replacement_opt = "-fcompare-debug=" ; |
4255 | arg = "" ; |
4256 | goto compare_debug_with_arg; |
4257 | |
4258 | case 1: |
4259 | compare_debug_replacement_opt = "-fcompare-debug=-gtoggle" ; |
4260 | arg = "-gtoggle" ; |
4261 | goto compare_debug_with_arg; |
4262 | |
4263 | default: |
4264 | gcc_unreachable (); |
4265 | } |
4266 | break; |
4267 | |
4268 | case OPT_fcompare_debug_: |
4269 | compare_debug_replacement_opt = decoded->canonical_option[0]; |
4270 | compare_debug_with_arg: |
4271 | gcc_assert (decoded->canonical_option_num_elements == 1); |
4272 | gcc_assert (arg != NULL); |
4273 | if (*arg) |
4274 | compare_debug = 1; |
4275 | else |
4276 | compare_debug = -1; |
4277 | if (compare_debug < 0) |
4278 | compare_debug_opt = NULL; |
4279 | else |
4280 | compare_debug_opt = arg; |
4281 | save_switch (opt: compare_debug_replacement_opt, n_args: 0, NULL, validated, known: true); |
4282 | set_source_date_epoch_envvar (); |
4283 | return true; |
4284 | |
4285 | case OPT_fdiagnostics_color_: |
4286 | diagnostic_color_init (dc, value); |
4287 | break; |
4288 | |
4289 | case OPT_fdiagnostics_urls_: |
4290 | diagnostic_urls_init (dc, value); |
4291 | break; |
4292 | |
4293 | case OPT_fdiagnostics_format_: |
4294 | { |
4295 | const char *basename = (opts->x_dump_base_name ? opts->x_dump_base_name |
4296 | : opts->x_main_input_basename); |
4297 | diagnostic_output_format_init (dc, base_file_name: basename, |
4298 | (enum diagnostics_output_format)value); |
4299 | break; |
4300 | } |
4301 | |
4302 | case OPT_Wa_: |
4303 | { |
4304 | int prev, j; |
4305 | /* Pass the rest of this option to the assembler. */ |
4306 | |
4307 | /* Split the argument at commas. */ |
4308 | prev = 0; |
4309 | for (j = 0; arg[j]; j++) |
4310 | if (arg[j] == ',') |
4311 | { |
4312 | add_assembler_option (option: arg + prev, len: j - prev); |
4313 | prev = j + 1; |
4314 | } |
4315 | |
4316 | /* Record the part after the last comma. */ |
4317 | add_assembler_option (option: arg + prev, len: j - prev); |
4318 | } |
4319 | do_save = false; |
4320 | break; |
4321 | |
4322 | case OPT_Wp_: |
4323 | { |
4324 | int prev, j; |
4325 | /* Pass the rest of this option to the preprocessor. */ |
4326 | |
4327 | /* Split the argument at commas. */ |
4328 | prev = 0; |
4329 | for (j = 0; arg[j]; j++) |
4330 | if (arg[j] == ',') |
4331 | { |
4332 | add_preprocessor_option (option: arg + prev, len: j - prev); |
4333 | prev = j + 1; |
4334 | } |
4335 | |
4336 | /* Record the part after the last comma. */ |
4337 | add_preprocessor_option (option: arg + prev, len: j - prev); |
4338 | } |
4339 | do_save = false; |
4340 | break; |
4341 | |
4342 | case OPT_Wl_: |
4343 | { |
4344 | int prev, j; |
4345 | /* Split the argument at commas. */ |
4346 | prev = 0; |
4347 | for (j = 0; arg[j]; j++) |
4348 | if (arg[j] == ',') |
4349 | { |
4350 | add_infile (name: save_string (arg + prev, j - prev), language: "*" ); |
4351 | prev = j + 1; |
4352 | } |
4353 | /* Record the part after the last comma. */ |
4354 | add_infile (name: arg + prev, language: "*" ); |
4355 | } |
4356 | do_save = false; |
4357 | break; |
4358 | |
4359 | case OPT_Xlinker: |
4360 | add_infile (name: arg, language: "*" ); |
4361 | do_save = false; |
4362 | break; |
4363 | |
4364 | case OPT_Xpreprocessor: |
4365 | add_preprocessor_option (option: arg, len: strlen (s: arg)); |
4366 | do_save = false; |
4367 | break; |
4368 | |
4369 | case OPT_Xassembler: |
4370 | add_assembler_option (option: arg, len: strlen (s: arg)); |
4371 | do_save = false; |
4372 | break; |
4373 | |
4374 | case OPT_l: |
4375 | /* POSIX allows separation of -l and the lib arg; canonicalize |
4376 | by concatenating -l with its arg */ |
4377 | add_infile (name: concat ("-l" , arg, NULL), language: "*" ); |
4378 | do_save = false; |
4379 | break; |
4380 | |
4381 | case OPT_L: |
4382 | /* Similarly, canonicalize -L for linkers that may not accept |
4383 | separate arguments. */ |
4384 | save_switch (opt: concat ("-L" , arg, NULL), n_args: 0, NULL, validated, known: true); |
4385 | return true; |
4386 | |
4387 | case OPT_F: |
4388 | /* Likewise -F. */ |
4389 | save_switch (opt: concat ("-F" , arg, NULL), n_args: 0, NULL, validated, known: true); |
4390 | return true; |
4391 | |
4392 | case OPT_save_temps: |
4393 | if (!save_temps_flag) |
4394 | save_temps_flag = SAVE_TEMPS_DUMP; |
4395 | validated = true; |
4396 | break; |
4397 | |
4398 | case OPT_save_temps_: |
4399 | if (strcmp (s1: arg, s2: "cwd" ) == 0) |
4400 | save_temps_flag = SAVE_TEMPS_CWD; |
4401 | else if (strcmp (s1: arg, s2: "obj" ) == 0 |
4402 | || strcmp (s1: arg, s2: "object" ) == 0) |
4403 | save_temps_flag = SAVE_TEMPS_OBJ; |
4404 | else |
4405 | fatal_error (input_location, "%qs is an unknown %<-save-temps%> option" , |
4406 | decoded->orig_option_with_args_text); |
4407 | save_temps_overrides_dumpdir = true; |
4408 | break; |
4409 | |
4410 | case OPT_dumpdir: |
4411 | free (ptr: dumpdir); |
4412 | dumpdir = xstrdup (arg); |
4413 | save_temps_overrides_dumpdir = false; |
4414 | break; |
4415 | |
4416 | case OPT_dumpbase: |
4417 | free (ptr: dumpbase); |
4418 | dumpbase = xstrdup (arg); |
4419 | break; |
4420 | |
4421 | case OPT_dumpbase_ext: |
4422 | free (ptr: dumpbase_ext); |
4423 | dumpbase_ext = xstrdup (arg); |
4424 | break; |
4425 | |
4426 | case OPT_no_canonical_prefixes: |
4427 | /* Already handled as a special case, so ignored here. */ |
4428 | do_save = false; |
4429 | break; |
4430 | |
4431 | case OPT_pipe: |
4432 | validated = true; |
4433 | /* These options set the variables specified in common.opt |
4434 | automatically, but do need to be saved for spec |
4435 | processing. */ |
4436 | break; |
4437 | |
4438 | case OPT_specs_: |
4439 | { |
4440 | struct user_specs *user = XNEW (struct user_specs); |
4441 | |
4442 | user->next = (struct user_specs *) 0; |
4443 | user->filename = arg; |
4444 | if (user_specs_tail) |
4445 | user_specs_tail->next = user; |
4446 | else |
4447 | user_specs_head = user; |
4448 | user_specs_tail = user; |
4449 | } |
4450 | validated = true; |
4451 | break; |
4452 | |
4453 | case OPT__sysroot_: |
4454 | target_system_root = arg; |
4455 | target_system_root_changed = 1; |
4456 | /* Saving this option is useful to let self-specs decide to |
4457 | provide a default one. */ |
4458 | do_save = true; |
4459 | validated = true; |
4460 | break; |
4461 | |
4462 | case OPT_time_: |
4463 | if (report_times_to_file) |
4464 | fclose (stream: report_times_to_file); |
4465 | report_times_to_file = fopen (filename: arg, modes: "a" ); |
4466 | do_save = false; |
4467 | break; |
4468 | |
4469 | case OPT____: |
4470 | /* "-###" |
4471 | This is similar to -v except that there is no execution |
4472 | of the commands and the echoed arguments are quoted. It |
4473 | is intended for use in shell scripts to capture the |
4474 | driver-generated command line. */ |
4475 | verbose_only_flag++; |
4476 | verbose_flag = 1; |
4477 | do_save = false; |
4478 | break; |
4479 | |
4480 | case OPT_B: |
4481 | { |
4482 | size_t len = strlen (s: arg); |
4483 | |
4484 | /* Catch the case where the user has forgotten to append a |
4485 | directory separator to the path. Note, they may be using |
4486 | -B to add an executable name prefix, eg "i386-elf-", in |
4487 | order to distinguish between multiple installations of |
4488 | GCC in the same directory. Hence we must check to see |
4489 | if appending a directory separator actually makes a |
4490 | valid directory name. */ |
4491 | if (!IS_DIR_SEPARATOR (arg[len - 1]) |
4492 | && is_directory (arg, false)) |
4493 | { |
4494 | char *tmp = XNEWVEC (char, len + 2); |
4495 | strcpy (dest: tmp, src: arg); |
4496 | tmp[len] = DIR_SEPARATOR; |
4497 | tmp[++len] = 0; |
4498 | arg = tmp; |
4499 | } |
4500 | |
4501 | add_prefix (pprefix: &exec_prefixes, prefix: arg, NULL, |
4502 | priority: PREFIX_PRIORITY_B_OPT, require_machine_suffix: 0, os_multilib: 0); |
4503 | add_prefix (pprefix: &startfile_prefixes, prefix: arg, NULL, |
4504 | priority: PREFIX_PRIORITY_B_OPT, require_machine_suffix: 0, os_multilib: 0); |
4505 | add_prefix (pprefix: &include_prefixes, prefix: arg, NULL, |
4506 | priority: PREFIX_PRIORITY_B_OPT, require_machine_suffix: 0, os_multilib: 0); |
4507 | } |
4508 | validated = true; |
4509 | break; |
4510 | |
4511 | case OPT_E: |
4512 | have_E = true; |
4513 | break; |
4514 | |
4515 | case OPT_x: |
4516 | spec_lang = arg; |
4517 | if (!strcmp (s1: spec_lang, s2: "none" )) |
4518 | /* Suppress the warning if -xnone comes after the last input |
4519 | file, because alternate command interfaces like g++ might |
4520 | find it useful to place -xnone after each input file. */ |
4521 | spec_lang = 0; |
4522 | else |
4523 | last_language_n_infiles = n_infiles; |
4524 | do_save = false; |
4525 | break; |
4526 | |
4527 | case OPT_o: |
4528 | have_o = 1; |
4529 | #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) || defined(HAVE_TARGET_OBJECT_SUFFIX) |
4530 | arg = convert_filename (arg, ! have_c, 0); |
4531 | #endif |
4532 | output_file = arg; |
4533 | /* On some systems, ld cannot handle "-o" without a space. So |
4534 | split the option from its argument. */ |
4535 | save_switch (opt: "-o" , n_args: 1, args: &arg, validated, known: true); |
4536 | return true; |
4537 | |
4538 | #ifdef ENABLE_DEFAULT_PIE |
4539 | case OPT_pie: |
4540 | /* -pie is turned on by default. */ |
4541 | #endif |
4542 | |
4543 | case OPT_static_libgcc: |
4544 | case OPT_shared_libgcc: |
4545 | case OPT_static_libgfortran: |
4546 | case OPT_static_libquadmath: |
4547 | case OPT_static_libphobos: |
4548 | case OPT_static_libgm2: |
4549 | case OPT_static_libstdc__: |
4550 | /* These are always valid; gcc.cc itself understands the first two |
4551 | gfortranspec.cc understands -static-libgfortran, |
4552 | libgfortran.spec handles -static-libquadmath, |
4553 | d-spec.cc understands -static-libphobos, |
4554 | gm2spec.cc understands -static-libgm2, |
4555 | and g++spec.cc understands -static-libstdc++. */ |
4556 | validated = true; |
4557 | break; |
4558 | |
4559 | case OPT_fwpa: |
4560 | flag_wpa = "" ; |
4561 | break; |
4562 | |
4563 | case OPT_foffload_options_: |
4564 | check_foffload_target_names (arg); |
4565 | break; |
4566 | |
4567 | case OPT_foffload_: |
4568 | handle_foffload_option (arg); |
4569 | if (arg[0] == '-' || NULL != strchr (s: arg, c: '=')) |
4570 | save_switch (opt: concat ("-foffload-options=" , arg, NULL), |
4571 | n_args: 0, NULL, validated, known: true); |
4572 | do_save = false; |
4573 | break; |
4574 | |
4575 | case OPT_gcodeview: |
4576 | add_infile (name: "--pdb=" , language: "*" ); |
4577 | break; |
4578 | |
4579 | default: |
4580 | /* Various driver options need no special processing at this |
4581 | point, having been handled in a prescan above or being |
4582 | handled by specs. */ |
4583 | break; |
4584 | } |
4585 | |
4586 | if (do_save) |
4587 | save_switch (opt: decoded->canonical_option[0], |
4588 | n_args: decoded->canonical_option_num_elements - 1, |
4589 | args: &decoded->canonical_option[1], validated, known: true); |
4590 | return true; |
4591 | } |
4592 | |
4593 | /* Return true if F2 is F1 followed by a single suffix, i.e., by a |
4594 | period and additional characters other than a period. */ |
4595 | |
4596 | static inline bool |
4597 | adds_single_suffix_p (const char *f2, const char *f1) |
4598 | { |
4599 | size_t len = strlen (s: f1); |
4600 | |
4601 | return (strncmp (s1: f1, s2: f2, n: len) == 0 |
4602 | && f2[len] == '.' |
4603 | && strchr (s: f2 + len + 1, c: '.') == NULL); |
4604 | } |
4605 | |
4606 | /* Put the driver's standard set of option handlers in *HANDLERS. */ |
4607 | |
4608 | static void |
4609 | set_option_handlers (struct cl_option_handlers *handlers) |
4610 | { |
4611 | handlers->unknown_option_callback = driver_unknown_option_callback; |
4612 | handlers->wrong_lang_callback = driver_wrong_lang_callback; |
4613 | handlers->num_handlers = 3; |
4614 | handlers->handlers[0].handler = driver_handle_option; |
4615 | handlers->handlers[0].mask = CL_DRIVER; |
4616 | handlers->handlers[1].handler = common_handle_option; |
4617 | handlers->handlers[1].mask = CL_COMMON; |
4618 | handlers->handlers[2].handler = target_handle_option; |
4619 | handlers->handlers[2].mask = CL_TARGET; |
4620 | } |
4621 | |
4622 | |
4623 | /* Return the index into infiles for the single non-library |
4624 | non-lto-wpa input file, -1 if there isn't any, or -2 if there is |
4625 | more than one. */ |
4626 | static inline int |
4627 | single_input_file_index () |
4628 | { |
4629 | int ret = -1; |
4630 | |
4631 | for (int i = 0; i < n_infiles; i++) |
4632 | { |
4633 | if (infiles[i].language |
4634 | && (infiles[i].language[0] == '*' |
4635 | || (flag_wpa |
4636 | && strcmp (s1: infiles[i].language, s2: "lto" ) == 0))) |
4637 | continue; |
4638 | |
4639 | if (ret != -1) |
4640 | return -2; |
4641 | |
4642 | ret = i; |
4643 | } |
4644 | |
4645 | return ret; |
4646 | } |
4647 | |
4648 | /* Create the vector `switches' and its contents. |
4649 | Store its length in `n_switches'. */ |
4650 | |
4651 | static void |
4652 | process_command (unsigned int decoded_options_count, |
4653 | struct cl_decoded_option *decoded_options) |
4654 | { |
4655 | const char *temp; |
4656 | char *temp1; |
4657 | char *tooldir_prefix, *tooldir_prefix2; |
4658 | char *(*get_relative_prefix) (const char *, const char *, |
4659 | const char *) = NULL; |
4660 | struct cl_option_handlers handlers; |
4661 | unsigned int j; |
4662 | |
4663 | gcc_exec_prefix = env.get (name: "GCC_EXEC_PREFIX" ); |
4664 | |
4665 | n_switches = 0; |
4666 | n_infiles = 0; |
4667 | added_libraries = 0; |
4668 | |
4669 | /* Figure compiler version from version string. */ |
4670 | |
4671 | compiler_version = temp1 = xstrdup (version_string); |
4672 | |
4673 | for (; *temp1; ++temp1) |
4674 | { |
4675 | if (*temp1 == ' ') |
4676 | { |
4677 | *temp1 = '\0'; |
4678 | break; |
4679 | } |
4680 | } |
4681 | |
4682 | /* Handle any -no-canonical-prefixes flag early, to assign the function |
4683 | that builds relative prefixes. This function creates default search |
4684 | paths that are needed later in normal option handling. */ |
4685 | |
4686 | for (j = 1; j < decoded_options_count; j++) |
4687 | { |
4688 | if (decoded_options[j].opt_index == OPT_no_canonical_prefixes) |
4689 | { |
4690 | get_relative_prefix = make_relative_prefix_ignore_links; |
4691 | break; |
4692 | } |
4693 | } |
4694 | if (! get_relative_prefix) |
4695 | get_relative_prefix = make_relative_prefix; |
4696 | |
4697 | /* Set up the default search paths. If there is no GCC_EXEC_PREFIX, |
4698 | see if we can create it from the pathname specified in |
4699 | decoded_options[0].arg. */ |
4700 | |
4701 | gcc_libexec_prefix = standard_libexec_prefix; |
4702 | #ifndef VMS |
4703 | /* FIXME: make_relative_prefix doesn't yet work for VMS. */ |
4704 | if (!gcc_exec_prefix) |
4705 | { |
4706 | gcc_exec_prefix = get_relative_prefix (decoded_options[0].arg, |
4707 | standard_bindir_prefix, |
4708 | standard_exec_prefix); |
4709 | gcc_libexec_prefix = get_relative_prefix (decoded_options[0].arg, |
4710 | standard_bindir_prefix, |
4711 | standard_libexec_prefix); |
4712 | if (gcc_exec_prefix) |
4713 | xputenv (string: concat ("GCC_EXEC_PREFIX=" , gcc_exec_prefix, NULL)); |
4714 | } |
4715 | else |
4716 | { |
4717 | /* make_relative_prefix requires a program name, but |
4718 | GCC_EXEC_PREFIX is typically a directory name with a trailing |
4719 | / (which is ignored by make_relative_prefix), so append a |
4720 | program name. */ |
4721 | char *tmp_prefix = concat (gcc_exec_prefix, "gcc" , NULL); |
4722 | gcc_libexec_prefix = get_relative_prefix (tmp_prefix, |
4723 | standard_exec_prefix, |
4724 | standard_libexec_prefix); |
4725 | |
4726 | /* The path is unrelocated, so fallback to the original setting. */ |
4727 | if (!gcc_libexec_prefix) |
4728 | gcc_libexec_prefix = standard_libexec_prefix; |
4729 | |
4730 | free (ptr: tmp_prefix); |
4731 | } |
4732 | #else |
4733 | #endif |
4734 | /* From this point onward, gcc_exec_prefix is non-null if the toolchain |
4735 | is relocated. The toolchain was either relocated using GCC_EXEC_PREFIX |
4736 | or an automatically created GCC_EXEC_PREFIX from |
4737 | decoded_options[0].arg. */ |
4738 | |
4739 | /* Do language-specific adjustment/addition of flags. */ |
4740 | lang_specific_driver (&decoded_options, &decoded_options_count, |
4741 | &added_libraries); |
4742 | |
4743 | if (gcc_exec_prefix) |
4744 | { |
4745 | int len = strlen (s: gcc_exec_prefix); |
4746 | |
4747 | if (len > (int) sizeof ("/lib/gcc/" ) - 1 |
4748 | && (IS_DIR_SEPARATOR (gcc_exec_prefix[len-1]))) |
4749 | { |
4750 | temp = gcc_exec_prefix + len - sizeof ("/lib/gcc/" ) + 1; |
4751 | if (IS_DIR_SEPARATOR (*temp) |
4752 | && filename_ncmp (s1: temp + 1, s2: "lib" , n: 3) == 0 |
4753 | && IS_DIR_SEPARATOR (temp[4]) |
4754 | && filename_ncmp (s1: temp + 5, s2: "gcc" , n: 3) == 0) |
4755 | len -= sizeof ("/lib/gcc/" ) - 1; |
4756 | } |
4757 | |
4758 | set_std_prefix (gcc_exec_prefix, len); |
4759 | add_prefix (pprefix: &exec_prefixes, prefix: gcc_libexec_prefix, component: "GCC" , |
4760 | priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 0, os_multilib: 0); |
4761 | add_prefix (pprefix: &startfile_prefixes, prefix: gcc_exec_prefix, component: "GCC" , |
4762 | priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 0, os_multilib: 0); |
4763 | } |
4764 | |
4765 | /* COMPILER_PATH and LIBRARY_PATH have values |
4766 | that are lists of directory names with colons. */ |
4767 | |
4768 | temp = env.get (name: "COMPILER_PATH" ); |
4769 | if (temp) |
4770 | { |
4771 | const char *startp, *endp; |
4772 | char *nstore = (char *) alloca (strlen (temp) + 3); |
4773 | |
4774 | startp = endp = temp; |
4775 | while (1) |
4776 | { |
4777 | if (*endp == PATH_SEPARATOR || *endp == 0) |
4778 | { |
4779 | strncpy (dest: nstore, src: startp, n: endp - startp); |
4780 | if (endp == startp) |
4781 | strcpy (dest: nstore, src: concat ("." , dir_separator_str, NULL)); |
4782 | else if (!IS_DIR_SEPARATOR (endp[-1])) |
4783 | { |
4784 | nstore[endp - startp] = DIR_SEPARATOR; |
4785 | nstore[endp - startp + 1] = 0; |
4786 | } |
4787 | else |
4788 | nstore[endp - startp] = 0; |
4789 | add_prefix (pprefix: &exec_prefixes, prefix: nstore, component: 0, |
4790 | priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 0, os_multilib: 0); |
4791 | add_prefix (pprefix: &include_prefixes, prefix: nstore, component: 0, |
4792 | priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 0, os_multilib: 0); |
4793 | if (*endp == 0) |
4794 | break; |
4795 | endp = startp = endp + 1; |
4796 | } |
4797 | else |
4798 | endp++; |
4799 | } |
4800 | } |
4801 | |
4802 | temp = env.get (LIBRARY_PATH_ENV); |
4803 | if (temp && *cross_compile == '0') |
4804 | { |
4805 | const char *startp, *endp; |
4806 | char *nstore = (char *) alloca (strlen (temp) + 3); |
4807 | |
4808 | startp = endp = temp; |
4809 | while (1) |
4810 | { |
4811 | if (*endp == PATH_SEPARATOR || *endp == 0) |
4812 | { |
4813 | strncpy (dest: nstore, src: startp, n: endp - startp); |
4814 | if (endp == startp) |
4815 | strcpy (dest: nstore, src: concat ("." , dir_separator_str, NULL)); |
4816 | else if (!IS_DIR_SEPARATOR (endp[-1])) |
4817 | { |
4818 | nstore[endp - startp] = DIR_SEPARATOR; |
4819 | nstore[endp - startp + 1] = 0; |
4820 | } |
4821 | else |
4822 | nstore[endp - startp] = 0; |
4823 | add_prefix (pprefix: &startfile_prefixes, prefix: nstore, NULL, |
4824 | priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 0, os_multilib: 1); |
4825 | if (*endp == 0) |
4826 | break; |
4827 | endp = startp = endp + 1; |
4828 | } |
4829 | else |
4830 | endp++; |
4831 | } |
4832 | } |
4833 | |
4834 | /* Use LPATH like LIBRARY_PATH (for the CMU build program). */ |
4835 | temp = env.get (name: "LPATH" ); |
4836 | if (temp && *cross_compile == '0') |
4837 | { |
4838 | const char *startp, *endp; |
4839 | char *nstore = (char *) alloca (strlen (temp) + 3); |
4840 | |
4841 | startp = endp = temp; |
4842 | while (1) |
4843 | { |
4844 | if (*endp == PATH_SEPARATOR || *endp == 0) |
4845 | { |
4846 | strncpy (dest: nstore, src: startp, n: endp - startp); |
4847 | if (endp == startp) |
4848 | strcpy (dest: nstore, src: concat ("." , dir_separator_str, NULL)); |
4849 | else if (!IS_DIR_SEPARATOR (endp[-1])) |
4850 | { |
4851 | nstore[endp - startp] = DIR_SEPARATOR; |
4852 | nstore[endp - startp + 1] = 0; |
4853 | } |
4854 | else |
4855 | nstore[endp - startp] = 0; |
4856 | add_prefix (pprefix: &startfile_prefixes, prefix: nstore, NULL, |
4857 | priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 0, os_multilib: 1); |
4858 | if (*endp == 0) |
4859 | break; |
4860 | endp = startp = endp + 1; |
4861 | } |
4862 | else |
4863 | endp++; |
4864 | } |
4865 | } |
4866 | |
4867 | /* Process the options and store input files and switches in their |
4868 | vectors. */ |
4869 | |
4870 | last_language_n_infiles = -1; |
4871 | |
4872 | set_option_handlers (&handlers); |
4873 | |
4874 | for (j = 1; j < decoded_options_count; j++) |
4875 | { |
4876 | switch (decoded_options[j].opt_index) |
4877 | { |
4878 | case OPT_S: |
4879 | case OPT_c: |
4880 | case OPT_E: |
4881 | have_c = 1; |
4882 | break; |
4883 | } |
4884 | if (have_c) |
4885 | break; |
4886 | } |
4887 | |
4888 | for (j = 1; j < decoded_options_count; j++) |
4889 | { |
4890 | if (decoded_options[j].opt_index == OPT_SPECIAL_input_file) |
4891 | { |
4892 | const char *arg = decoded_options[j].arg; |
4893 | |
4894 | #ifdef HAVE_TARGET_OBJECT_SUFFIX |
4895 | arg = convert_filename (arg, 0, access (arg, F_OK)); |
4896 | #endif |
4897 | add_infile (name: arg, language: spec_lang); |
4898 | |
4899 | continue; |
4900 | } |
4901 | |
4902 | read_cmdline_option (opts: &global_options, opts_set: &global_options_set, |
4903 | decoded: decoded_options + j, UNKNOWN_LOCATION, |
4904 | CL_DRIVER, handlers: &handlers, dc: global_dc); |
4905 | } |
4906 | |
4907 | /* If the user didn't specify any, default to all configured offload |
4908 | targets. */ |
4909 | if (ENABLE_OFFLOADING && offload_targets == NULL) |
4910 | { |
4911 | handle_foffload_option (OFFLOAD_TARGETS); |
4912 | #if OFFLOAD_DEFAULTED |
4913 | offload_targets_default = true; |
4914 | #endif |
4915 | } |
4916 | |
4917 | /* Handle -gtoggle as it would later in toplev.cc:process_options to |
4918 | make the debug-level-gt spec function work as expected. */ |
4919 | if (flag_gtoggle) |
4920 | { |
4921 | if (debug_info_level == DINFO_LEVEL_NONE) |
4922 | debug_info_level = DINFO_LEVEL_NORMAL; |
4923 | else |
4924 | debug_info_level = DINFO_LEVEL_NONE; |
4925 | } |
4926 | |
4927 | if (output_file |
4928 | && strcmp (s1: output_file, s2: "-" ) != 0 |
4929 | && strcmp (s1: output_file, HOST_BIT_BUCKET) != 0) |
4930 | { |
4931 | int i; |
4932 | for (i = 0; i < n_infiles; i++) |
4933 | if ((!infiles[i].language || infiles[i].language[0] != '*') |
4934 | && canonical_filename_eq (a: infiles[i].name, b: output_file)) |
4935 | fatal_error (input_location, |
4936 | "input file %qs is the same as output file" , |
4937 | output_file); |
4938 | } |
4939 | |
4940 | if (output_file != NULL && output_file[0] == '\0') |
4941 | fatal_error (input_location, "output filename may not be empty" ); |
4942 | |
4943 | /* -dumpdir and -save-temps=* both specify the location of aux/dump |
4944 | outputs; the one that appears last prevails. When compiling |
4945 | multiple sources, an explicit dumpbase (minus -ext) may be |
4946 | combined with an explicit or implicit dumpdir, whereas when |
4947 | linking, a specified or implied link output name (minus |
4948 | extension) may be combined with a prevailing -save-temps=* or an |
4949 | otherwise implied dumpdir, but not override a prevailing |
4950 | -dumpdir. Primary outputs (e.g., linker output when linking |
---|