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