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