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-arm.c
Line
Count
Source
1
/* BFD back-end for ARM COFF files.
2
   Copyright (C) 1990-2026 Free Software Foundation, Inc.
3
   Written by Cygnus Support.
4
5
   This file is part of BFD, the Binary File Descriptor library.
6
7
   This program is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 3 of the License, or
10
   (at your option) any later version.
11
12
   This program is distributed in the hope that it will be useful,
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
   GNU General Public License for more details.
16
17
   You should have received a copy of the GNU General Public License
18
   along with this program; if not, write to the Free Software
19
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20
   MA 02110-1301, USA.  */
21
22
#include "sysdep.h"
23
#include "bfd.h"
24
#include "libbfd.h"
25
#include "coff/arm.h"
26
#include "coff/internal.h"
27
#include "cpu-arm.h"
28
#include "coff-arm.h"
29
30
#ifdef COFF_WITH_PE
31
#include "coff/pe.h"
32
#endif
33
34
#include "libcoff.h"
35
36
/* All users of this file have bfd_octets_per_byte (abfd, sec) == 1.  */
37
0
#define OCTETS_PER_BYTE(ABFD, SEC) 1
38
39
/* Macros for manipulation the bits in the flags field of the coff data
40
   structure.  */
41
#define APCS_26_FLAG(abfd) \
42
357
  (coff_data (abfd)->flags & F_APCS_26)
43
44
#define APCS_FLOAT_FLAG(abfd) \
45
357
  (coff_data (abfd)->flags & F_APCS_FLOAT)
46
47
#define PIC_FLAG(abfd) \
48
357
  (coff_data (abfd)->flags & F_PIC)
49
50
#define APCS_SET(abfd) \
51
38.0k
  (coff_data (abfd)->flags & F_APCS_SET)
52
53
#define SET_APCS_FLAGS(abfd, flgs) \
54
18.5k
  do                  \
55
18.5k
    {                 \
56
18.5k
      coff_data (abfd)->flags &= ~(F_APCS_26 | F_APCS_FLOAT | F_PIC);  \
57
18.5k
      coff_data (abfd)->flags |= (flgs) | F_APCS_SET;     \
58
18.5k
    }                 \
59
18.5k
  while (0)
60
61
#define INTERWORK_FLAG(abfd) \
62
357
  (coff_data (abfd)->flags & F_INTERWORK)
63
64
#define INTERWORK_SET(abfd) \
65
38.7k
  (coff_data (abfd)->flags & F_INTERWORK_SET)
66
67
#define SET_INTERWORK_FLAG(abfd, flg) \
68
18.5k
  do                  \
69
18.5k
    {                 \
70
18.5k
      coff_data (abfd)->flags &= ~F_INTERWORK;       \
71
18.5k
      coff_data (abfd)->flags |= (flg) | F_INTERWORK_SET;   \
72
18.5k
    }                 \
73
18.5k
  while (0)
74
75
#ifndef NUM_ELEM
76
0
#define NUM_ELEM(a) ((sizeof (a)) / sizeof ((a)[0]))
77
#endif
78
79
typedef enum {bunknown, b9, b12, b23} thumb_pcrel_branchtype;
80
/* Some typedefs for holding instructions.  */
81
typedef unsigned long int insn32;
82
typedef unsigned short int insn16;
83
84
/* The linker script knows the section names for placement.
85
   The entry_names are used to do simple name mangling on the stubs.
86
   Given a function name, and its type, the stub can be found. The
87
   name can be changed. The only requirement is the %s be present.  */
88
89
0
#define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
90
0
#define THUMB2ARM_GLUE_ENTRY_NAME   "__%s_from_thumb"
91
92
0
#define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
93
0
#define ARM2THUMB_GLUE_ENTRY_NAME   "__%s_from_arm"
94
95
/* Used by the assembler.  */
96
97
static bfd_reloc_status_type
98
coff_arm_reloc (bfd *abfd,
99
    arelent *reloc_entry,
100
    asymbol *symbol ATTRIBUTE_UNUSED,
101
    void * data,
102
    asection *input_section,
103
    bfd *output_bfd,
104
    char **error_message ATTRIBUTE_UNUSED)
105
0
{
106
0
  symvalue diff;
107
108
0
  if (output_bfd == NULL)
109
0
    return bfd_reloc_continue;
110
111
0
  diff = reloc_entry->addend;
112
113
0
#define DOIT(x)             \
114
0
  x = ((x & ~howto->dst_mask)         \
115
0
       | (((x & howto->src_mask) + diff) & howto->dst_mask))
116
117
0
  if (diff != 0)
118
0
    {
119
0
      reloc_howto_type *howto = reloc_entry->howto;
120
0
      bfd_size_type octets = (reloc_entry->address
121
0
            * OCTETS_PER_BYTE (abfd, input_section));
122
0
      unsigned char *addr = (unsigned char *) data + octets;
123
124
0
      if (!bfd_reloc_offset_in_range (howto, abfd, input_section, octets))
125
0
  return bfd_reloc_outofrange;
126
127
0
      switch (bfd_get_reloc_size (howto))
128
0
  {
129
0
  case 1:
130
0
    {
131
0
      char x = bfd_get_8 (abfd, addr);
132
0
      DOIT (x);
133
0
      bfd_put_8 (abfd, x, addr);
134
0
    }
135
0
    break;
136
137
0
  case 2:
138
0
    {
139
0
      short x = bfd_get_16 (abfd, addr);
140
0
      DOIT (x);
141
0
      bfd_put_16 (abfd, (bfd_vma) x, addr);
142
0
    }
143
0
    break;
144
145
0
  case 4:
146
0
    {
147
0
      long x = bfd_get_32 (abfd, addr);
148
0
      DOIT (x);
149
0
      bfd_put_32 (abfd, (bfd_vma) x, addr);
150
0
    }
151
0
    break;
152
153
0
  default:
154
0
    abort ();
155
0
  }
156
0
    }
157
158
  /* Now let bfd_perform_relocation finish everything up.  */
159
0
  return bfd_reloc_continue;
160
0
}
Unexecuted instantiation: pe-arm-wince.c:coff_arm_reloc
Unexecuted instantiation: pe-arm.c:coff_arm_reloc
Unexecuted instantiation: pei-arm-wince.c:coff_arm_reloc
Unexecuted instantiation: pei-arm.c:coff_arm_reloc
161
162
/* If USER_LABEL_PREFIX is defined as "_" (see coff_arm_is_local_label_name()
163
   in this file), then TARGET_UNDERSCORE should be defined, otherwise it
164
   should not.  */
165
#ifndef TARGET_UNDERSCORE
166
3.38k
#define TARGET_UNDERSCORE '_'
167
#endif
168
169
#ifndef PCRELOFFSET
170
#define PCRELOFFSET true
171
#endif
172
173
/* These most certainly belong somewhere else. Just had to get rid of
174
   the manifest constants in the code.  */
175
176
#ifdef ARM_WINCE
177
178
#define ARM_26D      0
179
#define ARM_32       1
180
#define ARM_RVA32    2
181
#define ARM_26       3
182
#define ARM_THUMB12  4
183
#define ARM_SECTION  14
184
#define ARM_SECREL   15
185
186
#else
187
188
#define ARM_8      0
189
#define ARM_16       1
190
0
#define ARM_32       2
191
0
#define ARM_26       3
192
#define ARM_DISP8    4
193
#define ARM_DISP16   5
194
#define ARM_DISP32   6
195
0
#define ARM_26D      7
196
/* 8 is unused.  */
197
#define ARM_NEG16    9
198
#define ARM_NEG32   10
199
0
#define ARM_RVA32   11
200
#define ARM_THUMB9  12
201
#define ARM_THUMB12 13
202
0
#define ARM_THUMB23 14
203
204
#endif
205
206
static bfd_reloc_status_type aoutarm_fix_pcrel_26_done
207
  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
208
static bfd_reloc_status_type aoutarm_fix_pcrel_26
209
  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
210
static bfd_reloc_status_type coff_thumb_pcrel_12
211
  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
212
#ifndef ARM_WINCE
213
static bfd_reloc_status_type coff_thumb_pcrel_9
214
  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
215
static bfd_reloc_status_type coff_thumb_pcrel_23
216
  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
217
#endif
218
219
static reloc_howto_type aoutarm_std_reloc_howto[] =
220
  {
221
#ifdef ARM_WINCE
222
    HOWTO (ARM_26D,
223
     2,
224
     4,
225
     24,
226
     true,
227
     0,
228
     complain_overflow_dont,
229
     aoutarm_fix_pcrel_26_done,
230
     "ARM_26D",
231
     true,  /* partial_inplace.  */
232
     0x00ffffff,
233
     0x0,
234
     PCRELOFFSET),
235
    HOWTO (ARM_32,
236
     0,
237
     4,
238
     32,
239
     false,
240
     0,
241
     complain_overflow_bitfield,
242
     coff_arm_reloc,
243
     "ARM_32",
244
     true,  /* partial_inplace.  */
245
     0xffffffff,
246
     0xffffffff,
247
     PCRELOFFSET),
248
    HOWTO (ARM_RVA32,
249
     0,
250
     4,
251
     32,
252
     false,
253
     0,
254
     complain_overflow_bitfield,
255
     coff_arm_reloc,
256
     "ARM_RVA32",
257
     true,  /* partial_inplace.  */
258
     0xffffffff,
259
     0xffffffff,
260
     PCRELOFFSET),
261
    HOWTO (ARM_26,
262
     2,
263
     4,
264
     24,
265
     true,
266
     0,
267
     complain_overflow_signed,
268
     aoutarm_fix_pcrel_26 ,
269
     "ARM_26",
270
     false,
271
     0x00ffffff,
272
     0x00ffffff,
273
     PCRELOFFSET),
274
    HOWTO (ARM_THUMB12,
275
     1,
276
     2,
277
     11,
278
     true,
279
     0,
280
     complain_overflow_signed,
281
     coff_thumb_pcrel_12 ,
282
     "ARM_THUMB12",
283
     false,
284
     0x000007ff,
285
     0x000007ff,
286
     PCRELOFFSET),
287
    EMPTY_HOWTO (-1),
288
    EMPTY_HOWTO (-1),
289
    EMPTY_HOWTO (-1),
290
    EMPTY_HOWTO (-1),
291
    EMPTY_HOWTO (-1),
292
    EMPTY_HOWTO (-1),
293
    EMPTY_HOWTO (-1),
294
    EMPTY_HOWTO (-1),
295
    EMPTY_HOWTO (-1),
296
    HOWTO (ARM_SECTION,
297
     0,
298
     2,
299
     16,
300
     false,
301
     0,
302
     complain_overflow_bitfield,
303
     coff_arm_reloc,
304
     "ARM_SECTION",
305
     true,  /* partial_inplace.  */
306
     0x0000ffff,
307
     0x0000ffff,
308
     PCRELOFFSET),
309
    HOWTO (ARM_SECREL,
310
     0,
311
     4,
312
     32,
313
     false,
314
     0,
315
     complain_overflow_bitfield,
316
     coff_arm_reloc,
317
     "ARM_SECREL",
318
     true,  /* partial_inplace.  */
319
     0xffffffff,
320
     0xffffffff,
321
     PCRELOFFSET),
322
#else /* not ARM_WINCE */
323
    HOWTO (ARM_8,
324
     0,
325
     1,
326
     8,
327
     false,
328
     0,
329
     complain_overflow_bitfield,
330
     coff_arm_reloc,
331
     "ARM_8",
332
     true,
333
     0x000000ff,
334
     0x000000ff,
335
     PCRELOFFSET),
336
    HOWTO (ARM_16,
337
     0,
338
     2,
339
     16,
340
     false,
341
     0,
342
     complain_overflow_bitfield,
343
     coff_arm_reloc,
344
     "ARM_16",
345
     true,
346
     0x0000ffff,
347
     0x0000ffff,
348
     PCRELOFFSET),
349
    HOWTO (ARM_32,
350
     0,
351
     4,
352
     32,
353
     false,
354
     0,
355
     complain_overflow_bitfield,
356
     coff_arm_reloc,
357
     "ARM_32",
358
     true,
359
     0xffffffff,
360
     0xffffffff,
361
     PCRELOFFSET),
362
    HOWTO (ARM_26,
363
     2,
364
     4,
365
     24,
366
     true,
367
     0,
368
     complain_overflow_signed,
369
     aoutarm_fix_pcrel_26 ,
370
     "ARM_26",
371
     false,
372
     0x00ffffff,
373
     0x00ffffff,
374
     PCRELOFFSET),
375
    HOWTO (ARM_DISP8,
376
     0,
377
     1,
378
     8,
379
     true,
380
     0,
381
     complain_overflow_signed,
382
     coff_arm_reloc,
383
     "ARM_DISP8",
384
     true,
385
     0x000000ff,
386
     0x000000ff,
387
     true),
388
    HOWTO (ARM_DISP16,
389
     0,
390
     2,
391
     16,
392
     true,
393
     0,
394
     complain_overflow_signed,
395
     coff_arm_reloc,
396
     "ARM_DISP16",
397
     true,
398
     0x0000ffff,
399
     0x0000ffff,
400
     true),
401
    HOWTO (ARM_DISP32,
402
     0,
403
     4,
404
     32,
405
     true,
406
     0,
407
     complain_overflow_signed,
408
     coff_arm_reloc,
409
     "ARM_DISP32",
410
     true,
411
     0xffffffff,
412
     0xffffffff,
413
     true),
414
    HOWTO (ARM_26D,
415
     2,
416
     4,
417
     24,
418
     false,
419
     0,
420
     complain_overflow_dont,
421
     aoutarm_fix_pcrel_26_done,
422
     "ARM_26D",
423
     true,
424
     0x00ffffff,
425
     0x0,
426
     false),
427
    /* 8 is unused */
428
    EMPTY_HOWTO (-1),
429
    HOWTO (ARM_NEG16,
430
     0,
431
     -2,
432
     16,
433
     false,
434
     0,
435
     complain_overflow_bitfield,
436
     coff_arm_reloc,
437
     "ARM_NEG16",
438
     true,
439
     0x0000ffff,
440
     0x0000ffff,
441
     false),
442
    HOWTO (ARM_NEG32,
443
     0,
444
     -4,
445
     32,
446
     false,
447
     0,
448
     complain_overflow_bitfield,
449
     coff_arm_reloc,
450
     "ARM_NEG32",
451
     true,
452
     0xffffffff,
453
     0xffffffff,
454
     false),
455
    HOWTO (ARM_RVA32,
456
     0,
457
     4,
458
     32,
459
     false,
460
     0,
461
     complain_overflow_bitfield,
462
     coff_arm_reloc,
463
     "ARM_RVA32",
464
     true,
465
     0xffffffff,
466
     0xffffffff,
467
     PCRELOFFSET),
468
    HOWTO (ARM_THUMB9,
469
     1,
470
     2,
471
     8,
472
     true,
473
     0,
474
     complain_overflow_signed,
475
     coff_thumb_pcrel_9 ,
476
     "ARM_THUMB9",
477
     false,
478
     0x000000ff,
479
     0x000000ff,
480
     PCRELOFFSET),
481
    HOWTO (ARM_THUMB12,
482
     1,
483
     2,
484
     11,
485
     true,
486
     0,
487
     complain_overflow_signed,
488
     coff_thumb_pcrel_12 ,
489
     "ARM_THUMB12",
490
     false,
491
     0x000007ff,
492
     0x000007ff,
493
     PCRELOFFSET),
494
    HOWTO (ARM_THUMB23,
495
     1,
496
     4,
497
     22,
498
     true,
499
     0,
500
     complain_overflow_signed,
501
     coff_thumb_pcrel_23 ,
502
     "ARM_THUMB23",
503
     false,
504
     0x07ff07ff,
505
     0x07ff07ff,
506
     PCRELOFFSET)
507
#endif /* not ARM_WINCE */
508
  };
509
510
0
#define NUM_RELOCS NUM_ELEM (aoutarm_std_reloc_howto)
511
512
#ifdef COFF_WITH_PE
513
/* Return TRUE if this relocation should
514
   appear in the output .reloc section.  */
515
516
static bool
517
in_reloc_p (bfd * abfd ATTRIBUTE_UNUSED,
518
      reloc_howto_type * howto)
