source: trunk/binutils/bfd/elf32-mcore.c

Last change on this file was 610, checked in by bird, 22 years ago

This commit was generated by cvs2svn to compensate for changes in r609,
which included commits to RCS files with non-trunk default branches.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 22.2 KB
Line 
1/* Motorola MCore specific support for 32-bit ELF
2 Copyright 1994, 1995, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4
5This file is part of BFD, the Binary File Descriptor library.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21/* This file is based on a preliminary RCE ELF ABI. The
22 information may not match the final RCE ELF ABI. */
23
24#include "bfd.h"
25#include "sysdep.h"
26#include "bfdlink.h"
27#include "libbfd.h"
28#include "elf-bfd.h"
29#include "elf/mcore.h"
30#include <assert.h>
31
32/* RELA relocs are used here... */
33
34static void mcore_elf_howto_init
35 PARAMS ((void));
36static reloc_howto_type * mcore_elf_reloc_type_lookup
37 PARAMS ((bfd *, bfd_reloc_code_real_type));
38static void mcore_elf_info_to_howto
39 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
40static bfd_boolean mcore_elf_set_private_flags
41 PARAMS ((bfd *, flagword));
42static bfd_boolean mcore_elf_merge_private_bfd_data
43 PARAMS ((bfd *, bfd *));
44static bfd_reloc_status_type mcore_elf_unsupported_reloc
45 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
46static bfd_boolean mcore_elf_relocate_section
47 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
48 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
49static asection * mcore_elf_gc_mark_hook
50 PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
51 struct elf_link_hash_entry *, Elf_Internal_Sym *));
52static bfd_boolean mcore_elf_gc_sweep_hook
53 PARAMS ((bfd *, struct bfd_link_info *, asection *,
54 const Elf_Internal_Rela *));
55static bfd_boolean mcore_elf_check_relocs
56 PARAMS ((bfd *, struct bfd_link_info *, asection *,
57 const Elf_Internal_Rela *));
58
59static reloc_howto_type * mcore_elf_howto_table [(int) R_MCORE_max];
60
61static reloc_howto_type mcore_elf_howto_raw[] =
62{
63 /* This reloc does nothing. */
64 HOWTO (R_MCORE_NONE, /* type */
65 0, /* rightshift */
66 2, /* size (0 = byte, 1 = short, 2 = long) */
67 32, /* bitsize */
68 FALSE, /* pc_relative */
69 0, /* bitpos */
70 complain_overflow_bitfield, /* complain_on_overflow */
71 NULL, /* special_function */
72 "R_MCORE_NONE", /* name */
73 FALSE, /* partial_inplace */
74 0, /* src_mask */
75 0, /* dst_mask */
76 FALSE), /* pcrel_offset */
77
78 /* A standard 32 bit relocation. */
79 HOWTO (R_MCORE_ADDR32, /* type */
80 0, /* rightshift */
81 2, /* size (0 = byte, 1 = short, 2 = long) */
82 32, /* bitsize */
83 FALSE, /* pc_relative */
84 0, /* bitpos */
85 complain_overflow_bitfield, /* complain_on_overflow */
86 bfd_elf_generic_reloc, /* special_function */
87 "ADDR32", /* name *//* For compatability with coff/pe port. */
88 FALSE, /* partial_inplace */
89 0x0, /* src_mask */
90 0xffffffff, /* dst_mask */
91 FALSE), /* pcrel_offset */
92
93 /* 8 bits + 2 zero bits; jmpi/jsri/lrw instructions.
94 Should not appear in object files. */
95 HOWTO (R_MCORE_PCRELIMM8BY4, /* type */
96 2, /* rightshift */
97 1, /* size (0 = byte, 1 = short, 2 = long) */
98 8, /* bitsize */
99 TRUE, /* pc_relative */
100 0, /* bitpos */
101 complain_overflow_bitfield, /* complain_on_overflow */
102 mcore_elf_unsupported_reloc, /* special_function */
103 "R_MCORE_PCRELIMM8BY4",/* name */
104 FALSE, /* partial_inplace */
105 0, /* src_mask */
106 0, /* dst_mask */
107 TRUE), /* pcrel_offset */
108
109 /* bsr/bt/bf/br instructions; 11 bits + 1 zero bit
110 Span 2k instructions == 4k bytes.
111 Only useful pieces at the relocated address are the opcode (5 bits) */
112 HOWTO (R_MCORE_PCRELIMM11BY2,/* type */
113 1, /* rightshift */
114 1, /* size (0 = byte, 1 = short, 2 = long) */
115 11, /* bitsize */
116 TRUE, /* pc_relative */
117 0, /* bitpos */
118 complain_overflow_signed, /* complain_on_overflow */
119 bfd_elf_generic_reloc, /* special_function */
120 "R_MCORE_PCRELIMM11BY2",/* name */
121 FALSE, /* partial_inplace */
122 0x0, /* src_mask */
123 0x7ff, /* dst_mask */
124 TRUE), /* pcrel_offset */
125
126 /* 4 bits + 1 zero bit; 'loopt' instruction only; unsupported. */
127 HOWTO (R_MCORE_PCRELIMM4BY2, /* type */
128 1, /* rightshift */
129 1, /* size (0 = byte, 1 = short, 2 = long) */
130 4, /* bitsize */
131 TRUE, /* pc_relative */
132 0, /* bitpos */
133 complain_overflow_bitfield, /* complain_on_overflow */
134 mcore_elf_unsupported_reloc,/* special_function */
135 "R_MCORE_PCRELIMM4BY2",/* name */
136 FALSE, /* partial_inplace */
137 0, /* src_mask */
138 0, /* dst_mask */
139 TRUE), /* pcrel_offset */
140
141 /* 32-bit pc-relative. Eventually this will help support PIC code. */
142 HOWTO (R_MCORE_PCREL32, /* type */
143 0, /* rightshift */
144 2, /* size (0 = byte, 1 = short, 2 = long) */
145 32, /* bitsize */
146 TRUE, /* pc_relative */
147 0, /* bitpos */
148 complain_overflow_bitfield, /* complain_on_overflow */
149 bfd_elf_generic_reloc, /* special_function */
150 "R_MCORE_PCREL32", /* name */
151 FALSE, /* partial_inplace */
152 0x0, /* src_mask */
153 0xffffffff, /* dst_mask */
154 TRUE), /* pcrel_offset */
155
156 /* Like PCRELIMM11BY2, this relocation indicates that there is a
157 'jsri' at the specified address. There is a separate relocation
158 entry for the literal pool entry that it references, but we
159 might be able to change the jsri to a bsr if the target turns out
160 to be close enough [even though we won't reclaim the literal pool
161 entry, we'll get some runtime efficiency back]. Note that this
162 is a relocation that we are allowed to safely ignore. */
163 HOWTO (R_MCORE_PCRELJSR_IMM11BY2,/* type */
164 1, /* rightshift */
165 1, /* size (0 = byte, 1 = short, 2 = long) */
166 11, /* bitsize */
167 TRUE, /* pc_relative */
168 0, /* bitpos */
169 complain_overflow_signed, /* complain_on_overflow */
170 bfd_elf_generic_reloc, /* special_function */
171 "R_MCORE_PCRELJSR_IMM11BY2", /* name */
172 FALSE, /* partial_inplace */
173 0x0, /* src_mask */
174 0x7ff, /* dst_mask */
175 TRUE), /* pcrel_offset */
176
177 /* GNU extension to record C++ vtable hierarchy */
178 HOWTO (R_MCORE_GNU_VTINHERIT, /* type */
179 0, /* rightshift */
180 2, /* size (0 = byte, 1 = short, 2 = long) */
181 0, /* bitsize */
182 FALSE, /* pc_relative */
183 0, /* bitpos */
184 complain_overflow_dont, /* complain_on_overflow */
185 NULL, /* special_function */
186 "R_MCORE_GNU_VTINHERIT", /* name */
187 FALSE, /* partial_inplace */
188 0, /* src_mask */
189 0, /* dst_mask */
190 FALSE), /* pcrel_offset */
191
192 /* GNU extension to record C++ vtable member usage */
193 HOWTO (R_MCORE_GNU_VTENTRY, /* type */
194 0, /* rightshift */
195 2, /* size (0 = byte, 1 = short, 2 = long) */
196 0, /* bitsize */
197 FALSE, /* pc_relative */
198 0, /* bitpos */
199 complain_overflow_dont,/* complain_on_overflow */
200 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
201 "R_MCORE_GNU_VTENTRY", /* name */
202 FALSE, /* partial_inplace */
203 0, /* src_mask */
204 0, /* dst_mask */
205 FALSE), /* pcrel_offset */
206
207 HOWTO (R_MCORE_RELATIVE, /* type */
208 0, /* rightshift */
209 2, /* size (0 = byte, 1 = short, 2 = long) */
210 32, /* bitsize */
211 FALSE, /* pc_relative */
212 0, /* bitpos */
213 complain_overflow_signed, /* complain_on_overflow */
214 NULL, /* special_function */
215 "R_MCORE_RELATIVE", /* name */
216 TRUE, /* partial_inplace */
217 0xffffffff, /* src_mask */
218 0xffffffff, /* dst_mask */
219 FALSE) /* pcrel_offset */
220};
221
222#ifndef NUM_ELEM
223#define NUM_ELEM(a) (sizeof (a) / sizeof (a)[0])
224#endif
225
226
227/* Initialize the mcore_elf_howto_table, so that linear accesses can be done. */
228static void
229mcore_elf_howto_init ()
230{
231 unsigned int i;
232
233 for (i = NUM_ELEM (mcore_elf_howto_raw); i--;)
234 {
235 unsigned int type;
236
237 type = mcore_elf_howto_raw[i].type;
238
239 BFD_ASSERT (type < NUM_ELEM (mcore_elf_howto_table));
240
241 mcore_elf_howto_table [type] = & mcore_elf_howto_raw [i];
242 }
243}
244
245
246static reloc_howto_type *
247mcore_elf_reloc_type_lookup (abfd, code)
248 bfd * abfd ATTRIBUTE_UNUSED;
249 bfd_reloc_code_real_type code;
250{
251 enum elf_mcore_reloc_type mcore_reloc = R_MCORE_NONE;
252
253 switch (code)
254 {
255 case BFD_RELOC_NONE: mcore_reloc = R_MCORE_NONE; break;
256 case BFD_RELOC_32: mcore_reloc = R_MCORE_ADDR32; break;
257 case BFD_RELOC_MCORE_PCREL_IMM8BY4: mcore_reloc = R_MCORE_PCRELIMM8BY4; break;
258 case BFD_RELOC_MCORE_PCREL_IMM11BY2: mcore_reloc = R_MCORE_PCRELIMM11BY2; break;
259 case BFD_RELOC_MCORE_PCREL_IMM4BY2: mcore_reloc = R_MCORE_PCRELIMM4BY2; break;
260 case BFD_RELOC_32_PCREL: mcore_reloc = R_MCORE_PCREL32; break;
261 case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2: mcore_reloc = R_MCORE_PCRELJSR_IMM11BY2; break;
262 case BFD_RELOC_VTABLE_INHERIT: mcore_reloc = R_MCORE_GNU_VTINHERIT; break;
263 case BFD_RELOC_VTABLE_ENTRY: mcore_reloc = R_MCORE_GNU_VTENTRY; break;
264 case BFD_RELOC_RVA: mcore_reloc = R_MCORE_RELATIVE; break;
265 default:
266 return (reloc_howto_type *)NULL;
267 }
268
269 if (! mcore_elf_howto_table [R_MCORE_PCRELIMM8BY4]) /* Initialize howto table if needed */
270 mcore_elf_howto_init ();
271
272 return mcore_elf_howto_table [(int) mcore_reloc];
273};
274
275/* Set the howto pointer for a RCE ELF reloc. */
276static void
277mcore_elf_info_to_howto (abfd, cache_ptr, dst)
278 bfd * abfd ATTRIBUTE_UNUSED;
279 arelent * cache_ptr;
280 Elf_Internal_Rela * dst;
281{
282 if (! mcore_elf_howto_table [R_MCORE_PCRELIMM8BY4]) /* Initialize howto table if needed */
283 mcore_elf_howto_init ();
284
285 BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_MCORE_max);
286
287 cache_ptr->howto = mcore_elf_howto_table [ELF32_R_TYPE (dst->r_info)];
288}
289
290/* Function to set whether a module needs the -mrelocatable bit set. */
291static bfd_boolean
292mcore_elf_set_private_flags (abfd, flags)
293 bfd * abfd;
294 flagword flags;
295{
296 BFD_ASSERT (! elf_flags_init (abfd)
297 || elf_elfheader (abfd)->e_flags == flags);
298
299 elf_elfheader (abfd)->e_flags = flags;
300 elf_flags_init (abfd) = TRUE;
301 return TRUE;
302}
303
304/* Merge backend specific data from an object file to the output
305 object file when linking. */
306static bfd_boolean
307mcore_elf_merge_private_bfd_data (ibfd, obfd)
308 bfd * ibfd;
309 bfd * obfd;
310{
311 flagword old_flags;
312 flagword new_flags;
313
314 /* Check if we have the same endianess */
315 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
316 return FALSE;
317
318 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
319 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
320 return TRUE;
321
322 new_flags = elf_elfheader (ibfd)->e_flags;
323 old_flags = elf_elfheader (obfd)->e_flags;
324
325 if (! elf_flags_init (obfd)) /* First call, no flags set */
326 {
327 elf_flags_init (obfd) = TRUE;
328 elf_elfheader (obfd)->e_flags = new_flags;
329 }
330 else if (new_flags == old_flags) /* Compatible flags are ok */
331 ;
332 else
333 {
334 /* FIXME */
335 }
336
337 return TRUE;
338}
339
340
341/* Don't pretend we can deal with unsupported relocs. */
342
343static bfd_reloc_status_type
344mcore_elf_unsupported_reloc (abfd, reloc_entry, symbol, data, input_section,
345 output_bfd, error_message)
346 bfd * abfd;
347 arelent * reloc_entry;
348 asymbol * symbol ATTRIBUTE_UNUSED;
349 PTR data ATTRIBUTE_UNUSED;
350 asection * input_section ATTRIBUTE_UNUSED;
351 bfd * output_bfd ATTRIBUTE_UNUSED;
352 char ** error_message ATTRIBUTE_UNUSED;
353{
354 BFD_ASSERT (reloc_entry->howto != (reloc_howto_type *)0);
355
356 _bfd_error_handler (_("%s: Relocation %s (%d) is not currently supported.\n"),
357 bfd_archive_filename (abfd),
358 reloc_entry->howto->name,
359 reloc_entry->howto->type);
360
361 return bfd_reloc_notsupported;
362}
363
364
365/* The RELOCATE_SECTION function is called by the ELF backend linker
366 to handle the relocations for a section.
367
368 The relocs are always passed as Rela structures; if the section
369 actually uses Rel structures, the r_addend field will always be
370 zero.
371
372 This function is responsible for adjust the section contents as
373 necessary, and (if using Rela relocs and generating a
374 relocateable output file) adjusting the reloc addend as
375 necessary.
376
377 This function does not have to worry about setting the reloc
378 address or the reloc symbol index.
379
380 LOCAL_SYMS is a pointer to the swapped in local symbols.
381
382 LOCAL_SECTIONS is an array giving the section in the input file
383 corresponding to the st_shndx field of each local symbol.
384
385 The global hash table entry for the global symbols can be found
386 via elf_sym_hashes (input_bfd).
387
388 When generating relocateable output, this function must handle
389 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
390 going to be the section symbol corresponding to the output
391 section, which means that the addend must be adjusted
392 accordingly. */
393
394static bfd_boolean
395mcore_elf_relocate_section (output_bfd, info, input_bfd, input_section,
396 contents, relocs, local_syms, local_sections)
397 bfd * output_bfd;
398 struct bfd_link_info * info;
399 bfd * input_bfd;
400 asection * input_section;
401 bfd_byte * contents;
402 Elf_Internal_Rela * relocs;
403 Elf_Internal_Sym * local_syms;
404 asection ** local_sections;
405{
406 Elf_Internal_Shdr * symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
407 struct elf_link_hash_entry ** sym_hashes = elf_sym_hashes (input_bfd);
408 Elf_Internal_Rela * rel = relocs;
409 Elf_Internal_Rela * relend = relocs + input_section->reloc_count;
410 bfd_boolean ret = TRUE;
411
412#ifdef DEBUG
413 fprintf (stderr,
414 "mcore_elf_relocate_section called for %s section %s, %ld relocations%s\n",
415 bfd_archive_filename (input_bfd),
416 bfd_section_name(input_bfd, input_section),
417 (long) input_section->reloc_count,
418 (info->relocateable) ? " (relocatable)" : "");
419#endif
420
421 if (info->relocateable)
422 return TRUE;
423
424 if (! mcore_elf_howto_table [R_MCORE_PCRELIMM8BY4]) /* Initialize howto table if needed */
425 mcore_elf_howto_init ();
426
427 for (; rel < relend; rel++)
428 {
429 enum elf_mcore_reloc_type r_type = (enum elf_mcore_reloc_type) ELF32_R_TYPE (rel->r_info);
430 bfd_vma offset = rel->r_offset;
431 bfd_vma addend = rel->r_addend;
432 bfd_reloc_status_type r = bfd_reloc_other;
433 asection * sec = (asection *) 0;
434 reloc_howto_type * howto;
435 bfd_vma relocation;
436 Elf_Internal_Sym * sym = (Elf_Internal_Sym *) 0;
437 unsigned long r_symndx;
438 struct elf_link_hash_entry * h = (struct elf_link_hash_entry *) 0;
439 unsigned short oldinst = 0;
440
441 /* Unknown relocation handling */
442 if ((unsigned) r_type >= (unsigned) R_MCORE_max
443 || ! mcore_elf_howto_table [(int)r_type])
444 {
445 _bfd_error_handler (_("%s: Unknown relocation type %d\n"),
446 bfd_archive_filename (input_bfd),
447 (int) r_type);
448
449 bfd_set_error (bfd_error_bad_value);
450 ret = FALSE;
451 continue;
452 }
453
454 howto = mcore_elf_howto_table [(int) r_type];
455 r_symndx = ELF32_R_SYM (rel->r_info);
456
457 /* Complain about known relocation that are not yet supported. */
458 if (howto->special_function == mcore_elf_unsupported_reloc)
459 {
460 _bfd_error_handler (_("%s: Relocation %s (%d) is not currently supported.\n"),
461 bfd_archive_filename (input_bfd),
462 howto->name,
463 (int)r_type);
464
465 bfd_set_error (bfd_error_bad_value);
466 ret = FALSE;
467 continue;
468 }
469
470 if (r_symndx < symtab_hdr->sh_info)
471 {
472 sym = local_syms + r_symndx;
473 sec = local_sections [r_symndx];
474 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
475 addend = rel->r_addend;
476 }
477 else
478 {
479 h = sym_hashes [r_symndx - symtab_hdr->sh_info];
480 if ( h->root.type == bfd_link_hash_defined
481 || h->root.type == bfd_link_hash_defweak)
482 {
483 sec = h->root.u.def.section;
484 relocation = (h->root.u.def.value
485 + sec->output_section->vma
486 + sec->output_offset);
487 }
488 else if (h->root.type == bfd_link_hash_undefweak)
489 relocation = 0;
490 else if (info->shared
491 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
492 relocation = 0;
493 else
494 {
495 if (! ((*info->callbacks->undefined_symbol)
496 (info, h->root.root.string, input_bfd,
497 input_section, rel->r_offset, TRUE)))
498 return FALSE;
499
500 ret = FALSE;
501 continue;
502 }
503 }
504
505 switch (r_type)
506 {
507 default:
508 break;
509
510 case R_MCORE_PCRELJSR_IMM11BY2:
511 oldinst = bfd_get_16 (input_bfd, contents + offset);
512#define MCORE_INST_BSR 0xF800
513 bfd_put_16 (input_bfd, (bfd_vma) MCORE_INST_BSR, contents + offset);
514 break;
515 }
516
517#ifdef DEBUG
518 fprintf (stderr, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
519 howto->name, r_type, r_symndx, (long) offset, (long) addend);
520#endif
521
522 r = _bfd_final_link_relocate
523 (howto, input_bfd, input_section, contents, offset, relocation, addend);
524
525 if (r != bfd_reloc_ok && r_type == R_MCORE_PCRELJSR_IMM11BY2)
526 {
527 /* Wasn't ok, back it out and give up. */
528 bfd_put_16 (input_bfd, (bfd_vma) oldinst, contents + offset);
529 r = bfd_reloc_ok;
530 }
531
532 if (r != bfd_reloc_ok)
533 {
534 ret = FALSE;
535
536 switch (r)
537 {
538 default:
539 break;
540
541 case bfd_reloc_overflow:
542 {
543 const char * name;
544
545 if (h != NULL)
546 name = h->root.root.string;
547 else
548 {
549 name = bfd_elf_string_from_elf_section
550 (input_bfd, symtab_hdr->sh_link, sym->st_name);
551
552 if (name == NULL)
553 break;
554
555 if (* name == '\0')
556 name = bfd_section_name (input_bfd, sec);
557 }
558
559 (*info->callbacks->reloc_overflow)
560 (info, name, howto->name, (bfd_vma) 0, input_bfd, input_section,
561 offset);
562 }
563 break;
564 }
565 }
566 }
567
568#ifdef DEBUG
569 fprintf (stderr, "\n");
570#endif
571
572 return ret;
573}
574
575
576/* Return the section that should be marked against GC for a given
577 relocation. */
578
579static asection *
580mcore_elf_gc_mark_hook (sec, info, rel, h, sym)
581 asection * sec;
582 struct bfd_link_info * info ATTRIBUTE_UNUSED;
583 Elf_Internal_Rela * rel;
584 struct elf_link_hash_entry * h;
585 Elf_Internal_Sym * sym;
586{
587 if (h != NULL)
588 {
589 switch (ELF32_R_TYPE (rel->r_info))
590 {
591 case R_MCORE_GNU_VTINHERIT:
592 case R_MCORE_GNU_VTENTRY:
593 break;
594
595 default:
596 switch (h->root.type)
597 {
598 case bfd_link_hash_defined:
599 case bfd_link_hash_defweak:
600 return h->root.u.def.section;
601
602 case bfd_link_hash_common:
603 return h->root.u.c.p->section;
604
605 default:
606 break;
607 }
608 }
609 }
610 else
611 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
612
613 return NULL;
614}
615
616/* Update the got entry reference counts for the section being removed. */
617
618static bfd_boolean
619mcore_elf_gc_sweep_hook (abfd, info, sec, relocs)
620 bfd * abfd ATTRIBUTE_UNUSED;
621 struct bfd_link_info * info ATTRIBUTE_UNUSED;
622 asection * sec ATTRIBUTE_UNUSED;
623 const Elf_Internal_Rela * relocs ATTRIBUTE_UNUSED;
624{
625 return TRUE;
626}
627
628/* Look through the relocs for a section during the first phase.
629 Since we don't do .gots or .plts, we just need to consider the
630 virtual table relocs for gc. */
631
632static bfd_boolean
633mcore_elf_check_relocs (abfd, info, sec, relocs)
634 bfd * abfd;
635 struct bfd_link_info * info;
636 asection * sec;
637 const Elf_Internal_Rela * relocs;
638{
639 Elf_Internal_Shdr * symtab_hdr;
640 struct elf_link_hash_entry ** sym_hashes;
641 struct elf_link_hash_entry ** sym_hashes_end;
642 const Elf_Internal_Rela * rel;
643 const Elf_Internal_Rela * rel_end;
644
645 if (info->relocateable)
646 return TRUE;
647
648 symtab_hdr = & elf_tdata (abfd)->symtab_hdr;
649 sym_hashes = elf_sym_hashes (abfd);
650 sym_hashes_end = sym_hashes + symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
651 if (!elf_bad_symtab (abfd))
652 sym_hashes_end -= symtab_hdr->sh_info;
653
654 rel_end = relocs + sec->reloc_count;
655
656 for (rel = relocs; rel < rel_end; rel++)
657 {
658 struct elf_link_hash_entry * h;
659 unsigned long r_symndx;
660
661 r_symndx = ELF32_R_SYM (rel->r_info);
662
663 if (r_symndx < symtab_hdr->sh_info)
664 h = NULL;
665 else
666 h = sym_hashes [r_symndx - symtab_hdr->sh_info];
667
668 switch (ELF32_R_TYPE (rel->r_info))
669 {
670 /* This relocation describes the C++ object vtable hierarchy.
671 Reconstruct it for later use during GC. */
672 case R_MCORE_GNU_VTINHERIT:
673 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
674 return FALSE;
675 break;
676
677 /* This relocation describes which C++ vtable entries are actually
678 used. Record for later use during GC. */
679 case R_MCORE_GNU_VTENTRY:
680 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
681 return FALSE;
682 break;
683 }
684 }
685
686 return TRUE;
687}
688
689#define TARGET_BIG_SYM bfd_elf32_mcore_big_vec
690#define TARGET_BIG_NAME "elf32-mcore-big"
691#define TARGET_LITTLE_SYM bfd_elf32_mcore_little_vec
692#define TARGET_LITTLE_NAME "elf32-mcore-little"
693
694#define ELF_ARCH bfd_arch_mcore
695#define ELF_MACHINE_CODE EM_MCORE
696#define ELF_MAXPAGESIZE 0x1000 /* 4k, if we ever have 'em */
697#define elf_info_to_howto mcore_elf_info_to_howto
698#define elf_info_to_howto_rel NULL
699
700#define bfd_elf32_bfd_merge_private_bfd_data mcore_elf_merge_private_bfd_data
701#define bfd_elf32_bfd_set_private_flags mcore_elf_set_private_flags
702#define bfd_elf32_bfd_reloc_type_lookup mcore_elf_reloc_type_lookup
703#define elf_backend_relocate_section mcore_elf_relocate_section
704#define elf_backend_gc_mark_hook mcore_elf_gc_mark_hook
705#define elf_backend_gc_sweep_hook mcore_elf_gc_sweep_hook
706#define elf_backend_check_relocs mcore_elf_check_relocs
707
708#define elf_backend_can_gc_sections 1
709#define elf_backend_rela_normal 1
710
711#include "elf32-target.h"
Note: See TracBrowser for help on using the repository browser.