* pretty-print.h (struct pretty_print_info): Add
[official-gcc/alias-decl.git] / gcc / gcc.c
blobe89f3994adce0b5b11cc9829fdd77c8299610d13
1 /* Compiler driver program that can handle many languages.
2 Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* This program is the user interface to the C compiler and possibly to
23 other compilers. It is used because compilation is a complicated procedure
24 which involves running several programs and passing temporary files between
25 them, forwarding the users switches to those programs selectively,
26 and deleting the temporary files at the end.
28 CC recognizes how to compile each input file by suffixes in the file names.
29 Once it knows which kind of compilation to perform, the procedure for
30 compilation is specified by a string called a "spec". */
32 /* A Short Introduction to Adding a Command-Line Option.
34 Before adding a command-line option, consider if it is really
35 necessary. Each additional command-line option adds complexity and
36 is difficult to remove in subsequent versions.
38 In the following, consider adding the command-line argument
39 `--bar'.
41 1. Each command-line option is specified in the specs file. The
42 notation is described below in the comment entitled "The Specs
43 Language". Read it.
45 2. In this file, add an entry to "option_map" equating the long
46 `--' argument version and any shorter, single letter version. Read
47 the comments in the declaration of "struct option_map" for an
48 explanation. Do not omit the first `-'.
50 3. Look in the "specs" file to determine which program or option
51 list should be given the argument, e.g., "cc1_options". Add the
52 appropriate syntax for the shorter option version to the
53 corresponding "const char *" entry in this file. Omit the first
54 `-' from the option. For example, use `-bar', rather than `--bar'.
56 4. If the argument takes an argument, e.g., `--baz argument1',
57 modify either DEFAULT_SWITCH_TAKES_ARG or
58 DEFAULT_WORD_SWITCH_TAKES_ARG in gcc.h. Omit the first `-'
59 from `--baz'.
61 5. Document the option in this file's display_help(). If the
62 option is passed to a subprogram, modify its corresponding
63 function, e.g., cppinit.c:print_help() or toplev.c:display_help(),
64 instead.
66 6. Compile and test. Make sure that your new specs file is being
67 read. For example, use a debugger to investigate the value of
68 "specs_file" in main(). */
70 #include "config.h"
71 #include "system.h"
72 #include "coretypes.h"
73 #include "multilib.h" /* before tm.h */
74 #include "tm.h"
75 #include <signal.h>
76 #if ! defined( SIGCHLD ) && defined( SIGCLD )
77 # define SIGCHLD SIGCLD
78 #endif
79 #include "xregex.h"
80 #include "obstack.h"
81 #include "intl.h"
82 #include "prefix.h"
83 #include "gcc.h"
84 #include "flags.h"
85 #include "opts.h"
87 /* By default there is no special suffix for target executables. */
88 /* FIXME: when autoconf is fixed, remove the host check - dj */
89 #if defined(TARGET_EXECUTABLE_SUFFIX) && defined(HOST_EXECUTABLE_SUFFIX)
90 #define HAVE_TARGET_EXECUTABLE_SUFFIX
91 #endif
93 /* By default there is no special suffix for host executables. */
94 #ifdef HOST_EXECUTABLE_SUFFIX
95 #define HAVE_HOST_EXECUTABLE_SUFFIX
96 #else
97 #define HOST_EXECUTABLE_SUFFIX ""
98 #endif
100 /* By default, the suffix for target object files is ".o". */
101 #ifdef TARGET_OBJECT_SUFFIX
102 #define HAVE_TARGET_OBJECT_SUFFIX
103 #else
104 #define TARGET_OBJECT_SUFFIX ".o"
105 #endif
107 static const char dir_separator_str[] = { DIR_SEPARATOR, 0 };
109 /* Most every one is fine with LIBRARY_PATH. For some, it conflicts. */
110 #ifndef LIBRARY_PATH_ENV
111 #define LIBRARY_PATH_ENV "LIBRARY_PATH"
112 #endif
114 #ifndef HAVE_KILL
115 #define kill(p,s) raise(s)
116 #endif
118 /* If a stage of compilation returns an exit status >= 1,
119 compilation of that file ceases. */
121 #define MIN_FATAL_STATUS 1
123 /* Flag set by cppspec.c to 1. */
124 int is_cpp_driver;
126 /* Flag set to nonzero if an @file argument has been supplied to gcc. */
127 static bool at_file_supplied;
129 /* Flag saying to pass the greatest exit code returned by a sub-process
130 to the calling program. */
131 static int pass_exit_codes;
133 /* Definition of string containing the arguments given to configure. */
134 #include "configargs.h"
136 /* Flag saying to print the directories gcc will search through looking for
137 programs, libraries, etc. */
139 static int print_search_dirs;
141 /* Flag saying to print the full filename of this file
142 as found through our usual search mechanism. */
144 static const char *print_file_name = NULL;
146 /* As print_file_name, but search for executable file. */
148 static const char *print_prog_name = NULL;
150 /* Flag saying to print the relative path we'd use to
151 find libgcc.a given the current compiler flags. */
153 static int print_multi_directory;
155 static int print_sysroot;
157 /* Flag saying to print the relative path we'd use to
158 find OS libraries given the current compiler flags. */
160 static int print_multi_os_directory;
162 /* Flag saying to print the list of subdirectories and
163 compiler flags used to select them in a standard form. */
165 static int print_multi_lib;
167 /* Flag saying to print the command line options understood by gcc and its
168 sub-processes. */
170 static int print_help_list;
172 /* Flag saying to print the version of gcc and its sub-processes. */
174 static int print_version;
176 /* Flag saying to print the sysroot suffix used for searching for
177 headers. */
179 static int print_sysroot_headers_suffix;
181 /* Flag indicating whether we should print the command and arguments */
183 static int verbose_flag;
185 /* Flag indicating whether we should ONLY print the command and
186 arguments (like verbose_flag) without executing the command.
187 Displayed arguments are quoted so that the generated command
188 line is suitable for execution. This is intended for use in
189 shell scripts to capture the driver-generated command line. */
190 static int verbose_only_flag;
192 /* Flag indicating how to print command line options of sub-processes. */
194 static int print_subprocess_help;
196 /* Flag indicating whether we should report subprocess execution times
197 (if this is supported by the system - see pexecute.c). */
199 static int report_times;
201 /* Nonzero means place this string before uses of /, so that include
202 and library files can be found in an alternate location. */
204 #ifdef TARGET_SYSTEM_ROOT
205 static const char *target_system_root = TARGET_SYSTEM_ROOT;
206 #else
207 static const char *target_system_root = 0;
208 #endif
210 /* Nonzero means pass the updated target_system_root to the compiler. */
212 static int target_system_root_changed;
214 /* Nonzero means append this string to target_system_root. */
216 static const char *target_sysroot_suffix = 0;
218 /* Nonzero means append this string to target_system_root for headers. */
220 static const char *target_sysroot_hdrs_suffix = 0;
222 /* Nonzero means write "temp" files in source directory
223 and use the source file's name in them, and don't delete them. */
225 static enum save_temps {
226 SAVE_TEMPS_NONE, /* no -save-temps */
227 SAVE_TEMPS_CWD, /* -save-temps in current directory */
228 SAVE_TEMPS_OBJ /* -save-temps in object directory */
229 } save_temps_flag;
231 /* Output file to use to get the object directory for -save-temps=obj */
232 static char *save_temps_prefix = 0;
233 static size_t save_temps_length = 0;
235 /* Nonzero means pass multiple source files to the compiler at one time. */
237 static int combine_flag = 0;
239 /* Nonzero means use pipes to communicate between subprocesses.
240 Overridden by either of the above two flags. */
242 static int use_pipes;
244 /* The compiler version. */
246 static const char *compiler_version;
248 /* The target version specified with -V */
250 static const char *const spec_version = DEFAULT_TARGET_VERSION;
252 /* The target machine specified with -b. */
254 static const char *spec_machine = DEFAULT_TARGET_MACHINE;
256 /* Nonzero if cross-compiling.
257 When -b is used, the value comes from the `specs' file. */
259 #ifdef CROSS_DIRECTORY_STRUCTURE
260 static const char *cross_compile = "1";
261 #else
262 static const char *cross_compile = "0";
263 #endif
265 #ifdef MODIFY_TARGET_NAME
267 /* Information on how to alter the target name based on a command-line
268 switch. The only case we support now is simply appending or deleting a
269 string to or from the end of the first part of the configuration name. */
271 static const struct modify_target
273 const char *const sw;
274 const enum add_del {ADD, DELETE} add_del;
275 const char *const str;
277 modify_target[] = MODIFY_TARGET_NAME;
278 #endif
280 /* The number of errors that have occurred; the link phase will not be
281 run if this is nonzero. */
282 static int error_count = 0;
284 /* Greatest exit code of sub-processes that has been encountered up to
285 now. */
286 static int greatest_status = 1;
288 /* This is the obstack which we use to allocate many strings. */
290 static struct obstack obstack;
292 /* This is the obstack to build an environment variable to pass to
293 collect2 that describes all of the relevant switches of what to
294 pass the compiler in building the list of pointers to constructors
295 and destructors. */
297 static struct obstack collect_obstack;
299 /* This is a list of a wrapper program and its arguments.
300 e.g. wrapper_string of "strace,-c"
301 will cause all programs to run as
302 strace -c program arguments
303 instead of just
304 program arguments */
305 static const char *wrapper_string;
307 /* Forward declaration for prototypes. */
308 struct path_prefix;
309 struct prefix_list;
311 static void init_spec (void);
312 static void store_arg (const char *, int, int);
313 static void insert_wrapper (const char *);
314 static char *load_specs (const char *);
315 static void read_specs (const char *, int);
316 static void set_spec (const char *, const char *);
317 static struct compiler *lookup_compiler (const char *, size_t, const char *);
318 static char *build_search_list (const struct path_prefix *, const char *,
319 bool, bool);
320 static void xputenv (const char *);
321 static void putenv_from_prefixes (const struct path_prefix *, const char *,
322 bool);
323 static int access_check (const char *, int);
324 static char *find_a_file (const struct path_prefix *, const char *, int, bool);
325 static void add_prefix (struct path_prefix *, const char *, const char *,
326 int, int, int);
327 static void add_sysrooted_prefix (struct path_prefix *, const char *,
328 const char *, int, int, int);
329 static void translate_options (int *, const char *const **);
330 static char *skip_whitespace (char *);
331 static void delete_if_ordinary (const char *);
332 static void delete_temp_files (void);
333 static void delete_failure_queue (void);
334 static void clear_failure_queue (void);
335 static int check_live_switch (int, int);
336 static const char *handle_braces (const char *);
337 static inline bool input_suffix_matches (const char *, const char *);
338 static inline bool switch_matches (const char *, const char *, int);
339 static inline void mark_matching_switches (const char *, const char *, int);
340 static inline void process_marked_switches (void);
341 static const char *process_brace_body (const char *, const char *, const char *, int, int);
342 static const struct spec_function *lookup_spec_function (const char *);
343 static const char *eval_spec_function (const char *, const char *);
344 static const char *handle_spec_function (const char *);
345 static char *save_string (const char *, int);
346 static void set_collect_gcc_options (void);
347 static int do_spec_1 (const char *, int, const char *);
348 static int do_spec_2 (const char *);
349 static void do_option_spec (const char *, const char *);
350 static void do_self_spec (const char *);
351 static const char *find_file (const char *);
352 static int is_directory (const char *, bool);
353 static const char *validate_switches (const char *);
354 static void validate_all_switches (void);
355 static inline void validate_switches_from_spec (const char *);
356 static void give_switch (int, int);
357 static int used_arg (const char *, int);
358 static int default_arg (const char *, int);
359 static void set_multilib_dir (void);
360 static void print_multilib_info (void);
361 static void perror_with_name (const char *);
362 static void fatal_ice (const char *, ...) ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN;
363 static void notice (const char *, ...) ATTRIBUTE_PRINTF_1;
364 static void display_help (void);
365 static void add_preprocessor_option (const char *, int);
366 static void add_assembler_option (const char *, int);
367 static void add_linker_option (const char *, int);
368 static void process_command (int, const char **);
369 static int execute (void);
370 static void alloc_args (void);
371 static void clear_args (void);
372 static void fatal_error (int);
373 #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC)
374 static void init_gcc_specs (struct obstack *, const char *, const char *,
375 const char *);
376 #endif
377 #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
378 static const char *convert_filename (const char *, int, int);
379 #endif
381 static const char *getenv_spec_function (int, const char **);
382 static const char *if_exists_spec_function (int, const char **);
383 static const char *if_exists_else_spec_function (int, const char **);
384 static const char *replace_outfile_spec_function (int, const char **);
385 static const char *version_compare_spec_function (int, const char **);
386 static const char *include_spec_function (int, const char **);
387 static const char *print_asm_header_spec_function (int, const char **);
389 /* The Specs Language
391 Specs are strings containing lines, each of which (if not blank)
392 is made up of a program name, and arguments separated by spaces.
393 The program name must be exact and start from root, since no path
394 is searched and it is unreliable to depend on the current working directory.
395 Redirection of input or output is not supported; the subprograms must
396 accept filenames saying what files to read and write.
398 In addition, the specs can contain %-sequences to substitute variable text
399 or for conditional text. Here is a table of all defined %-sequences.
400 Note that spaces are not generated automatically around the results of
401 expanding these sequences; therefore, you can concatenate them together
402 or with constant text in a single argument.
404 %% substitute one % into the program name or argument.
405 %i substitute the name of the input file being processed.
406 %b substitute the basename of the input file being processed.
407 This is the substring up to (and not including) the last period
408 and not including the directory unless -save-temps was specified
409 to put temporaries in a different location.
410 %B same as %b, but include the file suffix (text after the last period).
411 %gSUFFIX
412 substitute a file name that has suffix SUFFIX and is chosen
413 once per compilation, and mark the argument a la %d. To reduce
414 exposure to denial-of-service attacks, the file name is now
415 chosen in a way that is hard to predict even when previously
416 chosen file names are known. For example, `%g.s ... %g.o ... %g.s'
417 might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches
418 the regexp "[.0-9A-Za-z]*%O"; "%O" is treated exactly as if it
419 had been pre-processed. Previously, %g was simply substituted
420 with a file name chosen once per compilation, without regard
421 to any appended suffix (which was therefore treated just like
422 ordinary text), making such attacks more likely to succeed.
423 %|SUFFIX
424 like %g, but if -pipe is in effect, expands simply to "-".
425 %mSUFFIX
426 like %g, but if -pipe is in effect, expands to nothing. (We have both
427 %| and %m to accommodate differences between system assemblers; see
428 the AS_NEEDS_DASH_FOR_PIPED_INPUT target macro.)
429 %uSUFFIX
430 like %g, but generates a new temporary file name even if %uSUFFIX
431 was already seen.
432 %USUFFIX
433 substitutes the last file name generated with %uSUFFIX, generating a
434 new one if there is no such last file name. In the absence of any
435 %uSUFFIX, this is just like %gSUFFIX, except they don't share
436 the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s'
437 would involve the generation of two distinct file names, one
438 for each `%g.s' and another for each `%U.s'. Previously, %U was
439 simply substituted with a file name chosen for the previous %u,
440 without regard to any appended suffix.
441 %jSUFFIX
442 substitutes the name of the HOST_BIT_BUCKET, if any, and if it is
443 writable, and if save-temps is off; otherwise, substitute the name
444 of a temporary file, just like %u. This temporary file is not
445 meant for communication between processes, but rather as a junk
446 disposal mechanism.
447 %.SUFFIX
448 substitutes .SUFFIX for the suffixes of a matched switch's args when
449 it is subsequently output with %*. SUFFIX is terminated by the next
450 space or %.
451 %d marks the argument containing or following the %d as a
452 temporary file name, so that that file will be deleted if GCC exits
453 successfully. Unlike %g, this contributes no text to the argument.
454 %w marks the argument containing or following the %w as the
455 "output file" of this compilation. This puts the argument
456 into the sequence of arguments that %o will substitute later.
457 %V indicates that this compilation produces no "output file".
458 %W{...}
459 like %{...} but mark last argument supplied within
460 as a file to be deleted on failure.
461 %o substitutes the names of all the output files, with spaces
462 automatically placed around them. You should write spaces
463 around the %o as well or the results are undefined.
464 %o is for use in the specs for running the linker.
465 Input files whose names have no recognized suffix are not compiled
466 at all, but they are included among the output files, so they will
467 be linked.
468 %O substitutes the suffix for object files. Note that this is
469 handled specially when it immediately follows %g, %u, or %U
470 (with or without a suffix argument) because of the need for
471 those to form complete file names. The handling is such that
472 %O is treated exactly as if it had already been substituted,
473 except that %g, %u, and %U do not currently support additional
474 SUFFIX characters following %O as they would following, for
475 example, `.o'.
476 %I Substitute any of -iprefix (made from GCC_EXEC_PREFIX), -isysroot
477 (made from TARGET_SYSTEM_ROOT), -isystem (made from COMPILER_PATH
478 and -B options) and -imultilib as necessary.
479 %s current argument is the name of a library or startup file of some sort.
480 Search for that file in a standard list of directories
481 and substitute the full name found.
482 %eSTR Print STR as an error message. STR is terminated by a newline.
483 Use this when inconsistent options are detected.
484 %nSTR Print STR as a notice. STR is terminated by a newline.
485 %x{OPTION} Accumulate an option for %X.
486 %X Output the accumulated linker options specified by compilations.
487 %Y Output the accumulated assembler options specified by compilations.
488 %Z Output the accumulated preprocessor options specified by compilations.
489 %a process ASM_SPEC as a spec.
490 This allows config.h to specify part of the spec for running as.
491 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
492 used here. This can be used to run a post-processor after the
493 assembler has done its job.
494 %D Dump out a -L option for each directory in startfile_prefixes.
495 If multilib_dir is set, extra entries are generated with it affixed.
496 %l process LINK_SPEC as a spec.
497 %L process LIB_SPEC as a spec.
498 %G process LIBGCC_SPEC as a spec.
499 %R Output the concatenation of target_system_root and
500 target_sysroot_suffix.
501 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
502 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
503 %C process CPP_SPEC as a spec.
504 %1 process CC1_SPEC as a spec.
505 %2 process CC1PLUS_SPEC as a spec.
506 %* substitute the variable part of a matched option. (See below.)
507 Note that each comma in the substituted string is replaced by
508 a single space.
509 %<S remove all occurrences of -S from the command line.
510 Note - this command is position dependent. % commands in the
511 spec string before this one will see -S, % commands in the
512 spec string after this one will not.
513 %<S* remove all occurrences of all switches beginning with -S from the
514 command line.
515 %:function(args)
516 Call the named function FUNCTION, passing it ARGS. ARGS is
517 first processed as a nested spec string, then split into an
518 argument vector in the usual fashion. The function returns
519 a string which is processed as if it had appeared literally
520 as part of the current spec.
521 %{S} substitutes the -S switch, if that switch was given to GCC.
522 If that switch was not specified, this substitutes nothing.
523 Here S is a metasyntactic variable.
524 %{S*} substitutes all the switches specified to GCC whose names start
525 with -S. This is used for -o, -I, etc; switches that take
526 arguments. GCC considers `-o foo' as being one switch whose
527 name starts with `o'. %{o*} would substitute this text,
528 including the space; thus, two arguments would be generated.
529 %{S*&T*} likewise, but preserve order of S and T options (the order
530 of S and T in the spec is not significant). Can be any number
531 of ampersand-separated variables; for each the wild card is
532 optional. Useful for CPP as %{D*&U*&A*}.
534 %{S:X} substitutes X, if the -S switch was given to GCC.
535 %{!S:X} substitutes X, if the -S switch was NOT given to GCC.
536 %{S*:X} substitutes X if one or more switches whose names start
537 with -S was given to GCC. Normally X is substituted only
538 once, no matter how many such switches appeared. However,
539 if %* appears somewhere in X, then X will be substituted
540 once for each matching switch, with the %* replaced by the
541 part of that switch that matched the '*'.
542 %{.S:X} substitutes X, if processing a file with suffix S.
543 %{!.S:X} substitutes X, if NOT processing a file with suffix S.
544 %{,S:X} substitutes X, if processing a file which will use spec S.
545 %{!,S:X} substitutes X, if NOT processing a file which will use spec S.
547 %{S|T:X} substitutes X if either -S or -T was given to GCC. This may be
548 combined with '!', '.', ',', and '*' as above binding stronger
549 than the OR.
550 If %* appears in X, all of the alternatives must be starred, and
551 only the first matching alternative is substituted.
552 %{S:X; if S was given to GCC, substitutes X;
553 T:Y; else if T was given to GCC, substitutes Y;
554 :D} else substitutes D. There can be as many clauses as you need.
555 This may be combined with '.', '!', ',', '|', and '*' as above.
557 %(Spec) processes a specification defined in a specs file as *Spec:
558 %[Spec] as above, but put __ around -D arguments
560 The conditional text X in a %{S:X} or similar construct may contain
561 other nested % constructs or spaces, or even newlines. They are
562 processed as usual, as described above. Trailing white space in X is
563 ignored. White space may also appear anywhere on the left side of the
564 colon in these constructs, except between . or * and the corresponding
565 word.
567 The -O, -f, -m, and -W switches are handled specifically in these
568 constructs. If another value of -O or the negated form of a -f, -m, or
569 -W switch is found later in the command line, the earlier switch
570 value is ignored, except with {S*} where S is just one letter; this
571 passes all matching options.
573 The character | at the beginning of the predicate text is used to indicate
574 that a command should be piped to the following command, but only if -pipe
575 is specified.
577 Note that it is built into GCC which switches take arguments and which
578 do not. You might think it would be useful to generalize this to
579 allow each compiler's spec to say which switches take arguments. But
580 this cannot be done in a consistent fashion. GCC cannot even decide
581 which input files have been specified without knowing which switches
582 take arguments, and it must know which input files to compile in order
583 to tell which compilers to run.
585 GCC also knows implicitly that arguments starting in `-l' are to be
586 treated as compiler output files, and passed to the linker in their
587 proper position among the other output files. */
589 /* Define the macros used for specs %a, %l, %L, %S, %C, %1. */
591 /* config.h can define ASM_SPEC to provide extra args to the assembler
592 or extra switch-translations. */
593 #ifndef ASM_SPEC
594 #define ASM_SPEC ""
595 #endif
597 /* config.h can define ASM_FINAL_SPEC to run a post processor after
598 the assembler has run. */
599 #ifndef ASM_FINAL_SPEC
600 #define ASM_FINAL_SPEC ""
601 #endif
603 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
604 or extra switch-translations. */
605 #ifndef CPP_SPEC
606 #define CPP_SPEC ""
607 #endif
609 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
610 or extra switch-translations. */
611 #ifndef CC1_SPEC
612 #define CC1_SPEC ""
613 #endif
615 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
616 or extra switch-translations. */
617 #ifndef CC1PLUS_SPEC
618 #define CC1PLUS_SPEC ""
619 #endif
621 /* config.h can define LINK_SPEC to provide extra args to the linker
622 or extra switch-translations. */
623 #ifndef LINK_SPEC
624 #define LINK_SPEC ""
625 #endif
627 /* config.h can define LIB_SPEC to override the default libraries. */
628 #ifndef LIB_SPEC
629 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
630 #endif
632 /* mudflap specs */
633 #ifndef MFWRAP_SPEC
634 /* XXX: valid only for GNU ld */
635 /* XXX: should exactly match hooks provided by libmudflap.a */
636 #define MFWRAP_SPEC " %{static: %{fmudflap|fmudflapth: \
637 --wrap=malloc --wrap=free --wrap=calloc --wrap=realloc\
638 --wrap=mmap --wrap=munmap --wrap=alloca\
639 } %{fmudflapth: --wrap=pthread_create\
640 }} %{fmudflap|fmudflapth: --wrap=main}"
641 #endif
642 #ifndef MFLIB_SPEC
643 #define MFLIB_SPEC "%{fmudflap|fmudflapth: -export-dynamic}"
644 #endif
646 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
647 included. */
648 #ifndef LIBGCC_SPEC
649 #if defined(REAL_LIBGCC_SPEC)
650 #define LIBGCC_SPEC REAL_LIBGCC_SPEC
651 #elif defined(LINK_LIBGCC_SPECIAL_1)
652 /* Have gcc do the search for libgcc.a. */
653 #define LIBGCC_SPEC "libgcc.a%s"
654 #else
655 #define LIBGCC_SPEC "-lgcc"
656 #endif
657 #endif
659 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
660 #ifndef STARTFILE_SPEC
661 #define STARTFILE_SPEC \
662 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
663 #endif
665 /* config.h can define SWITCHES_NEED_SPACES to control which options
666 require spaces between the option and the argument. */
667 #ifndef SWITCHES_NEED_SPACES
668 #define SWITCHES_NEED_SPACES ""
669 #endif
671 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
672 #ifndef ENDFILE_SPEC
673 #define ENDFILE_SPEC ""
674 #endif
676 #ifndef LINKER_NAME
677 #define LINKER_NAME "collect2"
678 #endif
680 #ifdef HAVE_AS_DEBUG_PREFIX_MAP
681 #define ASM_MAP " %{fdebug-prefix-map=*:--debug-prefix-map %*}"
682 #else
683 #define ASM_MAP ""
684 #endif
686 /* Define ASM_DEBUG_SPEC to be a spec suitable for translating '-g'
687 to the assembler. */
688 #ifndef ASM_DEBUG_SPEC
689 # if defined(DBX_DEBUGGING_INFO) && defined(DWARF2_DEBUGGING_INFO) \
690 && defined(HAVE_AS_GDWARF2_DEBUG_FLAG) && defined(HAVE_AS_GSTABS_DEBUG_FLAG)
691 # define ASM_DEBUG_SPEC \
692 (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG \
693 ? "%{!g0:%{gdwarf-2*:--gdwarf2}%{!gdwarf-2*:%{g*:--gstabs}}}" ASM_MAP \
694 : "%{!g0:%{gstabs*:--gstabs}%{!gstabs*:%{g*:--gdwarf2}}}" ASM_MAP)
695 # else
696 # if defined(DBX_DEBUGGING_INFO) && defined(HAVE_AS_GSTABS_DEBUG_FLAG)
697 # define ASM_DEBUG_SPEC "%{g*:%{!g0:--gstabs}}" ASM_MAP
698 # endif
699 # if defined(DWARF2_DEBUGGING_INFO) && defined(HAVE_AS_GDWARF2_DEBUG_FLAG)
700 # define ASM_DEBUG_SPEC "%{g*:%{!g0:--gdwarf2}}" ASM_MAP
701 # endif
702 # endif
703 #endif
704 #ifndef ASM_DEBUG_SPEC
705 # define ASM_DEBUG_SPEC ""
706 #endif
708 /* Here is the spec for running the linker, after compiling all files. */
710 /* This is overridable by the target in case they need to specify the
711 -lgcc and -lc order specially, yet not require them to override all
712 of LINK_COMMAND_SPEC. */
713 #ifndef LINK_GCC_C_SEQUENCE_SPEC
714 #define LINK_GCC_C_SEQUENCE_SPEC "%G %L %G"
715 #endif
717 #ifndef LINK_SSP_SPEC
718 #ifdef TARGET_LIBC_PROVIDES_SSP
719 #define LINK_SSP_SPEC "%{fstack-protector:}"
720 #else
721 #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all:-lssp_nonshared -lssp}"
722 #endif
723 #endif
725 #ifndef LINK_PIE_SPEC
726 #ifdef HAVE_LD_PIE
727 #define LINK_PIE_SPEC "%{pie:-pie} "
728 #else
729 #define LINK_PIE_SPEC "%{pie:} "
730 #endif
731 #endif
733 #ifndef LINK_BUILDID_SPEC
734 # if defined(HAVE_LD_BUILDID) && defined(ENABLE_LD_BUILDID)
735 # define LINK_BUILDID_SPEC "%{!r:--build-id} "
736 # endif
737 #endif
740 /* -u* was put back because both BSD and SysV seem to support it. */
741 /* %{static:} simply prevents an error message if the target machine
742 doesn't handle -static. */
743 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
744 scripts which exist in user specified directories, or in standard
745 directories. */
746 #ifndef LINK_COMMAND_SPEC
747 #define LINK_COMMAND_SPEC "\
748 %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
749 %(linker) %l " LINK_PIE_SPEC "%X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r}\
750 %{s} %{t} %{u*} %{x} %{z} %{Z} %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
751 %{static:} %{L*} %(mfwrap) %(link_libgcc) %o\
752 %{fopenmp|ftree-parallelize-loops=*:%:include(libgomp.spec)%(link_gomp)} %(mflib)\
753 %{fprofile-arcs|fprofile-generate*|coverage:-lgcov}\
754 %{!nostdlib:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}\
755 %{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} }}}}}}"
756 #endif
758 #ifndef LINK_LIBGCC_SPEC
759 /* Generate -L options for startfile prefix list. */
760 # define LINK_LIBGCC_SPEC "%D"
761 #endif
763 #ifndef STARTFILE_PREFIX_SPEC
764 # define STARTFILE_PREFIX_SPEC ""
765 #endif
767 #ifndef SYSROOT_SPEC
768 # define SYSROOT_SPEC "--sysroot=%R"
769 #endif
771 #ifndef SYSROOT_SUFFIX_SPEC
772 # define SYSROOT_SUFFIX_SPEC ""
773 #endif
775 #ifndef SYSROOT_HEADERS_SUFFIX_SPEC
776 # define SYSROOT_HEADERS_SUFFIX_SPEC ""
777 #endif
779 static const char *asm_debug;
780 static const char *cpp_spec = CPP_SPEC;
781 static const char *cc1_spec = CC1_SPEC;
782 static const char *cc1plus_spec = CC1PLUS_SPEC;
783 static const char *link_gcc_c_sequence_spec = LINK_GCC_C_SEQUENCE_SPEC;
784 static const char *link_ssp_spec = LINK_SSP_SPEC;
785 static const char *asm_spec = ASM_SPEC;
786 static const char *asm_final_spec = ASM_FINAL_SPEC;
787 static const char *link_spec = LINK_SPEC;
788 static const char *lib_spec = LIB_SPEC;
789 static const char *mfwrap_spec = MFWRAP_SPEC;
790 static const char *mflib_spec = MFLIB_SPEC;
791 static const char *link_gomp_spec = "";
792 static const char *libgcc_spec = LIBGCC_SPEC;
793 static const char *endfile_spec = ENDFILE_SPEC;
794 static const char *startfile_spec = STARTFILE_SPEC;
795 static const char *switches_need_spaces = SWITCHES_NEED_SPACES;
796 static const char *linker_name_spec = LINKER_NAME;
797 static const char *link_command_spec = LINK_COMMAND_SPEC;
798 static const char *link_libgcc_spec = LINK_LIBGCC_SPEC;
799 static const char *startfile_prefix_spec = STARTFILE_PREFIX_SPEC;
800 static const char *sysroot_spec = SYSROOT_SPEC;
801 static const char *sysroot_suffix_spec = SYSROOT_SUFFIX_SPEC;
802 static const char *sysroot_hdrs_suffix_spec = SYSROOT_HEADERS_SUFFIX_SPEC;
804 /* Standard options to cpp, cc1, and as, to reduce duplication in specs.
805 There should be no need to override these in target dependent files,
806 but we need to copy them to the specs file so that newer versions
807 of the GCC driver can correctly drive older tool chains with the
808 appropriate -B options. */
810 /* When cpplib handles traditional preprocessing, get rid of this, and
811 call cc1 (or cc1obj in objc/lang-specs.h) from the main specs so
812 that we default the front end language better. */
813 static const char *trad_capable_cpp =
814 "cc1 -E %{traditional|ftraditional|traditional-cpp:-traditional-cpp}";
816 /* We don't wrap .d files in %W{} since a missing .d file, and
817 therefore no dependency entry, confuses make into thinking a .o
818 file that happens to exist is up-to-date. */
819 static const char *cpp_unique_options =
820 "%{C|CC:%{!E:%eGCC does not support -C or -CC without -E}}\
821 %{!Q:-quiet} %{nostdinc*} %{C} %{CC} %{v} %{I*&F*} %{P} %I\
822 %{MD:-MD %{!o:%b.d}%{o*:%.d%*}}\
823 %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}}\
824 %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\
825 %{!E:%{!M:%{!MM:%{!MT:%{!MQ:%{MD|MMD:%{o*:-MQ %*}}}}}}}\
826 %{remap} %{g3|ggdb3|gstabs3|gcoff3|gxcoff3|gvms3:-dD}\
827 %{H} %C %{D*&U*&A*} %{i*} %Z %i\
828 %{fmudflap:-D_MUDFLAP -include mf-runtime.h}\
829 %{fmudflapth:-D_MUDFLAP -D_MUDFLAPTH -include mf-runtime.h}\
830 %{E|M|MM:%W{o*}}";
832 /* This contains cpp options which are common with cc1_options and are passed
833 only when preprocessing only to avoid duplication. We pass the cc1 spec
834 options to the preprocessor so that it the cc1 spec may manipulate
835 options used to set target flags. Those special target flags settings may
836 in turn cause preprocessor symbols to be defined specially. */
837 static const char *cpp_options =
838 "%(cpp_unique_options) %1 %{m*} %{std*&ansi&trigraphs} %{W*&pedantic*} %{w}\
839 %{f*} %{g*:%{!g0:%{g*} %{!fno-working-directory:-fworking-directory}}} %{O*}\
840 %{undef} %{save-temps*:-fpch-preprocess}";
842 /* This contains cpp options which are not passed when the preprocessor
843 output will be used by another program. */
844 static const char *cpp_debug_options = "%{d*}";
846 /* NB: This is shared amongst all front-ends, except for Ada. */
847 static const char *cc1_options =
848 "%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
849 %1 %{!Q:-quiet} -dumpbase %B %{d*} %{m*} %{a*}\
850 %{c|S:%{o*:-auxbase-strip %*}%{!o*:-auxbase %b}}%{!c:%{!S:-auxbase %b}}\
851 %{g*} %{O*} %{W*&pedantic*} %{w} %{std*&ansi&trigraphs}\
852 %{v:-version} %{pg:-p} %{p} %{f*} %{undef}\
853 %{Qn:-fno-ident} %{--help:--help}\
854 %{--target-help:--target-help}\
855 %{--help=*:--help=%(VALUE)}\
856 %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %b.s}}}\
857 %{fsyntax-only:-o %j} %{-param*}\
858 %{fmudflap|fmudflapth:-fno-builtin -fno-merge-constants}\
859 %{coverage:-fprofile-arcs -ftest-coverage}";
861 static const char *asm_options =
862 "%{--target-help:%:print-asm-header()} "
863 #if HAVE_GNU_AS
864 /* If GNU AS is used, then convert -w (no warnings), -I, and -v
865 to the assembler equivalents. */
866 "%{v} %{w:-W} %{I*} "
867 #endif
868 "%a %Y %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}";
870 static const char *invoke_as =
871 #ifdef AS_NEEDS_DASH_FOR_PIPED_INPUT
872 "%{!S:-o %|.s |\n as %(asm_options) %|.s %A }";
873 #else
874 "%{!S:-o %|.s |\n as %(asm_options) %m.s %A }";
875 #endif
877 /* Some compilers have limits on line lengths, and the multilib_select
878 and/or multilib_matches strings can be very long, so we build them at
879 run time. */
880 static struct obstack multilib_obstack;
881 static const char *multilib_select;
882 static const char *multilib_matches;
883 static const char *multilib_defaults;
884 static const char *multilib_exclusions;
886 /* Check whether a particular argument is a default argument. */
888 #ifndef MULTILIB_DEFAULTS
889 #define MULTILIB_DEFAULTS { "" }
890 #endif
892 static const char *const multilib_defaults_raw[] = MULTILIB_DEFAULTS;
894 #ifndef DRIVER_SELF_SPECS
895 #define DRIVER_SELF_SPECS ""
896 #endif
898 /* Adding -fopenmp should imply pthreads. This is particularly important
899 for targets that use different start files and suchlike. */
900 #ifndef GOMP_SELF_SPECS
901 #define GOMP_SELF_SPECS "%{fopenmp|ftree-parallelize-loops=*: -pthread}"
902 #endif
904 static const char *const driver_self_specs[] = {
905 DRIVER_SELF_SPECS, GOMP_SELF_SPECS
908 #ifndef OPTION_DEFAULT_SPECS
909 #define OPTION_DEFAULT_SPECS { "", "" }
910 #endif
912 struct default_spec
914 const char *name;
915 const char *spec;
918 static const struct default_spec
919 option_default_specs[] = { OPTION_DEFAULT_SPECS };
921 struct user_specs
923 struct user_specs *next;
924 const char *filename;
927 static struct user_specs *user_specs_head, *user_specs_tail;
929 #ifndef SWITCH_TAKES_ARG
930 #define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
931 #endif
933 #ifndef WORD_SWITCH_TAKES_ARG
934 #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
935 #endif
937 #ifdef HAVE_TARGET_EXECUTABLE_SUFFIX
938 /* This defines which switches stop a full compilation. */
939 #define DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR) \
940 ((CHAR) == 'c' || (CHAR) == 'S')
942 #ifndef SWITCH_CURTAILS_COMPILATION
943 #define SWITCH_CURTAILS_COMPILATION(CHAR) \
944 DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR)
945 #endif
946 #endif
948 /* Record the mapping from file suffixes for compilation specs. */
950 struct compiler
952 const char *suffix; /* Use this compiler for input files
953 whose names end in this suffix. */
955 const char *spec; /* To use this compiler, run this spec. */
957 const char *cpp_spec; /* If non-NULL, substitute this spec
958 for `%C', rather than the usual
959 cpp_spec. */
960 const int combinable; /* If nonzero, compiler can deal with
961 multiple source files at once (IMA). */
962 const int needs_preprocessing; /* If nonzero, source files need to
963 be run through a preprocessor. */
966 /* Pointer to a vector of `struct compiler' that gives the spec for
967 compiling a file, based on its suffix.
968 A file that does not end in any of these suffixes will be passed
969 unchanged to the loader and nothing else will be done to it.
971 An entry containing two 0s is used to terminate the vector.
973 If multiple entries match a file, the last matching one is used. */
975 static struct compiler *compilers;
977 /* Number of entries in `compilers', not counting the null terminator. */
979 static int n_compilers;
981 /* The default list of file name suffixes and their compilation specs. */
983 static const struct compiler default_compilers[] =
985 /* Add lists of suffixes of known languages here. If those languages
986 were not present when we built the driver, we will hit these copies
987 and be given a more meaningful error than "file not used since
988 linking is not done". */
989 {".m", "#Objective-C", 0, 0, 0}, {".mi", "#Objective-C", 0, 0, 0},
990 {".mm", "#Objective-C++", 0, 0, 0}, {".M", "#Objective-C++", 0, 0, 0},
991 {".mii", "#Objective-C++", 0, 0, 0},
992 {".cc", "#C++", 0, 0, 0}, {".cxx", "#C++", 0, 0, 0},
993 {".cpp", "#C++", 0, 0, 0}, {".cp", "#C++", 0, 0, 0},
994 {".c++", "#C++", 0, 0, 0}, {".C", "#C++", 0, 0, 0},
995 {".CPP", "#C++", 0, 0, 0}, {".ii", "#C++", 0, 0, 0},
996 {".ads", "#Ada", 0, 0, 0}, {".adb", "#Ada", 0, 0, 0},
997 {".f", "#Fortran", 0, 0, 0}, {".F", "#Fortran", 0, 0, 0},
998 {".for", "#Fortran", 0, 0, 0}, {".FOR", "#Fortran", 0, 0, 0},
999 {".ftn", "#Fortran", 0, 0, 0}, {".FTN", "#Fortran", 0, 0, 0},
1000 {".fpp", "#Fortran", 0, 0, 0}, {".FPP", "#Fortran", 0, 0, 0},
1001 {".f90", "#Fortran", 0, 0, 0}, {".F90", "#Fortran", 0, 0, 0},
1002 {".f95", "#Fortran", 0, 0, 0}, {".F95", "#Fortran", 0, 0, 0},
1003 {".f03", "#Fortran", 0, 0, 0}, {".F03", "#Fortran", 0, 0, 0},
1004 {".f08", "#Fortran", 0, 0, 0}, {".F08", "#Fortran", 0, 0, 0},
1005 {".r", "#Ratfor", 0, 0, 0},
1006 {".p", "#Pascal", 0, 0, 0}, {".pas", "#Pascal", 0, 0, 0},
1007 {".java", "#Java", 0, 0, 0}, {".class", "#Java", 0, 0, 0},
1008 {".zip", "#Java", 0, 0, 0}, {".jar", "#Java", 0, 0, 0},
1009 /* Next come the entries for C. */
1010 {".c", "@c", 0, 1, 1},
1011 {"@c",
1012 /* cc1 has an integrated ISO C preprocessor. We should invoke the
1013 external preprocessor if -save-temps is given. */
1014 "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\
1015 %{!E:%{!M:%{!MM:\
1016 %{traditional|ftraditional:\
1017 %eGNU C no longer supports -traditional without -E}\
1018 %{!combine:\
1019 %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \
1020 %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\
1021 cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \
1022 %(cc1_options)}\
1023 %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\
1024 cc1 %(cpp_unique_options) %(cc1_options)}}}\
1025 %{!fsyntax-only:%(invoke_as)}} \
1026 %{combine:\
1027 %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \
1028 %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i}}\
1029 %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\
1030 cc1 %(cpp_unique_options) %(cc1_options)}}\
1031 %{!fsyntax-only:%(invoke_as)}}}}}}", 0, 1, 1},
1032 {"-",
1033 "%{!E:%e-E or -x required when input is from standard input}\
1034 %(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)", 0, 0, 0},
1035 {".h", "@c-header", 0, 0, 0},
1036 {"@c-header",
1037 /* cc1 has an integrated ISO C preprocessor. We should invoke the
1038 external preprocessor if -save-temps is given. */
1039 "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\
1040 %{!E:%{!M:%{!MM:\
1041 %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \
1042 %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\
1043 cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \
1044 %(cc1_options)\
1045 -o %g.s %{!o*:--output-pch=%i.gch}\
1046 %W{o*:--output-pch=%*}%V}\
1047 %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\
1048 cc1 %(cpp_unique_options) %(cc1_options)\
1049 -o %g.s %{!o*:--output-pch=%i.gch}\
1050 %W{o*:--output-pch=%*}%V}}}}}}", 0, 0, 0},
1051 {".i", "@cpp-output", 0, 1, 0},
1052 {"@cpp-output",
1053 "%{!M:%{!MM:%{!E:cc1 -fpreprocessed %i %(cc1_options) %{!fsyntax-only:%(invoke_as)}}}}", 0, 1, 0},
1054 {".s", "@assembler", 0, 1, 0},
1055 {"@assembler",
1056 "%{!M:%{!MM:%{!E:%{!S:as %(asm_debug) %(asm_options) %i %A }}}}", 0, 1, 0},
1057 {".sx", "@assembler-with-cpp", 0, 1, 0},
1058 {".S", "@assembler-with-cpp", 0, 1, 0},
1059 {"@assembler-with-cpp",
1060 #ifdef AS_NEEDS_DASH_FOR_PIPED_INPUT
1061 "%(trad_capable_cpp) -lang-asm %(cpp_options) -fno-directives-only\
1062 %{E|M|MM:%(cpp_debug_options)}\
1063 %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\
1064 as %(asm_debug) %(asm_options) %|.s %A }}}}"
1065 #else
1066 "%(trad_capable_cpp) -lang-asm %(cpp_options) -fno-directives-only\
1067 %{E|M|MM:%(cpp_debug_options)}\
1068 %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\
1069 as %(asm_debug) %(asm_options) %m.s %A }}}}"
1070 #endif
1071 , 0, 1, 0},
1073 #include "specs.h"
1074 /* Mark end of table. */
1075 {0, 0, 0, 0, 0}
1078 /* Number of elements in default_compilers, not counting the terminator. */
1080 static const int n_default_compilers = ARRAY_SIZE (default_compilers) - 1;
1082 /* A vector of options to give to the linker.
1083 These options are accumulated by %x,
1084 and substituted into the linker command with %X. */
1085 static int n_linker_options;
1086 static char **linker_options;
1088 /* A vector of options to give to the assembler.
1089 These options are accumulated by -Wa,
1090 and substituted into the assembler command with %Y. */
1091 static int n_assembler_options;
1092 static char **assembler_options;
1094 /* A vector of options to give to the preprocessor.
1095 These options are accumulated by -Wp,
1096 and substituted into the preprocessor command with %Z. */
1097 static int n_preprocessor_options;
1098 static char **preprocessor_options;
1100 /* Define how to map long options into short ones. */
1102 /* This structure describes one mapping. */
1103 struct option_map
1105 /* The long option's name. */
1106 const char *const name;
1107 /* The equivalent short option. */
1108 const char *const equivalent;
1109 /* Argument info. A string of flag chars; NULL equals no options.
1110 a => argument required.
1111 o => argument optional.
1112 j => join argument to equivalent, making one word.
1113 * => require other text after NAME as an argument. */
1114 const char *const arg_info;
1117 /* This is the table of mappings. Mappings are tried sequentially
1118 for each option encountered; the first one that matches, wins. */
1120 static const struct option_map option_map[] =
1122 {"--all-warnings", "-Wall", 0},
1123 {"--ansi", "-ansi", 0},
1124 {"--assemble", "-S", 0},
1125 {"--assert", "-A", "a"},
1126 {"--classpath", "-fclasspath=", "aj"},
1127 {"--bootclasspath", "-fbootclasspath=", "aj"},
1128 {"--CLASSPATH", "-fclasspath=", "aj"},
1129 {"--combine", "-combine", 0},
1130 {"--comments", "-C", 0},
1131 {"--comments-in-macros", "-CC", 0},
1132 {"--compile", "-c", 0},
1133 {"--debug", "-g", "oj"},
1134 {"--define-macro", "-D", "aj"},
1135 {"--dependencies", "-M", 0},
1136 {"--dump", "-d", "a"},
1137 {"--dumpbase", "-dumpbase", "a"},
1138 {"--encoding", "-fencoding=", "aj"},
1139 {"--entry", "-e", 0},
1140 {"--extra-warnings", "-W", 0},
1141 {"--extdirs", "-fextdirs=", "aj"},
1142 {"--for-assembler", "-Wa", "a"},
1143 {"--for-linker", "-Xlinker", "a"},
1144 {"--force-link", "-u", "a"},
1145 {"--coverage", "-coverage", 0},
1146 {"--imacros", "-imacros", "a"},
1147 {"--include", "-include", "a"},
1148 {"--include-barrier", "-I-", 0},
1149 {"--include-directory", "-I", "aj"},
1150 {"--include-directory-after", "-idirafter", "a"},
1151 {"--include-prefix", "-iprefix", "a"},
1152 {"--include-with-prefix", "-iwithprefix", "a"},
1153 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
1154 {"--include-with-prefix-after", "-iwithprefix", "a"},
1155 {"--language", "-x", "a"},
1156 {"--library-directory", "-L", "a"},
1157 {"--machine", "-m", "aj"},
1158 {"--machine-", "-m", "*j"},
1159 {"--no-integrated-cpp", "-no-integrated-cpp", 0},
1160 {"--no-line-commands", "-P", 0},
1161 {"--no-precompiled-includes", "-noprecomp", 0},
1162 {"--no-standard-includes", "-nostdinc", 0},
1163 {"--no-standard-libraries", "-nostdlib", 0},
1164 {"--no-warnings", "-w", 0},
1165 {"--optimize", "-O", "oj"},
1166 {"--output", "-o", "a"},
1167 {"--output-class-directory", "-foutput-class-dir=", "ja"},
1168 {"--param", "--param", "a"},
1169 {"--pass-exit-codes", "-pass-exit-codes", 0},
1170 {"--pedantic", "-pedantic", 0},
1171 {"--pedantic-errors", "-pedantic-errors", 0},
1172 {"--pie", "-pie", 0},
1173 {"--pipe", "-pipe", 0},
1174 {"--prefix", "-B", "a"},
1175 {"--preprocess", "-E", 0},
1176 {"--print-search-dirs", "-print-search-dirs", 0},
1177 {"--print-file-name", "-print-file-name=", "aj"},
1178 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
1179 {"--print-missing-file-dependencies", "-MG", 0},
1180 {"--print-multi-lib", "-print-multi-lib", 0},
1181 {"--print-multi-directory", "-print-multi-directory", 0},
1182 {"--print-multi-os-directory", "-print-multi-os-directory", 0},
1183 {"--print-prog-name", "-print-prog-name=", "aj"},
1184 {"--print-sysroot", "-print-sysroot", 0},
1185 {"--print-sysroot-headers-suffix", "-print-sysroot-headers-suffix", 0},
1186 {"--profile", "-p", 0},
1187 {"--profile-blocks", "-a", 0},
1188 {"--quiet", "-q", 0},
1189 {"--resource", "-fcompile-resource=", "aj"},
1190 {"--save-temps", "-save-temps", 0},
1191 {"--shared", "-shared", 0},
1192 {"--silent", "-q", 0},
1193 {"--specs", "-specs=", "aj"},
1194 {"--static", "-static", 0},
1195 {"--std", "-std=", "aj"},
1196 {"--symbolic", "-symbolic", 0},
1197 {"--sysroot", "--sysroot=", "aj"},
1198 {"--time", "-time", 0},
1199 {"--trace-includes", "-H", 0},
1200 {"--traditional", "-traditional", 0},
1201 {"--traditional-cpp", "-traditional-cpp", 0},
1202 {"--trigraphs", "-trigraphs", 0},
1203 {"--undefine-macro", "-U", "aj"},
1204 {"--user-dependencies", "-MM", 0},
1205 {"--verbose", "-v", 0},
1206 {"--warn-", "-W", "*j"},
1207 {"--write-dependencies", "-MD", 0},
1208 {"--write-user-dependencies", "-MMD", 0},
1209 {"--", "-f", "*j"}
1213 #ifdef TARGET_OPTION_TRANSLATE_TABLE
1214 static const struct {
1215 const char *const option_found;
1216 const char *const replacements;
1217 } target_option_translations[] =
1219 TARGET_OPTION_TRANSLATE_TABLE,
1220 { 0, 0 }
1222 #endif
1224 /* Translate the options described by *ARGCP and *ARGVP.
1225 Make a new vector and store it back in *ARGVP,
1226 and store its length in *ARGCP. */
1228 static void
1229 translate_options (int *argcp, const char *const **argvp)
1231 int i;
1232 int argc = *argcp;
1233 const char *const *argv = *argvp;
1234 int newvsize = (argc + 2) * 2 * sizeof (const char *);
1235 const char **newv = XNEWVAR (const char *, newvsize);
1236 int newindex = 0;
1238 i = 0;
1239 newv[newindex++] = argv[i++];
1241 while (i < argc)
1243 #ifdef TARGET_OPTION_TRANSLATE_TABLE
1244 int tott_idx;
1246 for (tott_idx = 0;
1247 target_option_translations[tott_idx].option_found;
1248 tott_idx++)
1250 if (strcmp (target_option_translations[tott_idx].option_found,
1251 argv[i]) == 0)
1253 int spaces = 1;
1254 const char *sp;
1255 char *np;
1257 for (sp = target_option_translations[tott_idx].replacements;
1258 *sp; sp++)
1260 if (*sp == ' ')
1261 spaces ++;
1264 newvsize += spaces * sizeof (const char *);
1265 newv = XRESIZEVAR (const char *, newv, newvsize);
1267 sp = target_option_translations[tott_idx].replacements;
1268 np = xstrdup (sp);
1270 while (1)
1272 while (*np == ' ')
1273 np++;
1274 if (*np == 0)
1275 break;
1276 newv[newindex++] = np;
1277 while (*np != ' ' && *np)
1278 np++;
1279 if (*np == 0)
1280 break;
1281 *np++ = 0;
1284 i ++;
1285 break;
1288 if (target_option_translations[tott_idx].option_found)
1289 continue;
1290 #endif
1292 /* Translate -- options. */
1293 if (argv[i][0] == '-' && argv[i][1] == '-')
1295 size_t j;
1296 /* Find a mapping that applies to this option. */
1297 for (j = 0; j < ARRAY_SIZE (option_map); j++)
1299 size_t optlen = strlen (option_map[j].name);
1300 size_t arglen = strlen (argv[i]);
1301 size_t complen = arglen > optlen ? optlen : arglen;
1302 const char *arginfo = option_map[j].arg_info;
1304 if (arginfo == 0)
1305 arginfo = "";
1307 if (!strncmp (argv[i], option_map[j].name, complen))
1309 const char *arg = 0;
1311 if (arglen < optlen)
1313 size_t k;
1314 for (k = j + 1; k < ARRAY_SIZE (option_map); k++)
1315 if (strlen (option_map[k].name) >= arglen
1316 && !strncmp (argv[i], option_map[k].name, arglen))
1318 error ("ambiguous abbreviation %s", argv[i]);
1319 break;
1322 if (k != ARRAY_SIZE (option_map))
1323 break;
1326 if (arglen > optlen)
1328 /* If the option has an argument, accept that. */
1329 if (argv[i][optlen] == '=')
1330 arg = argv[i] + optlen + 1;
1332 /* If this mapping requires extra text at end of name,
1333 accept that as "argument". */
1334 else if (strchr (arginfo, '*') != 0)
1335 arg = argv[i] + optlen;
1337 /* Otherwise, extra text at end means mismatch.
1338 Try other mappings. */
1339 else
1340 continue;
1343 else if (strchr (arginfo, '*') != 0)
1345 error ("incomplete '%s' option", option_map[j].name);
1346 break;
1349 /* Handle arguments. */
1350 if (strchr (arginfo, 'a') != 0)
1352 if (arg == 0)
1354 if (i + 1 == argc)
1356 error ("missing argument to '%s' option",
1357 option_map[j].name);
1358 break;
1361 arg = argv[++i];
1364 else if (strchr (arginfo, '*') != 0)
1366 else if (strchr (arginfo, 'o') == 0)
1368 if (arg != 0)
1369 error ("extraneous argument to '%s' option",
1370 option_map[j].name);
1371 arg = 0;
1374 /* Store the translation as one argv elt or as two. */
1375 if (arg != 0 && strchr (arginfo, 'j') != 0)
1376 newv[newindex++] = concat (option_map[j].equivalent, arg,
1377 NULL);
1378 else if (arg != 0)
1380 newv[newindex++] = option_map[j].equivalent;
1381 newv[newindex++] = arg;
1383 else
1384 newv[newindex++] = option_map[j].equivalent;
1386 break;
1389 i++;
1392 /* Handle old-fashioned options--just copy them through,
1393 with their arguments. */
1394 else if (argv[i][0] == '-')
1396 const char *p = argv[i] + 1;
1397 int c = *p;
1398 int nskip = 1;
1400 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
1401 nskip += SWITCH_TAKES_ARG (c) - (p[1] != 0);
1402 else if (WORD_SWITCH_TAKES_ARG (p))
1403 nskip += WORD_SWITCH_TAKES_ARG (p);
1404 else if ((c == 'B' || c == 'b' || c == 'x')
1405 && p[1] == 0)
1406 nskip += 1;
1407 else if (! strcmp (p, "Xlinker"))
1408 nskip += 1;
1409 else if (! strcmp (p, "Xpreprocessor"))
1410 nskip += 1;
1411 else if (! strcmp (p, "Xassembler"))
1412 nskip += 1;
1414 /* Watch out for an option at the end of the command line that
1415 is missing arguments, and avoid skipping past the end of the
1416 command line. */
1417 if (nskip + i > argc)
1418 nskip = argc - i;
1420 while (nskip > 0)
1422 newv[newindex++] = argv[i++];
1423 nskip--;
1426 else
1427 /* Ordinary operands, or +e options. */
1428 newv[newindex++] = argv[i++];
1431 newv[newindex] = 0;
1433 *argvp = newv;
1434 *argcp = newindex;
1437 static char *
1438 skip_whitespace (char *p)
1440 while (1)
1442 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1443 be considered whitespace. */
1444 if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n')
1445 return p + 1;
1446 else if (*p == '\n' || *p == ' ' || *p == '\t')
1447 p++;
1448 else if (*p == '#')
1450 while (*p != '\n')
1451 p++;
1452 p++;
1454 else
1455 break;
1458 return p;
1460 /* Structures to keep track of prefixes to try when looking for files. */
1462 struct prefix_list
1464 const char *prefix; /* String to prepend to the path. */
1465 struct prefix_list *next; /* Next in linked list. */
1466 int require_machine_suffix; /* Don't use without machine_suffix. */
1467 /* 2 means try both machine_suffix and just_machine_suffix. */
1468 int priority; /* Sort key - priority within list. */
1469 int os_multilib; /* 1 if OS multilib scheme should be used,
1470 0 for GCC multilib scheme. */
1473 struct path_prefix
1475 struct prefix_list *plist; /* List of prefixes to try */
1476 int max_len; /* Max length of a prefix in PLIST */
1477 const char *name; /* Name of this list (used in config stuff) */
1480 /* List of prefixes to try when looking for executables. */
1482 static struct path_prefix exec_prefixes = { 0, 0, "exec" };
1484 /* List of prefixes to try when looking for startup (crt0) files. */
1486 static struct path_prefix startfile_prefixes = { 0, 0, "startfile" };
1488 /* List of prefixes to try when looking for include files. */
1490 static struct path_prefix include_prefixes = { 0, 0, "include" };
1492 /* Suffix to attach to directories searched for commands.
1493 This looks like `MACHINE/VERSION/'. */
1495 static const char *machine_suffix = 0;
1497 /* Suffix to attach to directories searched for commands.
1498 This is just `MACHINE/'. */
1500 static const char *just_machine_suffix = 0;
1502 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1504 static const char *gcc_exec_prefix;
1506 /* Adjusted value of standard_libexec_prefix. */
1508 static const char *gcc_libexec_prefix;
1510 /* Default prefixes to attach to command names. */
1512 #ifndef STANDARD_STARTFILE_PREFIX_1
1513 #define STANDARD_STARTFILE_PREFIX_1 "/lib/"
1514 #endif
1515 #ifndef STANDARD_STARTFILE_PREFIX_2
1516 #define STANDARD_STARTFILE_PREFIX_2 "/usr/lib/"
1517 #endif
1519 #ifdef CROSS_DIRECTORY_STRUCTURE /* Don't use these prefixes for a cross compiler. */
1520 #undef MD_EXEC_PREFIX
1521 #undef MD_STARTFILE_PREFIX
1522 #undef MD_STARTFILE_PREFIX_1
1523 #endif
1525 /* If no prefixes defined, use the null string, which will disable them. */
1526 #ifndef MD_EXEC_PREFIX
1527 #define MD_EXEC_PREFIX ""
1528 #endif
1529 #ifndef MD_STARTFILE_PREFIX
1530 #define MD_STARTFILE_PREFIX ""
1531 #endif
1532 #ifndef MD_STARTFILE_PREFIX_1
1533 #define MD_STARTFILE_PREFIX_1 ""
1534 #endif
1536 /* These directories are locations set at configure-time based on the
1537 --prefix option provided to configure. Their initializers are
1538 defined in Makefile.in. These paths are not *directly* used when
1539 gcc_exec_prefix is set because, in that case, we know where the
1540 compiler has been installed, and use paths relative to that
1541 location instead. */
1542 static const char *const standard_exec_prefix = STANDARD_EXEC_PREFIX;
1543 static const char *const standard_libexec_prefix = STANDARD_LIBEXEC_PREFIX;
1544 static const char *const standard_bindir_prefix = STANDARD_BINDIR_PREFIX;
1545 static const char *const standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
1547 /* For native compilers, these are well-known paths containing
1548 components that may be provided by the system. For cross
1549 compilers, these paths are not used. */
1550 static const char *const standard_exec_prefix_1 = "/usr/libexec/gcc/";
1551 static const char *const standard_exec_prefix_2 = "/usr/lib/gcc/";
1552 static const char *md_exec_prefix = MD_EXEC_PREFIX;
1553 static const char *md_startfile_prefix = MD_STARTFILE_PREFIX;
1554 static const char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
1555 static const char *const standard_startfile_prefix_1
1556 = STANDARD_STARTFILE_PREFIX_1;
1557 static const char *const standard_startfile_prefix_2
1558 = STANDARD_STARTFILE_PREFIX_2;
1560 /* A relative path to be used in finding the location of tools
1561 relative to the driver. */
1562 static const char *const tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
1564 /* Subdirectory to use for locating libraries. Set by
1565 set_multilib_dir based on the compilation options. */
1567 static const char *multilib_dir;
1569 /* Subdirectory to use for locating libraries in OS conventions. Set by
1570 set_multilib_dir based on the compilation options. */
1572 static const char *multilib_os_dir;
1574 /* Structure to keep track of the specs that have been defined so far.
1575 These are accessed using %(specname) or %[specname] in a compiler
1576 or link spec. */
1578 struct spec_list
1580 /* The following 2 fields must be first */
1581 /* to allow EXTRA_SPECS to be initialized */
1582 const char *name; /* name of the spec. */
1583 const char *ptr; /* available ptr if no static pointer */
1585 /* The following fields are not initialized */
1586 /* by EXTRA_SPECS */
1587 const char **ptr_spec; /* pointer to the spec itself. */
1588 struct spec_list *next; /* Next spec in linked list. */
1589 int name_len; /* length of the name */
1590 int alloc_p; /* whether string was allocated */
1593 #define INIT_STATIC_SPEC(NAME,PTR) \
1594 { NAME, NULL, PTR, (struct spec_list *) 0, sizeof (NAME) - 1, 0 }
1596 /* List of statically defined specs. */
1597 static struct spec_list static_specs[] =
1599 INIT_STATIC_SPEC ("asm", &asm_spec),
1600 INIT_STATIC_SPEC ("asm_debug", &asm_debug),
1601 INIT_STATIC_SPEC ("asm_final", &asm_final_spec),
1602 INIT_STATIC_SPEC ("asm_options", &asm_options),
1603 INIT_STATIC_SPEC ("invoke_as", &invoke_as),
1604 INIT_STATIC_SPEC ("cpp", &cpp_spec),
1605 INIT_STATIC_SPEC ("cpp_options", &cpp_options),
1606 INIT_STATIC_SPEC ("cpp_debug_options", &cpp_debug_options),
1607 INIT_STATIC_SPEC ("cpp_unique_options", &cpp_unique_options),
1608 INIT_STATIC_SPEC ("trad_capable_cpp", &trad_capable_cpp),
1609 INIT_STATIC_SPEC ("cc1", &cc1_spec),
1610 INIT_STATIC_SPEC ("cc1_options", &cc1_options),
1611 INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec),
1612 INIT_STATIC_SPEC ("link_gcc_c_sequence", &link_gcc_c_sequence_spec),
1613 INIT_STATIC_SPEC ("link_ssp", &link_ssp_spec),
1614 INIT_STATIC_SPEC ("endfile", &endfile_spec),
1615 INIT_STATIC_SPEC ("link", &link_spec),
1616 INIT_STATIC_SPEC ("lib", &lib_spec),
1617 INIT_STATIC_SPEC ("mfwrap", &mfwrap_spec),
1618 INIT_STATIC_SPEC ("mflib", &mflib_spec),
1619 INIT_STATIC_SPEC ("link_gomp", &link_gomp_spec),
1620 INIT_STATIC_SPEC ("libgcc", &libgcc_spec),
1621 INIT_STATIC_SPEC ("startfile", &startfile_spec),
1622 INIT_STATIC_SPEC ("switches_need_spaces", &switches_need_spaces),
1623 INIT_STATIC_SPEC ("cross_compile", &cross_compile),
1624 INIT_STATIC_SPEC ("version", &compiler_version),
1625 INIT_STATIC_SPEC ("multilib", &multilib_select),
1626 INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults),
1627 INIT_STATIC_SPEC ("multilib_extra", &multilib_extra),
1628 INIT_STATIC_SPEC ("multilib_matches", &multilib_matches),
1629 INIT_STATIC_SPEC ("multilib_exclusions", &multilib_exclusions),
1630 INIT_STATIC_SPEC ("multilib_options", &multilib_options),
1631 INIT_STATIC_SPEC ("linker", &linker_name_spec),
1632 INIT_STATIC_SPEC ("link_libgcc", &link_libgcc_spec),
1633 INIT_STATIC_SPEC ("md_exec_prefix", &md_exec_prefix),
1634 INIT_STATIC_SPEC ("md_startfile_prefix", &md_startfile_prefix),
1635 INIT_STATIC_SPEC ("md_startfile_prefix_1", &md_startfile_prefix_1),
1636 INIT_STATIC_SPEC ("startfile_prefix_spec", &startfile_prefix_spec),
1637 INIT_STATIC_SPEC ("sysroot_spec", &sysroot_spec),
1638 INIT_STATIC_SPEC ("sysroot_suffix_spec", &sysroot_suffix_spec),
1639 INIT_STATIC_SPEC ("sysroot_hdrs_suffix_spec", &sysroot_hdrs_suffix_spec),
1642 #ifdef EXTRA_SPECS /* additional specs needed */
1643 /* Structure to keep track of just the first two args of a spec_list.
1644 That is all that the EXTRA_SPECS macro gives us. */
1645 struct spec_list_1
1647 const char *const name;
1648 const char *const ptr;
1651 static const struct spec_list_1 extra_specs_1[] = { EXTRA_SPECS };
1652 static struct spec_list *extra_specs = (struct spec_list *) 0;
1653 #endif
1655 /* List of dynamically allocates specs that have been defined so far. */
1657 static struct spec_list *specs = (struct spec_list *) 0;
1659 /* List of static spec functions. */
1661 static const struct spec_function static_spec_functions[] =
1663 { "getenv", getenv_spec_function },
1664 { "if-exists", if_exists_spec_function },
1665 { "if-exists-else", if_exists_else_spec_function },
1666 { "replace-outfile", replace_outfile_spec_function },
1667 { "version-compare", version_compare_spec_function },
1668 { "include", include_spec_function },
1669 { "print-asm-header", print_asm_header_spec_function },
1670 #ifdef EXTRA_SPEC_FUNCTIONS
1671 EXTRA_SPEC_FUNCTIONS
1672 #endif
1673 { 0, 0 }
1676 static int processing_spec_function;
1678 /* Add appropriate libgcc specs to OBSTACK, taking into account
1679 various permutations of -shared-libgcc, -shared, and such. */
1681 #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC)
1683 #ifndef USE_LD_AS_NEEDED
1684 #define USE_LD_AS_NEEDED 0
1685 #endif
1687 static void
1688 init_gcc_specs (struct obstack *obstack, const char *shared_name,
1689 const char *static_name, const char *eh_name)
1691 char *buf;
1693 buf = concat ("%{static|static-libgcc:", static_name, " ", eh_name, "}"
1694 "%{!static:%{!static-libgcc:"
1695 #if USE_LD_AS_NEEDED
1696 "%{!shared-libgcc:",
1697 static_name, " --as-needed ", shared_name, " --no-as-needed"
1699 "%{shared-libgcc:",
1700 shared_name, "%{!shared: ", static_name, "}"
1702 #else
1703 "%{!shared:"
1704 "%{!shared-libgcc:", static_name, " ", eh_name, "}"
1705 "%{shared-libgcc:", shared_name, " ", static_name, "}"
1707 #ifdef LINK_EH_SPEC
1708 "%{shared:"
1709 "%{shared-libgcc:", shared_name, "}"
1710 "%{!shared-libgcc:", static_name, "}"
1712 #else
1713 "%{shared:", shared_name, "}"
1714 #endif
1715 #endif
1716 "}}", NULL);
1718 obstack_grow (obstack, buf, strlen (buf));
1719 free (buf);
1721 #endif /* ENABLE_SHARED_LIBGCC */
1723 /* Initialize the specs lookup routines. */
1725 static void
1726 init_spec (void)
1728 struct spec_list *next = (struct spec_list *) 0;
1729 struct spec_list *sl = (struct spec_list *) 0;
1730 int i;
1732 if (specs)
1733 return; /* Already initialized. */
1735 if (verbose_flag)
1736 notice ("Using built-in specs.\n");
1738 #ifdef EXTRA_SPECS
1739 extra_specs = XCNEWVEC (struct spec_list, ARRAY_SIZE (extra_specs_1));
1741 for (i = ARRAY_SIZE (extra_specs_1) - 1; i >= 0; i--)
1743 sl = &extra_specs[i];
1744 sl->name = extra_specs_1[i].name;
1745 sl->ptr = extra_specs_1[i].ptr;
1746 sl->next = next;
1747 sl->name_len = strlen (sl->name);
1748 sl->ptr_spec = &sl->ptr;
1749 next = sl;
1751 #endif
1753 for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--)
1755 sl = &static_specs[i];
1756 sl->next = next;
1757 next = sl;
1760 #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC)
1761 /* ??? If neither -shared-libgcc nor --static-libgcc was
1762 seen, then we should be making an educated guess. Some proposed
1763 heuristics for ELF include:
1765 (1) If "-Wl,--export-dynamic", then it's a fair bet that the
1766 program will be doing dynamic loading, which will likely
1767 need the shared libgcc.
1769 (2) If "-ldl", then it's also a fair bet that we're doing
1770 dynamic loading.
1772 (3) For each ET_DYN we're linking against (either through -lfoo
1773 or /some/path/foo.so), check to see whether it or one of
1774 its dependencies depends on a shared libgcc.
1776 (4) If "-shared"
1778 If the runtime is fixed to look for program headers instead
1779 of calling __register_frame_info at all, for each object,
1780 use the shared libgcc if any EH symbol referenced.
1782 If crtstuff is fixed to not invoke __register_frame_info
1783 automatically, for each object, use the shared libgcc if
1784 any non-empty unwind section found.
1786 Doing any of this probably requires invoking an external program to
1787 do the actual object file scanning. */
1789 const char *p = libgcc_spec;
1790 int in_sep = 1;
1792 /* Transform the extant libgcc_spec into one that uses the shared libgcc
1793 when given the proper command line arguments. */
1794 while (*p)
1796 if (in_sep && *p == '-' && strncmp (p, "-lgcc", 5) == 0)
1798 init_gcc_specs (&obstack,
1799 "-lgcc_s"
1800 #ifdef USE_LIBUNWIND_EXCEPTIONS
1801 " -lunwind"
1802 #endif
1804 "-lgcc",
1805 "-lgcc_eh"
1806 #ifdef USE_LIBUNWIND_EXCEPTIONS
1807 # ifdef HAVE_LD_STATIC_DYNAMIC
1808 " %{!static:-Bstatic} -lunwind %{!static:-Bdynamic}"
1809 # else
1810 " -lunwind"
1811 # endif
1812 #endif
1815 p += 5;
1816 in_sep = 0;
1818 else if (in_sep && *p == 'l' && strncmp (p, "libgcc.a%s", 10) == 0)
1820 /* Ug. We don't know shared library extensions. Hope that
1821 systems that use this form don't do shared libraries. */
1822 init_gcc_specs (&obstack,
1823 "-lgcc_s",
1824 "libgcc.a%s",
1825 "libgcc_eh.a%s"
1826 #ifdef USE_LIBUNWIND_EXCEPTIONS
1827 " -lunwind"
1828 #endif
1830 p += 10;
1831 in_sep = 0;
1833 else
1835 obstack_1grow (&obstack, *p);
1836 in_sep = (*p == ' ');
1837 p += 1;
1841 obstack_1grow (&obstack, '\0');
1842 libgcc_spec = XOBFINISH (&obstack, const char *);
1844 #endif
1845 #ifdef USE_AS_TRADITIONAL_FORMAT
1846 /* Prepend "--traditional-format" to whatever asm_spec we had before. */
1848 static const char tf[] = "--traditional-format ";
1849 obstack_grow (&obstack, tf, sizeof(tf) - 1);
1850 obstack_grow0 (&obstack, asm_spec, strlen (asm_spec));
1851 asm_spec = XOBFINISH (&obstack, const char *);
1853 #endif
1855 #if defined LINK_EH_SPEC || defined LINK_BUILDID_SPEC
1856 # ifdef LINK_BUILDID_SPEC
1857 /* Prepend LINK_BUILDID_SPEC to whatever link_spec we had before. */
1858 obstack_grow (&obstack, LINK_BUILDID_SPEC, sizeof(LINK_BUILDID_SPEC) - 1);
1859 # endif
1860 # ifdef LINK_EH_SPEC
1861 /* Prepend LINK_EH_SPEC to whatever link_spec we had before. */
1862 obstack_grow (&obstack, LINK_EH_SPEC, sizeof(LINK_EH_SPEC) - 1);
1863 # endif
1864 obstack_grow0 (&obstack, link_spec, strlen (link_spec));
1865 link_spec = XOBFINISH (&obstack, const char *);
1866 #endif
1868 specs = sl;
1871 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1872 removed; If the spec starts with a + then SPEC is added to the end of the
1873 current spec. */
1875 static void
1876 set_spec (const char *name, const char *spec)
1878 struct spec_list *sl;
1879 const char *old_spec;
1880 int name_len = strlen (name);
1881 int i;
1883 /* If this is the first call, initialize the statically allocated specs. */
1884 if (!specs)
1886 struct spec_list *next = (struct spec_list *) 0;
1887 for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--)
1889 sl = &static_specs[i];
1890 sl->next = next;
1891 next = sl;
1893 specs = sl;
1896 /* See if the spec already exists. */
1897 for (sl = specs; sl; sl = sl->next)
1898 if (name_len == sl->name_len && !strcmp (sl->name, name))
1899 break;
1901 if (!sl)
1903 /* Not found - make it. */
1904 sl = XNEW (struct spec_list);
1905 sl->name = xstrdup (name);
1906 sl->name_len = name_len;
1907 sl->ptr_spec = &sl->ptr;
1908 sl->alloc_p = 0;
1909 *(sl->ptr_spec) = "";
1910 sl->next = specs;
1911 specs = sl;
1914 old_spec = *(sl->ptr_spec);
1915 *(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE ((unsigned char)spec[1]))
1916 ? concat (old_spec, spec + 1, NULL)
1917 : xstrdup (spec));
1919 #ifdef DEBUG_SPECS
1920 if (verbose_flag)
1921 notice ("Setting spec %s to '%s'\n\n", name, *(sl->ptr_spec));
1922 #endif
1924 /* Free the old spec. */
1925 if (old_spec && sl->alloc_p)
1926 free (CONST_CAST(char *, old_spec));
1928 sl->alloc_p = 1;
1931 /* Accumulate a command (program name and args), and run it. */
1933 /* Vector of pointers to arguments in the current line of specifications. */
1935 static const char **argbuf;
1937 /* Number of elements allocated in argbuf. */
1939 static int argbuf_length;
1941 /* Number of elements in argbuf currently in use (containing args). */
1943 static int argbuf_index;
1945 /* Position in the argbuf array containing the name of the output file
1946 (the value associated with the "-o" flag). */
1948 static int have_o_argbuf_index = 0;
1950 /* Were the options -c or -S passed. */
1951 static int have_c = 0;
1953 /* Was the option -o passed. */
1954 static int have_o = 0;
1956 /* This is the list of suffixes and codes (%g/%u/%U/%j) and the associated
1957 temp file. If the HOST_BIT_BUCKET is used for %j, no entry is made for
1958 it here. */
1960 static struct temp_name {
1961 const char *suffix; /* suffix associated with the code. */
1962 int length; /* strlen (suffix). */
1963 int unique; /* Indicates whether %g or %u/%U was used. */
1964 const char *filename; /* associated filename. */
1965 int filename_length; /* strlen (filename). */
1966 struct temp_name *next;
1967 } *temp_names;
1969 /* Number of commands executed so far. */
1971 static int execution_count;
1973 /* Number of commands that exited with a signal. */
1975 static int signal_count;
1977 /* Name with which this program was invoked. */
1979 static const char *programname;
1981 /* Allocate the argument vector. */
1983 static void
1984 alloc_args (void)
1986 argbuf_length = 10;
1987 argbuf = XNEWVEC (const char *, argbuf_length);
1990 /* Clear out the vector of arguments (after a command is executed). */
1992 static void
1993 clear_args (void)
1995 argbuf_index = 0;
1998 /* Add one argument to the vector at the end.
1999 This is done when a space is seen or at the end of the line.
2000 If DELETE_ALWAYS is nonzero, the arg is a filename
2001 and the file should be deleted eventually.
2002 If DELETE_FAILURE is nonzero, the arg is a filename
2003 and the file should be deleted if this compilation fails. */
2005 static void
2006 store_arg (const char *arg, int delete_always, int delete_failure)
2008 if (argbuf_index + 1 == argbuf_length)
2009 argbuf = XRESIZEVEC (const char *, argbuf, (argbuf_length *= 2));
2011 argbuf[argbuf_index++] = arg;
2012 argbuf[argbuf_index] = 0;
2014 if (strcmp (arg, "-o") == 0)
2015 have_o_argbuf_index = argbuf_index;
2016 if (delete_always || delete_failure)
2017 record_temp_file (arg, delete_always, delete_failure);
2020 /* Load specs from a file name named FILENAME, replacing occurrences of
2021 various different types of line-endings, \r\n, \n\r and just \r, with
2022 a single \n. */
2024 static char *
2025 load_specs (const char *filename)
2027 int desc;
2028 int readlen;
2029 struct stat statbuf;
2030 char *buffer;
2031 char *buffer_p;
2032 char *specs;
2033 char *specs_p;
2035 if (verbose_flag)
2036 notice ("Reading specs from %s\n", filename);
2038 /* Open and stat the file. */
2039 desc = open (filename, O_RDONLY, 0);
2040 if (desc < 0)
2041 pfatal_with_name (filename);
2042 if (stat (filename, &statbuf) < 0)
2043 pfatal_with_name (filename);
2045 /* Read contents of file into BUFFER. */
2046 buffer = XNEWVEC (char, statbuf.st_size + 1);
2047 readlen = read (desc, buffer, (unsigned) statbuf.st_size);
2048 if (readlen < 0)
2049 pfatal_with_name (filename);
2050 buffer[readlen] = 0;
2051 close (desc);
2053 specs = XNEWVEC (char, readlen + 1);
2054 specs_p = specs;
2055 for (buffer_p = buffer; buffer_p && *buffer_p; buffer_p++)
2057 int skip = 0;
2058 char c = *buffer_p;
2059 if (c == '\r')
2061 if (buffer_p > buffer && *(buffer_p - 1) == '\n') /* \n\r */
2062 skip = 1;
2063 else if (*(buffer_p + 1) == '\n') /* \r\n */
2064 skip = 1;
2065 else /* \r */
2066 c = '\n';
2068 if (! skip)
2069 *specs_p++ = c;
2071 *specs_p = '\0';
2073 free (buffer);
2074 return (specs);
2077 /* Read compilation specs from a file named FILENAME,
2078 replacing the default ones.
2080 A suffix which starts with `*' is a definition for
2081 one of the machine-specific sub-specs. The "suffix" should be
2082 *asm, *cc1, *cpp, *link, *startfile, etc.
2083 The corresponding spec is stored in asm_spec, etc.,
2084 rather than in the `compilers' vector.
2086 Anything invalid in the file is a fatal error. */
2088 static void
2089 read_specs (const char *filename, int main_p)
2091 char *buffer;
2092 char *p;
2094 buffer = load_specs (filename);
2096 /* Scan BUFFER for specs, putting them in the vector. */
2097 p = buffer;
2098 while (1)
2100 char *suffix;
2101 char *spec;
2102 char *in, *out, *p1, *p2, *p3;
2104 /* Advance P in BUFFER to the next nonblank nocomment line. */
2105 p = skip_whitespace (p);
2106 if (*p == 0)
2107 break;
2109 /* Is this a special command that starts with '%'? */
2110 /* Don't allow this for the main specs file, since it would
2111 encourage people to overwrite it. */
2112 if (*p == '%' && !main_p)
2114 p1 = p;
2115 while (*p && *p != '\n')
2116 p++;
2118 /* Skip '\n'. */
2119 p++;
2121 if (!strncmp (p1, "%include", sizeof ("%include") - 1)
2122 && (p1[sizeof "%include" - 1] == ' '
2123 || p1[sizeof "%include" - 1] == '\t'))
2125 char *new_filename;
2127 p1 += sizeof ("%include");
2128 while (*p1 == ' ' || *p1 == '\t')
2129 p1++;
2131 if (*p1++ != '<' || p[-2] != '>')
2132 fatal ("specs %%include syntax malformed after %ld characters",
2133 (long) (p1 - buffer + 1));
2135 p[-2] = '\0';
2136 new_filename = find_a_file (&startfile_prefixes, p1, R_OK, true);
2137 read_specs (new_filename ? new_filename : p1, FALSE);
2138 continue;
2140 else if (!strncmp (p1, "%include_noerr", sizeof "%include_noerr" - 1)
2141 && (p1[sizeof "%include_noerr" - 1] == ' '
2142 || p1[sizeof "%include_noerr" - 1] == '\t'))
2144 char *new_filename;
2146 p1 += sizeof "%include_noerr";
2147 while (*p1 == ' ' || *p1 == '\t')
2148 p1++;
2150 if (*p1++ != '<' || p[-2] != '>')
2151 fatal ("specs %%include syntax malformed after %ld characters",
2152 (long) (p1 - buffer + 1));
2154 p[-2] = '\0';
2155 new_filename = find_a_file (&startfile_prefixes, p1, R_OK, true);
2156 if (new_filename)
2157 read_specs (new_filename, FALSE);
2158 else if (verbose_flag)
2159 notice ("could not find specs file %s\n", p1);
2160 continue;
2162 else if (!strncmp (p1, "%rename", sizeof "%rename" - 1)
2163 && (p1[sizeof "%rename" - 1] == ' '
2164 || p1[sizeof "%rename" - 1] == '\t'))
2166 int name_len;
2167 struct spec_list *sl;
2168 struct spec_list *newsl;
2170 /* Get original name. */
2171 p1 += sizeof "%rename";
2172 while (*p1 == ' ' || *p1 == '\t')
2173 p1++;
2175 if (! ISALPHA ((unsigned char) *p1))
2176 fatal ("specs %%rename syntax malformed after %ld characters",
2177 (long) (p1 - buffer));
2179 p2 = p1;
2180 while (*p2 && !ISSPACE ((unsigned char) *p2))
2181 p2++;
2183 if (*p2 != ' ' && *p2 != '\t')
2184 fatal ("specs %%rename syntax malformed after %ld characters",
2185 (long) (p2 - buffer));
2187 name_len = p2 - p1;
2188 *p2++ = '\0';
2189 while (*p2 == ' ' || *p2 == '\t')
2190 p2++;
2192 if (! ISALPHA ((unsigned char) *p2))
2193 fatal ("specs %%rename syntax malformed after %ld characters",
2194 (long) (p2 - buffer));
2196 /* Get new spec name. */
2197 p3 = p2;
2198 while (*p3 && !ISSPACE ((unsigned char) *p3))
2199 p3++;
2201 if (p3 != p - 1)
2202 fatal ("specs %%rename syntax malformed after %ld characters",
2203 (long) (p3 - buffer));
2204 *p3 = '\0';
2206 for (sl = specs; sl; sl = sl->next)
2207 if (name_len == sl->name_len && !strcmp (sl->name, p1))
2208 break;
2210 if (!sl)
2211 fatal ("specs %s spec was not found to be renamed", p1);
2213 if (strcmp (p1, p2) == 0)
2214 continue;
2216 for (newsl = specs; newsl; newsl = newsl->next)
2217 if (strcmp (newsl->name, p2) == 0)
2218 fatal ("%s: attempt to rename spec '%s' to already defined spec '%s'",
2219 filename, p1, p2);
2221 if (verbose_flag)
2223 notice ("rename spec %s to %s\n", p1, p2);
2224 #ifdef DEBUG_SPECS
2225 notice ("spec is '%s'\n\n", *(sl->ptr_spec));
2226 #endif
2229 set_spec (p2, *(sl->ptr_spec));
2230 if (sl->alloc_p)
2231 free (CONST_CAST (char *, *(sl->ptr_spec)));
2233 *(sl->ptr_spec) = "";
2234 sl->alloc_p = 0;
2235 continue;
2237 else
2238 fatal ("specs unknown %% command after %ld characters",
2239 (long) (p1 - buffer));
2242 /* Find the colon that should end the suffix. */
2243 p1 = p;
2244 while (*p1 && *p1 != ':' && *p1 != '\n')
2245 p1++;
2247 /* The colon shouldn't be missing. */
2248 if (*p1 != ':')
2249 fatal ("specs file malformed after %ld characters",
2250 (long) (p1 - buffer));
2252 /* Skip back over trailing whitespace. */
2253 p2 = p1;
2254 while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t'))
2255 p2--;
2257 /* Copy the suffix to a string. */
2258 suffix = save_string (p, p2 - p);
2259 /* Find the next line. */
2260 p = skip_whitespace (p1 + 1);
2261 if (p[1] == 0)
2262 fatal ("specs file malformed after %ld characters",
2263 (long) (p - buffer));
2265 p1 = p;
2266 /* Find next blank line or end of string. */
2267 while (*p1 && !(*p1 == '\n' && (p1[1] == '\n' || p1[1] == '\0')))
2268 p1++;
2270 /* Specs end at the blank line and do not include the newline. */
2271 spec = save_string (p, p1 - p);
2272 p = p1;
2274 /* Delete backslash-newline sequences from the spec. */
2275 in = spec;
2276 out = spec;
2277 while (*in != 0)
2279 if (in[0] == '\\' && in[1] == '\n')
2280 in += 2;
2281 else if (in[0] == '#')
2282 while (*in && *in != '\n')
2283 in++;
2285 else
2286 *out++ = *in++;
2288 *out = 0;
2290 if (suffix[0] == '*')
2292 if (! strcmp (suffix, "*link_command"))
2293 link_command_spec = spec;
2294 else
2295 set_spec (suffix + 1, spec);
2297 else
2299 /* Add this pair to the vector. */
2300 compilers
2301 = XRESIZEVEC (struct compiler, compilers, n_compilers + 2);
2303 compilers[n_compilers].suffix = suffix;
2304 compilers[n_compilers].spec = spec;
2305 n_compilers++;
2306 memset (&compilers[n_compilers], 0, sizeof compilers[n_compilers]);
2309 if (*suffix == 0)
2310 link_command_spec = spec;
2313 if (link_command_spec == 0)
2314 fatal ("spec file has no spec for linking");
2317 /* Record the names of temporary files we tell compilers to write,
2318 and delete them at the end of the run. */
2320 /* This is the common prefix we use to make temp file names.
2321 It is chosen once for each run of this program.
2322 It is substituted into a spec by %g or %j.
2323 Thus, all temp file names contain this prefix.
2324 In practice, all temp file names start with this prefix.
2326 This prefix comes from the envvar TMPDIR if it is defined;
2327 otherwise, from the P_tmpdir macro if that is defined;
2328 otherwise, in /usr/tmp or /tmp;
2329 or finally the current directory if all else fails. */
2331 static const char *temp_filename;
2333 /* Length of the prefix. */
2335 static int temp_filename_length;
2337 /* Define the list of temporary files to delete. */
2339 struct temp_file
2341 const char *name;
2342 struct temp_file *next;
2345 /* Queue of files to delete on success or failure of compilation. */
2346 static struct temp_file *always_delete_queue;
2347 /* Queue of files to delete on failure of compilation. */
2348 static struct temp_file *failure_delete_queue;
2350 /* Record FILENAME as a file to be deleted automatically.
2351 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
2352 otherwise delete it in any case.
2353 FAIL_DELETE nonzero means delete it if a compilation step fails;
2354 otherwise delete it in any case. */
2356 void
2357 record_temp_file (const char *filename, int always_delete, int fail_delete)
2359 char *const name = xstrdup (filename);
2361 if (always_delete)
2363 struct temp_file *temp;
2364 for (temp = always_delete_queue; temp; temp = temp->next)
2365 if (! strcmp (name, temp->name))
2366 goto already1;
2368 temp = XNEW (struct temp_file);
2369 temp->next = always_delete_queue;
2370 temp->name = name;
2371 always_delete_queue = temp;
2373 already1:;
2376 if (fail_delete)
2378 struct temp_file *temp;
2379 for (temp = failure_delete_queue; temp; temp = temp->next)
2380 if (! strcmp (name, temp->name))
2381 goto already2;
2383 temp = XNEW (struct temp_file);
2384 temp->next = failure_delete_queue;
2385 temp->name = name;
2386 failure_delete_queue = temp;
2388 already2:;
2392 /* Delete all the temporary files whose names we previously recorded. */
2394 #ifndef DELETE_IF_ORDINARY
2395 #define DELETE_IF_ORDINARY(NAME,ST,VERBOSE_FLAG) \
2396 do \
2398 if (stat (NAME, &ST) >= 0 && S_ISREG (ST.st_mode)) \
2399 if (unlink (NAME) < 0) \
2400 if (VERBOSE_FLAG) \
2401 perror_with_name (NAME); \
2402 } while (0)
2403 #endif
2405 static void
2406 delete_if_ordinary (const char *name)
2408 struct stat st;
2409 #ifdef DEBUG
2410 int i, c;
2412 printf ("Delete %s? (y or n) ", name);
2413 fflush (stdout);
2414 i = getchar ();
2415 if (i != '\n')
2416 while ((c = getchar ()) != '\n' && c != EOF)
2419 if (i == 'y' || i == 'Y')
2420 #endif /* DEBUG */
2421 DELETE_IF_ORDINARY (name, st, verbose_flag);
2424 static void
2425 delete_temp_files (void)
2427 struct temp_file *temp;
2429 for (temp = always_delete_queue; temp; temp = temp->next)
2430 delete_if_ordinary (temp->name);
2431 always_delete_queue = 0;
2434 /* Delete all the files to be deleted on error. */
2436 static void
2437 delete_failure_queue (void)
2439 struct temp_file *temp;
2441 for (temp = failure_delete_queue; temp; temp = temp->next)
2442 delete_if_ordinary (temp->name);
2445 static void
2446 clear_failure_queue (void)
2448 failure_delete_queue = 0;
2451 /* Call CALLBACK for each path in PATHS, breaking out early if CALLBACK
2452 returns non-NULL.
2453 If DO_MULTI is true iterate over the paths twice, first with multilib
2454 suffix then without, otherwise iterate over the paths once without
2455 adding a multilib suffix. When DO_MULTI is true, some attempt is made
2456 to avoid visiting the same path twice, but we could do better. For
2457 instance, /usr/lib/../lib is considered different from /usr/lib.
2458 At least EXTRA_SPACE chars past the end of the path passed to
2459 CALLBACK are available for use by the callback.
2460 CALLBACK_INFO allows extra parameters to be passed to CALLBACK.
2462 Returns the value returned by CALLBACK. */
2464 static void *
2465 for_each_path (const struct path_prefix *paths,
2466 bool do_multi,
2467 size_t extra_space,
2468 void *(*callback) (char *, void *),
2469 void *callback_info)
2471 struct prefix_list *pl;
2472 const char *multi_dir = NULL;
2473 const char *multi_os_dir = NULL;
2474 const char *multi_suffix;
2475 const char *just_multi_suffix;
2476 char *path = NULL;
2477 void *ret = NULL;
2478 bool skip_multi_dir = false;
2479 bool skip_multi_os_dir = false;
2481 multi_suffix = machine_suffix;
2482 just_multi_suffix = just_machine_suffix;
2483 if (do_multi && multilib_dir && strcmp (multilib_dir, ".") != 0)
2485 multi_dir = concat (multilib_dir, dir_separator_str, NULL);
2486 multi_suffix = concat (multi_suffix, multi_dir, NULL);
2487 just_multi_suffix = concat (just_multi_suffix, multi_dir, NULL);
2489 if (do_multi && multilib_os_dir && strcmp (multilib_os_dir, ".") != 0)
2490 multi_os_dir = concat (multilib_os_dir, dir_separator_str, NULL);
2492 while (1)
2494 size_t multi_dir_len = 0;
2495 size_t multi_os_dir_len = 0;
2496 size_t suffix_len;
2497 size_t just_suffix_len;
2498 size_t len;
2500 if (multi_dir)
2501 multi_dir_len = strlen (multi_dir);
2502 if (multi_os_dir)
2503 multi_os_dir_len = strlen (multi_os_dir);
2504 suffix_len = strlen (multi_suffix);
2505 just_suffix_len = strlen (just_multi_suffix);
2507 if (path == NULL)
2509 len = paths->max_len + extra_space + 1;
2510 if (suffix_len > multi_os_dir_len)
2511 len += suffix_len;
2512 else
2513 len += multi_os_dir_len;
2514 path = XNEWVEC (char, len);
2517 for (pl = paths->plist; pl != 0; pl = pl->next)
2519 len = strlen (pl->prefix);
2520 memcpy (path, pl->prefix, len);
2522 /* Look first in MACHINE/VERSION subdirectory. */
2523 if (!skip_multi_dir)
2525 memcpy (path + len, multi_suffix, suffix_len + 1);
2526 ret = callback (path, callback_info);
2527 if (ret)
2528 break;
2531 /* Some paths are tried with just the machine (ie. target)
2532 subdir. This is used for finding as, ld, etc. */
2533 if (!skip_multi_dir
2534 && pl->require_machine_suffix == 2)
2536 memcpy (path + len, just_multi_suffix, just_suffix_len + 1);
2537 ret = callback (path, callback_info);
2538 if (ret)
2539 break;
2542 /* Now try the base path. */
2543 if (!pl->require_machine_suffix
2544 && !(pl->os_multilib ? skip_multi_os_dir : skip_multi_dir))
2546 const char *this_multi;
2547 size_t this_multi_len;
2549 if (pl->os_multilib)
2551 this_multi = multi_os_dir;
2552 this_multi_len = multi_os_dir_len;
2554 else
2556 this_multi = multi_dir;
2557 this_multi_len = multi_dir_len;
2560 if (this_multi_len)
2561 memcpy (path + len, this_multi, this_multi_len + 1);
2562 else
2563 path[len] = '\0';
2565 ret = callback (path, callback_info);
2566 if (ret)
2567 break;
2570 if (pl)
2571 break;
2573 if (multi_dir == NULL && multi_os_dir == NULL)
2574 break;
2576 /* Run through the paths again, this time without multilibs.
2577 Don't repeat any we have already seen. */
2578 if (multi_dir)
2580 free (CONST_CAST (char *, multi_dir));
2581 multi_dir = NULL;
2582 free (CONST_CAST (char *, multi_suffix));
2583 multi_suffix = machine_suffix;
2584 free (CONST_CAST (char *, just_multi_suffix));
2585 just_multi_suffix = just_machine_suffix;
2587 else
2588 skip_multi_dir = true;
2589 if (multi_os_dir)
2591 free (CONST_CAST (char *, multi_os_dir));
2592 multi_os_dir = NULL;
2594 else
2595 skip_multi_os_dir = true;
2598 if (multi_dir)
2600 free (CONST_CAST (char *, multi_dir));
2601 free (CONST_CAST (char *, multi_suffix));
2602 free (CONST_CAST (char *, just_multi_suffix));
2604 if (multi_os_dir)
2605 free (CONST_CAST (char *, multi_os_dir));
2606 if (ret != path)
2607 free (path);
2608 return ret;
2611 /* Callback for build_search_list. Adds path to obstack being built. */
2613 struct add_to_obstack_info {
2614 struct obstack *ob;
2615 bool check_dir;
2616 bool first_time;
2619 static void *
2620 add_to_obstack (char *path, void *data)
2622 struct add_to_obstack_info *info = (struct add_to_obstack_info *) data;
2624 if (info->check_dir && !is_directory (path, false))
2625 return NULL;
2627 if (!info->first_time)
2628 obstack_1grow (info->ob, PATH_SEPARATOR);
2630 obstack_grow (info->ob, path, strlen (path));
2632 info->first_time = false;
2633 return NULL;
2636 /* Add or change the value of an environment variable, outputting the
2637 change to standard error if in verbose mode. */
2638 static void
2639 xputenv (const char *string)
2641 if (verbose_flag)
2642 notice ("%s\n", string);
2643 putenv (CONST_CAST (char *, string));
2646 /* Build a list of search directories from PATHS.
2647 PREFIX is a string to prepend to the list.
2648 If CHECK_DIR_P is true we ensure the directory exists.
2649 If DO_MULTI is true, multilib paths are output first, then
2650 non-multilib paths.
2651 This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
2652 It is also used by the --print-search-dirs flag. */
2654 static char *
2655 build_search_list (const struct path_prefix *paths, const char *prefix,
2656 bool check_dir, bool do_multi)
2658 struct add_to_obstack_info info;
2660 info.ob = &collect_obstack;
2661 info.check_dir = check_dir;
2662 info.first_time = true;
2664 obstack_grow (&collect_obstack, prefix, strlen (prefix));
2665 obstack_1grow (&collect_obstack, '=');
2667 for_each_path (paths, do_multi, 0, add_to_obstack, &info);
2669 obstack_1grow (&collect_obstack, '\0');
2670 return XOBFINISH (&collect_obstack, char *);
2673 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
2674 for collect. */
2676 static void
2677 putenv_from_prefixes (const struct path_prefix *paths, const char *env_var,
2678 bool do_multi)
2680 xputenv (build_search_list (paths, env_var, true, do_multi));
2683 /* Check whether NAME can be accessed in MODE. This is like access,
2684 except that it never considers directories to be executable. */
2686 static int
2687 access_check (const char *name, int mode)
2689 if (mode == X_OK)
2691 struct stat st;
2693 if (stat (name, &st) < 0
2694 || S_ISDIR (st.st_mode))
2695 return -1;
2698 return access (name, mode);
2701 /* Callback for find_a_file. Appends the file name to the directory
2702 path. If the resulting file exists in the right mode, return the
2703 full pathname to the file. */
2705 struct file_at_path_info {
2706 const char *name;
2707 const char *suffix;
2708 int name_len;
2709 int suffix_len;
2710 int mode;
2713 static void *
2714 file_at_path (char *path, void *data)
2716 struct file_at_path_info *info = (struct file_at_path_info *) data;
2717 size_t len = strlen (path);
2719 memcpy (path + len, info->name, info->name_len);
2720 len += info->name_len;
2722 /* Some systems have a suffix for executable files.
2723 So try appending that first. */
2724 if (info->suffix_len)
2726 memcpy (path + len, info->suffix, info->suffix_len + 1);
2727 if (access_check (path, info->mode) == 0)
2728 return path;
2731 path[len] = '\0';
2732 if (access_check (path, info->mode) == 0)
2733 return path;
2735 return NULL;
2738 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
2739 access to check permissions. If DO_MULTI is true, search multilib
2740 paths then non-multilib paths, otherwise do not search multilib paths.
2741 Return 0 if not found, otherwise return its name, allocated with malloc. */
2743 static char *
2744 find_a_file (const struct path_prefix *pprefix, const char *name, int mode,
2745 bool do_multi)
2747 struct file_at_path_info info;
2749 #ifdef DEFAULT_ASSEMBLER
2750 if (! strcmp (name, "as") && access (DEFAULT_ASSEMBLER, mode) == 0)
2751 return xstrdup (DEFAULT_ASSEMBLER);
2752 #endif
2754 #ifdef DEFAULT_LINKER
2755 if (! strcmp(name, "ld") && access (DEFAULT_LINKER, mode) == 0)
2756 return xstrdup (DEFAULT_LINKER);
2757 #endif
2759 /* Determine the filename to execute (special case for absolute paths). */
2761 if (IS_ABSOLUTE_PATH (name))
2763 if (access (name, mode) == 0)
2764 return xstrdup (name);
2766 return NULL;
2769 info.name = name;
2770 info.suffix = (mode & X_OK) != 0 ? HOST_EXECUTABLE_SUFFIX : "";
2771 info.name_len = strlen (info.name);
2772 info.suffix_len = strlen (info.suffix);
2773 info.mode = mode;
2775 return (char*) for_each_path (pprefix, do_multi,
2776 info.name_len + info.suffix_len,
2777 file_at_path, &info);
2780 /* Ranking of prefixes in the sort list. -B prefixes are put before
2781 all others. */
2783 enum path_prefix_priority
2785 PREFIX_PRIORITY_B_OPT,
2786 PREFIX_PRIORITY_LAST
2789 /* Add an entry for PREFIX in PLIST. The PLIST is kept in ascending
2790 order according to PRIORITY. Within each PRIORITY, new entries are
2791 appended.
2793 If WARN is nonzero, we will warn if no file is found
2794 through this prefix. WARN should point to an int
2795 which will be set to 1 if this entry is used.
2797 COMPONENT is the value to be passed to update_path.
2799 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
2800 the complete value of machine_suffix.
2801 2 means try both machine_suffix and just_machine_suffix. */
2803 static void
2804 add_prefix (struct path_prefix *pprefix, const char *prefix,
2805 const char *component, /* enum prefix_priority */ int priority,
2806 int require_machine_suffix, int os_multilib)
2808 struct prefix_list *pl, **prev;
2809 int len;
2811 for (prev = &pprefix->plist;
2812 (*prev) != NULL && (*prev)->priority <= priority;
2813 prev = &(*prev)->next)
2816 /* Keep track of the longest prefix. */
2818 prefix = update_path (prefix, component);
2819 len = strlen (prefix);
2820 if (len > pprefix->max_len)
2821 pprefix->max_len = len;
2823 pl = XNEW (struct prefix_list);
2824 pl->prefix = prefix;
2825 pl->require_machine_suffix = require_machine_suffix;
2826 pl->priority = priority;
2827 pl->os_multilib = os_multilib;
2829 /* Insert after PREV. */
2830 pl->next = (*prev);
2831 (*prev) = pl;
2834 /* Same as add_prefix, but prepending target_system_root to prefix. */
2835 /* The target_system_root prefix has been relocated by gcc_exec_prefix. */
2836 static void
2837 add_sysrooted_prefix (struct path_prefix *pprefix, const char *prefix,
2838 const char *component,
2839 /* enum prefix_priority */ int priority,
2840 int require_machine_suffix, int os_multilib)
2842 if (!IS_ABSOLUTE_PATH (prefix))
2843 fatal ("system path '%s' is not absolute", prefix);
2845 if (target_system_root)
2847 if (target_sysroot_suffix)
2848 prefix = concat (target_sysroot_suffix, prefix, NULL);
2849 prefix = concat (target_system_root, prefix, NULL);
2851 /* We have to override this because GCC's notion of sysroot
2852 moves along with GCC. */
2853 component = "GCC";
2856 add_prefix (pprefix, prefix, component, priority,
2857 require_machine_suffix, os_multilib);
2860 /* Execute the command specified by the arguments on the current line of spec.
2861 When using pipes, this includes several piped-together commands
2862 with `|' between them.
2864 Return 0 if successful, -1 if failed. */
2866 static int
2867 execute (void)
2869 int i;
2870 int n_commands; /* # of command. */
2871 char *string;
2872 struct pex_obj *pex;
2873 struct command
2875 const char *prog; /* program name. */
2876 const char **argv; /* vector of args. */
2879 struct command *commands; /* each command buffer with above info. */
2881 gcc_assert (!processing_spec_function);
2883 if (wrapper_string)
2885 string = find_a_file (&exec_prefixes, argbuf[0], X_OK, false);
2886 argbuf[0] = (string) ? string : argbuf[0];
2887 insert_wrapper (wrapper_string);
2890 /* Count # of piped commands. */
2891 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2892 if (strcmp (argbuf[i], "|") == 0)
2893 n_commands++;
2895 /* Get storage for each command. */
2896 commands = (struct command *) alloca (n_commands * sizeof (struct command));
2898 /* Split argbuf into its separate piped processes,
2899 and record info about each one.
2900 Also search for the programs that are to be run. */
2902 commands[0].prog = argbuf[0]; /* first command. */
2903 commands[0].argv = &argbuf[0];
2905 if (!wrapper_string)
2907 string = find_a_file (&exec_prefixes, commands[0].prog, X_OK, false);
2908 commands[0].argv[0] = (string) ? string : commands[0].argv[0];
2911 for (n_commands = 1, i = 0; i < argbuf_index; i++)
2912 if (strcmp (argbuf[i], "|") == 0)
2913 { /* each command. */
2914 #if defined (__MSDOS__) || defined (OS2) || defined (VMS)
2915 fatal ("-pipe not supported");
2916 #endif
2917 argbuf[i] = 0; /* termination of command args. */
2918 commands[n_commands].prog = argbuf[i + 1];
2919 commands[n_commands].argv = &argbuf[i + 1];
2920 string = find_a_file (&exec_prefixes, commands[n_commands].prog,
2921 X_OK, false);
2922 if (string)
2923 commands[n_commands].argv[0] = string;
2924 n_commands++;
2927 argbuf[argbuf_index] = 0;
2929 /* If -v, print what we are about to do, and maybe query. */
2931 if (verbose_flag)
2933 /* For help listings, put a blank line between sub-processes. */
2934 if (print_help_list)
2935 fputc ('\n', stderr);
2937 /* Print each piped command as a separate line. */
2938 for (i = 0; i < n_commands; i++)
2940 const char *const *j;
2942 if (verbose_only_flag)
2944 for (j = commands[i].argv; *j; j++)
2946 const char *p;
2947 fprintf (stderr, " \"");
2948 for (p = *j; *p; ++p)
2950 if (*p == '"' || *p == '\\' || *p == '$')
2951 fputc ('\\', stderr);
2952 fputc (*p, stderr);
2954 fputc ('"', stderr);
2957 else
2958 for (j = commands[i].argv; *j; j++)
2959 fprintf (stderr, " %s", *j);
2961 /* Print a pipe symbol after all but the last command. */
2962 if (i + 1 != n_commands)
2963 fprintf (stderr, " |");
2964 fprintf (stderr, "\n");
2966 fflush (stderr);
2967 if (verbose_only_flag != 0)
2969 /* verbose_only_flag should act as if the spec was
2970 executed, so increment execution_count before
2971 returning. This prevents spurious warnings about
2972 unused linker input files, etc. */
2973 execution_count++;
2974 return 0;
2976 #ifdef DEBUG
2977 notice ("\nGo ahead? (y or n) ");
2978 fflush (stderr);
2979 i = getchar ();
2980 if (i != '\n')
2981 while (getchar () != '\n')
2984 if (i != 'y' && i != 'Y')
2985 return 0;
2986 #endif /* DEBUG */
2989 #ifdef ENABLE_VALGRIND_CHECKING
2990 /* Run the each command through valgrind. To simplify prepending the
2991 path to valgrind and the option "-q" (for quiet operation unless
2992 something triggers), we allocate a separate argv array. */
2994 for (i = 0; i < n_commands; i++)
2996 const char **argv;
2997 int argc;
2998 int j;
3000 for (argc = 0; commands[i].argv[argc] != NULL; argc++)
3003 argv = XALLOCAVEC (const char *, argc + 3);
3005 argv[0] = VALGRIND_PATH;
3006 argv[1] = "-q";
3007 for (j = 2; j < argc + 2; j++)
3008 argv[j] = commands[i].argv[j - 2];
3009 argv[j] = NULL;
3011 commands[i].argv = argv;
3012 commands[i].prog = argv[0];
3014 #endif
3016 /* Run each piped subprocess. */
3018 pex = pex_init (PEX_USE_PIPES | (report_times ? PEX_RECORD_TIMES : 0),
3019 programname, temp_filename);
3020 if (pex == NULL)
3021 pfatal_with_name (_("pex_init failed"));
3023 for (i = 0; i < n_commands; i++)
3025 const char *errmsg;
3026 int err;
3027 const char *string = commands[i].argv[0];
3029 errmsg = pex_run (pex,
3030 ((i + 1 == n_commands ? PEX_LAST : 0)
3031 | (string == commands[i].prog ? PEX_SEARCH : 0)),
3032 string, CONST_CAST (char **, commands[i].argv),
3033 NULL, NULL, &err);
3034 if (errmsg != NULL)
3036 if (err == 0)
3037 fatal (errmsg);
3038 else
3040 errno = err;
3041 pfatal_with_name (errmsg);
3045 if (string != commands[i].prog)
3046 free (CONST_CAST (char *, string));
3049 execution_count++;
3051 /* Wait for all the subprocesses to finish. */
3054 int *statuses;
3055 struct pex_time *times = NULL;
3056 int ret_code = 0;
3058 statuses = (int *) alloca (n_commands * sizeof (int));
3059 if (!pex_get_status (pex, n_commands, statuses))
3060 pfatal_with_name (_("failed to get exit status"));
3062 if (report_times)
3064 times = (struct pex_time *) alloca (n_commands * sizeof (struct pex_time));
3065 if (!pex_get_times (pex, n_commands, times))
3066 pfatal_with_name (_("failed to get process times"));
3069 pex_free (pex);
3071 for (i = 0; i < n_commands; ++i)
3073 int status = statuses[i];
3075 if (WIFSIGNALED (status))
3077 #ifdef SIGPIPE
3078 /* SIGPIPE is a special case. It happens in -pipe mode
3079 when the compiler dies before the preprocessor is done,
3080 or the assembler dies before the compiler is done.
3081 There's generally been an error already, and this is
3082 just fallout. So don't generate another error unless
3083 we would otherwise have succeeded. */
3084 if (WTERMSIG (status) == SIGPIPE
3085 && (signal_count || greatest_status >= MIN_FATAL_STATUS))
3087 signal_count++;
3088 ret_code = -1;
3090 else
3091 #endif
3092 fatal_ice ("\
3093 Internal error: %s (program %s)\n\
3094 Please submit a full bug report.\n\
3095 See %s for instructions.",
3096 strsignal (WTERMSIG (status)), commands[i].prog,
3097 bug_report_url);
3099 else if (WIFEXITED (status)
3100 && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
3102 if (WEXITSTATUS (status) > greatest_status)
3103 greatest_status = WEXITSTATUS (status);
3104 ret_code = -1;
3107 if (report_times)
3109 struct pex_time *pt = &times[i];
3110 double ut, st;
3112 ut = ((double) pt->user_seconds
3113 + (double) pt->user_microseconds / 1.0e6);
3114 st = ((double) pt->system_seconds
3115 + (double) pt->system_microseconds / 1.0e6);
3117 if (ut + st != 0)
3118 notice ("# %s %.2f %.2f\n", commands[i].prog, ut, st);
3122 return ret_code;
3126 /* Find all the switches given to us
3127 and make a vector describing them.
3128 The elements of the vector are strings, one per switch given.
3129 If a switch uses following arguments, then the `part1' field
3130 is the switch itself and the `args' field
3131 is a null-terminated vector containing the following arguments.
3132 Bits in the `live_cond' field are:
3133 SWITCH_LIVE to indicate this switch is true in a conditional spec.
3134 SWITCH_FALSE to indicate this switch is overridden by a later switch.
3135 SWITCH_IGNORE to indicate this switch should be ignored (used in %<S).
3136 The `validated' field is nonzero if any spec has looked at this switch;
3137 if it remains zero at the end of the run, it must be meaningless. */
3139 #define SWITCH_LIVE 0x1
3140 #define SWITCH_FALSE 0x2
3141 #define SWITCH_IGNORE 0x4
3143 struct switchstr
3145 const char *part1;
3146 const char **args;
3147 unsigned int live_cond;
3148 unsigned char validated;
3149 unsigned char ordering;
3152 static struct switchstr *switches;
3154 static int n_switches;
3156 /* Language is one of three things:
3158 1) The name of a real programming language.
3159 2) NULL, indicating that no one has figured out
3160 what it is yet.
3161 3) '*', indicating that the file should be passed
3162 to the linker. */
3163 struct infile
3165 const char *name;
3166 const char *language;
3167 struct compiler *incompiler;
3168 bool compiled;
3169 bool preprocessed;
3172 /* Also a vector of input files specified. */
3174 static struct infile *infiles;
3176 int n_infiles;
3178 /* True if multiple input files are being compiled to a single
3179 assembly file. */
3181 static bool combine_inputs;
3183 /* This counts the number of libraries added by lang_specific_driver, so that
3184 we can tell if there were any user supplied any files or libraries. */
3186 static int added_libraries;
3188 /* And a vector of corresponding output files is made up later. */
3190 const char **outfiles;
3192 #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3194 /* Convert NAME to a new name if it is the standard suffix. DO_EXE
3195 is true if we should look for an executable suffix. DO_OBJ
3196 is true if we should look for an object suffix. */
3198 static const char *
3199 convert_filename (const char *name, int do_exe ATTRIBUTE_UNUSED,
3200 int do_obj ATTRIBUTE_UNUSED)
3202 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3203 int i;
3204 #endif
3205 int len;
3207 if (name == NULL)
3208 return NULL;
3210 len = strlen (name);
3212 #ifdef HAVE_TARGET_OBJECT_SUFFIX
3213 /* Convert x.o to x.obj if TARGET_OBJECT_SUFFIX is ".obj". */
3214 if (do_obj && len > 2
3215 && name[len - 2] == '.'
3216 && name[len - 1] == 'o')
3218 obstack_grow (&obstack, name, len - 2);
3219 obstack_grow0 (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX));
3220 name = XOBFINISH (&obstack, const char *);
3222 #endif
3224 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3225 /* If there is no filetype, make it the executable suffix (which includes
3226 the "."). But don't get confused if we have just "-o". */
3227 if (! do_exe || TARGET_EXECUTABLE_SUFFIX[0] == 0 || (len == 2 && name[0] == '-'))
3228 return name;
3230 for (i = len - 1; i >= 0; i--)
3231 if (IS_DIR_SEPARATOR (name[i]))
3232 break;
3234 for (i++; i < len; i++)
3235 if (name[i] == '.')
3236 return name;
3238 obstack_grow (&obstack, name, len);
3239 obstack_grow0 (&obstack, TARGET_EXECUTABLE_SUFFIX,
3240 strlen (TARGET_EXECUTABLE_SUFFIX));
3241 name = XOBFINISH (&obstack, const char *);
3242 #endif
3244 return name;
3246 #endif
3248 /* Display the command line switches accepted by gcc. */
3249 static void
3250 display_help (void)
3252 printf (_("Usage: %s [options] file...\n"), programname);
3253 fputs (_("Options:\n"), stdout);
3255 fputs (_(" -pass-exit-codes Exit with highest error code from a phase\n"), stdout);
3256 fputs (_(" --help Display this information\n"), stdout);
3257 fputs (_(" --target-help Display target specific command line options\n"), stdout);
3258 fputs (_(" --help={target|optimizers|warnings|params|[^]{joined|separate|undocumented}}[,...]\n"), stdout);
3259 fputs (_(" Display specific types of command line options\n"), stdout);
3260 if (! verbose_flag)
3261 fputs (_(" (Use '-v --help' to display command line options of sub-processes)\n"), stdout);
3262 fputs (_(" --version Display compiler version information\n"), stdout);
3263 fputs (_(" -dumpspecs Display all of the built in spec strings\n"), stdout);
3264 fputs (_(" -dumpversion Display the version of the compiler\n"), stdout);
3265 fputs (_(" -dumpmachine Display the compiler's target processor\n"), stdout);
3266 fputs (_(" -print-search-dirs Display the directories in the compiler's search path\n"), stdout);
3267 fputs (_(" -print-libgcc-file-name Display the name of the compiler's companion library\n"), stdout);
3268 fputs (_(" -print-file-name=<lib> Display the full path to library <lib>\n"), stdout);
3269 fputs (_(" -print-prog-name=<prog> Display the full path to compiler component <prog>\n"), stdout);
3270 fputs (_(" -print-multi-directory Display the root directory for versions of libgcc\n"), stdout);
3271 fputs (_("\
3272 -print-multi-lib Display the mapping between command line options and\n\
3273 multiple library search directories\n"), stdout);
3274 fputs (_(" -print-multi-os-directory Display the relative path to OS libraries\n"), stdout);
3275 fputs (_(" -print-sysroot Display the target libraries directory\n"), stdout);
3276 fputs (_(" -print-sysroot-headers-suffix Display the sysroot suffix used to find headers\n"), stdout);
3277 fputs (_(" -Wa,<options> Pass comma-separated <options> on to the assembler\n"), stdout);
3278 fputs (_(" -Wp,<options> Pass comma-separated <options> on to the preprocessor\n"), stdout);
3279 fputs (_(" -Wl,<options> Pass comma-separated <options> on to the linker\n"), stdout);
3280 fputs (_(" -Xassembler <arg> Pass <arg> on to the assembler\n"), stdout);
3281 fputs (_(" -Xpreprocessor <arg> Pass <arg> on to the preprocessor\n"), stdout);
3282 fputs (_(" -Xlinker <arg> Pass <arg> on to the linker\n"), stdout);
3283 fputs (_(" -combine Pass multiple source files to compiler at once\n"), stdout);
3284 fputs (_(" -save-temps Do not delete intermediate files\n"), stdout);
3285 fputs (_(" -save-temps=<arg> Do not delete intermediate files\n"), stdout);
3286 fputs (_(" -pipe Use pipes rather than intermediate files\n"), stdout);
3287 fputs (_(" -time Time the execution of each subprocess\n"), stdout);
3288 fputs (_(" -specs=<file> Override built-in specs with the contents of <file>\n"), stdout);
3289 fputs (_(" -std=<standard> Assume that the input sources are for <standard>\n"), stdout);
3290 fputs (_("\
3291 --sysroot=<directory> Use <directory> as the root directory for headers\n\
3292 and libraries\n"), stdout);
3293 fputs (_(" -B <directory> Add <directory> to the compiler's search paths\n"), stdout);
3294 fputs (_(" -b <machine> Run gcc for target <machine>, if installed\n"), stdout);
3295 fputs (_(" -V <version> Run gcc version number <version>, if installed\n"), stdout);
3296 fputs (_(" -v Display the programs invoked by the compiler\n"), stdout);
3297 fputs (_(" -### Like -v but options quoted and commands not executed\n"), stdout);
3298 fputs (_(" -E Preprocess only; do not compile, assemble or link\n"), stdout);
3299 fputs (_(" -S Compile only; do not assemble or link\n"), stdout);
3300 fputs (_(" -c Compile and assemble, but do not link\n"), stdout);
3301 fputs (_(" -o <file> Place the output into <file>\n"), stdout);
3302 fputs (_("\
3303 -x <language> Specify the language of the following input files\n\
3304 Permissible languages include: c c++ assembler none\n\
3305 'none' means revert to the default behavior of\n\
3306 guessing the language based on the file's extension\n\
3307 "), stdout);
3309 printf (_("\
3310 \nOptions starting with -g, -f, -m, -O, -W, or --param are automatically\n\
3311 passed on to the various sub-processes invoked by %s. In order to pass\n\
3312 other options on to these processes the -W<letter> options must be used.\n\
3313 "), programname);
3315 /* The rest of the options are displayed by invocations of the various
3316 sub-processes. */
3319 static void
3320 add_preprocessor_option (const char *option, int len)
3322 n_preprocessor_options++;
3324 if (! preprocessor_options)
3325 preprocessor_options = XNEWVEC (char *, n_preprocessor_options);
3326 else
3327 preprocessor_options = XRESIZEVEC (char *, preprocessor_options,
3328 n_preprocessor_options);
3330 preprocessor_options [n_preprocessor_options - 1] =
3331 save_string (option, len);
3334 static void
3335 add_assembler_option (const char *option, int len)
3337 n_assembler_options++;
3339 if (! assembler_options)
3340 assembler_options = XNEWVEC (char *, n_assembler_options);
3341 else
3342 assembler_options = XRESIZEVEC (char *, assembler_options,
3343 n_assembler_options);
3345 assembler_options [n_assembler_options - 1] = save_string (option, len);
3348 static void
3349 add_linker_option (const char *option, int len)
3351 n_linker_options++;
3353 if (! linker_options)
3354 linker_options = XNEWVEC (char *, n_linker_options);
3355 else
3356 linker_options = XRESIZEVEC (char *, linker_options, n_linker_options);
3358 linker_options [n_linker_options - 1] = save_string (option, len);
3361 /* Create the vector `switches' and its contents.
3362 Store its length in `n_switches'. */
3364 static void
3365 process_command (int argc, const char **argv)
3367 int i;
3368 const char *temp;
3369 char *temp1;
3370 const char *spec_lang = 0;
3371 int last_language_n_infiles;
3372 int lang_n_infiles = 0;
3373 #ifdef MODIFY_TARGET_NAME
3374 int is_modify_target_name;
3375 unsigned int j;
3376 #endif
3377 const char *tooldir_prefix;
3379 GET_ENVIRONMENT (gcc_exec_prefix, "GCC_EXEC_PREFIX");
3381 n_switches = 0;
3382 n_infiles = 0;
3383 added_libraries = 0;
3385 /* Figure compiler version from version string. */
3387 compiler_version = temp1 = xstrdup (version_string);
3389 for (; *temp1; ++temp1)
3391 if (*temp1 == ' ')
3393 *temp1 = '\0';
3394 break;
3398 /* If there is a -V or -b option (or both), process it now, before
3399 trying to interpret the rest of the command line.
3400 Use heuristic that all configuration names must have at least
3401 one dash '-'. This allows us to pass options starting with -b. */
3402 if (argc > 1 && argv[1][0] == '-'
3403 && (argv[1][1] == 'V'
3404 || (argv[1][1] == 'b'
3405 && (argv[1][2] == '\0'
3406 || NULL != strchr (argv[1] + 2, '-')))))
3408 const char *new_version = DEFAULT_TARGET_VERSION;
3409 const char *new_machine = DEFAULT_TARGET_MACHINE;
3410 const char *progname = argv[0];
3411 char **new_argv;
3412 char *new_argv0;
3413 int baselen;
3414 int status = 0;
3415 int err = 0;
3416 const char *errmsg;
3418 while (argc > 1 && argv[1][0] == '-'
3419 && (argv[1][1] == 'V'
3420 || (argv[1][1] == 'b'
3421 && (argv[1][2] == '\0'
3422 || NULL != strchr (argv[1] + 2, '-')))))
3424 char opt = argv[1][1];
3425 const char *arg;
3426 if (argv[1][2] != '\0')
3428 arg = argv[1] + 2;
3429 argc -= 1;
3430 argv += 1;
3432 else if (argc > 2)
3434 arg = argv[2];
3435 argc -= 2;
3436 argv += 2;
3438 else
3439 fatal ("'-%c' option must have argument", opt);
3440 if (opt == 'V')
3441 new_version = arg;
3442 else
3443 new_machine = arg;
3446 for (baselen = strlen (progname); baselen > 0; baselen--)
3447 if (IS_DIR_SEPARATOR (progname[baselen-1]))
3448 break;
3449 new_argv0 = XDUPVAR (char, progname, baselen,
3450 baselen + concat_length (new_version, new_machine,
3451 "-gcc-", NULL) + 1);
3452 strcpy (new_argv0 + baselen, new_machine);
3453 strcat (new_argv0, "-gcc-");
3454 strcat (new_argv0, new_version);
3456 new_argv = XDUPVEC (char *, argv, argc + 1);
3457 new_argv[0] = new_argv0;
3459 errmsg = pex_one (PEX_SEARCH, new_argv0, new_argv, progname, NULL,
3460 NULL, &status, &err);
3462 if (errmsg)
3464 if (err == 0)
3465 fatal ("couldn't run '%s': %s", new_argv0, errmsg);
3466 else
3467 fatal ("couldn't run '%s': %s: %s", new_argv0, errmsg,
3468 xstrerror (err));
3470 exit (status);
3473 /* Set up the default search paths. If there is no GCC_EXEC_PREFIX,
3474 see if we can create it from the pathname specified in argv[0]. */
3476 gcc_libexec_prefix = standard_libexec_prefix;
3477 #ifndef VMS
3478 /* FIXME: make_relative_prefix doesn't yet work for VMS. */
3479 if (!gcc_exec_prefix)
3481 gcc_exec_prefix = make_relative_prefix (argv[0], standard_bindir_prefix,
3482 standard_exec_prefix);
3483 gcc_libexec_prefix = make_relative_prefix (argv[0],
3484 standard_bindir_prefix,
3485 standard_libexec_prefix);
3486 if (gcc_exec_prefix)
3487 xputenv (concat ("GCC_EXEC_PREFIX=", gcc_exec_prefix, NULL));
3489 else
3491 /* make_relative_prefix requires a program name, but
3492 GCC_EXEC_PREFIX is typically a directory name with a trailing
3493 / (which is ignored by make_relative_prefix), so append a
3494 program name. */
3495 char *tmp_prefix = concat (gcc_exec_prefix, "gcc", NULL);
3496 gcc_libexec_prefix = make_relative_prefix (tmp_prefix,
3497 standard_exec_prefix,
3498 standard_libexec_prefix);
3500 /* The path is unrelocated, so fallback to the original setting. */
3501 if (!gcc_libexec_prefix)
3502 gcc_libexec_prefix = standard_libexec_prefix;
3504 free (tmp_prefix);
3506 #else
3507 #endif
3508 /* From this point onward, gcc_exec_prefix is non-null if the toolchain
3509 is relocated. The toolchain was either relocated using GCC_EXEC_PREFIX
3510 or an automatically created GCC_EXEC_PREFIX from argv[0]. */
3512 if (gcc_exec_prefix)
3514 int len = strlen (gcc_exec_prefix);
3516 if (len > (int) sizeof ("/lib/gcc/") - 1
3517 && (IS_DIR_SEPARATOR (gcc_exec_prefix[len-1])))
3519 temp = gcc_exec_prefix + len - sizeof ("/lib/gcc/") + 1;
3520 if (IS_DIR_SEPARATOR (*temp)
3521 && strncmp (temp + 1, "lib", 3) == 0
3522 && IS_DIR_SEPARATOR (temp[4])
3523 && strncmp (temp + 5, "gcc", 3) == 0)
3524 len -= sizeof ("/lib/gcc/") - 1;
3527 set_std_prefix (gcc_exec_prefix, len);
3528 add_prefix (&exec_prefixes, gcc_libexec_prefix, "GCC",
3529 PREFIX_PRIORITY_LAST, 0, 0);
3530 add_prefix (&startfile_prefixes, gcc_exec_prefix, "GCC",
3531 PREFIX_PRIORITY_LAST, 0, 0);
3534 /* COMPILER_PATH and LIBRARY_PATH have values
3535 that are lists of directory names with colons. */
3537 GET_ENVIRONMENT (temp, "COMPILER_PATH");
3538 if (temp)
3540 const char *startp, *endp;
3541 char *nstore = (char *) alloca (strlen (temp) + 3);
3543 startp = endp = temp;
3544 while (1)
3546 if (*endp == PATH_SEPARATOR || *endp == 0)
3548 strncpy (nstore, startp, endp - startp);
3549 if (endp == startp)
3550 strcpy (nstore, concat (".", dir_separator_str, NULL));
3551 else if (!IS_DIR_SEPARATOR (endp[-1]))
3553 nstore[endp - startp] = DIR_SEPARATOR;
3554 nstore[endp - startp + 1] = 0;
3556 else
3557 nstore[endp - startp] = 0;
3558 add_prefix (&exec_prefixes, nstore, 0,
3559 PREFIX_PRIORITY_LAST, 0, 0);
3560 add_prefix (&include_prefixes, nstore, 0,
3561 PREFIX_PRIORITY_LAST, 0, 0);
3562 if (*endp == 0)
3563 break;
3564 endp = startp = endp + 1;
3566 else
3567 endp++;
3571 GET_ENVIRONMENT (temp, LIBRARY_PATH_ENV);
3572 if (temp && *cross_compile == '0')
3574 const char *startp, *endp;
3575 char *nstore = (char *) alloca (strlen (temp) + 3);
3577 startp = endp = temp;
3578 while (1)
3580 if (*endp == PATH_SEPARATOR || *endp == 0)
3582 strncpy (nstore, startp, endp - startp);
3583 if (endp == startp)
3584 strcpy (nstore, concat (".", dir_separator_str, NULL));
3585 else if (!IS_DIR_SEPARATOR (endp[-1]))
3587 nstore[endp - startp] = DIR_SEPARATOR;
3588 nstore[endp - startp + 1] = 0;
3590 else
3591 nstore[endp - startp] = 0;
3592 add_prefix (&startfile_prefixes, nstore, NULL,
3593 PREFIX_PRIORITY_LAST, 0, 1);
3594 if (*endp == 0)
3595 break;
3596 endp = startp = endp + 1;
3598 else
3599 endp++;
3603 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
3604 GET_ENVIRONMENT (temp, "LPATH");
3605 if (temp && *cross_compile == '0')
3607 const char *startp, *endp;
3608 char *nstore = (char *) alloca (strlen (temp) + 3);
3610 startp = endp = temp;
3611 while (1)
3613 if (*endp == PATH_SEPARATOR || *endp == 0)
3615 strncpy (nstore, startp, endp - startp);
3616 if (endp == startp)
3617 strcpy (nstore, concat (".", dir_separator_str, NULL));
3618 else if (!IS_DIR_SEPARATOR (endp[-1]))
3620 nstore[endp - startp] = DIR_SEPARATOR;
3621 nstore[endp - startp + 1] = 0;
3623 else
3624 nstore[endp - startp] = 0;
3625 add_prefix (&startfile_prefixes, nstore, NULL,
3626 PREFIX_PRIORITY_LAST, 0, 1);
3627 if (*endp == 0)
3628 break;
3629 endp = startp = endp + 1;
3631 else
3632 endp++;
3636 /* Convert new-style -- options to old-style. */
3637 translate_options (&argc, (const char *const **) &argv);
3639 /* Do language-specific adjustment/addition of flags. */
3640 lang_specific_driver (&argc, (const char *const **) &argv, &added_libraries);
3642 /* Scan argv twice. Here, the first time, just count how many switches
3643 there will be in their vector, and how many input files in theirs.
3644 Here we also parse the switches that cc itself uses (e.g. -v). */
3646 for (i = 1; i < argc; i++)
3648 if (! strcmp (argv[i], "-dumpspecs"))
3650 struct spec_list *sl;
3651 init_spec ();
3652 for (sl = specs; sl; sl = sl->next)
3653 printf ("*%s:\n%s\n\n", sl->name, *(sl->ptr_spec));
3654 if (link_command_spec)
3655 printf ("*link_command:\n%s\n\n", link_command_spec);
3656 exit (0);
3658 else if (! strcmp (argv[i], "-dumpversion"))
3660 printf ("%s\n", spec_version);
3661 exit (0);
3663 else if (! strcmp (argv[i], "-dumpmachine"))
3665 printf ("%s\n", spec_machine);
3666 exit (0);
3668 else if (strcmp (argv[i], "-fversion") == 0)
3670 /* translate_options () has turned --version into -fversion. */
3671 print_version = 1;
3673 /* We will be passing a dummy file on to the sub-processes. */
3674 n_infiles++;
3675 n_switches++;
3677 /* CPP driver cannot obtain switch from cc1_options. */
3678 if (is_cpp_driver)
3679 add_preprocessor_option ("--version", strlen ("--version"));
3680 add_assembler_option ("--version", strlen ("--version"));
3681 add_linker_option ("--version", strlen ("--version"));
3683 else if (strcmp (argv[i], "-fhelp") == 0)
3685 /* translate_options () has turned --help into -fhelp. */
3686 print_help_list = 1;
3688 /* We will be passing a dummy file on to the sub-processes. */
3689 n_infiles++;
3690 n_switches++;
3692 /* CPP driver cannot obtain switch from cc1_options. */
3693 if (is_cpp_driver)
3694 add_preprocessor_option ("--help", 6);
3695 add_assembler_option ("--help", 6);
3696 add_linker_option ("--help", 6);
3698 else if (strncmp (argv[i], "-fhelp=", 7) == 0)
3700 /* translate_options () has turned --help into -fhelp. */
3701 print_subprocess_help = 2;
3703 /* We will be passing a dummy file on to the sub-processes. */
3704 n_infiles++;
3705 n_switches++;
3707 else if (strcmp (argv[i], "-ftarget-help") == 0)
3709 /* translate_options() has turned --target-help into -ftarget-help. */
3710 print_subprocess_help = 1;
3712 /* We will be passing a dummy file on to the sub-processes. */
3713 n_infiles++;
3714 n_switches++;
3716 /* CPP driver cannot obtain switch from cc1_options. */
3717 if (is_cpp_driver)
3718 add_preprocessor_option ("--target-help", 13);
3719 add_assembler_option ("--target-help", 13);
3720 add_linker_option ("--target-help", 13);
3722 else if (! strcmp (argv[i], "-pass-exit-codes"))
3724 pass_exit_codes = 1;
3725 n_switches++;
3727 else if (! strcmp (argv[i], "-print-search-dirs"))
3728 print_search_dirs = 1;
3729 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
3730 print_file_name = "libgcc.a";
3731 else if (! strncmp (argv[i], "-print-file-name=", 17))
3732 print_file_name = argv[i] + 17;
3733 else if (! strncmp (argv[i], "-print-prog-name=", 17))
3734 print_prog_name = argv[i] + 17;
3735 else if (! strcmp (argv[i], "-print-multi-lib"))
3736 print_multi_lib = 1;
3737 else if (! strcmp (argv[i], "-print-multi-directory"))
3738 print_multi_directory = 1;
3739 else if (! strcmp (argv[i], "-print-sysroot"))
3740 print_sysroot = 1;
3741 else if (! strcmp (argv[i], "-print-multi-os-directory"))
3742 print_multi_os_directory = 1;
3743 else if (! strcmp (argv[i], "-print-sysroot-headers-suffix"))
3744 print_sysroot_headers_suffix = 1;
3745 else if (! strncmp (argv[i], "-Wa,", 4))
3747 int prev, j;
3748 /* Pass the rest of this option to the assembler. */
3750 /* Split the argument at commas. */
3751 prev = 4;
3752 for (j = 4; argv[i][j]; j++)
3753 if (argv[i][j] == ',')
3755 add_assembler_option (argv[i] + prev, j - prev);
3756 prev = j + 1;
3759 /* Record the part after the last comma. */
3760 add_assembler_option (argv[i] + prev, j - prev);
3762 else if (! strncmp (argv[i], "-Wp,", 4))
3764 int prev, j;
3765 /* Pass the rest of this option to the preprocessor. */
3767 /* Split the argument at commas. */
3768 prev = 4;
3769 for (j = 4; argv[i][j]; j++)
3770 if (argv[i][j] == ',')
3772 add_preprocessor_option (argv[i] + prev, j - prev);
3773 prev = j + 1;
3776 /* Record the part after the last comma. */
3777 add_preprocessor_option (argv[i] + prev, j - prev);
3779 else if (argv[i][0] == '+' && argv[i][1] == 'e')
3780 /* The +e options to the C++ front-end. */
3781 n_switches++;
3782 else if (strncmp (argv[i], "-Wl,", 4) == 0)
3784 int j;
3785 /* Split the argument at commas. */
3786 for (j = 3; argv[i][j]; j++)
3787 n_infiles += (argv[i][j] == ',');
3789 else if (strcmp (argv[i], "-Xlinker") == 0)
3791 if (i + 1 == argc)
3792 fatal ("argument to '-Xlinker' is missing");
3794 n_infiles++;
3795 i++;
3797 else if (strcmp (argv[i], "-Xpreprocessor") == 0)
3799 if (i + 1 == argc)
3800 fatal ("argument to '-Xpreprocessor' is missing");
3802 add_preprocessor_option (argv[i+1], strlen (argv[i+1]));
3804 else if (strcmp (argv[i], "-Xassembler") == 0)
3806 if (i + 1 == argc)
3807 fatal ("argument to '-Xassembler' is missing");
3809 add_assembler_option (argv[i+1], strlen (argv[i+1]));
3811 else if (strcmp (argv[i], "-l") == 0)
3813 if (i + 1 == argc)
3814 fatal ("argument to '-l' is missing");
3816 n_infiles++;
3817 i++;
3819 else if (strncmp (argv[i], "-l", 2) == 0)
3820 n_infiles++;
3821 else if (strcmp (argv[i], "-save-temps") == 0)
3823 save_temps_flag = SAVE_TEMPS_CWD;
3824 n_switches++;
3826 else if (strncmp (argv[i], "-save-temps=", 12) == 0)
3828 n_switches++;
3829 if (strcmp (argv[i]+12, "cwd") == 0)
3830 save_temps_flag = SAVE_TEMPS_CWD;
3831 else if (strcmp (argv[i]+12, "obj") == 0
3832 || strcmp (argv[i]+12, "object") == 0)
3833 save_temps_flag = SAVE_TEMPS_OBJ;
3834 else
3835 fatal ("'%s' is an unknown -save-temps option", argv[i]);
3837 else if (strcmp (argv[i], "-combine") == 0)
3839 combine_flag = 1;
3840 n_switches++;
3842 else if (strcmp (argv[i], "-specs") == 0)
3844 struct user_specs *user = XNEW (struct user_specs);
3845 if (++i >= argc)
3846 fatal ("argument to '-specs' is missing");
3848 user->next = (struct user_specs *) 0;
3849 user->filename = argv[i];
3850 if (user_specs_tail)
3851 user_specs_tail->next = user;
3852 else
3853 user_specs_head = user;
3854 user_specs_tail = user;
3856 else if (strncmp (argv[i], "-specs=", 7) == 0)
3858 struct user_specs *user = XNEW (struct user_specs);
3859 if (strlen (argv[i]) == 7)
3860 fatal ("argument to '-specs=' is missing");
3862 user->next = (struct user_specs *) 0;
3863 user->filename = argv[i] + 7;
3864 if (user_specs_tail)
3865 user_specs_tail->next = user;
3866 else
3867 user_specs_head = user;
3868 user_specs_tail = user;
3870 else if (strcmp (argv[i], "-time") == 0)
3871 report_times = 1;
3872 else if (strcmp (argv[i], "-pipe") == 0)
3874 /* -pipe has to go into the switches array as well as
3875 setting a flag. */
3876 use_pipes = 1;
3877 n_switches++;
3879 else if (strcmp (argv[i], "-wrapper") == 0)
3881 if (++i >= argc)
3882 fatal ("argument to '-wrapper' is missing");
3884 wrapper_string = argv[i];
3885 n_switches++;
3886 n_switches++;
3888 else if (strcmp (argv[i], "-###") == 0)
3890 /* This is similar to -v except that there is no execution
3891 of the commands and the echoed arguments are quoted. It
3892 is intended for use in shell scripts to capture the
3893 driver-generated command line. */
3894 verbose_only_flag++;
3895 verbose_flag++;
3897 else if (argv[i][0] == '-' && argv[i][1] != 0)
3899 const char *p = &argv[i][1];
3900 int c = *p;
3902 switch (c)
3904 case 'b':
3905 if (p[1] && NULL == strchr (argv[i] + 2, '-'))
3906 goto normal_switch;
3908 /* Fall through. */
3909 case 'V':
3910 fatal ("'-%c' must come at the start of the command line", c);
3911 break;
3913 case 'B':
3915 const char *value;
3916 int len;
3918 if (p[1] == 0 && i + 1 == argc)
3919 fatal ("argument to '-B' is missing");
3920 if (p[1] == 0)
3921 value = argv[++i];
3922 else
3923 value = p + 1;
3925 len = strlen (value);
3927 /* Catch the case where the user has forgotten to append a
3928 directory separator to the path. Note, they may be using
3929 -B to add an executable name prefix, eg "i386-elf-", in
3930 order to distinguish between multiple installations of
3931 GCC in the same directory. Hence we must check to see
3932 if appending a directory separator actually makes a
3933 valid directory name. */
3934 if (! IS_DIR_SEPARATOR (value [len - 1])
3935 && is_directory (value, false))
3937 char *tmp = XNEWVEC (char, len + 2);
3938 strcpy (tmp, value);
3939 tmp[len] = DIR_SEPARATOR;
3940 tmp[++ len] = 0;
3941 value = tmp;
3944 add_prefix (&exec_prefixes, value, NULL,
3945 PREFIX_PRIORITY_B_OPT, 0, 0);
3946 add_prefix (&startfile_prefixes, value, NULL,
3947 PREFIX_PRIORITY_B_OPT, 0, 0);
3948 add_prefix (&include_prefixes, value, NULL,
3949 PREFIX_PRIORITY_B_OPT, 0, 0);
3950 n_switches++;
3952 break;
3954 case 'v': /* Print our subcommands and print versions. */
3955 n_switches++;
3956 /* If they do anything other than exactly `-v', don't set
3957 verbose_flag; rather, continue on to give the error. */
3958 if (p[1] != 0)
3959 break;
3960 verbose_flag++;
3961 break;
3963 case 'S':
3964 case 'c':
3965 if (p[1] == 0)
3967 have_c = 1;
3968 n_switches++;
3969 break;
3971 goto normal_switch;
3973 case 'o':
3974 have_o = 1;
3975 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3976 if (! have_c)
3978 int skip;
3980 /* Forward scan, just in case -S or -c is specified
3981 after -o. */
3982 int j = i + 1;
3983 if (p[1] == 0)
3984 ++j;
3985 while (j < argc)
3987 if (argv[j][0] == '-')
3989 if (SWITCH_CURTAILS_COMPILATION (argv[j][1])
3990 && argv[j][2] == 0)
3992 have_c = 1;
3993 break;
3995 else if ((skip = SWITCH_TAKES_ARG (argv[j][1])))
3996 j += skip - (argv[j][2] != 0);
3997 else if ((skip = WORD_SWITCH_TAKES_ARG (argv[j] + 1)))
3998 j += skip;
4000 j++;
4003 #endif
4004 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) || defined(HAVE_TARGET_OBJECT_SUFFIX)
4005 if (p[1] == 0)
4006 argv[i + 1] = convert_filename (argv[i + 1], ! have_c, 0);
4007 else
4008 argv[i] = convert_filename (argv[i], ! have_c, 0);
4009 #endif
4010 /* Save the output name in case -save-temps=obj was used. */
4011 save_temps_prefix = xstrdup ((p[1] == 0) ? argv[i + 1] : argv[i] + 1);
4012 goto normal_switch;
4014 default:
4015 normal_switch:
4017 #ifdef MODIFY_TARGET_NAME
4018 is_modify_target_name = 0;
4020 for (j = 0; j < ARRAY_SIZE (modify_target); j++)
4021 if (! strcmp (argv[i], modify_target[j].sw))
4023 char *new_name = XNEWVEC (char, strlen (modify_target[j].str)
4024 + strlen (spec_machine));
4025 const char *p, *r;
4026 char *q;
4027 int made_addition = 0;
4029 is_modify_target_name = 1;
4030 for (p = spec_machine, q = new_name; *p != 0; )
4032 if (modify_target[j].add_del == DELETE
4033 && (! strncmp (q, modify_target[j].str,
4034 strlen (modify_target[j].str))))
4035 p += strlen (modify_target[j].str);
4036 else if (modify_target[j].add_del == ADD
4037 && ! made_addition && *p == '-')
4039 for (r = modify_target[j].str; *r != 0; )
4040 *q++ = *r++;
4041 made_addition = 1;
4044 *q++ = *p++;
4047 spec_machine = new_name;
4050 if (is_modify_target_name)
4051 break;
4052 #endif
4054 n_switches++;
4056 if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
4057 i += SWITCH_TAKES_ARG (c) - (p[1] != 0);
4058 else if (WORD_SWITCH_TAKES_ARG (p))
4059 i += WORD_SWITCH_TAKES_ARG (p);
4062 else
4064 n_infiles++;
4065 lang_n_infiles++;
4069 /* If -save-temps=obj and -o name, create the prefix to use for %b.
4070 Otherwise just make -save-temps=obj the same as -save-temps=cwd. */
4071 if (save_temps_flag == SAVE_TEMPS_OBJ && save_temps_prefix != NULL)
4073 save_temps_length = strlen (save_temps_prefix);
4074 temp = strrchr (lbasename (save_temps_prefix), '.');
4075 if (temp)
4077 save_temps_length -= strlen (temp);
4078 save_temps_prefix[save_temps_length] = '\0';
4082 else if (save_temps_prefix != NULL)
4084 free (save_temps_prefix);
4085 save_temps_prefix = NULL;
4088 if (save_temps_flag && use_pipes)
4090 /* -save-temps overrides -pipe, so that temp files are produced */
4091 if (save_temps_flag)
4092 error ("warning: -pipe ignored because -save-temps specified");
4093 use_pipes = 0;
4096 /* Set up the search paths. We add directories that we expect to
4097 contain GNU Toolchain components before directories specified by
4098 the machine description so that we will find GNU components (like
4099 the GNU assembler) before those of the host system. */
4101 /* If we don't know where the toolchain has been installed, use the
4102 configured-in locations. */
4103 if (!gcc_exec_prefix)
4105 #ifndef OS2
4106 add_prefix (&exec_prefixes, standard_libexec_prefix, "GCC",
4107 PREFIX_PRIORITY_LAST, 1, 0);
4108 add_prefix (&exec_prefixes, standard_libexec_prefix, "BINUTILS",
4109 PREFIX_PRIORITY_LAST, 2, 0);
4110 add_prefix (&exec_prefixes, standard_exec_prefix, "BINUTILS",
4111 PREFIX_PRIORITY_LAST, 2, 0);
4112 #endif
4113 add_prefix (&startfile_prefixes, standard_exec_prefix, "BINUTILS",
4114 PREFIX_PRIORITY_LAST, 1, 0);
4117 /* If not cross-compiling, search well-known system locations. */
4118 if (*cross_compile == '0')
4120 #ifndef OS2
4121 add_prefix (&exec_prefixes, standard_exec_prefix_1, "BINUTILS",
4122 PREFIX_PRIORITY_LAST, 2, 0);
4123 add_prefix (&exec_prefixes, standard_exec_prefix_2, "BINUTILS",
4124 PREFIX_PRIORITY_LAST, 2, 0);
4125 #endif
4126 add_prefix (&startfile_prefixes, standard_exec_prefix_2, "BINUTILS",
4127 PREFIX_PRIORITY_LAST, 1, 0);
4130 gcc_assert (!IS_ABSOLUTE_PATH (tooldir_base_prefix));
4131 tooldir_prefix = concat (tooldir_base_prefix, spec_machine,
4132 dir_separator_str, NULL);
4134 /* Look for tools relative to the location from which the driver is
4135 running, or, if that is not available, the configured prefix. */
4136 tooldir_prefix
4137 = concat (gcc_exec_prefix ? gcc_exec_prefix : standard_exec_prefix,
4138 spec_machine, dir_separator_str,
4139 spec_version, dir_separator_str, tooldir_prefix, NULL);
4141 add_prefix (&exec_prefixes,
4142 concat (tooldir_prefix, "bin", dir_separator_str, NULL),
4143 "BINUTILS", PREFIX_PRIORITY_LAST, 0, 0);
4144 add_prefix (&startfile_prefixes,
4145 concat (tooldir_prefix, "lib", dir_separator_str, NULL),
4146 "BINUTILS", PREFIX_PRIORITY_LAST, 0, 1);
4148 #if defined(TARGET_SYSTEM_ROOT_RELOCATABLE) && !defined(VMS)
4149 /* If the normal TARGET_SYSTEM_ROOT is inside of $exec_prefix,
4150 then consider it to relocate with the rest of the GCC installation
4151 if GCC_EXEC_PREFIX is set.
4152 ``make_relative_prefix'' is not compiled for VMS, so don't call it. */
4153 if (target_system_root && gcc_exec_prefix)
4155 char *tmp_prefix = make_relative_prefix (argv[0],
4156 standard_bindir_prefix,
4157 target_system_root);
4158 if (tmp_prefix && access_check (tmp_prefix, F_OK) == 0)
4160 target_system_root = tmp_prefix;
4161 target_system_root_changed = 1;
4164 #endif
4166 /* More prefixes are enabled in main, after we read the specs file
4167 and determine whether this is cross-compilation or not. */
4169 /* Then create the space for the vectors and scan again. */
4171 switches = XNEWVEC (struct switchstr, n_switches + 1);
4172 infiles = XNEWVEC (struct infile, n_infiles + 1);
4173 n_switches = 0;
4174 n_infiles = 0;
4175 last_language_n_infiles = -1;
4177 /* This, time, copy the text of each switch and store a pointer
4178 to the copy in the vector of switches.
4179 Store all the infiles in their vector. */
4181 for (i = 1; i < argc; i++)
4183 /* Just skip the switches that were handled by the preceding loop. */
4184 #ifdef MODIFY_TARGET_NAME
4185 is_modify_target_name = 0;
4187 for (j = 0; j < ARRAY_SIZE (modify_target); j++)
4188 if (! strcmp (argv[i], modify_target[j].sw))
4189 is_modify_target_name = 1;
4191 if (is_modify_target_name)
4193 else
4194 #endif
4195 if (! strncmp (argv[i], "-Wa,", 4))
4197 else if (! strncmp (argv[i], "-Wp,", 4))
4199 else if (! strcmp (argv[i], "-pass-exit-codes"))
4201 else if (! strcmp (argv[i], "-print-search-dirs"))
4203 else if (! strcmp (argv[i], "-print-libgcc-file-name"))
4205 else if (! strncmp (argv[i], "-print-file-name=", 17))
4207 else if (! strncmp (argv[i], "-print-prog-name=", 17))
4209 else if (! strcmp (argv[i], "-print-multi-lib"))
4211 else if (! strcmp (argv[i], "-print-multi-directory"))
4213 else if (! strcmp (argv[i], "-print-sysroot"))
4215 else if (! strcmp (argv[i], "-print-multi-os-directory"))
4217 else if (! strcmp (argv[i], "-print-sysroot-headers-suffix"))
4219 else if (! strncmp (argv[i], "--sysroot=", strlen ("--sysroot=")))
4221 target_system_root = argv[i] + strlen ("--sysroot=");
4222 target_system_root_changed = 1;
4224 else if (argv[i][0] == '+' && argv[i][1] == 'e')
4226 /* Compensate for the +e options to the C++ front-end;
4227 they're there simply for cfront call-compatibility. We do
4228 some magic in default_compilers to pass them down properly.
4229 Note we deliberately start at the `+' here, to avoid passing
4230 -e0 or -e1 down into the linker. */
4231 switches[n_switches].part1 = &argv[i][0];
4232 switches[n_switches].args = 0;
4233 switches[n_switches].live_cond = 0;
4234 switches[n_switches].validated = 0;
4235 n_switches++;
4237 else if (strncmp (argv[i], "-Wl,", 4) == 0)
4239 int prev, j;
4240 /* Split the argument at commas. */
4241 prev = 4;
4242 for (j = 4; argv[i][j]; j++)
4243 if (argv[i][j] == ',')
4245 infiles[n_infiles].language = "*";
4246 infiles[n_infiles++].name
4247 = save_string (argv[i] + prev, j - prev);
4248 prev = j + 1;
4250 /* Record the part after the last comma. */
4251 infiles[n_infiles].language = "*";
4252 infiles[n_infiles++].name = argv[i] + prev;
4254 else if (strcmp (argv[i], "-Xlinker") == 0)
4256 infiles[n_infiles].language = "*";
4257 infiles[n_infiles++].name = argv[++i];
4259 /* Xassembler and Xpreprocessor were already handled in the first argv
4260 scan, so all we need to do here is ignore them and their argument. */
4261 else if (strcmp (argv[i], "-Xassembler") == 0)
4262 i++;
4263 else if (strcmp (argv[i], "-Xpreprocessor") == 0)
4264 i++;
4265 else if (strcmp (argv[i], "-l") == 0)
4266 { /* POSIX allows separation of -l and the lib arg;
4267 canonicalize by concatenating -l with its arg */
4268 infiles[n_infiles].language = "*";
4269 infiles[n_infiles++].name = concat ("-l", argv[++i], NULL);
4271 else if (strncmp (argv[i], "-l", 2) == 0)
4273 infiles[n_infiles].language = "*";
4274 infiles[n_infiles++].name = argv[i];
4276 else if (strcmp (argv[i], "-wrapper") == 0)
4277 i++;
4278 else if (strcmp (argv[i], "-specs") == 0)
4279 i++;
4280 else if (strncmp (argv[i], "-specs=", 7) == 0)
4282 else if (strcmp (argv[i], "-time") == 0)
4284 else if (strcmp (argv[i], "-###") == 0)
4286 else if (argv[i][0] == '-' && argv[i][1] != 0)
4288 const char *p = &argv[i][1];
4289 int c = *p;
4291 if (c == 'x')
4293 if (p[1] == 0 && i + 1 == argc)
4294 fatal ("argument to '-x' is missing");
4295 if (p[1] == 0)
4296 spec_lang = argv[++i];
4297 else
4298 spec_lang = p + 1;
4299 if (! strcmp (spec_lang, "none"))
4300 /* Suppress the warning if -xnone comes after the last input
4301 file, because alternate command interfaces like g++ might
4302 find it useful to place -xnone after each input file. */
4303 spec_lang = 0;
4304 else
4305 last_language_n_infiles = n_infiles;
4306 continue;
4308 switches[n_switches].part1 = p;
4309 /* Deal with option arguments in separate argv elements. */
4310 if ((SWITCH_TAKES_ARG (c) > (p[1] != 0))
4311 || WORD_SWITCH_TAKES_ARG (p))
4313 int j = 0;
4314 int n_args = WORD_SWITCH_TAKES_ARG (p);
4316 if (n_args == 0)
4318 /* Count only the option arguments in separate argv elements. */
4319 n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0);
4321 if (i + n_args >= argc)
4322 fatal ("argument to '-%s' is missing", p);
4323 switches[n_switches].args
4324 = XNEWVEC (const char *, n_args + 1);
4325 while (j < n_args)
4326 switches[n_switches].args[j++] = argv[++i];
4327 /* Null-terminate the vector. */
4328 switches[n_switches].args[j] = 0;
4330 else if (strchr (switches_need_spaces, c))
4332 /* On some systems, ld cannot handle some options without
4333 a space. So split the option from its argument. */
4334 char *part1 = XNEWVEC (char, 2);
4335 part1[0] = c;
4336 part1[1] = '\0';
4338 switches[n_switches].part1 = part1;
4339 switches[n_switches].args = XNEWVEC (const char *, 2);
4340 switches[n_switches].args[0] = xstrdup (p+1);
4341 switches[n_switches].args[1] = 0;
4343 else
4344 switches[n_switches].args = 0;
4346 switches[n_switches].live_cond = 0;
4347 switches[n_switches].validated = 0;
4348 switches[n_switches].ordering = 0;
4349 /* These are always valid, since gcc.c itself understands the
4350 first four and gfortranspec.c understands -static-libgfortran. */
4351 if (!strcmp (p, "save-temps")
4352 || !strcmp (p, "static-libgcc")
4353 || !strcmp (p, "shared-libgcc")
4354 || !strcmp (p, "pipe")
4355 || !strcmp (p, "static-libgfortran"))
4356 switches[n_switches].validated = 1;
4357 else
4359 char ch = switches[n_switches].part1[0];
4360 if (ch == 'B')
4361 switches[n_switches].validated = 1;
4363 n_switches++;
4365 else
4367 #ifdef HAVE_TARGET_OBJECT_SUFFIX
4368 argv[i] = convert_filename (argv[i], 0, access (argv[i], F_OK));
4369 #endif
4371 if (strcmp (argv[i], "-") != 0 && access (argv[i], F_OK) < 0)
4373 perror_with_name (argv[i]);
4374 error_count++;
4376 else
4378 infiles[n_infiles].language = spec_lang;
4379 infiles[n_infiles++].name = argv[i];
4384 if (n_infiles == last_language_n_infiles && spec_lang != 0)
4385 error ("warning: '-x %s' after last input file has no effect", spec_lang);
4387 /* Ensure we only invoke each subprocess once. */
4388 if (print_subprocess_help || print_help_list || print_version)
4390 n_infiles = 1;
4392 /* Create a dummy input file, so that we can pass
4393 the help option on to the various sub-processes. */
4394 infiles[0].language = "c";
4395 infiles[0].name = "help-dummy";
4398 switches[n_switches].part1 = 0;
4399 infiles[n_infiles].name = 0;
4402 /* Store switches not filtered out by %<S in spec in COLLECT_GCC_OPTIONS
4403 and place that in the environment. */
4405 static void
4406 set_collect_gcc_options (void)
4408 int i;
4409 int first_time;
4411 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4412 the compiler. */
4413 obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
4414 sizeof ("COLLECT_GCC_OPTIONS=") - 1);
4416 first_time = TRUE;
4417 for (i = 0; (int) i < n_switches; i++)
4419 const char *const *args;
4420 const char *p, *q;
4421 if (!first_time)
4422 obstack_grow (&collect_obstack, " ", 1);
4424 first_time = FALSE;
4426 /* Ignore elided switches. */
4427 if ((switches[i].live_cond & SWITCH_IGNORE) != 0)
4428 continue;
4430 obstack_grow (&collect_obstack, "'-", 2);
4431 q = switches[i].part1;
4432 while ((p = strchr (q, '\'')))
4434 obstack_grow (&collect_obstack, q, p - q);
4435 obstack_grow (&collect_obstack, "'\\''", 4);
4436 q = ++p;
4438 obstack_grow (&collect_obstack, q, strlen (q));
4439 obstack_grow (&collect_obstack, "'", 1);
4441 for (args = switches[i].args; args && *args; args++)
4443 obstack_grow (&collect_obstack, " '", 2);
4444 q = *args;
4445 while ((p = strchr (q, '\'')))
4447 obstack_grow (&collect_obstack, q, p - q);
4448 obstack_grow (&collect_obstack, "'\\''", 4);
4449 q = ++p;
4451 obstack_grow (&collect_obstack, q, strlen (q));
4452 obstack_grow (&collect_obstack, "'", 1);
4455 obstack_grow (&collect_obstack, "\0", 1);
4456 xputenv (XOBFINISH (&collect_obstack, char *));
4459 /* Process a spec string, accumulating and running commands. */
4461 /* These variables describe the input file name.
4462 input_file_number is the index on outfiles of this file,
4463 so that the output file name can be stored for later use by %o.
4464 input_basename is the start of the part of the input file
4465 sans all directory names, and basename_length is the number
4466 of characters starting there excluding the suffix .c or whatever. */
4468 static const char *input_filename;
4469 static int input_file_number;
4470 size_t input_filename_length;
4471 static int basename_length;
4472 static int suffixed_basename_length;
4473 static const char *input_basename;
4474 static const char *input_suffix;
4475 #ifndef HOST_LACKS_INODE_NUMBERS
4476 static struct stat input_stat;
4477 #endif
4478 static int input_stat_set;
4480 /* The compiler used to process the current input file. */
4481 static struct compiler *input_file_compiler;
4483 /* These are variables used within do_spec and do_spec_1. */
4485 /* Nonzero if an arg has been started and not yet terminated
4486 (with space, tab or newline). */
4487 static int arg_going;
4489 /* Nonzero means %d or %g has been seen; the next arg to be terminated
4490 is a temporary file name. */
4491 static int delete_this_arg;
4493 /* Nonzero means %w has been seen; the next arg to be terminated
4494 is the output file name of this compilation. */
4495 static int this_is_output_file;
4497 /* Nonzero means %s has been seen; the next arg to be terminated
4498 is the name of a library file and we should try the standard
4499 search dirs for it. */
4500 static int this_is_library_file;
4502 /* Nonzero means that the input of this command is coming from a pipe. */
4503 static int input_from_pipe;
4505 /* Nonnull means substitute this for any suffix when outputting a switches
4506 arguments. */
4507 static const char *suffix_subst;
4509 /* If there is an argument being accumulated, terminate it and store it. */
4511 static void
4512 end_going_arg (void)
4514 if (arg_going)
4516 const char *string;
4518 obstack_1grow (&obstack, 0);
4519 string = XOBFINISH (&obstack, const char *);
4520 if (this_is_library_file)
4521 string = find_file (string);
4522 store_arg (string, delete_this_arg, this_is_output_file);
4523 if (this_is_output_file)
4524 outfiles[input_file_number] = string;
4525 arg_going = 0;
4530 /* Parse the WRAPPER string which is a comma separated list of the command line
4531 and insert them into the beginning of argbuf. */
4533 static void
4534 insert_wrapper (const char *wrapper)
4536 int n = 0;
4537 int i;
4538 char *buf = xstrdup (wrapper);
4539 char *p = buf;
4543 n++;
4544 while (*p == ',')
4545 p++;
4547 while ((p = strchr (p, ',')) != NULL);
4549 if (argbuf_index + n >= argbuf_length)
4551 argbuf_length = argbuf_length * 2;
4552 while (argbuf_length < argbuf_index + n)
4553 argbuf_length *= 2;
4554 argbuf = XRESIZEVEC (const char *, argbuf, argbuf_length);
4556 for (i = argbuf_index - 1; i >= 0; i--)
4557 argbuf[i + n] = argbuf[i];
4559 i = 0;
4560 p = buf;
4563 while (*p == ',')
4565 *p = 0;
4566 p++;
4568 argbuf[i++] = p;
4570 while ((p = strchr (p, ',')) != NULL);
4571 gcc_assert (i == n);
4572 argbuf_index += n;
4575 /* Process the spec SPEC and run the commands specified therein.
4576 Returns 0 if the spec is successfully processed; -1 if failed. */
4579 do_spec (const char *spec)
4581 int value;
4583 value = do_spec_2 (spec);
4585 /* Force out any unfinished command.
4586 If -pipe, this forces out the last command if it ended in `|'. */
4587 if (value == 0)
4589 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
4590 argbuf_index--;
4592 set_collect_gcc_options ();
4594 if (argbuf_index > 0)
4595 value = execute ();
4598 return value;
4601 static int
4602 do_spec_2 (const char *spec)
4604 int result;
4606 clear_args ();
4607 arg_going = 0;
4608 delete_this_arg = 0;
4609 this_is_output_file = 0;
4610 this_is_library_file = 0;
4611 input_from_pipe = 0;
4612 suffix_subst = NULL;
4614 result = do_spec_1 (spec, 0, NULL);
4616 end_going_arg ();
4618 return result;
4622 /* Process the given spec string and add any new options to the end
4623 of the switches/n_switches array. */
4625 static void
4626 do_option_spec (const char *name, const char *spec)
4628 unsigned int i, value_count, value_len;
4629 const char *p, *q, *value;
4630 char *tmp_spec, *tmp_spec_p;
4632 if (configure_default_options[0].name == NULL)
4633 return;
4635 for (i = 0; i < ARRAY_SIZE (configure_default_options); i++)
4636 if (strcmp (configure_default_options[i].name, name) == 0)
4637 break;
4638 if (i == ARRAY_SIZE (configure_default_options))
4639 return;
4641 value = configure_default_options[i].value;
4642 value_len = strlen (value);
4644 /* Compute the size of the final spec. */
4645 value_count = 0;
4646 p = spec;
4647 while ((p = strstr (p, "%(VALUE)")) != NULL)
4649 p ++;
4650 value_count ++;
4653 /* Replace each %(VALUE) by the specified value. */
4654 tmp_spec = (char *) alloca (strlen (spec) + 1
4655 + value_count * (value_len - strlen ("%(VALUE)")));
4656 tmp_spec_p = tmp_spec;
4657 q = spec;
4658 while ((p = strstr (q, "%(VALUE)")) != NULL)
4660 memcpy (tmp_spec_p, q, p - q);
4661 tmp_spec_p = tmp_spec_p + (p - q);
4662 memcpy (tmp_spec_p, value, value_len);
4663 tmp_spec_p += value_len;
4664 q = p + strlen ("%(VALUE)");
4666 strcpy (tmp_spec_p, q);
4668 do_self_spec (tmp_spec);
4671 /* Process the given spec string and add any new options to the end
4672 of the switches/n_switches array. */
4674 static void
4675 do_self_spec (const char *spec)
4677 do_spec_2 (spec);
4678 do_spec_1 (" ", 0, NULL);
4680 if (argbuf_index > 0)
4682 int i, first;
4684 first = n_switches;
4685 n_switches += argbuf_index;
4686 switches = XRESIZEVEC (struct switchstr, switches, n_switches + 1);
4688 switches[n_switches] = switches[first];
4689 for (i = 0; i < argbuf_index; i++)
4691 struct switchstr *sw;
4693 /* Each switch should start with '-'. */
4694 if (argbuf[i][0] != '-')
4695 fatal ("switch '%s' does not start with '-'", argbuf[i]);
4697 sw = &switches[i + first];
4698 sw->part1 = &argbuf[i][1];
4699 sw->args = 0;
4700 sw->live_cond = 0;
4701 sw->validated = 0;
4702 sw->ordering = 0;
4707 /* Callback for processing %D and %I specs. */
4709 struct spec_path_info {
4710 const char *option;
4711 const char *append;
4712 size_t append_len;
4713 bool omit_relative;
4714 bool separate_options;
4717 static void *
4718 spec_path (char *path, void *data)
4720 struct spec_path_info *info = (struct spec_path_info *) data;
4721 size_t len = 0;
4722 char save = 0;
4724 if (info->omit_relative && !IS_ABSOLUTE_PATH (path))
4725 return NULL;
4727 if (info->append_len != 0)
4729 len = strlen (path);
4730 memcpy (path + len, info->append, info->append_len + 1);
4733 if (!is_directory (path, true))
4734 return NULL;
4736 do_spec_1 (info->option, 1, NULL);
4737 if (info->separate_options)
4738 do_spec_1 (" ", 0, NULL);
4740 if (info->append_len == 0)
4742 len = strlen (path);
4743 save = path[len - 1];
4744 if (IS_DIR_SEPARATOR (path[len - 1]))
4745 path[len - 1] = '\0';
4748 do_spec_1 (path, 1, NULL);
4749 do_spec_1 (" ", 0, NULL);
4751 /* Must not damage the original path. */
4752 if (info->append_len == 0)
4753 path[len - 1] = save;
4755 return NULL;
4758 /* Create a temporary FILE with the contents of ARGV. Add @FILE to the
4759 argument list. */
4761 static void
4762 create_at_file (char **argv)
4764 char *temp_file = make_temp_file ("");
4765 char *at_argument = concat ("@", temp_file, NULL);
4766 FILE *f = fopen (temp_file, "w");
4767 int status;
4769 if (f == NULL)
4770 fatal ("could not open temporary response file %s",
4771 temp_file);
4773 status = writeargv (argv, f);
4775 if (status)
4776 fatal ("could not write to temporary response file %s",
4777 temp_file);
4779 status = fclose (f);
4781 if (EOF == status)
4782 fatal ("could not close temporary response file %s",
4783 temp_file);
4785 store_arg (at_argument, 0, 0);
4787 record_temp_file (temp_file, !save_temps_flag, !save_temps_flag);
4790 /* True if we should compile INFILE. */
4792 static bool
4793 compile_input_file_p (struct infile *infile)
4795 if ((!infile->language) || (infile->language[0] != '*'))
4796 if (infile->incompiler == input_file_compiler)
4797 return true;
4798 return false;
4801 /* Process the sub-spec SPEC as a portion of a larger spec.
4802 This is like processing a whole spec except that we do
4803 not initialize at the beginning and we do not supply a
4804 newline by default at the end.
4805 INSWITCH nonzero means don't process %-sequences in SPEC;
4806 in this case, % is treated as an ordinary character.
4807 This is used while substituting switches.
4808 INSWITCH nonzero also causes SPC not to terminate an argument.
4810 Value is zero unless a line was finished
4811 and the command on that line reported an error. */
4813 static int
4814 do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part)
4816 const char *p = spec;
4817 int c;
4818 int i;
4819 int value;
4821 while ((c = *p++))
4822 /* If substituting a switch, treat all chars like letters.
4823 Otherwise, NL, SPC, TAB and % are special. */
4824 switch (inswitch ? 'a' : c)
4826 case '\n':
4827 end_going_arg ();
4829 if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
4831 /* A `|' before the newline means use a pipe here,
4832 but only if -pipe was specified.
4833 Otherwise, execute now and don't pass the `|' as an arg. */
4834 if (use_pipes)
4836 input_from_pipe = 1;
4837 break;
4839 else
4840 argbuf_index--;
4843 set_collect_gcc_options ();
4845 if (argbuf_index > 0)
4847 value = execute ();
4848 if (value)
4849 return value;
4851 /* Reinitialize for a new command, and for a new argument. */
4852 clear_args ();
4853 arg_going = 0;
4854 delete_this_arg = 0;
4855 this_is_output_file = 0;
4856 this_is_library_file = 0;
4857 input_from_pipe = 0;
4858 break;
4860 case '|':
4861 end_going_arg ();
4863 /* Use pipe */
4864 obstack_1grow (&obstack, c);
4865 arg_going = 1;
4866 break;
4868 case '\t':
4869 case ' ':
4870 end_going_arg ();
4872 /* Reinitialize for a new argument. */
4873 delete_this_arg = 0;
4874 this_is_output_file = 0;
4875 this_is_library_file = 0;
4876 break;
4878 case '%':
4879 switch (c = *p++)
4881 case 0:
4882 fatal ("spec '%s' invalid", spec);
4884 case 'b':
4885 if (save_temps_length)
4886 obstack_grow (&obstack, save_temps_prefix, save_temps_length);
4887 else
4888 obstack_grow (&obstack, input_basename, basename_length);
4889 arg_going = 1;
4890 break;
4892 case 'B':
4893 if (save_temps_length)
4894 obstack_grow (&obstack, save_temps_prefix, save_temps_length);
4895 else
4896 obstack_grow (&obstack, input_basename, suffixed_basename_length);
4897 arg_going = 1;
4898 break;
4900 case 'd':
4901 delete_this_arg = 2;
4902 break;
4904 /* Dump out the directories specified with LIBRARY_PATH,
4905 followed by the absolute directories
4906 that we search for startfiles. */
4907 case 'D':
4909 struct spec_path_info info;
4911 info.option = "-L";
4912 info.append_len = 0;
4913 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
4914 /* Used on systems which record the specified -L dirs
4915 and use them to search for dynamic linking.
4916 Relative directories always come from -B,
4917 and it is better not to use them for searching
4918 at run time. In particular, stage1 loses. */
4919 info.omit_relative = true;
4920 #else
4921 info.omit_relative = false;
4922 #endif
4923 info.separate_options = false;
4925 for_each_path (&startfile_prefixes, true, 0, spec_path, &info);
4927 break;
4929 case 'e':
4930 /* %efoo means report an error with `foo' as error message
4931 and don't execute any more commands for this file. */
4933 const char *q = p;
4934 char *buf;
4935 while (*p != 0 && *p != '\n')
4936 p++;
4937 buf = (char *) alloca (p - q + 1);
4938 strncpy (buf, q, p - q);
4939 buf[p - q] = 0;
4940 error ("%s", buf);
4941 return -1;
4943 break;
4944 case 'n':
4945 /* %nfoo means report a notice with `foo' on stderr. */
4947 const char *q = p;
4948 char *buf;
4949 while (*p != 0 && *p != '\n')
4950 p++;
4951 buf = (char *) alloca (p - q + 1);
4952 strncpy (buf, q, p - q);
4953 buf[p - q] = 0;
4954 notice ("%s\n", buf);
4955 if (*p)
4956 p++;
4958 break;
4960 case 'j':
4962 struct stat st;
4964 /* If save_temps_flag is off, and the HOST_BIT_BUCKET is
4965 defined, and it is not a directory, and it is
4966 writable, use it. Otherwise, treat this like any
4967 other temporary file. */
4969 if ((!save_temps_flag)
4970 && (stat (HOST_BIT_BUCKET, &st) == 0) && (!S_ISDIR (st.st_mode))
4971 && (access (HOST_BIT_BUCKET, W_OK) == 0))
4973 obstack_grow (&obstack, HOST_BIT_BUCKET,
4974 strlen (HOST_BIT_BUCKET));
4975 delete_this_arg = 0;
4976 arg_going = 1;
4977 break;
4980 goto create_temp_file;
4981 case '|':
4982 if (use_pipes)
4984 obstack_1grow (&obstack, '-');
4985 delete_this_arg = 0;
4986 arg_going = 1;
4988 /* consume suffix */
4989 while (*p == '.' || ISALNUM ((unsigned char) *p))
4990 p++;
4991 if (p[0] == '%' && p[1] == 'O')
4992 p += 2;
4994 break;
4996 goto create_temp_file;
4997 case 'm':
4998 if (use_pipes)
5000 /* consume suffix */
5001 while (*p == '.' || ISALNUM ((unsigned char) *p))
5002 p++;
5003 if (p[0] == '%' && p[1] == 'O')
5004 p += 2;
5006 break;
5008 goto create_temp_file;
5009 case 'g':
5010 case 'u':
5011 case 'U':
5012 create_temp_file:
5014 struct temp_name *t;
5015 int suffix_length;
5016 const char *suffix = p;
5017 char *saved_suffix = NULL;
5019 while (*p == '.' || ISALNUM ((unsigned char) *p))
5020 p++;
5021 suffix_length = p - suffix;
5022 if (p[0] == '%' && p[1] == 'O')
5024 p += 2;
5025 /* We don't support extra suffix characters after %O. */
5026 if (*p == '.' || ISALNUM ((unsigned char) *p))
5027 fatal ("spec '%s' has invalid '%%0%c'", spec, *p);
5028 if (suffix_length == 0)
5029 suffix = TARGET_OBJECT_SUFFIX;
5030 else
5032 saved_suffix
5033 = XNEWVEC (char, suffix_length
5034 + strlen (TARGET_OBJECT_SUFFIX));
5035 strncpy (saved_suffix, suffix, suffix_length);
5036 strcpy (saved_suffix + suffix_length,
5037 TARGET_OBJECT_SUFFIX);
5039 suffix_length += strlen (TARGET_OBJECT_SUFFIX);
5042 /* If -save-temps=obj and -o were specified, use that for the
5043 temp file. */
5044 if (save_temps_length)
5046 char *tmp;
5047 temp_filename_length
5048 = save_temps_length + suffix_length + 1;
5049 tmp = (char *) alloca (temp_filename_length);
5050 memcpy (tmp, save_temps_prefix, save_temps_length);
5051 memcpy (tmp + save_temps_length, suffix, suffix_length);
5052 tmp[save_temps_length + suffix_length] = '\0';
5053 temp_filename = save_string (tmp,
5054 temp_filename_length + 1);
5055 obstack_grow (&obstack, temp_filename,
5056 temp_filename_length);
5057 arg_going = 1;
5058 delete_this_arg = 0;
5059 break;
5062 /* If the input_filename has the same suffix specified
5063 for the %g, %u, or %U, and -save-temps is specified,
5064 we could end up using that file as an intermediate
5065 thus clobbering the user's source file (.e.g.,
5066 gcc -save-temps foo.s would clobber foo.s with the
5067 output of cpp0). So check for this condition and
5068 generate a temp file as the intermediate. */
5070 if (save_temps_flag)
5072 char *tmp;
5073 temp_filename_length = basename_length + suffix_length + 1;
5074 tmp = (char *) alloca (temp_filename_length);
5075 memcpy (tmp, input_basename, basename_length);
5076 memcpy (tmp + basename_length, suffix, suffix_length);
5077 tmp[basename_length + suffix_length] = '\0';
5078 temp_filename = tmp;
5080 if (strcmp (temp_filename, input_filename) != 0)
5082 #ifndef HOST_LACKS_INODE_NUMBERS
5083 struct stat st_temp;
5085 /* Note, set_input() resets input_stat_set to 0. */
5086 if (input_stat_set == 0)
5088 input_stat_set = stat (input_filename, &input_stat);
5089 if (input_stat_set >= 0)
5090 input_stat_set = 1;
5093 /* If we have the stat for the input_filename
5094 and we can do the stat for the temp_filename
5095 then the they could still refer to the same
5096 file if st_dev/st_ino's are the same. */
5097 if (input_stat_set != 1
5098 || stat (temp_filename, &st_temp) < 0
5099 || input_stat.st_dev != st_temp.st_dev
5100 || input_stat.st_ino != st_temp.st_ino)
5101 #else
5102 /* Just compare canonical pathnames. */
5103 char* input_realname = lrealpath (input_filename);
5104 char* temp_realname = lrealpath (temp_filename);
5105 bool files_differ = strcmp (input_realname, temp_realname);
5106 free (input_realname);
5107 free (temp_realname);
5108 if (files_differ)
5109 #endif
5111 temp_filename = save_string (temp_filename,
5112 temp_filename_length + 1);
5113 obstack_grow (&obstack, temp_filename,
5114 temp_filename_length);
5115 arg_going = 1;
5116 delete_this_arg = 0;
5117 break;
5122 /* See if we already have an association of %g/%u/%U and
5123 suffix. */
5124 for (t = temp_names; t; t = t->next)
5125 if (t->length == suffix_length
5126 && strncmp (t->suffix, suffix, suffix_length) == 0
5127 && t->unique == (c == 'u' || c == 'U' || c == 'j'))
5128 break;
5130 /* Make a new association if needed. %u and %j
5131 require one. */
5132 if (t == 0 || c == 'u' || c == 'j')
5134 if (t == 0)
5136 t = XNEW (struct temp_name);
5137 t->next = temp_names;
5138 temp_names = t;
5140 t->length = suffix_length;
5141 if (saved_suffix)
5143 t->suffix = saved_suffix;
5144 saved_suffix = NULL;
5146 else
5147 t->suffix = save_string (suffix, suffix_length);
5148 t->unique = (c == 'u' || c == 'U' || c == 'j');
5149 temp_filename = make_temp_file (t->suffix);
5150 temp_filename_length = strlen (temp_filename);
5151 t->filename = temp_filename;
5152 t->filename_length = temp_filename_length;
5155 if (saved_suffix)
5156 free (saved_suffix);
5158 obstack_grow (&obstack, t->filename, t->filename_length);
5159 delete_this_arg = 1;
5161 arg_going = 1;
5162 break;
5164 case 'i':
5165 if (combine_inputs)
5167 if (at_file_supplied)
5169 /* We are going to expand `%i' to `@FILE', where FILE
5170 is a newly-created temporary filename. The filenames
5171 that would usually be expanded in place of %o will be
5172 written to the temporary file. */
5173 char **argv;
5174 int n_files = 0;
5175 int j;
5177 for (i = 0; i < n_infiles; i++)
5178 if (compile_input_file_p (&infiles[i]))
5179 n_files++;
5181 argv = (char **) alloca (sizeof (char *) * (n_files + 1));
5183 /* Copy the strings over. */
5184 for (i = 0, j = 0; i < n_infiles; i++)
5185 if (compile_input_file_p (&infiles[i]))
5187 argv[j] = CONST_CAST (char *, infiles[i].name);
5188 infiles[i].compiled = true;
5189 j++;
5191 argv[j] = NULL;
5193 create_at_file (argv);
5195 else
5196 for (i = 0; (int) i < n_infiles; i++)
5197 if (compile_input_file_p (&infiles[i]))
5199 store_arg (infiles[i].name, 0, 0);
5200 infiles[i].compiled = true;
5203 else
5205 obstack_grow (&obstack, input_filename, input_filename_length);
5206 arg_going = 1;
5208 break;
5210 case 'I':
5212 struct spec_path_info info;
5214 if (multilib_dir)
5216 do_spec_1 ("-imultilib", 1, NULL);
5217 /* Make this a separate argument. */
5218 do_spec_1 (" ", 0, NULL);
5219 do_spec_1 (multilib_dir, 1, NULL);
5220 do_spec_1 (" ", 0, NULL);
5223 if (gcc_exec_prefix)
5225 do_spec_1 ("-iprefix", 1, NULL);
5226 /* Make this a separate argument. */
5227 do_spec_1 (" ", 0, NULL);
5228 do_spec_1 (gcc_exec_prefix, 1, NULL);
5229 do_spec_1 (" ", 0, NULL);
5232 if (target_system_root_changed ||
5233 (target_system_root && target_sysroot_hdrs_suffix))
5235 do_spec_1 ("-isysroot", 1, NULL);
5236 /* Make this a separate argument. */
5237 do_spec_1 (" ", 0, NULL);
5238 do_spec_1 (target_system_root, 1, NULL);
5239 if (target_sysroot_hdrs_suffix)
5240 do_spec_1 (target_sysroot_hdrs_suffix, 1, NULL);
5241 do_spec_1 (" ", 0, NULL);
5244 info.option = "-isystem";
5245 info.append = "include";
5246 info.append_len = strlen (info.append);
5247 info.omit_relative = false;
5248 info.separate_options = true;
5250 for_each_path (&include_prefixes, false, info.append_len,
5251 spec_path, &info);
5253 info.append = "include-fixed";
5254 if (*sysroot_hdrs_suffix_spec)
5255 info.append = concat (info.append, dir_separator_str,
5256 multilib_dir, NULL);
5257 info.append_len = strlen (info.append);
5258 for_each_path (&include_prefixes, false, info.append_len,
5259 spec_path, &info);
5261 break;
5263 case 'o':
5265 int max = n_infiles;
5266 max += lang_specific_extra_outfiles;
5268 if (HAVE_GNU_LD && at_file_supplied)
5270 /* We are going to expand `%o' to `@FILE', where FILE
5271 is a newly-created temporary filename. The filenames
5272 that would usually be expanded in place of %o will be
5273 written to the temporary file. */
5275 char **argv;
5276 int n_files, j;
5278 /* Convert OUTFILES into a form suitable for writeargv. */
5280 /* Determine how many are non-NULL. */
5281 for (n_files = 0, i = 0; i < max; i++)
5282 n_files += outfiles[i] != NULL;
5284 argv = (char **) alloca (sizeof (char *) * (n_files + 1));
5286 /* Copy the strings over. */
5287 for (i = 0, j = 0; i < max; i++)
5288 if (outfiles[i])
5290 argv[j] = CONST_CAST (char *, outfiles[i]);
5291 j++;
5293 argv[j] = NULL;
5295 create_at_file (argv);
5297 else
5298 for (i = 0; i < max; i++)
5299 if (outfiles[i])
5300 store_arg (outfiles[i], 0, 0);
5301 break;
5304 case 'O':
5305 obstack_grow (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX));
5306 arg_going = 1;
5307 break;
5309 case 's':
5310 this_is_library_file = 1;
5311 break;
5313 case 'V':
5314 outfiles[input_file_number] = NULL;
5315 break;
5317 case 'w':
5318 this_is_output_file = 1;
5319 break;
5321 case 'W':
5323 int cur_index = argbuf_index;
5324 /* Handle the {...} following the %W. */
5325 if (*p != '{')
5326 fatal ("spec '%s' has invalid '%%W%c", spec, *p);
5327 p = handle_braces (p + 1);
5328 if (p == 0)
5329 return -1;
5330 end_going_arg ();
5331 /* If any args were output, mark the last one for deletion
5332 on failure. */
5333 if (argbuf_index != cur_index)
5334 record_temp_file (argbuf[argbuf_index - 1], 0, 1);
5335 break;
5338 /* %x{OPTION} records OPTION for %X to output. */
5339 case 'x':
5341 const char *p1 = p;
5342 char *string;
5344 /* Skip past the option value and make a copy. */
5345 if (*p != '{')
5346 fatal ("spec '%s' has invalid '%%x%c'", spec, *p);
5347 while (*p++ != '}')
5349 string = save_string (p1 + 1, p - p1 - 2);
5351 /* See if we already recorded this option. */
5352 for (i = 0; i < n_linker_options; i++)
5353 if (! strcmp (string, linker_options[i]))
5355 free (string);
5356 return 0;
5359 /* This option is new; add it. */
5360 add_linker_option (string, strlen (string));
5362 break;
5364 /* Dump out the options accumulated previously using %x. */
5365 case 'X':
5366 for (i = 0; i < n_linker_options; i++)
5368 do_spec_1 (linker_options[i], 1, NULL);
5369 /* Make each accumulated option a separate argument. */
5370 do_spec_1 (" ", 0, NULL);
5372 break;
5374 /* Dump out the options accumulated previously using -Wa,. */
5375 case 'Y':
5376 for (i = 0; i < n_assembler_options; i++)
5378 do_spec_1 (assembler_options[i], 1, NULL);
5379 /* Make each accumulated option a separate argument. */
5380 do_spec_1 (" ", 0, NULL);
5382 break;
5384 /* Dump out the options accumulated previously using -Wp,. */
5385 case 'Z':
5386 for (i = 0; i < n_preprocessor_options; i++)
5388 do_spec_1 (preprocessor_options[i], 1, NULL);
5389 /* Make each accumulated option a separate argument. */
5390 do_spec_1 (" ", 0, NULL);
5392 break;
5394 /* Here are digits and numbers that just process
5395 a certain constant string as a spec. */
5397 case '1':
5398 value = do_spec_1 (cc1_spec, 0, NULL);
5399 if (value != 0)
5400 return value;
5401 break;
5403 case '2':
5404 value = do_spec_1 (cc1plus_spec, 0, NULL);
5405 if (value != 0)
5406 return value;
5407 break;
5409 case 'a':
5410 value = do_spec_1 (asm_spec, 0, NULL);
5411 if (value != 0)
5412 return value;
5413 break;
5415 case 'A':
5416 value = do_spec_1 (asm_final_spec, 0, NULL);
5417 if (value != 0)
5418 return value;
5419 break;
5421 case 'C':
5423 const char *const spec
5424 = (input_file_compiler->cpp_spec
5425 ? input_file_compiler->cpp_spec
5426 : cpp_spec);
5427 value = do_spec_1 (spec, 0, NULL);
5428 if (value != 0)
5429 return value;
5431 break;
5433 case 'E':
5434 value = do_spec_1 (endfile_spec, 0, NULL);
5435 if (value != 0)
5436 return value;
5437 break;
5439 case 'l':
5440 value = do_spec_1 (link_spec, 0, NULL);
5441 if (value != 0)
5442 return value;
5443 break;
5445 case 'L':
5446 value = do_spec_1 (lib_spec, 0, NULL);
5447 if (value != 0)
5448 return value;
5449 break;
5451 case 'G':
5452 value = do_spec_1 (libgcc_spec, 0, NULL);
5453 if (value != 0)
5454 return value;
5455 break;
5457 case 'R':
5458 /* We assume there is a directory
5459 separator at the end of this string. */
5460 if (target_system_root)
5462 obstack_grow (&obstack, target_system_root,
5463 strlen (target_system_root));
5464 if (target_sysroot_suffix)
5465 obstack_grow (&obstack, target_sysroot_suffix,
5466 strlen (target_sysroot_suffix));
5468 break;
5470 case 'S':
5471 value = do_spec_1 (startfile_spec, 0, NULL);
5472 if (value != 0)
5473 return value;
5474 break;
5476 /* Here we define characters other than letters and digits. */
5478 case '{':
5479 p = handle_braces (p);
5480 if (p == 0)
5481 return -1;
5482 break;
5484 case ':':
5485 p = handle_spec_function (p);
5486 if (p == 0)
5487 return -1;
5488 break;
5490 case '%':
5491 obstack_1grow (&obstack, '%');
5492 break;
5494 case '.':
5496 unsigned len = 0;
5498 while (p[len] && p[len] != ' ' && p[len] != '%')
5499 len++;
5500 suffix_subst = save_string (p - 1, len + 1);
5501 p += len;
5503 break;
5505 /* Henceforth ignore the option(s) matching the pattern
5506 after the %<. */
5507 case '<':
5509 unsigned len = 0;
5510 int have_wildcard = 0;
5511 int i;
5513 while (p[len] && p[len] != ' ' && p[len] != '\t')
5514 len++;
5516 if (p[len-1] == '*')
5517 have_wildcard = 1;
5519 for (i = 0; i < n_switches; i++)
5520 if (!strncmp (switches[i].part1, p, len - have_wildcard)
5521 && (have_wildcard || switches[i].part1[len] == '\0'))
5523 switches[i].live_cond |= SWITCH_IGNORE;
5524 switches[i].validated = 1;
5527 p += len;
5529 break;
5531 case '*':
5532 if (soft_matched_part)
5534 do_spec_1 (soft_matched_part, 1, NULL);
5535 do_spec_1 (" ", 0, NULL);
5537 else
5538 /* Catch the case where a spec string contains something like
5539 '%{foo:%*}'. i.e. there is no * in the pattern on the left
5540 hand side of the :. */
5541 error ("spec failure: '%%*' has not been initialized by pattern match");
5542 break;
5544 /* Process a string found as the value of a spec given by name.
5545 This feature allows individual machine descriptions
5546 to add and use their own specs.
5547 %[...] modifies -D options the way %P does;
5548 %(...) uses the spec unmodified. */
5549 case '[':
5550 error ("warning: use of obsolete %%[ operator in specs");
5551 case '(':
5553 const char *name = p;
5554 struct spec_list *sl;
5555 int len;
5557 /* The string after the S/P is the name of a spec that is to be
5558 processed. */
5559 while (*p && *p != ')' && *p != ']')
5560 p++;
5562 /* See if it's in the list. */
5563 for (len = p - name, sl = specs; sl; sl = sl->next)
5564 if (sl->name_len == len && !strncmp (sl->name, name, len))
5566 name = *(sl->ptr_spec);
5567 #ifdef DEBUG_SPECS
5568 notice ("Processing spec %c%s%c, which is '%s'\n",
5569 c, sl->name, (c == '(') ? ')' : ']', name);
5570 #endif
5571 break;
5574 if (sl)
5576 if (c == '(')
5578 value = do_spec_1 (name, 0, NULL);
5579 if (value != 0)
5580 return value;
5582 else
5584 char *x = (char *) alloca (strlen (name) * 2 + 1);
5585 char *buf = x;
5586 const char *y = name;
5587 int flag = 0;
5589 /* Copy all of NAME into BUF, but put __ after
5590 every -D and at the end of each arg. */
5591 while (1)
5593 if (! strncmp (y, "-D", 2))
5595 *x++ = '-';
5596 *x++ = 'D';
5597 *x++ = '_';
5598 *x++ = '_';
5599 y += 2;
5600 flag = 1;
5601 continue;
5603 else if (flag
5604 && (*y == ' ' || *y == '\t' || *y == '='
5605 || *y == '}' || *y == 0))
5607 *x++ = '_';
5608 *x++ = '_';
5609 flag = 0;
5611 if (*y == 0)
5612 break;
5613 else
5614 *x++ = *y++;
5616 *x = 0;
5618 value = do_spec_1 (buf, 0, NULL);
5619 if (value != 0)
5620 return value;
5624 /* Discard the closing paren or bracket. */
5625 if (*p)
5626 p++;
5628 break;
5630 default:
5631 error ("spec failure: unrecognized spec option '%c'", c);
5632 break;
5634 break;
5636 case '\\':
5637 /* Backslash: treat next character as ordinary. */
5638 c = *p++;
5640 /* Fall through. */
5641 default:
5642 /* Ordinary character: put it into the current argument. */
5643 obstack_1grow (&obstack, c);
5644 arg_going = 1;
5647 /* End of string. If we are processing a spec function, we need to
5648 end any pending argument. */
5649 if (processing_spec_function)
5650 end_going_arg ();
5652 return 0;
5655 /* Look up a spec function. */
5657 static const struct spec_function *
5658 lookup_spec_function (const char *name)
5660 const struct spec_function *sf;
5662 for (sf = static_spec_functions; sf->name != NULL; sf++)
5663 if (strcmp (sf->name, name) == 0)
5664 return sf;
5666 return NULL;
5669 /* Evaluate a spec function. */
5671 static const char *
5672 eval_spec_function (const char *func, const char *args)
5674 const struct spec_function *sf;
5675 const char *funcval;
5677 /* Saved spec processing context. */
5678 int save_argbuf_index;
5679 int save_argbuf_length;
5680 const char **save_argbuf;
5682 int save_arg_going;
5683 int save_delete_this_arg;
5684 int save_this_is_output_file;
5685 int save_this_is_library_file;
5686 int save_input_from_pipe;
5687 const char *save_suffix_subst;
5690 sf = lookup_spec_function (func);
5691 if (sf == NULL)
5692 fatal ("unknown spec function '%s'", func);
5694 /* Push the spec processing context. */
5695 save_argbuf_index = argbuf_index;
5696 save_argbuf_length = argbuf_length;
5697 save_argbuf = argbuf;
5699 save_arg_going = arg_going;
5700 save_delete_this_arg = delete_this_arg;
5701 save_this_is_output_file = this_is_output_file;
5702 save_this_is_library_file = this_is_library_file;
5703 save_input_from_pipe = input_from_pipe;
5704 save_suffix_subst = suffix_subst;
5706 /* Create a new spec processing context, and build the function
5707 arguments. */
5709 alloc_args ();
5710 if (do_spec_2 (args) < 0)
5711 fatal ("error in args to spec function '%s'", func);
5713 /* argbuf_index is an index for the next argument to be inserted, and
5714 so contains the count of the args already inserted. */
5716 funcval = (*sf->func) (argbuf_index, argbuf);
5718 /* Pop the spec processing context. */
5719 argbuf_index = save_argbuf_index;
5720 argbuf_length = save_argbuf_length;
5721 free (argbuf);
5722 argbuf = save_argbuf;
5724 arg_going = save_arg_going;
5725 delete_this_arg = save_delete_this_arg;
5726 this_is_output_file = save_this_is_output_file;
5727 this_is_library_file = save_this_is_library_file;
5728 input_from_pipe = save_input_from_pipe;
5729 suffix_subst = save_suffix_subst;
5731 return funcval;
5734 /* Handle a spec function call of the form:
5736 %:function(args)
5738 ARGS is processed as a spec in a separate context and split into an
5739 argument vector in the normal fashion. The function returns a string
5740 containing a spec which we then process in the caller's context, or
5741 NULL if no processing is required. */
5743 static const char *
5744 handle_spec_function (const char *p)
5746 char *func, *args;
5747 const char *endp, *funcval;
5748 int count;
5750 processing_spec_function++;
5752 /* Get the function name. */
5753 for (endp = p; *endp != '\0'; endp++)
5755 if (*endp == '(') /* ) */
5756 break;
5757 /* Only allow [A-Za-z0-9], -, and _ in function names. */
5758 if (!ISALNUM (*endp) && !(*endp == '-' || *endp == '_'))
5759 fatal ("malformed spec function name");
5761 if (*endp != '(') /* ) */
5762 fatal ("no arguments for spec function");
5763 func = save_string (p, endp - p);
5764 p = ++endp;
5766 /* Get the arguments. */
5767 for (count = 0; *endp != '\0'; endp++)
5769 /* ( */
5770 if (*endp == ')')
5772 if (count == 0)
5773 break;
5774 count--;
5776 else if (*endp == '(') /* ) */
5777 count++;
5779 /* ( */
5780 if (*endp != ')')
5781 fatal ("malformed spec function arguments");
5782 args = save_string (p, endp - p);
5783 p = ++endp;
5785 /* p now points to just past the end of the spec function expression. */
5787 funcval = eval_spec_function (func, args);
5788 if (funcval != NULL && do_spec_1 (funcval, 0, NULL) < 0)
5789 p = NULL;
5791 free (func);
5792 free (args);
5794 processing_spec_function--;
5796 return p;
5799 /* Inline subroutine of handle_braces. Returns true if the current
5800 input suffix matches the atom bracketed by ATOM and END_ATOM. */
5801 static inline bool
5802 input_suffix_matches (const char *atom, const char *end_atom)
5804 return (input_suffix
5805 && !strncmp (input_suffix, atom, end_atom - atom)
5806 && input_suffix[end_atom - atom] == '\0');
5809 /* Subroutine of handle_braces. Returns true if the current
5810 input file's spec name matches the atom bracketed by ATOM and END_ATOM. */
5811 static bool
5812 input_spec_matches (const char *atom, const char *end_atom)
5814 return (input_file_compiler
5815 && input_file_compiler->suffix
5816 && input_file_compiler->suffix[0] != '\0'
5817 && !strncmp (input_file_compiler->suffix + 1, atom,
5818 end_atom - atom)
5819 && input_file_compiler->suffix[end_atom - atom + 1] == '\0');
5822 /* Subroutine of handle_braces. Returns true if a switch
5823 matching the atom bracketed by ATOM and END_ATOM appeared on the
5824 command line. */
5825 static bool
5826 switch_matches (const char *atom, const char *end_atom, int starred)
5828 int i;
5829 int len = end_atom - atom;
5830 int plen = starred ? len : -1;
5832 for (i = 0; i < n_switches; i++)
5833 if (!strncmp (switches[i].part1, atom, len)
5834 && (starred || switches[i].part1[len] == '\0')
5835 && check_live_switch (i, plen))
5836 return true;
5838 return false;
5841 /* Inline subroutine of handle_braces. Mark all of the switches which
5842 match ATOM (extends to END_ATOM; STARRED indicates whether there
5843 was a star after the atom) for later processing. */
5844 static inline void
5845 mark_matching_switches (const char *atom, const char *end_atom, int starred)
5847 int i;
5848 int len = end_atom - atom;
5849 int plen = starred ? len : -1;
5851 for (i = 0; i < n_switches; i++)
5852 if (!strncmp (switches[i].part1, atom, len)
5853 && (starred || switches[i].part1[len] == '\0')
5854 && check_live_switch (i, plen))
5855 switches[i].ordering = 1;
5858 /* Inline subroutine of handle_braces. Process all the currently
5859 marked switches through give_switch, and clear the marks. */
5860 static inline void
5861 process_marked_switches (void)
5863 int i;
5865 for (i = 0; i < n_switches; i++)
5866 if (switches[i].ordering == 1)
5868 switches[i].ordering = 0;
5869 give_switch (i, 0);
5873 /* Handle a %{ ... } construct. P points just inside the leading {.
5874 Returns a pointer one past the end of the brace block, or 0
5875 if we call do_spec_1 and that returns -1. */
5877 static const char *
5878 handle_braces (const char *p)
5880 const char *atom, *end_atom;
5881 const char *d_atom = NULL, *d_end_atom = NULL;
5882 const char *orig = p;
5884 bool a_is_suffix;
5885 bool a_is_spectype;
5886 bool a_is_starred;
5887 bool a_is_negated;
5888 bool a_matched;
5890 bool a_must_be_last = false;
5891 bool ordered_set = false;
5892 bool disjunct_set = false;
5893 bool disj_matched = false;
5894 bool disj_starred = true;
5895 bool n_way_choice = false;
5896 bool n_way_matched = false;
5898 #define SKIP_WHITE() do { while (*p == ' ' || *p == '\t') p++; } while (0)
5902 if (a_must_be_last)
5903 goto invalid;
5905 /* Scan one "atom" (S in the description above of %{}, possibly
5906 with '!', '.', '@', ',', or '*' modifiers). */
5907 a_matched = false;
5908 a_is_suffix = false;
5909 a_is_starred = false;
5910 a_is_negated = false;
5911 a_is_spectype = false;
5913 SKIP_WHITE();
5914 if (*p == '!')
5915 p++, a_is_negated = true;
5917 SKIP_WHITE();
5918 if (*p == '.')
5919 p++, a_is_suffix = true;
5920 else if (*p == ',')
5921 p++, a_is_spectype = true;
5923 atom = p;
5924 while (ISIDNUM(*p) || *p == '-' || *p == '+' || *p == '='
5925 || *p == ',' || *p == '.' || *p == '@')
5926 p++;
5927 end_atom = p;
5929 if (*p == '*')
5930 p++, a_is_starred = 1;
5932 SKIP_WHITE();
5933 switch (*p)
5935 case '&': case '}':
5936 /* Substitute the switch(es) indicated by the current atom. */
5937 ordered_set = true;
5938 if (disjunct_set || n_way_choice || a_is_negated || a_is_suffix
5939 || a_is_spectype || atom == end_atom)
5940 goto invalid;
5942 mark_matching_switches (atom, end_atom, a_is_starred);
5944 if (*p == '}')
5945 process_marked_switches ();
5946 break;
5948 case '|': case ':':
5949 /* Substitute some text if the current atom appears as a switch
5950 or suffix. */
5951 disjunct_set = true;
5952 if (ordered_set)
5953 goto invalid;
5955 if (atom == end_atom)
5957 if (!n_way_choice || disj_matched || *p == '|'
5958 || a_is_negated || a_is_suffix || a_is_spectype
5959 || a_is_starred)
5960 goto invalid;
5962 /* An empty term may appear as the last choice of an
5963 N-way choice set; it means "otherwise". */
5964 a_must_be_last = true;
5965 disj_matched = !n_way_matched;
5966 disj_starred = false;
5968 else
5970 if ((a_is_suffix || a_is_spectype) && a_is_starred)
5971 goto invalid;
5973 if (!a_is_starred)
5974 disj_starred = false;
5976 /* Don't bother testing this atom if we already have a
5977 match. */
5978 if (!disj_matched && !n_way_matched)
5980 if (a_is_suffix)
5981 a_matched = input_suffix_matches (atom, end_atom);
5982 else if (a_is_spectype)
5983 a_matched = input_spec_matches (atom, end_atom);
5984 else
5985 a_matched = switch_matches (atom, end_atom, a_is_starred);
5987 if (a_matched != a_is_negated)
5989 disj_matched = true;
5990 d_atom = atom;
5991 d_end_atom = end_atom;
5996 if (*p == ':')
5998 /* Found the body, that is, the text to substitute if the
5999 current disjunction matches. */
6000 p = process_brace_body (p + 1, d_atom, d_end_atom, disj_starred,
6001 disj_matched && !n_way_matched);
6002 if (p == 0)
6003 return 0;
6005 /* If we have an N-way choice, reset state for the next
6006 disjunction. */
6007 if (*p == ';')
6009 n_way_choice = true;
6010 n_way_matched |= disj_matched;
6011 disj_matched = false;
6012 disj_starred = true;
6013 d_atom = d_end_atom = NULL;
6016 break;
6018 default:
6019 goto invalid;
6022 while (*p++ != '}');
6024 return p;
6026 invalid:
6027 fatal ("braced spec '%s' is invalid at '%c'", orig, *p);
6029 #undef SKIP_WHITE
6032 /* Subroutine of handle_braces. Scan and process a brace substitution body
6033 (X in the description of %{} syntax). P points one past the colon;
6034 ATOM and END_ATOM bracket the first atom which was found to be true
6035 (present) in the current disjunction; STARRED indicates whether all
6036 the atoms in the current disjunction were starred (for syntax validation);
6037 MATCHED indicates whether the disjunction matched or not, and therefore
6038 whether or not the body is to be processed through do_spec_1 or just
6039 skipped. Returns a pointer to the closing } or ;, or 0 if do_spec_1
6040 returns -1. */
6042 static const char *
6043 process_brace_body (const char *p, const char *atom, const char *end_atom,
6044 int starred, int matched)
6046 const char *body, *end_body;
6047 unsigned int nesting_level;
6048 bool have_subst = false;
6050 /* Locate the closing } or ;, honoring nested braces.
6051 Trim trailing whitespace. */
6052 body = p;
6053 nesting_level = 1;
6054 for (;;)
6056 if (*p == '{')
6057 nesting_level++;
6058 else if (*p == '}')
6060 if (!--nesting_level)
6061 break;
6063 else if (*p == ';' && nesting_level == 1)
6064 break;
6065 else if (*p == '%' && p[1] == '*' && nesting_level == 1)
6066 have_subst = true;
6067 else if (*p == '\0')
6068 goto invalid;
6069 p++;
6072 end_body = p;
6073 while (end_body[-1] == ' ' || end_body[-1] == '\t')
6074 end_body--;
6076 if (have_subst && !starred)
6077 goto invalid;
6079 if (matched)
6081 /* Copy the substitution body to permanent storage and execute it.
6082 If have_subst is false, this is a simple matter of running the
6083 body through do_spec_1... */
6084 char *string = save_string (body, end_body - body);
6085 if (!have_subst)
6087 if (do_spec_1 (string, 0, NULL) < 0)
6088 return 0;
6090 else
6092 /* ... but if have_subst is true, we have to process the
6093 body once for each matching switch, with %* set to the
6094 variant part of the switch. */
6095 unsigned int hard_match_len = end_atom - atom;
6096 int i;
6098 for (i = 0; i < n_switches; i++)
6099 if (!strncmp (switches[i].part1, atom, hard_match_len)
6100 && check_live_switch (i, hard_match_len))
6102 if (do_spec_1 (string, 0,
6103 &switches[i].part1[hard_match_len]) < 0)
6104 return 0;
6105 /* Pass any arguments this switch has. */
6106 give_switch (i, 1);
6107 suffix_subst = NULL;
6112 return p;
6114 invalid:
6115 fatal ("braced spec body '%s' is invalid", body);
6118 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
6119 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
6120 spec, or -1 if either exact match or %* is used.
6122 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
6123 whose value does not begin with "no-" is obsoleted by the same value
6124 with the "no-", similarly for a switch with the "no-" prefix. */
6126 static int
6127 check_live_switch (int switchnum, int prefix_length)
6129 const char *name = switches[switchnum].part1;
6130 int i;
6132 /* In the common case of {<at-most-one-letter>*}, a negating
6133 switch would always match, so ignore that case. We will just
6134 send the conflicting switches to the compiler phase. */
6135 if (prefix_length >= 0 && prefix_length <= 1)
6136 return 1;
6138 /* If we already processed this switch and determined if it was
6139 live or not, return our past determination. */
6140 if (switches[switchnum].live_cond != 0)
6141 return ((switches[switchnum].live_cond & SWITCH_LIVE) != 0
6142 && (switches[switchnum].live_cond & SWITCH_FALSE) == 0);
6144 /* Now search for duplicate in a manner that depends on the name. */
6145 switch (*name)
6147 case 'O':
6148 for (i = switchnum + 1; i < n_switches; i++)
6149 if (switches[i].part1[0] == 'O')
6151 switches[switchnum].validated = 1;
6152 switches[switchnum].live_cond = SWITCH_FALSE;
6153 return 0;
6155 break;
6157 case 'W': case 'f': case 'm':
6158 if (! strncmp (name + 1, "no-", 3))
6160 /* We have Xno-YYY, search for XYYY. */
6161 for (i = switchnum + 1; i < n_switches; i++)
6162 if (switches[i].part1[0] == name[0]
6163 && ! strcmp (&switches[i].part1[1], &name[4]))
6165 switches[switchnum].validated = 1;
6166 switches[switchnum].live_cond = SWITCH_FALSE;
6167 return 0;
6170 else
6172 /* We have XYYY, search for Xno-YYY. */
6173 for (i = switchnum + 1; i < n_switches; i++)
6174 if (switches[i].part1[0] == name[0]
6175 && switches[i].part1[1] == 'n'
6176 && switches[i].part1[2] == 'o'
6177 && switches[i].part1[3] == '-'
6178 && !strcmp (&switches[i].part1[4], &name[1]))
6180 switches[switchnum].validated = 1;
6181 switches[switchnum].live_cond = SWITCH_FALSE;
6182 return 0;
6185 break;
6188 /* Otherwise the switch is live. */
6189 switches[switchnum].live_cond |= SWITCH_LIVE;
6190 return 1;
6193 /* Pass a switch to the current accumulating command
6194 in the same form that we received it.
6195 SWITCHNUM identifies the switch; it is an index into
6196 the vector of switches gcc received, which is `switches'.
6197 This cannot fail since it never finishes a command line.
6199 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */
6201 static void
6202 give_switch (int switchnum, int omit_first_word)
6204 if ((switches[switchnum].live_cond & SWITCH_IGNORE) != 0)
6205 return;
6207 if (!omit_first_word)
6209 do_spec_1 ("-", 0, NULL);
6210 do_spec_1 (switches[switchnum].part1, 1, NULL);
6213 if (switches[switchnum].args != 0)
6215 const char **p;
6216 for (p = switches[switchnum].args; *p; p++)
6218 const char *arg = *p;
6220 do_spec_1 (" ", 0, NULL);
6221 if (suffix_subst)
6223 unsigned length = strlen (arg);
6224 int dot = 0;
6226 while (length-- && !IS_DIR_SEPARATOR (arg[length]))
6227 if (arg[length] == '.')
6229 (CONST_CAST(char *, arg))[length] = 0;
6230 dot = 1;
6231 break;
6233 do_spec_1 (arg, 1, NULL);
6234 if (dot)
6235 (CONST_CAST(char *, arg))[length] = '.';
6236 do_spec_1 (suffix_subst, 1, NULL);
6238 else
6239 do_spec_1 (arg, 1, NULL);
6243 do_spec_1 (" ", 0, NULL);
6244 switches[switchnum].validated = 1;
6247 /* Search for a file named NAME trying various prefixes including the
6248 user's -B prefix and some standard ones.
6249 Return the absolute file name found. If nothing is found, return NAME. */
6251 static const char *
6252 find_file (const char *name)
6254 char *newname = find_a_file (&startfile_prefixes, name, R_OK, true);
6255 return newname ? newname : name;
6258 /* Determine whether a directory exists. If LINKER, return 0 for
6259 certain fixed names not needed by the linker. */
6261 static int
6262 is_directory (const char *path1, bool linker)
6264 int len1;
6265 char *path;
6266 char *cp;
6267 struct stat st;
6269 /* Ensure the string ends with "/.". The resulting path will be a
6270 directory even if the given path is a symbolic link. */
6271 len1 = strlen (path1);
6272 path = (char *) alloca (3 + len1);
6273 memcpy (path, path1, len1);
6274 cp = path + len1;
6275 if (!IS_DIR_SEPARATOR (cp[-1]))
6276 *cp++ = DIR_SEPARATOR;
6277 *cp++ = '.';
6278 *cp = '\0';
6280 /* Exclude directories that the linker is known to search. */
6281 if (linker
6282 && IS_DIR_SEPARATOR (path[0])
6283 && ((cp - path == 6
6284 && strncmp (path + 1, "lib", 3) == 0)
6285 || (cp - path == 10
6286 && strncmp (path + 1, "usr", 3) == 0
6287 && IS_DIR_SEPARATOR (path[4])
6288 && strncmp (path + 5, "lib", 3) == 0)))
6289 return 0;
6291 return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
6294 /* Set up the various global variables to indicate that we're processing
6295 the input file named FILENAME. */
6297 void
6298 set_input (const char *filename)
6300 const char *p;
6302 input_filename = filename;
6303 input_filename_length = strlen (input_filename);
6304 input_basename = lbasename (input_filename);
6306 /* Find a suffix starting with the last period,
6307 and set basename_length to exclude that suffix. */
6308 basename_length = strlen (input_basename);
6309 suffixed_basename_length = basename_length;
6310 p = input_basename + basename_length;
6311 while (p != input_basename && *p != '.')
6312 --p;
6313 if (*p == '.' && p != input_basename)
6315 basename_length = p - input_basename;
6316 input_suffix = p + 1;
6318 else
6319 input_suffix = "";
6321 /* If a spec for 'g', 'u', or 'U' is seen with -save-temps then
6322 we will need to do a stat on the input_filename. The
6323 INPUT_STAT_SET signals that the stat is needed. */
6324 input_stat_set = 0;
6327 /* On fatal signals, delete all the temporary files. */
6329 static void
6330 fatal_error (int signum)
6332 signal (signum, SIG_DFL);
6333 delete_failure_queue ();
6334 delete_temp_files ();
6335 /* Get the same signal again, this time not handled,
6336 so its normal effect occurs. */
6337 kill (getpid (), signum);
6340 extern int main (int, char **);
6343 main (int argc, char **argv)
6345 size_t i;
6346 int value;
6347 int linker_was_run = 0;
6348 int lang_n_infiles = 0;
6349 int num_linker_inputs = 0;
6350 char *explicit_link_files;
6351 char *specs_file;
6352 const char *p;
6353 struct user_specs *uptr;
6354 char **old_argv = argv;
6356 /* Initialize here, not in definition. The IRIX 6 O32 cc sometimes chokes
6357 on ?: in file-scope variable initializations. */
6358 asm_debug = ASM_DEBUG_SPEC;
6360 p = argv[0] + strlen (argv[0]);
6361 while (p != argv[0] && !IS_DIR_SEPARATOR (p[-1]))
6362 --p;
6363 programname = p;
6365 xmalloc_set_program_name (programname);
6367 expandargv (&argc, &argv);
6369 /* Determine if any expansions were made. */
6370 if (argv != old_argv)
6371 at_file_supplied = true;
6373 prune_options (&argc, &argv);
6375 #ifdef GCC_DRIVER_HOST_INITIALIZATION
6376 /* Perform host dependent initialization when needed. */
6377 GCC_DRIVER_HOST_INITIALIZATION;
6378 #endif
6380 /* Unlock the stdio streams. */
6381 unlock_std_streams ();
6383 gcc_init_libintl ();
6385 if (signal (SIGINT, SIG_IGN) != SIG_IGN)
6386 signal (SIGINT, fatal_error);
6387 #ifdef SIGHUP
6388 if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
6389 signal (SIGHUP, fatal_error);
6390 #endif
6391 if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
6392 signal (SIGTERM, fatal_error);
6393 #ifdef SIGPIPE
6394 if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
6395 signal (SIGPIPE, fatal_error);
6396 #endif
6397 #ifdef SIGCHLD
6398 /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
6399 receive the signal. A different setting is inheritable */
6400 signal (SIGCHLD, SIG_DFL);
6401 #endif
6403 /* Allocate the argument vector. */
6404 alloc_args ();
6406 obstack_init (&obstack);
6408 /* Build multilib_select, et. al from the separate lines that make up each
6409 multilib selection. */
6411 const char *const *q = multilib_raw;
6412 int need_space;
6414 obstack_init (&multilib_obstack);
6415 while ((p = *q++) != (char *) 0)
6416 obstack_grow (&multilib_obstack, p, strlen (p));
6418 obstack_1grow (&multilib_obstack, 0);
6419 multilib_select = XOBFINISH (&multilib_obstack, const char *);
6421 q = multilib_matches_raw;
6422 while ((p = *q++) != (char *) 0)
6423 obstack_grow (&multilib_obstack, p, strlen (p));
6425 obstack_1grow (&multilib_obstack, 0);
6426 multilib_matches = XOBFINISH (&multilib_obstack, const char *);
6428 q = multilib_exclusions_raw;
6429 while ((p = *q++) != (char *) 0)
6430 obstack_grow (&multilib_obstack, p, strlen (p));
6432 obstack_1grow (&multilib_obstack, 0);
6433 multilib_exclusions = XOBFINISH (&multilib_obstack, const char *);
6435 need_space = FALSE;
6436 for (i = 0; i < ARRAY_SIZE (multilib_defaults_raw); i++)
6438 if (need_space)
6439 obstack_1grow (&multilib_obstack, ' ');
6440 obstack_grow (&multilib_obstack,
6441 multilib_defaults_raw[i],
6442 strlen (multilib_defaults_raw[i]));
6443 need_space = TRUE;
6446 obstack_1grow (&multilib_obstack, 0);
6447 multilib_defaults = XOBFINISH (&multilib_obstack, const char *);
6450 /* Set up to remember the pathname of gcc and any options
6451 needed for collect. We use argv[0] instead of programname because
6452 we need the complete pathname. */
6453 obstack_init (&collect_obstack);
6454 obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=") - 1);
6455 obstack_grow (&collect_obstack, argv[0], strlen (argv[0]) + 1);
6456 xputenv (XOBFINISH (&collect_obstack, char *));
6458 #ifdef INIT_ENVIRONMENT
6459 /* Set up any other necessary machine specific environment variables. */
6460 xputenv (INIT_ENVIRONMENT);
6461 #endif
6463 /* Make a table of what switches there are (switches, n_switches).
6464 Make a table of specified input files (infiles, n_infiles).
6465 Decode switches that are handled locally. */
6467 process_command (argc, (const char **) argv);
6469 /* Initialize the vector of specs to just the default.
6470 This means one element containing 0s, as a terminator. */
6472 compilers = XNEWVAR (struct compiler, sizeof default_compilers);
6473 memcpy (compilers, default_compilers, sizeof default_compilers);
6474 n_compilers = n_default_compilers;
6476 /* Read specs from a file if there is one. */
6478 machine_suffix = concat (spec_machine, dir_separator_str,
6479 spec_version, dir_separator_str, NULL);
6480 just_machine_suffix = concat (spec_machine, dir_separator_str, NULL);
6482 specs_file = find_a_file (&startfile_prefixes, "specs", R_OK, true);
6483 /* Read the specs file unless it is a default one. */
6484 if (specs_file != 0 && strcmp (specs_file, "specs"))
6485 read_specs (specs_file, TRUE);
6486 else
6487 init_spec ();
6489 /* We need to check standard_exec_prefix/just_machine_suffix/specs
6490 for any override of as, ld and libraries. */
6491 specs_file = (char *) alloca (strlen (standard_exec_prefix)
6492 + strlen (just_machine_suffix) + sizeof ("specs"));
6494 strcpy (specs_file, standard_exec_prefix);
6495 strcat (specs_file, just_machine_suffix);
6496 strcat (specs_file, "specs");
6497 if (access (specs_file, R_OK) == 0)
6498 read_specs (specs_file, TRUE);
6500 /* Process any configure-time defaults specified for the command line
6501 options, via OPTION_DEFAULT_SPECS. */
6502 for (i = 0; i < ARRAY_SIZE (option_default_specs); i++)
6503 do_option_spec (option_default_specs[i].name,
6504 option_default_specs[i].spec);
6506 /* Process DRIVER_SELF_SPECS, adding any new options to the end
6507 of the command line. */
6509 for (i = 0; i < ARRAY_SIZE (driver_self_specs); i++)
6510 do_self_spec (driver_self_specs[i]);
6512 /* If not cross-compiling, look for executables in the standard
6513 places. */
6514 if (*cross_compile == '0')
6516 if (*md_exec_prefix)
6518 add_prefix (&exec_prefixes, md_exec_prefix, "GCC",
6519 PREFIX_PRIORITY_LAST, 0, 0);
6523 /* Process sysroot_suffix_spec. */
6524 if (*sysroot_suffix_spec != 0
6525 && do_spec_2 (sysroot_suffix_spec) == 0)
6527 if (argbuf_index > 1)
6528 error ("spec failure: more than one arg to SYSROOT_SUFFIX_SPEC");
6529 else if (argbuf_index == 1)
6530 target_sysroot_suffix = xstrdup (argbuf[argbuf_index -1]);
6533 #ifdef HAVE_LD_SYSROOT
6534 /* Pass the --sysroot option to the linker, if it supports that. If
6535 there is a sysroot_suffix_spec, it has already been processed by
6536 this point, so target_system_root really is the system root we
6537 should be using. */
6538 if (target_system_root)
6540 obstack_grow (&obstack, "%(sysroot_spec) ", strlen ("%(sysroot_spec) "));
6541 obstack_grow0 (&obstack, link_spec, strlen (link_spec));
6542 set_spec ("link", XOBFINISH (&obstack, const char *));
6544 #endif
6546 /* Process sysroot_hdrs_suffix_spec. */
6547 if (*sysroot_hdrs_suffix_spec != 0
6548 && do_spec_2 (sysroot_hdrs_suffix_spec) == 0)
6550 if (argbuf_index > 1)
6551 error ("spec failure: more than one arg to SYSROOT_HEADERS_SUFFIX_SPEC");
6552 else if (argbuf_index == 1)
6553 target_sysroot_hdrs_suffix = xstrdup (argbuf[argbuf_index -1]);
6556 /* Look for startfiles in the standard places. */
6557 if (*startfile_prefix_spec != 0
6558 && do_spec_2 (startfile_prefix_spec) == 0
6559 && do_spec_1 (" ", 0, NULL) == 0)
6561 int ndx;
6562 for (ndx = 0; ndx < argbuf_index; ndx++)
6563 add_sysrooted_prefix (&startfile_prefixes, argbuf[ndx], "BINUTILS",
6564 PREFIX_PRIORITY_LAST, 0, 1);
6566 /* We should eventually get rid of all these and stick to
6567 startfile_prefix_spec exclusively. */
6568 else if (*cross_compile == '0' || target_system_root)
6570 if (*md_startfile_prefix)
6571 add_sysrooted_prefix (&startfile_prefixes, md_startfile_prefix,
6572 "GCC", PREFIX_PRIORITY_LAST, 0, 1);
6574 if (*md_startfile_prefix_1)
6575 add_sysrooted_prefix (&startfile_prefixes, md_startfile_prefix_1,
6576 "GCC", PREFIX_PRIORITY_LAST, 0, 1);
6578 /* If standard_startfile_prefix is relative, base it on
6579 standard_exec_prefix. This lets us move the installed tree
6580 as a unit. If GCC_EXEC_PREFIX is defined, base
6581 standard_startfile_prefix on that as well.
6583 If the prefix is relative, only search it for native compilers;
6584 otherwise we will search a directory containing host libraries. */
6585 if (IS_ABSOLUTE_PATH (standard_startfile_prefix))
6586 add_sysrooted_prefix (&startfile_prefixes,
6587 standard_startfile_prefix, "BINUTILS",
6588 PREFIX_PRIORITY_LAST, 0, 1);
6589 else if (*cross_compile == '0')
6591 add_prefix (&startfile_prefixes,
6592 concat (gcc_exec_prefix
6593 ? gcc_exec_prefix : standard_exec_prefix,
6594 machine_suffix,
6595 standard_startfile_prefix, NULL),
6596 NULL, PREFIX_PRIORITY_LAST, 0, 1);
6599 /* Sysrooted prefixes are relocated because target_system_root is
6600 also relocated by gcc_exec_prefix. */
6601 if (*standard_startfile_prefix_1)
6602 add_sysrooted_prefix (&startfile_prefixes,
6603 standard_startfile_prefix_1, "BINUTILS",
6604 PREFIX_PRIORITY_LAST, 0, 1);
6605 if (*standard_startfile_prefix_2)
6606 add_sysrooted_prefix (&startfile_prefixes,
6607 standard_startfile_prefix_2, "BINUTILS",
6608 PREFIX_PRIORITY_LAST, 0, 1);
6611 /* Process any user specified specs in the order given on the command
6612 line. */
6613 for (uptr = user_specs_head; uptr; uptr = uptr->next)
6615 char *filename = find_a_file (&startfile_prefixes, uptr->filename,
6616 R_OK, true);
6617 read_specs (filename ? filename : uptr->filename, FALSE);
6620 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
6621 if (gcc_exec_prefix)
6622 gcc_exec_prefix = concat (gcc_exec_prefix, spec_machine, dir_separator_str,
6623 spec_version, dir_separator_str, NULL);
6625 /* Now we have the specs.
6626 Set the `valid' bits for switches that match anything in any spec. */
6628 validate_all_switches ();
6630 /* Now that we have the switches and the specs, set
6631 the subdirectory based on the options. */
6632 set_multilib_dir ();
6634 /* Warn about any switches that no pass was interested in. */
6636 for (i = 0; (int) i < n_switches; i++)
6637 if (! switches[i].validated)
6638 error ("unrecognized option '-%s'", switches[i].part1);
6640 /* Obey some of the options. */
6642 if (print_search_dirs)
6644 printf (_("install: %s%s\n"),
6645 gcc_exec_prefix ? gcc_exec_prefix : standard_exec_prefix,
6646 gcc_exec_prefix ? "" : machine_suffix);
6647 printf (_("programs: %s\n"),
6648 build_search_list (&exec_prefixes, "", false, false));
6649 printf (_("libraries: %s\n"),
6650 build_search_list (&startfile_prefixes, "", false, true));
6651 return (0);
6654 if (print_file_name)
6656 printf ("%s\n", find_file (print_file_name));
6657 return (0);
6660 if (print_prog_name)
6662 char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK, 0);
6663 printf ("%s\n", (newname ? newname : print_prog_name));
6664 return (0);
6667 if (print_multi_lib)
6669 print_multilib_info ();
6670 return (0);
6673 if (print_multi_directory)
6675 if (multilib_dir == NULL)
6676 printf (".\n");
6677 else
6678 printf ("%s\n", multilib_dir);
6679 return (0);
6682 if (print_sysroot)
6684 if (target_system_root)
6686 if (target_sysroot_suffix)
6687 printf ("%s%s\n", target_system_root, target_sysroot_suffix);
6688 else
6689 printf ("%s\n", target_system_root);
6691 return (0);
6694 if (print_multi_os_directory)
6696 if (multilib_os_dir == NULL)
6697 printf (".\n");
6698 else
6699 printf ("%s\n", multilib_os_dir);
6700 return (0);
6703 if (print_sysroot_headers_suffix)
6705 if (*sysroot_hdrs_suffix_spec)
6707 printf("%s\n", (target_sysroot_hdrs_suffix
6708 ? target_sysroot_hdrs_suffix
6709 : ""));
6710 return (0);
6712 else
6713 /* The error status indicates that only one set of fixed
6714 headers should be built. */
6715 fatal ("not configured with sysroot headers suffix");
6718 if (print_help_list)
6720 display_help ();
6722 if (! verbose_flag)
6724 printf (_("\nFor bug reporting instructions, please see:\n"));
6725 printf ("%s.\n", bug_report_url);
6727 return (0);
6730 /* We do not exit here. Instead we have created a fake input file
6731 called 'help-dummy' which needs to be compiled, and we pass this
6732 on the various sub-processes, along with the --help switch.
6733 Ensure their output appears after ours. */
6734 fputc ('\n', stdout);
6735 fflush (stdout);
6738 if (print_version)
6740 printf (_("%s %s%s\n"), programname, pkgversion_string,
6741 version_string);
6742 printf ("Copyright %s 2009 Free Software Foundation, Inc.\n",
6743 _("(C)"));
6744 fputs (_("This is free software; see the source for copying conditions. There is NO\n\
6745 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"),
6746 stdout);
6747 if (! verbose_flag)
6748 return 0;
6750 /* We do not exit here. We use the same mechanism of --help to print
6751 the version of the sub-processes. */
6752 fputc ('\n', stdout);
6753 fflush (stdout);
6756 if (verbose_flag)
6758 int n;
6759 const char *thrmod;
6761 notice ("Target: %s\n", spec_machine);
6762 notice ("Configured with: %s\n", configuration_arguments);
6764 #ifdef THREAD_MODEL_SPEC
6765 /* We could have defined THREAD_MODEL_SPEC to "%*" by default,
6766 but there's no point in doing all this processing just to get
6767 thread_model back. */
6768 obstack_init (&obstack);
6769 do_spec_1 (THREAD_MODEL_SPEC, 0, thread_model);
6770 obstack_1grow (&obstack, '\0');
6771 thrmod = XOBFINISH (&obstack, const char *);
6772 #else
6773 thrmod = thread_model;
6774 #endif
6776 notice ("Thread model: %s\n", thrmod);
6778 /* compiler_version is truncated at the first space when initialized
6779 from version string, so truncate version_string at the first space
6780 before comparing. */
6781 for (n = 0; version_string[n]; n++)
6782 if (version_string[n] == ' ')
6783 break;
6785 if (! strncmp (version_string, compiler_version, n)
6786 && compiler_version[n] == 0)
6787 notice ("gcc version %s %s\n", version_string, pkgversion_string);
6788 else
6789 notice ("gcc driver version %s %sexecuting gcc version %s\n",
6790 version_string, pkgversion_string, compiler_version);
6792 if (n_infiles == 0)
6793 return (0);
6796 if (n_infiles == added_libraries)
6797 fatal ("no input files");
6799 /* Make a place to record the compiler output file names
6800 that correspond to the input files. */
6802 i = n_infiles;
6803 i += lang_specific_extra_outfiles;
6804 outfiles = XCNEWVEC (const char *, i);
6806 /* Record which files were specified explicitly as link input. */
6808 explicit_link_files = XCNEWVEC (char, n_infiles);
6810 if (combine_flag)
6811 combine_inputs = true;
6812 else
6813 combine_inputs = false;
6815 for (i = 0; (int) i < n_infiles; i++)
6817 const char *name = infiles[i].name;
6818 struct compiler *compiler = lookup_compiler (name,
6819 strlen (name),
6820 infiles[i].language);
6822 if (compiler && !(compiler->combinable))
6823 combine_inputs = false;
6825 if (lang_n_infiles > 0 && compiler != input_file_compiler
6826 && infiles[i].language && infiles[i].language[0] != '*')
6827 infiles[i].incompiler = compiler;
6828 else if (compiler)
6830 lang_n_infiles++;
6831 input_file_compiler = compiler;
6832 infiles[i].incompiler = compiler;
6834 else
6836 /* Since there is no compiler for this input file, assume it is a
6837 linker file. */
6838 explicit_link_files[i] = 1;
6839 infiles[i].incompiler = NULL;
6841 infiles[i].compiled = false;
6842 infiles[i].preprocessed = false;
6845 if (!combine_inputs && have_c && have_o && lang_n_infiles > 1)
6846 fatal ("cannot specify -o with -c or -S with multiple files");
6848 if (combine_flag && save_temps_flag)
6850 bool save_combine_inputs = combine_inputs;
6851 /* Must do a separate pre-processing pass for C & Objective-C files, to
6852 obtain individual .i files. */
6854 combine_inputs = false;
6855 for (i = 0; (int) i < n_infiles; i++)
6857 int this_file_error = 0;
6859 input_file_number = i;
6860 set_input (infiles[i].name);
6861 if (infiles[i].incompiler
6862 && (infiles[i].incompiler)->needs_preprocessing)
6863 input_file_compiler = infiles[i].incompiler;
6864 else
6865 continue;
6867 if (input_file_compiler)
6869 if (input_file_compiler->spec[0] == '#')
6871 error ("%s: %s compiler not installed on this system",
6872 input_filename, &input_file_compiler->spec[1]);
6873 this_file_error = 1;
6875 else
6877 value = do_spec (input_file_compiler->spec);
6878 infiles[i].preprocessed = true;
6879 if (!have_o_argbuf_index)
6880 fatal ("spec '%s' is invalid", input_file_compiler->spec);
6881 infiles[i].name = argbuf[have_o_argbuf_index];
6882 infiles[i].incompiler
6883 = lookup_compiler (infiles[i].name,
6884 strlen (infiles[i].name),
6885 infiles[i].language);
6887 if (value < 0)
6888 this_file_error = 1;
6892 if (this_file_error)
6894 delete_failure_queue ();
6895 error_count++;
6896 break;
6898 clear_failure_queue ();
6900 combine_inputs = save_combine_inputs;
6903 for (i = 0; (int) i < n_infiles; i++)
6905 int this_file_error = 0;
6907 /* Tell do_spec what to substitute for %i. */
6909 input_file_number = i;
6910 set_input (infiles[i].name);
6912 if (infiles[i].compiled)
6913 continue;
6915 /* Use the same thing in %o, unless cp->spec says otherwise. */
6917 outfiles[i] = input_filename;
6919 /* Figure out which compiler from the file's suffix. */
6921 if (! combine_inputs)
6922 input_file_compiler
6923 = lookup_compiler (infiles[i].name, input_filename_length,
6924 infiles[i].language);
6925 else
6926 input_file_compiler = infiles[i].incompiler;
6928 if (input_file_compiler)
6930 /* Ok, we found an applicable compiler. Run its spec. */
6932 if (input_file_compiler->spec[0] == '#')
6934 error ("%s: %s compiler not installed on this system",
6935 input_filename, &input_file_compiler->spec[1]);
6936 this_file_error = 1;
6938 else
6940 value = do_spec (input_file_compiler->spec);
6941 infiles[i].compiled = true;
6942 if (value < 0)
6943 this_file_error = 1;
6947 /* If this file's name does not contain a recognized suffix,
6948 record it as explicit linker input. */
6950 else
6951 explicit_link_files[i] = 1;
6953 /* Clear the delete-on-failure queue, deleting the files in it
6954 if this compilation failed. */
6956 if (this_file_error)
6958 delete_failure_queue ();
6959 error_count++;
6961 /* If this compilation succeeded, don't delete those files later. */
6962 clear_failure_queue ();
6965 /* Reset the input file name to the first compile/object file name, for use
6966 with %b in LINK_SPEC. We use the first input file that we can find
6967 a compiler to compile it instead of using infiles.language since for
6968 languages other than C we use aliases that we then lookup later. */
6969 if (n_infiles > 0)
6971 int i;
6973 for (i = 0; i < n_infiles ; i++)
6974 if (infiles[i].language && infiles[i].language[0] != '*')
6976 set_input (infiles[i].name);
6977 break;
6981 if (error_count == 0)
6983 /* Make sure INPUT_FILE_NUMBER points to first available open
6984 slot. */
6985 input_file_number = n_infiles;
6986 if (lang_specific_pre_link ())
6987 error_count++;
6990 /* Determine if there are any linker input files. */
6991 num_linker_inputs = 0;
6992 for (i = 0; (int) i < n_infiles; i++)
6993 if (explicit_link_files[i] || outfiles[i] != NULL)
6994 num_linker_inputs++;
6996 /* Run ld to link all the compiler output files. */
6998 if (num_linker_inputs > 0 && error_count == 0 && print_subprocess_help < 2)
7000 int tmp = execution_count;
7002 /* We'll use ld if we can't find collect2. */
7003 if (! strcmp (linker_name_spec, "collect2"))
7005 char *s = find_a_file (&exec_prefixes, "collect2", X_OK, false);
7006 if (s == NULL)
7007 linker_name_spec = "ld";
7009 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
7010 for collect. */
7011 putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH", false);
7012 putenv_from_prefixes (&startfile_prefixes, LIBRARY_PATH_ENV, true);
7014 if (print_subprocess_help == 1)
7016 printf (_("\nLinker options\n==============\n\n"));
7017 printf (_("Use \"-Wl,OPTION\" to pass \"OPTION\""
7018 " to the linker.\n\n"));
7019 fflush (stdout);
7021 value = do_spec (link_command_spec);
7022 if (value < 0)
7023 error_count = 1;
7024 linker_was_run = (tmp != execution_count);
7027 /* If options said don't run linker,
7028 complain about input files to be given to the linker. */
7030 if (! linker_was_run && error_count == 0)
7031 for (i = 0; (int) i < n_infiles; i++)
7032 if (explicit_link_files[i]
7033 && !(infiles[i].language && infiles[i].language[0] == '*'))
7034 error ("%s: linker input file unused because linking not done",
7035 outfiles[i]);
7037 /* Delete some or all of the temporary files we made. */
7039 if (error_count)
7040 delete_failure_queue ();
7041 delete_temp_files ();
7043 if (print_help_list)
7045 printf (("\nFor bug reporting instructions, please see:\n"));
7046 printf ("%s\n", bug_report_url);
7049 return (signal_count != 0 ? 2
7050 : error_count > 0 ? (pass_exit_codes ? greatest_status : 1)
7051 : 0);
7054 /* Find the proper compilation spec for the file name NAME,
7055 whose length is LENGTH. LANGUAGE is the specified language,
7056 or 0 if this file is to be passed to the linker. */
7058 static struct compiler *
7059 lookup_compiler (const char *name, size_t length, const char *language)
7061 struct compiler *cp;
7063 /* If this was specified by the user to be a linker input, indicate that. */
7064 if (language != 0 && language[0] == '*')
7065 return 0;
7067 /* Otherwise, look for the language, if one is spec'd. */
7068 if (language != 0)
7070 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
7071 if (cp->suffix[0] == '@' && !strcmp (cp->suffix + 1, language))
7072 return cp;
7074 error ("language %s not recognized", language);
7075 return 0;
7078 /* Look for a suffix. */
7079 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
7081 if (/* The suffix `-' matches only the file name `-'. */
7082 (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
7083 || (strlen (cp->suffix) < length
7084 /* See if the suffix matches the end of NAME. */
7085 && !strcmp (cp->suffix,
7086 name + length - strlen (cp->suffix))
7088 break;
7091 #if defined (OS2) ||defined (HAVE_DOS_BASED_FILE_SYSTEM)
7092 /* Look again, but case-insensitively this time. */
7093 if (cp < compilers)
7094 for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
7096 if (/* The suffix `-' matches only the file name `-'. */
7097 (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
7098 || (strlen (cp->suffix) < length
7099 /* See if the suffix matches the end of NAME. */
7100 && ((!strcmp (cp->suffix,
7101 name + length - strlen (cp->suffix))
7102 || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
7103 && !strcasecmp (cp->suffix,
7104 name + length - strlen (cp->suffix)))
7106 break;
7108 #endif
7110 if (cp >= compilers)
7112 if (cp->spec[0] != '@')
7113 /* A non-alias entry: return it. */
7114 return cp;
7116 /* An alias entry maps a suffix to a language.
7117 Search for the language; pass 0 for NAME and LENGTH
7118 to avoid infinite recursion if language not found. */
7119 return lookup_compiler (NULL, 0, cp->spec + 1);
7121 return 0;
7124 static char *
7125 save_string (const char *s, int len)
7127 char *result = XNEWVEC (char, len + 1);
7129 memcpy (result, s, len);
7130 result[len] = 0;
7131 return result;
7134 void
7135 pfatal_with_name (const char *name)
7137 perror_with_name (name);
7138 delete_temp_files ();
7139 exit (1);
7142 static void
7143 perror_with_name (const char *name)
7145 error ("%s: %s", name, xstrerror (errno));
7148 /* Output an error message and exit. */
7150 void
7151 fancy_abort (const char *file, int line, const char *func)
7153 fatal_ice ("internal gcc abort in %s, at %s:%d", func, file, line);
7156 /* Output an error message and exit. */
7158 void
7159 fatal_ice (const char *cmsgid, ...)
7161 va_list ap;
7163 va_start (ap, cmsgid);
7165 fprintf (stderr, "%s: ", programname);
7166 vfprintf (stderr, _(cmsgid), ap);
7167 va_end (ap);
7168 fprintf (stderr, "\n");
7169 delete_temp_files ();
7170 exit (pass_exit_codes ? ICE_EXIT_CODE : 1);
7173 void
7174 fatal (const char *cmsgid, ...)
7176 va_list ap;
7178 va_start (ap, cmsgid);
7180 fprintf (stderr, "%s: ", programname);
7181 vfprintf (stderr, _(cmsgid), ap);
7182 va_end (ap);
7183 fprintf (stderr, "\n");
7184 delete_temp_files ();
7185 exit (1);
7188 /* The argument is actually c-format, not gcc-internal-format,
7189 but because functions with identical names are used through
7190 the rest of the compiler with gcc-internal-format, we just
7191 need to hope all users of these functions use the common
7192 subset between c-format and gcc-internal-format. */
7194 void
7195 error (const char *gmsgid, ...)
7197 va_list ap;
7199 va_start (ap, gmsgid);
7200 fprintf (stderr, "%s: ", programname);
7201 vfprintf (stderr, _(gmsgid), ap);
7202 va_end (ap);
7204 fprintf (stderr, "\n");
7207 static void
7208 notice (const char *cmsgid, ...)
7210 va_list ap;
7212 va_start (ap, cmsgid);
7213 vfprintf (stderr, _(cmsgid), ap);
7214 va_end (ap);
7217 static inline void
7218 validate_switches_from_spec (const char *spec)
7220 const char *p = spec;
7221 char c;
7222 while ((c = *p++))
7223 if (c == '%' && (*p == '{' || *p == '<' || (*p == 'W' && *++p == '{')))
7224 /* We have a switch spec. */
7225 p = validate_switches (p + 1);
7228 static void
7229 validate_all_switches (void)
7231 struct compiler *comp;
7232 struct spec_list *spec;
7234 for (comp = compilers; comp->spec; comp++)
7235 validate_switches_from_spec (comp->spec);
7237 /* Look through the linked list of specs read from the specs file. */
7238 for (spec = specs; spec; spec = spec->next)
7239 validate_switches_from_spec (*spec->ptr_spec);
7241 validate_switches_from_spec (link_command_spec);
7244 /* Look at the switch-name that comes after START
7245 and mark as valid all supplied switches that match it. */
7247 static const char *
7248 validate_switches (const char *start)
7250 const char *p = start;
7251 const char *atom;
7252 size_t len;
7253 int i;
7254 bool suffix = false;
7255 bool starred = false;
7257 #define SKIP_WHITE() do { while (*p == ' ' || *p == '\t') p++; } while (0)
7259 next_member:
7260 SKIP_WHITE ();
7262 if (*p == '!')
7263 p++;
7265 SKIP_WHITE ();
7266 if (*p == '.' || *p == ',')
7267 suffix = true, p++;
7269 atom = p;
7270 while (ISIDNUM (*p) || *p == '-' || *p == '+' || *p == '='
7271 || *p == ',' || *p == '.' || *p == '@')
7272 p++;
7273 len = p - atom;
7275 if (*p == '*')
7276 starred = true, p++;
7278 SKIP_WHITE ();
7280 if (!suffix)
7282 /* Mark all matching switches as valid. */
7283 for (i = 0; i < n_switches; i++)
7284 if (!strncmp (switches[i].part1, atom, len)
7285 && (starred || switches[i].part1[len] == 0))
7286 switches[i].validated = 1;
7289 if (*p) p++;
7290 if (*p && (p[-1] == '|' || p[-1] == '&'))
7291 goto next_member;
7293 if (*p && p[-1] == ':')
7295 while (*p && *p != ';' && *p != '}')
7297 if (*p == '%')
7299 p++;
7300 if (*p == '{' || *p == '<')
7301 p = validate_switches (p+1);
7302 else if (p[0] == 'W' && p[1] == '{')
7303 p = validate_switches (p+2);
7305 else
7306 p++;
7309 if (*p) p++;
7310 if (*p && p[-1] == ';')
7311 goto next_member;
7314 return p;
7315 #undef SKIP_WHITE
7318 struct mdswitchstr
7320 const char *str;
7321 int len;
7324 static struct mdswitchstr *mdswitches;
7325 static int n_mdswitches;
7327 /* Check whether a particular argument was used. The first time we
7328 canonicalize the switches to keep only the ones we care about. */
7330 static int
7331 used_arg (const char *p, int len)
7333 struct mswitchstr
7335 const char *str;
7336 const char *replace;
7337 int len;
7338 int rep_len;
7341 static struct mswitchstr *mswitches;
7342 static int n_mswitches;
7343 int i, j;
7345 if (!mswitches)
7347 struct mswitchstr *matches;
7348 const char *q;
7349 int cnt = 0;
7351 /* Break multilib_matches into the component strings of string
7352 and replacement string. */
7353 for (q = multilib_matches; *q != '\0'; q++)
7354 if (*q == ';')
7355 cnt++;
7357 matches
7358 = (struct mswitchstr *) alloca ((sizeof (struct mswitchstr)) * cnt);
7359 i = 0;
7360 q = multilib_matches;
7361 while (*q != '\0')
7363 matches[i].str = q;
7364 while (*q != ' ')
7366 if (*q == '\0')
7368 invalid_matches:
7369 fatal ("multilib spec '%s' is invalid", multilib_matches);
7371 q++;
7373 matches[i].len = q - matches[i].str;
7375 matches[i].replace = ++q;
7376 while (*q != ';' && *q != '\0')
7378 if (*q == ' ')
7379 goto invalid_matches;
7380 q++;
7382 matches[i].rep_len = q - matches[i].replace;
7383 i++;
7384 if (*q == ';')
7385 q++;
7388 /* Now build a list of the replacement string for switches that we care
7389 about. Make sure we allocate at least one entry. This prevents
7390 xmalloc from calling fatal, and prevents us from re-executing this
7391 block of code. */
7392 mswitches
7393 = XNEWVEC (struct mswitchstr, n_mdswitches + (n_switches ? n_switches : 1));
7394 for (i = 0; i < n_switches; i++)
7395 if ((switches[i].live_cond & SWITCH_IGNORE) == 0)
7397 int xlen = strlen (switches[i].part1);
7398 for (j = 0; j < cnt; j++)
7399 if (xlen == matches[j].len
7400 && ! strncmp (switches[i].part1, matches[j].str, xlen))
7402 mswitches[n_mswitches].str = matches[j].replace;
7403 mswitches[n_mswitches].len = matches[j].rep_len;
7404 mswitches[n_mswitches].replace = (char *) 0;
7405 mswitches[n_mswitches].rep_len = 0;
7406 n_mswitches++;
7407 break;
7411 /* Add MULTILIB_DEFAULTS switches too, as long as they were not present
7412 on the command line nor any options mutually incompatible with
7413 them. */
7414 for (i = 0; i < n_mdswitches; i++)
7416 const char *r;
7418 for (q = multilib_options; *q != '\0'; q++)
7420 while (*q == ' ')
7421 q++;
7423 r = q;
7424 while (strncmp (q, mdswitches[i].str, mdswitches[i].len) != 0
7425 || strchr (" /", q[mdswitches[i].len]) == NULL)
7427 while (*q != ' ' && *q != '/' && *q != '\0')
7428 q++;
7429 if (*q != '/')
7430 break;
7431 q++;
7434 if (*q != ' ' && *q != '\0')
7436 while (*r != ' ' && *r != '\0')
7438 q = r;
7439 while (*q != ' ' && *q != '/' && *q != '\0')
7440 q++;
7442 if (used_arg (r, q - r))
7443 break;
7445 if (*q != '/')
7447 mswitches[n_mswitches].str = mdswitches[i].str;
7448 mswitches[n_mswitches].len = mdswitches[i].len;
7449 mswitches[n_mswitches].replace = (char *) 0;
7450 mswitches[n_mswitches].rep_len = 0;
7451 n_mswitches++;
7452 break;
7455 r = q + 1;
7457 break;
7463 for (i = 0; i < n_mswitches; i++)
7464 if (len == mswitches[i].len && ! strncmp (p, mswitches[i].str, len))
7465 return 1;
7467 return 0;
7470 static int
7471 default_arg (const char *p, int len)
7473 int i;
7475 for (i = 0; i < n_mdswitches; i++)
7476 if (len == mdswitches[i].len && ! strncmp (p, mdswitches[i].str, len))
7477 return 1;
7479 return 0;
7482 /* Work out the subdirectory to use based on the options. The format of
7483 multilib_select is a list of elements. Each element is a subdirectory
7484 name followed by a list of options followed by a semicolon. The format
7485 of multilib_exclusions is the same, but without the preceding
7486 directory. First gcc will check the exclusions, if none of the options
7487 beginning with an exclamation point are present, and all of the other
7488 options are present, then we will ignore this completely. Passing
7489 that, gcc will consider each multilib_select in turn using the same
7490 rules for matching the options. If a match is found, that subdirectory
7491 will be used. */
7493 static void
7494 set_multilib_dir (void)
7496 const char *p;
7497 unsigned int this_path_len;
7498 const char *this_path, *this_arg;
7499 const char *start, *end;
7500 int not_arg;
7501 int ok, ndfltok, first;
7503 n_mdswitches = 0;
7504 start = multilib_defaults;
7505 while (*start == ' ' || *start == '\t')
7506 start++;
7507 while (*start != '\0')
7509 n_mdswitches++;
7510 while (*start != ' ' && *start != '\t' && *start != '\0')
7511 start++;
7512 while (*start == ' ' || *start == '\t')
7513 start++;
7516 if (n_mdswitches)
7518 int i = 0;
7520 mdswitches = XNEWVEC (struct mdswitchstr, n_mdswitches);
7521 for (start = multilib_defaults; *start != '\0'; start = end + 1)
7523 while (*start == ' ' || *start == '\t')
7524 start++;
7526 if (*start == '\0')
7527 break;
7529 for (end = start + 1;
7530 *end != ' ' && *end != '\t' && *end != '\0'; end++)
7533 obstack_grow (&multilib_obstack, start, end - start);
7534 obstack_1grow (&multilib_obstack, 0);
7535 mdswitches[i].str = XOBFINISH (&multilib_obstack, const char *);
7536 mdswitches[i++].len = end - start;
7538 if (*end == '\0')
7539 break;
7543 p = multilib_exclusions;
7544 while (*p != '\0')
7546 /* Ignore newlines. */
7547 if (*p == '\n')
7549 ++p;
7550 continue;
7553 /* Check the arguments. */
7554 ok = 1;
7555 while (*p != ';')
7557 if (*p == '\0')
7559 invalid_exclusions:
7560 fatal ("multilib exclusions '%s' is invalid",
7561 multilib_exclusions);
7564 if (! ok)
7566 ++p;
7567 continue;
7570 this_arg = p;
7571 while (*p != ' ' && *p != ';')
7573 if (*p == '\0')
7574 goto invalid_exclusions;
7575 ++p;
7578 if (*this_arg != '!')
7579 not_arg = 0;
7580 else
7582 not_arg = 1;
7583 ++this_arg;
7586 ok = used_arg (this_arg, p - this_arg);
7587 if (not_arg)
7588 ok = ! ok;
7590 if (*p == ' ')
7591 ++p;
7594 if (ok)
7595 return;
7597 ++p;
7600 first = 1;
7601 p = multilib_select;
7602 while (*p != '\0')
7604 /* Ignore newlines. */
7605 if (*p == '\n')
7607 ++p;
7608 continue;
7611 /* Get the initial path. */
7612 this_path = p;
7613 while (*p != ' ')
7615 if (*p == '\0')
7617 invalid_select:
7618 fatal ("multilib select '%s' is invalid",
7619 multilib_select);
7621 ++p;
7623 this_path_len = p - this_path;
7625 /* Check the arguments. */
7626 ok = 1;
7627 ndfltok = 1;
7628 ++p;
7629 while (*p != ';')
7631 if (*p == '\0')
7632 goto invalid_select;
7634 if (! ok)
7636 ++p;
7637 continue;
7640 this_arg = p;
7641 while (*p != ' ' && *p != ';')
7643 if (*p == '\0')
7644 goto invalid_select;
7645 ++p;
7648 if (*this_arg != '!')
7649 not_arg = 0;
7650 else
7652 not_arg = 1;
7653 ++this_arg;
7656 /* If this is a default argument, we can just ignore it.
7657 This is true even if this_arg begins with '!'. Beginning
7658 with '!' does not mean that this argument is necessarily
7659 inappropriate for this library: it merely means that
7660 there is a more specific library which uses this
7661 argument. If this argument is a default, we need not
7662 consider that more specific library. */
7663 ok = used_arg (this_arg, p - this_arg);
7664 if (not_arg)
7665 ok = ! ok;
7667 if (! ok)
7668 ndfltok = 0;
7670 if (default_arg (this_arg, p - this_arg))
7671 ok = 1;
7673 if (*p == ' ')
7674 ++p;
7677 if (ok && first)
7679 if (this_path_len != 1
7680 || this_path[0] != '.')
7682 char *new_multilib_dir = XNEWVEC (char, this_path_len + 1);
7683 char *q;
7685 strncpy (new_multilib_dir, this_path, this_path_len);
7686 new_multilib_dir[this_path_len] = '\0';
7687 q = strchr (new_multilib_dir, ':');
7688 if (q != NULL)
7689 *q = '\0';
7690 multilib_dir = new_multilib_dir;
7692 first = 0;
7695 if (ndfltok)
7697 const char *q = this_path, *end = this_path + this_path_len;
7699 while (q < end && *q != ':')
7700 q++;
7701 if (q < end)
7703 char *new_multilib_os_dir = XNEWVEC (char, end - q);
7704 memcpy (new_multilib_os_dir, q + 1, end - q - 1);
7705 new_multilib_os_dir[end - q - 1] = '\0';
7706 multilib_os_dir = new_multilib_os_dir;
7707 break;
7711 ++p;
7714 if (multilib_dir == NULL && multilib_os_dir != NULL
7715 && strcmp (multilib_os_dir, ".") == 0)
7717 free (CONST_CAST (char *, multilib_os_dir));
7718 multilib_os_dir = NULL;
7720 else if (multilib_dir != NULL && multilib_os_dir == NULL)
7721 multilib_os_dir = multilib_dir;
7724 /* Print out the multiple library subdirectory selection
7725 information. This prints out a series of lines. Each line looks
7726 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
7727 required. Only the desired options are printed out, the negative
7728 matches. The options are print without a leading dash. There are
7729 no spaces to make it easy to use the information in the shell.
7730 Each subdirectory is printed only once. This assumes the ordering
7731 generated by the genmultilib script. Also, we leave out ones that match
7732 the exclusions. */
7734 static void
7735 print_multilib_info (void)
7737 const char *p = multilib_select;
7738 const char *last_path = 0, *this_path;
7739 int skip;
7740 unsigned int last_path_len = 0;
7742 while (*p != '\0')
7744 skip = 0;
7745 /* Ignore newlines. */
7746 if (*p == '\n')
7748 ++p;
7749 continue;
7752 /* Get the initial path. */
7753 this_path = p;
7754 while (*p != ' ')
7756 if (*p == '\0')
7758 invalid_select:
7759 fatal ("multilib select '%s' is invalid", multilib_select);
7762 ++p;
7765 /* When --disable-multilib was used but target defines
7766 MULTILIB_OSDIRNAMES, entries starting with .: are there just
7767 to find multilib_os_dir, so skip them from output. */
7768 if (this_path[0] == '.' && this_path[1] == ':')
7769 skip = 1;
7771 /* Check for matches with the multilib_exclusions. We don't bother
7772 with the '!' in either list. If any of the exclusion rules match
7773 all of its options with the select rule, we skip it. */
7775 const char *e = multilib_exclusions;
7776 const char *this_arg;
7778 while (*e != '\0')
7780 int m = 1;
7781 /* Ignore newlines. */
7782 if (*e == '\n')
7784 ++e;
7785 continue;
7788 /* Check the arguments. */
7789 while (*e != ';')
7791 const char *q;
7792 int mp = 0;
7794 if (*e == '\0')
7796 invalid_exclusion:
7797 fatal ("multilib exclusion '%s' is invalid",
7798 multilib_exclusions);
7801 if (! m)
7803 ++e;
7804 continue;
7807 this_arg = e;
7809 while (*e != ' ' && *e != ';')
7811 if (*e == '\0')
7812 goto invalid_exclusion;
7813 ++e;
7816 q = p + 1;
7817 while (*q != ';')
7819 const char *arg;
7820 int len = e - this_arg;
7822 if (*q == '\0')
7823 goto invalid_select;
7825 arg = q;
7827 while (*q != ' ' && *q != ';')
7829 if (*q == '\0')
7830 goto invalid_select;
7831 ++q;
7834 if (! strncmp (arg, this_arg,
7835 (len < q - arg) ? q - arg : len)
7836 || default_arg (this_arg, e - this_arg))
7838 mp = 1;
7839 break;
7842 if (*q == ' ')
7843 ++q;
7846 if (! mp)
7847 m = 0;
7849 if (*e == ' ')
7850 ++e;
7853 if (m)
7855 skip = 1;
7856 break;
7859 if (*e != '\0')
7860 ++e;
7864 if (! skip)
7866 /* If this is a duplicate, skip it. */
7867 skip = (last_path != 0
7868 && (unsigned int) (p - this_path) == last_path_len
7869 && ! strncmp (last_path, this_path, last_path_len));
7871 last_path = this_path;
7872 last_path_len = p - this_path;
7875 /* If this directory requires any default arguments, we can skip
7876 it. We will already have printed a directory identical to
7877 this one which does not require that default argument. */
7878 if (! skip)
7880 const char *q;
7882 q = p + 1;
7883 while (*q != ';')
7885 const char *arg;
7887 if (*q == '\0')
7888 goto invalid_select;
7890 if (*q == '!')
7891 arg = NULL;
7892 else
7893 arg = q;
7895 while (*q != ' ' && *q != ';')
7897 if (*q == '\0')
7898 goto invalid_select;
7899 ++q;
7902 if (arg != NULL
7903 && default_arg (arg, q - arg))
7905 skip = 1;
7906 break;
7909 if (*q == ' ')
7910 ++q;
7914 if (! skip)
7916 const char *p1;
7918 for (p1 = last_path; p1 < p && *p1 != ':'; p1++)
7919 putchar (*p1);
7920 putchar (';');
7923 ++p;
7924 while (*p != ';')
7926 int use_arg;
7928 if (*p == '\0')
7929 goto invalid_select;
7931 if (skip)
7933 ++p;
7934 continue;
7937 use_arg = *p != '!';
7939 if (use_arg)
7940 putchar ('@');
7942 while (*p != ' ' && *p != ';')
7944 if (*p == '\0')
7945 goto invalid_select;
7946 if (use_arg)
7947 putchar (*p);
7948 ++p;
7951 if (*p == ' ')
7952 ++p;
7955 if (! skip)
7957 /* If there are extra options, print them now. */
7958 if (multilib_extra && *multilib_extra)
7960 int print_at = TRUE;
7961 const char *q;
7963 for (q = multilib_extra; *q != '\0'; q++)
7965 if (*q == ' ')
7966 print_at = TRUE;
7967 else
7969 if (print_at)
7970 putchar ('@');
7971 putchar (*q);
7972 print_at = FALSE;
7977 putchar ('\n');
7980 ++p;
7984 /* getenv built-in spec function.
7986 Returns the value of the environment variable given by its first
7987 argument, concatenated with the second argument. If the
7988 environment variable is not defined, a fatal error is issued. */
7990 static const char *
7991 getenv_spec_function (int argc, const char **argv)
7993 char *value;
7994 char *result;
7995 char *ptr;
7996 size_t len;
7998 if (argc != 2)
7999 return NULL;
8001 value = getenv (argv[0]);
8002 if (!value)
8003 fatal ("environment variable \"%s\" not defined", argv[0]);
8005 /* We have to escape every character of the environment variable so
8006 they are not interpreted as active spec characters. A
8007 particularly painful case is when we are reading a variable
8008 holding a windows path complete with \ separators. */
8009 len = strlen (value) * 2 + strlen (argv[1]) + 1;
8010 result = XNEWVAR (char, len);
8011 for (ptr = result; *value; ptr += 2)
8013 ptr[0] = '\\';
8014 ptr[1] = *value++;
8017 strcpy (ptr, argv[1]);
8019 return result;
8022 /* if-exists built-in spec function.
8024 Checks to see if the file specified by the absolute pathname in
8025 ARGS exists. Returns that pathname if found.
8027 The usual use for this function is to check for a library file
8028 (whose name has been expanded with %s). */
8030 static const char *
8031 if_exists_spec_function (int argc, const char **argv)
8033 /* Must have only one argument. */
8034 if (argc == 1 && IS_ABSOLUTE_PATH (argv[0]) && ! access (argv[0], R_OK))
8035 return argv[0];
8037 return NULL;
8040 /* if-exists-else built-in spec function.
8042 This is like if-exists, but takes an additional argument which
8043 is returned if the first argument does not exist. */
8045 static const char *
8046 if_exists_else_spec_function (int argc, const char **argv)
8048 /* Must have exactly two arguments. */
8049 if (argc != 2)
8050 return NULL;
8052 if (IS_ABSOLUTE_PATH (argv[0]) && ! access (argv[0], R_OK))
8053 return argv[0];
8055 return argv[1];
8058 /* replace-outfile built-in spec function.
8060 This looks for the first argument in the outfiles array's name and
8061 replaces it with the second argument. */
8063 static const char *
8064 replace_outfile_spec_function (int argc, const char **argv)
8066 int i;
8067 /* Must have exactly two arguments. */
8068 if (argc != 2)
8069 abort ();
8071 for (i = 0; i < n_infiles; i++)
8073 if (outfiles[i] && !strcmp (outfiles[i], argv[0]))
8074 outfiles[i] = xstrdup (argv[1]);
8076 return NULL;
8079 /* Given two version numbers, compares the two numbers.
8080 A version number must match the regular expression
8081 ([1-9][0-9]*|0)(\.([1-9][0-9]*|0))*
8083 static int
8084 compare_version_strings (const char *v1, const char *v2)
8086 int rresult;
8087 regex_t r;
8089 if (regcomp (&r, "^([1-9][0-9]*|0)(\\.([1-9][0-9]*|0))*$",
8090 REG_EXTENDED | REG_NOSUB) != 0)
8091 abort ();
8092 rresult = regexec (&r, v1, 0, NULL, 0);
8093 if (rresult == REG_NOMATCH)
8094 fatal ("invalid version number `%s'", v1);
8095 else if (rresult != 0)
8096 abort ();
8097 rresult = regexec (&r, v2, 0, NULL, 0);
8098 if (rresult == REG_NOMATCH)
8099 fatal ("invalid version number `%s'", v2);
8100 else if (rresult != 0)
8101 abort ();
8103 return strverscmp (v1, v2);
8107 /* version_compare built-in spec function.
8109 This takes an argument of the following form:
8111 <comparison-op> <arg1> [<arg2>] <switch> <result>
8113 and produces "result" if the comparison evaluates to true,
8114 and nothing if it doesn't.
8116 The supported <comparison-op> values are:
8118 >= true if switch is a later (or same) version than arg1
8119 !> opposite of >=
8120 < true if switch is an earlier version than arg1
8121 !< opposite of <
8122 >< true if switch is arg1 or later, and earlier than arg2
8123 <> true if switch is earlier than arg1 or is arg2 or later
8125 If the switch is not present, the condition is false unless
8126 the first character of the <comparison-op> is '!'.
8128 For example,
8129 %:version-compare(>= 10.3 mmacosx-version-min= -lmx)
8130 adds -lmx if -mmacosx-version-min=10.3.9 was passed. */
8132 static const char *
8133 version_compare_spec_function (int argc, const char **argv)
8135 int comp1, comp2;
8136 size_t switch_len;
8137 const char *switch_value = NULL;
8138 int nargs = 1, i;
8139 bool result;
8141 if (argc < 3)
8142 fatal ("too few arguments to %%:version-compare");
8143 if (argv[0][0] == '\0')
8144 abort ();
8145 if ((argv[0][1] == '<' || argv[0][1] == '>') && argv[0][0] != '!')
8146 nargs = 2;
8147 if (argc != nargs + 3)
8148 fatal ("too many arguments to %%:version-compare");
8150 switch_len = strlen (argv[nargs + 1]);
8151 for (i = 0; i < n_switches; i++)
8152 if (!strncmp (switches[i].part1, argv[nargs + 1], switch_len)
8153 && check_live_switch (i, switch_len))
8154 switch_value = switches[i].part1 + switch_len;
8156 if (switch_value == NULL)
8157 comp1 = comp2 = -1;
8158 else
8160 comp1 = compare_version_strings (switch_value, argv[1]);
8161 if (nargs == 2)
8162 comp2 = compare_version_strings (switch_value, argv[2]);
8163 else
8164 comp2 = -1; /* This value unused. */
8167 switch (argv[0][0] << 8 | argv[0][1])
8169 case '>' << 8 | '=':
8170 result = comp1 >= 0;
8171 break;
8172 case '!' << 8 | '<':
8173 result = comp1 >= 0 || switch_value == NULL;
8174 break;
8175 case '<' << 8:
8176 result = comp1 < 0;
8177 break;
8178 case '!' << 8 | '>':
8179 result = comp1 < 0 || switch_value == NULL;
8180 break;
8181 case '>' << 8 | '<':
8182 result = comp1 >= 0 && comp2 < 0;
8183 break;
8184 case '<' << 8 | '>':
8185 result = comp1 < 0 || comp2 >= 0;
8186 break;
8188 default:
8189 fatal ("unknown operator '%s' in %%:version-compare", argv[0]);
8191 if (! result)
8192 return NULL;
8194 return argv[nargs + 2];
8197 /* %:include builtin spec function. This differs from %include in that it
8198 can be nested inside a spec, and thus be conditionalized. It takes
8199 one argument, the filename, and looks for it in the startfile path.
8200 The result is always NULL, i.e. an empty expansion. */
8202 static const char *
8203 include_spec_function (int argc, const char **argv)
8205 char *file;
8207 if (argc != 1)
8208 abort ();
8210 file = find_a_file (&startfile_prefixes, argv[0], R_OK, true);
8211 read_specs (file ? file : argv[0], FALSE);
8213 return NULL;
8216 /* %:print-asm-header spec function. Print a banner to say that the
8217 following output is from the assembler. */
8219 static const char *
8220 print_asm_header_spec_function (int arg ATTRIBUTE_UNUSED,
8221 const char **argv ATTRIBUTE_UNUSED)
8223 printf (_("Assembler options\n=================\n\n"));
8224 printf (_("Use \"-Wa,OPTION\" to pass \"OPTION\" to the assembler.\n\n"));
8225 fflush (stdout);
8226 return NULL;