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