519
0
{
520
0
  return !howto->pc_relative
521
# ifdef ARM_WINCE
522
   && howto->type != ARM_SECREL
523
   && howto->type != ARM_SECTION
524
# endif
525
0
   && howto->type != ARM_RVA32;
526
0
}
Unexecuted instantiation: pe-arm-wince.c:in_reloc_p
Unexecuted instantiation: pe-arm.c:in_reloc_p
Unexecuted instantiation: pei-arm-wince.c:in_reloc_p
Unexecuted instantiation: pei-arm.c:in_reloc_p
527
#endif
528
529
#define RTYPE2HOWTO(cache_ptr, dst)   \
530
0
  (cache_ptr)->howto =        \
531
0
    (dst)->r_type < NUM_RELOCS      \
532
0
    ? aoutarm_std_reloc_howto + (dst)->r_type  \
533
0
    : NULL
534
535
0
#define coff_rtype_to_howto coff_arm_rtype_to_howto
536
537
static reloc_howto_type *
538
coff_arm_rtype_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
539
       asection *sec,
540
       struct internal_reloc *rel,
541
       struct coff_link_hash_entry *h ATTRIBUTE_UNUSED,
542
       struct internal_syment *sym ATTRIBUTE_UNUSED,
543
       bfd_vma *addendp)
544
0
{
545
0
  reloc_howto_type * howto;
546
547
0
  if (rel->r_type >= NUM_RELOCS)
548
0
    return NULL;
549
550
0
  howto = aoutarm_std_reloc_howto + rel->r_type;
551
552
0
  if (rel->r_type == ARM_RVA32)
553
0
    *addendp -= pe_data (sec->output_section->owner)->pe_opthdr.ImageBase;
554
555
#if defined COFF_WITH_PE && defined ARM_WINCE
556
  if (rel->r_type == ARM_SECREL)
557
    {
558
      bfd_vma osect_vma;
559
560
      if (h && (h->type == bfd_link_hash_defined
561
    || h->type == bfd_link_hash_defweak))
562
  osect_vma = h->root.u.def.section->output_section->vma;
563
      else
564
  {
565
    int i;
566
567
    /* Sigh, the only way to get the section to offset against
568
       is to find it the hard way.  */
569
570
    for (sec = abfd->sections, i = 1; i < sym->n_scnum; i++)
571
      sec = sec->next;
572
573
    osect_vma = sec->output_section->vma;
574
  }
575
576
      *addendp -= osect_vma;
577
    }
578
#endif
579
580
0
  return howto;
581
0
}
Unexecuted instantiation: pe-arm-wince.c:coff_arm_rtype_to_howto
Unexecuted instantiation: pe-arm.c:coff_arm_rtype_to_howto
Unexecuted instantiation: pei-arm-wince.c:coff_arm_rtype_to_howto
Unexecuted instantiation: pei-arm.c:coff_arm_rtype_to_howto
582
583
/* Used by the assembler.  */
584
585
static bfd_reloc_status_type
586
aoutarm_fix_pcrel_26_done (bfd *abfd ATTRIBUTE_UNUSED,
587
         arelent *reloc_entry ATTRIBUTE_UNUSED,
588
         asymbol *symbol ATTRIBUTE_UNUSED,
589
         void * data ATTRIBUTE_UNUSED,
590
         asection *input_section ATTRIBUTE_UNUSED,
591
         bfd *output_bfd ATTRIBUTE_UNUSED,
592
         char **error_message ATTRIBUTE_UNUSED)
593
0
{
594
  /* This is dead simple at present.  */
595
0
  return bfd_reloc_ok;
596
0
}
Unexecuted instantiation: pe-arm-wince.c:aoutarm_fix_pcrel_26_done
Unexecuted instantiation: pe-arm.c:aoutarm_fix_pcrel_26_done
Unexecuted instantiation: pei-arm-wince.c:aoutarm_fix_pcrel_26_done
Unexecuted instantiation: pei-arm.c:aoutarm_fix_pcrel_26_done
597
598
/* Used by the assembler.  */
599
600
static bfd_reloc_status_type
601
aoutarm_fix_pcrel_26 (bfd *abfd,
602
          arelent *reloc_entry,
603
          asymbol *symbol,
604
          void * data,
605
          asection *input_section,
606
          bfd *output_bfd,
607
          char **error_message ATTRIBUTE_UNUSED)
608
0
{
609
0
  bfd_vma relocation;
610
0
  bfd_size_type addr = reloc_entry->address;
611
0
  long target;
612
0
  bfd_reloc_status_type flag = bfd_reloc_ok;
613
614
  /* If this is an undefined symbol, return error.  */
615
0
  if (bfd_is_und_section (symbol->section)
616
0
      && (symbol->flags & BSF_WEAK) == 0)
617
0
    return output_bfd ? bfd_reloc_continue : bfd_reloc_undefined;
618
619
  /* If the sections are different, and we are doing a partial relocation,
620
     just ignore it for now.  */
621
0
  if (symbol->section->name != input_section->name
622
0
      && output_bfd != NULL)
623
0
    return bfd_reloc_continue;
624
625
0
  if (!bfd_reloc_offset_in_range (reloc_entry->howto, abfd,
626
0
          input_section, addr))
627
0
    return bfd_reloc_outofrange;
628
629
0
  target = bfd_get_32 (abfd, (bfd_byte *) data + addr);
630
0
  relocation = (target & 0x00ffffff) << 2;
631
0
  relocation = (relocation ^ 0x02000000) - 0x02000000; /* Sign extend.  */
632
0
  relocation += symbol->value;
633
0
  relocation += symbol->section->output_section->vma;
634
0
  relocation += symbol->section->output_offset;
635
0
  relocation += reloc_entry->addend;
636
0
  relocation -= input_section->output_section->vma;
637
0
  relocation -= input_section->output_offset;
638
0
  relocation -= addr;
639
640
0
  if (relocation & 3)
641
0
    return bfd_reloc_overflow;
642
643
  /* Check for overflow.  */
644
0
  if (relocation & 0x02000000)
645
0
    {
646
0
      if ((relocation & ~ (bfd_vma) 0x03ffffff) != ~ (bfd_vma) 0x03ffffff)
647
0
  flag = bfd_reloc_overflow;
648
0
    }
649
0
  else if (relocation & ~(bfd_vma) 0x03ffffff)
650
0
    flag = bfd_reloc_overflow;
651
652
0
  target &= ~0x00ffffff;
653
0
  target |= (relocation >> 2) & 0x00ffffff;
654
0
  bfd_put_32 (abfd, (bfd_vma) target, (bfd_byte *) data + addr);
655
656
  /* Now the ARM magic... Change the reloc type so that it is marked as done.
657
     Strictly this is only necessary if we are doing a partial relocation.  */
658
0
  reloc_entry->howto = &aoutarm_std_reloc_howto[ARM_26D];
659
660
0
  return flag;
661
0
}
Unexecuted instantiation: pe-arm-wince.c:aoutarm_fix_pcrel_26
Unexecuted instantiation: pe-arm.c:aoutarm_fix_pcrel_26
Unexecuted instantiation: pei-arm-wince.c:aoutarm_fix_pcrel_26
Unexecuted instantiation: pei-arm.c:aoutarm_fix_pcrel_26
662
663
static bfd_reloc_status_type
664
coff_thumb_pcrel_common (bfd *abfd,
665
       arelent *reloc_entry,
666
       asymbol *symbol,
667
       void * data,
668
       asection *input_section,
669
       bfd *output_bfd,
670
       char **error_message ATTRIBUTE_UNUSED,
671
       thumb_pcrel_branchtype btype)
672
0
{
673
0
  bfd_vma relocation = 0;
674
0
  bfd_size_type addr = reloc_entry->address;
675
0
  long target;
676
0
  bfd_reloc_status_type flag = bfd_reloc_ok;
677
0
  bfd_vma dstmsk;
678
0
  bfd_vma offmsk;
679
0
  bfd_vma signbit;
680
681
  /* NOTE: This routine is currently used by GAS, but not by the link
682
     phase.  */
683
0
  switch (btype)
684
0
    {
685
0
    case b9:
686
0
      dstmsk  = 0x000000ff;
687
0
      offmsk  = 0x000001fe;
688
0
      signbit = 0x00000100;
689
0
      break;
690
691
0
    case b12:
692
0
      dstmsk  = 0x000007ff;
693
0
      offmsk  = 0x00000ffe;
694
0
      signbit = 0x00000800;
695
0
      break;
696
697
0
    case b23:
698
0
      dstmsk  = 0x07ff07ff;
699
0
      offmsk  = 0x007fffff;
700
0
      signbit = 0x00400000;
701
0
      break;
702
703
0
    default:
704
0
      abort ();
705
0
    }
706
707
  /* If this is an undefined symbol, return error.  */
708
0
  if (bfd_is_und_section (symbol->section)
709
0
      && (symbol->flags & BSF_WEAK) == 0)
710
0
    return output_bfd ? bfd_reloc_continue : bfd_reloc_undefined;
711
712
  /* If the sections are different, and we are doing a partial relocation,
713
     just ignore it for now.  */
714
0
  if (symbol->section->name != input_section->name
715
0
      && output_bfd != NULL)
716
0
    return bfd_reloc_continue;
717
718
0
  if (!bfd_reloc_offset_in_range (reloc_entry->howto, abfd,
719
0
          input_section, addr))
720
0
    return bfd_reloc_outofrange;
721
722
0
  target = bfd_get_32 (abfd, (bfd_byte *) data + addr);
723
724
0
  switch (btype)
725
0
    {
726
0
    case b9:
727
0
    case b12:
728
0
      relocation = ((target & dstmsk) << 1);
729
0
      break;
730
731
0
    case b23:
732
0
      if (bfd_big_endian (abfd))
733
0
  relocation = ((target & 0x7ff) << 1)  | ((target & 0x07ff0000) >> 4);
734
0
      else
735
0
  relocation = ((target & 0x7ff) << 12) | ((target & 0x07ff0000) >> 15);
736
0
      break;
737
738
0
    default:
739
0
      abort ();
740
0
    }
741
742
0
  relocation = (relocation ^ signbit) - signbit; /* Sign extend.  */
743
0
  relocation += symbol->value;
744
0
  relocation += symbol->section->output_section->vma;
745
0
  relocation += symbol->section->output_offset;
746
0
  relocation += reloc_entry->addend;
747
0
  relocation -= input_section->output_section->vma;
748
0
  relocation -= input_section->output_offset;
749
0
  relocation -= addr;
750
751
0
  if (relocation & 1)
752
0
    return bfd_reloc_overflow;
753
754
  /* Check for overflow.  */
755
0
  if (relocation & signbit)
756
0
    {
757
0
      if ((relocation & ~offmsk) != ~offmsk)
758
0
  flag = bfd_reloc_overflow;
759
0
    }
760
0
  else if (relocation & ~offmsk)
761
0
    flag = bfd_reloc_overflow;
762
763
0
  target &= ~dstmsk;
764
0
  switch (btype)
765
0
   {
766
0
   case b9:
767
0
   case b12:
768
0
     target |= (relocation >> 1);
769
0
     break;
770
771
0
   case b23:
772
0
     if (bfd_big_endian (abfd))
773
0
       target |= (((relocation & 0xfff) >> 1)
774
0
      | ((relocation << 4)  & 0x07ff0000));
775
0
     else
776
0
       target |= (((relocation & 0xffe) << 15)
777
0
      | ((relocation >> 12) & 0x7ff));
778
0
     break;
779
780
0
   default:
781
0
     abort ();
782
0
   }
783
784
0
  bfd_put_32 (abfd, (bfd_vma) target, (bfd_byte *) data + addr);
785
786
  /* Now the ARM magic... Change the reloc type so that it is marked as done.
787
     Strictly this is only necessary if we are doing a partial relocation.  */
788
0
  reloc_entry->howto = & aoutarm_std_reloc_howto [ARM_26D];
789
790
  /* TODO: We should possibly have DONE entries for the THUMB PCREL relocations.  */
791
0
  return flag;
792
0
}
Unexecuted instantiation: pe-arm-wince.c:coff_thumb_pcrel_common
Unexecuted instantiation: pe-arm.c:coff_thumb_pcrel_common
Unexecuted instantiation: pei-arm-wince.c:coff_thumb_pcrel_common
Unexecuted instantiation: pei-arm.c:coff_thumb_pcrel_common
793
794
#ifndef ARM_WINCE
795
static bfd_reloc_status_type
796
coff_thumb_pcrel_23 (bfd *abfd,
797
         arelent *reloc_entry,
798
         asymbol *symbol,
799
         void * data,
800
         asection *input_section,
801
         bfd *output_bfd,
802
         char **error_message)
803
0
{
804
0
  return coff_thumb_pcrel_common (abfd, reloc_entry, symbol, data,
805
0
          input_section, output_bfd, error_message,
806
0
          b23);
807
0
}
Unexecuted instantiation: pe-arm-wince.c:coff_thumb_pcrel_23
Unexecuted instantiation: pe-arm.c:coff_thumb_pcrel_23
Unexecuted instantiation: pei-arm-wince.c:coff_thumb_pcrel_23
Unexecuted instantiation: pei-arm.c:coff_thumb_pcrel_23
808
809
static bfd_reloc_status_type
810
coff_thumb_pcrel_9 (bfd *abfd,
811
        arelent *reloc_entry,
812
        asymbol *symbol,
813
        void * data,
814
        asection *input_section,
815
        bfd *output_bfd,
816
        char **error_message)
817
0
{
818
0
  return coff_thumb_pcrel_common (abfd, reloc_entry, symbol, data,
819
0
          input_section, output_bfd, error_message,
820
0
          b9);
821
0
}
Unexecuted instantiation: pe-arm-wince.c:coff_thumb_pcrel_9
Unexecuted instantiation: pe-arm.c:coff_thumb_pcrel_9
Unexecuted instantiation: pei-arm-wince.c:coff_thumb_pcrel_9
Unexecuted instantiation: pei-arm.c:coff_thumb_pcrel_9
822
#endif /* not ARM_WINCE */
823
824
static bfd_reloc_status_type
825
coff_thumb_pcrel_12 (bfd *abfd,
826
         arelent *reloc_entry,
827
         asymbol *symbol,
828
         void * data,
829
         asection *input_section,
830
         bfd *output_bfd,
831
         char **error_message)
