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