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