Coverage Report

Created: 2026-09-14 08:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/bfd/elf-m10300.c
Line
Count
Source
1
/* Matsushita 10300 specific support for 32-bit ELF
2
   Copyright (C) 1996-2026 Free Software Foundation, Inc.
3
4
   This file is part of BFD, the Binary File Descriptor library.
5
6
   This program is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License as published by
8
   the Free Software Foundation; either version 3 of the License, or
9
   (at your option) any later version.
10
11
   This program is distributed in the hope that it will be useful,
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
   GNU General Public License for more details.
15
16
   You should have received a copy of the GNU General Public License
17
   along with this program; if not, write to the Free Software
18
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19
   MA 02110-1301, USA.  */
20
21
#include "sysdep.h"
22
#include "bfd.h"
23
#include "libbfd.h"
24
#include "elf-bfd.h"
25
#include "elf/mn10300.h"
26
#include "libiberty.h"
27
28
/* The mn10300 linker needs to keep track of the number of relocs that
29
   it decides to copy in check_relocs for each symbol.  This is so
30
   that it can discard PC relative relocs if it doesn't need them when
31
   linking with -Bsymbolic.  We store the information in a field
32
   extending the regular ELF linker hash table.  */
33
34
struct elf32_mn10300_link_hash_entry
35
{
36
  /* The basic elf link hash table entry.  */
37
  struct elf_link_hash_entry root;
38
39
  /* For function symbols, the number of times this function is
40
     called directly (ie by name).  */
41
  unsigned int direct_calls;
42
43
  /* For function symbols, the size of this function's stack
44
     (if <= 255 bytes).  We stuff this into "call" instructions
45
     to this target when it's valid and profitable to do so.
46
47
     This does not include stack allocated by movm!  */
48
  unsigned char stack_size;
49
50
  /* For function symbols, arguments (if any) for movm instruction
51
     in the prologue.  We stuff this value into "call" instructions
52
     to the target when it's valid and profitable to do so.  */
53
  unsigned char movm_args;
54
55
  /* For function symbols, the amount of stack space that would be allocated
56
     by the movm instruction.  This is redundant with movm_args, but we
57
     add it to the hash table to avoid computing it over and over.  */
58
  unsigned char movm_stack_size;
59
60
/* When set, convert all "call" instructions to this target into "calls"
61
   instructions.  */
62
0
#define MN10300_CONVERT_CALL_TO_CALLS 0x1
63
64
/* Used to mark functions which have had redundant parts of their
65
   prologue deleted.  */
66
0
#define MN10300_DELETED_PROLOGUE_BYTES 0x2
67
  unsigned char flags;
68
69
  /* Calculated value.  */
70
  bfd_vma value;
71
72
0
#define GOT_UNKNOWN 0
73
0
#define GOT_NORMAL  1
74
0
#define GOT_TLS_GD  2
75
0
#define GOT_TLS_LD  3
76
0
#define GOT_TLS_IE  4
77
  /* Used to distinguish GOT entries for TLS types from normal GOT entries.  */
78
  unsigned char tls_type;
79
};
80
81
/* We derive a hash table from the main elf linker hash table so
82
   we can store state variables and a secondary hash table without
83
   resorting to global variables.  */
84
struct elf32_mn10300_link_hash_table
85
{
86
  /* The main hash table.  */
87
  struct elf_link_hash_table root;
88
89
  /* A hash table for static functions.  We could derive a new hash table
90
     instead of using the full elf32_mn10300_link_hash_table if we wanted
91
     to save some memory.  */
92
  struct elf32_mn10300_link_hash_table *static_hash_table;
93
94
  /* Random linker state flags.  */
95
0
#define MN10300_HASH_ENTRIES_INITIALIZED 0x1
96
  char flags;
97
  struct
98
  {
99
    bfd_signed_vma  refcount;
100
    bfd_vma     offset;
101
    char      got_allocated;
102
    char      rel_emitted;
103
  } tls_ldm_got;
104
};
105
106
0
#define elf_mn10300_hash_entry(ent) ((struct elf32_mn10300_link_hash_entry *)(ent))
107
108
struct elf_mn10300_obj_tdata
109
{
110
  struct elf_obj_tdata root;
111
112
  /* tls_type for each local got entry.  */
113
  char * local_got_tls_type;
114
};
115
116
#define elf_mn10300_tdata(abfd) \
117
0
  ((struct elf_mn10300_obj_tdata *) (abfd)->tdata.any)
118
119
#define elf_mn10300_local_got_tls_type(abfd) \
120
0
  (elf_mn10300_tdata (abfd)->local_got_tls_type)
121
122
#ifndef streq
123
0
#define streq(a, b) (strcmp ((a),(b)) == 0)
124
#endif
125
126
/* For MN10300 linker hash table.  */
127
128
/* Get the MN10300 ELF linker hash table from a link_info structure.  */
129
130
#define elf32_mn10300_hash_table(p) \
131
0
  ((is_elf_hash_table ((p)->hash)          \
132
0
    && elf_hash_table_id (elf_hash_table (p)) == MN10300_ELF_DATA) \
133
0
   ? (struct elf32_mn10300_link_hash_table *) (p)->hash : NULL)
134
135
#define elf32_mn10300_link_hash_traverse(table, func, info)   \
136
0
  (elf_link_hash_traverse           \
137
0
   (&(table)->root,             \
138
0
    (bool (*) (struct elf_link_hash_entry *, void *)) (func),   \
139
0
    (info)))
140
141
static reloc_howto_type elf_mn10300_howto_table[] =
142
{
143
  /* Dummy relocation.  Does nothing.  */
144
  HOWTO (R_MN10300_NONE,
145
   0,
146
   0,
147
   0,
148
   false,
149
   0,
150
   complain_overflow_dont,
151
   bfd_elf_generic_reloc,
152
   "R_MN10300_NONE",
153
   false,
154
   0,
155
   0,
156
   false),
157
  /* Standard 32 bit reloc.  */
158
  HOWTO (R_MN10300_32,
159
   0,
160
   4,
161
   32,
162
   false,
163
   0,
164
   complain_overflow_bitfield,
165
   bfd_elf_generic_reloc,
166
   "R_MN10300_32",
167
   false,
168
   0xffffffff,
169
   0xffffffff,
170
   false),
171
  /* Standard 16 bit reloc.  */
172
  HOWTO (R_MN10300_16,
173
   0,
174
   2,
175
   16,
176
   false,
177
   0,
178
   complain_overflow_bitfield,
179
   bfd_elf_generic_reloc,
180
   "R_MN10300_16",
181
   false,
182
   0xffff,
183
   0xffff,
184
   false),
185
  /* Standard 8 bit reloc.  */
186
  HOWTO (R_MN10300_8,
187
   0,
188
   1,
189
   8,
190
   false,
191
   0,
192
   complain_overflow_bitfield,
193
   bfd_elf_generic_reloc,
194
   "R_MN10300_8",
195
   false,
196
   0xff,
197
   0xff,
198
   false),
199
  /* Standard 32bit pc-relative reloc.  */
200
  HOWTO (R_MN10300_PCREL32,
201
   0,
202
   4,
203
   32,
204
   true,
205
   0,
206
   complain_overflow_bitfield,
207
   bfd_elf_generic_reloc,
208
   "R_MN10300_PCREL32",
209
   false,
210
   0xffffffff,
211
   0xffffffff,
212
   true),
213
  /* Standard 16bit pc-relative reloc.  */
214
  HOWTO (R_MN10300_PCREL16,
215
   0,
216
   2,
217
   16,
218
   true,
219
   0,
220
   complain_overflow_bitfield,
221
   bfd_elf_generic_reloc,
222
   "R_MN10300_PCREL16",
223
   false,
224
   0xffff,
225
   0xffff,
226
   true),
227
  /* Standard 8 pc-relative reloc.  */
228
  HOWTO (R_MN10300_PCREL8,
229
   0,
230
   1,
231
   8,
232
   true,
233
   0,
234
   complain_overflow_bitfield,
235
   bfd_elf_generic_reloc,
236
   "R_MN10300_PCREL8",
237
   false,
238
   0xff,
239
   0xff,
240
   true),
241
242
  /* GNU extension to record C++ vtable hierarchy.  */
243
  HOWTO (R_MN10300_GNU_VTINHERIT, /* type */
244
   0,     /* rightshift */
245
   0,     /* size */
246
   0,     /* bitsize */
247
   false,     /* pc_relative */
248
   0,     /* bitpos */
249
   complain_overflow_dont, /* complain_on_overflow */
250
   NULL,      /* special_function */
251
   "R_MN10300_GNU_VTINHERIT", /* name */
252
   false,     /* partial_inplace */
253
   0,     /* src_mask */
254
   0,     /* dst_mask */
255
   false),    /* pcrel_offset */
256
257
  /* GNU extension to record C++ vtable member usage */
258
  HOWTO (R_MN10300_GNU_VTENTRY, /* type */
259
   0,     /* rightshift */
260
   0,     /* size */
261
   0,     /* bitsize */
262
   false,     /* pc_relative */
263
   0,     /* bitpos */
264
   complain_overflow_dont, /* complain_on_overflow */
265
   NULL,      /* special_function */
266
   "R_MN10300_GNU_VTENTRY", /* name */
267
   false,     /* partial_inplace */
268
   0,     /* src_mask */
269
   0,     /* dst_mask */
270
   false),    /* pcrel_offset */
271
272
  /* Standard 24 bit reloc.  */
273
  HOWTO (R_MN10300_24,
274
   0,
275
   4,
276
   24,
277
   false,
278
   0,
279
   complain_overflow_bitfield,
280
   bfd_elf_generic_reloc,
281
   "R_MN10300_24",
282
   false,
283
   0xffffff,
284
   0xffffff,
285
   false),
286
  HOWTO (R_MN10300_GOTPC32, /* type */
287
   0,     /* rightshift */
288
   4,     /* size */
289
   32,      /* bitsize */
290
   true,      /* pc_relative */
291
   0,     /* bitpos */
292
   complain_overflow_bitfield, /* complain_on_overflow */
293
   bfd_elf_generic_reloc, /* */
294
   "R_MN10300_GOTPC32", /* name */
295
   false,     /* partial_inplace */
296
   0xffffffff,    /* src_mask */
297
   0xffffffff,    /* dst_mask */
298
   true),     /* pcrel_offset */
299
300
  HOWTO (R_MN10300_GOTPC16, /* type */
301
   0,     /* rightshift */
302
   2,     /* size */
303
   16,      /* bitsize */
304
   true,      /* pc_relative */
305
   0,     /* bitpos */
306
   complain_overflow_bitfield, /* complain_on_overflow */
307
   bfd_elf_generic_reloc, /* */
308
   "R_MN10300_GOTPC16", /* name */
309
   false,     /* partial_inplace */
310
   0xffff,    /* src_mask */
311
   0xffff,    /* dst_mask */
312
   true),     /* pcrel_offset */
313
314
  HOWTO (R_MN10300_GOTOFF32,  /* type */
315
   0,     /* rightshift */
316
   4,     /* size */
317
   32,      /* bitsize */
318
   false,     /* pc_relative */
319
   0,     /* bitpos */
320
   complain_overflow_bitfield, /* complain_on_overflow */
321
   bfd_elf_generic_reloc, /* */
322
   "R_MN10300_GOTOFF32",  /* name */
323
   false,     /* partial_inplace */
324
   0xffffffff,    /* src_mask */
325
   0xffffffff,    /* dst_mask */
326
   false),    /* pcrel_offset */
327
328
  HOWTO (R_MN10300_GOTOFF24,  /* type */
329
   0,     /* rightshift */
330
   4,     /* size */
331
   24,      /* bitsize */
332
   false,     /* pc_relative */
333
   0,     /* bitpos */
334
   complain_overflow_bitfield, /* complain_on_overflow */
335
   bfd_elf_generic_reloc, /* */
336
   "R_MN10300_GOTOFF24",  /* name */
337
   false,     /* partial_inplace */
338
   0xffffff,    /* src_mask */
339
   0xffffff,    /* dst_mask */
340
   false),    /* pcrel_offset */
341
342
  HOWTO (R_MN10300_GOTOFF16,  /* type */
343
   0,     /* rightshift */
344
   2,     /* size */
345
   16,      /* bitsize */
346
   false,     /* pc_relative */
347
   0,     /* bitpos */
348
   complain_overflow_bitfield, /* complain_on_overflow */
349
   bfd_elf_generic_reloc, /* */
350
   "R_MN10300_GOTOFF16",  /* name */
351
   false,     /* partial_inplace */
352
   0xffff,    /* src_mask */
353
   0xffff,    /* dst_mask */
354
   false),    /* pcrel_offset */
355
356
  HOWTO (R_MN10300_PLT32, /* type */
357
   0,     /* rightshift */
358
   4,     /* size */
359
   32,      /* bitsize */
360
   true,      /* pc_relative */
361
   0,     /* bitpos */
362
   complain_overflow_bitfield, /* complain_on_overflow */
363
   bfd_elf_generic_reloc, /* */
364
   "R_MN10300_PLT32", /* name */
365
   false,     /* partial_inplace */
366
   0xffffffff,    /* src_mask */
367
   0xffffffff,    /* dst_mask */
368
   true),     /* pcrel_offset */
369
370
  HOWTO (R_MN10300_PLT16, /* type */
371
   0,     /* rightshift */
372
   2,     /* size */
373
   16,      /* bitsize */
374
   true,      /* pc_relative */
375
   0,     /* bitpos */
376
   complain_overflow_bitfield, /* complain_on_overflow */
377
   bfd_elf_generic_reloc, /* */
378
   "R_MN10300_PLT16", /* name */
379
   false,     /* partial_inplace */
380
   0xffff,    /* src_mask */
381
   0xffff,    /* dst_mask */
382
   true),     /* pcrel_offset */
383
384
  HOWTO (R_MN10300_GOT32, /* type */
385
   0,     /* rightshift */
386
   4,     /* size */
387
   32,      /* bitsize */
388
   false,     /* pc_relative */
389
   0,     /* bitpos */
390
   complain_overflow_bitfield, /* complain_on_overflow */
391
   bfd_elf_generic_reloc, /* */
392
   "R_MN10300_GOT32", /* name */
393
   false,     /* partial_inplace */
394
   0xffffffff,    /* src_mask */
395
   0xffffffff,    /* dst_mask */
396
   false),    /* pcrel_offset */
397
398
  HOWTO (R_MN10300_GOT24, /* type */
399
   0,     /* rightshift */
400
   4,     /* size */
401
   24,      /* bitsize */
402
   false,     /* pc_relative */
403
   0,     /* bitpos */
404
   complain_overflow_bitfield, /* complain_on_overflow */
405
   bfd_elf_generic_reloc, /* */
406
   "R_MN10300_GOT24", /* name */
407
   false,     /* partial_inplace */
408
   0xffffffff,    /* src_mask */
409
   0xffffffff,    /* dst_mask */
410
   false),    /* pcrel_offset */
411
412
  HOWTO (R_MN10300_GOT16, /* type */
413
   0,     /* rightshift */
414
   2,     /* size */
415
   16,      /* bitsize */
416
   false,     /* pc_relative */
417
   0,     /* bitpos */
418
   complain_overflow_bitfield, /* complain_on_overflow */
419
   bfd_elf_generic_reloc, /* */
420
   "R_MN10300_GOT16", /* name */
421
   false,     /* partial_inplace */
422
   0xffffffff,    /* src_mask */
423
   0xffffffff,    /* dst_mask */
424
   false),    /* pcrel_offset */
425
426
  HOWTO (R_MN10300_COPY,  /* type */
427
   0,     /* rightshift */
428
   4,     /* size */
429
   32,      /* bitsize */
430
   false,     /* pc_relative */
431
   0,     /* bitpos */
432
   complain_overflow_bitfield, /* complain_on_overflow */
433
   bfd_elf_generic_reloc, /* */
434
   "R_MN10300_COPY",    /* name */
435
   false,     /* partial_inplace */
436
   0xffffffff,    /* src_mask */
437
   0xffffffff,    /* dst_mask */
438
   false),    /* pcrel_offset */
439
440
  HOWTO (R_MN10300_GLOB_DAT,  /* type */
441
   0,     /* rightshift */
442
   4,     /* size */
443
   32,      /* bitsize */
444
   false,     /* pc_relative */
445
   0,     /* bitpos */
446
   complain_overflow_bitfield, /* complain_on_overflow */
447
   bfd_elf_generic_reloc, /* */
448
   "R_MN10300_GLOB_DAT",  /* name */
449
   false,     /* partial_inplace */
450
   0xffffffff,    /* src_mask */
451
   0xffffffff,    /* dst_mask */
452
   false),    /* pcrel_offset */
453
454
  HOWTO (R_MN10300_JMP_SLOT,  /* type */
455
   0,     /* rightshift */
456
   4,     /* size */
457
   32,      /* bitsize */
458
   false,     /* pc_relative */
459
   0,     /* bitpos */
460
   complain_overflow_bitfield, /* complain_on_overflow */
461
   bfd_elf_generic_reloc, /* */
462
   "R_MN10300_JMP_SLOT",  /* name */
463
   false,     /* partial_inplace */
464
   0xffffffff,    /* src_mask */
465
   0xffffffff,    /* dst_mask */
466
   false),    /* pcrel_offset */
467
468
  HOWTO (R_MN10300_RELATIVE,  /* type */
469
   0,     /* rightshift */
470
   4,     /* size */
471
   32,      /* bitsize */
472
   false,     /* pc_relative */
473
   0,     /* bitpos */
474
   complain_overflow_bitfield, /* complain_on_overflow */
475
   bfd_elf_generic_reloc, /* */
476
   "R_MN10300_RELATIVE",  /* name */
477
   false,     /* partial_inplace */
478
   0xffffffff,    /* src_mask */
479
   0xffffffff,    /* dst_mask */
480
   false),    /* pcrel_offset */
481
482
  HOWTO (R_MN10300_TLS_GD,  /* type */
483
   0,     /* rightshift */
484
   4,     /* size */
485
   32,      /* bitsize */
486
   false,     /* pc_relative */
487
   0,     /* bitpos */
488
   complain_overflow_bitfield, /* complain_on_overflow */
489
   bfd_elf_generic_reloc, /* */
490
   "R_MN10300_TLS_GD",  /* name */
491
   false,     /* partial_inplace */
492
   0xffffffff,    /* src_mask */
493
   0xffffffff,    /* dst_mask */
494
   false),    /* pcrel_offset */
495
496
  HOWTO (R_MN10300_TLS_LD,  /* type */
497
   0,     /* rightshift */
498
   4,     /* size */
499
   32,      /* bitsize */
500
   false,     /* pc_relative */
501
   0,     /* bitpos */
502
   complain_overflow_bitfield, /* complain_on_overflow */
503
   bfd_elf_generic_reloc, /* */
504
   "R_MN10300_TLS_LD",  /* name */
505
   false,     /* partial_inplace */
506
   0xffffffff,    /* src_mask */
507
   0xffffffff,    /* dst_mask */
508
   false),    /* pcrel_offset */
509
510
  HOWTO (R_MN10300_TLS_LDO, /* type */
511
   0,     /* rightshift */
512
   4,     /* size */
513
   32,      /* bitsize */
514
   false,     /* pc_relative */
515
   0,     /* bitpos */
516
   complain_overflow_bitfield, /* complain_on_overflow */
517
   bfd_elf_generic_reloc, /* */
518
   "R_MN10300_TLS_LDO", /* name */
519
   false,     /* partial_inplace */
520
   0xffffffff,    /* src_mask */
521
   0xffffffff,    /* dst_mask */
522
   false),    /* pcrel_offset */
523
524
  HOWTO (R_MN10300_TLS_GOTIE, /* type */
525
   0,     /* rightshift */
526
   4,     /* size */
527
   32,      /* bitsize */
528
   false,     /* pc_relative */
529
   0,     /* bitpos */
530
   complain_overflow_bitfield, /* complain_on_overflow */
531
   bfd_elf_generic_reloc, /* */
532
   "R_MN10300_TLS_GOTIE", /* name */
533
   false,     /* partial_inplace */
534
   0xffffffff,    /* src_mask */
535
   0xffffffff,    /* dst_mask */
536
   false),    /* pcrel_offset */
537
538
  HOWTO (R_MN10300_TLS_IE,  /* type */
539
   0,     /* rightshift */
540
   4,     /* size */
541
   32,      /* bitsize */
542
   false,     /* pc_relative */
543
   0,     /* bitpos */
544
   complain_overflow_bitfield, /* complain_on_overflow */
545
   bfd_elf_generic_reloc, /* */
546
   "R_MN10300_TLS_IE",  /* name */
547
   false,     /* partial_inplace */
548
   0xffffffff,    /* src_mask */
549
   0xffffffff,    /* dst_mask */
550
   false),    /* pcrel_offset */
551
552
  HOWTO (R_MN10300_TLS_LE,  /* type */
553
   0,     /* rightshift */
554
   4,     /* size */
555
   32,      /* bitsize */
556
   false,     /* pc_relative */
557
   0,     /* bitpos */
558
   complain_overflow_bitfield, /* complain_on_overflow */
559
   bfd_elf_generic_reloc, /* */
560
   "R_MN10300_TLS_LE",  /* name */
561
   false,     /* partial_inplace */
562
   0xffffffff,    /* src_mask */
563
   0xffffffff,    /* dst_mask */
564
   false),    /* pcrel_offset */
565
566
  HOWTO (R_MN10300_TLS_DTPMOD,  /* type */
567
   0,     /* rightshift */
568
   4,     /* size */
569
   32,      /* bitsize */
570
   false,     /* pc_relative */
571
   0,     /* bitpos */
572
   complain_overflow_bitfield, /* complain_on_overflow */
573
   bfd_elf_generic_reloc, /* */
574
   "R_MN10300_TLS_DTPMOD",  /* name */
575
   false,     /* partial_inplace */
576
   0xffffffff,    /* src_mask */
577
   0xffffffff,    /* dst_mask */
578
   false),    /* pcrel_offset */
579
580
  HOWTO (R_MN10300_TLS_DTPOFF,  /* type */
581
   0,     /* rightshift */
582
   4,     /* size */
583
   32,      /* bitsize */
584
   false,     /* pc_relative */
585
   0,     /* bitpos */
586
   complain_overflow_bitfield, /* complain_on_overflow */
587
   bfd_elf_generic_reloc, /* */
588
   "R_MN10300_TLS_DTPOFF",  /* name */
589
   false,     /* partial_inplace */
590
   0xffffffff,    /* src_mask */
591
   0xffffffff,    /* dst_mask */
592
   false),    /* pcrel_offset */
593
594
  HOWTO (R_MN10300_TLS_TPOFF, /* type */
595
   0,     /* rightshift */
596
   4,     /* size */
597
   32,      /* bitsize */
598
   false,     /* pc_relative */
599
   0,     /* bitpos */
600
   complain_overflow_bitfield, /* complain_on_overflow */
601
   bfd_elf_generic_reloc, /* */
602
   "R_MN10300_TLS_TPOFF", /* name */
603
   false,     /* partial_inplace */
604
   0xffffffff,    /* src_mask */
605
   0xffffffff,    /* dst_mask */
606
   false),    /* pcrel_offset */
607
608
  HOWTO (R_MN10300_SYM_DIFF,  /* type */
609
   0,     /* rightshift */
610
   4,     /* size */
611
   32,      /* bitsize */
612
   false,     /* pc_relative */
613
   0,     /* bitpos */
614
   complain_overflow_dont,/* complain_on_overflow */
615
   NULL,      /* special handler.  */
616
   "R_MN10300_SYM_DIFF",  /* name */
617
   false,     /* partial_inplace */
618
   0xffffffff,    /* src_mask */
619
   0xffffffff,    /* dst_mask */
620
   false),    /* pcrel_offset */
621
622
  HOWTO (R_MN10300_ALIGN, /* type */
623
   0,     /* rightshift */
624
   1,     /* size */
625
   32,      /* bitsize */
626
   false,     /* pc_relative */
627
   0,     /* bitpos */
628
   complain_overflow_dont,/* complain_on_overflow */
629
   NULL,      /* special handler.  */
630
   "R_MN10300_ALIGN", /* name */
631
   false,     /* partial_inplace */
632
   0,     /* src_mask */
633
   0,     /* dst_mask */
634
   false)     /* pcrel_offset */
635
};
636
637
struct mn10300_reloc_map
638
{
639
  bfd_reloc_code_real_type bfd_reloc_val;
640
  unsigned char elf_reloc_val;
641
};
642
643
static const struct mn10300_reloc_map mn10300_reloc_map[] =
644
{
645
  { BFD_RELOC_NONE, R_MN10300_NONE, },
646
  { BFD_RELOC_32, R_MN10300_32, },
647
  { BFD_RELOC_16, R_MN10300_16, },
648
  { BFD_RELOC_8, R_MN10300_8, },
649
  { BFD_RELOC_32_PCREL, R_MN10300_PCREL32, },
650
  { BFD_RELOC_16_PCREL, R_MN10300_PCREL16, },
651
  { BFD_RELOC_8_PCREL, R_MN10300_PCREL8, },
652
  { BFD_RELOC_24, R_MN10300_24, },
653
  { BFD_RELOC_VTABLE_INHERIT, R_MN10300_GNU_VTINHERIT },
654
  { BFD_RELOC_VTABLE_ENTRY, R_MN10300_GNU_VTENTRY },
655
  { BFD_RELOC_32_GOT_PCREL, R_MN10300_GOTPC32 },
656
  { BFD_RELOC_16_GOT_PCREL, R_MN10300_GOTPC16 },
657
  { BFD_RELOC_32_GOTOFF, R_MN10300_GOTOFF32 },
658
  { BFD_RELOC_MN10300_GOTOFF24, R_MN10300_GOTOFF24 },
659
  { BFD_RELOC_16_GOTOFF, R_MN10300_GOTOFF16 },
660
  { BFD_RELOC_32_PLT_PCREL, R_MN10300_PLT32 },
661
  { BFD_RELOC_16_PLT_PCREL, R_MN10300_PLT16 },
662
  { BFD_RELOC_MN10300_GOT32, R_MN10300_GOT32 },
663
  { BFD_RELOC_MN10300_GOT24, R_MN10300_GOT24 },
664
  { BFD_RELOC_MN10300_GOT16, R_MN10300_GOT16 },
665
  { BFD_RELOC_COPY, R_MN10300_COPY },
666
  { BFD_RELOC_GLOB_DAT, R_MN10300_GLOB_DAT },
667
  { BFD_RELOC_JMP_SLOT, R_MN10300_JMP_SLOT },
668
  { BFD_RELOC_RELATIVE, R_MN10300_RELATIVE },
669
  { BFD_RELOC_MN10300_TLS_GD, R_MN10300_TLS_GD },
670
  { BFD_RELOC_MN10300_TLS_LD, R_MN10300_TLS_LD },
671
  { BFD_RELOC_MN10300_TLS_LDO, R_MN10300_TLS_LDO },
672
  { BFD_RELOC_MN10300_TLS_GOTIE, R_MN10300_TLS_GOTIE },
673
  { BFD_RELOC_MN10300_TLS_IE, R_MN10300_TLS_IE },
674
  { BFD_RELOC_MN10300_TLS_LE, R_MN10300_TLS_LE },
675
  { BFD_RELOC_MN10300_TLS_DTPMOD, R_MN10300_TLS_DTPMOD },
676
  { BFD_RELOC_MN10300_TLS_DTPOFF, R_MN10300_TLS_DTPOFF },
677
  { BFD_RELOC_MN10300_TLS_TPOFF, R_MN10300_TLS_TPOFF },
678
  { BFD_RELOC_MN10300_SYM_DIFF, R_MN10300_SYM_DIFF },
679
  { BFD_RELOC_MN10300_ALIGN, R_MN10300_ALIGN }
680
};
681
682
/* Create the GOT section.  */
683
684
static bool
685
_bfd_mn10300_elf_create_got_section (bfd * abfd,
686
             struct bfd_link_info * info)
687
0
{
688
0
  flagword   flags;
689
0
  flagword   pltflags;
690
0
  asection * s;
691
0
  struct elf_link_hash_entry * h;
692
0
  elf_backend_data * bed = get_elf_backend_data (abfd);
693
0
  struct elf_link_hash_table *htab;
694
0
  int ptralign;
695
696
  /* This function may be called more than once.  */
697
0
  htab = elf_hash_table (info);
698
0
  if (htab->sgot != NULL)
699
0
    return true;
700
701
0
  switch (bed->s->arch_size)
702
0
    {
703
0
    case 32:
704
0
      ptralign = 2;
705
0
      break;
706
707
0
    case 64:
708
0
      ptralign = 3;
709
0
      break;
710
711
0
    default:
712
0
      bfd_set_error (bfd_error_bad_value);
713
0
      return false;
714
0
    }
715
716
0
  flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
717
0
     | SEC_LINKER_CREATED);
718
719
0
  pltflags = flags;
720
0
  pltflags |= SEC_CODE;
721
0
  if (bed->plt_not_loaded)
722
0
    pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
723
0
  if (bed->plt_readonly)
724
0
    pltflags |= SEC_READONLY;
725
726
0
  s = bfd_make_section_anyway_with_flags (abfd, ".plt", pltflags);
727
0
  htab->splt = s;
728
0
  if (s == NULL
729
0
      || !bfd_set_section_alignment (s, bed->plt_alignment))
730
0
    return false;
731
732
  /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
733
     .plt section.  */
734
0
  if (bed->want_plt_sym)
735
0
    {
736
0
      h = _bfd_elf_define_linkage_sym (abfd, info, s,
737
0
               "_PROCEDURE_LINKAGE_TABLE_");
738
0
      htab->hplt = h;
739
0
      if (h == NULL)
740
0
  return false;
741
0
    }
742
743
0
  s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
744
0
  htab->sgot = s;
745
0
  if (s == NULL
746
0
      || !bfd_set_section_alignment (s, ptralign))
747
0
    return false;
748
749
0
  if (bed->want_got_plt)
750
0
    {
751
0
      s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags);
752
0
      htab->sgotplt = s;
753
0
      if (s == NULL
754
0
    || !bfd_set_section_alignment (s, ptralign))
755
0
  return false;
756
0
    }
757
758
  /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
759
     (or .got.plt) section.  We don't do this in the linker script
760
     because we don't want to define the symbol if we are not creating
761
     a global offset table.  */
762
0
  h = _bfd_elf_define_linkage_sym (abfd, info, s, "_GLOBAL_OFFSET_TABLE_");
763
0
  htab->hgot = h;
764
0
  if (h == NULL)
765
0
    return false;
766
767
  /* The first bit of the global offset table is the header.  */
768
0
  s->size += bed->got_header_size;
769
770
0
  return true;
