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"
50 /* From lto-streamer.h which we cannot include with -fkeep-inline-functions.
51 ??? Split out a lto-streamer-core.h. */
53 #define LTO_SECTION_NAME_PREFIX ".gnu.lto_"
55 /* End of lto-streamer.h copy. */
57 int debug
; /* true if -save-temps. */
58 int verbose
; /* true if -v. */
61 LTO_MODE_NONE
, /* Not doing LTO. */
62 LTO_MODE_LTO
, /* Normal LTO. */
63 LTO_MODE_WHOPR
/* WHOPR. */
66 /* Current LTO mode. */
67 static enum lto_mode_d lto_mode
= LTO_MODE_NONE
;
69 static char *ltrans_output_file
;
70 static char *flto_out
;
71 static char *args_name
;
72 static unsigned int nr
;
73 static char **input_names
;
74 static char **output_names
;
75 static char *makefile
;
77 static void maybe_unlink_file (const char *);
79 /* Delete tempfiles. */
82 lto_wrapper_cleanup (void)
84 static bool cleanup_done
= false;
90 /* Setting cleanup_done prevents an infinite loop if one of the
91 calls to maybe_unlink_file fails. */
94 if (ltrans_output_file
)
95 maybe_unlink_file (ltrans_output_file
);
97 maybe_unlink_file (flto_out
);
99 maybe_unlink_file (args_name
);
101 maybe_unlink_file (makefile
);
102 for (i
= 0; i
< nr
; ++i
)
104 maybe_unlink_file (input_names
[i
]);
106 maybe_unlink_file (output_names
[i
]);
111 fatal_signal (int signum
)
113 signal (signum
, SIG_DFL
);
114 lto_wrapper_cleanup ();
115 /* Get the same signal again, this time not handled,
116 so its normal effect occurs. */
117 kill (getpid (), signum
);
120 /* Just die. CMSGID is the error message. */
122 static void __attribute__ ((format (printf
, 1, 2)))
123 fatal (const char * cmsgid
, ...)
127 va_start (ap
, cmsgid
);
128 fprintf (stderr
, "lto-wrapper: ");
129 vfprintf (stderr
, _(cmsgid
), ap
);
130 fprintf (stderr
, "\n");
133 lto_wrapper_cleanup ();
134 exit (FATAL_EXIT_CODE
);
138 /* Die when sys call fails. CMSGID is the error message. */
140 static void __attribute__ ((format (printf
, 1, 2)))
141 fatal_perror (const char *cmsgid
, ...)
146 va_start (ap
, cmsgid
);
147 fprintf (stderr
, "lto-wrapper: ");
148 vfprintf (stderr
, _(cmsgid
), ap
);
149 fprintf (stderr
, ": %s\n", xstrerror (e
));
152 lto_wrapper_cleanup ();
153 exit (FATAL_EXIT_CODE
);
157 /* Execute a program, and wait for the reply. ARGV are the arguments. The
158 last one must be NULL. */
160 static struct pex_obj
*
161 collect_execute (char **argv
)
172 for (p_argv
= argv
; (str
= *p_argv
) != (char *) 0; p_argv
++)
173 fprintf (stderr
, " %s", str
);
175 fprintf (stderr
, "\n");
181 pex
= pex_init (0, "lto-wrapper", NULL
);
183 fatal_perror ("pex_init failed");
185 /* Do not use PEX_LAST here, we use our stdout for communicating with
186 collect2 or the linker-plugin. Any output from the sub-process
187 will confuse that. */
188 errmsg
= pex_run (pex
, PEX_SEARCH
, argv
[0], argv
, NULL
,
195 fatal_perror (errmsg
);
205 /* Wait for a process to finish, and exit if a nonzero status is found.
206 PROG is the program name. PEX is the process we should wait for. */
209 collect_wait (const char *prog
, struct pex_obj
*pex
)
213 if (!pex_get_status (pex
, 1, &status
))
214 fatal_perror ("can't get program status");
219 if (WIFSIGNALED (status
))
221 int sig
= WTERMSIG (status
);
222 if (WCOREDUMP (status
))
223 fatal ("%s terminated with signal %d [%s], core dumped",
224 prog
, sig
, strsignal (sig
));
226 fatal ("%s terminated with signal %d [%s]",
227 prog
, sig
, strsignal (sig
));
230 if (WIFEXITED (status
))
231 fatal ("%s returned %d exit status", prog
, WEXITSTATUS (status
));
238 /* Unlink a temporary LTRANS file unless requested otherwise. */
241 maybe_unlink_file (const char *file
)
245 if (unlink_if_ordinary (file
)
247 fatal_perror ("deleting LTRANS file %s", file
);
250 fprintf (stderr
, "[Leaving LTRANS %s]\n", file
);
254 /* Execute program ARGV[0] with arguments ARGV. Wait for it to finish. */
257 fork_execute (char **argv
)
265 args_name
= make_temp_file (".args");
266 at_args
= concat ("@", args_name
, NULL
);
267 args
= fopen (args_name
, "w");
269 fatal ("failed to open %s", args_name
);
271 status
= writeargv (&argv
[1], args
);
274 fatal ("could not write to temporary file %s", args_name
);
278 new_argv
[0] = argv
[0];
279 new_argv
[1] = at_args
;
282 pex
= collect_execute (new_argv
);
283 collect_wait (new_argv
[0], pex
);
285 maybe_unlink_file (args_name
);
290 /* Template of LTRANS dumpbase suffix. */
291 #define DUMPBASE_SUFFIX ".ltrans18446744073709551615"
293 /* Create decoded options from the COLLECT_GCC and COLLECT_GCC_OPTIONS
294 environment according to LANG_MASK. */
297 get_options_from_collect_gcc_options (const char *collect_gcc
,
298 const char *collect_gcc_options
,
299 unsigned int lang_mask
,
300 struct cl_decoded_option
**decoded_options
,
301 unsigned int *decoded_options_count
)
303 struct obstack argv_obstack
;
308 argv_storage
= xstrdup (collect_gcc_options
);
309 obstack_init (&argv_obstack
);
310 obstack_ptr_grow (&argv_obstack
, collect_gcc
);
312 for (j
= 0, k
= 0; argv_storage
[j
] != '\0'; ++j
)
314 if (argv_storage
[j
] == '\'')
316 obstack_ptr_grow (&argv_obstack
, &argv_storage
[k
]);
320 if (argv_storage
[j
] == '\0')
321 fatal ("malformed COLLECT_GCC_OPTIONS");
322 else if (strncmp (&argv_storage
[j
], "'\\''", 4) == 0)
324 argv_storage
[k
++] = '\'';
327 else if (argv_storage
[j
] == '\'')
330 argv_storage
[k
++] = argv_storage
[j
++];
333 argv_storage
[k
++] = '\0';
337 obstack_ptr_grow (&argv_obstack
, NULL
);
338 argc
= obstack_object_size (&argv_obstack
) / sizeof (void *) - 1;
339 argv
= XOBFINISH (&argv_obstack
, const char **);
341 decode_cmdline_options_to_array (argc
, (const char **)argv
,
343 decoded_options
, decoded_options_count
);
344 obstack_free (&argv_obstack
, NULL
);
347 /* Append OPTION to the options array DECODED_OPTIONS with size
348 DECODED_OPTIONS_COUNT. */
351 append_option (struct cl_decoded_option
**decoded_options
,
352 unsigned int *decoded_options_count
,
353 struct cl_decoded_option
*option
)
355 ++*decoded_options_count
;
357 = (struct cl_decoded_option
*)
358 xrealloc (*decoded_options
,
359 (*decoded_options_count
360 * sizeof (struct cl_decoded_option
)));
361 memcpy (&(*decoded_options
)[*decoded_options_count
- 1], option
,
362 sizeof (struct cl_decoded_option
));
365 /* Try to merge and complain about options FDECODED_OPTIONS when applied
366 ontop of DECODED_OPTIONS. */
369 merge_and_complain (struct cl_decoded_option
**decoded_options
,
370 unsigned int *decoded_options_count
,
371 struct cl_decoded_option
*fdecoded_options
,
372 unsigned int fdecoded_options_count
)
376 /* ??? Merge options from files. Most cases can be
377 handled by either unioning or intersecting
378 (for example -fwrapv is a case for unioning,
379 -ffast-math is for intersection). Most complaints
380 about real conflicts between different options can
381 be deferred to the compiler proper. Options that
382 we can neither safely handle by intersection nor
383 unioning would need to be complained about here.
384 Ideally we'd have a flag in the opt files that
385 tells whether to union or intersect or reject.
386 In absence of that it's unclear what a good default is.
387 It's also difficult to get positional handling correct. */
389 /* The following does what the old LTO option code did,
390 union all target and a selected set of common options. */
391 for (i
= 0; i
< fdecoded_options_count
; ++i
)
393 struct cl_decoded_option
*foption
= &fdecoded_options
[i
];
394 switch (foption
->opt_index
)
396 case OPT_SPECIAL_unknown
:
397 case OPT_SPECIAL_ignore
:
398 case OPT_SPECIAL_program_name
:
399 case OPT_SPECIAL_input_file
:
403 if (!(cl_options
[foption
->opt_index
].flags
& CL_TARGET
))
412 case OPT_fexceptions
:
413 case OPT_fnon_call_exceptions
:
415 /* Do what the old LTO code did - collect exactly one option
416 setting per OPT code, we pick the first we encounter.
417 ??? This doesn't make too much sense, but when it doesn't
418 then we should complain. */
419 for (j
= 0; j
< *decoded_options_count
; ++j
)
420 if ((*decoded_options
)[j
].opt_index
== foption
->opt_index
)
422 if (j
== *decoded_options_count
)
423 append_option (decoded_options
, decoded_options_count
, foption
);
427 case OPT_fstrict_overflow
:
428 case OPT_ffp_contract_
:
429 /* For selected options we can merge conservatively. */
430 for (j
= 0; j
< *decoded_options_count
; ++j
)
431 if ((*decoded_options
)[j
].opt_index
== foption
->opt_index
)
433 if (j
== *decoded_options_count
)
434 append_option (decoded_options
, decoded_options_count
, foption
);
435 /* FP_CONTRACT_OFF < FP_CONTRACT_ON < FP_CONTRACT_FAST,
436 -fno-trapv < -ftrapv,
437 -fno-strict-overflow < -fstrict-overflow */
438 else if (foption
->value
< (*decoded_options
)[j
].value
)
439 (*decoded_options
)[j
] = *foption
;
443 /* For selected options we can merge conservatively. */
444 for (j
= 0; j
< *decoded_options_count
; ++j
)
445 if ((*decoded_options
)[j
].opt_index
== foption
->opt_index
)
447 if (j
== *decoded_options_count
)
448 append_option (decoded_options
, decoded_options_count
, foption
);
449 /* -fwrapv > -fno-wrapv. */
450 else if (foption
->value
> (*decoded_options
)[j
].value
)
451 (*decoded_options
)[j
] = *foption
;
454 case OPT_freg_struct_return
:
455 case OPT_fpcc_struct_return
:
456 case OPT_fshort_double
:
457 for (j
= 0; j
< *decoded_options_count
; ++j
)
458 if ((*decoded_options
)[j
].opt_index
== foption
->opt_index
)
460 if (j
== *decoded_options_count
)
461 fatal ("Option %s not used consistently in all LTO input files",
462 foption
->orig_option_with_args_text
);
469 for (j
= 0; j
< *decoded_options_count
; ++j
)
470 if ((*decoded_options
)[j
].opt_index
== OPT_O
471 || (*decoded_options
)[j
].opt_index
== OPT_Ofast
472 || (*decoded_options
)[j
].opt_index
== OPT_Og
473 || (*decoded_options
)[j
].opt_index
== OPT_Os
)
475 if (j
== *decoded_options_count
)
476 append_option (decoded_options
, decoded_options_count
, foption
);
477 else if ((*decoded_options
)[j
].opt_index
== foption
->opt_index
478 && foption
->opt_index
!= OPT_O
)
479 /* Exact same options get merged. */
483 /* For mismatched option kinds preserve the optimization
484 level only, thus merge it as -On. This also handles
485 merging of same optimization level -On. */
487 switch (foption
->opt_index
)
490 if (foption
->arg
[0] == '\0')
491 level
= MAX (level
, 1);
493 level
= MAX (level
, atoi (foption
->arg
));
496 level
= MAX (level
, 3);
499 level
= MAX (level
, 1);
502 level
= MAX (level
, 2);
507 switch ((*decoded_options
)[j
].opt_index
)
510 if ((*decoded_options
)[j
].arg
[0] == '\0')
511 level
= MAX (level
, 1);
513 level
= MAX (level
, atoi ((*decoded_options
)[j
].arg
));
516 level
= MAX (level
, 3);
519 level
= MAX (level
, 1);
522 level
= MAX (level
, 2);
527 (*decoded_options
)[j
].opt_index
= OPT_O
;
529 asprintf (&tem
, "-O%d", level
);
530 (*decoded_options
)[j
].arg
= &tem
[2];
531 (*decoded_options
)[j
].canonical_option
[0] = tem
;
532 (*decoded_options
)[j
].value
= 1;
539 /* Execute gcc. ARGC is the number of arguments. ARGV contains the arguments. */
542 run_gcc (unsigned argc
, char *argv
[])
545 const char **new_argv
;
546 const char **argv_ptr
;
547 char *list_option_full
= NULL
;
548 const char *linker_output
= NULL
;
549 const char *collect_gcc
, *collect_gcc_options
;
552 bool no_partition
= false;
553 struct cl_decoded_option
*fdecoded_options
= NULL
;
554 unsigned int fdecoded_options_count
= 0;
555 struct cl_decoded_option
*decoded_options
;
556 unsigned int decoded_options_count
;
557 struct obstack argv_obstack
;
560 /* Get the driver and options. */
561 collect_gcc
= getenv ("COLLECT_GCC");
563 fatal ("environment variable COLLECT_GCC must be set");
564 collect_gcc_options
= getenv ("COLLECT_GCC_OPTIONS");
565 if (!collect_gcc_options
)
566 fatal ("environment variable COLLECT_GCC_OPTIONS must be set");
567 get_options_from_collect_gcc_options (collect_gcc
, collect_gcc_options
,
570 &decoded_options_count
);
572 /* Look at saved options in the IL files. */
573 for (i
= 1; i
< argc
; ++i
)
580 off_t file_offset
= 0, offset
, length
;
582 simple_object_read
*sobj
;
584 struct cl_decoded_option
*f2decoded_options
;
585 unsigned int f2decoded_options_count
;
586 char *filename
= argv
[i
];
587 if ((p
= strrchr (argv
[i
], '@'))
589 && sscanf (p
, "@%li%n", &loffset
, &consumed
) >= 1
590 && strlen (p
) == (unsigned int) consumed
)
592 filename
= XNEWVEC (char, p
- argv
[i
] + 1);
593 memcpy (filename
, argv
[i
], p
- argv
[i
]);
594 filename
[p
- argv
[i
]] = '\0';
595 file_offset
= (off_t
) loffset
;
597 fd
= open (argv
[i
], O_RDONLY
);
600 sobj
= simple_object_start_read (fd
, file_offset
, "__GNU_LTO",
607 if (!simple_object_find_section (sobj
, LTO_SECTION_NAME_PREFIX
"." "opts",
608 &offset
, &length
, &errmsg
, &err
))
610 simple_object_release_read (sobj
);
614 lseek (fd
, file_offset
+ offset
, SEEK_SET
);
615 data
= (char *)xmalloc (length
);
616 read (fd
, data
, length
);
620 get_options_from_collect_gcc_options (collect_gcc
,
623 &f2decoded_options_count
);
624 if (!fdecoded_options
)
626 fdecoded_options
= f2decoded_options
;
627 fdecoded_options_count
= f2decoded_options_count
;
630 merge_and_complain (&fdecoded_options
,
631 &fdecoded_options_count
,
632 f2decoded_options
, f2decoded_options_count
);
634 fopts
+= strlen (fopts
) + 1;
636 while (fopts
- data
< length
);
639 simple_object_release_read (sobj
);
643 /* Initalize the common arguments for the driver. */
644 obstack_init (&argv_obstack
);
645 obstack_ptr_grow (&argv_obstack
, collect_gcc
);
646 obstack_ptr_grow (&argv_obstack
, "-xlto");
647 obstack_ptr_grow (&argv_obstack
, "-c");
649 /* Append compiler driver arguments as far as they were merged. */
650 for (j
= 1; j
< fdecoded_options_count
; ++j
)
652 struct cl_decoded_option
*option
= &fdecoded_options
[j
];
654 /* File options have been properly filtered by lto-opts.c. */
655 switch (option
->opt_index
)
657 /* Drop arguments that we want to take from the link line. */
660 case OPT_flto_partition_none
:
661 case OPT_flto_partition_1to1
:
662 case OPT_flto_partition_balanced
:
669 /* For now do what the original LTO option code was doing - pass
670 on any CL_TARGET flag and a few selected others. */
671 switch (option
->opt_index
)
678 case OPT_fexceptions
:
679 case OPT_fnon_call_exceptions
:
681 case OPT_freg_struct_return
:
682 case OPT_fpcc_struct_return
:
683 case OPT_fshort_double
:
684 case OPT_ffp_contract_
:
687 case OPT_fstrict_overflow
:
695 if (!(cl_options
[option
->opt_index
].flags
& CL_TARGET
))
699 /* Pass the option on. */
700 for (i
= 0; i
< option
->canonical_option_num_elements
; ++i
)
701 obstack_ptr_grow (&argv_obstack
, option
->canonical_option
[i
]);
704 /* Append linker driver arguments. Compiler options from the linker
705 driver arguments will override / merge with those from the compiler. */
706 for (j
= 1; j
< decoded_options_count
; ++j
)
708 struct cl_decoded_option
*option
= &decoded_options
[j
];
710 /* Do not pass on frontend specific flags not suitable for lto. */
711 if (!(cl_options
[option
->opt_index
].flags
712 & (CL_COMMON
|CL_TARGET
|CL_DRIVER
|CL_LTO
)))
715 switch (option
->opt_index
)
718 linker_output
= option
->arg
;
719 /* We generate new intermediate output, drop this arg. */
730 case OPT_flto_partition_none
:
735 if (strcmp (option
->arg
, "jobserver") == 0)
742 parallel
= atoi (option
->arg
);
749 lto_mode
= LTO_MODE_WHOPR
;
750 /* We've handled these LTO options, do not pass them on. */
753 case OPT_freg_struct_return
:
754 case OPT_fpcc_struct_return
:
755 case OPT_fshort_double
:
756 /* Ignore these, they are determined by the input files.
757 ??? We fail to diagnose a possible mismatch here. */
764 /* Pass the option on. */
765 for (i
= 0; i
< option
->canonical_option_num_elements
; ++i
)
766 obstack_ptr_grow (&argv_obstack
, option
->canonical_option
[i
]);
771 lto_mode
= LTO_MODE_LTO
;
778 char *output_dir
, *base
, *name
;
779 bool bit_bucket
= strcmp (linker_output
, HOST_BIT_BUCKET
) == 0;
781 output_dir
= xstrdup (linker_output
);
783 for (name
= base
; *name
; name
++)
784 if (IS_DIR_SEPARATOR (*name
))
788 linker_output
= &linker_output
[base
- output_dir
];
789 if (*output_dir
== '\0')
791 static char current_dir
[] = { '.', DIR_SEPARATOR
, '\0' };
792 output_dir
= current_dir
;
796 obstack_ptr_grow (&argv_obstack
, "-dumpdir");
797 obstack_ptr_grow (&argv_obstack
, output_dir
);
800 obstack_ptr_grow (&argv_obstack
, "-dumpbase");
803 /* Remember at which point we can scrub args to re-use the commons. */
804 new_head_argc
= obstack_object_size (&argv_obstack
) / sizeof (void *);
806 if (lto_mode
== LTO_MODE_LTO
)
808 flto_out
= make_temp_file (".lto.o");
810 obstack_ptr_grow (&argv_obstack
, linker_output
);
811 obstack_ptr_grow (&argv_obstack
, "-o");
812 obstack_ptr_grow (&argv_obstack
, flto_out
);
816 const char *list_option
= "-fltrans-output-list=";
817 size_t list_option_len
= strlen (list_option
);
822 char *dumpbase
= (char *) xmalloc (strlen (linker_output
)
823 + sizeof (".wpa") + 1);
824 strcpy (dumpbase
, linker_output
);
825 strcat (dumpbase
, ".wpa");
826 obstack_ptr_grow (&argv_obstack
, dumpbase
);
829 if (linker_output
&& debug
)
831 ltrans_output_file
= (char *) xmalloc (strlen (linker_output
)
832 + sizeof (".ltrans.out") + 1);
833 strcpy (ltrans_output_file
, linker_output
);
834 strcat (ltrans_output_file
, ".ltrans.out");
837 ltrans_output_file
= make_temp_file (".ltrans.out");
838 list_option_full
= (char *) xmalloc (sizeof (char) *
839 (strlen (ltrans_output_file
) + list_option_len
+ 1));
840 tmp
= list_option_full
;
842 obstack_ptr_grow (&argv_obstack
, tmp
);
843 strcpy (tmp
, list_option
);
844 tmp
+= list_option_len
;
845 strcpy (tmp
, ltrans_output_file
);
848 obstack_ptr_grow (&argv_obstack
, xstrdup ("-fwpa=jobserver"));
849 else if (parallel
> 1)
852 sprintf (buf
, "-fwpa=%i", parallel
);
853 obstack_ptr_grow (&argv_obstack
, xstrdup (buf
));
856 obstack_ptr_grow (&argv_obstack
, "-fwpa");
859 /* Append the input objects and possible preceding arguments. */
860 for (i
= 1; i
< argc
; ++i
)
861 obstack_ptr_grow (&argv_obstack
, argv
[i
]);
862 obstack_ptr_grow (&argv_obstack
, NULL
);
864 new_argv
= XOBFINISH (&argv_obstack
, const char **);
865 argv_ptr
= &new_argv
[new_head_argc
];
866 fork_execute (CONST_CAST (char **, new_argv
));
868 if (lto_mode
== LTO_MODE_LTO
)
870 printf ("%s\n", flto_out
);
876 FILE *stream
= fopen (ltrans_output_file
, "r");
877 FILE *mstream
= NULL
;
878 struct obstack env_obstack
;
881 fatal_perror ("fopen: %s", ltrans_output_file
);
883 /* Parse the list of LTRANS inputs from the WPA stage. */
884 obstack_init (&env_obstack
);
888 const unsigned piece
= 32;
889 char *output_name
= NULL
;
890 char *buf
, *input_name
= (char *)xmalloc (piece
);
895 if (!fgets (buf
, piece
, stream
))
897 len
= strlen (input_name
);
898 if (input_name
[len
- 1] != '\n')
900 input_name
= (char *)xrealloc (input_name
, len
+ piece
);
901 buf
= input_name
+ len
;
904 input_name
[len
- 1] = '\0';
906 if (input_name
[0] == '*')
907 output_name
= &input_name
[1];
910 input_names
= (char **)xrealloc (input_names
, nr
* sizeof (char *));
911 output_names
= (char **)xrealloc (output_names
, nr
* sizeof (char *));
912 input_names
[nr
-1] = input_name
;
913 output_names
[nr
-1] = output_name
;
916 maybe_unlink_file (ltrans_output_file
);
917 ltrans_output_file
= NULL
;
921 makefile
= make_temp_file (".mk");
922 mstream
= fopen (makefile
, "w");
925 /* Execute the LTRANS stage for each input file (or prepare a
926 makefile to invoke this in parallel). */
927 for (i
= 0; i
< nr
; ++i
)
930 char *input_name
= input_names
[i
];
931 /* If it's a pass-through file do nothing. */
935 /* Replace the .o suffix with a .ltrans.o suffix and write
936 the resulting name to the LTRANS output list. */
937 obstack_grow (&env_obstack
, input_name
, strlen (input_name
) - 2);
938 obstack_grow (&env_obstack
, ".ltrans.o", sizeof (".ltrans.o"));
939 output_name
= XOBFINISH (&env_obstack
, char *);
941 /* Adjust the dumpbase if the linker output file was seen. */
945 = (char *) xmalloc (strlen (linker_output
)
946 + sizeof (DUMPBASE_SUFFIX
) + 1);
948 strlen (linker_output
) + sizeof (DUMPBASE_SUFFIX
),
949 "%s.ltrans%u", linker_output
, i
);
950 argv_ptr
[0] = dumpbase
;
953 argv_ptr
[1] = "-fltrans";
955 argv_ptr
[3] = output_name
;
956 argv_ptr
[4] = input_name
;
960 fprintf (mstream
, "%s:\n\t@%s ", output_name
, new_argv
[0]);
961 for (j
= 1; new_argv
[j
] != NULL
; ++j
)
962 fprintf (mstream
, " '%s'", new_argv
[j
]);
963 fprintf (mstream
, "\n");
964 /* If we are not preserving the ltrans input files then
965 truncate them as soon as we have processed it. This
966 reduces temporary disk-space usage. */
968 fprintf (mstream
, "\t@-touch -r %s %s.tem > /dev/null 2>&1 "
970 input_name
, input_name
, input_name
, input_name
);
974 fork_execute (CONST_CAST (char **, new_argv
));
975 maybe_unlink_file (input_name
);
978 output_names
[i
] = output_name
;
985 fprintf (mstream
, "all:");
986 for (i
= 0; i
< nr
; ++i
)
987 fprintf (mstream
, " \\\n\t%s", output_names
[i
]);
988 fprintf (mstream
, "\n");
992 /* Avoid passing --jobserver-fd= and similar flags
993 unless jobserver mode is explicitly enabled. */
994 putenv (xstrdup ("MAKEFLAGS="));
995 putenv (xstrdup ("MFLAGS="));
997 new_argv
[0] = getenv ("MAKE");
999 new_argv
[0] = "make";
1001 new_argv
[2] = makefile
;
1005 snprintf (jobs
, 31, "-j%d", parallel
);
1006 new_argv
[i
++] = jobs
;
1008 new_argv
[i
++] = "all";
1009 new_argv
[i
++] = NULL
;
1010 pex
= collect_execute (CONST_CAST (char **, new_argv
));
1011 collect_wait (new_argv
[0], pex
);
1012 maybe_unlink_file (makefile
);
1014 for (i
= 0; i
< nr
; ++i
)
1015 maybe_unlink_file (input_names
[i
]);
1017 for (i
= 0; i
< nr
; ++i
)
1019 fputs (output_names
[i
], stdout
);
1020 putc ('\n', stdout
);
1021 free (input_names
[i
]);
1024 free (output_names
);
1026 free (list_option_full
);
1027 obstack_free (&env_obstack
, NULL
);
1030 obstack_free (&argv_obstack
, NULL
);
1037 main (int argc
, char *argv
[])
1041 gcc_obstack_init (&opts_obstack
);
1043 p
= argv
[0] + strlen (argv
[0]);
1044 while (p
!= argv
[0] && !IS_DIR_SEPARATOR (p
[-1]))
1048 xmalloc_set_program_name (progname
);
1050 gcc_init_libintl ();
1052 diagnostic_initialize (global_dc
, 0);
1054 if (signal (SIGINT
, SIG_IGN
) != SIG_IGN
)
1055 signal (SIGINT
, fatal_signal
);
1057 if (signal (SIGHUP
, SIG_IGN
) != SIG_IGN
)
1058 signal (SIGHUP
, fatal_signal
);
1060 if (signal (SIGTERM
, SIG_IGN
) != SIG_IGN
)
1061 signal (SIGTERM
, fatal_signal
);
1063 if (signal (SIGPIPE
, SIG_IGN
) != SIG_IGN
)
1064 signal (SIGPIPE
, fatal_signal
);
1067 /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
1068 receive the signal. A different setting is inheritable */
1069 signal (SIGCHLD
, SIG_DFL
);
1072 /* We may be called with all the arguments stored in some file and
1073 passed with @file. Expand them into argv before processing. */
1074 expandargv (&argc
, &argv
);
1076 run_gcc (argc
, argv
);