ppc64elf.em 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932
  1. # This shell script emits a C file. -*- C -*-
  2. # Copyright (C) 2002-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 powerpc64-elf
  22. # specific routines.
  23. #
  24. fragment <<EOF
  25. #include "ldctor.h"
  26. #include "libbfd.h"
  27. #include "elf-bfd.h"
  28. #include "elf64-ppc.h"
  29. #include "ldlex.h"
  30. #include "elf/ppc64.h"
  31. static asection *ppc_add_stub_section (const char *, asection *);
  32. static void ppc_layout_sections_again (void);
  33. static struct ppc64_elf_params params = { NULL,
  34. &ppc_add_stub_section,
  35. &ppc_layout_sections_again,
  36. 1, -1, 0,
  37. ${DEFAULT_PLT_STATIC_CHAIN-0}, -1, 0,
  38. 0, -1, -1, 0};
  39. /* Fake input file for stubs. */
  40. static lang_input_statement_type *stub_file;
  41. /* Whether we need to call ppc_layout_sections_again. */
  42. static int need_laying_out = 0;
  43. /* Whether to add ".foo" entries for each "foo" in a version script. */
  44. static int dotsyms = 1;
  45. /* Whether to run tls optimization. */
  46. static int no_tls_opt = 0;
  47. /* Whether to run opd optimization. */
  48. static int no_opd_opt = 0;
  49. /* Whether to run toc optimization. */
  50. static int no_toc_opt = 0;
  51. /* Whether to sort input toc and got sections. */
  52. static int no_toc_sort = 0;
  53. /* Input .toc sections will be placed in this output section. */
  54. static const char *toc_section_name = ".got";
  55. static asection *toc_section = 0;
  56. /* This is called before the input files are opened. We create a new
  57. fake input file to hold the stub sections. */
  58. static void
  59. ppc_create_output_section_statements (void)
  60. {
  61. if (!(bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour
  62. && elf_object_id (link_info.output_bfd) == PPC64_ELF_DATA))
  63. return;
  64. link_info.wrap_char = '.';
  65. stub_file = lang_add_input_file ("linker stubs",
  66. lang_input_file_is_fake_enum,
  67. NULL);
  68. stub_file->the_bfd = bfd_create ("linker stubs", link_info.output_bfd);
  69. if (stub_file->the_bfd == NULL
  70. || !bfd_set_arch_mach (stub_file->the_bfd,
  71. bfd_get_arch (link_info.output_bfd),
  72. bfd_get_mach (link_info.output_bfd)))
  73. {
  74. einfo ("%F%P: can not create BFD: %E\n");
  75. return;
  76. }
  77. stub_file->the_bfd->flags |= BFD_LINKER_CREATED;
  78. ldlang_add_file (stub_file);
  79. params.stub_bfd = stub_file->the_bfd;
  80. if (params.save_restore_funcs < 0)
  81. params.save_restore_funcs = !bfd_link_relocatable (&link_info);
  82. if (!ppc64_elf_init_stub_bfd (&link_info, &params))
  83. einfo ("%F%P: can not init BFD: %E\n");
  84. }
  85. /* Called after opening files but before mapping sections. */
  86. static void
  87. ppc_after_open (void)
  88. {
  89. if (stub_file != NULL && link_info.relro && params.object_in_toc)
  90. {
  91. /* We have a .toc section that might be written to at run time.
  92. Don't put .toc into the .got output section. */
  93. lang_output_section_statement_type *got;
  94. got = lang_output_section_find (".got");
  95. if (got != NULL)
  96. {
  97. lang_statement_union_type *s;
  98. for (s = got->children.head; s != NULL; s = s->header.next)
  99. if (s->header.type == lang_wild_statement_enum
  100. && s->wild_statement.filename == NULL)
  101. {
  102. struct wildcard_list **i = &s->wild_statement.section_list;
  103. while (*i != NULL)
  104. if (strcmp ((*i)->spec.name, ".toc") == 0)
  105. *i = (*i)->next;
  106. else
  107. i = &(*i)->next;
  108. }
  109. /* Instead, .toc input sections will be mapped to the
  110. read/write .toc output section. If user scripts don't
  111. provide one then we'll lose toc sorting and multi-toc. */
  112. toc_section_name = ".toc";
  113. }
  114. }
  115. gld${EMULATION_NAME}_after_open ();
  116. }
  117. /* Move the input section statement at *U which happens to be on LIST
  118. to be just before *TO. */
  119. static void
  120. move_input_section (lang_statement_list_type *list,
  121. lang_statement_union_type **u,
  122. lang_statement_union_type **to)
  123. {
  124. lang_statement_union_type *s = *u;
  125. asection *i = s->input_section.section;
  126. asection *p, *n;
  127. /* Snip the input section from the statement list. If it was the
  128. last statement, fix the list tail pointer. */
  129. *u = s->header.next;
  130. if (*u == NULL)
  131. list->tail = u;
  132. /* Add it back in the new position. */
  133. s->header.next = *to;
  134. *to = s;
  135. if (list->tail == to)
  136. list->tail = &s->header.next;
  137. /* Trim I off the bfd map_head/map_tail doubly linked lists. */
  138. n = i->map_head.s;
  139. p = i->map_tail.s;
  140. (p != NULL ? p : i->output_section)->map_head.s = n;
  141. (n != NULL ? n : i->output_section)->map_tail.s = p;
  142. /* Add I back on in its new position. */
  143. if (s->header.next->header.type == lang_input_section_enum)
  144. {
  145. n = s->header.next->input_section.section;
  146. p = n->map_tail.s;
  147. }
  148. else
  149. {
  150. /* If the next statement is not an input section statement then
  151. TO must point at the previous input section statement
  152. header.next field. */
  153. lang_input_section_type *prev = (lang_input_section_type *)
  154. ((char *) to - offsetof (lang_statement_union_type, header.next));
  155. ASSERT (prev->header.type == lang_input_section_enum);
  156. p = prev->section;
  157. n = p->map_head.s;
  158. }
  159. i->map_head.s = n;
  160. i->map_tail.s = p;
  161. (p != NULL ? p : i->output_section)->map_head.s = i;
  162. (n != NULL ? n : i->output_section)->map_tail.s = i;
  163. }
  164. /* Sort input section statements in the linker script tree rooted at
  165. LIST so that those whose owning bfd happens to have a section
  166. called .init or .fini are placed first. Place any TOC sections
  167. referenced by small TOC relocs next, with TOC sections referenced
  168. only by bigtoc relocs last. */
  169. static void
  170. sort_toc_sections (lang_statement_list_type *list,
  171. lang_statement_union_type **ini,
  172. lang_statement_union_type **small)
  173. {
  174. lang_statement_union_type *s, **u;
  175. asection *i;
  176. u = &list->head;
  177. while ((s = *u) != NULL)
  178. {
  179. switch (s->header.type)
  180. {
  181. case lang_wild_statement_enum:
  182. sort_toc_sections (&s->wild_statement.children, ini, small);
  183. break;
  184. case lang_group_statement_enum:
  185. sort_toc_sections (&s->group_statement.children, ini, small);
  186. break;
  187. case lang_input_section_enum:
  188. i = s->input_section.section;
  189. /* Leave the stub_file .got where it is. We put the .got
  190. header there. */
  191. if (i->owner == stub_file->the_bfd)
  192. break;
  193. if (bfd_get_section_by_name (i->owner, ".init") != NULL
  194. || bfd_get_section_by_name (i->owner, ".fini") != NULL)
  195. {
  196. if (ini != NULL && *ini != s)
  197. {
  198. move_input_section (list, u, ini);
  199. if (small == ini)
  200. small = &s->header.next;
  201. ini = &s->header.next;
  202. continue;
  203. }
  204. if (small == ini)
  205. small = &s->header.next;
  206. ini = &s->header.next;
  207. break;
  208. }
  209. else if (ini == NULL)
  210. ini = u;
  211. if (ppc64_elf_has_small_toc_reloc (i))
  212. {
  213. if (small != NULL && *small != s)
  214. {
  215. move_input_section (list, u, small);
  216. small = &s->header.next;
  217. continue;
  218. }
  219. small = &s->header.next;
  220. }
  221. else if (small == NULL)
  222. small = u;
  223. break;
  224. default:
  225. break;
  226. }
  227. u = &s->header.next;
  228. }
  229. }
  230. static void
  231. prelim_size_sections (void)
  232. {
  233. if (expld.phase != lang_mark_phase_enum)
  234. {
  235. expld.phase = lang_mark_phase_enum;
  236. expld.dataseg.phase = exp_dataseg_none;
  237. one_lang_size_sections_pass (NULL, FALSE);
  238. /* We must not cache anything from the preliminary sizing. */
  239. lang_reset_memory_regions ();
  240. }
  241. }
  242. static void
  243. ppc_before_allocation (void)
  244. {
  245. if (stub_file != NULL)
  246. {
  247. if (!no_opd_opt
  248. && !ppc64_elf_edit_opd (&link_info))
  249. einfo ("%X%P: can not edit %s: %E\n", "opd");
  250. if (ppc64_elf_tls_setup (&link_info)
  251. && !no_tls_opt)
  252. {
  253. /* Size the sections. This is premature, but we want to know the
  254. TLS segment layout so that certain optimizations can be done. */
  255. prelim_size_sections ();
  256. if (!ppc64_elf_tls_optimize (&link_info))
  257. einfo ("%X%P: TLS problem %E\n");
  258. }
  259. if (!no_toc_opt
  260. && !bfd_link_relocatable (&link_info))
  261. {
  262. prelim_size_sections ();
  263. if (!ppc64_elf_edit_toc (&link_info))
  264. einfo ("%X%P: can not edit %s: %E\n", "toc");
  265. }
  266. if (!no_toc_sort)
  267. {
  268. lang_output_section_statement_type *toc_os;
  269. toc_os = lang_output_section_find (toc_section_name);
  270. if (toc_os != NULL)
  271. sort_toc_sections (&toc_os->children, NULL, NULL);
  272. }
  273. }
  274. gld${EMULATION_NAME}_before_allocation ();
  275. }
  276. struct hook_stub_info
  277. {
  278. lang_statement_list_type add;
  279. asection *input_section;
  280. };
  281. /* Traverse the linker tree to find the spot where the stub goes. */
  282. static bfd_boolean
  283. hook_in_stub (struct hook_stub_info *info, lang_statement_union_type **lp)
  284. {
  285. lang_statement_union_type *l;
  286. bfd_boolean ret;
  287. for (; (l = *lp) != NULL; lp = &l->header.next)
  288. {
  289. switch (l->header.type)
  290. {
  291. case lang_constructors_statement_enum:
  292. ret = hook_in_stub (info, &constructor_list.head);
  293. if (ret)
  294. return ret;
  295. break;
  296. case lang_output_section_statement_enum:
  297. ret = hook_in_stub (info,
  298. &l->output_section_statement.children.head);
  299. if (ret)
  300. return ret;
  301. break;
  302. case lang_wild_statement_enum:
  303. ret = hook_in_stub (info, &l->wild_statement.children.head);
  304. if (ret)
  305. return ret;
  306. break;
  307. case lang_group_statement_enum:
  308. ret = hook_in_stub (info, &l->group_statement.children.head);
  309. if (ret)
  310. return ret;
  311. break;
  312. case lang_input_section_enum:
  313. if (l->input_section.section == info->input_section)
  314. {
  315. /* We've found our section. Insert the stub immediately
  316. before its associated input section. */
  317. *lp = info->add.head;
  318. *(info->add.tail) = l;
  319. return TRUE;
  320. }
  321. break;
  322. case lang_data_statement_enum:
  323. case lang_reloc_statement_enum:
  324. case lang_object_symbols_statement_enum:
  325. case lang_output_statement_enum:
  326. case lang_target_statement_enum:
  327. case lang_input_statement_enum:
  328. case lang_assignment_statement_enum:
  329. case lang_padding_statement_enum:
  330. case lang_address_statement_enum:
  331. case lang_fill_statement_enum:
  332. break;
  333. default:
  334. FAIL ();
  335. break;
  336. }
  337. }
  338. return FALSE;
  339. }
  340. /* Call-back for ppc64_elf_size_stubs. */
  341. /* Create a new stub section, and arrange for it to be linked
  342. immediately before INPUT_SECTION. */
  343. static asection *
  344. ppc_add_stub_section (const char *stub_sec_name, asection *input_section)
  345. {
  346. asection *stub_sec;
  347. flagword flags;
  348. asection *output_section;
  349. lang_output_section_statement_type *os;
  350. struct hook_stub_info info;
  351. flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE
  352. | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_KEEP);
  353. stub_sec = bfd_make_section_anyway_with_flags (stub_file->the_bfd,
  354. stub_sec_name, flags);
  355. if (stub_sec == NULL
  356. || !bfd_set_section_alignment (stub_file->the_bfd, stub_sec,
  357. (params.plt_stub_align > 5
  358. ? params.plt_stub_align
  359. : 5)))
  360. goto err_ret;
  361. output_section = input_section->output_section;
  362. os = lang_output_section_get (output_section);
  363. info.input_section = input_section;
  364. lang_list_init (&info.add);
  365. lang_add_section (&info.add, stub_sec, NULL, os);
  366. if (info.add.head == NULL)
  367. goto err_ret;
  368. if (hook_in_stub (&info, &os->children.head))
  369. return stub_sec;
  370. err_ret:
  371. einfo ("%X%P: can not make stub section: %E\n");
  372. return NULL;
  373. }
  374. /* Another call-back for ppc64_elf_size_stubs. */
  375. static void
  376. ppc_layout_sections_again (void)
  377. {
  378. /* If we have changed sizes of the stub sections, then we need
  379. to recalculate all the section offsets. This may mean we need to
  380. add even more stubs. */
  381. gld${EMULATION_NAME}_map_segments (TRUE);
  382. if (!bfd_link_relocatable (&link_info))
  383. ppc64_elf_set_toc (&link_info, link_info.output_bfd);
  384. need_laying_out = -1;
  385. }
  386. static void
  387. build_toc_list (lang_statement_union_type *statement)
  388. {
  389. if (statement->header.type == lang_input_section_enum)
  390. {
  391. asection *i = statement->input_section.section;
  392. if (i->sec_info_type != SEC_INFO_TYPE_JUST_SYMS
  393. && (i->flags & SEC_EXCLUDE) == 0
  394. && i->output_section == toc_section)
  395. {
  396. if (!ppc64_elf_next_toc_section (&link_info, i))
  397. einfo ("%X%P: linker script separates .got and .toc\n");
  398. }
  399. }
  400. }
  401. static void
  402. build_section_lists (lang_statement_union_type *statement)
  403. {
  404. if (statement->header.type == lang_input_section_enum)
  405. {
  406. asection *i = statement->input_section.section;
  407. if (!((lang_input_statement_type *) i->owner->usrdata)->flags.just_syms
  408. && (i->flags & SEC_EXCLUDE) == 0
  409. && i->output_section != NULL
  410. && i->output_section->owner == link_info.output_bfd)
  411. {
  412. if (!ppc64_elf_next_input_section (&link_info, i))
  413. einfo ("%X%P: can not size stub section: %E\n");
  414. }
  415. }
  416. }
  417. /* Call the back-end function to set TOC base after we have placed all
  418. the sections. */
  419. static void
  420. gld${EMULATION_NAME}_after_allocation (void)
  421. {
  422. int ret;
  423. /* If generating a relocatable output file, then we don't have any
  424. stubs. */
  425. if (stub_file != NULL && !bfd_link_relocatable (&link_info))
  426. {
  427. ret = ppc64_elf_setup_section_lists (&link_info);
  428. if (ret < 0)
  429. einfo ("%X%P: can not size stub section: %E\n");
  430. else
  431. {
  432. ppc64_elf_start_multitoc_partition (&link_info);
  433. if (!params.no_multi_toc)
  434. {
  435. toc_section = bfd_get_section_by_name (link_info.output_bfd,
  436. toc_section_name);
  437. if (toc_section != NULL)
  438. lang_for_each_statement (build_toc_list);
  439. }
  440. if (ppc64_elf_layout_multitoc (&link_info)
  441. && !params.no_multi_toc
  442. && toc_section != NULL)
  443. lang_for_each_statement (build_toc_list);
  444. ppc64_elf_finish_multitoc_partition (&link_info);
  445. lang_for_each_statement (build_section_lists);
  446. if (!ppc64_elf_check_init_fini (&link_info))
  447. einfo ("%P: .init/.fini fragments use differing TOC pointers\n");
  448. /* Call into the BFD backend to do the real work. */
  449. if (!ppc64_elf_size_stubs (&link_info))
  450. einfo ("%X%P: can not size stub section: %E\n");
  451. }
  452. }
  453. /* We can't parse and merge .eh_frame until the glink .eh_frame has
  454. been generated. Otherwise the glink .eh_frame CIE won't be
  455. merged with other CIEs, and worse, the glink .eh_frame FDEs won't
  456. be listed in .eh_frame_hdr. */
  457. ret = bfd_elf_discard_info (link_info.output_bfd, &link_info);
  458. if (ret < 0)
  459. {
  460. einfo ("%X%P: .eh_frame/.stab edit: %E\n");
  461. return;
  462. }
  463. else if (ret > 0)
  464. need_laying_out = 1;
  465. /* Call map_segments regardless of the state of need_laying_out.
  466. need_laying_out set to -1 means we have just laid everything out,
  467. but ppc64_elf_size_stubs strips .branch_lt and .eh_frame if
  468. unneeded, after ppc_layout_sections_again. Another call removes
  469. these sections from the segment map. Their presence is
  470. innocuous except for confusing ELF_SECTION_IN_SEGMENT. */
  471. gld${EMULATION_NAME}_map_segments (need_laying_out > 0);
  472. if (need_laying_out != -1 && !bfd_link_relocatable (&link_info))
  473. ppc64_elf_set_toc (&link_info, link_info.output_bfd);
  474. }
  475. /* Final emulation specific call. */
  476. static void
  477. gld${EMULATION_NAME}_finish (void)
  478. {
  479. char *msg = NULL;
  480. char *line, *endline;
  481. /* e_entry on PowerPC64 points to the function descriptor for
  482. _start. If _start is missing, default to the first function
  483. descriptor in the .opd section. */
  484. if (stub_file != NULL
  485. && (elf_elfheader (link_info.output_bfd)->e_flags & EF_PPC64_ABI) == 1)
  486. entry_section = ".opd";
  487. if (params.emit_stub_syms < 0)
  488. params.emit_stub_syms = 1;
  489. if (stub_file != NULL
  490. && !bfd_link_relocatable (&link_info)
  491. && !ppc64_elf_build_stubs (&link_info, config.stats ? &msg : NULL))
  492. einfo ("%X%P: can not build stubs: %E\n");
  493. fflush (stdout);
  494. for (line = msg; line != NULL; line = endline)
  495. {
  496. endline = strchr (line, '\n');
  497. if (endline != NULL)
  498. *endline++ = '\0';
  499. fprintf (stderr, "%s: %s\n", program_name, line);
  500. }
  501. fflush (stderr);
  502. if (msg != NULL)
  503. free (msg);
  504. ppc64_elf_restore_symbols (&link_info);
  505. finish_default ();
  506. }
  507. /* Add a pattern matching ".foo" for every "foo" in a version script.
  508. The reason for doing this is that many shared library version
  509. scripts export a selected set of functions or data symbols, forcing
  510. others local. eg.
  511. . VERS_1 {
  512. . global:
  513. . this; that; some; thing;
  514. . local:
  515. . *;
  516. . };
  517. To make the above work for PowerPC64, we need to export ".this",
  518. ".that" and so on, otherwise only the function descriptor syms are
  519. exported. Lack of an exported function code sym may cause a
  520. definition to be pulled in from a static library. */
  521. static struct bfd_elf_version_expr *
  522. gld${EMULATION_NAME}_new_vers_pattern (struct bfd_elf_version_expr *entry)
  523. {
  524. struct bfd_elf_version_expr *dot_entry;
  525. unsigned int len;
  526. char *dot_pat;
  527. if (!dotsyms
  528. || entry->pattern[0] == '.'
  529. || (!entry->literal && entry->pattern[0] == '*'))
  530. return entry;
  531. dot_entry = xmalloc (sizeof *dot_entry);
  532. *dot_entry = *entry;
  533. dot_entry->next = entry;
  534. len = strlen (entry->pattern) + 2;
  535. dot_pat = xmalloc (len);
  536. dot_pat[0] = '.';
  537. memcpy (dot_pat + 1, entry->pattern, len - 1);
  538. dot_entry->pattern = dot_pat;
  539. dot_entry->script = 1;
  540. return dot_entry;
  541. }
  542. /* Avoid processing the fake stub_file in vercheck, stat_needed and
  543. check_needed routines. */
  544. static void (*real_func) (lang_input_statement_type *);
  545. static void ppc_for_each_input_file_wrapper (lang_input_statement_type *l)
  546. {
  547. if (l != stub_file)
  548. (*real_func) (l);
  549. }
  550. static void
  551. ppc_lang_for_each_input_file (void (*func) (lang_input_statement_type *))
  552. {
  553. real_func = func;
  554. lang_for_each_input_file (&ppc_for_each_input_file_wrapper);
  555. }
  556. #define lang_for_each_input_file ppc_lang_for_each_input_file
  557. EOF
  558. if grep -q 'ld_elf32_spu_emulation' ldemul-list.h; then
  559. fragment <<EOF
  560. /* Special handling for embedded SPU executables. */
  561. extern bfd_boolean embedded_spu_file (lang_input_statement_type *, const char *);
  562. static bfd_boolean gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *);
  563. static bfd_boolean
  564. ppc64_recognized_file (lang_input_statement_type *entry)
  565. {
  566. if (embedded_spu_file (entry, "-m64"))
  567. return TRUE;
  568. return gld${EMULATION_NAME}_load_symbols (entry);
  569. }
  570. EOF
  571. LDEMUL_RECOGNIZED_FILE=ppc64_recognized_file
  572. fi
  573. # Define some shell vars to insert bits of code into the standard elf
  574. # parse_args and list_options functions.
  575. #
  576. PARSE_AND_LIST_PROLOGUE=${PARSE_AND_LIST_PROLOGUE}'
  577. #define OPTION_STUBGROUP_SIZE 321
  578. #define OPTION_PLT_STATIC_CHAIN (OPTION_STUBGROUP_SIZE + 1)
  579. #define OPTION_NO_PLT_STATIC_CHAIN (OPTION_PLT_STATIC_CHAIN + 1)
  580. #define OPTION_PLT_THREAD_SAFE (OPTION_NO_PLT_STATIC_CHAIN + 1)
  581. #define OPTION_NO_PLT_THREAD_SAFE (OPTION_PLT_THREAD_SAFE + 1)
  582. #define OPTION_PLT_ALIGN (OPTION_NO_PLT_THREAD_SAFE + 1)
  583. #define OPTION_NO_PLT_ALIGN (OPTION_PLT_ALIGN + 1)
  584. #define OPTION_STUBSYMS (OPTION_NO_PLT_ALIGN + 1)
  585. #define OPTION_NO_STUBSYMS (OPTION_STUBSYMS + 1)
  586. #define OPTION_SAVRES (OPTION_NO_STUBSYMS + 1)
  587. #define OPTION_NO_SAVRES (OPTION_SAVRES + 1)
  588. #define OPTION_DOTSYMS (OPTION_NO_SAVRES + 1)
  589. #define OPTION_NO_DOTSYMS (OPTION_DOTSYMS + 1)
  590. #define OPTION_NO_TLS_OPT (OPTION_NO_DOTSYMS + 1)
  591. #define OPTION_TLS_GET_ADDR_OPT (OPTION_NO_TLS_OPT + 1)
  592. #define OPTION_NO_TLS_GET_ADDR_OPT (OPTION_TLS_GET_ADDR_OPT + 1)
  593. #define OPTION_NO_OPD_OPT (OPTION_NO_TLS_GET_ADDR_OPT + 1)
  594. #define OPTION_NO_TOC_OPT (OPTION_NO_OPD_OPT + 1)
  595. #define OPTION_NO_MULTI_TOC (OPTION_NO_TOC_OPT + 1)
  596. #define OPTION_NO_TOC_SORT (OPTION_NO_MULTI_TOC + 1)
  597. #define OPTION_NON_OVERLAPPING_OPD (OPTION_NO_TOC_SORT + 1)
  598. '
  599. PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}'
  600. { "stub-group-size", required_argument, NULL, OPTION_STUBGROUP_SIZE },
  601. { "plt-static-chain", no_argument, NULL, OPTION_PLT_STATIC_CHAIN },
  602. { "no-plt-static-chain", no_argument, NULL, OPTION_NO_PLT_STATIC_CHAIN },
  603. { "plt-thread-safe", no_argument, NULL, OPTION_PLT_THREAD_SAFE },
  604. { "no-plt-thread-safe", no_argument, NULL, OPTION_NO_PLT_THREAD_SAFE },
  605. { "plt-align", optional_argument, NULL, OPTION_PLT_ALIGN },
  606. { "no-plt-align", no_argument, NULL, OPTION_NO_PLT_ALIGN },
  607. { "emit-stub-syms", no_argument, NULL, OPTION_STUBSYMS },
  608. { "no-emit-stub-syms", no_argument, NULL, OPTION_NO_STUBSYMS },
  609. { "dotsyms", no_argument, NULL, OPTION_DOTSYMS },
  610. { "no-dotsyms", no_argument, NULL, OPTION_NO_DOTSYMS },
  611. { "save-restore-funcs", no_argument, NULL, OPTION_SAVRES },
  612. { "no-save-restore-funcs", no_argument, NULL, OPTION_NO_SAVRES },
  613. { "no-tls-optimize", no_argument, NULL, OPTION_NO_TLS_OPT },
  614. { "tls-get-addr-optimize", no_argument, NULL, OPTION_TLS_GET_ADDR_OPT },
  615. { "no-tls-get-addr-optimize", no_argument, NULL, OPTION_NO_TLS_GET_ADDR_OPT },
  616. { "no-opd-optimize", no_argument, NULL, OPTION_NO_OPD_OPT },
  617. { "no-toc-optimize", no_argument, NULL, OPTION_NO_TOC_OPT },
  618. { "no-multi-toc", no_argument, NULL, OPTION_NO_MULTI_TOC },
  619. { "no-toc-sort", no_argument, NULL, OPTION_NO_TOC_SORT },
  620. { "non-overlapping-opd", no_argument, NULL, OPTION_NON_OVERLAPPING_OPD },
  621. '
  622. PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}'
  623. fprintf (file, _("\
  624. --stub-group-size=N Maximum size of a group of input sections that\n\
  625. can be handled by one stub section. A negative\n\
  626. value locates all stubs before their branches\n\
  627. (with a group size of -N), while a positive\n\
  628. value allows two groups of input sections, one\n\
  629. before, and one after each stub section.\n\
  630. Values of +/-1 indicate the linker should\n\
  631. choose suitable defaults.\n"
  632. ));
  633. fprintf (file, _("\
  634. --plt-static-chain PLT call stubs should load r11.${DEFAULT_PLT_STATIC_CHAIN- (default)}\n"
  635. ));
  636. fprintf (file, _("\
  637. --no-plt-static-chain PLT call stubs should not load r11.${DEFAULT_PLT_STATIC_CHAIN+ (default)}\n"
  638. ));
  639. fprintf (file, _("\
  640. --plt-thread-safe PLT call stubs with load-load barrier.\n"
  641. ));
  642. fprintf (file, _("\
  643. --no-plt-thread-safe PLT call stubs without barrier.\n"
  644. ));
  645. fprintf (file, _("\
  646. --plt-align [=<align>] Align PLT call stubs to fit cache lines.\n"
  647. ));
  648. fprintf (file, _("\
  649. --no-plt-align Dont'\''t align individual PLT call stubs.\n"
  650. ));
  651. fprintf (file, _("\
  652. --emit-stub-syms Label linker stubs with a symbol.\n"
  653. ));
  654. fprintf (file, _("\
  655. --no-emit-stub-syms Don'\''t label linker stubs with a symbol.\n"
  656. ));
  657. fprintf (file, _("\
  658. --dotsyms For every version pattern \"foo\" in a version\n\
  659. script, add \".foo\" so that function code\n\
  660. symbols are treated the same as function\n\
  661. descriptor symbols. Defaults to on.\n"
  662. ));
  663. fprintf (file, _("\
  664. --no-dotsyms Don'\''t do anything special in version scripts.\n"
  665. ));
  666. fprintf (file, _("\
  667. --save-restore-funcs Provide register save and restore routines used\n\
  668. by gcc -Os code. Defaults to on for normal\n\
  669. final link, off for ld -r.\n"
  670. ));
  671. fprintf (file, _("\
  672. --no-save-restore-funcs Don'\''t provide these routines.\n"
  673. ));
  674. fprintf (file, _("\
  675. --no-tls-optimize Don'\''t try to optimize TLS accesses.\n"
  676. ));
  677. fprintf (file, _("\
  678. --tls-get-addr-optimize Force use of special __tls_get_addr call.\n"
  679. ));
  680. fprintf (file, _("\
  681. --no-tls-get-addr-optimize Don'\''t use a special __tls_get_addr call.\n"
  682. ));
  683. fprintf (file, _("\
  684. --no-opd-optimize Don'\''t optimize the OPD section.\n"
  685. ));
  686. fprintf (file, _("\
  687. --no-toc-optimize Don'\''t optimize the TOC section.\n"
  688. ));
  689. fprintf (file, _("\
  690. --no-multi-toc Disallow automatic multiple toc sections.\n"
  691. ));
  692. fprintf (file, _("\
  693. --no-toc-sort Don'\''t sort TOC and GOT sections.\n"
  694. ));
  695. fprintf (file, _("\
  696. --non-overlapping-opd Canonicalize .opd, so that there are no\n\
  697. overlapping .opd entries.\n"
  698. ));
  699. '
  700. PARSE_AND_LIST_ARGS_CASES=${PARSE_AND_LIST_ARGS_CASES}'
  701. case OPTION_STUBGROUP_SIZE:
  702. {
  703. const char *end;
  704. params.group_size = bfd_scan_vma (optarg, &end, 0);
  705. if (*end)
  706. einfo (_("%P%F: invalid number `%s'\''\n"), optarg);
  707. }
  708. break;
  709. case OPTION_PLT_STATIC_CHAIN:
  710. params.plt_static_chain = 1;
  711. break;
  712. case OPTION_NO_PLT_STATIC_CHAIN:
  713. params.plt_static_chain = 0;
  714. break;
  715. case OPTION_PLT_THREAD_SAFE:
  716. params.plt_thread_safe = 1;
  717. break;
  718. case OPTION_NO_PLT_THREAD_SAFE:
  719. params.plt_thread_safe = 0;
  720. break;
  721. case OPTION_PLT_ALIGN:
  722. if (optarg != NULL)
  723. {
  724. char *end;
  725. unsigned long val = strtoul (optarg, &end, 0);
  726. if (*end || val > 8)
  727. einfo (_("%P%F: invalid --plt-align `%s'\''\n"), optarg);
  728. params.plt_stub_align = val;
  729. }
  730. else
  731. params.plt_stub_align = 5;
  732. break;
  733. case OPTION_NO_PLT_ALIGN:
  734. params.plt_stub_align = 0;
  735. break;
  736. case OPTION_STUBSYMS:
  737. params.emit_stub_syms = 1;
  738. break;
  739. case OPTION_NO_STUBSYMS:
  740. params.emit_stub_syms = 0;
  741. break;
  742. case OPTION_DOTSYMS:
  743. dotsyms = 1;
  744. break;
  745. case OPTION_NO_DOTSYMS:
  746. dotsyms = 0;
  747. break;
  748. case OPTION_SAVRES:
  749. params.save_restore_funcs = 1;
  750. break;
  751. case OPTION_NO_SAVRES:
  752. params.save_restore_funcs = 0;
  753. break;
  754. case OPTION_NO_TLS_OPT:
  755. no_tls_opt = 1;
  756. break;
  757. case OPTION_TLS_GET_ADDR_OPT:
  758. params.tls_get_addr_opt = 1;
  759. break;
  760. case OPTION_NO_TLS_GET_ADDR_OPT:
  761. params.tls_get_addr_opt = 0;
  762. break;
  763. case OPTION_NO_OPD_OPT:
  764. no_opd_opt = 1;
  765. break;
  766. case OPTION_NO_TOC_OPT:
  767. no_toc_opt = 1;
  768. break;
  769. case OPTION_NO_MULTI_TOC:
  770. params.no_multi_toc = 1;
  771. break;
  772. case OPTION_NO_TOC_SORT:
  773. no_toc_sort = 1;
  774. break;
  775. case OPTION_NON_OVERLAPPING_OPD:
  776. params.non_overlapping_opd = 1;
  777. break;
  778. case OPTION_TRADITIONAL_FORMAT:
  779. no_tls_opt = 1;
  780. params.tls_get_addr_opt = 0;
  781. no_opd_opt = 1;
  782. no_toc_opt = 1;
  783. params.no_multi_toc = 1;
  784. no_toc_sort = 1;
  785. params.plt_static_chain = 1;
  786. return FALSE;
  787. '
  788. # Put these extra ppc64elf routines in ld_${EMULATION_NAME}_emulation
  789. #
  790. LDEMUL_NEW_VERS_PATTERN=gld${EMULATION_NAME}_new_vers_pattern
  791. LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=ppc_create_output_section_statements
  792. LDEMUL_AFTER_OPEN=ppc_after_open
  793. LDEMUL_BEFORE_ALLOCATION=ppc_before_allocation
  794. LDEMUL_AFTER_ALLOCATION=gld${EMULATION_NAME}_after_allocation
  795. LDEMUL_FINISH=gld${EMULATION_NAME}_finish