Mercurial > hg > CbC > CbC_gcc
annotate gcc/collect2.c @ 158:494b0b89df80 default tip
...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 25 May 2020 18:13:55 +0900 |
parents | 1830386684a0 |
children |
rev | line source |
---|---|
0 | 1 /* Collect static initialization info into data structures that can be |
2 traversed by C++ initialization and finalization routines. | |
145 | 3 Copyright (C) 1992-2020 Free Software Foundation, Inc. |
0 | 4 Contributed by Chris Smith (csmith@convex.com). |
5 Heavily modified by Michael Meissner (meissner@cygnus.com), | |
6 Per Bothner (bothner@cygnus.com), and John Gilmore (gnu@cygnus.com). | |
7 | |
8 This file is part of GCC. | |
9 | |
10 GCC is free software; you can redistribute it and/or modify it under | |
11 the terms of the GNU General Public License as published by the Free | |
12 Software Foundation; either version 3, or (at your option) any later | |
13 version. | |
14 | |
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
18 for more details. | |
19 | |
20 You should have received a copy of the GNU General Public License | |
21 along with GCC; see the file COPYING3. If not see | |
22 <http://www.gnu.org/licenses/>. */ | |
23 | |
24 | |
25 /* Build tables of static constructors and destructors and run ld. */ | |
26 | |
27 #include "config.h" | |
28 #include "system.h" | |
29 #include "coretypes.h" | |
30 #include "tm.h" | |
111 | 31 #include "filenames.h" |
32 #include "file-find.h" | |
145 | 33 #include "simple-object.h" |
34 #include "lto-section-names.h" | |
0 | 35 |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
36 /* TARGET_64BIT may be defined to use driver specific functionality. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
37 #undef TARGET_64BIT |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
38 #define TARGET_64BIT TARGET_64BIT_DEFAULT |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
39 |
0 | 40 #ifndef LIBRARY_PATH_ENV |
41 #define LIBRARY_PATH_ENV "LIBRARY_PATH" | |
42 #endif | |
43 | |
44 #define COLLECT | |
45 | |
46 #include "collect2.h" | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
47 #include "collect2-aix.h" |
111 | 48 #include "collect-utils.h" |
49 #include "diagnostic.h" | |
0 | 50 #include "demangle.h" |
51 #include "obstack.h" | |
52 #include "intl.h" | |
53 #include "version.h" | |
54 | |
55 /* On certain systems, we have code that works by scanning the object file | |
56 directly. But this code uses system-specific header files and library | |
57 functions, so turn it off in a cross-compiler. Likewise, the names of | |
58 the utilities are not correct for a cross-compiler; we have to hope that | |
59 cross-versions are in the proper directories. */ | |
60 | |
61 #ifdef CROSS_DIRECTORY_STRUCTURE | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
62 #ifndef CROSS_AIX_SUPPORT |
0 | 63 #undef OBJECT_FORMAT_COFF |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
64 #endif |
0 | 65 #undef MD_EXEC_PREFIX |
66 #undef REAL_LD_FILE_NAME | |
67 #undef REAL_NM_FILE_NAME | |
68 #undef REAL_STRIP_FILE_NAME | |
69 #endif | |
70 | |
71 /* If we cannot use a special method, use the ordinary one: | |
72 run nm to find what symbols are present. | |
73 In a cross-compiler, this means you need a cross nm, | |
74 but that is not quite as unpleasant as special headers. */ | |
75 | |
76 #if !defined (OBJECT_FORMAT_COFF) | |
77 #define OBJECT_FORMAT_NONE | |
78 #endif | |
79 | |
80 #ifdef OBJECT_FORMAT_COFF | |
81 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
82 #ifndef CROSS_DIRECTORY_STRUCTURE |
0 | 83 #include <a.out.h> |
84 #include <ar.h> | |
85 | |
86 #ifdef UMAX | |
87 #include <sgs.h> | |
88 #endif | |
89 | |
90 /* Many versions of ldfcn.h define these. */ | |
91 #ifdef FREAD | |
92 #undef FREAD | |
93 #undef FWRITE | |
94 #endif | |
95 | |
96 #include <ldfcn.h> | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
97 #endif |
0 | 98 |
99 /* Some systems have an ISCOFF macro, but others do not. In some cases | |
100 the macro may be wrong. MY_ISCOFF is defined in tm.h files for machines | |
101 that either do not have an ISCOFF macro in /usr/include or for those | |
102 where it is wrong. */ | |
103 | |
104 #ifndef MY_ISCOFF | |
105 #define MY_ISCOFF(X) ISCOFF (X) | |
106 #endif | |
107 | |
108 #endif /* OBJECT_FORMAT_COFF */ | |
109 | |
110 #ifdef OBJECT_FORMAT_NONE | |
111 | |
112 /* Default flags to pass to nm. */ | |
113 #ifndef NM_FLAGS | |
114 #define NM_FLAGS "-n" | |
115 #endif | |
116 | |
117 #endif /* OBJECT_FORMAT_NONE */ | |
118 | |
119 /* Some systems use __main in a way incompatible with its use in gcc, in these | |
120 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to | |
121 give the same symbol without quotes for an alternative entry point. */ | |
122 #ifndef NAME__MAIN | |
123 #define NAME__MAIN "__main" | |
124 #endif | |
125 | |
126 /* This must match tree.h. */ | |
127 #define DEFAULT_INIT_PRIORITY 65535 | |
128 | |
129 #ifndef COLLECT_SHARED_INIT_FUNC | |
130 #define COLLECT_SHARED_INIT_FUNC(STREAM, FUNC) \ | |
131 fprintf ((STREAM), "void _GLOBAL__DI() {\n\t%s();\n}\n", (FUNC)) | |
132 #endif | |
133 #ifndef COLLECT_SHARED_FINI_FUNC | |
134 #define COLLECT_SHARED_FINI_FUNC(STREAM, FUNC) \ | |
135 fprintf ((STREAM), "void _GLOBAL__DD() {\n\t%s();\n}\n", (FUNC)) | |
136 #endif | |
137 | |
138 #ifdef LDD_SUFFIX | |
139 #define SCAN_LIBRARIES | |
140 #endif | |
141 | |
142 #ifndef SHLIB_SUFFIX | |
143 #define SHLIB_SUFFIX ".so" | |
144 #endif | |
145 | |
146 #ifdef USE_COLLECT2 | |
147 int do_collecting = 1; | |
148 #else | |
149 int do_collecting = 0; | |
150 #endif | |
151 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
152 /* Cook up an always defined indication of whether we proceed the |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
153 "EXPORT_LIST" way. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
154 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
155 #ifdef COLLECT_EXPORT_LIST |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
156 #define DO_COLLECT_EXPORT_LIST 1 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
157 #else |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
158 #define DO_COLLECT_EXPORT_LIST 0 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
159 #endif |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
160 |
0 | 161 /* Nonzero if we should suppress the automatic demangling of identifiers |
162 in linker error messages. Set from COLLECT_NO_DEMANGLE. */ | |
163 int no_demangle; | |
164 | |
165 /* Linked lists of constructor and destructor names. */ | |
166 | |
167 struct id | |
168 { | |
169 struct id *next; | |
170 int sequence; | |
171 char name[1]; | |
172 }; | |
173 | |
174 struct head | |
175 { | |
176 struct id *first; | |
177 struct id *last; | |
178 int number; | |
179 }; | |
180 | |
181 static int rflag; /* true if -r */ | |
182 static int strip_flag; /* true if -s */ | |
183 #ifdef COLLECT_EXPORT_LIST | |
184 static int export_flag; /* true if -bE */ | |
185 static int aix64_flag; /* true if -b64 */ | |
186 static int aixrtl_flag; /* true if -brtl */ | |
111 | 187 static int aixlazy_flag; /* true if -blazy */ |
0 | 188 #endif |
189 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
190 enum lto_mode_d { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
191 LTO_MODE_NONE, /* Not doing LTO. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
192 LTO_MODE_LTO, /* Normal LTO. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
193 LTO_MODE_WHOPR /* WHOPR. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
194 }; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
195 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
196 /* Current LTO mode. */ |
111 | 197 #ifdef ENABLE_LTO |
198 static enum lto_mode_d lto_mode = LTO_MODE_WHOPR; | |
199 #else | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
200 static enum lto_mode_d lto_mode = LTO_MODE_NONE; |
111 | 201 #endif |
202 | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
203 bool helpflag; /* true if --help */ |
0 | 204 |
205 static int shared_obj; /* true if -shared */ | |
131 | 206 static int static_obj; /* true if -static */ |
0 | 207 |
145 | 208 static char *c_file; /* <xxx>.c for constructor/destructor list. */ |
209 static char *o_file; /* <xxx>.o for constructor/destructor list. */ | |
0 | 210 #ifdef COLLECT_EXPORT_LIST |
211 static const char *export_file; /* <xxx>.x for AIX export list. */ | |
212 #endif | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
213 static char **lto_o_files; /* Output files for LTO. */ |
0 | 214 const char *ldout; /* File for ld stdout. */ |
215 const char *lderrout; /* File for ld stderr. */ | |
216 static const char *output_file; /* Output file for ld. */ | |
217 static const char *nm_file_name; /* pathname of nm */ | |
218 #ifdef LDD_SUFFIX | |
219 static const char *ldd_file_name; /* pathname of ldd (or equivalent) */ | |
220 #endif | |
221 static const char *strip_file_name; /* pathname of strip */ | |
222 const char *c_file_name; /* pathname of gcc */ | |
223 static char *initname, *fininame; /* names of init and fini funcs */ | |
224 | |
111 | 225 |
226 #ifdef TARGET_AIX_VERSION | |
227 static char *aix_shared_initname; | |
228 static char *aix_shared_fininame; /* init/fini names as per the scheme | |
229 described in config/rs6000/aix.h */ | |
230 #endif | |
231 | |
0 | 232 static struct head constructors; /* list of constructors found */ |
233 static struct head destructors; /* list of destructors found */ | |
234 #ifdef COLLECT_EXPORT_LIST | |
235 static struct head exports; /* list of exported symbols */ | |
236 #endif | |
237 static struct head frame_tables; /* list of frame unwind info tables */ | |
238 | |
111 | 239 bool at_file_supplied; /* Whether to use @file arguments */ |
0 | 240 |
241 struct obstack temporary_obstack; | |
242 char * temporary_firstobj; | |
243 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
244 /* A string that must be prepended to a target OS path in order to find |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
245 it on the host system. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
246 #ifdef TARGET_SYSTEM_ROOT |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
247 static const char *target_system_root = TARGET_SYSTEM_ROOT; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
248 #else |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
249 static const char *target_system_root = ""; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
250 #endif |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
251 |
111 | 252 /* Whether we may unlink the output file, which should be set as soon as we |
253 know we have successfully produced it. This is typically useful to prevent | |
254 blindly attempting to unlink a read-only output that the target linker | |
255 would leave untouched. */ | |
256 bool may_unlink_output_file = false; | |
0 | 257 |
258 #ifdef COLLECT_EXPORT_LIST | |
259 /* Lists to keep libraries to be scanned for global constructors/destructors. */ | |
260 static struct head libs; /* list of libraries */ | |
131 | 261 static struct head static_libs; /* list of statically linked libraries */ |
0 | 262 static struct path_prefix cmdline_lib_dirs; /* directories specified with -L */ |
263 static struct path_prefix libpath_lib_dirs; /* directories in LIBPATH */ | |
264 static struct path_prefix *libpaths[3] = {&cmdline_lib_dirs, | |
265 &libpath_lib_dirs, NULL}; | |
266 #endif | |
267 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
268 /* List of names of object files containing LTO information. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
269 These are a subset of the object file names appearing on the |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
270 command line, and must be identical, in the sense of pointer |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
271 equality, with the names passed to maybe_run_lto_and_relink(). */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
272 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
273 struct lto_object |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
274 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
275 const char *name; /* Name of object file. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
276 struct lto_object *next; /* Next in linked list. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
277 }; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
278 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
279 struct lto_object_list |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
280 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
281 struct lto_object *first; /* First list element. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
282 struct lto_object *last; /* Last list element. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
283 }; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
284 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
285 static struct lto_object_list lto_objects; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
286 |
0 | 287 /* Special kinds of symbols that a name may denote. */ |
288 | |
111 | 289 enum symkind { |
0 | 290 SYM_REGULAR = 0, /* nothing special */ |
291 | |
292 SYM_CTOR = 1, /* constructor */ | |
293 SYM_DTOR = 2, /* destructor */ | |
294 SYM_INIT = 3, /* shared object routine that calls all the ctors */ | |
295 SYM_FINI = 4, /* shared object routine that calls all the dtors */ | |
111 | 296 SYM_DWEH = 5, /* DWARF exception handling table */ |
297 SYM_AIXI = 6, | |
298 SYM_AIXD = 7 | |
299 }; | |
300 | |
301 const char tool_name[] = "collect2"; | |
0 | 302 |
303 static symkind is_ctor_dtor (const char *); | |
304 | |
305 static void handler (int); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
306 static void maybe_unlink_list (char **); |
0 | 307 static void add_to_list (struct head *, const char *); |
308 static int extract_init_priority (const char *); | |
309 static void sort_ids (struct head *); | |
310 static void write_list (FILE *, const char *, struct id *); | |
311 #ifdef COLLECT_EXPORT_LIST | |
312 static void dump_list (FILE *, const char *, struct id *); | |
313 #endif | |
314 #if 0 | |
315 static void dump_prefix_list (FILE *, const char *, struct prefix_list *); | |
316 #endif | |
317 static void write_list_with_asm (FILE *, const char *, struct id *); | |
318 static void write_c_file (FILE *, const char *); | |
319 static void write_c_file_stat (FILE *, const char *); | |
320 #ifndef LD_INIT_SWITCH | |
321 static void write_c_file_glob (FILE *, const char *); | |
322 #endif | |
323 #ifdef SCAN_LIBRARIES | |
324 static void scan_libraries (const char *); | |
325 #endif | |
326 #ifdef COLLECT_EXPORT_LIST | |
327 static int is_in_list (const char *, struct id *); | |
328 static void write_aix_file (FILE *, struct id *); | |
329 static char *resolve_lib_name (const char *); | |
330 #endif | |
331 static char *extract_string (const char **); | |
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
|
332 static void post_ld_pass (bool); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
333 static void process_args (int *argcp, char **argv); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
334 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
335 /* Enumerations describing which pass this is for scanning the |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
336 program file ... */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
337 |
111 | 338 enum scanpass { |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
339 PASS_FIRST, /* without constructors */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
340 PASS_OBJ, /* individual objects */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
341 PASS_LIB, /* looking for shared libraries */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
342 PASS_SECOND, /* with constructors linked in */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
343 PASS_LTOINFO /* looking for objects with LTO info */ |
111 | 344 }; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
345 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
346 /* ... and which kinds of symbols are to be considered. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
347 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
348 enum scanfilter_masks { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
349 SCAN_NOTHING = 0, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
350 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
351 SCAN_CTOR = 1 << SYM_CTOR, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
352 SCAN_DTOR = 1 << SYM_DTOR, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
353 SCAN_INIT = 1 << SYM_INIT, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
354 SCAN_FINI = 1 << SYM_FINI, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
355 SCAN_DWEH = 1 << SYM_DWEH, |
111 | 356 SCAN_AIXI = 1 << SYM_AIXI, |
357 SCAN_AIXD = 1 << SYM_AIXD, | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
358 SCAN_ALL = ~0 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
359 }; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
360 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
361 /* This type is used for parameters and variables which hold |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
362 combinations of the flags in enum scanfilter_masks. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
363 typedef int scanfilter; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
364 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
365 /* Scan the name list of the loaded program for the symbols g++ uses for |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
366 static constructors and destructors. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
367 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
368 The SCANPASS argument tells which collect processing pass this is for and |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
369 the SCANFILTER argument tells which kinds of symbols to consider in this |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
370 pass. Symbols of a special kind not in the filter mask are considered as |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
371 regular ones. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
372 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
373 The constructor table begins at __CTOR_LIST__ and contains a count of the |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
374 number of pointers (or -1 if the constructors are built in a separate |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
375 section by the linker), followed by the pointers to the constructor |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
376 functions, terminated with a null pointer. The destructor table has the |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
377 same format, and begins at __DTOR_LIST__. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
378 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
379 static void scan_prog_file (const char *, scanpass, scanfilter); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
380 |
0 | 381 |
382 /* Delete tempfiles and exit function. */ | |
383 | |
384 void | |
111 | 385 tool_cleanup (bool from_signal) |
0 | 386 { |
387 if (c_file != 0 && c_file[0]) | |
388 maybe_unlink (c_file); | |
389 | |
390 if (o_file != 0 && o_file[0]) | |
391 maybe_unlink (o_file); | |
392 | |
393 #ifdef COLLECT_EXPORT_LIST | |
394 if (export_file != 0 && export_file[0]) | |
395 maybe_unlink (export_file); | |
396 #endif | |
397 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
398 if (lto_o_files) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
399 maybe_unlink_list (lto_o_files); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
400 |
0 | 401 if (ldout != 0 && ldout[0]) |
402 { | |
111 | 403 if (!from_signal) |
404 dump_ld_file (ldout, stdout); | |
0 | 405 maybe_unlink (ldout); |
406 } | |
407 | |
408 if (lderrout != 0 && lderrout[0]) | |
409 { | |
111 | 410 if (!from_signal) |
411 dump_ld_file (lderrout, stderr); | |
0 | 412 maybe_unlink (lderrout); |
413 } | |
111 | 414 } |
415 | |
416 static void | |
417 collect_atexit (void) | |
418 { | |
419 tool_cleanup (false); | |
0 | 420 } |
421 | |
111 | 422 static void |
423 handler (int signo) | |
0 | 424 { |
111 | 425 tool_cleanup (true); |
426 | |
427 signal (signo, SIG_DFL); | |
428 raise (signo); | |
0 | 429 } |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
430 /* Notify user of a non-error, without translating the format string. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
431 void |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
432 notice_translated (const char *cmsgid, ...) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
433 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
434 va_list ap; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
435 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
436 va_start (ap, cmsgid); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
437 vfprintf (stderr, cmsgid, ap); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
438 va_end (ap); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
439 } |
0 | 440 |
441 int | |
442 file_exists (const char *name) | |
443 { | |
444 return access (name, R_OK) == 0; | |
445 } | |
446 | |
447 /* Parse a reasonable subset of shell quoting syntax. */ | |
448 | |
449 static char * | |
450 extract_string (const char **pp) | |
451 { | |
452 const char *p = *pp; | |
453 int backquote = 0; | |
454 int inside = 0; | |
455 | |
456 for (;;) | |
457 { | |
458 char c = *p; | |
459 if (c == '\0') | |
460 break; | |
461 ++p; | |
462 if (backquote) | |
463 obstack_1grow (&temporary_obstack, c); | |
464 else if (! inside && c == ' ') | |
465 break; | |
466 else if (! inside && c == '\\') | |
467 backquote = 1; | |
468 else if (c == '\'') | |
469 inside = !inside; | |
470 else | |
471 obstack_1grow (&temporary_obstack, c); | |
472 } | |
473 | |
474 obstack_1grow (&temporary_obstack, '\0'); | |
475 *pp = p; | |
476 return XOBFINISH (&temporary_obstack, char *); | |
477 } | |
478 | |
479 void | |
111 | 480 dump_ld_file (const char *name, FILE *to) |
0 | 481 { |
482 FILE *stream = fopen (name, "r"); | |
483 | |
484 if (stream == 0) | |
485 return; | |
486 while (1) | |
487 { | |
488 int c; | |
489 while (c = getc (stream), | |
490 c != EOF && (ISIDNUM (c) || c == '$' || c == '.')) | |
491 obstack_1grow (&temporary_obstack, c); | |
492 if (obstack_object_size (&temporary_obstack) > 0) | |
493 { | |
494 const char *word, *p; | |
495 char *result; | |
496 obstack_1grow (&temporary_obstack, '\0'); | |
497 word = XOBFINISH (&temporary_obstack, const char *); | |
498 | |
499 if (*word == '.') | |
500 ++word, putc ('.', to); | |
501 p = word; | |
502 if (!strncmp (p, USER_LABEL_PREFIX, strlen (USER_LABEL_PREFIX))) | |
503 p += strlen (USER_LABEL_PREFIX); | |
504 | |
505 #ifdef HAVE_LD_DEMANGLE | |
506 result = 0; | |
507 #else | |
508 if (no_demangle) | |
509 result = 0; | |
510 else | |
511 result = cplus_demangle (p, DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE); | |
512 #endif | |
513 | |
514 if (result) | |
515 { | |
516 int diff; | |
517 fputs (result, to); | |
518 | |
519 diff = strlen (word) - strlen (result); | |
520 while (diff > 0 && c == ' ') | |
521 --diff, putc (' ', to); | |
522 if (diff < 0 && c == ' ') | |
523 { | |
524 while (diff < 0 && c == ' ') | |
525 ++diff, c = getc (stream); | |
526 if (!ISSPACE (c)) | |
527 { | |
528 /* Make sure we output at least one space, or | |
529 the demangled symbol name will run into | |
530 whatever text follows. */ | |
531 putc (' ', to); | |
532 } | |
533 } | |
534 | |
535 free (result); | |
536 } | |
537 else | |
538 fputs (word, to); | |
539 | |
540 fflush (to); | |
541 obstack_free (&temporary_obstack, temporary_firstobj); | |
542 } | |
543 if (c == EOF) | |
544 break; | |
545 putc (c, to); | |
546 } | |
547 fclose (stream); | |
548 } | |
549 | |
550 /* Return the kind of symbol denoted by name S. */ | |
551 | |
552 static symkind | |
553 is_ctor_dtor (const char *s) | |
554 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
555 struct names { const char *const name; const int len; symkind ret; |
0 | 556 const int two_underscores; }; |
557 | |
558 const struct names *p; | |
559 int ch; | |
560 const char *orig_s = s; | |
561 | |
562 static const struct names special[] = { | |
563 #ifndef NO_DOLLAR_IN_LABEL | |
564 { "GLOBAL__I$", sizeof ("GLOBAL__I$")-1, SYM_CTOR, 0 }, | |
565 { "GLOBAL__D$", sizeof ("GLOBAL__D$")-1, SYM_DTOR, 0 }, | |
566 #else | |
567 #ifndef NO_DOT_IN_LABEL | |
568 { "GLOBAL__I.", sizeof ("GLOBAL__I.")-1, SYM_CTOR, 0 }, | |
569 { "GLOBAL__D.", sizeof ("GLOBAL__D.")-1, SYM_DTOR, 0 }, | |
570 #endif /* NO_DOT_IN_LABEL */ | |
571 #endif /* NO_DOLLAR_IN_LABEL */ | |
572 { "GLOBAL__I_", sizeof ("GLOBAL__I_")-1, SYM_CTOR, 0 }, | |
573 { "GLOBAL__D_", sizeof ("GLOBAL__D_")-1, SYM_DTOR, 0 }, | |
574 { "GLOBAL__F_", sizeof ("GLOBAL__F_")-1, SYM_DWEH, 0 }, | |
575 { "GLOBAL__FI_", sizeof ("GLOBAL__FI_")-1, SYM_INIT, 0 }, | |
576 { "GLOBAL__FD_", sizeof ("GLOBAL__FD_")-1, SYM_FINI, 0 }, | |
111 | 577 #ifdef TARGET_AIX_VERSION |
578 { "GLOBAL__AIXI_", sizeof ("GLOBAL__AIXI_")-1, SYM_AIXI, 0 }, | |
579 { "GLOBAL__AIXD_", sizeof ("GLOBAL__AIXD_")-1, SYM_AIXD, 0 }, | |
580 #endif | |
0 | 581 { NULL, 0, SYM_REGULAR, 0 } |
582 }; | |
583 | |
584 while ((ch = *s) == '_') | |
585 ++s; | |
586 | |
587 if (s == orig_s) | |
588 return SYM_REGULAR; | |
589 | |
590 for (p = &special[0]; p->len > 0; p++) | |
591 { | |
592 if (ch == p->name[0] | |
593 && (!p->two_underscores || ((s - orig_s) >= 2)) | |
111 | 594 && strncmp (s, p->name, p->len) == 0) |
0 | 595 { |
596 return p->ret; | |
597 } | |
598 } | |
599 return SYM_REGULAR; | |
600 } | |
601 | |
602 /* We maintain two prefix lists: one from COMPILER_PATH environment variable | |
603 and one from the PATH variable. */ | |
604 | |
605 static struct path_prefix cpath, path; | |
606 | |
607 #ifdef CROSS_DIRECTORY_STRUCTURE | |
608 /* This is the name of the target machine. We use it to form the name | |
609 of the files to execute. */ | |
610 | |
611 static const char *const target_machine = TARGET_MACHINE; | |
612 #endif | |
613 | |
614 /* Search for NAME using prefix list PPREFIX. We only look for executable | |
615 files. | |
616 | |
617 Return 0 if not found, otherwise return its name, allocated with malloc. */ | |
618 | |
145 | 619 #ifdef OBJECT_FORMAT_NONE |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
620 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
621 /* Add an entry for the object file NAME to object file list LIST. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
622 New entries are added at the end of the list. The original pointer |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
623 value of NAME is preserved, i.e., no string copy is performed. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
624 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
625 static void |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
626 add_lto_object (struct lto_object_list *list, const char *name) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
627 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
628 struct lto_object *n = XNEW (struct lto_object); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
629 n->name = name; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
630 n->next = NULL; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
631 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
632 if (list->last) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
633 list->last->next = n; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
634 else |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
635 list->first = n; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
636 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
637 list->last = n; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
638 } |
145 | 639 #endif /* OBJECT_FORMAT_NONE */ |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
640 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
641 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
642 /* Perform a link-time recompilation and relink if any of the object |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
643 files contain LTO info. The linker command line LTO_LD_ARGV |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
644 represents the linker command that would produce a final executable |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
645 without the use of LTO. OBJECT_LST is a vector of object file names |
111 | 646 appearing in LTO_LD_ARGV that are to be considered for link-time |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
647 recompilation, where OBJECT is a pointer to the last valid element. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
648 (This awkward convention avoids an impedance mismatch with the |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
649 usage of similarly-named variables in main().) The elements of |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
650 OBJECT_LST must be identical, i.e., pointer equal, to the |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
651 corresponding arguments in LTO_LD_ARGV. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
652 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
653 Upon entry, at least one linker run has been performed without the |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
654 use of any LTO info that might be present. Any recompilations |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
655 necessary for template instantiations have been performed, and |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
656 initializer/finalizer tables have been created if needed and |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
657 included in the linker command line LTO_LD_ARGV. If any of the |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
658 object files contain LTO info, we run the LTO back end on all such |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
659 files, and perform the final link with the LTO back end output |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
660 substituted for the LTO-optimized files. In some cases, a final |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
661 link with all link-time generated code has already been performed, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
662 so there is no need to relink if no LTO info is found. In other |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
663 cases, our caller has not produced the final executable, and is |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
664 relying on us to perform the required link whether LTO info is |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
665 present or not. In that case, the FORCE argument should be true. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
666 Note that the linker command line argument LTO_LD_ARGV passed into |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
667 this function may be modified in place. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
668 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
669 static void |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
670 maybe_run_lto_and_relink (char **lto_ld_argv, char **object_lst, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
671 const char **object, bool force) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
672 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
673 const char **object_file = CONST_CAST2 (const char **, char **, object_lst); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
674 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
675 int num_lto_c_args = 1; /* Allow space for the terminating NULL. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
676 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
677 while (object_file < object) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
678 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
679 /* If file contains LTO info, add it to the list of LTO objects. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
680 scan_prog_file (*object_file++, PASS_LTOINFO, SCAN_ALL); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
681 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
682 /* Increment the argument count by the number of object file arguments |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
683 we will add. An upper bound suffices, so just count all of the |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
684 object files regardless of whether they contain LTO info. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
685 num_lto_c_args++; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
686 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
687 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
688 if (lto_objects.first) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
689 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
690 char **lto_c_argv; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
691 const char **lto_c_ptr; |
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
|
692 char **p; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
693 char **lto_o_ptr; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
694 struct lto_object *list; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
695 char *lto_wrapper = getenv ("COLLECT_LTO_WRAPPER"); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
696 struct pex_obj *pex; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
697 const char *prog = "lto-wrapper"; |
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
|
698 int lto_ld_argv_size = 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
|
699 char **out_lto_ld_argv; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
700 int out_lto_ld_argv_size; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
701 size_t num_files; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
702 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
703 if (!lto_wrapper) |
145 | 704 fatal_error (input_location, "environment variable " |
705 "%<COLLECT_LTO_WRAPPER%> must be set"); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
706 |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
707 num_lto_c_args++; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
708 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
709 /* There is at least one object file containing LTO info, |
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
|
710 so we need to run the LTO back end and relink. |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
711 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
712 To do so we build updated ld arguments with first |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
713 LTO object replaced by all partitions and other 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
|
714 objects removed. */ |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
715 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
716 lto_c_argv = (char **) xcalloc (sizeof (char *), num_lto_c_args); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
717 lto_c_ptr = CONST_CAST2 (const char **, char **, lto_c_argv); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
718 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
719 *lto_c_ptr++ = lto_wrapper; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
720 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
721 /* Add LTO objects to the wrapper command line. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
722 for (list = lto_objects.first; list; list = list->next) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
723 *lto_c_ptr++ = list->name; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
724 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
725 *lto_c_ptr = NULL; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
726 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
727 /* Run the LTO back end. */ |
111 | 728 pex = collect_execute (prog, lto_c_argv, NULL, NULL, PEX_SEARCH, |
729 at_file_supplied); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
730 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
731 int c; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
732 FILE *stream; |
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
|
733 size_t i; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
734 char *start, *end; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
735 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
736 stream = pex_read_output (pex, 0); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
737 gcc_assert (stream); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
738 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
739 num_files = 0; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
740 while ((c = getc (stream)) != EOF) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
741 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
742 obstack_1grow (&temporary_obstack, c); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
743 if (c == '\n') |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
744 ++num_files; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
745 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
746 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
747 lto_o_files = XNEWVEC (char *, num_files + 1); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
748 lto_o_files[num_files] = NULL; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
749 start = XOBFINISH (&temporary_obstack, char *); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
750 for (i = 0; i < num_files; ++i) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
751 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
752 end = start; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
753 while (*end != '\n') |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
754 ++end; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
755 *end = '\0'; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
756 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
757 lto_o_files[i] = xstrdup (start); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
758 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
759 start = end + 1; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
760 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
761 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
762 obstack_free (&temporary_obstack, temporary_firstobj); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
763 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
764 do_wait (prog, pex); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
765 pex = NULL; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
766 |
111 | 767 /* Compute memory needed for new LD arguments. At most number of original arguments |
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
|
768 plus number of partitions. */ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
769 for (lto_ld_argv_size = 0; lto_ld_argv[lto_ld_argv_size]; lto_ld_argv_size++) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
770 ; |
111 | 771 out_lto_ld_argv = XCNEWVEC (char *, num_files + lto_ld_argv_size + 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
|
772 out_lto_ld_argv_size = 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
|
773 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
774 /* After running the LTO back end, we will relink, substituting |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
775 the LTO output for the object files that we submitted to the |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
776 LTO. Here, we modify the linker command line for the relink. */ |
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
|
777 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
778 /* Copy all arguments until we find first LTO 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
|
779 p = lto_ld_argv; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
780 while (*p != NULL) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
781 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
782 for (list = lto_objects.first; list; list = list->next) |
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
|
783 if (*p == list->name) /* Note test for pointer equality! */ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
784 break; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
785 if (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
|
786 break; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
787 out_lto_ld_argv[out_lto_ld_argv_size++] = *p++; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
788 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
789 |
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
|
790 /* Now insert all LTO partitions. */ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
791 lto_o_ptr = lto_o_files; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
792 while (*lto_o_ptr) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
793 out_lto_ld_argv[out_lto_ld_argv_size++] = *lto_o_ptr++; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
794 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
795 /* ... and copy the rest. */ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
796 while (*p != 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
|
797 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
798 for (list = lto_objects.first; list; list = list->next) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
799 if (*p == list->name) /* Note test for pointer equality! */ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
800 break; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
801 if (!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
|
802 out_lto_ld_argv[out_lto_ld_argv_size++] = *p; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
803 p++; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
804 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
805 out_lto_ld_argv[out_lto_ld_argv_size++] = 0; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
806 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
807 /* Run the linker again, this time replacing the object files |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
808 optimized by the LTO with the temporary file generated by the LTO. */ |
111 | 809 fork_execute ("ld", out_lto_ld_argv, HAVE_GNU_LD && at_file_supplied); |
145 | 810 /* We assume that temp files were created, and therefore we need to take |
811 that into account (maybe run dsymutil). */ | |
812 post_ld_pass (/*temp_file*/true); | |
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
|
813 free (lto_ld_argv); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
814 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
815 maybe_unlink_list (lto_o_files); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
816 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
817 else if (force) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
818 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
819 /* Our caller is relying on us to do the link |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
820 even though there is no LTO back end work to be done. */ |
111 | 821 fork_execute ("ld", lto_ld_argv, HAVE_GNU_LD && at_file_supplied); |
145 | 822 /* No LTO objects were found, so no new temp file. */ |
823 post_ld_pass (/*temp_file*/false); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
824 } |
111 | 825 else |
145 | 826 post_ld_pass (false); /* No LTO objects were found, no temp file. */ |
827 } | |
828 /* Entry point for linker invoation. Called from main in collect2.c. | |
829 LD_ARGV is an array of arguments for the linker. */ | |
830 | |
831 static void | |
832 do_link (char **ld_argv) | |
833 { | |
834 struct pex_obj *pex; | |
835 const char *prog = "ld"; | |
836 pex = collect_execute (prog, ld_argv, NULL, NULL, | |
837 PEX_LAST | PEX_SEARCH, | |
838 HAVE_GNU_LD && at_file_supplied); | |
839 int ret = collect_wait (prog, pex); | |
840 if (ret) | |
841 { | |
842 error ("ld returned %d exit status", ret); | |
843 exit (ret); | |
844 } | |
845 else | |
846 { | |
847 /* We have just successfully produced an output file, so assume that we | |
848 may unlink it if need be for now on. */ | |
849 may_unlink_output_file = true; | |
850 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
851 } |
0 | 852 |
853 /* Main program. */ | |
854 | |
855 int | |
856 main (int argc, char **argv) | |
857 { | |
111 | 858 enum linker_select |
859 { | |
860 USE_DEFAULT_LD, | |
861 USE_PLUGIN_LD, | |
862 USE_GOLD_LD, | |
863 USE_BFD_LD, | |
145 | 864 USE_LLD_LD, |
111 | 865 USE_LD_MAX |
866 } selected_linker = USE_DEFAULT_LD; | |
867 static const char *const ld_suffixes[USE_LD_MAX] = | |
868 { | |
869 "ld", | |
870 PLUGIN_LD_SUFFIX, | |
871 "ld.gold", | |
145 | 872 "ld.bfd", |
873 "ld.lld" | |
111 | 874 }; |
0 | 875 static const char *const real_ld_suffix = "real-ld"; |
876 static const char *const collect_ld_suffix = "collect-ld"; | |
877 static const char *const nm_suffix = "nm"; | |
878 static const char *const gnm_suffix = "gnm"; | |
879 #ifdef LDD_SUFFIX | |
880 static const char *const ldd_suffix = LDD_SUFFIX; | |
881 #endif | |
882 static const char *const strip_suffix = "strip"; | |
883 static const char *const gstrip_suffix = "gstrip"; | |
884 | |
111 | 885 const char *full_ld_suffixes[USE_LD_MAX]; |
0 | 886 #ifdef CROSS_DIRECTORY_STRUCTURE |
887 /* If we look for a program in the compiler directories, we just use | |
888 the short name, since these directories are already system-specific. | |
889 But it we look for a program in the system directories, we need to | |
890 qualify the program name with the target machine. */ | |
891 | |
892 const char *const full_nm_suffix = | |
893 concat (target_machine, "-", nm_suffix, NULL); | |
894 const char *const full_gnm_suffix = | |
895 concat (target_machine, "-", gnm_suffix, NULL); | |
896 #ifdef LDD_SUFFIX | |
897 const char *const full_ldd_suffix = | |
898 concat (target_machine, "-", ldd_suffix, NULL); | |
899 #endif | |
900 const char *const full_strip_suffix = | |
901 concat (target_machine, "-", strip_suffix, NULL); | |
902 const char *const full_gstrip_suffix = | |
903 concat (target_machine, "-", gstrip_suffix, NULL); | |
904 #else | |
905 #ifdef LDD_SUFFIX | |
906 const char *const full_ldd_suffix = ldd_suffix; | |
907 #endif | |
111 | 908 const char *const full_nm_suffix = nm_suffix; |
909 const char *const full_gnm_suffix = gnm_suffix; | |
0 | 910 const char *const full_strip_suffix = strip_suffix; |
911 const char *const full_gstrip_suffix = gstrip_suffix; | |
912 #endif /* CROSS_DIRECTORY_STRUCTURE */ | |
913 | |
914 const char *arg; | |
915 FILE *outf; | |
916 #ifdef COLLECT_EXPORT_LIST | |
917 FILE *exportf; | |
918 #endif | |
919 const char *ld_file_name; | |
920 const char *p; | |
921 char **c_argv; | |
922 const char **c_ptr; | |
923 char **ld1_argv; | |
924 const char **ld1; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
925 bool use_plugin = false; |
111 | 926 bool use_collect_ld = false; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
927 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
928 /* The kinds of symbols we will have to consider when scanning the |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
929 outcome of a first pass link. This is ALL to start with, then might |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
930 be adjusted before getting to the first pass link per se, typically on |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
931 AIX where we perform an early scan of objects and libraries to fetch |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
932 the list of global ctors/dtors and make sure they are not garbage |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
933 collected. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
934 scanfilter ld1_filter = SCAN_ALL; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
935 |
0 | 936 char **ld2_argv; |
937 const char **ld2; | |
938 char **object_lst; | |
939 const char **object; | |
111 | 940 #ifdef TARGET_AIX_VERSION |
941 int object_nbr = argc; | |
942 #endif | |
0 | 943 int first_file; |
944 int num_c_args; | |
945 char **old_argv; | |
131 | 946 #ifdef COLLECT_EXPORT_LIST |
947 bool is_static = false; | |
948 #endif | |
111 | 949 int i; |
950 | |
951 for (i = 0; i < USE_LD_MAX; i++) | |
952 full_ld_suffixes[i] | |
953 #ifdef CROSS_DIRECTORY_STRUCTURE | |
954 = concat (target_machine, "-", ld_suffixes[i], NULL); | |
955 #else | |
956 = ld_suffixes[i]; | |
957 #endif | |
958 | |
959 p = argv[0] + strlen (argv[0]); | |
960 while (p != argv[0] && !IS_DIR_SEPARATOR (p[-1])) | |
961 --p; | |
962 progname = p; | |
963 | |
964 xmalloc_set_program_name (progname); | |
0 | 965 |
966 old_argv = argv; | |
967 expandargv (&argc, &argv); | |
968 if (argv != old_argv) | |
969 at_file_supplied = 1; | |
970 | |
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
|
971 process_args (&argc, argv); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
972 |
0 | 973 num_c_args = argc + 9; |
974 | |
111 | 975 #ifndef HAVE_LD_DEMANGLE |
0 | 976 no_demangle = !! getenv ("COLLECT_NO_DEMANGLE"); |
977 | |
978 /* Suppress demangling by the real linker, which may be broken. */ | |
111 | 979 putenv (xstrdup ("COLLECT_NO_DEMANGLE=1")); |
980 #endif | |
0 | 981 |
982 #if defined (COLLECT2_HOST_INITIALIZATION) | |
983 /* Perform system dependent initialization, if necessary. */ | |
984 COLLECT2_HOST_INITIALIZATION; | |
985 #endif | |
986 | |
987 #ifdef SIGCHLD | |
988 /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will | |
989 receive the signal. A different setting is inheritable */ | |
990 signal (SIGCHLD, SIG_DFL); | |
991 #endif | |
992 | |
993 /* Unlock the stdio streams. */ | |
994 unlock_std_streams (); | |
995 | |
996 gcc_init_libintl (); | |
997 | |
111 | 998 diagnostic_initialize (global_dc, 0); |
999 | |
1000 if (atexit (collect_atexit) != 0) | |
1001 fatal_error (input_location, "atexit failed"); | |
1002 | |
0 | 1003 /* Do not invoke xcalloc before this point, since locale needs to be |
1004 set first, in case a diagnostic is issued. */ | |
1005 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1006 ld1_argv = XCNEWVEC (char *, argc + 4); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1007 ld1 = CONST_CAST2 (const char **, char **, ld1_argv); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1008 ld2_argv = XCNEWVEC (char *, argc + 11); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1009 ld2 = CONST_CAST2 (const char **, char **, ld2_argv); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1010 object_lst = XCNEWVEC (char *, argc); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1011 object = CONST_CAST2 (const char **, char **, object_lst); |
0 | 1012 |
1013 #ifdef DEBUG | |
145 | 1014 debug = true; |
0 | 1015 #endif |
1016 | |
145 | 1017 save_temps = false; |
1018 verbose = false; | |
1019 | |
1020 #ifndef DEFAULT_A_OUT_NAME | |
1021 output_file = "a.out"; | |
1022 #else | |
1023 output_file = DEFAULT_A_OUT_NAME; | |
1024 #endif | |
1025 | |
1026 /* Parse command line / environment for flags we want early. | |
1027 This allows the debug flag to be set before functions like find_a_file() | |
1028 are called. */ | |
0 | 1029 { |
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
|
1030 bool no_partition = false; |
0 | 1031 |
1032 for (i = 1; argv[i] != NULL; i ++) | |
1033 { | |
1034 if (! strcmp (argv[i], "-debug")) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1035 debug = true; |
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
|
1036 else if (!strncmp (argv[i], "-fno-lto", 8)) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1037 lto_mode = LTO_MODE_NONE; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1038 else if (! strcmp (argv[i], "-plugin")) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1039 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1040 use_plugin = true; |
111 | 1041 if (selected_linker == USE_DEFAULT_LD) |
1042 selected_linker = USE_PLUGIN_LD; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1043 } |
111 | 1044 else if (strcmp (argv[i], "-fuse-ld=bfd") == 0) |
1045 selected_linker = USE_BFD_LD; | |
1046 else if (strcmp (argv[i], "-fuse-ld=gold") == 0) | |
1047 selected_linker = USE_GOLD_LD; | |
145 | 1048 else if (strcmp (argv[i], "-fuse-ld=lld") == 0) |
1049 selected_linker = USE_LLD_LD; | |
1050 else if (strncmp (argv[i], "-o", 2) == 0) | |
1051 { | |
1052 /* Parse the output filename if it's given so that we can make | |
1053 meaningful temp filenames. */ | |
1054 if (argv[i][2] == '\0') | |
1055 output_file = argv[i+1]; | |
1056 else | |
1057 output_file = &argv[i][2]; | |
1058 } | |
111 | 1059 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1060 #ifdef COLLECT_EXPORT_LIST |
111 | 1061 /* These flags are position independent, although their order |
1062 is important - subsequent flags override earlier ones. */ | |
1063 else if (strcmp (argv[i], "-b64") == 0) | |
1064 aix64_flag = 1; | |
1065 /* -bexport:filename always needs the :filename */ | |
1066 else if (strncmp (argv[i], "-bE:", 4) == 0 | |
1067 || strncmp (argv[i], "-bexport:", 9) == 0) | |
1068 export_flag = 1; | |
1069 else if (strcmp (argv[i], "-brtl") == 0 | |
1070 || strcmp (argv[i], "-bsvr4") == 0 | |
1071 || strcmp (argv[i], "-G") == 0) | |
1072 aixrtl_flag = 1; | |
1073 else if (strcmp (argv[i], "-bnortl") == 0) | |
1074 aixrtl_flag = 0; | |
1075 else if (strcmp (argv[i], "-blazy") == 0) | |
1076 aixlazy_flag = 1; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1077 #endif |
0 | 1078 } |
145 | 1079 |
1080 obstack_begin (&temporary_obstack, 0); | |
1081 temporary_firstobj = (char *) obstack_alloc (&temporary_obstack, 0); | |
1082 | |
1083 #ifndef HAVE_LD_DEMANGLE | |
1084 current_demangling_style = auto_demangling; | |
1085 #endif | |
1086 | |
1087 /* Now pick up any flags we want early from COLLECT_GCC_OPTIONS | |
1088 The LTO options are passed here as are other options that might | |
1089 be unsuitable for ld (e.g. -save-temps). */ | |
1090 p = getenv ("COLLECT_GCC_OPTIONS"); | |
1091 while (p && *p) | |
1092 { | |
1093 const char *q = extract_string (&p); | |
1094 if (*q == '-' && (q[1] == 'm' || q[1] == 'f')) | |
1095 num_c_args++; | |
1096 if (strncmp (q, "-flto-partition=none", 20) == 0) | |
1097 no_partition = true; | |
1098 else if (strncmp (q, "-fno-lto", 8) == 0) | |
1099 lto_mode = LTO_MODE_NONE; | |
1100 else if (strncmp (q, "-save-temps", 11) == 0) | |
1101 /* FIXME: Honour =obj. */ | |
1102 save_temps = true; | |
1103 } | |
1104 obstack_free (&temporary_obstack, temporary_firstobj); | |
1105 | |
1106 verbose = verbose || debug; | |
1107 save_temps = save_temps || debug; | |
111 | 1108 find_file_set_debug (debug); |
1109 if (use_plugin) | |
1110 lto_mode = LTO_MODE_NONE; | |
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
|
1111 if (no_partition && lto_mode == LTO_MODE_WHOPR) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1112 lto_mode = LTO_MODE_LTO; |
0 | 1113 } |
1114 | |
1115 /* -fno-profile-arcs -fno-test-coverage -fno-branch-probabilities | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1116 -fno-exceptions -w -fno-whole-program */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1117 num_c_args += 6; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1118 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1119 c_argv = XCNEWVEC (char *, num_c_args); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1120 c_ptr = CONST_CAST2 (const char **, char **, c_argv); |
0 | 1121 |
1122 if (argc < 2) | |
111 | 1123 fatal_error (input_location, "no arguments"); |
0 | 1124 |
1125 #ifdef SIGQUIT | |
1126 if (signal (SIGQUIT, SIG_IGN) != SIG_IGN) | |
1127 signal (SIGQUIT, handler); | |
1128 #endif | |
1129 if (signal (SIGINT, SIG_IGN) != SIG_IGN) | |
1130 signal (SIGINT, handler); | |
1131 #ifdef SIGALRM | |
1132 if (signal (SIGALRM, SIG_IGN) != SIG_IGN) | |
1133 signal (SIGALRM, handler); | |
1134 #endif | |
1135 #ifdef SIGHUP | |
1136 if (signal (SIGHUP, SIG_IGN) != SIG_IGN) | |
1137 signal (SIGHUP, handler); | |
1138 #endif | |
1139 if (signal (SIGSEGV, SIG_IGN) != SIG_IGN) | |
1140 signal (SIGSEGV, handler); | |
1141 #ifdef SIGBUS | |
1142 if (signal (SIGBUS, SIG_IGN) != SIG_IGN) | |
1143 signal (SIGBUS, handler); | |
1144 #endif | |
1145 | |
1146 /* Extract COMPILER_PATH and PATH into our prefix list. */ | |
1147 prefix_from_env ("COMPILER_PATH", &cpath); | |
1148 prefix_from_env ("PATH", &path); | |
1149 | |
1150 /* Try to discover a valid linker/nm/strip to use. */ | |
1151 | |
1152 /* Maybe we know the right file to use (if not cross). */ | |
1153 ld_file_name = 0; | |
1154 #ifdef DEFAULT_LINKER | |
145 | 1155 if (selected_linker == USE_BFD_LD || selected_linker == USE_GOLD_LD || |
1156 selected_linker == USE_LLD_LD) | |
111 | 1157 { |
1158 char *linker_name; | |
1159 # ifdef HOST_EXECUTABLE_SUFFIX | |
1160 int len = (sizeof (DEFAULT_LINKER) | |
1161 - sizeof (HOST_EXECUTABLE_SUFFIX)); | |
1162 linker_name = NULL; | |
1163 if (len > 0) | |
1164 { | |
1165 char *default_linker = xstrdup (DEFAULT_LINKER); | |
1166 /* Strip HOST_EXECUTABLE_SUFFIX if DEFAULT_LINKER contains | |
1167 HOST_EXECUTABLE_SUFFIX. */ | |
1168 if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX)) | |
1169 { | |
1170 default_linker[len] = '\0'; | |
1171 linker_name = concat (default_linker, | |
1172 &ld_suffixes[selected_linker][2], | |
1173 HOST_EXECUTABLE_SUFFIX, NULL); | |
1174 } | |
1175 } | |
1176 if (linker_name == NULL) | |
1177 # endif | |
1178 linker_name = concat (DEFAULT_LINKER, | |
1179 &ld_suffixes[selected_linker][2], | |
1180 NULL); | |
1181 if (access (linker_name, X_OK) == 0) | |
1182 ld_file_name = linker_name; | |
1183 } | |
1184 if (ld_file_name == 0 && access (DEFAULT_LINKER, X_OK) == 0) | |
0 | 1185 ld_file_name = DEFAULT_LINKER; |
1186 if (ld_file_name == 0) | |
1187 #endif | |
1188 #ifdef REAL_LD_FILE_NAME | |
111 | 1189 ld_file_name = find_a_file (&path, REAL_LD_FILE_NAME, X_OK); |
0 | 1190 if (ld_file_name == 0) |
1191 #endif | |
1192 /* Search the (target-specific) compiler dirs for ld'. */ | |
111 | 1193 ld_file_name = find_a_file (&cpath, real_ld_suffix, X_OK); |
0 | 1194 /* Likewise for `collect-ld'. */ |
1195 if (ld_file_name == 0) | |
111 | 1196 { |
1197 ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK); | |
1198 use_collect_ld = ld_file_name != 0; | |
1199 } | |
0 | 1200 /* Search the compiler directories for `ld'. We have protection against |
1201 recursive calls in find_a_file. */ | |
1202 if (ld_file_name == 0) | |
111 | 1203 ld_file_name = find_a_file (&cpath, ld_suffixes[selected_linker], X_OK); |
0 | 1204 /* Search the ordinary system bin directories |
1205 for `ld' (if native linking) or `TARGET-ld' (if cross). */ | |
1206 if (ld_file_name == 0) | |
111 | 1207 ld_file_name = find_a_file (&path, full_ld_suffixes[selected_linker], X_OK); |
0 | 1208 |
1209 #ifdef REAL_NM_FILE_NAME | |
111 | 1210 nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK); |
0 | 1211 if (nm_file_name == 0) |
1212 #endif | |
111 | 1213 nm_file_name = find_a_file (&cpath, gnm_suffix, X_OK); |
0 | 1214 if (nm_file_name == 0) |
111 | 1215 nm_file_name = find_a_file (&path, full_gnm_suffix, X_OK); |
0 | 1216 if (nm_file_name == 0) |
111 | 1217 nm_file_name = find_a_file (&cpath, nm_suffix, X_OK); |
0 | 1218 if (nm_file_name == 0) |
111 | 1219 nm_file_name = find_a_file (&path, full_nm_suffix, X_OK); |
0 | 1220 |
1221 #ifdef LDD_SUFFIX | |
111 | 1222 ldd_file_name = find_a_file (&cpath, ldd_suffix, X_OK); |
0 | 1223 if (ldd_file_name == 0) |
111 | 1224 ldd_file_name = find_a_file (&path, full_ldd_suffix, X_OK); |
0 | 1225 #endif |
1226 | |
1227 #ifdef REAL_STRIP_FILE_NAME | |
111 | 1228 strip_file_name = find_a_file (&path, REAL_STRIP_FILE_NAME, X_OK); |
0 | 1229 if (strip_file_name == 0) |
1230 #endif | |
111 | 1231 strip_file_name = find_a_file (&cpath, gstrip_suffix, X_OK); |
0 | 1232 if (strip_file_name == 0) |
111 | 1233 strip_file_name = find_a_file (&path, full_gstrip_suffix, X_OK); |
0 | 1234 if (strip_file_name == 0) |
111 | 1235 strip_file_name = find_a_file (&cpath, strip_suffix, X_OK); |
0 | 1236 if (strip_file_name == 0) |
111 | 1237 strip_file_name = find_a_file (&path, full_strip_suffix, X_OK); |
0 | 1238 |
1239 /* Determine the full path name of the C compiler to use. */ | |
1240 c_file_name = getenv ("COLLECT_GCC"); | |
1241 if (c_file_name == 0) | |
1242 { | |
1243 #ifdef CROSS_DIRECTORY_STRUCTURE | |
1244 c_file_name = concat (target_machine, "-gcc", NULL); | |
1245 #else | |
1246 c_file_name = "gcc"; | |
1247 #endif | |
1248 } | |
1249 | |
111 | 1250 p = find_a_file (&cpath, c_file_name, X_OK); |
0 | 1251 |
1252 /* Here it should be safe to use the system search path since we should have | |
1253 already qualified the name of the compiler when it is needed. */ | |
1254 if (p == 0) | |
111 | 1255 p = find_a_file (&path, c_file_name, X_OK); |
0 | 1256 |
1257 if (p) | |
1258 c_file_name = p; | |
1259 | |
1260 *ld1++ = *ld2++ = ld_file_name; | |
1261 | |
1262 /* Make temp file names. */ | |
145 | 1263 if (save_temps) |
1264 { | |
1265 c_file = (char *) xmalloc (strlen (output_file) | |
1266 + sizeof (".cdtor.c") + 1); | |
1267 strcpy (c_file, output_file); | |
1268 strcat (c_file, ".cdtor.c"); | |
1269 o_file = (char *) xmalloc (strlen (output_file) | |
1270 + sizeof (".cdtor.o") + 1); | |
1271 strcpy (o_file, output_file); | |
1272 strcat (o_file, ".cdtor.o"); | |
1273 } | |
1274 else | |
1275 { | |
1276 c_file = make_temp_file (".cdtor.c"); | |
1277 o_file = make_temp_file (".cdtor.o"); | |
1278 } | |
0 | 1279 #ifdef COLLECT_EXPORT_LIST |
1280 export_file = make_temp_file (".x"); | |
1281 #endif | |
111 | 1282 if (!debug) |
1283 { | |
1284 ldout = make_temp_file (".ld"); | |
1285 lderrout = make_temp_file (".le"); | |
1286 } | |
145 | 1287 /* Build the command line to compile the ctor/dtor list. */ |
0 | 1288 *c_ptr++ = c_file_name; |
1289 *c_ptr++ = "-x"; | |
1290 *c_ptr++ = "c"; | |
1291 *c_ptr++ = "-c"; | |
1292 *c_ptr++ = "-o"; | |
1293 *c_ptr++ = o_file; | |
1294 | |
1295 #ifdef COLLECT_EXPORT_LIST | |
1296 /* Generate a list of directories from LIBPATH. */ | |
1297 prefix_from_env ("LIBPATH", &libpath_lib_dirs); | |
1298 /* Add to this list also two standard directories where | |
1299 AIX loader always searches for libraries. */ | |
1300 add_prefix (&libpath_lib_dirs, "/lib"); | |
1301 add_prefix (&libpath_lib_dirs, "/usr/lib"); | |
1302 #endif | |
1303 | |
1304 /* Get any options that the upper GCC wants to pass to the sub-GCC. | |
1305 | |
1306 AIX support needs to know if -shared has been specified before | |
1307 parsing commandline arguments. */ | |
1308 | |
1309 p = getenv ("COLLECT_GCC_OPTIONS"); | |
1310 while (p && *p) | |
1311 { | |
1312 const char *q = extract_string (&p); | |
1313 if (*q == '-' && (q[1] == 'm' || q[1] == 'f')) | |
1314 *c_ptr++ = xstrdup (q); | |
1315 if (strcmp (q, "-EL") == 0 || strcmp (q, "-EB") == 0) | |
1316 *c_ptr++ = xstrdup (q); | |
1317 if (strcmp (q, "-shared") == 0) | |
1318 shared_obj = 1; | |
131 | 1319 if (strcmp (q, "-static") == 0) |
1320 static_obj = 1; | |
0 | 1321 if (*q == '-' && q[1] == 'B') |
1322 { | |
1323 *c_ptr++ = xstrdup (q); | |
1324 if (q[2] == 0) | |
1325 { | |
1326 q = extract_string (&p); | |
1327 *c_ptr++ = xstrdup (q); | |
1328 } | |
1329 } | |
1330 } | |
1331 obstack_free (&temporary_obstack, temporary_firstobj); | |
1332 *c_ptr++ = "-fno-profile-arcs"; | |
1333 *c_ptr++ = "-fno-test-coverage"; | |
1334 *c_ptr++ = "-fno-branch-probabilities"; | |
1335 *c_ptr++ = "-fno-exceptions"; | |
1336 *c_ptr++ = "-w"; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1337 *c_ptr++ = "-fno-whole-program"; |
0 | 1338 |
1339 /* !!! When GCC calls collect2, | |
1340 it does not know whether it is calling collect2 or ld. | |
1341 So collect2 cannot meaningfully understand any options | |
1342 except those ld understands. | |
1343 If you propose to make GCC pass some other option, | |
1344 just imagine what will happen if ld is really ld!!! */ | |
1345 | |
1346 /* Parse arguments. Remember output file spec, pass the rest to ld. */ | |
1347 /* After the first file, put in the c++ rt0. */ | |
1348 | |
131 | 1349 #ifdef COLLECT_EXPORT_LIST |
1350 is_static = static_obj; | |
1351 #endif | |
0 | 1352 first_file = 1; |
1353 while ((arg = *++argv) != (char *) 0) | |
1354 { | |
1355 *ld1++ = *ld2++ = arg; | |
1356 | |
1357 if (arg[0] == '-') | |
1358 { | |
1359 switch (arg[1]) | |
1360 { | |
1361 case 'd': | |
1362 if (!strcmp (arg, "-debug")) | |
1363 { | |
1364 /* Already parsed. */ | |
1365 ld1--; | |
1366 ld2--; | |
1367 } | |
1368 if (!strcmp (arg, "-dynamic-linker") && argv[1]) | |
1369 { | |
1370 ++argv; | |
1371 *ld1++ = *ld2++ = *argv; | |
1372 } | |
1373 break; | |
1374 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1375 case 'f': |
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
|
1376 if (strncmp (arg, "-flto", 5) == 0) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1377 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1378 #ifdef ENABLE_LTO |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1379 /* Do not pass LTO flag to the linker. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1380 ld1--; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1381 ld2--; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1382 #else |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1383 error ("LTO support has not been enabled in this " |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1384 "configuration"); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1385 #endif |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1386 } |
111 | 1387 else if (!use_collect_ld |
1388 && strncmp (arg, "-fuse-ld=", 9) == 0) | |
1389 { | |
145 | 1390 /* Do not pass -fuse-ld={bfd|gold|lld} to the linker. */ |
111 | 1391 ld1--; |
1392 ld2--; | |
1393 } | |
1394 else if (strncmp (arg, "-fno-lto", 8) == 0) | |
1395 { | |
1396 /* Do not pass -fno-lto to the linker. */ | |
1397 ld1--; | |
1398 ld2--; | |
1399 } | |
1400 #ifdef TARGET_AIX_VERSION | |
1401 else | |
1402 { | |
1403 /* File containing a list of input files to process. */ | |
1404 | |
1405 FILE *stream; | |
1406 char buf[MAXPATHLEN + 2]; | |
1407 /* Number of additionnal object files. */ | |
1408 int add_nbr = 0; | |
1409 /* Maximum of additionnal object files before vector | |
1410 expansion. */ | |
1411 int add_max = 0; | |
1412 const char *list_filename = arg + 2; | |
1413 | |
1414 /* Accept -fFILENAME and -f FILENAME. */ | |
1415 if (*list_filename == '\0' && argv[1]) | |
1416 { | |
1417 ++argv; | |
1418 list_filename = *argv; | |
1419 *ld1++ = *ld2++ = *argv; | |
1420 } | |
1421 | |
1422 stream = fopen (list_filename, "r"); | |
1423 if (stream == NULL) | |
145 | 1424 fatal_error (input_location, "cannot open %s: %m", |
111 | 1425 list_filename); |
1426 | |
1427 while (fgets (buf, sizeof buf, stream) != NULL) | |
1428 { | |
1429 /* Remove end of line. */ | |
1430 int len = strlen (buf); | |
1431 if (len >= 1 && buf[len - 1] =='\n') | |
1432 buf[len - 1] = '\0'; | |
1433 | |
1434 /* Put on object vector. | |
1435 Note: we only expanse vector here, so we must keep | |
1436 extra space for remaining arguments. */ | |
1437 if (add_nbr >= add_max) | |
1438 { | |
1439 int pos = | |
1440 object - CONST_CAST2 (const char **, char **, | |
1441 object_lst); | |
1442 add_max = (add_max == 0) ? 16 : add_max * 2; | |
1443 object_lst = XRESIZEVEC (char *, object_lst, | |
1444 object_nbr + add_max); | |
1445 object = CONST_CAST2 (const char **, char **, | |
1446 object_lst) + pos; | |
1447 object_nbr += add_max; | |
1448 } | |
1449 *object++ = xstrdup (buf); | |
1450 add_nbr++; | |
1451 } | |
1452 fclose (stream); | |
1453 } | |
1454 #endif | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1455 break; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1456 |
131 | 1457 #ifdef COLLECT_EXPORT_LIST |
1458 case 'b': | |
1459 if (!strcmp (arg, "-bstatic")) | |
1460 { | |
1461 is_static = true; | |
1462 } | |
1463 else if (!strcmp (arg, "-bdynamic") || !strcmp (arg, "-bshared")) | |
1464 { | |
1465 is_static = false; | |
1466 } | |
1467 break; | |
1468 #endif | |
0 | 1469 case 'l': |
1470 if (first_file) | |
1471 { | |
1472 /* place o_file BEFORE this argument! */ | |
1473 first_file = 0; | |
1474 ld2--; | |
1475 *ld2++ = o_file; | |
1476 *ld2++ = arg; | |
1477 } | |
1478 #ifdef COLLECT_EXPORT_LIST | |
1479 { | |
1480 /* Resolving full library name. */ | |
1481 const char *s = resolve_lib_name (arg+2); | |
1482 | |
1483 /* Saving a full library name. */ | |
1484 add_to_list (&libs, s); | |
131 | 1485 if (is_static) |
1486 add_to_list (&static_libs, s); | |
0 | 1487 } |
1488 #endif | |
1489 break; | |
1490 | |
1491 #ifdef COLLECT_EXPORT_LIST | |
1492 /* Saving directories where to search for libraries. */ | |
1493 case 'L': | |
1494 add_prefix (&cmdline_lib_dirs, arg+2); | |
1495 break; | |
1496 #endif | |
1497 | |
1498 case 'o': | |
1499 if (arg[2] == '\0') | |
1500 output_file = *ld1++ = *ld2++ = *++argv; | |
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
|
1501 else |
0 | 1502 output_file = &arg[2]; |
1503 break; | |
1504 | |
1505 case 'r': | |
1506 if (arg[2] == '\0') | |
1507 rflag = 1; | |
1508 break; | |
1509 | |
1510 case 's': | |
1511 if (arg[2] == '\0' && do_collecting) | |
1512 { | |
1513 /* We must strip after the nm run, otherwise C++ linking | |
1514 will not work. Thus we strip in the second ld run, or | |
1515 else with strip if there is no second ld run. */ | |
1516 strip_flag = 1; | |
1517 ld1--; | |
1518 } | |
1519 break; | |
1520 | |
1521 case 'v': | |
1522 if (arg[2] == '\0') | |
111 | 1523 verbose = true; |
0 | 1524 break; |
1525 | |
1526 case '-': | |
1527 if (strcmp (arg, "--no-demangle") == 0) | |
1528 { | |
111 | 1529 #ifndef HAVE_LD_DEMANGLE |
0 | 1530 no_demangle = 1; |
1531 ld1--; | |
1532 ld2--; | |
111 | 1533 #endif |
0 | 1534 } |
1535 else if (strncmp (arg, "--demangle", 10) == 0) | |
1536 { | |
111 | 1537 #ifndef HAVE_LD_DEMANGLE |
0 | 1538 no_demangle = 0; |
1539 if (arg[10] == '=') | |
1540 { | |
1541 enum demangling_styles style | |
1542 = cplus_demangle_name_to_style (arg+11); | |
1543 if (style == unknown_demangling) | |
145 | 1544 error ("unknown demangling style %qs", arg+11); |
0 | 1545 else |
1546 current_demangling_style = style; | |
1547 } | |
1548 ld1--; | |
1549 ld2--; | |
111 | 1550 #endif |
0 | 1551 } |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1552 else if (strncmp (arg, "--sysroot=", 10) == 0) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1553 target_system_root = arg + 10; |
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 else if (strcmp (arg, "--version") == 0) |
111 | 1555 verbose = true; |
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
|
1556 else if (strcmp (arg, "--help") == 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
|
1557 helpflag = true; |
0 | 1558 break; |
1559 } | |
1560 } | |
1561 else if ((p = strrchr (arg, '.')) != (char *) 0 | |
1562 && (strcmp (p, ".o") == 0 || strcmp (p, ".a") == 0 | |
1563 || strcmp (p, ".so") == 0 || strcmp (p, ".lo") == 0 | |
1564 || strcmp (p, ".obj") == 0)) | |
1565 { | |
1566 if (first_file) | |
1567 { | |
1568 first_file = 0; | |
1569 if (p[1] == 'o') | |
1570 *ld2++ = o_file; | |
1571 else | |
1572 { | |
1573 /* place o_file BEFORE this argument! */ | |
1574 ld2--; | |
1575 *ld2++ = o_file; | |
1576 *ld2++ = arg; | |
1577 } | |
1578 } | |
1579 if (p[1] == 'o' || p[1] == 'l') | |
1580 *object++ = arg; | |
1581 #ifdef COLLECT_EXPORT_LIST | |
1582 /* libraries can be specified directly, i.e. without -l flag. */ | |
1583 else | |
1584 { | |
1585 /* Saving a full library name. */ | |
1586 add_to_list (&libs, arg); | |
131 | 1587 if (is_static) |
1588 add_to_list (&static_libs, arg); | |
0 | 1589 } |
1590 #endif | |
1591 } | |
1592 } | |
1593 | |
1594 #ifdef COLLECT_EXPORT_LIST | |
1595 /* This is added only for debugging purposes. */ | |
1596 if (debug) | |
1597 { | |
1598 fprintf (stderr, "List of libraries:\n"); | |
1599 dump_list (stderr, "\t", libs.first); | |
131 | 1600 fprintf (stderr, "List of statically linked libraries:\n"); |
1601 dump_list (stderr, "\t", static_libs.first); | |
0 | 1602 } |
1603 | |
1604 /* The AIX linker will discard static constructors in object files if | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1605 nothing else in the file is referenced, so look at them first. Unless |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1606 we are building a shared object, ignore the eh frame tables, as we |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1607 would otherwise reference them all, hence drag all the corresponding |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1608 objects even if nothing else is referenced. */ |
0 | 1609 { |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1610 const char **export_object_lst |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1611 = CONST_CAST2 (const char **, char **, object_lst); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1612 |
0 | 1613 struct id *list = libs.first; |
1614 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1615 /* Compute the filter to use from the current one, do scan, then adjust |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1616 the "current" filter to remove what we just included here. This will |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1617 control whether we need a first pass link later on or not, and what |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1618 will remain to be scanned there. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1619 |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1620 scanfilter this_filter = ld1_filter; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1621 #if HAVE_AS_REF |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1622 if (!shared_obj) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1623 this_filter &= ~SCAN_DWEH; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1624 #endif |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1625 |
131 | 1626 /* Scan object files. */ |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1627 while (export_object_lst < object) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1628 scan_prog_file (*export_object_lst++, PASS_OBJ, this_filter); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1629 |
131 | 1630 /* Scan libraries. */ |
0 | 1631 for (; list; list = list->next) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1632 scan_prog_file (list->name, PASS_FIRST, this_filter); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1633 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1634 ld1_filter = ld1_filter & ~this_filter; |
0 | 1635 } |
1636 | |
1637 if (exports.first) | |
1638 { | |
1639 char *buf = concat ("-bE:", export_file, NULL); | |
1640 | |
1641 *ld1++ = buf; | |
1642 *ld2++ = buf; | |
1643 | |
1644 exportf = fopen (export_file, "w"); | |
1645 if (exportf == (FILE *) 0) | |
111 | 1646 fatal_error (input_location, "fopen %s: %m", export_file); |
0 | 1647 write_aix_file (exportf, exports.first); |
1648 if (fclose (exportf)) | |
111 | 1649 fatal_error (input_location, "fclose %s: %m", export_file); |
0 | 1650 } |
1651 #endif | |
1652 | |
1653 *c_ptr++ = c_file; | |
1654 *c_ptr = *ld1 = *object = (char *) 0; | |
1655 | |
111 | 1656 if (verbose) |
1657 notice ("collect2 version %s\n", version_string); | |
0 | 1658 |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1659 if (helpflag) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1660 { |
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
|
1661 printf ("Usage: collect2 [options]\n"); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1662 printf (" Wrap linker and generate constructor code if needed.\n"); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1663 printf (" Options:\n"); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1664 printf (" -debug Enable debug output\n"); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1665 printf (" --help Display this information\n"); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1666 printf (" -v, --version Display this program's version number\n"); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1667 printf ("\n"); |
145 | 1668 printf ("Overview: https://gcc.gnu.org/onlinedocs/gccint/Collect2.html\n"); |
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
|
1669 printf ("Report bugs: %s\n", bug_report_url); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1670 printf ("\n"); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1671 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1672 |
0 | 1673 if (debug) |
1674 { | |
1675 const char *ptr; | |
1676 fprintf (stderr, "ld_file_name = %s\n", | |
1677 (ld_file_name ? ld_file_name : "not found")); | |
1678 fprintf (stderr, "c_file_name = %s\n", | |
1679 (c_file_name ? c_file_name : "not found")); | |
1680 fprintf (stderr, "nm_file_name = %s\n", | |
1681 (nm_file_name ? nm_file_name : "not found")); | |
1682 #ifdef LDD_SUFFIX | |
1683 fprintf (stderr, "ldd_file_name = %s\n", | |
1684 (ldd_file_name ? ldd_file_name : "not found")); | |
1685 #endif | |
1686 fprintf (stderr, "strip_file_name = %s\n", | |
1687 (strip_file_name ? strip_file_name : "not found")); | |
1688 fprintf (stderr, "c_file = %s\n", | |
1689 (c_file ? c_file : "not found")); | |
1690 fprintf (stderr, "o_file = %s\n", | |
1691 (o_file ? o_file : "not found")); | |
1692 | |
1693 ptr = getenv ("COLLECT_GCC_OPTIONS"); | |
1694 if (ptr) | |
1695 fprintf (stderr, "COLLECT_GCC_OPTIONS = %s\n", ptr); | |
1696 | |
1697 ptr = getenv ("COLLECT_GCC"); | |
1698 if (ptr) | |
1699 fprintf (stderr, "COLLECT_GCC = %s\n", ptr); | |
1700 | |
1701 ptr = getenv ("COMPILER_PATH"); | |
1702 if (ptr) | |
1703 fprintf (stderr, "COMPILER_PATH = %s\n", ptr); | |
1704 | |
1705 ptr = getenv (LIBRARY_PATH_ENV); | |
1706 if (ptr) | |
1707 fprintf (stderr, "%-20s= %s\n", LIBRARY_PATH_ENV, ptr); | |
1708 | |
1709 fprintf (stderr, "\n"); | |
1710 } | |
1711 | |
1712 /* Load the program, searching all libraries and attempting to provide | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1713 undefined symbols from repository information. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1714 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1715 If -r or they will be run via some other method, do not build the |
0 | 1716 constructor or destructor list, just return now. */ |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1717 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1718 bool early_exit |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1719 = rflag || (! DO_COLLECT_EXPORT_LIST && ! do_collecting); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1720 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1721 /* Perform the first pass link now, if we're about to exit or if we need |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1722 to scan for things we haven't collected yet before pursuing further. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1723 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1724 On AIX, the latter typically includes nothing for shared objects or |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1725 frame tables for an executable, out of what the required early scan on |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1726 objects and libraries has performed above. In the !shared_obj case, we |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1727 expect the relevant tables to be dragged together with their associated |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1728 functions from precise cross reference insertions by the compiler. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1729 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1730 if (early_exit || ld1_filter != SCAN_NOTHING) |
145 | 1731 do_link (ld1_argv); |
0 | 1732 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1733 if (early_exit) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1734 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1735 #ifdef COLLECT_EXPORT_LIST |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1736 /* Make sure we delete the export file we may have created. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1737 if (export_file != 0 && export_file[0]) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1738 maybe_unlink (export_file); |
0 | 1739 #endif |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1740 if (lto_mode != LTO_MODE_NONE) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1741 maybe_run_lto_and_relink (ld1_argv, object_lst, object, false); |
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
|
1742 else |
145 | 1743 post_ld_pass (/*temp_file*/false); |
1744 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1745 return 0; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1746 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1747 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1748 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1749 /* Unless we have done it all already, examine the namelist and search for |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1750 static constructors and destructors to call. Write the constructor and |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1751 destructor tables to a .s file and reload. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1752 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1753 if (ld1_filter != SCAN_NOTHING) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1754 scan_prog_file (output_file, PASS_FIRST, ld1_filter); |
0 | 1755 |
1756 #ifdef SCAN_LIBRARIES | |
1757 scan_libraries (output_file); | |
1758 #endif | |
1759 | |
1760 if (debug) | |
1761 { | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1762 notice_translated (ngettext ("%d constructor found\n", |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1763 "%d constructors found\n", |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1764 constructors.number), |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1765 constructors.number); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1766 notice_translated (ngettext ("%d destructor found\n", |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1767 "%d destructors found\n", |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1768 destructors.number), |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1769 destructors.number); |
111 | 1770 notice_translated (ngettext ("%d frame table found\n", |
1771 "%d frame tables found\n", | |
1772 frame_tables.number), | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1773 frame_tables.number); |
0 | 1774 } |
1775 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1776 /* If the scan exposed nothing of special interest, there's no need to |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1777 generate the glue code and relink so return now. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1778 |
0 | 1779 if (constructors.number == 0 && destructors.number == 0 |
1780 && frame_tables.number == 0 | |
1781 #if defined (SCAN_LIBRARIES) || defined (COLLECT_EXPORT_LIST) | |
1782 /* If we will be running these functions ourselves, we want to emit | |
1783 stubs into the shared library so that we do not have to relink | |
1784 dependent programs when we add static objects. */ | |
1785 && ! shared_obj | |
1786 #endif | |
1787 ) | |
1788 { | |
145 | 1789 /* Do link without additional code generation now if we didn't |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1790 do it earlier for scanning purposes. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1791 if (ld1_filter == SCAN_NOTHING) |
145 | 1792 do_link (ld1_argv); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1793 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1794 if (lto_mode) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1795 maybe_run_lto_and_relink (ld1_argv, object_lst, object, false); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1796 |
0 | 1797 /* Strip now if it was requested on the command line. */ |
1798 if (strip_flag) | |
1799 { | |
1800 char **real_strip_argv = XCNEWVEC (char *, 3); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1801 const char ** strip_argv = CONST_CAST2 (const char **, char **, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1802 real_strip_argv); |
0 | 1803 |
1804 strip_argv[0] = strip_file_name; | |
1805 strip_argv[1] = output_file; | |
1806 strip_argv[2] = (char *) 0; | |
111 | 1807 fork_execute ("strip", real_strip_argv, false); |
0 | 1808 } |
1809 | |
1810 #ifdef COLLECT_EXPORT_LIST | |
1811 maybe_unlink (export_file); | |
1812 #endif | |
145 | 1813 post_ld_pass (/*temp_file*/false); |
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
|
1814 |
0 | 1815 maybe_unlink (c_file); |
1816 maybe_unlink (o_file); | |
1817 return 0; | |
1818 } | |
1819 | |
1820 /* Sort ctor and dtor lists by priority. */ | |
1821 sort_ids (&constructors); | |
1822 sort_ids (&destructors); | |
1823 | |
111 | 1824 maybe_unlink (output_file); |
0 | 1825 outf = fopen (c_file, "w"); |
1826 if (outf == (FILE *) 0) | |
111 | 1827 fatal_error (input_location, "fopen %s: %m", c_file); |
0 | 1828 |
1829 write_c_file (outf, c_file); | |
1830 | |
1831 if (fclose (outf)) | |
111 | 1832 fatal_error (input_location, "fclose %s: %m", c_file); |
0 | 1833 |
1834 /* Tell the linker that we have initializer and finalizer functions. */ | |
1835 #ifdef LD_INIT_SWITCH | |
1836 #ifdef COLLECT_EXPORT_LIST | |
1837 *ld2++ = concat (LD_INIT_SWITCH, ":", initname, ":", fininame, NULL); | |
1838 #else | |
1839 *ld2++ = LD_INIT_SWITCH; | |
1840 *ld2++ = initname; | |
1841 *ld2++ = LD_FINI_SWITCH; | |
1842 *ld2++ = fininame; | |
1843 #endif | |
1844 #endif | |
1845 | |
1846 #ifdef COLLECT_EXPORT_LIST | |
1847 if (shared_obj) | |
1848 { | |
1849 /* If we did not add export flag to link arguments before, add it to | |
1850 second link phase now. No new exports should have been added. */ | |
1851 if (! exports.first) | |
1852 *ld2++ = concat ("-bE:", export_file, NULL); | |
1853 | |
111 | 1854 #ifdef TARGET_AIX_VERSION |
1855 add_to_list (&exports, aix_shared_initname); | |
1856 add_to_list (&exports, aix_shared_fininame); | |
1857 #endif | |
1858 | |
0 | 1859 #ifndef LD_INIT_SWITCH |
1860 add_to_list (&exports, initname); | |
1861 add_to_list (&exports, fininame); | |
1862 add_to_list (&exports, "_GLOBAL__DI"); | |
1863 add_to_list (&exports, "_GLOBAL__DD"); | |
1864 #endif | |
1865 exportf = fopen (export_file, "w"); | |
1866 if (exportf == (FILE *) 0) | |
111 | 1867 fatal_error (input_location, "fopen %s: %m", export_file); |
0 | 1868 write_aix_file (exportf, exports.first); |
1869 if (fclose (exportf)) | |
111 | 1870 fatal_error (input_location, "fclose %s: %m", export_file); |
0 | 1871 } |
1872 #endif | |
1873 | |
1874 /* End of arguments to second link phase. */ | |
1875 *ld2 = (char*) 0; | |
1876 | |
1877 if (debug) | |
1878 { | |
1879 fprintf (stderr, "\n========== output_file = %s, c_file = %s\n", | |
1880 output_file, c_file); | |
1881 write_c_file (stderr, "stderr"); | |
1882 fprintf (stderr, "========== end of c_file\n\n"); | |
1883 #ifdef COLLECT_EXPORT_LIST | |
1884 fprintf (stderr, "\n========== export_file = %s\n", export_file); | |
1885 write_aix_file (stderr, exports.first); | |
1886 fprintf (stderr, "========== end of export_file\n\n"); | |
1887 #endif | |
1888 } | |
1889 | |
1890 /* Assemble the constructor and destructor tables. | |
1891 Link the tables in with the rest of the program. */ | |
1892 | |
111 | 1893 fork_execute ("gcc", c_argv, at_file_supplied); |
0 | 1894 #ifdef COLLECT_EXPORT_LIST |
145 | 1895 /* On AIX we must call link because of possible templates resolution. */ |
1896 do_link (ld2_argv); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1897 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1898 if (lto_mode) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1899 maybe_run_lto_and_relink (ld2_argv, object_lst, object, false); |
0 | 1900 #else |
145 | 1901 /* Otherwise, simply call ld because link is already done. */ |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1902 if (lto_mode) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1903 maybe_run_lto_and_relink (ld2_argv, object_lst, object, true); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1904 else |
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
|
1905 { |
111 | 1906 fork_execute ("ld", ld2_argv, HAVE_GNU_LD && at_file_supplied); |
145 | 1907 post_ld_pass (/*temp_file*/false); |
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
|
1908 } |
0 | 1909 |
1910 /* Let scan_prog_file do any final mods (OSF/rose needs this for | |
1911 constructors/destructors in shared libraries. */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1912 scan_prog_file (output_file, PASS_SECOND, SCAN_ALL); |
0 | 1913 #endif |
1914 | |
1915 maybe_unlink (c_file); | |
1916 maybe_unlink (o_file); | |
1917 | |
1918 #ifdef COLLECT_EXPORT_LIST | |
1919 maybe_unlink (export_file); | |
1920 #endif | |
1921 | |
1922 return 0; | |
1923 } | |
1924 | |
1925 | |
111 | 1926 /* Unlink FILE unless we are debugging or this is the output_file |
1927 and we may not unlink it. */ | |
1928 | |
1929 void | |
0 | 1930 maybe_unlink (const char *file) |
1931 { | |
145 | 1932 if (save_temps && file_exists (file)) |
111 | 1933 { |
145 | 1934 if (verbose) |
1935 notice ("[Leaving %s]\n", file); | |
111 | 1936 return; |
1937 } | |
1938 | |
1939 if (file == output_file && !may_unlink_output_file) | |
1940 return; | |
1941 | |
1942 unlink_if_ordinary (file); | |
0 | 1943 } |
1944 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1945 /* Call maybe_unlink on the NULL-terminated list, FILE_LIST. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1946 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1947 static void |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1948 maybe_unlink_list (char **file_list) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1949 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1950 char **tmp = file_list; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1951 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1952 while (*tmp) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1953 maybe_unlink (*(tmp++)); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1954 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1955 |
0 | 1956 |
1957 static long sequence_number = 0; | |
1958 | |
1959 /* Add a name to a linked list. */ | |
1960 | |
1961 static void | |
1962 add_to_list (struct head *head_ptr, const char *name) | |
1963 { | |
1964 struct id *newid | |
1965 = (struct id *) xcalloc (sizeof (struct id) + strlen (name), 1); | |
1966 struct id *p; | |
1967 strcpy (newid->name, name); | |
1968 | |
1969 if (head_ptr->first) | |
1970 head_ptr->last->next = newid; | |
1971 else | |
1972 head_ptr->first = newid; | |
1973 | |
1974 /* Check for duplicate symbols. */ | |
1975 for (p = head_ptr->first; | |
1976 strcmp (name, p->name) != 0; | |
1977 p = p->next) | |
1978 ; | |
1979 if (p != newid) | |
1980 { | |
1981 head_ptr->last->next = 0; | |
1982 free (newid); | |
1983 return; | |
1984 } | |
1985 | |
1986 newid->sequence = ++sequence_number; | |
1987 head_ptr->last = newid; | |
1988 head_ptr->number++; | |
1989 } | |
1990 | |
1991 /* Grab the init priority number from an init function name that | |
1992 looks like "_GLOBAL_.I.12345.foo". */ | |
1993 | |
1994 static int | |
1995 extract_init_priority (const char *name) | |
1996 { | |
1997 int pos = 0, pri; | |
1998 | |
111 | 1999 #ifdef TARGET_AIX_VERSION |
2000 /* Run dependent module initializers before any constructors in this | |
2001 module. */ | |
2002 switch (is_ctor_dtor (name)) | |
2003 { | |
2004 case SYM_AIXI: | |
2005 case SYM_AIXD: | |
2006 return INT_MIN; | |
2007 default: | |
2008 break; | |
2009 } | |
2010 #endif | |
2011 | |
0 | 2012 while (name[pos] == '_') |
2013 ++pos; | |
2014 pos += 10; /* strlen ("GLOBAL__X_") */ | |
2015 | |
2016 /* Extract init_p number from ctor/dtor name. */ | |
2017 pri = atoi (name + pos); | |
2018 return pri ? pri : DEFAULT_INIT_PRIORITY; | |
2019 } | |
2020 | |
2021 /* Insertion sort the ids from ctor/dtor list HEAD_PTR in descending order. | |
2022 ctors will be run from right to left, dtors from left to right. */ | |
2023 | |
2024 static void | |
2025 sort_ids (struct head *head_ptr) | |
2026 { | |
2027 /* id holds the current element to insert. id_next holds the next | |
2028 element to insert. id_ptr iterates through the already sorted elements | |
2029 looking for the place to insert id. */ | |
2030 struct id *id, *id_next, **id_ptr; | |
2031 | |
2032 id = head_ptr->first; | |
2033 | |
2034 /* We don't have any sorted elements yet. */ | |
2035 head_ptr->first = NULL; | |
2036 | |
2037 for (; id; id = id_next) | |
2038 { | |
2039 id_next = id->next; | |
2040 id->sequence = extract_init_priority (id->name); | |
2041 | |
2042 for (id_ptr = &(head_ptr->first); ; id_ptr = &((*id_ptr)->next)) | |
2043 if (*id_ptr == NULL | |
2044 /* If the sequence numbers are the same, we put the id from the | |
2045 file later on the command line later in the list. */ | |
2046 || id->sequence > (*id_ptr)->sequence | |
2047 /* Hack: do lexical compare, too. | |
2048 || (id->sequence == (*id_ptr)->sequence | |
2049 && strcmp (id->name, (*id_ptr)->name) > 0) */ | |
2050 ) | |
2051 { | |
2052 id->next = *id_ptr; | |
2053 *id_ptr = id; | |
2054 break; | |
2055 } | |
2056 } | |
2057 | |
2058 /* Now set the sequence numbers properly so write_c_file works. */ | |
2059 for (id = head_ptr->first; id; id = id->next) | |
2060 id->sequence = ++sequence_number; | |
2061 } | |
2062 | |
2063 /* Write: `prefix', the names on list LIST, `suffix'. */ | |
2064 | |
2065 static void | |
2066 write_list (FILE *stream, const char *prefix, struct id *list) | |
2067 { | |
2068 while (list) | |
2069 { | |
2070 fprintf (stream, "%sx%d,\n", prefix, list->sequence); | |
2071 list = list->next; | |
2072 } | |
2073 } | |
2074 | |
2075 #ifdef COLLECT_EXPORT_LIST | |
2076 /* This function is really used only on AIX, but may be useful. */ | |
2077 static int | |
2078 is_in_list (const char *prefix, struct id *list) | |
2079 { | |
2080 while (list) | |
2081 { | |
2082 if (!strcmp (prefix, list->name)) return 1; | |
2083 list = list->next; | |
2084 } | |
2085 return 0; | |
2086 } | |
2087 #endif /* COLLECT_EXPORT_LIST */ | |
2088 | |
2089 /* Added for debugging purpose. */ | |
2090 #ifdef COLLECT_EXPORT_LIST | |
2091 static void | |
2092 dump_list (FILE *stream, const char *prefix, struct id *list) | |
2093 { | |
2094 while (list) | |
2095 { | |
2096 fprintf (stream, "%s%s,\n", prefix, list->name); | |
2097 list = list->next; | |
2098 } | |
2099 } | |
2100 #endif | |
2101 | |
2102 #if 0 | |
2103 static void | |
2104 dump_prefix_list (FILE *stream, const char *prefix, struct prefix_list *list) | |
2105 { | |
2106 while (list) | |
2107 { | |
2108 fprintf (stream, "%s%s,\n", prefix, list->prefix); | |
2109 list = list->next; | |
2110 } | |
2111 } | |
2112 #endif | |
2113 | |
2114 static void | |
2115 write_list_with_asm (FILE *stream, const char *prefix, struct id *list) | |
2116 { | |
2117 while (list) | |
2118 { | |
2119 fprintf (stream, "%sx%d __asm__ (\"%s\");\n", | |
2120 prefix, list->sequence, list->name); | |
2121 list = list->next; | |
2122 } | |
2123 } | |
2124 | |
2125 /* Write out the constructor and destructor tables statically (for a shared | |
2126 object), along with the functions to execute them. */ | |
2127 | |
2128 static void | |
2129 write_c_file_stat (FILE *stream, const char *name ATTRIBUTE_UNUSED) | |
2130 { | |
2131 const char *p, *q; | |
2132 char *prefix, *r; | |
2133 int frames = (frame_tables.number > 0); | |
2134 | |
2135 /* Figure out name of output_file, stripping off .so version. */ | |
111 | 2136 q = p = lbasename (output_file); |
2137 | |
0 | 2138 while (q) |
2139 { | |
2140 q = strchr (q,'.'); | |
2141 if (q == 0) | |
2142 { | |
2143 q = p + strlen (p); | |
2144 break; | |
2145 } | |
2146 else | |
2147 { | |
111 | 2148 if (filename_ncmp (q, SHLIB_SUFFIX, strlen (SHLIB_SUFFIX)) == 0) |
0 | 2149 { |
2150 q += strlen (SHLIB_SUFFIX); | |
2151 break; | |
2152 } | |
2153 else | |
2154 q++; | |
2155 } | |
2156 } | |
2157 /* q points to null at end of the string (or . of the .so version) */ | |
2158 prefix = XNEWVEC (char, q - p + 1); | |
2159 strncpy (prefix, p, q - p); | |
2160 prefix[q - p] = 0; | |
2161 for (r = prefix; *r; r++) | |
2162 if (!ISALNUM ((unsigned char)*r)) | |
2163 *r = '_'; | |
2164 if (debug) | |
2165 notice ("\nwrite_c_file - output name is %s, prefix is %s\n", | |
2166 output_file, prefix); | |
2167 | |
2168 initname = concat ("_GLOBAL__FI_", prefix, NULL); | |
2169 fininame = concat ("_GLOBAL__FD_", prefix, NULL); | |
111 | 2170 #ifdef TARGET_AIX_VERSION |
2171 aix_shared_initname = concat ("_GLOBAL__AIXI_", prefix, NULL); | |
2172 aix_shared_fininame = concat ("_GLOBAL__AIXD_", prefix, NULL); | |
2173 #endif | |
0 | 2174 |
2175 free (prefix); | |
2176 | |
2177 /* Write the tables as C code. */ | |
2178 | |
111 | 2179 /* This count variable is used to prevent multiple calls to the |
2180 constructors/destructors. | |
2181 This guard against multiple calls is important on AIX as the initfini | |
2182 functions are deliberately invoked multiple times as part of the | |
2183 mechanisms GCC uses to order constructors across different dependent | |
2184 shared libraries (see config/rs6000/aix.h). | |
2185 */ | |
0 | 2186 fprintf (stream, "static int count;\n"); |
2187 fprintf (stream, "typedef void entry_pt();\n"); | |
2188 write_list_with_asm (stream, "extern entry_pt ", constructors.first); | |
2189 | |
2190 if (frames) | |
2191 { | |
2192 write_list_with_asm (stream, "extern void *", frame_tables.first); | |
2193 | |
2194 fprintf (stream, "\tstatic void *frame_table[] = {\n"); | |
2195 write_list (stream, "\t\t&", frame_tables.first); | |
2196 fprintf (stream, "\t0\n};\n"); | |
2197 | |
2198 /* This must match what's in frame.h. */ | |
2199 fprintf (stream, "struct object {\n"); | |
2200 fprintf (stream, " void *pc_begin;\n"); | |
2201 fprintf (stream, " void *pc_end;\n"); | |
2202 fprintf (stream, " void *fde_begin;\n"); | |
2203 fprintf (stream, " void *fde_array;\n"); | |
2204 fprintf (stream, " __SIZE_TYPE__ count;\n"); | |
2205 fprintf (stream, " struct object *next;\n"); | |
2206 fprintf (stream, "};\n"); | |
2207 | |
111 | 2208 fprintf (stream, "extern void __register_frame_info_table_bases (void *, struct object *, void *tbase, void *dbase);\n"); |
0 | 2209 fprintf (stream, "extern void __register_frame_info_table (void *, struct object *);\n"); |
2210 fprintf (stream, "extern void *__deregister_frame_info (void *);\n"); | |
111 | 2211 #ifdef TARGET_AIX_VERSION |
2212 fprintf (stream, "extern void *__gcc_unwind_dbase;\n"); | |
2213 #endif | |
0 | 2214 |
2215 fprintf (stream, "static void reg_frame () {\n"); | |
2216 fprintf (stream, "\tstatic struct object ob;\n"); | |
111 | 2217 #ifdef TARGET_AIX_VERSION |
2218 /* Use __gcc_unwind_dbase as the base address for data on AIX. | |
2219 This might not be the start of the segment, signed offsets assumed. | |
2220 */ | |
2221 fprintf (stream, "\t__register_frame_info_table_bases (frame_table, &ob, (void *)0, &__gcc_unwind_dbase);\n"); | |
2222 #else | |
0 | 2223 fprintf (stream, "\t__register_frame_info_table (frame_table, &ob);\n"); |
111 | 2224 #endif |
0 | 2225 fprintf (stream, "\t}\n"); |
2226 | |
2227 fprintf (stream, "static void dereg_frame () {\n"); | |
2228 fprintf (stream, "\t__deregister_frame_info (frame_table);\n"); | |
2229 fprintf (stream, "\t}\n"); | |
2230 } | |
2231 | |
2232 fprintf (stream, "void %s() {\n", initname); | |
2233 if (constructors.number > 0 || frames) | |
2234 { | |
2235 fprintf (stream, "\tstatic entry_pt *ctors[] = {\n"); | |
2236 write_list (stream, "\t\t", constructors.first); | |
2237 if (frames) | |
2238 fprintf (stream, "\treg_frame,\n"); | |
2239 fprintf (stream, "\t};\n"); | |
2240 fprintf (stream, "\tentry_pt **p;\n"); | |
2241 fprintf (stream, "\tif (count++ != 0) return;\n"); | |
2242 fprintf (stream, "\tp = ctors + %d;\n", constructors.number + frames); | |
2243 fprintf (stream, "\twhile (p > ctors) (*--p)();\n"); | |
2244 } | |
2245 else | |
2246 fprintf (stream, "\t++count;\n"); | |
2247 fprintf (stream, "}\n"); | |
2248 write_list_with_asm (stream, "extern entry_pt ", destructors.first); | |
2249 fprintf (stream, "void %s() {\n", fininame); | |
2250 if (destructors.number > 0 || frames) | |
2251 { | |
2252 fprintf (stream, "\tstatic entry_pt *dtors[] = {\n"); | |
2253 write_list (stream, "\t\t", destructors.first); | |
2254 if (frames) | |
2255 fprintf (stream, "\tdereg_frame,\n"); | |
2256 fprintf (stream, "\t};\n"); | |
2257 fprintf (stream, "\tentry_pt **p;\n"); | |
2258 fprintf (stream, "\tif (--count != 0) return;\n"); | |
2259 fprintf (stream, "\tp = dtors;\n"); | |
2260 fprintf (stream, "\twhile (p < dtors + %d) (*p++)();\n", | |
2261 destructors.number + frames); | |
2262 } | |
2263 fprintf (stream, "}\n"); | |
2264 | |
2265 if (shared_obj) | |
2266 { | |
111 | 2267 COLLECT_SHARED_INIT_FUNC (stream, initname); |
2268 COLLECT_SHARED_FINI_FUNC (stream, fininame); | |
0 | 2269 } |
2270 } | |
2271 | |
2272 /* Write the constructor/destructor tables. */ | |
2273 | |
2274 #ifndef LD_INIT_SWITCH | |
2275 static void | |
2276 write_c_file_glob (FILE *stream, const char *name ATTRIBUTE_UNUSED) | |
2277 { | |
2278 /* Write the tables as C code. */ | |
2279 | |
2280 int frames = (frame_tables.number > 0); | |
2281 | |
2282 fprintf (stream, "typedef void entry_pt();\n\n"); | |
2283 | |
2284 write_list_with_asm (stream, "extern entry_pt ", constructors.first); | |
2285 | |
2286 if (frames) | |
2287 { | |
2288 write_list_with_asm (stream, "extern void *", frame_tables.first); | |
2289 | |
2290 fprintf (stream, "\tstatic void *frame_table[] = {\n"); | |
2291 write_list (stream, "\t\t&", frame_tables.first); | |
2292 fprintf (stream, "\t0\n};\n"); | |
2293 | |
2294 /* This must match what's in frame.h. */ | |
2295 fprintf (stream, "struct object {\n"); | |
2296 fprintf (stream, " void *pc_begin;\n"); | |
2297 fprintf (stream, " void *pc_end;\n"); | |
2298 fprintf (stream, " void *fde_begin;\n"); | |
2299 fprintf (stream, " void *fde_array;\n"); | |
2300 fprintf (stream, " __SIZE_TYPE__ count;\n"); | |
2301 fprintf (stream, " struct object *next;\n"); | |
2302 fprintf (stream, "};\n"); | |
2303 | |
2304 fprintf (stream, "extern void __register_frame_info_table (void *, struct object *);\n"); | |
2305 fprintf (stream, "extern void *__deregister_frame_info (void *);\n"); | |
2306 | |
2307 fprintf (stream, "static void reg_frame () {\n"); | |
2308 fprintf (stream, "\tstatic struct object ob;\n"); | |
2309 fprintf (stream, "\t__register_frame_info_table (frame_table, &ob);\n"); | |
2310 fprintf (stream, "\t}\n"); | |
2311 | |
2312 fprintf (stream, "static void dereg_frame () {\n"); | |
2313 fprintf (stream, "\t__deregister_frame_info (frame_table);\n"); | |
2314 fprintf (stream, "\t}\n"); | |
2315 } | |
2316 | |
2317 fprintf (stream, "\nentry_pt * __CTOR_LIST__[] = {\n"); | |
2318 fprintf (stream, "\t(entry_pt *) %d,\n", constructors.number + frames); | |
2319 write_list (stream, "\t", constructors.first); | |
2320 if (frames) | |
2321 fprintf (stream, "\treg_frame,\n"); | |
2322 fprintf (stream, "\t0\n};\n\n"); | |
2323 | |
2324 write_list_with_asm (stream, "extern entry_pt ", destructors.first); | |
2325 | |
2326 fprintf (stream, "\nentry_pt * __DTOR_LIST__[] = {\n"); | |
2327 fprintf (stream, "\t(entry_pt *) %d,\n", destructors.number + frames); | |
2328 write_list (stream, "\t", destructors.first); | |
2329 if (frames) | |
2330 fprintf (stream, "\tdereg_frame,\n"); | |
2331 fprintf (stream, "\t0\n};\n\n"); | |
2332 | |
2333 fprintf (stream, "extern entry_pt %s;\n", NAME__MAIN); | |
2334 fprintf (stream, "entry_pt *__main_reference = %s;\n\n", NAME__MAIN); | |
2335 } | |
2336 #endif /* ! LD_INIT_SWITCH */ | |
2337 | |
2338 static void | |
2339 write_c_file (FILE *stream, const char *name) | |
2340 { | |
2341 #ifndef LD_INIT_SWITCH | |
2342 if (! shared_obj) | |
2343 write_c_file_glob (stream, name); | |
2344 else | |
2345 #endif | |
2346 write_c_file_stat (stream, name); | |
2347 } | |
2348 | |
2349 #ifdef COLLECT_EXPORT_LIST | |
2350 static void | |
2351 write_aix_file (FILE *stream, struct id *list) | |
2352 { | |
2353 for (; list; list = list->next) | |
2354 { | |
2355 fputs (list->name, stream); | |
2356 putc ('\n', stream); | |
2357 } | |
2358 } | |
2359 #endif | |
2360 | |
2361 #ifdef OBJECT_FORMAT_NONE | |
2362 | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2363 /* Check to make sure the file is an LTO object file. */ |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2364 |
145 | 2365 static int |
2366 has_lto_section (void *data, const char *name ATTRIBUTE_UNUSED, | |
2367 off_t offset ATTRIBUTE_UNUSED, | |
2368 off_t length ATTRIBUTE_UNUSED) | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2369 { |
145 | 2370 int *found = (int *) data; |
2371 | |
2372 if (strncmp (name, LTO_SECTION_NAME_PREFIX, | |
2373 sizeof (LTO_SECTION_NAME_PREFIX) - 1) != 0) | |
2374 { | |
2375 if (strncmp (name, OFFLOAD_SECTION_NAME_PREFIX, | |
2376 sizeof (OFFLOAD_SECTION_NAME_PREFIX) - 1) != 0) | |
2377 return 1; | |
2378 } | |
2379 | |
2380 *found = 1; | |
2381 | |
2382 /* Stop iteration. */ | |
2383 return 0; | |
2384 } | |
2385 | |
2386 static bool | |
2387 is_lto_object_file (const char *prog_name) | |
2388 { | |
2389 const char *errmsg; | |
2390 int err; | |
2391 int found = 0; | |
2392 off_t inoff = 0; | |
2393 int infd = open (prog_name, O_RDONLY | O_BINARY); | |
2394 | |
2395 if (infd == -1) | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2396 return false; |
145 | 2397 |
2398 simple_object_read *inobj = simple_object_start_read (infd, inoff, | |
2399 LTO_SEGMENT_NAME, | |
2400 &errmsg, &err); | |
2401 if (!inobj) | |
2402 return false; | |
2403 | |
2404 errmsg = simple_object_find_sections (inobj, has_lto_section, | |
2405 (void *) &found, &err); | |
2406 if (! errmsg && found) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2407 return true; |
145 | 2408 |
2409 if (errmsg) | |
2410 fatal_error (0, "%s: %s", errmsg, xstrerror (err)); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2411 return false; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2412 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2413 |
0 | 2414 /* Generic version to scan the name list of the loaded program for |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2415 the symbols g++ uses for static constructors and destructors. */ |
0 | 2416 |
2417 static void | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2418 scan_prog_file (const char *prog_name, scanpass which_pass, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2419 scanfilter filter) |
0 | 2420 { |
2421 void (*int_handler) (int); | |
2422 #ifdef SIGQUIT | |
2423 void (*quit_handler) (int); | |
2424 #endif | |
2425 char *real_nm_argv[4]; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2426 const char **nm_argv = CONST_CAST2 (const char **, char**, real_nm_argv); |
0 | 2427 int argc = 0; |
2428 struct pex_obj *pex; | |
2429 const char *errmsg; | |
2430 int err; | |
2431 char *p, buf[1024]; | |
2432 FILE *inf; | |
2433 | |
2434 if (which_pass == PASS_SECOND) | |
2435 return; | |
2436 | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2437 /* LTO objects must be in a known format. This check prevents |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2438 us from accepting an archive containing LTO objects, which |
111 | 2439 gcc cannot currently handle. */ |
145 | 2440 if (which_pass == PASS_LTOINFO) |
2441 { | |
2442 if(is_lto_object_file (prog_name)) { | |
2443 add_lto_object (<o_objects, prog_name); | |
2444 } | |
2445 return; | |
2446 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2447 |
0 | 2448 /* If we do not have an `nm', complain. */ |
2449 if (nm_file_name == 0) | |
145 | 2450 fatal_error (input_location, "cannot find %<nm%>"); |
0 | 2451 |
2452 nm_argv[argc++] = nm_file_name; | |
2453 if (NM_FLAGS[0] != '\0') | |
2454 nm_argv[argc++] = NM_FLAGS; | |
2455 | |
2456 nm_argv[argc++] = prog_name; | |
2457 nm_argv[argc++] = (char *) 0; | |
2458 | |
2459 /* Trace if needed. */ | |
111 | 2460 if (verbose) |
0 | 2461 { |
2462 const char **p_argv; | |
2463 const char *str; | |
2464 | |
2465 for (p_argv = &nm_argv[0]; (str = *p_argv) != (char *) 0; p_argv++) | |
2466 fprintf (stderr, " %s", str); | |
2467 | |
2468 fprintf (stderr, "\n"); | |
2469 } | |
2470 | |
2471 fflush (stdout); | |
2472 fflush (stderr); | |
2473 | |
2474 pex = pex_init (PEX_USE_PIPES, "collect2", NULL); | |
2475 if (pex == NULL) | |
145 | 2476 fatal_error (input_location, "%<pex_init%> failed: %m"); |
0 | 2477 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2478 errmsg = pex_run (pex, 0, nm_file_name, real_nm_argv, NULL, HOST_BIT_BUCKET, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2479 &err); |
0 | 2480 if (errmsg != NULL) |
2481 { | |
2482 if (err != 0) | |
2483 { | |
2484 errno = err; | |
111 | 2485 fatal_error (input_location, "%s: %m", _(errmsg)); |
0 | 2486 } |
2487 else | |
111 | 2488 fatal_error (input_location, errmsg); |
0 | 2489 } |
2490 | |
2491 int_handler = (void (*) (int)) signal (SIGINT, SIG_IGN); | |
2492 #ifdef SIGQUIT | |
2493 quit_handler = (void (*) (int)) signal (SIGQUIT, SIG_IGN); | |
2494 #endif | |
2495 | |
2496 inf = pex_read_output (pex, 0); | |
2497 if (inf == NULL) | |
145 | 2498 fatal_error (input_location, "cannot open nm output: %m"); |
0 | 2499 |
2500 if (debug) | |
145 | 2501 fprintf (stderr, "\nnm output with constructors/destructors.\n"); |
0 | 2502 |
2503 /* Read each line of nm output. */ | |
2504 while (fgets (buf, sizeof buf, inf) != (char *) 0) | |
2505 { | |
2506 int ch, ch2; | |
2507 char *name, *end; | |
2508 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2509 if (debug) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2510 fprintf (stderr, "\t%s\n", buf); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2511 |
0 | 2512 /* If it contains a constructor or destructor name, add the name |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2513 to the appropriate list unless this is a kind of symbol we're |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2514 not supposed to even consider. */ |
0 | 2515 |
2516 for (p = buf; (ch = *p) != '\0' && ch != '\n' && ch != '_'; p++) | |
2517 if (ch == ' ' && p[1] == 'U' && p[2] == ' ') | |
2518 break; | |
2519 | |
2520 if (ch != '_') | |
2521 continue; | |
2522 | |
2523 name = p; | |
2524 /* Find the end of the symbol name. | |
2525 Do not include `|', because Encore nm can tack that on the end. */ | |
2526 for (end = p; (ch2 = *end) != '\0' && !ISSPACE (ch2) && ch2 != '|'; | |
2527 end++) | |
2528 continue; | |
2529 | |
2530 | |
2531 *end = '\0'; | |
111 | 2532 |
0 | 2533 switch (is_ctor_dtor (name)) |
2534 { | |
2535 case SYM_CTOR: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2536 if (! (filter & SCAN_CTOR)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2537 break; |
0 | 2538 if (which_pass != PASS_LIB) |
2539 add_to_list (&constructors, name); | |
2540 break; | |
2541 | |
2542 case SYM_DTOR: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2543 if (! (filter & SCAN_DTOR)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2544 break; |
0 | 2545 if (which_pass != PASS_LIB) |
2546 add_to_list (&destructors, name); | |
2547 break; | |
2548 | |
2549 case SYM_INIT: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2550 if (! (filter & SCAN_INIT)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2551 break; |
0 | 2552 if (which_pass != PASS_LIB) |
111 | 2553 fatal_error (input_location, "init function found in object %s", |
2554 prog_name); | |
0 | 2555 #ifndef LD_INIT_SWITCH |
2556 add_to_list (&constructors, name); | |
2557 #endif | |
2558 break; | |
2559 | |
2560 case SYM_FINI: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2561 if (! (filter & SCAN_FINI)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2562 break; |
0 | 2563 if (which_pass != PASS_LIB) |
111 | 2564 fatal_error (input_location, "fini function found in object %s", |
2565 prog_name); | |
0 | 2566 #ifndef LD_FINI_SWITCH |
2567 add_to_list (&destructors, name); | |
2568 #endif | |
2569 break; | |
2570 | |
2571 case SYM_DWEH: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2572 if (! (filter & SCAN_DWEH)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2573 break; |
0 | 2574 if (which_pass != PASS_LIB) |
2575 add_to_list (&frame_tables, name); | |
2576 break; | |
2577 | |
2578 default: /* not a constructor or destructor */ | |
2579 continue; | |
2580 } | |
2581 } | |
2582 | |
2583 if (debug) | |
2584 fprintf (stderr, "\n"); | |
2585 | |
2586 do_wait (nm_file_name, pex); | |
2587 | |
2588 signal (SIGINT, int_handler); | |
2589 #ifdef SIGQUIT | |
2590 signal (SIGQUIT, quit_handler); | |
2591 #endif | |
2592 } | |
2593 | |
2594 #ifdef LDD_SUFFIX | |
2595 | |
2596 /* Use the List Dynamic Dependencies program to find shared libraries that | |
2597 the output file depends upon and their initialization/finalization | |
2598 routines, if any. */ | |
2599 | |
2600 static void | |
2601 scan_libraries (const char *prog_name) | |
2602 { | |
2603 static struct head libraries; /* list of shared libraries found */ | |
2604 struct id *list; | |
2605 void (*int_handler) (int); | |
2606 #ifdef SIGQUIT | |
2607 void (*quit_handler) (int); | |
2608 #endif | |
2609 char *real_ldd_argv[4]; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2610 const char **ldd_argv = CONST_CAST2 (const char **, char **, real_ldd_argv); |
0 | 2611 int argc = 0; |
2612 struct pex_obj *pex; | |
2613 const char *errmsg; | |
2614 int err; | |
2615 char buf[1024]; | |
2616 FILE *inf; | |
2617 | |
2618 /* If we do not have an `ldd', complain. */ | |
2619 if (ldd_file_name == 0) | |
2620 { | |
145 | 2621 error ("cannot find %<ldd%>"); |
0 | 2622 return; |
2623 } | |
2624 | |
2625 ldd_argv[argc++] = ldd_file_name; | |
2626 ldd_argv[argc++] = prog_name; | |
2627 ldd_argv[argc++] = (char *) 0; | |
2628 | |
2629 /* Trace if needed. */ | |
111 | 2630 if (verbose) |
0 | 2631 { |
2632 const char **p_argv; | |
2633 const char *str; | |
2634 | |
2635 for (p_argv = &ldd_argv[0]; (str = *p_argv) != (char *) 0; p_argv++) | |
2636 fprintf (stderr, " %s", str); | |
2637 | |
2638 fprintf (stderr, "\n"); | |
2639 } | |
2640 | |
2641 fflush (stdout); | |
2642 fflush (stderr); | |
2643 | |
2644 pex = pex_init (PEX_USE_PIPES, "collect2", NULL); | |
2645 if (pex == NULL) | |
111 | 2646 fatal_error (input_location, "pex_init failed: %m"); |
0 | 2647 |
2648 errmsg = pex_run (pex, 0, ldd_file_name, real_ldd_argv, NULL, NULL, &err); | |
2649 if (errmsg != NULL) | |
2650 { | |
2651 if (err != 0) | |
2652 { | |
2653 errno = err; | |
111 | 2654 fatal_error (input_location, "%s: %m", _(errmsg)); |
0 | 2655 } |
2656 else | |
111 | 2657 fatal_error (input_location, errmsg); |
0 | 2658 } |
2659 | |
2660 int_handler = (void (*) (int)) signal (SIGINT, SIG_IGN); | |
2661 #ifdef SIGQUIT | |
2662 quit_handler = (void (*) (int)) signal (SIGQUIT, SIG_IGN); | |
2663 #endif | |
2664 | |
2665 inf = pex_read_output (pex, 0); | |
2666 if (inf == NULL) | |
145 | 2667 fatal_error (input_location, "cannot open ldd output: %m"); |
0 | 2668 |
2669 if (debug) | |
2670 notice ("\nldd output with constructors/destructors.\n"); | |
2671 | |
2672 /* Read each line of ldd output. */ | |
2673 while (fgets (buf, sizeof buf, inf) != (char *) 0) | |
2674 { | |
2675 int ch2; | |
2676 char *name, *end, *p = buf; | |
2677 | |
2678 /* Extract names of libraries and add to list. */ | |
2679 PARSE_LDD_OUTPUT (p); | |
2680 if (p == 0) | |
2681 continue; | |
2682 | |
2683 name = p; | |
2684 if (strncmp (name, "not found", sizeof ("not found") - 1) == 0) | |
111 | 2685 fatal_error (input_location, "dynamic dependency %s not found", buf); |
0 | 2686 |
2687 /* Find the end of the symbol name. */ | |
2688 for (end = p; | |
2689 (ch2 = *end) != '\0' && ch2 != '\n' && !ISSPACE (ch2) && ch2 != '|'; | |
2690 end++) | |
2691 continue; | |
2692 *end = '\0'; | |
2693 | |
2694 if (access (name, R_OK) == 0) | |
2695 add_to_list (&libraries, name); | |
2696 else | |
145 | 2697 fatal_error (input_location, "unable to open dynamic dependency " |
2698 "%qs", buf); | |
0 | 2699 |
2700 if (debug) | |
2701 fprintf (stderr, "\t%s\n", buf); | |
2702 } | |
2703 if (debug) | |
2704 fprintf (stderr, "\n"); | |
2705 | |
2706 do_wait (ldd_file_name, pex); | |
2707 | |
2708 signal (SIGINT, int_handler); | |
2709 #ifdef SIGQUIT | |
2710 signal (SIGQUIT, quit_handler); | |
2711 #endif | |
2712 | |
2713 /* Now iterate through the library list adding their symbols to | |
2714 the list. */ | |
2715 for (list = libraries.first; list; list = list->next) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2716 scan_prog_file (list->name, PASS_LIB, SCAN_ALL); |
0 | 2717 } |
2718 | |
2719 #endif /* LDD_SUFFIX */ | |
2720 | |
2721 #endif /* OBJECT_FORMAT_NONE */ | |
2722 | |
2723 | |
2724 /* | |
2725 * COFF specific stuff. | |
2726 */ | |
2727 | |
2728 #ifdef OBJECT_FORMAT_COFF | |
2729 | |
111 | 2730 # define GCC_SYMBOLS(X) (HEADER (ldptr).f_nsyms) |
0 | 2731 # define GCC_SYMENT SYMENT |
2732 # if defined (C_WEAKEXT) | |
2733 # define GCC_OK_SYMBOL(X) \ | |
2734 (((X).n_sclass == C_EXT || (X).n_sclass == C_WEAKEXT) && \ | |
2735 ((X).n_scnum > N_UNDEF) && \ | |
2736 (aix64_flag \ | |
2737 || (((X).n_type & N_TMASK) == (DT_NON << N_BTSHFT) \ | |
2738 || ((X).n_type & N_TMASK) == (DT_FCN << N_BTSHFT)))) | |
2739 # define GCC_UNDEF_SYMBOL(X) \ | |
2740 (((X).n_sclass == C_EXT || (X).n_sclass == C_WEAKEXT) && \ | |
2741 ((X).n_scnum == N_UNDEF)) | |
2742 # else | |
2743 # define GCC_OK_SYMBOL(X) \ | |
2744 (((X).n_sclass == C_EXT) && \ | |
2745 ((X).n_scnum > N_UNDEF) && \ | |
2746 (aix64_flag \ | |
2747 || (((X).n_type & N_TMASK) == (DT_NON << N_BTSHFT) \ | |
2748 || ((X).n_type & N_TMASK) == (DT_FCN << N_BTSHFT)))) | |
2749 # define GCC_UNDEF_SYMBOL(X) \ | |
2750 (((X).n_sclass == C_EXT) && ((X).n_scnum == N_UNDEF)) | |
2751 # endif | |
2752 # define GCC_SYMINC(X) ((X).n_numaux+1) | |
2753 # define GCC_SYMZERO(X) 0 | |
2754 | |
2755 /* 0757 = U803XTOCMAGIC (AIX 4.3) and 0767 = U64_TOCMAGIC (AIX V5) */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2756 #if TARGET_AIX_VERSION >= 51 |
0 | 2757 # define GCC_CHECK_HDR(X) \ |
111 | 2758 (((HEADER (X).f_magic == U802TOCMAGIC && ! aix64_flag) \ |
2759 || (HEADER (X).f_magic == 0767 && aix64_flag)) \ | |
2760 && !(HEADER (X).f_flags & F_LOADONLY)) | |
0 | 2761 #else |
2762 # define GCC_CHECK_HDR(X) \ | |
111 | 2763 (((HEADER (X).f_magic == U802TOCMAGIC && ! aix64_flag) \ |
2764 || (HEADER (X).f_magic == 0757 && aix64_flag)) \ | |
2765 && !(HEADER (X).f_flags & F_LOADONLY)) | |
0 | 2766 #endif |
2767 | |
2768 #ifdef COLLECT_EXPORT_LIST | |
2769 /* Array of standard AIX libraries which should not | |
2770 be scanned for ctors/dtors. */ | |
2771 static const char *const aix_std_libs[] = { | |
2772 "/unix", | |
2773 "/lib/libc.a", | |
2774 "/lib/libm.a", | |
2775 "/lib/libc_r.a", | |
2776 "/lib/libm_r.a", | |
2777 "/usr/lib/libc.a", | |
2778 "/usr/lib/libm.a", | |
2779 "/usr/lib/libc_r.a", | |
2780 "/usr/lib/libm_r.a", | |
2781 "/usr/lib/threads/libc.a", | |
2782 "/usr/ccs/lib/libc.a", | |
2783 "/usr/ccs/lib/libm.a", | |
2784 "/usr/ccs/lib/libc_r.a", | |
2785 "/usr/ccs/lib/libm_r.a", | |
2786 NULL | |
2787 }; | |
2788 | |
2789 /* This function checks the filename and returns 1 | |
2790 if this name matches the location of a standard AIX library. */ | |
2791 static int ignore_library (const char *); | |
2792 static int | |
2793 ignore_library (const char *name) | |
2794 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2795 const char *const *p; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2796 size_t length; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2797 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2798 if (target_system_root[0] != '\0') |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2799 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2800 length = strlen (target_system_root); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2801 if (strncmp (name, target_system_root, length) != 0) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2802 return 0; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2803 name += length; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2804 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2805 for (p = &aix_std_libs[0]; *p != NULL; ++p) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2806 if (strcmp (name, *p) == 0) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2807 return 1; |
0 | 2808 return 0; |
2809 } | |
2810 #endif /* COLLECT_EXPORT_LIST */ | |
2811 | |
2812 #if defined (HAVE_DECL_LDGETNAME) && !HAVE_DECL_LDGETNAME | |
2813 extern char *ldgetname (LDFILE *, GCC_SYMENT *); | |
2814 #endif | |
2815 | |
2816 /* COFF version to scan the name list of the loaded program for | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2817 the symbols g++ uses for static constructors and destructors. */ |
0 | 2818 |
2819 static void | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2820 scan_prog_file (const char *prog_name, scanpass which_pass, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2821 scanfilter filter) |
0 | 2822 { |
2823 LDFILE *ldptr = NULL; | |
2824 int sym_index, sym_count; | |
2825 int is_shared = 0; | |
145 | 2826 |
2827 if (which_pass != PASS_FIRST && which_pass != PASS_OBJ) | |
0 | 2828 return; |
2829 | |
2830 #ifdef COLLECT_EXPORT_LIST | |
2831 /* We do not need scanning for some standard C libraries. */ | |
2832 if (which_pass == PASS_FIRST && ignore_library (prog_name)) | |
2833 return; | |
2834 | |
2835 /* On AIX we have a loop, because there is not much difference | |
2836 between an object and an archive. This trick allows us to | |
2837 eliminate scan_libraries() function. */ | |
2838 do | |
2839 { | |
2840 #endif | |
2841 /* Some platforms (e.g. OSF4) declare ldopen as taking a | |
2842 non-const char * filename parameter, even though it will not | |
2843 modify that string. So we must cast away const-ness here, | |
2844 using CONST_CAST to prevent complaints from -Wcast-qual. */ | |
2845 if ((ldptr = ldopen (CONST_CAST (char *, prog_name), ldptr)) != NULL) | |
2846 { | |
2847 if (! MY_ISCOFF (HEADER (ldptr).f_magic)) | |
111 | 2848 fatal_error (input_location, "%s: not a COFF file", prog_name); |
0 | 2849 |
2850 if (GCC_CHECK_HDR (ldptr)) | |
2851 { | |
2852 sym_count = GCC_SYMBOLS (ldptr); | |
2853 sym_index = GCC_SYMZERO (ldptr); | |
2854 | |
2855 #ifdef COLLECT_EXPORT_LIST | |
2856 /* Is current archive member a shared object? */ | |
2857 is_shared = HEADER (ldptr).f_flags & F_SHROBJ; | |
2858 #endif | |
2859 | |
2860 while (sym_index < sym_count) | |
2861 { | |
2862 GCC_SYMENT symbol; | |
2863 | |
2864 if (ldtbread (ldptr, sym_index, &symbol) <= 0) | |
2865 break; | |
2866 sym_index += GCC_SYMINC (symbol); | |
2867 | |
2868 if (GCC_OK_SYMBOL (symbol)) | |
2869 { | |
2870 char *name; | |
2871 | |
2872 if ((name = ldgetname (ldptr, &symbol)) == NULL) | |
2873 continue; /* Should never happen. */ | |
2874 | |
2875 #ifdef XCOFF_DEBUGGING_INFO | |
2876 /* All AIX function names have a duplicate entry | |
2877 beginning with a dot. */ | |
2878 if (*name == '.') | |
2879 ++name; | |
2880 #endif | |
2881 | |
2882 switch (is_ctor_dtor (name)) | |
2883 { | |
111 | 2884 #if TARGET_AIX_VERSION |
2885 /* Add AIX shared library initalisers/finalisers | |
2886 to the constructors/destructors list of the | |
2887 current module. */ | |
2888 case SYM_AIXI: | |
2889 if (! (filter & SCAN_CTOR)) | |
2890 break; | |
131 | 2891 if (is_shared && !aixlazy_flag |
2892 #ifdef COLLECT_EXPORT_LIST | |
2893 && ! static_obj | |
2894 && ! is_in_list (prog_name, static_libs.first) | |
2895 #endif | |
2896 ) | |
111 | 2897 add_to_list (&constructors, name); |
2898 break; | |
2899 | |
2900 case SYM_AIXD: | |
2901 if (! (filter & SCAN_DTOR)) | |
2902 break; | |
2903 if (is_shared && !aixlazy_flag) | |
2904 add_to_list (&destructors, name); | |
2905 break; | |
2906 #endif | |
2907 | |
0 | 2908 case SYM_CTOR: |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2909 if (! (filter & SCAN_CTOR)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2910 break; |
0 | 2911 if (! is_shared) |
2912 add_to_list (&constructors, name); | |
2913 #if defined (COLLECT_EXPORT_LIST) && !defined (LD_INIT_SWITCH) | |
2914 if (which_pass == PASS_OBJ) | |
2915 add_to_list (&exports, name); | |
2916 #endif | |
2917 break; | |
2918 | |
2919 case SYM_DTOR: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2920 if (! (filter & SCAN_DTOR)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2921 break; |
0 | 2922 if (! is_shared) |
2923 add_to_list (&destructors, name); | |
2924 #if defined (COLLECT_EXPORT_LIST) && !defined (LD_INIT_SWITCH) | |
2925 if (which_pass == PASS_OBJ) | |
2926 add_to_list (&exports, name); | |
2927 #endif | |
2928 break; | |
2929 | |
2930 #ifdef COLLECT_EXPORT_LIST | |
2931 case SYM_INIT: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2932 if (! (filter & SCAN_INIT)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2933 break; |
0 | 2934 #ifndef LD_INIT_SWITCH |
2935 if (is_shared) | |
2936 add_to_list (&constructors, name); | |
2937 #endif | |
2938 break; | |
2939 | |
2940 case SYM_FINI: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2941 if (! (filter & SCAN_FINI)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2942 break; |
0 | 2943 #ifndef LD_INIT_SWITCH |
2944 if (is_shared) | |
2945 add_to_list (&destructors, name); | |
2946 #endif | |
2947 break; | |
2948 #endif | |
2949 | |
2950 case SYM_DWEH: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2951 if (! (filter & SCAN_DWEH)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2952 break; |
0 | 2953 if (! is_shared) |
2954 add_to_list (&frame_tables, name); | |
2955 #if defined (COLLECT_EXPORT_LIST) && !defined (LD_INIT_SWITCH) | |
2956 if (which_pass == PASS_OBJ) | |
2957 add_to_list (&exports, name); | |
2958 #endif | |
2959 break; | |
2960 | |
2961 default: /* not a constructor or destructor */ | |
2962 #ifdef COLLECT_EXPORT_LIST | |
2963 /* Explicitly export all global symbols when | |
2964 building a shared object on AIX, but do not | |
2965 re-export symbols from another shared object | |
2966 and do not export symbols if the user | |
2967 provides an explicit export list. */ | |
2968 if (shared_obj && !is_shared | |
2969 && which_pass == PASS_OBJ && !export_flag) | |
111 | 2970 { |
2971 /* Do not auto-export __dso_handle or | |
2972 __gcc_unwind_dbase. They are required | |
2973 to be local to each module. */ | |
2974 if (strcmp(name, "__dso_handle") != 0 | |
2975 && strcmp(name, "__gcc_unwind_dbase") != 0) | |
2976 { | |
2977 add_to_list (&exports, name); | |
2978 } | |
2979 } | |
0 | 2980 #endif |
2981 continue; | |
2982 } | |
2983 | |
2984 if (debug) | |
2985 fprintf (stderr, "\tsec=%d class=%d type=%s%o %s\n", | |
2986 symbol.n_scnum, symbol.n_sclass, | |
2987 (symbol.n_type ? "0" : ""), symbol.n_type, | |
2988 name); | |
2989 } | |
2990 } | |
2991 } | |
2992 #ifdef COLLECT_EXPORT_LIST | |
2993 else | |
2994 { | |
2995 /* If archive contains both 32-bit and 64-bit objects, | |
2996 we want to skip objects in other mode so mismatch normal. */ | |
2997 if (debug) | |
2998 fprintf (stderr, "%s : magic=%o aix64=%d mismatch\n", | |
2999 prog_name, HEADER (ldptr).f_magic, aix64_flag); | |
3000 } | |
3001 #endif | |
3002 } | |
3003 else | |
3004 { | |
111 | 3005 fatal_error (input_location, "%s: cannot open as COFF file", |
3006 prog_name); | |
0 | 3007 } |
3008 #ifdef COLLECT_EXPORT_LIST | |
3009 /* On AIX loop continues while there are more members in archive. */ | |
3010 } | |
3011 while (ldclose (ldptr) == FAILURE); | |
3012 #else | |
3013 /* Otherwise we simply close ldptr. */ | |
111 | 3014 (void) ldclose (ldptr); |
0 | 3015 #endif |
3016 } | |
3017 #endif /* OBJECT_FORMAT_COFF */ | |
3018 | |
3019 #ifdef COLLECT_EXPORT_LIST | |
3020 /* Given a library name without "lib" prefix, this function | |
3021 returns a full library name including a path. */ | |
3022 static char * | |
3023 resolve_lib_name (const char *name) | |
3024 { | |
3025 char *lib_buf; | |
3026 int i, j, l = 0; | |
3027 /* Library extensions for AIX dynamic linking. */ | |
3028 const char * const libexts[2] = {"a", "so"}; | |
3029 | |
3030 for (i = 0; libpaths[i]; i++) | |
3031 if (libpaths[i]->max_len > l) | |
3032 l = libpaths[i]->max_len; | |
3033 | |
111 | 3034 lib_buf = XNEWVEC (char, l + strlen (name) + 10); |
0 | 3035 |
3036 for (i = 0; libpaths[i]; i++) | |
3037 { | |
3038 struct prefix_list *list = libpaths[i]->plist; | |
3039 for (; list; list = list->next) | |
3040 { | |
3041 /* The following lines are needed because path_prefix list | |
111 | 3042 may contain directories both with trailing DIR_SEPARATOR and |
0 | 3043 without it. */ |
3044 const char *p = ""; | |
111 | 3045 if (!IS_DIR_SEPARATOR (list->prefix[strlen (list->prefix)-1])) |
0 | 3046 p = "/"; |
3047 for (j = 0; j < 2; j++) | |
3048 { | |
3049 sprintf (lib_buf, "%s%slib%s.%s", | |
3050 list->prefix, p, name, | |
3051 libexts[(j + aixrtl_flag) % 2]); | |
3052 if (debug) fprintf (stderr, "searching for: %s\n", lib_buf); | |
3053 if (file_exists (lib_buf)) | |
3054 { | |
3055 if (debug) fprintf (stderr, "found: %s\n", lib_buf); | |
3056 return (lib_buf); | |
3057 } | |
3058 } | |
3059 } | |
3060 } | |
3061 if (debug) | |
3062 fprintf (stderr, "not found\n"); | |
3063 else | |
111 | 3064 fatal_error (input_location, "library lib%s not found", name); |
0 | 3065 return (NULL); |
3066 } | |
3067 #endif /* COLLECT_EXPORT_LIST */ | |
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
|
3068 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3069 #ifdef COLLECT_RUN_DSYMUTIL |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3070 static int flag_dsym = false; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3071 static int flag_idsym = false; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3072 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3073 static void |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3074 process_args (int *argcp, char **argv) { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3075 int i, 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
|
3076 int argc = *argcp; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3077 for (i=0; i<argc; ++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
|
3078 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3079 if (strcmp (argv[i], "-dsym") == 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
|
3080 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3081 flag_dsym = true; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3082 /* Remove the flag, as we handle all processing for it. */ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3083 j = 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
|
3084 do |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3085 argv[j] = argv[j+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
|
3086 while (++j < argc); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3087 --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
|
3088 argc = --(*argcp); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3089 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3090 else if (strcmp (argv[i], "-idsym") == 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
|
3091 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3092 flag_idsym = true; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3093 /* Remove the flag, as we handle all processing for it. */ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3094 j = 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
|
3095 do |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3096 argv[j] = argv[j+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
|
3097 while (++j < argc); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3098 --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
|
3099 argc = --(*argcp); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3100 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3101 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3102 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3103 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3104 static void |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3105 do_dsymutil (const char *output_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
|
3106 const char *dsymutil = DSYMUTIL + 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
|
3107 struct pex_obj *pex; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3108 char **real_argv = XCNEWVEC (char *, 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
|
3109 const char ** argv = CONST_CAST2 (const char **, 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
|
3110 real_argv); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3111 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3112 argv[0] = dsymutil; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3113 argv[1] = output_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
|
3114 argv[2] = (char *) 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
|
3115 |
111 | 3116 pex = collect_execute (dsymutil, real_argv, NULL, NULL, |
3117 PEX_LAST | PEX_SEARCH, false); | |
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
|
3118 do_wait (dsymutil, pex); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3119 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3120 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3121 static void |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3122 post_ld_pass (bool temp_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
|
3123 if (!(temp_file && flag_idsym) && !flag_dsym) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3124 return; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3125 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3126 do_dsymutil (output_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
|
3127 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3128 #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
|
3129 static void |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3130 process_args (int *argcp ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) { } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3131 static void post_ld_pass (bool temp_file ATTRIBUTE_UNUSED) { } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
3132 #endif |