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