Coverage Report

Created: 2026-11-21 09:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/bfd/coff-sh.c
Line
Count
Source
1
/* BFD back-end for Renesas Super-H COFF binaries.
2
   Copyright (C) 1993-2026 Free Software Foundation, Inc.
3
   Contributed by Cygnus Support.
4
   Written by Steve Chamberlain, <sac@cygnus.com>.
5
   Relaxing code written by Ian Lance Taylor, <ian@cygnus.com>.
6
7
   This file is part of BFD, the Binary File Descriptor library.
8
9
   This program is free software; you can redistribute it and/or modify
10
   it under the terms of the GNU General Public License as published by
11
   the Free Software Foundation; either version 3 of the License, or
12
   (at your option) any later version.
13
14
   This program is distributed in the hope that it will be useful,
15
   but WITHOUT ANY WARRANTY; without even the implied warranty of
16
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
   GNU General Public License for more details.
18
19
   You should have received a copy of the GNU General Public License
20
   along with this program; if not, write to the Free Software
21
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22
   MA 02110-1301, USA.  */
23
24
#include "sysdep.h"
25
#include "bfd.h"
26
#include "libiberty.h"
27
#include "libbfd.h"
28
#include "bfdlink.h"
29
#include "coff/sh.h"
30
#include "coff/internal.h"
31
32
#undef  bfd_pe_print_pdata
33
34
#ifdef COFF_WITH_PE
35
#include "coff/pe.h"
36
37
#ifndef COFF_IMAGE_WITH_PE
38
static bool sh_align_load_span
39
  (bfd *, asection *, bfd_byte *,
40
   bool (*) (bfd *, asection *, void *, bfd_byte *, bfd_vma),
41
   void *, bfd_vma **, bfd_vma *, bfd_vma, bfd_vma, bool *);
42
43
0
#define _bfd_sh_align_load_span sh_align_load_span
44
#endif
45
46
#define bfd_pe_print_pdata   _bfd_pe_print_ce_compressed_pdata
47
48
#else
49
50
#define bfd_pe_print_pdata   NULL
51
52
#endif /* COFF_WITH_PE.  */
53
54
#include "libcoff.h"
55
56
/* Internal functions.  */
57
58
#ifdef COFF_WITH_PE
59
/* Can't build import tables with 2**4 alignment.  */
60
197k
#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER  2
61
#else
62
/* Default section alignment to 2**4.  */
63
263k
#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER  4
64
#endif
65
66
#ifdef COFF_IMAGE_WITH_PE
67
/* Align PE executables.  */
68
203
#define COFF_PAGE_SIZE 0x1000
69
#endif
70
71
/* Generate long file names.  */
72
#define COFF_LONG_FILENAMES
73
74
#ifdef COFF_WITH_PE
75
/* Return TRUE if this relocation should
76
   appear in the output .reloc section.  */
77
78
static bool
79
in_reloc_p (bfd * abfd ATTRIBUTE_UNUSED,
80
      reloc_howto_type * howto)
81
0
{
82
0
  return ! howto->pc_relative && howto->type != R_SH_IMAGEBASE;
83
0
}
Unexecuted instantiation: pe-sh.c:in_reloc_p
Unexecuted instantiation: pei-sh.c:in_reloc_p
84
#endif
85
86
static bfd_reloc_status_type
87
sh_reloc (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
88
static bool
89
sh_relocate_section (bfd *, struct bfd_link_info *, bfd *, asection *,
90
         bfd_byte *, struct internal_reloc *,
91
         struct internal_syment *, asection **);
92
static bool
93
sh_align_loads (bfd *, asection *, struct internal_reloc *,
94
    bfd_byte *, bool *);
95
96
/* The supported relocations.  There are a lot of relocations defined
97
   in coff/internal.h which we do not expect to ever see.  */
98
static reloc_howto_type sh_coff_howtos[] =
99
{
100
  EMPTY_HOWTO (0),
101
  EMPTY_HOWTO (1),
102
#ifdef COFF_WITH_PE
103
  /* Windows CE */
104
  HOWTO (R_SH_IMM32CE,    /* type */
105
   0,     /* rightshift */
106
   4,     /* size */
107
   32,      /* bitsize */
108
   false,     /* pc_relative */
109
   0,     /* bitpos */
110
   complain_overflow_bitfield, /* complain_on_overflow */
111
   sh_reloc,    /* special_function */
112
   "r_imm32ce",   /* name */
113
   true,      /* partial_inplace */
114
   0xffffffff,    /* src_mask */
115
   0xffffffff,    /* dst_mask */
116
   false),    /* pcrel_offset */
117
#else
118
  EMPTY_HOWTO (2),
119
#endif
120
  EMPTY_HOWTO (3), /* R_SH_PCREL8 */
121
  EMPTY_HOWTO (4), /* R_SH_PCREL16 */
122
  EMPTY_HOWTO (5), /* R_SH_HIGH8 */
123
  EMPTY_HOWTO (6), /* R_SH_IMM24 */
124
  EMPTY_HOWTO (7), /* R_SH_LOW16 */
125
  EMPTY_HOWTO (8),
126
  EMPTY_HOWTO (9), /* R_SH_PCDISP8BY4 */
127
128
  HOWTO (R_SH_PCDISP8BY2, /* type */
129
   1,     /* rightshift */
130
   2,     /* size */
131
   8,     /* bitsize */
132
   true,      /* pc_relative */
133
   0,     /* bitpos */
134
   complain_overflow_signed, /* complain_on_overflow */
135
   sh_reloc,    /* special_function */
136
   "r_pcdisp8by2",  /* name */
137
   true,      /* partial_inplace */
138
   0xff,      /* src_mask */
139
   0xff,      /* dst_mask */
140
   true),     /* pcrel_offset */
141
142
  EMPTY_HOWTO (11), /* R_SH_PCDISP8 */
143
144
  HOWTO (R_SH_PCDISP,   /* type */
145
   1,     /* rightshift */
146
   2,     /* size */
147
   12,      /* bitsize */
148
   true,      /* pc_relative */
149
   0,     /* bitpos */
150
   complain_overflow_signed, /* complain_on_overflow */
151
   sh_reloc,    /* special_function */
152
   "r_pcdisp12by2", /* name */
153
   true,      /* partial_inplace */
154
   0xfff,     /* src_mask */
155
   0xfff,     /* dst_mask */
156
   true),     /* pcrel_offset */
157
158
  EMPTY_HOWTO (13),
159
160
  HOWTO (R_SH_IMM32,    /* type */
161
   0,     /* rightshift */
162
   4,     /* size */
163
   32,      /* bitsize */
164
   false,     /* pc_relative */
165
   0,     /* bitpos */
166
   complain_overflow_bitfield, /* complain_on_overflow */
167
   sh_reloc,    /* special_function */
168
   "r_imm32",   /* name */
169
   true,      /* partial_inplace */
170
   0xffffffff,    /* src_mask */
171
   0xffffffff,    /* dst_mask */
172
   false),    /* pcrel_offset */
173
174
  EMPTY_HOWTO (15),
175
#ifdef COFF_WITH_PE
176
  HOWTO (R_SH_IMAGEBASE,  /* type */
177
   0,     /* rightshift */
178
   4,     /* size */
179
   32,      /* bitsize */
180
   false,     /* pc_relative */
181
   0,     /* bitpos */
182
   complain_overflow_bitfield, /* complain_on_overflow */
183
   sh_reloc,    /* special_function */
184
   "rva32",   /* name */
185
   true,      /* partial_inplace */
186
   0xffffffff,    /* src_mask */
187
   0xffffffff,    /* dst_mask */
188
   false),    /* pcrel_offset */
189
#else
190
  EMPTY_HOWTO (16), /* R_SH_IMM8 */
191
#endif
192
  EMPTY_HOWTO (17), /* R_SH_IMM8BY2 */
193
  EMPTY_HOWTO (18), /* R_SH_IMM8BY4 */
194
  EMPTY_HOWTO (19), /* R_SH_IMM4 */
195
  EMPTY_HOWTO (20), /* R_SH_IMM4BY2 */
196
  EMPTY_HOWTO (21), /* R_SH_IMM4BY4 */
197
198
  HOWTO (R_SH_PCRELIMM8BY2, /* type */
199
   1,     /* rightshift */
200
   2,     /* size */
201
   8,     /* bitsize */
202
   true,      /* pc_relative */
203
   0,     /* bitpos */
204
   complain_overflow_unsigned, /* complain_on_overflow */
205
   sh_reloc,    /* special_function */
206
   "r_pcrelimm8by2",  /* name */
207
   true,      /* partial_inplace */
208
   0xff,      /* src_mask */
209
   0xff,      /* dst_mask */
210
   true),     /* pcrel_offset */
211
212
  HOWTO (R_SH_PCRELIMM8BY4, /* type */
213
   2,     /* rightshift */
214
   2,     /* size */
215
   8,     /* bitsize */
216
   true,      /* pc_relative */
217
   0,     /* bitpos */
218
   complain_overflow_unsigned, /* complain_on_overflow */
219
   sh_reloc,    /* special_function */
220
   "r_pcrelimm8by4",  /* name */
221
   true,      /* partial_inplace */
222
   0xff,      /* src_mask */
223
   0xff,      /* dst_mask */
224
   true),     /* pcrel_offset */
225
226
  HOWTO (R_SH_IMM16,    /* type */
227
   0,     /* rightshift */
228
   2,     /* size */
229
   16,      /* bitsize */
230
   false,     /* pc_relative */
231
   0,     /* bitpos */
232
   complain_overflow_bitfield, /* complain_on_overflow */
233
   sh_reloc,    /* special_function */
234
   "r_imm16",   /* name */
235
   true,      /* partial_inplace */
236
   0xffff,    /* src_mask */
237
   0xffff,    /* dst_mask */
238
   false),    /* pcrel_offset */
239
240
  HOWTO (R_SH_SWITCH16,   /* type */
241
   0,     /* rightshift */
242
   2,     /* size */
243
   16,      /* bitsize */
244
   false,     /* pc_relative */
245
   0,     /* bitpos */
246
   complain_overflow_bitfield, /* complain_on_overflow */
247
   sh_reloc,    /* special_function */
248
   "r_switch16",    /* name */
249
   true,      /* partial_inplace */
250
   0xffff,    /* src_mask */
251
   0xffff,    /* dst_mask */
252
   false),    /* pcrel_offset */
253
254
  HOWTO (R_SH_SWITCH32,   /* type */
255
   0,     /* rightshift */
256
   4,     /* size */
257
   32,      /* bitsize */
258
   false,     /* pc_relative */
259
   0,     /* bitpos */
260
   complain_overflow_bitfield, /* complain_on_overflow */
261
   sh_reloc,    /* special_function */
262
   "r_switch32",    /* name */
263
   true,      /* partial_inplace */
264
   0xffffffff,    /* src_mask */
265
   0xffffffff,    /* dst_mask */
266
   false),    /* pcrel_offset */
267
268
  HOWTO (R_SH_USES,   /* type */
269
   0,     /* rightshift */
270
   2,     /* size */
271
   16,      /* bitsize */
272
   false,     /* pc_relative */
273
   0,     /* bitpos */
274
   complain_overflow_bitfield, /* complain_on_overflow */
275
   sh_reloc,    /* special_function */
276
   "r_uses",    /* name */
277
   true,      /* partial_inplace */
278
   0xffff,    /* src_mask */
279
   0xffff,    /* dst_mask */
280
   false),    /* pcrel_offset */
281
282
  HOWTO (R_SH_COUNT,    /* type */
283
   0,     /* rightshift */
284
   4,     /* size */
285
   32,      /* bitsize */
286
   false,     /* pc_relative */
287
   0,     /* bitpos */
288
   complain_overflow_bitfield, /* complain_on_overflow */
289
   sh_reloc,    /* special_function */
290
   "r_count",   /* name */
291
   true,      /* partial_inplace */
292
   0xffffffff,    /* src_mask */
293
   0xffffffff,    /* dst_mask */
294
   false),    /* pcrel_offset */
295
296
  HOWTO (R_SH_ALIGN,    /* type */
297
   0,     /* rightshift */
298
   4,     /* size */
299
   32,      /* bitsize */
300
   false,     /* pc_relative */
301
   0,     /* bitpos */
302
   complain_overflow_bitfield, /* complain_on_overflow */
303
   sh_reloc,    /* special_function */
304
   "r_align",   /* name */
305
   true,      /* partial_inplace */
306
   0xffffffff,    /* src_mask */
307
   0xffffffff,    /* dst_mask */
308
   false),    /* pcrel_offset */
309
310
  HOWTO (R_SH_CODE,   /* type */
311
   0,     /* rightshift */
312
   4,     /* size */
313
   32,      /* bitsize */
314
   false,     /* pc_relative */
315
   0,     /* bitpos */
316
   complain_overflow_bitfield, /* complain_on_overflow */
317
   sh_reloc,    /* special_function */
318
   "r_code",    /* name */
319
   true,      /* partial_inplace */
320
   0xffffffff,    /* src_mask */
321
   0xffffffff,    /* dst_mask */
322
   false),    /* pcrel_offset */
323
324
  HOWTO (R_SH_DATA,   /* type */
325
   0,     /* rightshift */
326
   4,     /* size */
327
   32,      /* bitsize */
328
   false,     /* pc_relative */
329
   0,     /* bitpos */
330
   complain_overflow_bitfield, /* complain_on_overflow */
331
   sh_reloc,    /* special_function */
332
   "r_data",    /* name */
333
   true,      /* partial_inplace */
334
   0xffffffff,    /* src_mask */
335
   0xffffffff,    /* dst_mask */
336
   false),    /* pcrel_offset */
337
338
  HOWTO (R_SH_LABEL,    /* type */
339
   0,     /* rightshift */
340
   4,     /* size */
341
   32,      /* bitsize */
342
   false,     /* pc_relative */
343
   0,     /* bitpos */
344
   complain_overflow_bitfield, /* complain_on_overflow */
345
   sh_reloc,    /* special_function */
346
   "r_label",   /* name */
347
   true,      /* partial_inplace */
348
   0xffffffff,    /* src_mask */
349
   0xffffffff,    /* dst_mask */
350
   false),    /* pcrel_offset */
351
352
  HOWTO (R_SH_SWITCH8,    /* type */
353
   0,     /* rightshift */
354
   1,     /* size */
355
   8,     /* bitsize */
356
   false,     /* pc_relative */
357
   0,     /* bitpos */
358
   complain_overflow_bitfield, /* complain_on_overflow */
359
   sh_reloc,    /* special_function */
360
   "r_switch8",   /* name */
361
   true,      /* partial_inplace */
362
   0xff,      /* src_mask */
363
   0xff,      /* dst_mask */
364
   false)     /* pcrel_offset */
365
};
366
367
1.58k
#define SH_COFF_HOWTO_COUNT (sizeof sh_coff_howtos / sizeof sh_coff_howtos[0])
368
369
/* Check for a bad magic number.  */
370
701k
#define BADMAG(x) SHBADMAG(x)
371
372
/* Customize coffcode.h (this is not currently used).  */
373
#define SH 1
374
375
/* FIXME: This should not be set here.  */
376
#define __A_MAGIC_SET__
377
378
#ifndef COFF_WITH_PE
379
/* Swap the r_offset field in and out.  */
380
736
#define SWAP_IN_RELOC_OFFSET  H_GET_32
381
0
#define SWAP_OUT_RELOC_OFFSET H_PUT_32
382
383
/* Swap out extra information in the reloc structure.  */
384
#define SWAP_OUT_RELOC_EXTRA(abfd, src, dst)  \
385
0
  do            \
386
0
    {           \
387
0
      dst->r_stuff[0] = 'S';      \
388
0
      dst->r_stuff[1] = 'C';      \
389
0
    }            \
390
0
  while (0)
391
#endif
392
393
/* Get the value of a symbol, when performing a relocation.  */
394
395
static long
396
get_symbol_value (asymbol *symbol)
397
0
{
398
0
  bfd_vma relocation;
399
400
0
  if (bfd_is_com_section (symbol->section))
401
0
    relocation = 0;
402
0
  else
403
0
    relocation = (symbol->value +
404
0
      symbol->section->output_section->vma +
405
0
      symbol->section->output_offset);
406
407
0
  return relocation;
408
0
}
Unexecuted instantiation: coff-sh.c:get_symbol_value
Unexecuted instantiation: pe-sh.c:get_symbol_value
Unexecuted instantiation: pei-sh.c:get_symbol_value
409
410
#ifdef COFF_WITH_PE
411
/* Convert an rtype to howto for the COFF backend linker.
412
   Copied from coff-i386.  */
413
#define coff_rtype_to_howto coff_sh_rtype_to_howto
414
415
416
static reloc_howto_type *
417
coff_sh_rtype_to_howto (bfd * abfd ATTRIBUTE_UNUSED,
418
      asection * sec,
419
      struct internal_reloc * rel,
420
      struct coff_link_hash_entry * h,
421
      struct internal_syment * sym,
422
      bfd_vma * addendp)
423
0
{
424
0
  reloc_howto_type * howto;
425
426
0
  howto = sh_coff_howtos + rel->r_type;
427
428
0
  *addendp = 0;
429
430
0
  if (howto->pc_relative)
431
0
    *addendp += sec->vma;
432
433
0
  if (sym != NULL && sym->n_scnum == 0 && sym->n_value != 0)
434
0
    {
435
      /* This is a common symbol.  The section contents include the
436
   size (sym->n_value) as an addend.  The relocate_section
437
   function will be adding in the final value of the symbol.  We
438
   need to subtract out the current size in order to get the
439
   correct result.  */
440
0
      BFD_ASSERT (h != NULL);
441
0
    }
442
443
0
  if (howto->pc_relative)
444
0
    {
445
0
      *addendp -= 4;
446
447
      /* If the symbol is defined, then the generic code is going to
448
   add back the symbol value in order to cancel out an
449
   adjustment it made to the addend.  However, we set the addend
450
   to 0 at the start of this function.  We need to adjust here,
451
   to avoid the adjustment the generic code will make.  FIXME:
452
   This is getting a bit hackish.  */
453
0
      if (sym != NULL && sym->n_scnum != 0)
454
0
  *addendp -= sym->n_value;
455
0
    }
456
457
0
  if (rel->r_type == R_SH_IMAGEBASE)
458
0
    *addendp -= pe_data (sec->output_section->owner)->pe_opthdr.ImageBase;
459
460
0
  return howto;
461
0
}
Unexecuted instantiation: pe-sh.c:coff_sh_rtype_to_howto
Unexecuted instantiation: pei-sh.c:coff_sh_rtype_to_howto
462
463
#endif /* COFF_WITH_PE */
464
465
/* This structure is used to map BFD reloc codes to SH PE relocs.  */
466
struct shcoff_reloc_map
467
{
468
  bfd_reloc_code_real_type bfd_reloc_val;
469
  unsigned char shcoff_reloc_val;
470
};
471
472
#ifdef COFF_WITH_PE
473
/* An array mapping BFD reloc codes to SH PE relocs.  */
474
static const struct shcoff_reloc_map sh_reloc_map[] =
475
{
476
  { BFD_RELOC_32, R_SH_IMM32CE },
477
  { BFD_RELOC_RVA, R_SH_IMAGEBASE },
478
  { BFD_RELOC_CTOR, R_SH_IMM32CE },
479
};
480
#else
481
/* An array mapping BFD reloc codes to SH PE relocs.  */
482
static const struct shcoff_reloc_map sh_reloc_map[] =
483
{
484
  { BFD_RELOC_32, R_SH_IMM32 },
485
  { BFD_RELOC_CTOR, R_SH_IMM32 },
486
};
487
#endif
488
489
/* Given a BFD reloc code, return the howto structure for the
490
   corresponding SH PE reloc.  */
491
#define coff_bfd_reloc_type_lookup  sh_coff_reloc_type_lookup
492
#define coff_bfd_reloc_name_lookup sh_coff_reloc_name_lookup
493
494
static reloc_howto_type *
495
sh_coff_reloc_type_lookup (bfd *abfd,
496
         bfd_reloc_code_real_type code)
497
363
{
498
363
  unsigned int i;
499
500
807
  for (i = ARRAY_SIZE (sh_reloc_map); i--;)
501
807
    if (sh_reloc_map[i].bfd_reloc_val == code)
502
363
      return &sh_coff_howtos[(int) sh_reloc_map[i].shcoff_reloc_val];
503
504
0
  _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
505
0
          abfd, (unsigned int) code);
506
0
  return NULL;
507
363
}
Unexecuted instantiation: coff-sh.c:sh_coff_reloc_type_lookup
Unexecuted instantiation: pe-sh.c:sh_coff_reloc_type_lookup
pei-sh.c:sh_coff_reloc_type_lookup
Line
Count
Source
497
363
{
498
363
  unsigned int i;
499
500
807
  for (i = ARRAY_SIZE (sh_reloc_map); i--;)
501
807
    if (sh_reloc_map[i].bfd_reloc_val == code)
502
363
      return &sh_coff_howtos[(int) sh_reloc_map[i].shcoff_reloc_val];
503
504
0
  _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
505
0
          abfd, (unsigned int) code);