771
0
}
Unexecuted instantiation: elf-m10300.c:_bfd_mn10300_elf_create_got_section
Unexecuted instantiation: elf32-am33lin.c:_bfd_mn10300_elf_create_got_section
772
773
static reloc_howto_type *
774
bfd_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
775
         bfd_reloc_code_real_type code)
776
0
{
777
0
  unsigned int i;
778
779
0
  for (i = ARRAY_SIZE (mn10300_reloc_map); i--;)
780
0
    if (mn10300_reloc_map[i].bfd_reloc_val == code)
781
0
      return &elf_mn10300_howto_table[mn10300_reloc_map[i].elf_reloc_val];
782
783
0
  return NULL;
784
0
}
Unexecuted instantiation: elf-m10300.c:bfd_elf32_bfd_reloc_type_lookup
Unexecuted instantiation: elf32-am33lin.c:bfd_elf32_bfd_reloc_type_lookup
785
786
static reloc_howto_type *
787
bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
788
         const char *r_name)
789
0
{
790
0
  unsigned int i;
791
792
0
  for (i = ARRAY_SIZE (elf_mn10300_howto_table); i--;)
793
0
    if (elf_mn10300_howto_table[i].name != NULL
794
0
  && strcasecmp (elf_mn10300_howto_table[i].name, r_name) == 0)
795
0
      return elf_mn10300_howto_table + i;
796
797
0
  return NULL;
798
0
}
Unexecuted instantiation: elf-m10300.c:bfd_elf32_bfd_reloc_name_lookup
Unexecuted instantiation: elf32-am33lin.c:bfd_elf32_bfd_reloc_name_lookup
799
800
/* Set the howto pointer for an MN10300 ELF reloc.  */
801
802
static bool
803
mn10300_info_to_howto (bfd *abfd,
804
           arelent *cache_ptr,
805
           Elf_Internal_Rela *dst)
806
266
{
807
266
  unsigned int r_type;
808
809
266
  r_type = ELF32_R_TYPE (dst->r_info);
810
266
  if (r_type >= R_MN10300_MAX)
811
18
    {
812
      /* xgettext:c-format */
813
18
      _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
814
18
        abfd, r_type);
815
18
      bfd_set_error (bfd_error_bad_value);
816
18
      return false;
817
18
    }
818
248
  cache_ptr->howto = elf_mn10300_howto_table + r_type;
819
248
  return true;
820
266
}
Unexecuted instantiation: elf-m10300.c:mn10300_info_to_howto
elf32-am33lin.c:mn10300_info_to_howto
Line
Count
Source
806
266
{
807
266
  unsigned int r_type;
808
809
266
  r_type = ELF32_R_TYPE (dst->r_info);
810
266
  if (r_type >= R_MN10300_MAX)
811
18
    {
812
      /* xgettext:c-format */
813
18
      _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
814
18
        abfd, r_type);
815
18
      bfd_set_error (bfd_error_bad_value);
816
18
      return false;
817
18
    }
818
248
  cache_ptr->howto = elf_mn10300_howto_table + r_type;
819
  return true;
820
266
}
821
822
static int
823
elf_mn10300_tls_transition (struct bfd_link_info *    info,
824
          int         r_type,
825
          struct elf_link_hash_entry *  h,
826
          asection *        sec,
827
          bool        counting)
828
0
{
829
0
  bool is_local;
830
831
0
  if (r_type == R_MN10300_TLS_GD
832
0
      && h != NULL
833
0
      && elf_mn10300_hash_entry (h)->tls_type == GOT_TLS_IE)
834
0
    return R_MN10300_TLS_GOTIE;
835
836
0
  if (bfd_link_pic (info))
837
0
    return r_type;
838
839
0
  if (! (sec->flags & SEC_CODE))
840
0
    return r_type;
841
842
0
  if (! counting && h != NULL && ! elf_hash_table (info)->dynamic_sections_created)
843
0
    is_local = true;
844
0
  else
845
0
    is_local = SYMBOL_CALLS_LOCAL (info, h);
846
847
  /* For the main program, these are the transitions we do.  */
848
0
  switch (r_type)
849
0
    {
850
0
    case R_MN10300_TLS_GD: return is_local ? R_MN10300_TLS_LE : R_MN10300_TLS_GOTIE;
851
0
    case R_MN10300_TLS_LD: return R_MN10300_NONE;
852
0
    case R_MN10300_TLS_LDO: return R_MN10300_TLS_LE;
853
0
    case R_MN10300_TLS_IE:
854
0
    case R_MN10300_TLS_GOTIE: return is_local ? R_MN10300_TLS_LE : r_type;
855
0
    }
856
857
0
  return r_type;
858
0
}
Unexecuted instantiation: elf-m10300.c:elf_mn10300_tls_transition
Unexecuted instantiation: elf32-am33lin.c:elf_mn10300_tls_transition
859
860
/* Return the relocation value for @tpoff relocation
861
   if STT_TLS virtual address is ADDRESS.  */
862
863
static bfd_vma
864
dtpoff (struct bfd_link_info * info, bfd_vma address)
865
0
{
866
0
  struct elf_link_hash_table *htab = elf_hash_table (info);
867
868
  /* If tls_sec is NULL, we should have signalled an error already.  */
869
0
  if (htab->tls_sec == NULL)
870
0
    return 0;
871
0
  return address - htab->tls_sec->vma;
872
0
}
Unexecuted instantiation: elf-m10300.c:dtpoff
Unexecuted instantiation: elf32-am33lin.c:dtpoff
873
874
/* Return the relocation value for @tpoff relocation
875
   if STT_TLS virtual address is ADDRESS.  */
876
877
static bfd_vma
878
tpoff (struct bfd_link_info * info, bfd_vma address)
879
0
{
880
0
  struct elf_link_hash_table *htab = elf_hash_table (info);
881
882
  /* If tls_sec is NULL, we should have signalled an error already.  */
883
0
  if (htab->tls_sec == NULL)
884
0
    return 0;
885
0
  return address - (htab->tls_size + htab->tls_sec->vma);
886
0
}
Unexecuted instantiation: elf-m10300.c:tpoff
Unexecuted instantiation: elf32-am33lin.c:tpoff
887
888
/* Returns nonzero if there's a R_MN10300_PLT32 reloc that we now need
889
   to skip, after this one.  The actual value is the offset between
890
   this reloc and the PLT reloc.  */
891
892
static int
893
mn10300_do_tls_transition (bfd *   input_bfd,
894
         unsigned int  r_type,
895
         unsigned int  tls_r_type,
896
         bfd_byte *  contents,
897
         bfd_vma   offset)
898
0
{
899
0
  bfd_byte *op = contents + offset;
900
0
  int gotreg = 0;
901
902
0
#define TLS_PAIR(r1,r2) ((r1) * R_MN10300_MAX + (r2))
903
904
  /* This is common to all GD/LD transitions, so break it out.  */
905
0
  if (r_type == R_MN10300_TLS_GD
906
0
      || r_type == R_MN10300_TLS_LD)
907
0
    {
908
0
      op -= 2;
909
      /* mov imm,d0.  */
910
0
      BFD_ASSERT (bfd_get_8 (input_bfd, op) == 0xFC);
911
0
      BFD_ASSERT (bfd_get_8 (input_bfd, op + 1) == 0xCC);
912
      /* add aN,d0.  */
913
0
      BFD_ASSERT (bfd_get_8 (input_bfd, op + 6) == 0xF1);
914
0
      gotreg = (bfd_get_8 (input_bfd, op + 7) & 0x0c) >> 2;
915
      /* Call.  */
916
0
      BFD_ASSERT (bfd_get_8 (input_bfd, op + 8) == 0xDD);
917
0
    }
918
919
0
  switch (TLS_PAIR (r_type, tls_r_type))
920
0
    {
921
0
    case TLS_PAIR (R_MN10300_TLS_GD, R_MN10300_TLS_GOTIE):
922
0
      {
923
  /* Keep track of which register we put GOTptr in.  */
924
  /* mov (_x@indntpoff,a2),a0.  */
925
0
  memcpy (op, "\xFC\x20\x00\x00\x00\x00", 6);
926
0
  op[1] |= gotreg;
927
  /* add e2,a0.  */
928
0
  memcpy (op+6, "\xF9\x78\x28", 3);
929
  /* or  0x00000000, d0 - six byte nop.  */
930
0
  memcpy (op+9, "\xFC\xE4\x00\x00\x00\x00", 6);
931
0
      }
932
0
      return 7;
933
934
0
    case TLS_PAIR (R_MN10300_TLS_GD, R_MN10300_TLS_LE):
935
0
      {
936
  /* Register is *always* a0.  */
937
  /* mov _x@tpoff,a0.  */
938
0
  memcpy (op, "\xFC\xDC\x00\x00\x00\x00", 6);
939
  /* add e2,a0.  */
940
0
  memcpy (op+6, "\xF9\x78\x28", 3);
941
  /* or  0x00000000, d0 - six byte nop.  */
942
0
  memcpy (op+9, "\xFC\xE4\x00\x00\x00\x00", 6);
943
0
      }
944
0
      return 7;
945
0
    case TLS_PAIR (R_MN10300_TLS_LD, R_MN10300_NONE):
946
0
      {
947
  /* Register is *always* a0.  */
948
  /* mov e2,a0.  */
949
0
  memcpy (op, "\xF5\x88", 2);
950
  /* or  0x00000000, d0 - six byte nop.  */
951
0
  memcpy (op+2, "\xFC\xE4\x00\x00\x00\x00", 6);
952
  /* or  0x00000000, e2 - seven byte nop.  */
953
0
  memcpy (op+8, "\xFE\x19\x22\x00\x00\x00\x00", 7);
954
0
      }
955
0
      return 7;
956
957
0
    case TLS_PAIR (R_MN10300_TLS_LDO, R_MN10300_TLS_LE):
958
      /* No changes needed, just the reloc change.  */
959
0
      return 0;
960
961
    /*  These are a little tricky, because we have to detect which
962
  opcode is being used (they're different sizes, with the reloc
963
  at different offsets within the opcode) and convert each
964
  accordingly, copying the operands as needed.  The conversions
965
  we do are as follows (IE,GOTIE,LE):
966
967
       1111 1100  1010 01Dn  [-- abs32 --]  MOV (x@indntpoff),Dn
968
       1111 1100  0000 DnAm  [-- abs32 --]  MOV (x@gotntpoff,Am),Dn
969
       1111 1100  1100 11Dn  [-- abs32 --]  MOV x@tpoff,Dn
970
971
       1111 1100  1010 00An  [-- abs32 --]  MOV (x@indntpoff),An
972
       1111 1100  0010 AnAm  [-- abs32 --]  MOV (x@gotntpoff,Am),An
973
       1111 1100  1101 11An  [-- abs32 --]  MOV x@tpoff,An
974
975
  1111 1110  0000 1110  Rnnn Xxxx  [-- abs32 --]  MOV (x@indntpoff),Rn
976
  1111 1110  0000 1010  Rnnn Rmmm  [-- abs32 --]  MOV (x@indntpoff,Rm),Rn
977
  1111 1110  0000 1000  Rnnn Xxxx  [-- abs32 --]  MOV x@tpoff,Rn
978
979
  Since the GOT pointer is always $a2, we assume the last
980
  normally won't happen, but let's be paranoid and plan for the
981
  day that GCC optimizes it somewhow.  */
982
983
0
    case TLS_PAIR (R_MN10300_TLS_IE, R_MN10300_TLS_LE):
984
0
      if (op[-2] == 0xFC)
985
0
  {
986
0
    op -= 2;
987
0
    if ((op[1] & 0xFC) == 0xA4) /* Dn */
988
0
      {
989
0
        op[1] &= 0x03; /* Leaves Dn.  */
990
0
        op[1] |= 0xCC;
991
0
      }
992
0
    else /* An */
993
0
      {
994
0
        op[1] &= 0x03; /* Leaves An. */
995
0
        op[1] |= 0xDC;
996
0
      }
997
0
  }
998
0
      else if (op[-3] == 0xFE)
999
0
  op[-2] = 0x08;
1000
0
      else
1001
0
  abort ();
1002
0
      break;
1003
1004
0
    case TLS_PAIR (R_MN10300_TLS_GOTIE, R_MN10300_TLS_LE):
1005
0
      if (op[-2] == 0xFC)
1006
0
  {
1007
0
    op -= 2;
1008
0
    if ((op[1] & 0xF0) == 0x00) /* Dn */
1009
0
      {
1010
0
        op[1] &= 0x0C; /* Leaves Dn.  */
1011
0
        op[1] >>= 2;
1012
0
        op[1] |= 0xCC;
1013
0
      }
1014
0
    else /* An */
1015
0
      {
1016
0
        op[1] &= 0x0C; /* Leaves An.  */
1017
0
        op[1] >>= 2;
1018
0
        op[1] |= 0xDC;
1019
0
      }
1020
0
  }
1021
0
      else if (op[-3] == 0xFE)
1022
0
  op[-2] = 0x08;
1023
0
      else
1024
0
  abort ();
1025
0
      break;
1026
1027
0
    default:
1028
0
      _bfd_error_handler
1029
  /* xgettext:c-format */
1030
0
  (_("%pB: unsupported transition from %s to %s"),
1031
0
   input_bfd,
1032
0
   elf_mn10300_howto_table[r_type].name,
1033
0
   elf_mn10300_howto_table[tls_r_type].name);
1034
0
      break;
1035
0
    }
1036
0
#undef TLS_PAIR
1037
0
  return 0;
1038
0
}
Unexecuted instantiation: elf-m10300.c:mn10300_do_tls_transition
Unexecuted instantiation: elf32-am33lin.c:mn10300_do_tls_transition
1039
1040
/* Look through the relocs for a section during the first phase.
1041
   Since we don't do .gots or .plts, we just need to consider the
1042
   virtual table relocs for gc.  */
1043
1044
static bool
1045
mn10300_elf_check_relocs (bfd *abfd,
1046
        struct bfd_link_info *info,
1047
        asection *sec,
1048
        const Elf_Internal_Rela *relocs)
1049
0
{
1050
0
  struct elf32_mn10300_link_hash_table * htab = elf32_mn10300_hash_table (info);
1051
0
  bool sym_diff_reloc_seen;
1052
0
  Elf_Internal_Shdr *symtab_hdr;
1053
0
  Elf_Internal_Sym * isymbuf = NULL;
1054
0
  struct elf_link_hash_entry **sym_hashes;
1055
0
  const Elf_Internal_Rela *rel;
1056
0
  const Elf_Internal_Rela *rel_end;
1057
0
  bfd *      dynobj;
1058
0
  bfd_vma *  local_got_offsets;
1059
0
  asection * sgot;
1060
0
  asection * srelgot;
1061
0
  asection * sreloc;
1062
0
  bool result = false;
1063
1064
0
  sgot    = NULL;
1065
0
  srelgot = NULL;
1066
0
  sreloc  = NULL;
1067
1068
0
  if (bfd_link_relocatable (info))
1069
0
    return true;
1070
1071
0
  symtab_hdr = &elf_symtab_hdr (abfd);
1072
0
  isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
1073
0
  sym_hashes = elf_sym_hashes (abfd);
1074
1075
0
  dynobj = elf_hash_table (info)->dynobj;
1076
0
  local_got_offsets = elf_local_got_offsets (abfd);
1077
0
  rel_end = relocs + sec->reloc_count;
1078
0
  sym_diff_reloc_seen = false;
1079
1080
0
  for (rel = relocs; rel < rel_end; rel++)
1081
0
    {
1082
0
      struct elf_link_hash_entry *h;
1083
0
      unsigned long r_symndx;
1084
0
      unsigned int r_type;
1085
0
      int tls_type = GOT_NORMAL;
1086
1087
0
      r_symndx = ELF32_R_SYM (rel->r_info);
1088
0
      if (r_symndx < symtab_hdr->sh_info)
1089
0
  h = NULL;
1090
0
      else
1091
0
  {
1092
0
    h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1093
0
    while (h->root.type == bfd_link_hash_indirect
1094
0
     || h->root.type == bfd_link_hash_warning)
1095
0
      h = (struct elf_link_hash_entry *) h->root.u.i.link;
1096
0
  }
1097
1098
0
      r_type = ELF32_R_TYPE (rel->r_info);
1099
0
      r_type = elf_mn10300_tls_transition (info, r_type, h, sec, true);
1100
1101
      /* Some relocs require a global offset table.  */
1102
0
      if (dynobj == NULL)
1103
0
  {
1104
0
    switch (r_type)
1105
0
      {
1106
0
      case R_MN10300_GOT32:
1107
0
      case R_MN10300_GOT24:
1108
0
      case R_MN10300_GOT16:
1109
0
      case R_MN10300_GOTOFF32:
1110
0
      case R_MN10300_GOTOFF24:
1111
0
      case R_MN10300_GOTOFF16:
1112
0
      case R_MN10300_GOTPC32:
1113
0
      case R_MN10300_GOTPC16:
1114
0
      case R_MN10300_TLS_GD:
1115
0
      case R_MN10300_TLS_LD:
1116
0
      case R_MN10300_TLS_GOTIE:
1117
0
      case R_MN10300_TLS_IE:
1118
0
        dynobj = _bfd_elf_link_dynobj (info);
1119
0
        if (dynobj == NULL)
1120
0
    goto fail;
1121
0
        if (! _bfd_mn10300_elf_create_got_section (dynobj, info))
1122
0
    goto fail;
1123
0
        break;
1124
1125
0
      default:
1126
0
        break;
1127
0
      }
1128
0
  }
1129
1130
0
      switch (r_type)
1131
0
  {
1132
  /* This relocation describes the C++ object vtable hierarchy.
1133
     Reconstruct it for later use during GC.  */
1134
0
  case R_MN10300_GNU_VTINHERIT:
1135
0
    if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
1136
0
      goto fail;
1137
0
    break;
1138
1139
  /* This relocation describes which C++ vtable entries are actually
1140
     used.  Record for later use during GC.  */
1141
0
  case R_MN10300_GNU_VTENTRY:
1142
0
    if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
1143
0
      goto fail;
1144
0
    break;
1145
1146
0
  case R_MN10300_TLS_LD:
1147
0
    htab->tls_ldm_got.refcount ++;
1148
0
    tls_type = GOT_TLS_LD;
1149
1150
0
    if (htab->tls_ldm_got.got_allocated)
1151
0
      break;
1152
0
    goto create_got;
1153
1154
0
  case R_MN10300_TLS_IE:
1155
0
  case R_MN10300_TLS_GOTIE:
1156
0
    if (bfd_link_pic (info))
1157
0
      info->flags |= DF_STATIC_TLS;
1158
    /* Fall through */
1159
1160
0
  case R_MN10300_TLS_GD:
1161
0
  case R_MN10300_GOT32:
1162
0
  case R_MN10300_GOT24:
1163
0
  case R_MN10300_GOT16:
1164
0
  create_got:
1165
    /* This symbol requires a global offset table entry.  */
1166
1167
0
    switch (r_type)
1168
0
      {
1169
0
      case R_MN10300_TLS_IE:
1170
0
      case R_MN10300_TLS_GOTIE: tls_type = GOT_TLS_IE; break;
1171
0
      case R_MN10300_TLS_GD:    tls_type = GOT_TLS_GD; break;
1172
0
      default:          tls_type = GOT_NORMAL; break;
1173
0
      }
1174
1175
0
    sgot = htab->root.sgot;
1176
0
    srelgot = htab->root.srelgot;
1177
0
    BFD_ASSERT (sgot != NULL && srelgot != NULL);
1178
1179
0
    if (r_type == R_MN10300_TLS_LD)
1180
0
      {
1181
0
        htab->tls_ldm_got.offset = sgot->size;
1182
0
        htab->tls_ldm_got.got_allocated ++;
1183
0
      }
1184
0
    else if (h != NULL)
1185
0
      {
1186
0
        if (elf_mn10300_hash_entry (h)->tls_type != tls_type
1187
0
      && elf_mn10300_hash_entry (h)->tls_type != GOT_UNKNOWN)
1188
0
    {
1189
0
      if (tls_type == GOT_TLS_IE
1190
0
          && elf_mn10300_hash_entry (h)->tls_type == GOT_TLS_GD)
1191
0
        /* No change - this is ok.  */;
1192
0
      else if (tls_type == GOT_TLS_GD
1193
0
          && elf_mn10300_hash_entry (h)->tls_type == GOT_TLS_IE)
1194
        /* Transition GD->IE.  */
1195
0
        tls_type = GOT_TLS_IE;
1196
0
      else
1197
0
        _bfd_error_handler
1198
          /* xgettext:c-format */
1199
0
          (_("%pB: %s' accessed both as normal and thread local symbol"),
1200
0
           abfd, h ? h->root.root.string : "<local>");
1201
0
    }
1202
1203
0
        elf_mn10300_hash_entry (h)->tls_type = tls_type;
1204
1205
0
        if (h->got.offset != (bfd_vma) -1)
1206
    /* We have already allocated space in the .got.  */
1207
0
    break;
1208
1209
0
        h->got.offset = sgot->size;
1210
1211
0
        if (ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
1212
      /* Make sure this symbol is output as a dynamic symbol.  */
1213
0
      && h->dynindx == -1)
1214
0
    {
1215
0
      if (! bfd_elf_link_record_dynamic_symbol (info, h))
1216
0
        goto fail;
1217
0
    }
1218
1219
0
        srelgot->size += sizeof (Elf32_External_Rela);
1220
0
        if (r_type == R_MN10300_TLS_GD)
1221
0
    srelgot->size += sizeof (Elf32_External_Rela);
1222
0
      }
1223
0
    else
1224
0
      {
1225
        /* This is a global offset table entry for a local
1226
     symbol.  */
1227
0
        if (local_got_offsets == NULL)
1228
0
    {
1229
0
      size_t       size;
1230
0
      unsigned int i;
1231
1232
0
      size = symtab_hdr->sh_info * (sizeof (bfd_vma) + sizeof (char));
1233
0
      local_got_offsets = bfd_alloc (abfd, size);
1234
1235
0
      if (local_got_offsets == NULL)
1236
0
        goto fail;
1237
1238
0
      elf_local_got_offsets (abfd) = local_got_offsets;
1239
0
      elf_mn10300_local_got_tls_type (abfd)
1240
0
          = (char *) (local_got_offsets + symtab_hdr->sh_info);
1241
1242
0
      for (i = 0; i < symtab_hdr->sh_info; i++)
1243
0
        local_got_offsets[i] = (bfd_vma) -1;
1244
0
    }
1245
1246
0
        if (local_got_offsets[r_symndx] != (bfd_vma) -1)
1247
    /* We have already allocated space in the .got.  */
1248
0
    break;
1249
1250
0
        local_got_offsets[r_symndx] = sgot->size;
1251
1252
0
        if (bfd_link_pic (info))
1253
0
    {
1254
      /* If we are generating a shared object, we need to
1255
         output a R_MN10300_RELATIVE reloc so that the dynamic
1256
         linker can adjust this GOT entry.  */
1257
0
      srelgot->size += sizeof (Elf32_External_Rela);
1258
1259
0
      if (r_type == R_MN10300_TLS_GD)
1260
        /* And a R_MN10300_TLS_DTPOFF reloc as well.  */
1261
0
        srelgot->size += sizeof (Elf32_External_Rela);
1262
0
    }
1263
1264
0
        elf_mn10300_local_got_tls_type (abfd) [r_symndx] = tls_type;
1265
0
      }
1266
1267
0
    sgot->size += 4;
1268
0
    if (r_type == R_MN10300_TLS_GD
1269
0
        || r_type == R_MN10300_TLS_LD)
1270
0
      sgot->size += 4;
1271
1272
0
    goto need_shared_relocs;
1273
1274
0
  case R_MN10300_PLT32:
1275
0
  case R_MN10300_PLT16:
1276
    /* This symbol requires a procedure linkage table entry.  We
1277
       actually build the entry in adjust_dynamic_symbol,
1278
       because this might be a case of linking PIC code which is
1279
       never referenced by a dynamic object, in which case we
1280
       don't need to generate a procedure linkage table entry
1281
       after all.  */
1282
1283
    /* If this is a local symbol, we resolve it directly without
1284
       creating a procedure linkage table entry.  */
1285
0
    if (h == NULL)
1286
0
      continue;
1287
1288
0
    if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
1289
0
        || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
1290
0
      break;
1291
1292
0
    h->needs_plt = 1;
1293
0
    break;
1294
1295
0
  case R_MN10300_24:
1296
0
  case R_MN10300_16:
1297
0
  case R_MN10300_8:
1298
0
  case R_MN10300_PCREL32:
1299
0
  case R_MN10300_PCREL16:
1300
0
  case R_MN10300_PCREL8:
1301
0
    if (h != NULL)
1302
0
      h->non_got_ref = 1;
1303
0
    break;
1304
1305
0
  case R_MN10300_SYM_DIFF:
1306
0
    sym_diff_reloc_seen = true;
1307
0
    break;
1308
1309
0
  case R_MN10300_32:
1310
0
    if (h != NULL)
1311
0
      h->non_got_ref = 1;
1312
1313
0
  need_shared_relocs:
1314
    /* If we are creating a shared library, then we
1315
       need to copy the reloc into the shared library.  */
1316
0
    if (bfd_link_pic (info)
1317
0
        && (sec->flags & SEC_ALLOC) != 0
1318
        /* Do not generate a dynamic reloc for a
1319
     reloc associated with a SYM_DIFF operation.  */
1320
0
        && ! sym_diff_reloc_seen)
1321
0
      {
1322
0
        asection * sym_section = NULL;
1323
1324
        /* Find the section containing the
1325
     symbol involved in the relocation.  */
1326
0
        if (h == NULL)
1327
0
    {
1328
0
      Elf_Internal_Sym * isym;
1329
1330
0
      if (isymbuf == NULL)
1331
0
        isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
1332
0
                symtab_hdr->sh_info, 0,
1333
0
                NULL, NULL, NULL);
1334
0
      if (isymbuf)
1335
0
        {
1336
0
          isym = isymbuf + r_symndx;
1337
          /* All we care about is whether this local symbol is absolute.  */
1338
0
          if (isym->st_shndx == SHN_ABS)
1339
0
      sym_section = bfd_abs_section_ptr;
1340
0
        }
1341
0
    }
1342
0
        else
1343
0
    {
1344
0
      if (h->root.type == bfd_link_hash_defined
1345
0
          || h->root.type == bfd_link_hash_defweak)
1346
0
        sym_section = h->root.u.def.section;
1347
0
    }
1348
1349
        /* If the symbol is absolute then the relocation can
1350
     be resolved during linking and there is no need for
1351
     a dynamic reloc.  */
1352
0
        if (sym_section != bfd_abs_section_ptr)
1353
0
    {
1354
      /* When creating a shared object, we must copy these
1355
         reloc types into the output file.  We create a reloc
1356
         section in dynobj and make room for this reloc.  */
1357
0
      if (sreloc == NULL)
1358
0
        {
1359
0
          sreloc = _bfd_elf_make_dynamic_reloc_section
1360
0
      (sec, dynobj, 2, abfd, /*rela?*/ true);
1361
0
          if (sreloc == NULL)
1362
0
      goto fail;
1363
0
        }
1364
1365
0
      sreloc->size += sizeof (Elf32_External_Rela);
1366
0
    }
1367
0
      }
1368
1369
0
    break;
1370
0
  }
1371
1372
0
      if (ELF32_R_TYPE (rel->r_info) != R_MN10300_SYM_DIFF)
1373
0
  sym_diff_reloc_seen = false;
1374
0
    }
1375
1376
0
  result = true;
1377
0
 fail:
1378
0
  if (symtab_hdr->contents != (unsigned char *) isymbuf)
1379
0
    free (isymbuf);
1380
1381
0
  return result;
1382
0
}
Unexecuted instantiation: elf-m10300.c:mn10300_elf_check_relocs
Unexecuted instantiation: elf32-am33lin.c:mn10300_elf_check_relocs
1383
1384
/* Return the section that should be marked against GC for a given
1385
   relocation.  */
1386
1387
static asection *
1388
mn10300_elf_gc_mark_hook (asection *sec,
1389
        struct bfd_link_info *info,
1390
        struct elf_reloc_cookie *cookie,
1391
        struct elf_link_hash_entry *h,
1392
        unsigned int symndx)
1393
0
{
1394
0
  if (h != NULL)
1395
0
    switch (ELF32_R_TYPE (cookie->rel->r_info))
1396
0
      {
1397
0
      case R_MN10300_GNU_VTINHERIT:
1398
0
      case R_MN10300_GNU_VTENTRY:
1399
0
  return NULL;
1400
0
      }
1401
1402
0
  return _bfd_elf_gc_mark_hook (sec, info, cookie, h, symndx);
1403
0
}
Unexecuted instantiation: elf-m10300.c:mn10300_elf_gc_mark_hook
Unexecuted instantiation: elf32-am33lin.c:mn10300_elf_gc_mark_hook
1404
1405
/* Perform a relocation as part of a final link.  */
1406
1407
static bfd_reloc_status_type
1408
mn10300_elf_final_link_relocate (reloc_howto_type *howto,
1409
         bfd *input_bfd,
1410
         bfd *output_bfd ATTRIBUTE_UNUSED,
1411
         asection *input_section,
1412
         bfd_byte *contents,
1413
         bfd_vma offset,
1414
         bfd_vma value,
1415
         bfd_vma addend,
1416
         struct elf_link_hash_entry * h,
1417
         unsigned long symndx,
1418
         struct bfd_link_info *info,
1419
         asection *sym_sec ATTRIBUTE_UNUSED,
1420
         int is_local ATTRIBUTE_UNUSED)
