1 /* Wrapper to call lto. Used by collect2 and the linker plugin.
2 Copyright (C) 2009-2014 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"
51 int debug
; /* true if -save-temps. */
52 int verbose
; /* true if -v. */
55 LTO_MODE_NONE
, /* Not doing LTO. */
56 LTO_MODE_LTO
, /* Normal LTO. */
57 LTO_MODE_WHOPR
/* WHOPR. */
60 /* Current LTO mode. */
61 static enum lto_mode_d lto_mode
= LTO_MODE_NONE
;
63 static char *ltrans_output_file
;
64 static char *flto_out
;
65 static char *args_name
;
66 static unsigned int nr
;
67 static char **input_names
;
68 static char **output_names
;
69 static char *makefile
;
71 static void maybe_unlink_file (const char *);
73 /* Delete tempfiles. */
76 lto_wrapper_cleanup (void)
78 static bool cleanup_done
= false;
84 /* Setting cleanup_done prevents an infinite loop if one of the
85 calls to maybe_unlink_file fails. */
88 if (ltrans_output_file
)
89 maybe_unlink_file (ltrans_output_file
);
91 maybe_unlink_file (flto_out
);
93 maybe_unlink_file (args_name
);
95 maybe_unlink_file (makefile
);
96 for (i
= 0; i
< nr
; ++i
)
98 maybe_unlink_file (input_names
[i
]);
100 maybe_unlink_file (output_names
[i
]);
105 fatal_signal (int signum
)
107 signal (signum
, SIG_DFL
);
108 lto_wrapper_cleanup ();
109 /* Get the same signal again, this time not handled,
110 so its normal effect occurs. */
111 kill (getpid (), signum
);
114 /* Execute a program, and wait for the reply. ARGV are the arguments. The
115 last one must be NULL. */
117 static struct pex_obj
*
118 collect_execute (char **argv
)
129 for (p_argv
= argv
; (str
= *p_argv
) != (char *) 0; p_argv
++)
130 fprintf (stderr
, " %s", str
);
132 fprintf (stderr
, "\n");
138 pex
= pex_init (0, "lto-wrapper", NULL
);
140 fatal_error ("pex_init failed: %m");
142 /* Do not use PEX_LAST here, we use our stdout for communicating with
143 collect2 or the linker-plugin. Any output from the sub-process
144 will confuse that. */
145 errmsg
= pex_run (pex
, PEX_SEARCH
, argv
[0], argv
, NULL
,
152 fatal_error ("%s: %m", _(errmsg
));
155 fatal_error (errmsg
);
162 /* Wait for a process to finish, and exit if a nonzero status is found.
163 PROG is the program name. PEX is the process we should wait for. */
166 collect_wait (const char *prog
, struct pex_obj
*pex
)
170 if (!pex_get_status (pex
, 1, &status
))
171 fatal_error ("can't get program status: %m");
176 if (WIFSIGNALED (status
))
178 int sig
= WTERMSIG (status
);
179 if (WCOREDUMP (status
))
180 fatal_error ("%s terminated with signal %d [%s], core dumped",
181 prog
, sig
, strsignal (sig
));
183 fatal_error ("%s terminated with signal %d [%s]",
184 prog
, sig
, strsignal (sig
));
187 if (WIFEXITED (status
))
188 fatal_error ("%s returned %d exit status", prog
, WEXITSTATUS (status
));
195 /* Unlink a temporary LTRANS file unless requested otherwise. */
198 maybe_unlink_file (const char *file
)
202 if (unlink_if_ordinary (file
)
204 fatal_error ("deleting LTRANS file %s: %m", file
);
207 fprintf (stderr
, "[Leaving LTRANS %s]\n", file
);
211 /* Execute program ARGV[0] with arguments ARGV. Wait for it to finish. */
214 fork_execute (char **argv
)
222 args_name
= make_temp_file (".args");
223 at_args
= concat ("@", args_name
, NULL
);
224 args
= fopen (args_name
, "w");
226 fatal_error ("failed to open %s", args_name
);
228 status
= writeargv (&argv
[1], args
);
231 fatal_error ("could not write to temporary file %s", args_name
);
235 new_argv
[0] = argv
[0];
236 new_argv
[1] = at_args
;
239 pex
= collect_execute (new_argv
);
240 collect_wait (new_argv
[0], pex
);
242 maybe_unlink_file (args_name
);
247 /* Template of LTRANS dumpbase suffix. */
248 #define DUMPBASE_SUFFIX ".ltrans18446744073709551615"
250 /* Create decoded options from the COLLECT_GCC and COLLECT_GCC_OPTIONS
251 environment according to LANG_MASK. */
254 get_options_from_collect_gcc_options (const char *collect_gcc
,
255 const char *collect_gcc_options
,
256 unsigned int lang_mask
,
257 struct cl_decoded_option
**decoded_options
,
258 unsigned int *decoded_options_count
)
260 struct obstack argv_obstack
;
265 argv_storage
= xstrdup (collect_gcc_options
);
266 obstack_init (&argv_obstack
);
267 obstack_ptr_grow (&argv_obstack
, collect_gcc
);
269 for (j
= 0, k
= 0; argv_storage
[j
] != '\0'; ++j
)
271 if (argv_storage
[j
] == '\'')
273 obstack_ptr_grow (&argv_obstack
, &argv_storage
[k
]);
277 if (argv_storage
[j
] == '\0')
278 fatal_error ("malformed COLLECT_GCC_OPTIONS");
279 else if (strncmp (&argv_storage
[j
], "'\\''", 4) == 0)
281 argv_storage
[k
++] = '\'';
284 else if (argv_storage
[j
] == '\'')
287 argv_storage
[k
++] = argv_storage
[j
++];
290 argv_storage
[k
++] = '\0';
294 obstack_ptr_grow (&argv_obstack
, NULL
);
295 argc
= obstack_object_size (&argv_obstack
) / sizeof (void *) - 1;
296 argv
= XOBFINISH (&argv_obstack
, const char **);
298 decode_cmdline_options_to_array (argc
, (const char **)argv
,
300 decoded_options
, decoded_options_count
);
301 obstack_free (&argv_obstack
, NULL
);
304 /* Append OPTION to the options array DECODED_OPTIONS with size
305 DECODED_OPTIONS_COUNT. */
308 append_option (struct cl_decoded_option
**decoded_options
,
309 unsigned int *decoded_options_count
,
310 struct cl_decoded_option
*option
)
312 ++*decoded_options_count
;
314 = (struct cl_decoded_option
*)
315 xrealloc (*decoded_options
,
316 (*decoded_options_count
317 * sizeof (struct cl_decoded_option
)));
318 memcpy (&(*decoded_options
)[*decoded_options_count
- 1], option
,
319 sizeof (struct cl_decoded_option
));
322 /* Try to merge and complain about options FDECODED_OPTIONS when applied
323 ontop of DECODED_OPTIONS. */
326 merge_and_complain (struct cl_decoded_option
**decoded_options
,
327 unsigned int *decoded_options_count
,
328 struct cl_decoded_option
*fdecoded_options
,
329 unsigned int fdecoded_options_count
)
333 /* ??? Merge options from files. Most cases can be
334 handled by either unioning or intersecting
335 (for example -fwrapv is a case for unioning,
336 -ffast-math is for intersection). Most complaints
337 about real conflicts between different options can
338 be deferred to the compiler proper. Options that
339 we can neither safely handle by intersection nor
340 unioning would need to be complained about here.
341 Ideally we'd have a flag in the opt files that
342 tells whether to union or intersect or reject.
343 In absence of that it's unclear what a good default is.
344 It's also difficult to get positional handling correct. */
346 /* The following does what the old LTO option code did,
347 union all target and a selected set of common options. */
348 for (i
= 0; i
< fdecoded_options_count
; ++i
)
350 struct cl_decoded_option
*foption
= &fdecoded_options
[i
];
351 switch (foption
->opt_index
)
353 case OPT_SPECIAL_unknown
:
354 case OPT_SPECIAL_ignore
:
355 case OPT_SPECIAL_program_name
:
356 case OPT_SPECIAL_input_file
:
360 if (!(cl_options
[foption
->opt_index
].flags
& CL_TARGET
))
369 case OPT_fexceptions
:
370 case OPT_fnon_call_exceptions
:
372 /* Do what the old LTO code did - collect exactly one option
373 setting per OPT code, we pick the first we encounter.
374 ??? This doesn't make too much sense, but when it doesn't
375 then we should complain. */
376 for (j
= 0; j
< *decoded_options_count
; ++j
)
377 if ((*decoded_options
)[j
].opt_index
== foption
->opt_index
)
379 if (j
== *decoded_options_count
)
380 append_option (decoded_options
, decoded_options_count
, foption
);
384 case OPT_fstrict_overflow
:
385 case OPT_ffp_contract_
:
386 /* For selected options we can merge conservatively. */
387 for (j
= 0; j
< *decoded_options_count
; ++j
)
388 if ((*decoded_options
)[j
].opt_index
== foption
->opt_index
)
390 if (j
== *decoded_options_count
)
391 append_option (decoded_options
, decoded_options_count
, foption
);
392 /* FP_CONTRACT_OFF < FP_CONTRACT_ON < FP_CONTRACT_FAST,
393 -fno-trapv < -ftrapv,
394 -fno-strict-overflow < -fstrict-overflow */
395 else if (foption
->value
< (*decoded_options
)[j
].value
)
396 (*decoded_options
)[j
] = *foption
;
400 /* For selected options we can merge conservatively. */
401 for (j
= 0; j
< *decoded_options_count
; ++j
)
402 if ((*decoded_options
)[j
].opt_index
== foption
->opt_index
)
404 if (j
== *decoded_options_count
)
405 append_option (decoded_options
, decoded_options_count
, foption
);
406 /* -fwrapv > -fno-wrapv. */
407 else if (foption
->value
> (*decoded_options
)[j
].value
)
408 (*decoded_options
)[j
] = *foption
;
411 case OPT_freg_struct_return
:
412 case OPT_fpcc_struct_return
:
413 case OPT_fshort_double
:
414 for (j
= 0; j
< *decoded_options_count
; ++j
)
415 if ((*decoded_options
)[j
].opt_index
== foption
->opt_index
)
417 if (j
== *decoded_options_count
)
418 fatal_error ("Option %s not used consistently in all LTO input"
419 " files", foption
->orig_option_with_args_text
);
426 for (j
= 0; j
< *decoded_options_count
; ++j
)
427 if ((*decoded_options
)[j
].opt_index
== OPT_O
428 || (*decoded_options
)[j
].opt_index
== OPT_Ofast
429 || (*decoded_options
)[j
].opt_index
== OPT_Og
430 || (*decoded_options
)[j
].opt_index
== OPT_Os
)
432 if (j
== *decoded_options_count
)
433 append_option (decoded_options
, decoded_options_count
, foption
);
434 else if ((*decoded_options
)[j
].opt_index
== foption
->opt_index
435 && foption
->opt_index
!= OPT_O
)
436 /* Exact same options get merged. */
440 /* For mismatched option kinds preserve the optimization
441 level only, thus merge it as -On. This also handles
442 merging of same optimization level -On. */
444 switch (foption
->opt_index
)
447 if (foption
->arg
[0] == '\0')
448 level
= MAX (level
, 1);
450 level
= MAX (level
, atoi (foption
->arg
));
453 level
= MAX (level
, 3);
456 level
= MAX (level
, 1);
459 level
= MAX (level
, 2);
464 switch ((*decoded_options
)[j
].opt_index
)
467 if ((*decoded_options
)[j
].arg
[0] == '\0')
468 level
= MAX (level
, 1);
470 level
= MAX (level
, atoi ((*decoded_options
)[j
].arg
));
473 level
= MAX (level
, 3);
476 level
= MAX (level
, 1);
479 level
= MAX (level
, 2);
484 (*decoded_options
)[j
].opt_index
= OPT_O
;
486 asprintf (&tem
, "-O%d", level
);
487 (*decoded_options
)[j
].arg
= &tem
[2];
488 (*decoded_options
)[j
].canonical_option
[0] = tem
;
489 (*decoded_options
)[j
].value
= 1;
496 /* Execute gcc. ARGC is the number of arguments. ARGV contains the arguments. */
499 run_gcc (unsigned argc
, char *argv
[])
502 const char **new_argv
;
503 const char **argv_ptr
;
504 char *list_option_full
= NULL
;
505 const char *linker_output
= NULL
;
506 const char *collect_gcc
, *collect_gcc_options
;
509 bool no_partition
= false;
510 struct cl_decoded_option
*fdecoded_options
= NULL
;
511 unsigned int fdecoded_options_count
= 0;
512 struct cl_decoded_option
*decoded_options
;
513 unsigned int decoded_options_count
;
514 struct obstack argv_obstack
;
517 /* Get the driver and options. */
518 collect_gcc
= getenv ("COLLECT_GCC");
520 fatal_error ("environment variable COLLECT_GCC must be set");
521 collect_gcc_options
= getenv ("COLLECT_GCC_OPTIONS");
522 if (!collect_gcc_options
)
523 fatal_error ("environment variable COLLECT_GCC_OPTIONS must be set");
524 get_options_from_collect_gcc_options (collect_gcc
, collect_gcc_options
,
527 &decoded_options_count
);
529 /* Look at saved options in the IL files. */
530 for (i
= 1; i
< argc
; ++i
)
537 off_t file_offset
= 0, offset
, length
;
539 simple_object_read
*sobj
;
541 struct cl_decoded_option
*f2decoded_options
;
542 unsigned int f2decoded_options_count
;
543 char *filename
= argv
[i
];
544 if ((p
= strrchr (argv
[i
], '@'))
546 && sscanf (p
, "@%li%n", &loffset
, &consumed
) >= 1
547 && strlen (p
) == (unsigned int) consumed
)
549 filename
= XNEWVEC (char, p
- argv
[i
] + 1);
550 memcpy (filename
, argv
[i
], p
- argv
[i
]);
551 filename
[p
- argv
[i
]] = '\0';
552 file_offset
= (off_t
) loffset
;
554 fd
= open (argv
[i
], O_RDONLY
);
557 sobj
= simple_object_start_read (fd
, file_offset
, "__GNU_LTO",
564 if (!simple_object_find_section (sobj
, LTO_SECTION_NAME_PREFIX
"." "opts",
565 &offset
, &length
, &errmsg
, &err
))
567 simple_object_release_read (sobj
);
571 lseek (fd
, file_offset
+ offset
, SEEK_SET
);
572 data
= (char *)xmalloc (length
);
573 read (fd
, data
, length
);
577 get_options_from_collect_gcc_options (collect_gcc
,
580 &f2decoded_options_count
);
581 if (!fdecoded_options
)
583 fdecoded_options
= f2decoded_options
;
584 fdecoded_options_count
= f2decoded_options_count
;
587 merge_and_complain (&fdecoded_options
,
588 &fdecoded_options_count
,
589 f2decoded_options
, f2decoded_options_count
);
591 fopts
+= strlen (fopts
) + 1;
593 while (fopts
- data
< length
);
596 simple_object_release_read (sobj
);
600 /* Initalize the common arguments for the driver. */
601 obstack_init (&argv_obstack
);
602 obstack_ptr_grow (&argv_obstack
, collect_gcc
);
603 obstack_ptr_grow (&argv_obstack
, "-xlto");
604 obstack_ptr_grow (&argv_obstack
, "-c");
606 /* Append compiler driver arguments as far as they were merged. */
607 for (j
= 1; j
< fdecoded_options_count
; ++j
)
609 struct cl_decoded_option
*option
= &fdecoded_options
[j
];
611 /* File options have been properly filtered by lto-opts.c. */
612 switch (option
->opt_index
)
614 /* Drop arguments that we want to take from the link line. */
617 case OPT_flto_partition_
:
624 /* For now do what the original LTO option code was doing - pass
625 on any CL_TARGET flag and a few selected others. */
626 switch (option
->opt_index
)
633 case OPT_fexceptions
:
634 case OPT_fnon_call_exceptions
:
636 case OPT_freg_struct_return
:
637 case OPT_fpcc_struct_return
:
638 case OPT_fshort_double
:
639 case OPT_ffp_contract_
:
642 case OPT_fstrict_overflow
:
650 if (!(cl_options
[option
->opt_index
].flags
& CL_TARGET
))
654 /* Pass the option on. */
655 for (i
= 0; i
< option
->canonical_option_num_elements
; ++i
)
656 obstack_ptr_grow (&argv_obstack
, option
->canonical_option
[i
]);
659 /* Append linker driver arguments. Compiler options from the linker
660 driver arguments will override / merge with those from the compiler. */
661 for (j
= 1; j
< decoded_options_count
; ++j
)
663 struct cl_decoded_option
*option
= &decoded_options
[j
];
665 /* Do not pass on frontend specific flags not suitable for lto. */
666 if (!(cl_options
[option
->opt_index
].flags
667 & (CL_COMMON
|CL_TARGET
|CL_DRIVER
|CL_LTO
)))
670 switch (option
->opt_index
)
673 linker_output
= option
->arg
;
674 /* We generate new intermediate output, drop this arg. */
685 case OPT_flto_partition_
:
686 if (strcmp (option
->arg
, "none") == 0)
691 if (strcmp (option
->arg
, "jobserver") == 0)
698 parallel
= atoi (option
->arg
);
705 lto_mode
= LTO_MODE_WHOPR
;
706 /* We've handled these LTO options, do not pass them on. */
709 case OPT_freg_struct_return
:
710 case OPT_fpcc_struct_return
:
711 case OPT_fshort_double
:
712 /* Ignore these, they are determined by the input files.
713 ??? We fail to diagnose a possible mismatch here. */
720 /* Pass the option on. */
721 for (i
= 0; i
< option
->canonical_option_num_elements
; ++i
)
722 obstack_ptr_grow (&argv_obstack
, option
->canonical_option
[i
]);
727 lto_mode
= LTO_MODE_LTO
;
734 char *output_dir
, *base
, *name
;
735 bool bit_bucket
= strcmp (linker_output
, HOST_BIT_BUCKET
) == 0;
737 output_dir
= xstrdup (linker_output
);
739 for (name
= base
; *name
; name
++)
740 if (IS_DIR_SEPARATOR (*name
))
744 linker_output
= &linker_output
[base
- output_dir
];
745 if (*output_dir
== '\0')
747 static char current_dir
[] = { '.', DIR_SEPARATOR
, '\0' };
748 output_dir
= current_dir
;
752 obstack_ptr_grow (&argv_obstack
, "-dumpdir");
753 obstack_ptr_grow (&argv_obstack
, output_dir
);
756 obstack_ptr_grow (&argv_obstack
, "-dumpbase");
759 /* Remember at which point we can scrub args to re-use the commons. */
760 new_head_argc
= obstack_object_size (&argv_obstack
) / sizeof (void *);
762 if (lto_mode
== LTO_MODE_LTO
)
764 flto_out
= make_temp_file (".lto.o");
766 obstack_ptr_grow (&argv_obstack
, linker_output
);
767 obstack_ptr_grow (&argv_obstack
, "-o");
768 obstack_ptr_grow (&argv_obstack
, flto_out
);
772 const char *list_option
= "-fltrans-output-list=";
773 size_t list_option_len
= strlen (list_option
);
778 char *dumpbase
= (char *) xmalloc (strlen (linker_output
)
779 + sizeof (".wpa") + 1);
780 strcpy (dumpbase
, linker_output
);
781 strcat (dumpbase
, ".wpa");
782 obstack_ptr_grow (&argv_obstack
, dumpbase
);
785 if (linker_output
&& debug
)
787 ltrans_output_file
= (char *) xmalloc (strlen (linker_output
)
788 + sizeof (".ltrans.out") + 1);
789 strcpy (ltrans_output_file
, linker_output
);
790 strcat (ltrans_output_file
, ".ltrans.out");
793 ltrans_output_file
= make_temp_file (".ltrans.out");
794 list_option_full
= (char *) xmalloc (sizeof (char) *
795 (strlen (ltrans_output_file
) + list_option_len
+ 1));
796 tmp
= list_option_full
;
798 obstack_ptr_grow (&argv_obstack
, tmp
);
799 strcpy (tmp
, list_option
);
800 tmp
+= list_option_len
;
801 strcpy (tmp
, ltrans_output_file
);
804 obstack_ptr_grow (&argv_obstack
, xstrdup ("-fwpa=jobserver"));
805 else if (parallel
> 1)
808 sprintf (buf
, "-fwpa=%i", parallel
);
809 obstack_ptr_grow (&argv_obstack
, xstrdup (buf
));
812 obstack_ptr_grow (&argv_obstack
, "-fwpa");
815 /* Append the input objects and possible preceding arguments. */
816 for (i
= 1; i
< argc
; ++i
)
817 obstack_ptr_grow (&argv_obstack
, argv
[i
]);
818 obstack_ptr_grow (&argv_obstack
, NULL
);
820 new_argv
= XOBFINISH (&argv_obstack
, const char **);
821 argv_ptr
= &new_argv
[new_head_argc
];
822 fork_execute (CONST_CAST (char **, new_argv
));
824 if (lto_mode
== LTO_MODE_LTO
)
826 printf ("%s\n", flto_out
);
832 FILE *stream
= fopen (ltrans_output_file
, "r");
833 FILE *mstream
= NULL
;
834 struct obstack env_obstack
;
837 fatal_error ("fopen: %s: %m", ltrans_output_file
);
839 /* Parse the list of LTRANS inputs from the WPA stage. */
840 obstack_init (&env_obstack
);
844 const unsigned piece
= 32;
845 char *output_name
= NULL
;
846 char *buf
, *input_name
= (char *)xmalloc (piece
);
851 if (!fgets (buf
, piece
, stream
))
853 len
= strlen (input_name
);
854 if (input_name
[len
- 1] != '\n')
856 input_name
= (char *)xrealloc (input_name
, len
+ piece
);
857 buf
= input_name
+ len
;
860 input_name
[len
- 1] = '\0';
862 if (input_name
[0] == '*')
863 output_name
= &input_name
[1];
866 input_names
= (char **)xrealloc (input_names
, nr
* sizeof (char *));
867 output_names
= (char **)xrealloc (output_names
, nr
* sizeof (char *));
868 input_names
[nr
-1] = input_name
;
869 output_names
[nr
-1] = output_name
;
872 maybe_unlink_file (ltrans_output_file
);
873 ltrans_output_file
= NULL
;
877 makefile
= make_temp_file (".mk");
878 mstream
= fopen (makefile
, "w");
881 /* Execute the LTRANS stage for each input file (or prepare a
882 makefile to invoke this in parallel). */
883 for (i
= 0; i
< nr
; ++i
)
886 char *input_name
= input_names
[i
];
887 /* If it's a pass-through file do nothing. */
891 /* Replace the .o suffix with a .ltrans.o suffix and write
892 the resulting name to the LTRANS output list. */
893 obstack_grow (&env_obstack
, input_name
, strlen (input_name
) - 2);
894 obstack_grow (&env_obstack
, ".ltrans.o", sizeof (".ltrans.o"));
895 output_name
= XOBFINISH (&env_obstack
, char *);
897 /* Adjust the dumpbase if the linker output file was seen. */
901 = (char *) xmalloc (strlen (linker_output
)
902 + sizeof (DUMPBASE_SUFFIX
) + 1);
904 strlen (linker_output
) + sizeof (DUMPBASE_SUFFIX
),
905 "%s.ltrans%u", linker_output
, i
);
906 argv_ptr
[0] = dumpbase
;
909 argv_ptr
[1] = "-fltrans";
911 argv_ptr
[3] = output_name
;
912 argv_ptr
[4] = input_name
;
916 fprintf (mstream
, "%s:\n\t@%s ", output_name
, new_argv
[0]);
917 for (j
= 1; new_argv
[j
] != NULL
; ++j
)
918 fprintf (mstream
, " '%s'", new_argv
[j
]);
919 fprintf (mstream
, "\n");
920 /* If we are not preserving the ltrans input files then
921 truncate them as soon as we have processed it. This
922 reduces temporary disk-space usage. */
924 fprintf (mstream
, "\t@-touch -r %s %s.tem > /dev/null 2>&1 "
926 input_name
, input_name
, input_name
, input_name
);
930 fork_execute (CONST_CAST (char **, new_argv
));
931 maybe_unlink_file (input_name
);
934 output_names
[i
] = output_name
;
941 fprintf (mstream
, "all:");
942 for (i
= 0; i
< nr
; ++i
)
943 fprintf (mstream
, " \\\n\t%s", output_names
[i
]);
944 fprintf (mstream
, "\n");
948 /* Avoid passing --jobserver-fd= and similar flags
949 unless jobserver mode is explicitly enabled. */
950 putenv (xstrdup ("MAKEFLAGS="));
951 putenv (xstrdup ("MFLAGS="));
953 new_argv
[0] = getenv ("MAKE");
955 new_argv
[0] = "make";
957 new_argv
[2] = makefile
;
961 snprintf (jobs
, 31, "-j%d", parallel
);
962 new_argv
[i
++] = jobs
;
964 new_argv
[i
++] = "all";
965 new_argv
[i
++] = NULL
;
966 pex
= collect_execute (CONST_CAST (char **, new_argv
));
967 collect_wait (new_argv
[0], pex
);
968 maybe_unlink_file (makefile
);
970 for (i
= 0; i
< nr
; ++i
)
971 maybe_unlink_file (input_names
[i
]);
973 for (i
= 0; i
< nr
; ++i
)
975 fputs (output_names
[i
], stdout
);
977 free (input_names
[i
]);
982 free (list_option_full
);
983 obstack_free (&env_obstack
, NULL
);
986 obstack_free (&argv_obstack
, NULL
);
993 main (int argc
, char *argv
[])
997 gcc_obstack_init (&opts_obstack
);
999 p
= argv
[0] + strlen (argv
[0]);
1000 while (p
!= argv
[0] && !IS_DIR_SEPARATOR (p
[-1]))
1004 xmalloc_set_program_name (progname
);
1006 if (atexit (lto_wrapper_cleanup
) != 0)
1007 fatal_error ("atexit failed");
1009 gcc_init_libintl ();
1011 diagnostic_initialize (global_dc
, 0);
1013 if (signal (SIGINT
, SIG_IGN
) != SIG_IGN
)
1014 signal (SIGINT
, fatal_signal
);
1016 if (signal (SIGHUP
, SIG_IGN
) != SIG_IGN
)
1017 signal (SIGHUP
, fatal_signal
);
1019 if (signal (SIGTERM
, SIG_IGN
) != SIG_IGN
)
1020 signal (SIGTERM
, fatal_signal
);
1022 if (signal (SIGPIPE
, SIG_IGN
) != SIG_IGN
)
1023 signal (SIGPIPE
, fatal_signal
);
1026 /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
1027 receive the signal. A different setting is inheritable */
1028 signal (SIGCHLD
, SIG_DFL
);
1031 /* We may be called with all the arguments stored in some file and
1032 passed with @file. Expand them into argv before processing. */
1033 expandargv (&argc
, &argv
);
1035 run_gcc (argc
, argv
);