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