1421
0
{
1422
0
  struct elf32_mn10300_link_hash_table * htab = elf32_mn10300_hash_table (info);
1423
0
  static asection *  sym_diff_section;
1424
0
  static bfd_vma     sym_diff_value;
1425
0
  bool is_sym_diff_reloc;
1426
0
  unsigned long r_type = howto->type;
1427
0
  bfd_byte * hit_data = contents + offset;
1428
0
  bfd *      dynobj;
1429
0
  asection * sgot;
1430
0
  asection * splt;
1431
0
  asection * sreloc;
1432
1433
0
  dynobj = elf_hash_table (info)->dynobj;
1434
0
  sgot   = NULL;
1435
0
  splt   = NULL;
1436
1437
0
  switch (r_type)
1438
0
    {
1439
0
    case R_MN10300_24:
1440
0
    case R_MN10300_16:
1441
0
    case R_MN10300_8:
1442
0
    case R_MN10300_PCREL8:
1443
0
    case R_MN10300_PCREL16:
1444
0
    case R_MN10300_PCREL32:
1445
0
    case R_MN10300_GOTOFF32:
1446
0
    case R_MN10300_GOTOFF24:
1447
0
    case R_MN10300_GOTOFF16:
1448
0
      if (bfd_link_pic (info)
1449
0
    && (input_section->flags & SEC_ALLOC) != 0
1450
0
    && h != NULL
1451
0
    && ! SYMBOL_REFERENCES_LOCAL (info, h))
1452
0
  return bfd_reloc_dangerous;
1453
      /* Fall through.  */
1454
0
    case R_MN10300_GOT32:
1455
      /* Issue 2052223:
1456
   Taking the address of a protected function in a shared library
1457
   is illegal.  Issue an error message here.  */
1458
0
      if (bfd_link_pic (info)
1459
0
    && (input_section->flags & SEC_ALLOC) != 0
1460
0
    && h != NULL
1461
0
    && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED
1462
0
    && (h->type == STT_FUNC || h->type == STT_GNU_IFUNC)
1463
0
    && ! SYMBOL_REFERENCES_LOCAL (info, h))
1464
0
  return bfd_reloc_dangerous;
1465
0
    }
1466
1467
0
  is_sym_diff_reloc = false;
1468
0
  if (sym_diff_section != NULL)
1469
0
    {
1470
0
      BFD_ASSERT (sym_diff_section == input_section);
1471
1472
0
      switch (r_type)
1473
0
  {
1474
0
  case R_MN10300_32:
1475
0
  case R_MN10300_24:
1476
0
  case R_MN10300_16:
1477
0
  case R_MN10300_8:
1478
0
    value -= sym_diff_value;
1479
    /* If we are computing a 32-bit value for the location lists
1480
       and the result is 0 then we add one to the value.  A zero
1481
       value can result because of linker relaxation deleteing
1482
       prologue instructions and using a value of 1 (for the begin
1483
       and end offsets in the location list entry) results in a
1484
       nul entry which does not prevent the following entries from
1485
       being parsed.  */
1486
0
    if (r_type == R_MN10300_32
1487
0
        && value == 0
1488
0
        && strcmp (input_section->name, ".debug_loc") == 0)
1489
0
      value = 1;
1490
0
    sym_diff_section = NULL;
1491
0
    is_sym_diff_reloc = true;
1492
0
    break;
1493
1494
0
  default:
1495
0
    sym_diff_section = NULL;
1496
0
    break;
1497
0
  }
1498
0
    }
1499
1500
0
  switch (r_type)
1501
0
    {
1502
0
    case R_MN10300_SYM_DIFF:
1503
0
      BFD_ASSERT (addend == 0);
1504
      /* Cache the input section and value.
1505
   The offset is unreliable, since relaxation may
1506
   have reduced the following reloc's offset.  */
1507
0
      sym_diff_section = input_section;
1508
0
      sym_diff_value = value;
1509
0
      return bfd_reloc_ok;
1510
1511
0
    case R_MN10300_ALIGN:
1512
0
    case R_MN10300_NONE:
1513
0
      return bfd_reloc_ok;
1514
1515
0
    case R_MN10300_32:
1516
0
      if (bfd_link_pic (info)
1517
    /* Do not generate relocs when an R_MN10300_32 has been used
1518
       with an R_MN10300_SYM_DIFF to compute a difference of two
1519
       symbols.  */
1520
0
    && !is_sym_diff_reloc
1521
    /* Also, do not generate a reloc when the symbol associated
1522
       with the R_MN10300_32 reloc is absolute - there is no
1523
       need for a run time computation in this case.  */
1524
0
    && sym_sec != bfd_abs_section_ptr
1525
    /* If the section is not going to be allocated at load time
1526
       then there is no need to generate relocs for it.  */
1527
0
    && (input_section->flags & SEC_ALLOC) != 0)
1528
0
  {
1529
0
    Elf_Internal_Rela outrel;
1530
0
    bool skip, relocate;
1531
1532
    /* When generating a shared object, these relocations are
1533
       copied into the output file to be resolved at run
1534
       time.  */
1535
0
    sreloc = elf_section_data (input_section)->sreloc;
1536
0
    if (sreloc == NULL)
1537
0
      return false;
1538
1539
0
    skip = false;
1540
1541
0
    outrel.r_offset = _bfd_elf_section_offset (input_bfd, info,
1542
0
                 input_section, offset);
1543
0
    if (outrel.r_offset == (bfd_vma) -1)
1544
0
      skip = true;
1545
1546
0
    outrel.r_offset += (input_section->output_section->vma
1547
0
            + input_section->output_offset);
1548
1549
0
    if (skip)
1550
0
      {
1551
0
        memset (&outrel, 0, sizeof outrel);
1552
0
        relocate = false;
1553
0
      }
1554
0
    else
1555
0
      {
1556
        /* h->dynindx may be -1 if this symbol was marked to
1557
     become local.  */
1558
0
        if (h == NULL
1559
0
      || SYMBOL_REFERENCES_LOCAL (info, h))
1560
0
    {
1561
0
      relocate = true;
1562
0
      outrel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE);
1563
0
      outrel.r_addend = value + addend;
1564
0
    }
1565
0
        else
1566
0
    {
1567
0
      BFD_ASSERT (h->dynindx != -1);
1568
0
      relocate = false;
1569
0
      outrel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_32);
1570
0
      outrel.r_addend = value + addend;
1571
0
    }
1572
0
      }
1573
1574
0
    bfd_elf32_swap_reloca_out (output_bfd, &outrel,
1575
0
             (bfd_byte *) (((Elf32_External_Rela *) sreloc->contents)
1576
0
               + sreloc->reloc_count));
1577
0
    ++sreloc->reloc_count;
1578
1579
    /* If this reloc is against an external symbol, we do
1580
       not want to fiddle with the addend.  Otherwise, we
1581
       need to include the symbol value so that it becomes
1582
       an addend for the dynamic reloc.  */
1583
0
    if (! relocate)
1584
0
      return bfd_reloc_ok;
1585
0
  }
1586
0
      value += addend;
1587
0
      bfd_put_32 (input_bfd, value, hit_data);
1588
0
      return bfd_reloc_ok;
1589
1590
0
    case R_MN10300_24:
1591
0
      value += addend;
1592
1593
0
      if ((long) value > 0x7fffff || (long) value < -0x800000)
1594
0
  return bfd_reloc_overflow;
1595
1596
0
      bfd_put_8 (input_bfd, value & 0xff, hit_data);
1597
0
      bfd_put_8 (input_bfd, (value >> 8) & 0xff, hit_data + 1);
1598
0
      bfd_put_8 (input_bfd, (value >> 16) & 0xff, hit_data + 2);
1599
0
      return bfd_reloc_ok;
1600
1601
0
    case R_MN10300_16:
1602
0
      value += addend;
1603
1604
0
      if ((long) value > 0x7fff || (long) value < -0x8000)
1605
0
  return bfd_reloc_overflow;
1606
1607
0
      bfd_put_16 (input_bfd, value, hit_data);
1608
0
      return bfd_reloc_ok;
1609
1610
0
    case R_MN10300_8:
1611
0
      value += addend;
1612
1613
0
      if ((long) value > 0x7f || (long) value < -0x80)
1614
0
  return bfd_reloc_overflow;
1615
1616
0
      bfd_put_8 (input_bfd, value, hit_data);
1617
0
      return bfd_reloc_ok;
1618
1619
0
    case R_MN10300_PCREL8:
1620
0
      value -= (input_section->output_section->vma
1621
0
    + input_section->output_offset);
1622
0
      value -= offset;
1623
0
      value += addend;
1624
1625
0
      if ((long) value > 0x7f || (long) value < -0x80)
1626
0
  return bfd_reloc_overflow;
1627
1628
0
      bfd_put_8 (input_bfd, value, hit_data);
1629
0
      return bfd_reloc_ok;
1630
1631
0
    case R_MN10300_PCREL16:
1632
0
      value -= (input_section->output_section->vma
1633
0
    + input_section->output_offset);
1634
0
      value -= offset;
1635
0
      value += addend;
1636
1637
0
      if ((long) value > 0x7fff || (long) value < -0x8000)
1638
0
  return bfd_reloc_overflow;
1639
1640
0
      bfd_put_16 (input_bfd, value, hit_data);
1641
0
      return bfd_reloc_ok;
1642
1643
0
    case R_MN10300_PCREL32:
1644
0
      value -= (input_section->output_section->vma
1645
0
    + input_section->output_offset);
1646
0
      value -= offset;
1647
0
      value += addend;
1648
1649
0
      bfd_put_32 (input_bfd, value, hit_data);
1650
0
      return bfd_reloc_ok;
1651
1652
0
    case R_MN10300_GNU_VTINHERIT:
1653
0
    case R_MN10300_GNU_VTENTRY:
1654
0
      return bfd_reloc_ok;
1655
1656
0
    case R_MN10300_GOTPC32:
1657
0
      if (dynobj == NULL)
1658
0
  return bfd_reloc_dangerous;
1659
1660
      /* Use global offset table as symbol value.  */
1661
0
      value = htab->root.sgot->output_section->vma;
1662
0
      value -= (input_section->output_section->vma
1663
0
    + input_section->output_offset);
1664
0
      value -= offset;
1665
0
      value += addend;
1666
1667
0
      bfd_put_32 (input_bfd, value, hit_data);
1668
0
      return bfd_reloc_ok;
1669
1670
0
    case R_MN10300_GOTPC16:
1671
0
      if (dynobj == NULL)
1672
0
  return bfd_reloc_dangerous;
1673
1674
      /* Use global offset table as symbol value.  */
1675
0
      value = htab->root.sgot->output_section->vma;
1676
0
      value -= (input_section->output_section->vma
1677
0
    + input_section->output_offset);
1678
0
      value -= offset;
1679
0
      value += addend;
1680
1681
0
      if ((long) value > 0x7fff || (long) value < -0x8000)
1682
0
  return bfd_reloc_overflow;
1683
1684
0
      bfd_put_16 (input_bfd, value, hit_data);
1685
0
      return bfd_reloc_ok;
1686
1687
0
    case R_MN10300_GOTOFF32:
1688
0
      if (dynobj == NULL)
1689
0
  return bfd_reloc_dangerous;
1690
1691
0
      value -= htab->root.sgot->output_section->vma;
1692
0
      value += addend;
1693
1694
0
      bfd_put_32 (input_bfd, value, hit_data);
1695
0
      return bfd_reloc_ok;
1696
1697
0
    case R_MN10300_GOTOFF24:
1698
0
      if (dynobj == NULL)
1699
0
  return bfd_reloc_dangerous;
1700
1701
0
      value -= htab->root.sgot->output_section->vma;
1702
0
      value += addend;
1703
1704
0
      if ((long) value > 0x7fffff || (long) value < -0x800000)
1705
0
  return bfd_reloc_overflow;
1706
1707
0
      bfd_put_8 (input_bfd, value, hit_data);
1708
0
      bfd_put_8 (input_bfd, (value >> 8) & 0xff, hit_data + 1);
1709
0
      bfd_put_8 (input_bfd, (value >> 16) & 0xff, hit_data + 2);
1710
0
      return bfd_reloc_ok;
1711
1712
0
    case R_MN10300_GOTOFF16:
1713
0
      if (dynobj == NULL)
1714
0
  return bfd_reloc_dangerous;
1715
1716
0
      value -= htab->root.sgot->output_section->vma;
1717
0
      value += addend;
1718
1719
0
      if ((long) value > 0x7fff || (long) value < -0x8000)
1720
0
  return bfd_reloc_overflow;
1721
1722
0
      bfd_put_16 (input_bfd, value, hit_data);
1723
0
      return bfd_reloc_ok;
1724
1725
0
    case R_MN10300_PLT32:
1726
0
      if (h != NULL
1727
0
    && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
1728
0
    && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN
1729
0
    && h->plt.offset != (bfd_vma) -1)
1730
0
  {
1731
0
    if (dynobj == NULL)
1732
0
      return bfd_reloc_dangerous;
1733
1734
0
    splt = htab->root.splt;
1735
0
    value = (splt->output_section->vma
1736
0
       + splt->output_offset
1737
0
       + h->plt.offset) - value;
1738
0
  }
1739
1740
0
      value -= (input_section->output_section->vma
1741
0
    + input_section->output_offset);
1742
0
      value -= offset;
1743
0
      value += addend;
1744
1745
0
      bfd_put_32 (input_bfd, value, hit_data);
1746
0
      return bfd_reloc_ok;
1747
1748
0
    case R_MN10300_PLT16:
1749
0
      if (h != NULL
1750
0
    && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
1751
0
    && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN
1752
0
    && h->plt.offset != (bfd_vma) -1)
1753
0
  {
1754
0
    if (dynobj == NULL)
1755
0
      return bfd_reloc_dangerous;
1756
1757
0
    splt = htab->root.splt;
1758
0
    value = (splt->output_section->vma
1759
0
       + splt->output_offset
1760
0
       + h->plt.offset) - value;
1761
0
  }
1762
1763
0
      value -= (input_section->output_section->vma
1764
0
    + input_section->output_offset);
1765
0
      value -= offset;
1766
0
      value += addend;
1767
1768
0
      if ((long) value > 0x7fff || (long) value < -0x8000)
1769
0
  return bfd_reloc_overflow;
1770
1771
0
      bfd_put_16 (input_bfd, value, hit_data);
1772
0
      return bfd_reloc_ok;
1773
1774
0
    case R_MN10300_TLS_LDO:
1775
0
      value = dtpoff (info, value);
1776
0
      bfd_put_32 (input_bfd, value + addend, hit_data);
1777
0
      return bfd_reloc_ok;
1778
1779
0
    case R_MN10300_TLS_LE:
1780
0
      value = tpoff (info, value);
1781
0
      bfd_put_32 (input_bfd, value + addend, hit_data);
1782
0
      return bfd_reloc_ok;
1783
1784
0
    case R_MN10300_TLS_LD:
1785
0
      if (dynobj == NULL)
1786
0
  return bfd_reloc_dangerous;
1787
1788
0
      sgot = htab->root.sgot;
1789
0
      BFD_ASSERT (sgot != NULL);
1790
0
      value = htab->tls_ldm_got.offset + sgot->output_offset;
1791
0
      bfd_put_32 (input_bfd, value, hit_data);
1792
1793
0
      if (!htab->tls_ldm_got.rel_emitted)
1794
0
  {
1795
0
    asection *srelgot = htab->root.srelgot;
1796
0
    Elf_Internal_Rela rel;
1797
1798
0
    BFD_ASSERT (srelgot != NULL);
1799
0
    htab->tls_ldm_got.rel_emitted ++;
1800
0
    rel.r_offset = (sgot->output_section->vma
1801
0
        + sgot->output_offset
1802
0
        + htab->tls_ldm_got.offset);
1803
0
    bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + htab->tls_ldm_got.offset);
1804
0
    bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + htab->tls_ldm_got.offset+4);
1805
0
    rel.r_info = ELF32_R_INFO (0, R_MN10300_TLS_DTPMOD);
1806
0
    rel.r_addend = 0;
1807
0
    bfd_elf32_swap_reloca_out (output_bfd, & rel,
1808
0
             (bfd_byte *) ((Elf32_External_Rela *) srelgot->contents
1809
0
               + srelgot->reloc_count));
1810
0
    ++ srelgot->reloc_count;
1811
0
  }
1812
1813
0
      return bfd_reloc_ok;
1814
1815
0
    case R_MN10300_TLS_GOTIE:
1816
0
      value = tpoff (info, value);
1817
      /* Fall Through.  */
1818
1819
0
    case R_MN10300_TLS_GD:
1820
0
    case R_MN10300_TLS_IE:
1821
0
    case R_MN10300_GOT32:
1822
0
    case R_MN10300_GOT24:
1823
0
    case R_MN10300_GOT16:
1824
0
      if (dynobj == NULL)
1825
0
  return bfd_reloc_dangerous;
1826
1827
0
      sgot = htab->root.sgot;
1828
0
      if (r_type == R_MN10300_TLS_GD)
1829
0
  value = dtpoff (info, value);
1830
1831
0
      if (h != NULL)
1832
0
  {
1833
0
    bfd_vma off;
1834
1835
0
    off = h->got.offset;
1836
    /* Offsets in the GOT are allocated in check_relocs
1837
       which is not called for shared libraries... */
1838
0
    if (off == (bfd_vma) -1)
1839
0
      off = 0;
1840
1841
0
    if (sgot->contents != NULL
1842
0
        && (! elf_hash_table (info)->dynamic_sections_created
1843
0
      || SYMBOL_REFERENCES_LOCAL (info, h)))
1844
      /* This is actually a static link, or it is a
1845
         -Bsymbolic link and the symbol is defined
1846
         locally, or the symbol was forced to be local
1847
         because of a version file.  We must initialize
1848
         this entry in the global offset table.
1849
1850
         When doing a dynamic link, we create a .rela.got
1851
         relocation entry to initialize the value.  This
1852
         is done in the finish_dynamic_symbol routine.  */
1853
0
      bfd_put_32 (output_bfd, value,
1854
0
      sgot->contents + off);
1855
1856
0
    value = sgot->output_offset + off;
1857
0
  }
1858
0
      else
1859
0
  {
1860
0
    bfd_vma off;
1861
1862
0
    off = elf_local_got_offsets (input_bfd)[symndx];
1863
1864
0
    if (off & 1)
1865
0
      bfd_put_32 (output_bfd, value, sgot->contents + (off & ~ 1));
1866
0
    else
1867
0
      {
1868
0
        bfd_put_32 (output_bfd, value, sgot->contents + off);
1869
1870
0
        if (bfd_link_pic (info))
1871
0
    {
1872
0
      asection *srelgot = htab->root.srelgot;;
1873
0
      Elf_Internal_Rela outrel;
1874
1875
0
      BFD_ASSERT (srelgot != NULL);
1876
1877
0
      outrel.r_offset = (sgot->output_section->vma
1878
0
             + sgot->output_offset
1879
0
             + off);
1880
0
      switch (r_type)
1881
0
        {
1882
0
        case R_MN10300_TLS_GD:
1883
0
          outrel.r_info = ELF32_R_INFO (0, R_MN10300_TLS_DTPOFF);
1884
0
          outrel.r_offset = (sgot->output_section->vma
1885
0
           + sgot->output_offset
1886
0
           + off + 4);
1887
0
          bfd_elf32_swap_reloca_out (output_bfd, & outrel,
1888
0
             (bfd_byte *) (((Elf32_External_Rela *)
1889
0
                srelgot->contents)
1890
0
                     + srelgot->reloc_count));
1891
0
          ++ srelgot->reloc_count;
1892
0
          outrel.r_info = ELF32_R_INFO (0, R_MN10300_TLS_DTPMOD);
1893
0
          break;
1894
0
        case R_MN10300_TLS_GOTIE:
1895
0
        case R_MN10300_TLS_IE:
1896
0
          outrel.r_info = ELF32_R_INFO (0, R_MN10300_TLS_TPOFF);
1897
0
          break;
1898
0
        default:
1899
0
          outrel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE);
1900
0
          break;
1901
0
        }
1902
1903
0
      outrel.r_addend = value;
1904
0
      bfd_elf32_swap_reloca_out (output_bfd, &outrel,
1905
0
               (bfd_byte *) (((Elf32_External_Rela *)
1906
0
                  srelgot->contents)
1907
0
                 + srelgot->reloc_count));
1908
0
      ++ srelgot->reloc_count;
1909
0
      elf_local_got_offsets (input_bfd)[symndx] |= 1;
1910
0
    }
1911
1912
0
        value = sgot->output_offset + (off & ~(bfd_vma) 1);
1913
0
      }
1914
0
  }
1915
1916
0
      value += addend;
1917
1918
0
      if (r_type == R_MN10300_TLS_IE)
1919
0
  {
1920
0
    value += sgot->output_section->vma;
1921
0
    bfd_put_32 (input_bfd, value, hit_data);
1922
0
    return bfd_reloc_ok;
1923
0
  }
1924
0
      else if (r_type == R_MN10300_TLS_GOTIE
1925
0
         || r_type == R_MN10300_TLS_GD
1926
0
         || r_type == R_MN10300_TLS_LD)
1927
0
  {
1928
0
    bfd_put_32 (input_bfd, value, hit_data);
1929
0
    return bfd_reloc_ok;
1930
0
  }
1931
0
      else if (r_type == R_MN10300_GOT32)
1932
0
  {
1933
0
    bfd_put_32 (input_bfd, value, hit_data);
1934
0
    return bfd_reloc_ok;
1935
0
  }
1936
0
      else if (r_type == R_MN10300_GOT24)
1937
0
  {
1938
0
    if ((long) value > 0x7fffff || (long) value < -0x800000)
1939
0
      return bfd_reloc_overflow;
1940
1941
0
    bfd_put_8 (input_bfd, value & 0xff, hit_data);
1942
0
    bfd_put_8 (input_bfd, (value >> 8) & 0xff, hit_data + 1);
1943
0
    bfd_put_8 (input_bfd, (value >> 16) & 0xff, hit_data + 2);
1944
0
    return bfd_reloc_ok;
1945
0
  }
1946
0
      else if (r_type == R_MN10300_GOT16)
1947
0
  {
1948
0
    if ((long) value > 0x7fff || (long) value < -0x8000)
1949
0
      return bfd_reloc_overflow;
1950
1951
0
    bfd_put_16 (input_bfd, value, hit_data);
1952
0
    return bfd_reloc_ok;
1953
0
  }
1954
      /* Fall through.  */
1955
1956
0
    default:
1957
0
      return bfd_reloc_notsupported;
1958
0
    }
1959
0
}
Unexecuted instantiation: elf-m10300.c:mn10300_elf_final_link_relocate
Unexecuted instantiation: elf32-am33lin.c:mn10300_elf_final_link_relocate
1960

1961
/* Relocate an MN10300 ELF section.  */
1962
1963
static int
1964
mn10300_elf_relocate_section (struct bfd_link_info *info,
1965
            bfd *input_bfd,
1966
            asection *input_section,
1967
            bfd_byte *contents,
1968
            Elf_Internal_Rela *relocs,
1969
            Elf_Internal_Sym *local_syms,
1970
            asection **local_sections)
1971
0
{
1972
0
  Elf_Internal_Shdr *symtab_hdr;
1973
0
  struct elf_link_hash_entry **sym_hashes;
1974
0
  Elf_Internal_Rela *rel, *relend;
1975
0
  Elf_Internal_Rela * trel;
1976
1977
0
  symtab_hdr = &elf_symtab_hdr (input_bfd);
1978
0
  sym_hashes = elf_sym_hashes (input_bfd);
1979
1980
0
  rel = relocs;
1981
0
  relend = relocs + input_section->reloc_count;
1982
0
  for (; rel < relend; rel++)
1983
0
    {
1984
0
      int r_type;
1985
0
      reloc_howto_type *howto;
1986
0
      unsigned long r_symndx;
1987
0
      Elf_Internal_Sym *sym;
1988
0
      asection *sec;
1989
0
      struct elf32_mn10300_link_hash_entry *h;
1990
0
      bfd_vma relocation;
1991
0
      bfd_reloc_status_type r;
1992
0
      int tls_r_type;
1993
0
      bool unresolved_reloc = false;
1994
0
      bool warned, ignored;
1995
0
      struct elf_link_hash_entry * hh;
1996
1997
0
      relocation = 0;
1998
0
      r_symndx = ELF32_R_SYM (rel->r_info);
1999
0
      r_type = ELF32_R_TYPE (rel->r_info);
2000
0
      howto = elf_mn10300_howto_table + r_type;
2001
2002
      /* Just skip the vtable gc relocs.  */
2003
0
      if (r_type == R_MN10300_GNU_VTINHERIT
2004
0
    || r_type == R_MN10300_GNU_VTENTRY)
2005
0
  continue;
2006
2007
0
      h = NULL;
2008
0
      sym = NULL;
2009
0
      sec = NULL;
2010
0
      if (r_symndx < symtab_hdr->sh_info)
2011
0
  hh = NULL;
2012
0
      else
2013
0
  {
2014
0
    RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
2015
0
           r_symndx, symtab_hdr, sym_hashes,
2016
0
           hh, sec, relocation,
2017
0
           unresolved_reloc, warned, ignored);
2018
0
  }
2019
0
      h = elf_mn10300_hash_entry (hh);
2020
2021
0
      tls_r_type = elf_mn10300_tls_transition (info, r_type, hh, input_section, 0);
2022
0
      if (tls_r_type != r_type)
2023
0
  {
2024
0
    bool had_plt;
2025
2026
0
    had_plt = mn10300_do_tls_transition (input_bfd, r_type, tls_r_type,
2027
0
                 contents, rel->r_offset);
2028
0
    r_type = tls_r_type;
2029
0
    howto = elf_mn10300_howto_table + r_type;
2030
2031
0
    if (had_plt)
2032
0
      for (trel = rel+1; trel < relend; trel++)
2033
0
        if ((ELF32_R_TYPE (trel->r_info) == R_MN10300_PLT32
2034
0
       || ELF32_R_TYPE (trel->r_info) == R_MN10300_PCREL32)
2035
0
      && rel->r_offset + had_plt == trel->r_offset)
2036
0
    trel->r_info = ELF32_R_INFO (0, R_MN10300_NONE);
2037
0
  }
2038
2039
0
      if (r_symndx < symtab_hdr->sh_info)
2040
0
  {
2041
0
    sym = local_syms + r_symndx;
2042
0
    sec = local_sections[r_symndx];
2043
0
    relocation = _bfd_elf_rela_local_sym (info->output_bfd,
2044
0
            sym, &sec, rel);
2045
0
  }
2046
0
      else
2047
0
  {
2048
0
    if ((h->root.root.type == bfd_link_hash_defined
2049
0
        || h->root.root.type == bfd_link_hash_defweak)
2050
0
        && (   r_type == R_MN10300_GOTPC32
2051
0
      || r_type == R_MN10300_GOTPC16
2052
0
      || ((   r_type == R_MN10300_PLT32
2053
0
           || r_type == R_MN10300_PLT16)
2054
0
          && ELF_ST_VISIBILITY (h->root.other) != STV_INTERNAL
2055
0
          && ELF_ST_VISIBILITY (h->root.other) != STV_HIDDEN
2056
0
          && h->root.plt.offset != (bfd_vma) -1)
2057
0
      || ((   r_type == R_MN10300_GOT32
2058
0
           || r_type == R_MN10300_GOT24
2059
0
           || r_type == R_MN10300_TLS_GD
2060
0
           || r_type == R_MN10300_TLS_LD
2061
0
           || r_type == R_MN10300_TLS_GOTIE
2062
0
           || r_type == R_MN10300_TLS_IE
2063
0
           || r_type == R_MN10300_GOT16)
2064
0
          && elf_hash_table (info)->dynamic_sections_created
2065
0
          && !SYMBOL_REFERENCES_LOCAL (info, hh))
2066
0
      || (r_type == R_MN10300_32
2067
0
          && !SYMBOL_REFERENCES_LOCAL (info, hh)
2068
          /* _32 relocs in executables force _COPY relocs,
2069
       such that the address of the symbol ends up
2070
       being local.  */
2071
0
          && (((input_section->flags & SEC_ALLOC) != 0
2072
0
         && !bfd_link_executable (info))
2073
        /* DWARF will emit R_MN10300_32 relocations
2074
           in its sections against symbols defined
2075
           externally in shared libraries.  We can't
2076
           do anything with them here.  */
2077
0
        || ((input_section->flags & SEC_DEBUGGING) != 0
2078
0
            && h->root.def_dynamic)))))
2079
      /* In these cases, we don't need the relocation
2080
         value.  We check specially because in some
2081
         obscure cases sec->output_section will be NULL.  */
2082
0
      relocation = 0;
2083
2084
0
    else if (!bfd_link_relocatable (info) && unresolved_reloc
2085
0
       && _bfd_elf_section_offset (info->output_bfd, info,
2086
0
                 input_section,
2087
0
                 rel->r_offset) != (bfd_vma) -1)
2088
2089
0
      _bfd_error_handler
2090
        /* xgettext:c-format */
2091
0
        (_("%pB(%pA+%#" PRIx64 "): "
2092
0
     "unresolvable %s relocation against symbol `%s'"),
2093
0
         input_bfd,
2094
0
         input_section,
2095
0
         (uint64_t) rel->r_offset,
2096
0
         howto->name,
2097
0
         h->root.root.root.string);
2098
0
  }
2099
2100
0
      if (sec != NULL && discarded_section (sec))
2101
0
  RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
2102
0
           rel, 1, relend, R_MN10300_NONE,
2103
0
           howto, 0, contents);
2104
2105
0
      if (bfd_link_relocatable (info))
2106
0
  continue;
2107
2108
0
      r = mn10300_elf_final_link_relocate (howto, input_bfd, info->output_bfd,
2109
0
             input_section,
2110
0
             contents, rel->r_offset,
2111
0
             relocation, rel->r_addend,
2112
0
             (struct elf_link_hash_entry *) h,
2113
0
             r_symndx,
2114
0
             info, sec, h == NULL);
2115
2116
0
      if (r != bfd_reloc_ok)
2117
0
  {
2118
0
    const char *name;
2119
0
    const char *msg = NULL;
2120
2121
0
    if (h != NULL)
2122
0
      name = h->root.root.root.string;
2123
0
    else
2124
0
      {
2125
0
        name = (bfd_elf_string_from_elf_section
2126
0
          (input_bfd, symtab_hdr->sh_link, sym->st_name));
2127
0
        if (name == NULL || *name == '\0')
2128
0
    name = bfd_section_name (sec);
2129
0
      }
2130
2131
0
    switch (r)
2132
0
      {
2133
0
      case bfd_reloc_overflow:
2134
0
        (*info->callbacks->reloc_overflow)
2135
0
    (info, (h ? &h->root.root : NULL), name, howto->name,
2136
0
     (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
2137
0
        break;
2138
2139
0
      case bfd_reloc_undefined:
2140
0
        (*info->callbacks->undefined_symbol)
2141
0
    (info, name, input_bfd, input_section, rel->r_offset, true);
2142
0
        break;
2143
2144
0
      case bfd_reloc_outofrange:
2145
0
        msg = _("internal error: out of range error");
2146
0
        goto common_error;
2147
2148
0
      case bfd_reloc_notsupported:
2149
0
        msg = _("internal error: unsupported relocation error");
2150
0
        goto common_error;
2151
2152
0
      case bfd_reloc_dangerous:
2153
0
        if (r_type == R_MN10300_PCREL32)
2154
0
    msg = _("error: inappropriate relocation type for shared"
2155
0
      " library (did you forget -fpic?)");
2156
0
        else if (r_type == R_MN10300_GOT32)
2157
    /* xgettext:c-format */
2158
0
    msg = _("%pB: taking the address of protected function"
2159
0
      " '%s' cannot be done when making a shared library");
2160
0
        else
2161
0
    msg = _("internal error: suspicious relocation type used"
2162
0
      " in shared library");
2163
0
        goto common_error;
2164
2165
0
      default:
2166
0
        msg = _("internal error: unknown error");
2167
        /* Fall through.  */
2168
2169
0
      common_error:
2170
0
        _bfd_error_handler (msg, input_bfd, name);
2171
0
        bfd_set_error (bfd_error_bad_value);
2172
0
        return false;
2173
0
      }
2174
0
  }
2175
0
    }
2176
2177
0
  return true;
2178
0
}
Unexecuted instantiation: elf-m10300.c:mn10300_elf_relocate_section
Unexecuted instantiation: elf32-am33lin.c:mn10300_elf_relocate_section
2179
2180
/* Finish initializing one hash table entry.  */
2181
2182
static bool
2183
elf32_mn10300_finish_hash_table_entry (struct bfd_hash_entry *gen_entry,
2184
               void * in_args)
