re PR target/69894 (dependency of gcc-plugin.h not installed on aarch64-linux-gnu)
[gcc.git] / gcc / lto-wrapper.c
1 /* Wrapper to call lto. Used by collect2 and the linker plugin.
2 Copyright (C) 2009-2016 Free Software Foundation, Inc.
3
4 Factored out of collect2 by Rafael Espindola <espindola@google.com>
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 3, 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 COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
21
22
23 /* This program is passed a gcc, a list of gcc arguments and a list of
24 object files containing IL. It scans the argument list to check if
25 we are in whopr mode or not modifies the arguments and needed and
26 prints a list of output files on stdout.
27
28 Example:
29
30 $ lto-wrapper gcc/xgcc -B gcc a.o b.o -o test -flto
31
32 The above will print something like
33 /tmp/ccwbQ8B2.lto.o
34
35 If WHOPR is used instead, more than one file might be produced
36 ./ccXj2DTk.lto.ltrans.o
37 ./ccCJuXGv.lto.ltrans.o
38 */
39
40 #include "config.h"
41 #include "system.h"
42 #include "coretypes.h"
43 #include "intl.h"
44 #include "diagnostic.h"
45 #include "obstack.h"
46 #include "opts.h"
47 #include "options.h"
48 #include "simple-object.h"
49 #include "lto-section-names.h"
50 #include "collect-utils.h"
51
52 /* Environment variable, used for passing the names of offload targets from GCC
53 driver to lto-wrapper. */
54 #define OFFLOAD_TARGET_NAMES_ENV "OFFLOAD_TARGET_NAMES"
55
56 enum lto_mode_d {
57 LTO_MODE_NONE, /* Not doing LTO. */
58 LTO_MODE_LTO, /* Normal LTO. */
59 LTO_MODE_WHOPR /* WHOPR. */
60 };
61
62 /* Current LTO mode. */
63 static enum lto_mode_d lto_mode = LTO_MODE_NONE;
64
65 static char *ltrans_output_file;
66 static char *flto_out;
67 static unsigned int nr;
68 static char **input_names;
69 static char **output_names;
70 static char **offload_names;
71 static const char *offloadbegin, *offloadend;
72 static char *makefile;
73
74 const char tool_name[] = "lto-wrapper";
75
76 /* Delete tempfiles. Called from utils_cleanup. */
77
78 void
79 tool_cleanup (bool)
80 {
81 unsigned int i;
82
83 if (ltrans_output_file)
84 maybe_unlink (ltrans_output_file);
85 if (flto_out)
86 maybe_unlink (flto_out);
87 if (makefile)
88 maybe_unlink (makefile);
89 for (i = 0; i < nr; ++i)
90 {
91 maybe_unlink (input_names[i]);
92 if (output_names[i])
93 maybe_unlink (output_names[i]);
94 }
95 }
96
97 static void
98 lto_wrapper_cleanup (void)
99 {
100 utils_cleanup (false);
101 }
102
103 /* Unlink a temporary LTRANS file unless requested otherwise. */
104
105 void
106 maybe_unlink (const char *file)
107 {
108 if (!save_temps)
109 {
110 if (unlink_if_ordinary (file)
111 && errno != ENOENT)
112 fatal_error (input_location, "deleting LTRANS file %s: %m", file);
113 }
114 else if (verbose)
115 fprintf (stderr, "[Leaving LTRANS %s]\n", file);
116 }
117
118 /* Template of LTRANS dumpbase suffix. */
119 #define DUMPBASE_SUFFIX ".ltrans18446744073709551615"
120
121 /* Create decoded options from the COLLECT_GCC and COLLECT_GCC_OPTIONS
122 environment according to LANG_MASK. */
123
124 static void
125 get_options_from_collect_gcc_options (const char *collect_gcc,
126 const char *collect_gcc_options,
127 unsigned int lang_mask,
128 struct cl_decoded_option **decoded_options,
129 unsigned int *decoded_options_count)
130 {
131 struct obstack argv_obstack;
132 char *argv_storage;
133 const char **argv;
134 int j, k, argc;
135
136 argv_storage = xstrdup (collect_gcc_options);
137 obstack_init (&argv_obstack);
138 obstack_ptr_grow (&argv_obstack, collect_gcc);
139
140 for (j = 0, k = 0; argv_storage[j] != '\0'; ++j)
141 {
142 if (argv_storage[j] == '\'')
143 {
144 obstack_ptr_grow (&argv_obstack, &argv_storage[k]);
145 ++j;
146 do
147 {
148 if (argv_storage[j] == '\0')
149 fatal_error (input_location, "malformed COLLECT_GCC_OPTIONS");
150 else if (strncmp (&argv_storage[j], "'\\''", 4) == 0)
151 {
152 argv_storage[k++] = '\'';
153 j += 4;
154 }
155 else if (argv_storage[j] == '\'')
156 break;
157 else
158 argv_storage[k++] = argv_storage[j++];
159 }
160 while (1);
161 argv_storage[k++] = '\0';
162 }
163 }
164
165 obstack_ptr_grow (&argv_obstack, NULL);
166 argc = obstack_object_size (&argv_obstack) / sizeof (void *) - 1;
167 argv = XOBFINISH (&argv_obstack, const char **);
168
169 decode_cmdline_options_to_array (argc, (const char **)argv,
170 lang_mask,
171 decoded_options, decoded_options_count);
172 obstack_free (&argv_obstack, NULL);
173 }
174
175 /* Append OPTION to the options array DECODED_OPTIONS with size
176 DECODED_OPTIONS_COUNT. */
177
178 static void
179 append_option (struct cl_decoded_option **decoded_options,
180 unsigned int *decoded_options_count,
181 struct cl_decoded_option *option)
182 {
183 ++*decoded_options_count;
184 *decoded_options
185 = (struct cl_decoded_option *)
186 xrealloc (*decoded_options,
187 (*decoded_options_count
188 * sizeof (struct cl_decoded_option)));
189 memcpy (&(*decoded_options)[*decoded_options_count - 1], option,
190 sizeof (struct cl_decoded_option));
191 }
192
193 /* Try to merge and complain about options FDECODED_OPTIONS when applied
194 ontop of DECODED_OPTIONS. */
195
196 static void
197 merge_and_complain (struct cl_decoded_option **decoded_options,
198 unsigned int *decoded_options_count,
199 struct cl_decoded_option *fdecoded_options,
200 unsigned int fdecoded_options_count)
201 {
202 unsigned int i, j;
203
204 /* ??? Merge options from files. Most cases can be
205 handled by either unioning or intersecting
206 (for example -fwrapv is a case for unioning,
207 -ffast-math is for intersection). Most complaints
208 about real conflicts between different options can
209 be deferred to the compiler proper. Options that
210 we can neither safely handle by intersection nor
211 unioning would need to be complained about here.
212 Ideally we'd have a flag in the opt files that
213 tells whether to union or intersect or reject.
214 In absence of that it's unclear what a good default is.
215 It's also difficult to get positional handling correct. */
216
217 /* The following does what the old LTO option code did,
218 union all target and a selected set of common options. */
219 for (i = 0; i < fdecoded_options_count; ++i)
220 {
221 struct cl_decoded_option *foption = &fdecoded_options[i];
222 switch (foption->opt_index)
223 {
224 case OPT_SPECIAL_unknown:
225 case OPT_SPECIAL_ignore:
226 case OPT_SPECIAL_program_name:
227 case OPT_SPECIAL_input_file:
228 break;
229
230 default:
231 if (!(cl_options[foption->opt_index].flags & CL_TARGET))
232 break;
233
234 /* Fallthru. */
235 case OPT_fdiagnostics_show_caret:
236 case OPT_fdiagnostics_show_option:
237 case OPT_fdiagnostics_show_location_:
238 case OPT_fshow_column:
239 case OPT_fPIC:
240 case OPT_fpic:
241 case OPT_fPIE:
242 case OPT_fpie:
243 case OPT_fcommon:
244 case OPT_fexceptions:
245 case OPT_fnon_call_exceptions:
246 case OPT_fgnu_tm:
247 /* Do what the old LTO code did - collect exactly one option
248 setting per OPT code, we pick the first we encounter.
249 ??? This doesn't make too much sense, but when it doesn't
250 then we should complain. */
251 for (j = 0; j < *decoded_options_count; ++j)
252 if ((*decoded_options)[j].opt_index == foption->opt_index)
253 break;
254 if (j == *decoded_options_count)
255 append_option (decoded_options, decoded_options_count, foption);
256 break;
257
258 case OPT_ftrapv:
259 case OPT_fstrict_overflow:
260 case OPT_ffp_contract_:
261 /* For selected options we can merge conservatively. */
262 for (j = 0; j < *decoded_options_count; ++j)
263 if ((*decoded_options)[j].opt_index == foption->opt_index)
264 break;
265 if (j == *decoded_options_count)
266 append_option (decoded_options, decoded_options_count, foption);
267 /* FP_CONTRACT_OFF < FP_CONTRACT_ON < FP_CONTRACT_FAST,
268 -fno-trapv < -ftrapv,
269 -fno-strict-overflow < -fstrict-overflow */
270 else if (foption->value < (*decoded_options)[j].value)
271 (*decoded_options)[j] = *foption;
272 break;
273
274 case OPT_fmath_errno:
275 case OPT_fsigned_zeros:
276 case OPT_ftrapping_math:
277 case OPT_fwrapv:
278 case OPT_fopenmp:
279 case OPT_fopenacc:
280 case OPT_fcilkplus:
281 case OPT_fcheck_pointer_bounds:
282 /* For selected options we can merge conservatively. */
283 for (j = 0; j < *decoded_options_count; ++j)
284 if ((*decoded_options)[j].opt_index == foption->opt_index)
285 break;
286 if (j == *decoded_options_count)
287 append_option (decoded_options, decoded_options_count, foption);
288 /* -fmath-errno > -fno-math-errno,
289 -fsigned-zeros > -fno-signed-zeros,
290 -ftrapping-math > -fno-trapping-math,
291 -fwrapv > -fno-wrapv. */
292 else if (foption->value > (*decoded_options)[j].value)
293 (*decoded_options)[j] = *foption;
294 break;
295
296 case OPT_fopenacc_dim_:
297 /* Append or check identical. */
298 for (j = 0; j < *decoded_options_count; ++j)
299 if ((*decoded_options)[j].opt_index == foption->opt_index)
300 break;
301 if (j == *decoded_options_count)
302 append_option (decoded_options, decoded_options_count, foption);
303 else if (strcmp ((*decoded_options)[j].arg, foption->arg))
304 fatal_error (input_location,
305 "Option %s with different values",
306 foption->orig_option_with_args_text);
307 break;
308
309 case OPT_freg_struct_return:
310 case OPT_fpcc_struct_return:
311 for (j = 0; j < *decoded_options_count; ++j)
312 if ((*decoded_options)[j].opt_index == foption->opt_index)
313 break;
314 if (j == *decoded_options_count)
315 fatal_error (input_location,
316 "Option %s not used consistently in all LTO input"
317 " files", foption->orig_option_with_args_text);
318 break;
319
320 case OPT_foffload_abi_:
321 for (j = 0; j < *decoded_options_count; ++j)
322 if ((*decoded_options)[j].opt_index == foption->opt_index)
323 break;
324 if (j == *decoded_options_count)
325 append_option (decoded_options, decoded_options_count, foption);
326 else if (foption->value != (*decoded_options)[j].value)
327 fatal_error (input_location,
328 "Option %s not used consistently in all LTO input"
329 " files", foption->orig_option_with_args_text);
330 break;
331
332 case OPT_O:
333 case OPT_Ofast:
334 case OPT_Og:
335 case OPT_Os:
336 for (j = 0; j < *decoded_options_count; ++j)
337 if ((*decoded_options)[j].opt_index == OPT_O
338 || (*decoded_options)[j].opt_index == OPT_Ofast
339 || (*decoded_options)[j].opt_index == OPT_Og
340 || (*decoded_options)[j].opt_index == OPT_Os)
341 break;
342 if (j == *decoded_options_count)
343 append_option (decoded_options, decoded_options_count, foption);
344 else if ((*decoded_options)[j].opt_index == foption->opt_index
345 && foption->opt_index != OPT_O)
346 /* Exact same options get merged. */
347 ;
348 else
349 {
350 /* For mismatched option kinds preserve the optimization
351 level only, thus merge it as -On. This also handles
352 merging of same optimization level -On. */
353 int level = 0;
354 switch (foption->opt_index)
355 {
356 case OPT_O:
357 if (foption->arg[0] == '\0')
358 level = MAX (level, 1);
359 else
360 level = MAX (level, atoi (foption->arg));
361 break;
362 case OPT_Ofast:
363 level = MAX (level, 3);
364 break;
365 case OPT_Og:
366 level = MAX (level, 1);
367 break;
368 case OPT_Os:
369 level = MAX (level, 2);
370 break;
371 default:
372 gcc_unreachable ();
373 }
374 switch ((*decoded_options)[j].opt_index)
375 {
376 case OPT_O:
377 if ((*decoded_options)[j].arg[0] == '\0')
378 level = MAX (level, 1);
379 else
380 level = MAX (level, atoi ((*decoded_options)[j].arg));
381 break;
382 case OPT_Ofast:
383 level = MAX (level, 3);
384 break;
385 case OPT_Og:
386 level = MAX (level, 1);
387 break;
388 case OPT_Os:
389 level = MAX (level, 2);
390 break;
391 default:
392 gcc_unreachable ();
393 }
394 (*decoded_options)[j].opt_index = OPT_O;
395 char *tem;
396 tem = xasprintf ("-O%d", level);
397 (*decoded_options)[j].arg = &tem[2];
398 (*decoded_options)[j].canonical_option[0] = tem;
399 (*decoded_options)[j].value = 1;
400 }
401 break;
402
403 case OPT_foffload_:
404 append_option (decoded_options, decoded_options_count, foption);
405 break;
406 }
407 }
408 }
409
410 /* Auxiliary function that frees elements of PTR and PTR itself.
411 N is number of elements to be freed. If PTR is NULL, nothing is freed.
412 If an element is NULL, subsequent elements are not freed. */
413
414 static void **
415 free_array_of_ptrs (void **ptr, unsigned n)
416 {
417 if (!ptr)
418 return NULL;
419 for (unsigned i = 0; i < n; i++)
420 {
421 if (!ptr[i])
422 break;
423 free (ptr[i]);
424 }
425 free (ptr);
426 return NULL;
427 }
428
429 /* Parse STR, saving found tokens into PVALUES and return their number.
430 Tokens are assumed to be delimited by ':'. If APPEND is non-null,
431 append it to every token we find. */
432
433 static unsigned
434 parse_env_var (const char *str, char ***pvalues, const char *append)
435 {
436 const char *curval, *nextval;
437 char **values;
438 unsigned num = 1, i;
439
440 curval = strchr (str, ':');
441 while (curval)
442 {
443 num++;
444 curval = strchr (curval + 1, ':');
445 }
446
447 values = (char**) xmalloc (num * sizeof (char*));
448 curval = str;
449 nextval = strchr (curval, ':');
450 if (nextval == NULL)
451 nextval = strchr (curval, '\0');
452
453 int append_len = append ? strlen (append) : 0;
454 for (i = 0; i < num; i++)
455 {
456 int l = nextval - curval;
457 values[i] = (char*) xmalloc (l + 1 + append_len);
458 memcpy (values[i], curval, l);
459 values[i][l] = 0;
460 if (append)
461 strcat (values[i], append);
462 curval = nextval + 1;
463 nextval = strchr (curval, ':');
464 if (nextval == NULL)
465 nextval = strchr (curval, '\0');
466 }
467 *pvalues = values;
468 return num;
469 }
470
471 /* Append options OPTS from lto or offload_lto sections to ARGV_OBSTACK. */
472
473 static void
474 append_compiler_options (obstack *argv_obstack, struct cl_decoded_option *opts,
475 unsigned int count)
476 {
477 /* Append compiler driver arguments as far as they were merged. */
478 for (unsigned int j = 1; j < count; ++j)
479 {
480 struct cl_decoded_option *option = &opts[j];
481
482 /* File options have been properly filtered by lto-opts.c. */
483 switch (option->opt_index)
484 {
485 /* Drop arguments that we want to take from the link line. */
486 case OPT_flto_:
487 case OPT_flto:
488 case OPT_flto_partition_:
489 continue;
490
491 default:
492 break;
493 }
494
495 /* For now do what the original LTO option code was doing - pass
496 on any CL_TARGET flag and a few selected others. */
497 switch (option->opt_index)
498 {
499 case OPT_fdiagnostics_show_caret:
500 case OPT_fdiagnostics_show_option:
501 case OPT_fdiagnostics_show_location_:
502 case OPT_fshow_column:
503 case OPT_fPIC:
504 case OPT_fpic:
505 case OPT_fPIE:
506 case OPT_fpie:
507 case OPT_fcommon:
508 case OPT_fexceptions:
509 case OPT_fnon_call_exceptions:
510 case OPT_fgnu_tm:
511 case OPT_freg_struct_return:
512 case OPT_fpcc_struct_return:
513 case OPT_ffp_contract_:
514 case OPT_fmath_errno:
515 case OPT_fsigned_zeros:
516 case OPT_ftrapping_math:
517 case OPT_fwrapv:
518 case OPT_fopenmp:
519 case OPT_fopenacc:
520 case OPT_fopenacc_dim_:
521 case OPT_fcilkplus:
522 case OPT_ftrapv:
523 case OPT_fstrict_overflow:
524 case OPT_foffload_abi_:
525 case OPT_O:
526 case OPT_Ofast:
527 case OPT_Og:
528 case OPT_Os:
529 case OPT_fcheck_pointer_bounds:
530 break;
531
532 default:
533 if (!(cl_options[option->opt_index].flags & CL_TARGET))
534 continue;
535 }
536
537 /* Pass the option on. */
538 for (unsigned int i = 0; i < option->canonical_option_num_elements; ++i)
539 obstack_ptr_grow (argv_obstack, option->canonical_option[i]);
540 }
541 }
542
543 /* Append diag options in OPTS with length COUNT to ARGV_OBSTACK. */
544
545 static void
546 append_diag_options (obstack *argv_obstack, struct cl_decoded_option *opts,
547 unsigned int count)
548 {
549 /* Append compiler driver arguments as far as they were merged. */
550 for (unsigned int j = 1; j < count; ++j)
551 {
552 struct cl_decoded_option *option = &opts[j];
553
554 switch (option->opt_index)
555 {
556 case OPT_fdiagnostics_color_:
557 case OPT_fdiagnostics_show_caret:
558 case OPT_fdiagnostics_show_option:
559 case OPT_fdiagnostics_show_location_:
560 case OPT_fshow_column:
561 break;
562 default:
563 continue;
564 }
565
566 /* Pass the option on. */
567 for (unsigned int i = 0; i < option->canonical_option_num_elements; ++i)
568 obstack_ptr_grow (argv_obstack, option->canonical_option[i]);
569 }
570 }
571
572
573 /* Append linker options OPTS to ARGV_OBSTACK. */
574
575 static void
576 append_linker_options (obstack *argv_obstack, struct cl_decoded_option *opts,
577 unsigned int count)
578 {
579 /* Append linker driver arguments. Compiler options from the linker
580 driver arguments will override / merge with those from the compiler. */
581 for (unsigned int j = 1; j < count; ++j)
582 {
583 struct cl_decoded_option *option = &opts[j];
584
585 /* Do not pass on frontend specific flags not suitable for lto. */
586 if (!(cl_options[option->opt_index].flags
587 & (CL_COMMON|CL_TARGET|CL_DRIVER|CL_LTO)))
588 continue;
589
590 switch (option->opt_index)
591 {
592 case OPT_o:
593 case OPT_flto_:
594 case OPT_flto:
595 /* We've handled these LTO options, do not pass them on. */
596 continue;
597
598 case OPT_freg_struct_return:
599 case OPT_fpcc_struct_return:
600 /* Ignore these, they are determined by the input files.
601 ??? We fail to diagnose a possible mismatch here. */
602 continue;
603
604 case OPT_fopenmp:
605 case OPT_fopenacc:
606 case OPT_fcilkplus:
607 /* Ignore -fno-XXX form of these options, as otherwise
608 corresponding builtins will not be enabled. */
609 if (option->value == 0)
610 continue;
611 break;
612
613 default:
614 break;
615 }
616
617 /* Pass the option on. */
618 for (unsigned int i = 0; i < option->canonical_option_num_elements; ++i)
619 obstack_ptr_grow (argv_obstack, option->canonical_option[i]);
620 }
621 }
622
623 /* Extract options for TARGET offload compiler from OPTIONS and append
624 them to ARGV_OBSTACK. */
625
626 static void
627 append_offload_options (obstack *argv_obstack, const char *target,
628 struct cl_decoded_option *options,
629 unsigned int options_count)
630 {
631 for (unsigned i = 0; i < options_count; i++)
632 {
633 const char *cur, *next, *opts;
634 char **argv;
635 unsigned argc;
636 struct cl_decoded_option *option = &options[i];
637
638 if (option->opt_index != OPT_foffload_)
639 continue;
640
641 /* If option argument starts with '-' then no target is specified. That
642 means offload options are specified for all targets, so we need to
643 append them. */
644 if (option->arg[0] == '-')
645 opts = option->arg;
646 else
647 {
648 opts = strchr (option->arg, '=');
649 /* If there are offload targets specified, but no actual options,
650 there is nothing to do here. */
651 if (!opts)
652 continue;
653
654 cur = option->arg;
655
656 while (cur < opts)
657 {
658 next = strchr (cur, ',');
659 if (next == NULL)
660 next = opts;
661 next = (next > opts) ? opts : next;
662
663 /* Are we looking for this offload target? */
664 if (strlen (target) == (size_t) (next - cur)
665 && strncmp (target, cur, next - cur) == 0)
666 break;
667
668 /* Skip the comma or equal sign. */
669 cur = next + 1;
670 }
671
672 if (cur >= opts)
673 continue;
674
675 opts++;
676 }
677
678 argv = buildargv (opts);
679 for (argc = 0; argv[argc]; argc++)
680 obstack_ptr_grow (argv_obstack, argv[argc]);
681 }
682 }
683
684 /* Check whether NAME can be accessed in MODE. This is like access,
685 except that it never considers directories to be executable. */
686
687 static int
688 access_check (const char *name, int mode)
689 {
690 if (mode == X_OK)
691 {
692 struct stat st;
693
694 if (stat (name, &st) < 0
695 || S_ISDIR (st.st_mode))
696 return -1;
697 }
698
699 return access (name, mode);
700 }
701
702 /* Prepare a target image for offload TARGET, using mkoffload tool from
703 COMPILER_PATH. Return the name of the resultant object file. */
704
705 static char *
706 compile_offload_image (const char *target, const char *compiler_path,
707 unsigned in_argc, char *in_argv[],
708 struct cl_decoded_option *compiler_opts,
709 unsigned int compiler_opt_count,
710 struct cl_decoded_option *linker_opts,
711 unsigned int linker_opt_count)
712 {
713 char *filename = NULL;
714 char **argv;
715 char *suffix
716 = XALLOCAVEC (char, sizeof ("/accel//mkoffload") + strlen (target));
717 strcpy (suffix, "/accel/");
718 strcat (suffix, target);
719 strcat (suffix, "/mkoffload");
720
721 char **paths = NULL;
722 unsigned n_paths = parse_env_var (compiler_path, &paths, suffix);
723
724 const char *compiler = NULL;
725 for (unsigned i = 0; i < n_paths; i++)
726 if (access_check (paths[i], X_OK) == 0)
727 {
728 compiler = paths[i];
729 break;
730 }
731
732 if (compiler)
733 {
734 /* Generate temporary output file name. */
735 filename = make_temp_file (".target.o");
736
737 struct obstack argv_obstack;
738 obstack_init (&argv_obstack);
739 obstack_ptr_grow (&argv_obstack, compiler);
740 if (save_temps)
741 obstack_ptr_grow (&argv_obstack, "-save-temps");
742 if (verbose)
743 obstack_ptr_grow (&argv_obstack, "-v");
744 obstack_ptr_grow (&argv_obstack, "-o");
745 obstack_ptr_grow (&argv_obstack, filename);
746
747 /* Append names of input object files. */
748 for (unsigned i = 0; i < in_argc; i++)
749 obstack_ptr_grow (&argv_obstack, in_argv[i]);
750
751 /* Append options from offload_lto sections. */
752 append_compiler_options (&argv_obstack, compiler_opts,
753 compiler_opt_count);
754 append_diag_options (&argv_obstack, linker_opts, linker_opt_count);
755
756 /* Append options specified by -foffload last. In case of conflicting
757 options we expect offload compiler to choose the latest. */
758 append_offload_options (&argv_obstack, target, compiler_opts,
759 compiler_opt_count);
760 append_offload_options (&argv_obstack, target, linker_opts,
761 linker_opt_count);
762
763 obstack_ptr_grow (&argv_obstack, NULL);
764 argv = XOBFINISH (&argv_obstack, char **);
765 fork_execute (argv[0], argv, true);
766 obstack_free (&argv_obstack, NULL);
767 }
768
769 free_array_of_ptrs ((void **) paths, n_paths);
770 return filename;
771 }
772
773
774 /* The main routine dealing with offloading.
775 The routine builds a target image for each offload target. IN_ARGC and
776 IN_ARGV specify options and input object files. As all of them could contain
777 target sections, we pass them all to target compilers. */
778
779 static void
780 compile_images_for_offload_targets (unsigned in_argc, char *in_argv[],
781 struct cl_decoded_option *compiler_opts,
782 unsigned int compiler_opt_count,
783 struct cl_decoded_option *linker_opts,
784 unsigned int linker_opt_count)
785 {
786 char **names = NULL;
787 const char *target_names = getenv (OFFLOAD_TARGET_NAMES_ENV);
788 if (!target_names)
789 return;
790 unsigned num_targets = parse_env_var (target_names, &names, NULL);
791
792 int next_name_entry = 0;
793 const char *compiler_path = getenv ("COMPILER_PATH");
794 if (!compiler_path)
795 goto out;
796
797 /* Prepare an image for each target and save the name of the resultant object
798 file to the OFFLOAD_NAMES array. It is terminated by a NULL entry. */
799 offload_names = XCNEWVEC (char *, num_targets + 1);
800 for (unsigned i = 0; i < num_targets; i++)
801 {
802 /* HSA does not use LTO-like streaming and a different compiler, skip
803 it. */
804 if (strcmp (names[i], "hsa") == 0)
805 continue;
806
807 offload_names[next_name_entry]
808 = compile_offload_image (names[i], compiler_path, in_argc, in_argv,
809 compiler_opts, compiler_opt_count,
810 linker_opts, linker_opt_count);
811 if (!offload_names[next_name_entry])
812 fatal_error (input_location,
813 "problem with building target image for %s\n", names[i]);
814 next_name_entry++;
815 }
816
817 out:
818 free_array_of_ptrs ((void **) names, num_targets);
819 }
820
821 /* Copy a file from SRC to DEST. */
822
823 static void
824 copy_file (const char *dest, const char *src)
825 {
826 FILE *d = fopen (dest, "wb");
827 FILE *s = fopen (src, "rb");
828 char buffer[512];
829 while (!feof (s))
830 {
831 size_t len = fread (buffer, 1, 512, s);
832 if (ferror (s) != 0)
833 fatal_error (input_location, "reading input file");
834 if (len > 0)
835 {
836 fwrite (buffer, 1, len, d);
837 if (ferror (d) != 0)
838 fatal_error (input_location, "writing output file");
839 }
840 }
841 }
842
843 /* Find the crtoffloadbegin.o and crtoffloadend.o files in LIBRARY_PATH, make
844 copies and store the names of the copies in offloadbegin and offloadend. */
845
846 static void
847 find_offloadbeginend (void)
848 {
849 char **paths = NULL;
850 const char *library_path = getenv ("LIBRARY_PATH");
851 if (!library_path)
852 return;
853 unsigned n_paths = parse_env_var (library_path, &paths, "/crtoffloadbegin.o");
854
855 unsigned i;
856 for (i = 0; i < n_paths; i++)
857 if (access_check (paths[i], R_OK) == 0)
858 {
859 size_t len = strlen (paths[i]);
860 char *tmp = xstrdup (paths[i]);
861 strcpy (paths[i] + len - strlen ("begin.o"), "end.o");
862 if (access_check (paths[i], R_OK) != 0)
863 fatal_error (input_location,
864 "installation error, can't find crtoffloadend.o");
865 /* The linker will delete the filenames we give it, so make
866 copies. */
867 offloadbegin = make_temp_file (".o");
868 offloadend = make_temp_file (".o");
869 copy_file (offloadbegin, tmp);
870 copy_file (offloadend, paths[i]);
871 free (tmp);
872 break;
873 }
874 if (i == n_paths)
875 fatal_error (input_location,
876 "installation error, can't find crtoffloadbegin.o");
877
878 free_array_of_ptrs ((void **) paths, n_paths);
879 }
880
881 /* A subroutine of run_gcc. Examine the open file FD for lto sections with
882 name prefix PREFIX, at FILE_OFFSET, and store any options we find in OPTS
883 and OPT_COUNT. Return true if we found a matchingn section, false
884 otherwise. COLLECT_GCC holds the value of the environment variable with
885 the same name. */
886
887 static bool
888 find_and_merge_options (int fd, off_t file_offset, const char *prefix,
889 struct cl_decoded_option **opts,
890 unsigned int *opt_count, const char *collect_gcc)
891 {
892 off_t offset, length;
893 char *data;
894 char *fopts;
895 const char *errmsg;
896 int err;
897 struct cl_decoded_option *fdecoded_options = *opts;
898 unsigned int fdecoded_options_count = *opt_count;
899
900 simple_object_read *sobj;
901 sobj = simple_object_start_read (fd, file_offset, "__GNU_LTO",
902 &errmsg, &err);
903 if (!sobj)
904 return false;
905
906 char *secname = XALLOCAVEC (char, strlen (prefix) + sizeof (".opts"));
907 strcpy (secname, prefix);
908 strcat (secname, ".opts");
909 if (!simple_object_find_section (sobj, secname, &offset, &length,
910 &errmsg, &err))
911 {
912 simple_object_release_read (sobj);
913 return false;
914 }
915
916 lseek (fd, file_offset + offset, SEEK_SET);
917 data = (char *)xmalloc (length);
918 read (fd, data, length);
919 fopts = data;
920 do
921 {
922 struct cl_decoded_option *f2decoded_options;
923 unsigned int f2decoded_options_count;
924 get_options_from_collect_gcc_options (collect_gcc,
925 fopts, CL_LANG_ALL,
926 &f2decoded_options,
927 &f2decoded_options_count);
928 if (!fdecoded_options)
929 {
930 fdecoded_options = f2decoded_options;
931 fdecoded_options_count = f2decoded_options_count;
932 }
933 else
934 merge_and_complain (&fdecoded_options,
935 &fdecoded_options_count,
936 f2decoded_options, f2decoded_options_count);
937
938 fopts += strlen (fopts) + 1;
939 }
940 while (fopts - data < length);
941
942 free (data);
943 simple_object_release_read (sobj);
944 *opts = fdecoded_options;
945 *opt_count = fdecoded_options_count;
946 return true;
947 }
948
949 /* Execute gcc. ARGC is the number of arguments. ARGV contains the arguments. */
950
951 static void
952 run_gcc (unsigned argc, char *argv[])
953 {
954 unsigned i, j;
955 const char **new_argv;
956 const char **argv_ptr;
957 char *list_option_full = NULL;
958 const char *linker_output = NULL;
959 const char *collect_gcc, *collect_gcc_options;
960 int parallel = 0;
961 int jobserver = 0;
962 bool no_partition = false;
963 struct cl_decoded_option *fdecoded_options = NULL;
964 struct cl_decoded_option *offload_fdecoded_options = NULL;
965 unsigned int fdecoded_options_count = 0;
966 unsigned int offload_fdecoded_options_count = 0;
967 struct cl_decoded_option *decoded_options;
968 unsigned int decoded_options_count;
969 struct obstack argv_obstack;
970 int new_head_argc;
971 bool have_lto = false;
972 bool have_offload = false;
973 unsigned lto_argc = 0, offload_argc = 0;
974 char **lto_argv, **offload_argv;
975
976 /* Get the driver and options. */
977 collect_gcc = getenv ("COLLECT_GCC");
978 if (!collect_gcc)
979 fatal_error (input_location,
980 "environment variable COLLECT_GCC must be set");
981 collect_gcc_options = getenv ("COLLECT_GCC_OPTIONS");
982 if (!collect_gcc_options)
983 fatal_error (input_location,
984 "environment variable COLLECT_GCC_OPTIONS must be set");
985 get_options_from_collect_gcc_options (collect_gcc, collect_gcc_options,
986 CL_LANG_ALL,
987 &decoded_options,
988 &decoded_options_count);
989
990 /* Allocate arrays for input object files with LTO or offload IL,
991 and for possible preceding arguments. */
992 lto_argv = XNEWVEC (char *, argc);
993 offload_argv = XNEWVEC (char *, argc);
994
995 /* Look at saved options in the IL files. */
996 for (i = 1; i < argc; ++i)
997 {
998 char *p;
999 int fd;
1000 off_t file_offset = 0;
1001 long loffset;
1002 int consumed;
1003 char *filename = argv[i];
1004
1005 if ((p = strrchr (argv[i], '@'))
1006 && p != argv[i]
1007 && sscanf (p, "@%li%n", &loffset, &consumed) >= 1
1008 && strlen (p) == (unsigned int) consumed)
1009 {
1010 filename = XNEWVEC (char, p - argv[i] + 1);
1011 memcpy (filename, argv[i], p - argv[i]);
1012 filename[p - argv[i]] = '\0';
1013 file_offset = (off_t) loffset;
1014 }
1015 fd = open (filename, O_RDONLY | O_BINARY);
1016 if (fd == -1)
1017 {
1018 lto_argv[lto_argc++] = argv[i];
1019 continue;
1020 }
1021
1022 if (find_and_merge_options (fd, file_offset, LTO_SECTION_NAME_PREFIX,
1023 &fdecoded_options, &fdecoded_options_count,
1024 collect_gcc))
1025 {
1026 have_lto = true;
1027 lto_argv[lto_argc++] = argv[i];
1028 }
1029
1030 if (find_and_merge_options (fd, file_offset, OFFLOAD_SECTION_NAME_PREFIX,
1031 &offload_fdecoded_options,
1032 &offload_fdecoded_options_count, collect_gcc))
1033 {
1034 have_offload = true;
1035 offload_argv[offload_argc++] = argv[i];
1036 }
1037
1038 close (fd);
1039 }
1040
1041 /* Initalize the common arguments for the driver. */
1042 obstack_init (&argv_obstack);
1043 obstack_ptr_grow (&argv_obstack, collect_gcc);
1044 obstack_ptr_grow (&argv_obstack, "-xlto");
1045 obstack_ptr_grow (&argv_obstack, "-c");
1046
1047 append_compiler_options (&argv_obstack, fdecoded_options,
1048 fdecoded_options_count);
1049 append_linker_options (&argv_obstack, decoded_options, decoded_options_count);
1050
1051 /* Scan linker driver arguments for things that are of relevance to us. */
1052 for (j = 1; j < decoded_options_count; ++j)
1053 {
1054 struct cl_decoded_option *option = &decoded_options[j];
1055 switch (option->opt_index)
1056 {
1057 case OPT_o:
1058 linker_output = option->arg;
1059 break;
1060
1061 case OPT_save_temps:
1062 save_temps = 1;
1063 break;
1064
1065 case OPT_v:
1066 verbose = 1;
1067 break;
1068
1069 case OPT_flto_partition_:
1070 if (strcmp (option->arg, "none") == 0)
1071 no_partition = true;
1072 break;
1073
1074 case OPT_flto_:
1075 if (strcmp (option->arg, "jobserver") == 0)
1076 {
1077 jobserver = 1;
1078 parallel = 1;
1079 }
1080 else
1081 {
1082 parallel = atoi (option->arg);
1083 if (parallel <= 1)
1084 parallel = 0;
1085 }
1086 /* Fallthru. */
1087
1088 case OPT_flto:
1089 lto_mode = LTO_MODE_WHOPR;
1090 break;
1091
1092 default:
1093 break;
1094 }
1095 }
1096
1097 if (no_partition)
1098 {
1099 lto_mode = LTO_MODE_LTO;
1100 jobserver = 0;
1101 parallel = 0;
1102 }
1103
1104 if (linker_output)
1105 {
1106 char *output_dir, *base, *name;
1107 bool bit_bucket = strcmp (linker_output, HOST_BIT_BUCKET) == 0;
1108
1109 output_dir = xstrdup (linker_output);
1110 base = output_dir;
1111 for (name = base; *name; name++)
1112 if (IS_DIR_SEPARATOR (*name))
1113 base = name + 1;
1114 *base = '\0';
1115
1116 linker_output = &linker_output[base - output_dir];
1117 if (*output_dir == '\0')
1118 {
1119 static char current_dir[] = { '.', DIR_SEPARATOR, '\0' };
1120 output_dir = current_dir;
1121 }
1122 if (!bit_bucket)
1123 {
1124 obstack_ptr_grow (&argv_obstack, "-dumpdir");
1125 obstack_ptr_grow (&argv_obstack, output_dir);
1126 }
1127
1128 obstack_ptr_grow (&argv_obstack, "-dumpbase");
1129 }
1130
1131 /* Remember at which point we can scrub args to re-use the commons. */
1132 new_head_argc = obstack_object_size (&argv_obstack) / sizeof (void *);
1133
1134 if (have_offload)
1135 {
1136 compile_images_for_offload_targets (offload_argc, offload_argv,
1137 offload_fdecoded_options,
1138 offload_fdecoded_options_count,
1139 decoded_options,
1140 decoded_options_count);
1141 if (offload_names)
1142 {
1143 find_offloadbeginend ();
1144 for (i = 0; offload_names[i]; i++)
1145 printf ("%s\n", offload_names[i]);
1146 free_array_of_ptrs ((void **) offload_names, i);
1147 }
1148 }
1149
1150 if (offloadbegin)
1151 printf ("%s\n", offloadbegin);
1152
1153 /* If object files contain offload sections, but do not contain LTO sections,
1154 then there is no need to perform a link-time recompilation, i.e.
1155 lto-wrapper is used only for a compilation of offload images. */
1156 if (have_offload && !have_lto)
1157 {
1158 for (i = 1; i < argc; ++i)
1159 if (strncmp (argv[i], "-fresolution=",
1160 sizeof ("-fresolution=") - 1) != 0
1161 && strncmp (argv[i], "-flinker-output=",
1162 sizeof ("-flinker-output=") - 1) != 0)
1163 {
1164 char *out_file;
1165 /* Can be ".o" or ".so". */
1166 char *ext = strrchr (argv[i], '.');
1167 if (ext == NULL)
1168 out_file = make_temp_file ("");
1169 else
1170 out_file = make_temp_file (ext);
1171 /* The linker will delete the files we give it, so make copies. */
1172 copy_file (out_file, argv[i]);
1173 printf ("%s\n", out_file);
1174 }
1175 goto finish;
1176 }
1177
1178 if (lto_mode == LTO_MODE_LTO)
1179 {
1180 flto_out = make_temp_file (".lto.o");
1181 if (linker_output)
1182 obstack_ptr_grow (&argv_obstack, linker_output);
1183 obstack_ptr_grow (&argv_obstack, "-o");
1184 obstack_ptr_grow (&argv_obstack, flto_out);
1185 }
1186 else
1187 {
1188 const char *list_option = "-fltrans-output-list=";
1189 size_t list_option_len = strlen (list_option);
1190 char *tmp;
1191
1192 if (linker_output)
1193 {
1194 char *dumpbase = (char *) xmalloc (strlen (linker_output)
1195 + sizeof (".wpa") + 1);
1196 strcpy (dumpbase, linker_output);
1197 strcat (dumpbase, ".wpa");
1198 obstack_ptr_grow (&argv_obstack, dumpbase);
1199 }
1200
1201 if (linker_output && save_temps)
1202 {
1203 ltrans_output_file = (char *) xmalloc (strlen (linker_output)
1204 + sizeof (".ltrans.out") + 1);
1205 strcpy (ltrans_output_file, linker_output);
1206 strcat (ltrans_output_file, ".ltrans.out");
1207 }
1208 else
1209 ltrans_output_file = make_temp_file (".ltrans.out");
1210 list_option_full = (char *) xmalloc (sizeof (char) *
1211 (strlen (ltrans_output_file) + list_option_len + 1));
1212 tmp = list_option_full;
1213
1214 obstack_ptr_grow (&argv_obstack, tmp);
1215 strcpy (tmp, list_option);
1216 tmp += list_option_len;
1217 strcpy (tmp, ltrans_output_file);
1218
1219 if (jobserver)
1220 obstack_ptr_grow (&argv_obstack, xstrdup ("-fwpa=jobserver"));
1221 else if (parallel > 1)
1222 {
1223 char buf[256];
1224 sprintf (buf, "-fwpa=%i", parallel);
1225 obstack_ptr_grow (&argv_obstack, xstrdup (buf));
1226 }
1227 else
1228 obstack_ptr_grow (&argv_obstack, "-fwpa");
1229 }
1230
1231 /* Append the input objects and possible preceding arguments. */
1232 for (i = 0; i < lto_argc; ++i)
1233 obstack_ptr_grow (&argv_obstack, lto_argv[i]);
1234 obstack_ptr_grow (&argv_obstack, NULL);
1235
1236 new_argv = XOBFINISH (&argv_obstack, const char **);
1237 argv_ptr = &new_argv[new_head_argc];
1238 fork_execute (new_argv[0], CONST_CAST (char **, new_argv), true);
1239
1240 if (lto_mode == LTO_MODE_LTO)
1241 {
1242 printf ("%s\n", flto_out);
1243 free (flto_out);
1244 flto_out = NULL;
1245 }
1246 else
1247 {
1248 FILE *stream = fopen (ltrans_output_file, "r");
1249 FILE *mstream = NULL;
1250 struct obstack env_obstack;
1251
1252 if (!stream)
1253 fatal_error (input_location, "fopen: %s: %m", ltrans_output_file);
1254
1255 /* Parse the list of LTRANS inputs from the WPA stage. */
1256 obstack_init (&env_obstack);
1257 nr = 0;
1258 for (;;)
1259 {
1260 const unsigned piece = 32;
1261 char *output_name = NULL;
1262 char *buf, *input_name = (char *)xmalloc (piece);
1263 size_t len;
1264
1265 buf = input_name;
1266 cont:
1267 if (!fgets (buf, piece, stream))
1268 break;
1269 len = strlen (input_name);
1270 if (input_name[len - 1] != '\n')
1271 {
1272 input_name = (char *)xrealloc (input_name, len + piece);
1273 buf = input_name + len;
1274 goto cont;
1275 }
1276 input_name[len - 1] = '\0';
1277
1278 if (input_name[0] == '*')
1279 output_name = &input_name[1];
1280
1281 nr++;
1282 input_names = (char **)xrealloc (input_names, nr * sizeof (char *));
1283 output_names = (char **)xrealloc (output_names, nr * sizeof (char *));
1284 input_names[nr-1] = input_name;
1285 output_names[nr-1] = output_name;
1286 }
1287 fclose (stream);
1288 maybe_unlink (ltrans_output_file);
1289 ltrans_output_file = NULL;
1290
1291 if (parallel)
1292 {
1293 makefile = make_temp_file (".mk");
1294 mstream = fopen (makefile, "w");
1295 }
1296
1297 /* Execute the LTRANS stage for each input file (or prepare a
1298 makefile to invoke this in parallel). */
1299 for (i = 0; i < nr; ++i)
1300 {
1301 char *output_name;
1302 char *input_name = input_names[i];
1303 /* If it's a pass-through file do nothing. */
1304 if (output_names[i])
1305 continue;
1306
1307 /* Replace the .o suffix with a .ltrans.o suffix and write
1308 the resulting name to the LTRANS output list. */
1309 obstack_grow (&env_obstack, input_name, strlen (input_name) - 2);
1310 obstack_grow (&env_obstack, ".ltrans.o", sizeof (".ltrans.o"));
1311 output_name = XOBFINISH (&env_obstack, char *);
1312
1313 /* Adjust the dumpbase if the linker output file was seen. */
1314 if (linker_output)
1315 {
1316 char *dumpbase
1317 = (char *) xmalloc (strlen (linker_output)
1318 + sizeof (DUMPBASE_SUFFIX) + 1);
1319 snprintf (dumpbase,
1320 strlen (linker_output) + sizeof (DUMPBASE_SUFFIX),
1321 "%s.ltrans%u", linker_output, i);
1322 argv_ptr[0] = dumpbase;
1323 }
1324
1325 argv_ptr[1] = "-fltrans";
1326 argv_ptr[2] = "-o";
1327 argv_ptr[3] = output_name;
1328 argv_ptr[4] = input_name;
1329 argv_ptr[5] = NULL;
1330 if (parallel)
1331 {
1332 fprintf (mstream, "%s:\n\t@%s ", output_name, new_argv[0]);
1333 for (j = 1; new_argv[j] != NULL; ++j)
1334 fprintf (mstream, " '%s'", new_argv[j]);
1335 fprintf (mstream, "\n");
1336 /* If we are not preserving the ltrans input files then
1337 truncate them as soon as we have processed it. This
1338 reduces temporary disk-space usage. */
1339 if (! save_temps)
1340 fprintf (mstream, "\t@-touch -r %s %s.tem > /dev/null 2>&1 "
1341 "&& mv %s.tem %s\n",
1342 input_name, input_name, input_name, input_name);
1343 }
1344 else
1345 {
1346 fork_execute (new_argv[0], CONST_CAST (char **, new_argv),
1347 true);
1348 maybe_unlink (input_name);
1349 }
1350
1351 output_names[i] = output_name;
1352 }
1353 if (parallel)
1354 {
1355 struct pex_obj *pex;
1356 char jobs[32];
1357
1358 fprintf (mstream, "all:");
1359 for (i = 0; i < nr; ++i)
1360 fprintf (mstream, " \\\n\t%s", output_names[i]);
1361 fprintf (mstream, "\n");
1362 fclose (mstream);
1363 if (!jobserver)
1364 {
1365 /* Avoid passing --jobserver-fd= and similar flags
1366 unless jobserver mode is explicitly enabled. */
1367 putenv (xstrdup ("MAKEFLAGS="));
1368 putenv (xstrdup ("MFLAGS="));
1369 }
1370 new_argv[0] = getenv ("MAKE");
1371 if (!new_argv[0])
1372 new_argv[0] = "make";
1373 new_argv[1] = "-f";
1374 new_argv[2] = makefile;
1375 i = 3;
1376 if (!jobserver)
1377 {
1378 snprintf (jobs, 31, "-j%d", parallel);
1379 new_argv[i++] = jobs;
1380 }
1381 new_argv[i++] = "all";
1382 new_argv[i++] = NULL;
1383 pex = collect_execute (new_argv[0], CONST_CAST (char **, new_argv),
1384 NULL, NULL, PEX_SEARCH, false);
1385 do_wait (new_argv[0], pex);
1386 maybe_unlink (makefile);
1387 makefile = NULL;
1388 for (i = 0; i < nr; ++i)
1389 maybe_unlink (input_names[i]);
1390 }
1391 for (i = 0; i < nr; ++i)
1392 {
1393 fputs (output_names[i], stdout);
1394 putc ('\n', stdout);
1395 free (input_names[i]);
1396 }
1397 nr = 0;
1398 free (output_names);
1399 free (input_names);
1400 free (list_option_full);
1401 obstack_free (&env_obstack, NULL);
1402 }
1403
1404 finish:
1405 if (offloadend)
1406 printf ("%s\n", offloadend);
1407
1408 XDELETE (lto_argv);
1409 XDELETE (offload_argv);
1410 obstack_free (&argv_obstack, NULL);
1411 }
1412
1413
1414 /* Entry point. */
1415
1416 int
1417 main (int argc, char *argv[])
1418 {
1419 const char *p;
1420
1421 init_opts_obstack ();
1422
1423 p = argv[0] + strlen (argv[0]);
1424 while (p != argv[0] && !IS_DIR_SEPARATOR (p[-1]))
1425 --p;
1426 progname = p;
1427
1428 xmalloc_set_program_name (progname);
1429
1430 gcc_init_libintl ();
1431
1432 diagnostic_initialize (global_dc, 0);
1433
1434 if (atexit (lto_wrapper_cleanup) != 0)
1435 fatal_error (input_location, "atexit failed");
1436
1437 if (signal (SIGINT, SIG_IGN) != SIG_IGN)
1438 signal (SIGINT, fatal_signal);
1439 #ifdef SIGHUP
1440 if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
1441 signal (SIGHUP, fatal_signal);
1442 #endif
1443 if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
1444 signal (SIGTERM, fatal_signal);
1445 #ifdef SIGPIPE
1446 if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
1447 signal (SIGPIPE, fatal_signal);
1448 #endif
1449 #ifdef SIGCHLD
1450 /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
1451 receive the signal. A different setting is inheritable */
1452 signal (SIGCHLD, SIG_DFL);
1453 #endif
1454
1455 /* We may be called with all the arguments stored in some file and
1456 passed with @file. Expand them into argv before processing. */
1457 expandargv (&argc, &argv);
1458
1459 run_gcc (argc, argv);
1460
1461 return 0;
1462 }