506
  return NULL;
507
363
}
508
509
static reloc_howto_type *
510
sh_coff_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
511
         const char *r_name)
512
0
{
513
0
  unsigned int i;
514
515
0
  for (i = 0; i < sizeof (sh_coff_howtos) / sizeof (sh_coff_howtos[0]); i++)
516
0
    if (sh_coff_howtos[i].name != NULL
517
0
  && strcasecmp (sh_coff_howtos[i].name, r_name) == 0)
518
0
      return &sh_coff_howtos[i];
519
520
0
  return NULL;
521
0
}
Unexecuted instantiation: coff-sh.c:sh_coff_reloc_name_lookup
Unexecuted instantiation: pe-sh.c:sh_coff_reloc_name_lookup
Unexecuted instantiation: pei-sh.c:sh_coff_reloc_name_lookup
522
523
/* This macro is used in coffcode.h to get the howto corresponding to
524
   an internal reloc.  */
525
526
#define RTYPE2HOWTO(relent, internal)   \
527
1.58k
  ((relent)->howto =        \
528
1.58k
   ((internal)->r_type < SH_COFF_HOWTO_COUNT  \
529
1.58k
    ? &sh_coff_howtos[(internal)->r_type]  \
530
1.58k
    : (reloc_howto_type *) NULL))
531
532
/* This is the same as the macro in coffcode.h, except that it copies
533
   r_offset into reloc_entry->addend for some relocs.  */
534
#define CALC_ADDEND(abfd, ptr, reloc, cache_ptr)    \
535
1.58k
  {               \
536
1.58k
    coff_symbol_type *coffsym = (coff_symbol_type *) NULL;  \
537
1.58k
    if (ptr && bfd_asymbol_bfd (ptr) != abfd)     \
538
1.58k
      coffsym = (obj_symbols (abfd)       \
539
0
     + (cache_ptr->sym_ptr_ptr - symbols));   \
540
1.58k
    else if (ptr)           \
541
1.58k
      coffsym = coff_symbol_from (ptr);       \
542
1.58k
    if (coffsym != (coff_symbol_type *) NULL      \
543
1.58k
  && coffsym->native->u.syment.n_scnum == 0)   \
544
1.58k
      cache_ptr->addend = 0;         \
545
1.58k
    else if (ptr && bfd_asymbol_bfd (ptr) == abfd    \
546
1.51k
       && ptr->section != (asection *) NULL)   \
547
1.51k
      cache_ptr->addend = - (ptr->section->vma      \
548
301
           + COFF_PE_ADDEND_BIAS (ptr)); \
549
1.51k
    else              \
550
1.51k
      cache_ptr->addend = 0;         \
551
1.58k
    if ((reloc).r_type == R_SH_SWITCH8        \
552
1.58k
  || (reloc).r_type == R_SH_SWITCH16      \
553
1.58k
  || (reloc).r_type == R_SH_SWITCH32      \
554
1.58k
  || (reloc).r_type == R_SH_USES        \
555
1.58k
  || (reloc).r_type == R_SH_COUNT        \
556
1.58k
  || (reloc).r_type == R_SH_ALIGN)     \
557
1.58k
      cache_ptr->addend = (reloc).r_offset;     \
558
1.58k
  }
559
560
/* This is the howto function for the SH relocations.  */
561
562
static bfd_reloc_status_type
563
sh_reloc (bfd *      abfd,
564
    arelent *  reloc_entry,
565
    asymbol *  symbol_in,
566
    void *     data,
567
    asection * input_section,
568
    bfd *      output_bfd,
569
    char **    error_message ATTRIBUTE_UNUSED)
570
0
{
571
0
  bfd_vma insn;
572
0
  bfd_vma sym_value;
573
0
  unsigned short r_type;
574
0
  bfd_vma addr = reloc_entry->address;
575
0
  bfd_byte *hit_data = addr + (bfd_byte *) data;
576
577
0
  r_type = reloc_entry->howto->type;
578
579
0
  if (output_bfd != NULL)
580
0
    {
581
      /* Partial linking--do nothing.  */
582
0
      reloc_entry->address += input_section->output_offset;
583
0
      return bfd_reloc_ok;
584
0
    }
585
586
  /* Almost all relocs have to do with relaxing.  If any work must be
587
     done for them, it has been done in sh_relax_section.  */
588
0
  if (r_type != R_SH_IMM32
589
#ifdef COFF_WITH_PE
590
0
      && r_type != R_SH_IMM32CE
591
0
      && r_type != R_SH_IMAGEBASE
592
0
#endif
593
0
      && (r_type != R_SH_PCDISP
594
0
    || (symbol_in->flags & BSF_LOCAL) != 0))
595
0
    return bfd_reloc_ok;
596
597
0
  if (symbol_in != NULL
598
0
      && bfd_is_und_section (symbol_in->section))
599
0
    return bfd_reloc_undefined;
600
601
0
  if (!bfd_reloc_offset_in_range (reloc_entry->howto, abfd, input_section,
602
0
          addr))
603
0
    return bfd_reloc_outofrange;
604
605
0
  sym_value = get_symbol_value (symbol_in);
606
607
0
  switch (r_type)
608
0
    {
609
0
    case R_SH_IMM32:
610
#ifdef COFF_WITH_PE
611
0
    case R_SH_IMM32CE:
612
#endif
613
0
      insn = bfd_get_32 (abfd, hit_data);
614
0
      insn += sym_value + reloc_entry->addend;
615
0
      bfd_put_32 (abfd, insn, hit_data);
616
0
      break;
617
#ifdef COFF_WITH_PE
618
0
    case R_SH_IMAGEBASE:
619
0
      insn = bfd_get_32 (abfd, hit_data);
620
0
      insn += sym_value + reloc_entry->addend;
621
0
      insn -= pe_data (input_section->output_section->owner)->pe_opthdr.ImageBase;
622
0
      bfd_put_32 (abfd, insn, hit_data);
623
0
      break;
624
0
#endif
625
0
    case R_SH_PCDISP:
626
0
      insn = bfd_get_16 (abfd, hit_data);
627
0
      sym_value += reloc_entry->addend;
628
0
      sym_value -= (input_section->output_section->vma
629
0
        + input_section->output_offset
630
0
        + addr
631
0
        + 4);
632
0
      sym_value += (((insn & 0xfff) ^ 0x800) - 0x800) << 1;
633
0
      insn = (insn & 0xf000) | ((sym_value >> 1) & 0xfff);
634
0
      bfd_put_16 (abfd, insn, hit_data);
635
0
      if (sym_value + 0x1000 >= 0x2000 || (sym_value & 1) != 0)
636
0
  return bfd_reloc_overflow;
637
0
      break;
638
0
    default:
639
0
      abort ();
640
0
      break;
641
0
    }
642
643
0
  return bfd_reloc_ok;
644
0
}
Unexecuted instantiation: coff-sh.c:sh_reloc
Unexecuted instantiation: pe-sh.c:sh_reloc
Unexecuted instantiation: pei-sh.c:sh_reloc
645
646
#define coff_bfd_merge_private_bfd_data _bfd_generic_verify_endian_match
647
648
/* We can do relaxing.  */
649
#define coff_bfd_relax_section sh_relax_section
650
651
/* We use the special COFF backend linker.  */
652
#define coff_relocate_section sh_relocate_section
653
654
/* When relaxing, we need to use special code to get the relocated
655
   section contents.  */
656
#define coff_bfd_get_relocated_section_contents \
657
  sh_coff_get_relocated_section_contents
658
659
#include "coffcode.h"
660

661
static bool
662
sh_relax_delete_bytes (bfd *, asection *, bfd_vma, int);
663
664
/* This function handles relaxing on the SH.
665
666
   Function calls on the SH look like this:
667
668
       movl  L1,r0
669
       ...
670
       jsr   @r0
671
       ...
672
     L1:
673
       .long function
674
675
   The compiler and assembler will cooperate to create R_SH_USES
676
   relocs on the jsr instructions.  The r_offset field of the
677
   R_SH_USES reloc is the PC relative offset to the instruction which
678
   loads the register (the r_offset field is computed as though it
679
   were a jump instruction, so the offset value is actually from four
680
   bytes past the instruction).  The linker can use this reloc to
681
   determine just which function is being called, and thus decide
682
   whether it is possible to replace the jsr with a bsr.
683
684
   If multiple function calls are all based on a single register load
685
   (i.e., the same function is called multiple times), the compiler
686
   guarantees that each function call will have an R_SH_USES reloc.
687
   Therefore, if the linker is able to convert each R_SH_USES reloc
688
   which refers to that address, it can safely eliminate the register
689
   load.
690
691
   When the assembler creates an R_SH_USES reloc, it examines it to
692
   determine which address is being loaded (L1 in the above example).
693
   It then counts the number of references to that address, and
694
   creates an R_SH_COUNT reloc at that address.  The r_offset field of
695
   the R_SH_COUNT reloc will be the number of references.  If the
696
   linker is able to eliminate a register load, it can use the
697
   R_SH_COUNT reloc to see whether it can also eliminate the function
698
   address.
699
700
   SH relaxing also handles another, unrelated, matter.  On the SH, if
701
   a load or store instruction is not aligned on a four byte boundary,
702
   the memory cycle interferes with the 32 bit instruction fetch,
703
   causing a one cycle bubble in the pipeline.  Therefore, we try to
704
   align load and store instructions on four byte boundaries if we
705
   can, by swapping them with one of the adjacent instructions.  */
706
707
static bool
708
sh_relax_section (bfd *abfd,
709
      asection *sec,
710
      struct bfd_link_info *link_info,
711
      bool *again)
712
0
{
713
0
  struct internal_reloc *internal_relocs;
714
0
  bool have_code;
715
0
  struct internal_reloc *irel, *irelend;
716
0
  bfd_byte *contents = NULL;
717
718
0
  *again = false;
719
720
0
  if (bfd_link_relocatable (link_info)
721
0
      || (sec->flags & SEC_HAS_CONTENTS) == 0
722
0
      || (sec->flags & SEC_RELOC) == 0
723
0
      || sec->reloc_count == 0)
724
0
    return true;
725
726
0
  if (coff_section_data (abfd, sec) == NULL)
727
0
    {
728
0
      size_t amt = sizeof (struct coff_section_tdata);
729
0
      sec->used_by_bfd = bfd_zalloc (abfd, amt);
730
0
      if (sec->used_by_bfd == NULL)
731
0
  return false;
732
0
    }
733
734
0
  internal_relocs = (bfd_coff_read_internal_relocs
735
0
         (abfd, sec, link_info->keep_memory,
736
0
          NULL, false, NULL));
737
0
  if (internal_relocs == NULL)
738
0
    goto error_return;
739
740
0
  have_code = false;
741
742
0
  irelend = internal_relocs + sec->reloc_count;
743
0
  for (irel = internal_relocs; irel < irelend; irel++)
744
0
    {
745
0
      bfd_vma laddr, paddr, symval;
746
0
      unsigned short insn;
747
0
      struct internal_reloc *irelfn, *irelscan, *irelcount;
748
0
      struct internal_syment sym;
749
0
      bfd_signed_vma foff;
750
751
0
      if (irel->r_type == R_SH_CODE)
752
0
  have_code = true;
753
754
0
      if (irel->r_type != R_SH_USES)
755
0
  continue;
756
757
      /* Get the section contents.  */
758
0
      if (contents == NULL)
759
0
  {
760
0
    if (coff_section_data (abfd, sec)->contents != NULL)
761
0
      contents = coff_section_data (abfd, sec)->contents;
762
0
    else
763
0
      {
764
0
        if (!bfd_malloc_and_get_section (abfd, sec, &contents))
765
0
    goto error_return;
766
0
      }
767
0
  }
768
769
      /* The r_offset field of the R_SH_USES reloc will point us to
770
   the register load.  The 4 is because the r_offset field is
771
   computed as though it were a jump offset, which are based
772
   from 4 bytes after the jump instruction.  */
773
0
      laddr = irel->r_vaddr - sec->vma + 4;
774
      /* Careful to sign extend the 32-bit offset.  */
775
0
      laddr += ((irel->r_offset & 0xffffffff) ^ 0x80000000) - 0x80000000;
776
0
      if (laddr >= sec->size)
777
0
  {
778
    /* xgettext: c-format */
779
0
    _bfd_error_handler
780
0
      (_("%pB: %#" PRIx64 ": warning: bad R_SH_USES offset"),
781
0
       abfd, (uint64_t) irel->r_vaddr);
782
0
    continue;
783
0
  }
784
0
      insn = bfd_get_16 (abfd, contents + laddr);
785
786
      /* If the instruction is not mov.l NN,rN, we don't know what to do.  */
787
0
      if ((insn & 0xf000) != 0xd000)
788
0
  {
789
0
    _bfd_error_handler
790
      /* xgettext: c-format */
791
0
      (_("%pB: %#" PRIx64 ": warning: R_SH_USES points to unrecognized insn %#x"),
792
0
       abfd, (uint64_t) irel->r_vaddr, insn);
793
0
    continue;
794
0
  }
795
796
      /* Get the address from which the register is being loaded.  The
797
   displacement in the mov.l instruction is quadrupled.  It is a
798
   displacement from four bytes after the movl instruction, but,
799
   before adding in the PC address, two least significant bits
800
   of the PC are cleared.  We assume that the section is aligned
801
   on a four byte boundary.  */
802
0
      paddr = insn & 0xff;
803
0
      paddr *= 4;
804
0
      paddr += (laddr + 4) &~ (bfd_vma) 3;
805
0
      if (paddr >= sec->size)
806
0
  {
807
0
    _bfd_error_handler
808
      /* xgettext: c-format */
809
0
      (_("%pB: %#" PRIx64 ": warning: bad R_SH_USES load offset"),
810
0
       abfd, (uint64_t) irel->r_vaddr);
811
0
    continue;
812
0
  }
813
814
      /* Get the reloc for the address from which the register is
815
   being loaded.  This reloc will tell us which function is
816
   actually being called.  */
817
0
      paddr += sec->vma;
818
0
      for (irelfn = internal_relocs; irelfn < irelend; irelfn++)
819
0
  if (irelfn->r_vaddr == paddr
820
#ifdef COFF_WITH_PE
821
0
      && (irelfn->r_type == R_SH_IMM32
822
0
    || irelfn->r_type == R_SH_IMM32CE
823
0
    || irelfn->r_type == R_SH_IMAGEBASE)
824
825
#else
826
0
      && irelfn->r_type == R_SH_IMM32
827
#endif
828
0
      )
829
0
    break;
830
0
      if (irelfn >= irelend)
831
0
  {
832
0
    _bfd_error_handler
833
      /* xgettext: c-format */
834
0
      (_("%pB: %#" PRIx64 ": warning: could not find expected reloc"),
835
0
       abfd, (uint64_t) paddr);
836
0
    continue;
837
0
  }
838
839
      /* Get the value of the symbol referred to by the reloc.  */
840
0
      if (! _bfd_coff_get_external_symbols (abfd))
841
0
  goto error_return;
842
      /* Sentinel -1 indicates no symbol; skip.  */
843
0
      if (irelfn->r_symndx == -1)
844
0
  continue;
845
0
      if (! coff_symndx_in_range (abfd, irelfn->r_symndx))
846
0
  {
847
0
    _bfd_error_handler
848
      /* xgettext: c-format */
849
0
      (_("%pB: %#" PRIx64 ": invalid symbol index %ld in relocs"),
850
0
       abfd, (uint64_t) irelfn->r_vaddr, irelfn->r_symndx);
851
0
    continue;
852
0
  }
853
0
      bfd_coff_swap_sym_in (abfd,
854
0
          ((bfd_byte *) obj_coff_external_syms (abfd)
855
0
           + (irelfn->r_symndx
856
0
        * bfd_coff_symesz (abfd))),
857
0
          &sym);
858
0
      if (sym.n_scnum != 0 && sym.n_scnum != sec->target_index)
859
0
  {
860
0
    _bfd_error_handler
861
      /* xgettext: c-format */
862
0
      (_("%pB: %#" PRIx64 ": warning: symbol in unexpected section"),
863
0
       abfd, (uint64_t) paddr);
864
0
    continue;
865
0
  }
866
867
0
      if (sym.n_sclass != C_EXT)
868
0
  {
869
0
    symval = (sym.n_value
870
0
        - sec->vma
871
0
        + sec->output_section->vma
872
0
        + sec->output_offset);
873
0
  }
874
0
      else
875
0
  {
876
0
    struct coff_link_hash_entry *h;
877
878
0
    h = obj_coff_sym_hashes (abfd)[irelfn->r_symndx];
879
0
    BFD_ASSERT (h != NULL);
880
0
    if (h->root.type != bfd_link_hash_defined
881
0
        && h->root.type != bfd_link_hash_defweak)
882
0
      {
883
        /* This appears to be a reference to an undefined
884
     symbol.  Just ignore it--it will be caught by the
885
     regular reloc processing.  */
886
0
        continue;
887
0
      }
888
889
0
    symval = (h->root.u.def.value
890
0
        + h->root.u.def.section->output_section->vma
891
0
        + h->root.u.def.section->output_offset);
892
0
  }
893
894
0
      symval += bfd_get_32 (abfd, contents + paddr - sec->vma);
895
896
      /* See if this function call can be shortened.  */
897
0
      foff = (symval
898
0
        - (irel->r_vaddr
899
0
     - sec->vma
900
0
     + sec->output_section->vma
901
0
     + sec->output_offset
902
0
     + 4));
903
0
      if (foff < -0x1000 || foff >= 0x1000)
904
0
  {
905
    /* After all that work, we can't shorten this function call.  */
906
0
    continue;
907
0
  }
908
909
      /* Shorten the function call.  */
910
911
      /* For simplicity of coding, we are going to modify the section
912
   contents, the section relocs, and the BFD symbol table.  We
913
   must tell the rest of the code not to free up this
914
   information.  It would be possible to instead create a table
915
   of changes which have to be made, as is done in coff-mips.c;
916
   that would be more work, but would require less memory when
917
   the linker is run.  */
918
919
0
      coff_section_data (abfd, sec)->relocs = internal_relocs;
920
0
      coff_section_data (abfd, sec)->contents = contents;
921
922
      /* Replace the jsr with a bsr.  */
923
924
      /* Change the R_SH_USES reloc into an R_SH_PCDISP reloc, and
925
   replace the jsr with a bsr.  */
926
0
      irel->r_type = R_SH_PCDISP;
927
0
      irel->r_symndx = irelfn->r_symndx;
928
0
      if (sym.n_sclass != C_EXT)
929
0
  {
930
    /* If this needs to be changed because of future relaxing,
931
       it will be handled here like other internal PCDISP
932
       relocs.  */
933
0
    bfd_put_16 (abfd,
934
0
          (bfd_vma) 0xb000 | ((foff >> 1) & 0xfff),
935
0
          contents + irel->r_vaddr - sec->vma);
936
0
  }
937
0
      else
938
0
  {
939
    /* We can't fully resolve this yet, because the external
940
       symbol value may be changed by future relaxing.  We let
941
       the final link phase handle it.  */
942
0
    bfd_put_16 (abfd, (bfd_vma) 0xb000,
943
0
          contents + irel->r_vaddr - sec->vma);
944
0
  }
945
946
      /* See if there is another R_SH_USES reloc referring to the same
947
   register load.  */
948
0
      for (irelscan = internal_relocs; irelscan < irelend; irelscan++)
949
0
  if (irelscan->r_type == R_SH_USES
950
0
      && laddr == irelscan->r_vaddr - sec->vma + 4 + irelscan->r_offset)
951
0
    break;
952
0
      if (irelscan < irelend)
953
0
  {
954
    /* Some other function call depends upon this register load,
955
       and we have not yet converted that function call.
956
       Indeed, we may never be able to convert it.  There is
957
       nothing else we can do at this point.  */
958
0
    continue;
959
0
  }
960
961
      /* Look for a R_SH_COUNT reloc on the location where the
962
   function address is stored.  Do this before deleting any
963
   bytes, to avoid confusion about the address.  */
964
0
      for (irelcount = internal_relocs; irelcount < irelend; irelcount++)
965
0
  if (irelcount->r_vaddr == paddr
966
0
      && irelcount->r_type == R_SH_COUNT)
967
0
    break;
968
969
      /* Delete the register load.  */
970
0
      if (! sh_relax_delete_bytes (abfd, sec, laddr, 2))
971
0
  goto error_return;
972
973
      /* That will change things, so, just in case it permits some
974
   other function call to come within range, we should relax
975
   again.  Note that this is not required, and it may be slow.  */
976
0
      *again = true;
977
978
      /* Now check whether we got a COUNT reloc.  */
979
0
      if (irelcount >= irelend)
980
0
  {
981
0
    _bfd_error_handler
982
      /* xgettext: c-format */
983
0
      (_("%pB: %#" PRIx64 ": warning: could not find expected COUNT reloc"),
984
0
       abfd, (uint64_t) paddr);
985
0
    continue;
986
0
  }
987
988
      /* The number of uses is stored in the r_offset field.  We've
989
   just deleted one.  */
990
0
      if (irelcount->r_offset == 0)
991
0
  {
992
    /* xgettext: c-format */
993
0
    _bfd_error_handler (_("%pB: %#" PRIx64 ": warning: bad count"),
994
0
            abfd, (uint64_t) paddr);
995
0
    continue;
996
0
  }
997
998
0
      --irelcount->r_offset;
999
1000
      /* If there are no more uses, we can delete the address.  Reload
1001
   the address from irelfn, in case it was changed by the
1002
   previous call to sh_relax_delete_bytes.  */
1003
0
      if (irelcount->r_offset == 0)
1004
0
  {
1005
0
    if (! sh_relax_delete_bytes (abfd, sec,
1006
0
               irelfn->r_vaddr - sec->vma, 4))
1007
0
      goto error_return;
1008
0
  }
1009
1010
      /* We've done all we can with that function call.  */
1011
0
    }
1012
1013
  /* Look for load and store instructions that we can align on four
1014
     byte boundaries.  */
1015
0
  if (have_code)
1016
0
    {
1017
0
      bool swapped;
1018
1019
      /* Get the section contents.  */
1020
0
      if (contents == NULL)
1021
0
  {
1022
0
    if (coff_section_data (abfd, sec)->contents != NULL)
1023
0
      contents = coff_section_data (abfd, sec)->contents;
1024
0
    else
1025
0
      {
1026
0
        if (!bfd_malloc_and_get_section (abfd, sec, &contents))
1027
0
    goto error_return;
1028
0
      }
1029
0
  }
1030
1031
0
      if (! sh_align_loads (abfd, sec, internal_relocs, contents, &swapped))
1032
0
  goto error_return;
1033
1034
0
      if (swapped)
1035
0
  {
1036
0
    coff_section_data (abfd, sec)->relocs = internal_relocs;
1037
0
    coff_section_data (abfd, sec)->contents = contents;
1038
0
  }
1039
0
    }
1040
1041
0
  if (internal_relocs != NULL
1042
0
      && internal_relocs != coff_section_data (abfd, sec)->relocs)
1043
0
    {
1044
0
      if (! link_info->keep_memory)
1045
0
  free (internal_relocs);
1046
0
      else
1047
0
  coff_section_data (abfd, sec)->relocs = internal_relocs;
1048
0
    }
1049
1050
0
  if (contents != NULL && contents != coff_section_data (abfd, sec)->contents)
1051
0
    {
1052
0
      if (! link_info->keep_memory)
1053
0
  free (contents);
1054
0
      else
1055
  /* Cache the section contents for coff_link_input_bfd.  */
1056
0
  coff_section_data (abfd, sec)->contents = contents;
1057
0
    }
1058
1059
0
  return true;
1060
1061
0
 error_return:
1062
0
  if (internal_relocs != coff_section_data (abfd, sec)->relocs)
1063
0
    free (internal_relocs);
1064
0
  if (contents != coff_section_data (abfd, sec)->contents)
1065
0
    free (contents);
1066
0
  return false;
1067
0
}
Unexecuted instantiation: coff-sh.c:sh_relax_section
Unexecuted instantiation: pe-sh.c:sh_relax_section
Unexecuted instantiation: pei-sh.c:sh_relax_section
1068
1069
/* Delete some bytes from a section while relaxing.  */
1070
1071
static bool
1072
sh_relax_delete_bytes (bfd *abfd,
1073
           asection *sec,
1074
           bfd_vma addr,
1075
           int count)