2185
0
{
2186
0
  struct elf32_mn10300_link_hash_entry *entry;
2187
0
  struct bfd_link_info *link_info = (struct bfd_link_info *) in_args;
2188
0
  unsigned int byte_count = 0;
2189
2190
0
  entry = (struct elf32_mn10300_link_hash_entry *) gen_entry;
2191
2192
  /* If we already know we want to convert "call" to "calls" for calls
2193
     to this symbol, then return now.  */
2194
0
  if (entry->flags == MN10300_CONVERT_CALL_TO_CALLS)
2195
0
    return true;
2196
2197
  /* If there are no named calls to this symbol, or there's nothing we
2198
     can move from the function itself into the "call" instruction,
2199
     then note that all "call" instructions should be converted into
2200
     "calls" instructions and return.  If a symbol is available for
2201
     dynamic symbol resolution (overridable or overriding), avoid
2202
     custom calling conventions.  */
2203
0
  if (entry->direct_calls == 0
2204
0
      || (entry->stack_size == 0 && entry->movm_args == 0)
2205
0
      || (elf_hash_table (link_info)->dynamic_sections_created
2206
0
    && ELF_ST_VISIBILITY (entry->root.other) != STV_INTERNAL
2207
0
    && ELF_ST_VISIBILITY (entry->root.other) != STV_HIDDEN))
2208
0
    {
2209
      /* Make a note that we should convert "call" instructions to "calls"
2210
   instructions for calls to this symbol.  */
2211
0
      entry->flags |= MN10300_CONVERT_CALL_TO_CALLS;
2212
0
      return true;
2213
0
    }
2214
2215
  /* We may be able to move some instructions from the function itself into
2216
     the "call" instruction.  Count how many bytes we might be able to
2217
     eliminate in the function itself.  */
2218
2219
  /* A movm instruction is two bytes.  */
2220
0
  if (entry->movm_args)
2221
0
    byte_count += 2;
2222
2223
  /* Count the insn to allocate stack space too.  */
2224
0
  if (entry->stack_size > 0)
2225
0
    {
2226
0
      if (entry->stack_size <= 128)
2227
0
  byte_count += 3;
2228
0
      else
2229
0
  byte_count += 4;
2230
0
    }
2231
2232
  /* If using "call" will result in larger code, then turn all
2233
     the associated "call" instructions into "calls" instructions.  */
2234
0
  if (byte_count < entry->direct_calls)
2235
0
    entry->flags |= MN10300_CONVERT_CALL_TO_CALLS;
2236
2237
  /* This routine never fails.  */
2238
0
  return true;
2239
0
}
Unexecuted instantiation: elf-m10300.c:elf32_mn10300_finish_hash_table_entry
Unexecuted instantiation: elf32-am33lin.c:elf32_mn10300_finish_hash_table_entry
2240
2241
/* Used to count hash table entries.  */
2242
2243
static bool
2244
elf32_mn10300_count_hash_table_entries (struct bfd_hash_entry *gen_entry ATTRIBUTE_UNUSED,
2245
          void * in_args)
2246
0
{
2247
0
  int *count = (int *) in_args;
2248
2249
0
  (*count) ++;
2250
0
  return true;
2251
0
}
Unexecuted instantiation: elf-m10300.c:elf32_mn10300_count_hash_table_entries
Unexecuted instantiation: elf32-am33lin.c:elf32_mn10300_count_hash_table_entries
2252
2253
/* Used to enumerate hash table entries into a linear array.  */
2254
2255
static bool
2256
elf32_mn10300_list_hash_table_entries (struct bfd_hash_entry *gen_entry,
2257
               void * in_args)
2258
0
{
2259
0
  struct bfd_hash_entry ***ptr = (struct bfd_hash_entry ***) in_args;
2260
2261
0
  **ptr = gen_entry;
2262
0
  (*ptr) ++;
2263
0
  return true;
2264
0
}
Unexecuted instantiation: elf-m10300.c:elf32_mn10300_list_hash_table_entries
Unexecuted instantiation: elf32-am33lin.c:elf32_mn10300_list_hash_table_entries
2265
2266
/* Used to sort the array created by the above.  */
2267
2268
static int
2269
sort_by_value (const void *va, const void *vb)
2270
0
{
2271
0
  struct elf32_mn10300_link_hash_entry *a
2272
0
    = *(struct elf32_mn10300_link_hash_entry **) va;
2273
0
  struct elf32_mn10300_link_hash_entry *b
2274
0
    = *(struct elf32_mn10300_link_hash_entry **) vb;
2275
2276
0
  return a->value - b->value;
2277
0
}
Unexecuted instantiation: elf-m10300.c:sort_by_value
Unexecuted instantiation: elf32-am33lin.c:sort_by_value
2278
2279
/* Compute the stack size and movm arguments for the function
2280
   referred to by HASH at address ADDR in section with
2281
   contents CONTENTS, store the information in the hash table.  */
2282
2283
static void
2284
compute_function_info (bfd *abfd,
2285
           struct elf32_mn10300_link_hash_entry *hash,
2286
           bfd_vma addr,
2287
           unsigned char *contents)
2288
0
{
2289
0
  unsigned char byte1, byte2;
2290
  /* We only care about a very small subset of the possible prologue
2291
     sequences here.  Basically we look for:
2292
2293
     movm [d2,d3,a2,a3],sp (optional)
2294
     add <size>,sp (optional, and only for sizes which fit in an unsigned
2295
        8 bit number)
2296
2297
     If we find anything else, we quit.  */
2298
2299
  /* Look for movm [regs],sp.  */
2300
0
  byte1 = bfd_get_8 (abfd, contents + addr);
2301
0
  byte2 = bfd_get_8 (abfd, contents + addr + 1);
2302
2303
0
  if (byte1 == 0xcf)
2304
0
    {
2305
0
      hash->movm_args = byte2;
2306
0
      addr += 2;
2307
0
      byte1 = bfd_get_8 (abfd, contents + addr);
2308
0
      byte2 = bfd_get_8 (abfd, contents + addr + 1);
2309
0
    }
2310
2311
  /* Now figure out how much stack space will be allocated by the movm
2312
     instruction.  We need this kept separate from the function's normal
2313
     stack space.  */
2314
0
  if (hash->movm_args)
2315
0
    {
2316
      /* Space for d2.  */
2317
0
      if (hash->movm_args & 0x80)
2318
0
  hash->movm_stack_size += 4;
2319
2320
      /* Space for d3.  */
2321
0
      if (hash->movm_args & 0x40)
2322
0
  hash->movm_stack_size += 4;
2323
2324
      /* Space for a2.  */
2325
0
      if (hash->movm_args & 0x20)
2326
0
  hash->movm_stack_size += 4;
2327
2328
      /* Space for a3.  */
2329
0
      if (hash->movm_args & 0x10)
2330
0
  hash->movm_stack_size += 4;
2331
2332
      /* "other" space.  d0, d1, a0, a1, mdr, lir, lar, 4 byte pad.  */
2333
0
      if (hash->movm_args & 0x08)
2334
0
  hash->movm_stack_size += 8 * 4;
2335
2336
0
      if (bfd_get_mach (abfd) == bfd_mach_am33
2337
0
    || bfd_get_mach (abfd) == bfd_mach_am33_2)
2338
0
  {
2339
    /* "exother" space.  e0, e1, mdrq, mcrh, mcrl, mcvf */
2340
0
    if (hash->movm_args & 0x1)
2341
0
      hash->movm_stack_size += 6 * 4;
2342
2343
    /* exreg1 space.  e4, e5, e6, e7 */
2344
0
    if (hash->movm_args & 0x2)
2345
0
      hash->movm_stack_size += 4 * 4;
2346
2347
    /* exreg0 space.  e2, e3  */
2348
0
    if (hash->movm_args & 0x4)
2349
0
      hash->movm_stack_size += 2 * 4;
2350
0
  }
2351
0
    }
2352
2353
  /* Now look for the two stack adjustment variants.  */
2354
0
  if (byte1 == 0xf8 && byte2 == 0xfe)
2355
0
    {
2356
0
      int temp = bfd_get_8 (abfd, contents + addr + 2);
2357
0
      temp = ((temp & 0xff) ^ (~0x7f)) + 0x80;
2358
2359
0
      hash->stack_size = -temp;
2360
0
    }
2361
0
  else if (byte1 == 0xfa && byte2 == 0xfe)
2362
0
    {
2363
0
      int temp = bfd_get_16 (abfd, contents + addr + 2);
2364
0
      temp = ((temp & 0xffff) ^ (~0x7fff)) + 0x8000;
2365
0
      temp = -temp;
2366
2367
0
      if (temp < 255)
2368
0
  hash->stack_size = temp;
2369
0
    }
2370
2371
  /* If the total stack to be allocated by the call instruction is more
2372
     than 255 bytes, then we can't remove the stack adjustment by using
2373
     "call" (we might still be able to remove the "movm" instruction.  */
2374
0
  if (hash->stack_size + hash->movm_stack_size > 255)
2375
0
    hash->stack_size = 0;
2376
0
}
Unexecuted instantiation: elf-m10300.c:compute_function_info
Unexecuted instantiation: elf32-am33lin.c:compute_function_info
2377
2378
/* Delete some bytes from a section while relaxing.  */
2379
2380
static bool
2381
mn10300_elf_relax_delete_bytes (bfd *abfd,
2382
        asection *sec,
2383
        bfd_vma addr,
2384
        int count)
2385
0
{
2386
0
  Elf_Internal_Shdr *symtab_hdr;
2387
0
  unsigned int sec_shndx;
2388
0
  bfd_byte *contents;
2389
0
  Elf_Internal_Rela *irel, *irelend;
2390
0
  Elf_Internal_Rela *irelalign;
2391
0
  bfd_vma toaddr;
2392
0
  Elf_Internal_Sym *isym, *isymend;
2393
0
  struct elf_link_hash_entry **sym_hashes;
2394
0
  struct elf_link_hash_entry **end_hashes;
2395
0
  unsigned int symcount;
2396
2397
0
  sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
2398
2399
0
  contents = elf_section_data (sec)->this_hdr.contents;
2400
2401
0
  irelalign = NULL;
2402
0
  toaddr = sec->size;
2403
2404
0
  irel = elf_section_data (sec)->relocs;
2405
0
  irelend = irel + sec->reloc_count;
2406
2407
0
  if (sec->reloc_count > 0)
2408
0
    {
2409
      /* If there is an align reloc at the end of the section ignore it.
2410
   GAS creates these relocs for reasons of its own, and they just
2411
   serve to keep the section artifically inflated.  */
2412
0
      if (ELF32_R_TYPE ((irelend - 1)->r_info) == (int) R_MN10300_ALIGN)
2413
0
  --irelend;
2414
2415
      /* The deletion must stop at the next ALIGN reloc for an alignment
2416
   power larger than, or not a multiple of, the number of bytes we
2417
   are deleting.  */
2418
0
      for (; irel < irelend; irel++)
2419
0
  {
2420
0
    if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_ALIGN
2421
0
        && irel->r_offset > addr
2422
0
        && irel->r_offset < toaddr)
2423
0
      {
2424
0
        int alignment = 1 << irel->r_addend;
2425
2426
0
        if (count < alignment
2427
0
      || alignment % count != 0)
2428
0
    {
2429
0
      irelalign = irel;
2430
0
      toaddr = irel->r_offset;
2431
0
      break;
2432
0
    }
2433
0
      }
2434
0
  }
2435
0
    }
2436
2437
  /* Actually delete the bytes.  */
2438
0
  memmove (contents + addr, contents + addr + count,
2439
0
     (size_t) (toaddr - addr - count));
2440
2441
  /* Adjust the section's size if we are shrinking it, or else
2442
     pad the bytes between the end of the shrunken region and
2443
     the start of the next region with NOP codes.  */
2444
0
  if (irelalign == NULL)
2445
0
    {
2446
0
      sec->size -= count;
2447
      /* Include symbols at the end of the section, but
2448
   not at the end of a sub-region of the section.  */
2449
0
      toaddr ++;
2450
0
    }
2451
0
  else
2452
0
    {
2453
0
      int i;
2454
2455
0
#define NOP_OPCODE 0xcb
2456
2457
0
      for (i = 0; i < count; i ++)
2458
0
  bfd_put_8 (abfd, (bfd_vma) NOP_OPCODE, contents + toaddr - count + i);
2459
0
    }
2460
2461
  /* Adjust all the relocs.  */
2462
0
  for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)
2463
0
    {
2464
      /* Get the new reloc address.  */
2465
0
      if ((irel->r_offset > addr
2466
0
     && irel->r_offset < toaddr)
2467
0
    || (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_ALIGN
2468
0
        && irel->r_offset == toaddr))
2469
0
  irel->r_offset -= count;
2470
0
    }
2471
2472
  /* Adjust the local symbols in the section, reducing their value
2473
     by the number of bytes deleted.  Note - symbols within the deleted
2474
     region are moved to the address of the start of the region, which
2475
     actually means that they will address the byte beyond the end of
2476
     the region once the deletion has been completed.  */
2477
0
  symtab_hdr = &elf_symtab_hdr (abfd);
2478
0
  isym = (Elf_Internal_Sym *) symtab_hdr->contents;
2479
0
  for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++)
2480
0
    {
2481
0
      if (isym->st_shndx == sec_shndx
2482
0
    && isym->st_value > addr
2483
0
    && isym->st_value < toaddr)
2484
0
  {
2485
0
    if (isym->st_value < addr + count)
2486
0
      isym->st_value = addr;
2487
0
    else
2488
0
      isym->st_value -= count;
2489
0
  }
2490
      /* Adjust the function symbol's size as well.  */
2491
0
      else if (isym->st_shndx == sec_shndx
2492
0
         && ELF_ST_TYPE (isym->st_info) == STT_FUNC
2493
0
         && isym->st_value + isym->st_size > addr
2494
0
         && isym->st_value + isym->st_size < toaddr)
2495
0
  isym->st_size -= count;
2496
0
    }
2497
2498
  /* Now adjust the global symbols defined in this section.  */
2499
0
  symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
2500
0
        - symtab_hdr->sh_info);
2501
0
  sym_hashes = elf_sym_hashes (abfd);
2502
0
  end_hashes = sym_hashes + symcount;
2503
0
  for (; sym_hashes < end_hashes; sym_hashes++)
2504
0
    {
2505
0
      struct elf_link_hash_entry *sym_hash = *sym_hashes;
2506
2507
0
      if ((sym_hash->root.type == bfd_link_hash_defined
2508
0
     || sym_hash->root.type == bfd_link_hash_defweak)
2509
0
    && sym_hash->root.u.def.section == sec
2510
0
    && sym_hash->root.u.def.value > addr
2511
0
    && sym_hash->root.u.def.value < toaddr)
2512
0
  {
2513
0
    if (sym_hash->root.u.def.value < addr + count)
2514
0
      sym_hash->root.u.def.value = addr;
2515
0
    else
2516
0
      sym_hash->root.u.def.value -= count;
2517
0
  }
2518
      /* Adjust the function symbol's size as well.  */
2519
0
      else if (sym_hash->root.type == bfd_link_hash_defined
2520
0
         && sym_hash->root.u.def.section == sec
2521
0
         && sym_hash->type == STT_FUNC
2522
0
         && sym_hash->root.u.def.value + sym_hash->size > addr
2523
0
         && sym_hash->root.u.def.value + sym_hash->size < toaddr)
2524
0
  sym_hash->size -= count;
2525
0
    }
2526
2527
  /* See if we can move the ALIGN reloc forward.
2528
     We have adjusted r_offset for it already.  */
2529
0
  if (irelalign != NULL)
2530
0
    {
2531
0
      bfd_vma alignto, alignaddr;
2532
2533
0
      if ((int) irelalign->r_addend > 0)
2534
0
  {
2535
    /* This is the old address.  */
2536
0
    alignto = BFD_ALIGN (toaddr, 1 << irelalign->r_addend);
2537
    /* This is where the align points to now.  */
2538
0
    alignaddr = BFD_ALIGN (irelalign->r_offset,
2539
0
         1 << irelalign->r_addend);
2540
0
    if (alignaddr < alignto)
2541
      /* Tail recursion.  */
2542
0
      return mn10300_elf_relax_delete_bytes (abfd, sec, alignaddr,
2543
0
               (int) (alignto - alignaddr));
2544
0
  }
2545
0
    }
2546
2547
0
  return true;
2548
0
}
Unexecuted instantiation: elf-m10300.c:mn10300_elf_relax_delete_bytes
Unexecuted instantiation: elf32-am33lin.c:mn10300_elf_relax_delete_bytes
2549
2550
/* Return TRUE if a symbol exists at the given address, else return
2551
   FALSE.  */
2552
2553
static bool
2554
mn10300_elf_symbol_address_p (bfd *abfd,
2555
            asection *sec,
2556
            Elf_Internal_Sym *isym,
2557
            bfd_vma addr)
2558
0
{
2559
0
  Elf_Internal_Shdr *symtab_hdr;
2560
0
  unsigned int sec_shndx;
2561
0
  Elf_Internal_Sym *isymend;
2562
0
  struct elf_link_hash_entry **sym_hashes;
2563
0
  struct elf_link_hash_entry **end_hashes;
2564
0
  unsigned int symcount;
2565
2566
0
  sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
2567
2568
  /* Examine all the symbols.  */
2569
0
  symtab_hdr = &elf_symtab_hdr (abfd);
2570
0
  for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++)
2571
0
    if (isym->st_shndx == sec_shndx
2572
0
  && isym->st_value == addr)
2573
0
      return true;
2574
2575
0
  symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
2576
0
        - symtab_hdr->sh_info);
2577
0
  sym_hashes = elf_sym_hashes (abfd);
2578
0
  end_hashes = sym_hashes + symcount;
2579
0
  for (; sym_hashes < end_hashes; sym_hashes++)
2580
0
    {
2581
0
      struct elf_link_hash_entry *sym_hash = *sym_hashes;
2582
2583
0
      if ((sym_hash->root.type == bfd_link_hash_defined
2584
0
     || sym_hash->root.type == bfd_link_hash_defweak)
2585
0
    && sym_hash->root.u.def.section == sec
2586
0
    && sym_hash->root.u.def.value == addr)
2587
0
  return true;
2588
0
    }
2589
2590
0
  return false;
2591
0
}
Unexecuted instantiation: elf-m10300.c:mn10300_elf_symbol_address_p
Unexecuted instantiation: elf32-am33lin.c:mn10300_elf_symbol_address_p
2592
2593
/* This function handles relaxing for the mn10300.
2594
2595
   There are quite a few relaxing opportunities available on the mn10300:
2596
2597
  * calls:32 -> calls:16             2 bytes
2598
  * call:32  -> call:16            2 bytes
2599
2600
  * call:32 -> calls:32            1 byte
2601
  * call:16 -> calls:16            1 byte
2602
    * These are done anytime using "calls" would result
2603
    in smaller code, or when necessary to preserve the
2604
    meaning of the program.
2605
2606
  * call:32              varies
2607
  * call:16
2608
    * In some circumstances we can move instructions
2609
    from a function prologue into a "call" instruction.
2610
    This is only done if the resulting code is no larger
2611
    than the original code.
2612
2613
  * jmp:32 -> jmp:16             2 bytes
2614
  * jmp:16 -> bra:8            1 byte
2615
2616
    * If the previous instruction is a conditional branch
2617
    around the jump/bra, we may be able to reverse its condition
2618
    and change its target to the jump's target.  The jump/bra
2619
    can then be deleted.           2 bytes
2620
2621
  * mov abs32 -> mov abs16           1 or 2 bytes
2622
2623
  * Most instructions which accept imm32 can relax to imm16  1 or 2 bytes
2624
  - Most instructions which accept imm16 can relax to imm8   1 or 2 bytes
2625
2626
  * Most instructions which accept d32 can relax to d16    1 or 2 bytes
2627
  - Most instructions which accept d16 can relax to d8     1 or 2 bytes
2628
2629
  We don't handle imm16->imm8 or d16->d8 as they're very rare
2630
  and somewhat more difficult to support.  */
2631
2632
static bool
2633
mn10300_elf_relax_section (bfd *abfd,
2634
         asection *sec,
2635
         struct bfd_link_info *link_info,
2636
         bool *again)
2637
0
{
2638
0
  Elf_Internal_Shdr *symtab_hdr;
2639
0
  Elf_Internal_Rela *internal_relocs = NULL;
2640
0
  Elf_Internal_Rela *irel, *irelend;
2641
0
  bfd_byte *contents = NULL;
2642
0
  Elf_Internal_Sym *isymbuf = NULL;
2643
0
  struct elf32_mn10300_link_hash_table *hash_table;
2644
0
  asection *section = sec;
2645
0
  bfd_vma align_gap_adjustment;
2646
2647
0
  if (bfd_link_relocatable (link_info))
2648
0
    link_info->callbacks->fatal
2649
0
      (_("%P: --relax and -r may not be used together\n"));
2650
2651
  /* Assume nothing changes.  */
2652
0
  *again = false;
2653
2654
  /* We need a pointer to the mn10300 specific hash table.  */
2655
0
  hash_table = elf32_mn10300_hash_table (link_info);
2656
0
  if (hash_table == NULL)
2657
0
    return false;
2658
2659
  /* Initialize fields in each hash table entry the first time through.  */
2660
0
  if ((hash_table->flags & MN10300_HASH_ENTRIES_INITIALIZED) == 0)
2661
0
    {
2662
0
      bfd *input_bfd;
2663
2664
      /* Iterate over all the input bfds.  */
2665
0
      for (input_bfd = link_info->input_bfds;
2666
0
     input_bfd != NULL;
2667
0
     input_bfd = input_bfd->link.next)
2668
0
  {
2669
    /* We're going to need all the symbols for each bfd.  */
2670
0
    symtab_hdr = &elf_symtab_hdr (input_bfd);
2671
0
    if (symtab_hdr->sh_info != 0)
2672
0
      {
2673
0
        isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
2674
0
        if (isymbuf == NULL)
2675
0
    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
2676
0
            symtab_hdr->sh_info, 0,
2677
0
            NULL, NULL, NULL);
2678
0
        if (isymbuf == NULL)
2679
0
    goto error_return;
2680
0
      }
2681
2682
    /* Iterate over each section in this bfd.  */
2683
0
    for (section = input_bfd->sections;
2684
0
         section != NULL;
2685
0
         section = section->next)
2686
0
      {
2687
0
        struct elf32_mn10300_link_hash_entry *hash;
2688
0
        asection *sym_sec = NULL;
2689
0
        const char *sym_name;
2690
0
        char *new_name;
2691
2692
        /* If there's nothing to do in this section, skip it.  */
2693
0
        if (! ((section->flags & SEC_RELOC) != 0
2694
0
         && section->reloc_count != 0))
2695
0
    continue;
2696
0
        if ((section->flags & SEC_ALLOC) == 0
2697
0
      || (section->flags & SEC_HAS_CONTENTS) == 0)
2698
0
    continue;
2699
2700
        /* Get cached copy of section contents if it exists.  */
2701
0
        if (elf_section_data (section)->this_hdr.contents != NULL)
2702
0
    contents = elf_section_data (section)->this_hdr.contents;
2703
0
        else if (section->size != 0)
2704
0
    {
2705
      /* Go get them off disk.  */
2706
0
      if (!bfd_malloc_and_get_section (input_bfd, section,
2707
0
               &contents))
2708
0
        goto error_return;
2709
0
    }
2710
0
        else
2711
0
    contents = NULL;
2712
2713
        /* If there aren't any relocs, then there's nothing to do.  */
2714
0
        if ((section->flags & SEC_RELOC) != 0
2715
0
      && section->reloc_count != 0)
2716
0
    {
2717
      /* Get a copy of the native relocations.  */
2718
0
      internal_relocs = _bfd_elf_link_read_relocs (input_bfd, section,
2719
0
                     NULL, NULL,
2720
0
                     link_info->keep_memory);
2721
0
      if (internal_relocs == NULL)
2722
0
        goto error_return;
2723
2724
      /* Now examine each relocation.  */
2725
0
      irel = internal_relocs;
2726
0
      irelend = irel + section->reloc_count;
2727
0
      for (; irel < irelend; irel++)
2728
0
        {
2729
0
          long r_type;
2730
0
          unsigned long r_index;
2731
0
          unsigned char code;
2732
2733
0
          r_type = ELF32_R_TYPE (irel->r_info);
2734
0
          r_index = ELF32_R_SYM (irel->r_info);
2735
2736
0
          if (r_type < 0 || r_type >= (int) R_MN10300_MAX)
2737
0
      goto error_return;
2738
2739
          /* We need the name and hash table entry of the target
2740
       symbol!  */
2741
0
          hash = NULL;
2742
0
          sym_sec = NULL;
2743
2744
0
          if (r_index < symtab_hdr->sh_info)
2745
0
      {
2746
        /* A local symbol.  */
2747
0
        Elf_Internal_Sym *isym;
2748
0
        struct elf_link_hash_table *elftab;
2749
0
        size_t amt;
2750
2751
0
        isym = isymbuf + r_index;
2752
0
        if (isym->st_shndx == SHN_UNDEF)
2753
0
          sym_sec = bfd_und_section_ptr;
2754
0
        else if (isym->st_shndx == SHN_ABS)
2755
0
          sym_sec = bfd_abs_section_ptr;
2756
0
        else if (isym->st_shndx == SHN_COMMON)
2757
0
          sym_sec = bfd_com_section_ptr;
2758
0
        else
2759
0
          sym_sec
2760
0
            = bfd_section_from_elf_index (input_bfd,
2761
0
                  isym->st_shndx);
2762
2763
0
        sym_name
2764
0
          = bfd_elf_string_from_elf_section (input_bfd,
2765
0
                     (symtab_hdr
2766
0
                ->sh_link),
2767
0
                     isym->st_name);
2768
2769
        /* If it isn't a function, then we don't care
2770
           about it.  */
2771
0
        if (ELF_ST_TYPE (isym->st_info) != STT_FUNC)
2772
0
          continue;
2773
2774
        /* Tack on an ID so we can uniquely identify this
2775
           local symbol in the global hash table.  */
2776
0
        amt = strlen (sym_name) + 10;
2777
0
        new_name = bfd_malloc (amt);
2778
0
        if (new_name == NULL)
2779
0
          goto error_return;
2780
2781
0
        sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
2782
0
        sym_name = new_name;
2783
2784
0
        elftab = &hash_table->static_hash_table->root;
2785
0
        hash = ((struct elf32_mn10300_link_hash_entry *)
2786
0
          elf_link_hash_lookup (elftab, sym_name,
2787
0
              true, true, false));
2788
0
        free (new_name);
2789
0
      }
2790
0
          else
2791
0
      {
2792
0
        r_index -= symtab_hdr->sh_info;
2793
0
        hash = (struct elf32_mn10300_link_hash_entry *)
2794
0
           elf_sym_hashes (input_bfd)[r_index];
2795
0
      }
2796
2797
0
          sym_name = hash->root.root.root.string;
2798
0
          if ((section->flags & SEC_CODE) != 0)
2799
0
      {
2800
        /* If this is not a "call" instruction, then we
2801
           should convert "call" instructions to "calls"
2802
           instructions.  */
2803
0
        code = bfd_get_8 (input_bfd,
2804
0
              contents + irel->r_offset - 1);
2805
0
        if (code != 0xdd && code != 0xcd)
2806
0
          hash->flags |= MN10300_CONVERT_CALL_TO_CALLS;
2807
0
      }
2808
2809
          /* If this is a jump/call, then bump the
2810
       direct_calls counter.  Else force "call" to
2811
       "calls" conversions.  */
2812
0
          if (r_type == R_MN10300_PCREL32
2813
0
        || r_type == R_MN10300_PLT32
2814
0
        || r_type == R_MN10300_PLT16
2815
0
        || r_type == R_MN10300_PCREL16)
2816
0
      hash->direct_calls++;
2817
0
          else
2818
0
      hash->flags |= MN10300_CONVERT_CALL_TO_CALLS;
2819
0
        }
2820
0
    }
2821
2822
        /* Now look at the actual contents to get the stack size,
2823
     and a list of what registers were saved in the prologue
2824
     (ie movm_args).  */
2825
0
        if ((section->flags & SEC_CODE) != 0)
2826
0
    {
2827
0
      Elf_Internal_Sym *isym, *isymend;
2828
0
      unsigned int sec_shndx;
2829
0
      struct elf_link_hash_entry **hashes;
2830
0
      struct elf_link_hash_entry **end_hashes;
2831
0
      unsigned int symcount;
2832
2833
0
      sec_shndx = _bfd_elf_section_from_bfd_section (input_bfd,
2834
0
                 section);
2835
2836
0
      symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
2837
0
            - symtab_hdr->sh_info);
2838
0
      hashes = elf_sym_hashes (input_bfd);
2839
0
      end_hashes = hashes + symcount;
2840
2841
      /* Look at each function defined in this section and
2842
         update info for that function.  */
2843
0
      isymend = isymbuf + symtab_hdr->sh_info;
2844
0
      for (isym = isymbuf; isym < isymend; isym++)
2845
0
        {
2846
0
          if (isym->st_shndx == sec_shndx
2847
0
        && ELF_ST_TYPE (isym->st_info) == STT_FUNC)
2848
0
      {
2849
0
        struct elf_link_hash_table *elftab;
2850
0
        size_t amt;
2851
0
        struct elf_link_hash_entry **lhashes = hashes;
2852
2853
        /* Skip a local symbol if it aliases a
2854
           global one.  */
2855
0
        for (; lhashes < end_hashes; lhashes++)
2856
0
          {
2857
0
            hash = (struct elf32_mn10300_link_hash_entry *) *lhashes;
2858
0
            if ((hash->root.root.type == bfd_link_hash_defined
2859
0
           || hash->root.root.type == bfd_link_hash_defweak)
2860
0
          && hash->root.root.u.def.section == section
2861
0
          && hash->root.type == STT_FUNC
2862
0
          && hash->root.root.u.def.value == isym->st_value)
2863
0
        break;
2864
0
          }
2865
0
        if (lhashes != end_hashes)
2866
0
          continue;
2867
2868
0
        if (isym->st_shndx == SHN_UNDEF)
2869
0
          sym_sec = bfd_und_section_ptr;
2870
0
        else if (isym->st_shndx == SHN_ABS)
2871
0
          sym_sec = bfd_abs_section_ptr;
2872
0
        else if (isym->st_shndx == SHN_COMMON)
2873
0
          sym_sec = bfd_com_section_ptr;
2874
0
        else
2875
0
          sym_sec
2876
0
            = bfd_section_from_elf_index (input_bfd,
2877
0
                  isym->st_shndx);
2878
2879
0
        sym_name = (bfd_elf_string_from_elf_section
2880
0
              (input_bfd, symtab_hdr->sh_link,
2881
0
               isym->st_name));
2882
2883
        /* Tack on an ID so we can uniquely identify this
2884
           local symbol in the global hash table.  */
2885
0
        amt = strlen (sym_name) + 10;
2886
0
        new_name = bfd_malloc (amt);
2887
0
        if (new_name == NULL)
2888
0
          goto error_return;
2889
2890
0
        sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
2891
0
        sym_name = new_name;
2892
2893
0
        elftab = &hash_table->static_hash_table->root;
2894
0
        hash = ((struct elf32_mn10300_link_hash_entry *)
2895
0
          elf_link_hash_lookup (elftab, sym_name,
2896
0
              true, true, false));
2897
0
        free (new_name);
2898
0
        compute_function_info (input_bfd, hash,
2899
0
             isym->st_value, contents);
2900
0
        hash->value = isym->st_value;
2901
0
      }
2902
0
        }
2903
2904
0
      for (; hashes < end_hashes; hashes++)
2905
0
        {
2906
0
          hash = (struct elf32_mn10300_link_hash_entry *) *hashes;
2907
0
          if ((hash->root.root.type == bfd_link_hash_defined
2908
0
         || hash->root.root.type == bfd_link_hash_defweak)
2909
0
        && hash->root.root.u.def.section == section
2910
0
        && hash->root.type == STT_FUNC)
2911
0
      compute_function_info (input_bfd, hash,
2912
0
                 (hash)->root.root.u.def.value,
2913
0
                 contents);
2914
0
        }
2915
0
    }
2916
2917
        /* Cache or free any memory we allocated for the relocs.  */
2918
0
        if (elf_section_data (section)->relocs != internal_relocs)
2919
0
    free (internal_relocs);
2920
0
        internal_relocs = NULL;
2921
2922
        /* Cache or free any memory we allocated for the contents.  */
2923
0
        if (contents != NULL
2924
0
      && elf_section_data (section)->this_hdr.contents != contents)
2925
0
    {
2926
0
      if (! link_info->keep_memory)
2927
0
        free (contents);
2928
0
      else
2929
0
        {
2930
          /* Cache the section contents for elf_link_input_bfd.  */
2931
0
          elf_section_data (section)->this_hdr.contents = contents;
2932
0
        }
2933
0
    }
2934
0
        contents = NULL;
2935
0
      }
2936
2937
    /* Cache or free any memory we allocated for the symbols.  */
2938
0
    if (isymbuf != NULL
2939
0
        && symtab_hdr->contents != (unsigned char *) isymbuf)
2940
0
      {
2941
0
        if (! link_info->keep_memory)
2942
0
    free (isymbuf);
2943
0
        else
2944
0
    {
2945
      /* Cache the symbols for elf_link_input_bfd.  */
2946
0
      symtab_hdr->contents = (unsigned char *) isymbuf;
2947
0
    }
2948
0
      }
2949
0
    isymbuf = NULL;
2950
0
  }
