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