1 /* Wrapper to call lto. Used by collect2 and the linker plugin.
2 Copyright (C) 2009-2019 Free Software Foundation, Inc.
4 Factored out of collect2 by Rafael Espindola <espindola@google.com>
6 This file is part of GCC.
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
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
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/>. */
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.
30 $ lto-wrapper gcc/xgcc -B gcc a.o b.o -o test -flto
32 The above will print something like
35 If WHOPR is used instead, more than one file might be produced
36 ./ccXj2DTk.lto.ltrans.o
37 ./ccCJuXGv.lto.ltrans.o
42 #include "coretypes.h"
44 #include "diagnostic.h"
48 #include "simple-object.h"
49 #include "lto-section-names.h"
50 #include "collect-utils.h"
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"
57 LTO_MODE_NONE
, /* Not doing LTO. */
58 LTO_MODE_LTO
, /* Normal LTO. */
59 LTO_MODE_WHOPR
/* WHOPR. */
62 /* Current LTO mode. */
63 static enum lto_mode_d lto_mode
= LTO_MODE_NONE
;
65 static char *ltrans_output_file
;
66 static char *flto_out
;
67 static unsigned int nr
;
68 static int *ltrans_priorities
;
69 static char **input_names
;
70 static char **output_names
;
71 static char **offload_names
;
72 static char *offload_objects_file_name
;
73 static char *makefile
;
74 static unsigned int num_deb_objs
;
75 static const char **early_debug_object_names
;
77 const char tool_name
[] = "lto-wrapper";
79 /* Delete tempfiles. Called from utils_cleanup. */
86 if (ltrans_output_file
)
87 maybe_unlink (ltrans_output_file
);
89 maybe_unlink (flto_out
);
90 if (offload_objects_file_name
)
91 maybe_unlink (offload_objects_file_name
);
93 maybe_unlink (makefile
);
94 if (early_debug_object_names
)
95 for (i
= 0; i
< num_deb_objs
; ++i
)
96 if (early_debug_object_names
[i
])
97 maybe_unlink (early_debug_object_names
[i
]);
98 for (i
= 0; i
< nr
; ++i
)
100 maybe_unlink (input_names
[i
]);
102 maybe_unlink (output_names
[i
]);
107 lto_wrapper_cleanup (void)
109 utils_cleanup (false);
112 /* Unlink a temporary LTRANS file unless requested otherwise. */
115 maybe_unlink (const char *file
)
119 if (unlink_if_ordinary (file
)
121 fatal_error (input_location
, "deleting LTRANS file %s: %m", file
);
124 fprintf (stderr
, "[Leaving LTRANS %s]\n", file
);
127 /* Template of LTRANS dumpbase suffix. */
128 #define DUMPBASE_SUFFIX ".ltrans18446744073709551615"
130 /* Create decoded options from the COLLECT_GCC and COLLECT_GCC_OPTIONS
131 environment according to LANG_MASK. */
134 get_options_from_collect_gcc_options (const char *collect_gcc
,
135 const char *collect_gcc_options
,
136 unsigned int lang_mask
,
137 struct cl_decoded_option
**decoded_options
,
138 unsigned int *decoded_options_count
)
140 struct obstack argv_obstack
;
145 argv_storage
= xstrdup (collect_gcc_options
);
146 obstack_init (&argv_obstack
);
147 obstack_ptr_grow (&argv_obstack
, collect_gcc
);
149 for (j
= 0, k
= 0; argv_storage
[j
] != '\0'; ++j
)
151 if (argv_storage
[j
] == '\'')
153 obstack_ptr_grow (&argv_obstack
, &argv_storage
[k
]);
157 if (argv_storage
[j
] == '\0')
158 fatal_error (input_location
, "malformed COLLECT_GCC_OPTIONS");
159 else if (strncmp (&argv_storage
[j
], "'\\''", 4) == 0)
161 argv_storage
[k
++] = '\'';
164 else if (argv_storage
[j
] == '\'')
167 argv_storage
[k
++] = argv_storage
[j
++];
170 argv_storage
[k
++] = '\0';
174 obstack_ptr_grow (&argv_obstack
, NULL
);
175 argc
= obstack_object_size (&argv_obstack
) / sizeof (void *) - 1;
176 argv
= XOBFINISH (&argv_obstack
, const char **);
178 decode_cmdline_options_to_array (argc
, (const char **)argv
,
180 decoded_options
, decoded_options_count
);
181 obstack_free (&argv_obstack
, NULL
);
184 /* Append OPTION to the options array DECODED_OPTIONS with size
185 DECODED_OPTIONS_COUNT. */
188 append_option (struct cl_decoded_option
**decoded_options
,
189 unsigned int *decoded_options_count
,
190 struct cl_decoded_option
*option
)
192 ++*decoded_options_count
;
194 = (struct cl_decoded_option
*)
195 xrealloc (*decoded_options
,
196 (*decoded_options_count
197 * sizeof (struct cl_decoded_option
)));
198 memcpy (&(*decoded_options
)[*decoded_options_count
- 1], option
,
199 sizeof (struct cl_decoded_option
));
202 /* Remove option number INDEX from DECODED_OPTIONS, update
203 DECODED_OPTIONS_COUNT. */
206 remove_option (struct cl_decoded_option
**decoded_options
,
207 int index
, unsigned int *decoded_options_count
)
209 --*decoded_options_count
;
210 memmove (&(*decoded_options
)[index
+ 1],
211 &(*decoded_options
)[index
],
212 sizeof (struct cl_decoded_option
)
213 * (*decoded_options_count
- index
));
216 /* Try to merge and complain about options FDECODED_OPTIONS when applied
217 ontop of DECODED_OPTIONS. */
220 merge_and_complain (struct cl_decoded_option
**decoded_options
,
221 unsigned int *decoded_options_count
,
222 struct cl_decoded_option
*fdecoded_options
,
223 unsigned int fdecoded_options_count
)
226 struct cl_decoded_option
*pic_option
= NULL
;
227 struct cl_decoded_option
*pie_option
= NULL
;
229 /* ??? Merge options from files. Most cases can be
230 handled by either unioning or intersecting
231 (for example -fwrapv is a case for unioning,
232 -ffast-math is for intersection). Most complaints
233 about real conflicts between different options can
234 be deferred to the compiler proper. Options that
235 we can neither safely handle by intersection nor
236 unioning would need to be complained about here.
237 Ideally we'd have a flag in the opt files that
238 tells whether to union or intersect or reject.
239 In absence of that it's unclear what a good default is.
240 It's also difficult to get positional handling correct. */
242 /* The following does what the old LTO option code did,
243 union all target and a selected set of common options. */
244 for (i
= 0; i
< fdecoded_options_count
; ++i
)
246 struct cl_decoded_option
*foption
= &fdecoded_options
[i
];
247 switch (foption
->opt_index
)
249 case OPT_SPECIAL_unknown
:
250 case OPT_SPECIAL_ignore
:
251 case OPT_SPECIAL_deprecated
:
252 case OPT_SPECIAL_program_name
:
253 case OPT_SPECIAL_input_file
:
257 if (!(cl_options
[foption
->opt_index
].flags
& CL_TARGET
))
261 case OPT_fdiagnostics_show_caret
:
262 case OPT_fdiagnostics_show_labels
:
263 case OPT_fdiagnostics_show_line_numbers
:
264 case OPT_fdiagnostics_show_option
:
265 case OPT_fdiagnostics_show_location_
:
266 case OPT_fshow_column
:
269 /* Do what the old LTO code did - collect exactly one option
270 setting per OPT code, we pick the first we encounter.
271 ??? This doesn't make too much sense, but when it doesn't
272 then we should complain. */
273 for (j
= 0; j
< *decoded_options_count
; ++j
)
274 if ((*decoded_options
)[j
].opt_index
== foption
->opt_index
)
276 if (j
== *decoded_options_count
)
277 append_option (decoded_options
, decoded_options_count
, foption
);
280 /* Figure out what PIC/PIE level wins and merge the results. */
283 pic_option
= foption
;
287 pie_option
= foption
;
292 /* For selected options we can merge conservatively. */
293 for (j
= 0; j
< *decoded_options_count
; ++j
)
294 if ((*decoded_options
)[j
].opt_index
== foption
->opt_index
)
296 if (j
== *decoded_options_count
)
297 append_option (decoded_options
, decoded_options_count
, foption
);
298 /* -fopenmp > -fno-openmp,
299 -fopenacc > -fno-openacc */
300 else if (foption
->value
> (*decoded_options
)[j
].value
)
301 (*decoded_options
)[j
] = *foption
;
304 case OPT_fopenacc_dim_
:
305 /* Append or check identical. */
306 for (j
= 0; j
< *decoded_options_count
; ++j
)
307 if ((*decoded_options
)[j
].opt_index
== foption
->opt_index
)
309 if (j
== *decoded_options_count
)
310 append_option (decoded_options
, decoded_options_count
, foption
);
311 else if (strcmp ((*decoded_options
)[j
].arg
, foption
->arg
))
312 fatal_error (input_location
,
313 "Option %s with different values",
314 foption
->orig_option_with_args_text
);
321 for (j
= 0; j
< *decoded_options_count
; ++j
)
322 if ((*decoded_options
)[j
].opt_index
== OPT_O
323 || (*decoded_options
)[j
].opt_index
== OPT_Ofast
324 || (*decoded_options
)[j
].opt_index
== OPT_Og
325 || (*decoded_options
)[j
].opt_index
== OPT_Os
)
327 if (j
== *decoded_options_count
)
328 append_option (decoded_options
, decoded_options_count
, foption
);
329 else if ((*decoded_options
)[j
].opt_index
== foption
->opt_index
330 && foption
->opt_index
!= OPT_O
)
331 /* Exact same options get merged. */
335 /* For mismatched option kinds preserve the optimization
336 level only, thus merge it as -On. This also handles
337 merging of same optimization level -On. */
339 switch (foption
->opt_index
)
342 if (foption
->arg
[0] == '\0')
343 level
= MAX (level
, 1);
345 level
= MAX (level
, atoi (foption
->arg
));
348 level
= MAX (level
, 3);
351 level
= MAX (level
, 1);
354 level
= MAX (level
, 2);
359 switch ((*decoded_options
)[j
].opt_index
)
362 if ((*decoded_options
)[j
].arg
[0] == '\0')
363 level
= MAX (level
, 1);
365 level
= MAX (level
, atoi ((*decoded_options
)[j
].arg
));
368 level
= MAX (level
, 3);
371 level
= MAX (level
, 1);
374 level
= MAX (level
, 2);
379 (*decoded_options
)[j
].opt_index
= OPT_O
;
381 tem
= xasprintf ("-O%d", level
);
382 (*decoded_options
)[j
].arg
= &tem
[2];
383 (*decoded_options
)[j
].canonical_option
[0] = tem
;
384 (*decoded_options
)[j
].value
= 1;
389 case OPT_foffload_abi_
:
390 for (j
= 0; j
< *decoded_options_count
; ++j
)
391 if ((*decoded_options
)[j
].opt_index
== foption
->opt_index
)
393 if (j
== *decoded_options_count
)
394 append_option (decoded_options
, decoded_options_count
, foption
);
395 else if (foption
->value
!= (*decoded_options
)[j
].value
)
396 fatal_error (input_location
,
397 "Option %s not used consistently in all LTO input"
398 " files", foption
->orig_option_with_args_text
);
403 append_option (decoded_options
, decoded_options_count
, foption
);
408 /* Merge PIC options:
409 -fPIC + -fpic = -fpic
410 -fPIC + -fno-pic = -fno-pic
411 -fpic/-fPIC + nothin = nothing.
412 It is a common mistake to mix few -fPIC compiled objects into otherwise
413 non-PIC code. We do not want to build everything with PIC then.
415 Similarly we merge PIE options, however in addition we keep
416 -fPIC + -fPIE = -fPIE
417 -fpic + -fPIE = -fpie
418 -fPIC/-fpic + -fpie = -fpie
420 It would be good to warn on mismatches, but it is bit hard to do as
421 we do not know what nothing translates to. */
423 for (unsigned int j
= 0; j
< *decoded_options_count
;)
424 if ((*decoded_options
)[j
].opt_index
== OPT_fPIC
425 || (*decoded_options
)[j
].opt_index
== OPT_fpic
)
427 /* -fno-pic in one unit implies -fno-pic everywhere. */
428 if ((*decoded_options
)[j
].value
== 0)
430 /* If we have no pic option or merge in -fno-pic, we still may turn
431 existing pic/PIC mode into pie/PIE if -fpie/-fPIE is present. */
432 else if ((pic_option
&& pic_option
->value
== 0)
437 bool big
= (*decoded_options
)[j
].opt_index
== OPT_fPIC
438 && pie_option
->opt_index
== OPT_fPIE
;
439 (*decoded_options
)[j
].opt_index
= big
? OPT_fPIE
: OPT_fpie
;
440 if (pie_option
->value
)
441 (*decoded_options
)[j
].canonical_option
[0] = big
? "-fPIE" : "-fpie";
443 (*decoded_options
)[j
].canonical_option
[0] = big
? "-fno-pie" : "-fno-pie";
444 (*decoded_options
)[j
].value
= pie_option
->value
;
449 (*decoded_options
)[j
] = *pic_option
;
452 /* We do not know if target defaults to pic or not, so just remove
453 option if it is missing in one unit but enabled in other. */
455 remove_option (decoded_options
, j
, decoded_options_count
);
457 else if (pic_option
->opt_index
== OPT_fpic
458 && (*decoded_options
)[j
].opt_index
== OPT_fPIC
)
460 (*decoded_options
)[j
] = *pic_option
;
466 else if ((*decoded_options
)[j
].opt_index
== OPT_fPIE
467 || (*decoded_options
)[j
].opt_index
== OPT_fpie
)
469 /* -fno-pie in one unit implies -fno-pie everywhere. */
470 if ((*decoded_options
)[j
].value
== 0)
472 /* If we have no pie option or merge in -fno-pie, we still preserve
473 PIE/pie if pic/PIC is present. */
474 else if ((pie_option
&& pie_option
->value
== 0)
477 /* If -fPIC/-fpic is given, merge it with -fPIE/-fpie. */
480 if (pic_option
->opt_index
== OPT_fpic
481 && (*decoded_options
)[j
].opt_index
== OPT_fPIE
)
483 (*decoded_options
)[j
].opt_index
= OPT_fpie
;
484 (*decoded_options
)[j
].canonical_option
[0]
485 = pic_option
->value
? "-fpie" : "-fno-pie";
487 else if (!pic_option
->value
)
488 (*decoded_options
)[j
].canonical_option
[0] = "-fno-pie";
489 (*decoded_options
)[j
].value
= pic_option
->value
;
494 (*decoded_options
)[j
] = *pie_option
;
497 /* Because we always append pic/PIE options this code path should
498 not happen unless the LTO object was built by old lto1 which
499 did not contain that logic yet. */
501 remove_option (decoded_options
, j
, decoded_options_count
);
503 else if (pie_option
->opt_index
== OPT_fpie
504 && (*decoded_options
)[j
].opt_index
== OPT_fPIE
)
506 (*decoded_options
)[j
] = *pie_option
;
516 /* Auxiliary function that frees elements of PTR and PTR itself.
517 N is number of elements to be freed. If PTR is NULL, nothing is freed.
518 If an element is NULL, subsequent elements are not freed. */
521 free_array_of_ptrs (void **ptr
, unsigned n
)
525 for (unsigned i
= 0; i
< n
; i
++)
535 /* Parse STR, saving found tokens into PVALUES and return their number.
536 Tokens are assumed to be delimited by ':'. If APPEND is non-null,
537 append it to every token we find. */
540 parse_env_var (const char *str
, char ***pvalues
, const char *append
)
542 const char *curval
, *nextval
;
546 curval
= strchr (str
, ':');
550 curval
= strchr (curval
+ 1, ':');
553 values
= (char**) xmalloc (num
* sizeof (char*));
555 nextval
= strchr (curval
, ':');
557 nextval
= strchr (curval
, '\0');
559 int append_len
= append
? strlen (append
) : 0;
560 for (i
= 0; i
< num
; i
++)
562 int l
= nextval
- curval
;
563 values
[i
] = (char*) xmalloc (l
+ 1 + append_len
);
564 memcpy (values
[i
], curval
, l
);
567 strcat (values
[i
], append
);
568 curval
= nextval
+ 1;
569 nextval
= strchr (curval
, ':');
571 nextval
= strchr (curval
, '\0');
577 /* Append options OPTS from lto or offload_lto sections to ARGV_OBSTACK. */
580 append_compiler_options (obstack
*argv_obstack
, struct cl_decoded_option
*opts
,
583 /* Append compiler driver arguments as far as they were merged. */
584 for (unsigned int j
= 1; j
< count
; ++j
)
586 struct cl_decoded_option
*option
= &opts
[j
];
588 /* File options have been properly filtered by lto-opts.c. */
589 switch (option
->opt_index
)
591 /* Drop arguments that we want to take from the link line. */
594 case OPT_flto_partition_
:
601 /* For now do what the original LTO option code was doing - pass
602 on any CL_TARGET flag and a few selected others. */
603 switch (option
->opt_index
)
605 case OPT_fdiagnostics_show_caret
:
606 case OPT_fdiagnostics_show_labels
:
607 case OPT_fdiagnostics_show_line_numbers
:
608 case OPT_fdiagnostics_show_option
:
609 case OPT_fdiagnostics_show_location_
:
610 case OPT_fshow_column
:
619 case OPT_fopenacc_dim_
:
620 case OPT_foffload_abi_
:
628 if (!(cl_options
[option
->opt_index
].flags
& CL_TARGET
))
632 /* Pass the option on. */
633 for (unsigned int i
= 0; i
< option
->canonical_option_num_elements
; ++i
)
634 obstack_ptr_grow (argv_obstack
, option
->canonical_option
[i
]);
638 /* Append diag options in OPTS with length COUNT to ARGV_OBSTACK. */
641 append_diag_options (obstack
*argv_obstack
, struct cl_decoded_option
*opts
,
644 /* Append compiler driver arguments as far as they were merged. */
645 for (unsigned int j
= 1; j
< count
; ++j
)
647 struct cl_decoded_option
*option
= &opts
[j
];
649 switch (option
->opt_index
)
651 case OPT_fdiagnostics_color_
:
652 case OPT_fdiagnostics_format_
:
653 case OPT_fdiagnostics_show_caret
:
654 case OPT_fdiagnostics_show_labels
:
655 case OPT_fdiagnostics_show_line_numbers
:
656 case OPT_fdiagnostics_show_option
:
657 case OPT_fdiagnostics_show_location_
:
658 case OPT_fshow_column
:
664 /* Pass the option on. */
665 for (unsigned int i
= 0; i
< option
->canonical_option_num_elements
; ++i
)
666 obstack_ptr_grow (argv_obstack
, option
->canonical_option
[i
]);
671 /* Append linker options OPTS to ARGV_OBSTACK. */
674 append_linker_options (obstack
*argv_obstack
, struct cl_decoded_option
*opts
,
677 /* Append linker driver arguments. Compiler options from the linker
678 driver arguments will override / merge with those from the compiler. */
679 for (unsigned int j
= 1; j
< count
; ++j
)
681 struct cl_decoded_option
*option
= &opts
[j
];
683 /* Do not pass on frontend specific flags not suitable for lto. */
684 if (!(cl_options
[option
->opt_index
].flags
685 & (CL_COMMON
|CL_TARGET
|CL_DRIVER
|CL_LTO
)))
688 switch (option
->opt_index
)
693 /* We've handled these LTO options, do not pass them on. */
698 /* Ignore -fno-XXX form of these options, as otherwise
699 corresponding builtins will not be enabled. */
700 if (option
->value
== 0)
708 /* Pass the option on. */
709 for (unsigned int i
= 0; i
< option
->canonical_option_num_elements
; ++i
)
710 obstack_ptr_grow (argv_obstack
, option
->canonical_option
[i
]);
714 /* Extract options for TARGET offload compiler from OPTIONS and append
715 them to ARGV_OBSTACK. */
718 append_offload_options (obstack
*argv_obstack
, const char *target
,
719 struct cl_decoded_option
*options
,
720 unsigned int options_count
)
722 for (unsigned i
= 0; i
< options_count
; i
++)
724 const char *cur
, *next
, *opts
;
727 struct cl_decoded_option
*option
= &options
[i
];
729 if (option
->opt_index
!= OPT_foffload_
)
732 /* If option argument starts with '-' then no target is specified. That
733 means offload options are specified for all targets, so we need to
735 if (option
->arg
[0] == '-')
739 opts
= strchr (option
->arg
, '=');
740 /* If there are offload targets specified, but no actual options,
741 there is nothing to do here. */
749 next
= strchr (cur
, ',');
752 next
= (next
> opts
) ? opts
: next
;
754 /* Are we looking for this offload target? */
755 if (strlen (target
) == (size_t) (next
- cur
)
756 && strncmp (target
, cur
, next
- cur
) == 0)
759 /* Skip the comma or equal sign. */
769 argv
= buildargv (opts
);
770 for (argc
= 0; argv
[argc
]; argc
++)
771 obstack_ptr_grow (argv_obstack
, argv
[argc
]);
775 /* Check whether NAME can be accessed in MODE. This is like access,
776 except that it never considers directories to be executable. */
779 access_check (const char *name
, int mode
)
785 if (stat (name
, &st
) < 0
786 || S_ISDIR (st
.st_mode
))
790 return access (name
, mode
);
793 /* Prepare a target image for offload TARGET, using mkoffload tool from
794 COMPILER_PATH. Return the name of the resultant object file. */
797 compile_offload_image (const char *target
, const char *compiler_path
,
798 unsigned in_argc
, char *in_argv
[],
799 struct cl_decoded_option
*compiler_opts
,
800 unsigned int compiler_opt_count
,
801 struct cl_decoded_option
*linker_opts
,
802 unsigned int linker_opt_count
)
804 char *filename
= NULL
;
807 = XALLOCAVEC (char, sizeof ("/accel//mkoffload") + strlen (target
));
808 strcpy (suffix
, "/accel/");
809 strcat (suffix
, target
);
810 strcat (suffix
, "/mkoffload");
813 unsigned n_paths
= parse_env_var (compiler_path
, &paths
, suffix
);
815 const char *compiler
= NULL
;
816 for (unsigned i
= 0; i
< n_paths
; i
++)
817 if (access_check (paths
[i
], X_OK
) == 0)
824 fatal_error (input_location
,
825 "could not find %s in %s (consider using %<-B%>)\n",
826 suffix
+ 1, compiler_path
);
828 /* Generate temporary output file name. */
829 filename
= make_temp_file (".target.o");
831 struct obstack argv_obstack
;
832 obstack_init (&argv_obstack
);
833 obstack_ptr_grow (&argv_obstack
, compiler
);
835 obstack_ptr_grow (&argv_obstack
, "-save-temps");
837 obstack_ptr_grow (&argv_obstack
, "-v");
838 obstack_ptr_grow (&argv_obstack
, "-o");
839 obstack_ptr_grow (&argv_obstack
, filename
);
841 /* Append names of input object files. */
842 for (unsigned i
= 0; i
< in_argc
; i
++)
843 obstack_ptr_grow (&argv_obstack
, in_argv
[i
]);
845 /* Append options from offload_lto sections. */
846 append_compiler_options (&argv_obstack
, compiler_opts
,
848 append_diag_options (&argv_obstack
, linker_opts
, linker_opt_count
);
850 /* Append options specified by -foffload last. In case of conflicting
851 options we expect offload compiler to choose the latest. */
852 append_offload_options (&argv_obstack
, target
, compiler_opts
,
854 append_offload_options (&argv_obstack
, target
, linker_opts
,
857 obstack_ptr_grow (&argv_obstack
, NULL
);
858 argv
= XOBFINISH (&argv_obstack
, char **);
859 fork_execute (argv
[0], argv
, true);
860 obstack_free (&argv_obstack
, NULL
);
862 free_array_of_ptrs ((void **) paths
, n_paths
);
867 /* The main routine dealing with offloading.
868 The routine builds a target image for each offload target. IN_ARGC and
869 IN_ARGV specify options and input object files. As all of them could contain
870 target sections, we pass them all to target compilers. */
873 compile_images_for_offload_targets (unsigned in_argc
, char *in_argv
[],
874 struct cl_decoded_option
*compiler_opts
,
875 unsigned int compiler_opt_count
,
876 struct cl_decoded_option
*linker_opts
,
877 unsigned int linker_opt_count
)
880 const char *target_names
= getenv (OFFLOAD_TARGET_NAMES_ENV
);
883 unsigned num_targets
= parse_env_var (target_names
, &names
, NULL
);
885 int next_name_entry
= 0;
886 const char *compiler_path
= getenv ("COMPILER_PATH");
890 /* Prepare an image for each target and save the name of the resultant object
891 file to the OFFLOAD_NAMES array. It is terminated by a NULL entry. */
892 offload_names
= XCNEWVEC (char *, num_targets
+ 1);
893 for (unsigned i
= 0; i
< num_targets
; i
++)
895 /* HSA does not use LTO-like streaming and a different compiler, skip
897 if (strcmp (names
[i
], "hsa") == 0)
900 offload_names
[next_name_entry
]
901 = compile_offload_image (names
[i
], compiler_path
, in_argc
, in_argv
,
902 compiler_opts
, compiler_opt_count
,
903 linker_opts
, linker_opt_count
);
904 if (!offload_names
[next_name_entry
])
905 fatal_error (input_location
,
906 "problem with building target image for %s\n", names
[i
]);
911 free_array_of_ptrs ((void **) names
, num_targets
);
914 /* Copy a file from SRC to DEST. */
917 copy_file (const char *dest
, const char *src
)
919 FILE *d
= fopen (dest
, "wb");
920 FILE *s
= fopen (src
, "rb");
924 size_t len
= fread (buffer
, 1, 512, s
);
926 fatal_error (input_location
, "reading input file");
929 fwrite (buffer
, 1, len
, d
);
931 fatal_error (input_location
, "writing output file");
938 /* Find the crtoffloadtable.o file in LIBRARY_PATH, make copy and pass name of
939 the copy to the linker. */
942 find_crtoffloadtable (void)
945 const char *library_path
= getenv ("LIBRARY_PATH");
948 unsigned n_paths
= parse_env_var (library_path
, &paths
, "/crtoffloadtable.o");
951 for (i
= 0; i
< n_paths
; i
++)
952 if (access_check (paths
[i
], R_OK
) == 0)
954 /* The linker will delete the filename we give it, so make a copy. */
955 char *crtoffloadtable
= make_temp_file (".crtoffloadtable.o");
956 copy_file (crtoffloadtable
, paths
[i
]);
957 printf ("%s\n", crtoffloadtable
);
958 XDELETEVEC (crtoffloadtable
);
962 fatal_error (input_location
,
963 "installation error, can%'t find crtoffloadtable.o");
965 free_array_of_ptrs ((void **) paths
, n_paths
);
968 /* A subroutine of run_gcc. Examine the open file FD for lto sections with
969 name prefix PREFIX, at FILE_OFFSET, and store any options we find in OPTS
970 and OPT_COUNT. Return true if we found a matchingn section, false
971 otherwise. COLLECT_GCC holds the value of the environment variable with
975 find_and_merge_options (int fd
, off_t file_offset
, const char *prefix
,
976 struct cl_decoded_option
**opts
,
977 unsigned int *opt_count
, const char *collect_gcc
)
979 off_t offset
, length
;
984 struct cl_decoded_option
*fdecoded_options
= *opts
;
985 unsigned int fdecoded_options_count
= *opt_count
;
987 simple_object_read
*sobj
;
988 sobj
= simple_object_start_read (fd
, file_offset
, "__GNU_LTO",
993 char *secname
= XALLOCAVEC (char, strlen (prefix
) + sizeof (".opts"));
994 strcpy (secname
, prefix
);
995 strcat (secname
, ".opts");
996 if (!simple_object_find_section (sobj
, secname
, &offset
, &length
,
999 simple_object_release_read (sobj
);
1003 lseek (fd
, file_offset
+ offset
, SEEK_SET
);
1004 data
= (char *)xmalloc (length
);
1005 read (fd
, data
, length
);
1009 struct cl_decoded_option
*f2decoded_options
;
1010 unsigned int f2decoded_options_count
;
1011 get_options_from_collect_gcc_options (collect_gcc
,
1014 &f2decoded_options_count
);
1015 if (!fdecoded_options
)
1017 fdecoded_options
= f2decoded_options
;
1018 fdecoded_options_count
= f2decoded_options_count
;
1021 merge_and_complain (&fdecoded_options
,
1022 &fdecoded_options_count
,
1023 f2decoded_options
, f2decoded_options_count
);
1025 fopts
+= strlen (fopts
) + 1;
1027 while (fopts
- data
< length
);
1030 simple_object_release_read (sobj
);
1031 *opts
= fdecoded_options
;
1032 *opt_count
= fdecoded_options_count
;
1036 /* Copy early debug info sections from INFILE to a new file whose name
1037 is returned. Return NULL on error. */
1040 debug_objcopy (const char *infile
, bool rename
)
1050 if ((p
= strrchr (infile
, '@'))
1052 && sscanf (p
, "@%li%n", &loffset
, &consumed
) >= 1
1053 && strlen (p
) == (unsigned int) consumed
)
1055 char *fname
= xstrdup (infile
);
1056 fname
[p
- infile
] = '\0';
1058 inoff
= (off_t
) loffset
;
1060 int infd
= open (infile
, O_RDONLY
| O_BINARY
);
1063 simple_object_read
*inobj
= simple_object_start_read (infd
, inoff
,
1070 if (simple_object_find_section (inobj
, ".gnu.debuglto_.debug_info",
1071 &off
, &len
, &errmsg
, &err
) != 1)
1074 fatal_error (0, "%s: %s\n", errmsg
, xstrerror (err
));
1076 simple_object_release_read (inobj
);
1083 outfile
= (char *) xmalloc (strlen (infile
)
1084 + sizeof (".debug.temp.o") + 1);
1085 strcpy (outfile
, infile
);
1086 strcat (outfile
, ".debug.temp.o");
1089 outfile
= make_temp_file (".debug.temp.o");
1090 errmsg
= simple_object_copy_lto_debug_sections (inobj
, outfile
, &err
, rename
);
1093 unlink_if_ordinary (outfile
);
1094 fatal_error (0, "%s: %s\n", errmsg
, xstrerror (err
));
1097 simple_object_release_read (inobj
);
1103 /* Helper for qsort: compare priorities for parallel compilation. */
1106 cmp_priority (const void *a
, const void *b
)
1108 return *((const int *)b
)-*((const int *)a
);
1112 /* Execute gcc. ARGC is the number of arguments. ARGV contains the arguments. */
1115 run_gcc (unsigned argc
, char *argv
[])
1118 const char **new_argv
;
1119 const char **argv_ptr
;
1120 char *list_option_full
= NULL
;
1121 const char *linker_output
= NULL
;
1122 const char *collect_gcc
, *collect_gcc_options
;
1125 bool no_partition
= false;
1126 struct cl_decoded_option
*fdecoded_options
= NULL
;
1127 struct cl_decoded_option
*offload_fdecoded_options
= NULL
;
1128 unsigned int fdecoded_options_count
= 0;
1129 unsigned int offload_fdecoded_options_count
= 0;
1130 struct cl_decoded_option
*decoded_options
;
1131 unsigned int decoded_options_count
;
1132 struct obstack argv_obstack
;
1134 bool have_lto
= false;
1135 bool have_offload
= false;
1136 unsigned lto_argc
= 0, ltoobj_argc
= 0;
1137 char **lto_argv
, **ltoobj_argv
;
1138 bool linker_output_rel
= false;
1139 bool skip_debug
= false;
1140 unsigned n_debugobj
;
1142 /* Get the driver and options. */
1143 collect_gcc
= getenv ("COLLECT_GCC");
1145 fatal_error (input_location
,
1146 "environment variable COLLECT_GCC must be set");
1147 collect_gcc_options
= getenv ("COLLECT_GCC_OPTIONS");
1148 if (!collect_gcc_options
)
1149 fatal_error (input_location
,
1150 "environment variable COLLECT_GCC_OPTIONS must be set");
1151 get_options_from_collect_gcc_options (collect_gcc
, collect_gcc_options
,
1154 &decoded_options_count
);
1156 /* Allocate array for input object files with LTO IL,
1157 and for possible preceding arguments. */
1158 lto_argv
= XNEWVEC (char *, argc
);
1159 ltoobj_argv
= XNEWVEC (char *, argc
);
1161 /* Look at saved options in the IL files. */
1162 for (i
= 1; i
< argc
; ++i
)
1166 off_t file_offset
= 0;
1169 char *filename
= argv
[i
];
1171 if (strncmp (argv
[i
], "-foffload-objects=",
1172 sizeof ("-foffload-objects=") - 1) == 0)
1174 have_offload
= true;
1175 offload_objects_file_name
1176 = argv
[i
] + sizeof ("-foffload-objects=") - 1;
1180 if ((p
= strrchr (argv
[i
], '@'))
1182 && sscanf (p
, "@%li%n", &loffset
, &consumed
) >= 1
1183 && strlen (p
) == (unsigned int) consumed
)
1185 filename
= XNEWVEC (char, p
- argv
[i
] + 1);
1186 memcpy (filename
, argv
[i
], p
- argv
[i
]);
1187 filename
[p
- argv
[i
]] = '\0';
1188 file_offset
= (off_t
) loffset
;
1190 fd
= open (filename
, O_RDONLY
| O_BINARY
);
1191 /* Linker plugin passes -fresolution and -flinker-output options.
1192 -flinker-output is passed only when user did not specify one and thus
1193 we do not need to worry about duplicities with the option handling
1197 lto_argv
[lto_argc
++] = argv
[i
];
1198 if (strcmp (argv
[i
], "-flinker-output=rel") == 0)
1199 linker_output_rel
= true;
1203 if (find_and_merge_options (fd
, file_offset
, LTO_SECTION_NAME_PREFIX
,
1204 &fdecoded_options
, &fdecoded_options_count
,
1208 ltoobj_argv
[ltoobj_argc
++] = argv
[i
];
1213 /* Initalize the common arguments for the driver. */
1214 obstack_init (&argv_obstack
);
1215 obstack_ptr_grow (&argv_obstack
, collect_gcc
);
1216 obstack_ptr_grow (&argv_obstack
, "-xlto");
1217 obstack_ptr_grow (&argv_obstack
, "-c");
1219 append_compiler_options (&argv_obstack
, fdecoded_options
,
1220 fdecoded_options_count
);
1221 append_linker_options (&argv_obstack
, decoded_options
, decoded_options_count
);
1223 /* Scan linker driver arguments for things that are of relevance to us. */
1224 for (j
= 1; j
< decoded_options_count
; ++j
)
1226 struct cl_decoded_option
*option
= &decoded_options
[j
];
1227 switch (option
->opt_index
)
1230 linker_output
= option
->arg
;
1233 case OPT_save_temps
:
1241 case OPT_flto_partition_
:
1242 if (strcmp (option
->arg
, "none") == 0)
1243 no_partition
= true;
1247 if (strcmp (option
->arg
, "jobserver") == 0)
1254 parallel
= atoi (option
->arg
);
1261 lto_mode
= LTO_MODE_WHOPR
;
1264 case OPT_flinker_output_
:
1265 linker_output_rel
= !strcmp (option
->arg
, "rel");
1274 /* Output lto-wrapper invocation command. */
1277 for (i
= 0; i
< argc
; ++i
)
1279 fputs (argv
[i
], stderr
);
1280 fputc (' ', stderr
);
1282 fputc ('\n', stderr
);
1285 if (linker_output_rel
)
1286 no_partition
= true;
1290 lto_mode
= LTO_MODE_LTO
;
1297 char *output_dir
, *base
, *name
;
1298 bool bit_bucket
= strcmp (linker_output
, HOST_BIT_BUCKET
) == 0;
1300 output_dir
= xstrdup (linker_output
);
1302 for (name
= base
; *name
; name
++)
1303 if (IS_DIR_SEPARATOR (*name
))
1307 linker_output
= &linker_output
[base
- output_dir
];
1308 if (*output_dir
== '\0')
1310 static char current_dir
[] = { '.', DIR_SEPARATOR
, '\0' };
1311 output_dir
= current_dir
;
1315 obstack_ptr_grow (&argv_obstack
, "-dumpdir");
1316 obstack_ptr_grow (&argv_obstack
, output_dir
);
1319 obstack_ptr_grow (&argv_obstack
, "-dumpbase");
1322 /* Remember at which point we can scrub args to re-use the commons. */
1323 new_head_argc
= obstack_object_size (&argv_obstack
) / sizeof (void *);
1327 unsigned i
, num_offload_files
;
1328 char **offload_argv
;
1331 f
= fopen (offload_objects_file_name
, "r");
1333 fatal_error (input_location
, "cannot open %s: %m",
1334 offload_objects_file_name
);
1335 if (fscanf (f
, "%u ", &num_offload_files
) != 1)
1336 fatal_error (input_location
, "cannot read %s: %m",
1337 offload_objects_file_name
);
1338 offload_argv
= XCNEWVEC (char *, num_offload_files
);
1340 /* Read names of object files with offload. */
1341 for (i
= 0; i
< num_offload_files
; i
++)
1343 const unsigned piece
= 32;
1344 char *buf
, *filename
= XNEWVEC (char, piece
);
1349 if (!fgets (buf
, piece
, f
))
1351 len
= strlen (filename
);
1352 if (filename
[len
- 1] != '\n')
1354 filename
= XRESIZEVEC (char, filename
, len
+ piece
);
1355 buf
= filename
+ len
;
1358 filename
[len
- 1] = '\0';
1359 offload_argv
[i
] = filename
;
1362 if (offload_argv
[num_offload_files
- 1] == NULL
)
1363 fatal_error (input_location
, "invalid format of %s",
1364 offload_objects_file_name
);
1365 maybe_unlink (offload_objects_file_name
);
1366 offload_objects_file_name
= NULL
;
1368 /* Look at saved offload options in files. */
1369 for (i
= 0; i
< num_offload_files
; i
++)
1374 off_t file_offset
= 0;
1375 char *filename
= offload_argv
[i
];
1377 if ((p
= strrchr (offload_argv
[i
], '@'))
1378 && p
!= offload_argv
[i
]
1379 && sscanf (p
, "@%li%n", &loffset
, &consumed
) >= 1
1380 && strlen (p
) == (unsigned int) consumed
)
1382 filename
= XNEWVEC (char, p
- offload_argv
[i
] + 1);
1383 memcpy (filename
, offload_argv
[i
], p
- offload_argv
[i
]);
1384 filename
[p
- offload_argv
[i
]] = '\0';
1385 file_offset
= (off_t
) loffset
;
1387 fd
= open (filename
, O_RDONLY
| O_BINARY
);
1389 fatal_error (input_location
, "cannot open %s: %m", filename
);
1390 if (!find_and_merge_options (fd
, file_offset
,
1391 OFFLOAD_SECTION_NAME_PREFIX
,
1392 &offload_fdecoded_options
,
1393 &offload_fdecoded_options_count
,
1395 fatal_error (input_location
, "cannot read %s: %m", filename
);
1397 if (filename
!= offload_argv
[i
])
1398 XDELETEVEC (filename
);
1401 compile_images_for_offload_targets (num_offload_files
, offload_argv
,
1402 offload_fdecoded_options
,
1403 offload_fdecoded_options_count
,
1405 decoded_options_count
);
1407 free_array_of_ptrs ((void **) offload_argv
, num_offload_files
);
1411 find_crtoffloadtable ();
1412 for (i
= 0; offload_names
[i
]; i
++)
1413 printf ("%s\n", offload_names
[i
]);
1414 free_array_of_ptrs ((void **) offload_names
, i
);
1418 /* If object files contain offload sections, but do not contain LTO sections,
1419 then there is no need to perform a link-time recompilation, i.e.
1420 lto-wrapper is used only for a compilation of offload images. */
1421 if (have_offload
&& !have_lto
)
1424 if (lto_mode
== LTO_MODE_LTO
)
1428 obstack_ptr_grow (&argv_obstack
, linker_output
);
1429 flto_out
= (char *) xmalloc (strlen (linker_output
)
1430 + sizeof (".lto.o") + 1);
1431 strcpy (flto_out
, linker_output
);
1432 strcat (flto_out
, ".lto.o");
1435 flto_out
= make_temp_file (".lto.o");
1436 obstack_ptr_grow (&argv_obstack
, "-o");
1437 obstack_ptr_grow (&argv_obstack
, flto_out
);
1441 const char *list_option
= "-fltrans-output-list=";
1442 size_t list_option_len
= strlen (list_option
);
1447 char *dumpbase
= (char *) xmalloc (strlen (linker_output
)
1448 + sizeof (".wpa") + 1);
1449 strcpy (dumpbase
, linker_output
);
1450 strcat (dumpbase
, ".wpa");
1451 obstack_ptr_grow (&argv_obstack
, dumpbase
);
1454 if (linker_output
&& save_temps
)
1456 ltrans_output_file
= (char *) xmalloc (strlen (linker_output
)
1457 + sizeof (".ltrans.out") + 1);
1458 strcpy (ltrans_output_file
, linker_output
);
1459 strcat (ltrans_output_file
, ".ltrans.out");
1463 char *prefix
= NULL
;
1466 prefix
= (char *) xmalloc (strlen (linker_output
) + 2);
1467 strcpy (prefix
, linker_output
);
1468 strcat (prefix
, ".");
1471 ltrans_output_file
= make_temp_file_with_prefix (prefix
,
1475 list_option_full
= (char *) xmalloc (sizeof (char) *
1476 (strlen (ltrans_output_file
) + list_option_len
+ 1));
1477 tmp
= list_option_full
;
1479 obstack_ptr_grow (&argv_obstack
, tmp
);
1480 strcpy (tmp
, list_option
);
1481 tmp
+= list_option_len
;
1482 strcpy (tmp
, ltrans_output_file
);
1485 obstack_ptr_grow (&argv_obstack
, xstrdup ("-fwpa=jobserver"));
1486 else if (parallel
> 1)
1489 sprintf (buf
, "-fwpa=%i", parallel
);
1490 obstack_ptr_grow (&argv_obstack
, xstrdup (buf
));
1493 obstack_ptr_grow (&argv_obstack
, "-fwpa");
1496 /* Append input arguments. */
1497 for (i
= 0; i
< lto_argc
; ++i
)
1498 obstack_ptr_grow (&argv_obstack
, lto_argv
[i
]);
1499 /* Append the input objects. */
1500 for (i
= 0; i
< ltoobj_argc
; ++i
)
1501 obstack_ptr_grow (&argv_obstack
, ltoobj_argv
[i
]);
1502 obstack_ptr_grow (&argv_obstack
, NULL
);
1504 new_argv
= XOBFINISH (&argv_obstack
, const char **);
1505 argv_ptr
= &new_argv
[new_head_argc
];
1506 fork_execute (new_argv
[0], CONST_CAST (char **, new_argv
), true);
1508 /* Copy the early generated debug info from the objects to temporary
1509 files and append those to the partial link commandline. */
1511 early_debug_object_names
= NULL
;
1514 early_debug_object_names
= XCNEWVEC (const char *, ltoobj_argc
+ 1);
1515 num_deb_objs
= ltoobj_argc
;
1516 for (i
= 0; i
< ltoobj_argc
; ++i
)
1519 if ((tem
= debug_objcopy (ltoobj_argv
[i
], !linker_output_rel
)))
1521 early_debug_object_names
[i
] = tem
;
1527 if (lto_mode
== LTO_MODE_LTO
)
1529 printf ("%s\n", flto_out
);
1532 for (i
= 0; i
< ltoobj_argc
; ++i
)
1533 if (early_debug_object_names
[i
] != NULL
)
1534 printf ("%s\n", early_debug_object_names
[i
]);
1536 /* These now belong to collect2. */
1539 free (early_debug_object_names
);
1540 early_debug_object_names
= NULL
;
1544 FILE *stream
= fopen (ltrans_output_file
, "r");
1545 FILE *mstream
= NULL
;
1546 struct obstack env_obstack
;
1550 fatal_error (input_location
, "fopen: %s: %m", ltrans_output_file
);
1552 /* Parse the list of LTRANS inputs from the WPA stage. */
1553 obstack_init (&env_obstack
);
1557 const unsigned piece
= 32;
1558 char *output_name
= NULL
;
1559 char *buf
, *input_name
= (char *)xmalloc (piece
);
1563 if (fscanf (stream
, "%i\n", &priority
) != 1)
1566 fatal_error (input_location
,
1567 "Corrupted ltrans output file %s",
1568 ltrans_output_file
);
1572 if (!fgets (buf
, piece
, stream
))
1574 len
= strlen (input_name
);
1575 if (input_name
[len
- 1] != '\n')
1577 input_name
= (char *)xrealloc (input_name
, len
+ piece
);
1578 buf
= input_name
+ len
;
1581 input_name
[len
- 1] = '\0';
1583 if (input_name
[0] == '*')
1584 output_name
= &input_name
[1];
1588 = (int *)xrealloc (ltrans_priorities
, nr
* sizeof (int) * 2);
1589 input_names
= (char **)xrealloc (input_names
, nr
* sizeof (char *));
1590 output_names
= (char **)xrealloc (output_names
, nr
* sizeof (char *));
1591 ltrans_priorities
[(nr
-1)*2] = priority
;
1592 ltrans_priorities
[(nr
-1)*2+1] = nr
-1;
1593 input_names
[nr
-1] = input_name
;
1594 output_names
[nr
-1] = output_name
;
1597 maybe_unlink (ltrans_output_file
);
1598 ltrans_output_file
= NULL
;
1602 makefile
= make_temp_file (".mk");
1603 mstream
= fopen (makefile
, "w");
1604 qsort (ltrans_priorities
, nr
, sizeof (int) * 2, cmp_priority
);
1607 /* Execute the LTRANS stage for each input file (or prepare a
1608 makefile to invoke this in parallel). */
1609 for (i
= 0; i
< nr
; ++i
)
1612 char *input_name
= input_names
[i
];
1613 /* If it's a pass-through file do nothing. */
1614 if (output_names
[i
])
1617 /* Replace the .o suffix with a .ltrans.o suffix and write
1618 the resulting name to the LTRANS output list. */
1619 obstack_grow (&env_obstack
, input_name
, strlen (input_name
) - 2);
1620 obstack_grow (&env_obstack
, ".ltrans.o", sizeof (".ltrans.o"));
1621 output_name
= XOBFINISH (&env_obstack
, char *);
1623 /* Adjust the dumpbase if the linker output file was seen. */
1627 = (char *) xmalloc (strlen (linker_output
)
1628 + sizeof (DUMPBASE_SUFFIX
) + 1);
1630 strlen (linker_output
) + sizeof (DUMPBASE_SUFFIX
),
1631 "%s.ltrans%u", linker_output
, i
);
1632 argv_ptr
[0] = dumpbase
;
1635 argv_ptr
[1] = "-fltrans";
1637 argv_ptr
[3] = output_name
;
1638 argv_ptr
[4] = input_name
;
1642 fprintf (mstream
, "%s:\n\t@%s ", output_name
, new_argv
[0]);
1643 for (j
= 1; new_argv
[j
] != NULL
; ++j
)
1644 fprintf (mstream
, " '%s'", new_argv
[j
]);
1645 fprintf (mstream
, "\n");
1646 /* If we are not preserving the ltrans input files then
1647 truncate them as soon as we have processed it. This
1648 reduces temporary disk-space usage. */
1650 fprintf (mstream
, "\t@-touch -r %s %s.tem > /dev/null 2>&1 "
1651 "&& mv %s.tem %s\n",
1652 input_name
, input_name
, input_name
, input_name
);
1656 fork_execute (new_argv
[0], CONST_CAST (char **, new_argv
),
1658 maybe_unlink (input_name
);
1661 output_names
[i
] = output_name
;
1665 struct pex_obj
*pex
;
1671 for (i
= 0; i
< nr
; ++i
)
1673 int j
= ltrans_priorities
[i
*2 + 1];
1674 fprintf (mstream
, " \\\n\t%s", output_names
[j
]);
1676 fprintf (mstream
, "\n");
1680 /* Avoid passing --jobserver-fd= and similar flags
1681 unless jobserver mode is explicitly enabled. */
1682 putenv (xstrdup ("MAKEFLAGS="));
1683 putenv (xstrdup ("MFLAGS="));
1685 new_argv
[0] = getenv ("MAKE");
1687 new_argv
[0] = "make";
1689 new_argv
[2] = makefile
;
1693 snprintf (jobs
, 31, "-j%d", parallel
);
1694 new_argv
[i
++] = jobs
;
1696 new_argv
[i
++] = "all";
1697 new_argv
[i
++] = NULL
;
1698 pex
= collect_execute (new_argv
[0], CONST_CAST (char **, new_argv
),
1699 NULL
, NULL
, PEX_SEARCH
, false);
1700 do_wait (new_argv
[0], pex
);
1701 maybe_unlink (makefile
);
1703 for (i
= 0; i
< nr
; ++i
)
1704 maybe_unlink (input_names
[i
]);
1706 for (i
= 0; i
< nr
; ++i
)
1708 fputs (output_names
[i
], stdout
);
1709 putc ('\n', stdout
);
1710 free (input_names
[i
]);
1714 for (i
= 0; i
< ltoobj_argc
; ++i
)
1715 if (early_debug_object_names
[i
] != NULL
)
1716 printf ("%s\n", early_debug_object_names
[i
]);
1719 free (ltrans_priorities
);
1720 free (output_names
);
1721 output_names
= NULL
;
1722 free (early_debug_object_names
);
1723 early_debug_object_names
= NULL
;
1725 free (list_option_full
);
1726 obstack_free (&env_obstack
, NULL
);
1731 obstack_free (&argv_obstack
, NULL
);
1738 main (int argc
, char *argv
[])
1742 init_opts_obstack ();
1744 p
= argv
[0] + strlen (argv
[0]);
1745 while (p
!= argv
[0] && !IS_DIR_SEPARATOR (p
[-1]))
1749 xmalloc_set_program_name (progname
);
1751 gcc_init_libintl ();
1753 diagnostic_initialize (global_dc
, 0);
1755 if (atexit (lto_wrapper_cleanup
) != 0)
1756 fatal_error (input_location
, "atexit failed");
1758 if (signal (SIGINT
, SIG_IGN
) != SIG_IGN
)
1759 signal (SIGINT
, fatal_signal
);
1761 if (signal (SIGHUP
, SIG_IGN
) != SIG_IGN
)
1762 signal (SIGHUP
, fatal_signal
);
1764 if (signal (SIGTERM
, SIG_IGN
) != SIG_IGN
)
1765 signal (SIGTERM
, fatal_signal
);
1767 if (signal (SIGPIPE
, SIG_IGN
) != SIG_IGN
)
1768 signal (SIGPIPE
, fatal_signal
);
1771 /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
1772 receive the signal. A different setting is inheritable */
1773 signal (SIGCHLD
, SIG_DFL
);
1776 /* We may be called with all the arguments stored in some file and
1777 passed with @file. Expand them into argv before processing. */
1778 expandargv (&argc
, &argv
);
1780 run_gcc (argc
, argv
);