832
0
{
833
0
  return coff_thumb_pcrel_common (abfd, reloc_entry, symbol, data,
834
0
          input_section, output_bfd, error_message,
835
0
          b12);
836
0
}
Unexecuted instantiation: pe-arm-wince.c:coff_thumb_pcrel_12
Unexecuted instantiation: pe-arm.c:coff_thumb_pcrel_12
Unexecuted instantiation: pei-arm-wince.c:coff_thumb_pcrel_12
Unexecuted instantiation: pei-arm.c:coff_thumb_pcrel_12
837
838
static reloc_howto_type *
839
coff_arm_reloc_type_lookup (bfd * abfd, bfd_reloc_code_real_type code)
840
324
{
841
324
#define ASTD(i,j)       case i: return aoutarm_std_reloc_howto + j
842
843
324
  if (code == BFD_RELOC_CTOR)
844
0
    switch (bfd_arch_bits_per_address (abfd))
845
0
      {
846
0
      case 32:
847
0
  code = BFD_RELOC_32;
848
0
  break;
849
0
      default:
850
0
  return NULL;
851
0
      }
852
853
324
  switch (code)
854
324
    {
855
#ifdef ARM_WINCE
856
      ASTD (BFD_RELOC_32,       ARM_32);
857
      ASTD (BFD_RELOC_RVA,        ARM_RVA32);
858
      ASTD (BFD_RELOC_ARM_PCREL_BRANCH,     ARM_26);
859
      ASTD (BFD_RELOC_THUMB_PCREL_BRANCH12, ARM_THUMB12);
860
      ASTD (BFD_RELOC_32_SECREL,      ARM_SECREL);
861
#else
862
0
      ASTD (BFD_RELOC_8,        ARM_8);
863
0
      ASTD (BFD_RELOC_16,       ARM_16);
864
84
      ASTD (BFD_RELOC_32,       ARM_32);
865
0
      ASTD (BFD_RELOC_ARM_PCREL_BRANCH,     ARM_26);
866
0
      ASTD (BFD_RELOC_ARM_PCREL_BLX,      ARM_26);
867
0
      ASTD (BFD_RELOC_8_PCREL,        ARM_DISP8);
868
0
      ASTD (BFD_RELOC_16_PCREL,       ARM_DISP16);
869
0
      ASTD (BFD_RELOC_32_PCREL,       ARM_DISP32);
870
240
      ASTD (BFD_RELOC_RVA,        ARM_RVA32);
871
0
      ASTD (BFD_RELOC_THUMB_PCREL_BRANCH9,  ARM_THUMB9);
872
0
      ASTD (BFD_RELOC_THUMB_PCREL_BRANCH12, ARM_THUMB12);
873
0
      ASTD (BFD_RELOC_THUMB_PCREL_BRANCH23, ARM_THUMB23);
874
0
      ASTD (BFD_RELOC_THUMB_PCREL_BLX,      ARM_THUMB23);
875
0
#endif
876
0
    default: return NULL;
877
324
    }
878
324
}
Unexecuted instantiation: pe-arm-wince.c:coff_arm_reloc_type_lookup
Unexecuted instantiation: pe-arm.c:coff_arm_reloc_type_lookup
pei-arm-wince.c:coff_arm_reloc_type_lookup
Line
Count
Source
840
158
{
841
158
#define ASTD(i,j)       case i: return aoutarm_std_reloc_howto + j
842
843
158
  if (code == BFD_RELOC_CTOR)
844
0
    switch (bfd_arch_bits_per_address (abfd))
845
0
      {
846
0
      case 32:
847
0
  code = BFD_RELOC_32;
848
0
  break;
849
0
      default:
850
0
  return NULL;
851
0
      }
852
853
158
  switch (code)
854
158
    {
855
#ifdef ARM_WINCE
856
      ASTD (BFD_RELOC_32,       ARM_32);
857
      ASTD (BFD_RELOC_RVA,        ARM_RVA32);
858
      ASTD (BFD_RELOC_ARM_PCREL_BRANCH,     ARM_26);
859
      ASTD (BFD_RELOC_THUMB_PCREL_BRANCH12, ARM_THUMB12);
860
      ASTD (BFD_RELOC_32_SECREL,      ARM_SECREL);
861
#else
862
0
      ASTD (BFD_RELOC_8,        ARM_8);
863
0
      ASTD (BFD_RELOC_16,       ARM_16);
864
40
      ASTD (BFD_RELOC_32,       ARM_32);
865
0
      ASTD (BFD_RELOC_ARM_PCREL_BRANCH,     ARM_26);
866
0
      ASTD (BFD_RELOC_ARM_PCREL_BLX,      ARM_26);
867
0
      ASTD (BFD_RELOC_8_PCREL,        ARM_DISP8);
868
0
      ASTD (BFD_RELOC_16_PCREL,       ARM_DISP16);
869
0
      ASTD (BFD_RELOC_32_PCREL,       ARM_DISP32);
870
118
      ASTD (BFD_RELOC_RVA,        ARM_RVA32);
871
0
      ASTD (BFD_RELOC_THUMB_PCREL_BRANCH9,  ARM_THUMB9);
872
0
      ASTD (BFD_RELOC_THUMB_PCREL_BRANCH12, ARM_THUMB12);
873
0
      ASTD (BFD_RELOC_THUMB_PCREL_BRANCH23, ARM_THUMB23);
874
0
      ASTD (BFD_RELOC_THUMB_PCREL_BLX,      ARM_THUMB23);
875
0
#endif
876
0
    default: return NULL;
877
158
    }
878
158
}
pei-arm.c:coff_arm_reloc_type_lookup
Line
Count
Source
840
166
{
841
166
#define ASTD(i,j)       case i: return aoutarm_std_reloc_howto + j
842
843
166
  if (code == BFD_RELOC_CTOR)
844
0
    switch (bfd_arch_bits_per_address (abfd))
845
0
      {
846
0
      case 32:
847
0
  code = BFD_RELOC_32;
848
0
  break;
849
0
      default:
850
0
  return NULL;
851
0
      }
852
853
166
  switch (code)
854
166
    {
855
#ifdef ARM_WINCE
856
      ASTD (BFD_RELOC_32,       ARM_32);
857
      ASTD (BFD_RELOC_RVA,        ARM_RVA32);
858
      ASTD (BFD_RELOC_ARM_PCREL_BRANCH,     ARM_26);
859
      ASTD (BFD_RELOC_THUMB_PCREL_BRANCH12, ARM_THUMB12);
860
      ASTD (BFD_RELOC_32_SECREL,      ARM_SECREL);
861
#else
862
0
      ASTD (BFD_RELOC_8,        ARM_8);
863
0
      ASTD (BFD_RELOC_16,       ARM_16);
864
44
      ASTD (BFD_RELOC_32,       ARM_32);
865
0
      ASTD (BFD_RELOC_ARM_PCREL_BRANCH,     ARM_26);
866
0
      ASTD (BFD_RELOC_ARM_PCREL_BLX,      ARM_26);
867
0
      ASTD (BFD_RELOC_8_PCREL,        ARM_DISP8);
868
0
      ASTD (BFD_RELOC_16_PCREL,       ARM_DISP16);
869
0
      ASTD (BFD_RELOC_32_PCREL,       ARM_DISP32);
870
122
      ASTD (BFD_RELOC_RVA,        ARM_RVA32);
871
0
      ASTD (BFD_RELOC_THUMB_PCREL_BRANCH9,  ARM_THUMB9);
872
0
      ASTD (BFD_RELOC_THUMB_PCREL_BRANCH12, ARM_THUMB12);
873
0
      ASTD (BFD_RELOC_THUMB_PCREL_BRANCH23, ARM_THUMB23);
874
0
      ASTD (BFD_RELOC_THUMB_PCREL_BLX,      ARM_THUMB23);
875
0
#endif
876
0
    default: return NULL;
877
166
    }
878
166
}
879
880
static reloc_howto_type *
881
coff_arm_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
882
          const char *r_name)
883
0
{
884
0
  unsigned int i;
885
886
0
  for (i = 0;
887
0
       i < (sizeof (aoutarm_std_reloc_howto)
888
0
      / sizeof (aoutarm_std_reloc_howto[0]));
889
0
       i++)
890
0
    if (aoutarm_std_reloc_howto[i].name != NULL
891
0
  && strcasecmp (aoutarm_std_reloc_howto[i].name, r_name) == 0)
892
0
      return &aoutarm_std_reloc_howto[i];
893
894
0
  return NULL;
895
0
}
Unexecuted instantiation: pe-arm-wince.c:coff_arm_reloc_name_lookup
Unexecuted instantiation: pe-arm.c:coff_arm_reloc_name_lookup
Unexecuted instantiation: pei-arm-wince.c:coff_arm_reloc_name_lookup
Unexecuted instantiation: pei-arm.c:coff_arm_reloc_name_lookup
896
897
317k
#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER  2
898
384
#define COFF_PAGE_SIZE            0x1000
899
900
/* Turn a howto into a reloc  nunmber.  */
901
3
#define SELECT_RELOC(x,howto) { x.r_type = howto->type; }
902
858k
#define BADMAG(x)       ARMBADMAG(x)
903
#define ARM         1     /* Customize coffcode.h.  */
904
905
#ifndef ARM_WINCE
906
/* Make sure that the 'r_offset' field is copied properly
907
   so that identical binaries will compare the same.  */
908
12.3k
#define SWAP_IN_RELOC_OFFSET  H_GET_32
909
3
#define SWAP_OUT_RELOC_OFFSET H_PUT_32
910
#endif
911
912
/* Extend the coff_link_hash_table structure with a few ARM specific fields.
913
   This allows us to store global data here without actually creating any
914
   global variables, which is a no-no in the BFD world.  */
915
struct coff_arm_link_hash_table
916
  {
917
    /* The original coff_link_hash_table structure.  MUST be first field.  */
918
    struct coff_link_hash_table root;
919
920
    /* The size in bytes of the section containing the Thumb-to-ARM glue.  */
921
    bfd_size_type   thumb_glue_size;
922
923
    /* The size in bytes of the section containing the ARM-to-Thumb glue.  */
924
    bfd_size_type   arm_glue_size;
925
926
    /* An arbitrary input BFD chosen to hold the glue sections.  */
927
    bfd *     bfd_of_glue_owner;
928
929
    /* Support interworking with old, non-interworking aware ARM code.  */
930
    int       support_old_code;
931
};
932
933
/* Get the ARM coff linker hash table from a link_info structure.  */
934
#define coff_arm_hash_table(info) \
935
0
  ((struct coff_arm_link_hash_table *) ((info)->hash))
936
937
/* Create an ARM coff linker hash table.  */
938
939
static struct bfd_link_hash_table *
940
coff_arm_link_hash_table_create (bfd * abfd)
941
0
{
942
0
  struct coff_arm_link_hash_table * ret;
943
0
  size_t amt = sizeof (struct coff_arm_link_hash_table);
944
945
0
  ret = bfd_zmalloc (amt);
946
0
  if (ret == NULL)
947
0
    return NULL;
948
949
0
  if (!_bfd_coff_link_hash_table_init (&ret->root,
950
0
               abfd,
951
0
               _bfd_coff_link_hash_newfunc,
952
0
               sizeof (struct coff_link_hash_entry)))
953
0
    {
954
0
      free (ret);
955
0
      return NULL;
956
0
    }
957
958
0
  return & ret->root.root;
959
0
}
Unexecuted instantiation: pe-arm-wince.c:coff_arm_link_hash_table_create
Unexecuted instantiation: pe-arm.c:coff_arm_link_hash_table_create
Unexecuted instantiation: pei-arm-wince.c:coff_arm_link_hash_table_create
Unexecuted instantiation: pei-arm.c:coff_arm_link_hash_table_create
960
961
static bool
962
arm_emit_base_file_entry (struct bfd_link_info *info,
963
        bfd *output_bfd,
964
        asection *input_section,
965
        bfd_vma reloc_offset)
966
0
{
967
0
  bfd_vma addr = (reloc_offset
968
0
      - input_section->vma
969
0
      + input_section->output_offset
970
0
      + input_section->output_section->vma);
971
972
0
  if (obj_pe (output_bfd))
973
0
     addr -= pe_data (output_bfd)->pe_opthdr.ImageBase;
974
0
  if (fwrite (&addr, sizeof (addr), 1, (FILE *) info->base_file) == 1)
975
0
    return true;
976
977
0
  bfd_set_error (bfd_error_system_call);
978
0
  return false;
979
0
}
Unexecuted instantiation: pe-arm-wince.c:arm_emit_base_file_entry
Unexecuted instantiation: pe-arm.c:arm_emit_base_file_entry
Unexecuted instantiation: pei-arm-wince.c:arm_emit_base_file_entry
Unexecuted instantiation: pei-arm.c:arm_emit_base_file_entry
980

981
#ifndef ARM_WINCE
982
/* The thumb form of a long branch is a bit finicky, because the offset
983
   encoding is split over two fields, each in it's own instruction. They
984
   can occur in any order. So given a thumb form of long branch, and an
985
   offset, insert the offset into the thumb branch and return finished
986
   instruction.
987
988
   It takes two thumb instructions to encode the target address. Each has
989
   11 bits to invest. The upper 11 bits are stored in one (identified by
990
   H-0.. see below), the lower 11 bits are stored in the other (identified
991
   by H-1).
992
993
   Combine together and shifted left by 1 (it's a half word address) and
994
   there you have it.
995
996
     Op: 1111 = F,
997
     H-0, upper address-0 = 000
998
     Op: 1111 = F,
999
     H-1, lower address-0 = 800
1000
1001
   They can be ordered either way, but the arm tools I've seen always put
1002
   the lower one first. It probably doesn't matter. krk@cygnus.com
1003
1004
   XXX:  Actually the order does matter.  The second instruction (H-1)
1005
   moves the computed address into the PC, so it must be the second one
1006
   in the sequence.  The problem, however is that whilst little endian code
1007
   stores the instructions in HI then LOW order, big endian code does the
1008
   reverse.  nickc@cygnus.com.  */
1009
1010
0
#define LOW_HI_ORDER 0xF800F000
1011
0
#define HI_LOW_ORDER 0xF000F800
1012
1013
static insn32
1014
insert_thumb_branch (insn32 br_insn, int rel_off)
1015
0
{
1016
0
  unsigned int low_bits;
1017
0
  unsigned int high_bits;
1018
1019
0
  BFD_ASSERT ((rel_off & 1) != 1);
1020
1021
0
  rel_off >>= 1;            /* Half word aligned address.  */
1022
0
  low_bits = rel_off & 0x000007FF;        /* The bottom 11 bits.  */
1023
0
  high_bits = (rel_off >> 11) & 0x000007FF;   /* The top 11 bits.  */
1024
1025
0
  if ((br_insn & LOW_HI_ORDER) == LOW_HI_ORDER)
1026
0
    br_insn = LOW_HI_ORDER | (low_bits << 16) | high_bits;
1027
0
  else if ((br_insn & HI_LOW_ORDER) == HI_LOW_ORDER)
1028
0
    br_insn = HI_LOW_ORDER | (high_bits << 16) | low_bits;
1029
0
  else
1030
    /* FIXME: the BFD library should never abort except for internal errors
1031
       - it should return an error status.  */
1032
0
    abort (); /* Error - not a valid branch instruction form.  */
1033
1034
0
  return br_insn;
1035
0
}
Unexecuted instantiation: pe-arm-wince.c:insert_thumb_branch
Unexecuted instantiation: pe-arm.c:insert_thumb_branch
Unexecuted instantiation: pei-arm-wince.c:insert_thumb_branch
Unexecuted instantiation: pei-arm.c:insert_thumb_branch
1036
1037

1038
static struct coff_link_hash_entry *
1039
find_thumb_glue (struct bfd_link_info *info,
1040
     const char *name,
1041
     bfd *input_bfd)
1042
0
{
1043
0
  char *tmp_name;
1044
0
  struct coff_link_hash_entry *myh;
1045
0
  size_t amt = strlen (name) + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1;
1046
1047
0
  tmp_name = bfd_malloc (amt);
1048
1049
0
  BFD_ASSERT (tmp_name);
1050
1051
0
  sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
1052
1053
0
  myh = coff_link_hash_lookup
1054
0
    (coff_hash_table (info), tmp_name, false, false, true);
1055
1056
0
  if (myh == NULL)
1057
    /* xgettext:c-format */
1058
0
    _bfd_error_handler (_("%pB: unable to find THUMB glue '%s' for `%s'"),
1059
0
      input_bfd, tmp_name, name);
1060
1061
0
  free (tmp_name);
1062
1063
0
  return myh;
1064
0
}
Unexecuted instantiation: pe-arm-wince.c:find_thumb_glue
Unexecuted instantiation: pe-arm.c:find_thumb_glue
Unexecuted instantiation: pei-arm-wince.c:find_thumb_glue
Unexecuted instantiation: pei-arm.c:find_thumb_glue
1065
#endif /* not ARM_WINCE */
1066
1067
static struct coff_link_hash_entry *
1068
find_arm_glue (struct bfd_link_info *info,
1069
         const char *name,
1070
         bfd *input_bfd)