1076
0
{
1077
0
  bfd_byte *contents;
1078
0
  struct internal_reloc *irel, *irelend;
1079
0
  struct internal_reloc *irelalign;
1080
0
  bfd_vma toaddr;
1081
0
  bfd_byte *esym, *esymend;
1082
0
  bfd_size_type symesz;
1083
0
  struct coff_link_hash_entry **sym_hash;
1084
0
  asection *o;
1085
1086
0
  contents = coff_section_data (abfd, sec)->contents;
1087
1088
  /* The deletion must stop at the next ALIGN reloc for an alignment
1089
     power larger than the number of bytes we are deleting.  */
1090
1091
0
  irelalign = NULL;
1092
0
  toaddr = sec->size;
1093
1094
0
  irel = coff_section_data (abfd, sec)->relocs;
1095
0
  irelend = irel + sec->reloc_count;
1096
0
  for (; irel < irelend; irel++)
1097
0
    {
1098
0
      if (irel->r_type == R_SH_ALIGN
1099
0
    && irel->r_vaddr - sec->vma > addr
1100
0
    && count < (1 << irel->r_offset))
1101
0
  {
1102
0
    irelalign = irel;
1103
0
    toaddr = irel->r_vaddr - sec->vma;
1104
0
    break;
1105
0
  }
1106
0
    }
1107
1108
  /* Actually delete the bytes.  */
1109
0
  memmove (contents + addr, contents + addr + count,
1110
0
     (size_t) (toaddr - addr - count));
1111
0
  if (irelalign == NULL)
1112
0
    sec->size -= count;
1113
0
  else
1114
0
    {
1115
0
      int i;
1116
1117
0
#define NOP_OPCODE (0x0009)
1118
1119
0
      BFD_ASSERT ((count & 1) == 0);
1120
0
      for (i = 0; i < count; i += 2)
1121
0
  bfd_put_16 (abfd, (bfd_vma) NOP_OPCODE, contents + toaddr - count + i);
1122
0
    }
1123
1124
  /* Adjust all the relocs.  */
1125
0
  for (irel = coff_section_data (abfd, sec)->relocs; irel < irelend; irel++)
1126
0
    {
1127
0
      bfd_vma nraddr, stop;
1128
0
      bfd_vma start = 0;
1129
0
      int insn = 0;
1130
0
      struct internal_syment sym;
1131
0
      int off, adjust, oinsn;
1132
0
      bfd_signed_vma voff = 0;
1133
0
      bool overflow;
1134
1135
      /* Get the new reloc address.  */
1136
0
      nraddr = irel->r_vaddr - sec->vma;
1137
0
      if ((irel->r_vaddr - sec->vma > addr
1138
0
     && irel->r_vaddr - sec->vma < toaddr)
1139
0
    || (irel->r_type == R_SH_ALIGN
1140
0
        && irel->r_vaddr - sec->vma == toaddr))
1141
0
  nraddr -= count;
1142
1143
      /* See if this reloc was for the bytes we have deleted, in which
1144
   case we no longer care about it.  Don't delete relocs which
1145
   represent addresses, though.  */
1146
0
      if (irel->r_vaddr - sec->vma >= addr
1147
0
    && irel->r_vaddr - sec->vma < addr + count
1148
0
    && irel->r_type != R_SH_ALIGN
1149
0
    && irel->r_type != R_SH_CODE
1150
0
    && irel->r_type != R_SH_DATA
1151
0
    && irel->r_type != R_SH_LABEL)
1152
0
  irel->r_type = R_SH_UNUSED;
1153
1154
      /* If this is a PC relative reloc, see if the range it covers
1155
   includes the bytes we have deleted.  */
1156
0
      switch (irel->r_type)
1157
0
  {
1158
0
  default:
1159
0
    break;
1160
1161
0
  case R_SH_PCDISP8BY2:
1162
0
  case R_SH_PCDISP:
1163
0
  case R_SH_PCRELIMM8BY2:
1164
0
  case R_SH_PCRELIMM8BY4:
1165
0
    start = irel->r_vaddr - sec->vma;
1166
0
    insn = bfd_get_16 (abfd, contents + nraddr);
1167
0
    break;
1168
0
  }
1169
1170
0
      switch (irel->r_type)
1171
0
  {
1172
0
  default:
1173
0
    start = stop = addr;
1174
0
    break;
1175
1176
0
  case R_SH_IMM32:
1177
#ifdef COFF_WITH_PE
1178
0
  case R_SH_IMM32CE:
1179
0
  case R_SH_IMAGEBASE:
1180
0
#endif
1181
    /* Sentinel -1 indicates no symbol; nothing to adjust.  */
1182
0
    if (irel->r_symndx == -1)
1183
0
      {
1184
0
        start = stop = addr;
1185
0
        break;
1186
0
      }
1187
    /* Skip adjusting this relocation for an invalid symbol index while
1188
       allowing error recovery.  */
1189
0
    if (! coff_symndx_in_range (abfd, irel->r_symndx))
1190
0
      {
1191
0
        _bfd_error_handler
1192
    /* xgettext: c-format */
1193
0
    (_("%pB: %#" PRIx64 ": invalid symbol index %ld in relocs"),
1194
0
     abfd, (uint64_t) irel->r_vaddr, irel->r_symndx);
1195
0
        start = stop = addr;
1196
0
        break;
1197
0
      }
1198
1199
    /* If this reloc is against a symbol defined in this
1200
       section, and the symbol will not be adjusted below, we
1201
       must check the addend to see it will put the value in
1202
       range to be adjusted, and hence must be changed.  */
1203
0
    bfd_coff_swap_sym_in (abfd,
1204
0
        ((bfd_byte *) obj_coff_external_syms (abfd)
1205
0
         + (irel->r_symndx
1206
0
            * bfd_coff_symesz (abfd))),
1207
0
        &sym);
1208
0
    if (sym.n_sclass != C_EXT
1209
0
        && sym.n_scnum == sec->target_index
1210
0
        && ((bfd_vma) sym.n_value <= addr
1211
0
      || (bfd_vma) sym.n_value >= toaddr))
1212
0
      {
1213
0
        bfd_vma val;
1214
1215
0
        val = bfd_get_32 (abfd, contents + nraddr);
1216
0
        val += sym.n_value;
1217
0
        if (val > addr && val < toaddr)
1218
0
    bfd_put_32 (abfd, val - count, contents + nraddr);
1219
0
      }
1220
0
    start = stop = addr;
1221
0
    break;
1222
1223
0
  case R_SH_PCDISP8BY2:
1224
0
    off = insn & 0xff;
1225
0
    if (off & 0x80)
1226
0
      off -= 0x100;
1227
0
    stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
1228
0
    break;
1229
1230
0
  case R_SH_PCDISP:
1231
    /* Sentinel -1 indicates no symbol; nothing to adjust.  */
1232
0
    if (irel->r_symndx == -1)
1233
0
      {
1234
0
        start = stop = addr;
1235
0
        break;
1236
0
      }
1237
0
    if (! coff_symndx_in_range (abfd, irel->r_symndx))
1238
0
      {
1239
0
        _bfd_error_handler
1240
    /* xgettext: c-format */
1241
0
    (_("%pB: %#" PRIx64 ": invalid symbol index %ld in relocs"),
1242
0
     abfd, (uint64_t) irel->r_vaddr, irel->r_symndx);
1243
0
        start = stop = addr;
1244
0
        break;
1245
0
      }
1246
0
    bfd_coff_swap_sym_in (abfd,
1247
0
        ((bfd_byte *) obj_coff_external_syms (abfd)
1248
0
         + (irel->r_symndx
1249
0
            * bfd_coff_symesz (abfd))),
1250
0
        &sym);
1251
0
    if (sym.n_sclass == C_EXT)
1252
0
      start = stop = addr;
1253
0
    else
1254
0
      {
1255
0
        off = insn & 0xfff;
1256
0
        if (off & 0x800)
1257
0
    off -= 0x1000;
1258
0
        stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
1259
0
      }
1260
0
    break;
1261
1262
0
  case R_SH_PCRELIMM8BY2:
1263
0
    off = insn & 0xff;
1264
0
    stop = start + 4 + off * 2;
1265
0
    break;
1266
1267
0
  case R_SH_PCRELIMM8BY4:
1268
0
    off = insn & 0xff;
1269
0
    stop = (start &~ (bfd_vma) 3) + 4 + off * 4;
1270
0
    break;
1271
1272
0
  case R_SH_SWITCH8:
1273
0
  case R_SH_SWITCH16:
1274
0
  case R_SH_SWITCH32:
1275
    /* These relocs types represent
1276
         .word L2-L1
1277
       The r_offset field holds the difference between the reloc
1278
       address and L1.  That is the start of the reloc, and
1279
       adding in the contents gives us the top.  We must adjust
1280
       both the r_offset field and the section contents.  */
1281
1282
0
    start = irel->r_vaddr - sec->vma;
1283
0
    stop = (bfd_vma) ((bfd_signed_vma) start - (long) irel->r_offset);
1284
1285
0
    if (start > addr
1286
0
        && start < toaddr
1287
0
        && (stop <= addr || stop >= toaddr))
1288
0
      irel->r_offset += count;
1289
0
    else if (stop > addr
1290
0
       && stop < toaddr
1291
0
       && (start <= addr || start >= toaddr))
1292
0
      irel->r_offset -= count;
1293
1294
0
    start = stop;
1295
1296
0
    if (irel->r_type == R_SH_SWITCH16)
1297
0
      voff = bfd_get_signed_16 (abfd, contents + nraddr);
1298
0
    else if (irel->r_type == R_SH_SWITCH8)
1299
0
      voff = bfd_get_8 (abfd, contents + nraddr);
1300
0
    else
1301
0
      voff = bfd_get_signed_32 (abfd, contents + nraddr);
1302
0
    stop = (bfd_vma) ((bfd_signed_vma) start + voff);
1303
1304
0
    break;
1305
1306
0
  case R_SH_USES:
1307
0
    start = irel->r_vaddr - sec->vma;
1308
0
    stop = (bfd_vma) ((bfd_signed_vma) start
1309
0
          + (long) irel->r_offset
1310
0
          + 4);
1311
0
    break;
1312
0
  }
1313
1314
0
      if (start > addr
1315
0
    && start < toaddr
1316
0
    && (stop <= addr || stop >= toaddr))
1317
0
  adjust = count;
1318
0
      else if (stop > addr
1319
0
         && stop < toaddr
1320
0
         && (start <= addr || start >= toaddr))
1321
0
  adjust = - count;
1322
0
      else
1323
0
  adjust = 0;
1324
1325
0
      if (adjust != 0)
1326
0
  {
1327
0
    oinsn = insn;
1328
0
    overflow = false;
1329
0
    switch (irel->r_type)
1330
0
      {
1331
0
      default:
1332
0
        abort ();
1333
0
        break;
1334
1335
0
      case R_SH_PCDISP8BY2:
1336
0
      case R_SH_PCRELIMM8BY2:
1337
0
        insn += adjust / 2;
1338
0
        if ((oinsn & 0xff00) != (insn & 0xff00))
1339
0
    overflow = true;
1340
0
        bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
1341
0
        break;
1342
1343
0
      case R_SH_PCDISP:
1344
0
        insn += adjust / 2;
1345
0
        if ((oinsn & 0xf000) != (insn & 0xf000))
1346
0
    overflow = true;
1347
0
        bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
1348
0
        break;
1349
1350
0
      case R_SH_PCRELIMM8BY4:
1351
0
        BFD_ASSERT (adjust == count || count >= 4);
1352
0
        if (count >= 4)
1353
0
    insn += adjust / 4;
1354
0
        else
1355
0
    {
1356
0
      if ((irel->r_vaddr & 3) == 0)
1357
0
        ++insn;
1358
0
    }
1359
0
        if ((oinsn & 0xff00) != (insn & 0xff00))
1360
0
    overflow = true;
1361
0
        bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
1362
0
        break;
1363
1364
0
      case R_SH_SWITCH8:
1365
0
        voff += adjust;
1366
0
        if (voff < 0 || voff >= 0xff)
1367
0
    overflow = true;
1368
0
        bfd_put_8 (abfd, (bfd_vma) voff, contents + nraddr);
1369
0
        break;
1370
1371
0
      case R_SH_SWITCH16:
1372
0
        voff += adjust;
1373
0
        if (voff < - 0x8000 || voff >= 0x8000)
1374
0
    overflow = true;
1375
0
        bfd_put_signed_16 (abfd, (bfd_vma) voff, contents + nraddr);
1376
0
        break;
1377
1378
0
      case R_SH_SWITCH32:
1379
0
        voff += adjust;
1380
0
        bfd_put_signed_32 (abfd, (bfd_vma) voff, contents + nraddr);
1381
0
        break;
1382
1383
0
      case R_SH_USES:
1384
0
        irel->r_offset += adjust;
1385
0
        break;
1386
0
      }
1387
1388
0
    if (overflow)
1389
0
      {
1390
0
        _bfd_error_handler
1391
    /* xgettext: c-format */
1392
0
    (_("%pB: %#" PRIx64 ": fatal: reloc overflow while relaxing"),
1393
0
     abfd, (uint64_t) irel->r_vaddr);
1394
0
        bfd_set_error (bfd_error_bad_value);
1395
0
        return false;
1396
0
      }
1397
0
  }
1398
1399
0
      irel->r_vaddr = nraddr + sec->vma;
1400
0
    }
1401
1402
  /* Look through all the other sections.  If there contain any IMM32
1403
     relocs against internal symbols which we are not going to adjust
1404
     below, we may need to adjust the addends.  */
1405
0
  for (o = abfd->sections; o != NULL; o = o->next)
1406
0
    {
1407
0
      struct internal_reloc *internal_relocs;
1408
0
      struct internal_reloc *irelscan, *irelscanend;
1409
0
      bfd_byte *ocontents;
1410
1411
0
      if (o == sec
1412
0
    || (o->flags & SEC_HAS_CONTENTS) == 0
1413
0
    || (o->flags & SEC_RELOC) == 0
1414
0
    || o->reloc_count == 0)
1415
0
  continue;
1416
1417
      /* We always cache the relocs.  Perhaps, if info->keep_memory is
1418
   FALSE, we should free them, if we are permitted to, when we
1419
   leave sh_coff_relax_section.  */
1420
0
      internal_relocs = (bfd_coff_read_internal_relocs
1421
0
       (abfd, o, true, NULL, false, NULL));
1422
0
      if (internal_relocs == NULL)
1423
0
  return false;
1424
1425
0
      ocontents = NULL;
1426
0
      irelscanend = internal_relocs + o->reloc_count;
1427
0
      for (irelscan = internal_relocs; irelscan < irelscanend; irelscan++)
1428
0
  {
1429
0
    struct internal_syment sym;
1430
1431
#ifdef COFF_WITH_PE
1432
0
    if (irelscan->r_type != R_SH_IMM32
1433
0
        && irelscan->r_type != R_SH_IMAGEBASE
1434
0
        && irelscan->r_type != R_SH_IMM32CE)
1435
#else
1436
0
    if (irelscan->r_type != R_SH_IMM32)
1437
0
#endif
1438
0
      continue;
1439
1440
    /* Sentinel -1 indicates no symbol; skip.  */
1441
0
    if (irelscan->r_symndx == -1)
1442
0
      continue;
1443
0
    if (! coff_symndx_in_range (abfd, irelscan->r_symndx))
1444
0
      {
1445
0
        _bfd_error_handler
1446
    /* xgettext: c-format */
1447
0
    (_("%pB: %#" PRIx64 ": invalid symbol index %ld in relocs"),
1448
0
     abfd, (uint64_t) irelscan->r_vaddr, irelscan->r_symndx);
1449
0
        continue;
1450
0
      }
1451
0
    bfd_coff_swap_sym_in (abfd,
1452
0
        ((bfd_byte *) obj_coff_external_syms (abfd)
1453
0
         + (irelscan->r_symndx
1454
0
            * bfd_coff_symesz (abfd))),
1455
0
        &sym);
1456
0
    if (sym.n_sclass != C_EXT
1457
0
        && sym.n_scnum == sec->target_index
1458
0
        && ((bfd_vma) sym.n_value <= addr
1459
0
      || (bfd_vma) sym.n_value >= toaddr))
1460
0
      {
1461
0
        bfd_vma val;
1462
1463
0
        if (ocontents == NULL)
1464
0
    {
1465
0
      if (coff_section_data (abfd, o)->contents != NULL)
1466
0
        ocontents = coff_section_data (abfd, o)->contents;
1467
0
      else
1468
0
        {
1469
0
          if (!bfd_malloc_and_get_section (abfd, o, &ocontents))
1470
0
      return false;
1471
          /* We always cache the section contents.
1472
       Perhaps, if info->keep_memory is FALSE, we
1473
       should free them, if we are permitted to,
1474
       when we leave sh_coff_relax_section.  */
1475
0
          coff_section_data (abfd, o)->contents = ocontents;
1476
0
        }
1477
0
    }
1478
1479
0
        val = bfd_get_32 (abfd, ocontents + irelscan->r_vaddr - o->vma);
1480
0
        val += sym.n_value;
1481
0
        if (val > addr && val < toaddr)
1482
0
    bfd_put_32 (abfd, val - count,
1483
0
          ocontents + irelscan->r_vaddr - o->vma);
1484
0
      }
1485
0
  }
1486
0
    }
1487
1488
  /* Adjusting the internal symbols will not work if something has
1489
     already retrieved the generic symbols.  It would be possible to
1490
     make this work by adjusting the generic symbols at the same time.
1491
     However, this case should not arise in normal usage.  */
1492
0
  if (obj_symbols (abfd) != NULL
1493
0
      || obj_raw_syments (abfd) != NULL)
1494
0
    {
1495
0
      _bfd_error_handler
1496
0
  (_("%pB: fatal: generic symbols retrieved before relaxing"), abfd);
1497
0
      bfd_set_error (bfd_error_invalid_operation);
1498
0
      return false;
1499
0
    }
1500
1501
  /* Adjust all the symbols.  */
1502
0
  sym_hash = obj_coff_sym_hashes (abfd);
1503
0
  symesz = bfd_coff_symesz (abfd);
1504
0
  esym = (bfd_byte *) obj_coff_external_syms (abfd);
1505
0
  esymend = esym + obj_raw_syment_count (abfd) * symesz;
1506
0
  while (esym < esymend)
1507
0
    {
1508
0
      struct internal_syment isym;
1509
1510
0
      bfd_coff_swap_sym_in (abfd, esym, &isym);
1511
1512
0
      if (isym.n_scnum == sec->target_index
1513
0
    && (bfd_vma) isym.n_value > addr
1514
0
    && (bfd_vma) isym.n_value < toaddr)
1515
0
  {
1516
0
    isym.n_value -= count;
1517
1518
0
    bfd_coff_swap_sym_out (abfd, &isym, esym);
1519
1520
0
    if (*sym_hash != NULL)
1521
0
      {
1522
0
        BFD_ASSERT ((*sym_hash)->root.type == bfd_link_hash_defined
1523
0
        || (*sym_hash)->root.type == bfd_link_hash_defweak);
1524
0
        BFD_ASSERT ((*sym_hash)->root.u.def.value >= addr
1525
0
        && (*sym_hash)->root.u.def.value < toaddr);
1526
0
        (*sym_hash)->root.u.def.value -= count;
1527
0
      }
1528
0
  }
1529
1530
0
      esym += (isym.n_numaux + 1) * symesz;
1531
0
      sym_hash += isym.n_numaux + 1;
1532
0
    }
1533
1534
  /* See if we can move the ALIGN reloc forward.  We have adjusted
1535
     r_vaddr for it already.  */
1536
0
  if (irelalign != NULL)
1537
0
    {
1538
0
      bfd_vma alignto, alignaddr;
1539
1540
0
      alignto = BFD_ALIGN (toaddr, 1 << irelalign->r_offset);
1541
0
      alignaddr = BFD_ALIGN (irelalign->r_vaddr - sec->vma,
1542
0
           1 << irelalign->r_offset);
1543
0
      if (alignto != alignaddr)
1544
0
  {
1545
    /* Tail recursion.  */
1546
0
    return sh_relax_delete_bytes (abfd, sec, alignaddr,
1547
0
          (int) (alignto - alignaddr));
1548
0
  }
1549
0
    }
1550
1551
0
  return true;
1552
0
}
Unexecuted instantiation: coff-sh.c:sh_relax_delete_bytes
Unexecuted instantiation: pe-sh.c:sh_relax_delete_bytes
Unexecuted instantiation: pei-sh.c:sh_relax_delete_bytes
1553

