]>
Commit | Line | Data |
---|---|---|
ed1f651b | 1 | /* Compiler driver program that can handle many languages. |
9218435e | 2 | Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, |
d7fb0a6d | 3 | 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, |
66f1b195 | 4 | 2010, 2011, 2012 |
c662432e | 5 | Free Software Foundation, Inc. |
ed1f651b | 6 | |
1322177d | 7 | This file is part of GCC. |
ed1f651b | 8 | |
1322177d LB |
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 | |
9dcd6f09 | 11 | Software Foundation; either version 3, or (at your option) any later |
1322177d | 12 | version. |
ed1f651b | 13 | |
1322177d LB |
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 | |
17 | for more details. | |
ed1f651b RS |
18 | |
19 | You should have received a copy of the GNU General Public License | |
9dcd6f09 | 20 | along with GCC; see the file COPYING3. If not see |
8a554c70 | 21 | <http://www.gnu.org/licenses/>. */ |
ed1f651b RS |
22 | |
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. | |
28 | ||
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". */ | |
c5c76735 | 32 | |
e9a25f70 | 33 | #include "config.h" |
670ee920 | 34 | #include "system.h" |
4977bab6 | 35 | #include "coretypes.h" |
1713a69f | 36 | #include "multilib.h" /* before tm.h */ |
4977bab6 | 37 | #include "tm.h" |
ed5b9f96 | 38 | #include "xregex.h" |
17248a6b | 39 | #include "obstack.h" |
ab87f8c8 | 40 | #include "intl.h" |
460ee112 | 41 | #include "prefix.h" |
9257393c | 42 | #include "gcc.h" |
6afbc885 | 43 | #include "diagnostic.h" |
8a63621f | 44 | #include "flags.h" |
14c7833c | 45 | #include "opts.h" |
a7d0d30f | 46 | #include "params.h" |
5b634ee0 | 47 | #include "vec.h" |
ba78087b | 48 | #include "filenames.h" |
c10d53dd | 49 | |
45936a85 DD |
50 | /* By default there is no special suffix for target executables. */ |
51 | /* FIXME: when autoconf is fixed, remove the host check - dj */ | |
52 | #if defined(TARGET_EXECUTABLE_SUFFIX) && defined(HOST_EXECUTABLE_SUFFIX) | |
53 | #define HAVE_TARGET_EXECUTABLE_SUFFIX | |
ed1f651b | 54 | #endif |
f6ec7e54 | 55 | |
45936a85 DD |
56 | /* By default there is no special suffix for host executables. */ |
57 | #ifdef HOST_EXECUTABLE_SUFFIX | |
58 | #define HAVE_HOST_EXECUTABLE_SUFFIX | |
f70165f6 | 59 | #else |
45936a85 DD |
60 | #define HOST_EXECUTABLE_SUFFIX "" |
61 | #endif | |
62 | ||
63 | /* By default, the suffix for target object files is ".o". */ | |
64 | #ifdef TARGET_OBJECT_SUFFIX | |
65 | #define HAVE_TARGET_OBJECT_SUFFIX | |
66 | #else | |
67 | #define TARGET_OBJECT_SUFFIX ".o" | |
ed7dae04 RK |
68 | #endif |
69 | ||
8b60264b | 70 | static const char dir_separator_str[] = { DIR_SEPARATOR, 0 }; |
48ff801b | 71 | |
512b62fb JM |
72 | /* Most every one is fine with LIBRARY_PATH. For some, it conflicts. */ |
73 | #ifndef LIBRARY_PATH_ENV | |
74 | #define LIBRARY_PATH_ENV "LIBRARY_PATH" | |
75 | #endif | |
76 | ||
ed1f651b RS |
77 | /* If a stage of compilation returns an exit status >= 1, |
78 | compilation of that file ceases. */ | |
79 | ||
80 | #define MIN_FATAL_STATUS 1 | |
81 | ||
69927b59 NB |
82 | /* Flag set by cppspec.c to 1. */ |
83 | int is_cpp_driver; | |
84 | ||
110abdbc | 85 | /* Flag set to nonzero if an @file argument has been supplied to gcc. */ |
2091ff66 NF |
86 | static bool at_file_supplied; |
87 | ||
f5fa9a5b PE |
88 | /* Definition of string containing the arguments given to configure. */ |
89 | #include "configargs.h" | |
90 | ||
b8468bc7 NC |
91 | /* Flag saying to print the command line options understood by gcc and its |
92 | sub-processes. */ | |
93 | ||
94 | static int print_help_list; | |
95 | ||
41fd0f9b RAE |
96 | /* Flag saying to print the version of gcc and its sub-processes. */ |
97 | ||
98 | static int print_version; | |
99 | ||
99f78cdd IR |
100 | /* Flag indicating whether we should ONLY print the command and |
101 | arguments (like verbose_flag) without executing the command. | |
102 | Displayed arguments are quoted so that the generated command | |
103 | line is suitable for execution. This is intended for use in | |
104 | shell scripts to capture the driver-generated command line. */ | |
105 | static int verbose_only_flag; | |
106 | ||
c662432e | 107 | /* Flag indicating how to print command line options of sub-processes. */ |
91606ce2 | 108 | |
c662432e | 109 | static int print_subprocess_help; |
91606ce2 | 110 | |
bdde878c AO |
111 | /* Whether we should report subprocess execution times to a file. */ |
112 | ||
113 | FILE *report_times_to_file = NULL; | |
114 | ||
4977bab6 ZW |
115 | /* Nonzero means place this string before uses of /, so that include |
116 | and library files can be found in an alternate location. */ | |
117 | ||
db720d9a | 118 | #ifdef TARGET_SYSTEM_ROOT |
4977bab6 | 119 | static const char *target_system_root = TARGET_SYSTEM_ROOT; |
db720d9a DJ |
120 | #else |
121 | static const char *target_system_root = 0; | |
122 | #endif | |
4977bab6 | 123 | |
047d636f DJ |
124 | /* Nonzero means pass the updated target_system_root to the compiler. */ |
125 | ||
126 | static int target_system_root_changed; | |
127 | ||
e7f13528 GP |
128 | /* Nonzero means append this string to target_system_root. */ |
129 | ||
130 | static const char *target_sysroot_suffix = 0; | |
131 | ||
132 | /* Nonzero means append this string to target_system_root for headers. */ | |
133 | ||
134 | static const char *target_sysroot_hdrs_suffix = 0; | |
135 | ||
ed1f651b RS |
136 | /* Nonzero means write "temp" files in source directory |
137 | and use the source file's name in them, and don't delete them. */ | |
138 | ||
14fdc613 MM |
139 | static enum save_temps { |
140 | SAVE_TEMPS_NONE, /* no -save-temps */ | |
141 | SAVE_TEMPS_CWD, /* -save-temps in current directory */ | |
142 | SAVE_TEMPS_OBJ /* -save-temps in object directory */ | |
143 | } save_temps_flag; | |
144 | ||
145 | /* Output file to use to get the object directory for -save-temps=obj */ | |
146 | static char *save_temps_prefix = 0; | |
147 | static size_t save_temps_length = 0; | |
ed1f651b | 148 | |
53117a2f | 149 | /* The compiler version. */ |
ed1f651b | 150 | |
3b304f5b | 151 | static const char *compiler_version; |
53117a2f | 152 | |
1401cf37 | 153 | /* The target version. */ |
53117a2f | 154 | |
37a4aa31 | 155 | static const char *const spec_version = DEFAULT_TARGET_VERSION; |
ed1f651b | 156 | |
1401cf37 | 157 | /* The target machine. */ |
ed1f651b | 158 | |
878f32c3 | 159 | static const char *spec_machine = DEFAULT_TARGET_MACHINE; |
ed1f651b | 160 | |
004fd4d5 RS |
161 | /* Nonzero if cross-compiling. |
162 | When -b is used, the value comes from the `specs' file. */ | |
163 | ||
2989d30c | 164 | #ifdef CROSS_DIRECTORY_STRUCTURE |
3b304f5b | 165 | static const char *cross_compile = "1"; |
004fd4d5 | 166 | #else |
3b304f5b | 167 | static const char *cross_compile = "0"; |
004fd4d5 RS |
168 | #endif |
169 | ||
14a774a9 RK |
170 | /* Greatest exit code of sub-processes that has been encountered up to |
171 | now. */ | |
172 | static int greatest_status = 1; | |
173 | ||
ed1f651b RS |
174 | /* This is the obstack which we use to allocate many strings. */ |
175 | ||
176 | static struct obstack obstack; | |
177 | ||
b3865ca9 | 178 | /* This is the obstack to build an environment variable to pass to |
6dc42e49 | 179 | collect2 that describes all of the relevant switches of what to |
b3865ca9 RS |
180 | pass the compiler in building the list of pointers to constructors |
181 | and destructors. */ | |
182 | ||
183 | static struct obstack collect_obstack; | |
184 | ||
99360286 DE |
185 | /* Forward declaration for prototypes. */ |
186 | struct path_prefix; | |
76391e5a | 187 | struct prefix_list; |
99360286 | 188 | |
1d088dee AJ |
189 | static void init_spec (void); |
190 | static void store_arg (const char *, int, int); | |
fe7df9c4 | 191 | static void insert_wrapper (const char *); |
1d088dee AJ |
192 | static char *load_specs (const char *); |
193 | static void read_specs (const char *, int); | |
194 | static void set_spec (const char *, const char *); | |
195 | static struct compiler *lookup_compiler (const char *, size_t, const char *); | |
00dcee0c AM |
196 | static char *build_search_list (const struct path_prefix *, const char *, |
197 | bool, bool); | |
e9c15f6e | 198 | static void xputenv (const char *); |
00dcee0c AM |
199 | static void putenv_from_prefixes (const struct path_prefix *, const char *, |
200 | bool); | |
1d088dee | 201 | static int access_check (const char *, int); |
00dcee0c | 202 | static char *find_a_file (const struct path_prefix *, const char *, int, bool); |
1d088dee | 203 | static void add_prefix (struct path_prefix *, const char *, const char *, |
1a5d37a1 | 204 | int, int, int); |
1d088dee | 205 | static void add_sysrooted_prefix (struct path_prefix *, const char *, |
1a5d37a1 | 206 | const char *, int, int, int); |
1d088dee AJ |
207 | static char *skip_whitespace (char *); |
208 | static void delete_if_ordinary (const char *); | |
209 | static void delete_temp_files (void); | |
210 | static void delete_failure_queue (void); | |
211 | static void clear_failure_queue (void); | |
212 | static int check_live_switch (int, int); | |
213 | static const char *handle_braces (const char *); | |
214 | static inline bool input_suffix_matches (const char *, const char *); | |
215 | static inline bool switch_matches (const char *, const char *, int); | |
216 | static inline void mark_matching_switches (const char *, const char *, int); | |
217 | static inline void process_marked_switches (void); | |
218 | static const char *process_brace_body (const char *, const char *, const char *, int, int); | |
219 | static const struct spec_function *lookup_spec_function (const char *); | |
220 | static const char *eval_spec_function (const char *, const char *); | |
221 | static const char *handle_spec_function (const char *); | |
222 | static char *save_string (const char *, int); | |
223 | static void set_collect_gcc_options (void); | |
224 | static int do_spec_1 (const char *, int, const char *); | |
225 | static int do_spec_2 (const char *); | |
226 | static void do_option_spec (const char *, const char *); | |
227 | static void do_self_spec (const char *); | |
228 | static const char *find_file (const char *); | |
00dcee0c | 229 | static int is_directory (const char *, bool); |
1d088dee AJ |
230 | static const char *validate_switches (const char *); |
231 | static void validate_all_switches (void); | |
232 | static inline void validate_switches_from_spec (const char *); | |
233 | static void give_switch (int, int); | |
234 | static int used_arg (const char *, int); | |
235 | static int default_arg (const char *, int); | |
236 | static void set_multilib_dir (void); | |
237 | static void print_multilib_info (void); | |
238 | static void perror_with_name (const char *); | |
1d088dee AJ |
239 | static void display_help (void); |
240 | static void add_preprocessor_option (const char *, int); | |
241 | static void add_assembler_option (const char *, int); | |
242 | static void add_linker_option (const char *, int); | |
60cf253a | 243 | static void process_command (unsigned int, struct cl_decoded_option *); |
1d088dee AJ |
244 | static int execute (void); |
245 | static void alloc_args (void); | |
246 | static void clear_args (void); | |
2dec80c7 | 247 | static void fatal_signal (int); |
328163dc | 248 | #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC) |
1d088dee AJ |
249 | static void init_gcc_specs (struct obstack *, const char *, const char *, |
250 | const char *); | |
6894579f | 251 | #endif |
40cdfca6 | 252 | #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX) |
1d088dee | 253 | static const char *convert_filename (const char *, int, int); |
40cdfca6 | 254 | #endif |
f3226a90 | 255 | |
30d8946b | 256 | static const char *getenv_spec_function (int, const char **); |
1d088dee AJ |
257 | static const char *if_exists_spec_function (int, const char **); |
258 | static const char *if_exists_else_spec_function (int, const char **); | |
3dd53121 | 259 | static const char *replace_outfile_spec_function (int, const char **); |
2642f659 | 260 | static const char *remove_outfile_spec_function (int, const char **); |
ed5b9f96 | 261 | static const char *version_compare_spec_function (int, const char **); |
953ff289 | 262 | static const char *include_spec_function (int, const char **); |
4adbd5dd | 263 | static const char *find_file_spec_function (int, const char **); |
c1ce46a5 | 264 | static const char *find_plugindir_spec_function (int, const char **); |
a0f87454 | 265 | static const char *print_asm_header_spec_function (int, const char **); |
2153915d AO |
266 | static const char *compare_debug_dump_opt_spec_function (int, const char **); |
267 | static const char *compare_debug_self_opt_spec_function (int, const char **); | |
268 | static const char *compare_debug_auxbase_opt_spec_function (int, const char **); | |
9a37bc07 | 269 | static const char *pass_through_libs_spec_func (int, const char **); |
ed1f651b | 270 | \f |
d991c721 BK |
271 | /* The Specs Language |
272 | ||
273 | Specs are strings containing lines, each of which (if not blank) | |
ed1f651b RS |
274 | is made up of a program name, and arguments separated by spaces. |
275 | The program name must be exact and start from root, since no path | |
276 | is searched and it is unreliable to depend on the current working directory. | |
277 | Redirection of input or output is not supported; the subprograms must | |
278 | accept filenames saying what files to read and write. | |
279 | ||
280 | In addition, the specs can contain %-sequences to substitute variable text | |
281 | or for conditional text. Here is a table of all defined %-sequences. | |
282 | Note that spaces are not generated automatically around the results of | |
283 | expanding these sequences; therefore, you can concatenate them together | |
284 | or with constant text in a single argument. | |
285 | ||
286 | %% substitute one % into the program name or argument. | |
287 | %i substitute the name of the input file being processed. | |
288 | %b substitute the basename of the input file being processed. | |
289 | This is the substring up to (and not including) the last period | |
14fdc613 | 290 | and not including the directory unless -save-temps was specified |
3beb864c | 291 | to put temporaries in a different location. |
ea414c97 | 292 | %B same as %b, but include the file suffix (text after the last period). |
dd75c292 CB |
293 | %gSUFFIX |
294 | substitute a file name that has suffix SUFFIX and is chosen | |
295 | once per compilation, and mark the argument a la %d. To reduce | |
296 | exposure to denial-of-service attacks, the file name is now | |
297 | chosen in a way that is hard to predict even when previously | |
298 | chosen file names are known. For example, `%g.s ... %g.o ... %g.s' | |
299 | might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches | |
a92dd235 | 300 | the regexp "[.0-9A-Za-z]*%O"; "%O" is treated exactly as if it |
a1d9074c TT |
301 | had been pre-processed. Previously, %g was simply substituted |
302 | with a file name chosen once per compilation, without regard | |
303 | to any appended suffix (which was therefore treated just like | |
304 | ordinary text), making such attacks more likely to succeed. | |
4977bab6 ZW |
305 | %|SUFFIX |
306 | like %g, but if -pipe is in effect, expands simply to "-". | |
307 | %mSUFFIX | |
308 | like %g, but if -pipe is in effect, expands to nothing. (We have both | |
309 | %| and %m to accommodate differences between system assemblers; see | |
310 | the AS_NEEDS_DASH_FOR_PIPED_INPUT target macro.) | |
dd75c292 CB |
311 | %uSUFFIX |
312 | like %g, but generates a new temporary file name even if %uSUFFIX | |
313 | was already seen. | |
314 | %USUFFIX | |
315 | substitutes the last file name generated with %uSUFFIX, generating a | |
316 | new one if there is no such last file name. In the absence of any | |
317 | %uSUFFIX, this is just like %gSUFFIX, except they don't share | |
318 | the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s' | |
319 | would involve the generation of two distinct file names, one | |
320 | for each `%g.s' and another for each `%U.s'. Previously, %U was | |
321 | simply substituted with a file name chosen for the previous %u, | |
322 | without regard to any appended suffix. | |
49009afd JL |
323 | %jSUFFIX |
324 | substitutes the name of the HOST_BIT_BUCKET, if any, and if it is | |
325 | writable, and if save-temps is off; otherwise, substitute the name | |
326 | of a temporary file, just like %u. This temporary file is not | |
327 | meant for communication between processes, but rather as a junk | |
328 | disposal mechanism. | |
11972f66 NS |
329 | %.SUFFIX |
330 | substitutes .SUFFIX for the suffixes of a matched switch's args when | |
331 | it is subsequently output with %*. SUFFIX is terminated by the next | |
332 | space or %. | |
ed1f651b | 333 | %d marks the argument containing or following the %d as a |
ee618c17 | 334 | temporary file name, so that that file will be deleted if GCC exits |
ed1f651b RS |
335 | successfully. Unlike %g, this contributes no text to the argument. |
336 | %w marks the argument containing or following the %w as the | |
337 | "output file" of this compilation. This puts the argument | |
338 | into the sequence of arguments that %o will substitute later. | |
17211ab5 | 339 | %V indicates that this compilation produces no "output file". |
ed1f651b RS |
340 | %W{...} |
341 | like %{...} but mark last argument supplied within | |
342 | as a file to be deleted on failure. | |
343 | %o substitutes the names of all the output files, with spaces | |
344 | automatically placed around them. You should write spaces | |
345 | around the %o as well or the results are undefined. | |
346 | %o is for use in the specs for running the linker. | |
347 | Input files whose names have no recognized suffix are not compiled | |
348 | at all, but they are included among the output files, so they will | |
349 | be linked. | |
dd75c292 | 350 | %O substitutes the suffix for object files. Note that this is |
a1d9074c TT |
351 | handled specially when it immediately follows %g, %u, or %U |
352 | (with or without a suffix argument) because of the need for | |
353 | those to form complete file names. The handling is such that | |
354 | %O is treated exactly as if it had already been substituted, | |
355 | except that %g, %u, and %U do not currently support additional | |
356 | SUFFIX characters following %O as they would following, for | |
357 | example, `.o'. | |
047d636f | 358 | %I Substitute any of -iprefix (made from GCC_EXEC_PREFIX), -isysroot |
2b6dd222 JM |
359 | (made from TARGET_SYSTEM_ROOT), -isystem (made from COMPILER_PATH |
360 | and -B options) and -imultilib as necessary. | |
ed1f651b RS |
361 | %s current argument is the name of a library or startup file of some sort. |
362 | Search for that file in a standard list of directories | |
363 | and substitute the full name found. | |
364 | %eSTR Print STR as an error message. STR is terminated by a newline. | |
365 | Use this when inconsistent options are detected. | |
09da1532 | 366 | %nSTR Print STR as a notice. STR is terminated by a newline. |
ed1f651b RS |
367 | %x{OPTION} Accumulate an option for %X. |
368 | %X Output the accumulated linker options specified by compilations. | |
c9ebacb8 | 369 | %Y Output the accumulated assembler options specified by compilations. |
57cb9b60 | 370 | %Z Output the accumulated preprocessor options specified by compilations. |
ed1f651b RS |
371 | %a process ASM_SPEC as a spec. |
372 | This allows config.h to specify part of the spec for running as. | |
373 | %A process ASM_FINAL_SPEC as a spec. A capital A is actually | |
374 | used here. This can be used to run a post-processor after the | |
9ec36da5 | 375 | assembler has done its job. |
48ff801b | 376 | %D Dump out a -L option for each directory in startfile_prefixes. |
60103a34 | 377 | If multilib_dir is set, extra entries are generated with it affixed. |
ed1f651b RS |
378 | %l process LINK_SPEC as a spec. |
379 | %L process LIB_SPEC as a spec. | |
68d69835 | 380 | %G process LIBGCC_SPEC as a spec. |
380e5ca4 MM |
381 | %R Output the concatenation of target_system_root and |
382 | target_sysroot_suffix. | |
ed1f651b RS |
383 | %S process STARTFILE_SPEC as a spec. A capital S is actually used here. |
384 | %E process ENDFILE_SPEC as a spec. A capital E is actually used here. | |
9db0819e | 385 | %C process CPP_SPEC as a spec. |
ed1f651b RS |
386 | %1 process CC1_SPEC as a spec. |
387 | %2 process CC1PLUS_SPEC as a spec. | |
388 | %* substitute the variable part of a matched option. (See below.) | |
389 | Note that each comma in the substituted string is replaced by | |
390 | a single space. | |
4977bab6 ZW |
391 | %<S remove all occurrences of -S from the command line. |
392 | Note - this command is position dependent. % commands in the | |
393 | spec string before this one will see -S, % commands in the | |
394 | spec string after this one will not. | |
96f5b137 | 395 | %>S Similar to "%<S", but keep it in the GCC command line. |
4977bab6 ZW |
396 | %<S* remove all occurrences of all switches beginning with -S from the |
397 | command line. | |
f3226a90 JT |
398 | %:function(args) |
399 | Call the named function FUNCTION, passing it ARGS. ARGS is | |
400 | first processed as a nested spec string, then split into an | |
401 | argument vector in the usual fashion. The function returns | |
402 | a string which is processed as if it had appeared literally | |
403 | as part of the current spec. | |
ee618c17 | 404 | %{S} substitutes the -S switch, if that switch was given to GCC. |
ed1f651b RS |
405 | If that switch was not specified, this substitutes nothing. |
406 | Here S is a metasyntactic variable. | |
ee618c17 | 407 | %{S*} substitutes all the switches specified to GCC whose names start |
196a37f4 | 408 | with -S. This is used for -o, -I, etc; switches that take |
ee618c17 | 409 | arguments. GCC considers `-o foo' as being one switch whose |
ed1f651b RS |
410 | name starts with `o'. %{o*} would substitute this text, |
411 | including the space; thus, two arguments would be generated. | |
196a37f4 | 412 | %{S*&T*} likewise, but preserve order of S and T options (the order |
1d088dee AJ |
413 | of S and T in the spec is not significant). Can be any number |
414 | of ampersand-separated variables; for each the wild card is | |
415 | optional. Useful for CPP as %{D*&U*&A*}. | |
4977bab6 | 416 | |
ee618c17 BE |
417 | %{S:X} substitutes X, if the -S switch was given to GCC. |
418 | %{!S:X} substitutes X, if the -S switch was NOT given to GCC. | |
4977bab6 | 419 | %{S*:X} substitutes X if one or more switches whose names start |
ee618c17 | 420 | with -S was given to GCC. Normally X is substituted only |
4977bab6 ZW |
421 | once, no matter how many such switches appeared. However, |
422 | if %* appears somewhere in X, then X will be substituted | |
423 | once for each matching switch, with the %* replaced by the | |
424 | part of that switch that matched the '*'. | |
425 | %{.S:X} substitutes X, if processing a file with suffix S. | |
426 | %{!.S:X} substitutes X, if NOT processing a file with suffix S. | |
48137d59 GK |
427 | %{,S:X} substitutes X, if processing a file which will use spec S. |
428 | %{!,S:X} substitutes X, if NOT processing a file which will use spec S. | |
3beb864c | 429 | |
ee618c17 | 430 | %{S|T:X} substitutes X if either -S or -T was given to GCC. This may be |
48137d59 GK |
431 | combined with '!', '.', ',', and '*' as above binding stronger |
432 | than the OR. | |
4977bab6 ZW |
433 | If %* appears in X, all of the alternatives must be starred, and |
434 | only the first matching alternative is substituted. | |
ee618c17 BE |
435 | %{S:X; if S was given to GCC, substitutes X; |
436 | T:Y; else if T was given to GCC, substitutes Y; | |
4977bab6 | 437 | :D} else substitutes D. There can be as many clauses as you need. |
48137d59 | 438 | This may be combined with '.', '!', ',', '|', and '*' as above. |
4977bab6 | 439 | |
b3865ca9 | 440 | %(Spec) processes a specification defined in a specs file as *Spec: |
ed1f651b | 441 | |
4977bab6 | 442 | The conditional text X in a %{S:X} or similar construct may contain |
ed1f651b | 443 | other nested % constructs or spaces, or even newlines. They are |
4977bab6 ZW |
444 | processed as usual, as described above. Trailing white space in X is |
445 | ignored. White space may also appear anywhere on the left side of the | |
446 | colon in these constructs, except between . or * and the corresponding | |
447 | word. | |
ed1f651b | 448 | |
6c396fb5 | 449 | The -O, -f, -m, and -W switches are handled specifically in these |
f5b0eb4e RK |
450 | constructs. If another value of -O or the negated form of a -f, -m, or |
451 | -W switch is found later in the command line, the earlier switch | |
6c396fb5 RK |
452 | value is ignored, except with {S*} where S is just one letter; this |
453 | passes all matching options. | |
f5b0eb4e | 454 | |
9bf09437 RH |
455 | The character | at the beginning of the predicate text is used to indicate |
456 | that a command should be piped to the following command, but only if -pipe | |
457 | is specified. | |
ed1f651b | 458 | |
ee618c17 | 459 | Note that it is built into GCC which switches take arguments and which |
ed1f651b RS |
460 | do not. You might think it would be useful to generalize this to |
461 | allow each compiler's spec to say which switches take arguments. But | |
ee618c17 | 462 | this cannot be done in a consistent fashion. GCC cannot even decide |
ed1f651b RS |
463 | which input files have been specified without knowing which switches |
464 | take arguments, and it must know which input files to compile in order | |
465 | to tell which compilers to run. | |
466 | ||
ee618c17 | 467 | GCC also knows implicitly that arguments starting in `-l' are to be |
ed1f651b RS |
468 | treated as compiler output files, and passed to the linker in their |
469 | proper position among the other output files. */ | |
470 | \f | |
0fef3fd0 | 471 | /* Define the macros used for specs %a, %l, %L, %S, %C, %1. */ |
ed1f651b RS |
472 | |
473 | /* config.h can define ASM_SPEC to provide extra args to the assembler | |
474 | or extra switch-translations. */ | |
475 | #ifndef ASM_SPEC | |
476 | #define ASM_SPEC "" | |
477 | #endif | |
478 | ||
479 | /* config.h can define ASM_FINAL_SPEC to run a post processor after | |
480 | the assembler has run. */ | |
481 | #ifndef ASM_FINAL_SPEC | |
482 | #define ASM_FINAL_SPEC "" | |
483 | #endif | |
484 | ||
485 | /* config.h can define CPP_SPEC to provide extra args to the C preprocessor | |
486 | or extra switch-translations. */ | |
487 | #ifndef CPP_SPEC | |
488 | #define CPP_SPEC "" | |
489 | #endif | |
490 | ||
491 | /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus | |
492 | or extra switch-translations. */ | |
493 | #ifndef CC1_SPEC | |
494 | #define CC1_SPEC "" | |
495 | #endif | |
496 | ||
497 | /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus | |
498 | or extra switch-translations. */ | |
499 | #ifndef CC1PLUS_SPEC | |
500 | #define CC1PLUS_SPEC "" | |
501 | #endif | |
502 | ||
503 | /* config.h can define LINK_SPEC to provide extra args to the linker | |
504 | or extra switch-translations. */ | |
505 | #ifndef LINK_SPEC | |
506 | #define LINK_SPEC "" | |
507 | #endif | |
508 | ||
509 | /* config.h can define LIB_SPEC to override the default libraries. */ | |
510 | #ifndef LIB_SPEC | |
68d69835 JM |
511 | #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}" |
512 | #endif | |
513 | ||
6de9cd9a DN |
514 | /* mudflap specs */ |
515 | #ifndef MFWRAP_SPEC | |
516 | /* XXX: valid only for GNU ld */ | |
517 | /* XXX: should exactly match hooks provided by libmudflap.a */ | |
518 | #define MFWRAP_SPEC " %{static: %{fmudflap|fmudflapth: \ | |
519 | --wrap=malloc --wrap=free --wrap=calloc --wrap=realloc\ | |
891a2e42 | 520 | --wrap=mmap --wrap=mmap64 --wrap=munmap --wrap=alloca\ |
7544a87f | 521 | } %{fmudflapth: --wrap=pthread_create\ |
6de9cd9a DN |
522 | }} %{fmudflap|fmudflapth: --wrap=main}" |
523 | #endif | |
524 | #ifndef MFLIB_SPEC | |
7904f95f | 525 | #define MFLIB_SPEC "%{fmudflap|fmudflapth: -export-dynamic}" |
6de9cd9a DN |
526 | #endif |
527 | ||
7458026b ILT |
528 | /* When using -fsplit-stack we need to wrap pthread_create, in order |
529 | to initialize the stack guard. We always use wrapping, rather than | |
530 | shared library ordering, and we keep the wrapper function in | |
531 | libgcc. This is not yet a real spec, though it could become one; | |
532 | it is currently just stuffed into LINK_SPEC. FIXME: This wrapping | |
533 | only works with GNU ld and gold. FIXME: This is incompatible with | |
534 | -fmudflap when linking statically, which wants to do its own | |
535 | wrapping. */ | |
536 | #define STACK_SPLIT_SPEC " %{fsplit-stack: --wrap=pthread_create}" | |
537 | ||
68d69835 JM |
538 | /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is |
539 | included. */ | |
540 | #ifndef LIBGCC_SPEC | |
328163dc MA |
541 | #if defined(REAL_LIBGCC_SPEC) |
542 | #define LIBGCC_SPEC REAL_LIBGCC_SPEC | |
57642751 | 543 | #elif defined(LINK_LIBGCC_SPECIAL_1) |
68d69835 | 544 | /* Have gcc do the search for libgcc.a. */ |
ba2b7435 | 545 | #define LIBGCC_SPEC "libgcc.a%s" |
68d69835 | 546 | #else |
ba2b7435 | 547 | #define LIBGCC_SPEC "-lgcc" |
68d69835 | 548 | #endif |
ed1f651b RS |
549 | #endif |
550 | ||
551 | /* config.h can define STARTFILE_SPEC to override the default crt0 files. */ | |
552 | #ifndef STARTFILE_SPEC | |
553 | #define STARTFILE_SPEC \ | |
adcb8d7d | 554 | "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}" |
ed1f651b RS |
555 | #endif |
556 | ||
ed1f651b RS |
557 | /* config.h can define ENDFILE_SPEC to override the default crtn files. */ |
558 | #ifndef ENDFILE_SPEC | |
559 | #define ENDFILE_SPEC "" | |
560 | #endif | |
561 | ||
10da1131 BM |
562 | #ifndef LINKER_NAME |
563 | #define LINKER_NAME "collect2" | |
564 | #endif | |
565 | ||
c8aea42c PB |
566 | #ifdef HAVE_AS_DEBUG_PREFIX_MAP |
567 | #define ASM_MAP " %{fdebug-prefix-map=*:--debug-prefix-map %*}" | |
568 | #else | |
569 | #define ASM_MAP "" | |
570 | #endif | |
571 | ||
5f0e9ea2 GK |
572 | /* Define ASM_DEBUG_SPEC to be a spec suitable for translating '-g' |
573 | to the assembler. */ | |
574 | #ifndef ASM_DEBUG_SPEC | |
b2ace8a4 JJ |
575 | # if defined(DBX_DEBUGGING_INFO) && defined(DWARF2_DEBUGGING_INFO) \ |
576 | && defined(HAVE_AS_GDWARF2_DEBUG_FLAG) && defined(HAVE_AS_GSTABS_DEBUG_FLAG) | |
c8aea42c PB |
577 | # define ASM_DEBUG_SPEC \ |
578 | (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG \ | |
c7b94907 MM |
579 | ? "%{!g0:%{gdwarf-2*:--gdwarf2}%{!gdwarf-2*:%{g*:--gstabs}}}" ASM_MAP \ |
580 | : "%{!g0:%{gstabs*:--gstabs}%{!gstabs*:%{g*:--gdwarf2}}}" ASM_MAP) | |
b2ace8a4 JJ |
581 | # else |
582 | # if defined(DBX_DEBUGGING_INFO) && defined(HAVE_AS_GSTABS_DEBUG_FLAG) | |
c7b94907 | 583 | # define ASM_DEBUG_SPEC "%{g*:%{!g0:--gstabs}}" ASM_MAP |
b2ace8a4 JJ |
584 | # endif |
585 | # if defined(DWARF2_DEBUGGING_INFO) && defined(HAVE_AS_GDWARF2_DEBUG_FLAG) | |
c7b94907 | 586 | # define ASM_DEBUG_SPEC "%{g*:%{!g0:--gdwarf2}}" ASM_MAP |
5f0e9ea2 | 587 | # endif |
5f0e9ea2 GK |
588 | # endif |
589 | #endif | |
8a63621f JJ |
590 | #ifndef ASM_DEBUG_SPEC |
591 | # define ASM_DEBUG_SPEC "" | |
592 | #endif | |
5f0e9ea2 | 593 | |
ea414c97 ZW |
594 | /* Here is the spec for running the linker, after compiling all files. */ |
595 | ||
bbd7687d DM |
596 | /* This is overridable by the target in case they need to specify the |
597 | -lgcc and -lc order specially, yet not require them to override all | |
598 | of LINK_COMMAND_SPEC. */ | |
599 | #ifndef LINK_GCC_C_SEQUENCE_SPEC | |
600 | #define LINK_GCC_C_SEQUENCE_SPEC "%G %L %G" | |
601 | #endif | |
602 | ||
77008252 JJ |
603 | #ifndef LINK_SSP_SPEC |
604 | #ifdef TARGET_LIBC_PROVIDES_SSP | |
605 | #define LINK_SSP_SPEC "%{fstack-protector:}" | |
606 | #else | |
ec92bd4b | 607 | #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all:-lssp_nonshared -lssp}" |
77008252 JJ |
608 | #endif |
609 | #endif | |
610 | ||
24a4dd31 JJ |
611 | #ifndef LINK_PIE_SPEC |
612 | #ifdef HAVE_LD_PIE | |
613 | #define LINK_PIE_SPEC "%{pie:-pie} " | |
614 | #else | |
615 | #define LINK_PIE_SPEC "%{pie:} " | |
616 | #endif | |
617 | #endif | |
618 | ||
cd533689 PP |
619 | #ifndef LINK_BUILDID_SPEC |
620 | # if defined(HAVE_LD_BUILDID) && defined(ENABLE_LD_BUILDID) | |
621 | # define LINK_BUILDID_SPEC "%{!r:--build-id} " | |
622 | # endif | |
623 | #endif | |
624 | ||
55b46574 | 625 | /* Conditional to test whether the LTO plugin is used or not. |
56e22cab JH |
626 | FIXME: For slim LTO we will need to enable plugin unconditionally. This |
627 | still cause problems with PLUGIN_LD != LD and when plugin is built but | |
628 | not useable. For GCC 4.6 we don't support slim LTO and thus we can enable | |
629 | plugin only when LTO is enabled. We still honor explicit | |
55b46574 RO |
630 | -fuse-linker-plugin if the linker used understands -plugin. */ |
631 | ||
632 | /* The linker has some plugin support. */ | |
633 | #if HAVE_LTO_PLUGIN > 0 | |
634 | /* The linker used has full plugin support, use LTO plugin by default. */ | |
635 | #if HAVE_LTO_PLUGIN == 2 | |
56e22cab JH |
636 | #define PLUGIN_COND "!fno-use-linker-plugin:%{flto|flto=*|fuse-linker-plugin" |
637 | #define PLUGIN_COND_CLOSE "}" | |
96bdf9b4 | 638 | #else |
55b46574 RO |
639 | /* The linker used has limited plugin support, use LTO plugin with explicit |
640 | -fuse-linker-plugin. */ | |
96bdf9b4 | 641 | #define PLUGIN_COND "fuse-linker-plugin" |
56e22cab | 642 | #define PLUGIN_COND_CLOSE "" |
96bdf9b4 | 643 | #endif |
55b46574 RO |
644 | #define LINK_PLUGIN_SPEC \ |
645 | "%{"PLUGIN_COND": \ | |
646 | -plugin %(linker_plugin_file) \ | |
647 | -plugin-opt=%(lto_wrapper) \ | |
648 | -plugin-opt=-fresolution=%u.res \ | |
649 | %{!nostdlib:%{!nodefaultlibs:%:pass-through-libs(%(link_gcc_c_sequence))}} \ | |
650 | }"PLUGIN_COND_CLOSE | |
651 | #else | |
652 | /* The linker used doesn't support -plugin, reject -fuse-linker-plugin. */ | |
653 | #define LINK_PLUGIN_SPEC "%{fuse-linker-plugin:\ | |
654 | %e-fuse-linker-plugin is not supported in this configuration}" | |
655 | #endif | |
96bdf9b4 | 656 | |
cd533689 | 657 | |
ea414c97 ZW |
658 | /* -u* was put back because both BSD and SysV seem to support it. */ |
659 | /* %{static:} simply prevents an error message if the target machine | |
660 | doesn't handle -static. */ | |
661 | /* We want %{T*} after %{L*} and %D so that it can be used to specify linker | |
662 | scripts which exist in user specified directories, or in standard | |
663 | directories. */ | |
014d92e1 | 664 | /* We pass any -flto flags on to the linker, which is expected |
d7f09764 | 665 | to understand them. In practice, this means it had better be collect2. */ |
fa381cb2 | 666 | /* %{e*} includes -export-dynamic; see comment in common.opt. */ |
ea414c97 ZW |
667 | #ifndef LINK_COMMAND_SPEC |
668 | #define LINK_COMMAND_SPEC "\ | |
669 | %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\ | |
55b46574 RO |
670 | %(linker) " \ |
671 | LINK_PLUGIN_SPEC \ | |
672 | "%{flto|flto=*:%<fcompare-debug*} \ | |
56e22cab | 673 | %{flto} %{flto=*} %l " LINK_PIE_SPEC \ |
12b57b0f JM |
674 | "%X %{o*} %{e*} %{N} %{n} %{r}\ |
675 | %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!nostartfiles:%S}}\ | |
8beb0d9e | 676 | %{static:} %{L*} %(mfwrap) %(link_libgcc) %o\ |
7458026b | 677 | %{fopenmp|ftree-parallelize-loops=*:%:include(libgomp.spec)%(link_gomp)}\ |
255a9a1b | 678 | %{fgnu-tm:%:include(libitm.spec)%(link_itm)}\ |
7458026b | 679 | %(mflib) " STACK_SPLIT_SPEC "\ |
a123d175 | 680 | %{fprofile-arcs|fprofile-generate*|coverage:-lgcov}\ |
9714c911 | 681 | %{!nostdlib:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}\ |
12b57b0f | 682 | %{!nostdlib:%{!nostartfiles:%E}} %{T*} }}}}}}" |
ea414c97 ZW |
683 | #endif |
684 | ||
685 | #ifndef LINK_LIBGCC_SPEC | |
57642751 DJ |
686 | /* Generate -L options for startfile prefix list. */ |
687 | # define LINK_LIBGCC_SPEC "%D" | |
ea414c97 ZW |
688 | #endif |
689 | ||
343f59d9 AM |
690 | #ifndef STARTFILE_PREFIX_SPEC |
691 | # define STARTFILE_PREFIX_SPEC "" | |
692 | #endif | |
693 | ||
380e5ca4 MM |
694 | #ifndef SYSROOT_SPEC |
695 | # define SYSROOT_SPEC "--sysroot=%R" | |
696 | #endif | |
697 | ||
e7f13528 GP |
698 | #ifndef SYSROOT_SUFFIX_SPEC |
699 | # define SYSROOT_SUFFIX_SPEC "" | |
700 | #endif | |
701 | ||
702 | #ifndef SYSROOT_HEADERS_SUFFIX_SPEC | |
703 | # define SYSROOT_HEADERS_SUFFIX_SPEC "" | |
704 | #endif | |
705 | ||
b24513a1 | 706 | static const char *asm_debug = ASM_DEBUG_SPEC; |
3b304f5b | 707 | static const char *cpp_spec = CPP_SPEC; |
3b304f5b ZW |
708 | static const char *cc1_spec = CC1_SPEC; |
709 | static const char *cc1plus_spec = CC1PLUS_SPEC; | |
bbd7687d | 710 | static const char *link_gcc_c_sequence_spec = LINK_GCC_C_SEQUENCE_SPEC; |
77008252 | 711 | static const char *link_ssp_spec = LINK_SSP_SPEC; |
3b304f5b ZW |
712 | static const char *asm_spec = ASM_SPEC; |
713 | static const char *asm_final_spec = ASM_FINAL_SPEC; | |
714 | static const char *link_spec = LINK_SPEC; | |
715 | static const char *lib_spec = LIB_SPEC; | |
6de9cd9a DN |
716 | static const char *mfwrap_spec = MFWRAP_SPEC; |
717 | static const char *mflib_spec = MFLIB_SPEC; | |
953ff289 | 718 | static const char *link_gomp_spec = ""; |
3b304f5b ZW |
719 | static const char *libgcc_spec = LIBGCC_SPEC; |
720 | static const char *endfile_spec = ENDFILE_SPEC; | |
721 | static const char *startfile_spec = STARTFILE_SPEC; | |
3b304f5b | 722 | static const char *linker_name_spec = LINKER_NAME; |
d7f09764 DN |
723 | static const char *linker_plugin_file_spec = ""; |
724 | static const char *lto_wrapper_spec = ""; | |
725 | static const char *lto_gcc_spec = ""; | |
ea414c97 ZW |
726 | static const char *link_command_spec = LINK_COMMAND_SPEC; |
727 | static const char *link_libgcc_spec = LINK_LIBGCC_SPEC; | |
343f59d9 | 728 | static const char *startfile_prefix_spec = STARTFILE_PREFIX_SPEC; |
380e5ca4 | 729 | static const char *sysroot_spec = SYSROOT_SPEC; |
e7f13528 GP |
730 | static const char *sysroot_suffix_spec = SYSROOT_SUFFIX_SPEC; |
731 | static const char *sysroot_hdrs_suffix_spec = SYSROOT_HEADERS_SUFFIX_SPEC; | |
84f405a1 | 732 | static const char *self_spec = ""; |
ea414c97 ZW |
733 | |
734 | /* Standard options to cpp, cc1, and as, to reduce duplication in specs. | |
735 | There should be no need to override these in target dependent files, | |
736 | but we need to copy them to the specs file so that newer versions | |
737 | of the GCC driver can correctly drive older tool chains with the | |
738 | appropriate -B options. */ | |
739 | ||
e5f5feea NB |
740 | /* When cpplib handles traditional preprocessing, get rid of this, and |
741 | call cc1 (or cc1obj in objc/lang-specs.h) from the main specs so | |
742 | that we default the front end language better. */ | |
ea414c97 | 743 | static const char *trad_capable_cpp = |
3028a95c | 744 | "cc1 -E %{traditional|traditional-cpp:-traditional-cpp}"; |
ea414c97 | 745 | |
4ca1256f NB |
746 | /* We don't wrap .d files in %W{} since a missing .d file, and |
747 | therefore no dependency entry, confuses make into thinking a .o | |
748 | file that happens to exist is up-to-date. */ | |
ffdeea47 | 749 | static const char *cpp_unique_options = |
9cc54940 | 750 | "%{!Q:-quiet} %{nostdinc*} %{C} %{CC} %{v} %{I*&F*} %{P} %I\ |
c878765b JM |
751 | %{MD:-MD %{!o:%b.d}%{o*:%.d%*}}\ |
752 | %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}}\ | |
4ca1256f | 753 | %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\ |
3dfe046f | 754 | %{!E:%{!M:%{!MM:%{!MT:%{!MQ:%{MD|MMD:%{o*:-MQ %*}}}}}}}\ |
3a610de8 | 755 | %{remap} %{g3|ggdb3|gstabs3|gcoff3|gxcoff3|gvms3:-dD}\ |
c1ce46a5 | 756 | %{!iplugindir*:%{fplugin*:%:find-plugindir()}}\ |
3a610de8 | 757 | %{H} %C %{D*&U*&A*} %{i*} %Z %i\ |
6de9cd9a DN |
758 | %{fmudflap:-D_MUDFLAP -include mf-runtime.h}\ |
759 | %{fmudflapth:-D_MUDFLAP -D_MUDFLAPTH -include mf-runtime.h}\ | |
56cd5b95 | 760 | %{E|M|MM:%W{o*}}"; |
ffdeea47 JJ |
761 | |
762 | /* This contains cpp options which are common with cc1_options and are passed | |
059ba716 CD |
763 | only when preprocessing only to avoid duplication. We pass the cc1 spec |
764 | options to the preprocessor so that it the cc1 spec may manipulate | |
765 | options used to set target flags. Those special target flags settings may | |
766 | in turn cause preprocessor symbols to be defined specially. */ | |
ffdeea47 | 767 | static const char *cpp_options = |
740ca4b2 | 768 | "%(cpp_unique_options) %1 %{m*} %{std*&ansi&trigraphs} %{W*&pedantic*} %{w}\ |
09828811 | 769 | %{f*} %{g*:%{!g0:%{g*} %{!fno-working-directory:-fworking-directory}}} %{O*}\ |
14fdc613 | 770 | %{undef} %{save-temps*:-fpch-preprocess}"; |
ea414c97 | 771 | |
8b968bd1 MW |
772 | /* This contains cpp options which are not passed when the preprocessor |
773 | output will be used by another program. */ | |
774 | static const char *cpp_debug_options = "%{d*}"; | |
775 | ||
708bceb7 | 776 | /* NB: This is shared amongst all front-ends, except for Ada. */ |
ea414c97 ZW |
777 | static const char *cc1_options = |
778 | "%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\ | |
c1ce46a5 | 779 | %{!iplugindir*:%{fplugin*:%:find-plugindir()}}\ |
1890bccc | 780 | %1 %{!Q:-quiet} %{!dumpbase:-dumpbase %B} %{d*} %{m*} %{aux-info*}\ |
2153915d AO |
781 | %{fcompare-debug-second:%:compare-debug-auxbase-opt(%b)} \ |
782 | %{!fcompare-debug-second:%{c|S:%{o*:-auxbase-strip %*}%{!o*:-auxbase %b}}}%{!c:%{!S:-auxbase %b}} \ | |
740ca4b2 | 783 | %{g*} %{O*} %{W*&pedantic*} %{w} %{std*&ansi&trigraphs}\ |
3df89291 | 784 | %{v:-version} %{pg:-p} %{p} %{f*} %{undef}\ |
dd9f93dc | 785 | %{Qn:-fno-ident} %{Qy:} %{-help:--help}\ |
e200444e JM |
786 | %{-target-help:--target-help}\ |
787 | %{-version:--version}\ | |
788 | %{-help=*:--help=%*}\ | |
49009afd | 789 | %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %b.s}}}\ |
6de9cd9a | 790 | %{fsyntax-only:-o %j} %{-param*}\ |
ee4c708e BE |
791 | %{fmudflap|fmudflapth:-fno-builtin -fno-merge-constants}\ |
792 | %{coverage:-fprofile-arcs -ftest-coverage}"; | |
ea414c97 ZW |
793 | |
794 | static const char *asm_options = | |
a016dc83 | 795 | "%{-target-help:%:print-asm-header()} " |
dc60b775 CD |
796 | #if HAVE_GNU_AS |
797 | /* If GNU AS is used, then convert -w (no warnings), -I, and -v | |
798 | to the assembler equivalents. */ | |
799 | "%{v} %{w:-W} %{I*} " | |
800 | #endif | |
801 | "%a %Y %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}"; | |
ffd86336 | 802 | |
5a8e2650 | 803 | static const char *invoke_as = |
4977bab6 | 804 | #ifdef AS_NEEDS_DASH_FOR_PIPED_INPUT |
d7f09764 DN |
805 | "%{!fwpa:\ |
806 | %{fcompare-debug=*|fdump-final-insns=*:%:compare-debug-dump-opt()}\ | |
807 | %{!S:-o %|.s |\n as %(asm_options) %|.s %A }\ | |
808 | }"; | |
4977bab6 | 809 | #else |
d7f09764 DN |
810 | "%{!fwpa:\ |
811 | %{fcompare-debug=*|fdump-final-insns=*:%:compare-debug-dump-opt()}\ | |
812 | %{!S:-o %|.s |\n as %(asm_options) %m.s %A }\ | |
813 | }"; | |
4977bab6 | 814 | #endif |
5a8e2650 | 815 | |
ffd86336 | 816 | /* Some compilers have limits on line lengths, and the multilib_select |
961b7009 MM |
817 | and/or multilib_matches strings can be very long, so we build them at |
818 | run time. */ | |
ffd86336 | 819 | static struct obstack multilib_obstack; |
3b304f5b ZW |
820 | static const char *multilib_select; |
821 | static const char *multilib_matches; | |
822 | static const char *multilib_defaults; | |
823 | static const char *multilib_exclusions; | |
961b7009 MM |
824 | |
825 | /* Check whether a particular argument is a default argument. */ | |
826 | ||
827 | #ifndef MULTILIB_DEFAULTS | |
828 | #define MULTILIB_DEFAULTS { "" } | |
829 | #endif | |
830 | ||
d25a45d4 | 831 | static const char *const multilib_defaults_raw[] = MULTILIB_DEFAULTS; |
ed1f651b | 832 | |
db36994b RS |
833 | #ifndef DRIVER_SELF_SPECS |
834 | #define DRIVER_SELF_SPECS "" | |
835 | #endif | |
836 | ||
953ff289 DN |
837 | /* Adding -fopenmp should imply pthreads. This is particularly important |
838 | for targets that use different start files and suchlike. */ | |
839 | #ifndef GOMP_SELF_SPECS | |
daf49354 | 840 | #define GOMP_SELF_SPECS "%{fopenmp|ftree-parallelize-loops=*: -pthread}" |
953ff289 DN |
841 | #endif |
842 | ||
255a9a1b EB |
843 | /* Likewise for -fgnu-tm. */ |
844 | #ifndef GTM_SELF_SPECS | |
845 | #define GTM_SELF_SPECS "%{fgnu-tm: -pthread}" | |
846 | #endif | |
847 | ||
953ff289 | 848 | static const char *const driver_self_specs[] = { |
b5b8b0ac | 849 | "%{fdump-final-insns:-fdump-final-insns=.} %<fdump-final-insns", |
255a9a1b | 850 | DRIVER_SELF_SPECS, CONFIGURE_SPECS, GOMP_SELF_SPECS, GTM_SELF_SPECS |
953ff289 | 851 | }; |
db36994b | 852 | |
7816bea0 DJ |
853 | #ifndef OPTION_DEFAULT_SPECS |
854 | #define OPTION_DEFAULT_SPECS { "", "" } | |
855 | #endif | |
856 | ||
857 | struct default_spec | |
858 | { | |
859 | const char *name; | |
860 | const char *spec; | |
861 | }; | |
862 | ||
863 | static const struct default_spec | |
864 | option_default_specs[] = { OPTION_DEFAULT_SPECS }; | |
865 | ||
3ac63d94 NC |
866 | struct user_specs |
867 | { | |
d9ac3a07 | 868 | struct user_specs *next; |
878f32c3 | 869 | const char *filename; |
d9ac3a07 MM |
870 | }; |
871 | ||
872 | static struct user_specs *user_specs_head, *user_specs_tail; | |
873 | ||
ed1f651b RS |
874 | \f |
875 | /* Record the mapping from file suffixes for compilation specs. */ | |
876 | ||
877 | struct compiler | |
878 | { | |
878f32c3 | 879 | const char *suffix; /* Use this compiler for input files |
ed1f651b | 880 | whose names end in this suffix. */ |
ec32609a | 881 | |
ea414c97 | 882 | const char *spec; /* To use this compiler, run this spec. */ |
a9374841 MM |
883 | |
884 | const char *cpp_spec; /* If non-NULL, substitute this spec | |
885 | for `%C', rather than the usual | |
886 | cpp_spec. */ | |
1ea7e6ad | 887 | const int combinable; /* If nonzero, compiler can deal with |
0855eab7 | 888 | multiple source files at once (IMA). */ |
1ea7e6ad | 889 | const int needs_preprocessing; /* If nonzero, source files need to |
0855eab7 | 890 | be run through a preprocessor. */ |
ed1f651b RS |
891 | }; |
892 | ||
893 | /* Pointer to a vector of `struct compiler' that gives the spec for | |
894 | compiling a file, based on its suffix. | |
895 | A file that does not end in any of these suffixes will be passed | |
896 | unchanged to the loader and nothing else will be done to it. | |
897 | ||
898 | An entry containing two 0s is used to terminate the vector. | |
899 | ||
900 | If multiple entries match a file, the last matching one is used. */ | |
901 | ||
902 | static struct compiler *compilers; | |
903 | ||
904 | /* Number of entries in `compilers', not counting the null terminator. */ | |
905 | ||
906 | static int n_compilers; | |
907 | ||
908 | /* The default list of file name suffixes and their compilation specs. */ | |
909 | ||
5e65297b | 910 | static const struct compiler default_compilers[] = |
ed1f651b | 911 | { |
4689ad58 | 912 | /* Add lists of suffixes of known languages here. If those languages |
e9a25f70 JL |
913 | were not present when we built the driver, we will hit these copies |
914 | and be given a more meaningful error than "file not used since | |
4689ad58 | 915 | linking is not done". */ |
0855eab7 | 916 | {".m", "#Objective-C", 0, 0, 0}, {".mi", "#Objective-C", 0, 0, 0}, |
ad8c162b ZL |
917 | {".mm", "#Objective-C++", 0, 0, 0}, {".M", "#Objective-C++", 0, 0, 0}, |
918 | {".mii", "#Objective-C++", 0, 0, 0}, | |
7904f95f EC |
919 | {".cc", "#C++", 0, 0, 0}, {".cxx", "#C++", 0, 0, 0}, |
920 | {".cpp", "#C++", 0, 0, 0}, {".cp", "#C++", 0, 0, 0}, | |
0855eab7 CT |
921 | {".c++", "#C++", 0, 0, 0}, {".C", "#C++", 0, 0, 0}, |
922 | {".CPP", "#C++", 0, 0, 0}, {".ii", "#C++", 0, 0, 0}, | |
923 | {".ads", "#Ada", 0, 0, 0}, {".adb", "#Ada", 0, 0, 0}, | |
3135ce84 FXC |
924 | {".f", "#Fortran", 0, 0, 0}, {".F", "#Fortran", 0, 0, 0}, |
925 | {".for", "#Fortran", 0, 0, 0}, {".FOR", "#Fortran", 0, 0, 0}, | |
926 | {".ftn", "#Fortran", 0, 0, 0}, {".FTN", "#Fortran", 0, 0, 0}, | |
927 | {".fpp", "#Fortran", 0, 0, 0}, {".FPP", "#Fortran", 0, 0, 0}, | |
928 | {".f90", "#Fortran", 0, 0, 0}, {".F90", "#Fortran", 0, 0, 0}, | |
929 | {".f95", "#Fortran", 0, 0, 0}, {".F95", "#Fortran", 0, 0, 0}, | |
930 | {".f03", "#Fortran", 0, 0, 0}, {".F03", "#Fortran", 0, 0, 0}, | |
931 | {".f08", "#Fortran", 0, 0, 0}, {".F08", "#Fortran", 0, 0, 0}, | |
0855eab7 CT |
932 | {".r", "#Ratfor", 0, 0, 0}, |
933 | {".p", "#Pascal", 0, 0, 0}, {".pas", "#Pascal", 0, 0, 0}, | |
934 | {".java", "#Java", 0, 0, 0}, {".class", "#Java", 0, 0, 0}, | |
935 | {".zip", "#Java", 0, 0, 0}, {".jar", "#Java", 0, 0, 0}, | |
7a938933 | 936 | {".go", "#Go", 0, 1, 0}, |
4689ad58 | 937 | /* Next come the entries for C. */ |
c3224d6f | 938 | {".c", "@c", 0, 0, 1}, |
ed1f651b | 939 | {"@c", |
5a8e2650 | 940 | /* cc1 has an integrated ISO C preprocessor. We should invoke the |
f458d1d5 | 941 | external preprocessor if -save-temps is given. */ |
f749a36b | 942 | "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\ |
5a8e2650 | 943 | %{!E:%{!M:%{!MM:\ |
3028a95c | 944 | %{traditional:\ |
f458d1d5 | 945 | %eGNU C no longer supports -traditional without -E}\ |
c3224d6f RG |
946 | %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \ |
947 | %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\ | |
948 | cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \ | |
949 | %(cc1_options)}\ | |
950 | %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\ | |
951 | cc1 %(cpp_unique_options) %(cc1_options)}}}\ | |
952 | %{!fsyntax-only:%(invoke_as)}}}}", 0, 0, 1}, | |
ed1f651b | 953 | {"-", |
6ba40dd7 | 954 | "%{!E:%e-E or -x required when input is from standard input}\ |
0855eab7 CT |
955 | %(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)", 0, 0, 0}, |
956 | {".h", "@c-header", 0, 0, 0}, | |
ed1f651b | 957 | {"@c-header", |
17211ab5 GK |
958 | /* cc1 has an integrated ISO C preprocessor. We should invoke the |
959 | external preprocessor if -save-temps is given. */ | |
960 | "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\ | |
961 | %{!E:%{!M:%{!MM:\ | |
14fdc613 MM |
962 | %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \ |
963 | %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\ | |
964 | cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \ | |
0de12fcc | 965 | %(cc1_options)\ |
9cc54940 AC |
966 | %{!fdump-ada-spec*:-o %g.s %{!o*:--output-pch=%i.gch}\ |
967 | %W{o*:--output-pch=%*}}%V}\ | |
14fdc613 | 968 | %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\ |
17211ab5 | 969 | cc1 %(cpp_unique_options) %(cc1_options)\ |
9cc54940 AC |
970 | %{!fdump-ada-spec*:-o %g.s %{!o*:--output-pch=%i.gch}\ |
971 | %W{o*:--output-pch=%*}}%V}}}}}}", 0, 0, 0}, | |
c3224d6f | 972 | {".i", "@cpp-output", 0, 0, 0}, |
ed1f651b | 973 | {"@cpp-output", |
ca3da783 | 974 | "%{!M:%{!MM:%{!E:cc1 -fpreprocessed %i %(cc1_options) %{!fsyntax-only:%(invoke_as)}}}}", 0, 0, 0}, |
a0d43bac | 975 | {".s", "@assembler", 0, 0, 0}, |
ed1f651b | 976 | {"@assembler", |
a0d43bac JZ |
977 | "%{!M:%{!MM:%{!E:%{!S:as %(asm_debug) %(asm_options) %i %A }}}}", 0, 0, 0}, |
978 | {".sx", "@assembler-with-cpp", 0, 0, 0}, | |
979 | {".S", "@assembler-with-cpp", 0, 0, 0}, | |
ed1f651b | 980 | {"@assembler-with-cpp", |
4977bab6 | 981 | #ifdef AS_NEEDS_DASH_FOR_PIPED_INPUT |
2710d6d7 | 982 | "%(trad_capable_cpp) -lang-asm %(cpp_options) -fno-directives-only\ |
8b968bd1 | 983 | %{E|M|MM:%(cpp_debug_options)}\ |
4977bab6 ZW |
984 | %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\ |
985 | as %(asm_debug) %(asm_options) %|.s %A }}}}" | |
986 | #else | |
2710d6d7 | 987 | "%(trad_capable_cpp) -lang-asm %(cpp_options) -fno-directives-only\ |
4977bab6 ZW |
988 | %{E|M|MM:%(cpp_debug_options)}\ |
989 | %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\ | |
990 | as %(asm_debug) %(asm_options) %m.s %A }}}}" | |
991 | #endif | |
a0d43bac | 992 | , 0, 0, 0}, |
1d088dee | 993 | |
1346ae41 | 994 | #include "specs.h" |
f9da5064 | 995 | /* Mark end of table. */ |
0855eab7 | 996 | {0, 0, 0, 0, 0} |
ed1f651b RS |
997 | }; |
998 | ||
999 | /* Number of elements in default_compilers, not counting the terminator. */ | |
1000 | ||
ca7558fc | 1001 | static const int n_default_compilers = ARRAY_SIZE (default_compilers) - 1; |
ed1f651b | 1002 | |
69d540bd NF |
1003 | typedef char *char_p; /* For DEF_VEC_P. */ |
1004 | DEF_VEC_P(char_p); | |
1005 | DEF_VEC_ALLOC_P(char_p,heap); | |
1006 | ||
ed1f651b | 1007 | /* A vector of options to give to the linker. |
368dfd3a | 1008 | These options are accumulated by %x, |
ed1f651b | 1009 | and substituted into the linker command with %X. */ |
69d540bd | 1010 | static VEC(char_p,heap) *linker_options; |
c9ebacb8 RS |
1011 | |
1012 | /* A vector of options to give to the assembler. | |
1013 | These options are accumulated by -Wa, | |
57cb9b60 | 1014 | and substituted into the assembler command with %Y. */ |
69d540bd | 1015 | static VEC(char_p,heap) *assembler_options; |
57cb9b60 JW |
1016 | |
1017 | /* A vector of options to give to the preprocessor. | |
1018 | These options are accumulated by -Wp, | |
1019 | and substituted into the preprocessor command with %Z. */ | |
69d540bd | 1020 | static VEC(char_p,heap) *preprocessor_options; |
ed1f651b | 1021 | \f |
ed1f651b | 1022 | static char * |
1d088dee | 1023 | skip_whitespace (char *p) |
ed1f651b RS |
1024 | { |
1025 | while (1) | |
1026 | { | |
1027 | /* A fully-blank line is a delimiter in the SPEC file and shouldn't | |
1028 | be considered whitespace. */ | |
1029 | if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n') | |
1030 | return p + 1; | |
1031 | else if (*p == '\n' || *p == ' ' || *p == '\t') | |
1032 | p++; | |
1033 | else if (*p == '#') | |
1034 | { | |
d25a45d4 KH |
1035 | while (*p != '\n') |
1036 | p++; | |
ed1f651b RS |
1037 | p++; |
1038 | } | |
1039 | else | |
1040 | break; | |
1041 | } | |
1042 | ||
1043 | return p; | |
1044 | } | |
2296d164 RK |
1045 | /* Structures to keep track of prefixes to try when looking for files. */ |
1046 | ||
1047 | struct prefix_list | |
1048 | { | |
8060c8ee | 1049 | const char *prefix; /* String to prepend to the path. */ |
2296d164 RK |
1050 | struct prefix_list *next; /* Next in linked list. */ |
1051 | int require_machine_suffix; /* Don't use without machine_suffix. */ | |
1052 | /* 2 means try both machine_suffix and just_machine_suffix. */ | |
5bbcd587 JJ |
1053 | int priority; /* Sort key - priority within list. */ |
1054 | int os_multilib; /* 1 if OS multilib scheme should be used, | |
1055 | 0 for GCC multilib scheme. */ | |
2296d164 RK |
1056 | }; |
1057 | ||
1058 | struct path_prefix | |
1059 | { | |
1060 | struct prefix_list *plist; /* List of prefixes to try */ | |
1061 | int max_len; /* Max length of a prefix in PLIST */ | |
1062 | const char *name; /* Name of this list (used in config stuff) */ | |
1063 | }; | |
1064 | ||
1065 | /* List of prefixes to try when looking for executables. */ | |
1066 | ||
1067 | static struct path_prefix exec_prefixes = { 0, 0, "exec" }; | |
1068 | ||
1069 | /* List of prefixes to try when looking for startup (crt0) files. */ | |
1070 | ||
1071 | static struct path_prefix startfile_prefixes = { 0, 0, "startfile" }; | |
1072 | ||
1073 | /* List of prefixes to try when looking for include files. */ | |
1074 | ||
1075 | static struct path_prefix include_prefixes = { 0, 0, "include" }; | |
1076 | ||
1077 | /* Suffix to attach to directories searched for commands. | |
1078 | This looks like `MACHINE/VERSION/'. */ | |
1079 | ||
1080 | static const char *machine_suffix = 0; | |
1081 | ||
1082 | /* Suffix to attach to directories searched for commands. | |
1083 | This is just `MACHINE/'. */ | |
1084 | ||
1085 | static const char *just_machine_suffix = 0; | |
1086 | ||
1087 | /* Adjusted value of GCC_EXEC_PREFIX envvar. */ | |
1088 | ||
1089 | static const char *gcc_exec_prefix; | |
1090 | ||
a8ee6e2d GK |
1091 | /* Adjusted value of standard_libexec_prefix. */ |
1092 | ||
1093 | static const char *gcc_libexec_prefix; | |
1094 | ||
2296d164 RK |
1095 | /* Default prefixes to attach to command names. */ |
1096 | ||
656c7a3a AL |
1097 | #ifndef STANDARD_STARTFILE_PREFIX_1 |
1098 | #define STANDARD_STARTFILE_PREFIX_1 "/lib/" | |
1099 | #endif | |
1100 | #ifndef STANDARD_STARTFILE_PREFIX_2 | |
1101 | #define STANDARD_STARTFILE_PREFIX_2 "/usr/lib/" | |
1102 | #endif | |
7904f95f | 1103 | |
2989d30c | 1104 | #ifdef CROSS_DIRECTORY_STRUCTURE /* Don't use these prefixes for a cross compiler. */ |
2296d164 RK |
1105 | #undef MD_EXEC_PREFIX |
1106 | #undef MD_STARTFILE_PREFIX | |
1107 | #undef MD_STARTFILE_PREFIX_1 | |
1108 | #endif | |
1109 | ||
1110 | /* If no prefixes defined, use the null string, which will disable them. */ | |
1111 | #ifndef MD_EXEC_PREFIX | |
1112 | #define MD_EXEC_PREFIX "" | |
1113 | #endif | |
1114 | #ifndef MD_STARTFILE_PREFIX | |
1115 | #define MD_STARTFILE_PREFIX "" | |
1116 | #endif | |
1117 | #ifndef MD_STARTFILE_PREFIX_1 | |
1118 | #define MD_STARTFILE_PREFIX_1 "" | |
1119 | #endif | |
1120 | ||
f4c0a303 CD |
1121 | /* These directories are locations set at configure-time based on the |
1122 | --prefix option provided to configure. Their initializers are | |
1123 | defined in Makefile.in. These paths are not *directly* used when | |
1124 | gcc_exec_prefix is set because, in that case, we know where the | |
1125 | compiler has been installed, and use paths relative to that | |
1126 | location instead. */ | |
27c38fbe | 1127 | static const char *const standard_exec_prefix = STANDARD_EXEC_PREFIX; |
f4c0a303 CD |
1128 | static const char *const standard_libexec_prefix = STANDARD_LIBEXEC_PREFIX; |
1129 | static const char *const standard_bindir_prefix = STANDARD_BINDIR_PREFIX; | |
1130 | static const char *const standard_startfile_prefix = STANDARD_STARTFILE_PREFIX; | |
1131 | ||
1132 | /* For native compilers, these are well-known paths containing | |
1133 | components that may be provided by the system. For cross | |
1134 | compilers, these paths are not used. */ | |
2296d164 | 1135 | static const char *md_exec_prefix = MD_EXEC_PREFIX; |
2296d164 RK |
1136 | static const char *md_startfile_prefix = MD_STARTFILE_PREFIX; |
1137 | static const char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1; | |
c662432e | 1138 | static const char *const standard_startfile_prefix_1 |
656c7a3a AL |
1139 | = STANDARD_STARTFILE_PREFIX_1; |
1140 | static const char *const standard_startfile_prefix_2 | |
1141 | = STANDARD_STARTFILE_PREFIX_2; | |
2296d164 | 1142 | |
f4c0a303 CD |
1143 | /* A relative path to be used in finding the location of tools |
1144 | relative to the driver. */ | |
27c38fbe | 1145 | static const char *const tooldir_base_prefix = TOOLDIR_BASE_PREFIX; |
a8ee6e2d | 1146 | |
2296d164 RK |
1147 | /* Subdirectory to use for locating libraries. Set by |
1148 | set_multilib_dir based on the compilation options. */ | |
1149 | ||
1150 | static const char *multilib_dir; | |
5bbcd587 JJ |
1151 | |
1152 | /* Subdirectory to use for locating libraries in OS conventions. Set by | |
1153 | set_multilib_dir based on the compilation options. */ | |
1154 | ||
1155 | static const char *multilib_os_dir; | |
ed1f651b | 1156 | \f |
0f41302f | 1157 | /* Structure to keep track of the specs that have been defined so far. |
3ce9f090 JM |
1158 | These are accessed using %(specname) in a compiler or link |
1159 | spec. */ | |
ed1f651b RS |
1160 | |
1161 | struct spec_list | |
1162 | { | |
79aff5ac MM |
1163 | /* The following 2 fields must be first */ |
1164 | /* to allow EXTRA_SPECS to be initialized */ | |
3b304f5b ZW |
1165 | const char *name; /* name of the spec. */ |
1166 | const char *ptr; /* available ptr if no static pointer */ | |
79aff5ac MM |
1167 | |
1168 | /* The following fields are not initialized */ | |
1169 | /* by EXTRA_SPECS */ | |
3b304f5b | 1170 | const char **ptr_spec; /* pointer to the spec itself. */ |
79aff5ac MM |
1171 | struct spec_list *next; /* Next spec in linked list. */ |
1172 | int name_len; /* length of the name */ | |
1173 | int alloc_p; /* whether string was allocated */ | |
ed1f651b RS |
1174 | }; |
1175 | ||
79aff5ac | 1176 | #define INIT_STATIC_SPEC(NAME,PTR) \ |
6496a589 | 1177 | { NAME, NULL, PTR, (struct spec_list *) 0, sizeof (NAME) - 1, 0 } |
79aff5ac | 1178 | |
3ac63d94 NC |
1179 | /* List of statically defined specs. */ |
1180 | static struct spec_list static_specs[] = | |
1181 | { | |
79aff5ac | 1182 | INIT_STATIC_SPEC ("asm", &asm_spec), |
5f0e9ea2 | 1183 | INIT_STATIC_SPEC ("asm_debug", &asm_debug), |
79aff5ac | 1184 | INIT_STATIC_SPEC ("asm_final", &asm_final_spec), |
ea414c97 | 1185 | INIT_STATIC_SPEC ("asm_options", &asm_options), |
5a8e2650 | 1186 | INIT_STATIC_SPEC ("invoke_as", &invoke_as), |
79aff5ac | 1187 | INIT_STATIC_SPEC ("cpp", &cpp_spec), |
ea414c97 | 1188 | INIT_STATIC_SPEC ("cpp_options", &cpp_options), |
8b968bd1 | 1189 | INIT_STATIC_SPEC ("cpp_debug_options", &cpp_debug_options), |
ffdeea47 | 1190 | INIT_STATIC_SPEC ("cpp_unique_options", &cpp_unique_options), |
ea414c97 | 1191 | INIT_STATIC_SPEC ("trad_capable_cpp", &trad_capable_cpp), |
79aff5ac | 1192 | INIT_STATIC_SPEC ("cc1", &cc1_spec), |
ea414c97 | 1193 | INIT_STATIC_SPEC ("cc1_options", &cc1_options), |
79aff5ac | 1194 | INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec), |
bbd7687d | 1195 | INIT_STATIC_SPEC ("link_gcc_c_sequence", &link_gcc_c_sequence_spec), |
77008252 | 1196 | INIT_STATIC_SPEC ("link_ssp", &link_ssp_spec), |
79aff5ac MM |
1197 | INIT_STATIC_SPEC ("endfile", &endfile_spec), |
1198 | INIT_STATIC_SPEC ("link", &link_spec), | |
1199 | INIT_STATIC_SPEC ("lib", &lib_spec), | |
6de9cd9a DN |
1200 | INIT_STATIC_SPEC ("mfwrap", &mfwrap_spec), |
1201 | INIT_STATIC_SPEC ("mflib", &mflib_spec), | |
953ff289 | 1202 | INIT_STATIC_SPEC ("link_gomp", &link_gomp_spec), |
79aff5ac MM |
1203 | INIT_STATIC_SPEC ("libgcc", &libgcc_spec), |
1204 | INIT_STATIC_SPEC ("startfile", &startfile_spec), | |
79aff5ac MM |
1205 | INIT_STATIC_SPEC ("cross_compile", &cross_compile), |
1206 | INIT_STATIC_SPEC ("version", &compiler_version), | |
1207 | INIT_STATIC_SPEC ("multilib", &multilib_select), | |
1208 | INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults), | |
1209 | INIT_STATIC_SPEC ("multilib_extra", &multilib_extra), | |
1210 | INIT_STATIC_SPEC ("multilib_matches", &multilib_matches), | |
0a8d6618 | 1211 | INIT_STATIC_SPEC ("multilib_exclusions", &multilib_exclusions), |
5bbcd587 | 1212 | INIT_STATIC_SPEC ("multilib_options", &multilib_options), |
10da1131 | 1213 | INIT_STATIC_SPEC ("linker", &linker_name_spec), |
d7f09764 DN |
1214 | INIT_STATIC_SPEC ("linker_plugin_file", &linker_plugin_file_spec), |
1215 | INIT_STATIC_SPEC ("lto_wrapper", <o_wrapper_spec), | |
1216 | INIT_STATIC_SPEC ("lto_gcc", <o_gcc_spec), | |
ea414c97 | 1217 | INIT_STATIC_SPEC ("link_libgcc", &link_libgcc_spec), |
2296d164 RK |
1218 | INIT_STATIC_SPEC ("md_exec_prefix", &md_exec_prefix), |
1219 | INIT_STATIC_SPEC ("md_startfile_prefix", &md_startfile_prefix), | |
1220 | INIT_STATIC_SPEC ("md_startfile_prefix_1", &md_startfile_prefix_1), | |
343f59d9 | 1221 | INIT_STATIC_SPEC ("startfile_prefix_spec", &startfile_prefix_spec), |
380e5ca4 | 1222 | INIT_STATIC_SPEC ("sysroot_spec", &sysroot_spec), |
e7f13528 GP |
1223 | INIT_STATIC_SPEC ("sysroot_suffix_spec", &sysroot_suffix_spec), |
1224 | INIT_STATIC_SPEC ("sysroot_hdrs_suffix_spec", &sysroot_hdrs_suffix_spec), | |
84f405a1 | 1225 | INIT_STATIC_SPEC ("self_spec", &self_spec), |
79aff5ac MM |
1226 | }; |
1227 | ||
1228 | #ifdef EXTRA_SPECS /* additional specs needed */ | |
829245be | 1229 | /* Structure to keep track of just the first two args of a spec_list. |
3ac63d94 | 1230 | That is all that the EXTRA_SPECS macro gives us. */ |
829245be KG |
1231 | struct spec_list_1 |
1232 | { | |
8b60264b KG |
1233 | const char *const name; |
1234 | const char *const ptr; | |
829245be KG |
1235 | }; |
1236 | ||
8b60264b | 1237 | static const struct spec_list_1 extra_specs_1[] = { EXTRA_SPECS }; |
d25a45d4 | 1238 | static struct spec_list *extra_specs = (struct spec_list *) 0; |
79aff5ac MM |
1239 | #endif |
1240 | ||
1241 | /* List of dynamically allocates specs that have been defined so far. */ | |
1242 | ||
9218435e | 1243 | static struct spec_list *specs = (struct spec_list *) 0; |
79aff5ac | 1244 | \f |
f3226a90 JT |
1245 | /* List of static spec functions. */ |
1246 | ||
1247 | static const struct spec_function static_spec_functions[] = | |
1248 | { | |
30d8946b | 1249 | { "getenv", getenv_spec_function }, |
f3226a90 | 1250 | { "if-exists", if_exists_spec_function }, |
152a5a9c | 1251 | { "if-exists-else", if_exists_else_spec_function }, |
3dd53121 | 1252 | { "replace-outfile", replace_outfile_spec_function }, |
2642f659 | 1253 | { "remove-outfile", remove_outfile_spec_function }, |
ed5b9f96 | 1254 | { "version-compare", version_compare_spec_function }, |
953ff289 | 1255 | { "include", include_spec_function }, |
4adbd5dd | 1256 | { "find-file", find_file_spec_function }, |
c1ce46a5 | 1257 | { "find-plugindir", find_plugindir_spec_function }, |
a0f87454 | 1258 | { "print-asm-header", print_asm_header_spec_function }, |
2153915d AO |
1259 | { "compare-debug-dump-opt", compare_debug_dump_opt_spec_function }, |
1260 | { "compare-debug-self-opt", compare_debug_self_opt_spec_function }, | |
1261 | { "compare-debug-auxbase-opt", compare_debug_auxbase_opt_spec_function }, | |
9a37bc07 | 1262 | { "pass-through-libs", pass_through_libs_spec_func }, |
fa959ce4 MM |
1263 | #ifdef EXTRA_SPEC_FUNCTIONS |
1264 | EXTRA_SPEC_FUNCTIONS | |
1265 | #endif | |
f3226a90 JT |
1266 | { 0, 0 } |
1267 | }; | |
1268 | ||
1269 | static int processing_spec_function; | |
1270 | \f | |
049f6ec9 MM |
1271 | /* Add appropriate libgcc specs to OBSTACK, taking into account |
1272 | various permutations of -shared-libgcc, -shared, and such. */ | |
1273 | ||
328163dc | 1274 | #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC) |
8efcd34f AM |
1275 | |
1276 | #ifndef USE_LD_AS_NEEDED | |
1277 | #define USE_LD_AS_NEEDED 0 | |
1278 | #endif | |
1279 | ||
049f6ec9 | 1280 | static void |
1d088dee AJ |
1281 | init_gcc_specs (struct obstack *obstack, const char *shared_name, |
1282 | const char *static_name, const char *eh_name) | |
049f6ec9 | 1283 | { |
5c181756 AO |
1284 | char *buf; |
1285 | ||
5e4f1974 AM |
1286 | buf = concat ("%{static|static-libgcc:", static_name, " ", eh_name, "}" |
1287 | "%{!static:%{!static-libgcc:" | |
8efcd34f | 1288 | #if USE_LD_AS_NEEDED |
5e4f1974 AM |
1289 | "%{!shared-libgcc:", |
1290 | static_name, " --as-needed ", shared_name, " --no-as-needed" | |
1291 | "}" | |
1292 | "%{shared-libgcc:", | |
1293 | shared_name, "%{!shared: ", static_name, "}" | |
1294 | "}" | |
765f1bf9 | 1295 | #else |
5e4f1974 AM |
1296 | "%{!shared:" |
1297 | "%{!shared-libgcc:", static_name, " ", eh_name, "}" | |
1298 | "%{shared-libgcc:", shared_name, " ", static_name, "}" | |
1299 | "}" | |
275b60d6 | 1300 | #ifdef LINK_EH_SPEC |
5e4f1974 AM |
1301 | "%{shared:" |
1302 | "%{shared-libgcc:", shared_name, "}" | |
1303 | "%{!shared-libgcc:", static_name, "}" | |
1304 | "}" | |
275b60d6 | 1305 | #else |
5e4f1974 | 1306 | "%{shared:", shared_name, "}" |
765f1bf9 | 1307 | #endif |
275b60d6 | 1308 | #endif |
5e4f1974 | 1309 | "}}", NULL); |
5c181756 AO |
1310 | |
1311 | obstack_grow (obstack, buf, strlen (buf)); | |
1312 | free (buf); | |
049f6ec9 | 1313 | } |
6894579f | 1314 | #endif /* ENABLE_SHARED_LIBGCC */ |
049f6ec9 | 1315 | |
79aff5ac MM |
1316 | /* Initialize the specs lookup routines. */ |
1317 | ||
1318 | static void | |
7e51717c | 1319 | init_spec (void) |
79aff5ac | 1320 | { |
9218435e KH |
1321 | struct spec_list *next = (struct spec_list *) 0; |
1322 | struct spec_list *sl = (struct spec_list *) 0; | |
79aff5ac MM |
1323 | int i; |
1324 | ||
1325 | if (specs) | |
3ac63d94 | 1326 | return; /* Already initialized. */ |
79aff5ac | 1327 | |
20df0482 | 1328 | if (verbose_flag) |
2dec80c7 | 1329 | fnotice (stderr, "Using built-in specs.\n"); |
20df0482 | 1330 | |
79aff5ac | 1331 | #ifdef EXTRA_SPECS |
e1e4cdc4 | 1332 | extra_specs = XCNEWVEC (struct spec_list, ARRAY_SIZE (extra_specs_1)); |
9218435e | 1333 | |
b6a1cbae | 1334 | for (i = ARRAY_SIZE (extra_specs_1) - 1; i >= 0; i--) |
03fc1620 JW |
1335 | { |
1336 | sl = &extra_specs[i]; | |
829245be KG |
1337 | sl->name = extra_specs_1[i].name; |
1338 | sl->ptr = extra_specs_1[i].ptr; | |
03fc1620 JW |
1339 | sl->next = next; |
1340 | sl->name_len = strlen (sl->name); | |
1341 | sl->ptr_spec = &sl->ptr; | |
1342 | next = sl; | |
1343 | } | |
79aff5ac MM |
1344 | #endif |
1345 | ||
b6a1cbae | 1346 | for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--) |
79aff5ac MM |
1347 | { |
1348 | sl = &static_specs[i]; | |
1349 | sl->next = next; | |
1350 | next = sl; | |
1351 | } | |
1352 | ||
328163dc | 1353 | #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC) |
9db0819e RH |
1354 | /* ??? If neither -shared-libgcc nor --static-libgcc was |
1355 | seen, then we should be making an educated guess. Some proposed | |
1356 | heuristics for ELF include: | |
1357 | ||
1358 | (1) If "-Wl,--export-dynamic", then it's a fair bet that the | |
1359 | program will be doing dynamic loading, which will likely | |
1360 | need the shared libgcc. | |
1361 | ||
1362 | (2) If "-ldl", then it's also a fair bet that we're doing | |
1363 | dynamic loading. | |
1364 | ||
1365 | (3) For each ET_DYN we're linking against (either through -lfoo | |
1366 | or /some/path/foo.so), check to see whether it or one of | |
ff7cc307 | 1367 | its dependencies depends on a shared libgcc. |
9db0819e RH |
1368 | |
1369 | (4) If "-shared" | |
1370 | ||
1371 | If the runtime is fixed to look for program headers instead | |
1372 | of calling __register_frame_info at all, for each object, | |
1373 | use the shared libgcc if any EH symbol referenced. | |
1374 | ||
1375 | If crtstuff is fixed to not invoke __register_frame_info | |
1376 | automatically, for each object, use the shared libgcc if | |
1377 | any non-empty unwind section found. | |
1378 | ||
1379 | Doing any of this probably requires invoking an external program to | |
1380 | do the actual object file scanning. */ | |
1381 | { | |
1382 | const char *p = libgcc_spec; | |
1383 | int in_sep = 1; | |
589005ff | 1384 | |
16757495 | 1385 | /* Transform the extant libgcc_spec into one that uses the shared libgcc |
9db0819e RH |
1386 | when given the proper command line arguments. */ |
1387 | while (*p) | |
1388 | { | |
589005ff | 1389 | if (in_sep && *p == '-' && strncmp (p, "-lgcc", 5) == 0) |
9db0819e | 1390 | { |
049f6ec9 | 1391 | init_gcc_specs (&obstack, |
049f6ec9 | 1392 | "-lgcc_s" |
443728bb L |
1393 | #ifdef USE_LIBUNWIND_EXCEPTIONS |
1394 | " -lunwind" | |
4977bab6 | 1395 | #endif |
348d71c7 JW |
1396 | , |
1397 | "-lgcc", | |
1398 | "-lgcc_eh" | |
4977bab6 | 1399 | #ifdef USE_LIBUNWIND_EXCEPTIONS |
7e9d8517 | 1400 | # ifdef HAVE_LD_STATIC_DYNAMIC |
c6092243 RO |
1401 | " %{!static:" LD_STATIC_OPTION "} -lunwind" |
1402 | " %{!static:" LD_DYNAMIC_OPTION "}" | |
7e9d8517 | 1403 | # else |
4977bab6 | 1404 | " -lunwind" |
7e9d8517 | 1405 | # endif |
9db0819e | 1406 | #endif |
348d71c7 JW |
1407 | ); |
1408 | ||
ba2b7435 | 1409 | p += 5; |
9db0819e RH |
1410 | in_sep = 0; |
1411 | } | |
ba2b7435 | 1412 | else if (in_sep && *p == 'l' && strncmp (p, "libgcc.a%s", 10) == 0) |
9db0819e RH |
1413 | { |
1414 | /* Ug. We don't know shared library extensions. Hope that | |
1415 | systems that use this form don't do shared libraries. */ | |
049f6ec9 | 1416 | init_gcc_specs (&obstack, |
4e8d0554 | 1417 | "-lgcc_s", |
275b60d6 | 1418 | "libgcc.a%s", |
aedec8dd JW |
1419 | "libgcc_eh.a%s" |
1420 | #ifdef USE_LIBUNWIND_EXCEPTIONS | |
1421 | " -lunwind" | |
1422 | #endif | |
1423 | ); | |
ba2b7435 | 1424 | p += 10; |
9db0819e RH |
1425 | in_sep = 0; |
1426 | } | |
1427 | else | |
1428 | { | |
1429 | obstack_1grow (&obstack, *p); | |
1430 | in_sep = (*p == ' '); | |
1431 | p += 1; | |
1432 | } | |
1433 | } | |
1434 | ||
1435 | obstack_1grow (&obstack, '\0'); | |
7973fd2a | 1436 | libgcc_spec = XOBFINISH (&obstack, const char *); |
9db0819e RH |
1437 | } |
1438 | #endif | |
c64688ae RH |
1439 | #ifdef USE_AS_TRADITIONAL_FORMAT |
1440 | /* Prepend "--traditional-format" to whatever asm_spec we had before. */ | |
1441 | { | |
8b60264b | 1442 | static const char tf[] = "--traditional-format "; |
c64688ae RH |
1443 | obstack_grow (&obstack, tf, sizeof(tf) - 1); |
1444 | obstack_grow0 (&obstack, asm_spec, strlen (asm_spec)); | |
7973fd2a | 1445 | asm_spec = XOBFINISH (&obstack, const char *); |
c64688ae RH |
1446 | } |
1447 | #endif | |
cd533689 | 1448 | |
79bec923 ST |
1449 | #if defined LINK_EH_SPEC || defined LINK_BUILDID_SPEC || \ |
1450 | defined LINKER_HASH_STYLE | |
cd533689 PP |
1451 | # ifdef LINK_BUILDID_SPEC |
1452 | /* Prepend LINK_BUILDID_SPEC to whatever link_spec we had before. */ | |
1453 | obstack_grow (&obstack, LINK_BUILDID_SPEC, sizeof(LINK_BUILDID_SPEC) - 1); | |
1454 | # endif | |
1455 | # ifdef LINK_EH_SPEC | |
275b60d6 JJ |
1456 | /* Prepend LINK_EH_SPEC to whatever link_spec we had before. */ |
1457 | obstack_grow (&obstack, LINK_EH_SPEC, sizeof(LINK_EH_SPEC) - 1); | |
79bec923 ST |
1458 | # endif |
1459 | # ifdef LINKER_HASH_STYLE | |
1460 | /* Prepend --hash-style=LINKER_HASH_STYLE to whatever link_spec we had | |
1461 | before. */ | |
1462 | { | |
1463 | static const char hash_style[] = "--hash-style="; | |
1464 | obstack_grow (&obstack, hash_style, sizeof(hash_style) - 1); | |
1465 | obstack_grow (&obstack, LINKER_HASH_STYLE, sizeof(LINKER_HASH_STYLE) - 1); | |
1466 | obstack_1grow (&obstack, ' '); | |
1467 | } | |
cd533689 | 1468 | # endif |
275b60d6 | 1469 | obstack_grow0 (&obstack, link_spec, strlen (link_spec)); |
7973fd2a | 1470 | link_spec = XOBFINISH (&obstack, const char *); |
275b60d6 | 1471 | #endif |
9db0819e | 1472 | |
79aff5ac MM |
1473 | specs = sl; |
1474 | } | |
ed1f651b RS |
1475 | \f |
1476 | /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is | |
1477 | removed; If the spec starts with a + then SPEC is added to the end of the | |
0f41302f | 1478 | current spec. */ |
ed1f651b RS |
1479 | |
1480 | static void | |
1d088dee | 1481 | set_spec (const char *name, const char *spec) |
ed1f651b RS |
1482 | { |
1483 | struct spec_list *sl; | |
3b304f5b | 1484 | const char *old_spec; |
79aff5ac MM |
1485 | int name_len = strlen (name); |
1486 | int i; | |
1487 | ||
3ac63d94 | 1488 | /* If this is the first call, initialize the statically allocated specs. */ |
20df0482 MM |
1489 | if (!specs) |
1490 | { | |
9218435e | 1491 | struct spec_list *next = (struct spec_list *) 0; |
b6a1cbae | 1492 | for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--) |
20df0482 MM |
1493 | { |
1494 | sl = &static_specs[i]; | |
1495 | sl->next = next; | |
1496 | next = sl; | |
1497 | } | |
1498 | specs = sl; | |
1499 | } | |
1500 | ||
3ac63d94 | 1501 | /* See if the spec already exists. */ |
ed1f651b | 1502 | for (sl = specs; sl; sl = sl->next) |
79aff5ac | 1503 | if (name_len == sl->name_len && !strcmp (sl->name, name)) |
ed1f651b RS |
1504 | break; |
1505 | ||
1506 | if (!sl) | |
1507 | { | |
3ac63d94 | 1508 | /* Not found - make it. */ |
5ed6ace5 | 1509 | sl = XNEW (struct spec_list); |
ad85216e | 1510 | sl->name = xstrdup (name); |
79aff5ac MM |
1511 | sl->name_len = name_len; |
1512 | sl->ptr_spec = &sl->ptr; | |
1513 | sl->alloc_p = 0; | |
1514 | *(sl->ptr_spec) = ""; | |
ed1f651b RS |
1515 | sl->next = specs; |
1516 | specs = sl; | |
1517 | } | |
1518 | ||
79aff5ac | 1519 | old_spec = *(sl->ptr_spec); |
e51712db | 1520 | *(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE ((unsigned char)spec[1])) |
d4f2852f | 1521 | ? concat (old_spec, spec + 1, NULL) |
ad85216e | 1522 | : xstrdup (spec)); |
841faeed | 1523 | |
20df0482 MM |
1524 | #ifdef DEBUG_SPECS |
1525 | if (verbose_flag) | |
2dec80c7 | 1526 | fnotice (stderr, "Setting spec %s to '%s'\n\n", name, *(sl->ptr_spec)); |
20df0482 MM |
1527 | #endif |
1528 | ||
3ac63d94 | 1529 | /* Free the old spec. */ |
79aff5ac | 1530 | if (old_spec && sl->alloc_p) |
b1d5455a | 1531 | free (CONST_CAST(char *, old_spec)); |
79aff5ac MM |
1532 | |
1533 | sl->alloc_p = 1; | |
ed1f651b RS |
1534 | } |
1535 | \f | |
1536 | /* Accumulate a command (program name and args), and run it. */ | |
1537 | ||
5b634ee0 JM |
1538 | typedef const char *const_char_p; /* For DEF_VEC_P. */ |
1539 | DEF_VEC_P(const_char_p); | |
1540 | DEF_VEC_ALLOC_P(const_char_p,heap); | |
ed1f651b | 1541 | |
5b634ee0 | 1542 | /* Vector of pointers to arguments in the current line of specifications. */ |
ed1f651b | 1543 | |
5b634ee0 | 1544 | static VEC(const_char_p,heap) *argbuf; |
ed1f651b | 1545 | |
5b634ee0 | 1546 | /* Position in the argbuf vector containing the name of the output file |
0855eab7 CT |
1547 | (the value associated with the "-o" flag). */ |
1548 | ||
1549 | static int have_o_argbuf_index = 0; | |
1550 | ||
1b5bc8e9 | 1551 | /* Were the options -c, -S or -E passed. */ |
af41c57d AP |
1552 | static int have_c = 0; |
1553 | ||
1554 | /* Was the option -o passed. */ | |
1555 | static int have_o = 0; | |
1556 | ||
49009afd JL |
1557 | /* This is the list of suffixes and codes (%g/%u/%U/%j) and the associated |
1558 | temp file. If the HOST_BIT_BUCKET is used for %j, no entry is made for | |
1559 | it here. */ | |
fb266030 TW |
1560 | |
1561 | static struct temp_name { | |
878f32c3 | 1562 | const char *suffix; /* suffix associated with the code. */ |
fb266030 TW |
1563 | int length; /* strlen (suffix). */ |
1564 | int unique; /* Indicates whether %g or %u/%U was used. */ | |
878f32c3 | 1565 | const char *filename; /* associated filename. */ |
fb266030 TW |
1566 | int filename_length; /* strlen (filename). */ |
1567 | struct temp_name *next; | |
1568 | } *temp_names; | |
39d45901 | 1569 | |
ed1f651b RS |
1570 | /* Number of commands executed so far. */ |
1571 | ||
1572 | static int execution_count; | |
1573 | ||
3b9b4d3f RS |
1574 | /* Number of commands that exited with a signal. */ |
1575 | ||
1576 | static int signal_count; | |
ed1f651b | 1577 | \f |
f3226a90 JT |
1578 | /* Allocate the argument vector. */ |
1579 | ||
1580 | static void | |
7e51717c | 1581 | alloc_args (void) |
f3226a90 | 1582 | { |
5b634ee0 | 1583 | argbuf = VEC_alloc (const_char_p, heap, 10); |
f3226a90 JT |
1584 | } |
1585 | ||
ed1f651b RS |
1586 | /* Clear out the vector of arguments (after a command is executed). */ |
1587 | ||
1588 | static void | |
1d088dee | 1589 | clear_args (void) |
ed1f651b | 1590 | { |
5b634ee0 | 1591 | VEC_truncate (const_char_p, argbuf, 0); |
ed1f651b RS |
1592 | } |
1593 | ||
1594 | /* Add one argument to the vector at the end. | |
1595 | This is done when a space is seen or at the end of the line. | |
1596 | If DELETE_ALWAYS is nonzero, the arg is a filename | |
1597 | and the file should be deleted eventually. | |
1598 | If DELETE_FAILURE is nonzero, the arg is a filename | |
1599 | and the file should be deleted if this compilation fails. */ | |
1600 | ||
1601 | static void | |
1d088dee | 1602 | store_arg (const char *arg, int delete_always, int delete_failure) |
ed1f651b | 1603 | { |
5b634ee0 | 1604 | VEC_safe_push (const_char_p, heap, argbuf, arg); |
ed1f651b | 1605 | |
0855eab7 | 1606 | if (strcmp (arg, "-o") == 0) |
5b634ee0 | 1607 | have_o_argbuf_index = VEC_length (const_char_p, argbuf); |
ed1f651b | 1608 | if (delete_always || delete_failure) |
d6205185 RG |
1609 | { |
1610 | const char *p; | |
1611 | /* If the temporary file we should delete is specified as | |
1612 | part of a joined argument extract the filename. */ | |
1613 | if (arg[0] == '-' | |
1614 | && (p = strrchr (arg, '='))) | |
1615 | arg = p + 1; | |
1616 | record_temp_file (arg, delete_always, delete_failure); | |
1617 | } | |
ed1f651b RS |
1618 | } |
1619 | \f | |
ff7cc307 | 1620 | /* Load specs from a file name named FILENAME, replacing occurrences of |
9218435e | 1621 | various different types of line-endings, \r\n, \n\r and just \r, with |
b633b6c0 | 1622 | a single \n. */ |
20df0482 | 1623 | |
d25a45d4 | 1624 | static char * |
1d088dee | 1625 | load_specs (const char *filename) |
20df0482 MM |
1626 | { |
1627 | int desc; | |
1628 | int readlen; | |
1629 | struct stat statbuf; | |
1630 | char *buffer; | |
b633b6c0 MK |
1631 | char *buffer_p; |
1632 | char *specs; | |
1633 | char *specs_p; | |
20df0482 MM |
1634 | |
1635 | if (verbose_flag) | |
2dec80c7 | 1636 | fnotice (stderr, "Reading specs from %s\n", filename); |
20df0482 MM |
1637 | |
1638 | /* Open and stat the file. */ | |
1639 | desc = open (filename, O_RDONLY, 0); | |
1640 | if (desc < 0) | |
1641 | pfatal_with_name (filename); | |
1642 | if (stat (filename, &statbuf) < 0) | |
1643 | pfatal_with_name (filename); | |
1644 | ||
1645 | /* Read contents of file into BUFFER. */ | |
5ed6ace5 | 1646 | buffer = XNEWVEC (char, statbuf.st_size + 1); |
20df0482 MM |
1647 | readlen = read (desc, buffer, (unsigned) statbuf.st_size); |
1648 | if (readlen < 0) | |
1649 | pfatal_with_name (filename); | |
1650 | buffer[readlen] = 0; | |
1651 | close (desc); | |
1652 | ||
5ed6ace5 | 1653 | specs = XNEWVEC (char, readlen + 1); |
b633b6c0 MK |
1654 | specs_p = specs; |
1655 | for (buffer_p = buffer; buffer_p && *buffer_p; buffer_p++) | |
1656 | { | |
1657 | int skip = 0; | |
1658 | char c = *buffer_p; | |
1659 | if (c == '\r') | |
d25a45d4 KH |
1660 | { |
1661 | if (buffer_p > buffer && *(buffer_p - 1) == '\n') /* \n\r */ | |
b633b6c0 | 1662 | skip = 1; |
d25a45d4 | 1663 | else if (*(buffer_p + 1) == '\n') /* \r\n */ |
b633b6c0 MK |
1664 | skip = 1; |
1665 | else /* \r */ | |
1666 | c = '\n'; | |
1667 | } | |
1668 | if (! skip) | |
1669 | *specs_p++ = c; | |
1670 | } | |
1671 | *specs_p = '\0'; | |
1672 | ||
1673 | free (buffer); | |
1674 | return (specs); | |
1675 | } | |
1676 | ||
1677 | /* Read compilation specs from a file named FILENAME, | |
1678 | replacing the default ones. | |
1679 | ||
1680 | A suffix which starts with `*' is a definition for | |
1681 | one of the machine-specific sub-specs. The "suffix" should be | |
0fef3fd0 | 1682 | *asm, *cc1, *cpp, *link, *startfile, etc. |
b633b6c0 MK |
1683 | The corresponding spec is stored in asm_spec, etc., |
1684 | rather than in the `compilers' vector. | |
1685 | ||
1686 | Anything invalid in the file is a fatal error. */ | |
1687 | ||
1688 | static void | |
1d088dee | 1689 | read_specs (const char *filename, int main_p) |
b633b6c0 MK |
1690 | { |
1691 | char *buffer; | |
b3694847 | 1692 | char *p; |
b633b6c0 MK |
1693 | |
1694 | buffer = load_specs (filename); | |
1695 | ||
20df0482 MM |
1696 | /* Scan BUFFER for specs, putting them in the vector. */ |
1697 | p = buffer; | |
1698 | while (1) | |
1699 | { | |
1700 | char *suffix; | |
1701 | char *spec; | |
1702 | char *in, *out, *p1, *p2, *p3; | |
1703 | ||
1704 | /* Advance P in BUFFER to the next nonblank nocomment line. */ | |
1705 | p = skip_whitespace (p); | |
1706 | if (*p == 0) | |
1707 | break; | |
1708 | ||
1709 | /* Is this a special command that starts with '%'? */ | |
1710 | /* Don't allow this for the main specs file, since it would | |
1711 | encourage people to overwrite it. */ | |
1712 | if (*p == '%' && !main_p) | |
1713 | { | |
1714 | p1 = p; | |
e9a25f70 JL |
1715 | while (*p && *p != '\n') |
1716 | p++; | |
1717 | ||
d25a45d4 KH |
1718 | /* Skip '\n'. */ |
1719 | p++; | |
20df0482 | 1720 | |
d25a45d4 | 1721 | if (!strncmp (p1, "%include", sizeof ("%include") - 1) |
e9a25f70 JL |
1722 | && (p1[sizeof "%include" - 1] == ' ' |
1723 | || p1[sizeof "%include" - 1] == '\t')) | |
20df0482 MM |
1724 | { |
1725 | char *new_filename; | |
1726 | ||
1727 | p1 += sizeof ("%include"); | |
e9a25f70 JL |
1728 | while (*p1 == ' ' || *p1 == '\t') |
1729 | p1++; | |
20df0482 MM |
1730 | |
1731 | if (*p1++ != '<' || p[-2] != '>') | |
2dec80c7 JM |
1732 | fatal_error ("specs %%include syntax malformed after " |
1733 | "%ld characters", | |
1734 | (long) (p1 - buffer + 1)); | |
20df0482 MM |
1735 | |
1736 | p[-2] = '\0'; | |
00dcee0c | 1737 | new_filename = find_a_file (&startfile_prefixes, p1, R_OK, true); |
20df0482 MM |
1738 | read_specs (new_filename ? new_filename : p1, FALSE); |
1739 | continue; | |
1740 | } | |
e9a25f70 JL |
1741 | else if (!strncmp (p1, "%include_noerr", sizeof "%include_noerr" - 1) |
1742 | && (p1[sizeof "%include_noerr" - 1] == ' ' | |
1743 | || p1[sizeof "%include_noerr" - 1] == '\t')) | |
20df0482 MM |
1744 | { |
1745 | char *new_filename; | |
1746 | ||
e9a25f70 | 1747 | p1 += sizeof "%include_noerr"; |
d25a45d4 KH |
1748 | while (*p1 == ' ' || *p1 == '\t') |
1749 | p1++; | |
20df0482 MM |
1750 | |
1751 | if (*p1++ != '<' || p[-2] != '>') | |
2dec80c7 JM |
1752 | fatal_error ("specs %%include syntax malformed after " |
1753 | "%ld characters", | |
1754 | (long) (p1 - buffer + 1)); | |
20df0482 MM |
1755 | |
1756 | p[-2] = '\0'; | |
00dcee0c | 1757 | new_filename = find_a_file (&startfile_prefixes, p1, R_OK, true); |
20df0482 MM |
1758 | if (new_filename) |
1759 | read_specs (new_filename, FALSE); | |
1760 | else if (verbose_flag) | |
2dec80c7 | 1761 | fnotice (stderr, "could not find specs file %s\n", p1); |
20df0482 MM |
1762 | continue; |
1763 | } | |
e9a25f70 JL |
1764 | else if (!strncmp (p1, "%rename", sizeof "%rename" - 1) |
1765 | && (p1[sizeof "%rename" - 1] == ' ' | |
1766 | || p1[sizeof "%rename" - 1] == '\t')) | |
20df0482 MM |
1767 | { |
1768 | int name_len; | |
1769 | struct spec_list *sl; | |
169ce44d | 1770 | struct spec_list *newsl; |
20df0482 | 1771 | |
169ce44d | 1772 | /* Get original name. */ |
e9a25f70 JL |
1773 | p1 += sizeof "%rename"; |
1774 | while (*p1 == ' ' || *p1 == '\t') | |
1775 | p1++; | |
1776 | ||
9218435e | 1777 | if (! ISALPHA ((unsigned char) *p1)) |
2dec80c7 JM |
1778 | fatal_error ("specs %%rename syntax malformed after " |
1779 | "%ld characters", | |
1780 | (long) (p1 - buffer)); | |
20df0482 MM |
1781 | |
1782 | p2 = p1; | |
9218435e | 1783 | while (*p2 && !ISSPACE ((unsigned char) *p2)) |
e9a25f70 JL |
1784 | p2++; |
1785 | ||
20df0482 | 1786 | if (*p2 != ' ' && *p2 != '\t') |
2dec80c7 JM |
1787 | fatal_error ("specs %%rename syntax malformed after " |
1788 | "%ld characters", | |
1789 | (long) (p2 - buffer)); | |
20df0482 MM |
1790 | |
1791 | name_len = p2 - p1; | |
1792 | *p2++ = '\0'; | |
e9a25f70 JL |
1793 | while (*p2 == ' ' || *p2 == '\t') |
1794 | p2++; | |
1795 | ||
9218435e | 1796 | if (! ISALPHA ((unsigned char) *p2)) |
2dec80c7 JM |
1797 | fatal_error ("specs %%rename syntax malformed after " |
1798 | "%ld characters", | |
1799 | (long) (p2 - buffer)); | |
20df0482 | 1800 | |
d25a45d4 | 1801 | /* Get new spec name. */ |
20df0482 | 1802 | p3 = p2; |
9218435e | 1803 | while (*p3 && !ISSPACE ((unsigned char) *p3)) |
e9a25f70 JL |
1804 | p3++; |
1805 | ||
d25a45d4 | 1806 | if (p3 != p - 1) |
2dec80c7 JM |
1807 | fatal_error ("specs %%rename syntax malformed after " |
1808 | "%ld characters", | |
1809 | (long) (p3 - buffer)); | |
20df0482 MM |
1810 | *p3 = '\0'; |
1811 | ||
1812 | for (sl = specs; sl; sl = sl->next) | |
1813 | if (name_len == sl->name_len && !strcmp (sl->name, p1)) | |
1814 | break; | |
1815 | ||
1816 | if (!sl) | |
2dec80c7 | 1817 | fatal_error ("specs %s spec was not found to be renamed", p1); |
20df0482 | 1818 | |
e9a25f70 | 1819 | if (strcmp (p1, p2) == 0) |
20df0482 MM |
1820 | continue; |
1821 | ||
169ce44d NC |
1822 | for (newsl = specs; newsl; newsl = newsl->next) |
1823 | if (strcmp (newsl->name, p2) == 0) | |
bdc6b402 JM |
1824 | fatal_error ("%s: attempt to rename spec %qs to " |
1825 | "already defined spec %qs", | |
169ce44d NC |
1826 | filename, p1, p2); |
1827 | ||
20df0482 MM |
1828 | if (verbose_flag) |
1829 | { | |
2dec80c7 | 1830 | fnotice (stderr, "rename spec %s to %s\n", p1, p2); |
20df0482 | 1831 | #ifdef DEBUG_SPECS |
2dec80c7 | 1832 | fnotice (stderr, "spec is '%s'\n\n", *(sl->ptr_spec)); |
20df0482 MM |
1833 | #endif |
1834 | } | |
1835 | ||
1836 | set_spec (p2, *(sl->ptr_spec)); | |
1837 | if (sl->alloc_p) | |
b1d5455a | 1838 | free (CONST_CAST (char *, *(sl->ptr_spec))); |
20df0482 MM |
1839 | |
1840 | *(sl->ptr_spec) = ""; | |
1841 | sl->alloc_p = 0; | |
1842 | continue; | |
1843 | } | |
1844 | else | |
2dec80c7 JM |
1845 | fatal_error ("specs unknown %% command after %ld characters", |
1846 | (long) (p1 - buffer)); | |
20df0482 MM |
1847 | } |
1848 | ||
1849 | /* Find the colon that should end the suffix. */ | |
1850 | p1 = p; | |
e9a25f70 JL |
1851 | while (*p1 && *p1 != ':' && *p1 != '\n') |
1852 | p1++; | |
1853 | ||
20df0482 MM |
1854 | /* The colon shouldn't be missing. */ |
1855 | if (*p1 != ':') | |
2dec80c7 JM |
1856 | fatal_error ("specs file malformed after %ld characters", |
1857 | (long) (p1 - buffer)); | |
e9a25f70 | 1858 | |
20df0482 MM |
1859 | /* Skip back over trailing whitespace. */ |
1860 | p2 = p1; | |
e9a25f70 JL |
1861 | while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t')) |
1862 | p2--; | |
1863 | ||
20df0482 MM |
1864 | /* Copy the suffix to a string. */ |
1865 | suffix = save_string (p, p2 - p); | |
1866 | /* Find the next line. */ | |
1867 | p = skip_whitespace (p1 + 1); | |
1868 | if (p[1] == 0) | |
2dec80c7 JM |
1869 | fatal_error ("specs file malformed after %ld characters", |
1870 | (long) (p - buffer)); | |
e9a25f70 | 1871 | |
20df0482 | 1872 | p1 = p; |
bbeb7b65 JW |
1873 | /* Find next blank line or end of string. */ |
1874 | while (*p1 && !(*p1 == '\n' && (p1[1] == '\n' || p1[1] == '\0'))) | |
e9a25f70 JL |
1875 | p1++; |
1876 | ||
20df0482 MM |
1877 | /* Specs end at the blank line and do not include the newline. */ |
1878 | spec = save_string (p, p1 - p); | |
1879 | p = p1; | |
1880 | ||
1881 | /* Delete backslash-newline sequences from the spec. */ | |
1882 | in = spec; | |
1883 | out = spec; | |
1884 | while (*in != 0) | |
1885 | { | |
1886 | if (in[0] == '\\' && in[1] == '\n') | |
1887 | in += 2; | |
1888 | else if (in[0] == '#') | |
e9a25f70 JL |
1889 | while (*in && *in != '\n') |
1890 | in++; | |
1891 | ||
20df0482 MM |
1892 | else |
1893 | *out++ = *in++; | |
1894 | } | |
1895 | *out = 0; | |
1896 | ||
1897 | if (suffix[0] == '*') | |
1898 | { | |
1899 | if (! strcmp (suffix, "*link_command")) | |
1900 | link_command_spec = spec; | |
1901 | else | |
1902 | set_spec (suffix + 1, spec); | |
1903 | } | |
1904 | else | |
1905 | { | |
1906 | /* Add this pair to the vector. */ | |
1907 | compilers | |
e1e4cdc4 | 1908 | = XRESIZEVEC (struct compiler, compilers, n_compilers + 2); |
e9a25f70 | 1909 | |
20df0482 | 1910 | compilers[n_compilers].suffix = suffix; |
ea414c97 | 1911 | compilers[n_compilers].spec = spec; |
20df0482 | 1912 | n_compilers++; |
9257393c | 1913 | memset (&compilers[n_compilers], 0, sizeof compilers[n_compilers]); |
20df0482 MM |
1914 | } |
1915 | ||
1916 | if (*suffix == 0) | |
1917 | link_command_spec = spec; | |
1918 | } | |
1919 | ||
1920 | if (link_command_spec == 0) | |
2dec80c7 | 1921 | fatal_error ("spec file has no spec for linking"); |
20df0482 MM |
1922 | } |
1923 | \f | |
ed1f651b RS |
1924 | /* Record the names of temporary files we tell compilers to write, |
1925 | and delete them at the end of the run. */ | |
1926 | ||
aa34f42c RG |
1927 | /* This is the common prefix we use to make temp file names. |
1928 | It is chosen once for each run of this program. | |
1929 | It is substituted into a spec by %g or %j. | |
1930 | Thus, all temp file names contain this prefix. | |
1931 | In practice, all temp file names start with this prefix. | |
1932 | ||
1933 | This prefix comes from the envvar TMPDIR if it is defined; | |
1934 | otherwise, from the P_tmpdir macro if that is defined; | |
1935 | otherwise, in /usr/tmp or /tmp; | |
1936 | or finally the current directory if all else fails. */ | |
1937 | ||
1938 | static const char *temp_filename; | |
1939 | ||
1940 | /* Length of the prefix. */ | |
1941 | ||
1942 | static int temp_filename_length; | |
1943 | ||
ed1f651b RS |
1944 | /* Define the list of temporary files to delete. */ |
1945 | ||
1946 | struct temp_file | |
1947 | { | |
878f32c3 | 1948 | const char *name; |
ed1f651b RS |
1949 | struct temp_file *next; |
1950 | }; | |
1951 | ||
1952 | /* Queue of files to delete on success or failure of compilation. */ | |
1953 | static struct temp_file *always_delete_queue; | |
1954 | /* Queue of files to delete on failure of compilation. */ | |
1955 | static struct temp_file *failure_delete_queue; | |
1956 | ||
1957 | /* Record FILENAME as a file to be deleted automatically. | |
1958 | ALWAYS_DELETE nonzero means delete it if all compilation succeeds; | |
1959 | otherwise delete it in any case. | |
1960 | FAIL_DELETE nonzero means delete it if a compilation step fails; | |
1961 | otherwise delete it in any case. */ | |
1962 | ||
d991c721 | 1963 | void |
1d088dee | 1964 | record_temp_file (const char *filename, int always_delete, int fail_delete) |
ed1f651b | 1965 | { |
b3694847 | 1966 | char *const name = xstrdup (filename); |
ed1f651b RS |
1967 | |
1968 | if (always_delete) | |
1969 | { | |
b3694847 | 1970 | struct temp_file *temp; |
ed1f651b | 1971 | for (temp = always_delete_queue; temp; temp = temp->next) |
ba78087b | 1972 | if (! filename_cmp (name, temp->name)) |
ed1f651b | 1973 | goto already1; |
e9a25f70 | 1974 | |
5ed6ace5 | 1975 | temp = XNEW (struct temp_file); |
ed1f651b RS |
1976 | temp->next = always_delete_queue; |
1977 | temp->name = name; | |
1978 | always_delete_queue = temp; | |
e9a25f70 | 1979 | |
ed1f651b RS |
1980 | already1:; |
1981 | } | |
1982 | ||
1983 | if (fail_delete) | |
1984 | { | |
b3694847 | 1985 | struct temp_file *temp; |
ed1f651b | 1986 | for (temp = failure_delete_queue; temp; temp = temp->next) |
ba78087b | 1987 | if (! filename_cmp (name, temp->name)) |
ed1f651b | 1988 | goto already2; |
e9a25f70 | 1989 | |
5ed6ace5 | 1990 | temp = XNEW (struct temp_file); |
ed1f651b RS |
1991 | temp->next = failure_delete_queue; |
1992 | temp->name = name; | |
1993 | failure_delete_queue = temp; | |
e9a25f70 | 1994 | |
ed1f651b RS |
1995 | already2:; |
1996 | } | |
1997 | } | |
1998 | ||
1999 | /* Delete all the temporary files whose names we previously recorded. */ | |
2000 | ||
8fd58397 DR |
2001 | #ifndef DELETE_IF_ORDINARY |
2002 | #define DELETE_IF_ORDINARY(NAME,ST,VERBOSE_FLAG) \ | |
2003 | do \ | |
2004 | { \ | |
2005 | if (stat (NAME, &ST) >= 0 && S_ISREG (ST.st_mode)) \ | |
2006 | if (unlink (NAME) < 0) \ | |
2007 | if (VERBOSE_FLAG) \ | |
2008 | perror_with_name (NAME); \ | |
2009 | } while (0) | |
2010 | #endif | |
2011 | ||
d5ea2ac4 | 2012 | static void |
1d088dee | 2013 | delete_if_ordinary (const char *name) |
d5ea2ac4 RK |
2014 | { |
2015 | struct stat st; | |
2016 | #ifdef DEBUG | |
2017 | int i, c; | |
2018 | ||
2019 | printf ("Delete %s? (y or n) ", name); | |
2020 | fflush (stdout); | |
2021 | i = getchar (); | |
2022 | if (i != '\n') | |
e9a25f70 JL |
2023 | while ((c = getchar ()) != '\n' && c != EOF) |
2024 | ; | |
2025 | ||
d5ea2ac4 RK |
2026 | if (i == 'y' || i == 'Y') |
2027 | #endif /* DEBUG */ | |
8fd58397 | 2028 | DELETE_IF_ORDINARY (name, st, verbose_flag); |
d5ea2ac4 RK |
2029 | } |
2030 | ||
ed1f651b | 2031 | static void |
1d088dee | 2032 | delete_temp_files (void) |
ed1f651b | 2033 | { |
b3694847 | 2034 | struct temp_file *temp; |
ed1f651b RS |
2035 | |
2036 | for (temp = always_delete_queue; temp; temp = temp->next) | |
d5ea2ac4 | 2037 | delete_if_ordinary (temp->name); |
ed1f651b RS |
2038 | always_delete_queue = 0; |
2039 | } | |
2040 | ||
2041 | /* Delete all the files to be deleted on error. */ | |
2042 | ||
2043 | static void | |
1d088dee | 2044 | delete_failure_queue (void) |
ed1f651b | 2045 | { |
b3694847 | 2046 | struct temp_file *temp; |
ed1f651b RS |
2047 | |
2048 | for (temp = failure_delete_queue; temp; temp = temp->next) | |
d5ea2ac4 | 2049 | delete_if_ordinary (temp->name); |
ed1f651b RS |
2050 | } |
2051 | ||
2052 | static void | |
1d088dee | 2053 | clear_failure_queue (void) |
ed1f651b RS |
2054 | { |
2055 | failure_delete_queue = 0; | |
2056 | } | |
b3865ca9 | 2057 | \f |
00dcee0c AM |
2058 | /* Call CALLBACK for each path in PATHS, breaking out early if CALLBACK |
2059 | returns non-NULL. | |
2060 | If DO_MULTI is true iterate over the paths twice, first with multilib | |
2061 | suffix then without, otherwise iterate over the paths once without | |
2062 | adding a multilib suffix. When DO_MULTI is true, some attempt is made | |
2063 | to avoid visiting the same path twice, but we could do better. For | |
2064 | instance, /usr/lib/../lib is considered different from /usr/lib. | |
2065 | At least EXTRA_SPACE chars past the end of the path passed to | |
2066 | CALLBACK are available for use by the callback. | |
2067 | CALLBACK_INFO allows extra parameters to be passed to CALLBACK. | |
2068 | ||
2069 | Returns the value returned by CALLBACK. */ | |
2070 | ||
2071 | static void * | |
2072 | for_each_path (const struct path_prefix *paths, | |
2073 | bool do_multi, | |
2074 | size_t extra_space, | |
2075 | void *(*callback) (char *, void *), | |
2076 | void *callback_info) | |
b3865ca9 | 2077 | { |
00dcee0c AM |
2078 | struct prefix_list *pl; |
2079 | const char *multi_dir = NULL; | |
2080 | const char *multi_os_dir = NULL; | |
2081 | const char *multi_suffix; | |
2082 | const char *just_multi_suffix; | |
2083 | char *path = NULL; | |
2084 | void *ret = NULL; | |
2085 | bool skip_multi_dir = false; | |
2086 | bool skip_multi_os_dir = false; | |
2087 | ||
2088 | multi_suffix = machine_suffix; | |
2089 | just_multi_suffix = just_machine_suffix; | |
2090 | if (do_multi && multilib_dir && strcmp (multilib_dir, ".") != 0) | |
b3865ca9 | 2091 | { |
00dcee0c AM |
2092 | multi_dir = concat (multilib_dir, dir_separator_str, NULL); |
2093 | multi_suffix = concat (multi_suffix, multi_dir, NULL); | |
2094 | just_multi_suffix = concat (just_multi_suffix, multi_dir, NULL); | |
2095 | } | |
2096 | if (do_multi && multilib_os_dir && strcmp (multilib_os_dir, ".") != 0) | |
2097 | multi_os_dir = concat (multilib_os_dir, dir_separator_str, NULL); | |
b3865ca9 | 2098 | |
00dcee0c AM |
2099 | while (1) |
2100 | { | |
2101 | size_t multi_dir_len = 0; | |
2102 | size_t multi_os_dir_len = 0; | |
2103 | size_t suffix_len; | |
2104 | size_t just_suffix_len; | |
2105 | size_t len; | |
2106 | ||
2107 | if (multi_dir) | |
2108 | multi_dir_len = strlen (multi_dir); | |
2109 | if (multi_os_dir) | |
2110 | multi_os_dir_len = strlen (multi_os_dir); | |
2111 | suffix_len = strlen (multi_suffix); | |
2112 | just_suffix_len = strlen (just_multi_suffix); | |
2113 | ||
2114 | if (path == NULL) | |
b3865ca9 | 2115 | { |
00dcee0c AM |
2116 | len = paths->max_len + extra_space + 1; |
2117 | if (suffix_len > multi_os_dir_len) | |
2118 | len += suffix_len; | |
2119 | else | |
2120 | len += multi_os_dir_len; | |
5ed6ace5 | 2121 | path = XNEWVEC (char, len); |
b3865ca9 RS |
2122 | } |
2123 | ||
00dcee0c | 2124 | for (pl = paths->plist; pl != 0; pl = pl->next) |
ae04227b | 2125 | { |
00dcee0c AM |
2126 | len = strlen (pl->prefix); |
2127 | memcpy (path, pl->prefix, len); | |
9218435e | 2128 | |
00dcee0c AM |
2129 | /* Look first in MACHINE/VERSION subdirectory. */ |
2130 | if (!skip_multi_dir) | |
2131 | { | |
2132 | memcpy (path + len, multi_suffix, suffix_len + 1); | |
2133 | ret = callback (path, callback_info); | |
2134 | if (ret) | |
2135 | break; | |
2136 | } | |
2137 | ||
2138 | /* Some paths are tried with just the machine (ie. target) | |
2139 | subdir. This is used for finding as, ld, etc. */ | |
2140 | if (!skip_multi_dir | |
2141 | && pl->require_machine_suffix == 2) | |
2142 | { | |
2143 | memcpy (path + len, just_multi_suffix, just_suffix_len + 1); | |
2144 | ret = callback (path, callback_info); | |
2145 | if (ret) | |
2146 | break; | |
2147 | } | |
2148 | ||
2149 | /* Now try the base path. */ | |
2150 | if (!pl->require_machine_suffix | |
2151 | && !(pl->os_multilib ? skip_multi_os_dir : skip_multi_dir)) | |
2152 | { | |
2153 | const char *this_multi; | |
2154 | size_t this_multi_len; | |
2155 | ||
2156 | if (pl->os_multilib) | |
2157 | { | |
2158 | this_multi = multi_os_dir; | |
2159 | this_multi_len = multi_os_dir_len; | |
2160 | } | |
2161 | else | |
2162 | { | |
2163 | this_multi = multi_dir; | |
2164 | this_multi_len = multi_dir_len; | |
2165 | } | |
2166 | ||
2167 | if (this_multi_len) | |
2168 | memcpy (path + len, this_multi, this_multi_len + 1); | |
2169 | else | |
2170 | path[len] = '\0'; | |
2171 | ||
2172 | ret = callback (path, callback_info); | |
2173 | if (ret) | |
2174 | break; | |
2175 | } | |
ae04227b | 2176 | } |
00dcee0c AM |
2177 | if (pl) |
2178 | break; | |
ae04227b | 2179 | |
00dcee0c AM |
2180 | if (multi_dir == NULL && multi_os_dir == NULL) |
2181 | break; | |
b3865ca9 | 2182 | |
00dcee0c AM |
2183 | /* Run through the paths again, this time without multilibs. |
2184 | Don't repeat any we have already seen. */ | |
2185 | if (multi_dir) | |
2186 | { | |
b1d5455a | 2187 | free (CONST_CAST (char *, multi_dir)); |
00dcee0c | 2188 | multi_dir = NULL; |
b1d5455a | 2189 | free (CONST_CAST (char *, multi_suffix)); |
00dcee0c | 2190 | multi_suffix = machine_suffix; |
b1d5455a | 2191 | free (CONST_CAST (char *, just_multi_suffix)); |
00dcee0c | 2192 | just_multi_suffix = just_machine_suffix; |
b3865ca9 | 2193 | } |
00dcee0c AM |
2194 | else |
2195 | skip_multi_dir = true; | |
2196 | if (multi_os_dir) | |
2197 | { | |
b1d5455a | 2198 | free (CONST_CAST (char *, multi_os_dir)); |
00dcee0c AM |
2199 | multi_os_dir = NULL; |
2200 | } | |
2201 | else | |
2202 | skip_multi_os_dir = true; | |
2203 | } | |
2204 | ||
2205 | if (multi_dir) | |
2206 | { | |
b1d5455a KG |
2207 | free (CONST_CAST (char *, multi_dir)); |
2208 | free (CONST_CAST (char *, multi_suffix)); | |
2209 | free (CONST_CAST (char *, just_multi_suffix)); | |
b3865ca9 | 2210 | } |
00dcee0c | 2211 | if (multi_os_dir) |
b1d5455a | 2212 | free (CONST_CAST (char *, multi_os_dir)); |
00dcee0c AM |
2213 | if (ret != path) |
2214 | free (path); | |
2215 | return ret; | |
2216 | } | |
2217 | ||
2218 | /* Callback for build_search_list. Adds path to obstack being built. */ | |
2219 | ||
2220 | struct add_to_obstack_info { | |
2221 | struct obstack *ob; | |
2222 | bool check_dir; | |
2223 | bool first_time; | |
2224 | }; | |
2225 | ||
2226 | static void * | |
2227 | add_to_obstack (char *path, void *data) | |
2228 | { | |
e1e4cdc4 | 2229 | struct add_to_obstack_info *info = (struct add_to_obstack_info *) data; |
00dcee0c AM |
2230 | |
2231 | if (info->check_dir && !is_directory (path, false)) | |
2232 | return NULL; | |
2233 | ||
2234 | if (!info->first_time) | |
2235 | obstack_1grow (info->ob, PATH_SEPARATOR); | |
2236 | ||
2237 | obstack_grow (info->ob, path, strlen (path)); | |
2238 | ||
2239 | info->first_time = false; | |
2240 | return NULL; | |
2241 | } | |
2242 | ||
47d33318 FXC |
2243 | /* Add or change the value of an environment variable, outputting the |
2244 | change to standard error if in verbose mode. */ | |
2245 | static void | |
e9c15f6e | 2246 | xputenv (const char *string) |
47d33318 FXC |
2247 | { |
2248 | if (verbose_flag) | |
2dec80c7 | 2249 | fnotice (stderr, "%s\n", string); |
e9c15f6e | 2250 | putenv (CONST_CAST (char *, string)); |
47d33318 FXC |
2251 | } |
2252 | ||
00dcee0c AM |
2253 | /* Build a list of search directories from PATHS. |
2254 | PREFIX is a string to prepend to the list. | |
2255 | If CHECK_DIR_P is true we ensure the directory exists. | |
2256 | If DO_MULTI is true, multilib paths are output first, then | |
2257 | non-multilib paths. | |
2258 | This is used mostly by putenv_from_prefixes so we use `collect_obstack'. | |
2259 | It is also used by the --print-search-dirs flag. */ | |
2260 | ||
2261 | static char * | |
2262 | build_search_list (const struct path_prefix *paths, const char *prefix, | |
2263 | bool check_dir, bool do_multi) | |
2264 | { | |
2265 | struct add_to_obstack_info info; | |
2266 | ||
2267 | info.ob = &collect_obstack; | |
2268 | info.check_dir = check_dir; | |
2269 | info.first_time = true; | |
2270 | ||
2271 | obstack_grow (&collect_obstack, prefix, strlen (prefix)); | |
2272 | obstack_1grow (&collect_obstack, '='); | |
2273 | ||
2274 | for_each_path (paths, do_multi, 0, add_to_obstack, &info); | |
e9a25f70 | 2275 | |
3ae7de4e | 2276 | obstack_1grow (&collect_obstack, '\0'); |
7973fd2a | 2277 | return XOBFINISH (&collect_obstack, char *); |
b3865ca9 RS |
2278 | } |
2279 | ||
0f41302f MS |
2280 | /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables |
2281 | for collect. */ | |
2628b9d3 DE |
2282 | |
2283 | static void | |
00dcee0c AM |
2284 | putenv_from_prefixes (const struct path_prefix *paths, const char *env_var, |
2285 | bool do_multi) | |
2628b9d3 | 2286 | { |
47d33318 | 2287 | xputenv (build_search_list (paths, env_var, true, do_multi)); |
2628b9d3 | 2288 | } |
ed1f651b | 2289 | \f |
ca606201 ILT |
2290 | /* Check whether NAME can be accessed in MODE. This is like access, |
2291 | except that it never considers directories to be executable. */ | |
2292 | ||
2293 | static int | |
1d088dee | 2294 | access_check (const char *name, int mode) |
ca606201 ILT |
2295 | { |
2296 | if (mode == X_OK) | |
2297 | { | |
2298 | struct stat st; | |
2299 | ||
2300 | if (stat (name, &st) < 0 | |
2301 | || S_ISDIR (st.st_mode)) | |
2302 | return -1; | |
2303 | } | |
2304 | ||
2305 | return access (name, mode); | |
2306 | } | |
2307 | ||
00dcee0c AM |
2308 | /* Callback for find_a_file. Appends the file name to the directory |
2309 | path. If the resulting file exists in the right mode, return the | |
2310 | full pathname to the file. */ | |
2311 | ||
2312 | struct file_at_path_info { | |
2313 | const char *name; | |
2314 | const char *suffix; | |
2315 | int name_len; | |
2316 | int suffix_len; | |
2317 | int mode; | |
2318 | }; | |
2319 | ||
2320 | static void * | |
2321 | file_at_path (char *path, void *data) | |
2322 | { | |
e1e4cdc4 | 2323 | struct file_at_path_info *info = (struct file_at_path_info *) data; |
00dcee0c AM |
2324 | size_t len = strlen (path); |
2325 | ||
2326 | memcpy (path + len, info->name, info->name_len); | |
2327 | len += info->name_len; | |
2328 | ||
2329 | /* Some systems have a suffix for executable files. | |
2330 | So try appending that first. */ | |
2331 | if (info->suffix_len) | |
2332 | { | |
2333 | memcpy (path + len, info->suffix, info->suffix_len + 1); | |
2334 | if (access_check (path, info->mode) == 0) | |
2335 | return path; | |
2336 | } | |
2337 | ||
2338 | path[len] = '\0'; | |
2339 | if (access_check (path, info->mode) == 0) | |
2340 | return path; | |
2341 | ||
2342 | return NULL; | |
2343 | } | |
2344 | ||
ed1f651b | 2345 | /* Search for NAME using the prefix list PREFIXES. MODE is passed to |
00dcee0c AM |
2346 | access to check permissions. If DO_MULTI is true, search multilib |
2347 | paths then non-multilib paths, otherwise do not search multilib paths. | |
0f41302f | 2348 | Return 0 if not found, otherwise return its name, allocated with malloc. */ |
ed1f651b RS |
2349 | |
2350 | static char * | |
00dcee0c AM |
2351 | find_a_file (const struct path_prefix *pprefix, const char *name, int mode, |
2352 | bool do_multi) | |
ed1f651b | 2353 | { |
00dcee0c | 2354 | struct file_at_path_info info; |
ed1f651b | 2355 | |
ab339d62 | 2356 | #ifdef DEFAULT_ASSEMBLER |
c5c0b3d9 | 2357 | if (! strcmp (name, "as") && access (DEFAULT_ASSEMBLER, mode) == 0) |
ad85216e | 2358 | return xstrdup (DEFAULT_ASSEMBLER); |
ab339d62 AO |
2359 | #endif |
2360 | ||
2361 | #ifdef DEFAULT_LINKER | |
ad85216e KG |
2362 | if (! strcmp(name, "ld") && access (DEFAULT_LINKER, mode) == 0) |
2363 | return xstrdup (DEFAULT_LINKER); | |
ab339d62 AO |
2364 | #endif |
2365 | ||
ed1f651b RS |
2366 | /* Determine the filename to execute (special case for absolute paths). */ |
2367 | ||
3dce1408 | 2368 | if (IS_ABSOLUTE_PATH (name)) |
ed1f651b | 2369 | { |
ab339d62 | 2370 | if (access (name, mode) == 0) |
00dcee0c | 2371 | return xstrdup (name); |
460dcab4 | 2372 | |
00dcee0c AM |
2373 | return NULL; |
2374 | } | |
460dcab4 | 2375 | |
00dcee0c AM |
2376 | info.name = name; |
2377 | info.suffix = (mode & X_OK) != 0 ? HOST_EXECUTABLE_SUFFIX : ""; | |
2378 | info.name_len = strlen (info.name); | |
2379 | info.suffix_len = strlen (info.suffix); | |
2380 | info.mode = mode; | |
ed1f651b | 2381 | |
e1e4cdc4 KG |
2382 | return (char*) for_each_path (pprefix, do_multi, |
2383 | info.name_len + info.suffix_len, | |
2384 | file_at_path, &info); | |
ed1f651b RS |
2385 | } |
2386 | ||
922a4beb | 2387 | /* Ranking of prefixes in the sort list. -B prefixes are put before |
9218435e | 2388 | all others. */ |
922a4beb AC |
2389 | |
2390 | enum path_prefix_priority | |
2391 | { | |
2392 | PREFIX_PRIORITY_B_OPT, | |
2393 | PREFIX_PRIORITY_LAST | |
2394 | }; | |
2395 | ||
fbe5a4a6 | 2396 | /* Add an entry for PREFIX in PLIST. The PLIST is kept in ascending |
922a4beb AC |
2397 | order according to PRIORITY. Within each PRIORITY, new entries are |
2398 | appended. | |
ed1f651b RS |
2399 | |
2400 | If WARN is nonzero, we will warn if no file is found | |
2401 | through this prefix. WARN should point to an int | |
ae04227b CH |
2402 | which will be set to 1 if this entry is used. |
2403 | ||
e9a25f70 JL |
2404 | COMPONENT is the value to be passed to update_path. |
2405 | ||
ae04227b CH |
2406 | REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without |
2407 | the complete value of machine_suffix. | |
2408 | 2 means try both machine_suffix and just_machine_suffix. */ | |
ed1f651b RS |
2409 | |
2410 | static void | |
1d088dee AJ |
2411 | add_prefix (struct path_prefix *pprefix, const char *prefix, |
2412 | const char *component, /* enum prefix_priority */ int priority, | |
1a5d37a1 | 2413 | int require_machine_suffix, int os_multilib) |
ed1f651b RS |
2414 | { |
2415 | struct prefix_list *pl, **prev; | |
2416 | int len; | |
2417 | ||
922a4beb AC |
2418 | for (prev = &pprefix->plist; |
2419 | (*prev) != NULL && (*prev)->priority <= priority; | |
2420 | prev = &(*prev)->next) | |
2421 | ; | |
ed1f651b | 2422 | |
f9da5064 | 2423 | /* Keep track of the longest prefix. */ |
ed1f651b | 2424 | |
e9a25f70 | 2425 | prefix = update_path (prefix, component); |
ed1f651b RS |
2426 | len = strlen (prefix); |
2427 | if (len > pprefix->max_len) | |
2428 | pprefix->max_len = len; | |
2429 | ||
5ed6ace5 | 2430 | pl = XNEW (struct prefix_list); |
51c04256 | 2431 | pl->prefix = prefix; |
ed1f651b | 2432 | pl->require_machine_suffix = require_machine_suffix; |
922a4beb | 2433 | pl->priority = priority; |
5bbcd587 | 2434 | pl->os_multilib = os_multilib; |
ed1f651b | 2435 | |
f9da5064 | 2436 | /* Insert after PREV. */ |
922a4beb AC |
2437 | pl->next = (*prev); |
2438 | (*prev) = pl; | |
ed1f651b | 2439 | } |
4977bab6 ZW |
2440 | |
2441 | /* Same as add_prefix, but prepending target_system_root to prefix. */ | |
f4c0a303 | 2442 | /* The target_system_root prefix has been relocated by gcc_exec_prefix. */ |
4977bab6 | 2443 | static void |
1d088dee AJ |
2444 | add_sysrooted_prefix (struct path_prefix *pprefix, const char *prefix, |
2445 | const char *component, | |
2446 | /* enum prefix_priority */ int priority, | |
1a5d37a1 | 2447 | int require_machine_suffix, int os_multilib) |
4977bab6 | 2448 | { |
3dce1408 | 2449 | if (!IS_ABSOLUTE_PATH (prefix)) |
bdc6b402 | 2450 | fatal_error ("system path %qs is not absolute", prefix); |
4977bab6 ZW |
2451 | |
2452 | if (target_system_root) | |
2453 | { | |
2fda54bd MK |
2454 | char *sysroot_no_trailing_dir_separator = xstrdup (target_system_root); |
2455 | size_t sysroot_len = strlen (target_system_root); | |
2456 | ||
2457 | if (sysroot_len > 0 | |
2458 | && target_system_root[sysroot_len - 1] == DIR_SEPARATOR) | |
2459 | sysroot_no_trailing_dir_separator[sysroot_len - 1] = '\0'; | |
2460 | ||
e7f13528 GP |
2461 | if (target_sysroot_suffix) |
2462 | prefix = concat (target_sysroot_suffix, prefix, NULL); | |
2fda54bd MK |
2463 | prefix = concat (sysroot_no_trailing_dir_separator, prefix, NULL); |
2464 | free (sysroot_no_trailing_dir_separator); | |
e7f13528 | 2465 | |
4977bab6 ZW |
2466 | /* We have to override this because GCC's notion of sysroot |
2467 | moves along with GCC. */ | |
2468 | component = "GCC"; | |
2469 | } | |
2470 | ||
2471 | add_prefix (pprefix, prefix, component, priority, | |
1a5d37a1 | 2472 | require_machine_suffix, os_multilib); |
4977bab6 | 2473 | } |
ed1f651b RS |
2474 | \f |
2475 | /* Execute the command specified by the arguments on the current line of spec. | |
2476 | When using pipes, this includes several piped-together commands | |
2477 | with `|' between them. | |
2478 | ||
2479 | Return 0 if successful, -1 if failed. */ | |
2480 | ||
2481 | static int | |
1d088dee | 2482 | execute (void) |
ed1f651b RS |
2483 | { |
2484 | int i; | |
2485 | int n_commands; /* # of command. */ | |
2486 | char *string; | |
054e88a8 | 2487 | struct pex_obj *pex; |
ed1f651b | 2488 | struct command |
d25a45d4 KH |
2489 | { |
2490 | const char *prog; /* program name. */ | |
2491 | const char **argv; /* vector of args. */ | |
d25a45d4 | 2492 | }; |
5b634ee0 | 2493 | const char *arg; |
ed1f651b RS |
2494 | |
2495 | struct command *commands; /* each command buffer with above info. */ | |
2496 | ||
3b5edfee | 2497 | gcc_assert (!processing_spec_function); |
f3226a90 | 2498 | |
fe7df9c4 SP |
2499 | if (wrapper_string) |
2500 | { | |
5b634ee0 JM |
2501 | string = find_a_file (&exec_prefixes, |
2502 | VEC_index (const_char_p, argbuf, 0), X_OK, false); | |
2503 | if (string) | |
2504 | VEC_replace (const_char_p, argbuf, 0, string); | |
fe7df9c4 SP |
2505 | insert_wrapper (wrapper_string); |
2506 | } | |
2507 | ||
ed1f651b | 2508 | /* Count # of piped commands. */ |
5b634ee0 JM |
2509 | for (n_commands = 1, i = 0; VEC_iterate (const_char_p, argbuf, i, arg); i++) |
2510 | if (strcmp (arg, "|") == 0) | |
ed1f651b RS |
2511 | n_commands++; |
2512 | ||
2513 | /* Get storage for each command. */ | |
e1e4cdc4 | 2514 | commands = (struct command *) alloca (n_commands * sizeof (struct command)); |
ed1f651b RS |
2515 | |
2516 | /* Split argbuf into its separate piped processes, | |
2517 | and record info about each one. | |
2518 | Also search for the programs that are to be run. */ | |
2519 | ||
5b634ee0 JM |
2520 | VEC_safe_push (const_char_p, heap, argbuf, 0); |
2521 | ||
2522 | commands[0].prog = VEC_index (const_char_p, argbuf, 0); /* first command. */ | |
2523 | commands[0].argv = VEC_address (const_char_p, argbuf); | |
b8698a0f | 2524 | |
fe7df9c4 SP |
2525 | if (!wrapper_string) |
2526 | { | |
2527 | string = find_a_file (&exec_prefixes, commands[0].prog, X_OK, false); | |
2528 | commands[0].argv[0] = (string) ? string : commands[0].argv[0]; | |
2529 | } | |
ed1f651b | 2530 | |
5b634ee0 JM |
2531 | for (n_commands = 1, i = 0; VEC_iterate (const_char_p, argbuf, i, arg); i++) |
2532 | if (arg && strcmp (arg, "|") == 0) | |
ed1f651b | 2533 | { /* each command. */ |
6405c0ec | 2534 | #if defined (__MSDOS__) || defined (OS2) || defined (VMS) |
2dec80c7 | 2535 | fatal_error ("-pipe not supported"); |
ed1f651b | 2536 | #endif |
5b634ee0 JM |
2537 | VEC_replace (const_char_p, argbuf, i, 0); /* Termination of |
2538 | command args. */ | |
2539 | commands[n_commands].prog = VEC_index (const_char_p, argbuf, i + 1); | |
2540 | commands[n_commands].argv | |
2541 | = &(VEC_address (const_char_p, argbuf))[i + 1]; | |
5bbcd587 | 2542 | string = find_a_file (&exec_prefixes, commands[n_commands].prog, |
00dcee0c | 2543 | X_OK, false); |
ed1f651b RS |
2544 | if (string) |
2545 | commands[n_commands].argv[0] = string; | |
2546 | n_commands++; | |
2547 | } | |
2548 | ||
ed1f651b RS |
2549 | /* If -v, print what we are about to do, and maybe query. */ |
2550 | ||
b3865ca9 | 2551 | if (verbose_flag) |
ed1f651b | 2552 | { |
b8468bc7 NC |
2553 | /* For help listings, put a blank line between sub-processes. */ |
2554 | if (print_help_list) | |
2555 | fputc ('\n', stderr); | |
9218435e | 2556 | |
ed1f651b | 2557 | /* Print each piped command as a separate line. */ |
d25a45d4 | 2558 | for (i = 0; i < n_commands; i++) |
ed1f651b | 2559 | { |
37620334 | 2560 | const char *const *j; |
ed1f651b | 2561 | |
589005ff KH |
2562 | if (verbose_only_flag) |
2563 | { | |
99f78cdd IR |
2564 | for (j = commands[i].argv; *j; j++) |
2565 | { | |
88f92c0f | 2566 | const char *p; |
99f78cdd | 2567 | for (p = *j; *p; ++p) |
09b201fc JJ |
2568 | if (!ISALNUM ((unsigned char) *p) |
2569 | && *p != '_' && *p != '/' && *p != '-' && *p != '.') | |
2570 | break; | |
2571 | if (*p || !*j) | |
99f78cdd | 2572 | { |
09b201fc JJ |
2573 | fprintf (stderr, " \""); |
2574 | for (p = *j; *p; ++p) | |
2575 | { | |
2576 | if (*p == '"' || *p == '\\' || *p == '$') | |
2577 | fputc ('\\', stderr); | |
2578 | fputc (*p, stderr); | |
2579 | } | |
2580 | fputc ('"', stderr); | |
99f78cdd | 2581 | } |
7fcf46f5 JZ |
2582 | /* If it's empty, print "". */ |
2583 | else if (!**j) | |
2584 | fprintf (stderr, " \"\""); | |
09b201fc JJ |
2585 | else |
2586 | fprintf (stderr, " %s", *j); | |
99f78cdd | 2587 | } |
589005ff KH |
2588 | } |
2589 | else | |
99f78cdd | 2590 | for (j = commands[i].argv; *j; j++) |
7fcf46f5 JZ |
2591 | /* If it's empty, print "". */ |
2592 | if (!**j) | |
2593 | fprintf (stderr, " \"\""); | |
2594 | else | |
2595 | fprintf (stderr, " %s", *j); | |
ed1f651b RS |
2596 | |
2597 | /* Print a pipe symbol after all but the last command. */ | |
2598 | if (i + 1 != n_commands) | |
2599 | fprintf (stderr, " |"); | |
2600 | fprintf (stderr, "\n"); | |
2601 | } | |
2602 | fflush (stderr); | |
99f78cdd | 2603 | if (verbose_only_flag != 0) |
6a40fb21 AP |
2604 | { |
2605 | /* verbose_only_flag should act as if the spec was | |
2606 | executed, so increment execution_count before | |
ba228239 | 2607 | returning. This prevents spurious warnings about |
6a40fb21 AP |
2608 | unused linker input files, etc. */ |
2609 | execution_count++; | |
2610 | return 0; | |
2611 | } | |
ed1f651b | 2612 | #ifdef DEBUG |
2dec80c7 | 2613 | fnotice (stderr, "\nGo ahead? (y or n) "); |
ed1f651b RS |
2614 | fflush (stderr); |
2615 | i = getchar (); | |
2616 | if (i != '\n') | |
e9a25f70 JL |
2617 | while (getchar () != '\n') |
2618 | ; | |
2619 | ||
ed1f651b RS |
2620 | if (i != 'y' && i != 'Y') |
2621 | return 0; | |
2622 | #endif /* DEBUG */ | |
2623 | } | |
2624 | ||
414d23ae | 2625 | #ifdef ENABLE_VALGRIND_CHECKING |
fbe5a4a6 | 2626 | /* Run the each command through valgrind. To simplify prepending the |
414d23ae HPN |
2627 | path to valgrind and the option "-q" (for quiet operation unless |
2628 | something triggers), we allocate a separate argv array. */ | |
2629 | ||
2630 | for (i = 0; i < n_commands; i++) | |
2631 | { | |
2632 | const char **argv; | |
2633 | int argc; | |
2634 | int j; | |
2635 | ||
2636 | for (argc = 0; commands[i].argv[argc] != NULL; argc++) | |
2637 | ; | |
2638 | ||
63ab5b8c | 2639 | argv = XALLOCAVEC (const char *, argc + 3); |
414d23ae HPN |
2640 | |
2641 | argv[0] = VALGRIND_PATH; | |
2642 | argv[1] = "-q"; | |
2643 | for (j = 2; j < argc + 2; j++) | |
2644 | argv[j] = commands[i].argv[j - 2]; | |
2645 | argv[j] = NULL; | |
2646 | ||
2647 | commands[i].argv = argv; | |
2648 | commands[i].prog = argv[0]; | |
2649 | } | |
2650 | #endif | |
2651 | ||
ed1f651b RS |
2652 | /* Run each piped subprocess. */ |
2653 | ||
bdde878c AO |
2654 | pex = pex_init (PEX_USE_PIPES | ((report_times || report_times_to_file) |
2655 | ? PEX_RECORD_TIMES : 0), | |
6afbc885 | 2656 | progname, temp_filename); |
054e88a8 | 2657 | if (pex == NULL) |
bdc6b402 | 2658 | fatal_error ("pex_init failed: %m"); |
054e88a8 | 2659 | |
ed1f651b RS |
2660 | for (i = 0; i < n_commands; i++) |
2661 | { | |
054e88a8 ILT |
2662 | const char *errmsg; |
2663 | int err; | |
fbd40359 | 2664 | const char *string = commands[i].argv[0]; |
ed1f651b | 2665 | |
054e88a8 ILT |
2666 | errmsg = pex_run (pex, |
2667 | ((i + 1 == n_commands ? PEX_LAST : 0) | |
2668 | | (string == commands[i].prog ? PEX_SEARCH : 0)), | |
b1d5455a | 2669 | string, CONST_CAST (char **, commands[i].argv), |
054e88a8 ILT |
2670 | NULL, NULL, &err); |
2671 | if (errmsg != NULL) | |
2672 | { | |
2673 | if (err == 0) | |
2dec80c7 | 2674 | fatal_error (errmsg); |
054e88a8 ILT |
2675 | else |
2676 | { | |
2677 | errno = err; | |
2678 | pfatal_with_name (errmsg); | |
2679 | } | |
2680 | } | |
ed1f651b RS |
2681 | |
2682 | if (string != commands[i].prog) | |
b1d5455a | 2683 | free (CONST_CAST (char *, string)); |
ed1f651b RS |
2684 | } |
2685 | ||
2686 | execution_count++; | |
2687 | ||
054e88a8 | 2688 | /* Wait for all the subprocesses to finish. */ |
ed1f651b RS |
2689 | |
2690 | { | |
054e88a8 ILT |
2691 | int *statuses; |
2692 | struct pex_time *times = NULL; | |
ed1f651b RS |
2693 | int ret_code = 0; |
2694 | ||
e1e4cdc4 | 2695 | statuses = (int *) alloca (n_commands * sizeof (int)); |
054e88a8 | 2696 | if (!pex_get_status (pex, n_commands, statuses)) |
bdc6b402 | 2697 | fatal_error ("failed to get exit status: %m"); |
054e88a8 | 2698 | |
bdde878c | 2699 | if (report_times || report_times_to_file) |
ed1f651b | 2700 | { |
e1e4cdc4 | 2701 | times = (struct pex_time *) alloca (n_commands * sizeof (struct pex_time)); |
054e88a8 | 2702 | if (!pex_get_times (pex, n_commands, times)) |
bdc6b402 | 2703 | fatal_error ("failed to get process times: %m"); |
054e88a8 | 2704 | } |
ed1f651b | 2705 | |
054e88a8 | 2706 | pex_free (pex); |
ed1f651b | 2707 | |
054e88a8 ILT |
2708 | for (i = 0; i < n_commands; ++i) |
2709 | { | |
2710 | int status = statuses[i]; | |
03c41c05 | 2711 | |
054e88a8 ILT |
2712 | if (WIFSIGNALED (status)) |
2713 | { | |
c334349b | 2714 | #ifdef SIGPIPE |
054e88a8 ILT |
2715 | /* SIGPIPE is a special case. It happens in -pipe mode |
2716 | when the compiler dies before the preprocessor is done, | |
2717 | or the assembler dies before the compiler is done. | |
2718 | There's generally been an error already, and this is | |
2719 | just fallout. So don't generate another error unless | |
2720 | we would otherwise have succeeded. */ | |
2721 | if (WTERMSIG (status) == SIGPIPE | |
2722 | && (signal_count || greatest_status >= MIN_FATAL_STATUS)) | |
eeac616e VR |
2723 | { |
2724 | signal_count++; | |
2725 | ret_code = -1; | |
2726 | } | |
054e88a8 ILT |
2727 | else |
2728 | #endif | |
6afbc885 JM |
2729 | internal_error ("%s (program %s)", |
2730 | strsignal (WTERMSIG (status)), commands[i].prog); | |
054e88a8 ILT |
2731 | } |
2732 | else if (WIFEXITED (status) | |
2733 | && WEXITSTATUS (status) >= MIN_FATAL_STATUS) | |
2734 | { | |
2735 | if (WEXITSTATUS (status) > greatest_status) | |
2736 | greatest_status = WEXITSTATUS (status); | |
2737 | ret_code = -1; | |
2738 | } | |
2739 | ||
bdde878c | 2740 | if (report_times || report_times_to_file) |
054e88a8 ILT |
2741 | { |
2742 | struct pex_time *pt = ×[i]; | |
2743 | double ut, st; | |
2744 | ||
2745 | ut = ((double) pt->user_seconds | |
2746 | + (double) pt->user_microseconds / 1.0e6); | |
2747 | st = ((double) pt->system_seconds | |
2748 | + (double) pt->system_microseconds / 1.0e6); | |
2749 | ||
2750 | if (ut + st != 0) | |
bdde878c AO |
2751 | { |
2752 | if (report_times) | |
2dec80c7 JM |
2753 | fnotice (stderr, "# %s %.2f %.2f\n", |
2754 | commands[i].prog, ut, st); | |
bdde878c AO |
2755 | |
2756 | if (report_times_to_file) | |
2757 | { | |
2758 | int c = 0; | |
2759 | const char *const *j; | |
2760 | ||
2761 | fprintf (report_times_to_file, "%g %g", ut, st); | |
2762 | ||
2763 | for (j = &commands[i].prog; *j; j = &commands[i].argv[++c]) | |
2764 | { | |
2765 | const char *p; | |
2766 | for (p = *j; *p; ++p) | |
2767 | if (*p == '"' || *p == '\\' || *p == '$' | |
2768 | || ISSPACE (*p)) | |
2769 | break; | |
2770 | ||
2771 | if (*p) | |
2772 | { | |
2773 | fprintf (report_times_to_file, " \""); | |
2774 | for (p = *j; *p; ++p) | |
2775 | { | |
2776 | if (*p == '"' || *p == '\\' || *p == '$') | |
2777 | fputc ('\\', report_times_to_file); | |
2778 | fputc (*p, report_times_to_file); | |
2779 | } | |
2780 | fputc ('"', report_times_to_file); | |
2781 | } | |
2782 | else | |
2783 | fprintf (report_times_to_file, " %s", *j); | |
2784 | } | |
2785 | ||
2786 | fputc ('\n', report_times_to_file); | |
2787 | } | |
2788 | } | |
054e88a8 | 2789 | } |
ed1f651b | 2790 | } |
054e88a8 | 2791 | |
ed1f651b RS |
2792 | return ret_code; |
2793 | } | |
2794 | } | |
2795 | \f | |
2796 | /* Find all the switches given to us | |
2797 | and make a vector describing them. | |
2798 | The elements of the vector are strings, one per switch given. | |
2799 | If a switch uses following arguments, then the `part1' field | |
2800 | is the switch itself and the `args' field | |
2801 | is a null-terminated vector containing the following arguments. | |
3371362c L |
2802 | Bits in the `live_cond' field are: |
2803 | SWITCH_LIVE to indicate this switch is true in a conditional spec. | |
2804 | SWITCH_FALSE to indicate this switch is overridden by a later switch. | |
2805 | SWITCH_IGNORE to indicate this switch should be ignored (used in %<S). | |
94b90527 JJ |
2806 | SWITCH_IGNORE_PERMANENTLY to indicate this switch should be ignored |
2807 | in all do_spec calls afterwards. Used for %<S from self specs. | |
ab87f8c8 | 2808 | The `validated' field is nonzero if any spec has looked at this switch; |
ed1f651b RS |
2809 | if it remains zero at the end of the run, it must be meaningless. */ |
2810 | ||
96f5b137 L |
2811 | #define SWITCH_LIVE (1 << 0) |
2812 | #define SWITCH_FALSE (1 << 1) | |
2813 | #define SWITCH_IGNORE (1 << 2) | |
2814 | #define SWITCH_IGNORE_PERMANENTLY (1 << 3) | |
2815 | #define SWITCH_KEEP_FOR_GCC (1 << 4) | |
8097c429 | 2816 | |
ed1f651b RS |
2817 | struct switchstr |
2818 | { | |
878f32c3 | 2819 | const char *part1; |
fbd40359 | 2820 | const char **args; |
3371362c | 2821 | unsigned int live_cond; |
196a37f4 NB |
2822 | unsigned char validated; |
2823 | unsigned char ordering; | |
ed1f651b RS |
2824 | }; |
2825 | ||
2826 | static struct switchstr *switches; | |
2827 | ||
2828 | static int n_switches; | |
2829 | ||
922e1882 JM |
2830 | static int n_switches_alloc; |
2831 | ||
2153915d AO |
2832 | /* Set to zero if -fcompare-debug is disabled, positive if it's |
2833 | enabled and we're running the first compilation, negative if it's | |
2834 | enabled and we're running the second compilation. For most of the | |
2835 | time, it's in the range -1..1, but it can be temporarily set to 2 | |
2836 | or 3 to indicate that the -fcompare-debug flags didn't come from | |
2837 | the command-line, but rather from the GCC_COMPARE_DEBUG environment | |
2838 | variable, until a synthesized -fcompare-debug flag is added to the | |
2839 | command line. */ | |
2840 | int compare_debug; | |
2841 | ||
2842 | /* Set to nonzero if we've seen the -fcompare-debug-second flag. */ | |
2843 | int compare_debug_second; | |
2844 | ||
2845 | /* Set to the flags that should be passed to the second compilation in | |
2846 | a -fcompare-debug compilation. */ | |
2847 | const char *compare_debug_opt; | |
2848 | ||
2849 | static struct switchstr *switches_debug_check[2]; | |
2850 | ||
2851 | static int n_switches_debug_check[2]; | |
2852 | ||
efe5e5a0 JM |
2853 | static int n_switches_alloc_debug_check[2]; |
2854 | ||
2153915d AO |
2855 | static char *debug_check_temp_file[2]; |
2856 | ||
817a8255 EC |
2857 | /* Language is one of three things: |
2858 | ||
2859 | 1) The name of a real programming language. | |
2860 | 2) NULL, indicating that no one has figured out | |
2861 | what it is yet. | |
2862 | 3) '*', indicating that the file should be passed | |
2863 | to the linker. */ | |
ed1f651b RS |
2864 | struct infile |
2865 | { | |
878f32c3 KG |
2866 | const char *name; |
2867 | const char *language; | |
0855eab7 CT |
2868 | struct compiler *incompiler; |
2869 | bool compiled; | |
2870 | bool preprocessed; | |
ed1f651b RS |
2871 | }; |
2872 | ||
2873 | /* Also a vector of input files specified. */ | |
2874 | ||
2875 | static struct infile *infiles; | |
2876 | ||
3a5a9edc | 2877 | int n_infiles; |
ed1f651b | 2878 | |
922e1882 JM |
2879 | static int n_infiles_alloc; |
2880 | ||
d1bd0ded GK |
2881 | /* True if multiple input files are being compiled to a single |
2882 | assembly file. */ | |
2883 | ||
2884 | static bool combine_inputs; | |
2885 | ||
08dc830e | 2886 | /* This counts the number of libraries added by lang_specific_driver, so that |
a2a05b0a JW |
2887 | we can tell if there were any user supplied any files or libraries. */ |
2888 | ||
2889 | static int added_libraries; | |
2890 | ||
ed1f651b RS |
2891 | /* And a vector of corresponding output files is made up later. */ |
2892 | ||
3a5a9edc | 2893 | const char **outfiles; |
853e0b2d | 2894 | \f |
45936a85 | 2895 | #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX) |
853e0b2d RK |
2896 | |
2897 | /* Convert NAME to a new name if it is the standard suffix. DO_EXE | |
a9657ce8 DR |
2898 | is true if we should look for an executable suffix. DO_OBJ |
2899 | is true if we should look for an object suffix. */ | |
853e0b2d | 2900 | |
40cdfca6 | 2901 | static const char * |
1d088dee AJ |
2902 | convert_filename (const char *name, int do_exe ATTRIBUTE_UNUSED, |
2903 | int do_obj ATTRIBUTE_UNUSED) | |
853e0b2d | 2904 | { |
40cdfca6 | 2905 | #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) |
853e0b2d | 2906 | int i; |
40cdfca6 | 2907 | #endif |
87e690e2 MK |
2908 | int len; |
2909 | ||
2910 | if (name == NULL) | |
2911 | return NULL; | |
9218435e | 2912 | |
87e690e2 | 2913 | len = strlen (name); |
853e0b2d | 2914 | |
45936a85 DD |
2915 | #ifdef HAVE_TARGET_OBJECT_SUFFIX |
2916 | /* Convert x.o to x.obj if TARGET_OBJECT_SUFFIX is ".obj". */ | |
a9657ce8 | 2917 | if (do_obj && len > 2 |
853e0b2d RK |
2918 | && name[len - 2] == '.' |
2919 | && name[len - 1] == 'o') | |
2920 | { | |
bdc5ed93 | 2921 | obstack_grow (&obstack, name, len - 2); |
45936a85 | 2922 | obstack_grow0 (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX)); |
7973fd2a | 2923 | name = XOBFINISH (&obstack, const char *); |
853e0b2d RK |
2924 | } |
2925 | #endif | |
2926 | ||
45936a85 | 2927 | #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) |
853e0b2d RK |
2928 | /* If there is no filetype, make it the executable suffix (which includes |
2929 | the "."). But don't get confused if we have just "-o". */ | |
45936a85 | 2930 | if (! do_exe || TARGET_EXECUTABLE_SUFFIX[0] == 0 || (len == 2 && name[0] == '-')) |
853e0b2d RK |
2931 | return name; |
2932 | ||
e0040a8e | 2933 | for (i = len - 1; i >= 0; i--) |
509781a4 | 2934 | if (IS_DIR_SEPARATOR (name[i])) |
e0040a8e RK |
2935 | break; |
2936 | ||
2937 | for (i++; i < len; i++) | |
853e0b2d RK |
2938 | if (name[i] == '.') |
2939 | return name; | |
2940 | ||
2941 | obstack_grow (&obstack, name, len); | |
5d9669fd RK |
2942 | obstack_grow0 (&obstack, TARGET_EXECUTABLE_SUFFIX, |
2943 | strlen (TARGET_EXECUTABLE_SUFFIX)); | |
7973fd2a | 2944 | name = XOBFINISH (&obstack, const char *); |
853e0b2d RK |
2945 | #endif |
2946 | ||
2947 | return name; | |
2948 | } | |
2949 | #endif | |
b8468bc7 NC |
2950 | \f |
2951 | /* Display the command line switches accepted by gcc. */ | |
2952 | static void | |
1d088dee | 2953 | display_help (void) |
b8468bc7 | 2954 | { |
6afbc885 | 2955 | printf (_("Usage: %s [options] file...\n"), progname); |
5e4adfba | 2956 | fputs (_("Options:\n"), stdout); |
b8468bc7 | 2957 | |
5e4adfba PT |
2958 | fputs (_(" -pass-exit-codes Exit with highest error code from a phase\n"), stdout); |
2959 | fputs (_(" --help Display this information\n"), stdout); | |
91606ce2 | 2960 | fputs (_(" --target-help Display target specific command line options\n"), stdout); |
cdbfc61d | 2961 | fputs (_(" --help={common|optimizers|params|target|warnings|[^]{joined|separate|undocumented}}[,...]\n"), stdout); |
c662432e | 2962 | fputs (_(" Display specific types of command line options\n"), stdout); |
b8468bc7 | 2963 | if (! verbose_flag) |
5e4adfba | 2964 | fputs (_(" (Use '-v --help' to display command line options of sub-processes)\n"), stdout); |
1156c176 | 2965 | fputs (_(" --version Display compiler version information\n"), stdout); |
5e4adfba PT |
2966 | fputs (_(" -dumpspecs Display all of the built in spec strings\n"), stdout); |
2967 | fputs (_(" -dumpversion Display the version of the compiler\n"), stdout); | |
2968 | fputs (_(" -dumpmachine Display the compiler's target processor\n"), stdout); | |
2969 | fputs (_(" -print-search-dirs Display the directories in the compiler's search path\n"), stdout); | |
2970 | fputs (_(" -print-libgcc-file-name Display the name of the compiler's companion library\n"), stdout); | |
2971 | fputs (_(" -print-file-name=<lib> Display the full path to library <lib>\n"), stdout); | |
2972 | fputs (_(" -print-prog-name=<prog> Display the full path to compiler component <prog>\n"), stdout); | |
2973 | fputs (_(" -print-multi-directory Display the root directory for versions of libgcc\n"), stdout); | |
2974 | fputs (_("\ | |
2975 | -print-multi-lib Display the mapping between command line options and\n\ | |
2976 | multiple library search directories\n"), stdout); | |
5bbcd587 | 2977 | fputs (_(" -print-multi-os-directory Display the relative path to OS libraries\n"), stdout); |
3def1397 | 2978 | fputs (_(" -print-sysroot Display the target libraries directory\n"), stdout); |
14da6073 | 2979 | fputs (_(" -print-sysroot-headers-suffix Display the sysroot suffix used to find headers\n"), stdout); |
5e4adfba PT |
2980 | fputs (_(" -Wa,<options> Pass comma-separated <options> on to the assembler\n"), stdout); |
2981 | fputs (_(" -Wp,<options> Pass comma-separated <options> on to the preprocessor\n"), stdout); | |
2982 | fputs (_(" -Wl,<options> Pass comma-separated <options> on to the linker\n"), stdout); | |
4977bab6 ZW |
2983 | fputs (_(" -Xassembler <arg> Pass <arg> on to the assembler\n"), stdout); |
2984 | fputs (_(" -Xpreprocessor <arg> Pass <arg> on to the preprocessor\n"), stdout); | |
5e4adfba PT |
2985 | fputs (_(" -Xlinker <arg> Pass <arg> on to the linker\n"), stdout); |
2986 | fputs (_(" -save-temps Do not delete intermediate files\n"), stdout); | |
14fdc613 | 2987 | fputs (_(" -save-temps=<arg> Do not delete intermediate files\n"), stdout); |
ba0c638e SB |
2988 | fputs (_("\ |
2989 | -no-canonical-prefixes Do not canonicalize paths when building relative\n\ | |
2990 | prefixes to other gcc components\n"), stdout); | |
5e4adfba PT |
2991 | fputs (_(" -pipe Use pipes rather than intermediate files\n"), stdout); |
2992 | fputs (_(" -time Time the execution of each subprocess\n"), stdout); | |
b0287a90 | 2993 | fputs (_(" -specs=<file> Override built-in specs with the contents of <file>\n"), stdout); |
5e4adfba | 2994 | fputs (_(" -std=<standard> Assume that the input sources are for <standard>\n"), stdout); |
160633c6 MM |
2995 | fputs (_("\ |
2996 | --sysroot=<directory> Use <directory> as the root directory for headers\n\ | |
b3cccd58 | 2997 | and libraries\n"), stdout); |
5e4adfba | 2998 | fputs (_(" -B <directory> Add <directory> to the compiler's search paths\n"), stdout); |
5e4adfba | 2999 | fputs (_(" -v Display the programs invoked by the compiler\n"), stdout); |
99f78cdd | 3000 | fputs (_(" -### Like -v but options quoted and commands not executed\n"), stdout); |
5e4adfba PT |
3001 | fputs (_(" -E Preprocess only; do not compile, assemble or link\n"), stdout); |
3002 | fputs (_(" -S Compile only; do not assemble or link\n"), stdout); | |
3003 | fputs (_(" -c Compile and assemble, but do not link\n"), stdout); | |
3004 | fputs (_(" -o <file> Place the output into <file>\n"), stdout); | |
5460e1fc JJ |
3005 | fputs (_(" -pie Create a position independent executable\n"), stdout); |
3006 | fputs (_(" -shared Create a shared library\n"), stdout); | |
5e4adfba PT |
3007 | fputs (_("\ |
3008 | -x <language> Specify the language of the following input files\n\ | |
8e854b76 | 3009 | Permissible languages include: c c++ assembler none\n\ |
1737c953 | 3010 | 'none' means revert to the default behavior of\n\ |
5e4adfba PT |
3011 | guessing the language based on the file's extension\n\ |
3012 | "), stdout); | |
3013 | ||
0c386769 | 3014 | printf (_("\ |
d991c721 BK |
3015 | \nOptions starting with -g, -f, -m, -O, -W, or --param are automatically\n\ |
3016 | passed on to the various sub-processes invoked by %s. In order to pass\n\ | |
3017 | other options on to these processes the -W<letter> options must be used.\n\ | |
6afbc885 | 3018 | "), progname); |
b8468bc7 NC |
3019 | |
3020 | /* The rest of the options are displayed by invocations of the various | |
3021 | sub-processes. */ | |
3022 | } | |
3023 | ||
9218435e | 3024 | static void |
1d088dee | 3025 | add_preprocessor_option (const char *option, int len) |
9218435e | 3026 | { |
69d540bd NF |
3027 | VEC_safe_push (char_p, heap, preprocessor_options, |
3028 | save_string (option, len)); | |
40f943dd | 3029 | } |
9218435e KH |
3030 | |
3031 | static void | |
1d088dee | 3032 | add_assembler_option (const char *option, int len) |
878f32c3 | 3033 | { |
69d540bd | 3034 | VEC_safe_push (char_p, heap, assembler_options, save_string (option, len)); |
b8468bc7 | 3035 | } |
9218435e KH |
3036 | |
3037 | static void | |
1d088dee | 3038 | add_linker_option (const char *option, int len) |
878f32c3 | 3039 | { |
69d540bd | 3040 | VEC_safe_push (char_p, heap, linker_options, save_string (option, len)); |
40f943dd | 3041 | } |
853e0b2d | 3042 | \f |
922e1882 JM |
3043 | /* Allocate space for an input file in infiles. */ |
3044 | ||
3045 | static void | |
3046 | alloc_infile (void) | |
3047 | { | |
3048 | if (n_infiles_alloc == 0) | |
3049 | { | |
3050 | n_infiles_alloc = 16; | |
3051 | infiles = XNEWVEC (struct infile, n_infiles_alloc); | |
3052 | } | |
3053 | else if (n_infiles_alloc == n_infiles) | |
3054 | { | |
3055 | n_infiles_alloc *= 2; | |
3056 | infiles = XRESIZEVEC (struct infile, infiles, n_infiles_alloc); | |
3057 | } | |
3058 | } | |
3059 | ||
3060 | /* Store an input file with the given NAME and LANGUAGE in | |
3061 | infiles. */ | |
3062 | ||
3063 | static void | |
3064 | add_infile (const char *name, const char *language) | |
3065 | { | |
3066 | alloc_infile (); | |
3067 | infiles[n_infiles].name = name; | |
3068 | infiles[n_infiles++].language = language; | |
3069 | } | |
3070 | ||
3071 | /* Allocate space for a switch in switches. */ | |
3072 | ||
3073 | static void | |
3074 | alloc_switch (void) | |
3075 | { | |
3076 | if (n_switches_alloc == 0) | |
3077 | { | |
3078 | n_switches_alloc = 16; | |
3079 | switches = XNEWVEC (struct switchstr, n_switches_alloc); | |
3080 | } | |
3081 | else if (n_switches_alloc == n_switches) | |
3082 | { | |
3083 | n_switches_alloc *= 2; | |
3084 | switches = XRESIZEVEC (struct switchstr, switches, n_switches_alloc); | |
3085 | } | |
3086 | } | |
3087 | ||
603349bf JM |
3088 | /* Save an option OPT with N_ARGS arguments in array ARGS, marking it |
3089 | as validated if VALIDATED. */ | |
3090 | ||
3091 | static void | |
3092 | save_switch (const char *opt, size_t n_args, const char *const *args, | |
3093 | bool validated) | |
3094 | { | |
3095 | alloc_switch (); | |
3096 | switches[n_switches].part1 = opt + 1; | |
3097 | if (n_args == 0) | |
3098 | switches[n_switches].args = 0; | |
3099 | else | |
3100 | { | |
3101 | switches[n_switches].args = XNEWVEC (const char *, n_args + 1); | |
3102 | memcpy (switches[n_switches].args, args, n_args * sizeof (const char *)); | |
3103 | switches[n_switches].args[n_args] = NULL; | |
3104 | } | |
3105 | ||
3106 | switches[n_switches].live_cond = 0; | |
3107 | switches[n_switches].validated = validated; | |
3108 | switches[n_switches].ordering = 0; | |
3109 | n_switches++; | |
3110 | } | |
3111 | ||
3112 | /* Handle an option DECODED that is unknown to the option-processing | |
66017846 | 3113 | machinery. */ |
603349bf JM |
3114 | |
3115 | static bool | |
3116 | driver_unknown_option_callback (const struct cl_decoded_option *decoded) | |
3117 | { | |
66017846 JM |
3118 | const char *opt = decoded->arg; |
3119 | if (opt[1] == 'W' && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-' | |
3120 | && !(decoded->errors & CL_ERR_NEGATIVE)) | |
3121 | { | |
3122 | /* Leave unknown -Wno-* options for the compiler proper, to be | |
3123 | diagnosed only if there are warnings. */ | |
3124 | save_switch (decoded->canonical_option[0], | |
3125 | decoded->canonical_option_num_elements - 1, | |
3126 | &decoded->canonical_option[1], false); | |
3127 | return false; | |
3128 | } | |
3129 | else | |
3130 | return true; | |
603349bf JM |
3131 | } |
3132 | ||
3133 | /* Handle an option DECODED that is not marked as CL_DRIVER. | |
3134 | LANG_MASK will always be CL_DRIVER. */ | |
3135 | ||
3136 | static void | |
3137 | driver_wrong_lang_callback (const struct cl_decoded_option *decoded, | |
3138 | unsigned int lang_mask ATTRIBUTE_UNUSED) | |
3139 | { | |
3140 | /* At this point, non-driver options are accepted (and expected to | |
3141 | be passed down by specs) unless marked to be rejected by the | |
3142 | driver. Options to be rejected by the driver but accepted by the | |
3143 | compilers proper are treated just like completely unknown | |
3144 | options. */ | |
3145 | const struct cl_option *option = &cl_options[decoded->opt_index]; | |
3146 | ||
300d83d9 | 3147 | if (option->cl_reject_driver) |
603349bf JM |
3148 | error ("unrecognized command line option %qs", |
3149 | decoded->orig_option_with_args_text); | |
3150 | else | |
66017846 JM |
3151 | save_switch (decoded->canonical_option[0], |
3152 | decoded->canonical_option_num_elements - 1, | |
3153 | &decoded->canonical_option[1], false); | |
603349bf JM |
3154 | } |
3155 | ||
603349bf JM |
3156 | static const char *spec_lang = 0; |
3157 | static int last_language_n_infiles; | |
3158 | ||
3159 | /* Handle a driver option; arguments and return value as for | |
3160 | handle_option. */ | |
3161 | ||
3162 | static bool | |
46625112 | 3163 | driver_handle_option (struct gcc_options *opts, |
d4d24ba4 | 3164 | struct gcc_options *opts_set, |
46625112 | 3165 | const struct cl_decoded_option *decoded, |
603349bf | 3166 | unsigned int lang_mask ATTRIBUTE_UNUSED, int kind, |
a4d8c676 | 3167 | location_t loc, |
d5478783 JM |
3168 | const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED, |
3169 | diagnostic_context *dc) | |
603349bf JM |
3170 | { |
3171 | size_t opt_index = decoded->opt_index; | |
3172 | const char *arg = decoded->arg; | |
3173 | const char *compare_debug_replacement_opt; | |
3174 | int value = decoded->value; | |
3175 | bool validated = false; | |
3176 | bool do_save = true; | |
3177 | ||
46625112 | 3178 | gcc_assert (opts == &global_options); |
d4d24ba4 | 3179 | gcc_assert (opts_set == &global_options_set); |
603349bf | 3180 | gcc_assert (kind == DK_UNSPECIFIED); |
a4d8c676 | 3181 | gcc_assert (loc == UNKNOWN_LOCATION); |
d5478783 | 3182 | gcc_assert (dc == global_dc); |
603349bf JM |
3183 | |
3184 | switch (opt_index) | |
3185 | { | |
3186 | case OPT_dumpspecs: | |
3187 | { | |
3188 | struct spec_list *sl; | |
3189 | init_spec (); | |
3190 | for (sl = specs; sl; sl = sl->next) | |
3191 | printf ("*%s:\n%s\n\n", sl->name, *(sl->ptr_spec)); | |
3192 | if (link_command_spec) | |
3193 | printf ("*link_command:\n%s\n\n", link_command_spec); | |
3194 | exit (0); | |
3195 | } | |
3196 | ||
3197 | case OPT_dumpversion: | |
3198 | printf ("%s\n", spec_version); | |
3199 | exit (0); | |
3200 | ||
3201 | case OPT_dumpmachine: | |
3202 | printf ("%s\n", spec_machine); | |
3203 | exit (0); | |
3204 | ||
e200444e | 3205 | case OPT__version: |
603349bf JM |
3206 | print_version = 1; |
3207 | ||
3208 | /* CPP driver cannot obtain switch from cc1_options. */ | |
3209 | if (is_cpp_driver) | |
3210 | add_preprocessor_option ("--version", strlen ("--version")); | |
3211 | add_assembler_option ("--version", strlen ("--version")); | |
3212 | add_linker_option ("--version", strlen ("--version")); | |
3213 | break; | |
3214 | ||
e200444e | 3215 | case OPT__help: |
603349bf JM |
3216 | print_help_list = 1; |
3217 | ||
3218 | /* CPP driver cannot obtain switch from cc1_options. */ | |
3219 | if (is_cpp_driver) | |
3220 | add_preprocessor_option ("--help", 6); | |
3221 | add_assembler_option ("--help", 6); | |
3222 | add_linker_option ("--help", 6); | |
3223 | break; | |
3224 | ||
e200444e | 3225 | case OPT__help_: |
603349bf JM |
3226 | print_subprocess_help = 2; |
3227 | break; | |
3228 | ||
e200444e | 3229 | case OPT__target_help: |
603349bf JM |
3230 | print_subprocess_help = 1; |
3231 | ||
3232 | /* CPP driver cannot obtain switch from cc1_options. */ | |
3233 | if (is_cpp_driver) | |
3234 | add_preprocessor_option ("--target-help", 13); | |
3235 | add_assembler_option ("--target-help", 13); | |
3236 | add_linker_option ("--target-help", 13); | |
3237 | break; | |
3238 | ||
3239 | case OPT_pass_exit_codes: | |
3240 | case OPT_print_search_dirs: | |
3241 | case OPT_print_file_name_: | |
3242 | case OPT_print_prog_name_: | |
3243 | case OPT_print_multi_lib: | |
3244 | case OPT_print_multi_directory: | |
3245 | case OPT_print_sysroot: | |
3246 | case OPT_print_multi_os_directory: | |
3247 | case OPT_print_sysroot_headers_suffix: | |
3248 | case OPT_time: | |
3249 | case OPT_wrapper: | |
3250 | /* These options set the variables specified in common.opt | |
3251 | automatically, and do not need to be saved for spec | |
3252 | processing. */ | |
3253 | do_save = false; | |
3254 | break; | |
3255 | ||
3256 | case OPT_print_libgcc_file_name: | |
3257 | print_file_name = "libgcc.a"; | |
3258 | do_save = false; | |
3259 | break; | |
3260 | ||
3261 | case OPT_fcompare_debug_second: | |
3262 | compare_debug_second = 1; | |
3263 | break; | |
3264 | ||
3265 | case OPT_fcompare_debug: | |
3266 | switch (value) | |
3267 | { | |
3268 | case 0: | |
3269 | compare_debug_replacement_opt = "-fcompare-debug="; | |
3270 | arg = ""; | |
3271 | goto compare_debug_with_arg; | |
3272 | ||
3273 | case 1: | |
3274 | compare_debug_replacement_opt = "-fcompare-debug=-gtoggle"; | |
3275 | arg = "-gtoggle"; | |
3276 | goto compare_debug_with_arg; | |
3277 | ||
3278 | default: | |
3279 | gcc_unreachable (); | |
3280 | } | |
3281 | break; | |
3282 | ||
3283 | case OPT_fcompare_debug_: | |
3284 | compare_debug_replacement_opt = decoded->canonical_option[0]; | |
3285 | compare_debug_with_arg: | |
3286 | gcc_assert (decoded->canonical_option_num_elements == 1); | |
3287 | gcc_assert (arg != NULL); | |
28c14a04 | 3288 | if (*arg) |
603349bf JM |
3289 | compare_debug = 1; |
3290 | else | |
3291 | compare_debug = -1; | |
3292 | if (compare_debug < 0) | |
3293 | compare_debug_opt = NULL; | |
3294 | else | |
3295 | compare_debug_opt = arg; | |
3296 | save_switch (compare_debug_replacement_opt, 0, NULL, validated); | |
3297 | return true; | |
3298 | ||
3299 | case OPT_Wa_: | |
3300 | { | |
3301 | int prev, j; | |
3302 | /* Pass the rest of this option to the assembler. */ | |
3303 | ||
3304 | /* Split the argument at commas. */ | |
3305 | prev = 0; | |
3306 | for (j = 0; arg[j]; j++) | |
3307 | if (arg[j] == ',') | |
3308 | { | |
3309 | add_assembler_option (arg + prev, j - prev); | |
3310 | prev = j + 1; | |
3311 | } | |
3312 | ||
3313 | /* Record the part after the last comma. */ | |
3314 | add_assembler_option (arg + prev, j - prev); | |
3315 | } | |
3316 | do_save = false; | |
3317 | break; | |
3318 | ||
3319 | case OPT_Wp_: | |
3320 | { | |
3321 | int prev, j; | |
3322 | /* Pass the rest of this option to the preprocessor. */ | |
3323 | ||
3324 | /* Split the argument at commas. */ | |
3325 | prev = 0; | |
3326 | for (j = 0; arg[j]; j++) | |
3327 | if (arg[j] == ',') | |
3328 | { | |
3329 | add_preprocessor_option (arg + prev, j - prev); | |
3330 | prev = j + 1; | |
3331 | } | |
3332 | ||
3333 | /* Record the part after the last comma. */ | |
3334 | add_preprocessor_option (arg + prev, j - prev); | |
3335 | } | |
3336 | do_save = false; | |
3337 | break; | |
3338 | ||
3339 | case OPT_Wl_: | |
3340 | { | |
3341 | int prev, j; | |
3342 | /* Split the argument at commas. */ | |
3343 | prev = 0; | |
3344 | for (j = 0; arg[j]; j++) | |
3345 | if (arg[j] == ',') | |
3346 | { | |
3347 | add_infile (save_string (arg + prev, j - prev), "*"); | |
3348 | prev = j + 1; | |
3349 | } | |
3350 | /* Record the part after the last comma. */ | |
3351 | add_infile (arg + prev, "*"); | |
3352 | } | |
3353 | do_save = false; | |
3354 | break; | |
3355 | ||
3356 | case OPT_Xlinker: | |
3357 | add_infile (arg, "*"); | |
3358 | do_save = false; | |
3359 | break; | |
3360 | ||
3361 | case OPT_Xpreprocessor: | |
3362 | add_preprocessor_option (arg, strlen (arg)); | |
3363 | do_save = false; | |
3364 | break; | |
3365 | ||
3366 | case OPT_Xassembler: | |
3367 | add_assembler_option (arg, strlen (arg)); | |
3368 | do_save = false; | |
3369 | break; | |
3370 | ||
3371 | case OPT_l: | |
3372 | /* POSIX allows separation of -l and the lib arg; canonicalize | |
3373 | by concatenating -l with its arg */ | |
3374 | add_infile (concat ("-l", arg, NULL), "*"); | |
3375 | do_save = false; | |
3376 | break; | |
3377 | ||
5de8299c JM |
3378 | case OPT_L: |
3379 | /* Similarly, canonicalize -L for linkers that may not accept | |
3380 | separate arguments. */ | |
3381 | save_switch (concat ("-L", arg, NULL), 0, NULL, validated); | |
3382 | return true; | |
3383 | ||
a350a6c8 IS |
3384 | case OPT_F: |
3385 | /* Likewise -F. */ | |
3386 | save_switch (concat ("-F", arg, NULL), 0, NULL, validated); | |
3387 | return true; | |
3388 | ||
603349bf JM |
3389 | case OPT_save_temps: |
3390 | save_temps_flag = SAVE_TEMPS_CWD; | |
3391 | validated = true; | |
3392 | break; | |
3393 | ||
3394 | case OPT_save_temps_: | |
3395 | if (strcmp (arg, "cwd") == 0) | |
3396 | save_temps_flag = SAVE_TEMPS_CWD; | |
3397 | else if (strcmp (arg, "obj") == 0 | |
3398 | || strcmp (arg, "object") == 0) | |
3399 | save_temps_flag = SAVE_TEMPS_OBJ; | |
3400 | else | |
3401 | fatal_error ("%qs is an unknown -save-temps option", | |
3402 | decoded->orig_option_with_args_text); | |
3403 | break; | |
3404 | ||
3405 | case OPT_no_canonical_prefixes: | |
3406 | /* Already handled as a special case, so ignored here. */ | |
3407 | do_save = false; | |
3408 | break; | |
3409 | ||
3410 | case OPT_pipe: | |
3411 | validated = true; | |
603349bf JM |
3412 | /* These options set the variables specified in common.opt |
3413 | automatically, but do need to be saved for spec | |
3414 | processing. */ | |
3415 | break; | |
3416 | ||
603349bf JM |
3417 | case OPT_specs_: |
3418 | { | |
3419 | struct user_specs *user = XNEW (struct user_specs); | |
3420 | ||
3421 | user->next = (struct user_specs *) 0; | |
3422 | user->filename = arg; | |
3423 | if (user_specs_tail) | |
3424 | user_specs_tail->next = user; | |
3425 | else | |
3426 | user_specs_head = user; | |
3427 | user_specs_tail = user; | |
3428 | } | |
3429 | do_save = false; | |
3430 | break; | |
3431 | ||
3432 | case OPT__sysroot_: | |
3433 | target_system_root = arg; | |
3434 | target_system_root_changed = 1; | |
3435 | do_save = false; | |
3436 | break; | |
3437 | ||
3438 | case OPT_time_: | |
3439 | if (report_times_to_file) | |
3440 | fclose (report_times_to_file); | |
3441 | report_times_to_file = fopen (arg, "a"); | |
3442 | do_save = false; | |
3443 | break; | |
3444 | ||
3445 | case OPT____: | |
3446 | /* "-###" | |
3447 | This is similar to -v except that there is no execution | |
3448 | of the commands and the echoed arguments are quoted. It | |
3449 | is intended for use in shell scripts to capture the | |
3450 | driver-generated command line. */ | |
3451 | verbose_only_flag++; | |
d5478783 | 3452 | verbose_flag = 1; |
603349bf JM |
3453 | do_save = false; |
3454 | break; | |
3455 | ||
3456 | case OPT_B: | |
3457 | { | |
3458 | size_t len = strlen (arg); | |
3459 | ||
3460 | /* Catch the case where the user has forgotten to append a | |
3461 | directory separator to the path. Note, they may be using | |
3462 | -B to add an executable name prefix, eg "i386-elf-", in | |
3463 | order to distinguish between multiple installations of | |
3464 | GCC in the same directory. Hence we must check to see | |
3465 | if appending a directory separator actually makes a | |
3466 | valid directory name. */ | |
3467 | if (!IS_DIR_SEPARATOR (arg[len - 1]) | |
3468 | && is_directory (arg, false)) | |
3469 | { | |
3470 | char *tmp = XNEWVEC (char, len + 2); | |
3471 | strcpy (tmp, arg); | |
3472 | tmp[len] = DIR_SEPARATOR; | |
3473 | tmp[++len] = 0; | |
3474 | arg = tmp; | |
3475 | } | |
3476 | ||
3477 | add_prefix (&exec_prefixes, arg, NULL, | |
3478 | PREFIX_PRIORITY_B_OPT, 0, 0); | |
3479 | add_prefix (&startfile_prefixes, arg, NULL, | |
3480 | PREFIX_PRIORITY_B_OPT, 0, 0); | |
3481 | add_prefix (&include_prefixes, arg, NULL, | |
3482 | PREFIX_PRIORITY_B_OPT, 0, 0); | |
3483 | } | |
3484 | validated = true; | |
3485 | break; | |
3486 | ||
603349bf JM |
3487 | case OPT_x: |
3488 | spec_lang = arg; | |
3489 | if (!strcmp (spec_lang, "none")) | |
3490 | /* Suppress the warning if -xnone comes after the last input | |
3491 | file, because alternate command interfaces like g++ might | |
3492 | find it useful to place -xnone after each input file. */ | |
3493 | spec_lang = 0; | |
3494 | else | |
3495 | last_language_n_infiles = n_infiles; | |
3496 | do_save = false; | |
3497 | break; | |
3498 | ||
603349bf JM |
3499 | case OPT_o: |
3500 | have_o = 1; | |
3501 | #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) || defined(HAVE_TARGET_OBJECT_SUFFIX) | |
3502 | arg = convert_filename (arg, ! have_c, 0); | |
3503 | #endif | |
3504 | /* Save the output name in case -save-temps=obj was used. */ | |
3505 | save_temps_prefix = xstrdup (arg); | |
3506 | /* On some systems, ld cannot handle "-o" without a space. So | |
3507 | split the option from its argument. */ | |
3508 | save_switch ("-o", 1, &arg, validated); | |
3509 | return true; | |
3510 | ||
3511 | case OPT_static_libgcc: | |
3512 | case OPT_shared_libgcc: | |
3513 | case OPT_static_libgfortran: | |
3514 | case OPT_static_libstdc__: | |
3515 | /* These are always valid, since gcc.c itself understands the | |
3516 | first two, gfortranspec.c understands -static-libgfortran and | |
3517 | g++spec.c understands -static-libstdc++ */ | |
3518 | validated = true; | |
3519 | break; | |
3520 | ||
3521 | default: | |
d9d16a19 JM |
3522 | /* Various driver options need no special processing at this |
3523 | point, having been handled in a prescan above or being | |
3524 | handled by specs. */ | |
3525 | break; | |
603349bf JM |
3526 | } |
3527 | ||
3528 | if (do_save) | |
3529 | save_switch (decoded->canonical_option[0], | |
3530 | decoded->canonical_option_num_elements - 1, | |
3531 | &decoded->canonical_option[1], validated); | |
3532 | return true; | |
3533 | } | |
3534 | ||
efe5e5a0 JM |
3535 | /* Put the driver's standard set of option handlers in *HANDLERS. */ |
3536 | ||
3537 | static void | |
3538 | set_option_handlers (struct cl_option_handlers *handlers) | |
3539 | { | |
3540 | handlers->unknown_option_callback = driver_unknown_option_callback; | |
3541 | handlers->wrong_lang_callback = driver_wrong_lang_callback; | |
a7d0d30f | 3542 | handlers->num_handlers = 3; |
efe5e5a0 JM |
3543 | handlers->handlers[0].handler = driver_handle_option; |
3544 | handlers->handlers[0].mask = CL_DRIVER; | |
a7d0d30f JM |
3545 | handlers->handlers[1].handler = common_handle_option; |
3546 | handlers->handlers[1].mask = CL_COMMON; | |
3547 | handlers->handlers[2].handler = target_handle_option; | |
3548 | handlers->handlers[2].mask = CL_TARGET; | |
efe5e5a0 JM |
3549 | } |
3550 | ||
ed1f651b RS |
3551 | /* Create the vector `switches' and its contents. |
3552 | Store its length in `n_switches'. */ | |
3553 | ||
3554 | static void | |
60cf253a JM |
3555 | process_command (unsigned int decoded_options_count, |
3556 | struct cl_decoded_option *decoded_options) | |
ed1f651b | 3557 | { |
878f32c3 KG |
3558 | const char *temp; |
3559 | char *temp1; | |
f4c0a303 | 3560 | const char *tooldir_prefix; |
ba0c638e SB |
3561 | char *(*get_relative_prefix) (const char *, const char *, |
3562 | const char *) = NULL; | |
603349bf | 3563 | struct cl_option_handlers handlers; |
60cf253a | 3564 | unsigned int j; |
ed1f651b | 3565 | |
71f3e391 | 3566 | gcc_exec_prefix = getenv ("GCC_EXEC_PREFIX"); |
8eebb258 | 3567 | |
ed1f651b RS |
3568 | n_switches = 0; |
3569 | n_infiles = 0; | |
a2a05b0a | 3570 | added_libraries = 0; |
2484b6d2 | 3571 | |
53117a2f RK |
3572 | /* Figure compiler version from version string. */ |
3573 | ||
9218435e | 3574 | compiler_version = temp1 = xstrdup (version_string); |
ad85216e | 3575 | |
878f32c3 | 3576 | for (; *temp1; ++temp1) |
53117a2f | 3577 | { |
878f32c3 | 3578 | if (*temp1 == ' ') |
53117a2f | 3579 | { |
878f32c3 | 3580 | *temp1 = '\0'; |
53117a2f RK |
3581 | break; |
3582 | } | |
3583 | } | |
ed1f651b | 3584 | |
ba0c638e SB |
3585 | /* Handle any -no-canonical-prefixes flag early, to assign the function |
3586 | that builds relative prefixes. This function creates default search | |
3587 | paths that are needed later in normal option handling. */ | |
3588 | ||
e200444e | 3589 | for (j = 1; j < decoded_options_count; j++) |
ba0c638e | 3590 | { |
e200444e | 3591 | if (decoded_options[j].opt_index == OPT_no_canonical_prefixes) |
ba0c638e SB |
3592 | { |
3593 | get_relative_prefix = make_relative_prefix_ignore_links; | |
3594 | break; | |
3595 | } | |
3596 | } | |
3597 | if (! get_relative_prefix) | |
3598 | get_relative_prefix = make_relative_prefix; | |
3599 | ||
0deb20df | 3600 | /* Set up the default search paths. If there is no GCC_EXEC_PREFIX, |
60cf253a JM |
3601 | see if we can create it from the pathname specified in |
3602 | decoded_options[0].arg. */ | |
0deb20df | 3603 | |
a8ee6e2d | 3604 | gcc_libexec_prefix = standard_libexec_prefix; |
0deb20df TT |
3605 | #ifndef VMS |
3606 | /* FIXME: make_relative_prefix doesn't yet work for VMS. */ | |
3607 | if (!gcc_exec_prefix) | |
3608 | { | |
60cf253a | 3609 | gcc_exec_prefix = get_relative_prefix (decoded_options[0].arg, |
ba0c638e SB |
3610 | standard_bindir_prefix, |
3611 | standard_exec_prefix); | |
60cf253a | 3612 | gcc_libexec_prefix = get_relative_prefix (decoded_options[0].arg, |
ba0c638e SB |
3613 | standard_bindir_prefix, |
3614 | standard_libexec_prefix); | |
0deb20df | 3615 | if (gcc_exec_prefix) |
47d33318 | 3616 | xputenv (concat ("GCC_EXEC_PREFIX=", gcc_exec_prefix, NULL)); |
0deb20df | 3617 | } |
a8ee6e2d | 3618 | else |
c7370b83 JM |
3619 | { |
3620 | /* make_relative_prefix requires a program name, but | |
3621 | GCC_EXEC_PREFIX is typically a directory name with a trailing | |
3622 | / (which is ignored by make_relative_prefix), so append a | |
3623 | program name. */ | |
3624 | char *tmp_prefix = concat (gcc_exec_prefix, "gcc", NULL); | |
ba0c638e SB |
3625 | gcc_libexec_prefix = get_relative_prefix (tmp_prefix, |
3626 | standard_exec_prefix, | |
3627 | standard_libexec_prefix); | |
f4c0a303 CD |
3628 | |
3629 | /* The path is unrelocated, so fallback to the original setting. */ | |
3630 | if (!gcc_libexec_prefix) | |
3631 | gcc_libexec_prefix = standard_libexec_prefix; | |
3632 | ||
c7370b83 JM |
3633 | free (tmp_prefix); |
3634 | } | |
a8ee6e2d | 3635 | #else |
0deb20df | 3636 | #endif |
f4c0a303 CD |
3637 | /* From this point onward, gcc_exec_prefix is non-null if the toolchain |
3638 | is relocated. The toolchain was either relocated using GCC_EXEC_PREFIX | |
60cf253a JM |
3639 | or an automatically created GCC_EXEC_PREFIX from |
3640 | decoded_options[0].arg. */ | |
ed1f651b | 3641 | |
a288b143 | 3642 | /* Do language-specific adjustment/addition of flags. */ |
d9d16a19 | 3643 | lang_specific_driver (&decoded_options, &decoded_options_count, |
a288b143 AH |
3644 | &added_libraries); |
3645 | ||
8eebb258 | 3646 | if (gcc_exec_prefix) |
ed1f651b | 3647 | { |
6ed4bb9a | 3648 | int len = strlen (gcc_exec_prefix); |
c5c0b3d9 | 3649 | |
a8ee6e2d | 3650 | if (len > (int) sizeof ("/lib/gcc/") - 1 |
509781a4 | 3651 | && (IS_DIR_SEPARATOR (gcc_exec_prefix[len-1]))) |
6ed4bb9a | 3652 | { |
a8ee6e2d | 3653 | temp = gcc_exec_prefix + len - sizeof ("/lib/gcc/") + 1; |
509781a4 | 3654 | if (IS_DIR_SEPARATOR (*temp) |
ba78087b | 3655 | && filename_ncmp (temp + 1, "lib", 3) == 0 |
509781a4 | 3656 | && IS_DIR_SEPARATOR (temp[4]) |
ba78087b | 3657 | && filename_ncmp (temp + 5, "gcc", 3) == 0) |
a8ee6e2d | 3658 | len -= sizeof ("/lib/gcc/") - 1; |
6ed4bb9a MM |
3659 | } |
3660 | ||
3661 | set_std_prefix (gcc_exec_prefix, len); | |
a8ee6e2d | 3662 | add_prefix (&exec_prefixes, gcc_libexec_prefix, "GCC", |
1a5d37a1 | 3663 | PREFIX_PRIORITY_LAST, 0, 0); |
922a4beb | 3664 | add_prefix (&startfile_prefixes, gcc_exec_prefix, "GCC", |
1a5d37a1 | 3665 | PREFIX_PRIORITY_LAST, 0, 0); |
ed1f651b RS |
3666 | } |
3667 | ||
3668 | /* COMPILER_PATH and LIBRARY_PATH have values | |
3669 | that are lists of directory names with colons. */ | |
3670 | ||
71f3e391 | 3671 | temp = getenv ("COMPILER_PATH"); |
ed1f651b RS |
3672 | if (temp) |
3673 | { | |
878f32c3 | 3674 | const char *startp, *endp; |
e1e4cdc4 | 3675 | char *nstore = (char *) alloca (strlen (temp) + 3); |
ed1f651b RS |
3676 | |
3677 | startp = endp = temp; | |
3678 | while (1) | |
3679 | { | |
f6ec7e54 | 3680 | if (*endp == PATH_SEPARATOR || *endp == 0) |
ed1f651b | 3681 | { |
d25a45d4 | 3682 | strncpy (nstore, startp, endp - startp); |
ed1f651b | 3683 | if (endp == startp) |
d4f2852f | 3684 | strcpy (nstore, concat (".", dir_separator_str, NULL)); |
509781a4 | 3685 | else if (!IS_DIR_SEPARATOR (endp[-1])) |
ed1f651b | 3686 | { |
d25a45d4 KH |
3687 | nstore[endp - startp] = DIR_SEPARATOR; |
3688 | nstore[endp - startp + 1] = 0; | |
ed1f651b RS |
3689 | } |
3690 | else | |
d25a45d4 | 3691 | nstore[endp - startp] = 0; |
922a4beb | 3692 | add_prefix (&exec_prefixes, nstore, 0, |
1a5d37a1 | 3693 | PREFIX_PRIORITY_LAST, 0, 0); |
76391e5a | 3694 | add_prefix (&include_prefixes, nstore, 0, |
1a5d37a1 | 3695 | PREFIX_PRIORITY_LAST, 0, 0); |
ed1f651b RS |
3696 | if (*endp == 0) |
3697 | break; | |
3698 | endp = startp = endp + 1; | |
3699 | } | |
3700 | else | |
3701 | endp++; | |
3702 | } | |
3703 | } | |
3704 | ||
71f3e391 | 3705 | temp = getenv (LIBRARY_PATH_ENV); |
fcc9ad83 | 3706 | if (temp && *cross_compile == '0') |
ed1f651b | 3707 | { |
878f32c3 | 3708 | const char *startp, *endp; |
e1e4cdc4 | 3709 | char *nstore = (char *) alloca (strlen (temp) + 3); |
ed1f651b RS |
3710 | |
3711 | startp = endp = temp; | |
3712 | while (1) | |
3713 | { | |
f6ec7e54 | 3714 | if (*endp == PATH_SEPARATOR || *endp == 0) |
ed1f651b | 3715 | { |
d25a45d4 | 3716 | strncpy (nstore, startp, endp - startp); |
ed1f651b | 3717 | if (endp == startp) |
d4f2852f | 3718 | strcpy (nstore, concat (".", dir_separator_str, NULL)); |
509781a4 | 3719 | else if (!IS_DIR_SEPARATOR (endp[-1])) |
ed1f651b | 3720 | { |
d25a45d4 KH |
3721 | nstore[endp - startp] = DIR_SEPARATOR; |
3722 | nstore[endp - startp + 1] = 0; | |
ed1f651b RS |
3723 | } |
3724 | else | |
d25a45d4 | 3725 | nstore[endp - startp] = 0; |
6496a589 | 3726 | add_prefix (&startfile_prefixes, nstore, NULL, |
1a5d37a1 | 3727 | PREFIX_PRIORITY_LAST, 0, 1); |
ed1f651b RS |
3728 | if (*endp == 0) |
3729 | break; | |
3730 | endp = startp = endp + 1; | |
3731 | } | |
3732 | else | |
3733 | endp++; | |
3734 | } | |
3735 | } | |
3736 | ||
3737 | /* Use LPATH like LIBRARY_PATH (for the CMU build program). */ | |
71f3e391 | 3738 | temp = getenv ("LPATH"); |
fcc9ad83 | 3739 | if (temp && *cross_compile == '0') |
ed1f651b | 3740 | { |
878f32c3 | 3741 | const char *startp, *endp; |
e1e4cdc4 | 3742 | char *nstore = (char *) alloca (strlen (temp) + 3); |
ed1f651b RS |
3743 | |
3744 | startp = endp = temp; | |
3745 | while (1) | |
3746 | { | |
f6ec7e54 | 3747 | if (*endp == PATH_SEPARATOR || *endp == 0) |
ed1f651b | 3748 | { |
d25a45d4 | 3749 | strncpy (nstore, startp, endp - startp); |
ed1f651b | 3750 | if (endp == startp) |
d4f2852f | 3751 | strcpy (nstore, concat (".", dir_separator_str, NULL)); |
509781a4 | 3752 | else if (!IS_DIR_SEPARATOR (endp[-1])) |
ed1f651b | 3753 | { |
d25a45d4 KH |
3754 | nstore[endp - startp] = DIR_SEPARATOR; |
3755 | nstore[endp - startp + 1] = 0; | |
ed1f651b RS |
3756 | } |
3757 | else | |
d25a45d4 | 3758 | nstore[endp - startp] = 0; |
6496a589 | 3759 | add_prefix (&startfile_prefixes, nstore, NULL, |
1a5d37a1 | 3760 | PREFIX_PRIORITY_LAST, 0, 1); |
ed1f651b RS |
3761 | if (*endp == 0) |
3762 | break; | |
3763 | endp = startp = endp + 1; | |
3764 | } | |
3765 | else | |
3766 | endp++; | |
3767 | } | |
3768 | } | |
3769 | ||
922e1882 JM |
3770 | /* Process the options and store input files and switches in their |
3771 | vectors. */ | |
3772 | ||
3773 | last_language_n_infiles = -1; | |
ed1f651b | 3774 | |
efe5e5a0 | 3775 | set_option_handlers (&handlers); |
fe7df9c4 | 3776 | |
603349bf JM |
3777 | for (j = 1; j < decoded_options_count; j++) |
3778 | { | |
3779 | switch (decoded_options[j].opt_index) | |
99f78cdd | 3780 | { |
603349bf JM |
3781 | case OPT_S: |
3782 | case OPT_c: | |
3783 | case OPT_E: | |
3784 | have_c = 1; | |
3785 | break; | |
99f78cdd | 3786 | } |
603349bf JM |
3787 | if (have_c) |
3788 | break; | |
3789 | } | |
ed1f651b | 3790 | |
603349bf JM |
3791 | for (j = 1; j < decoded_options_count; j++) |
3792 | { | |
3793 | if (decoded_options[j].opt_index == OPT_SPECIAL_input_file) | |
3a265431 | 3794 | { |
603349bf JM |
3795 | const char *arg = decoded_options[j].arg; |
3796 | const char *p = strrchr (arg, '@'); | |
922e1882 JM |
3797 | char *fname; |
3798 | long offset; | |
3799 | int consumed; | |
3800 | #ifdef HAVE_TARGET_OBJECT_SUFFIX | |
603349bf | 3801 | arg = convert_filename (arg, 0, access (arg, F_OK)); |
922e1882 JM |
3802 | #endif |
3803 | /* For LTO static archive support we handle input file | |
3804 | specifications that are composed of a filename and | |
3805 | an offset like FNAME@OFFSET. */ | |
3806 | if (p | |
603349bf | 3807 | && p != arg |
922e1882 JM |
3808 | && sscanf (p, "@%li%n", &offset, &consumed) >= 1 |
3809 | && strlen (p) == (unsigned int)consumed) | |
3810 | { | |
603349bf JM |
3811 | fname = (char *)xmalloc (p - arg + 1); |
3812 | memcpy (fname, arg, p - arg); | |
3813 | fname[p - arg] = '\0'; | |
922e1882 JM |
3814 | /* Only accept non-stdin and existing FNAME parts, otherwise |
3815 | try with the full name. */ | |
3816 | if (strcmp (fname, "-") == 0 || access (fname, F_OK) < 0) | |
3817 | { | |
3818 | free (fname); | |
603349bf | 3819 | fname = xstrdup (arg); |
922e1882 JM |
3820 | } |
3821 | } | |
3822 | else | |
603349bf | 3823 | fname = xstrdup (arg); |
922e1882 JM |
3824 | |
3825 | if (strcmp (fname, "-") != 0 && access (fname, F_OK) < 0) | |
3826 | perror_with_name (fname); | |
3827 | else | |
603349bf | 3828 | add_infile (arg, spec_lang); |
922e1882 JM |
3829 | |
3830 | free (fname); | |
603349bf | 3831 | continue; |
3a265431 | 3832 | } |
603349bf | 3833 | |
d4d24ba4 | 3834 | read_cmdline_option (&global_options, &global_options_set, |
a4d8c676 JM |
3835 | decoded_options + j, UNKNOWN_LOCATION, |
3836 | CL_DRIVER, &handlers, global_dc); | |
ed1f651b RS |
3837 | } |
3838 | ||
14fdc613 MM |
3839 | /* If -save-temps=obj and -o name, create the prefix to use for %b. |
3840 | Otherwise just make -save-temps=obj the same as -save-temps=cwd. */ | |
3841 | if (save_temps_flag == SAVE_TEMPS_OBJ && save_temps_prefix != NULL) | |
3842 | { | |
3843 | save_temps_length = strlen (save_temps_prefix); | |
3844 | temp = strrchr (lbasename (save_temps_prefix), '.'); | |
3845 | if (temp) | |
3846 | { | |
3847 | save_temps_length -= strlen (temp); | |
3848 | save_temps_prefix[save_temps_length] = '\0'; | |
3849 | } | |
3850 | ||
3851 | } | |
3852 | else if (save_temps_prefix != NULL) | |
3853 | { | |
3854 | free (save_temps_prefix); | |
3855 | save_temps_prefix = NULL; | |
3856 | } | |
3857 | ||
054e88a8 | 3858 | if (save_temps_flag && use_pipes) |
4977bab6 ZW |
3859 | { |
3860 | /* -save-temps overrides -pipe, so that temp files are produced */ | |
3861 | if (save_temps_flag) | |
2dec80c7 | 3862 | warning (0, "-pipe ignored because -save-temps specified"); |
4977bab6 ZW |
3863 | use_pipes = 0; |
3864 | } | |
1d088dee | 3865 | |
2153915d AO |
3866 | if (!compare_debug) |
3867 | { | |
3868 | const char *gcd = getenv ("GCC_COMPARE_DEBUG"); | |
3869 | ||
3870 | if (gcd && gcd[0] == '-') | |
3871 | { | |
3872 | compare_debug = 2; | |
3873 | compare_debug_opt = gcd; | |
2153915d AO |
3874 | } |
3875 | else if (gcd && *gcd && strcmp (gcd, "0")) | |
3876 | { | |
3877 | compare_debug = 3; | |
3878 | compare_debug_opt = "-gtoggle"; | |
2153915d AO |
3879 | } |
3880 | } | |
3881 | else if (compare_debug < 0) | |
3882 | { | |
3883 | compare_debug = 0; | |
3884 | gcc_assert (!compare_debug_opt); | |
3885 | } | |
3886 | ||
f4c0a303 CD |
3887 | /* Set up the search paths. We add directories that we expect to |
3888 | contain GNU Toolchain components before directories specified by | |
3889 | the machine description so that we will find GNU components (like | |
b8698a0f | 3890 | the GNU assembler) before those of the host system. */ |
ed1f651b | 3891 | |
f4c0a303 CD |
3892 | /* If we don't know where the toolchain has been installed, use the |
3893 | configured-in locations. */ | |
3894 | if (!gcc_exec_prefix) | |
3895 | { | |
48ff801b | 3896 | #ifndef OS2 |
f4c0a303 CD |
3897 | add_prefix (&exec_prefixes, standard_libexec_prefix, "GCC", |
3898 | PREFIX_PRIORITY_LAST, 1, 0); | |
3899 | add_prefix (&exec_prefixes, standard_libexec_prefix, "BINUTILS", | |
3900 | PREFIX_PRIORITY_LAST, 2, 0); | |
3901 | add_prefix (&exec_prefixes, standard_exec_prefix, "BINUTILS", | |
3902 | PREFIX_PRIORITY_LAST, 2, 0); | |
48ff801b | 3903 | #endif |
f4c0a303 CD |
3904 | add_prefix (&startfile_prefixes, standard_exec_prefix, "BINUTILS", |
3905 | PREFIX_PRIORITY_LAST, 1, 0); | |
3906 | } | |
ed1f651b | 3907 | |
f4c0a303 | 3908 | gcc_assert (!IS_ABSOLUTE_PATH (tooldir_base_prefix)); |
9218435e | 3909 | tooldir_prefix = concat (tooldir_base_prefix, spec_machine, |
d4f2852f | 3910 | dir_separator_str, NULL); |
c648ab8a | 3911 | |
f4c0a303 CD |
3912 | /* Look for tools relative to the location from which the driver is |
3913 | running, or, if that is not available, the configured prefix. */ | |
3914 | tooldir_prefix | |
3915 | = concat (gcc_exec_prefix ? gcc_exec_prefix : standard_exec_prefix, | |
3916 | spec_machine, dir_separator_str, | |
3917 | spec_version, dir_separator_str, tooldir_prefix, NULL); | |
c648ab8a | 3918 | |
9218435e | 3919 | add_prefix (&exec_prefixes, |
d4f2852f | 3920 | concat (tooldir_prefix, "bin", dir_separator_str, NULL), |
1a5d37a1 | 3921 | "BINUTILS", PREFIX_PRIORITY_LAST, 0, 0); |
48ff801b | 3922 | add_prefix (&startfile_prefixes, |
d4f2852f | 3923 | concat (tooldir_prefix, "lib", dir_separator_str, NULL), |
1a5d37a1 | 3924 | "BINUTILS", PREFIX_PRIORITY_LAST, 0, 1); |
f18fd956 | 3925 | |
047d636f DJ |
3926 | #if defined(TARGET_SYSTEM_ROOT_RELOCATABLE) && !defined(VMS) |
3927 | /* If the normal TARGET_SYSTEM_ROOT is inside of $exec_prefix, | |
3928 | then consider it to relocate with the rest of the GCC installation | |
3929 | if GCC_EXEC_PREFIX is set. | |
3930 | ``make_relative_prefix'' is not compiled for VMS, so don't call it. */ | |
922e1882 | 3931 | if (target_system_root && !target_system_root_changed && gcc_exec_prefix) |
4977bab6 | 3932 | { |
60cf253a | 3933 | char *tmp_prefix = get_relative_prefix (decoded_options[0].arg, |
ba0c638e SB |
3934 | standard_bindir_prefix, |
3935 | target_system_root); | |
4977bab6 | 3936 | if (tmp_prefix && access_check (tmp_prefix, F_OK) == 0) |
047d636f DJ |
3937 | { |
3938 | target_system_root = tmp_prefix; | |
3939 | target_system_root_changed = 1; | |
3940 | } | |
4977bab6 | 3941 | } |
047d636f | 3942 | #endif |
4977bab6 | 3943 | |
004fd4d5 RS |
3944 | /* More prefixes are enabled in main, after we read the specs file |
3945 | and determine whether this is cross-compilation or not. */ | |
ed1f651b | 3946 | |
fa0d5369 | 3947 | if (n_infiles == last_language_n_infiles && spec_lang != 0) |
bdc6b402 | 3948 | warning (0, "%<-x %s%> after last input file has no effect", spec_lang); |
ed1f651b | 3949 | |
2153915d AO |
3950 | if (compare_debug == 2 || compare_debug == 3) |
3951 | { | |
922e1882 | 3952 | alloc_switch (); |
2153915d AO |
3953 | switches[n_switches].part1 = concat ("fcompare-debug=", |
3954 | compare_debug_opt, | |
3955 | NULL); | |
3956 | switches[n_switches].args = 0; | |
3957 | switches[n_switches].live_cond = 0; | |
3958 | switches[n_switches].validated = 0; | |
3959 | switches[n_switches].ordering = 0; | |
3960 | n_switches++; | |
3961 | compare_debug = 1; | |
3962 | } | |
3963 | ||
69927b59 | 3964 | /* Ensure we only invoke each subprocess once. */ |
41fd0f9b | 3965 | if (print_subprocess_help || print_help_list || print_version) |
69927b59 | 3966 | { |
922e1882 | 3967 | n_infiles = 0; |
69927b59 | 3968 | |
c662432e NC |
3969 | /* Create a dummy input file, so that we can pass |
3970 | the help option on to the various sub-processes. */ | |
922e1882 | 3971 | add_infile ("help-dummy", "c"); |
69927b59 NB |
3972 | } |
3973 | ||
922e1882 | 3974 | alloc_switch (); |
ed1f651b | 3975 | switches[n_switches].part1 = 0; |
922e1882 | 3976 | alloc_infile (); |
ed1f651b RS |
3977 | infiles[n_infiles].name = 0; |
3978 | } | |
b856c15d | 3979 | |
4977bab6 | 3980 | /* Store switches not filtered out by %<S in spec in COLLECT_GCC_OPTIONS |
b856c15d RO |
3981 | and place that in the environment. */ |
3982 | ||
3983 | static void | |
1d088dee | 3984 | set_collect_gcc_options (void) |
b856c15d RO |
3985 | { |
3986 | int i; | |
3987 | int first_time; | |
3988 | ||
3989 | /* Build COLLECT_GCC_OPTIONS to have all of the options specified to | |
3990 | the compiler. */ | |
3991 | obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=", | |
3992 | sizeof ("COLLECT_GCC_OPTIONS=") - 1); | |
3993 | ||
3994 | first_time = TRUE; | |
3995 | for (i = 0; (int) i < n_switches; i++) | |
3996 | { | |
3997 | const char *const *args; | |
3998 | const char *p, *q; | |
3999 | if (!first_time) | |
4000 | obstack_grow (&collect_obstack, " ", 1); | |
4001 | ||
4002 | first_time = FALSE; | |
4003 | ||
4004 | /* Ignore elided switches. */ | |
96f5b137 L |
4005 | if ((switches[i].live_cond |
4006 | & (SWITCH_IGNORE | SWITCH_KEEP_FOR_GCC)) | |
4007 | == SWITCH_IGNORE) | |
b856c15d RO |
4008 | continue; |
4009 | ||
4010 | obstack_grow (&collect_obstack, "'-", 2); | |
4011 | q = switches[i].part1; | |
4012 | while ((p = strchr (q, '\''))) | |
4013 | { | |
4014 | obstack_grow (&collect_obstack, q, p - q); | |
4015 | obstack_grow (&collect_obstack, "'\\''", 4); | |
4016 | q = ++p; | |
4017 | } | |
4018 | obstack_grow (&collect_obstack, q, strlen (q)); | |
4019 | obstack_grow (&collect_obstack, "'", 1); | |
4020 | ||
4021 | for (args = switches[i].args; args && *args; args++) | |
4022 | { | |
4023 | obstack_grow (&collect_obstack, " '", 2); | |
4024 | q = *args; | |
4025 | while ((p = strchr (q, '\''))) | |
4026 | { | |
4027 | obstack_grow (&collect_obstack, q, p - q); | |
4028 | obstack_grow (&collect_obstack, "'\\''", 4); | |
4029 | q = ++p; | |
4030 | } | |
4031 | obstack_grow (&collect_obstack, q, strlen (q)); | |
4032 | obstack_grow (&collect_obstack, "'", 1); | |
4033 | } | |
4034 | } | |
4035 | obstack_grow (&collect_obstack, "\0", 1); | |
47d33318 | 4036 | xputenv (XOBFINISH (&collect_obstack, char *)); |
b856c15d | 4037 | } |
ed1f651b RS |
4038 | \f |
4039 | /* Process a spec string, accumulating and running commands. */ | |
4040 | ||
4041 | /* These variables describe the input file name. | |
4042 | input_file_number is the index on outfiles of this file, | |
4043 | so that the output file name can be stored for later use by %o. | |
4044 | input_basename is the start of the part of the input file | |
4045 | sans all directory names, and basename_length is the number | |
4046 | of characters starting there excluding the suffix .c or whatever. */ | |
4047 | ||
6afbc885 | 4048 | static const char *gcc_input_filename; |
ed1f651b | 4049 | static int input_file_number; |
f271358e | 4050 | size_t input_filename_length; |
ed1f651b | 4051 | static int basename_length; |
ea414c97 | 4052 | static int suffixed_basename_length; |
878f32c3 KG |
4053 | static const char *input_basename; |
4054 | static const char *input_suffix; | |
a9024779 | 4055 | #ifndef HOST_LACKS_INODE_NUMBERS |
99f78cdd | 4056 | static struct stat input_stat; |
a9024779 | 4057 | #endif |
99f78cdd | 4058 | static int input_stat_set; |
ed1f651b | 4059 | |
a9374841 MM |
4060 | /* The compiler used to process the current input file. */ |
4061 | static struct compiler *input_file_compiler; | |
4062 | ||
ed1f651b RS |
4063 | /* These are variables used within do_spec and do_spec_1. */ |
4064 | ||
4065 | /* Nonzero if an arg has been started and not yet terminated | |
4066 | (with space, tab or newline). */ | |
4067 | static int arg_going; | |
4068 | ||
4069 | /* Nonzero means %d or %g has been seen; the next arg to be terminated | |
4070 | is a temporary file name. */ | |
4071 | static int delete_this_arg; | |
4072 | ||
4073 | /* Nonzero means %w has been seen; the next arg to be terminated | |
4074 | is the output file name of this compilation. */ | |
4075 | static int this_is_output_file; | |
4076 | ||
4077 | /* Nonzero means %s has been seen; the next arg to be terminated | |
4078 | is the name of a library file and we should try the standard | |
4079 | search dirs for it. */ | |
4080 | static int this_is_library_file; | |
4081 | ||
3beb864c NC |
4082 | /* Nonzero means %T has been seen; the next arg to be terminated |
4083 | is the name of a linker script and we should try all of the | |
4084 | standard search dirs for it. If it is found insert a --script | |
4085 | command line switch and then substitute the full path in place, | |
4086 | otherwise generate an error message. */ | |
4087 | static int this_is_linker_script; | |
4088 | ||
a99bf70c JW |
4089 | /* Nonzero means that the input of this command is coming from a pipe. */ |
4090 | static int input_from_pipe; | |
4091 | ||
11972f66 | 4092 | /* Nonnull means substitute this for any suffix when outputting a switches |
dc297297 | 4093 | arguments. */ |
11972f66 NS |
4094 | static const char *suffix_subst; |
4095 | ||
13e7cedb DH |
4096 | /* If there is an argument being accumulated, terminate it and store it. */ |
4097 | ||
4098 | static void | |
4099 | end_going_arg (void) | |
4100 | { | |
4101 | if (arg_going) | |
4102 | { | |
4103 | const char *string; | |
4104 | ||
4105 | obstack_1grow (&obstack, 0); | |
4106 | string = XOBFINISH (&obstack, const char *); | |
4107 | if (this_is_library_file) | |
4108 | string = find_file (string); | |
3beb864c NC |
4109 | if (this_is_linker_script) |
4110 | { | |
4111 | char * full_script_path = find_a_file (&startfile_prefixes, string, R_OK, true); | |
4112 | ||
4113 | if (full_script_path == NULL) | |
4114 | { | |
bdc6b402 | 4115 | error ("unable to locate default linker script %qs in the library search paths", string); |
3beb864c NC |
4116 | /* Script was not found on search path. */ |
4117 | return; | |
4118 | } | |
4119 | store_arg ("--script", false, false); | |
4120 | string = full_script_path; | |
4121 | } | |
13e7cedb DH |
4122 | store_arg (string, delete_this_arg, this_is_output_file); |
4123 | if (this_is_output_file) | |
4124 | outfiles[input_file_number] = string; | |
4125 | arg_going = 0; | |
4126 | } | |
4127 | } | |
4128 | ||
fe7df9c4 SP |
4129 | |
4130 | /* Parse the WRAPPER string which is a comma separated list of the command line | |
4131 | and insert them into the beginning of argbuf. */ | |
4132 | ||
4133 | static void | |
4134 | insert_wrapper (const char *wrapper) | |
4135 | { | |
4136 | int n = 0; | |
4137 | int i; | |
4138 | char *buf = xstrdup (wrapper); | |
4139 | char *p = buf; | |
5b634ee0 | 4140 | unsigned int old_length = VEC_length (const_char_p, argbuf); |
fe7df9c4 SP |
4141 | |
4142 | do | |
4143 | { | |
4144 | n++; | |
4145 | while (*p == ',') | |
4146 | p++; | |
4147 | } | |
4148 | while ((p = strchr (p, ',')) != NULL); | |
4149 | ||
5b634ee0 JM |
4150 | VEC_safe_grow (const_char_p, heap, argbuf, old_length + n); |
4151 | memmove (VEC_address (const_char_p, argbuf) + n, | |
4152 | VEC_address (const_char_p, argbuf), | |
4153 | old_length * sizeof (const_char_p)); | |
fe7df9c4 SP |
4154 | |
4155 | i = 0; | |
4156 | p = buf; | |
4157 | do | |
4158 | { | |
4159 | while (*p == ',') | |
4160 | { | |
4161 | *p = 0; | |
4162 | p++; | |
4163 | } | |
5b634ee0 JM |
4164 | VEC_replace (const_char_p, argbuf, i, p); |
4165 | i++; | |
fe7df9c4 SP |
4166 | } |
4167 | while ((p = strchr (p, ',')) != NULL); | |
4168 | gcc_assert (i == n); | |
fe7df9c4 SP |
4169 | } |
4170 | ||
ed1f651b RS |
4171 | /* Process the spec SPEC and run the commands specified therein. |
4172 | Returns 0 if the spec is successfully processed; -1 if failed. */ | |
4173 | ||
f271358e | 4174 | int |
1d088dee | 4175 | do_spec (const char *spec) |
ed1f651b RS |
4176 | { |
4177 | int value; | |
4178 | ||
343f59d9 | 4179 | value = do_spec_2 (spec); |
ed1f651b RS |
4180 | |
4181 | /* Force out any unfinished command. | |
4182 | If -pipe, this forces out the last command if it ended in `|'. */ | |
4183 | if (value == 0) | |
4184 | { | |
5b634ee0 JM |
4185 | if (VEC_length (const_char_p, argbuf) > 0 |
4186 | && !strcmp (VEC_last (const_char_p, argbuf), "|")) | |
4187 | VEC_pop (const_char_p, argbuf); | |
ed1f651b | 4188 | |
b856c15d RO |
4189 | set_collect_gcc_options (); |
4190 | ||
5b634ee0 | 4191 | if (VEC_length (const_char_p, argbuf) > 0) |
ed1f651b RS |
4192 | value = execute (); |
4193 | } | |
4194 | ||
4195 | return value; | |
4196 | } | |
4197 | ||
343f59d9 | 4198 | static int |
1d088dee | 4199 | do_spec_2 (const char *spec) |
343f59d9 | 4200 | { |
6544fbcb RS |
4201 | int result; |
4202 | ||
343f59d9 AM |
4203 | clear_args (); |
4204 | arg_going = 0; | |
4205 | delete_this_arg = 0; | |
4206 | this_is_output_file = 0; | |
4207 | this_is_library_file = 0; | |
3beb864c | 4208 | this_is_linker_script = 0; |
343f59d9 AM |
4209 | input_from_pipe = 0; |
4210 | suffix_subst = NULL; | |
4211 | ||
6544fbcb RS |
4212 | result = do_spec_1 (spec, 0, NULL); |
4213 | ||
13e7cedb | 4214 | end_going_arg (); |
6544fbcb RS |
4215 | |
4216 | return result; | |
343f59d9 AM |
4217 | } |
4218 | ||
db36994b | 4219 | |
7816bea0 DJ |
4220 | /* Process the given spec string and add any new options to the end |
4221 | of the switches/n_switches array. */ | |
4222 | ||
4223 | static void | |
1d088dee | 4224 | do_option_spec (const char *name, const char *spec) |
7816bea0 DJ |
4225 | { |
4226 | unsigned int i, value_count, value_len; | |
4227 | const char *p, *q, *value; | |
4228 | char *tmp_spec, *tmp_spec_p; | |
4229 | ||
4230 | if (configure_default_options[0].name == NULL) | |
4231 | return; | |
4232 | ||
4233 | for (i = 0; i < ARRAY_SIZE (configure_default_options); i++) | |
4234 | if (strcmp (configure_default_options[i].name, name) == 0) | |
4235 | break; | |
4236 | if (i == ARRAY_SIZE (configure_default_options)) | |
4237 | return; | |
4238 | ||
4239 | value = configure_default_options[i].value; | |
4240 | value_len = strlen (value); | |
4241 | ||
4242 | /* Compute the size of the final spec. */ | |
4243 | value_count = 0; | |
4244 | p = spec; | |
4245 | while ((p = strstr (p, "%(VALUE)")) != NULL) | |
4246 | { | |
4247 | p ++; | |
4248 | value_count ++; | |
4249 | } | |
4250 | ||
4251 | /* Replace each %(VALUE) by the specified value. */ | |
e1e4cdc4 | 4252 | tmp_spec = (char *) alloca (strlen (spec) + 1 |
7816bea0 DJ |
4253 | + value_count * (value_len - strlen ("%(VALUE)"))); |
4254 | tmp_spec_p = tmp_spec; | |
4255 | q = spec; | |
4256 | while ((p = strstr (q, "%(VALUE)")) != NULL) | |
4257 | { | |
4258 | memcpy (tmp_spec_p, q, p - q); | |
4259 | tmp_spec_p = tmp_spec_p + (p - q); | |
4260 | memcpy (tmp_spec_p, value, value_len); | |
4261 | tmp_spec_p += value_len; | |
4262 | q = p + strlen ("%(VALUE)"); | |
4263 | } | |
4264 | strcpy (tmp_spec_p, q); | |
4265 | ||
4266 | do_self_spec (tmp_spec); | |
4267 | } | |
4268 | ||
db36994b RS |
4269 | /* Process the given spec string and add any new options to the end |
4270 | of the switches/n_switches array. */ | |
4271 | ||
4272 | static void | |
1d088dee | 4273 | do_self_spec (const char *spec) |
db36994b | 4274 | { |
94b90527 JJ |
4275 | int i; |
4276 | ||
db36994b RS |
4277 | do_spec_2 (spec); |
4278 | do_spec_1 (" ", 0, NULL); | |
4279 | ||
94b90527 JJ |
4280 | /* Mark %<S switches processed by do_self_spec to be ignored permanently. |
4281 | do_self_specs adds the replacements to switches array, so it shouldn't | |
4282 | be processed afterwards. */ | |
4283 | for (i = 0; i < n_switches; i++) | |
4284 | if ((switches[i].live_cond & SWITCH_IGNORE)) | |
4285 | switches[i].live_cond |= SWITCH_IGNORE_PERMANENTLY; | |
4286 | ||
5b634ee0 | 4287 | if (VEC_length (const_char_p, argbuf) > 0) |
db36994b | 4288 | { |
efe5e5a0 JM |
4289 | const char **argbuf_copy; |
4290 | struct cl_decoded_option *decoded_options; | |
4291 | struct cl_option_handlers handlers; | |
4292 | unsigned int decoded_options_count; | |
4293 | unsigned int j; | |
db36994b | 4294 | |
efe5e5a0 JM |
4295 | /* Create a copy of argbuf with a dummy argv[0] entry for |
4296 | decode_cmdline_options_to_array. */ | |
5b634ee0 JM |
4297 | argbuf_copy = XNEWVEC (const char *, |
4298 | VEC_length (const_char_p, argbuf) + 1); | |
efe5e5a0 | 4299 | argbuf_copy[0] = ""; |
5b634ee0 JM |
4300 | memcpy (argbuf_copy + 1, VEC_address (const_char_p, argbuf), |
4301 | VEC_length (const_char_p, argbuf) * sizeof (const char *)); | |
db36994b | 4302 | |
5b634ee0 JM |
4303 | decode_cmdline_options_to_array (VEC_length (const_char_p, argbuf) + 1, |
4304 | argbuf_copy, | |
efe5e5a0 JM |
4305 | CL_DRIVER, &decoded_options, |
4306 | &decoded_options_count); | |
2153915d | 4307 | |
efe5e5a0 | 4308 | set_option_handlers (&handlers); |
2153915d | 4309 | |
efe5e5a0 JM |
4310 | for (j = 1; j < decoded_options_count; j++) |
4311 | { | |
4312 | switch (decoded_options[j].opt_index) | |
2153915d | 4313 | { |
efe5e5a0 JM |
4314 | case OPT_SPECIAL_input_file: |
4315 | /* Specs should only generate options, not input | |
4316 | files. */ | |
4317 | if (strcmp (decoded_options[j].arg, "-") != 0) | |
4318 | fatal_error ("switch %qs does not start with %<-%>", | |
4319 | decoded_options[j].arg); | |
4320 | else | |
4321 | fatal_error ("spec-generated switch is just %<-%>"); | |
4322 | break; | |
2153915d | 4323 | |
efe5e5a0 JM |
4324 | case OPT_fcompare_debug_second: |
4325 | case OPT_fcompare_debug: | |
4326 | case OPT_fcompare_debug_: | |
4327 | case OPT_o: | |
4328 | /* Avoid duplicate processing of some options from | |
4329 | compare-debug specs; just save them here. */ | |
4330 | save_switch (decoded_options[j].canonical_option[0], | |
4331 | (decoded_options[j].canonical_option_num_elements | |
4332 | - 1), | |
4333 | &decoded_options[j].canonical_option[1], false); | |
4334 | break; | |
4335 | ||
4336 | default: | |
4337 | read_cmdline_option (&global_options, &global_options_set, | |
a4d8c676 JM |
4338 | decoded_options + j, UNKNOWN_LOCATION, |
4339 | CL_DRIVER, &handlers, global_dc); | |
efe5e5a0 | 4340 | break; |
2153915d | 4341 | } |
db36994b | 4342 | } |
2153915d | 4343 | |
efe5e5a0 | 4344 | alloc_switch (); |
2153915d | 4345 | switches[n_switches].part1 = 0; |
db36994b RS |
4346 | } |
4347 | } | |
4348 | ||
00dcee0c AM |
4349 | /* Callback for processing %D and %I specs. */ |
4350 | ||
4351 | struct spec_path_info { | |
4352 | const char *option; | |
4353 | const char *append; | |
4354 | size_t append_len; | |
4355 | bool omit_relative; | |
4356 | bool separate_options; | |
4357 | }; | |
4358 | ||
4359 | static void * | |
4360 | spec_path (char *path, void *data) | |
76391e5a | 4361 | { |
e1e4cdc4 | 4362 | struct spec_path_info *info = (struct spec_path_info *) data; |
00dcee0c AM |
4363 | size_t len = 0; |
4364 | char save = 0; | |
76391e5a | 4365 | |
00dcee0c AM |
4366 | if (info->omit_relative && !IS_ABSOLUTE_PATH (path)) |
4367 | return NULL; | |
4368 | ||
4369 | if (info->append_len != 0) | |
76391e5a | 4370 | { |
00dcee0c AM |
4371 | len = strlen (path); |
4372 | memcpy (path + len, info->append, info->append_len + 1); | |
76391e5a PB |
4373 | } |
4374 | ||
00dcee0c AM |
4375 | if (!is_directory (path, true)) |
4376 | return NULL; | |
76391e5a | 4377 | |
00dcee0c AM |
4378 | do_spec_1 (info->option, 1, NULL); |
4379 | if (info->separate_options) | |
4380 | do_spec_1 (" ", 0, NULL); | |
4381 | ||
4382 | if (info->append_len == 0) | |
76391e5a | 4383 | { |
00dcee0c AM |
4384 | len = strlen (path); |
4385 | save = path[len - 1]; | |
4386 | if (IS_DIR_SEPARATOR (path[len - 1])) | |
4387 | path[len - 1] = '\0'; | |
76391e5a | 4388 | } |
00dcee0c AM |
4389 | |
4390 | do_spec_1 (path, 1, NULL); | |
4391 | do_spec_1 (" ", 0, NULL); | |
4392 | ||
4393 | /* Must not damage the original path. */ | |
4394 | if (info->append_len == 0) | |
4395 | path[len - 1] = save; | |
4396 | ||
4397 | return NULL; | |
76391e5a PB |
4398 | } |
4399 | ||
5a691e98 RAE |
4400 | /* Create a temporary FILE with the contents of ARGV. Add @FILE to the |
4401 | argument list. */ | |
4402 | ||
4403 | static void | |
4404 | create_at_file (char **argv) | |
4405 | { | |
4406 | char *temp_file = make_temp_file (""); | |
4407 | char *at_argument = concat ("@", temp_file, NULL); | |
4408 | FILE *f = fopen (temp_file, "w"); | |
4409 | int status; | |
4410 | ||
4411 | if (f == NULL) | |
2dec80c7 JM |
4412 | fatal_error ("could not open temporary response file %s", |
4413 | temp_file); | |
5a691e98 RAE |
4414 | |
4415 | status = writeargv (argv, f); | |
4416 | ||
4417 | if (status) | |
2dec80c7 JM |
4418 | fatal_error ("could not write to temporary response file %s", |
4419 | temp_file); | |
5a691e98 RAE |
4420 | |
4421 | status = fclose (f); | |
4422 | ||
4423 | if (EOF == status) | |
2dec80c7 JM |
4424 | fatal_error ("could not close temporary response file %s", |
4425 | temp_file); | |
5a691e98 RAE |
4426 | |
4427 | store_arg (at_argument, 0, 0); | |
4428 | ||
4429 | record_temp_file (temp_file, !save_temps_flag, !save_temps_flag); | |
4430 | } | |
4431 | ||
4432 | /* True if we should compile INFILE. */ | |
4433 | ||
4434 | static bool | |
4435 | compile_input_file_p (struct infile *infile) | |
4436 | { | |
4437 | if ((!infile->language) || (infile->language[0] != '*')) | |
4438 | if (infile->incompiler == input_file_compiler) | |
4439 | return true; | |
4440 | return false; | |
4441 | } | |
4442 | ||
69d540bd NF |
4443 | /* Process each member of VEC as a spec. */ |
4444 | ||
4445 | static void | |
4446 | do_specs_vec (VEC(char_p,heap) *vec) | |
4447 | { | |
4448 | unsigned ix; | |
4449 | char *opt; | |
4450 | ||
4451 | FOR_EACH_VEC_ELT (char_p, vec, ix, opt) | |
4452 | { | |
4453 | do_spec_1 (opt, 1, NULL); | |
4454 | /* Make each accumulated option a separate argument. */ | |
4455 | do_spec_1 (" ", 0, NULL); | |
4456 | } | |
4457 | } | |
4458 | ||
ed1f651b RS |
4459 | /* Process the sub-spec SPEC as a portion of a larger spec. |
4460 | This is like processing a whole spec except that we do | |
4461 | not initialize at the beginning and we do not supply a | |
4462 | newline by default at the end. | |
4463 | INSWITCH nonzero means don't process %-sequences in SPEC; | |
4464 | in this case, % is treated as an ordinary character. | |
4465 | This is used while substituting switches. | |
4466 | INSWITCH nonzero also causes SPC not to terminate an argument. | |
4467 | ||
4468 | Value is zero unless a line was finished | |
4469 | and the command on that line reported an error. */ | |
4470 | ||
4471 | static int | |
1d088dee | 4472 | do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part) |
ed1f651b | 4473 | { |
b3694847 SS |
4474 | const char *p = spec; |
4475 | int c; | |
ed1f651b | 4476 | int i; |
3279bba6 | 4477 | int value; |
ed1f651b | 4478 | |
7fcf46f5 JZ |
4479 | /* If it's an empty string argument to a switch, keep it as is. */ |
4480 | if (inswitch && !*p) | |
4481 | arg_going = 1; | |
4482 | ||
ededb2fc | 4483 | while ((c = *p++)) |
ed1f651b RS |
4484 | /* If substituting a switch, treat all chars like letters. |
4485 | Otherwise, NL, SPC, TAB and % are special. */ | |
4486 | switch (inswitch ? 'a' : c) | |
4487 | { | |
4488 | case '\n': | |
13e7cedb | 4489 | end_going_arg (); |
ed1f651b | 4490 | |
5b634ee0 JM |
4491 | if (VEC_length (const_char_p, argbuf) > 0 |
4492 | && !strcmp (VEC_last (const_char_p, argbuf), "|")) | |
ed1f651b | 4493 | { |
ed1f651b RS |
4494 | /* A `|' before the newline means use a pipe here, |
4495 | but only if -pipe was specified. | |
4496 | Otherwise, execute now and don't pass the `|' as an arg. */ | |
4977bab6 | 4497 | if (use_pipes) |
ed1f651b | 4498 | { |
a99bf70c | 4499 | input_from_pipe = 1; |
ed1f651b RS |
4500 | break; |
4501 | } | |
4502 | else | |
5b634ee0 | 4503 | VEC_pop (const_char_p, argbuf); |
ed1f651b RS |
4504 | } |
4505 | ||
b856c15d RO |
4506 | set_collect_gcc_options (); |
4507 | ||
5b634ee0 | 4508 | if (VEC_length (const_char_p, argbuf) > 0) |
ed1f651b | 4509 | { |
3279bba6 | 4510 | value = execute (); |
ed1f651b RS |
4511 | if (value) |
4512 | return value; | |
4513 | } | |
4514 | /* Reinitialize for a new command, and for a new argument. */ | |
4515 | clear_args (); | |
4516 | arg_going = 0; | |
4517 | delete_this_arg = 0; | |
4518 | this_is_output_file = 0; | |
4519 | this_is_library_file = 0; | |
3beb864c | 4520 | this_is_linker_script = 0; |
a99bf70c | 4521 | input_from_pipe = 0; |
ed1f651b RS |
4522 | break; |
4523 | ||
4524 | case '|': | |
13e7cedb | 4525 | end_going_arg (); |
ed1f651b RS |
4526 | |
4527 | /* Use pipe */ | |
4528 | obstack_1grow (&obstack, c); | |
4529 | arg_going = 1; | |
4530 | break; | |
4531 | ||
4532 | case '\t': | |
4533 | case ' ': | |
13e7cedb DH |
4534 | end_going_arg (); |
4535 | ||
ed1f651b | 4536 | /* Reinitialize for a new argument. */ |
ed1f651b RS |
4537 | delete_this_arg = 0; |
4538 | this_is_output_file = 0; | |
4539 | this_is_library_file = 0; | |
3beb864c | 4540 | this_is_linker_script = 0; |
ed1f651b RS |
4541 | break; |
4542 | ||
4543 | case '%': | |
4544 | switch (c = *p++) | |
4545 | { | |
4546 | case 0: | |
bdc6b402 | 4547 | fatal_error ("spec %qs invalid", spec); |
ed1f651b RS |
4548 | |
4549 | case 'b': | |
14fdc613 MM |
4550 | if (save_temps_length) |
4551 | obstack_grow (&obstack, save_temps_prefix, save_temps_length); | |
4552 | else | |
4553 | obstack_grow (&obstack, input_basename, basename_length); | |
2153915d AO |
4554 | if (compare_debug < 0) |
4555 | obstack_grow (&obstack, ".gk", 3); | |
ed1f651b RS |
4556 | arg_going = 1; |
4557 | break; | |
4558 | ||
ea414c97 | 4559 | case 'B': |
14fdc613 MM |
4560 | if (save_temps_length) |
4561 | obstack_grow (&obstack, save_temps_prefix, save_temps_length); | |
4562 | else | |
4563 | obstack_grow (&obstack, input_basename, suffixed_basename_length); | |
2153915d AO |
4564 | if (compare_debug < 0) |
4565 | obstack_grow (&obstack, ".gk", 3); | |
ea414c97 ZW |
4566 | arg_going = 1; |
4567 | break; | |
4568 | ||
ed1f651b RS |
4569 | case 'd': |
4570 | delete_this_arg = 2; | |
4571 | break; | |
4572 | ||
4573 | /* Dump out the directories specified with LIBRARY_PATH, | |
004fd4d5 RS |
4574 | followed by the absolute directories |
4575 | that we search for startfiles. */ | |
ed1f651b | 4576 | case 'D': |
8cacec76 | 4577 | { |
00dcee0c | 4578 | struct spec_path_info info; |
59014d0a | 4579 | |
00dcee0c AM |
4580 | info.option = "-L"; |
4581 | info.append_len = 0; | |
76391e5a | 4582 | #ifdef RELATIVE_PREFIX_NOT_LINKDIR |
00dcee0c AM |
4583 | /* Used on systems which record the specified -L dirs |
4584 | and use them to search for dynamic linking. | |
4585 | Relative directories always come from -B, | |
4586 | and it is better not to use them for searching | |
4587 | at run time. In particular, stage1 loses. */ | |
4588 | info.omit_relative = true; | |
76391e5a | 4589 | #else |
00dcee0c | 4590 | info.omit_relative = false; |
004fd4d5 | 4591 | #endif |
00dcee0c AM |
4592 | info.separate_options = false; |
4593 | ||
4594 | for_each_path (&startfile_prefixes, true, 0, spec_path, &info); | |
8cacec76 | 4595 | } |
ed1f651b RS |
4596 | break; |
4597 | ||
4598 | case 'e': | |
ab87f8c8 | 4599 | /* %efoo means report an error with `foo' as error message |
ed1f651b RS |
4600 | and don't execute any more commands for this file. */ |
4601 | { | |
878f32c3 | 4602 | const char *q = p; |
ed1f651b | 4603 | char *buf; |
d25a45d4 KH |
4604 | while (*p != 0 && *p != '\n') |
4605 | p++; | |
e1e4cdc4 | 4606 | buf = (char *) alloca (p - q + 1); |
ed1f651b RS |
4607 | strncpy (buf, q, p - q); |
4608 | buf[p - q] = 0; | |
5bc69b92 | 4609 | error ("%s", _(buf)); |
ed1f651b RS |
4610 | return -1; |
4611 | } | |
4612 | break; | |
4a88a060 | 4613 | case 'n': |
09da1532 | 4614 | /* %nfoo means report a notice with `foo' on stderr. */ |
4a88a060 JH |
4615 | { |
4616 | const char *q = p; | |
4617 | char *buf; | |
4618 | while (*p != 0 && *p != '\n') | |
4619 | p++; | |
e1e4cdc4 | 4620 | buf = (char *) alloca (p - q + 1); |
4a88a060 JH |
4621 | strncpy (buf, q, p - q); |
4622 | buf[p - q] = 0; | |
2dec80c7 | 4623 | inform (0, "%s", _(buf)); |
4a88a060 JH |
4624 | if (*p) |
4625 | p++; | |
4626 | } | |
4627 | break; | |
ed1f651b | 4628 | |
d25a45d4 KH |
4629 | case 'j': |
4630 | { | |
4631 | struct stat st; | |
4632 | ||
4977bab6 ZW |
4633 | /* If save_temps_flag is off, and the HOST_BIT_BUCKET is |
4634 | defined, and it is not a directory, and it is | |
4635 | writable, use it. Otherwise, treat this like any | |
4636 | other temporary file. */ | |
d25a45d4 KH |
4637 | |
4638 | if ((!save_temps_flag) | |
4639 | && (stat (HOST_BIT_BUCKET, &st) == 0) && (!S_ISDIR (st.st_mode)) | |
4640 | && (access (HOST_BIT_BUCKET, W_OK) == 0)) | |
4641 | { | |
4642 | obstack_grow (&obstack, HOST_BIT_BUCKET, | |
4643 | strlen (HOST_BIT_BUCKET)); | |
4644 | delete_this_arg = 0; | |
4645 | arg_going = 1; | |
4646 | break; | |
4647 | } | |
4648 | } | |
4977bab6 ZW |
4649 | goto create_temp_file; |
4650 | case '|': | |
4651 | if (use_pipes) | |
4652 | { | |
4653 | obstack_1grow (&obstack, '-'); | |
4654 | delete_this_arg = 0; | |
4655 | arg_going = 1; | |
4656 | ||
4657 | /* consume suffix */ | |
a92dd235 | 4658 | while (*p == '.' || ISALNUM ((unsigned char) *p)) |
4977bab6 ZW |
4659 | p++; |
4660 | if (p[0] == '%' && p[1] == 'O') | |
4661 | p += 2; | |
1d088dee | 4662 | |
4977bab6 ZW |
4663 | break; |
4664 | } | |
4665 | goto create_temp_file; | |
4666 | case 'm': | |
4667 | if (use_pipes) | |
4668 | { | |
4669 | /* consume suffix */ | |
a92dd235 | 4670 | while (*p == '.' || ISALNUM ((unsigned char) *p)) |
4977bab6 ZW |
4671 | p++; |
4672 | if (p[0] == '%' && p[1] == 'O') | |
4673 | p += 2; | |
1d088dee | 4674 | |
4977bab6 ZW |
4675 | break; |
4676 | } | |
4677 | goto create_temp_file; | |
ed1f651b | 4678 | case 'g': |
d887e808 | 4679 | case 'u': |
4401b31c | 4680 | case 'U': |
4977bab6 | 4681 | create_temp_file: |
ed1f651b | 4682 | { |
fb266030 | 4683 | struct temp_name *t; |
dd75c292 | 4684 | int suffix_length; |
878f32c3 | 4685 | const char *suffix = p; |
a1d9074c | 4686 | char *saved_suffix = NULL; |
dd75c292 | 4687 | |
a92dd235 | 4688 | while (*p == '.' || ISALNUM ((unsigned char) *p)) |
a1d9074c TT |
4689 | p++; |
4690 | suffix_length = p - suffix; | |
dd75c292 CB |
4691 | if (p[0] == '%' && p[1] == 'O') |
4692 | { | |
cbc54665 | 4693 | p += 2; |
dd75c292 | 4694 | /* We don't support extra suffix characters after %O. */ |
a92dd235 | 4695 | if (*p == '.' || ISALNUM ((unsigned char) *p)) |
bdc6b402 | 4696 | fatal_error ("spec %qs has invalid %<%%0%c%>", spec, *p); |
a1d9074c | 4697 | if (suffix_length == 0) |
45936a85 | 4698 | suffix = TARGET_OBJECT_SUFFIX; |
a1d9074c TT |
4699 | else |
4700 | { | |
4701 | saved_suffix | |
5ed6ace5 | 4702 | = XNEWVEC (char, suffix_length |
703ad42b | 4703 | + strlen (TARGET_OBJECT_SUFFIX)); |
a1d9074c TT |
4704 | strncpy (saved_suffix, suffix, suffix_length); |
4705 | strcpy (saved_suffix + suffix_length, | |
45936a85 | 4706 | TARGET_OBJECT_SUFFIX); |
a1d9074c | 4707 | } |
45936a85 | 4708 | suffix_length += strlen (TARGET_OBJECT_SUFFIX); |
dd75c292 | 4709 | } |
589005ff | 4710 | |
2153915d AO |
4711 | if (compare_debug < 0) |
4712 | { | |
4713 | suffix = concat (".gk", suffix, NULL); | |
4714 | suffix_length += 3; | |
4715 | } | |
4716 | ||
14fdc613 MM |
4717 | /* If -save-temps=obj and -o were specified, use that for the |
4718 | temp file. */ | |
4719 | if (save_temps_length) | |
4720 | { | |
4721 | char *tmp; | |
4722 | temp_filename_length | |
4723 | = save_temps_length + suffix_length + 1; | |
4724 | tmp = (char *) alloca (temp_filename_length); | |
4725 | memcpy (tmp, save_temps_prefix, save_temps_length); | |
4726 | memcpy (tmp + save_temps_length, suffix, suffix_length); | |
4727 | tmp[save_temps_length + suffix_length] = '\0'; | |
4728 | temp_filename = save_string (tmp, | |
4729 | temp_filename_length + 1); | |
4730 | obstack_grow (&obstack, temp_filename, | |
4731 | temp_filename_length); | |
4732 | arg_going = 1; | |
4733 | delete_this_arg = 0; | |
4734 | break; | |
4735 | } | |
4736 | ||
6afbc885 | 4737 | /* If the gcc_input_filename has the same suffix specified |
99f78cdd IR |
4738 | for the %g, %u, or %U, and -save-temps is specified, |
4739 | we could end up using that file as an intermediate | |
4740 | thus clobbering the user's source file (.e.g., | |
4741 | gcc -save-temps foo.s would clobber foo.s with the | |
4742 | output of cpp0). So check for this condition and | |
4743 | generate a temp file as the intermediate. */ | |
589005ff | 4744 | |
99f78cdd IR |
4745 | if (save_temps_flag) |
4746 | { | |
6ea2b70d | 4747 | char *tmp; |
14fdc613 MM |
4748 | temp_filename_length = basename_length + suffix_length + 1; |
4749 | tmp = (char *) alloca (temp_filename_length); | |
4750 | memcpy (tmp, input_basename, basename_length); | |
4751 | memcpy (tmp + basename_length, suffix, suffix_length); | |
4752 | tmp[basename_length + suffix_length] = '\0'; | |
6ea2b70d | 4753 | temp_filename = tmp; |
14fdc613 | 4754 | |
ba78087b | 4755 | if (filename_cmp (temp_filename, gcc_input_filename) != 0) |
99f78cdd | 4756 | { |
a9024779 | 4757 | #ifndef HOST_LACKS_INODE_NUMBERS |
1d088dee | 4758 | struct stat st_temp; |
589005ff | 4759 | |
1d088dee AJ |
4760 | /* Note, set_input() resets input_stat_set to 0. */ |
4761 | if (input_stat_set == 0) | |
4762 | { | |
6afbc885 JM |
4763 | input_stat_set = stat (gcc_input_filename, |
4764 | &input_stat); | |
1d088dee AJ |
4765 | if (input_stat_set >= 0) |
4766 | input_stat_set = 1; | |
4767 | } | |
589005ff | 4768 | |
6afbc885 | 4769 | /* If we have the stat for the gcc_input_filename |
1d088dee AJ |
4770 | and we can do the stat for the temp_filename |
4771 | then the they could still refer to the same | |
4772 | file if st_dev/st_ino's are the same. */ | |
99f78cdd IR |
4773 | if (input_stat_set != 1 |
4774 | || stat (temp_filename, &st_temp) < 0 | |
4775 | || input_stat.st_dev != st_temp.st_dev | |
4776 | || input_stat.st_ino != st_temp.st_ino) | |
a9024779 DS |
4777 | #else |
4778 | /* Just compare canonical pathnames. */ | |
6afbc885 | 4779 | char* input_realname = lrealpath (gcc_input_filename); |
a9024779 | 4780 | char* temp_realname = lrealpath (temp_filename); |
ba78087b | 4781 | bool files_differ = filename_cmp (input_realname, temp_realname); |
a9024779 DS |
4782 | free (input_realname); |
4783 | free (temp_realname); | |
7904f95f | 4784 | if (files_differ) |
a9024779 | 4785 | #endif |
589005ff | 4786 | { |
99f78cdd IR |
4787 | temp_filename = save_string (temp_filename, |
4788 | temp_filename_length + 1); | |
4789 | obstack_grow (&obstack, temp_filename, | |
1d088dee | 4790 | temp_filename_length); |
99f78cdd | 4791 | arg_going = 1; |
d2dff06b | 4792 | delete_this_arg = 0; |
99f78cdd IR |
4793 | break; |
4794 | } | |
4795 | } | |
4796 | } | |
fb266030 TW |
4797 | |
4798 | /* See if we already have an association of %g/%u/%U and | |
4799 | suffix. */ | |
4800 | for (t = temp_names; t; t = t->next) | |
dd75c292 CB |
4801 | if (t->length == suffix_length |
4802 | && strncmp (t->suffix, suffix, suffix_length) == 0 | |
95456d43 | 4803 | && t->unique == (c == 'u' || c == 'U' || c == 'j')) |
fb266030 TW |
4804 | break; |
4805 | ||
2297fdf1 TT |
4806 | /* Make a new association if needed. %u and %j |
4807 | require one. */ | |
49009afd | 4808 | if (t == 0 || c == 'u' || c == 'j') |
fb266030 TW |
4809 | { |
4810 | if (t == 0) | |
4811 | { | |
e1e4cdc4 | 4812 | t = XNEW (struct temp_name); |
fb266030 TW |
4813 | t->next = temp_names; |
4814 | temp_names = t; | |
4815 | } | |
dd75c292 | 4816 | t->length = suffix_length; |
2297fdf1 TT |
4817 | if (saved_suffix) |
4818 | { | |
4819 | t->suffix = saved_suffix; | |
4820 | saved_suffix = NULL; | |
4821 | } | |
4822 | else | |
4823 | t->suffix = save_string (suffix, suffix_length); | |
95456d43 | 4824 | t->unique = (c == 'u' || c == 'U' || c == 'j'); |
dd75c292 | 4825 | temp_filename = make_temp_file (t->suffix); |
6aa62cff | 4826 | temp_filename_length = strlen (temp_filename); |
fb266030 TW |
4827 | t->filename = temp_filename; |
4828 | t->filename_length = temp_filename_length; | |
4829 | } | |
4830 | ||
04695783 | 4831 | free (saved_suffix); |
a1d9074c | 4832 | |
fb266030 | 4833 | obstack_grow (&obstack, t->filename, t->filename_length); |
b9490a6e | 4834 | delete_this_arg = 1; |
ed1f651b RS |
4835 | } |
4836 | arg_going = 1; | |
4837 | break; | |
4838 | ||
4839 | case 'i': | |
d1bd0ded GK |
4840 | if (combine_inputs) |
4841 | { | |
5a691e98 RAE |
4842 | if (at_file_supplied) |
4843 | { | |
4844 | /* We are going to expand `%i' to `@FILE', where FILE | |
4845 | is a newly-created temporary filename. The filenames | |
4846 | that would usually be expanded in place of %o will be | |
4847 | written to the temporary file. */ | |
4848 | char **argv; | |
4849 | int n_files = 0; | |
4850 | int j; | |
4851 | ||
4852 | for (i = 0; i < n_infiles; i++) | |
4853 | if (compile_input_file_p (&infiles[i])) | |
4854 | n_files++; | |
4855 | ||
4856 | argv = (char **) alloca (sizeof (char *) * (n_files + 1)); | |
4857 | ||
4858 | /* Copy the strings over. */ | |
4859 | for (i = 0, j = 0; i < n_infiles; i++) | |
4860 | if (compile_input_file_p (&infiles[i])) | |
4861 | { | |
4862 | argv[j] = CONST_CAST (char *, infiles[i].name); | |
4863 | infiles[i].compiled = true; | |
4864 | j++; | |
4865 | } | |
4866 | argv[j] = NULL; | |
4867 | ||
4868 | create_at_file (argv); | |
4869 | } | |
4870 | else | |
4871 | for (i = 0; (int) i < n_infiles; i++) | |
4872 | if (compile_input_file_p (&infiles[i])) | |
0855eab7 CT |
4873 | { |
4874 | store_arg (infiles[i].name, 0, 0); | |
4875 | infiles[i].compiled = true; | |
4876 | } | |
d1bd0ded GK |
4877 | } |
4878 | else | |
4879 | { | |
6afbc885 JM |
4880 | obstack_grow (&obstack, gcc_input_filename, |
4881 | input_filename_length); | |
d1bd0ded GK |
4882 | arg_going = 1; |
4883 | } | |
ed1f651b RS |
4884 | break; |
4885 | ||
8eebb258 | 4886 | case 'I': |
2d879387 | 4887 | { |
00dcee0c | 4888 | struct spec_path_info info; |
2d879387 | 4889 | |
2b6dd222 JM |
4890 | if (multilib_dir) |
4891 | { | |
4892 | do_spec_1 ("-imultilib", 1, NULL); | |
4893 | /* Make this a separate argument. */ | |
4894 | do_spec_1 (" ", 0, NULL); | |
4895 | do_spec_1 (multilib_dir, 1, NULL); | |
4896 | do_spec_1 (" ", 0, NULL); | |
4897 | } | |
4898 | ||
2d879387 JW |
4899 | if (gcc_exec_prefix) |
4900 | { | |
6496a589 | 4901 | do_spec_1 ("-iprefix", 1, NULL); |
2d879387 | 4902 | /* Make this a separate argument. */ |
6496a589 KG |
4903 | do_spec_1 (" ", 0, NULL); |
4904 | do_spec_1 (gcc_exec_prefix, 1, NULL); | |
4905 | do_spec_1 (" ", 0, NULL); | |
2d879387 JW |
4906 | } |
4907 | ||
e7f13528 GP |
4908 | if (target_system_root_changed || |
4909 | (target_system_root && target_sysroot_hdrs_suffix)) | |
047d636f DJ |
4910 | { |
4911 | do_spec_1 ("-isysroot", 1, NULL); | |
4912 | /* Make this a separate argument. */ | |
4913 | do_spec_1 (" ", 0, NULL); | |
4914 | do_spec_1 (target_system_root, 1, NULL); | |
e7f13528 GP |
4915 | if (target_sysroot_hdrs_suffix) |
4916 | do_spec_1 (target_sysroot_hdrs_suffix, 1, NULL); | |
047d636f DJ |
4917 | do_spec_1 (" ", 0, NULL); |
4918 | } | |
4919 | ||
00dcee0c AM |
4920 | info.option = "-isystem"; |
4921 | info.append = "include"; | |
4922 | info.append_len = strlen (info.append); | |
4923 | info.omit_relative = false; | |
4924 | info.separate_options = true; | |
4925 | ||
4926 | for_each_path (&include_prefixes, false, info.append_len, | |
4927 | spec_path, &info); | |
f686ec05 JM |
4928 | |
4929 | info.append = "include-fixed"; | |
14da6073 JM |
4930 | if (*sysroot_hdrs_suffix_spec) |
4931 | info.append = concat (info.append, dir_separator_str, | |
4932 | multilib_dir, NULL); | |
f686ec05 JM |
4933 | info.append_len = strlen (info.append); |
4934 | for_each_path (&include_prefixes, false, info.append_len, | |
4935 | spec_path, &info); | |
2d879387 | 4936 | } |
8eebb258 RS |
4937 | break; |
4938 | ||
ed1f651b | 4939 | case 'o': |
15c5edb9 TT |
4940 | { |
4941 | int max = n_infiles; | |
15c5edb9 | 4942 | max += lang_specific_extra_outfiles; |
08dc830e | 4943 | |
2091ff66 NF |
4944 | if (HAVE_GNU_LD && at_file_supplied) |
4945 | { | |
4946 | /* We are going to expand `%o' to `@FILE', where FILE | |
4947 | is a newly-created temporary filename. The filenames | |
4948 | that would usually be expanded in place of %o will be | |
4949 | written to the temporary file. */ | |
4950 | ||
2091ff66 | 4951 | char **argv; |
5a691e98 | 4952 | int n_files, j; |
2091ff66 NF |
4953 | |
4954 | /* Convert OUTFILES into a form suitable for writeargv. */ | |
4955 | ||
4956 | /* Determine how many are non-NULL. */ | |
4957 | for (n_files = 0, i = 0; i < max; i++) | |
4958 | n_files += outfiles[i] != NULL; | |
4959 | ||
e1e4cdc4 | 4960 | argv = (char **) alloca (sizeof (char *) * (n_files + 1)); |
2091ff66 NF |
4961 | |
4962 | /* Copy the strings over. */ | |
4963 | for (i = 0, j = 0; i < max; i++) | |
4964 | if (outfiles[i]) | |
4965 | { | |
b1d5455a | 4966 | argv[j] = CONST_CAST (char *, outfiles[i]); |
2091ff66 NF |
4967 | j++; |
4968 | } | |
4969 | argv[j] = NULL; | |
4970 | ||
5a691e98 | 4971 | create_at_file (argv); |
2091ff66 NF |
4972 | } |
4973 | else | |
4974 | for (i = 0; i < max; i++) | |
4975 | if (outfiles[i]) | |
4976 | store_arg (outfiles[i], 0, 0); | |
15c5edb9 TT |
4977 | break; |
4978 | } | |
ed1f651b | 4979 | |
ed7dae04 | 4980 | case 'O': |
45936a85 | 4981 | obstack_grow (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX)); |
ed7dae04 RK |
4982 | arg_going = 1; |
4983 | break; | |
4984 | ||
ed1f651b RS |
4985 | case 's': |
4986 | this_is_library_file = 1; | |
4987 | break; | |
4988 | ||
3beb864c NC |
4989 | case 'T': |
4990 | this_is_linker_script = 1; | |
4991 | break; | |
4992 | ||
17211ab5 GK |
4993 | case 'V': |
4994 | outfiles[input_file_number] = NULL; | |
4995 | break; | |
4996 | ||
ed1f651b RS |
4997 | case 'w': |
4998 | this_is_output_file = 1; | |
4999 | break; | |
5000 | ||
5001 | case 'W': | |
5002 | { | |
5b634ee0 | 5003 | unsigned int cur_index = VEC_length (const_char_p, argbuf); |
ed1f651b RS |
5004 | /* Handle the {...} following the %W. */ |
5005 | if (*p != '{') | |
bdc6b402 | 5006 | fatal_error ("spec %qs has invalid %<%%W%c%>", spec, *p); |
ed1f651b RS |
5007 | p = handle_braces (p + 1); |
5008 | if (p == 0) | |
5009 | return -1; | |
13e7cedb | 5010 | end_going_arg (); |
ed1f651b RS |
5011 | /* If any args were output, mark the last one for deletion |
5012 | on failure. */ | |
5b634ee0 JM |
5013 | if (VEC_length (const_char_p, argbuf) != cur_index) |
5014 | record_temp_file (VEC_last (const_char_p, argbuf), 0, 1); | |
ed1f651b RS |
5015 | break; |
5016 | } | |
5017 | ||
5018 | /* %x{OPTION} records OPTION for %X to output. */ | |
5019 | case 'x': | |
5020 | { | |
878f32c3 | 5021 | const char *p1 = p; |
ed1f651b | 5022 | char *string; |
69d540bd NF |
5023 | char *opt; |
5024 | unsigned ix; | |
ed1f651b RS |
5025 | |
5026 | /* Skip past the option value and make a copy. */ | |
5027 | if (*p != '{') | |
bdc6b402 | 5028 | fatal_error ("spec %qs has invalid %<%%x%c%>", spec, *p); |
ed1f651b RS |
5029 | while (*p++ != '}') |
5030 | ; | |
5031 | string = save_string (p1 + 1, p - p1 - 2); | |
5032 | ||
5033 | /* See if we already recorded this option. */ | |
69d540bd NF |
5034 | FOR_EACH_VEC_ELT (char_p, linker_options, ix, opt) |
5035 | if (! strcmp (string, opt)) | |
ed1f651b RS |
5036 | { |
5037 | free (string); | |
5038 | return 0; | |
5039 | } | |
5040 | ||
5041 | /* This option is new; add it. */ | |
b8468bc7 | 5042 | add_linker_option (string, strlen (string)); |
ed1f651b RS |
5043 | } |
5044 | break; | |
5045 | ||
368dfd3a | 5046 | /* Dump out the options accumulated previously using %x. */ |
ed1f651b | 5047 | case 'X': |
69d540bd | 5048 | do_specs_vec (linker_options); |
ed1f651b RS |
5049 | break; |
5050 | ||
c9ebacb8 RS |
5051 | /* Dump out the options accumulated previously using -Wa,. */ |
5052 | case 'Y': | |
69d540bd | 5053 | do_specs_vec (assembler_options); |
c9ebacb8 RS |
5054 | break; |
5055 | ||
57cb9b60 JW |
5056 | /* Dump out the options accumulated previously using -Wp,. */ |
5057 | case 'Z': | |
69d540bd | 5058 | do_specs_vec (preprocessor_options); |
57cb9b60 JW |
5059 | break; |
5060 | ||
ed1f651b RS |
5061 | /* Here are digits and numbers that just process |
5062 | a certain constant string as a spec. */ | |
5063 | ||
5064 | case '1': | |
6496a589 | 5065 | value = do_spec_1 (cc1_spec, 0, NULL); |
3279bba6 RS |
5066 | if (value != 0) |
5067 | return value; | |
ed1f651b RS |
5068 | break; |
5069 | ||
5070 | case '2': | |
6496a589 | 5071 | value = do_spec_1 (cc1plus_spec, 0, NULL); |
3279bba6 RS |
5072 | if (value != 0) |
5073 | return value; | |
ed1f651b RS |
5074 | break; |
5075 | ||
5076 | case 'a': | |
6496a589 | 5077 | value = do_spec_1 (asm_spec, 0, NULL); |
3279bba6 RS |
5078 | if (value != 0) |
5079 | return value; | |
ed1f651b RS |
5080 | break; |
5081 | ||
5082 | case 'A': | |
6496a589 | 5083 | value = do_spec_1 (asm_final_spec, 0, NULL); |
3279bba6 RS |
5084 | if (value != 0) |
5085 | return value; | |
ed1f651b RS |
5086 | break; |
5087 | ||
ed1f651b | 5088 | case 'C': |
a9374841 | 5089 | { |
83182544 | 5090 | const char *const spec |
589005ff KH |
5091 | = (input_file_compiler->cpp_spec |
5092 | ? input_file_compiler->cpp_spec | |
a9374841 | 5093 | : cpp_spec); |
6496a589 | 5094 | value = do_spec_1 (spec, 0, NULL); |
a9374841 MM |
5095 | if (value != 0) |
5096 | return value; | |
5097 | } | |
ed1f651b RS |
5098 | break; |
5099 | ||
5100 | case 'E': | |
6496a589 | 5101 | value = do_spec_1 (endfile_spec, 0, NULL); |
3279bba6 RS |
5102 | if (value != 0) |
5103 | return value; | |
ed1f651b RS |
5104 | break; |
5105 | ||
5106 | case 'l': | |
6496a589 | 5107 | value = do_spec_1 (link_spec, 0, NULL); |
3279bba6 RS |
5108 | if (value != 0) |
5109 | return value; | |
ed1f651b RS |
5110 | break; |
5111 | ||
5112 | case 'L': | |
6496a589 | 5113 | value = do_spec_1 (lib_spec, 0, NULL); |
3279bba6 RS |
5114 | if (value != 0) |
5115 | return value; | |
ed1f651b RS |
5116 | break; |
5117 | ||
68d69835 | 5118 | case 'G': |
6496a589 | 5119 | value = do_spec_1 (libgcc_spec, 0, NULL); |
68d69835 JM |
5120 | if (value != 0) |
5121 | return value; | |
5122 | break; | |
5123 | ||
4977bab6 ZW |
5124 | case 'R': |
5125 | /* We assume there is a directory | |
5126 | separator at the end of this string. */ | |
5127 | if (target_system_root) | |
1d088dee AJ |
5128 | { |
5129 | obstack_grow (&obstack, target_system_root, | |
e7f13528 GP |
5130 | strlen (target_system_root)); |
5131 | if (target_sysroot_suffix) | |
1d088dee | 5132 | obstack_grow (&obstack, target_sysroot_suffix, |
e7f13528 GP |
5133 | strlen (target_sysroot_suffix)); |
5134 | } | |
4977bab6 ZW |
5135 | break; |
5136 | ||
ed1f651b | 5137 | case 'S': |
6496a589 | 5138 | value = do_spec_1 (startfile_spec, 0, NULL); |
3279bba6 RS |
5139 | if (value != 0) |
5140 | return value; | |
ed1f651b RS |
5141 | break; |
5142 | ||
5143 | /* Here we define characters other than letters and digits. */ | |
5144 | ||
5145 | case '{': | |
5146 | p = handle_braces (p); | |
5147 | if (p == 0) | |
5148 | return -1; | |
5149 | break; | |
5150 | ||
f3226a90 JT |
5151 | case ':': |
5152 | p = handle_spec_function (p); | |
5153 | if (p == 0) | |
5154 | return -1; | |
5155 | break; | |
5156 | ||
ed1f651b RS |
5157 | case '%': |
5158 | obstack_1grow (&obstack, '%'); | |
5159 | break; | |
5160 | ||
589005ff KH |
5161 | case '.': |
5162 | { | |
5163 | unsigned len = 0; | |
11972f66 | 5164 | |
589005ff KH |
5165 | while (p[len] && p[len] != ' ' && p[len] != '%') |
5166 | len++; | |
5167 | suffix_subst = save_string (p - 1, len + 1); | |
5168 | p += len; | |
5169 | } | |
11972f66 | 5170 | break; |
589005ff | 5171 | |
4977bab6 ZW |
5172 | /* Henceforth ignore the option(s) matching the pattern |
5173 | after the %<. */ | |
5174 | case '<': | |
96f5b137 | 5175 | case '>': |
4977bab6 ZW |
5176 | { |
5177 | unsigned len = 0; | |
5178 | int have_wildcard = 0; | |
5179 | int i; | |
96f5b137 L |
5180 | int switch_option; |
5181 | ||
5182 | if (c == '>') | |
5183 | switch_option = SWITCH_IGNORE | SWITCH_KEEP_FOR_GCC; | |
5184 | else | |
5185 | switch_option = SWITCH_IGNORE; | |
4977bab6 ZW |
5186 | |
5187 | while (p[len] && p[len] != ' ' && p[len] != '\t') | |
5188 | len++; | |
5189 | ||
5190 | if (p[len-1] == '*') | |
5191 | have_wildcard = 1; | |
5192 | ||
5193 | for (i = 0; i < n_switches; i++) | |
5194 | if (!strncmp (switches[i].part1, p, len - have_wildcard) | |
5195 | && (have_wildcard || switches[i].part1[len] == '\0')) | |
5196 | { | |
96f5b137 | 5197 | switches[i].live_cond |= switch_option; |
4977bab6 ZW |
5198 | switches[i].validated = 1; |
5199 | } | |
5200 | ||
5201 | p += len; | |
5202 | } | |
5203 | break; | |
5204 | ||
ed1f651b | 5205 | case '*': |
3ac63d94 NC |
5206 | if (soft_matched_part) |
5207 | { | |
7fcf46f5 JZ |
5208 | if (soft_matched_part[0]) |
5209 | do_spec_1 (soft_matched_part, 1, NULL); | |
6496a589 | 5210 | do_spec_1 (" ", 0, NULL); |
3ac63d94 NC |
5211 | } |
5212 | else | |
5213 | /* Catch the case where a spec string contains something like | |
454ff5cb | 5214 | '%{foo:%*}'. i.e. there is no * in the pattern on the left |
3ac63d94 | 5215 | hand side of the :. */ |
bdc6b402 | 5216 | error ("spec failure: %<%%*%> has not been initialized by pattern match"); |
ed1f651b RS |
5217 | break; |
5218 | ||
5219 | /* Process a string found as the value of a spec given by name. | |
5220 | This feature allows individual machine descriptions | |
3ce9f090 | 5221 | to add and use their own specs. */ |
ed1f651b | 5222 | case '(': |
ed1f651b | 5223 | { |
878f32c3 | 5224 | const char *name = p; |
ed1f651b RS |
5225 | struct spec_list *sl; |
5226 | int len; | |
5227 | ||
5228 | /* The string after the S/P is the name of a spec that is to be | |
0f41302f | 5229 | processed. */ |
3ce9f090 | 5230 | while (*p && *p != ')') |
ed1f651b RS |
5231 | p++; |
5232 | ||
3ac63d94 | 5233 | /* See if it's in the list. */ |
ed1f651b | 5234 | for (len = p - name, sl = specs; sl; sl = sl->next) |
79aff5ac | 5235 | if (sl->name_len == len && !strncmp (sl->name, name, len)) |
ed1f651b | 5236 | { |
79aff5ac | 5237 | name = *(sl->ptr_spec); |
20df0482 | 5238 | #ifdef DEBUG_SPECS |
3ce9f090 JM |
5239 | fnotice (stderr, "Processing spec (%s), which is '%s'\n", |
5240 | sl->name, name); | |
20df0482 | 5241 | #endif |
ed1f651b RS |
5242 | break; |
5243 | } | |
5244 | ||
5245 | if (sl) | |
5246 | { | |
3ce9f090 JM |
5247 | value = do_spec_1 (name, 0, NULL); |
5248 | if (value != 0) | |
5249 | return value; | |
ed1f651b | 5250 | } |
b3865ca9 | 5251 | |
3ce9f090 | 5252 | /* Discard the closing paren. */ |
b3865ca9 RS |
5253 | if (*p) |
5254 | p++; | |
ed1f651b RS |
5255 | } |
5256 | break; | |
5257 | ||
5258 | default: | |
bdc6b402 | 5259 | error ("spec failure: unrecognized spec option %qc", c); |
3ac63d94 | 5260 | break; |
ed1f651b RS |
5261 | } |
5262 | break; | |
5263 | ||
5264 | case '\\': | |
5265 | /* Backslash: treat next character as ordinary. */ | |
5266 | c = *p++; | |
5267 | ||
938d968e | 5268 | /* Fall through. */ |
ed1f651b RS |
5269 | default: |
5270 | /* Ordinary character: put it into the current argument. */ | |
5271 | obstack_1grow (&obstack, c); | |
5272 | arg_going = 1; | |
5273 | } | |
5274 | ||
f3226a90 JT |
5275 | /* End of string. If we are processing a spec function, we need to |
5276 | end any pending argument. */ | |
13e7cedb DH |
5277 | if (processing_spec_function) |
5278 | end_going_arg (); | |
f3226a90 | 5279 | |
d25a45d4 | 5280 | return 0; |
ed1f651b RS |
5281 | } |
5282 | ||
f3226a90 JT |
5283 | /* Look up a spec function. */ |
5284 | ||
5285 | static const struct spec_function * | |
1d088dee | 5286 | lookup_spec_function (const char *name) |
f3226a90 | 5287 | { |
f3226a90 | 5288 | const struct spec_function *sf; |
f3226a90 | 5289 | |
4c360e1f RE |
5290 | for (sf = static_spec_functions; sf->name != NULL; sf++) |
5291 | if (strcmp (sf->name, name) == 0) | |
5292 | return sf; | |
f3226a90 JT |
5293 | |
5294 | return NULL; | |
5295 | } | |
5296 | ||
5297 | /* Evaluate a spec function. */ | |
5298 | ||
5299 | static const char * | |
1d088dee | 5300 | eval_spec_function (const char *func, const char *args) |
f3226a90 JT |
5301 | { |
5302 | const struct spec_function *sf; | |
5303 | const char *funcval; | |
5304 | ||
5305 | /* Saved spec processing context. */ | |
5b634ee0 | 5306 | VEC(const_char_p,heap) *save_argbuf; |
f3226a90 JT |
5307 | |
5308 | int save_arg_going; | |
5309 | int save_delete_this_arg; | |
5310 | int save_this_is_output_file; | |
5311 | int save_this_is_library_file; | |
5312 | int save_input_from_pipe; | |
3beb864c | 5313 | int save_this_is_linker_script; |
f3226a90 JT |
5314 | const char *save_suffix_subst; |
5315 | ||
b50ff8bb OH |
5316 | int save_growing_size; |
5317 | void *save_growing_value; | |
f3226a90 JT |
5318 | |
5319 | sf = lookup_spec_function (func); | |
5320 | if (sf == NULL) | |
bdc6b402 | 5321 | fatal_error ("unknown spec function %qs", func); |
f3226a90 JT |
5322 | |
5323 | /* Push the spec processing context. */ | |
f3226a90 JT |
5324 | save_argbuf = argbuf; |
5325 | ||
5326 | save_arg_going = arg_going; | |
5327 | save_delete_this_arg = delete_this_arg; | |
5328 | save_this_is_output_file = this_is_output_file; | |
5329 | save_this_is_library_file = this_is_library_file; | |
3beb864c | 5330 | save_this_is_linker_script = this_is_linker_script; |
f3226a90 JT |
5331 | save_input_from_pipe = input_from_pipe; |
5332 | save_suffix_subst = suffix_subst; | |
5333 | ||
b50ff8bb OH |
5334 | /* If we have some object growing now, finalize it so the args and function |
5335 | eval proceed from a cleared context. This is needed to prevent the first | |
5336 | constructed arg from mistakenly including the growing value. We'll push | |
5337 | this value back on the obstack once the function evaluation is done, to | |
5338 | restore a consistent processing context for our caller. This is fine as | |
5339 | the address of growing objects isn't guaranteed to remain stable until | |
5340 | they are finalized, and we expect this situation to be rare enough for | |
5341 | the extra copy not to be an issue. */ | |
5342 | save_growing_size = obstack_object_size (&obstack); | |
5343 | if (save_growing_size > 0) | |
5344 | save_growing_value = obstack_finish (&obstack); | |
5345 | ||
f3226a90 JT |
5346 | /* Create a new spec processing context, and build the function |
5347 | arguments. */ | |
5348 | ||
5349 | alloc_args (); | |
5350 | if (do_spec_2 (args) < 0) | |
bdc6b402 | 5351 | fatal_error ("error in args to spec function %qs", func); |
f3226a90 JT |
5352 | |
5353 | /* argbuf_index is an index for the next argument to be inserted, and | |
5354 | so contains the count of the args already inserted. */ | |
5355 | ||
5b634ee0 JM |
5356 | funcval = (*sf->func) (VEC_length (const_char_p, argbuf), |
5357 | VEC_address (const_char_p, argbuf)); | |
f3226a90 JT |
5358 | |
5359 | /* Pop the spec processing context. */ | |
5b634ee0 | 5360 | VEC_free (const_char_p, heap, argbuf); |
f3226a90 JT |
5361 | argbuf = save_argbuf; |
5362 | ||
5363 | arg_going = save_arg_going; | |
5364 | delete_this_arg = save_delete_this_arg; | |
5365 | this_is_output_file = save_this_is_output_file; | |
5366 | this_is_library_file = save_this_is_library_file; | |
3beb864c | 5367 | this_is_linker_script = save_this_is_linker_script; |
f3226a90 JT |
5368 | input_from_pipe = save_input_from_pipe; |
5369 | suffix_subst = save_suffix_subst; | |
5370 | ||
b50ff8bb OH |
5371 | if (save_growing_size > 0) |
5372 | obstack_grow (&obstack, save_growing_value, save_growing_size); | |
5373 | ||
f3226a90 JT |
5374 | return funcval; |
5375 | } | |
5376 | ||
5377 | /* Handle a spec function call of the form: | |
5378 | ||
5379 | %:function(args) | |
5380 | ||
5381 | ARGS is processed as a spec in a separate context and split into an | |
5382 | argument vector in the normal fashion. The function returns a string | |
5383 | containing a spec which we then process in the caller's context, or | |
5384 | NULL if no processing is required. */ | |
5385 | ||
5386 | static const char * | |
1d088dee | 5387 | handle_spec_function (const char *p) |
f3226a90 JT |
5388 | { |
5389 | char *func, *args; | |
5390 | const char *endp, *funcval; | |
5391 | int count; | |
5392 | ||
5393 | processing_spec_function++; | |
5394 | ||
5395 | /* Get the function name. */ | |
5396 | for (endp = p; *endp != '\0'; endp++) | |
5397 | { | |
5398 | if (*endp == '(') /* ) */ | |
5399 | break; | |
5400 | /* Only allow [A-Za-z0-9], -, and _ in function names. */ | |
5401 | if (!ISALNUM (*endp) && !(*endp == '-' || *endp == '_')) | |
2dec80c7 | 5402 | fatal_error ("malformed spec function name"); |
f3226a90 JT |
5403 | } |
5404 | if (*endp != '(') /* ) */ | |
2dec80c7 | 5405 | fatal_error ("no arguments for spec function"); |
f3226a90 JT |
5406 | func = save_string (p, endp - p); |
5407 | p = ++endp; | |
5408 | ||
5409 | /* Get the arguments. */ | |
5410 | for (count = 0; *endp != '\0'; endp++) | |
5411 | { | |
5412 | /* ( */ | |
5413 | if (*endp == ')') | |
5414 | { | |
5415 | if (count == 0) | |
5416 | break; | |
5417 | count--; | |
5418 | } | |
5419 | else if (*endp == '(') /* ) */ | |
5420 | count++; | |
5421 | } | |
5422 | /* ( */ | |
5423 | if (*endp != ')') | |
2dec80c7 | 5424 | fatal_error ("malformed spec function arguments"); |
f3226a90 JT |
5425 | args = save_string (p, endp - p); |
5426 | p = ++endp; | |
5427 | ||
5428 | /* p now points to just past the end of the spec function expression. */ | |
5429 | ||
5430 | funcval = eval_spec_function (func, args); | |
5431 | if (funcval != NULL && do_spec_1 (funcval, 0, NULL) < 0) | |
5432 | p = NULL; | |
5433 | ||
5434 | free (func); | |
5435 | free (args); | |
5436 | ||
5437 | processing_spec_function--; | |
5438 | ||
5439 | return p; | |
5440 | } | |
5441 | ||
4977bab6 ZW |
5442 | /* Inline subroutine of handle_braces. Returns true if the current |
5443 | input suffix matches the atom bracketed by ATOM and END_ATOM. */ | |
5444 | static inline bool | |
1d088dee | 5445 | input_suffix_matches (const char *atom, const char *end_atom) |
4977bab6 ZW |
5446 | { |
5447 | return (input_suffix | |
5448 | && !strncmp (input_suffix, atom, end_atom - atom) | |
5449 | && input_suffix[end_atom - atom] == '\0'); | |
5450 | } | |
ed1f651b | 5451 | |
48137d59 GK |
5452 | /* Subroutine of handle_braces. Returns true if the current |
5453 | input file's spec name matches the atom bracketed by ATOM and END_ATOM. */ | |
5454 | static bool | |
5455 | input_spec_matches (const char *atom, const char *end_atom) | |
5456 | { | |
5457 | return (input_file_compiler | |
5458 | && input_file_compiler->suffix | |
5459 | && input_file_compiler->suffix[0] != '\0' | |
5460 | && !strncmp (input_file_compiler->suffix + 1, atom, | |
5461 | end_atom - atom) | |
5462 | && input_file_compiler->suffix[end_atom - atom + 1] == '\0'); | |
5463 | } | |
5464 | ||
953ff289 | 5465 | /* Subroutine of handle_braces. Returns true if a switch |
4977bab6 ZW |
5466 | matching the atom bracketed by ATOM and END_ATOM appeared on the |
5467 | command line. */ | |
953ff289 | 5468 | static bool |
1d088dee | 5469 | switch_matches (const char *atom, const char *end_atom, int starred) |
ed1f651b | 5470 | { |
4977bab6 ZW |
5471 | int i; |
5472 | int len = end_atom - atom; | |
5473 | int plen = starred ? len : -1; | |
ed1f651b | 5474 | |
4977bab6 ZW |
5475 | for (i = 0; i < n_switches; i++) |
5476 | if (!strncmp (switches[i].part1, atom, len) | |
5477 | && (starred || switches[i].part1[len] == '\0') | |
5478 | && check_live_switch (i, plen)) | |
5479 | return true; | |
8097c429 | 5480 | |
5371f719 MG |
5481 | /* Check if a switch with separated form matching the atom. |
5482 | We check -D and -U switches. */ | |
5483 | else if (switches[i].args != 0) | |
5484 | { | |
5485 | if ((*switches[i].part1 == 'D' || *switches[i].part1 == 'U') | |
5486 | && *switches[i].part1 == atom[0]) | |
5487 | { | |
5488 | if (!strncmp (switches[i].args[0], &atom[1], len - 1) | |
5489 | && (starred || (switches[i].part1[1] == '\0' | |
5490 | && switches[i].args[0][len - 1] == '\0')) | |
5491 | && check_live_switch (i, (starred ? 1 : -1))) | |
5492 | return true; | |
5493 | } | |
5494 | } | |
5495 | ||
4977bab6 ZW |
5496 | return false; |
5497 | } | |
ed1f651b | 5498 | |
4977bab6 ZW |
5499 | /* Inline subroutine of handle_braces. Mark all of the switches which |
5500 | match ATOM (extends to END_ATOM; STARRED indicates whether there | |
5501 | was a star after the atom) for later processing. */ | |
5502 | static inline void | |
1d088dee | 5503 | mark_matching_switches (const char *atom, const char *end_atom, int starred) |
4977bab6 ZW |
5504 | { |
5505 | int i; | |
5506 | int len = end_atom - atom; | |
5507 | int plen = starred ? len : -1; | |
5508 | ||
5509 | for (i = 0; i < n_switches; i++) | |
5510 | if (!strncmp (switches[i].part1, atom, len) | |
5511 | && (starred || switches[i].part1[len] == '\0') | |
5512 | && check_live_switch (i, plen)) | |
5513 | switches[i].ordering = 1; | |
5514 | } | |
9bf09437 | 5515 | |
4977bab6 ZW |
5516 | /* Inline subroutine of handle_braces. Process all the currently |
5517 | marked switches through give_switch, and clear the marks. */ | |
5518 | static inline void | |
1d088dee | 5519 | process_marked_switches (void) |
4977bab6 ZW |
5520 | { |
5521 | int i; | |
ed1f651b | 5522 | |
4977bab6 ZW |
5523 | for (i = 0; i < n_switches; i++) |
5524 | if (switches[i].ordering == 1) | |
5525 | { | |
5526 | switches[i].ordering = 0; | |
5527 | give_switch (i, 0); | |
5528 | } | |
5529 | } | |
ed1f651b | 5530 | |
4977bab6 ZW |
5531 | /* Handle a %{ ... } construct. P points just inside the leading {. |
5532 | Returns a pointer one past the end of the brace block, or 0 | |
5533 | if we call do_spec_1 and that returns -1. */ | |
ed1f651b | 5534 | |
4977bab6 | 5535 | static const char * |
1d088dee | 5536 | handle_braces (const char *p) |
4977bab6 ZW |
5537 | { |
5538 | const char *atom, *end_atom; | |
5539 | const char *d_atom = NULL, *d_end_atom = NULL; | |
3b5edfee | 5540 | const char *orig = p; |
8097c429 | 5541 | |
4977bab6 | 5542 | bool a_is_suffix; |
48137d59 | 5543 | bool a_is_spectype; |
4977bab6 ZW |
5544 | bool a_is_starred; |
5545 | bool a_is_negated; | |
5546 | bool a_matched; | |
9bf09437 | 5547 | |
4977bab6 ZW |
5548 | bool a_must_be_last = false; |
5549 | bool ordered_set = false; | |
5550 | bool disjunct_set = false; | |
5551 | bool disj_matched = false; | |
5552 | bool disj_starred = true; | |
5553 | bool n_way_choice = false; | |
5554 | bool n_way_matched = false; | |
5555 | ||
5556 | #define SKIP_WHITE() do { while (*p == ' ' || *p == '\t') p++; } while (0) | |
9bf09437 | 5557 | |
4977bab6 | 5558 | do |
ed1f651b | 5559 | { |
4977bab6 | 5560 | if (a_must_be_last) |
3b5edfee | 5561 | goto invalid; |
9bf09437 | 5562 | |
4977bab6 | 5563 | /* Scan one "atom" (S in the description above of %{}, possibly |
48137d59 GK |
5564 | with '!', '.', '@', ',', or '*' modifiers). */ |
5565 | a_matched = false; | |
5566 | a_is_suffix = false; | |
5567 | a_is_starred = false; | |
5568 | a_is_negated = false; | |
5569 | a_is_spectype = false; | |
9218435e | 5570 | |
4977bab6 ZW |
5571 | SKIP_WHITE(); |
5572 | if (*p == '!') | |
5573 | p++, a_is_negated = true; | |
ed1f651b | 5574 | |
4977bab6 ZW |
5575 | SKIP_WHITE(); |
5576 | if (*p == '.') | |
5577 | p++, a_is_suffix = true; | |
48137d59 GK |
5578 | else if (*p == ',') |
5579 | p++, a_is_spectype = true; | |
ed1f651b | 5580 | |
4977bab6 ZW |
5581 | atom = p; |
5582 | while (ISIDNUM(*p) || *p == '-' || *p == '+' || *p == '=' | |
cde26509 | 5583 | || *p == ',' || *p == '.' || *p == '@') |
4977bab6 ZW |
5584 | p++; |
5585 | end_atom = p; | |
ed1f651b | 5586 | |
4977bab6 ZW |
5587 | if (*p == '*') |
5588 | p++, a_is_starred = 1; | |
196a37f4 | 5589 | |
4977bab6 | 5590 | SKIP_WHITE(); |
3b5edfee | 5591 | switch (*p) |
4977bab6 | 5592 | { |
3b5edfee | 5593 | case '&': case '}': |
4977bab6 ZW |
5594 | /* Substitute the switch(es) indicated by the current atom. */ |
5595 | ordered_set = true; | |
5596 | if (disjunct_set || n_way_choice || a_is_negated || a_is_suffix | |
48137d59 | 5597 | || a_is_spectype || atom == end_atom) |
3b5edfee | 5598 | goto invalid; |
ed1f651b | 5599 | |
4977bab6 ZW |
5600 | mark_matching_switches (atom, end_atom, a_is_starred); |
5601 | ||
5602 | if (*p == '}') | |
5603 | process_marked_switches (); | |
3b5edfee NS |
5604 | break; |
5605 | ||
5606 | case '|': case ':': | |
4977bab6 ZW |
5607 | /* Substitute some text if the current atom appears as a switch |
5608 | or suffix. */ | |
5609 | disjunct_set = true; | |
5610 | if (ordered_set) | |
3b5edfee | 5611 | goto invalid; |
ed1f651b | 5612 | |
4977bab6 | 5613 | if (atom == end_atom) |
ed1f651b | 5614 | { |
4977bab6 | 5615 | if (!n_way_choice || disj_matched || *p == '|' |
b8698a0f | 5616 | || a_is_negated || a_is_suffix || a_is_spectype |
48137d59 | 5617 | || a_is_starred) |
3b5edfee | 5618 | goto invalid; |
4977bab6 ZW |
5619 | |
5620 | /* An empty term may appear as the last choice of an | |
5621 | N-way choice set; it means "otherwise". */ | |
5622 | a_must_be_last = true; | |
5623 | disj_matched = !n_way_matched; | |
5624 | disj_starred = false; | |
ed1f651b | 5625 | } |
4977bab6 | 5626 | else |
ed1f651b | 5627 | { |
48137d59 GK |
5628 | if ((a_is_suffix || a_is_spectype) && a_is_starred) |
5629 | goto invalid; | |
3beb864c | 5630 | |
48137d59 GK |
5631 | if (!a_is_starred) |
5632 | disj_starred = false; | |
5633 | ||
5634 | /* Don't bother testing this atom if we already have a | |
5635 | match. */ | |
5636 | if (!disj_matched && !n_way_matched) | |
5637 | { | |
5638 | if (a_is_suffix) | |
5639 | a_matched = input_suffix_matches (atom, end_atom); | |
5640 | else if (a_is_spectype) | |
5641 | a_matched = input_spec_matches (atom, end_atom); | |
5642 | else | |
5643 | a_matched = switch_matches (atom, end_atom, a_is_starred); | |
3beb864c | 5644 | |
48137d59 GK |
5645 | if (a_matched != a_is_negated) |
5646 | { | |
5647 | disj_matched = true; | |
5648 | d_atom = atom; | |
5649 | d_end_atom = end_atom; | |
5650 | } | |
5651 | } | |
ed1f651b | 5652 | } |
ed1f651b | 5653 | |
4977bab6 | 5654 | if (*p == ':') |
ed1f651b | 5655 | { |
4977bab6 ZW |
5656 | /* Found the body, that is, the text to substitute if the |
5657 | current disjunction matches. */ | |
5658 | p = process_brace_body (p + 1, d_atom, d_end_atom, disj_starred, | |
5659 | disj_matched && !n_way_matched); | |
5660 | if (p == 0) | |
5661 | return 0; | |
ed1f651b | 5662 | |
4977bab6 ZW |
5663 | /* If we have an N-way choice, reset state for the next |
5664 | disjunction. */ | |
5665 | if (*p == ';') | |
ed1f651b | 5666 | { |
4977bab6 ZW |
5667 | n_way_choice = true; |
5668 | n_way_matched |= disj_matched; | |
5669 | disj_matched = false; | |
5670 | disj_starred = true; | |
5671 | d_atom = d_end_atom = NULL; | |
ed1f651b RS |
5672 | } |
5673 | } | |
3b5edfee NS |
5674 | break; |
5675 | ||
5676 | default: | |
5677 | goto invalid; | |
ed1f651b | 5678 | } |
4977bab6 ZW |
5679 | } |
5680 | while (*p++ != '}'); | |
ed1f651b | 5681 | |
4977bab6 | 5682 | return p; |
7904f95f | 5683 | |
3b5edfee | 5684 | invalid: |
bdc6b402 | 5685 | fatal_error ("braced spec %qs is invalid at %qc", orig, *p); |
7904f95f | 5686 | |
4977bab6 ZW |
5687 | #undef SKIP_WHITE |
5688 | } | |
5689 | ||
5690 | /* Subroutine of handle_braces. Scan and process a brace substitution body | |
5691 | (X in the description of %{} syntax). P points one past the colon; | |
5692 | ATOM and END_ATOM bracket the first atom which was found to be true | |
5693 | (present) in the current disjunction; STARRED indicates whether all | |
5694 | the atoms in the current disjunction were starred (for syntax validation); | |
5695 | MATCHED indicates whether the disjunction matched or not, and therefore | |
5696 | whether or not the body is to be processed through do_spec_1 or just | |
5697 | skipped. Returns a pointer to the closing } or ;, or 0 if do_spec_1 | |
5698 | returns -1. */ | |
5699 | ||
5700 | static const char * | |
1d088dee AJ |
5701 | process_brace_body (const char *p, const char *atom, const char *end_atom, |
5702 | int starred, int matched) | |
4977bab6 ZW |
5703 | { |
5704 | const char *body, *end_body; | |
5705 | unsigned int nesting_level; | |
5706 | bool have_subst = false; | |
5707 | ||
5708 | /* Locate the closing } or ;, honoring nested braces. | |
5709 | Trim trailing whitespace. */ | |
5710 | body = p; | |
5711 | nesting_level = 1; | |
5712 | for (;;) | |
5713 | { | |
5714 | if (*p == '{') | |
5715 | nesting_level++; | |
5716 | else if (*p == '}') | |
ed1f651b | 5717 | { |
4977bab6 ZW |
5718 | if (!--nesting_level) |
5719 | break; | |
ed1f651b | 5720 | } |
4977bab6 ZW |
5721 | else if (*p == ';' && nesting_level == 1) |
5722 | break; | |
5723 | else if (*p == '%' && p[1] == '*' && nesting_level == 1) | |
5724 | have_subst = true; | |
5725 | else if (*p == '\0') | |
3b5edfee | 5726 | goto invalid; |
4977bab6 | 5727 | p++; |
ed1f651b | 5728 | } |
1d088dee | 5729 | |
4977bab6 ZW |
5730 | end_body = p; |
5731 | while (end_body[-1] == ' ' || end_body[-1] == '\t') | |
5732 | end_body--; | |
ed1f651b | 5733 | |
4977bab6 | 5734 | if (have_subst && !starred) |
3b5edfee | 5735 | goto invalid; |
9bf09437 | 5736 | |
4977bab6 | 5737 | if (matched) |
196a37f4 | 5738 | { |
4977bab6 ZW |
5739 | /* Copy the substitution body to permanent storage and execute it. |
5740 | If have_subst is false, this is a simple matter of running the | |
5741 | body through do_spec_1... */ | |
5742 | char *string = save_string (body, end_body - body); | |
5743 | if (!have_subst) | |
5744 | { | |
5745 | if (do_spec_1 (string, 0, NULL) < 0) | |
5746 | return 0; | |
5747 | } | |
5748 | else | |
5749 | { | |
5750 | /* ... but if have_subst is true, we have to process the | |
5751 | body once for each matching switch, with %* set to the | |
5752 | variant part of the switch. */ | |
5753 | unsigned int hard_match_len = end_atom - atom; | |
5754 | int i; | |
196a37f4 | 5755 | |
4977bab6 ZW |
5756 | for (i = 0; i < n_switches; i++) |
5757 | if (!strncmp (switches[i].part1, atom, hard_match_len) | |
5758 | && check_live_switch (i, hard_match_len)) | |
5759 | { | |
5760 | if (do_spec_1 (string, 0, | |
5761 | &switches[i].part1[hard_match_len]) < 0) | |
5762 | return 0; | |
5763 | /* Pass any arguments this switch has. */ | |
5764 | give_switch (i, 1); | |
5765 | suffix_subst = NULL; | |
5766 | } | |
5767 | } | |
10ebf5fe NB |
5768 | } |
5769 | ||
4977bab6 | 5770 | return p; |
3b5edfee NS |
5771 | |
5772 | invalid: | |
bdc6b402 | 5773 | fatal_error ("braced spec body %qs is invalid", body); |
ed1f651b | 5774 | } |
f5b0eb4e | 5775 | \f |
6c396fb5 RK |
5776 | /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch |
5777 | on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*} | |
5778 | spec, or -1 if either exact match or %* is used. | |
f5b0eb4e RK |
5779 | |
5780 | A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch | |
5781 | whose value does not begin with "no-" is obsoleted by the same value | |
5782 | with the "no-", similarly for a switch with the "no-" prefix. */ | |
5783 | ||
5784 | static int | |
1d088dee | 5785 | check_live_switch (int switchnum, int prefix_length) |
f5b0eb4e | 5786 | { |
878f32c3 | 5787 | const char *name = switches[switchnum].part1; |
f5b0eb4e RK |
5788 | int i; |
5789 | ||
2153915d AO |
5790 | /* If we already processed this switch and determined if it was |
5791 | live or not, return our past determination. */ | |
5792 | if (switches[switchnum].live_cond != 0) | |
5793 | return ((switches[switchnum].live_cond & SWITCH_LIVE) != 0 | |
5794 | && (switches[switchnum].live_cond & SWITCH_FALSE) == 0 | |
94b90527 JJ |
5795 | && (switches[switchnum].live_cond & SWITCH_IGNORE_PERMANENTLY) |
5796 | == 0); | |
2153915d | 5797 | |
6c396fb5 | 5798 | /* In the common case of {<at-most-one-letter>*}, a negating |
f5b0eb4e RK |
5799 | switch would always match, so ignore that case. We will just |
5800 | send the conflicting switches to the compiler phase. */ | |
6c396fb5 | 5801 | if (prefix_length >= 0 && prefix_length <= 1) |
f5b0eb4e RK |
5802 | return 1; |
5803 | ||
f5b0eb4e RK |
5804 | /* Now search for duplicate in a manner that depends on the name. */ |
5805 | switch (*name) | |
5806 | { | |
5807 | case 'O': | |
d25a45d4 KH |
5808 | for (i = switchnum + 1; i < n_switches; i++) |
5809 | if (switches[i].part1[0] == 'O') | |
5810 | { | |
5811 | switches[switchnum].validated = 1; | |
5812 | switches[switchnum].live_cond = SWITCH_FALSE; | |
5813 | return 0; | |
5814 | } | |
f5b0eb4e | 5815 | break; |
ed1f651b | 5816 | |
f5b0eb4e | 5817 | case 'W': case 'f': case 'm': |
6c396fb5 | 5818 | if (! strncmp (name + 1, "no-", 3)) |
f5b0eb4e | 5819 | { |
0f41302f | 5820 | /* We have Xno-YYY, search for XYYY. */ |
f5b0eb4e RK |
5821 | for (i = switchnum + 1; i < n_switches; i++) |
5822 | if (switches[i].part1[0] == name[0] | |
5823 | && ! strcmp (&switches[i].part1[1], &name[4])) | |
d25a45d4 KH |
5824 | { |
5825 | switches[switchnum].validated = 1; | |
5826 | switches[switchnum].live_cond = SWITCH_FALSE; | |
5827 | return 0; | |
5828 | } | |
f5b0eb4e RK |
5829 | } |
5830 | else | |
5831 | { | |
5832 | /* We have XYYY, search for Xno-YYY. */ | |
5833 | for (i = switchnum + 1; i < n_switches; i++) | |
5834 | if (switches[i].part1[0] == name[0] | |
5835 | && switches[i].part1[1] == 'n' | |
5836 | && switches[i].part1[2] == 'o' | |
5837 | && switches[i].part1[3] == '-' | |
5838 | && !strcmp (&switches[i].part1[4], &name[1])) | |
d25a45d4 KH |
5839 | { |
5840 | switches[switchnum].validated = 1; | |
5841 | switches[switchnum].live_cond = SWITCH_FALSE; | |
5842 | return 0; | |
5843 | } | |
f5b0eb4e RK |
5844 | } |
5845 | break; | |
5846 | } | |
5847 | ||
5848 | /* Otherwise the switch is live. */ | |
3371362c | 5849 | switches[switchnum].live_cond |= SWITCH_LIVE; |
f5b0eb4e RK |
5850 | return 1; |
5851 | } | |
5852 | \f | |
ed1f651b RS |
5853 | /* Pass a switch to the current accumulating command |
5854 | in the same form that we received it. | |
5855 | SWITCHNUM identifies the switch; it is an index into | |
5856 | the vector of switches gcc received, which is `switches'. | |
5857 | This cannot fail since it never finishes a command line. | |
5858 | ||
4977bab6 | 5859 | If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */ |
ed1f651b RS |
5860 | |
5861 | static void | |
1d088dee | 5862 | give_switch (int switchnum, int omit_first_word) |
ed1f651b | 5863 | { |
3371362c | 5864 | if ((switches[switchnum].live_cond & SWITCH_IGNORE) != 0) |
8097c429 TT |
5865 | return; |
5866 | ||
ed1f651b RS |
5867 | if (!omit_first_word) |
5868 | { | |
6496a589 KG |
5869 | do_spec_1 ("-", 0, NULL); |
5870 | do_spec_1 (switches[switchnum].part1, 1, NULL); | |
ed1f651b | 5871 | } |
1ba9a487 | 5872 | |
ed1f651b RS |
5873 | if (switches[switchnum].args != 0) |
5874 | { | |
fbd40359 | 5875 | const char **p; |
ed1f651b RS |
5876 | for (p = switches[switchnum].args; *p; p++) |
5877 | { | |
11972f66 NS |
5878 | const char *arg = *p; |
5879 | ||
4977bab6 | 5880 | do_spec_1 (" ", 0, NULL); |
11972f66 NS |
5881 | if (suffix_subst) |
5882 | { | |
5883 | unsigned length = strlen (arg); | |
e65677af | 5884 | int dot = 0; |
11972f66 NS |
5885 | |
5886 | while (length-- && !IS_DIR_SEPARATOR (arg[length])) | |
5887 | if (arg[length] == '.') | |
5888 | { | |
b1d5455a | 5889 | (CONST_CAST(char *, arg))[length] = 0; |
e65677af | 5890 | dot = 1; |
11972f66 NS |
5891 | break; |
5892 | } | |
6496a589 | 5893 | do_spec_1 (arg, 1, NULL); |
e65677af | 5894 | if (dot) |
b1d5455a | 5895 | (CONST_CAST(char *, arg))[length] = '.'; |
e65677af | 5896 | do_spec_1 (suffix_subst, 1, NULL); |
11972f66 NS |
5897 | } |
5898 | else | |
6496a589 | 5899 | do_spec_1 (arg, 1, NULL); |
ed1f651b RS |
5900 | } |
5901 | } | |
1ba9a487 | 5902 | |
6496a589 | 5903 | do_spec_1 (" ", 0, NULL); |
ab87f8c8 | 5904 | switches[switchnum].validated = 1; |
ed1f651b RS |
5905 | } |
5906 | \f | |
5907 | /* Search for a file named NAME trying various prefixes including the | |
5908 | user's -B prefix and some standard ones. | |
5909 | Return the absolute file name found. If nothing is found, return NAME. */ | |
5910 | ||
878f32c3 | 5911 | static const char * |
1d088dee | 5912 | find_file (const char *name) |
ed1f651b | 5913 | { |
00dcee0c | 5914 | char *newname = find_a_file (&startfile_prefixes, name, R_OK, true); |
ed1f651b RS |
5915 | return newname ? newname : name; |
5916 | } | |
5917 | ||
0ad5835e | 5918 | /* Determine whether a directory exists. If LINKER, return 0 for |
00dcee0c | 5919 | certain fixed names not needed by the linker. */ |
ed1f651b RS |
5920 | |
5921 | static int | |
00dcee0c | 5922 | is_directory (const char *path1, bool linker) |
ed1f651b | 5923 | { |
00dcee0c AM |
5924 | int len1; |
5925 | char *path; | |
ed1f651b RS |
5926 | char *cp; |
5927 | struct stat st; | |
5928 | ||
00dcee0c AM |
5929 | /* Ensure the string ends with "/.". The resulting path will be a |
5930 | directory even if the given path is a symbolic link. */ | |
5931 | len1 = strlen (path1); | |
e1e4cdc4 | 5932 | path = (char *) alloca (3 + len1); |
7e2231e7 | 5933 | memcpy (path, path1, len1); |
00dcee0c | 5934 | cp = path + len1; |
509781a4 | 5935 | if (!IS_DIR_SEPARATOR (cp[-1])) |
48ff801b | 5936 | *cp++ = DIR_SEPARATOR; |
ed1f651b RS |
5937 | *cp++ = '.'; |
5938 | *cp = '\0'; | |
5939 | ||
5940 | /* Exclude directories that the linker is known to search. */ | |
0ad5835e | 5941 | if (linker |
00dcee0c | 5942 | && IS_DIR_SEPARATOR (path[0]) |
48ff801b | 5943 | && ((cp - path == 6 |
ba78087b | 5944 | && filename_ncmp (path + 1, "lib", 3) == 0) |
48ff801b | 5945 | || (cp - path == 10 |
ba78087b | 5946 | && filename_ncmp (path + 1, "usr", 3) == 0 |
00dcee0c | 5947 | && IS_DIR_SEPARATOR (path[4]) |
ba78087b | 5948 | && filename_ncmp (path + 5, "lib", 3) == 0))) |
ed1f651b RS |
5949 | return 0; |
5950 | ||
5951 | return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode)); | |
5952 | } | |
512b62fb JM |
5953 | |
5954 | /* Set up the various global variables to indicate that we're processing | |
5955 | the input file named FILENAME. */ | |
5956 | ||
b856c15d | 5957 | void |
1d088dee | 5958 | set_input (const char *filename) |
512b62fb | 5959 | { |
b3694847 | 5960 | const char *p; |
512b62fb | 5961 | |
6afbc885 JM |
5962 | gcc_input_filename = filename; |
5963 | input_filename_length = strlen (gcc_input_filename); | |
5964 | input_basename = lbasename (gcc_input_filename); | |
512b62fb JM |
5965 | |
5966 | /* Find a suffix starting with the last period, | |
5967 | and set basename_length to exclude that suffix. */ | |
5968 | basename_length = strlen (input_basename); | |
ea414c97 | 5969 | suffixed_basename_length = basename_length; |
512b62fb | 5970 | p = input_basename + basename_length; |
d25a45d4 KH |
5971 | while (p != input_basename && *p != '.') |
5972 | --p; | |
512b62fb JM |
5973 | if (*p == '.' && p != input_basename) |
5974 | { | |
5975 | basename_length = p - input_basename; | |
5976 | input_suffix = p + 1; | |
5977 | } | |
5978 | else | |
5979 | input_suffix = ""; | |
589005ff | 5980 | |
99f78cdd | 5981 | /* If a spec for 'g', 'u', or 'U' is seen with -save-temps then |
6afbc885 | 5982 | we will need to do a stat on the gcc_input_filename. The |
99f78cdd IR |
5983 | INPUT_STAT_SET signals that the stat is needed. */ |
5984 | input_stat_set = 0; | |
512b62fb | 5985 | } |
ed1f651b RS |
5986 | \f |
5987 | /* On fatal signals, delete all the temporary files. */ | |
5988 | ||
5989 | static void | |
2dec80c7 | 5990 | fatal_signal (int signum) |
ed1f651b RS |
5991 | { |
5992 | signal (signum, SIG_DFL); | |
5993 | delete_failure_queue (); | |
5994 | delete_temp_files (); | |
5995 | /* Get the same signal again, this time not handled, | |
5996 | so its normal effect occurs. */ | |
5997 | kill (getpid (), signum); | |
5998 | } | |
5999 | ||
2153915d AO |
6000 | /* Compare the contents of the two files named CMPFILE[0] and |
6001 | CMPFILE[1]. Return zero if they're identical, nonzero | |
6002 | otherwise. */ | |
6003 | ||
6004 | static int | |
6005 | compare_files (char *cmpfile[]) | |
6006 | { | |
6007 | int ret = 0; | |
6008 | FILE *temp[2] = { NULL, NULL }; | |
6009 | int i; | |
6010 | ||
6011 | #if HAVE_MMAP_FILE | |
6012 | { | |
6013 | size_t length[2]; | |
6014 | void *map[2] = { NULL, NULL }; | |
6015 | ||
6016 | for (i = 0; i < 2; i++) | |
6017 | { | |
6018 | struct stat st; | |
6019 | ||
6020 | if (stat (cmpfile[i], &st) < 0 || !S_ISREG (st.st_mode)) | |
6021 | { | |
6022 | error ("%s: could not determine length of compare-debug file %s", | |
6afbc885 | 6023 | gcc_input_filename, cmpfile[i]); |
2153915d AO |
6024 | ret = 1; |
6025 | break; | |
6026 | } | |
6027 | ||
6028 | length[i] = st.st_size; | |
6029 | } | |
6030 | ||
6031 | if (!ret && length[0] != length[1]) | |
6032 | { | |
6afbc885 | 6033 | error ("%s: -fcompare-debug failure (length)", gcc_input_filename); |
2153915d AO |
6034 | ret = 1; |
6035 | } | |
6036 | ||
6037 | if (!ret) | |
6038 | for (i = 0; i < 2; i++) | |
6039 | { | |
6040 | int fd = open (cmpfile[i], O_RDONLY); | |
6041 | if (fd < 0) | |
6042 | { | |
6043 | error ("%s: could not open compare-debug file %s", | |
6afbc885 | 6044 | gcc_input_filename, cmpfile[i]); |
2153915d AO |
6045 | ret = 1; |
6046 | break; | |
6047 | } | |
6048 | ||
6049 | map[i] = mmap (NULL, length[i], PROT_READ, MAP_PRIVATE, fd, 0); | |
6050 | close (fd); | |
6051 | ||
6052 | if (map[i] == (void *) MAP_FAILED) | |
6053 | { | |
6054 | ret = -1; | |
6055 | break; | |
6056 | } | |
6057 | } | |
6058 | ||
6059 | if (!ret) | |
6060 | { | |
6061 | if (memcmp (map[0], map[1], length[0]) != 0) | |
6062 | { | |
6afbc885 | 6063 | error ("%s: -fcompare-debug failure", gcc_input_filename); |
2153915d AO |
6064 | ret = 1; |
6065 | } | |
6066 | } | |
6067 | ||
6068 | for (i = 0; i < 2; i++) | |
6069 | if (map[i]) | |
e7aae3e8 | 6070 | munmap ((caddr_t) map[i], length[i]); |
2153915d AO |
6071 | |
6072 | if (ret >= 0) | |
6073 | return ret; | |
6074 | ||
6075 | ret = 0; | |
6076 | } | |
6077 | #endif | |
6078 | ||
6079 | for (i = 0; i < 2; i++) | |
6080 | { | |
6081 | temp[i] = fopen (cmpfile[i], "r"); | |
6082 | if (!temp[i]) | |
6083 | { | |
6084 | error ("%s: could not open compare-debug file %s", | |
6afbc885 | 6085 | gcc_input_filename, cmpfile[i]); |
2153915d AO |
6086 | ret = 1; |
6087 | break; | |
6088 | } | |
6089 | } | |
6090 | ||
6091 | if (!ret && temp[0] && temp[1]) | |
6092 | for (;;) | |
6093 | { | |
6094 | int c0, c1; | |
6095 | c0 = fgetc (temp[0]); | |
6096 | c1 = fgetc (temp[1]); | |
6097 | ||
6098 | if (c0 != c1) | |
6099 | { | |
6100 | error ("%s: -fcompare-debug failure", | |
6afbc885 | 6101 | gcc_input_filename); |
2153915d AO |
6102 | ret = 1; |
6103 | break; | |
6104 | } | |
6105 | ||
6106 | if (c0 == EOF) | |
6107 | break; | |
6108 | } | |
6109 | ||
6110 | for (i = 1; i >= 0; i--) | |
6111 | { | |
6112 | if (temp[i]) | |
6113 | fclose (temp[i]); | |
6114 | } | |
6115 | ||
6116 | return ret; | |
6117 | } | |
6118 | ||
07a3df01 | 6119 | extern int main (int, char **); |
a8f227e7 | 6120 | |
ed1f651b | 6121 | int |
07a3df01 | 6122 | main (int argc, char **argv) |
ed1f651b | 6123 | { |
ea414c97 | 6124 | size_t i; |
ed1f651b | 6125 | int value; |
ed1f651b | 6126 | int linker_was_run = 0; |
0855eab7 | 6127 | int lang_n_infiles = 0; |
17211ab5 | 6128 | int num_linker_inputs = 0; |
ed1f651b RS |
6129 | char *explicit_link_files; |
6130 | char *specs_file; | |
de9a793e | 6131 | char *lto_wrapper_file; |
878f32c3 | 6132 | const char *p; |
d9ac3a07 | 6133 | struct user_specs *uptr; |
2091ff66 | 6134 | char **old_argv = argv; |
60cf253a JM |
6135 | struct cl_decoded_option *decoded_options; |
6136 | unsigned int decoded_options_count; | |
ed1f651b | 6137 | |
afcd8a02 | 6138 | p = argv[0] + strlen (argv[0]); |
509781a4 ME |
6139 | while (p != argv[0] && !IS_DIR_SEPARATOR (p[-1])) |
6140 | --p; | |
6afbc885 | 6141 | progname = p; |
ed1f651b | 6142 | |
6afbc885 | 6143 | xmalloc_set_program_name (progname); |
e1a132c6 | 6144 | |
9d530538 MM |
6145 | expandargv (&argc, &argv); |
6146 | ||
2091ff66 NF |
6147 | /* Determine if any expansions were made. */ |
6148 | if (argv != old_argv) | |
6149 | at_file_supplied = true; | |
6150 | ||
a7d0d30f JM |
6151 | /* Register the language-independent parameters. */ |
6152 | global_init_params (); | |
6153 | finish_params (); | |
6154 | ||
6155 | init_options_struct (&global_options, &global_options_set); | |
a75bfaa6 | 6156 | |
60cf253a JM |
6157 | decode_cmdline_options_to_array (argc, CONST_CAST2 (const char **, char **, |
6158 | argv), | |
6159 | CL_DRIVER, | |
6160 | &decoded_options, &decoded_options_count); | |
14c7833c | 6161 | |
93284395 | 6162 | #ifdef GCC_DRIVER_HOST_INITIALIZATION |
ff7cc307 | 6163 | /* Perform host dependent initialization when needed. */ |
93284395 ME |
6164 | GCC_DRIVER_HOST_INITIALIZATION; |
6165 | #endif | |
6166 | ||
98a3dad4 | 6167 | /* Unlock the stdio streams. */ |
2653bb0c | 6168 | unlock_std_streams (); |
98a3dad4 | 6169 | |
191bf464 | 6170 | gcc_init_libintl (); |
ab87f8c8 | 6171 | |
6afbc885 JM |
6172 | diagnostic_initialize (global_dc, 0); |
6173 | if (atexit (delete_temp_files) != 0) | |
6174 | fatal_error ("atexit failed"); | |
6175 | ||
ed1f651b | 6176 | if (signal (SIGINT, SIG_IGN) != SIG_IGN) |
2dec80c7 | 6177 | signal (SIGINT, fatal_signal); |
2a353d3a | 6178 | #ifdef SIGHUP |
ed1f651b | 6179 | if (signal (SIGHUP, SIG_IGN) != SIG_IGN) |
2dec80c7 | 6180 | signal (SIGHUP, fatal_signal); |
2a353d3a | 6181 | #endif |
ed1f651b | 6182 | if (signal (SIGTERM, SIG_IGN) != SIG_IGN) |
2dec80c7 | 6183 | signal (SIGTERM, fatal_signal); |
ed1f651b RS |
6184 | #ifdef SIGPIPE |
6185 | if (signal (SIGPIPE, SIG_IGN) != SIG_IGN) | |
2dec80c7 | 6186 | signal (SIGPIPE, fatal_signal); |
ed1f651b | 6187 | #endif |
798bdf70 | 6188 | #ifdef SIGCHLD |
0bf679a3 BK |
6189 | /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will |
6190 | receive the signal. A different setting is inheritable */ | |
6191 | signal (SIGCHLD, SIG_DFL); | |
798bdf70 | 6192 | #endif |
ed1f651b | 6193 | |
d423df48 JJ |
6194 | /* Parsing and gimplification sometimes need quite large stack. |
6195 | Increase stack size limits if possible. */ | |
6196 | stack_limit_increase (64 * 1024 * 1024); | |
6197 | ||
f3226a90 JT |
6198 | /* Allocate the argument vector. */ |
6199 | alloc_args (); | |
ed1f651b RS |
6200 | |
6201 | obstack_init (&obstack); | |
6202 | ||
961b7009 MM |
6203 | /* Build multilib_select, et. al from the separate lines that make up each |
6204 | multilib selection. */ | |
ffd86336 | 6205 | { |
3b304f5b | 6206 | const char *const *q = multilib_raw; |
961b7009 | 6207 | int need_space; |
ffd86336 JW |
6208 | |
6209 | obstack_init (&multilib_obstack); | |
0f41302f | 6210 | while ((p = *q++) != (char *) 0) |
ffd86336 JW |
6211 | obstack_grow (&multilib_obstack, p, strlen (p)); |
6212 | ||
6213 | obstack_1grow (&multilib_obstack, 0); | |
7973fd2a | 6214 | multilib_select = XOBFINISH (&multilib_obstack, const char *); |
961b7009 MM |
6215 | |
6216 | q = multilib_matches_raw; | |
6217 | while ((p = *q++) != (char *) 0) | |
6218 | obstack_grow (&multilib_obstack, p, strlen (p)); | |
6219 | ||
6220 | obstack_1grow (&multilib_obstack, 0); | |
7973fd2a | 6221 | multilib_matches = XOBFINISH (&multilib_obstack, const char *); |
961b7009 | 6222 | |
0a8d6618 BC |
6223 | q = multilib_exclusions_raw; |
6224 | while ((p = *q++) != (char *) 0) | |
d25a45d4 | 6225 | obstack_grow (&multilib_obstack, p, strlen (p)); |
0a8d6618 BC |
6226 | |
6227 | obstack_1grow (&multilib_obstack, 0); | |
7973fd2a | 6228 | multilib_exclusions = XOBFINISH (&multilib_obstack, const char *); |
9218435e | 6229 | |
961b7009 | 6230 | need_space = FALSE; |
b6a1cbae | 6231 | for (i = 0; i < ARRAY_SIZE (multilib_defaults_raw); i++) |
961b7009 MM |
6232 | { |
6233 | if (need_space) | |
6234 | obstack_1grow (&multilib_obstack, ' '); | |
6235 | obstack_grow (&multilib_obstack, | |
6236 | multilib_defaults_raw[i], | |
6237 | strlen (multilib_defaults_raw[i])); | |
6238 | need_space = TRUE; | |
6239 | } | |
6240 | ||
6241 | obstack_1grow (&multilib_obstack, 0); | |
7973fd2a | 6242 | multilib_defaults = XOBFINISH (&multilib_obstack, const char *); |
ffd86336 JW |
6243 | } |
6244 | ||
8faf4a68 JW |
6245 | #ifdef INIT_ENVIRONMENT |
6246 | /* Set up any other necessary machine specific environment variables. */ | |
47d33318 | 6247 | xputenv (INIT_ENVIRONMENT); |
8faf4a68 JW |
6248 | #endif |
6249 | ||
ed1f651b RS |
6250 | /* Make a table of what switches there are (switches, n_switches). |
6251 | Make a table of specified input files (infiles, n_infiles). | |
6252 | Decode switches that are handled locally. */ | |
6253 | ||
60cf253a | 6254 | process_command (decoded_options_count, decoded_options); |
ed1f651b RS |
6255 | |
6256 | /* Initialize the vector of specs to just the default. | |
6257 | This means one element containing 0s, as a terminator. */ | |
6258 | ||
e1e4cdc4 | 6259 | compilers = XNEWVAR (struct compiler, sizeof default_compilers); |
703ad42b | 6260 | memcpy (compilers, default_compilers, sizeof default_compilers); |
ed1f651b RS |
6261 | n_compilers = n_default_compilers; |
6262 | ||
6263 | /* Read specs from a file if there is one. */ | |
6264 | ||
6aa62cff | 6265 | machine_suffix = concat (spec_machine, dir_separator_str, |
d4f2852f KG |
6266 | spec_version, dir_separator_str, NULL); |
6267 | just_machine_suffix = concat (spec_machine, dir_separator_str, NULL); | |
ed1f651b | 6268 | |
00dcee0c | 6269 | specs_file = find_a_file (&startfile_prefixes, "specs", R_OK, true); |
ed1f651b RS |
6270 | /* Read the specs file unless it is a default one. */ |
6271 | if (specs_file != 0 && strcmp (specs_file, "specs")) | |
20df0482 MM |
6272 | read_specs (specs_file, TRUE); |
6273 | else | |
6274 | init_spec (); | |
841faeed | 6275 | |
5bb67e36 | 6276 | /* We need to check standard_exec_prefix/just_machine_suffix/specs |
3ac63d94 | 6277 | for any override of as, ld and libraries. */ |
e1e4cdc4 | 6278 | specs_file = (char *) alloca (strlen (standard_exec_prefix) |
703ad42b | 6279 | + strlen (just_machine_suffix) + sizeof ("specs")); |
5bb67e36 RK |
6280 | |
6281 | strcpy (specs_file, standard_exec_prefix); | |
6282 | strcat (specs_file, just_machine_suffix); | |
6283 | strcat (specs_file, "specs"); | |
6284 | if (access (specs_file, R_OK) == 0) | |
6285 | read_specs (specs_file, TRUE); | |
9218435e | 6286 | |
7816bea0 DJ |
6287 | /* Process any configure-time defaults specified for the command line |
6288 | options, via OPTION_DEFAULT_SPECS. */ | |
6289 | for (i = 0; i < ARRAY_SIZE (option_default_specs); i++) | |
6290 | do_option_spec (option_default_specs[i].name, | |
6291 | option_default_specs[i].spec); | |
6292 | ||
3bd6d4c4 AO |
6293 | /* Process DRIVER_SELF_SPECS, adding any new options to the end |
6294 | of the command line. */ | |
6295 | ||
6296 | for (i = 0; i < ARRAY_SIZE (driver_self_specs); i++) | |
6297 | do_self_spec (driver_self_specs[i]); | |
6298 | ||
4977bab6 ZW |
6299 | /* If not cross-compiling, look for executables in the standard |
6300 | places. */ | |
6301 | if (*cross_compile == '0') | |
004fd4d5 | 6302 | { |
2296d164 RK |
6303 | if (*md_exec_prefix) |
6304 | { | |
6305 | add_prefix (&exec_prefixes, md_exec_prefix, "GCC", | |
1a5d37a1 | 6306 | PREFIX_PRIORITY_LAST, 0, 0); |
2296d164 | 6307 | } |
4977bab6 ZW |
6308 | } |
6309 | ||
71c0e7fc | 6310 | /* Process sysroot_suffix_spec. */ |
e7f13528 GP |
6311 | if (*sysroot_suffix_spec != 0 |
6312 | && do_spec_2 (sysroot_suffix_spec) == 0) | |
6313 | { | |
5b634ee0 | 6314 | if (VEC_length (const_char_p, argbuf) > 1) |
ab532386 | 6315 | error ("spec failure: more than one arg to SYSROOT_SUFFIX_SPEC"); |
5b634ee0 JM |
6316 | else if (VEC_length (const_char_p, argbuf) == 1) |
6317 | target_sysroot_suffix = xstrdup (VEC_last (const_char_p, argbuf)); | |
e7f13528 GP |
6318 | } |
6319 | ||
380e5ca4 MM |
6320 | #ifdef HAVE_LD_SYSROOT |
6321 | /* Pass the --sysroot option to the linker, if it supports that. If | |
6322 | there is a sysroot_suffix_spec, it has already been processed by | |
6323 | this point, so target_system_root really is the system root we | |
6324 | should be using. */ | |
6325 | if (target_system_root) | |
6326 | { | |
6327 | obstack_grow (&obstack, "%(sysroot_spec) ", strlen ("%(sysroot_spec) ")); | |
6328 | obstack_grow0 (&obstack, link_spec, strlen (link_spec)); | |
7973fd2a | 6329 | set_spec ("link", XOBFINISH (&obstack, const char *)); |
380e5ca4 MM |
6330 | } |
6331 | #endif | |
6332 | ||
71c0e7fc | 6333 | /* Process sysroot_hdrs_suffix_spec. */ |
e7f13528 GP |
6334 | if (*sysroot_hdrs_suffix_spec != 0 |
6335 | && do_spec_2 (sysroot_hdrs_suffix_spec) == 0) | |
6336 | { | |
5b634ee0 | 6337 | if (VEC_length (const_char_p, argbuf) > 1) |
ab532386 | 6338 | error ("spec failure: more than one arg to SYSROOT_HEADERS_SUFFIX_SPEC"); |
5b634ee0 JM |
6339 | else if (VEC_length (const_char_p, argbuf) == 1) |
6340 | target_sysroot_hdrs_suffix = xstrdup (VEC_last (const_char_p, argbuf)); | |
e7f13528 GP |
6341 | } |
6342 | ||
4977bab6 ZW |
6343 | /* Look for startfiles in the standard places. */ |
6344 | if (*startfile_prefix_spec != 0 | |
6345 | && do_spec_2 (startfile_prefix_spec) == 0 | |
6346 | && do_spec_1 (" ", 0, NULL) == 0) | |
6347 | { | |
5b634ee0 | 6348 | const char *arg; |
4977bab6 | 6349 | int ndx; |
5b634ee0 JM |
6350 | FOR_EACH_VEC_ELT (const_char_p, argbuf, ndx, arg) |
6351 | add_sysrooted_prefix (&startfile_prefixes, arg, "BINUTILS", | |
1a5d37a1 | 6352 | PREFIX_PRIORITY_LAST, 0, 1); |
4977bab6 ZW |
6353 | } |
6354 | /* We should eventually get rid of all these and stick to | |
6355 | startfile_prefix_spec exclusively. */ | |
6356 | else if (*cross_compile == '0' || target_system_root) | |
6357 | { | |
2296d164 | 6358 | if (*md_startfile_prefix) |
4977bab6 | 6359 | add_sysrooted_prefix (&startfile_prefixes, md_startfile_prefix, |
1a5d37a1 | 6360 | "GCC", PREFIX_PRIORITY_LAST, 0, 1); |
004fd4d5 | 6361 | |
2296d164 | 6362 | if (*md_startfile_prefix_1) |
4977bab6 | 6363 | add_sysrooted_prefix (&startfile_prefixes, md_startfile_prefix_1, |
1a5d37a1 | 6364 | "GCC", PREFIX_PRIORITY_LAST, 0, 1); |
607a4f7d | 6365 | |
4dbc7773 ILT |
6366 | /* If standard_startfile_prefix is relative, base it on |
6367 | standard_exec_prefix. This lets us move the installed tree | |
6368 | as a unit. If GCC_EXEC_PREFIX is defined, base | |
0d037580 DJ |
6369 | standard_startfile_prefix on that as well. |
6370 | ||
6371 | If the prefix is relative, only search it for native compilers; | |
6372 | otherwise we will search a directory containing host libraries. */ | |
3dce1408 | 6373 | if (IS_ABSOLUTE_PATH (standard_startfile_prefix)) |
4977bab6 ZW |
6374 | add_sysrooted_prefix (&startfile_prefixes, |
6375 | standard_startfile_prefix, "BINUTILS", | |
1a5d37a1 | 6376 | PREFIX_PRIORITY_LAST, 0, 1); |
0d037580 | 6377 | else if (*cross_compile == '0') |
4dbc7773 | 6378 | { |
48ff801b | 6379 | add_prefix (&startfile_prefixes, |
b8698a0f L |
6380 | concat (gcc_exec_prefix |
6381 | ? gcc_exec_prefix : standard_exec_prefix, | |
6382 | machine_suffix, | |
d4f2852f | 6383 | standard_startfile_prefix, NULL), |
1a5d37a1 | 6384 | NULL, PREFIX_PRIORITY_LAST, 0, 1); |
9218435e | 6385 | } |
4dbc7773 | 6386 | |
f4c0a303 CD |
6387 | /* Sysrooted prefixes are relocated because target_system_root is |
6388 | also relocated by gcc_exec_prefix. */ | |
656c7a3a AL |
6389 | if (*standard_startfile_prefix_1) |
6390 | add_sysrooted_prefix (&startfile_prefixes, | |
6391 | standard_startfile_prefix_1, "BINUTILS", | |
1a5d37a1 | 6392 | PREFIX_PRIORITY_LAST, 0, 1); |
656c7a3a AL |
6393 | if (*standard_startfile_prefix_2) |
6394 | add_sysrooted_prefix (&startfile_prefixes, | |
6395 | standard_startfile_prefix_2, "BINUTILS", | |
1a5d37a1 | 6396 | PREFIX_PRIORITY_LAST, 0, 1); |
004fd4d5 | 6397 | } |
343f59d9 | 6398 | |
8607048d TT |
6399 | /* Process any user specified specs in the order given on the command |
6400 | line. */ | |
6401 | for (uptr = user_specs_head; uptr; uptr = uptr->next) | |
6402 | { | |
5bbcd587 | 6403 | char *filename = find_a_file (&startfile_prefixes, uptr->filename, |
00dcee0c | 6404 | R_OK, true); |
8607048d TT |
6405 | read_specs (filename ? filename : uptr->filename, FALSE); |
6406 | } | |
6407 | ||
84f405a1 JJ |
6408 | /* Process any user self specs. */ |
6409 | { | |
6410 | struct spec_list *sl; | |
6411 | for (sl = specs; sl; sl = sl->next) | |
6412 | if (sl->name_len == sizeof "self_spec" - 1 | |
6413 | && !strcmp (sl->name, "self_spec")) | |
6414 | do_self_spec (*sl->ptr_spec); | |
6415 | } | |
6416 | ||
6417 | if (compare_debug) | |
6418 | { | |
6419 | enum save_temps save; | |
6420 | ||
6421 | if (!compare_debug_second) | |
6422 | { | |
6423 | n_switches_debug_check[1] = n_switches; | |
6424 | n_switches_alloc_debug_check[1] = n_switches_alloc; | |
6425 | switches_debug_check[1] = XDUPVEC (struct switchstr, switches, | |
6426 | n_switches_alloc); | |
6427 | ||
6428 | do_self_spec ("%:compare-debug-self-opt()"); | |
6429 | n_switches_debug_check[0] = n_switches; | |
6430 | n_switches_alloc_debug_check[0] = n_switches_alloc; | |
6431 | switches_debug_check[0] = switches; | |
6432 | ||
6433 | n_switches = n_switches_debug_check[1]; | |
6434 | n_switches_alloc = n_switches_alloc_debug_check[1]; | |
6435 | switches = switches_debug_check[1]; | |
6436 | } | |
6437 | ||
6438 | /* Avoid crash when computing %j in this early. */ | |
6439 | save = save_temps_flag; | |
6440 | save_temps_flag = SAVE_TEMPS_NONE; | |
6441 | ||
6442 | compare_debug = -compare_debug; | |
6443 | do_self_spec ("%:compare-debug-self-opt()"); | |
6444 | ||
6445 | save_temps_flag = save; | |
6446 | ||
6447 | if (!compare_debug_second) | |
6448 | { | |
6449 | n_switches_debug_check[1] = n_switches; | |
6450 | n_switches_alloc_debug_check[1] = n_switches_alloc; | |
6451 | switches_debug_check[1] = switches; | |
6452 | compare_debug = -compare_debug; | |
6453 | n_switches = n_switches_debug_check[0]; | |
6454 | n_switches_alloc = n_switches_debug_check[0]; | |
6455 | switches = switches_debug_check[0]; | |
6456 | } | |
6457 | } | |
6458 | ||
6459 | ||
e8601ecb JW |
6460 | /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */ |
6461 | if (gcc_exec_prefix) | |
cb6edbcb KG |
6462 | gcc_exec_prefix = concat (gcc_exec_prefix, spec_machine, dir_separator_str, |
6463 | spec_version, dir_separator_str, NULL); | |
004fd4d5 | 6464 | |
ed1f651b RS |
6465 | /* Now we have the specs. |
6466 | Set the `valid' bits for switches that match anything in any spec. */ | |
6467 | ||
6468 | validate_all_switches (); | |
6469 | ||
60103a34 DE |
6470 | /* Now that we have the switches and the specs, set |
6471 | the subdirectory based on the options. */ | |
6472 | set_multilib_dir (); | |
6473 | ||
d7f09764 | 6474 | /* Set up to remember the pathname of gcc and any options |
6afbc885 | 6475 | needed for collect. We use argv[0] instead of progname because |
d7f09764 DN |
6476 | we need the complete pathname. */ |
6477 | obstack_init (&collect_obstack); | |
6478 | obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=") - 1); | |
6479 | obstack_grow (&collect_obstack, argv[0], strlen (argv[0]) + 1); | |
6480 | xputenv (XOBFINISH (&collect_obstack, char *)); | |
6481 | ||
6482 | /* Set up to remember the pathname of the lto wrapper. */ | |
6483 | ||
117cb2bc JJ |
6484 | if (have_c) |
6485 | lto_wrapper_file = NULL; | |
6486 | else | |
6487 | lto_wrapper_file = find_a_file (&exec_prefixes, "lto-wrapper", | |
6488 | X_OK, false); | |
de9a793e | 6489 | if (lto_wrapper_file) |
d7f09764 | 6490 | { |
de9a793e | 6491 | lto_wrapper_spec = lto_wrapper_file; |
d7f09764 DN |
6492 | obstack_init (&collect_obstack); |
6493 | obstack_grow (&collect_obstack, "COLLECT_LTO_WRAPPER=", | |
6494 | sizeof ("COLLECT_LTO_WRAPPER=") - 1); | |
6495 | obstack_grow (&collect_obstack, lto_wrapper_spec, | |
6496 | strlen (lto_wrapper_spec) + 1); | |
6497 | xputenv (XOBFINISH (&collect_obstack, char *)); | |
6498 | } | |
6499 | ||
ed1f651b RS |
6500 | /* Warn about any switches that no pass was interested in. */ |
6501 | ||
d25a45d4 | 6502 | for (i = 0; (int) i < n_switches; i++) |
ab87f8c8 | 6503 | if (! switches[i].validated) |
bdc6b402 | 6504 | error ("unrecognized option %<-%s%>", switches[i].part1); |
ed1f651b | 6505 | |
6a9e290e RK |
6506 | /* Obey some of the options. */ |
6507 | ||
2628b9d3 DE |
6508 | if (print_search_dirs) |
6509 | { | |
f4c0a303 CD |
6510 | printf (_("install: %s%s\n"), |
6511 | gcc_exec_prefix ? gcc_exec_prefix : standard_exec_prefix, | |
6512 | gcc_exec_prefix ? "" : machine_suffix); | |
00dcee0c AM |
6513 | printf (_("programs: %s\n"), |
6514 | build_search_list (&exec_prefixes, "", false, false)); | |
6515 | printf (_("libraries: %s\n"), | |
6516 | build_search_list (&startfile_prefixes, "", false, true)); | |
9257393c | 6517 | return (0); |
2628b9d3 DE |
6518 | } |
6519 | ||
6a9e290e | 6520 | if (print_file_name) |
2dcb563f | 6521 | { |
6a9e290e | 6522 | printf ("%s\n", find_file (print_file_name)); |
9257393c | 6523 | return (0); |
2dcb563f RS |
6524 | } |
6525 | ||
6a9e290e RK |
6526 | if (print_prog_name) |
6527 | { | |
5bbcd587 | 6528 | char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK, 0); |
6a9e290e | 6529 | printf ("%s\n", (newname ? newname : print_prog_name)); |
9257393c | 6530 | return (0); |
6a9e290e | 6531 | } |
ed1f651b | 6532 | |
60103a34 DE |
6533 | if (print_multi_lib) |
6534 | { | |
6535 | print_multilib_info (); | |
9257393c | 6536 | return (0); |
60103a34 DE |
6537 | } |
6538 | ||
6539 | if (print_multi_directory) | |
6540 | { | |
6541 | if (multilib_dir == NULL) | |
6542 | printf (".\n"); | |
6543 | else | |
6544 | printf ("%s\n", multilib_dir); | |
9257393c | 6545 | return (0); |
60103a34 DE |
6546 | } |
6547 | ||
3def1397 VP |
6548 | if (print_sysroot) |
6549 | { | |
6550 | if (target_system_root) | |
6551 | { | |
6552 | if (target_sysroot_suffix) | |
6553 | printf ("%s%s\n", target_system_root, target_sysroot_suffix); | |
6554 | else | |
6555 | printf ("%s\n", target_system_root); | |
6556 | } | |
6557 | return (0); | |
6558 | } | |
6559 | ||
5bbcd587 JJ |
6560 | if (print_multi_os_directory) |
6561 | { | |
6562 | if (multilib_os_dir == NULL) | |
6563 | printf (".\n"); | |
6564 | else | |
6565 | printf ("%s\n", multilib_os_dir); | |
6566 | return (0); | |
6567 | } | |
6568 | ||
14da6073 JM |
6569 | if (print_sysroot_headers_suffix) |
6570 | { | |
6571 | if (*sysroot_hdrs_suffix_spec) | |
6572 | { | |
dc5bbad3 JM |
6573 | printf("%s\n", (target_sysroot_hdrs_suffix |
6574 | ? target_sysroot_hdrs_suffix | |
6575 | : "")); | |
14da6073 JM |
6576 | return (0); |
6577 | } | |
6578 | else | |
6579 | /* The error status indicates that only one set of fixed | |
6580 | headers should be built. */ | |
2dec80c7 | 6581 | fatal_error ("not configured with sysroot headers suffix"); |
14da6073 JM |
6582 | } |
6583 | ||
b8468bc7 NC |
6584 | if (print_help_list) |
6585 | { | |
6586 | display_help (); | |
6587 | ||
6588 | if (! verbose_flag) | |
6589 | { | |
5e4adfba | 6590 | printf (_("\nFor bug reporting instructions, please see:\n")); |
a976603e | 6591 | printf ("%s.\n", bug_report_url); |
9218435e | 6592 | |
9257393c | 6593 | return (0); |
b8468bc7 NC |
6594 | } |
6595 | ||
6596 | /* We do not exit here. Instead we have created a fake input file | |
6597 | called 'help-dummy' which needs to be compiled, and we pass this | |
033505fc RW |
6598 | on the various sub-processes, along with the --help switch. |
6599 | Ensure their output appears after ours. */ | |
6600 | fputc ('\n', stdout); | |
6601 | fflush (stdout); | |
b8468bc7 | 6602 | } |
9218435e | 6603 | |
41fd0f9b RAE |
6604 | if (print_version) |
6605 | { | |
6afbc885 | 6606 | printf (_("%s %s%s\n"), progname, pkgversion_string, |
41fd0f9b | 6607 | version_string); |
66f1b195 | 6608 | printf ("Copyright %s 2012 Free Software Foundation, Inc.\n", |
41fd0f9b RAE |
6609 | _("(C)")); |
6610 | fputs (_("This is free software; see the source for copying conditions. There is NO\n\ | |
6611 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"), | |
6612 | stdout); | |
6613 | if (! verbose_flag) | |
6614 | return 0; | |
6615 | ||
6616 | /* We do not exit here. We use the same mechanism of --help to print | |
6617 | the version of the sub-processes. */ | |
6618 | fputc ('\n', stdout); | |
6619 | fflush (stdout); | |
6620 | } | |
6621 | ||
ed1f651b RS |
6622 | if (verbose_flag) |
6623 | { | |
7ad9ff7a | 6624 | int n; |
008355a6 | 6625 | const char *thrmod; |
7ad9ff7a | 6626 | |
2dec80c7 JM |
6627 | fnotice (stderr, "Target: %s\n", spec_machine); |
6628 | fnotice (stderr, "Configured with: %s\n", configuration_arguments); | |
f5fa9a5b | 6629 | |
008355a6 AO |
6630 | #ifdef THREAD_MODEL_SPEC |
6631 | /* We could have defined THREAD_MODEL_SPEC to "%*" by default, | |
6632 | but there's no point in doing all this processing just to get | |
6633 | thread_model back. */ | |
6634 | obstack_init (&obstack); | |
6635 | do_spec_1 (THREAD_MODEL_SPEC, 0, thread_model); | |
6636 | obstack_1grow (&obstack, '\0'); | |
7973fd2a | 6637 | thrmod = XOBFINISH (&obstack, const char *); |
008355a6 AO |
6638 | #else |
6639 | thrmod = thread_model; | |
6640 | #endif | |
6641 | ||
2dec80c7 | 6642 | fnotice (stderr, "Thread model: %s\n", thrmod); |
a6687d2b | 6643 | |
7ad9ff7a DE |
6644 | /* compiler_version is truncated at the first space when initialized |
6645 | from version string, so truncate version_string at the first space | |
6646 | before comparing. */ | |
6647 | for (n = 0; version_string[n]; n++) | |
6648 | if (version_string[n] == ' ') | |
6649 | break; | |
6650 | ||
6651 | if (! strncmp (version_string, compiler_version, n) | |
6652 | && compiler_version[n] == 0) | |
2dec80c7 JM |
6653 | fnotice (stderr, "gcc version %s %s\n", version_string, |
6654 | pkgversion_string); | |
9c4faac1 | 6655 | else |
2dec80c7 JM |
6656 | fnotice (stderr, "gcc driver version %s %sexecuting gcc version %s\n", |
6657 | version_string, pkgversion_string, compiler_version); | |
9c4faac1 | 6658 | |
ed1f651b | 6659 | if (n_infiles == 0) |
9257393c | 6660 | return (0); |
ed1f651b RS |
6661 | } |
6662 | ||
a2a05b0a | 6663 | if (n_infiles == added_libraries) |
2dec80c7 | 6664 | fatal_error ("no input files"); |
ed1f651b | 6665 | |
4df47bca JM |
6666 | if (seen_error ()) |
6667 | goto out; | |
6668 | ||
ed1f651b RS |
6669 | /* Make a place to record the compiler output file names |
6670 | that correspond to the input files. */ | |
6671 | ||
f271358e | 6672 | i = n_infiles; |
e37cda9b | 6673 | i += lang_specific_extra_outfiles; |
5ed6ace5 | 6674 | outfiles = XCNEWVEC (const char *, i); |
ed1f651b RS |
6675 | |
6676 | /* Record which files were specified explicitly as link input. */ | |
6677 | ||
d900f77d | 6678 | explicit_link_files = XCNEWVEC (char, n_infiles); |
ed1f651b | 6679 | |
56b721c5 | 6680 | combine_inputs = have_o || flag_wpa; |
0855eab7 CT |
6681 | |
6682 | for (i = 0; (int) i < n_infiles; i++) | |
d1bd0ded | 6683 | { |
0855eab7 | 6684 | const char *name = infiles[i].name; |
7904f95f EC |
6685 | struct compiler *compiler = lookup_compiler (name, |
6686 | strlen (name), | |
0855eab7 | 6687 | infiles[i].language); |
7904f95f | 6688 | |
0855eab7 CT |
6689 | if (compiler && !(compiler->combinable)) |
6690 | combine_inputs = false; | |
7904f95f | 6691 | |
0855eab7 CT |
6692 | if (lang_n_infiles > 0 && compiler != input_file_compiler |
6693 | && infiles[i].language && infiles[i].language[0] != '*') | |
6694 | infiles[i].incompiler = compiler; | |
6695 | else if (compiler) | |
6696 | { | |
6697 | lang_n_infiles++; | |
6698 | input_file_compiler = compiler; | |
6699 | infiles[i].incompiler = compiler; | |
6700 | } | |
6701 | else | |
6702 | { | |
6703 | /* Since there is no compiler for this input file, assume it is a | |
9cf737f8 | 6704 | linker file. */ |
0855eab7 CT |
6705 | explicit_link_files[i] = 1; |
6706 | infiles[i].incompiler = NULL; | |
6707 | } | |
6708 | infiles[i].compiled = false; | |
6709 | infiles[i].preprocessed = false; | |
d1bd0ded | 6710 | } |
953ff289 | 6711 | |
de19a50e | 6712 | if (!combine_inputs && have_c && have_o && lang_n_infiles > 1) |
c3224d6f | 6713 | fatal_error ("cannot specify -o with -c, -S or -E with multiple files"); |
0855eab7 CT |
6714 | |
6715 | for (i = 0; (int) i < n_infiles; i++) | |
ed1f651b | 6716 | { |
ed1f651b RS |
6717 | int this_file_error = 0; |
6718 | ||
6719 | /* Tell do_spec what to substitute for %i. */ | |
6720 | ||
ed1f651b | 6721 | input_file_number = i; |
512b62fb | 6722 | set_input (infiles[i].name); |
ed1f651b | 6723 | |
0855eab7 CT |
6724 | if (infiles[i].compiled) |
6725 | continue; | |
6726 | ||
ed1f651b RS |
6727 | /* Use the same thing in %o, unless cp->spec says otherwise. */ |
6728 | ||
6afbc885 | 6729 | outfiles[i] = gcc_input_filename; |
ed1f651b RS |
6730 | |
6731 | /* Figure out which compiler from the file's suffix. */ | |
6732 | ||
c3224d6f RG |
6733 | input_file_compiler |
6734 | = lookup_compiler (infiles[i].name, input_filename_length, | |
6735 | infiles[i].language); | |
589005ff | 6736 | |
a9374841 | 6737 | if (input_file_compiler) |
ed1f651b RS |
6738 | { |
6739 | /* Ok, we found an applicable compiler. Run its spec. */ | |
ed1f651b | 6740 | |
a9374841 | 6741 | if (input_file_compiler->spec[0] == '#') |
d644be7b ZW |
6742 | { |
6743 | error ("%s: %s compiler not installed on this system", | |
6afbc885 | 6744 | gcc_input_filename, &input_file_compiler->spec[1]); |
d644be7b ZW |
6745 | this_file_error = 1; |
6746 | } | |
6747 | else | |
6748 | { | |
2153915d AO |
6749 | if (compare_debug) |
6750 | { | |
04695783 | 6751 | free (debug_check_temp_file[0]); |
2153915d AO |
6752 | debug_check_temp_file[0] = NULL; |
6753 | ||
04695783 | 6754 | free (debug_check_temp_file[1]); |
2153915d AO |
6755 | debug_check_temp_file[1] = NULL; |
6756 | } | |
6757 | ||
d644be7b | 6758 | value = do_spec (input_file_compiler->spec); |
0855eab7 | 6759 | infiles[i].compiled = true; |
d644be7b | 6760 | if (value < 0) |
b21292d0 | 6761 | this_file_error = 1; |
2153915d AO |
6762 | else if (compare_debug && debug_check_temp_file[0]) |
6763 | { | |
6764 | if (verbose_flag) | |
2dec80c7 | 6765 | inform (0, "recompiling with -fcompare-debug"); |
2153915d AO |
6766 | |
6767 | compare_debug = -compare_debug; | |
6768 | n_switches = n_switches_debug_check[1]; | |
efe5e5a0 | 6769 | n_switches_alloc = n_switches_alloc_debug_check[1]; |
2153915d AO |
6770 | switches = switches_debug_check[1]; |
6771 | ||
6772 | value = do_spec (input_file_compiler->spec); | |
6773 | ||
6774 | compare_debug = -compare_debug; | |
6775 | n_switches = n_switches_debug_check[0]; | |
efe5e5a0 | 6776 | n_switches_alloc = n_switches_alloc_debug_check[0]; |
2153915d AO |
6777 | switches = switches_debug_check[0]; |
6778 | ||
6779 | if (value < 0) | |
6780 | { | |
6781 | error ("during -fcompare-debug recompilation"); | |
6782 | this_file_error = 1; | |
6783 | } | |
6784 | ||
6785 | gcc_assert (debug_check_temp_file[1] | |
ba78087b KT |
6786 | && filename_cmp (debug_check_temp_file[0], |
6787 | debug_check_temp_file[1])); | |
2153915d AO |
6788 | |
6789 | if (verbose_flag) | |
2dec80c7 | 6790 | inform (0, "comparing final insns dumps"); |
2153915d AO |
6791 | |
6792 | if (compare_files (debug_check_temp_file)) | |
6793 | this_file_error = 1; | |
6794 | } | |
6795 | ||
6796 | if (compare_debug) | |
6797 | { | |
04695783 | 6798 | free (debug_check_temp_file[0]); |
2153915d AO |
6799 | debug_check_temp_file[0] = NULL; |
6800 | ||
04695783 | 6801 | free (debug_check_temp_file[1]); |
2153915d AO |
6802 | debug_check_temp_file[1] = NULL; |
6803 | } | |
d644be7b | 6804 | } |
ed1f651b RS |
6805 | } |
6806 | ||
6807 | /* If this file's name does not contain a recognized suffix, | |
6808 | record it as explicit linker input. */ | |
6809 | ||
6810 | else | |
6811 | explicit_link_files[i] = 1; | |
6812 | ||
6813 | /* Clear the delete-on-failure queue, deleting the files in it | |
6814 | if this compilation failed. */ | |
6815 | ||
6816 | if (this_file_error) | |
6817 | { | |
6818 | delete_failure_queue (); | |
6afbc885 | 6819 | errorcount++; |
ed1f651b RS |
6820 | } |
6821 | /* If this compilation succeeded, don't delete those files later. */ | |
6822 | clear_failure_queue (); | |
6823 | } | |
6824 | ||
817a8255 EC |
6825 | /* Reset the input file name to the first compile/object file name, for use |
6826 | with %b in LINK_SPEC. We use the first input file that we can find | |
7904f95f | 6827 | a compiler to compile it instead of using infiles.language since for |
817a8255 | 6828 | languages other than C we use aliases that we then lookup later. */ |
512b62fb | 6829 | if (n_infiles > 0) |
817a8255 EC |
6830 | { |
6831 | int i; | |
6832 | ||
6833 | for (i = 0; i < n_infiles ; i++) | |
42113d6b RG |
6834 | if (infiles[i].incompiler |
6835 | || (infiles[i].language && infiles[i].language[0] != '*')) | |
817a8255 EC |
6836 | { |
6837 | set_input (infiles[i].name); | |
6838 | break; | |
6839 | } | |
6840 | } | |
512b62fb | 6841 | |
6afbc885 | 6842 | if (!seen_error ()) |
15c5edb9 TT |
6843 | { |
6844 | /* Make sure INPUT_FILE_NUMBER points to first available open | |
6845 | slot. */ | |
6846 | input_file_number = n_infiles; | |
6847 | if (lang_specific_pre_link ()) | |
6afbc885 | 6848 | errorcount++; |
15c5edb9 | 6849 | } |
f271358e | 6850 | |
17211ab5 GK |
6851 | /* Determine if there are any linker input files. */ |
6852 | num_linker_inputs = 0; | |
6853 | for (i = 0; (int) i < n_infiles; i++) | |
6854 | if (explicit_link_files[i] || outfiles[i] != NULL) | |
6855 | num_linker_inputs++; | |
6856 | ||
ed1f651b RS |
6857 | /* Run ld to link all the compiler output files. */ |
6858 | ||
6afbc885 | 6859 | if (num_linker_inputs > 0 && !seen_error () && print_subprocess_help < 2) |
ed1f651b RS |
6860 | { |
6861 | int tmp = execution_count; | |
117cb2bc JJ |
6862 | |
6863 | if (! have_c) | |
6864 | { | |
55b46574 RO |
6865 | #if HAVE_LTO_PLUGIN > 0 |
6866 | #if HAVE_LTO_PLUGIN == 2 | |
117cb2bc | 6867 | const char *fno_use_linker_plugin = "fno-use-linker-plugin"; |
96bdf9b4 | 6868 | #else |
117cb2bc | 6869 | const char *fuse_linker_plugin = "fuse-linker-plugin"; |
55b46574 | 6870 | #endif |
96bdf9b4 | 6871 | #endif |
b3865ca9 | 6872 | |
117cb2bc JJ |
6873 | /* We'll use ld if we can't find collect2. */ |
6874 | if (! strcmp (linker_name_spec, "collect2")) | |
6875 | { | |
6876 | char *s = find_a_file (&exec_prefixes, "collect2", X_OK, false); | |
6877 | if (s == NULL) | |
6878 | linker_name_spec = "ld"; | |
6879 | } | |
d7f09764 | 6880 | |
55b46574 RO |
6881 | #if HAVE_LTO_PLUGIN > 0 |
6882 | #if HAVE_LTO_PLUGIN == 2 | |
117cb2bc JJ |
6883 | if (!switch_matches (fno_use_linker_plugin, |
6884 | fno_use_linker_plugin | |
6885 | + strlen (fno_use_linker_plugin), 0)) | |
96bdf9b4 | 6886 | #else |
117cb2bc JJ |
6887 | if (switch_matches (fuse_linker_plugin, |
6888 | fuse_linker_plugin | |
6889 | + strlen (fuse_linker_plugin), 0)) | |
96bdf9b4 | 6890 | #endif |
117cb2bc JJ |
6891 | { |
6892 | linker_plugin_file_spec = find_a_file (&exec_prefixes, | |
6893 | LTOPLUGINSONAME, R_OK, | |
6894 | false); | |
6895 | if (!linker_plugin_file_spec) | |
6896 | fatal_error ("-fuse-linker-plugin, but %s not found", | |
6897 | LTOPLUGINSONAME); | |
6898 | } | |
55b46574 | 6899 | #endif |
117cb2bc JJ |
6900 | lto_gcc_spec = argv[0]; |
6901 | } | |
d7f09764 | 6902 | |
b3865ca9 RS |
6903 | /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables |
6904 | for collect. */ | |
00dcee0c AM |
6905 | putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH", false); |
6906 | putenv_from_prefixes (&startfile_prefixes, LIBRARY_PATH_ENV, true); | |
b3865ca9 | 6907 | |
a0f87454 RS |
6908 | if (print_subprocess_help == 1) |
6909 | { | |
6910 | printf (_("\nLinker options\n==============\n\n")); | |
6911 | printf (_("Use \"-Wl,OPTION\" to pass \"OPTION\"" | |
6912 | " to the linker.\n\n")); | |
6913 | fflush (stdout); | |
6914 | } | |
ed1f651b RS |
6915 | value = do_spec (link_command_spec); |
6916 | if (value < 0) | |
6afbc885 | 6917 | errorcount = 1; |
ed1f651b RS |
6918 | linker_was_run = (tmp != execution_count); |
6919 | } | |
6920 | ||
ed1f651b RS |
6921 | /* If options said don't run linker, |
6922 | complain about input files to be given to the linker. */ | |
6923 | ||
6afbc885 | 6924 | if (! linker_was_run && !seen_error ()) |
d25a45d4 | 6925 | for (i = 0; (int) i < n_infiles; i++) |
01e4dd0d KH |
6926 | if (explicit_link_files[i] |
6927 | && !(infiles[i].language && infiles[i].language[0] == '*')) | |
2dec80c7 JM |
6928 | warning (0, "%s: linker input file unused because linking not done", |
6929 | outfiles[i]); | |
ed1f651b RS |
6930 | |
6931 | /* Delete some or all of the temporary files we made. */ | |
6932 | ||
6afbc885 | 6933 | if (seen_error ()) |
ed1f651b RS |
6934 | delete_failure_queue (); |
6935 | delete_temp_files (); | |
6936 | ||
b8468bc7 NC |
6937 | if (print_help_list) |
6938 | { | |
5e4adfba | 6939 | printf (("\nFor bug reporting instructions, please see:\n")); |
a976603e | 6940 | printf ("%s\n", bug_report_url); |
b8468bc7 | 6941 | } |
9218435e | 6942 | |
4df47bca | 6943 | out: |
14a774a9 | 6944 | return (signal_count != 0 ? 2 |
6afbc885 | 6945 | : seen_error () ? (pass_exit_codes ? greatest_status : 1) |
14a774a9 | 6946 | : 0); |
ed1f651b RS |
6947 | } |
6948 | ||
6949 | /* Find the proper compilation spec for the file name NAME, | |
004fd4d5 | 6950 | whose length is LENGTH. LANGUAGE is the specified language, |
e5e809f4 | 6951 | or 0 if this file is to be passed to the linker. */ |
ed1f651b RS |
6952 | |
6953 | static struct compiler * | |
1d088dee | 6954 | lookup_compiler (const char *name, size_t length, const char *language) |
ed1f651b RS |
6955 | { |
6956 | struct compiler *cp; | |
6957 | ||
3ac63d94 | 6958 | /* If this was specified by the user to be a linker input, indicate that. */ |
e5e809f4 JL |
6959 | if (language != 0 && language[0] == '*') |
6960 | return 0; | |
6961 | ||
6962 | /* Otherwise, look for the language, if one is spec'd. */ | |
ed1f651b RS |
6963 | if (language != 0) |
6964 | { | |
6965 | for (cp = compilers + n_compilers - 1; cp >= compilers; cp--) | |
e5e809f4 JL |
6966 | if (cp->suffix[0] == '@' && !strcmp (cp->suffix + 1, language)) |
6967 | return cp; | |
6968 | ||
ed1f651b | 6969 | error ("language %s not recognized", language); |
e5e809f4 | 6970 | return 0; |
ed1f651b RS |
6971 | } |
6972 | ||
6973 | /* Look for a suffix. */ | |
6974 | for (cp = compilers + n_compilers - 1; cp >= compilers; cp--) | |
6975 | { | |
4cf3301c RS |
6976 | if (/* The suffix `-' matches only the file name `-'. */ |
6977 | (!strcmp (cp->suffix, "-") && !strcmp (name, "-")) | |
e5e809f4 JL |
6978 | || (strlen (cp->suffix) < length |
6979 | /* See if the suffix matches the end of NAME. */ | |
e5e809f4 JL |
6980 | && !strcmp (cp->suffix, |
6981 | name + length - strlen (cp->suffix)) | |
e5e809f4 | 6982 | )) |
589005ff | 6983 | break; |
03bf1c28 | 6984 | } |
e5e809f4 | 6985 | |
03bf1c28 | 6986 | #if defined (OS2) ||defined (HAVE_DOS_BASED_FILE_SYSTEM) |
a1105617 | 6987 | /* Look again, but case-insensitively this time. */ |
03bf1c28 MK |
6988 | if (cp < compilers) |
6989 | for (cp = compilers + n_compilers - 1; cp >= compilers; cp--) | |
6990 | { | |
6991 | if (/* The suffix `-' matches only the file name `-'. */ | |
6992 | (!strcmp (cp->suffix, "-") && !strcmp (name, "-")) | |
6993 | || (strlen (cp->suffix) < length | |
6994 | /* See if the suffix matches the end of NAME. */ | |
6995 | && ((!strcmp (cp->suffix, | |
6996 | name + length - strlen (cp->suffix)) | |
6997 | || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")) | |
6998 | && !strcasecmp (cp->suffix, | |
6999 | name + length - strlen (cp->suffix))) | |
7000 | )) | |
7001 | break; | |
7002 | } | |
7003 | #endif | |
7004 | ||
03bf1c28 MK |
7005 | if (cp >= compilers) |
7006 | { | |
ea414c97 ZW |
7007 | if (cp->spec[0] != '@') |
7008 | /* A non-alias entry: return it. */ | |
7009 | return cp; | |
9218435e | 7010 | |
ea414c97 ZW |
7011 | /* An alias entry maps a suffix to a language. |
7012 | Search for the language; pass 0 for NAME and LENGTH | |
7013 | to avoid infinite recursion if language not found. */ | |
6496a589 | 7014 | return lookup_compiler (NULL, 0, cp->spec + 1); |
ed1f651b | 7015 | } |
ed1f651b RS |
7016 | return 0; |
7017 | } | |
7018 | \f | |
ed1f651b | 7019 | static char * |
1d088dee | 7020 | save_string (const char *s, int len) |
ed1f651b | 7021 | { |
5ed6ace5 | 7022 | char *result = XNEWVEC (char, len + 1); |
ed1f651b | 7023 | |
da61dec9 | 7024 | memcpy (result, s, len); |
ed1f651b RS |
7025 | result[len] = 0; |
7026 | return result; | |
7027 | } | |
7028 | ||
d991c721 | 7029 | void |
1d088dee | 7030 | pfatal_with_name (const char *name) |
ed1f651b | 7031 | { |
ab87f8c8 JL |
7032 | perror_with_name (name); |
7033 | delete_temp_files (); | |
7034 | exit (1); | |
ed1f651b RS |
7035 | } |
7036 | ||
7037 | static void | |
1d088dee | 7038 | perror_with_name (const char *name) |
ed1f651b | 7039 | { |
bdc6b402 | 7040 | error ("%s: %m", name); |
ed1f651b | 7041 | } |
ed1f651b | 7042 | \f |
4977bab6 | 7043 | static inline void |
1d088dee | 7044 | validate_switches_from_spec (const char *spec) |
4977bab6 ZW |
7045 | { |
7046 | const char *p = spec; | |
7047 | char c; | |
7048 | while ((c = *p++)) | |
7049 | if (c == '%' && (*p == '{' || *p == '<' || (*p == 'W' && *++p == '{'))) | |
7050 | /* We have a switch spec. */ | |
7051 | p = validate_switches (p + 1); | |
7052 | } | |
7053 | ||
ed1f651b | 7054 | static void |
1d088dee | 7055 | validate_all_switches (void) |
ed1f651b RS |
7056 | { |
7057 | struct compiler *comp; | |
b3865ca9 | 7058 | struct spec_list *spec; |
ed1f651b | 7059 | |
ea414c97 | 7060 | for (comp = compilers; comp->spec; comp++) |
4977bab6 | 7061 | validate_switches_from_spec (comp->spec); |
ed1f651b | 7062 | |
3ac63d94 | 7063 | /* Look through the linked list of specs read from the specs file. */ |
d25a45d4 | 7064 | for (spec = specs; spec; spec = spec->next) |
4977bab6 | 7065 | validate_switches_from_spec (*spec->ptr_spec); |
b3865ca9 | 7066 | |
4977bab6 | 7067 | validate_switches_from_spec (link_command_spec); |
ed1f651b RS |
7068 | } |
7069 | ||
7070 | /* Look at the switch-name that comes after START | |
7071 | and mark as valid all supplied switches that match it. */ | |
7072 | ||
4977bab6 | 7073 | static const char * |
1d088dee | 7074 | validate_switches (const char *start) |
ed1f651b | 7075 | { |
b3694847 | 7076 | const char *p = start; |
4977bab6 ZW |
7077 | const char *atom; |
7078 | size_t len; | |
b3694847 | 7079 | int i; |
4977bab6 ZW |
7080 | bool suffix = false; |
7081 | bool starred = false; | |
1d088dee | 7082 | |
4977bab6 | 7083 | #define SKIP_WHITE() do { while (*p == ' ' || *p == '\t') p++; } while (0) |
1d088dee | 7084 | |
10ebf5fe | 7085 | next_member: |
4977bab6 ZW |
7086 | SKIP_WHITE (); |
7087 | ||
ed1f651b | 7088 | if (*p == '!') |
4977bab6 | 7089 | p++; |
ed1f651b | 7090 | |
4977bab6 | 7091 | SKIP_WHITE (); |
48137d59 | 7092 | if (*p == '.' || *p == ',') |
4977bab6 | 7093 | suffix = true, p++; |
ed1f651b | 7094 | |
4977bab6 ZW |
7095 | atom = p; |
7096 | while (ISIDNUM (*p) || *p == '-' || *p == '+' || *p == '=' | |
7a975113 | 7097 | || *p == ',' || *p == '.' || *p == '@') |
d25a45d4 | 7098 | p++; |
4977bab6 | 7099 | len = p - atom; |
ed1f651b | 7100 | |
4977bab6 ZW |
7101 | if (*p == '*') |
7102 | starred = true, p++; | |
7103 | ||
7104 | SKIP_WHITE (); | |
7105 | ||
7106 | if (!suffix) | |
ed1f651b RS |
7107 | { |
7108 | /* Mark all matching switches as valid. */ | |
ed1f651b | 7109 | for (i = 0; i < n_switches; i++) |
4977bab6 ZW |
7110 | if (!strncmp (switches[i].part1, atom, len) |
7111 | && (starred || switches[i].part1[len] == 0)) | |
ab87f8c8 | 7112 | switches[i].validated = 1; |
ed1f651b | 7113 | } |
4977bab6 | 7114 | |
5a0ba8c9 LJR |
7115 | if (*p) p++; |
7116 | if (*p && (p[-1] == '|' || p[-1] == '&')) | |
4977bab6 ZW |
7117 | goto next_member; |
7118 | ||
5a0ba8c9 | 7119 | if (*p && p[-1] == ':') |
ed1f651b | 7120 | { |
4977bab6 | 7121 | while (*p && *p != ';' && *p != '}') |
ed1f651b | 7122 | { |
4977bab6 ZW |
7123 | if (*p == '%') |
7124 | { | |
7125 | p++; | |
7126 | if (*p == '{' || *p == '<') | |
7127 | p = validate_switches (p+1); | |
7128 | else if (p[0] == 'W' && p[1] == '{') | |
7129 | p = validate_switches (p+2); | |
7130 | } | |
e17aafd1 GK |
7131 | else |
7132 | p++; | |
ed1f651b | 7133 | } |
4977bab6 | 7134 | |
5a0ba8c9 LJR |
7135 | if (*p) p++; |
7136 | if (*p && p[-1] == ';') | |
4977bab6 | 7137 | goto next_member; |
ed1f651b | 7138 | } |
10ebf5fe | 7139 | |
4977bab6 ZW |
7140 | return p; |
7141 | #undef SKIP_WHITE | |
ed1f651b | 7142 | } |
60103a34 | 7143 | \f |
5bbcd587 JJ |
7144 | struct mdswitchstr |
7145 | { | |
7146 | const char *str; | |
7147 | int len; | |
7148 | }; | |
7149 | ||
7150 | static struct mdswitchstr *mdswitches; | |
7151 | static int n_mdswitches; | |
7152 | ||
961b7009 | 7153 | /* Check whether a particular argument was used. The first time we |
956d6950 | 7154 | canonicalize the switches to keep only the ones we care about. */ |
60103a34 DE |
7155 | |
7156 | static int | |
1d088dee | 7157 | used_arg (const char *p, int len) |
60103a34 | 7158 | { |
3ac63d94 NC |
7159 | struct mswitchstr |
7160 | { | |
3b304f5b ZW |
7161 | const char *str; |
7162 | const char *replace; | |
961b7009 MM |
7163 | int len; |
7164 | int rep_len; | |
7165 | }; | |
7166 | ||
7167 | static struct mswitchstr *mswitches; | |
7168 | static int n_mswitches; | |
7169 | int i, j; | |
7170 | ||
7171 | if (!mswitches) | |
7172 | { | |
7173 | struct mswitchstr *matches; | |
3b304f5b | 7174 | const char *q; |
c8c2dcdc | 7175 | int cnt = 0; |
961b7009 | 7176 | |
d25a45d4 KH |
7177 | /* Break multilib_matches into the component strings of string |
7178 | and replacement string. */ | |
1a0bdd29 RK |
7179 | for (q = multilib_matches; *q != '\0'; q++) |
7180 | if (*q == ';') | |
961b7009 MM |
7181 | cnt++; |
7182 | ||
e1e4cdc4 KG |
7183 | matches |
7184 | = (struct mswitchstr *) alloca ((sizeof (struct mswitchstr)) * cnt); | |
961b7009 MM |
7185 | i = 0; |
7186 | q = multilib_matches; | |
7187 | while (*q != '\0') | |
7188 | { | |
7189 | matches[i].str = q; | |
7190 | while (*q != ' ') | |
7191 | { | |
7192 | if (*q == '\0') | |
3b5edfee NS |
7193 | { |
7194 | invalid_matches: | |
bdc6b402 | 7195 | fatal_error ("multilib spec %qs is invalid", |
2dec80c7 | 7196 | multilib_matches); |
3b5edfee | 7197 | } |
961b7009 MM |
7198 | q++; |
7199 | } | |
961b7009 | 7200 | matches[i].len = q - matches[i].str; |
60103a34 | 7201 | |
961b7009 MM |
7202 | matches[i].replace = ++q; |
7203 | while (*q != ';' && *q != '\0') | |
7204 | { | |
7205 | if (*q == ' ') | |
3b5edfee | 7206 | goto invalid_matches; |
961b7009 MM |
7207 | q++; |
7208 | } | |
7209 | matches[i].rep_len = q - matches[i].replace; | |
7210 | i++; | |
83a0c799 ZW |
7211 | if (*q == ';') |
7212 | q++; | |
961b7009 | 7213 | } |
60103a34 | 7214 | |
71591a1d JW |
7215 | /* Now build a list of the replacement string for switches that we care |
7216 | about. Make sure we allocate at least one entry. This prevents | |
7217 | xmalloc from calling fatal, and prevents us from re-executing this | |
7218 | block of code. */ | |
7219 | mswitches | |
5ed6ace5 | 7220 | = XNEWVEC (struct mswitchstr, n_mdswitches + (n_switches ? n_switches : 1)); |
961b7009 | 7221 | for (i = 0; i < n_switches; i++) |
3371362c | 7222 | if ((switches[i].live_cond & SWITCH_IGNORE) == 0) |
f645e2bd RS |
7223 | { |
7224 | int xlen = strlen (switches[i].part1); | |
7225 | for (j = 0; j < cnt; j++) | |
7226 | if (xlen == matches[j].len | |
7227 | && ! strncmp (switches[i].part1, matches[j].str, xlen)) | |
7228 | { | |
7229 | mswitches[n_mswitches].str = matches[j].replace; | |
7230 | mswitches[n_mswitches].len = matches[j].rep_len; | |
7231 | mswitches[n_mswitches].replace = (char *) 0; | |
7232 | mswitches[n_mswitches].rep_len = 0; | |
7233 | n_mswitches++; | |
7234 | break; | |
7235 | } | |
7236 | } | |
5bbcd587 JJ |
7237 | |
7238 | /* Add MULTILIB_DEFAULTS switches too, as long as they were not present | |
7239 | on the command line nor any options mutually incompatible with | |
7240 | them. */ | |
7241 | for (i = 0; i < n_mdswitches; i++) | |
7242 | { | |
7243 | const char *r; | |
7244 | ||
7245 | for (q = multilib_options; *q != '\0'; q++) | |
7246 | { | |
7247 | while (*q == ' ') | |
7248 | q++; | |
7249 | ||
7250 | r = q; | |
7251 | while (strncmp (q, mdswitches[i].str, mdswitches[i].len) != 0 | |
7252 | || strchr (" /", q[mdswitches[i].len]) == NULL) | |
7253 | { | |
7254 | while (*q != ' ' && *q != '/' && *q != '\0') | |
7255 | q++; | |
7256 | if (*q != '/') | |
7257 | break; | |
7258 | q++; | |
7259 | } | |
7260 | ||
7261 | if (*q != ' ' && *q != '\0') | |
7262 | { | |
7263 | while (*r != ' ' && *r != '\0') | |
7264 | { | |
7265 | q = r; | |
7266 | while (*q != ' ' && *q != '/' && *q != '\0') | |
7267 | q++; | |
7268 | ||
7269 | if (used_arg (r, q - r)) | |
7270 | break; | |
7271 | ||
7272 | if (*q != '/') | |
7273 | { | |
7274 | mswitches[n_mswitches].str = mdswitches[i].str; | |
7275 | mswitches[n_mswitches].len = mdswitches[i].len; | |
7276 | mswitches[n_mswitches].replace = (char *) 0; | |
7277 | mswitches[n_mswitches].rep_len = 0; | |
7278 | n_mswitches++; | |
7279 | break; | |
7280 | } | |
7281 | ||
7282 | r = q + 1; | |
7283 | } | |
7284 | break; | |
7285 | } | |
7286 | } | |
7287 | } | |
961b7009 | 7288 | } |
03c42484 | 7289 | |
961b7009 MM |
7290 | for (i = 0; i < n_mswitches; i++) |
7291 | if (len == mswitches[i].len && ! strncmp (p, mswitches[i].str, len)) | |
7292 | return 1; | |
03c42484 | 7293 | |
961b7009 MM |
7294 | return 0; |
7295 | } | |
03c42484 RK |
7296 | |
7297 | static int | |
1d088dee | 7298 | default_arg (const char *p, int len) |
03c42484 | 7299 | { |
5bbcd587 | 7300 | int i; |
e29ef920 | 7301 | |
5bbcd587 JJ |
7302 | for (i = 0; i < n_mdswitches; i++) |
7303 | if (len == mdswitches[i].len && ! strncmp (p, mdswitches[i].str, len)) | |
7304 | return 1; | |
03c42484 RK |
7305 | |
7306 | return 0; | |
7307 | } | |
7308 | ||
0a8d6618 BC |
7309 | /* Work out the subdirectory to use based on the options. The format of |
7310 | multilib_select is a list of elements. Each element is a subdirectory | |
7311 | name followed by a list of options followed by a semicolon. The format | |
7312 | of multilib_exclusions is the same, but without the preceding | |
7313 | directory. First gcc will check the exclusions, if none of the options | |
7314 | beginning with an exclamation point are present, and all of the other | |
7315 | options are present, then we will ignore this completely. Passing | |
7316 | that, gcc will consider each multilib_select in turn using the same | |
7317 | rules for matching the options. If a match is found, that subdirectory | |
7318 | will be used. */ | |
60103a34 DE |
7319 | |
7320 | static void | |
1d088dee | 7321 | set_multilib_dir (void) |
60103a34 | 7322 | { |
3b304f5b | 7323 | const char *p; |
3ac63d94 | 7324 | unsigned int this_path_len; |
3b304f5b | 7325 | const char *this_path, *this_arg; |
5bbcd587 | 7326 | const char *start, *end; |
03c42484 | 7327 | int not_arg; |
5bbcd587 JJ |
7328 | int ok, ndfltok, first; |
7329 | ||
7330 | n_mdswitches = 0; | |
7331 | start = multilib_defaults; | |
7332 | while (*start == ' ' || *start == '\t') | |
7333 | start++; | |
7334 | while (*start != '\0') | |
7335 | { | |
7336 | n_mdswitches++; | |
7337 | while (*start != ' ' && *start != '\t' && *start != '\0') | |
7338 | start++; | |
7339 | while (*start == ' ' || *start == '\t') | |
7340 | start++; | |
7341 | } | |
7342 | ||
7343 | if (n_mdswitches) | |
7344 | { | |
7345 | int i = 0; | |
7346 | ||
5ed6ace5 | 7347 | mdswitches = XNEWVEC (struct mdswitchstr, n_mdswitches); |
5bbcd587 JJ |
7348 | for (start = multilib_defaults; *start != '\0'; start = end + 1) |
7349 | { | |
7350 | while (*start == ' ' || *start == '\t') | |
7351 | start++; | |
7352 | ||
7353 | if (*start == '\0') | |
7354 | break; | |
1d088dee | 7355 | |
5bbcd587 JJ |
7356 | for (end = start + 1; |
7357 | *end != ' ' && *end != '\t' && *end != '\0'; end++) | |
7358 | ; | |
7359 | ||
7360 | obstack_grow (&multilib_obstack, start, end - start); | |
7361 | obstack_1grow (&multilib_obstack, 0); | |
7973fd2a | 7362 | mdswitches[i].str = XOBFINISH (&multilib_obstack, const char *); |
5bbcd587 JJ |
7363 | mdswitches[i++].len = end - start; |
7364 | ||
7365 | if (*end == '\0') | |
7366 | break; | |
7367 | } | |
7368 | } | |
60103a34 | 7369 | |
0a8d6618 BC |
7370 | p = multilib_exclusions; |
7371 | while (*p != '\0') | |
7372 | { | |
7373 | /* Ignore newlines. */ | |
7374 | if (*p == '\n') | |
d25a45d4 KH |
7375 | { |
7376 | ++p; | |
7377 | continue; | |
7378 | } | |
0a8d6618 BC |
7379 | |
7380 | /* Check the arguments. */ | |
7381 | ok = 1; | |
7382 | while (*p != ';') | |
d25a45d4 KH |
7383 | { |
7384 | if (*p == '\0') | |
3b5edfee NS |
7385 | { |
7386 | invalid_exclusions: | |
bdc6b402 | 7387 | fatal_error ("multilib exclusions %qs is invalid", |
2dec80c7 | 7388 | multilib_exclusions); |
3b5edfee | 7389 | } |
d25a45d4 KH |
7390 | |
7391 | if (! ok) | |
7392 | { | |
7393 | ++p; | |
7394 | continue; | |
7395 | } | |
7396 | ||
7397 | this_arg = p; | |
7398 | while (*p != ' ' && *p != ';') | |
7399 | { | |
7400 | if (*p == '\0') | |
3b5edfee | 7401 | goto invalid_exclusions; |
d25a45d4 KH |
7402 | ++p; |
7403 | } | |
7404 | ||
7405 | if (*this_arg != '!') | |
7406 | not_arg = 0; | |
7407 | else | |
7408 | { | |
7409 | not_arg = 1; | |
7410 | ++this_arg; | |
7411 | } | |
9218435e | 7412 | |
0a8d6618 BC |
7413 | ok = used_arg (this_arg, p - this_arg); |
7414 | if (not_arg) | |
7415 | ok = ! ok; | |
7416 | ||
d25a45d4 KH |
7417 | if (*p == ' ') |
7418 | ++p; | |
7419 | } | |
0a8d6618 BC |
7420 | |
7421 | if (ok) | |
3ac63d94 | 7422 | return; |
0a8d6618 BC |
7423 | |
7424 | ++p; | |
7425 | } | |
7426 | ||
5bbcd587 | 7427 | first = 1; |
0a8d6618 | 7428 | p = multilib_select; |
60103a34 DE |
7429 | while (*p != '\0') |
7430 | { | |
7431 | /* Ignore newlines. */ | |
7432 | if (*p == '\n') | |
7433 | { | |
7434 | ++p; | |
7435 | continue; | |
7436 | } | |
7437 | ||
7438 | /* Get the initial path. */ | |
7439 | this_path = p; | |
7440 | while (*p != ' ') | |
7441 | { | |
7442 | if (*p == '\0') | |
3b5edfee NS |
7443 | { |
7444 | invalid_select: | |
bdc6b402 | 7445 | fatal_error ("multilib select %qs is invalid", |
2dec80c7 | 7446 | multilib_select); |
3b5edfee | 7447 | } |
60103a34 DE |
7448 | ++p; |
7449 | } | |
7450 | this_path_len = p - this_path; | |
7451 | ||
7452 | /* Check the arguments. */ | |
03c42484 | 7453 | ok = 1; |
5bbcd587 | 7454 | ndfltok = 1; |
60103a34 DE |
7455 | ++p; |
7456 | while (*p != ';') | |
7457 | { | |
7458 | if (*p == '\0') | |
3b5edfee | 7459 | goto invalid_select; |
60103a34 | 7460 | |
03c42484 | 7461 | if (! ok) |
60103a34 DE |
7462 | { |
7463 | ++p; | |
7464 | continue; | |
7465 | } | |
7466 | ||
7467 | this_arg = p; | |
7468 | while (*p != ' ' && *p != ';') | |
7469 | { | |
7470 | if (*p == '\0') | |
3b5edfee | 7471 | goto invalid_select; |
60103a34 DE |
7472 | ++p; |
7473 | } | |
7474 | ||
03c42484 RK |
7475 | if (*this_arg != '!') |
7476 | not_arg = 0; | |
60103a34 | 7477 | else |
03c42484 RK |
7478 | { |
7479 | not_arg = 1; | |
7480 | ++this_arg; | |
7481 | } | |
7482 | ||
7483 | /* If this is a default argument, we can just ignore it. | |
7484 | This is true even if this_arg begins with '!'. Beginning | |
7485 | with '!' does not mean that this argument is necessarily | |
7486 | inappropriate for this library: it merely means that | |
7487 | there is a more specific library which uses this | |
7488 | argument. If this argument is a default, we need not | |
7489 | consider that more specific library. */ | |
5bbcd587 JJ |
7490 | ok = used_arg (this_arg, p - this_arg); |
7491 | if (not_arg) | |
7492 | ok = ! ok; | |
7493 | ||
7494 | if (! ok) | |
7495 | ndfltok = 0; | |
7496 | ||
7497 | if (default_arg (this_arg, p - this_arg)) | |
7498 | ok = 1; | |
60103a34 DE |
7499 | |
7500 | if (*p == ' ') | |
7501 | ++p; | |
7502 | } | |
7503 | ||
5bbcd587 | 7504 | if (ok && first) |
60103a34 DE |
7505 | { |
7506 | if (this_path_len != 1 | |
7507 | || this_path[0] != '.') | |
7508 | { | |
5ed6ace5 | 7509 | char *new_multilib_dir = XNEWVEC (char, this_path_len + 1); |
5bbcd587 JJ |
7510 | char *q; |
7511 | ||
878f32c3 KG |
7512 | strncpy (new_multilib_dir, this_path, this_path_len); |
7513 | new_multilib_dir[this_path_len] = '\0'; | |
5bbcd587 JJ |
7514 | q = strchr (new_multilib_dir, ':'); |
7515 | if (q != NULL) | |
7516 | *q = '\0'; | |
878f32c3 | 7517 | multilib_dir = new_multilib_dir; |
60103a34 | 7518 | } |
5bbcd587 JJ |
7519 | first = 0; |
7520 | } | |
7521 | ||
7522 | if (ndfltok) | |
7523 | { | |
7524 | const char *q = this_path, *end = this_path + this_path_len; | |
7525 | ||
7526 | while (q < end && *q != ':') | |
7527 | q++; | |
c49d2df6 | 7528 | if (q < end) |
5bbcd587 | 7529 | { |
5ed6ace5 | 7530 | char *new_multilib_os_dir = XNEWVEC (char, end - q); |
c49d2df6 JJ |
7531 | memcpy (new_multilib_os_dir, q + 1, end - q - 1); |
7532 | new_multilib_os_dir[end - q - 1] = '\0'; | |
5bbcd587 JJ |
7533 | multilib_os_dir = new_multilib_os_dir; |
7534 | break; | |
7535 | } | |
60103a34 DE |
7536 | } |
7537 | ||
7538 | ++p; | |
9218435e | 7539 | } |
5bbcd587 JJ |
7540 | |
7541 | if (multilib_dir == NULL && multilib_os_dir != NULL | |
7542 | && strcmp (multilib_os_dir, ".") == 0) | |
7543 | { | |
b1d5455a | 7544 | free (CONST_CAST (char *, multilib_os_dir)); |
5bbcd587 JJ |
7545 | multilib_os_dir = NULL; |
7546 | } | |
7547 | else if (multilib_dir != NULL && multilib_os_dir == NULL) | |
7548 | multilib_os_dir = multilib_dir; | |
60103a34 DE |
7549 | } |
7550 | ||
7551 | /* Print out the multiple library subdirectory selection | |
7552 | information. This prints out a series of lines. Each line looks | |
7553 | like SUBDIRECTORY;@OPTION@OPTION, with as many options as is | |
7554 | required. Only the desired options are printed out, the negative | |
7555 | matches. The options are print without a leading dash. There are | |
7556 | no spaces to make it easy to use the information in the shell. | |
7557 | Each subdirectory is printed only once. This assumes the ordering | |
0a8d6618 BC |
7558 | generated by the genmultilib script. Also, we leave out ones that match |
7559 | the exclusions. */ | |
60103a34 DE |
7560 | |
7561 | static void | |
1d088dee | 7562 | print_multilib_info (void) |
60103a34 | 7563 | { |
3b304f5b ZW |
7564 | const char *p = multilib_select; |
7565 | const char *last_path = 0, *this_path; | |
03c42484 | 7566 | int skip; |
3ac63d94 | 7567 | unsigned int last_path_len = 0; |
60103a34 DE |
7568 | |
7569 | while (*p != '\0') | |
7570 | { | |
0a8d6618 | 7571 | skip = 0; |
60103a34 DE |
7572 | /* Ignore newlines. */ |
7573 | if (*p == '\n') | |
7574 | { | |
7575 | ++p; | |
7576 | continue; | |
7577 | } | |
7578 | ||
7579 | /* Get the initial path. */ | |
7580 | this_path = p; | |
7581 | while (*p != ' ') | |
7582 | { | |
7583 | if (*p == '\0') | |
3b5edfee NS |
7584 | { |
7585 | invalid_select: | |
bdc6b402 | 7586 | fatal_error ("multilib select %qs is invalid", multilib_select); |
3b5edfee | 7587 | } |
7904f95f | 7588 | |
60103a34 DE |
7589 | ++p; |
7590 | } | |
7591 | ||
c49d2df6 JJ |
7592 | /* When --disable-multilib was used but target defines |
7593 | MULTILIB_OSDIRNAMES, entries starting with .: are there just | |
7594 | to find multilib_os_dir, so skip them from output. */ | |
7595 | if (this_path[0] == '.' && this_path[1] == ':') | |
7596 | skip = 1; | |
7597 | ||
0a8d6618 BC |
7598 | /* Check for matches with the multilib_exclusions. We don't bother |
7599 | with the '!' in either list. If any of the exclusion rules match | |
7600 | all of its options with the select rule, we skip it. */ | |
d25a45d4 KH |
7601 | { |
7602 | const char *e = multilib_exclusions; | |
7603 | const char *this_arg; | |
0a8d6618 | 7604 | |
d25a45d4 KH |
7605 | while (*e != '\0') |
7606 | { | |
7607 | int m = 1; | |
7608 | /* Ignore newlines. */ | |
7609 | if (*e == '\n') | |
7610 | { | |
7611 | ++e; | |
7612 | continue; | |
7613 | } | |
0a8d6618 | 7614 | |
d25a45d4 KH |
7615 | /* Check the arguments. */ |
7616 | while (*e != ';') | |
7617 | { | |
7618 | const char *q; | |
7619 | int mp = 0; | |
0a8d6618 | 7620 | |
d25a45d4 | 7621 | if (*e == '\0') |
3b5edfee NS |
7622 | { |
7623 | invalid_exclusion: | |
bdc6b402 | 7624 | fatal_error ("multilib exclusion %qs is invalid", |
2dec80c7 | 7625 | multilib_exclusions); |
3b5edfee | 7626 | } |
9218435e | 7627 | |
d25a45d4 KH |
7628 | if (! m) |
7629 | { | |
7630 | ++e; | |
7631 | continue; | |
7632 | } | |
0a8d6618 | 7633 | |
d25a45d4 | 7634 | this_arg = e; |
9218435e | 7635 | |
d25a45d4 KH |
7636 | while (*e != ' ' && *e != ';') |
7637 | { | |
7638 | if (*e == '\0') | |
3b5edfee | 7639 | goto invalid_exclusion; |
d25a45d4 KH |
7640 | ++e; |
7641 | } | |
0a8d6618 | 7642 | |
d25a45d4 KH |
7643 | q = p + 1; |
7644 | while (*q != ';') | |
7645 | { | |
7646 | const char *arg; | |
7647 | int len = e - this_arg; | |
0a8d6618 | 7648 | |
d25a45d4 | 7649 | if (*q == '\0') |
3b5edfee | 7650 | goto invalid_select; |
0a8d6618 | 7651 | |
d25a45d4 KH |
7652 | arg = q; |
7653 | ||
7654 | while (*q != ' ' && *q != ';') | |
7655 | { | |
7656 | if (*q == '\0') | |
3b5edfee | 7657 | goto invalid_select; |
0a8d6618 | 7658 | ++q; |
d25a45d4 | 7659 | } |
0a8d6618 | 7660 | |
3b5edfee NS |
7661 | if (! strncmp (arg, this_arg, |
7662 | (len < q - arg) ? q - arg : len) | |
7663 | || default_arg (this_arg, e - this_arg)) | |
d25a45d4 KH |
7664 | { |
7665 | mp = 1; | |
7666 | break; | |
7667 | } | |
0a8d6618 | 7668 | |
d25a45d4 KH |
7669 | if (*q == ' ') |
7670 | ++q; | |
7671 | } | |
9218435e | 7672 | |
d25a45d4 KH |
7673 | if (! mp) |
7674 | m = 0; | |
0a8d6618 | 7675 | |
d25a45d4 KH |
7676 | if (*e == ' ') |
7677 | ++e; | |
7678 | } | |
7679 | ||
7680 | if (m) | |
7681 | { | |
7682 | skip = 1; | |
7683 | break; | |
7684 | } | |
7685 | ||
7686 | if (*e != '\0') | |
7687 | ++e; | |
7688 | } | |
7689 | } | |
0a8d6618 BC |
7690 | |
7691 | if (! skip) | |
d25a45d4 KH |
7692 | { |
7693 | /* If this is a duplicate, skip it. */ | |
3b5edfee NS |
7694 | skip = (last_path != 0 |
7695 | && (unsigned int) (p - this_path) == last_path_len | |
ba78087b | 7696 | && ! filename_ncmp (last_path, this_path, last_path_len)); |
60103a34 | 7697 | |
d25a45d4 KH |
7698 | last_path = this_path; |
7699 | last_path_len = p - this_path; | |
0a8d6618 | 7700 | } |
60103a34 | 7701 | |
03c42484 RK |
7702 | /* If this directory requires any default arguments, we can skip |
7703 | it. We will already have printed a directory identical to | |
7704 | this one which does not require that default argument. */ | |
7705 | if (! skip) | |
7706 | { | |
3b304f5b | 7707 | const char *q; |
03c42484 RK |
7708 | |
7709 | q = p + 1; | |
7710 | while (*q != ';') | |
7711 | { | |
3b304f5b | 7712 | const char *arg; |
03c42484 RK |
7713 | |
7714 | if (*q == '\0') | |
3b5edfee | 7715 | goto invalid_select; |
03c42484 RK |
7716 | |
7717 | if (*q == '!') | |
7718 | arg = NULL; | |
7719 | else | |
7720 | arg = q; | |
7721 | ||
7722 | while (*q != ' ' && *q != ';') | |
7723 | { | |
7724 | if (*q == '\0') | |
3b5edfee | 7725 | goto invalid_select; |
03c42484 RK |
7726 | ++q; |
7727 | } | |
7728 | ||
7729 | if (arg != NULL | |
7730 | && default_arg (arg, q - arg)) | |
7731 | { | |
7732 | skip = 1; | |
7733 | break; | |
7734 | } | |
7735 | ||
7736 | if (*q == ' ') | |
7737 | ++q; | |
7738 | } | |
7739 | } | |
7740 | ||
60103a34 DE |
7741 | if (! skip) |
7742 | { | |
3b304f5b | 7743 | const char *p1; |
60103a34 | 7744 | |
5bbcd587 | 7745 | for (p1 = last_path; p1 < p && *p1 != ':'; p1++) |
60103a34 DE |
7746 | putchar (*p1); |
7747 | putchar (';'); | |
7748 | } | |
7749 | ||
7750 | ++p; | |
7751 | while (*p != ';') | |
7752 | { | |
7753 | int use_arg; | |
7754 | ||
7755 | if (*p == '\0') | |
3b5edfee | 7756 | goto invalid_select; |
60103a34 DE |
7757 | |
7758 | if (skip) | |
7759 | { | |
7760 | ++p; | |
7761 | continue; | |
7762 | } | |
7763 | ||
7764 | use_arg = *p != '!'; | |
7765 | ||
7766 | if (use_arg) | |
7767 | putchar ('@'); | |
7768 | ||
7769 | while (*p != ' ' && *p != ';') | |
7770 | { | |
7771 | if (*p == '\0') | |
3b5edfee | 7772 | goto invalid_select; |
60103a34 DE |
7773 | if (use_arg) |
7774 | putchar (*p); | |
7775 | ++p; | |
7776 | } | |
7777 | ||
7778 | if (*p == ' ') | |
7779 | ++p; | |
7780 | } | |
7781 | ||
7782 | if (! skip) | |
961b7009 | 7783 | { |
3ac63d94 | 7784 | /* If there are extra options, print them now. */ |
961b7009 MM |
7785 | if (multilib_extra && *multilib_extra) |
7786 | { | |
7787 | int print_at = TRUE; | |
3b304f5b | 7788 | const char *q; |
961b7009 MM |
7789 | |
7790 | for (q = multilib_extra; *q != '\0'; q++) | |
7791 | { | |
7792 | if (*q == ' ') | |
7793 | print_at = TRUE; | |
7794 | else | |
7795 | { | |
7796 | if (print_at) | |
7797 | putchar ('@'); | |
7798 | putchar (*q); | |
7799 | print_at = FALSE; | |
7800 | } | |
7801 | } | |
7802 | } | |
9218435e | 7803 | |
961b7009 MM |
7804 | putchar ('\n'); |
7805 | } | |
60103a34 DE |
7806 | |
7807 | ++p; | |
7808 | } | |
7809 | } | |
f3226a90 | 7810 | \f |
30d8946b MM |
7811 | /* getenv built-in spec function. |
7812 | ||
7813 | Returns the value of the environment variable given by its first | |
7814 | argument, concatenated with the second argument. If the | |
7815 | environment variable is not defined, a fatal error is issued. */ | |
7816 | ||
7817 | static const char * | |
7818 | getenv_spec_function (int argc, const char **argv) | |
7819 | { | |
7820 | char *value; | |
5557813a NS |
7821 | char *result; |
7822 | char *ptr; | |
7823 | size_t len; | |
30d8946b MM |
7824 | |
7825 | if (argc != 2) | |
7826 | return NULL; | |
7827 | ||
7828 | value = getenv (argv[0]); | |
7829 | if (!value) | |
bdc6b402 | 7830 | fatal_error ("environment variable %qs not defined", argv[0]); |
30d8946b | 7831 | |
5557813a | 7832 | /* We have to escape every character of the environment variable so |
fa10beec RW |
7833 | they are not interpreted as active spec characters. A |
7834 | particularly painful case is when we are reading a variable | |
5557813a NS |
7835 | holding a windows path complete with \ separators. */ |
7836 | len = strlen (value) * 2 + strlen (argv[1]) + 1; | |
e1e4cdc4 | 7837 | result = XNEWVAR (char, len); |
5557813a NS |
7838 | for (ptr = result; *value; ptr += 2) |
7839 | { | |
7840 | ptr[0] = '\\'; | |
7841 | ptr[1] = *value++; | |
7842 | } | |
b8698a0f | 7843 | |
5557813a | 7844 | strcpy (ptr, argv[1]); |
b8698a0f | 7845 | |
5557813a | 7846 | return result; |
30d8946b MM |
7847 | } |
7848 | ||
f3226a90 JT |
7849 | /* if-exists built-in spec function. |
7850 | ||
7851 | Checks to see if the file specified by the absolute pathname in | |
7852 | ARGS exists. Returns that pathname if found. | |
7853 | ||
7854 | The usual use for this function is to check for a library file | |
7855 | (whose name has been expanded with %s). */ | |
7856 | ||
7857 | static const char * | |
1d088dee | 7858 | if_exists_spec_function (int argc, const char **argv) |
f3226a90 JT |
7859 | { |
7860 | /* Must have only one argument. */ | |
3dce1408 | 7861 | if (argc == 1 && IS_ABSOLUTE_PATH (argv[0]) && ! access (argv[0], R_OK)) |
f3226a90 JT |
7862 | return argv[0]; |
7863 | ||
7864 | return NULL; | |
7865 | } | |
152a5a9c JT |
7866 | |
7867 | /* if-exists-else built-in spec function. | |
7868 | ||
7869 | This is like if-exists, but takes an additional argument which | |
7870 | is returned if the first argument does not exist. */ | |
7871 | ||
7872 | static const char * | |
1d088dee | 7873 | if_exists_else_spec_function (int argc, const char **argv) |
152a5a9c JT |
7874 | { |
7875 | /* Must have exactly two arguments. */ | |
7876 | if (argc != 2) | |
7877 | return NULL; | |
7878 | ||
3dce1408 | 7879 | if (IS_ABSOLUTE_PATH (argv[0]) && ! access (argv[0], R_OK)) |
152a5a9c JT |
7880 | return argv[0]; |
7881 | ||
7882 | return argv[1]; | |
7883 | } | |
3dd53121 AP |
7884 | |
7885 | /* replace-outfile built-in spec function. | |
ed5b9f96 GK |
7886 | |
7887 | This looks for the first argument in the outfiles array's name and | |
7888 | replaces it with the second argument. */ | |
3dd53121 AP |
7889 | |
7890 | static const char * | |
7891 | replace_outfile_spec_function (int argc, const char **argv) | |
7892 | { | |
7893 | int i; | |
7894 | /* Must have exactly two arguments. */ | |
7895 | if (argc != 2) | |
7896 | abort (); | |
7904f95f | 7897 | |
3dd53121 AP |
7898 | for (i = 0; i < n_infiles; i++) |
7899 | { | |
ba78087b | 7900 | if (outfiles[i] && !filename_cmp (outfiles[i], argv[0])) |
3dd53121 AP |
7901 | outfiles[i] = xstrdup (argv[1]); |
7902 | } | |
7903 | return NULL; | |
7904 | } | |
7905 | ||
2642f659 JH |
7906 | /* remove-outfile built-in spec function. |
7907 | * | |
7908 | * This looks for the first argument in the outfiles array's name and | |
7909 | * removes it. */ | |
7910 | ||
7911 | static const char * | |
7912 | remove_outfile_spec_function (int argc, const char **argv) | |
7913 | { | |
7914 | int i; | |
7915 | /* Must have exactly one argument. */ | |
7916 | if (argc != 1) | |
7917 | abort (); | |
7918 | ||
7919 | for (i = 0; i < n_infiles; i++) | |
7920 | { | |
ba78087b | 7921 | if (outfiles[i] && !filename_cmp (outfiles[i], argv[0])) |
2642f659 JH |
7922 | outfiles[i] = NULL; |
7923 | } | |
7924 | return NULL; | |
7925 | } | |
7926 | ||
7904f95f | 7927 | /* Given two version numbers, compares the two numbers. |
ed5b9f96 GK |
7928 | A version number must match the regular expression |
7929 | ([1-9][0-9]*|0)(\.([1-9][0-9]*|0))* | |
7930 | */ | |
7931 | static int | |
7932 | compare_version_strings (const char *v1, const char *v2) | |
7933 | { | |
7934 | int rresult; | |
7935 | regex_t r; | |
7904f95f | 7936 | |
ed5b9f96 GK |
7937 | if (regcomp (&r, "^([1-9][0-9]*|0)(\\.([1-9][0-9]*|0))*$", |
7938 | REG_EXTENDED | REG_NOSUB) != 0) | |
7939 | abort (); | |
7940 | rresult = regexec (&r, v1, 0, NULL, 0); | |
7941 | if (rresult == REG_NOMATCH) | |
bdc6b402 | 7942 | fatal_error ("invalid version number %qs", v1); |
ed5b9f96 GK |
7943 | else if (rresult != 0) |
7944 | abort (); | |
7945 | rresult = regexec (&r, v2, 0, NULL, 0); | |
7946 | if (rresult == REG_NOMATCH) | |
bdc6b402 | 7947 | fatal_error ("invalid version number %qs", v2); |
ed5b9f96 GK |
7948 | else if (rresult != 0) |
7949 | abort (); | |
7950 | ||
7951 | return strverscmp (v1, v2); | |
7952 | } | |
7953 | ||
7954 | ||
7955 | /* version_compare built-in spec function. | |
7956 | ||
7957 | This takes an argument of the following form: | |
7958 | ||
7959 | <comparison-op> <arg1> [<arg2>] <switch> <result> | |
7960 | ||
7961 | and produces "result" if the comparison evaluates to true, | |
7962 | and nothing if it doesn't. | |
7963 | ||
7964 | The supported <comparison-op> values are: | |
7904f95f | 7965 | |
ed5b9f96 GK |
7966 | >= true if switch is a later (or same) version than arg1 |
7967 | !> opposite of >= | |
7968 | < true if switch is an earlier version than arg1 | |
7969 | !< opposite of < | |
7970 | >< true if switch is arg1 or later, and earlier than arg2 | |
7971 | <> true if switch is earlier than arg1 or is arg2 or later | |
7972 | ||
7973 | If the switch is not present, the condition is false unless | |
7974 | the first character of the <comparison-op> is '!'. | |
7975 | ||
7976 | For example, | |
7977 | %:version-compare(>= 10.3 mmacosx-version-min= -lmx) | |
7978 | adds -lmx if -mmacosx-version-min=10.3.9 was passed. */ | |
7979 | ||
7980 | static const char * | |
7981 | version_compare_spec_function (int argc, const char **argv) | |
7982 | { | |
7983 | int comp1, comp2; | |
7984 | size_t switch_len; | |
7985 | const char *switch_value = NULL; | |
7986 | int nargs = 1, i; | |
7987 | bool result; | |
7988 | ||
7989 | if (argc < 3) | |
2dec80c7 | 7990 | fatal_error ("too few arguments to %%:version-compare"); |
ed5b9f96 GK |
7991 | if (argv[0][0] == '\0') |
7992 | abort (); | |
7993 | if ((argv[0][1] == '<' || argv[0][1] == '>') && argv[0][0] != '!') | |
7994 | nargs = 2; | |
7995 | if (argc != nargs + 3) | |
2dec80c7 | 7996 | fatal_error ("too many arguments to %%:version-compare"); |
ed5b9f96 GK |
7997 | |
7998 | switch_len = strlen (argv[nargs + 1]); | |
7999 | for (i = 0; i < n_switches; i++) | |
8000 | if (!strncmp (switches[i].part1, argv[nargs + 1], switch_len) | |
8001 | && check_live_switch (i, switch_len)) | |
8002 | switch_value = switches[i].part1 + switch_len; | |
8003 | ||
8004 | if (switch_value == NULL) | |
8005 | comp1 = comp2 = -1; | |
8006 | else | |
8007 | { | |
8008 | comp1 = compare_version_strings (switch_value, argv[1]); | |
8009 | if (nargs == 2) | |
8010 | comp2 = compare_version_strings (switch_value, argv[2]); | |
8011 | else | |
8012 | comp2 = -1; /* This value unused. */ | |
8013 | } | |
8014 | ||
8015 | switch (argv[0][0] << 8 | argv[0][1]) | |
8016 | { | |
8017 | case '>' << 8 | '=': | |
8018 | result = comp1 >= 0; | |
8019 | break; | |
8020 | case '!' << 8 | '<': | |
8021 | result = comp1 >= 0 || switch_value == NULL; | |
8022 | break; | |
8023 | case '<' << 8: | |
8024 | result = comp1 < 0; | |
8025 | break; | |
8026 | case '!' << 8 | '>': | |
8027 | result = comp1 < 0 || switch_value == NULL; | |
8028 | break; | |
8029 | case '>' << 8 | '<': | |
8030 | result = comp1 >= 0 && comp2 < 0; | |
8031 | break; | |
8032 | case '<' << 8 | '>': | |
8033 | result = comp1 < 0 || comp2 >= 0; | |
8034 | break; | |
7904f95f | 8035 | |
ed5b9f96 | 8036 | default: |
bdc6b402 | 8037 | fatal_error ("unknown operator %qs in %%:version-compare", argv[0]); |
ed5b9f96 GK |
8038 | } |
8039 | if (! result) | |
8040 | return NULL; | |
8041 | ||
8042 | return argv[nargs + 2]; | |
8043 | } | |
953ff289 DN |
8044 | |
8045 | /* %:include builtin spec function. This differs from %include in that it | |
8046 | can be nested inside a spec, and thus be conditionalized. It takes | |
8047 | one argument, the filename, and looks for it in the startfile path. | |
8048 | The result is always NULL, i.e. an empty expansion. */ | |
8049 | ||
8050 | static const char * | |
8051 | include_spec_function (int argc, const char **argv) | |
8052 | { | |
8053 | char *file; | |
8054 | ||
8055 | if (argc != 1) | |
8056 | abort (); | |
8057 | ||
4d2b059d | 8058 | file = find_a_file (&startfile_prefixes, argv[0], R_OK, true); |
953ff289 DN |
8059 | read_specs (file ? file : argv[0], FALSE); |
8060 | ||
8061 | return NULL; | |
8062 | } | |
a0f87454 | 8063 | |
c1ce46a5 | 8064 | /* %:find-file spec function. This function replaces its argument by |
4adbd5dd MK |
8065 | the file found thru find_file, that is the -print-file-name gcc |
8066 | program option. */ | |
8067 | static const char * | |
c1ce46a5 | 8068 | find_file_spec_function (int argc, const char **argv) |
4adbd5dd MK |
8069 | { |
8070 | const char *file; | |
8071 | ||
8072 | if (argc != 1) | |
8073 | abort (); | |
8074 | ||
8075 | file = find_file (argv[0]); | |
8076 | return file; | |
8077 | } | |
8078 | ||
8079 | ||
c1ce46a5 MK |
8080 | /* %:find-plugindir spec function. This function replaces its argument |
8081 | by the -iplugindir=<dir> option. `dir' is found thru find_file, that | |
8082 | is the -print-file-name gcc program option. */ | |
8083 | static const char * | |
8084 | find_plugindir_spec_function (int argc, const char **argv ATTRIBUTE_UNUSED) | |
8085 | { | |
8086 | const char *option; | |
8087 | ||
8088 | if (argc != 0) | |
8089 | abort (); | |
8090 | ||
8091 | option = concat ("-iplugindir=", find_file ("plugin"), NULL); | |
8092 | return option; | |
8093 | } | |
8094 | ||
8095 | ||
a0f87454 RS |
8096 | /* %:print-asm-header spec function. Print a banner to say that the |
8097 | following output is from the assembler. */ | |
8098 | ||
8099 | static const char * | |
8100 | print_asm_header_spec_function (int arg ATTRIBUTE_UNUSED, | |
8101 | const char **argv ATTRIBUTE_UNUSED) | |
8102 | { | |
4dad0aca | 8103 | printf (_("Assembler options\n=================\n\n")); |
a0f87454 RS |
8104 | printf (_("Use \"-Wa,OPTION\" to pass \"OPTION\" to the assembler.\n\n")); |
8105 | fflush (stdout); | |
8106 | return NULL; | |
8107 | } | |
2153915d | 8108 | |
44a22bdb | 8109 | /* Get a random number for -frandom-seed */ |
b5b8b0ac | 8110 | |
44a22bdb AK |
8111 | static unsigned HOST_WIDE_INT |
8112 | get_random_number (void) | |
b5b8b0ac | 8113 | { |
44a22bdb AK |
8114 | unsigned HOST_WIDE_INT ret = 0; |
8115 | int fd; | |
8116 | ||
8117 | fd = open ("/dev/urandom", O_RDONLY); | |
8118 | if (fd >= 0) | |
8119 | { | |
8120 | read (fd, &ret, sizeof (HOST_WIDE_INT)); | |
8121 | close (fd); | |
8122 | if (ret) | |
8123 | return ret; | |
8124 | } | |
b5b8b0ac AO |
8125 | |
8126 | /* Get some more or less random data. */ | |
8127 | #ifdef HAVE_GETTIMEOFDAY | |
8128 | { | |
8129 | struct timeval tv; | |
8130 | ||
8131 | gettimeofday (&tv, NULL); | |
8132 | ret = tv.tv_sec * 1000 + tv.tv_usec / 1000; | |
8133 | } | |
8134 | #else | |
8135 | { | |
8136 | time_t now = time (NULL); | |
8137 | ||
8138 | if (now != (time_t)-1) | |
8139 | ret = (unsigned) now; | |
8140 | } | |
8141 | #endif | |
8142 | ||
44a22bdb | 8143 | return ret ^ getpid(); |
b5b8b0ac AO |
8144 | } |
8145 | ||
2153915d AO |
8146 | /* %:compare-debug-dump-opt spec function. Save the last argument, |
8147 | expected to be the last -fdump-final-insns option, or generate a | |
8148 | temporary. */ | |
8149 | ||
8150 | static const char * | |
8151 | compare_debug_dump_opt_spec_function (int arg, | |
8152 | const char **argv ATTRIBUTE_UNUSED) | |
8153 | { | |
8154 | const char *ret; | |
8155 | char *name; | |
8156 | int which; | |
b5b8b0ac | 8157 | static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3]; |
2153915d AO |
8158 | |
8159 | if (arg != 0) | |
2dec80c7 | 8160 | fatal_error ("too many arguments to %%:compare-debug-dump-opt"); |
2153915d | 8161 | |
2153915d AO |
8162 | do_spec_2 ("%{fdump-final-insns=*:%*}"); |
8163 | do_spec_1 (" ", 0, NULL); | |
8164 | ||
5b634ee0 JM |
8165 | if (VEC_length (const_char_p, argbuf) > 0 |
8166 | && strcmp (argv[VEC_length (const_char_p, argbuf) - 1], ".")) | |
2153915d | 8167 | { |
b5b8b0ac AO |
8168 | if (!compare_debug) |
8169 | return NULL; | |
8170 | ||
5b634ee0 | 8171 | name = xstrdup (argv[VEC_length (const_char_p, argbuf) - 1]); |
2153915d AO |
8172 | ret = NULL; |
8173 | } | |
8174 | else | |
8175 | { | |
b5b8b0ac AO |
8176 | const char *ext = NULL; |
8177 | ||
5b634ee0 | 8178 | if (VEC_length (const_char_p, argbuf) > 0) |
b5b8b0ac AO |
8179 | { |
8180 | do_spec_2 ("%{o*:%*}%{!o:%{!S:%b%O}%{S:%b.s}}"); | |
8181 | ext = ".gkd"; | |
8182 | } | |
8183 | else if (!compare_debug) | |
8184 | return NULL; | |
8185 | else | |
8186 | do_spec_2 ("%g.gkd"); | |
2153915d | 8187 | |
2153915d | 8188 | do_spec_1 (" ", 0, NULL); |
2153915d | 8189 | |
5b634ee0 | 8190 | gcc_assert (VEC_length (const_char_p, argbuf) > 0); |
2153915d | 8191 | |
5b634ee0 | 8192 | name = concat (VEC_last (const_char_p, argbuf), ext, NULL); |
b5b8b0ac AO |
8193 | |
8194 | ret = concat ("-fdump-final-insns=", name, NULL); | |
2153915d AO |
8195 | } |
8196 | ||
8197 | which = compare_debug < 0; | |
8198 | debug_check_temp_file[which] = name; | |
8199 | ||
b5b8b0ac AO |
8200 | if (!which) |
8201 | { | |
44a22bdb | 8202 | unsigned HOST_WIDE_INT value = get_random_number (); |
b5b8b0ac AO |
8203 | |
8204 | sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value); | |
8205 | } | |
8206 | ||
8207 | if (*random_seed) | |
8208 | ret = concat ("%{!frandom-seed=*:-frandom-seed=", random_seed, "} ", | |
8209 | ret, NULL); | |
8210 | ||
8211 | if (which) | |
8212 | *random_seed = 0; | |
2153915d AO |
8213 | |
8214 | return ret; | |
8215 | } | |
8216 | ||
8217 | static const char *debug_auxbase_opt; | |
8218 | ||
8219 | /* %:compare-debug-self-opt spec function. Expands to the options | |
8220 | that are to be passed in the second compilation of | |
8221 | compare-debug. */ | |
8222 | ||
8223 | static const char * | |
8224 | compare_debug_self_opt_spec_function (int arg, | |
8225 | const char **argv ATTRIBUTE_UNUSED) | |
8226 | { | |
8227 | if (arg != 0) | |
2dec80c7 | 8228 | fatal_error ("too many arguments to %%:compare-debug-self-opt"); |
2153915d AO |
8229 | |
8230 | if (compare_debug >= 0) | |
8231 | return NULL; | |
8232 | ||
8233 | do_spec_2 ("%{c|S:%{o*:%*}}"); | |
8234 | do_spec_1 (" ", 0, NULL); | |
8235 | ||
5b634ee0 | 8236 | if (VEC_length (const_char_p, argbuf) > 0) |
2153915d | 8237 | debug_auxbase_opt = concat ("-auxbase-strip ", |
5b634ee0 | 8238 | VEC_last (const_char_p, argbuf), |
2153915d AO |
8239 | NULL); |
8240 | else | |
8241 | debug_auxbase_opt = NULL; | |
8242 | ||
8243 | return concat ("\ | |
8244 | %<o %<MD %<MMD %<MF* %<MG %<MP %<MQ* %<MT* \ | |
8245 | %<fdump-final-insns=* -w -S -o %j \ | |
8246 | %{!fcompare-debug-second:-fcompare-debug-second} \ | |
8247 | ", compare_debug_opt, NULL); | |
8248 | } | |
8249 | ||
8250 | /* %:compare-debug-auxbase-opt spec function. Expands to the auxbase | |
8251 | options that are to be passed in the second compilation of | |
8252 | compare-debug. It expects, as an argument, the basename of the | |
8253 | current input file name, with the .gk suffix appended to it. */ | |
8254 | ||
8255 | static const char * | |
8256 | compare_debug_auxbase_opt_spec_function (int arg, | |
8257 | const char **argv) | |
8258 | { | |
8259 | char *name; | |
8260 | int len; | |
8261 | ||
8262 | if (arg == 0) | |
2dec80c7 | 8263 | fatal_error ("too few arguments to %%:compare-debug-auxbase-opt"); |
2153915d AO |
8264 | |
8265 | if (arg != 1) | |
2dec80c7 | 8266 | fatal_error ("too many arguments to %%:compare-debug-auxbase-opt"); |
2153915d AO |
8267 | |
8268 | if (compare_debug >= 0) | |
8269 | return NULL; | |
8270 | ||
8271 | len = strlen (argv[0]); | |
8272 | if (len < 3 || strcmp (argv[0] + len - 3, ".gk") != 0) | |
2dec80c7 JM |
8273 | fatal_error ("argument to %%:compare-debug-auxbase-opt " |
8274 | "does not end in .gk"); | |
2153915d AO |
8275 | |
8276 | if (debug_auxbase_opt) | |
8277 | return debug_auxbase_opt; | |
8278 | ||
8279 | #define OPT "-auxbase " | |
8280 | ||
8281 | len -= 3; | |
8282 | name = (char*) xmalloc (sizeof (OPT) + len); | |
8283 | memcpy (name, OPT, sizeof (OPT) - 1); | |
8284 | memcpy (name + sizeof (OPT) - 1, argv[0], len); | |
8285 | name[sizeof (OPT) - 1 + len] = '\0'; | |
8286 | ||
b5b8b0ac AO |
8287 | #undef OPT |
8288 | ||
2153915d AO |
8289 | return name; |
8290 | } | |
9a37bc07 DK |
8291 | |
8292 | /* %:pass-through-libs spec function. Finds all -l options and input | |
8293 | file names in the lib spec passed to it, and makes a list of them | |
8294 | prepended with the plugin option to cause them to be passed through | |
8295 | to the final link after all the new object files have been added. */ | |
8296 | ||
8297 | const char * | |
8298 | pass_through_libs_spec_func (int argc, const char **argv) | |
8299 | { | |
8300 | char *prepended = xstrdup (" "); | |
8301 | int n; | |
8302 | /* Shlemiel the painter's algorithm. Innately horrible, but at least | |
8303 | we know that there will never be more than a handful of strings to | |
8304 | concat, and it's only once per run, so it's not worth optimising. */ | |
8305 | for (n = 0; n < argc; n++) | |
8306 | { | |
8307 | char *old = prepended; | |
8308 | /* Anything that isn't an option is a full path to an output | |
8309 | file; pass it through if it ends in '.a'. Among options, | |
8310 | pass only -l. */ | |
8311 | if (argv[n][0] == '-' && argv[n][1] == 'l') | |
8312 | { | |
8313 | const char *lopt = argv[n] + 2; | |
8314 | /* Handle both joined and non-joined -l options. If for any | |
8315 | reason there's a trailing -l with no joined or following | |
8316 | arg just discard it. */ | |
8317 | if (!*lopt && ++n >= argc) | |
8318 | break; | |
8319 | else if (!*lopt) | |
8320 | lopt = argv[n]; | |
8321 | prepended = concat (prepended, "-plugin-opt=-pass-through=-l", | |
8322 | lopt, " ", NULL); | |
8323 | } | |
8324 | else if (!strcmp (".a", argv[n] + strlen (argv[n]) - 2)) | |
8325 | { | |
8326 | prepended = concat (prepended, "-plugin-opt=-pass-through=", | |
8327 | argv[n], " ", NULL); | |
8328 | } | |
8329 | if (prepended != old) | |
8330 | free (old); | |
8331 | } | |
8332 | return prepended; | |
8333 | } |