2951
2952
      /* Now iterate on each symbol in the hash table and perform
2953
   the final initialization steps on each.  */
2954
0
      elf32_mn10300_link_hash_traverse (hash_table,
2955
0
          elf32_mn10300_finish_hash_table_entry,
2956
0
          link_info);
2957
0
      elf32_mn10300_link_hash_traverse (hash_table->static_hash_table,
2958
0
          elf32_mn10300_finish_hash_table_entry,
2959
0
          link_info);
2960
2961
0
      {
2962
  /* This section of code collects all our local symbols, sorts
2963
     them by value, and looks for multiple symbols referring to
2964
     the same address.  For those symbols, the flags are merged.
2965
     At this point, the only flag that can be set is
2966
     MN10300_CONVERT_CALL_TO_CALLS, so we simply OR the flags
2967
     together.  */
2968
0
  int static_count = 0, i;
2969
0
  struct elf32_mn10300_link_hash_entry **entries;
2970
0
  struct elf32_mn10300_link_hash_entry **ptr;
2971
2972
0
  elf32_mn10300_link_hash_traverse (hash_table->static_hash_table,
2973
0
            elf32_mn10300_count_hash_table_entries,
2974
0
            &static_count);
2975
2976
0
  entries = bfd_malloc (static_count * sizeof (* ptr));
2977
2978
0
  ptr = entries;
2979
0
  elf32_mn10300_link_hash_traverse (hash_table->static_hash_table,
2980
0
            elf32_mn10300_list_hash_table_entries,
2981
0
            & ptr);
2982
2983
0
  qsort (entries, static_count, sizeof (entries[0]), sort_by_value);
2984
2985
0
  for (i = 0; i < static_count - 1; i++)
2986
0
    if (entries[i]->value && entries[i]->value == entries[i+1]->value)
2987
0
      {
2988
0
        int v = entries[i]->flags;
2989
0
        int j;
2990
2991
0
        for (j = i + 1; j < static_count && entries[j]->value == entries[i]->value; j++)
2992
0
    v |= entries[j]->flags;
2993
2994
0
        for (j = i; j < static_count && entries[j]->value == entries[i]->value; j++)
2995
0
    entries[j]->flags = v;
2996
2997
0
        i = j - 1;
2998
0
      }
2999
0
      }
3000
3001
      /* All entries in the hash table are fully initialized.  */
3002
0
      hash_table->flags |= MN10300_HASH_ENTRIES_INITIALIZED;
3003
3004
      /* Now that everything has been initialized, go through each
3005
   code section and delete any prologue insns which will be
3006
   redundant because their operations will be performed by
3007
   a "call" instruction.  */
3008
0
      for (input_bfd = link_info->input_bfds;
3009
0
     input_bfd != NULL;
3010
0
     input_bfd = input_bfd->link.next)
3011
0
  {
3012
    /* We're going to need all the local symbols for each bfd.  */
3013
0
    symtab_hdr = &elf_symtab_hdr (input_bfd);
3014
0
    if (symtab_hdr->sh_info != 0)
3015
0
      {
3016
0
        isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
3017
0
        if (isymbuf == NULL)
3018
0
    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
3019
0
            symtab_hdr->sh_info, 0,
3020
0
            NULL, NULL, NULL);
3021
0
        if (isymbuf == NULL)
3022
0
    goto error_return;
3023
0
      }
3024
3025
    /* Walk over each section in this bfd.  */
3026
0
    for (section = input_bfd->sections;
3027
0
         section != NULL;
3028
0
         section = section->next)
3029
0
      {
3030
0
        unsigned int sec_shndx;
3031
0
        Elf_Internal_Sym *isym, *isymend;
3032
0
        struct elf_link_hash_entry **hashes;
3033
0
        struct elf_link_hash_entry **end_hashes;
3034
0
        unsigned int symcount;
3035
3036
        /* Skip non-code sections and empty sections.  */
3037
0
        if ((section->flags & SEC_CODE) == 0
3038
0
      || (section->flags & SEC_HAS_CONTENTS) == 0
3039
0
      || section->size == 0)
3040
0
    continue;
3041
3042
0
        if (section->reloc_count != 0)
3043
0
    {
3044
      /* Get a copy of the native relocations.  */
3045
0
      internal_relocs = _bfd_elf_link_read_relocs (input_bfd, section,
3046
0
                     NULL, NULL,
3047
0
                     link_info->keep_memory);
3048
0
      if (internal_relocs == NULL)
3049
0
        goto error_return;
3050
0
    }
3051
3052
        /* Get cached copy of section contents if it exists.  */
3053
0
        if (elf_section_data (section)->this_hdr.contents != NULL)
3054
0
    contents = elf_section_data (section)->this_hdr.contents;
3055
0
        else
3056
0
    {
3057
      /* Go get them off disk.  */
3058
0
      if (!bfd_malloc_and_get_section (input_bfd, section,
3059
0
               &contents))
3060
0
        goto error_return;
3061
0
    }
3062
3063
0
        sec_shndx = _bfd_elf_section_from_bfd_section (input_bfd,
3064
0
                   section);
3065
3066
        /* Now look for any function in this section which needs
3067
     insns deleted from its prologue.  */
3068
0
        isymend = isymbuf + symtab_hdr->sh_info;
3069
0
        for (isym = isymbuf; isym < isymend; isym++)
3070
0
    {
3071
0
      struct elf32_mn10300_link_hash_entry *sym_hash;
3072
0
      asection *sym_sec = NULL;
3073
0
      const char *sym_name;
3074
0
      char *new_name;
3075
0
      struct elf_link_hash_table *elftab;
3076
0
      size_t amt;
3077
3078
0
      if (isym->st_shndx != sec_shndx)
3079
0
        continue;
3080
3081
0
      if (isym->st_shndx == SHN_UNDEF)
3082
0
        sym_sec = bfd_und_section_ptr;
3083
0
      else if (isym->st_shndx == SHN_ABS)
3084
0
        sym_sec = bfd_abs_section_ptr;
3085
0
      else if (isym->st_shndx == SHN_COMMON)
3086
0
        sym_sec = bfd_com_section_ptr;
3087
0
      else
3088
0
        sym_sec
3089
0
          = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
3090
3091
0
      sym_name
3092
0
        = bfd_elf_string_from_elf_section (input_bfd,
3093
0
                   symtab_hdr->sh_link,
3094
0
                   isym->st_name);
3095
3096
      /* Tack on an ID so we can uniquely identify this
3097
         local symbol in the global hash table.  */
3098
0
      amt = strlen (sym_name) + 10;
3099
0
      new_name = bfd_malloc (amt);
3100
0
      if (new_name == NULL)
3101
0
        goto error_return;
3102
0
      sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
3103
0
      sym_name = new_name;
3104
3105
0
      elftab = & hash_table->static_hash_table->root;
3106
0
      sym_hash = (struct elf32_mn10300_link_hash_entry *)
3107
0
        elf_link_hash_lookup (elftab, sym_name,
3108
0
            false, false, false);
3109
3110
0
      free (new_name);
3111
0
      if (sym_hash == NULL)
3112
0
        continue;
3113
3114
0
      if (! (sym_hash->flags & MN10300_CONVERT_CALL_TO_CALLS)
3115
0
          && ! (sym_hash->flags & MN10300_DELETED_PROLOGUE_BYTES))
3116
0
        {
3117
0
          int bytes = 0;
3118
3119
          /* Note that we've changed things.  */
3120
0
          elf_section_data (section)->relocs = internal_relocs;
3121
0
          elf_section_data (section)->this_hdr.contents = contents;
3122
0
          symtab_hdr->contents = (unsigned char *) isymbuf;
3123
3124
          /* Count how many bytes we're going to delete.  */
3125
0
          if (sym_hash->movm_args)
3126
0
      bytes += 2;
3127
3128
0
          if (sym_hash->stack_size > 0)
3129
0
      {
3130
0
        if (sym_hash->stack_size <= 128)
3131
0
          bytes += 3;
3132
0
        else
3133
0
          bytes += 4;
3134
0
      }
3135
3136
          /* Note that we've deleted prologue bytes for this
3137
       function.  */
3138
0
          sym_hash->flags |= MN10300_DELETED_PROLOGUE_BYTES;
3139
3140
          /* Actually delete the bytes.  */
3141
0
          if (!mn10300_elf_relax_delete_bytes (input_bfd,
3142
0
                 section,
3143
0
                 isym->st_value,
3144
0
                 bytes))
3145
0
      goto error_return;
3146
3147
          /* Something changed.  Not strictly necessary, but
3148
       may lead to more relaxing opportunities.  */
3149
0
          *again = true;
3150
0
        }
3151
0
    }
3152
3153
        /* Look for any global functions in this section which
3154
     need insns deleted from their prologues.  */
3155
0
        symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
3156
0
        - symtab_hdr->sh_info);
3157
0
        hashes = elf_sym_hashes (input_bfd);
3158
0
        end_hashes = hashes + symcount;
3159
0
        for (; hashes < end_hashes; hashes++)
3160
0
    {
3161
0
      struct elf32_mn10300_link_hash_entry *sym_hash;
3162
3163
0
      sym_hash = (struct elf32_mn10300_link_hash_entry *) *hashes;
3164
0
      if ((sym_hash->root.root.type == bfd_link_hash_defined
3165
0
           || sym_hash->root.root.type == bfd_link_hash_defweak)
3166
0
          && sym_hash->root.root.u.def.section == section
3167
0
          && ! (sym_hash->flags & MN10300_CONVERT_CALL_TO_CALLS)
3168
0
          && ! (sym_hash->flags & MN10300_DELETED_PROLOGUE_BYTES))
3169
0
        {
3170
0
          int bytes = 0;
3171
0
          bfd_vma symval;
3172
0
          struct elf_link_hash_entry **hh;
3173
3174
          /* Note that we've changed things.  */
3175
0
          elf_section_data (section)->relocs = internal_relocs;
3176
0
          elf_section_data (section)->this_hdr.contents = contents;
3177
0
          symtab_hdr->contents = (unsigned char *) isymbuf;
3178
3179
          /* Count how many bytes we're going to delete.  */
3180
0
          if (sym_hash->movm_args)
3181
0
      bytes += 2;
3182
3183
0
          if (sym_hash->stack_size > 0)
3184
0
      {
3185
0
        if (sym_hash->stack_size <= 128)
3186
0
          bytes += 3;
3187
0
        else
3188
0
          bytes += 4;
3189
0
      }
3190
3191
          /* Note that we've deleted prologue bytes for this
3192
       function.  */
3193
0
          sym_hash->flags |= MN10300_DELETED_PROLOGUE_BYTES;
3194
3195
          /* Actually delete the bytes.  */
3196
0
          symval = sym_hash->root.root.u.def.value;
3197
0
          if (!mn10300_elf_relax_delete_bytes (input_bfd,
3198
0
                 section,
3199
0
                 symval,
3200
0
                 bytes))
3201
0
      goto error_return;
3202
3203
          /* There may be other C++ functions symbols with the same
3204
       address.  If so then mark these as having had their
3205
       prologue bytes deleted as well.  */
3206
0
          for (hh = elf_sym_hashes (input_bfd); hh < end_hashes; hh++)
3207
0
      {
3208
0
        struct elf32_mn10300_link_hash_entry *h;
3209
3210
0
        h = (struct elf32_mn10300_link_hash_entry *) * hh;
3211
3212
0
        if (h != sym_hash
3213
0
            && (h->root.root.type == bfd_link_hash_defined
3214
0
          || h->root.root.type == bfd_link_hash_defweak)
3215
0
            && h->root.root.u.def.section == section
3216
0
            && ! (h->flags & MN10300_CONVERT_CALL_TO_CALLS)
3217
0
            && h->root.root.u.def.value == symval
3218
0
            && h->root.type == STT_FUNC)
3219
0
          h->flags |= MN10300_DELETED_PROLOGUE_BYTES;
3220
0
      }
3221
3222
          /* Something changed.  Not strictly necessary, but
3223
       may lead to more relaxing opportunities.  */
3224
0
          *again = true;
3225
0
        }
3226
0
    }
3227
3228
        /* Cache or free any memory we allocated for the relocs.  */
3229
0
        if (elf_section_data (section)->relocs != internal_relocs)
3230
0
    free (internal_relocs);
3231
0
        internal_relocs = NULL;
3232
3233
        /* Cache or free any memory we allocated for the contents.  */
3234
0
        if (contents != NULL
3235
0
      && elf_section_data (section)->this_hdr.contents != contents)
3236
0
    {
3237
0
      if (! link_info->keep_memory)
3238
0
        free (contents);
3239
0
      else
3240
        /* Cache the section contents for elf_link_input_bfd.  */
3241
0
        elf_section_data (section)->this_hdr.contents = contents;
3242
0
    }
3243
0
        contents = NULL;
3244
0
      }
3245
3246
    /* Cache or free any memory we allocated for the symbols.  */
3247
0
    if (isymbuf != NULL
3248
0
        && symtab_hdr->contents != (unsigned char *) isymbuf)
3249
0
      {
3250
0
        if (! link_info->keep_memory)
3251
0
    free (isymbuf);
3252
0
        else
3253
    /* Cache the symbols for elf_link_input_bfd.  */
3254
0
    symtab_hdr->contents = (unsigned char *) isymbuf;
3255
0
      }
3256
0
    isymbuf = NULL;
3257
0
  }
3258
0
    }
3259
3260
  /* (Re)initialize for the basic instruction shortening/relaxing pass.  */
3261
0
  contents = NULL;
3262
0
  internal_relocs = NULL;
3263
0
  isymbuf = NULL;
3264
  /* For error_return.  */
3265
0
  section = sec;
3266
3267
  /* We don't have to do anything for a relocatable link, if
3268
     this section does not have relocs, or if this is not a
3269
     code section.  */
3270
0
  if (bfd_link_relocatable (link_info)
3271
0
      || (sec->flags & SEC_RELOC) == 0
3272
0
      || sec->reloc_count == 0
3273
0
      || (sec->flags & SEC_CODE) == 0)
3274
0
    return true;
3275
3276
0
  symtab_hdr = &elf_symtab_hdr (abfd);
3277
3278
  /* Get a copy of the native relocations.  */
3279
0
  internal_relocs = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL,
3280
0
                 link_info->keep_memory);
3281
0
  if (internal_relocs == NULL)
3282
0
    goto error_return;
3283
3284
  /* Scan for worst case alignment gap changes.  Note that this logic
3285
     is not ideal; what we should do is run this scan for every
3286
     opcode/address range and adjust accordingly, but that's
3287
     expensive.  Worst case is that for an alignment of N bytes, we
3288
     move by 2*N-N-1 bytes, assuming we have aligns of 1, 2, 4, 8, etc
3289
     all before it.  Plus, this still doesn't cover cross-section
3290
     jumps with section alignment.  */
3291
0
  irelend = internal_relocs + sec->reloc_count;
3292
0
  align_gap_adjustment = 0;
3293
0
  for (irel = internal_relocs; irel < irelend; irel++)
3294
0
    {
3295
0
      if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_ALIGN)
3296
0
  {
3297
0
    bfd_vma adj = 1 << irel->r_addend;
3298
0
    bfd_vma aend = irel->r_offset;
3299
3300
0
    aend = BFD_ALIGN (aend, 1 << irel->r_addend);
3301
0
    adj = 2 * adj - adj - 1;
3302
3303
    /* Record the biggest adjustmnet.  Skip any alignment at the
3304
       end of our section.  */
3305
0
    if (align_gap_adjustment < adj
3306
0
        && aend < sec->output_section->vma + sec->output_offset + sec->size)
3307
0
      align_gap_adjustment = adj;
3308
0
  }
3309
0
    }
3310
3311
  /* Walk through them looking for relaxing opportunities.  */
3312
0
  irelend = internal_relocs + sec->reloc_count;
3313
0
  for (irel = internal_relocs; irel < irelend; irel++)
3314
0
    {
3315
0
      bfd_vma symval;
3316
0
      bfd_signed_vma jump_offset;
3317
0
      asection *sym_sec = NULL;
3318
0
      struct elf32_mn10300_link_hash_entry *h = NULL;
3319
3320
      /* If this isn't something that can be relaxed, then ignore
3321
   this reloc.  */
3322
0
      if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_NONE
3323
0
    || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_8
3324
0
    || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_MAX)
3325
0
  continue;
3326
3327
      /* Get the section contents if we haven't done so already.  */
3328
0
      if (contents == NULL)
3329
0
  {
3330
    /* Get cached copy if it exists.  */
3331
0
    if (elf_section_data (sec)->this_hdr.contents != NULL)
3332
0
      contents = elf_section_data (sec)->this_hdr.contents;
3333
0
    else
3334
0
      {
3335
        /* Go get them off disk.  */
3336
0
        if (!bfd_malloc_and_get_section (abfd, sec, &contents))
3337
0
    goto error_return;
3338
0
      }
3339
0
  }
3340
3341
      /* Read this BFD's symbols if we haven't done so already.  */
3342
0
      if (isymbuf == NULL && symtab_hdr->sh_info != 0)
3343
0
  {
3344
0
    isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
3345
0
    if (isymbuf == NULL)
3346
0
      isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
3347
0
              symtab_hdr->sh_info, 0,
3348
0
              NULL, NULL, NULL);
3349
0
    if (isymbuf == NULL)
3350
0
      goto error_return;
3351
0
  }
3352
3353
      /* Get the value of the symbol referred to by the reloc.  */
3354
0
      if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
3355
0
  {
3356
0
    Elf_Internal_Sym *isym;
3357
0
    const char *sym_name;
3358
0
    char *new_name;
3359
3360
    /* A local symbol.  */
3361
0
    isym = isymbuf + ELF32_R_SYM (irel->r_info);
3362
0
    if (isym->st_shndx == SHN_UNDEF)
3363
0
      sym_sec = bfd_und_section_ptr;
3364
0
    else if (isym->st_shndx == SHN_ABS)
3365
0
      sym_sec = bfd_abs_section_ptr;
3366
0
    else if (isym->st_shndx == SHN_COMMON)
3367
0
      sym_sec = bfd_com_section_ptr;
3368
0
    else
3369
0
      sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
3370
3371
0
    sym_name = bfd_elf_string_from_elf_section (abfd,
3372
0
                  symtab_hdr->sh_link,
3373
0
                  isym->st_name);
3374
3375
0
    if ((sym_sec->flags & SEC_MERGE)
3376
0
        && sym_sec->sec_info_type == SEC_INFO_TYPE_MERGE)
3377
0
      {
3378
0
        symval = isym->st_value;
3379
3380
        /* GAS may reduce relocations against symbols in SEC_MERGE
3381
     sections to a relocation against the section symbol when
3382
     the original addend was zero.  When the reloc is against
3383
     a section symbol we should include the addend in the
3384
     offset passed to _bfd_merged_section_offset, since the
3385
     location of interest is the original symbol.  On the
3386
     other hand, an access to "sym+addend" where "sym" is not
3387
     a section symbol should not include the addend;  Such an
3388
     access is presumed to be an offset from "sym";  The
3389
     location of interest is just "sym".  */
3390
0
        if (ELF_ST_TYPE (isym->st_info) == STT_SECTION)
3391
0
    symval += irel->r_addend;
3392
3393
0
        symval = _bfd_merged_section_offset (abfd, & sym_sec,
3394
0
               symval);
3395
3396
0
        if (ELF_ST_TYPE (isym->st_info) != STT_SECTION)
3397
0
    symval += irel->r_addend;
3398
3399
0
        symval += sym_sec->output_section->vma
3400
0
    + sym_sec->output_offset - irel->r_addend;
3401
0
      }
3402
0
    else
3403
0
      symval = (isym->st_value
3404
0
          + sym_sec->output_section->vma
3405
0
          + sym_sec->output_offset);
3406
3407
    /* Tack on an ID so we can uniquely identify this
3408
       local symbol in the global hash table.  */
3409
0
    new_name = bfd_malloc ((bfd_size_type) strlen (sym_name) + 10);
3410
0
    if (new_name == NULL)
3411
0
      goto error_return;
3412
0
    sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
3413
0
    sym_name = new_name;
3414
3415
0
    h = (struct elf32_mn10300_link_hash_entry *)
3416
0
    elf_link_hash_lookup (&hash_table->static_hash_table->root,
3417
0
              sym_name, false, false, false);
3418
0
    free (new_name);
3419
0
  }
3420
0
      else
3421
0
  {
3422
0
    unsigned long indx;
3423
3424
    /* An external symbol.  */
3425
0
    indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
3426
0
    h = (struct elf32_mn10300_link_hash_entry *)
3427
0
    (elf_sym_hashes (abfd)[indx]);
3428
0
    BFD_ASSERT (h != NULL);
3429
0
    if (h->root.root.type != bfd_link_hash_defined
3430
0
        && h->root.root.type != bfd_link_hash_defweak)
3431
      /* This appears to be a reference to an undefined
3432
         symbol.  Just ignore it--it will be caught by the
3433
         regular reloc processing.  */
3434
0
      continue;
3435
3436
    /* Check for a reference to a discarded symbol and ignore it.  */
3437
0
    if (h->root.root.u.def.section->output_section == NULL)
3438
0
      continue;
3439
3440
0
    sym_sec = h->root.root.u.def.section->output_section;
3441
3442
0
    symval = (h->root.root.u.def.value
3443
0
        + h->root.root.u.def.section->output_section->vma
3444
0
        + h->root.root.u.def.section->output_offset);
3445
0
  }
3446
3447
      /* For simplicity of coding, we are going to modify the section
3448
   contents, the section relocs, and the BFD symbol table.  We
3449
   must tell the rest of the code not to free up this
3450
   information.  It would be possible to instead create a table
3451
   of changes which have to be made, as is done in coff-mips.c;
3452
   that would be more work, but would require less memory when
3453
   the linker is run.  */
3454
3455
      /* Try to turn a 32bit pc-relative branch/call into a 16bit pc-relative
3456
   branch/call, also deal with "call" -> "calls" conversions and
3457
   insertion of prologue data into "call" instructions.  */
3458
0
      if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL32
3459
0
    || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PLT32)
3460
0
  {
3461
0
    bfd_vma value = symval;
3462
3463
0
    if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PLT32
3464
0
        && h != NULL
3465
0
        && ELF_ST_VISIBILITY (h->root.other) != STV_INTERNAL
3466
0
        && ELF_ST_VISIBILITY (h->root.other) != STV_HIDDEN
3467
0
        && h->root.plt.offset != (bfd_vma) -1)
3468
0
      {
3469
0
        asection * splt;
3470
3471
0
        splt = hash_table->root.splt;
3472
0
        value = ((splt->output_section->vma
3473
0
      + splt->output_offset
3474
0
      + h->root.plt.offset)
3475
0
           - (sec->output_section->vma
3476
0
        + sec->output_offset
3477
0
        + irel->r_offset));
3478
0
      }
3479
3480
    /* If we've got a "call" instruction that needs to be turned
3481
       into a "calls" instruction, do so now.  It saves a byte.  */
3482
0
    if (h && (h->flags & MN10300_CONVERT_CALL_TO_CALLS))
3483
0
      {
3484
0
        unsigned char code;
3485
3486
        /* Get the opcode.  */
3487
0
        code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
3488
3489
        /* Make sure we're working with a "call" instruction!  */
3490
0
        if (code == 0xdd)
3491
0
    {
3492
      /* Note that we've changed the relocs, section contents,
3493
         etc.  */
3494
0
      elf_section_data (sec)->relocs = internal_relocs;
3495
0
      elf_section_data (sec)->this_hdr.contents = contents;
3496
0
      symtab_hdr->contents = (unsigned char *) isymbuf;
3497
3498
      /* Fix the opcode.  */
3499
0
      bfd_put_8 (abfd, 0xfc, contents + irel->r_offset - 1);
3500
0
      bfd_put_8 (abfd, 0xff, contents + irel->r_offset);
3501
3502
      /* Fix irel->r_offset and irel->r_addend.  */
3503
0
      irel->r_offset += 1;
3504
0
      irel->r_addend += 1;
3505
3506
      /* Delete one byte of data.  */
3507
0
      if (!mn10300_elf_relax_delete_bytes (abfd, sec,
3508
0
                   irel->r_offset + 3, 1))
3509
0
        goto error_return;
3510
3511
      /* That will change things, so, we should relax again.
3512
         Note that this is not required, and it may be slow.  */
3513
0
      *again = true;
3514
0
    }
3515
0
      }
3516
0
    else if (h)
3517
0
      {
3518
        /* We've got a "call" instruction which needs some data
3519
     from target function filled in.  */
3520
0
        unsigned char code;
3521
3522
        /* Get the opcode.  */
3523
0
        code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
3524
3525
        /* Insert data from the target function into the "call"
3526
     instruction if needed.  */
3527
0
        if (code == 0xdd)
3528
0
    {
3529
0
      bfd_put_8 (abfd, h->movm_args, contents + irel->r_offset + 4);
3530
0
      bfd_put_8 (abfd, h->stack_size + h->movm_stack_size,
3531
0
           contents + irel->r_offset + 5);
3532
0
    }
3533
0
      }
3534
3535
    /* Deal with pc-relative gunk.  */
3536
0
    value -= (sec->output_section->vma + sec->output_offset);
3537
0
    value -= irel->r_offset;
3538
0
    value += irel->r_addend;
3539
3540
    /* See if the value will fit in 16 bits, note the high value is
3541
       0x7fff + 2 as the target will be two bytes closer if we are
3542
       able to relax, if it's in the same section.  */
3543
0
    if (sec->output_section == sym_sec->output_section)
3544
0
      jump_offset = 0x8001;
3545
0
    else
3546
0
      jump_offset = 0x7fff;
3547
3548
    /* Account for jumps across alignment boundaries using
3549
       align_gap_adjustment.  */
3550
0
    if ((bfd_signed_vma) value < jump_offset - (bfd_signed_vma) align_gap_adjustment
3551
0
        && ((bfd_signed_vma) value > -0x8000 + (bfd_signed_vma) align_gap_adjustment))
3552
0
      {
3553
0
        unsigned char code;
3554
3555
        /* Get the opcode.  */
3556
0
        code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
3557
3558
0
        if (code != 0xdc && code != 0xdd && code != 0xff)
3559
0
    continue;
3560
3561
        /* Note that we've changed the relocs, section contents, etc.  */
3562
0
        elf_section_data (sec)->relocs = internal_relocs;
3563
0
        elf_section_data (sec)->this_hdr.contents = contents;
3564
0
        symtab_hdr->contents = (unsigned char *) isymbuf;
3565
3566
        /* Fix the opcode.  */
3567
0
        if (code == 0xdc)
3568
0
    bfd_put_8 (abfd, 0xcc, contents + irel->r_offset - 1);
3569
0
        else if (code == 0xdd)
3570
0
    bfd_put_8 (abfd, 0xcd, contents + irel->r_offset - 1);
3571
0
        else if (code == 0xff)
3572
0
    bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
3573
3574
        /* Fix the relocation's type.  */
3575
0
        irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3576
0
             (ELF32_R_TYPE (irel->r_info)
3577
0
              == (int) R_MN10300_PLT32)
3578
0
             ? R_MN10300_PLT16 :
3579
0
             R_MN10300_PCREL16);
3580
3581
        /* Delete two bytes of data.  */
3582
0
        if (!mn10300_elf_relax_delete_bytes (abfd, sec,
3583
0
               irel->r_offset + 1, 2))
3584
0
    goto error_return;
