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