spuelf.em 24 KB

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