]>
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 (); | |
bbb0fc04 AM |
311 | |
312 | spu_elf_place_overlay_data (&link_info); | |
e9f53129 AM |
313 | } |
314 | ||
315 | /* We must not cache anything from the preliminary sizing. */ | |
316 | lang_reset_memory_regions (); | |
317 | } | |
318 | ||
319 | gld${EMULATION_NAME}_before_allocation (); | |
320 | } | |
321 | ||
9dcc4794 AM |
322 | struct tflist { |
323 | struct tflist *next; | |
324 | char name[9]; | |
325 | }; | |
326 | ||
327 | static struct tflist *tmp_file_list; | |
328 | ||
329 | static void clean_tmp (void) | |
330 | { | |
331 | for (; tmp_file_list != NULL; tmp_file_list = tmp_file_list->next) | |
332 | unlink (tmp_file_list->name); | |
333 | } | |
334 | ||
335 | static int | |
336 | new_tmp_file (char **fname) | |
337 | { | |
338 | struct tflist *tf; | |
339 | int fd; | |
340 | ||
341 | if (tmp_file_list == NULL) | |
342 | atexit (clean_tmp); | |
343 | tf = xmalloc (sizeof (*tf)); | |
344 | tf->next = tmp_file_list; | |
345 | tmp_file_list = tf; | |
346 | memcpy (tf->name, "ldXXXXXX", sizeof (tf->name)); | |
347 | *fname = tf->name; | |
348 | #ifdef HAVE_MKSTEMP | |
349 | fd = mkstemp (*fname); | |
350 | #else | |
351 | *fname = mktemp (*fname); | |
352 | if (*fname == NULL) | |
353 | return -1; | |
354 | fd = open (fname, O_RDWR | O_CREAT | O_EXCL, 0600); | |
355 | #endif | |
356 | return fd; | |
357 | } | |
358 | ||
359 | static FILE * | |
360 | spu_elf_open_overlay_script (void) | |
361 | { | |
362 | FILE *script = NULL; | |
363 | ||
364 | if (auto_overlay_file == NULL) | |
365 | { | |
366 | int fd = new_tmp_file (&auto_overlay_file); | |
367 | if (fd == -1) | |
368 | goto file_err; | |
369 | script = fdopen (fd, "w"); | |
370 | } | |
371 | else | |
372 | script = fopen (auto_overlay_file, "w"); | |
373 | ||
374 | if (script == NULL) | |
375 | { | |
376 | file_err: | |
377 | einfo ("%F%P: can not open script: %E\n"); | |
378 | } | |
379 | return script; | |
380 | } | |
381 | ||
382 | static void | |
383 | spu_elf_relink (void) | |
384 | { | |
d77ec871 | 385 | char **argv = xmalloc ((my_argc + 4) * sizeof (*argv)); |
9dcc4794 AM |
386 | |
387 | memcpy (argv, my_argv, my_argc * sizeof (*argv)); | |
388 | argv[my_argc++] = "--no-auto-overlay"; | |
389 | if (tmp_file_list->name == auto_overlay_file) | |
d77ec871 AM |
390 | argv[my_argc - 1] = concat (argv[my_argc - 1], "=", |
391 | auto_overlay_file, (const char *) NULL); | |
9dcc4794 AM |
392 | argv[my_argc++] = "-T"; |
393 | argv[my_argc++] = auto_overlay_file; | |
394 | argv[my_argc] = 0; | |
395 | execvp (argv[0], (char *const *) argv); | |
396 | perror (argv[0]); | |
397 | _exit (127); | |
398 | } | |
399 | ||
e9f53129 AM |
400 | /* Final emulation specific call. */ |
401 | ||
402 | static void | |
403 | gld${EMULATION_NAME}_finish (void) | |
404 | { | |
405 | int need_laying_out; | |
406 | ||
f13a99db | 407 | need_laying_out = bfd_elf_discard_info (link_info.output_bfd, &link_info); |
e9f53129 AM |
408 | |
409 | gld${EMULATION_NAME}_map_segments (need_laying_out); | |
410 | ||
771a9c5f | 411 | if (is_spu_target ()) |
e9f53129 | 412 | { |
64615358 | 413 | if (params.local_store_lo < params.local_store_hi) |
771a9c5f AM |
414 | { |
415 | asection *s; | |
416 | ||
64615358 AM |
417 | s = spu_elf_check_vma (&link_info); |
418 | if (s != NULL && !params.auto_overlay) | |
771a9c5f AM |
419 | einfo ("%X%P: %A exceeds local store range\n", s); |
420 | } | |
64615358 | 421 | else if (params.auto_overlay) |
9dcc4794 | 422 | einfo ("%P: --auto-overlay ignored with zero local store range\n"); |
e9f53129 AM |
423 | } |
424 | ||
e9f53129 AM |
425 | finish_default (); |
426 | } | |
427 | ||
9dcc4794 AM |
428 | static char * |
429 | gld${EMULATION_NAME}_choose_target (int argc, char *argv[]) | |
430 | { | |
431 | my_argc = argc; | |
432 | my_argv = argv; | |
433 | return ldemul_default_target (argc, argv); | |
434 | } | |
435 | ||
e9f53129 AM |
436 | EOF |
437 | ||
dc27aea4 | 438 | if grep -q 'ld_elf.*ppc.*_emulation' ldemul-list.h; then |
92b93329 | 439 | fragment <<EOF |
fc15a272 | 440 | #include <errno.h> |
dc27aea4 | 441 | #include "filenames.h" |
fc15a272 | 442 | #include "libiberty.h" |
dc27aea4 | 443 | |
3ba20bde AM |
444 | static const char * |
445 | base_name (const char *path) | |
446 | { | |
447 | const char *file = strrchr (path, '/'); | |
448 | #ifdef HAVE_DOS_BASED_FILE_SYSTEM | |
449 | { | |
0fd1c9f1 | 450 | char *bslash = strrchr (path, '\\\\'); |
3ba20bde AM |
451 | |
452 | if (file == NULL || (bslash != NULL && bslash > file)) | |
453 | file = bslash; | |
454 | if (file == NULL | |
455 | && path[0] != '\0' | |
456 | && path[1] == ':') | |
457 | file = path + 1; | |
458 | } | |
459 | #endif | |
460 | if (file == NULL) | |
461 | file = path; | |
462 | else | |
463 | ++file; | |
464 | return file; | |
465 | } | |
466 | ||
dc27aea4 AM |
467 | /* This function is called when building a ppc32 or ppc64 executable |
468 | to handle embedded spu images. */ | |
469 | extern bfd_boolean embedded_spu_file (lang_input_statement_type *, const char *); | |
470 | ||
471 | bfd_boolean | |
472 | embedded_spu_file (lang_input_statement_type *entry, const char *flags) | |
473 | { | |
474 | const char *cmd[6]; | |
fc15a272 | 475 | const char *pex_return; |
dc27aea4 AM |
476 | const char *sym; |
477 | char *handle, *p; | |
dc27aea4 AM |
478 | char *oname; |
479 | int fd; | |
dc27aea4 AM |
480 | int status; |
481 | union lang_statement_union **old_stat_tail; | |
482 | union lang_statement_union **old_file_tail; | |
483 | union lang_statement_union *new_ent; | |
3ba20bde | 484 | lang_input_statement_type *search; |
dc27aea4 AM |
485 | |
486 | if (entry->the_bfd->format != bfd_object | |
487 | || strcmp (entry->the_bfd->xvec->name, "elf32-spu") != 0 | |
488 | || (entry->the_bfd->tdata.elf_obj_data->elf_header->e_type != ET_EXEC | |
489 | && entry->the_bfd->tdata.elf_obj_data->elf_header->e_type != ET_DYN)) | |
490 | return FALSE; | |
491 | ||
492 | /* Use the filename as the symbol marking the program handle struct. */ | |
3ba20bde | 493 | sym = base_name (entry->the_bfd->filename); |
dc27aea4 AM |
494 | |
495 | handle = xstrdup (sym); | |
496 | for (p = handle; *p; ++p) | |
497 | if (!(ISALNUM (*p) || *p == '$' || *p == '.')) | |
498 | *p = '_'; | |
499 | ||
9dcc4794 | 500 | fd = new_tmp_file (&oname); |
dc27aea4 AM |
501 | if (fd == -1) |
502 | return FALSE; | |
503 | close (fd); | |
504 | ||
3ba20bde AM |
505 | for (search = (lang_input_statement_type *) input_file_chain.head; |
506 | search != NULL; | |
507 | search = (lang_input_statement_type *) search->next_real_file) | |
80c4ed32 AM |
508 | if (search->filename != NULL) |
509 | { | |
510 | const char *infile = base_name (search->filename); | |
511 | ||
512 | if (strncmp (infile, "crtbegin", 8) == 0) | |
513 | { | |
514 | if (infile[8] == 'S') | |
ff7a0acf | 515 | flags = concat (flags, " -fPIC", (const char *) NULL); |
80c4ed32 | 516 | else if (infile[8] == 'T') |
ff7a0acf | 517 | flags = concat (flags, " -fpie", (const char *) NULL); |
80c4ed32 AM |
518 | break; |
519 | } | |
520 | } | |
3ba20bde | 521 | |
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 | ||
fc15a272 AM |
535 | pex_return = pex_one (PEX_SEARCH | PEX_LAST, cmd[0], (char *const *) cmd, |
536 | cmd[0], NULL, NULL, &status, &errno); | |
537 | if (NULL != pex_return) { | |
42ba7415 | 538 | if (strcmp ("embedspu", EMBEDSPU) != 0) |
628e8859 AM |
539 | { |
540 | cmd[0] = "embedspu"; | |
fc15a272 AM |
541 | pex_return = pex_one (PEX_SEARCH | PEX_LAST, cmd[0], (char *const *) cmd, |
542 | cmd[0], NULL, NULL, &status, &errno); | |
628e8859 | 543 | } |
fc15a272 AM |
544 | if (NULL != pex_return) { |
545 | perror (pex_return); | |
546 | _exit (127); | |
547 | } | |
548 | } | |
549 | if (status) | |
dc27aea4 | 550 | return FALSE; |
fc15a272 | 551 | |
dc27aea4 AM |
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 | ||
bde18da4 | 558 | /* lang_add_input_file puts the new list entry at the end of the statement |
dc27aea4 AM |
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) | |
a7e11ee1 AM |
585 | #define OPTION_SPU_COMPACT_STUBS (OPTION_SPU_NO_OVERLAYS + 1) |
586 | #define OPTION_SPU_STUB_SYMS (OPTION_SPU_COMPACT_STUBS + 1) | |
e9f53129 AM |
587 | #define OPTION_SPU_NON_OVERLAY_STUBS (OPTION_SPU_STUB_SYMS + 1) |
588 | #define OPTION_SPU_LOCAL_STORE (OPTION_SPU_NON_OVERLAY_STUBS + 1) | |
49fa1e15 AM |
589 | #define OPTION_SPU_STACK_ANALYSIS (OPTION_SPU_LOCAL_STORE + 1) |
590 | #define OPTION_SPU_STACK_SYMS (OPTION_SPU_STACK_ANALYSIS + 1) | |
9dcc4794 AM |
591 | #define OPTION_SPU_AUTO_OVERLAY (OPTION_SPU_STACK_SYMS + 1) |
592 | #define OPTION_SPU_AUTO_RELINK (OPTION_SPU_AUTO_OVERLAY + 1) | |
593 | #define OPTION_SPU_OVERLAY_RODATA (OPTION_SPU_AUTO_RELINK + 1) | |
cd4a7468 AM |
594 | #define OPTION_SPU_SOFT_ICACHE (OPTION_SPU_OVERLAY_RODATA + 1) |
595 | #define OPTION_SPU_LINE_SIZE (OPTION_SPU_SOFT_ICACHE + 1) | |
596 | #define OPTION_SPU_NUM_LINES (OPTION_SPU_LINE_SIZE + 1) | |
597 | #define OPTION_SPU_LRLIVE (OPTION_SPU_NUM_LINES + 1) | |
fb266b8b AM |
598 | #define OPTION_SPU_NON_IA_TEXT (OPTION_SPU_LRLIVE + 1) |
599 | #define OPTION_SPU_FIXED_SPACE (OPTION_SPU_NON_IA_TEXT + 1) | |
9dcc4794 | 600 | #define OPTION_SPU_RESERVED_SPACE (OPTION_SPU_FIXED_SPACE + 1) |
99302af9 AM |
601 | #define OPTION_SPU_EXTRA_STACK (OPTION_SPU_RESERVED_SPACE + 1) |
602 | #define OPTION_SPU_NO_AUTO_OVERLAY (OPTION_SPU_EXTRA_STACK + 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 }, |
e9f53129 AM |
628 | ' |
629 | ||
630 | PARSE_AND_LIST_OPTIONS=' | |
631 | fprintf (file, _("\ | |
442996ee AM |
632 | --plugin Make SPU plugin.\n\ |
633 | --no-overlays No overlay handling.\n\ | |
a7e11ee1 | 634 | --compact-stubs Use smaller and possibly slower call stubs.\n\ |
442996ee AM |
635 | --emit-stub-syms Add symbols on overlay call stubs.\n\ |
636 | --extra-overlay-stubs Add stubs on all calls out of overlay regions.\n\ | |
637 | --local-store=lo:hi Valid address range.\n\ | |
638 | --stack-analysis Estimate maximum stack requirement.\n\ | |
9dcc4794 AM |
639 | --emit-stack-syms Add sym giving stack needed for each func.\n\ |
640 | --auto-overlay [=filename] Create an overlay script in filename if\n\ | |
641 | executable does not fit in local store.\n\ | |
642 | --auto-relink Rerun linker using auto-overlay script.\n\ | |
643 | --overlay-rodata Place read-only data with associated function\n\ | |
644 | code in overlays.\n\ | |
a3a219a9 | 645 | --num-regions Number of overlay buffers (default 1).\n\ |
cd4a7468 | 646 | --region-size Size of overlay buffers (default 0, auto).\n\ |
9dcc4794 | 647 | --fixed-space=bytes Local store for non-overlay code and data.\n\ |
99302af9 AM |
648 | --reserved-space=bytes Local store for stack and heap. If not specified\n\ |
649 | ld will estimate stack size and assume no heap.\n\ | |
650 | --extra-stack-space=bytes Space for negative sp access (default 2000) if\n\ | |
cd4a7468 AM |
651 | --reserved-space not given.\n\ |
652 | --soft-icache Generate software icache overlays.\n\ | |
653 | --num-lines Number of soft-icache lines (default 32).\n\ | |
654 | --line-size Size of soft-icache lines (default 1k).\n\ | |
fb266b8b | 655 | --non-ia-text Allow non-icache code in icache lines.\n\ |
cd4a7468 | 656 | --lrlive-analysis Scan function prologue for lr liveness.\n" |
e9f53129 AM |
657 | )); |
658 | ' | |
659 | ||
660 | PARSE_AND_LIST_ARGS_CASES=' | |
661 | case OPTION_SPU_PLUGIN: | |
662 | spu_elf_plugin (1); | |
663 | break; | |
664 | ||
665 | case OPTION_SPU_NO_OVERLAYS: | |
a7e11ee1 AM |
666 | no_overlays = 1; |
667 | break; | |
668 | ||
669 | case OPTION_SPU_COMPACT_STUBS: | |
670 | params.compact_stub = 1; | |
e9f53129 AM |
671 | break; |
672 | ||
673 | case OPTION_SPU_STUB_SYMS: | |
64615358 | 674 | params.emit_stub_syms = 1; |
e9f53129 AM |
675 | break; |
676 | ||
677 | case OPTION_SPU_NON_OVERLAY_STUBS: | |
64615358 | 678 | params.non_overlay_stubs = 1; |
e9f53129 AM |
679 | break; |
680 | ||
681 | case OPTION_SPU_LOCAL_STORE: | |
682 | { | |
683 | char *end; | |
64615358 | 684 | params.local_store_lo = strtoul (optarg, &end, 0); |
e9f53129 AM |
685 | if (*end == '\'':'\'') |
686 | { | |
64615358 | 687 | params.local_store_hi = strtoul (end + 1, &end, 0); |
e9f53129 AM |
688 | if (*end == 0) |
689 | break; | |
690 | } | |
691 | einfo (_("%P%F: invalid --local-store address range `%s'\''\n"), optarg); | |
692 | } | |
693 | break; | |
49fa1e15 AM |
694 | |
695 | case OPTION_SPU_STACK_ANALYSIS: | |
64615358 | 696 | params.stack_analysis = 1; |
49fa1e15 AM |
697 | break; |
698 | ||
699 | case OPTION_SPU_STACK_SYMS: | |
64615358 | 700 | params.emit_stack_syms = 1; |
49fa1e15 | 701 | break; |
9dcc4794 AM |
702 | |
703 | case OPTION_SPU_AUTO_OVERLAY: | |
64615358 | 704 | params.auto_overlay |= 1; |
9dcc4794 AM |
705 | if (optarg != NULL) |
706 | { | |
707 | auto_overlay_file = optarg; | |
708 | break; | |
709 | } | |
710 | /* Fall thru */ | |
711 | ||
712 | case OPTION_SPU_AUTO_RELINK: | |
64615358 | 713 | params.auto_overlay |= 2; |
9dcc4794 AM |
714 | break; |
715 | ||
716 | case OPTION_SPU_OVERLAY_RODATA: | |
64615358 | 717 | params.auto_overlay |= 4; |
9dcc4794 AM |
718 | break; |
719 | ||
cd4a7468 AM |
720 | case OPTION_SPU_SOFT_ICACHE: |
721 | params.ovly_flavour = ovly_soft_icache; | |
cdc83fba UW |
722 | /* Software i-cache stubs are always "compact". */ |
723 | params.compact_stub = 1; | |
cd4a7468 AM |
724 | if (!num_lines_set) |
725 | params.num_lines = 32; | |
726 | else if ((params.num_lines & -params.num_lines) != params.num_lines) | |
727 | einfo (_("%P%F: invalid --num-lines/--num-regions `%u'\''\n"), | |
728 | params.num_lines); | |
729 | if (!line_size_set) | |
730 | params.line_size = 1024; | |
731 | else if ((params.line_size & -params.line_size) != params.line_size) | |
732 | einfo (_("%P%F: invalid --line-size/--region-size `%u'\''\n"), | |
733 | params.line_size); | |
734 | break; | |
735 | ||
736 | case OPTION_SPU_LRLIVE: | |
737 | params.lrlive_analysis = 1; | |
738 | break; | |
739 | ||
fb266b8b AM |
740 | case OPTION_SPU_NON_IA_TEXT: |
741 | params.non_ia_text = 1; | |
742 | break; | |
743 | ||
cd4a7468 AM |
744 | case OPTION_SPU_NUM_LINES: |
745 | { | |
746 | char *end; | |
747 | params.num_lines = strtoul (optarg, &end, 0); | |
748 | num_lines_set = 1; | |
749 | if (*end == 0 | |
750 | && (params.ovly_flavour != ovly_soft_icache | |
751 | || (params.num_lines & -params.num_lines) == params.num_lines)) | |
752 | break; | |
753 | einfo (_("%P%F: invalid --num-lines/--num-regions `%s'\''\n"), optarg); | |
754 | } | |
755 | break; | |
756 | ||
757 | case OPTION_SPU_LINE_SIZE: | |
a3a219a9 AM |
758 | { |
759 | char *end; | |
cd4a7468 AM |
760 | params.line_size = strtoul (optarg, &end, 0); |
761 | line_size_set = 1; | |
762 | if (*end == 0 | |
763 | && (params.ovly_flavour != ovly_soft_icache | |
764 | || (params.line_size & -params.line_size) == params.line_size)) | |
a3a219a9 | 765 | break; |
cd4a7468 | 766 | einfo (_("%P%F: invalid --line-size/--region-size `%s'\''\n"), optarg); |
a3a219a9 AM |
767 | } |
768 | break; | |
769 | ||
9dcc4794 AM |
770 | case OPTION_SPU_FIXED_SPACE: |
771 | { | |
772 | char *end; | |
64615358 | 773 | params.auto_overlay_fixed = strtoul (optarg, &end, 0); |
9dcc4794 AM |
774 | if (*end != 0) |
775 | einfo (_("%P%F: invalid --fixed-space value `%s'\''\n"), optarg); | |
776 | } | |
777 | break; | |
778 | ||
779 | case OPTION_SPU_RESERVED_SPACE: | |
780 | { | |
781 | char *end; | |
64615358 | 782 | params.auto_overlay_reserved = strtoul (optarg, &end, 0); |
9dcc4794 AM |
783 | if (*end != 0) |
784 | einfo (_("%P%F: invalid --reserved-space value `%s'\''\n"), optarg); | |
785 | } | |
786 | break; | |
787 | ||
99302af9 AM |
788 | case OPTION_SPU_EXTRA_STACK: |
789 | { | |
790 | char *end; | |
64615358 | 791 | params.extra_stack_space = strtol (optarg, &end, 0); |
99302af9 AM |
792 | if (*end != 0) |
793 | einfo (_("%P%F: invalid --extra-stack-space value `%s'\''\n"), optarg); | |
794 | } | |
795 | break; | |
796 | ||
9dcc4794 | 797 | case OPTION_SPU_NO_AUTO_OVERLAY: |
64615358 | 798 | params.auto_overlay = 0; |
9dcc4794 AM |
799 | if (optarg != NULL) |
800 | { | |
801 | struct tflist *tf; | |
802 | size_t len; | |
803 | ||
804 | if (tmp_file_list == NULL) | |
805 | atexit (clean_tmp); | |
806 | ||
807 | len = strlen (optarg) + 1; | |
808 | tf = xmalloc (sizeof (*tf) - sizeof (tf->name) + len); | |
809 | memcpy (tf->name, optarg, len); | |
810 | tf->next = tmp_file_list; | |
811 | tmp_file_list = tf; | |
812 | break; | |
813 | } | |
814 | break; | |
e9f53129 AM |
815 | ' |
816 | ||
817 | LDEMUL_AFTER_OPEN=spu_after_open | |
818 | LDEMUL_BEFORE_ALLOCATION=spu_before_allocation | |
819 | LDEMUL_FINISH=gld${EMULATION_NAME}_finish | |
9dcc4794 | 820 | LDEMUL_CHOOSE_TARGET=gld${EMULATION_NAME}_choose_target |