1071
0
{
1072
0
  char *tmp_name;
1073
0
  struct coff_link_hash_entry * myh;
1074
0
  size_t amt = strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1;
1075
1076
0
  tmp_name = bfd_malloc (amt);
1077
1078
0
  BFD_ASSERT (tmp_name);
1079
1080
0
  sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
1081
1082
0
  myh = coff_link_hash_lookup
1083
0
    (coff_hash_table (info), tmp_name, false, false, true);
1084
1085
0
  if (myh == NULL)
1086
    /* xgettext:c-format */
1087
0
    _bfd_error_handler (_("%pB: unable to find ARM glue '%s' for `%s'"),
1088
0
      input_bfd, tmp_name, name);
1089
1090
0
  free (tmp_name);
1091
1092
0
  return myh;
1093
0
}
Unexecuted instantiation: pe-arm-wince.c:find_arm_glue
Unexecuted instantiation: pe-arm.c:find_arm_glue
Unexecuted instantiation: pei-arm-wince.c:find_arm_glue
Unexecuted instantiation: pei-arm.c:find_arm_glue
1094
1095
/*
1096
  ARM->Thumb glue:
1097
1098
       .arm
1099
       __func_from_arm:
1100
       ldr r12, __func_addr
1101
       bx  r12
1102
       __func_addr:
1103
      .word func    @ behave as if you saw a ARM_32 reloc
1104
*/
1105
1106
0
#define ARM2THUMB_GLUE_SIZE 12
1107
static const insn32 a2t1_ldr_insn       = 0xe59fc000;
1108
static const insn32 a2t2_bx_r12_insn    = 0xe12fff1c;
1109
static const insn32 a2t3_func_addr_insn = 0x00000001;
1110
1111
/*
1112
   Thumb->ARM:        Thumb->(non-interworking aware) ARM
1113
1114
   .thumb       .thumb
1115
   .align 2       .align 2
1116
      __func_from_thumb:       __func_from_thumb:
1117
     bx pc        push {r6, lr}
1118
     nop          ldr  r6, __func_addr
1119
   .arm           mov  lr, pc
1120
      __func_change_to_arm:     bx   r6
1121
     b func     .arm
1122
             __func_back_to_thumb:
1123
            ldmia r13! {r6, lr}
1124
            bx    lr
1125
             __func_addr:
1126
            .word func
1127
*/
1128
1129
0
#define THUMB2ARM_GLUE_SIZE (globals->support_old_code ? 20 : 8)
1130
#ifndef ARM_WINCE
1131
static const insn16 t2a1_bx_pc_insn = 0x4778;
1132
static const insn16 t2a2_noop_insn  = 0x46c0;
1133
static const insn32 t2a3_b_insn     = 0xea000000;
1134
1135
static const insn16 t2a1_push_insn  = 0xb540;
1136
static const insn16 t2a2_ldr_insn   = 0x4e03;
1137
static const insn16 t2a3_mov_insn   = 0x46fe;
1138
static const insn16 t2a4_bx_insn    = 0x4730;
1139
static const insn32 t2a5_pop_insn   = 0xe8bd4040;
1140
static const insn32 t2a6_bx_insn    = 0xe12fff1e;
1141
#endif
1142
1143
/* TODO:
1144
     We should really create new local (static) symbols in destination
1145
     object for each stub we create.  We should also create local
1146
     (static) symbols within the stubs when switching between ARM and
1147
     Thumb code.  This will ensure that the debugger and disassembler
1148
     can present a better view of stubs.
1149
1150
     We can treat stubs like literal sections, and for the THUMB9 ones
1151
     (short addressing range) we should be able to insert the stubs
1152
     between sections. i.e. the simplest approach (since relocations
1153
     are done on a section basis) is to dump the stubs at the end of
1154
     processing a section. That way we can always try and minimise the
1155
     offset to and from a stub. However, this does not map well onto
1156
     the way that the linker/BFD does its work: mapping all input
1157
     sections to output sections via the linker script before doing
1158
     all the processing.
1159
1160
     Unfortunately it may be easier to just to disallow short range
1161
     Thumb->ARM stubs (i.e. no conditional inter-working branches,
1162
     only branch-and-link (BL) calls.  This will simplify the processing
1163
     since we can then put all of the stubs into their own section.
1164
1165
  TODO:
1166
     On a different subject, rather than complaining when a
1167
     branch cannot fit in the number of bits available for the
1168
     instruction we should generate a trampoline stub (needed to
1169
     address the complete 32bit address space).  */
1170
1171
/* The standard COFF backend linker does not cope with the special
1172
   Thumb BRANCH23 relocation.  The alternative would be to split the
1173
   BRANCH23 into separate HI23 and LO23 relocations. However, it is a
1174
   bit simpler simply providing our own relocation driver.  */
1175
1176
/* The reloc processing routine for the ARM/Thumb COFF linker.  NOTE:
1177
   This code is a very slightly modified copy of
1178
   _bfd_coff_generic_relocate_section.  It would be a much more
1179
   maintainable solution to have a MACRO that could be expanded within
1180
   _bfd_coff_generic_relocate_section that would only be provided for
1181
   ARM/Thumb builds.  It is only the code marked THUMBEXTENSION that
1182
   is different from the original.  */
1183
1184
static bool
1185
coff_arm_relocate_section (bfd *output_bfd,
1186
         struct bfd_link_info *info,
1187
         bfd *input_bfd,
1188
         asection *input_section,
1189
         bfd_byte *contents,
1190
         struct internal_reloc *relocs,
1191
         struct internal_syment *syms,
1192
         asection **sections)
