elf32-fr30.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. /* FR30-specific support for 32-bit ELF.
  2. Copyright (C) 1998-2015 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 void
  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. _bfd_error_handler (_("%B: invalid FR30 reloc number: %d"), abfd, r_type);
  336. r_type = 0;
  337. }
  338. cache_ptr->howto = & fr30_elf_howto_table [r_type];
  339. }
  340. /* Perform a single relocation. By default we use the standard BFD
  341. routines, but a few relocs, we have to do them ourselves. */
  342. static bfd_reloc_status_type
  343. fr30_final_link_relocate (reloc_howto_type *howto,
  344. bfd *input_bfd,
  345. asection *input_section,
  346. bfd_byte *contents,
  347. Elf_Internal_Rela *rel,
  348. bfd_vma relocation)
  349. {
  350. bfd_reloc_status_type r = bfd_reloc_ok;
  351. bfd_vma x;
  352. bfd_signed_vma srel;
  353. switch (howto->type)
  354. {
  355. case R_FR30_20:
  356. contents += rel->r_offset;
  357. relocation += rel->r_addend;
  358. if (relocation > ((1 << 20) - 1))
  359. return bfd_reloc_overflow;
  360. x = bfd_get_32 (input_bfd, contents);
  361. x = (x & 0xff0f0000) | (relocation & 0x0000ffff) | ((relocation & 0x000f0000) << 4);
  362. bfd_put_32 (input_bfd, x, contents);
  363. break;
  364. case R_FR30_48:
  365. contents += rel->r_offset + 2;
  366. relocation += rel->r_addend;
  367. bfd_put_32 (input_bfd, relocation, contents);
  368. break;
  369. case R_FR30_9_PCREL:
  370. contents += rel->r_offset + 1;
  371. srel = (bfd_signed_vma) relocation;
  372. srel += rel->r_addend;
  373. srel -= rel->r_offset;
  374. srel -= 2; /* Branch instructions add 2 to the PC... */
  375. srel -= (input_section->output_section->vma +
  376. input_section->output_offset);
  377. if (srel & 1)
  378. return bfd_reloc_outofrange;
  379. if (srel > ((1 << 8) - 1) || (srel < - (1 << 8)))
  380. return bfd_reloc_overflow;
  381. bfd_put_8 (input_bfd, srel >> 1, contents);
  382. break;
  383. case R_FR30_12_PCREL:
  384. contents += rel->r_offset;
  385. srel = (bfd_signed_vma) relocation;
  386. srel += rel->r_addend;
  387. srel -= rel->r_offset;
  388. srel -= 2; /* Branch instructions add 2 to the PC... */
  389. srel -= (input_section->output_section->vma +
  390. input_section->output_offset);
  391. if (srel & 1)
  392. return bfd_reloc_outofrange;
  393. if (srel > ((1 << 11) - 1) || (srel < - (1 << 11)))
  394. return bfd_reloc_overflow;
  395. x = bfd_get_16 (input_bfd, contents);
  396. x = (x & 0xf800) | ((srel >> 1) & 0x7ff);
  397. bfd_put_16 (input_bfd, x, contents);
  398. break;
  399. default:
  400. r = _bfd_final_link_relocate (howto, input_bfd, input_section,
  401. contents, rel->r_offset,
  402. relocation, rel->r_addend);
  403. }
  404. return r;
  405. }
  406. /* Relocate an FR30 ELF section.
  407. The RELOCATE_SECTION function is called by the new ELF backend linker
  408. to handle the relocations for a section.
  409. The relocs are always passed as Rela structures; if the section
  410. actually uses Rel structures, the r_addend field will always be
  411. zero.
  412. This function is responsible for adjusting the section contents as
  413. necessary, and (if using Rela relocs and generating a relocatable
  414. output file) adjusting the reloc addend as necessary.
  415. This function does not have to worry about setting the reloc
  416. address or the reloc symbol index.
  417. LOCAL_SYMS is a pointer to the swapped in local symbols.
  418. LOCAL_SECTIONS is an array giving the section in the input file
  419. corresponding to the st_shndx field of each local symbol.
  420. The global hash table entry for the global symbols can be found
  421. via elf_sym_hashes (input_bfd).
  422. When generating relocatable output, this function must handle
  423. STB_LOCAL/STT_SECTION symbols specially. The output symbol is
  424. going to be the section symbol corresponding to the output
  425. section, which means that the addend must be adjusted
  426. accordingly. */
  427. static bfd_boolean
  428. fr30_elf_relocate_section (bfd *output_bfd,
  429. struct bfd_link_info *info,
  430. bfd *input_bfd,
  431. asection *input_section,
  432. bfd_byte *contents,
  433. Elf_Internal_Rela *relocs,
  434. Elf_Internal_Sym *local_syms,
  435. asection **local_sections)
  436. {
  437. Elf_Internal_Shdr *symtab_hdr;
  438. struct elf_link_hash_entry **sym_hashes;
  439. Elf_Internal_Rela *rel;
  440. Elf_Internal_Rela *relend;
  441. symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
  442. sym_hashes = elf_sym_hashes (input_bfd);
  443. relend = relocs + input_section->reloc_count;
  444. for (rel = relocs; rel < relend; rel ++)
  445. {
  446. reloc_howto_type *howto;
  447. unsigned long r_symndx;
  448. Elf_Internal_Sym *sym;
  449. asection *sec;
  450. struct elf_link_hash_entry *h;
  451. bfd_vma relocation;
  452. bfd_reloc_status_type r;
  453. const char *name;
  454. int r_type;
  455. r_type = ELF32_R_TYPE (rel->r_info);
  456. if ( r_type == R_FR30_GNU_VTINHERIT
  457. || r_type == R_FR30_GNU_VTENTRY)
  458. continue;
  459. r_symndx = ELF32_R_SYM (rel->r_info);
  460. howto = fr30_elf_howto_table + ELF32_R_TYPE (rel->r_info);
  461. h = NULL;
  462. sym = NULL;
  463. sec = NULL;
  464. if (r_symndx < symtab_hdr->sh_info)
  465. {
  466. sym = local_syms + r_symndx;
  467. sec = local_sections [r_symndx];
  468. relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
  469. name = bfd_elf_string_from_elf_section
  470. (input_bfd, symtab_hdr->sh_link, sym->st_name);
  471. name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name;
  472. }
  473. else
  474. {
  475. bfd_boolean unresolved_reloc, warned, ignored;
  476. RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
  477. r_symndx, symtab_hdr, sym_hashes,
  478. h, sec, relocation,
  479. unresolved_reloc, warned, ignored);
  480. name = h->root.root.string;
  481. }
  482. if (sec != NULL && discarded_section (sec))
  483. RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
  484. rel, 1, relend, howto, 0, contents);
  485. if (bfd_link_relocatable (info))
  486. continue;
  487. r = fr30_final_link_relocate (howto, input_bfd, input_section,
  488. contents, rel, relocation);
  489. if (r != bfd_reloc_ok)
  490. {
  491. const char * msg = (const char *) NULL;
  492. switch (r)
  493. {
  494. case bfd_reloc_overflow:
  495. r = info->callbacks->reloc_overflow
  496. (info, (h ? &h->root : NULL), name, howto->name,
  497. (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
  498. break;
  499. case bfd_reloc_undefined:
  500. r = info->callbacks->undefined_symbol
  501. (info, name, input_bfd, input_section, rel->r_offset,
  502. TRUE);
  503. break;
  504. case bfd_reloc_outofrange:
  505. msg = _("internal error: out of range error");
  506. break;
  507. case bfd_reloc_notsupported:
  508. msg = _("internal error: unsupported relocation error");
  509. break;
  510. case bfd_reloc_dangerous:
  511. msg = _("internal error: dangerous relocation");
  512. break;
  513. default:
  514. msg = _("internal error: unknown error");
  515. break;
  516. }
  517. if (msg)
  518. r = info->callbacks->warning
  519. (info, msg, name, input_bfd, input_section, rel->r_offset);
  520. if (! r)
  521. return FALSE;
  522. }
  523. }
  524. return TRUE;
  525. }
  526. /* Return the section that should be marked against GC for a given
  527. relocation. */
  528. static asection *
  529. fr30_elf_gc_mark_hook (asection *sec,
  530. struct bfd_link_info *info,
  531. Elf_Internal_Rela *rel,
  532. struct elf_link_hash_entry *h,
  533. Elf_Internal_Sym *sym)
  534. {
  535. if (h != NULL)
  536. switch (ELF32_R_TYPE (rel->r_info))
  537. {
  538. case R_FR30_GNU_VTINHERIT:
  539. case R_FR30_GNU_VTENTRY:
  540. return NULL;
  541. }
  542. return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
  543. }
  544. /* Look through the relocs for a section during the first phase.
  545. Since we don't do .gots or .plts, we just need to consider the
  546. virtual table relocs for gc. */
  547. static bfd_boolean
  548. fr30_elf_check_relocs (bfd *abfd,
  549. struct bfd_link_info *info,
  550. asection *sec,
  551. const Elf_Internal_Rela *relocs)
  552. {
  553. Elf_Internal_Shdr *symtab_hdr;
  554. struct elf_link_hash_entry **sym_hashes;
  555. const Elf_Internal_Rela *rel;
  556. const Elf_Internal_Rela *rel_end;
  557. if (bfd_link_relocatable (info))
  558. return TRUE;
  559. symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  560. sym_hashes = elf_sym_hashes (abfd);
  561. rel_end = relocs + sec->reloc_count;
  562. for (rel = relocs; rel < rel_end; rel++)
  563. {
  564. struct elf_link_hash_entry *h;
  565. unsigned long r_symndx;
  566. r_symndx = ELF32_R_SYM (rel->r_info);
  567. if (r_symndx < symtab_hdr->sh_info)
  568. h = NULL;
  569. else
  570. {
  571. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  572. while (h->root.type == bfd_link_hash_indirect
  573. || h->root.type == bfd_link_hash_warning)
  574. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  575. /* PR15323, ref flags aren't set for references in the same
  576. object. */
  577. h->root.non_ir_ref = 1;
  578. }
  579. switch (ELF32_R_TYPE (rel->r_info))
  580. {
  581. /* This relocation describes the C++ object vtable hierarchy.
  582. Reconstruct it for later use during GC. */
  583. case R_FR30_GNU_VTINHERIT:
  584. if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
  585. return FALSE;
  586. break;
  587. /* This relocation describes which C++ vtable entries are actually
  588. used. Record for later use during GC. */
  589. case R_FR30_GNU_VTENTRY:
  590. BFD_ASSERT (h != NULL);
  591. if (h != NULL
  592. && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
  593. return FALSE;
  594. break;
  595. }
  596. }
  597. return TRUE;
  598. }
  599. #define ELF_ARCH bfd_arch_fr30
  600. #define ELF_MACHINE_CODE EM_FR30
  601. #define ELF_MACHINE_ALT1 EM_CYGNUS_FR30
  602. #define ELF_MAXPAGESIZE 0x1000
  603. #define TARGET_BIG_SYM fr30_elf32_vec
  604. #define TARGET_BIG_NAME "elf32-fr30"
  605. #define elf_info_to_howto_rel NULL
  606. #define elf_info_to_howto fr30_info_to_howto_rela
  607. #define elf_backend_relocate_section fr30_elf_relocate_section
  608. #define elf_backend_gc_mark_hook fr30_elf_gc_mark_hook
  609. #define elf_backend_check_relocs fr30_elf_check_relocs
  610. #define elf_backend_can_gc_sections 1
  611. #define elf_backend_rela_normal 1
  612. #define bfd_elf32_bfd_reloc_type_lookup fr30_reloc_type_lookup
  613. #define bfd_elf32_bfd_reloc_name_lookup fr30_reloc_name_lookup
  614. #include "elf32-target.h"