]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - ld/emultempl/spuelf.em
[gdb/build] Cleanup gdb/features/feature_to_c.sh
[thirdparty/binutils-gdb.git] / ld / emultempl / spuelf.em
CommitLineData
e9f53129 1# This shell script emits a C file. -*- C -*-
fd67aa11 2# Copyright (C) 2006-2024 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
075a2b89 22# This file is sourced from elf.em, and defines extra spu specific
e9f53129
AM
23# features.
24#
92b93329 25fragment <<EOF
e9f53129
AM
26#include "ldctor.h"
27#include "elf32-spu.h"
28
64615358
AM
29static void spu_place_special_section (asection *, asection *, const char *);
30static bfd_size_type spu_elf_load_ovl_mgr (void);
31static FILE *spu_elf_open_overlay_script (void);
32static void spu_elf_relink (void);
e9f53129 33
64615358
AM
34static 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,
9cc305ec 40 0, ovly_normal, 0, 0, 0, 0, 0, 0, 0, 0,
64615358 41 0, 0x3ffff,
cd4a7468 42 1, 0, 16, 0, 0, 2000
64615358 43};
a7e11ee1 44
e4492aa0 45static unsigned int no_overlays = 0;
cd4a7468
AM
46static unsigned int num_lines_set = 0;
47static unsigned int line_size_set = 0;
9dcc4794 48static char *auto_overlay_file = 0;
9dcc4794
AM
49int my_argc;
50char **my_argv;
51
671ace2f
AM
52static const char ovl_mgr[] = {
53EOF
54
4b64c41f 55if ! cat ${srcdir}/emultempl/spu_ovl.o_c >> e${EMULATION_NAME}.c
2f9300ef 56then
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
60fi
61
62fragment <<EOF
63};
64
65static const char icache_mgr[] = {
66EOF
67
68if ! cat ${srcdir}/emultempl/spu_icache.o_c >> e${EMULATION_NAME}.c
69then
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
73fi
671ace2f 74
92b93329 75fragment <<EOF
671ace2f 76};
e9f53129
AM
77
78static const struct _ovl_stream ovl_mgr_stream = {
671ace2f
AM
79 ovl_mgr,
80 ovl_mgr + sizeof (ovl_mgr)
e9f53129
AM
81};
82
cd4a7468
AM
83static const struct _ovl_stream icache_mgr_stream = {
84 icache_mgr,
85 icache_mgr + sizeof (icache_mgr)
86};
87
e9f53129
AM
88
89static int
90is_spu_target (void)
91{
6d00b590 92 extern const bfd_target spu_elf32_vec;
e9f53129 93
6d00b590 94 return link_info.output_bfd->xvec == &spu_elf32_vec;
e9f53129
AM
95}
96
97/* Create our note section. */
98
99static void
100spu_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, &params);
109
0e1862bb 110 if (bfd_link_relocatable (&link_info))
df636c05
AM
111 lang_add_unique (".text.ia.*");
112
0e1862bb 113 if (!bfd_link_relocatable (&link_info)
64615358
AM
114 && link_info.input_bfds != NULL
115 && !spu_elf_create_sections (&link_info))
d003af55 116 einfo (_("%X%P: can not create note section: %E\n"));
64615358 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
134static void
47f6dab9 135spu_place_special_section (asection *s, asection *o, const char *output_name)
e9f53129
AM
136{
137 lang_output_section_statement_type *os;
138
64615358 139 if (o != NULL)
24ef1aa7
GM
140 os = lang_output_section_get (o);
141 else
142 os = lang_output_section_find (output_name);
e9f53129 143 if (os == NULL)
cd4a7468 144 {
d871d478 145 os = ldelf_place_orphan (s, output_name, 0);
cd4a7468
AM
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);
b209b5a6 154 lang_add_section (&add, s, NULL, NULL, os);
47f6dab9
AM
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);
f38a2680 168 lang_add_assignment (exp_assign (".", e_size, false));
bde18da4 169 pop_stat_ptr ();
cd4a7468 170 }
b209b5a6 171 lang_add_section (&os->children, s, NULL, NULL, os);
cd4a7468 172 }
e9f53129
AM
173
174 s->output_section->size += s->size;
175}
176
64615358 177/* Load built-in overlay manager. */
e9f53129 178
64615358 179static bfd_size_type
e9f53129
AM
180spu_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),
f38a2680 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)
d003af55 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))
d003af55 215 einfo (_("%X%P: can not open built-in overlay manager: %E\n"));
e9f53129
AM
216 else
217 {
218 asection *in;
219
220 if (!load_symbols (ovl_is, NULL))
d003af55 221 einfo (_("%X%P: can not load built-in overlay manager: %E\n"));
e9f53129 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
263static void
264spu_before_allocation (void)
265{
266 if (is_spu_target ()
0e1862bb 267 && !bfd_link_relocatable (&link_info)
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;
58e6cc77 275 expld.dataseg.phase = exp_seg_none;
f38a2680 276 one_lang_size_sections_pass (NULL, true);
e9f53129
AM
277
278 /* Find overlays by inspecting section vmas. */
ad2adbc8
AM
279 ret = spu_elf_find_overlays (&link_info);
280 if (ret == 0)
d003af55 281 einfo (_("%X%P: can not find overlays: %E\n"));
ad2adbc8 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 287 {
d003af55 288 einfo (_("%P: --auto-overlay ignored with user overlay script\n"));
64615358 289 params.auto_overlay = 0;
9dcc4794
AM
290 }
291
64615358 292 /* Ensure alignment of overlay sections is sufficient. */
8ce18f9c 293 for (os = (void *) lang_os_list.head;
64615358
AM
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)
d003af55 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 320 if (is_spu_target ()
0e1862bb 321 && !bfd_link_relocatable (&link_info))
9cc305ec
TS
322 spu_elf_size_sections (link_info.output_bfd, &link_info);
323
e9f53129
AM
324 gld${EMULATION_NAME}_before_allocation ();
325}
326
9dcc4794
AM
327struct tflist {
328 struct tflist *next;
329 char name[9];
330};
331
332static struct tflist *tmp_file_list;
333
334static 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
340static int
341new_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
364static FILE *
365spu_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:
d003af55 382 einfo (_("%F%P: can not open script: %E\n"));
9dcc4794
AM
383 }
384 return script;
385}
386
87f1617a
NC
387#include <errno.h>
388
9dcc4794
AM
389static void
390spu_elf_relink (void)
391{
87f1617a
NC
392 const char *pex_return;
393 int status;
d77ec871 394 char **argv = xmalloc ((my_argc + 4) * sizeof (*argv));
9dcc4794
AM
395
396 memcpy (argv, my_argv, my_argc * sizeof (*argv));
397 argv[my_argc++] = "--no-auto-overlay";
32168ca6 398 if (tmp_file_list != NULL && tmp_file_list->name == auto_overlay_file)
d77ec871
AM
399 argv[my_argc - 1] = concat (argv[my_argc - 1], "=",
400 auto_overlay_file, (const char *) NULL);
9dcc4794
AM
401 argv[my_argc++] = "-T";
402 argv[my_argc++] = auto_overlay_file;
403 argv[my_argc] = 0;
87f1617a
NC
404
405 pex_return = pex_one (PEX_SEARCH | PEX_LAST, (const char *) argv[0],
406 (char * const *) argv, (const char *) argv[0],
407 NULL, NULL, & status, & errno);
408 if (pex_return != NULL)
409 {
410 perror (pex_return);
411 _exit (127);
412 }
413 exit (status);
9dcc4794
AM
414}
415
e9f53129
AM
416/* Final emulation specific call. */
417
418static void
419gld${EMULATION_NAME}_finish (void)
420{
771a9c5f 421 if (is_spu_target ())
e9f53129 422 {
64615358 423 if (params.local_store_lo < params.local_store_hi)
6c19b93b 424 {
771a9c5f
AM
425 asection *s;
426
64615358
AM
427 s = spu_elf_check_vma (&link_info);
428 if (s != NULL && !params.auto_overlay)
871b3ab2 429 einfo (_("%X%P: %pA exceeds local store range\n"), s);
771a9c5f 430 }
64615358 431 else if (params.auto_overlay)
d003af55 432 einfo (_("%P: --auto-overlay ignored with zero local store range\n"));
e9f53129
AM
433 }
434
e9f53129
AM
435 finish_default ();
436}
437
9dcc4794
AM
438static char *
439gld${EMULATION_NAME}_choose_target (int argc, char *argv[])
440{
441 my_argc = argc;
442 my_argv = argv;
443 return ldemul_default_target (argc, argv);
444}
445
e9f53129
AM
446EOF
447
dc27aea4 448if grep -q 'ld_elf.*ppc.*_emulation' ldemul-list.h; then
92b93329 449 fragment <<EOF
e30d16e9 450#include "safe-ctype.h"
dc27aea4 451#include "filenames.h"
fc15a272 452#include "libiberty.h"
dc27aea4 453
3ba20bde
AM
454static const char *
455base_name (const char *path)
456{
457 const char *file = strrchr (path, '/');
458#ifdef HAVE_DOS_BASED_FILE_SYSTEM
459 {
0fd1c9f1 460 char *bslash = strrchr (path, '\\\\');
3ba20bde
AM
461
462 if (file == NULL || (bslash != NULL && bslash > file))
463 file = bslash;
464 if (file == NULL
465 && path[0] != '\0'
466 && path[1] == ':')
467 file = path + 1;
468 }
469#endif
470 if (file == NULL)
471 file = path;
472 else
473 ++file;
474 return file;
475}
476
dc27aea4
AM
477/* This function is called when building a ppc32 or ppc64 executable
478 to handle embedded spu images. */
f38a2680 479extern bool embedded_spu_file (lang_input_statement_type *, const char *);
dc27aea4 480
f38a2680 481bool
dc27aea4
AM
482embedded_spu_file (lang_input_statement_type *entry, const char *flags)
483{
484 const char *cmd[6];
fc15a272 485 const char *pex_return;
dc27aea4
AM
486 const char *sym;
487 char *handle, *p;
dc27aea4
AM
488 char *oname;
489 int fd;
dc27aea4
AM
490 int status;
491 union lang_statement_union **old_stat_tail;
492 union lang_statement_union **old_file_tail;
493 union lang_statement_union *new_ent;
3ba20bde 494 lang_input_statement_type *search;
dc27aea4
AM
495
496 if (entry->the_bfd->format != bfd_object
497 || strcmp (entry->the_bfd->xvec->name, "elf32-spu") != 0
498 || (entry->the_bfd->tdata.elf_obj_data->elf_header->e_type != ET_EXEC
499 && entry->the_bfd->tdata.elf_obj_data->elf_header->e_type != ET_DYN))
f38a2680 500 return false;
dc27aea4
AM
501
502 /* Use the filename as the symbol marking the program handle struct. */
607b4833 503 sym = base_name (bfd_get_filename (entry->the_bfd));
dc27aea4
AM
504
505 handle = xstrdup (sym);
506 for (p = handle; *p; ++p)
507 if (!(ISALNUM (*p) || *p == '$' || *p == '.'))
508 *p = '_';
509
9dcc4794 510 fd = new_tmp_file (&oname);
dc27aea4 511 if (fd == -1)
f38a2680 512 return false;
dc27aea4
AM
513 close (fd);
514
8ce18f9c 515 for (search = (void *) input_file_chain.head;
3ba20bde 516 search != NULL;
36983a93 517 search = search->next_real_file)
80c4ed32
AM
518 if (search->filename != NULL)
519 {
520 const char *infile = base_name (search->filename);
521
522 if (strncmp (infile, "crtbegin", 8) == 0)
523 {
524 if (infile[8] == 'S')
ff7a0acf 525 flags = concat (flags, " -fPIC", (const char *) NULL);
80c4ed32 526 else if (infile[8] == 'T')
ff7a0acf 527 flags = concat (flags, " -fpie", (const char *) NULL);
80c4ed32
AM
528 break;
529 }
530 }
3ba20bde 531
42ba7415 532 cmd[0] = EMBEDSPU;
dc27aea4
AM
533 cmd[1] = flags;
534 cmd[2] = handle;
607b4833 535 cmd[3] = bfd_get_filename (entry->the_bfd);
dc27aea4
AM
536 cmd[4] = oname;
537 cmd[5] = NULL;
cd6f1cf3 538 if (verbose)
dc27aea4
AM
539 {
540 info_msg (_("running: %s \"%s\" \"%s\" \"%s\" \"%s\"\n"),
541 cmd[0], cmd[1], cmd[2], cmd[3], cmd[4]);
542 fflush (stdout);
543 }
544
fc15a272
AM
545 pex_return = pex_one (PEX_SEARCH | PEX_LAST, cmd[0], (char *const *) cmd,
546 cmd[0], NULL, NULL, &status, &errno);
547 if (NULL != pex_return) {
42ba7415 548 if (strcmp ("embedspu", EMBEDSPU) != 0)
628e8859
AM
549 {
550 cmd[0] = "embedspu";
fc15a272
AM
551 pex_return = pex_one (PEX_SEARCH | PEX_LAST, cmd[0], (char *const *) cmd,
552 cmd[0], NULL, NULL, &status, &errno);
628e8859 553 }
e4492aa0 554 if (NULL != pex_return) {
fc15a272
AM
555 perror (pex_return);
556 _exit (127);
557 }
558 }
559 if (status)
f38a2680 560 return false;
fc15a272 561
dc27aea4
AM
562
563 old_stat_tail = stat_ptr->tail;
564 old_file_tail = input_file_chain.tail;
565 if (lang_add_input_file (oname, lang_input_file_is_file_enum, NULL) == NULL)
f38a2680 566 return false;
dc27aea4 567
bde18da4 568 /* lang_add_input_file puts the new list entry at the end of the statement
dc27aea4
AM
569 and input file lists. Move it to just after the current entry. */
570 new_ent = *old_stat_tail;
571 *old_stat_tail = NULL;
572 stat_ptr->tail = old_stat_tail;
573 *old_file_tail = NULL;
574 input_file_chain.tail = old_file_tail;
575 new_ent->header.next = entry->header.next;
576 entry->header.next = new_ent;
577 new_ent->input_statement.next_real_file = entry->next_real_file;
36983a93 578 entry->next_real_file = &new_ent->input_statement;
dc27aea4
AM
579
580 /* Ensure bfd sections are excluded from the output. */
581 bfd_section_list_clear (entry->the_bfd);
f38a2680
AM
582 entry->flags.loaded = true;
583 return true;
dc27aea4
AM
584}
585
586EOF
587fi
588
e9f53129
AM
589# Define some shell vars to insert bits of code into the standard elf
590# parse_args and list_options functions.
591#
e9f53129
AM
592PARSE_AND_LIST_LONGOPTS='
593 { "plugin", no_argument, NULL, OPTION_SPU_PLUGIN },
cd4a7468
AM
594 { "soft-icache", no_argument, NULL, OPTION_SPU_SOFT_ICACHE },
595 { "lrlive-analysis", no_argument, NULL, OPTION_SPU_LRLIVE },
596 { "num-lines", required_argument, NULL, OPTION_SPU_NUM_LINES },
597 { "line-size", required_argument, NULL, OPTION_SPU_LINE_SIZE },
fb266b8b 598 { "non-ia-text", no_argument, NULL, OPTION_SPU_NON_IA_TEXT },
e9f53129 599 { "no-overlays", no_argument, NULL, OPTION_SPU_NO_OVERLAYS },
a7e11ee1 600 { "compact-stubs", no_argument, NULL, OPTION_SPU_COMPACT_STUBS },
e9f53129
AM
601 { "emit-stub-syms", no_argument, NULL, OPTION_SPU_STUB_SYMS },
602 { "extra-overlay-stubs", no_argument, NULL, OPTION_SPU_NON_OVERLAY_STUBS },
603 { "local-store", required_argument, NULL, OPTION_SPU_LOCAL_STORE },
49fa1e15
AM
604 { "stack-analysis", no_argument, NULL, OPTION_SPU_STACK_ANALYSIS },
605 { "emit-stack-syms", no_argument, NULL, OPTION_SPU_STACK_SYMS },
9dcc4794
AM
606 { "auto-overlay", optional_argument, NULL, OPTION_SPU_AUTO_OVERLAY },
607 { "auto-relink", no_argument, NULL, OPTION_SPU_AUTO_RELINK },
608 { "overlay-rodata", no_argument, NULL, OPTION_SPU_OVERLAY_RODATA },
cd4a7468
AM
609 { "num-regions", required_argument, NULL, OPTION_SPU_NUM_LINES },
610 { "region-size", required_argument, NULL, OPTION_SPU_LINE_SIZE },
9dcc4794
AM
611 { "fixed-space", required_argument, NULL, OPTION_SPU_FIXED_SPACE },
612 { "reserved-space", required_argument, NULL, OPTION_SPU_RESERVED_SPACE },
99302af9 613 { "extra-stack-space", required_argument, NULL, OPTION_SPU_EXTRA_STACK },
9dcc4794 614 { "no-auto-overlay", optional_argument, NULL, OPTION_SPU_NO_AUTO_OVERLAY },
9cc305ec 615 { "emit-fixups", optional_argument, NULL, OPTION_SPU_EMIT_FIXUPS },
e9f53129
AM
616'
617
618PARSE_AND_LIST_OPTIONS='
619 fprintf (file, _("\
df5f2391
AM
620 --plugin Make SPU plugin\n"));
621 fprintf (file, _("\
622 --no-overlays No overlay handling\n"));
623 fprintf (file, _("\
624 --compact-stubs Use smaller and possibly slower call stubs\n"));
625 fprintf (file, _("\
626 --emit-stub-syms Add symbols on overlay call stubs\n"));
627 fprintf (file, _("\
628 --extra-overlay-stubs Add stubs on all calls out of overlay regions\n"));
629 fprintf (file, _("\
630 --local-store=lo:hi Valid address range\n"));
631 fprintf (file, _("\
632 --stack-analysis Estimate maximum stack requirement\n"));
633 fprintf (file, _("\
634 --emit-stack-syms Add sym giving stack needed for each func\n"));
635 fprintf (file, _("\
9dcc4794 636 --auto-overlay [=filename] Create an overlay script in filename if\n\
df5f2391
AM
637 executable does not fit in local store\n"));
638 fprintf (file, _("\
639 --auto-relink Rerun linker using auto-overlay script\n"));
640 fprintf (file, _("\
9dcc4794 641 --overlay-rodata Place read-only data with associated function\n\
df5f2391
AM
642 code in overlays\n"));
643 fprintf (file, _("\
644 --num-regions Number of overlay buffers (default 1)\n"));
645 fprintf (file, _("\
646 --region-size Size of overlay buffers (default 0, auto)\n"));
647 fprintf (file, _("\
648 --fixed-space=bytes Local store for non-overlay code and data\n"));
649 fprintf (file, _("\
99302af9 650 --reserved-space=bytes Local store for stack and heap. If not specified\n\
df5f2391
AM
651 ld will estimate stack size and assume no heap\n"));
652 fprintf (file, _("\
99302af9 653 --extra-stack-space=bytes Space for negative sp access (default 2000) if\n\
df5f2391
AM
654 --reserved-space not given\n"));
655 fprintf (file, _("\
656 --soft-icache Generate software icache overlays\n"));
657 fprintf (file, _("\
658 --num-lines Number of soft-icache lines (default 32)\n"));
659 fprintf (file, _("\
660 --line-size Size of soft-icache lines (default 1k)\n"));
661 fprintf (file, _("\
662 --non-ia-text Allow non-icache code in icache lines\n"));
663 fprintf (file, _("\
664 --lrlive-analysis Scan function prologue for lr liveness\n"));
e9f53129
AM
665'
666
667PARSE_AND_LIST_ARGS_CASES='
668 case OPTION_SPU_PLUGIN:
669 spu_elf_plugin (1);
670 break;
671
672 case OPTION_SPU_NO_OVERLAYS:
a7e11ee1
AM
673 no_overlays = 1;
674 break;
675
676 case OPTION_SPU_COMPACT_STUBS:
677 params.compact_stub = 1;
e9f53129
AM
678 break;
679
680 case OPTION_SPU_STUB_SYMS:
64615358 681 params.emit_stub_syms = 1;
e9f53129
AM
682 break;
683
684 case OPTION_SPU_NON_OVERLAY_STUBS:
64615358 685 params.non_overlay_stubs = 1;
e9f53129
AM
686 break;
687
688 case OPTION_SPU_LOCAL_STORE:
689 {
690 char *end;
64615358 691 params.local_store_lo = strtoul (optarg, &end, 0);
e9f53129
AM
692 if (*end == '\'':'\'')
693 {
64615358 694 params.local_store_hi = strtoul (end + 1, &end, 0);
e9f53129
AM
695 if (*end == 0)
696 break;
697 }
df5f2391 698 einfo (_("%F%P: invalid --local-store address range `%s'\''\n"), optarg);
e9f53129
AM
699 }
700 break;
49fa1e15
AM
701
702 case OPTION_SPU_STACK_ANALYSIS:
64615358 703 params.stack_analysis = 1;
49fa1e15
AM
704 break;
705
706 case OPTION_SPU_STACK_SYMS:
64615358 707 params.emit_stack_syms = 1;
49fa1e15 708 break;
9dcc4794
AM
709
710 case OPTION_SPU_AUTO_OVERLAY:
64615358 711 params.auto_overlay |= 1;
9dcc4794
AM
712 if (optarg != NULL)
713 {
714 auto_overlay_file = optarg;
715 break;
716 }
839b0b3f 717 /* Fallthru */
9dcc4794
AM
718
719 case OPTION_SPU_AUTO_RELINK:
64615358 720 params.auto_overlay |= 2;
9dcc4794
AM
721 break;
722
723 case OPTION_SPU_OVERLAY_RODATA:
64615358 724 params.auto_overlay |= 4;
9dcc4794
AM
725 break;
726
cd4a7468
AM
727 case OPTION_SPU_SOFT_ICACHE:
728 params.ovly_flavour = ovly_soft_icache;
cdc83fba
UW
729 /* Software i-cache stubs are always "compact". */
730 params.compact_stub = 1;
cd4a7468
AM
731 if (!num_lines_set)
732 params.num_lines = 32;
733 else if ((params.num_lines & -params.num_lines) != params.num_lines)
df5f2391 734 einfo (_("%F%P: invalid --num-lines/--num-regions `%u'\''\n"),
cd4a7468
AM
735 params.num_lines);
736 if (!line_size_set)
737 params.line_size = 1024;
738 else if ((params.line_size & -params.line_size) != params.line_size)
df5f2391 739 einfo (_("%F%P: invalid --line-size/--region-size `%u'\''\n"),
cd4a7468
AM
740 params.line_size);
741 break;
742
743 case OPTION_SPU_LRLIVE:
744 params.lrlive_analysis = 1;
745 break;
746
fb266b8b
AM
747 case OPTION_SPU_NON_IA_TEXT:
748 params.non_ia_text = 1;
749 break;
750
cd4a7468
AM
751 case OPTION_SPU_NUM_LINES:
752 {
753 char *end;
754 params.num_lines = strtoul (optarg, &end, 0);
755 num_lines_set = 1;
756 if (*end == 0
757 && (params.ovly_flavour != ovly_soft_icache
758 || (params.num_lines & -params.num_lines) == params.num_lines))
759 break;
df5f2391 760 einfo (_("%F%P: invalid --num-lines/--num-regions `%s'\''\n"), optarg);
cd4a7468
AM
761 }
762 break;
763
764 case OPTION_SPU_LINE_SIZE:
a3a219a9
AM
765 {
766 char *end;
cd4a7468
AM
767 params.line_size = strtoul (optarg, &end, 0);
768 line_size_set = 1;
769 if (*end == 0
770 && (params.ovly_flavour != ovly_soft_icache
771 || (params.line_size & -params.line_size) == params.line_size))
a3a219a9 772 break;
df5f2391 773 einfo (_("%F%P: invalid --line-size/--region-size `%s'\''\n"), optarg);
a3a219a9
AM
774 }
775 break;
776
9dcc4794
AM
777 case OPTION_SPU_FIXED_SPACE:
778 {
779 char *end;
64615358 780 params.auto_overlay_fixed = strtoul (optarg, &end, 0);
9dcc4794 781 if (*end != 0)
df5f2391 782 einfo (_("%F%P: invalid --fixed-space value `%s'\''\n"), optarg);
9dcc4794
AM
783 }
784 break;
785
786 case OPTION_SPU_RESERVED_SPACE:
787 {
788 char *end;
64615358 789 params.auto_overlay_reserved = strtoul (optarg, &end, 0);
9dcc4794 790 if (*end != 0)
df5f2391 791 einfo (_("%F%P: invalid --reserved-space value `%s'\''\n"), optarg);
9dcc4794
AM
792 }
793 break;
794
99302af9
AM
795 case OPTION_SPU_EXTRA_STACK:
796 {
797 char *end;
64615358 798 params.extra_stack_space = strtol (optarg, &end, 0);
99302af9 799 if (*end != 0)
df5f2391 800 einfo (_("%F%P: invalid --extra-stack-space value `%s'\''\n"), optarg);
99302af9
AM
801 }
802 break;
803
9dcc4794 804 case OPTION_SPU_NO_AUTO_OVERLAY:
64615358 805 params.auto_overlay = 0;
9dcc4794
AM
806 if (optarg != NULL)
807 {
808 struct tflist *tf;
809 size_t len;
810
811 if (tmp_file_list == NULL)
812 atexit (clean_tmp);
813
814 len = strlen (optarg) + 1;
815 tf = xmalloc (sizeof (*tf) - sizeof (tf->name) + len);
816 memcpy (tf->name, optarg, len);
817 tf->next = tmp_file_list;
818 tmp_file_list = tf;
819 break;
820 }
821 break;
9cc305ec
TS
822
823 case OPTION_SPU_EMIT_FIXUPS:
824 params.emit_fixups = 1;
825 break;
e9f53129
AM
826'
827
828LDEMUL_AFTER_OPEN=spu_after_open
829LDEMUL_BEFORE_ALLOCATION=spu_before_allocation
830LDEMUL_FINISH=gld${EMULATION_NAME}_finish
9dcc4794 831LDEMUL_CHOOSE_TARGET=gld${EMULATION_NAME}_choose_target