1554
/* This is yet another version of the SH opcode table, used to rapidly
1555
   get information about a particular instruction.  */
1556
1557
/* The opcode map is represented by an array of these structures.  The
1558
   array is indexed by the high order four bits in the instruction.  */
1559
1560
struct sh_major_opcode
1561
{
1562
  /* A pointer to the instruction list.  This is an array which
1563
     contains all the instructions with this major opcode.  */
1564
  const struct sh_minor_opcode *minor_opcodes;
1565
  /* The number of elements in minor_opcodes.  */
1566
  unsigned short count;
1567
};
1568
1569
/* This structure holds information for a set of SH opcodes.  The
1570
   instruction code is anded with the mask value, and the resulting
1571
   value is used to search the order opcode list.  */
1572
1573
struct sh_minor_opcode
1574
{
1575
  /* The sorted opcode list.  */
1576
  const struct sh_opcode *opcodes;
1577
  /* The number of elements in opcodes.  */
1578
  unsigned short count;
1579
  /* The mask value to use when searching the opcode list.  */
1580
  unsigned short mask;
1581
};
1582
1583
/* This structure holds information for an SH instruction.  An array
1584
   of these structures is sorted in order by opcode.  */
1585
1586
struct sh_opcode
1587
{
1588
  /* The code for this instruction, after it has been anded with the
1589
     mask value in the sh_major_opcode structure.  */
1590
  unsigned short opcode;
1591
  /* Flags for this instruction.  */
1592
  unsigned long flags;
1593
};
1594
1595
/* Flag which appear in the sh_opcode structure.  */
1596
1597
/* This instruction loads a value from memory.  */
1598
0
#define LOAD (0x1)
1599
1600
/* This instruction stores a value to memory.  */
1601
0
#define STORE (0x2)
1602
1603
/* This instruction is a branch.  */
1604
0
#define BRANCH (0x4)
1605
1606
/* This instruction has a delay slot.  */
1607
0
#define DELAY (0x8)
1608
1609
/* This instruction uses the value in the register in the field at
1610
   mask 0x0f00 of the instruction.  */
1611
0
#define USES1 (0x10)
1612
0
#define USES1_REG(x) ((x & 0x0f00) >> 8)
1613
1614
/* This instruction uses the value in the register in the field at
1615
   mask 0x00f0 of the instruction.  */
1616
0
#define USES2 (0x20)
1617
0
#define USES2_REG(x) ((x & 0x00f0) >> 4)
1618
1619
/* This instruction uses the value in register 0.  */
1620
0
#define USESR0 (0x40)
1621
1622
/* This instruction sets the value in the register in the field at
1623
   mask 0x0f00 of the instruction.  */
1624
0
#define SETS1 (0x80)
1625
0
#define SETS1_REG(x) ((x & 0x0f00) >> 8)
1626
1627
/* This instruction sets the value in the register in the field at
1628
   mask 0x00f0 of the instruction.  */
1629
0
#define SETS2 (0x100)
1630
0
#define SETS2_REG(x) ((x & 0x00f0) >> 4)
1631
1632
/* This instruction sets register 0.  */
1633
0
#define SETSR0 (0x200)
1634
1635
/* This instruction sets a special register.  */
1636
0
#define SETSSP (0x400)
1637
1638
/* This instruction uses a special register.  */
1639
0
#define USESSP (0x800)
1640
1641
/* This instruction uses the floating point register in the field at
1642
   mask 0x0f00 of the instruction.  */
1643
0
#define USESF1 (0x1000)
1644
0
#define USESF1_REG(x) ((x & 0x0f00) >> 8)
1645
1646
/* This instruction uses the floating point register in the field at
1647
   mask 0x00f0 of the instruction.  */
1648
0
#define USESF2 (0x2000)
1649
0
#define USESF2_REG(x) ((x & 0x00f0) >> 4)
1650
1651
/* This instruction uses floating point register 0.  */
1652
0
#define USESF0 (0x4000)
1653
1654
/* This instruction sets the floating point register in the field at
1655
   mask 0x0f00 of the instruction.  */
