1 /* D10V-specific support for 32-bit ELF
2 Copyright (C) 1996, 1998, 1999, 2000 Free Software Foundation, Inc.
3 Contributed by Martin Hunt (hunt@cygnus.com).
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
28 PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
29 static void d10v_info_to_howto_rel
30 PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *));
33 /* Use REL instead of RELA to save space */
36 static reloc_howto_type elf_d10v_howto_table[] =
38 /* This reloc does nothing. */
39 HOWTO (R_D10V_NONE, /* type */
41 2, /* size (0 = byte, 1 = short, 2 = long) */
43 false, /* pc_relative */
45 complain_overflow_bitfield, /* complain_on_overflow */
46 bfd_elf_generic_reloc, /* special_function */
47 "R_D10V_NONE", /* name */
48 false, /* partial_inplace */
51 false), /* pcrel_offset */
53 /* An PC Relative 10-bit relocation, shifted by 2 */
55 HOWTO (R_D10V_10_PCREL_R, /* type */
57 2, /* size (0 = byte, 1 = short, 2 = long) */
59 true, /* pc_relative */
61 complain_overflow_bitfield, /* complain_on_overflow */
62 bfd_elf_generic_reloc, /* special_function */
63 "R_D10V_10_PCREL_R", /* name */
64 false, /* partial_inplace */
67 true), /* pcrel_offset */
69 /* An PC Relative 10-bit relocation, shifted by 2 */
71 HOWTO (R_D10V_10_PCREL_L, /* type */
73 2, /* size (0 = byte, 1 = short, 2 = long) */
75 true, /* pc_relative */
77 complain_overflow_bitfield, /* complain_on_overflow */
78 bfd_elf_generic_reloc, /* special_function */
79 "R_D10V_10_PCREL_L", /* name */
80 false, /* partial_inplace */
81 0x07f8000, /* src_mask */
82 0x07f8000, /* dst_mask */
83 true), /* pcrel_offset */
85 /* A 16 bit absolute relocation */
86 HOWTO (R_D10V_16, /* type */
88 1, /* size (0 = byte, 1 = short, 2 = long) */
90 false, /* pc_relative */
92 complain_overflow_dont, /* complain_on_overflow */
93 bfd_elf_generic_reloc, /* special_function */
94 "R_D10V_16", /* name */
95 false, /* partial_inplace */
96 0xffff, /* src_mask */
97 0xffff, /* dst_mask */
98 false), /* pcrel_offset */
100 /* An 18 bit absolute relocation, right shifted 2 */
101 HOWTO (R_D10V_18, /* type */
103 1, /* size (0 = byte, 1 = short, 2 = long) */
105 false, /* pc_relative */
107 complain_overflow_dont, /* complain_on_overflow */
108 bfd_elf_generic_reloc, /* special_function */
109 "R_D10V_18", /* name */
110 false, /* partial_inplace */
111 0xffff, /* src_mask */
112 0xffff, /* dst_mask */
113 false), /* pcrel_offset */
115 /* A relative 18 bit relocation, right shifted by 2 */
116 HOWTO (R_D10V_18_PCREL, /* type */
118 2, /* size (0 = byte, 1 = short, 2 = long) */
120 true, /* pc_relative */
122 complain_overflow_signed, /* complain_on_overflow */
123 bfd_elf_generic_reloc, /* special_function */
124 "R_D10V_18_PCREL", /* name */
125 false, /* partial_inplace */
126 0xffff, /* src_mask */
127 0xffff, /* dst_mask */
128 true), /* pcrel_offset */
130 /* A 32 bit absolute relocation */
131 HOWTO (R_D10V_32, /* type */
133 2, /* size (0 = byte, 1 = short, 2 = long) */
135 false, /* pc_relative */
137 complain_overflow_bitfield, /* complain_on_overflow */
138 bfd_elf_generic_reloc, /* special_function */
139 "R_D10V_32", /* name */
140 false, /* partial_inplace */
141 0xffffffff, /* src_mask */
142 0xffffffff, /* dst_mask */
143 false), /* pcrel_offset */
145 /* GNU extension to record C++ vtable hierarchy */
146 HOWTO (R_D10V_GNU_VTINHERIT, /* type */
148 2, /* size (0 = byte, 1 = short, 2 = long) */
150 false, /* pc_relative */
152 complain_overflow_dont, /* complain_on_overflow */
153 NULL, /* special_function */
154 "R_D10V_GNU_VTINHERIT", /* name */
155 false, /* partial_inplace */
158 false), /* pcrel_offset */
160 /* GNU extension to record C++ vtable member usage */
161 HOWTO (R_D10V_GNU_VTENTRY, /* type */
163 2, /* size (0 = byte, 1 = short, 2 = long) */
165 false, /* pc_relative */
167 complain_overflow_dont, /* complain_on_overflow */
168 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
169 "R_D10V_GNU_VTENTRY", /* name */
170 false, /* partial_inplace */
173 false), /* pcrel_offset */
177 /* Map BFD reloc types to D10V ELF reloc types. */
179 struct d10v_reloc_map
181 bfd_reloc_code_real_type bfd_reloc_val;
182 unsigned char elf_reloc_val;
185 static const struct d10v_reloc_map d10v_reloc_map[] =
187 { BFD_RELOC_NONE, R_D10V_NONE, },
188 { BFD_RELOC_D10V_10_PCREL_R, R_D10V_10_PCREL_R },
189 { BFD_RELOC_D10V_10_PCREL_L, R_D10V_10_PCREL_L },
190 { BFD_RELOC_16, R_D10V_16 },
191 { BFD_RELOC_D10V_18, R_D10V_18 },
192 { BFD_RELOC_D10V_18_PCREL, R_D10V_18_PCREL },
193 { BFD_RELOC_32, R_D10V_32 },
194 { BFD_RELOC_VTABLE_INHERIT, R_D10V_GNU_VTINHERIT },
195 { BFD_RELOC_VTABLE_ENTRY, R_D10V_GNU_VTENTRY },
198 static reloc_howto_type *
199 bfd_elf32_bfd_reloc_type_lookup (abfd, code)
200 bfd *abfd ATTRIBUTE_UNUSED;
201 bfd_reloc_code_real_type code;
206 i < sizeof (d10v_reloc_map) / sizeof (struct d10v_reloc_map);
209 if (d10v_reloc_map[i].bfd_reloc_val == code)
210 return &elf_d10v_howto_table[d10v_reloc_map[i].elf_reloc_val];
216 /* Set the howto pointer for an D10V ELF reloc. */
219 d10v_info_to_howto_rel (abfd, cache_ptr, dst)
220 bfd *abfd ATTRIBUTE_UNUSED;
222 Elf32_Internal_Rel *dst;
226 r_type = ELF32_R_TYPE (dst->r_info);
227 BFD_ASSERT (r_type < (unsigned int) R_D10V_max);
228 cache_ptr->howto = &elf_d10v_howto_table[r_type];
232 elf32_d10v_gc_mark_hook (abfd, info, rel, h, sym)
234 struct bfd_link_info *info ATTRIBUTE_UNUSED;
235 Elf_Internal_Rela *rel;
236 struct elf_link_hash_entry *h;
237 Elf_Internal_Sym *sym;
241 switch (ELF32_R_TYPE (rel->r_info))
243 case R_D10V_GNU_VTINHERIT:
244 case R_D10V_GNU_VTENTRY:
248 switch (h->root.type)
250 case bfd_link_hash_defined:
251 case bfd_link_hash_defweak:
252 return h->root.u.def.section;
254 case bfd_link_hash_common:
255 return h->root.u.c.p->section;
264 if (!(elf_bad_symtab (abfd)
265 && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
266 && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
267 && sym->st_shndx != SHN_COMMON))
269 return bfd_section_from_elf_index (abfd, sym->st_shndx);
276 elf32_d10v_gc_sweep_hook (abfd, info, sec, relocs)
277 bfd *abfd ATTRIBUTE_UNUSED;
278 struct bfd_link_info *info ATTRIBUTE_UNUSED;
279 asection *sec ATTRIBUTE_UNUSED;
280 const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED;
282 /* we don't use got and plt entries for d10v */
286 /* Look through the relocs for a section during the first phase.
287 Since we don't do .gots or .plts, we just need to consider the
288 virtual table relocs for gc. */
291 elf32_d10v_check_relocs (abfd, info, sec, relocs)
293 struct bfd_link_info *info;
295 const Elf_Internal_Rela *relocs;
297 Elf_Internal_Shdr *symtab_hdr;
298 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
299 const Elf_Internal_Rela *rel;
300 const Elf_Internal_Rela *rel_end;
302 if (info->relocateable)
305 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
306 sym_hashes = elf_sym_hashes (abfd);
307 sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof(Elf32_External_Sym);
308 if (!elf_bad_symtab (abfd))
309 sym_hashes_end -= symtab_hdr->sh_info;
311 rel_end = relocs + sec->reloc_count;
312 for (rel = relocs; rel < rel_end; rel++)
314 struct elf_link_hash_entry *h;
315 unsigned long r_symndx;
317 r_symndx = ELF32_R_SYM (rel->r_info);
318 if (r_symndx < symtab_hdr->sh_info)
321 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
323 switch (ELF32_R_TYPE (rel->r_info))
325 /* This relocation describes the C++ object vtable hierarchy.
326 Reconstruct it for later use during GC. */
327 case R_D10V_GNU_VTINHERIT:
328 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
332 /* This relocation describes which C++ vtable entries are actually
333 used. Record for later use during GC. */
334 case R_D10V_GNU_VTENTRY:
335 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_offset))
344 /* Relocate a D10V ELF section. */
346 elf32_d10v_relocate_section (output_bfd, info, input_bfd, input_section,
347 contents, relocs, local_syms, local_sections)
348 bfd *output_bfd ATTRIBUTE_UNUSED;
349 struct bfd_link_info *info;
351 asection *input_section;
353 Elf_Internal_Rela *relocs;
354 Elf_Internal_Sym *local_syms;
355 asection **local_sections;
357 Elf_Internal_Shdr *symtab_hdr;
358 struct elf_link_hash_entry **sym_hashes;
359 Elf_Internal_Rela *rel, *relend;
362 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
363 sym_hashes = elf_sym_hashes (input_bfd);
366 relend = relocs + input_section->reloc_count;
367 for (; rel < relend; rel++)
370 reloc_howto_type *howto;
371 unsigned long r_symndx;
372 Elf_Internal_Sym *sym;
374 struct elf_link_hash_entry *h;
376 bfd_reloc_status_type r;
378 r_symndx = ELF32_R_SYM (rel->r_info);
379 r_type = ELF32_R_TYPE (rel->r_info);
381 if (r_type == R_D10V_GNU_VTENTRY
382 || r_type == R_D10V_GNU_VTINHERIT )
385 howto = elf_d10v_howto_table + r_type;
387 if (info->relocateable)
389 /* This is a relocateable link. We don't have to change
390 anything, unless the reloc is against a section symbol,
391 in which case we have to adjust according to where the
392 section symbol winds up in the output section. */
393 if (r_symndx < symtab_hdr->sh_info)
395 sym = local_syms + r_symndx;
396 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
398 sec = local_sections[r_symndx];
399 rel->r_addend += sec->output_offset + sym->st_value;
406 /* This is a final link. */
410 if (r_symndx < symtab_hdr->sh_info)
412 sym = local_syms + r_symndx;
413 sec = local_sections[r_symndx];
414 relocation = (sec->output_section->vma
420 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
421 while (h->root.type == bfd_link_hash_indirect
422 || h->root.type == bfd_link_hash_warning)
423 h = (struct elf_link_hash_entry *) h->root.u.i.link;
424 if (h->root.type == bfd_link_hash_defined
425 || h->root.type == bfd_link_hash_defweak)
427 sec = h->root.u.def.section;
428 relocation = (h->root.u.def.value
429 + sec->output_section->vma
430 + sec->output_offset);
432 else if (h->root.type == bfd_link_hash_undefweak)
436 if (!((*info->callbacks->undefined_symbol)
437 (info, h->root.root.string, input_bfd,
438 input_section, rel->r_offset, true)))
445 name = h->root.root.string;
448 name = (bfd_elf_string_from_elf_section
449 (input_bfd, symtab_hdr->sh_link, sym->st_name));
450 if (name == NULL || *name == '\0')
451 name = bfd_section_name (input_bfd, sec);
454 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
455 contents, rel->r_offset,
456 relocation, rel->r_addend);
458 if (r != bfd_reloc_ok)
460 const char * msg = (const char *) 0;
464 case bfd_reloc_overflow:
465 if (!((*info->callbacks->reloc_overflow)
466 (info, name, howto->name, (bfd_vma) 0,
467 input_bfd, input_section, rel->r_offset)))
471 case bfd_reloc_undefined:
472 if (!((*info->callbacks->undefined_symbol)
473 (info, name, input_bfd, input_section,
474 rel->r_offset, true)))
478 case bfd_reloc_outofrange:
479 msg = _ ("internal error: out of range error");
482 case bfd_reloc_notsupported:
483 msg = _ ("internal error: unsupported relocation error");
486 case bfd_reloc_dangerous:
487 msg = _ ("internal error: dangerous error");
491 msg = _ ("internal error: unknown error");
495 if (!((*info->callbacks->warning)
496 (info, msg, name, input_bfd, input_section,
506 #define ELF_ARCH bfd_arch_d10v
507 #define ELF_MACHINE_CODE EM_CYGNUS_D10V
508 #define ELF_MAXPAGESIZE 0x1000
510 #define TARGET_BIG_SYM bfd_elf32_d10v_vec
511 #define TARGET_BIG_NAME "elf32-d10v"
513 #define elf_info_to_howto 0
514 #define elf_info_to_howto_rel d10v_info_to_howto_rel
515 #define elf_backend_object_p 0
516 #define elf_backend_final_write_processing 0
517 #define elf_backend_gc_mark_hook elf32_d10v_gc_mark_hook
518 #define elf_backend_gc_sweep_hook elf32_d10v_gc_sweep_hook
519 #define elf_backend_check_relocs elf32_d10v_check_relocs
520 #define elf_backend_relocate_section elf32_d10v_relocate_section
521 #define elf_backend_can_gc_sections 1
523 #include "elf32-target.h"