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 /* Just die. CMSGID is the error message. */
116 static void __attribute__ ((format (printf
, 1, 2)))
117 fatal (const char * cmsgid
, ...)
121 va_start (ap
, cmsgid
);
122 fprintf (stderr
, "lto-wrapper: ");
123 vfprintf (stderr
, _(cmsgid
), ap
);
124 fprintf (stderr
, "\n");
127 lto_wrapper_cleanup ();
128 exit (FATAL_EXIT_CODE
);
132 /* Die when sys call fails. CMSGID is the error message. */
134 static void __attribute__ ((format (printf
, 1, 2)))
135 fatal_perror (const char *cmsgid
, ...)
140 va_start (ap
, cmsgid
);
141 fprintf (stderr
, "lto-wrapper: ");
142 vfprintf (stderr
, _(cmsgid
), ap
);
143 fprintf (stderr
, ": %s\n", xstrerror (e
));
146 lto_wrapper_cleanup ();
147 exit (FATAL_EXIT_CODE
);
151 /* Execute a program, and wait for the reply. ARGV are the arguments. The
152 last one must be NULL. */
154 static struct pex_obj
*
155 collect_execute (char **argv
)
166 for (p_argv
= argv
; (str
= *p_argv
) != (char *) 0; p_argv
++)
167 fprintf (stderr
, " %s", str
);
169 fprintf (stderr
, "\n");
175 pex
= pex_init (0, "lto-wrapper", NULL
);
177 fatal_perror ("pex_init failed");
179 /* Do not use PEX_LAST here, we use our stdout for communicating with
180 collect2 or the linker-plugin. Any output from the sub-process
181 will confuse that. */
182 errmsg
= pex_run (pex
, PEX_SEARCH
, argv
[0], argv
, NULL
,
189 fatal_perror (errmsg
);
199 /* Wait for a process to finish, and exit if a nonzero status is found.
200 PROG is the program name. PEX is the process we should wait for. */
203 collect_wait (const char *prog
, struct pex_obj
*pex
)
207 if (!pex_get_status (pex
, 1, &status
))
208 fatal_perror ("can't get program status");
213 if (WIFSIGNALED (status
))
215 int sig
= WTERMSIG (status
);
216 if (WCOREDUMP (status
))
217 fatal ("%s terminated with signal %d [%s], core dumped",
218 prog
, sig
, strsignal (sig
));
220 fatal ("%s terminated with signal %d [%s]",
221 prog
, sig
, strsignal (sig
));
224 if (WIFEXITED (status
))
225 fatal ("%s returned %d exit status", prog
, WEXITSTATUS (status
));
232 /* Unlink a temporary LTRANS file unless requested otherwise. */
235 maybe_unlink_file (const char *file
)
239 if (unlink_if_ordinary (file
)
241 fatal_perror ("deleting LTRANS file %s", file
);
244 fprintf (stderr
, "[Leaving LTRANS %s]\n", file
);
248 /* Execute program ARGV[0] with arguments ARGV. Wait for it to finish. */
251 fork_execute (char **argv
)
259 args_name
= make_temp_file (".args");
260 at_args
= concat ("@", args_name
, NULL
);
261 args
= fopen (args_name
, "w");
263 fatal ("failed to open %s", args_name
);
265 status
= writeargv (&argv
[1], args
);
268 fatal ("could not write to temporary file %s", args_name
);
272 new_argv
[0] = argv
[0];
273 new_argv
[1] = at_args
;
276 pex
= collect_execute (new_argv
);
277 collect_wait (new_argv
[0], pex
);
279 maybe_unlink_file (args_name
);
284 /* Template of LTRANS dumpbase suffix. */
285 #define DUMPBASE_SUFFIX ".ltrans18446744073709551615"
287 /* Create decoded options from the COLLECT_GCC and COLLECT_GCC_OPTIONS
288 environment according to LANG_MASK. */
291 get_options_from_collect_gcc_options (const char *collect_gcc
,
292 const char *collect_gcc_options
,
293 unsigned int lang_mask
,
294 struct cl_decoded_option
**decoded_options
,
295 unsigned int *decoded_options_count
)
297 struct obstack argv_obstack
;
302 argv_storage
= xstrdup (collect_gcc_options
);
303 obstack_init (&argv_obstack
);
304 obstack_ptr_grow (&argv_obstack
, collect_gcc
);
306 for (j
= 0, k
= 0; argv_storage
[j
] != '\0'; ++j
)
308 if (argv_storage
[j
] == '\'')
310 obstack_ptr_grow (&argv_obstack
, &argv_storage
[k
]);
314 if (argv_storage
[j
] == '\0')
315 fatal ("malformed COLLECT_GCC_OPTIONS");
316 else if (strncmp (&argv_storage
[j
], "'\\''", 4) == 0)
318 argv_storage
[k
++] = '\'';
321 else if (argv_storage
[j
] == '\'')
324 argv_storage
[k
++] = argv_storage
[j
++];
327 argv_storage
[k
++] = '\0';
331 obstack_ptr_grow (&argv_obstack
, NULL
);
332 argc
= obstack_object_size (&argv_obstack
) / sizeof (void *) - 1;
333 argv
= XOBFINISH (&argv_obstack
, const char **);
335 decode_cmdline_options_to_array (argc
, (const char **)argv
,
337 decoded_options
, decoded_options_count
);
338 obstack_free (&argv_obstack
, NULL
);
341 /* Append OPTION to the options array DECODED_OPTIONS with size
342 DECODED_OPTIONS_COUNT. */
345 append_option (struct cl_decoded_option
**decoded_options
,
346 unsigned int *decoded_options_count
,
347 struct cl_decoded_option
*option
)
349 ++*decoded_options_count
;
351 = (struct cl_decoded_option
*)
352 xrealloc (*decoded_options
,
353 (*decoded_options_count
354 * sizeof (struct cl_decoded_option
)));
355 memcpy (&(*decoded_options
)[*decoded_options_count
- 1], option
,
356 sizeof (struct cl_decoded_option
));
359 /* Try to merge and complain about options FDECODED_OPTIONS when applied
360 ontop of DECODED_OPTIONS. */
363 merge_and_complain (struct cl_decoded_option
**decoded_options
,
364 unsigned int *decoded_options_count
,
365 struct cl_decoded_option
*fdecoded_options
,
366 unsigned int fdecoded_options_count
)
370 /* ??? Merge options from files. Most cases can be
371 handled by either unioning or intersecting
372 (for example -fwrapv is a case for unioning,
373 -ffast-math is for intersection). Most complaints
374 about real conflicts between different options can
375 be deferred to the compiler proper. Options that
376 we can neither safely handle by intersection nor
377 unioning would need to be complained about here.
378 Ideally we'd have a flag in the opt files that
379 tells whether to union or intersect or reject.
380 In absence of that it's unclear what a good default is.
381 It's also difficult to get positional handling correct. */
383 /* The following does what the old LTO option code did,
384 union all target and a selected set of common options. */
385 for (i
= 0; i
< fdecoded_options_count
; ++i
)
387 struct cl_decoded_option
*foption
= &fdecoded_options
[i
];
388 switch (foption
->opt_index
)
390 case OPT_SPECIAL_unknown
:
391 case OPT_SPECIAL_ignore
:
392 case OPT_SPECIAL_program_name
:
393 case OPT_SPECIAL_input_file
:
397 if (!(cl_options
[foption
->opt_index
].flags
& CL_TARGET
))
406 case OPT_fexceptions
:
407 case OPT_fnon_call_exceptions
:
409 /* Do what the old LTO code did - collect exactly one option
410 setting per OPT code, we pick the first we encounter.
411 ??? This doesn't make too much sense, but when it doesn't
412 then we should complain. */
413 for (j
= 0; j
< *decoded_options_count
; ++j
)
414 if ((*decoded_options
)[j
].opt_index
== foption
->opt_index
)
416 if (j
== *decoded_options_count
)
417 append_option (decoded_options
, decoded_options_count
, foption
);
421 case OPT_fstrict_overflow
:
422 case OPT_ffp_contract_
:
423 /* For selected options we can merge conservatively. */
424 for (j
= 0; j
< *decoded_options_count
; ++j
)
425 if ((*decoded_options
)[j
].opt_index
== foption
->opt_index
)
427 if (j
== *decoded_options_count
)
428 append_option (decoded_options
, decoded_options_count
, foption
);
429 /* FP_CONTRACT_OFF < FP_CONTRACT_ON < FP_CONTRACT_FAST,
430 -fno-trapv < -ftrapv,
431 -fno-strict-overflow < -fstrict-overflow */
432 else if (foption
->value
< (*decoded_options
)[j
].value
)
433 (*decoded_options
)[j
] = *foption
;
437 /* For selected options we can merge conservatively. */
438 for (j
= 0; j
< *decoded_options_count
; ++j
)
439 if ((*decoded_options
)[j
].opt_index
== foption
->opt_index
)
441 if (j
== *decoded_options_count
)
442 append_option (decoded_options
, decoded_options_count
, foption
);
443 /* -fwrapv > -fno-wrapv. */
444 else if (foption
->value
> (*decoded_options
)[j
].value
)
445 (*decoded_options
)[j
] = *foption
;
448 case OPT_freg_struct_return
:
449 case OPT_fpcc_struct_return
:
450 case OPT_fshort_double
:
451 for (j
= 0; j
< *decoded_options_count
; ++j
)
452 if ((*decoded_options
)[j
].opt_index
== foption
->opt_index
)
454 if (j
== *decoded_options_count
)
455 fatal ("Option %s not used consistently in all LTO input files",
456 foption
->orig_option_with_args_text
);
463 for (j
= 0; j
< *decoded_options_count
; ++j
)
464 if ((*decoded_options
)[j
].opt_index
== OPT_O
465 || (*decoded_options
)[j
].opt_index
== OPT_Ofast
466 || (*decoded_options
)[j
].opt_index
== OPT_Og
467 || (*decoded_options
)[j
].opt_index
== OPT_Os
)
469 if (j
== *decoded_options_count
)
470 append_option (decoded_options
, decoded_options_count
, foption
);
471 else if ((*decoded_options
)[j
].opt_index
== foption
->opt_index
472 && foption
->opt_index
!= OPT_O
)
473 /* Exact same options get merged. */
477 /* For mismatched option kinds preserve the optimization
478 level only, thus merge it as -On. This also handles
479 merging of same optimization level -On. */
481 switch (foption
->opt_index
)
484 if (foption
->arg
[0] == '\0')
485 level
= MAX (level
, 1);
487 level
= MAX (level
, atoi (foption
->arg
));
490 level
= MAX (level
, 3);
493 level
= MAX (level
, 1);
496 level
= MAX (level
, 2);
501 switch ((*decoded_options
)[j
].opt_index
)
504 if ((*decoded_options
)[j
].arg
[0] == '\0')
505 level
= MAX (level
, 1);
507 level
= MAX (level
, atoi ((*decoded_options
)[j
].arg
));
510 level
= MAX (level
, 3);
513 level
= MAX (level
, 1);
516 level
= MAX (level
, 2);
521 (*decoded_options
)[j
].opt_index
= OPT_O
;
523 asprintf (&tem
, "-O%d", level
);
524 (*decoded_options
)[j
].arg
= &tem
[2];
525 (*decoded_options
)[j
].canonical_option
[0] = tem
;
526 (*decoded_options
)[j
].value
= 1;
533 /* Execute gcc. ARGC is the number of arguments. ARGV contains the arguments. */
536 run_gcc (unsigned argc
, char *argv
[])
539 const char **new_argv
;
540 const char **argv_ptr
;
541 char *list_option_full
= NULL
;
542 const char *linker_output
= NULL
;
543 const char *collect_gcc
, *collect_gcc_options
;
546 bool no_partition
= false;
547 struct cl_decoded_option
*fdecoded_options
= NULL
;
548 unsigned int fdecoded_options_count
= 0;
549 struct cl_decoded_option
*decoded_options
;
550 unsigned int decoded_options_count
;
551 struct obstack argv_obstack
;
554 /* Get the driver and options. */
555 collect_gcc
= getenv ("COLLECT_GCC");
557 fatal ("environment variable COLLECT_GCC must be set");
558 collect_gcc_options
= getenv ("COLLECT_GCC_OPTIONS");
559 if (!collect_gcc_options
)
560 fatal ("environment variable COLLECT_GCC_OPTIONS must be set");
561 get_options_from_collect_gcc_options (collect_gcc
, collect_gcc_options
,
564 &decoded_options_count
);
566 /* Look at saved options in the IL files. */
567 for (i
= 1; i
< argc
; ++i
)
574 off_t file_offset
= 0, offset
, length
;
576 simple_object_read
*sobj
;
578 struct cl_decoded_option
*f2decoded_options
;
579 unsigned int f2decoded_options_count
;
580 char *filename
= argv
[i
];
581 if ((p
= strrchr (argv
[i
], '@'))
583 && sscanf (p
, "@%li%n", &loffset
, &consumed
) >= 1
584 && strlen (p
) == (unsigned int) consumed
)
586 filename
= XNEWVEC (char, p
- argv
[i
] + 1);
587 memcpy (filename
, argv
[i
], p
- argv
[i
]);
588 filename
[p
- argv
[i
]] = '\0';
589 file_offset
= (off_t
) loffset
;
591 fd
= open (argv
[i
], O_RDONLY
);
594 sobj
= simple_object_start_read (fd
, file_offset
, "__GNU_LTO",
601 if (!simple_object_find_section (sobj
, LTO_SECTION_NAME_PREFIX
"." "opts",
602 &offset
, &length
, &errmsg
, &err
))
604 simple_object_release_read (sobj
);
608 lseek (fd
, file_offset
+ offset
, SEEK_SET
);
609 data
= (char *)xmalloc (length
);
610 read (fd
, data
, length
);
614 get_options_from_collect_gcc_options (collect_gcc
,
617 &f2decoded_options_count
);
618 if (!fdecoded_options
)
620 fdecoded_options
= f2decoded_options
;
621 fdecoded_options_count
= f2decoded_options_count
;
624 merge_and_complain (&fdecoded_options
,
625 &fdecoded_options_count
,
626 f2decoded_options
, f2decoded_options_count
);
628 fopts
+= strlen (fopts
) + 1;
630 while (fopts
- data
< length
);
633 simple_object_release_read (sobj
);
637 /* Initalize the common arguments for the driver. */
638 obstack_init (&argv_obstack
);
639 obstack_ptr_grow (&argv_obstack
, collect_gcc
);
640 obstack_ptr_grow (&argv_obstack
, "-xlto");
641 obstack_ptr_grow (&argv_obstack
, "-c");
643 /* Append compiler driver arguments as far as they were merged. */
644 for (j
= 1; j
< fdecoded_options_count
; ++j
)
646 struct cl_decoded_option
*option
= &fdecoded_options
[j
];
648 /* File options have been properly filtered by lto-opts.c. */
649 switch (option
->opt_index
)
651 /* Drop arguments that we want to take from the link line. */
654 case OPT_flto_partition_
:
661 /* For now do what the original LTO option code was doing - pass
662 on any CL_TARGET flag and a few selected others. */
663 switch (option
->opt_index
)
670 case OPT_fexceptions
:
671 case OPT_fnon_call_exceptions
:
673 case OPT_freg_struct_return
:
674 case OPT_fpcc_struct_return
:
675 case OPT_fshort_double
:
676 case OPT_ffp_contract_
:
679 case OPT_fstrict_overflow
:
687 if (!(cl_options
[option
->opt_index
].flags
& CL_TARGET
))
691 /* Pass the option on. */
692 for (i
= 0; i
< option
->canonical_option_num_elements
; ++i
)
693 obstack_ptr_grow (&argv_obstack
, option
->canonical_option
[i
]);
696 /* Append linker driver arguments. Compiler options from the linker
697 driver arguments will override / merge with those from the compiler. */
698 for (j
= 1; j
< decoded_options_count
; ++j
)
700 struct cl_decoded_option
*option
= &decoded_options
[j
];
702 /* Do not pass on frontend specific flags not suitable for lto. */
703 if (!(cl_options
[option
->opt_index
].flags
704 & (CL_COMMON
|CL_TARGET
|CL_DRIVER
|CL_LTO
)))
707 switch (option
->opt_index
)
710 linker_output
= option
->arg
;
711 /* We generate new intermediate output, drop this arg. */
722 case OPT_flto_partition_
:
723 if (strcmp (option
->arg
, "none") == 0)
728 if (strcmp (option
->arg
, "jobserver") == 0)
735 parallel
= atoi (option
->arg
);
742 lto_mode
= LTO_MODE_WHOPR
;
743 /* We've handled these LTO options, do not pass them on. */
746 case OPT_freg_struct_return
:
747 case OPT_fpcc_struct_return
:
748 case OPT_fshort_double
:
749 /* Ignore these, they are determined by the input files.
750 ??? We fail to diagnose a possible mismatch here. */
757 /* Pass the option on. */
758 for (i
= 0; i
< option
->canonical_option_num_elements
; ++i
)
759 obstack_ptr_grow (&argv_obstack
, option
->canonical_option
[i
]);
764 lto_mode
= LTO_MODE_LTO
;
771 char *output_dir
, *base
, *name
;
772 bool bit_bucket
= strcmp (linker_output
, HOST_BIT_BUCKET
) == 0;
774 output_dir
= xstrdup (linker_output
);
776 for (name
= base
; *name
; name
++)
777 if (IS_DIR_SEPARATOR (*name
))
781 linker_output
= &linker_output
[base
- output_dir
];
782 if (*output_dir
== '\0')
784 static char current_dir
[] = { '.', DIR_SEPARATOR
, '\0' };
785 output_dir
= current_dir
;
789 obstack_ptr_grow (&argv_obstack
, "-dumpdir");
790 obstack_ptr_grow (&argv_obstack
, output_dir
);
793 obstack_ptr_grow (&argv_obstack
, "-dumpbase");
796 /* Remember at which point we can scrub args to re-use the commons. */
797 new_head_argc
= obstack_object_size (&argv_obstack
) / sizeof (void *);
799 if (lto_mode
== LTO_MODE_LTO
)
801 flto_out
= make_temp_file (".lto.o");
803 obstack_ptr_grow (&argv_obstack
, linker_output
);
804 obstack_ptr_grow (&argv_obstack
, "-o");
805 obstack_ptr_grow (&argv_obstack
, flto_out
);
809 const char *list_option
= "-fltrans-output-list=";
810 size_t list_option_len
= strlen (list_option
);
815 char *dumpbase
= (char *) xmalloc (strlen (linker_output
)
816 + sizeof (".wpa") + 1);
817 strcpy (dumpbase
, linker_output
);
818 strcat (dumpbase
, ".wpa");
819 obstack_ptr_grow (&argv_obstack
, dumpbase
);
822 if (linker_output
&& debug
)
824 ltrans_output_file
= (char *) xmalloc (strlen (linker_output
)
825 + sizeof (".ltrans.out") + 1);
826 strcpy (ltrans_output_file
, linker_output
);
827 strcat (ltrans_output_file
, ".ltrans.out");
830 ltrans_output_file
= make_temp_file (".ltrans.out");
831 list_option_full
= (char *) xmalloc (sizeof (char) *
832 (strlen (ltrans_output_file
) + list_option_len
+ 1));
833 tmp
= list_option_full
;
835 obstack_ptr_grow (&argv_obstack
, tmp
);
836 strcpy (tmp
, list_option
);
837 tmp
+= list_option_len
;
838 strcpy (tmp
, ltrans_output_file
);
841 obstack_ptr_grow (&argv_obstack
, xstrdup ("-fwpa=jobserver"));
842 else if (parallel
> 1)
845 sprintf (buf
, "-fwpa=%i", parallel
);
846 obstack_ptr_grow (&argv_obstack
, xstrdup (buf
));
849 obstack_ptr_grow (&argv_obstack
, "-fwpa");
852 /* Append the input objects and possible preceding arguments. */
853 for (i
= 1; i
< argc
; ++i
)
854 obstack_ptr_grow (&argv_obstack
, argv
[i
]);
855 obstack_ptr_grow (&argv_obstack
, NULL
);
857 new_argv
= XOBFINISH (&argv_obstack
, const char **);
858 argv_ptr
= &new_argv
[new_head_argc
];
859 fork_execute (CONST_CAST (char **, new_argv
));
861 if (lto_mode
== LTO_MODE_LTO
)
863 printf ("%s\n", flto_out
);
869 FILE *stream
= fopen (ltrans_output_file
, "r");
870 FILE *mstream
= NULL
;
871 struct obstack env_obstack
;
874 fatal_perror ("fopen: %s", ltrans_output_file
);
876 /* Parse the list of LTRANS inputs from the WPA stage. */
877 obstack_init (&env_obstack
);
881 const unsigned piece
= 32;
882 char *output_name
= NULL
;
883 char *buf
, *input_name
= (char *)xmalloc (piece
);
888 if (!fgets (buf
, piece
, stream
))
890 len
= strlen (input_name
);
891 if (input_name
[len
- 1] != '\n')
893 input_name
= (char *)xrealloc (input_name
, len
+ piece
);
894 buf
= input_name
+ len
;
897 input_name
[len
- 1] = '\0';
899 if (input_name
[0] == '*')
900 output_name
= &input_name
[1];
903 input_names
= (char **)xrealloc (input_names
, nr
* sizeof (char *));
904 output_names
= (char **)xrealloc (output_names
, nr
* sizeof (char *));
905 input_names
[nr
-1] = input_name
;
906 output_names
[nr
-1] = output_name
;
909 maybe_unlink_file (ltrans_output_file
);
910 ltrans_output_file
= NULL
;
914 makefile
= make_temp_file (".mk");
915 mstream
= fopen (makefile
, "w");
918 /* Execute the LTRANS stage for each input file (or prepare a
919 makefile to invoke this in parallel). */
920 for (i
= 0; i
< nr
; ++i
)
923 char *input_name
= input_names
[i
];
924 /* If it's a pass-through file do nothing. */
928 /* Replace the .o suffix with a .ltrans.o suffix and write
929 the resulting name to the LTRANS output list. */
930 obstack_grow (&env_obstack
, input_name
, strlen (input_name
) - 2);
931 obstack_grow (&env_obstack
, ".ltrans.o", sizeof (".ltrans.o"));
932 output_name
= XOBFINISH (&env_obstack
, char *);
934 /* Adjust the dumpbase if the linker output file was seen. */
938 = (char *) xmalloc (strlen (linker_output
)
939 + sizeof (DUMPBASE_SUFFIX
) + 1);
941 strlen (linker_output
) + sizeof (DUMPBASE_SUFFIX
),
942 "%s.ltrans%u", linker_output
, i
);
943 argv_ptr
[0] = dumpbase
;
946 argv_ptr
[1] = "-fltrans";
948 argv_ptr
[3] = output_name
;
949 argv_ptr
[4] = input_name
;
953 fprintf (mstream
, "%s:\n\t@%s ", output_name
, new_argv
[0]);
954 for (j
= 1; new_argv
[j
] != NULL
; ++j
)
955 fprintf (mstream
, " '%s'", new_argv
[j
]);
956 fprintf (mstream
, "\n");
957 /* If we are not preserving the ltrans input files then
958 truncate them as soon as we have processed it. This
959 reduces temporary disk-space usage. */
961 fprintf (mstream
, "\t@-touch -r %s %s.tem > /dev/null 2>&1 "
963 input_name
, input_name
, input_name
, input_name
);
967 fork_execute (CONST_CAST (char **, new_argv
));
968 maybe_unlink_file (input_name
);
971 output_names
[i
] = output_name
;
978 fprintf (mstream
, "all:");
979 for (i
= 0; i
< nr
; ++i
)
980 fprintf (mstream
, " \\\n\t%s", output_names
[i
]);
981 fprintf (mstream
, "\n");
985 /* Avoid passing --jobserver-fd= and similar flags
986 unless jobserver mode is explicitly enabled. */
987 putenv (xstrdup ("MAKEFLAGS="));
988 putenv (xstrdup ("MFLAGS="));
990 new_argv
[0] = getenv ("MAKE");
992 new_argv
[0] = "make";
994 new_argv
[2] = makefile
;
998 snprintf (jobs
, 31, "-j%d", parallel
);
999 new_argv
[i
++] = jobs
;
1001 new_argv
[i
++] = "all";
1002 new_argv
[i
++] = NULL
;
1003 pex
= collect_execute (CONST_CAST (char **, new_argv
));
1004 collect_wait (new_argv
[0], pex
);
1005 maybe_unlink_file (makefile
);
1007 for (i
= 0; i
< nr
; ++i
)
1008 maybe_unlink_file (input_names
[i
]);
1010 for (i
= 0; i
< nr
; ++i
)
1012 fputs (output_names
[i
], stdout
);
1013 putc ('\n', stdout
);
1014 free (input_names
[i
]);
1017 free (output_names
);
1019 free (list_option_full
);
1020 obstack_free (&env_obstack
, NULL
);
1023 obstack_free (&argv_obstack
, NULL
);
1030 main (int argc
, char *argv
[])
1034 gcc_obstack_init (&opts_obstack
);
1036 p
= argv
[0] + strlen (argv
[0]);
1037 while (p
!= argv
[0] && !IS_DIR_SEPARATOR (p
[-1]))
1041 xmalloc_set_program_name (progname
);
1043 gcc_init_libintl ();
1045 diagnostic_initialize (global_dc
, 0);
1047 if (signal (SIGINT
, SIG_IGN
) != SIG_IGN
)
1048 signal (SIGINT
, fatal_signal
);
1050 if (signal (SIGHUP
, SIG_IGN
) != SIG_IGN
)
1051 signal (SIGHUP
, fatal_signal
);
1053 if (signal (SIGTERM
, SIG_IGN
) != SIG_IGN
)
1054 signal (SIGTERM
, fatal_signal
);
1056 if (signal (SIGPIPE
, SIG_IGN
) != SIG_IGN
)
1057 signal (SIGPIPE
, fatal_signal
);
1060 /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
1061 receive the signal. A different setting is inheritable */
1062 signal (SIGCHLD
, SIG_DFL
);
1065 /* We may be called with all the arguments stored in some file and
1066 passed with @file. Expand them into argv before processing. */
1067 expandargv (&argc
, &argv
);
1069 run_gcc (argc
, argv
);