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