1656
0
#define SETSF1 (0x8000)
1657
0
#define SETSF1_REG(x) ((x & 0x0f00) >> 8)
1658
1659
0
#define USESAS (0x10000)
1660
0
#define USESAS_REG(x) (((((x) >> 8) - 2) & 3) + 2)
1661
0
#define USESR8 (0x20000)
1662
0
#define SETSAS (0x40000)
1663
0
#define SETSAS_REG(x) USESAS_REG (x)
1664
1665
#define MAP(a) a, sizeof a / sizeof a[0]
1666
1667
#ifndef COFF_IMAGE_WITH_PE
1668
1669
/* The opcode maps.  */
1670
1671
static const struct sh_opcode sh_opcode00[] =
1672
{
1673
  { 0x0008, SETSSP },     /* clrt */
1674
  { 0x0009, 0 },      /* nop */
1675
  { 0x000b, BRANCH | DELAY | USESSP },  /* rts */
1676
  { 0x0018, SETSSP },     /* sett */
1677
  { 0x0019, SETSSP },     /* div0u */
1678
  { 0x001b, 0 },      /* sleep */
1679
  { 0x0028, SETSSP },     /* clrmac */
1680
  { 0x002b, BRANCH | DELAY | SETSSP },  /* rte */
1681
  { 0x0038, USESSP | SETSSP },    /* ldtlb */
1682
  { 0x0048, SETSSP },     /* clrs */
1683
  { 0x0058, SETSSP }      /* sets */
1684
};
1685
1686
static const struct sh_opcode sh_opcode01[] =
1687
{
1688
  { 0x0003, BRANCH | DELAY | USES1 | SETSSP },  /* bsrf rn */
1689
  { 0x000a, SETS1 | USESSP },     /* sts mach,rn */
1690
  { 0x001a, SETS1 | USESSP },     /* sts macl,rn */
1691
  { 0x0023, BRANCH | DELAY | USES1 },   /* braf rn */
1692
  { 0x0029, SETS1 | USESSP },     /* movt rn */
1693
  { 0x002a, SETS1 | USESSP },     /* sts pr,rn */
1694
  { 0x005a, SETS1 | USESSP },     /* sts fpul,rn */
1695
  { 0x006a, SETS1 | USESSP },     /* sts fpscr,rn / sts dsr,rn */
1696
  { 0x0083, LOAD | USES1 },     /* pref @rn */
1697
  { 0x007a, SETS1 | USESSP },     /* sts a0,rn */
1698
  { 0x008a, SETS1 | USESSP },     /* sts x0,rn */
1699
  { 0x009a, SETS1 | USESSP },     /* sts x1,rn */
1700
  { 0x00aa, SETS1 | USESSP },     /* sts y0,rn */
1701
  { 0x00ba, SETS1 | USESSP }      /* sts y1,rn */
1702
};
1703
1704
static const struct sh_opcode sh_opcode02[] =
1705
{
1706
  { 0x0002, SETS1 | USESSP },     /* stc <special_reg>,rn */
1707
  { 0x0004, STORE | USES1 | USES2 | USESR0 }, /* mov.b rm,@(r0,rn) */
1708
  { 0x0005, STORE | USES1 | USES2 | USESR0 }, /* mov.w rm,@(r0,rn) */
1709
  { 0x0006, STORE | USES1 | USES2 | USESR0 }, /* mov.l rm,@(r0,rn) */
1710
  { 0x0007, SETSSP | USES1 | USES2 },   /* mul.l rm,rn */
1711
  { 0x000c, LOAD | SETS1 | USES2 | USESR0 },  /* mov.b @(r0,rm),rn */
1712
  { 0x000d, LOAD | SETS1 | USES2 | USESR0 },  /* mov.w @(r0,rm),rn */
1713
  { 0x000e, LOAD | SETS1 | USES2 | USESR0 },  /* mov.l @(r0,rm),rn */
1714
  { 0x000f, LOAD|SETS1|SETS2|SETSSP|USES1|USES2|USESSP }, /* mac.l @rm+,@rn+ */
1715
};
1716
1717
static const struct sh_minor_opcode sh_opcode0[] =
1718
{
1719
  { MAP (sh_opcode00), 0xffff },
1720
  { MAP (sh_opcode01), 0xf0ff },
1721
  { MAP (sh_opcode02), 0xf00f }
1722
};
1723
1724
static const struct sh_opcode sh_opcode10[] =
1725
{
1726
  { 0x1000, STORE | USES1 | USES2 } /* mov.l rm,@(disp,rn) */
1727
};
1728
1729
static const struct sh_minor_opcode sh_opcode1[] =
1730
{
1731
  { MAP (sh_opcode10), 0xf000 }
1732
};
1733
1734
static const struct sh_opcode sh_opcode20[] =
1735
{
1736
  { 0x2000, STORE | USES1 | USES2 },    /* mov.b rm,@rn */
1737
  { 0x2001, STORE | USES1 | USES2 },    /* mov.w rm,@rn */
1738
  { 0x2002, STORE | USES1 | USES2 },    /* mov.l rm,@rn */
1739
  { 0x2004, STORE | SETS1 | USES1 | USES2 },  /* mov.b rm,@-rn */
1740
  { 0x2005, STORE | SETS1 | USES1 | USES2 },  /* mov.w rm,@-rn */
1741
  { 0x2006, STORE | SETS1 | USES1 | USES2 },  /* mov.l rm,@-rn */
1742
  { 0x2007, SETSSP | USES1 | USES2 | USESSP },  /* div0s */
1743
  { 0x2008, SETSSP | USES1 | USES2 },   /* tst rm,rn */
1744
  { 0x2009, SETS1 | USES1 | USES2 },    /* and rm,rn */
1745
  { 0x200a, SETS1 | USES1 | USES2 },    /* xor rm,rn */
1746
  { 0x200b, SETS1 | USES1 | USES2 },    /* or rm,rn */
1747
  { 0x200c, SETSSP | USES1 | USES2 },   /* cmp/str rm,rn */
1748
  { 0x200d, SETS1 | USES1 | USES2 },    /* xtrct rm,rn */
1749
  { 0x200e, SETSSP | USES1 | USES2 },   /* mulu.w rm,rn */
1750
  { 0x200f, SETSSP | USES1 | USES2 }    /* muls.w rm,rn */
1751
};
1752
1753
static const struct sh_minor_opcode sh_opcode2[] =
1754
{
1755
  { MAP (sh_opcode20), 0xf00f }
1756
};
1757
1758
static const struct sh_opcode sh_opcode30[] =
1759
{
1760
  { 0x3000, SETSSP | USES1 | USES2 },   /* cmp/eq rm,rn */
1761
  { 0x3002, SETSSP | USES1 | USES2 },   /* cmp/hs rm,rn */
1762
  { 0x3003, SETSSP | USES1 | USES2 },   /* cmp/ge rm,rn */
1763
  { 0x3004, SETSSP | USESSP | USES1 | USES2 },  /* div1 rm,rn */
1764
  { 0x3005, SETSSP | USES1 | USES2 },   /* dmulu.l rm,rn */
1765
  { 0x3006, SETSSP | USES1 | USES2 },   /* cmp/hi rm,rn */
1766
  { 0x3007, SETSSP | USES1 | USES2 },   /* cmp/gt rm,rn */
1767
  { 0x3008, SETS1 | USES1 | USES2 },    /* sub rm,rn */
1768
  { 0x300a, SETS1 | SETSSP | USES1 | USES2 | USESSP }, /* subc rm,rn */
1769
  { 0x300b, SETS1 | SETSSP | USES1 | USES2 }, /* subv rm,rn */
1770
  { 0x300c, SETS1 | USES1 | USES2 },    /* add rm,rn */
1771
  { 0x300d, SETSSP | USES1 | USES2 },   /* dmuls.l rm,rn */
1772
  { 0x300e, SETS1 | SETSSP | USES1 | USES2 | USESSP }, /* addc rm,rn */
1773
  { 0x300f, SETS1 | SETSSP | USES1 | USES2 }  /* addv rm,rn */
1774
};
1775
1776
static const struct sh_minor_opcode sh_opcode3[] =
1777
{
1778
  { MAP (sh_opcode30), 0xf00f }
1779
};
1780
1781
static const struct sh_opcode sh_opcode40[] =
1782
{
1783
  { 0x4000, SETS1 | SETSSP | USES1 },   /* shll rn */
1784
  { 0x4001, SETS1 | SETSSP | USES1 },   /* shlr rn */
1785
  { 0x4002, STORE | SETS1 | USES1 | USESSP }, /* sts.l mach,@-rn */
1786
  { 0x4004, SETS1 | SETSSP | USES1 },   /* rotl rn */
1787
  { 0x4005, SETS1 | SETSSP | USES1 },   /* rotr rn */
1788
  { 0x4006, LOAD | SETS1 | SETSSP | USES1 },  /* lds.l @rm+,mach */
1789
  { 0x4008, SETS1 | USES1 },      /* shll2 rn */
1790
  { 0x4009, SETS1 | USES1 },      /* shlr2 rn */
1791
  { 0x400a, SETSSP | USES1 },     /* lds rm,mach */
1792
  { 0x400b, BRANCH | DELAY | USES1 },   /* jsr @rn */
1793
  { 0x4010, SETS1 | SETSSP | USES1 },   /* dt rn */
1794
  { 0x4011, SETSSP | USES1 },     /* cmp/pz rn */
1795
  { 0x4012, STORE | SETS1 | USES1 | USESSP }, /* sts.l macl,@-rn */
1796
  { 0x4014, SETSSP | USES1 },     /* setrc rm */
1797
  { 0x4015, SETSSP | USES1 },     /* cmp/pl rn */
1798
  { 0x4016, LOAD | SETS1 | SETSSP | USES1 },  /* lds.l @rm+,macl */
1799
  { 0x4018, SETS1 | USES1 },      /* shll8 rn */
1800
  { 0x4019, SETS1 | USES1 },      /* shlr8 rn */
1801
  { 0x401a, SETSSP | USES1 },     /* lds rm,macl */
1802
  { 0x401b, LOAD | SETSSP | USES1 },    /* tas.b @rn */
1803
  { 0x4020, SETS1 | SETSSP | USES1 },   /* shal rn */
1804
  { 0x4021, SETS1 | SETSSP | USES1 },   /* shar rn */
1805
  { 0x4022, STORE | SETS1 | USES1 | USESSP }, /* sts.l pr,@-rn */
1806
  { 0x4024, SETS1 | SETSSP | USES1 | USESSP },  /* rotcl rn */
1807
  { 0x4025, SETS1 | SETSSP | USES1 | USESSP },  /* rotcr rn */
1808
  { 0x4026, LOAD | SETS1 | SETSSP | USES1 },  /* lds.l @rm+,pr */
1809
  { 0x4028, SETS1 | USES1 },      /* shll16 rn */
1810
  { 0x4029, SETS1 | USES1 },      /* shlr16 rn */
1811
  { 0x402a, SETSSP | USES1 },     /* lds rm,pr */
1812
  { 0x402b, BRANCH | DELAY | USES1 },   /* jmp @rn */
1813
  { 0x4052, STORE | SETS1 | USES1 | USESSP }, /* sts.l fpul,@-rn */
1814
  { 0x4056, LOAD | SETS1 | SETSSP | USES1 },  /* lds.l @rm+,fpul */
1815
  { 0x405a, SETSSP | USES1 },     /* lds.l rm,fpul */
1816
  { 0x4062, STORE | SETS1 | USES1 | USESSP }, /* sts.l fpscr / dsr,@-rn */
1817
  { 0x4066, LOAD | SETS1 | SETSSP | USES1 },  /* lds.l @rm+,fpscr / dsr */
1818
  { 0x406a, SETSSP | USES1 },     /* lds rm,fpscr / lds rm,dsr */
1819
  { 0x4072, STORE | SETS1 | USES1 | USESSP }, /* sts.l a0,@-rn */
1820
  { 0x4076, LOAD | SETS1 | SETSSP | USES1 },  /* lds.l @rm+,a0 */
1821
  { 0x407a, SETSSP | USES1 },     /* lds.l rm,a0 */
1822
  { 0x4082, STORE | SETS1 | USES1 | USESSP }, /* sts.l x0,@-rn */
1823
  { 0x4086, LOAD | SETS1 | SETSSP | USES1 },  /* lds.l @rm+,x0 */
1824
  { 0x408a, SETSSP | USES1 },     /* lds.l rm,x0 */
1825
  { 0x4092, STORE | SETS1 | USES1 | USESSP }, /* sts.l x1,@-rn */
1826
  { 0x4096, LOAD | SETS1 | SETSSP | USES1 },  /* lds.l @rm+,x1 */
1827
  { 0x409a, SETSSP | USES1 },     /* lds.l rm,x1 */
1828
  { 0x40a2, STORE | SETS1 | USES1 | USESSP }, /* sts.l y0,@-rn */
1829
  { 0x40a6, LOAD | SETS1 | SETSSP | USES1 },  /* lds.l @rm+,y0 */
1830
  { 0x40aa, SETSSP | USES1 },     /* lds.l rm,y0 */
1831
  { 0x40b2, STORE | SETS1 | USES1 | USESSP }, /* sts.l y1,@-rn */
1832
  { 0x40b6, LOAD | SETS1 | SETSSP | USES1 },  /* lds.l @rm+,y1 */
1833
  { 0x40ba, SETSSP | USES1 }      /* lds.l rm,y1 */
1834
};
1835
1836
static const struct sh_opcode sh_opcode41[] =
1837
{
1838
  { 0x4003, STORE | SETS1 | USES1 | USESSP }, /* stc.l <special_reg>,@-rn */
1839
  { 0x4007, LOAD | SETS1 | SETSSP | USES1 },  /* ldc.l @rm+,<special_reg> */
1840
  { 0x400c, SETS1 | USES1 | USES2 },    /* shad rm,rn */
1841
  { 0x400d, SETS1 | USES1 | USES2 },    /* shld rm,rn */
1842
  { 0x400e, SETSSP | USES1 },     /* ldc rm,<special_reg> */
1843
  { 0x400f, LOAD|SETS1|SETS2|SETSSP|USES1|USES2|USESSP }, /* mac.w @rm+,@rn+ */
1844
};
1845
1846
static const struct sh_minor_opcode sh_opcode4[] =
1847
{
1848
  { MAP (sh_opcode40), 0xf0ff },
1849
  { MAP (sh_opcode41), 0xf00f }
1850
};
1851
1852
static const struct sh_opcode sh_opcode50[] =
1853
{
1854
  { 0x5000, LOAD | SETS1 | USES2 }  /* mov.l @(disp,rm),rn */
1855
};
1856
1857
static const struct sh_minor_opcode sh_opcode5[] =
1858
{
1859
  { MAP (sh_opcode50), 0xf000 }
1860
};
1861
1862
static const struct sh_opcode sh_opcode60[] =
1863
{
1864
  { 0x6000, LOAD | SETS1 | USES2 },   /* mov.b @rm,rn */
1865
  { 0x6001, LOAD | SETS1 | USES2 },   /* mov.w @rm,rn */
1866
  { 0x6002, LOAD | SETS1 | USES2 },   /* mov.l @rm,rn */
1867
  { 0x6003, SETS1 | USES2 },      /* mov rm,rn */
1868
  { 0x6004, LOAD | SETS1 | SETS2 | USES2 }, /* mov.b @rm+,rn */
1869
  { 0x6005, LOAD | SETS1 | SETS2 | USES2 }, /* mov.w @rm+,rn */
1870
  { 0x6006, LOAD | SETS1 | SETS2 | USES2 }, /* mov.l @rm+,rn */
1871
  { 0x6007, SETS1 | USES2 },      /* not rm,rn */
1872
  { 0x6008, SETS1 | USES2 },      /* swap.b rm,rn */
1873
  { 0x6009, SETS1 | USES2 },      /* swap.w rm,rn */
1874
  { 0x600a, SETS1 | SETSSP | USES2 | USESSP },  /* negc rm,rn */
1875
  { 0x600b, SETS1 | USES2 },      /* neg rm,rn */
1876
  { 0x600c, SETS1 | USES2 },      /* extu.b rm,rn */
1877
  { 0x600d, SETS1 | USES2 },      /* extu.w rm,rn */
1878
  { 0x600e, SETS1 | USES2 },      /* exts.b rm,rn */
1879
  { 0x600f, SETS1 | USES2 }     /* exts.w rm,rn */
1880
};
1881
1882
static const struct sh_minor_opcode sh_opcode6[] =
1883
{
1884
  { MAP (sh_opcode60), 0xf00f }
1885
};
1886
1887
static const struct sh_opcode sh_opcode70[] =
1888
{
1889
  { 0x7000, SETS1 | USES1 }   /* add #imm,rn */
1890
};
1891
1892
static const struct sh_minor_opcode sh_opcode7[] =
1893
{
1894
  { MAP (sh_opcode70), 0xf000 }
1895
};
1896
1897
static const struct sh_opcode sh_opcode80[] =
1898
{
1899
  { 0x8000, STORE | USES2 | USESR0 }, /* mov.b r0,@(disp,rn) */
1900
  { 0x8100, STORE | USES2 | USESR0 }, /* mov.w r0,@(disp,rn) */
1901
  { 0x8200, SETSSP },     /* setrc #imm */
1902
  { 0x8400, LOAD | SETSR0 | USES2 },  /* mov.b @(disp,rm),r0 */
1903
  { 0x8500, LOAD | SETSR0 | USES2 },  /* mov.w @(disp,rn),r0 */
1904
  { 0x8800, SETSSP | USESR0 },    /* cmp/eq #imm,r0 */
1905
  { 0x8900, BRANCH | USESSP },    /* bt label */
1906
  { 0x8b00, BRANCH | USESSP },    /* bf label */
1907
  { 0x8c00, SETSSP },     /* ldrs @(disp,pc) */
1908
  { 0x8d00, BRANCH | DELAY | USESSP },  /* bt/s label */
1909
  { 0x8e00, SETSSP },     /* ldre @(disp,pc) */
1910
  { 0x8f00, BRANCH | DELAY | USESSP } /* bf/s label */
1911
};
1912
1913
static const struct sh_minor_opcode sh_opcode8[] =
1914
{
1915
  { MAP (sh_opcode80), 0xff00 }
1916
};
1917
1918
static const struct sh_opcode sh_opcode90[] =
1919
{
1920
  { 0x9000, LOAD | SETS1 }  /* mov.w @(disp,pc),rn */
1921
};
1922
1923
static const struct sh_minor_opcode sh_opcode9[] =
1924
{
1925
  { MAP (sh_opcode90), 0xf000 }
1926
};
1927
1928
static const struct sh_opcode sh_opcodea0[] =
1929
{
1930
  { 0xa000, BRANCH | DELAY }  /* bra label */
1931
};
1932
1933
static const struct sh_minor_opcode sh_opcodea[] =
1934
{
1935
  { MAP (sh_opcodea0), 0xf000 }
1936
};
1937
1938
static const struct sh_opcode sh_opcodeb0[] =
1939
{
1940
  { 0xb000, BRANCH | DELAY }  /* bsr label */
1941
};
1942
1943
static const struct sh_minor_opcode sh_opcodeb[] =
1944
{
1945
  { MAP (sh_opcodeb0), 0xf000 }
1946
};
1947
1948
static const struct sh_opcode sh_opcodec0[] =
1949
{
1950
  { 0xc000, STORE | USESR0 | USESSP },    /* mov.b r0,@(disp,gbr) */
1951
  { 0xc100, STORE | USESR0 | USESSP },    /* mov.w r0,@(disp,gbr) */
1952
  { 0xc200, STORE | USESR0 | USESSP },    /* mov.l r0,@(disp,gbr) */
1953
  { 0xc300, BRANCH | USESSP },      /* trapa #imm */
1954
  { 0xc400, LOAD | SETSR0 | USESSP },   /* mov.b @(disp,gbr),r0 */
1955
  { 0xc500, LOAD | SETSR0 | USESSP },   /* mov.w @(disp,gbr),r0 */
1956
  { 0xc600, LOAD | SETSR0 | USESSP },   /* mov.l @(disp,gbr),r0 */
1957
  { 0xc700, SETSR0 },       /* mova @(disp,pc),r0 */
1958
  { 0xc800, SETSSP | USESR0 },      /* tst #imm,r0 */
1959
  { 0xc900, SETSR0 | USESR0 },      /* and #imm,r0 */
1960
  { 0xca00, SETSR0 | USESR0 },      /* xor #imm,r0 */
1961
  { 0xcb00, SETSR0 | USESR0 },      /* or #imm,r0 */
1962
  { 0xcc00, LOAD | SETSSP | USESR0 | USESSP },  /* tst.b #imm,@(r0,gbr) */
1963
  { 0xcd00, LOAD | STORE | USESR0 | USESSP }, /* and.b #imm,@(r0,gbr) */
1964
  { 0xce00, LOAD | STORE | USESR0 | USESSP }, /* xor.b #imm,@(r0,gbr) */
1965
  { 0xcf00, LOAD | STORE | USESR0 | USESSP }  /* or.b #imm,@(r0,gbr) */
1966
};
1967
1968
static const struct sh_minor_opcode sh_opcodec[] =
1969
{
1970
  { MAP (sh_opcodec0), 0xff00 }
1971
};
1972
1973
static const struct sh_opcode sh_opcoded0[] =
1974
{
1975
  { 0xd000, LOAD | SETS1 }    /* mov.l @(disp,pc),rn */
1976
};
1977
1978
static const struct sh_minor_opcode sh_opcoded[] =
1979
{
1980
  { MAP (sh_opcoded0), 0xf000 }
1981
};
1982
1983
static const struct sh_opcode sh_opcodee0[] =
1984
{
1985
  { 0xe000, SETS1 }   /* mov #imm,rn */
1986
};
1987
1988
static const struct sh_minor_opcode sh_opcodee[] =
1989
{
1990
  { MAP (sh_opcodee0), 0xf000 }
1991
};
1992
1993
static const struct sh_opcode sh_opcodef0[] =
1994
{
1995
  { 0xf000, SETSF1 | USESF1 | USESF2 },   /* fadd fm,fn */
1996
  { 0xf001, SETSF1 | USESF1 | USESF2 },   /* fsub fm,fn */
1997
  { 0xf002, SETSF1 | USESF1 | USESF2 },   /* fmul fm,fn */
1998
  { 0xf003, SETSF1 | USESF1 | USESF2 },   /* fdiv fm,fn */
1999
  { 0xf004, SETSSP | USESF1 | USESF2 },   /* fcmp/eq fm,fn */
2000
  { 0xf005, SETSSP | USESF1 | USESF2 },   /* fcmp/gt fm,fn */
2001
  { 0xf006, LOAD | SETSF1 | USES2 | USESR0 }, /* fmov.s @(r0,rm),fn */
2002
  { 0xf007, STORE | USES1 | USESF2 | USESR0 },  /* fmov.s fm,@(r0,rn) */
2003
  { 0xf008, LOAD | SETSF1 | USES2 },    /* fmov.s @rm,fn */
2004
  { 0xf009, LOAD | SETS2 | SETSF1 | USES2 },  /* fmov.s @rm+,fn */
2005
  { 0xf00a, STORE | USES1 | USESF2 },   /* fmov.s fm,@rn */
2006
  { 0xf00b, STORE | SETS1 | USES1 | USESF2 }, /* fmov.s fm,@-rn */
2007
  { 0xf00c, SETSF1 | USESF2 },      /* fmov fm,fn */
2008
  { 0xf00e, SETSF1 | USESF1 | USESF2 | USESF0 } /* fmac f0,fm,fn */
2009
};
2010
2011
static const struct sh_opcode sh_opcodef1[] =
2012
{
2013
  { 0xf00d, SETSF1 | USESSP },  /* fsts fpul,fn */
2014
  { 0xf01d, SETSSP | USESF1 },  /* flds fn,fpul */
2015
  { 0xf02d, SETSF1 | USESSP },  /* float fpul,fn */
2016
  { 0xf03d, SETSSP | USESF1 },  /* ftrc fn,fpul */
2017
  { 0xf04d, SETSF1 | USESF1 },  /* fneg fn */
2018
  { 0xf05d, SETSF1 | USESF1 },  /* fabs fn */
2019
  { 0xf06d, SETSF1 | USESF1 },  /* fsqrt fn */
2020
  { 0xf07d, SETSSP | USESF1 },  /* ftst/nan fn */
2021
  { 0xf08d, SETSF1 },   /* fldi0 fn */
2022
  { 0xf09d, SETSF1 }    /* fldi1 fn */
2023
};
2024
2025
static const struct sh_minor_opcode sh_opcodef[] =
2026
{
2027
  { MAP (sh_opcodef0), 0xf00f },
2028
  { MAP (sh_opcodef1), 0xf0ff }
2029
};
2030
2031
static struct sh_major_opcode sh_opcodes[] =
2032
{
2033
  { MAP (sh_opcode0) },
2034
  { MAP (sh_opcode1) },
2035
  { MAP (sh_opcode2) },
2036
  { MAP (sh_opcode3) },
2037
  { MAP (sh_opcode4) },
2038
  { MAP (sh_opcode5) },
2039
  { MAP (sh_opcode6) },
2040
  { MAP (sh_opcode7) },
2041
  { MAP (sh_opcode8) },
2042
  { MAP (sh_opcode9) },
2043
  { MAP (sh_opcodea) },
2044
  { MAP (sh_opcodeb) },
2045
  { MAP (sh_opcodec) },
2046
  { MAP (sh_opcoded) },
2047
  { MAP (sh_opcodee) },
2048
  { MAP (sh_opcodef) }
2049
};
2050
2051
/* The double data transfer / parallel processing insns are not
2052
   described here.  This will cause sh_align_load_span to leave them alone.  */