1193
0
{
1194
0
  struct internal_reloc * rel;
1195
0
  struct internal_reloc * relend;
1196
0
#ifndef ARM_WINCE
1197
0
  bfd_vma high_address = bfd_get_section_limit (input_bfd, input_section);
1198
0
#endif
1199
1200
0
  rel = relocs;
1201
0
  relend = rel + input_section->reloc_count;
1202
1203
0
  for (; rel < relend; rel++)
1204
0
    {
1205
0
      int          done = 0;
1206
0
      long           symndx;
1207
0
      struct coff_link_hash_entry *  h;
1208
0
      struct internal_syment *       sym;
1209
0
      bfd_vma          addend;
1210
0
      bfd_vma          val;
1211
0
      reloc_howto_type *       howto;
1212
0
      bfd_reloc_status_type      rstat;
1213
0
      bfd_vma          h_val;
1214
1215
0
      symndx = rel->r_symndx;
1216
1217
0
      if (symndx == -1)
1218
0
  {
1219
0
    h = NULL;
1220
0
    sym = NULL;
1221
0
  }
1222
0
      else if (! coff_symndx_in_range (input_bfd, symndx))
1223
0
  {
1224
0
    _bfd_error_handler
1225
      /* xgettext: c-format */
1226
0
      (_("%pB: invalid symbol index %ld in relocs"),
1227
0
       input_bfd, symndx);
1228
0
    bfd_set_error (bfd_error_bad_value);
1229
0
    return false;
1230
0
  }
1231
0
      else
1232
0
  {
1233
0
    h = obj_coff_sym_hashes (input_bfd)[symndx];
1234
0
    sym = syms + symndx;
1235
0
  }
1236
1237
      /* COFF treats common symbols in one of two ways.  Either the
1238
   size of the symbol is included in the section contents, or it
1239
   is not.  We assume that the size is not included, and force
1240
   the rtype_to_howto function to adjust the addend as needed.  */
1241
1242
0
      if (sym != NULL && sym->n_scnum != 0)
1243
0
  addend = - sym->n_value;
1244
0
      else
1245
0
  addend = 0;
1246
1247
0
      howto = coff_rtype_to_howto (input_bfd, input_section, rel, h,
1248
0
               sym, &addend);
1249
0
      if (howto == NULL)
1250
0
  return false;
1251
1252
      /* The relocation_section function will skip pcrel_offset relocs
1253
   when doing a relocatable link.  However, we want to convert
1254
   ARM_26 to ARM_26D relocs if possible.  We return a fake howto in
1255
   this case without pcrel_offset set, and adjust the addend to
1256
   compensate.  'partial_inplace' is also set, since we want 'done'
1257
   relocations to be reflected in section's data.  */
1258
0
      if (rel->r_type == ARM_26
1259
0
    && h != NULL
1260
0
    && bfd_link_relocatable (info)
1261
0
    && (h->root.type == bfd_link_hash_defined
1262
0
        || h->root.type == bfd_link_hash_defweak)
1263
0
    && (h->root.u.def.section->output_section
1264
0
        == input_section->output_section))
1265
0
  {
1266
0
    static reloc_howto_type fake_arm26_reloc =
1267
0
      HOWTO (ARM_26,
1268
0
         2,
1269
0
         4,
1270
0
         24,
1271
0
         true,
1272
0
         0,
1273
0
         complain_overflow_signed,
1274
0
         aoutarm_fix_pcrel_26 ,
1275
0
         "ARM_26",
1276
0
         true,
1277
0
         0x00ffffff,
1278
0
         0x00ffffff,
1279
0
         false);
1280
1281
0
    addend -= rel->r_vaddr - input_section->vma;
1282
#ifdef ARM_WINCE
1283
    /* FIXME: I don't know why, but the hack is necessary for correct
1284
        generation of bl's instruction offset.  */
1285
    addend -= 8;
1286
#endif
1287
0
    howto = & fake_arm26_reloc;
1288
0
  }
1289
1290
#ifdef ARM_WINCE
1291
      /* MS ARM-CE makes the reloc relative to the opcode's pc, not
1292
   the next opcode's pc, so is off by one.  */
1293
      if (howto->pc_relative && !bfd_link_relocatable (info))
1294
  addend -= 8;
1295
#endif
1296
1297
      /* If we are doing a relocatable link, then we can just ignore
1298
   a PC relative reloc that is pcrel_offset.  It will already
1299
   have the correct value.  If this is not a relocatable link,
1300
   then we should ignore the symbol value.  */
1301
0
      if (howto->pc_relative && howto->pcrel_offset)
1302
0
  {
1303
0
    if (bfd_link_relocatable (info))
1304
0
      continue;
1305
    /* FIXME - it is not clear which targets need this next test
1306
       and which do not.  It is known that it is needed for the
1307
       VxWorks targets but it is also known that it was suppressed
1308
       for other ARM targets.  This ought to be sorted out one day.  */
1309
#ifdef ARM_COFF_BUGFIX
1310
    /* We must not ignore the symbol value.  If the symbol is
1311
       within the same section, the relocation should have already
1312
       been fixed, but if it is not, we'll be handed a reloc into
1313
       the beginning of the symbol's section, so we must not cancel
1314
       out the symbol's value, otherwise we'll be adding it in
1315
       twice.  */
1316
    if (sym != NULL && sym->n_scnum != 0)
1317
      addend += sym->n_value;
1318
#endif
1319
0
  }
1320
1321
0
      val = 0;
1322
1323
0
      if (h == NULL)
1324
0
  {
1325
0
    asection *sec;
1326
1327
0
    if (symndx == -1)
1328
0
      {
1329
0
        sec = bfd_abs_section_ptr;
1330
0
        val = 0;
1331
0
      }
1332
0
    else
1333
0
      {
1334
0
        sec = sections[symndx];
1335
0
        val = (sec->output_section->vma
1336
0
         + sec->output_offset
1337
0
         + sym->n_value
1338
0
         - sec->vma);
1339
0
      }
1340
0
  }
1341
0
      else
1342
0
  {
1343
    /* We don't output the stubs if we are generating a
1344
       relocatable output file, since we may as well leave the
1345
       stub generation to the final linker pass. If we fail to
1346
       verify that the name is defined, we'll try to build stubs
1347
       for an undefined name...  */
1348
0
    if (! bfd_link_relocatable (info)
1349
0
        && (   h->root.type == bfd_link_hash_defined
1350
0
      || h->root.type == bfd_link_hash_defweak))
1351
0
      {
1352
0
        asection *   h_sec = h->root.u.def.section;
1353
0
        const char * name  = h->root.root.string;
1354
1355
        /* h locates the symbol referenced in the reloc.  */
1356
0
        h_val = (h->root.u.def.value
1357
0
           + h_sec->output_section->vma
1358
0
           + h_sec->output_offset);
1359
1360
0
        if (howto->type == ARM_26)
1361
0
    {
1362
0
      if (   h->symbol_class == C_THUMBSTATFUNC
1363
0
          || h->symbol_class == C_THUMBEXTFUNC)
1364
0
        {
1365
          /* Arm code calling a Thumb function.  */
1366
0
          unsigned long int     tmp;
1367
0
          bfd_vma       my_offset;
1368
0
          asection *      s;
1369
0
          long int        ret_offset;
1370
0
          struct coff_link_hash_entry * myh;
1371
0
          struct coff_arm_link_hash_table * globals;
1372
1373
0
          myh = find_arm_glue (info, name, input_bfd);
1374
0
          if (myh == NULL)
1375
0
      return false;
1376
1377
0
          globals = coff_arm_hash_table (info);
1378
1379
0
          BFD_ASSERT (globals != NULL);
1380
0
          BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
1381
1382
0
          my_offset = myh->root.u.def.value;
1383
1384
0
          s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
1385
0
              ARM2THUMB_GLUE_SECTION_NAME);
1386
0
          BFD_ASSERT (s != NULL);
1387
0
          BFD_ASSERT (s->contents != NULL);
1388
0
          BFD_ASSERT (s->output_section != NULL);
1389
1390
0
          if ((my_offset & 0x01) == 0x01)
1391
0
      {
1392
0
        if (h_sec->owner != NULL
1393
0
            && INTERWORK_SET (h_sec->owner)
1394
0
            && ! INTERWORK_FLAG (h_sec->owner))
1395
0
          _bfd_error_handler
1396
            /* xgettext:c-format */
1397
0
            (_("%pB(%s): warning: interworking not enabled; "
1398
0
         "first occurrence: %pB: arm call to thumb"),
1399
0
             h_sec->owner, name, input_bfd);
1400
1401
0
        --my_offset;
1402
0
        myh->root.u.def.value = my_offset;
1403
1404
0
        bfd_put_32 (output_bfd, (bfd_vma) a2t1_ldr_insn,
1405
0
              s->contents + my_offset);
1406
1407
0
        bfd_put_32 (output_bfd, (bfd_vma) a2t2_bx_r12_insn,
1408
0
              s->contents + my_offset + 4);
1409
1410
        /* It's a thumb address.  Add the low order bit.  */
1411
0
        bfd_put_32 (output_bfd, h_val | a2t3_func_addr_insn,
1412
0
              s->contents + my_offset + 8);
1413
1414
0
        if (info->base_file
1415
0
            && !arm_emit_base_file_entry (info, output_bfd,
1416
0
                  s, my_offset + 8))
1417
0
          return false;
1418
0
      }
1419
1420
0
          BFD_ASSERT (my_offset <= globals->arm_glue_size);
1421
1422
0
          tmp = bfd_get_32 (input_bfd, contents + rel->r_vaddr
1423
0
          - input_section->vma);
1424
1425
0
          tmp = tmp & 0xFF000000;
1426
1427
          /* Somehow these are both 4 too far, so subtract 8.  */
1428
0
          ret_offset =
1429
0
      s->output_offset
1430
0
      + my_offset
1431
0
      + s->output_section->vma
1432
0
      - (input_section->output_offset
1433
0
         + input_section->output_section->vma
1434
0
         + rel->r_vaddr)
1435
0
      - 8;
1436
1437
0
          tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
1438
1439
0
          bfd_put_32 (output_bfd, (bfd_vma) tmp,
1440
0
          contents + rel->r_vaddr - input_section->vma);
1441
0
          done = 1;
1442
0
        }
1443
0
    }
1444
1445
0
#ifndef ARM_WINCE
1446
        /* Note: We used to check for ARM_THUMB9 and ARM_THUMB12.  */
1447
0
        else if (howto->type == ARM_THUMB23)
1448
0
    {
1449
0
      if (   h->symbol_class == C_EXT
1450
0
          || h->symbol_class == C_STAT
1451
0
          || h->symbol_class == C_LABEL)
1452
0
        {
1453
          /* Thumb code calling an ARM function.  */
1454
0
          asection *       s = 0;
1455
0
          bfd_vma        my_offset;
1456
0
          unsigned long int      tmp;
1457
0
          long int         ret_offset;
1458
0
          struct coff_link_hash_entry *  myh;
1459
0
          struct coff_arm_link_hash_table *  globals;
1460
1461
0
          myh = find_thumb_glue (info, name, input_bfd);
1462
0
          if (myh == NULL)
1463
0
      return false;
1464
1465
0
          globals = coff_arm_hash_table (info);
1466
1467
0
          BFD_ASSERT (globals != NULL);
1468
0
          BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
1469
1470
0
          my_offset = myh->root.u.def.value;
1471
1472
0
          s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
1473
0
               THUMB2ARM_GLUE_SECTION_NAME);
1474
1475
0
          BFD_ASSERT (s != NULL);
1476
0
          BFD_ASSERT (s->contents != NULL);
1477
0
          BFD_ASSERT (s->output_section != NULL);
1478
1479
0
          if ((my_offset & 0x01) == 0x01)
1480
0
      {
1481
0
        if (h_sec->owner != NULL
1482
0
            && INTERWORK_SET (h_sec->owner)
1483
0
            && ! INTERWORK_FLAG (h_sec->owner)
1484
0
            && ! globals->support_old_code)
1485
0
          _bfd_error_handler
1486
            /* xgettext:c-format */
1487
0
            (_("%pB(%s): warning: interworking not enabled; "
1488
0
         "first occurrence: %pB: thumb call to arm; "
1489
0
         "consider relinking with --support-old-code "
1490
0
         "enabled"),
1491
0
             h_sec->owner, name, input_bfd);
1492
1493
0
        -- my_offset;
1494
0
        myh->root.u.def.value = my_offset;
1495
1496
0
        if (globals->support_old_code)
1497
0
          {
1498
0
            bfd_put_16 (output_bfd, (bfd_vma) t2a1_push_insn,
1499
0
            s->contents + my_offset);
1500
1501
0
            bfd_put_16 (output_bfd, (bfd_vma) t2a2_ldr_insn,
1502
0
            s->contents + my_offset + 2);
1503
1504
0
            bfd_put_16 (output_bfd, (bfd_vma) t2a3_mov_insn,
1505
0
            s->contents + my_offset + 4);
1506
1507
0
            bfd_put_16 (output_bfd, (bfd_vma) t2a4_bx_insn,
1508
0
            s->contents + my_offset + 6);
1509
1510
0
            bfd_put_32 (output_bfd, (bfd_vma) t2a5_pop_insn,
1511
0
            s->contents + my_offset + 8);
1512
1513
0
            bfd_put_32 (output_bfd, (bfd_vma) t2a6_bx_insn,
1514
0
            s->contents + my_offset + 12);
1515
1516
            /* Store the address of the function in the last word of the stub.  */
1517
0
            bfd_put_32 (output_bfd, h_val,
1518
0
            s->contents + my_offset + 16);
1519
1520
0
            if (info->base_file
1521
0
          && !arm_emit_base_file_entry (info,
1522
0
                output_bfd, s,
1523
0
                my_offset + 16))
1524
0
        return false;
1525
0
          }
1526
0
        else
1527
0
          {
1528
0
            bfd_put_16 (output_bfd, (bfd_vma) t2a1_bx_pc_insn,
1529
0
            s->contents + my_offset);
1530
1531
0
            bfd_put_16 (output_bfd, (bfd_vma) t2a2_noop_insn,
1532
0
            s->contents + my_offset + 2);
1533
1534
0
            ret_offset =
1535
    /* Address of destination of the stub.  */
1536
0
        ((bfd_signed_vma) h_val)
1537
0
        - ((bfd_signed_vma)
1538
    /* Offset from the start of the current section to the start of the stubs.  */
1539
0
           (s->output_offset
1540
    /* Offset of the start of this stub from the start of the stubs.  */
1541
0
            + my_offset
1542
    /* Address of the start of the current section.  */
1543
0
            + s->output_section->vma)
1544
    /* The branch instruction is 4 bytes into the stub.  */
1545
0
           + 4
1546
    /* ARM branches work from the pc of the instruction + 8.  */
1547
0
           + 8);
1548
1549
0
            bfd_put_32 (output_bfd,
1550
0
            (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
1551
0
            s->contents + my_offset + 4);
1552
1553
0
          }
1554
0
      }
1555
1556
0
          BFD_ASSERT (my_offset <= globals->thumb_glue_size);
1557
1558
          /* Now go back and fix up the original BL insn to point
1559
       to here.  */
1560
0
          ret_offset =
1561
0
      s->output_offset
1562
0
      + my_offset
1563
0
      - (input_section->output_offset
1564
0
         + rel->r_vaddr)
1565
0
      -4;
1566
1567
0
          tmp = bfd_get_32 (input_bfd, contents + rel->r_vaddr
1568
0
          - input_section->vma);
1569
1570
0
          bfd_put_32 (output_bfd,
1571
0
          (bfd_vma) insert_thumb_branch (tmp,
1572
0
                 ret_offset),
1573
0
          contents + rel->r_vaddr - input_section->vma);
1574
1575
0
          done = 1;
1576
0
        }
1577
0
    }
1578
0
#endif
1579
0
      }
1580
1581
    /* If the relocation type and destination symbol does not
1582
       fall into one of the above categories, then we can just
1583
       perform a direct link.  */
1584
1585
0
    if (done)
1586
0
      rstat = bfd_reloc_ok;
1587
0
    else
1588
0
      if (   h->root.type == bfd_link_hash_defined
1589
0
    || h->root.type == bfd_link_hash_defweak)
1590
0
      {
1591
0
        asection *sec;
1592
1593
0
        sec = h->root.u.def.section;
1594
0
        val = (h->root.u.def.value
1595
0
         + sec->output_section->vma
1596
0
         + sec->output_offset);
1597
0
        }
1598
1599
0
    else if (! bfd_link_relocatable (info))
1600
0
      (*info->callbacks->undefined_symbol)
1601
0
        (info, h->root.root.string, input_bfd, input_section,
1602
0
         rel->r_vaddr - input_section->vma, true);
1603
0
  }
1604
1605
      /* Emit a reloc if the backend thinks it needs it.  */
1606
0
      if (info->base_file
1607
0
    && sym
1608
0
    && pe_data(output_bfd)->in_reloc_p(output_bfd, howto)
1609
0
    && !arm_emit_base_file_entry (info, output_bfd, input_section,
1610
0
          rel->r_vaddr))
1611
0
  return false;
1612
1613
0
      if (done)
1614
0
  rstat = bfd_reloc_ok;
1615
0
#ifndef ARM_WINCE
1616
      /* Only perform this fix during the final link, not a relocatable link.  */
1617
0
      else if (! bfd_link_relocatable (info)
1618
0
         && howto->type == ARM_THUMB23)
1619
0
  {
1620
    /* This is pretty much a copy of what the default
1621
       _bfd_final_link_relocate and _bfd_relocate_contents
1622
       routines do to perform a relocation, with special
1623
       processing for the split addressing of the Thumb BL
1624
       instruction.  Again, it would probably be simpler adding a
1625
       ThumbBRANCH23 specific macro expansion into the default
1626
       code.  */
1627
1628
0
    bfd_vma address = rel->r_vaddr - input_section->vma;
1629
1630
0
    if (address > high_address)
1631
0
      rstat = bfd_reloc_outofrange;
1632
0
    else
1633
0
      {
1634
0
        bfd_vma relocation = val + addend;
1635
0
        int size = bfd_get_reloc_size (howto);
1636
0
        bool overflow = false;
1637
0
        bfd_byte *location = contents + address;
1638
0
        bfd_vma x = bfd_get_32 (input_bfd, location);
1639
0
        bfd_vma src_mask = 0x007FFFFE;
1640
0
        bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
1641
0
        bfd_signed_vma reloc_signed_min = ~reloc_signed_max;
1642
0
        bfd_vma check;
1643
0
        bfd_signed_vma signed_check;
1644
0
        bfd_vma add;
1645
0
        bfd_signed_vma signed_add;
1646
1647
0
        BFD_ASSERT (size == 4);
1648
1649
        /* howto->pc_relative should be TRUE for type 14 BRANCH23.  */
1650
0
        relocation -= (input_section->output_section->vma
1651
0
           + input_section->output_offset);
1652
1653
        /* howto->pcrel_offset should be TRUE for type 14 BRANCH23.  */
1654
0
        relocation -= address;
1655
1656
        /* No need to negate the relocation with BRANCH23.  */
1657
        /* howto->complain_on_overflow == complain_overflow_signed for BRANCH23.  */
1658
        /* howto->rightshift == 1 */
1659
1660
        /* Drop unwanted bits from the value we are relocating to.  */
1661
0
        check = relocation >> howto->rightshift;
1662
1663
        /* If this is a signed value, the rightshift just dropped
1664
     leading 1 bits (assuming twos complement).  */
1665
0
        if ((bfd_signed_vma) relocation >= 0)
1666
0
    signed_check = check;
1667
0
        else
1668
0
    signed_check = (check
1669
0
        | ((bfd_vma) - 1
1670
0
           & ~((bfd_vma) - 1 >> howto->rightshift)));
1671
1672
        /* Get the value from the object file.  */
1673
0
        if (bfd_big_endian (input_bfd))
1674
0
    add = (((x) & 0x07ff0000) >> 4) | (((x) & 0x7ff) << 1);
1675
0
        else
1676
0
    add = ((((x) & 0x7ff) << 12) | (((x) & 0x07ff0000) >> 15));
1677
1678
        /* Get the value from the object file with an appropriate sign.
1679
     The expression involving howto->src_mask isolates the upper
1680
     bit of src_mask.  If that bit is set in the value we are
1681
     adding, it is negative, and we subtract out that number times
1682
     two.  If src_mask includes the highest possible bit, then we
1683
     can not get the upper bit, but that does not matter since
1684
     signed_add needs no adjustment to become negative in that
1685
     case.  */
1686
0
        signed_add = add;
1687
1688
0
        if ((add & (((~ src_mask) >> 1) & src_mask)) != 0)
1689
0
    signed_add -= (((~ src_mask) >> 1) & src_mask) << 1;
1690
1691
        /* howto->bitpos == 0 */
1692
        /* Add the value from the object file, shifted so that it is a
1693
     straight number.  */
1694
0
        signed_check += signed_add;
1695
0
        relocation   += signed_add;
1696
1697
0
        BFD_ASSERT (howto->complain_on_overflow == complain_overflow_signed);
1698
1699
        /* Assumes two's complement.  */
1700
0
        if (   signed_check > reloc_signed_max
1701
0
      || signed_check < reloc_signed_min)
1702
0
    overflow = true;
1703
1704
        /* Put the relocation into the correct bits.
1705
     For a BLX instruction, make sure that the relocation is rounded up
1706
     to a word boundary.  This follows the semantics of the instruction
1707
     which specifies that bit 1 of the target address will come from bit
1708
     1 of the base address.  */
1709
0
        if (bfd_big_endian (input_bfd))
1710
0
    {
1711
0
      if ((x & 0x1800) == 0x0800 && (relocation & 0x02))
1712
0
        relocation += 2;
1713
0
      relocation = (((relocation & 0xffe) >> 1)  | ((relocation << 4) & 0x07ff0000));
1714
0
    }
1715
0
        else
1716
0
    {
1717
0
      if ((x & 0x18000000) == 0x08000000 && (relocation & 0x02))
1718
0
        relocation += 2;
1719
0
      relocation = (((relocation & 0xffe) << 15) | ((relocation >> 12) & 0x7ff));
1720
0
    }
1721
1722
        /* Add the relocation to the correct bits of X.  */
1723
0
        x = ((x & ~howto->dst_mask) | relocation);
1724
1725
        /* Put the relocated value back in the object file.  */
1726
0
        bfd_put_32 (input_bfd, x, location);
1727
1728
0
        rstat = overflow ? bfd_reloc_overflow : bfd_reloc_ok;
1729
0
      }
1730
0
  }
1731
0
#endif
1732
0
      else
1733
0
  if (bfd_link_relocatable (info) && ! howto->partial_inplace)
1734
0
      rstat = bfd_reloc_ok;
1735
0
  else
1736
0
    rstat = _bfd_final_link_relocate (howto, input_bfd, input_section,
1737
0
              contents,
1738
0
              rel->r_vaddr - input_section->vma,
1739
0
              val, addend);
1740
      /* Only perform this fix during the final link, not a relocatable link.  */
1741
0
      if (! bfd_link_relocatable (info)
1742
0
    && (rel->r_type == ARM_32 || rel->r_type == ARM_RVA32))
1743
0
  {
1744
    /* Determine if we need to set the bottom bit of a relocated address
1745
       because the address is the address of a Thumb code symbol.  */
1746
0
    int patchit = false;
1747
1748
0
    if (h != NULL
1749
0
        && (   h->symbol_class == C_THUMBSTATFUNC
1750
0
      || h->symbol_class == C_THUMBEXTFUNC))
1751
0
      {
1752
0
        patchit = true;
1753
0
      }
1754
0
    else if (sym != NULL
1755
0
       && sym->n_scnum > N_UNDEF)
1756
0
      {
1757
        /* No hash entry - use the symbol instead.  */
1758
0
        if (   sym->n_sclass == C_THUMBSTATFUNC
1759
0
      || sym->n_sclass == C_THUMBEXTFUNC)
1760
0
    patchit = true;
1761
0
      }
1762
1763
0
    if (patchit)
1764
0
      {
1765
0
        bfd_byte * location = contents + rel->r_vaddr - input_section->vma;
1766
0
        bfd_vma  x    = bfd_get_32 (input_bfd, location);
1767
1768
0
        bfd_put_32 (input_bfd, x | 1, location);
1769
0
      }
1770
0
  }
1771
1772
0
      switch (rstat)
1773
0
  {
1774
0
  default:
1775
0
    abort ();
1776
0
  case bfd_reloc_ok:
1777
0
    break;
1778
0
  case bfd_reloc_outofrange:
1779
0
    _bfd_error_handler
1780
      /* xgettext:c-format */
1781
0
      (_("%pB: bad reloc address %#" PRIx64 " in section `%pA'"),
1782
0
       input_bfd, (uint64_t) rel->r_vaddr, input_section);
1783
0
    return false;
1784
0
  case bfd_reloc_overflow:
1785
0
    {
1786
0
      const char *name;
1787
0
      char buf[SYMNMLEN + 1];
1788
1789
0
      if (symndx == -1)
1790
0
        name = "*ABS*";
1791
0
      else if (h != NULL)
1792
0
        name = NULL;
1793
0
      else
1794
0
        {
1795
0
    name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
1796
0
    if (name == NULL)
1797
0
      return false;
1798
0
        }
1799
1800
0
      (*info->callbacks->reloc_overflow)
1801
0
        (info, (h ? &h->root : NULL), name, howto->name,
1802
0
         (bfd_vma) 0, input_bfd, input_section,
1803
0
         rel->r_vaddr - input_section->vma);
1804
0
    }
1805
0
  }
1806
0
    }
1807
1808
0
  return true;
