Commit | Line | Data |
---|---|---|
b3baf5d0 | 1 | /* OpenRISC-specific support for 32-bit ELF. |
47b0e7ad | 2 | Copyright 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. |
b3baf5d0 NC |
3 | Contributed by Johan Rydberg, jrydberg@opencores.org |
4 | ||
47b0e7ad | 5 | This file is part of BFD, the Binary File Descriptor library. |
b3baf5d0 | 6 | |
47b0e7ad NC |
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. | |
b3baf5d0 | 11 | |
47b0e7ad NC |
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. | |
b3baf5d0 | 16 | |
47b0e7ad NC |
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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, | |
20 | USA. */ | |
b3baf5d0 NC |
21 | |
22 | #include "bfd.h" | |
23 | #include "sysdep.h" | |
24 | #include "libbfd.h" | |
25 | #include "elf-bfd.h" | |
26 | #include "elf/openrisc.h" | |
27 | #include "libiberty.h" | |
28 | ||
b3baf5d0 | 29 | static reloc_howto_type openrisc_elf_howto_table[] = |
47b0e7ad | 30 | { |
b3baf5d0 NC |
31 | /* This reloc does nothing. */ |
32 | HOWTO (R_OPENRISC_NONE, /* type */ | |
33 | 0, /* rightshift */ | |
34 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
35 | 32, /* bitsize */ | |
b34976b6 | 36 | FALSE, /* pc_relative */ |
b3baf5d0 NC |
37 | 0, /* bitpos */ |
38 | complain_overflow_bitfield, /* complain_on_overflow */ | |
39 | bfd_elf_generic_reloc, /* special_function */ | |
40 | "R_OPENRISC_NONE", /* name */ | |
b34976b6 | 41 | FALSE, /* partial_inplace */ |
b3baf5d0 NC |
42 | 0, /* src_mask */ |
43 | 0, /* dst_mask */ | |
b34976b6 | 44 | FALSE), /* pcrel_offset */ |
b3baf5d0 NC |
45 | |
46 | /* A PC relative 26 bit relocation, right shifted by 2. */ | |
47 | HOWTO (R_OPENRISC_INSN_REL_26, /* type */ | |
48 | 2, /* rightshift */ | |
49 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
50 | 26, /* bitsize */ | |
b34976b6 | 51 | TRUE, /* pc_relative */ |
b3baf5d0 NC |
52 | 0, /* bitpos */ |
53 | complain_overflow_signed, /* complain_on_overflow */ | |
54 | bfd_elf_generic_reloc, /* special_function */ | |
55 | "R_OPENRISC_INSN_REL_26", /* name */ | |
b34976b6 | 56 | FALSE, /* partial_inplace */ |
b3baf5d0 NC |
57 | 0x00000000, /* src_mask */ |
58 | 0x03ffffff, /* dst_mask */ | |
b34976b6 | 59 | FALSE), /* pcrel_offset */ |
b3baf5d0 NC |
60 | |
61 | /* A absolute 26 bit relocation, right shifted by 2. */ | |
62 | HOWTO (R_OPENRISC_INSN_ABS_26, /* type */ | |
63 | 2, /* rightshift */ | |
64 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
65 | 26, /* bitsize */ | |
b34976b6 | 66 | FALSE, /* pc_relative */ |
b3baf5d0 NC |
67 | 0, /* bitpos */ |
68 | complain_overflow_signed, /* complain_on_overflow */ | |
69 | bfd_elf_generic_reloc, /* special_function */ | |
70 | "R_OPENRISC_INSN_ABS_26", /* name */ | |
b34976b6 | 71 | FALSE, /* partial_inplace */ |
b3baf5d0 NC |
72 | 0x00000000, /* src_mask */ |
73 | 0x03ffffff, /* dst_mask */ | |
b34976b6 | 74 | FALSE), /* pcrel_offset */ |
b3baf5d0 NC |
75 | |
76 | HOWTO (R_OPENRISC_LO_16_IN_INSN, /* type */ | |
77 | 0, /* rightshift */ | |
c7e40348 | 78 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
b3baf5d0 | 79 | 16, /* bitsize */ |
b34976b6 | 80 | FALSE, /* pc_relative */ |
b3baf5d0 | 81 | 0, /* bitpos */ |
c7e40348 | 82 | complain_overflow_dont, /* complain_on_overflow */ |
b3baf5d0 NC |
83 | bfd_elf_generic_reloc, /* special_function */ |
84 | "R_OPENRISC_LO_16_IN_INSN", /* name */ | |
b34976b6 | 85 | FALSE, /* partial_inplace */ |
c7e40348 | 86 | 0, /* src_mask */ |
b3baf5d0 | 87 | 0x0000ffff, /* dst_mask */ |
b34976b6 | 88 | FALSE), /* pcrel_offset */ |
b3baf5d0 NC |
89 | |
90 | HOWTO (R_OPENRISC_HI_16_IN_INSN, /* type */ | |
91 | 16, /* rightshift */ | |
c7e40348 | 92 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
b3baf5d0 | 93 | 16, /* bitsize */ |
b34976b6 | 94 | FALSE, /* pc_relative */ |
b3baf5d0 | 95 | 0, /* bitpos */ |
c7e40348 | 96 | complain_overflow_dont, /* complain_on_overflow */ |
b3baf5d0 NC |
97 | bfd_elf_generic_reloc, /* special_function */ |
98 | "R_OPENRISC_HI_16_IN_INSN", /* name */ | |
b34976b6 | 99 | FALSE, /* partial_inplace */ |
c7e40348 | 100 | 0, /* src_mask */ |
b3baf5d0 | 101 | 0x0000ffff, /* dst_mask */ |
b34976b6 | 102 | FALSE), /* pcrel_offset */ |
b3baf5d0 NC |
103 | |
104 | /* An 8 bit absolute relocation. */ | |
105 | HOWTO (R_OPENRISC_8, /* type */ | |
106 | 0, /* rightshift */ | |
107 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
108 | 8, /* bitsize */ | |
b34976b6 | 109 | FALSE, /* pc_relative */ |
b3baf5d0 NC |
110 | 0, /* bitpos */ |
111 | complain_overflow_bitfield, /* complain_on_overflow */ | |
112 | bfd_elf_generic_reloc, /* special_function */ | |
113 | "R_OPENRISC_8", /* name */ | |
b34976b6 | 114 | TRUE, /* partial_inplace */ |
b3baf5d0 NC |
115 | 0x0000, /* src_mask */ |
116 | 0x00ff, /* dst_mask */ | |
b34976b6 | 117 | FALSE), /* pcrel_offset */ |
b3baf5d0 NC |
118 | |
119 | /* A 16 bit absolute relocation. */ | |
120 | HOWTO (R_OPENRISC_16, /* type */ | |
121 | 0, /* rightshift */ | |
122 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
123 | 16, /* bitsize */ | |
b34976b6 | 124 | FALSE, /* pc_relative */ |
b3baf5d0 NC |
125 | 0, /* bitpos */ |
126 | complain_overflow_bitfield, /* complain_on_overflow */ | |
127 | bfd_elf_generic_reloc, /* special_function */ | |
128 | "R_OPENRISC_16", /* name */ | |
b34976b6 | 129 | TRUE, /* partial_inplace */ |
b3baf5d0 NC |
130 | 0x00000000, /* src_mask */ |
131 | 0x0000ffff, /* dst_mask */ | |
b34976b6 | 132 | FALSE), /* pcrel_offset */ |
b3baf5d0 NC |
133 | |
134 | /* A 32 bit absolute relocation. */ | |
135 | HOWTO (R_OPENRISC_32, /* type */ | |
136 | 0, /* rightshift */ | |
137 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
138 | 32, /* bitsize */ | |
b34976b6 | 139 | FALSE, /* pc_relative */ |
b3baf5d0 NC |
140 | 0, /* bitpos */ |
141 | complain_overflow_bitfield, /* complain_on_overflow */ | |
142 | bfd_elf_generic_reloc, /* special_function */ | |
143 | "R_OPENRISC_32", /* name */ | |
b34976b6 | 144 | TRUE, /* partial_inplace */ |
b3baf5d0 NC |
145 | 0x00000000, /* src_mask */ |
146 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 147 | FALSE), /* pcrel_offset */ |
b3baf5d0 | 148 | |
47b0e7ad | 149 | /* GNU extension to record C++ vtable hierarchy. */ |
b3baf5d0 NC |
150 | HOWTO (R_OPENRISC_GNU_VTINHERIT, /* type */ |
151 | 0, /* rightshift */ | |
152 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
153 | 0, /* bitsize */ | |
b34976b6 | 154 | FALSE, /* pc_relative */ |
b3baf5d0 NC |
155 | 0, /* bitpos */ |
156 | complain_overflow_dont, /* complain_on_overflow */ | |
157 | NULL, /* special_function */ | |
158 | "R_OPENRISC_GNU_VTINHERIT", /* name */ | |
b34976b6 | 159 | FALSE, /* partial_inplace */ |
b3baf5d0 NC |
160 | 0, /* src_mask */ |
161 | 0, /* dst_mask */ | |
b34976b6 | 162 | FALSE), /* pcrel_offset */ |
b3baf5d0 | 163 | |
47b0e7ad | 164 | /* GNU extension to record C++ vtable member usage. */ |
b3baf5d0 NC |
165 | HOWTO (R_OPENRISC_GNU_VTENTRY, /* type */ |
166 | 0, /* rightshift */ | |
167 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
168 | 0, /* bitsize */ | |
b34976b6 | 169 | FALSE, /* pc_relative */ |
b3baf5d0 NC |
170 | 0, /* bitpos */ |
171 | complain_overflow_dont, /* complain_on_overflow */ | |
172 | _bfd_elf_rel_vtable_reloc_fn, /* special_function */ | |
173 | "R_OPENRISC_GNU_VTENTRY", /* name */ | |
b34976b6 | 174 | FALSE, /* partial_inplace */ |
b3baf5d0 NC |
175 | 0, /* src_mask */ |
176 | 0, /* dst_mask */ | |
b34976b6 | 177 | FALSE), /* pcrel_offset */ |
b3baf5d0 NC |
178 | }; |
179 | ||
180 | /* Map BFD reloc types to OpenRISC ELF reloc types. */ | |
181 | ||
182 | struct openrisc_reloc_map | |
47b0e7ad NC |
183 | { |
184 | bfd_reloc_code_real_type bfd_reloc_val; | |
185 | unsigned int openrisc_reloc_val; | |
186 | }; | |
b3baf5d0 NC |
187 | |
188 | static const struct openrisc_reloc_map openrisc_reloc_map[] = | |
47b0e7ad NC |
189 | { |
190 | { BFD_RELOC_NONE, R_OPENRISC_NONE }, | |
191 | { BFD_RELOC_32, R_OPENRISC_32 }, | |
192 | { BFD_RELOC_16, R_OPENRISC_16 }, | |
193 | { BFD_RELOC_8, R_OPENRISC_8 }, | |
194 | { BFD_RELOC_OPENRISC_REL_26,R_OPENRISC_INSN_REL_26 }, | |
195 | { BFD_RELOC_OPENRISC_ABS_26,R_OPENRISC_INSN_ABS_26 }, | |
b3baf5d0 | 196 | { BFD_RELOC_HI16, R_OPENRISC_HI_16_IN_INSN }, |
47b0e7ad NC |
197 | { BFD_RELOC_LO16, R_OPENRISC_LO_16_IN_INSN }, |
198 | { BFD_RELOC_VTABLE_INHERIT, R_OPENRISC_GNU_VTINHERIT }, | |
199 | { BFD_RELOC_VTABLE_ENTRY, R_OPENRISC_GNU_VTENTRY } | |
200 | }; | |
b3baf5d0 NC |
201 | |
202 | static reloc_howto_type * | |
47b0e7ad NC |
203 | openrisc_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, |
204 | bfd_reloc_code_real_type code) | |
b3baf5d0 NC |
205 | { |
206 | unsigned int i; | |
207 | ||
208 | for (i = ARRAY_SIZE (openrisc_reloc_map); --i;) | |
209 | if (openrisc_reloc_map[i].bfd_reloc_val == code) | |
210 | return & openrisc_elf_howto_table[openrisc_reloc_map[i]. | |
211 | openrisc_reloc_val]; | |
212 | ||
213 | return NULL; | |
214 | } | |
215 | ||
216 | /* Set the howto pointer for an OpenRISC ELF reloc. */ | |
217 | ||
218 | static void | |
47b0e7ad NC |
219 | openrisc_info_to_howto_rela (bfd * abfd ATTRIBUTE_UNUSED, |
220 | arelent * cache_ptr, | |
221 | Elf_Internal_Rela * dst) | |
b3baf5d0 NC |
222 | { |
223 | unsigned int r_type; | |
224 | ||
225 | r_type = ELF32_R_TYPE (dst->r_info); | |
226 | BFD_ASSERT (r_type < (unsigned int) R_OPENRISC_max); | |
227 | cache_ptr->howto = & openrisc_elf_howto_table[r_type]; | |
228 | } | |
229 | ||
230 | /* Perform a single relocation. By default we use the standard BFD | |
231 | routines, but a few relocs, we have to do them ourselves. */ | |
232 | ||
233 | static bfd_reloc_status_type | |
47b0e7ad NC |
234 | openrisc_final_link_relocate (reloc_howto_type *howto, |
235 | bfd *input_bfd, | |
236 | asection *input_section, | |
237 | bfd_byte *contents, | |
238 | Elf_Internal_Rela *rel, | |
239 | bfd_vma relocation) | |
b3baf5d0 NC |
240 | { |
241 | bfd_reloc_status_type r = bfd_reloc_ok; | |
242 | ||
243 | switch (howto->type) | |
244 | { | |
245 | case R_OPENRISC_LO_16_IN_INSN: | |
246 | relocation &= 0xffff; | |
247 | r = _bfd_final_link_relocate (howto, input_bfd, input_section, | |
248 | contents, rel->r_offset, | |
249 | relocation, rel->r_addend); | |
250 | break; | |
251 | ||
252 | default: | |
253 | r = _bfd_final_link_relocate (howto, input_bfd, input_section, | |
254 | contents, rel->r_offset, | |
255 | relocation, rel->r_addend); | |
256 | } | |
257 | ||
258 | return r; | |
259 | } | |
260 | ||
261 | /* Relocate an OpenRISC ELF section. | |
b3baf5d0 NC |
262 | |
263 | The RELOCATE_SECTION function is called by the new ELF backend linker | |
264 | to handle the relocations for a section. | |
265 | ||
266 | The relocs are always passed as Rela structures; if the section | |
267 | actually uses Rel structures, the r_addend field will always be | |
268 | zero. | |
269 | ||
270 | This function is responsible for adjusting the section contents as | |
1049f94e | 271 | necessary, and (if using Rela relocs and generating a relocatable |
b3baf5d0 NC |
272 | output file) adjusting the reloc addend as necessary. |
273 | ||
274 | This function does not have to worry about setting the reloc | |
275 | address or the reloc symbol index. | |
276 | ||
277 | LOCAL_SYMS is a pointer to the swapped in local symbols. | |
278 | ||
279 | LOCAL_SECTIONS is an array giving the section in the input file | |
280 | corresponding to the st_shndx field of each local symbol. | |
281 | ||
282 | The global hash table entry for the global symbols can be found | |
283 | via elf_sym_hashes (input_bfd). | |
284 | ||
1049f94e | 285 | When generating relocatable output, this function must handle |
b3baf5d0 NC |
286 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is |
287 | going to be the section symbol corresponding to the output | |
288 | section, which means that the addend must be adjusted | |
289 | accordingly. */ | |
290 | ||
b34976b6 | 291 | static bfd_boolean |
47b0e7ad NC |
292 | openrisc_elf_relocate_section (bfd *output_bfd, |
293 | struct bfd_link_info *info, | |
294 | bfd *input_bfd, | |
295 | asection *input_section, | |
296 | bfd_byte *contents, | |
297 | Elf_Internal_Rela *relocs, | |
298 | Elf_Internal_Sym *local_syms, | |
299 | asection **local_sections) | |
b3baf5d0 NC |
300 | { |
301 | Elf_Internal_Shdr *symtab_hdr; | |
302 | struct elf_link_hash_entry **sym_hashes; | |
303 | Elf_Internal_Rela *rel; | |
304 | Elf_Internal_Rela *relend; | |
305 | ||
1049f94e | 306 | if (info->relocatable) |
b34976b6 | 307 | return TRUE; |
b491616a | 308 | |
b3baf5d0 NC |
309 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
310 | sym_hashes = elf_sym_hashes (input_bfd); | |
311 | relend = relocs + input_section->reloc_count; | |
312 | ||
313 | for (rel = relocs; rel < relend; rel++) | |
314 | { | |
315 | reloc_howto_type *howto; | |
316 | unsigned long r_symndx; | |
317 | Elf_Internal_Sym *sym; | |
318 | asection *sec; | |
319 | struct elf_link_hash_entry *h; | |
320 | bfd_vma relocation; | |
321 | bfd_reloc_status_type r; | |
322 | const char *name = NULL; | |
323 | int r_type; | |
324 | ||
325 | r_type = ELF32_R_TYPE (rel->r_info); | |
326 | r_symndx = ELF32_R_SYM (rel->r_info); | |
327 | ||
328 | if (r_type == R_OPENRISC_GNU_VTINHERIT | |
329 | || r_type == R_OPENRISC_GNU_VTENTRY) | |
330 | continue; | |
331 | ||
b3baf5d0 NC |
332 | if ((unsigned int) r_type > |
333 | (sizeof openrisc_elf_howto_table / sizeof (reloc_howto_type))) | |
334 | abort (); | |
335 | ||
336 | /* This is a final link. */ | |
337 | howto = openrisc_elf_howto_table + ELF32_R_TYPE (rel->r_info); | |
338 | h = NULL; | |
339 | sym = NULL; | |
340 | sec = NULL; | |
341 | ||
342 | if (r_symndx < symtab_hdr->sh_info) | |
343 | { | |
344 | sym = local_syms + r_symndx; | |
345 | sec = local_sections[r_symndx]; | |
8517fae7 | 346 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); |
b3baf5d0 NC |
347 | |
348 | name = bfd_elf_string_from_elf_section | |
349 | (input_bfd, symtab_hdr->sh_link, sym->st_name); | |
350 | name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name; | |
351 | } | |
352 | else | |
353 | { | |
59c2e50f | 354 | bfd_boolean unresolved_reloc, warned; |
b3baf5d0 | 355 | |
b2a8e766 AM |
356 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
357 | r_symndx, symtab_hdr, sym_hashes, | |
358 | h, sec, relocation, | |
359 | unresolved_reloc, warned); | |
b3baf5d0 NC |
360 | } |
361 | ||
362 | r = openrisc_final_link_relocate (howto, input_bfd, input_section, | |
363 | contents, rel, relocation); | |
364 | ||
365 | if (r != bfd_reloc_ok) | |
366 | { | |
47b0e7ad | 367 | const char *msg = NULL; |
b3baf5d0 NC |
368 | |
369 | switch (r) | |
370 | { | |
371 | case bfd_reloc_overflow: | |
372 | r = info->callbacks->reloc_overflow | |
dfeffb9f L |
373 | (info, (h ? &h->root : NULL), name, howto->name, |
374 | (bfd_vma) 0, input_bfd, input_section, rel->r_offset); | |
b3baf5d0 NC |
375 | break; |
376 | ||
377 | case bfd_reloc_undefined: | |
378 | r = info->callbacks->undefined_symbol | |
b34976b6 | 379 | (info, name, input_bfd, input_section, rel->r_offset, TRUE); |
b3baf5d0 NC |
380 | break; |
381 | ||
382 | case bfd_reloc_outofrange: | |
383 | msg = _("internal error: out of range error"); | |
384 | break; | |
385 | ||
386 | case bfd_reloc_notsupported: | |
387 | msg = _("internal error: unsupported relocation error"); | |
388 | break; | |
389 | ||
390 | case bfd_reloc_dangerous: | |
391 | msg = _("internal error: dangerous relocation"); | |
392 | break; | |
393 | ||
394 | default: | |
395 | msg = _("internal error: unknown error"); | |
396 | break; | |
397 | } | |
398 | ||
399 | if (msg) | |
400 | r = info->callbacks->warning | |
401 | (info, msg, name, input_bfd, input_section, rel->r_offset); | |
402 | ||
403 | if (!r) | |
b34976b6 | 404 | return FALSE; |
b3baf5d0 NC |
405 | } |
406 | } | |
407 | ||
b34976b6 | 408 | return TRUE; |
b3baf5d0 NC |
409 | } |
410 | ||
411 | /* Return the section that should be marked against GC for a given | |
412 | relocation. */ | |
413 | ||
414 | static asection * | |
47b0e7ad NC |
415 | openrisc_elf_gc_mark_hook (asection *sec, |
416 | struct bfd_link_info *info ATTRIBUTE_UNUSED, | |
417 | Elf_Internal_Rela *rel, | |
418 | struct elf_link_hash_entry *h, | |
419 | Elf_Internal_Sym *sym) | |
b3baf5d0 | 420 | { |
47b0e7ad NC |
421 | if (h == NULL) |
422 | return bfd_section_from_elf_index (sec->owner, sym->st_shndx); | |
423 | ||
424 | switch (ELF32_R_TYPE (rel->r_info)) | |
b3baf5d0 | 425 | { |
47b0e7ad NC |
426 | case R_OPENRISC_GNU_VTINHERIT: |
427 | case R_OPENRISC_GNU_VTENTRY: | |
428 | break; | |
b3baf5d0 | 429 | |
47b0e7ad NC |
430 | default: |
431 | switch (h->root.type) | |
432 | { | |
433 | case bfd_link_hash_defined: | |
434 | case bfd_link_hash_defweak: | |
435 | return h->root.u.def.section; | |
b3baf5d0 | 436 | |
47b0e7ad NC |
437 | case bfd_link_hash_common: |
438 | return h->root.u.c.p->section; | |
b3baf5d0 | 439 | |
47b0e7ad NC |
440 | default: |
441 | break; | |
b3baf5d0 NC |
442 | } |
443 | } | |
b3baf5d0 NC |
444 | |
445 | return NULL; | |
446 | } | |
447 | ||
448 | /* Update the got entry reference counts for the section being removed. */ | |
449 | ||
b34976b6 | 450 | static bfd_boolean |
47b0e7ad NC |
451 | openrisc_elf_gc_sweep_hook (bfd *abfd ATTRIBUTE_UNUSED, |
452 | struct bfd_link_info *info ATTRIBUTE_UNUSED, | |
453 | asection *sec ATTRIBUTE_UNUSED, | |
454 | const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED) | |
b3baf5d0 | 455 | { |
b34976b6 | 456 | return TRUE; |
b3baf5d0 NC |
457 | } |
458 | ||
459 | /* Look through the relocs for a section during the first phase. | |
460 | Since we don't do .gots or .plts, we just need to consider the | |
461 | virtual table relocs for gc. */ | |
462 | ||
b34976b6 | 463 | static bfd_boolean |
47b0e7ad NC |
464 | openrisc_elf_check_relocs (bfd *abfd, |
465 | struct bfd_link_info *info, | |
466 | asection *sec, | |
467 | const Elf_Internal_Rela *relocs) | |
b3baf5d0 NC |
468 | { |
469 | Elf_Internal_Shdr *symtab_hdr; | |
470 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; | |
471 | const Elf_Internal_Rela *rel; | |
472 | const Elf_Internal_Rela *rel_end; | |
473 | ||
1049f94e | 474 | if (info->relocatable) |
b34976b6 | 475 | return TRUE; |
b3baf5d0 NC |
476 | |
477 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
478 | sym_hashes = elf_sym_hashes (abfd); | |
479 | sym_hashes_end = | |
480 | sym_hashes + symtab_hdr->sh_size / sizeof (Elf32_External_Sym); | |
481 | if (!elf_bad_symtab (abfd)) | |
482 | sym_hashes_end -= symtab_hdr->sh_info; | |
483 | ||
484 | rel_end = relocs + sec->reloc_count; | |
485 | for (rel = relocs; rel < rel_end; rel++) | |
486 | { | |
487 | struct elf_link_hash_entry *h; | |
488 | unsigned long r_symndx; | |
489 | ||
490 | r_symndx = ELF32_R_SYM (rel->r_info); | |
491 | if (r_symndx < symtab_hdr->sh_info) | |
492 | h = NULL; | |
493 | else | |
973a3492 L |
494 | { |
495 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
496 | while (h->root.type == bfd_link_hash_indirect | |
497 | || h->root.type == bfd_link_hash_warning) | |
498 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
499 | } | |
b3baf5d0 NC |
500 | |
501 | switch (ELF32_R_TYPE (rel->r_info)) | |
502 | { | |
503 | /* This relocation describes the C++ object vtable hierarchy. | |
504 | Reconstruct it for later use during GC. */ | |
505 | case R_OPENRISC_GNU_VTINHERIT: | |
c152c796 | 506 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
b34976b6 | 507 | return FALSE; |
b3baf5d0 NC |
508 | break; |
509 | ||
510 | /* This relocation describes which C++ vtable entries are actually | |
511 | used. Record for later use during GC. */ | |
512 | case R_OPENRISC_GNU_VTENTRY: | |
c152c796 | 513 | if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) |
b34976b6 | 514 | return FALSE; |
b3baf5d0 NC |
515 | break; |
516 | } | |
517 | } | |
518 | ||
b34976b6 | 519 | return TRUE; |
b3baf5d0 NC |
520 | } |
521 | ||
522 | /* Set the right machine number. */ | |
523 | ||
b34976b6 | 524 | static bfd_boolean |
47b0e7ad | 525 | openrisc_elf_object_p (bfd *abfd) |
b3baf5d0 | 526 | { |
47b0e7ad | 527 | bfd_default_set_arch_mach (abfd, bfd_arch_openrisc, 0); |
b34976b6 | 528 | return TRUE; |
b3baf5d0 NC |
529 | } |
530 | ||
531 | /* Store the machine number in the flags field. */ | |
532 | ||
533 | static void | |
47b0e7ad NC |
534 | openrisc_elf_final_write_processing (bfd *abfd, |
535 | bfd_boolean linker ATTRIBUTE_UNUSED) | |
b3baf5d0 NC |
536 | { |
537 | unsigned long val; | |
538 | ||
539 | switch (bfd_get_mach (abfd)) | |
540 | { | |
541 | default: | |
542 | val = 0; | |
543 | break; | |
544 | } | |
545 | ||
546 | elf_elfheader (abfd)->e_flags &= ~0xf; | |
547 | elf_elfheader (abfd)->e_flags |= val; | |
548 | } | |
549 | ||
550 | ||
551 | #define ELF_ARCH bfd_arch_openrisc | |
552 | #define ELF_MACHINE_CODE EM_OPENRISC | |
c11cc227 | 553 | #define ELF_MACHINE_ALT1 EM_OPENRISC_OLD |
b3baf5d0 NC |
554 | #define ELF_MAXPAGESIZE 0x1000 |
555 | ||
556 | #define TARGET_BIG_SYM bfd_elf32_openrisc_vec | |
557 | #define TARGET_BIG_NAME "elf32-openrisc" | |
558 | ||
559 | #define elf_info_to_howto_rel NULL | |
560 | #define elf_info_to_howto openrisc_info_to_howto_rela | |
561 | #define elf_backend_relocate_section openrisc_elf_relocate_section | |
562 | #define elf_backend_gc_mark_hook openrisc_elf_gc_mark_hook | |
563 | #define elf_backend_gc_sweep_hook openrisc_elf_gc_sweep_hook | |
564 | #define elf_backend_check_relocs openrisc_elf_check_relocs | |
565 | ||
566 | #define elf_backend_can_gc_sections 1 | |
b491616a | 567 | #define elf_backend_rela_normal 1 |
b3baf5d0 NC |
568 | |
569 | #define bfd_elf32_bfd_reloc_type_lookup openrisc_reloc_type_lookup | |
570 | ||
571 | #define elf_backend_object_p openrisc_elf_object_p | |
572 | #define elf_backend_final_write_processing openrisc_elf_final_write_processing | |
573 | ||
574 | #include "elf32-target.h" |