armelf.em 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. # This shell script emits a C file. -*- C -*-
  2. # Copyright (C) 1991-2022 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 elf.em, and defines extra arm-elf
  22. # specific routines.
  23. #
  24. test -z "$TARGET2_TYPE" && TARGET2_TYPE="rel"
  25. fragment <<EOF
  26. #include "ldctor.h"
  27. #include "elf/arm.h"
  28. #include "elf32-arm.h"
  29. static struct elf32_arm_params params =
  30. {
  31. NULL, /* thumb_entry_symbol */
  32. 0, /* byteswap_code */
  33. 0${TARGET1_IS_REL}, /* target1_is_rel */
  34. "${TARGET2_TYPE}", /* target2_type */
  35. 0, /* fix_v4bx */
  36. 0, /* use_blx */
  37. BFD_ARM_VFP11_FIX_DEFAULT, /* vfp11_denorm_fix */
  38. BFD_ARM_STM32L4XX_FIX_NONE, /* stm32l4xx_fix */
  39. 0, /* no_enum_size_warning */
  40. 0, /* no_wchar_size_warning */
  41. 0, /* pic_veneer */
  42. -1, /* fix_cortex_a8 */
  43. 1, /* fix_arm1176 */
  44. -1, /* merge_exidx_entries */
  45. 0, /* cmse_implib */
  46. NULL /* in_implib_bfd */
  47. };
  48. static char *in_implib_filename = NULL;
  49. static void
  50. gld${EMULATION_NAME}_before_parse (void)
  51. {
  52. #ifndef TARGET_ /* I.e., if not generic. */
  53. ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown);
  54. #endif /* not TARGET_ */
  55. input_flags.dynamic = ${DYNAMIC_LINK-true};
  56. config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo true ; else echo false ; fi`;
  57. config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo true ; else echo false ; fi`;
  58. link_info.check_relocs_after_open_input = true;
  59. EOF
  60. if test -n "$COMMONPAGESIZE"; then
  61. fragment <<EOF
  62. link_info.relro = DEFAULT_LD_Z_RELRO;
  63. EOF
  64. fi
  65. fragment <<EOF
  66. }
  67. static void
  68. gld${EMULATION_NAME}_set_symbols (void)
  69. {
  70. /* PR 19106: The section resizing code in gldarmelf_after_allocation
  71. is effectively the same as relaxation, so prevent early memory
  72. region checks which produce bogus error messages.
  73. Note - this test has nothing to do with symbols. It is just here
  74. because this is the first emulation routine that is called after
  75. the command line has been parsed. */
  76. if (!bfd_link_relocatable (&link_info))
  77. TARGET_ENABLE_RELAXATION;
  78. }
  79. static void
  80. arm_elf_before_allocation (void)
  81. {
  82. bfd_elf32_arm_set_byteswap_code (&link_info, params.byteswap_code);
  83. /* Choose type of VFP11 erratum fix, or warn if specified fix is unnecessary
  84. due to architecture version. */
  85. bfd_elf32_arm_set_vfp11_fix (link_info.output_bfd, &link_info);
  86. /* Choose type of STM32L4XX erratum fix, or warn if specified fix is
  87. unnecessary due to architecture version. */
  88. bfd_elf32_arm_set_stm32l4xx_fix (link_info.output_bfd, &link_info);
  89. /* Auto-select Cortex-A8 erratum fix if it wasn't explicitly specified. */
  90. bfd_elf32_arm_set_cortex_a8_fix (link_info.output_bfd, &link_info);
  91. /* Ensure the output sections of veneers needing a dedicated one is not
  92. removed. */
  93. bfd_elf32_arm_keep_private_stub_output_sections (&link_info);
  94. /* We should be able to set the size of the interworking stub section. We
  95. can't do it until later if we have dynamic sections, though. */
  96. if (elf_hash_table (&link_info)->dynobj == NULL)
  97. {
  98. /* Here we rummage through the found bfds to collect glue information. */
  99. LANG_FOR_EACH_INPUT_STATEMENT (is)
  100. {
  101. /* Initialise mapping tables for code/data. */
  102. bfd_elf32_arm_init_maps (is->the_bfd);
  103. if (!bfd_elf32_arm_process_before_allocation (is->the_bfd,
  104. &link_info)
  105. || !bfd_elf32_arm_vfp11_erratum_scan (is->the_bfd, &link_info)
  106. || !bfd_elf32_arm_stm32l4xx_erratum_scan (is->the_bfd,
  107. &link_info))
  108. /* xgettext:c-format */
  109. einfo (_("%P: errors encountered processing file %s\n"),
  110. is->filename);
  111. }
  112. /* We have seen it all. Allocate it, and carry on. */
  113. bfd_elf32_arm_allocate_interworking_sections (& link_info);
  114. }
  115. /* Call the standard elf routine. */
  116. gld${EMULATION_NAME}_before_allocation ();
  117. }
  118. /* Fake input file for stubs. */
  119. static lang_input_statement_type *stub_file;
  120. /* Whether we need to call gldarm_layout_sections_again. */
  121. static int need_laying_out = 0;
  122. /* Maximum size of a group of input sections that can be handled by
  123. one stub section. A value of +/-1 indicates the bfd back-end
  124. should use a suitable default size. */
  125. static bfd_signed_vma group_size = 1;
  126. struct hook_stub_info
  127. {
  128. lang_statement_list_type add;
  129. asection *input_section;
  130. };
  131. /* Traverse the linker tree to find the spot where the stub goes. */
  132. static bool
  133. hook_in_stub (struct hook_stub_info *info, lang_statement_union_type **lp)
  134. {
  135. lang_statement_union_type *l;
  136. bool ret;
  137. for (; (l = *lp) != NULL; lp = &l->header.next)
  138. {
  139. switch (l->header.type)
  140. {
  141. case lang_constructors_statement_enum:
  142. ret = hook_in_stub (info, &constructor_list.head);
  143. if (ret)
  144. return ret;
  145. break;
  146. case lang_output_section_statement_enum:
  147. ret = hook_in_stub (info,
  148. &l->output_section_statement.children.head);
  149. if (ret)
  150. return ret;
  151. break;
  152. case lang_wild_statement_enum:
  153. ret = hook_in_stub (info, &l->wild_statement.children.head);
  154. if (ret)
  155. return ret;
  156. break;
  157. case lang_group_statement_enum:
  158. ret = hook_in_stub (info, &l->group_statement.children.head);
  159. if (ret)
  160. return ret;
  161. break;
  162. case lang_input_section_enum:
  163. if (l->input_section.section == info->input_section)
  164. {
  165. /* We've found our section. Insert the stub immediately
  166. after its associated input section. */
  167. *(info->add.tail) = l->header.next;
  168. l->header.next = info->add.head;
  169. return true;
  170. }
  171. break;
  172. case lang_data_statement_enum:
  173. case lang_reloc_statement_enum:
  174. case lang_object_symbols_statement_enum:
  175. case lang_output_statement_enum:
  176. case lang_target_statement_enum:
  177. case lang_input_statement_enum:
  178. case lang_assignment_statement_enum:
  179. case lang_padding_statement_enum:
  180. case lang_address_statement_enum:
  181. case lang_fill_statement_enum:
  182. break;
  183. default:
  184. FAIL ();
  185. break;
  186. }
  187. }
  188. return false;
  189. }
  190. /* Call-back for elf32_arm_size_stubs. */
  191. /* Create a new stub section, and arrange for it to be linked
  192. immediately after INPUT_SECTION. */
  193. static asection *
  194. elf32_arm_add_stub_section (const char * stub_sec_name,
  195. asection * output_section,
  196. asection * after_input_section,
  197. unsigned int alignment_power)
  198. {
  199. asection *stub_sec;
  200. flagword flags;
  201. lang_output_section_statement_type *os;
  202. struct hook_stub_info info;
  203. flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE
  204. | SEC_HAS_CONTENTS | SEC_RELOC | SEC_IN_MEMORY | SEC_KEEP
  205. | SEC_LINKER_CREATED);
  206. stub_sec = bfd_make_section_anyway_with_flags (stub_file->the_bfd,
  207. stub_sec_name, flags);
  208. if (stub_sec == NULL)
  209. goto err_ret;
  210. bfd_set_section_alignment (stub_sec, alignment_power);
  211. os = lang_output_section_get (output_section);
  212. info.input_section = after_input_section;
  213. lang_list_init (&info.add);
  214. lang_add_section (&info.add, stub_sec, NULL, NULL, os);
  215. if (info.add.head == NULL)
  216. goto err_ret;
  217. if (after_input_section == NULL)
  218. {
  219. lang_statement_union_type **lp = &os->children.head;
  220. lang_statement_union_type *l, *lprev = NULL;
  221. for (; (l = *lp) != NULL; lp = &l->header.next, lprev = l);
  222. if (lprev)
  223. lprev->header.next = info.add.head;
  224. else
  225. os->children.head = info.add.head;
  226. return stub_sec;
  227. }
  228. else
  229. {
  230. if (hook_in_stub (&info, &os->children.head))
  231. return stub_sec;
  232. }
  233. err_ret:
  234. einfo (_("%X%P: can not make stub section: %E\n"));
  235. return NULL;
  236. }
  237. /* Another call-back for elf_arm_size_stubs. */
  238. static void
  239. gldarm_layout_sections_again (void)
  240. {
  241. /* If we have changed sizes of the stub sections, then we need
  242. to recalculate all the section offsets. This may mean we need to
  243. add even more stubs. */
  244. ldelf_map_segments (true);
  245. need_laying_out = -1;
  246. }
  247. static void
  248. build_section_lists (lang_statement_union_type *statement)
  249. {
  250. if (statement->header.type == lang_input_section_enum)
  251. {
  252. asection *i = statement->input_section.section;
  253. if (i->sec_info_type != SEC_INFO_TYPE_JUST_SYMS
  254. && (i->flags & SEC_EXCLUDE) == 0
  255. && i->output_section != NULL
  256. && i->output_section->owner == link_info.output_bfd)
  257. elf32_arm_next_input_section (& link_info, i);
  258. }
  259. }
  260. static int
  261. compare_output_sec_vma (const void *a, const void *b)
  262. {
  263. asection *asec = *(asection **) a, *bsec = *(asection **) b;
  264. asection *aout = asec->output_section, *bout = bsec->output_section;
  265. bfd_vma avma, bvma;
  266. /* If there's no output section for some reason, compare equal. */
  267. if (!aout || !bout)
  268. return 0;
  269. avma = aout->vma + asec->output_offset;
  270. bvma = bout->vma + bsec->output_offset;
  271. if (avma > bvma)
  272. return 1;
  273. else if (avma < bvma)
  274. return -1;
  275. return 0;
  276. }
  277. static void
  278. gld${EMULATION_NAME}_after_allocation (void)
  279. {
  280. int ret;
  281. /* Build a sorted list of input text sections, then use that to process
  282. the unwind table index. */
  283. unsigned int list_size = 10;
  284. asection **sec_list = (asection **)
  285. xmalloc (list_size * sizeof (asection *));
  286. unsigned int sec_count = 0;
  287. LANG_FOR_EACH_INPUT_STATEMENT (is)
  288. {
  289. bfd *abfd = is->the_bfd;
  290. asection *sec;
  291. if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
  292. continue;
  293. for (sec = abfd->sections; sec != NULL; sec = sec->next)
  294. {
  295. asection *out_sec = sec->output_section;
  296. if (out_sec
  297. && elf_section_data (sec)
  298. && elf_section_type (sec) == SHT_PROGBITS
  299. && (elf_section_flags (sec) & SHF_EXECINSTR) != 0
  300. && (sec->flags & SEC_EXCLUDE) == 0
  301. && sec->sec_info_type != SEC_INFO_TYPE_JUST_SYMS
  302. && out_sec != bfd_abs_section_ptr)
  303. {
  304. if (sec_count == list_size)
  305. {
  306. list_size *= 2;
  307. sec_list = (asection **)
  308. xrealloc (sec_list, list_size * sizeof (asection *));
  309. }
  310. sec_list[sec_count++] = sec;
  311. }
  312. }
  313. }
  314. qsort (sec_list, sec_count, sizeof (asection *), &compare_output_sec_vma);
  315. if (elf32_arm_fix_exidx_coverage (sec_list, sec_count, &link_info,
  316. params.merge_exidx_entries))
  317. need_laying_out = 1;
  318. free (sec_list);
  319. /* bfd_elf32_discard_info just plays with debugging sections,
  320. ie. doesn't affect any code, so we can delay resizing the
  321. sections. It's likely we'll resize everything in the process of
  322. adding stubs. */
  323. ret = bfd_elf_discard_info (link_info.output_bfd, & link_info);
  324. if (ret < 0)
  325. {
  326. einfo (_("%X%P: .eh_frame/.stab edit: %E\n"));
  327. return;
  328. }
  329. else if (ret > 0)
  330. need_laying_out = 1;
  331. /* If generating a relocatable output file, then we don't
  332. have to examine the relocs. */
  333. if (stub_file != NULL && !bfd_link_relocatable (&link_info))
  334. {
  335. ret = elf32_arm_setup_section_lists (link_info.output_bfd, &link_info);
  336. if (ret != 0)
  337. {
  338. if (ret < 0)
  339. {
  340. einfo (_("%X%P: could not compute sections lists "
  341. "for stub generation: %E\n"));
  342. return;
  343. }
  344. lang_for_each_statement (build_section_lists);
  345. /* Call into the BFD backend to do the real work. */
  346. if (! elf32_arm_size_stubs (link_info.output_bfd,
  347. stub_file->the_bfd,
  348. & link_info,
  349. group_size,
  350. & elf32_arm_add_stub_section,
  351. & gldarm_layout_sections_again))
  352. {
  353. einfo (_("%X%P: can not size stub section: %E\n"));
  354. return;
  355. }
  356. }
  357. }
  358. if (need_laying_out != -1)
  359. ldelf_map_segments (need_laying_out);
  360. }
  361. static void
  362. gld${EMULATION_NAME}_finish (void)
  363. {
  364. struct bfd_link_hash_entry * h;
  365. {
  366. LANG_FOR_EACH_INPUT_STATEMENT (is)
  367. {
  368. /* Figure out where VFP11 erratum veneers (and the labels returning
  369. from same) have been placed. */
  370. bfd_elf32_arm_vfp11_fix_veneer_locations (is->the_bfd, &link_info);
  371. /* Figure out where STM32L4XX erratum veneers (and the labels returning
  372. from them) have been placed. */
  373. bfd_elf32_arm_stm32l4xx_fix_veneer_locations (is->the_bfd, &link_info);
  374. }
  375. }
  376. if (!bfd_link_relocatable (&link_info))
  377. {
  378. /* Now build the linker stubs. */
  379. if (stub_file->the_bfd->sections != NULL)
  380. {
  381. if (! elf32_arm_build_stubs (& link_info))
  382. einfo (_("%X%P: can not build stubs: %E\n"));
  383. }
  384. }
  385. finish_default ();
  386. if (params.thumb_entry_symbol)
  387. {
  388. h = bfd_link_hash_lookup (link_info.hash, params.thumb_entry_symbol,
  389. false, false, true);
  390. }
  391. else
  392. {
  393. struct elf_link_hash_entry * eh;
  394. if (!entry_symbol.name || !is_elf_hash_table (link_info.hash))
  395. return;
  396. h = bfd_link_hash_lookup (link_info.hash, entry_symbol.name,
  397. false, false, true);
  398. eh = (struct elf_link_hash_entry *)h;
  399. if (!h || ARM_GET_SYM_BRANCH_TYPE (eh->target_internal)
  400. != ST_BRANCH_TO_THUMB)
  401. return;
  402. }
  403. if (h != (struct bfd_link_hash_entry *) NULL
  404. && (h->type == bfd_link_hash_defined
  405. || h->type == bfd_link_hash_defweak)
  406. && h->u.def.section->output_section != NULL)
  407. {
  408. static char buffer[32];
  409. bfd_vma val;
  410. /* Special procesing is required for a Thumb entry symbol. The
  411. bottom bit of its address must be set. */
  412. val = (h->u.def.value
  413. + bfd_section_vma (h->u.def.section->output_section)
  414. + h->u.def.section->output_offset);
  415. val |= 1;
  416. /* Now convert this value into a string and store it in entry_symbol
  417. where the lang_finish() function will pick it up. */
  418. buffer[0] = '0';
  419. buffer[1] = 'x';
  420. sprintf_vma (buffer + 2, val);
  421. if (params.thumb_entry_symbol != NULL && entry_symbol.name != NULL
  422. && entry_from_cmdline)
  423. einfo (_("%P: warning: '--thumb-entry %s' is overriding '-e %s'\n"),
  424. params.thumb_entry_symbol, entry_symbol.name);
  425. entry_symbol.name = buffer;
  426. }
  427. else
  428. einfo (_("%P: warning: cannot find thumb start symbol %s\n"),
  429. h->root.string);
  430. }
  431. /* This is a convenient point to tell BFD about target specific flags.
  432. After the output has been created, but before inputs are read. */
  433. static void
  434. arm_elf_create_output_section_statements (void)
  435. {
  436. if (strstr (bfd_get_target (link_info.output_bfd), "arm") == NULL)
  437. {
  438. /* The arm backend needs special fields in the output hash structure.
  439. These will only be created if the output format is an arm format,
  440. hence we do not support linking and changing output formats at the
  441. same time. Use a link followed by objcopy to change output formats. */
  442. einfo (_("%F%P: error: cannot change output format "
  443. "whilst linking %s binaries\n"), "ARM");
  444. return;
  445. }
  446. if (in_implib_filename)
  447. {
  448. params.in_implib_bfd = bfd_openr (in_implib_filename,
  449. bfd_get_target (link_info.output_bfd));
  450. if (params.in_implib_bfd == NULL)
  451. einfo (_("%F%P: %s: can't open: %E\n"), in_implib_filename);
  452. if (!bfd_check_format (params.in_implib_bfd, bfd_object))
  453. einfo (_("%F%P: %s: not a relocatable file: %E\n"), in_implib_filename);
  454. }
  455. bfd_elf32_arm_set_target_params (link_info.output_bfd, &link_info, &params);
  456. stub_file = lang_add_input_file ("linker stubs",
  457. lang_input_file_is_fake_enum,
  458. NULL);
  459. stub_file->the_bfd = bfd_create ("linker stubs", link_info.output_bfd);
  460. if (stub_file->the_bfd == NULL
  461. || ! bfd_set_arch_mach (stub_file->the_bfd,
  462. bfd_get_arch (link_info.output_bfd),
  463. bfd_get_mach (link_info.output_bfd)))
  464. {
  465. einfo (_("%F%P: can not create BFD: %E\n"));
  466. return;
  467. }
  468. stub_file->the_bfd->flags |= BFD_LINKER_CREATED;
  469. ldlang_add_file (stub_file);
  470. /* Also use the stub file for stubs placed in a single output section. */
  471. bfd_elf32_arm_add_glue_sections_to_bfd (stub_file->the_bfd, &link_info);
  472. bfd_elf32_arm_get_bfd_for_interworking (stub_file->the_bfd, &link_info);
  473. }
  474. EOF
  475. # Define some shell vars to insert bits of code into the standard elf
  476. # parse_args and list_options functions.
  477. #
  478. PARSE_AND_LIST_PROLOGUE='
  479. #define OPTION_THUMB_ENTRY 301
  480. #define OPTION_BE8 302
  481. #define OPTION_TARGET1_REL 303
  482. #define OPTION_TARGET1_ABS 304
  483. #define OPTION_TARGET2 305
  484. #define OPTION_FIX_V4BX 306
  485. #define OPTION_USE_BLX 307
  486. #define OPTION_VFP11_DENORM_FIX 308
  487. #define OPTION_NO_ENUM_SIZE_WARNING 309
  488. #define OPTION_PIC_VENEER 310
  489. #define OPTION_FIX_V4BX_INTERWORKING 311
  490. #define OPTION_STUBGROUP_SIZE 312
  491. #define OPTION_NO_WCHAR_SIZE_WARNING 313
  492. #define OPTION_FIX_CORTEX_A8 314
  493. #define OPTION_NO_FIX_CORTEX_A8 315
  494. #define OPTION_NO_MERGE_EXIDX_ENTRIES 316
  495. #define OPTION_FIX_ARM1176 317
  496. #define OPTION_NO_FIX_ARM1176 318
  497. #define OPTION_LONG_PLT 319
  498. #define OPTION_STM32L4XX_FIX 320
  499. #define OPTION_CMSE_IMPLIB 321
  500. #define OPTION_IN_IMPLIB 322
  501. '
  502. PARSE_AND_LIST_SHORTOPTS=p
  503. PARSE_AND_LIST_LONGOPTS='
  504. { "no-pipeline-knowledge", no_argument, NULL, '\'p\''},
  505. { "thumb-entry", required_argument, NULL, OPTION_THUMB_ENTRY},
  506. { "be8", no_argument, NULL, OPTION_BE8},
  507. { "target1-rel", no_argument, NULL, OPTION_TARGET1_REL},
  508. { "target1-abs", no_argument, NULL, OPTION_TARGET1_ABS},
  509. { "target2", required_argument, NULL, OPTION_TARGET2},
  510. { "fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
  511. { "fix-v4bx-interworking", no_argument, NULL, OPTION_FIX_V4BX_INTERWORKING},
  512. { "use-blx", no_argument, NULL, OPTION_USE_BLX},
  513. { "vfp11-denorm-fix", required_argument, NULL, OPTION_VFP11_DENORM_FIX},
  514. { "fix-stm32l4xx-629360", optional_argument, NULL, OPTION_STM32L4XX_FIX},
  515. { "no-enum-size-warning", no_argument, NULL, OPTION_NO_ENUM_SIZE_WARNING},
  516. { "pic-veneer", no_argument, NULL, OPTION_PIC_VENEER},
  517. { "stub-group-size", required_argument, NULL, OPTION_STUBGROUP_SIZE },
  518. { "no-wchar-size-warning", no_argument, NULL, OPTION_NO_WCHAR_SIZE_WARNING},
  519. { "fix-cortex-a8", no_argument, NULL, OPTION_FIX_CORTEX_A8 },
  520. { "no-fix-cortex-a8", no_argument, NULL, OPTION_NO_FIX_CORTEX_A8 },
  521. { "no-merge-exidx-entries", no_argument, NULL, OPTION_NO_MERGE_EXIDX_ENTRIES },
  522. { "fix-arm1176", no_argument, NULL, OPTION_FIX_ARM1176 },
  523. { "no-fix-arm1176", no_argument, NULL, OPTION_NO_FIX_ARM1176 },
  524. { "long-plt", no_argument, NULL, OPTION_LONG_PLT },
  525. { "cmse-implib", no_argument, NULL, OPTION_CMSE_IMPLIB },
  526. { "in-implib", required_argument, NULL, OPTION_IN_IMPLIB },
  527. '
  528. PARSE_AND_LIST_OPTIONS='
  529. fprintf (file, _(" --thumb-entry=<sym> Set the entry point to be Thumb symbol <sym>\n"));
  530. fprintf (file, _(" --be8 Output BE8 format image\n"));
  531. fprintf (file, _(" --target1-rel Interpret R_ARM_TARGET1 as R_ARM_REL32\n"));
  532. fprintf (file, _(" --target1-abs Interpret R_ARM_TARGET1 as R_ARM_ABS32\n"));
  533. fprintf (file, _(" --target2=<type> Specify definition of R_ARM_TARGET2\n"));
  534. fprintf (file, _(" --fix-v4bx Rewrite BX rn as MOV pc, rn for ARMv4\n"));
  535. fprintf (file, _(" --fix-v4bx-interworking Rewrite BX rn branch to ARMv4 interworking veneer\n"));
  536. fprintf (file, _(" --use-blx Enable use of BLX instructions\n"));
  537. fprintf (file, _(" --vfp11-denorm-fix Specify how to fix VFP11 denorm erratum\n"));
  538. fprintf (file, _(" --fix-stm32l4xx-629360 Specify how to fix STM32L4XX 629360 erratum\n"));
  539. fprintf (file, _(" --no-enum-size-warning Don'\''t warn about objects with incompatible\n"
  540. " enum sizes\n"));
  541. fprintf (file, _(" --no-wchar-size-warning Don'\''t warn about objects with incompatible\n"
  542. " wchar_t sizes\n"));
  543. fprintf (file, _(" --pic-veneer Always generate PIC interworking veneers\n"));
  544. fprintf (file, _(" --long-plt Generate long .plt entries\n"
  545. " to handle large .plt/.got displacements\n"));
  546. fprintf (file, _(" --cmse-implib Make import library to be a secure gateway import\n"
  547. " library as per ARMv8-M Security Extensions\n"));
  548. fprintf (file, _(" --in-implib Import library whose symbols address must\n"
  549. " remain stable\n"));
  550. fprintf (file, _("\
  551. --stub-group-size=N Maximum size of a group of input sections that\n\
  552. can be handled by one stub section. A negative\n\
  553. value locates all stubs after their branches\n\
  554. (with a group size of -N), while a positive\n\
  555. value allows two groups of input sections, one\n\
  556. before, and one after each stub section.\n\
  557. Values of +/-1 indicate the linker should\n\
  558. choose suitable defaults.\n"));
  559. fprintf (file, _(" --[no-]fix-cortex-a8 Disable/enable Cortex-A8 Thumb-2 branch erratum fix\n"));
  560. fprintf (file, _(" --no-merge-exidx-entries Disable merging exidx entries\n"));
  561. fprintf (file, _(" --[no-]fix-arm1176 Disable/enable ARM1176 BLX immediate erratum fix\n"));
  562. '
  563. PARSE_AND_LIST_ARGS_CASES='
  564. case '\'p\'':
  565. /* Only here for backwards compatibility. */
  566. break;
  567. case OPTION_THUMB_ENTRY:
  568. params.thumb_entry_symbol = optarg;
  569. break;
  570. case OPTION_BE8:
  571. params.byteswap_code = 1;
  572. break;
  573. case OPTION_TARGET1_REL:
  574. params.target1_is_rel = 1;
  575. break;
  576. case OPTION_TARGET1_ABS:
  577. params.target1_is_rel = 0;
  578. break;
  579. case OPTION_TARGET2:
  580. params.target2_type = optarg;
  581. break;
  582. case OPTION_FIX_V4BX:
  583. params.fix_v4bx = 1;
  584. break;
  585. case OPTION_FIX_V4BX_INTERWORKING:
  586. params.fix_v4bx = 2;
  587. break;
  588. case OPTION_USE_BLX:
  589. params.use_blx = 1;
  590. break;
  591. case OPTION_VFP11_DENORM_FIX:
  592. if (strcmp (optarg, "none") == 0)
  593. params.vfp11_denorm_fix = BFD_ARM_VFP11_FIX_NONE;
  594. else if (strcmp (optarg, "scalar") == 0)
  595. params.vfp11_denorm_fix = BFD_ARM_VFP11_FIX_SCALAR;
  596. else if (strcmp (optarg, "vector") == 0)
  597. params.vfp11_denorm_fix = BFD_ARM_VFP11_FIX_VECTOR;
  598. else
  599. einfo (_("%P: unrecognized VFP11 fix type '\''%s'\''\n"), optarg);
  600. break;
  601. case OPTION_STM32L4XX_FIX:
  602. if (!optarg)
  603. params.stm32l4xx_fix = BFD_ARM_STM32L4XX_FIX_DEFAULT;
  604. else if (strcmp (optarg, "none") == 0)
  605. params.stm32l4xx_fix = BFD_ARM_STM32L4XX_FIX_NONE;
  606. else if (strcmp (optarg, "default") == 0)
  607. params.stm32l4xx_fix = BFD_ARM_STM32L4XX_FIX_DEFAULT;
  608. else if (strcmp (optarg, "all") == 0)
  609. params.stm32l4xx_fix = BFD_ARM_STM32L4XX_FIX_ALL;
  610. else
  611. einfo (_("%P: unrecognized STM32L4XX fix type '\''%s'\''\n"), optarg);
  612. break;
  613. case OPTION_NO_ENUM_SIZE_WARNING:
  614. params.no_enum_size_warning = 1;
  615. break;
  616. case OPTION_NO_WCHAR_SIZE_WARNING:
  617. params.no_wchar_size_warning = 1;
  618. break;
  619. case OPTION_PIC_VENEER:
  620. params.pic_veneer = 1;
  621. break;
  622. case OPTION_STUBGROUP_SIZE:
  623. {
  624. const char *end;
  625. group_size = bfd_scan_vma (optarg, &end, 0);
  626. if (*end)
  627. einfo (_("%F%P: invalid number `%s'\''\n"), optarg);
  628. }
  629. break;
  630. case OPTION_FIX_CORTEX_A8:
  631. params.fix_cortex_a8 = 1;
  632. break;
  633. case OPTION_NO_FIX_CORTEX_A8:
  634. params.fix_cortex_a8 = 0;
  635. break;
  636. case OPTION_NO_MERGE_EXIDX_ENTRIES:
  637. params.merge_exidx_entries = 0;
  638. break;
  639. case OPTION_FIX_ARM1176:
  640. params.fix_arm1176 = 1;
  641. break;
  642. case OPTION_NO_FIX_ARM1176:
  643. params.fix_arm1176 = 0;
  644. break;
  645. case OPTION_LONG_PLT:
  646. bfd_elf32_arm_use_long_plt ();
  647. break;
  648. case OPTION_CMSE_IMPLIB:
  649. params.cmse_implib = 1;
  650. break;
  651. case OPTION_IN_IMPLIB:
  652. in_implib_filename = optarg;
  653. break;
  654. '
  655. # We have our own before_allocation etc. functions, but they call
  656. # the standard routines, so give them a different name.
  657. LDEMUL_BEFORE_ALLOCATION=arm_elf_before_allocation
  658. LDEMUL_AFTER_ALLOCATION=gld${EMULATION_NAME}_after_allocation
  659. LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=arm_elf_create_output_section_statements
  660. # Replace the elf before_parse function with our own.
  661. LDEMUL_BEFORE_PARSE=gld"${EMULATION_NAME}"_before_parse
  662. LDEMUL_SET_SYMBOLS=gld"${EMULATION_NAME}"_set_symbols
  663. # Call the extra arm-elf function
  664. LDEMUL_FINISH=gld${EMULATION_NAME}_finish