1809
0
}
Unexecuted instantiation: pe-arm-wince.c:coff_arm_relocate_section
Unexecuted instantiation: pe-arm.c:coff_arm_relocate_section
Unexecuted instantiation: pei-arm-wince.c:coff_arm_relocate_section
Unexecuted instantiation: pei-arm.c:coff_arm_relocate_section
1810
1811
#ifndef COFF_IMAGE_WITH_PE
1812
1813
bool
1814
bfd_arm_allocate_interworking_sections (struct bfd_link_info * info)
1815
0
{
1816
0
  asection *          s;
1817
0
  bfd_byte *          foo;
1818
0
  struct coff_arm_link_hash_table * globals;
1819
1820
0
  globals = coff_arm_hash_table (info);
1821
1822
0
  BFD_ASSERT (globals != NULL);
1823
1824
0
  if (globals->arm_glue_size != 0)
1825
0
    {
1826
0
      BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
1827
1828
0
      s = bfd_get_section_by_name
1829
0
  (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
1830
1831
0
      BFD_ASSERT (s != NULL);
1832
1833
0
      foo = bfd_alloc (globals->bfd_of_glue_owner, globals->arm_glue_size);
1834
1835
0
      s->size = globals->arm_glue_size;
1836
0
      s->contents = foo;
1837
0
      s->alloced = 1;
1838
0
    }
1839
1840
0
  if (globals->thumb_glue_size != 0)
1841
0
    {
1842
0
      BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
1843
1844
0
      s = bfd_get_section_by_name
1845
0
  (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
1846
1847
0
      BFD_ASSERT (s != NULL);
1848
1849
0
      foo = bfd_alloc (globals->bfd_of_glue_owner, globals->thumb_glue_size);
1850
1851
0
      s->size = globals->thumb_glue_size;
1852
0
      s->contents = foo;
1853
0
      s->alloced = 1;
1854
0
    }
1855
1856
0
  return true;
1857
0
}
Unexecuted instantiation: bfd_arm_wince_pe_allocate_interworking_sections
Unexecuted instantiation: bfd_armpe_allocate_interworking_sections
1858
1859
static void
1860
record_arm_to_thumb_glue (struct bfd_link_info *  info,
1861
        struct coff_link_hash_entry * h)
1862
0
{
1863
0
  const char *          name = h->root.root.string;
1864
0
  register asection *       s;
1865
0
  char *          tmp_name;
1866
0
  struct coff_link_hash_entry *     myh;
1867
0
  struct bfd_link_hash_entry *      bh;
1868
0
  struct coff_arm_link_hash_table * globals;
1869
0
  bfd_vma val;
1870
0
  size_t amt;
1871
1872
0
  globals = coff_arm_hash_table (info);
1873
1874
0
  BFD_ASSERT (globals != NULL);
1875
0
  BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
1876
1877
0
  s = bfd_get_section_by_name
1878
0
    (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
1879
1880
0
  BFD_ASSERT (s != NULL);
1881
1882
0
  amt = strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1;
1883
0
  tmp_name = bfd_malloc (amt);
1884
1885
0
  BFD_ASSERT (tmp_name);
1886
1887
0
  sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
1888
1889
0
  myh = coff_link_hash_lookup
1890
0
    (coff_hash_table (info), tmp_name, false, false, true);
1891
1892
0
  if (myh != NULL)
1893
0
    {
1894
0
      free (tmp_name);
1895
      /* We've already seen this guy.  */
1896
0
      return;
1897
0
    }
1898
1899
  /* The only trick here is using globals->arm_glue_size as the value. Even
1900
     though the section isn't allocated yet, this is where we will be putting
1901
     it.  */
1902
0
  bh = NULL;
1903
0
  val = globals->arm_glue_size + 1;
1904
0
  _bfd_generic_link_add_one_symbol (info, globals->bfd_of_glue_owner, tmp_name,
1905
0
            BSF_GLOBAL, s, val, NULL, true, false, &bh);
1906
1907
0
  free (tmp_name);
1908
1909
0
  globals->arm_glue_size += ARM2THUMB_GLUE_SIZE;
1910
1911
0
  return;
1912
0
}
Unexecuted instantiation: pe-arm-wince.c:record_arm_to_thumb_glue
Unexecuted instantiation: pe-arm.c:record_arm_to_thumb_glue
1913
1914
#ifndef ARM_WINCE
1915
static void
1916
record_thumb_to_arm_glue (struct bfd_link_info *  info,
1917
        struct coff_link_hash_entry * h)
1918
0
{
1919
0
  const char *           name = h->root.root.string;
1920
0
  asection *           s;
1921
0
  char *           tmp_name;
1922
0
  struct coff_link_hash_entry *      myh;
1923
0
  struct bfd_link_hash_entry *       bh;
1924
0
  struct coff_arm_link_hash_table *  globals;
1925
0
  bfd_vma val;
1926
0
  size_t amt;
1927
1928
0
  globals = coff_arm_hash_table (info);
1929
1930
0
  BFD_ASSERT (globals != NULL);
1931
0
  BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
1932
1933
0
  s = bfd_get_section_by_name
1934
0
    (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
1935
1936
0
  BFD_ASSERT (s != NULL);
1937
1938
0
  amt = strlen (name) + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1;
1939
0
  tmp_name = bfd_malloc (amt);
1940
1941
0
  BFD_ASSERT (tmp_name);
1942
1943
0
  sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
1944
1945
0
  myh = coff_link_hash_lookup
1946
0
    (coff_hash_table (info), tmp_name, false, false, true);
1947
1948
0
  if (myh != NULL)
1949
0
    {
1950
0
      free (tmp_name);
1951
      /* We've already seen this guy.  */
1952
0
      return;
1953
0
    }
1954
1955
0
  bh = NULL;
1956
0
  val = globals->thumb_glue_size + 1;
1957
0
  _bfd_generic_link_add_one_symbol (info, globals->bfd_of_glue_owner, tmp_name,
1958
0
            BSF_GLOBAL, s, val, NULL, true, false, &bh);
1959
1960
  /* If we mark it 'thumb', the disassembler will do a better job.  */
1961
0
  myh = (struct coff_link_hash_entry *) bh;
1962
0
  myh->symbol_class = C_THUMBEXTFUNC;
1963
1964
0
  free (tmp_name);
1965
1966
  /* Allocate another symbol to mark where we switch to arm mode.  */
1967
1968
0
#define CHANGE_TO_ARM "__%s_change_to_arm"
1969
0
#define BACK_FROM_ARM "__%s_back_from_arm"
1970
1971
0
  amt = strlen (name) + strlen (CHANGE_TO_ARM) + 1;
1972
0
  tmp_name = bfd_malloc (amt);
1973
1974
0
  BFD_ASSERT (tmp_name);
1975
1976
0
  sprintf (tmp_name, globals->support_old_code ? BACK_FROM_ARM : CHANGE_TO_ARM, name);
1977
1978
0
  bh = NULL;
1979
0
  val = globals->thumb_glue_size + (globals->support_old_code ? 8 : 4);
1980
0
  _bfd_generic_link_add_one_symbol (info, globals->bfd_of_glue_owner, tmp_name,
1981
0
            BSF_LOCAL, s, val, NULL, true, false, &bh);
1982
1983
0
  free (tmp_name);
1984
1985
0
  globals->thumb_glue_size += THUMB2ARM_GLUE_SIZE;
1986
1987
0
  return;
1988
0
}
Unexecuted instantiation: pe-arm-wince.c:record_thumb_to_arm_glue
Unexecuted instantiation: pe-arm.c:record_thumb_to_arm_glue
1989
#endif /* not ARM_WINCE */
1990
1991
/* Select a BFD to be used to hold the sections used by the glue code.
1992
   This function is called from the linker scripts in ld/emultempl/
1993
   {armcoff/pe}.em  */
1994
1995
bool
1996
bfd_arm_get_bfd_for_interworking (bfd *      abfd,
1997
          struct bfd_link_info * info)
1998
0
{
1999
0
  struct coff_arm_link_hash_table * globals;
2000
0
  flagword          flags;
2001
0
  asection *          sec;
2002
2003
  /* If we are only performing a partial link do not bother
2004
     getting a bfd to hold the glue.  */
2005
0
  if (bfd_link_relocatable (info))
2006
0
    return true;
2007
2008
0
  globals = coff_arm_hash_table (info);
2009
2010
0
  BFD_ASSERT (globals != NULL);
2011
2012
0
  if (globals->bfd_of_glue_owner != NULL)
2013
0
    return true;
2014
2015
0
  sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME);
2016
2017
0
  if (sec == NULL)
2018
0
    {
2019
0
      flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2020
0
         | SEC_CODE | SEC_READONLY);
2021
0
      sec = bfd_make_section_with_flags (abfd, ARM2THUMB_GLUE_SECTION_NAME,
2022
0
           flags);
2023
0
      if (sec == NULL
2024
0
    || !bfd_set_section_alignment (sec, 2))
2025
0
  return false;
2026
0
    }
2027
2028
0
  sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME);
2029
2030
0
  if (sec == NULL)
2031
0
    {
2032
0
      flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2033
0
         | SEC_CODE | SEC_READONLY);
2034
0
      sec = bfd_make_section_with_flags (abfd, THUMB2ARM_GLUE_SECTION_NAME,
2035
0
           flags);
2036
2037
0
      if (sec == NULL
2038
0
    || !bfd_set_section_alignment (sec, 2))
2039
0
  return false;
2040
0
    }
2041
2042
  /* Save the bfd for later use.  */
2043
0
  globals->bfd_of_glue_owner = abfd;
2044
2045
0
  return true;
2046
0
}
Unexecuted instantiation: bfd_arm_wince_pe_get_bfd_for_interworking
Unexecuted instantiation: bfd_armpe_get_bfd_for_interworking
2047
2048
bool
2049
bfd_arm_process_before_allocation (bfd *       abfd,
2050
           struct bfd_link_info *  info,
2051
           int         support_old_code)
2052
0
{
2053
0
  asection * sec;
2054
0
  struct coff_arm_link_hash_table * globals;
2055
2056
  /* If we are only performing a partial link do not bother
2057
     to construct any glue.  */
2058
0
  if (bfd_link_relocatable (info))
2059
0
    return true;
2060
2061
  /* Here we have a bfd that is to be included on the link.  We have a hook
2062
     to do reloc rummaging, before section sizes are nailed down.  */
2063
0
  _bfd_coff_get_external_symbols (abfd);
2064
2065
0
  globals = coff_arm_hash_table (info);
2066
2067
0
  BFD_ASSERT (globals != NULL);
2068
0
  BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2069
2070
0
  globals->support_old_code = support_old_code;
2071
2072
  /* Rummage around all the relocs and map the glue vectors.  */
2073
0
  sec = abfd->sections;
2074
2075
0
  if (sec == NULL)
2076
0
    return true;
2077
2078
0
  for (; sec != NULL; sec = sec->next)
2079
0
    {
2080
0
      struct internal_reloc * i;
2081
0
      struct internal_reloc * rel;
2082
2083
0
      if (sec->reloc_count == 0)
2084
0
  continue;
2085
2086
      /* Load the relocs.  */
2087
      /* FIXME: there may be a storage leak here.  */
2088
0
      i = bfd_coff_read_internal_relocs (abfd, sec, true, NULL, false, NULL);
2089
2090
0
      BFD_ASSERT (i != 0);
2091
2092
0
      for (rel = i; rel < i + sec->reloc_count; ++rel)
2093
0
  {
2094
0
    unsigned short     r_type  = rel->r_type;
2095
0
    long         symndx;
2096
0
    struct coff_link_hash_entry *  h;
2097
2098
0
    symndx = rel->r_symndx;
2099
2100
    /* If the relocation is not against a symbol it cannot concern us.  */
2101
0
    if (symndx == -1)
2102
0
      continue;
2103
2104
    /* If the index is outside of the range of our table, something has gone wrong.  */
2105
0
    if (!coff_symndx_in_range (abfd, symndx))
2106
0
      {
2107
        /* xgettext:c-format */
2108
0
        _bfd_error_handler (_("%pB: invalid symbol index %ld in relocs"),
2109
0
          abfd, symndx);
2110
0
        continue;
2111
0
      }
2112
2113
0
    h = obj_coff_sym_hashes (abfd)[symndx];
2114
2115
    /* If the relocation is against a static symbol it must be within
2116
       the current section and so cannot be a cross ARM/Thumb relocation.  */
2117
0
    if (h == NULL)
2118
0
      continue;
2119
2120
0
    switch (r_type)
2121
0
      {
2122
0
      case ARM_26:
2123
        /* This one is a call from arm code.  We need to look up
2124
     the target of the call. If it is a thumb target, we
2125
     insert glue.  */
2126
2127
0
        if (h->symbol_class == C_THUMBEXTFUNC)
2128
0
    record_arm_to_thumb_glue (info, h);
2129
0
        break;
2130
2131
0
#ifndef ARM_WINCE
2132
0
      case ARM_THUMB23:
2133
        /* This one is a call from thumb code.  We used to look
2134
     for ARM_THUMB9 and ARM_THUMB12 as well.  We need to look
2135
     up the target of the call. If it is an arm target, we
2136
     insert glue.  If the symbol does not exist it will be
2137
     given a class of C_EXT and so we will generate a stub
2138
     for it.  This is not really a problem, since the link
2139
     is doomed anyway.  */
2140
2141
0
        switch (h->symbol_class)
2142
0
    {
2143
0
    case C_EXT:
2144
0
    case C_STAT:
2145
0
    case C_LABEL:
2146
0
      record_thumb_to_arm_glue (info, h);
2147
0
      break;
2148
0
    default:
2149
0
      ;
2150
0
    }
2151
0
        break;
2152
0
#endif
2153
2154
0
      default:
2155
0
        break;
2156
0
      }
2157
0
  }
2158
0
    }
2159
2160
0
  return true;
2161
0
}
Unexecuted instantiation: bfd_arm_wince_pe_process_before_allocation
Unexecuted instantiation: bfd_armpe_process_before_allocation
2162
2163
#endif /* ! defined (COFF_IMAGE_WITH_PE) */
2164
2165
#define coff_bfd_reloc_type_lookup    coff_arm_reloc_type_lookup
2166
#define coff_bfd_reloc_name_lookup    coff_arm_reloc_name_lookup
2167
#define coff_relocate_section     coff_arm_relocate_section
2168
#define coff_bfd_is_local_label_name    coff_arm_is_local_label_name
2169
#define coff_adjust_symndx      coff_arm_adjust_symndx
2170
#define coff_link_output_has_begun    coff_arm_link_output_has_begun
2171
#define coff_final_link_postscript    coff_arm_final_link_postscript
2172
#define coff_bfd_merge_private_bfd_data   coff_arm_merge_private_bfd_data
2173
#define coff_bfd_print_private_bfd_data   coff_arm_print_private_bfd_data
2174
#define coff_bfd_set_private_flags    _bfd_coff_arm_set_private_flags
2175
#define coff_bfd_copy_private_bfd_data    coff_arm_copy_private_bfd_data
2176
#define coff_bfd_link_hash_table_create   coff_arm_link_hash_table_create
2177
2178
/* When doing a relocatable link, we want to convert ARM_26 relocs
2179
   into ARM_26D relocs.  */
2180
2181
static bool
2182
coff_arm_adjust_symndx (bfd *obfd ATTRIBUTE_UNUSED,
2183
      struct bfd_link_info *info ATTRIBUTE_UNUSED,
2184
      bfd *ibfd,
2185
      asection *sec,
2186
      struct internal_reloc *irel,
2187
      bool *adjustedp)
2188
0
{
2189
0
  if (irel->r_type == ARM_26)
2190
0
    {
2191
0
      struct coff_link_hash_entry *h;
2192
2193
0
      if (! coff_symndx_in_range (ibfd, irel->r_symndx))
2194
0
  {
2195
0
    _bfd_error_handler
2196
      /* xgettext: c-format */
2197
0
      (_("%pB: invalid symbol index %ld in relocs"),
2198
0
       ibfd, irel->r_symndx);
2199
0
    bfd_set_error (bfd_error_bad_value);
2200
0
    return false;
2201
0
  }
2202
2203
0
      h = obj_coff_sym_hashes (ibfd)[irel->r_symndx];
2204
0
      if (h != NULL
2205
0
    && (h->root.type == bfd_link_hash_defined
2206
0
        || h->root.type == bfd_link_hash_defweak)
2207
0
    && h->root.u.def.section->output_section == sec->output_section)
2208
0
  irel->r_type = ARM_26D;
2209
0
    }
2210
0
  *adjustedp = false;
2211
0
  return true;
2212
0
}
Unexecuted instantiation: pe-arm-wince.c:coff_arm_adjust_symndx
Unexecuted instantiation: pe-arm.c:coff_arm_adjust_symndx
Unexecuted instantiation: pei-arm-wince.c:coff_arm_adjust_symndx
Unexecuted instantiation: pei-arm.c:coff_arm_adjust_symndx
2213
2214
/* Called when merging the private data areas of two BFDs.
2215
   This is important as it allows us to detect if we are
2216
   attempting to merge binaries compiled for different ARM
2217
   targets, eg different CPUs or different APCS's.     */
