1 | /* CRIS-specific support for 32-bit ELF.
|
---|
2 | Copyright 2000, 2001 Free Software Foundation, Inc.
|
---|
3 | Contributed by Axis Communications AB.
|
---|
4 | Written by Hans-Peter Nilsson, based on elf32-fr30.c
|
---|
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
|
---|
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
---|
21 |
|
---|
22 | #include "bfd.h"
|
---|
23 | #include "sysdep.h"
|
---|
24 | #include "libbfd.h"
|
---|
25 | #include "elf-bfd.h"
|
---|
26 | #include "elf/cris.h"
|
---|
27 |
|
---|
28 | /* Forward declarations. */
|
---|
29 | static reloc_howto_type * cris_reloc_type_lookup
|
---|
30 | PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
|
---|
31 |
|
---|
32 | static void cris_info_to_howto_rela
|
---|
33 | PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *));
|
---|
34 |
|
---|
35 | static boolean cris_elf_relocate_section
|
---|
36 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
|
---|
37 | Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
|
---|
38 |
|
---|
39 | static bfd_reloc_status_type cris_final_link_relocate
|
---|
40 | PARAMS ((reloc_howto_type *, bfd *, asection *, bfd_byte *,
|
---|
41 | Elf_Internal_Rela *, bfd_vma));
|
---|
42 |
|
---|
43 | static boolean cris_elf_gc_sweep_hook
|
---|
44 | PARAMS ((bfd *, struct bfd_link_info *, asection *,
|
---|
45 | const Elf_Internal_Rela *));
|
---|
46 |
|
---|
47 | static asection * cris_elf_gc_mark_hook
|
---|
48 | PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *,
|
---|
49 | struct elf_link_hash_entry *, Elf_Internal_Sym *));
|
---|
50 |
|
---|
51 | static boolean cris_elf_object_p PARAMS ((bfd *));
|
---|
52 |
|
---|
53 | static void cris_elf_final_write_processing PARAMS ((bfd *, boolean));
|
---|
54 |
|
---|
55 | static boolean cris_elf_print_private_bfd_data PARAMS ((bfd *, PTR));
|
---|
56 |
|
---|
57 | static boolean cris_elf_merge_private_bfd_data PARAMS ((bfd *, bfd *));
|
---|
58 |
|
---|
59 | static reloc_howto_type cris_elf_howto_table [] =
|
---|
60 | {
|
---|
61 | /* This reloc does nothing. */
|
---|
62 | HOWTO (R_CRIS_NONE, /* type */
|
---|
63 | 0, /* rightshift */
|
---|
64 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
65 | 32, /* bitsize */
|
---|
66 | false, /* pc_relative */
|
---|
67 | 0, /* bitpos */
|
---|
68 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
69 | bfd_elf_generic_reloc, /* special_function */
|
---|
70 | "R_CRIS_NONE", /* name */
|
---|
71 | false, /* partial_inplace */
|
---|
72 | 0, /* src_mask */
|
---|
73 | 0, /* dst_mask */
|
---|
74 | false), /* pcrel_offset */
|
---|
75 |
|
---|
76 | /* An 8 bit absolute relocation. */
|
---|
77 | HOWTO (R_CRIS_8, /* type */
|
---|
78 | 0, /* rightshift */
|
---|
79 | 0, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
80 | 8, /* bitsize */
|
---|
81 | false, /* pc_relative */
|
---|
82 | 0, /* bitpos */
|
---|
83 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
84 | bfd_elf_generic_reloc, /* special_function */
|
---|
85 | "R_CRIS_8", /* name */
|
---|
86 | false, /* partial_inplace */
|
---|
87 | 0x0000, /* src_mask */
|
---|
88 | 0x00ff, /* dst_mask */
|
---|
89 | false), /* pcrel_offset */
|
---|
90 |
|
---|
91 | /* A 16 bit absolute relocation. */
|
---|
92 | HOWTO (R_CRIS_16, /* type */
|
---|
93 | 0, /* rightshift */
|
---|
94 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
95 | 16, /* bitsize */
|
---|
96 | false, /* pc_relative */
|
---|
97 | 0, /* bitpos */
|
---|
98 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
99 | bfd_elf_generic_reloc, /* special_function */
|
---|
100 | "R_CRIS_16", /* name */
|
---|
101 | false, /* partial_inplace */
|
---|
102 | 0x00000000, /* src_mask */
|
---|
103 | 0x0000ffff, /* dst_mask */
|
---|
104 | false), /* pcrel_offset */
|
---|
105 |
|
---|
106 | /* A 32 bit absolute relocation. */
|
---|
107 | HOWTO (R_CRIS_32, /* type */
|
---|
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 */
|
---|
114 | bfd_elf_generic_reloc, /* special_function */
|
---|
115 | "R_CRIS_32", /* name */
|
---|
116 | false, /* partial_inplace */
|
---|
117 | 0x00000000, /* src_mask */
|
---|
118 | 0xffffffff, /* dst_mask */
|
---|
119 | false), /* pcrel_offset */
|
---|
120 |
|
---|
121 | /* An 8 bit absolute relocation. */
|
---|
122 | HOWTO (R_CRIS_8_PCREL, /* type */
|
---|
123 | 0, /* rightshift */
|
---|
124 | 0, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
125 | 8, /* bitsize */
|
---|
126 | true, /* pc_relative */
|
---|
127 | 0, /* bitpos */
|
---|
128 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
129 | bfd_elf_generic_reloc, /* special_function */
|
---|
130 | "R_CRIS_8_PCREL", /* name */
|
---|
131 | false, /* partial_inplace */
|
---|
132 | 0x0000, /* src_mask */
|
---|
133 | 0x00ff, /* dst_mask */
|
---|
134 | false), /* pcrel_offset */
|
---|
135 |
|
---|
136 | /* A 16 bit absolute relocation. */
|
---|
137 | HOWTO (R_CRIS_16_PCREL, /* type */
|
---|
138 | 0, /* rightshift */
|
---|
139 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
140 | 16, /* bitsize */
|
---|
141 | true, /* pc_relative */
|
---|
142 | 0, /* bitpos */
|
---|
143 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
144 | bfd_elf_generic_reloc, /* special_function */
|
---|
145 | "R_CRIS_16", /* name */
|
---|
146 | false, /* partial_inplace */
|
---|
147 | 0x00000000, /* src_mask */
|
---|
148 | 0x0000ffff, /* dst_mask */
|
---|
149 | false), /* pcrel_offset */
|
---|
150 |
|
---|
151 | /* A 32 bit absolute relocation. */
|
---|
152 | HOWTO (R_CRIS_32_PCREL, /* type */
|
---|
153 | 0, /* rightshift */
|
---|
154 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
155 | 32, /* bitsize */
|
---|
156 | true, /* pc_relative */
|
---|
157 | 0, /* bitpos */
|
---|
158 | complain_overflow_bitfield, /* complain_on_overflow */
|
---|
159 | bfd_elf_generic_reloc, /* special_function */
|
---|
160 | "R_CRIS_32", /* name */
|
---|
161 | false, /* partial_inplace */
|
---|
162 | 0x00000000, /* src_mask */
|
---|
163 | 0xffffffff, /* dst_mask */
|
---|
164 | false), /* pcrel_offset */
|
---|
165 |
|
---|
166 | /* GNU extension to record C++ vtable hierarchy */
|
---|
167 | HOWTO (R_CRIS_GNU_VTINHERIT, /* type */
|
---|
168 | 0, /* rightshift */
|
---|
169 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
170 | 0, /* bitsize */
|
---|
171 | false, /* pc_relative */
|
---|
172 | 0, /* bitpos */
|
---|
173 | complain_overflow_dont, /* complain_on_overflow */
|
---|
174 | NULL, /* special_function */
|
---|
175 | "R_CRIS_GNU_VTINHERIT", /* name */
|
---|
176 | false, /* partial_inplace */
|
---|
177 | 0, /* src_mask */
|
---|
178 | 0, /* dst_mask */
|
---|
179 | false), /* pcrel_offset */
|
---|
180 |
|
---|
181 | /* GNU extension to record C++ vtable member usage */
|
---|
182 | HOWTO (R_CRIS_GNU_VTENTRY, /* type */
|
---|
183 | 0, /* rightshift */
|
---|
184 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
---|
185 | 0, /* bitsize */
|
---|
186 | false, /* pc_relative */
|
---|
187 | 0, /* bitpos */
|
---|
188 | complain_overflow_dont, /* complain_on_overflow */
|
---|
189 | _bfd_elf_rel_vtable_reloc_fn, /* special_function */
|
---|
190 | "R_CRIS_GNU_VTENTRY", /* name */
|
---|
191 | false, /* partial_inplace */
|
---|
192 | 0, /* src_mask */
|
---|
193 | 0, /* dst_mask */
|
---|
194 | false) /* pcrel_offset */
|
---|
195 | };
|
---|
196 | |
---|
197 |
|
---|
198 | /* Map BFD reloc types to CRIS ELF reloc types. */
|
---|
199 |
|
---|
200 | struct cris_reloc_map
|
---|
201 | {
|
---|
202 | bfd_reloc_code_real_type bfd_reloc_val;
|
---|
203 | unsigned int cris_reloc_val;
|
---|
204 | };
|
---|
205 |
|
---|
206 | static const struct cris_reloc_map cris_reloc_map [] =
|
---|
207 | {
|
---|
208 | { BFD_RELOC_NONE, R_CRIS_NONE },
|
---|
209 | { BFD_RELOC_8, R_CRIS_8 },
|
---|
210 | { BFD_RELOC_16, R_CRIS_16 },
|
---|
211 | { BFD_RELOC_32, R_CRIS_32 },
|
---|
212 | { BFD_RELOC_8_PCREL, R_CRIS_8_PCREL },
|
---|
213 | { BFD_RELOC_16_PCREL, R_CRIS_16_PCREL },
|
---|
214 | { BFD_RELOC_32_PCREL, R_CRIS_32_PCREL },
|
---|
215 | { BFD_RELOC_VTABLE_INHERIT, R_CRIS_GNU_VTINHERIT },
|
---|
216 | { BFD_RELOC_VTABLE_ENTRY, R_CRIS_GNU_VTENTRY }
|
---|
217 | };
|
---|
218 |
|
---|
219 | static reloc_howto_type *
|
---|
220 | cris_reloc_type_lookup (abfd, code)
|
---|
221 | bfd * abfd ATTRIBUTE_UNUSED;
|
---|
222 | bfd_reloc_code_real_type code;
|
---|
223 | {
|
---|
224 | unsigned int i;
|
---|
225 |
|
---|
226 | for (i = sizeof (cris_reloc_map) / sizeof (cris_reloc_map[0]);
|
---|
227 | --i;)
|
---|
228 | if (cris_reloc_map [i].bfd_reloc_val == code)
|
---|
229 | return & cris_elf_howto_table [cris_reloc_map[i].cris_reloc_val];
|
---|
230 |
|
---|
231 | return NULL;
|
---|
232 | }
|
---|
233 |
|
---|
234 | /* Set the howto pointer for an CRIS ELF reloc. */
|
---|
235 |
|
---|
236 | static void
|
---|
237 | cris_info_to_howto_rela (abfd, cache_ptr, dst)
|
---|
238 | bfd * abfd ATTRIBUTE_UNUSED;
|
---|
239 | arelent * cache_ptr;
|
---|
240 | Elf32_Internal_Rela * dst;
|
---|
241 | {
|
---|
242 | unsigned int r_type;
|
---|
243 |
|
---|
244 | r_type = ELF32_R_TYPE (dst->r_info);
|
---|
245 | BFD_ASSERT (r_type < (unsigned int) R_CRIS_max);
|
---|
246 | cache_ptr->howto = & cris_elf_howto_table [r_type];
|
---|
247 | }
|
---|
248 | |
---|
249 |
|
---|
250 | /* Perform a single relocation. By default we use the standard BFD
|
---|
251 | routines, but we might have to do a few relocs ourselves in the future. */
|
---|
252 |
|
---|
253 | static bfd_reloc_status_type
|
---|
254 | cris_final_link_relocate (howto, input_bfd, input_section, contents, rel,
|
---|
255 | relocation)
|
---|
256 | reloc_howto_type * howto;
|
---|
257 | bfd * input_bfd;
|
---|
258 | asection * input_section;
|
---|
259 | bfd_byte * contents;
|
---|
260 | Elf_Internal_Rela * rel;
|
---|
261 | bfd_vma relocation;
|
---|
262 | {
|
---|
263 | bfd_reloc_status_type r
|
---|
264 | = _bfd_final_link_relocate (howto, input_bfd, input_section,
|
---|
265 | contents, rel->r_offset,
|
---|
266 | relocation, rel->r_addend);
|
---|
267 | return r;
|
---|
268 | }
|
---|
269 | |
---|
270 |
|
---|
271 | /* Relocate an CRIS ELF section. See elf32-fr30.c, from where this was
|
---|
272 | copied, for further comments. */
|
---|
273 |
|
---|
274 | static boolean
|
---|
275 | cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
|
---|
276 | contents, relocs, local_syms, local_sections)
|
---|
277 | bfd * output_bfd ATTRIBUTE_UNUSED;
|
---|
278 | struct bfd_link_info * info;
|
---|
279 | bfd * input_bfd;
|
---|
280 | asection * input_section;
|
---|
281 | bfd_byte * contents;
|
---|
282 | Elf_Internal_Rela * relocs;
|
---|
283 | Elf_Internal_Sym * local_syms;
|
---|
284 | asection ** local_sections;
|
---|
285 | {
|
---|
286 | Elf_Internal_Shdr * symtab_hdr;
|
---|
287 | struct elf_link_hash_entry ** sym_hashes;
|
---|
288 | Elf_Internal_Rela * rel;
|
---|
289 | Elf_Internal_Rela * relend;
|
---|
290 |
|
---|
291 | symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
|
---|
292 | sym_hashes = elf_sym_hashes (input_bfd);
|
---|
293 | relend = relocs + input_section->reloc_count;
|
---|
294 |
|
---|
295 | /* It seems this can happen with erroneous or unsupported input (mixing
|
---|
296 | a.out and elf in an archive, for example.) */
|
---|
297 | if (sym_hashes == NULL)
|
---|
298 | return false;
|
---|
299 |
|
---|
300 | for (rel = relocs; rel < relend; rel ++)
|
---|
301 | {
|
---|
302 | reloc_howto_type * howto;
|
---|
303 | unsigned long r_symndx;
|
---|
304 | Elf_Internal_Sym * sym;
|
---|
305 | asection * sec;
|
---|
306 | struct elf_link_hash_entry * h;
|
---|
307 | bfd_vma relocation;
|
---|
308 | bfd_reloc_status_type r;
|
---|
309 | const char * name = NULL;
|
---|
310 | int r_type;
|
---|
311 |
|
---|
312 | r_type = ELF32_R_TYPE (rel->r_info);
|
---|
313 |
|
---|
314 | if ( r_type == R_CRIS_GNU_VTINHERIT
|
---|
315 | || r_type == R_CRIS_GNU_VTENTRY)
|
---|
316 | continue;
|
---|
317 |
|
---|
318 | r_symndx = ELF32_R_SYM (rel->r_info);
|
---|
319 |
|
---|
320 | if (info->relocateable)
|
---|
321 | {
|
---|
322 | /* This is a relocateable link. We don't have to change
|
---|
323 | anything, unless the reloc is against a section symbol,
|
---|
324 | in which case we have to adjust according to where the
|
---|
325 | section symbol winds up in the output section. */
|
---|
326 | if (r_symndx < symtab_hdr->sh_info)
|
---|
327 | {
|
---|
328 | sym = local_syms + r_symndx;
|
---|
329 |
|
---|
330 | if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
|
---|
331 | {
|
---|
332 | sec = local_sections [r_symndx];
|
---|
333 | rel->r_addend += sec->output_offset + sym->st_value;
|
---|
334 | }
|
---|
335 | }
|
---|
336 |
|
---|
337 | continue;
|
---|
338 | }
|
---|
339 |
|
---|
340 | /* This is a final link. */
|
---|
341 | howto = cris_elf_howto_table + ELF32_R_TYPE (rel->r_info);
|
---|
342 | h = NULL;
|
---|
343 | sym = NULL;
|
---|
344 | sec = NULL;
|
---|
345 |
|
---|
346 | if (r_symndx < symtab_hdr->sh_info)
|
---|
347 | {
|
---|
348 | sym = local_syms + r_symndx;
|
---|
349 | sec = local_sections [r_symndx];
|
---|
350 | relocation = (sec->output_section->vma
|
---|
351 | + sec->output_offset
|
---|
352 | + sym->st_value);
|
---|
353 |
|
---|
354 | name = bfd_elf_string_from_elf_section
|
---|
355 | (input_bfd, symtab_hdr->sh_link, sym->st_name);
|
---|
356 | name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name;
|
---|
357 | #if 0
|
---|
358 | fprintf (stderr, "local: sec: %s, sym: %s (%d), value: %x + %x + %x addend %x\n",
|
---|
359 | sec->name, name, sym->st_name,
|
---|
360 | sec->output_section->vma, sec->output_offset,
|
---|
361 | sym->st_value, rel->r_addend);
|
---|
362 | #endif
|
---|
363 | }
|
---|
364 | else
|
---|
365 | {
|
---|
366 | h = sym_hashes [r_symndx - symtab_hdr->sh_info];
|
---|
367 |
|
---|
368 | while (h->root.type == bfd_link_hash_indirect
|
---|
369 | || h->root.type == bfd_link_hash_warning)
|
---|
370 | h = (struct elf_link_hash_entry *) h->root.u.i.link;
|
---|
371 |
|
---|
372 | name = h->root.root.string;
|
---|
373 |
|
---|
374 | if (h->root.type == bfd_link_hash_defined
|
---|
375 | || h->root.type == bfd_link_hash_defweak)
|
---|
376 | {
|
---|
377 | sec = h->root.u.def.section;
|
---|
378 | relocation = (h->root.u.def.value
|
---|
379 | + sec->output_section->vma
|
---|
380 | + sec->output_offset);
|
---|
381 | #if 0
|
---|
382 | fprintf (stderr,
|
---|
383 | "defined: sec: %s, name: %s, value: %x + %x + %x gives: %x\n",
|
---|
384 | sec->name, name, h->root.u.def.value,
|
---|
385 | sec->output_section->vma, sec->output_offset, relocation);
|
---|
386 | #endif
|
---|
387 | }
|
---|
388 | else if (h->root.type == bfd_link_hash_undefweak)
|
---|
389 | {
|
---|
390 | #if 0
|
---|
391 | fprintf (stderr, "undefined: sec: %s, name: %s\n",
|
---|
392 | sec->name, name);
|
---|
393 | #endif
|
---|
394 | relocation = 0;
|
---|
395 | }
|
---|
396 | else if (info->shared
|
---|
397 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
|
---|
398 | relocation = 0;
|
---|
399 | else
|
---|
400 | {
|
---|
401 | if (! ((*info->callbacks->undefined_symbol)
|
---|
402 | (info, h->root.root.string, input_bfd,
|
---|
403 | input_section, rel->r_offset, true)))
|
---|
404 | return false;
|
---|
405 | #if 0
|
---|
406 | fprintf (stderr, "unknown: name: %s\n", name);
|
---|
407 | #endif
|
---|
408 | relocation = 0;
|
---|
409 | }
|
---|
410 | }
|
---|
411 |
|
---|
412 | r = cris_final_link_relocate (howto, input_bfd, input_section,
|
---|
413 | contents, rel, relocation);
|
---|
414 |
|
---|
415 | if (r != bfd_reloc_ok)
|
---|
416 | {
|
---|
417 | const char * msg = (const char *) NULL;
|
---|
418 |
|
---|
419 | switch (r)
|
---|
420 | {
|
---|
421 | case bfd_reloc_overflow:
|
---|
422 | r = info->callbacks->reloc_overflow
|
---|
423 | (info, name, howto->name, (bfd_vma) 0,
|
---|
424 | input_bfd, input_section, rel->r_offset);
|
---|
425 | break;
|
---|
426 |
|
---|
427 | case bfd_reloc_undefined:
|
---|
428 | r = info->callbacks->undefined_symbol
|
---|
429 | (info, name, input_bfd, input_section, rel->r_offset,
|
---|
430 | true);
|
---|
431 | break;
|
---|
432 |
|
---|
433 | case bfd_reloc_outofrange:
|
---|
434 | msg = _("internal error: out of range error");
|
---|
435 | break;
|
---|
436 |
|
---|
437 | case bfd_reloc_notsupported:
|
---|
438 | msg = _("internal error: unsupported relocation error");
|
---|
439 | break;
|
---|
440 |
|
---|
441 | case bfd_reloc_dangerous:
|
---|
442 | msg = _("internal error: dangerous relocation");
|
---|
443 | break;
|
---|
444 |
|
---|
445 | default:
|
---|
446 | msg = _("internal error: unknown error");
|
---|
447 | break;
|
---|
448 | }
|
---|
449 |
|
---|
450 | if (msg)
|
---|
451 | r = info->callbacks->warning
|
---|
452 | (info, msg, name, input_bfd, input_section, rel->r_offset);
|
---|
453 |
|
---|
454 | if (! r)
|
---|
455 | return false;
|
---|
456 | }
|
---|
457 | }
|
---|
458 |
|
---|
459 | return true;
|
---|
460 | }
|
---|
461 | |
---|
462 |
|
---|
463 | /* Return the section that should be marked against GC for a given
|
---|
464 | relocation. */
|
---|
465 |
|
---|
466 | static asection *
|
---|
467 | cris_elf_gc_mark_hook (abfd, info, rel, h, sym)
|
---|
468 | bfd * abfd;
|
---|
469 | struct bfd_link_info * info ATTRIBUTE_UNUSED;
|
---|
470 | Elf_Internal_Rela * rel;
|
---|
471 | struct elf_link_hash_entry * h;
|
---|
472 | Elf_Internal_Sym * sym;
|
---|
473 | {
|
---|
474 | if (h != NULL)
|
---|
475 | {
|
---|
476 | switch (ELF32_R_TYPE (rel->r_info))
|
---|
477 | {
|
---|
478 | case R_CRIS_GNU_VTINHERIT:
|
---|
479 | case R_CRIS_GNU_VTENTRY:
|
---|
480 | break;
|
---|
481 |
|
---|
482 | default:
|
---|
483 | switch (h->root.type)
|
---|
484 | {
|
---|
485 | case bfd_link_hash_defined:
|
---|
486 | case bfd_link_hash_defweak:
|
---|
487 | return h->root.u.def.section;
|
---|
488 |
|
---|
489 | case bfd_link_hash_common:
|
---|
490 | return h->root.u.c.p->section;
|
---|
491 |
|
---|
492 | default:
|
---|
493 | break;
|
---|
494 | }
|
---|
495 | }
|
---|
496 | }
|
---|
497 | else
|
---|
498 | {
|
---|
499 | if (!(elf_bad_symtab (abfd)
|
---|
500 | && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
|
---|
501 | && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
|
---|
502 | && sym->st_shndx != SHN_COMMON))
|
---|
503 | {
|
---|
504 | return bfd_section_from_elf_index (abfd, sym->st_shndx);
|
---|
505 | }
|
---|
506 | }
|
---|
507 |
|
---|
508 | return NULL;
|
---|
509 | }
|
---|
510 |
|
---|
511 | /* Update the got entry reference counts for the section being removed. */
|
---|
512 |
|
---|
513 | static boolean
|
---|
514 | cris_elf_gc_sweep_hook (abfd, info, sec, relocs)
|
---|
515 | bfd * abfd ATTRIBUTE_UNUSED;
|
---|
516 | struct bfd_link_info * info ATTRIBUTE_UNUSED;
|
---|
517 | asection * sec ATTRIBUTE_UNUSED;
|
---|
518 | const Elf_Internal_Rela * relocs ATTRIBUTE_UNUSED;
|
---|
519 | {
|
---|
520 | return true;
|
---|
521 | }
|
---|
522 |
|
---|
523 | /* Look through the relocs for a section during the first phase.
|
---|
524 | Since we don't do .gots or .plts, we just need to consider the
|
---|
525 | virtual table relocs for gc. */
|
---|
526 |
|
---|
527 | static boolean
|
---|
528 | cris_elf_check_relocs (abfd, info, sec, relocs)
|
---|
529 | bfd *abfd;
|
---|
530 | struct bfd_link_info *info;
|
---|
531 | asection *sec;
|
---|
532 | const Elf_Internal_Rela *relocs;
|
---|
533 | {
|
---|
534 | Elf_Internal_Shdr *symtab_hdr;
|
---|
535 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
|
---|
536 | const Elf_Internal_Rela *rel;
|
---|
537 | const Elf_Internal_Rela *rel_end;
|
---|
538 |
|
---|
539 | if (info->relocateable)
|
---|
540 | return true;
|
---|
541 |
|
---|
542 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
|
---|
543 | sym_hashes = elf_sym_hashes (abfd);
|
---|
544 | sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof (Elf32_External_Sym);
|
---|
545 | if (!elf_bad_symtab (abfd))
|
---|
546 | sym_hashes_end -= symtab_hdr->sh_info;
|
---|
547 |
|
---|
548 | rel_end = relocs + sec->reloc_count;
|
---|
549 | for (rel = relocs; rel < rel_end; rel++)
|
---|
550 | {
|
---|
551 | struct elf_link_hash_entry *h;
|
---|
552 | unsigned long r_symndx;
|
---|
553 |
|
---|
554 | r_symndx = ELF32_R_SYM (rel->r_info);
|
---|
555 | if (r_symndx < symtab_hdr->sh_info)
|
---|
556 | h = NULL;
|
---|
557 | else
|
---|
558 | h = sym_hashes[r_symndx - symtab_hdr->sh_info];
|
---|
559 |
|
---|
560 | switch (ELF32_R_TYPE (rel->r_info))
|
---|
561 | {
|
---|
562 | /* This relocation describes the C++ object vtable hierarchy.
|
---|
563 | Reconstruct it for later use during GC. */
|
---|
564 | case R_CRIS_GNU_VTINHERIT:
|
---|
565 | if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
|
---|
566 | return false;
|
---|
567 | break;
|
---|
568 |
|
---|
569 | /* This relocation describes which C++ vtable entries are actually
|
---|
570 | used. Record for later use during GC. */
|
---|
571 | case R_CRIS_GNU_VTENTRY:
|
---|
572 | if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
|
---|
573 | return false;
|
---|
574 | break;
|
---|
575 | }
|
---|
576 | }
|
---|
577 |
|
---|
578 | return true;
|
---|
579 | }
|
---|
580 |
|
---|
581 | /* Reject a file depending on underscores on symbols. */
|
---|
582 |
|
---|
583 | static boolean
|
---|
584 | cris_elf_object_p (abfd)
|
---|
585 | bfd *abfd;
|
---|
586 | {
|
---|
587 | if ((elf_elfheader (abfd)->e_flags & EF_CRIS_UNDERSCORE))
|
---|
588 | return (bfd_get_symbol_leading_char (abfd) == '_');
|
---|
589 | else
|
---|
590 | return (bfd_get_symbol_leading_char (abfd) == 0);
|
---|
591 | }
|
---|
592 |
|
---|
593 | /* Mark presence or absence of leading underscore. */
|
---|
594 |
|
---|
595 | static void
|
---|
596 | cris_elf_final_write_processing (abfd, linker)
|
---|
597 | bfd *abfd;
|
---|
598 | boolean linker ATTRIBUTE_UNUSED;
|
---|
599 | {
|
---|
600 | if (bfd_get_symbol_leading_char (abfd) == '_')
|
---|
601 | elf_elfheader (abfd)->e_flags |= EF_CRIS_UNDERSCORE;
|
---|
602 | else
|
---|
603 | elf_elfheader (abfd)->e_flags &= ~EF_CRIS_UNDERSCORE;
|
---|
604 | }
|
---|
605 |
|
---|
606 | /* Display the flags field. */
|
---|
607 |
|
---|
608 | static boolean
|
---|
609 | cris_elf_print_private_bfd_data (abfd, ptr)
|
---|
610 | bfd *abfd;
|
---|
611 | PTR ptr;
|
---|
612 | {
|
---|
613 | FILE *file = (FILE *) ptr;
|
---|
614 |
|
---|
615 | BFD_ASSERT (abfd != NULL && ptr != NULL)
|
---|
616 |
|
---|
617 | _bfd_elf_print_private_bfd_data (abfd, ptr);
|
---|
618 |
|
---|
619 | fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
|
---|
620 |
|
---|
621 | if (elf_elfheader (abfd)->e_flags & EF_CRIS_UNDERSCORE)
|
---|
622 | fprintf (file, _(" [symbols have a _ prefix]"));
|
---|
623 |
|
---|
624 | fputc ('\n', file);
|
---|
625 | return true;
|
---|
626 | }
|
---|
627 |
|
---|
628 | /* Don't mix files with and without a leading underscore. */
|
---|
629 |
|
---|
630 | static boolean
|
---|
631 | cris_elf_merge_private_bfd_data (ibfd, obfd)
|
---|
632 | bfd *ibfd;
|
---|
633 | bfd *obfd;
|
---|
634 | {
|
---|
635 | flagword old_flags, new_flags;
|
---|
636 |
|
---|
637 | if (_bfd_generic_verify_endian_match (ibfd, obfd) == false)
|
---|
638 | return false;
|
---|
639 |
|
---|
640 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
|
---|
641 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
|
---|
642 | return true;
|
---|
643 |
|
---|
644 | if (! elf_flags_init (obfd))
|
---|
645 | {
|
---|
646 | /* This happens when ld starts out with a 'blank' output file. */
|
---|
647 | elf_flags_init (obfd) = true;
|
---|
648 |
|
---|
649 | /* Set flags according to current bfd_target. */
|
---|
650 | cris_elf_final_write_processing (obfd, false);
|
---|
651 | }
|
---|
652 |
|
---|
653 | old_flags = elf_elfheader (obfd)->e_flags;
|
---|
654 | new_flags = elf_elfheader (ibfd)->e_flags;
|
---|
655 |
|
---|
656 | /* Is this good or bad? We'll follow with other excluding flags. */
|
---|
657 | if ((old_flags & EF_CRIS_UNDERSCORE) != (new_flags & EF_CRIS_UNDERSCORE))
|
---|
658 | {
|
---|
659 | (*_bfd_error_handler)
|
---|
660 | ((new_flags & EF_CRIS_UNDERSCORE)
|
---|
661 | ? _("%s: uses _-prefixed symbols, but writing file with non-prefixed symbols")
|
---|
662 | : _("%s: uses non-prefixed symbols, but writing file with _-prefixed symbols"),
|
---|
663 | bfd_get_filename (ibfd));
|
---|
664 | bfd_set_error (bfd_error_bad_value);
|
---|
665 | return false;
|
---|
666 | }
|
---|
667 |
|
---|
668 | return true;
|
---|
669 | }
|
---|
670 | |
---|
671 |
|
---|
672 | #define ELF_ARCH bfd_arch_cris
|
---|
673 | #define ELF_MACHINE_CODE EM_CRIS
|
---|
674 | #define ELF_MAXPAGESIZE 0x2000
|
---|
675 |
|
---|
676 | #define TARGET_LITTLE_SYM bfd_elf32_cris_vec
|
---|
677 | #define TARGET_LITTLE_NAME "elf32-cris"
|
---|
678 | #define elf_symbol_leading_char 0
|
---|
679 |
|
---|
680 | #define elf_info_to_howto_rel NULL
|
---|
681 | #define elf_info_to_howto cris_info_to_howto_rela
|
---|
682 | #define elf_backend_relocate_section cris_elf_relocate_section
|
---|
683 | #define elf_backend_gc_mark_hook cris_elf_gc_mark_hook
|
---|
684 | #define elf_backend_gc_sweep_hook cris_elf_gc_sweep_hook
|
---|
685 | #define elf_backend_check_relocs cris_elf_check_relocs
|
---|
686 |
|
---|
687 | #define elf_backend_can_gc_sections 1
|
---|
688 |
|
---|
689 | #define elf_backend_object_p cris_elf_object_p
|
---|
690 | #define elf_backend_final_write_processing \
|
---|
691 | cris_elf_final_write_processing
|
---|
692 | #define bfd_elf32_bfd_print_private_bfd_data \
|
---|
693 | cris_elf_print_private_bfd_data
|
---|
694 | #define bfd_elf32_bfd_merge_private_bfd_data \
|
---|
695 | cris_elf_merge_private_bfd_data
|
---|
696 |
|
---|
697 | #define bfd_elf32_bfd_reloc_type_lookup cris_reloc_type_lookup
|
---|
698 |
|
---|
699 | /* Later, we my want to optimize RELA entries into REL entries for dynamic
|
---|
700 | linking and libraries (if it's a win of any significance). Until then,
|
---|
701 | take the easy route. */
|
---|
702 | #define elf_backend_may_use_rel_p 0
|
---|
703 | #define elf_backend_may_use_rela_p 1
|
---|
704 |
|
---|
705 | #include "elf32-target.h"
|
---|
706 |
|
---|
707 | #define INCLUDED_TARGET_FILE
|
---|
708 |
|
---|
709 | #undef TARGET_LITTLE_SYM
|
---|
710 | #undef TARGET_LITTLE_NAME
|
---|
711 | #undef elf_symbol_leading_char
|
---|
712 |
|
---|
713 | #define TARGET_LITTLE_SYM bfd_elf32_us_cris_vec
|
---|
714 | #define TARGET_LITTLE_NAME "elf32-us-cris"
|
---|
715 | #define elf_symbol_leading_char '_'
|
---|
716 |
|
---|
717 | #include "elf32-target.h"
|
---|