elf32-ft32.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. /* ft32-specific support for 32-bit ELF.
  2. Copyright (C) 2013-2022 Free Software Foundation, Inc.
  3. Copied from elf32-moxie.c which is..
  4. Copyright (C) 2009-2022 Free Software Foundation, Inc.
  5. Free Software Foundation, Inc.
  6. This file is part of BFD, the Binary File Descriptor library.
  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
  9. the Free Software Foundation; either version 3 of the License, or
  10. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  18. MA 02110-1301, USA. */
  19. #include "sysdep.h"
  20. #include "bfd.h"
  21. #include "libbfd.h"
  22. #include "elf-bfd.h"
  23. #include "elf/ft32.h"
  24. #include "opcode/ft32.h"
  25. static bool debug_relax = false;
  26. static bfd_reloc_status_type
  27. bfd_elf_ft32_diff_reloc (bfd *, arelent *, asymbol *, void *,
  28. asection *, bfd *, char **);
  29. static reloc_howto_type ft32_elf_howto_table [] =
  30. {
  31. /* This reloc does nothing. */
  32. HOWTO (R_FT32_NONE, /* type */
  33. 0, /* rightshift */
  34. 2, /* size (0 = byte, 1 = short, 2 = long) */
  35. 32, /* bitsize */
  36. false, /* pc_relative */
  37. 0, /* bitpos */
  38. complain_overflow_bitfield, /* complain_on_overflow */
  39. bfd_elf_generic_reloc, /* special_function */
  40. "R_FT32_NONE", /* name */
  41. false, /* partial_inplace */
  42. 0, /* src_mask */
  43. 0, /* dst_mask */
  44. false), /* pcrel_offset */
  45. /* A 32 bit absolute relocation. */
  46. HOWTO (R_FT32_32, /* type */
  47. 0, /* rightshift */
  48. 2, /* size (0 = byte, 1 = short, 2 = long) */
  49. 32, /* bitsize */
  50. false, /* pc_relative */
  51. 0, /* bitpos */
  52. complain_overflow_bitfield, /* complain_on_overflow */
  53. bfd_elf_generic_reloc, /* special_function */
  54. "R_FT32_32", /* name */
  55. false, /* partial_inplace */
  56. 0x00000000, /* src_mask */
  57. 0xffffffff, /* dst_mask */
  58. false), /* pcrel_offset */
  59. HOWTO (R_FT32_16, /* type */
  60. 0, /* rightshift */
  61. 1, /* size (0 = byte, 1 = short, 2 = long) */
  62. 16, /* bitsize */
  63. false, /* pc_relative */
  64. 0, /* bitpos */
  65. complain_overflow_dont, /* complain_on_overflow */
  66. bfd_elf_generic_reloc, /* special_function */
  67. "R_FT32_16", /* name */
  68. false, /* partial_inplace */
  69. 0x00000000, /* src_mask */
  70. 0x0000ffff, /* dst_mask */
  71. false), /* pcrel_offset */
  72. HOWTO (R_FT32_8, /* type */
  73. 0, /* rightshift */
  74. 0, /* size (0 = byte, 1 = short, 2 = long) */
  75. 8, /* bitsize */
  76. false, /* pc_relative */
  77. 0, /* bitpos */
  78. complain_overflow_signed, /* complain_on_overflow */
  79. bfd_elf_generic_reloc, /* special_function */
  80. "R_FT32_8", /* name */
  81. false, /* partial_inplace */
  82. 0x00000000, /* src_mask */
  83. 0x000000ff, /* dst_mask */
  84. false), /* pcrel_offset */
  85. HOWTO (R_FT32_10, /* type */
  86. 0, /* rightshift */
  87. 1, /* size (0 = byte, 1 = short, 2 = long) */
  88. 10, /* bitsize */
  89. false, /* pc_relative */
  90. 4, /* bitpos */
  91. complain_overflow_bitfield, /* complain_on_overflow */
  92. bfd_elf_generic_reloc, /* special_function */
  93. "R_FT32_10", /* name */
  94. false, /* partial_inplace */
  95. 0x00000000, /* src_mask */
  96. 0x00003ff0, /* dst_mask */
  97. false), /* pcrel_offset */
  98. HOWTO (R_FT32_20, /* type */
  99. 0, /* rightshift */
  100. 2, /* size (0 = byte, 1 = short, 2 = long) */
  101. 20, /* bitsize */
  102. false, /* pc_relative */
  103. 0, /* bitpos */
  104. complain_overflow_dont, /* complain_on_overflow */
  105. bfd_elf_generic_reloc, /* special_function */
  106. "R_FT32_20", /* name */
  107. false, /* partial_inplace */
  108. 0x00000000, /* src_mask */
  109. 0x000fffff, /* dst_mask */
  110. false), /* pcrel_offset */
  111. HOWTO (R_FT32_17, /* type */
  112. 0, /* rightshift */
  113. 2, /* size (0 = byte, 1 = short, 2 = long) */
  114. 17, /* bitsize */
  115. false, /* pc_relative */
  116. 0, /* bitpos */
  117. complain_overflow_dont, /* complain_on_overflow */
  118. bfd_elf_generic_reloc, /* special_function */
  119. "R_FT32_17", /* name */
  120. false, /* partial_inplace */
  121. 0x00000000, /* src_mask */
  122. 0x0001ffff, /* dst_mask */
  123. false), /* pcrel_offset */
  124. HOWTO (R_FT32_18, /* type */
  125. 2, /* rightshift */
  126. 2, /* size (0 = byte, 1 = short, 2 = long) */
  127. 18, /* bitsize */
  128. false, /* pc_relative */
  129. 0, /* bitpos */
  130. complain_overflow_dont, /* complain_on_overflow */
  131. bfd_elf_generic_reloc, /* special_function */
  132. "R_FT32_18", /* name */
  133. false, /* partial_inplace */
  134. 0x00000000, /* src_mask */
  135. 0x0003ffff, /* dst_mask */
  136. false), /* pcrel_offset */
  137. HOWTO (R_FT32_RELAX, /* type */
  138. 0, /* rightshift */
  139. 1, /* size (0 = byte, 1 = short, 2 = long) */
  140. 10, /* bitsize */
  141. false, /* pc_relative */
  142. 4, /* bitpos */
  143. complain_overflow_signed, /* complain_on_overflow */
  144. bfd_elf_generic_reloc, /* special_function */
  145. "R_FT32_RELAX", /* name */
  146. false, /* partial_inplace */
  147. 0x00000000, /* src_mask */
  148. 0x00000000, /* dst_mask */
  149. false), /* pcrel_offset */
  150. HOWTO (R_FT32_SC0, /* type */
  151. 0, /* rightshift */
  152. 1, /* size (0 = byte, 1 = short, 2 = long) */
  153. 10, /* bitsize */
  154. false, /* pc_relative */
  155. 4, /* bitpos */
  156. complain_overflow_signed, /* complain_on_overflow */
  157. bfd_elf_generic_reloc, /* special_function */
  158. "R_FT32_SC0", /* name */
  159. false, /* partial_inplace */
  160. 0x00000000, /* src_mask */
  161. 0x00000000, /* dst_mask */
  162. false), /* pcrel_offset */
  163. HOWTO (R_FT32_SC1, /* type */
  164. 2, /* rightshift */
  165. 2, /* size (0 = byte, 1 = short, 2 = long) */
  166. 22, /* bitsize */
  167. true, /* pc_relative */
  168. 7, /* bitpos */
  169. complain_overflow_dont, /* complain_on_overflow */
  170. bfd_elf_generic_reloc, /* special_function */
  171. "R_FT32_SC1", /* name */
  172. true, /* partial_inplace */
  173. 0x07ffff80, /* src_mask */
  174. 0x07ffff80, /* dst_mask */
  175. false), /* pcrel_offset */
  176. HOWTO (R_FT32_15, /* type */
  177. 0, /* rightshift */
  178. 2, /* size (0 = byte, 1 = short, 2 = long) */
  179. 15, /* bitsize */
  180. false, /* pc_relative */
  181. 0, /* bitpos */
  182. complain_overflow_dont, /* complain_on_overflow */
  183. bfd_elf_generic_reloc, /* special_function */
  184. "R_FT32_15", /* name */
  185. false, /* partial_inplace */
  186. 0x00000000, /* src_mask */
  187. 0x00007fff, /* dst_mask */
  188. false), /* pcrel_offset */
  189. HOWTO (R_FT32_DIFF32, /* type */
  190. 0, /* rightshift */
  191. 2, /* size (0 = byte, 1 = short, 2 = long) */
  192. 32, /* bitsize */
  193. false, /* pc_relative */
  194. 0, /* bitpos */
  195. complain_overflow_dont, /* complain_on_overflow */
  196. bfd_elf_ft32_diff_reloc, /* special_function */
  197. "R_FT32_DIFF32", /* name */
  198. false, /* partial_inplace */
  199. 0, /* src_mask */
  200. 0xffffffff, /* dst_mask */
  201. false), /* pcrel_offset */
  202. };
  203. /* Map BFD reloc types to FT32 ELF reloc types. */
  204. struct ft32_reloc_map
  205. {
  206. bfd_reloc_code_real_type bfd_reloc_val;
  207. unsigned int ft32_reloc_val;
  208. };
  209. static const struct ft32_reloc_map ft32_reloc_map [] =
  210. {
  211. { BFD_RELOC_NONE, R_FT32_NONE },
  212. { BFD_RELOC_32, R_FT32_32 },
  213. { BFD_RELOC_16, R_FT32_16 },
  214. { BFD_RELOC_8, R_FT32_8 },
  215. { BFD_RELOC_FT32_10, R_FT32_10 },
  216. { BFD_RELOC_FT32_20, R_FT32_20 },
  217. { BFD_RELOC_FT32_17, R_FT32_17 },
  218. { BFD_RELOC_FT32_18, R_FT32_18 },
  219. { BFD_RELOC_FT32_RELAX, R_FT32_RELAX },
  220. { BFD_RELOC_FT32_SC0, R_FT32_SC0 },
  221. { BFD_RELOC_FT32_SC1, R_FT32_SC1 },
  222. { BFD_RELOC_FT32_15, R_FT32_15 },
  223. { BFD_RELOC_FT32_DIFF32, R_FT32_DIFF32 },
  224. };
  225. /* Perform a diff relocation. Nothing to do, as the difference value is
  226. already written into the section's contents. */
  227. static bfd_reloc_status_type
  228. bfd_elf_ft32_diff_reloc (bfd *abfd ATTRIBUTE_UNUSED,
  229. arelent *reloc_entry ATTRIBUTE_UNUSED,
  230. asymbol *symbol ATTRIBUTE_UNUSED,
  231. void *data ATTRIBUTE_UNUSED,
  232. asection *input_section ATTRIBUTE_UNUSED,
  233. bfd *output_bfd ATTRIBUTE_UNUSED,
  234. char **error_message ATTRIBUTE_UNUSED)
  235. {
  236. return bfd_reloc_ok;
  237. }
  238. static reloc_howto_type *
  239. ft32_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  240. bfd_reloc_code_real_type code)
  241. {
  242. unsigned int i;
  243. for (i = 0; i < sizeof (ft32_reloc_map) / sizeof (ft32_reloc_map[0]); i++)
  244. if (ft32_reloc_map [i].bfd_reloc_val == code)
  245. return & ft32_elf_howto_table [ft32_reloc_map[i].ft32_reloc_val];
  246. return NULL;
  247. }
  248. static reloc_howto_type *
  249. ft32_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name)
  250. {
  251. unsigned int i;
  252. for (i = 0;
  253. i < sizeof (ft32_elf_howto_table) / sizeof (ft32_elf_howto_table[0]);
  254. i++)
  255. if (ft32_elf_howto_table[i].name != NULL
  256. && strcasecmp (ft32_elf_howto_table[i].name, r_name) == 0)
  257. return &ft32_elf_howto_table[i];
  258. return NULL;
  259. }
  260. /* Set the howto pointer for an FT32 ELF reloc. */
  261. static bool
  262. ft32_info_to_howto_rela (bfd *abfd,
  263. arelent *cache_ptr,
  264. Elf_Internal_Rela *dst)
  265. {
  266. unsigned int r_type;
  267. r_type = ELF32_R_TYPE (dst->r_info);
  268. if (r_type >= (unsigned int) R_FT32_max)
  269. {
  270. /* xgettext:c-format */
  271. _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
  272. abfd, r_type);
  273. bfd_set_error (bfd_error_bad_value);
  274. return false;
  275. }
  276. cache_ptr->howto = & ft32_elf_howto_table [r_type];
  277. return cache_ptr->howto != NULL;
  278. }
  279. /* Relocate an FT32 ELF section.
  280. The RELOCATE_SECTION function is called by the new ELF backend linker
  281. to handle the relocations for a section.
  282. The relocs are always passed as Rela structures; if the section
  283. actually uses Rel structures, the r_addend field will always be
  284. zero.
  285. This function is responsible for adjusting the section contents as
  286. necessary, and (if using Rela relocs and generating a relocatable
  287. output file) adjusting the reloc addend as necessary.
  288. This function does not have to worry about setting the reloc
  289. address or the reloc symbol index.
  290. LOCAL_SYMS is a pointer to the swapped in local symbols.
  291. LOCAL_SECTIONS is an array giving the section in the input file
  292. corresponding to the st_shndx field of each local symbol.
  293. The global hash table entry for the global symbols can be found
  294. via elf_sym_hashes (input_bfd).
  295. When generating relocatable output, this function must handle
  296. STB_LOCAL/STT_SECTION symbols specially. The output symbol is
  297. going to be the section symbol corresponding to the output
  298. section, which means that the addend must be adjusted
  299. accordingly. */
  300. static int
  301. ft32_elf_relocate_section (bfd *output_bfd,
  302. struct bfd_link_info *info,
  303. bfd *input_bfd,
  304. asection *input_section,
  305. bfd_byte *contents,
  306. Elf_Internal_Rela *relocs,
  307. Elf_Internal_Sym *local_syms,
  308. asection **local_sections)
  309. {
  310. Elf_Internal_Shdr *symtab_hdr;
  311. struct elf_link_hash_entry **sym_hashes;
  312. Elf_Internal_Rela *rel;
  313. Elf_Internal_Rela *relend;
  314. symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
  315. sym_hashes = elf_sym_hashes (input_bfd);
  316. relend = relocs + input_section->reloc_count;
  317. for (rel = relocs; rel < relend; rel ++)
  318. {
  319. reloc_howto_type *howto;
  320. unsigned long r_symndx;
  321. Elf_Internal_Sym *sym;
  322. asection *sec;
  323. struct elf_link_hash_entry *h;
  324. bfd_vma relocation;
  325. bfd_reloc_status_type r;
  326. const char *name;
  327. int r_type;
  328. r_type = ELF32_R_TYPE (rel->r_info);
  329. r_symndx = ELF32_R_SYM (rel->r_info);
  330. howto = ft32_elf_howto_table + r_type;
  331. h = NULL;
  332. sym = NULL;
  333. sec = NULL;
  334. if (r_symndx < symtab_hdr->sh_info)
  335. {
  336. sym = local_syms + r_symndx;
  337. sec = local_sections [r_symndx];
  338. relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
  339. name = bfd_elf_string_from_elf_section
  340. (input_bfd, symtab_hdr->sh_link, sym->st_name);
  341. name = name == NULL ? bfd_section_name (sec) : name;
  342. }
  343. else
  344. {
  345. bool unresolved_reloc, warned, ignored;
  346. RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
  347. r_symndx, symtab_hdr, sym_hashes,
  348. h, sec, relocation,
  349. unresolved_reloc, warned, ignored);
  350. name = h->root.root.string;
  351. }
  352. if (sec != NULL && discarded_section (sec))
  353. RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
  354. rel, 1, relend, howto, 0, contents);
  355. if (bfd_link_relocatable (info))
  356. continue;
  357. switch (howto->type)
  358. {
  359. case R_FT32_SC0:
  360. {
  361. unsigned int insn;
  362. int offset;
  363. unsigned int code15[2];
  364. insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
  365. ft32_split_shortcode (insn, code15);
  366. offset = (int)relocation;
  367. offset += (int)(rel->r_addend - rel->r_offset);
  368. offset -= (input_section->output_section->vma +
  369. input_section->output_offset);
  370. if ((offset < -1024) || (offset >= 1024))
  371. {
  372. r = bfd_reloc_outofrange;
  373. break;
  374. }
  375. code15[0] |= ((offset / 4) & 511);
  376. insn = ft32_merge_shortcode (code15);
  377. bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
  378. }
  379. r = bfd_reloc_ok;
  380. break;
  381. case R_FT32_SC1:
  382. {
  383. unsigned int insn;
  384. int offset;
  385. unsigned int code15[2];
  386. insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
  387. ft32_split_shortcode (insn, code15);
  388. offset = (int)relocation;
  389. offset += (int)(rel->r_addend - rel->r_offset);
  390. offset -= (input_section->output_section->vma +
  391. input_section->output_offset);
  392. if ((offset < -1024) || (offset >= 1024))
  393. {
  394. r = bfd_reloc_outofrange;
  395. break;
  396. }
  397. code15[1] |= ((offset / 4) & 511);
  398. insn = ft32_merge_shortcode (code15);
  399. bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
  400. }
  401. r = bfd_reloc_ok;
  402. break;
  403. case R_FT32_DIFF32:
  404. r = bfd_reloc_ok;
  405. break;
  406. default:
  407. r = _bfd_final_link_relocate (howto, input_bfd, input_section,
  408. contents, rel->r_offset,
  409. relocation, rel->r_addend);
  410. break;
  411. }
  412. if (r != bfd_reloc_ok)
  413. {
  414. const char * msg = NULL;
  415. switch (r)
  416. {
  417. case bfd_reloc_overflow:
  418. (*info->callbacks->reloc_overflow)
  419. (info, (h ? &h->root : NULL), name, howto->name,
  420. (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
  421. break;
  422. case bfd_reloc_undefined:
  423. (*info->callbacks->undefined_symbol)
  424. (info, name, input_bfd, input_section, rel->r_offset, true);
  425. break;
  426. case bfd_reloc_outofrange:
  427. msg = _("internal error: out of range error");
  428. break;
  429. case bfd_reloc_notsupported:
  430. msg = _("internal error: unsupported relocation error");
  431. break;
  432. case bfd_reloc_dangerous:
  433. msg = _("internal error: dangerous relocation");
  434. break;
  435. default:
  436. msg = _("internal error: unknown error");
  437. break;
  438. }
  439. if (msg)
  440. (*info->callbacks->warning) (info, msg, name, input_bfd,
  441. input_section, rel->r_offset);
  442. }
  443. }
  444. return true;
  445. }
  446. /* Relaxation. */
  447. static bool
  448. ft32_reloc_shortable
  449. (bfd * abfd,
  450. asection * sec,
  451. Elf_Internal_Sym * isymbuf ATTRIBUTE_UNUSED,
  452. bfd_byte * contents,
  453. bfd_vma pc ATTRIBUTE_UNUSED,
  454. Elf_Internal_Rela * irel,
  455. unsigned int * sc)
  456. {
  457. Elf_Internal_Shdr *symtab_hdr ATTRIBUTE_UNUSED;
  458. bfd_vma symval;
  459. enum elf_ft32_reloc_type r_type;
  460. reloc_howto_type *howto = NULL;
  461. unsigned int insn;
  462. int offset;
  463. bfd_vma dot, value;
  464. r_type = ELF32_R_TYPE (irel->r_info);
  465. howto = &ft32_elf_howto_table [r_type];
  466. symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  467. /* Get the value of the symbol referred to by the reloc. */
  468. if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
  469. {
  470. /* A local symbol. */
  471. Elf_Internal_Sym *isym;
  472. asection *sym_sec;
  473. isym = isymbuf + ELF32_R_SYM (irel->r_info);
  474. sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
  475. symval = isym->st_value;
  476. /* If the reloc is absolute, it will not have
  477. a symbol or section associated with it. */
  478. if (sym_sec)
  479. symval += sym_sec->output_section->vma
  480. + sym_sec->output_offset;
  481. }
  482. else
  483. {
  484. unsigned long indx;
  485. struct elf_link_hash_entry *h;
  486. /* An external symbol. */
  487. indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
  488. h = elf_sym_hashes (abfd)[indx];
  489. BFD_ASSERT (h != NULL);
  490. if (h->root.type != bfd_link_hash_defined
  491. && h->root.type != bfd_link_hash_defweak)
  492. /* This appears to be a reference to an undefined
  493. symbol. Just ignore it--it will be caught by the
  494. regular reloc processing. */
  495. return false;
  496. symval = (h->root.u.def.value
  497. + h->root.u.def.section->output_section->vma
  498. + h->root.u.def.section->output_offset);
  499. }
  500. switch (r_type)
  501. {
  502. case R_FT32_8:
  503. case R_FT32_10:
  504. case R_FT32_16:
  505. case R_FT32_20:
  506. case R_FT32_RELAX:
  507. if (symval != 0)
  508. return false;
  509. insn = bfd_get_32 (abfd, contents + irel->r_offset);
  510. insn |= ((symval + irel->r_addend) << howto->bitpos) & howto->dst_mask;
  511. return ft32_shortcode (insn, sc);
  512. case R_FT32_18:
  513. insn = bfd_get_32 (abfd, contents + irel->r_offset);
  514. /* Get the address of this instruction. */
  515. dot = (sec->output_section->vma
  516. + sec->output_offset + irel->r_offset);
  517. value = symval + irel->r_addend;
  518. offset = (value - dot) / 4;
  519. if ((dot > 0x8c) && (-256 <= offset) && (offset < 256))
  520. {
  521. switch (insn)
  522. {
  523. case 0x00200000: *sc = (3 << 13) | (0 << 9); return true;
  524. case 0x00280000: *sc = (3 << 13) | (1 << 9); return true;
  525. case 0x00600000: *sc = (3 << 13) | (2 << 9); return true;
  526. case 0x00680000: *sc = (3 << 13) | (3 << 9); return true;
  527. case 0x00a00000: *sc = (3 << 13) | (4 << 9); return true;
  528. case 0x00a80000: *sc = (3 << 13) | (5 << 9); return true;
  529. case 0x00e00000: *sc = (3 << 13) | (6 << 9); return true;
  530. case 0x00e80000: *sc = (3 << 13) | (7 << 9); return true;
  531. case 0x01200000: *sc = (3 << 13) | (8 << 9); return true;
  532. case 0x01280000: *sc = (3 << 13) | (9 << 9); return true;
  533. case 0x01600000: *sc = (3 << 13) | (10 << 9); return true;
  534. case 0x01680000: *sc = (3 << 13) | (11 << 9); return true;
  535. case 0x01a00000: *sc = (3 << 13) | (12 << 9); return true;
  536. case 0x01a80000: *sc = (3 << 13) | (13 << 9); return true;
  537. case 0x00300000: *sc = (3 << 13) | (14 << 9); return true;
  538. case 0x00340000: *sc = (3 << 13) | (15 << 9); return true;
  539. default:
  540. break;
  541. }
  542. }
  543. break;
  544. default:
  545. break;
  546. }
  547. return false;
  548. }
  549. /* Returns whether the relocation type passed is a diff reloc. */
  550. static bool
  551. elf32_ft32_is_diff_reloc (Elf_Internal_Rela *irel)
  552. {
  553. return (ELF32_R_TYPE (irel->r_info) == R_FT32_DIFF32);
  554. }
  555. /* Reduce the diff value written in the section by count if the shrinked
  556. insn address happens to fall between the two symbols for which this
  557. diff reloc was emitted. */
  558. static bool
  559. elf32_ft32_adjust_diff_reloc_value (bfd *abfd,
  560. struct bfd_section *isec,
  561. Elf_Internal_Rela *irel,
  562. bfd_vma symval,
  563. bfd_vma shrinked_insn_address,
  564. int count)
  565. {
  566. unsigned char * reloc_contents = NULL;
  567. unsigned char * isec_contents = elf_section_data (isec)->this_hdr.contents;
  568. bfd_signed_vma x = 0;
  569. bfd_vma sym2_address;
  570. bfd_vma sym1_address;
  571. bfd_vma start_address;
  572. bfd_vma end_address;
  573. if (isec_contents == NULL)
  574. {
  575. if (! bfd_malloc_and_get_section (abfd, isec, &isec_contents))
  576. return false;
  577. elf_section_data (isec)->this_hdr.contents = isec_contents;
  578. }
  579. reloc_contents = isec_contents + irel->r_offset;
  580. /* Read value written in object file. */
  581. switch (ELF32_R_TYPE (irel->r_info))
  582. {
  583. case R_FT32_DIFF32:
  584. x = bfd_get_signed_32 (abfd, reloc_contents);
  585. break;
  586. default:
  587. return false;
  588. }
  589. /* For a diff reloc sym1 - sym2 the diff at assembly time (x) is written
  590. into the object file at the reloc offset. sym2's logical value is
  591. symval (<start_of_section>) + reloc addend. Compute the start and end
  592. addresses and check if the shrinked insn falls between sym1 and sym2. */
  593. sym2_address = symval + irel->r_addend;
  594. sym1_address = sym2_address - x;
  595. /* Don't assume sym2 is bigger than sym1 - the difference
  596. could be negative. Compute start and end addresses, and
  597. use those to see if they span shrinked_insn_address. */
  598. start_address = sym1_address < sym2_address ? sym1_address : sym2_address;
  599. end_address = sym1_address > sym2_address ? sym1_address : sym2_address;
  600. if (shrinked_insn_address >= start_address
  601. && shrinked_insn_address < end_address)
  602. {
  603. /* Reduce the diff value by count bytes and write it back into section
  604. contents. */
  605. bfd_signed_vma new_diff = x < 0 ? x + count : x - count;
  606. if (sym2_address > shrinked_insn_address)
  607. irel->r_addend -= count;
  608. switch (ELF32_R_TYPE (irel->r_info))
  609. {
  610. case R_FT32_DIFF32:
  611. bfd_put_signed_32 (abfd, new_diff & 0xFFFFFFFF, reloc_contents);
  612. break;
  613. default:
  614. return false;
  615. }
  616. }
  617. return true;
  618. }
  619. static bool
  620. elf32_ft32_adjust_reloc_if_spans_insn (bfd *abfd,
  621. asection *isec,
  622. Elf_Internal_Rela *irel, bfd_vma symval,
  623. bfd_vma shrinked_insn_address,
  624. bfd_vma shrink_boundary,
  625. int count)
  626. {
  627. if (elf32_ft32_is_diff_reloc (irel))
  628. {
  629. if (!elf32_ft32_adjust_diff_reloc_value (abfd, isec, irel,
  630. symval,
  631. shrinked_insn_address,
  632. count))
  633. return false;
  634. }
  635. else
  636. {
  637. bfd_vma reloc_value = symval + irel->r_addend;
  638. bool addend_within_shrink_boundary =
  639. (reloc_value <= shrink_boundary);
  640. bool reloc_spans_insn =
  641. (symval <= shrinked_insn_address
  642. && reloc_value > shrinked_insn_address
  643. && addend_within_shrink_boundary);
  644. if (! reloc_spans_insn)
  645. return true;
  646. irel->r_addend -= count;
  647. if (debug_relax)
  648. printf ("Relocation's addend needed to be fixed \n");
  649. }
  650. return true;
  651. }
  652. /* Delete some bytes from a section while relaxing. */
  653. static bool
  654. elf32_ft32_relax_delete_bytes (struct bfd_link_info *link_info, bfd * abfd,
  655. asection * sec, bfd_vma addr, int count)
  656. {
  657. Elf_Internal_Shdr *symtab_hdr;
  658. unsigned int sec_shndx;
  659. bfd_byte *contents;
  660. Elf_Internal_Rela *irel, *irelend;
  661. bfd_vma toaddr;
  662. Elf_Internal_Sym *isym;
  663. Elf_Internal_Sym *isymend;
  664. struct elf_link_hash_entry **sym_hashes;
  665. struct elf_link_hash_entry **end_hashes;
  666. struct elf_link_hash_entry **start_hashes;
  667. unsigned int symcount;
  668. Elf_Internal_Sym *isymbuf = NULL;
  669. symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  670. sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
  671. contents = elf_section_data (sec)->this_hdr.contents;
  672. toaddr = sec->size;
  673. irel = elf_section_data (sec)->relocs;
  674. irelend = irel + sec->reloc_count;
  675. /* Actually delete the bytes. */
  676. memmove (contents + addr, contents + addr + count,
  677. (size_t) (toaddr - addr - count));
  678. sec->size -= count;
  679. /* Adjust all the relocs. */
  680. for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)
  681. /* Get the new reloc address. */
  682. if ((irel->r_offset > addr && irel->r_offset < toaddr))
  683. irel->r_offset -= count;
  684. /* The reloc's own addresses are now ok. However, we need to readjust
  685. the reloc's addend, i.e. the reloc's value if two conditions are met:
  686. 1.) the reloc is relative to a symbol in this section that
  687. is located in front of the shrinked instruction
  688. 2.) symbol plus addend end up behind the shrinked instruction.
  689. The most common case where this happens are relocs relative to
  690. the section-start symbol.
  691. This step needs to be done for all of the sections of the bfd. */
  692. {
  693. struct bfd_section *isec;
  694. for (isec = abfd->sections; isec; isec = isec->next)
  695. {
  696. bfd_vma symval;
  697. bfd_vma shrinked_insn_address;
  698. if (isec->reloc_count == 0)
  699. continue;
  700. shrinked_insn_address = (sec->output_section->vma
  701. + sec->output_offset + addr - count);
  702. irel = elf_section_data (isec)->relocs;
  703. /* PR 12161: Read in the relocs for this section if necessary. */
  704. if (irel == NULL)
  705. irel = _bfd_elf_link_read_relocs (abfd, isec, NULL, NULL, true);
  706. for (irelend = irel + isec->reloc_count; irel < irelend; irel++)
  707. {
  708. /* Read this BFD's local symbols if we haven't done
  709. so already. */
  710. if (isymbuf == NULL && symtab_hdr->sh_info != 0)
  711. {
  712. isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
  713. if (isymbuf == NULL)
  714. isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
  715. symtab_hdr->sh_info, 0,
  716. NULL, NULL, NULL);
  717. if (isymbuf == NULL)
  718. return false;
  719. }
  720. /* Get the value of the symbol referred to by the reloc. */
  721. if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
  722. {
  723. /* A local symbol. */
  724. asection *sym_sec;
  725. isym = isymbuf + ELF32_R_SYM (irel->r_info);
  726. sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
  727. symval = isym->st_value;
  728. /* If the reloc is absolute, it will not have
  729. a symbol or section associated with it. */
  730. if (sym_sec == sec)
  731. {
  732. symval += sym_sec->output_section->vma
  733. + sym_sec->output_offset;
  734. if (debug_relax)
  735. printf ("Checking if the relocation's "
  736. "addend needs corrections.\n"
  737. "Address of anchor symbol: 0x%x \n"
  738. "Address of relocation target: 0x%x \n"
  739. "Address of relaxed insn: 0x%x \n",
  740. (unsigned int) symval,
  741. (unsigned int) (symval + irel->r_addend),
  742. (unsigned int) shrinked_insn_address);
  743. if (symval <= shrinked_insn_address
  744. && (symval + irel->r_addend) > shrinked_insn_address)
  745. {
  746. /* If there is an alignment boundary, we only need to
  747. adjust addends that end up below the boundary. */
  748. bfd_vma shrink_boundary = (toaddr
  749. + sec->output_section->vma
  750. + sec->output_offset);
  751. if (debug_relax)
  752. printf
  753. ("Relocation's addend needed to be fixed \n");
  754. if (!elf32_ft32_adjust_reloc_if_spans_insn (abfd, isec,
  755. irel, symval,
  756. shrinked_insn_address,
  757. shrink_boundary,
  758. count))
  759. return false;
  760. }
  761. }
  762. /* else reference symbol is absolute. No adjustment needed. */
  763. }
  764. /* else...Reference symbol is extern. No need for adjusting
  765. the addend. */
  766. }
  767. }
  768. }
  769. /* Adjust the local symbols defined in this section. */
  770. symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  771. isym = (Elf_Internal_Sym *) symtab_hdr->contents;
  772. if (isym)
  773. {
  774. for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++)
  775. {
  776. if (isym->st_shndx == sec_shndx
  777. && isym->st_value > addr && isym->st_value < toaddr)
  778. isym->st_value -= count;
  779. }
  780. }
  781. /* Now adjust the global symbols defined in this section. */
  782. symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
  783. - symtab_hdr->sh_info);
  784. sym_hashes = start_hashes = elf_sym_hashes (abfd);
  785. end_hashes = sym_hashes + symcount;
  786. for (; sym_hashes < end_hashes; sym_hashes++)
  787. {
  788. struct elf_link_hash_entry *sym_hash = *sym_hashes;
  789. /* The '--wrap SYMBOL' option is causing a pain when the object file,
  790. containing the definition of __wrap_SYMBOL, includes a direct
  791. call to SYMBOL as well. Since both __wrap_SYMBOL and SYMBOL reference
  792. the same symbol (which is __wrap_SYMBOL), but still exist as two
  793. different symbols in 'sym_hashes', we don't want to adjust
  794. the global symbol __wrap_SYMBOL twice.
  795. This check is only relevant when symbols are being wrapped. */
  796. if (link_info->wrap_hash != NULL)
  797. {
  798. struct elf_link_hash_entry **cur_sym_hashes;
  799. /* Loop only over the symbols whom been already checked. */
  800. for (cur_sym_hashes = start_hashes; cur_sym_hashes < sym_hashes;
  801. cur_sym_hashes++)
  802. /* If the current symbol is identical to 'sym_hash', that means
  803. the symbol was already adjusted (or at least checked). */
  804. if (*cur_sym_hashes == sym_hash)
  805. break;
  806. /* Don't adjust the symbol again. */
  807. if (cur_sym_hashes < sym_hashes)
  808. continue;
  809. }
  810. if ((sym_hash->root.type == bfd_link_hash_defined
  811. || sym_hash->root.type == bfd_link_hash_defweak)
  812. && sym_hash->root.u.def.section == sec
  813. && sym_hash->root.u.def.value > addr
  814. && sym_hash->root.u.def.value < toaddr)
  815. sym_hash->root.u.def.value -= count;
  816. }
  817. return true;
  818. }
  819. /* Return TRUE if LOC can be a target of a branch, jump or call. */
  820. static bool
  821. elf32_ft32_relax_is_branch_target (struct bfd_link_info *link_info,
  822. bfd * abfd, asection * sec,
  823. bfd_vma loc)
  824. {
  825. Elf_Internal_Shdr *symtab_hdr;
  826. Elf_Internal_Rela *irel, *irelend;
  827. Elf_Internal_Sym *isym;
  828. Elf_Internal_Sym *isymbuf = NULL;
  829. bfd_vma symval;
  830. struct bfd_section *isec;
  831. struct elf_link_hash_entry **sym_hashes;
  832. struct elf_link_hash_entry **end_hashes;
  833. struct elf_link_hash_entry **start_hashes;
  834. unsigned int symcount;
  835. symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  836. /* Now we check for relocations pointing to ret. */
  837. for (isec = abfd->sections; isec; isec = isec->next)
  838. {
  839. irel = elf_section_data (isec)->relocs;
  840. if (irel == NULL)
  841. irel = _bfd_elf_link_read_relocs (abfd, isec, NULL, NULL, true);
  842. irelend = irel + isec->reloc_count;
  843. for (; irel < irelend; irel++)
  844. {
  845. /* Read this BFD's local symbols if we haven't done
  846. so already. */
  847. if (isymbuf == NULL && symtab_hdr->sh_info != 0)
  848. {
  849. isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
  850. if (isymbuf == NULL)
  851. isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
  852. symtab_hdr->sh_info, 0,
  853. NULL, NULL, NULL);
  854. if (isymbuf == NULL)
  855. return false;
  856. }
  857. /* Get the value of the symbol referred to by the reloc. */
  858. if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
  859. {
  860. /* A local symbol. */
  861. asection *sym_sec;
  862. isym = isymbuf + ELF32_R_SYM (irel->r_info);
  863. sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
  864. symval = isym->st_value;
  865. /* If the reloc is absolute, it will not have
  866. a symbol or section associated with it. */
  867. if (sym_sec == sec)
  868. {
  869. symval += sym_sec->output_section->vma
  870. + sym_sec->output_offset;
  871. if (debug_relax)
  872. printf ("0x%x: Address of anchor symbol: 0x%x "
  873. "Address of relocation target: 0x%x \n",
  874. (unsigned int) irel->r_offset,
  875. (unsigned int) symval,
  876. (unsigned int) (symval + irel->r_addend));
  877. if ((irel->r_addend) == loc)
  878. return true;
  879. }
  880. }
  881. }
  882. }
  883. symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
  884. - symtab_hdr->sh_info);
  885. sym_hashes = start_hashes = elf_sym_hashes (abfd);
  886. end_hashes = sym_hashes + symcount;
  887. for (; sym_hashes < end_hashes; sym_hashes++)
  888. {
  889. struct elf_link_hash_entry *sym_hash = *sym_hashes;
  890. /* The '--wrap SYMBOL' option is causing a pain when the object file,
  891. containing the definition of __wrap_SYMBOL, includes a direct
  892. call to SYMBOL as well. Since both __wrap_SYMBOL and SYMBOL reference
  893. the same symbol (which is __wrap_SYMBOL), but still exist as two
  894. different symbols in 'sym_hashes', we don't want to adjust
  895. the global symbol __wrap_SYMBOL twice.
  896. This check is only relevant when symbols are being wrapped. */
  897. if (link_info->wrap_hash != NULL)
  898. {
  899. struct elf_link_hash_entry **cur_sym_hashes;
  900. /* Loop only over the symbols whom been already checked. */
  901. for (cur_sym_hashes = start_hashes; cur_sym_hashes < sym_hashes;
  902. cur_sym_hashes++)
  903. /* If the current symbol is identical to 'sym_hash', that means
  904. the symbol was already adjusted (or at least checked). */
  905. if (*cur_sym_hashes == sym_hash)
  906. break;
  907. /* Don't adjust the symbol again. */
  908. if (cur_sym_hashes < sym_hashes)
  909. continue;
  910. }
  911. if ((sym_hash->root.type == bfd_link_hash_defined
  912. || sym_hash->root.type == bfd_link_hash_defweak)
  913. && sym_hash->root.u.def.section == sec
  914. && sym_hash->root.u.def.value == loc)
  915. return true;
  916. }
  917. return false;
  918. }
  919. static bool
  920. ft32_elf_relax_section (bfd *abfd,
  921. asection *sec,
  922. struct bfd_link_info *link_info,
  923. bool *again)
  924. {
  925. Elf_Internal_Rela * free_relocs = NULL;
  926. Elf_Internal_Rela * internal_relocs;
  927. Elf_Internal_Rela * irelend;
  928. Elf_Internal_Rela * irel;
  929. bfd_byte * contents = NULL;
  930. Elf_Internal_Shdr * symtab_hdr;
  931. Elf_Internal_Sym * isymbuf = NULL;
  932. /* Assume nothing changes. */
  933. *again = false;
  934. /* We don't have to do anything for a relocatable link, if
  935. this section does not have relocs, or if this is not a
  936. code section. */
  937. if (bfd_link_relocatable (link_info)
  938. || (sec->flags & SEC_RELOC) == 0
  939. || sec->reloc_count == 0
  940. || (sec->flags & SEC_CODE) == 0)
  941. return true;
  942. /* Get the section contents. */
  943. if (elf_section_data (sec)->this_hdr.contents != NULL)
  944. contents = elf_section_data (sec)->this_hdr.contents;
  945. /* Go get them off disk. */
  946. else
  947. {
  948. if (! bfd_malloc_and_get_section (abfd, sec, &contents))
  949. goto error_return;
  950. elf_section_data (sec)->this_hdr.contents = contents;
  951. }
  952. symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  953. /* Read this BFD's local symbols if we haven't done so already. */
  954. if (isymbuf == NULL && symtab_hdr->sh_info != 0)
  955. {
  956. isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
  957. if (isymbuf == NULL)
  958. isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
  959. symtab_hdr->sh_info, 0,
  960. NULL, NULL, NULL);
  961. if (isymbuf == NULL)
  962. goto error_return;
  963. symtab_hdr->contents = (unsigned char *) isymbuf;
  964. }
  965. internal_relocs = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL,
  966. link_info->keep_memory);
  967. if (internal_relocs == NULL)
  968. goto error_return;
  969. if (! link_info->keep_memory)
  970. free_relocs = internal_relocs;
  971. /* Walk through them looking for relaxing opportunities. */
  972. irelend = internal_relocs + sec->reloc_count;
  973. /* Test every adjacent pair of relocs. If both have shortcodes,
  974. fuse them and delete the relocs. */
  975. irel = internal_relocs;
  976. while (irel < irelend - 1)
  977. {
  978. Elf_Internal_Rela * irel_next = irel + 1;
  979. unsigned int sc0, sc1;
  980. bfd_vma pc;
  981. pc = irel->r_offset;
  982. if (((pc + 4) == (irel_next->r_offset))
  983. && ft32_reloc_shortable (abfd, sec, isymbuf, contents, pc, irel,
  984. &sc0)
  985. && ft32_reloc_shortable (abfd, sec, isymbuf, contents, pc,
  986. irel_next, &sc1)
  987. && !elf32_ft32_relax_is_branch_target (link_info, abfd, sec,
  988. irel_next->r_offset))
  989. {
  990. unsigned int code30 = (sc1 << 15) | sc0;
  991. unsigned int code27 = code30 >> 3;
  992. unsigned int code3 = code30 & 7;
  993. static const unsigned char pat3[] = {2, 3, 4, 5, 6, 9, 10, 14};
  994. unsigned int pattern = pat3[code3];
  995. unsigned int fused = (pattern << 27) | code27;
  996. /* Move second reloc to same place as first. */
  997. irel_next->r_offset = irel->r_offset;
  998. /* Change both relocs to R_FT32_NONE. */
  999. if (ELF32_R_TYPE (irel->r_info) == R_FT32_18)
  1000. {
  1001. irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
  1002. R_FT32_SC0);
  1003. }
  1004. else
  1005. {
  1006. irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
  1007. R_FT32_NONE);
  1008. }
  1009. if (ELF32_R_TYPE (irel_next->r_info) == R_FT32_18)
  1010. {
  1011. irel_next->r_info = ELF32_R_INFO (ELF32_R_SYM (irel_next->r_info),
  1012. R_FT32_SC1);
  1013. }
  1014. else
  1015. {
  1016. irel_next->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
  1017. R_FT32_NONE);
  1018. }
  1019. /* Replace the first insn with the fused version. */
  1020. bfd_put_32 (abfd, fused, contents + irel->r_offset);
  1021. /* Delete the second insn. */
  1022. if (!elf32_ft32_relax_delete_bytes (link_info, abfd, sec,
  1023. irel->r_offset + 4, 4))
  1024. goto error_return;
  1025. /* That will change things, so, we should relax again.
  1026. Note that this is not required, and it may be slow. */
  1027. *again = true;
  1028. irel += 2;
  1029. }
  1030. else
  1031. {
  1032. irel += 1;
  1033. }
  1034. }
  1035. if (isymbuf != NULL
  1036. && symtab_hdr->contents != (unsigned char *) isymbuf)
  1037. {
  1038. if (! link_info->keep_memory)
  1039. free (isymbuf);
  1040. else
  1041. /* Cache the symbols for elf_link_input_bfd. */
  1042. symtab_hdr->contents = (unsigned char *) isymbuf;
  1043. }
  1044. if (contents != NULL
  1045. && elf_section_data (sec)->this_hdr.contents != contents)
  1046. {
  1047. if (! link_info->keep_memory)
  1048. free (contents);
  1049. else
  1050. /* Cache the section contents for elf_link_input_bfd. */
  1051. elf_section_data (sec)->this_hdr.contents = contents;
  1052. }
  1053. if (elf_section_data (sec)->relocs != internal_relocs)
  1054. free (internal_relocs);
  1055. return true;
  1056. error_return:
  1057. free (free_relocs);
  1058. return true;
  1059. }
  1060. #define ELF_ARCH bfd_arch_ft32
  1061. #define ELF_MACHINE_CODE EM_FT32
  1062. #define ELF_MAXPAGESIZE 0x1
  1063. #define TARGET_LITTLE_SYM ft32_elf32_vec
  1064. #define TARGET_LITTLE_NAME "elf32-ft32"
  1065. #define elf_info_to_howto_rel NULL
  1066. #define elf_info_to_howto ft32_info_to_howto_rela
  1067. #define elf_backend_relocate_section ft32_elf_relocate_section
  1068. #define elf_backend_can_gc_sections 1
  1069. #define elf_backend_rela_normal 1
  1070. #define bfd_elf32_bfd_reloc_type_lookup ft32_reloc_type_lookup
  1071. #define bfd_elf32_bfd_reloc_name_lookup ft32_reloc_name_lookup
  1072. #define bfd_elf32_bfd_relax_section ft32_elf_relax_section
  1073. #include "elf32-target.h"