3585
3586
        /* That will change things, so, we should relax again.
3587
     Note that this is not required, and it may be slow.  */
3588
0
        *again = true;
3589
0
      }
3590
0
  }
3591
3592
      /* Try to turn a 16bit pc-relative branch into a 8bit pc-relative
3593
   branch.  */
3594
0
      if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL16)
3595
0
  {
3596
0
    bfd_vma value = symval;
3597
3598
    /* If we've got a "call" instruction that needs to be turned
3599
       into a "calls" instruction, do so now.  It saves a byte.  */
3600
0
    if (h && (h->flags & MN10300_CONVERT_CALL_TO_CALLS))
3601
0
      {
3602
0
        unsigned char code;
3603
3604
        /* Get the opcode.  */
3605
0
        code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
3606
3607
        /* Make sure we're working with a "call" instruction!  */
3608
0
        if (code == 0xcd)
3609
0
    {
3610
      /* Note that we've changed the relocs, section contents,
3611
         etc.  */
3612
0
      elf_section_data (sec)->relocs = internal_relocs;
3613
0
      elf_section_data (sec)->this_hdr.contents = contents;
3614
0
      symtab_hdr->contents = (unsigned char *) isymbuf;
3615
3616
      /* Fix the opcode.  */
3617
0
      bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 1);
3618
0
      bfd_put_8 (abfd, 0xff, contents + irel->r_offset);
3619
3620
      /* Fix irel->r_offset and irel->r_addend.  */
3621
0
      irel->r_offset += 1;
3622
0
      irel->r_addend += 1;
3623
3624
      /* Delete one byte of data.  */
3625
0
      if (!mn10300_elf_relax_delete_bytes (abfd, sec,
3626
0
                   irel->r_offset + 1, 1))
3627
0
        goto error_return;
3628
3629
      /* That will change things, so, we should relax again.
3630
         Note that this is not required, and it may be slow.  */
3631
0
      *again = true;
3632
0
    }
3633
0
      }
3634
0
    else if (h)
3635
0
      {
3636
0
        unsigned char code;
3637
3638
        /* Get the opcode.  */
3639
0
        code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
3640
3641
        /* Insert data from the target function into the "call"
3642
     instruction if needed.  */
3643
0
        if (code == 0xcd)
3644
0
    {
3645
0
      bfd_put_8 (abfd, h->movm_args, contents + irel->r_offset + 2);
3646
0
      bfd_put_8 (abfd, h->stack_size + h->movm_stack_size,
3647
0
           contents + irel->r_offset + 3);
3648
0
    }
3649
0
      }
3650
3651
    /* Deal with pc-relative gunk.  */
3652
0
    value -= (sec->output_section->vma + sec->output_offset);
3653
0
    value -= irel->r_offset;
3654
0
    value += irel->r_addend;
3655
3656
    /* See if the value will fit in 8 bits, note the high value is
3657
       0x7f + 1 as the target will be one bytes closer if we are
3658
       able to relax.  */
3659
0
    if ((long) value < 0x80 && (long) value > -0x80)
3660
0
      {
3661
0
        unsigned char code;
3662
3663
        /* Get the opcode.  */
3664
0
        code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
3665
3666
0
        if (code != 0xcc)
3667
0
    continue;
3668
3669
        /* Note that we've changed the relocs, section contents, etc.  */
3670
0
        elf_section_data (sec)->relocs = internal_relocs;
3671
0
        elf_section_data (sec)->this_hdr.contents = contents;
3672
0
        symtab_hdr->contents = (unsigned char *) isymbuf;
3673
3674
        /* Fix the opcode.  */
3675
0
        bfd_put_8 (abfd, 0xca, contents + irel->r_offset - 1);
3676
3677
        /* Fix the relocation's type.  */
3678
0
        irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3679
0
             R_MN10300_PCREL8);
3680
3681
        /* Delete one byte of data.  */
3682
0
        if (!mn10300_elf_relax_delete_bytes (abfd, sec,
3683
0
               irel->r_offset + 1, 1))
3684
0
    goto error_return;
3685
3686
        /* That will change things, so, we should relax again.
3687
     Note that this is not required, and it may be slow.  */
3688
0
        *again = true;
3689
0
      }
3690
0
  }
3691
3692
      /* Try to eliminate an unconditional 8 bit pc-relative branch
3693
   which immediately follows a conditional 8 bit pc-relative
3694
   branch around the unconditional branch.
3695
3696
      original:   new:
3697
      bCC lab1    bCC' lab2
3698
      bra lab2
3699
     lab1:         lab1:
3700
3701
   This happens when the bCC can't reach lab2 at assembly time,
3702
   but due to other relaxations it can reach at link time.  */
3703
0
      if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL8)
3704
0
  {
3705
0
    Elf_Internal_Rela *nrel;
3706
0
    unsigned char code;
3707
3708
    /* Do nothing if this reloc is the last byte in the section.  */
3709
0
    if (irel->r_offset == sec->size)
3710
0
      continue;
3711
3712
    /* See if the next instruction is an unconditional pc-relative
3713
       branch, more often than not this test will fail, so we
3714
       test it first to speed things up.  */
3715
0
    code = bfd_get_8 (abfd, contents + irel->r_offset + 1);
3716
0
    if (code != 0xca)
3717
0
      continue;
3718
3719
    /* Also make sure the next relocation applies to the next
3720
       instruction and that it's a pc-relative 8 bit branch.  */
3721
0
    nrel = irel + 1;
3722
0
    if (nrel == irelend
3723
0
        || irel->r_offset + 2 != nrel->r_offset
3724
0
        || ELF32_R_TYPE (nrel->r_info) != (int) R_MN10300_PCREL8)
3725
0
      continue;
3726
3727
    /* Make sure our destination immediately follows the
3728
       unconditional branch.  */
3729
0
    if (symval != (sec->output_section->vma + sec->output_offset
3730
0
       + irel->r_offset + 3))
3731
0
      continue;
3732
3733
    /* Now make sure we are a conditional branch.  This may not
3734
       be necessary, but why take the chance.
3735
3736
       Note these checks assume that R_MN10300_PCREL8 relocs
3737
       only occur on bCC and bCCx insns.  If they occured
3738
       elsewhere, we'd need to know the start of this insn
3739
       for this check to be accurate.  */
3740
0
    code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
3741
0
    if (code != 0xc0 && code != 0xc1 && code != 0xc2
3742
0
        && code != 0xc3 && code != 0xc4 && code != 0xc5
3743
0
        && code != 0xc6 && code != 0xc7 && code != 0xc8
3744
0
        && code != 0xc9 && code != 0xe8 && code != 0xe9
3745
0
        && code != 0xea && code != 0xeb)
3746
0
      continue;
3747
3748
    /* We also have to be sure there is no symbol/label
3749
       at the unconditional branch.  */
3750
0
    if (mn10300_elf_symbol_address_p (abfd, sec, isymbuf,
3751
0
              irel->r_offset + 1))
3752
0
      continue;
3753
3754
    /* Note that we've changed the relocs, section contents, etc.  */
3755
0
    elf_section_data (sec)->relocs = internal_relocs;
3756
0
    elf_section_data (sec)->this_hdr.contents = contents;
3757
0
    symtab_hdr->contents = (unsigned char *) isymbuf;
3758
3759
    /* Reverse the condition of the first branch.  */
3760
0
    switch (code)
3761
0
      {
3762
0
      case 0xc8:
3763
0
        code = 0xc9;
3764
0
        break;
3765
0
      case 0xc9:
3766
0
        code = 0xc8;
3767
0
        break;
3768
0
      case 0xc0:
3769
0
        code = 0xc2;
3770
0
        break;
3771
0
      case 0xc2:
3772
0
        code = 0xc0;
3773
0
        break;
3774
0
      case 0xc3:
3775
0
        code = 0xc1;
3776
0
        break;
3777
0
      case 0xc1:
3778
0
        code = 0xc3;
3779
0
        break;
3780
0
      case 0xc4:
3781
0
        code = 0xc6;
3782
0
        break;
3783
0
      case 0xc6:
3784
0
        code = 0xc4;
3785
0
        break;
3786
0
      case 0xc7:
3787
0
        code = 0xc5;
3788
0
        break;
3789
0
      case 0xc5:
3790
0
        code = 0xc7;
3791
0
        break;
3792
0
      case 0xe8:
3793
0
        code = 0xe9;
3794
0
        break;
3795
0
      case 0x9d:
3796
0
        code = 0xe8;
3797
0
        break;
3798
0
      case 0xea:
3799
0
        code = 0xeb;
3800
0
        break;
3801
0
      case 0xeb:
3802
0
        code = 0xea;
3803
0
        break;
3804
0
      }
3805
0
    bfd_put_8 (abfd, code, contents + irel->r_offset - 1);
3806
3807
    /* Set the reloc type and symbol for the first branch
3808
       from the second branch.  */
3809
0
    irel->r_info = nrel->r_info;
3810
3811
    /* Make the reloc for the second branch a null reloc.  */
3812
0
    nrel->r_info = ELF32_R_INFO (ELF32_R_SYM (nrel->r_info),
3813
0
               R_MN10300_NONE);
3814
3815
    /* Delete two bytes of data.  */
3816
0
    if (!mn10300_elf_relax_delete_bytes (abfd, sec,
3817
0
                 irel->r_offset + 1, 2))
3818
0
      goto error_return;
3819
3820
    /* That will change things, so, we should relax again.
3821
       Note that this is not required, and it may be slow.  */
3822
0
    *again = true;
3823
0
  }
3824
3825
      /* Try to turn a 24 immediate, displacement or absolute address
3826
   into a 8 immediate, displacement or absolute address.  */
3827
0
      if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_24)
3828
0
  {
3829
0
    bfd_vma value = symval;
3830
0
    value += irel->r_addend;
3831
3832
    /* See if the value will fit in 8 bits.  */
3833
0
    if ((long) value < 0x7f && (long) value > -0x80)
3834
0
      {
3835
0
        unsigned char code;
3836
3837
        /* AM33 insns which have 24 operands are 6 bytes long and
3838
     will have 0xfd as the first byte.  */
3839
3840
        /* Get the first opcode.  */
3841
0
        code = bfd_get_8 (abfd, contents + irel->r_offset - 3);
3842
3843
0
        if (code == 0xfd)
3844
0
    {
3845
      /* Get the second opcode.  */
3846
0
      code = bfd_get_8 (abfd, contents + irel->r_offset - 2);
3847
3848
      /* We can not relax 0x6b, 0x7b, 0x8b, 0x9b as no 24bit
3849
         equivalent instructions exists.  */
3850
0
      if (code != 0x6b && code != 0x7b
3851
0
          && code != 0x8b && code != 0x9b
3852
0
          && ((code & 0x0f) == 0x09 || (code & 0x0f) == 0x08
3853
0
        || (code & 0x0f) == 0x0a || (code & 0x0f) == 0x0b
3854
0
        || (code & 0x0f) == 0x0e))
3855
0
        {
3856
          /* Not safe if the high bit is on as relaxing may
3857
       move the value out of high mem and thus not fit
3858
       in a signed 8bit value.  This is currently over
3859
       conservative.  */
3860
0
          if ((value & 0x80) == 0)
3861
0
      {
3862
        /* Note that we've changed the relocation contents,
3863
           etc.  */
3864
0
        elf_section_data (sec)->relocs = internal_relocs;
3865
0
        elf_section_data (sec)->this_hdr.contents = contents;
3866
0
        symtab_hdr->contents = (unsigned char *) isymbuf;
3867
3868
        /* Fix the opcode.  */
3869
0
        bfd_put_8 (abfd, 0xfb, contents + irel->r_offset - 3);
3870
0
        bfd_put_8 (abfd, code, contents + irel->r_offset - 2);
3871
3872
        /* Fix the relocation's type.  */
3873
0
        irel->r_info =
3874
0
          ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3875
0
            R_MN10300_8);
3876
3877
        /* Delete two bytes of data.  */
3878
0
        if (!mn10300_elf_relax_delete_bytes (abfd, sec,
3879
0
                     irel->r_offset + 1, 2))
3880
0
          goto error_return;
3881
3882
        /* That will change things, so, we should relax
3883
           again.  Note that this is not required, and it
3884
           may be slow.  */
3885
0
        *again = true;
3886
0
        break;
3887
0
      }
3888
0
        }
3889
0
    }
3890
0
      }
3891
0
  }
3892
3893
      /* Try to turn a 32bit immediate, displacement or absolute address
3894
   into a 16bit immediate, displacement or absolute address.  */
3895
0
      if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_32
3896
0
    || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOT32
3897
0
    || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTOFF32)
3898
0
  {
3899
0
    bfd_vma value = symval;
3900
3901
0
    if (ELF32_R_TYPE (irel->r_info) != (int) R_MN10300_32)
3902
0
      {
3903
0
        asection * sgot;
3904
3905
0
        sgot = hash_table->root.sgot;
3906
0
        if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOT32)
3907
0
    {
3908
0
      value = sgot->output_offset;
3909
3910
0
      if (h)
3911
0
        value += h->root.got.offset;
3912
0
      else
3913
0
        value += (elf_local_got_offsets
3914
0
            (abfd)[ELF32_R_SYM (irel->r_info)]);
3915
0
    }
3916
0
        else if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTOFF32)
3917
0
    value -= sgot->output_section->vma;
3918
0
        else if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTPC32)
3919
0
    value = (sgot->output_section->vma
3920
0
       - (sec->output_section->vma
3921
0
          + sec->output_offset
3922
0
          + irel->r_offset));
3923
0
        else
3924
0
    abort ();
3925
0
      }
3926
3927
0
    value += irel->r_addend;
3928
3929
    /* See if the value will fit in 24 bits.
3930
       We allow any 16bit match here.  We prune those we can't
3931
       handle below.  */
3932
0
    if (value + 0x800000 < 0x1000000 && irel->r_offset >= 3)
3933
0
      {
3934
0
        unsigned char code;
3935
3936
        /* AM33 insns which have 32bit operands are 7 bytes long and
3937
     will have 0xfe as the first byte.  */
3938
3939
        /* Get the first opcode.  */
3940
0
        code = bfd_get_8 (abfd, contents + irel->r_offset - 3);
3941
3942
0
        if (code == 0xfe)
3943
0
    {
3944
      /* Get the second opcode.  */
3945
0
      code = bfd_get_8 (abfd, contents + irel->r_offset - 2);
3946
3947
      /* All the am33 32 -> 24 relaxing possibilities.  */
3948
      /* We can not relax 0x6b, 0x7b, 0x8b, 0x9b as no 24bit
3949
         equivalent instructions exists.  */
3950
0
      if (code != 0x6b && code != 0x7b
3951
0
          && code != 0x8b && code != 0x9b
3952
0
          && (ELF32_R_TYPE (irel->r_info)
3953
0
        != (int) R_MN10300_GOTPC32)
3954
0
          && ((code & 0x0f) == 0x09 || (code & 0x0f) == 0x08
3955
0
        || (code & 0x0f) == 0x0a || (code & 0x0f) == 0x0b
3956
0
        || (code & 0x0f) == 0x0e))
3957
0
        {
3958
          /* Not safe if the high bit is on as relaxing may
3959
       move the value out of high mem and thus not fit
3960
       in a signed 16bit value.  This is currently over
3961
       conservative.  */
3962
0
          if ((value & 0x8000) == 0)
3963
0
      {
3964
        /* Note that we've changed the relocation contents,
3965
           etc.  */
3966
0
        elf_section_data (sec)->relocs = internal_relocs;
3967
0
        elf_section_data (sec)->this_hdr.contents = contents;
3968
0
        symtab_hdr->contents = (unsigned char *) isymbuf;
3969
3970
        /* Fix the opcode.  */
3971
0
        bfd_put_8 (abfd, 0xfd, contents + irel->r_offset - 3);
3972
0
        bfd_put_8 (abfd, code, contents + irel->r_offset - 2);
3973
3974
        /* Fix the relocation's type.  */
3975
0
        irel->r_info =
3976
0
          ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3977
0
            (ELF32_R_TYPE (irel->r_info)
3978
0
             == (int) R_MN10300_GOTOFF32)
3979
0
            ? R_MN10300_GOTOFF24
3980
0
            : (ELF32_R_TYPE (irel->r_info)
3981
0
               == (int) R_MN10300_GOT32)
3982
0
            ? R_MN10300_GOT24 :
3983
0
            R_MN10300_24);
3984
3985
        /* Delete one byte of data.  */
3986
0
        if (!mn10300_elf_relax_delete_bytes (abfd, sec,
3987
0
                     irel->r_offset + 3, 1))
3988
0
          goto error_return;
3989
3990
        /* That will change things, so, we should relax
3991
           again.  Note that this is not required, and it
3992
           may be slow.  */
3993
0
        *again = true;
3994
0
        break;
3995
0
      }
3996
0
        }
3997
0
    }
3998
0
      }
3999
4000
    /* See if the value will fit in 16 bits.
4001
       We allow any 16bit match here.  We prune those we can't
4002
       handle below.  */
4003
0
    if (value + 0x8000 < 0x10000 && irel->r_offset >= 2)
4004
0
      {
4005
0
        unsigned char code;
4006
4007
        /* Most insns which have 32bit operands are 6 bytes long;
4008
     exceptions are pcrel insns and bit insns.
4009
4010
     We handle pcrel insns above.  We don't bother trying
4011
     to handle the bit insns here.
4012
4013
     The first byte of the remaining insns will be 0xfc.  */
4014
4015
        /* Get the first opcode.  */
4016
0
        code = bfd_get_8 (abfd, contents + irel->r_offset - 2);
4017
4018
0
        if (code != 0xfc)
4019
0
    continue;
4020
4021
        /* Get the second opcode.  */
4022
0
        code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
4023
4024
0
        if ((code & 0xf0) < 0x80)
4025
0
    switch (code & 0xf0)
4026
0
      {
4027
      /* mov (d32,am),dn   -> mov (d32,am),dn
4028
         mov dm,(d32,am)   -> mov dn,(d32,am)
4029
         mov (d32,am),an   -> mov (d32,am),an
4030
         mov dm,(d32,am)   -> mov dn,(d32,am)
4031
         movbu (d32,am),dn -> movbu (d32,am),dn
4032
         movbu dm,(d32,am) -> movbu dn,(d32,am)
4033
         movhu (d32,am),dn -> movhu (d32,am),dn
4034
         movhu dm,(d32,am) -> movhu dn,(d32,am) */
4035
0
      case 0x00:
4036
0
      case 0x10:
4037
0
      case 0x20:
4038
0
      case 0x30:
4039
0
      case 0x40:
4040
0
      case 0x50:
4041
0
      case 0x60:
4042
0
      case 0x70:
4043
        /* Not safe if the high bit is on as relaxing may
4044
           move the value out of high mem and thus not fit
4045
           in a signed 16bit value.  */
4046
0
        if (code == 0xcc
4047
0
      && (value & 0x8000))
4048
0
          continue;
4049
4050
        /* Note that we've changed the relocation contents, etc.  */
4051
0
        elf_section_data (sec)->relocs = internal_relocs;
4052
0
        elf_section_data (sec)->this_hdr.contents = contents;
4053
0
        symtab_hdr->contents = (unsigned char *) isymbuf;
4054
4055
        /* Fix the opcode.  */
4056
0
        bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
4057
0
        bfd_put_8 (abfd, code, contents + irel->r_offset - 1);
4058
4059
        /* Fix the relocation's type.  */
4060
0
        irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
4061
0
             (ELF32_R_TYPE (irel->r_info)
4062
0
              == (int) R_MN10300_GOTOFF32)
4063
0
             ? R_MN10300_GOTOFF16
4064
0
             : (ELF32_R_TYPE (irel->r_info)
4065
0
                == (int) R_MN10300_GOT32)
4066
0
             ? R_MN10300_GOT16
4067
0
             : (ELF32_R_TYPE (irel->r_info)
4068
0
                == (int) R_MN10300_GOTPC32)
4069
0
             ? R_MN10300_GOTPC16 :
4070
0
             R_MN10300_16);
4071
4072
        /* Delete two bytes of data.  */
4073
0
        if (!mn10300_elf_relax_delete_bytes (abfd, sec,
4074
0
               irel->r_offset + 2, 2))
4075
0
          goto error_return;
4076
4077
        /* That will change things, so, we should relax again.
4078
           Note that this is not required, and it may be slow.  */
4079
0
        *again = true;
4080
0
        break;
4081
0
      }
4082
0
        else if ((code & 0xf0) == 0x80
4083
0
           || (code & 0xf0) == 0x90)
4084
0
    switch (code & 0xf3)
4085
0
      {
4086
      /* mov dn,(abs32)   -> mov dn,(abs16)
4087
         movbu dn,(abs32) -> movbu dn,(abs16)
4088
         movhu dn,(abs32) -> movhu dn,(abs16)  */
4089
0
      case 0x81:
4090
0
      case 0x82:
4091
0
      case 0x83:
4092
        /* Note that we've changed the relocation contents, etc.  */
4093
0
        elf_section_data (sec)->relocs = internal_relocs;
4094
0
        elf_section_data (sec)->this_hdr.contents = contents;
4095
0
        symtab_hdr->contents = (unsigned char *) isymbuf;
4096
4097
0
        if ((code & 0xf3) == 0x81)
4098
0
          code = 0x01 + (code & 0x0c);
4099
0
        else if ((code & 0xf3) == 0x82)
4100
0
          code = 0x02 + (code & 0x0c);
4101
0
        else if ((code & 0xf3) == 0x83)
4102
0
          code = 0x03 + (code & 0x0c);
4103
0
        else
4104
0
          abort ();
4105
4106
        /* Fix the opcode.  */
4107
0
        bfd_put_8 (abfd, code, contents + irel->r_offset - 2);
4108
4109
        /* Fix the relocation's type.  */
4110
0
        irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
4111
0
             (ELF32_R_TYPE (irel->r_info)
4112
0
              == (int) R_MN10300_GOTOFF32)
4113
0
             ? R_MN10300_GOTOFF16
4114
0
             : (ELF32_R_TYPE (irel->r_info)
4115
0
                == (int) R_MN10300_GOT32)
4116
0
             ? R_MN10300_GOT16
4117
0
             : (ELF32_R_TYPE (irel->r_info)
4118
0
                == (int) R_MN10300_GOTPC32)
4119
0
             ? R_MN10300_GOTPC16 :
4120
0
             R_MN10300_16);
4121
4122
        /* The opcode got shorter too, so we have to fix the
4123
           addend and offset too!  */
4124
0
        irel->r_offset -= 1;
4125
4126
        /* Delete three bytes of data.  */
4127
0
        if (!mn10300_elf_relax_delete_bytes (abfd, sec,
4128
0
               irel->r_offset + 1, 3))
4129
0
          goto error_return;
4130
4131
        /* That will change things, so, we should relax again.
4132
           Note that this is not required, and it may be slow.  */
4133
0
        *again = true;
4134
0
        break;
4135
4136
      /* mov am,(abs32)    -> mov am,(abs16)
4137
         mov am,(d32,sp)   -> mov am,(d16,sp)
4138
         mov dm,(d32,sp)   -> mov dm,(d32,sp)
4139
         movbu dm,(d32,sp) -> movbu dm,(d32,sp)
4140
         movhu dm,(d32,sp) -> movhu dm,(d32,sp) */
4141
0
      case 0x80:
4142
0
      case 0x90:
4143
0
      case 0x91:
4144
0
      case 0x92:
4145
0
      case 0x93:
4146
        /* sp-based offsets are zero-extended.  */
4147
0
        if (code >= 0x90 && code <= 0x93
4148
0
      && (long) value < 0)
4149
0
          continue;
4150
4151
        /* Note that we've changed the relocation contents, etc.  */
4152
0
        elf_section_data (sec)->relocs = internal_relocs;
4153
0
        elf_section_data (sec)->this_hdr.contents = contents;
4154
0
        symtab_hdr->contents = (unsigned char *) isymbuf;
4155
4156
        /* Fix the opcode.  */
4157
0
        bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
4158
0
        bfd_put_8 (abfd, code, contents + irel->r_offset - 1);
4159
4160
        /* Fix the relocation's type.  */
4161
0
        irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
4162
0
             (ELF32_R_TYPE (irel->r_info)
4163
0
              == (int) R_MN10300_GOTOFF32)
4164
0
             ? R_MN10300_GOTOFF16
4165
0
             : (ELF32_R_TYPE (irel->r_info)
4166
0
                == (int) R_MN10300_GOT32)
4167
0
             ? R_MN10300_GOT16
4168
0
             : (ELF32_R_TYPE (irel->r_info)
4169
0
                == (int) R_MN10300_GOTPC32)
4170
0
             ? R_MN10300_GOTPC16 :
4171
0
             R_MN10300_16);
4172
4173
        /* Delete two bytes of data.  */
4174
0
        if (!mn10300_elf_relax_delete_bytes (abfd, sec,
4175
0
               irel->r_offset + 2, 2))
4176
0
          goto error_return;
4177
4178
        /* That will change things, so, we should relax again.
4179
           Note that this is not required, and it may be slow.  */
4180
0
        *again = true;
4181
0
        break;
4182
0
      }
4183
0
        else if ((code & 0xf0) < 0xf0)
4184
0
    switch (code & 0xfc)
4185
0
      {
4186
      /* mov imm32,dn     -> mov imm16,dn
4187
         mov imm32,an     -> mov imm16,an
4188
         mov (abs32),dn   -> mov (abs16),dn
4189
         movbu (abs32),dn -> movbu (abs16),dn
4190
         movhu (abs32),dn -> movhu (abs16),dn  */
4191
0
      case 0xcc:
4192
0
      case 0xdc:
4193
0
      case 0xa4:
4194
0
      case 0xa8:
4195
0
      case 0xac:
4196
        /* Not safe if the high bit is on as relaxing may
4197
           move the value out of high mem and thus not fit
4198
           in a signed 16bit value.  */
4199
0
        if (code == 0xcc
4200
0
      && (value & 0x8000))
4201
0
          continue;
4202
4203
        /* "mov imm16, an" zero-extends the immediate.  */
4204
0
        if ((code & 0xfc) == 0xdc
4205
0
      && (long) value < 0)
4206
0
          continue;
4207
4208
        /* Note that we've changed the relocation contents, etc.  */
4209
0
        elf_section_data (sec)->relocs = internal_relocs;
4210
0
        elf_section_data (sec)->this_hdr.contents = contents;
4211
0
        symtab_hdr->contents = (unsigned char *) isymbuf;
4212
4213
0
        if ((code & 0xfc) == 0xcc)
4214
0
          code = 0x2c + (code & 0x03);
4215
0
        else if ((code & 0xfc) == 0xdc)
4216
0
          code = 0x24 + (code & 0x03);
4217
0
        else if ((code & 0xfc) == 0xa4)
4218
0
          code = 0x30 + (code & 0x03);
4219
0
        else if ((code & 0xfc) == 0xa8)
4220
0
          code = 0x34 + (code & 0x03);
4221
0
        else if ((code & 0xfc) == 0xac)
4222
0
          code = 0x38 + (code & 0x03);
4223
0
        else
4224
0
          abort ();
4225
4226
        /* Fix the opcode.  */
4227
0
        bfd_put_8 (abfd, code, contents + irel->r_offset - 2);
4228
4229
        /* Fix the relocation's type.  */
4230
0
        irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
4231
0
             (ELF32_R_TYPE (irel->r_info)
4232
0
              == (int) R_MN10300_GOTOFF32)
4233
0
             ? R_MN10300_GOTOFF16
4234
0
             : (ELF32_R_TYPE (irel->r_info)
4235
0
                == (int) R_MN10300_GOT32)
4236
0
             ? R_MN10300_GOT16
4237
0
             : (ELF32_R_TYPE (irel->r_info)
4238
0
                == (int) R_MN10300_GOTPC32)
4239
0
             ? R_MN10300_GOTPC16 :
4240
0
             R_MN10300_16);
4241
4242
        /* The opcode got shorter too, so we have to fix the
4243
           addend and offset too!  */
4244
0
        irel->r_offset -= 1;
4245
4246
        /* Delete three bytes of data.  */
4247
0
        if (!mn10300_elf_relax_delete_bytes (abfd, sec,
4248
0
               irel->r_offset + 1, 3))
4249
0
          goto error_return;
4250
4251
        /* That will change things, so, we should relax again.
4252
           Note that this is not required, and it may be slow.  */
4253
0
        *again = true;
4254
0
        break;
4255
4256
      /* mov (abs32),an    -> mov (abs16),an
4257
         mov (d32,sp),an   -> mov (d16,sp),an
4258
         mov (d32,sp),dn   -> mov (d16,sp),dn
4259
         movbu (d32,sp),dn -> movbu (d16,sp),dn
4260
         movhu (d32,sp),dn -> movhu (d16,sp),dn
4261
         add imm32,dn      -> add imm16,dn
4262
         cmp imm32,dn      -> cmp imm16,dn
4263
         add imm32,an      -> add imm16,an
4264
         cmp imm32,an      -> cmp imm16,an
4265
         and imm32,dn      -> and imm16,dn
4266
         or imm32,dn       -> or imm16,dn
4267
         xor imm32,dn      -> xor imm16,dn
4268
         btst imm32,dn     -> btst imm16,dn */
4269
4270
0
      case 0xa0:
4271
0
      case 0xb0:
4272
0
      case 0xb1:
4273
0
      case 0xb2:
4274
0
      case 0xb3:
4275
0
      case 0xc0:
4276
0
      case 0xc8:
4277
4278
0
      case 0xd0:
4279
0
      case 0xd8:
4280
0
      case 0xe0:
4281
0
      case 0xe1:
4282
0
      case 0xe2:
4283
0
      case 0xe3:
4284
        /* cmp imm16, an zero-extends the immediate.  */
4285
0
        if (code == 0xdc
4286
0
      && (long) value < 0)
4287
0
          continue;
4288
4289
        /* So do sp-based offsets.  */
4290
0
        if (code >= 0xb0 && code <= 0xb3
4291
0
      && (long) value < 0)
4292
0
          continue;
4293
4294
        /* Note that we've changed the relocation contents, etc.  */
4295
0
        elf_section_data (sec)->relocs = internal_relocs;
4296
0
        elf_section_data (sec)->this_hdr.contents = contents;
4297
0
        symtab_hdr->contents = (unsigned char *) isymbuf;
4298
4299
        /* Fix the opcode.  */
4300
0
        bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
4301
0
        bfd_put_8 (abfd, code, contents + irel->r_offset - 1);
4302
4303
        /* Fix the relocation's type.  */
4304
0
        irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
4305
0
             (ELF32_R_TYPE (irel->r_info)
4306
0
              == (int) R_MN10300_GOTOFF32)
4307
0
             ? R_MN10300_GOTOFF16
4308
0
             : (ELF32_R_TYPE (irel->r_info)
4309
0
                == (int) R_MN10300_GOT32)
