* gdb.dwarf2/dwp-symlink.exp: Rewrite to use remote_* commands instead
[deliverable/binutils-gdb.git] / ld / emultempl / spuelf.em
CommitLineData
e9f53129 1# This shell script emits a C file. -*- C -*-
66be1055 2# Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012
2e57b2af 3# Free Software Foundation, Inc.
e9f53129 4#
f96b4a7b 5# This file is part of the GNU Binutils.
e9f53129
AM
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
f96b4a7b 9# the Free Software Foundation; either version 3 of the License, or
e9f53129
AM
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
f96b4a7b
NC
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20# MA 02110-1301, USA.
e9f53129
AM
21#
22
23# This file is sourced from elf32.em, and defines extra spu specific
24# features.
25#
92b93329 26fragment <<EOF
e9f53129
AM
27#include "ldctor.h"
28#include "elf32-spu.h"
29
64615358
AM
30static void spu_place_special_section (asection *, asection *, const char *);
31static bfd_size_type spu_elf_load_ovl_mgr (void);
32static FILE *spu_elf_open_overlay_script (void);
33static void spu_elf_relink (void);
e9f53129 34
64615358
AM
35static struct spu_elf_params params =
36{
37 &spu_place_special_section,
38 &spu_elf_load_ovl_mgr,
39 &spu_elf_open_overlay_script,
40 &spu_elf_relink,
9cc305ec 41 0, ovly_normal, 0, 0, 0, 0, 0, 0, 0, 0,
64615358 42 0, 0x3ffff,
cd4a7468 43 1, 0, 16, 0, 0, 2000
64615358 44};
a7e11ee1 45
e4492aa0 46static unsigned int no_overlays = 0;
cd4a7468
AM
47static unsigned int num_lines_set = 0;
48static unsigned int line_size_set = 0;
9dcc4794 49static char *auto_overlay_file = 0;
9dcc4794
AM
50int my_argc;
51char **my_argv;
52
671ace2f
AM
53static const char ovl_mgr[] = {
54EOF
55
4b64c41f 56if ! cat ${srcdir}/emultempl/spu_ovl.o_c >> e${EMULATION_NAME}.c
2f9300ef 57then
4b64c41f 58 echo >&2 "Missing ${srcdir}/emultempl/spu_ovl.o_c"
cd4a7468
AM
59 echo >&2 "You must build gas/as-new with --target=spu"
60 exit 1
61fi
62
63fragment <<EOF
64};
65
66static const char icache_mgr[] = {
67EOF
68
69if ! cat ${srcdir}/emultempl/spu_icache.o_c >> e${EMULATION_NAME}.c
70then
71 echo >&2 "Missing ${srcdir}/emultempl/spu_icache.o_c"
72 echo >&2 "You must build gas/as-new with --target=spu"
2f9300ef
JK
73 exit 1
74fi
671ace2f 75
92b93329 76fragment <<EOF
671ace2f 77};
e9f53129
AM
78
79static const struct _ovl_stream ovl_mgr_stream = {
671ace2f
AM
80 ovl_mgr,
81 ovl_mgr + sizeof (ovl_mgr)
e9f53129
AM
82};
83
cd4a7468
AM
84static const struct _ovl_stream icache_mgr_stream = {
85 icache_mgr,
86 icache_mgr + sizeof (icache_mgr)
87};
88
e9f53129
AM
89
90static int
91is_spu_target (void)
92{
93 extern const bfd_target bfd_elf32_spu_vec;
94
f13a99db 95 return link_info.output_bfd->xvec == &bfd_elf32_spu_vec;
e9f53129
AM
96}
97
98/* Create our note section. */
99
100static void
101spu_after_open (void)
102{
64615358
AM
103 if (is_spu_target ())
104 {
105 /* Pass params to backend. */
106 if ((params.auto_overlay & AUTO_OVERLAY) == 0)
107 params.auto_overlay = 0;
108 params.emit_stub_syms |= link_info.emitrelocations;
109 spu_elf_setup (&link_info, &params);
110
df636c05
AM
111 if (link_info.relocatable)
112 lang_add_unique (".text.ia.*");
113
64615358
AM
114 if (!link_info.relocatable
115 && link_info.input_bfds != NULL
116 && !spu_elf_create_sections (&link_info))
117 einfo ("%X%P: can not create note section: %E\n");
118 }
e9f53129
AM
119
120 gld${EMULATION_NAME}_after_open ();
121}
122
47f6dab9 123/* If O is NULL, add section S at the end of output section OUTPUT_NAME.
cd4a7468
AM
124 If O is not NULL, add section S at the beginning of output section O,
125 except for soft-icache which adds to the end.
e9f53129
AM
126
127 Really, we should be duplicating ldlang.c map_input_to_output_sections
128 logic here, ie. using the linker script to find where the section
129 goes. That's rather a lot of code, and we don't want to run
130 map_input_to_output_sections again because most sections are already
131 mapped. So cheat, and put the section in a fixed place, ignoring any
132 attempt via a linker script to put .stub, .ovtab, and built-in
133 overlay manager code somewhere else. */
134
135static void
47f6dab9 136spu_place_special_section (asection *s, asection *o, const char *output_name)
e9f53129
AM
137{
138 lang_output_section_statement_type *os;
139
64615358 140 if (o != NULL)
24ef1aa7
GM
141 os = lang_output_section_get (o);
142 else
143 os = lang_output_section_find (output_name);
e9f53129 144 if (os == NULL)
cd4a7468
AM
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)
47f6dab9
AM
151 {
152 lang_statement_list_type add;
153
154 lang_list_init (&add);
b9c361e0 155 lang_add_section (&add, s, NULL, os);
47f6dab9
AM
156 *add.tail = os->children.head;
157 os->children.head = add.head;
158 }
e9f53129 159 else
cd4a7468
AM
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;
cd4a7468 166
bde18da4 167 push_stat_ptr (&os->children);
cd4a7468 168 e_size = exp_intop (params.line_size - s->size);
eb8476a6 169 lang_add_assignment (exp_assign (".", e_size, FALSE));
bde18da4 170 pop_stat_ptr ();
cd4a7468 171 }
b9c361e0 172 lang_add_section (&os->children, s, NULL, os);
cd4a7468 173 }
e9f53129
AM
174
175 s->output_section->size += s->size;
176}
177
64615358 178/* Load built-in overlay manager. */
e9f53129 179
64615358 180static bfd_size_type
e9f53129
AM
181spu_elf_load_ovl_mgr (void)
182{
e9f53129 183 struct elf_link_hash_entry *h;
cd4a7468
AM
184 const char *ovly_mgr_entry;
185 const struct _ovl_stream *mgr_stream;
64615358 186 bfd_size_type total = 0;
e9f53129 187
cd4a7468
AM
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 }
e9f53129 195 h = elf_link_hash_lookup (elf_hash_table (&link_info),
cd4a7468 196 ovly_mgr_entry, FALSE, FALSE, FALSE);
e9f53129
AM
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 }
cd4a7468 205 else if (mgr_stream->start == mgr_stream->end)
45d3b878 206 einfo ("%F%P: no built-in overlay manager\n");
e9f53129
AM
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
cd4a7468 215 if (!spu_elf_open_builtin_lib (&ovl_is->the_bfd, mgr_stream))
e9f53129
AM
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
cd4a7468
AM
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. */
e9f53129
AM
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))
64615358 231 {
cd4a7468
AM
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);
64615358 256 }
e9f53129
AM
257 }
258 }
64615358 259 return total;
e9f53129
AM
260}
261
262/* Go find if we need to do anything special for overlays. */
263
264static void
265spu_before_allocation (void)
266{
267 if (is_spu_target ()
268 && !link_info.relocatable
a7e11ee1 269 && !no_overlays)
e9f53129 270 {
ad2adbc8
AM
271 int ret;
272
e9f53129
AM
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. */
ad2adbc8
AM
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)
e9f53129 284 {
64615358 285 lang_output_section_statement_type *os;
e9f53129 286
64615358 287 if (params.auto_overlay != 0)
9dcc4794
AM
288 {
289 einfo ("%P: --auto-overlay ignored with user overlay script\n");
64615358 290 params.auto_overlay = 0;
9dcc4794
AM
291 }
292
64615358
AM
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);
47f6dab9 309 if (ret == 0)
e9f53129 310 einfo ("%X%P: can not size overlay stubs: %E\n");
47f6dab9
AM
311 else if (ret == 2)
312 spu_elf_load_ovl_mgr ();
bbb0fc04
AM
313
314 spu_elf_place_overlay_data (&link_info);
e9f53129
AM
315 }
316
317 /* We must not cache anything from the preliminary sizing. */
318 lang_reset_memory_regions ();
319 }
320
9cc305ec
TS
321 if (is_spu_target ()
322 && !link_info.relocatable)
323 spu_elf_size_sections (link_info.output_bfd, &link_info);
324
e9f53129
AM
325 gld${EMULATION_NAME}_before_allocation ();
326}
327
9dcc4794
AM
328struct tflist {
329 struct tflist *next;
330 char name[9];
331};
332
333static struct tflist *tmp_file_list;
334
335static 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
341static int
342new_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;
a38ce0d0 360 fd = open (*fname, O_RDWR | O_CREAT | O_EXCL, 0600);
9dcc4794
AM
361#endif
362 return fd;
363}
364
365static FILE *
366spu_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
87f1617a
NC
388#include <errno.h>
389
9dcc4794
AM
390static void
391spu_elf_relink (void)
392{
87f1617a
NC
393 const char *pex_return;
394 int status;
d77ec871 395 char **argv = xmalloc ((my_argc + 4) * sizeof (*argv));
9dcc4794
AM
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)
d77ec871
AM
400 argv[my_argc - 1] = concat (argv[my_argc - 1], "=",
401 auto_overlay_file, (const char *) NULL);
9dcc4794
AM
402 argv[my_argc++] = "-T";
403 argv[my_argc++] = auto_overlay_file;
404 argv[my_argc] = 0;
87f1617a
NC
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);
9dcc4794
AM
415}
416
e9f53129
AM
417/* Final emulation specific call. */
418
419static void
420gld${EMULATION_NAME}_finish (void)
421{
771a9c5f 422 if (is_spu_target ())
e9f53129 423 {
64615358 424 if (params.local_store_lo < params.local_store_hi)
771a9c5f
AM
425 {
426 asection *s;
427
64615358
AM
428 s = spu_elf_check_vma (&link_info);
429 if (s != NULL && !params.auto_overlay)
771a9c5f
AM
430 einfo ("%X%P: %A exceeds local store range\n", s);
431 }
64615358 432 else if (params.auto_overlay)
9dcc4794 433 einfo ("%P: --auto-overlay ignored with zero local store range\n");
e9f53129
AM
434 }
435
e9f53129
AM
436 finish_default ();
437}
438
9dcc4794
AM
439static char *
440gld${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
e9f53129
AM
447EOF
448
dc27aea4 449if grep -q 'ld_elf.*ppc.*_emulation' ldemul-list.h; then
92b93329 450 fragment <<EOF
fc15a272 451#include <errno.h>
dc27aea4 452#include "filenames.h"
fc15a272 453#include "libiberty.h"
dc27aea4 454
3ba20bde
AM
455static const char *
456base_name (const char *path)
457{
458 const char *file = strrchr (path, '/');
459#ifdef HAVE_DOS_BASED_FILE_SYSTEM
460 {
0fd1c9f1 461 char *bslash = strrchr (path, '\\\\');
3ba20bde
AM
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
dc27aea4
AM
478/* This function is called when building a ppc32 or ppc64 executable
479 to handle embedded spu images. */
480extern bfd_boolean embedded_spu_file (lang_input_statement_type *, const char *);
481
482bfd_boolean
483embedded_spu_file (lang_input_statement_type *entry, const char *flags)
484{
485 const char *cmd[6];
fc15a272 486 const char *pex_return;
dc27aea4
AM
487 const char *sym;
488 char *handle, *p;
dc27aea4
AM
489 char *oname;
490 int fd;
dc27aea4
AM
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;
3ba20bde 495 lang_input_statement_type *search;
dc27aea4
AM
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. */
3ba20bde 504 sym = base_name (entry->the_bfd->filename);
dc27aea4
AM
505
506 handle = xstrdup (sym);
507 for (p = handle; *p; ++p)
508 if (!(ISALNUM (*p) || *p == '$' || *p == '.'))
509 *p = '_';
510
9dcc4794 511 fd = new_tmp_file (&oname);
dc27aea4
AM
512 if (fd == -1)
513 return FALSE;
514 close (fd);
515
3ba20bde
AM
516 for (search = (lang_input_statement_type *) input_file_chain.head;
517 search != NULL;
518 search = (lang_input_statement_type *) search->next_real_file)
80c4ed32
AM
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')
ff7a0acf 526 flags = concat (flags, " -fPIC", (const char *) NULL);
80c4ed32 527 else if (infile[8] == 'T')
ff7a0acf 528 flags = concat (flags, " -fpie", (const char *) NULL);
80c4ed32
AM
529 break;
530 }
531 }
3ba20bde 532
42ba7415 533 cmd[0] = EMBEDSPU;
dc27aea4
AM
534 cmd[1] = flags;
535 cmd[2] = handle;
536 cmd[3] = entry->the_bfd->filename;
537 cmd[4] = oname;
538 cmd[5] = NULL;
cd6f1cf3 539 if (verbose)
dc27aea4
AM
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
fc15a272
AM
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) {
42ba7415 549 if (strcmp ("embedspu", EMBEDSPU) != 0)
628e8859
AM
550 {
551 cmd[0] = "embedspu";
fc15a272
AM
552 pex_return = pex_one (PEX_SEARCH | PEX_LAST, cmd[0], (char *const *) cmd,
553 cmd[0], NULL, NULL, &status, &errno);
628e8859 554 }
e4492aa0 555 if (NULL != pex_return) {
fc15a272
AM
556 perror (pex_return);
557 _exit (127);
558 }
559 }
560 if (status)
dc27aea4 561 return FALSE;
fc15a272 562
dc27aea4
AM
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
bde18da4 569 /* lang_add_input_file puts the new list entry at the end of the statement
dc27aea4
AM
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);
66be1055 583 entry->flags.loaded = TRUE;
dc27aea4
AM
584 return TRUE;
585}
586
587EOF
588fi
589
e9f53129
AM
590# Define some shell vars to insert bits of code into the standard elf
591# parse_args and list_options functions.
592#
593PARSE_AND_LIST_PROLOGUE='
594#define OPTION_SPU_PLUGIN 301
595#define OPTION_SPU_NO_OVERLAYS (OPTION_SPU_PLUGIN + 1)
a7e11ee1
AM
596#define OPTION_SPU_COMPACT_STUBS (OPTION_SPU_NO_OVERLAYS + 1)
597#define OPTION_SPU_STUB_SYMS (OPTION_SPU_COMPACT_STUBS + 1)
e9f53129
AM
598#define OPTION_SPU_NON_OVERLAY_STUBS (OPTION_SPU_STUB_SYMS + 1)
599#define OPTION_SPU_LOCAL_STORE (OPTION_SPU_NON_OVERLAY_STUBS + 1)
49fa1e15
AM
600#define OPTION_SPU_STACK_ANALYSIS (OPTION_SPU_LOCAL_STORE + 1)
601#define OPTION_SPU_STACK_SYMS (OPTION_SPU_STACK_ANALYSIS + 1)
9dcc4794
AM
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)
cd4a7468
AM
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)
fb266b8b
AM
609#define OPTION_SPU_NON_IA_TEXT (OPTION_SPU_LRLIVE + 1)
610#define OPTION_SPU_FIXED_SPACE (OPTION_SPU_NON_IA_TEXT + 1)
9dcc4794 611#define OPTION_SPU_RESERVED_SPACE (OPTION_SPU_FIXED_SPACE + 1)
99302af9
AM
612#define OPTION_SPU_EXTRA_STACK (OPTION_SPU_RESERVED_SPACE + 1)
613#define OPTION_SPU_NO_AUTO_OVERLAY (OPTION_SPU_EXTRA_STACK + 1)
9cc305ec 614#define OPTION_SPU_EMIT_FIXUPS (OPTION_SPU_NO_AUTO_OVERLAY + 1)
e9f53129
AM
615'
616
617PARSE_AND_LIST_LONGOPTS='
618 { "plugin", no_argument, NULL, OPTION_SPU_PLUGIN },
cd4a7468
AM
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 },
fb266b8b 623 { "non-ia-text", no_argument, NULL, OPTION_SPU_NON_IA_TEXT },
e9f53129 624 { "no-overlays", no_argument, NULL, OPTION_SPU_NO_OVERLAYS },
a7e11ee1 625 { "compact-stubs", no_argument, NULL, OPTION_SPU_COMPACT_STUBS },
e9f53129
AM
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 },
49fa1e15
AM
629 { "stack-analysis", no_argument, NULL, OPTION_SPU_STACK_ANALYSIS },
630 { "emit-stack-syms", no_argument, NULL, OPTION_SPU_STACK_SYMS },
9dcc4794
AM
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 },
cd4a7468
AM
634 { "num-regions", required_argument, NULL, OPTION_SPU_NUM_LINES },
635 { "region-size", required_argument, NULL, OPTION_SPU_LINE_SIZE },
9dcc4794
AM
636 { "fixed-space", required_argument, NULL, OPTION_SPU_FIXED_SPACE },
637 { "reserved-space", required_argument, NULL, OPTION_SPU_RESERVED_SPACE },
99302af9 638 { "extra-stack-space", required_argument, NULL, OPTION_SPU_EXTRA_STACK },
9dcc4794 639 { "no-auto-overlay", optional_argument, NULL, OPTION_SPU_NO_AUTO_OVERLAY },
9cc305ec 640 { "emit-fixups", optional_argument, NULL, OPTION_SPU_EMIT_FIXUPS },
e9f53129
AM
641'
642
643PARSE_AND_LIST_OPTIONS='
644 fprintf (file, _("\
442996ee
AM
645 --plugin Make SPU plugin.\n\
646 --no-overlays No overlay handling.\n\
a7e11ee1 647 --compact-stubs Use smaller and possibly slower call stubs.\n\
442996ee
AM
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\
9dcc4794
AM
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\
a3a219a9 658 --num-regions Number of overlay buffers (default 1).\n\
cd4a7468 659 --region-size Size of overlay buffers (default 0, auto).\n\
9dcc4794 660 --fixed-space=bytes Local store for non-overlay code and data.\n\
99302af9
AM
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\
cd4a7468
AM
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\
fb266b8b 668 --non-ia-text Allow non-icache code in icache lines.\n\
cd4a7468 669 --lrlive-analysis Scan function prologue for lr liveness.\n"
e9f53129
AM
670 ));
671'
672
673PARSE_AND_LIST_ARGS_CASES='
674 case OPTION_SPU_PLUGIN:
675 spu_elf_plugin (1);
676 break;
677
678 case OPTION_SPU_NO_OVERLAYS:
a7e11ee1
AM
679 no_overlays = 1;
680 break;
681
682 case OPTION_SPU_COMPACT_STUBS:
683 params.compact_stub = 1;
e9f53129
AM
684 break;
685
686 case OPTION_SPU_STUB_SYMS:
64615358 687 params.emit_stub_syms = 1;
e9f53129
AM
688 break;
689
690 case OPTION_SPU_NON_OVERLAY_STUBS:
64615358 691 params.non_overlay_stubs = 1;
e9f53129
AM
692 break;
693
694 case OPTION_SPU_LOCAL_STORE:
695 {
696 char *end;
64615358 697 params.local_store_lo = strtoul (optarg, &end, 0);
e9f53129
AM
698 if (*end == '\'':'\'')
699 {
64615358 700 params.local_store_hi = strtoul (end + 1, &end, 0);
e9f53129
AM
701 if (*end == 0)
702 break;
703 }
704 einfo (_("%P%F: invalid --local-store address range `%s'\''\n"), optarg);
705 }
706 break;
49fa1e15
AM
707
708 case OPTION_SPU_STACK_ANALYSIS:
64615358 709 params.stack_analysis = 1;
49fa1e15
AM
710 break;
711
712 case OPTION_SPU_STACK_SYMS:
64615358 713 params.emit_stack_syms = 1;
49fa1e15 714 break;
9dcc4794
AM
715
716 case OPTION_SPU_AUTO_OVERLAY:
64615358 717 params.auto_overlay |= 1;
9dcc4794
AM
718 if (optarg != NULL)
719 {
720 auto_overlay_file = optarg;
721 break;
722 }
723 /* Fall thru */
724
725 case OPTION_SPU_AUTO_RELINK:
64615358 726 params.auto_overlay |= 2;
9dcc4794
AM
727 break;
728
729 case OPTION_SPU_OVERLAY_RODATA:
64615358 730 params.auto_overlay |= 4;
9dcc4794
AM
731 break;
732
cd4a7468
AM
733 case OPTION_SPU_SOFT_ICACHE:
734 params.ovly_flavour = ovly_soft_icache;
cdc83fba
UW
735 /* Software i-cache stubs are always "compact". */
736 params.compact_stub = 1;
cd4a7468
AM
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
fb266b8b
AM
753 case OPTION_SPU_NON_IA_TEXT:
754 params.non_ia_text = 1;
755 break;
756
cd4a7468
AM
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:
a3a219a9
AM
771 {
772 char *end;
cd4a7468
AM
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))
a3a219a9 778 break;
cd4a7468 779 einfo (_("%P%F: invalid --line-size/--region-size `%s'\''\n"), optarg);
a3a219a9
AM
780 }
781 break;
782
9dcc4794
AM
783 case OPTION_SPU_FIXED_SPACE:
784 {
785 char *end;
64615358 786 params.auto_overlay_fixed = strtoul (optarg, &end, 0);
9dcc4794
AM
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;
64615358 795 params.auto_overlay_reserved = strtoul (optarg, &end, 0);
9dcc4794
AM
796 if (*end != 0)
797 einfo (_("%P%F: invalid --reserved-space value `%s'\''\n"), optarg);
798 }
799 break;
800
99302af9
AM
801 case OPTION_SPU_EXTRA_STACK:
802 {
803 char *end;
64615358 804 params.extra_stack_space = strtol (optarg, &end, 0);
99302af9
AM
805 if (*end != 0)
806 einfo (_("%P%F: invalid --extra-stack-space value `%s'\''\n"), optarg);
807 }
808 break;
809
9dcc4794 810 case OPTION_SPU_NO_AUTO_OVERLAY:
64615358 811 params.auto_overlay = 0;
9dcc4794
AM
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;
9cc305ec
TS
828
829 case OPTION_SPU_EMIT_FIXUPS:
830 params.emit_fixups = 1;
831 break;
e9f53129
AM
832'
833
834LDEMUL_AFTER_OPEN=spu_after_open
835LDEMUL_BEFORE_ALLOCATION=spu_before_allocation
836LDEMUL_FINISH=gld${EMULATION_NAME}_finish
9dcc4794 837LDEMUL_CHOOSE_TARGET=gld${EMULATION_NAME}_choose_target
This page took 0.342158 seconds and 4 git commands to generate.