Mercurial > hg > CbC > CbC_gcc
annotate gcc/lto-wrapper.c @ 143:76e1cf5455ef
add cbc_gc test
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 23 Dec 2018 19:24:05 +0900 |
parents | 84e7813d76e9 |
children | 1830386684a0 |
rev | line source |
---|---|
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 /* Wrapper to call lto. Used by collect2 and the linker plugin. |
131 | 2 Copyright (C) 2009-2018 Free Software Foundation, Inc. |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 Factored out of collect2 by Rafael Espindola <espindola@google.com> |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 This file is part of GCC. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 GCC is free software; you can redistribute it and/or modify it under |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 the terms of the GNU General Public License as published by the Free |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 Software Foundation; either version 3, or (at your option) any later |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 version. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 for more details. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 You should have received a copy of the GNU General Public License |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 along with GCC; see the file COPYING3. If not see |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 <http://www.gnu.org/licenses/>. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 /* This program is passed a gcc, a list of gcc arguments and a list of |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 object files containing IL. It scans the argument list to check if |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 we are in whopr mode or not modifies the arguments and needed and |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 prints a list of output files on stdout. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 Example: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 $ lto-wrapper gcc/xgcc -B gcc a.o b.o -o test -flto |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 The above will print something like |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 /tmp/ccwbQ8B2.lto.o |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
35 If WHOPR is used instead, more than one file might be produced |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 ./ccXj2DTk.lto.ltrans.o |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 ./ccCJuXGv.lto.ltrans.o |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 #include "config.h" |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 #include "system.h" |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 #include "coretypes.h" |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 #include "intl.h" |
111 | 44 #include "diagnostic.h" |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
45 #include "obstack.h" |
111 | 46 #include "opts.h" |
47 #include "options.h" | |
48 #include "simple-object.h" | |
49 #include "lto-section-names.h" | |
50 #include "collect-utils.h" | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 |
111 | 52 /* Environment variable, used for passing the names of offload targets from GCC |
53 driver to lto-wrapper. */ | |
54 #define OFFLOAD_TARGET_NAMES_ENV "OFFLOAD_TARGET_NAMES" | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 enum lto_mode_d { |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
57 LTO_MODE_NONE, /* Not doing LTO. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
58 LTO_MODE_LTO, /* Normal LTO. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
59 LTO_MODE_WHOPR /* WHOPR. */ |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 }; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
62 /* Current LTO mode. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
63 static enum lto_mode_d lto_mode = LTO_MODE_NONE; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
64 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
65 static char *ltrans_output_file; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
66 static char *flto_out; |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
67 static unsigned int nr; |
131 | 68 static int *ltrans_priorities; |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
69 static char **input_names; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
70 static char **output_names; |
111 | 71 static char **offload_names; |
72 static char *offload_objects_file_name; | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
73 static char *makefile; |
111 | 74 static char *debug_obj; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
75 |
111 | 76 const char tool_name[] = "lto-wrapper"; |
77 | |
78 /* Delete tempfiles. Called from utils_cleanup. */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
79 |
111 | 80 void |
81 tool_cleanup (bool) | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82 { |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
83 unsigned int i; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
84 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
85 if (ltrans_output_file) |
111 | 86 maybe_unlink (ltrans_output_file); |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
87 if (flto_out) |
111 | 88 maybe_unlink (flto_out); |
89 if (offload_objects_file_name) | |
90 maybe_unlink (offload_objects_file_name); | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
91 if (makefile) |
111 | 92 maybe_unlink (makefile); |
93 if (debug_obj) | |
94 maybe_unlink (debug_obj); | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
95 for (i = 0; i < nr; ++i) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
96 { |
111 | 97 maybe_unlink (input_names[i]); |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
98 if (output_names[i]) |
111 | 99 maybe_unlink (output_names[i]); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
100 } |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
101 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
102 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
103 static void |
111 | 104 lto_wrapper_cleanup (void) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
105 { |
111 | 106 utils_cleanup (false); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
107 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
108 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
109 /* Unlink a temporary LTRANS file unless requested otherwise. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
110 |
111 | 111 void |
112 maybe_unlink (const char *file) | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
113 { |
111 | 114 if (!save_temps) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
115 { |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
116 if (unlink_if_ordinary (file) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
117 && errno != ENOENT) |
111 | 118 fatal_error (input_location, "deleting LTRANS file %s: %m", file); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
119 } |
111 | 120 else if (verbose) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
121 fprintf (stderr, "[Leaving LTRANS %s]\n", file); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
122 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
123 |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
124 /* Template of LTRANS dumpbase suffix. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
125 #define DUMPBASE_SUFFIX ".ltrans18446744073709551615" |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
126 |
111 | 127 /* Create decoded options from the COLLECT_GCC and COLLECT_GCC_OPTIONS |
128 environment according to LANG_MASK. */ | |
129 | |
130 static void | |
131 get_options_from_collect_gcc_options (const char *collect_gcc, | |
132 const char *collect_gcc_options, | |
133 unsigned int lang_mask, | |
134 struct cl_decoded_option **decoded_options, | |
135 unsigned int *decoded_options_count) | |
136 { | |
137 struct obstack argv_obstack; | |
138 char *argv_storage; | |
139 const char **argv; | |
140 int j, k, argc; | |
141 | |
142 argv_storage = xstrdup (collect_gcc_options); | |
143 obstack_init (&argv_obstack); | |
144 obstack_ptr_grow (&argv_obstack, collect_gcc); | |
145 | |
146 for (j = 0, k = 0; argv_storage[j] != '\0'; ++j) | |
147 { | |
148 if (argv_storage[j] == '\'') | |
149 { | |
150 obstack_ptr_grow (&argv_obstack, &argv_storage[k]); | |
151 ++j; | |
152 do | |
153 { | |
154 if (argv_storage[j] == '\0') | |
155 fatal_error (input_location, "malformed COLLECT_GCC_OPTIONS"); | |
156 else if (strncmp (&argv_storage[j], "'\\''", 4) == 0) | |
157 { | |
158 argv_storage[k++] = '\''; | |
159 j += 4; | |
160 } | |
161 else if (argv_storage[j] == '\'') | |
162 break; | |
163 else | |
164 argv_storage[k++] = argv_storage[j++]; | |
165 } | |
166 while (1); | |
167 argv_storage[k++] = '\0'; | |
168 } | |
169 } | |
170 | |
171 obstack_ptr_grow (&argv_obstack, NULL); | |
172 argc = obstack_object_size (&argv_obstack) / sizeof (void *) - 1; | |
173 argv = XOBFINISH (&argv_obstack, const char **); | |
174 | |
175 decode_cmdline_options_to_array (argc, (const char **)argv, | |
176 lang_mask, | |
177 decoded_options, decoded_options_count); | |
178 obstack_free (&argv_obstack, NULL); | |
179 } | |
180 | |
181 /* Append OPTION to the options array DECODED_OPTIONS with size | |
182 DECODED_OPTIONS_COUNT. */ | |
183 | |
184 static void | |
185 append_option (struct cl_decoded_option **decoded_options, | |
186 unsigned int *decoded_options_count, | |
187 struct cl_decoded_option *option) | |
188 { | |
189 ++*decoded_options_count; | |
190 *decoded_options | |
191 = (struct cl_decoded_option *) | |
192 xrealloc (*decoded_options, | |
193 (*decoded_options_count | |
194 * sizeof (struct cl_decoded_option))); | |
195 memcpy (&(*decoded_options)[*decoded_options_count - 1], option, | |
196 sizeof (struct cl_decoded_option)); | |
197 } | |
198 | |
199 /* Remove option number INDEX from DECODED_OPTIONS, update | |
200 DECODED_OPTIONS_COUNT. */ | |
201 | |
202 static void | |
203 remove_option (struct cl_decoded_option **decoded_options, | |
204 int index, unsigned int *decoded_options_count) | |
205 { | |
206 --*decoded_options_count; | |
207 memmove (&(*decoded_options)[index + 1], | |
208 &(*decoded_options)[index], | |
209 sizeof (struct cl_decoded_option) | |
210 * (*decoded_options_count - index)); | |
211 } | |
212 | |
213 /* Try to merge and complain about options FDECODED_OPTIONS when applied | |
214 ontop of DECODED_OPTIONS. */ | |
215 | |
216 static void | |
217 merge_and_complain (struct cl_decoded_option **decoded_options, | |
218 unsigned int *decoded_options_count, | |
219 struct cl_decoded_option *fdecoded_options, | |
220 unsigned int fdecoded_options_count) | |
221 { | |
222 unsigned int i, j; | |
223 struct cl_decoded_option *pic_option = NULL; | |
224 struct cl_decoded_option *pie_option = NULL; | |
225 | |
226 /* ??? Merge options from files. Most cases can be | |
227 handled by either unioning or intersecting | |
228 (for example -fwrapv is a case for unioning, | |
229 -ffast-math is for intersection). Most complaints | |
230 about real conflicts between different options can | |
231 be deferred to the compiler proper. Options that | |
232 we can neither safely handle by intersection nor | |
233 unioning would need to be complained about here. | |
234 Ideally we'd have a flag in the opt files that | |
235 tells whether to union or intersect or reject. | |
236 In absence of that it's unclear what a good default is. | |
237 It's also difficult to get positional handling correct. */ | |
238 | |
239 /* The following does what the old LTO option code did, | |
240 union all target and a selected set of common options. */ | |
241 for (i = 0; i < fdecoded_options_count; ++i) | |
242 { | |
243 struct cl_decoded_option *foption = &fdecoded_options[i]; | |
244 switch (foption->opt_index) | |
245 { | |
246 case OPT_SPECIAL_unknown: | |
247 case OPT_SPECIAL_ignore: | |
131 | 248 case OPT_SPECIAL_deprecated: |
111 | 249 case OPT_SPECIAL_program_name: |
250 case OPT_SPECIAL_input_file: | |
251 break; | |
252 | |
253 default: | |
254 if (!(cl_options[foption->opt_index].flags & CL_TARGET)) | |
255 break; | |
256 | |
257 /* Fallthru. */ | |
258 case OPT_fdiagnostics_show_caret: | |
131 | 259 case OPT_fdiagnostics_show_labels: |
260 case OPT_fdiagnostics_show_line_numbers: | |
111 | 261 case OPT_fdiagnostics_show_option: |
262 case OPT_fdiagnostics_show_location_: | |
263 case OPT_fshow_column: | |
264 case OPT_fcommon: | |
265 case OPT_fgnu_tm: | |
266 /* Do what the old LTO code did - collect exactly one option | |
267 setting per OPT code, we pick the first we encounter. | |
268 ??? This doesn't make too much sense, but when it doesn't | |
269 then we should complain. */ | |
270 for (j = 0; j < *decoded_options_count; ++j) | |
271 if ((*decoded_options)[j].opt_index == foption->opt_index) | |
272 break; | |
273 if (j == *decoded_options_count) | |
274 append_option (decoded_options, decoded_options_count, foption); | |
275 break; | |
276 | |
277 /* Figure out what PIC/PIE level wins and merge the results. */ | |
278 case OPT_fPIC: | |
279 case OPT_fpic: | |
280 pic_option = foption; | |
281 break; | |
282 case OPT_fPIE: | |
283 case OPT_fpie: | |
284 pie_option = foption; | |
285 break; | |
286 | |
287 case OPT_fopenmp: | |
288 case OPT_fopenacc: | |
289 /* For selected options we can merge conservatively. */ | |
290 for (j = 0; j < *decoded_options_count; ++j) | |
291 if ((*decoded_options)[j].opt_index == foption->opt_index) | |
292 break; | |
293 if (j == *decoded_options_count) | |
294 append_option (decoded_options, decoded_options_count, foption); | |
295 /* -fopenmp > -fno-openmp, | |
131 | 296 -fopenacc > -fno-openacc */ |
111 | 297 else if (foption->value > (*decoded_options)[j].value) |
298 (*decoded_options)[j] = *foption; | |
299 break; | |
300 | |
301 case OPT_fopenacc_dim_: | |
302 /* Append or check identical. */ | |
303 for (j = 0; j < *decoded_options_count; ++j) | |
304 if ((*decoded_options)[j].opt_index == foption->opt_index) | |
305 break; | |
306 if (j == *decoded_options_count) | |
307 append_option (decoded_options, decoded_options_count, foption); | |
308 else if (strcmp ((*decoded_options)[j].arg, foption->arg)) | |
309 fatal_error (input_location, | |
310 "Option %s with different values", | |
311 foption->orig_option_with_args_text); | |
312 break; | |
313 | |
314 case OPT_O: | |
315 case OPT_Ofast: | |
316 case OPT_Og: | |
317 case OPT_Os: | |
318 for (j = 0; j < *decoded_options_count; ++j) | |
319 if ((*decoded_options)[j].opt_index == OPT_O | |
320 || (*decoded_options)[j].opt_index == OPT_Ofast | |
321 || (*decoded_options)[j].opt_index == OPT_Og | |
322 || (*decoded_options)[j].opt_index == OPT_Os) | |
323 break; | |
324 if (j == *decoded_options_count) | |
325 append_option (decoded_options, decoded_options_count, foption); | |
326 else if ((*decoded_options)[j].opt_index == foption->opt_index | |
327 && foption->opt_index != OPT_O) | |
328 /* Exact same options get merged. */ | |
329 ; | |
330 else | |
331 { | |
332 /* For mismatched option kinds preserve the optimization | |
333 level only, thus merge it as -On. This also handles | |
334 merging of same optimization level -On. */ | |
335 int level = 0; | |
336 switch (foption->opt_index) | |
337 { | |
338 case OPT_O: | |
339 if (foption->arg[0] == '\0') | |
340 level = MAX (level, 1); | |
341 else | |
342 level = MAX (level, atoi (foption->arg)); | |
343 break; | |
344 case OPT_Ofast: | |
345 level = MAX (level, 3); | |
346 break; | |
347 case OPT_Og: | |
348 level = MAX (level, 1); | |
349 break; | |
350 case OPT_Os: | |
351 level = MAX (level, 2); | |
352 break; | |
353 default: | |
354 gcc_unreachable (); | |
355 } | |
356 switch ((*decoded_options)[j].opt_index) | |
357 { | |
358 case OPT_O: | |
359 if ((*decoded_options)[j].arg[0] == '\0') | |
360 level = MAX (level, 1); | |
361 else | |
362 level = MAX (level, atoi ((*decoded_options)[j].arg)); | |
363 break; | |
364 case OPT_Ofast: | |
365 level = MAX (level, 3); | |
366 break; | |
367 case OPT_Og: | |
368 level = MAX (level, 1); | |
369 break; | |
370 case OPT_Os: | |
371 level = MAX (level, 2); | |
372 break; | |
373 default: | |
374 gcc_unreachable (); | |
375 } | |
376 (*decoded_options)[j].opt_index = OPT_O; | |
377 char *tem; | |
378 tem = xasprintf ("-O%d", level); | |
379 (*decoded_options)[j].arg = &tem[2]; | |
380 (*decoded_options)[j].canonical_option[0] = tem; | |
381 (*decoded_options)[j].value = 1; | |
382 } | |
383 break; | |
384 | |
385 | |
386 case OPT_foffload_abi_: | |
387 for (j = 0; j < *decoded_options_count; ++j) | |
388 if ((*decoded_options)[j].opt_index == foption->opt_index) | |
389 break; | |
390 if (j == *decoded_options_count) | |
391 append_option (decoded_options, decoded_options_count, foption); | |
392 else if (foption->value != (*decoded_options)[j].value) | |
393 fatal_error (input_location, | |
394 "Option %s not used consistently in all LTO input" | |
395 " files", foption->orig_option_with_args_text); | |
396 break; | |
397 | |
398 | |
399 case OPT_foffload_: | |
400 append_option (decoded_options, decoded_options_count, foption); | |
401 break; | |
402 } | |
403 } | |
404 | |
405 /* Merge PIC options: | |
406 -fPIC + -fpic = -fpic | |
407 -fPIC + -fno-pic = -fno-pic | |
408 -fpic/-fPIC + nothin = nothing. | |
409 It is a common mistake to mix few -fPIC compiled objects into otherwise | |
410 non-PIC code. We do not want to build everything with PIC then. | |
411 | |
131 | 412 Similarly we merge PIE options, however in addition we keep |
413 -fPIC + -fPIE = -fPIE | |
414 -fpic + -fPIE = -fpie | |
415 -fPIC/-fpic + -fpie = -fpie | |
416 | |
111 | 417 It would be good to warn on mismatches, but it is bit hard to do as |
418 we do not know what nothing translates to. */ | |
419 | |
420 for (unsigned int j = 0; j < *decoded_options_count;) | |
421 if ((*decoded_options)[j].opt_index == OPT_fPIC | |
422 || (*decoded_options)[j].opt_index == OPT_fpic) | |
423 { | |
131 | 424 /* -fno-pic in one unit implies -fno-pic everywhere. */ |
425 if ((*decoded_options)[j].value == 0) | |
426 j++; | |
427 /* If we have no pic option or merge in -fno-pic, we still may turn | |
428 existing pic/PIC mode into pie/PIE if -fpie/-fPIE is present. */ | |
429 else if ((pic_option && pic_option->value == 0) | |
430 || !pic_option) | |
431 { | |
432 if (pie_option) | |
433 { | |
434 bool big = (*decoded_options)[j].opt_index == OPT_fPIC | |
435 && pie_option->opt_index == OPT_fPIE; | |
436 (*decoded_options)[j].opt_index = big ? OPT_fPIE : OPT_fpie; | |
437 if (pie_option->value) | |
438 (*decoded_options)[j].canonical_option[0] = big ? "-fPIE" : "-fpie"; | |
439 else | |
440 (*decoded_options)[j].canonical_option[0] = big ? "-fno-pie" : "-fno-pie"; | |
441 (*decoded_options)[j].value = pie_option->value; | |
442 j++; | |
443 } | |
444 else if (pic_option) | |
445 { | |
446 (*decoded_options)[j] = *pic_option; | |
447 j++; | |
448 } | |
449 /* We do not know if target defaults to pic or not, so just remove | |
450 option if it is missing in one unit but enabled in other. */ | |
451 else | |
452 remove_option (decoded_options, j, decoded_options_count); | |
453 } | |
454 else if (pic_option->opt_index == OPT_fpic | |
455 && (*decoded_options)[j].opt_index == OPT_fPIC) | |
111 | 456 { |
457 (*decoded_options)[j] = *pic_option; | |
458 j++; | |
459 } | |
460 else | |
461 j++; | |
462 } | |
463 else if ((*decoded_options)[j].opt_index == OPT_fPIE | |
464 || (*decoded_options)[j].opt_index == OPT_fpie) | |
465 { | |
131 | 466 /* -fno-pie in one unit implies -fno-pie everywhere. */ |
467 if ((*decoded_options)[j].value == 0) | |
468 j++; | |
469 /* If we have no pie option or merge in -fno-pie, we still preserve | |
470 PIE/pie if pic/PIC is present. */ | |
471 else if ((pie_option && pie_option->value == 0) | |
472 || !pie_option) | |
473 { | |
474 /* If -fPIC/-fpic is given, merge it with -fPIE/-fpie. */ | |
475 if (pic_option) | |
476 { | |
477 if (pic_option->opt_index == OPT_fpic | |
478 && (*decoded_options)[j].opt_index == OPT_fPIE) | |
479 { | |
480 (*decoded_options)[j].opt_index = OPT_fpie; | |
481 (*decoded_options)[j].canonical_option[0] | |
482 = pic_option->value ? "-fpie" : "-fno-pie"; | |
483 } | |
484 else if (!pic_option->value) | |
485 (*decoded_options)[j].canonical_option[0] = "-fno-pie"; | |
486 (*decoded_options)[j].value = pic_option->value; | |
487 j++; | |
488 } | |
489 else if (pie_option) | |
490 { | |
491 (*decoded_options)[j] = *pie_option; | |
492 j++; | |
493 } | |
494 /* Because we always append pic/PIE options this code path should | |
495 not happen unless the LTO object was built by old lto1 which | |
496 did not contain that logic yet. */ | |
497 else | |
498 remove_option (decoded_options, j, decoded_options_count); | |
499 } | |
500 else if (pie_option->opt_index == OPT_fpie | |
501 && (*decoded_options)[j].opt_index == OPT_fPIE) | |
111 | 502 { |
503 (*decoded_options)[j] = *pie_option; | |
504 j++; | |
505 } | |
506 else | |
507 j++; | |
508 } | |
509 else | |
510 j++; | |
511 } | |
512 | |
513 /* Auxiliary function that frees elements of PTR and PTR itself. | |
514 N is number of elements to be freed. If PTR is NULL, nothing is freed. | |
515 If an element is NULL, subsequent elements are not freed. */ | |
516 | |
517 static void ** | |
518 free_array_of_ptrs (void **ptr, unsigned n) | |
519 { | |
520 if (!ptr) | |
521 return NULL; | |
522 for (unsigned i = 0; i < n; i++) | |
523 { | |
524 if (!ptr[i]) | |
525 break; | |
526 free (ptr[i]); | |
527 } | |
528 free (ptr); | |
529 return NULL; | |
530 } | |
531 | |
532 /* Parse STR, saving found tokens into PVALUES and return their number. | |
533 Tokens are assumed to be delimited by ':'. If APPEND is non-null, | |
534 append it to every token we find. */ | |
535 | |
536 static unsigned | |
537 parse_env_var (const char *str, char ***pvalues, const char *append) | |
538 { | |
539 const char *curval, *nextval; | |
540 char **values; | |
541 unsigned num = 1, i; | |
542 | |
543 curval = strchr (str, ':'); | |
544 while (curval) | |
545 { | |
546 num++; | |
547 curval = strchr (curval + 1, ':'); | |
548 } | |
549 | |
550 values = (char**) xmalloc (num * sizeof (char*)); | |
551 curval = str; | |
552 nextval = strchr (curval, ':'); | |
553 if (nextval == NULL) | |
554 nextval = strchr (curval, '\0'); | |
555 | |
556 int append_len = append ? strlen (append) : 0; | |
557 for (i = 0; i < num; i++) | |
558 { | |
559 int l = nextval - curval; | |
560 values[i] = (char*) xmalloc (l + 1 + append_len); | |
561 memcpy (values[i], curval, l); | |
562 values[i][l] = 0; | |
563 if (append) | |
564 strcat (values[i], append); | |
565 curval = nextval + 1; | |
566 nextval = strchr (curval, ':'); | |
567 if (nextval == NULL) | |
568 nextval = strchr (curval, '\0'); | |
569 } | |
570 *pvalues = values; | |
571 return num; | |
572 } | |
573 | |
574 /* Append options OPTS from lto or offload_lto sections to ARGV_OBSTACK. */ | |
575 | |
576 static void | |
577 append_compiler_options (obstack *argv_obstack, struct cl_decoded_option *opts, | |
578 unsigned int count) | |
579 { | |
580 /* Append compiler driver arguments as far as they were merged. */ | |
581 for (unsigned int j = 1; j < count; ++j) | |
582 { | |
583 struct cl_decoded_option *option = &opts[j]; | |
584 | |
585 /* File options have been properly filtered by lto-opts.c. */ | |
586 switch (option->opt_index) | |
587 { | |
588 /* Drop arguments that we want to take from the link line. */ | |
589 case OPT_flto_: | |
590 case OPT_flto: | |
591 case OPT_flto_partition_: | |
592 continue; | |
593 | |
594 default: | |
595 break; | |
596 } | |
597 | |
598 /* For now do what the original LTO option code was doing - pass | |
599 on any CL_TARGET flag and a few selected others. */ | |
600 switch (option->opt_index) | |
601 { | |
602 case OPT_fdiagnostics_show_caret: | |
131 | 603 case OPT_fdiagnostics_show_labels: |
604 case OPT_fdiagnostics_show_line_numbers: | |
111 | 605 case OPT_fdiagnostics_show_option: |
606 case OPT_fdiagnostics_show_location_: | |
607 case OPT_fshow_column: | |
608 case OPT_fPIC: | |
609 case OPT_fpic: | |
610 case OPT_fPIE: | |
611 case OPT_fpie: | |
612 case OPT_fcommon: | |
613 case OPT_fgnu_tm: | |
614 case OPT_fopenmp: | |
615 case OPT_fopenacc: | |
616 case OPT_fopenacc_dim_: | |
617 case OPT_foffload_abi_: | |
618 case OPT_O: | |
619 case OPT_Ofast: | |
620 case OPT_Og: | |
621 case OPT_Os: | |
622 break; | |
623 | |
624 default: | |
625 if (!(cl_options[option->opt_index].flags & CL_TARGET)) | |
626 continue; | |
627 } | |
628 | |
629 /* Pass the option on. */ | |
630 for (unsigned int i = 0; i < option->canonical_option_num_elements; ++i) | |
631 obstack_ptr_grow (argv_obstack, option->canonical_option[i]); | |
632 } | |
633 } | |
634 | |
635 /* Append diag options in OPTS with length COUNT to ARGV_OBSTACK. */ | |
636 | |
637 static void | |
638 append_diag_options (obstack *argv_obstack, struct cl_decoded_option *opts, | |
639 unsigned int count) | |
640 { | |
641 /* Append compiler driver arguments as far as they were merged. */ | |
642 for (unsigned int j = 1; j < count; ++j) | |
643 { | |
644 struct cl_decoded_option *option = &opts[j]; | |
645 | |
646 switch (option->opt_index) | |
647 { | |
648 case OPT_fdiagnostics_color_: | |
649 case OPT_fdiagnostics_show_caret: | |
131 | 650 case OPT_fdiagnostics_show_labels: |
651 case OPT_fdiagnostics_show_line_numbers: | |
111 | 652 case OPT_fdiagnostics_show_option: |
653 case OPT_fdiagnostics_show_location_: | |
654 case OPT_fshow_column: | |
655 break; | |
656 default: | |
657 continue; | |
658 } | |
659 | |
660 /* Pass the option on. */ | |
661 for (unsigned int i = 0; i < option->canonical_option_num_elements; ++i) | |
662 obstack_ptr_grow (argv_obstack, option->canonical_option[i]); | |
663 } | |
664 } | |
665 | |
666 | |
667 /* Append linker options OPTS to ARGV_OBSTACK. */ | |
668 | |
669 static void | |
670 append_linker_options (obstack *argv_obstack, struct cl_decoded_option *opts, | |
671 unsigned int count) | |
672 { | |
673 /* Append linker driver arguments. Compiler options from the linker | |
674 driver arguments will override / merge with those from the compiler. */ | |
675 for (unsigned int j = 1; j < count; ++j) | |
676 { | |
677 struct cl_decoded_option *option = &opts[j]; | |
678 | |
679 /* Do not pass on frontend specific flags not suitable for lto. */ | |
680 if (!(cl_options[option->opt_index].flags | |
681 & (CL_COMMON|CL_TARGET|CL_DRIVER|CL_LTO))) | |
682 continue; | |
683 | |
684 switch (option->opt_index) | |
685 { | |
686 case OPT_o: | |
687 case OPT_flto_: | |
688 case OPT_flto: | |
689 /* We've handled these LTO options, do not pass them on. */ | |
690 continue; | |
691 | |
692 case OPT_fopenmp: | |
693 case OPT_fopenacc: | |
694 /* Ignore -fno-XXX form of these options, as otherwise | |
695 corresponding builtins will not be enabled. */ | |
696 if (option->value == 0) | |
697 continue; | |
698 break; | |
699 | |
700 default: | |
701 break; | |
702 } | |
703 | |
704 /* Pass the option on. */ | |
705 for (unsigned int i = 0; i < option->canonical_option_num_elements; ++i) | |
706 obstack_ptr_grow (argv_obstack, option->canonical_option[i]); | |
707 } | |
708 } | |
709 | |
710 /* Extract options for TARGET offload compiler from OPTIONS and append | |
711 them to ARGV_OBSTACK. */ | |
712 | |
713 static void | |
714 append_offload_options (obstack *argv_obstack, const char *target, | |
715 struct cl_decoded_option *options, | |
716 unsigned int options_count) | |
717 { | |
718 for (unsigned i = 0; i < options_count; i++) | |
719 { | |
720 const char *cur, *next, *opts; | |
721 char **argv; | |
722 unsigned argc; | |
723 struct cl_decoded_option *option = &options[i]; | |
724 | |
725 if (option->opt_index != OPT_foffload_) | |
726 continue; | |
727 | |
728 /* If option argument starts with '-' then no target is specified. That | |
729 means offload options are specified for all targets, so we need to | |
730 append them. */ | |
731 if (option->arg[0] == '-') | |
732 opts = option->arg; | |
733 else | |
734 { | |
735 opts = strchr (option->arg, '='); | |
736 /* If there are offload targets specified, but no actual options, | |
737 there is nothing to do here. */ | |
738 if (!opts) | |
739 continue; | |
740 | |
741 cur = option->arg; | |
742 | |
743 while (cur < opts) | |
744 { | |
745 next = strchr (cur, ','); | |
746 if (next == NULL) | |
747 next = opts; | |
748 next = (next > opts) ? opts : next; | |
749 | |
750 /* Are we looking for this offload target? */ | |
751 if (strlen (target) == (size_t) (next - cur) | |
752 && strncmp (target, cur, next - cur) == 0) | |
753 break; | |
754 | |
755 /* Skip the comma or equal sign. */ | |
756 cur = next + 1; | |
757 } | |
758 | |
759 if (cur >= opts) | |
760 continue; | |
761 | |
762 opts++; | |
763 } | |
764 | |
765 argv = buildargv (opts); | |
766 for (argc = 0; argv[argc]; argc++) | |
767 obstack_ptr_grow (argv_obstack, argv[argc]); | |
768 } | |
769 } | |
770 | |
771 /* Check whether NAME can be accessed in MODE. This is like access, | |
772 except that it never considers directories to be executable. */ | |
773 | |
774 static int | |
775 access_check (const char *name, int mode) | |
776 { | |
777 if (mode == X_OK) | |
778 { | |
779 struct stat st; | |
780 | |
781 if (stat (name, &st) < 0 | |
782 || S_ISDIR (st.st_mode)) | |
783 return -1; | |
784 } | |
785 | |
786 return access (name, mode); | |
787 } | |
788 | |
789 /* Prepare a target image for offload TARGET, using mkoffload tool from | |
790 COMPILER_PATH. Return the name of the resultant object file. */ | |
791 | |
792 static char * | |
793 compile_offload_image (const char *target, const char *compiler_path, | |
794 unsigned in_argc, char *in_argv[], | |
795 struct cl_decoded_option *compiler_opts, | |
796 unsigned int compiler_opt_count, | |
797 struct cl_decoded_option *linker_opts, | |
798 unsigned int linker_opt_count) | |
799 { | |
800 char *filename = NULL; | |
801 char **argv; | |
802 char *suffix | |
803 = XALLOCAVEC (char, sizeof ("/accel//mkoffload") + strlen (target)); | |
804 strcpy (suffix, "/accel/"); | |
805 strcat (suffix, target); | |
806 strcat (suffix, "/mkoffload"); | |
807 | |
808 char **paths = NULL; | |
809 unsigned n_paths = parse_env_var (compiler_path, &paths, suffix); | |
810 | |
811 const char *compiler = NULL; | |
812 for (unsigned i = 0; i < n_paths; i++) | |
813 if (access_check (paths[i], X_OK) == 0) | |
814 { | |
815 compiler = paths[i]; | |
816 break; | |
817 } | |
818 | |
131 | 819 if (!compiler) |
820 fatal_error (input_location, | |
821 "could not find %s in %s (consider using '-B')\n", suffix + 1, | |
822 compiler_path); | |
823 | |
824 /* Generate temporary output file name. */ | |
825 filename = make_temp_file (".target.o"); | |
111 | 826 |
131 | 827 struct obstack argv_obstack; |
828 obstack_init (&argv_obstack); | |
829 obstack_ptr_grow (&argv_obstack, compiler); | |
830 if (save_temps) | |
831 obstack_ptr_grow (&argv_obstack, "-save-temps"); | |
832 if (verbose) | |
833 obstack_ptr_grow (&argv_obstack, "-v"); | |
834 obstack_ptr_grow (&argv_obstack, "-o"); | |
835 obstack_ptr_grow (&argv_obstack, filename); | |
111 | 836 |
131 | 837 /* Append names of input object files. */ |
838 for (unsigned i = 0; i < in_argc; i++) | |
839 obstack_ptr_grow (&argv_obstack, in_argv[i]); | |
111 | 840 |
131 | 841 /* Append options from offload_lto sections. */ |
842 append_compiler_options (&argv_obstack, compiler_opts, | |
843 compiler_opt_count); | |
844 append_diag_options (&argv_obstack, linker_opts, linker_opt_count); | |
111 | 845 |
131 | 846 /* Append options specified by -foffload last. In case of conflicting |
847 options we expect offload compiler to choose the latest. */ | |
848 append_offload_options (&argv_obstack, target, compiler_opts, | |
849 compiler_opt_count); | |
850 append_offload_options (&argv_obstack, target, linker_opts, | |
851 linker_opt_count); | |
111 | 852 |
131 | 853 obstack_ptr_grow (&argv_obstack, NULL); |
854 argv = XOBFINISH (&argv_obstack, char **); | |
855 fork_execute (argv[0], argv, true); | |
856 obstack_free (&argv_obstack, NULL); | |
111 | 857 |
858 free_array_of_ptrs ((void **) paths, n_paths); | |
859 return filename; | |
860 } | |
861 | |
862 | |
863 /* The main routine dealing with offloading. | |
864 The routine builds a target image for each offload target. IN_ARGC and | |
865 IN_ARGV specify options and input object files. As all of them could contain | |
866 target sections, we pass them all to target compilers. */ | |
867 | |
868 static void | |
869 compile_images_for_offload_targets (unsigned in_argc, char *in_argv[], | |
870 struct cl_decoded_option *compiler_opts, | |
871 unsigned int compiler_opt_count, | |
872 struct cl_decoded_option *linker_opts, | |
873 unsigned int linker_opt_count) | |
874 { | |
875 char **names = NULL; | |
876 const char *target_names = getenv (OFFLOAD_TARGET_NAMES_ENV); | |
877 if (!target_names) | |
878 return; | |
879 unsigned num_targets = parse_env_var (target_names, &names, NULL); | |
880 | |
881 int next_name_entry = 0; | |
882 const char *compiler_path = getenv ("COMPILER_PATH"); | |
883 if (!compiler_path) | |
884 goto out; | |
885 | |
886 /* Prepare an image for each target and save the name of the resultant object | |
887 file to the OFFLOAD_NAMES array. It is terminated by a NULL entry. */ | |
888 offload_names = XCNEWVEC (char *, num_targets + 1); | |
889 for (unsigned i = 0; i < num_targets; i++) | |
890 { | |
891 /* HSA does not use LTO-like streaming and a different compiler, skip | |
892 it. */ | |
893 if (strcmp (names[i], "hsa") == 0) | |
894 continue; | |
895 | |
896 offload_names[next_name_entry] | |
897 = compile_offload_image (names[i], compiler_path, in_argc, in_argv, | |
898 compiler_opts, compiler_opt_count, | |
899 linker_opts, linker_opt_count); | |
900 if (!offload_names[next_name_entry]) | |
901 fatal_error (input_location, | |
902 "problem with building target image for %s\n", names[i]); | |
903 next_name_entry++; | |
904 } | |
905 | |
906 out: | |
907 free_array_of_ptrs ((void **) names, num_targets); | |
908 } | |
909 | |
910 /* Copy a file from SRC to DEST. */ | |
911 | |
912 static void | |
913 copy_file (const char *dest, const char *src) | |
914 { | |
915 FILE *d = fopen (dest, "wb"); | |
916 FILE *s = fopen (src, "rb"); | |
917 char buffer[512]; | |
918 while (!feof (s)) | |
919 { | |
920 size_t len = fread (buffer, 1, 512, s); | |
921 if (ferror (s) != 0) | |
922 fatal_error (input_location, "reading input file"); | |
923 if (len > 0) | |
924 { | |
925 fwrite (buffer, 1, len, d); | |
926 if (ferror (d) != 0) | |
927 fatal_error (input_location, "writing output file"); | |
928 } | |
929 } | |
930 fclose (d); | |
931 fclose (s); | |
932 } | |
933 | |
934 /* Find the crtoffloadtable.o file in LIBRARY_PATH, make copy and pass name of | |
935 the copy to the linker. */ | |
936 | |
937 static void | |
938 find_crtoffloadtable (void) | |
939 { | |
940 char **paths = NULL; | |
941 const char *library_path = getenv ("LIBRARY_PATH"); | |
942 if (!library_path) | |
943 return; | |
944 unsigned n_paths = parse_env_var (library_path, &paths, "/crtoffloadtable.o"); | |
945 | |
946 unsigned i; | |
947 for (i = 0; i < n_paths; i++) | |
948 if (access_check (paths[i], R_OK) == 0) | |
949 { | |
950 /* The linker will delete the filename we give it, so make a copy. */ | |
951 char *crtoffloadtable = make_temp_file (".crtoffloadtable.o"); | |
952 copy_file (crtoffloadtable, paths[i]); | |
953 printf ("%s\n", crtoffloadtable); | |
954 XDELETEVEC (crtoffloadtable); | |
955 break; | |
956 } | |
957 if (i == n_paths) | |
958 fatal_error (input_location, | |
959 "installation error, can't find crtoffloadtable.o"); | |
960 | |
961 free_array_of_ptrs ((void **) paths, n_paths); | |
962 } | |
963 | |
964 /* A subroutine of run_gcc. Examine the open file FD for lto sections with | |
965 name prefix PREFIX, at FILE_OFFSET, and store any options we find in OPTS | |
966 and OPT_COUNT. Return true if we found a matchingn section, false | |
967 otherwise. COLLECT_GCC holds the value of the environment variable with | |
968 the same name. */ | |
969 | |
970 static bool | |
971 find_and_merge_options (int fd, off_t file_offset, const char *prefix, | |
972 struct cl_decoded_option **opts, | |
973 unsigned int *opt_count, const char *collect_gcc) | |
974 { | |
975 off_t offset, length; | |
976 char *data; | |
977 char *fopts; | |
978 const char *errmsg; | |
979 int err; | |
980 struct cl_decoded_option *fdecoded_options = *opts; | |
981 unsigned int fdecoded_options_count = *opt_count; | |
982 | |
983 simple_object_read *sobj; | |
984 sobj = simple_object_start_read (fd, file_offset, "__GNU_LTO", | |
985 &errmsg, &err); | |
986 if (!sobj) | |
987 return false; | |
988 | |
989 char *secname = XALLOCAVEC (char, strlen (prefix) + sizeof (".opts")); | |
990 strcpy (secname, prefix); | |
991 strcat (secname, ".opts"); | |
992 if (!simple_object_find_section (sobj, secname, &offset, &length, | |
993 &errmsg, &err)) | |
994 { | |
995 simple_object_release_read (sobj); | |
996 return false; | |
997 } | |
998 | |
999 lseek (fd, file_offset + offset, SEEK_SET); | |
1000 data = (char *)xmalloc (length); | |
1001 read (fd, data, length); | |
1002 fopts = data; | |
1003 do | |
1004 { | |
1005 struct cl_decoded_option *f2decoded_options; | |
1006 unsigned int f2decoded_options_count; | |
1007 get_options_from_collect_gcc_options (collect_gcc, | |
1008 fopts, CL_LANG_ALL, | |
1009 &f2decoded_options, | |
1010 &f2decoded_options_count); | |
1011 if (!fdecoded_options) | |
1012 { | |
1013 fdecoded_options = f2decoded_options; | |
1014 fdecoded_options_count = f2decoded_options_count; | |
1015 } | |
1016 else | |
1017 merge_and_complain (&fdecoded_options, | |
1018 &fdecoded_options_count, | |
1019 f2decoded_options, f2decoded_options_count); | |
1020 | |
1021 fopts += strlen (fopts) + 1; | |
1022 } | |
1023 while (fopts - data < length); | |
1024 | |
1025 free (data); | |
1026 simple_object_release_read (sobj); | |
1027 *opts = fdecoded_options; | |
1028 *opt_count = fdecoded_options_count; | |
1029 return true; | |
1030 } | |
1031 | |
1032 /* Copy early debug info sections from INFILE to a new file whose name | |
1033 is returned. Return NULL on error. */ | |
1034 | |
1035 const char * | |
131 | 1036 debug_objcopy (const char *infile, bool rename) |
111 | 1037 { |
1038 const char *outfile; | |
1039 const char *errmsg; | |
1040 int err; | |
1041 | |
1042 const char *p; | |
1043 off_t inoff = 0; | |
1044 long loffset; | |
1045 int consumed; | |
1046 if ((p = strrchr (infile, '@')) | |
1047 && p != infile | |
1048 && sscanf (p, "@%li%n", &loffset, &consumed) >= 1 | |
1049 && strlen (p) == (unsigned int) consumed) | |
1050 { | |
1051 char *fname = xstrdup (infile); | |
1052 fname[p - infile] = '\0'; | |
1053 infile = fname; | |
1054 inoff = (off_t) loffset; | |
1055 } | |
131 | 1056 int infd = open (infile, O_RDONLY | O_BINARY); |
111 | 1057 if (infd == -1) |
1058 return NULL; | |
1059 simple_object_read *inobj = simple_object_start_read (infd, inoff, | |
1060 "__GNU_LTO", | |
1061 &errmsg, &err); | |
1062 if (!inobj) | |
1063 return NULL; | |
1064 | |
1065 off_t off, len; | |
1066 if (simple_object_find_section (inobj, ".gnu.debuglto_.debug_info", | |
1067 &off, &len, &errmsg, &err) != 1) | |
1068 { | |
1069 if (errmsg) | |
1070 fatal_error (0, "%s: %s\n", errmsg, xstrerror (err)); | |
1071 | |
1072 simple_object_release_read (inobj); | |
1073 close (infd); | |
1074 return NULL; | |
1075 } | |
1076 | |
1077 outfile = make_temp_file ("debugobjtem"); | |
131 | 1078 errmsg = simple_object_copy_lto_debug_sections (inobj, outfile, &err, rename); |
111 | 1079 if (errmsg) |
1080 { | |
1081 unlink_if_ordinary (outfile); | |
1082 fatal_error (0, "%s: %s\n", errmsg, xstrerror (err)); | |
1083 } | |
1084 | |
1085 simple_object_release_read (inobj); | |
1086 close (infd); | |
1087 | |
1088 return outfile; | |
1089 } | |
1090 | |
131 | 1091 /* Helper for qsort: compare priorities for parallel compilation. */ |
1092 | |
1093 int | |
1094 cmp_priority (const void *a, const void *b) | |
1095 { | |
1096 return *((const int *)b)-*((const int *)a); | |
1097 } | |
111 | 1098 |
1099 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1100 /* Execute gcc. ARGC is the number of arguments. ARGV contains the arguments. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1101 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1102 static void |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1103 run_gcc (unsigned argc, char *argv[]) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1104 { |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1105 unsigned i, j; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1106 const char **new_argv; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1107 const char **argv_ptr; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1108 char *list_option_full = NULL; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1109 const char *linker_output = NULL; |
111 | 1110 const char *collect_gcc, *collect_gcc_options; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1111 int parallel = 0; |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1112 int jobserver = 0; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1113 bool no_partition = false; |
111 | 1114 struct cl_decoded_option *fdecoded_options = NULL; |
1115 struct cl_decoded_option *offload_fdecoded_options = NULL; | |
1116 unsigned int fdecoded_options_count = 0; | |
1117 unsigned int offload_fdecoded_options_count = 0; | |
1118 struct cl_decoded_option *decoded_options; | |
1119 unsigned int decoded_options_count; | |
1120 struct obstack argv_obstack; | |
1121 int new_head_argc; | |
1122 bool have_lto = false; | |
1123 bool have_offload = false; | |
1124 unsigned lto_argc = 0, ltoobj_argc = 0; | |
1125 char **lto_argv, **ltoobj_argv; | |
131 | 1126 bool linker_output_rel = false; |
111 | 1127 bool skip_debug = false; |
1128 unsigned n_debugobj; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1129 |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1130 /* Get the driver and options. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1131 collect_gcc = getenv ("COLLECT_GCC"); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1132 if (!collect_gcc) |
111 | 1133 fatal_error (input_location, |
1134 "environment variable COLLECT_GCC must be set"); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1135 collect_gcc_options = getenv ("COLLECT_GCC_OPTIONS"); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1136 if (!collect_gcc_options) |
111 | 1137 fatal_error (input_location, |
1138 "environment variable COLLECT_GCC_OPTIONS must be set"); | |
1139 get_options_from_collect_gcc_options (collect_gcc, collect_gcc_options, | |
1140 CL_LANG_ALL, | |
1141 &decoded_options, | |
1142 &decoded_options_count); | |
1143 | |
1144 /* Allocate array for input object files with LTO IL, | |
1145 and for possible preceding arguments. */ | |
1146 lto_argv = XNEWVEC (char *, argc); | |
1147 ltoobj_argv = XNEWVEC (char *, argc); | |
1148 | |
1149 /* Look at saved options in the IL files. */ | |
1150 for (i = 1; i < argc; ++i) | |
1151 { | |
1152 char *p; | |
1153 int fd; | |
1154 off_t file_offset = 0; | |
1155 long loffset; | |
1156 int consumed; | |
1157 char *filename = argv[i]; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1158 |
111 | 1159 if (strncmp (argv[i], "-foffload-objects=", |
1160 sizeof ("-foffload-objects=") - 1) == 0) | |
1161 { | |
1162 have_offload = true; | |
1163 offload_objects_file_name | |
1164 = argv[i] + sizeof ("-foffload-objects=") - 1; | |
1165 continue; | |
1166 } | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1167 |
111 | 1168 if ((p = strrchr (argv[i], '@')) |
1169 && p != argv[i] | |
1170 && sscanf (p, "@%li%n", &loffset, &consumed) >= 1 | |
1171 && strlen (p) == (unsigned int) consumed) | |
1172 { | |
1173 filename = XNEWVEC (char, p - argv[i] + 1); | |
1174 memcpy (filename, argv[i], p - argv[i]); | |
1175 filename[p - argv[i]] = '\0'; | |
1176 file_offset = (off_t) loffset; | |
1177 } | |
1178 fd = open (filename, O_RDONLY | O_BINARY); | |
131 | 1179 /* Linker plugin passes -fresolution and -flinker-output options. |
1180 -flinker-output is passed only when user did not specify one and thus | |
1181 we do not need to worry about duplicities with the option handling | |
1182 below. */ | |
111 | 1183 if (fd == -1) |
1184 { | |
1185 lto_argv[lto_argc++] = argv[i]; | |
131 | 1186 if (strcmp (argv[i], "-flinker-output=rel") == 0) |
1187 linker_output_rel = true; | |
111 | 1188 continue; |
1189 } | |
1190 | |
1191 if (find_and_merge_options (fd, file_offset, LTO_SECTION_NAME_PREFIX, | |
1192 &fdecoded_options, &fdecoded_options_count, | |
1193 collect_gcc)) | |
1194 { | |
1195 have_lto = true; | |
1196 ltoobj_argv[ltoobj_argc++] = argv[i]; | |
1197 } | |
1198 close (fd); | |
1199 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1200 |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1201 /* Initalize the common arguments for the driver. */ |
111 | 1202 obstack_init (&argv_obstack); |
1203 obstack_ptr_grow (&argv_obstack, collect_gcc); | |
1204 obstack_ptr_grow (&argv_obstack, "-xlto"); | |
1205 obstack_ptr_grow (&argv_obstack, "-c"); | |
1206 | |
1207 append_compiler_options (&argv_obstack, fdecoded_options, | |
1208 fdecoded_options_count); | |
1209 append_linker_options (&argv_obstack, decoded_options, decoded_options_count); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1210 |
111 | 1211 /* Scan linker driver arguments for things that are of relevance to us. */ |
1212 for (j = 1; j < decoded_options_count; ++j) | |
1213 { | |
1214 struct cl_decoded_option *option = &decoded_options[j]; | |
1215 switch (option->opt_index) | |
1216 { | |
1217 case OPT_o: | |
1218 linker_output = option->arg; | |
1219 break; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1220 |
111 | 1221 case OPT_save_temps: |
1222 save_temps = 1; | |
1223 break; | |
1224 | |
1225 case OPT_v: | |
1226 verbose = 1; | |
1227 break; | |
1228 | |
1229 case OPT_flto_partition_: | |
1230 if (strcmp (option->arg, "none") == 0) | |
1231 no_partition = true; | |
1232 break; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1233 |
111 | 1234 case OPT_flto_: |
1235 if (strcmp (option->arg, "jobserver") == 0) | |
1236 { | |
1237 jobserver = 1; | |
1238 parallel = 1; | |
1239 } | |
1240 else | |
1241 { | |
1242 parallel = atoi (option->arg); | |
1243 if (parallel <= 1) | |
1244 parallel = 0; | |
1245 } | |
1246 /* Fallthru. */ | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1247 |
111 | 1248 case OPT_flto: |
1249 lto_mode = LTO_MODE_WHOPR; | |
1250 break; | |
1251 | |
131 | 1252 case OPT_flinker_output_: |
1253 linker_output_rel = !strcmp (option->arg, "rel"); | |
1254 break; | |
1255 | |
1256 | |
111 | 1257 default: |
1258 break; | |
1259 } | |
1260 } | |
1261 | |
1262 /* Output lto-wrapper invocation command. */ | |
1263 if (verbose) | |
1264 { | |
1265 for (i = 0; i < argc; ++i) | |
1266 { | |
1267 fputs (argv[i], stderr); | |
1268 fputc (' ', stderr); | |
1269 } | |
1270 fputc ('\n', stderr); | |
1271 } | |
1272 | |
131 | 1273 if (linker_output_rel) |
1274 no_partition = true; | |
1275 | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1276 if (no_partition) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1277 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1278 lto_mode = LTO_MODE_LTO; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1279 jobserver = 0; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1280 parallel = 0; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1281 } |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1282 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1283 if (linker_output) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1284 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1285 char *output_dir, *base, *name; |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1286 bool bit_bucket = strcmp (linker_output, HOST_BIT_BUCKET) == 0; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1287 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1288 output_dir = xstrdup (linker_output); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1289 base = output_dir; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1290 for (name = base; *name; name++) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1291 if (IS_DIR_SEPARATOR (*name)) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1292 base = name + 1; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1293 *base = '\0'; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1294 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1295 linker_output = &linker_output[base - output_dir]; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1296 if (*output_dir == '\0') |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1297 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1298 static char current_dir[] = { '.', DIR_SEPARATOR, '\0' }; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1299 output_dir = current_dir; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1300 } |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1301 if (!bit_bucket) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1302 { |
111 | 1303 obstack_ptr_grow (&argv_obstack, "-dumpdir"); |
1304 obstack_ptr_grow (&argv_obstack, output_dir); | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1305 } |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1306 |
111 | 1307 obstack_ptr_grow (&argv_obstack, "-dumpbase"); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1308 } |
111 | 1309 |
1310 /* Remember at which point we can scrub args to re-use the commons. */ | |
1311 new_head_argc = obstack_object_size (&argv_obstack) / sizeof (void *); | |
1312 | |
1313 if (have_offload) | |
1314 { | |
1315 unsigned i, num_offload_files; | |
1316 char **offload_argv; | |
1317 FILE *f; | |
1318 | |
1319 f = fopen (offload_objects_file_name, "r"); | |
1320 if (f == NULL) | |
1321 fatal_error (input_location, "cannot open %s: %m", | |
1322 offload_objects_file_name); | |
1323 if (fscanf (f, "%u ", &num_offload_files) != 1) | |
1324 fatal_error (input_location, "cannot read %s: %m", | |
1325 offload_objects_file_name); | |
1326 offload_argv = XCNEWVEC (char *, num_offload_files); | |
1327 | |
1328 /* Read names of object files with offload. */ | |
1329 for (i = 0; i < num_offload_files; i++) | |
1330 { | |
1331 const unsigned piece = 32; | |
1332 char *buf, *filename = XNEWVEC (char, piece); | |
1333 size_t len; | |
1334 | |
1335 buf = filename; | |
1336 cont1: | |
1337 if (!fgets (buf, piece, f)) | |
1338 break; | |
1339 len = strlen (filename); | |
1340 if (filename[len - 1] != '\n') | |
1341 { | |
1342 filename = XRESIZEVEC (char, filename, len + piece); | |
1343 buf = filename + len; | |
1344 goto cont1; | |
1345 } | |
1346 filename[len - 1] = '\0'; | |
1347 offload_argv[i] = filename; | |
1348 } | |
1349 fclose (f); | |
1350 if (offload_argv[num_offload_files - 1] == NULL) | |
1351 fatal_error (input_location, "invalid format of %s", | |
1352 offload_objects_file_name); | |
1353 maybe_unlink (offload_objects_file_name); | |
1354 offload_objects_file_name = NULL; | |
1355 | |
1356 /* Look at saved offload options in files. */ | |
1357 for (i = 0; i < num_offload_files; i++) | |
1358 { | |
1359 char *p; | |
1360 long loffset; | |
1361 int fd, consumed; | |
1362 off_t file_offset = 0; | |
1363 char *filename = offload_argv[i]; | |
1364 | |
1365 if ((p = strrchr (offload_argv[i], '@')) | |
1366 && p != offload_argv[i] | |
1367 && sscanf (p, "@%li%n", &loffset, &consumed) >= 1 | |
1368 && strlen (p) == (unsigned int) consumed) | |
1369 { | |
1370 filename = XNEWVEC (char, p - offload_argv[i] + 1); | |
1371 memcpy (filename, offload_argv[i], p - offload_argv[i]); | |
1372 filename[p - offload_argv[i]] = '\0'; | |
1373 file_offset = (off_t) loffset; | |
1374 } | |
1375 fd = open (filename, O_RDONLY | O_BINARY); | |
1376 if (fd == -1) | |
1377 fatal_error (input_location, "cannot open %s: %m", filename); | |
1378 if (!find_and_merge_options (fd, file_offset, | |
1379 OFFLOAD_SECTION_NAME_PREFIX, | |
1380 &offload_fdecoded_options, | |
1381 &offload_fdecoded_options_count, | |
1382 collect_gcc)) | |
1383 fatal_error (input_location, "cannot read %s: %m", filename); | |
1384 close (fd); | |
1385 if (filename != offload_argv[i]) | |
1386 XDELETEVEC (filename); | |
1387 } | |
1388 | |
1389 compile_images_for_offload_targets (num_offload_files, offload_argv, | |
1390 offload_fdecoded_options, | |
1391 offload_fdecoded_options_count, | |
1392 decoded_options, | |
1393 decoded_options_count); | |
1394 | |
1395 free_array_of_ptrs ((void **) offload_argv, num_offload_files); | |
1396 | |
1397 if (offload_names) | |
1398 { | |
1399 find_crtoffloadtable (); | |
1400 for (i = 0; offload_names[i]; i++) | |
1401 printf ("%s\n", offload_names[i]); | |
1402 free_array_of_ptrs ((void **) offload_names, i); | |
1403 } | |
1404 } | |
1405 | |
1406 /* If object files contain offload sections, but do not contain LTO sections, | |
1407 then there is no need to perform a link-time recompilation, i.e. | |
1408 lto-wrapper is used only for a compilation of offload images. */ | |
1409 if (have_offload && !have_lto) | |
1410 goto finish; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1411 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1412 if (lto_mode == LTO_MODE_LTO) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1413 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1414 flto_out = make_temp_file (".lto.o"); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1415 if (linker_output) |
111 | 1416 obstack_ptr_grow (&argv_obstack, linker_output); |
1417 obstack_ptr_grow (&argv_obstack, "-o"); | |
1418 obstack_ptr_grow (&argv_obstack, flto_out); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1419 } |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1420 else |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1421 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1422 const char *list_option = "-fltrans-output-list="; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1423 size_t list_option_len = strlen (list_option); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1424 char *tmp; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1425 |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1426 if (linker_output) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1427 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1428 char *dumpbase = (char *) xmalloc (strlen (linker_output) |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1429 + sizeof (".wpa") + 1); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1430 strcpy (dumpbase, linker_output); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1431 strcat (dumpbase, ".wpa"); |
111 | 1432 obstack_ptr_grow (&argv_obstack, dumpbase); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1433 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1434 |
111 | 1435 if (linker_output && save_temps) |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1436 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1437 ltrans_output_file = (char *) xmalloc (strlen (linker_output) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1438 + sizeof (".ltrans.out") + 1); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1439 strcpy (ltrans_output_file, linker_output); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1440 strcat (ltrans_output_file, ".ltrans.out"); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1441 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1442 else |
131 | 1443 { |
1444 char *prefix = NULL; | |
1445 if (linker_output) | |
1446 { | |
1447 prefix = (char *) xmalloc (strlen (linker_output) + 2); | |
1448 strcpy (prefix, linker_output); | |
1449 strcat (prefix, "."); | |
1450 } | |
1451 | |
1452 ltrans_output_file = make_temp_file_with_prefix (prefix, | |
1453 ".ltrans.out"); | |
1454 free (prefix); | |
1455 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1456 list_option_full = (char *) xmalloc (sizeof (char) * |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1457 (strlen (ltrans_output_file) + list_option_len + 1)); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1458 tmp = list_option_full; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1459 |
111 | 1460 obstack_ptr_grow (&argv_obstack, tmp); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1461 strcpy (tmp, list_option); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1462 tmp += list_option_len; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1463 strcpy (tmp, ltrans_output_file); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1464 |
111 | 1465 if (jobserver) |
1466 obstack_ptr_grow (&argv_obstack, xstrdup ("-fwpa=jobserver")); | |
1467 else if (parallel > 1) | |
1468 { | |
1469 char buf[256]; | |
1470 sprintf (buf, "-fwpa=%i", parallel); | |
1471 obstack_ptr_grow (&argv_obstack, xstrdup (buf)); | |
1472 } | |
1473 else | |
1474 obstack_ptr_grow (&argv_obstack, "-fwpa"); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1475 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1476 |
111 | 1477 /* Append input arguments. */ |
1478 for (i = 0; i < lto_argc; ++i) | |
1479 obstack_ptr_grow (&argv_obstack, lto_argv[i]); | |
1480 /* Append the input objects. */ | |
1481 for (i = 0; i < ltoobj_argc; ++i) | |
1482 obstack_ptr_grow (&argv_obstack, ltoobj_argv[i]); | |
1483 obstack_ptr_grow (&argv_obstack, NULL); | |
1484 | |
1485 new_argv = XOBFINISH (&argv_obstack, const char **); | |
1486 argv_ptr = &new_argv[new_head_argc]; | |
1487 fork_execute (new_argv[0], CONST_CAST (char **, new_argv), true); | |
1488 | |
1489 /* Handle early generated debug information. At compile-time | |
1490 we output early DWARF debug info into .gnu.debuglto_ prefixed | |
1491 sections. LTRANS object DWARF debug info refers to that. | |
1492 So we need to transfer the .gnu.debuglto_ sections to the final | |
1493 link. Ideally the linker plugin interface would allow us to | |
1494 not claim those sections and instruct the linker to keep | |
1495 them, renaming them in the process. For now we extract and | |
1496 rename those sections via a simple-object interface to produce | |
1497 regular objects containing only the early debug info. We | |
1498 then partially link those to a single early debug info object | |
1499 and pass that as additional output back to the linker plugin. */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1500 |
111 | 1501 /* Prepare the partial link to gather the compile-time generated |
1502 debug-info into a single input for the final link. */ | |
1503 debug_obj = make_temp_file ("debugobj"); | |
1504 obstack_ptr_grow (&argv_obstack, collect_gcc); | |
1505 for (i = 1; i < decoded_options_count; ++i) | |
1506 { | |
1507 /* Retain linker choice and -B. */ | |
1508 if (decoded_options[i].opt_index == OPT_B | |
1509 || decoded_options[i].opt_index == OPT_fuse_ld_bfd | |
1510 || decoded_options[i].opt_index == OPT_fuse_ld_gold) | |
1511 append_linker_options (&argv_obstack, &decoded_options[i-1], 2); | |
1512 /* Retain all target options, this preserves -m32 for example. */ | |
1513 if (cl_options[decoded_options[i].opt_index].flags & CL_TARGET) | |
1514 append_linker_options (&argv_obstack, &decoded_options[i-1], 2); | |
1515 /* Recognize -g0. */ | |
1516 if (decoded_options[i].opt_index == OPT_g | |
1517 && strcmp (decoded_options[i].arg, "0") == 0) | |
1518 skip_debug = true; | |
1519 } | |
1520 obstack_ptr_grow (&argv_obstack, "-r"); | |
1521 obstack_ptr_grow (&argv_obstack, "-nostdlib"); | |
1522 obstack_ptr_grow (&argv_obstack, "-o"); | |
1523 obstack_ptr_grow (&argv_obstack, debug_obj); | |
1524 | |
1525 /* Copy the early generated debug info from the objects to temporary | |
1526 files and append those to the partial link commandline. */ | |
1527 n_debugobj = 0; | |
1528 if (! skip_debug) | |
1529 for (i = 0; i < ltoobj_argc; ++i) | |
1530 { | |
1531 const char *tem; | |
131 | 1532 if ((tem = debug_objcopy (ltoobj_argv[i], !linker_output_rel))) |
111 | 1533 { |
1534 obstack_ptr_grow (&argv_obstack, tem); | |
1535 n_debugobj++; | |
1536 } | |
1537 } | |
1538 | |
1539 /* Link them all into a single object. Ideally this would reduce | |
1540 disk space usage mainly due to .debug_str merging but unfortunately | |
1541 GNU ld doesn't perform this with -r. */ | |
1542 if (n_debugobj) | |
1543 { | |
1544 obstack_ptr_grow (&argv_obstack, NULL); | |
1545 const char **debug_link_argv = XOBFINISH (&argv_obstack, const char **); | |
1546 fork_execute (debug_link_argv[0], | |
1547 CONST_CAST (char **, debug_link_argv), false); | |
1548 | |
1549 /* And dispose the temporaries. */ | |
1550 for (i = 0; debug_link_argv[i]; ++i) | |
1551 ; | |
1552 for (--i; i > 0; --i) | |
1553 { | |
1554 if (strcmp (debug_link_argv[i], debug_obj) == 0) | |
1555 break; | |
1556 maybe_unlink (debug_link_argv[i]); | |
1557 } | |
1558 } | |
1559 else | |
1560 { | |
1561 unlink_if_ordinary (debug_obj); | |
1562 free (debug_obj); | |
1563 debug_obj = NULL; | |
1564 skip_debug = true; | |
1565 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1566 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1567 if (lto_mode == LTO_MODE_LTO) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1568 { |
111 | 1569 printf ("%s\n", flto_out); |
1570 if (!skip_debug) | |
1571 { | |
1572 printf ("%s\n", debug_obj); | |
1573 free (debug_obj); | |
1574 debug_obj = NULL; | |
1575 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1576 free (flto_out); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1577 flto_out = NULL; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1578 } |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1579 else |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1580 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1581 FILE *stream = fopen (ltrans_output_file, "r"); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1582 FILE *mstream = NULL; |
111 | 1583 struct obstack env_obstack; |
131 | 1584 int priority; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1585 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1586 if (!stream) |
111 | 1587 fatal_error (input_location, "fopen: %s: %m", ltrans_output_file); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1588 |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1589 /* Parse the list of LTRANS inputs from the WPA stage. */ |
111 | 1590 obstack_init (&env_obstack); |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1591 nr = 0; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1592 for (;;) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1593 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1594 const unsigned piece = 32; |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1595 char *output_name = NULL; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1596 char *buf, *input_name = (char *)xmalloc (piece); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1597 size_t len; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1598 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1599 buf = input_name; |
131 | 1600 if (fscanf (stream, "%i\n", &priority) != 1) |
1601 { | |
1602 if (!feof (stream)) | |
1603 fatal_error (input_location, | |
1604 "Corrupted ltrans output file %s", | |
1605 ltrans_output_file); | |
1606 break; | |
1607 } | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1608 cont: |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1609 if (!fgets (buf, piece, stream)) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1610 break; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1611 len = strlen (input_name); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1612 if (input_name[len - 1] != '\n') |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1613 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1614 input_name = (char *)xrealloc (input_name, len + piece); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1615 buf = input_name + len; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1616 goto cont; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1617 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1618 input_name[len - 1] = '\0'; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1619 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1620 if (input_name[0] == '*') |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1621 output_name = &input_name[1]; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1622 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1623 nr++; |
131 | 1624 ltrans_priorities |
1625 = (int *)xrealloc (ltrans_priorities, nr * sizeof (int) * 2); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1626 input_names = (char **)xrealloc (input_names, nr * sizeof (char *)); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1627 output_names = (char **)xrealloc (output_names, nr * sizeof (char *)); |
131 | 1628 ltrans_priorities[(nr-1)*2] = priority; |
1629 ltrans_priorities[(nr-1)*2+1] = nr-1; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1630 input_names[nr-1] = input_name; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1631 output_names[nr-1] = output_name; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1632 } |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1633 fclose (stream); |
111 | 1634 maybe_unlink (ltrans_output_file); |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1635 ltrans_output_file = NULL; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1636 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1637 if (parallel) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1638 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1639 makefile = make_temp_file (".mk"); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1640 mstream = fopen (makefile, "w"); |
131 | 1641 qsort (ltrans_priorities, nr, sizeof (int) * 2, cmp_priority); |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1642 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1643 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1644 /* Execute the LTRANS stage for each input file (or prepare a |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1645 makefile to invoke this in parallel). */ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1646 for (i = 0; i < nr; ++i) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1647 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1648 char *output_name; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1649 char *input_name = input_names[i]; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1650 /* If it's a pass-through file do nothing. */ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1651 if (output_names[i]) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1652 continue; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1653 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1654 /* Replace the .o suffix with a .ltrans.o suffix and write |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1655 the resulting name to the LTRANS output list. */ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1656 obstack_grow (&env_obstack, input_name, strlen (input_name) - 2); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1657 obstack_grow (&env_obstack, ".ltrans.o", sizeof (".ltrans.o")); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1658 output_name = XOBFINISH (&env_obstack, char *); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1659 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1660 /* Adjust the dumpbase if the linker output file was seen. */ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1661 if (linker_output) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1662 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1663 char *dumpbase |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1664 = (char *) xmalloc (strlen (linker_output) |
111 | 1665 + sizeof (DUMPBASE_SUFFIX) + 1); |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1666 snprintf (dumpbase, |
111 | 1667 strlen (linker_output) + sizeof (DUMPBASE_SUFFIX), |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1668 "%s.ltrans%u", linker_output, i); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1669 argv_ptr[0] = dumpbase; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1670 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1671 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1672 argv_ptr[1] = "-fltrans"; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1673 argv_ptr[2] = "-o"; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1674 argv_ptr[3] = output_name; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1675 argv_ptr[4] = input_name; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1676 argv_ptr[5] = NULL; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1677 if (parallel) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1678 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1679 fprintf (mstream, "%s:\n\t@%s ", output_name, new_argv[0]); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1680 for (j = 1; new_argv[j] != NULL; ++j) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1681 fprintf (mstream, " '%s'", new_argv[j]); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1682 fprintf (mstream, "\n"); |
111 | 1683 /* If we are not preserving the ltrans input files then |
1684 truncate them as soon as we have processed it. This | |
1685 reduces temporary disk-space usage. */ | |
1686 if (! save_temps) | |
1687 fprintf (mstream, "\t@-touch -r %s %s.tem > /dev/null 2>&1 " | |
1688 "&& mv %s.tem %s\n", | |
1689 input_name, input_name, input_name, input_name); | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1690 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1691 else |
111 | 1692 { |
1693 fork_execute (new_argv[0], CONST_CAST (char **, new_argv), | |
1694 true); | |
1695 maybe_unlink (input_name); | |
1696 } | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1697 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1698 output_names[i] = output_name; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1699 } |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1700 if (parallel) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1701 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1702 struct pex_obj *pex; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1703 char jobs[32]; |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1704 |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1705 fprintf (mstream, "all:"); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1706 for (i = 0; i < nr; ++i) |
131 | 1707 { |
1708 int j = ltrans_priorities[i*2 + 1]; | |
1709 fprintf (mstream, " \\\n\t%s", output_names[j]); | |
1710 } | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1711 fprintf (mstream, "\n"); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1712 fclose (mstream); |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1713 if (!jobserver) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1714 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1715 /* Avoid passing --jobserver-fd= and similar flags |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1716 unless jobserver mode is explicitly enabled. */ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1717 putenv (xstrdup ("MAKEFLAGS=")); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1718 putenv (xstrdup ("MFLAGS=")); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1719 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1720 new_argv[0] = getenv ("MAKE"); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1721 if (!new_argv[0]) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1722 new_argv[0] = "make"; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1723 new_argv[1] = "-f"; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1724 new_argv[2] = makefile; |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1725 i = 3; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1726 if (!jobserver) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1727 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1728 snprintf (jobs, 31, "-j%d", parallel); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1729 new_argv[i++] = jobs; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1730 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1731 new_argv[i++] = "all"; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1732 new_argv[i++] = NULL; |
111 | 1733 pex = collect_execute (new_argv[0], CONST_CAST (char **, new_argv), |
1734 NULL, NULL, PEX_SEARCH, false); | |
1735 do_wait (new_argv[0], pex); | |
1736 maybe_unlink (makefile); | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1737 makefile = NULL; |
111 | 1738 for (i = 0; i < nr; ++i) |
1739 maybe_unlink (input_names[i]); | |
1740 } | |
1741 if (!skip_debug) | |
1742 { | |
1743 printf ("%s\n", debug_obj); | |
1744 free (debug_obj); | |
1745 debug_obj = NULL; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1746 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1747 for (i = 0; i < nr; ++i) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1748 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1749 fputs (output_names[i], stdout); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1750 putc ('\n', stdout); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1751 free (input_names[i]); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1752 } |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1753 nr = 0; |
131 | 1754 free (ltrans_priorities); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1755 free (output_names); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1756 free (input_names); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1757 free (list_option_full); |
111 | 1758 obstack_free (&env_obstack, NULL); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1759 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1760 |
111 | 1761 finish: |
1762 XDELETE (lto_argv); | |
1763 obstack_free (&argv_obstack, NULL); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1764 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1765 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1766 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1767 /* Entry point. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1768 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1769 int |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1770 main (int argc, char *argv[]) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1771 { |
111 | 1772 const char *p; |
1773 | |
1774 init_opts_obstack (); | |
1775 | |
1776 p = argv[0] + strlen (argv[0]); | |
1777 while (p != argv[0] && !IS_DIR_SEPARATOR (p[-1])) | |
1778 --p; | |
1779 progname = p; | |
1780 | |
1781 xmalloc_set_program_name (progname); | |
1782 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1783 gcc_init_libintl (); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1784 |
111 | 1785 diagnostic_initialize (global_dc, 0); |
1786 | |
1787 if (atexit (lto_wrapper_cleanup) != 0) | |
1788 fatal_error (input_location, "atexit failed"); | |
1789 | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1790 if (signal (SIGINT, SIG_IGN) != SIG_IGN) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1791 signal (SIGINT, fatal_signal); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1792 #ifdef SIGHUP |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1793 if (signal (SIGHUP, SIG_IGN) != SIG_IGN) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1794 signal (SIGHUP, fatal_signal); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1795 #endif |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1796 if (signal (SIGTERM, SIG_IGN) != SIG_IGN) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1797 signal (SIGTERM, fatal_signal); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1798 #ifdef SIGPIPE |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1799 if (signal (SIGPIPE, SIG_IGN) != SIG_IGN) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1800 signal (SIGPIPE, fatal_signal); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1801 #endif |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1802 #ifdef SIGCHLD |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1803 /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1804 receive the signal. A different setting is inheritable */ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1805 signal (SIGCHLD, SIG_DFL); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1806 #endif |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1807 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1808 /* We may be called with all the arguments stored in some file and |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1809 passed with @file. Expand them into argv before processing. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1810 expandargv (&argc, &argv); |
111 | 1811 |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1812 run_gcc (argc, argv); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1813 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1814 return 0; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1815 } |