4310
0
             ? R_MN10300_GOT16
4311
0
             : (ELF32_R_TYPE (irel->r_info)
4312
0
                == (int) R_MN10300_GOTPC32)
4313
0
             ? R_MN10300_GOTPC16 :
4314
0
             R_MN10300_16);
4315
4316
        /* Delete two bytes of data.  */
4317
0
        if (!mn10300_elf_relax_delete_bytes (abfd, sec,
4318
0
               irel->r_offset + 2, 2))
4319
0
          goto error_return;
4320
4321
        /* That will change things, so, we should relax again.
4322
           Note that this is not required, and it may be slow.  */
4323
0
        *again = true;
4324
0
        break;
4325
0
      }
4326
0
        else if (code == 0xfe)
4327
0
    {
4328
      /* add imm32,sp -> add imm16,sp  */
4329
4330
      /* Note that we've changed the relocation contents, etc.  */
4331
0
      elf_section_data (sec)->relocs = internal_relocs;
4332
0
      elf_section_data (sec)->this_hdr.contents = contents;
4333
0
      symtab_hdr->contents = (unsigned char *) isymbuf;
4334
4335
      /* Fix the opcode.  */
4336
0
      bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
4337
0
      bfd_put_8 (abfd, 0xfe, contents + irel->r_offset - 1);
4338
4339
      /* Fix the relocation's type.  */
4340
0
      irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
4341
0
                 (ELF32_R_TYPE (irel->r_info)
4342
0
            == (int) R_MN10300_GOT32)
4343
0
                 ? R_MN10300_GOT16
4344
0
                 : (ELF32_R_TYPE (irel->r_info)
4345
0
              == (int) R_MN10300_GOTOFF32)
4346
0
                 ? R_MN10300_GOTOFF16
4347
0
                 : (ELF32_R_TYPE (irel->r_info)
4348
0
              == (int) R_MN10300_GOTPC32)
4349
0
                 ? R_MN10300_GOTPC16 :
4350
0
                 R_MN10300_16);
4351
4352
      /* Delete two bytes of data.  */
4353
0
      if (!mn10300_elf_relax_delete_bytes (abfd, sec,
4354
0
                   irel->r_offset + 2, 2))
4355
0
        goto error_return;
4356
4357
      /* That will change things, so, we should relax again.
4358
         Note that this is not required, and it may be slow.  */
4359
0
      *again = true;
4360
0
      break;
4361
0
    }
4362
0
      }
4363
0
  }
4364
0
    }
4365
4366
0
  if (isymbuf != NULL
4367
0
      && symtab_hdr->contents != (unsigned char *) isymbuf)
4368
0
    {
4369
0
      if (! link_info->keep_memory)
4370
0
  free (isymbuf);
4371
0
      else
4372
0
  {
4373
    /* Cache the symbols for elf_link_input_bfd.  */
4374
0
    symtab_hdr->contents = (unsigned char *) isymbuf;
4375
0
  }
4376
0
    }
4377
4378
0
  if (contents != NULL
4379
0
      && elf_section_data (sec)->this_hdr.contents != contents)
4380
0
    {
4381
0
      if (! link_info->keep_memory)
4382
0
  free (contents);
4383
0
      else
4384
0
  {
4385
    /* Cache the section contents for elf_link_input_bfd.  */
4386
0
    elf_section_data (sec)->this_hdr.contents = contents;
4387
0
  }
4388
0
    }
4389
4390
0
  if (elf_section_data (sec)->relocs != internal_relocs)
4391
0
    free (internal_relocs);
4392
4393
0
  return true;
4394
4395
0
 error_return:
4396
0
  if (symtab_hdr->contents != (unsigned char *) isymbuf)
4397
0
    free (isymbuf);
4398
0
  if (elf_section_data (section)->this_hdr.contents != contents)
4399
0
    free (contents);
4400
0
  if (elf_section_data (section)->relocs != internal_relocs)
4401
0
    free (internal_relocs);
4402
4403
0
  return false;
4404
0
}
Unexecuted instantiation: elf-m10300.c:mn10300_elf_relax_section
Unexecuted instantiation: elf32-am33lin.c:mn10300_elf_relax_section
4405
4406
/* This is a version of bfd_generic_get_relocated_section_contents
4407
   which uses mn10300_elf_relocate_section.  */
4408
4409
static bfd_byte *
4410
mn10300_elf_get_relocated_section_contents
4411
  (bfd *output_bfd,
4412
   struct bfd_link_info *link_info,
4413
   const struct bfd_link_order *link_order,
4414
   bfd_byte *data,
4415
   bool relocatable,
4416
   asymbol **symbols)
4417
4
{
4418
4
  Elf_Internal_Shdr *symtab_hdr;
4419
4
  asection *input_section = link_order->u.indirect.section;
4420
4
  bfd *input_bfd = input_section->owner;
4421
4
  asection **sections = NULL;
4422
4
  Elf_Internal_Rela *internal_relocs = NULL;
4423
4
  Elf_Internal_Sym *isymbuf = NULL;
4424
4425
  /* We only need to handle the case of relaxing, or of having a
4426
     particular set of section contents, specially.  */
4427
4
  if (relocatable
4428
4
      || elf_section_data (input_section)->this_hdr.contents == NULL)
4429
4
    return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
4430
4
                   link_order, data,
4431
4
                   relocatable,
4432
4
                   symbols);
4433
4434
0
  symtab_hdr = &elf_symtab_hdr (input_bfd);
4435
4436
0
  bfd_byte *orig_data = data;
4437
0
  if (data == NULL)
4438
0
    {
4439
0
      data = bfd_malloc (input_section->size);
4440
0
      if (data == NULL)
4441
0
  return NULL;
4442
0
    }
4443
0
  memcpy (data, elf_section_data (input_section)->this_hdr.contents,
4444
0
    (size_t) input_section->size);
4445
4446
0
  if ((input_section->flags & SEC_RELOC) != 0
4447
0
      && input_section->reloc_count > 0)
4448
0
    {
4449
0
      asection **secpp;
4450
0
      Elf_Internal_Sym *isym, *isymend;
4451
0
      bfd_size_type amt;
4452
4453
0
      internal_relocs = _bfd_elf_link_read_relocs (input_bfd, input_section,
4454
0
               NULL, NULL, false);
4455
0
      if (internal_relocs == NULL)
4456
0
  goto error_return;
4457
4458
0
      if (symtab_hdr->sh_info != 0)
4459
0
  {
4460
0
    isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
4461
0
    if (isymbuf == NULL)
4462
0
      isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
4463
0
              symtab_hdr->sh_info, 0,
4464
0
              NULL, NULL, NULL);
4465
0
    if (isymbuf == NULL)
4466
0
      goto error_return;
4467
0
  }
4468
4469
0
      amt = symtab_hdr->sh_info;
4470
0
      amt *= sizeof (asection *);
4471
0
      sections = bfd_malloc (amt);
4472
0
      if (sections == NULL && amt != 0)
4473
0
  goto error_return;
4474
4475
0
      isymend = isymbuf + symtab_hdr->sh_info;
4476
0
      for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp)
4477
0
  {
4478
0
    asection *isec;
4479
4480
0
    if (isym->st_shndx == SHN_UNDEF)
4481
0
      isec = bfd_und_section_ptr;
4482
0
    else if (isym->st_shndx == SHN_ABS)
4483
0
      isec = bfd_abs_section_ptr;
4484
0
    else if (isym->st_shndx == SHN_COMMON)
4485
0
      isec = bfd_com_section_ptr;
4486
0
    else
4487
0
      isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
4488
4489
0
    *secpp = isec;
4490
0
  }
4491
4492
0
      if (! mn10300_elf_relocate_section (link_info, input_bfd,
4493
0
            input_section, data, internal_relocs,
4494
0
            isymbuf, sections))
4495
0
  goto error_return;
4496
4497
0
      free (sections);
4498
0
      if (symtab_hdr->contents != (unsigned char *) isymbuf)
4499
0
  free (isymbuf);
4500
0
      if (internal_relocs != elf_section_data (input_section)->relocs)
4501
0
  free (internal_relocs);
4502
0
    }
4503
4504
0
  return data;
4505
4506
0
 error_return:
4507
0
  free (sections);
4508
0
  if (symtab_hdr->contents != (unsigned char *) isymbuf)
4509
0
    free (isymbuf);
4510
0
  if (internal_relocs != elf_section_data (input_section)->relocs)
4511
0
    free (internal_relocs);
4512
0
  if (orig_data == NULL)
4513
0
    free (data);
4514
0
  return NULL;
4515
0
}
Unexecuted instantiation: elf-m10300.c:mn10300_elf_get_relocated_section_contents
elf32-am33lin.c:mn10300_elf_get_relocated_section_contents
Line
Count
Source
4417
4
{
4418
4
  Elf_Internal_Shdr *symtab_hdr;
4419
4
  asection *input_section = link_order->u.indirect.section;
4420
4
  bfd *input_bfd = input_section->owner;
4421
4
  asection **sections = NULL;
4422
4
  Elf_Internal_Rela *internal_relocs = NULL;
4423
4
  Elf_Internal_Sym *isymbuf = NULL;
4424
4425
  /* We only need to handle the case of relaxing, or of having a
4426
     particular set of section contents, specially.  */
4427
4
  if (relocatable
4428
4
      || elf_section_data (input_section)->this_hdr.contents == NULL)
4429
4
    return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
4430
4
                   link_order, data,
4431
4
                   relocatable,
4432
4
                   symbols);
4433
4434
0
  symtab_hdr = &elf_symtab_hdr (input_bfd);
4435
4436
0
  bfd_byte *orig_data = data;
4437
0
  if (data == NULL)
4438
0
    {
4439
0
      data = bfd_malloc (input_section->size);
4440
0
      if (data == NULL)
4441
0
  return NULL;
4442
0
    }
4443
0
  memcpy (data, elf_section_data (input_section)->this_hdr.contents,
4444
0
    (size_t) input_section->size);
4445
4446
0
  if ((input_section->flags & SEC_RELOC) != 0
4447
0
      && input_section->reloc_count > 0)
4448
0
    {
4449
0
      asection **secpp;
4450
0
      Elf_Internal_Sym *isym, *isymend;
4451
0
      bfd_size_type amt;
4452
4453
0
      internal_relocs = _bfd_elf_link_read_relocs (input_bfd, input_section,
4454
0
               NULL, NULL, false);
4455
0
      if (internal_relocs == NULL)
4456
0
  goto error_return;
4457
4458
0
      if (symtab_hdr->sh_info != 0)
4459
0
  {
4460
0
    isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
4461
0
    if (isymbuf == NULL)
4462
0
      isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
4463
0
              symtab_hdr->sh_info, 0,
4464
0
              NULL, NULL, NULL);
4465
0
    if (isymbuf == NULL)
4466
0
      goto error_return;
4467
0
  }
4468
4469
0
      amt = symtab_hdr->sh_info;
4470
0
      amt *= sizeof (asection *);
4471
0
      sections = bfd_malloc (amt);
4472
0
      if (sections == NULL && amt != 0)
4473
0
  goto error_return;
4474
4475
0
      isymend = isymbuf + symtab_hdr->sh_info;
4476
0
      for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp)
4477
0
  {
4478
0
    asection *isec;
4479
4480
0
    if (isym->st_shndx == SHN_UNDEF)
4481
0
      isec = bfd_und_section_ptr;
4482
0
    else if (isym->st_shndx == SHN_ABS)
4483
0
      isec = bfd_abs_section_ptr;
4484
0
    else if (isym->st_shndx == SHN_COMMON)
4485
0
      isec = bfd_com_section_ptr;
4486
0
    else
4487
0
      isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
4488
4489
0
    *secpp = isec;
4490
0
  }
4491
4492
0
      if (! mn10300_elf_relocate_section (link_info, input_bfd,
4493
0
            input_section, data, internal_relocs,
4494
0
            isymbuf, sections))
4495
0
  goto error_return;
4496
4497
0
      free (sections);
4498
0
      if (symtab_hdr->contents != (unsigned char *) isymbuf)
4499
0
  free (isymbuf);
4500
0
      if (internal_relocs != elf_section_data (input_section)->relocs)
4501
0
  free (internal_relocs);
4502
0
    }
4503
4504
0
  return data;
4505
4506
0
 error_return:
4507
0
  free (sections);
4508
0
  if (symtab_hdr->contents != (unsigned char *) isymbuf)
4509
0
    free (isymbuf);
4510
0
  if (internal_relocs != elf_section_data (input_section)->relocs)
4511
0
    free (internal_relocs);
4512
0
  if (orig_data == NULL)
4513
0
    free (data);
4514
  return NULL;
4515
0
}
4516
4517
/* Assorted hash table functions.  */
4518
4519
/* Initialize an entry in the link hash table.  */
4520
4521
/* Create an entry in an MN10300 ELF linker hash table.  */
4522
4523
static struct bfd_hash_entry *
4524
elf32_mn10300_link_hash_newfunc (struct bfd_hash_entry *entry,
4525
         struct bfd_hash_table *table,
4526
         const char *string)
4527
0
{
4528
0
  struct elf32_mn10300_link_hash_entry *ret =
4529
0
    (struct elf32_mn10300_link_hash_entry *) entry;
4530
4531
  /* Allocate the structure if it has not already been allocated by a
4532
     subclass.  */
4533
0
  if (ret == NULL)
4534
0
    ret = (struct elf32_mn10300_link_hash_entry *)
4535
0
     bfd_hash_allocate (table, sizeof (* ret));
4536
0
  if (ret == NULL)
4537
0
    return (struct bfd_hash_entry *) ret;
4538
4539
  /* Call the allocation method of the superclass.  */
4540
0
  ret = (struct elf32_mn10300_link_hash_entry *)
4541
0
   _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
4542
0
             table, string);
4543
0
  if (ret != NULL)
4544
0
    {
4545
0
      ret->direct_calls = 0;
4546
0
      ret->stack_size = 0;
4547
0
      ret->movm_args = 0;
4548
0
      ret->movm_stack_size = 0;
4549
0
      ret->flags = 0;
4550
0
      ret->value = 0;
4551
0
      ret->tls_type = GOT_UNKNOWN;
4552
0
    }
4553
4554
0
  return (struct bfd_hash_entry *) ret;
4555
0
}
Unexecuted instantiation: elf-m10300.c:elf32_mn10300_link_hash_newfunc
Unexecuted instantiation: elf32-am33lin.c:elf32_mn10300_link_hash_newfunc
4556
4557
static void
4558
_bfd_mn10300_copy_indirect_symbol (struct bfd_link_info *  info,
4559
           struct elf_link_hash_entry *  dir,
4560
           struct elf_link_hash_entry *  ind)
4561
0
{
4562
0
  struct elf32_mn10300_link_hash_entry * edir;
4563
0
  struct elf32_mn10300_link_hash_entry * eind;
4564
4565
0
  edir = elf_mn10300_hash_entry (dir);
4566
0
  eind = elf_mn10300_hash_entry (ind);
4567
4568
0
  if (ind->root.type == bfd_link_hash_indirect
4569
0
      && dir->got.refcount <= 0)
4570
0
    {
4571
0
      edir->tls_type = eind->tls_type;
4572
0
      eind->tls_type = GOT_UNKNOWN;
4573
0
    }
4574
0
  edir->direct_calls = eind->direct_calls;
4575
0
  edir->stack_size = eind->stack_size;
4576
0
  edir->movm_args = eind->movm_args;
4577
0
  edir->movm_stack_size = eind->movm_stack_size;
4578
0
  edir->flags = eind->flags;
4579
4580
0
  _bfd_elf_link_hash_copy_indirect (info, dir, ind);
4581
0
}
Unexecuted instantiation: elf-m10300.c:_bfd_mn10300_copy_indirect_symbol
Unexecuted instantiation: elf32-am33lin.c:_bfd_mn10300_copy_indirect_symbol
4582
4583
/* Destroy an mn10300 ELF linker hash table.  */
4584
4585
static void
4586
elf32_mn10300_link_hash_table_free (bfd *obfd)
4587
0
{
4588
0
  struct elf32_mn10300_link_hash_table *ret
4589
0
    = (struct elf32_mn10300_link_hash_table *) obfd->link.hash;
4590
4591
0
  obfd->link.hash = &ret->static_hash_table->root.root;
4592
0
  _bfd_elf_link_hash_table_free (obfd);
4593
0
  obfd->is_linker_output = true;
4594
0
  obfd->link.hash = &ret->root.root;
4595
0
  _bfd_elf_link_hash_table_free (obfd);
4596
0
}
Unexecuted instantiation: elf-m10300.c:elf32_mn10300_link_hash_table_free
Unexecuted instantiation: elf32-am33lin.c:elf32_mn10300_link_hash_table_free
4597
4598
/* Create an mn10300 ELF linker hash table.  */
4599
4600
static struct bfd_link_hash_table *
4601
elf32_mn10300_link_hash_table_create (bfd *abfd)
4602
0
{
4603
0
  struct elf32_mn10300_link_hash_table *ret;
4604
0
  size_t amt = sizeof (* ret);
4605
4606
0
  ret = bfd_zmalloc (amt);
4607
0
  if (ret == NULL)
4608
0
    return NULL;
4609
4610
0
  amt = sizeof (struct elf_link_hash_table);
4611
0
  ret->static_hash_table = bfd_zmalloc (amt);
4612
0
  if (ret->static_hash_table == NULL)
4613
0
    {
4614
0
      free (ret);
4615
0
      return NULL;
4616
0
    }
4617
4618
0
  if (!_bfd_elf_link_hash_table_init (&ret->static_hash_table->root, abfd,
4619
0
              elf32_mn10300_link_hash_newfunc,
4620
0
              sizeof (struct elf32_mn10300_link_hash_entry)))
4621
0
    {
4622
0
      free (ret->static_hash_table);
4623
0
      free (ret);
4624
0
      return NULL;
4625
0
    }
4626
4627
0
  abfd->is_linker_output = false;
4628
0
  abfd->link.hash = NULL;
4629
0
  if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
4630
0
              elf32_mn10300_link_hash_newfunc,
4631
0
              sizeof (struct elf32_mn10300_link_hash_entry)))
4632
0
    {
4633
0
      abfd->is_linker_output = true;
4634
0
      abfd->link.hash = &ret->static_hash_table->root.root;
4635
0
      _bfd_elf_link_hash_table_free (abfd);
4636
0
      free (ret);
4637
0
      return NULL;
4638
0
    }
4639
0
  ret->root.root.hash_table_free = elf32_mn10300_link_hash_table_free;
4640
4641
0
  ret->tls_ldm_got.offset = -1;
4642
4643
0
  return & ret->root.root;
4644
0
}
Unexecuted instantiation: elf-m10300.c:elf32_mn10300_link_hash_table_create
Unexecuted instantiation: elf32-am33lin.c:elf32_mn10300_link_hash_table_create
4645
4646
static unsigned long
4647
elf_mn10300_mach (flagword flags)
4648
378
{
4649
378
  switch (flags & EF_MN10300_MACH)
4650
378
    {
4651
5
    case E_MN10300_MACH_MN10300:
4652
370
    default:
4653
370
      return bfd_mach_mn10300;
4654
4655
8
    case E_MN10300_MACH_AM33:
4656
8
      return bfd_mach_am33;
4657
4658
0
    case E_MN10300_MACH_AM33_2:
4659
0
      return bfd_mach_am33_2;
4660
378
    }
4661
378
}
elf-m10300.c:elf_mn10300_mach
Line
Count
Source
4648
170
{
4649
170
  switch (flags & EF_MN10300_MACH)
4650
170
    {
4651
2
    case E_MN10300_MACH_MN10300:
4652
167
    default:
4653
167
      return bfd_mach_mn10300;
4654
4655
3
    case E_MN10300_MACH_AM33:
4656
3
      return bfd_mach_am33;
4657
4658
0
    case E_MN10300_MACH_AM33_2:
4659
0
      return bfd_mach_am33_2;
4660
170
    }
4661
170
}
elf32-am33lin.c:elf_mn10300_mach
Line
Count
Source
4648
208
{
4649
208
  switch (flags & EF_MN10300_MACH)
4650
208
    {
4651
3
    case E_MN10300_MACH_MN10300:
4652
203
    default:
4653
203
      return bfd_mach_mn10300;
4654
4655
5
    case E_MN10300_MACH_AM33:
4656
5
      return bfd_mach_am33;
4657
4658
0
    case E_MN10300_MACH_AM33_2:
4659
0
      return bfd_mach_am33_2;
4660
208
    }
4661
208
}
4662
4663
/* The final processing done just before writing out a MN10300 ELF object
4664
   file.  This gets the MN10300 architecture right based on the machine
4665
   number.  */
4666
4667
static bool
4668
_bfd_mn10300_elf_final_write_processing (bfd *abfd)
4669
1
{
4670
1
  unsigned long val;
4671
4672
1
  switch (bfd_get_mach (abfd))
4673
1
    {
4674
0
    default:
4675
1
    case bfd_mach_mn10300:
4676
1
      val = E_MN10300_MACH_MN10300;
4677
1
      break;
4678
4679
0
    case bfd_mach_am33:
4680
0
      val = E_MN10300_MACH_AM33;
4681
0
      break;
4682
4683
0
    case bfd_mach_am33_2:
4684
0
      val = E_MN10300_MACH_AM33_2;
4685
0
      break;
4686
1
    }
4687
4688
1
  elf_elfheader (abfd)->e_flags &= ~ (EF_MN10300_MACH);
4689
1
  elf_elfheader (abfd)->e_flags |= val;
4690
1
  return _bfd_elf_final_write_processing (abfd);
4691
1
}
Unexecuted instantiation: elf-m10300.c:_bfd_mn10300_elf_final_write_processing
elf32-am33lin.c:_bfd_am33_elf_final_write_processing
Line
Count
Source
4669
1
{
4670
1
  unsigned long val;
4671
4672
1
  switch (bfd_get_mach (abfd))
4673
1
    {
4674
0
    default:
4675
1
    case bfd_mach_mn10300:
4676
1
      val = E_MN10300_MACH_MN10300;
4677
1
      break;
4678
4679
0
    case bfd_mach_am33:
4680
0
      val = E_MN10300_MACH_AM33;
4681
0
      break;
4682
4683
0
    case bfd_mach_am33_2:
4684
0
      val = E_MN10300_MACH_AM33_2;
4685
0
      break;
4686
1
    }
4687
4688
1
  elf_elfheader (abfd)->e_flags &= ~ (EF_MN10300_MACH);
4689
1
  elf_elfheader (abfd)->e_flags |= val;
4690
1
  return _bfd_elf_final_write_processing (abfd);
4691
1
}
4692
4693
static bool
4694
_bfd_mn10300_elf_object_p (bfd *abfd)
4695
378
{
4696
378
  bfd_default_set_arch_mach (abfd, bfd_arch_mn10300,
4697
378
           elf_mn10300_mach (elf_elfheader (abfd)->e_flags));
4698
378
  return true;
4699
378
}
elf-m10300.c:_bfd_mn10300_elf_object_p
Line
Count
Source
4695
170
{
4696
170
  bfd_default_set_arch_mach (abfd, bfd_arch_mn10300,
4697
170
           elf_mn10300_mach (elf_elfheader (abfd)->e_flags));
4698
  return true;
4699
170
}
elf32-am33lin.c:_bfd_am33_elf_object_p
Line
Count
Source
4695
208
{
4696
208
  bfd_default_set_arch_mach (abfd, bfd_arch_mn10300,
4697
208
           elf_mn10300_mach (elf_elfheader (abfd)->e_flags));
4698
  return true;
4699
208
}
4700
4701
/* Merge backend specific data from an object file to the output
4702
   object file when linking.  */
4703
4704
static bool
4705
_bfd_mn10300_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
4706
0
{
4707
0
  bfd *obfd = info->output_bfd;
4708
4709
0
  if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
4710
0
    return true;
4711
4712
0
  if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
4713
0
      && bfd_get_mach (obfd) < bfd_get_mach (ibfd))
4714
0
    {
4715
0
      if (! bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
4716
0
             bfd_get_mach (ibfd)))
4717
0
  return false;
4718
0
    }
4719
4720
0
  return true;
4721
0
}
Unexecuted instantiation: elf-m10300.c:_bfd_mn10300_elf_merge_private_bfd_data
Unexecuted instantiation: elf32-am33lin.c:_bfd_am33_elf_merge_private_bfd_data
4722
4723
0
#define PLT0_ENTRY_SIZE     15
4724
0
#define PLT_ENTRY_SIZE      20
4725
0
#define PIC_PLT_ENTRY_SIZE  24
4726
4727
static const bfd_byte elf_mn10300_plt0_entry[PLT0_ENTRY_SIZE] =
4728
{
4729
  0xfc, 0xa0, 0, 0, 0, 0, /* mov  (.got+8),a0 */
4730
  0xfe, 0xe, 0x10, 0, 0, 0, 0,  /* mov  (.got+4),r1 */
4731
  0xf0, 0xf4,     /* jmp  (a0) */
4732
};
4733
4734
static const bfd_byte elf_mn10300_plt_entry[PLT_ENTRY_SIZE] =
4735
{
4736
  0xfc, 0xa0, 0, 0, 0, 0, /* mov  (nameN@GOT + .got),a0 */
4737
  0xf0, 0xf4,     /* jmp  (a0) */
4738
  0xfe, 8, 0, 0, 0, 0, 0, /* mov  reloc-table-address,r0 */
4739
  0xdc, 0, 0, 0, 0,   /* jmp  .plt0 */
4740
};
4741
4742
static const bfd_byte elf_mn10300_pic_plt_entry[PIC_PLT_ENTRY_SIZE] =
4743
{
4744
  0xfc, 0x22, 0, 0, 0, 0, /* mov  (nameN@GOT,a2),a0 */
4745
  0xf0, 0xf4,     /* jmp  (a0) */
4746
  0xfe, 8, 0, 0, 0, 0, 0, /* mov  reloc-table-address,r0 */
4747
  0xf8, 0x22, 8,    /* mov  (8,a2),a0 */
4748
  0xfb, 0xa, 0x1a, 4,   /* mov  (4,a2),r1 */
4749
  0xf0, 0xf4,     /* jmp  (a0) */
4750
};
4751
4752
/* Return size of the first PLT entry.  */
4753
#define elf_mn10300_sizeof_plt0(info) \
4754
0
  (bfd_link_pic (info) ? PIC_PLT_ENTRY_SIZE : PLT0_ENTRY_SIZE)
4755
4756
/* Return size of a PLT entry.  */
4757
#define elf_mn10300_sizeof_plt(info) \
4758
0
  (bfd_link_pic (info) ? PIC_PLT_ENTRY_SIZE : PLT_ENTRY_SIZE)
4759
4760
/* Return offset of the PLT0 address in an absolute PLT entry.  */
4761
#define elf_mn10300_plt_plt0_offset(info) 16
4762
4763
/* Return offset of the linker in PLT0 entry.  */
4764
#define elf_mn10300_plt0_linker_offset(info) 2
4765
4766
/* Return offset of the GOT id in PLT0 entry.  */
4767
#define elf_mn10300_plt0_gotid_offset(info) 9
4768
4769
/* Return offset of the temporary in PLT entry.  */
4770
#define elf_mn10300_plt_temp_offset(info) 8
4771
4772
/* Return offset of the symbol in PLT entry.  */
4773
#define elf_mn10300_plt_symbol_offset(info) 2
4774
4775
/* Return offset of the relocation in PLT entry.  */
4776
#define elf_mn10300_plt_reloc_offset(info) 11
4777
4778
/* The name of the dynamic interpreter.  This is put in the .interp
4779
   section.  */
4780
4781
0
#define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
4782
4783
/* Create dynamic sections when linking against a dynamic object.  */
4784
4785
static bool
4786
_bfd_mn10300_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
4787
0
{
4788
0
  flagword   flags;
4789
0
  asection * s;
4790
0
  elf_backend_data *bed = get_elf_backend_data (abfd);
4791
0
  struct elf32_mn10300_link_hash_table *htab = elf32_mn10300_hash_table (info);
4792
0
  int ptralign = 0;
4793
4794
0
  switch (bed->s->arch_size)
4795
0
    {
4796
0
    case 32:
4797
0
      ptralign = 2;
4798
0
      break;
4799
4800
0
    case 64:
4801
0
      ptralign = 3;
4802
0
      break;
4803
4804
0
    default:
4805
0
      bfd_set_error (bfd_error_bad_value);
4806
0
      return false;
4807
0
    }
4808
4809
  /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
4810
     .rel[a].bss sections.  */
4811
0
  flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
4812
0
     | SEC_LINKER_CREATED);
4813
4814
0
  s = bfd_make_section_anyway_with_flags (abfd,
4815
0
            (bed->default_use_rela_p
4816
0
             ? ".rela.plt" : ".rel.plt"),
4817
0
            flags | SEC_READONLY);
4818
0
  htab->root.srelplt = s;
4819
0
  if (s == NULL
4820
0
      || !bfd_set_section_alignment (s, ptralign))
4821
0
    return false;
4822
4823
0
  if (! _bfd_mn10300_elf_create_got_section (abfd, info))
4824
0
    return false;
4825
4826
0
  if (bed->want_dynbss)
4827
0
    {
4828
      /* The .dynbss section is a place to put symbols which are defined
4829
   by dynamic objects, are referenced by regular objects, and are
4830
   not functions.  We must allocate space for them in the process
4831
   image and use a R_*_COPY reloc to tell the dynamic linker to
4832
   initialize them at run time.  The linker script puts the .dynbss
4833
   section into the .bss section of the final image.  */
4834
0
      s = bfd_make_section_anyway_with_flags (abfd, ".dynbss",
4835
0
                SEC_ALLOC | SEC_LINKER_CREATED);
4836
0
      if (s == NULL)
4837
0
  return false;
4838
4839
      /* The .rel[a].bss section holds copy relocs.  This section is not
4840
   normally needed.  We need to create it here, though, so that the
4841
   linker will map it to an output section.  We can't just create it
4842
   only if we need it, because we will not know whether we need it
4843
   until we have seen all the input files, and the first time the
4844
   main linker code calls BFD after examining all the input files
4845
   (size_dynamic_sections) the input sections have already been
4846
   mapped to the output sections.  If the section turns out not to
4847
   be needed, we can discard it later.  We will never need this
4848
   section when generating a shared object, since they do not use
4849
   copy relocs.  */
4850
0
      if (! bfd_link_pic (info))
4851
0
  {
4852
0
    s = bfd_make_section_anyway_with_flags (abfd,
4853
0
              (bed->default_use_rela_p
4854
0
               ? ".rela.bss" : ".rel.bss"),
4855
0
              flags | SEC_READONLY);
4856
0
    if (s == NULL
4857
0
        || !bfd_set_section_alignment (s, ptralign))
4858
0
      return false;
4859
0
  }
4860
0
    }