2218
2219
static bool
2220
coff_arm_merge_private_bfd_data (bfd * ibfd, struct bfd_link_info *info)
2221
0
{
2222
0
  bfd *obfd = info->output_bfd;
2223
0
  BFD_ASSERT (ibfd != NULL && obfd != NULL);
2224
2225
0
  if (ibfd == obfd)
2226
0
    return true;
2227
2228
  /* If the two formats are different we cannot merge anything.
2229
     This is not an error, since it is permissable to change the
2230
     input and output formats.  */
2231
0
  if (ibfd->xvec->flavour != bfd_target_coff_flavour)
2232
0
    return true;
2233
2234
  /* Determine what should happen if the input ARM architecture
2235
     does not match the output ARM architecture.  */
2236
0
  if (! bfd_arm_merge_machines (ibfd, obfd))
2237
0
    return false;
2238
2239
  /* Verify that the APCS is the same for the two BFDs.  */
2240
0
  if (APCS_SET (ibfd))
2241
0
    {
2242
0
      if (APCS_SET (obfd))
2243
0
  {
2244
    /* If the src and dest have different APCS flag bits set, fail.  */
2245
0
    if (APCS_26_FLAG (obfd) != APCS_26_FLAG (ibfd))
2246
0
      {
2247
0
        _bfd_error_handler
2248
    /* xgettext: c-format */
2249
0
    (_("error: %pB is compiled for APCS-%d, "
2250
0
       "whereas %pB is compiled for APCS-%d"),
2251
0
     ibfd, APCS_26_FLAG (ibfd) ? 26 : 32,
2252
0
     obfd, APCS_26_FLAG (obfd) ? 26 : 32
2253
0
     );
2254
2255
0
        bfd_set_error (bfd_error_wrong_format);
2256
0
        return false;
2257
0
      }
2258
2259
0
    if (APCS_FLOAT_FLAG (obfd) != APCS_FLOAT_FLAG (ibfd))
2260
0
      {
2261
0
        if (APCS_FLOAT_FLAG (ibfd))
2262
    /* xgettext: c-format */
2263
0
    _bfd_error_handler
2264
0
      (_("error: %pB passes floats in float registers, "
2265
0
         "whereas %pB passes them in integer registers"),
2266
0
       ibfd, obfd);
2267
0
        else
2268
    /* xgettext: c-format */
2269
0
    _bfd_error_handler
2270
0
      (_("error: %pB passes floats in integer registers, "
2271
0
         "whereas %pB passes them in float registers"),
2272
0
       ibfd, obfd);
2273
2274
0
        bfd_set_error (bfd_error_wrong_format);
2275
0
        return false;
2276
0
      }
2277
2278
0
    if (PIC_FLAG (obfd) != PIC_FLAG (ibfd))
2279
0
      {
2280
0
        if (PIC_FLAG (ibfd))
2281
    /* xgettext: c-format */
2282
0
    _bfd_error_handler
2283
0
      (_("error: %pB is compiled as position independent code, "
2284
0
         "whereas target %pB is absolute position"),
2285
0
       ibfd, obfd);
2286
0
        else
2287
    /* xgettext: c-format */
2288
0
    _bfd_error_handler
2289
0
      (_("error: %pB is compiled as absolute position code, "
2290
0
         "whereas target %pB is position independent"),
2291
0
       ibfd, obfd);
2292
2293
0
        bfd_set_error (bfd_error_wrong_format);
2294
0
        return false;
2295
0
      }
2296
0
  }
2297
0
      else
2298
0
  {
2299
0
    SET_APCS_FLAGS (obfd, APCS_26_FLAG (ibfd) | APCS_FLOAT_FLAG (ibfd) | PIC_FLAG (ibfd));
2300
2301
    /* Set up the arch and fields as well as these are probably wrong.  */
2302
0
    bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
2303
0
  }
2304
0
    }
2305
2306
  /* Check the interworking support.  */
2307
0
  if (INTERWORK_SET (ibfd))
2308
0
    {
2309
0
      if (INTERWORK_SET (obfd))
2310
0
  {
2311
    /* If the src and dest differ in their interworking issue a warning.  */
2312
0
    if (INTERWORK_FLAG (obfd) != INTERWORK_FLAG (ibfd))
2313
0
      {
2314
0
        if (INTERWORK_FLAG (ibfd))
2315
    /* xgettext: c-format */
2316
0
    _bfd_error_handler (_("warning: %pB supports interworking, "
2317
0
              "whereas %pB does not"),
2318
0
            ibfd, obfd);
2319
0
        else
2320
    /* xgettext: c-format */
2321
0
    _bfd_error_handler
2322
0
      (_("warning: %pB does not support interworking, "
2323
0
         "whereas %pB does"),
2324
0
       ibfd, obfd);
2325
0
      }
2326
0
  }
2327
0
      else
2328
0
  {
2329
0
    SET_INTERWORK_FLAG (obfd, INTERWORK_FLAG (ibfd));
2330
0
  }
2331
0
    }
2332
2333
0
  return true;
2334
0
}
Unexecuted instantiation: pe-arm-wince.c:coff_arm_merge_private_bfd_data
Unexecuted instantiation: pe-arm.c:coff_arm_merge_private_bfd_data
Unexecuted instantiation: pei-arm-wince.c:coff_arm_merge_private_bfd_data
Unexecuted instantiation: pei-arm.c:coff_arm_merge_private_bfd_data
2335
2336
/* Display the flags field.  */
2337
2338
static bool
2339
coff_arm_print_private_bfd_data (bfd * abfd, void * ptr)
2340
205
{
2341
205
  FILE * file = (FILE *) ptr;
2342
2343
205
  BFD_ASSERT (abfd != NULL && ptr != NULL);
2344
2345
205
  fprintf (file, _("private flags = %x:"), coff_data (abfd)->flags);
2346
2347
205
  if (APCS_SET (abfd))
2348
205
    {
2349
      /* xgettext: APCS is ARM Procedure Call Standard, it should not be translated.  */
2350
205
      fprintf (file, " [APCS-%d]", APCS_26_FLAG (abfd) ? 26 : 32);
2351
2352
205
      if (APCS_FLOAT_FLAG (abfd))
2353
5
  fprintf (file, _(" [floats passed in float registers]"));
2354
200
      else
2355
200
  fprintf (file, _(" [floats passed in integer registers]"));
2356
2357
205
      if (PIC_FLAG (abfd))
2358
7
  fprintf (file, _(" [position independent]"));
2359
198
      else
2360
198
  fprintf (file, _(" [absolute position]"));
2361
205
    }
2362
2363
205
  if (! INTERWORK_SET (abfd))
2364
0
    fprintf (file, _(" [interworking flag not initialised]"));
2365
205
  else if (INTERWORK_FLAG (abfd))
2366
7
    fprintf (file, _(" [interworking supported]"));
2367
198
  else
2368
198
    fprintf (file, _(" [interworking not supported]"));
2369
2370
205
  fputc ('\n', file);
2371
2372
205
  return true;
2373
205
}
Unexecuted instantiation: pe-arm-wince.c:coff_arm_print_private_bfd_data
Unexecuted instantiation: pe-arm.c:coff_arm_print_private_bfd_data
pei-arm-wince.c:coff_arm_print_private_bfd_data
Line
Count
Source
2340
7
{
2341
7
  FILE * file = (FILE *) ptr;
2342
2343
7
  BFD_ASSERT (abfd != NULL && ptr != NULL);
2344
2345
7
  fprintf (file, _("private flags = %x:"), coff_data (abfd)->flags);
2346
2347
7
  if (APCS_SET (abfd))
2348
7
    {
2349
      /* xgettext: APCS is ARM Procedure Call Standard, it should not be translated.  */
2350
7
      fprintf (file, " [APCS-%d]", APCS_26_FLAG (abfd) ? 26 : 32);
2351
2352
7
      if (APCS_FLOAT_FLAG (abfd))
2353
0
  fprintf (file, _(" [floats passed in float registers]"));
2354
7
      else
2355
7
  fprintf (file, _(" [floats passed in integer registers]"));
2356
2357
7
      if (PIC_FLAG (abfd))
2358
0
  fprintf (file, _(" [position independent]"));
2359
7
      else
2360
7
  fprintf (file, _(" [absolute position]"));
2361
7
    }
2362
2363
7
  if (! INTERWORK_SET (abfd))
2364
0
    fprintf (file, _(" [interworking flag not initialised]"));
2365
7
  else if (INTERWORK_FLAG (abfd))
2366
0
    fprintf (file, _(" [interworking supported]"));
2367
7
  else
2368
7
    fprintf (file, _(" [interworking not supported]"));
2369
2370
7
  fputc ('\n', file);
2371
2372
  return true;
2373
7
}
pei-arm.c:coff_arm_print_private_bfd_data
Line
Count
Source
2340
198
{
2341
198
  FILE * file = (FILE *) ptr;
2342
2343
198
  BFD_ASSERT (abfd != NULL && ptr != NULL);
2344
2345
198
  fprintf (file, _("private flags = %x:"), coff_data (abfd)->flags);
2346
2347
198
  if (APCS_SET (abfd))
2348
198
    {
2349
      /* xgettext: APCS is ARM Procedure Call Standard, it should not be translated.  */
2350
198
      fprintf (file, " [APCS-%d]", APCS_26_FLAG (abfd) ? 26 : 32);
2351
2352
198
      if (APCS_FLOAT_FLAG (abfd))
2353
5
  fprintf (file, _(" [floats passed in float registers]"));
2354
193
      else
2355
193
  fprintf (file, _(" [floats passed in integer registers]"));
2356
2357
198
      if (PIC_FLAG (abfd))
2358
7
  fprintf (file, _(" [position independent]"));
2359
191
      else
2360
191
  fprintf (file, _(" [absolute position]"));
2361
198
    }
2362
2363
198
  if (! INTERWORK_SET (abfd))
2364
0
    fprintf (file, _(" [interworking flag not initialised]"));
2365
198
  else if (INTERWORK_FLAG (abfd))
2366
7
    fprintf (file, _(" [interworking supported]"));
2367
191
  else
2368
191
    fprintf (file, _(" [interworking not supported]"));
2369
2370
198
  fputc ('\n', file);
2371
2372
  return true;
2373
198
}
2374
2375
/* Copies the given flags into the coff_tdata.flags field.
2376
   Typically these flags come from the f_flags[] field of
2377
   the COFF filehdr structure, which contains important,
2378
   target specific information.
2379
   Note: Although this function is static, it is explicitly
2380
   called from both coffcode.h and peicode.h.  */
2381
2382
static bool
2383
_bfd_coff_arm_set_private_flags (bfd * abfd, flagword flags)
2384
18.3k
{
2385
18.3k
  flagword flag;
2386
2387
18.3k
  BFD_ASSERT (abfd != NULL);
2388
2389
18.3k
  flag = (flags & F_APCS26) ? F_APCS_26 : 0;
2390
2391
  /* Make sure that the APCS field has not been initialised to the opposite
2392
     value.  */
2393
18.3k
  if (APCS_SET (abfd)
2394
0
      && (   (APCS_26_FLAG    (abfd) != flag)
2395
0
    || (APCS_FLOAT_FLAG (abfd) != (flags & F_APCS_FLOAT))
2396
0
    || (PIC_FLAG        (abfd) != (flags & F_PIC))
2397
0
    ))
2398
0
    return false;
2399
2400
18.3k
  flag |= (flags & (F_APCS_FLOAT | F_PIC));
2401
2402
18.3k
  SET_APCS_FLAGS (abfd, flag);
2403
2404
18.3k
  flag = (flags & F_INTERWORK);
2405
2406
  /* If the BFD has already had its interworking flag set, but it
2407
     is different from the value that we have been asked to set,
2408
     then assume that that merged code will not support interworking
2409
     and set the flag accordingly.  */
2410
18.3k
  if (INTERWORK_SET (abfd) && (INTERWORK_FLAG (abfd) != flag))
2411
0
    {
2412
0
      if (flag)
2413
0
  _bfd_error_handler (_("warning: not setting interworking flag of %pB since it has already been specified as non-interworking"),
2414
0
          abfd);
2415
0
      else
2416
0
  _bfd_error_handler (_("warning: clearing the interworking flag of %pB due to outside request"),
2417
0
          abfd);
2418
0
      flag = 0;
2419
0
    }
2420
2421
18.3k
  SET_INTERWORK_FLAG (abfd, flag);
2422
2423
18.3k
  return true;
2424
18.3k
}
pe-arm-wince.c:_bfd_coff_arm_set_private_flags
Line
Count
Source
2384
2.88k
{
2385
2.88k
  flagword flag;
2386
2387
2.88k
  BFD_ASSERT (abfd != NULL);
2388
2389
2.88k
  flag = (flags & F_APCS26) ? F_APCS_26 : 0;
2390
2391
  /* Make sure that the APCS field has not been initialised to the opposite
2392
     value.  */
2393
2.88k
  if (APCS_SET (abfd)
2394
0
      && (   (APCS_26_FLAG    (abfd) != flag)
2395
0
    || (APCS_FLOAT_FLAG (abfd) != (flags & F_APCS_FLOAT))
2396
0
    || (PIC_FLAG        (abfd) != (flags & F_PIC))
2397
0
    ))
2398
0
    return false;
2399
2400
2.88k
  flag |= (flags & (F_APCS_FLOAT | F_PIC));
2401
2402
2.88k
  SET_APCS_FLAGS (abfd, flag);
2403
2404
2.88k
  flag = (flags & F_INTERWORK);
2405
2406
  /* If the BFD has already had its interworking flag set, but it
2407
     is different from the value that we have been asked to set,
2408
     then assume that that merged code will not support interworking
2409
     and set the flag accordingly.  */
2410
2.88k
  if (INTERWORK_SET (abfd) && (INTERWORK_FLAG (abfd) != flag))
2411
0
    {
2412
0
      if (flag)
2413
0
  _bfd_error_handler (_("warning: not setting interworking flag of %pB since it has already been specified as non-interworking"),
2414
0
          abfd);
2415
0
      else
2416
0
  _bfd_error_handler (_("warning: clearing the interworking flag of %pB due to outside request"),
2417
0
          abfd);
2418
0
      flag = 0;
2419
0
    }
2420
2421
2.88k
  SET_INTERWORK_FLAG (abfd, flag);
2422
2423
  return true;
2424
2.88k
}
pe-arm.c:_bfd_coff_arm_set_private_flags
Line
Count
Source
2384
2.88k
{
2385
2.88k
  flagword flag;
2386
2387
2.88k
  BFD_ASSERT (abfd != NULL);
2388
2389
2.88k
  flag = (flags & F_APCS26) ? F_APCS_26 : 0;
2390
2391
  /* Make sure that the APCS field has not been initialised to the opposite
2392
     value.  */
2393
2.88k
  if (APCS_SET (abfd)
2394
0
      && (   (APCS_26_FLAG    (abfd) != flag)
2395
0
    || (APCS_FLOAT_FLAG (abfd) != (flags & F_APCS_FLOAT))
2396
0
    || (PIC_FLAG        (abfd) != (flags & F_PIC))
2397
0
    ))
2398
0
    return false;
2399
2400
2.88k
  flag |= (flags & (F_APCS_FLOAT | F_PIC));
2401
2402
2.88k
  SET_APCS_FLAGS (abfd, flag);
2403
2404
2.88k
  flag = (flags & F_INTERWORK);
2405
2406
  /* If the BFD has already had its interworking flag set, but it
2407
     is different from the value that we have been asked to set,
2408
     then assume that that merged code will not support interworking
2409
     and set the flag accordingly.  */
2410
2.88k
  if (INTERWORK_SET (abfd) && (INTERWORK_FLAG (abfd) != flag))
2411
0
    {
2412
0
      if (flag)
2413
0
  _bfd_error_handler (_("warning: not setting interworking flag of %pB since it has already been specified as non-interworking"),
2414
0
          abfd);
2415
0
      else
2416
0
  _bfd_error_handler (_("warning: clearing the interworking flag of %pB due to outside request"),
2417
0
          abfd);
2418
0
      flag = 0;
2419
0
    }
2420
2421
2.88k
  SET_INTERWORK_FLAG (abfd, flag);
2422
2423
  return true;
2424
2.88k
}
pei-arm-wince.c:_bfd_coff_arm_set_private_flags
Line
Count
Source
2384
5.44k
{
2385
5.44k
  flagword flag;
2386
2387
5.44k
  BFD_ASSERT (abfd != NULL);
2388
2389
5.44k
  flag = (flags & F_APCS26) ? F_APCS_26 : 0;
2390
2391
  /* Make sure that the APCS field has not been initialised to the opposite
2392
     value.  */
2393
5.44k
  if (APCS_SET (abfd)
2394
0
      && (   (APCS_26_FLAG    (abfd) != flag)
2395
0
    || (APCS_FLOAT_FLAG (abfd) != (flags & F_APCS_FLOAT))
2396
0
    || (PIC_FLAG        (abfd) != (flags & F_PIC))
2397
0
    ))
2398
0
    return false;
2399
2400
5.44k
  flag |= (flags & (F_APCS_FLOAT | F_PIC));
2401
2402
5.44k
  SET_APCS_FLAGS (abfd, flag);
2403
2404
5.44k
  flag = (flags & F_INTERWORK);
2405
2406
  /* If the BFD has already had its interworking flag set, but it
2407
     is different from the value that we have been asked to set,
2408
     then assume that that merged code will not support interworking
2409
     and set the flag accordingly.  */
2410
5.44k
  if (INTERWORK_SET (abfd) && (INTERWORK_FLAG (abfd) != flag))
2411
0
    {
2412
0
      if (flag)
2413
0
  _bfd_error_handler (_("warning: not setting interworking flag of %pB since it has already been specified as non-interworking"),
2414
0
          abfd);
2415
0
      else
2416
0
  _bfd_error_handler (_("warning: clearing the interworking flag of %pB due to outside request"),
2417
0
          abfd);
2418
0
      flag = 0;
2419
0
    }
2420
2421
5.44k
  SET_INTERWORK_FLAG (abfd, flag);
2422
2423
  return true;
2424
5.44k
}
pei-arm.c:_bfd_coff_arm_set_private_flags
Line
Count
Source
2384
7.15k
{
2385
7.15k
  flagword flag;
2386
2387
7.15k
  BFD_ASSERT (abfd != NULL);
2388
2389
7.15k
  flag = (flags & F_APCS26) ? F_APCS_26 : 0;
2390
2391
  /* Make sure that the APCS field has not been initialised to the opposite
2392
     value.  */
2393
7.15k
  if (APCS_SET (abfd)
2394
0
      && (   (APCS_26_FLAG    (abfd) != flag)
2395
0
    || (APCS_FLOAT_FLAG (abfd) != (flags & F_APCS_FLOAT))
2396
0
    || (PIC_FLAG        (abfd) != (flags & F_PIC))
2397
0
    ))
2398
0
    return false;
2399
2400
7.15k
  flag |= (flags & (F_APCS_FLOAT | F_PIC));
2401
2402
7.15k
  SET_APCS_FLAGS (abfd, flag);
2403
2404
7.15k
  flag = (flags & F_INTERWORK);
2405
2406
  /* If the BFD has already had its interworking flag set, but it
2407
     is different from the value that we have been asked to set,
2408
     then assume that that merged code will not support interworking
2409
     and set the flag accordingly.  */
2410
7.15k
  if (INTERWORK_SET (abfd) && (INTERWORK_FLAG (abfd) != flag))
2411
0
    {
2412
0
      if (flag)
2413
0
  _bfd_error_handler (_("warning: not setting interworking flag of %pB since it has already been specified as non-interworking"),
2414
0
          abfd);
2415
0
      else
2416
0
  _bfd_error_handler (_("warning: clearing the interworking flag of %pB due to outside request"),
2417
0
          abfd);
2418
0
      flag = 0;
2419
0
    }
2420
2421
7.15k
  SET_INTERWORK_FLAG (abfd, flag);
2422
2423
  return true;
2424
7.15k
}
2425
2426
/* Copy the important parts of the target specific data
2427
   from one instance of a BFD to another.  */
