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,
5 Free Software Foundation, Inc.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
23 /* This program is the user interface to the C compiler and possibly to
24 other compilers. It is used because compilation is a complicated procedure
25 which involves running several programs and passing temporary files between
26 them, forwarding the users switches to those programs selectively,
27 and deleting the temporary files at the end.
29 CC recognizes how to compile each input file by suffixes in the file names.
30 Once it knows which kind of compilation to perform, the procedure for
31 compilation is specified by a string called a "spec". */
33 /* A Short Introduction to Adding a Command-Line Option.
35 Before adding a command-line option, consider if it is really
36 necessary. Each additional command-line option adds complexity and
37 is difficult to remove in subsequent versions.
39 In the following, consider adding the command-line argument
42 1. Each command-line option is specified in the specs file. The
43 notation is described below in the comment entitled "The Specs
46 2. In this file, add an entry to "option_map" equating the long
47 `--' argument version and any shorter, single letter version. Read
48 the comments in the declaration of "struct option_map" for an
49 explanation. Do not omit the first `-'.
51 3. Look in the "specs" file to determine which program or option
52 list should be given the argument, e.g., "cc1_options". Add the
53 appropriate syntax for the shorter option version to the
54 corresponding "const char *" entry in this file. Omit the first
55 `-' from the option. For example, use `-bar', rather than `--bar'.
57 4. If the argument takes an argument, e.g., `--baz argument1',
58 modify either DEFAULT_SWITCH_TAKES_ARG or
59 DEFAULT_WORD_SWITCH_TAKES_ARG in gcc.h. Omit the first `-'
62 5. Document the option in this file's display_help(). If the
63 option is passed to a subprogram, modify its corresponding
64 function, e.g., cppinit.c:print_help() or toplev.c:display_help(),
67 6. Compile and test. Make sure that your new specs file is being
68 read. For example, use a debugger to investigate the value of
69 "specs_file" in main(). */
73 #include "coretypes.h"
74 #include "multilib.h" /* before tm.h */
77 #if ! defined( SIGCHLD ) && defined( SIGCLD )
78 # define SIGCHLD SIGCLD
85 #include "diagnostic.h"
90 # include <sys/mman.h>
92 /* This is on Solaris. */
93 # include <sys/types.h>
98 # define MAP_FAILED ((void *)-1)
101 /* By default there is no special suffix for target executables. */
102 /* FIXME: when autoconf is fixed, remove the host check - dj */
103 #if defined(TARGET_EXECUTABLE_SUFFIX) && defined(HOST_EXECUTABLE_SUFFIX)
104 #define HAVE_TARGET_EXECUTABLE_SUFFIX
107 /* By default there is no special suffix for host executables. */
108 #ifdef HOST_EXECUTABLE_SUFFIX
109 #define HAVE_HOST_EXECUTABLE_SUFFIX
111 #define HOST_EXECUTABLE_SUFFIX ""
114 /* By default, the suffix for target object files is ".o". */
115 #ifdef TARGET_OBJECT_SUFFIX
116 #define HAVE_TARGET_OBJECT_SUFFIX
118 #define TARGET_OBJECT_SUFFIX ".o"
121 static const char dir_separator_str
[] = { DIR_SEPARATOR
, 0 };
123 /* Most every one is fine with LIBRARY_PATH. For some, it conflicts. */
124 #ifndef LIBRARY_PATH_ENV
125 #define LIBRARY_PATH_ENV "LIBRARY_PATH"
129 #define kill(p,s) raise(s)
132 /* If a stage of compilation returns an exit status >= 1,
133 compilation of that file ceases. */
135 #define MIN_FATAL_STATUS 1
137 /* Flag set by cppspec.c to 1. */
140 /* Flag set to nonzero if an @file argument has been supplied to gcc. */
141 static bool at_file_supplied
;
143 /* Definition of string containing the arguments given to configure. */
144 #include "configargs.h"
146 /* Flag saying to print the command line options understood by gcc and its
149 static int print_help_list
;
151 /* Flag saying to print the version of gcc and its sub-processes. */
153 static int print_version
;
155 /* Flag indicating whether we should print the command and arguments */
157 static int verbose_flag
;
159 /* Flag indicating whether we should ONLY print the command and
160 arguments (like verbose_flag) without executing the command.
161 Displayed arguments are quoted so that the generated command
162 line is suitable for execution. This is intended for use in
163 shell scripts to capture the driver-generated command line. */
164 static int verbose_only_flag
;
166 /* Flag indicating how to print command line options of sub-processes. */
168 static int print_subprocess_help
;
170 /* Whether we should report subprocess execution times to a file. */
172 FILE *report_times_to_file
= NULL
;
174 /* Nonzero means place this string before uses of /, so that include
175 and library files can be found in an alternate location. */
177 #ifdef TARGET_SYSTEM_ROOT
178 static const char *target_system_root
= TARGET_SYSTEM_ROOT
;
180 static const char *target_system_root
= 0;
183 /* Nonzero means pass the updated target_system_root to the compiler. */
185 static int target_system_root_changed
;
187 /* Nonzero means append this string to target_system_root. */
189 static const char *target_sysroot_suffix
= 0;
191 /* Nonzero means append this string to target_system_root for headers. */
193 static const char *target_sysroot_hdrs_suffix
= 0;
195 /* Nonzero means write "temp" files in source directory
196 and use the source file's name in them, and don't delete them. */
198 static enum save_temps
{
199 SAVE_TEMPS_NONE
, /* no -save-temps */
200 SAVE_TEMPS_CWD
, /* -save-temps in current directory */
201 SAVE_TEMPS_OBJ
/* -save-temps in object directory */
204 /* Output file to use to get the object directory for -save-temps=obj */
205 static char *save_temps_prefix
= 0;
206 static size_t save_temps_length
= 0;
208 /* The compiler version. */
210 static const char *compiler_version
;
212 /* The target version. */
214 static const char *const spec_version
= DEFAULT_TARGET_VERSION
;
216 /* The target machine. */
218 static const char *spec_machine
= DEFAULT_TARGET_MACHINE
;
220 /* Nonzero if cross-compiling.
221 When -b is used, the value comes from the `specs' file. */
223 #ifdef CROSS_DIRECTORY_STRUCTURE
224 static const char *cross_compile
= "1";
226 static const char *cross_compile
= "0";
229 /* Greatest exit code of sub-processes that has been encountered up to
231 static int greatest_status
= 1;
233 /* This is the obstack which we use to allocate many strings. */
235 static struct obstack obstack
;
237 /* This is the obstack to build an environment variable to pass to
238 collect2 that describes all of the relevant switches of what to
239 pass the compiler in building the list of pointers to constructors
242 static struct obstack collect_obstack
;
244 /* Forward declaration for prototypes. */
248 static void init_spec (void);
249 static void store_arg (const char *, int, int);
250 static void insert_wrapper (const char *);
251 static char *load_specs (const char *);
252 static void read_specs (const char *, int);
253 static void set_spec (const char *, const char *);
254 static struct compiler
*lookup_compiler (const char *, size_t, const char *);
255 static char *build_search_list (const struct path_prefix
*, const char *,
257 static void xputenv (const char *);
258 static void putenv_from_prefixes (const struct path_prefix
*, const char *,
260 static int access_check (const char *, int);
261 static char *find_a_file (const struct path_prefix
*, const char *, int, bool);
262 static void add_prefix (struct path_prefix
*, const char *, const char *,
264 static void add_sysrooted_prefix (struct path_prefix
*, const char *,
265 const char *, int, int, int);
266 static void translate_options (int *, const char *const **);
267 static char *skip_whitespace (char *);
268 static void delete_if_ordinary (const char *);
269 static void delete_temp_files (void);
270 static void delete_failure_queue (void);
271 static void clear_failure_queue (void);
272 static int check_live_switch (int, int);
273 static const char *handle_braces (const char *);
274 static inline bool input_suffix_matches (const char *, const char *);
275 static inline bool switch_matches (const char *, const char *, int);
276 static inline void mark_matching_switches (const char *, const char *, int);
277 static inline void process_marked_switches (void);
278 static const char *process_brace_body (const char *, const char *, const char *, int, int);
279 static const struct spec_function
*lookup_spec_function (const char *);
280 static const char *eval_spec_function (const char *, const char *);
281 static const char *handle_spec_function (const char *);
282 static char *save_string (const char *, int);
283 static void set_collect_gcc_options (void);
284 static int do_spec_1 (const char *, int, const char *);
285 static int do_spec_2 (const char *);
286 static void do_option_spec (const char *, const char *);
287 static void do_self_spec (const char *);
288 static const char *find_file (const char *);
289 static int is_directory (const char *, bool);
290 static const char *validate_switches (const char *);
291 static void validate_all_switches (void);
292 static inline void validate_switches_from_spec (const char *);
293 static void give_switch (int, int);
294 static int used_arg (const char *, int);
295 static int default_arg (const char *, int);
296 static void set_multilib_dir (void);
297 static void print_multilib_info (void);
298 static void perror_with_name (const char *);
299 static void display_help (void);
300 static void add_preprocessor_option (const char *, int);
301 static void add_assembler_option (const char *, int);
302 static void add_linker_option (const char *, int);
303 static void process_command (int, const char **);
304 static int execute (void);
305 static void alloc_args (void);
306 static void clear_args (void);
307 static void fatal_signal (int);
308 #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC)
309 static void init_gcc_specs (struct obstack
*, const char *, const char *,
312 #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
313 static const char *convert_filename (const char *, int, int);
316 static const char *getenv_spec_function (int, const char **);
317 static const char *if_exists_spec_function (int, const char **);
318 static const char *if_exists_else_spec_function (int, const char **);
319 static const char *replace_outfile_spec_function (int, const char **);
320 static const char *version_compare_spec_function (int, const char **);
321 static const char *include_spec_function (int, const char **);
322 static const char *find_file_spec_function (int, const char **);
323 static const char *find_plugindir_spec_function (int, const char **);
324 static const char *print_asm_header_spec_function (int, const char **);
325 static const char *compare_debug_dump_opt_spec_function (int, const char **);
326 static const char *compare_debug_self_opt_spec_function (int, const char **);
327 static const char *compare_debug_auxbase_opt_spec_function (int, const char **);
329 /* The Specs Language
331 Specs are strings containing lines, each of which (if not blank)
332 is made up of a program name, and arguments separated by spaces.
333 The program name must be exact and start from root, since no path
334 is searched and it is unreliable to depend on the current working directory.
335 Redirection of input or output is not supported; the subprograms must
336 accept filenames saying what files to read and write.
338 In addition, the specs can contain %-sequences to substitute variable text
339 or for conditional text. Here is a table of all defined %-sequences.
340 Note that spaces are not generated automatically around the results of
341 expanding these sequences; therefore, you can concatenate them together
342 or with constant text in a single argument.
344 %% substitute one % into the program name or argument.
345 %i substitute the name of the input file being processed.
346 %b substitute the basename of the input file being processed.
347 This is the substring up to (and not including) the last period
348 and not including the directory unless -save-temps was specified
349 to put temporaries in a different location.
350 %B same as %b, but include the file suffix (text after the last period).
352 substitute a file name that has suffix SUFFIX and is chosen
353 once per compilation, and mark the argument a la %d. To reduce
354 exposure to denial-of-service attacks, the file name is now
355 chosen in a way that is hard to predict even when previously
356 chosen file names are known. For example, `%g.s ... %g.o ... %g.s'
357 might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches
358 the regexp "[.0-9A-Za-z]*%O"; "%O" is treated exactly as if it
359 had been pre-processed. Previously, %g was simply substituted
360 with a file name chosen once per compilation, without regard
361 to any appended suffix (which was therefore treated just like
362 ordinary text), making such attacks more likely to succeed.
364 like %g, but if -pipe is in effect, expands simply to "-".
366 like %g, but if -pipe is in effect, expands to nothing. (We have both
367 %| and %m to accommodate differences between system assemblers; see
368 the AS_NEEDS_DASH_FOR_PIPED_INPUT target macro.)
370 like %g, but generates a new temporary file name even if %uSUFFIX
373 substitutes the last file name generated with %uSUFFIX, generating a
374 new one if there is no such last file name. In the absence of any
375 %uSUFFIX, this is just like %gSUFFIX, except they don't share
376 the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s'
377 would involve the generation of two distinct file names, one
378 for each `%g.s' and another for each `%U.s'. Previously, %U was
379 simply substituted with a file name chosen for the previous %u,
380 without regard to any appended suffix.
382 substitutes the name of the HOST_BIT_BUCKET, if any, and if it is
383 writable, and if save-temps is off; otherwise, substitute the name
384 of a temporary file, just like %u. This temporary file is not
385 meant for communication between processes, but rather as a junk
388 substitutes .SUFFIX for the suffixes of a matched switch's args when
389 it is subsequently output with %*. SUFFIX is terminated by the next
391 %d marks the argument containing or following the %d as a
392 temporary file name, so that that file will be deleted if GCC exits
393 successfully. Unlike %g, this contributes no text to the argument.
394 %w marks the argument containing or following the %w as the
395 "output file" of this compilation. This puts the argument
396 into the sequence of arguments that %o will substitute later.
397 %V indicates that this compilation produces no "output file".
399 like %{...} but mark last argument supplied within
400 as a file to be deleted on failure.
401 %o substitutes the names of all the output files, with spaces
402 automatically placed around them. You should write spaces
403 around the %o as well or the results are undefined.
404 %o is for use in the specs for running the linker.
405 Input files whose names have no recognized suffix are not compiled
406 at all, but they are included among the output files, so they will
408 %O substitutes the suffix for object files. Note that this is
409 handled specially when it immediately follows %g, %u, or %U
410 (with or without a suffix argument) because of the need for
411 those to form complete file names. The handling is such that
412 %O is treated exactly as if it had already been substituted,
413 except that %g, %u, and %U do not currently support additional
414 SUFFIX characters following %O as they would following, for
416 %I Substitute any of -iprefix (made from GCC_EXEC_PREFIX), -isysroot
417 (made from TARGET_SYSTEM_ROOT), -isystem (made from COMPILER_PATH
418 and -B options) and -imultilib as necessary.
419 %s current argument is the name of a library or startup file of some sort.
420 Search for that file in a standard list of directories
421 and substitute the full name found.
422 %eSTR Print STR as an error message. STR is terminated by a newline.
423 Use this when inconsistent options are detected.
424 %nSTR Print STR as a notice. STR is terminated by a newline.
425 %x{OPTION} Accumulate an option for %X.
426 %X Output the accumulated linker options specified by compilations.
427 %Y Output the accumulated assembler options specified by compilations.
428 %Z Output the accumulated preprocessor options specified by compilations.
429 %a process ASM_SPEC as a spec.
430 This allows config.h to specify part of the spec for running as.
431 %A process ASM_FINAL_SPEC as a spec. A capital A is actually
432 used here. This can be used to run a post-processor after the
433 assembler has done its job.
434 %D Dump out a -L option for each directory in startfile_prefixes.
435 If multilib_dir is set, extra entries are generated with it affixed.
436 %l process LINK_SPEC as a spec.
437 %L process LIB_SPEC as a spec.
438 %G process LIBGCC_SPEC as a spec.
439 %R Output the concatenation of target_system_root and
440 target_sysroot_suffix.
441 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
442 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
443 %C process CPP_SPEC as a spec.
444 %1 process CC1_SPEC as a spec.
445 %2 process CC1PLUS_SPEC as a spec.
446 %* substitute the variable part of a matched option. (See below.)
447 Note that each comma in the substituted string is replaced by
449 %<S remove all occurrences of -S from the command line.
450 Note - this command is position dependent. % commands in the
451 spec string before this one will see -S, % commands in the
452 spec string after this one will not.
453 %<S* remove all occurrences of all switches beginning with -S from the
456 Call the named function FUNCTION, passing it ARGS. ARGS is
457 first processed as a nested spec string, then split into an
458 argument vector in the usual fashion. The function returns
459 a string which is processed as if it had appeared literally
460 as part of the current spec.
461 %{S} substitutes the -S switch, if that switch was given to GCC.
462 If that switch was not specified, this substitutes nothing.
463 Here S is a metasyntactic variable.
464 %{S*} substitutes all the switches specified to GCC whose names start
465 with -S. This is used for -o, -I, etc; switches that take
466 arguments. GCC considers `-o foo' as being one switch whose
467 name starts with `o'. %{o*} would substitute this text,
468 including the space; thus, two arguments would be generated.
469 %{S*&T*} likewise, but preserve order of S and T options (the order
470 of S and T in the spec is not significant). Can be any number
471 of ampersand-separated variables; for each the wild card is
472 optional. Useful for CPP as %{D*&U*&A*}.
474 %{S:X} substitutes X, if the -S switch was given to GCC.
475 %{!S:X} substitutes X, if the -S switch was NOT given to GCC.
476 %{S*:X} substitutes X if one or more switches whose names start
477 with -S was given to GCC. Normally X is substituted only
478 once, no matter how many such switches appeared. However,
479 if %* appears somewhere in X, then X will be substituted
480 once for each matching switch, with the %* replaced by the
481 part of that switch that matched the '*'.
482 %{.S:X} substitutes X, if processing a file with suffix S.
483 %{!.S:X} substitutes X, if NOT processing a file with suffix S.
484 %{,S:X} substitutes X, if processing a file which will use spec S.
485 %{!,S:X} substitutes X, if NOT processing a file which will use spec S.
487 %{S|T:X} substitutes X if either -S or -T was given to GCC. This may be
488 combined with '!', '.', ',', and '*' as above binding stronger
490 If %* appears in X, all of the alternatives must be starred, and
491 only the first matching alternative is substituted.
492 %{S:X; if S was given to GCC, substitutes X;
493 T:Y; else if T was given to GCC, substitutes Y;
494 :D} else substitutes D. There can be as many clauses as you need.
495 This may be combined with '.', '!', ',', '|', and '*' as above.
497 %(Spec) processes a specification defined in a specs file as *Spec:
498 %[Spec] as above, but put __ around -D arguments
500 The conditional text X in a %{S:X} or similar construct may contain
501 other nested % constructs or spaces, or even newlines. They are
502 processed as usual, as described above. Trailing white space in X is
503 ignored. White space may also appear anywhere on the left side of the
504 colon in these constructs, except between . or * and the corresponding
507 The -O, -f, -m, and -W switches are handled specifically in these
508 constructs. If another value of -O or the negated form of a -f, -m, or
509 -W switch is found later in the command line, the earlier switch
510 value is ignored, except with {S*} where S is just one letter; this
511 passes all matching options.
513 The character | at the beginning of the predicate text is used to indicate
514 that a command should be piped to the following command, but only if -pipe
517 Note that it is built into GCC which switches take arguments and which
518 do not. You might think it would be useful to generalize this to
519 allow each compiler's spec to say which switches take arguments. But
520 this cannot be done in a consistent fashion. GCC cannot even decide
521 which input files have been specified without knowing which switches
522 take arguments, and it must know which input files to compile in order
523 to tell which compilers to run.
525 GCC also knows implicitly that arguments starting in `-l' are to be
526 treated as compiler output files, and passed to the linker in their
527 proper position among the other output files. */
529 /* Define the macros used for specs %a, %l, %L, %S, %C, %1. */
531 /* config.h can define ASM_SPEC to provide extra args to the assembler
532 or extra switch-translations. */
537 /* config.h can define ASM_FINAL_SPEC to run a post processor after
538 the assembler has run. */
539 #ifndef ASM_FINAL_SPEC
540 #define ASM_FINAL_SPEC ""
543 /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
544 or extra switch-translations. */
549 /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
550 or extra switch-translations. */
555 /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
556 or extra switch-translations. */
558 #define CC1PLUS_SPEC ""
561 /* config.h can define LINK_SPEC to provide extra args to the linker
562 or extra switch-translations. */
567 /* config.h can define LIB_SPEC to override the default libraries. */
569 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
574 /* XXX: valid only for GNU ld */
575 /* XXX: should exactly match hooks provided by libmudflap.a */
576 #define MFWRAP_SPEC " %{static: %{fmudflap|fmudflapth: \
577 --wrap=malloc --wrap=free --wrap=calloc --wrap=realloc\
578 --wrap=mmap --wrap=munmap --wrap=alloca\
579 } %{fmudflapth: --wrap=pthread_create\
580 }} %{fmudflap|fmudflapth: --wrap=main}"
583 #define MFLIB_SPEC "%{fmudflap|fmudflapth: -export-dynamic}"
586 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
589 #if defined(REAL_LIBGCC_SPEC)
590 #define LIBGCC_SPEC REAL_LIBGCC_SPEC
591 #elif defined(LINK_LIBGCC_SPECIAL_1)
592 /* Have gcc do the search for libgcc.a. */
593 #define LIBGCC_SPEC "libgcc.a%s"
595 #define LIBGCC_SPEC "-lgcc"
599 /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
600 #ifndef STARTFILE_SPEC
601 #define STARTFILE_SPEC \
602 "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
605 /* config.h can define ENDFILE_SPEC to override the default crtn files. */
607 #define ENDFILE_SPEC ""
611 #define LINKER_NAME "collect2"
614 #ifdef HAVE_AS_DEBUG_PREFIX_MAP
615 #define ASM_MAP " %{fdebug-prefix-map=*:--debug-prefix-map %*}"
620 /* Define ASM_DEBUG_SPEC to be a spec suitable for translating '-g'
622 #ifndef ASM_DEBUG_SPEC
623 # if defined(DBX_DEBUGGING_INFO) && defined(DWARF2_DEBUGGING_INFO) \
624 && defined(HAVE_AS_GDWARF2_DEBUG_FLAG) && defined(HAVE_AS_GSTABS_DEBUG_FLAG)
625 # define ASM_DEBUG_SPEC \
626 (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG \
627 ? "%{!g0:%{gdwarf-2*:--gdwarf2}%{!gdwarf-2*:%{g*:--gstabs}}}" ASM_MAP \
628 : "%{!g0:%{gstabs*:--gstabs}%{!gstabs*:%{g*:--gdwarf2}}}" ASM_MAP)
630 # if defined(DBX_DEBUGGING_INFO) && defined(HAVE_AS_GSTABS_DEBUG_FLAG)
631 # define ASM_DEBUG_SPEC "%{g*:%{!g0:--gstabs}}" ASM_MAP
633 # if defined(DWARF2_DEBUGGING_INFO) && defined(HAVE_AS_GDWARF2_DEBUG_FLAG)
634 # define ASM_DEBUG_SPEC "%{g*:%{!g0:--gdwarf2}}" ASM_MAP
638 #ifndef ASM_DEBUG_SPEC
639 # define ASM_DEBUG_SPEC ""
642 /* Here is the spec for running the linker, after compiling all files. */
644 /* This is overridable by the target in case they need to specify the
645 -lgcc and -lc order specially, yet not require them to override all
646 of LINK_COMMAND_SPEC. */
647 #ifndef LINK_GCC_C_SEQUENCE_SPEC
648 #define LINK_GCC_C_SEQUENCE_SPEC "%G %L %G"
651 #ifndef LINK_SSP_SPEC
652 #ifdef TARGET_LIBC_PROVIDES_SSP
653 #define LINK_SSP_SPEC "%{fstack-protector:}"
655 #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all:-lssp_nonshared -lssp}"
659 #ifndef LINK_PIE_SPEC
661 #define LINK_PIE_SPEC "%{pie:-pie} "
663 #define LINK_PIE_SPEC "%{pie:} "
667 #ifndef LINK_BUILDID_SPEC
668 # if defined(HAVE_LD_BUILDID) && defined(ENABLE_LD_BUILDID)
669 # define LINK_BUILDID_SPEC "%{!r:--build-id} "
674 /* -u* was put back because both BSD and SysV seem to support it. */
675 /* %{static:} simply prevents an error message if the target machine
676 doesn't handle -static. */
677 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
678 scripts which exist in user specified directories, or in standard
680 /* We pass any -flto and -fwhopr flags on to the linker, which is expected
681 to understand them. In practice, this means it had better be collect2. */
682 #ifndef LINK_COMMAND_SPEC
683 #define LINK_COMMAND_SPEC "\
684 %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
686 %{fuse-linker-plugin: \
687 -plugin %(linker_plugin_file) \
688 -plugin-opt=%(lto_wrapper) \
689 -plugin-opt=-fresolution=%u.res \
690 %{static|static-libgcc:-plugin-opt=-pass-through=%(lto_libgcc)} \
691 %{static:-plugin-opt=-pass-through=-lc} \
693 %{flto:%<fcompare-debug*} %{fwhopr*:%<fcompare-debug*} \
694 %{flto} %{fwhopr*} %l " LINK_PIE_SPEC \
695 "%X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r}\
696 %{s} %{t} %{u*} %{x} %{z} %{Z} %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
697 %{static:} %{L*} %(mfwrap) %(link_libgcc) %o\
698 %{fopenmp|ftree-parallelize-loops=*:%:include(libgomp.spec)%(link_gomp)} %(mflib)\
699 %{fprofile-arcs|fprofile-generate*|coverage:-lgcov}\
700 %{!nostdlib:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}\
701 %{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} }}}}}}"
704 #ifndef LINK_LIBGCC_SPEC
705 /* Generate -L options for startfile prefix list. */
706 # define LINK_LIBGCC_SPEC "%D"
709 #ifndef STARTFILE_PREFIX_SPEC
710 # define STARTFILE_PREFIX_SPEC ""
714 # define SYSROOT_SPEC "--sysroot=%R"
717 #ifndef SYSROOT_SUFFIX_SPEC
718 # define SYSROOT_SUFFIX_SPEC ""
721 #ifndef SYSROOT_HEADERS_SUFFIX_SPEC
722 # define SYSROOT_HEADERS_SUFFIX_SPEC ""
725 static const char *asm_debug
;
726 static const char *cpp_spec
= CPP_SPEC
;
727 static const char *cc1_spec
= CC1_SPEC
;
728 static const char *cc1plus_spec
= CC1PLUS_SPEC
;
729 static const char *link_gcc_c_sequence_spec
= LINK_GCC_C_SEQUENCE_SPEC
;
730 static const char *link_ssp_spec
= LINK_SSP_SPEC
;
731 static const char *asm_spec
= ASM_SPEC
;
732 static const char *asm_final_spec
= ASM_FINAL_SPEC
;
733 static const char *link_spec
= LINK_SPEC
;
734 static const char *lib_spec
= LIB_SPEC
;
735 static const char *mfwrap_spec
= MFWRAP_SPEC
;
736 static const char *mflib_spec
= MFLIB_SPEC
;
737 static const char *link_gomp_spec
= "";
738 static const char *libgcc_spec
= LIBGCC_SPEC
;
739 static const char *endfile_spec
= ENDFILE_SPEC
;
740 static const char *startfile_spec
= STARTFILE_SPEC
;
741 static const char *linker_name_spec
= LINKER_NAME
;
742 static const char *linker_plugin_file_spec
= "";
743 static const char *lto_wrapper_spec
= "";
744 static const char *lto_gcc_spec
= "";
745 static const char *lto_libgcc_spec
= "";
746 static const char *link_command_spec
= LINK_COMMAND_SPEC
;
747 static const char *link_libgcc_spec
= LINK_LIBGCC_SPEC
;
748 static const char *startfile_prefix_spec
= STARTFILE_PREFIX_SPEC
;
749 static const char *sysroot_spec
= SYSROOT_SPEC
;
750 static const char *sysroot_suffix_spec
= SYSROOT_SUFFIX_SPEC
;
751 static const char *sysroot_hdrs_suffix_spec
= SYSROOT_HEADERS_SUFFIX_SPEC
;
753 /* Standard options to cpp, cc1, and as, to reduce duplication in specs.
754 There should be no need to override these in target dependent files,
755 but we need to copy them to the specs file so that newer versions
756 of the GCC driver can correctly drive older tool chains with the
757 appropriate -B options. */
759 /* When cpplib handles traditional preprocessing, get rid of this, and
760 call cc1 (or cc1obj in objc/lang-specs.h) from the main specs so
761 that we default the front end language better. */
762 static const char *trad_capable_cpp
=
763 "cc1 -E %{traditional|ftraditional|traditional-cpp:-traditional-cpp}";
765 /* We don't wrap .d files in %W{} since a missing .d file, and
766 therefore no dependency entry, confuses make into thinking a .o
767 file that happens to exist is up-to-date. */
768 static const char *cpp_unique_options
=
769 "%{!Q:-quiet} %{nostdinc*} %{C} %{CC} %{v} %{I*&F*} %{P} %I\
770 %{MD:-MDX %{!o:%b.d}%{o*:%.d%*}}\
771 %{MMD:-MMDX %{!o:%b.d}%{o*:%.d%*}}\
772 %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\
773 %{!E:%{!M:%{!MM:%{!MT:%{!MQ:%{MD|MMD:%{o*:-MQ %*}}}}}}}\
774 %{remap} %{g3|ggdb3|gstabs3|gcoff3|gxcoff3|gvms3:-dD}\
775 %{!iplugindir*:%{fplugin*:%:find-plugindir()}}\
776 %{H} %C %{D*&U*&A*} %{i*} %Z %i\
777 %{fmudflap:-D_MUDFLAP -include mf-runtime.h}\
778 %{fmudflapth:-D_MUDFLAP -D_MUDFLAPTH -include mf-runtime.h}\
781 /* This contains cpp options which are common with cc1_options and are passed
782 only when preprocessing only to avoid duplication. We pass the cc1 spec
783 options to the preprocessor so that it the cc1 spec may manipulate
784 options used to set target flags. Those special target flags settings may
785 in turn cause preprocessor symbols to be defined specially. */
786 static const char *cpp_options
=
787 "%(cpp_unique_options) %1 %{m*} %{std*&ansi&trigraphs} %{W*&pedantic*} %{w}\
788 %{f*} %{g*:%{!g0:%{g*} %{!fno-working-directory:-fworking-directory}}} %{O*}\
789 %{undef} %{save-temps*:-fpch-preprocess}";
791 /* This contains cpp options which are not passed when the preprocessor
792 output will be used by another program. */
793 static const char *cpp_debug_options
= "%{d*}";
795 /* NB: This is shared amongst all front-ends, except for Ada. */
796 static const char *cc1_options
=
797 "%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
798 %{!iplugindir*:%{fplugin*:%:find-plugindir()}}\
799 %1 %{!Q:-quiet} %{!dumpbase:-dumpbase %B} %{d*} %{m*} %{aux-info*}\
800 %{fcompare-debug-second:%:compare-debug-auxbase-opt(%b)} \
801 %{!fcompare-debug-second:%{c|S:%{o*:-auxbase-strip %*}%{!o*:-auxbase %b}}}%{!c:%{!S:-auxbase %b}} \
802 %{g*} %{O*} %{W*&pedantic*} %{w} %{std*&ansi&trigraphs}\
803 %{v:-version} %{pg:-p} %{p} %{f*} %{undef}\
804 %{Qn:-fno-ident} %{--help:--help}\
805 %{--target-help:--target-help}\
806 %{--help=*:--help=%(VALUE)}\
807 %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %b.s}}}\
808 %{fsyntax-only:-o %j} %{-param*}\
809 %{fmudflap|fmudflapth:-fno-builtin -fno-merge-constants}\
810 %{coverage:-fprofile-arcs -ftest-coverage}";
812 static const char *asm_options
=
813 "%{--target-help:%:print-asm-header()} "
815 /* If GNU AS is used, then convert -w (no warnings), -I, and -v
816 to the assembler equivalents. */
817 "%{v} %{w:-W} %{I*} "
819 "%a %Y %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}";
821 static const char *invoke_as
=
822 #ifdef AS_NEEDS_DASH_FOR_PIPED_INPUT
824 %{fcompare-debug=*|fdump-final-insns=*:%:compare-debug-dump-opt()}\
825 %{!S:-o %|.s |\n as %(asm_options) %|.s %A }\
829 %{fcompare-debug=*|fdump-final-insns=*:%:compare-debug-dump-opt()}\
830 %{!S:-o %|.s |\n as %(asm_options) %m.s %A }\
834 /* Some compilers have limits on line lengths, and the multilib_select
835 and/or multilib_matches strings can be very long, so we build them at
837 static struct obstack multilib_obstack
;
838 static const char *multilib_select
;
839 static const char *multilib_matches
;
840 static const char *multilib_defaults
;
841 static const char *multilib_exclusions
;
843 /* Check whether a particular argument is a default argument. */
845 #ifndef MULTILIB_DEFAULTS
846 #define MULTILIB_DEFAULTS { "" }
849 static const char *const multilib_defaults_raw
[] = MULTILIB_DEFAULTS
;
851 #ifndef DRIVER_SELF_SPECS
852 #define DRIVER_SELF_SPECS ""
855 /* Adding -fopenmp should imply pthreads. This is particularly important
856 for targets that use different start files and suchlike. */
857 #ifndef GOMP_SELF_SPECS
858 #define GOMP_SELF_SPECS "%{fopenmp|ftree-parallelize-loops=*: -pthread}"
861 static const char *const driver_self_specs
[] = {
862 "%{fdump-final-insns:-fdump-final-insns=.} %<fdump-final-insns",
863 DRIVER_SELF_SPECS
, CONFIGURE_SPECS
, GOMP_SELF_SPECS
866 #ifndef OPTION_DEFAULT_SPECS
867 #define OPTION_DEFAULT_SPECS { "", "" }
876 static const struct default_spec
877 option_default_specs
[] = { OPTION_DEFAULT_SPECS
};
881 struct user_specs
*next
;
882 const char *filename
;
885 static struct user_specs
*user_specs_head
, *user_specs_tail
;
888 #ifdef HAVE_TARGET_EXECUTABLE_SUFFIX
889 /* This defines which switches stop a full compilation. */
890 #define DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR) \
891 ((CHAR) == 'c' || (CHAR) == 'S' || (CHAR) == 'E')
893 #ifndef SWITCH_CURTAILS_COMPILATION
894 #define SWITCH_CURTAILS_COMPILATION(CHAR) \
895 DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR)
899 /* Record the mapping from file suffixes for compilation specs. */
903 const char *suffix
; /* Use this compiler for input files
904 whose names end in this suffix. */
906 const char *spec
; /* To use this compiler, run this spec. */
908 const char *cpp_spec
; /* If non-NULL, substitute this spec
909 for `%C', rather than the usual
911 const int combinable
; /* If nonzero, compiler can deal with
912 multiple source files at once (IMA). */
913 const int needs_preprocessing
; /* If nonzero, source files need to
914 be run through a preprocessor. */
917 /* Pointer to a vector of `struct compiler' that gives the spec for
918 compiling a file, based on its suffix.
919 A file that does not end in any of these suffixes will be passed
920 unchanged to the loader and nothing else will be done to it.
922 An entry containing two 0s is used to terminate the vector.
924 If multiple entries match a file, the last matching one is used. */
926 static struct compiler
*compilers
;
928 /* Number of entries in `compilers', not counting the null terminator. */
930 static int n_compilers
;
932 /* The default list of file name suffixes and their compilation specs. */
934 static const struct compiler default_compilers
[] =
936 /* Add lists of suffixes of known languages here. If those languages
937 were not present when we built the driver, we will hit these copies
938 and be given a more meaningful error than "file not used since
939 linking is not done". */
940 {".m", "#Objective-C", 0, 0, 0}, {".mi", "#Objective-C", 0, 0, 0},
941 {".mm", "#Objective-C++", 0, 0, 0}, {".M", "#Objective-C++", 0, 0, 0},
942 {".mii", "#Objective-C++", 0, 0, 0},
943 {".cc", "#C++", 0, 0, 0}, {".cxx", "#C++", 0, 0, 0},
944 {".cpp", "#C++", 0, 0, 0}, {".cp", "#C++", 0, 0, 0},
945 {".c++", "#C++", 0, 0, 0}, {".C", "#C++", 0, 0, 0},
946 {".CPP", "#C++", 0, 0, 0}, {".ii", "#C++", 0, 0, 0},
947 {".ads", "#Ada", 0, 0, 0}, {".adb", "#Ada", 0, 0, 0},
948 {".f", "#Fortran", 0, 0, 0}, {".F", "#Fortran", 0, 0, 0},
949 {".for", "#Fortran", 0, 0, 0}, {".FOR", "#Fortran", 0, 0, 0},
950 {".ftn", "#Fortran", 0, 0, 0}, {".FTN", "#Fortran", 0, 0, 0},
951 {".fpp", "#Fortran", 0, 0, 0}, {".FPP", "#Fortran", 0, 0, 0},
952 {".f90", "#Fortran", 0, 0, 0}, {".F90", "#Fortran", 0, 0, 0},
953 {".f95", "#Fortran", 0, 0, 0}, {".F95", "#Fortran", 0, 0, 0},
954 {".f03", "#Fortran", 0, 0, 0}, {".F03", "#Fortran", 0, 0, 0},
955 {".f08", "#Fortran", 0, 0, 0}, {".F08", "#Fortran", 0, 0, 0},
956 {".r", "#Ratfor", 0, 0, 0},
957 {".p", "#Pascal", 0, 0, 0}, {".pas", "#Pascal", 0, 0, 0},
958 {".java", "#Java", 0, 0, 0}, {".class", "#Java", 0, 0, 0},
959 {".zip", "#Java", 0, 0, 0}, {".jar", "#Java", 0, 0, 0},
960 /* Next come the entries for C. */
961 {".c", "@c", 0, 1, 1},
963 /* cc1 has an integrated ISO C preprocessor. We should invoke the
964 external preprocessor if -save-temps is given. */
965 "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\
967 %{traditional|ftraditional:\
968 %eGNU C no longer supports -traditional without -E}\
970 %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \
971 %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\
972 cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \
974 %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\
975 cc1 %(cpp_unique_options) %(cc1_options)}}}\
976 %{!fsyntax-only:%(invoke_as)}} \
978 %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \
979 %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i}}\
980 %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\
981 cc1 %(cpp_unique_options) %(cc1_options)}}\
982 %{!fsyntax-only:%(invoke_as)}}}}}}", 0, 1, 1},
984 "%{!E:%e-E or -x required when input is from standard input}\
985 %(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)", 0, 0, 0},
986 {".h", "@c-header", 0, 0, 0},
988 /* cc1 has an integrated ISO C preprocessor. We should invoke the
989 external preprocessor if -save-temps is given. */
990 "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\
992 %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \
993 %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\
994 cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \
996 %{!fdump-ada-spec*:-o %g.s %{!o*:--output-pch=%i.gch}\
997 %W{o*:--output-pch=%*}}%V}\
998 %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\
999 cc1 %(cpp_unique_options) %(cc1_options)\
1000 %{!fdump-ada-spec*:-o %g.s %{!o*:--output-pch=%i.gch}\
1001 %W{o*:--output-pch=%*}}%V}}}}}}", 0, 0, 0},
1002 {".i", "@cpp-output", 0, 1, 0},
1004 "%{!M:%{!MM:%{!E:cc1 -fpreprocessed %i %(cc1_options) %{!fsyntax-only:%(invoke_as)}}}}", 0, 1, 0},
1005 {".s", "@assembler", 0, 1, 0},
1007 "%{!M:%{!MM:%{!E:%{!S:as %(asm_debug) %(asm_options) %i %A }}}}", 0, 1, 0},
1008 {".sx", "@assembler-with-cpp", 0, 1, 0},
1009 {".S", "@assembler-with-cpp", 0, 1, 0},
1010 {"@assembler-with-cpp",
1011 #ifdef AS_NEEDS_DASH_FOR_PIPED_INPUT
1012 "%(trad_capable_cpp) -lang-asm %(cpp_options) -fno-directives-only\
1013 %{E|M|MM:%(cpp_debug_options)}\
1014 %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\
1015 as %(asm_debug) %(asm_options) %|.s %A }}}}"
1017 "%(trad_capable_cpp) -lang-asm %(cpp_options) -fno-directives-only\
1018 %{E|M|MM:%(cpp_debug_options)}\
1019 %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\
1020 as %(asm_debug) %(asm_options) %m.s %A }}}}"
1025 /* Mark end of table. */
1029 /* Number of elements in default_compilers, not counting the terminator. */
1031 static const int n_default_compilers
= ARRAY_SIZE (default_compilers
) - 1;
1033 /* A vector of options to give to the linker.
1034 These options are accumulated by %x,
1035 and substituted into the linker command with %X. */
1036 static int n_linker_options
;
1037 static char **linker_options
;
1039 /* A vector of options to give to the assembler.
1040 These options are accumulated by -Wa,
1041 and substituted into the assembler command with %Y. */
1042 static int n_assembler_options
;
1043 static char **assembler_options
;
1045 /* A vector of options to give to the preprocessor.
1046 These options are accumulated by -Wp,
1047 and substituted into the preprocessor command with %Z. */
1048 static int n_preprocessor_options
;
1049 static char **preprocessor_options
;
1051 /* Define how to map long options into short ones. */
1053 /* This structure describes one mapping. */
1056 /* The long option's name. */
1057 const char *const name
;
1058 /* The equivalent short option. */
1059 const char *const equivalent
;
1060 /* Argument info. A string of flag chars; NULL equals no options.
1061 a => argument required.
1062 o => argument optional.
1063 j => join argument to equivalent, making one word.
1064 * => require other text after NAME as an argument. */
1065 const char *const arg_info
;
1068 /* This is the table of mappings. Mappings are tried sequentially
1069 for each option encountered; the first one that matches, wins. */
1071 static const struct option_map option_map
[] =
1073 {"--all-warnings", "-Wall", 0},
1074 {"--ansi", "-ansi", 0},
1075 {"--assemble", "-S", 0},
1076 {"--assert", "-A", "a"},
1077 {"--classpath", "-fclasspath=", "aj"},
1078 {"--bootclasspath", "-fbootclasspath=", "aj"},
1079 {"--CLASSPATH", "-fclasspath=", "aj"},
1080 {"--combine", "-combine", 0},
1081 {"--comments", "-C", 0},
1082 {"--comments-in-macros", "-CC", 0},
1083 {"--compile", "-c", 0},
1084 {"--debug", "-g", "oj"},
1085 {"--define-macro", "-D", "aj"},
1086 {"--dependencies", "-M", 0},
1087 {"--dump", "-d", "a"},
1088 {"--dumpbase", "-dumpbase", "a"},
1089 {"--dumpdir", "-dumpdir", "a"},
1090 {"--encoding", "-fencoding=", "aj"},
1091 {"--entry", "-e", 0},
1092 {"--extra-warnings", "-W", 0},
1093 {"--extdirs", "-fextdirs=", "aj"},
1094 {"--for-assembler", "-Wa", "a"},
1095 {"--for-linker", "-Xlinker", "a"},
1096 {"--force-link", "-u", "a"},
1097 {"--coverage", "-coverage", 0},
1098 {"--imacros", "-imacros", "a"},
1099 {"--include", "-include", "a"},
1100 {"--include-barrier", "-I-", 0},
1101 {"--include-directory", "-I", "aj"},
1102 {"--include-directory-after", "-idirafter", "a"},
1103 {"--include-prefix", "-iprefix", "a"},
1104 {"--include-with-prefix", "-iwithprefix", "a"},
1105 {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
1106 {"--include-with-prefix-after", "-iwithprefix", "a"},
1107 {"--language", "-x", "a"},
1108 {"--library-directory", "-L", "a"},
1109 {"--machine", "-m", "aj"},
1110 {"--machine-", "-m", "*j"},
1111 {"--no-canonical-prefixes", "-no-canonical-prefixes", 0},
1112 {"--no-integrated-cpp", "-no-integrated-cpp", 0},
1113 {"--no-line-commands", "-P", 0},
1114 {"--no-precompiled-includes", "-noprecomp", 0},
1115 {"--no-standard-includes", "-nostdinc", 0},
1116 {"--no-standard-libraries", "-nostdlib", 0},
1117 {"--no-warnings", "-w", 0},
1118 {"--optimize", "-O", "oj"},
1119 {"--output", "-o", "a"},
1120 {"--output-class-directory", "-foutput-class-dir=", "ja"},
1121 {"--param", "--param", "a"},
1122 {"--pass-exit-codes", "-pass-exit-codes", 0},
1123 {"--pedantic", "-pedantic", 0},
1124 {"--pedantic-errors", "-pedantic-errors", 0},
1125 {"--pie", "-pie", 0},
1126 {"--pipe", "-pipe", 0},
1127 {"--prefix", "-B", "a"},
1128 {"--preprocess", "-E", 0},
1129 {"--print-search-dirs", "-print-search-dirs", 0},
1130 {"--print-file-name", "-print-file-name=", "aj"},
1131 {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
1132 {"--print-missing-file-dependencies", "-MG", 0},
1133 {"--print-multi-lib", "-print-multi-lib", 0},
1134 {"--print-multi-directory", "-print-multi-directory", 0},
1135 {"--print-multi-os-directory", "-print-multi-os-directory", 0},
1136 {"--print-prog-name", "-print-prog-name=", "aj"},
1137 {"--print-sysroot", "-print-sysroot", 0},
1138 {"--print-sysroot-headers-suffix", "-print-sysroot-headers-suffix", 0},
1139 {"--profile", "-p", 0},
1140 {"--resource", "-fcompile-resource=", "aj"},
1141 {"--save-temps", "-save-temps", 0},
1142 {"--shared", "-shared", 0},
1143 {"--specs", "-specs=", "aj"},
1144 {"--static", "-static", 0},
1145 {"--std", "-std=", "aj"},
1146 {"--symbolic", "-symbolic", 0},
1147 {"--sysroot", "--sysroot=", "aj"},
1148 {"--time", "-time", 0},
1149 {"--trace-includes", "-H", 0},
1150 {"--traditional", "-traditional", 0},
1151 {"--traditional-cpp", "-traditional-cpp", 0},
1152 {"--trigraphs", "-trigraphs", 0},
1153 {"--undefine-macro", "-U", "aj"},
1154 {"--user-dependencies", "-MM", 0},
1155 {"--verbose", "-v", 0},
1156 {"--warn-", "-W", "*j"},
1157 {"--write-dependencies", "-MD", 0},
1158 {"--write-user-dependencies", "-MMD", 0},
1163 #ifdef TARGET_OPTION_TRANSLATE_TABLE
1164 static const struct {
1165 const char *const option_found
;
1166 const char *const replacements
;
1167 } target_option_translations
[] =
1169 TARGET_OPTION_TRANSLATE_TABLE
,
1174 /* Translate the options described by *ARGCP and *ARGVP.
1175 Make a new vector and store it back in *ARGVP,
1176 and store its length in *ARGCP. */
1179 translate_options (int *argcp
, const char *const **argvp
)
1183 const char *const *argv
= *argvp
;
1184 int newvsize
= (argc
+ 2) * 2 * sizeof (const char *);
1185 const char **newv
= XNEWVAR (const char *, newvsize
);
1189 newv
[newindex
++] = argv
[i
++];
1193 #ifdef TARGET_OPTION_TRANSLATE_TABLE
1197 target_option_translations
[tott_idx
].option_found
;
1200 if (strcmp (target_option_translations
[tott_idx
].option_found
,
1207 for (sp
= target_option_translations
[tott_idx
].replacements
;
1214 newvsize
+= spaces
* sizeof (const char *);
1215 newv
= XRESIZEVAR (const char *, newv
, newvsize
);
1217 sp
= target_option_translations
[tott_idx
].replacements
;
1226 newv
[newindex
++] = np
;
1227 while (*np
!= ' ' && *np
)
1238 if (target_option_translations
[tott_idx
].option_found
)
1242 /* Translate -- options. */
1243 if (argv
[i
][0] == '-' && argv
[i
][1] == '-')
1246 /* Find a mapping that applies to this option. */
1247 for (j
= 0; j
< ARRAY_SIZE (option_map
); j
++)
1249 size_t optlen
= strlen (option_map
[j
].name
);
1250 size_t arglen
= strlen (argv
[i
]);
1251 size_t complen
= arglen
> optlen
? optlen
: arglen
;
1252 const char *arginfo
= option_map
[j
].arg_info
;
1257 if (!strncmp (argv
[i
], option_map
[j
].name
, complen
))
1259 const char *arg
= 0;
1261 if (arglen
< optlen
)
1264 for (k
= j
+ 1; k
< ARRAY_SIZE (option_map
); k
++)
1265 if (strlen (option_map
[k
].name
) >= arglen
1266 && !strncmp (argv
[i
], option_map
[k
].name
, arglen
))
1268 error ("ambiguous abbreviation %s", argv
[i
]);
1272 if (k
!= ARRAY_SIZE (option_map
))
1276 if (arglen
> optlen
)
1278 /* If the option has an argument, accept that. */
1279 if (argv
[i
][optlen
] == '=')
1280 arg
= argv
[i
] + optlen
+ 1;
1282 /* If this mapping requires extra text at end of name,
1283 accept that as "argument". */
1284 else if (strchr (arginfo
, '*') != 0)
1285 arg
= argv
[i
] + optlen
;
1287 /* Otherwise, extra text at end means mismatch.
1288 Try other mappings. */
1293 else if (strchr (arginfo
, '*') != 0)
1295 error ("incomplete %qs option", option_map
[j
].name
);
1299 /* Handle arguments. */
1300 if (strchr (arginfo
, 'a') != 0)
1306 error ("missing argument to %qs option",
1307 option_map
[j
].name
);
1314 else if (strchr (arginfo
, '*') != 0)
1316 else if (strchr (arginfo
, 'o') == 0)
1319 error ("extraneous argument to %qs option",
1320 option_map
[j
].name
);
1324 /* Store the translation as one argv elt or as two. */
1325 if (arg
!= 0 && strchr (arginfo
, 'j') != 0)
1326 newv
[newindex
++] = concat (option_map
[j
].equivalent
, arg
,
1330 newv
[newindex
++] = option_map
[j
].equivalent
;
1331 newv
[newindex
++] = arg
;
1334 newv
[newindex
++] = option_map
[j
].equivalent
;
1342 /* Handle old-fashioned options--just copy them through,
1343 with their arguments. */
1344 else if (argv
[i
][0] == '-')
1346 const char *p
= argv
[i
] + 1;
1350 if (SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
1351 nskip
+= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
1352 else if (WORD_SWITCH_TAKES_ARG (p
))
1353 nskip
+= WORD_SWITCH_TAKES_ARG (p
);
1354 else if ((c
== 'B' || c
== 'b' || c
== 'x')
1357 else if (! strcmp (p
, "Xlinker"))
1359 else if (! strcmp (p
, "Xpreprocessor"))
1361 else if (! strcmp (p
, "Xassembler"))
1364 /* Watch out for an option at the end of the command line that
1365 is missing arguments, and avoid skipping past the end of the
1367 if (nskip
+ i
> argc
)
1372 newv
[newindex
++] = argv
[i
++];
1377 /* Ordinary operands. */
1378 newv
[newindex
++] = argv
[i
++];
1388 skip_whitespace (char *p
)
1392 /* A fully-blank line is a delimiter in the SPEC file and shouldn't
1393 be considered whitespace. */
1394 if (p
[0] == '\n' && p
[1] == '\n' && p
[2] == '\n')
1396 else if (*p
== '\n' || *p
== ' ' || *p
== '\t')
1410 /* Structures to keep track of prefixes to try when looking for files. */
1414 const char *prefix
; /* String to prepend to the path. */
1415 struct prefix_list
*next
; /* Next in linked list. */
1416 int require_machine_suffix
; /* Don't use without machine_suffix. */
1417 /* 2 means try both machine_suffix and just_machine_suffix. */
1418 int priority
; /* Sort key - priority within list. */
1419 int os_multilib
; /* 1 if OS multilib scheme should be used,
1420 0 for GCC multilib scheme. */
1425 struct prefix_list
*plist
; /* List of prefixes to try */
1426 int max_len
; /* Max length of a prefix in PLIST */
1427 const char *name
; /* Name of this list (used in config stuff) */
1430 /* List of prefixes to try when looking for executables. */
1432 static struct path_prefix exec_prefixes
= { 0, 0, "exec" };
1434 /* List of prefixes to try when looking for startup (crt0) files. */
1436 static struct path_prefix startfile_prefixes
= { 0, 0, "startfile" };
1438 /* List of prefixes to try when looking for include files. */
1440 static struct path_prefix include_prefixes
= { 0, 0, "include" };
1442 /* Suffix to attach to directories searched for commands.
1443 This looks like `MACHINE/VERSION/'. */
1445 static const char *machine_suffix
= 0;
1447 /* Suffix to attach to directories searched for commands.
1448 This is just `MACHINE/'. */
1450 static const char *just_machine_suffix
= 0;
1452 /* Adjusted value of GCC_EXEC_PREFIX envvar. */
1454 static const char *gcc_exec_prefix
;
1456 /* Adjusted value of standard_libexec_prefix. */
1458 static const char *gcc_libexec_prefix
;
1460 /* Default prefixes to attach to command names. */
1462 #ifndef STANDARD_STARTFILE_PREFIX_1
1463 #define STANDARD_STARTFILE_PREFIX_1 "/lib/"
1465 #ifndef STANDARD_STARTFILE_PREFIX_2
1466 #define STANDARD_STARTFILE_PREFIX_2 "/usr/lib/"
1469 #ifdef CROSS_DIRECTORY_STRUCTURE /* Don't use these prefixes for a cross compiler. */
1470 #undef MD_EXEC_PREFIX
1471 #undef MD_STARTFILE_PREFIX
1472 #undef MD_STARTFILE_PREFIX_1
1475 /* If no prefixes defined, use the null string, which will disable them. */
1476 #ifndef MD_EXEC_PREFIX
1477 #define MD_EXEC_PREFIX ""
1479 #ifndef MD_STARTFILE_PREFIX
1480 #define MD_STARTFILE_PREFIX ""
1482 #ifndef MD_STARTFILE_PREFIX_1
1483 #define MD_STARTFILE_PREFIX_1 ""
1486 /* These directories are locations set at configure-time based on the
1487 --prefix option provided to configure. Their initializers are
1488 defined in Makefile.in. These paths are not *directly* used when
1489 gcc_exec_prefix is set because, in that case, we know where the
1490 compiler has been installed, and use paths relative to that
1491 location instead. */
1492 static const char *const standard_exec_prefix
= STANDARD_EXEC_PREFIX
;
1493 static const char *const standard_libexec_prefix
= STANDARD_LIBEXEC_PREFIX
;
1494 static const char *const standard_bindir_prefix
= STANDARD_BINDIR_PREFIX
;
1495 static const char *const standard_startfile_prefix
= STANDARD_STARTFILE_PREFIX
;
1497 /* For native compilers, these are well-known paths containing
1498 components that may be provided by the system. For cross
1499 compilers, these paths are not used. */
1500 static const char *md_exec_prefix
= MD_EXEC_PREFIX
;
1501 static const char *md_startfile_prefix
= MD_STARTFILE_PREFIX
;
1502 static const char *md_startfile_prefix_1
= MD_STARTFILE_PREFIX_1
;
1503 static const char *const standard_startfile_prefix_1
1504 = STANDARD_STARTFILE_PREFIX_1
;
1505 static const char *const standard_startfile_prefix_2
1506 = STANDARD_STARTFILE_PREFIX_2
;
1508 /* A relative path to be used in finding the location of tools
1509 relative to the driver. */
1510 static const char *const tooldir_base_prefix
= TOOLDIR_BASE_PREFIX
;
1512 /* Subdirectory to use for locating libraries. Set by
1513 set_multilib_dir based on the compilation options. */
1515 static const char *multilib_dir
;
1517 /* Subdirectory to use for locating libraries in OS conventions. Set by
1518 set_multilib_dir based on the compilation options. */
1520 static const char *multilib_os_dir
;
1522 /* Structure to keep track of the specs that have been defined so far.
1523 These are accessed using %(specname) or %[specname] in a compiler
1528 /* The following 2 fields must be first */
1529 /* to allow EXTRA_SPECS to be initialized */
1530 const char *name
; /* name of the spec. */
1531 const char *ptr
; /* available ptr if no static pointer */
1533 /* The following fields are not initialized */
1534 /* by EXTRA_SPECS */
1535 const char **ptr_spec
; /* pointer to the spec itself. */
1536 struct spec_list
*next
; /* Next spec in linked list. */
1537 int name_len
; /* length of the name */
1538 int alloc_p
; /* whether string was allocated */
1541 #define INIT_STATIC_SPEC(NAME,PTR) \
1542 { NAME, NULL, PTR, (struct spec_list *) 0, sizeof (NAME) - 1, 0 }
1544 /* List of statically defined specs. */
1545 static struct spec_list static_specs
[] =
1547 INIT_STATIC_SPEC ("asm", &asm_spec
),
1548 INIT_STATIC_SPEC ("asm_debug", &asm_debug
),
1549 INIT_STATIC_SPEC ("asm_final", &asm_final_spec
),
1550 INIT_STATIC_SPEC ("asm_options", &asm_options
),
1551 INIT_STATIC_SPEC ("invoke_as", &invoke_as
),
1552 INIT_STATIC_SPEC ("cpp", &cpp_spec
),
1553 INIT_STATIC_SPEC ("cpp_options", &cpp_options
),
1554 INIT_STATIC_SPEC ("cpp_debug_options", &cpp_debug_options
),
1555 INIT_STATIC_SPEC ("cpp_unique_options", &cpp_unique_options
),
1556 INIT_STATIC_SPEC ("trad_capable_cpp", &trad_capable_cpp
),
1557 INIT_STATIC_SPEC ("cc1", &cc1_spec
),
1558 INIT_STATIC_SPEC ("cc1_options", &cc1_options
),
1559 INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec
),
1560 INIT_STATIC_SPEC ("link_gcc_c_sequence", &link_gcc_c_sequence_spec
),
1561 INIT_STATIC_SPEC ("link_ssp", &link_ssp_spec
),
1562 INIT_STATIC_SPEC ("endfile", &endfile_spec
),
1563 INIT_STATIC_SPEC ("link", &link_spec
),
1564 INIT_STATIC_SPEC ("lib", &lib_spec
),
1565 INIT_STATIC_SPEC ("mfwrap", &mfwrap_spec
),
1566 INIT_STATIC_SPEC ("mflib", &mflib_spec
),
1567 INIT_STATIC_SPEC ("link_gomp", &link_gomp_spec
),
1568 INIT_STATIC_SPEC ("libgcc", &libgcc_spec
),
1569 INIT_STATIC_SPEC ("startfile", &startfile_spec
),
1570 INIT_STATIC_SPEC ("cross_compile", &cross_compile
),
1571 INIT_STATIC_SPEC ("version", &compiler_version
),
1572 INIT_STATIC_SPEC ("multilib", &multilib_select
),
1573 INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults
),
1574 INIT_STATIC_SPEC ("multilib_extra", &multilib_extra
),
1575 INIT_STATIC_SPEC ("multilib_matches", &multilib_matches
),
1576 INIT_STATIC_SPEC ("multilib_exclusions", &multilib_exclusions
),
1577 INIT_STATIC_SPEC ("multilib_options", &multilib_options
),
1578 INIT_STATIC_SPEC ("linker", &linker_name_spec
),
1579 INIT_STATIC_SPEC ("linker_plugin_file", &linker_plugin_file_spec
),
1580 INIT_STATIC_SPEC ("lto_wrapper", <o_wrapper_spec
),
1581 INIT_STATIC_SPEC ("lto_gcc", <o_gcc_spec
),
1582 INIT_STATIC_SPEC ("lto_libgcc", <o_libgcc_spec
),
1583 INIT_STATIC_SPEC ("link_libgcc", &link_libgcc_spec
),
1584 INIT_STATIC_SPEC ("md_exec_prefix", &md_exec_prefix
),
1585 INIT_STATIC_SPEC ("md_startfile_prefix", &md_startfile_prefix
),
1586 INIT_STATIC_SPEC ("md_startfile_prefix_1", &md_startfile_prefix_1
),
1587 INIT_STATIC_SPEC ("startfile_prefix_spec", &startfile_prefix_spec
),
1588 INIT_STATIC_SPEC ("sysroot_spec", &sysroot_spec
),
1589 INIT_STATIC_SPEC ("sysroot_suffix_spec", &sysroot_suffix_spec
),
1590 INIT_STATIC_SPEC ("sysroot_hdrs_suffix_spec", &sysroot_hdrs_suffix_spec
),
1593 #ifdef EXTRA_SPECS /* additional specs needed */
1594 /* Structure to keep track of just the first two args of a spec_list.
1595 That is all that the EXTRA_SPECS macro gives us. */
1598 const char *const name
;
1599 const char *const ptr
;
1602 static const struct spec_list_1 extra_specs_1
[] = { EXTRA_SPECS
};
1603 static struct spec_list
*extra_specs
= (struct spec_list
*) 0;
1606 /* List of dynamically allocates specs that have been defined so far. */
1608 static struct spec_list
*specs
= (struct spec_list
*) 0;
1610 /* List of static spec functions. */
1612 static const struct spec_function static_spec_functions
[] =
1614 { "getenv", getenv_spec_function
},
1615 { "if-exists", if_exists_spec_function
},
1616 { "if-exists-else", if_exists_else_spec_function
},
1617 { "replace-outfile", replace_outfile_spec_function
},
1618 { "version-compare", version_compare_spec_function
},
1619 { "include", include_spec_function
},
1620 { "find-file", find_file_spec_function
},
1621 { "find-plugindir", find_plugindir_spec_function
},
1622 { "print-asm-header", print_asm_header_spec_function
},
1623 { "compare-debug-dump-opt", compare_debug_dump_opt_spec_function
},
1624 { "compare-debug-self-opt", compare_debug_self_opt_spec_function
},
1625 { "compare-debug-auxbase-opt", compare_debug_auxbase_opt_spec_function
},
1626 #ifdef EXTRA_SPEC_FUNCTIONS
1627 EXTRA_SPEC_FUNCTIONS
1632 static int processing_spec_function
;
1634 /* Add appropriate libgcc specs to OBSTACK, taking into account
1635 various permutations of -shared-libgcc, -shared, and such. */
1637 #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC)
1639 #ifndef USE_LD_AS_NEEDED
1640 #define USE_LD_AS_NEEDED 0
1644 init_gcc_specs (struct obstack
*obstack
, const char *shared_name
,
1645 const char *static_name
, const char *eh_name
)
1649 buf
= concat ("%{static|static-libgcc:", static_name
, " ", eh_name
, "}"
1650 "%{!static:%{!static-libgcc:"
1651 #if USE_LD_AS_NEEDED
1652 "%{!shared-libgcc:",
1653 static_name
, " --as-needed ", shared_name
, " --no-as-needed"
1656 shared_name
, "%{!shared: ", static_name
, "}"
1660 "%{!shared-libgcc:", static_name
, " ", eh_name
, "}"
1661 "%{shared-libgcc:", shared_name
, " ", static_name
, "}"
1665 "%{shared-libgcc:", shared_name
, "}"
1666 "%{!shared-libgcc:", static_name
, "}"
1669 "%{shared:", shared_name
, "}"
1674 obstack_grow (obstack
, buf
, strlen (buf
));
1677 #endif /* ENABLE_SHARED_LIBGCC */
1679 /* Initialize the specs lookup routines. */
1684 struct spec_list
*next
= (struct spec_list
*) 0;
1685 struct spec_list
*sl
= (struct spec_list
*) 0;
1689 return; /* Already initialized. */
1692 fnotice (stderr
, "Using built-in specs.\n");
1695 extra_specs
= XCNEWVEC (struct spec_list
, ARRAY_SIZE (extra_specs_1
));
1697 for (i
= ARRAY_SIZE (extra_specs_1
) - 1; i
>= 0; i
--)
1699 sl
= &extra_specs
[i
];
1700 sl
->name
= extra_specs_1
[i
].name
;
1701 sl
->ptr
= extra_specs_1
[i
].ptr
;
1703 sl
->name_len
= strlen (sl
->name
);
1704 sl
->ptr_spec
= &sl
->ptr
;
1709 for (i
= ARRAY_SIZE (static_specs
) - 1; i
>= 0; i
--)
1711 sl
= &static_specs
[i
];
1716 #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC)
1717 /* ??? If neither -shared-libgcc nor --static-libgcc was
1718 seen, then we should be making an educated guess. Some proposed
1719 heuristics for ELF include:
1721 (1) If "-Wl,--export-dynamic", then it's a fair bet that the
1722 program will be doing dynamic loading, which will likely
1723 need the shared libgcc.
1725 (2) If "-ldl", then it's also a fair bet that we're doing
1728 (3) For each ET_DYN we're linking against (either through -lfoo
1729 or /some/path/foo.so), check to see whether it or one of
1730 its dependencies depends on a shared libgcc.
1734 If the runtime is fixed to look for program headers instead
1735 of calling __register_frame_info at all, for each object,
1736 use the shared libgcc if any EH symbol referenced.
1738 If crtstuff is fixed to not invoke __register_frame_info
1739 automatically, for each object, use the shared libgcc if
1740 any non-empty unwind section found.
1742 Doing any of this probably requires invoking an external program to
1743 do the actual object file scanning. */
1745 const char *p
= libgcc_spec
;
1748 /* Transform the extant libgcc_spec into one that uses the shared libgcc
1749 when given the proper command line arguments. */
1752 if (in_sep
&& *p
== '-' && strncmp (p
, "-lgcc", 5) == 0)
1754 init_gcc_specs (&obstack
,
1756 #ifdef USE_LIBUNWIND_EXCEPTIONS
1762 #ifdef USE_LIBUNWIND_EXCEPTIONS
1763 # ifdef HAVE_LD_STATIC_DYNAMIC
1764 " %{!static:-Bstatic} -lunwind %{!static:-Bdynamic}"
1774 else if (in_sep
&& *p
== 'l' && strncmp (p
, "libgcc.a%s", 10) == 0)
1776 /* Ug. We don't know shared library extensions. Hope that
1777 systems that use this form don't do shared libraries. */
1778 init_gcc_specs (&obstack
,
1782 #ifdef USE_LIBUNWIND_EXCEPTIONS
1791 obstack_1grow (&obstack
, *p
);
1792 in_sep
= (*p
== ' ');
1797 obstack_1grow (&obstack
, '\0');
1798 libgcc_spec
= XOBFINISH (&obstack
, const char *);
1801 #ifdef USE_AS_TRADITIONAL_FORMAT
1802 /* Prepend "--traditional-format" to whatever asm_spec we had before. */
1804 static const char tf
[] = "--traditional-format ";
1805 obstack_grow (&obstack
, tf
, sizeof(tf
) - 1);
1806 obstack_grow0 (&obstack
, asm_spec
, strlen (asm_spec
));
1807 asm_spec
= XOBFINISH (&obstack
, const char *);
1811 #if defined LINK_EH_SPEC || defined LINK_BUILDID_SPEC
1812 # ifdef LINK_BUILDID_SPEC
1813 /* Prepend LINK_BUILDID_SPEC to whatever link_spec we had before. */
1814 obstack_grow (&obstack
, LINK_BUILDID_SPEC
, sizeof(LINK_BUILDID_SPEC
) - 1);
1816 # ifdef LINK_EH_SPEC
1817 /* Prepend LINK_EH_SPEC to whatever link_spec we had before. */
1818 obstack_grow (&obstack
, LINK_EH_SPEC
, sizeof(LINK_EH_SPEC
) - 1);
1820 obstack_grow0 (&obstack
, link_spec
, strlen (link_spec
));
1821 link_spec
= XOBFINISH (&obstack
, const char *);
1827 /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
1828 removed; If the spec starts with a + then SPEC is added to the end of the
1832 set_spec (const char *name
, const char *spec
)
1834 struct spec_list
*sl
;
1835 const char *old_spec
;
1836 int name_len
= strlen (name
);
1839 /* If this is the first call, initialize the statically allocated specs. */
1842 struct spec_list
*next
= (struct spec_list
*) 0;
1843 for (i
= ARRAY_SIZE (static_specs
) - 1; i
>= 0; i
--)
1845 sl
= &static_specs
[i
];
1852 /* See if the spec already exists. */
1853 for (sl
= specs
; sl
; sl
= sl
->next
)
1854 if (name_len
== sl
->name_len
&& !strcmp (sl
->name
, name
))
1859 /* Not found - make it. */
1860 sl
= XNEW (struct spec_list
);
1861 sl
->name
= xstrdup (name
);
1862 sl
->name_len
= name_len
;
1863 sl
->ptr_spec
= &sl
->ptr
;
1865 *(sl
->ptr_spec
) = "";
1870 old_spec
= *(sl
->ptr_spec
);
1871 *(sl
->ptr_spec
) = ((spec
[0] == '+' && ISSPACE ((unsigned char)spec
[1]))
1872 ? concat (old_spec
, spec
+ 1, NULL
)
1877 fnotice (stderr
, "Setting spec %s to '%s'\n\n", name
, *(sl
->ptr_spec
));
1880 /* Free the old spec. */
1881 if (old_spec
&& sl
->alloc_p
)
1882 free (CONST_CAST(char *, old_spec
));
1887 /* Accumulate a command (program name and args), and run it. */
1889 /* Vector of pointers to arguments in the current line of specifications. */
1891 static const char **argbuf
;
1893 /* Number of elements allocated in argbuf. */
1895 static int argbuf_length
;
1897 /* Number of elements in argbuf currently in use (containing args). */
1899 static int argbuf_index
;
1901 /* Position in the argbuf array containing the name of the output file
1902 (the value associated with the "-o" flag). */
1904 static int have_o_argbuf_index
= 0;
1906 /* Were the options -c, -S or -E passed. */
1907 static int have_c
= 0;
1909 /* Was the option -o passed. */
1910 static int have_o
= 0;
1912 /* This is the list of suffixes and codes (%g/%u/%U/%j) and the associated
1913 temp file. If the HOST_BIT_BUCKET is used for %j, no entry is made for
1916 static struct temp_name
{
1917 const char *suffix
; /* suffix associated with the code. */
1918 int length
; /* strlen (suffix). */
1919 int unique
; /* Indicates whether %g or %u/%U was used. */
1920 const char *filename
; /* associated filename. */
1921 int filename_length
; /* strlen (filename). */
1922 struct temp_name
*next
;
1925 /* Number of commands executed so far. */
1927 static int execution_count
;
1929 /* Number of commands that exited with a signal. */
1931 static int signal_count
;
1933 /* Allocate the argument vector. */
1939 argbuf
= XNEWVEC (const char *, argbuf_length
);
1942 /* Clear out the vector of arguments (after a command is executed). */
1950 /* Add one argument to the vector at the end.
1951 This is done when a space is seen or at the end of the line.
1952 If DELETE_ALWAYS is nonzero, the arg is a filename
1953 and the file should be deleted eventually.
1954 If DELETE_FAILURE is nonzero, the arg is a filename
1955 and the file should be deleted if this compilation fails. */
1958 store_arg (const char *arg
, int delete_always
, int delete_failure
)
1960 if (argbuf_index
+ 1 == argbuf_length
)
1961 argbuf
= XRESIZEVEC (const char *, argbuf
, (argbuf_length
*= 2));
1963 argbuf
[argbuf_index
++] = arg
;
1964 argbuf
[argbuf_index
] = 0;
1966 if (strcmp (arg
, "-o") == 0)
1967 have_o_argbuf_index
= argbuf_index
;
1968 if (delete_always
|| delete_failure
)
1971 /* If the temporary file we should delete is specified as
1972 part of a joined argument extract the filename. */
1974 && (p
= strrchr (arg
, '=')))
1976 record_temp_file (arg
, delete_always
, delete_failure
);
1980 /* Load specs from a file name named FILENAME, replacing occurrences of
1981 various different types of line-endings, \r\n, \n\r and just \r, with
1985 load_specs (const char *filename
)
1989 struct stat statbuf
;
1996 fnotice (stderr
, "Reading specs from %s\n", filename
);
1998 /* Open and stat the file. */
1999 desc
= open (filename
, O_RDONLY
, 0);
2001 pfatal_with_name (filename
);
2002 if (stat (filename
, &statbuf
) < 0)
2003 pfatal_with_name (filename
);
2005 /* Read contents of file into BUFFER. */
2006 buffer
= XNEWVEC (char, statbuf
.st_size
+ 1);
2007 readlen
= read (desc
, buffer
, (unsigned) statbuf
.st_size
);
2009 pfatal_with_name (filename
);
2010 buffer
[readlen
] = 0;
2013 specs
= XNEWVEC (char, readlen
+ 1);
2015 for (buffer_p
= buffer
; buffer_p
&& *buffer_p
; buffer_p
++)
2021 if (buffer_p
> buffer
&& *(buffer_p
- 1) == '\n') /* \n\r */
2023 else if (*(buffer_p
+ 1) == '\n') /* \r\n */
2037 /* Read compilation specs from a file named FILENAME,
2038 replacing the default ones.
2040 A suffix which starts with `*' is a definition for
2041 one of the machine-specific sub-specs. The "suffix" should be
2042 *asm, *cc1, *cpp, *link, *startfile, etc.
2043 The corresponding spec is stored in asm_spec, etc.,
2044 rather than in the `compilers' vector.
2046 Anything invalid in the file is a fatal error. */
2049 read_specs (const char *filename
, int main_p
)
2054 buffer
= load_specs (filename
);
2056 /* Scan BUFFER for specs, putting them in the vector. */
2062 char *in
, *out
, *p1
, *p2
, *p3
;
2064 /* Advance P in BUFFER to the next nonblank nocomment line. */
2065 p
= skip_whitespace (p
);
2069 /* Is this a special command that starts with '%'? */
2070 /* Don't allow this for the main specs file, since it would
2071 encourage people to overwrite it. */
2072 if (*p
== '%' && !main_p
)
2075 while (*p
&& *p
!= '\n')
2081 if (!strncmp (p1
, "%include", sizeof ("%include") - 1)
2082 && (p1
[sizeof "%include" - 1] == ' '
2083 || p1
[sizeof "%include" - 1] == '\t'))
2087 p1
+= sizeof ("%include");
2088 while (*p1
== ' ' || *p1
== '\t')
2091 if (*p1
++ != '<' || p
[-2] != '>')
2092 fatal_error ("specs %%include syntax malformed after "
2094 (long) (p1
- buffer
+ 1));
2097 new_filename
= find_a_file (&startfile_prefixes
, p1
, R_OK
, true);
2098 read_specs (new_filename
? new_filename
: p1
, FALSE
);
2101 else if (!strncmp (p1
, "%include_noerr", sizeof "%include_noerr" - 1)
2102 && (p1
[sizeof "%include_noerr" - 1] == ' '
2103 || p1
[sizeof "%include_noerr" - 1] == '\t'))
2107 p1
+= sizeof "%include_noerr";
2108 while (*p1
== ' ' || *p1
== '\t')
2111 if (*p1
++ != '<' || p
[-2] != '>')
2112 fatal_error ("specs %%include syntax malformed after "
2114 (long) (p1
- buffer
+ 1));
2117 new_filename
= find_a_file (&startfile_prefixes
, p1
, R_OK
, true);
2119 read_specs (new_filename
, FALSE
);
2120 else if (verbose_flag
)
2121 fnotice (stderr
, "could not find specs file %s\n", p1
);
2124 else if (!strncmp (p1
, "%rename", sizeof "%rename" - 1)
2125 && (p1
[sizeof "%rename" - 1] == ' '
2126 || p1
[sizeof "%rename" - 1] == '\t'))
2129 struct spec_list
*sl
;
2130 struct spec_list
*newsl
;
2132 /* Get original name. */
2133 p1
+= sizeof "%rename";
2134 while (*p1
== ' ' || *p1
== '\t')
2137 if (! ISALPHA ((unsigned char) *p1
))
2138 fatal_error ("specs %%rename syntax malformed after "
2140 (long) (p1
- buffer
));
2143 while (*p2
&& !ISSPACE ((unsigned char) *p2
))
2146 if (*p2
!= ' ' && *p2
!= '\t')
2147 fatal_error ("specs %%rename syntax malformed after "
2149 (long) (p2
- buffer
));
2153 while (*p2
== ' ' || *p2
== '\t')
2156 if (! ISALPHA ((unsigned char) *p2
))
2157 fatal_error ("specs %%rename syntax malformed after "
2159 (long) (p2
- buffer
));
2161 /* Get new spec name. */
2163 while (*p3
&& !ISSPACE ((unsigned char) *p3
))
2167 fatal_error ("specs %%rename syntax malformed after "
2169 (long) (p3
- buffer
));
2172 for (sl
= specs
; sl
; sl
= sl
->next
)
2173 if (name_len
== sl
->name_len
&& !strcmp (sl
->name
, p1
))
2177 fatal_error ("specs %s spec was not found to be renamed", p1
);
2179 if (strcmp (p1
, p2
) == 0)
2182 for (newsl
= specs
; newsl
; newsl
= newsl
->next
)
2183 if (strcmp (newsl
->name
, p2
) == 0)
2184 fatal_error ("%s: attempt to rename spec %qs to "
2185 "already defined spec %qs",
2190 fnotice (stderr
, "rename spec %s to %s\n", p1
, p2
);
2192 fnotice (stderr
, "spec is '%s'\n\n", *(sl
->ptr_spec
));
2196 set_spec (p2
, *(sl
->ptr_spec
));
2198 free (CONST_CAST (char *, *(sl
->ptr_spec
)));
2200 *(sl
->ptr_spec
) = "";
2205 fatal_error ("specs unknown %% command after %ld characters",
2206 (long) (p1
- buffer
));
2209 /* Find the colon that should end the suffix. */
2211 while (*p1
&& *p1
!= ':' && *p1
!= '\n')
2214 /* The colon shouldn't be missing. */
2216 fatal_error ("specs file malformed after %ld characters",
2217 (long) (p1
- buffer
));
2219 /* Skip back over trailing whitespace. */
2221 while (p2
> buffer
&& (p2
[-1] == ' ' || p2
[-1] == '\t'))
2224 /* Copy the suffix to a string. */
2225 suffix
= save_string (p
, p2
- p
);
2226 /* Find the next line. */
2227 p
= skip_whitespace (p1
+ 1);
2229 fatal_error ("specs file malformed after %ld characters",
2230 (long) (p
- buffer
));
2233 /* Find next blank line or end of string. */
2234 while (*p1
&& !(*p1
== '\n' && (p1
[1] == '\n' || p1
[1] == '\0')))
2237 /* Specs end at the blank line and do not include the newline. */
2238 spec
= save_string (p
, p1
- p
);
2241 /* Delete backslash-newline sequences from the spec. */
2246 if (in
[0] == '\\' && in
[1] == '\n')
2248 else if (in
[0] == '#')
2249 while (*in
&& *in
!= '\n')
2257 if (suffix
[0] == '*')
2259 if (! strcmp (suffix
, "*link_command"))
2260 link_command_spec
= spec
;
2262 set_spec (suffix
+ 1, spec
);
2266 /* Add this pair to the vector. */
2268 = XRESIZEVEC (struct compiler
, compilers
, n_compilers
+ 2);
2270 compilers
[n_compilers
].suffix
= suffix
;
2271 compilers
[n_compilers
].spec
= spec
;
2273 memset (&compilers
[n_compilers
], 0, sizeof compilers
[n_compilers
]);
2277 link_command_spec
= spec
;
2280 if (link_command_spec
== 0)
2281 fatal_error ("spec file has no spec for linking");
2284 /* Record the names of temporary files we tell compilers to write,
2285 and delete them at the end of the run. */
2287 /* This is the common prefix we use to make temp file names.
2288 It is chosen once for each run of this program.
2289 It is substituted into a spec by %g or %j.
2290 Thus, all temp file names contain this prefix.
2291 In practice, all temp file names start with this prefix.
2293 This prefix comes from the envvar TMPDIR if it is defined;
2294 otherwise, from the P_tmpdir macro if that is defined;
2295 otherwise, in /usr/tmp or /tmp;
2296 or finally the current directory if all else fails. */
2298 static const char *temp_filename
;
2300 /* Length of the prefix. */
2302 static int temp_filename_length
;
2304 /* Define the list of temporary files to delete. */
2309 struct temp_file
*next
;
2312 /* Queue of files to delete on success or failure of compilation. */
2313 static struct temp_file
*always_delete_queue
;
2314 /* Queue of files to delete on failure of compilation. */
2315 static struct temp_file
*failure_delete_queue
;
2317 /* Record FILENAME as a file to be deleted automatically.
2318 ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
2319 otherwise delete it in any case.
2320 FAIL_DELETE nonzero means delete it if a compilation step fails;
2321 otherwise delete it in any case. */
2324 record_temp_file (const char *filename
, int always_delete
, int fail_delete
)
2326 char *const name
= xstrdup (filename
);
2330 struct temp_file
*temp
;
2331 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
2332 if (! strcmp (name
, temp
->name
))
2335 temp
= XNEW (struct temp_file
);
2336 temp
->next
= always_delete_queue
;
2338 always_delete_queue
= temp
;
2345 struct temp_file
*temp
;
2346 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
2347 if (! strcmp (name
, temp
->name
))
2350 temp
= XNEW (struct temp_file
);
2351 temp
->next
= failure_delete_queue
;
2353 failure_delete_queue
= temp
;
2359 /* Delete all the temporary files whose names we previously recorded. */
2361 #ifndef DELETE_IF_ORDINARY
2362 #define DELETE_IF_ORDINARY(NAME,ST,VERBOSE_FLAG) \
2365 if (stat (NAME, &ST) >= 0 && S_ISREG (ST.st_mode)) \
2366 if (unlink (NAME) < 0) \
2368 perror_with_name (NAME); \
2373 delete_if_ordinary (const char *name
)
2379 printf ("Delete %s? (y or n) ", name
);
2383 while ((c
= getchar ()) != '\n' && c
!= EOF
)
2386 if (i
== 'y' || i
== 'Y')
2388 DELETE_IF_ORDINARY (name
, st
, verbose_flag
);
2392 delete_temp_files (void)
2394 struct temp_file
*temp
;
2396 for (temp
= always_delete_queue
; temp
; temp
= temp
->next
)
2397 delete_if_ordinary (temp
->name
);
2398 always_delete_queue
= 0;
2401 /* Delete all the files to be deleted on error. */
2404 delete_failure_queue (void)
2406 struct temp_file
*temp
;
2408 for (temp
= failure_delete_queue
; temp
; temp
= temp
->next
)
2409 delete_if_ordinary (temp
->name
);
2413 clear_failure_queue (void)
2415 failure_delete_queue
= 0;
2418 /* Call CALLBACK for each path in PATHS, breaking out early if CALLBACK
2420 If DO_MULTI is true iterate over the paths twice, first with multilib
2421 suffix then without, otherwise iterate over the paths once without
2422 adding a multilib suffix. When DO_MULTI is true, some attempt is made
2423 to avoid visiting the same path twice, but we could do better. For
2424 instance, /usr/lib/../lib is considered different from /usr/lib.
2425 At least EXTRA_SPACE chars past the end of the path passed to
2426 CALLBACK are available for use by the callback.
2427 CALLBACK_INFO allows extra parameters to be passed to CALLBACK.
2429 Returns the value returned by CALLBACK. */
2432 for_each_path (const struct path_prefix
*paths
,
2435 void *(*callback
) (char *, void *),
2436 void *callback_info
)
2438 struct prefix_list
*pl
;
2439 const char *multi_dir
= NULL
;
2440 const char *multi_os_dir
= NULL
;
2441 const char *multi_suffix
;
2442 const char *just_multi_suffix
;
2445 bool skip_multi_dir
= false;
2446 bool skip_multi_os_dir
= false;
2448 multi_suffix
= machine_suffix
;
2449 just_multi_suffix
= just_machine_suffix
;
2450 if (do_multi
&& multilib_dir
&& strcmp (multilib_dir
, ".") != 0)
2452 multi_dir
= concat (multilib_dir
, dir_separator_str
, NULL
);
2453 multi_suffix
= concat (multi_suffix
, multi_dir
, NULL
);
2454 just_multi_suffix
= concat (just_multi_suffix
, multi_dir
, NULL
);
2456 if (do_multi
&& multilib_os_dir
&& strcmp (multilib_os_dir
, ".") != 0)
2457 multi_os_dir
= concat (multilib_os_dir
, dir_separator_str
, NULL
);
2461 size_t multi_dir_len
= 0;
2462 size_t multi_os_dir_len
= 0;
2464 size_t just_suffix_len
;
2468 multi_dir_len
= strlen (multi_dir
);
2470 multi_os_dir_len
= strlen (multi_os_dir
);
2471 suffix_len
= strlen (multi_suffix
);
2472 just_suffix_len
= strlen (just_multi_suffix
);
2476 len
= paths
->max_len
+ extra_space
+ 1;
2477 if (suffix_len
> multi_os_dir_len
)
2480 len
+= multi_os_dir_len
;
2481 path
= XNEWVEC (char, len
);
2484 for (pl
= paths
->plist
; pl
!= 0; pl
= pl
->next
)
2486 len
= strlen (pl
->prefix
);
2487 memcpy (path
, pl
->prefix
, len
);
2489 /* Look first in MACHINE/VERSION subdirectory. */
2490 if (!skip_multi_dir
)
2492 memcpy (path
+ len
, multi_suffix
, suffix_len
+ 1);
2493 ret
= callback (path
, callback_info
);
2498 /* Some paths are tried with just the machine (ie. target)
2499 subdir. This is used for finding as, ld, etc. */
2501 && pl
->require_machine_suffix
== 2)
2503 memcpy (path
+ len
, just_multi_suffix
, just_suffix_len
+ 1);
2504 ret
= callback (path
, callback_info
);
2509 /* Now try the base path. */
2510 if (!pl
->require_machine_suffix
2511 && !(pl
->os_multilib
? skip_multi_os_dir
: skip_multi_dir
))
2513 const char *this_multi
;
2514 size_t this_multi_len
;
2516 if (pl
->os_multilib
)
2518 this_multi
= multi_os_dir
;
2519 this_multi_len
= multi_os_dir_len
;
2523 this_multi
= multi_dir
;
2524 this_multi_len
= multi_dir_len
;
2528 memcpy (path
+ len
, this_multi
, this_multi_len
+ 1);
2532 ret
= callback (path
, callback_info
);
2540 if (multi_dir
== NULL
&& multi_os_dir
== NULL
)
2543 /* Run through the paths again, this time without multilibs.
2544 Don't repeat any we have already seen. */
2547 free (CONST_CAST (char *, multi_dir
));
2549 free (CONST_CAST (char *, multi_suffix
));
2550 multi_suffix
= machine_suffix
;
2551 free (CONST_CAST (char *, just_multi_suffix
));
2552 just_multi_suffix
= just_machine_suffix
;
2555 skip_multi_dir
= true;
2558 free (CONST_CAST (char *, multi_os_dir
));
2559 multi_os_dir
= NULL
;
2562 skip_multi_os_dir
= true;
2567 free (CONST_CAST (char *, multi_dir
));
2568 free (CONST_CAST (char *, multi_suffix
));
2569 free (CONST_CAST (char *, just_multi_suffix
));
2572 free (CONST_CAST (char *, multi_os_dir
));
2578 /* Callback for build_search_list. Adds path to obstack being built. */
2580 struct add_to_obstack_info
{
2587 add_to_obstack (char *path
, void *data
)
2589 struct add_to_obstack_info
*info
= (struct add_to_obstack_info
*) data
;
2591 if (info
->check_dir
&& !is_directory (path
, false))
2594 if (!info
->first_time
)
2595 obstack_1grow (info
->ob
, PATH_SEPARATOR
);
2597 obstack_grow (info
->ob
, path
, strlen (path
));
2599 info
->first_time
= false;
2603 /* Add or change the value of an environment variable, outputting the
2604 change to standard error if in verbose mode. */
2606 xputenv (const char *string
)
2609 fnotice (stderr
, "%s\n", string
);
2610 putenv (CONST_CAST (char *, string
));
2613 /* Build a list of search directories from PATHS.
2614 PREFIX is a string to prepend to the list.
2615 If CHECK_DIR_P is true we ensure the directory exists.
2616 If DO_MULTI is true, multilib paths are output first, then
2618 This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
2619 It is also used by the --print-search-dirs flag. */
2622 build_search_list (const struct path_prefix
*paths
, const char *prefix
,
2623 bool check_dir
, bool do_multi
)
2625 struct add_to_obstack_info info
;
2627 info
.ob
= &collect_obstack
;
2628 info
.check_dir
= check_dir
;
2629 info
.first_time
= true;
2631 obstack_grow (&collect_obstack
, prefix
, strlen (prefix
));
2632 obstack_1grow (&collect_obstack
, '=');
2634 for_each_path (paths
, do_multi
, 0, add_to_obstack
, &info
);
2636 obstack_1grow (&collect_obstack
, '\0');
2637 return XOBFINISH (&collect_obstack
, char *);
2640 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
2644 putenv_from_prefixes (const struct path_prefix
*paths
, const char *env_var
,
2647 xputenv (build_search_list (paths
, env_var
, true, do_multi
));
2650 /* Check whether NAME can be accessed in MODE. This is like access,
2651 except that it never considers directories to be executable. */
2654 access_check (const char *name
, int mode
)
2660 if (stat (name
, &st
) < 0
2661 || S_ISDIR (st
.st_mode
))
2665 return access (name
, mode
);
2668 /* Callback for find_a_file. Appends the file name to the directory
2669 path. If the resulting file exists in the right mode, return the
2670 full pathname to the file. */
2672 struct file_at_path_info
{
2681 file_at_path (char *path
, void *data
)
2683 struct file_at_path_info
*info
= (struct file_at_path_info
*) data
;
2684 size_t len
= strlen (path
);
2686 memcpy (path
+ len
, info
->name
, info
->name_len
);
2687 len
+= info
->name_len
;
2689 /* Some systems have a suffix for executable files.
2690 So try appending that first. */
2691 if (info
->suffix_len
)
2693 memcpy (path
+ len
, info
->suffix
, info
->suffix_len
+ 1);
2694 if (access_check (path
, info
->mode
) == 0)
2699 if (access_check (path
, info
->mode
) == 0)
2705 /* Search for NAME using the prefix list PREFIXES. MODE is passed to
2706 access to check permissions. If DO_MULTI is true, search multilib
2707 paths then non-multilib paths, otherwise do not search multilib paths.
2708 Return 0 if not found, otherwise return its name, allocated with malloc. */
2711 find_a_file (const struct path_prefix
*pprefix
, const char *name
, int mode
,
2714 struct file_at_path_info info
;
2716 #ifdef DEFAULT_ASSEMBLER
2717 if (! strcmp (name
, "as") && access (DEFAULT_ASSEMBLER
, mode
) == 0)
2718 return xstrdup (DEFAULT_ASSEMBLER
);
2721 #ifdef DEFAULT_LINKER
2722 if (! strcmp(name
, "ld") && access (DEFAULT_LINKER
, mode
) == 0)
2723 return xstrdup (DEFAULT_LINKER
);
2726 /* Determine the filename to execute (special case for absolute paths). */
2728 if (IS_ABSOLUTE_PATH (name
))
2730 if (access (name
, mode
) == 0)
2731 return xstrdup (name
);
2737 info
.suffix
= (mode
& X_OK
) != 0 ? HOST_EXECUTABLE_SUFFIX
: "";
2738 info
.name_len
= strlen (info
.name
);
2739 info
.suffix_len
= strlen (info
.suffix
);
2742 return (char*) for_each_path (pprefix
, do_multi
,
2743 info
.name_len
+ info
.suffix_len
,
2744 file_at_path
, &info
);
2747 /* Ranking of prefixes in the sort list. -B prefixes are put before
2750 enum path_prefix_priority
2752 PREFIX_PRIORITY_B_OPT
,
2753 PREFIX_PRIORITY_LAST
2756 /* Add an entry for PREFIX in PLIST. The PLIST is kept in ascending
2757 order according to PRIORITY. Within each PRIORITY, new entries are
2760 If WARN is nonzero, we will warn if no file is found
2761 through this prefix. WARN should point to an int
2762 which will be set to 1 if this entry is used.
2764 COMPONENT is the value to be passed to update_path.
2766 REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
2767 the complete value of machine_suffix.
2768 2 means try both machine_suffix and just_machine_suffix. */
2771 add_prefix (struct path_prefix
*pprefix
, const char *prefix
,
2772 const char *component
, /* enum prefix_priority */ int priority
,
2773 int require_machine_suffix
, int os_multilib
)
2775 struct prefix_list
*pl
, **prev
;
2778 for (prev
= &pprefix
->plist
;
2779 (*prev
) != NULL
&& (*prev
)->priority
<= priority
;
2780 prev
= &(*prev
)->next
)
2783 /* Keep track of the longest prefix. */
2785 prefix
= update_path (prefix
, component
);
2786 len
= strlen (prefix
);
2787 if (len
> pprefix
->max_len
)
2788 pprefix
->max_len
= len
;
2790 pl
= XNEW (struct prefix_list
);
2791 pl
->prefix
= prefix
;
2792 pl
->require_machine_suffix
= require_machine_suffix
;
2793 pl
->priority
= priority
;
2794 pl
->os_multilib
= os_multilib
;
2796 /* Insert after PREV. */
2801 /* Same as add_prefix, but prepending target_system_root to prefix. */
2802 /* The target_system_root prefix has been relocated by gcc_exec_prefix. */
2804 add_sysrooted_prefix (struct path_prefix
*pprefix
, const char *prefix
,
2805 const char *component
,
2806 /* enum prefix_priority */ int priority
,
2807 int require_machine_suffix
, int os_multilib
)
2809 if (!IS_ABSOLUTE_PATH (prefix
))
2810 fatal_error ("system path %qs is not absolute", prefix
);
2812 if (target_system_root
)
2814 if (target_sysroot_suffix
)
2815 prefix
= concat (target_sysroot_suffix
, prefix
, NULL
);
2816 prefix
= concat (target_system_root
, prefix
, NULL
);
2818 /* We have to override this because GCC's notion of sysroot
2819 moves along with GCC. */
2823 add_prefix (pprefix
, prefix
, component
, priority
,
2824 require_machine_suffix
, os_multilib
);
2827 /* Execute the command specified by the arguments on the current line of spec.
2828 When using pipes, this includes several piped-together commands
2829 with `|' between them.
2831 Return 0 if successful, -1 if failed. */
2837 int n_commands
; /* # of command. */
2839 struct pex_obj
*pex
;
2842 const char *prog
; /* program name. */
2843 const char **argv
; /* vector of args. */
2846 struct command
*commands
; /* each command buffer with above info. */
2848 gcc_assert (!processing_spec_function
);
2852 string
= find_a_file (&exec_prefixes
, argbuf
[0], X_OK
, false);
2853 argbuf
[0] = (string
) ? string
: argbuf
[0];
2854 insert_wrapper (wrapper_string
);
2857 /* Count # of piped commands. */
2858 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2859 if (strcmp (argbuf
[i
], "|") == 0)
2862 /* Get storage for each command. */
2863 commands
= (struct command
*) alloca (n_commands
* sizeof (struct command
));
2865 /* Split argbuf into its separate piped processes,
2866 and record info about each one.
2867 Also search for the programs that are to be run. */
2869 commands
[0].prog
= argbuf
[0]; /* first command. */
2870 commands
[0].argv
= &argbuf
[0];
2872 if (!wrapper_string
)
2874 string
= find_a_file (&exec_prefixes
, commands
[0].prog
, X_OK
, false);
2875 commands
[0].argv
[0] = (string
) ? string
: commands
[0].argv
[0];
2878 for (n_commands
= 1, i
= 0; i
< argbuf_index
; i
++)
2879 if (strcmp (argbuf
[i
], "|") == 0)
2880 { /* each command. */
2881 #if defined (__MSDOS__) || defined (OS2) || defined (VMS)
2882 fatal_error ("-pipe not supported");
2884 argbuf
[i
] = 0; /* termination of command args. */
2885 commands
[n_commands
].prog
= argbuf
[i
+ 1];
2886 commands
[n_commands
].argv
= &argbuf
[i
+ 1];
2887 string
= find_a_file (&exec_prefixes
, commands
[n_commands
].prog
,
2890 commands
[n_commands
].argv
[0] = string
;
2894 argbuf
[argbuf_index
] = 0;
2896 /* If -v, print what we are about to do, and maybe query. */
2900 /* For help listings, put a blank line between sub-processes. */
2901 if (print_help_list
)
2902 fputc ('\n', stderr
);
2904 /* Print each piped command as a separate line. */
2905 for (i
= 0; i
< n_commands
; i
++)
2907 const char *const *j
;
2909 if (verbose_only_flag
)
2911 for (j
= commands
[i
].argv
; *j
; j
++)
2914 for (p
= *j
; *p
; ++p
)
2915 if (!ISALNUM ((unsigned char) *p
)
2916 && *p
!= '_' && *p
!= '/' && *p
!= '-' && *p
!= '.')
2920 fprintf (stderr
, " \"");
2921 for (p
= *j
; *p
; ++p
)
2923 if (*p
== '"' || *p
== '\\' || *p
== '$')
2924 fputc ('\\', stderr
);
2927 fputc ('"', stderr
);
2930 fprintf (stderr
, " %s", *j
);
2934 for (j
= commands
[i
].argv
; *j
; j
++)
2935 fprintf (stderr
, " %s", *j
);
2937 /* Print a pipe symbol after all but the last command. */
2938 if (i
+ 1 != n_commands
)
2939 fprintf (stderr
, " |");
2940 fprintf (stderr
, "\n");
2943 if (verbose_only_flag
!= 0)
2945 /* verbose_only_flag should act as if the spec was
2946 executed, so increment execution_count before
2947 returning. This prevents spurious warnings about
2948 unused linker input files, etc. */
2953 fnotice (stderr
, "\nGo ahead? (y or n) ");
2957 while (getchar () != '\n')
2960 if (i
!= 'y' && i
!= 'Y')
2965 #ifdef ENABLE_VALGRIND_CHECKING
2966 /* Run the each command through valgrind. To simplify prepending the
2967 path to valgrind and the option "-q" (for quiet operation unless
2968 something triggers), we allocate a separate argv array. */
2970 for (i
= 0; i
< n_commands
; i
++)
2976 for (argc
= 0; commands
[i
].argv
[argc
] != NULL
; argc
++)
2979 argv
= XALLOCAVEC (const char *, argc
+ 3);
2981 argv
[0] = VALGRIND_PATH
;
2983 for (j
= 2; j
< argc
+ 2; j
++)
2984 argv
[j
] = commands
[i
].argv
[j
- 2];
2987 commands
[i
].argv
= argv
;
2988 commands
[i
].prog
= argv
[0];
2992 /* Run each piped subprocess. */
2994 pex
= pex_init (PEX_USE_PIPES
| ((report_times
|| report_times_to_file
)
2995 ? PEX_RECORD_TIMES
: 0),
2996 progname
, temp_filename
);
2998 fatal_error ("pex_init failed: %m");
3000 for (i
= 0; i
< n_commands
; i
++)
3004 const char *string
= commands
[i
].argv
[0];
3006 errmsg
= pex_run (pex
,
3007 ((i
+ 1 == n_commands
? PEX_LAST
: 0)
3008 | (string
== commands
[i
].prog
? PEX_SEARCH
: 0)),
3009 string
, CONST_CAST (char **, commands
[i
].argv
),
3014 fatal_error (errmsg
);
3018 pfatal_with_name (errmsg
);
3022 if (string
!= commands
[i
].prog
)
3023 free (CONST_CAST (char *, string
));
3028 /* Wait for all the subprocesses to finish. */
3032 struct pex_time
*times
= NULL
;
3035 statuses
= (int *) alloca (n_commands
* sizeof (int));
3036 if (!pex_get_status (pex
, n_commands
, statuses
))
3037 fatal_error ("failed to get exit status: %m");
3039 if (report_times
|| report_times_to_file
)
3041 times
= (struct pex_time
*) alloca (n_commands
* sizeof (struct pex_time
));
3042 if (!pex_get_times (pex
, n_commands
, times
))
3043 fatal_error ("failed to get process times: %m");
3048 for (i
= 0; i
< n_commands
; ++i
)
3050 int status
= statuses
[i
];
3052 if (WIFSIGNALED (status
))
3055 /* SIGPIPE is a special case. It happens in -pipe mode
3056 when the compiler dies before the preprocessor is done,
3057 or the assembler dies before the compiler is done.
3058 There's generally been an error already, and this is
3059 just fallout. So don't generate another error unless
3060 we would otherwise have succeeded. */
3061 if (WTERMSIG (status
) == SIGPIPE
3062 && (signal_count
|| greatest_status
>= MIN_FATAL_STATUS
))
3069 internal_error ("%s (program %s)",
3070 strsignal (WTERMSIG (status
)), commands
[i
].prog
);
3072 else if (WIFEXITED (status
)
3073 && WEXITSTATUS (status
) >= MIN_FATAL_STATUS
)
3075 if (WEXITSTATUS (status
) > greatest_status
)
3076 greatest_status
= WEXITSTATUS (status
);
3080 if (report_times
|| report_times_to_file
)
3082 struct pex_time
*pt
= ×
[i
];
3085 ut
= ((double) pt
->user_seconds
3086 + (double) pt
->user_microseconds
/ 1.0e6
);
3087 st
= ((double) pt
->system_seconds
3088 + (double) pt
->system_microseconds
/ 1.0e6
);
3093 fnotice (stderr
, "# %s %.2f %.2f\n",
3094 commands
[i
].prog
, ut
, st
);
3096 if (report_times_to_file
)
3099 const char *const *j
;
3101 fprintf (report_times_to_file
, "%g %g", ut
, st
);
3103 for (j
= &commands
[i
].prog
; *j
; j
= &commands
[i
].argv
[++c
])
3106 for (p
= *j
; *p
; ++p
)
3107 if (*p
== '"' || *p
== '\\' || *p
== '$'
3113 fprintf (report_times_to_file
, " \"");
3114 for (p
= *j
; *p
; ++p
)
3116 if (*p
== '"' || *p
== '\\' || *p
== '$')
3117 fputc ('\\', report_times_to_file
);
3118 fputc (*p
, report_times_to_file
);
3120 fputc ('"', report_times_to_file
);
3123 fprintf (report_times_to_file
, " %s", *j
);
3126 fputc ('\n', report_times_to_file
);
3136 /* Find all the switches given to us
3137 and make a vector describing them.
3138 The elements of the vector are strings, one per switch given.
3139 If a switch uses following arguments, then the `part1' field
3140 is the switch itself and the `args' field
3141 is a null-terminated vector containing the following arguments.
3142 Bits in the `live_cond' field are:
3143 SWITCH_LIVE to indicate this switch is true in a conditional spec.
3144 SWITCH_FALSE to indicate this switch is overridden by a later switch.
3145 SWITCH_IGNORE to indicate this switch should be ignored (used in %<S).
3146 SWITCH_IGNORE_PERMANENTLY to indicate this switch should be ignored
3147 in all do_spec calls afterwards. Used for %<S from self specs.
3148 The `validated' field is nonzero if any spec has looked at this switch;
3149 if it remains zero at the end of the run, it must be meaningless. */
3151 #define SWITCH_LIVE 0x1
3152 #define SWITCH_FALSE 0x2
3153 #define SWITCH_IGNORE 0x4
3154 #define SWITCH_IGNORE_PERMANENTLY 0x8
3160 unsigned int live_cond
;
3161 unsigned char validated
;
3162 unsigned char ordering
;
3165 static struct switchstr
*switches
;
3167 static int n_switches
;
3169 static int n_switches_alloc
;
3171 /* Set to zero if -fcompare-debug is disabled, positive if it's
3172 enabled and we're running the first compilation, negative if it's
3173 enabled and we're running the second compilation. For most of the
3174 time, it's in the range -1..1, but it can be temporarily set to 2
3175 or 3 to indicate that the -fcompare-debug flags didn't come from
3176 the command-line, but rather from the GCC_COMPARE_DEBUG environment
3177 variable, until a synthesized -fcompare-debug flag is added to the
3181 /* Set to nonzero if we've seen the -fcompare-debug-second flag. */
3182 int compare_debug_second
;
3184 /* Set to the flags that should be passed to the second compilation in
3185 a -fcompare-debug compilation. */
3186 const char *compare_debug_opt
;
3188 static struct switchstr
*switches_debug_check
[2];
3190 static int n_switches_debug_check
[2];
3192 static char *debug_check_temp_file
[2];
3194 /* Language is one of three things:
3196 1) The name of a real programming language.
3197 2) NULL, indicating that no one has figured out
3199 3) '*', indicating that the file should be passed
3204 const char *language
;
3205 struct compiler
*incompiler
;
3210 /* Also a vector of input files specified. */
3212 static struct infile
*infiles
;
3216 static int n_infiles_alloc
;
3218 /* True if multiple input files are being compiled to a single
3221 static bool combine_inputs
;
3223 /* This counts the number of libraries added by lang_specific_driver, so that
3224 we can tell if there were any user supplied any files or libraries. */
3226 static int added_libraries
;
3228 /* And a vector of corresponding output files is made up later. */
3230 const char **outfiles
;
3232 #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3234 /* Convert NAME to a new name if it is the standard suffix. DO_EXE
3235 is true if we should look for an executable suffix. DO_OBJ
3236 is true if we should look for an object suffix. */
3239 convert_filename (const char *name
, int do_exe ATTRIBUTE_UNUSED
,
3240 int do_obj ATTRIBUTE_UNUSED
)
3242 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3250 len
= strlen (name
);
3252 #ifdef HAVE_TARGET_OBJECT_SUFFIX
3253 /* Convert x.o to x.obj if TARGET_OBJECT_SUFFIX is ".obj". */
3254 if (do_obj
&& len
> 2
3255 && name
[len
- 2] == '.'
3256 && name
[len
- 1] == 'o')
3258 obstack_grow (&obstack
, name
, len
- 2);
3259 obstack_grow0 (&obstack
, TARGET_OBJECT_SUFFIX
, strlen (TARGET_OBJECT_SUFFIX
));
3260 name
= XOBFINISH (&obstack
, const char *);
3264 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
3265 /* If there is no filetype, make it the executable suffix (which includes
3266 the "."). But don't get confused if we have just "-o". */
3267 if (! do_exe
|| TARGET_EXECUTABLE_SUFFIX
[0] == 0 || (len
== 2 && name
[0] == '-'))
3270 for (i
= len
- 1; i
>= 0; i
--)
3271 if (IS_DIR_SEPARATOR (name
[i
]))
3274 for (i
++; i
< len
; i
++)
3278 obstack_grow (&obstack
, name
, len
);
3279 obstack_grow0 (&obstack
, TARGET_EXECUTABLE_SUFFIX
,
3280 strlen (TARGET_EXECUTABLE_SUFFIX
));
3281 name
= XOBFINISH (&obstack
, const char *);
3288 /* Display the command line switches accepted by gcc. */
3292 printf (_("Usage: %s [options] file...\n"), progname
);
3293 fputs (_("Options:\n"), stdout
);
3295 fputs (_(" -pass-exit-codes Exit with highest error code from a phase\n"), stdout
);
3296 fputs (_(" --help Display this information\n"), stdout
);
3297 fputs (_(" --target-help Display target specific command line options\n"), stdout
);
3298 fputs (_(" --help={target|optimizers|warnings|params|[^]{joined|separate|undocumented}}[,...]\n"), stdout
);
3299 fputs (_(" Display specific types of command line options\n"), stdout
);
3301 fputs (_(" (Use '-v --help' to display command line options of sub-processes)\n"), stdout
);
3302 fputs (_(" --version Display compiler version information\n"), stdout
);
3303 fputs (_(" -dumpspecs Display all of the built in spec strings\n"), stdout
);
3304 fputs (_(" -dumpversion Display the version of the compiler\n"), stdout
);
3305 fputs (_(" -dumpmachine Display the compiler's target processor\n"), stdout
);
3306 fputs (_(" -print-search-dirs Display the directories in the compiler's search path\n"), stdout
);
3307 fputs (_(" -print-libgcc-file-name Display the name of the compiler's companion library\n"), stdout
);
3308 fputs (_(" -print-file-name=<lib> Display the full path to library <lib>\n"), stdout
);
3309 fputs (_(" -print-prog-name=<prog> Display the full path to compiler component <prog>\n"), stdout
);
3310 fputs (_(" -print-multi-directory Display the root directory for versions of libgcc\n"), stdout
);
3312 -print-multi-lib Display the mapping between command line options and\n\
3313 multiple library search directories\n"), stdout
);
3314 fputs (_(" -print-multi-os-directory Display the relative path to OS libraries\n"), stdout
);
3315 fputs (_(" -print-sysroot Display the target libraries directory\n"), stdout
);
3316 fputs (_(" -print-sysroot-headers-suffix Display the sysroot suffix used to find headers\n"), stdout
);
3317 fputs (_(" -Wa,<options> Pass comma-separated <options> on to the assembler\n"), stdout
);
3318 fputs (_(" -Wp,<options> Pass comma-separated <options> on to the preprocessor\n"), stdout
);
3319 fputs (_(" -Wl,<options> Pass comma-separated <options> on to the linker\n"), stdout
);
3320 fputs (_(" -Xassembler <arg> Pass <arg> on to the assembler\n"), stdout
);
3321 fputs (_(" -Xpreprocessor <arg> Pass <arg> on to the preprocessor\n"), stdout
);
3322 fputs (_(" -Xlinker <arg> Pass <arg> on to the linker\n"), stdout
);
3323 fputs (_(" -combine Pass multiple source files to compiler at once\n"), stdout
);
3324 fputs (_(" -save-temps Do not delete intermediate files\n"), stdout
);
3325 fputs (_(" -save-temps=<arg> Do not delete intermediate files\n"), stdout
);
3327 -no-canonical-prefixes Do not canonicalize paths when building relative\n\
3328 prefixes to other gcc components\n"), stdout
);
3329 fputs (_(" -pipe Use pipes rather than intermediate files\n"), stdout
);
3330 fputs (_(" -time Time the execution of each subprocess\n"), stdout
);
3331 fputs (_(" -specs=<file> Override built-in specs with the contents of <file>\n"), stdout
);
3332 fputs (_(" -std=<standard> Assume that the input sources are for <standard>\n"), stdout
);
3334 --sysroot=<directory> Use <directory> as the root directory for headers\n\
3335 and libraries\n"), stdout
);
3336 fputs (_(" -B <directory> Add <directory> to the compiler's search paths\n"), stdout
);
3337 fputs (_(" -v Display the programs invoked by the compiler\n"), stdout
);
3338 fputs (_(" -### Like -v but options quoted and commands not executed\n"), stdout
);
3339 fputs (_(" -E Preprocess only; do not compile, assemble or link\n"), stdout
);
3340 fputs (_(" -S Compile only; do not assemble or link\n"), stdout
);
3341 fputs (_(" -c Compile and assemble, but do not link\n"), stdout
);
3342 fputs (_(" -o <file> Place the output into <file>\n"), stdout
);
3344 -x <language> Specify the language of the following input files\n\
3345 Permissible languages include: c c++ assembler none\n\
3346 'none' means revert to the default behavior of\n\
3347 guessing the language based on the file's extension\n\
3351 \nOptions starting with -g, -f, -m, -O, -W, or --param are automatically\n\
3352 passed on to the various sub-processes invoked by %s. In order to pass\n\
3353 other options on to these processes the -W<letter> options must be used.\n\
3356 /* The rest of the options are displayed by invocations of the various
3361 add_preprocessor_option (const char *option
, int len
)
3363 n_preprocessor_options
++;
3365 if (! preprocessor_options
)
3366 preprocessor_options
= XNEWVEC (char *, n_preprocessor_options
);
3368 preprocessor_options
= XRESIZEVEC (char *, preprocessor_options
,
3369 n_preprocessor_options
);
3371 preprocessor_options
[n_preprocessor_options
- 1] =
3372 save_string (option
, len
);
3376 add_assembler_option (const char *option
, int len
)
3378 n_assembler_options
++;
3380 if (! assembler_options
)
3381 assembler_options
= XNEWVEC (char *, n_assembler_options
);
3383 assembler_options
= XRESIZEVEC (char *, assembler_options
,
3384 n_assembler_options
);
3386 assembler_options
[n_assembler_options
- 1] = save_string (option
, len
);
3390 add_linker_option (const char *option
, int len
)
3394 if (! linker_options
)
3395 linker_options
= XNEWVEC (char *, n_linker_options
);
3397 linker_options
= XRESIZEVEC (char *, linker_options
, n_linker_options
);
3399 linker_options
[n_linker_options
- 1] = save_string (option
, len
);
3402 /* Allocate space for an input file in infiles. */
3407 if (n_infiles_alloc
== 0)
3409 n_infiles_alloc
= 16;
3410 infiles
= XNEWVEC (struct infile
, n_infiles_alloc
);
3412 else if (n_infiles_alloc
== n_infiles
)
3414 n_infiles_alloc
*= 2;
3415 infiles
= XRESIZEVEC (struct infile
, infiles
, n_infiles_alloc
);
3419 /* Store an input file with the given NAME and LANGUAGE in
3423 add_infile (const char *name
, const char *language
)
3426 infiles
[n_infiles
].name
= name
;
3427 infiles
[n_infiles
++].language
= language
;
3430 /* Allocate space for a switch in switches. */
3435 if (n_switches_alloc
== 0)
3437 n_switches_alloc
= 16;
3438 switches
= XNEWVEC (struct switchstr
, n_switches_alloc
);
3440 else if (n_switches_alloc
== n_switches
)
3442 n_switches_alloc
*= 2;
3443 switches
= XRESIZEVEC (struct switchstr
, switches
, n_switches_alloc
);
3447 /* Save an option OPT with N_ARGS arguments in array ARGS, marking it
3448 as validated if VALIDATED. */
3451 save_switch (const char *opt
, size_t n_args
, const char *const *args
,
3455 switches
[n_switches
].part1
= opt
+ 1;
3457 switches
[n_switches
].args
= 0;
3460 switches
[n_switches
].args
= XNEWVEC (const char *, n_args
+ 1);
3461 memcpy (switches
[n_switches
].args
, args
, n_args
* sizeof (const char *));
3462 switches
[n_switches
].args
[n_args
] = NULL
;
3465 switches
[n_switches
].live_cond
= 0;
3466 switches
[n_switches
].validated
= validated
;
3467 switches
[n_switches
].ordering
= 0;
3471 /* Handle an option DECODED that is unknown to the option-processing
3472 machinery, but may be known to specs. */
3475 driver_unknown_option_callback (const struct cl_decoded_option
*decoded
)
3477 save_switch (decoded
->canonical_option
[0],
3478 decoded
->canonical_option_num_elements
- 1,
3479 &decoded
->canonical_option
[1], false);
3484 /* Handle an option DECODED that is not marked as CL_DRIVER.
3485 LANG_MASK will always be CL_DRIVER. */
3488 driver_wrong_lang_callback (const struct cl_decoded_option
*decoded
,
3489 unsigned int lang_mask ATTRIBUTE_UNUSED
)
3491 /* At this point, non-driver options are accepted (and expected to
3492 be passed down by specs) unless marked to be rejected by the
3493 driver. Options to be rejected by the driver but accepted by the
3494 compilers proper are treated just like completely unknown
3496 const struct cl_option
*option
= &cl_options
[decoded
->opt_index
];
3498 if (option
->flags
& CL_REJECT_DRIVER
)
3499 error ("unrecognized command line option %qs",
3500 decoded
->orig_option_with_args_text
);
3502 driver_unknown_option_callback (decoded
);
3505 /* Note that an option (index OPT_INDEX, argument ARG, value VALUE)
3506 has been successfully handled with a handler for mask MASK. */
3509 driver_post_handling_callback (const struct cl_decoded_option
*decoded ATTRIBUTE_UNUSED
,
3510 unsigned int mask ATTRIBUTE_UNUSED
)
3512 /* Nothing to do here. */
3515 static const char *spec_lang
= 0;
3516 static int last_language_n_infiles
;
3518 /* Handle a driver option; arguments and return value as for
3522 driver_handle_option (const struct cl_decoded_option
*decoded
,
3523 unsigned int lang_mask ATTRIBUTE_UNUSED
, int kind
,
3524 const struct cl_option_handlers
*handlers ATTRIBUTE_UNUSED
)
3526 size_t opt_index
= decoded
->opt_index
;
3527 const char *arg
= decoded
->arg
;
3528 const char *compare_debug_replacement_opt
;
3529 int value
= decoded
->value
;
3530 bool validated
= false;
3531 bool do_save
= true;
3533 gcc_assert (kind
== DK_UNSPECIFIED
);
3539 struct spec_list
*sl
;
3541 for (sl
= specs
; sl
; sl
= sl
->next
)
3542 printf ("*%s:\n%s\n\n", sl
->name
, *(sl
->ptr_spec
));
3543 if (link_command_spec
)
3544 printf ("*link_command:\n%s\n\n", link_command_spec
);
3548 case OPT_dumpversion
:
3549 printf ("%s\n", spec_version
);
3552 case OPT_dumpmachine
:
3553 printf ("%s\n", spec_machine
);
3557 /* translate_options () has turned --version into -fversion. */
3560 /* CPP driver cannot obtain switch from cc1_options. */
3562 add_preprocessor_option ("--version", strlen ("--version"));
3563 add_assembler_option ("--version", strlen ("--version"));
3564 add_linker_option ("--version", strlen ("--version"));
3568 /* translate_options () has turned --help into -fhelp. */
3569 print_help_list
= 1;
3571 /* CPP driver cannot obtain switch from cc1_options. */
3573 add_preprocessor_option ("--help", 6);
3574 add_assembler_option ("--help", 6);
3575 add_linker_option ("--help", 6);
3579 /* translate_options () has turned --help into -fhelp. */
3580 print_subprocess_help
= 2;
3583 case OPT_ftarget_help
:
3584 /* translate_options() has turned --target-help into -ftarget-help. */
3585 print_subprocess_help
= 1;
3587 /* CPP driver cannot obtain switch from cc1_options. */
3589 add_preprocessor_option ("--target-help", 13);
3590 add_assembler_option ("--target-help", 13);
3591 add_linker_option ("--target-help", 13);
3594 case OPT_pass_exit_codes
:
3595 case OPT_print_search_dirs
:
3596 case OPT_print_file_name_
:
3597 case OPT_print_prog_name_
:
3598 case OPT_print_multi_lib
:
3599 case OPT_print_multi_directory
:
3600 case OPT_print_sysroot
:
3601 case OPT_print_multi_os_directory
:
3602 case OPT_print_sysroot_headers_suffix
:
3605 /* These options set the variables specified in common.opt
3606 automatically, and do not need to be saved for spec
3611 case OPT_print_libgcc_file_name
:
3612 print_file_name
= "libgcc.a";
3616 case OPT_fcompare_debug_second
:
3617 compare_debug_second
= 1;
3620 case OPT_fcompare_debug
:
3624 compare_debug_replacement_opt
= "-fcompare-debug=";
3626 goto compare_debug_with_arg
;
3629 compare_debug_replacement_opt
= "-fcompare-debug=-gtoggle";
3631 goto compare_debug_with_arg
;
3638 case OPT_fcompare_debug_
:
3639 compare_debug_replacement_opt
= decoded
->canonical_option
[0];
3640 compare_debug_with_arg
:
3641 gcc_assert (decoded
->canonical_option_num_elements
== 1);
3642 gcc_assert (arg
!= NULL
);
3647 if (compare_debug
< 0)
3648 compare_debug_opt
= NULL
;
3650 compare_debug_opt
= arg
;
3651 save_switch (compare_debug_replacement_opt
, 0, NULL
, validated
);
3657 /* Pass the rest of this option to the assembler. */
3659 /* Split the argument at commas. */
3661 for (j
= 0; arg
[j
]; j
++)
3664 add_assembler_option (arg
+ prev
, j
- prev
);
3668 /* Record the part after the last comma. */
3669 add_assembler_option (arg
+ prev
, j
- prev
);
3677 /* Pass the rest of this option to the preprocessor. */
3679 /* Split the argument at commas. */
3681 for (j
= 0; arg
[j
]; j
++)
3684 add_preprocessor_option (arg
+ prev
, j
- prev
);
3688 /* Record the part after the last comma. */
3689 add_preprocessor_option (arg
+ prev
, j
- prev
);
3697 /* Split the argument at commas. */
3699 for (j
= 0; arg
[j
]; j
++)
3702 add_infile (save_string (arg
+ prev
, j
- prev
), "*");
3705 /* Record the part after the last comma. */
3706 add_infile (arg
+ prev
, "*");
3712 add_infile (arg
, "*");
3716 case OPT_Xpreprocessor
:
3717 add_preprocessor_option (arg
, strlen (arg
));
3721 case OPT_Xassembler
:
3722 add_assembler_option (arg
, strlen (arg
));
3727 /* POSIX allows separation of -l and the lib arg; canonicalize
3728 by concatenating -l with its arg */
3729 add_infile (concat ("-l", arg
, NULL
), "*");
3733 case OPT_save_temps
:
3734 save_temps_flag
= SAVE_TEMPS_CWD
;
3738 case OPT_save_temps_
:
3739 if (strcmp (arg
, "cwd") == 0)
3740 save_temps_flag
= SAVE_TEMPS_CWD
;
3741 else if (strcmp (arg
, "obj") == 0
3742 || strcmp (arg
, "object") == 0)
3743 save_temps_flag
= SAVE_TEMPS_OBJ
;
3745 fatal_error ("%qs is an unknown -save-temps option",
3746 decoded
->orig_option_with_args_text
);
3749 case OPT_no_canonical_prefixes
:
3750 /* Already handled as a special case, so ignored here. */
3758 /* These options set the variables specified in common.opt
3759 automatically, but do need to be saved for spec
3766 struct user_specs
*user
= XNEW (struct user_specs
);
3768 user
->next
= (struct user_specs
*) 0;
3769 user
->filename
= arg
;
3770 if (user_specs_tail
)
3771 user_specs_tail
->next
= user
;
3773 user_specs_head
= user
;
3774 user_specs_tail
= user
;
3780 target_system_root
= arg
;
3781 target_system_root_changed
= 1;
3786 if (report_times_to_file
)
3787 fclose (report_times_to_file
);
3788 report_times_to_file
= fopen (arg
, "a");
3794 This is similar to -v except that there is no execution
3795 of the commands and the echoed arguments are quoted. It
3796 is intended for use in shell scripts to capture the
3797 driver-generated command line. */
3798 verbose_only_flag
++;
3805 size_t len
= strlen (arg
);
3807 /* Catch the case where the user has forgotten to append a
3808 directory separator to the path. Note, they may be using
3809 -B to add an executable name prefix, eg "i386-elf-", in
3810 order to distinguish between multiple installations of
3811 GCC in the same directory. Hence we must check to see
3812 if appending a directory separator actually makes a
3813 valid directory name. */
3814 if (!IS_DIR_SEPARATOR (arg
[len
- 1])
3815 && is_directory (arg
, false))
3817 char *tmp
= XNEWVEC (char, len
+ 2);
3819 tmp
[len
] = DIR_SEPARATOR
;
3824 add_prefix (&exec_prefixes
, arg
, NULL
,
3825 PREFIX_PRIORITY_B_OPT
, 0, 0);
3826 add_prefix (&startfile_prefixes
, arg
, NULL
,
3827 PREFIX_PRIORITY_B_OPT
, 0, 0);
3828 add_prefix (&include_prefixes
, arg
, NULL
,
3829 PREFIX_PRIORITY_B_OPT
, 0, 0);
3834 case OPT_v
: /* Print our subcommands and print versions. */
3840 if (!strcmp (spec_lang
, "none"))
3841 /* Suppress the warning if -xnone comes after the last input
3842 file, because alternate command interfaces like g++ might
3843 find it useful to place -xnone after each input file. */
3846 last_language_n_infiles
= n_infiles
;
3853 /* have_c already set in a prescan above. */
3858 #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) || defined(HAVE_TARGET_OBJECT_SUFFIX)
3859 arg
= convert_filename (arg
, ! have_c
, 0);
3861 /* Save the output name in case -save-temps=obj was used. */
3862 save_temps_prefix
= xstrdup (arg
);
3863 /* On some systems, ld cannot handle "-o" without a space. So
3864 split the option from its argument. */
3865 save_switch ("-o", 1, &arg
, validated
);
3868 case OPT_static_libgcc
:
3869 case OPT_shared_libgcc
:
3870 case OPT_static_libgfortran
:
3871 case OPT_static_libstdc__
:
3872 /* These are always valid, since gcc.c itself understands the
3873 first two, gfortranspec.c understands -static-libgfortran and
3874 g++spec.c understands -static-libstdc++ */
3883 save_switch (decoded
->canonical_option
[0],
3884 decoded
->canonical_option_num_elements
- 1,
3885 &decoded
->canonical_option
[1], validated
);
3889 /* Create the vector `switches' and its contents.
3890 Store its length in `n_switches'. */
3893 process_command (int argc
, const char **argv
)
3898 const char *tooldir_prefix
;
3899 char *(*get_relative_prefix
) (const char *, const char *,
3900 const char *) = NULL
;
3901 struct cl_option_handlers handlers
;
3902 struct cl_decoded_option
*decoded_options
;
3903 unsigned int decoded_options_count
, j
;
3905 GET_ENVIRONMENT (gcc_exec_prefix
, "GCC_EXEC_PREFIX");
3909 added_libraries
= 0;
3911 /* Figure compiler version from version string. */
3913 compiler_version
= temp1
= xstrdup (version_string
);
3915 for (; *temp1
; ++temp1
)
3924 /* Convert new-style -- options to old-style. */
3925 translate_options (&argc
,
3926 CONST_CAST2 (const char *const **, const char ***,
3929 /* Handle any -no-canonical-prefixes flag early, to assign the function
3930 that builds relative prefixes. This function creates default search
3931 paths that are needed later in normal option handling. */
3933 for (i
= 1; i
< argc
; i
++)
3935 if (! strcmp (argv
[i
], "-no-canonical-prefixes"))
3937 get_relative_prefix
= make_relative_prefix_ignore_links
;
3941 if (! get_relative_prefix
)
3942 get_relative_prefix
= make_relative_prefix
;
3944 /* Set up the default search paths. If there is no GCC_EXEC_PREFIX,
3945 see if we can create it from the pathname specified in argv[0]. */
3947 gcc_libexec_prefix
= standard_libexec_prefix
;
3949 /* FIXME: make_relative_prefix doesn't yet work for VMS. */
3950 if (!gcc_exec_prefix
)
3952 gcc_exec_prefix
= get_relative_prefix (argv
[0],
3953 standard_bindir_prefix
,
3954 standard_exec_prefix
);
3955 gcc_libexec_prefix
= get_relative_prefix (argv
[0],
3956 standard_bindir_prefix
,
3957 standard_libexec_prefix
);
3958 if (gcc_exec_prefix
)
3959 xputenv (concat ("GCC_EXEC_PREFIX=", gcc_exec_prefix
, NULL
));
3963 /* make_relative_prefix requires a program name, but
3964 GCC_EXEC_PREFIX is typically a directory name with a trailing
3965 / (which is ignored by make_relative_prefix), so append a
3967 char *tmp_prefix
= concat (gcc_exec_prefix
, "gcc", NULL
);
3968 gcc_libexec_prefix
= get_relative_prefix (tmp_prefix
,
3969 standard_exec_prefix
,
3970 standard_libexec_prefix
);
3972 /* The path is unrelocated, so fallback to the original setting. */
3973 if (!gcc_libexec_prefix
)
3974 gcc_libexec_prefix
= standard_libexec_prefix
;
3980 /* From this point onward, gcc_exec_prefix is non-null if the toolchain
3981 is relocated. The toolchain was either relocated using GCC_EXEC_PREFIX
3982 or an automatically created GCC_EXEC_PREFIX from argv[0]. */
3984 /* Do language-specific adjustment/addition of flags. */
3985 lang_specific_driver (&argc
,
3986 CONST_CAST2 (const char *const **, const char ***,
3990 if (gcc_exec_prefix
)
3992 int len
= strlen (gcc_exec_prefix
);
3994 if (len
> (int) sizeof ("/lib/gcc/") - 1
3995 && (IS_DIR_SEPARATOR (gcc_exec_prefix
[len
-1])))
3997 temp
= gcc_exec_prefix
+ len
- sizeof ("/lib/gcc/") + 1;
3998 if (IS_DIR_SEPARATOR (*temp
)
3999 && strncmp (temp
+ 1, "lib", 3) == 0
4000 && IS_DIR_SEPARATOR (temp
[4])
4001 && strncmp (temp
+ 5, "gcc", 3) == 0)
4002 len
-= sizeof ("/lib/gcc/") - 1;
4005 set_std_prefix (gcc_exec_prefix
, len
);
4006 add_prefix (&exec_prefixes
, gcc_libexec_prefix
, "GCC",
4007 PREFIX_PRIORITY_LAST
, 0, 0);
4008 add_prefix (&startfile_prefixes
, gcc_exec_prefix
, "GCC",
4009 PREFIX_PRIORITY_LAST
, 0, 0);
4012 /* COMPILER_PATH and LIBRARY_PATH have values
4013 that are lists of directory names with colons. */
4015 GET_ENVIRONMENT (temp
, "COMPILER_PATH");
4018 const char *startp
, *endp
;
4019 char *nstore
= (char *) alloca (strlen (temp
) + 3);
4021 startp
= endp
= temp
;
4024 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
4026 strncpy (nstore
, startp
, endp
- startp
);
4028 strcpy (nstore
, concat (".", dir_separator_str
, NULL
));
4029 else if (!IS_DIR_SEPARATOR (endp
[-1]))
4031 nstore
[endp
- startp
] = DIR_SEPARATOR
;
4032 nstore
[endp
- startp
+ 1] = 0;
4035 nstore
[endp
- startp
] = 0;
4036 add_prefix (&exec_prefixes
, nstore
, 0,
4037 PREFIX_PRIORITY_LAST
, 0, 0);
4038 add_prefix (&include_prefixes
, nstore
, 0,
4039 PREFIX_PRIORITY_LAST
, 0, 0);
4042 endp
= startp
= endp
+ 1;
4049 GET_ENVIRONMENT (temp
, LIBRARY_PATH_ENV
);
4050 if (temp
&& *cross_compile
== '0')
4052 const char *startp
, *endp
;
4053 char *nstore
= (char *) alloca (strlen (temp
) + 3);
4055 startp
= endp
= temp
;
4058 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
4060 strncpy (nstore
, startp
, endp
- startp
);
4062 strcpy (nstore
, concat (".", dir_separator_str
, NULL
));
4063 else if (!IS_DIR_SEPARATOR (endp
[-1]))
4065 nstore
[endp
- startp
] = DIR_SEPARATOR
;
4066 nstore
[endp
- startp
+ 1] = 0;
4069 nstore
[endp
- startp
] = 0;
4070 add_prefix (&startfile_prefixes
, nstore
, NULL
,
4071 PREFIX_PRIORITY_LAST
, 0, 1);
4074 endp
= startp
= endp
+ 1;
4081 /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
4082 GET_ENVIRONMENT (temp
, "LPATH");
4083 if (temp
&& *cross_compile
== '0')
4085 const char *startp
, *endp
;
4086 char *nstore
= (char *) alloca (strlen (temp
) + 3);
4088 startp
= endp
= temp
;
4091 if (*endp
== PATH_SEPARATOR
|| *endp
== 0)
4093 strncpy (nstore
, startp
, endp
- startp
);
4095 strcpy (nstore
, concat (".", dir_separator_str
, NULL
));
4096 else if (!IS_DIR_SEPARATOR (endp
[-1]))
4098 nstore
[endp
- startp
] = DIR_SEPARATOR
;
4099 nstore
[endp
- startp
+ 1] = 0;
4102 nstore
[endp
- startp
] = 0;
4103 add_prefix (&startfile_prefixes
, nstore
, NULL
,
4104 PREFIX_PRIORITY_LAST
, 0, 1);
4107 endp
= startp
= endp
+ 1;
4114 /* Process the options and store input files and switches in their
4117 last_language_n_infiles
= -1;
4119 decode_cmdline_options_to_array (argc
, argv
, CL_DRIVER
,
4120 &decoded_options
, &decoded_options_count
);
4122 handlers
.unknown_option_callback
= driver_unknown_option_callback
;
4123 handlers
.wrong_lang_callback
= driver_wrong_lang_callback
;
4124 handlers
.post_handling_callback
= driver_post_handling_callback
;
4125 handlers
.num_handlers
= 1;
4126 handlers
.handlers
[0].handler
= driver_handle_option
;
4127 handlers
.handlers
[0].mask
= CL_DRIVER
;
4129 for (j
= 1; j
< decoded_options_count
; j
++)
4131 switch (decoded_options
[j
].opt_index
)
4143 for (j
= 1; j
< decoded_options_count
; j
++)
4145 if (decoded_options
[j
].opt_index
== OPT_SPECIAL_input_file
)
4147 const char *arg
= decoded_options
[j
].arg
;
4148 const char *p
= strrchr (arg
, '@');
4152 #ifdef HAVE_TARGET_OBJECT_SUFFIX
4153 arg
= convert_filename (arg
, 0, access (arg
, F_OK
));
4155 /* For LTO static archive support we handle input file
4156 specifications that are composed of a filename and
4157 an offset like FNAME@OFFSET. */
4160 && sscanf (p
, "@%li%n", &offset
, &consumed
) >= 1
4161 && strlen (p
) == (unsigned int)consumed
)
4163 fname
= (char *)xmalloc (p
- arg
+ 1);
4164 memcpy (fname
, arg
, p
- arg
);
4165 fname
[p
- arg
] = '\0';
4166 /* Only accept non-stdin and existing FNAME parts, otherwise
4167 try with the full name. */
4168 if (strcmp (fname
, "-") == 0 || access (fname
, F_OK
) < 0)
4171 fname
= xstrdup (arg
);
4175 fname
= xstrdup (arg
);
4177 if (strcmp (fname
, "-") != 0 && access (fname
, F_OK
) < 0)
4178 perror_with_name (fname
);
4180 add_infile (arg
, spec_lang
);
4186 read_cmdline_option (decoded_options
+ j
, CL_DRIVER
, &handlers
);
4189 /* If -save-temps=obj and -o name, create the prefix to use for %b.
4190 Otherwise just make -save-temps=obj the same as -save-temps=cwd. */
4191 if (save_temps_flag
== SAVE_TEMPS_OBJ
&& save_temps_prefix
!= NULL
)
4193 save_temps_length
= strlen (save_temps_prefix
);
4194 temp
= strrchr (lbasename (save_temps_prefix
), '.');
4197 save_temps_length
-= strlen (temp
);
4198 save_temps_prefix
[save_temps_length
] = '\0';
4202 else if (save_temps_prefix
!= NULL
)
4204 free (save_temps_prefix
);
4205 save_temps_prefix
= NULL
;
4208 if (save_temps_flag
&& use_pipes
)
4210 /* -save-temps overrides -pipe, so that temp files are produced */
4211 if (save_temps_flag
)
4212 warning (0, "-pipe ignored because -save-temps specified");
4218 const char *gcd
= getenv ("GCC_COMPARE_DEBUG");
4220 if (gcd
&& gcd
[0] == '-')
4223 compare_debug_opt
= gcd
;
4225 else if (gcd
&& *gcd
&& strcmp (gcd
, "0"))
4228 compare_debug_opt
= "-gtoggle";
4231 else if (compare_debug
< 0)
4234 gcc_assert (!compare_debug_opt
);
4237 /* Set up the search paths. We add directories that we expect to
4238 contain GNU Toolchain components before directories specified by
4239 the machine description so that we will find GNU components (like
4240 the GNU assembler) before those of the host system. */
4242 /* If we don't know where the toolchain has been installed, use the
4243 configured-in locations. */
4244 if (!gcc_exec_prefix
)
4247 add_prefix (&exec_prefixes
, standard_libexec_prefix
, "GCC",
4248 PREFIX_PRIORITY_LAST
, 1, 0);
4249 add_prefix (&exec_prefixes
, standard_libexec_prefix
, "BINUTILS",
4250 PREFIX_PRIORITY_LAST
, 2, 0);
4251 add_prefix (&exec_prefixes
, standard_exec_prefix
, "BINUTILS",
4252 PREFIX_PRIORITY_LAST
, 2, 0);
4254 add_prefix (&startfile_prefixes
, standard_exec_prefix
, "BINUTILS",
4255 PREFIX_PRIORITY_LAST
, 1, 0);
4258 gcc_assert (!IS_ABSOLUTE_PATH (tooldir_base_prefix
));
4259 tooldir_prefix
= concat (tooldir_base_prefix
, spec_machine
,
4260 dir_separator_str
, NULL
);
4262 /* Look for tools relative to the location from which the driver is
4263 running, or, if that is not available, the configured prefix. */
4265 = concat (gcc_exec_prefix
? gcc_exec_prefix
: standard_exec_prefix
,
4266 spec_machine
, dir_separator_str
,
4267 spec_version
, dir_separator_str
, tooldir_prefix
, NULL
);
4269 add_prefix (&exec_prefixes
,
4270 concat (tooldir_prefix
, "bin", dir_separator_str
, NULL
),
4271 "BINUTILS", PREFIX_PRIORITY_LAST
, 0, 0);
4272 add_prefix (&startfile_prefixes
,
4273 concat (tooldir_prefix
, "lib", dir_separator_str
, NULL
),
4274 "BINUTILS", PREFIX_PRIORITY_LAST
, 0, 1);
4276 #if defined(TARGET_SYSTEM_ROOT_RELOCATABLE) && !defined(VMS)
4277 /* If the normal TARGET_SYSTEM_ROOT is inside of $exec_prefix,
4278 then consider it to relocate with the rest of the GCC installation
4279 if GCC_EXEC_PREFIX is set.
4280 ``make_relative_prefix'' is not compiled for VMS, so don't call it. */
4281 if (target_system_root
&& !target_system_root_changed
&& gcc_exec_prefix
)
4283 char *tmp_prefix
= get_relative_prefix (argv
[0],
4284 standard_bindir_prefix
,
4285 target_system_root
);
4286 if (tmp_prefix
&& access_check (tmp_prefix
, F_OK
) == 0)
4288 target_system_root
= tmp_prefix
;
4289 target_system_root_changed
= 1;
4294 /* More prefixes are enabled in main, after we read the specs file
4295 and determine whether this is cross-compilation or not. */
4297 if (n_infiles
== last_language_n_infiles
&& spec_lang
!= 0)
4298 warning (0, "%<-x %s%> after last input file has no effect", spec_lang
);
4300 if (compare_debug
== 2 || compare_debug
== 3)
4303 switches
[n_switches
].part1
= concat ("fcompare-debug=",
4306 switches
[n_switches
].args
= 0;
4307 switches
[n_switches
].live_cond
= 0;
4308 switches
[n_switches
].validated
= 0;
4309 switches
[n_switches
].ordering
= 0;
4314 /* Ensure we only invoke each subprocess once. */
4315 if (print_subprocess_help
|| print_help_list
|| print_version
)
4319 /* Create a dummy input file, so that we can pass
4320 the help option on to the various sub-processes. */
4321 add_infile ("help-dummy", "c");
4325 switches
[n_switches
].part1
= 0;
4327 infiles
[n_infiles
].name
= 0;
4330 /* Store switches not filtered out by %<S in spec in COLLECT_GCC_OPTIONS
4331 and place that in the environment. */
4334 set_collect_gcc_options (void)
4339 /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
4341 obstack_grow (&collect_obstack
, "COLLECT_GCC_OPTIONS=",
4342 sizeof ("COLLECT_GCC_OPTIONS=") - 1);
4345 for (i
= 0; (int) i
< n_switches
; i
++)
4347 const char *const *args
;
4350 obstack_grow (&collect_obstack
, " ", 1);
4354 /* Ignore elided switches. */
4355 if ((switches
[i
].live_cond
& SWITCH_IGNORE
) != 0)
4358 obstack_grow (&collect_obstack
, "'-", 2);
4359 q
= switches
[i
].part1
;
4360 while ((p
= strchr (q
, '\'')))
4362 obstack_grow (&collect_obstack
, q
, p
- q
);
4363 obstack_grow (&collect_obstack
, "'\\''", 4);
4366 obstack_grow (&collect_obstack
, q
, strlen (q
));
4367 obstack_grow (&collect_obstack
, "'", 1);
4369 for (args
= switches
[i
].args
; args
&& *args
; args
++)
4371 obstack_grow (&collect_obstack
, " '", 2);
4373 while ((p
= strchr (q
, '\'')))
4375 obstack_grow (&collect_obstack
, q
, p
- q
);
4376 obstack_grow (&collect_obstack
, "'\\''", 4);
4379 obstack_grow (&collect_obstack
, q
, strlen (q
));
4380 obstack_grow (&collect_obstack
, "'", 1);
4383 obstack_grow (&collect_obstack
, "\0", 1);
4384 xputenv (XOBFINISH (&collect_obstack
, char *));
4387 /* Process a spec string, accumulating and running commands. */
4389 /* These variables describe the input file name.
4390 input_file_number is the index on outfiles of this file,
4391 so that the output file name can be stored for later use by %o.
4392 input_basename is the start of the part of the input file
4393 sans all directory names, and basename_length is the number
4394 of characters starting there excluding the suffix .c or whatever. */
4396 static const char *gcc_input_filename
;
4397 static int input_file_number
;
4398 size_t input_filename_length
;
4399 static int basename_length
;
4400 static int suffixed_basename_length
;
4401 static const char *input_basename
;
4402 static const char *input_suffix
;
4403 #ifndef HOST_LACKS_INODE_NUMBERS
4404 static struct stat input_stat
;
4406 static int input_stat_set
;
4408 /* The compiler used to process the current input file. */
4409 static struct compiler
*input_file_compiler
;
4411 /* These are variables used within do_spec and do_spec_1. */
4413 /* Nonzero if an arg has been started and not yet terminated
4414 (with space, tab or newline). */
4415 static int arg_going
;
4417 /* Nonzero means %d or %g has been seen; the next arg to be terminated
4418 is a temporary file name. */
4419 static int delete_this_arg
;
4421 /* Nonzero means %w has been seen; the next arg to be terminated
4422 is the output file name of this compilation. */
4423 static int this_is_output_file
;
4425 /* Nonzero means %s has been seen; the next arg to be terminated
4426 is the name of a library file and we should try the standard
4427 search dirs for it. */
4428 static int this_is_library_file
;
4430 /* Nonzero means %T has been seen; the next arg to be terminated
4431 is the name of a linker script and we should try all of the
4432 standard search dirs for it. If it is found insert a --script
4433 command line switch and then substitute the full path in place,
4434 otherwise generate an error message. */
4435 static int this_is_linker_script
;
4437 /* Nonzero means that the input of this command is coming from a pipe. */
4438 static int input_from_pipe
;
4440 /* Nonnull means substitute this for any suffix when outputting a switches
4442 static const char *suffix_subst
;
4444 /* If there is an argument being accumulated, terminate it and store it. */
4447 end_going_arg (void)
4453 obstack_1grow (&obstack
, 0);
4454 string
= XOBFINISH (&obstack
, const char *);
4455 if (this_is_library_file
)
4456 string
= find_file (string
);
4457 if (this_is_linker_script
)
4459 char * full_script_path
= find_a_file (&startfile_prefixes
, string
, R_OK
, true);
4461 if (full_script_path
== NULL
)
4463 error ("unable to locate default linker script %qs in the library search paths", string
);
4464 /* Script was not found on search path. */
4467 store_arg ("--script", false, false);
4468 string
= full_script_path
;
4470 store_arg (string
, delete_this_arg
, this_is_output_file
);
4471 if (this_is_output_file
)
4472 outfiles
[input_file_number
] = string
;
4478 /* Parse the WRAPPER string which is a comma separated list of the command line
4479 and insert them into the beginning of argbuf. */
4482 insert_wrapper (const char *wrapper
)
4486 char *buf
= xstrdup (wrapper
);
4495 while ((p
= strchr (p
, ',')) != NULL
);
4497 if (argbuf_index
+ n
>= argbuf_length
)
4499 argbuf_length
= argbuf_length
* 2;
4500 while (argbuf_length
< argbuf_index
+ n
)
4502 argbuf
= XRESIZEVEC (const char *, argbuf
, argbuf_length
);
4504 for (i
= argbuf_index
- 1; i
>= 0; i
--)
4505 argbuf
[i
+ n
] = argbuf
[i
];
4518 while ((p
= strchr (p
, ',')) != NULL
);
4519 gcc_assert (i
== n
);
4523 /* Process the spec SPEC and run the commands specified therein.
4524 Returns 0 if the spec is successfully processed; -1 if failed. */
4527 do_spec (const char *spec
)
4531 value
= do_spec_2 (spec
);
4533 /* Force out any unfinished command.
4534 If -pipe, this forces out the last command if it ended in `|'. */
4537 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
4540 set_collect_gcc_options ();
4542 if (argbuf_index
> 0)
4550 do_spec_2 (const char *spec
)
4556 delete_this_arg
= 0;
4557 this_is_output_file
= 0;
4558 this_is_library_file
= 0;
4559 this_is_linker_script
= 0;
4560 input_from_pipe
= 0;
4561 suffix_subst
= NULL
;
4563 result
= do_spec_1 (spec
, 0, NULL
);
4571 /* Process the given spec string and add any new options to the end
4572 of the switches/n_switches array. */
4575 do_option_spec (const char *name
, const char *spec
)
4577 unsigned int i
, value_count
, value_len
;
4578 const char *p
, *q
, *value
;
4579 char *tmp_spec
, *tmp_spec_p
;
4581 if (configure_default_options
[0].name
== NULL
)
4584 for (i
= 0; i
< ARRAY_SIZE (configure_default_options
); i
++)
4585 if (strcmp (configure_default_options
[i
].name
, name
) == 0)
4587 if (i
== ARRAY_SIZE (configure_default_options
))
4590 value
= configure_default_options
[i
].value
;
4591 value_len
= strlen (value
);
4593 /* Compute the size of the final spec. */
4596 while ((p
= strstr (p
, "%(VALUE)")) != NULL
)
4602 /* Replace each %(VALUE) by the specified value. */
4603 tmp_spec
= (char *) alloca (strlen (spec
) + 1
4604 + value_count
* (value_len
- strlen ("%(VALUE)")));
4605 tmp_spec_p
= tmp_spec
;
4607 while ((p
= strstr (q
, "%(VALUE)")) != NULL
)
4609 memcpy (tmp_spec_p
, q
, p
- q
);
4610 tmp_spec_p
= tmp_spec_p
+ (p
- q
);
4611 memcpy (tmp_spec_p
, value
, value_len
);
4612 tmp_spec_p
+= value_len
;
4613 q
= p
+ strlen ("%(VALUE)");
4615 strcpy (tmp_spec_p
, q
);
4617 do_self_spec (tmp_spec
);
4620 /* Process the given spec string and add any new options to the end
4621 of the switches/n_switches array. */
4624 do_self_spec (const char *spec
)
4629 do_spec_1 (" ", 0, NULL
);
4631 /* Mark %<S switches processed by do_self_spec to be ignored permanently.
4632 do_self_specs adds the replacements to switches array, so it shouldn't
4633 be processed afterwards. */
4634 for (i
= 0; i
< n_switches
; i
++)
4635 if ((switches
[i
].live_cond
& SWITCH_IGNORE
))
4636 switches
[i
].live_cond
|= SWITCH_IGNORE_PERMANENTLY
;
4638 if (argbuf_index
> 0)
4640 switches
= XRESIZEVEC (struct switchstr
, switches
,
4641 n_switches
+ argbuf_index
+ 1);
4643 for (i
= 0; i
< argbuf_index
; i
++)
4645 struct switchstr
*sw
;
4646 const char *p
= argbuf
[i
];
4649 /* Each switch should start with '-'. */
4651 fatal_error ("switch %qs does not start with %<-%>", argbuf
[i
]);
4656 sw
= &switches
[n_switches
++];
4662 /* Deal with option arguments in separate argv elements. */
4663 if ((SWITCH_TAKES_ARG (c
) > (p
[1] != 0))
4664 || WORD_SWITCH_TAKES_ARG (p
))
4667 int n_args
= WORD_SWITCH_TAKES_ARG (p
);
4671 /* Count only the option arguments in separate argv elements. */
4672 n_args
= SWITCH_TAKES_ARG (c
) - (p
[1] != 0);
4674 if (i
+ n_args
>= argbuf_index
)
4675 fatal_error ("argument to %<-%s%> is missing", p
);
4677 = XNEWVEC (const char *, n_args
+ 1);
4679 sw
->args
[j
++] = argbuf
[++i
];
4680 /* Null-terminate the vector. */
4685 /* On some systems, ld cannot handle "-o" without
4686 a space. So split the option from its argument. */
4687 char *part1
= XNEWVEC (char, 2);
4692 sw
->args
= XNEWVEC (const char *, 2);
4693 sw
->args
[0] = xstrdup (p
+1);
4700 switches
[n_switches
].part1
= 0;
4704 /* Callback for processing %D and %I specs. */
4706 struct spec_path_info
{
4711 bool separate_options
;
4715 spec_path (char *path
, void *data
)
4717 struct spec_path_info
*info
= (struct spec_path_info
*) data
;
4721 if (info
->omit_relative
&& !IS_ABSOLUTE_PATH (path
))
4724 if (info
->append_len
!= 0)
4726 len
= strlen (path
);
4727 memcpy (path
+ len
, info
->append
, info
->append_len
+ 1);
4730 if (!is_directory (path
, true))
4733 do_spec_1 (info
->option
, 1, NULL
);
4734 if (info
->separate_options
)
4735 do_spec_1 (" ", 0, NULL
);
4737 if (info
->append_len
== 0)
4739 len
= strlen (path
);
4740 save
= path
[len
- 1];
4741 if (IS_DIR_SEPARATOR (path
[len
- 1]))
4742 path
[len
- 1] = '\0';
4745 do_spec_1 (path
, 1, NULL
);
4746 do_spec_1 (" ", 0, NULL
);
4748 /* Must not damage the original path. */
4749 if (info
->append_len
== 0)
4750 path
[len
- 1] = save
;
4755 /* Create a temporary FILE with the contents of ARGV. Add @FILE to the
4759 create_at_file (char **argv
)
4761 char *temp_file
= make_temp_file ("");
4762 char *at_argument
= concat ("@", temp_file
, NULL
);
4763 FILE *f
= fopen (temp_file
, "w");
4767 fatal_error ("could not open temporary response file %s",
4770 status
= writeargv (argv
, f
);
4773 fatal_error ("could not write to temporary response file %s",
4776 status
= fclose (f
);
4779 fatal_error ("could not close temporary response file %s",
4782 store_arg (at_argument
, 0, 0);
4784 record_temp_file (temp_file
, !save_temps_flag
, !save_temps_flag
);
4787 /* True if we should compile INFILE. */
4790 compile_input_file_p (struct infile
*infile
)
4792 if ((!infile
->language
) || (infile
->language
[0] != '*'))
4793 if (infile
->incompiler
== input_file_compiler
)
4798 /* Process the sub-spec SPEC as a portion of a larger spec.
4799 This is like processing a whole spec except that we do
4800 not initialize at the beginning and we do not supply a
4801 newline by default at the end.
4802 INSWITCH nonzero means don't process %-sequences in SPEC;
4803 in this case, % is treated as an ordinary character.
4804 This is used while substituting switches.
4805 INSWITCH nonzero also causes SPC not to terminate an argument.
4807 Value is zero unless a line was finished
4808 and the command on that line reported an error. */
4811 do_spec_1 (const char *spec
, int inswitch
, const char *soft_matched_part
)
4813 const char *p
= spec
;
4819 /* If substituting a switch, treat all chars like letters.
4820 Otherwise, NL, SPC, TAB and % are special. */
4821 switch (inswitch
? 'a' : c
)
4826 if (argbuf_index
> 0 && !strcmp (argbuf
[argbuf_index
- 1], "|"))
4828 /* A `|' before the newline means use a pipe here,
4829 but only if -pipe was specified.
4830 Otherwise, execute now and don't pass the `|' as an arg. */
4833 input_from_pipe
= 1;
4840 set_collect_gcc_options ();
4842 if (argbuf_index
> 0)
4848 /* Reinitialize for a new command, and for a new argument. */
4851 delete_this_arg
= 0;
4852 this_is_output_file
= 0;
4853 this_is_library_file
= 0;
4854 this_is_linker_script
= 0;
4855 input_from_pipe
= 0;
4862 obstack_1grow (&obstack
, c
);
4870 /* Reinitialize for a new argument. */
4871 delete_this_arg
= 0;
4872 this_is_output_file
= 0;
4873 this_is_library_file
= 0;
4874 this_is_linker_script
= 0;
4881 fatal_error ("spec %qs invalid", spec
);
4884 if (save_temps_length
)
4885 obstack_grow (&obstack
, save_temps_prefix
, save_temps_length
);
4887 obstack_grow (&obstack
, input_basename
, basename_length
);
4888 if (compare_debug
< 0)
4889 obstack_grow (&obstack
, ".gk", 3);
4894 if (save_temps_length
)
4895 obstack_grow (&obstack
, save_temps_prefix
, save_temps_length
);
4897 obstack_grow (&obstack
, input_basename
, suffixed_basename_length
);
4898 if (compare_debug
< 0)
4899 obstack_grow (&obstack
, ".gk", 3);
4904 delete_this_arg
= 2;
4907 /* Dump out the directories specified with LIBRARY_PATH,
4908 followed by the absolute directories
4909 that we search for startfiles. */
4912 struct spec_path_info info
;
4915 info
.append_len
= 0;
4916 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
4917 /* Used on systems which record the specified -L dirs
4918 and use them to search for dynamic linking.
4919 Relative directories always come from -B,
4920 and it is better not to use them for searching
4921 at run time. In particular, stage1 loses. */
4922 info
.omit_relative
= true;
4924 info
.omit_relative
= false;
4926 info
.separate_options
= false;
4928 for_each_path (&startfile_prefixes
, true, 0, spec_path
, &info
);
4933 /* %efoo means report an error with `foo' as error message
4934 and don't execute any more commands for this file. */
4938 while (*p
!= 0 && *p
!= '\n')
4940 buf
= (char *) alloca (p
- q
+ 1);
4941 strncpy (buf
, q
, p
- q
);
4943 error ("%s", _(buf
));
4948 /* %nfoo means report a notice with `foo' on stderr. */
4952 while (*p
!= 0 && *p
!= '\n')
4954 buf
= (char *) alloca (p
- q
+ 1);
4955 strncpy (buf
, q
, p
- q
);
4957 inform (0, "%s", _(buf
));
4967 /* If save_temps_flag is off, and the HOST_BIT_BUCKET is
4968 defined, and it is not a directory, and it is
4969 writable, use it. Otherwise, treat this like any
4970 other temporary file. */
4972 if ((!save_temps_flag
)
4973 && (stat (HOST_BIT_BUCKET
, &st
) == 0) && (!S_ISDIR (st
.st_mode
))
4974 && (access (HOST_BIT_BUCKET
, W_OK
) == 0))
4976 obstack_grow (&obstack
, HOST_BIT_BUCKET
,
4977 strlen (HOST_BIT_BUCKET
));
4978 delete_this_arg
= 0;
4983 goto create_temp_file
;
4987 obstack_1grow (&obstack
, '-');
4988 delete_this_arg
= 0;
4991 /* consume suffix */
4992 while (*p
== '.' || ISALNUM ((unsigned char) *p
))
4994 if (p
[0] == '%' && p
[1] == 'O')
4999 goto create_temp_file
;
5003 /* consume suffix */
5004 while (*p
== '.' || ISALNUM ((unsigned char) *p
))
5006 if (p
[0] == '%' && p
[1] == 'O')
5011 goto create_temp_file
;
5017 struct temp_name
*t
;
5019 const char *suffix
= p
;
5020 char *saved_suffix
= NULL
;
5022 while (*p
== '.' || ISALNUM ((unsigned char) *p
))
5024 suffix_length
= p
- suffix
;
5025 if (p
[0] == '%' && p
[1] == 'O')
5028 /* We don't support extra suffix characters after %O. */
5029 if (*p
== '.' || ISALNUM ((unsigned char) *p
))
5030 fatal_error ("spec %qs has invalid %<%%0%c%>", spec
, *p
);
5031 if (suffix_length
== 0)
5032 suffix
= TARGET_OBJECT_SUFFIX
;
5036 = XNEWVEC (char, suffix_length
5037 + strlen (TARGET_OBJECT_SUFFIX
));
5038 strncpy (saved_suffix
, suffix
, suffix_length
);
5039 strcpy (saved_suffix
+ suffix_length
,
5040 TARGET_OBJECT_SUFFIX
);
5042 suffix_length
+= strlen (TARGET_OBJECT_SUFFIX
);
5045 if (compare_debug
< 0)
5047 suffix
= concat (".gk", suffix
, NULL
);
5051 /* If -save-temps=obj and -o were specified, use that for the
5053 if (save_temps_length
)
5056 temp_filename_length
5057 = save_temps_length
+ suffix_length
+ 1;
5058 tmp
= (char *) alloca (temp_filename_length
);
5059 memcpy (tmp
, save_temps_prefix
, save_temps_length
);
5060 memcpy (tmp
+ save_temps_length
, suffix
, suffix_length
);
5061 tmp
[save_temps_length
+ suffix_length
] = '\0';
5062 temp_filename
= save_string (tmp
,
5063 temp_filename_length
+ 1);
5064 obstack_grow (&obstack
, temp_filename
,
5065 temp_filename_length
);
5067 delete_this_arg
= 0;
5071 /* If the gcc_input_filename has the same suffix specified
5072 for the %g, %u, or %U, and -save-temps is specified,
5073 we could end up using that file as an intermediate
5074 thus clobbering the user's source file (.e.g.,
5075 gcc -save-temps foo.s would clobber foo.s with the
5076 output of cpp0). So check for this condition and
5077 generate a temp file as the intermediate. */
5079 if (save_temps_flag
)
5082 temp_filename_length
= basename_length
+ suffix_length
+ 1;
5083 tmp
= (char *) alloca (temp_filename_length
);
5084 memcpy (tmp
, input_basename
, basename_length
);
5085 memcpy (tmp
+ basename_length
, suffix
, suffix_length
);
5086 tmp
[basename_length
+ suffix_length
] = '\0';
5087 temp_filename
= tmp
;
5089 if (strcmp (temp_filename
, gcc_input_filename
) != 0)
5091 #ifndef HOST_LACKS_INODE_NUMBERS
5092 struct stat st_temp
;
5094 /* Note, set_input() resets input_stat_set to 0. */
5095 if (input_stat_set
== 0)
5097 input_stat_set
= stat (gcc_input_filename
,
5099 if (input_stat_set
>= 0)
5103 /* If we have the stat for the gcc_input_filename
5104 and we can do the stat for the temp_filename
5105 then the they could still refer to the same
5106 file if st_dev/st_ino's are the same. */
5107 if (input_stat_set
!= 1
5108 || stat (temp_filename
, &st_temp
) < 0
5109 || input_stat
.st_dev
!= st_temp
.st_dev
5110 || input_stat
.st_ino
!= st_temp
.st_ino
)
5112 /* Just compare canonical pathnames. */
5113 char* input_realname
= lrealpath (gcc_input_filename
);
5114 char* temp_realname
= lrealpath (temp_filename
);
5115 bool files_differ
= strcmp (input_realname
, temp_realname
);
5116 free (input_realname
);
5117 free (temp_realname
);
5121 temp_filename
= save_string (temp_filename
,
5122 temp_filename_length
+ 1);
5123 obstack_grow (&obstack
, temp_filename
,
5124 temp_filename_length
);
5126 delete_this_arg
= 0;
5132 /* See if we already have an association of %g/%u/%U and
5134 for (t
= temp_names
; t
; t
= t
->next
)
5135 if (t
->length
== suffix_length
5136 && strncmp (t
->suffix
, suffix
, suffix_length
) == 0
5137 && t
->unique
== (c
== 'u' || c
== 'U' || c
== 'j'))
5140 /* Make a new association if needed. %u and %j
5142 if (t
== 0 || c
== 'u' || c
== 'j')
5146 t
= XNEW (struct temp_name
);
5147 t
->next
= temp_names
;
5150 t
->length
= suffix_length
;
5153 t
->suffix
= saved_suffix
;
5154 saved_suffix
= NULL
;
5157 t
->suffix
= save_string (suffix
, suffix_length
);
5158 t
->unique
= (c
== 'u' || c
== 'U' || c
== 'j');
5159 temp_filename
= make_temp_file (t
->suffix
);
5160 temp_filename_length
= strlen (temp_filename
);
5161 t
->filename
= temp_filename
;
5162 t
->filename_length
= temp_filename_length
;
5166 free (saved_suffix
);
5168 obstack_grow (&obstack
, t
->filename
, t
->filename_length
);
5169 delete_this_arg
= 1;
5177 if (at_file_supplied
)
5179 /* We are going to expand `%i' to `@FILE', where FILE
5180 is a newly-created temporary filename. The filenames
5181 that would usually be expanded in place of %o will be
5182 written to the temporary file. */
5187 for (i
= 0; i
< n_infiles
; i
++)
5188 if (compile_input_file_p (&infiles
[i
]))
5191 argv
= (char **) alloca (sizeof (char *) * (n_files
+ 1));
5193 /* Copy the strings over. */
5194 for (i
= 0, j
= 0; i
< n_infiles
; i
++)
5195 if (compile_input_file_p (&infiles
[i
]))
5197 argv
[j
] = CONST_CAST (char *, infiles
[i
].name
);
5198 infiles
[i
].compiled
= true;
5203 create_at_file (argv
);
5206 for (i
= 0; (int) i
< n_infiles
; i
++)
5207 if (compile_input_file_p (&infiles
[i
]))
5209 store_arg (infiles
[i
].name
, 0, 0);
5210 infiles
[i
].compiled
= true;
5215 obstack_grow (&obstack
, gcc_input_filename
,
5216 input_filename_length
);
5223 struct spec_path_info info
;
5227 do_spec_1 ("-imultilib", 1, NULL
);
5228 /* Make this a separate argument. */
5229 do_spec_1 (" ", 0, NULL
);
5230 do_spec_1 (multilib_dir
, 1, NULL
);
5231 do_spec_1 (" ", 0, NULL
);
5234 if (gcc_exec_prefix
)
5236 do_spec_1 ("-iprefix", 1, NULL
);
5237 /* Make this a separate argument. */
5238 do_spec_1 (" ", 0, NULL
);
5239 do_spec_1 (gcc_exec_prefix
, 1, NULL
);
5240 do_spec_1 (" ", 0, NULL
);
5243 if (target_system_root_changed
||
5244 (target_system_root
&& target_sysroot_hdrs_suffix
))
5246 do_spec_1 ("-isysroot", 1, NULL
);
5247 /* Make this a separate argument. */
5248 do_spec_1 (" ", 0, NULL
);
5249 do_spec_1 (target_system_root
, 1, NULL
);
5250 if (target_sysroot_hdrs_suffix
)
5251 do_spec_1 (target_sysroot_hdrs_suffix
, 1, NULL
);
5252 do_spec_1 (" ", 0, NULL
);
5255 info
.option
= "-isystem";
5256 info
.append
= "include";
5257 info
.append_len
= strlen (info
.append
);
5258 info
.omit_relative
= false;
5259 info
.separate_options
= true;
5261 for_each_path (&include_prefixes
, false, info
.append_len
,
5264 info
.append
= "include-fixed";
5265 if (*sysroot_hdrs_suffix_spec
)
5266 info
.append
= concat (info
.append
, dir_separator_str
,
5267 multilib_dir
, NULL
);
5268 info
.append_len
= strlen (info
.append
);
5269 for_each_path (&include_prefixes
, false, info
.append_len
,
5276 int max
= n_infiles
;
5277 max
+= lang_specific_extra_outfiles
;
5279 if (HAVE_GNU_LD
&& at_file_supplied
)
5281 /* We are going to expand `%o' to `@FILE', where FILE
5282 is a newly-created temporary filename. The filenames
5283 that would usually be expanded in place of %o will be
5284 written to the temporary file. */
5289 /* Convert OUTFILES into a form suitable for writeargv. */
5291 /* Determine how many are non-NULL. */
5292 for (n_files
= 0, i
= 0; i
< max
; i
++)
5293 n_files
+= outfiles
[i
] != NULL
;
5295 argv
= (char **) alloca (sizeof (char *) * (n_files
+ 1));
5297 /* Copy the strings over. */
5298 for (i
= 0, j
= 0; i
< max
; i
++)
5301 argv
[j
] = CONST_CAST (char *, outfiles
[i
]);
5306 create_at_file (argv
);
5309 for (i
= 0; i
< max
; i
++)
5311 store_arg (outfiles
[i
], 0, 0);
5316 obstack_grow (&obstack
, TARGET_OBJECT_SUFFIX
, strlen (TARGET_OBJECT_SUFFIX
));
5321 this_is_library_file
= 1;
5325 this_is_linker_script
= 1;
5329 outfiles
[input_file_number
] = NULL
;
5333 this_is_output_file
= 1;
5338 int cur_index
= argbuf_index
;
5339 /* Handle the {...} following the %W. */
5341 fatal_error ("spec %qs has invalid %<%%W%c%>", spec
, *p
);
5342 p
= handle_braces (p
+ 1);
5346 /* If any args were output, mark the last one for deletion
5348 if (argbuf_index
!= cur_index
)
5349 record_temp_file (argbuf
[argbuf_index
- 1], 0, 1);
5353 /* %x{OPTION} records OPTION for %X to output. */
5359 /* Skip past the option value and make a copy. */
5361 fatal_error ("spec %qs has invalid %<%%x%c%>", spec
, *p
);
5364 string
= save_string (p1
+ 1, p
- p1
- 2);
5366 /* See if we already recorded this option. */
5367 for (i
= 0; i
< n_linker_options
; i
++)
5368 if (! strcmp (string
, linker_options
[i
]))
5374 /* This option is new; add it. */
5375 add_linker_option (string
, strlen (string
));
5379 /* Dump out the options accumulated previously using %x. */
5381 for (i
= 0; i
< n_linker_options
; i
++)
5383 do_spec_1 (linker_options
[i
], 1, NULL
);
5384 /* Make each accumulated option a separate argument. */
5385 do_spec_1 (" ", 0, NULL
);
5389 /* Dump out the options accumulated previously using -Wa,. */
5391 for (i
= 0; i
< n_assembler_options
; i
++)
5393 do_spec_1 (assembler_options
[i
], 1, NULL
);
5394 /* Make each accumulated option a separate argument. */
5395 do_spec_1 (" ", 0, NULL
);
5399 /* Dump out the options accumulated previously using -Wp,. */
5401 for (i
= 0; i
< n_preprocessor_options
; i
++)
5403 do_spec_1 (preprocessor_options
[i
], 1, NULL
);
5404 /* Make each accumulated option a separate argument. */
5405 do_spec_1 (" ", 0, NULL
);
5409 /* Here are digits and numbers that just process
5410 a certain constant string as a spec. */
5413 value
= do_spec_1 (cc1_spec
, 0, NULL
);
5419 value
= do_spec_1 (cc1plus_spec
, 0, NULL
);
5425 value
= do_spec_1 (asm_spec
, 0, NULL
);
5431 value
= do_spec_1 (asm_final_spec
, 0, NULL
);
5438 const char *const spec
5439 = (input_file_compiler
->cpp_spec
5440 ? input_file_compiler
->cpp_spec
5442 value
= do_spec_1 (spec
, 0, NULL
);
5449 value
= do_spec_1 (endfile_spec
, 0, NULL
);
5455 value
= do_spec_1 (link_spec
, 0, NULL
);
5461 value
= do_spec_1 (lib_spec
, 0, NULL
);
5467 value
= do_spec_1 (libgcc_spec
, 0, NULL
);
5473 /* We assume there is a directory
5474 separator at the end of this string. */
5475 if (target_system_root
)
5477 obstack_grow (&obstack
, target_system_root
,
5478 strlen (target_system_root
));
5479 if (target_sysroot_suffix
)
5480 obstack_grow (&obstack
, target_sysroot_suffix
,
5481 strlen (target_sysroot_suffix
));
5486 value
= do_spec_1 (startfile_spec
, 0, NULL
);
5491 /* Here we define characters other than letters and digits. */
5494 p
= handle_braces (p
);
5500 p
= handle_spec_function (p
);
5506 obstack_1grow (&obstack
, '%');
5513 while (p
[len
] && p
[len
] != ' ' && p
[len
] != '%')
5515 suffix_subst
= save_string (p
- 1, len
+ 1);
5520 /* Henceforth ignore the option(s) matching the pattern
5525 int have_wildcard
= 0;
5528 while (p
[len
] && p
[len
] != ' ' && p
[len
] != '\t')
5531 if (p
[len
-1] == '*')
5534 for (i
= 0; i
< n_switches
; i
++)
5535 if (!strncmp (switches
[i
].part1
, p
, len
- have_wildcard
)
5536 && (have_wildcard
|| switches
[i
].part1
[len
] == '\0'))
5538 switches
[i
].live_cond
|= SWITCH_IGNORE
;
5539 switches
[i
].validated
= 1;
5547 if (soft_matched_part
)
5549 do_spec_1 (soft_matched_part
, 1, NULL
);
5550 do_spec_1 (" ", 0, NULL
);
5553 /* Catch the case where a spec string contains something like
5554 '%{foo:%*}'. i.e. there is no * in the pattern on the left
5555 hand side of the :. */
5556 error ("spec failure: %<%%*%> has not been initialized by pattern match");
5559 /* Process a string found as the value of a spec given by name.
5560 This feature allows individual machine descriptions
5561 to add and use their own specs.
5562 %[...] modifies -D options the way %P does;
5563 %(...) uses the spec unmodified. */
5565 warning (0, "use of obsolete %%[ operator in specs");
5568 const char *name
= p
;
5569 struct spec_list
*sl
;
5572 /* The string after the S/P is the name of a spec that is to be
5574 while (*p
&& *p
!= ')' && *p
!= ']')
5577 /* See if it's in the list. */
5578 for (len
= p
- name
, sl
= specs
; sl
; sl
= sl
->next
)
5579 if (sl
->name_len
== len
&& !strncmp (sl
->name
, name
, len
))
5581 name
= *(sl
->ptr_spec
);
5583 fnotice (stderr
, "Processing spec %c%s%c, which is '%s'\n",
5584 c
, sl
->name
, (c
== '(') ? ')' : ']', name
);
5593 value
= do_spec_1 (name
, 0, NULL
);
5599 char *x
= (char *) alloca (strlen (name
) * 2 + 1);
5601 const char *y
= name
;
5604 /* Copy all of NAME into BUF, but put __ after
5605 every -D and at the end of each arg. */
5608 if (! strncmp (y
, "-D", 2))
5619 && (*y
== ' ' || *y
== '\t' || *y
== '='
5620 || *y
== '}' || *y
== 0))
5633 value
= do_spec_1 (buf
, 0, NULL
);
5639 /* Discard the closing paren or bracket. */
5646 error ("spec failure: unrecognized spec option %qc", c
);
5652 /* Backslash: treat next character as ordinary. */
5657 /* Ordinary character: put it into the current argument. */
5658 obstack_1grow (&obstack
, c
);
5662 /* End of string. If we are processing a spec function, we need to
5663 end any pending argument. */
5664 if (processing_spec_function
)
5670 /* Look up a spec function. */
5672 static const struct spec_function
*
5673 lookup_spec_function (const char *name
)
5675 const struct spec_function
*sf
;
5677 for (sf
= static_spec_functions
; sf
->name
!= NULL
; sf
++)
5678 if (strcmp (sf
->name
, name
) == 0)
5684 /* Evaluate a spec function. */
5687 eval_spec_function (const char *func
, const char *args
)
5689 const struct spec_function
*sf
;
5690 const char *funcval
;
5692 /* Saved spec processing context. */
5693 int save_argbuf_index
;
5694 int save_argbuf_length
;
5695 const char **save_argbuf
;
5698 int save_delete_this_arg
;
5699 int save_this_is_output_file
;
5700 int save_this_is_library_file
;
5701 int save_input_from_pipe
;
5702 int save_this_is_linker_script
;
5703 const char *save_suffix_subst
;
5706 sf
= lookup_spec_function (func
);
5708 fatal_error ("unknown spec function %qs", func
);
5710 /* Push the spec processing context. */
5711 save_argbuf_index
= argbuf_index
;
5712 save_argbuf_length
= argbuf_length
;
5713 save_argbuf
= argbuf
;
5715 save_arg_going
= arg_going
;
5716 save_delete_this_arg
= delete_this_arg
;
5717 save_this_is_output_file
= this_is_output_file
;
5718 save_this_is_library_file
= this_is_library_file
;
5719 save_this_is_linker_script
= this_is_linker_script
;
5720 save_input_from_pipe
= input_from_pipe
;
5721 save_suffix_subst
= suffix_subst
;
5723 /* Create a new spec processing context, and build the function
5727 if (do_spec_2 (args
) < 0)
5728 fatal_error ("error in args to spec function %qs", func
);
5730 /* argbuf_index is an index for the next argument to be inserted, and
5731 so contains the count of the args already inserted. */
5733 funcval
= (*sf
->func
) (argbuf_index
, argbuf
);
5735 /* Pop the spec processing context. */
5736 argbuf_index
= save_argbuf_index
;
5737 argbuf_length
= save_argbuf_length
;
5739 argbuf
= save_argbuf
;
5741 arg_going
= save_arg_going
;
5742 delete_this_arg
= save_delete_this_arg
;
5743 this_is_output_file
= save_this_is_output_file
;
5744 this_is_library_file
= save_this_is_library_file
;
5745 this_is_linker_script
= save_this_is_linker_script
;
5746 input_from_pipe
= save_input_from_pipe
;
5747 suffix_subst
= save_suffix_subst
;
5752 /* Handle a spec function call of the form:
5756 ARGS is processed as a spec in a separate context and split into an
5757 argument vector in the normal fashion. The function returns a string
5758 containing a spec which we then process in the caller's context, or
5759 NULL if no processing is required. */
5762 handle_spec_function (const char *p
)
5765 const char *endp
, *funcval
;
5768 processing_spec_function
++;
5770 /* Get the function name. */
5771 for (endp
= p
; *endp
!= '\0'; endp
++)
5773 if (*endp
== '(') /* ) */
5775 /* Only allow [A-Za-z0-9], -, and _ in function names. */
5776 if (!ISALNUM (*endp
) && !(*endp
== '-' || *endp
== '_'))
5777 fatal_error ("malformed spec function name");
5779 if (*endp
!= '(') /* ) */
5780 fatal_error ("no arguments for spec function");
5781 func
= save_string (p
, endp
- p
);
5784 /* Get the arguments. */
5785 for (count
= 0; *endp
!= '\0'; endp
++)
5794 else if (*endp
== '(') /* ) */
5799 fatal_error ("malformed spec function arguments");
5800 args
= save_string (p
, endp
- p
);
5803 /* p now points to just past the end of the spec function expression. */
5805 funcval
= eval_spec_function (func
, args
);
5806 if (funcval
!= NULL
&& do_spec_1 (funcval
, 0, NULL
) < 0)
5812 processing_spec_function
--;
5817 /* Inline subroutine of handle_braces. Returns true if the current
5818 input suffix matches the atom bracketed by ATOM and END_ATOM. */
5820 input_suffix_matches (const char *atom
, const char *end_atom
)
5822 return (input_suffix
5823 && !strncmp (input_suffix
, atom
, end_atom
- atom
)
5824 && input_suffix
[end_atom
- atom
] == '\0');
5827 /* Subroutine of handle_braces. Returns true if the current
5828 input file's spec name matches the atom bracketed by ATOM and END_ATOM. */
5830 input_spec_matches (const char *atom
, const char *end_atom
)
5832 return (input_file_compiler
5833 && input_file_compiler
->suffix
5834 && input_file_compiler
->suffix
[0] != '\0'
5835 && !strncmp (input_file_compiler
->suffix
+ 1, atom
,
5837 && input_file_compiler
->suffix
[end_atom
- atom
+ 1] == '\0');
5840 /* Subroutine of handle_braces. Returns true if a switch
5841 matching the atom bracketed by ATOM and END_ATOM appeared on the
5844 switch_matches (const char *atom
, const char *end_atom
, int starred
)
5847 int len
= end_atom
- atom
;
5848 int plen
= starred
? len
: -1;
5850 for (i
= 0; i
< n_switches
; i
++)
5851 if (!strncmp (switches
[i
].part1
, atom
, len
)
5852 && (starred
|| switches
[i
].part1
[len
] == '\0')
5853 && check_live_switch (i
, plen
))
5859 /* Inline subroutine of handle_braces. Mark all of the switches which
5860 match ATOM (extends to END_ATOM; STARRED indicates whether there
5861 was a star after the atom) for later processing. */
5863 mark_matching_switches (const char *atom
, const char *end_atom
, int starred
)
5866 int len
= end_atom
- atom
;
5867 int plen
= starred
? len
: -1;
5869 for (i
= 0; i
< n_switches
; i
++)
5870 if (!strncmp (switches
[i
].part1
, atom
, len
)
5871 && (starred
|| switches
[i
].part1
[len
] == '\0')
5872 && check_live_switch (i
, plen
))
5873 switches
[i
].ordering
= 1;
5876 /* Inline subroutine of handle_braces. Process all the currently
5877 marked switches through give_switch, and clear the marks. */
5879 process_marked_switches (void)
5883 for (i
= 0; i
< n_switches
; i
++)
5884 if (switches
[i
].ordering
== 1)
5886 switches
[i
].ordering
= 0;
5891 /* Handle a %{ ... } construct. P points just inside the leading {.
5892 Returns a pointer one past the end of the brace block, or 0
5893 if we call do_spec_1 and that returns -1. */
5896 handle_braces (const char *p
)
5898 const char *atom
, *end_atom
;
5899 const char *d_atom
= NULL
, *d_end_atom
= NULL
;
5900 const char *orig
= p
;
5908 bool a_must_be_last
= false;
5909 bool ordered_set
= false;
5910 bool disjunct_set
= false;
5911 bool disj_matched
= false;
5912 bool disj_starred
= true;
5913 bool n_way_choice
= false;
5914 bool n_way_matched
= false;
5916 #define SKIP_WHITE() do { while (*p == ' ' || *p == '\t') p++; } while (0)
5923 /* Scan one "atom" (S in the description above of %{}, possibly
5924 with '!', '.', '@', ',', or '*' modifiers). */
5926 a_is_suffix
= false;
5927 a_is_starred
= false;
5928 a_is_negated
= false;
5929 a_is_spectype
= false;
5933 p
++, a_is_negated
= true;
5937 p
++, a_is_suffix
= true;
5939 p
++, a_is_spectype
= true;
5942 while (ISIDNUM(*p
) || *p
== '-' || *p
== '+' || *p
== '='
5943 || *p
== ',' || *p
== '.' || *p
== '@')
5948 p
++, a_is_starred
= 1;
5954 /* Substitute the switch(es) indicated by the current atom. */
5956 if (disjunct_set
|| n_way_choice
|| a_is_negated
|| a_is_suffix
5957 || a_is_spectype
|| atom
== end_atom
)
5960 mark_matching_switches (atom
, end_atom
, a_is_starred
);
5963 process_marked_switches ();
5967 /* Substitute some text if the current atom appears as a switch
5969 disjunct_set
= true;
5973 if (atom
== end_atom
)
5975 if (!n_way_choice
|| disj_matched
|| *p
== '|'
5976 || a_is_negated
|| a_is_suffix
|| a_is_spectype
5980 /* An empty term may appear as the last choice of an
5981 N-way choice set; it means "otherwise". */
5982 a_must_be_last
= true;
5983 disj_matched
= !n_way_matched
;
5984 disj_starred
= false;
5988 if ((a_is_suffix
|| a_is_spectype
) && a_is_starred
)
5992 disj_starred
= false;
5994 /* Don't bother testing this atom if we already have a
5996 if (!disj_matched
&& !n_way_matched
)
5999 a_matched
= input_suffix_matches (atom
, end_atom
);
6000 else if (a_is_spectype
)
6001 a_matched
= input_spec_matches (atom
, end_atom
);
6003 a_matched
= switch_matches (atom
, end_atom
, a_is_starred
);
6005 if (a_matched
!= a_is_negated
)
6007 disj_matched
= true;
6009 d_end_atom
= end_atom
;
6016 /* Found the body, that is, the text to substitute if the
6017 current disjunction matches. */
6018 p
= process_brace_body (p
+ 1, d_atom
, d_end_atom
, disj_starred
,
6019 disj_matched
&& !n_way_matched
);
6023 /* If we have an N-way choice, reset state for the next
6027 n_way_choice
= true;
6028 n_way_matched
|= disj_matched
;
6029 disj_matched
= false;
6030 disj_starred
= true;
6031 d_atom
= d_end_atom
= NULL
;
6040 while (*p
++ != '}');
6045 fatal_error ("braced spec %qs is invalid at %qc", orig
, *p
);
6050 /* Subroutine of handle_braces. Scan and process a brace substitution body
6051 (X in the description of %{} syntax). P points one past the colon;
6052 ATOM and END_ATOM bracket the first atom which was found to be true
6053 (present) in the current disjunction; STARRED indicates whether all
6054 the atoms in the current disjunction were starred (for syntax validation);
6055 MATCHED indicates whether the disjunction matched or not, and therefore
6056 whether or not the body is to be processed through do_spec_1 or just
6057 skipped. Returns a pointer to the closing } or ;, or 0 if do_spec_1
6061 process_brace_body (const char *p
, const char *atom
, const char *end_atom
,
6062 int starred
, int matched
)
6064 const char *body
, *end_body
;
6065 unsigned int nesting_level
;
6066 bool have_subst
= false;
6068 /* Locate the closing } or ;, honoring nested braces.
6069 Trim trailing whitespace. */
6078 if (!--nesting_level
)
6081 else if (*p
== ';' && nesting_level
== 1)
6083 else if (*p
== '%' && p
[1] == '*' && nesting_level
== 1)
6085 else if (*p
== '\0')
6091 while (end_body
[-1] == ' ' || end_body
[-1] == '\t')
6094 if (have_subst
&& !starred
)
6099 /* Copy the substitution body to permanent storage and execute it.
6100 If have_subst is false, this is a simple matter of running the
6101 body through do_spec_1... */
6102 char *string
= save_string (body
, end_body
- body
);
6105 if (do_spec_1 (string
, 0, NULL
) < 0)
6110 /* ... but if have_subst is true, we have to process the
6111 body once for each matching switch, with %* set to the
6112 variant part of the switch. */
6113 unsigned int hard_match_len
= end_atom
- atom
;
6116 for (i
= 0; i
< n_switches
; i
++)
6117 if (!strncmp (switches
[i
].part1
, atom
, hard_match_len
)
6118 && check_live_switch (i
, hard_match_len
))
6120 if (do_spec_1 (string
, 0,
6121 &switches
[i
].part1
[hard_match_len
]) < 0)
6123 /* Pass any arguments this switch has. */
6125 suffix_subst
= NULL
;
6133 fatal_error ("braced spec body %qs is invalid", body
);
6136 /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
6137 on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
6138 spec, or -1 if either exact match or %* is used.
6140 A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch
6141 whose value does not begin with "no-" is obsoleted by the same value
6142 with the "no-", similarly for a switch with the "no-" prefix. */
6145 check_live_switch (int switchnum
, int prefix_length
)
6147 const char *name
= switches
[switchnum
].part1
;
6150 /* If we already processed this switch and determined if it was
6151 live or not, return our past determination. */
6152 if (switches
[switchnum
].live_cond
!= 0)
6153 return ((switches
[switchnum
].live_cond
& SWITCH_LIVE
) != 0
6154 && (switches
[switchnum
].live_cond
& SWITCH_FALSE
) == 0
6155 && (switches
[switchnum
].live_cond
& SWITCH_IGNORE_PERMANENTLY
)
6158 /* In the common case of {<at-most-one-letter>*}, a negating
6159 switch would always match, so ignore that case. We will just
6160 send the conflicting switches to the compiler phase. */
6161 if (prefix_length
>= 0 && prefix_length
<= 1)
6164 /* Now search for duplicate in a manner that depends on the name. */
6168 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
6169 if (switches
[i
].part1
[0] == 'O')
6171 switches
[switchnum
].validated
= 1;
6172 switches
[switchnum
].live_cond
= SWITCH_FALSE
;
6177 case 'W': case 'f': case 'm':
6178 if (! strncmp (name
+ 1, "no-", 3))
6180 /* We have Xno-YYY, search for XYYY. */
6181 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
6182 if (switches
[i
].part1
[0] == name
[0]
6183 && ! strcmp (&switches
[i
].part1
[1], &name
[4]))
6185 switches
[switchnum
].validated
= 1;
6186 switches
[switchnum
].live_cond
= SWITCH_FALSE
;
6192 /* We have XYYY, search for Xno-YYY. */
6193 for (i
= switchnum
+ 1; i
< n_switches
; i
++)
6194 if (switches
[i
].part1
[0] == name
[0]
6195 && switches
[i
].part1
[1] == 'n'
6196 && switches
[i
].part1
[2] == 'o'
6197 && switches
[i
].part1
[3] == '-'
6198 && !strcmp (&switches
[i
].part1
[4], &name
[1]))
6200 switches
[switchnum
].validated
= 1;
6201 switches
[switchnum
].live_cond
= SWITCH_FALSE
;
6208 /* Otherwise the switch is live. */
6209 switches
[switchnum
].live_cond
|= SWITCH_LIVE
;
6213 /* Pass a switch to the current accumulating command
6214 in the same form that we received it.
6215 SWITCHNUM identifies the switch; it is an index into
6216 the vector of switches gcc received, which is `switches'.
6217 This cannot fail since it never finishes a command line.
6219 If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */
6222 give_switch (int switchnum
, int omit_first_word
)
6224 if ((switches
[switchnum
].live_cond
& SWITCH_IGNORE
) != 0)
6227 if (!omit_first_word
)
6229 do_spec_1 ("-", 0, NULL
);
6230 do_spec_1 (switches
[switchnum
].part1
, 1, NULL
);
6233 if (switches
[switchnum
].args
!= 0)
6236 for (p
= switches
[switchnum
].args
; *p
; p
++)
6238 const char *arg
= *p
;
6240 do_spec_1 (" ", 0, NULL
);
6243 unsigned length
= strlen (arg
);
6246 while (length
-- && !IS_DIR_SEPARATOR (arg
[length
]))
6247 if (arg
[length
] == '.')
6249 (CONST_CAST(char *, arg
))[length
] = 0;
6253 do_spec_1 (arg
, 1, NULL
);
6255 (CONST_CAST(char *, arg
))[length
] = '.';
6256 do_spec_1 (suffix_subst
, 1, NULL
);
6259 do_spec_1 (arg
, 1, NULL
);
6263 do_spec_1 (" ", 0, NULL
);
6264 switches
[switchnum
].validated
= 1;
6267 /* Search for a file named NAME trying various prefixes including the
6268 user's -B prefix and some standard ones.
6269 Return the absolute file name found. If nothing is found, return NAME. */
6272 find_file (const char *name
)
6274 char *newname
= find_a_file (&startfile_prefixes
, name
, R_OK
, true);
6275 return newname
? newname
: name
;
6278 /* Determine whether a directory exists. If LINKER, return 0 for
6279 certain fixed names not needed by the linker. */
6282 is_directory (const char *path1
, bool linker
)
6289 /* Ensure the string ends with "/.". The resulting path will be a
6290 directory even if the given path is a symbolic link. */
6291 len1
= strlen (path1
);
6292 path
= (char *) alloca (3 + len1
);
6293 memcpy (path
, path1
, len1
);
6295 if (!IS_DIR_SEPARATOR (cp
[-1]))
6296 *cp
++ = DIR_SEPARATOR
;
6300 /* Exclude directories that the linker is known to search. */
6302 && IS_DIR_SEPARATOR (path
[0])
6304 && strncmp (path
+ 1, "lib", 3) == 0)
6306 && strncmp (path
+ 1, "usr", 3) == 0
6307 && IS_DIR_SEPARATOR (path
[4])
6308 && strncmp (path
+ 5, "lib", 3) == 0)))
6311 return (stat (path
, &st
) >= 0 && S_ISDIR (st
.st_mode
));
6314 /* Set up the various global variables to indicate that we're processing
6315 the input file named FILENAME. */
6318 set_input (const char *filename
)
6322 gcc_input_filename
= filename
;
6323 input_filename_length
= strlen (gcc_input_filename
);
6324 input_basename
= lbasename (gcc_input_filename
);
6326 /* Find a suffix starting with the last period,
6327 and set basename_length to exclude that suffix. */
6328 basename_length
= strlen (input_basename
);
6329 suffixed_basename_length
= basename_length
;
6330 p
= input_basename
+ basename_length
;
6331 while (p
!= input_basename
&& *p
!= '.')
6333 if (*p
== '.' && p
!= input_basename
)
6335 basename_length
= p
- input_basename
;
6336 input_suffix
= p
+ 1;
6341 /* If a spec for 'g', 'u', or 'U' is seen with -save-temps then
6342 we will need to do a stat on the gcc_input_filename. The
6343 INPUT_STAT_SET signals that the stat is needed. */
6347 /* On fatal signals, delete all the temporary files. */
6350 fatal_signal (int signum
)
6352 signal (signum
, SIG_DFL
);
6353 delete_failure_queue ();
6354 delete_temp_files ();
6355 /* Get the same signal again, this time not handled,
6356 so its normal effect occurs. */
6357 kill (getpid (), signum
);
6360 /* Compare the contents of the two files named CMPFILE[0] and
6361 CMPFILE[1]. Return zero if they're identical, nonzero
6365 compare_files (char *cmpfile
[])
6368 FILE *temp
[2] = { NULL
, NULL
};
6374 void *map
[2] = { NULL
, NULL
};
6376 for (i
= 0; i
< 2; i
++)
6380 if (stat (cmpfile
[i
], &st
) < 0 || !S_ISREG (st
.st_mode
))
6382 error ("%s: could not determine length of compare-debug file %s",
6383 gcc_input_filename
, cmpfile
[i
]);
6388 length
[i
] = st
.st_size
;
6391 if (!ret
&& length
[0] != length
[1])
6393 error ("%s: -fcompare-debug failure (length)", gcc_input_filename
);
6398 for (i
= 0; i
< 2; i
++)
6400 int fd
= open (cmpfile
[i
], O_RDONLY
);
6403 error ("%s: could not open compare-debug file %s",
6404 gcc_input_filename
, cmpfile
[i
]);
6409 map
[i
] = mmap (NULL
, length
[i
], PROT_READ
, MAP_PRIVATE
, fd
, 0);
6412 if (map
[i
] == (void *) MAP_FAILED
)
6421 if (memcmp (map
[0], map
[1], length
[0]) != 0)
6423 error ("%s: -fcompare-debug failure", gcc_input_filename
);
6428 for (i
= 0; i
< 2; i
++)
6430 munmap ((caddr_t
) map
[i
], length
[i
]);
6439 for (i
= 0; i
< 2; i
++)
6441 temp
[i
] = fopen (cmpfile
[i
], "r");
6444 error ("%s: could not open compare-debug file %s",
6445 gcc_input_filename
, cmpfile
[i
]);
6451 if (!ret
&& temp
[0] && temp
[1])
6455 c0
= fgetc (temp
[0]);
6456 c1
= fgetc (temp
[1]);
6460 error ("%s: -fcompare-debug failure",
6461 gcc_input_filename
);
6470 for (i
= 1; i
>= 0; i
--)
6479 extern int main (int, char **);
6482 main (int argc
, char **argv
)
6486 int linker_was_run
= 0;
6487 int lang_n_infiles
= 0;
6488 int num_linker_inputs
= 0;
6489 char *explicit_link_files
;
6492 struct user_specs
*uptr
;
6493 char **old_argv
= argv
;
6495 /* Initialize here, not in definition. The IRIX 6 O32 cc sometimes chokes
6496 on ?: in file-scope variable initializations. */
6497 asm_debug
= ASM_DEBUG_SPEC
;
6499 p
= argv
[0] + strlen (argv
[0]);
6500 while (p
!= argv
[0] && !IS_DIR_SEPARATOR (p
[-1]))
6504 xmalloc_set_program_name (progname
);
6506 expandargv (&argc
, &argv
);
6508 /* Determine if any expansions were made. */
6509 if (argv
!= old_argv
)
6510 at_file_supplied
= true;
6512 prune_options (&argc
, &argv
);
6514 #ifdef GCC_DRIVER_HOST_INITIALIZATION
6515 /* Perform host dependent initialization when needed. */
6516 GCC_DRIVER_HOST_INITIALIZATION
;
6519 /* Unlock the stdio streams. */
6520 unlock_std_streams ();
6522 gcc_init_libintl ();
6524 diagnostic_initialize (global_dc
, 0);
6525 if (atexit (delete_temp_files
) != 0)
6526 fatal_error ("atexit failed");
6528 if (signal (SIGINT
, SIG_IGN
) != SIG_IGN
)
6529 signal (SIGINT
, fatal_signal
);
6531 if (signal (SIGHUP
, SIG_IGN
) != SIG_IGN
)
6532 signal (SIGHUP
, fatal_signal
);
6534 if (signal (SIGTERM
, SIG_IGN
) != SIG_IGN
)
6535 signal (SIGTERM
, fatal_signal
);
6537 if (signal (SIGPIPE
, SIG_IGN
) != SIG_IGN
)
6538 signal (SIGPIPE
, fatal_signal
);
6541 /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
6542 receive the signal. A different setting is inheritable */
6543 signal (SIGCHLD
, SIG_DFL
);
6546 /* Allocate the argument vector. */
6549 obstack_init (&obstack
);
6551 /* Build multilib_select, et. al from the separate lines that make up each
6552 multilib selection. */
6554 const char *const *q
= multilib_raw
;
6557 obstack_init (&multilib_obstack
);
6558 while ((p
= *q
++) != (char *) 0)
6559 obstack_grow (&multilib_obstack
, p
, strlen (p
));
6561 obstack_1grow (&multilib_obstack
, 0);
6562 multilib_select
= XOBFINISH (&multilib_obstack
, const char *);
6564 q
= multilib_matches_raw
;
6565 while ((p
= *q
++) != (char *) 0)
6566 obstack_grow (&multilib_obstack
, p
, strlen (p
));
6568 obstack_1grow (&multilib_obstack
, 0);
6569 multilib_matches
= XOBFINISH (&multilib_obstack
, const char *);
6571 q
= multilib_exclusions_raw
;
6572 while ((p
= *q
++) != (char *) 0)
6573 obstack_grow (&multilib_obstack
, p
, strlen (p
));
6575 obstack_1grow (&multilib_obstack
, 0);
6576 multilib_exclusions
= XOBFINISH (&multilib_obstack
, const char *);
6579 for (i
= 0; i
< ARRAY_SIZE (multilib_defaults_raw
); i
++)
6582 obstack_1grow (&multilib_obstack
, ' ');
6583 obstack_grow (&multilib_obstack
,
6584 multilib_defaults_raw
[i
],
6585 strlen (multilib_defaults_raw
[i
]));
6589 obstack_1grow (&multilib_obstack
, 0);
6590 multilib_defaults
= XOBFINISH (&multilib_obstack
, const char *);
6593 #ifdef INIT_ENVIRONMENT
6594 /* Set up any other necessary machine specific environment variables. */
6595 xputenv (INIT_ENVIRONMENT
);
6598 /* Make a table of what switches there are (switches, n_switches).
6599 Make a table of specified input files (infiles, n_infiles).
6600 Decode switches that are handled locally. */
6602 process_command (argc
, CONST_CAST2 (const char **, char **, argv
));
6604 /* Initialize the vector of specs to just the default.
6605 This means one element containing 0s, as a terminator. */
6607 compilers
= XNEWVAR (struct compiler
, sizeof default_compilers
);
6608 memcpy (compilers
, default_compilers
, sizeof default_compilers
);
6609 n_compilers
= n_default_compilers
;
6611 /* Read specs from a file if there is one. */
6613 machine_suffix
= concat (spec_machine
, dir_separator_str
,
6614 spec_version
, dir_separator_str
, NULL
);
6615 just_machine_suffix
= concat (spec_machine
, dir_separator_str
, NULL
);
6617 specs_file
= find_a_file (&startfile_prefixes
, "specs", R_OK
, true);
6618 /* Read the specs file unless it is a default one. */
6619 if (specs_file
!= 0 && strcmp (specs_file
, "specs"))
6620 read_specs (specs_file
, TRUE
);
6624 /* We need to check standard_exec_prefix/just_machine_suffix/specs
6625 for any override of as, ld and libraries. */
6626 specs_file
= (char *) alloca (strlen (standard_exec_prefix
)
6627 + strlen (just_machine_suffix
) + sizeof ("specs"));
6629 strcpy (specs_file
, standard_exec_prefix
);
6630 strcat (specs_file
, just_machine_suffix
);
6631 strcat (specs_file
, "specs");
6632 if (access (specs_file
, R_OK
) == 0)
6633 read_specs (specs_file
, TRUE
);
6635 /* Process any configure-time defaults specified for the command line
6636 options, via OPTION_DEFAULT_SPECS. */
6637 for (i
= 0; i
< ARRAY_SIZE (option_default_specs
); i
++)
6638 do_option_spec (option_default_specs
[i
].name
,
6639 option_default_specs
[i
].spec
);
6641 /* Process DRIVER_SELF_SPECS, adding any new options to the end
6642 of the command line. */
6644 for (i
= 0; i
< ARRAY_SIZE (driver_self_specs
); i
++)
6645 do_self_spec (driver_self_specs
[i
]);
6649 enum save_temps save
;
6651 if (!compare_debug_second
)
6653 n_switches_debug_check
[1] = n_switches
;
6654 switches_debug_check
[1] = XDUPVEC (struct switchstr
, switches
,
6657 do_self_spec ("%:compare-debug-self-opt()");
6658 n_switches_debug_check
[0] = n_switches
;
6659 switches_debug_check
[0] = switches
;
6661 n_switches
= n_switches_debug_check
[1];
6662 switches
= switches_debug_check
[1];
6665 /* Avoid crash when computing %j in this early. */
6666 save
= save_temps_flag
;
6667 save_temps_flag
= SAVE_TEMPS_NONE
;
6669 compare_debug
= -compare_debug
;
6670 do_self_spec ("%:compare-debug-self-opt()");
6672 save_temps_flag
= save
;
6674 if (!compare_debug_second
)
6676 n_switches_debug_check
[1] = n_switches
;
6677 switches_debug_check
[1] = switches
;
6678 compare_debug
= -compare_debug
;
6679 n_switches
= n_switches_debug_check
[0];
6680 switches
= switches_debug_check
[0];
6684 /* If not cross-compiling, look for executables in the standard
6686 if (*cross_compile
== '0')
6688 if (*md_exec_prefix
)
6690 add_prefix (&exec_prefixes
, md_exec_prefix
, "GCC",
6691 PREFIX_PRIORITY_LAST
, 0, 0);
6695 /* Process sysroot_suffix_spec. */
6696 if (*sysroot_suffix_spec
!= 0
6697 && do_spec_2 (sysroot_suffix_spec
) == 0)
6699 if (argbuf_index
> 1)
6700 error ("spec failure: more than one arg to SYSROOT_SUFFIX_SPEC");
6701 else if (argbuf_index
== 1)
6702 target_sysroot_suffix
= xstrdup (argbuf
[argbuf_index
-1]);
6705 #ifdef HAVE_LD_SYSROOT
6706 /* Pass the --sysroot option to the linker, if it supports that. If
6707 there is a sysroot_suffix_spec, it has already been processed by
6708 this point, so target_system_root really is the system root we
6710 if (target_system_root
)
6712 obstack_grow (&obstack
, "%(sysroot_spec) ", strlen ("%(sysroot_spec) "));
6713 obstack_grow0 (&obstack
, link_spec
, strlen (link_spec
));
6714 set_spec ("link", XOBFINISH (&obstack
, const char *));
6718 /* Process sysroot_hdrs_suffix_spec. */
6719 if (*sysroot_hdrs_suffix_spec
!= 0
6720 && do_spec_2 (sysroot_hdrs_suffix_spec
) == 0)
6722 if (argbuf_index
> 1)
6723 error ("spec failure: more than one arg to SYSROOT_HEADERS_SUFFIX_SPEC");
6724 else if (argbuf_index
== 1)
6725 target_sysroot_hdrs_suffix
= xstrdup (argbuf
[argbuf_index
-1]);
6728 /* Look for startfiles in the standard places. */
6729 if (*startfile_prefix_spec
!= 0
6730 && do_spec_2 (startfile_prefix_spec
) == 0
6731 && do_spec_1 (" ", 0, NULL
) == 0)
6734 for (ndx
= 0; ndx
< argbuf_index
; ndx
++)
6735 add_sysrooted_prefix (&startfile_prefixes
, argbuf
[ndx
], "BINUTILS",
6736 PREFIX_PRIORITY_LAST
, 0, 1);
6738 /* We should eventually get rid of all these and stick to
6739 startfile_prefix_spec exclusively. */
6740 else if (*cross_compile
== '0' || target_system_root
)
6742 if (*md_startfile_prefix
)
6743 add_sysrooted_prefix (&startfile_prefixes
, md_startfile_prefix
,
6744 "GCC", PREFIX_PRIORITY_LAST
, 0, 1);
6746 if (*md_startfile_prefix_1
)
6747 add_sysrooted_prefix (&startfile_prefixes
, md_startfile_prefix_1
,
6748 "GCC", PREFIX_PRIORITY_LAST
, 0, 1);
6750 /* If standard_startfile_prefix is relative, base it on
6751 standard_exec_prefix. This lets us move the installed tree
6752 as a unit. If GCC_EXEC_PREFIX is defined, base
6753 standard_startfile_prefix on that as well.
6755 If the prefix is relative, only search it for native compilers;
6756 otherwise we will search a directory containing host libraries. */
6757 if (IS_ABSOLUTE_PATH (standard_startfile_prefix
))
6758 add_sysrooted_prefix (&startfile_prefixes
,
6759 standard_startfile_prefix
, "BINUTILS",
6760 PREFIX_PRIORITY_LAST
, 0, 1);
6761 else if (*cross_compile
== '0')
6763 add_prefix (&startfile_prefixes
,
6764 concat (gcc_exec_prefix
6765 ? gcc_exec_prefix
: standard_exec_prefix
,
6767 standard_startfile_prefix
, NULL
),
6768 NULL
, PREFIX_PRIORITY_LAST
, 0, 1);
6771 /* Sysrooted prefixes are relocated because target_system_root is
6772 also relocated by gcc_exec_prefix. */
6773 if (*standard_startfile_prefix_1
)
6774 add_sysrooted_prefix (&startfile_prefixes
,
6775 standard_startfile_prefix_1
, "BINUTILS",
6776 PREFIX_PRIORITY_LAST
, 0, 1);
6777 if (*standard_startfile_prefix_2
)
6778 add_sysrooted_prefix (&startfile_prefixes
,
6779 standard_startfile_prefix_2
, "BINUTILS",
6780 PREFIX_PRIORITY_LAST
, 0, 1);
6783 /* Process any user specified specs in the order given on the command
6785 for (uptr
= user_specs_head
; uptr
; uptr
= uptr
->next
)
6787 char *filename
= find_a_file (&startfile_prefixes
, uptr
->filename
,
6789 read_specs (filename
? filename
: uptr
->filename
, FALSE
);
6792 /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
6793 if (gcc_exec_prefix
)
6794 gcc_exec_prefix
= concat (gcc_exec_prefix
, spec_machine
, dir_separator_str
,
6795 spec_version
, dir_separator_str
, NULL
);
6797 /* Now we have the specs.
6798 Set the `valid' bits for switches that match anything in any spec. */
6800 validate_all_switches ();
6802 /* Now that we have the switches and the specs, set
6803 the subdirectory based on the options. */
6804 set_multilib_dir ();
6806 /* Set up to remember the pathname of gcc and any options
6807 needed for collect. We use argv[0] instead of progname because
6808 we need the complete pathname. */
6809 obstack_init (&collect_obstack
);
6810 obstack_grow (&collect_obstack
, "COLLECT_GCC=", sizeof ("COLLECT_GCC=") - 1);
6811 obstack_grow (&collect_obstack
, argv
[0], strlen (argv
[0]) + 1);
6812 xputenv (XOBFINISH (&collect_obstack
, char *));
6814 /* Set up to remember the pathname of the lto wrapper. */
6816 lto_wrapper_spec
= find_a_file (&exec_prefixes
, "lto-wrapper", X_OK
, false);
6817 if (lto_wrapper_spec
)
6819 obstack_init (&collect_obstack
);
6820 obstack_grow (&collect_obstack
, "COLLECT_LTO_WRAPPER=",
6821 sizeof ("COLLECT_LTO_WRAPPER=") - 1);
6822 obstack_grow (&collect_obstack
, lto_wrapper_spec
,
6823 strlen (lto_wrapper_spec
) + 1);
6824 xputenv (XOBFINISH (&collect_obstack
, char *));
6827 /* Warn about any switches that no pass was interested in. */
6829 for (i
= 0; (int) i
< n_switches
; i
++)
6830 if (! switches
[i
].validated
)
6831 error ("unrecognized option %<-%s%>", switches
[i
].part1
);
6833 /* Obey some of the options. */
6835 if (print_search_dirs
)
6837 printf (_("install: %s%s\n"),
6838 gcc_exec_prefix
? gcc_exec_prefix
: standard_exec_prefix
,
6839 gcc_exec_prefix
? "" : machine_suffix
);
6840 printf (_("programs: %s\n"),
6841 build_search_list (&exec_prefixes
, "", false, false));
6842 printf (_("libraries: %s\n"),
6843 build_search_list (&startfile_prefixes
, "", false, true));
6847 if (print_file_name
)
6849 printf ("%s\n", find_file (print_file_name
));
6853 if (print_prog_name
)
6855 char *newname
= find_a_file (&exec_prefixes
, print_prog_name
, X_OK
, 0);
6856 printf ("%s\n", (newname
? newname
: print_prog_name
));
6860 if (print_multi_lib
)
6862 print_multilib_info ();
6866 if (print_multi_directory
)
6868 if (multilib_dir
== NULL
)
6871 printf ("%s\n", multilib_dir
);
6877 if (target_system_root
)
6879 if (target_sysroot_suffix
)
6880 printf ("%s%s\n", target_system_root
, target_sysroot_suffix
);
6882 printf ("%s\n", target_system_root
);
6887 if (print_multi_os_directory
)
6889 if (multilib_os_dir
== NULL
)
6892 printf ("%s\n", multilib_os_dir
);
6896 if (print_sysroot_headers_suffix
)
6898 if (*sysroot_hdrs_suffix_spec
)
6900 printf("%s\n", (target_sysroot_hdrs_suffix
6901 ? target_sysroot_hdrs_suffix
6906 /* The error status indicates that only one set of fixed
6907 headers should be built. */
6908 fatal_error ("not configured with sysroot headers suffix");
6911 if (print_help_list
)
6917 printf (_("\nFor bug reporting instructions, please see:\n"));
6918 printf ("%s.\n", bug_report_url
);
6923 /* We do not exit here. Instead we have created a fake input file
6924 called 'help-dummy' which needs to be compiled, and we pass this
6925 on the various sub-processes, along with the --help switch.
6926 Ensure their output appears after ours. */
6927 fputc ('\n', stdout
);
6933 printf (_("%s %s%s\n"), progname
, pkgversion_string
,
6935 printf ("Copyright %s 2010 Free Software Foundation, Inc.\n",
6937 fputs (_("This is free software; see the source for copying conditions. There is NO\n\
6938 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"),
6943 /* We do not exit here. We use the same mechanism of --help to print
6944 the version of the sub-processes. */
6945 fputc ('\n', stdout
);
6954 fnotice (stderr
, "Target: %s\n", spec_machine
);
6955 fnotice (stderr
, "Configured with: %s\n", configuration_arguments
);
6957 #ifdef THREAD_MODEL_SPEC
6958 /* We could have defined THREAD_MODEL_SPEC to "%*" by default,
6959 but there's no point in doing all this processing just to get
6960 thread_model back. */
6961 obstack_init (&obstack
);
6962 do_spec_1 (THREAD_MODEL_SPEC
, 0, thread_model
);
6963 obstack_1grow (&obstack
, '\0');
6964 thrmod
= XOBFINISH (&obstack
, const char *);
6966 thrmod
= thread_model
;
6969 fnotice (stderr
, "Thread model: %s\n", thrmod
);
6971 /* compiler_version is truncated at the first space when initialized
6972 from version string, so truncate version_string at the first space
6973 before comparing. */
6974 for (n
= 0; version_string
[n
]; n
++)
6975 if (version_string
[n
] == ' ')
6978 if (! strncmp (version_string
, compiler_version
, n
)
6979 && compiler_version
[n
] == 0)
6980 fnotice (stderr
, "gcc version %s %s\n", version_string
,
6983 fnotice (stderr
, "gcc driver version %s %sexecuting gcc version %s\n",
6984 version_string
, pkgversion_string
, compiler_version
);
6990 if (n_infiles
== added_libraries
)
6991 fatal_error ("no input files");
6993 /* Make a place to record the compiler output file names
6994 that correspond to the input files. */
6997 i
+= lang_specific_extra_outfiles
;
6998 outfiles
= XCNEWVEC (const char *, i
);
7000 /* Record which files were specified explicitly as link input. */
7002 explicit_link_files
= XCNEWVEC (char, n_infiles
);
7005 combine_inputs
= true;
7007 combine_inputs
= false;
7009 for (i
= 0; (int) i
< n_infiles
; i
++)
7011 const char *name
= infiles
[i
].name
;
7012 struct compiler
*compiler
= lookup_compiler (name
,
7014 infiles
[i
].language
);
7016 if (compiler
&& !(compiler
->combinable
))
7017 combine_inputs
= false;
7019 if (lang_n_infiles
> 0 && compiler
!= input_file_compiler
7020 && infiles
[i
].language
&& infiles
[i
].language
[0] != '*')
7021 infiles
[i
].incompiler
= compiler
;
7025 input_file_compiler
= compiler
;
7026 infiles
[i
].incompiler
= compiler
;
7030 /* Since there is no compiler for this input file, assume it is a
7032 explicit_link_files
[i
] = 1;
7033 infiles
[i
].incompiler
= NULL
;
7035 infiles
[i
].compiled
= false;
7036 infiles
[i
].preprocessed
= false;
7039 if (!combine_inputs
&& have_c
&& have_o
&& lang_n_infiles
> 1)
7040 fatal_error ("cannot specify -o with -c, -S or -E with multiple files");
7042 if (combine_flag
&& save_temps_flag
)
7044 bool save_combine_inputs
= combine_inputs
;
7045 /* Must do a separate pre-processing pass for C & Objective-C files, to
7046 obtain individual .i files. */
7048 combine_inputs
= false;
7049 for (i
= 0; (int) i
< n_infiles
; i
++)
7051 int this_file_error
= 0;
7053 input_file_number
= i
;
7054 set_input (infiles
[i
].name
);
7055 if (infiles
[i
].incompiler
7056 && (infiles
[i
].incompiler
)->needs_preprocessing
)
7057 input_file_compiler
= infiles
[i
].incompiler
;
7061 if (input_file_compiler
)
7063 if (input_file_compiler
->spec
[0] == '#')
7065 error ("%s: %s compiler not installed on this system",
7066 gcc_input_filename
, &input_file_compiler
->spec
[1]);
7067 this_file_error
= 1;
7071 value
= do_spec (input_file_compiler
->spec
);
7072 infiles
[i
].preprocessed
= true;
7073 if (!have_o_argbuf_index
)
7074 fatal_error ("spec %qs is invalid",
7075 input_file_compiler
->spec
);
7076 infiles
[i
].name
= argbuf
[have_o_argbuf_index
];
7077 infiles
[i
].incompiler
7078 = lookup_compiler (infiles
[i
].name
,
7079 strlen (infiles
[i
].name
),
7080 infiles
[i
].language
);
7083 this_file_error
= 1;
7087 if (this_file_error
)
7089 delete_failure_queue ();
7093 clear_failure_queue ();
7095 combine_inputs
= save_combine_inputs
;
7098 for (i
= 0; (int) i
< n_infiles
; i
++)
7100 int this_file_error
= 0;
7102 /* Tell do_spec what to substitute for %i. */
7104 input_file_number
= i
;
7105 set_input (infiles
[i
].name
);
7107 if (infiles
[i
].compiled
)
7110 /* Use the same thing in %o, unless cp->spec says otherwise. */
7112 outfiles
[i
] = gcc_input_filename
;
7114 /* Figure out which compiler from the file's suffix. */
7116 if (! combine_inputs
)
7118 = lookup_compiler (infiles
[i
].name
, input_filename_length
,
7119 infiles
[i
].language
);
7121 input_file_compiler
= infiles
[i
].incompiler
;
7123 if (input_file_compiler
)
7125 /* Ok, we found an applicable compiler. Run its spec. */
7127 if (input_file_compiler
->spec
[0] == '#')
7129 error ("%s: %s compiler not installed on this system",
7130 gcc_input_filename
, &input_file_compiler
->spec
[1]);
7131 this_file_error
= 1;
7137 if (debug_check_temp_file
[0])
7138 free (debug_check_temp_file
[0]);
7139 debug_check_temp_file
[0] = NULL
;
7141 if (debug_check_temp_file
[1])
7142 free (debug_check_temp_file
[1]);
7143 debug_check_temp_file
[1] = NULL
;
7146 value
= do_spec (input_file_compiler
->spec
);
7147 infiles
[i
].compiled
= true;
7149 this_file_error
= 1;
7150 else if (compare_debug
&& debug_check_temp_file
[0])
7153 inform (0, "recompiling with -fcompare-debug");
7155 compare_debug
= -compare_debug
;
7156 n_switches
= n_switches_debug_check
[1];
7157 switches
= switches_debug_check
[1];
7159 value
= do_spec (input_file_compiler
->spec
);
7161 compare_debug
= -compare_debug
;
7162 n_switches
= n_switches_debug_check
[0];
7163 switches
= switches_debug_check
[0];
7167 error ("during -fcompare-debug recompilation");
7168 this_file_error
= 1;
7171 gcc_assert (debug_check_temp_file
[1]
7172 && strcmp (debug_check_temp_file
[0],
7173 debug_check_temp_file
[1]));
7176 inform (0, "comparing final insns dumps");
7178 if (compare_files (debug_check_temp_file
))
7179 this_file_error
= 1;
7184 if (debug_check_temp_file
[0])
7185 free (debug_check_temp_file
[0]);
7186 debug_check_temp_file
[0] = NULL
;
7188 if (debug_check_temp_file
[1])
7189 free (debug_check_temp_file
[1]);
7190 debug_check_temp_file
[1] = NULL
;
7195 /* If this file's name does not contain a recognized suffix,
7196 record it as explicit linker input. */
7199 explicit_link_files
[i
] = 1;
7201 /* Clear the delete-on-failure queue, deleting the files in it
7202 if this compilation failed. */
7204 if (this_file_error
)
7206 delete_failure_queue ();
7209 /* If this compilation succeeded, don't delete those files later. */
7210 clear_failure_queue ();
7213 /* Reset the input file name to the first compile/object file name, for use
7214 with %b in LINK_SPEC. We use the first input file that we can find
7215 a compiler to compile it instead of using infiles.language since for
7216 languages other than C we use aliases that we then lookup later. */
7221 for (i
= 0; i
< n_infiles
; i
++)
7222 if (infiles
[i
].language
&& infiles
[i
].language
[0] != '*')
7224 set_input (infiles
[i
].name
);
7231 /* Make sure INPUT_FILE_NUMBER points to first available open
7233 input_file_number
= n_infiles
;
7234 if (lang_specific_pre_link ())
7238 /* Determine if there are any linker input files. */
7239 num_linker_inputs
= 0;
7240 for (i
= 0; (int) i
< n_infiles
; i
++)
7241 if (explicit_link_files
[i
] || outfiles
[i
] != NULL
)
7242 num_linker_inputs
++;
7244 /* Run ld to link all the compiler output files. */
7246 if (num_linker_inputs
> 0 && !seen_error () && print_subprocess_help
< 2)
7248 int tmp
= execution_count
;
7249 const char *fuse_linker_plugin
= "fuse-linker-plugin";
7251 /* We'll use ld if we can't find collect2. */
7252 if (! strcmp (linker_name_spec
, "collect2"))
7254 char *s
= find_a_file (&exec_prefixes
, "collect2", X_OK
, false);
7256 linker_name_spec
= "ld";
7259 if (switch_matches (fuse_linker_plugin
,
7260 fuse_linker_plugin
+ strlen (fuse_linker_plugin
), 0))
7262 linker_plugin_file_spec
= find_a_file (&exec_prefixes
,
7263 "liblto_plugin.so", R_OK
,
7265 if (!linker_plugin_file_spec
)
7266 fatal_error ("-fuse-linker-plugin, but liblto_plugin.so not found");
7268 lto_libgcc_spec
= find_a_file (&startfile_prefixes
, "libgcc.a",
7270 if (!lto_libgcc_spec
)
7271 fatal_error ("could not find libgcc.a");
7273 lto_gcc_spec
= argv
[0];
7275 /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
7277 putenv_from_prefixes (&exec_prefixes
, "COMPILER_PATH", false);
7278 putenv_from_prefixes (&startfile_prefixes
, LIBRARY_PATH_ENV
, true);
7280 if (print_subprocess_help
== 1)
7282 printf (_("\nLinker options\n==============\n\n"));
7283 printf (_("Use \"-Wl,OPTION\" to pass \"OPTION\""
7284 " to the linker.\n\n"));
7287 value
= do_spec (link_command_spec
);
7290 linker_was_run
= (tmp
!= execution_count
);
7293 /* If options said don't run linker,
7294 complain about input files to be given to the linker. */
7296 if (! linker_was_run
&& !seen_error ())
7297 for (i
= 0; (int) i
< n_infiles
; i
++)
7298 if (explicit_link_files
[i
]
7299 && !(infiles
[i
].language
&& infiles
[i
].language
[0] == '*'))
7300 warning (0, "%s: linker input file unused because linking not done",
7303 /* Delete some or all of the temporary files we made. */
7306 delete_failure_queue ();
7307 delete_temp_files ();
7309 if (print_help_list
)
7311 printf (("\nFor bug reporting instructions, please see:\n"));
7312 printf ("%s\n", bug_report_url
);
7315 return (signal_count
!= 0 ? 2
7316 : seen_error () ? (pass_exit_codes
? greatest_status
: 1)
7320 /* Find the proper compilation spec for the file name NAME,
7321 whose length is LENGTH. LANGUAGE is the specified language,
7322 or 0 if this file is to be passed to the linker. */
7324 static struct compiler
*
7325 lookup_compiler (const char *name
, size_t length
, const char *language
)
7327 struct compiler
*cp
;
7329 /* If this was specified by the user to be a linker input, indicate that. */
7330 if (language
!= 0 && language
[0] == '*')
7333 /* Otherwise, look for the language, if one is spec'd. */
7336 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
7337 if (cp
->suffix
[0] == '@' && !strcmp (cp
->suffix
+ 1, language
))
7340 error ("language %s not recognized", language
);
7344 /* Look for a suffix. */
7345 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
7347 if (/* The suffix `-' matches only the file name `-'. */
7348 (!strcmp (cp
->suffix
, "-") && !strcmp (name
, "-"))
7349 || (strlen (cp
->suffix
) < length
7350 /* See if the suffix matches the end of NAME. */
7351 && !strcmp (cp
->suffix
,
7352 name
+ length
- strlen (cp
->suffix
))
7357 #if defined (OS2) ||defined (HAVE_DOS_BASED_FILE_SYSTEM)
7358 /* Look again, but case-insensitively this time. */
7360 for (cp
= compilers
+ n_compilers
- 1; cp
>= compilers
; cp
--)
7362 if (/* The suffix `-' matches only the file name `-'. */
7363 (!strcmp (cp
->suffix
, "-") && !strcmp (name
, "-"))
7364 || (strlen (cp
->suffix
) < length
7365 /* See if the suffix matches the end of NAME. */
7366 && ((!strcmp (cp
->suffix
,
7367 name
+ length
- strlen (cp
->suffix
))
7368 || !strpbrk (cp
->suffix
, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
7369 && !strcasecmp (cp
->suffix
,
7370 name
+ length
- strlen (cp
->suffix
)))
7376 if (cp
>= compilers
)
7378 if (cp
->spec
[0] != '@')
7379 /* A non-alias entry: return it. */
7382 /* An alias entry maps a suffix to a language.
7383 Search for the language; pass 0 for NAME and LENGTH
7384 to avoid infinite recursion if language not found. */
7385 return lookup_compiler (NULL
, 0, cp
->spec
+ 1);
7391 save_string (const char *s
, int len
)
7393 char *result
= XNEWVEC (char, len
+ 1);
7395 memcpy (result
, s
, len
);
7401 pfatal_with_name (const char *name
)
7403 perror_with_name (name
);
7404 delete_temp_files ();
7409 perror_with_name (const char *name
)
7411 error ("%s: %m", name
);
7415 validate_switches_from_spec (const char *spec
)
7417 const char *p
= spec
;
7420 if (c
== '%' && (*p
== '{' || *p
== '<' || (*p
== 'W' && *++p
== '{')))
7421 /* We have a switch spec. */
7422 p
= validate_switches (p
+ 1);
7426 validate_all_switches (void)
7428 struct compiler
*comp
;
7429 struct spec_list
*spec
;
7431 for (comp
= compilers
; comp
->spec
; comp
++)
7432 validate_switches_from_spec (comp
->spec
);
7434 /* Look through the linked list of specs read from the specs file. */
7435 for (spec
= specs
; spec
; spec
= spec
->next
)
7436 validate_switches_from_spec (*spec
->ptr_spec
);
7438 validate_switches_from_spec (link_command_spec
);
7441 /* Look at the switch-name that comes after START
7442 and mark as valid all supplied switches that match it. */
7445 validate_switches (const char *start
)
7447 const char *p
= start
;
7451 bool suffix
= false;
7452 bool starred
= false;
7454 #define SKIP_WHITE() do { while (*p == ' ' || *p == '\t') p++; } while (0)
7463 if (*p
== '.' || *p
== ',')
7467 while (ISIDNUM (*p
) || *p
== '-' || *p
== '+' || *p
== '='
7468 || *p
== ',' || *p
== '.' || *p
== '@')
7473 starred
= true, p
++;
7479 /* Mark all matching switches as valid. */
7480 for (i
= 0; i
< n_switches
; i
++)
7481 if (!strncmp (switches
[i
].part1
, atom
, len
)
7482 && (starred
|| switches
[i
].part1
[len
] == 0))
7483 switches
[i
].validated
= 1;
7487 if (*p
&& (p
[-1] == '|' || p
[-1] == '&'))
7490 if (*p
&& p
[-1] == ':')
7492 while (*p
&& *p
!= ';' && *p
!= '}')
7497 if (*p
== '{' || *p
== '<')
7498 p
= validate_switches (p
+1);
7499 else if (p
[0] == 'W' && p
[1] == '{')
7500 p
= validate_switches (p
+2);
7507 if (*p
&& p
[-1] == ';')
7521 static struct mdswitchstr
*mdswitches
;
7522 static int n_mdswitches
;
7524 /* Check whether a particular argument was used. The first time we
7525 canonicalize the switches to keep only the ones we care about. */
7528 used_arg (const char *p
, int len
)
7533 const char *replace
;
7538 static struct mswitchstr
*mswitches
;
7539 static int n_mswitches
;
7544 struct mswitchstr
*matches
;
7548 /* Break multilib_matches into the component strings of string
7549 and replacement string. */
7550 for (q
= multilib_matches
; *q
!= '\0'; q
++)
7555 = (struct mswitchstr
*) alloca ((sizeof (struct mswitchstr
)) * cnt
);
7557 q
= multilib_matches
;
7566 fatal_error ("multilib spec %qs is invalid",
7571 matches
[i
].len
= q
- matches
[i
].str
;
7573 matches
[i
].replace
= ++q
;
7574 while (*q
!= ';' && *q
!= '\0')
7577 goto invalid_matches
;
7580 matches
[i
].rep_len
= q
- matches
[i
].replace
;
7586 /* Now build a list of the replacement string for switches that we care
7587 about. Make sure we allocate at least one entry. This prevents
7588 xmalloc from calling fatal, and prevents us from re-executing this
7591 = XNEWVEC (struct mswitchstr
, n_mdswitches
+ (n_switches
? n_switches
: 1));
7592 for (i
= 0; i
< n_switches
; i
++)
7593 if ((switches
[i
].live_cond
& SWITCH_IGNORE
) == 0)
7595 int xlen
= strlen (switches
[i
].part1
);
7596 for (j
= 0; j
< cnt
; j
++)
7597 if (xlen
== matches
[j
].len
7598 && ! strncmp (switches
[i
].part1
, matches
[j
].str
, xlen
))
7600 mswitches
[n_mswitches
].str
= matches
[j
].replace
;
7601 mswitches
[n_mswitches
].len
= matches
[j
].rep_len
;
7602 mswitches
[n_mswitches
].replace
= (char *) 0;
7603 mswitches
[n_mswitches
].rep_len
= 0;
7609 /* Add MULTILIB_DEFAULTS switches too, as long as they were not present
7610 on the command line nor any options mutually incompatible with
7612 for (i
= 0; i
< n_mdswitches
; i
++)
7616 for (q
= multilib_options
; *q
!= '\0'; q
++)
7622 while (strncmp (q
, mdswitches
[i
].str
, mdswitches
[i
].len
) != 0
7623 || strchr (" /", q
[mdswitches
[i
].len
]) == NULL
)
7625 while (*q
!= ' ' && *q
!= '/' && *q
!= '\0')
7632 if (*q
!= ' ' && *q
!= '\0')
7634 while (*r
!= ' ' && *r
!= '\0')
7637 while (*q
!= ' ' && *q
!= '/' && *q
!= '\0')
7640 if (used_arg (r
, q
- r
))
7645 mswitches
[n_mswitches
].str
= mdswitches
[i
].str
;
7646 mswitches
[n_mswitches
].len
= mdswitches
[i
].len
;
7647 mswitches
[n_mswitches
].replace
= (char *) 0;
7648 mswitches
[n_mswitches
].rep_len
= 0;
7661 for (i
= 0; i
< n_mswitches
; i
++)
7662 if (len
== mswitches
[i
].len
&& ! strncmp (p
, mswitches
[i
].str
, len
))
7669 default_arg (const char *p
, int len
)
7673 for (i
= 0; i
< n_mdswitches
; i
++)
7674 if (len
== mdswitches
[i
].len
&& ! strncmp (p
, mdswitches
[i
].str
, len
))
7680 /* Work out the subdirectory to use based on the options. The format of
7681 multilib_select is a list of elements. Each element is a subdirectory
7682 name followed by a list of options followed by a semicolon. The format
7683 of multilib_exclusions is the same, but without the preceding
7684 directory. First gcc will check the exclusions, if none of the options
7685 beginning with an exclamation point are present, and all of the other
7686 options are present, then we will ignore this completely. Passing
7687 that, gcc will consider each multilib_select in turn using the same
7688 rules for matching the options. If a match is found, that subdirectory
7692 set_multilib_dir (void)
7695 unsigned int this_path_len
;
7696 const char *this_path
, *this_arg
;
7697 const char *start
, *end
;
7699 int ok
, ndfltok
, first
;
7702 start
= multilib_defaults
;
7703 while (*start
== ' ' || *start
== '\t')
7705 while (*start
!= '\0')
7708 while (*start
!= ' ' && *start
!= '\t' && *start
!= '\0')
7710 while (*start
== ' ' || *start
== '\t')
7718 mdswitches
= XNEWVEC (struct mdswitchstr
, n_mdswitches
);
7719 for (start
= multilib_defaults
; *start
!= '\0'; start
= end
+ 1)
7721 while (*start
== ' ' || *start
== '\t')
7727 for (end
= start
+ 1;
7728 *end
!= ' ' && *end
!= '\t' && *end
!= '\0'; end
++)
7731 obstack_grow (&multilib_obstack
, start
, end
- start
);
7732 obstack_1grow (&multilib_obstack
, 0);
7733 mdswitches
[i
].str
= XOBFINISH (&multilib_obstack
, const char *);
7734 mdswitches
[i
++].len
= end
- start
;
7741 p
= multilib_exclusions
;
7744 /* Ignore newlines. */
7751 /* Check the arguments. */
7758 fatal_error ("multilib exclusions %qs is invalid",
7759 multilib_exclusions
);
7769 while (*p
!= ' ' && *p
!= ';')
7772 goto invalid_exclusions
;
7776 if (*this_arg
!= '!')
7784 ok
= used_arg (this_arg
, p
- this_arg
);
7799 p
= multilib_select
;
7802 /* Ignore newlines. */
7809 /* Get the initial path. */
7816 fatal_error ("multilib select %qs is invalid",
7821 this_path_len
= p
- this_path
;
7823 /* Check the arguments. */
7830 goto invalid_select
;
7839 while (*p
!= ' ' && *p
!= ';')
7842 goto invalid_select
;
7846 if (*this_arg
!= '!')
7854 /* If this is a default argument, we can just ignore it.
7855 This is true even if this_arg begins with '!'. Beginning
7856 with '!' does not mean that this argument is necessarily
7857 inappropriate for this library: it merely means that
7858 there is a more specific library which uses this
7859 argument. If this argument is a default, we need not
7860 consider that more specific library. */
7861 ok
= used_arg (this_arg
, p
- this_arg
);
7868 if (default_arg (this_arg
, p
- this_arg
))
7877 if (this_path_len
!= 1
7878 || this_path
[0] != '.')
7880 char *new_multilib_dir
= XNEWVEC (char, this_path_len
+ 1);
7883 strncpy (new_multilib_dir
, this_path
, this_path_len
);
7884 new_multilib_dir
[this_path_len
] = '\0';
7885 q
= strchr (new_multilib_dir
, ':');
7888 multilib_dir
= new_multilib_dir
;
7895 const char *q
= this_path
, *end
= this_path
+ this_path_len
;
7897 while (q
< end
&& *q
!= ':')
7901 char *new_multilib_os_dir
= XNEWVEC (char, end
- q
);
7902 memcpy (new_multilib_os_dir
, q
+ 1, end
- q
- 1);
7903 new_multilib_os_dir
[end
- q
- 1] = '\0';
7904 multilib_os_dir
= new_multilib_os_dir
;
7912 if (multilib_dir
== NULL
&& multilib_os_dir
!= NULL
7913 && strcmp (multilib_os_dir
, ".") == 0)
7915 free (CONST_CAST (char *, multilib_os_dir
));
7916 multilib_os_dir
= NULL
;
7918 else if (multilib_dir
!= NULL
&& multilib_os_dir
== NULL
)
7919 multilib_os_dir
= multilib_dir
;
7922 /* Print out the multiple library subdirectory selection
7923 information. This prints out a series of lines. Each line looks
7924 like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
7925 required. Only the desired options are printed out, the negative
7926 matches. The options are print without a leading dash. There are
7927 no spaces to make it easy to use the information in the shell.
7928 Each subdirectory is printed only once. This assumes the ordering
7929 generated by the genmultilib script. Also, we leave out ones that match
7933 print_multilib_info (void)
7935 const char *p
= multilib_select
;
7936 const char *last_path
= 0, *this_path
;
7938 unsigned int last_path_len
= 0;
7943 /* Ignore newlines. */
7950 /* Get the initial path. */
7957 fatal_error ("multilib select %qs is invalid", multilib_select
);
7963 /* When --disable-multilib was used but target defines
7964 MULTILIB_OSDIRNAMES, entries starting with .: are there just
7965 to find multilib_os_dir, so skip them from output. */
7966 if (this_path
[0] == '.' && this_path
[1] == ':')
7969 /* Check for matches with the multilib_exclusions. We don't bother
7970 with the '!' in either list. If any of the exclusion rules match
7971 all of its options with the select rule, we skip it. */
7973 const char *e
= multilib_exclusions
;
7974 const char *this_arg
;
7979 /* Ignore newlines. */
7986 /* Check the arguments. */
7995 fatal_error ("multilib exclusion %qs is invalid",
7996 multilib_exclusions
);
8007 while (*e
!= ' ' && *e
!= ';')
8010 goto invalid_exclusion
;
8018 int len
= e
- this_arg
;
8021 goto invalid_select
;
8025 while (*q
!= ' ' && *q
!= ';')
8028 goto invalid_select
;
8032 if (! strncmp (arg
, this_arg
,
8033 (len
< q
- arg
) ? q
- arg
: len
)
8034 || default_arg (this_arg
, e
- this_arg
))
8064 /* If this is a duplicate, skip it. */
8065 skip
= (last_path
!= 0
8066 && (unsigned int) (p
- this_path
) == last_path_len
8067 && ! strncmp (last_path
, this_path
, last_path_len
));
8069 last_path
= this_path
;
8070 last_path_len
= p
- this_path
;
8073 /* If this directory requires any default arguments, we can skip
8074 it. We will already have printed a directory identical to
8075 this one which does not require that default argument. */
8086 goto invalid_select
;
8093 while (*q
!= ' ' && *q
!= ';')
8096 goto invalid_select
;
8101 && default_arg (arg
, q
- arg
))
8116 for (p1
= last_path
; p1
< p
&& *p1
!= ':'; p1
++)
8127 goto invalid_select
;
8135 use_arg
= *p
!= '!';
8140 while (*p
!= ' ' && *p
!= ';')
8143 goto invalid_select
;
8155 /* If there are extra options, print them now. */
8156 if (multilib_extra
&& *multilib_extra
)
8158 int print_at
= TRUE
;
8161 for (q
= multilib_extra
; *q
!= '\0'; q
++)
8182 /* getenv built-in spec function.
8184 Returns the value of the environment variable given by its first
8185 argument, concatenated with the second argument. If the
8186 environment variable is not defined, a fatal error is issued. */
8189 getenv_spec_function (int argc
, const char **argv
)
8199 value
= getenv (argv
[0]);
8201 fatal_error ("environment variable %qs not defined", argv
[0]);
8203 /* We have to escape every character of the environment variable so
8204 they are not interpreted as active spec characters. A
8205 particularly painful case is when we are reading a variable
8206 holding a windows path complete with \ separators. */
8207 len
= strlen (value
) * 2 + strlen (argv
[1]) + 1;
8208 result
= XNEWVAR (char, len
);
8209 for (ptr
= result
; *value
; ptr
+= 2)
8215 strcpy (ptr
, argv
[1]);
8220 /* if-exists built-in spec function.
8222 Checks to see if the file specified by the absolute pathname in
8223 ARGS exists. Returns that pathname if found.
8225 The usual use for this function is to check for a library file
8226 (whose name has been expanded with %s). */
8229 if_exists_spec_function (int argc
, const char **argv
)
8231 /* Must have only one argument. */
8232 if (argc
== 1 && IS_ABSOLUTE_PATH (argv
[0]) && ! access (argv
[0], R_OK
))
8238 /* if-exists-else built-in spec function.
8240 This is like if-exists, but takes an additional argument which
8241 is returned if the first argument does not exist. */
8244 if_exists_else_spec_function (int argc
, const char **argv
)
8246 /* Must have exactly two arguments. */
8250 if (IS_ABSOLUTE_PATH (argv
[0]) && ! access (argv
[0], R_OK
))
8256 /* replace-outfile built-in spec function.
8258 This looks for the first argument in the outfiles array's name and
8259 replaces it with the second argument. */
8262 replace_outfile_spec_function (int argc
, const char **argv
)
8265 /* Must have exactly two arguments. */
8269 for (i
= 0; i
< n_infiles
; i
++)
8271 if (outfiles
[i
] && !strcmp (outfiles
[i
], argv
[0]))
8272 outfiles
[i
] = xstrdup (argv
[1]);
8277 /* Given two version numbers, compares the two numbers.
8278 A version number must match the regular expression
8279 ([1-9][0-9]*|0)(\.([1-9][0-9]*|0))*
8282 compare_version_strings (const char *v1
, const char *v2
)
8287 if (regcomp (&r
, "^([1-9][0-9]*|0)(\\.([1-9][0-9]*|0))*$",
8288 REG_EXTENDED
| REG_NOSUB
) != 0)
8290 rresult
= regexec (&r
, v1
, 0, NULL
, 0);
8291 if (rresult
== REG_NOMATCH
)
8292 fatal_error ("invalid version number %qs", v1
);
8293 else if (rresult
!= 0)
8295 rresult
= regexec (&r
, v2
, 0, NULL
, 0);
8296 if (rresult
== REG_NOMATCH
)
8297 fatal_error ("invalid version number %qs", v2
);
8298 else if (rresult
!= 0)
8301 return strverscmp (v1
, v2
);
8305 /* version_compare built-in spec function.
8307 This takes an argument of the following form:
8309 <comparison-op> <arg1> [<arg2>] <switch> <result>
8311 and produces "result" if the comparison evaluates to true,
8312 and nothing if it doesn't.
8314 The supported <comparison-op> values are:
8316 >= true if switch is a later (or same) version than arg1
8318 < true if switch is an earlier version than arg1
8320 >< true if switch is arg1 or later, and earlier than arg2
8321 <> true if switch is earlier than arg1 or is arg2 or later
8323 If the switch is not present, the condition is false unless
8324 the first character of the <comparison-op> is '!'.
8327 %:version-compare(>= 10.3 mmacosx-version-min= -lmx)
8328 adds -lmx if -mmacosx-version-min=10.3.9 was passed. */
8331 version_compare_spec_function (int argc
, const char **argv
)
8335 const char *switch_value
= NULL
;
8340 fatal_error ("too few arguments to %%:version-compare");
8341 if (argv
[0][0] == '\0')
8343 if ((argv
[0][1] == '<' || argv
[0][1] == '>') && argv
[0][0] != '!')
8345 if (argc
!= nargs
+ 3)
8346 fatal_error ("too many arguments to %%:version-compare");
8348 switch_len
= strlen (argv
[nargs
+ 1]);
8349 for (i
= 0; i
< n_switches
; i
++)
8350 if (!strncmp (switches
[i
].part1
, argv
[nargs
+ 1], switch_len
)
8351 && check_live_switch (i
, switch_len
))
8352 switch_value
= switches
[i
].part1
+ switch_len
;
8354 if (switch_value
== NULL
)
8358 comp1
= compare_version_strings (switch_value
, argv
[1]);
8360 comp2
= compare_version_strings (switch_value
, argv
[2]);
8362 comp2
= -1; /* This value unused. */
8365 switch (argv
[0][0] << 8 | argv
[0][1])
8367 case '>' << 8 | '=':
8368 result
= comp1
>= 0;
8370 case '!' << 8 | '<':
8371 result
= comp1
>= 0 || switch_value
== NULL
;
8376 case '!' << 8 | '>':
8377 result
= comp1
< 0 || switch_value
== NULL
;
8379 case '>' << 8 | '<':
8380 result
= comp1
>= 0 && comp2
< 0;
8382 case '<' << 8 | '>':
8383 result
= comp1
< 0 || comp2
>= 0;
8387 fatal_error ("unknown operator %qs in %%:version-compare", argv
[0]);
8392 return argv
[nargs
+ 2];
8395 /* %:include builtin spec function. This differs from %include in that it
8396 can be nested inside a spec, and thus be conditionalized. It takes
8397 one argument, the filename, and looks for it in the startfile path.
8398 The result is always NULL, i.e. an empty expansion. */
8401 include_spec_function (int argc
, const char **argv
)
8408 file
= find_a_file (&startfile_prefixes
, argv
[0], R_OK
, true);
8409 read_specs (file
? file
: argv
[0], FALSE
);
8414 /* %:find-file spec function. This function replaces its argument by
8415 the file found thru find_file, that is the -print-file-name gcc
8418 find_file_spec_function (int argc
, const char **argv
)
8425 file
= find_file (argv
[0]);
8430 /* %:find-plugindir spec function. This function replaces its argument
8431 by the -iplugindir=<dir> option. `dir' is found thru find_file, that
8432 is the -print-file-name gcc program option. */
8434 find_plugindir_spec_function (int argc
, const char **argv ATTRIBUTE_UNUSED
)
8441 option
= concat ("-iplugindir=", find_file ("plugin"), NULL
);
8446 /* %:print-asm-header spec function. Print a banner to say that the
8447 following output is from the assembler. */
8450 print_asm_header_spec_function (int arg ATTRIBUTE_UNUSED
,
8451 const char **argv ATTRIBUTE_UNUSED
)
8453 printf (_("Assembler options\n=================\n\n"));
8454 printf (_("Use \"-Wa,OPTION\" to pass \"OPTION\" to the assembler.\n\n"));
8459 /* Compute a timestamp to initialize flag_random_seed. */
8462 get_local_tick (void)
8466 /* Get some more or less random data. */
8467 #ifdef HAVE_GETTIMEOFDAY
8471 gettimeofday (&tv
, NULL
);
8472 ret
= tv
.tv_sec
* 1000 + tv
.tv_usec
/ 1000;
8476 time_t now
= time (NULL
);
8478 if (now
!= (time_t)-1)
8479 ret
= (unsigned) now
;
8486 /* %:compare-debug-dump-opt spec function. Save the last argument,
8487 expected to be the last -fdump-final-insns option, or generate a
8491 compare_debug_dump_opt_spec_function (int arg
,
8492 const char **argv ATTRIBUTE_UNUSED
)
8497 static char random_seed
[HOST_BITS_PER_WIDE_INT
/ 4 + 3];
8500 fatal_error ("too many arguments to %%:compare-debug-dump-opt");
8502 do_spec_2 ("%{fdump-final-insns=*:%*}");
8503 do_spec_1 (" ", 0, NULL
);
8505 if (argbuf_index
> 0 && strcmp (argv
[argbuf_index
- 1], "."))
8510 name
= xstrdup (argv
[argbuf_index
- 1]);
8515 const char *ext
= NULL
;
8517 if (argbuf_index
> 0)
8519 do_spec_2 ("%{o*:%*}%{!o:%{!S:%b%O}%{S:%b.s}}");
8522 else if (!compare_debug
)
8525 do_spec_2 ("%g.gkd");
8527 do_spec_1 (" ", 0, NULL
);
8529 gcc_assert (argbuf_index
> 0);
8531 name
= concat (argbuf
[argbuf_index
- 1], ext
, NULL
);
8533 ret
= concat ("-fdump-final-insns=", name
, NULL
);
8536 which
= compare_debug
< 0;
8537 debug_check_temp_file
[which
] = name
;
8541 unsigned HOST_WIDE_INT value
= get_local_tick () ^ getpid ();
8543 sprintf (random_seed
, HOST_WIDE_INT_PRINT_HEX
, value
);
8547 ret
= concat ("%{!frandom-seed=*:-frandom-seed=", random_seed
, "} ",
8556 static const char *debug_auxbase_opt
;
8558 /* %:compare-debug-self-opt spec function. Expands to the options
8559 that are to be passed in the second compilation of
8563 compare_debug_self_opt_spec_function (int arg
,
8564 const char **argv ATTRIBUTE_UNUSED
)
8567 fatal_error ("too many arguments to %%:compare-debug-self-opt");
8569 if (compare_debug
>= 0)
8572 do_spec_2 ("%{c|S:%{o*:%*}}");
8573 do_spec_1 (" ", 0, NULL
);
8575 if (argbuf_index
> 0)
8576 debug_auxbase_opt
= concat ("-auxbase-strip ",
8577 argbuf
[argbuf_index
- 1],
8580 debug_auxbase_opt
= NULL
;
8583 %<o %<MD %<MMD %<MF* %<MG %<MP %<MQ* %<MT* \
8584 %<fdump-final-insns=* -w -S -o %j \
8585 %{!fcompare-debug-second:-fcompare-debug-second} \
8586 ", compare_debug_opt
, NULL
);
8589 /* %:compare-debug-auxbase-opt spec function. Expands to the auxbase
8590 options that are to be passed in the second compilation of
8591 compare-debug. It expects, as an argument, the basename of the
8592 current input file name, with the .gk suffix appended to it. */
8595 compare_debug_auxbase_opt_spec_function (int arg
,
8602 fatal_error ("too few arguments to %%:compare-debug-auxbase-opt");
8605 fatal_error ("too many arguments to %%:compare-debug-auxbase-opt");
8607 if (compare_debug
>= 0)
8610 len
= strlen (argv
[0]);
8611 if (len
< 3 || strcmp (argv
[0] + len
- 3, ".gk") != 0)
8612 fatal_error ("argument to %%:compare-debug-auxbase-opt "
8613 "does not end in .gk");
8615 if (debug_auxbase_opt
)
8616 return debug_auxbase_opt
;
8618 #define OPT "-auxbase "
8621 name
= (char*) xmalloc (sizeof (OPT
) + len
);
8622 memcpy (name
, OPT
, sizeof (OPT
) - 1);
8623 memcpy (name
+ sizeof (OPT
) - 1, argv
[0], len
);
8624 name
[sizeof (OPT
) - 1 + len
] = '\0';