4861
4862
0
  return true;
4863
0
}
Unexecuted instantiation: elf-m10300.c:_bfd_mn10300_elf_create_dynamic_sections
Unexecuted instantiation: elf32-am33lin.c:_bfd_mn10300_elf_create_dynamic_sections
4864

4865
/* Adjust a symbol defined by a dynamic object and referenced by a
4866
   regular object.  The current definition is in some section of the
4867
   dynamic object, but we're not including those sections.  We have to
4868
   change the definition to something the rest of the link can
4869
   understand.  */
4870
4871
static bool
4872
_bfd_mn10300_elf_adjust_dynamic_symbol (struct bfd_link_info * info,
4873
          struct elf_link_hash_entry * h)
4874
0
{
4875
0
  struct elf32_mn10300_link_hash_table *htab = elf32_mn10300_hash_table (info);
4876
0
  bfd * dynobj;
4877
0
  asection * s;
4878
4879
0
  dynobj = htab->root.dynobj;
4880
4881
  /* Make sure we know what is going on here.  */
4882
0
  BFD_ASSERT (dynobj != NULL
4883
0
        && (h->needs_plt
4884
0
      || h->is_weakalias
4885
0
      || (h->def_dynamic
4886
0
          && h->ref_regular
4887
0
          && !h->def_regular)));
4888
4889
  /* If this is a function, put it in the procedure linkage table.  We
4890
     will fill in the contents of the procedure linkage table later,
4891
     when we know the address of the .got section.  */
4892
0
  if (h->type == STT_FUNC
4893
0
      || h->needs_plt)
4894
0
    {
4895
0
      if (! bfd_link_pic (info)
4896
0
    && !h->def_dynamic
4897
0
    && !h->ref_dynamic)
4898
0
  {
4899
    /* This case can occur if we saw a PLT reloc in an input
4900
       file, but the symbol was never referred to by a dynamic
4901
       object.  In such a case, we don't actually need to build
4902
       a procedure linkage table, and we can just do a REL32
4903
       reloc instead.  */
4904
0
    BFD_ASSERT (h->needs_plt);
4905
0
    return true;
4906
0
  }
4907
4908
      /* Make sure this symbol is output as a dynamic symbol.  */
4909
0
      if (h->dynindx == -1)
4910
0
  {
4911
0
    if (! bfd_elf_link_record_dynamic_symbol (info, h))
4912
0
      return false;
4913
0
  }
4914
4915
0
      s = htab->root.splt;
4916
0
      BFD_ASSERT (s != NULL);
4917
4918
      /* If this is the first .plt entry, make room for the special
4919
   first entry.  */
4920
0
      if (s->size == 0)
4921
0
  s->size += elf_mn10300_sizeof_plt0 (info);
4922
4923
      /* If this symbol is not defined in a regular file, and we are
4924
   not generating a shared library, then set the symbol to this
4925
   location in the .plt.  This is required to make function
4926
   pointers compare as equal between the normal executable and
4927
   the shared library.  */
4928
0
      if (! bfd_link_pic (info)
4929
0
    && !h->def_regular)
4930
0
  {
4931
0
    h->root.u.def.section = s;
4932
0
    h->root.u.def.value = s->size;
4933
0
  }
4934
4935
0
      h->plt.offset = s->size;
4936
4937
      /* Make room for this entry.  */
4938
0
      s->size += elf_mn10300_sizeof_plt (info);
4939
4940
      /* We also need to make an entry in the .got.plt section, which
4941
   will be placed in the .got section by the linker script.  */
4942
0
      s = htab->root.sgotplt;
4943
0
      BFD_ASSERT (s != NULL);
4944
0
      s->size += 4;
4945
4946
      /* We also need to make an entry in the .rela.plt section.  */
4947
0
      s = htab->root.srelplt;
4948
0
      BFD_ASSERT (s != NULL);
4949
0
      s->size += sizeof (Elf32_External_Rela);
4950
4951
0
      return true;
4952
0
    }
4953
4954
  /* If this is a weak symbol, and there is a real definition, the
4955
     processor independent code will have arranged for us to see the
4956
     real definition first, and we can just use the same value.  */
4957
0
  if (h->is_weakalias)
4958
0
    {
4959
0
      struct elf_link_hash_entry *def = weakdef (h);
4960
0
      BFD_ASSERT (def->root.type == bfd_link_hash_defined);
4961
0
      h->root.u.def.section = def->root.u.def.section;
4962
0
      h->root.u.def.value = def->root.u.def.value;
4963
0
      return true;
4964
0
    }
4965
4966
  /* This is a reference to a symbol defined by a dynamic object which
4967
     is not a function.  */
4968
4969
  /* If we are creating a shared library, we must presume that the
4970
     only references to the symbol are via the global offset table.
4971
     For such cases we need not do anything here; the relocations will
4972
     be handled correctly by relocate_section.  */
4973
0
  if (bfd_link_pic (info))
4974
0
    return true;
4975
4976
  /* If there are no references to this symbol that do not use the
4977
     GOT, we don't need to generate a copy reloc.  */
4978
0
  if (!h->non_got_ref)
4979
0
    return true;
4980
4981
  /* We must allocate the symbol in our .dynbss section, which will
4982
     become part of the .bss section of the executable.  There will be
4983
     an entry for this symbol in the .dynsym section.  The dynamic
4984
     object will contain position independent code, so all references
4985
     from the dynamic object to this symbol will go through the global
4986
     offset table.  The dynamic linker will use the .dynsym entry to
4987
     determine the address it must put in the global offset table, so
4988
     both the dynamic object and the regular object will refer to the
4989
     same memory location for the variable.  */
4990
4991
0
  s = bfd_get_linker_section (dynobj, ".dynbss");
4992
0
  BFD_ASSERT (s != NULL);
4993
4994
  /* We must generate a R_MN10300_COPY reloc to tell the dynamic linker to
4995
     copy the initial value out of the dynamic object and into the
4996
     runtime process image.  We need to remember the offset into the
4997
     .rela.bss section we are going to use.  */
4998
0
  if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
4999
0
    {
5000
0
      asection * srel;
5001
5002
0
      srel = bfd_get_linker_section (dynobj, ".rela.bss");
5003
0
      BFD_ASSERT (srel != NULL);
5004
0
      srel->size += sizeof (Elf32_External_Rela);
5005
0
      h->needs_copy = 1;
5006
0
    }
5007
5008
0
  return _bfd_elf_adjust_dynamic_copy (info, h, s);
5009
0
}
Unexecuted instantiation: elf-m10300.c:_bfd_mn10300_elf_adjust_dynamic_symbol
Unexecuted instantiation: elf32-am33lin.c:_bfd_mn10300_elf_adjust_dynamic_symbol
5010
5011
/* Set the sizes of the dynamic sections.  */
5012
5013
static bool
5014
_bfd_mn10300_elf_late_size_sections (struct bfd_link_info *info)
5015
0
{
5016
0
  struct elf32_mn10300_link_hash_table *htab = elf32_mn10300_hash_table (info);
5017
0
  bfd * dynobj;
5018
0
  asection * s;
5019
0
  bool relocs;
5020
5021
0
  dynobj = htab->root.dynobj;
5022
0
  if (dynobj == NULL)
5023
0
    return true;
5024
5025
0
  if (elf_hash_table (info)->dynamic_sections_created)
5026
0
    {
5027
      /* Set the contents of the .interp section to the interpreter.  */
5028
0
      if (bfd_link_executable (info) && !info->nointerp)
5029
0
  {
5030
0
    s = elf_hash_table (info)->interp;
5031
0
    BFD_ASSERT (s != NULL);
5032
0
    s->size = sizeof ELF_DYNAMIC_INTERPRETER;
5033
0
    s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
5034
0
    s->alloced = 1;
5035
0
  }
5036
0
    }
5037
0
  else
5038
0
    {
5039
      /* We may have created entries in the .rela.got section.
5040
   However, if we are not creating the dynamic sections, we will
5041
   not actually use these entries.  Reset the size of .rela.got,
5042
   which will cause it to get stripped from the output file
5043
   below.  */
5044
0
      s = htab->root.sgot;
5045
0
      if (s != NULL)
5046
0
  s->size = 0;
5047
0
    }
5048
5049
0
  if (htab->tls_ldm_got.refcount > 0)
5050
0
    {
5051
0
      s = htab->root.srelgot;
5052
0
      BFD_ASSERT (s != NULL);
5053
0
      s->size += sizeof (Elf32_External_Rela);
5054
0
    }
5055
5056
  /* The check_relocs and adjust_dynamic_symbol entry points have
5057
     determined the sizes of the various dynamic sections.  Allocate
5058
     memory for them.  */
5059
0
  relocs = false;
5060
0
  for (s = dynobj->sections; s != NULL; s = s->next)
5061
0
    {
5062
0
      const char * name;
5063
5064
0
      if ((s->flags & SEC_LINKER_CREATED) == 0)
5065
0
  continue;
5066
5067
      /* It's OK to base decisions on the section name, because none
5068
   of the dynobj section names depend upon the input files.  */
5069
0
      name = bfd_section_name (s);
5070
5071
0
      if (streq (name, ".plt"))
5072
0
  {
5073
    /* Remember whether there is a PLT.  */
5074
0
    ;
5075
0
  }
5076
0
      else if (startswith (name, ".rela"))
5077
0
  {
5078
0
    if (s->size != 0)
5079
0
      {
5080
        /* Remember whether there are any reloc sections other
5081
     than .rela.plt.  */
5082
0
        if (! streq (name, ".rela.plt"))
5083
0
    relocs = true;
5084
5085
        /* We use the reloc_count field as a counter if we need
5086
     to copy relocs into the output file.  */
5087
0
        s->reloc_count = 0;
5088
0
      }
5089
0
  }
5090
0
      else if (! startswith (name, ".got")
5091
0
         && ! streq (name, ".dynbss"))
5092
  /* It's not one of our sections, so don't allocate space.  */
5093
0
  continue;
5094
5095
0
      if (s->size == 0)
5096
0
  {
5097
    /* If we don't need this section, strip it from the
5098
       output file.  This is mostly to handle .rela.bss and
5099
       .rela.plt.  We must create both sections in
5100
       create_dynamic_sections, because they must be created
5101
       before the linker maps input sections to output
5102
       sections.  The linker does that before
5103
       adjust_dynamic_symbol is called, and it is that
5104
       function which decides whether anything needs to go
5105
       into these sections.  */
5106
0
    s->flags |= SEC_EXCLUDE;
5107
0
    continue;
5108
0
  }
5109
5110
0
  if ((s->flags & SEC_HAS_CONTENTS) == 0)
5111
0
    continue;
5112
5113
      /* Allocate memory for the section contents.  We use bfd_zalloc
5114
   here in case unused entries are not reclaimed before the
5115
   section's contents are written out.  This should not happen,
5116
   but this way if it does, we get a R_MN10300_NONE reloc
5117
   instead of garbage.  */
5118
0
      s->contents = bfd_zalloc (dynobj, s->size);
5119
0
      if (s->contents == NULL)
5120
0
  return false;
5121
0
      s->alloced = 1;
5122
0
    }
5123
5124
0
  return _bfd_elf_add_dynamic_tags (info, relocs);
5125
0
}
Unexecuted instantiation: elf-m10300.c:_bfd_mn10300_elf_late_size_sections
Unexecuted instantiation: elf32-am33lin.c:_bfd_mn10300_elf_late_size_sections
5126
5127
/* Finish up dynamic symbol handling.  We set the contents of various
5128
   dynamic sections here.  */
5129
5130
static bool
5131
_bfd_mn10300_elf_finish_dynamic_symbol (struct bfd_link_info * info,
5132
          struct elf_link_hash_entry * h,
5133
          Elf_Internal_Sym * sym)
5134
0
{
5135
0
  struct elf32_mn10300_link_hash_table *htab = elf32_mn10300_hash_table (info);
5136
0
  bfd * dynobj;
5137
5138
0
  dynobj = htab->root.dynobj;
5139
5140
0
  if (h->plt.offset != (bfd_vma) -1)
5141
0
    {
5142
0
      asection *  splt;
5143
0
      asection *  sgot;
5144
0
      asection *  srel;
5145
0
      bfd_vma   plt_index;
5146
0
      bfd_vma   got_offset;
5147
0
      Elf_Internal_Rela rel;
5148
5149
      /* This symbol has an entry in the procedure linkage table.  Set
5150
   it up.  */
5151
5152
0
      BFD_ASSERT (h->dynindx != -1);
5153
5154
0
      splt = htab->root.splt;
5155
0
      sgot = htab->root.sgotplt;
5156
0
      srel = htab->root.srelplt;
5157
0
      BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
5158
5159
      /* Get the index in the procedure linkage table which
5160
   corresponds to this symbol.  This is the index of this symbol
5161
   in all the symbols for which we are making plt entries.  The
5162
   first entry in the procedure linkage table is reserved.  */
5163
0
      plt_index = ((h->plt.offset - elf_mn10300_sizeof_plt0 (info))
5164
0
       / elf_mn10300_sizeof_plt (info));
5165
5166
      /* Get the offset into the .got table of the entry that
5167
   corresponds to this function.  Each .got entry is 4 bytes.
5168
   The first three are reserved.  */
5169
0
      got_offset = (plt_index + 3) * 4;
5170
5171
      /* Fill in the entry in the procedure linkage table.  */
5172
0
      if (! bfd_link_pic (info))
5173
0
  {
5174
0
    memcpy (splt->contents + h->plt.offset, elf_mn10300_plt_entry,
5175
0
      elf_mn10300_sizeof_plt (info));
5176
0
    bfd_put_32 (info->output_bfd,
5177
0
          (sgot->output_section->vma
5178
0
           + sgot->output_offset
5179
0
           + got_offset),
5180
0
          (splt->contents + h->plt.offset
5181
0
           + elf_mn10300_plt_symbol_offset (info)));
5182
5183
0
    bfd_put_32 (info->output_bfd,
5184
0
          (1 - h->plt.offset - elf_mn10300_plt_plt0_offset (info)),
5185
0
          (splt->contents + h->plt.offset
5186
0
           + elf_mn10300_plt_plt0_offset (info)));
5187
0
  }
5188
0
      else
5189
0
  {
5190
0
    memcpy (splt->contents + h->plt.offset, elf_mn10300_pic_plt_entry,
5191
0
      elf_mn10300_sizeof_plt (info));
5192
5193
0
    bfd_put_32 (info->output_bfd, got_offset,
5194
0
          (splt->contents + h->plt.offset
5195
0
           + elf_mn10300_plt_symbol_offset (info)));
5196
0
  }
5197
5198
0
      bfd_put_32 (info->output_bfd, plt_index * sizeof (Elf32_External_Rela),
5199
0
      (splt->contents + h->plt.offset
5200
0
       + elf_mn10300_plt_reloc_offset (info)));
5201
5202
      /* Fill in the entry in the global offset table.  */
5203
0
      bfd_put_32 (info->output_bfd,
5204
0
      (splt->output_section->vma
5205
0
       + splt->output_offset
5206
0
       + h->plt.offset
5207
0
       + elf_mn10300_plt_temp_offset (info)),
5208
0
      sgot->contents + got_offset);
5209
5210
      /* Fill in the entry in the .rela.plt section.  */
5211
0
      rel.r_offset = (sgot->output_section->vma
5212
0
          + sgot->output_offset
5213
0
          + got_offset);
5214
0
      rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_JMP_SLOT);
5215
0
      rel.r_addend = 0;
5216
0
      bfd_elf32_swap_reloca_out (info->output_bfd, &rel,
5217
0
         (bfd_byte *) ((Elf32_External_Rela *) srel->contents
5218
0
                 + plt_index));
5219
5220
0
      if (!h->def_regular)
5221
  /* Mark the symbol as undefined, rather than as defined in
5222
     the .plt section.  Leave the value alone.  */
5223
0
  sym->st_shndx = SHN_UNDEF;
5224
0
    }
5225
5226
0
  if (h->got.offset != (bfd_vma) -1)
5227
0
    {
5228
0
      asection *  sgot;
5229
0
      asection *  srel;
5230
0
      Elf_Internal_Rela rel;
5231
5232
      /* This symbol has an entry in the global offset table.  Set it up.  */
5233
0
      sgot = htab->root.sgot;
5234
0
      srel = htab->root.srelgot;
5235
0
      BFD_ASSERT (sgot != NULL && srel != NULL);
5236
5237
0
      rel.r_offset = (sgot->output_section->vma
5238
0
          + sgot->output_offset
5239
0
          + (h->got.offset & ~1));
5240
5241
0
      switch (elf_mn10300_hash_entry (h)->tls_type)
5242
0
  {
5243
0
  case GOT_TLS_GD:
5244
0
    bfd_put_32 (info->output_bfd, 0, sgot->contents + h->got.offset);
5245
0
    bfd_put_32 (info->output_bfd, 0, sgot->contents + h->got.offset + 4);
5246
0
    rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_TLS_DTPMOD);
5247
0
    rel.r_addend = 0;
5248
0
    bfd_elf32_swap_reloca_out (info->output_bfd, & rel,
5249
0
             (bfd_byte *) ((Elf32_External_Rela *) srel->contents
5250
0
               + srel->reloc_count));
5251
0
    ++ srel->reloc_count;
5252
0
    rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_TLS_DTPOFF);
5253
0
    rel.r_offset += 4;
5254
0
    rel.r_addend = 0;
5255
0
    break;
5256
5257
0
  case GOT_TLS_IE:
5258
    /* We originally stored the addend in the GOT, but at this
5259
       point, we want to move it to the reloc instead as that's
5260
       where the dynamic linker wants it.  */
5261
0
    rel.r_addend = bfd_get_32 (info->output_bfd,
5262
0
             sgot->contents + h->got.offset);
5263
0
    bfd_put_32 (info->output_bfd, 0, sgot->contents + h->got.offset);
5264
0
    if (h->dynindx == -1)
5265
0
      rel.r_info = ELF32_R_INFO (0, R_MN10300_TLS_TPOFF);
5266
0
    else
5267
0
      rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_TLS_TPOFF);
5268
0
    break;
5269
5270
0
  default:
5271
    /* If this is a -Bsymbolic link, and the symbol is defined
5272
       locally, we just want to emit a RELATIVE reloc.  Likewise if
5273
       the symbol was forced to be local because of a version file.
5274
       The entry in the global offset table will already have been
5275
       initialized in the relocate_section function.  */
5276
0
    if (bfd_link_pic (info)
5277
0
        && (info->symbolic || h->dynindx == -1)
5278
0
        && h->def_regular)
5279
0
      {
5280
0
        rel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE);
5281
0
        rel.r_addend = (h->root.u.def.value
5282
0
            + h->root.u.def.section->output_section->vma
5283
0
            + h->root.u.def.section->output_offset);
5284
0
      }
5285
0
    else
5286
0
      {
5287
0
        bfd_put_32 (info->output_bfd, 0, sgot->contents + h->got.offset);
5288
0
        rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_GLOB_DAT);
5289
0
        rel.r_addend = 0;
5290
0
      }
5291
0
  }
5292
5293
0
      if (ELF32_R_TYPE (rel.r_info) != R_MN10300_NONE)
5294
0
  {
5295
0
    bfd_elf32_swap_reloca_out (info->output_bfd, &rel,
5296
0
             (bfd_byte *) ((Elf32_External_Rela *) srel->contents
5297
0
               + srel->reloc_count));
5298
0
    ++ srel->reloc_count;
5299
0
  }
5300
0
    }
5301
5302
0
  if (h->needs_copy)
5303
0
    {
5304
0
      asection *  s;
5305
0
      Elf_Internal_Rela rel;
5306
5307
      /* This symbol needs a copy reloc.  Set it up.  */
5308
0
      BFD_ASSERT (h->dynindx != -1
5309
0
      && (h->root.type == bfd_link_hash_defined
5310
0
          || h->root.type == bfd_link_hash_defweak));
5311
5312
0
      s = bfd_get_linker_section (dynobj, ".rela.bss");
5313
0
      BFD_ASSERT (s != NULL);
5314
5315
0
      rel.r_offset = (h->root.u.def.value
5316
0
          + h->root.u.def.section->output_section->vma
5317
0
          + h->root.u.def.section->output_offset);
5318
0
      rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_COPY);
5319
0
      rel.r_addend = 0;
5320
0
      bfd_elf32_swap_reloca_out (info->output_bfd, & rel,
5321
0
         (bfd_byte *) ((Elf32_External_Rela *) s->contents
5322
0
                 + s->reloc_count));
5323
0
      ++ s->reloc_count;
5324
0
    }
5325
5326
  /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.  */
5327
0
  if (h == elf_hash_table (info)->hdynamic
5328
0
      || h == elf_hash_table (info)->hgot)
5329
0
    sym->st_shndx = SHN_ABS;
5330
5331
0
  return true;
5332
0
}
Unexecuted instantiation: elf-m10300.c:_bfd_mn10300_elf_finish_dynamic_symbol
Unexecuted instantiation: elf32-am33lin.c:_bfd_mn10300_elf_finish_dynamic_symbol
5333
5334
/* Finish up the dynamic sections.  */
5335
5336
static bool
5337
_bfd_mn10300_elf_finish_dynamic_sections (struct bfd_link_info *info,
5338
            bfd_byte *buf ATTRIBUTE_UNUSED)
5339
0
{
5340
0
  bfd *      dynobj;
5341
0
  asection * sgot;
5342
0
  asection * sdyn;
5343
0
  struct elf32_mn10300_link_hash_table *htab = elf32_mn10300_hash_table (info);
5344
5345
0
  dynobj = htab->root.dynobj;
5346
0
  sgot = htab->root.sgotplt;
5347
0
  sdyn = bfd_get_linker_section (dynobj, ".dynamic");
5348
5349
0
  if (htab->root.dynamic_sections_created)
5350
0
    {
5351
0
      asection *     splt;
5352
0
      Elf32_External_Dyn * dyncon;
5353
0
      Elf32_External_Dyn * dynconend;
5354
5355
0
      BFD_ASSERT (sdyn != NULL && sgot != NULL);
5356
5357
0
      dyncon = (Elf32_External_Dyn *) sdyn->contents;
5358
0
      dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
5359
5360
0
      for (; dyncon < dynconend; dyncon++)
5361
0
  {
5362
0
    Elf_Internal_Dyn dyn;
5363
0
    asection * s;
5364
5365
0
    bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
5366
5367
0
    switch (dyn.d_tag)
5368
0
      {
5369
0
      default:
5370
0
        break;
5371
5372
0
      case DT_PLTGOT:
5373
0
        s = htab->root.sgot;
5374
0
        goto get_vma;
5375
5376
0
      case DT_JMPREL:
5377
0
        s = htab->root.srelplt;
5378
0
      get_vma:
5379
0
        dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
5380
0
        bfd_elf32_swap_dyn_out (info->output_bfd, &dyn, dyncon);
5381
0
        break;
5382
5383
0
      case DT_PLTRELSZ:
5384
0
        s = htab->root.srelplt;
5385
0
        dyn.d_un.d_val = s->size;
5386
0
        bfd_elf32_swap_dyn_out (info->output_bfd, &dyn, dyncon);
5387
0
        break;
5388
0
      }
5389
0
  }
5390
5391
      /* Fill in the first entry in the procedure linkage table.  */
5392
0
      splt = htab->root.splt;
5393
0
      if (splt && splt->size > 0)
5394
0
  {
5395
0
    if (bfd_link_pic (info))
5396
0
      {
5397
0
        memcpy (splt->contents, elf_mn10300_pic_plt_entry,
5398
0
          elf_mn10300_sizeof_plt (info));
5399
0
      }
5400
0
    else
5401
0
      {
5402
0
        memcpy (splt->contents, elf_mn10300_plt0_entry, PLT0_ENTRY_SIZE);
5403
0
        bfd_put_32 (info->output_bfd,
5404
0
        sgot->output_section->vma + sgot->output_offset + 4,
5405
0
        splt->contents + elf_mn10300_plt0_gotid_offset (info));
5406
0
        bfd_put_32 (info->output_bfd,
5407
0
        sgot->output_section->vma + sgot->output_offset + 8,
5408
0
        splt->contents + elf_mn10300_plt0_linker_offset (info));
5409
0
      }
5410
5411
    /* UnixWare sets the entsize of .plt to 4, although that doesn't
5412
       really seem like the right value.  */
5413
0
    elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
5414
5415
    /* UnixWare sets the entsize of .plt to 4, but this is incorrect
5416
       as it means that the size of the PLT0 section (15 bytes) is not
5417
       a multiple of the sh_entsize.  Some ELF tools flag this as an
5418
       error.  We could pad PLT0 to 16 bytes, but that would introduce
5419
       compatibilty issues with previous toolchains, so instead we
5420
       just set the entry size to 1.  */
5421
0
    elf_section_data (splt->output_section)->this_hdr.sh_entsize = 1;
5422
0
  }
5423
0
    }
5424
5425
  /* Fill in the first three entries in the global offset table.  */
5426
0
  if (sgot != NULL && sgot->size > 0)
5427
0
    {
5428
0
      if (sdyn == NULL)
5429
0
  bfd_put_32 (info->output_bfd, 0, sgot->contents);
5430
0
      else
5431
0
  bfd_put_32 (info->output_bfd,
5432
0
        sdyn->output_section->vma + sdyn->output_offset,
5433
0
        sgot->contents);
5434
0
      bfd_put_32 (info->output_bfd, 0, sgot->contents + 4);
5435
0
      bfd_put_32 (info->output_bfd, 0, sgot->contents + 8);
5436
5437
0
      elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
5438
0
    }
5439
5440
0
  return true;
5441
0
}
Unexecuted instantiation: elf-m10300.c:_bfd_mn10300_elf_finish_dynamic_sections
Unexecuted instantiation: elf32-am33lin.c:_bfd_mn10300_elf_finish_dynamic_sections
5442
5443
/* Classify relocation types, such that combreloc can sort them
5444
   properly.  */
5445
5446
static enum elf_reloc_type_class
5447
_bfd_mn10300_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
5448
           const asection *rel_sec ATTRIBUTE_UNUSED,
5449
           const Elf_Internal_Rela *rela)
5450
0
{
5451
0
  switch ((int) ELF32_R_TYPE (rela->r_info))
5452
0
    {
5453
0
    case R_MN10300_RELATIVE:  return reloc_class_relative;
5454
0
    case R_MN10300_JMP_SLOT:  return reloc_class_plt;
5455
0
    case R_MN10300_COPY:  return reloc_class_copy;
5456
0
    default:      return reloc_class_normal;
5457
0
    }
5458
0
}
Unexecuted instantiation: elf-m10300.c:_bfd_mn10300_elf_reloc_type_class
Unexecuted instantiation: elf32-am33lin.c:_bfd_mn10300_elf_reloc_type_class
5459
5460
/* Allocate space for an MN10300 extension to the bfd elf data structure.  */
5461
5462
static bool
5463
mn10300_elf_mkobject (bfd *abfd)
5464
47.0k
{
5465
47.0k
  return bfd_elf_allocate_object (abfd, sizeof (struct elf_mn10300_obj_tdata));
5466
47.0k
}
elf-m10300.c:mn10300_elf_mkobject
Line
Count
Source
5464
23.5k
{
5465
23.5k
  return bfd_elf_allocate_object (abfd, sizeof (struct elf_mn10300_obj_tdata));
5466
23.5k
}
elf32-am33lin.c:mn10300_elf_mkobject
Line
Count
Source
5464
23.5k
{
5465
23.5k
  return bfd_elf_allocate_object (abfd, sizeof (struct elf_mn10300_obj_tdata));
5466
23.5k
}
5467
5468
#define bfd_elf32_mkobject  mn10300_elf_mkobject
5469
5470
#ifndef ELF_ARCH
5471
#define TARGET_LITTLE_SYM mn10300_elf32_vec
5472
#define TARGET_LITTLE_NAME  "elf32-mn10300"
5473
#define ELF_ARCH    bfd_arch_mn10300
5474
#define ELF_TARGET_ID   MN10300_ELF_DATA
5475
#define ELF_MACHINE_CODE  EM_MN10300
5476
#define ELF_MACHINE_ALT1  EM_CYGNUS_MN10300
5477
#define ELF_MAXPAGESIZE   0x1000
5478
#endif
5479
5480
#define elf_info_to_howto   mn10300_info_to_howto
5481
#define elf_info_to_howto_rel   NULL
5482
#define elf_backend_can_gc_sections 1
5483
#define elf_backend_rela_normal   1
5484
#define elf_backend_check_relocs  mn10300_elf_check_relocs
5485
#define elf_backend_gc_mark_hook  mn10300_elf_gc_mark_hook
5486
#define elf_backend_relocate_section  mn10300_elf_relocate_section
5487
#define bfd_elf32_bfd_relax_section mn10300_elf_relax_section
5488
#define bfd_elf32_bfd_get_relocated_section_contents \
5489
        mn10300_elf_get_relocated_section_contents
5490
#define bfd_elf32_bfd_link_hash_table_create \
5491
        elf32_mn10300_link_hash_table_create
5492
5493
#ifndef elf_symbol_leading_char
5494
#define elf_symbol_leading_char '_'
5495
#endif
5496
5497
/* So we can set bits in e_flags.  */
5498
#define elf_backend_final_write_processing \
5499
          _bfd_mn10300_elf_final_write_processing
5500
#define elf_backend_object_p    _bfd_mn10300_elf_object_p
5501
5502
#define bfd_elf32_bfd_merge_private_bfd_data \
5503
          _bfd_mn10300_elf_merge_private_bfd_data
5504
5505
#define elf_backend_can_gc_sections 1
5506
#define elf_backend_create_dynamic_sections \
5507
  _bfd_mn10300_elf_create_dynamic_sections
5508
#define elf_backend_adjust_dynamic_symbol \
5509
  _bfd_mn10300_elf_adjust_dynamic_symbol
5510
#define elf_backend_late_size_sections \
5511
  _bfd_mn10300_elf_late_size_sections
5512
#define elf_backend_omit_section_dynsym _bfd_elf_omit_section_dynsym_all
5513
#define elf_backend_finish_dynamic_symbol \
5514
  _bfd_mn10300_elf_finish_dynamic_symbol
5515
#define elf_backend_finish_dynamic_sections \
5516
  _bfd_mn10300_elf_finish_dynamic_sections
5517
#define elf_backend_copy_indirect_symbol \
5518
  _bfd_mn10300_copy_indirect_symbol
5519
#define elf_backend_reloc_type_class \
5520
  _bfd_mn10300_elf_reloc_type_class
5521
5522
#define elf_backend_want_got_plt  1
5523
#define elf_backend_plt_readonly  1
5524
#define elf_backend_want_plt_sym  0
5525
#define elf_backend_got_header_size 12
5526
#define elf_backend_dtrel_excludes_plt  1
5527
5528
#include "elf32-target.h"