elf32-fr30.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. /* FR30-specific support for 32-bit ELF.
  2. Copyright (C) 1998-2022 Free Software Foundation, Inc.
  3. This file is part of BFD, the Binary File Descriptor library.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  15. MA 02110-1301, USA. */
  16. #include "sysdep.h"
  17. #include "bfd.h"
  18. #include "libbfd.h"
  19. #include "elf-bfd.h"
  20. #include "elf/fr30.h"
  21. /* Forward declarations. */
  22. static bfd_reloc_status_type
  23. fr30_elf_i20_reloc (bfd *, arelent *, asymbol *, void * data,
  24. asection *, bfd *, char **error_message);
  25. static bfd_reloc_status_type
  26. fr30_elf_i32_reloc (bfd *, arelent *, asymbol *, void *,
  27. asection *, bfd *, char **);
  28. static reloc_howto_type fr30_elf_howto_table [] =
  29. {
  30. /* This reloc does nothing. */
  31. HOWTO (R_FR30_NONE, /* type */
  32. 0, /* rightshift */
  33. 3, /* size (0 = byte, 1 = short, 2 = long) */
  34. 0, /* bitsize */
  35. false, /* pc_relative */
  36. 0, /* bitpos */
  37. complain_overflow_dont, /* complain_on_overflow */
  38. bfd_elf_generic_reloc, /* special_function */
  39. "R_FR30_NONE", /* name */
  40. false, /* partial_inplace */
  41. 0, /* src_mask */
  42. 0, /* dst_mask */
  43. false), /* pcrel_offset */
  44. /* An 8 bit absolute relocation. */
  45. HOWTO (R_FR30_8, /* type */
  46. 0, /* rightshift */
  47. 1, /* size (0 = byte, 1 = short, 2 = long) */
  48. 8, /* bitsize */
  49. false, /* pc_relative */
  50. 4, /* bitpos */
  51. complain_overflow_bitfield, /* complain_on_overflow */
  52. bfd_elf_generic_reloc, /* special_function */
  53. "R_FR30_8", /* name */
  54. false, /* partial_inplace */
  55. 0x0000, /* src_mask */
  56. 0x0ff0, /* dst_mask */
  57. false), /* pcrel_offset */
  58. /* A 20 bit absolute relocation. */
  59. HOWTO (R_FR30_20, /* type */
  60. 0, /* rightshift */
  61. 2, /* size (0 = byte, 1 = short, 2 = long) */
  62. 20, /* bitsize */
  63. false, /* pc_relative */
  64. 0, /* bitpos */
  65. complain_overflow_bitfield, /* complain_on_overflow */
  66. fr30_elf_i20_reloc, /* special_function */
  67. "R_FR30_20", /* name */
  68. false, /* partial_inplace */
  69. 0x00000000, /* src_mask */
  70. 0x00f0ffff, /* dst_mask */
  71. false), /* pcrel_offset */
  72. /* A 32 bit absolute relocation. */
  73. HOWTO (R_FR30_32, /* type */
  74. 0, /* rightshift */
  75. 2, /* size (0 = byte, 1 = short, 2 = long) */
  76. 32, /* bitsize */
  77. false, /* pc_relative */
  78. 0, /* bitpos */
  79. complain_overflow_bitfield, /* complain_on_overflow */
  80. bfd_elf_generic_reloc, /* special_function */
  81. "R_FR30_32", /* name */
  82. false, /* partial_inplace */
  83. 0x00000000, /* src_mask */
  84. 0xffffffff, /* dst_mask */
  85. false), /* pcrel_offset */
  86. /* A 32 bit into 48 bits absolute relocation. */
  87. HOWTO (R_FR30_48, /* type */
  88. 0, /* rightshift */
  89. 2, /* size (0 = byte, 1 = short, 2 = long) */
  90. 32, /* bitsize */
  91. false, /* pc_relative */
  92. 0, /* bitpos */
  93. complain_overflow_bitfield, /* complain_on_overflow */
  94. fr30_elf_i32_reloc, /* special_function */
  95. "R_FR30_48", /* name */
  96. false, /* partial_inplace */
  97. 0x00000000, /* src_mask */
  98. 0xffffffff, /* dst_mask */
  99. false), /* pcrel_offset */
  100. /* A 6 bit absolute relocation. */
  101. HOWTO (R_FR30_6_IN_4, /* type */
  102. 2, /* rightshift */
  103. 1, /* size (0 = byte, 1 = short, 2 = long) */
  104. 6, /* bitsize */
  105. false, /* pc_relative */
  106. 4, /* bitpos */
  107. complain_overflow_unsigned, /* complain_on_overflow */
  108. bfd_elf_generic_reloc, /* special_function */
  109. "R_FR30_6_IN_4", /* name */
  110. false, /* partial_inplace */
  111. 0x0000, /* src_mask */
  112. 0x00f0, /* dst_mask */
  113. false), /* pcrel_offset */
  114. /* An 8 bit absolute relocation. */
  115. HOWTO (R_FR30_8_IN_8, /* type */
  116. 0, /* rightshift */
  117. 1, /* size (0 = byte, 1 = short, 2 = long) */
  118. 8, /* bitsize */
  119. false, /* pc_relative */
  120. 4, /* bitpos */
  121. complain_overflow_signed, /* complain_on_overflow */
  122. bfd_elf_generic_reloc,/* special_function */
  123. "R_FR30_8_IN_8", /* name */
  124. false, /* partial_inplace */
  125. 0x0000, /* src_mask */
  126. 0x0ff0, /* dst_mask */
  127. false), /* pcrel_offset */
  128. /* A 9 bit absolute relocation. */
  129. HOWTO (R_FR30_9_IN_8, /* type */
  130. 1, /* rightshift */
  131. 1, /* size (0 = byte, 1 = short, 2 = long) */
  132. 9, /* bitsize */
  133. false, /* pc_relative */
  134. 4, /* bitpos */
  135. complain_overflow_signed, /* complain_on_overflow */
  136. bfd_elf_generic_reloc,/* special_function */
  137. "R_FR30_9_IN_8", /* name */
  138. false, /* partial_inplace */
  139. 0x0000, /* src_mask */
  140. 0x0ff0, /* dst_mask */
  141. false), /* pcrel_offset */
  142. /* A 10 bit absolute relocation. */
  143. HOWTO (R_FR30_10_IN_8, /* type */
  144. 2, /* rightshift */
  145. 1, /* size (0 = byte, 1 = short, 2 = long) */
  146. 10, /* bitsize */
  147. false, /* pc_relative */
  148. 4, /* bitpos */
  149. complain_overflow_signed, /* complain_on_overflow */
  150. bfd_elf_generic_reloc,/* special_function */
  151. "R_FR30_10_IN_8", /* name */
  152. false, /* partial_inplace */
  153. 0x0000, /* src_mask */
  154. 0x0ff0, /* dst_mask */
  155. false), /* pcrel_offset */
  156. /* A PC relative 9 bit relocation, right shifted by 1. */
  157. HOWTO (R_FR30_9_PCREL, /* type */
  158. 1, /* rightshift */
  159. 1, /* size (0 = byte, 1 = short, 2 = long) */
  160. 9, /* bitsize */
  161. true, /* pc_relative */
  162. 0, /* bitpos */
  163. complain_overflow_signed, /* complain_on_overflow */
  164. bfd_elf_generic_reloc, /* special_function */
  165. "R_FR30_9_PCREL", /* name */
  166. false, /* partial_inplace */
  167. 0x0000, /* src_mask */
  168. 0x00ff, /* dst_mask */
  169. false), /* pcrel_offset */
  170. /* A PC relative 12 bit relocation, right shifted by 1. */
  171. HOWTO (R_FR30_12_PCREL, /* type */
  172. 1, /* rightshift */
  173. 1, /* size (0 = byte, 1 = short, 2 = long) */
  174. 12, /* bitsize */
  175. true, /* pc_relative */
  176. 0, /* bitpos */
  177. complain_overflow_signed, /* complain_on_overflow */
  178. bfd_elf_generic_reloc, /* special_function */
  179. "R_FR30_12_PCREL", /* name */
  180. false, /* partial_inplace */
  181. 0x0000, /* src_mask */
  182. 0x07ff, /* dst_mask */
  183. false), /* pcrel_offset */
  184. /* GNU extension to record C++ vtable hierarchy */
  185. HOWTO (R_FR30_GNU_VTINHERIT, /* type */
  186. 0, /* rightshift */
  187. 2, /* size (0 = byte, 1 = short, 2 = long) */
  188. 0, /* bitsize */
  189. false, /* pc_relative */
  190. 0, /* bitpos */
  191. complain_overflow_dont, /* complain_on_overflow */
  192. NULL, /* special_function */
  193. "R_FR30_GNU_VTINHERIT", /* name */
  194. false, /* partial_inplace */
  195. 0, /* src_mask */
  196. 0, /* dst_mask */
  197. false), /* pcrel_offset */
  198. /* GNU extension to record C++ vtable member usage */
  199. HOWTO (R_FR30_GNU_VTENTRY, /* type */
  200. 0, /* rightshift */
  201. 2, /* size (0 = byte, 1 = short, 2 = long) */
  202. 0, /* bitsize */
  203. false, /* pc_relative */
  204. 0, /* bitpos */
  205. complain_overflow_dont, /* complain_on_overflow */
  206. _bfd_elf_rel_vtable_reloc_fn, /* special_function */
  207. "R_FR30_GNU_VTENTRY", /* name */
  208. false, /* partial_inplace */
  209. 0, /* src_mask */
  210. 0, /* dst_mask */
  211. false), /* pcrel_offset */
  212. };
  213. /* Utility to actually perform an R_FR30_20 reloc. */
  214. static bfd_reloc_status_type
  215. fr30_elf_i20_reloc (bfd *abfd,
  216. arelent *reloc_entry,
  217. asymbol *symbol,
  218. void * data,
  219. asection *input_section,
  220. bfd *output_bfd,
  221. char **error_message ATTRIBUTE_UNUSED)
  222. {
  223. bfd_vma relocation;
  224. unsigned long x;
  225. /* This part is from bfd_elf_generic_reloc. */
  226. if (output_bfd != (bfd *) NULL
  227. && (symbol->flags & BSF_SECTION_SYM) == 0
  228. && (! reloc_entry->howto->partial_inplace
  229. || reloc_entry->addend == 0))
  230. {
  231. reloc_entry->address += input_section->output_offset;
  232. return bfd_reloc_ok;
  233. }
  234. if (output_bfd != NULL)
  235. /* FIXME: See bfd_perform_relocation. Is this right? */
  236. return bfd_reloc_ok;
  237. relocation =
  238. symbol->value
  239. + symbol->section->output_section->vma
  240. + symbol->section->output_offset
  241. + reloc_entry->addend;
  242. if (relocation > (((bfd_vma) 1 << 20) - 1))
  243. return bfd_reloc_overflow;
  244. x = bfd_get_32 (abfd, (char *) data + reloc_entry->address);
  245. x = (x & 0xff0f0000) | (relocation & 0x0000ffff) | ((relocation & 0x000f0000) << 4);
  246. bfd_put_32 (abfd, (bfd_vma) x, (char *) data + reloc_entry->address);
  247. return bfd_reloc_ok;
  248. }
  249. /* Utility to actually perform a R_FR30_48 reloc. */
  250. static bfd_reloc_status_type
  251. fr30_elf_i32_reloc (bfd *abfd,
  252. arelent *reloc_entry,
  253. asymbol *symbol,
  254. void * data,
  255. asection *input_section,
  256. bfd *output_bfd,
  257. char **error_message ATTRIBUTE_UNUSED)
  258. {
  259. bfd_vma relocation;
  260. /* This part is from bfd_elf_generic_reloc. */
  261. if (output_bfd != (bfd *) NULL
  262. && (symbol->flags & BSF_SECTION_SYM) == 0
  263. && (! reloc_entry->howto->partial_inplace
  264. || reloc_entry->addend == 0))
  265. {
  266. reloc_entry->address += input_section->output_offset;
  267. return bfd_reloc_ok;
  268. }
  269. if (output_bfd != NULL)
  270. /* FIXME: See bfd_perform_relocation. Is this right? */
  271. return bfd_reloc_ok;
  272. relocation =
  273. symbol->value
  274. + symbol->section->output_section->vma
  275. + symbol->section->output_offset
  276. + reloc_entry->addend;
  277. bfd_put_32 (abfd, relocation, (char *) data + reloc_entry->address + 2);
  278. return bfd_reloc_ok;
  279. }
  280. /* Map BFD reloc types to FR30 ELF reloc types. */
  281. struct fr30_reloc_map
  282. {
  283. bfd_reloc_code_real_type bfd_reloc_val;
  284. unsigned int fr30_reloc_val;
  285. };
  286. static const struct fr30_reloc_map fr30_reloc_map [] =
  287. {
  288. { BFD_RELOC_NONE, R_FR30_NONE },
  289. { BFD_RELOC_8, R_FR30_8 },
  290. { BFD_RELOC_FR30_20, R_FR30_20 },
  291. { BFD_RELOC_32, R_FR30_32 },
  292. { BFD_RELOC_FR30_48, R_FR30_48 },
  293. { BFD_RELOC_FR30_6_IN_4, R_FR30_6_IN_4 },
  294. { BFD_RELOC_FR30_8_IN_8, R_FR30_8_IN_8 },
  295. { BFD_RELOC_FR30_9_IN_8, R_FR30_9_IN_8 },
  296. { BFD_RELOC_FR30_10_IN_8, R_FR30_10_IN_8 },
  297. { BFD_RELOC_FR30_9_PCREL, R_FR30_9_PCREL },
  298. { BFD_RELOC_FR30_12_PCREL, R_FR30_12_PCREL },
  299. { BFD_RELOC_VTABLE_INHERIT, R_FR30_GNU_VTINHERIT },
  300. { BFD_RELOC_VTABLE_ENTRY, R_FR30_GNU_VTENTRY },
  301. };
  302. static reloc_howto_type *
  303. fr30_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  304. bfd_reloc_code_real_type code)
  305. {
  306. unsigned int i;
  307. for (i = sizeof (fr30_reloc_map) / sizeof (fr30_reloc_map[0]);
  308. i--;)
  309. if (fr30_reloc_map [i].bfd_reloc_val == code)
  310. return & fr30_elf_howto_table [fr30_reloc_map[i].fr30_reloc_val];
  311. return NULL;
  312. }
  313. static reloc_howto_type *
  314. fr30_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name)
  315. {
  316. unsigned int i;
  317. for (i = 0;
  318. i < sizeof (fr30_elf_howto_table) / sizeof (fr30_elf_howto_table[0]);
  319. i++)
  320. if (fr30_elf_howto_table[i].name != NULL
  321. && strcasecmp (fr30_elf_howto_table[i].name, r_name) == 0)
  322. return &fr30_elf_howto_table[i];
  323. return NULL;
  324. }
  325. /* Set the howto pointer for an FR30 ELF reloc. */
  326. static bool
  327. fr30_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
  328. arelent *cache_ptr,
  329. Elf_Internal_Rela *dst)
  330. {
  331. unsigned int r_type;
  332. r_type = ELF32_R_TYPE (dst->r_info);
  333. if (r_type >= (unsigned int) R_FR30_max)
  334. {
  335. /* xgettext:c-format */
  336. _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
  337. abfd, r_type);
  338. bfd_set_error (bfd_error_bad_value);
  339. return false;
  340. }
  341. cache_ptr->howto = & fr30_elf_howto_table [r_type];
  342. return true;
  343. }
  344. /* Perform a single relocation. By default we use the standard BFD
  345. routines, but a few relocs, we have to do them ourselves. */
  346. static bfd_reloc_status_type
  347. fr30_final_link_relocate (reloc_howto_type *howto,
  348. bfd *input_bfd,
  349. asection *input_section,
  350. bfd_byte *contents,
  351. Elf_Internal_Rela *rel,
  352. bfd_vma relocation)
  353. {
  354. bfd_reloc_status_type r = bfd_reloc_ok;
  355. bfd_vma x;
  356. bfd_signed_vma srel;
  357. switch (howto->type)
  358. {
  359. case R_FR30_20:
  360. contents += rel->r_offset;
  361. relocation += rel->r_addend;
  362. if (relocation > ((1 << 20) - 1))
  363. return bfd_reloc_overflow;
  364. x = bfd_get_32 (input_bfd, contents);
  365. x = (x & 0xff0f0000) | (relocation & 0x0000ffff) | ((relocation & 0x000f0000) << 4);
  366. bfd_put_32 (input_bfd, x, contents);
  367. break;
  368. case R_FR30_48:
  369. contents += rel->r_offset + 2;
  370. relocation += rel->r_addend;
  371. bfd_put_32 (input_bfd, relocation, contents);
  372. break;
  373. case R_FR30_9_PCREL:
  374. contents += rel->r_offset + 1;
  375. srel = (bfd_signed_vma) relocation;
  376. srel += rel->r_addend;
  377. srel -= rel->r_offset;
  378. srel -= 2; /* Branch instructions add 2 to the PC... */
  379. srel -= (input_section->output_section->vma +
  380. input_section->output_offset);
  381. if (srel & 1)
  382. return bfd_reloc_outofrange;
  383. if (srel > ((1 << 8) - 1) || (srel < - (1 << 8)))
  384. return bfd_reloc_overflow;
  385. bfd_put_8 (input_bfd, srel >> 1, contents);
  386. break;
  387. case R_FR30_12_PCREL:
  388. contents += rel->r_offset;
  389. srel = (bfd_signed_vma) relocation;
  390. srel += rel->r_addend;
  391. srel -= rel->r_offset;
  392. srel -= 2; /* Branch instructions add 2 to the PC... */
  393. srel -= (input_section->output_section->vma +
  394. input_section->output_offset);
  395. if (srel & 1)
  396. return bfd_reloc_outofrange;
  397. if (srel > ((1 << 11) - 1) || (srel < - (1 << 11)))
  398. return bfd_reloc_overflow;
  399. x = bfd_get_16 (input_bfd, contents);
  400. x = (x & 0xf800) | ((srel >> 1) & 0x7ff);
  401. bfd_put_16 (input_bfd, x, contents);
  402. break;
  403. default:
  404. r = _bfd_final_link_relocate (howto, input_bfd, input_section,
  405. contents, rel->r_offset,
  406. relocation, rel->r_addend);
  407. }
  408. return r;
  409. }
  410. /* Relocate an FR30 ELF section.
  411. The RELOCATE_SECTION function is called by the new ELF backend linker
  412. to handle the relocations for a section.
  413. The relocs are always passed as Rela structures; if the section
  414. actually uses Rel structures, the r_addend field will always be
  415. zero.
  416. This function is responsible for adjusting the section contents as
  417. necessary, and (if using Rela relocs and generating a relocatable
  418. output file) adjusting the reloc addend as necessary.
  419. This function does not have to worry about setting the reloc
  420. address or the reloc symbol index.
  421. LOCAL_SYMS is a pointer to the swapped in local symbols.
  422. LOCAL_SECTIONS is an array giving the section in the input file
  423. corresponding to the st_shndx field of each local symbol.
  424. The global hash table entry for the global symbols can be found
  425. via elf_sym_hashes (input_bfd).
  426. When generating relocatable output, this function must handle
  427. STB_LOCAL/STT_SECTION symbols specially. The output symbol is
  428. going to be the section symbol corresponding to the output
  429. section, which means that the addend must be adjusted
  430. accordingly. */
  431. static int
  432. fr30_elf_relocate_section (bfd *output_bfd,
  433. struct bfd_link_info *info,
  434. bfd *input_bfd,
  435. asection *input_section,
  436. bfd_byte *contents,
  437. Elf_Internal_Rela *relocs,
  438. Elf_Internal_Sym *local_syms,
  439. asection **local_sections)
  440. {
  441. Elf_Internal_Shdr *symtab_hdr;
  442. struct elf_link_hash_entry **sym_hashes;
  443. Elf_Internal_Rela *rel;
  444. Elf_Internal_Rela *relend;
  445. symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
  446. sym_hashes = elf_sym_hashes (input_bfd);
  447. relend = relocs + input_section->reloc_count;
  448. for (rel = relocs; rel < relend; rel ++)
  449. {
  450. reloc_howto_type *howto;
  451. unsigned long r_symndx;
  452. Elf_Internal_Sym *sym;
  453. asection *sec;
  454. struct elf_link_hash_entry *h;
  455. bfd_vma relocation;
  456. bfd_reloc_status_type r;
  457. const char *name;
  458. int r_type;
  459. r_type = ELF32_R_TYPE (rel->r_info);
  460. if ( r_type == R_FR30_GNU_VTINHERIT
  461. || r_type == R_FR30_GNU_VTENTRY)
  462. continue;
  463. r_symndx = ELF32_R_SYM (rel->r_info);
  464. howto = fr30_elf_howto_table + ELF32_R_TYPE (rel->r_info);
  465. h = NULL;
  466. sym = NULL;
  467. sec = NULL;
  468. if (r_symndx < symtab_hdr->sh_info)
  469. {
  470. sym = local_syms + r_symndx;
  471. sec = local_sections [r_symndx];
  472. relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
  473. name = bfd_elf_string_from_elf_section
  474. (input_bfd, symtab_hdr->sh_link, sym->st_name);
  475. name = name == NULL ? bfd_section_name (sec) : name;
  476. }
  477. else
  478. {
  479. bool unresolved_reloc, warned, ignored;
  480. RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
  481. r_symndx, symtab_hdr, sym_hashes,
  482. h, sec, relocation,
  483. unresolved_reloc, warned, ignored);
  484. name = h->root.root.string;
  485. }
  486. if (sec != NULL && discarded_section (sec))
  487. RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
  488. rel, 1, relend, howto, 0, contents);
  489. if (bfd_link_relocatable (info))
  490. continue;
  491. r = fr30_final_link_relocate (howto, input_bfd, input_section,
  492. contents, rel, relocation);
  493. if (r != bfd_reloc_ok)
  494. {
  495. const char * msg = (const char *) NULL;
  496. switch (r)
  497. {
  498. case bfd_reloc_overflow:
  499. (*info->callbacks->reloc_overflow)
  500. (info, (h ? &h->root : NULL), name, howto->name,
  501. (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
  502. break;
  503. case bfd_reloc_undefined:
  504. (*info->callbacks->undefined_symbol)
  505. (info, name, input_bfd, input_section, rel->r_offset, true);
  506. break;
  507. case bfd_reloc_outofrange:
  508. msg = _("internal error: out of range error");
  509. break;
  510. case bfd_reloc_notsupported:
  511. msg = _("internal error: unsupported relocation error");
  512. break;
  513. case bfd_reloc_dangerous:
  514. msg = _("internal error: dangerous relocation");
  515. break;
  516. default:
  517. msg = _("internal error: unknown error");
  518. break;
  519. }
  520. if (msg)
  521. (*info->callbacks->warning) (info, msg, name, input_bfd,
  522. input_section, rel->r_offset);
  523. }
  524. }
  525. return true;
  526. }
  527. /* Return the section that should be marked against GC for a given
  528. relocation. */
  529. static asection *
  530. fr30_elf_gc_mark_hook (asection *sec,
  531. struct bfd_link_info *info,
  532. Elf_Internal_Rela *rel,
  533. struct elf_link_hash_entry *h,
  534. Elf_Internal_Sym *sym)
  535. {
  536. if (h != NULL)
  537. switch (ELF32_R_TYPE (rel->r_info))
  538. {
  539. case R_FR30_GNU_VTINHERIT:
  540. case R_FR30_GNU_VTENTRY:
  541. return NULL;
  542. }
  543. return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
  544. }
  545. /* Look through the relocs for a section during the first phase.
  546. Since we don't do .gots or .plts, we just need to consider the
  547. virtual table relocs for gc. */
  548. static bool
  549. fr30_elf_check_relocs (bfd *abfd,
  550. struct bfd_link_info *info,
  551. asection *sec,
  552. const Elf_Internal_Rela *relocs)
  553. {
  554. Elf_Internal_Shdr *symtab_hdr;
  555. struct elf_link_hash_entry **sym_hashes;
  556. const Elf_Internal_Rela *rel;
  557. const Elf_Internal_Rela *rel_end;
  558. if (bfd_link_relocatable (info))
  559. return true;
  560. symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  561. sym_hashes = elf_sym_hashes (abfd);
  562. rel_end = relocs + sec->reloc_count;
  563. for (rel = relocs; rel < rel_end; rel++)
  564. {
  565. struct elf_link_hash_entry *h;
  566. unsigned long r_symndx;
  567. r_symndx = ELF32_R_SYM (rel->r_info);
  568. if (r_symndx < symtab_hdr->sh_info)
  569. h = NULL;
  570. else
  571. {
  572. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  573. while (h->root.type == bfd_link_hash_indirect
  574. || h->root.type == bfd_link_hash_warning)
  575. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  576. }
  577. switch (ELF32_R_TYPE (rel->r_info))
  578. {
  579. /* This relocation describes the C++ object vtable hierarchy.
  580. Reconstruct it for later use during GC. */
  581. case R_FR30_GNU_VTINHERIT:
  582. if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
  583. return false;
  584. break;
  585. /* This relocation describes which C++ vtable entries are actually
  586. used. Record for later use during GC. */
  587. case R_FR30_GNU_VTENTRY:
  588. if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
  589. return false;
  590. break;
  591. }
  592. }
  593. return true;
  594. }
  595. #define ELF_ARCH bfd_arch_fr30
  596. #define ELF_MACHINE_CODE EM_FR30
  597. #define ELF_MACHINE_ALT1 EM_CYGNUS_FR30
  598. #define ELF_MAXPAGESIZE 0x1000
  599. #define TARGET_BIG_SYM fr30_elf32_vec
  600. #define TARGET_BIG_NAME "elf32-fr30"
  601. #define elf_info_to_howto_rel NULL
  602. #define elf_info_to_howto fr30_info_to_howto_rela
  603. #define elf_backend_relocate_section fr30_elf_relocate_section
  604. #define elf_backend_gc_mark_hook fr30_elf_gc_mark_hook
  605. #define elf_backend_check_relocs fr30_elf_check_relocs
  606. #define elf_backend_can_gc_sections 1
  607. #define elf_backend_rela_normal 1
  608. #define bfd_elf32_bfd_reloc_type_lookup fr30_reloc_type_lookup
  609. #define bfd_elf32_bfd_reloc_name_lookup fr30_reloc_name_lookup
  610. #include "elf32-target.h"