2053
2054
static const struct sh_opcode sh_dsp_opcodef0[] =
2055
{
2056
  { 0xf400, USESAS | SETSAS | LOAD | SETSSP },  /* movs.x @-as,ds */
2057
  { 0xf401, USESAS | SETSAS | STORE | USESSP }, /* movs.x ds,@-as */
2058
  { 0xf404, USESAS | LOAD | SETSSP },   /* movs.x @as,ds */
2059
  { 0xf405, USESAS | STORE | USESSP },    /* movs.x ds,@as */
2060
  { 0xf408, USESAS | SETSAS | LOAD | SETSSP },  /* movs.x @as+,ds */
2061
  { 0xf409, USESAS | SETSAS | STORE | USESSP }, /* movs.x ds,@as+ */
2062
  { 0xf40c, USESAS | SETSAS | LOAD | SETSSP | USESR8 }, /* movs.x @as+r8,ds */
2063
  { 0xf40d, USESAS | SETSAS | STORE | USESSP | USESR8 } /* movs.x ds,@as+r8 */
2064
};
2065
2066
static const struct sh_minor_opcode sh_dsp_opcodef[] =
2067
{
2068
  { MAP (sh_dsp_opcodef0), 0xfc0d }
2069
};
2070
2071
/* Given an instruction, return a pointer to the corresponding
2072
   sh_opcode structure.  Return NULL if the instruction is not
2073
   recognized.  */
2074
2075
static const struct sh_opcode *
2076
sh_insn_info (unsigned int insn)
2077
0
{
2078
0
  const struct sh_major_opcode *maj;
2079
0
  const struct sh_minor_opcode *min, *minend;
2080
2081
0
  maj = &sh_opcodes[(insn & 0xf000) >> 12];
2082
0
  min = maj->minor_opcodes;
2083
0
  minend = min + maj->count;
2084
0
  for (; min < minend; min++)
2085
0
    {
2086
0
      unsigned int l;
2087
0
      const struct sh_opcode *op, *opend;
2088
2089
0
      l = insn & min->mask;
2090
0
      op = min->opcodes;
2091
0
      opend = op + min->count;
2092
2093
      /* Since the opcodes tables are sorted, we could use a binary
2094
   search here if the count were above some cutoff value.  */
2095
0
      for (; op < opend; op++)
2096
0
  if (op->opcode == l)
2097
0
    return op;
2098
0
    }
2099
2100
0
  return NULL;
2101
0
}
Unexecuted instantiation: coff-sh.c:sh_insn_info
Unexecuted instantiation: pe-sh.c:sh_insn_info
2102
2103
/* See whether an instruction uses a general purpose register.  */
2104
2105
static bool
2106
sh_insn_uses_reg (unsigned int insn,
2107
      const struct sh_opcode *op,
2108
      unsigned int reg)
2109
0
{
2110
0
  unsigned int f;
2111
2112
0
  f = op->flags;
2113
2114
0
  if ((f & USES1) != 0
2115
0
      && USES1_REG (insn) == reg)
2116
0
    return true;
2117
0
  if ((f & USES2) != 0
2118
0
      && USES2_REG (insn) == reg)
2119
0
    return true;
2120
0
  if ((f & USESR0) != 0
2121
0
      && reg == 0)
2122
0
    return true;
2123
0
  if ((f & USESAS) && reg == USESAS_REG (insn))
2124
0
    return true;
2125
0
  if ((f & USESR8) && reg == 8)
2126
0
    return true;
2127
2128
0
  return false;
2129
0
}
Unexecuted instantiation: coff-sh.c:sh_insn_uses_reg
Unexecuted instantiation: pe-sh.c:sh_insn_uses_reg
2130
2131
/* See whether an instruction sets a general purpose register.  */
2132
2133
static bool
2134
sh_insn_sets_reg (unsigned int insn,
2135
      const struct sh_opcode *op,
2136
      unsigned int reg)
2137
0
{
2138
0
  unsigned int f;
2139
2140
0
  f = op->flags;
2141
2142
0
  if ((f & SETS1) != 0
2143
0
      && SETS1_REG (insn) == reg)
2144
0
    return true;
2145
0
  if ((f & SETS2) != 0
2146
0
      && SETS2_REG (insn) == reg)
2147
0
    return true;
2148
0
  if ((f & SETSR0) != 0
2149
0
      && reg == 0)
2150
0
    return true;
2151
0
  if ((f & SETSAS) && reg == SETSAS_REG (insn))
2152
0
    return true;
2153
2154
0
  return false;
2155
0
}
Unexecuted instantiation: coff-sh.c:sh_insn_sets_reg
Unexecuted instantiation: pe-sh.c:sh_insn_sets_reg
2156
2157
/* See whether an instruction uses or sets a general purpose register */
2158
2159
static bool
2160
sh_insn_uses_or_sets_reg (unsigned int insn,
2161
        const struct sh_opcode *op,
2162
        unsigned int reg)
2163
0
{
2164
0
  if (sh_insn_uses_reg (insn, op, reg))
2165
0
    return true;
2166
2167
0
  return sh_insn_sets_reg (insn, op, reg);
2168
0
}
Unexecuted instantiation: coff-sh.c:sh_insn_uses_or_sets_reg
Unexecuted instantiation: pe-sh.c:sh_insn_uses_or_sets_reg
2169
2170
/* See whether an instruction uses a floating point register.  */
2171
2172
static bool
2173
sh_insn_uses_freg (unsigned int insn,
2174
       const struct sh_opcode *op,
2175
       unsigned int freg)
2176
0
{
2177
0
  unsigned int f;
2178
2179
0
  f = op->flags;
2180
2181
  /* We can't tell if this is a double-precision insn, so just play safe
2182
     and assume that it might be.  So not only have we test FREG against
2183
     itself, but also even FREG against FREG+1 - if the using insn uses
2184
     just the low part of a double precision value - but also an odd
2185
     FREG against FREG-1 -  if the setting insn sets just the low part
2186
     of a double precision value.
2187
     So what this all boils down to is that we have to ignore the lowest
2188
     bit of the register number.  */
2189
2190
0
  if ((f & USESF1) != 0
2191
0
      && (USESF1_REG (insn) & 0xe) == (freg & 0xe))
2192
0
    return true;
2193
0
  if ((f & USESF2) != 0
2194
0
      && (USESF2_REG (insn) & 0xe) == (freg & 0xe))
2195
0
    return true;
2196
0
  if ((f & USESF0) != 0
2197
0
      && freg == 0)
2198
0
    return true;
2199
2200
0
  return false;
2201
0
}
Unexecuted instantiation: coff-sh.c:sh_insn_uses_freg
Unexecuted instantiation: pe-sh.c:sh_insn_uses_freg
2202
2203
/* See whether an instruction sets a floating point register.  */
2204
2205
static bool
2206
sh_insn_sets_freg (unsigned int insn,
2207
       const struct sh_opcode *op,
2208
       unsigned int freg)
2209
0
{
2210
0
  unsigned int f;
2211
2212
0
  f = op->flags;
2213
2214
  /* We can't tell if this is a double-precision insn, so just play safe
2215
     and assume that it might be.  So not only have we test FREG against
2216
     itself, but also even FREG against FREG+1 - if the using insn uses
2217
     just the low part of a double precision value - but also an odd
2218
     FREG against FREG-1 -  if the setting insn sets just the low part
2219
     of a double precision value.
2220
     So what this all boils down to is that we have to ignore the lowest
2221
     bit of the register number.  */
2222
2223
0
  if ((f & SETSF1) != 0
2224
0
      && (SETSF1_REG (insn) & 0xe) == (freg & 0xe))
2225
0
    return true;
2226
2227
0
  return false;
2228
0
}
Unexecuted instantiation: coff-sh.c:sh_insn_sets_freg
Unexecuted instantiation: pe-sh.c:sh_insn_sets_freg
2229
2230
/* See whether an instruction uses or sets a floating point register */
2231
2232
static bool
2233
sh_insn_uses_or_sets_freg (unsigned int insn,
2234
         const struct sh_opcode *op,
2235
         unsigned int reg)
2236
0
{
2237
0
  if (sh_insn_uses_freg (insn, op, reg))
2238
0
    return true;
2239
2240
0
  return sh_insn_sets_freg (insn, op, reg);
2241
0
}
Unexecuted instantiation: coff-sh.c:sh_insn_uses_or_sets_freg
Unexecuted instantiation: pe-sh.c:sh_insn_uses_or_sets_freg
2242
2243
/* See whether instructions I1 and I2 conflict, assuming I1 comes
2244
   before I2.  OP1 and OP2 are the corresponding sh_opcode structures.
2245
   This should return TRUE if there is a conflict, or FALSE if the
2246
   instructions can be swapped safely.  */
2247
2248
static bool
2249
sh_insns_conflict (unsigned int i1,
2250
       const struct sh_opcode *op1,
2251
       unsigned int i2,
2252
       const struct sh_opcode *op2)
2253
0
{
2254
0
  unsigned int f1, f2;
2255
2256
0
  f1 = op1->flags;
2257
0
  f2 = op2->flags;
2258
2259
  /* Load of fpscr conflicts with floating point operations.
2260
     FIXME: shouldn't test raw opcodes here.  */
2261
0
  if (((i1 & 0xf0ff) == 0x4066 && (i2 & 0xf000) == 0xf000)
2262
0
      || ((i2 & 0xf0ff) == 0x4066 && (i1 & 0xf000) == 0xf000))
2263
0
    return true;
2264
2265
0
  if ((f1 & (BRANCH | DELAY)) != 0
2266
0
      || (f2 & (BRANCH | DELAY)) != 0)
2267
0
    return true;
2268
2269
0
  if (((f1 | f2) & SETSSP)
2270
0
      && (f1 & (SETSSP | USESSP))
2271
0
      && (f2 & (SETSSP | USESSP)))
2272
0
    return true;
2273
2274
0
  if ((f1 & SETS1) != 0
2275
0
      && sh_insn_uses_or_sets_reg (i2, op2, SETS1_REG (i1)))
2276
0
    return true;
2277
0
  if ((f1 & SETS2) != 0
2278
0
      && sh_insn_uses_or_sets_reg (i2, op2, SETS2_REG (i1)))
2279
0
    return true;
2280
0
  if ((f1 & SETSR0) != 0
2281
0
      && sh_insn_uses_or_sets_reg (i2, op2, 0))
2282
0
    return true;
2283
0
  if ((f1 & SETSAS)
2284
0
      && sh_insn_uses_or_sets_reg (i2, op2, SETSAS_REG (i1)))
2285
0
    return true;
2286
0
  if ((f1 & SETSF1) != 0
2287
0
      && sh_insn_uses_or_sets_freg (i2, op2, SETSF1_REG (i1)))
2288
0
    return true;
2289
2290
0
  if ((f2 & SETS1) != 0
2291
0
      && sh_insn_uses_or_sets_reg (i1, op1, SETS1_REG (i2)))
2292
0
    return true;
2293
0
  if ((f2 & SETS2) != 0
2294
0
      && sh_insn_uses_or_sets_reg (i1, op1, SETS2_REG (i2)))
2295
0
    return true;
2296
0
  if ((f2 & SETSR0) != 0
2297
0
      && sh_insn_uses_or_sets_reg (i1, op1, 0))
2298
0
    return true;
2299
0
  if ((f2 & SETSAS)
2300
0
      && sh_insn_uses_or_sets_reg (i1, op1, SETSAS_REG (i2)))
2301
0
    return true;
2302
0
  if ((f2 & SETSF1) != 0
2303
0
      && sh_insn_uses_or_sets_freg (i1, op1, SETSF1_REG (i2)))
2304
0
    return true;
2305
2306
  /* The instructions do not conflict.  */
2307
0
  return false;
2308
0
}
Unexecuted instantiation: coff-sh.c:sh_insns_conflict
Unexecuted instantiation: pe-sh.c:sh_insns_conflict
2309
2310
/* I1 is a load instruction, and I2 is some other instruction.  Return
2311
   TRUE if I1 loads a register which I2 uses.  */
2312
2313
static bool
2314
sh_load_use (unsigned int i1,
2315
       const struct sh_opcode *op1,
2316
       unsigned int i2,
2317
       const struct sh_opcode *op2)
2318
0
{
2319
0
  unsigned int f1;
2320
2321
0
  f1 = op1->flags;
2322
2323
0
  if ((f1 & LOAD) == 0)
2324
0
    return false;
2325
2326
  /* If both SETS1 and SETSSP are set, that means a load to a special
2327
     register using postincrement addressing mode, which we don't care
2328
     about here.  */
2329
0
  if ((f1 & SETS1) != 0
2330
0
      && (f1 & SETSSP) == 0
2331
0
      && sh_insn_uses_reg (i2, op2, (i1 & 0x0f00) >> 8))
2332
0
    return true;
2333
2334
0
  if ((f1 & SETSR0) != 0
2335
0
      && sh_insn_uses_reg (i2, op2, 0))
2336
0
    return true;
2337
2338
0
  if ((f1 & SETSF1) != 0
2339
0
      && sh_insn_uses_freg (i2, op2, (i1 & 0x0f00) >> 8))
2340
0
    return true;
2341
2342
0
  return false;
2343
0
}
Unexecuted instantiation: coff-sh.c:sh_load_use
Unexecuted instantiation: pe-sh.c:sh_load_use
2344
2345
/* Try to align loads and stores within a span of memory.  This is
2346
   called by both the ELF and the COFF sh targets.  ABFD and SEC are
2347
   the BFD and section we are examining.  CONTENTS is the contents of
2348
   the section.  SWAP is the routine to call to swap two instructions.
2349
   RELOCS is a pointer to the internal relocation information, to be
2350
   passed to SWAP.  PLABEL is a pointer to the current label in a
2351
   sorted list of labels; LABEL_END is the end of the list.  START and
2352
   STOP are the range of memory to examine.  If a swap is made,
2353
   *PSWAPPED is set to TRUE.  */
2354
2355
#ifdef COFF_WITH_PE
2356
static
2357
#endif
2358
bool
2359
_bfd_sh_align_load_span (bfd *abfd,
2360
       asection *sec,
2361
       bfd_byte *contents,
2362
       bool (*swap) (bfd *, asection *, void *, bfd_byte *, bfd_vma),
2363
       void * relocs,
2364
       bfd_vma **plabel,
2365
       bfd_vma *label_end,
2366
       bfd_vma start,
2367
       bfd_vma stop,
2368
       bool *pswapped)
