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