2428
2429
static bool
2430
coff_arm_copy_private_bfd_data (bfd * src, bfd * dest)
2431
169
{
2432
169
  BFD_ASSERT (src != NULL && dest != NULL);
2433
2434
169
  if (src == dest)
2435
0
    return true;
2436
2437
  /* If the destination is not in the same format as the source, do not do
2438
     the copy.  */
2439
169
  if (src->xvec != dest->xvec)
2440
0
    return true;
2441
2442
  /* Copy the flags field.  */
2443
169
  if (APCS_SET (src))
2444
169
    {
2445
169
      if (APCS_SET (dest))
2446
0
  {
2447
    /* If the src and dest have different APCS flag bits set, fail.  */
2448
0
    if (APCS_26_FLAG (dest) != APCS_26_FLAG (src))
2449
0
      return false;
2450
2451
0
    if (APCS_FLOAT_FLAG (dest) != APCS_FLOAT_FLAG (src))
2452
0
      return false;
2453
2454
0
    if (PIC_FLAG (dest) != PIC_FLAG (src))
2455
0
      return false;
2456
0
  }
2457
169
      else
2458
169
  SET_APCS_FLAGS (dest, APCS_26_FLAG (src) | APCS_FLOAT_FLAG (src)
2459
169
      | PIC_FLAG (src));
2460
169
    }
2461
2462
169
  if (INTERWORK_SET (src))
2463
169
    {
2464
169
      if (INTERWORK_SET (dest))
2465
0
  {
2466
    /* If the src and dest have different interworking flags then turn
2467
       off the interworking bit.  */
2468
0
    if (INTERWORK_FLAG (dest) != INTERWORK_FLAG (src))
2469
0
      {
2470
0
        if (INTERWORK_FLAG (dest))
2471
0
    {
2472
      /* xgettext:c-format */
2473
0
      _bfd_error_handler
2474
0
        (_("warning: clearing the interworking flag of %pB "
2475
0
           "because non-interworking code in %pB has been "
2476
0
           "linked with it"),
2477
0
         dest, src);
2478
0
    }
2479
2480
0
        SET_INTERWORK_FLAG (dest, 0);
2481
0
      }
2482
0
  }
2483
169
      else
2484
169
  {
2485
169
    SET_INTERWORK_FLAG (dest, INTERWORK_FLAG (src));
2486
169
  }
2487
169
    }
2488
2489
169
  return true;
2490
169
}
Unexecuted instantiation: pe-arm-wince.c:coff_arm_copy_private_bfd_data
Unexecuted instantiation: pe-arm.c:coff_arm_copy_private_bfd_data
pei-arm-wince.c:coff_arm_copy_private_bfd_data
Line
Count
Source
2431
65
{
2432
65
  BFD_ASSERT (src != NULL && dest != NULL);
2433
2434
65
  if (src == dest)
2435
0
    return true;
2436
2437
  /* If the destination is not in the same format as the source, do not do
2438
     the copy.  */
2439
65
  if (src->xvec != dest->xvec)
2440
0
    return true;
2441
2442
  /* Copy the flags field.  */
2443
65
  if (APCS_SET (src))
2444
65
    {
2445
65
      if (APCS_SET (dest))
2446
0
  {
2447
    /* If the src and dest have different APCS flag bits set, fail.  */
2448
0
    if (APCS_26_FLAG (dest) != APCS_26_FLAG (src))
2449
0
      return false;
2450
2451
0
    if (APCS_FLOAT_FLAG (dest) != APCS_FLOAT_FLAG (src))
2452
0
      return false;
2453
2454
0
    if (PIC_FLAG (dest) != PIC_FLAG (src))
2455
0
      return false;
2456
0
  }
2457
65
      else
2458
65
  SET_APCS_FLAGS (dest, APCS_26_FLAG (src) | APCS_FLOAT_FLAG (src)
2459
65
      | PIC_FLAG (src));
2460
65
    }
2461
2462
65
  if (INTERWORK_SET (src))
2463
65
    {
2464
65
      if (INTERWORK_SET (dest))
2465
0
  {
2466
    /* If the src and dest have different interworking flags then turn
2467
       off the interworking bit.  */
2468
0
    if (INTERWORK_FLAG (dest) != INTERWORK_FLAG (src))
2469
0
      {
2470
0
        if (INTERWORK_FLAG (dest))
2471
0
    {
2472
      /* xgettext:c-format */
2473
0
      _bfd_error_handler
2474
0
        (_("warning: clearing the interworking flag of %pB "
2475
0
           "because non-interworking code in %pB has been "
2476
0
           "linked with it"),
2477
0
         dest, src);
2478
0
    }
2479
2480
0
        SET_INTERWORK_FLAG (dest, 0);
2481
0
      }
2482
0
  }
2483
65
      else
2484
65
  {
2485
65
    SET_INTERWORK_FLAG (dest, INTERWORK_FLAG (src));
2486
65
  }
2487
65
    }
2488
2489
  return true;
2490
65
}
pei-arm.c:coff_arm_copy_private_bfd_data
Line
Count
Source
2431
104
{
2432
104
  BFD_ASSERT (src != NULL && dest != NULL);
2433
2434
104
  if (src == dest)
2435
0
    return true;
2436
2437
  /* If the destination is not in the same format as the source, do not do
2438
     the copy.  */
2439
104
  if (src->xvec != dest->xvec)
2440
0
    return true;
2441
2442
  /* Copy the flags field.  */
2443
104
  if (APCS_SET (src))
2444
104
    {
2445
104
      if (APCS_SET (dest))
2446
0
  {
2447
    /* If the src and dest have different APCS flag bits set, fail.  */
2448
0
    if (APCS_26_FLAG (dest) != APCS_26_FLAG (src))
2449
0
      return false;
2450
2451
0
    if (APCS_FLOAT_FLAG (dest) != APCS_FLOAT_FLAG (src))
2452
0
      return false;
2453
2454
0
    if (PIC_FLAG (dest) != PIC_FLAG (src))
2455
0
      return false;
2456
0
  }
2457
104
      else
2458
104
  SET_APCS_FLAGS (dest, APCS_26_FLAG (src) | APCS_FLOAT_FLAG (src)
2459
104
      | PIC_FLAG (src));
2460
104
    }
2461
2462
104
  if (INTERWORK_SET (src))
2463
104
    {
2464
104
      if (INTERWORK_SET (dest))
2465
0
  {
2466
    /* If the src and dest have different interworking flags then turn
2467
       off the interworking bit.  */
2468
0
    if (INTERWORK_FLAG (dest) != INTERWORK_FLAG (src))
2469
0
      {
2470
0
        if (INTERWORK_FLAG (dest))
2471
0
    {
2472
      /* xgettext:c-format */
2473
0
      _bfd_error_handler
2474
0
        (_("warning: clearing the interworking flag of %pB "
2475
0
           "because non-interworking code in %pB has been "
2476
0
           "linked with it"),
2477
0
         dest, src);
2478
0
    }
2479
2480
0
        SET_INTERWORK_FLAG (dest, 0);
2481
0
      }
2482
0
  }
2483
104
      else
2484
104
  {
2485
104
    SET_INTERWORK_FLAG (dest, INTERWORK_FLAG (src));
2486
104
  }
2487
104
    }
2488
2489
  return true;
2490
104
}
2491
2492
/* Note:  the definitions here of LOCAL_LABEL_PREFIX and USER_LABEL_PREIFX
2493
   *must* match the definitions in gcc/config/arm/{coff|semi|aout}.h.  */
2494
#ifndef LOCAL_LABEL_PREFIX
2495
0
#define LOCAL_LABEL_PREFIX ""
2496
#endif
2497
#ifndef USER_LABEL_PREFIX
2498
0
#define USER_LABEL_PREFIX "_"
2499
#endif
2500
2501
/* Like _bfd_coff_is_local_label_name, but
2502
   a) test against USER_LABEL_PREFIX, to avoid stripping labels known to be
2503
      non-local.
2504
   b) Allow other prefixes than ".", e.g. an empty prefix would cause all
2505
      labels of the form Lxxx to be stripped.  */
2506
2507
static bool
2508
coff_arm_is_local_label_name (bfd *    abfd ATTRIBUTE_UNUSED,
2509
            const char * name)
2510
0
{
2511
0
#ifdef USER_LABEL_PREFIX
2512
0
  if (USER_LABEL_PREFIX[0] != 0)
2513
0
    {
2514
0
      size_t len = strlen (USER_LABEL_PREFIX);
2515
2516
0
      if (strncmp (name, USER_LABEL_PREFIX, len) == 0)
2517
0
  return false;
2518
0
    }
2519
0
#endif
2520
2521
0
#ifdef LOCAL_LABEL_PREFIX
2522
  /* If there is a prefix for local labels then look for this.
2523
     If the prefix exists, but it is empty, then ignore the test.  */
2524
2525
0
  if (LOCAL_LABEL_PREFIX[0] != 0)
2526
0
    {
2527
0
      size_t len = strlen (LOCAL_LABEL_PREFIX);
2528
2529
0
      if (strncmp (name, LOCAL_LABEL_PREFIX, len) != 0)
2530
0
  return false;
2531
2532
      /* Perform the checks below for the rest of the name.  */
2533
0
      name += len;
2534
0
    }
2535
0
#endif
2536
2537
0
  return name[0] == 'L';
2538
0
}
Unexecuted instantiation: pe-arm-wince.c:coff_arm_is_local_label_name
Unexecuted instantiation: pe-arm.c:coff_arm_is_local_label_name
Unexecuted instantiation: pei-arm-wince.c:coff_arm_is_local_label_name
Unexecuted instantiation: pei-arm.c:coff_arm_is_local_label_name
2539
2540
/* This piece of machinery exists only to guarantee that the bfd that holds
2541
   the glue section is written last.
2542
2543
   This does depend on bfd_make_section attaching a new section to the
2544
   end of the section list for the bfd.  */
2545
2546
static bool
2547
coff_arm_link_output_has_begun (bfd * sub, struct coff_final_link_info * info)
2548
0
{
2549
0
  return (sub->output_has_begun
2550
0
    || sub == coff_arm_hash_table (info->info)->bfd_of_glue_owner);
2551
0
}
Unexecuted instantiation: pe-arm-wince.c:coff_arm_link_output_has_begun
Unexecuted instantiation: pe-arm.c:coff_arm_link_output_has_begun
Unexecuted instantiation: pei-arm-wince.c:coff_arm_link_output_has_begun
Unexecuted instantiation: pei-arm.c:coff_arm_link_output_has_begun
2552
2553
static bool
2554
coff_arm_final_link_postscript (bfd * abfd ATTRIBUTE_UNUSED,
2555
        struct coff_final_link_info * pfinfo)
2556
0
{
2557
0
  struct coff_arm_link_hash_table * globals;
2558
2559
0
  globals = coff_arm_hash_table (pfinfo->info);
2560
2561
0
  BFD_ASSERT (globals != NULL);
2562
2563
0
  if (globals->bfd_of_glue_owner != NULL)
2564
0
    {
2565
0
      if (! _bfd_coff_link_input_bfd (pfinfo, globals->bfd_of_glue_owner))
2566
0
  return false;
2567
2568
0
      globals->bfd_of_glue_owner->output_has_begun = true;
2569
0
    }
2570
2571
0
  return bfd_arm_update_notes (abfd, ARM_NOTE_SECTION);
2572
0
}
Unexecuted instantiation: pe-arm-wince.c:coff_arm_final_link_postscript
Unexecuted instantiation: pe-arm.c:coff_arm_final_link_postscript
Unexecuted instantiation: pei-arm-wince.c:coff_arm_final_link_postscript
Unexecuted instantiation: pei-arm.c:coff_arm_final_link_postscript
2573
2574
#ifndef bfd_pe_print_pdata
2575
#define bfd_pe_print_pdata  NULL
2576
#endif
2577
2578
#include "coffcode.h"
2579
2580
#ifndef TARGET_LITTLE_SYM
2581
#define TARGET_LITTLE_SYM arm_coff_le_vec
2582
#endif
2583
#ifndef TARGET_LITTLE_NAME
2584
#define TARGET_LITTLE_NAME "coff-arm-little"
2585
#endif
2586
#ifndef TARGET_BIG_SYM
2587
#define TARGET_BIG_SYM arm_coff_be_vec
2588
#endif
2589
#ifndef TARGET_BIG_NAME
2590
#define TARGET_BIG_NAME "coff-arm-big"
2591
#endif
2592
2593
#ifndef TARGET_UNDERSCORE
2594
#define TARGET_UNDERSCORE 0
2595
#endif
2596
2597
/* Forward declaration for use initialising alternative_target field.  */
2598
extern const bfd_target TARGET_BIG_SYM ;
2599
2600
/* Target vectors.  */
2601
CREATE_LITTLE_COFF_TARGET_VEC (TARGET_LITTLE_SYM, TARGET_LITTLE_NAME, D_PAGED, SEC_CODE, TARGET_UNDERSCORE, & TARGET_BIG_SYM, COFF_SWAP_TABLE)
2602
CREATE_BIG_COFF_TARGET_VEC (TARGET_BIG_SYM, TARGET_BIG_NAME, D_PAGED, SEC_CODE, TARGET_UNDERSCORE, & TARGET_LITTLE_SYM, COFF_SWAP_TABLE)