1 | /* Compiler driver program that can handle many languages. |
2 | Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, |
3 | 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, |
4 | Inc. |
5 | |
6 | This file is part of GCC. |
7 | |
8 | GCC is free software; you can redistribute it and/or modify it under |
9 | the terms of the GNU General Public License as published by the Free |
10 | Software Foundation; either version 2, or (at your option) any later |
11 | version. |
12 | |
13 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
14 | WARRANTY; without even the implied warranty of MERCHANTABILITY or |
15 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
16 | for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with GCC; see the file COPYING. If not, write to the Free |
20 | Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA |
21 | 02110-1301, USA. |
22 | |
23 | This paragraph is here to try to keep Sun CC from dying. |
24 | The number of chars here seems crucial!!!! */ |
25 | |
26 | /* This program is the user interface to the C compiler and possibly to |
27 | other compilers. It is used because compilation is a complicated procedure |
28 | which involves running several programs and passing temporary files between |
29 | them, forwarding the users switches to those programs selectively, |
30 | and deleting the temporary files at the end. |
31 | |
32 | CC recognizes how to compile each input file by suffixes in the file names. |
33 | Once it knows which kind of compilation to perform, the procedure for |
34 | compilation is specified by a string called a "spec". */ |
35 | |
36 | /* A Short Introduction to Adding a Command-Line Option. |
37 | |
38 | Before adding a command-line option, consider if it is really |
39 | necessary. Each additional command-line option adds complexity and |
40 | is difficult to remove in subsequent versions. |
41 | |
42 | In the following, consider adding the command-line argument |
43 | `--bar'. |
44 | |
45 | 1. Each command-line option is specified in the specs file. The |
46 | notation is described below in the comment entitled "The Specs |
47 | Language". Read it. |
48 | |
49 | 2. In this file, add an entry to "option_map" equating the long |
50 | `--' argument version and any shorter, single letter version. Read |
51 | the comments in the declaration of "struct option_map" for an |
52 | explanation. Do not omit the first `-'. |
53 | |
54 | 3. Look in the "specs" file to determine which program or option |
55 | list should be given the argument, e.g., "cc1_options". Add the |
56 | appropriate syntax for the shorter option version to the |
57 | corresponding "const char *" entry in this file. Omit the first |
58 | `-' from the option. For example, use `-bar', rather than `--bar'. |
59 | |
60 | 4. If the argument takes an argument, e.g., `--baz argument1', |
61 | modify either DEFAULT_SWITCH_TAKES_ARG or |
62 | DEFAULT_WORD_SWITCH_TAKES_ARG in gcc.h. Omit the first `-' |
63 | from `--baz'. |
64 | |
65 | 5. Document the option in this file's display_help(). If the |
66 | option is passed to a subprogram, modify its corresponding |
67 | function, e.g., cppinit.c:print_help() or toplev.c:display_help(), |
68 | instead. |
69 | |
70 | 6. Compile and test. Make sure that your new specs file is being |
71 | read. For example, use a debugger to investigate the value of |
72 | "specs_file" in main(). */ |
73 | |
74 | #include "config.h" |
75 | #include "system.h" |
76 | #include "coretypes.h" |
77 | #include "multilib.h" /* before tm.h */ |
78 | #include "tm.h" |
79 | #include <signal.h> |
80 | #if ! defined( SIGCHLD ) && defined( SIGCLD ) |
81 | # define SIGCHLD SIGCLD |
82 | #endif |
83 | #include "xregex.h" |
84 | #include "obstack.h" |
85 | #include "intl.h" |
86 | #include "prefix.h" |
87 | #include "gcc.h" |
88 | #include "flags.h" |
89 | #include "opts.h" |
90 | |
91 | /* By default there is no special suffix for target executables. */ |
92 | /* FIXME: when autoconf is fixed, remove the host check - dj */ |
93 | #if defined(TARGET_EXECUTABLE_SUFFIX) && defined(HOST_EXECUTABLE_SUFFIX) |
94 | #define HAVE_TARGET_EXECUTABLE_SUFFIX |
95 | #endif |
96 | |
97 | /* By default there is no special suffix for host executables. */ |
98 | #ifdef HOST_EXECUTABLE_SUFFIX |
99 | #define HAVE_HOST_EXECUTABLE_SUFFIX |
100 | #else |
101 | #define HOST_EXECUTABLE_SUFFIX "" |
102 | #endif |
103 | |
104 | /* By default, the suffix for target object files is ".o". */ |
105 | #ifdef TARGET_OBJECT_SUFFIX |
106 | #define HAVE_TARGET_OBJECT_SUFFIX |
107 | #else |
108 | #define TARGET_OBJECT_SUFFIX ".o" |
109 | #endif |
110 | |
111 | static const char dir_separator_str[] = { DIR_SEPARATOR'/', 0 }; |
112 | |
113 | /* Most every one is fine with LIBRARY_PATH. For some, it conflicts. */ |
114 | #ifndef LIBRARY_PATH_ENV |
115 | #define LIBRARY_PATH_ENV "LIBRARY_PATH" |
116 | #endif |
117 | |
118 | #ifndef HAVE_KILL |
119 | #define kill(p,s) raise(s) |
120 | #endif |
121 | |
122 | /* If a stage of compilation returns an exit status >= 1, |
123 | compilation of that file ceases. */ |
124 | |
125 | #define MIN_FATAL_STATUS 1 |
126 | |
127 | /* Flag set by cppspec.c to 1. */ |
128 | int is_cpp_driver; |
129 | |
130 | /* Flag saying to pass the greatest exit code returned by a sub-process |
131 | to the calling program. */ |
132 | static int pass_exit_codes; |
133 | |
134 | /* Definition of string containing the arguments given to configure. */ |
135 | #include "configargs.h" |
136 | |
137 | /* Flag saying to print the directories gcc will search through looking for |
138 | programs, libraries, etc. */ |
139 | |
140 | static int print_search_dirs; |
141 | |
142 | /* Flag saying to print the full filename of this file |
143 | as found through our usual search mechanism. */ |
144 | |
145 | static const char *print_file_name = NULL( ( void * ) 0 ); |
146 | |
147 | /* As print_file_name, but search for executable file. */ |
148 | |
149 | static const char *print_prog_name = NULL( ( void * ) 0 ); |
150 | |
151 | /* Flag saying to print the relative path we'd use to |
152 | find libgcc.a given the current compiler flags. */ |
153 | |
154 | static int print_multi_directory; |
155 | |
156 | /* Flag saying to print the relative path we'd use to |
157 | find OS libraries given the current compiler flags. */ |
158 | |
159 | static int print_multi_os_directory; |
160 | |
161 | /* Flag saying to print the list of subdirectories and |
162 | compiler flags used to select them in a standard form. */ |
163 | |
164 | static int print_multi_lib; |
165 | |
166 | /* Flag saying to print the command line options understood by gcc and its |
167 | sub-processes. */ |
168 | |
169 | static int print_help_list; |
170 | |
171 | /* Flag indicating whether we should print the command and arguments */ |
172 | |
173 | static int verbose_flag; |
174 | |
175 | /* Flag indicating whether we should ONLY print the command and |
176 | arguments (like verbose_flag) without executing the command. |
177 | Displayed arguments are quoted so that the generated command |
178 | line is suitable for execution. This is intended for use in |
179 | shell scripts to capture the driver-generated command line. */ |
180 | static int verbose_only_flag; |
181 | |
182 | /* Flag indicating to print target specific command line options. */ |
183 | |
184 | static int target_help_flag; |
185 | |
186 | /* Flag indicating whether we should report subprocess execution times |
187 | (if this is supported by the system - see pexecute.c). */ |
188 | |
189 | static int report_times; |
190 | |
191 | /* Nonzero means place this string before uses of /, so that include |
192 | and library files can be found in an alternate location. */ |
193 | |
194 | #ifdef TARGET_SYSTEM_ROOT |
195 | static const char *target_system_root = TARGET_SYSTEM_ROOT; |
196 | #else |
197 | static const char *target_system_root = 0; |
198 | #endif |
199 | |
200 | /* Nonzero means pass the updated target_system_root to the compiler. */ |
201 | |
202 | static int target_system_root_changed; |
203 | |
204 | /* Nonzero means append this string to target_system_root. */ |
205 | |
206 | static const char *target_sysroot_suffix = 0; |
207 | |
208 | /* Nonzero means append this string to target_system_root for headers. */ |
209 | |
210 | static const char *target_sysroot_hdrs_suffix = 0; |
211 | |
212 | /* Nonzero means write "temp" files in source directory |
213 | and use the source file's name in them, and don't delete them. */ |
214 | |
215 | static int save_temps_flag; |
216 | |
217 | /* Nonzero means pass multiple source files to the compiler at one time. */ |
218 | |
219 | static int combine_flag = 0; |
220 | |
221 | /* Nonzero means use pipes to communicate between subprocesses. |
222 | Overridden by either of the above two flags. */ |
223 | |
224 | static int use_pipes; |
225 | |
226 | /* The compiler version. */ |
227 | |
228 | static const char *compiler_version; |
229 | |
230 | /* The target version specified with -V */ |
231 | |
232 | static const char *const spec_version = DEFAULT_TARGET_VERSION"4.2.1"; |
233 | |
234 | /* The target machine specified with -b. */ |
235 | |
236 | static const char *spec_machine = DEFAULT_TARGET_MACHINE"i686-apple-darwin8"; |
237 | |
238 | /* APPLE LOCAL begin CC_PRINT_OPTIONS (radar 3313335) */ |
239 | static char *cc_print_options = 0; |
240 | static char *cc_print_options_filename; |
241 | /* APPLE LOCAL end CC_PRINT_OPTIONS */ |
242 | |
243 | /* Nonzero if cross-compiling. |
244 | When -b is used, the value comes from the `specs' file. */ |
245 | |
246 | /* APPLE LOCAL begin mainline 4.3 2006-12-13 CROSS_DIRECTORY_STRUCTURE 4697325 */ |
247 | #ifdef CROSS_DIRECTORY_STRUCTURE |
248 | /* APPLE LOCAL end mainline 4.3 2006-12-13 CROSS_DIRECTORY_STRUCTURE 4697325 */ |
249 | static const char *cross_compile = "1"; |
250 | #else |
251 | static const char *cross_compile = "0"; |
252 | #endif |
253 | |
254 | #ifdef MODIFY_TARGET_NAME |
255 | |
256 | /* Information on how to alter the target name based on a command-line |
257 | switch. The only case we support now is simply appending or deleting a |
258 | string to or from the end of the first part of the configuration name. */ |
259 | |
260 | static const struct modify_target |
261 | { |
262 | const char *const sw; |
263 | const enum add_del {ADD, DELETE} add_del; |
264 | const char *const str; |
265 | } |
266 | modify_target[] = MODIFY_TARGET_NAME; |
267 | #endif |
268 | |
269 | /* The number of errors that have occurred; the link phase will not be |
270 | run if this is nonzero. */ |
271 | static int error_count = 0; |
272 | |
273 | /* Greatest exit code of sub-processes that has been encountered up to |
274 | now. */ |
275 | static int greatest_status = 1; |
276 | |
277 | /* This is the obstack which we use to allocate many strings. */ |
278 | |
279 | static struct obstack obstack; |
280 | |
281 | /* This is the obstack to build an environment variable to pass to |
282 | collect2 that describes all of the relevant switches of what to |
283 | pass the compiler in building the list of pointers to constructors |
284 | and destructors. */ |
285 | |
286 | static struct obstack collect_obstack; |
287 | |
288 | /* Forward declaration for prototypes. */ |
289 | struct path_prefix; |
290 | struct prefix_list; |
291 | |
292 | static void init_spec (void); |
293 | static void store_arg (const char *, int, int); |
294 | static char *load_specs (const char *); |
295 | static void read_specs (const char *, int); |
296 | static void set_spec (const char *, const char *); |
297 | static struct compiler *lookup_compiler (const char *, size_t, const char *); |
298 | static char *build_search_list (const struct path_prefix *, const char *, |
299 | bool_Bool, bool_Bool); |
300 | static void putenv_from_prefixes (const struct path_prefix *, const char *, |
301 | bool_Bool); |
302 | static int access_check (const char *, int); |
303 | static char *find_a_file (const struct path_prefix *, const char *, int, bool_Bool); |
304 | static void add_prefix (struct path_prefix *, const char *, const char *, |
305 | int, int, int); |
306 | static void add_sysrooted_prefix (struct path_prefix *, const char *, |
307 | const char *, int, int, int); |
308 | static void translate_options (int *, const char *const **); |
309 | static char *skip_whitespace (char *); |
310 | static void delete_if_ordinary (const char *); |
311 | static void delete_temp_files (void); |
312 | static void delete_failure_queue (void); |
313 | static void clear_failure_queue (void); |
314 | static int check_live_switch (int, int); |
315 | static const char *handle_braces (const char *); |
316 | static inline__inline__ bool_Bool input_suffix_matches (const char *, const char *); |
317 | static inline__inline__ bool_Bool switch_matches (const char *, const char *, int); |
318 | static inline__inline__ void mark_matching_switches (const char *, const char *, int); |
319 | static inline__inline__ void process_marked_switches (void); |
320 | static const char *process_brace_body (const char *, const char *, const char *, int, int); |
321 | static const struct spec_function *lookup_spec_function (const char *); |
322 | static const char *eval_spec_function (const char *, const char *); |
323 | static const char *handle_spec_function (const char *); |
324 | static char *save_string (const char *, int); |
325 | static void set_collect_gcc_options (void); |
326 | /* APPLE LOCAL %b/save-temps can clobber input file (radar 2871891) --ilr */ |
327 | static const char *check_basename_derived_file (const char *string); |
328 | static int do_spec_1 (const char *, int, const char *); |
329 | static int do_spec_2 (const char *); |
330 | static void do_option_spec (const char *, const char *); |
331 | static void do_self_spec (const char *); |
332 | static const char *find_file (const char *); |
333 | static int is_directory (const char *, bool_Bool); |
334 | static const char *validate_switches (const char *); |
335 | static void validate_all_switches (void); |
336 | static inline__inline__ void validate_switches_from_spec (const char *); |
337 | static void give_switch (int, int); |
338 | static int used_arg (const char *, int); |
339 | static int default_arg (const char *, int); |
340 | static void set_multilib_dir (void); |
341 | static void print_multilib_info (void); |
342 | static void perror_with_name (const char *); |
343 | static void fatal_ice (const char *, ...) ATTRIBUTE_PRINTF_1__attribute__ ( ( __format__ ( __printf__ , 1 , 2 ) ) ) __attribute__ ( ( __nonnull__ ( 1 ) ) ) ATTRIBUTE_NORETURN__attribute__ ( ( __noreturn__ ) ); |
344 | static void notice (const char *, ...) ATTRIBUTE_PRINTF_1__attribute__ ( ( __format__ ( __printf__ , 1 , 2 ) ) ) __attribute__ ( ( __nonnull__ ( 1 ) ) ); |
345 | static void display_help (void); |
346 | static void add_preprocessor_option (const char *, int); |
347 | static void add_assembler_option (const char *, int); |
348 | static void add_linker_option (const char *, int); |
349 | static void process_command (int, const char **); |
350 | static int execute (void); |
351 | static void alloc_args (void); |
352 | static void clear_args (void); |
353 | static void fatal_error (int); |
354 | #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC) |
355 | static void init_gcc_specs (struct obstack *, const char *, const char *, |
356 | const char *); |
357 | #endif |
358 | #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX) |
359 | static const char *convert_filename (const char *, int, int); |
360 | #endif |
361 | |
362 | static const char *if_exists_spec_function (int, const char **); |
363 | static const char *if_exists_else_spec_function (int, const char **); |
364 | static const char *replace_outfile_spec_function (int, const char **); |
365 | static const char *version_compare_spec_function (int, const char **); |
366 | static const char *include_spec_function (int, const char **); |
367 | |
368 | /* The Specs Language |
369 | |
370 | Specs are strings containing lines, each of which (if not blank) |
371 | is made up of a program name, and arguments separated by spaces. |
372 | The program name must be exact and start from root, since no path |
373 | is searched and it is unreliable to depend on the current working directory. |
374 | Redirection of input or output is not supported; the subprograms must |
375 | accept filenames saying what files to read and write. |
376 | |
377 | In addition, the specs can contain %-sequences to substitute variable text |
378 | or for conditional text. Here is a table of all defined %-sequences. |
379 | Note that spaces are not generated automatically around the results of |
380 | expanding these sequences; therefore, you can concatenate them together |
381 | or with constant text in a single argument. |
382 | |
383 | %% substitute one % into the program name or argument. |
384 | %i substitute the name of the input file being processed. |
385 | %b substitute the basename of the input file being processed. |
386 | This is the substring up to (and not including) the last period |
387 | and not including the directory. |
388 | %B same as %b, but include the file suffix (text after the last period). |
389 | %gSUFFIX |
390 | substitute a file name that has suffix SUFFIX and is chosen |
391 | once per compilation, and mark the argument a la %d. To reduce |
392 | exposure to denial-of-service attacks, the file name is now |
393 | chosen in a way that is hard to predict even when previously |
394 | chosen file names are known. For example, `%g.s ... %g.o ... %g.s' |
395 | might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches |
396 | the regexp "[.0-9A-Za-z]*%O"; "%O" is treated exactly as if it |
397 | had been pre-processed. Previously, %g was simply substituted |
398 | with a file name chosen once per compilation, without regard |
399 | to any appended suffix (which was therefore treated just like |
400 | ordinary text), making such attacks more likely to succeed. |
401 | %|SUFFIX |
402 | like %g, but if -pipe is in effect, expands simply to "-". |
403 | %mSUFFIX |
404 | like %g, but if -pipe is in effect, expands to nothing. (We have both |
405 | %| and %m to accommodate differences between system assemblers; see |
406 | the AS_NEEDS_DASH_FOR_PIPED_INPUT target macro.) |
407 | %uSUFFIX |
408 | like %g, but generates a new temporary file name even if %uSUFFIX |
409 | was already seen. |
410 | %USUFFIX |
411 | substitutes the last file name generated with %uSUFFIX, generating a |
412 | new one if there is no such last file name. In the absence of any |
413 | %uSUFFIX, this is just like %gSUFFIX, except they don't share |
414 | the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s' |
415 | would involve the generation of two distinct file names, one |
416 | for each `%g.s' and another for each `%U.s'. Previously, %U was |
417 | simply substituted with a file name chosen for the previous %u, |
418 | without regard to any appended suffix. |
419 | %jSUFFIX |
420 | substitutes the name of the HOST_BIT_BUCKET, if any, and if it is |
421 | writable, and if save-temps is off; otherwise, substitute the name |
422 | of a temporary file, just like %u. This temporary file is not |
423 | meant for communication between processes, but rather as a junk |
424 | disposal mechanism. |
425 | %.SUFFIX |
426 | substitutes .SUFFIX for the suffixes of a matched switch's args when |
427 | it is subsequently output with %*. SUFFIX is terminated by the next |
428 | space or %. |
429 | %d marks the argument containing or following the %d as a |
430 | temporary file name, so that that file will be deleted if CC exits |
431 | successfully. Unlike %g, this contributes no text to the argument. |
432 | %w marks the argument containing or following the %w as the |
433 | "output file" of this compilation. This puts the argument |
434 | into the sequence of arguments that %o will substitute later. |
435 | %V indicates that this compilation produces no "output file". |
436 | %W{...} |
437 | like %{...} but mark last argument supplied within |
438 | as a file to be deleted on failure. |
439 | %o substitutes the names of all the output files, with spaces |
440 | automatically placed around them. You should write spaces |
441 | around the %o as well or the results are undefined. |
442 | %o is for use in the specs for running the linker. |
443 | Input files whose names have no recognized suffix are not compiled |
444 | at all, but they are included among the output files, so they will |
445 | be linked. |
446 | %O substitutes the suffix for object files. Note that this is |
447 | handled specially when it immediately follows %g, %u, or %U |
448 | (with or without a suffix argument) because of the need for |
449 | those to form complete file names. The handling is such that |
450 | %O is treated exactly as if it had already been substituted, |
451 | except that %g, %u, and %U do not currently support additional |
452 | SUFFIX characters following %O as they would following, for |
453 | example, `.o'. |
454 | %I Substitute any of -iprefix (made from GCC_EXEC_PREFIX), -isysroot |
455 | (made from TARGET_SYSTEM_ROOT), -isystem (made from COMPILER_PATH |
456 | and -B options) and -imultilib as necessary. |
457 | APPLE LOCAL frameworks |
458 | %Q Substitute -iframework default paths. |
459 | %s current argument is the name of a library or startup file of some sort. |
460 | Search for that file in a standard list of directories |
461 | and substitute the full name found. |
462 | %eSTR Print STR as an error message. STR is terminated by a newline. |
463 | Use this when inconsistent options are detected. |
464 | %nSTR Print STR as a notice. STR is terminated by a newline. |
465 | %x{OPTION} Accumulate an option for %X. |
466 | %X Output the accumulated linker options specified by compilations. |
467 | %Y Output the accumulated assembler options specified by compilations. |
468 | %Z Output the accumulated preprocessor options specified by compilations. |
469 | %a process ASM_SPEC as a spec. |
470 | This allows config.h to specify part of the spec for running as. |
471 | %A process ASM_FINAL_SPEC as a spec. A capital A is actually |
472 | used here. This can be used to run a post-processor after the |
473 | assembler has done its job. |
474 | %D Dump out a -L option for each directory in startfile_prefixes. |
475 | If multilib_dir is set, extra entries are generated with it affixed. |
476 | %l process LINK_SPEC as a spec. |
477 | %L process LIB_SPEC as a spec. |
478 | %G process LIBGCC_SPEC as a spec. |
479 | %R Output the concatenation of target_system_root and |
480 | target_sysroot_suffix. |
481 | %S process STARTFILE_SPEC as a spec. A capital S is actually used here. |
482 | %E process ENDFILE_SPEC as a spec. A capital E is actually used here. |
483 | %C process CPP_SPEC as a spec. |
484 | %1 process CC1_SPEC as a spec. |
485 | %2 process CC1PLUS_SPEC as a spec. |
486 | %* substitute the variable part of a matched option. (See below.) |
487 | Note that each comma in the substituted string is replaced by |
488 | a single space. |
489 | %<S remove all occurrences of -S from the command line. |
490 | Note - this command is position dependent. % commands in the |
491 | spec string before this one will see -S, % commands in the |
492 | spec string after this one will not. |
493 | %<S* remove all occurrences of all switches beginning with -S from the |
494 | command line. |
495 | %:function(args) |
496 | Call the named function FUNCTION, passing it ARGS. ARGS is |
497 | first processed as a nested spec string, then split into an |
498 | argument vector in the usual fashion. The function returns |
499 | a string which is processed as if it had appeared literally |
500 | as part of the current spec. |
501 | %{S} substitutes the -S switch, if that switch was given to CC. |
502 | If that switch was not specified, this substitutes nothing. |
503 | Here S is a metasyntactic variable. |
504 | %{S*} substitutes all the switches specified to CC whose names start |
505 | with -S. This is used for -o, -I, etc; switches that take |
506 | arguments. CC considers `-o foo' as being one switch whose |
507 | name starts with `o'. %{o*} would substitute this text, |
508 | including the space; thus, two arguments would be generated. |
509 | %{S*&T*} likewise, but preserve order of S and T options (the order |
510 | of S and T in the spec is not significant). Can be any number |
511 | of ampersand-separated variables; for each the wild card is |
512 | optional. Useful for CPP as %{D*&U*&A*}. |
513 | |
514 | %{S:X} substitutes X, if the -S switch was given to CC. |
515 | %{!S:X} substitutes X, if the -S switch was NOT given to CC. |
516 | %{S*:X} substitutes X if one or more switches whose names start |
517 | with -S was given to CC. Normally X is substituted only |
518 | once, no matter how many such switches appeared. However, |
519 | if %* appears somewhere in X, then X will be substituted |
520 | once for each matching switch, with the %* replaced by the |
521 | part of that switch that matched the '*'. |
522 | %{.S:X} substitutes X, if processing a file with suffix S. |
523 | %{!.S:X} substitutes X, if NOT processing a file with suffix S. |
524 | APPLE LOCAL begin mainline 2007-03-13 5040758 |
525 | %{,S:X} substitutes X, if processing a file which will use spec S. |
526 | %{!,S:X} substitutes X, if NOT processing a file which will use spec S. |
527 | |
528 | %{S|T:X} substitutes X if either -S or -T was given to CC. This may be |
529 | combined with '!', '.', ',', and '*' as above binding stronger |
530 | than the OR. |
531 | If %* appears in X, all of the alternatives must be starred, and |
532 | only the first matching alternative is substituted. |
533 | %{S:X; if S was given to CC, substitutes X; |
534 | T:Y; else if T was given to CC, substitutes Y; |
535 | :D} else substitutes D. There can be as many clauses as you need. |
536 | This may be combined with '.', '!', ',', '|', and '*' as above. |
537 | APPLE LOCAL end mainline 2007-03-13 5040758 |
538 | |
539 | %(Spec) processes a specification defined in a specs file as *Spec: |
540 | %[Spec] as above, but put __ around -D arguments |
541 | |
542 | The conditional text X in a %{S:X} or similar construct may contain |
543 | other nested % constructs or spaces, or even newlines. They are |
544 | processed as usual, as described above. Trailing white space in X is |
545 | ignored. White space may also appear anywhere on the left side of the |
546 | colon in these constructs, except between . or * and the corresponding |
547 | word. |
548 | |
549 | The -O, -f, -m, and -W switches are handled specifically in these |
550 | constructs. If another value of -O or the negated form of a -f, -m, or |
551 | -W switch is found later in the command line, the earlier switch |
552 | value is ignored, except with {S*} where S is just one letter; this |
553 | passes all matching options. |
554 | |
555 | The character | at the beginning of the predicate text is used to indicate |
556 | that a command should be piped to the following command, but only if -pipe |
557 | is specified. |
558 | |
559 | Note that it is built into CC which switches take arguments and which |
560 | do not. You might think it would be useful to generalize this to |
561 | allow each compiler's spec to say which switches take arguments. But |
562 | this cannot be done in a consistent fashion. CC cannot even decide |
563 | which input files have been specified without knowing which switches |
564 | take arguments, and it must know which input files to compile in order |
565 | to tell which compilers to run. |
566 | |
567 | CC also knows implicitly that arguments starting in `-l' are to be |
568 | treated as compiler output files, and passed to the linker in their |
569 | proper position among the other output files. */ |
570 | |
571 | /* Define the macros used for specs %a, %l, %L, %S, %C, %1. */ |
572 | |
573 | /* config.h can define ASM_SPEC to provide extra args to the assembler |
574 | or extra switch-translations. */ |
575 | #ifndef ASM_SPEC |
576 | #define ASM_SPEC "" |
577 | #endif |
578 | |
579 | /* config.h can define ASM_FINAL_SPEC to run a post processor after |
580 | the assembler has run. */ |
581 | #ifndef ASM_FINAL_SPEC |
582 | #define ASM_FINAL_SPEC "" |
583 | #endif |
584 | |
585 | /* config.h can define CPP_SPEC to provide extra args to the C preprocessor |
586 | or extra switch-translations. */ |
587 | #ifndef CPP_SPEC |
588 | #define CPP_SPEC "" |
589 | #endif |
590 | |
591 | /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus |
592 | or extra switch-translations. */ |
593 | #ifndef CC1_SPEC |
594 | #define CC1_SPEC "" |
595 | #endif |
596 | |
597 | /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus |
598 | or extra switch-translations. */ |
599 | #ifndef CC1PLUS_SPEC |
600 | #define CC1PLUS_SPEC "" |
601 | #endif |
602 | |
603 | /* config.h can define LINK_SPEC to provide extra args to the linker |
604 | or extra switch-translations. */ |
605 | #ifndef LINK_SPEC |
606 | #define LINK_SPEC "" |
607 | #endif |
608 | |
609 | /* config.h can define LIB_SPEC to override the default libraries. */ |
610 | #ifndef LIB_SPEC |
611 | #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}" |
612 | #endif |
613 | |
614 | /* mudflap specs */ |
615 | #ifndef MFWRAP_SPEC |
616 | /* XXX: valid only for GNU ld */ |
617 | /* XXX: should exactly match hooks provided by libmudflap.a */ |
618 | #define MFWRAP_SPEC " %{static: %{fmudflap|fmudflapth: \ |
619 | --wrap=malloc --wrap=free --wrap=calloc --wrap=realloc\ |
620 | --wrap=mmap --wrap=munmap --wrap=alloca\ |
621 | } %{fmudflapth: --wrap=pthread_create\ |
622 | }} %{fmudflap|fmudflapth: --wrap=main}" |
623 | #endif |
624 | #ifndef MFLIB_SPEC |
625 | #define MFLIB_SPEC "%{fmudflap|fmudflapth: -export-dynamic}" |
626 | #endif |
627 | |
628 | /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is |
629 | included. */ |
630 | #ifndef LIBGCC_SPEC |
631 | #if defined(REAL_LIBGCC_SPEC) |
632 | #define LIBGCC_SPEC REAL_LIBGCC_SPEC |
633 | #elif defined(LINK_LIBGCC_SPECIAL_1) |
634 | /* Have gcc do the search for libgcc.a. */ |
635 | #define LIBGCC_SPEC "libgcc.a%s" |
636 | #else |
637 | #define LIBGCC_SPEC "-lgcc" |
638 | #endif |
639 | #endif |
640 | |
641 | /* config.h can define STARTFILE_SPEC to override the default crt0 files. */ |
642 | #ifndef STARTFILE_SPEC |
643 | #define STARTFILE_SPEC \ |
644 | "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}" |
645 | #endif |
646 | |
647 | /* config.h can define SWITCHES_NEED_SPACES to control which options |
648 | require spaces between the option and the argument. */ |
649 | #ifndef SWITCHES_NEED_SPACES |
650 | #define SWITCHES_NEED_SPACES "" |
651 | #endif |
652 | |
653 | /* config.h can define ENDFILE_SPEC to override the default crtn files. */ |
654 | #ifndef ENDFILE_SPEC |
655 | #define ENDFILE_SPEC "" |
656 | #endif |
657 | |
658 | #ifndef LINKER_NAME |
659 | #define LINKER_NAME "collect2" |
660 | #endif |
661 | |
662 | /* Define ASM_DEBUG_SPEC to be a spec suitable for translating '-g' |
663 | to the assembler. */ |
664 | #ifndef ASM_DEBUG_SPEC |
665 | # if defined(DBX_DEBUGGING_INFO) && defined(DWARF2_DEBUGGING_INFO) \ |
666 | && defined(HAVE_AS_GDWARF2_DEBUG_FLAG) && defined(HAVE_AS_GSTABS_DEBUG_FLAG) |
667 | # define ASM_DEBUG_SPEC \ |
668 | (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG \ |
669 | ? "%{gdwarf-2*:--gdwarf2}%{!gdwarf-2*:%{g*:--gstabs}}" \ |
670 | : "%{gstabs*:--gstabs}%{!gstabs*:%{g*:--gdwarf2}}") |
671 | # else |
672 | # if defined(DBX_DEBUGGING_INFO) && defined(HAVE_AS_GSTABS_DEBUG_FLAG) |
673 | # define ASM_DEBUG_SPEC "%{g*:--gstabs}" |
674 | # endif |
675 | # if defined(DWARF2_DEBUGGING_INFO) && defined(HAVE_AS_GDWARF2_DEBUG_FLAG) |
676 | # define ASM_DEBUG_SPEC "%{g*:--gdwarf2}" |
677 | # endif |
678 | # endif |
679 | #endif |
680 | #ifndef ASM_DEBUG_SPEC |
681 | # define ASM_DEBUG_SPEC "" |
682 | #endif |
683 | |
684 | /* Here is the spec for running the linker, after compiling all files. */ |
685 | |
686 | /* This is overridable by the target in case they need to specify the |
687 | -lgcc and -lc order specially, yet not require them to override all |
688 | of LINK_COMMAND_SPEC. */ |
689 | #ifndef LINK_GCC_C_SEQUENCE_SPEC |
690 | #define LINK_GCC_C_SEQUENCE_SPEC "%G %L %G" |
691 | #endif |
692 | |
693 | #ifndef LINK_SSP_SPEC |
694 | #ifdef TARGET_LIBC_PROVIDES_SSP |
695 | #define LINK_SSP_SPEC "%{fstack-protector:}" |
696 | #else |
697 | #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all:-lssp_nonshared -lssp}" |
698 | #endif |
699 | #endif |
700 | |
701 | #ifndef LINK_PIE_SPEC |
702 | #ifdef HAVE_LD_PIE |
703 | #define LINK_PIE_SPEC "%{pie:-pie} " |
704 | #else |
705 | #define LINK_PIE_SPEC "%{pie:} " |
706 | #endif |
707 | #endif |
708 | |
709 | /* -u* was put back because both BSD and SysV seem to support it. */ |
710 | /* %{static:} simply prevents an error message if the target machine |
711 | doesn't handle -static. */ |
712 | /* We want %{T*} after %{L*} and %D so that it can be used to specify linker |
713 | scripts which exist in user specified directories, or in standard |
714 | directories. */ |
715 | /* APPLE LOCAL begin add fcreate-profile */ |
716 | #ifndef LINK_COMMAND_SPEC |
717 | #define LINK_COMMAND_SPEC "\ |
718 | %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\ |
719 | %(linker) %l " LINK_PIE_SPEC "%X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r}\ |
720 | %{s} %{t} %{u*} %{x} %{z} %{Z} %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\ |
721 | %{static:} %{L*} %(mfwrap) %(link_libgcc) %o\ |
722 | %{fopenmp:%:include(libgomp.spec)%(link_gomp)} %(mflib)\ |
723 | %{fprofile-arcs|fprofile-generate|coverage|fcreate-profile:-lgcov}\ |
724 | %{!nostdlib:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}\ |
725 | %{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} }}}}}}" |
726 | #endif |
727 | /* APPLE LOCAL end add fcreate-profile */ |
728 | |
729 | #ifndef LINK_LIBGCC_SPEC |
730 | /* Generate -L options for startfile prefix list. */ |
731 | # define LINK_LIBGCC_SPEC "%D" |
732 | #endif |
733 | |
734 | #ifndef STARTFILE_PREFIX_SPEC |
735 | # define STARTFILE_PREFIX_SPEC "" |
736 | #endif |
737 | |
738 | #ifndef SYSROOT_SPEC |
739 | # define SYSROOT_SPEC "--sysroot=%R" |
740 | #endif |
741 | |
742 | #ifndef SYSROOT_SUFFIX_SPEC |
743 | # define SYSROOT_SUFFIX_SPEC "" |
744 | #endif |
745 | |
746 | #ifndef SYSROOT_HEADERS_SUFFIX_SPEC |
747 | # define SYSROOT_HEADERS_SUFFIX_SPEC "" |
748 | #endif |
749 | |
750 | static const char *asm_debug; |
751 | static const char *cpp_spec = CPP_SPEC"%{static:%{!dynamic:-D__STATIC__}}%{!static:-D__DYNAMIC__}" " %{pthread:-D_REENTRANT}"; |
752 | static const char *cc1_spec = CC1_SPEC"%{!mkernel:%{!static:%{!mdynamic-no-pic:-fPIC}}} " " % " % |
753 | static const char *cc1plus_spec = CC1PLUS_SPEC"-D__private_extern__=extern"; |
754 | static const char *link_gcc_c_sequence_spec = LINK_GCC_C_SEQUENCE_SPEC"%G %L %G"; |
755 | static const char *link_ssp_spec = LINK_SSP_SPEC"%{fstack-protector:}"; |
756 | static const char *asm_spec = ASM_SPEC"-arch %(darwin_arch) -force_cpusubtype_ALL"; |
757 | static const char *asm_final_spec = ASM_FINAL_SPEC""; |
758 | static const char *link_spec = LINK_SPEC"%{static}%{!static:-dynamic} %{fgnu-runtime:%:replace-outfile(-lobjc -lobjc-gnu)} %{!Zdynamiclib: %{Zforce_cpusubtype_ALL:-arch %(darwin_arch) -force_cpusubtype_ALL} %{!Zforce_cpusubtype_ALL:-arch %(darwin_subarch)} %{Zbundle:-bundle} %{Zbundle_loader*:-bundle_loader %*} %{client_name*} %{compatibility_version*:%e-compatibility_version only allowed with -dynamiclib} %{current_version*:%e-current_version only allowed with -dynamiclib} %{Zforce_flat_namespace:-force_flat_namespace} %{Zinstall_name*:%e-install_name only allowed with -dynamiclib} %{keep_private_externs} %{private_bundle} } %{Zdynamiclib: -dylib %{Zbundle:%e-bundle not allowed with -dynamiclib} %{Zbundle_loader*:%e-bundle_loader not allowed with -dynamiclib} %{client_name*:%e-client_name not allowed with -dynamiclib} %{compatibility_version*:-dylib_compatibility_version %*} %{current_version*:-dylib_current_version %*} %{Zforce_cpusubtype_ALL:-arch %(darwin_arch)} %{!Zforce_cpusubtype_ALL: -arch %(darwin_subarch)} %{Zforce_flat_namespace:%e-force_flat_namespace not allowed with -dynamiclib} %{Zinstall_name*:-dylib_install_name %*} %{keep_private_externs:%e-keep_private_externs not allowed with -dynamiclib} %{private_bundle:%e-private_bundle not allowed with -dynamiclib} } %{Zall_load:-all_load} %{Zallowable_client*:-allowable_client %*} %{Zbind_at_load:-bind_at_load} %{Zarch_errors_fatal:-arch_errors_fatal} %{Zdead_strip:-dead_strip} %{Zno_dead_strip_inits_and_terms:-no_dead_strip_inits_and_terms} %{Zdylib_file*:-dylib_file %*} %{Zdynamic:-dynamic} %{Zexported_symbols_list*:-exported_symbols_list %*} %{Zflat_namespace:-flat_namespace} %{headerpad_max_install_names*} %{Zimage_base*:-image_base %*} %{Zinit*:-init %*} " " %{!mmacosx-version-min=*:-macosx_version_min %(darwin_minversion)} %{mmacosx-version-min=*:-macosx_version_min %*} " " %{nomultidefs} %{Zmulti_module:-multi_module} %{Zsingle_module:-single_module} %{Zmultiply_defined*:-multiply_defined %*} %{!Zmultiply_defined*:%{shared-libgcc: %:version-compare(< 10.5 mmacosx-version-min= -multiply_defined) %:version-compare(< 10.5 mmacosx-version-min= suppress)}} %{Zmultiplydefinedunused*:-multiply_defined_unused %*} " " %{fpie:-pie} %{prebind} %{noprebind} %{nofixprebinding} %{prebind_all_twolevel_modules} %{read_only_relocs} %{sectcreate*} %{sectorder*} %{seg1addr*} %{segprot*} %{Zsegaddr*:-segaddr %*} %{Zsegs_read_only_addr*:-segs_read_only_addr %*} %{Zsegs_read_write_addr*:-segs_read_write_addr %*} %{Zseg_addr_table*: -seg_addr_table %*} %{Zfn_seg_addr_table_filename*:-seg_addr_table_filename %*} %{sub_library*} %{sub_umbrella*} " "%{isysroot*:-syslibroot %*}" " %{twolevel_namespace} %{twolevel_namespace_hints} %{Zumbrella*: -umbrella %*} %{undefined*} %{Zunexported_symbols_list*:-unexported_symbols_list %*} %{Zweak_reference_mismatches*:-weak_reference_mismatches %*} %{!Zweak_reference_mismatches*:-weak_reference_mismatches non-weak} %{X} %{y*} %{w} %{pagezero_size*} %{segs_read_*} %{seglinkedit} %{noseglinkedit} %{sectalign*} %{sectobjectsymbols*} %{segcreate*} %{whyload} %{whatsloaded} %{dylinker_install_name*} %{dylinker} %{Mach} "; |
759 | static const char *lib_spec = LIB_SPEC"%{!static:-lSystem}"; |
760 | static const char *mfwrap_spec = MFWRAP_SPEC" %{static: %{fmudflap|fmudflapth: --wrap=malloc --wrap=free --wrap=calloc --wrap=realloc --wrap=mmap --wrap=munmap --wrap=alloca} %{fmudflapth: --wrap=pthread_create}} %{fmudflap|fmudflapth: --wrap=main}"; |
761 | static const char *mflib_spec = MFLIB_SPEC"%{fmudflap|fmudflapth: -export-dynamic}"; |
762 | static const char *link_gomp_spec = ""; |
763 | static const char *libgcc_spec = LIBGCC_SPEC"%{static:-lgcc_static; static-libgcc: -lgcc_eh -lgcc; shared-libgcc|fexceptions|fgnu-runtime: %:version-compare(!> 10.5 mmacosx-version-min= -lgcc_s.10.4) %:version-compare(>= 10.5 mmacosx-version-min= -lgcc_s.10.5) -lgcc; :%:version-compare(>< 10.3.9 10.5 mmacosx-version-min= -lgcc_s.10.4) %:version-compare(>= 10.5 mmacosx-version-min= -lgcc_s.10.5) -lgcc}"; |
764 | static const char *endfile_spec = ENDFILE_SPEC""; |
765 | static const char *startfile_spec = STARTFILE_SPEC"%{Zdynamiclib: %(darwin_dylib1) } %{!Zdynamiclib:%{Zbundle:%{!static:-lbundle1.o}} %{!Zbundle:%{pg:%{static:-lgcrt0.o} %{!static:%{object:-lgcrt0.o} %{!object:%{preload:-lgcrt0.o} %{!preload:-lgcrt1.o %(darwin_crt2)}}}} %{!pg:%{static:-lcrt0.o} %{!static:%{object:-lcrt0.o} %{!object:%{preload:-lcrt0.o} %{!preload: %(darwin_crt1) %(darwin_crt2)}}}}}} %{shared-libgcc:%:version-compare(< 10.5 mmacosx-version-min= crt3.o%s)}"; |
766 | static const char *switches_need_spaces = SWITCHES_NEED_SPACES""; |
767 | static const char *linker_name_spec = LINKER_NAME"collect2"; |
768 | static const char *link_command_spec = LINK_COMMAND_SPEC"%{!fdump=*:%{!fsyntax-only:%{!precomp:%{!c:%{!M:%{!MM:%{!E:%{!S: %(linker) %l %X %{d} %{s} %{t} %{Z} %{u*} %{A} %{e*} %{m} %{r} %{x} %{o*}%{!o:-o a.out} %{!A:%{!nostdlib:%{!nostartfiles:%S}}} %{L*} %{fopenmp:%:include(libgomp.spec)%(link_gomp)} " " %(link_libgcc) %o %{fprofile-arcs|fprofile-generate|fcreate-profile|coverage:-lgcov} " " %{fnested-functions: -allow_stack_execute} %{!nostdlib:%{!nodefaultlibs:%(link_ssp) %G %L}} " " %{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} %{F*} }}}}}}}}\n%{!fdump=*:%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:" "" "" " %{.c|.cc|.C|.cpp|.cp|.c++|.cxx|.CPP|.m|.mm: %{!O: %{!O1: %{!O2: %{!O3: %{!O4: %{!Os: %(darwin_dsymutil) }}}}}}}}}}}}}}"; |
769 | static const char *link_libgcc_spec = LINK_LIBGCC_SPEC"%D"; |
770 | static const char *startfile_prefix_spec = STARTFILE_PREFIX_SPEC""; |
771 | static const char *sysroot_spec = SYSROOT_SPEC"--sysroot=%R"; |
772 | static const char *sysroot_suffix_spec = SYSROOT_SUFFIX_SPEC""; |
773 | static const char *sysroot_hdrs_suffix_spec = SYSROOT_HEADERS_SUFFIX_SPEC""; |
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 | |
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. */ |
784 | static const char *trad_capable_cpp = |
785 | "cc1 -E %{traditional|ftraditional|traditional-cpp:-traditional-cpp}"; |
786 | |
787 | /* APPLE LOCAL begin pch */ |
788 | /* When making PCH file use this. */ |
789 | static const char *pch = |
790 | /* APPLE LOCAL begin ss2 */ |
791 | "-o %g.s %{!o*:--output-pch=%i.gch} %W{o*:--output-pch=%*} \ |
792 | %{fsave-repository=*: \n as %a -o %w%* %g.s %A}%V"; |
793 | /* APPLE LOCAL end ss2 */ |
794 | /* APPLE LOCAL end pch */ |
795 | |
796 | /* We don't wrap .d files in %W{} since a missing .d file, and |
797 | therefore no dependency entry, confuses make into thinking a .o |
798 | file that happens to exist is up-to-date. */ |
799 | static const char *cpp_unique_options = |
800 | "%{C|CC:%{!E:%eGCC does not support -C or -CC without -E}}\ |
801 | %{!Q:-quiet} %{nostdinc*} %{C} %{CC} %{v} %{I*&F*} %{P} %I\ |
802 | %{MD:-MD %{!o:%b.d}%{o*:%.d%*}}\ |
803 | %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}}\ |
804 | %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\ |
805 | %{!E:%{!M:%{!MM:%{MD|MMD:%{o*:-MQ %*}}}}}\ |
806 | %{remap} %{g3:-dD} %{H} %C %{D*&U*&A*} %{i*} %Z %i\ |
807 | %{fmudflap:-D_MUDFLAP -include mf-runtime.h}\ |
808 | %{fmudflapth:-D_MUDFLAP -D_MUDFLAPTH -include mf-runtime.h}\ |
809 | %{E|M|MM:%W{o*}}"; |
810 | |
811 | /* This contains cpp options which are common with cc1_options and are passed |
812 | only when preprocessing only to avoid duplication. We pass the cc1 spec |
813 | options to the preprocessor so that it the cc1 spec may manipulate |
814 | options used to set target flags. Those special target flags settings may |
815 | in turn cause preprocessor symbols to be defined specially. */ |
816 | static const char *cpp_options = |
817 | "%(cpp_unique_options) %1 %{m*} %{std*&ansi&trigraphs} %{W*&pedantic*} %{w}\ |
818 | %{f*} %{g*:%{!g0:%{!fno-working-directory:-fworking-directory}}} %{O*}\ |
819 | %{undef} %{save-temps:-fpch-preprocess}"; |
820 | |
821 | /* This contains cpp options which are not passed when the preprocessor |
822 | output will be used by another program. */ |
823 | static const char *cpp_debug_options = "%{d*}"; |
824 | |
825 | /* LLVM LOCAL begin */ |
826 | static const char *llvm_options = |
827 | #ifdef ENABLE_LLVM |
828 | "%{O4|emit-llvm:%{S:-emit-llvm} \ |
829 | %{!S:-emit-llvm-bc \ |
830 | %{c: %W{o*} %{!o*:-o %b%w.o}} \ |
831 | %{!c:-o %d%w%u%O}}}" |
832 | #else |
833 | "%{emit-llvm:%e--emit-llvm is not supported in this configuration.}" |
834 | #endif |
835 | ; |
836 | /* LLVM LOCAL end */ |
837 | /* NB: This is shared amongst all front-ends. */ |
838 | static const char *cc1_options = |
839 | /* APPLE LOCAL begin -fast or -fastf or -fastcp */ |
840 | "%{fast:-O3}\ |
841 | %{fastf:-O3}\ |
842 | %{fastcp:-O3}" |
843 | /* APPLE LOCAL end -fast or -fastf or -fastcp */ |
844 | "%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\ |
845 | "/* LLVM LOCAL */"\ |
846 | %1 %{!Q:-quiet} -dumpbase %B %{d*} %{Zmllvm*: -mllvm %*} %{m*} %{a*}\ |
847 | %{c|S:%{o*:-auxbase-strip %*}%{!o*:-auxbase %b}}%{!c:%{!S:-auxbase %b}}\ |
848 | %{g*} %{O*} %{W*&pedantic*} %{w} %{std*&ansi&trigraphs}\ |
849 | %{v:-version} %{pg:-p} %{p} %{f*} %{undef}\ |
850 | %{Qn:-fno-ident} %{--help:--help}\ |
851 | %{--target-help:--target-help}\ |
852 | %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %b.s}}}\ |
853 | %{fsyntax-only:-o %j} %{-param*}\ |
854 | %{fmudflap|fmudflapth:-fno-builtin -fno-merge-constants}\ |
855 | %{coverage:-fprofile-arcs -ftest-coverage}"; |
856 | |
857 | static const char *asm_options = |
858 | "%a %Y %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}"; |
859 | |
860 | static const char *invoke_as = |
861 | #ifdef AS_NEEDS_DASH_FOR_PIPED_INPUT |
862 | /* LLVM LOCAL */ |
863 | "%{!O4:%{!emit-llvm:%{!S:-o %|.s |\n as %(asm_options) %|.s %A }}}"; |
864 | #else |
865 | /* LLVM LOCAL */ |
866 | "%{!O4:%{!emit-llvm:%{!S:-o %|.s |\n as %(asm_options) %m.s %A }}}"; |
867 | #endif |
868 | |
869 | /* Some compilers have limits on line lengths, and the multilib_select |
870 | and/or multilib_matches strings can be very long, so we build them at |
871 | run time. */ |
872 | static struct obstack multilib_obstack; |
873 | static const char *multilib_select; |
874 | static const char *multilib_matches; |
875 | static const char *multilib_defaults; |
876 | static const char *multilib_exclusions; |
877 | |
878 | /* Check whether a particular argument is a default argument. */ |
879 | |
880 | #ifndef MULTILIB_DEFAULTS |
881 | #define MULTILIB_DEFAULTS { "" } |
882 | #endif |
883 | |
884 | static const char *const multilib_defaults_raw[] = MULTILIB_DEFAULTS{ "" }; |
885 | |
886 | #ifndef DRIVER_SELF_SPECS |
887 | #define DRIVER_SELF_SPECS "" |
888 | #endif |
889 | |
890 | /* Adding -fopenmp should imply pthreads. This is particularly important |
891 | for targets that use different start files and suchlike. */ |
892 | #ifndef GOMP_SELF_SPECS |
893 | #define GOMP_SELF_SPECS "%{fopenmp: -pthread}" |
894 | #endif |
895 | |
896 | static const char *const driver_self_specs[] = { |
897 | DRIVER_SELF_SPECS"", GOMP_SELF_SPECS"" |
898 | }; |
899 | |
900 | #ifndef OPTION_DEFAULT_SPECS |
901 | #define OPTION_DEFAULT_SPECS { "", "" } |
902 | #endif |
903 | |
904 | struct default_spec |
905 | { |
906 | const char *name; |
907 | const char *spec; |
908 | }; |
909 | |
910 | static const struct default_spec |
911 | option_default_specs[] = { OPTION_DEFAULT_SPECS{ "tune" , "%{!mtune=*:%{!mcpu=*:%{!march=*:-mtune=%(VALUE)}}}" } , { "cpu" , "%{!mtune=*:%{!mcpu=*:%{!march=*:-mtune=%(VALUE)}}}" } , { "arch" , "%{!march=*:-march=%(VALUE)}" } }; |
912 | |
913 | struct user_specs |
914 | { |
915 | struct user_specs *next; |
916 | const char *filename; |
917 | }; |
918 | |
919 | static struct user_specs *user_specs_head, *user_specs_tail; |
920 | |
921 | #ifndef SWITCH_TAKES_ARG |
922 | #define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR) |
923 | #endif |
924 | |
925 | #ifndef WORD_SWITCH_TAKES_ARG |
926 | #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR) |
927 | #endif |
928 | |
929 | #ifdef HAVE_TARGET_EXECUTABLE_SUFFIX |
930 | /* This defines which switches stop a full compilation. */ |
931 | #define DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR) \ |
932 | ((CHAR) == 'c' || (CHAR) == 'S') |
933 | |
934 | #ifndef SWITCH_CURTAILS_COMPILATION |
935 | #define SWITCH_CURTAILS_COMPILATION(CHAR) \ |
936 | DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR) |
937 | #endif |
938 | #endif |
939 | |
940 | /* Record the mapping from file suffixes for compilation specs. */ |
941 | |
942 | struct compiler |
943 | { |
944 | const char *suffix; /* Use this compiler for input files |
945 | whose names end in this suffix. */ |
946 | |
947 | const char *spec; /* To use this compiler, run this spec. */ |
948 | |
949 | const char *cpp_spec; /* If non-NULL, substitute this spec |
950 | for `%C', rather than the usual |
951 | cpp_spec. */ |
952 | const int combinable; /* If nonzero, compiler can deal with |
953 | multiple source files at once (IMA). */ |
954 | const int needs_preprocessing; /* If nonzero, source files need to |
955 | be run through a preprocessor. */ |
956 | }; |
957 | |
958 | /* Pointer to a vector of `struct compiler' that gives the spec for |
959 | compiling a file, based on its suffix. |
960 | A file that does not end in any of these suffixes will be passed |
961 | unchanged to the loader and nothing else will be done to it. |
962 | |
963 | An entry containing two 0s is used to terminate the vector. |
964 | |
965 | If multiple entries match a file, the last matching one is used. */ |
966 | |
967 | static struct compiler *compilers; |
968 | |
969 | /* Number of entries in `compilers', not counting the null terminator. */ |
970 | |
971 | static int n_compilers; |
972 | |
973 | /* The default list of file name suffixes and their compilation specs. */ |
974 | |
975 | static const struct compiler default_compilers[] = |
976 | { |
977 | /* Add lists of suffixes of known languages here. If those languages |
978 | were not present when we built the driver, we will hit these copies |
979 | and be given a more meaningful error than "file not used since |
980 | linking is not done". */ |
981 | {".m", "#Objective-C", 0, 0, 0}, {".mi", "#Objective-C", 0, 0, 0}, |
982 | {".mm", "#Objective-C++", 0, 0, 0}, {".M", "#Objective-C++", 0, 0, 0}, |
983 | {".mii", "#Objective-C++", 0, 0, 0}, |
984 | {".cc", "#C++", 0, 0, 0}, {".cxx", "#C++", 0, 0, 0}, |
985 | {".cpp", "#C++", 0, 0, 0}, {".cp", "#C++", 0, 0, 0}, |
986 | {".c++", "#C++", 0, 0, 0}, {".C", "#C++", 0, 0, 0}, |
987 | {".CPP", "#C++", 0, 0, 0}, {".ii", "#C++", 0, 0, 0}, |
988 | {".ads", "#Ada", 0, 0, 0}, {".adb", "#Ada", 0, 0, 0}, |
989 | {".f", "#Fortran", 0, 0, 0}, {".for", "#Fortran", 0, 0, 0}, |
990 | {".fpp", "#Fortran", 0, 0, 0}, {".F", "#Fortran", 0, 0, 0}, |
991 | {".FOR", "#Fortran", 0, 0, 0}, {".FPP", "#Fortran", 0, 0, 0}, |
992 | {".f90", "#Fortran", 0, 0, 0}, {".f95", "#Fortran", 0, 0, 0}, |
993 | {".F90", "#Fortran", 0, 0, 0}, {".F95", "#Fortran", 0, 0, 0}, |
994 | {".r", "#Ratfor", 0, 0, 0}, |
995 | {".p", "#Pascal", 0, 0, 0}, {".pas", "#Pascal", 0, 0, 0}, |
996 | {".java", "#Java", 0, 0, 0}, {".class", "#Java", 0, 0, 0}, |
997 | {".zip", "#Java", 0, 0, 0}, {".jar", "#Java", 0, 0, 0}, |
998 | /* Next come the entries for C. */ |
999 | {".c", "@c", 0, 1, 1}, |
1000 | {"@c", |
1001 | /* cc1 has an integrated ISO C preprocessor. We should invoke the |
1002 | external preprocessor if -save-temps is given. */ |
1003 | /* APPLE LOCAL begin treat -fast same as -combine --dbj */ |
1004 | "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\ |
1005 | %{!E:%{!M:%{!MM:\ |
1006 | %{traditional|ftraditional:\ |
1007 | %eGNU C no longer supports -traditional without -E}\ |
1008 | %{combine|fast|fastf|fastcp:\ |
1009 | %{save-temps|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \ |
1010 | %(cpp_options) -o %{save-temps:%b.i} %{!save-temps:%g.i}}\ |
1011 | %{!save-temps:%{!traditional-cpp:%{!no-integrated-cpp:\ |
1012 | "/* LLVM LOCAL */"\ |
1013 | cc1 %(cpp_unique_options) %(llvm_options) %(cc1_options)}}\ |
1014 | %{!fsyntax-only:%(invoke_as)}};:\ |
1015 | %{save-temps|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \ |
1016 | %(cpp_options) -o %{save-temps:%b.i} %{!save-temps:%g.i} \n\ |
1017 | "/* APPLE LOCAL predictive compilation */"\ |
1018 | cc1 -fpreprocessed %<fpredictive-compilation* %{save-temps:%b.i} %{!save-temps:%g.i} \ |
1019 | "/* LLVM LOCAL */"\ |
1020 | %(llvm_options) %(cc1_options)}\ |
1021 | %{!save-temps:%{!traditional-cpp:%{!no-integrated-cpp:\ |
1022 | "/* LLVM LOCAL */"\ |
1023 | cc1 %(cpp_unique_options) %(llvm_options) %(cc1_options)}}}\ |
1024 | %{!fsyntax-only:%(invoke_as)}}}}}", 0, 1, 1}, |
1025 | /* APPLE LOCAL end treat -fast same as -combine --dbj */ |
1026 | {"-", |
1027 | "%{!E:%e-E or -x required when input is from standard input}\ |
1028 | %(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)", 0, 0, 0}, |
1029 | {".h", "@c-header", 0, 0, 0}, |
1030 | {"@c-header", |
1031 | /* cc1 has an integrated ISO C preprocessor. We should invoke the |
1032 | external preprocessor if -save-temps is given. */ |
1033 | "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\ |
1034 | %{!E:%{!M:%{!MM:\ |
1035 | %{save-temps|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \ |
1036 | %(cpp_options) -o %{save-temps:%b.i} %{!save-temps:%g.i} \n\ |
1037 | "/* APPLE LOCAL predictive compilation */"\ |
1038 | cc1 -fpreprocessed %<fpredictive-compilation* %{save-temps:%b.i} %{!save-temps:%g.i} \ |
1039 | %(cc1_options)\ |
1040 | "/* APPLE LOCAL pch */"\ |
1041 | %(pch)}\ |
1042 | %{!save-temps:%{!traditional-cpp:%{!no-integrated-cpp:\ |
1043 | cc1 %(cpp_unique_options) %(cc1_options)\ |
1044 | "/* APPLE LOCAL pch */"\ |
1045 | %(pch)}}}}}}", 0, 0, 0}, |
1046 | {".i", "@cpp-output", 0, 1, 0}, |
1047 | {"@cpp-output", |
1048 | /* APPLE LOCAL predictive compilation */ |
1049 | /* LLVM LOCAL */ |
1050 | "%{!M:%{!MM:%{!E:cc1 -fpreprocessed %i %(llvm_options) %(cc1_options) %<fpredictive-compilation* %{!fsyntax-only:%(invoke_as)}}}}", 0, 1, 0}, |
1051 | /* APPLE LOCAL begin preprocess .s files 2001-07-24 --sts */ |
1052 | /* This is kind of lame; the purpose of having .s and .S be treated |
1053 | differently is so that we can control whether to run the |
1054 | preprocessor on assembly files. The standard behavior would |
1055 | still work even on HFS filesystems, because they preserve case, |
1056 | but we'd have to get a number of projects to change their files, |
1057 | and of course that's just *too* *hard*. */ |
1058 | {".s", "@assembler-with-cpp", 0, 1, 0}, |
1059 | /* APPLE LOCAL end preprocess .s files 2001-07-24 --sts */ |
1060 | {"@assembler", |
1061 | "%{!M:%{!MM:%{!E:%{!S:as %(asm_debug) %(asm_options) %i %A }}}}", 0, 1, 0}, |
1062 | {".S", "@assembler-with-cpp", 0, 1, 0}, |
1063 | {"@assembler-with-cpp", |
1064 | #ifdef AS_NEEDS_DASH_FOR_PIPED_INPUT |
1065 | "%(trad_capable_cpp) -lang-asm %(cpp_options)\ |
1066 | %{E|M|MM:%(cpp_debug_options)}\ |
1067 | %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\ |
1068 | as %(asm_debug) %(asm_options) %|.s %A }}}}" |
1069 | #else |
1070 | "%(trad_capable_cpp) -lang-asm %(cpp_options)\ |
1071 | %{E|M|MM:%(cpp_debug_options)}\ |
1072 | %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\ |
1073 | as %(asm_debug) %(asm_options) %m.s %A }}}}" |
1074 | #endif |
1075 | , 0, 1, 0}, |
1076 | |
1077 | #include "specs.h" |
1078 | /* Mark end of table. */ |
1079 | {0, 0, 0, 0, 0} |
1080 | }; |
1081 | |
1082 | /* Number of elements in default_compilers, not counting the terminator. */ |
1083 | |
1084 | static const int n_default_compilers = ARRAY_SIZE( sizeof ( default_compilers ) / sizeof ( ( default_compilers ) [ 0 ] ) ) (default_compilers) - 1; |
1085 | |
1086 | /* APPLE LOCAL begin -ObjC 2001-08-03 --sts */ |
1087 | /* -ObjC is not the same as -x objective-c, since it only affects the |
1088 | expectation of the language in files already thought to be source |
1089 | code. */ |
1090 | static const char *default_language; |
1091 | /* APPLE LOCAL end -ObjC 2001-08-03 --sts */ |
1092 | /* A vector of options to give to the linker. |
1093 | These options are accumulated by %x, |
1094 | and substituted into the linker command with %X. */ |
1095 | static int n_linker_options; |
1096 | static char **linker_options; |
1097 | |
1098 | /* A vector of options to give to the assembler. |
1099 | These options are accumulated by -Wa, |
1100 | and substituted into the assembler command with %Y. */ |
1101 | static int n_assembler_options; |
1102 | static char **assembler_options; |
1103 | |
1104 | /* A vector of options to give to the preprocessor. |
1105 | These options are accumulated by -Wp, |
1106 | and substituted into the preprocessor command with %Z. */ |
1107 | static int n_preprocessor_options; |
1108 | static char **preprocessor_options; |
1109 | |
1110 | /* Define how to map long options into short ones. */ |
1111 | |
1112 | /* This structure describes one mapping. */ |
1113 | struct option_map |
1114 | { |
1115 | /* The long option's name. */ |
1116 | const char *const name; |
1117 | /* The equivalent short option. */ |
1118 | const char *const equivalent; |
1119 | /* Argument info. A string of flag chars; NULL equals no options. |
1120 | a => argument required. |
1121 | o => argument optional. |
1122 | j => join argument to equivalent, making one word. |
1123 | * => require other text after NAME as an argument. */ |
1124 | const char *const arg_info; |
1125 | }; |
1126 | |
1127 | /* This is the table of mappings. Mappings are tried sequentially |
1128 | for each option encountered; the first one that matches, wins. */ |
1129 | |
1130 | static const struct option_map option_map[] = |
1131 | { |
1132 | {"--all-warnings", "-Wall", 0}, |
1133 | {"--ansi", "-ansi", 0}, |
1134 | {"--assemble", "-S", 0}, |
1135 | {"--assert", "-A", "a"}, |
1136 | {"--classpath", "-fclasspath=", "aj"}, |
1137 | {"--bootclasspath", "-fbootclasspath=", "aj"}, |
1138 | {"--CLASSPATH", "-fclasspath=", "aj"}, |
1139 | {"--combine", "-combine", 0}, |
1140 | {"--comments", "-C", 0}, |
1141 | {"--comments-in-macros", "-CC", 0}, |
1142 | {"--compile", "-c", 0}, |
1143 | {"--debug", "-g", "oj"}, |
1144 | {"--define-macro", "-D", "aj"}, |
1145 | {"--dependencies", "-M", 0}, |
1146 | {"--dump", "-d", "a"}, |
1147 | {"--dumpbase", "-dumpbase", "a"}, |
1148 | /* LLVM LOCAL */ |
1149 | {"--emit-llvm", "-emit-llvm", 0 }, |
1150 | {"--encoding", "-fencoding=", "aj"}, |
1151 | {"--entry", "-e", 0}, |
1152 | {"--extra-warnings", "-W", 0}, |
1153 | {"--extdirs", "-fextdirs=", "aj"}, |
1154 | {"--for-assembler", "-Wa", "a"}, |
1155 | {"--for-linker", "-Xlinker", "a"}, |
1156 | {"--force-link", "-u", "a"}, |
1157 | {"--coverage", "-coverage", 0}, |
1158 | {"--imacros", "-imacros", "a"}, |
1159 | {"--include", "-include", "a"}, |
1160 | {"--include-barrier", "-I-", 0}, |
1161 | {"--include-directory", "-I", "aj"}, |
1162 | {"--include-directory-after", "-idirafter", "a"}, |
1163 | {"--include-prefix", "-iprefix", "a"}, |
1164 | {"--include-with-prefix", "-iwithprefix", "a"}, |
1165 | {"--include-with-prefix-before", "-iwithprefixbefore", "a"}, |
1166 | {"--include-with-prefix-after", "-iwithprefix", "a"}, |
1167 | {"--language", "-x", "a"}, |
1168 | {"--library-directory", "-L", "a"}, |
1169 | {"--machine", "-m", "aj"}, |
1170 | {"--machine-", "-m", "*j"}, |
1171 | {"--no-integrated-cpp", "-no-integrated-cpp", 0}, |
1172 | {"--no-line-commands", "-P", 0}, |
1173 | {"--no-precompiled-includes", "-noprecomp", 0}, |
1174 | {"--no-standard-includes", "-nostdinc", 0}, |
1175 | {"--no-standard-libraries", "-nostdlib", 0}, |
1176 | {"--no-warnings", "-w", 0}, |
1177 | {"--optimize", "-O", "oj"}, |
1178 | {"--output", "-o", "a"}, |
1179 | {"--output-class-directory", "-foutput-class-dir=", "ja"}, |
1180 | {"--param", "--param", "a"}, |
1181 | {"--pass-exit-codes", "-pass-exit-codes", 0}, |
1182 | {"--pedantic", "-pedantic", 0}, |
1183 | {"--pedantic-errors", "-pedantic-errors", 0}, |
1184 | {"--pie", "-pie", 0}, |
1185 | {"--pipe", "-pipe", 0}, |
1186 | {"--prefix", "-B", "a"}, |
1187 | {"--preprocess", "-E", 0}, |
1188 | {"--print-search-dirs", "-print-search-dirs", 0}, |
1189 | {"--print-file-name", "-print-file-name=", "aj"}, |
1190 | {"--print-libgcc-file-name", "-print-libgcc-file-name", 0}, |
1191 | {"--print-missing-file-dependencies", "-MG", 0}, |
1192 | {"--print-multi-lib", "-print-multi-lib", 0}, |
1193 | {"--print-multi-directory", "-print-multi-directory", 0}, |
1194 | {"--print-multi-os-directory", "-print-multi-os-directory", 0}, |
1195 | {"--print-prog-name", "-print-prog-name=", "aj"}, |
1196 | {"--profile", "-p", 0}, |
1197 | {"--profile-blocks", "-a", 0}, |
1198 | {"--quiet", "-q", 0}, |
1199 | {"--resource", "-fcompile-resource=", "aj"}, |
1200 | {"--save-temps", "-save-temps", 0}, |
1201 | {"--shared", "-shared", 0}, |
1202 | {"--silent", "-q", 0}, |
1203 | {"--specs", "-specs=", "aj"}, |
1204 | {"--static", "-static", 0}, |
1205 | {"--std", "-std=", "aj"}, |
1206 | {"--symbolic", "-symbolic", 0}, |
1207 | {"--sysroot", "--sysroot=", "aj"}, |
1208 | {"--time", "-time", 0}, |
1209 | {"--trace-includes", "-H", 0}, |
1210 | {"--traditional", "-traditional", 0}, |
1211 | {"--traditional-cpp", "-traditional-cpp", 0}, |
1212 | {"--trigraphs", "-trigraphs", 0}, |
1213 | {"--undefine-macro", "-U", "aj"}, |
1214 | {"--user-dependencies", "-MM", 0}, |
1215 | {"--verbose", "-v", 0}, |
1216 | {"--warn-", "-W", "*j"}, |
1217 | {"--write-dependencies", "-MD", 0}, |
1218 | {"--write-user-dependencies", "-MMD", 0}, |
1219 | {"--", "-f", "*j"} |
1220 | }; |
1221 | |
1222 | |
1223 | #ifdef TARGET_OPTION_TRANSLATE_TABLE |
1224 | static const struct { |
1225 | const char *const option_found; |
1226 | const char *const replacements; |
1227 | } target_option_translations[] = |
1228 | { |
1229 | TARGET_OPTION_TRANSLATE_TABLE{ "-all_load" , "-Zall_load" } , { "-allowable_client" , "-Zallowable_client" } , { "-arch_errors_fatal" , "-Zarch_errors_fatal" } , { "-bind_at_load" , "-Zbind_at_load" } , { "-bundle" , "-Zbundle" } , { "-bundle_loader" , "-Zbundle_loader" } , { "-weak_reference_mismatches" , "-Zweak_reference_mismatches" } , { "-dead_strip" , "-Zdead_strip" } , { "-no_dead_strip_inits_and_terms" , "-Zno_dead_strip_inits_and_terms" } , { "-dependency-file" , "-MF" } , { "-dylib_file" , "-Zdylib_file" } , { "-dynamic" , "-Zdynamic" } , { "-dynamiclib" , "-Zdynamiclib" } , { "-exported_symbols_list" , "-Zexported_symbols_list" } , { "-gfull" , "-g -fno-eliminate-unused-debug-symbols" } , { "-gused" , "-g -feliminate-unused-debug-symbols" } , { "-segaddr" , "-Zsegaddr" } , { "-segs_read_only_addr" , "-Zsegs_read_only_addr" } , { "-segs_read_write_addr" , "-Zsegs_read_write_addr" } , { "-seg_addr_table" , "-Zseg_addr_table" } , { "-seg_addr_table_filename" , "-Zfn_seg_addr_table_filename" } , { "-umbrella" , "-Zumbrella" } , { "-fapple-kext" , "-fapple-kext -static -Wa,-static" } , { "-filelist" , "-Xlinker -filelist -Xlinker" } , { "-findirect-virtual-calls" , "-fapple-kext" } , { "-flat_namespace" , "-Zflat_namespace" } , { "-force_cpusubtype_ALL" , "-Zforce_cpusubtype_ALL" } , { "-force_flat_namespace" , "-Zforce_flat_namespace" } , { "-framework" , "-Xlinker -framework -Xlinker" } , { "-fterminated-vtables" , "-fapple-kext" } , { "-image_base" , "-Zimage_base" } , { "-init" , "-Zinit" } , { "-install_name" , "-Zinstall_name" } , { "-mllvm" , "-Zmllvm" } , { "-mkernel" , "-mkernel -static -Wa,-static" } , { "-multiply_defined_unused" , "-Zmultiplydefinedunused" } , { "-multiply_defined" , "-Zmultiply_defined" } , { "-multi_module" , "-Zmulti_module" } , { "-static" , "-static -Wa,-static" } , { "-shared" , "-Zdynamiclib" } , { "-single_module" , "-Zsingle_module" } , { "-unexported_symbols_list" , "-Zunexported_symbols_list" } , { "-fobjc-gc" , "-fobjc-gc -Wno-non-lvalue-assign" } , { "-fconstant-cfstrings" , "-mconstant-cfstrings" } , { "-fno-constant-cfstrings" , "-mno-constant-cfstrings" } , { "-Wnonportable-cfstrings" , "-mwarn-nonportable-cfstrings" } , { "-Wno-nonportable-cfstrings" , "-mno-warn-nonportable-cfstrings" } , { "-fpascal-strings" , "-mpascal-strings" } , { "-fno-pascal-strings" , "-mno-pascal-strings" } , { "" , "" }, |
1230 | { 0, 0 } |
1231 | }; |
1232 | #endif |
1233 | |
1234 | /* Translate the options described by *ARGCP and *ARGVP. |
1235 | Make a new vector and store it back in *ARGVP, |
1236 | and store its length in *ARGVC. */ |
1237 | |
1238 | static void |
1239 | translate_options (int *argcp, const char *const **argvp) |
1240 | { |
1241 | int i; |
1242 | int argc = *argcp; |
1243 | const char *const *argv = *argvp; |
1244 | int newvsize = (argc + 2) * 2 * sizeof (const char *); |
1245 | const char **newv = xmalloc (newvsize); |
1246 | int newindex = 0; |
1247 | |
1248 | i = 0; |
1249 | newv[newindex++] = argv[i++]; |
1250 | |
1251 | while (i < argc) |
1252 | { |
1253 | #ifdef TARGET_OPTION_TRANSLATE_TABLE |
1254 | int tott_idx; |
1255 | |
1256 | for (tott_idx = 0; |
1257 | target_option_translations[tott_idx].option_found; |
1258 | tott_idx++) |
1259 | { |
1260 | if (strcmp (target_option_translations[tott_idx].option_found, |
1261 | argv[i]) == 0) |
1262 | { |
1263 | int spaces = 1; |
1264 | const char *sp; |
1265 | char *np; |
1266 | |
1267 | for (sp = target_option_translations[tott_idx].replacements; |
1268 | *sp; sp++) |
1269 | { |
1270 | if (*sp == ' ') |
1271 | spaces ++; |
1272 | } |
1273 | |
1274 | newvsize += spaces * sizeof (const char *); |
1275 | newv = xrealloc (newv, newvsize); |
1276 | |
1277 | sp = target_option_translations[tott_idx].replacements; |
1278 | np = xstrdup (sp); |
1279 | |
1280 | while (1) |
1281 | { |
1282 | while (*np == ' ') |
1283 | np++; |
1284 | if (*np == 0) |
1285 | break; |
1286 | newv[newindex++] = np; |
1287 | while (*np != ' ' && *np) |
1288 | np++; |
1289 | if (*np == 0) |
1290 | break; |
1291 | *np++ = 0; |
1292 | } |
1293 | |
1294 | i ++; |
1295 | break; |
1296 | } |
1297 | } |
1298 | if (target_option_translations[tott_idx].option_found) |
1299 | continue; |
1300 | #endif |
1301 | |
1302 | /* Translate -- options. */ |
1303 | if (argv[i][0] == '-' && argv[i][1] == '-') |
1304 | { |
1305 | size_t j; |
1306 | /* Find a mapping that applies to this option. */ |
1307 | for (j = 0; j < ARRAY_SIZE( sizeof ( option_map ) / sizeof ( ( option_map ) [ 0 ] ) ) (option_map); j++) |
1308 | { |
1309 | size_t optlen = strlen (option_map[j].name); |
1310 | size_t arglen = strlen (argv[i]); |
1311 | size_t complen = arglen > optlen ? optlen : arglen; |
1312 | const char *arginfo = option_map[j].arg_info; |
1313 | |
1314 | if (arginfo == 0) |
1315 | arginfo = ""; |
1316 | |
1317 | if (!strncmp (argv[i], option_map[j].name, complen)) |
1318 | { |
1319 | const char *arg = 0; |
1320 | |
1321 | if (arglen < optlen) |
1322 | { |
1323 | size_t k; |
1324 | for (k = j + 1; k < ARRAY_SIZE( sizeof ( option_map ) / sizeof ( ( option_map ) [ 0 ] ) ) (option_map); k++) |
1325 | if (strlen (option_map[k].name) >= arglen |
1326 | && !strncmp (argv[i], option_map[k].name, arglen)) |
1327 | { |
1328 | error ("ambiguous abbreviation %s", argv[i]); |
1329 | break; |
1330 | } |
1331 | |
1332 | if (k != ARRAY_SIZE( sizeof ( option_map ) / sizeof ( ( option_map ) [ 0 ] ) ) (option_map)) |
1333 | break; |
1334 | } |
1335 | |
1336 | if (arglen > optlen) |
1337 | { |
1338 | /* If the option has an argument, accept that. */ |
1339 | if (argv[i][optlen] == '=') |
1340 | arg = argv[i] + optlen + 1; |
1341 | |
1342 | /* If this mapping requires extra text at end of name, |
1343 | accept that as "argument". */ |
1344 | else if (strchr (arginfo, '*') != 0) |
1345 | arg = argv[i] + optlen; |
1346 | |
1347 | /* Otherwise, extra text at end means mismatch. |
1348 | Try other mappings. */ |
1349 | else |
1350 | continue; |
1351 | } |
1352 | |
1353 | else if (strchr (arginfo, '*') != 0) |
1354 | { |
1355 | error ("incomplete '%s' option", option_map[j].name); |
1356 | break; |
1357 | } |
1358 | |
1359 | /* Handle arguments. */ |
1360 | if (strchr (arginfo, 'a') != 0) |
1361 | { |
1362 | if (arg == 0) |
1363 | { |
1364 | if (i + 1 == argc) |
1365 | { |
1366 | error ("missing argument to '%s' option", |
1367 | option_map[j].name); |
1368 | break; |
1369 | } |
1370 | |
1371 | arg = argv[++i]; |
1372 | } |
1373 | } |
1374 | else if (strchr (arginfo, '*') != 0) |
1375 | ; |
1376 | else if (strchr (arginfo, 'o') == 0) |
1377 | { |
1378 | if (arg != 0) |
1379 | error ("extraneous argument to '%s' option", |
1380 | option_map[j].name); |
1381 | arg = 0; |
1382 | } |
1383 | |
1384 | /* Store the translation as one argv elt or as two. */ |
1385 | if (arg != 0 && strchr (arginfo, 'j') != 0) |
1386 | newv[newindex++] = concat (option_map[j].equivalent, arg, |
1387 | NULL( ( void * ) 0 )); |
1388 | else if (arg != 0) |
1389 | { |
1390 | newv[newindex++] = option_map[j].equivalent; |
1391 | newv[newindex++] = arg; |
1392 | } |
1393 | else |
1394 | newv[newindex++] = option_map[j].equivalent; |
1395 | |
1396 | break; |
1397 | } |
1398 | } |
1399 | i++; |
1400 | } |
1401 | |
1402 | /* Handle old-fashioned options--just copy them through, |
1403 | with their arguments. */ |
1404 | else if (argv[i][0] == '-') |
1405 | { |
1406 | const char *p = argv[i] + 1; |
1407 | int c = *p; |
1408 | int nskip = 1; |
1409 | |
1410 | if (SWITCH_TAKES_ARG( ( c ) == 'D' || ( c ) == 'U' || ( c ) == 'o' || ( c ) == 'e' || ( c ) == 'T' || ( c ) == 'u' || ( c ) == 'I' || ( c ) == 'm' || ( c ) == 'x' || ( c ) == 'L' || ( c ) == 'A' || ( c ) == 'V' || ( c ) == 'F' || ( c ) == 'B' || ( c ) == 'b' ) (c) > (p[1] != 0)) |
1411 | nskip += SWITCH_TAKES_ARG( ( c ) == 'D' || ( c ) == 'U' || ( c ) == 'o' || ( c ) == 'e' || ( c ) == 'T' || ( c ) == 'u' || ( c ) == 'I' || ( c ) == 'm' || ( c ) == 'x' || ( c ) == 'L' || ( c ) == 'A' || ( c ) == 'V' || ( c ) == 'F' || ( c ) == 'B' || ( c ) == 'b' ) (c) - (p[1] != 0); |
1412 | else if (WORD_SWITCH_TAKES_ARG( ( ! strcmp ( p , "Tdata" ) || ! strcmp ( p , "Ttext" ) || ! strcmp ( p , "Tbss" ) || ! strcmp ( p , "include" ) || ! strcmp ( p , "imacros" ) || ! strcmp ( p , "aux-info" ) || ! strcmp ( p , "idirafter" ) || ! strcmp ( p , "iprefix" ) || ! strcmp ( p , "iwithprefix" ) || ! strcmp ( p , "iwithprefixbefore" ) || ! strcmp ( p , "iquote" ) || ! strcmp ( p , "isystem" ) || ! strcmp ( p , "isysroot" ) || ! strcmp ( p , "-param" ) || ! strcmp ( p , "specs" ) || ! strcmp ( p , "MF" ) || ! strcmp ( p , "MT" ) || ! strcmp ( p , "MQ" ) ) ? 1 : ! strcmp ( p , "Zallowable_client" ) ? 1 : ! strcmp ( p , "arch" ) ? 1 : ! strcmp ( p , "arch_only" ) ? 1 : ! strcmp ( p , "Zbundle_loader" ) ? 1 : ! strcmp ( p , "client_name" ) ? 1 : ! strcmp ( p , "compatibility_version" ) ? 1 : ! strcmp ( p , "current_version" ) ? 1 : ! strcmp ( p , "Zdylib_file" ) ? 1 : ! strcmp ( p , "Zexported_symbols_list" ) ? 1 : ! strcmp ( p , "Zimage_base" ) ? 1 : ! strcmp ( p , "Zinit" ) ? 1 : ! strcmp ( p , "Zinstall_name" ) ? 1 : ! strcmp ( p , "Zmllvm" ) ? 1 : ! strcmp ( p , "Zmultiplydefinedunused" ) ? 1 : ! strcmp ( p , "Zmultiply_defined" ) ? 1 : ! strcmp ( p , "precomp-trustfile" ) ? 1 : ! strcmp ( p , "read_only_relocs" ) ? 1 : ! strcmp ( p , "sectcreate" ) ? 3 : ! strcmp ( p , "sectorder" ) ? 3 : ! strcmp ( p , "Zsegaddr" ) ? 2 : ! strcmp ( p , "Zsegs_read_only_addr" ) ? 1 : ! strcmp ( p , "Zsegs_read_write_addr" ) ? 1 : ! strcmp ( p , "Zseg_addr_table" ) ? 1 : ! strcmp ( p , "Zfn_seg_addr_table_filename" ) ? 1 : ! strcmp ( p , "seg1addr" ) ? 1 : ! strcmp ( p , "segprot" ) ? 3 : ! strcmp ( p , "sub_library" ) ? 1 : ! strcmp ( p , "sub_umbrella" ) ? 1 : ! strcmp ( p , "Zumbrella" ) ? 1 : ! strcmp ( p , "undefined" ) ? 1 : ! strcmp ( p , "Zunexported_symbols_list" ) ? 1 : ! strcmp ( p , "Zweak_reference_mismatches" ) ? 1 : ! strcmp ( p , "pagezero_size" ) ? 1 : ! strcmp ( p , "segs_read_only_addr" ) ? 1 : ! strcmp ( p , "segs_read_write_addr" ) ? 1 : ! strcmp ( p , "sectalign" ) ? 3 : ! strcmp ( p , "sectobjectsymbols" ) ? 2 : ! strcmp ( p , "segcreate" ) ? 3 : ! strcmp ( p , "dylinker_install_name" ) ? 1 : 0 ) (p)) |
1413 | nskip += WORD_SWITCH_TAKES_ARG( ( ! strcmp ( p , "Tdata" ) || ! strcmp ( p , "Ttext" ) || ! strcmp ( p , "Tbss" ) || ! strcmp ( p , "include" ) || ! strcmp ( p , "imacros" ) || ! strcmp ( p , "aux-info" ) || ! strcmp ( p , "idirafter" ) || ! strcmp ( p , "iprefix" ) || ! strcmp ( p , "iwithprefix" ) || ! strcmp ( p , "iwithprefixbefore" ) || ! strcmp ( p , "iquote" ) || ! strcmp ( p , "isystem" ) || ! strcmp ( p , "isysroot" ) || ! strcmp ( p , "-param" ) || ! strcmp ( p , "specs" ) || ! strcmp ( p , "MF" ) || ! strcmp ( p , "MT" ) || ! strcmp ( p , "MQ" ) ) ? 1 : ! strcmp ( p , "Zallowable_client" ) ? 1 : ! strcmp ( p , "arch" ) ? 1 : ! strcmp ( p , "arch_only" ) ? 1 : ! strcmp ( p , "Zbundle_loader" ) ? 1 : ! strcmp ( p , "client_name" ) ? 1 : ! strcmp ( p , "compatibility_version" ) ? 1 : ! strcmp ( p , "current_version" ) ? 1 : ! strcmp ( p , "Zdylib_file" ) ? 1 : ! strcmp ( p , "Zexported_symbols_list" ) ? 1 : ! strcmp ( p , "Zimage_base" ) ? 1 : ! strcmp ( p , "Zinit" ) ? 1 : ! strcmp ( p , "Zinstall_name" ) ? 1 : ! strcmp ( p , "Zmllvm" ) ? 1 : ! strcmp ( p , "Zmultiplydefinedunused" ) ? 1 : ! strcmp ( p , "Zmultiply_defined" ) ? 1 : ! strcmp ( p , "precomp-trustfile" ) ? 1 : ! strcmp ( p , "read_only_relocs" ) ? 1 : ! strcmp ( p , "sectcreate" ) ? 3 : ! strcmp ( p , "sectorder" ) ? 3 : ! strcmp ( p , "Zsegaddr" ) ? 2 : ! strcmp ( p , "Zsegs_read_only_addr" ) ? 1 : ! strcmp ( p , "Zsegs_read_write_addr" ) ? 1 : ! strcmp ( p , "Zseg_addr_table" ) ? 1 : ! strcmp ( p , "Zfn_seg_addr_table_filename" ) ? 1 : ! strcmp ( p , "seg1addr" ) ? 1 : ! strcmp ( p , "segprot" ) ? 3 : ! strcmp ( p , "sub_library" ) ? 1 : ! strcmp ( p , "sub_umbrella" ) ? 1 : ! strcmp ( p , "Zumbrella" ) ? 1 : ! strcmp ( p , "undefined" ) ? 1 : ! strcmp ( p , "Zunexported_symbols_list" ) ? 1 : ! strcmp ( p , "Zweak_reference_mismatches" ) ? 1 : ! strcmp ( p , "pagezero_size" ) ? 1 : ! strcmp ( p , "segs_read_only_addr" ) ? 1 : ! strcmp ( p , "segs_read_write_addr" ) ? 1 : ! strcmp ( p , "sectalign" ) ? 3 : ! strcmp ( p , "sectobjectsymbols" ) ? 2 : ! strcmp ( p , "segcreate" ) ? 3 : ! strcmp ( p , "dylinker_install_name" ) ? 1 : 0 ) (p); |
1414 | else if ((c == 'B' || c == 'b' || c == 'x') |
1415 | && p[1] == 0) |
1416 | nskip += 1; |
1417 | else if (! strcmp (p, "Xlinker")) |
1418 | nskip += 1; |
1419 | else if (! strcmp (p, "Xpreprocessor")) |
1420 | nskip += 1; |
1421 | else if (! strcmp (p, "Xassembler")) |
1422 | nskip += 1; |
1423 | |
1424 | /* Watch out for an option at the end of the command line that |
1425 | is missing arguments, and avoid skipping past the end of the |
1426 | command line. */ |
1427 | if (nskip + i > argc) |
1428 | nskip = argc - i; |
1429 | |
1430 | while (nskip > 0) |
1431 | { |
1432 | newv[newindex++] = argv[i++]; |
1433 | nskip--; |
1434 | } |
1435 | } |
1436 | else |
1437 | /* Ordinary operands, or +e options. */ |
1438 | newv[newindex++] = argv[i++]; |
1439 | } |
1440 | |
1441 | newv[newindex] = 0; |
1442 | |
1443 | *argvp = newv; |
1444 | *argcp = newindex; |
1445 | } |
1446 | |
1447 | static char * |
1448 | skip_whitespace (char *p) |
1449 | { |
1450 | while (1) |
1451 | { |
1452 | /* A fully-blank line is a delimiter in the SPEC file and shouldn't |
1453 | be considered whitespace. */ |
1454 | if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n') |
1455 | return p + 1; |
1456 | else if (*p == '\n' || *p == ' ' || *p == '\t') |
1457 | p++; |
1458 | else if (*p == '#') |
1459 | { |
1460 | while (*p != '\n') |
1461 | p++; |
1462 | p++; |
1463 | } |
1464 | else |
1465 | break; |
1466 | } |
1467 | |
1468 | return p; |
1469 | } |
1470 | /* Structures to keep track of prefixes to try when looking for files. */ |
1471 | |
1472 | struct prefix_list |
1473 | { |
1474 | const char *prefix; /* String to prepend to the path. */ |
1475 | struct prefix_list *next; /* Next in linked list. */ |
1476 | int require_machine_suffix; /* Don't use without machine_suffix. */ |
1477 | /* 2 means try both machine_suffix and just_machine_suffix. */ |
1478 | int priority; /* Sort key - priority within list. */ |
1479 | int os_multilib; /* 1 if OS multilib scheme should be used, |
1480 | 0 for GCC multilib scheme. */ |
1481 | }; |
1482 | |
1483 | struct path_prefix |
1484 | { |
1485 | struct prefix_list *plist; /* List of prefixes to try */ |
1486 | int max_len; /* Max length of a prefix in PLIST */ |
1487 | const char *name; /* Name of this list (used in config stuff) */ |
1488 | }; |
1489 | |
1490 | /* List of prefixes to try when looking for executables. */ |
1491 | |
1492 | static struct path_prefix exec_prefixes = { 0, 0, "exec" }; |
1493 | |
1494 | /* List of prefixes to try when looking for startup (crt0) files. */ |
1495 | |
1496 | static struct path_prefix startfile_prefixes = { 0, 0, "startfile" }; |
1497 | |
1498 | /* List of prefixes to try when looking for include files. */ |
1499 | |
1500 | static struct path_prefix include_prefixes = { 0, 0, "include" }; |
1501 | |
1502 | /* Suffix to attach to directories searched for commands. |
1503 | This looks like `MACHINE/VERSION/'. */ |
1504 | |
1505 | static const char *machine_suffix = 0; |
1506 | |
1507 | /* Suffix to attach to directories searched for commands. |
1508 | This is just `MACHINE/'. */ |
1509 | |
1510 | static const char *just_machine_suffix = 0; |
1511 | |
1512 | /* Adjusted value of GCC_EXEC_PREFIX envvar. */ |
1513 | |
1514 | static const char *gcc_exec_prefix; |
1515 | |
1516 | /* Adjusted value of standard_libexec_prefix. */ |
1517 | |
1518 | static const char *gcc_libexec_prefix; |
1519 | |
1520 | /* Default prefixes to attach to command names. */ |
1521 | |
1522 | #ifndef STANDARD_STARTFILE_PREFIX_1 |
1523 | #define STANDARD_STARTFILE_PREFIX_1 "/lib/" |
1524 | #endif |
1525 | #ifndef STANDARD_STARTFILE_PREFIX_2 |
1526 | #define STANDARD_STARTFILE_PREFIX_2 "/usr/lib/" |
1527 | #endif |
1528 | |
1529 | /* APPLE LOCAL begin mainline 4.3 2006-12-13 CROSS_DIRECTORY_STRUCTURE 4697325 */ |
1530 | #ifdef CROSS_DIRECTORY_STRUCTURE /* Don't use these prefixes for a cross compiler. */ |
1531 | /* APPLE LOCAL end mainline 4.3 2006-12-13 CROSS_DIRECTORY_STRUCTURE 4697325 */ |
1532 | #undef MD_EXEC_PREFIX |
1533 | #undef MD_STARTFILE_PREFIX |
1534 | #undef MD_STARTFILE_PREFIX_1 |
1535 | #endif |
1536 | |
1537 | /* If no prefixes defined, use the null string, which will disable them. */ |
1538 | #ifndef MD_EXEC_PREFIX |
1539 | #define MD_EXEC_PREFIX "" |
1540 | #endif |
1541 | #ifndef MD_STARTFILE_PREFIX |
1542 | #define MD_STARTFILE_PREFIX "" |
1543 | #endif |
1544 | #ifndef MD_STARTFILE_PREFIX_1 |
1545 | #define MD_STARTFILE_PREFIX_1 "" |
1546 | #endif |
1547 | |
1548 | static const char *const standard_exec_prefix = STANDARD_EXEC_PREFIX"/Users/sabre/cvs/llvm-gcc-4.2/install/lib/gcc/"; |
1549 | static const char *const standard_exec_prefix_1 = "/usr/libexec/gcc/"; |
1550 | static const char *const standard_exec_prefix_2 = "/usr/lib/gcc/"; |
1551 | static const char *md_exec_prefix = MD_EXEC_PREFIX""; |
1552 | |
1553 | static const char *md_startfile_prefix = MD_STARTFILE_PREFIX""; |
1554 | static const char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1""; |
1555 | static const char *const standard_startfile_prefix = STANDARD_STARTFILE_PREFIX"../../../"; |
1556 | static const char *const standard_startfile_prefix_1 |
1557 | = STANDARD_STARTFILE_PREFIX_1"/lib/"; |
1558 | static const char *const standard_startfile_prefix_2 |
1559 | = STANDARD_STARTFILE_PREFIX_2"/usr/lib/"; |
1560 | |
1561 | static const char *const tooldir_base_prefix = TOOLDIR_BASE_PREFIX"../../../../"; |
1562 | static const char *tooldir_prefix; |
1563 | |
1564 | static const char *const standard_bindir_prefix = STANDARD_BINDIR_PREFIX"/Users/sabre/cvs/llvm-gcc-4.2/install/bin/"; |
1565 | |
1566 | static const char *standard_libexec_prefix = STANDARD_LIBEXEC_PREFIX"/Users/sabre/cvs/llvm-gcc-4.2/install/libexec/gcc/"; |
1567 | |
1568 | /* Subdirectory to use for locating libraries. Set by |
1569 | set_multilib_dir based on the compilation options. */ |
1570 | |
1571 | static const char *multilib_dir; |
1572 | |
1573 | /* Subdirectory to use for locating libraries in OS conventions. Set by |
1574 | set_multilib_dir based on the compilation options. */ |
1575 | |
1576 | static const char *multilib_os_dir; |
1577 | |
1578 | /* Structure to keep track of the specs that have been defined so far. |
1579 | These are accessed using %(specname) or %[specname] in a compiler |
1580 | or link spec. */ |
1581 | |
1582 | struct spec_list |
1583 | { |
1584 | /* The following 2 fields must be first */ |
1585 | /* to allow EXTRA_SPECS to be initialized */ |
1586 | const char *name; /* name of the spec. */ |
1587 | const char *ptr; /* available ptr if no static pointer */ |
1588 | |
1589 | /* The following fields are not initialized */ |
1590 | /* by EXTRA_SPECS */ |
1591 | const char **ptr_spec; /* pointer to the spec itself. */ |
1592 | struct spec_list *next; /* Next spec in linked list. */ |
1593 | int name_len; /* length of the name */ |
1594 | int alloc_p; /* whether string was allocated */ |
1595 | }; |
1596 | |
1597 | #define INIT_STATIC_SPEC(NAME,PTR) \ |
1598 | { NAME, NULL, PTR, (struct spec_list *) 0, sizeof (NAME) - 1, 0 } |
1599 | |
1600 | /* List of statically defined specs. */ |
1601 | static struct spec_list static_specs[] = |
1602 | { |
1603 | INIT_STATIC_SPEC{ "asm" , ( ( void * ) 0 ) , & asm_spec , ( struct spec_list * ) 0 , sizeof ( "asm" ) - 1 , 0 } ("asm", &asm_spec), |
1604 | INIT_STATIC_SPEC{ "asm_debug" , ( ( void * ) 0 ) , & asm_debug , ( struct spec_list * ) 0 , sizeof ( "asm_debug" ) - 1 , 0 } ("asm_debug", &asm_debug), |
1605 | INIT_STATIC_SPEC{ "asm_final" , ( ( void * ) 0 ) , & asm_final_spec , ( struct spec_list * ) 0 , sizeof ( "asm_final" ) - 1 , 0 } ("asm_final", &asm_final_spec), |
1606 | INIT_STATIC_SPEC{ "asm_options" , ( ( void * ) 0 ) , & asm_options , ( struct spec_list * ) 0 , sizeof ( "asm_options" ) - 1 , 0 } ("asm_options", &asm_options), |
1607 | INIT_STATIC_SPEC{ "invoke_as" , ( ( void * ) 0 ) , & invoke_as , ( struct spec_list * ) 0 , sizeof ( "invoke_as" ) - 1 , 0 } ("invoke_as", &invoke_as), |
1608 | INIT_STATIC_SPEC{ "cpp" , ( ( void * ) 0 ) , & cpp_spec , ( struct spec_list * ) 0 , sizeof ( "cpp" ) - 1 , 0 } ("cpp", &cpp_spec), |
1609 | INIT_STATIC_SPEC{ "cpp_options" , ( ( void * ) 0 ) , & cpp_options , ( struct spec_list * ) 0 , sizeof ( "cpp_options" ) - 1 , 0 } ("cpp_options", &cpp_options), |
1610 | INIT_STATIC_SPEC{ "cpp_debug_options" , ( ( void * ) 0 ) , & cpp_debug_options , ( struct spec_list * ) 0 , sizeof ( "cpp_debug_options" ) - 1 , 0 } ("cpp_debug_options", &cpp_debug_options), |
1611 | INIT_STATIC_SPEC{ "cpp_unique_options" , ( ( void * ) 0 ) , & cpp_unique_options , ( struct spec_list * ) 0 , sizeof ( "cpp_unique_options" ) - 1 , 0 } ("cpp_unique_options", &cpp_unique_options), |
1612 | INIT_STATIC_SPEC{ "trad_capable_cpp" , ( ( void * ) 0 ) , & trad_capable_cpp , ( struct spec_list * ) 0 , sizeof ( "trad_capable_cpp" ) - 1 , 0 } ("trad_capable_cpp", &trad_capable_cpp), |
1613 | /* APPLE LOCAL pch */ |
1614 | INIT_STATIC_SPEC{ "pch" , ( ( void * ) 0 ) , & pch , ( struct spec_list * ) 0 , sizeof ( "pch" ) - 1 , 0 } ("pch", &pch), |
1615 | INIT_STATIC_SPEC{ "cc1" , ( ( void * ) 0 ) , & cc1_spec , ( struct spec_list * ) 0 , sizeof ( "cc1" ) - 1 , 0 } ("cc1", &cc1_spec), |
1616 | INIT_STATIC_SPEC{ "cc1_options" , ( ( void * ) 0 ) , & cc1_options , ( struct spec_list * ) 0 , sizeof ( "cc1_options" ) - 1 , 0 } ("cc1_options", &cc1_options), |
1617 | INIT_STATIC_SPEC{ "cc1plus" , ( ( void * ) 0 ) , & cc1plus_spec , ( struct spec_list * ) 0 , sizeof ( "cc1plus" ) - 1 , 0 } ("cc1plus", &cc1plus_spec), |
1618 | INIT_STATIC_SPEC{ "link_gcc_c_sequence" , ( ( void * ) 0 ) , & link_gcc_c_sequence_spec , ( struct spec_list * ) 0 , sizeof ( "link_gcc_c_sequence" ) - 1 , 0 } ("link_gcc_c_sequence", &link_gcc_c_sequence_spec), |
1619 | INIT_STATIC_SPEC{ "link_ssp" , ( ( void * ) 0 ) , & link_ssp_spec , ( struct spec_list * ) 0 , sizeof ( "link_ssp" ) - 1 , 0 } ("link_ssp", &link_ssp_spec), |
1620 | INIT_STATIC_SPEC{ "endfile" , ( ( void * ) 0 ) , & endfile_spec , ( struct spec_list * ) 0 , sizeof ( "endfile" ) - 1 , 0 } ("endfile", &endfile_spec), |
1621 | INIT_STATIC_SPEC{ "link" , ( ( void * ) 0 ) , & link_spec , ( struct spec_list * ) 0 , sizeof ( "link" ) - 1 , 0 } ("link", &link_spec), |
1622 | INIT_STATIC_SPEC{ "lib" , ( ( void * ) 0 ) , & lib_spec , ( struct spec_list * ) 0 , sizeof ( "lib" ) - 1 , 0 } ("lib", &lib_spec), |
1623 | INIT_STATIC_SPEC{ "mfwrap" , ( ( void * ) 0 ) , & mfwrap_spec , ( struct spec_list * ) 0 , sizeof ( "mfwrap" ) - 1 , 0 } ("mfwrap", &mfwrap_spec), |
1624 | INIT_STATIC_SPEC{ "mflib" , ( ( void * ) 0 ) , & mflib_spec , ( struct spec_list * ) 0 , sizeof ( "mflib" ) - 1 , 0 } ("mflib", &mflib_spec), |
1625 | INIT_STATIC_SPEC{ "link_gomp" , ( ( void * ) 0 ) , & link_gomp_spec , ( struct spec_list * ) 0 , sizeof ( "link_gomp" ) - 1 , 0 } ("link_gomp", &link_gomp_spec), |
1626 | INIT_STATIC_SPEC{ "libgcc" , ( ( void * ) 0 ) , & libgcc_spec , ( struct spec_list * ) 0 , sizeof ( "libgcc" ) - 1 , 0 } ("libgcc", &libgcc_spec), |
1627 | INIT_STATIC_SPEC{ "startfile" , ( ( void * ) 0 ) , & startfile_spec , ( struct spec_list * ) 0 , sizeof ( "startfile" ) - 1 , 0 } ("startfile", &startfile_spec), |
1628 | INIT_STATIC_SPEC{ "switches_need_spaces" , ( ( void * ) 0 ) , & switches_need_spaces , ( struct spec_list * ) 0 , sizeof ( "switches_need_spaces" ) - 1 , 0 } ("switches_need_spaces", &switches_need_spaces), |
1629 | INIT_STATIC_SPEC{ "cross_compile" , ( ( void * ) 0 ) , & cross_compile , ( struct spec_list * ) 0 , sizeof ( "cross_compile" ) - 1 , 0 } ("cross_compile", &cross_compile), |
1630 | INIT_STATIC_SPEC{ "version" , ( ( void * ) 0 ) , & compiler_version , ( struct spec_list * ) 0 , sizeof ( "version" ) - 1 , 0 } ("version", &compiler_version), |
1631 | INIT_STATIC_SPEC{ "multilib" , ( ( void * ) 0 ) , & multilib_select , ( struct spec_list * ) 0 , sizeof ( "multilib" ) - 1 , 0 } ("multilib", &multilib_select), |
1632 | INIT_STATIC_SPEC{ "multilib_defaults" , ( ( void * ) 0 ) , & multilib_defaults , ( struct spec_list * ) 0 , sizeof ( "multilib_defaults" ) - 1 , 0 } ("multilib_defaults", &multilib_defaults), |
1633 | INIT_STATIC_SPEC{ "multilib_extra" , ( ( void * ) 0 ) , & multilib_extra , ( struct spec_list * ) 0 , sizeof ( "multilib_extra" ) - 1 , 0 } ("multilib_extra", &multilib_extra), |
1634 | INIT_STATIC_SPEC{ "multilib_matches" , ( ( void * ) 0 ) , & multilib_matches , ( struct spec_list * ) 0 , sizeof ( "multilib_matches" ) - 1 , 0 } ("multilib_matches", &multilib_matches), |
1635 | INIT_STATIC_SPEC{ "multilib_exclusions" , ( ( void * ) 0 ) , & multilib_exclusions , ( struct spec_list * ) 0 , sizeof ( "multilib_exclusions" ) - 1 , 0 } ("multilib_exclusions", &multilib_exclusions), |
1636 | INIT_STATIC_SPEC{ "multilib_options" , ( ( void * ) 0 ) , & multilib_options , ( struct spec_list * ) 0 , sizeof ( "multilib_options" ) - 1 , 0 } ("multilib_options", &multilib_options), |
1637 | INIT_STATIC_SPEC{ "linker" , ( ( void * ) 0 ) , & linker_name_spec , ( struct spec_list * ) 0 , sizeof ( "linker" ) - 1 , 0 } ("linker", &linker_name_spec), |
1638 | INIT_STATIC_SPEC{ "link_libgcc" , ( ( void * ) 0 ) , & link_libgcc_spec , ( struct spec_list * ) 0 , sizeof ( "link_libgcc" ) - 1 , 0 } ("link_libgcc", &link_libgcc_spec), |
1639 | /* LLVM LOCAL */ |
1640 | INIT_STATIC_SPEC{ "llvm_options" , ( ( void * ) 0 ) , & llvm_options , ( struct spec_list * ) 0 , sizeof ( "llvm_options" ) - 1 , 0 } ("llvm_options", &llvm_options), |
1641 | INIT_STATIC_SPEC{ "md_exec_prefix" , ( ( void * ) 0 ) , & md_exec_prefix , ( struct spec_list * ) 0 , sizeof ( "md_exec_prefix" ) - 1 , 0 } ("md_exec_prefix", &md_exec_prefix), |
1642 | INIT_STATIC_SPEC{ "md_startfile_prefix" , ( ( void * ) 0 ) , & md_startfile_prefix , ( struct spec_list * ) 0 , sizeof ( "md_startfile_prefix" ) - 1 , 0 } ("md_startfile_prefix", &md_startfile_prefix), |
1643 | INIT_STATIC_SPEC{ "md_startfile_prefix_1" , ( ( void * ) 0 ) , & md_startfile_prefix_1 , ( struct spec_list * ) 0 , sizeof ( "md_startfile_prefix_1" ) - 1 , 0 } ("md_startfile_prefix_1", &md_startfile_prefix_1), |
1644 | INIT_STATIC_SPEC{ "startfile_prefix_spec" , ( ( void * ) 0 ) , & startfile_prefix_spec , ( struct spec_list * ) 0 , sizeof ( "startfile_prefix_spec" ) - 1 , 0 } ("startfile_prefix_spec", &startfile_prefix_spec), |
1645 | INIT_STATIC_SPEC{ "sysroot_spec" , ( ( void * ) 0 ) , & sysroot_spec , ( struct spec_list * ) 0 , sizeof ( "sysroot_spec" ) - 1 , 0 } ("sysroot_spec", &sysroot_spec), |
1646 | INIT_STATIC_SPEC{ "sysroot_suffix_spec" , ( ( void * ) 0 ) , & sysroot_suffix_spec , ( struct spec_list * ) 0 , sizeof ( "sysroot_suffix_spec" ) - 1 , 0 } ("sysroot_suffix_spec", &sysroot_suffix_spec), |
1647 | INIT_STATIC_SPEC{ "sysroot_hdrs_suffix_spec" , ( ( void * ) 0 ) , & sysroot_hdrs_suffix_spec , ( struct spec_list * ) 0 , sizeof ( "sysroot_hdrs_suffix_spec" ) - 1 , 0 } ("sysroot_hdrs_suffix_spec", &sysroot_hdrs_suffix_spec), |
1648 | }; |
1649 | |
1650 | #ifdef EXTRA_SPECS /* additional specs needed */ |
1651 | /* Structure to keep track of just the first two args of a spec_list. |
1652 | That is all that the EXTRA_SPECS macro gives us. */ |
1653 | struct spec_list_1 |
1654 | { |
1655 | const char *const name; |
1656 | const char *const ptr; |
1657 | }; |
1658 | |
1659 | static const struct spec_list_1 extra_specs_1[] = { EXTRA_SPECS{ "cc1_cpu" , "%{!mtune*: %{m386:mtune=i386 %n`-m386' is deprecated. Use `-march=i386' or `-mtune=i386' instead.\n} %{m486:-mtune=i486 %n`-m486' is deprecated. Use `-march=i486' or `-mtune=i486' instead.\n} %{mpentium:-mtune=pentium %n`-mpentium' is deprecated. Use `-march=pentium' or `-mtune=pentium' instead.\n} %{mpentiumpro:-mtune=pentiumpro %n`-mpentiumpro' is deprecated. Use `-march=pentiumpro' or `-mtune=pentiumpro' instead.\n} %{mcpu=*:-mtune=%* %n`-mcpu=' is deprecated. Use `-mtune=' or '-march=' instead.\n}} % } , { "darwin_dylib1" , "%:version-compare(!> 10.5 mmacosx-version-min= -ldylib1.o) %:version-compare(>= 10.5 mmacosx-version-min= -ldylib1.10.5.o)" } , { "darwin_minversion" , "%{!m64|fgnu-runtime:10.4; ,objective-c|,objc-cpp-output:10.5; ,objective-c-header:10.5; ,objective-c++|,objective-c++-cpp-output:10.5; ,objective-c++-header|,objc++-cpp-output:10.5; :10.4}" } , { "darwin_dsymutil" , "%{g*:%{!gstabs*:%{!g0: dsymutil %{o*:%*}%{!o:a.out}}}}" } , { "darwin_arch" , "%{m64:x86_64;:i386}" } , { "darwin_crt2" , "" } , { "darwin_subarch" , "%{m64:x86_64;:i386}" } , |
1660 | static struct spec_list *extra_specs = (struct spec_list *) 0; |
1661 | #endif |
1662 | |
1663 | /* List of dynamically allocates specs that have been defined so far. */ |
1664 | |
1665 | static struct spec_list *specs = (struct spec_list *) 0; |
1666 | |
1667 | /* List of static spec functions. */ |
1668 | |
1669 | static const struct spec_function static_spec_functions[] = |
1670 | { |
1671 | { "if-exists", if_exists_spec_function }, |
1672 | { "if-exists-else", if_exists_else_spec_function }, |
1673 | { "replace-outfile", replace_outfile_spec_function }, |
1674 | { "version-compare", version_compare_spec_function }, |
1675 | { "include", include_spec_function }, |
1676 | #ifdef EXTRA_SPEC_FUNCTIONS |
1677 | EXTRA_SPEC_FUNCTIONS{ "local_cpu_detect" , host_detect_local_cpu } , |
1678 | #endif |
1679 | { 0, 0 } |
1680 | }; |
1681 | |
1682 | static int processing_spec_function; |
1683 | |
1684 | /* Add appropriate libgcc specs to OBSTACK, taking into account |
1685 | various permutations of -shared-libgcc, -shared, and such. */ |
1686 | |
1687 | #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC) |
1688 | |
1689 | #ifndef USE_LD_AS_NEEDED |
1690 | #define USE_LD_AS_NEEDED 0 |
1691 | #endif |
1692 | |
1693 | static void |
1694 | init_gcc_specs (struct obstack *obstack, const char *shared_name, |
1695 | const char *static_name, const char *eh_name) |
1696 | { |
1697 | char *buf; |
1698 | |
1699 | buf = concat ("%{static|static-libgcc:", static_name, " ", eh_name, "}" |
1700 | "%{!static:%{!static-libgcc:" |
1701 | #if USE_LD_AS_NEEDED |
1702 | "%{!shared-libgcc:", |
1703 | static_name, " --as-needed ", shared_name, " --no-as-needed" |
1704 | "}" |
1705 | "%{shared-libgcc:", |
1706 | shared_name, "%{!shared: ", static_name, "}" |
1707 | "}" |
1708 | #else |
1709 | "%{!shared:" |
1710 | "%{!shared-libgcc:", static_name, " ", eh_name, "}" |
1711 | "%{shared-libgcc:", shared_name, " ", static_name, "}" |
1712 | "}" |
1713 | #ifdef LINK_EH_SPEC |
1714 | "%{shared:" |
1715 | "%{shared-libgcc:", shared_name, "}" |
1716 | "%{!shared-libgcc:", static_name, "}" |
1717 | "}" |
1718 | #else |
1719 | "%{shared:", shared_name, "}" |
1720 | #endif |
1721 | #endif |
1722 | "}}", NULL); |
1723 | |
1724 | obstack_grow (obstack, buf, strlen (buf)); |
1725 | free (buf); |
1726 | } |
1727 | #endif /* ENABLE_SHARED_LIBGCC */ |
1728 | |
1729 | /* Initialize the specs lookup routines. */ |
1730 | |
1731 | static void |
1732 | init_spec (void) |
1733 | { |
1734 | struct spec_list *next = (struct spec_list *) 0; |
1735 | struct spec_list *sl = (struct spec_list *) 0; |
1736 | int i; |
1737 | |
1738 | if (specs) |
1739 | return; /* Already initialized. */ |
1740 | |
1741 | if (verbose_flag) |
1742 | notice ("Using built-in specs.\n"); |
1743 | |
1744 | #ifdef EXTRA_SPECS |
1745 | extra_specs = xcalloc (sizeof (struct spec_list), |
1746 | ARRAY_SIZE( sizeof ( extra_specs_1 ) / sizeof ( ( extra_specs_1 ) [ 0 ] ) ) (extra_specs_1)); |
1747 | |
1748 | for (i = ARRAY_SIZE( sizeof ( extra_specs_1 ) / sizeof ( ( extra_specs_1 ) [ 0 ] ) ) (extra_specs_1) - 1; i >= 0; i--) |
1749 | { |
1750 | sl = &extra_specs[i]; |
1751 | sl->name = extra_specs_1[i].name; |
1752 | sl->ptr = extra_specs_1[i].ptr; |
1753 | sl->next = next; |
1754 | sl->name_len = strlen (sl->name); |
1755 | sl->ptr_spec = &sl->ptr; |
1756 | next = sl; |
1757 | } |
1758 | #endif |
1759 | |
1760 | /* Initialize here, not in definition. The IRIX 6 O32 cc sometimes chokes |
1761 | on ?: in file-scope variable initializations. */ |
1762 | asm_debug = ASM_DEBUG_SPEC"%{g*:--gstabs}"; |
1763 | |
1764 | for (i = ARRAY_SIZE( sizeof ( static_specs ) / sizeof ( ( static_specs ) [ 0 ] ) ) (static_specs) - 1; i >= 0; i--) |
1765 | { |
1766 | sl = &static_specs[i]; |
1767 | sl->next = next; |
1768 | next = sl; |
1769 | } |
1770 | |
1771 | #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC) |
1772 | /* ??? If neither -shared-libgcc nor --static-libgcc was |
1773 | seen, then we should be making an educated guess. Some proposed |
1774 | heuristics for ELF include: |
1775 | |
1776 | (1) If "-Wl,--export-dynamic", then it's a fair bet that the |
1777 | program will be doing dynamic loading, which will likely |
1778 | need the shared libgcc. |
1779 | |
1780 | (2) If "-ldl", then it's also a fair bet that we're doing |
1781 | dynamic loading. |
1782 | |
1783 | (3) For each ET_DYN we're linking against (either through -lfoo |
1784 | or /some/path/foo.so), check to see whether it or one of |
1785 | its dependencies depends on a shared libgcc. |
1786 | |
1787 | (4) If "-shared" |
1788 | |
1789 | If the runtime is fixed to look for program headers instead |
1790 | of calling __register_frame_info at all, for each object, |
1791 | use the shared libgcc if any EH symbol referenced. |
1792 | |
1793 | If crtstuff is fixed to not invoke __register_frame_info |
1794 | automatically, for each object, use the shared libgcc if |
1795 | any non-empty unwind section found. |
1796 | |
1797 | Doing any of this probably requires invoking an external program to |
1798 | do the actual object file scanning. */ |
1799 | { |
1800 | const char *p = libgcc_spec; |
1801 | int in_sep = 1; |
1802 | |
1803 | /* Transform the extant libgcc_spec into one that uses the shared libgcc |
1804 | when given the proper command line arguments. */ |
1805 | while (*p) |
1806 | { |
1807 | if (in_sep && *p == '-' && strncmp (p, "-lgcc", 5) == 0) |
1808 | { |
1809 | init_gcc_specs (&obstack, |
1810 | "-lgcc_s" |
1811 | #ifdef USE_LIBUNWIND_EXCEPTIONS |
1812 | " -lunwind" |
1813 | #endif |
1814 | , |
1815 | "-lgcc", |
1816 | "-lgcc_eh" |
1817 | #ifdef USE_LIBUNWIND_EXCEPTIONS |
1818 | # ifdef HAVE_LD_STATIC_DYNAMIC |
1819 | " %{!static:-Bstatic} -lunwind %{!static:-Bdynamic}" |
1820 | # else |
1821 | " -lunwind" |
1822 | # endif |
1823 | #endif |
1824 | ); |
1825 | |
1826 | p += 5; |
1827 | in_sep = 0; |
1828 | } |
1829 | else if (in_sep && *p == 'l' && strncmp (p, "libgcc.a%s", 10) == 0) |
1830 | { |
1831 | /* Ug. We don't know shared library extensions. Hope that |
1832 | systems that use this form don't do shared libraries. */ |
1833 | init_gcc_specs (&obstack, |
1834 | "-lgcc_s", |
1835 | "libgcc.a%s", |
1836 | "libgcc_eh.a%s" |
1837 | #ifdef USE_LIBUNWIND_EXCEPTIONS |
1838 | " -lunwind" |
1839 | #endif |
1840 | ); |
1841 | p += 10; |
1842 | in_sep = 0; |
1843 | } |
1844 | else |
1845 | { |
1846 | obstack_1grow (&obstack, *p); |
1847 | in_sep = (*p == ' '); |
1848 | p += 1; |
1849 | } |
1850 | } |
1851 | |
1852 | obstack_1grow (&obstack, '\0'); |
1853 | libgcc_spec = XOBFINISH (&obstack, const char *); |
1854 | } |
1855 | #endif |
1856 | #ifdef USE_AS_TRADITIONAL_FORMAT |
1857 | /* Prepend "--traditional-format" to whatever asm_spec we had before. */ |
1858 | { |
1859 | static const char tf[] = "--traditional-format "; |
1860 | obstack_grow (&obstack, tf, sizeof(tf) - 1); |
1861 | obstack_grow0 (&obstack, asm_spec, strlen (asm_spec)); |
1862 | asm_spec = XOBFINISH (&obstack, const char *); |
1863 | } |
1864 | #endif |
1865 | #ifdef LINK_EH_SPEC |
1866 | /* Prepend LINK_EH_SPEC to whatever link_spec we had before. */ |
1867 | obstack_grow (&obstack, LINK_EH_SPEC, sizeof(LINK_EH_SPEC) - 1); |
1868 | obstack_grow0 (&obstack, link_spec, strlen (link_spec)); |
1869 | link_spec = XOBFINISH (&obstack, const char *); |
1870 | #endif |
1871 | |
1872 | specs = sl; |
1873 | } |
1874 | |
1875 | /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is |
1876 | removed; If the spec starts with a + then SPEC is added to the end of the |
1877 | current spec. */ |
1878 | |
1879 | static void |
1880 | set_spec (const char *name, const char *spec) |
1881 | { |
1882 | struct spec_list *sl; |
1883 | const char *old_spec; |
1884 | int name_len = strlen (name); |
1885 | int i; |
1886 | |
1887 | /* If this is the first call, initialize the statically allocated specs. */ |
1888 | if (!specs) |
1889 | { |
1890 | struct spec_list *next = (struct spec_list *) 0; |
1891 | for (i = ARRAY_SIZE( sizeof ( static_specs ) / sizeof ( ( static_specs ) [ 0 ] ) ) (static_specs) - 1; i >= 0; i--) |
1892 | { |
1893 | sl = &static_specs[i]; |
1894 | sl->next = next; |
1895 | next = sl; |
1896 | } |
1897 | specs = sl; |
1898 | } |
1899 | |
1900 | /* See if the spec already exists. */ |
1901 | for (sl = specs; sl; sl = sl->next) |
1902 | if (name_len == sl->name_len && !strcmp (sl->name, name)) |
1903 | break; |
1904 | |
1905 | if (!sl) |
1906 | { |
1907 | /* Not found - make it. */ |
1908 | sl = XNEW( ( struct spec_list * ) xmalloc ( sizeof ( struct spec_list ) ) ) (struct spec_list); |
1909 | sl->name = xstrdup (name); |
1910 | sl->name_len = name_len; |
1911 | sl->ptr_spec = &sl->ptr; |
1912 | sl->alloc_p = 0; |
1913 | *(sl->ptr_spec) = ""; |
1914 | sl->next = specs; |
1915 | specs = sl; |
1916 | } |
1917 | |
1918 | old_spec = *(sl->ptr_spec); |
1919 | *(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE( _sch_istable [ ( ( unsigned char ) spec [ 1 ] ) & 0xff ] & ( unsigned short ) ( _sch_isspace ) ) ((unsigned char)spec[1])) |
1920 | ? concat (old_spec, spec + 1, NULL( ( void * ) 0 )) |
1921 | : xstrdup (spec)); |
1922 | |
1923 | #ifdef DEBUG_SPECS |
1924 | if (verbose_flag) |
1925 | notice ("Setting spec %s to '%s'\n\n", name, *(sl->ptr_spec)); |
1926 | #endif |
1927 | |
1928 | /* Free the old spec. */ |
1929 | if (old_spec && sl->alloc_p) |
1930 | free ((void *) old_spec); |
1931 | |
1932 | sl->alloc_p = 1; |
1933 | } |
1934 | |
1935 | /* Accumulate a command (program name and args), and run it. */ |
1936 | |
1937 | /* Vector of pointers to arguments in the current line of specifications. */ |
1938 | |
1939 | static const char **argbuf; |
1940 | |
1941 | /* Number of elements allocated in argbuf. */ |
1942 | |
1943 | static int argbuf_length; |
1944 | |
1945 | /* Number of elements in argbuf currently in use (containing args). */ |
1946 | |
1947 | static int argbuf_index; |
1948 | |
1949 | /* Position in the argbuf array containing the name of the output file |
1950 | (the value associated with the "-o" flag). */ |
1951 | |
1952 | static int have_o_argbuf_index = 0; |
1953 | |
1954 | /* Were the options -c or -S passed. */ |
1955 | static int have_c = 0; |
1956 | |
1957 | /* Was the option -o passed. */ |
1958 | static int have_o = 0; |
1959 | |
1960 | /* This is the list of suffixes and codes (%g/%u/%U/%j) and the associated |
1961 | temp file. If the HOST_BIT_BUCKET is used for %j, no entry is made for |
1962 | it here. */ |
1963 | |
1964 | static struct temp_name { |
1965 | const char *suffix; /* suffix associated with the code. */ |
1966 | int length; /* strlen (suffix). */ |
1967 | int unique; /* Indicates whether %g or %u/%U was used. */ |
1968 | const char *filename; /* associated filename. */ |
1969 | int filename_length; /* strlen (filename). */ |
1970 | struct temp_name *next; |
1971 | } *temp_names; |
1972 | |
1973 | /* Number of commands executed so far. */ |
1974 | |
1975 | static int execution_count; |
1976 | |
1977 | /* Number of commands that exited with a signal. */ |
1978 | |
1979 | static int signal_count; |
1980 | |
1981 | /* Name with which this program was invoked. */ |
1982 | |
1983 | static const char *programname; |
1984 | |
1985 | /* Allocate the argument vector. */ |
1986 | |
1987 | static void |
1988 | alloc_args (void) |
1989 | { |
1990 | argbuf_length = 10; |
1991 | argbuf = XNEWVEC( ( const char * * ) xmalloc ( sizeof ( const char * ) * ( argbuf_length ) ) ) (const char *, argbuf_length); |
1992 | } |
1993 | |
1994 | /* Clear out the vector of arguments (after a command is executed). */ |
1995 | |
1996 | static void |
1997 | clear_args (void) |
1998 | { |
1999 | argbuf_index = 0; |
2000 | } |
2001 | |
2002 | /* Add one argument to the vector at the end. |
2003 | This is done when a space is seen or at the end of the line. |
2004 | If DELETE_ALWAYS is nonzero, the arg is a filename |
2005 | and the file should be deleted eventually. |
2006 | If DELETE_FAILURE is nonzero, the arg is a filename |
2007 | and the file should be deleted if this compilation fails. */ |
2008 | |
2009 | static void |
2010 | store_arg (const char *arg, int delete_always, int delete_failure) |
2011 | { |
2012 | if (argbuf_index + 1 == argbuf_length) |
2013 | argbuf = xrealloc (argbuf, (argbuf_length *= 2) * sizeof (const char *)); |
2014 | |
2015 | argbuf[argbuf_index++] = arg; |
2016 | argbuf[argbuf_index] = 0; |
2017 | |
2018 | if (strcmp (arg, "-o") == 0) |
2019 | have_o_argbuf_index = argbuf_index; |
2020 | if (delete_always || delete_failure) |
2021 | record_temp_file (arg, delete_always, delete_failure); |
2022 | } |
2023 | |
2024 | /* Load specs from a file name named FILENAME, replacing occurrences of |
2025 | various different types of line-endings, \r\n, \n\r and just \r, with |
2026 | a single \n. */ |
2027 | |
2028 | static char * |
2029 | load_specs (const char *filename) |
2030 | { |
2031 | int desc; |
2032 | int readlen; |
2033 | struct stat statbuf; |
2034 | char *buffer; |
2035 | char *buffer_p; |
2036 | char *specs; |
2037 | char *specs_p; |
2038 | |
2039 | if (verbose_flag) |
2040 | notice ("Reading specs from %s\n", filename); |
2041 | |
2042 | /* Open and stat the file. */ |
2043 | desc = open (filename, O_RDONLY0x0000, 0); |
2044 | if (desc < 0) |
2045 | pfatal_with_name (filename); |
2046 | if (stat (filename, &statbuf) < 0) |
2047 | pfatal_with_name (filename); |
2048 | |
2049 | /* Read contents of file into BUFFER. */ |
2050 | buffer = XNEWVEC( ( char * ) xmalloc ( sizeof ( char ) * ( statbuf . st_size + 1 ) ) ) (char, statbuf.st_size + 1); |
2051 | readlen = read (desc, buffer, (unsigned) statbuf.st_size); |
2052 | if (readlen < 0) |
2053 | pfatal_with_name (filename); |
2054 | buffer[readlen] = 0; |
2055 | close (desc); |
2056 | |
2057 | specs = XNEWVEC( ( char * ) xmalloc ( sizeof ( char ) * ( readlen + 1 ) ) ) (char, readlen + 1); |
2058 | specs_p = specs; |
2059 | for (buffer_p = buffer; buffer_p && *buffer_p; buffer_p++) |
2060 | { |
2061 | int skip = 0; |
2062 | char c = *buffer_p; |
2063 | if (c == '\r') |
2064 | { |
2065 | if (buffer_p > buffer && *(buffer_p - 1) == '\n') /* \n\r */ |
2066 | skip = 1; |
2067 | else if (*(buffer_p + 1) == '\n') /* \r\n */ |
2068 | skip = 1; |
2069 | else /* \r */ |
2070 | c = '\n'; |
2071 | } |
2072 | if (! skip) |
2073 | *specs_p++ = c; |
2074 | } |
2075 | *specs_p = '\0'; |
2076 | |
2077 | free (buffer); |
2078 | return (specs); |
2079 | } |
2080 | |
2081 | /* Read compilation specs from a file named FILENAME, |
2082 | replacing the default ones. |
2083 | |
2084 | A suffix which starts with `*' is a definition for |
2085 | one of the machine-specific sub-specs. The "suffix" should be |
2086 | *asm, *cc1, *cpp, *link, *startfile, etc. |
2087 | The corresponding spec is stored in asm_spec, etc., |
2088 | rather than in the `compilers' vector. |
2089 | |
2090 | Anything invalid in the file is a fatal error. */ |
2091 | |
2092 | static void |
2093 | read_specs (const char *filename, int main_p) |
2094 | { |
2095 | char *buffer; |
2096 | char *p; |
2097 | |
2098 | buffer = load_specs (filename); |
2099 | |
2100 | /* Scan BUFFER for specs, putting them in the vector. */ |
2101 | p = buffer; |
2102 | while (1) |
2103 | { |
2104 | char *suffix; |
2105 | char *spec; |
2106 | char *in, *out, *p1, *p2, *p3; |
2107 | |
2108 | /* Advance P in BUFFER to the next nonblank nocomment line. */ |
2109 | p = skip_whitespace (p); |
2110 | if (*p == 0) |
2111 | break; |
2112 | |
2113 | /* Is this a special command that starts with '%'? */ |
2114 | /* Don't allow this for the main specs file, since it would |
2115 | encourage people to overwrite it. */ |
2116 | if (*p == '%' && !main_p) |
2117 | { |
2118 | p1 = p; |
2119 | while (*p && *p != '\n') |
2120 | p++; |
2121 | |
2122 | /* Skip '\n'. */ |
2123 | p++; |
2124 | |
2125 | if (!strncmp (p1, "%include", sizeof ("%include") - 1) |
2126 | && (p1[sizeof "%include" - 1] == ' ' |
2127 | || p1[sizeof "%include" - 1] == '\t')) |
2128 | { |
2129 | char *new_filename; |
2130 | |
2131 | p1 += sizeof ("%include"); |
2132 | while (*p1 == ' ' || *p1 == '\t') |
2133 | p1++; |
2134 | |
2135 | if (*p1++ != '<' || p[-2] != '>') |
2136 | fatal ("specs %%include syntax malformed after %ld characters", |
2137 | (long) (p1 - buffer + 1)); |
2138 | |
2139 | p[-2] = '\0'; |
2140 | new_filename = find_a_file (&startfile_prefixes, p1, R_OK( 1 << 2 ), true1); |
2141 | read_specs (new_filename ? new_filename : p1, FALSE0); |
2142 | continue; |
2143 | } |
2144 | else if (!strncmp (p1, "%include_noerr", sizeof "%include_noerr" - 1) |
2145 | && (p1[sizeof "%include_noerr" - 1] == ' ' |
2146 | || p1[sizeof "%include_noerr" - 1] == '\t')) |
2147 | { |
2148 | char *new_filename; |
2149 | |
2150 | p1 += sizeof "%include_noerr"; |
2151 | while (*p1 == ' ' || *p1 == '\t') |
2152 | p1++; |
2153 | |
2154 | if (*p1++ != '<' || p[-2] != '>') |
2155 | fatal ("specs %%include syntax malformed after %ld characters", |
2156 | (long) (p1 - buffer + 1)); |
2157 | |
2158 | p[-2] = '\0'; |
2159 | new_filename = find_a_file (&startfile_prefixes, p1, R_OK( 1 << 2 ), true1); |
2160 | if (new_filename) |
2161 | read_specs (new_filename, FALSE0); |
2162 | else if (verbose_flag) |
2163 | notice ("could not find specs file %s\n", p1); |
2164 | continue; |
2165 | } |
2166 | else if (!strncmp (p1, "%rename", sizeof "%rename" - 1) |
2167 | && (p1[sizeof "%rename" - 1] == ' ' |
2168 | || p1[sizeof "%rename" - 1] == '\t')) |
2169 | { |
2170 | int name_len; |
2171 | struct spec_list *sl; |
2172 | struct spec_list *newsl; |
2173 | |
2174 | /* Get original name. */ |
2175 | p1 += sizeof "%rename"; |
2176 | while (*p1 == ' ' || *p1 == '\t') |
2177 | p1++; |
2178 | |
2179 | if (! ISALPHA( _sch_istable [ ( ( unsigned char ) * p1 ) & 0xff ] & ( unsigned short ) ( _sch_isalpha ) ) ((unsigned char) *p1)) |
2180 | fatal ("specs %%rename syntax malformed after %ld characters", |
2181 | (long) (p1 - buffer)); |
2182 | |
2183 | p2 = p1; |
2184 | while (*p2 && !ISSPACE( _sch_istable [ ( ( unsigned char ) * p2 ) & 0xff ] & ( unsigned short ) ( _sch_isspace ) ) ((unsigned char) *p2)) |
2185 | p2++; |
2186 | |
2187 | if (*p2 != ' ' && *p2 != '\t') |
2188 | fatal ("specs %%rename syntax malformed after %ld characters", |
2189 | (long) (p2 - buffer)); |
2190 | |
2191 | name_len = p2 - p1; |
2192 | *p2++ = '\0'; |
2193 | while (*p2 == ' ' || *p2 == '\t') |
2194 | p2++; |
2195 | |
2196 | if (! ISALPHA( _sch_istable [ ( ( unsigned char ) * p2 ) & 0xff ] & ( unsigned short ) ( _sch_isalpha ) ) ((unsigned char) *p2)) |
2197 | fatal ("specs %%rename syntax malformed after %ld characters", |
2198 | (long) (p2 - buffer)); |
2199 | |
2200 | /* Get new spec name. */ |
2201 | p3 = p2; |
2202 | while (*p3 && !ISSPACE( _sch_istable [ ( ( unsigned char ) * p3 ) & 0xff ] & ( unsigned short ) ( _sch_isspace ) ) ((unsigned char) *p3)) |
2203 | p3++; |
2204 | |
2205 | if (p3 != p - 1) |
2206 | fatal ("specs %%rename syntax malformed after %ld characters", |
2207 | (long) (p3 - buffer)); |
2208 | *p3 = '\0'; |
2209 | |
2210 | for (sl = specs; sl; sl = sl->next) |
2211 | if (name_len == sl->name_len && !strcmp (sl->name, p1)) |
2212 | break; |
2213 | |
2214 | if (!sl) |
2215 | fatal ("specs %s spec was not found to be renamed", p1); |
2216 | |
2217 | if (strcmp (p1, p2) == 0) |
2218 | continue; |
2219 | |
2220 | for (newsl = specs; newsl; newsl = newsl->next) |
2221 | if (strcmp (newsl->name, p2) == 0) |
2222 | fatal ("%s: attempt to rename spec '%s' to already defined spec '%s'", |
2223 | filename, p1, p2); |
2224 | |
2225 | if (verbose_flag) |
2226 | { |
2227 | notice ("rename spec %s to %s\n", p1, p2); |
2228 | #ifdef DEBUG_SPECS |
2229 | notice ("spec is '%s'\n\n", *(sl->ptr_spec)); |
2230 | #endif |
2231 | } |
2232 | |
2233 | set_spec (p2, *(sl->ptr_spec)); |
2234 | if (sl->alloc_p) |
2235 | free ((void *) *(sl->ptr_spec)); |
2236 | |
2237 | *(sl->ptr_spec) = ""; |
2238 | sl->alloc_p = 0; |
2239 | continue; |
2240 | } |
2241 | else |
2242 | fatal ("specs unknown %% command after %ld characters", |
2243 | (long) (p1 - buffer)); |
2244 | } |
2245 | |
2246 | /* Find the colon that should end the suffix. */ |
2247 | p1 = p; |
2248 | while (*p1 && *p1 != ':' && *p1 != '\n') |
2249 | p1++; |
2250 | |
2251 | /* The colon shouldn't be missing. */ |
2252 | if (*p1 != ':') |
2253 | fatal ("specs file malformed after %ld characters", |
2254 | (long) (p1 - buffer)); |
2255 | |
2256 | /* Skip back over trailing whitespace. */ |
2257 | p2 = p1; |
2258 | while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t')) |
2259 | p2--; |
2260 | |
2261 | /* Copy the suffix to a string. */ |
2262 | suffix = save_string (p, p2 - p); |
2263 | /* Find the next line. */ |
2264 | p = skip_whitespace (p1 + 1); |
2265 | if (p[1] == 0) |
2266 | fatal ("specs file malformed after %ld characters", |
2267 | (long) (p - buffer)); |
2268 | |
2269 | p1 = p; |
2270 | /* Find next blank line or end of string. */ |
2271 | while (*p1 && !(*p1 == '\n' && (p1[1] == '\n' || p1[1] == '\0'))) |
2272 | p1++; |
2273 | |
2274 | /* Specs end at the blank line and do not include the newline. */ |
2275 | spec = save_string (p, p1 - p); |
2276 | p = p1; |
2277 | |
2278 | /* Delete backslash-newline sequences from the spec. */ |
2279 | in = spec; |
2280 | out = spec; |
2281 | while (*in != 0) |
2282 | { |
2283 | if (in[0] == '\\' && in[1] == '\n') |
2284 | in += 2; |
2285 | else if (in[0] == '#') |
2286 | while (*in && *in != '\n') |
2287 | in++; |
2288 | |
2289 | else |
2290 | *out++ = *in++; |
2291 | } |
2292 | *out = 0; |
2293 | |
2294 | if (suffix[0] == '*') |
2295 | { |
2296 | if (! strcmp (suffix, "*link_command")) |
2297 | link_command_spec = spec; |
2298 | else |
2299 | set_spec (suffix + 1, spec); |
2300 | } |
2301 | else |
2302 | { |
2303 | /* Add this pair to the vector. */ |
2304 | compilers |
2305 | = xrealloc (compilers, |
2306 | (n_compilers + 2) * sizeof (struct compiler)); |
2307 | |
2308 | compilers[n_compilers].suffix = suffix; |
2309 | compilers[n_compilers].spec = spec; |
2310 | n_compilers++; |
2311 | memset (&compilers[n_compilers], 0, sizeof compilers[n_compilers]); |
2312 | } |
2313 | |
2314 | if (*suffix == 0) |
2315 | link_command_spec = spec; |
2316 | } |
2317 | |
2318 | if (link_command_spec == 0) |
2319 | fatal ("spec file has no spec for linking"); |
2320 | } |
2321 | |
2322 | /* Record the names of temporary files we tell compilers to write, |
2323 | and delete them at the end of the run. */ |
2324 | |
2325 | /* This is the common prefix we use to make temp file names. |
2326 | It is chosen once for each run of this program. |
2327 | It is substituted into a spec by %g or %j. |
2328 | Thus, all temp file names contain this prefix. |
2329 | In practice, all temp file names start with this prefix. |
2330 | |
2331 | This prefix comes from the envvar TMPDIR if it is defined; |
2332 | otherwise, from the P_tmpdir macro if that is defined; |
2333 | otherwise, in /usr/tmp or /tmp; |
2334 | or finally the current directory if all else fails. */ |
2335 | |
2336 | static const char *temp_filename; |
2337 | |
2338 | /* Length of the prefix. */ |
2339 | |
2340 | static int temp_filename_length; |
2341 | |
2342 | /* Define the list of temporary files to delete. */ |
2343 | |
2344 | struct temp_file |
2345 | { |
2346 | const char *name; |
2347 | struct temp_file *next; |
2348 | }; |
2349 | |
2350 | /* Queue of files to delete on success or failure of compilation. */ |
2351 | static struct temp_file *always_delete_queue; |
2352 | /* Queue of files to delete on failure of compilation. */ |
2353 | static struct temp_file *failure_delete_queue; |
2354 | |
2355 | /* Record FILENAME as a file to be deleted automatically. |
2356 | ALWAYS_DELETE nonzero means delete it if all compilation succeeds; |
2357 | otherwise delete it in any case. |
2358 | FAIL_DELETE nonzero means delete it if a compilation step fails; |
2359 | otherwise delete it in any case. */ |
2360 | |
2361 | void |
2362 | record_temp_file (const char *filename, int always_delete, int fail_delete) |
2363 | { |
2364 | char *const name = xstrdup (filename); |
2365 | |
2366 | if (always_delete) |
2367 | { |
2368 | struct temp_file *temp; |
2369 | for (temp = always_delete_queue; temp; temp = temp->next) |
2370 | if (! strcmp (name, temp->name)) |
2371 | goto already1; |
2372 | |
2373 | temp = XNEW( ( struct temp_file * ) xmalloc ( sizeof ( struct temp_file ) ) ) (struct temp_file); |
2374 | temp->next = always_delete_queue; |
2375 | temp->name = name; |
2376 | always_delete_queue = temp; |
2377 | |
2378 | already1:; |
2379 | } |
2380 | |
2381 | if (fail_delete) |
2382 | { |
2383 | struct temp_file *temp; |
2384 | for (temp = failure_delete_queue; temp; temp = temp->next) |
2385 | if (! strcmp (name, temp->name)) |
2386 | goto already2; |
2387 | |
2388 | temp = XNEW( ( struct temp_file * ) xmalloc ( sizeof ( struct temp_file ) ) ) (struct temp_file); |
2389 | temp->next = failure_delete_queue; |
2390 | temp->name = name; |
2391 | failure_delete_queue = temp; |
2392 | |
2393 | already2:; |
2394 | } |
2395 | } |
2396 | |
2397 | /* Delete all the temporary files whose names we previously recorded. */ |
2398 | |
2399 | #ifndef DELETE_IF_ORDINARY |
2400 | #define DELETE_IF_ORDINARY(NAME,ST,VERBOSE_FLAG) \ |
2401 | do \ |
2402 | { \ |
2403 | if (stat (NAME, &ST) >= 0 && S_ISREG (ST.st_mode)) \ |
2404 | if (unlink (NAME) < 0) \ |
2405 | if (VERBOSE_FLAG) \ |
2406 | perror_with_name (NAME); \ |
2407 | } while (0) |
2408 | #endif |
2409 | |
2410 | static void |
2411 | delete_if_ordinary (const char *name) |
2412 | { |
2413 | struct stat st; |
2414 | #ifdef DEBUG |
2415 | int i, c; |
2416 | |
2417 | printf ("Delete %s? (y or n) ", name); |
2418 | fflush (stdout); |
2419 | i = getchar (); |
2420 | if (i != '\n') |
2421 | while ((c = getchar ()) != '\n' && c != EOF) |
2422 | ; |
2423 | |
2424 | if (i == 'y' || i == 'Y') |
2425 | #endif /* DEBUG */ |
2426 | DELETE_IF_ORDINARYdo { if ( stat ( name , & st ) >= 0 && ( ( ( st . st_mode ) & 0170000 ) == 0100000 ) ) if ( unlink ( name ) < 0 ) if ( verbose_flag ) perror_with_name ( name ) ; } while ( 0 ) (name, st, verbose_flag); |
2427 | } |
2428 | |
2429 | static void |
2430 | delete_temp_files (void) |
2431 | { |
2432 | struct temp_file *temp; |
2433 | |
2434 | for (temp = always_delete_queue; temp; temp = temp->next) |
2435 | delete_if_ordinary (temp->name); |
2436 | always_delete_queue = 0; |
2437 | } |
2438 | |
2439 | /* Delete all the files to be deleted on error. */ |
2440 | |
2441 | static void |
2442 | delete_failure_queue (void) |
2443 | { |
2444 | struct temp_file *temp; |
2445 | |
2446 | for (temp = failure_delete_queue; temp; temp = temp->next) |
2447 | delete_if_ordinary (temp->name); |
2448 | } |
2449 | |
2450 | static void |
2451 | clear_failure_queue (void) |
2452 | { |
2453 | failure_delete_queue = 0; |
2454 | } |
2455 | |
2456 | /* Call CALLBACK for each path in PATHS, breaking out early if CALLBACK |
2457 | returns non-NULL. |
2458 | If DO_MULTI is true iterate over the paths twice, first with multilib |
2459 | suffix then without, otherwise iterate over the paths once without |
2460 | adding a multilib suffix. When DO_MULTI is true, some attempt is made |
2461 | to avoid visiting the same path twice, but we could do better. For |
2462 | instance, /usr/lib/../lib is considered different from /usr/lib. |
2463 | At least EXTRA_SPACE chars past the end of the path passed to |
2464 | CALLBACK are available for use by the callback. |
2465 | CALLBACK_INFO allows extra parameters to be passed to CALLBACK. |
2466 | |
2467 | Returns the value returned by CALLBACK. */ |
2468 | |
2469 | static void * |
2470 | for_each_path (const struct path_prefix *paths, |
2471 | bool_Bool do_multi, |
2472 | size_t extra_space, |
2473 | void *(*callback) (char *, void *), |
2474 | void *callback_info) |
2475 | { |
2476 | struct prefix_list *pl; |
2477 | const char *multi_dir = NULL( ( void * ) 0 ); |
2478 | const char *multi_os_dir = NULL( ( void * ) 0 ); |
2479 | const char *multi_suffix; |
2480 | const char *just_multi_suffix; |
2481 | char *path = NULL( ( void * ) 0 ); |
2482 | void *ret = NULL( ( void * ) 0 ); |
2483 | bool_Bool skip_multi_dir = false0; |
2484 | bool_Bool skip_multi_os_dir = false0; |
2485 | |
2486 | multi_suffix = machine_suffix; |
2487 | just_multi_suffix = just_machine_suffix; |
2488 | if (do_multi && multilib_dir && strcmp (multilib_dir, ".") != 0) |
2489 | { |
2490 | multi_dir = concat (multilib_dir, dir_separator_str, NULL( ( void * ) 0 )); |
2491 | multi_suffix = concat (multi_suffix, multi_dir, NULL( ( void * ) 0 )); |
2492 | just_multi_suffix = concat (just_multi_suffix, multi_dir, NULL( ( void * ) 0 )); |
2493 | } |
2494 | if (do_multi && multilib_os_dir && strcmp (multilib_os_dir, ".") != 0) |
2495 | multi_os_dir = concat (multilib_os_dir, dir_separator_str, NULL( ( void * ) 0 )); |
2496 | |
2497 | while (1) |
2498 | { |
2499 | size_t multi_dir_len = 0; |
2500 | size_t multi_os_dir_len = 0; |
2501 | size_t suffix_len; |
2502 | size_t just_suffix_len; |
2503 | size_t len; |
2504 | |
2505 | if (multi_dir) |
2506 | multi_dir_len = strlen (multi_dir); |
2507 | if (multi_os_dir) |
2508 | multi_os_dir_len = strlen (multi_os_dir); |
2509 | suffix_len = strlen (multi_suffix); |
2510 | just_suffix_len = strlen (just_multi_suffix); |
2511 | |
2512 | if (path == NULL( ( void * ) 0 )) |
2513 | { |
2514 | len = paths->max_len + extra_space + 1; |
2515 | if (suffix_len > multi_os_dir_len) |
2516 | len += suffix_len; |
2517 | else |
2518 | len += multi_os_dir_len; |
2519 | path = XNEWVEC( ( char * ) xmalloc ( sizeof ( char ) * ( len ) ) ) (char, len); |
2520 | } |
2521 | |
2522 | for (pl = paths->plist; pl != 0; pl = pl->next) |
2523 | { |
2524 | len = strlen (pl->prefix); |
2525 | memcpy (path, pl->prefix, len); |
2526 | |
2527 | /* Look first in MACHINE/VERSION subdirectory. */ |
2528 | if (!skip_multi_dir) |
2529 | { |
2530 | memcpy (path + len, multi_suffix, suffix_len + 1); |
2531 | ret = callback (path, callback_info); |
2532 | if (ret) |
2533 | break; |
2534 | } |
2535 | |
2536 | /* Some paths are tried with just the machine (ie. target) |
2537 | subdir. This is used for finding as, ld, etc. */ |
2538 | if (!skip_multi_dir |
2539 | && pl->require_machine_suffix == 2) |
2540 | { |
2541 | memcpy (path + len, just_multi_suffix, just_suffix_len + 1); |
2542 | ret = callback (path, callback_info); |
2543 | if (ret) |
2544 | break; |
2545 | } |
2546 | |
2547 | /* Now try the base path. */ |
2548 | if (!pl->require_machine_suffix |
2549 | && !(pl->os_multilib ? skip_multi_os_dir : skip_multi_dir)) |
2550 | { |
2551 | const char *this_multi; |
2552 | size_t this_multi_len; |
2553 | |
2554 | if (pl->os_multilib) |
2555 | { |
2556 | this_multi = multi_os_dir; |
2557 | this_multi_len = multi_os_dir_len; |
2558 | } |
2559 | else |
2560 | { |
2561 | this_multi = multi_dir; |
2562 | this_multi_len = multi_dir_len; |
2563 | } |
2564 | |
2565 | if (this_multi_len) |
2566 | memcpy (path + len, this_multi, this_multi_len + 1); |
2567 | else |
2568 | path[len] = '\0'; |
2569 | |
2570 | ret = callback (path, callback_info); |
2571 | if (ret) |
2572 | break; |
2573 | } |
2574 | } |
2575 | if (pl) |
2576 | break; |
2577 | |
2578 | if (multi_dir == NULL( ( void * ) 0 ) && multi_os_dir == NULL( ( void * ) 0 )) |
2579 | break; |
2580 | |
2581 | /* Run through the paths again, this time without multilibs. |
2582 | Don't repeat any we have already seen. */ |
2583 | if (multi_dir) |
2584 | { |
2585 | free ((char *) multi_dir); |
2586 | multi_dir = NULL( ( void * ) 0 ); |
2587 | free ((char *) multi_suffix); |
2588 | multi_suffix = machine_suffix; |
2589 | free ((char *) just_multi_suffix); |
2590 | just_multi_suffix = just_machine_suffix; |
2591 | } |
2592 | else |
2593 | skip_multi_dir = true1; |
2594 | if (multi_os_dir) |
2595 | { |
2596 | free ((char *) multi_os_dir); |
2597 | multi_os_dir = NULL( ( void * ) 0 ); |
2598 | } |
2599 | else |
2600 | skip_multi_os_dir = true1; |
2601 | } |
2602 | |
2603 | if (multi_dir) |
2604 | { |
2605 | free ((char *) multi_dir); |
2606 | free ((char *) multi_suffix); |
2607 | free ((char *) just_multi_suffix); |
2608 | } |
2609 | if (multi_os_dir) |
2610 | free ((char *) multi_os_dir); |
2611 | if (ret != path) |
2612 | free (path); |
2613 | return ret; |
2614 | } |
2615 | |
2616 | /* Callback for build_search_list. Adds path to obstack being built. */ |
2617 | |
2618 | struct add_to_obstack_info { |
2619 | struct obstack *ob; |
2620 | bool_Bool check_dir; |
2621 | bool_Bool first_time; |
2622 | }; |
2623 | |
2624 | static void * |
2625 | add_to_obstack (char *path, void *data) |
2626 | { |
2627 | struct add_to_obstack_info *info = data; |
2628 | |
2629 | if (info->check_dir && !is_directory (path, false0)) |
2630 | return NULL( ( void * ) 0 ); |
2631 | |
2632 | if (!info->first_time) |
2633 | obstack_1grow__extension__ ( { struct obstack * __o = ( info -> ob ) ; if ( __o -> next_free + 1 > __o -> chunk_limit ) _obstack_newchunk ( __o , 1 ) ; ( * ( ( __o ) -> next_free ) ++ = ( ':' ) ) ; ( void ) 0 ; } ) (info->ob, PATH_SEPARATOR); |
2634 | |
2635 | obstack_grow__extension__ ( { struct obstack * __o = ( info -> ob ) ; int __len = ( strlen ( path ) ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( path ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (info->ob, path, strlen (path)); |
2636 | |
2637 | info->first_time = false0; |
2638 | return NULL( ( void * ) 0 ); |
2639 | } |
2640 | |
2641 | /* Build a list of search directories from PATHS. |
2642 | PREFIX is a string to prepend to the list. |
2643 | If CHECK_DIR_P is true we ensure the directory exists. |
2644 | If DO_MULTI is true, multilib paths are output first, then |
2645 | non-multilib paths. |
2646 | This is used mostly by putenv_from_prefixes so we use `collect_obstack'. |
2647 | It is also used by the --print-search-dirs flag. */ |
2648 | |
2649 | static char * |
2650 | build_search_list (const struct path_prefix *paths, const char *prefix, |
2651 | bool_Bool check_dir, bool_Bool do_multi) |
2652 | { |
2653 | struct add_to_obstack_info info; |
2654 | |
2655 | info.ob = &collect_obstack; |
2656 | info.check_dir = check_dir; |
2657 | info.first_time = true1; |
2658 | |
2659 | obstack_grow__extension__ ( { struct obstack * __o = ( & collect_obstack ) ; int __len = ( strlen ( prefix ) ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( prefix ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&collect_obstack, prefix, strlen (prefix)); |
2660 | obstack_1grow__extension__ ( { struct obstack * __o = ( & collect_obstack ) ; if ( __o -> next_free + 1 > __o -> chunk_limit ) _obstack_newchunk ( __o , 1 ) ; ( * ( ( __o ) -> next_free ) ++ = ( '=' ) ) ; ( void ) 0 ; } ) (&collect_obstack, '='); |
2661 | |
2662 | for_each_path (paths, do_multi, 0, add_to_obstack, &info); |
2663 | |
2664 | obstack_1grow__extension__ ( { struct obstack * __o = ( & collect_obstack ) ; if ( __o -> next_free + 1 > __o -> chunk_limit ) _obstack_newchunk ( __o , 1 ) ; ( * ( ( __o ) -> next_free ) ++ = ( '\0' ) ) ; ( void ) 0 ; } ) (&collect_obstack, '\0'); |
2665 | return XOBFINISH( ( char * ) __extension__ ( { struct obstack * __o1 = ( ( & collect_obstack ) ) ; void * value ; value = ( void * ) __o1 -> object_base ; if ( __o1 -> next_free == value ) __o1 -> maybe_empty_object = 1 ; __o1 -> next_free = ( ( ( ( ( __o1 -> next_free ) - ( char * ) 0 ) + __o1 -> alignment_mask ) & ~ ( __o1 -> alignment_mask ) ) + ( char * ) 0 ) ; if ( __o1 -> next_free - ( char * ) __o1 -> chunk > __o1 -> chunk_limit - ( char * ) __o1 -> chunk ) __o1 -> next_free = __o1 -> chunk_limit ; __o1 -> object_base = __o1 -> next_free ; value ; } ) ) (&collect_obstack, char *); |
2666 | } |
2667 | |
2668 | /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables |
2669 | for collect. */ |
2670 | |
2671 | static void |
2672 | putenv_from_prefixes (const struct path_prefix *paths, const char *env_var, |
2673 | bool_Bool do_multi) |
2674 | { |
2675 | putenv (build_search_list (paths, env_var, true1, do_multi)); |
2676 | } |
2677 | |
2678 | /* Check whether NAME can be accessed in MODE. This is like access, |
2679 | except that it never considers directories to be executable. */ |
2680 | |
2681 | static int |
2682 | access_check (const char *name, int mode) |
2683 | { |
2684 | if (mode == X_OK( 1 << 0 )) |
2685 | { |
2686 | struct stat st; |
2687 | |
2688 | if (stat (name, &st) < 0 |
2689 | || S_ISDIR( ( ( st . st_mode ) & 0170000 ) == 0040000 ) (st.st_mode)) |
2690 | return -1; |
2691 | } |
2692 | |
2693 | return access (name, mode); |
2694 | } |
2695 | |
2696 | /* Callback for find_a_file. Appends the file name to the directory |
2697 | path. If the resulting file exists in the right mode, return the |
2698 | full pathname to the file. */ |
2699 | |
2700 | struct file_at_path_info { |
2701 | const char *name; |
2702 | const char *suffix; |
2703 | int name_len; |
2704 | int suffix_len; |
2705 | int mode; |
2706 | }; |
2707 | |
2708 | static void * |
2709 | file_at_path (char *path, void *data) |
2710 | { |
2711 | struct file_at_path_info *info = data; |
2712 | size_t len = strlen (path); |
2713 | |
2714 | memcpy (path + len, info->name, info->name_len); |
2715 | len += info->name_len; |
2716 | |
2717 | /* Some systems have a suffix for executable files. |
2718 | So try appending that first. */ |
2719 | if (info->suffix_len) |
2720 | { |
2721 | memcpy (path + len, info->suffix, info->suffix_len + 1); |
2722 | if (access_check (path, info->mode) == 0) |
2723 | return path; |
2724 | } |
2725 | |
2726 | path[len] = '\0'; |
2727 | if (access_check (path, info->mode) == 0) |
2728 | return path; |
2729 | |
2730 | return NULL( ( void * ) 0 ); |
2731 | } |
2732 | |
2733 | /* Search for NAME using the prefix list PREFIXES. MODE is passed to |
2734 | access to check permissions. If DO_MULTI is true, search multilib |
2735 | paths then non-multilib paths, otherwise do not search multilib paths. |
2736 | Return 0 if not found, otherwise return its name, allocated with malloc. */ |
2737 | |
2738 | static char * |
2739 | find_a_file (const struct path_prefix *pprefix, const char *name, int mode, |
2740 | bool_Bool do_multi) |
2741 | { |
2742 | struct file_at_path_info info; |
2743 | |
2744 | #ifdef DEFAULT_ASSEMBLER |
2745 | if (! strcmp (name, "as") && access (DEFAULT_ASSEMBLER, mode) == 0) |
2746 | return xstrdup (DEFAULT_ASSEMBLER); |
2747 | #endif |
2748 | |
2749 | #ifdef DEFAULT_LINKER |
2750 | if (! strcmp(name, "ld") && access (DEFAULT_LINKER, mode) == 0) |
2751 | return xstrdup (DEFAULT_LINKER); |
2752 | #endif |
2753 | |
2754 | /* Determine the filename to execute (special case for absolute paths). */ |
2755 | |
2756 | if (IS_ABSOLUTE_PATH( ( ( ( name ) [ 0 ] ) == '/' ) ) (name)) |
2757 | { |
2758 | if (access (name, mode) == 0) |
2759 | return xstrdup (name); |
2760 | |
2761 | return NULL( ( void * ) 0 ); |
2762 | } |
2763 | |
2764 | info.name = name; |
2765 | info.suffix = (mode & X_OK( 1 << 0 )) != 0 ? HOST_EXECUTABLE_SUFFIX"" : ""; |
2766 | info.name_len = strlen (info.name); |
2767 | info.suffix_len = strlen (info.suffix); |
2768 | info.mode = mode; |
2769 | |
2770 | return for_each_path (pprefix, do_multi, info.name_len + info.suffix_len, |
2771 | file_at_path, &info); |
2772 | } |
2773 | |
2774 | /* Ranking of prefixes in the sort list. -B prefixes are put before |
2775 | all others. */ |
2776 | |
2777 | enum path_prefix_priority |
2778 | { |
2779 | /* APPLE LOCAL isysroot 5083137 */ |
2780 | PREFIX_PRIORITY_FIRST, |
2781 | PREFIX_PRIORITY_B_OPT, |
2782 | PREFIX_PRIORITY_LAST |
2783 | }; |
2784 | |
2785 | /* Add an entry for PREFIX in PLIST. The PLIST is kept in ascending |
2786 | order according to PRIORITY. Within each PRIORITY, new entries are |
2787 | appended. |
2788 | |
2789 | If WARN is nonzero, we will warn if no file is found |
2790 | through this prefix. WARN should point to an int |
2791 | which will be set to 1 if this entry is used. |
2792 | |
2793 | COMPONENT is the value to be passed to update_path. |
2794 | |
2795 | REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without |
2796 | the complete value of machine_suffix. |
2797 | 2 means try both machine_suffix and just_machine_suffix. */ |
2798 | |
2799 | static void |
2800 | add_prefix (struct path_prefix *pprefix, const char *prefix, |
2801 | const char *component, /* enum prefix_priority */ int priority, |
2802 | int require_machine_suffix, int os_multilib) |
2803 | { |
2804 | struct prefix_list *pl, **prev; |
2805 | int len; |
2806 | |
2807 | for (prev = &pprefix->plist; |
2808 | (*prev) != NULL( ( void * ) 0 ) && (*prev)->priority <= priority; |
2809 | prev = &(*prev)->next) |
2810 | ; |
2811 | |
2812 | /* Keep track of the longest prefix. */ |
2813 | |
2814 | prefix = update_path (prefix, component); |
2815 | len = strlen (prefix); |
2816 | if (len > pprefix->max_len) |
2817 | pprefix->max_len = len; |
2818 | |
2819 | pl = XNEW( ( struct prefix_list * ) xmalloc ( sizeof ( struct prefix_list ) ) ) (struct prefix_list); |
2820 | pl->prefix = prefix; |
2821 | pl->require_machine_suffix = require_machine_suffix; |
2822 | pl->priority = priority; |
2823 | pl->os_multilib = os_multilib; |
2824 | |
2825 | /* Insert after PREV. */ |
2826 | pl->next = (*prev); |
2827 | (*prev) = pl; |
2828 | } |
2829 | |
2830 | /* Same as add_prefix, but prepending target_system_root to prefix. */ |
2831 | static void |
2832 | add_sysrooted_prefix (struct path_prefix *pprefix, const char *prefix, |
2833 | const char *component, |
2834 | /* enum prefix_priority */ int priority, |
2835 | int require_machine_suffix, int os_multilib) |
2836 | { |
2837 | if (!IS_ABSOLUTE_PATH( ( ( ( prefix ) [ 0 ] ) == '/' ) ) (prefix)) |
2838 | fatal ("system path '%s' is not absolute", prefix); |
2839 | |
2840 | if (target_system_root) |
2841 | { |
2842 | if (target_sysroot_suffix) |
2843 | prefix = concat (target_sysroot_suffix, prefix, NULL( ( void * ) 0 )); |
2844 | prefix = concat (target_system_root, prefix, NULL( ( void * ) 0 )); |
2845 | |
2846 | /* We have to override this because GCC's notion of sysroot |
2847 | moves along with GCC. */ |
2848 | component = "GCC"; |
2849 | } |
2850 | |
2851 | add_prefix (pprefix, prefix, component, priority, |
2852 | require_machine_suffix, os_multilib); |
2853 | } |
2854 | |
2855 | /* Execute the command specified by the arguments on the current line of spec. |
2856 | When using pipes, this includes several piped-together commands |
2857 | with `|' between them. |
2858 | |
2859 | Return 0 if successful, -1 if failed. */ |
2860 | |
2861 | static int |
2862 | execute (void) |
2863 | { |
2864 | int i; |
2865 | int n_commands; /* # of command. */ |
2866 | char *string; |
2867 | struct pex_obj *pex; |
2868 | struct command |
2869 | { |
2870 | const char *prog; /* program name. */ |
2871 | const char **argv; /* vector of args. */ |
2872 | }; |
2873 | |
2874 | struct command *commands; /* each command buffer with above info. */ |
2875 | |
2876 | gcc_assert( ( void ) ( ! ( ! processing_spec_function ) ? fancy_abort ( "../../src/gcc/gcc.c" , 2876 , __FUNCTION__ ) , 0 : 0 ) ) (!processing_spec_function); |
2877 | |
2878 | /* Count # of piped commands. */ |
2879 | for (n_commands = 1, i = 0; i < argbuf_index; i++) |
2880 | if (strcmp (argbuf[i], "|") == 0) |
2881 | n_commands++; |
2882 | |
2883 | /* Get storage for each command. */ |
2884 | commands = alloca__builtin_alloca ( n_commands * sizeof ( struct command ) ) (n_commands * sizeof (struct command)); |
2885 | |
2886 | /* Split argbuf into its separate piped processes, |
2887 | and record info about each one. |
2888 | Also search for the programs that are to be run. */ |
2889 | |
2890 | commands[0].prog = argbuf[0]; /* first command. */ |
2891 | commands[0].argv = &argbuf[0]; |
2892 | string = find_a_file (&exec_prefixes, commands[0].prog, X_OK( 1 << 0 ), false0); |
2893 | |
2894 | if (string) |
2895 | commands[0].argv[0] = string; |
2896 | |
2897 | for (n_commands = 1, i = 0; i < argbuf_index; i++) |
2898 | if (strcmp (argbuf[i], "|") == 0) |
2899 | { /* each command. */ |
2900 | #if defined (__MSDOS__) || defined (OS2) || defined (VMS) |
2901 | fatal ("-pipe not supported"); |
2902 | #endif |
2903 | argbuf[i] = 0; /* termination of command args. */ |
2904 | commands[n_commands].prog = argbuf[i + 1]; |
2905 | commands[n_commands].argv = &argbuf[i + 1]; |
2906 | string = find_a_file (&exec_prefixes, commands[n_commands].prog, |
2907 | X_OK( 1 << 0 ), false0); |
2908 | if (string) |
2909 | commands[n_commands].argv[0] = string; |
2910 | n_commands++; |
2911 | } |
2912 | |
2913 | argbuf[argbuf_index] = 0; |
2914 | |
2915 | /* If -v, print what we are about to do, and maybe query. */ |
2916 | |
2917 | /* APPLE LOCAL begin CC_PRINT_OPTIONS (radar 3313335, 3360444) */ |
2918 | if (verbose_flag || cc_print_options) |
2919 | { |
2920 | /* For help listings, put a blank line between sub-processes. */ |
2921 | if (print_help_list) |
2922 | fputc ('\n', stderr__stderrp); |
2923 | |
2924 | /* Print each piped command as a separate line. */ |
2925 | for (i = 0; i < n_commands; i++) |
2926 | { |
2927 | const char *const *j; |
2928 | |
2929 | FILE *f = stderr__stderrp; |
2930 | if (cc_print_options) |
2931 | { |
2932 | if (cc_print_options_filename) |
2933 | { |
2934 | f = fopenfopen_unlocked ( cc_print_options_filename , "a" ) (cc_print_options_filename, "a"); |
2935 | if (!f) |
2936 | { |
2937 | fprintf (stderr__stderrp, "can not open CC_PRINT_OPTIONS_FILE %s\n", |
2938 | cc_print_options_filename); |
2939 | exit (1); |
2940 | } |
2941 | } |
2942 | fprintf (f, "[Logging gcc options]"); |
2943 | } |
2944 | |
2945 | if (verbose_only_flag || cc_print_options) |
2946 | { |
2947 | for (j = commands[i].argv; *j; j++) |
2948 | { |
2949 | const char *p; |
2950 | fprintf (f, " \""); |
2951 | for (p = *j; *p; ++p) |
2952 | { |
2953 | if (*p == '"' || *p == '\\' || *p == '$') |
2954 | fputc ('\\', f); |
2955 | fputc (*p, f); |
2956 | } |
2957 | fputc ('"', f); |
2958 | } |
2959 | } |
2960 | else |
2961 | for (j = commands[i].argv; *j; j++) |
2962 | fprintf (f, " %s", *j); |
2963 | |
2964 | /* Print a pipe symbol after all but the last command. */ |
2965 | if (i + 1 != n_commands) |
2966 | fprintf (f, " |"); |
2967 | fprintf (f, "\n"); |
2968 | |
2969 | if (cc_print_options_filename) |
2970 | fclose (f); |
2971 | /* APPLE LOCAL end CC_PRINT_OPTIONS */ |
2972 | } |
2973 | fflush (stderr__stderrp); |
2974 | if (verbose_only_flag != 0) |
2975 | { |
2976 | /* verbose_only_flag should act as if the spec was |
2977 | executed, so increment execution_count before |
2978 | returning. This prevents spurious warnings about |
2979 | unused linker input files, etc. */ |
2980 | execution_count++; |
2981 | return 0; |
2982 | } |
2983 | #ifdef DEBUG |
2984 | notice ("\nGo ahead? (y or n) "); |
2985 | fflush (stderr); |
2986 | i = getchar (); |
2987 | if (i != '\n') |
2988 | while (getchar () != '\n') |
2989 | ; |
2990 | |
2991 | if (i != 'y' && i != 'Y') |
2992 | return 0; |
2993 | #endif /* DEBUG */ |
2994 | } |
2995 | |
2996 | #ifdef ENABLE_VALGRIND_CHECKING |
2997 | /* Run the each command through valgrind. To simplify prepending the |
2998 | path to valgrind and the option "-q" (for quiet operation unless |
2999 | something triggers), we allocate a separate argv array. */ |
3000 | |
3001 | for (i = 0; i < n_commands; i++) |
3002 | { |
3003 | const char **argv; |
3004 | int argc; |
3005 | int j; |
3006 | |
3007 | for (argc = 0; commands[i].argv[argc] != NULL; argc++) |
3008 | ; |
3009 | |
3010 | argv = alloca ((argc + 3) * sizeof (char *)); |
3011 | |
3012 | argv[0] = VALGRIND_PATH; |
3013 | argv[1] = "-q"; |
3014 | for (j = 2; j < argc + 2; j++) |
3015 | argv[j] = commands[i].argv[j - 2]; |
3016 | argv[j] = NULL; |
3017 | |
3018 | commands[i].argv = argv; |
3019 | commands[i].prog = argv[0]; |
3020 | } |
3021 | #endif |
3022 | |
3023 | /* Run each piped subprocess. */ |
3024 | |
3025 | pex = pex_init (PEX_USE_PIPES0x2 | (report_times ? PEX_RECORD_TIMES0x1 : 0), |
3026 | programname, temp_filename); |
3027 | if (pex == NULL( ( void * ) 0 )) |
3028 | pfatal_with_name (_libintl_gettext ( "pex_init failed" )("pex_init failed")); |
3029 | |
3030 | for (i = 0; i < n_commands; i++) |
3031 | { |
3032 | const char *errmsg; |
3033 | int err; |
3034 | const char *string = commands[i].argv[0]; |
3035 | |
3036 | /* APPLE LOCAL begin verbose help 2920964 */ |
3037 | if (verbose_flag |
3038 | && print_help_list |
3039 | && (!strcmp ("/usr/libexec/gcc/darwin/ppc/as", string) |
3040 | || !strcmp ("/usr/libexec/gcc/darwin/i386/as", string) |
3041 | || !strcmp ("ld", string))) |
3042 | { |
3043 | /* Do nothing. |
3044 | as and ld do not entertain --help. */ |
3045 | errmsg = NULL( ( void * ) 0 ); |
3046 | } |
3047 | else |
3048 | errmsg = pex_run (pex, |
3049 | ((i + 1 == n_commands ? PEX_LAST0x1 : 0) |
3050 | | (string == commands[i].prog ? PEX_SEARCH0x2 : 0)), |
3051 | string, (char * const *) commands[i].argv, |
3052 | NULL( ( void * ) 0 ), NULL( ( void * ) 0 ), &err); |
3053 | /* APPLE LOCAL end verbose help 2920964 */ |
3054 | if (errmsg != NULL( ( void * ) 0 )) |
3055 | { |
3056 | if (err == 0) |
3057 | fatal (errmsg); |
3058 | else |
3059 | { |
3060 | errno( * __error ( ) ) = err; |
3061 | pfatal_with_name (errmsg); |
3062 | } |
3063 | } |
3064 | |
3065 | if (string != commands[i].prog) |
3066 | free ((void *) string); |
3067 | } |
3068 | |
3069 | execution_count++; |
3070 | |
3071 | /* Wait for all the subprocesses to finish. */ |
3072 | |
3073 | { |
3074 | int *statuses; |
3075 | struct pex_time *times = NULL( ( void * ) 0 ); |
3076 | int ret_code = 0; |
3077 | |
3078 | statuses = alloca__builtin_alloca ( n_commands * sizeof ( int ) ) (n_commands * sizeof (int)); |
3079 | if (!pex_get_status (pex, n_commands, statuses)) |
3080 | pfatal_with_name (_libintl_gettext ( "failed to get exit status" )("failed to get exit status")); |
3081 | |
3082 | if (report_times) |
3083 | { |
3084 | times = alloca__builtin_alloca ( n_commands * sizeof ( struct pex_time ) ) (n_commands * sizeof (struct pex_time)); |
3085 | if (!pex_get_times (pex, n_commands, times)) |
3086 | pfatal_with_name (_libintl_gettext ( "failed to get process times" )("failed to get process times")); |
3087 | } |
3088 | |
3089 | pex_free (pex); |
3090 | |
3091 | for (i = 0; i < n_commands; ++i) |
3092 | { |
3093 | int status = statuses[i]; |
3094 | |
3095 | if (WIFSIGNALED( ( ( * ( int * ) & ( status ) ) & 0177 ) != 0177 && ( ( * ( int * ) & ( status ) ) & 0177 ) != 0 ) (status)) |
3096 | { |
3097 | #ifdef SIGPIPE |
3098 | /* SIGPIPE is a special case. It happens in -pipe mode |
3099 | when the compiler dies before the preprocessor is done, |
3100 | or the assembler dies before the compiler is done. |
3101 | There's generally been an error already, and this is |
3102 | just fallout. So don't generate another error unless |
3103 | we would otherwise have succeeded. */ |
3104 | if (WTERMSIG( ( ( * ( int * ) & ( status ) ) & 0177 ) ) (status) == SIGPIPE13 |
3105 | && (signal_count || greatest_status >= MIN_FATAL_STATUS1)) |
3106 | { |
3107 | signal_count++; |
3108 | ret_code = -1; |
3109 | } |
3110 | else |
3111 | #endif |
3112 | fatal_ice ("\ |
3113 | Internal error: %s (program %s)\n\ |
3114 | Please submit a full bug report.\n\ |
3115 | See %s for instructions.", |
3116 | strsignal (WTERMSIG( ( ( * ( int * ) & ( status ) ) & 0177 ) ) (status)), commands[i].prog, |
3117 | bug_report_url); |
3118 | } |
3119 | else if (WIFEXITED( ( ( * ( int * ) & ( status ) ) & 0177 ) == 0 ) (status) |
3120 | && WEXITSTATUS( ( ( * ( int * ) & ( status ) ) >> 8 ) & 0x000000ff ) (status) >= MIN_FATAL_STATUS1) |
3121 | { |
3122 | if (WEXITSTATUS( ( ( * ( int * ) & ( status ) ) >> 8 ) & 0x000000ff ) (status) > greatest_status) |
3123 | greatest_status = WEXITSTATUS( ( ( * ( int * ) & ( status ) ) >> 8 ) & 0x000000ff ) (status); |
3124 | ret_code = -1; |
3125 | } |
3126 | |
3127 | if (report_times) |
3128 | { |
3129 | struct pex_time *pt = ×[i]; |
3130 | double ut, st; |
3131 | |
3132 | ut = ((double) pt->user_seconds |
3133 | + (double) pt->user_microseconds / 1.0e6); |
3134 | st = ((double) pt->system_seconds |
3135 | + (double) pt->system_microseconds / 1.0e6); |
3136 | |
3137 | if (ut + st != 0) |
3138 | notice ("# %s %.2f %.2f\n", commands[i].prog, ut, st); |
3139 | } |
3140 | } |
3141 | |
3142 | return ret_code; |
3143 | } |
3144 | } |
3145 | |
3146 | /* Find all the switches given to us |
3147 | and make a vector describing them. |
3148 | The elements of the vector are strings, one per switch given. |
3149 | If a switch uses following arguments, then the `part1' field |
3150 | is the switch itself and the `args' field |
3151 | is a null-terminated vector containing the following arguments. |
3152 | The `live_cond' field is: |
3153 | 0 when initialized |
3154 | 1 if the switch is true in a conditional spec, |
3155 | -1 if false (overridden by a later switch) |
3156 | -2 if this switch should be ignored (used in %<S) |
3157 | The `validated' field is nonzero if any spec has looked at this switch; |
3158 | if it remains zero at the end of the run, it must be meaningless. */ |
3159 | |
3160 | #define SWITCH_OK 0 |
3161 | #define SWITCH_FALSE -1 |
3162 | #define SWITCH_IGNORE -2 |
3163 | #define SWITCH_LIVE 1 |
3164 | |
3165 | struct switchstr |
3166 | { |
3167 | const char *part1; |
3168 | const char **args; |
3169 | int live_cond; |
3170 | unsigned char validated; |
3171 | unsigned char ordering; |
3172 | }; |
3173 | |
3174 | static struct switchstr *switches; |
3175 | |
3176 | static int n_switches; |
3177 | |
3178 | /* Language is one of three things: |
3179 | |
3180 | 1) The name of a real programming language. |
3181 | 2) NULL, indicating that no one has figured out |
3182 | what it is yet. |
3183 | 3) '*', indicating that the file should be passed |
3184 | to the linker. */ |
3185 | struct infile |
3186 | { |
3187 | const char *name; |
3188 | const char *language; |
3189 | /* APPLE LOCAL begin IMA */ |
3190 | struct compiler *incompiler; |
3191 | |
3192 | /* Use separate temp file for each input file. */ |
3193 | const char *temp_filename; |
3194 | bool_Bool compiled; |
3195 | bool_Bool preprocessed; |
3196 | /* APPLE LOCAL end IMA */ |
3197 | }; |
3198 | |
3199 | /* Also a vector of input files specified. */ |
3200 | |
3201 | static struct infile *infiles; |
3202 | |
3203 | int n_infiles; |
3204 | |
3205 | /* True if multiple input files are being compiled to a single |
3206 | assembly file. */ |
3207 | |
3208 | static bool_Bool combine_inputs; |
3209 | |
3210 | /* APPLE LOCAL begin IMA */ |
3211 | |
3212 | /* True if "-traditional-cpp" appears on commandline. */ |
3213 | static int traditional_cpp_flag = 0; |
3214 | |
3215 | /* True if "-E" appears on commandline. */ |
3216 | static int capital_e_flag = 0; |
3217 | /* APPLE LOCAL end IMA */ |
3218 | |
3219 | /* This counts the number of libraries added by lang_specific_driver, so that |
3220 | we can tell if there were any user supplied any files or libraries. */ |
3221 | |
3222 | static int added_libraries; |
3223 | |
3224 | /* And a vector of corresponding output files is made up later. */ |
3225 | |
3226 | const char **outfiles; |
3227 | |
3228 | #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX) |
3229 | |
3230 | /* Convert NAME to a new name if it is the standard suffix. DO_EXE |
3231 | is true if we should look for an executable suffix. DO_OBJ |
3232 | is true if we should look for an object suffix. */ |
3233 | |
3234 | static const char * |
3235 | convert_filename (const char *name, int do_exe ATTRIBUTE_UNUSED__attribute__ ( ( __unused__ ) ), |
3236 | int do_obj ATTRIBUTE_UNUSED__attribute__ ( ( __unused__ ) )) |
3237 | { |
3238 | #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) |
3239 | int i; |
3240 | #endif |
3241 | int len; |
3242 | |
3243 | if (name == NULL( ( void * ) 0 )) |
3244 | return NULL( ( void * ) 0 ); |
3245 | |
3246 | len = strlen (name); |
3247 | |
3248 | #ifdef HAVE_TARGET_OBJECT_SUFFIX |
3249 | /* Convert x.o to x.obj if TARGET_OBJECT_SUFFIX is ".obj". */ |
3250 | if (do_obj && len > 2 |
3251 | && name[len - 2] == '.' |
3252 | && name[len - 1] == 'o') |
3253 | { |
3254 | obstack_grow__extension__ ( { struct obstack * __o = ( & obstack ) ; int __len = ( len - 2 ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( name ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&obstack, name, len - 2); |
3255 | obstack_grow0__extension__ ( { struct obstack * __o = ( & obstack ) ; int __len = ( strlen ( ".o" ) ) ; if ( __o -> next_free + __len + 1 > __o -> chunk_limit ) _obstack_newchunk ( __o , __len + 1 ) ; memcpy ( ( __o -> next_free ) , ( ( ".o" ) ) , ( __len ) ) ; __o -> next_free += __len ; * ( __o -> next_free ) ++ = 0 ; ( void ) 0 ; } ) (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX)); |
3256 | name = XOBFINISH( ( const char * ) __extension__ ( { struct obstack * __o1 = ( ( & obstack ) ) ; void * value ; value = ( void * ) __o1 -> object_base ; if ( __o1 -> next_free == value ) __o1 -> maybe_empty_object = 1 ; __o1 -> next_free = ( ( ( ( ( __o1 -> next_free ) - ( char * ) 0 ) + __o1 -> alignment_mask ) & ~ ( __o1 -> alignment_mask ) ) + ( char * ) 0 ) ; if ( __o1 -> next_free - ( char * ) __o1 -> chunk > __o1 -> chunk_limit - ( char * ) __o1 -> chunk ) __o1 -> next_free = __o1 -> chunk_limit ; __o1 -> object_base = __o1 -> next_free ; value ; } ) ) (&obstack, const char *); |
3257 | } |
3258 | #endif |
3259 | |
3260 | #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) |
3261 | /* If there is no filetype, make it the executable suffix (which includes |
3262 | the "."). But don't get confused if we have just "-o". */ |
3263 | if (! do_exe || TARGET_EXECUTABLE_SUFFIX[0] == 0 || (len == 2 && name[0] == '-')) |
3264 | return name; |
3265 | |
3266 | for (i = len - 1; i >= 0; i--) |
3267 | if (IS_DIR_SEPARATOR (name[i])) |
3268 | break; |
3269 | |
3270 | for (i++; i < len; i++) |
3271 | if (name[i] == '.') |
3272 | return name; |
3273 | |
3274 | obstack_grow (&obstack, name, len); |
3275 | obstack_grow0 (&obstack, TARGET_EXECUTABLE_SUFFIX, |
3276 | strlen (TARGET_EXECUTABLE_SUFFIX)); |
3277 | name = XOBFINISH (&obstack, const char *); |
3278 | #endif |
3279 | |
3280 | return name; |
3281 | } |
3282 | #endif |
3283 | |
3284 | /* Display the command line switches accepted by gcc. */ |
3285 | static void |
3286 | display_help (void) |
3287 | { |
3288 | printf (_libintl_gettext ( "Usage: %s [options] file...\n" )("Usage: %s [options] file...\n"), programname); |
3289 | fputs (_libintl_gettext ( "Options:\n" )("Options:\n"), stdout__stdoutp); |
3290 | |
3291 | fputs (_libintl_gettext ( " -pass-exit-codes Exit with highest error code from a phase\n" )(" -pass-exit-codes Exit with highest error code from a phase\n"), stdout__stdoutp); |
3292 | fputs (_libintl_gettext ( " --help Display this information\n" )(" --help Display this information\n"), stdout__stdoutp); |
3293 | fputs (_libintl_gettext ( " --target-help Display target specific command line options\n" )(" --target-help Display target specific command line options\n"), stdout__stdoutp); |
3294 | if (! verbose_flag) |
3295 | fputs (_libintl_gettext ( " (Use '-v --help' to display command line options of sub-processes)\n" )(" (Use '-v --help' to display command line options of sub-processes)\n"), stdout__stdoutp); |
3296 | fputs (_libintl_gettext ( " -dumpspecs Display all of the built in spec strings\n" )(" -dumpspecs Display all of the built in spec strings\n"), stdout__stdoutp); |
3297 | fputs (_libintl_gettext ( " -dumpversion Display the version of the compiler\n" )(" -dumpversion Display the version of the compiler\n"), stdout__stdoutp); |
3298 | fputs (_libintl_gettext ( " -dumpmachine Display the compiler's target processor\n" )(" -dumpmachine Display the compiler's target processor\n"), stdout__stdoutp); |
3299 | fputs (_libintl_gettext ( " -print-search-dirs Display the directories in the compiler's search path\n" )(" -print-search-dirs Display the directories in the compiler's search path\n"), stdout__stdoutp); |
3300 | fputs (_libintl_gettext ( " -print-libgcc-file-name Display the name of the compiler's companion library\n" )(" -print-libgcc-file-name Display the name of the compiler's companion library\n"), stdout__stdoutp); |
3301 | fputs (_libintl_gettext ( " -print-file-name= ) |
3302 | fputs (_libintl_gettext ( " -print-prog-name= ) |
3303 | fputs (_libintl_gettext ( " -print-multi-directory Display the root directory for versions of libgcc\n" )(" -print-multi-directory Display the root directory for versions of libgcc\n"), stdout__stdoutp); |
3304 | fputs (_libintl_gettext ( " -print-multi-lib Display the mapping between command line options and\n multiple library search directories\n" )("\ |
3305 | -print-multi-lib Display the mapping between command line options and\n\ |
3306 | multiple library search directories\n"), stdout__stdoutp); |
3307 | fputs (_libintl_gettext ( " -print-multi-os-directory Display the relative path to OS libraries\n" )(" -print-multi-os-directory Display the relative path to OS libraries\n"), stdout__stdoutp); |
3308 | fputs (_libintl_gettext ( " -Wa, ) |
3309 | fputs (_libintl_gettext ( " -Wp, ) |
3310 | fputs (_libintl_gettext ( " -Wl, ) |
3311 | fputs (_libintl_gettext ( " -Xassembler ) |
3312 | fputs (_libintl_gettext ( " -Xpreprocessor ) |
3313 | fputs (_libintl_gettext ( " -Xlinker ) |
3314 | fputs (_libintl_gettext ( " -combine Pass multiple source files to compiler at once\n" )(" -combine Pass multiple source files to compiler at once\n"), stdout__stdoutp); |
3315 | fputs (_libintl_gettext ( " -save-temps Do not delete intermediate files\n" )(" -save-temps Do not delete intermediate files\n"), stdout__stdoutp); |
3316 | fputs (_libintl_gettext ( " -pipe Use pipes rather than intermediate files\n" )(" -pipe Use pipes rather than intermediate files\n"), stdout__stdoutp); |
3317 | fputs (_libintl_gettext ( " -time Time the execution of each subprocess\n" )(" -time Time the execution of each subprocess\n"), stdout__stdoutp); |
3318 | fputs (_libintl_gettext ( " -specs= ) |
3319 | fputs (_libintl_gettext ( " -std= ) |
3320 | fputs (_libintl_gettext ( " --sysroot= ) |
3321 | --sysroot=<directory> Use <directory> as the root directory for headers\n\ |
3322 | and libraries\n"), stdout__stdoutp); |
3323 | fputs (_libintl_gettext ( " -B ) |
3324 | fputs (_libintl_gettext ( " -b ) |
3325 | fputs (_libintl_gettext ( " -V ) |
3326 | fputs (_libintl_gettext ( " -v Display the programs invoked by the compiler\n" )(" -v Display the programs invoked by the compiler\n"), stdout__stdoutp); |
3327 | fputs (_libintl_gettext ( " -### Like -v but options quoted and commands not executed\n" )(" -### Like -v but options quoted and commands not executed\n"), stdout__stdoutp); |
3328 | fputs (_libintl_gettext ( " -E Preprocess only; do not compile, assemble or link\n" )(" -E Preprocess only; do not compile, assemble or link\n"), stdout__stdoutp); |
3329 | fputs (_libintl_gettext ( " -S Compile only; do not assemble or link\n" )(" -S Compile only; do not assemble or link\n"), stdout__stdoutp); |
3330 | fputs (_libintl_gettext ( " -c Compile and assemble, but do not link\n" )(" -c Compile and assemble, but do not link\n"), stdout__stdoutp); |
3331 | fputs (_libintl_gettext ( " -o ) |
3332 | fputs (_libintl_gettext ( " -x ) |
3333 | -x <language> Specify the language of the following input files\n\ |
3334 | Permissible languages include: c c++ assembler none\n\ |
3335 | 'none' means revert to the default behavior of\n\ |
3336 | guessing the language based on the file's extension\n\ |
3337 | "), stdout__stdoutp); |
3338 | |
3339 | printf (_libintl_gettext ( "\nOptions starting with -g, -f, -m, -O, -W, or --param are automatically\n passed on to the various sub-processes invoked by %s. In order to pass\n other options on to these processes the -W ) |
3340 | \nOptions starting with -g, -f, -m, -O, -W, or --param are automatically\n\ |
3341 | passed on to the various sub-processes invoked by %s. In order to pass\n\ |
3342 | other options on to these processes the -W<letter> options must be used.\n\ |
3343 | "), programname); |
3344 | |
3345 | /* The rest of the options are displayed by invocations of the various |
3346 | sub-processes. */ |
3347 | } |
3348 | |
3349 | static void |
3350 | add_preprocessor_option (const char *option, int len) |
3351 | { |
3352 | n_preprocessor_options++; |
3353 | |
3354 | if (! preprocessor_options) |
3355 | preprocessor_options = XNEWVEC( ( char * * ) xmalloc ( sizeof ( char * ) * ( n_preprocessor_options ) ) ) (char *, n_preprocessor_options); |
3356 | else |
3357 | preprocessor_options = xrealloc (preprocessor_options, |
3358 | n_preprocessor_options * sizeof (char *)); |
3359 | |
3360 | preprocessor_options [n_preprocessor_options - 1] = |
3361 | save_string (option, len); |
3362 | } |
3363 | |
3364 | static void |
3365 | add_assembler_option (const char *option, int len) |
3366 | { |
3367 | n_assembler_options++; |
3368 | |
3369 | if (! assembler_options) |
3370 | assembler_options = XNEWVEC( ( char * * ) xmalloc ( sizeof ( char * ) * ( n_assembler_options ) ) ) (char *, n_assembler_options); |
3371 | else |
3372 | assembler_options = xrealloc (assembler_options, |
3373 | n_assembler_options * sizeof (char *)); |
3374 | |
3375 | assembler_options [n_assembler_options - 1] = save_string (option, len); |
3376 | } |
3377 | |
3378 | static void |
3379 | add_linker_option (const char *option, int len) |
3380 | { |
3381 | n_linker_options++; |
3382 | |
3383 | if (! linker_options) |
3384 | linker_options = XNEWVEC( ( char * * ) xmalloc ( sizeof ( char * ) * ( n_linker_options ) ) ) (char *, n_linker_options); |
3385 | else |
3386 | linker_options = xrealloc (linker_options, |
3387 | n_linker_options * sizeof (char *)); |
3388 | |
3389 | linker_options [n_linker_options - 1] = save_string (option, len); |
3390 | } |
3391 | |
3392 | /* Create the vector `switches' and its contents. |
3393 | Store its length in `n_switches'. */ |
3394 | |
3395 | static void |
3396 | process_command (int argc, const char **argv) |
3397 | { |
3398 | int i; |
3399 | const char *temp; |
3400 | char *temp1; |
3401 | const char *spec_lang = 0; |
3402 | int last_language_n_infiles; |
3403 | int lang_n_infiles = 0; |
3404 | #ifdef MODIFY_TARGET_NAME |
3405 | int is_modify_target_name; |
3406 | unsigned int j; |
3407 | #endif |
3408 | |
3409 | GET_ENVIRONMENTdo { ( gcc_exec_prefix ) = getenv ( "GCC_EXEC_PREFIX" ) ; } while ( 0 ) (gcc_exec_prefix, "GCC_EXEC_PREFIX"); |
3410 | |
3411 | n_switches = 0; |
3412 | n_infiles = 0; |
3413 | added_libraries = 0; |
3414 | |
3415 | /* Figure compiler version from version string. */ |
3416 | |
3417 | compiler_version = temp1 = xstrdup (version_string); |
3418 | |
3419 | for (; *temp1; ++temp1) |
3420 | { |
3421 | if (*temp1 == ' ') |
3422 | { |
3423 | *temp1 = '\0'; |
3424 | break; |
3425 | } |
3426 | } |
3427 | |
3428 | /* APPLE LOCAL begin translate_options */ |
3429 | /* FSF patch pending. Move translate_options() call before -b processing |
3430 | so that -bundle like options can be translated, if required. */ |
3431 | /* Convert new-style -- options to old-style. */ |
3432 | translate_options (&argc, (const char *const **) &argv); |
3433 | /* APPLE LOCAL end */ |
3434 | |
3435 | /* If there is a -V or -b option (or both), process it now, before |
3436 | trying to interpret the rest of the command line. |
3437 | Use heuristic that all configuration names must have at least |
3438 | one dash '-'. This allows us to pass options starting with -b. */ |
3439 | if (argc > 1 && argv[1][0] == '-' |
3440 | && (argv[1][1] == 'V' || |
3441 | ((argv[1][1] == 'b') && (NULL( ( void * ) 0 ) != strchr(argv[1] + 2,'-'))))) |
3442 | { |
3443 | const char *new_version = DEFAULT_TARGET_VERSION"4.2.1"; |
3444 | const char *new_machine = DEFAULT_TARGET_MACHINE"i686-apple-darwin8"; |
3445 | const char *progname = argv[0]; |
3446 | char **new_argv; |
3447 | char *new_argv0; |
3448 | int baselen; |
3449 | |
3450 | while (argc > 1 && argv[1][0] == '-' |
3451 | && (argv[1][1] == 'V' || |
3452 | ((argv[1][1] == 'b') && ( NULL( ( void * ) 0 ) != strchr(argv[1] + 2,'-'))))) |
3453 | { |
3454 | char opt = argv[1][1]; |
3455 | const char *arg; |
3456 | if (argv[1][2] != '\0') |
3457 | { |
3458 | arg = argv[1] + 2; |
3459 | argc -= 1; |
3460 | argv += 1; |
3461 | } |
3462 | else if (argc > 2) |
3463 | { |
3464 | arg = argv[2]; |
3465 | argc -= 2; |
3466 | argv += 2; |
3467 | } |
3468 | else |
3469 | fatal ("'-%c' option must have argument", opt); |
3470 | if (opt == 'V') |
3471 | new_version = arg; |
3472 | else |
3473 | new_machine = arg; |
3474 | } |
3475 | |
3476 | for (baselen = strlen (progname); baselen > 0; baselen--) |
3477 | if (IS_DIR_SEPARATOR( ( progname [ baselen - 1 ] ) == '/' ) (progname[baselen-1])) |
3478 | break; |
3479 | new_argv0 = xmemdup (progname, baselen, |
3480 | baselen + concat_length (new_version, new_machine, |
3481 | "-gcc-", NULL( ( void * ) 0 )) + 1); |
3482 | strcpy (new_argv0 + baselen, new_machine); |
3483 | strcat (new_argv0, "-gcc-"); |
3484 | strcat (new_argv0, new_version); |
3485 | |
3486 | new_argv = xmemdup (argv, (argc + 1) * sizeof (argv[0]), |
3487 | (argc + 1) * sizeof (argv[0])); |
3488 | new_argv[0] = new_argv0; |
3489 | |
3490 | execvp (new_argv0, new_argv); |
3491 | fatal ("couldn't run '%s': %s", new_argv0, xstrerror (errno( * __error ( ) ))); |
3492 | } |
3493 | |
3494 | /* Set up the default search paths. If there is no GCC_EXEC_PREFIX, |
3495 | see if we can create it from the pathname specified in argv[0]. */ |
3496 | |
3497 | gcc_libexec_prefix = standard_libexec_prefix; |
3498 | #ifndef VMS |
3499 | /* FIXME: make_relative_prefix doesn't yet work for VMS. */ |
3500 | if (!gcc_exec_prefix) |
3501 | { |
3502 | gcc_exec_prefix = make_relative_prefix (argv[0], standard_bindir_prefix, |
3503 | standard_exec_prefix); |
3504 | gcc_libexec_prefix = make_relative_prefix (argv[0], |
3505 | standard_bindir_prefix, |
3506 | standard_libexec_prefix); |
3507 | if (gcc_exec_prefix) |
3508 | putenv (concat ("GCC_EXEC_PREFIX=", gcc_exec_prefix, NULL( ( void * ) 0 ))); |
3509 | } |
3510 | else |
3511 | { |
3512 | /* make_relative_prefix requires a program name, but |
3513 | GCC_EXEC_PREFIX is typically a directory name with a trailing |
3514 | / (which is ignored by make_relative_prefix), so append a |
3515 | program name. */ |
3516 | char *tmp_prefix = concat (gcc_exec_prefix, "gcc", NULL( ( void * ) 0 )); |
3517 | gcc_libexec_prefix = make_relative_prefix (tmp_prefix, |
3518 | standard_exec_prefix, |
3519 | standard_libexec_prefix); |
3520 | free (tmp_prefix); |
3521 | } |
3522 | #else |
3523 | #endif |
3524 | |
3525 | if (gcc_exec_prefix) |
3526 | { |
3527 | int len = strlen (gcc_exec_prefix); |
3528 | |
3529 | if (len > (int) sizeof ("/lib/gcc/") - 1 |
3530 | && (IS_DIR_SEPARATOR( ( gcc_exec_prefix [ len - 1 ] ) == '/' ) (gcc_exec_prefix[len-1]))) |
3531 | { |
3532 | temp = gcc_exec_prefix + len - sizeof ("/lib/gcc/") + 1; |
3533 | if (IS_DIR_SEPARATOR( ( * temp ) == '/' ) (*temp) |
3534 | && strncmp (temp + 1, "lib", 3) == 0 |
3535 | && IS_DIR_SEPARATOR( ( temp [ 4 ] ) == '/' ) (temp[4]) |
3536 | && strncmp (temp + 5, "gcc", 3) == 0) |
3537 | len -= sizeof ("/lib/gcc/") - 1; |
3538 | } |
3539 | |
3540 | set_std_prefix (gcc_exec_prefix, len); |
3541 | add_prefix (&exec_prefixes, gcc_libexec_prefix, "GCC", |
3542 | PREFIX_PRIORITY_LAST, 0, 0); |
3543 | add_prefix (&startfile_prefixes, gcc_exec_prefix, "GCC", |
3544 | PREFIX_PRIORITY_LAST, 0, 0); |
3545 | } |
3546 | |
3547 | /* COMPILER_PATH and LIBRARY_PATH have values |
3548 | that are lists of directory names with colons. */ |
3549 | |
3550 | GET_ENVIRONMENTdo { ( temp ) = getenv ( "COMPILER_PATH" ) ; } while ( 0 ) (temp, "COMPILER_PATH"); |
3551 | if (temp) |
3552 | { |
3553 | const char *startp, *endp; |
3554 | char *nstore = alloca__builtin_alloca ( strlen ( temp ) + 3 ) (strlen (temp) + 3); |
3555 | |
3556 | startp = endp = temp; |
3557 | while (1) |
3558 | { |
3559 | if (*endp == PATH_SEPARATOR':' || *endp == 0) |
3560 | { |
3561 | strncpy (nstore, startp, endp - startp); |
3562 | if (endp == startp) |
3563 | strcpy (nstore, concat (".", dir_separator_str, NULL( ( void * ) 0 ))); |
3564 | else if (!IS_DIR_SEPARATOR( ( endp [ - 1 ] ) == '/' ) (endp[-1])) |
3565 | { |
3566 | nstore[endp - startp] = DIR_SEPARATOR'/'; |
3567 | nstore[endp - startp + 1] = 0; |
3568 | } |
3569 | else |
3570 | nstore[endp - startp] = 0; |
3571 | add_prefix (&exec_prefixes, nstore, 0, |
3572 | PREFIX_PRIORITY_LAST, 0, 0); |
3573 | add_prefix (&include_prefixes, nstore, 0, |
3574 | PREFIX_PRIORITY_LAST, 0, 0); |
3575 | if (*endp == 0) |
3576 | break; |
3577 | endp = startp = endp + 1; |
3578 | } |
3579 | else |
3580 | endp++; |
3581 | } |
3582 | } |
3583 | |
3584 | GET_ENVIRONMENTdo { ( temp ) = getenv ( "LIBRARY_PATH" ) ; } while ( 0 ) (temp, LIBRARY_PATH_ENV); |
3585 | if (temp && *cross_compile == '0') |
3586 | { |
3587 | const char *startp, *endp; |
3588 | char *nstore = alloca__builtin_alloca ( strlen ( temp ) + 3 ) (strlen (temp) + 3); |
3589 | |
3590 | startp = endp = temp; |
3591 | while (1) |
3592 | { |
3593 | if (*endp == PATH_SEPARATOR':' || *endp == 0) |
3594 | { |
3595 | strncpy (nstore, startp, endp - startp); |
3596 | if (endp == startp) |
3597 | strcpy (nstore, concat (".", dir_separator_str, NULL( ( void * ) 0 ))); |
3598 | else if (!IS_DIR_SEPARATOR( ( endp [ - 1 ] ) == '/' ) (endp[-1])) |
3599 | { |
3600 | nstore[endp - startp] = DIR_SEPARATOR'/'; |
3601 | nstore[endp - startp + 1] = 0; |
3602 | } |
3603 | else |
3604 | nstore[endp - startp] = 0; |
3605 | add_prefix (&startfile_prefixes, nstore, NULL( ( void * ) 0 ), |
3606 | PREFIX_PRIORITY_LAST, 0, 1); |
3607 | if (*endp == 0) |
3608 | break; |
3609 | endp = startp = endp + 1; |
3610 | } |
3611 | else |
3612 | endp++; |
3613 | } |
3614 | } |
3615 | |
3616 | /* Use LPATH like LIBRARY_PATH (for the CMU build program). */ |
3617 | GET_ENVIRONMENTdo { ( temp ) = getenv ( "LPATH" ) ; } while ( 0 ) (temp, "LPATH"); |
3618 | if (temp && *cross_compile == '0') |
3619 | { |
3620 | const char *startp, *endp; |
3621 | char *nstore = alloca__builtin_alloca ( strlen ( temp ) + 3 ) (strlen (temp) + 3); |
3622 | |
3623 | startp = endp = temp; |
3624 | while (1) |
3625 | { |
3626 | if (*endp == PATH_SEPARATOR':' || *endp == 0) |
3627 | { |
3628 | strncpy (nstore, startp, endp - startp); |
3629 | if (endp == startp) |
3630 | strcpy (nstore, concat (".", dir_separator_str, NULL( ( void * ) 0 ))); |
3631 | else if (!IS_DIR_SEPARATOR( ( endp [ - 1 ] ) == '/' ) (endp[-1])) |
3632 | { |
3633 | nstore[endp - startp] = DIR_SEPARATOR'/'; |
3634 | nstore[endp - startp + 1] = 0; |
3635 | } |
3636 | else |
3637 | nstore[endp - startp] = 0; |
3638 | add_prefix (&startfile_prefixes, nstore, NULL( ( void * ) 0 ), |
3639 | PREFIX_PRIORITY_LAST, 0, 1); |
3640 | if (*endp == 0) |
3641 | break; |
3642 | endp = startp = endp + 1; |
3643 | } |
3644 | else |
3645 | endp++; |
3646 | } |
3647 | } |
3648 | |
3649 | /* Convert new-style -- options to old-style. */ |
3650 | translate_options (&argc, (const char *const **) &argv); |
3651 | |
3652 | /* Do language-specific adjustment/addition of flags. */ |
3653 | lang_specific_driver (&argc, (const char *const **) &argv, &added_libraries); |
3654 | |
3655 | /* Scan argv twice. Here, the first time, just count how many switches |
3656 | there will be in their vector, and how many input files in theirs. |
3657 | Here we also parse the switches that cc itself uses (e.g. -v). */ |
3658 | |
3659 | for (i = 1; i < argc; i++) |
3660 | { |
3661 | if (! strcmp (argv[i], "-dumpspecs")) |
3662 | { |
3663 | struct spec_list *sl; |
3664 | init_spec (); |
3665 | for (sl = specs; sl; sl = sl->next) |
3666 | printf ("*%s:\n%s\n\n", sl->name, *(sl->ptr_spec)); |
3667 | if (link_command_spec) |
3668 | printf ("*link_command:\n%s\n\n", link_command_spec); |
3669 | exit (0); |
3670 | } |
3671 | else if (! strcmp (argv[i], "-dumpversion")) |
3672 | { |
3673 | printf ("%s\n", spec_version); |
3674 | exit (0); |
3675 | } |
3676 | else if (! strcmp (argv[i], "-dumpmachine")) |
3677 | { |
3678 | printf ("%s\n", spec_machine); |
3679 | exit (0); |
3680 | } |
3681 | else if (strcmp (argv[i], "-fversion") == 0) |
3682 | { |
3683 | /* translate_options () has turned --version into -fversion. */ |
3684 | printf (_libintl_gettext ( "%s (GCC) %s\n" )("%s (GCC) %s\n"), programname, version_string); |
3685 | printf ("Copyright %s 2007 Free Software Foundation, Inc.\n", |
3686 | _libintl_gettext ( "(C)" )("(C)")); |
3687 | fputs (_libintl_gettext ( "This is free software; see the source for copying conditions. There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n" )("This is free software; see the source for copying conditions. There is NO\n\ |
3688 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"), |
3689 | stdout__stdoutp); |
3690 | exit (0); |
3691 | } |
3692 | else if (strcmp (argv[i], "-fhelp") == 0) |
3693 | { |
3694 | /* translate_options () has turned --help into -fhelp. */ |
3695 | print_help_list = 1; |
3696 | |
3697 | /* We will be passing a dummy file on to the sub-processes. */ |
3698 | n_infiles++; |
3699 | n_switches++; |
3700 | |
3701 | /* CPP driver cannot obtain switch from cc1_options. */ |
3702 | if (is_cpp_driver) |
3703 | add_preprocessor_option ("--help", 6); |
3704 | /* APPLE LOCAL begin verbose help 2920964 */ |
3705 | #if 0 |
3706 | /* Our assembler and linkder do not support --help. */ |
3707 | /* APPLE LOCAL end verbose help 2920964 */ |
3708 | add_assembler_option ("--help", 6); |
3709 | add_linker_option ("--help", 6); |
3710 | /* APPLE LOCAL verbose help 2920964 */ |
3711 | #endif |
3712 | } |
3713 | else if (strcmp (argv[i], "-ftarget-help") == 0) |
3714 | { |
3715 | /* translate_options() has turned --target-help into -ftarget-help. */ |
3716 | target_help_flag = 1; |
3717 | |
3718 | /* We will be passing a dummy file on to the sub-processes. */ |
3719 | n_infiles++; |
3720 | n_switches++; |
3721 | |
3722 | /* CPP driver cannot obtain switch from cc1_options. */ |
3723 | if (is_cpp_driver) |
3724 | add_preprocessor_option ("--target-help", 13); |
3725 | add_assembler_option ("--target-help", 13); |
3726 | add_linker_option ("--target-help", 13); |
3727 | } |
3728 | else if (! strcmp (argv[i], "-pass-exit-codes")) |
3729 | { |
3730 | pass_exit_codes = 1; |
3731 | n_switches++; |
3732 | } |
3733 | else if (! strcmp (argv[i], "-print-search-dirs")) |
3734 | print_search_dirs = 1; |
3735 | else if (! strcmp (argv[i], "-print-libgcc-file-name")) |
3736 | print_file_name = "libgcc.a"; |
3737 | else if (! strncmp (argv[i], "-print-file-name=", 17)) |
3738 | print_file_name = argv[i] + 17; |
3739 | else if (! strncmp (argv[i], "-print-prog-name=", 17)) |
3740 | print_prog_name = argv[i] + 17; |
3741 | else if (! strcmp (argv[i], "-print-multi-lib")) |
3742 | print_multi_lib = 1; |
3743 | else if (! strcmp (argv[i], "-print-multi-directory")) |
3744 | print_multi_directory = 1; |
3745 | else if (! strcmp (argv[i], "-print-multi-os-directory")) |
3746 | print_multi_os_directory = 1; |
3747 | else if (! strncmp (argv[i], "-Wa,", 4)) |
3748 | { |
3749 | int prev, j; |
3750 | /* Pass the rest of this option to the assembler. */ |
3751 | |
3752 | /* Split the argument at commas. */ |
3753 | prev = 4; |
3754 | for (j = 4; argv[i][j]; j++) |
3755 | if (argv[i][j] == ',') |
3756 | { |
3757 | add_assembler_option (argv[i] + prev, j - prev); |
3758 | prev = j + 1; |
3759 | } |
3760 | |
3761 | /* Record the part after the last comma. */ |
3762 | add_assembler_option (argv[i] + prev, j - prev); |
3763 | } |
3764 | else if (! strncmp (argv[i], "-Wp,", 4)) |
3765 | { |
3766 | int prev, j; |
3767 | /* Pass the rest of this option to the preprocessor. */ |
3768 | |
3769 | /* Split the argument at commas. */ |
3770 | prev = 4; |
3771 | for (j = 4; argv[i][j]; j++) |
3772 | if (argv[i][j] == ',') |
3773 | { |
3774 | add_preprocessor_option (argv[i] + prev, j - prev); |
3775 | prev = j + 1; |
3776 | } |
3777 | |
3778 | /* Record the part after the last comma. */ |
3779 | add_preprocessor_option (argv[i] + prev, j - prev); |
3780 | } |
3781 | else if (argv[i][0] == '+' && argv[i][1] == 'e') |
3782 | /* The +e options to the C++ front-end. */ |
3783 | n_switches++; |
3784 | else if (strncmp (argv[i], "-Wl,", 4) == 0) |
3785 | { |
3786 | int j; |
3787 | /* Split the argument at commas. */ |
3788 | for (j = 3; argv[i][j]; j++) |
3789 | n_infiles += (argv[i][j] == ','); |
3790 | } |
3791 | else if (strcmp (argv[i], "-Xlinker") == 0) |
3792 | { |
3793 | if (i + 1 == argc) |
3794 | fatal ("argument to '-Xlinker' is missing"); |
3795 | |
3796 | n_infiles++; |
3797 | i++; |
3798 | } |
3799 | else if (strcmp (argv[i], "-Xpreprocessor") == 0) |
3800 | { |
3801 | if (i + 1 == argc) |
3802 | fatal ("argument to '-Xpreprocessor' is missing"); |
3803 | |
3804 | add_preprocessor_option (argv[i+1], strlen (argv[i+1])); |
3805 | } |
3806 | else if (strcmp (argv[i], "-Xassembler") == 0) |
3807 | { |
3808 | if (i + 1 == argc) |
3809 | fatal ("argument to '-Xassembler' is missing"); |
3810 | |
3811 | add_assembler_option (argv[i+1], strlen (argv[i+1])); |
3812 | } |
3813 | else if (strcmp (argv[i], "-l") == 0) |
3814 | { |
3815 | if (i + 1 == argc) |
3816 | fatal ("argument to '-l' is missing"); |
3817 | |
3818 | n_infiles++; |
3819 | i++; |
3820 | } |
3821 | else if (strncmp (argv[i], "-l", 2) == 0) |
3822 | n_infiles++; |
3823 | else if (strcmp (argv[i], "-save-temps") == 0) |
3824 | { |
3825 | save_temps_flag = 1; |
3826 | n_switches++; |
3827 | } |
3828 | /* APPLE LOCAL begin IMA */ |
3829 | else if (strcmp (argv[i], "-fast") == 0 |
3830 | || strcmp (argv[i], "-fastf") == 0 |
3831 | || strcmp (argv[i], "-fastcp") == 0) |
3832 | { |
3833 | combine_flag = 1; |
3834 | n_switches++; |
3835 | } |
3836 | else if (strcmp (argv[i], "-traditional-cpp") == 0) |
3837 | { |
3838 | traditional_cpp_flag = 1; |
3839 | n_switches++; |
3840 | } |
3841 | else if (strcmp (argv[i], "-E") == 0) |
3842 | { |
3843 | capital_e_flag = 1; |
3844 | n_switches++; |
3845 | } |
3846 | /* APPLE LOCAL end IMA */ |
3847 | /* APPLE LOCAL begin -weak_* (radar 3235250) */ |
3848 | else if (strncmp (argv[i], "-weak-l", 7) == 0) |
3849 | n_infiles++; |
3850 | else if (strcmp (argv[i], "-weak_library") == 0) |
3851 | { |
3852 | if (i + 1 == argc) |
3853 | fatal ("argument to `-weak_library' is missing"); |
3854 | |
3855 | n_infiles += 2; |
3856 | i++; |
3857 | } |
3858 | else if (strcmp (argv[i], "-weak_framework") == 0) |
3859 | { |
3860 | if (i + 1 == argc) |
3861 | fatal ("argument to `-weak_framework' is missing"); |
3862 | |
3863 | n_infiles += 2; |
3864 | i++; |
3865 | } |
3866 | /* APPLE LOCAL end -weak_* (radar 3235250) */ |
3867 | else if (strcmp (argv[i], "-combine") == 0) |
3868 | { |
3869 | combine_flag = 1; |
3870 | n_switches++; |
3871 | } |
3872 | else if (strcmp (argv[i], "-specs") == 0) |
3873 | { |
3874 | struct user_specs *user = XNEW( ( struct user_specs * ) xmalloc ( sizeof ( struct user_specs ) ) ) (struct user_specs); |
3875 | if (++i >= argc) |
3876 | fatal ("argument to '-specs' is missing"); |
3877 | |
3878 | user->next = (struct user_specs *) 0; |
3879 | user->filename = argv[i]; |
3880 | if (user_specs_tail) |
3881 | user_specs_tail->next = user; |
3882 | else |
3883 | user_specs_head = user; |
3884 | user_specs_tail = user; |
3885 | } |
3886 | else if (strncmp (argv[i], "-specs=", 7) == 0) |
3887 | { |
3888 | struct user_specs *user = XNEW( ( struct user_specs * ) xmalloc ( sizeof ( struct user_specs ) ) ) (struct user_specs); |
3889 | if (strlen (argv[i]) == 7) |
3890 | fatal ("argument to '-specs=' is missing"); |
3891 | |
3892 | user->next = (struct user_specs *) 0; |
3893 | user->filename = argv[i] + 7; |
3894 | if (user_specs_tail) |
3895 | user_specs_tail->next = user; |
3896 | else |
3897 | user_specs_head = user; |
3898 | user_specs_tail = user; |
3899 | } |
3900 | else if (strcmp (argv[i], "-time") == 0) |
3901 | report_times = 1; |
3902 | else if (strcmp (argv[i], "-pipe") == 0) |
3903 | { |
3904 | /* -pipe has to go into the switches array as well as |
3905 | setting a flag. */ |
3906 | use_pipes = 1; |
3907 | n_switches++; |
3908 | } |
3909 | else if (strcmp (argv[i], "-###") == 0) |
3910 | { |
3911 | /* This is similar to -v except that there is no execution |
3912 | of the commands and the echoed arguments are quoted. It |
3913 | is intended for use in shell scripts to capture the |
3914 | driver-generated command line. */ |
3915 | verbose_only_flag++; |
3916 | verbose_flag++; |
3917 | } |
3918 | /* APPLE LOCAL begin frameworks */ |
3919 | else if (strcmp (argv[i], "-framework") == 0) |
3920 | { |
3921 | if (i + 1 == argc) |
3922 | fatal ("argument to `-framework' is missing"); |
3923 | |
3924 | n_infiles += 2; |
3925 | i++; |
3926 | } |
3927 | /* APPLE LOCAL end frameworks */ |
3928 | else if (argv[i][0] == '-' && argv[i][1] != 0) |
3929 | { |
3930 | const char *p = &argv[i][1]; |
3931 | int c = *p; |
3932 | |
3933 | switch (c) |
3934 | { |
3935 | case 'b': |
3936 | if (NULL( ( void * ) 0 ) == strchr(argv[i] + 2, '-')) |
3937 | goto normal_switch; |
3938 | |
3939 | /* Fall through. */ |
3940 | case 'V': |
3941 | fatal ("'-%c' must come at the start of the command line", c); |
3942 | break; |
3943 | |
3944 | case 'B': |
3945 | { |
3946 | const char *value; |
3947 | int len; |
3948 | |
3949 | if (p[1] == 0 && i + 1 == argc) |
3950 | fatal ("argument to '-B' is missing"); |
3951 | if (p[1] == 0) |
3952 | value = argv[++i]; |
3953 | else |
3954 | value = p + 1; |
3955 | |
3956 | len = strlen (value); |
3957 | |
3958 | /* Catch the case where the user has forgotten to append a |
3959 | directory separator to the path. Note, they may be using |
3960 | -B to add an executable name prefix, eg "i386-elf-", in |
3961 | order to distinguish between multiple installations of |
3962 | GCC in the same directory. Hence we must check to see |
3963 | if appending a directory separator actually makes a |
3964 | valid directory name. */ |
3965 | if (! IS_DIR_SEPARATOR( ( value [ len - 1 ] ) == '/' ) (value [len - 1]) |
3966 | && is_directory (value, false0)) |
3967 | { |
3968 | char *tmp = XNEWVEC( ( char * ) xmalloc ( sizeof ( char ) * ( len + 2 ) ) ) (char, len + 2); |
3969 | strcpy (tmp, value); |
3970 | tmp[len] = DIR_SEPARATOR'/'; |
3971 | tmp[++ len] = 0; |
3972 | value = tmp; |
3973 | } |
3974 | |
3975 | /* As a kludge, if the arg is "[foo/]stageN/", just |
3976 | add "[foo/]include" to the include prefix. */ |
3977 | if ((len == 7 |
3978 | || (len > 7 |
3979 | && (IS_DIR_SEPARATOR( ( value [ len - 8 ] ) == '/' ) (value[len - 8])))) |
3980 | && strncmp (value + len - 7, "stage", 5) == 0 |
3981 | && ISDIGIT( _sch_istable [ ( value [ len - 2 ] ) & 0xff ] & ( unsigned short ) ( _sch_isdigit ) ) (value[len - 2]) |
3982 | && (IS_DIR_SEPARATOR( ( value [ len - 1 ] ) == '/' ) (value[len - 1]))) |
3983 | { |
3984 | if (len == 7) |
3985 | add_prefix (&include_prefixes, "./", NULL( ( void * ) 0 ), |
3986 | PREFIX_PRIORITY_B_OPT, 0, 0); |
3987 | else |
3988 | { |
3989 | char *string = xmalloc (len - 6); |
3990 | memcpy (string, value, len - 7); |
3991 | string[len - 7] = 0; |
3992 | add_prefix (&include_prefixes, string, NULL( ( void * ) 0 ), |
3993 | PREFIX_PRIORITY_B_OPT, 0, 0); |
3994 | } |
3995 | } |
3996 | |
3997 | add_prefix (&exec_prefixes, value, NULL( ( void * ) 0 ), |
3998 | PREFIX_PRIORITY_B_OPT, 0, 0); |
3999 | add_prefix (&startfile_prefixes, value, NULL( ( void * ) 0 ), |
4000 | PREFIX_PRIORITY_B_OPT, 0, 0); |
4001 | add_prefix (&include_prefixes, value, NULL( ( void * ) 0 ), |
4002 | PREFIX_PRIORITY_B_OPT, 0, 0); |
4003 | n_switches++; |
4004 | } |
4005 | break; |
4006 | |
4007 | case 'v': /* Print our subcommands and print versions. */ |
4008 | n_switches++; |
4009 | /* If they do anything other than exactly `-v', don't set |
4010 | verbose_flag; rather, continue on to give the error. */ |
4011 | if (p[1] != 0) |
4012 | break; |
4013 | verbose_flag++; |
4014 | break; |
4015 | |
4016 | case 'S': |
4017 | case 'c': |
4018 | if (p[1] == 0) |
4019 | { |
4020 | have_c = 1; |
4021 | n_switches++; |
4022 | break; |
4023 | } |
4024 | goto normal_switch; |
4025 | |
4026 | case 'o': |
4027 | have_o = 1; |
4028 | #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) |
4029 | if (! have_c) |
4030 | { |
4031 | int skip; |
4032 | |
4033 | /* Forward scan, just in case -S or -c is specified |
4034 | after -o. */ |
4035 | int j = i + 1; |
4036 | if (p[1] == 0) |
4037 | ++j; |
4038 | while (j < argc) |
4039 | { |
4040 | if (argv[j][0] == '-') |
4041 | { |
4042 | if (SWITCH_CURTAILS_COMPILATION (argv[j][1]) |
4043 | && argv[j][2] == 0) |
4044 | { |
4045 | have_c = 1; |
4046 | break; |
4047 | } |
4048 | else if ((skip = SWITCH_TAKES_ARG (argv[j][1]))) |
4049 | j += skip - (argv[j][2] != 0); |
4050 | else if ((skip = WORD_SWITCH_TAKES_ARG (argv[j] + 1))) |
4051 | j += skip; |
4052 | } |
4053 | j++; |
4054 | } |
4055 | } |
4056 | #endif |
4057 | #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) || defined(HAVE_TARGET_OBJECT_SUFFIX) |
4058 | if (p[1] == 0) |
4059 | argv[i + 1] = convert_filename (argv[i + 1], ! have_c, 0); |
4060 | else |
4061 | argv[i] = convert_filename (argv[i], ! have_c, 0); |
4062 | #endif |
4063 | goto normal_switch; |
4064 | |
4065 | default: |
4066 | normal_switch: |
4067 | |
4068 | #ifdef MODIFY_TARGET_NAME |
4069 | is_modify_target_name = 0; |
4070 | |
4071 | for (j = 0; j < ARRAY_SIZE (modify_target); j++) |
4072 | if (! strcmp (argv[i], modify_target[j].sw)) |
4073 | { |
4074 | char *new_name = xmalloc (strlen (modify_target[j].str) |
4075 | + strlen (spec_machine)); |
4076 | const char *p, *r; |
4077 | char *q; |
4078 | int made_addition = 0; |
4079 | |
4080 | is_modify_target_name = 1; |
4081 | for (p = spec_machine, q = new_name; *p != 0; ) |
4082 | { |
4083 | if (modify_target[j].add_del == DELETE |
4084 | && (! strncmp (q, modify_target[j].str, |
4085 | strlen (modify_target[j].str)))) |
4086 | p += strlen (modify_target[j].str); |
4087 | else if (modify_target[j].add_del == ADD |
4088 | && ! made_addition && *p == '-') |
4089 | { |
4090 | for (r = modify_target[j].str; *r != 0; ) |
4091 | *q++ = *r++; |
4092 | made_addition = 1; |
4093 | } |
4094 | |
4095 | *q++ = *p++; |
4096 | } |
4097 | |
4098 | spec_machine = new_name; |
4099 | } |
4100 | |
4101 | if (is_modify_target_name) |
4102 | break; |
4103 | #endif |
4104 | |
4105 | n_switches++; |
4106 | |
4107 | if (SWITCH_TAKES_ARG( ( c ) == 'D' || ( c ) == 'U' || ( c ) == 'o' || ( c ) == 'e' || ( c ) == 'T' || ( c ) == 'u' || ( c ) == 'I' || ( c ) == 'm' || ( c ) == 'x' || ( c ) == 'L' || ( c ) == 'A' || ( c ) == 'V' || ( c ) == 'F' || ( c ) == 'B' || ( c ) == 'b' ) (c) > (p[1] != 0)) |
4108 | i += SWITCH_TAKES_ARG( ( c ) == 'D' || ( c ) == 'U' || ( c ) == 'o' || ( c ) == 'e' || ( c ) == 'T' || ( c ) == 'u' || ( c ) == 'I' || ( c ) == 'm' || ( c ) == 'x' || ( c ) == 'L' || ( c ) == 'A' || ( c ) == 'V' || ( c ) == 'F' || ( c ) == 'B' || ( c ) == 'b' ) (c) - (p[1] != 0); |
4109 | else if (WORD_SWITCH_TAKES_ARG( ( ! strcmp ( p , "Tdata" ) || ! strcmp ( p , "Ttext" ) || ! strcmp ( p , "Tbss" ) || ! strcmp ( p , "include" ) || ! strcmp ( p , "imacros" ) || ! strcmp ( p , "aux-info" ) || ! strcmp ( p , "idirafter" ) || ! strcmp ( p , "iprefix" ) || ! strcmp ( p , "iwithprefix" ) || ! strcmp ( p , "iwithprefixbefore" ) || ! strcmp ( p , "iquote" ) || ! strcmp ( p , "isystem" ) || ! strcmp ( p , "isysroot" ) || ! strcmp ( p , "-param" ) || ! strcmp ( p , "specs" ) || ! strcmp ( p , "MF" ) || ! strcmp ( p , "MT" ) || ! strcmp ( p , "MQ" ) ) ? 1 : ! strcmp ( p , "Zallowable_client" ) ? 1 : ! strcmp ( p , "arch" ) ? 1 : ! strcmp ( p , "arch_only" ) ? 1 : ! strcmp ( p , "Zbundle_loader" ) ? 1 : ! strcmp ( p , "client_name" ) ? 1 : ! strcmp ( p , "compatibility_version" ) ? 1 : ! strcmp ( p , "current_version" ) ? 1 : ! strcmp ( p , "Zdylib_file" ) ? 1 : ! strcmp ( p , "Zexported_symbols_list" ) ? 1 : ! strcmp ( p , "Zimage_base" ) ? 1 : ! strcmp ( p , "Zinit" ) ? 1 : ! strcmp ( p , "Zinstall_name" ) ? 1 : ! strcmp ( p , "Zmllvm" ) ? 1 : ! strcmp ( p , "Zmultiplydefinedunused" ) ? 1 : ! strcmp ( p , "Zmultiply_defined" ) ? 1 : ! strcmp ( p , "precomp-trustfile" ) ? 1 : ! strcmp ( p , "read_only_relocs" ) ? 1 : ! strcmp ( p , "sectcreate" ) ? 3 : ! strcmp ( p , "sectorder" ) ? 3 : ! strcmp ( p , "Zsegaddr" ) ? 2 : ! strcmp ( p , "Zsegs_read_only_addr" ) ? 1 : ! strcmp ( p , "Zsegs_read_write_addr" ) ? 1 : ! strcmp ( p , "Zseg_addr_table" ) ? 1 : ! strcmp ( p , "Zfn_seg_addr_table_filename" ) ? 1 : ! strcmp ( p , "seg1addr" ) ? 1 : ! strcmp ( p , "segprot" ) ? 3 : ! strcmp ( p , "sub_library" ) ? 1 : ! strcmp ( p , "sub_umbrella" ) ? 1 : ! strcmp ( p , "Zumbrella" ) ? 1 : ! strcmp ( p , "undefined" ) ? 1 : ! strcmp ( p , "Zunexported_symbols_list" ) ? 1 : ! strcmp ( p , "Zweak_reference_mismatches" ) ? 1 : ! strcmp ( p , "pagezero_size" ) ? 1 : ! strcmp ( p , "segs_read_only_addr" ) ? 1 : ! strcmp ( p , "segs_read_write_addr" ) ? 1 : ! strcmp ( p , "sectalign" ) ? 3 : ! strcmp ( p , "sectobjectsymbols" ) ? 2 : ! strcmp ( p , "segcreate" ) ? 3 : ! strcmp ( p , "dylinker_install_name" ) ? 1 : 0 ) (p)) |
4110 | i += WORD_SWITCH_TAKES_ARG( ( ! strcmp ( p , "Tdata" ) || ! strcmp ( p , "Ttext" ) || ! strcmp ( p , "Tbss" ) || ! strcmp ( p , "include" ) || ! strcmp ( p , "imacros" ) || ! strcmp ( p , "aux-info" ) || ! strcmp ( p , "idirafter" ) || ! strcmp ( p , "iprefix" ) || ! strcmp ( p , "iwithprefix" ) || ! strcmp ( p , "iwithprefixbefore" ) || ! strcmp ( p , "iquote" ) || ! strcmp ( p , "isystem" ) || ! strcmp ( p , "isysroot" ) || ! strcmp ( p , "-param" ) || ! strcmp ( p , "specs" ) || ! strcmp ( p , "MF" ) || ! strcmp ( p , "MT" ) || ! strcmp ( p , "MQ" ) ) ? 1 : ! strcmp ( p , "Zallowable_client" ) ? 1 : ! strcmp ( p , "arch" ) ? 1 : ! strcmp ( p , "arch_only" ) ? 1 : ! strcmp ( p , "Zbundle_loader" ) ? 1 : ! strcmp ( p , "client_name" ) ? 1 : ! strcmp ( p , "compatibility_version" ) ? 1 : ! strcmp ( p , "current_version" ) ? 1 : ! strcmp ( p , "Zdylib_file" ) ? 1 : ! strcmp ( p , "Zexported_symbols_list" ) ? 1 : ! strcmp ( p , "Zimage_base" ) ? 1 : ! strcmp ( p , "Zinit" ) ? 1 : ! strcmp ( p , "Zinstall_name" ) ? 1 : ! strcmp ( p , "Zmllvm" ) ? 1 : ! strcmp ( p , "Zmultiplydefinedunused" ) ? 1 : ! strcmp ( p , "Zmultiply_defined" ) ? 1 : ! strcmp ( p , "precomp-trustfile" ) ? 1 : ! strcmp ( p , "read_only_relocs" ) ? 1 : ! strcmp ( p , "sectcreate" ) ? 3 : ! strcmp ( p , "sectorder" ) ? 3 : ! strcmp ( p , "Zsegaddr" ) ? 2 : ! strcmp ( p , "Zsegs_read_only_addr" ) ? 1 : ! strcmp ( p , "Zsegs_read_write_addr" ) ? 1 : ! strcmp ( p , "Zseg_addr_table" ) ? 1 : ! strcmp ( p , "Zfn_seg_addr_table_filename" ) ? 1 : ! strcmp ( p , "seg1addr" ) ? 1 : ! strcmp ( p , "segprot" ) ? 3 : ! strcmp ( p , "sub_library" ) ? 1 : ! strcmp ( p , "sub_umbrella" ) ? 1 : ! strcmp ( p , "Zumbrella" ) ? 1 : ! strcmp ( p , "undefined" ) ? 1 : ! strcmp ( p , "Zunexported_symbols_list" ) ? 1 : ! strcmp ( p , "Zweak_reference_mismatches" ) ? 1 : ! strcmp ( p , "pagezero_size" ) ? 1 : ! strcmp ( p , "segs_read_only_addr" ) ? 1 : ! strcmp ( p , "segs_read_write_addr" ) ? 1 : ! strcmp ( p , "sectalign" ) ? 3 : ! strcmp ( p , "sectobjectsymbols" ) ? 2 : ! strcmp ( p , "segcreate" ) ? 3 : ! strcmp ( p , "dylinker_install_name" ) ? 1 : 0 ) (p); |
4111 | } |
4112 | } |
4113 | else |
4114 | { |
4115 | n_infiles++; |
4116 | lang_n_infiles++; |
4117 | } |
4118 | } |
4119 | |
4120 | if (save_temps_flag && use_pipes) |
4121 | { |
4122 | /* -save-temps overrides -pipe, so that temp files are produced */ |
4123 | if (save_temps_flag) |
4124 | error ("warning: -pipe ignored because -save-temps specified"); |
4125 | use_pipes = 0; |
4126 | } |
4127 | |
4128 | /* Set up the search paths before we go looking for config files. */ |
4129 | |
4130 | /* These come before the md prefixes so that we will find gcc's subcommands |
4131 | (such as cpp) rather than those of the host system. */ |
4132 | /* Use 2 as fourth arg meaning try just the machine as a suffix, |
4133 | as well as trying the machine and the version. */ |
4134 | #ifndef OS2 |
4135 | add_prefix (&exec_prefixes, standard_libexec_prefix, "GCC", |
4136 | PREFIX_PRIORITY_LAST, 1, 0); |
4137 | add_prefix (&exec_prefixes, standard_libexec_prefix, "BINUTILS", |
4138 | PREFIX_PRIORITY_LAST, 2, 0); |
4139 | add_prefix (&exec_prefixes, standard_exec_prefix, "BINUTILS", |
4140 | PREFIX_PRIORITY_LAST, 2, 0); |
4141 | add_prefix (&exec_prefixes, standard_exec_prefix_1, "BINUTILS", |
4142 | PREFIX_PRIORITY_LAST, 2, 0); |
4143 | add_prefix (&exec_prefixes, standard_exec_prefix_2, "BINUTILS", |
4144 | PREFIX_PRIORITY_LAST, 2, 0); |
4145 | #endif |
4146 | |
4147 | add_prefix (&startfile_prefixes, standard_exec_prefix, "BINUTILS", |
4148 | PREFIX_PRIORITY_LAST, 1, 0); |
4149 | add_prefix (&startfile_prefixes, standard_exec_prefix_2, "BINUTILS", |
4150 | PREFIX_PRIORITY_LAST, 1, 0); |
4151 | |
4152 | tooldir_prefix = concat (tooldir_base_prefix, spec_machine, |
4153 | dir_separator_str, NULL( ( void * ) 0 )); |
4154 | |
4155 | /* If tooldir is relative, base it on exec_prefixes. A relative |
4156 | tooldir lets us move the installed tree as a unit. |
4157 | |
4158 | If GCC_EXEC_PREFIX is defined, then we want to add two relative |
4159 | directories, so that we can search both the user specified directory |
4160 | and the standard place. */ |
4161 | |
4162 | if (!IS_ABSOLUTE_PATH( ( ( ( tooldir_prefix ) [ 0 ] ) == '/' ) ) (tooldir_prefix)) |
4163 | { |
4164 | if (gcc_exec_prefix) |
4165 | { |
4166 | char *gcc_exec_tooldir_prefix |
4167 | = concat (gcc_exec_prefix, spec_machine, dir_separator_str, |
4168 | spec_version, dir_separator_str, tooldir_prefix, NULL( ( void * ) 0 )); |
4169 | |
4170 | add_prefix (&exec_prefixes, |
4171 | concat (gcc_exec_tooldir_prefix, "bin", |
4172 | dir_separator_str, NULL( ( void * ) 0 )), |
4173 | NULL( ( void * ) 0 ), PREFIX_PRIORITY_LAST, 0, 0); |
4174 | add_prefix (&startfile_prefixes, |
4175 | concat (gcc_exec_tooldir_prefix, "lib", |
4176 | dir_separator_str, NULL( ( void * ) 0 )), |
4177 | NULL( ( void * ) 0 ), PREFIX_PRIORITY_LAST, 0, 1); |
4178 | } |
4179 | |
4180 | tooldir_prefix = concat (standard_exec_prefix, spec_machine, |
4181 | dir_separator_str, spec_version, |
4182 | dir_separator_str, tooldir_prefix, NULL( ( void * ) 0 )); |
4183 | } |
4184 | |
4185 | add_prefix (&exec_prefixes, |
4186 | concat (tooldir_prefix, "bin", dir_separator_str, NULL( ( void * ) 0 )), |
4187 | "BINUTILS", PREFIX_PRIORITY_LAST, 0, 0); |
4188 | add_prefix (&startfile_prefixes, |
4189 | concat (tooldir_prefix, "lib", dir_separator_str, NULL( ( void * ) 0 )), |
4190 | "BINUTILS", PREFIX_PRIORITY_LAST, 0, 1); |
4191 | |
4192 | #if defined(TARGET_SYSTEM_ROOT_RELOCATABLE) && !defined(VMS) |
4193 | /* If the normal TARGET_SYSTEM_ROOT is inside of $exec_prefix, |
4194 | then consider it to relocate with the rest of the GCC installation |
4195 | if GCC_EXEC_PREFIX is set. |
4196 | ``make_relative_prefix'' is not compiled for VMS, so don't call it. */ |
4197 | if (target_system_root && gcc_exec_prefix) |
4198 | { |
4199 | char *tmp_prefix = make_relative_prefix (argv[0], |
4200 | standard_bindir_prefix, |
4201 | target_system_root); |
4202 | if (tmp_prefix && access_check (tmp_prefix, F_OK) == 0) |
4203 | { |
4204 | target_system_root = tmp_prefix; |
4205 | target_system_root_changed = 1; |
4206 | } |
4207 | } |
4208 | #endif |
4209 | |
4210 | /* More prefixes are enabled in main, after we read the specs file |
4211 | and determine whether this is cross-compilation or not. */ |
4212 | |
4213 | /* Then create the space for the vectors and scan again. */ |
4214 | |
4215 | switches = XNEWVEC( ( struct switchstr * ) xmalloc ( sizeof ( struct switchstr ) * ( n_switches + 1 ) ) ) (struct switchstr, n_switches + 1); |
4216 | infiles = XNEWVEC( ( struct infile * ) xmalloc ( sizeof ( struct infile ) * ( n_infiles + 1 ) ) ) (struct infile, n_infiles + 1); |
4217 | n_switches = 0; |
4218 | n_infiles = 0; |
4219 | last_language_n_infiles = -1; |
4220 | |
4221 | /* This, time, copy the text of each switch and store a pointer |
4222 | to the copy in the vector of switches. |
4223 | Store all the infiles in their vector. */ |
4224 | |
4225 | for (i = 1; i < argc; i++) |
4226 | { |
4227 | /* Just skip the switches that were handled by the preceding loop. */ |
4228 | #ifdef MODIFY_TARGET_NAME |
4229 | is_modify_target_name = 0; |
4230 | |
4231 | for (j = 0; j < ARRAY_SIZE (modify_target); j++) |
4232 | if (! strcmp (argv[i], modify_target[j].sw)) |
4233 | is_modify_target_name = 1; |
4234 | |
4235 | if (is_modify_target_name) |
4236 | ; |
4237 | else |
4238 | #endif |
4239 | if (! strncmp (argv[i], "-Wa,", 4)) |
4240 | ; |
4241 | else if (! strncmp (argv[i], "-Wp,", 4)) |
4242 | ; |
4243 | else if (! strcmp (argv[i], "-pass-exit-codes")) |
4244 | ; |
4245 | else if (! strcmp (argv[i], "-print-search-dirs")) |
4246 | ; |
4247 | else if (! strcmp (argv[i], "-print-libgcc-file-name")) |
4248 | ; |
4249 | else if (! strncmp (argv[i], "-print-file-name=", 17)) |
4250 | ; |
4251 | else if (! strncmp (argv[i], "-print-prog-name=", 17)) |
4252 | ; |
4253 | else if (! strcmp (argv[i], "-print-multi-lib")) |
4254 | ; |
4255 | else if (! strcmp (argv[i], "-print-multi-directory")) |
4256 | ; |
4257 | else if (! strcmp (argv[i], "-print-multi-os-directory")) |
4258 | ; |
4259 | else if (! strcmp (argv[i], "-ftarget-help")) |
4260 | ; |
4261 | else if (! strcmp (argv[i], "-fhelp")) |
4262 | ; |
4263 | else if (! strncmp (argv[i], "--sysroot=", strlen ("--sysroot="))) |
4264 | { |
4265 | target_system_root = argv[i] + strlen ("--sysroot="); |
4266 | target_system_root_changed = 1; |
4267 | } |
4268 | else if (argv[i][0] == '+' && argv[i][1] == 'e') |
4269 | { |
4270 | /* Compensate for the +e options to the C++ front-end; |
4271 | they're there simply for cfront call-compatibility. We do |
4272 | some magic in default_compilers to pass them down properly. |
4273 | Note we deliberately start at the `+' here, to avoid passing |
4274 | -e0 or -e1 down into the linker. */ |
4275 | switches[n_switches].part1 = &argv[i][0]; |
4276 | switches[n_switches].args = 0; |
4277 | switches[n_switches].live_cond = SWITCH_OK0; |
4278 | switches[n_switches].validated = 0; |
4279 | n_switches++; |
4280 | } |
4281 | else if (strncmp (argv[i], "-Wl,", 4) == 0) |
4282 | { |
4283 | int prev, j; |
4284 | /* Split the argument at commas. */ |
4285 | prev = 4; |
4286 | for (j = 4; argv[i][j]; j++) |
4287 | if (argv[i][j] == ',') |
4288 | { |
4289 | infiles[n_infiles].language = "*"; |
4290 | infiles[n_infiles++].name |
4291 | = save_string (argv[i] + prev, j - prev); |
4292 | prev = j + 1; |
4293 | } |
4294 | /* Record the part after the last comma. */ |
4295 | infiles[n_infiles].language = "*"; |
4296 | infiles[n_infiles++].name = argv[i] + prev; |
4297 | } |
4298 | else if (strcmp (argv[i], "-Xlinker") == 0) |
4299 | { |
4300 | infiles[n_infiles].language = "*"; |
4301 | infiles[n_infiles++].name = argv[++i]; |
4302 | } |
4303 | /* Xassembler and Xpreprocessor were already handled in the first argv |
4304 | scan, so all we need to do here is ignore them and their argument. */ |
4305 | else if (strcmp (argv[i], "-Xassembler") == 0) |
4306 | i++; |
4307 | else if (strcmp (argv[i], "-Xpreprocessor") == 0) |
4308 | i++; |
4309 | else if (strcmp (argv[i], "-l") == 0) |
4310 | { /* POSIX allows separation of -l and the lib arg; |
4311 | canonicalize by concatenating -l with its arg */ |
4312 | infiles[n_infiles].language = "*"; |
4313 | infiles[n_infiles++].name = concat ("-l", argv[++i], NULL( ( void * ) 0 )); |
4314 | } |
4315 | else if (strncmp (argv[i], "-l", 2) == 0) |
4316 | { |
4317 | infiles[n_infiles].language = "*"; |
4318 | infiles[n_infiles++].name = argv[i]; |
4319 | } |
4320 | /* APPLE LOCAL begin -weak_* (radar 3235250) */ |
4321 | else if (strncmp (argv[i], "-weak-l", 7) == 0) |
4322 | { |
4323 | infiles[n_infiles].language = "*"; |
4324 | infiles[n_infiles++].name = argv[i]; |
4325 | } |
4326 | else if (strcmp (argv[i], "-weak_library") == 0) |
4327 | { |
4328 | infiles[n_infiles].language = "*"; |
4329 | infiles[n_infiles++].name = argv[i]; |
4330 | infiles[n_infiles].language = "*"; |
4331 | infiles[n_infiles++].name = argv[++i]; |
4332 | } |
4333 | else if (strcmp (argv[i], "-weak_framework") == 0) |
4334 | { |
4335 | infiles[n_infiles].language = "*"; |
4336 | infiles[n_infiles++].name = argv[i]; |
4337 | infiles[n_infiles].language = "*"; |
4338 | infiles[n_infiles++].name = argv[++i]; |
4339 | } |
4340 | /* APPLE LOCAL end -weak_* (radar #3235250) */ |
4341 | else if (strcmp (argv[i], "-specs") == 0) |
4342 | i++; |
4343 | else if (strncmp (argv[i], "-specs=", 7) == 0) |
4344 | ; |
4345 | /* APPLE LOCAL begin -ObjC 2001-08-03 --sts */ |
4346 | else if (!strcmp (argv[i], "-ObjC") || !strcmp (argv[i], "-fobjc")) |
4347 | { |
4348 | default_language = "objective-c"; |
4349 | add_linker_option ("-ObjC", 5); |
4350 | } |
4351 | else if (strcmp (argv[i], "-ObjC++") == 0) |
4352 | { |
4353 | default_language = "objective-c++"; |
4354 | add_linker_option ("-ObjC", 5); |
4355 | } |
4356 | /* APPLE LOCAL end -ObjC 2001-08-03 --sts */ |
4357 | else if (strcmp (argv[i], "-time") == 0) |
4358 | ; |
4359 | else if (strcmp (argv[i], "-###") == 0) |
4360 | ; |
4361 | /* APPLE LOCAL begin frameworks */ |
4362 | else if (strcmp (argv[i], "-framework") == 0) |
4363 | { |
4364 | infiles[n_infiles].language = "*"; |
4365 | infiles[n_infiles++].name = argv[i]; |
4366 | infiles[n_infiles].language = "*"; |
4367 | infiles[n_infiles++].name = argv[++i]; |
4368 | } |
4369 | /* APPLE LOCAL end frameworks */ |
4370 | else if (argv[i][0] == '-' && argv[i][1] != 0) |
4371 | { |
4372 | const char *p = &argv[i][1]; |
4373 | int c = *p; |
4374 | |
4375 | if (c == 'x') |
4376 | { |
4377 | if (p[1] == 0 && i + 1 == argc) |
4378 | fatal ("argument to '-x' is missing"); |
4379 | if (p[1] == 0) |
4380 | spec_lang = argv[++i]; |
4381 | else |
4382 | spec_lang = p + 1; |
4383 | if (! strcmp (spec_lang, "none")) |
4384 | /* Suppress the warning if -xnone comes after the last input |
4385 | file, because alternate command interfaces like g++ might |
4386 | find it useful to place -xnone after each input file. */ |
4387 | spec_lang = 0; |
4388 | else |
4389 | last_language_n_infiles = n_infiles; |
4390 | continue; |
4391 | } |
4392 | switches[n_switches].part1 = p; |
4393 | /* Deal with option arguments in separate argv elements. */ |
4394 | if ((SWITCH_TAKES_ARG( ( c ) == 'D' || ( c ) == 'U' || ( c ) == 'o' || ( c ) == 'e' || ( c ) == 'T' || ( c ) == 'u' || ( c ) == 'I' || ( c ) == 'm' || ( c ) == 'x' || ( c ) == 'L' || ( c ) == 'A' || ( c ) == 'V' || ( c ) == 'F' || ( c ) == 'B' || ( c ) == 'b' ) (c) > (p[1] != 0)) |
4395 | || WORD_SWITCH_TAKES_ARG( ( ! strcmp ( p , "Tdata" ) || ! strcmp ( p , "Ttext" ) || ! strcmp ( p , "Tbss" ) || ! strcmp ( p , "include" ) || ! strcmp ( p , "imacros" ) || ! strcmp ( p , "aux-info" ) || ! strcmp ( p , "idirafter" ) || ! strcmp ( p , "iprefix" ) || ! strcmp ( p , "iwithprefix" ) || ! strcmp ( p , "iwithprefixbefore" ) || ! strcmp ( p , "iquote" ) || ! strcmp ( p , "isystem" ) || ! strcmp ( p , "isysroot" ) || ! strcmp ( p , "-param" ) || ! strcmp ( p , "specs" ) || ! strcmp ( p , "MF" ) || ! strcmp ( p , "MT" ) || ! strcmp ( p , "MQ" ) ) ? 1 : ! strcmp ( p , "Zallowable_client" ) ? 1 : ! strcmp ( p , "arch" ) ? 1 : ! strcmp ( p , "arch_only" ) ? 1 : ! strcmp ( p , "Zbundle_loader" ) ? 1 : ! strcmp ( p , "client_name" ) ? 1 : ! strcmp ( p , "compatibility_version" ) ? 1 : ! strcmp ( p , "current_version" ) ? 1 : ! strcmp ( p , "Zdylib_file" ) ? 1 : ! strcmp ( p , "Zexported_symbols_list" ) ? 1 : ! strcmp ( p , "Zimage_base" ) ? 1 : ! strcmp ( p , "Zinit" ) ? 1 : ! strcmp ( p , "Zinstall_name" ) ? 1 : ! strcmp ( p , "Zmllvm" ) ? 1 : ! strcmp ( p , "Zmultiplydefinedunused" ) ? 1 : ! strcmp ( p , "Zmultiply_defined" ) ? 1 : ! strcmp ( p , "precomp-trustfile" ) ? 1 : ! strcmp ( p , "read_only_relocs" ) ? 1 : ! strcmp ( p , "sectcreate" ) ? 3 : ! strcmp ( p , "sectorder" ) ? 3 : ! strcmp ( p , "Zsegaddr" ) ? 2 : ! strcmp ( p , "Zsegs_read_only_addr" ) ? 1 : ! strcmp ( p , "Zsegs_read_write_addr" ) ? 1 : ! strcmp ( p , "Zseg_addr_table" ) ? 1 : ! strcmp ( p , "Zfn_seg_addr_table_filename" ) ? 1 : ! strcmp ( p , "seg1addr" ) ? 1 : ! strcmp ( p , "segprot" ) ? 3 : ! strcmp ( p , "sub_library" ) ? 1 : ! strcmp ( p , "sub_umbrella" ) ? 1 : ! strcmp ( p , "Zumbrella" ) ? 1 : ! strcmp ( p , "undefined" ) ? 1 : ! strcmp ( p , "Zunexported_symbols_list" ) ? 1 : ! strcmp ( p , "Zweak_reference_mismatches" ) ? 1 : ! strcmp ( p , "pagezero_size" ) ? 1 : ! strcmp ( p , "segs_read_only_addr" ) ? 1 : ! strcmp ( p , "segs_read_write_addr" ) ? 1 : ! strcmp ( p , "sectalign" ) ? 3 : ! strcmp ( p , "sectobjectsymbols" ) ? 2 : ! strcmp ( p , "segcreate" ) ? 3 : ! strcmp ( p , "dylinker_install_name" ) ? 1 : 0 ) (p)) |
4396 | { |
4397 | int j = 0; |
4398 | int n_args = WORD_SWITCH_TAKES_ARG( ( ! strcmp ( p , "Tdata" ) || ! strcmp ( p , "Ttext" ) || ! strcmp ( p , "Tbss" ) || ! strcmp ( p , "include" ) || ! strcmp ( p , "imacros" ) || ! strcmp ( p , "aux-info" ) || ! strcmp ( p , "idirafter" ) || ! strcmp ( p , "iprefix" ) || ! strcmp ( p , "iwithprefix" ) || ! strcmp ( p , "iwithprefixbefore" ) || ! strcmp ( p , "iquote" ) || ! strcmp ( p , "isystem" ) || ! strcmp ( p , "isysroot" ) || ! strcmp ( p , "-param" ) || ! strcmp ( p , "specs" ) || ! strcmp ( p , "MF" ) || ! strcmp ( p , "MT" ) || ! strcmp ( p , "MQ" ) ) ? 1 : ! strcmp ( p , "Zallowable_client" ) ? 1 : ! strcmp ( p , "arch" ) ? 1 : ! strcmp ( p , "arch_only" ) ? 1 : ! strcmp ( p , "Zbundle_loader" ) ? 1 : ! strcmp ( p , "client_name" ) ? 1 : ! strcmp ( p , "compatibility_version" ) ? 1 : ! strcmp ( p , "current_version" ) ? 1 : ! strcmp ( p , "Zdylib_file" ) ? 1 : ! strcmp ( p , "Zexported_symbols_list" ) ? 1 : ! strcmp ( p , "Zimage_base" ) ? 1 : ! strcmp ( p , "Zinit" ) ? 1 : ! strcmp ( p , "Zinstall_name" ) ? 1 : ! strcmp ( p , "Zmllvm" ) ? 1 : ! strcmp ( p , "Zmultiplydefinedunused" ) ? 1 : ! strcmp ( p , "Zmultiply_defined" ) ? 1 : ! strcmp ( p , "precomp-trustfile" ) ? 1 : ! strcmp ( p , "read_only_relocs" ) ? 1 : ! strcmp ( p , "sectcreate" ) ? 3 : ! strcmp ( p , "sectorder" ) ? 3 : ! strcmp ( p , "Zsegaddr" ) ? 2 : ! strcmp ( p , "Zsegs_read_only_addr" ) ? 1 : ! strcmp ( p , "Zsegs_read_write_addr" ) ? 1 : ! strcmp ( p , "Zseg_addr_table" ) ? 1 : ! strcmp ( p , "Zfn_seg_addr_table_filename" ) ? 1 : ! strcmp ( p , "seg1addr" ) ? 1 : ! strcmp ( p , "segprot" ) ? 3 : ! strcmp ( p , "sub_library" ) ? 1 : ! strcmp ( p , "sub_umbrella" ) ? 1 : ! strcmp ( p , "Zumbrella" ) ? 1 : ! strcmp ( p , "undefined" ) ? 1 : ! strcmp ( p , "Zunexported_symbols_list" ) ? 1 : ! strcmp ( p , "Zweak_reference_mismatches" ) ? 1 : ! strcmp ( p , "pagezero_size" ) ? 1 : ! strcmp ( p , "segs_read_only_addr" ) ? 1 : ! strcmp ( p , "segs_read_write_addr" ) ? 1 : ! strcmp ( p , "sectalign" ) ? 3 : ! strcmp ( p , "sectobjectsymbols" ) ? 2 : ! strcmp ( p , "segcreate" ) ? 3 : ! strcmp ( p , "dylinker_install_name" ) ? 1 : 0 ) (p); |
4399 | |
4400 | if (n_args == 0) |
4401 | { |
4402 | /* Count only the option arguments in separate argv elements. */ |
4403 | n_args = SWITCH_TAKES_ARG( ( c ) == 'D' || ( c ) == 'U' || ( c ) == 'o' || ( c ) == 'e' || ( c ) == 'T' || ( c ) == 'u' || ( c ) == 'I' || ( c ) == 'm' || ( c ) == 'x' || ( c ) == 'L' || ( c ) == 'A' || ( c ) == 'V' || ( c ) == 'F' || ( c ) == 'B' || ( c ) == 'b' ) (c) - (p[1] != 0); |
4404 | } |
4405 | if (i + n_args >= argc) |
4406 | fatal ("argument to '-%s' is missing", p); |
4407 | switches[n_switches].args |
4408 | = XNEWVEC( ( const char * * ) xmalloc ( sizeof ( const char * ) * ( n_args + 1 ) ) ) (const char *, n_args + 1); |
4409 | while (j < n_args) |
4410 | switches[n_switches].args[j++] = argv[++i]; |
4411 | /* Null-terminate the vector. */ |
4412 | switches[n_switches].args[j] = 0; |
4413 | } |
4414 | else if (strchr (switches_need_spaces, c)) |
4415 | { |
4416 | /* On some systems, ld cannot handle some options without |
4417 | a space. So split the option from its argument. */ |
4418 | char *part1 = XNEWVEC( ( char * ) xmalloc ( sizeof ( char ) * ( 2 ) ) ) (char, 2); |
4419 | part1[0] = c; |
4420 | part1[1] = '\0'; |
4421 | |
4422 | switches[n_switches].part1 = part1; |
4423 | switches[n_switches].args = XNEWVEC( ( const char * * ) xmalloc ( sizeof ( const char * ) * ( 2 ) ) ) (const char *, 2); |
4424 | switches[n_switches].args[0] = xstrdup (p+1); |
4425 | switches[n_switches].args[1] = 0; |
4426 | } |
4427 | else |
4428 | switches[n_switches].args = 0; |
4429 | |
4430 | switches[n_switches].live_cond = SWITCH_OK0; |
4431 | switches[n_switches].validated = 0; |
4432 | switches[n_switches].ordering = 0; |
4433 | /* These are always valid, since gcc.c itself understands them. */ |
4434 | if (!strcmp (p, "save-temps") |
4435 | || !strcmp (p, "static-libgcc") |
4436 | || !strcmp (p, "shared-libgcc") |
4437 | || !strcmp (p, "pipe")) |
4438 | switches[n_switches].validated = 1; |
4439 | else |
4440 | { |
4441 | char ch = switches[n_switches].part1[0]; |
4442 | if (ch == 'B') |
4443 | switches[n_switches].validated = 1; |
4444 | } |
4445 | n_switches++; |
4446 | } |
4447 | else |
4448 | { |
4449 | #ifdef HAVE_TARGET_OBJECT_SUFFIX |
4450 | argv[i] = convert_filename (argv[i], 0, access (argv[i], F_OK0)); |
4451 | #endif |
4452 | |
4453 | if (strcmp (argv[i], "-") != 0 && access (argv[i], F_OK0) < 0) |
4454 | { |
4455 | perror_with_name (argv[i]); |
4456 | error_count++; |
4457 | } |
4458 | else |
4459 | { |
4460 | infiles[n_infiles].language = spec_lang; |
4461 | infiles[n_infiles++].name = argv[i]; |
4462 | } |
4463 | } |
4464 | } |
4465 | |
4466 | if (n_infiles == last_language_n_infiles && spec_lang != 0) |
4467 | error ("warning: '-x %s' after last input file has no effect", spec_lang); |
4468 | |
4469 | /* Ensure we only invoke each subprocess once. */ |
4470 | if (target_help_flag || print_help_list) |
4471 | { |
4472 | n_infiles = 1; |
4473 | |
4474 | /* Create a dummy input file, so that we can pass --target-help on to |
4475 | the various sub-processes. */ |
4476 | infiles[0].language = "c"; |
4477 | infiles[0].name = "help-dummy"; |
4478 | |
4479 | if (target_help_flag) |
4480 | { |
4481 | switches[n_switches].part1 = "--target-help"; |
4482 | switches[n_switches].args = 0; |
4483 | switches[n_switches].live_cond = SWITCH_OK0; |
4484 | switches[n_switches].validated = 0; |
4485 | |
4486 | n_switches++; |
4487 | } |
4488 | |
4489 | if (print_help_list) |
4490 | { |
4491 | switches[n_switches].part1 = "--help"; |
4492 | switches[n_switches].args = 0; |
4493 | switches[n_switches].live_cond = SWITCH_OK0; |
4494 | switches[n_switches].validated = 0; |
4495 | |
4496 | n_switches++; |
4497 | } |
4498 | } |
4499 | |
4500 | switches[n_switches].part1 = 0; |
4501 | infiles[n_infiles].name = 0; |
4502 | } |
4503 | |
4504 | /* Store switches not filtered out by %<S in spec in COLLECT_GCC_OPTIONS |
4505 | and place that in the environment. */ |
4506 | |
4507 | static void |
4508 | set_collect_gcc_options (void) |
4509 | { |
4510 | int i; |
4511 | int first_time; |
4512 | |
4513 | /* Build COLLECT_GCC_OPTIONS to have all of the options specified to |
4514 | the compiler. */ |
4515 | obstack_grow__extension__ ( { struct obstack * __o = ( & collect_obstack ) ; int __len = ( sizeof ( "COLLECT_GCC_OPTIONS=" ) - 1 ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( "COLLECT_GCC_OPTIONS=" ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&collect_obstack, "COLLECT_GCC_OPTIONS=", |
4516 | sizeof ("COLLECT_GCC_OPTIONS=") - 1); |
4517 | |
4518 | first_time = TRUE1; |
4519 | for (i = 0; (int) i < n_switches; i++) |
4520 | { |
4521 | const char *const *args; |
4522 | const char *p, *q; |
4523 | if (!first_time) |
4524 | obstack_grow__extension__ ( { struct obstack * __o = ( & collect_obstack ) ; int __len = ( 1 ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( " " ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&collect_obstack, " ", 1); |
4525 | |
4526 | first_time = FALSE0; |
4527 | |
4528 | /* Ignore elided switches. */ |
4529 | if (switches[i].live_cond == SWITCH_IGNORE- 2) |
4530 | continue; |
4531 | |
4532 | obstack_grow__extension__ ( { struct obstack * __o = ( & collect_obstack ) ; int __len = ( 2 ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( "'-" ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&collect_obstack, "'-", 2); |
4533 | q = switches[i].part1; |
4534 | while ((p = strchr (q, '\''))) |
4535 | { |
4536 | obstack_grow__extension__ ( { struct obstack * __o = ( & collect_obstack ) ; int __len = ( p - q ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( q ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&collect_obstack, q, p - q); |
4537 | obstack_grow__extension__ ( { struct obstack * __o = ( & collect_obstack ) ; int __len = ( 4 ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( "'\\''" ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&collect_obstack, "'\\''", 4); |
4538 | q = ++p; |
4539 | } |
4540 | obstack_grow__extension__ ( { struct obstack * __o = ( & collect_obstack ) ; int __len = ( strlen ( q ) ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( q ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&collect_obstack, q, strlen (q)); |
4541 | obstack_grow__extension__ ( { struct obstack * __o = ( & collect_obstack ) ; int __len = ( 1 ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( "'" ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&collect_obstack, "'", 1); |
4542 | |
4543 | for (args = switches[i].args; args && *args; args++) |
4544 | { |
4545 | obstack_grow__extension__ ( { struct obstack * __o = ( & collect_obstack ) ; int __len = ( 2 ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( " '" ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&collect_obstack, " '", 2); |
4546 | q = *args; |
4547 | while ((p = strchr (q, '\''))) |
4548 | { |
4549 | obstack_grow__extension__ ( { struct obstack * __o = ( & collect_obstack ) ; int __len = ( p - q ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( q ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&collect_obstack, q, p - q); |
4550 | obstack_grow__extension__ ( { struct obstack * __o = ( & collect_obstack ) ; int __len = ( 4 ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( "'\\''" ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&collect_obstack, "'\\''", 4); |
4551 | q = ++p; |
4552 | } |
4553 | obstack_grow__extension__ ( { struct obstack * __o = ( & collect_obstack ) ; int __len = ( strlen ( q ) ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( q ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&collect_obstack, q, strlen (q)); |
4554 | obstack_grow__extension__ ( { struct obstack * __o = ( & collect_obstack ) ; int __len = ( 1 ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( "'" ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&collect_obstack, "'", 1); |
4555 | } |
4556 | } |
4557 | obstack_grow__extension__ ( { struct obstack * __o = ( & collect_obstack ) ; int __len = ( 1 ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( "\0" ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&collect_obstack, "\0", 1); |
4558 | putenv (XOBFINISH( ( char * ) __extension__ ( { struct obstack * __o1 = ( ( & collect_obstack ) ) ; void * value ; value = ( void * ) __o1 -> object_base ; if ( __o1 -> next_free == value ) __o1 -> maybe_empty_object = 1 ; __o1 -> next_free = ( ( ( ( ( __o1 -> next_free ) - ( char * ) 0 ) + __o1 -> alignment_mask ) & ~ ( __o1 -> alignment_mask ) ) + ( char * ) 0 ) ; if ( __o1 -> next_free - ( char * ) __o1 -> chunk > __o1 -> chunk_limit - ( char * ) __o1 -> chunk ) __o1 -> next_free = __o1 -> chunk_limit ; __o1 -> object_base = __o1 -> next_free ; value ; } ) ) (&collect_obstack, char *)); |
4559 | } |
4560 | |
4561 | /* Process a spec string, accumulating and running commands. */ |
4562 | |
4563 | /* These variables describe the input file name. |
4564 | input_file_number is the index on outfiles of this file, |
4565 | so that the output file name can be stored for later use by %o. |
4566 | input_basename is the start of the part of the input file |
4567 | sans all directory names, and basename_length is the number |
4568 | of characters starting there excluding the suffix .c or whatever. */ |
4569 | |
4570 | static const char *input_filename; |
4571 | static int input_file_number; |
4572 | size_t input_filename_length; |
4573 | static int basename_length; |
4574 | static int suffixed_basename_length; |
4575 | static const char *input_basename; |
4576 | static const char *input_suffix; |
4577 | #ifndef HOST_LACKS_INODE_NUMBERS |
4578 | static struct stat input_stat; |
4579 | #endif |
4580 | static int input_stat_set; |
4581 | |
4582 | /* The compiler used to process the current input file. */ |
4583 | static struct compiler *input_file_compiler; |
4584 | |
4585 | /* These are variables used within do_spec and do_spec_1. */ |
4586 | |
4587 | /* Nonzero if an arg has been started and not yet terminated |
4588 | (with space, tab or newline). */ |
4589 | static int arg_going; |
4590 | |
4591 | /* Nonzero means %d or %g has been seen; the next arg to be terminated |
4592 | is a temporary file name. */ |
4593 | static int delete_this_arg; |
4594 | |
4595 | /* Nonzero means %w has been seen; the next arg to be terminated |
4596 | is the output file name of this compilation. */ |
4597 | static int this_is_output_file; |
4598 | |
4599 | /* APPLE LOCAL begin %b/save-temps can clobber input file (radar 2871891) --ilr */ |
4600 | /* Nonzero if %b or %B has been seen; the next arg to be terminated |
4601 | is a temp file based on the input file's basename. This has |
4602 | the potential to be the same as the input file itself so we |
4603 | need to take precautions if it is. */ |
4604 | static int this_is_basename_derived_file = 0; |
4605 | /* APPLE LOCAL end %b/save-temps can clobber input file (radar 2871891) --ilr */ |
4606 | |
4607 | /* Nonzero means %s has been seen; the next arg to be terminated |
4608 | is the name of a library file and we should try the standard |
4609 | search dirs for it. */ |
4610 | static int this_is_library_file; |
4611 | |
4612 | /* Nonzero means that the input of this command is coming from a pipe. */ |
4613 | static int input_from_pipe; |
4614 | |
4615 | /* Nonnull means substitute this for any suffix when outputting a switches |
4616 | arguments. */ |
4617 | static const char *suffix_subst; |
4618 | |
4619 | /* Process the spec SPEC and run the commands specified therein. |
4620 | Returns 0 if the spec is successfully processed; -1 if failed. */ |
4621 | |
4622 | int |
4623 | do_spec (const char *spec) |
4624 | { |
4625 | int value; |
4626 | |
4627 | /* APPLE LOCAL begin %b/save-temps can clobber input file (radar 2871891) --ilr */ |
4628 | this_is_basename_derived_file = 0; |
4629 | /* APPLE LOCAL end %b/save-temps can clobber input file (radar 2871891) --ilr */ |
4630 | |
4631 | value = do_spec_2 (spec); |
4632 | |
4633 | /* Force out any unfinished command. |
4634 | If -pipe, this forces out the last command if it ended in `|'. */ |
4635 | if (value == 0) |
4636 | { |
4637 | if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|")) |
4638 | argbuf_index--; |
4639 | |
4640 | set_collect_gcc_options (); |
4641 | |
4642 | if (argbuf_index > 0) |
4643 | value = execute (); |
4644 | } |
4645 | |
4646 | return value; |
4647 | } |
4648 | |
4649 | /* APPLE LOCAL begin %b/save-temps can clobber input file (radar 2871891) --ilr */ |
4650 | /* For %b and %B specs, which create a filename based on the input |
4651 | file's basename, there is a possibility that the resulting file |
4652 | is the same as the input file. Assuming that such names are |
4653 | intended to be used as intermediate (temporary) files there is |
4654 | the risk of clobbering the input file. We check for that here |
4655 | and use a temp file instead if that would happen. */ |
4656 | |
4657 | static const char * |
4658 | check_basename_derived_file (const char *string) |
4659 | { |
4660 | int suffix_length, string_length; |
4661 | const char *suffix; |
4662 | |
4663 | static struct base_temp_name { |
4664 | int suffix_length; |
4665 | int filename_length; |
4666 | const char *filename; |
4667 | struct base_temp_name *next; |
4668 | } *t, *base_temp_names = NULL( ( void * ) 0 ); |
4669 | |
4670 | /* LLVM LOCAL: apple local portability problem */ |
4671 | #ifndef HOST_LACKS_INODE_NUMBERS |
4672 | if (strcmp (string, input_filename) != 0) |
4673 | { |
4674 | struct stat st_temp; |
4675 | |
4676 | /* Note, set_input() resets input_stat_set to 0. This can also |
4677 | be done buy or for %U, %u, and %g. */ |
4678 | if (input_stat_set == 0) |
4679 | { |
4680 | input_stat_set = stat (input_filename, &input_stat); |
4681 | if (input_stat_set >= 0) |
4682 | input_stat_set = 1; |
4683 | } |
4684 | |
4685 | if (input_stat_set != 1 |
4686 | || stat (string, &st_temp) < 0 |
4687 | || input_stat.st_dev != st_temp.st_dev |
4688 | || input_stat.st_ino != st_temp.st_ino) |
4689 | { |
4690 | this_is_basename_derived_file = 0; |
4691 | return string; |
4692 | } |
4693 | } |
4694 | /* LLVM LOCAL begin: apple local portability problem */ |
4695 | #else |
4696 | /* This should be fixed sometimes for normal operation */ |
4697 | this_is_basename_derived_file = 0; |
4698 | return string; |
4699 | #endif |
4700 | /* LLVM LOCAL end: apple local portability problem */ |
4701 | |
4702 | string_length = strlen (string); |
4703 | suffix_length = string_length - basename_length; |
4704 | suffix = string + string_length - suffix_length; |
4705 | |
4706 | if (suffix_length > 0) |
4707 | { |
4708 | for (t = base_temp_names; t; t = t->next) |
4709 | if (t->suffix_length == suffix_length |
4710 | && strcmp (t->filename + t->filename_length - suffix_length, |
4711 | suffix) == 0) |
4712 | break; |
4713 | } |
4714 | else |
4715 | t = NULL( ( void * ) 0 ); |
4716 | |
4717 | if (!t) |
4718 | { |
4719 | t = (struct base_temp_name *) xmalloc (sizeof (struct base_temp_name)); |
4720 | t->next = base_temp_names; |
4721 | base_temp_names = t; |
4722 | |
4723 | t->filename = make_temp_file (suffix); |
4724 | t->filename_length = strlen (t->filename); |
4725 | t->suffix_length = suffix_length; |
4726 | } |
4727 | |
4728 | delete_this_arg = 1; |
4729 | return t->filename; |
4730 | } |
4731 | /* APPLE LOCAL end %b/save-temps can clobber input file (radar 2871891) --ilr */ |
4732 | |
4733 | static int |
4734 | do_spec_2 (const char *spec) |
4735 | { |
4736 | const char *string; |
4737 | int result; |
4738 | |
4739 | clear_args (); |
4740 | arg_going = 0; |
4741 | delete_this_arg = 0; |
4742 | this_is_output_file = 0; |
4743 | this_is_library_file = 0; |
4744 | input_from_pipe = 0; |
4745 | suffix_subst = NULL( ( void * ) 0 ); |
4746 | |
4747 | result = do_spec_1 (spec, 0, NULL( ( void * ) 0 )); |
4748 | |
4749 | /* End any pending argument. */ |
4750 | if (arg_going) |
4751 | { |
4752 | obstack_1grow__extension__ ( { struct obstack * __o = ( & obstack ) ; if ( __o -> next_free + 1 > __o -> chunk_limit ) _obstack_newchunk ( __o , 1 ) ; ( * ( ( __o ) -> next_free ) ++ = ( 0 ) ) ; ( void ) 0 ; } ) (&obstack, 0); |
4753 | string = XOBFINISH( ( const char * ) __extension__ ( { struct obstack * __o1 = ( ( & obstack ) ) ; void * value ; value = ( void * ) __o1 -> object_base ; if ( __o1 -> next_free == value ) __o1 -> maybe_empty_object = 1 ; __o1 -> next_free = ( ( ( ( ( __o1 -> next_free ) - ( char * ) 0 ) + __o1 -> alignment_mask ) & ~ ( __o1 -> alignment_mask ) ) + ( char * ) 0 ) ; if ( __o1 -> next_free - ( char * ) __o1 -> chunk > __o1 -> chunk_limit - ( char * ) __o1 -> chunk ) __o1 -> next_free = __o1 -> chunk_limit ; __o1 -> object_base = __o1 -> next_free ; value ; } ) ) (&obstack, const char *); |
4754 | if (this_is_library_file) |
4755 | string = find_file (string); |
4756 | store_arg (string, delete_this_arg, this_is_output_file); |
4757 | if (this_is_output_file) |
4758 | outfiles[input_file_number] = string; |
4759 | arg_going = 0; |
4760 | } |
4761 | |
4762 | return result; |
4763 | } |
4764 | |
4765 | |
4766 | /* Process the given spec string and add any new options to the end |
4767 | of the switches/n_switches array. */ |
4768 | |
4769 | static void |
4770 | do_option_spec (const char *name, const char *spec) |
4771 | { |
4772 | unsigned int i, value_count, value_len; |
4773 | const char *p, *q, *value; |
4774 | char *tmp_spec, *tmp_spec_p; |
4775 | |
4776 | if (configure_default_options[0].name == NULL( ( void * ) 0 )) |
4777 | return; |
4778 | |
4779 | for (i = 0; i < ARRAY_SIZE( sizeof ( configure_default_options ) / sizeof ( ( configure_default_options ) [ 0 ] ) ) (configure_default_options); i++) |
4780 | if (strcmp (configure_default_options[i].name, name) == 0) |
4781 | break; |
4782 | if (i == ARRAY_SIZE( sizeof ( configure_default_options ) / sizeof ( ( configure_default_options ) [ 0 ] ) ) (configure_default_options)) |
4783 | return; |
4784 | |
4785 | value = configure_default_options[i].value; |
4786 | value_len = strlen (value); |
4787 | |
4788 | /* Compute the size of the final spec. */ |
4789 | value_count = 0; |
4790 | p = spec; |
4791 | while ((p = strstr (p, "%(VALUE)")) != NULL( ( void * ) 0 )) |
4792 | { |
4793 | p ++; |
4794 | value_count ++; |
4795 | } |
4796 | |
4797 | /* Replace each %(VALUE) by the specified value. */ |
4798 | tmp_spec = alloca__builtin_alloca ( strlen ( spec ) + 1 + value_count * ( value_len - strlen ( "%(VALUE)" ) ) ) (strlen (spec) + 1 |
4799 | + value_count * (value_len - strlen ("%(VALUE)"))); |
4800 | tmp_spec_p = tmp_spec; |
4801 | q = spec; |
4802 | while ((p = strstr (q, "%(VALUE)")) != NULL( ( void * ) 0 )) |
4803 | { |
4804 | memcpy (tmp_spec_p, q, p - q); |
4805 | tmp_spec_p = tmp_spec_p + (p - q); |
4806 | memcpy (tmp_spec_p, value, value_len); |
4807 | tmp_spec_p += value_len; |
4808 | q = p + strlen ("%(VALUE)"); |
4809 | } |
4810 | strcpy (tmp_spec_p, q); |
4811 | |
4812 | do_self_spec (tmp_spec); |
4813 | } |
4814 | |
4815 | /* Process the given spec string and add any new options to the end |
4816 | of the switches/n_switches array. */ |
4817 | |
4818 | static void |
4819 | do_self_spec (const char *spec) |
4820 | { |
4821 | do_spec_2 (spec); |
4822 | do_spec_1 (" ", 0, NULL( ( void * ) 0 )); |
4823 | |
4824 | if (argbuf_index > 0) |
4825 | { |
4826 | int i, first; |
4827 | |
4828 | first = n_switches; |
4829 | n_switches += argbuf_index; |
4830 | switches = xrealloc (switches, |
4831 | sizeof (struct switchstr) * (n_switches + 1)); |
4832 | |
4833 | switches[n_switches] = switches[first]; |
4834 | for (i = 0; i < argbuf_index; i++) |
4835 | { |
4836 | struct switchstr *sw; |
4837 | |
4838 | /* Each switch should start with '-'. */ |
4839 | if (argbuf[i][0] != '-') |
4840 | fatal ("switch '%s' does not start with '-'", argbuf[i]); |
4841 | |
4842 | sw = &switches[i + first]; |
4843 | sw->part1 = &argbuf[i][1]; |
4844 | sw->args = 0; |
4845 | sw->live_cond = SWITCH_OK0; |
4846 | sw->validated = 0; |
4847 | sw->ordering = 0; |
4848 | } |
4849 | } |
4850 | } |
4851 | |
4852 | /* Callback for processing %D and %I specs. */ |
4853 | |
4854 | struct spec_path_info { |
4855 | const char *option; |
4856 | const char *append; |
4857 | size_t append_len; |
4858 | bool_Bool omit_relative; |
4859 | bool_Bool separate_options; |
4860 | }; |
4861 | |
4862 | static void * |
4863 | spec_path (char *path, void *data) |
4864 | { |
4865 | struct spec_path_info *info = data; |
4866 | size_t len = 0; |
4867 | char save = 0; |
4868 | |
4869 | if (info->omit_relative && !IS_ABSOLUTE_PATH( ( ( ( path ) [ 0 ] ) == '/' ) ) (path)) |
4870 | return NULL( ( void * ) 0 ); |
4871 | |
4872 | if (info->append_len != 0) |
4873 | { |
4874 | len = strlen (path); |
4875 | memcpy (path + len, info->append, info->append_len + 1); |
4876 | } |
4877 | |
4878 | if (!is_directory (path, true1)) |
4879 | return NULL( ( void * ) 0 ); |
4880 | |
4881 | do_spec_1 (info->option, 1, NULL( ( void * ) 0 )); |
4882 | if (info->separate_options) |
4883 | do_spec_1 (" ", 0, NULL( ( void * ) 0 )); |
4884 | |
4885 | if (info->append_len == 0) |
4886 | { |
4887 | len = strlen (path); |
4888 | save = path[len - 1]; |
4889 | if (IS_DIR_SEPARATOR( ( path [ len - 1 ] ) == '/' ) (path[len - 1])) |
4890 | path[len - 1] = '\0'; |
4891 | } |
4892 | |
4893 | do_spec_1 (path, 1, NULL( ( void * ) 0 )); |
4894 | do_spec_1 (" ", 0, NULL( ( void * ) 0 )); |
4895 | |
4896 | /* Must not damage the original path. */ |
4897 | if (info->append_len == 0) |
4898 | path[len - 1] = save; |
4899 | |
4900 | return NULL( ( void * ) 0 ); |
4901 | } |
4902 | |
4903 | /* Process the sub-spec SPEC as a portion of a larger spec. |
4904 | This is like processing a whole spec except that we do |
4905 | not initialize at the beginning and we do not supply a |
4906 | newline by default at the end. |
4907 | INSWITCH nonzero means don't process %-sequences in SPEC; |
4908 | in this case, % is treated as an ordinary character. |
4909 | This is used while substituting switches. |
4910 | INSWITCH nonzero also causes SPC not to terminate an argument. |
4911 | |
4912 | Value is zero unless a line was finished |
4913 | and the command on that line reported an error. */ |
4914 | |
4915 | static int |
4916 | do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part) |
4917 | { |
4918 | const char *p = spec; |
4919 | int c; |
4920 | int i; |
4921 | const char *string; |
4922 | int value; |
4923 | |
4924 | while ((c = *p++)) |
4925 | /* If substituting a switch, treat all chars like letters. |
4926 | Otherwise, NL, SPC, TAB and % are special. */ |
4927 | switch (inswitch ? 'a' : c) |
4928 | { |
4929 | case '\n': |
4930 | /* End of line: finish any pending argument, |
4931 | then run the pending command if one has been started. */ |
4932 | if (arg_going) |
4933 | { |
4934 | obstack_1grow__extension__ ( { struct obstack * __o = ( & obstack ) ; if ( __o -> next_free + 1 > __o -> chunk_limit ) _obstack_newchunk ( __o , 1 ) ; ( * ( ( __o ) -> next_free ) ++ = ( 0 ) ) ; ( void ) 0 ; } ) (&obstack, 0); |
4935 | string = XOBFINISH( ( const char * ) __extension__ ( { struct obstack * __o1 = ( ( & obstack ) ) ; void * value ; value = ( void * ) __o1 -> object_base ; if ( __o1 -> next_free == value ) __o1 -> maybe_empty_object = 1 ; __o1 -> next_free = ( ( ( ( ( __o1 -> next_free ) - ( char * ) 0 ) + __o1 -> alignment_mask ) & ~ ( __o1 -> alignment_mask ) ) + ( char * ) 0 ) ; if ( __o1 -> next_free - ( char * ) __o1 -> chunk > __o1 -> chunk_limit - ( char * ) __o1 -> chunk ) __o1 -> next_free = __o1 -> chunk_limit ; __o1 -> object_base = __o1 -> next_free ; value ; } ) ) (&obstack, const char *); |
4936 | /* APPLE LOCAL begin %b/save-temps can clobber input file (radar 2871891) --ilr */ |
4937 | if (this_is_basename_derived_file) |
4938 | string = check_basename_derived_file (string); |
4939 | else if (this_is_library_file) |
4940 | string = find_file (string); |
4941 | store_arg (string, delete_this_arg, this_is_output_file |
4942 | || this_is_basename_derived_file); |
4943 | /* APPLE LOCAL end %b/save-temps can clobber input file (radar 2871891) --ilr */ |
4944 | if (this_is_output_file) |
4945 | outfiles[input_file_number] = string; |
4946 | } |
4947 | arg_going = 0; |
4948 | |
4949 | if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|")) |
4950 | { |
4951 | /* A `|' before the newline means use a pipe here, |
4952 | but only if -pipe was specified. |
4953 | Otherwise, execute now and don't pass the `|' as an arg. */ |
4954 | if (use_pipes) |
4955 | { |
4956 | input_from_pipe = 1; |
4957 | break; |
4958 | } |
4959 | else |
4960 | argbuf_index--; |
4961 | } |
4962 | |
4963 | set_collect_gcc_options (); |
4964 | |
4965 | if (argbuf_index > 0) |
4966 | { |
4967 | value = execute (); |
4968 | if (value) |
4969 | return value; |
4970 | } |
4971 | /* Reinitialize for a new command, and for a new argument. */ |
4972 | clear_args (); |
4973 | arg_going = 0; |
4974 | delete_this_arg = 0; |
4975 | this_is_output_file = 0; |
4976 | /* APPLE LOCAL %b/save-temps can clobber input file (radar 2871891) --ilr */ |
4977 | this_is_basename_derived_file = 0; |
4978 | this_is_library_file = 0; |
4979 | input_from_pipe = 0; |
4980 | break; |
4981 | |
4982 | case '|': |
4983 | /* End any pending argument. */ |
4984 | if (arg_going) |
4985 | { |
4986 | obstack_1grow__extension__ ( { struct obstack * __o = ( & obstack ) ; if ( __o -> next_free + 1 > __o -> chunk_limit ) _obstack_newchunk ( __o , 1 ) ; ( * ( ( __o ) -> next_free ) ++ = ( 0 ) ) ; ( void ) 0 ; } ) (&obstack, 0); |
4987 | string = XOBFINISH( ( const char * ) __extension__ ( { struct obstack * __o1 = ( ( & obstack ) ) ; void * value ; value = ( void * ) __o1 -> object_base ; if ( __o1 -> next_free == value ) __o1 -> maybe_empty_object = 1 ; __o1 -> next_free = ( ( ( ( ( __o1 -> next_free ) - ( char * ) 0 ) + __o1 -> alignment_mask ) & ~ ( __o1 -> alignment_mask ) ) + ( char * ) 0 ) ; if ( __o1 -> next_free - ( char * ) __o1 -> chunk > __o1 -> chunk_limit - ( char * ) __o1 -> chunk ) __o1 -> next_free = __o1 -> chunk_limit ; __o1 -> object_base = __o1 -> next_free ; value ; } ) ) (&obstack, const char *); |
4988 | /* APPLE LOCAL begin %b/save-temps can clobber input file (radar 2871891) --ilr */ |
4989 | if (this_is_basename_derived_file) |
4990 | string = check_basename_derived_file (string); |
4991 | else if (this_is_library_file) |
4992 | string = find_file (string); |
4993 | store_arg (string, delete_this_arg, this_is_output_file |
4994 | || this_is_basename_derived_file); |
4995 | /* APPLE LOCAL end %b/save-temps can clobber input file (radar 2871891) --ilr */ |
4996 | if (this_is_output_file) |
4997 | outfiles[input_file_number] = string; |
4998 | } |
4999 | |
5000 | /* Use pipe */ |
5001 | obstack_1grow__extension__ ( { struct obstack * __o = ( & obstack ) ; if ( __o -> next_free + 1 > __o -> chunk_limit ) _obstack_newchunk ( __o , 1 ) ; ( * ( ( __o ) -> next_free ) ++ = ( c ) ) ; ( void ) 0 ; } ) (&obstack, c); |
5002 | arg_going = 1; |
5003 | break; |
5004 | |
5005 | case '\t': |
5006 | case ' ': |
5007 | /* Space or tab ends an argument if one is pending. */ |
5008 | if (arg_going) |
5009 | { |
5010 | obstack_1grow__extension__ ( { struct obstack * __o = ( & obstack ) ; if ( __o -> next_free + 1 > __o -> chunk_limit ) _obstack_newchunk ( __o , 1 ) ; ( * ( ( __o ) -> next_free ) ++ = ( 0 ) ) ; ( void ) 0 ; } ) (&obstack, 0); |
5011 | string = XOBFINISH( ( const char * ) __extension__ ( { struct obstack * __o1 = ( ( & obstack ) ) ; void * value ; value = ( void * ) __o1 -> object_base ; if ( __o1 -> next_free == value ) __o1 -> maybe_empty_object = 1 ; __o1 -> next_free = ( ( ( ( ( __o1 -> next_free ) - ( char * ) 0 ) + __o1 -> alignment_mask ) & ~ ( __o1 -> alignment_mask ) ) + ( char * ) 0 ) ; if ( __o1 -> next_free - ( char * ) __o1 -> chunk > __o1 -> chunk_limit - ( char * ) __o1 -> chunk ) __o1 -> next_free = __o1 -> chunk_limit ; __o1 -> object_base = __o1 -> next_free ; value ; } ) ) (&obstack, const char *); |
5012 | /* APPLE LOCAL begin %b/save-temps can clobber input file (radar 2871891) --ilr */ |
5013 | if (this_is_basename_derived_file) |
5014 | string = check_basename_derived_file (string); |
5015 | else if (this_is_library_file) |
5016 | string = find_file (string); |
5017 | store_arg (string, delete_this_arg, this_is_output_file |
5018 | || this_is_basename_derived_file); |
5019 | /* APPLE LOCAL end %b/save-temps can clobber input file (radar 2871891) --ilr */ |
5020 | if (this_is_output_file) |
5021 | outfiles[input_file_number] = string; |
5022 | } |
5023 | /* Reinitialize for a new argument. */ |
5024 | arg_going = 0; |
5025 | delete_this_arg = 0; |
5026 | this_is_output_file = 0; |
5027 | /* APPLE LOCAL %b/save-temps can clobber input file (radar 2871891) --ilr */ |
5028 | this_is_basename_derived_file = 0; |
5029 | this_is_library_file = 0; |
5030 | break; |
5031 | |
5032 | case '%': |
5033 | switch (c = *p++) |
5034 | { |
5035 | case 0: |
5036 | fatal ("spec '%s' invalid", spec); |
5037 | |
5038 | case 'b': |
5039 | /* APPLE LOCAL %b/save-temps can clobber input file (radar 2871891) --ilr */ |
5040 | this_is_basename_derived_file = 1; |
5041 | obstack_grow__extension__ ( { struct obstack * __o = ( & obstack ) ; int __len = ( basename_length ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( input_basename ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&obstack, input_basename, basename_length); |
5042 | arg_going = 1; |
5043 | break; |
5044 | |
5045 | case 'B': |
5046 | obstack_grow__extension__ ( { struct obstack * __o = ( & obstack ) ; int __len = ( suffixed_basename_length ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( input_basename ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&obstack, input_basename, suffixed_basename_length); |
5047 | arg_going = 1; |
5048 | break; |
5049 | |
5050 | case 'd': |
5051 | delete_this_arg = 2; |
5052 | break; |
5053 | |
5054 | /* Dump out the directories specified with LIBRARY_PATH, |
5055 | followed by the absolute directories |
5056 | that we search for startfiles. */ |
5057 | case 'D': |
5058 | { |
5059 | struct spec_path_info info; |
5060 | |
5061 | info.option = "-L"; |
5062 | info.append_len = 0; |
5063 | #ifdef RELATIVE_PREFIX_NOT_LINKDIR |
5064 | /* Used on systems which record the specified -L dirs |
5065 | and use them to search for dynamic linking. |
5066 | Relative directories always come from -B, |
5067 | and it is better not to use them for searching |
5068 | at run time. In particular, stage1 loses. */ |
5069 | info.omit_relative = true; |
5070 | #else |
5071 | info.omit_relative = false0; |
5072 | #endif |
5073 | info.separate_options = false0; |
5074 | |
5075 | for_each_path (&startfile_prefixes, true1, 0, spec_path, &info); |
5076 | } |
5077 | break; |
5078 | |
5079 | case 'e': |
5080 | /* %efoo means report an error with `foo' as error message |
5081 | and don't execute any more commands for this file. */ |
5082 | { |
5083 | const char *q = p; |
5084 | char *buf; |
5085 | while (*p != 0 && *p != '\n') |
5086 | p++; |
5087 | buf = alloca__builtin_alloca ( p - q + 1 ) (p - q + 1); |
5088 | strncpy (buf, q, p - q); |
5089 | buf[p - q] = 0; |
5090 | error ("%s", buf); |
5091 | return -1; |
5092 | } |
5093 | break; |
5094 | case 'n': |
5095 | /* %nfoo means report a notice with `foo' on stderr. */ |
5096 | { |
5097 | const char *q = p; |
5098 | char *buf; |
5099 | while (*p != 0 && *p != '\n') |
5100 | p++; |
5101 | buf = alloca__builtin_alloca ( p - q + 1 ) (p - q + 1); |
5102 | strncpy (buf, q, p - q); |
5103 | buf[p - q] = 0; |
5104 | notice ("%s\n", buf); |
5105 | if (*p) |
5106 | p++; |
5107 | } |
5108 | break; |
5109 | |
5110 | case 'j': |
5111 | { |
5112 | struct stat st; |
5113 | |
5114 | /* If save_temps_flag is off, and the HOST_BIT_BUCKET is |
5115 | defined, and it is not a directory, and it is |
5116 | writable, use it. Otherwise, treat this like any |
5117 | other temporary file. */ |
5118 | |
5119 | if ((!save_temps_flag) |
5120 | && (stat (HOST_BIT_BUCKET"/dev/null", &st) == 0) && (!S_ISDIR( ( ( st . st_mode ) & 0170000 ) == 0040000 ) (st.st_mode)) |
5121 | && (access (HOST_BIT_BUCKET"/dev/null", W_OK( 1 << 1 )) == 0)) |
5122 | { |
5123 | obstack_grow__extension__ ( { struct obstack * __o = ( & obstack ) ; int __len = ( strlen ( "/dev/null" ) ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( "/dev/null" ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&obstack, HOST_BIT_BUCKET, |
5124 | strlen (HOST_BIT_BUCKET)); |
5125 | delete_this_arg = 0; |
5126 | arg_going = 1; |
5127 | break; |
5128 | } |
5129 | } |
5130 | goto create_temp_file; |
5131 | case '|': |
5132 | if (use_pipes) |
5133 | { |
5134 | obstack_1grow__extension__ ( { struct obstack * __o = ( & obstack ) ; if ( __o -> next_free + 1 > __o -> chunk_limit ) _obstack_newchunk ( __o , 1 ) ; ( * ( ( __o ) -> next_free ) ++ = ( '-' ) ) ; ( void ) 0 ; } ) (&obstack, '-'); |
5135 | delete_this_arg = 0; |
5136 | arg_going = 1; |
5137 | |
5138 | /* consume suffix */ |
5139 | while (*p == '.' || ISALNUM( _sch_istable [ ( ( unsigned char ) * p ) & 0xff ] & ( unsigned short ) ( _sch_isalnum ) ) ((unsigned char) *p)) |
5140 | p++; |
5141 | if (p[0] == '%' && p[1] == 'O') |
5142 | p += 2; |
5143 | |
5144 | break; |
5145 | } |
5146 | goto create_temp_file; |
5147 | case 'm': |
5148 | if (use_pipes) |
5149 | { |
5150 | /* consume suffix */ |
5151 | while (*p == '.' || ISALNUM( _sch_istable [ ( ( unsigned char ) * p ) & 0xff ] & ( unsigned short ) ( _sch_isalnum ) ) ((unsigned char) *p)) |
5152 | p++; |
5153 | if (p[0] == '%' && p[1] == 'O') |
5154 | p += 2; |
5155 | |
5156 | break; |
5157 | } |
5158 | goto create_temp_file; |
5159 | case 'g': |
5160 | case 'u': |
5161 | case 'U': |
5162 | create_temp_file: |
5163 | { |
5164 | struct temp_name *t; |
5165 | int suffix_length; |
5166 | const char *suffix = p; |
5167 | char *saved_suffix = NULL( ( void * ) 0 ); |
5168 | |
5169 | while (*p == '.' || ISALNUM( _sch_istable [ ( ( unsigned char ) * p ) & 0xff ] & ( unsigned short ) ( _sch_isalnum ) ) ((unsigned char) *p)) |
5170 | p++; |
5171 | suffix_length = p - suffix; |
5172 | if (p[0] == '%' && p[1] == 'O') |
5173 | { |
5174 | p += 2; |
5175 | /* We don't support extra suffix characters after %O. */ |
5176 | if (*p == '.' || ISALNUM( _sch_istable [ ( ( unsigned char ) * p ) & 0xff ] & ( unsigned short ) ( _sch_isalnum ) ) ((unsigned char) *p)) |
5177 | fatal ("spec '%s' has invalid '%%0%c'", spec, *p); |
5178 | if (suffix_length == 0) |
5179 | suffix = TARGET_OBJECT_SUFFIX".o"; |
5180 | else |
5181 | { |
5182 | saved_suffix |
5183 | = XNEWVEC( ( char * ) xmalloc ( sizeof ( char ) * ( suffix_length + strlen ( ".o" ) ) ) ) (char, suffix_length |
5184 | + strlen (TARGET_OBJECT_SUFFIX)); |
5185 | strncpy (saved_suffix, suffix, suffix_length); |
5186 | strcpy (saved_suffix + suffix_length, |
5187 | TARGET_OBJECT_SUFFIX".o"); |
5188 | } |
5189 | suffix_length += strlen (TARGET_OBJECT_SUFFIX".o"); |
5190 | } |
5191 | |
5192 | /* If the input_filename has the same suffix specified |
5193 | for the %g, %u, or %U, and -save-temps is specified, |
5194 | we could end up using that file as an intermediate |
5195 | thus clobbering the user's source file (.e.g., |
5196 | gcc -save-temps foo.s would clobber foo.s with the |
5197 | output of cpp0). So check for this condition and |
5198 | generate a temp file as the intermediate. */ |
5199 | |
5200 | if (save_temps_flag) |
5201 | { |
5202 | temp_filename_length = basename_length + suffix_length; |
5203 | temp_filename = alloca__builtin_alloca ( temp_filename_length + 1 ) (temp_filename_length + 1); |
5204 | strncpy ((char *) temp_filename, input_basename, basename_length); |
5205 | strncpy ((char *) temp_filename + basename_length, suffix, |
5206 | suffix_length); |
5207 | *((char *) temp_filename + temp_filename_length) = '\0'; |
5208 | if (strcmp (temp_filename, input_filename) != 0) |
5209 | { |
5210 | #ifndef HOST_LACKS_INODE_NUMBERS |
5211 | struct stat st_temp; |
5212 | |
5213 | /* Note, set_input() resets input_stat_set to 0. */ |
5214 | if (input_stat_set == 0) |
5215 | { |
5216 | input_stat_set = stat (input_filename, &input_stat); |
5217 | if (input_stat_set >= 0) |
5218 | input_stat_set = 1; |
5219 | } |
5220 | |
5221 | /* If we have the stat for the input_filename |
5222 | and we can do the stat for the temp_filename |
5223 | then the they could still refer to the same |
5224 | file if st_dev/st_ino's are the same. */ |
5225 | if (input_stat_set != 1 |
5226 | || stat (temp_filename, &st_temp) < 0 |
5227 | || input_stat.st_dev != st_temp.st_dev |
5228 | || input_stat.st_ino != st_temp.st_ino) |
5229 | #else |
5230 | /* Just compare canonical pathnames. */ |
5231 | char* input_realname = lrealpath (input_filename); |
5232 | char* temp_realname = lrealpath (temp_filename); |
5233 | bool files_differ = strcmp (input_realname, temp_realname); |
5234 | free (input_realname); |
5235 | free (temp_realname); |
5236 | if (files_differ) |
5237 | #endif |
5238 | { |
5239 | temp_filename = save_string (temp_filename, |
5240 | temp_filename_length + 1); |
5241 | obstack_grow__extension__ ( { struct obstack * __o = ( & obstack ) ; int __len = ( temp_filename_length ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( temp_filename ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&obstack, temp_filename, |
5242 | temp_filename_length); |
5243 | arg_going = 1; |
5244 | delete_this_arg = 0; |
5245 | break; |
5246 | } |
5247 | } |
5248 | } |
5249 | |
5250 | /* See if we already have an association of %g/%u/%U and |
5251 | suffix. */ |
5252 | for (t = temp_names; t; t = t->next) |
5253 | if (t->length == suffix_length |
5254 | /* APPLE LOCAL begin IMA */ |
5255 | #if 0 |
5256 | /* This causes gcc.dg/cpp/trad/builtins.c to fail. |
5257 | Disable this for now. */ |
5258 | /* Create new temp file for each source file. */ |
5259 | && strcmp (suffix, ".i") |
5260 | && strcmp (suffix, ".ii") |
5261 | #endif |
5262 | /* APPLE LOCAL end IMA */ |
5263 | && strncmp (t->suffix, suffix, suffix_length) == 0 |
5264 | && t->unique == (c == 'u' || c == 'U' || c == 'j')) |
5265 | break; |
5266 | |
5267 | /* Make a new association if needed. %u and %j |
5268 | require one. */ |
5269 | if (t == 0 || c == 'u' || c == 'j') |
5270 | { |
5271 | if (t == 0) |
5272 | { |
5273 | t = xmalloc (sizeof (struct temp_name)); |
5274 | t->next = temp_names; |
5275 | temp_names = t; |
5276 | } |
5277 | t->length = suffix_length; |
5278 | if (saved_suffix) |
5279 | { |
5280 | t->suffix = saved_suffix; |
5281 | saved_suffix = NULL( ( void * ) 0 ); |
5282 | } |
5283 | else |
5284 | t->suffix = save_string (suffix, suffix_length); |
5285 | t->unique = (c == 'u' || c == 'U' || c == 'j'); |
5286 | temp_filename = make_temp_file (t->suffix); |
5287 | temp_filename_length = strlen (temp_filename); |
5288 | t->filename = temp_filename; |
5289 | t->filename_length = temp_filename_length; |
5290 | /* APPLE LOCAL begin IMA */ |
5291 | infiles[input_file_number].temp_filename = temp_filename; |
5292 | /* APPLE LOCAL end IMA */ |
5293 | } |
5294 | |
5295 | if (saved_suffix) |
5296 | free (saved_suffix); |
5297 | |
5298 | obstack_grow__extension__ ( { struct obstack * __o = ( & obstack ) ; int __len = ( t -> filename_length ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( t -> filename ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&obstack, t->filename, t->filename_length); |
5299 | /* APPLE LOCAL what is this for? */ |
5300 | delete_this_arg = (save_temps_flag == 0); |
5301 | } |
5302 | arg_going = 1; |
5303 | break; |
5304 | |
5305 | case 'i': |
5306 | if (combine_inputs) |
5307 | { |
5308 | for (i = 0; (int) i < n_infiles; i++) |
5309 | if ((!infiles[i].language) || (infiles[i].language[0] != '*')) |
5310 | if (infiles[i].incompiler == input_file_compiler) |
5311 | { |
5312 | store_arg (infiles[i].name, 0, 0); |
5313 | infiles[i].compiled = true1; |
5314 | } |
5315 | } |
5316 | else |
5317 | { |
5318 | obstack_grow__extension__ ( { struct obstack * __o = ( & obstack ) ; int __len = ( input_filename_length ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( input_filename ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&obstack, input_filename, input_filename_length); |
5319 | arg_going = 1; |
5320 | } |
5321 | break; |
5322 | |
5323 | case 'I': |
5324 | { |
5325 | struct spec_path_info info; |
5326 | |
5327 | if (multilib_dir) |
5328 | { |
5329 | do_spec_1 ("-imultilib", 1, NULL( ( void * ) 0 )); |
5330 | /* Make this a separate argument. */ |
5331 | do_spec_1 (" ", 0, NULL( ( void * ) 0 )); |
5332 | do_spec_1 (multilib_dir, 1, NULL( ( void * ) 0 )); |
5333 | do_spec_1 (" ", 0, NULL( ( void * ) 0 )); |
5334 | } |
5335 | |
5336 | if (gcc_exec_prefix) |
5337 | { |
5338 | do_spec_1 ("-iprefix", 1, NULL( ( void * ) 0 )); |
5339 | /* Make this a separate argument. */ |
5340 | do_spec_1 (" ", 0, NULL( ( void * ) 0 )); |
5341 | do_spec_1 (gcc_exec_prefix, 1, NULL( ( void * ) 0 )); |
5342 | do_spec_1 (" ", 0, NULL( ( void * ) 0 )); |
5343 | } |
5344 | |
5345 | if (target_system_root_changed || |
5346 | (target_system_root && target_sysroot_hdrs_suffix)) |
5347 | { |
5348 | do_spec_1 ("-isysroot", 1, NULL( ( void * ) 0 )); |
5349 | /* Make this a separate argument. */ |
5350 | do_spec_1 (" ", 0, NULL( ( void * ) 0 )); |
5351 | do_spec_1 (target_system_root, 1, NULL( ( void * ) 0 )); |
5352 | if (target_sysroot_hdrs_suffix) |
5353 | do_spec_1 (target_sysroot_hdrs_suffix, 1, NULL( ( void * ) 0 )); |
5354 | do_spec_1 (" ", 0, NULL( ( void * ) 0 )); |
5355 | } |
5356 | |
5357 | info.option = "-isystem"; |
5358 | info.append = "include"; |
5359 | info.append_len = strlen (info.append); |
5360 | info.omit_relative = false0; |
5361 | info.separate_options = true1; |
5362 | |
5363 | for_each_path (&include_prefixes, false0, info.append_len, |
5364 | spec_path, &info); |
5365 | } |
5366 | break; |
5367 | |
5368 | case 'o': |
5369 | { |
5370 | int max = n_infiles; |
5371 | max += lang_specific_extra_outfiles; |
5372 | |
5373 | for (i = 0; i < max; i++) |
5374 | if (outfiles[i]) |
5375 | store_arg (outfiles[i], 0, 0); |
5376 | break; |
5377 | } |
5378 | |
5379 | case 'O': |
5380 | obstack_grow__extension__ ( { struct obstack * __o = ( & obstack ) ; int __len = ( strlen ( ".o" ) ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( ".o" ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX)); |
5381 | arg_going = 1; |
5382 | break; |
5383 | |
5384 | case 's': |
5385 | this_is_library_file = 1; |
5386 | break; |
5387 | |
5388 | case 'V': |
5389 | outfiles[input_file_number] = NULL( ( void * ) 0 ); |
5390 | break; |
5391 | |
5392 | case 'w': |
5393 | this_is_output_file = 1; |
5394 | break; |
5395 | |
5396 | case 'W': |
5397 | { |
5398 | int cur_index = argbuf_index; |
5399 | /* Handle the {...} following the %W. */ |
5400 | if (*p != '{') |
5401 | fatal ("spec '%s' has invalid '%%W%c", spec, *p); |
5402 | p = handle_braces (p + 1); |
5403 | if (p == 0) |
5404 | return -1; |
5405 | /* End any pending argument. */ |
5406 | if (arg_going) |
5407 | { |
5408 | obstack_1grow__extension__ ( { struct obstack * __o = ( & obstack ) ; if ( __o -> next_free + 1 > __o -> chunk_limit ) _obstack_newchunk ( __o , 1 ) ; ( * ( ( __o ) -> next_free ) ++ = ( 0 ) ) ; ( void ) 0 ; } ) (&obstack, 0); |
5409 | string = XOBFINISH( ( const char * ) __extension__ ( { struct obstack * __o1 = ( ( & obstack ) ) ; void * value ; value = ( void * ) __o1 -> object_base ; if ( __o1 -> next_free == value ) __o1 -> maybe_empty_object = 1 ; __o1 -> next_free = ( ( ( ( ( __o1 -> next_free ) - ( char * ) 0 ) + __o1 -> alignment_mask ) & ~ ( __o1 -> alignment_mask ) ) + ( char * ) 0 ) ; if ( __o1 -> next_free - ( char * ) __o1 -> chunk > __o1 -> chunk_limit - ( char * ) __o1 -> chunk ) __o1 -> next_free = __o1 -> chunk_limit ; __o1 -> object_base = __o1 -> next_free ; value ; } ) ) (&obstack, const char *); |
5410 | if (this_is_library_file) |
5411 | string = find_file (string); |
5412 | store_arg (string, delete_this_arg, this_is_output_file); |
5413 | if (this_is_output_file) |
5414 | outfiles[input_file_number] = string; |
5415 | arg_going = 0; |
5416 | } |
5417 | /* If any args were output, mark the last one for deletion |
5418 | on failure. */ |
5419 | if (argbuf_index != cur_index) |
5420 | record_temp_file (argbuf[argbuf_index - 1], 0, 1); |
5421 | break; |
5422 | } |
5423 | |
5424 | /* %x{OPTION} records OPTION for %X to output. */ |
5425 | case 'x': |
5426 | { |
5427 | const char *p1 = p; |
5428 | char *string; |
5429 | |
5430 | /* Skip past the option value and make a copy. */ |
5431 | if (*p != '{') |
5432 | fatal ("spec '%s' has invalid '%%x%c'", spec, *p); |
5433 | while (*p++ != '}') |
5434 | ; |
5435 | string = save_string (p1 + 1, p - p1 - 2); |
5436 | |
5437 | /* See if we already recorded this option. */ |
5438 | for (i = 0; i < n_linker_options; i++) |
5439 | if (! strcmp (string, linker_options[i])) |
5440 | { |
5441 | free (string); |
5442 | return 0; |
5443 | } |
5444 | |
5445 | /* This option is new; add it. */ |
5446 | add_linker_option (string, strlen (string)); |
5447 | } |
5448 | break; |
5449 | |
5450 | /* Dump out the options accumulated previously using %x. */ |
5451 | case 'X': |
5452 | for (i = 0; i < n_linker_options; i++) |
5453 | { |
5454 | do_spec_1 (linker_options[i], 1, NULL( ( void * ) 0 )); |
5455 | /* Make each accumulated option a separate argument. */ |
5456 | do_spec_1 (" ", 0, NULL( ( void * ) 0 )); |
5457 | } |
5458 | break; |
5459 | |
5460 | /* Dump out the options accumulated previously using -Wa,. */ |
5461 | case 'Y': |
5462 | for (i = 0; i < n_assembler_options; i++) |
5463 | { |
5464 | do_spec_1 (assembler_options[i], 1, NULL( ( void * ) 0 )); |
5465 | /* Make each accumulated option a separate argument. */ |
5466 | do_spec_1 (" ", 0, NULL( ( void * ) 0 )); |
5467 | } |
5468 | break; |
5469 | |
5470 | /* Dump out the options accumulated previously using -Wp,. */ |
5471 | case 'Z': |
5472 | for (i = 0; i < n_preprocessor_options; i++) |
5473 | { |
5474 | do_spec_1 (preprocessor_options[i], 1, NULL( ( void * ) 0 )); |
5475 | /* Make each accumulated option a separate argument. */ |
5476 | do_spec_1 (" ", 0, NULL( ( void * ) 0 )); |
5477 | } |
5478 | break; |
5479 | |
5480 | /* Here are digits and numbers that just process |
5481 | a certain constant string as a spec. */ |
5482 | |
5483 | case '1': |
5484 | value = do_spec_1 (cc1_spec, 0, NULL( ( void * ) 0 )); |
5485 | if (value != 0) |
5486 | return value; |
5487 | break; |
5488 | |
5489 | case '2': |
5490 | value = do_spec_1 (cc1plus_spec, 0, NULL( ( void * ) 0 )); |
5491 | if (value != 0) |
5492 | return value; |
5493 | break; |
5494 | |
5495 | case 'a': |
5496 | value = do_spec_1 (asm_spec, 0, NULL( ( void * ) 0 )); |
5497 | if (value != 0) |
5498 | return value; |
5499 | break; |
5500 | |
5501 | case 'A': |
5502 | value = do_spec_1 (asm_final_spec, 0, NULL( ( void * ) 0 )); |
5503 | if (value != 0) |
5504 | return value; |
5505 | break; |
5506 | |
5507 | case 'C': |
5508 | { |
5509 | const char *const spec |
5510 | = (input_file_compiler->cpp_spec |
5511 | ? input_file_compiler->cpp_spec |
5512 | : cpp_spec); |
5513 | value = do_spec_1 (spec, 0, NULL( ( void * ) 0 )); |
5514 | if (value != 0) |
5515 | return value; |
5516 | } |
5517 | break; |
5518 | |
5519 | case 'E': |
5520 | value = do_spec_1 (endfile_spec, 0, NULL( ( void * ) 0 )); |
5521 | if (value != 0) |
5522 | return value; |
5523 | break; |
5524 | |
5525 | case 'l': |
5526 | value = do_spec_1 (link_spec, 0, NULL( ( void * ) 0 )); |
5527 | if (value != 0) |
5528 | return value; |
5529 | break; |
5530 | |
5531 | case 'L': |
5532 | value = do_spec_1 (lib_spec, 0, NULL( ( void * ) 0 )); |
5533 | if (value != 0) |
5534 | return value; |
5535 | break; |
5536 | |
5537 | case 'G': |
5538 | value = do_spec_1 (libgcc_spec, 0, NULL( ( void * ) 0 )); |
5539 | if (value != 0) |
5540 | return value; |
5541 | break; |
5542 | |
5543 | case 'R': |
5544 | /* We assume there is a directory |
5545 | separator at the end of this string. */ |
5546 | if (target_system_root) |
5547 | { |
5548 | obstack_grow__extension__ ( { struct obstack * __o = ( & obstack ) ; int __len = ( strlen ( target_system_root ) ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( target_system_root ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&obstack, target_system_root, |
5549 | strlen (target_system_root)); |
5550 | if (target_sysroot_suffix) |
5551 | obstack_grow__extension__ ( { struct obstack * __o = ( & obstack ) ; int __len = ( strlen ( target_sysroot_suffix ) ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( target_sysroot_suffix ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&obstack, target_sysroot_suffix, |
5552 | strlen (target_sysroot_suffix)); |
5553 | } |
5554 | break; |
5555 | |
5556 | case 'S': |
5557 | value = do_spec_1 (startfile_spec, 0, NULL( ( void * ) 0 )); |
5558 | if (value != 0) |
5559 | return value; |
5560 | break; |
5561 | |
5562 | /* Here we define characters other than letters and digits. */ |
5563 | |
5564 | case '{': |
5565 | p = handle_braces (p); |
5566 | if (p == 0) |
5567 | return -1; |
5568 | break; |
5569 | |
5570 | case ':': |
5571 | p = handle_spec_function (p); |
5572 | if (p == 0) |
5573 | return -1; |
5574 | break; |
5575 | |
5576 | case '%': |
5577 | obstack_1grow__extension__ ( { struct obstack * __o = ( & obstack ) ; if ( __o -> next_free + 1 > __o -> chunk_limit ) _obstack_newchunk ( __o , 1 ) ; ( * ( ( __o ) -> next_free ) ++ = ( '%' ) ) ; ( void ) 0 ; } ) (&obstack, '%'); |
5578 | break; |
5579 | |
5580 | case '.': |
5581 | { |
5582 | unsigned len = 0; |
5583 | |
5584 | while (p[len] && p[len] != ' ' && p[len] != '%') |
5585 | len++; |
5586 | suffix_subst = save_string (p - 1, len + 1); |
5587 | p += len; |
5588 | } |
5589 | break; |
5590 | |
5591 | /* Henceforth ignore the option(s) matching the pattern |
5592 | after the %<. */ |
5593 | case '<': |
5594 | { |
5595 | unsigned len = 0; |
5596 | int have_wildcard = 0; |
5597 | int i; |
5598 | |
5599 | while (p[len] && p[len] != ' ' && p[len] != '\t') |
5600 | len++; |
5601 | |
5602 | if (p[len-1] == '*') |
5603 | have_wildcard = 1; |
5604 | |
5605 | for (i = 0; i < n_switches; i++) |
5606 | if (!strncmp (switches[i].part1, p, len - have_wildcard) |
5607 | && (have_wildcard || switches[i].part1[len] == '\0')) |
5608 | { |
5609 | switches[i].live_cond = SWITCH_IGNORE- 2; |
5610 | switches[i].validated = 1; |
5611 | } |
5612 | |
5613 | p += len; |
5614 | } |
5615 | break; |
5616 | |
5617 | case '*': |
5618 | if (soft_matched_part) |
5619 | { |
5620 | do_spec_1 (soft_matched_part, 1, NULL( ( void * ) 0 )); |
5621 | do_spec_1 (" ", 0, NULL( ( void * ) 0 )); |
5622 | } |
5623 | else |
5624 | /* Catch the case where a spec string contains something like |
5625 | '%{foo:%*}'. i.e. there is no * in the pattern on the left |
5626 | hand side of the :. */ |
5627 | error ("spec failure: '%%*' has not been initialized by pattern match"); |
5628 | break; |
5629 | |
5630 | /* Process a string found as the value of a spec given by name. |
5631 | This feature allows individual machine descriptions |
5632 | to add and use their own specs. |
5633 | %[...] modifies -D options the way %P does; |
5634 | %(...) uses the spec unmodified. */ |
5635 | case '[': |
5636 | error ("warning: use of obsolete %%[ operator in specs"); |
5637 | case '(': |
5638 | { |
5639 | const char *name = p; |
5640 | struct spec_list *sl; |
5641 | int len; |
5642 | |
5643 | /* The string after the S/P is the name of a spec that is to be |
5644 | processed. */ |
5645 | while (*p && *p != ')' && *p != ']') |
5646 | p++; |
5647 | |
5648 | /* See if it's in the list. */ |
5649 | for (len = p - name, sl = specs; sl; sl = sl->next) |
5650 | if (sl->name_len == len && !strncmp (sl->name, name, len)) |
5651 | { |
5652 | name = *(sl->ptr_spec); |
5653 | #ifdef DEBUG_SPECS |
5654 | notice ("Processing spec %c%s%c, which is '%s'\n", |
5655 | c, sl->name, (c == '(') ? ')' : ']', name); |
5656 | #endif |
5657 | break; |
5658 | } |
5659 | |
5660 | if (sl) |
5661 | { |
5662 | if (c == '(') |
5663 | { |
5664 | value = do_spec_1 (name, 0, NULL( ( void * ) 0 )); |
5665 | if (value != 0) |
5666 | return value; |
5667 | } |
5668 | else |
5669 | { |
5670 | char *x = alloca__builtin_alloca ( strlen ( name ) * 2 + 1 ) (strlen (name) * 2 + 1); |
5671 | char *buf = x; |
5672 | const char *y = name; |
5673 | int flag = 0; |
5674 | |
5675 | /* Copy all of NAME into BUF, but put __ after |
5676 | every -D and at the end of each arg. */ |
5677 | while (1) |
5678 | { |
5679 | if (! strncmp (y, "-D", 2)) |
5680 | { |
5681 | *x++ = '-'; |
5682 | *x++ = 'D'; |
5683 | *x++ = '_'; |
5684 | *x++ = '_'; |
5685 | y += 2; |
5686 | flag = 1; |
5687 | continue; |
5688 | } |
5689 | else if (flag |
5690 | && (*y == ' ' || *y == '\t' || *y == '=' |
5691 | || *y == '}' || *y == 0)) |
5692 | { |
5693 | *x++ = '_'; |
5694 | *x++ = '_'; |
5695 | flag = 0; |
5696 | } |
5697 | if (*y == 0) |
5698 | break; |
5699 | else |
5700 | *x++ = *y++; |
5701 | } |
5702 | *x = 0; |
5703 | |
5704 | value = do_spec_1 (buf, 0, NULL( ( void * ) 0 )); |
5705 | if (value != 0) |
5706 | return value; |
5707 | } |
5708 | } |
5709 | |
5710 | /* Discard the closing paren or bracket. */ |
5711 | if (*p) |
5712 | p++; |
5713 | } |
5714 | break; |
5715 | |
5716 | default: |
5717 | error ("spec failure: unrecognized spec option '%c'", c); |
5718 | break; |
5719 | } |
5720 | break; |
5721 | |
5722 | case '\\': |
5723 | /* Backslash: treat next character as ordinary. */ |
5724 | c = *p++; |
5725 | |
5726 | /* Fall through. */ |
5727 | default: |
5728 | /* Ordinary character: put it into the current argument. */ |
5729 | obstack_1grow__extension__ ( { struct obstack * __o = ( & obstack ) ; if ( __o -> next_free + 1 > __o -> chunk_limit ) _obstack_newchunk ( __o , 1 ) ; ( * ( ( __o ) -> next_free ) ++ = ( c ) ) ; ( void ) 0 ; } ) (&obstack, c); |
5730 | arg_going = 1; |
5731 | } |
5732 | |
5733 | /* End of string. If we are processing a spec function, we need to |
5734 | end any pending argument. */ |
5735 | if (processing_spec_function && arg_going) |
5736 | { |
5737 | obstack_1grow__extension__ ( { struct obstack * __o = ( & obstack ) ; if ( __o -> next_free + 1 > __o -> chunk_limit ) _obstack_newchunk ( __o , 1 ) ; ( * ( ( __o ) -> next_free ) ++ = ( 0 ) ) ; ( void ) 0 ; } ) (&obstack, 0); |
5738 | string = XOBFINISH( ( const char * ) __extension__ ( { struct obstack * __o1 = ( ( & obstack ) ) ; void * value ; value = ( void * ) __o1 -> object_base ; if ( __o1 -> next_free == value ) __o1 -> maybe_empty_object = 1 ; __o1 -> next_free = ( ( ( ( ( __o1 -> next_free ) - ( char * ) 0 ) + __o1 -> alignment_mask ) & ~ ( __o1 -> alignment_mask ) ) + ( char * ) 0 ) ; if ( __o1 -> next_free - ( char * ) __o1 -> chunk > __o1 -> chunk_limit - ( char * ) __o1 -> chunk ) __o1 -> next_free = __o1 -> chunk_limit ; __o1 -> object_base = __o1 -> next_free ; value ; } ) ) (&obstack, const char *); |
5739 | if (this_is_library_file) |
5740 | string = find_file (string); |
5741 | store_arg (string, delete_this_arg, this_is_output_file); |
5742 | if (this_is_output_file) |
5743 | outfiles[input_file_number] = string; |
5744 | arg_going = 0; |
5745 | } |
5746 | |
5747 | return 0; |
5748 | } |
5749 | |
5750 | /* Look up a spec function. */ |
5751 | |
5752 | static const struct spec_function * |
5753 | lookup_spec_function (const char *name) |
5754 | { |
5755 | const struct spec_function *sf; |
5756 | |
5757 | for (sf = static_spec_functions; sf->name != NULL( ( void * ) 0 ); sf++) |
5758 | if (strcmp (sf->name, name) == 0) |
5759 | return sf; |
5760 | |
5761 | return NULL( ( void * ) 0 ); |
5762 | } |
5763 | |
5764 | /* Evaluate a spec function. */ |
5765 | |
5766 | static const char * |
5767 | eval_spec_function (const char *func, const char *args) |
5768 | { |
5769 | const struct spec_function *sf; |
5770 | const char *funcval; |
5771 | |
5772 | /* Saved spec processing context. */ |
5773 | int save_argbuf_index; |
5774 | int save_argbuf_length; |
5775 | const char **save_argbuf; |
5776 | |
5777 | int save_arg_going; |
5778 | int save_delete_this_arg; |
5779 | int save_this_is_output_file; |
5780 | int save_this_is_library_file; |
5781 | int save_input_from_pipe; |
5782 | const char *save_suffix_subst; |
5783 | |
5784 | |
5785 | sf = lookup_spec_function (func); |
5786 | if (sf == NULL( ( void * ) 0 )) |
5787 | fatal ("unknown spec function '%s'", func); |
5788 | |
5789 | /* Push the spec processing context. */ |
5790 | save_argbuf_index = argbuf_index; |
5791 | save_argbuf_length = argbuf_length; |
5792 | save_argbuf = argbuf; |
5793 | |
5794 | save_arg_going = arg_going; |
5795 | save_delete_this_arg = delete_this_arg; |
5796 | save_this_is_output_file = this_is_output_file; |
5797 | save_this_is_library_file = this_is_library_file; |
5798 | save_input_from_pipe = input_from_pipe; |
5799 | save_suffix_subst = suffix_subst; |
5800 | |
5801 | /* Create a new spec processing context, and build the function |
5802 | arguments. */ |
5803 | |
5804 | alloc_args (); |
5805 | if (do_spec_2 (args) < 0) |
5806 | fatal ("error in args to spec function '%s'", func); |
5807 | |
5808 | /* argbuf_index is an index for the next argument to be inserted, and |
5809 | so contains the count of the args already inserted. */ |
5810 | |
5811 | funcval = (*sf->func) (argbuf_index, argbuf); |
5812 | |
5813 | /* Pop the spec processing context. */ |
5814 | argbuf_index = save_argbuf_index; |
5815 | argbuf_length = save_argbuf_length; |
5816 | free (argbuf); |
5817 | argbuf = save_argbuf; |
5818 | |
5819 | arg_going = save_arg_going; |
5820 | delete_this_arg = save_delete_this_arg; |
5821 | this_is_output_file = save_this_is_output_file; |
5822 | this_is_library_file = save_this_is_library_file; |
5823 | input_from_pipe = save_input_from_pipe; |
5824 | suffix_subst = save_suffix_subst; |
5825 | |
5826 | return funcval; |
5827 | } |
5828 | |
5829 | /* Handle a spec function call of the form: |
5830 | |
5831 | %:function(args) |
5832 | |
5833 | ARGS is processed as a spec in a separate context and split into an |
5834 | argument vector in the normal fashion. The function returns a string |
5835 | containing a spec which we then process in the caller's context, or |
5836 | NULL if no processing is required. */ |
5837 | |
5838 | static const char * |
5839 | handle_spec_function (const char *p) |
5840 | { |
5841 | char *func, *args; |
5842 | const char *endp, *funcval; |
5843 | int count; |
5844 | |
5845 | processing_spec_function++; |
5846 | |
5847 | /* Get the function name. */ |
5848 | for (endp = p; *endp != '\0'; endp++) |
5849 | { |
5850 | if (*endp == '(') /* ) */ |
5851 | break; |
5852 | /* Only allow [A-Za-z0-9], -, and _ in function names. */ |
5853 | if (!ISALNUM( _sch_istable [ ( * endp ) & 0xff ] & ( unsigned short ) ( _sch_isalnum ) ) (*endp) && !(*endp == '-' || *endp == '_')) |
5854 | fatal ("malformed spec function name"); |
5855 | } |
5856 | if (*endp != '(') /* ) */ |
5857 | fatal ("no arguments for spec function"); |
5858 | func = save_string (p, endp - p); |
5859 | p = ++endp; |
5860 | |
5861 | /* Get the arguments. */ |
5862 | for (count = 0; *endp != '\0'; endp++) |
5863 | { |
5864 | /* ( */ |
5865 | if (*endp == ')') |
5866 | { |
5867 | if (count == 0) |
5868 | break; |
5869 | count--; |
5870 | } |
5871 | else if (*endp == '(') /* ) */ |
5872 | count++; |
5873 | } |
5874 | /* ( */ |
5875 | if (*endp != ')') |
5876 | fatal ("malformed spec function arguments"); |
5877 | args = save_string (p, endp - p); |
5878 | p = ++endp; |
5879 | |
5880 | /* p now points to just past the end of the spec function expression. */ |
5881 | |
5882 | funcval = eval_spec_function (func, args); |
5883 | if (funcval != NULL( ( void * ) 0 ) && do_spec_1 (funcval, 0, NULL( ( void * ) 0 )) < 0) |
5884 | p = NULL( ( void * ) 0 ); |
5885 | |
5886 | free (func); |
5887 | free (args); |
5888 | |
5889 | processing_spec_function--; |
5890 | |
5891 | return p; |
5892 | } |
5893 | |
5894 | /* Inline subroutine of handle_braces. Returns true if the current |
5895 | input suffix matches the atom bracketed by ATOM and END_ATOM. */ |
5896 | static inline__inline__ bool_Bool |
5897 | input_suffix_matches (const char *atom, const char *end_atom) |
5898 | /* APPLE LOCAL begin mainline 2007-03-13 5040758 */ \ |
5899 | { |
5900 | return (input_suffix |
5901 | && !strncmp (input_suffix, atom, end_atom - atom) |
5902 | && input_suffix[end_atom - atom] == '\0'); |
5903 | } |
5904 | |
5905 | /* Subroutine of handle_braces. Returns true if the current |
5906 | input file's spec name matches the atom bracketed by ATOM and END_ATOM. */ |
5907 | static bool_Bool |
5908 | input_spec_matches (const char *atom, const char *end_atom) |
5909 | { |
5910 | return (input_file_compiler |
5911 | && input_file_compiler->suffix |
5912 | && input_file_compiler->suffix[0] != '\0' |
5913 | && !strncmp (input_file_compiler->suffix + 1, atom, |
5914 | end_atom - atom) |
5915 | && input_file_compiler->suffix[end_atom - atom + 1] == '\0'); |
5916 | } |
5917 | |
5918 | /* APPLE LOCAL end mainline 2007-03-13 5040758 */ \ |
5919 | /* Subroutine of handle_braces. Returns true if a switch |
5920 | matching the atom bracketed by ATOM and END_ATOM appeared on the |
5921 | command line. */ |
5922 | static bool_Bool |
5923 | switch_matches (const char *atom, const char *end_atom, int starred) |
5924 | { |
5925 | int i; |
5926 | int len = end_atom - atom; |
5927 | int plen = starred ? len : -1; |
5928 | |
5929 | for (i = 0; i < n_switches; i++) |
5930 | if (!strncmp (switches[i].part1, atom, len) |
5931 | && (starred || switches[i].part1[len] == '\0') |
5932 | && check_live_switch (i, plen)) |
5933 | return true1; |
5934 | |
5935 | return false0; |
5936 | } |
5937 | |
5938 | /* Inline subroutine of handle_braces. Mark all of the switches which |
5939 | match ATOM (extends to END_ATOM; STARRED indicates whether there |
5940 | was a star after the atom) for later processing. */ |
5941 | static inline__inline__ void |
5942 | mark_matching_switches (const char *atom, const char *end_atom, int starred) |
5943 | { |
5944 | int i; |
5945 | int len = end_atom - atom; |
5946 | int plen = starred ? len : -1; |
5947 | |
5948 | for (i = 0; i < n_switches; i++) |
5949 | if (!strncmp (switches[i].part1, atom, len) |
5950 | && (starred || switches[i].part1[len] == '\0') |
5951 | && check_live_switch (i, plen)) |
5952 | switches[i].ordering = 1; |
5953 | } |
5954 | |
5955 | /* Inline subroutine of handle_braces. Process all the currently |
5956 | marked switches through give_switch, and clear the marks. */ |
5957 | static inline__inline__ void |
5958 | process_marked_switches (void) |
5959 | { |
5960 | int i; |
5961 | |
5962 | for (i = 0; i < n_switches; i++) |
5963 | if (switches[i].ordering == 1) |
5964 | { |
5965 | switches[i].ordering = 0; |
5966 | give_switch (i, 0); |
5967 | } |
5968 | } |
5969 | |
5970 | /* Handle a %{ ... } construct. P points just inside the leading {. |
5971 | Returns a pointer one past the end of the brace block, or 0 |
5972 | if we call do_spec_1 and that returns -1. */ |
5973 | |
5974 | static const char * |
5975 | handle_braces (const char *p) |
5976 | { |
5977 | const char *atom, *end_atom; |
5978 | const char *d_atom = NULL( ( void * ) 0 ), *d_end_atom = NULL( ( void * ) 0 ); |
5979 | const char *orig = p; |
5980 | |
5981 | bool_Bool a_is_suffix; |
5982 | /* APPLE LOCAL begin mainline 2007-03-13 5040758 */ \ |
5983 | bool_Bool a_is_spectype; |
5984 | /* APPLE LOCAL end mainline 2007-03-13 5040758 */ \ |
5985 | bool_Bool a_is_starred; |
5986 | bool_Bool a_is_negated; |
5987 | bool_Bool a_matched; |
5988 | |
5989 | bool_Bool a_must_be_last = false0; |
5990 | bool_Bool ordered_set = false0; |
5991 | bool_Bool disjunct_set = false0; |
5992 | bool_Bool disj_matched = false0; |
5993 | bool_Bool disj_starred = true1; |
5994 | bool_Bool n_way_choice = false0; |
5995 | bool_Bool n_way_matched = false0; |
5996 | |
5997 | #define SKIP_WHITE() do { while (*p == ' ' || *p == '\t') p++; } while (0) |
5998 | |
5999 | do |
6000 | { |
6001 | if (a_must_be_last) |
6002 | goto invalid; |
6003 | |
6004 | /* APPLE LOCAL begin mainline 2007-03-13 5040758 */ \ |
6005 | /* Scan one "atom" (S in the description above of %{}, possibly |
6006 | with '!', '.', '@', ',', or '*' modifiers). */ |
6007 | a_matched = false0; |
6008 | a_is_suffix = false0; |
6009 | a_is_starred = false0; |
6010 | a_is_negated = false0; |
6011 | a_is_spectype = false0; |
6012 | |
6013 | /* APPLE LOCAL end mainline 2007-03-13 5040758 */ \ |
6014 | SKIP_WHITEdo { while ( * p == ' ' || * p == '\t' ) p ++ ; } while ( 0 )(); |
6015 | if (*p == '!') |
6016 | p++, a_is_negated = true1; |
6017 | |
6018 | SKIP_WHITEdo { while ( * p == ' ' || * p == '\t' ) p ++ ; } while ( 0 )(); |
6019 | if (*p == '.') |
6020 | p++, a_is_suffix = true1; |
6021 | /* APPLE LOCAL begin mainline 2007-03-13 5040758 */ \ |
6022 | else if (*p == ',') |
6023 | p++, a_is_spectype = true1; |
6024 | |
6025 | /* APPLE LOCAL end mainline 2007-03-13 5040758 */ \ |
6026 | atom = p; |
6027 | while (ISIDNUM( _sch_istable [ ( * p ) & 0xff ] & ( unsigned short ) ( _sch_isidnum ) )(*p) || *p == '-' || *p == '+' || *p == '=' |
6028 | || *p == ',' || *p == '.' || *p == '@') |
6029 | p++; |
6030 | end_atom = p; |
6031 | |
6032 | if (*p == '*') |
6033 | p++, a_is_starred = 1; |
6034 | |
6035 | SKIP_WHITEdo { while ( * p == ' ' || * p == '\t' ) p ++ ; } while ( 0 )(); |
6036 | switch (*p) |
6037 | { |
6038 | case '&': case '}': |
6039 | /* Substitute the switch(es) indicated by the current atom. */ |
6040 | ordered_set = true1; |
6041 | if (disjunct_set || n_way_choice || a_is_negated || a_is_suffix |
6042 | /* APPLE LOCAL begin mainline 2007-03-13 5040758 */ \ |
6043 | || a_is_spectype || atom == end_atom) |
6044 | /* APPLE LOCAL end mainline 2007-03-13 5040758 */ \ |
6045 | goto invalid; |
6046 | |
6047 | mark_matching_switches (atom, end_atom, a_is_starred); |
6048 | |
6049 | if (*p == '}') |
6050 | process_marked_switches (); |
6051 | break; |
6052 | |
6053 | case '|': case ':': |
6054 | /* Substitute some text if the current atom appears as a switch |
6055 | or suffix. */ |
6056 | disjunct_set = true1; |
6057 | if (ordered_set) |
6058 | goto invalid; |
6059 | |
6060 | if (atom == end_atom) |
6061 | { |
6062 | if (!n_way_choice || disj_matched || *p == '|' |
6063 | /* APPLE LOCAL begin mainline 2007-03-13 5040758 */ \ |
6064 | || a_is_negated || a_is_suffix || a_is_spectype |
6065 | || a_is_starred) |
6066 | /* APPLE LOCAL end mainline 2007-03-13 5040758 */ \ |
6067 | goto invalid; |
6068 | |
6069 | /* An empty term may appear as the last choice of an |
6070 | N-way choice set; it means "otherwise". */ |
6071 | a_must_be_last = true1; |
6072 | disj_matched = !n_way_matched; |
6073 | disj_starred = false0; |
6074 | } |
6075 | else |
6076 | { |
6077 | /* APPLE LOCAL begin mainline 2007-03-13 5040758 */ \ |
6078 | if ((a_is_suffix || a_is_spectype) && a_is_starred) |
6079 | goto invalid; |
6080 | |
6081 | if (!a_is_starred) |
6082 | disj_starred = false0; |
6083 | |
6084 | /* Don't bother testing this atom if we already have a |
6085 | match. */ |
6086 | if (!disj_matched && !n_way_matched) |
6087 | { |
6088 | if (a_is_suffix) |
6089 | a_matched = input_suffix_matches (atom, end_atom); |
6090 | else if (a_is_spectype) |
6091 | a_matched = input_spec_matches (atom, end_atom); |
6092 | else |
6093 | a_matched = switch_matches (atom, end_atom, a_is_starred); |
6094 | |
6095 | if (a_matched != a_is_negated) |
6096 | { |
6097 | disj_matched = true1; |
6098 | d_atom = atom; |
6099 | d_end_atom = end_atom; |
6100 | } |
6101 | } |
6102 | /* APPLE LOCAL end mainline 2007-03-13 5040758 */ \ |
6103 | } |
6104 | |
6105 | if (*p == ':') |
6106 | { |
6107 | /* Found the body, that is, the text to substitute if the |
6108 | current disjunction matches. */ |
6109 | p = process_brace_body (p + 1, d_atom, d_end_atom, disj_starred, |
6110 | disj_matched && !n_way_matched); |
6111 | if (p == 0) |
6112 | return 0; |
6113 | |
6114 | /* If we have an N-way choice, reset state for the next |
6115 | disjunction. */ |
6116 | if (*p == ';') |
6117 | { |
6118 | n_way_choice = true1; |
6119 | n_way_matched |= disj_matched; |
6120 | disj_matched = false0; |
6121 | disj_starred = true1; |
6122 | d_atom = d_end_atom = NULL( ( void * ) 0 ); |
6123 | } |
6124 | } |
6125 | break; |
6126 | |
6127 | default: |
6128 | goto invalid; |
6129 | } |
6130 | } |
6131 | while (*p++ != '}'); |
6132 | |
6133 | return p; |
6134 | |
6135 | invalid: |
6136 | fatal ("braced spec '%s' is invalid at '%c'", orig, *p); |
6137 | |
6138 | #undef SKIP_WHITE |
6139 | } |
6140 | |
6141 | /* Subroutine of handle_braces. Scan and process a brace substitution body |
6142 | (X in the description of %{} syntax). P points one past the colon; |
6143 | ATOM and END_ATOM bracket the first atom which was found to be true |
6144 | (present) in the current disjunction; STARRED indicates whether all |
6145 | the atoms in the current disjunction were starred (for syntax validation); |
6146 | MATCHED indicates whether the disjunction matched or not, and therefore |
6147 | whether or not the body is to be processed through do_spec_1 or just |
6148 | skipped. Returns a pointer to the closing } or ;, or 0 if do_spec_1 |
6149 | returns -1. */ |
6150 | |
6151 | static const char * |
6152 | process_brace_body (const char *p, const char *atom, const char *end_atom, |
6153 | int starred, int matched) |
6154 | { |
6155 | const char *body, *end_body; |
6156 | unsigned int nesting_level; |
6157 | bool_Bool have_subst = false0; |
6158 | |
6159 | /* Locate the closing } or ;, honoring nested braces. |
6160 | Trim trailing whitespace. */ |
6161 | body = p; |
6162 | nesting_level = 1; |
6163 | for (;;) |
6164 | { |
6165 | if (*p == '{') |
6166 | nesting_level++; |
6167 | else if (*p == '}') |
6168 | { |
6169 | if (!--nesting_level) |
6170 | break; |
6171 | } |
6172 | else if (*p == ';' && nesting_level == 1) |
6173 | break; |
6174 | else if (*p == '%' && p[1] == '*' && nesting_level == 1) |
6175 | have_subst = true1; |
6176 | else if (*p == '\0') |
6177 | goto invalid; |
6178 | p++; |
6179 | } |
6180 | |
6181 | end_body = p; |
6182 | while (end_body[-1] == ' ' || end_body[-1] == '\t') |
6183 | end_body--; |
6184 | |
6185 | if (have_subst && !starred) |
6186 | goto invalid; |
6187 | |
6188 | if (matched) |
6189 | { |
6190 | /* Copy the substitution body to permanent storage and execute it. |
6191 | If have_subst is false, this is a simple matter of running the |
6192 | body through do_spec_1... */ |
6193 | char *string = save_string (body, end_body - body); |
6194 | if (!have_subst) |
6195 | { |
6196 | if (do_spec_1 (string, 0, NULL( ( void * ) 0 )) < 0) |
6197 | return 0; |
6198 | } |
6199 | else |
6200 | { |
6201 | /* ... but if have_subst is true, we have to process the |
6202 | body once for each matching switch, with %* set to the |
6203 | variant part of the switch. */ |
6204 | unsigned int hard_match_len = end_atom - atom; |
6205 | int i; |
6206 | |
6207 | for (i = 0; i < n_switches; i++) |
6208 | if (!strncmp (switches[i].part1, atom, hard_match_len) |
6209 | && check_live_switch (i, hard_match_len)) |
6210 | { |
6211 | if (do_spec_1 (string, 0, |
6212 | &switches[i].part1[hard_match_len]) < 0) |
6213 | return 0; |
6214 | /* Pass any arguments this switch has. */ |
6215 | give_switch (i, 1); |
6216 | suffix_subst = NULL( ( void * ) 0 ); |
6217 | } |
6218 | } |
6219 | } |
6220 | |
6221 | return p; |
6222 | |
6223 | invalid: |
6224 | fatal ("braced spec body '%s' is invalid", body); |
6225 | } |
6226 | |
6227 | /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch |
6228 | on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*} |
6229 | spec, or -1 if either exact match or %* is used. |
6230 | |
6231 | A -O switch is obsoleted by a later -O switch. A -f, -m, or -W switch |
6232 | whose value does not begin with "no-" is obsoleted by the same value |
6233 | with the "no-", similarly for a switch with the "no-" prefix. */ |
6234 | |
6235 | static int |
6236 | check_live_switch (int switchnum, int prefix_length) |
6237 | { |
6238 | const char *name = switches[switchnum].part1; |
6239 | int i; |
6240 | |
6241 | /* In the common case of {<at-most-one-letter>*}, a negating |
6242 | switch would always match, so ignore that case. We will just |
6243 | send the conflicting switches to the compiler phase. */ |
6244 | if (prefix_length >= 0 && prefix_length <= 1) |
6245 | return 1; |
6246 | |
6247 | /* If we already processed this switch and determined if it was |
6248 | live or not, return our past determination. */ |
6249 | if (switches[switchnum].live_cond != 0) |
6250 | return switches[switchnum].live_cond > 0; |
6251 | |
6252 | /* Now search for duplicate in a manner that depends on the name. */ |
6253 | switch (*name) |
6254 | { |
6255 | case 'O': |
6256 | for (i = switchnum + 1; i < n_switches; i++) |
6257 | if (switches[i].part1[0] == 'O') |
6258 | { |
6259 | switches[switchnum].validated = 1; |
6260 | switches[switchnum].live_cond = SWITCH_FALSE- 1; |
6261 | return 0; |
6262 | } |
6263 | break; |
6264 | |
6265 | case 'W': case 'f': case 'm': |
6266 | if (! strncmp (name + 1, "no-", 3)) |
6267 | { |
6268 | /* We have Xno-YYY, search for XYYY. */ |
6269 | for (i = switchnum + 1; i < n_switches; i++) |
6270 | if (switches[i].part1[0] == name[0] |
6271 | && ! strcmp (&switches[i].part1[1], &name[4])) |
6272 | { |
6273 | switches[switchnum].validated = 1; |
6274 | switches[switchnum].live_cond = SWITCH_FALSE- 1; |
6275 | return 0; |
6276 | } |
6277 | } |
6278 | else |
6279 | { |
6280 | /* We have XYYY, search for Xno-YYY. */ |
6281 | for (i = switchnum + 1; i < n_switches; i++) |
6282 | if (switches[i].part1[0] == name[0] |
6283 | && switches[i].part1[1] == 'n' |
6284 | && switches[i].part1[2] == 'o' |
6285 | && switches[i].part1[3] == '-' |
6286 | && !strcmp (&switches[i].part1[4], &name[1])) |
6287 | { |
6288 | switches[switchnum].validated = 1; |
6289 | switches[switchnum].live_cond = SWITCH_FALSE- 1; |
6290 | return 0; |
6291 | } |
6292 | } |
6293 | break; |
6294 | } |
6295 | |
6296 | /* Otherwise the switch is live. */ |
6297 | switches[switchnum].live_cond = SWITCH_LIVE1; |
6298 | return 1; |
6299 | } |
6300 | |
6301 | /* Pass a switch to the current accumulating command |
6302 | in the same form that we received it. |
6303 | SWITCHNUM identifies the switch; it is an index into |
6304 | the vector of switches gcc received, which is `switches'. |
6305 | This cannot fail since it never finishes a command line. |
6306 | |
6307 | If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */ |
6308 | |
6309 | static void |
6310 | give_switch (int switchnum, int omit_first_word) |
6311 | { |
6312 | if (switches[switchnum].live_cond == SWITCH_IGNORE- 2) |
6313 | return; |
6314 | |
6315 | if (!omit_first_word) |
6316 | { |
6317 | do_spec_1 ("-", 0, NULL( ( void * ) 0 )); |
6318 | do_spec_1 (switches[switchnum].part1, 1, NULL( ( void * ) 0 )); |
6319 | } |
6320 | |
6321 | if (switches[switchnum].args != 0) |
6322 | { |
6323 | const char **p; |
6324 | for (p = switches[switchnum].args; *p; p++) |
6325 | { |
6326 | const char *arg = *p; |
6327 | |
6328 | do_spec_1 (" ", 0, NULL( ( void * ) 0 )); |
6329 | if (suffix_subst) |
6330 | { |
6331 | unsigned length = strlen (arg); |
6332 | int dot = 0; |
6333 | |
6334 | while (length-- && !IS_DIR_SEPARATOR( ( arg [ length ] ) == '/' ) (arg[length])) |
6335 | if (arg[length] == '.') |
6336 | { |
6337 | ((char *)arg)[length] = 0; |
6338 | dot = 1; |
6339 | break; |
6340 | } |
6341 | do_spec_1 (arg, 1, NULL( ( void * ) 0 )); |
6342 | if (dot) |
6343 | ((char *)arg)[length] = '.'; |
6344 | do_spec_1 (suffix_subst, 1, NULL( ( void * ) 0 )); |
6345 | } |
6346 | else |
6347 | do_spec_1 (arg, 1, NULL( ( void * ) 0 )); |
6348 | } |
6349 | } |
6350 | |
6351 | do_spec_1 (" ", 0, NULL( ( void * ) 0 )); |
6352 | switches[switchnum].validated = 1; |
6353 | } |
6354 | |
6355 | /* Search for a file named NAME trying various prefixes including the |
6356 | user's -B prefix and some standard ones. |
6357 | Return the absolute file name found. If nothing is found, return NAME. */ |
6358 | |
6359 | static const char * |
6360 | find_file (const char *name) |
6361 | { |
6362 | char *newname = find_a_file (&startfile_prefixes, name, R_OK( 1 << 2 ), true1); |
6363 | return newname ? newname : name; |
6364 | } |
6365 | |
6366 | /* Determine whether a directory exists. If LINKER, return 0 for |
6367 | certain fixed names not needed by the linker. */ |
6368 | |
6369 | static int |
6370 | is_directory (const char *path1, bool_Bool linker) |
6371 | { |
6372 | int len1; |
6373 | char *path; |
6374 | char *cp; |
6375 | struct stat st; |
6376 | |
6377 | /* Ensure the string ends with "/.". The resulting path will be a |
6378 | directory even if the given path is a symbolic link. */ |
6379 | len1 = strlen (path1); |
6380 | path = alloca__builtin_alloca ( 3 + len1 ) (3 + len1); |
6381 | memcpy (path, path1, len1); |
6382 | cp = path + len1; |
6383 | if (!IS_DIR_SEPARATOR( ( cp [ - 1 ] ) == '/' ) (cp[-1])) |
6384 | *cp++ = DIR_SEPARATOR'/'; |
6385 | *cp++ = '.'; |
6386 | *cp = '\0'; |
6387 | |
6388 | /* Exclude directories that the linker is known to search. */ |
6389 | if (linker |
6390 | && IS_DIR_SEPARATOR( ( path [ 0 ] ) == '/' ) (path[0]) |
6391 | && ((cp - path == 6 |
6392 | && strncmp (path + 1, "lib", 3) == 0) |
6393 | || (cp - path == 10 |
6394 | && strncmp (path + 1, "usr", 3) == 0 |
6395 | && IS_DIR_SEPARATOR( ( path [ 4 ] ) == '/' ) (path[4]) |
6396 | && strncmp (path + 5, "lib", 3) == 0))) |
6397 | return 0; |
6398 | |
6399 | return (stat (path, &st) >= 0 && S_ISDIR( ( ( st . st_mode ) & 0170000 ) == 0040000 ) (st.st_mode)); |
6400 | } |
6401 | |
6402 | /* Set up the various global variables to indicate that we're processing |
6403 | the input file named FILENAME. */ |
6404 | |
6405 | void |
6406 | set_input (const char *filename) |
6407 | { |
6408 | const char *p; |
6409 | |
6410 | input_filename = filename; |
6411 | input_filename_length = strlen (input_filename); |
6412 | |
6413 | input_basename = input_filename; |
6414 | #ifdef HAVE_DOS_BASED_FILE_SYSTEM |
6415 | /* Skip drive name so 'x:foo' is handled properly. */ |
6416 | if (input_basename[1] == ':') |
6417 | input_basename += 2; |
6418 | #endif |
6419 | for (p = input_basename; *p; p++) |
6420 | if (IS_DIR_SEPARATOR( ( * p ) == '/' ) (*p)) |
6421 | input_basename = p + 1; |
6422 | |
6423 | /* Find a suffix starting with the last period, |
6424 | and set basename_length to exclude that suffix. */ |
6425 | basename_length = strlen (input_basename); |
6426 | suffixed_basename_length = basename_length; |
6427 | p = input_basename + basename_length; |
6428 | while (p != input_basename && *p != '.') |
6429 | --p; |
6430 | if (*p == '.' && p != input_basename) |
6431 | { |
6432 | basename_length = p - input_basename; |
6433 | input_suffix = p + 1; |
6434 | } |
6435 | else |
6436 | input_suffix = ""; |
6437 | |
6438 | /* If a spec for 'g', 'u', or 'U' is seen with -save-temps then |
6439 | we will need to do a stat on the input_filename. The |
6440 | INPUT_STAT_SET signals that the stat is needed. */ |
6441 | input_stat_set = 0; |
6442 | } |
6443 | |
6444 | /* On fatal signals, delete all the temporary files. */ |
6445 | |
6446 | static void |
6447 | fatal_error (int signum) |
6448 | { |
6449 | signal (signum, SIG_DFL( void ( * ) ( int ) ) 0); |
6450 | delete_failure_queue (); |
6451 | delete_temp_files (); |
6452 | /* Get the same signal again, this time not handled, |
6453 | so its normal effect occurs. */ |
6454 | kill (getpid (), signum); |
6455 | } |
6456 | |
6457 | extern int main (int, char **); |
6458 | |
6459 | int |
6460 | main (int argc, char **argv) |
6461 | { |
6462 | size_t i; |
6463 | int value; |
6464 | int linker_was_run = 0; |
6465 | int lang_n_infiles = 0; |
6466 | int num_linker_inputs = 0; |
6467 | char *explicit_link_files; |
6468 | char *specs_file; |
6469 | const char *p; |
6470 | struct user_specs *uptr; |
6471 | |
6472 | /* APPLE LOCAL begin CC_PRINT_OPTIONS (radar 3313335, 3360444) */ |
6473 | cc_print_options = getenv ("CC_PRINT_OPTIONS"); |
6474 | cc_print_options_filename = getenv ("CC_PRINT_OPTIONS_FILE"); |
6475 | /* APPLE LOCAL end */ |
6476 | |
6477 | p = argv[0] + strlen (argv[0]); |
6478 | while (p != argv[0] && !IS_DIR_SEPARATOR( ( p [ - 1 ] ) == '/' ) (p[-1])) |
6479 | --p; |
6480 | programname = p; |
6481 | |
6482 | xmalloc_set_program_name (programname); |
6483 | |
6484 | expandargv (&argc, &argv); |
6485 | |
6486 | prune_options (&argc, &argv); |
6487 | |
6488 | #ifdef GCC_DRIVER_HOST_INITIALIZATION |
6489 | /* Perform host dependent initialization when needed. */ |
6490 | GCC_DRIVER_HOST_INITIALIZATIONdo { int i ; for ( i = 0 ; i < argc ; ++ i ) { if ( strcmp ( argv [ i ] , "-isysroot" ) == 0 ) { if ( argv [ i ] [ 9 ] ) target_system_root = & argv [ i ] [ 9 ] ; else if ( i + 1 < argc ) { target_system_root = argv [ i + 1 ] ; ++ i ; } } } } while ( 0 ) ; darwin_default_min_version ( & argc , & argv ); |
6491 | #endif |
6492 | |
6493 | /* Unlock the stdio streams. */ |
6494 | unlock_std_streams (); |
6495 | |
6496 | gcc_init_libintl (); |
6497 | |
6498 | if (signal (SIGINT2, SIG_IGN( void ( * ) ( int ) ) 1) != SIG_IGN( void ( * ) ( int ) ) 1) |
6499 | signal (SIGINT2, fatal_error); |
6500 | #ifdef SIGHUP |
6501 | if (signal (SIGHUP1, SIG_IGN( void ( * ) ( int ) ) 1) != SIG_IGN( void ( * ) ( int ) ) 1) |
6502 | signal (SIGHUP1, fatal_error); |
6503 | #endif |
6504 | if (signal (SIGTERM15, SIG_IGN( void ( * ) ( int ) ) 1) != SIG_IGN( void ( * ) ( int ) ) 1) |
6505 | signal (SIGTERM15, fatal_error); |
6506 | #ifdef SIGPIPE |
6507 | if (signal (SIGPIPE13, SIG_IGN( void ( * ) ( int ) ) 1) != SIG_IGN( void ( * ) ( int ) ) 1) |
6508 | signal (SIGPIPE13, fatal_error); |
6509 | #endif |
6510 | #ifdef SIGCHLD |
6511 | /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will |
6512 | receive the signal. A different setting is inheritable */ |
6513 | signal (SIGCHLD20, SIG_DFL( void ( * ) ( int ) ) 0); |
6514 | #endif |
6515 | |
6516 | /* Allocate the argument vector. */ |
6517 | alloc_args (); |
6518 | |
6519 | obstack_init_obstack_begin ( ( & obstack ) , 0 , 0 , ( void * ( * ) ( long ) ) ( ( void * ( * ) ( long ) ) xmalloc ) , ( void ( * ) ( void * ) ) ( ( void ( * ) ( void * ) ) free ) ) (&obstack); |
6520 | |
6521 | /* Build multilib_select, et. al from the separate lines that make up each |
6522 | multilib selection. */ |
6523 | { |
6524 | const char *const *q = multilib_raw; |
6525 | int need_space; |
6526 | |
6527 | obstack_init_obstack_begin ( ( & multilib_obstack ) , 0 , 0 , ( void * ( * ) ( long ) ) ( ( void * ( * ) ( long ) ) xmalloc ) , ( void ( * ) ( void * ) ) ( ( void ( * ) ( void * ) ) free ) ) (&multilib_obstack); |
6528 | while ((p = *q++) != (char *) 0) |
6529 | obstack_grow__extension__ ( { struct obstack * __o = ( & multilib_obstack ) ; int __len = ( strlen ( p ) ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( p ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&multilib_obstack, p, strlen (p)); |
6530 | |
6531 | obstack_1grow__extension__ ( { struct obstack * __o = ( & multilib_obstack ) ; if ( __o -> next_free + 1 > __o -> chunk_limit ) _obstack_newchunk ( __o , 1 ) ; ( * ( ( __o ) -> next_free ) ++ = ( 0 ) ) ; ( void ) 0 ; } ) (&multilib_obstack, 0); |
6532 | multilib_select = XOBFINISH( ( const char * ) __extension__ ( { struct obstack * __o1 = ( ( & multilib_obstack ) ) ; void * value ; value = ( void * ) __o1 -> object_base ; if ( __o1 -> next_free == value ) __o1 -> maybe_empty_object = 1 ; __o1 -> next_free = ( ( ( ( ( __o1 -> next_free ) - ( char * ) 0 ) + __o1 -> alignment_mask ) & ~ ( __o1 -> alignment_mask ) ) + ( char * ) 0 ) ; if ( __o1 -> next_free - ( char * ) __o1 -> chunk > __o1 -> chunk_limit - ( char * ) __o1 -> chunk ) __o1 -> next_free = __o1 -> chunk_limit ; __o1 -> object_base = __o1 -> next_free ; value ; } ) ) (&multilib_obstack, const char *); |
6533 | |
6534 | q = multilib_matches_raw; |
6535 | while ((p = *q++) != (char *) 0) |
6536 | obstack_grow__extension__ ( { struct obstack * __o = ( & multilib_obstack ) ; int __len = ( strlen ( p ) ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( p ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&multilib_obstack, p, strlen (p)); |
6537 | |
6538 | obstack_1grow__extension__ ( { struct obstack * __o = ( & multilib_obstack ) ; if ( __o -> next_free + 1 > __o -> chunk_limit ) _obstack_newchunk ( __o , 1 ) ; ( * ( ( __o ) -> next_free ) ++ = ( 0 ) ) ; ( void ) 0 ; } ) (&multilib_obstack, 0); |
6539 | multilib_matches = XOBFINISH( ( const char * ) __extension__ ( { struct obstack * __o1 = ( ( & multilib_obstack ) ) ; void * value ; value = ( void * ) __o1 -> object_base ; if ( __o1 -> next_free == value ) __o1 -> maybe_empty_object = 1 ; __o1 -> next_free = ( ( ( ( ( __o1 -> next_free ) - ( char * ) 0 ) + __o1 -> alignment_mask ) & ~ ( __o1 -> alignment_mask ) ) + ( char * ) 0 ) ; if ( __o1 -> next_free - ( char * ) __o1 -> chunk > __o1 -> chunk_limit - ( char * ) __o1 -> chunk ) __o1 -> next_free = __o1 -> chunk_limit ; __o1 -> object_base = __o1 -> next_free ; value ; } ) ) (&multilib_obstack, const char *); |
6540 | |
6541 | q = multilib_exclusions_raw; |
6542 | while ((p = *q++) != (char *) 0) |
6543 | obstack_grow__extension__ ( { struct obstack * __o = ( & multilib_obstack ) ; int __len = ( strlen ( p ) ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( p ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&multilib_obstack, p, strlen (p)); |
6544 | |
6545 | obstack_1grow__extension__ ( { struct obstack * __o = ( & multilib_obstack ) ; if ( __o -> next_free + 1 > __o -> chunk_limit ) _obstack_newchunk ( __o , 1 ) ; ( * ( ( __o ) -> next_free ) ++ = ( 0 ) ) ; ( void ) 0 ; } ) (&multilib_obstack, 0); |
6546 | multilib_exclusions = XOBFINISH( ( const char * ) __extension__ ( { struct obstack * __o1 = ( ( & multilib_obstack ) ) ; void * value ; value = ( void * ) __o1 -> object_base ; if ( __o1 -> next_free == value ) __o1 -> maybe_empty_object = 1 ; __o1 -> next_free = ( ( ( ( ( __o1 -> next_free ) - ( char * ) 0 ) + __o1 -> alignment_mask ) & ~ ( __o1 -> alignment_mask ) ) + ( char * ) 0 ) ; if ( __o1 -> next_free - ( char * ) __o1 -> chunk > __o1 -> chunk_limit - ( char * ) __o1 -> chunk ) __o1 -> next_free = __o1 -> chunk_limit ; __o1 -> object_base = __o1 -> next_free ; value ; } ) ) (&multilib_obstack, const char *); |
6547 | |
6548 | need_space = FALSE0; |
6549 | for (i = 0; i < ARRAY_SIZE( sizeof ( multilib_defaults_raw ) / sizeof ( ( multilib_defaults_raw ) [ 0 ] ) ) (multilib_defaults_raw); i++) |
6550 | { |
6551 | if (need_space) |
6552 | obstack_1grow__extension__ ( { struct obstack * __o = ( & multilib_obstack ) ; if ( __o -> next_free + 1 > __o -> chunk_limit ) _obstack_newchunk ( __o , 1 ) ; ( * ( ( __o ) -> next_free ) ++ = ( ' ' ) ) ; ( void ) 0 ; } ) (&multilib_obstack, ' '); |
6553 | obstack_grow__extension__ ( { struct obstack * __o = ( & multilib_obstack ) ; int __len = ( strlen ( multilib_defaults_raw [ i ] ) ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( multilib_defaults_raw [ i ] ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&multilib_obstack, |
6554 | multilib_defaults_raw[i], |
6555 | strlen (multilib_defaults_raw[i])); |
6556 | need_space = TRUE1; |
6557 | } |
6558 | |
6559 | obstack_1grow__extension__ ( { struct obstack * __o = ( & multilib_obstack ) ; if ( __o -> next_free + 1 > __o -> chunk_limit ) _obstack_newchunk ( __o , 1 ) ; ( * ( ( __o ) -> next_free ) ++ = ( 0 ) ) ; ( void ) 0 ; } ) (&multilib_obstack, 0); |
6560 | multilib_defaults = XOBFINISH( ( const char * ) __extension__ ( { struct obstack * __o1 = ( ( & multilib_obstack ) ) ; void * value ; value = ( void * ) __o1 -> object_base ; if ( __o1 -> next_free == value ) __o1 -> maybe_empty_object = 1 ; __o1 -> next_free = ( ( ( ( ( __o1 -> next_free ) - ( char * ) 0 ) + __o1 -> alignment_mask ) & ~ ( __o1 -> alignment_mask ) ) + ( char * ) 0 ) ; if ( __o1 -> next_free - ( char * ) __o1 -> chunk > __o1 -> chunk_limit - ( char * ) __o1 -> chunk ) __o1 -> next_free = __o1 -> chunk_limit ; __o1 -> object_base = __o1 -> next_free ; value ; } ) ) (&multilib_obstack, const char *); |
6561 | } |
6562 | |
6563 | /* Set up to remember the pathname of gcc and any options |
6564 | needed for collect. We use argv[0] instead of programname because |
6565 | we need the complete pathname. */ |
6566 | obstack_init_obstack_begin ( ( & collect_obstack ) , 0 , 0 , ( void * ( * ) ( long ) ) ( ( void * ( * ) ( long ) ) xmalloc ) , ( void ( * ) ( void * ) ) ( ( void ( * ) ( void * ) ) free ) ) (&collect_obstack); |
6567 | obstack_grow__extension__ ( { struct obstack * __o = ( & collect_obstack ) ; int __len = ( sizeof ( "COLLECT_GCC=" ) - 1 ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( "COLLECT_GCC=" ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=") - 1); |
6568 | obstack_grow__extension__ ( { struct obstack * __o = ( & collect_obstack ) ; int __len = ( strlen ( argv [ 0 ] ) + 1 ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( argv [ 0 ] ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&collect_obstack, argv[0], strlen (argv[0]) + 1); |
6569 | putenv (XOBFINISH( ( char * ) __extension__ ( { struct obstack * __o1 = ( ( & collect_obstack ) ) ; void * value ; value = ( void * ) __o1 -> object_base ; if ( __o1 -> next_free == value ) __o1 -> maybe_empty_object = 1 ; __o1 -> next_free = ( ( ( ( ( __o1 -> next_free ) - ( char * ) 0 ) + __o1 -> alignment_mask ) & ~ ( __o1 -> alignment_mask ) ) + ( char * ) 0 ) ; if ( __o1 -> next_free - ( char * ) __o1 -> chunk > __o1 -> chunk_limit - ( char * ) __o1 -> chunk ) __o1 -> next_free = __o1 -> chunk_limit ; __o1 -> object_base = __o1 -> next_free ; value ; } ) ) (&collect_obstack, char *)); |
6570 | |
6571 | #ifdef INIT_ENVIRONMENT |
6572 | /* Set up any other necessary machine specific environment variables. */ |
6573 | putenv (INIT_ENVIRONMENT); |
6574 | #endif |
6575 | |
6576 | /* Make a table of what switches there are (switches, n_switches). |
6577 | Make a table of specified input files (infiles, n_infiles). |
6578 | Decode switches that are handled locally. */ |
6579 | |
6580 | process_command (argc, (const char **) argv); |
6581 | |
6582 | /* Initialize the vector of specs to just the default. |
6583 | This means one element containing 0s, as a terminator. */ |
6584 | |
6585 | compilers = xmalloc (sizeof default_compilers); |
6586 | memcpy (compilers, default_compilers, sizeof default_compilers); |
6587 | n_compilers = n_default_compilers; |
6588 | |
6589 | /* Read specs from a file if there is one. */ |
6590 | |
6591 | machine_suffix = concat (spec_machine, dir_separator_str, |
6592 | spec_version, dir_separator_str, NULL( ( void * ) 0 )); |
6593 | just_machine_suffix = concat (spec_machine, dir_separator_str, NULL( ( void * ) 0 )); |
6594 | |
6595 | specs_file = find_a_file (&startfile_prefixes, "specs", R_OK( 1 << 2 ), true1); |
6596 | /* Read the specs file unless it is a default one. */ |
6597 | if (specs_file != 0 && strcmp (specs_file, "specs")) |
6598 | read_specs (specs_file, TRUE1); |
6599 | else |
6600 | init_spec (); |
6601 | |
6602 | /* We need to check standard_exec_prefix/just_machine_suffix/specs |
6603 | for any override of as, ld and libraries. */ |
6604 | specs_file = alloca__builtin_alloca ( strlen ( standard_exec_prefix ) + strlen ( just_machine_suffix ) + sizeof ( "specs" ) ) (strlen (standard_exec_prefix) |
6605 | + strlen (just_machine_suffix) + sizeof ("specs")); |
6606 | |
6607 | strcpy (specs_file, standard_exec_prefix); |
6608 | strcat (specs_file, just_machine_suffix); |
6609 | strcat (specs_file, "specs"); |
6610 | if (access (specs_file, R_OK( 1 << 2 )) == 0) |
6611 | read_specs (specs_file, TRUE1); |
6612 | |
6613 | /* Process any configure-time defaults specified for the command line |
6614 | options, via OPTION_DEFAULT_SPECS. */ |
6615 | for (i = 0; i < ARRAY_SIZE( sizeof ( option_default_specs ) / sizeof ( ( option_default_specs ) [ 0 ] ) ) (option_default_specs); i++) |
6616 | do_option_spec (option_default_specs[i].name, |
6617 | option_default_specs[i].spec); |
6618 | |
6619 | /* Process DRIVER_SELF_SPECS, adding any new options to the end |
6620 | of the command line. */ |
6621 | |
6622 | for (i = 0; i < ARRAY_SIZE( sizeof ( driver_self_specs ) / sizeof ( ( driver_self_specs ) [ 0 ] ) ) (driver_self_specs); i++) |
6623 | do_self_spec (driver_self_specs[i]); |
6624 | |
6625 | /* If not cross-compiling, look for executables in the standard |
6626 | places. */ |
6627 | if (*cross_compile == '0') |
6628 | { |
6629 | if (*md_exec_prefix) |
6630 | { |
6631 | add_prefix (&exec_prefixes, md_exec_prefix, "GCC", |
6632 | PREFIX_PRIORITY_LAST, 0, 0); |
6633 | } |
6634 | } |
6635 | |
6636 | /* Process sysroot_suffix_spec. */ |
6637 | if (*sysroot_suffix_spec != 0 |
6638 | && do_spec_2 (sysroot_suffix_spec) == 0) |
6639 | { |
6640 | if (argbuf_index > 1) |
6641 | error ("spec failure: more than one arg to SYSROOT_SUFFIX_SPEC"); |
6642 | else if (argbuf_index == 1) |
6643 | target_sysroot_suffix = xstrdup (argbuf[argbuf_index -1]); |
6644 | } |
6645 | |
6646 | #ifdef HAVE_LD_SYSROOT |
6647 | /* Pass the --sysroot option to the linker, if it supports that. If |
6648 | there is a sysroot_suffix_spec, it has already been processed by |
6649 | this point, so target_system_root really is the system root we |
6650 | should be using. */ |
6651 | if (target_system_root) |
6652 | { |
6653 | obstack_grow (&obstack, "%(sysroot_spec) ", strlen ("%(sysroot_spec) ")); |
6654 | obstack_grow0 (&obstack, link_spec, strlen (link_spec)); |
6655 | set_spec ("link", XOBFINISH (&obstack, const char *)); |
6656 | } |
6657 | #endif |
6658 | |
6659 | /* Process sysroot_hdrs_suffix_spec. */ |
6660 | if (*sysroot_hdrs_suffix_spec != 0 |
6661 | && do_spec_2 (sysroot_hdrs_suffix_spec) == 0) |
6662 | { |
6663 | if (argbuf_index > 1) |
6664 | error ("spec failure: more than one arg to SYSROOT_HEADERS_SUFFIX_SPEC"); |
6665 | else if (argbuf_index == 1) |
6666 | target_sysroot_hdrs_suffix = xstrdup (argbuf[argbuf_index -1]); |
6667 | } |
6668 | |
6669 | /* APPLE LOCAL begin isysroot 5083137 */ |
6670 | #ifndef SYSROOT_PRIORITY |
6671 | #define SYSROOT_PRIORITY PREFIX_PRIORITY_LAST |
6672 | #endif |
6673 | /* APPLE LOCAL end isysroot 5083137 */ |
6674 | |
6675 | /* Look for startfiles in the standard places. */ |
6676 | if (*startfile_prefix_spec != 0 |
6677 | && do_spec_2 (startfile_prefix_spec) == 0 |
6678 | && do_spec_1 (" ", 0, NULL( ( void * ) 0 )) == 0) |
6679 | { |
6680 | int ndx; |
6681 | for (ndx = 0; ndx < argbuf_index; ndx++) |
6682 | add_sysrooted_prefix (&startfile_prefixes, argbuf[ndx], "BINUTILS", |
6683 | /* APPLE LOCAL isysroot 5083137 */ |
6684 | SYSROOT_PRIORITYPREFIX_PRIORITY_FIRST, 0, 1); |
6685 | } |
6686 | /* We should eventually get rid of all these and stick to |
6687 | startfile_prefix_spec exclusively. */ |
6688 | else if (*cross_compile == '0' || target_system_root) |
6689 | { |
6690 | if (*md_startfile_prefix) |
6691 | add_sysrooted_prefix (&startfile_prefixes, md_startfile_prefix, |
6692 | /* APPLE LOCAL isysroot 5083137 */ |
6693 | "GCC", SYSROOT_PRIORITYPREFIX_PRIORITY_FIRST, 0, 1); |
6694 | |
6695 | if (*md_startfile_prefix_1) |
6696 | add_sysrooted_prefix (&startfile_prefixes, md_startfile_prefix_1, |
6697 | /* APPLE LOCAL isysroot 5083137 */ |
6698 | "GCC", SYSROOT_PRIORITYPREFIX_PRIORITY_FIRST, 0, 1); |
6699 | |
6700 | /* If standard_startfile_prefix is relative, base it on |
6701 | standard_exec_prefix. This lets us move the installed tree |
6702 | as a unit. If GCC_EXEC_PREFIX is defined, base |
6703 | standard_startfile_prefix on that as well. |
6704 | |
6705 | If the prefix is relative, only search it for native compilers; |
6706 | otherwise we will search a directory containing host libraries. */ |
6707 | if (IS_ABSOLUTE_PATH( ( ( ( standard_startfile_prefix ) [ 0 ] ) == '/' ) ) (standard_startfile_prefix)) |
6708 | add_sysrooted_prefix (&startfile_prefixes, |
6709 | standard_startfile_prefix, "BINUTILS", |
6710 | /* APPLE LOCAL isysroot 5083137 */ |
6711 | SYSROOT_PRIORITYPREFIX_PRIORITY_FIRST, 0, 1); |
6712 | else if (*cross_compile == '0') |
6713 | { |
6714 | if (gcc_exec_prefix) |
6715 | add_prefix (&startfile_prefixes, |
6716 | concat (gcc_exec_prefix, machine_suffix, |
6717 | standard_startfile_prefix, NULL( ( void * ) 0 )), |
6718 | NULL( ( void * ) 0 ), PREFIX_PRIORITY_LAST, 0, 1); |
6719 | |
6720 | /* APPLE LOCAL begin ARM sysroot startfile_prefixes */ |
6721 | /* All absolute startfile_prefixes must be sysrooted so we |
6722 | don't pick up host headers. */ |
6723 | if (IS_ABSOLUTE_PATH( ( ( ( standard_exec_prefix ) [ 0 ] ) == '/' ) ) (standard_exec_prefix)) |
6724 | add_sysrooted_prefix (&startfile_prefixes, |
6725 | concat (standard_exec_prefix, |
6726 | machine_suffix, |
6727 | standard_startfile_prefix, NULL( ( void * ) 0 )), |
6728 | NULL( ( void * ) 0 ), PREFIX_PRIORITY_LAST, 0, 1); |
6729 | else |
6730 | add_prefix (&startfile_prefixes, |
6731 | concat (standard_exec_prefix, |
6732 | machine_suffix, |
6733 | standard_startfile_prefix, NULL( ( void * ) 0 )), |
6734 | NULL( ( void * ) 0 ), PREFIX_PRIORITY_LAST, 0, 1); |
6735 | /* APPLE LOCAL end ARM sysroot startfile_prefixes */ |
6736 | } |
6737 | |
6738 | if (*standard_startfile_prefix_1) |
6739 | add_sysrooted_prefix (&startfile_prefixes, |
6740 | standard_startfile_prefix_1, "BINUTILS", |
6741 | /* APPLE LOCAL isysroot 5083137 */ |
6742 | SYSROOT_PRIORITYPREFIX_PRIORITY_FIRST, 0, 1); |
6743 | if (*standard_startfile_prefix_2) |
6744 | add_sysrooted_prefix (&startfile_prefixes, |
6745 | standard_startfile_prefix_2, "BINUTILS", |
6746 | /* APPLE LOCAL isysroot 5083137 */ |
6747 | SYSROOT_PRIORITYPREFIX_PRIORITY_FIRST, 0, 1); |
6748 | } |
6749 | |
6750 | /* Process any user specified specs in the order given on the command |
6751 | line. */ |
6752 | for (uptr = user_specs_head; uptr; uptr = uptr->next) |
6753 | { |
6754 | char *filename = find_a_file (&startfile_prefixes, uptr->filename, |
6755 | R_OK( 1 << 2 ), true1); |
6756 | read_specs (filename ? filename : uptr->filename, FALSE0); |
6757 | } |
6758 | |
6759 | /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */ |
6760 | if (gcc_exec_prefix) |
6761 | gcc_exec_prefix = concat (gcc_exec_prefix, spec_machine, dir_separator_str, |
6762 | spec_version, dir_separator_str, NULL( ( void * ) 0 )); |
6763 | |
6764 | /* Now we have the specs. |
6765 | Set the `valid' bits for switches that match anything in any spec. */ |
6766 | |
6767 | validate_all_switches (); |
6768 | |
6769 | /* Now that we have the switches and the specs, set |
6770 | the subdirectory based on the options. */ |
6771 | set_multilib_dir (); |
6772 | |
6773 | /* Warn about any switches that no pass was interested in. */ |
6774 | |
6775 | for (i = 0; (int) i < n_switches; i++) |
6776 | if (! switches[i].validated) |
6777 | error ("unrecognized option '-%s'", switches[i].part1); |
6778 | |
6779 | /* Obey some of the options. */ |
6780 | |
6781 | if (print_search_dirs) |
6782 | { |
6783 | printf (_libintl_gettext ( "install: %s%s\n" )("install: %s%s\n"), standard_exec_prefix, machine_suffix); |
6784 | printf (_libintl_gettext ( "programs: %s\n" )("programs: %s\n"), |
6785 | build_search_list (&exec_prefixes, "", false0, false0)); |
6786 | printf (_libintl_gettext ( "libraries: %s\n" )("libraries: %s\n"), |
6787 | build_search_list (&startfile_prefixes, "", false0, true1)); |
6788 | return (0); |
6789 | } |
6790 | |
6791 | if (print_file_name) |
6792 | { |
6793 | printf ("%s\n", find_file (print_file_name)); |
6794 | return (0); |
6795 | } |
6796 | |
6797 | if (print_prog_name) |
6798 | { |
6799 | char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK( 1 << 0 ), 0); |
6800 | printf ("%s\n", (newname ? newname : print_prog_name)); |
6801 | return (0); |
6802 | } |
6803 | |
6804 | if (print_multi_lib) |
6805 | { |
6806 | print_multilib_info (); |
6807 | return (0); |
6808 | } |
6809 | |
6810 | if (print_multi_directory) |
6811 | { |
6812 | if (multilib_dir == NULL( ( void * ) 0 )) |
6813 | printf (".\n"); |
6814 | else |
6815 | printf ("%s\n", multilib_dir); |
6816 | return (0); |
6817 | } |
6818 | |
6819 | if (print_multi_os_directory) |
6820 | { |
6821 | if (multilib_os_dir == NULL( ( void * ) 0 )) |
6822 | printf (".\n"); |
6823 | else |
6824 | printf ("%s\n", multilib_os_dir); |
6825 | return (0); |
6826 | } |
6827 | |
6828 | if (target_help_flag) |
6829 | { |
6830 | /* Print if any target specific options. */ |
6831 | |
6832 | /* We do not exit here. Instead we have created a fake input file |
6833 | called 'target-dummy' which needs to be compiled, and we pass this |
6834 | on to the various sub-processes, along with the --target-help |
6835 | switch. */ |
6836 | } |
6837 | |
6838 | if (print_help_list) |
6839 | { |
6840 | display_help (); |
6841 | |
6842 | if (! verbose_flag) |
6843 | { |
6844 | printf (_libintl_gettext ( "\nFor bug reporting instructions, please see:\n" )("\nFor bug reporting instructions, please see:\n")); |
6845 | printf ("%s.\n", bug_report_url); |
6846 | |
6847 | return (0); |
6848 | } |
6849 | |
6850 | /* We do not exit here. Instead we have created a fake input file |
6851 | called 'help-dummy' which needs to be compiled, and we pass this |
6852 | on the various sub-processes, along with the --help switch. */ |
6853 | } |
6854 | |
6855 | if (verbose_flag) |
6856 | { |
6857 | int n; |
6858 | const char *thrmod; |
6859 | |
6860 | notice ("Target: %s\n", spec_machine); |
6861 | notice ("Configured with: %s\n", configuration_arguments); |
6862 | |
6863 | #ifdef THREAD_MODEL_SPEC |
6864 | /* We could have defined THREAD_MODEL_SPEC to "%*" by default, |
6865 | but there's no point in doing all this processing just to get |
6866 | thread_model back. */ |
6867 | obstack_init (&obstack); |
6868 | do_spec_1 (THREAD_MODEL_SPEC, 0, thread_model); |
6869 | obstack_1grow (&obstack, '\0'); |
6870 | thrmod = XOBFINISH (&obstack, const char *); |
6871 | #else |
6872 | thrmod = thread_model; |
6873 | #endif |
6874 | |
6875 | notice ("Thread model: %s\n", thrmod); |
6876 | |
6877 | /* compiler_version is truncated at the first space when initialized |
6878 | from version string, so truncate version_string at the first space |
6879 | before comparing. */ |
6880 | for (n = 0; version_string[n]; n++) |
6881 | if (version_string[n] == ' ') |
6882 | break; |
6883 | |
6884 | if (! strncmp (version_string, compiler_version, n) |
6885 | && compiler_version[n] == 0) |
6886 | notice ("gcc version %s\n", version_string); |
6887 | else |
6888 | notice ("gcc driver version %s executing gcc version %s\n", |
6889 | version_string, compiler_version); |
6890 | |
6891 | if (n_infiles == 0) |
6892 | return (0); |
6893 | } |
6894 | |
6895 | if (n_infiles == added_libraries) |
6896 | fatal ("no input files"); |
6897 | |
6898 | /* Make a place to record the compiler output file names |
6899 | that correspond to the input files. */ |
6900 | |
6901 | i = n_infiles; |
6902 | i += lang_specific_extra_outfiles; |
6903 | outfiles = XCNEWVEC( ( const char * * ) xcalloc ( ( i ) , sizeof ( const char * ) ) ) (const char *, i); |
6904 | |
6905 | /* Record which files were specified explicitly as link input. */ |
6906 | |
6907 | explicit_link_files = XCNEWVEC( ( char * ) xcalloc ( ( n_infiles ) , sizeof ( char ) ) ) (char, n_infiles); |
6908 | |
6909 | if (combine_flag) |
6910 | combine_inputs = true1; |
6911 | else |
6912 | combine_inputs = false0; |
6913 | |
6914 | for (i = 0; (int) i < n_infiles; i++) |
6915 | { |
6916 | const char *name = infiles[i].name; |
6917 | struct compiler *compiler = lookup_compiler (name, |
6918 | strlen (name), |
6919 | infiles[i].language); |
6920 | |
6921 | if (compiler && !(compiler->combinable)) |
6922 | combine_inputs = false0; |
6923 | |
6924 | if (lang_n_infiles > 0 && compiler != input_file_compiler |
6925 | && infiles[i].language && infiles[i].language[0] != '*') |
6926 | infiles[i].incompiler = compiler; |
6927 | else if (compiler) |
6928 | { |
6929 | lang_n_infiles++; |
6930 | input_file_compiler = compiler; |
6931 | infiles[i].incompiler = compiler; |
6932 | } |
6933 | else |
6934 | { |
6935 | /* Since there is no compiler for this input file, assume it is a |
6936 | linker file. */ |
6937 | explicit_link_files[i] = 1; |
6938 | infiles[i].incompiler = NULL( ( void * ) 0 ); |
6939 | } |
6940 | infiles[i].compiled = false0; |
6941 | infiles[i].preprocessed = false0; |
6942 | } |
6943 | |
6944 | if (!combine_inputs && have_c && have_o && lang_n_infiles > 1) |
6945 | fatal ("cannot specify -o with -c or -S with multiple files"); |
6946 | |
6947 | /* APPLE LOCAL begin IMA */ |
6948 | if (combine_flag |
6949 | && (save_temps_flag || traditional_cpp_flag || capital_e_flag)) |
6950 | { |
6951 | bool_Bool save_combine_inputs = combine_inputs; |
6952 | /* Must do a separate pre-processing pass for C & Objective-C files, to |
6953 | obtain individual .i files. */ |
6954 | |
6955 | combine_inputs = false0; |
6956 | for (i = 0; (int) i < n_infiles; i++) |
6957 | { |
6958 | int this_file_error = 0; |
6959 | |
6960 | input_file_number = i; |
6961 | set_input (infiles[i].name); |
6962 | if (infiles[i].incompiler |
6963 | && (infiles[i].incompiler)->needs_preprocessing) |
6964 | input_file_compiler = infiles[i].incompiler; |
6965 | else |
6966 | continue; |
6967 | |
6968 | if (input_file_compiler) |
6969 | { |
6970 | if (input_file_compiler->spec[0] == '#') |
6971 | { |
6972 | error ("%s: %s compiler not installed on this system", |
6973 | input_filename, &input_file_compiler->spec[1]); |
6974 | this_file_error = 1; |
6975 | } |
6976 | else if (capital_e_flag) |
6977 | { |
6978 | value = do_spec (input_file_compiler->spec); |
6979 | infiles[i].preprocessed = true1; |
6980 | if (!have_o_argbuf_index) |
6981 | fatal ("spec '%s' is invalid", input_file_compiler->spec); |
6982 | infiles[i].name = argbuf[have_o_argbuf_index]; |
6983 | infiles[i].incompiler |
6984 | = lookup_compiler (infiles[i].name, |
6985 | strlen (infiles[i].name), |
6986 | infiles[i].language); |
6987 | |
6988 | if (value < 0) |
6989 | this_file_error = 1; |
6990 | } |
6991 | else if (save_temps_flag) |
6992 | { |
6993 | value = do_spec (input_file_compiler->spec); |
6994 | infiles[i].preprocessed = TRUE1; |
6995 | if (have_o_argbuf_index) |
6996 | infiles[i].name = argbuf[have_o_argbuf_index]; |
6997 | else |
6998 | abortfancy_abort ( "../../src/gcc/gcc.c" , 6998 , __FUNCTION__ ) (); |
6999 | |
7000 | infiles[i].incompiler = lookup_compiler (infiles[i].name, |
7001 | strlen (infiles[i].name), |
7002 | infiles[i].language); |
7003 | |
7004 | if (value < 0) |
7005 | this_file_error = 1; |
7006 | } |
7007 | else if (traditional_cpp_flag) |
7008 | { |
7009 | /* Temp file name is stored in infiles->temp_filename. |
7010 | Use it as input file name. */ |
7011 | infiles[i].name = infiles[i].temp_filename; |
7012 | infiles[i].incompiler = lookup_compiler (infiles[i].name, |
7013 | strlen (infiles[i].name), |
7014 | infiles[i].language); |
7015 | } |
7016 | } |
7017 | |
7018 | if (this_file_error) |
7019 | { |
7020 | delete_failure_queue (); |
7021 | error_count++; |
7022 | break; |
7023 | } |
7024 | clear_failure_queue (); |
7025 | } |
7026 | combine_inputs = save_combine_inputs; |
7027 | } |
7028 | /* APPLE LOCAL end IMA */ |
7029 | |
7030 | for (i = 0; (int) i < n_infiles; i++) |
7031 | { |
7032 | int this_file_error = 0; |
7033 | |
7034 | /* Tell do_spec what to substitute for %i. */ |
7035 | |
7036 | input_file_number = i; |
7037 | set_input (infiles[i].name); |
7038 | |
7039 | if (infiles[i].compiled) |
7040 | continue; |
7041 | |
7042 | /* Use the same thing in %o, unless cp->spec says otherwise. */ |
7043 | |
7044 | outfiles[i] = input_filename; |
7045 | |
7046 | /* Figure out which compiler from the file's suffix. */ |
7047 | |
7048 | if (! combine_inputs) |
7049 | input_file_compiler |
7050 | = lookup_compiler (infiles[i].name, input_filename_length, |
7051 | infiles[i].language); |
7052 | else |
7053 | input_file_compiler = infiles[i].incompiler; |
7054 | |
7055 | if (input_file_compiler) |
7056 | { |
7057 | /* Ok, we found an applicable compiler. Run its spec. */ |
7058 | |
7059 | if (input_file_compiler->spec[0] == '#') |
7060 | { |
7061 | error ("%s: %s compiler not installed on this system", |
7062 | input_filename, &input_file_compiler->spec[1]); |
7063 | this_file_error = 1; |
7064 | } |
7065 | /* APPLE LOCAL begin IMA */ |
7066 | /* Check if -E is not used on command line OR input file is |
7067 | assembly file. If -E is used then do not invoke compiler |
7068 | again, because preprocessed output is already generated |
7069 | above. However |
7070 | 1) If -E is used with assembly input file then continue. |
7071 | 2) If inputs are not combined then continue. */ |
7072 | else if (!capital_e_flag || !combine_inputs) |
7073 | /* APPLE LOCAL end IMA */ |
7074 | { |
7075 | value = do_spec (input_file_compiler->spec); |
7076 | infiles[i].compiled = true1; |
7077 | if (value < 0) |
7078 | this_file_error = 1; |
7079 | } |
7080 | } |
7081 | |
7082 | /* If this file's name does not contain a recognized suffix, |
7083 | record it as explicit linker input. */ |
7084 | |
7085 | else |
7086 | explicit_link_files[i] = 1; |
7087 | |
7088 | /* Clear the delete-on-failure queue, deleting the files in it |
7089 | if this compilation failed. */ |
7090 | |
7091 | if (this_file_error) |
7092 | { |
7093 | delete_failure_queue (); |
7094 | error_count++; |
7095 | } |
7096 | /* If this compilation succeeded, don't delete those files later. */ |
7097 | clear_failure_queue (); |
7098 | } |
7099 | |
7100 | /* Reset the input file name to the first compile/object file name, for use |
7101 | with %b in LINK_SPEC. We use the first input file that we can find |
7102 | a compiler to compile it instead of using infiles.language since for |
7103 | languages other than C we use aliases that we then lookup later. */ |
7104 | if (n_infiles > 0) |
7105 | { |
7106 | int i; |
7107 | |
7108 | for (i = 0; i < n_infiles ; i++) |
7109 | /* APPLE LOCAL suffix 5226662 */ |
7110 | if (infiles[i].language == 0 || infiles[i].language[0] != '*') |
7111 | { |
7112 | set_input (infiles[i].name); |
7113 | break; |
7114 | } |
7115 | } |
7116 | |
7117 | if (error_count == 0) |
7118 | { |
7119 | /* Make sure INPUT_FILE_NUMBER points to first available open |
7120 | slot. */ |
7121 | input_file_number = n_infiles; |
7122 | if (lang_specific_pre_link ()) |
7123 | error_count++; |
7124 | } |
7125 | |
7126 | /* Determine if there are any linker input files. */ |
7127 | num_linker_inputs = 0; |
7128 | for (i = 0; (int) i < n_infiles; i++) |
7129 | if (explicit_link_files[i] || outfiles[i] != NULL( ( void * ) 0 )) |
7130 | num_linker_inputs++; |
7131 | |
7132 | /* Run ld to link all the compiler output files. */ |
7133 | |
7134 | if (num_linker_inputs > 0 && error_count == 0) |
7135 | { |
7136 | int tmp = execution_count; |
7137 | |
7138 | /* We'll use ld if we can't find collect2. */ |
7139 | if (! strcmp (linker_name_spec, "collect2")) |
7140 | { |
7141 | char *s = find_a_file (&exec_prefixes, "collect2", X_OK( 1 << 0 ), false0); |
7142 | if (s == NULL( ( void * ) 0 )) |
7143 | linker_name_spec = "ld"; |
7144 | } |
7145 | /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables |
7146 | for collect. */ |
7147 | putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH", false0); |
7148 | putenv_from_prefixes (&startfile_prefixes, LIBRARY_PATH_ENV"LIBRARY_PATH", true1); |
7149 | |
7150 | value = do_spec (link_command_spec); |
7151 | if (value < 0) |
7152 | error_count = 1; |
7153 | linker_was_run = (tmp != execution_count); |
7154 | } |
7155 | |
7156 | /* If options said don't run linker, |
7157 | complain about input files to be given to the linker. */ |
7158 | |
7159 | if (! linker_was_run && error_count == 0) |
7160 | for (i = 0; (int) i < n_infiles; i++) |
7161 | if (explicit_link_files[i]) |
7162 | error ("%s: linker input file unused because linking not done", |
7163 | outfiles[i]); |
7164 | |
7165 | /* Delete some or all of the temporary files we made. */ |
7166 | |
7167 | if (error_count) |
7168 | delete_failure_queue (); |
7169 | delete_temp_files (); |
7170 | |
7171 | if (print_help_list) |
7172 | { |
7173 | printf (("\nFor bug reporting instructions, please see:\n")); |
7174 | printf ("%s\n", bug_report_url); |
7175 | } |
7176 | |
7177 | return (signal_count != 0 ? 2 |
7178 | : error_count > 0 ? (pass_exit_codes ? greatest_status : 1) |
7179 | : 0); |
7180 | } |
7181 | |
7182 | /* Find the proper compilation spec for the file name NAME, |
7183 | whose length is LENGTH. LANGUAGE is the specified language, |
7184 | or 0 if this file is to be passed to the linker. */ |
7185 | |
7186 | static struct compiler * |
7187 | lookup_compiler (const char *name, size_t length, const char *language) |
7188 | { |
7189 | struct compiler *cp; |
7190 | |
7191 | /* If this was specified by the user to be a linker input, indicate that. */ |
7192 | if (language != 0 && language[0] == '*') |
7193 | return 0; |
7194 | |
7195 | /* Otherwise, look for the language, if one is spec'd. */ |
7196 | if (language != 0) |
7197 | { |
7198 | for (cp = compilers + n_compilers - 1; cp >= compilers; cp--) |
7199 | if (cp->suffix[0] == '@' && !strcmp (cp->suffix + 1, language)) |
7200 | return cp; |
7201 | |
7202 | error ("language %s not recognized", language); |
7203 | return 0; |
7204 | } |
7205 | |
7206 | /* Look for a suffix. */ |
7207 | for (cp = compilers + n_compilers - 1; cp >= compilers; cp--) |
7208 | { |
7209 | if (/* The suffix `-' matches only the file name `-'. */ |
7210 | (!strcmp (cp->suffix, "-") && !strcmp (name, "-")) |
7211 | || (strlen (cp->suffix) < length |
7212 | /* See if the suffix matches the end of NAME. */ |
7213 | && !strcmp (cp->suffix, |
7214 | name + length - strlen (cp->suffix)) |
7215 | )) |
7216 | break; |
7217 | } |
7218 | |
7219 | #if defined (OS2) ||defined (HAVE_DOS_BASED_FILE_SYSTEM) |
7220 | /* Look again, but case-insensitively this time. */ |
7221 | if (cp < compilers) |
7222 | for (cp = compilers + n_compilers - 1; cp >= compilers; cp--) |
7223 | { |
7224 | if (/* The suffix `-' matches only the file name `-'. */ |
7225 | (!strcmp (cp->suffix, "-") && !strcmp (name, "-")) |
7226 | || (strlen (cp->suffix) < length |
7227 | /* See if the suffix matches the end of NAME. */ |
7228 | && ((!strcmp (cp->suffix, |
7229 | name + length - strlen (cp->suffix)) |
7230 | || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")) |
7231 | && !strcasecmp (cp->suffix, |
7232 | name + length - strlen (cp->suffix))) |
7233 | )) |
7234 | break; |
7235 | } |
7236 | #endif |
7237 | |
7238 | if (cp >= compilers) |
7239 | { |
7240 | /* APPLE LOCAL begin -ObjC 2001-08-03 --sts */ |
7241 | /* We found a language, but because we set a default language, |
7242 | override with the default. */ |
7243 | if (default_language) |
7244 | { |
7245 | struct compiler *ncomp = lookup_compiler (NULL( ( void * ) 0 ), 0, default_language); |
7246 | #if 0 /* unhelpful without docs to educate users, skip for now -sts 2002-01-01 */ |
7247 | if (cp == ncomp |
7248 | || (cp->spec[0] == '@' |
7249 | && ncomp |
7250 | && strcmp (cp->spec, ncomp->suffix) == 0)) |
7251 | { |
7252 | if (strcmp (default_language, "objective-c") == 0) |
7253 | error ("Warning: -ObjC/-fobjc option is redundant"); |
7254 | if (strcmp (default_language, "objective-c++") == 0) |
7255 | error ("Warning: -ObjC++ option is redundant"); |
7256 | } |
7257 | #endif |
7258 | return ncomp; |
7259 | } |
7260 | /* APPLE LOCAL end -ObjC 2001-08-03 --sts */ |
7261 | if (cp->spec[0] != '@') |
7262 | /* A non-alias entry: return it. */ |
7263 | return cp; |
7264 | |
7265 | /* An alias entry maps a suffix to a language. |
7266 | Search for the language; pass 0 for NAME and LENGTH |
7267 | to avoid infinite recursion if language not found. */ |
7268 | return lookup_compiler (NULL( ( void * ) 0 ), 0, cp->spec + 1); |
7269 | } |
7270 | return 0; |
7271 | } |
7272 | |
7273 | static char * |
7274 | save_string (const char *s, int len) |
7275 | { |
7276 | char *result = XNEWVEC( ( char * ) xmalloc ( sizeof ( char ) * ( len + 1 ) ) ) (char, len + 1); |
7277 | |
7278 | memcpy (result, s, len); |
7279 | result[len] = 0; |
7280 | return result; |
7281 | } |
7282 | |
7283 | void |
7284 | pfatal_with_name (const char *name) |
7285 | { |
7286 | perror_with_name (name); |
7287 | delete_temp_files (); |
7288 | exit (1); |
7289 | } |
7290 | |
7291 | static void |
7292 | perror_with_name (const char *name) |
7293 | { |
7294 | error ("%s: %s", name, xstrerror (errno( * __error ( ) ))); |
7295 | } |
7296 | |
7297 | /* Output an error message and exit. */ |
7298 | |
7299 | void |
7300 | fancy_abort (const char *file, int line, const char *func) |
7301 | { |
7302 | fatal_ice ("internal gcc abort in %s, at %s:%d", func, file, line); |
7303 | } |
7304 | |
7305 | /* Output an error message and exit. */ |
7306 | |
7307 | void |
7308 | fatal_ice (const char *cmsgid, ...) |
7309 | { |
7310 | va_list ap; |
7311 | |
7312 | va_start__builtin_va_start ( ap , cmsgid ) (ap, cmsgid); |
7313 | |
7314 | fprintf (stderr__stderrp, "%s: ", programname); |
7315 | vfprintf (stderr__stderrp, _libintl_gettext ( cmsgid )(cmsgid), ap); |
7316 | va_end__builtin_va_end ( ap ) (ap); |
7317 | fprintf (stderr__stderrp, "\n"); |
7318 | delete_temp_files (); |
7319 | exit (pass_exit_codes ? ICE_EXIT_CODE4 : 1); |
7320 | } |
7321 | |
7322 | void |
7323 | fatal (const char *cmsgid, ...) |
7324 | { |
7325 | va_list ap; |
7326 | |
7327 | va_start__builtin_va_start ( ap , cmsgid ) (ap, cmsgid); |
7328 | |
7329 | fprintf (stderr__stderrp, "%s: ", programname); |
7330 | vfprintf (stderr__stderrp, _libintl_gettext ( cmsgid )(cmsgid), ap); |
7331 | va_end__builtin_va_end ( ap ) (ap); |
7332 | fprintf (stderr__stderrp, "\n"); |
7333 | delete_temp_files (); |
7334 | exit (1); |
7335 | } |
7336 | |
7337 | /* The argument is actually c-format, not gcc-internal-format, |
7338 | but because functions with identical names are used through |
7339 | the rest of the compiler with gcc-internal-format, we just |
7340 | need to hope all users of these functions use the common |
7341 | subset between c-format and gcc-internal-format. */ |
7342 | |
7343 | void |
7344 | error (const char *gmsgid, ...) |
7345 | { |
7346 | va_list ap; |
7347 | |
7348 | va_start__builtin_va_start ( ap , gmsgid ) (ap, gmsgid); |
7349 | fprintf (stderr__stderrp, "%s: ", programname); |
7350 | vfprintf (stderr__stderrp, _libintl_gettext ( gmsgid )(gmsgid), ap); |
7351 | va_end__builtin_va_end ( ap ) (ap); |
7352 | |
7353 | fprintf (stderr__stderrp, "\n"); |
7354 | } |
7355 | |
7356 | static void |
7357 | notice (const char *cmsgid, ...) |
7358 | { |
7359 | va_list ap; |
7360 | |
7361 | va_start__builtin_va_start ( ap , cmsgid ) (ap, cmsgid); |
7362 | vfprintf (stderr__stderrp, _libintl_gettext ( cmsgid )(cmsgid), ap); |
7363 | va_end__builtin_va_end ( ap ) (ap); |
7364 | } |
7365 | |
7366 | static inline__inline__ void |
7367 | validate_switches_from_spec (const char *spec) |
7368 | { |
7369 | const char *p = spec; |
7370 | char c; |
7371 | while ((c = *p++)) |
7372 | if (c == '%' && (*p == '{' || *p == '<' || (*p == 'W' && *++p == '{'))) |
7373 | /* We have a switch spec. */ |
7374 | p = validate_switches (p + 1); |
7375 | } |
7376 | |
7377 | static void |
7378 | validate_all_switches (void) |
7379 | { |
7380 | struct compiler *comp; |
7381 | struct spec_list *spec; |
7382 | |
7383 | for (comp = compilers; comp->spec; comp++) |
7384 | validate_switches_from_spec (comp->spec); |
7385 | |
7386 | /* Look through the linked list of specs read from the specs file. */ |
7387 | for (spec = specs; spec; spec = spec->next) |
7388 | validate_switches_from_spec (*spec->ptr_spec); |
7389 | |
7390 | validate_switches_from_spec (link_command_spec); |
7391 | } |
7392 | |
7393 | /* Look at the switch-name that comes after START |
7394 | and mark as valid all supplied switches that match it. */ |
7395 | |
7396 | static const char * |
7397 | validate_switches (const char *start) |
7398 | { |
7399 | const char *p = start; |
7400 | const char *atom; |
7401 | size_t len; |
7402 | int i; |
7403 | bool_Bool suffix = false0; |
7404 | bool_Bool starred = false0; |
7405 | |
7406 | #define SKIP_WHITE() do { while (*p == ' ' || *p == '\t') p++; } while (0) |
7407 | |
7408 | next_member: |
7409 | SKIP_WHITEdo { while ( * p == ' ' || * p == '\t' ) p ++ ; } while ( 0 ) (); |
7410 | |
7411 | if (*p == '!') |
7412 | p++; |
7413 | |
7414 | SKIP_WHITEdo { while ( * p == ' ' || * p == '\t' ) p ++ ; } while ( 0 ) (); |
7415 | /* APPLE LOCAL begin mainline 2007-03-13 5040758 */ \ |
7416 | if (*p == '.' || *p == ',') |
7417 | /* APPLE LOCAL end mainline 2007-03-13 5040758 */ \ |
7418 | suffix = true1, p++; |
7419 | |
7420 | atom = p; |
7421 | while (ISIDNUM( _sch_istable [ ( * p ) & 0xff ] & ( unsigned short ) ( _sch_isidnum ) ) (*p) || *p == '-' || *p == '+' || *p == '=' |
7422 | || *p == ',' || *p == '.' || *p == '@') |
7423 | p++; |
7424 | len = p - atom; |
7425 | |
7426 | if (*p == '*') |
7427 | starred = true1, p++; |
7428 | |
7429 | SKIP_WHITEdo { while ( * p == ' ' || * p == '\t' ) p ++ ; } while ( 0 ) (); |
7430 | |
7431 | if (!suffix) |
7432 | { |
7433 | /* Mark all matching switches as valid. */ |
7434 | for (i = 0; i < n_switches; i++) |
7435 | if (!strncmp (switches[i].part1, atom, len) |
7436 | && (starred || switches[i].part1[len] == 0)) |
7437 | switches[i].validated = 1; |
7438 | } |
7439 | |
7440 | if (*p) p++; |
7441 | if (*p && (p[-1] == '|' || p[-1] == '&')) |
7442 | goto next_member; |
7443 | |
7444 | if (*p && p[-1] == ':') |
7445 | { |
7446 | while (*p && *p != ';' && *p != '}') |
7447 | { |
7448 | if (*p == '%') |
7449 | { |
7450 | p++; |
7451 | if (*p == '{' || *p == '<') |
7452 | p = validate_switches (p+1); |
7453 | else if (p[0] == 'W' && p[1] == '{') |
7454 | p = validate_switches (p+2); |
7455 | } |
7456 | else |
7457 | p++; |
7458 | } |
7459 | |
7460 | if (*p) p++; |
7461 | if (*p && p[-1] == ';') |
7462 | goto next_member; |
7463 | } |
7464 | |
7465 | return p; |
7466 | #undef SKIP_WHITE |
7467 | } |
7468 | |
7469 | struct mdswitchstr |
7470 | { |
7471 | const char *str; |
7472 | int len; |
7473 | }; |
7474 | |
7475 | static struct mdswitchstr *mdswitches; |
7476 | static int n_mdswitches; |
7477 | |
7478 | /* Check whether a particular argument was used. The first time we |
7479 | canonicalize the switches to keep only the ones we care about. */ |
7480 | |
7481 | static int |
7482 | used_arg (const char *p, int len) |
7483 | { |
7484 | struct mswitchstr |
7485 | { |
7486 | const char *str; |
7487 | const char *replace; |
7488 | int len; |
7489 | int rep_len; |
7490 | }; |
7491 | |
7492 | static struct mswitchstr *mswitches; |
7493 | static int n_mswitches; |
7494 | int i, j; |
7495 | |
7496 | if (!mswitches) |
7497 | { |
7498 | struct mswitchstr *matches; |
7499 | const char *q; |
7500 | int cnt = 0; |
7501 | |
7502 | /* Break multilib_matches into the component strings of string |
7503 | and replacement string. */ |
7504 | for (q = multilib_matches; *q != '\0'; q++) |
7505 | if (*q == ';') |
7506 | cnt++; |
7507 | |
7508 | matches = alloca__builtin_alloca ( ( sizeof ( struct mswitchstr ) ) * cnt ) ((sizeof (struct mswitchstr)) * cnt); |
7509 | i = 0; |
7510 | q = multilib_matches; |
7511 | while (*q != '\0') |
7512 | { |
7513 | matches[i].str = q; |
7514 | while (*q != ' ') |
7515 | { |
7516 | if (*q == '\0') |
7517 | { |
7518 | invalid_matches: |
7519 | fatal ("multilib spec '%s' is invalid", multilib_matches); |
7520 | } |
7521 | q++; |
7522 | } |
7523 | matches[i].len = q - matches[i].str; |
7524 | |
7525 | matches[i].replace = ++q; |
7526 | while (*q != ';' && *q != '\0') |
7527 | { |
7528 | if (*q == ' ') |
7529 | goto invalid_matches; |
7530 | q++; |
7531 | } |
7532 | matches[i].rep_len = q - matches[i].replace; |
7533 | i++; |
7534 | if (*q == ';') |
7535 | q++; |
7536 | } |
7537 | |
7538 | /* Now build a list of the replacement string for switches that we care |
7539 | about. Make sure we allocate at least one entry. This prevents |
7540 | xmalloc from calling fatal, and prevents us from re-executing this |
7541 | block of code. */ |
7542 | mswitches |
7543 | = XNEWVEC( ( struct mswitchstr * ) xmalloc ( sizeof ( struct mswitchstr ) * ( n_mdswitches + ( n_switches ? n_switches : 1 ) ) ) ) (struct mswitchstr, n_mdswitches + (n_switches ? n_switches : 1)); |
7544 | for (i = 0; i < n_switches; i++) |
7545 | if (switches[i].live_cond != SWITCH_IGNORE- 2) |
7546 | { |
7547 | int xlen = strlen (switches[i].part1); |
7548 | for (j = 0; j < cnt; j++) |
7549 | if (xlen == matches[j].len |
7550 | && ! strncmp (switches[i].part1, matches[j].str, xlen)) |
7551 | { |
7552 | mswitches[n_mswitches].str = matches[j].replace; |
7553 | mswitches[n_mswitches].len = matches[j].rep_len; |
7554 | mswitches[n_mswitches].replace = (char *) 0; |
7555 | mswitches[n_mswitches].rep_len = 0; |
7556 | n_mswitches++; |
7557 | break; |
7558 | } |
7559 | } |
7560 | |
7561 | /* Add MULTILIB_DEFAULTS switches too, as long as they were not present |
7562 | on the command line nor any options mutually incompatible with |
7563 | them. */ |
7564 | for (i = 0; i < n_mdswitches; i++) |
7565 | { |
7566 | const char *r; |
7567 | |
7568 | for (q = multilib_options; *q != '\0'; q++) |
7569 | { |
7570 | while (*q == ' ') |
7571 | q++; |
7572 | |
7573 | r = q; |
7574 | while (strncmp (q, mdswitches[i].str, mdswitches[i].len) != 0 |
7575 | || strchr (" /", q[mdswitches[i].len]) == NULL( ( void * ) 0 )) |
7576 | { |
7577 | while (*q != ' ' && *q != '/' && *q != '\0') |
7578 | q++; |
7579 | if (*q != '/') |
7580 | break; |
7581 | q++; |
7582 | } |
7583 | |
7584 | if (*q != ' ' && *q != '\0') |
7585 | { |
7586 | while (*r != ' ' && *r != '\0') |
7587 | { |
7588 | q = r; |
7589 | while (*q != ' ' && *q != '/' && *q != '\0') |
7590 | q++; |
7591 | |
7592 | if (used_arg (r, q - r)) |
7593 | break; |
7594 | |
7595 | if (*q != '/') |
7596 | { |
7597 | mswitches[n_mswitches].str = mdswitches[i].str; |
7598 | mswitches[n_mswitches].len = mdswitches[i].len; |
7599 | mswitches[n_mswitches].replace = (char *) 0; |
7600 | mswitches[n_mswitches].rep_len = 0; |
7601 | n_mswitches++; |
7602 | break; |
7603 | } |
7604 | |
7605 | r = q + 1; |
7606 | } |
7607 | break; |
7608 | } |
7609 | } |
7610 | } |
7611 | } |
7612 | |
7613 | for (i = 0; i < n_mswitches; i++) |
7614 | if (len == mswitches[i].len && ! strncmp (p, mswitches[i].str, len)) |
7615 | return 1; |
7616 | |
7617 | return 0; |
7618 | } |
7619 | |
7620 | static int |
7621 | default_arg (const char *p, int len) |
7622 | { |
7623 | int i; |
7624 | |
7625 | for (i = 0; i < n_mdswitches; i++) |
7626 | if (len == mdswitches[i].len && ! strncmp (p, mdswitches[i].str, len)) |
7627 | return 1; |
7628 | |
7629 | return 0; |
7630 | } |
7631 | |
7632 | /* Work out the subdirectory to use based on the options. The format of |
7633 | multilib_select is a list of elements. Each element is a subdirectory |
7634 | name followed by a list of options followed by a semicolon. The format |
7635 | of multilib_exclusions is the same, but without the preceding |
7636 | directory. First gcc will check the exclusions, if none of the options |
7637 | beginning with an exclamation point are present, and all of the other |
7638 | options are present, then we will ignore this completely. Passing |
7639 | that, gcc will consider each multilib_select in turn using the same |
7640 | rules for matching the options. If a match is found, that subdirectory |
7641 | will be used. */ |
7642 | |
7643 | static void |
7644 | set_multilib_dir (void) |
7645 | { |
7646 | const char *p; |
7647 | unsigned int this_path_len; |
7648 | const char *this_path, *this_arg; |
7649 | const char *start, *end; |
7650 | int not_arg; |
7651 | int ok, ndfltok, first; |
7652 | |
7653 | n_mdswitches = 0; |
7654 | start = multilib_defaults; |
7655 | while (*start == ' ' || *start == '\t') |
7656 | start++; |
7657 | while (*start != '\0') |
7658 | { |
7659 | n_mdswitches++; |
7660 | while (*start != ' ' && *start != '\t' && *start != '\0') |
7661 | start++; |
7662 | while (*start == ' ' || *start == '\t') |
7663 | start++; |
7664 | } |
7665 | |
7666 | if (n_mdswitches) |
7667 | { |
7668 | int i = 0; |
7669 | |
7670 | mdswitches = XNEWVEC( ( struct mdswitchstr * ) xmalloc ( sizeof ( struct mdswitchstr ) * ( n_mdswitches ) ) ) (struct mdswitchstr, n_mdswitches); |
7671 | for (start = multilib_defaults; *start != '\0'; start = end + 1) |
7672 | { |
7673 | while (*start == ' ' || *start == '\t') |
7674 | start++; |
7675 | |
7676 | if (*start == '\0') |
7677 | break; |
7678 | |
7679 | for (end = start + 1; |
7680 | *end != ' ' && *end != '\t' && *end != '\0'; end++) |
7681 | ; |
7682 | |
7683 | obstack_grow__extension__ ( { struct obstack * __o = ( & multilib_obstack ) ; int __len = ( end - start ) ; if ( __o -> next_free + __len > __o -> chunk_limit ) _obstack_newchunk ( __o , __len ) ; memcpy ( ( __o -> next_free ) , ( ( start ) ) , ( __len ) ) ; __o -> next_free += __len ; ( void ) 0 ; } ) (&multilib_obstack, start, end - start); |
7684 | obstack_1grow__extension__ ( { struct obstack * __o = ( & multilib_obstack ) ; if ( __o -> next_free + 1 > __o -> chunk_limit ) _obstack_newchunk ( __o , 1 ) ; ( * ( ( __o ) -> next_free ) ++ = ( 0 ) ) ; ( void ) 0 ; } ) (&multilib_obstack, 0); |
7685 | mdswitches[i].str = XOBFINISH( ( const char * ) __extension__ ( { struct obstack * __o1 = ( ( & multilib_obstack ) ) ; void * value ; value = ( void * ) __o1 -> object_base ; if ( __o1 -> next_free == value ) __o1 -> maybe_empty_object = 1 ; __o1 -> next_free = ( ( ( ( ( __o1 -> next_free ) - ( char * ) 0 ) + __o1 -> alignment_mask ) & ~ ( __o1 -> alignment_mask ) ) + ( char * ) 0 ) ; if ( __o1 -> next_free - ( char * ) __o1 -> chunk > __o1 -> chunk_limit - ( char * ) __o1 -> chunk ) __o1 -> next_free = __o1 -> chunk_limit ; __o1 -> object_base = __o1 -> next_free ; value ; } ) ) (&multilib_obstack, const char *); |
7686 | mdswitches[i++].len = end - start; |
7687 | |
7688 | if (*end == '\0') |
7689 | break; |
7690 | } |
7691 | } |
7692 | |
7693 | p = multilib_exclusions; |
7694 | while (*p != '\0') |
7695 | { |
7696 | /* Ignore newlines. */ |
7697 | if (*p == '\n') |
7698 | { |
7699 | ++p; |
7700 | continue; |
7701 | } |
7702 | |
7703 | /* Check the arguments. */ |
7704 | ok = 1; |
7705 | while (*p != ';') |
7706 | { |
7707 | if (*p == '\0') |
7708 | { |
7709 | invalid_exclusions: |
7710 | fatal ("multilib exclusions '%s' is invalid", |
7711 | multilib_exclusions); |
7712 | } |
7713 | |
7714 | if (! ok) |
7715 | { |
7716 | ++p; |
7717 | continue; |
7718 | } |
7719 | |
7720 | this_arg = p; |
7721 | while (*p != ' ' && *p != ';') |
7722 | { |
7723 | if (*p == '\0') |
7724 | goto invalid_exclusions; |
7725 | ++p; |
7726 | } |
7727 | |
7728 | if (*this_arg != '!') |
7729 | not_arg = 0; |
7730 | else |
7731 | { |
7732 | not_arg = 1; |
7733 | ++this_arg; |
7734 | } |
7735 | |
7736 | ok = used_arg (this_arg, p - this_arg); |
7737 | if (not_arg) |
7738 | ok = ! ok; |
7739 | |
7740 | if (*p == ' ') |
7741 | ++p; |
7742 | } |
7743 | |
7744 | if (ok) |
7745 | return; |
7746 | |
7747 | ++p; |
7748 | } |
7749 | |
7750 | first = 1; |
7751 | p = multilib_select; |
7752 | while (*p != '\0') |
7753 | { |
7754 | /* Ignore newlines. */ |
7755 | if (*p == '\n') |
7756 | { |
7757 | ++p; |
7758 | continue; |
7759 | } |
7760 | |
7761 | /* Get the initial path. */ |
7762 | this_path = p; |
7763 | while (*p != ' ') |
7764 | { |
7765 | if (*p == '\0') |
7766 | { |
7767 | invalid_select: |
7768 | fatal ("multilib select '%s' is invalid", |
7769 | multilib_select); |
7770 | } |
7771 | ++p; |
7772 | } |
7773 | this_path_len = p - this_path; |
7774 | |
7775 | /* Check the arguments. */ |
7776 | ok = 1; |
7777 | ndfltok = 1; |
7778 | ++p; |
7779 | while (*p != ';') |
7780 | { |
7781 | if (*p == '\0') |
7782 | goto invalid_select; |
7783 | |
7784 | if (! ok) |
7785 | { |
7786 | ++p; |
7787 | continue; |
7788 | } |
7789 | |
7790 | this_arg = p; |
7791 | while (*p != ' ' && *p != ';') |
7792 | { |
7793 | if (*p == '\0') |
7794 | goto invalid_select; |
7795 | ++p; |
7796 | } |
7797 | |
7798 | if (*this_arg != '!') |
7799 | not_arg = 0; |
7800 | else |
7801 | { |
7802 | not_arg = 1; |
7803 | ++this_arg; |
7804 | } |
7805 | |
7806 | /* If this is a default argument, we can just ignore it. |
7807 | This is true even if this_arg begins with '!'. Beginning |
7808 | with '!' does not mean that this argument is necessarily |
7809 | inappropriate for this library: it merely means that |
7810 | there is a more specific library which uses this |
7811 | argument. If this argument is a default, we need not |
7812 | consider that more specific library. */ |
7813 | ok = used_arg (this_arg, p - this_arg); |
7814 | if (not_arg) |
7815 | ok = ! ok; |
7816 | |
7817 | if (! ok) |
7818 | ndfltok = 0; |
7819 | |
7820 | if (default_arg (this_arg, p - this_arg)) |
7821 | ok = 1; |
7822 | |
7823 | if (*p == ' ') |
7824 | ++p; |
7825 | } |
7826 | |
7827 | if (ok && first) |
7828 | { |
7829 | if (this_path_len != 1 |
7830 | || this_path[0] != '.') |
7831 | { |
7832 | char *new_multilib_dir = XNEWVEC( ( char * ) xmalloc ( sizeof ( char ) * ( this_path_len + 1 ) ) ) (char, this_path_len + 1); |
7833 | char *q; |
7834 | |
7835 | strncpy (new_multilib_dir, this_path, this_path_len); |
7836 | new_multilib_dir[this_path_len] = '\0'; |
7837 | q = strchr (new_multilib_dir, ':'); |
7838 | if (q != NULL( ( void * ) 0 )) |
7839 | *q = '\0'; |
7840 | multilib_dir = new_multilib_dir; |
7841 | } |
7842 | first = 0; |
7843 | } |
7844 | |
7845 | if (ndfltok) |
7846 | { |
7847 | const char *q = this_path, *end = this_path + this_path_len; |
7848 | |
7849 | while (q < end && *q != ':') |
7850 | q++; |
7851 | if (q < end) |
7852 | { |
7853 | char *new_multilib_os_dir = XNEWVEC( ( char * ) xmalloc ( sizeof ( char ) * ( end - q ) ) ) (char, end - q); |
7854 | memcpy (new_multilib_os_dir, q + 1, end - q - 1); |
7855 | new_multilib_os_dir[end - q - 1] = '\0'; |
7856 | multilib_os_dir = new_multilib_os_dir; |
7857 | break; |
7858 | } |
7859 | } |
7860 | |
7861 | ++p; |
7862 | } |
7863 | |
7864 | if (multilib_dir == NULL( ( void * ) 0 ) && multilib_os_dir != NULL( ( void * ) 0 ) |
7865 | && strcmp (multilib_os_dir, ".") == 0) |
7866 | { |
7867 | free ((char *) multilib_os_dir); |
7868 | multilib_os_dir = NULL( ( void * ) 0 ); |
7869 | } |
7870 | else if (multilib_dir != NULL( ( void * ) 0 ) && multilib_os_dir == NULL( ( void * ) 0 )) |
7871 | multilib_os_dir = multilib_dir; |
7872 | } |
7873 | |
7874 | /* Print out the multiple library subdirectory selection |
7875 | information. This prints out a series of lines. Each line looks |
7876 | like SUBDIRECTORY;@OPTION@OPTION, with as many options as is |
7877 | required. Only the desired options are printed out, the negative |
7878 | matches. The options are print without a leading dash. There are |
7879 | no spaces to make it easy to use the information in the shell. |
7880 | Each subdirectory is printed only once. This assumes the ordering |
7881 | generated by the genmultilib script. Also, we leave out ones that match |
7882 | the exclusions. */ |
7883 | |
7884 | static void |
7885 | print_multilib_info (void) |
7886 | { |
7887 | const char *p = multilib_select; |
7888 | const char *last_path = 0, *this_path; |
7889 | int skip; |
7890 | unsigned int last_path_len = 0; |
7891 | |
7892 | while (*p != '\0') |
7893 | { |
7894 | skip = 0; |
7895 | /* Ignore newlines. */ |
7896 | if (*p == '\n') |
7897 | { |
7898 | ++p; |
7899 | continue; |
7900 | } |
7901 | |
7902 | /* Get the initial path. */ |
7903 | this_path = p; |
7904 | while (*p != ' ') |
7905 | { |
7906 | if (*p == '\0') |
7907 | { |
7908 | invalid_select: |
7909 | fatal ("multilib select '%s' is invalid", multilib_select); |
7910 | } |
7911 | |
7912 | ++p; |
7913 | } |
7914 | |
7915 | /* When --disable-multilib was used but target defines |
7916 | MULTILIB_OSDIRNAMES, entries starting with .: are there just |
7917 | to find multilib_os_dir, so skip them from output. */ |
7918 | if (this_path[0] == '.' && this_path[1] == ':') |
7919 | skip = 1; |
7920 | |
7921 | /* Check for matches with the multilib_exclusions. We don't bother |
7922 | with the '!' in either list. If any of the exclusion rules match |
7923 | all of its options with the select rule, we skip it. */ |
7924 | { |
7925 | const char *e = multilib_exclusions; |
7926 | const char *this_arg; |
7927 | |
7928 | while (*e != '\0') |
7929 | { |
7930 | int m = 1; |
7931 | /* Ignore newlines. */ |
7932 | if (*e == '\n') |
7933 | { |
7934 | ++e; |
7935 | continue; |
7936 | } |
7937 | |
7938 | /* Check the arguments. */ |
7939 | while (*e != ';') |
7940 | { |
7941 | const char *q; |
7942 | int mp = 0; |
7943 | |
7944 | if (*e == '\0') |
7945 | { |
7946 | invalid_exclusion: |
7947 | fatal ("multilib exclusion '%s' is invalid", |
7948 | multilib_exclusions); |
7949 | } |
7950 | |
7951 | if (! m) |
7952 | { |
7953 | ++e; |
7954 | continue; |
7955 | } |
7956 | |
7957 | this_arg = e; |
7958 | |
7959 | while (*e != ' ' && *e != ';') |
7960 | { |
7961 | if (*e == '\0') |
7962 | goto invalid_exclusion; |
7963 | ++e; |
7964 | } |
7965 | |
7966 | q = p + 1; |
7967 | while (*q != ';') |
7968 | { |
7969 | const char *arg; |
7970 | int len = e - this_arg; |
7971 | |
7972 | if (*q == '\0') |
7973 | goto invalid_select; |
7974 | |
7975 | arg = q; |
7976 | |
7977 | while (*q != ' ' && *q != ';') |
7978 | { |
7979 | if (*q == '\0') |
7980 | goto invalid_select; |
7981 | ++q; |
7982 | } |
7983 | |
7984 | if (! strncmp (arg, this_arg, |
7985 | (len < q - arg) ? q - arg : len) |
7986 | || default_arg (this_arg, e - this_arg)) |
7987 | { |
7988 | mp = 1; |
7989 | break; |
7990 | } |
7991 | |
7992 | if (*q == ' ') |
7993 | ++q; |
7994 | } |
7995 | |
7996 | if (! mp) |
7997 | m = 0; |
7998 | |
7999 | if (*e == ' ') |
8000 | ++e; |
8001 | } |
8002 | |
8003 | if (m) |
8004 | { |
8005 | skip = 1; |
8006 | break; |
8007 | } |
8008 | |
8009 | if (*e != '\0') |
8010 | ++e; |
8011 | } |
8012 | } |
8013 | |
8014 | if (! skip) |
8015 | { |
8016 | /* If this is a duplicate, skip it. */ |
8017 | skip = (last_path != 0 |
8018 | && (unsigned int) (p - this_path) == last_path_len |
8019 | && ! strncmp (last_path, this_path, last_path_len)); |
8020 | |
8021 | last_path = this_path; |
8022 | last_path_len = p - this_path; |
8023 | } |
8024 | |
8025 | /* If this directory requires any default arguments, we can skip |
8026 | it. We will already have printed a directory identical to |
8027 | this one which does not require that default argument. */ |
8028 | if (! skip) |
8029 | { |
8030 | const char *q; |
8031 | |
8032 | q = p + 1; |
8033 | while (*q != ';') |
8034 | { |
8035 | const char *arg; |
8036 | |
8037 | if (*q == '\0') |
8038 | goto invalid_select; |
8039 | |
8040 | if (*q == '!') |
8041 | arg = NULL( ( void * ) 0 ); |
8042 | else |
8043 | arg = q; |
8044 | |
8045 | while (*q != ' ' && *q != ';') |
8046 | { |
8047 | if (*q == '\0') |
8048 | goto invalid_select; |
8049 | ++q; |
8050 | } |
8051 | |
8052 | if (arg != NULL( ( void * ) 0 ) |
8053 | && default_arg (arg, q - arg)) |
8054 | { |
8055 | skip = 1; |
8056 | break; |
8057 | } |
8058 | |
8059 | if (*q == ' ') |
8060 | ++q; |
8061 | } |
8062 | } |
8063 | |
8064 | if (! skip) |
8065 | { |
8066 | const char *p1; |
8067 | |
8068 | for (p1 = last_path; p1 < p && *p1 != ':'; p1++) |
8069 | putchar__sputc ( * p1 , __stdoutp ) (*p1); |
8070 | putchar__sputc ( ';' , __stdoutp ) (';'); |
8071 | } |
8072 | |
8073 | ++p; |
8074 | while (*p != ';') |
8075 | { |
8076 | int use_arg; |
8077 | |
8078 | if (*p == '\0') |
8079 | goto invalid_select; |
8080 | |
8081 | if (skip) |
8082 | { |
8083 | ++p; |
8084 | continue; |
8085 | } |
8086 | |
8087 | use_arg = *p != '!'; |
8088 | |
8089 | if (use_arg) |
8090 | putchar__sputc ( '@' , __stdoutp ) ('@'); |
8091 | |
8092 | while (*p != ' ' && *p != ';') |
8093 | { |
8094 | if (*p == '\0') |
8095 | goto invalid_select; |
8096 | if (use_arg) |
8097 | putchar__sputc ( * p , __stdoutp ) (*p); |
8098 | ++p; |
8099 | } |
8100 | |
8101 | if (*p == ' ') |
8102 | ++p; |
8103 | } |
8104 | |
8105 | if (! skip) |
8106 | { |
8107 | /* If there are extra options, print them now. */ |
8108 | if (multilib_extra && *multilib_extra) |
8109 | { |
8110 | int print_at = TRUE1; |
8111 | const char *q; |
8112 | |
8113 | for (q = multilib_extra; *q != '\0'; q++) |
8114 | { |
8115 | if (*q == ' ') |
8116 | print_at = TRUE1; |
8117 | else |
8118 | { |
8119 | if (print_at) |
8120 | putchar__sputc ( '@' , __stdoutp ) ('@'); |
8121 | putchar__sputc ( * q , __stdoutp ) (*q); |
8122 | print_at = FALSE0; |
8123 | } |
8124 | } |
8125 | } |
8126 | |
8127 | putchar__sputc ( '\n' , __stdoutp ) ('\n'); |
8128 | } |
8129 | |
8130 | ++p; |
8131 | } |
8132 | } |
8133 | |
8134 | /* if-exists built-in spec function. |
8135 | |
8136 | Checks to see if the file specified by the absolute pathname in |
8137 | ARGS exists. Returns that pathname if found. |
8138 | |
8139 | The usual use for this function is to check for a library file |
8140 | (whose name has been expanded with %s). */ |
8141 | |
8142 | static const char * |
8143 | if_exists_spec_function (int argc, const char **argv) |
8144 | { |
8145 | /* Must have only one argument. */ |
8146 | if (argc == 1 && IS_ABSOLUTE_PATH( ( ( ( argv [ 0 ] ) [ 0 ] ) == '/' ) ) (argv[0]) && ! access (argv[0], R_OK( 1 << 2 ))) |
8147 | return argv[0]; |
8148 | |
8149 | return NULL( ( void * ) 0 ); |
8150 | } |
8151 | |
8152 | /* if-exists-else built-in spec function. |
8153 | |
8154 | This is like if-exists, but takes an additional argument which |
8155 | is returned if the first argument does not exist. */ |
8156 | |
8157 | static const char * |
8158 | if_exists_else_spec_function (int argc, const char **argv) |
8159 | { |
8160 | /* Must have exactly two arguments. */ |
8161 | if (argc != 2) |
8162 | return NULL( ( void * ) 0 ); |
8163 | |
8164 | if (IS_ABSOLUTE_PATH( ( ( ( argv [ 0 ] ) [ 0 ] ) == '/' ) ) (argv[0]) && ! access (argv[0], R_OK( 1 << 2 ))) |
8165 | return argv[0]; |
8166 | |
8167 | return argv[1]; |
8168 | } |
8169 | |
8170 | /* replace-outfile built-in spec function. |
8171 | |
8172 | This looks for the first argument in the outfiles array's name and |
8173 | replaces it with the second argument. */ |
8174 | |
8175 | static const char * |
8176 | replace_outfile_spec_function (int argc, const char **argv) |
8177 | { |
8178 | int i; |
8179 | /* Must have exactly two arguments. */ |
8180 | if (argc != 2) |
8181 | abortfancy_abort ( "../../src/gcc/gcc.c" , 8181 , __FUNCTION__ ) (); |
8182 | |
8183 | for (i = 0; i < n_infiles; i++) |
8184 | { |
8185 | if (outfiles[i] && !strcmp (outfiles[i], argv[0])) |
8186 | outfiles[i] = xstrdup (argv[1]); |
8187 | } |
8188 | return NULL( ( void * ) 0 ); |
8189 | } |
8190 | |
8191 | /* Given two version numbers, compares the two numbers. |
8192 | A version number must match the regular expression |
8193 | ([1-9][0-9]*|0)(\.([1-9][0-9]*|0))* |
8194 | */ |
8195 | static int |
8196 | compare_version_strings (const char *v1, const char *v2) |
8197 | { |
8198 | int rresult; |
8199 | regex_t r; |
8200 | |
8201 | if (regcompxregcomp (&r, "^([1-9][0-9]*|0)(\\.([1-9][0-9]*|0))*$", |
8202 | REG_EXTENDED1 | REG_NOSUB( ( ( 1 << 1 ) << 1 ) << 1 )) != 0) |
8203 | abortfancy_abort ( "../../src/gcc/gcc.c" , 8203 , __FUNCTION__ ) (); |
8204 | rresult = regexecxregexec (&r, v1, 0, NULL( ( void * ) 0 ), 0); |
8205 | if (rresult == REG_NOMATCH) |
8206 | fatal ("invalid version number `%s'", v1); |
8207 | else if (rresult != 0) |
8208 | abortfancy_abort ( "../../src/gcc/gcc.c" , 8208 , __FUNCTION__ ) (); |
8209 | rresult = regexecxregexec (&r, v2, 0, NULL( ( void * ) 0 ), 0); |
8210 | if (rresult == REG_NOMATCH) |
8211 | fatal ("invalid version number `%s'", v2); |
8212 | else if (rresult != 0) |
8213 | abortfancy_abort ( "../../src/gcc/gcc.c" , 8213 , __FUNCTION__ ) (); |
8214 | |
8215 | return strverscmp (v1, v2); |
8216 | } |
8217 | |
8218 | |
8219 | /* version_compare built-in spec function. |
8220 | |
8221 | This takes an argument of the following form: |
8222 | |
8223 | <comparison-op> <arg1> [<arg2>] <switch> <result> |
8224 | |
8225 | and produces "result" if the comparison evaluates to true, |
8226 | and nothing if it doesn't. |
8227 | |
8228 | The supported <comparison-op> values are: |
8229 | |
8230 | >= true if switch is a later (or same) version than arg1 |
8231 | !> opposite of >= |
8232 | < true if switch is an earlier version than arg1 |
8233 | !< opposite of < |
8234 | >< true if switch is arg1 or later, and earlier than arg2 |
8235 | <> true if switch is earlier than arg1 or is arg2 or later |
8236 | |
8237 | If the switch is not present, the condition is false unless |
8238 | the first character of the <comparison-op> is '!'. |
8239 | |
8240 | For example, |
8241 | %:version-compare(>= 10.3 mmacosx-version-min= -lmx) |
8242 | adds -lmx if -mmacosx-version-min=10.3.9 was passed. */ |
8243 | |
8244 | static const char * |
8245 | version_compare_spec_function (int argc, const char **argv) |
8246 | { |
8247 | int comp1, comp2; |
8248 | size_t switch_len; |
8249 | const char *switch_value = NULL( ( void * ) 0 ); |
8250 | int nargs = 1, i; |
8251 | bool_Bool result; |
8252 | |
8253 | if (argc < 3) |
8254 | fatal ("too few arguments to %%:version-compare"); |
8255 | if (argv[0][0] == '\0') |
8256 | abortfancy_abort ( "../../src/gcc/gcc.c" , 8256 , __FUNCTION__ ) (); |
8257 | if ((argv[0][1] == '<' || argv[0][1] == '>') && argv[0][0] != '!') |
8258 | nargs = 2; |
8259 | if (argc != nargs + 3) |
8260 | fatal ("too many arguments to %%:version-compare"); |
8261 | |
8262 | switch_len = strlen (argv[nargs + 1]); |
8263 | for (i = 0; i < n_switches; i++) |
8264 | if (!strncmp (switches[i].part1, argv[nargs + 1], switch_len) |
8265 | && check_live_switch (i, switch_len)) |
8266 | switch_value = switches[i].part1 + switch_len; |
8267 | |
8268 | if (switch_value == NULL( ( void * ) 0 )) |
8269 | comp1 = comp2 = -1; |
8270 | else |
8271 | { |
8272 | comp1 = compare_version_strings (switch_value, argv[1]); |
8273 | if (nargs == 2) |
8274 | comp2 = compare_version_strings (switch_value, argv[2]); |
8275 | else |
8276 | comp2 = -1; /* This value unused. */ |
8277 | } |
8278 | |
8279 | switch (argv[0][0] << 8 | argv[0][1]) |
8280 | { |
8281 | case '>' << 8 | '=': |
8282 | result = comp1 >= 0; |
8283 | break; |
8284 | case '!' << 8 | '<': |
8285 | result = comp1 >= 0 || switch_value == NULL( ( void * ) 0 ); |
8286 | break; |
8287 | case '<' << 8: |
8288 | result = comp1 < 0; |
8289 | break; |
8290 | case '!' << 8 | '>': |
8291 | result = comp1 < 0 || switch_value == NULL( ( void * ) 0 ); |
8292 | break; |
8293 | case '>' << 8 | '<': |
8294 | result = comp1 >= 0 && comp2 < 0; |
8295 | break; |
8296 | case '<' << 8 | '>': |
8297 | result = comp1 < 0 || comp2 >= 0; |
8298 | break; |
8299 | |
8300 | default: |
8301 | fatal ("unknown operator '%s' in %%:version-compare", argv[0]); |
8302 | } |
8303 | if (! result) |
8304 | return NULL( ( void * ) 0 ); |
8305 | |
8306 | /* APPLE LOCAL begin version-compare quoting 5378841 */ |
8307 | { |
8308 | /* Escape all spec special characters. */ |
8309 | const char *p = argv[nargs + 2]; |
8310 | char *q, *b; |
8311 | while (*p) |
8312 | { |
8313 | if (*p == ' ' || *p == '\t' || *p == '\n' || *p == '%' || *p == '\\') |
8314 | break; |
8315 | ++p; |
8316 | } |
8317 | |
8318 | if (*p == 0) |
8319 | return argv[nargs + 2]; |
8320 | |
8321 | q = b = xmalloc (strlen (p)*2 + 1); |
8322 | p = argv[nargs + 2]; |
8323 | while (*p) |
8324 | { |
8325 | if (*p == ' ' || *p == '\t' || *p == '\n' || *p == '%' || *p == '\\') |
8326 | *q++ = '\\'; |
8327 | *q++ = *p++; |
8328 | } |
8329 | *q = *p; |
8330 | return b; |
8331 | } |
8332 | /* APPLE LOCAL end version-compare quoting 5378841 */ |
8333 | } |
8334 | |
8335 | /* %:include builtin spec function. This differs from %include in that it |
8336 | can be nested inside a spec, and thus be conditionalized. It takes |
8337 | one argument, the filename, and looks for it in the startfile path. |
8338 | The result is always NULL, i.e. an empty expansion. */ |
8339 | |
8340 | static const char * |
8341 | include_spec_function (int argc, const char **argv) |
8342 | { |
8343 | char *file; |
8344 | |
8345 | if (argc != 1) |
8346 | abortfancy_abort ( "../../src/gcc/gcc.c" , 8346 , __FUNCTION__ ) (); |
8347 | |
8348 | file = find_a_file (&startfile_prefixes, argv[0], R_OK( 1 << 2 ), 0); |
8349 | read_specs (file ? file : argv[0], FALSE0); |
8350 | |
8351 | return NULL( ( void * ) 0 ); |
8352 | } |