2369
0
{
2370
0
  int dsp = (abfd->arch_info->mach == bfd_mach_sh_dsp
2371
0
       || abfd->arch_info->mach == bfd_mach_sh3_dsp);
2372
0
  bfd_vma i;
2373
2374
  /* The SH4 has a Harvard architecture, hence aligning loads is not
2375
     desirable.  In fact, it is counter-productive, since it interferes
2376
     with the schedules generated by the compiler.  */
2377
0
  if (abfd->arch_info->mach == bfd_mach_sh4)
2378
0
    return true;
2379
2380
  /* If we are linking sh[3]-dsp code, swap the FPU instructions for DSP
2381
     instructions.  */
2382
0
  if (dsp)
2383
0
    {
2384
0
      sh_opcodes[0xf].minor_opcodes = sh_dsp_opcodef;
2385
0
      sh_opcodes[0xf].count = sizeof sh_dsp_opcodef / sizeof sh_dsp_opcodef [0];
2386
0
    }
2387
2388
  /* Instructions should be aligned on 2 byte boundaries.  */
2389
0
  if ((start & 1) == 1)
2390
0
    ++start;
2391
2392
  /* Now look through the unaligned addresses.  */
2393
0
  i = start;
2394
0
  if ((i & 2) == 0)
2395
0
    i += 2;
2396
0
  for (; i < stop; i += 4)
2397
0
    {
2398
0
      unsigned int insn;
2399
0
      const struct sh_opcode *op;
2400
0
      unsigned int prev_insn = 0;
2401
0
      const struct sh_opcode *prev_op = NULL;
2402
2403
0
      insn = bfd_get_16 (abfd, contents + i);
2404
0
      op = sh_insn_info (insn);
2405
0
      if (op == NULL
2406
0
    || (op->flags & (LOAD | STORE)) == 0)
2407
0
  continue;
2408
2409
      /* This is a load or store which is not on a four byte boundary.  */
2410
2411
0
      while (*plabel < label_end && **plabel < i)
2412
0
  ++*plabel;
2413
2414
0
      if (i > start)
2415
0
  {
2416
0
    prev_insn = bfd_get_16 (abfd, contents + i - 2);
2417
    /* If INSN is the field b of a parallel processing insn, it is not
2418
       a load / store after all.  Note that the test here might mistake
2419
       the field_b of a pcopy insn for the starting code of a parallel
2420
       processing insn; this might miss a swapping opportunity, but at
2421
       least we're on the safe side.  */
2422
0
    if (dsp && (prev_insn & 0xfc00) == 0xf800)
2423
0
      continue;
2424
2425
    /* Check if prev_insn is actually the field b of a parallel
2426
       processing insn.  Again, this can give a spurious match
2427
       after a pcopy.  */
2428
0
    if (dsp && i - 2 > start)
2429
0
      {
2430
0
        unsigned pprev_insn = bfd_get_16 (abfd, contents + i - 4);
2431
2432
0
        if ((pprev_insn & 0xfc00) == 0xf800)
2433
0
    prev_op = NULL;
2434
0
        else
2435
0
    prev_op = sh_insn_info (prev_insn);
2436
0
      }
2437
0
    else
2438
0
      prev_op = sh_insn_info (prev_insn);
2439
2440
    /* If the load/store instruction is in a delay slot, we
2441
       can't swap.  */
2442
0
    if (prev_op == NULL
2443
0
        || (prev_op->flags & DELAY) != 0)
2444
0
      continue;
2445
0
  }
2446
0
      if (i > start
2447
0
    && (*plabel >= label_end || **plabel != i)
2448
0
    && prev_op != NULL
2449
0
    && (prev_op->flags & (LOAD | STORE)) == 0
2450
0
    && ! sh_insns_conflict (prev_insn, prev_op, insn, op))
2451
0
  {
2452
0
    bool ok;
2453
2454
    /* The load/store instruction does not have a label, and
2455
       there is a previous instruction; PREV_INSN is not
2456
       itself a load/store instruction, and PREV_INSN and
2457
       INSN do not conflict.  */
2458
2459
0
    ok = true;
2460
2461
0
    if (i >= start + 4)
2462
0
      {
2463
0
        unsigned int prev2_insn;
2464
0
        const struct sh_opcode *prev2_op;
2465
2466
0
        prev2_insn = bfd_get_16 (abfd, contents + i - 4);
2467
0
        prev2_op = sh_insn_info (prev2_insn);
2468
2469
        /* If the instruction before PREV_INSN has a delay
2470
     slot--that is, PREV_INSN is in a delay slot--we
2471
     can not swap.  */
2472
0
        if (prev2_op == NULL
2473
0
      || (prev2_op->flags & DELAY) != 0)
2474
0
    ok = false;
2475
2476
        /* If the instruction before PREV_INSN is a load,
2477
     and it sets a register which INSN uses, then
2478
     putting INSN immediately after PREV_INSN will
2479
     cause a pipeline bubble, so there is no point to
2480
     making the swap.  */
2481
0
        if (ok
2482
0
      && (prev2_op->flags & LOAD) != 0
2483
0
      && sh_load_use (prev2_insn, prev2_op, insn, op))
2484
0
    ok = false;
2485
0
      }
2486
2487
0
    if (ok)
2488
0
      {
2489
0
        if (! (*swap) (abfd, sec, relocs, contents, i - 2))
2490
0
    return false;
2491
0
        *pswapped = true;
2492
0
        continue;
2493
0
      }
2494
0
  }
2495
2496
0
      while (*plabel < label_end && **plabel < i + 2)
2497
0
  ++*plabel;
2498
2499
0
      if (i + 2 < stop
2500
0
    && (*plabel >= label_end || **plabel != i + 2))
2501
0
  {
2502
0
    unsigned int next_insn;
2503
0
    const struct sh_opcode *next_op;
2504
2505
    /* There is an instruction after the load/store
2506
       instruction, and it does not have a label.  */
2507
0
    next_insn = bfd_get_16 (abfd, contents + i + 2);
2508
0
    next_op = sh_insn_info (next_insn);
2509
0
    if (next_op != NULL
2510
0
        && (next_op->flags & (LOAD | STORE)) == 0
2511
0
        && ! sh_insns_conflict (insn, op, next_insn, next_op))
2512
0
      {
2513
0
        bool ok;
2514
2515
        /* NEXT_INSN is not itself a load/store instruction,
2516
     and it does not conflict with INSN.  */
2517
2518
0
        ok = true;
2519
2520
        /* If PREV_INSN is a load, and it sets a register
2521
     which NEXT_INSN uses, then putting NEXT_INSN
2522
     immediately after PREV_INSN will cause a pipeline
2523
     bubble, so there is no reason to make this swap.  */
2524
0
        if (prev_op != NULL
2525
0
      && (prev_op->flags & LOAD) != 0
2526
0
      && sh_load_use (prev_insn, prev_op, next_insn, next_op))
2527
0
    ok = false;
2528
2529
        /* If INSN is a load, and it sets a register which
2530
     the insn after NEXT_INSN uses, then doing the
2531
     swap will cause a pipeline bubble, so there is no
2532
     reason to make the swap.  However, if the insn
2533
     after NEXT_INSN is itself a load or store
2534
     instruction, then it is misaligned, so
2535
     optimistically hope that it will be swapped
2536
     itself, and just live with the pipeline bubble if
2537
     it isn't.  */
2538
0
        if (ok
2539
0
      && i + 4 < stop
2540
0
      && (op->flags & LOAD) != 0)
2541
0
    {
2542
0
      unsigned int next2_insn;
2543
0
      const struct sh_opcode *next2_op;
2544
2545
0
      next2_insn = bfd_get_16 (abfd, contents + i + 4);
2546
0
      next2_op = sh_insn_info (next2_insn);
2547
0
      if (next2_op == NULL
2548
0
          || ((next2_op->flags & (LOAD | STORE)) == 0
2549
0
        && sh_load_use (insn, op, next2_insn, next2_op)))
2550
0
        ok = false;
2551
0
    }
2552
2553
0
        if (ok)
2554
0
    {
2555
0
      if (! (*swap) (abfd, sec, relocs, contents, i))
2556
0
        return false;
2557
0
      *pswapped = true;
2558
0
      continue;
2559
0
    }
2560
0
      }
2561
0
  }
2562
0
    }
2563
2564
0
  return true;
2565
0
}
Unexecuted instantiation: _bfd_sh_align_load_span
Unexecuted instantiation: pe-sh.c:sh_align_load_span
2566
#endif /* not COFF_IMAGE_WITH_PE */
2567
2568
/* Swap two SH instructions.  */
2569
2570
static bool
2571
sh_swap_insns (bfd *      abfd,
2572
         asection * sec,
2573
         void *     relocs,
2574
         bfd_byte * contents,
2575
         bfd_vma    addr)
2576
0
{
2577
0
  struct internal_reloc *internal_relocs = (struct internal_reloc *) relocs;
2578
0
  unsigned short i1, i2;
2579
0
  struct internal_reloc *irel, *irelend;
2580
2581
  /* Swap the instructions themselves.  */
2582
0
  i1 = bfd_get_16 (abfd, contents + addr);
2583
0
  i2 = bfd_get_16 (abfd, contents + addr + 2);
2584
0
  bfd_put_16 (abfd, (bfd_vma) i2, contents + addr);
2585
0
  bfd_put_16 (abfd, (bfd_vma) i1, contents + addr + 2);
2586
2587
  /* Adjust all reloc addresses.  */
2588
0
  irelend = internal_relocs + sec->reloc_count;
2589
0
  for (irel = internal_relocs; irel < irelend; irel++)
2590
0
    {
2591
0
      int type, add;
2592
2593
      /* There are a few special types of relocs that we don't want to
2594
   adjust.  These relocs do not apply to the instruction itself,
2595
   but are only associated with the address.  */
2596
0
      type = irel->r_type;
2597
0
      if (type == R_SH_ALIGN
2598
0
    || type == R_SH_CODE
2599
0
    || type == R_SH_DATA
2600
0
    || type == R_SH_LABEL)
2601
0
  continue;
2602
2603
      /* If an R_SH_USES reloc points to one of the addresses being
2604
   swapped, we must adjust it.  It would be incorrect to do this
2605
   for a jump, though, since we want to execute both
2606
   instructions after the jump.  (We have avoided swapping
2607
   around a label, so the jump will not wind up executing an
2608
   instruction it shouldn't).  */
2609
0
      if (type == R_SH_USES)
2610
0
  {
2611
0
    bfd_vma off;
2612
2613
0
    off = irel->r_vaddr - sec->vma + 4 + irel->r_offset;
2614
0
    if (off == addr)
2615
0
      irel->r_offset += 2;
2616
0
    else if (off == addr + 2)
2617
0
      irel->r_offset -= 2;
2618
0
  }
2619
2620
0
      if (irel->r_vaddr - sec->vma == addr)
2621
0
  {
2622
0
    irel->r_vaddr += 2;
2623
0
    add = -2;
2624
0
  }
2625
0
      else if (irel->r_vaddr - sec->vma == addr + 2)
2626
0
  {
2627
0
    irel->r_vaddr -= 2;
2628
0
    add = 2;
2629
0
  }
2630
0
      else
2631
0
  add = 0;
2632
2633
0
      if (add != 0)
2634
0
  {
2635
0
    bfd_byte *loc;
2636
0
    unsigned short insn, oinsn;
2637
0
    bool overflow;
2638
2639
0
    loc = contents + irel->r_vaddr - sec->vma;
2640
0
    overflow = false;
2641
0
    switch (type)
2642
0
      {
2643
0
      default:
2644
0
        break;
2645
2646
0
      case R_SH_PCDISP8BY2:
2647
0
      case R_SH_PCRELIMM8BY2:
2648
0
        insn = bfd_get_16 (abfd, loc);
2649
0
        oinsn = insn;
2650
0
        insn += add / 2;
2651
0
        if ((oinsn & 0xff00) != (insn & 0xff00))
2652
0
    overflow = true;
2653
0
        bfd_put_16 (abfd, (bfd_vma) insn, loc);
2654
0
        break;
2655
2656
0
      case R_SH_PCDISP:
2657
0
        insn = bfd_get_16 (abfd, loc);
2658
0
        oinsn = insn;
2659
0
        insn += add / 2;
2660
0
        if ((oinsn & 0xf000) != (insn & 0xf000))
2661
0
    overflow = true;
2662
0
        bfd_put_16 (abfd, (bfd_vma) insn, loc);
2663
0
        break;
2664
2665
0
      case R_SH_PCRELIMM8BY4:
2666
        /* This reloc ignores the least significant 3 bits of
2667
     the program counter before adding in the offset.
2668
     This means that if ADDR is at an even address, the
2669
     swap will not affect the offset.  If ADDR is an at an
2670
     odd address, then the instruction will be crossing a
2671
     four byte boundary, and must be adjusted.  */
2672
0
        if ((addr & 3) != 0)
2673
0
    {
2674
0
      insn = bfd_get_16 (abfd, loc);
2675
0
      oinsn = insn;
2676
0
      insn += add / 2;
2677
0
      if ((oinsn & 0xff00) != (insn & 0xff00))
2678
0
        overflow = true;
2679
0
      bfd_put_16 (abfd, (bfd_vma) insn, loc);
2680
0
    }
2681
2682
0
        break;
2683
0
      }
2684
2685
0
    if (overflow)
2686
0
      {
2687
0
        _bfd_error_handler
2688
    /* xgettext: c-format */
2689
0
    (_("%pB: %#" PRIx64 ": fatal: reloc overflow while relaxing"),
2690
0
     abfd, (uint64_t) irel->r_vaddr);
2691
0
        bfd_set_error (bfd_error_bad_value);
2692
0
        return false;
2693
0
      }
2694
0
  }
2695
0
    }
2696
2697
0
  return true;
2698
0
}
Unexecuted instantiation: coff-sh.c:sh_swap_insns
Unexecuted instantiation: pe-sh.c:sh_swap_insns
Unexecuted instantiation: pei-sh.c:sh_swap_insns
2699
2700
/* Look for loads and stores which we can align to four byte
2701
   boundaries.  See the longer comment above sh_relax_section for why
2702
   this is desirable.  This sets *PSWAPPED if some instruction was
2703
   swapped.  */
2704
2705
static bool
2706
sh_align_loads (bfd *abfd,
2707
    asection *sec,
2708
    struct internal_reloc *internal_relocs,
2709
    bfd_byte *contents,
2710
    bool *pswapped)
2711
0
{
2712
0
  struct internal_reloc *irel, *irelend;
2713
0
  bfd_vma *labels = NULL;
2714
0
  bfd_vma *label, *label_end;
2715
0
  bfd_size_type amt;
2716
2717
0
  *pswapped = false;
2718
2719
0
  irelend = internal_relocs + sec->reloc_count;
2720
2721
  /* Get all the addresses with labels on them.  */
2722
0
  amt = (bfd_size_type) sec->reloc_count * sizeof (bfd_vma);
2723
0
  labels = (bfd_vma *) bfd_malloc (amt);
2724
0
  if (labels == NULL)
2725
0
    goto error_return;
2726
0
  label_end = labels;
2727
0
  for (irel = internal_relocs; irel < irelend; irel++)
2728
0
    {
2729
0
      if (irel->r_type == R_SH_LABEL)
2730
0
  {
2731
0
    *label_end = irel->r_vaddr - sec->vma;
2732
0
    ++label_end;
2733
0
  }
2734
0
    }
2735
2736
  /* Note that the assembler currently always outputs relocs in
2737
     address order.  If that ever changes, this code will need to sort
2738
     the label values and the relocs.  */
2739
2740
0
  label = labels;
2741
2742
0
  for (irel = internal_relocs; irel < irelend; irel++)
2743
0
    {
2744
0
      bfd_vma start, stop;
2745
2746
0
      if (irel->r_type != R_SH_CODE)
2747
0
  continue;
2748
2749
0
      start = irel->r_vaddr - sec->vma;
2750
2751
0
      for (irel++; irel < irelend; irel++)
2752
0
  if (irel->r_type == R_SH_DATA)
2753
0
    break;
2754
0
      if (irel < irelend)
2755
0
  stop = irel->r_vaddr - sec->vma;
2756
0
      else
2757
0
  stop = sec->size;
2758
2759
0
      if (! _bfd_sh_align_load_span (abfd, sec, contents, sh_swap_insns,
2760
0
             internal_relocs, &label,
2761
0
             label_end, start, stop, pswapped))
2762
0
  goto error_return;
2763
0
    }
2764
2765
0
  free (labels);
2766
2767
0
  return true;
2768
2769
0
 error_return:
2770
0
  free (labels);
2771
0
  return false;
2772
0
}
Unexecuted instantiation: coff-sh.c:sh_align_loads
Unexecuted instantiation: pe-sh.c:sh_align_loads
Unexecuted instantiation: pei-sh.c:sh_align_loads
2773

2774
/* This is a modification of _bfd_coff_generic_relocate_section, which
2775
   will handle SH relaxing.  */
2776
2777
static bool
2778
sh_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
2779
         struct bfd_link_info *info,
2780
         bfd *input_bfd,
2781
         asection *input_section,
2782
         bfd_byte *contents,
2783
         struct internal_reloc *relocs,
2784
         struct internal_syment *syms,
2785
         asection **sections)
2786
0
{
2787
0
  struct internal_reloc *rel;
2788
0
  struct internal_reloc *relend;
2789
2790
0
  rel = relocs;
2791
0
  relend = rel + input_section->reloc_count;
2792
0
  for (; rel < relend; rel++)
2793
0
    {
2794
0
      long symndx;
2795
0
      struct coff_link_hash_entry *h;
2796
0
      struct internal_syment *sym;
2797
0
      bfd_vma addend;
2798
0
      bfd_vma val;
2799
0
      reloc_howto_type *howto;
2800
0
      bfd_reloc_status_type rstat;
2801
2802
      /* Almost all relocs have to do with relaxing.  If any work must
2803
   be done for them, it has been done in sh_relax_section.  */
2804
0
      if (rel->r_type != R_SH_IMM32
2805
#ifdef COFF_WITH_PE
2806
0
    && rel->r_type != R_SH_IMM32CE
2807
0
    && rel->r_type != R_SH_IMAGEBASE
2808
0
#endif
2809
0
    && rel->r_type != R_SH_PCDISP)
2810
0
  continue;
2811
2812
0
      symndx = rel->r_symndx;
2813
2814
0
      if (symndx == -1)
2815
0
  {
2816
0
    h = NULL;
2817
0
    sym = NULL;
2818
0
  }
2819
0
      else
2820
0
  {
2821
0
    if (symndx < 0
2822
0
        || (unsigned long) symndx >= obj_raw_syment_count (input_bfd))
2823
0
      {
2824
0
        _bfd_error_handler
2825
    /* xgettext: c-format */
2826
0
    (_("%pB: invalid symbol index %ld in relocs"),
2827
0
     input_bfd, symndx);
2828
0
        bfd_set_error (bfd_error_bad_value);
2829
0
        return false;
2830
0
      }
2831
0
    h = obj_coff_sym_hashes (input_bfd)[symndx];
2832
0
    sym = syms + symndx;
2833
0
  }
2834
2835
0
      if (sym != NULL && sym->n_scnum != 0)
2836
0
  addend = - sym->n_value;
2837
0
      else
2838
0
  addend = 0;
2839
2840
0
      if (rel->r_type == R_SH_PCDISP)
2841
0
  addend -= 4;
2842
2843
0
      if (rel->r_type >= SH_COFF_HOWTO_COUNT)
2844
0
  howto = NULL;
2845
0
      else
2846
0
  howto = &sh_coff_howtos[rel->r_type];
2847
2848
0
      if (howto == NULL)
2849
0
  {
2850
0
    bfd_set_error (bfd_error_bad_value);
2851
0
    return false;
2852
0
  }
2853
2854
#ifdef COFF_WITH_PE
2855
0
      if (rel->r_type == R_SH_IMAGEBASE)
2856
0
  addend -= pe_data (input_section->output_section->owner)->pe_opthdr.ImageBase;
2857
#endif
2858
2859
0
      val = 0;
2860
2861
0
      if (h == NULL)
2862
0
  {
2863
0
    asection *sec;
2864
2865
    /* There is nothing to do for an internal PCDISP reloc.  */
2866
0
    if (rel->r_type == R_SH_PCDISP)
2867
0
      continue;
2868
2869
0
    if (symndx == -1)
2870
0
      {
2871
0
        sec = bfd_abs_section_ptr;
2872
0
        val = 0;
2873
0
      }
2874
0
    else
2875
0
      {
2876
0
        sec = sections[symndx];
2877
0
        val = (sec->output_section->vma
2878
0
         + sec->output_offset
2879
0
         + sym->n_value
2880
0
         - sec->vma);
2881
0
      }
2882
0
  }
2883
0
      else
2884
0
  {
2885
0
    if (h->root.type == bfd_link_hash_defined
2886
0
        || h->root.type == bfd_link_hash_defweak)
2887
0
      {
2888
0
        asection *sec;
2889
2890
0
        sec = h->root.u.def.section;
2891
0
        val = (h->root.u.def.value
2892
0
         + sec->output_section->vma
2893
0
         + sec->output_offset);
2894
0
      }
2895
0
    else if (! bfd_link_relocatable (info))
2896
0
      (*info->callbacks->undefined_symbol)
2897
0
        (info, h->root.root.string, input_bfd, input_section,
2898
0
         rel->r_vaddr - input_section->vma, true);
2899
0
  }
2900
2901
0
      rstat = _bfd_final_link_relocate (howto, input_bfd, input_section,
2902
0
          contents,
2903
0
          rel->r_vaddr - input_section->vma,
2904
0
          val, addend);
2905
2906
0
      switch (rstat)
2907
0
  {
2908
0
  default:
2909
0
    abort ();
2910
0
  case bfd_reloc_ok:
2911
0
    break;
2912
0
  case bfd_reloc_overflow:
2913
0
    {
2914
0
      const char *name;
2915
0
      char buf[SYMNMLEN + 1];
2916
2917
0
      if (symndx == -1)
2918
0
        name = "*ABS*";
2919
0
      else if (h != NULL)
2920
0
        name = NULL;
2921
0
      else if (sym->_n._n_n._n_zeroes == 0
2922
0
         && sym->_n._n_n._n_offset != 0)
2923
0
        {
2924
0
    if (sym->_n._n_n._n_offset < obj_coff_strings_len (input_bfd))
2925
0
      name = obj_coff_strings (input_bfd) + sym->_n._n_n._n_offset;
2926
0
    else
2927
0
      name = "?";
2928
0
        }
2929
0
      else
2930
0
        {
2931
0
    strncpy (buf, sym->_n._n_name, SYMNMLEN);
2932
0
    buf[SYMNMLEN] = '\0';
2933
0
    name = buf;
2934
0
        }
2935
2936
0
      (*info->callbacks->reloc_overflow)
2937
0
        (info, (h ? &h->root : NULL), name, howto->name,
2938
0
         (bfd_vma) 0, input_bfd, input_section,
2939
0
         rel->r_vaddr - input_section->vma);
2940
0
    }
2941
0
  }
2942
0
    }
2943
2944
0
  return true;
2945
0
}
Unexecuted instantiation: coff-sh.c:sh_relocate_section
Unexecuted instantiation: pe-sh.c:sh_relocate_section
Unexecuted instantiation: pei-sh.c:sh_relocate_section
2946
2947
/* This is a version of bfd_generic_get_relocated_section_contents
2948
   which uses sh_relocate_section.  */
