Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* D10V-specific support for 32-bit ELF |
b2a8e766 | 2 | Copyright 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004 |
1049f94e | 3 | Free Software Foundation, Inc. |
252b5132 RH |
4 | Contributed by Martin Hunt (hunt@cygnus.com). |
5 | ||
6 | This file is part of BFD, the Binary File Descriptor library. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
3e110533 | 20 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ |
252b5132 RH |
21 | |
22 | #include "bfd.h" | |
23 | #include "sysdep.h" | |
24 | #include "libbfd.h" | |
25 | #include "elf-bfd.h" | |
1b452ec6 | 26 | #include "elf/d10v.h" |
252b5132 RH |
27 | |
28 | static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup | |
29 | PARAMS ((bfd *abfd, bfd_reloc_code_real_type code)); | |
30 | static void d10v_info_to_howto_rel | |
947216bf | 31 | PARAMS ((bfd *, arelent *, Elf_Internal_Rela *)); |
917583ad | 32 | static asection * elf32_d10v_gc_mark_hook |
1e2f5b6e | 33 | PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *, |
917583ad | 34 | struct elf_link_hash_entry *, Elf_Internal_Sym *)); |
b34976b6 | 35 | static bfd_boolean elf32_d10v_gc_sweep_hook |
917583ad NC |
36 | PARAMS ((bfd *, struct bfd_link_info *, asection *, |
37 | const Elf_Internal_Rela *)); | |
b34976b6 | 38 | static bfd_boolean elf32_d10v_check_relocs |
917583ad NC |
39 | PARAMS ((bfd *, struct bfd_link_info *, asection *, |
40 | const Elf_Internal_Rela *)); | |
a2b0fe9d AM |
41 | static bfd_vma extract_rel_addend |
42 | PARAMS ((bfd *, bfd_byte *, reloc_howto_type *)); | |
43 | static void insert_rel_addend | |
44 | PARAMS ((bfd *, bfd_byte *, reloc_howto_type *, bfd_vma)); | |
b34976b6 | 45 | static bfd_boolean elf32_d10v_relocate_section |
917583ad NC |
46 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, |
47 | bfd_byte *, Elf_Internal_Rela *, Elf_Internal_Sym *, | |
48 | asection **)); | |
49 | ||
50 | /* Use REL instead of RELA to save space. */ | |
acf8aed4 | 51 | #define USE_REL 1 |
252b5132 | 52 | |
252b5132 | 53 | static reloc_howto_type elf_d10v_howto_table[] = |
917583ad NC |
54 | { |
55 | /* This reloc does nothing. */ | |
56 | HOWTO (R_D10V_NONE, /* type */ | |
57 | 0, /* rightshift */ | |
58 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
59 | 32, /* bitsize */ | |
b34976b6 | 60 | FALSE, /* pc_relative */ |
917583ad | 61 | 0, /* bitpos */ |
2888ec15 AO |
62 | complain_overflow_dont, /* complain_on_overflow */ |
63 | bfd_elf_generic_reloc, /* special_function */ | |
64 | "R_D10V_NONE", /* name */ | |
b34976b6 | 65 | FALSE, /* partial_inplace */ |
917583ad NC |
66 | 0, /* src_mask */ |
67 | 0, /* dst_mask */ | |
b34976b6 | 68 | FALSE), /* pcrel_offset */ |
917583ad NC |
69 | |
70 | /* An PC Relative 10-bit relocation, shifted by 2 */ | |
71 | /* right container */ | |
72 | HOWTO (R_D10V_10_PCREL_R, /* type */ | |
73 | 2, /* rightshift */ | |
74 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
57fb03ac | 75 | 7, /* bitsize */ |
b34976b6 | 76 | TRUE, /* pc_relative */ |
917583ad | 77 | 0, /* bitpos */ |
57fb03ac | 78 | complain_overflow_bitfield, /* complain_on_overflow */ |
917583ad NC |
79 | bfd_elf_generic_reloc, /* special_function */ |
80 | "R_D10V_10_PCREL_R", /* name */ | |
b34976b6 | 81 | FALSE, /* partial_inplace */ |
2888ec15 | 82 | 0xff, /* src_mask */ |
917583ad | 83 | 0xff, /* dst_mask */ |
b34976b6 | 84 | TRUE), /* pcrel_offset */ |
917583ad NC |
85 | |
86 | /* An PC Relative 10-bit relocation, shifted by 2 */ | |
87 | /* left container */ | |
88 | HOWTO (R_D10V_10_PCREL_L, /* type */ | |
89 | 2, /* rightshift */ | |
90 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
57fb03ac | 91 | 7, /* bitsize */ |
b34976b6 | 92 | TRUE, /* pc_relative */ |
917583ad | 93 | 15, /* bitpos */ |
57fb03ac | 94 | complain_overflow_bitfield, /* complain_on_overflow */ |
917583ad NC |
95 | bfd_elf_generic_reloc, /* special_function */ |
96 | "R_D10V_10_PCREL_L", /* name */ | |
b34976b6 | 97 | FALSE, /* partial_inplace */ |
2888ec15 AO |
98 | 0x07f8000, /* src_mask */ |
99 | 0x07f8000, /* dst_mask */ | |
b34976b6 | 100 | TRUE), /* pcrel_offset */ |
917583ad NC |
101 | |
102 | /* A 16 bit absolute relocation */ | |
103 | HOWTO (R_D10V_16, /* type */ | |
104 | 0, /* rightshift */ | |
105 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
106 | 16, /* bitsize */ | |
b34976b6 | 107 | FALSE, /* pc_relative */ |
917583ad NC |
108 | 0, /* bitpos */ |
109 | complain_overflow_dont, /* complain_on_overflow */ | |
2888ec15 | 110 | bfd_elf_generic_reloc, /* special_function */ |
917583ad | 111 | "R_D10V_16", /* name */ |
b34976b6 | 112 | FALSE, /* partial_inplace */ |
917583ad NC |
113 | 0xffff, /* src_mask */ |
114 | 0xffff, /* dst_mask */ | |
b34976b6 | 115 | FALSE), /* pcrel_offset */ |
917583ad NC |
116 | |
117 | /* An 18 bit absolute relocation, right shifted 2 */ | |
118 | HOWTO (R_D10V_18, /* type */ | |
119 | 2, /* rightshift */ | |
120 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
2888ec15 | 121 | 16, /* bitsize */ |
b34976b6 | 122 | FALSE, /* pc_relative */ |
917583ad NC |
123 | 0, /* bitpos */ |
124 | complain_overflow_dont, /* complain_on_overflow */ | |
2888ec15 | 125 | bfd_elf_generic_reloc, /* special_function */ |
917583ad | 126 | "R_D10V_18", /* name */ |
b34976b6 | 127 | FALSE, /* partial_inplace */ |
917583ad NC |
128 | 0xffff, /* src_mask */ |
129 | 0xffff, /* dst_mask */ | |
b34976b6 | 130 | FALSE), /* pcrel_offset */ |
917583ad NC |
131 | |
132 | /* A relative 18 bit relocation, right shifted by 2 */ | |
133 | HOWTO (R_D10V_18_PCREL, /* type */ | |
134 | 2, /* rightshift */ | |
135 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
57fb03ac | 136 | 15, /* bitsize */ |
b34976b6 | 137 | TRUE, /* pc_relative */ |
917583ad | 138 | 0, /* bitpos */ |
57fb03ac | 139 | complain_overflow_bitfield, /* complain_on_overflow */ |
2888ec15 | 140 | bfd_elf_generic_reloc, /* special_function */ |
917583ad | 141 | "R_D10V_18_PCREL", /* name */ |
b34976b6 | 142 | FALSE, /* partial_inplace */ |
917583ad NC |
143 | 0xffff, /* src_mask */ |
144 | 0xffff, /* dst_mask */ | |
b34976b6 | 145 | TRUE), /* pcrel_offset */ |
917583ad NC |
146 | |
147 | /* A 32 bit absolute relocation */ | |
148 | HOWTO (R_D10V_32, /* type */ | |
149 | 0, /* rightshift */ | |
150 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
151 | 32, /* bitsize */ | |
b34976b6 | 152 | FALSE, /* pc_relative */ |
917583ad | 153 | 0, /* bitpos */ |
2888ec15 AO |
154 | complain_overflow_dont, /* complain_on_overflow */ |
155 | bfd_elf_generic_reloc, /* special_function */ | |
917583ad | 156 | "R_D10V_32", /* name */ |
b34976b6 | 157 | FALSE, /* partial_inplace */ |
917583ad NC |
158 | 0xffffffff, /* src_mask */ |
159 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 160 | FALSE), /* pcrel_offset */ |
917583ad NC |
161 | |
162 | /* GNU extension to record C++ vtable hierarchy */ | |
163 | HOWTO (R_D10V_GNU_VTINHERIT, /* type */ | |
164 | 0, /* rightshift */ | |
165 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
166 | 0, /* bitsize */ | |
b34976b6 | 167 | FALSE, /* pc_relative */ |
917583ad NC |
168 | 0, /* bitpos */ |
169 | complain_overflow_dont, /* complain_on_overflow */ | |
170 | NULL, /* special_function */ | |
171 | "R_D10V_GNU_VTINHERIT", /* name */ | |
b34976b6 | 172 | FALSE, /* partial_inplace */ |
917583ad NC |
173 | 0, /* src_mask */ |
174 | 0, /* dst_mask */ | |
b34976b6 | 175 | FALSE), /* pcrel_offset */ |
917583ad NC |
176 | |
177 | /* GNU extension to record C++ vtable member usage */ | |
178 | HOWTO (R_D10V_GNU_VTENTRY, /* type */ | |
179 | 0, /* rightshift */ | |
180 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
181 | 0, /* bitsize */ | |
b34976b6 | 182 | FALSE, /* pc_relative */ |
917583ad NC |
183 | 0, /* bitpos */ |
184 | complain_overflow_dont, /* complain_on_overflow */ | |
185 | _bfd_elf_rel_vtable_reloc_fn, /* special_function */ | |
186 | "R_D10V_GNU_VTENTRY", /* name */ | |
b34976b6 | 187 | FALSE, /* partial_inplace */ |
917583ad NC |
188 | 0, /* src_mask */ |
189 | 0, /* dst_mask */ | |
b34976b6 | 190 | FALSE), /* pcrel_offset */ |
917583ad | 191 | }; |
252b5132 RH |
192 | |
193 | /* Map BFD reloc types to D10V ELF reloc types. */ | |
194 | ||
195 | struct d10v_reloc_map | |
917583ad NC |
196 | { |
197 | bfd_reloc_code_real_type bfd_reloc_val; | |
198 | unsigned char elf_reloc_val; | |
199 | }; | |
200 | ||
201 | static const struct d10v_reloc_map d10v_reloc_map[] = | |
202 | { | |
203 | { BFD_RELOC_NONE, R_D10V_NONE, }, | |
204 | { BFD_RELOC_D10V_10_PCREL_R, R_D10V_10_PCREL_R }, | |
205 | { BFD_RELOC_D10V_10_PCREL_L, R_D10V_10_PCREL_L }, | |
206 | { BFD_RELOC_16, R_D10V_16 }, | |
207 | { BFD_RELOC_D10V_18, R_D10V_18 }, | |
208 | { BFD_RELOC_D10V_18_PCREL, R_D10V_18_PCREL }, | |
209 | { BFD_RELOC_32, R_D10V_32 }, | |
210 | { BFD_RELOC_VTABLE_INHERIT, R_D10V_GNU_VTINHERIT }, | |
211 | { BFD_RELOC_VTABLE_ENTRY, R_D10V_GNU_VTENTRY }, | |
212 | }; | |
252b5132 RH |
213 | |
214 | static reloc_howto_type * | |
215 | bfd_elf32_bfd_reloc_type_lookup (abfd, code) | |
5f771d47 | 216 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
217 | bfd_reloc_code_real_type code; |
218 | { | |
219 | unsigned int i; | |
220 | ||
221 | for (i = 0; | |
222 | i < sizeof (d10v_reloc_map) / sizeof (struct d10v_reloc_map); | |
223 | i++) | |
224 | { | |
225 | if (d10v_reloc_map[i].bfd_reloc_val == code) | |
226 | return &elf_d10v_howto_table[d10v_reloc_map[i].elf_reloc_val]; | |
227 | } | |
228 | ||
229 | return NULL; | |
230 | } | |
231 | ||
232 | /* Set the howto pointer for an D10V ELF reloc. */ | |
233 | ||
234 | static void | |
235 | d10v_info_to_howto_rel (abfd, cache_ptr, dst) | |
5f771d47 | 236 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 | 237 | arelent *cache_ptr; |
947216bf | 238 | Elf_Internal_Rela *dst; |
252b5132 RH |
239 | { |
240 | unsigned int r_type; | |
241 | ||
242 | r_type = ELF32_R_TYPE (dst->r_info); | |
243 | BFD_ASSERT (r_type < (unsigned int) R_D10V_max); | |
244 | cache_ptr->howto = &elf_d10v_howto_table[r_type]; | |
245 | } | |
246 | ||
247 | static asection * | |
1e2f5b6e AM |
248 | elf32_d10v_gc_mark_hook (sec, info, rel, h, sym) |
249 | asection *sec; | |
250 | struct bfd_link_info *info ATTRIBUTE_UNUSED; | |
251 | Elf_Internal_Rela *rel; | |
252 | struct elf_link_hash_entry *h; | |
253 | Elf_Internal_Sym *sym; | |
252b5132 RH |
254 | { |
255 | if (h != NULL) | |
256 | { | |
257 | switch (ELF32_R_TYPE (rel->r_info)) | |
258 | { | |
259 | case R_D10V_GNU_VTINHERIT: | |
260 | case R_D10V_GNU_VTENTRY: | |
261 | break; | |
262 | ||
263 | default: | |
264 | switch (h->root.type) | |
265 | { | |
266 | case bfd_link_hash_defined: | |
267 | case bfd_link_hash_defweak: | |
268 | return h->root.u.def.section; | |
269 | ||
270 | case bfd_link_hash_common: | |
271 | return h->root.u.c.p->section; | |
e049a0de ILT |
272 | |
273 | default: | |
274 | break; | |
252b5132 RH |
275 | } |
276 | } | |
277 | } | |
278 | else | |
1e2f5b6e AM |
279 | return bfd_section_from_elf_index (sec->owner, sym->st_shndx); |
280 | ||
252b5132 RH |
281 | return NULL; |
282 | } | |
283 | ||
b34976b6 | 284 | static bfd_boolean |
252b5132 | 285 | elf32_d10v_gc_sweep_hook (abfd, info, sec, relocs) |
5f771d47 ILT |
286 | bfd *abfd ATTRIBUTE_UNUSED; |
287 | struct bfd_link_info *info ATTRIBUTE_UNUSED; | |
288 | asection *sec ATTRIBUTE_UNUSED; | |
289 | const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED; | |
252b5132 RH |
290 | { |
291 | /* we don't use got and plt entries for d10v */ | |
b34976b6 | 292 | return TRUE; |
252b5132 RH |
293 | } |
294 | ||
295 | /* Look through the relocs for a section during the first phase. | |
296 | Since we don't do .gots or .plts, we just need to consider the | |
297 | virtual table relocs for gc. */ | |
a7c10850 | 298 | |
b34976b6 | 299 | static bfd_boolean |
252b5132 RH |
300 | elf32_d10v_check_relocs (abfd, info, sec, relocs) |
301 | bfd *abfd; | |
302 | struct bfd_link_info *info; | |
303 | asection *sec; | |
304 | const Elf_Internal_Rela *relocs; | |
305 | { | |
306 | Elf_Internal_Shdr *symtab_hdr; | |
307 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; | |
308 | const Elf_Internal_Rela *rel; | |
309 | const Elf_Internal_Rela *rel_end; | |
a7c10850 | 310 | |
1049f94e | 311 | if (info->relocatable) |
b34976b6 | 312 | return TRUE; |
a7c10850 | 313 | |
252b5132 RH |
314 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
315 | sym_hashes = elf_sym_hashes (abfd); | |
a7c10850 | 316 | sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof (Elf32_External_Sym); |
252b5132 RH |
317 | if (!elf_bad_symtab (abfd)) |
318 | sym_hashes_end -= symtab_hdr->sh_info; | |
a7c10850 | 319 | |
252b5132 RH |
320 | rel_end = relocs + sec->reloc_count; |
321 | for (rel = relocs; rel < rel_end; rel++) | |
322 | { | |
323 | struct elf_link_hash_entry *h; | |
324 | unsigned long r_symndx; | |
a7c10850 | 325 | |
252b5132 RH |
326 | r_symndx = ELF32_R_SYM (rel->r_info); |
327 | if (r_symndx < symtab_hdr->sh_info) | |
328 | h = NULL; | |
329 | else | |
973a3492 L |
330 | { |
331 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
332 | while (h->root.type == bfd_link_hash_indirect | |
333 | || h->root.type == bfd_link_hash_warning) | |
334 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
335 | } | |
a7c10850 | 336 | |
252b5132 RH |
337 | switch (ELF32_R_TYPE (rel->r_info)) |
338 | { | |
339 | /* This relocation describes the C++ object vtable hierarchy. | |
340 | Reconstruct it for later use during GC. */ | |
341 | case R_D10V_GNU_VTINHERIT: | |
c152c796 | 342 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
b34976b6 | 343 | return FALSE; |
252b5132 | 344 | break; |
a7c10850 | 345 | |
252b5132 RH |
346 | /* This relocation describes which C++ vtable entries are actually |
347 | used. Record for later use during GC. */ | |
348 | case R_D10V_GNU_VTENTRY: | |
c152c796 | 349 | if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset)) |
b34976b6 | 350 | return FALSE; |
252b5132 RH |
351 | break; |
352 | } | |
353 | } | |
a7c10850 | 354 | |
b34976b6 | 355 | return TRUE; |
252b5132 RH |
356 | } |
357 | ||
a2b0fe9d AM |
358 | static bfd_vma |
359 | extract_rel_addend (abfd, where, howto) | |
360 | bfd *abfd; | |
361 | bfd_byte *where; | |
362 | reloc_howto_type *howto; | |
363 | { | |
364 | bfd_vma insn, val; | |
365 | ||
366 | switch (howto->size) | |
367 | { | |
368 | case 0: | |
369 | insn = bfd_get_8 (abfd, where); | |
370 | break; | |
371 | case 1: | |
372 | insn = bfd_get_16 (abfd, where); | |
373 | break; | |
374 | case 2: | |
375 | insn = bfd_get_32 (abfd, where); | |
376 | break; | |
377 | default: | |
378 | abort (); | |
379 | } | |
380 | ||
381 | val = (insn & howto->dst_mask) >> howto->bitpos << howto->rightshift; | |
382 | /* We should really be testing for signed addends here, but we don't | |
383 | have that info directly in the howto. */ | |
384 | if (howto->pc_relative) | |
385 | { | |
386 | bfd_vma sign; | |
387 | sign = howto->dst_mask & (~howto->dst_mask >> 1 | ~(-(bfd_vma) 1 >> 1)); | |
388 | sign = sign >> howto->bitpos << howto->rightshift; | |
389 | val = (val ^ sign) - sign; | |
390 | } | |
391 | return val; | |
392 | } | |
393 | ||
394 | static void | |
395 | insert_rel_addend (abfd, where, howto, addend) | |
396 | bfd *abfd; | |
397 | bfd_byte *where; | |
398 | reloc_howto_type *howto; | |
399 | bfd_vma addend; | |
400 | { | |
401 | bfd_vma insn; | |
402 | ||
403 | addend = (addend >> howto->rightshift << howto->bitpos) & howto->dst_mask; | |
404 | insn = ~howto->dst_mask; | |
405 | switch (howto->size) | |
406 | { | |
407 | case 0: | |
408 | insn &= bfd_get_8 (abfd, where); | |
409 | insn |= addend; | |
410 | bfd_put_8 (abfd, insn, where); | |
411 | break; | |
412 | case 1: | |
413 | insn &= bfd_get_16 (abfd, where); | |
414 | insn |= addend; | |
415 | bfd_put_16 (abfd, insn, where); | |
416 | break; | |
417 | case 2: | |
418 | insn &= bfd_get_32 (abfd, where); | |
419 | insn |= addend; | |
420 | bfd_put_32 (abfd, insn, where); | |
421 | break; | |
422 | default: | |
423 | abort (); | |
424 | } | |
425 | } | |
426 | ||
252b5132 | 427 | /* Relocate a D10V ELF section. */ |
b34976b6 | 428 | static bfd_boolean |
252b5132 RH |
429 | elf32_d10v_relocate_section (output_bfd, info, input_bfd, input_section, |
430 | contents, relocs, local_syms, local_sections) | |
f8df10f4 | 431 | bfd *output_bfd; |
252b5132 RH |
432 | struct bfd_link_info *info; |
433 | bfd *input_bfd; | |
434 | asection *input_section; | |
435 | bfd_byte *contents; | |
436 | Elf_Internal_Rela *relocs; | |
437 | Elf_Internal_Sym *local_syms; | |
438 | asection **local_sections; | |
439 | { | |
440 | Elf_Internal_Shdr *symtab_hdr; | |
441 | struct elf_link_hash_entry **sym_hashes; | |
442 | Elf_Internal_Rela *rel, *relend; | |
443 | const char *name; | |
444 | ||
445 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
446 | sym_hashes = elf_sym_hashes (input_bfd); | |
447 | ||
448 | rel = relocs; | |
449 | relend = relocs + input_section->reloc_count; | |
450 | for (; rel < relend; rel++) | |
451 | { | |
452 | int r_type; | |
453 | reloc_howto_type *howto; | |
454 | unsigned long r_symndx; | |
455 | Elf_Internal_Sym *sym; | |
456 | asection *sec; | |
457 | struct elf_link_hash_entry *h; | |
458 | bfd_vma relocation; | |
459 | bfd_reloc_status_type r; | |
460 | ||
461 | r_symndx = ELF32_R_SYM (rel->r_info); | |
462 | r_type = ELF32_R_TYPE (rel->r_info); | |
463 | ||
464 | if (r_type == R_D10V_GNU_VTENTRY | |
465 | || r_type == R_D10V_GNU_VTINHERIT ) | |
466 | continue; | |
467 | ||
468 | howto = elf_d10v_howto_table + r_type; | |
469 | ||
1049f94e | 470 | if (info->relocatable) |
252b5132 | 471 | { |
a2b0fe9d AM |
472 | bfd_vma val; |
473 | bfd_byte *where; | |
474 | ||
1049f94e | 475 | /* This is a relocatable link. We don't have to change |
252b5132 RH |
476 | anything, unless the reloc is against a section symbol, |
477 | in which case we have to adjust according to where the | |
478 | section symbol winds up in the output section. */ | |
a2b0fe9d AM |
479 | if (r_symndx >= symtab_hdr->sh_info) |
480 | continue; | |
252b5132 | 481 | |
a2b0fe9d AM |
482 | sym = local_syms + r_symndx; |
483 | if (ELF_ST_TYPE (sym->st_info) != STT_SECTION) | |
484 | continue; | |
485 | ||
486 | sec = local_sections[r_symndx]; | |
487 | val = sec->output_offset; | |
488 | if (val == 0) | |
489 | continue; | |
490 | ||
491 | where = contents + rel->r_offset; | |
492 | val += extract_rel_addend (input_bfd, where, howto); | |
493 | insert_rel_addend (input_bfd, where, howto, val); | |
252b5132 RH |
494 | continue; |
495 | } | |
496 | ||
497 | /* This is a final link. */ | |
498 | h = NULL; | |
499 | sym = NULL; | |
500 | sec = NULL; | |
501 | if (r_symndx < symtab_hdr->sh_info) | |
502 | { | |
503 | sym = local_syms + r_symndx; | |
504 | sec = local_sections[r_symndx]; | |
a2b0fe9d AM |
505 | relocation = (sec->output_section->vma |
506 | + sec->output_offset | |
507 | + sym->st_value); | |
508 | if ((sec->flags & SEC_MERGE) | |
509 | && ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
510 | { | |
511 | asection *msec; | |
512 | bfd_vma addend; | |
513 | bfd_byte *where = contents + rel->r_offset; | |
514 | ||
515 | addend = extract_rel_addend (input_bfd, where, howto); | |
516 | msec = sec; | |
517 | addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend); | |
518 | addend -= relocation; | |
519 | addend += msec->output_section->vma + msec->output_offset; | |
520 | insert_rel_addend (input_bfd, where, howto, addend); | |
521 | } | |
252b5132 RH |
522 | } |
523 | else | |
524 | { | |
59c2e50f L |
525 | bfd_boolean unresolved_reloc, warned; |
526 | ||
b2a8e766 AM |
527 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
528 | r_symndx, symtab_hdr, sym_hashes, | |
529 | h, sec, relocation, | |
530 | unresolved_reloc, warned); | |
252b5132 RH |
531 | } |
532 | ||
533 | if (h != NULL) | |
534 | name = h->root.root.string; | |
535 | else | |
536 | { | |
537 | name = (bfd_elf_string_from_elf_section | |
538 | (input_bfd, symtab_hdr->sh_link, sym->st_name)); | |
539 | if (name == NULL || *name == '\0') | |
540 | name = bfd_section_name (input_bfd, sec); | |
541 | } | |
a7c10850 | 542 | |
252b5132 RH |
543 | r = _bfd_final_link_relocate (howto, input_bfd, input_section, |
544 | contents, rel->r_offset, | |
a2b0fe9d | 545 | relocation, (bfd_vma) 0); |
252b5132 RH |
546 | |
547 | if (r != bfd_reloc_ok) | |
548 | { | |
549 | const char * msg = (const char *) 0; | |
550 | ||
551 | switch (r) | |
552 | { | |
553 | case bfd_reloc_overflow: | |
554 | if (!((*info->callbacks->reloc_overflow) | |
dfeffb9f L |
555 | (info, (h ? &h->root : NULL), name, howto->name, |
556 | (bfd_vma) 0, input_bfd, input_section, | |
557 | rel->r_offset))) | |
b34976b6 | 558 | return FALSE; |
252b5132 RH |
559 | break; |
560 | ||
561 | case bfd_reloc_undefined: | |
562 | if (!((*info->callbacks->undefined_symbol) | |
563 | (info, name, input_bfd, input_section, | |
b34976b6 AM |
564 | rel->r_offset, TRUE))) |
565 | return FALSE; | |
252b5132 RH |
566 | break; |
567 | ||
568 | case bfd_reloc_outofrange: | |
517662d4 | 569 | msg = _("internal error: out of range error"); |
252b5132 RH |
570 | goto common_error; |
571 | ||
572 | case bfd_reloc_notsupported: | |
517662d4 | 573 | msg = _("internal error: unsupported relocation error"); |
252b5132 RH |
574 | goto common_error; |
575 | ||
576 | case bfd_reloc_dangerous: | |
517662d4 | 577 | msg = _("internal error: dangerous error"); |
252b5132 RH |
578 | goto common_error; |
579 | ||
580 | default: | |
517662d4 | 581 | msg = _("internal error: unknown error"); |
252b5132 RH |
582 | /* fall through */ |
583 | ||
584 | common_error: | |
585 | if (!((*info->callbacks->warning) | |
586 | (info, msg, name, input_bfd, input_section, | |
587 | rel->r_offset))) | |
b34976b6 | 588 | return FALSE; |
252b5132 RH |
589 | break; |
590 | } | |
591 | } | |
592 | } | |
593 | ||
b34976b6 | 594 | return TRUE; |
252b5132 RH |
595 | } |
596 | #define ELF_ARCH bfd_arch_d10v | |
aa4f99bb AO |
597 | #define ELF_MACHINE_CODE EM_D10V |
598 | #define ELF_MACHINE_ALT1 EM_CYGNUS_D10V | |
252b5132 RH |
599 | #define ELF_MAXPAGESIZE 0x1000 |
600 | ||
601 | #define TARGET_BIG_SYM bfd_elf32_d10v_vec | |
602 | #define TARGET_BIG_NAME "elf32-d10v" | |
603 | ||
604 | #define elf_info_to_howto 0 | |
605 | #define elf_info_to_howto_rel d10v_info_to_howto_rel | |
606 | #define elf_backend_object_p 0 | |
607 | #define elf_backend_final_write_processing 0 | |
608 | #define elf_backend_gc_mark_hook elf32_d10v_gc_mark_hook | |
609 | #define elf_backend_gc_sweep_hook elf32_d10v_gc_sweep_hook | |
610 | #define elf_backend_check_relocs elf32_d10v_check_relocs | |
611 | #define elf_backend_relocate_section elf32_d10v_relocate_section | |
612 | #define elf_backend_can_gc_sections 1 | |
613 | ||
614 | #include "elf32-target.h" |