Coverage Report

Created: 2026-03-10 08:46

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