2949
2950
static bfd_byte *
2951
sh_coff_get_relocated_section_contents (bfd *output_bfd,
2952
          struct bfd_link_info *link_info,
2953
          const struct bfd_link_order *link_order,
2954
          bfd_byte *data,
2955
          bool relocatable,
2956
          asymbol **symbols)
2957
15
{
2958
15
  asection *input_section = link_order->u.indirect.section;
2959
15
  bfd *input_bfd = input_section->owner;
2960
15
  asection **sections = NULL;
2961
15
  struct internal_reloc *internal_relocs = NULL;
2962
15
  struct internal_syment *internal_syms = NULL;
2963
2964
  /* We only need to handle the case of relaxing, or of having a
2965
     particular set of section contents, specially.  */
2966
15
  if (relocatable
2967
15
      || coff_section_data (input_bfd, input_section) == NULL
2968
0
      || coff_section_data (input_bfd, input_section)->contents == NULL)
2969
15
    return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
2970
15
                   link_order, data,
2971
15
                   relocatable,
2972
15
                   symbols);
2973
2974
0
  bfd_byte *orig_data = data;
2975
0
  if (data == NULL)
2976
0
    {
2977
0
      data = bfd_malloc (input_section->size);
2978
0
      if (data == NULL)
2979
0
  return NULL;
2980
0
    }
2981
0
  memcpy (data, coff_section_data (input_bfd, input_section)->contents,
2982
0
    (size_t) input_section->size);
2983
2984
0
  if ((input_section->flags & SEC_RELOC) != 0
2985
0
      && input_section->reloc_count > 0)
2986
0
    {
2987
0
      bfd_size_type symesz = bfd_coff_symesz (input_bfd);
2988
0
      bfd_byte *esym, *esymend;
2989
0
      struct internal_syment *isymp;
2990
0
      asection **secpp;
2991
0
      bfd_size_type amt;
2992
2993
0
      if (! _bfd_coff_get_external_symbols (input_bfd))
2994
0
  goto error_return;
2995
2996
0
      internal_relocs = (bfd_coff_read_internal_relocs
2997
0
       (input_bfd, input_section, false, NULL, false, NULL));
2998
0
      if (internal_relocs == NULL)
2999
0
  goto error_return;
3000
3001
0
      amt = obj_raw_syment_count (input_bfd);
3002
0
      amt *= sizeof (struct internal_syment);
3003
0
      internal_syms = (struct internal_syment *) bfd_malloc (amt);
3004
0
      if (internal_syms == NULL)
3005
0
  goto error_return;
3006
3007
0
      amt = obj_raw_syment_count (input_bfd);
3008
0
      amt *= sizeof (asection *);
3009
0
      sections = (asection **) bfd_malloc (amt);
3010
0
      if (sections == NULL)
3011
0
  goto error_return;
3012
3013
0
      isymp = internal_syms;
3014
0
      secpp = sections;
3015
0
      esym = (bfd_byte *) obj_coff_external_syms (input_bfd);
3016
0
      esymend = esym + obj_raw_syment_count (input_bfd) * symesz;
3017
0
      while (esym < esymend)
3018
0
  {
3019
0
    bfd_coff_swap_sym_in (input_bfd, esym, isymp);
3020
3021
0
    if (isymp->n_scnum != 0)
3022
0
      *secpp = coff_section_from_bfd_index (input_bfd, isymp->n_scnum);
3023
0
    else
3024
0
      {
3025
0
        if (isymp->n_value == 0)
3026
0
    *secpp = bfd_und_section_ptr;
3027
0
        else
3028
0
    *secpp = bfd_com_section_ptr;
3029
0
      }
3030
3031
0
    esym += (isymp->n_numaux + 1) * symesz;
3032
0
    secpp += isymp->n_numaux + 1;
3033
0
    isymp += isymp->n_numaux + 1;
3034
0
  }
3035
3036
0
      if (! sh_relocate_section (output_bfd, link_info, input_bfd,
3037
0
         input_section, data, internal_relocs,
3038
0
         internal_syms, sections))
3039
0
  goto error_return;
3040
3041
0
      free (sections);
3042
0
      sections = NULL;
3043
0
      free (internal_syms);
3044
0
      internal_syms = NULL;
3045
0
      free (internal_relocs);
3046
0
      internal_relocs = NULL;
3047
0
    }
3048
3049
0
  return data;
3050
3051
0
 error_return:
3052
0
  free (internal_relocs);
3053
0
  free (internal_syms);
3054
0
  free (sections);
3055
0
  if (orig_data == NULL)
3056
0
    free (data);
3057
0
  return NULL;
3058
0
}
coff-sh.c:sh_coff_get_relocated_section_contents
Line
Count
Source
2957
15
{
2958
15
  asection *input_section = link_order->u.indirect.section;
2959
15
  bfd *input_bfd = input_section->owner;
2960
15
  asection **sections = NULL;
2961
15
  struct internal_reloc *internal_relocs = NULL;
2962
15
  struct internal_syment *internal_syms = NULL;
2963
2964
  /* We only need to handle the case of relaxing, or of having a
2965
     particular set of section contents, specially.  */
2966
15
  if (relocatable
2967
15
      || coff_section_data (input_bfd, input_section) == NULL
2968
0
      || coff_section_data (input_bfd, input_section)->contents == NULL)
2969
15
    return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
2970
15
                   link_order, data,
2971
15
                   relocatable,
2972
15
                   symbols);
2973
2974
0
  bfd_byte *orig_data = data;
2975
0
  if (data == NULL)
2976
0
    {
2977
0
      data = bfd_malloc (input_section->size);
2978
0
      if (data == NULL)
2979
0
  return NULL;
2980
0
    }
2981
0
  memcpy (data, coff_section_data (input_bfd, input_section)->contents,
2982
0
    (size_t) input_section->size);
2983
2984
0
  if ((input_section->flags & SEC_RELOC) != 0
2985
0
      && input_section->reloc_count > 0)
2986
0
    {
2987
0
      bfd_size_type symesz = bfd_coff_symesz (input_bfd);
2988
0
      bfd_byte *esym, *esymend;
2989
0
      struct internal_syment *isymp;
2990
0
      asection **secpp;
2991
0
      bfd_size_type amt;
2992
2993
0
      if (! _bfd_coff_get_external_symbols (input_bfd))
2994
0
  goto error_return;
2995
2996
0
      internal_relocs = (bfd_coff_read_internal_relocs
2997
0
       (input_bfd, input_section, false, NULL, false, NULL));
2998
0
      if (internal_relocs == NULL)
2999
0
  goto error_return;
3000
3001
0
      amt = obj_raw_syment_count (input_bfd);
3002
0
      amt *= sizeof (struct internal_syment);
3003
0
      internal_syms = (struct internal_syment *) bfd_malloc (amt);
3004
0
      if (internal_syms == NULL)
3005
0
  goto error_return;
3006
3007
0
      amt = obj_raw_syment_count (input_bfd);
3008
0
      amt *= sizeof (asection *);
3009
0
      sections = (asection **) bfd_malloc (amt);
3010
0
      if (sections == NULL)
3011
0
  goto error_return;
3012
3013
0
      isymp = internal_syms;
3014
0
      secpp = sections;
3015
0
      esym = (bfd_byte *) obj_coff_external_syms (input_bfd);
3016
0
      esymend = esym + obj_raw_syment_count (input_bfd) * symesz;
3017
0
      while (esym < esymend)
3018
0
  {
3019
0
    bfd_coff_swap_sym_in (input_bfd, esym, isymp);
3020
3021
0
    if (isymp->n_scnum != 0)
3022
0
      *secpp = coff_section_from_bfd_index (input_bfd, isymp->n_scnum);
3023
0
    else
3024
0
      {
3025
0
        if (isymp->n_value == 0)
3026
0
    *secpp = bfd_und_section_ptr;
3027
0
        else
3028
0
    *secpp = bfd_com_section_ptr;
3029
0
      }
3030
3031
0
    esym += (isymp->n_numaux + 1) * symesz;
3032
0
    secpp += isymp->n_numaux + 1;
3033
0
    isymp += isymp->n_numaux + 1;
3034
0
  }
3035
3036
0
      if (! sh_relocate_section (output_bfd, link_info, input_bfd,
3037
0
         input_section, data, internal_relocs,
3038
0
         internal_syms, sections))
3039
0
  goto error_return;
3040
3041
0
      free (sections);
3042
0
      sections = NULL;
3043
0
      free (internal_syms);
3044
0
      internal_syms = NULL;
3045
0
      free (internal_relocs);
3046
0
      internal_relocs = NULL;
3047
0
    }
3048
3049
0
  return data;
3050
3051
0
 error_return:
3052
0
  free (internal_relocs);
3053
0
  free (internal_syms);
3054
0
  free (sections);
3055
0
  if (orig_data == NULL)
3056
0
    free (data);
3057
  return NULL;
3058
0
}
Unexecuted instantiation: pe-sh.c:sh_coff_get_relocated_section_contents
Unexecuted instantiation: pei-sh.c:sh_coff_get_relocated_section_contents
3059
3060
/* The target vectors.  */
3061
3062
#ifndef TARGET_SHL_SYM
3063
CREATE_BIG_COFF_TARGET_VEC (sh_coff_vec, "coff-sh", BFD_IS_RELAXABLE, 0, '_', NULL, COFF_SWAP_TABLE)
3064
#endif
3065
3066
#ifdef TARGET_SHL_SYM
3067
#define TARGET_SYM TARGET_SHL_SYM
3068
#else
3069
#define TARGET_SYM sh_coff_le_vec
3070
#endif
3071
3072
#ifndef TARGET_SHL_NAME
3073
#define TARGET_SHL_NAME "coff-shl"
3074
#endif
3075
3076
#ifdef COFF_WITH_PE
3077
CREATE_LITTLE_COFF_TARGET_VEC (TARGET_SYM, TARGET_SHL_NAME, BFD_IS_RELAXABLE,
3078
             0, '_', NULL, COFF_SWAP_TABLE);
3079
#else
3080
CREATE_LITTLE_COFF_TARGET_VEC (TARGET_SYM, TARGET_SHL_NAME, BFD_IS_RELAXABLE,
3081
             0, '_', NULL, COFF_SWAP_TABLE)
3082
#endif
3083
3084
#ifndef TARGET_SHL_SYM
3085
3086
/* Some people want versions of the SH COFF target which do not align
3087
   to 16 byte boundaries.  We implement that by adding a couple of new
3088
   target vectors.  These are just like the ones above, but they
3089
   change the default section alignment.  To generate them in the
3090
   assembler, use -small.  To use them in the linker, use -b
3091
   coff-sh{l}-small and -oformat coff-sh{l}-small.
3092
3093
   Yes, this is a horrible hack.  A general solution for setting
3094
   section alignment in COFF is rather complex.  ELF handles this
3095
   correctly.  */
3096
3097
/* Only recognize the small versions if the target was not defaulted.
3098
   Otherwise we won't recognize the non default endianness.  */
3099
3100
static bfd_cleanup
3101
coff_small_object_p (bfd *abfd)
3102
391k
{
3103
391k
  if (abfd->target_defaulted)
3104
309k
    {
3105
309k
      bfd_set_error (bfd_error_wrong_format);
3106
309k
      return NULL;
3107
309k
    }
3108
82.2k
  return coff_object_p (abfd);
3109
391k
}
3110
3111
/* Set the section alignment for the small versions.  */
3112
3113
static bool
3114
coff_small_new_section_hook (bfd *abfd, asection *section)
3115
17.1k
{
3116
17.1k
  if (! coff_new_section_hook (abfd, section))
3117
0
    return false;
3118
3119
  /* We must align to at least a four byte boundary, because longword
3120
     accesses must be on a four byte boundary.  */
3121
17.1k
  if (section->alignment_power == COFF_DEFAULT_SECTION_ALIGNMENT_POWER)
3122
16.6k
    section->alignment_power = 2;
3123
3124
  return true;
3125
17.1k
}
3126
3127
/* This is copied from bfd_coff_std_swap_table so that we can change
3128
   the default section alignment power.  */
3129
3130
static const bfd_coff_backend_data bfd_coff_small_swap_table =
3131
{
3132
  coff_swap_aux_in, coff_swap_sym_in, coff_swap_lineno_in,
3133
  coff_swap_aux_out, coff_swap_sym_out,
3134
  coff_swap_lineno_out, coff_swap_reloc_out,
3135
  coff_swap_filehdr_out, coff_swap_aouthdr_out,
3136
  coff_swap_scnhdr_out,
3137
  FILHSZ, AOUTSZ, SCNHSZ, SYMESZ, AUXESZ, RELSZ, LINESZ, FILNMLEN,
3138
#ifdef COFF_LONG_FILENAMES
3139
  true,
3140
#else
3141
  false,
3142
#endif
3143
  COFF_DEFAULT_LONG_SECTION_NAMES,
3144
  2,
3145
#ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
3146
  true,
3147
#else
3148
  false,
3149
#endif
3150
#ifdef COFF_DEBUG_STRING_WIDE_PREFIX
3151
  4,
3152
#else
3153
  2,
3154
#endif
3155
  32768,
3156
  coff_swap_filehdr_in, coff_swap_aouthdr_in, coff_swap_scnhdr_in,
3157
  coff_swap_reloc_in, coff_bad_format_hook, coff_set_arch_mach_hook,
3158
  coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
3159
  coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
3160
  coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
3161
  coff_classify_symbol, coff_compute_section_file_positions,
3162
  coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
3163
  coff_adjust_symndx,
3164
  coff_link_output_has_begun, coff_final_link_postscript,
3165
  bfd_pe_print_pdata
3166
};
3167
3168
#define coff_small_close_and_cleanup \
3169
  coff_close_and_cleanup
3170
#define coff_small_bfd_free_cached_info \
3171
  coff_bfd_free_cached_info
3172
#define coff_small_get_section_contents \
3173
  coff_get_section_contents
3174
3175
extern const bfd_target sh_coff_small_le_vec;
3176
3177
const bfd_target sh_coff_small_vec =
3178
{
3179
  "coff-sh-small",    /* name */
3180
  bfd_target_coff_flavour,
3181
  BFD_ENDIAN_BIG,   /* data byte order is big */
3182
  BFD_ENDIAN_BIG,   /* header byte order is big */
3183
3184
  (HAS_RELOC | EXEC_P   /* object flags */
3185
   | HAS_LINENO | HAS_DEBUG
3186
   | HAS_SYMS | HAS_LOCALS | WP_TEXT | BFD_IS_RELAXABLE),
3187
3188
  (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC),
3189
  '_',        /* leading symbol underscore */
3190
  '/',        /* ar_pad_char */
3191
  15,       /* ar_max_namelen */
3192
  0,        /* match priority.  */
3193
  TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols.  */
3194
  TARGET_MERGE_SECTIONS,
3195
  bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3196
  bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3197
  bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
3198
  bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3199
  bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3200
  bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
3201
3202
  {       /* bfd_check_format */
3203
    _bfd_dummy_target,
3204
    coff_small_object_p,
3205
    bfd_generic_archive_p,
3206
    _bfd_dummy_target
3207
  },
3208
  {       /* bfd_set_format */
3209
    _bfd_bool_bfd_false_error,
3210
    coff_mkobject,
3211
    _bfd_generic_mkarchive,
3212
    _bfd_bool_bfd_false_error
3213
  },
3214
  {       /* bfd_write_contents */
3215
    _bfd_bool_bfd_false_error,
3216
    coff_write_object_contents,
3217
    _bfd_write_archive_contents,
3218
    _bfd_bool_bfd_false_error
3219
  },
3220
3221
  BFD_JUMP_TABLE_GENERIC (coff_small),
3222
  BFD_JUMP_TABLE_COPY (coff),
3223
  BFD_JUMP_TABLE_CORE (_bfd_nocore),
3224
  BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
3225
  BFD_JUMP_TABLE_SYMBOLS (coff),
3226
  BFD_JUMP_TABLE_RELOCS (coff),
3227
  BFD_JUMP_TABLE_WRITE (coff),
3228
  BFD_JUMP_TABLE_LINK (coff),
3229
  BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
3230
3231
  &sh_coff_small_le_vec,
3232
3233
  &bfd_coff_small_swap_table
3234
};
3235
3236
const bfd_target sh_coff_small_le_vec =
3237
{
3238
  "coff-shl-small",   /* name */
3239
  bfd_target_coff_flavour,
3240
  BFD_ENDIAN_LITTLE,    /* data byte order is little */
3241
  BFD_ENDIAN_LITTLE,    /* header byte order is little endian too*/
3242
3243
  (HAS_RELOC | EXEC_P   /* object flags */
3244
   | HAS_LINENO | HAS_DEBUG
3245
   | HAS_SYMS | HAS_LOCALS | WP_TEXT | BFD_IS_RELAXABLE),
3246
3247
  (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC),
3248
  '_',        /* leading symbol underscore */
3249
  '/',        /* ar_pad_char */
3250
  15,       /* ar_max_namelen */
3251
  0,        /* match priority.  */
3252
  TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols.  */
3253
  TARGET_MERGE_SECTIONS,
3254
  bfd_getl64, bfd_getl_signed_64, bfd_putl64,
3255
  bfd_getl32, bfd_getl_signed_32, bfd_putl32,
3256
  bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
3257
  bfd_getl64, bfd_getl_signed_64, bfd_putl64,
3258
  bfd_getl32, bfd_getl_signed_32, bfd_putl32,
3259
  bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
3260
3261
  {       /* bfd_check_format */
3262
    _bfd_dummy_target,
3263
    coff_small_object_p,
3264
    bfd_generic_archive_p,
3265
    _bfd_dummy_target
3266
  },
3267
  {       /* bfd_set_format */
3268
    _bfd_bool_bfd_false_error,
3269
    coff_mkobject,
3270
    _bfd_generic_mkarchive,
3271
    _bfd_bool_bfd_false_error
3272
  },
3273
  {       /* bfd_write_contents */
3274
    _bfd_bool_bfd_false_error,
3275
    coff_write_object_contents,
3276
    _bfd_write_archive_contents,
3277
    _bfd_bool_bfd_false_error
3278
  },
3279
3280
  BFD_JUMP_TABLE_GENERIC (coff_small),
3281
  BFD_JUMP_TABLE_COPY (coff),
3282
  BFD_JUMP_TABLE_CORE (_bfd_nocore),
3283
  BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
3284
  BFD_JUMP_TABLE_SYMBOLS (coff),
3285
  BFD_JUMP_TABLE_RELOCS (coff),
3286
  BFD_JUMP_TABLE_WRITE (coff),
3287
  BFD_JUMP_TABLE_LINK (coff),
3288
  BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
3289
3290
  &sh_coff_small_vec,
3291
3292
  &bfd_coff_small_swap_table
3293
};
3294
#endif