Commit | Line | Data |
---|---|---|
e9f53129 | 1 | # This shell script emits a C file. -*- C -*- |
cd4a7468 | 2 | # Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc. |
e9f53129 | 3 | # |
f96b4a7b | 4 | # This file is part of the GNU Binutils. |
e9f53129 AM |
5 | # |
6 | # This program is free software; you can redistribute it and/or modify | |
7 | # it under the terms of the GNU General Public License as published by | |
f96b4a7b | 8 | # the Free Software Foundation; either version 3 of the License, or |
e9f53129 AM |
9 | # (at your option) any later version. |
10 | # | |
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. | |
15 | # | |
f96b4a7b NC |
16 | # You should have received a copy of the GNU General Public License |
17 | # along with this program; if not, write to the Free Software | |
18 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
19 | # MA 02110-1301, USA. | |
e9f53129 AM |
20 | # |
21 | ||
22 | # This file is sourced from elf32.em, and defines extra spu specific | |
23 | # features. | |
24 | # | |
92b93329 | 25 | fragment <<EOF |
e9f53129 AM |
26 | #include "ldctor.h" |
27 | #include "elf32-spu.h" | |
28 | ||
64615358 AM |
29 | static void spu_place_special_section (asection *, asection *, const char *); |
30 | static bfd_size_type spu_elf_load_ovl_mgr (void); | |
31 | static FILE *spu_elf_open_overlay_script (void); | |
32 | static void spu_elf_relink (void); | |
e9f53129 | 33 | |
64615358 AM |
34 | static struct spu_elf_params params = |
35 | { | |
36 | &spu_place_special_section, | |
37 | &spu_elf_load_ovl_mgr, | |
38 | &spu_elf_open_overlay_script, | |
39 | &spu_elf_relink, | |
fb266b8b | 40 | 0, ovly_normal, 0, 0, 0, 0, 0, 0, |
64615358 | 41 | 0, 0x3ffff, |
cd4a7468 | 42 | 1, 0, 16, 0, 0, 2000 |
64615358 AM |
43 | }; |
44 | ||
cd4a7468 AM |
45 | static unsigned int num_lines_set = 0; |
46 | static unsigned int line_size_set = 0; | |
9dcc4794 | 47 | static char *auto_overlay_file = 0; |
9dcc4794 AM |
48 | int my_argc; |
49 | char **my_argv; | |
50 | ||
671ace2f AM |
51 | static const char ovl_mgr[] = { |
52 | EOF | |
53 | ||
4b64c41f | 54 | if ! cat ${srcdir}/emultempl/spu_ovl.o_c >> e${EMULATION_NAME}.c |
2f9300ef | 55 | then |
4b64c41f | 56 | echo >&2 "Missing ${srcdir}/emultempl/spu_ovl.o_c" |
cd4a7468 AM |
57 | echo >&2 "You must build gas/as-new with --target=spu" |
58 | exit 1 | |
59 | fi | |
60 | ||
61 | fragment <<EOF | |
62 | }; | |
63 | ||
64 | static const char icache_mgr[] = { | |
65 | EOF | |
66 | ||
67 | if ! cat ${srcdir}/emultempl/spu_icache.o_c >> e${EMULATION_NAME}.c | |
68 | then | |
69 | echo >&2 "Missing ${srcdir}/emultempl/spu_icache.o_c" | |
70 | echo >&2 "You must build gas/as-new with --target=spu" | |
2f9300ef JK |
71 | exit 1 |
72 | fi | |
671ace2f | 73 | |
92b93329 | 74 | fragment <<EOF |
671ace2f | 75 | }; |
e9f53129 AM |
76 | |
77 | static const struct _ovl_stream ovl_mgr_stream = { | |
671ace2f AM |
78 | ovl_mgr, |
79 | ovl_mgr + sizeof (ovl_mgr) | |
e9f53129 AM |
80 | }; |
81 | ||
cd4a7468 AM |
82 | static const struct _ovl_stream icache_mgr_stream = { |
83 | icache_mgr, | |
84 | icache_mgr + sizeof (icache_mgr) | |
85 | }; | |
86 | ||
e9f53129 AM |
87 | |
88 | static int | |
89 | is_spu_target (void) | |
90 | { | |
91 | extern const bfd_target bfd_elf32_spu_vec; | |
92 | ||
f13a99db | 93 | return link_info.output_bfd->xvec == &bfd_elf32_spu_vec; |
e9f53129 AM |
94 | } |
95 | ||
96 | /* Create our note section. */ | |
97 | ||
98 | static void | |
99 | spu_after_open (void) | |
100 | { | |
64615358 AM |
101 | if (is_spu_target ()) |
102 | { | |
103 | /* Pass params to backend. */ | |
104 | if ((params.auto_overlay & AUTO_OVERLAY) == 0) | |
105 | params.auto_overlay = 0; | |
106 | params.emit_stub_syms |= link_info.emitrelocations; | |
107 | spu_elf_setup (&link_info, ¶ms); | |
108 | ||
df636c05 AM |
109 | if (link_info.relocatable) |
110 | lang_add_unique (".text.ia.*"); | |
111 | ||
64615358 AM |
112 | if (!link_info.relocatable |
113 | && link_info.input_bfds != NULL | |
114 | && !spu_elf_create_sections (&link_info)) | |
115 | einfo ("%X%P: can not create note section: %E\n"); | |
116 | } | |
e9f53129 AM |
117 | |
118 | gld${EMULATION_NAME}_after_open (); | |
119 | } | |
120 | ||
47f6dab9 | 121 | /* If O is NULL, add section S at the end of output section OUTPUT_NAME. |
cd4a7468 AM |
122 | If O is not NULL, add section S at the beginning of output section O, |
123 | except for soft-icache which adds to the end. | |
e9f53129 AM |
124 | |
125 | Really, we should be duplicating ldlang.c map_input_to_output_sections | |
126 | logic here, ie. using the linker script to find where the section | |
127 | goes. That's rather a lot of code, and we don't want to run | |
128 | map_input_to_output_sections again because most sections are already | |
129 | mapped. So cheat, and put the section in a fixed place, ignoring any | |
130 | attempt via a linker script to put .stub, .ovtab, and built-in | |
131 | overlay manager code somewhere else. */ | |
132 | ||
133 | static void | |
47f6dab9 | 134 | spu_place_special_section (asection *s, asection *o, const char *output_name) |
e9f53129 AM |
135 | { |
136 | lang_output_section_statement_type *os; | |
137 | ||
64615358 AM |
138 | if (o != NULL) |
139 | output_name = o->name; | |
140 | os = lang_output_section_find (output_name); | |
e9f53129 | 141 | if (os == NULL) |
cd4a7468 AM |
142 | { |
143 | os = gld${EMULATION_NAME}_place_orphan (s, output_name, 0); | |
144 | os->addr_tree = NULL; | |
145 | } | |
146 | else if (params.ovly_flavour != ovly_soft_icache | |
147 | && o != NULL && os->children.head != NULL) | |
47f6dab9 AM |
148 | { |
149 | lang_statement_list_type add; | |
150 | ||
151 | lang_list_init (&add); | |
152 | lang_add_section (&add, s, os); | |
153 | *add.tail = os->children.head; | |
154 | os->children.head = add.head; | |
155 | } | |
e9f53129 | 156 | else |
cd4a7468 AM |
157 | { |
158 | if (params.ovly_flavour == ovly_soft_icache && o != NULL) | |
159 | { | |
160 | /* Pad this stub section so that it finishes at the | |
161 | end of the icache line. */ | |
162 | etree_type *e_size; | |
163 | lang_statement_list_type *save = stat_ptr; | |
164 | ||
165 | stat_ptr = &os->children; | |
166 | e_size = exp_intop (params.line_size - s->size); | |
167 | lang_add_assignment (exp_assop ('=', ".", e_size)); | |
168 | stat_ptr = save; | |
169 | } | |
170 | lang_add_section (&os->children, s, os); | |
171 | } | |
e9f53129 AM |
172 | |
173 | s->output_section->size += s->size; | |
174 | } | |
175 | ||
64615358 | 176 | /* Load built-in overlay manager. */ |
e9f53129 | 177 | |
64615358 | 178 | static bfd_size_type |
e9f53129 AM |
179 | spu_elf_load_ovl_mgr (void) |
180 | { | |
e9f53129 | 181 | struct elf_link_hash_entry *h; |
cd4a7468 AM |
182 | const char *ovly_mgr_entry; |
183 | const struct _ovl_stream *mgr_stream; | |
64615358 | 184 | bfd_size_type total = 0; |
e9f53129 | 185 | |
cd4a7468 AM |
186 | ovly_mgr_entry = "__ovly_load"; |
187 | mgr_stream = &ovl_mgr_stream; | |
188 | if (params.ovly_flavour == ovly_soft_icache) | |
189 | { | |
190 | ovly_mgr_entry = "__icache_br_handler"; | |
191 | mgr_stream = &icache_mgr_stream; | |
192 | } | |
e9f53129 | 193 | h = elf_link_hash_lookup (elf_hash_table (&link_info), |
cd4a7468 | 194 | ovly_mgr_entry, FALSE, FALSE, FALSE); |
e9f53129 AM |
195 | |
196 | if (h != NULL | |
197 | && (h->root.type == bfd_link_hash_defined | |
198 | || h->root.type == bfd_link_hash_defweak) | |
199 | && h->def_regular) | |
200 | { | |
201 | /* User supplied __ovly_load. */ | |
202 | } | |
cd4a7468 | 203 | else if (mgr_stream->start == mgr_stream->end) |
45d3b878 | 204 | einfo ("%F%P: no built-in overlay manager\n"); |
e9f53129 AM |
205 | else |
206 | { | |
207 | lang_input_statement_type *ovl_is; | |
208 | ||
209 | ovl_is = lang_add_input_file ("builtin ovl_mgr", | |
210 | lang_input_file_is_file_enum, | |
211 | NULL); | |
212 | ||
cd4a7468 | 213 | if (!spu_elf_open_builtin_lib (&ovl_is->the_bfd, mgr_stream)) |
e9f53129 AM |
214 | einfo ("%X%P: can not open built-in overlay manager: %E\n"); |
215 | else | |
216 | { | |
217 | asection *in; | |
218 | ||
219 | if (!load_symbols (ovl_is, NULL)) | |
220 | einfo ("%X%P: can not load built-in overlay manager: %E\n"); | |
221 | ||
cd4a7468 AM |
222 | /* Map overlay manager sections to output sections. |
223 | First try for a matching output section name, if that | |
224 | fails then try mapping .abc.xyz to .abc, otherwise map | |
225 | to .text. */ | |
e9f53129 AM |
226 | for (in = ovl_is->the_bfd->sections; in != NULL; in = in->next) |
227 | if ((in->flags & (SEC_ALLOC | SEC_LOAD)) | |
228 | == (SEC_ALLOC | SEC_LOAD)) | |
64615358 | 229 | { |
cd4a7468 AM |
230 | const char *oname = in->name; |
231 | if (strncmp (in->name, ".ovl.init", 9) != 0) | |
232 | { | |
233 | total += in->size; | |
234 | if (!lang_output_section_find (oname)) | |
235 | { | |
236 | lang_output_section_statement_type *os = NULL; | |
237 | char *p = strchr (oname + 1, '.'); | |
238 | if (p != NULL) | |
239 | { | |
240 | size_t len = p - oname; | |
241 | p = memcpy (xmalloc (len + 1), oname, len); | |
242 | p[len] = '\0'; | |
243 | os = lang_output_section_find (p); | |
244 | free (p); | |
245 | } | |
246 | if (os != NULL) | |
247 | oname = os->name; | |
248 | else | |
249 | oname = ".text"; | |
250 | } | |
251 | } | |
252 | ||
253 | spu_place_special_section (in, NULL, oname); | |
64615358 | 254 | } |
e9f53129 AM |
255 | } |
256 | } | |
64615358 | 257 | return total; |
e9f53129 AM |
258 | } |
259 | ||
260 | /* Go find if we need to do anything special for overlays. */ | |
261 | ||
262 | static void | |
263 | spu_before_allocation (void) | |
264 | { | |
265 | if (is_spu_target () | |
266 | && !link_info.relocatable | |
64615358 | 267 | && params.ovly_flavour != ovly_none) |
e9f53129 AM |
268 | { |
269 | /* Size the sections. This is premature, but we need to know the | |
270 | rough layout so that overlays can be found. */ | |
271 | expld.phase = lang_mark_phase_enum; | |
272 | expld.dataseg.phase = exp_dataseg_none; | |
273 | one_lang_size_sections_pass (NULL, TRUE); | |
274 | ||
275 | /* Find overlays by inspecting section vmas. */ | |
c65be8d7 | 276 | if (spu_elf_find_overlays (&link_info)) |
e9f53129 | 277 | { |
47f6dab9 | 278 | int ret; |
64615358 | 279 | lang_output_section_statement_type *os; |
e9f53129 | 280 | |
64615358 | 281 | if (params.auto_overlay != 0) |
9dcc4794 AM |
282 | { |
283 | einfo ("%P: --auto-overlay ignored with user overlay script\n"); | |
64615358 | 284 | params.auto_overlay = 0; |
9dcc4794 AM |
285 | } |
286 | ||
64615358 AM |
287 | /* Ensure alignment of overlay sections is sufficient. */ |
288 | for (os = &lang_output_section_statement.head->output_section_statement; | |
289 | os != NULL; | |
290 | os = os->next) | |
291 | if (os->bfd_section != NULL | |
292 | && spu_elf_section_data (os->bfd_section) != NULL | |
293 | && spu_elf_section_data (os->bfd_section)->u.o.ovl_index != 0) | |
294 | { | |
295 | if (os->bfd_section->alignment_power < 4) | |
296 | os->bfd_section->alignment_power = 4; | |
297 | ||
298 | /* Also ensure size rounds up. */ | |
299 | os->block_value = 16; | |
300 | } | |
301 | ||
302 | ret = spu_elf_size_stubs (&link_info); | |
47f6dab9 | 303 | if (ret == 0) |
e9f53129 | 304 | einfo ("%X%P: can not size overlay stubs: %E\n"); |
47f6dab9 AM |
305 | else if (ret == 2) |
306 | spu_elf_load_ovl_mgr (); | |
e9f53129 AM |
307 | } |
308 | ||
309 | /* We must not cache anything from the preliminary sizing. */ | |
310 | lang_reset_memory_regions (); | |
311 | } | |
312 | ||
313 | gld${EMULATION_NAME}_before_allocation (); | |
314 | } | |
315 | ||
9dcc4794 AM |
316 | struct tflist { |
317 | struct tflist *next; | |
318 | char name[9]; | |
319 | }; | |
320 | ||
321 | static struct tflist *tmp_file_list; | |
322 | ||
323 | static void clean_tmp (void) | |
324 | { | |
325 | for (; tmp_file_list != NULL; tmp_file_list = tmp_file_list->next) | |
326 | unlink (tmp_file_list->name); | |
327 | } | |
328 | ||
329 | static int | |
330 | new_tmp_file (char **fname) | |
331 | { | |
332 | struct tflist *tf; | |
333 | int fd; | |
334 | ||
335 | if (tmp_file_list == NULL) | |
336 | atexit (clean_tmp); | |
337 | tf = xmalloc (sizeof (*tf)); | |
338 | tf->next = tmp_file_list; | |
339 | tmp_file_list = tf; | |
340 | memcpy (tf->name, "ldXXXXXX", sizeof (tf->name)); | |
341 | *fname = tf->name; | |
342 | #ifdef HAVE_MKSTEMP | |
343 | fd = mkstemp (*fname); | |
344 | #else | |
345 | *fname = mktemp (*fname); | |
346 | if (*fname == NULL) | |
347 | return -1; | |
348 | fd = open (fname, O_RDWR | O_CREAT | O_EXCL, 0600); | |
349 | #endif | |
350 | return fd; | |
351 | } | |
352 | ||
353 | static FILE * | |
354 | spu_elf_open_overlay_script (void) | |
355 | { | |
356 | FILE *script = NULL; | |
357 | ||
358 | if (auto_overlay_file == NULL) | |
359 | { | |
360 | int fd = new_tmp_file (&auto_overlay_file); | |
361 | if (fd == -1) | |
362 | goto file_err; | |
363 | script = fdopen (fd, "w"); | |
364 | } | |
365 | else | |
366 | script = fopen (auto_overlay_file, "w"); | |
367 | ||
368 | if (script == NULL) | |
369 | { | |
370 | file_err: | |
371 | einfo ("%F%P: can not open script: %E\n"); | |
372 | } | |
373 | return script; | |
374 | } | |
375 | ||
376 | static void | |
377 | spu_elf_relink (void) | |
378 | { | |
d77ec871 | 379 | char **argv = xmalloc ((my_argc + 4) * sizeof (*argv)); |
9dcc4794 AM |
380 | |
381 | memcpy (argv, my_argv, my_argc * sizeof (*argv)); | |
382 | argv[my_argc++] = "--no-auto-overlay"; | |
383 | if (tmp_file_list->name == auto_overlay_file) | |
d77ec871 AM |
384 | argv[my_argc - 1] = concat (argv[my_argc - 1], "=", |
385 | auto_overlay_file, (const char *) NULL); | |
9dcc4794 AM |
386 | argv[my_argc++] = "-T"; |
387 | argv[my_argc++] = auto_overlay_file; | |
388 | argv[my_argc] = 0; | |
389 | execvp (argv[0], (char *const *) argv); | |
390 | perror (argv[0]); | |
391 | _exit (127); | |
392 | } | |
393 | ||
e9f53129 AM |
394 | /* Final emulation specific call. */ |
395 | ||
396 | static void | |
397 | gld${EMULATION_NAME}_finish (void) | |
398 | { | |
399 | int need_laying_out; | |
400 | ||
f13a99db | 401 | need_laying_out = bfd_elf_discard_info (link_info.output_bfd, &link_info); |
e9f53129 AM |
402 | |
403 | gld${EMULATION_NAME}_map_segments (need_laying_out); | |
404 | ||
771a9c5f | 405 | if (is_spu_target ()) |
e9f53129 | 406 | { |
64615358 | 407 | if (params.local_store_lo < params.local_store_hi) |
771a9c5f AM |
408 | { |
409 | asection *s; | |
410 | ||
64615358 AM |
411 | s = spu_elf_check_vma (&link_info); |
412 | if (s != NULL && !params.auto_overlay) | |
771a9c5f AM |
413 | einfo ("%X%P: %A exceeds local store range\n", s); |
414 | } | |
64615358 | 415 | else if (params.auto_overlay) |
9dcc4794 | 416 | einfo ("%P: --auto-overlay ignored with zero local store range\n"); |
e9f53129 AM |
417 | } |
418 | ||
e9f53129 AM |
419 | finish_default (); |
420 | } | |
421 | ||
9dcc4794 AM |
422 | static char * |
423 | gld${EMULATION_NAME}_choose_target (int argc, char *argv[]) | |
424 | { | |
425 | my_argc = argc; | |
426 | my_argv = argv; | |
427 | return ldemul_default_target (argc, argv); | |
428 | } | |
429 | ||
e9f53129 AM |
430 | EOF |
431 | ||
dc27aea4 | 432 | if grep -q 'ld_elf.*ppc.*_emulation' ldemul-list.h; then |
92b93329 | 433 | fragment <<EOF |
dc27aea4 AM |
434 | #include "filenames.h" |
435 | #include <fcntl.h> | |
436 | #include <sys/wait.h> | |
437 | ||
3ba20bde AM |
438 | static const char * |
439 | base_name (const char *path) | |
440 | { | |
441 | const char *file = strrchr (path, '/'); | |
442 | #ifdef HAVE_DOS_BASED_FILE_SYSTEM | |
443 | { | |
0fd1c9f1 | 444 | char *bslash = strrchr (path, '\\\\'); |
3ba20bde AM |
445 | |
446 | if (file == NULL || (bslash != NULL && bslash > file)) | |
447 | file = bslash; | |
448 | if (file == NULL | |
449 | && path[0] != '\0' | |
450 | && path[1] == ':') | |
451 | file = path + 1; | |
452 | } | |
453 | #endif | |
454 | if (file == NULL) | |
455 | file = path; | |
456 | else | |
457 | ++file; | |
458 | return file; | |
459 | } | |
460 | ||
dc27aea4 AM |
461 | /* This function is called when building a ppc32 or ppc64 executable |
462 | to handle embedded spu images. */ | |
463 | extern bfd_boolean embedded_spu_file (lang_input_statement_type *, const char *); | |
464 | ||
465 | bfd_boolean | |
466 | embedded_spu_file (lang_input_statement_type *entry, const char *flags) | |
467 | { | |
468 | const char *cmd[6]; | |
469 | const char *sym; | |
470 | char *handle, *p; | |
dc27aea4 AM |
471 | char *oname; |
472 | int fd; | |
473 | pid_t pid; | |
474 | int status; | |
475 | union lang_statement_union **old_stat_tail; | |
476 | union lang_statement_union **old_file_tail; | |
477 | union lang_statement_union *new_ent; | |
3ba20bde | 478 | lang_input_statement_type *search; |
dc27aea4 AM |
479 | |
480 | if (entry->the_bfd->format != bfd_object | |
481 | || strcmp (entry->the_bfd->xvec->name, "elf32-spu") != 0 | |
482 | || (entry->the_bfd->tdata.elf_obj_data->elf_header->e_type != ET_EXEC | |
483 | && entry->the_bfd->tdata.elf_obj_data->elf_header->e_type != ET_DYN)) | |
484 | return FALSE; | |
485 | ||
486 | /* Use the filename as the symbol marking the program handle struct. */ | |
3ba20bde | 487 | sym = base_name (entry->the_bfd->filename); |
dc27aea4 AM |
488 | |
489 | handle = xstrdup (sym); | |
490 | for (p = handle; *p; ++p) | |
491 | if (!(ISALNUM (*p) || *p == '$' || *p == '.')) | |
492 | *p = '_'; | |
493 | ||
9dcc4794 | 494 | fd = new_tmp_file (&oname); |
dc27aea4 AM |
495 | if (fd == -1) |
496 | return FALSE; | |
497 | close (fd); | |
498 | ||
3ba20bde AM |
499 | for (search = (lang_input_statement_type *) input_file_chain.head; |
500 | search != NULL; | |
501 | search = (lang_input_statement_type *) search->next_real_file) | |
80c4ed32 AM |
502 | if (search->filename != NULL) |
503 | { | |
504 | const char *infile = base_name (search->filename); | |
505 | ||
506 | if (strncmp (infile, "crtbegin", 8) == 0) | |
507 | { | |
508 | if (infile[8] == 'S') | |
ff7a0acf | 509 | flags = concat (flags, " -fPIC", (const char *) NULL); |
80c4ed32 | 510 | else if (infile[8] == 'T') |
ff7a0acf | 511 | flags = concat (flags, " -fpie", (const char *) NULL); |
80c4ed32 AM |
512 | break; |
513 | } | |
514 | } | |
3ba20bde | 515 | |
dc27aea4 AM |
516 | /* Use fork() and exec() rather than system() so that we don't |
517 | need to worry about quoting args. */ | |
42ba7415 | 518 | cmd[0] = EMBEDSPU; |
dc27aea4 AM |
519 | cmd[1] = flags; |
520 | cmd[2] = handle; | |
521 | cmd[3] = entry->the_bfd->filename; | |
522 | cmd[4] = oname; | |
523 | cmd[5] = NULL; | |
524 | if (trace_file_tries) | |
525 | { | |
526 | info_msg (_("running: %s \"%s\" \"%s\" \"%s\" \"%s\"\n"), | |
527 | cmd[0], cmd[1], cmd[2], cmd[3], cmd[4]); | |
528 | fflush (stdout); | |
529 | } | |
530 | ||
531 | pid = fork (); | |
532 | if (pid == -1) | |
533 | return FALSE; | |
534 | if (pid == 0) | |
535 | { | |
536 | execvp (cmd[0], (char *const *) cmd); | |
42ba7415 | 537 | if (strcmp ("embedspu", EMBEDSPU) != 0) |
628e8859 AM |
538 | { |
539 | cmd[0] = "embedspu"; | |
540 | execvp (cmd[0], (char *const *) cmd); | |
541 | } | |
dc27aea4 AM |
542 | perror (cmd[0]); |
543 | _exit (127); | |
544 | } | |
545 | #ifdef HAVE_WAITPID | |
546 | #define WAITFOR(PID, STAT) waitpid (PID, STAT, 0) | |
547 | #else | |
548 | #define WAITFOR(PID, STAT) wait (STAT) | |
549 | #endif | |
550 | if (WAITFOR (pid, &status) != pid | |
551 | || !WIFEXITED (status) | |
552 | || WEXITSTATUS (status) != 0) | |
553 | return FALSE; | |
554 | #undef WAITFOR | |
555 | ||
556 | old_stat_tail = stat_ptr->tail; | |
557 | old_file_tail = input_file_chain.tail; | |
558 | if (lang_add_input_file (oname, lang_input_file_is_file_enum, NULL) == NULL) | |
559 | return FALSE; | |
560 | ||
561 | /* lang_add_input_file put the new list entry at the end of the statement | |
562 | and input file lists. Move it to just after the current entry. */ | |
563 | new_ent = *old_stat_tail; | |
564 | *old_stat_tail = NULL; | |
565 | stat_ptr->tail = old_stat_tail; | |
566 | *old_file_tail = NULL; | |
567 | input_file_chain.tail = old_file_tail; | |
568 | new_ent->header.next = entry->header.next; | |
569 | entry->header.next = new_ent; | |
570 | new_ent->input_statement.next_real_file = entry->next_real_file; | |
571 | entry->next_real_file = new_ent; | |
572 | ||
573 | /* Ensure bfd sections are excluded from the output. */ | |
574 | bfd_section_list_clear (entry->the_bfd); | |
575 | entry->loaded = TRUE; | |
576 | return TRUE; | |
577 | } | |
578 | ||
579 | EOF | |
580 | fi | |
581 | ||
e9f53129 AM |
582 | # Define some shell vars to insert bits of code into the standard elf |
583 | # parse_args and list_options functions. | |
584 | # | |
585 | PARSE_AND_LIST_PROLOGUE=' | |
586 | #define OPTION_SPU_PLUGIN 301 | |
587 | #define OPTION_SPU_NO_OVERLAYS (OPTION_SPU_PLUGIN + 1) | |
588 | #define OPTION_SPU_STUB_SYMS (OPTION_SPU_NO_OVERLAYS + 1) | |
589 | #define OPTION_SPU_NON_OVERLAY_STUBS (OPTION_SPU_STUB_SYMS + 1) | |
590 | #define OPTION_SPU_LOCAL_STORE (OPTION_SPU_NON_OVERLAY_STUBS + 1) | |
49fa1e15 AM |
591 | #define OPTION_SPU_STACK_ANALYSIS (OPTION_SPU_LOCAL_STORE + 1) |
592 | #define OPTION_SPU_STACK_SYMS (OPTION_SPU_STACK_ANALYSIS + 1) | |
9dcc4794 AM |
593 | #define OPTION_SPU_AUTO_OVERLAY (OPTION_SPU_STACK_SYMS + 1) |
594 | #define OPTION_SPU_AUTO_RELINK (OPTION_SPU_AUTO_OVERLAY + 1) | |
595 | #define OPTION_SPU_OVERLAY_RODATA (OPTION_SPU_AUTO_RELINK + 1) | |
cd4a7468 AM |
596 | #define OPTION_SPU_SOFT_ICACHE (OPTION_SPU_OVERLAY_RODATA + 1) |
597 | #define OPTION_SPU_LINE_SIZE (OPTION_SPU_SOFT_ICACHE + 1) | |
598 | #define OPTION_SPU_NUM_LINES (OPTION_SPU_LINE_SIZE + 1) | |
599 | #define OPTION_SPU_LRLIVE (OPTION_SPU_NUM_LINES + 1) | |
fb266b8b AM |
600 | #define OPTION_SPU_NON_IA_TEXT (OPTION_SPU_LRLIVE + 1) |
601 | #define OPTION_SPU_FIXED_SPACE (OPTION_SPU_NON_IA_TEXT + 1) | |
9dcc4794 | 602 | #define OPTION_SPU_RESERVED_SPACE (OPTION_SPU_FIXED_SPACE + 1) |
99302af9 AM |
603 | #define OPTION_SPU_EXTRA_STACK (OPTION_SPU_RESERVED_SPACE + 1) |
604 | #define OPTION_SPU_NO_AUTO_OVERLAY (OPTION_SPU_EXTRA_STACK + 1) | |
e9f53129 AM |
605 | ' |
606 | ||
607 | PARSE_AND_LIST_LONGOPTS=' | |
608 | { "plugin", no_argument, NULL, OPTION_SPU_PLUGIN }, | |
cd4a7468 AM |
609 | { "soft-icache", no_argument, NULL, OPTION_SPU_SOFT_ICACHE }, |
610 | { "lrlive-analysis", no_argument, NULL, OPTION_SPU_LRLIVE }, | |
611 | { "num-lines", required_argument, NULL, OPTION_SPU_NUM_LINES }, | |
612 | { "line-size", required_argument, NULL, OPTION_SPU_LINE_SIZE }, | |
fb266b8b | 613 | { "non-ia-text", no_argument, NULL, OPTION_SPU_NON_IA_TEXT }, |
e9f53129 AM |
614 | { "no-overlays", no_argument, NULL, OPTION_SPU_NO_OVERLAYS }, |
615 | { "emit-stub-syms", no_argument, NULL, OPTION_SPU_STUB_SYMS }, | |
616 | { "extra-overlay-stubs", no_argument, NULL, OPTION_SPU_NON_OVERLAY_STUBS }, | |
617 | { "local-store", required_argument, NULL, OPTION_SPU_LOCAL_STORE }, | |
49fa1e15 AM |
618 | { "stack-analysis", no_argument, NULL, OPTION_SPU_STACK_ANALYSIS }, |
619 | { "emit-stack-syms", no_argument, NULL, OPTION_SPU_STACK_SYMS }, | |
9dcc4794 AM |
620 | { "auto-overlay", optional_argument, NULL, OPTION_SPU_AUTO_OVERLAY }, |
621 | { "auto-relink", no_argument, NULL, OPTION_SPU_AUTO_RELINK }, | |
622 | { "overlay-rodata", no_argument, NULL, OPTION_SPU_OVERLAY_RODATA }, | |
cd4a7468 AM |
623 | { "num-regions", required_argument, NULL, OPTION_SPU_NUM_LINES }, |
624 | { "region-size", required_argument, NULL, OPTION_SPU_LINE_SIZE }, | |
9dcc4794 AM |
625 | { "fixed-space", required_argument, NULL, OPTION_SPU_FIXED_SPACE }, |
626 | { "reserved-space", required_argument, NULL, OPTION_SPU_RESERVED_SPACE }, | |
99302af9 | 627 | { "extra-stack-space", required_argument, NULL, OPTION_SPU_EXTRA_STACK }, |
9dcc4794 | 628 | { "no-auto-overlay", optional_argument, NULL, OPTION_SPU_NO_AUTO_OVERLAY }, |
e9f53129 AM |
629 | ' |
630 | ||
631 | PARSE_AND_LIST_OPTIONS=' | |
632 | fprintf (file, _("\ | |
442996ee AM |
633 | --plugin Make SPU plugin.\n\ |
634 | --no-overlays No overlay handling.\n\ | |
635 | --emit-stub-syms Add symbols on overlay call stubs.\n\ | |
636 | --extra-overlay-stubs Add stubs on all calls out of overlay regions.\n\ | |
637 | --local-store=lo:hi Valid address range.\n\ | |
638 | --stack-analysis Estimate maximum stack requirement.\n\ | |
9dcc4794 AM |
639 | --emit-stack-syms Add sym giving stack needed for each func.\n\ |
640 | --auto-overlay [=filename] Create an overlay script in filename if\n\ | |
641 | executable does not fit in local store.\n\ | |
642 | --auto-relink Rerun linker using auto-overlay script.\n\ | |
643 | --overlay-rodata Place read-only data with associated function\n\ | |
644 | code in overlays.\n\ | |
a3a219a9 | 645 | --num-regions Number of overlay buffers (default 1).\n\ |
cd4a7468 | 646 | --region-size Size of overlay buffers (default 0, auto).\n\ |
9dcc4794 | 647 | --fixed-space=bytes Local store for non-overlay code and data.\n\ |
99302af9 AM |
648 | --reserved-space=bytes Local store for stack and heap. If not specified\n\ |
649 | ld will estimate stack size and assume no heap.\n\ | |
650 | --extra-stack-space=bytes Space for negative sp access (default 2000) if\n\ | |
cd4a7468 AM |
651 | --reserved-space not given.\n\ |
652 | --soft-icache Generate software icache overlays.\n\ | |
653 | --num-lines Number of soft-icache lines (default 32).\n\ | |
654 | --line-size Size of soft-icache lines (default 1k).\n\ | |
fb266b8b | 655 | --non-ia-text Allow non-icache code in icache lines.\n\ |
cd4a7468 | 656 | --lrlive-analysis Scan function prologue for lr liveness.\n" |
e9f53129 AM |
657 | )); |
658 | ' | |
659 | ||
660 | PARSE_AND_LIST_ARGS_CASES=' | |
661 | case OPTION_SPU_PLUGIN: | |
662 | spu_elf_plugin (1); | |
663 | break; | |
664 | ||
665 | case OPTION_SPU_NO_OVERLAYS: | |
64615358 | 666 | params.ovly_flavour = ovly_none; |
e9f53129 AM |
667 | break; |
668 | ||
669 | case OPTION_SPU_STUB_SYMS: | |
64615358 | 670 | params.emit_stub_syms = 1; |
e9f53129 AM |
671 | break; |
672 | ||
673 | case OPTION_SPU_NON_OVERLAY_STUBS: | |
64615358 | 674 | params.non_overlay_stubs = 1; |
e9f53129 AM |
675 | break; |
676 | ||
677 | case OPTION_SPU_LOCAL_STORE: | |
678 | { | |
679 | char *end; | |
64615358 | 680 | params.local_store_lo = strtoul (optarg, &end, 0); |
e9f53129 AM |
681 | if (*end == '\'':'\'') |
682 | { | |
64615358 | 683 | params.local_store_hi = strtoul (end + 1, &end, 0); |
e9f53129 AM |
684 | if (*end == 0) |
685 | break; | |
686 | } | |
687 | einfo (_("%P%F: invalid --local-store address range `%s'\''\n"), optarg); | |
688 | } | |
689 | break; | |
49fa1e15 AM |
690 | |
691 | case OPTION_SPU_STACK_ANALYSIS: | |
64615358 | 692 | params.stack_analysis = 1; |
49fa1e15 AM |
693 | break; |
694 | ||
695 | case OPTION_SPU_STACK_SYMS: | |
64615358 | 696 | params.emit_stack_syms = 1; |
49fa1e15 | 697 | break; |
9dcc4794 AM |
698 | |
699 | case OPTION_SPU_AUTO_OVERLAY: | |
64615358 | 700 | params.auto_overlay |= 1; |
9dcc4794 AM |
701 | if (optarg != NULL) |
702 | { | |
703 | auto_overlay_file = optarg; | |
704 | break; | |
705 | } | |
706 | /* Fall thru */ | |
707 | ||
708 | case OPTION_SPU_AUTO_RELINK: | |
64615358 | 709 | params.auto_overlay |= 2; |
9dcc4794 AM |
710 | break; |
711 | ||
712 | case OPTION_SPU_OVERLAY_RODATA: | |
64615358 | 713 | params.auto_overlay |= 4; |
9dcc4794 AM |
714 | break; |
715 | ||
cd4a7468 AM |
716 | case OPTION_SPU_SOFT_ICACHE: |
717 | params.ovly_flavour = ovly_soft_icache; | |
718 | if (!num_lines_set) | |
719 | params.num_lines = 32; | |
720 | else if ((params.num_lines & -params.num_lines) != params.num_lines) | |
721 | einfo (_("%P%F: invalid --num-lines/--num-regions `%u'\''\n"), | |
722 | params.num_lines); | |
723 | if (!line_size_set) | |
724 | params.line_size = 1024; | |
725 | else if ((params.line_size & -params.line_size) != params.line_size) | |
726 | einfo (_("%P%F: invalid --line-size/--region-size `%u'\''\n"), | |
727 | params.line_size); | |
728 | break; | |
729 | ||
730 | case OPTION_SPU_LRLIVE: | |
731 | params.lrlive_analysis = 1; | |
732 | break; | |
733 | ||
fb266b8b AM |
734 | case OPTION_SPU_NON_IA_TEXT: |
735 | params.non_ia_text = 1; | |
736 | break; | |
737 | ||
cd4a7468 AM |
738 | case OPTION_SPU_NUM_LINES: |
739 | { | |
740 | char *end; | |
741 | params.num_lines = strtoul (optarg, &end, 0); | |
742 | num_lines_set = 1; | |
743 | if (*end == 0 | |
744 | && (params.ovly_flavour != ovly_soft_icache | |
745 | || (params.num_lines & -params.num_lines) == params.num_lines)) | |
746 | break; | |
747 | einfo (_("%P%F: invalid --num-lines/--num-regions `%s'\''\n"), optarg); | |
748 | } | |
749 | break; | |
750 | ||
751 | case OPTION_SPU_LINE_SIZE: | |
a3a219a9 AM |
752 | { |
753 | char *end; | |
cd4a7468 AM |
754 | params.line_size = strtoul (optarg, &end, 0); |
755 | line_size_set = 1; | |
756 | if (*end == 0 | |
757 | && (params.ovly_flavour != ovly_soft_icache | |
758 | || (params.line_size & -params.line_size) == params.line_size)) | |
a3a219a9 | 759 | break; |
cd4a7468 | 760 | einfo (_("%P%F: invalid --line-size/--region-size `%s'\''\n"), optarg); |
a3a219a9 AM |
761 | } |
762 | break; | |
763 | ||
9dcc4794 AM |
764 | case OPTION_SPU_FIXED_SPACE: |
765 | { | |
766 | char *end; | |
64615358 | 767 | params.auto_overlay_fixed = strtoul (optarg, &end, 0); |
9dcc4794 AM |
768 | if (*end != 0) |
769 | einfo (_("%P%F: invalid --fixed-space value `%s'\''\n"), optarg); | |
770 | } | |
771 | break; | |
772 | ||
773 | case OPTION_SPU_RESERVED_SPACE: | |
774 | { | |
775 | char *end; | |
64615358 | 776 | params.auto_overlay_reserved = strtoul (optarg, &end, 0); |
9dcc4794 AM |
777 | if (*end != 0) |
778 | einfo (_("%P%F: invalid --reserved-space value `%s'\''\n"), optarg); | |
779 | } | |
780 | break; | |
781 | ||
99302af9 AM |
782 | case OPTION_SPU_EXTRA_STACK: |
783 | { | |
784 | char *end; | |
64615358 | 785 | params.extra_stack_space = strtol (optarg, &end, 0); |
99302af9 AM |
786 | if (*end != 0) |
787 | einfo (_("%P%F: invalid --extra-stack-space value `%s'\''\n"), optarg); | |
788 | } | |
789 | break; | |
790 | ||
9dcc4794 | 791 | case OPTION_SPU_NO_AUTO_OVERLAY: |
64615358 | 792 | params.auto_overlay = 0; |
9dcc4794 AM |
793 | if (optarg != NULL) |
794 | { | |
795 | struct tflist *tf; | |
796 | size_t len; | |
797 | ||
798 | if (tmp_file_list == NULL) | |
799 | atexit (clean_tmp); | |
800 | ||
801 | len = strlen (optarg) + 1; | |
802 | tf = xmalloc (sizeof (*tf) - sizeof (tf->name) + len); | |
803 | memcpy (tf->name, optarg, len); | |
804 | tf->next = tmp_file_list; | |
805 | tmp_file_list = tf; | |
806 | break; | |
807 | } | |
808 | break; | |
e9f53129 AM |
809 | ' |
810 | ||
811 | LDEMUL_AFTER_OPEN=spu_after_open | |
812 | LDEMUL_BEFORE_ALLOCATION=spu_before_allocation | |
813 | LDEMUL_FINISH=gld${EMULATION_NAME}_finish | |
9dcc4794 | 814 | LDEMUL_CHOOSE_TARGET=gld${EMULATION_NAME}_choose_target |