OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gdb-7.2/] [bfd/] [elf64-sh64.c] - Blame information for rev 841

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 330 jeremybenn
/* SuperH SH64-specific support for 64-bit ELF
2
   Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
3
   2010  Free Software Foundation, Inc.
4
 
5
   This file is part of BFD, the Binary File Descriptor library.
6
 
7
   This program is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 3 of the License, or
10
   (at your option) any later version.
11
 
12
   This program is distributed in the hope that it will be useful,
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
   GNU General Public License for more details.
16
 
17
   You should have received a copy of the GNU General Public License
18
   along with this program; if not, write to the Free Software
19
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20
   MA 02110-1301, USA.  */
21
 
22
#define SH64_ELF64
23
 
24
#include "sysdep.h"
25
#include "bfd.h"
26
#include "bfdlink.h"
27
#include "libbfd.h"
28
#include "elf-bfd.h"
29
#include "elf/sh.h"
30
 
31
/* Add a suffix for datalabel indirection symbols.  It must not match any
32
   other symbols; user symbols with or without version or other
33
   decoration.  It must only be used internally and not emitted by any
34
   means.  */
35
#define DATALABEL_SUFFIX " DL"
36
 
37
#define GOT_BIAS (-((long)-32768))
38
 
39
#define PLT_ENTRY_SIZE 64
40
 
41
/* Return size of a PLT entry.  */
42
#define elf_sh64_sizeof_plt(info) PLT_ENTRY_SIZE
43
 
44
/* Return offset of the PLT0 address in an absolute PLT entry.  */
45
#define elf_sh64_plt_plt0_offset(info) 32
46
 
47
/* Return offset of the linker in PLT0 entry.  */
48
#define elf_sh64_plt0_gotplt_offset(info) 0
49
 
50
/* Return offset of the trampoline in PLT entry */
51
#define elf_sh64_plt_temp_offset(info) 33 /* Add one because it's SHmedia.  */
52
 
53
/* Return offset of the symbol in PLT entry.  */
54
#define elf_sh64_plt_symbol_offset(info) 0
55
 
56
/* Return offset of the relocation in PLT entry.  */
57
#define elf_sh64_plt_reloc_offset(info) (info->shared ? 52 : 44)
58
 
59
#define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
60
 
61
/* The sh linker needs to keep track of the number of relocs that it
62
   decides to copy in check_relocs for each symbol.  This is so that
63
   it can discard PC relative relocs if it doesn't need them when
64
   linking with -Bsymbolic.  We store the information in a field
65
   extending the regular ELF linker hash table.  */
66
 
67
/* This structure keeps track of the number of PC relative relocs we
68
   have copied for a given symbol.  */
69
 
70
struct elf_sh64_pcrel_relocs_copied
71
{
72
  /* Next section.  */
73
  struct elf_sh64_pcrel_relocs_copied *next;
74
  /* A section in dynobj.  */
75
  asection *section;
76
  /* Number of relocs copied in this section.  */
77
  bfd_size_type count;
78
};
79
 
80
/* sh ELF linker hash entry.  */
81
 
82
struct elf_sh64_link_hash_entry
83
{
84
  struct elf_link_hash_entry root;
85
 
86
  bfd_vma datalabel_got_offset;
87
 
88
  /* Number of PC relative relocs copied for this symbol.  */
89
  struct elf_sh64_pcrel_relocs_copied *pcrel_relocs_copied;
90
};
91
 
92
/* Traverse an sh ELF linker hash table.  */
93
 
94
#define sh64_elf64_link_hash_traverse(table, func, info)        \
95
  (elf_link_hash_traverse                                       \
96
   ((table),                                                    \
97
    (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
98
    (info)))
99
 
100
static bfd_reloc_status_type sh_elf64_ignore_reloc
101
  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
102
static bfd_reloc_status_type sh_elf64_reloc
103
  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
104
 
105
static reloc_howto_type sh_elf64_howto_table[] = {
106
  /* No relocation.  */
107
  HOWTO (R_SH_NONE,             /* type */
108
         0,                      /* rightshift */
109
         0,                      /* size (0 = byte, 1 = short, 2 = long) */
110
         0,                      /* bitsize */
111
         FALSE,                 /* pc_relative */
112
         0,                      /* bitpos */
113
         complain_overflow_dont, /* complain_on_overflow */
114
         sh_elf64_ignore_reloc, /* special_function */
115
         "R_SH_NONE",           /* name */
116
         FALSE,                 /* partial_inplace */
117
         0,                      /* src_mask */
118
         0,                      /* dst_mask */
119
         FALSE),                /* pcrel_offset */
120
 
121
  /* 32 bit absolute relocation.  Setting partial_inplace to TRUE and
122
     src_mask to a non-zero value is similar to the COFF toolchain.  */
123
  HOWTO (R_SH_DIR32,            /* type */
124
         0,                      /* rightshift */
125
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
126
         32,                    /* bitsize */
127
         FALSE,                 /* pc_relative */
128
         0,                      /* bitpos */
129
         complain_overflow_bitfield, /* complain_on_overflow */
130
         sh_elf64_reloc,                /* special_function */
131
         "R_SH_DIR32",          /* name */
132
         TRUE,                  /* partial_inplace */
133
         0xffffffff,            /* src_mask */
134
         0xffffffff,            /* dst_mask */
135
         FALSE),                /* pcrel_offset */
136
 
137
  /* 32 bit PC relative relocation.  */
138
  HOWTO (R_SH_REL32,            /* type */
139
         0,                      /* rightshift */
140
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
141
         32,                    /* bitsize */
142
         TRUE,                  /* pc_relative */
143
         0,                      /* bitpos */
144
         complain_overflow_signed, /* complain_on_overflow */
145
         sh_elf64_ignore_reloc, /* special_function */
146
         "R_SH_REL32",          /* name */
147
         FALSE,                 /* partial_inplace */
148
         0,                      /* src_mask */
149
         0xffffffff,            /* dst_mask */
150
         TRUE),                 /* pcrel_offset */
151
 
152
  /* For 32-bit sh, this is R_SH_DIR8WPN.  */
153
  EMPTY_HOWTO (3),
154
 
155
  /* For 32-bit sh, this is R_SH_IND12W.  */
156
  EMPTY_HOWTO (4),
157
 
158
  /* For 32-bit sh, this is R_SH_DIR8WPL.  */
159
  EMPTY_HOWTO (5),
160
 
161
  /* For 32-bit sh, this is R_SH_DIR8WPZ.  */
162
  EMPTY_HOWTO (6),
163
 
164
  /* For 32-bit sh, this is R_SH_DIR8BP.  */
165
  EMPTY_HOWTO (7),
166
 
167
  /* For 32-bit sh, this is R_SH_DIR8W.  */
168
  EMPTY_HOWTO (8),
169
 
170
  /* For 32-bit sh, this is R_SH_DIR8L.  */
171
  EMPTY_HOWTO (9),
172
 
173
  EMPTY_HOWTO (10),
174
  EMPTY_HOWTO (11),
175
  EMPTY_HOWTO (12),
176
  EMPTY_HOWTO (13),
177
  EMPTY_HOWTO (14),
178
  EMPTY_HOWTO (15),
179
  EMPTY_HOWTO (16),
180
  EMPTY_HOWTO (17),
181
  EMPTY_HOWTO (18),
182
  EMPTY_HOWTO (19),
183
  EMPTY_HOWTO (20),
184
  EMPTY_HOWTO (21),
185
  EMPTY_HOWTO (22),
186
  EMPTY_HOWTO (23),
187
  EMPTY_HOWTO (24),
188
 
189
  /* The remaining relocs are a GNU extension used for relaxing.  The
190
     final pass of the linker never needs to do anything with any of
191
     these relocs.  Any required operations are handled by the
192
     relaxation code.  */
193
 
194
  /* A 16 bit switch table entry.  This is generated for an expression
195
     such as ``.word L1 - L2''.  The offset holds the difference
196
     between the reloc address and L2.  */
197
  HOWTO (R_SH_SWITCH16,         /* type */
198
         0,                      /* rightshift */
199
         1,                     /* size (0 = byte, 1 = short, 2 = long) */
200
         16,                    /* bitsize */
201
         FALSE,                 /* pc_relative */
202
         0,                      /* bitpos */
203
         complain_overflow_unsigned, /* complain_on_overflow */
204
         sh_elf64_ignore_reloc, /* special_function */
205
         "R_SH_SWITCH16",       /* name */
206
         FALSE,                 /* partial_inplace */
207
         0,                      /* src_mask */
208
         0,                      /* dst_mask */
209
         TRUE),                 /* pcrel_offset */
210
 
211
  /* A 32 bit switch table entry.  This is generated for an expression
212
     such as ``.long L1 - L2''.  The offset holds the difference
213
     between the reloc address and L2.  */
214
  HOWTO (R_SH_SWITCH32,         /* type */
215
         0,                      /* rightshift */
216
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
217
         32,                    /* bitsize */
218
         FALSE,                 /* pc_relative */
219
         0,                      /* bitpos */
220
         complain_overflow_unsigned, /* complain_on_overflow */
221
         sh_elf64_ignore_reloc, /* special_function */
222
         "R_SH_SWITCH32",       /* name */
223
         FALSE,                 /* partial_inplace */
224
         0,                      /* src_mask */
225
         0,                      /* dst_mask */
226
         TRUE),                 /* pcrel_offset */
227
 
228
  /* For 32-bit sh, this is R_SH_USES.  */
229
  EMPTY_HOWTO (27),
230
 
231
  /* For 32-bit sh, this is R_SH_COUNT.  */
232
  EMPTY_HOWTO (28),
233
 
234
  /* For 32-bit sh, this is R_SH_ALIGN.  FIXME: For linker relaxation,
235
     this might be emitted.  When linker relaxation is implemented, we
236
     might want to use it.  */
237
  EMPTY_HOWTO (29),
238
 
239
  /* For 32-bit sh, this is R_SH_CODE.  FIXME: For linker relaxation,
240
     this might be emitted.  When linker relaxation is implemented, we
241
     might want to use it.  */
242
  EMPTY_HOWTO (30),
243
 
244
  /* For 32-bit sh, this is R_SH_DATA.  FIXME: For linker relaxation,
245
     this might be emitted.  When linker relaxation is implemented, we
246
     might want to use it.  */
247
  EMPTY_HOWTO (31),
248
 
249
  /* For 32-bit sh, this is R_SH_LABEL.  FIXME: For linker relaxation,
250
     this might be emitted.  When linker relaxation is implemented, we
251
     might want to use it.  */
252
  EMPTY_HOWTO (32),
253
 
254
  /* An 8 bit switch table entry.  This is generated for an expression
255
     such as ``.word L1 - L2''.  The offset holds the difference
256
     between the reloc address and L2.  */
257
  HOWTO (R_SH_SWITCH8,          /* type */
258
         0,                      /* rightshift */
259
         0,                      /* size (0 = byte, 1 = short, 2 = long) */
260
         8,                     /* bitsize */
261
         FALSE,                 /* pc_relative */
262
         0,                      /* bitpos */
263
         complain_overflow_unsigned, /* complain_on_overflow */
264
         sh_elf64_ignore_reloc, /* special_function */
265
         "R_SH_SWITCH8",        /* name */
266
         FALSE,                 /* partial_inplace */
267
         0,                      /* src_mask */
268
         0,                      /* dst_mask */
269
         TRUE),                 /* pcrel_offset */
270
 
271
  /* GNU extension to record C++ vtable hierarchy */
272
  HOWTO (R_SH_GNU_VTINHERIT, /* type */
273
         0,                     /* rightshift */
274
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
275
         0,                     /* bitsize */
276
         FALSE,                 /* pc_relative */
277
         0,                     /* bitpos */
278
         complain_overflow_dont, /* complain_on_overflow */
279
         NULL,                  /* special_function */
280
         "R_SH_GNU_VTINHERIT", /* name */
281
         FALSE,                 /* partial_inplace */
282
         0,                     /* src_mask */
283
         0,                     /* dst_mask */
284
         FALSE),                /* pcrel_offset */
285
 
286
  /* GNU extension to record C++ vtable member usage */
287
  HOWTO (R_SH_GNU_VTENTRY,     /* type */
288
         0,                     /* rightshift */
289
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
290
         0,                     /* bitsize */
291
         FALSE,                 /* pc_relative */
292
         0,                     /* bitpos */
293
         complain_overflow_dont, /* complain_on_overflow */
294
         _bfd_elf_rel_vtable_reloc_fn,  /* special_function */
295
         "R_SH_GNU_VTENTRY",   /* name */
296
         FALSE,                 /* partial_inplace */
297
         0,                     /* src_mask */
298
         0,                     /* dst_mask */
299
         FALSE),                /* pcrel_offset */
300
 
301
  /* For 32-bit sh, this is R_SH_LOOP_START.  */
302
  EMPTY_HOWTO (36),
303
 
304
  /* For 32-bit sh, this is R_SH_LOOP_END.  */
305
  EMPTY_HOWTO (37),
306
 
307
  EMPTY_HOWTO (38),
308
  EMPTY_HOWTO (39),
309
  EMPTY_HOWTO (40),
310
  EMPTY_HOWTO (41),
311
  EMPTY_HOWTO (42),
312
  EMPTY_HOWTO (43),
313
  EMPTY_HOWTO (44),
314
 
315
  /* Used in SHLLI.L and SHLRI.L.  */
316
  HOWTO (R_SH_DIR5U,            /* type */
317
         0,                      /* rightshift */
318
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
319
         5,                     /* bitsize */
320
         FALSE,                 /* pc_relative */
321
         10,                    /* bitpos */
322
         complain_overflow_unsigned, /* complain_on_overflow */
323
         bfd_elf_generic_reloc, /* special_function */
324
         "R_SH_DIR5U",          /* name */
325
         FALSE,                 /* partial_inplace */
326
         0,                      /* src_mask */
327
         0xfc00,                /* dst_mask */
328
         FALSE),                /* pcrel_offset */
329
 
330
  /* Used in SHARI, SHLLI et al.  */
331
  HOWTO (R_SH_DIR6U,            /* type */
332
         0,                      /* rightshift */
333
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
334
         6,                     /* bitsize */
335
         FALSE,                 /* pc_relative */
336
         10,                    /* bitpos */
337
         complain_overflow_unsigned, /* complain_on_overflow */
338
         bfd_elf_generic_reloc, /* special_function */
339
         "R_SH_DIR6U",          /* name */
340
         FALSE,                 /* partial_inplace */
341
         0,                      /* src_mask */
342
         0xfc00,                /* dst_mask */
343
         FALSE),                /* pcrel_offset */
344
 
345
  /* Used in BxxI, LDHI.L et al.  */
346
  HOWTO (R_SH_DIR6S,            /* type */
347
         0,                      /* rightshift */
348
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
349
         6,                     /* bitsize */
350
         FALSE,                 /* pc_relative */
351
         10,                    /* bitpos */
352
         complain_overflow_signed, /* complain_on_overflow */
353
         bfd_elf_generic_reloc, /* special_function */
354
         "R_SH_DIR6S",          /* name */
355
         FALSE,                 /* partial_inplace */
356
         0,                      /* src_mask */
357
         0xfc00,                /* dst_mask */
358
         FALSE),                /* pcrel_offset */
359
 
360
  /* Used in ADDI, ANDI et al.  */
361
  HOWTO (R_SH_DIR10S,           /* type */
362
         0,                      /* rightshift */
363
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
364
         10,                    /* bitsize */
365
         FALSE,                 /* pc_relative */
366
         10,                    /* bitpos */
367
         complain_overflow_signed, /* complain_on_overflow */
368
         bfd_elf_generic_reloc, /* special_function */
369
         "R_SH_DIR10S",         /* name */
370
         FALSE,                 /* partial_inplace */
371
         0,                      /* src_mask */
372
         0xffc00,               /* dst_mask */
373
         FALSE),                /* pcrel_offset */
374
 
375
  /* Used in LD.UW, ST.W et al.  */
376
  HOWTO (R_SH_DIR10SW,  /* type */
377
         1,                     /* rightshift */
378
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
379
         11,                    /* bitsize */
380
         FALSE,                 /* pc_relative */
381
         10,                    /* bitpos */
382
         complain_overflow_signed, /* complain_on_overflow */
383
         bfd_elf_generic_reloc, /* special_function */
384
         "R_SH_DIR10SW",        /* name */
385
         FALSE,                 /* partial_inplace */
386
         0,                      /* src_mask */
387
         0xffc00,               /* dst_mask */
388
         FALSE),                /* pcrel_offset */
389
 
390
  /* Used in LD.L, FLD.S et al.  */
391
  HOWTO (R_SH_DIR10SL,  /* type */
392
         2,                     /* rightshift */
393
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
394
         12,                    /* bitsize */
395
         FALSE,                 /* pc_relative */
396
         10,                    /* bitpos */
397
         complain_overflow_signed, /* complain_on_overflow */
398
         bfd_elf_generic_reloc, /* special_function */
399
         "R_SH_DIR10SL",        /* name */
400
         FALSE,                 /* partial_inplace */
401
         0,                      /* src_mask */
402
         0xffc00,               /* dst_mask */
403
         FALSE),                /* pcrel_offset */
404
 
405
  /* Used in FLD.D, FST.P et al.  */
406
  HOWTO (R_SH_DIR10SQ,  /* type */
407
         3,                     /* rightshift */
408
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
409
         13,                    /* bitsize */
410
         FALSE,                 /* pc_relative */
411
         10,                    /* bitpos */
412
         complain_overflow_signed, /* complain_on_overflow */
413
         bfd_elf_generic_reloc, /* special_function */
414
         "R_SH_DIR10SQ",        /* name */
415
         FALSE,                 /* partial_inplace */
416
         0,                      /* src_mask */
417
         0xffc00,               /* dst_mask */
418
         FALSE),                /* pcrel_offset */
419
 
420
  EMPTY_HOWTO (52),
421
  EMPTY_HOWTO (53),
422
  EMPTY_HOWTO (54),
423
  EMPTY_HOWTO (55),
424
  EMPTY_HOWTO (56),
425
  EMPTY_HOWTO (57),
426
  EMPTY_HOWTO (58),
427
  EMPTY_HOWTO (59),
428
  EMPTY_HOWTO (60),
429
  EMPTY_HOWTO (61),
430
  EMPTY_HOWTO (62),
431
  EMPTY_HOWTO (63),
432
  EMPTY_HOWTO (64),
433
  EMPTY_HOWTO (65),
434
  EMPTY_HOWTO (66),
435
  EMPTY_HOWTO (67),
436
  EMPTY_HOWTO (68),
437
  EMPTY_HOWTO (69),
438
  EMPTY_HOWTO (70),
439
  EMPTY_HOWTO (71),
440
  EMPTY_HOWTO (72),
441
  EMPTY_HOWTO (73),
442
  EMPTY_HOWTO (74),
443
  EMPTY_HOWTO (75),
444
  EMPTY_HOWTO (76),
445
  EMPTY_HOWTO (77),
446
  EMPTY_HOWTO (78),
447
  EMPTY_HOWTO (79),
448
  EMPTY_HOWTO (80),
449
  EMPTY_HOWTO (81),
450
  EMPTY_HOWTO (82),
451
  EMPTY_HOWTO (83),
452
  EMPTY_HOWTO (84),
453
  EMPTY_HOWTO (85),
454
  EMPTY_HOWTO (86),
455
  EMPTY_HOWTO (87),
456
  EMPTY_HOWTO (88),
457
  EMPTY_HOWTO (89),
458
  EMPTY_HOWTO (90),
459
  EMPTY_HOWTO (91),
460
  EMPTY_HOWTO (92),
461
  EMPTY_HOWTO (93),
462
  EMPTY_HOWTO (94),
463
  EMPTY_HOWTO (95),
464
  EMPTY_HOWTO (96),
465
  EMPTY_HOWTO (97),
466
  EMPTY_HOWTO (98),
467
  EMPTY_HOWTO (99),
468
  EMPTY_HOWTO (100),
469
  EMPTY_HOWTO (101),
470
  EMPTY_HOWTO (102),
471
  EMPTY_HOWTO (103),
472
  EMPTY_HOWTO (104),
473
  EMPTY_HOWTO (105),
474
  EMPTY_HOWTO (106),
475
  EMPTY_HOWTO (107),
476
  EMPTY_HOWTO (108),
477
  EMPTY_HOWTO (109),
478
  EMPTY_HOWTO (110),
479
  EMPTY_HOWTO (111),
480
  EMPTY_HOWTO (112),
481
  EMPTY_HOWTO (113),
482
  EMPTY_HOWTO (114),
483
  EMPTY_HOWTO (115),
484
  EMPTY_HOWTO (116),
485
  EMPTY_HOWTO (117),
486
  EMPTY_HOWTO (118),
487
  EMPTY_HOWTO (119),
488
  EMPTY_HOWTO (120),
489
  EMPTY_HOWTO (121),
490
  EMPTY_HOWTO (122),
491
  EMPTY_HOWTO (123),
492
  EMPTY_HOWTO (124),
493
  EMPTY_HOWTO (125),
494
  EMPTY_HOWTO (126),
495
  EMPTY_HOWTO (127),
496
  EMPTY_HOWTO (128),
497
  EMPTY_HOWTO (129),
498
  EMPTY_HOWTO (130),
499
  EMPTY_HOWTO (131),
500
  EMPTY_HOWTO (132),
501
  EMPTY_HOWTO (133),
502
  EMPTY_HOWTO (134),
503
  EMPTY_HOWTO (135),
504
  EMPTY_HOWTO (136),
505
  EMPTY_HOWTO (137),
506
  EMPTY_HOWTO (138),
507
  EMPTY_HOWTO (139),
508
  EMPTY_HOWTO (140),
509
  EMPTY_HOWTO (141),
510
  EMPTY_HOWTO (142),
511
  EMPTY_HOWTO (143),
512
  EMPTY_HOWTO (144),
513
  EMPTY_HOWTO (145),
514
  EMPTY_HOWTO (146),
515
  EMPTY_HOWTO (147),
516
  EMPTY_HOWTO (148),
517
  EMPTY_HOWTO (149),
518
  EMPTY_HOWTO (150),
519
  EMPTY_HOWTO (151),
520
  EMPTY_HOWTO (152),
521
  EMPTY_HOWTO (153),
522
  EMPTY_HOWTO (154),
523
  EMPTY_HOWTO (155),
524
  EMPTY_HOWTO (156),
525
  EMPTY_HOWTO (157),
526
  EMPTY_HOWTO (158),
527
  EMPTY_HOWTO (159),
528
 
529
  /* Relocs for dynamic linking for 32-bit SH would follow.  We don't have
530
     any dynamic linking support for 64-bit SH at present.  */
531
 
532
  EMPTY_HOWTO (160),
533
  EMPTY_HOWTO (161),
534
  EMPTY_HOWTO (162),
535
  EMPTY_HOWTO (163),
536
  EMPTY_HOWTO (164),
537
  EMPTY_HOWTO (165),
538
  EMPTY_HOWTO (166),
539
  EMPTY_HOWTO (167),
540
  EMPTY_HOWTO (168),
541
 
542
  /* Back to SH5 relocations.  */
543
  /* Used in MOVI and SHORI (x & 65536).  */
544
  HOWTO (R_SH_GOT_LOW16,        /* type */
545
         0,                      /* rightshift */
546
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
547
         64,                    /* bitsize */
548
         FALSE,                 /* pc_relative */
549
         10,                    /* bitpos */
550
         complain_overflow_dont, /* complain_on_overflow */
551
         bfd_elf_generic_reloc, /* special_function */
552
         "R_SH_GOT_LOW16",      /* name */
553
         FALSE,                 /* partial_inplace */
554
         0,                      /* src_mask */
555
         0x3fffc00,             /* dst_mask */
556
         FALSE),                /* pcrel_offset */
557
 
558
  /* Used in MOVI and SHORI ((x >> 16) & 65536).  */
559
  HOWTO (R_SH_GOT_MEDLOW16,     /* type */
560
         16,                    /* rightshift */
561
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
562
         64,                    /* bitsize */
563
         FALSE,                 /* pc_relative */
564
         10,                    /* bitpos */
565
         complain_overflow_dont, /* complain_on_overflow */
566
         bfd_elf_generic_reloc, /* special_function */
567
         "R_SH_GOT_MEDLOW16",   /* name */
568
         FALSE,                 /* partial_inplace */
569
         0,                      /* src_mask */
570
         0x3fffc00,             /* dst_mask */
571
         FALSE),                /* pcrel_offset */
572
 
573
  /* Used in MOVI and SHORI ((x >> 32) & 65536).  */
574
  HOWTO (R_SH_GOT_MEDHI16,      /* type */
575
         32,                    /* rightshift */
576
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
577
         64,                    /* bitsize */
578
         FALSE,                 /* pc_relative */
579
         10,                    /* bitpos */
580
         complain_overflow_dont, /* complain_on_overflow */
581
         bfd_elf_generic_reloc, /* special_function */
582
         "R_SH_GOT_MEDHI16",    /* name */
583
         FALSE,                 /* partial_inplace */
584
         0,                      /* src_mask */
585
         0x3fffc00,             /* dst_mask */
586
         FALSE),                /* pcrel_offset */
587
 
588
  /* Used in MOVI and SHORI ((x >> 48) & 65536).  */
589
  HOWTO (R_SH_GOT_HI16,         /* type */
590
         48,                    /* rightshift */
591
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
592
         64,                    /* bitsize */
593
         FALSE,                 /* pc_relative */
594
         10,                    /* bitpos */
595
         complain_overflow_dont, /* complain_on_overflow */
596
         bfd_elf_generic_reloc, /* special_function */
597
         "R_SH_GOT_HI16",       /* name */
598
         FALSE,                 /* partial_inplace */
599
         0,                      /* src_mask */
600
         0x3fffc00,             /* dst_mask */
601
         FALSE),                /* pcrel_offset */
602
 
603
  /* Used in MOVI and SHORI (x & 65536).  */
604
  HOWTO (R_SH_GOTPLT_LOW16,     /* type */
605
         0,                      /* rightshift */
606
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
607
         64,                    /* bitsize */
608
         FALSE,                 /* pc_relative */
609
         10,                    /* bitpos */
610
         complain_overflow_dont, /* complain_on_overflow */
611
         bfd_elf_generic_reloc, /* special_function */
612
         "R_SH_GOTPLT_LOW16",   /* name */
613
         FALSE,                 /* partial_inplace */
614
         0,                      /* src_mask */
615
         0x3fffc00,             /* dst_mask */
616
         FALSE),                /* pcrel_offset */
617
 
618
  /* Used in MOVI and SHORI ((x >> 16) & 65536).  */
619
  HOWTO (R_SH_GOTPLT_MEDLOW16,  /* type */
620
         16,                    /* rightshift */
621
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
622
         64,                    /* bitsize */
623
         FALSE,                 /* pc_relative */
624
         10,                    /* bitpos */
625
         complain_overflow_dont, /* complain_on_overflow */
626
         bfd_elf_generic_reloc, /* special_function */
627
         "R_SH_GOTPLT_MEDLOW16", /* name */
628
         FALSE,                 /* partial_inplace */
629
         0,                      /* src_mask */
630
         0x3fffc00,             /* dst_mask */
631
         FALSE),                /* pcrel_offset */
632
 
633
  /* Used in MOVI and SHORI ((x >> 32) & 65536).  */
634
  HOWTO (R_SH_GOTPLT_MEDHI16,   /* type */
635
         32,                    /* rightshift */
636
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
637
         64,                    /* bitsize */
638
         FALSE,                 /* pc_relative */
639
         10,                    /* bitpos */
640
         complain_overflow_dont, /* complain_on_overflow */
641
         bfd_elf_generic_reloc, /* special_function */
642
         "R_SH_GOTPLT_MEDHI16", /* name */
643
         FALSE,                 /* partial_inplace */
644
         0,                      /* src_mask */
645
         0x3fffc00,             /* dst_mask */
646
         FALSE),                /* pcrel_offset */
647
 
648
  /* Used in MOVI and SHORI ((x >> 48) & 65536).  */
649
  HOWTO (R_SH_GOTPLT_HI16,      /* type */
650
         48,                    /* rightshift */
651
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
652
         64,                    /* bitsize */
653
         FALSE,                 /* pc_relative */
654
         10,                    /* bitpos */
655
         complain_overflow_dont, /* complain_on_overflow */
656
         bfd_elf_generic_reloc, /* special_function */
657
         "R_SH_GOTPLT_HI16",    /* name */
658
         FALSE,                 /* partial_inplace */
659
         0,                      /* src_mask */
660
         0x3fffc00,             /* dst_mask */
661
         FALSE),                /* pcrel_offset */
662
 
663
  /* Used in MOVI and SHORI (x & 65536).  */
664
  HOWTO (R_SH_PLT_LOW16,        /* type */
665
         0,                      /* rightshift */
666
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
667
         64,                    /* bitsize */
668
         TRUE,                  /* pc_relative */
669
         10,                    /* bitpos */
670
         complain_overflow_dont, /* complain_on_overflow */
671
         bfd_elf_generic_reloc, /* special_function */
672
         "R_SH_PLT_LOW16",      /* name */
673
         FALSE,                 /* partial_inplace */
674
         0,                      /* src_mask */
675
         0x3fffc00,             /* dst_mask */
676
         TRUE),                 /* pcrel_offset */
677
 
678
  /* Used in MOVI and SHORI ((x >> 16) & 65536).  */
679
  HOWTO (R_SH_PLT_MEDLOW16,     /* type */
680
         16,                    /* rightshift */
681
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
682
         64,                    /* bitsize */
683
         TRUE,                  /* pc_relative */
684
         10,                    /* bitpos */
685
         complain_overflow_dont, /* complain_on_overflow */
686
         bfd_elf_generic_reloc, /* special_function */
687
         "R_SH_PLT_MEDLOW16",   /* name */
688
         FALSE,                 /* partial_inplace */
689
         0,                      /* src_mask */
690
         0x3fffc00,             /* dst_mask */
691
         TRUE),                 /* pcrel_offset */
692
 
693
  /* Used in MOVI and SHORI ((x >> 32) & 65536).  */
694
  HOWTO (R_SH_PLT_MEDHI16,      /* type */
695
         32,                    /* rightshift */
696
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
697
         64,                    /* bitsize */
698
         TRUE,                  /* pc_relative */
699
         10,                    /* bitpos */
700
         complain_overflow_dont, /* complain_on_overflow */
701
         bfd_elf_generic_reloc, /* special_function */
702
         "R_SH_PLT_MEDHI16",    /* name */
703
         FALSE,                 /* partial_inplace */
704
         0,                      /* src_mask */
705
         0x3fffc00,             /* dst_mask */
706
         TRUE),                 /* pcrel_offset */
707
 
708
  /* Used in MOVI and SHORI ((x >> 48) & 65536).  */
709
  HOWTO (R_SH_PLT_HI16,         /* type */
710
         48,                    /* rightshift */
711
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
712
         64,                    /* bitsize */
713
         TRUE,                  /* pc_relative */
714
         10,                    /* bitpos */
715
         complain_overflow_dont, /* complain_on_overflow */
716
         bfd_elf_generic_reloc, /* special_function */
717
         "R_SH_PLT_HI16",       /* name */
718
         FALSE,                 /* partial_inplace */
719
         0,                      /* src_mask */
720
         0x3fffc00,             /* dst_mask */
721
         TRUE),                 /* pcrel_offset */
722
 
723
  /* Used in MOVI and SHORI (x & 65536).  */
724
  HOWTO (R_SH_GOTOFF_LOW16,     /* type */
725
         0,                      /* rightshift */
726
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
727
         64,                    /* bitsize */
728
         FALSE,                 /* pc_relative */
729
         10,                    /* bitpos */
730
         complain_overflow_dont, /* complain_on_overflow */
731
         bfd_elf_generic_reloc, /* special_function */
732
         "R_SH_GOTOFF_LOW16",   /* name */
733
         FALSE,                 /* partial_inplace */
734
         0,                      /* src_mask */
735
         0x3fffc00,             /* dst_mask */
736
         FALSE),                /* pcrel_offset */
737
 
738
  /* Used in MOVI and SHORI ((x >> 16) & 65536).  */
739
  HOWTO (R_SH_GOTOFF_MEDLOW16,  /* type */
740
         16,                    /* rightshift */
741
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
742
         64,                    /* bitsize */
743
         FALSE,                 /* pc_relative */
744
         10,                    /* bitpos */
745
         complain_overflow_dont, /* complain_on_overflow */
746
         bfd_elf_generic_reloc, /* special_function */
747
         "R_SH_GOTOFF_MEDLOW16", /* name */
748
         FALSE,                 /* partial_inplace */
749
         0,                      /* src_mask */
750
         0x3fffc00,             /* dst_mask */
751
         FALSE),                /* pcrel_offset */
752
 
753
  /* Used in MOVI and SHORI ((x >> 32) & 65536).  */
754
  HOWTO (R_SH_GOTOFF_MEDHI16,   /* type */
755
         32,                    /* rightshift */
756
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
757
         64,                    /* bitsize */
758
         FALSE,                 /* pc_relative */
759
         10,                    /* bitpos */
760
         complain_overflow_dont, /* complain_on_overflow */
761
         bfd_elf_generic_reloc, /* special_function */
762
         "R_SH_GOTOFF_MEDHI16", /* name */
763
         FALSE,                 /* partial_inplace */
764
         0,                      /* src_mask */
765
         0x3fffc00,             /* dst_mask */
766
         FALSE),                /* pcrel_offset */
767
 
768
  /* Used in MOVI and SHORI ((x >> 48) & 65536).  */
769
  HOWTO (R_SH_GOTOFF_HI16,      /* type */
770
         48,                    /* rightshift */
771
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
772
         64,                    /* bitsize */
773
         FALSE,                 /* pc_relative */
774
         10,                    /* bitpos */
775
         complain_overflow_dont, /* complain_on_overflow */
776
         bfd_elf_generic_reloc, /* special_function */
777
         "R_SH_GOTOFF_HI16",    /* name */
778
         FALSE,                 /* partial_inplace */
779
         0,                      /* src_mask */
780
         0x3fffc00,             /* dst_mask */
781
         FALSE),                /* pcrel_offset */
782
 
783
  /* Used in MOVI and SHORI (x & 65536).  */
784
  HOWTO (R_SH_GOTPC_LOW16,      /* type */
785
         0,                      /* rightshift */
786
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
787
         64,                    /* bitsize */
788
         TRUE,                  /* pc_relative */
789
         10,                    /* bitpos */
790
         complain_overflow_dont, /* complain_on_overflow */
791
         bfd_elf_generic_reloc, /* special_function */
792
         "R_SH_GOTPC_LOW16",    /* name */
793
         FALSE,                 /* partial_inplace */
794
         0,                      /* src_mask */
795
         0x3fffc00,             /* dst_mask */
796
         TRUE),                 /* pcrel_offset */
797
 
798
  /* Used in MOVI and SHORI ((x >> 16) & 65536).  */
799
  HOWTO (R_SH_GOTPC_MEDLOW16,   /* type */
800
         16,                    /* rightshift */
801
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
802
         64,                    /* bitsize */
803
         TRUE,                  /* pc_relative */
804
         10,                    /* bitpos */
805
         complain_overflow_dont, /* complain_on_overflow */
806
         bfd_elf_generic_reloc, /* special_function */
807
         "R_SH_GOTPC_MEDLOW16", /* name */
808
         FALSE,                 /* partial_inplace */
809
         0,                      /* src_mask */
810
         0x3fffc00,             /* dst_mask */
811
         TRUE),                 /* pcrel_offset */
812
 
813
  /* Used in MOVI and SHORI ((x >> 32) & 65536).  */
814
  HOWTO (R_SH_GOTPC_MEDHI16,    /* type */
815
         32,                    /* rightshift */
816
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
817
         64,                    /* bitsize */
818
         TRUE,                  /* pc_relative */
819
         10,                    /* bitpos */
820
         complain_overflow_dont, /* complain_on_overflow */
821
         bfd_elf_generic_reloc, /* special_function */
822
         "R_SH_GOTPC_MEDHI16",  /* name */
823
         FALSE,                 /* partial_inplace */
824
         0,                      /* src_mask */
825
         0x3fffc00,             /* dst_mask */
826
         TRUE),                 /* pcrel_offset */
827
 
828
  /* Used in MOVI and SHORI ((x >> 48) & 65536).  */
829
  HOWTO (R_SH_GOTPC_HI16,       /* type */
830
         48,                    /* rightshift */
831
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
832
         64,                    /* bitsize */
833
         TRUE,                  /* pc_relative */
834
         10,                    /* bitpos */
835
         complain_overflow_dont, /* complain_on_overflow */
836
         bfd_elf_generic_reloc, /* special_function */
837
         "R_SH_GOTPC_HI16",     /* name */
838
         FALSE,                 /* partial_inplace */
839
         0,                      /* src_mask */
840
         0x3fffc00,             /* dst_mask */
841
         TRUE),                 /* pcrel_offset */
842
 
843
  /* Used in LD.L, FLD.S et al.  */
844
  HOWTO (R_SH_GOT10BY4,         /* type */
845
         2,                     /* rightshift */
846
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
847
         12,                    /* bitsize */
848
         FALSE,                 /* pc_relative */
849
         10,                    /* bitpos */
850
         complain_overflow_signed, /* complain_on_overflow */
851
         bfd_elf_generic_reloc, /* special_function */
852
         "R_SH_GOT10BY4",       /* name */
853
         FALSE,                 /* partial_inplace */
854
         0,                      /* src_mask */
855
         0xffc00,               /* dst_mask */
856
         FALSE),                /* pcrel_offset */
857
 
858
  /* Used in LD.L, FLD.S et al.  */
859
  HOWTO (R_SH_GOTPLT10BY4,      /* type */
860
         2,                     /* rightshift */
861
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
862
         12,                    /* bitsize */
863
         FALSE,                 /* pc_relative */
864
         10,                    /* bitpos */
865
         complain_overflow_signed, /* complain_on_overflow */
866
         bfd_elf_generic_reloc, /* special_function */
867
         "R_SH_GOTPLT10BY4",    /* name */
868
         FALSE,                 /* partial_inplace */
869
         0,                      /* src_mask */
870
         0xffc00,               /* dst_mask */
871
         FALSE),                /* pcrel_offset */
872
 
873
  /* Used in FLD.D, FST.P et al.  */
874
  HOWTO (R_SH_GOT10BY8,         /* type */
875
         3,                     /* rightshift */
876
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
877
         13,                    /* bitsize */
878
         FALSE,                 /* pc_relative */
879
         10,                    /* bitpos */
880
         complain_overflow_signed, /* complain_on_overflow */
881
         bfd_elf_generic_reloc, /* special_function */
882
         "R_SH_GOT10BY8",       /* name */
883
         FALSE,                 /* partial_inplace */
884
         0,                      /* src_mask */
885
         0xffc00,               /* dst_mask */
886
         FALSE),                /* pcrel_offset */
887
 
888
  /* Used in FLD.D, FST.P et al.  */
889
  HOWTO (R_SH_GOTPLT10BY8,      /* type */
890
         3,                     /* rightshift */
891
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
892
         13,                    /* bitsize */
893
         FALSE,                 /* pc_relative */
894
         10,                    /* bitpos */
895
         complain_overflow_signed, /* complain_on_overflow */
896
         bfd_elf_generic_reloc, /* special_function */
897
         "R_SH_GOTPLT10BY8",    /* name */
898
         FALSE,                 /* partial_inplace */
899
         0,                      /* src_mask */
900
         0xffc00,               /* dst_mask */
901
         FALSE),                /* pcrel_offset */
902
 
903
  HOWTO (R_SH_COPY64,           /* type */
904
         0,                      /* rightshift */
905
         4,                     /* size (0 = byte, 1 = short, 2 = long) */
906
         64,                    /* bitsize */
907
         FALSE,                 /* pc_relative */
908
         0,                      /* bitpos */
909
         complain_overflow_dont, /* complain_on_overflow */
910
         bfd_elf_generic_reloc, /* special_function */
911
         "R_SH_COPY64",         /* name */
912
         FALSE,                 /* partial_inplace */
913
         0,                      /* src_mask */
914
         ((bfd_vma) 0) - 1,      /* dst_mask */
915
         FALSE),                /* pcrel_offset */
916
 
917
  HOWTO (R_SH_GLOB_DAT64,       /* type */
918
         0,                      /* rightshift */
919
         4,                     /* size (0 = byte, 1 = short, 2 = long) */
920
         64,                    /* bitsize */
921
         FALSE,                 /* pc_relative */
922
         0,                      /* bitpos */
923
         complain_overflow_dont, /* complain_on_overflow */
924
         bfd_elf_generic_reloc, /* special_function */
925
         "R_SH_GLOB_DAT64",     /* name */
926
         FALSE,                 /* partial_inplace */
927
         0,                      /* src_mask */
928
         ((bfd_vma) 0) - 1,      /* dst_mask */
929
         FALSE),                /* pcrel_offset */
930
 
931
  HOWTO (R_SH_JMP_SLOT64,       /* type */
932
         0,                      /* rightshift */
933
         4,                     /* size (0 = byte, 1 = short, 2 = long) */
934
         64,                    /* bitsize */
935
         FALSE,                 /* pc_relative */
936
         0,                      /* bitpos */
937
         complain_overflow_dont, /* complain_on_overflow */
938
         bfd_elf_generic_reloc, /* special_function */
939
         "R_SH_JMP_SLOT64",     /* name */
940
         FALSE,                 /* partial_inplace */
941
         0,                      /* src_mask */
942
         ((bfd_vma) 0) - 1,      /* dst_mask */
943
         FALSE),                /* pcrel_offset */
944
 
945
  HOWTO (R_SH_RELATIVE64,       /* type */
946
         0,                      /* rightshift */
947
         4,                     /* size (0 = byte, 1 = short, 2 = long) */
948
         64,                    /* bitsize */
949
         FALSE,                 /* pc_relative */
950
         0,                      /* bitpos */
951
         complain_overflow_dont, /* complain_on_overflow */
952
         bfd_elf_generic_reloc, /* special_function */
953
         "R_SH_RELATIVE64",     /* name */
954
         FALSE,                 /* partial_inplace */
955
         0,                      /* src_mask */
956
         ((bfd_vma) 0) - 1,      /* dst_mask */
957
         FALSE),                /* pcrel_offset */
958
 
959
  EMPTY_HOWTO (197),
960
  EMPTY_HOWTO (198),
961
  EMPTY_HOWTO (199),
962
  EMPTY_HOWTO (200),
963
  EMPTY_HOWTO (201),
964
  EMPTY_HOWTO (202),
965
  EMPTY_HOWTO (203),
966
  EMPTY_HOWTO (204),
967
  EMPTY_HOWTO (205),
968
  EMPTY_HOWTO (206),
969
  EMPTY_HOWTO (207),
970
  EMPTY_HOWTO (208),
971
  EMPTY_HOWTO (209),
972
  EMPTY_HOWTO (210),
973
  EMPTY_HOWTO (211),
974
  EMPTY_HOWTO (212),
975
  EMPTY_HOWTO (213),
976
  EMPTY_HOWTO (214),
977
  EMPTY_HOWTO (215),
978
  EMPTY_HOWTO (216),
979
  EMPTY_HOWTO (217),
980
  EMPTY_HOWTO (218),
981
  EMPTY_HOWTO (219),
982
  EMPTY_HOWTO (220),
983
  EMPTY_HOWTO (221),
984
  EMPTY_HOWTO (222),
985
  EMPTY_HOWTO (223),
986
  EMPTY_HOWTO (224),
987
  EMPTY_HOWTO (225),
988
  EMPTY_HOWTO (226),
989
  EMPTY_HOWTO (227),
990
  EMPTY_HOWTO (228),
991
  EMPTY_HOWTO (229),
992
  EMPTY_HOWTO (230),
993
  EMPTY_HOWTO (231),
994
  EMPTY_HOWTO (232),
995
  EMPTY_HOWTO (233),
996
  EMPTY_HOWTO (234),
997
  EMPTY_HOWTO (235),
998
  EMPTY_HOWTO (236),
999
  EMPTY_HOWTO (237),
1000
  EMPTY_HOWTO (238),
1001
  EMPTY_HOWTO (239),
1002
  EMPTY_HOWTO (240),
1003
  EMPTY_HOWTO (241),
1004
 
1005
  /* Relocations for SHmedia code.  None of these are partial_inplace or
1006
     use the field being relocated.  */
1007
 
1008
  /* The assembler will generate this reloc before a block of SHmedia
1009
     instructions.  A section should be processed as assuming it contains
1010
     data, unless this reloc is seen.  Note that a block of SHcompact
1011
     instructions are instead preceded by R_SH_CODE.
1012
     This is currently not implemented, but should be used for SHmedia
1013
     linker relaxation.  */
1014
  HOWTO (R_SH_SHMEDIA_CODE,     /* type */
1015
         0,                      /* rightshift */
1016
         1,                     /* size (0 = byte, 1 = short, 2 = long) */
1017
         0,                      /* bitsize */
1018
         FALSE,                 /* pc_relative */
1019
         0,                      /* bitpos */
1020
         complain_overflow_unsigned, /* complain_on_overflow */
1021
         sh_elf64_ignore_reloc, /* special_function */
1022
         "R_SH_SHMEDIA_CODE",   /* name */
1023
         FALSE,                 /* partial_inplace */
1024
         0,                      /* src_mask */
1025
         0,                      /* dst_mask */
1026
         FALSE),                /* pcrel_offset */
1027
 
1028
  /* The assembler will generate this reloc at a PTA or PTB instruction,
1029
     and the linker checks the right type of target, or changes a PTA to a
1030
     PTB, if the original insn was PT.  */
1031
  HOWTO (R_SH_PT_16,            /* type */
1032
         2,                     /* rightshift */
1033
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
1034
         18,                    /* bitsize */
1035
         TRUE,                  /* pc_relative */
1036
         10,                    /* bitpos */
1037
         complain_overflow_signed, /* complain_on_overflow */
1038
         bfd_elf_generic_reloc, /* special_function */
1039
         "R_SH_PT_16",          /* name */
1040
         FALSE,                 /* partial_inplace */
1041
         0,                      /* src_mask */
1042
         0x3fffc00,             /* dst_mask */
1043
         TRUE),                 /* pcrel_offset */
1044
 
1045
  /* Used in unexpanded MOVI.  */
1046
  HOWTO (R_SH_IMMS16,           /* type */
1047
         0,                      /* rightshift */
1048
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
1049
         16,                    /* bitsize */
1050
         FALSE,                 /* pc_relative */
1051
         10,                    /* bitpos */
1052
         complain_overflow_signed, /* complain_on_overflow */
1053
         bfd_elf_generic_reloc, /* special_function */
1054
         "R_SH_IMMS16",         /* name */
1055
         FALSE,                 /* partial_inplace */
1056
         0,                      /* src_mask */
1057
         0x3fffc00,             /* dst_mask */
1058
         FALSE),                /* pcrel_offset */
1059
 
1060
  /* Used in SHORI.  */
1061
  HOWTO (R_SH_IMMU16,           /* type */
1062
         0,                      /* rightshift */
1063
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
1064
         16,                    /* bitsize */
1065
         FALSE,                 /* pc_relative */
1066
         10,                    /* bitpos */
1067
         complain_overflow_unsigned, /* complain_on_overflow */
1068
         bfd_elf_generic_reloc, /* special_function */
1069
         "R_SH_IMMU16",         /* name */
1070
         FALSE,                 /* partial_inplace */
1071
         0,                      /* src_mask */
1072
         0x3fffc00,             /* dst_mask */
1073
         FALSE),                /* pcrel_offset */
1074
 
1075
  /* Used in MOVI and SHORI (x & 65536).  */
1076
  HOWTO (R_SH_IMM_LOW16,        /* type */
1077
         0,                      /* rightshift */
1078
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
1079
         64,                    /* bitsize */
1080
         FALSE,                 /* pc_relative */
1081
         10,                    /* bitpos */
1082
         complain_overflow_dont, /* complain_on_overflow */
1083
         bfd_elf_generic_reloc, /* special_function */
1084
         "R_SH_IMM_LOW16",      /* name */
1085
         FALSE,                 /* partial_inplace */
1086
         0,                      /* src_mask */
1087
         0x3fffc00,             /* dst_mask */
1088
         FALSE),                /* pcrel_offset */
1089
 
1090
  /* Used in MOVI and SHORI ((x - $) & 65536).  */
1091
  HOWTO (R_SH_IMM_LOW16_PCREL,  /* type */
1092
         0,                      /* rightshift */
1093
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
1094
         64,                    /* bitsize */
1095
         TRUE,                  /* pc_relative */
1096
         10,                    /* bitpos */
1097
         complain_overflow_dont, /* complain_on_overflow */
1098
         bfd_elf_generic_reloc, /* special_function */
1099
         "R_SH_IMM_LOW16_PCREL", /* name */
1100
         FALSE,                 /* partial_inplace */
1101
         0,                      /* src_mask */
1102
         0x3fffc00,             /* dst_mask */
1103
         TRUE),                 /* pcrel_offset */
1104
 
1105
  /* Used in MOVI and SHORI ((x >> 16) & 65536).  */
1106
  HOWTO (R_SH_IMM_MEDLOW16,     /* type */
1107
         16,                    /* rightshift */
1108
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
1109
         64,                    /* bitsize */
1110
         FALSE,                 /* pc_relative */
1111
         10,                    /* bitpos */
1112
         complain_overflow_dont, /* complain_on_overflow */
1113
         bfd_elf_generic_reloc, /* special_function */
1114
         "R_SH_IMM_MEDLOW16",   /* name */
1115
         FALSE,                 /* partial_inplace */
1116
         0,                      /* src_mask */
1117
         0x3fffc00,             /* dst_mask */
1118
         FALSE),                /* pcrel_offset */
1119
 
1120
  /* Used in MOVI and SHORI (((x - $) >> 16) & 65536).  */
1121
  HOWTO (R_SH_IMM_MEDLOW16_PCREL, /* type */
1122
         16,                    /* rightshift */
1123
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
1124
         64,                    /* bitsize */
1125
         TRUE,                  /* pc_relative */
1126
         10,                    /* bitpos */
1127
         complain_overflow_dont, /* complain_on_overflow */
1128
         bfd_elf_generic_reloc, /* special_function */
1129
         "R_SH_IMM_MEDLOW16_PCREL", /* name */
1130
         FALSE,                 /* partial_inplace */
1131
         0,                      /* src_mask */
1132
         0x3fffc00,             /* dst_mask */
1133
         TRUE),                 /* pcrel_offset */
1134
 
1135
  /* Used in MOVI and SHORI ((x >> 32) & 65536).  */
1136
  HOWTO (R_SH_IMM_MEDHI16,      /* type */
1137
         32,                    /* rightshift */
1138
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
1139
         64,                    /* bitsize */
1140
         FALSE,                 /* pc_relative */
1141
         10,                    /* bitpos */
1142
         complain_overflow_dont, /* complain_on_overflow */
1143
         bfd_elf_generic_reloc, /* special_function */
1144
         "R_SH_IMM_MEDHI16",    /* name */
1145
         FALSE,                 /* partial_inplace */
1146
         0,                      /* src_mask */
1147
         0x3fffc00,             /* dst_mask */
1148
         FALSE),                /* pcrel_offset */
1149
 
1150
  /* Used in MOVI and SHORI (((x - $) >> 32) & 65536).  */
1151
  HOWTO (R_SH_IMM_MEDHI16_PCREL, /* type */
1152
         32,                    /* rightshift */
1153
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
1154
         64,                    /* bitsize */
1155
         TRUE,                  /* pc_relative */
1156
         10,                    /* bitpos */
1157
         complain_overflow_dont, /* complain_on_overflow */
1158
         bfd_elf_generic_reloc, /* special_function */
1159
         "R_SH_IMM_MEDHI16_PCREL", /* name */
1160
         FALSE,                 /* partial_inplace */
1161
         0,                      /* src_mask */
1162
         0x3fffc00,             /* dst_mask */
1163
         TRUE),                 /* pcrel_offset */
1164
 
1165
  /* Used in MOVI and SHORI ((x >> 48) & 65536).  */
1166
  HOWTO (R_SH_IMM_HI16,         /* type */
1167
         48,                    /* rightshift */
1168
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
1169
         64,                    /* bitsize */
1170
         FALSE,                 /* pc_relative */
1171
         10,                    /* bitpos */
1172
         complain_overflow_dont, /* complain_on_overflow */
1173
         bfd_elf_generic_reloc, /* special_function */
1174
         "R_SH_IMM_HI16",       /* name */
1175
         FALSE,                 /* partial_inplace */
1176
         0,                      /* src_mask */
1177
         0x3fffc00,             /* dst_mask */
1178
         FALSE),                /* pcrel_offset */
1179
 
1180
  /* Used in MOVI and SHORI (((x - $) >> 48) & 65536).  */
1181
  HOWTO (R_SH_IMM_HI16_PCREL,   /* type */
1182
         48,                    /* rightshift */
1183
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
1184
         64,                    /* bitsize */
1185
         TRUE,                  /* pc_relative */
1186
         10,                    /* bitpos */
1187
         complain_overflow_dont, /* complain_on_overflow */
1188
         bfd_elf_generic_reloc, /* special_function */
1189
         "R_SH_IMM_HI16_PCREL", /* name */
1190
         FALSE,                 /* partial_inplace */
1191
         0,                      /* src_mask */
1192
         0x3fffc00,             /* dst_mask */
1193
         TRUE),                 /* pcrel_offset */
1194
 
1195
  /* For the .uaquad pseudo.  */
1196
  HOWTO (R_SH_64,               /* type */
1197
         0,                      /* rightshift */
1198
         4,                     /* size (0 = byte, 1 = short, 2 = long) */
1199
         64,                    /* bitsize */
1200
         FALSE,                 /* pc_relative */
1201
         0,                      /* bitpos */
1202
         complain_overflow_dont, /* complain_on_overflow */
1203
         bfd_elf_generic_reloc, /* special_function */
1204
         "R_SH_64",             /* name */
1205
         FALSE,                 /* partial_inplace */
1206
         0,                      /* src_mask */
1207
         ((bfd_vma) 0) - 1,      /* dst_mask */
1208
         FALSE),                /* pcrel_offset */
1209
 
1210
  /* For the .uaquad pseudo, (x - $).  */
1211
  HOWTO (R_SH_64_PCREL,         /* type */
1212
         48,                    /* rightshift */
1213
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
1214
         64,                    /* bitsize */
1215
         TRUE,                  /* pc_relative */
1216
         10,                    /* bitpos */
1217
         complain_overflow_dont, /* complain_on_overflow */
1218
         bfd_elf_generic_reloc, /* special_function */
1219
         "R_SH_64_PCREL",       /* name */
1220
         FALSE,                 /* partial_inplace */
1221
         0,                      /* src_mask */
1222
         ((bfd_vma) 0) - 1,      /* dst_mask */
1223
         TRUE),                 /* pcrel_offset */
1224
 
1225
};
1226
 
1227
/* This function is used for relocs which are only used for relaxing,
1228
   which the linker should otherwise ignore.  */
1229
 
1230
static bfd_reloc_status_type
1231
sh_elf64_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc_entry,
1232
                       asymbol *symbol ATTRIBUTE_UNUSED,
1233
                       void *data ATTRIBUTE_UNUSED, asection *input_section,
1234
                       bfd *output_bfd,
1235
                       char **error_message ATTRIBUTE_UNUSED)
1236
{
1237
  if (output_bfd != NULL)
1238
    reloc_entry->address += input_section->output_offset;
1239
  return bfd_reloc_ok;
1240
}
1241
 
1242
/* This function is used for normal relocs.  This used to be like the COFF
1243
   function, and is almost certainly incorrect for other ELF targets.
1244
 
1245
   See sh_elf_reloc in elf32-sh.c for the original.  */
1246
 
1247
static bfd_reloc_status_type
1248
sh_elf64_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol_in,
1249
                void *data, asection *input_section, bfd *output_bfd,
1250
                char **error_message ATTRIBUTE_UNUSED)
1251
{
1252
  unsigned long insn;
1253
  bfd_vma sym_value;
1254
  enum elf_sh_reloc_type r_type;
1255
  bfd_vma addr = reloc_entry->address;
1256
  bfd_byte *hit_data = addr + (bfd_byte *) data;
1257
 
1258
  r_type = (enum elf_sh_reloc_type) reloc_entry->howto->type;
1259
 
1260
  if (output_bfd != NULL)
1261
    {
1262
      /* Partial linking--do nothing.  */
1263
      reloc_entry->address += input_section->output_offset;
1264
      return bfd_reloc_ok;
1265
    }
1266
 
1267
  if (symbol_in != NULL
1268
      && bfd_is_und_section (symbol_in->section))
1269
    return bfd_reloc_undefined;
1270
 
1271
  if (bfd_is_com_section (symbol_in->section))
1272
    sym_value = 0;
1273
  else
1274
    sym_value = (symbol_in->value +
1275
                 symbol_in->section->output_section->vma +
1276
                 symbol_in->section->output_offset);
1277
 
1278
  switch (r_type)
1279
    {
1280
    case R_SH_DIR32:
1281
      insn = bfd_get_32 (abfd, hit_data);
1282
      insn += sym_value + reloc_entry->addend;
1283
      bfd_put_32 (abfd, insn, hit_data);
1284
      break;
1285
 
1286
    default:
1287
      abort ();
1288
      break;
1289
    }
1290
 
1291
  return bfd_reloc_ok;
1292
}
1293
 
1294
/* This structure is used to map BFD reloc codes to SH ELF relocs.  */
1295
 
1296
struct elf_reloc_map
1297
{
1298
  bfd_reloc_code_real_type bfd_reloc_val;
1299
  unsigned char elf_reloc_val;
1300
};
1301
 
1302
/* An array mapping BFD reloc codes to SH ELF relocs.  */
1303
 
1304
static const struct elf_reloc_map sh64_reloc_map[] =
1305
{
1306
  { BFD_RELOC_NONE, R_SH_NONE },
1307
  { BFD_RELOC_32, R_SH_DIR32 },
1308
  { BFD_RELOC_CTOR, R_SH_DIR32 },
1309
  { BFD_RELOC_32_PCREL, R_SH_REL32 },
1310
  { BFD_RELOC_8_PCREL, R_SH_SWITCH8 },
1311
  { BFD_RELOC_SH_SWITCH16, R_SH_SWITCH16 },
1312
  { BFD_RELOC_SH_SWITCH32, R_SH_SWITCH32 },
1313
  { BFD_RELOC_VTABLE_INHERIT, R_SH_GNU_VTINHERIT },
1314
  { BFD_RELOC_VTABLE_ENTRY, R_SH_GNU_VTENTRY },
1315
  { BFD_RELOC_SH_GOT_LOW16, R_SH_GOT_LOW16 },
1316
  { BFD_RELOC_SH_GOT_MEDLOW16, R_SH_GOT_MEDLOW16 },
1317
  { BFD_RELOC_SH_GOT_MEDHI16, R_SH_GOT_MEDHI16 },
1318
  { BFD_RELOC_SH_GOT_HI16, R_SH_GOT_HI16 },
1319
  { BFD_RELOC_SH_GOTPLT_LOW16, R_SH_GOTPLT_LOW16 },
1320
  { BFD_RELOC_SH_GOTPLT_MEDLOW16, R_SH_GOTPLT_MEDLOW16 },
1321
  { BFD_RELOC_SH_GOTPLT_MEDHI16, R_SH_GOTPLT_MEDHI16 },
1322
  { BFD_RELOC_SH_GOTPLT_HI16, R_SH_GOTPLT_HI16 },
1323
  { BFD_RELOC_SH_PLT_LOW16, R_SH_PLT_LOW16 },
1324
  { BFD_RELOC_SH_PLT_MEDLOW16, R_SH_PLT_MEDLOW16 },
1325
  { BFD_RELOC_SH_PLT_MEDHI16, R_SH_PLT_MEDHI16 },
1326
  { BFD_RELOC_SH_PLT_HI16, R_SH_PLT_HI16 },
1327
  { BFD_RELOC_SH_GOTOFF_LOW16, R_SH_GOTOFF_LOW16 },
1328
  { BFD_RELOC_SH_GOTOFF_MEDLOW16, R_SH_GOTOFF_MEDLOW16 },
1329
  { BFD_RELOC_SH_GOTOFF_MEDHI16, R_SH_GOTOFF_MEDHI16 },
1330
  { BFD_RELOC_SH_GOTOFF_HI16, R_SH_GOTOFF_HI16 },
1331
  { BFD_RELOC_SH_GOTPC_LOW16, R_SH_GOTPC_LOW16 },
1332
  { BFD_RELOC_SH_GOTPC_MEDLOW16, R_SH_GOTPC_MEDLOW16 },
1333
  { BFD_RELOC_SH_GOTPC_MEDHI16, R_SH_GOTPC_MEDHI16 },
1334
  { BFD_RELOC_SH_GOTPC_HI16, R_SH_GOTPC_HI16 },
1335
  { BFD_RELOC_SH_COPY64, R_SH_COPY64 },
1336
  { BFD_RELOC_SH_GLOB_DAT64, R_SH_GLOB_DAT64 },
1337
  { BFD_RELOC_SH_JMP_SLOT64, R_SH_JMP_SLOT64 },
1338
  { BFD_RELOC_SH_RELATIVE64, R_SH_RELATIVE64 },
1339
  { BFD_RELOC_SH_GOT10BY4, R_SH_GOT10BY4 },
1340
  { BFD_RELOC_SH_GOT10BY8, R_SH_GOT10BY8 },
1341
  { BFD_RELOC_SH_GOTPLT10BY4, R_SH_GOTPLT10BY4 },
1342
  { BFD_RELOC_SH_GOTPLT10BY8, R_SH_GOTPLT10BY8 },
1343
  { BFD_RELOC_SH_PT_16, R_SH_PT_16 },
1344
  { BFD_RELOC_SH_SHMEDIA_CODE, R_SH_SHMEDIA_CODE },
1345
  { BFD_RELOC_SH_IMMU5, R_SH_DIR5U },
1346
  { BFD_RELOC_SH_IMMS6, R_SH_DIR6S },
1347
  { BFD_RELOC_SH_IMMU6, R_SH_DIR6U },
1348
  { BFD_RELOC_SH_IMMS10, R_SH_DIR10S },
1349
  { BFD_RELOC_SH_IMMS10BY2, R_SH_DIR10SW },
1350
  { BFD_RELOC_SH_IMMS10BY4, R_SH_DIR10SL },
1351
  { BFD_RELOC_SH_IMMS10BY8, R_SH_DIR10SQ },
1352
  { BFD_RELOC_SH_IMMS16, R_SH_IMMS16 },
1353
  { BFD_RELOC_SH_IMMU16, R_SH_IMMU16 },
1354
  { BFD_RELOC_SH_IMM_LOW16, R_SH_IMM_LOW16 },
1355
  { BFD_RELOC_SH_IMM_LOW16_PCREL, R_SH_IMM_LOW16_PCREL },
1356
  { BFD_RELOC_SH_IMM_MEDLOW16, R_SH_IMM_MEDLOW16 },
1357
  { BFD_RELOC_SH_IMM_MEDLOW16_PCREL, R_SH_IMM_MEDLOW16_PCREL },
1358
  { BFD_RELOC_SH_IMM_MEDHI16, R_SH_IMM_MEDHI16 },
1359
  { BFD_RELOC_SH_IMM_MEDHI16_PCREL, R_SH_IMM_MEDHI16_PCREL },
1360
  { BFD_RELOC_SH_IMM_HI16, R_SH_IMM_HI16 },
1361
  { BFD_RELOC_SH_IMM_HI16_PCREL, R_SH_IMM_HI16_PCREL },
1362
  { BFD_RELOC_64, R_SH_64 },
1363
  { BFD_RELOC_64_PCREL, R_SH_64_PCREL },
1364
};
1365
 
1366
/* Given a BFD reloc code, return the howto structure for the
1367
   corresponding SH ELf reloc.  */
1368
 
1369
static reloc_howto_type *
1370
sh_elf64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1371
                            bfd_reloc_code_real_type code)
1372
{
1373
  unsigned int i;
1374
 
1375
  for (i = 0; i < sizeof (sh64_reloc_map) / sizeof (struct elf_reloc_map); i++)
1376
    {
1377
      if (sh64_reloc_map[i].bfd_reloc_val == code)
1378
        return &sh_elf64_howto_table[(int) sh64_reloc_map[i].elf_reloc_val];
1379
    }
1380
 
1381
  return NULL;
1382
}
1383
 
1384
static reloc_howto_type *
1385
sh_elf64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1386
                            const char *r_name)
1387
{
1388
  unsigned int i;
1389
 
1390
  for (i = 0;
1391
       i < sizeof (sh_elf64_howto_table) / sizeof (sh_elf64_howto_table[0]);
1392
       i++)
1393
    if (sh_elf64_howto_table[i].name != NULL
1394
        && strcasecmp (sh_elf64_howto_table[i].name, r_name) == 0)
1395
      return &sh_elf64_howto_table[i];
1396
 
1397
  return NULL;
1398
}
1399
 
1400
/* Given an ELF reloc, fill in the howto field of a relent.
1401
 
1402
   See sh_elf_info_to_howto in elf32-sh.c for the original.  */
1403
 
1404
static void
1405
sh_elf64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
1406
                        Elf_Internal_Rela *dst)
1407
{
1408
  unsigned int r;
1409
 
1410
  r = ELF64_R_TYPE (dst->r_info);
1411
 
1412
  BFD_ASSERT (r <= (unsigned int) R_SH_64_PCREL);
1413
  BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC || r > R_SH_LAST_INVALID_RELOC);
1414
  BFD_ASSERT (r < R_SH_DIR8WPN || r > R_SH_LAST_INVALID_RELOC_2);
1415
  BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_3 || r > R_SH_GOTPLT32);
1416
  BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_4 || r > R_SH_LAST_INVALID_RELOC_4);
1417
 
1418
  cache_ptr->howto = &sh_elf64_howto_table[r];
1419
}
1420
 
1421
/* Relocate an SH ELF section.
1422
 
1423
   See sh_elf_info_to_howto in elf32-sh.c for the original.  */
1424
 
1425
static bfd_boolean
1426
sh_elf64_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
1427
                           struct bfd_link_info *info, bfd *input_bfd,
1428
                           asection *input_section, bfd_byte *contents,
1429
                           Elf_Internal_Rela *relocs,
1430
                           Elf_Internal_Sym *local_syms,
1431
                           asection **local_sections)
1432
{
1433
  Elf_Internal_Shdr *symtab_hdr;
1434
  struct elf_link_hash_entry **sym_hashes;
1435
  Elf_Internal_Rela *rel, *relend;
1436
  bfd *dynobj;
1437
  bfd_vma *local_got_offsets;
1438
  asection *sgot;
1439
  asection *sgotplt;
1440
  asection *splt;
1441
  asection *sreloc;
1442
  bfd_vma disp, dropped;
1443
 
1444
  symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1445
  sym_hashes = elf_sym_hashes (input_bfd);
1446
  dynobj = elf_hash_table (info)->dynobj;
1447
  local_got_offsets = elf_local_got_offsets (input_bfd);
1448
 
1449
  sgot = NULL;
1450
  sgotplt = NULL;
1451
  splt = NULL;
1452
  sreloc = NULL;
1453
 
1454
  rel = relocs;
1455
  relend = relocs + input_section->reloc_count;
1456
  for (; rel < relend; rel++)
1457
    {
1458
      int r_type;
1459
      reloc_howto_type *howto;
1460
      unsigned long r_symndx;
1461
      Elf_Internal_Sym *sym;
1462
      asection *sec;
1463
      struct elf_link_hash_entry *h;
1464
      bfd_vma relocation;
1465
      bfd_vma addend = (bfd_vma)0;
1466
      bfd_reloc_status_type r;
1467
      int seen_stt_datalabel = 0;
1468
 
1469
      r_symndx = ELF64_R_SYM (rel->r_info);
1470
 
1471
      r_type = ELF64_R_TYPE (rel->r_info);
1472
 
1473
      if (r_type == (int) R_SH_NONE)
1474
        continue;
1475
 
1476
      if (r_type < 0
1477
          || r_type > R_SH_64_PCREL
1478
          || (r_type >= (int) R_SH_FIRST_INVALID_RELOC
1479
              && r_type <= (int) R_SH_LAST_INVALID_RELOC)
1480
          || (r_type >= (int) R_SH_DIR8WPN
1481
              && r_type <= (int) R_SH_LAST_INVALID_RELOC)
1482
          || (r_type >= (int) R_SH_GNU_VTINHERIT
1483
              && r_type <= (int) R_SH_PSHL)
1484
          || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_2
1485
              && r_type <= R_SH_GOTPLT32)
1486
          || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_4
1487
              && r_type <= (int) R_SH_LAST_INVALID_RELOC_4))
1488
        {
1489
          bfd_set_error (bfd_error_bad_value);
1490
          return FALSE;
1491
        }
1492
 
1493
      howto = sh_elf64_howto_table + r_type;
1494
 
1495
      h = NULL;
1496
      sym = NULL;
1497
      sec = NULL;
1498
      relocation = 0;
1499
      if (r_symndx < symtab_hdr->sh_info)
1500
        {
1501
          sym = local_syms + r_symndx;
1502
          sec = local_sections[r_symndx];
1503
          relocation = ((sec->output_section->vma
1504
                         + sec->output_offset
1505
                         + sym->st_value)
1506
                        | ((sym->st_other & STO_SH5_ISA32) != 0));
1507
 
1508
          /* A local symbol never has STO_SH5_ISA32, so we don't need
1509
             datalabel processing here.  Make sure this does not change
1510
             without notice.  */
1511
          if ((sym->st_other & STO_SH5_ISA32) != 0)
1512
            ((*info->callbacks->reloc_dangerous)
1513
             (info,
1514
              _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
1515
              input_bfd, input_section, rel->r_offset));
1516
 
1517
          if (sec != NULL && elf_discarded_section (sec))
1518
            /* Handled below.  */
1519
            ;
1520
          else if (info->relocatable)
1521
            {
1522
              /* This is a relocatable link.  We don't have to change
1523
                 anything, unless the reloc is against a section symbol,
1524
                 in which case we have to adjust according to where the
1525
                 section symbol winds up in the output section.  */
1526
              if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
1527
                goto final_link_relocate;
1528
 
1529
              continue;
1530
            }
1531
          else if (! howto->partial_inplace)
1532
            {
1533
              relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
1534
              relocation |= ((sym->st_other & STO_SH5_ISA32) != 0);
1535
            }
1536
          else if ((sec->flags & SEC_MERGE)
1537
                   && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
1538
            {
1539
              asection *msec;
1540
 
1541
              if (howto->rightshift || howto->src_mask != 0xffffffff)
1542
                {
1543
                  (*_bfd_error_handler)
1544
                    (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
1545
                     input_bfd, input_section,
1546
                     (long) rel->r_offset, howto->name);
1547
                  return FALSE;
1548
                }
1549
 
1550
              addend = bfd_get_32 (input_bfd, contents + rel->r_offset);
1551
              msec = sec;
1552
              addend =
1553
                _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
1554
                - relocation;
1555
              addend += msec->output_section->vma + msec->output_offset;
1556
              bfd_put_32 (input_bfd, addend, contents + rel->r_offset);
1557
              addend = 0;
1558
            }
1559
        }
1560
      else
1561
        {
1562
          /* ??? Could we use the RELOC_FOR_GLOBAL_SYMBOL macro here ?  */
1563
 
1564
          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1565
          while (h->root.type == bfd_link_hash_indirect
1566
                 || h->root.type == bfd_link_hash_warning)
1567
            {
1568
              /* If the reference passes a symbol marked with
1569
                 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
1570
                 doesn't count.  */
1571
              seen_stt_datalabel |= h->type == STT_DATALABEL;
1572
              h = (struct elf_link_hash_entry *) h->root.u.i.link;
1573
            }
1574
 
1575
          if (h->root.type == bfd_link_hash_defined
1576
              || h->root.type == bfd_link_hash_defweak)
1577
            {
1578
              sec = h->root.u.def.section;
1579
              /* In these cases, we don't need the relocation value.
1580
                 We check specially because in some obscure cases
1581
                 sec->output_section will be NULL.  */
1582
              if (r_type == R_SH_GOTPC_LOW16
1583
                  || r_type == R_SH_GOTPC_MEDLOW16
1584
                  || r_type == R_SH_GOTPC_MEDHI16
1585
                  || r_type == R_SH_GOTPC_HI16
1586
                  || ((r_type == R_SH_PLT_LOW16
1587
                       || r_type == R_SH_PLT_MEDLOW16
1588
                       || r_type == R_SH_PLT_MEDHI16
1589
                       || r_type == R_SH_PLT_HI16)
1590
                      && h->plt.offset != (bfd_vma) -1)
1591
                  || ((r_type == R_SH_GOT_LOW16
1592
                       || r_type == R_SH_GOT_MEDLOW16
1593
                       || r_type == R_SH_GOT_MEDHI16
1594
                       || r_type == R_SH_GOT_HI16)
1595
                      && elf_hash_table (info)->dynamic_sections_created
1596
                      && (! info->shared
1597
                          || (! info->symbolic && h->dynindx != -1)
1598
                          || !h->def_regular))
1599
                  /* The cases above are those in which relocation is
1600
                     overwritten in the switch block below.  The cases
1601
                     below are those in which we must defer relocation
1602
                     to run-time, because we can't resolve absolute
1603
                     addresses when creating a shared library.  */
1604
                  || (info->shared
1605
                      && ((! info->symbolic && h->dynindx != -1)
1606
                          || !h->def_regular)
1607
                      && ((r_type == R_SH_64
1608
                           && !(ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
1609
                                || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN))
1610
                          || r_type == R_SH_64_PCREL)
1611
                      && ((input_section->flags & SEC_ALLOC) != 0
1612
                          /* DWARF will emit R_SH_DIR32 relocations in its
1613
                             sections against symbols defined externally
1614
                             in shared libraries.  We can't do anything
1615
                             with them here.  */
1616
                          || (input_section->flags & SEC_DEBUGGING) != 0))
1617
                  /* Dynamic relocs are not propagated for SEC_DEBUGGING
1618
                     sections because such sections are not SEC_ALLOC and
1619
                     thus ld.so will not process them.  */
1620
                  || (sec->output_section == NULL
1621
                      && ((input_section->flags & SEC_DEBUGGING) != 0
1622
                          && h->def_dynamic)))
1623
                ;
1624
              else if (sec->output_section != NULL)
1625
                relocation = ((h->root.u.def.value
1626
                               + sec->output_section->vma
1627
                               + sec->output_offset)
1628
                              /* A STO_SH5_ISA32 causes a "bitor 1" to the
1629
                                 symbol value, unless we've seen
1630
                                 STT_DATALABEL on the way to it.  */
1631
                              | ((h->other & STO_SH5_ISA32) != 0
1632
                                 && ! seen_stt_datalabel));
1633
              else if (!info->relocatable)
1634
                {
1635
                  (*_bfd_error_handler)
1636
                    (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
1637
                     input_bfd,
1638
                     input_section,
1639
                     (long) rel->r_offset,
1640
                     howto->name,
1641
                     h->root.root.string);
1642
                }
1643
            }
1644
          else if (h->root.type == bfd_link_hash_undefweak)
1645
            ;
1646
          else if (info->unresolved_syms_in_objects == RM_IGNORE
1647
                   && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
1648
            ;
1649
          else if (!info->relocatable)
1650
            {
1651
              if (! ((*info->callbacks->undefined_symbol)
1652
                     (info, h->root.root.string, input_bfd,
1653
                      input_section, rel->r_offset,
1654
                      (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
1655
                       || ELF_ST_VISIBILITY (h->other)))))
1656
                return FALSE;
1657
            }
1658
        }
1659
 
1660
      if (sec != NULL && elf_discarded_section (sec))
1661
        {
1662
          /* For relocs against symbols from removed linkonce sections,
1663
             or sections discarded by a linker script, we just want the
1664
             section contents zeroed.  Avoid any special processing.  */
1665
          _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
1666
          rel->r_info = 0;
1667
          rel->r_addend = 0;
1668
          continue;
1669
        }
1670
 
1671
      if (info->relocatable)
1672
        continue;
1673
 
1674
      disp = (relocation
1675
              - input_section->output_section->vma
1676
              - input_section->output_offset
1677
              - rel->r_offset);
1678
      dropped = 0;
1679
      switch ((int)r_type)
1680
        {
1681
        case R_SH_PT_16:     dropped = disp & 2; break;
1682
        case R_SH_DIR10SW: dropped = disp & 1; break;
1683
        case R_SH_DIR10SL: dropped = disp & 3; break;
1684
        case R_SH_DIR10SQ: dropped = disp & 7; break;
1685
        }
1686
      if (dropped != 0)
1687
        {
1688
          (*_bfd_error_handler)
1689
            (_("%s: error: unaligned relocation type %d at %08x reloc %08x\n"),
1690
             bfd_get_filename (input_bfd), (int)r_type, (unsigned)rel->r_offset, (unsigned)relocation);
1691
          bfd_set_error (bfd_error_bad_value);
1692
          return FALSE;
1693
        }
1694
      switch ((int)r_type)
1695
        {
1696
        case R_SH_64:
1697
        case R_SH_64_PCREL:
1698
          if (info->shared
1699
              && (input_section->flags & SEC_ALLOC) != 0
1700
              && (r_type != R_SH_64_PCREL
1701
                  || (h != NULL
1702
                      && h->dynindx != -1
1703
                      && (! info->symbolic
1704
                          || !h->def_regular))))
1705
            {
1706
              Elf_Internal_Rela outrel;
1707
              bfd_byte *loc;
1708
              bfd_boolean skip, relocate;
1709
 
1710
              /* When generating a shared object, these relocations
1711
                 are copied into the output file to be resolved at run
1712
                 time.  */
1713
 
1714
              if (sreloc == NULL)
1715
                {
1716
                  sreloc = _bfd_elf_get_dynamic_reloc_section
1717
                    (input_bfd, input_section, /*rela?*/ TRUE);
1718
                  if (sreloc == NULL)
1719
                    return FALSE;
1720
                }
1721
 
1722
              skip = FALSE;
1723
              relocate = FALSE;
1724
 
1725
              outrel.r_offset
1726
                = _bfd_elf_section_offset (output_bfd, info,
1727
                                           input_section, rel->r_offset);
1728
 
1729
              if (outrel.r_offset == (bfd_vma) -1)
1730
                skip = TRUE;
1731
              else if (outrel.r_offset == (bfd_vma) -2)
1732
                skip = TRUE, relocate = TRUE;
1733
 
1734
              outrel.r_offset += (input_section->output_section->vma
1735
                                  + input_section->output_offset);
1736
 
1737
              if (skip)
1738
                memset (&outrel, 0, sizeof outrel);
1739
              else if (r_type == R_SH_64_PCREL)
1740
                {
1741
                  BFD_ASSERT (h != NULL && h->dynindx != -1);
1742
                  outrel.r_info = ELF64_R_INFO (h->dynindx, R_SH_64_PCREL);
1743
                  outrel.r_addend = rel->r_addend;
1744
                }
1745
              else
1746
                {
1747
                  /* h->dynindx may be -1 if this symbol was marked to
1748
                     become local.  */
1749
                  if (h == NULL
1750
                      || ((info->symbolic || h->dynindx == -1)
1751
                          && h->def_regular))
1752
                    {
1753
                      relocate = TRUE;
1754
                      outrel.r_info = ELF64_R_INFO (0, R_SH_RELATIVE64);
1755
                      outrel.r_addend = relocation + rel->r_addend;
1756
                    }
1757
                  else
1758
                    {
1759
                      BFD_ASSERT (h->dynindx != -1);
1760
                      outrel.r_info = ELF64_R_INFO (h->dynindx, R_SH_64);
1761
                      outrel.r_addend = relocation + rel->r_addend;
1762
                    }
1763
                }
1764
 
1765
              loc = sreloc->contents;
1766
              loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
1767
              bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
1768
 
1769
              /* If this reloc is against an external symbol, we do
1770
                 not want to fiddle with the addend.  Otherwise, we
1771
                 need to include the symbol value so that it becomes
1772
                 an addend for the dynamic reloc.  */
1773
              if (! relocate)
1774
                continue;
1775
            }
1776
          else if (r_type == R_SH_64)
1777
            addend = rel->r_addend;
1778
          goto final_link_relocate;
1779
 
1780
        case R_SH_GOTPLT_LOW16:
1781
        case R_SH_GOTPLT_MEDLOW16:
1782
        case R_SH_GOTPLT_MEDHI16:
1783
        case R_SH_GOTPLT_HI16:
1784
        case R_SH_GOTPLT10BY4:
1785
        case R_SH_GOTPLT10BY8:
1786
          /* Relocation is to the entry for this symbol in the
1787
             procedure linkage table.  */
1788
 
1789
          if (h == NULL
1790
              || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
1791
              || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
1792
              || ! info->shared
1793
              || info->symbolic
1794
              || h->dynindx == -1
1795
              || h->plt.offset == (bfd_vma) -1
1796
              || h->got.offset != (bfd_vma) -1)
1797
            goto force_got;
1798
 
1799
          /* Relocation is to the entry for this symbol in the global
1800
             offset table extension for the procedure linkage table.  */
1801
          if (sgotplt == NULL)
1802
            {
1803
              sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
1804
              BFD_ASSERT (sgotplt != NULL);
1805
            }
1806
 
1807
          relocation = (sgotplt->output_offset
1808
                        + ((h->plt.offset / elf_sh64_sizeof_plt (info)
1809
                            - 1 + 3) * 8));
1810
 
1811
          relocation -= GOT_BIAS;
1812
 
1813
          goto final_link_relocate;
1814
 
1815
        force_got:
1816
        case R_SH_GOT_LOW16:
1817
        case R_SH_GOT_MEDLOW16:
1818
        case R_SH_GOT_MEDHI16:
1819
        case R_SH_GOT_HI16:
1820
        case R_SH_GOT10BY4:
1821
        case R_SH_GOT10BY8:
1822
          /* Relocation is to the entry for this symbol in the global
1823
             offset table.  */
1824
          if (sgot == NULL)
1825
            {
1826
              sgot = bfd_get_section_by_name (dynobj, ".got");
1827
              BFD_ASSERT (sgot != NULL);
1828
            }
1829
 
1830
          if (h != NULL)
1831
            {
1832
              bfd_vma off;
1833
 
1834
              off = h->got.offset;
1835
              if (seen_stt_datalabel)
1836
                {
1837
                  struct elf_sh64_link_hash_entry *hsh;
1838
 
1839
                  hsh = (struct elf_sh64_link_hash_entry *)h;
1840
                  off = hsh->datalabel_got_offset;
1841
                }
1842
              BFD_ASSERT (off != (bfd_vma) -1);
1843
 
1844
              if (! elf_hash_table (info)->dynamic_sections_created
1845
                  || (info->shared
1846
                      && (info->symbolic || h->dynindx == -1
1847
                          || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
1848
                          || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
1849
                      && h->def_regular))
1850
                {
1851
                  /* This is actually a static link, or it is a
1852
                     -Bsymbolic link and the symbol is defined
1853
                     locally, or the symbol was forced to be local
1854
                     because of a version file.  We must initialize
1855
                     this entry in the global offset table.  Since the
1856
                     offset must always be a multiple of 4, we use the
1857
                     least significant bit to record whether we have
1858
                     initialized it already.
1859
 
1860
                     When doing a dynamic link, we create a .rela.got
1861
                     relocation entry to initialize the value.  This
1862
                     is done in the finish_dynamic_symbol routine.  */
1863
                  if ((off & 1) != 0)
1864
                    off &= ~1;
1865
                  else
1866
                    {
1867
                      bfd_put_64 (output_bfd, relocation,
1868
                                  sgot->contents + off);
1869
                      if (seen_stt_datalabel)
1870
                        {
1871
                          struct elf_sh64_link_hash_entry *hsh;
1872
 
1873
                          hsh = (struct elf_sh64_link_hash_entry *)h;
1874
                          hsh->datalabel_got_offset |= 1;
1875
                        }
1876
                      else
1877
                        h->got.offset |= 1;
1878
                    }
1879
                }
1880
 
1881
              relocation = sgot->output_offset + off;
1882
            }
1883
          else
1884
            {
1885
              bfd_vma off;
1886
 
1887
              if (rel->r_addend)
1888
                {
1889
                  BFD_ASSERT (local_got_offsets != NULL
1890
                              && (local_got_offsets[symtab_hdr->sh_info
1891
                                                    + r_symndx]
1892
                                  != (bfd_vma) -1));
1893
 
1894
                  off = local_got_offsets[symtab_hdr->sh_info
1895
                                          + r_symndx];
1896
                }
1897
              else
1898
                {
1899
                  BFD_ASSERT (local_got_offsets != NULL
1900
                              && local_got_offsets[r_symndx] != (bfd_vma) -1);
1901
 
1902
                  off = local_got_offsets[r_symndx];
1903
                }
1904
 
1905
              /* The offset must always be a multiple of 8.  We use
1906
                 the least significant bit to record whether we have
1907
                 already generated the necessary reloc.  */
1908
              if ((off & 1) != 0)
1909
                off &= ~1;
1910
              else
1911
                {
1912
                  bfd_put_64 (output_bfd, relocation, sgot->contents + off);
1913
 
1914
                  if (info->shared)
1915
                    {
1916
                      asection *s;
1917
                      Elf_Internal_Rela outrel;
1918
                      bfd_byte *loc;
1919
 
1920
                      s = bfd_get_section_by_name (dynobj, ".rela.got");
1921
                      BFD_ASSERT (s != NULL);
1922
 
1923
                      outrel.r_offset = (sgot->output_section->vma
1924
                                         + sgot->output_offset
1925
                                         + off);
1926
                      outrel.r_info = ELF64_R_INFO (0, R_SH_RELATIVE64);
1927
                      outrel.r_addend = relocation;
1928
                      loc = s->contents;
1929
                      loc += s->reloc_count++ * sizeof (Elf64_External_Rela);
1930
                      bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
1931
                    }
1932
 
1933
                  if (rel->r_addend)
1934
                    local_got_offsets[symtab_hdr->sh_info + r_symndx] |= 1;
1935
                  else
1936
                    local_got_offsets[r_symndx] |= 1;
1937
                }
1938
 
1939
              relocation = sgot->output_offset + off;
1940
            }
1941
 
1942
          relocation -= GOT_BIAS;
1943
 
1944
          goto final_link_relocate;
1945
 
1946
        case R_SH_GOTOFF_LOW16:
1947
        case R_SH_GOTOFF_MEDLOW16:
1948
        case R_SH_GOTOFF_MEDHI16:
1949
        case R_SH_GOTOFF_HI16:
1950
          /* Relocation is relative to the start of the global offset
1951
             table.  */
1952
 
1953
          if (sgot == NULL)
1954
            {
1955
              sgot = bfd_get_section_by_name (dynobj, ".got");
1956
              BFD_ASSERT (sgot != NULL);
1957
            }
1958
 
1959
          /* Note that sgot->output_offset is not involved in this
1960
             calculation.  We always want the start of .got.  If we
1961
             defined _GLOBAL_OFFSET_TABLE in a different way, as is
1962
             permitted by the ABI, we might have to change this
1963
             calculation.  */
1964
          relocation -= sgot->output_section->vma;
1965
 
1966
          relocation -= GOT_BIAS;
1967
 
1968
          addend = rel->r_addend;
1969
 
1970
          goto final_link_relocate;
1971
 
1972
        case R_SH_GOTPC_LOW16:
1973
        case R_SH_GOTPC_MEDLOW16:
1974
        case R_SH_GOTPC_MEDHI16:
1975
        case R_SH_GOTPC_HI16:
1976
          /* Use global offset table as symbol value.  */
1977
 
1978
          if (sgot == NULL)
1979
            {
1980
              sgot = bfd_get_section_by_name (dynobj, ".got");
1981
              BFD_ASSERT (sgot != NULL);
1982
            }
1983
 
1984
          relocation = sgot->output_section->vma;
1985
 
1986
          relocation += GOT_BIAS;
1987
 
1988
          addend = rel->r_addend;
1989
 
1990
          goto final_link_relocate;
1991
 
1992
        case R_SH_PLT_LOW16:
1993
        case R_SH_PLT_MEDLOW16:
1994
        case R_SH_PLT_MEDHI16:
1995
        case R_SH_PLT_HI16:
1996
          /* Relocation is to the entry for this symbol in the
1997
             procedure linkage table.  */
1998
 
1999
          /* Resolve a PLT reloc against a local symbol directly,
2000
             without using the procedure linkage table.  */
2001
          if (h == NULL)
2002
            goto final_link_relocate;
2003
 
2004
          if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
2005
              || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
2006
            goto final_link_relocate;
2007
 
2008
          if (h->plt.offset == (bfd_vma) -1)
2009
            {
2010
              /* We didn't make a PLT entry for this symbol.  This
2011
                 happens when statically linking PIC code, or when
2012
                 using -Bsymbolic.  */
2013
              goto final_link_relocate;
2014
            }
2015
 
2016
          if (splt == NULL)
2017
            {
2018
              splt = bfd_get_section_by_name (dynobj, ".plt");
2019
              BFD_ASSERT (splt != NULL);
2020
            }
2021
 
2022
          relocation = (splt->output_section->vma
2023
                        + splt->output_offset
2024
                        + h->plt.offset);
2025
          relocation++;
2026
 
2027
          addend = rel->r_addend;
2028
 
2029
          goto final_link_relocate;
2030
 
2031
        case R_SH_DIR32:
2032
        case R_SH_SHMEDIA_CODE:
2033
        case R_SH_PT_16:
2034
        case R_SH_DIR5U:
2035
        case R_SH_DIR6S:
2036
        case R_SH_DIR6U:
2037
        case R_SH_DIR10S:
2038
        case R_SH_DIR10SW:
2039
        case R_SH_DIR10SL:
2040
        case R_SH_DIR10SQ:
2041
        case R_SH_IMMS16:
2042
        case R_SH_IMMU16:
2043
        case R_SH_IMM_LOW16:
2044
        case R_SH_IMM_LOW16_PCREL:
2045
        case R_SH_IMM_MEDLOW16:
2046
        case R_SH_IMM_MEDLOW16_PCREL:
2047
        case R_SH_IMM_MEDHI16:
2048
        case R_SH_IMM_MEDHI16_PCREL:
2049
        case R_SH_IMM_HI16:
2050
        case R_SH_IMM_HI16_PCREL:
2051
          addend = rel->r_addend;
2052
          /* Fall through.  */
2053
        case R_SH_REL32:
2054
        final_link_relocate:
2055
          r = _bfd_final_link_relocate (howto, input_bfd, input_section,
2056
                                        contents, rel->r_offset,
2057
                                        relocation, addend);
2058
          break;
2059
 
2060
        default:
2061
          bfd_set_error (bfd_error_bad_value);
2062
          return FALSE;
2063
 
2064
        }
2065
 
2066
      if (r != bfd_reloc_ok)
2067
        {
2068
          switch (r)
2069
            {
2070
            default:
2071
            case bfd_reloc_outofrange:
2072
              abort ();
2073
            case bfd_reloc_overflow:
2074
              {
2075
                const char *name;
2076
 
2077
                if (h != NULL)
2078
                  name = NULL;
2079
                else
2080
                  {
2081
                    name = (bfd_elf_string_from_elf_section
2082
                            (input_bfd, symtab_hdr->sh_link, sym->st_name));
2083
                    if (name == NULL)
2084
                      return FALSE;
2085
                    if (*name == '\0')
2086
                      name = bfd_section_name (input_bfd, sec);
2087
                  }
2088
                if (! ((*info->callbacks->reloc_overflow)
2089
                       (info, (h ? &h->root : NULL), name, howto->name,
2090
                        (bfd_vma) 0, input_bfd, input_section,
2091
                        rel->r_offset)))
2092
                  return FALSE;
2093
              }
2094
              break;
2095
            }
2096
        }
2097
    }
2098
 
2099
  return TRUE;
2100
}
2101
 
2102
/* This is a version of bfd_generic_get_relocated_section_contents
2103
   that uses sh_elf64_relocate_section.
2104
 
2105
   See sh_elf_relocate_section in elf32-sh.c for the original.  */
2106
 
2107
static bfd_byte *
2108
sh_elf64_get_relocated_section_contents (bfd *output_bfd,
2109
                                         struct bfd_link_info *link_info,
2110
                                         struct bfd_link_order *link_order,
2111
                                         bfd_byte *data,
2112
                                         bfd_boolean relocatable,
2113
                                         asymbol **symbols)
2114
{
2115
  Elf_Internal_Shdr *symtab_hdr;
2116
  asection *input_section = link_order->u.indirect.section;
2117
  bfd *input_bfd = input_section->owner;
2118
  asection **sections = NULL;
2119
  Elf_Internal_Rela *internal_relocs = NULL;
2120
  Elf_Internal_Sym *isymbuf = NULL;
2121
 
2122
  /* We only need to handle the case of relaxing, or of having a
2123
     particular set of section contents, specially.  */
2124
  if (relocatable
2125
      || elf_section_data (input_section)->this_hdr.contents == NULL)
2126
    return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
2127
                                                       link_order, data,
2128
                                                       relocatable,
2129
                                                       symbols);
2130
 
2131
  symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2132
 
2133
  memcpy (data, elf_section_data (input_section)->this_hdr.contents,
2134
          input_section->size);
2135
 
2136
  if ((input_section->flags & SEC_RELOC) != 0
2137
      && input_section->reloc_count > 0)
2138
    {
2139
      Elf_Internal_Sym *isymp;
2140
      Elf_Internal_Sym *isymend;
2141
      asection **secpp;
2142
 
2143
      /* Read this BFD's local symbols.  */
2144
      if (symtab_hdr->sh_info != 0)
2145
        {
2146
          isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
2147
          if (isymbuf == NULL)
2148
            isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
2149
                                            symtab_hdr->sh_info, 0,
2150
                                            NULL, NULL, NULL);
2151
          if (isymbuf == NULL)
2152
            goto error_return;
2153
        }
2154
 
2155
      internal_relocs = (_bfd_elf_link_read_relocs
2156
                         (input_bfd, input_section, NULL,
2157
                          (Elf_Internal_Rela *) NULL, FALSE));
2158
      if (internal_relocs == NULL)
2159
        goto error_return;
2160
 
2161
      sections = (asection **) bfd_malloc (symtab_hdr->sh_info
2162
                                           * sizeof (asection *));
2163
      if (sections == NULL && symtab_hdr->sh_info > 0)
2164
        goto error_return;
2165
 
2166
      secpp = sections;
2167
      isymend = isymbuf + symtab_hdr->sh_info;
2168
      for (isymp = isymbuf; isymp < isymend; ++isymp, ++secpp)
2169
        {
2170
          asection *isec;
2171
 
2172
          if (isymp->st_shndx == SHN_UNDEF)
2173
            isec = bfd_und_section_ptr;
2174
          else if (isymp->st_shndx == SHN_ABS)
2175
            isec = bfd_abs_section_ptr;
2176
          else if (isymp->st_shndx == SHN_COMMON)
2177
            isec = bfd_com_section_ptr;
2178
          else
2179
            isec = bfd_section_from_elf_index (input_bfd, isymp->st_shndx);
2180
 
2181
          *secpp = isec;
2182
        }
2183
 
2184
      if (! sh_elf64_relocate_section (output_bfd, link_info, input_bfd,
2185
                                       input_section, data, internal_relocs,
2186
                                       isymbuf, sections))
2187
        goto error_return;
2188
 
2189
      if (sections != NULL)
2190
        free (sections);
2191
      if (internal_relocs != elf_section_data (input_section)->relocs)
2192
        free (internal_relocs);
2193
      if (isymbuf != NULL
2194
          && (unsigned char *) isymbuf != symtab_hdr->contents)
2195
        free (isymbuf);
2196
    }
2197
 
2198
  return data;
2199
 
2200
 error_return:
2201
  if (sections != NULL)
2202
    free (sections);
2203
  if (internal_relocs != NULL
2204
      && internal_relocs != elf_section_data (input_section)->relocs)
2205
    free (internal_relocs);
2206
  if (isymbuf != NULL
2207
      && (unsigned char *) isymbuf != symtab_hdr->contents)
2208
    free (isymbuf);
2209
  return NULL;
2210
}
2211
 
2212
/* Set the SHF_SH5_ISA32 flag for ISA SHmedia code sections.  */
2213
 
2214
static bfd_boolean
2215
sh64_elf64_fake_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
2216
                          Elf_Internal_Shdr *elf_section_hdr,
2217
                          asection *asect)
2218
{
2219
  /* Code sections can only contain SH64 code, so mark them as such.  */
2220
  if (bfd_get_section_flags (output_bfd, asect) & SEC_CODE)
2221
    elf_section_hdr->sh_flags |= SHF_SH5_ISA32;
2222
 
2223
  return TRUE;
2224
}
2225
 
2226
static bfd_boolean
2227
sh_elf64_set_mach_from_flags (bfd *abfd)
2228
{
2229
  flagword flags = elf_elfheader (abfd)->e_flags;
2230
 
2231
  switch (flags & EF_SH_MACH_MASK)
2232
    {
2233
    case EF_SH5:
2234
      /* Just one, but keep the switch construct to make additions easy.  */
2235
      bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh5);
2236
      break;
2237
 
2238
    default:
2239
      bfd_set_error (bfd_error_wrong_format);
2240
      return FALSE;
2241
    }
2242
  return TRUE;
2243
}
2244
 
2245
/* Function to keep SH64 specific file flags.
2246
 
2247
   See sh64_elf_set_private_flags in elf32-sh64.c for the original.  */
2248
 
2249
static bfd_boolean
2250
sh_elf64_set_private_flags (bfd *abfd, flagword flags)
2251
{
2252
  BFD_ASSERT (! elf_flags_init (abfd)
2253
              || elf_elfheader (abfd)->e_flags == flags);
2254
 
2255
  elf_elfheader (abfd)->e_flags = flags;
2256
  elf_flags_init (abfd) = TRUE;
2257
  return sh_elf64_set_mach_from_flags (abfd);
2258
}
2259
 
2260
/* Copy the SHF_SH5_ISA32 attribute that we keep on all sections with
2261
   code, to keep attributes the same as for SHmedia in 32-bit ELF.  */
2262
 
2263
static bfd_boolean
2264
sh_elf64_copy_private_data_internal (bfd *ibfd, bfd *obfd)
2265
{
2266
  Elf_Internal_Shdr **o_shdrp;
2267
  asection *isec;
2268
  asection *osec;
2269
 
2270
  if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
2271
      || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
2272
    return TRUE;
2273
 
2274
  o_shdrp = elf_elfsections (obfd);
2275
  for (osec = obfd->sections; osec; osec = osec->next)
2276
    {
2277
      int oIndex = ((struct bfd_elf_section_data *) elf_section_data (osec))->this_idx;
2278
      for (isec = ibfd->sections; isec; isec = isec->next)
2279
        {
2280
          if (strcmp (osec->name, isec->name) == 0)
2281
            {
2282
              /* Note that we're not disallowing mixing data and code.  */
2283
              if ((elf_section_data (isec)->this_hdr.sh_flags
2284
                   & SHF_SH5_ISA32) != 0)
2285
                o_shdrp[oIndex]->sh_flags |= SHF_SH5_ISA32;
2286
              break;
2287
            }
2288
        }
2289
    }
2290
 
2291
  /* Copy object attributes.  */
2292
  _bfd_elf_copy_obj_attributes (ibfd, obfd);
2293
 
2294
  return sh_elf64_set_private_flags (obfd, elf_elfheader (ibfd)->e_flags);
2295
}
2296
 
2297
static bfd_boolean
2298
sh_elf64_copy_private_data (bfd *ibfd, bfd *obfd)
2299
{
2300
  return sh_elf64_copy_private_data_internal (ibfd, obfd);
2301
}
2302
 
2303
static bfd_boolean
2304
sh_elf64_merge_private_data (bfd *ibfd, bfd *obfd)
2305
{
2306
  flagword old_flags, new_flags;
2307
 
2308
  if (! _bfd_generic_verify_endian_match (ibfd, obfd))
2309
    return FALSE;
2310
 
2311
  if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour
2312
      || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
2313
    return TRUE;
2314
 
2315
  if (bfd_get_arch_size (ibfd) != bfd_get_arch_size (obfd))
2316
    {
2317
      const char *msg;
2318
 
2319
      if (bfd_get_arch_size (ibfd) == 32
2320
          && bfd_get_arch_size (obfd) == 64)
2321
        msg = _("%s: compiled as 32-bit object and %s is 64-bit");
2322
      else if (bfd_get_arch_size (ibfd) == 64
2323
               && bfd_get_arch_size (obfd) == 32)
2324
        msg = _("%s: compiled as 64-bit object and %s is 32-bit");
2325
      else
2326
        msg = _("%s: object size does not match that of target %s");
2327
 
2328
      (*_bfd_error_handler) (msg, bfd_get_filename (ibfd),
2329
                             bfd_get_filename (obfd));
2330
      bfd_set_error (bfd_error_wrong_format);
2331
      return FALSE;
2332
    }
2333
 
2334
  old_flags = elf_elfheader (obfd)->e_flags;
2335
  new_flags = elf_elfheader (ibfd)->e_flags;
2336
  if (! elf_flags_init (obfd))
2337
    {
2338
      /* This happens when ld starts out with a 'blank' output file.  */
2339
      elf_flags_init (obfd) = TRUE;
2340
      elf_elfheader (obfd)->e_flags = old_flags = new_flags;
2341
    }
2342
  /* We don't allow linking in anything else than SH64 code, and since
2343
     this is a 64-bit ELF, we assume the 64-bit ABI is used.  Add code
2344
     here as things change.  */
2345
  else if ((new_flags & EF_SH_MACH_MASK) != EF_SH5)
2346
    {
2347
      (*_bfd_error_handler)
2348
        ("%s: does not use the SH64 64-bit ABI as previous modules do",
2349
         bfd_get_filename (ibfd));
2350
      bfd_set_error (bfd_error_bad_value);
2351
      return FALSE;
2352
    }
2353
 
2354
  sh_elf64_copy_private_data_internal (ibfd, obfd);
2355
 
2356
  /* I can't think of anything sane other than old_flags being EF_SH5 and
2357
     that we need to preserve that.  */
2358
  elf_elfheader (obfd)->e_flags = old_flags;
2359
 
2360
  return sh_elf64_set_mach_from_flags (obfd);
2361
}
2362
 
2363
/* Return the section that should be marked against GC for a given
2364
   relocation.  */
2365
 
2366
static asection *
2367
sh_elf64_gc_mark_hook (asection *sec,
2368
                       struct bfd_link_info *info,
2369
                       Elf_Internal_Rela *rel,
2370
                       struct elf_link_hash_entry *h,
2371
                       Elf_Internal_Sym *sym)
2372
{
2373
  if (h != NULL)
2374
    switch (ELF64_R_TYPE (rel->r_info))
2375
      {
2376
      case R_SH_GNU_VTINHERIT:
2377
      case R_SH_GNU_VTENTRY:
2378
        return NULL;
2379
      }
2380
 
2381
  return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
2382
}
2383
 
2384
/* Look through the relocs for a section during the first phase.
2385
   Since we don't do .gots or .plts, we just need to consider the
2386
   virtual table relocs for gc.  */
2387
 
2388
static bfd_boolean
2389
sh_elf64_check_relocs (bfd *abfd, struct bfd_link_info *info,
2390
                       asection *sec, const Elf_Internal_Rela *relocs)
2391
{
2392
  Elf_Internal_Shdr *symtab_hdr;
2393
  struct elf_link_hash_entry **sym_hashes;
2394
  const Elf_Internal_Rela *rel;
2395
  const Elf_Internal_Rela *rel_end;
2396
  bfd *dynobj;
2397
  bfd_vma *local_got_offsets;
2398
  asection *sgot;
2399
  asection *srelgot;
2400
  asection *sreloc;
2401
 
2402
  sgot = NULL;
2403
  srelgot = NULL;
2404
  sreloc = NULL;
2405
 
2406
  if (info->relocatable)
2407
    return TRUE;
2408
 
2409
  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2410
  sym_hashes = elf_sym_hashes (abfd);
2411
 
2412
  dynobj = elf_hash_table (info)->dynobj;
2413
  local_got_offsets = elf_local_got_offsets (abfd);
2414
 
2415
  rel_end = relocs + sec->reloc_count;
2416
  for (rel = relocs; rel < rel_end; rel++)
2417
    {
2418
      struct elf_link_hash_entry *h;
2419
      unsigned long r_symndx;
2420
 
2421
      r_symndx = ELF64_R_SYM (rel->r_info);
2422
      if (r_symndx < symtab_hdr->sh_info)
2423
        h = NULL;
2424
      else
2425
        {
2426
          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2427
          while (h->root.type == bfd_link_hash_indirect
2428
                 || h->root.type == bfd_link_hash_warning)
2429
            h = (struct elf_link_hash_entry *) h->root.u.i.link;
2430
        }
2431
 
2432
      /* Some relocs require a global offset table.  */
2433
      if (dynobj == NULL)
2434
        {
2435
          switch (ELF64_R_TYPE (rel->r_info))
2436
            {
2437
            case R_SH_GOTPLT_LOW16:
2438
            case R_SH_GOTPLT_MEDLOW16:
2439
            case R_SH_GOTPLT_MEDHI16:
2440
            case R_SH_GOTPLT_HI16:
2441
            case R_SH_GOTPLT10BY4:
2442
            case R_SH_GOTPLT10BY8:
2443
            case R_SH_GOT_LOW16:
2444
            case R_SH_GOT_MEDLOW16:
2445
            case R_SH_GOT_MEDHI16:
2446
            case R_SH_GOT_HI16:
2447
            case R_SH_GOT10BY4:
2448
            case R_SH_GOT10BY8:
2449
            case R_SH_GOTOFF_LOW16:
2450
            case R_SH_GOTOFF_MEDLOW16:
2451
            case R_SH_GOTOFF_MEDHI16:
2452
            case R_SH_GOTOFF_HI16:
2453
            case R_SH_GOTPC_LOW16:
2454
            case R_SH_GOTPC_MEDLOW16:
2455
            case R_SH_GOTPC_MEDHI16:
2456
            case R_SH_GOTPC_HI16:
2457
              elf_hash_table (info)->dynobj = dynobj = abfd;
2458
              if (! _bfd_elf_create_got_section (dynobj, info))
2459
                return FALSE;
2460
              break;
2461
 
2462
            default:
2463
              break;
2464
            }
2465
        }
2466
 
2467
      switch (ELF64_R_TYPE (rel->r_info))
2468
        {
2469
          /* This relocation describes the C++ object vtable hierarchy.
2470
             Reconstruct it for later use during GC.  */
2471
        case R_SH_GNU_VTINHERIT:
2472
          if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2473
            return FALSE;
2474
          break;
2475
 
2476
          /* This relocation describes which C++ vtable entries are actually
2477
             used.  Record for later use during GC.  */
2478
        case R_SH_GNU_VTENTRY:
2479
          BFD_ASSERT (h != NULL);
2480
          if (h != NULL
2481
              && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2482
            return FALSE;
2483
          break;
2484
 
2485
        force_got:
2486
        case R_SH_GOT_LOW16:
2487
        case R_SH_GOT_MEDLOW16:
2488
        case R_SH_GOT_MEDHI16:
2489
        case R_SH_GOT_HI16:
2490
        case R_SH_GOT10BY4:
2491
        case R_SH_GOT10BY8:
2492
          /* This symbol requires a global offset table entry.  */
2493
 
2494
          if (sgot == NULL)
2495
            {
2496
              sgot = bfd_get_section_by_name (dynobj, ".got");
2497
              BFD_ASSERT (sgot != NULL);
2498
            }
2499
 
2500
          if (srelgot == NULL
2501
              && (h != NULL || info->shared))
2502
            {
2503
              srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
2504
              if (srelgot == NULL)
2505
                {
2506
                  srelgot = bfd_make_section_with_flags (dynobj,
2507
                                                         ".rela.got",
2508
                                                         (SEC_ALLOC
2509
                                                          | SEC_LOAD
2510
                                                          | SEC_HAS_CONTENTS
2511
                                                          | SEC_IN_MEMORY
2512
                                                          | SEC_LINKER_CREATED
2513
                                                          | SEC_READONLY));
2514
                  if (srelgot == NULL
2515
                      || ! bfd_set_section_alignment (dynobj, srelgot, 2))
2516
                    return FALSE;
2517
                }
2518
            }
2519
 
2520
          if (h != NULL)
2521
            {
2522
              if (h->type == STT_DATALABEL)
2523
                {
2524
                  struct elf_sh64_link_hash_entry *hsh;
2525
 
2526
                  h = (struct elf_link_hash_entry *) h->root.u.i.link;
2527
                  hsh = (struct elf_sh64_link_hash_entry *)h;
2528
                  if (hsh->datalabel_got_offset != (bfd_vma) -1)
2529
                    break;
2530
 
2531
                  hsh->datalabel_got_offset = sgot->size;
2532
                }
2533
              else
2534
                {
2535
                  if (h->got.offset != (bfd_vma) -1)
2536
                    {
2537
                      /* We have already allocated space in the .got.  */
2538
                      break;
2539
                    }
2540
                  h->got.offset = sgot->size;
2541
                }
2542
 
2543
              /* Make sure this symbol is output as a dynamic symbol.  */
2544
              if (h->dynindx == -1)
2545
                {
2546
                  if (! bfd_elf_link_record_dynamic_symbol (info, h))
2547
                    return FALSE;
2548
                }
2549
 
2550
              srelgot->size += sizeof (Elf64_External_Rela);
2551
            }
2552
          else
2553
            {
2554
              /* This is a global offset table entry for a local
2555
                 symbol.  */
2556
              if (local_got_offsets == NULL)
2557
                {
2558
                  size_t size;
2559
                  register unsigned int i;
2560
 
2561
                  size = symtab_hdr->sh_info * sizeof (bfd_vma);
2562
                  /* Reserve space for both the datalabel and
2563
                     codelabel local GOT offsets.  */
2564
                  size *= 2;
2565
                  local_got_offsets = (bfd_vma *) bfd_alloc (abfd, size);
2566
                  if (local_got_offsets == NULL)
2567
                    return FALSE;
2568
                  elf_local_got_offsets (abfd) = local_got_offsets;
2569
                  for (i = 0; i < symtab_hdr->sh_info; i++)
2570
                    local_got_offsets[i] = (bfd_vma) -1;
2571
                  for (; i < 2 * symtab_hdr->sh_info; i++)
2572
                    local_got_offsets[i] = (bfd_vma) -1;
2573
                }
2574
              if ((rel->r_addend & 1) != 0)
2575
                {
2576
                  if (local_got_offsets[symtab_hdr->sh_info
2577
                                        + r_symndx] != (bfd_vma) -1)
2578
                    {
2579
                      /* We have already allocated space in the .got.  */
2580
                      break;
2581
                    }
2582
                  local_got_offsets[symtab_hdr->sh_info
2583
                                    + r_symndx] = sgot->size;
2584
                }
2585
              else
2586
                {
2587
                  if (local_got_offsets[r_symndx] != (bfd_vma) -1)
2588
                    {
2589
                      /* We have already allocated space in the .got.  */
2590
                      break;
2591
                    }
2592
                  local_got_offsets[r_symndx] = sgot->size;
2593
                }
2594
 
2595
              if (info->shared)
2596
                {
2597
                  /* If we are generating a shared object, we need to
2598
                     output a R_SH_RELATIVE reloc so that the dynamic
2599
                     linker can adjust this GOT entry.  */
2600
                  srelgot->size += sizeof (Elf64_External_Rela);
2601
                }
2602
            }
2603
 
2604
          sgot->size += 8;
2605
 
2606
          break;
2607
 
2608
        case R_SH_GOTPLT_LOW16:
2609
        case R_SH_GOTPLT_MEDLOW16:
2610
        case R_SH_GOTPLT_MEDHI16:
2611
        case R_SH_GOTPLT_HI16:
2612
        case R_SH_GOTPLT10BY4:
2613
        case R_SH_GOTPLT10BY8:
2614
          /* If this is a local symbol, we resolve it directly without
2615
             creating a procedure linkage table entry.  */
2616
 
2617
          if (h == NULL
2618
              || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
2619
              || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
2620
              || ! info->shared
2621
              || info->symbolic
2622
              || h->dynindx == -1
2623
              || h->got.offset != (bfd_vma) -1)
2624
            goto force_got;
2625
 
2626
          /* Make sure this symbol is output as a dynamic symbol.  */
2627
          if (h->dynindx == -1)
2628
            {
2629
              if (! bfd_elf_link_record_dynamic_symbol (info, h))
2630
                return FALSE;
2631
            }
2632
 
2633
          h->needs_plt = 1;
2634
 
2635
          break;
2636
 
2637
        case R_SH_PLT_LOW16:
2638
        case R_SH_PLT_MEDLOW16:
2639
        case R_SH_PLT_MEDHI16:
2640
        case R_SH_PLT_HI16:
2641
          /* This symbol requires a procedure linkage table entry.  We
2642
             actually build the entry in adjust_dynamic_symbol,
2643
             because this might be a case of linking PIC code which is
2644
             never referenced by a dynamic object, in which case we
2645
             don't need to generate a procedure linkage table entry
2646
             after all.  */
2647
 
2648
          /* If this is a local symbol, we resolve it directly without
2649
             creating a procedure linkage table entry.  */
2650
          if (h == NULL)
2651
            continue;
2652
 
2653
          if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
2654
              || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
2655
            break;
2656
 
2657
          h->needs_plt = 1;
2658
 
2659
          break;
2660
 
2661
        case R_SH_64:
2662
        case R_SH_64_PCREL:
2663
          if (h != NULL)
2664
            h->non_got_ref = 1;
2665
 
2666
          /* If we are creating a shared library, and this is a reloc
2667
             against a global symbol, or a non PC relative reloc
2668
             against a local symbol, then we need to copy the reloc
2669
             into the shared library.  However, if we are linking with
2670
             -Bsymbolic, we do not need to copy a reloc against a
2671
             global symbol which is defined in an object we are
2672
             including in the link (i.e., DEF_REGULAR is set).  At
2673
             this point we have not seen all the input files, so it is
2674
             possible that DEF_REGULAR is not set now but will be set
2675
             later (it is never cleared).  We account for that
2676
             possibility below by storing information in the
2677
             pcrel_relocs_copied field of the hash table entry.  */
2678
          if (info->shared
2679
              && (sec->flags & SEC_ALLOC) != 0
2680
              && (ELF32_R_TYPE (rel->r_info) != R_SH_64_PCREL
2681
                  || (h != NULL
2682
                      && (! info->symbolic
2683
                          || !h->def_regular))))
2684
            {
2685
              /* When creating a shared object, we must copy these
2686
                 reloc types into the output file.  We create a reloc
2687
                 section in dynobj and make room for this reloc.  */
2688
              if (sreloc == NULL)
2689
                {
2690
                  sreloc = _bfd_elf_make_dynamic_reloc_section
2691
                    (sec, dynobj, 2, abfd, /*rela?*/ TRUE);
2692
 
2693
                  if (sreloc == NULL)
2694
                    return FALSE;
2695
                }
2696
 
2697
              sreloc->size += sizeof (Elf64_External_Rela);
2698
 
2699
              /* If we are linking with -Bsymbolic, and this is a
2700
                 global symbol, we count the number of PC relative
2701
                 relocations we have entered for this symbol, so that
2702
                 we can discard them again if the symbol is later
2703
                 defined by a regular object.  Note that this function
2704
                 is only called if we are using an elf_sh linker
2705
                 hash table, which means that h is really a pointer to
2706
                 an elf_sh_link_hash_entry.  */
2707
              if (h != NULL && info->symbolic
2708
                  && ELF64_R_TYPE (rel->r_info) == R_SH_64_PCREL)
2709
                {
2710
                  struct elf_sh64_link_hash_entry *eh;
2711
                  struct elf_sh64_pcrel_relocs_copied *p;
2712
 
2713
                  eh = (struct elf_sh64_link_hash_entry *) h;
2714
 
2715
                  for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next)
2716
                    if (p->section == sreloc)
2717
                      break;
2718
 
2719
                  if (p == NULL)
2720
                    {
2721
                      p = ((struct elf_sh64_pcrel_relocs_copied *)
2722
                           bfd_alloc (dynobj, sizeof *p));
2723
                      if (p == NULL)
2724
                        return FALSE;
2725
                      p->next = eh->pcrel_relocs_copied;
2726
                      eh->pcrel_relocs_copied = p;
2727
                      p->section = sreloc;
2728
                      p->count = 0;
2729
                    }
2730
 
2731
                  ++p->count;
2732
                }
2733
            }
2734
 
2735
          break;
2736
        }
2737
    }
2738
 
2739
  return TRUE;
2740
}
2741
 
2742
static int
2743
sh64_elf64_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
2744
{
2745
  if (ELF_ST_TYPE (elf_sym->st_info) == STT_DATALABEL)
2746
    return STT_DATALABEL;
2747
 
2748
  return type;
2749
}
2750
 
2751
/* FIXME: This is a copy of sh64_elf_add_symbol_hook in elf32-sh64.c.
2752
   Either file can presumably exist without the other, but do not differ
2753
   in elf-size-ness.  How to share?
2754
 
2755
   Hook called by the linker routine which adds symbols from an object
2756
   file.  We must make indirect symbols for undefined symbols marked with
2757
   STT_DATALABEL, so relocations passing them will pick up that attribute
2758
   and neutralize STO_SH5_ISA32 found on the symbol definition.
2759
 
2760
   There is a problem, though: We want to fill in the hash-table entry for
2761
   this symbol and signal to the caller that no further processing is
2762
   needed.  But we don't have the index for this hash-table entry.  We
2763
   rely here on that the current entry is the first hash-entry with NULL,
2764
   which seems brittle.  Also, iterating over the hash-table to find that
2765
   entry is a linear operation on the number of symbols in this input
2766
   file, and this function should take constant time, so that's not good
2767
   too.  Only comfort is that DataLabel references should only be found in
2768
   hand-written assembly code and thus be rare.  FIXME: Talk maintainers
2769
   into adding an option to elf_add_symbol_hook (preferably) for the index
2770
   or the hash entry, alternatively adding the index to Elf_Internal_Sym
2771
   (not so good).  */
2772
 
2773
static bfd_boolean
2774
sh64_elf64_add_symbol_hook (bfd *abfd, struct bfd_link_info *info,
2775
                            Elf_Internal_Sym *sym, const char **namep,
2776
                            flagword *flagsp ATTRIBUTE_UNUSED,
2777
                            asection **secp, bfd_vma *valp)
2778
{
2779
  /* We want to do this for relocatable as well as final linking.  */
2780
  if (ELF_ST_TYPE (sym->st_info) == STT_DATALABEL
2781
      && is_elf_hash_table (info->hash))
2782
    {
2783
      struct elf_link_hash_entry *h;
2784
 
2785
      /* For relocatable links, we register the DataLabel sym in its own
2786
         right, and tweak the name when it's output.  Otherwise, we make
2787
         an indirect symbol of it.  */
2788
      flagword flags
2789
        = info->relocatable || info->emitrelocations
2790
        ? BSF_GLOBAL : BSF_GLOBAL | BSF_INDIRECT;
2791
 
2792
      char *dl_name
2793
        = bfd_malloc (strlen (*namep) + sizeof (DATALABEL_SUFFIX));
2794
      struct elf_link_hash_entry ** sym_hash = elf_sym_hashes (abfd);
2795
 
2796
      BFD_ASSERT (sym_hash != NULL);
2797
 
2798
      /* Allocation may fail.  */
2799
      if (dl_name == NULL)
2800
        return FALSE;
2801
 
2802
      strcpy (dl_name, *namep);
2803
      strcat (dl_name, DATALABEL_SUFFIX);
2804
 
2805
      h = (struct elf_link_hash_entry *)
2806
        bfd_link_hash_lookup (info->hash, dl_name, FALSE, FALSE, FALSE);
2807
 
2808
      if (h == NULL)
2809
        {
2810
          /* No previous datalabel symbol.  Make one.  */
2811
          struct bfd_link_hash_entry *bh = NULL;
2812
          const struct elf_backend_data *bed = get_elf_backend_data (abfd);
2813
 
2814
          if (! _bfd_generic_link_add_one_symbol (info, abfd, dl_name,
2815
                                                  flags, *secp, *valp,
2816
                                                  *namep, FALSE,
2817
                                                  bed->collect, &bh))
2818
            {
2819
              free (dl_name);
2820
              return FALSE;
2821
            }
2822
 
2823
          h = (struct elf_link_hash_entry *) bh;
2824
          h->non_elf = 0;
2825
          h->type = STT_DATALABEL;
2826
        }
2827
      else
2828
        /* If a new symbol was created, it holds the allocated name.
2829
           Otherwise, we don't need it anymore and should deallocate it.  */
2830
        free (dl_name);
2831
 
2832
      if (h->type != STT_DATALABEL
2833
          || ((info->relocatable || info->emitrelocations)
2834
              && h->root.type != bfd_link_hash_undefined)
2835
          || (! info->relocatable && !info->emitrelocations
2836
              && h->root.type != bfd_link_hash_indirect))
2837
        {
2838
          /* Make sure we don't get confused on invalid input.  */
2839
          (*_bfd_error_handler)
2840
            (_("%s: encountered datalabel symbol in input"),
2841
             bfd_get_filename (abfd));
2842
          bfd_set_error (bfd_error_bad_value);
2843
          return FALSE;
2844
        }
2845
 
2846
      /* Now find the hash-table slot for this entry and fill it in.  */
2847
      while (*sym_hash != NULL)
2848
        sym_hash++;
2849
      *sym_hash = h;
2850
 
2851
      /* Signal to caller to skip this symbol - we've handled it.  */
2852
      *namep = NULL;
2853
    }
2854
 
2855
  return TRUE;
2856
}
2857
 
2858
/* This hook function is called before the linker writes out a global
2859
   symbol.  For relocatable links, DataLabel symbols will be present in
2860
   linker output.  We cut off the special suffix on those symbols, so the
2861
   right name appears in the output.
2862
 
2863
   When linking and emitting relocations, there can appear global symbols
2864
   that are not referenced by relocs, but rather only implicitly through
2865
   DataLabel references, a relation that is not visible to the linker.
2866
   Since no stripping of global symbols in done when doing such linking,
2867
   we don't need to look up and make sure to emit the main symbol for each
2868
   DataLabel symbol.  */
2869
 
2870
static int
2871
sh64_elf64_link_output_symbol_hook (struct bfd_link_info *info,
2872
                                    const char *cname,
2873
                                    Elf_Internal_Sym *sym,
2874
                                    asection *input_sec ATTRIBUTE_UNUSED,
2875
                                    struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
2876
{
2877
  char *name = (char *) cname;
2878
 
2879
  if (info->relocatable || info->emitrelocations)
2880
    {
2881
      if (ELF_ST_TYPE (sym->st_info) == STT_DATALABEL)
2882
        name[strlen (name) - strlen (DATALABEL_SUFFIX)] = 0;
2883
    }
2884
 
2885
  return 1;
2886
}
2887
 
2888
/* Set bit 0 on the entry address; it always points to SHmedia code.  This
2889
   is mostly for symmetry with the 32-bit format, where code can be
2890
   SHcompact and we need to make a distinction to make sure execution
2891
   starts in the right ISA mode.  It is also convenient for a loader,
2892
   which would otherwise have to set this bit when loading a TR register
2893
   before jumping to the program entry.  */
2894
 
2895
static void
2896
sh64_elf64_final_write_processing (bfd *abfd,
2897
                                   bfd_boolean linker ATTRIBUTE_UNUSED)
2898
{
2899
  /* FIXME: Perhaps we shouldn't do this if the entry address was supplied
2900
     numerically, but we currently lack the infrastructure to recognize
2901
     that: The entry symbol, and info whether it is numeric or a symbol
2902
     name is kept private in the linker.  */
2903
  if (elf_elfheader (abfd)->e_type == ET_EXEC)
2904
    elf_elfheader (abfd)->e_entry |= 1;
2905
}
2906
 
2907
/* First entry in an absolute procedure linkage table look like this.  */
2908
 
2909
static const bfd_byte elf_sh64_plt0_entry_be[PLT_ENTRY_SIZE] =
2910
{
2911
  0xcc, 0x00, 0x01, 0x10, /* movi  .got.plt >> 48, r17 */
2912
  0xc8, 0x00, 0x01, 0x10, /* shori (.got.plt >> 32) & 65535, r17 */
2913
  0xc8, 0x00, 0x01, 0x10, /* shori (.got.plt >> 16) & 65535, r17 */
2914
  0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
2915
  0x8d, 0x10, 0x09, 0x90, /* ld.q  r17, 16, r25 */
2916
  0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
2917
  0x8d, 0x10, 0x05, 0x10, /* ld.q  r17, 8, r17 */
2918
  0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
2919
  0x6f, 0xf0, 0xff, 0xf0, /* nop */
2920
  0x6f, 0xf0, 0xff, 0xf0, /* nop */
2921
  0x6f, 0xf0, 0xff, 0xf0, /* nop */
2922
  0x6f, 0xf0, 0xff, 0xf0, /* nop */
2923
  0x6f, 0xf0, 0xff, 0xf0, /* nop */
2924
  0x6f, 0xf0, 0xff, 0xf0, /* nop */
2925
  0x6f, 0xf0, 0xff, 0xf0, /* nop */
2926
  0x6f, 0xf0, 0xff, 0xf0, /* nop */
2927
};
2928
 
2929
static const bfd_byte elf_sh64_plt0_entry_le[PLT_ENTRY_SIZE] =
2930
{
2931
  0x10, 0x01, 0x00, 0xcc, /* movi  .got.plt >> 16, r17 */
2932
  0x10, 0x01, 0x00, 0xc8, /* shori (.got.plt >> 32) & 65535, r17 */
2933
  0x10, 0x01, 0x00, 0xc8, /* shori (.got.plt >> 16) & 65535, r17 */
2934
  0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
2935
  0x90, 0x09, 0x10, 0x8d, /* ld.q  r17, 16, r25 */
2936
  0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
2937
  0x10, 0x05, 0x10, 0x8d, /* ld.q  r17, 8, r17 */
2938
  0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
2939
  0xf0, 0xff, 0xf0, 0x6f, /* nop */
2940
  0xf0, 0xff, 0xf0, 0x6f, /* nop */
2941
  0xf0, 0xff, 0xf0, 0x6f, /* nop */
2942
  0xf0, 0xff, 0xf0, 0x6f, /* nop */
2943
  0xf0, 0xff, 0xf0, 0x6f, /* nop */
2944
  0xf0, 0xff, 0xf0, 0x6f, /* nop */
2945
  0xf0, 0xff, 0xf0, 0x6f, /* nop */
2946
  0xf0, 0xff, 0xf0, 0x6f, /* nop */
2947
};
2948
 
2949
/* Sebsequent entries in an absolute procedure linkage table look like
2950
   this.  */
2951
 
2952
static const bfd_byte elf_sh64_plt_entry_be[PLT_ENTRY_SIZE] =
2953
{
2954
  0xcc, 0x00, 0x01, 0x90, /* movi  nameN-in-GOT >> 48, r25 */
2955
  0xc8, 0x00, 0x01, 0x90, /* shori (nameN-in-GOT >> 32) & 65535, r25 */
2956
  0xc8, 0x00, 0x01, 0x90, /* shori (nameN-in-GOT >> 16) & 65535, r25 */
2957
  0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
2958
  0x8d, 0x90, 0x01, 0x90, /* ld.q  r25, 0, r25 */
2959
  0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
2960
  0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
2961
  0x6f, 0xf0, 0xff, 0xf0, /* nop */
2962
  0xcc, 0x00, 0x01, 0x90, /* movi  (.+8-.PLT0) >> 16, r25 */
2963
  0xc8, 0x00, 0x01, 0x90, /* shori (.+4-.PLT0) & 65535, r25 */
2964
  0x6b, 0xf5, 0x66, 0x00, /* ptrel r25, tr0 */
2965
  0xcc, 0x00, 0x01, 0x50, /* movi  reloc-offset >> 16, r21 */
2966
  0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
2967
  0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
2968
  0x6f, 0xf0, 0xff, 0xf0, /* nop */
2969
  0x6f, 0xf0, 0xff, 0xf0, /* nop */
2970
};
2971
 
2972
static const bfd_byte elf_sh64_plt_entry_le[PLT_ENTRY_SIZE] =
2973
{
2974
  0x90, 0x01, 0x00, 0xcc, /* movi  nameN-in-GOT >> 16, r25 */
2975
  0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
2976
  0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
2977
  0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
2978
  0x90, 0x01, 0x90, 0x8d, /* ld.q  r25, 0, r25 */
2979
  0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
2980
  0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
2981
  0xf0, 0xff, 0xf0, 0x6f, /* nop */
2982
  0x90, 0x01, 0x00, 0xcc, /* movi  (.+8-.PLT0) >> 16, r25 */
2983
  0x90, 0x01, 0x00, 0xc8, /* shori (.+4-.PLT0) & 65535, r25 */
2984
  0x00, 0x66, 0xf5, 0x6b, /* ptrel r25, tr0 */
2985
  0x50, 0x01, 0x00, 0xcc, /* movi  reloc-offset >> 16, r21 */
2986
  0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
2987
  0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
2988
  0xf0, 0xff, 0xf0, 0x6f, /* nop */
2989
  0xf0, 0xff, 0xf0, 0x6f, /* nop */
2990
};
2991
 
2992
/* Entries in a PIC procedure linkage table look like this.  */
2993
 
2994
static const bfd_byte elf_sh64_pic_plt_entry_be[PLT_ENTRY_SIZE] =
2995
{
2996
  0xcc, 0x00, 0x01, 0x90, /* movi  nameN@GOT >> 16, r25 */
2997
  0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
2998
  0x40, 0xc3, 0x65, 0x90, /* ldx.q r12, r25, r25 */
2999
  0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3000
  0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3001
  0x6f, 0xf0, 0xff, 0xf0, /* nop */
3002
  0x6f, 0xf0, 0xff, 0xf0, /* nop */
3003
  0x6f, 0xf0, 0xff, 0xf0, /* nop */
3004
  0xce, 0x00, 0x01, 0x10, /* movi  -GOT_BIAS, r17 */
3005
  0x00, 0xc9, 0x45, 0x10, /* add   r12, r17, r17 */
3006
  0x8d, 0x10, 0x09, 0x90, /* ld.q  r17, 16, r25 */
3007
  0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3008
  0x8d, 0x10, 0x05, 0x10, /* ld.q  r17, 8, r17 */
3009
  0xcc, 0x00, 0x01, 0x50, /* movi  reloc-offset >> 16, r21 */
3010
  0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3011
  0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3012
};
3013
 
3014
static const bfd_byte elf_sh64_pic_plt_entry_le[PLT_ENTRY_SIZE] =
3015
{
3016
  0x90, 0x01, 0x00, 0xcc, /* movi  nameN@GOT >> 16, r25 */
3017
  0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
3018
  0x90, 0x65, 0xc3, 0x40, /* ldx.q r12, r25, r25 */
3019
  0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3020
  0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3021
  0xf0, 0xff, 0xf0, 0x6f, /* nop */
3022
  0xf0, 0xff, 0xf0, 0x6f, /* nop */
3023
  0xf0, 0xff, 0xf0, 0x6f, /* nop */
3024
  0x10, 0x01, 0x00, 0xce, /* movi  -GOT_BIAS, r17 */
3025
  0x10, 0x45, 0xc9, 0x00, /* add   r12, r17, r17 */
3026
  0x90, 0x09, 0x10, 0x8d, /* ld.q  r17, 16, r25 */
3027
  0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3028
  0x10, 0x05, 0x10, 0x8d, /* ld.q  r17, 8, r17 */
3029
  0x50, 0x01, 0x00, 0xcc, /* movi  reloc-offset >> 16, r21 */
3030
  0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3031
  0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3032
};
3033
 
3034
static const bfd_byte *elf_sh64_plt0_entry;
3035
static const bfd_byte *elf_sh64_plt_entry;
3036
static const bfd_byte *elf_sh64_pic_plt_entry;
3037
 
3038
/* Create an entry in an sh ELF linker hash table.  */
3039
 
3040
static struct bfd_hash_entry *
3041
sh64_elf64_link_hash_newfunc (struct bfd_hash_entry *entry,
3042
                              struct bfd_hash_table *table,
3043
                              const char *string)
3044
{
3045
  struct elf_sh64_link_hash_entry *ret =
3046
    (struct elf_sh64_link_hash_entry *) entry;
3047
 
3048
  /* Allocate the structure if it has not already been allocated by a
3049
     subclass.  */
3050
  if (ret == (struct elf_sh64_link_hash_entry *) NULL)
3051
    ret = ((struct elf_sh64_link_hash_entry *)
3052
           bfd_hash_allocate (table,
3053
                              sizeof (struct elf_sh64_link_hash_entry)));
3054
  if (ret == (struct elf_sh64_link_hash_entry *) NULL)
3055
    return (struct bfd_hash_entry *) ret;
3056
 
3057
  /* Call the allocation method of the superclass.  */
3058
  ret = ((struct elf_sh64_link_hash_entry *)
3059
         _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
3060
                                     table, string));
3061
  if (ret != (struct elf_sh64_link_hash_entry *) NULL)
3062
    {
3063
      ret->pcrel_relocs_copied = NULL;
3064
      ret->datalabel_got_offset = (bfd_vma) -1;
3065
    }
3066
 
3067
  return (struct bfd_hash_entry *) ret;
3068
}
3069
 
3070
/* Create an sh64 ELF linker hash table.  */
3071
 
3072
static struct bfd_link_hash_table *
3073
sh64_elf64_link_hash_table_create (bfd *abfd)
3074
{
3075
  struct elf_link_hash_table *ret;
3076
 
3077
  ret = (struct elf_link_hash_table *) bfd_malloc (sizeof (* ret));
3078
  if (ret == (struct elf_link_hash_table *) NULL)
3079
    return NULL;
3080
 
3081
  if (!_bfd_elf_link_hash_table_init (ret, abfd,
3082
                                      sh64_elf64_link_hash_newfunc,
3083
                                      sizeof (struct elf_sh64_link_hash_entry),
3084
                                      GENERIC_ELF_DATA))
3085
    {
3086
      free (ret);
3087
      return NULL;
3088
    }
3089
 
3090
  return &ret->root;
3091
}
3092
 
3093
inline static void
3094
movi_shori_putval (bfd *output_bfd, unsigned long value, bfd_byte *addr)
3095
{
3096
  bfd_put_32 (output_bfd,
3097
              bfd_get_32 (output_bfd, addr)
3098
              | ((value >> 6) & 0x3fffc00),
3099
              addr);
3100
  bfd_put_32 (output_bfd,
3101
              bfd_get_32 (output_bfd, addr + 4)
3102
              | ((value << 10) & 0x3fffc00),
3103
              addr + 4);
3104
}
3105
 
3106
inline static void
3107
movi_3shori_putval (bfd *output_bfd, bfd_vma value, bfd_byte *addr)
3108
{
3109
  bfd_put_32 (output_bfd,
3110
              bfd_get_32 (output_bfd, addr)
3111
              | ((value >> 38) & 0x3fffc00),
3112
              addr);
3113
  bfd_put_32 (output_bfd,
3114
              bfd_get_32 (output_bfd, addr + 4)
3115
              | ((value >> 22) & 0x3fffc00),
3116
              addr + 4);
3117
  bfd_put_32 (output_bfd,
3118
              bfd_get_32 (output_bfd, addr + 8)
3119
              | ((value >> 6) & 0x3fffc00),
3120
              addr + 8);
3121
  bfd_put_32 (output_bfd,
3122
              bfd_get_32 (output_bfd, addr + 12)
3123
              | ((value << 10) & 0x3fffc00),
3124
              addr + 12);
3125
}
3126
 
3127
/* Create dynamic sections when linking against a dynamic object.  */
3128
 
3129
static bfd_boolean
3130
sh64_elf64_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
3131
{
3132
  flagword flags, pltflags;
3133
  register asection *s;
3134
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
3135
  int ptralign = 0;
3136
 
3137
  switch (bed->s->arch_size)
3138
    {
3139
    case 32:
3140
      ptralign = 2;
3141
      break;
3142
 
3143
    case 64:
3144
      ptralign = 3;
3145
      break;
3146
 
3147
    default:
3148
      bfd_set_error (bfd_error_bad_value);
3149
      return FALSE;
3150
    }
3151
 
3152
  /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3153
     .rel[a].bss sections.  */
3154
 
3155
  flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3156
           | SEC_LINKER_CREATED);
3157
 
3158
  pltflags = flags;
3159
  pltflags |= SEC_CODE;
3160
  if (bed->plt_not_loaded)
3161
    pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
3162
  if (bed->plt_readonly)
3163
    pltflags |= SEC_READONLY;
3164
 
3165
  s = bfd_make_section_with_flags (abfd, ".plt", pltflags);
3166
  if (s == NULL
3167
      || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
3168
    return FALSE;
3169
 
3170
  if (bed->want_plt_sym)
3171
    {
3172
      /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3173
         .plt section.  */
3174
      struct elf_link_hash_entry *h;
3175
      struct bfd_link_hash_entry *bh = NULL;
3176
 
3177
      if (! (_bfd_generic_link_add_one_symbol
3178
             (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
3179
              (bfd_vma) 0, (const char *) NULL, FALSE, bed->collect, &bh)))
3180
        return FALSE;
3181
 
3182
      h = (struct elf_link_hash_entry *) bh;
3183
      h->def_regular = 1;
3184
      h->type = STT_OBJECT;
3185
      elf_hash_table (info)->hplt = h;
3186
 
3187
      if (info->shared
3188
          && ! bfd_elf_link_record_dynamic_symbol (info, h))
3189
        return FALSE;
3190
    }
3191
 
3192
  s = bfd_make_section_with_flags (abfd,
3193
                                   bed->default_use_rela_p ? ".rela.plt" : ".rel.plt",
3194
                                   flags | SEC_READONLY);
3195
  if (s == NULL
3196
      || ! bfd_set_section_alignment (abfd, s, ptralign))
3197
    return FALSE;
3198
 
3199
  if (! _bfd_elf_create_got_section (abfd, info))
3200
    return FALSE;
3201
 
3202
  {
3203
    const char *secname;
3204
    char *relname;
3205
    flagword secflags;
3206
    asection *sec;
3207
 
3208
    for (sec = abfd->sections; sec; sec = sec->next)
3209
      {
3210
        secflags = bfd_get_section_flags (abfd, sec);
3211
        if ((secflags & (SEC_DATA | SEC_LINKER_CREATED))
3212
            || ((secflags & SEC_HAS_CONTENTS) != SEC_HAS_CONTENTS))
3213
          continue;
3214
        secname = bfd_get_section_name (abfd, sec);
3215
        relname = (char *) bfd_malloc (strlen (secname) + 6);
3216
        strcpy (relname, ".rela");
3217
        strcat (relname, secname);
3218
        s = bfd_make_section_with_flags (abfd, relname,
3219
                                         flags | SEC_READONLY);
3220
        if (s == NULL
3221
            || ! bfd_set_section_alignment (abfd, s, ptralign))
3222
          return FALSE;
3223
      }
3224
  }
3225
 
3226
  if (bed->want_dynbss)
3227
    {
3228
      /* The .dynbss section is a place to put symbols which are defined
3229
         by dynamic objects, are referenced by regular objects, and are
3230
         not functions.  We must allocate space for them in the process
3231
         image and use a R_*_COPY reloc to tell the dynamic linker to
3232
         initialize them at run time.  The linker script puts the .dynbss
3233
         section into the .bss section of the final image.  */
3234
      s = bfd_make_section_with_flags (abfd, ".dynbss",
3235
                                       SEC_ALLOC | SEC_LINKER_CREATED);
3236
      if (s == NULL)
3237
        return FALSE;
3238
 
3239
      /* The .rel[a].bss section holds copy relocs.  This section is not
3240
         normally needed.  We need to create it here, though, so that the
3241
         linker will map it to an output section.  We can't just create it
3242
         only if we need it, because we will not know whether we need it
3243
         until we have seen all the input files, and the first time the
3244
         main linker code calls BFD after examining all the input files
3245
         (size_dynamic_sections) the input sections have already been
3246
         mapped to the output sections.  If the section turns out not to
3247
         be needed, we can discard it later.  We will never need this
3248
         section when generating a shared object, since they do not use
3249
         copy relocs.  */
3250
      if (! info->shared)
3251
        {
3252
          s = bfd_make_section_with_flags (abfd,
3253
                                           (bed->default_use_rela_p
3254
                                            ? ".rela.bss" : ".rel.bss"),
3255
                                           flags | SEC_READONLY);
3256
          if (s == NULL
3257
              || ! bfd_set_section_alignment (abfd, s, ptralign))
3258
            return FALSE;
3259
        }
3260
    }
3261
 
3262
  return TRUE;
3263
}
3264
 
3265
/* Adjust a symbol defined by a dynamic object and referenced by a
3266
   regular object.  The current definition is in some section of the
3267
   dynamic object, but we're not including those sections.  We have to
3268
   change the definition to something the rest of the link can
3269
   understand.  */
3270
 
3271
static bfd_boolean
3272
sh64_elf64_adjust_dynamic_symbol (struct bfd_link_info *info,
3273
                                  struct elf_link_hash_entry *h)
3274
{
3275
  bfd *dynobj;
3276
  asection *s;
3277
 
3278
  dynobj = elf_hash_table (info)->dynobj;
3279
 
3280
  /* Make sure we know what is going on here.  */
3281
  BFD_ASSERT (dynobj != NULL
3282
              && (h->needs_plt
3283
                  || h->u.weakdef != NULL
3284
                  || (h->def_dynamic
3285
                      && h->ref_regular
3286
                      && !h->def_regular)));
3287
 
3288
  /* If this is a function, put it in the procedure linkage table.  We
3289
     will fill in the contents of the procedure linkage table later,
3290
     when we know the address of the .got section.  */
3291
  if (h->type == STT_FUNC
3292
      || h->needs_plt)
3293
    {
3294
      if (! info->shared
3295
          && !h->def_dynamic
3296
          && !h->ref_dynamic)
3297
        {
3298
          /* This case can occur if we saw a PLT reloc in an input
3299
             file, but the symbol was never referred to by a dynamic
3300
             object.  In such a case, we don't actually need to build
3301
             a procedure linkage table, and we can just do a REL64
3302
             reloc instead.  */
3303
          BFD_ASSERT (h->needs_plt);
3304
          return TRUE;
3305
        }
3306
 
3307
      /* Make sure this symbol is output as a dynamic symbol.  */
3308
      if (h->dynindx == -1)
3309
        {
3310
          if (! bfd_elf_link_record_dynamic_symbol (info, h))
3311
            return FALSE;
3312
        }
3313
 
3314
      s = bfd_get_section_by_name (dynobj, ".plt");
3315
      BFD_ASSERT (s != NULL);
3316
 
3317
      /* If this is the first .plt entry, make room for the special
3318
         first entry.  */
3319
      if (s->size == 0)
3320
        s->size += PLT_ENTRY_SIZE;
3321
 
3322
      /* If this symbol is not defined in a regular file, and we are
3323
         not generating a shared library, then set the symbol to this
3324
         location in the .plt.  This is required to make function
3325
         pointers compare as equal between the normal executable and
3326
         the shared library.  */
3327
      if (! info->shared
3328
          && !h->def_regular)
3329
        {
3330
          h->root.u.def.section = s;
3331
          h->root.u.def.value = s->size;
3332
        }
3333
 
3334
      h->plt.offset = s->size;
3335
 
3336
      /* Make room for this entry.  */
3337
      s->size += elf_sh64_sizeof_plt (info);
3338
 
3339
      /* We also need to make an entry in the .got.plt section, which
3340
         will be placed in the .got section by the linker script.  */
3341
 
3342
      s = bfd_get_section_by_name (dynobj, ".got.plt");
3343
      BFD_ASSERT (s != NULL);
3344
      s->size += 8;
3345
 
3346
      /* We also need to make an entry in the .rela.plt section.  */
3347
 
3348
      s = bfd_get_section_by_name (dynobj, ".rela.plt");
3349
      BFD_ASSERT (s != NULL);
3350
      s->size += sizeof (Elf64_External_Rela);
3351
 
3352
      return TRUE;
3353
    }
3354
 
3355
  /* If this is a weak symbol, and there is a real definition, the
3356
     processor independent code will have arranged for us to see the
3357
     real definition first, and we can just use the same value.  */
3358
  if (h->u.weakdef != NULL)
3359
    {
3360
      BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
3361
                  || h->u.weakdef->root.type == bfd_link_hash_defweak);
3362
      h->root.u.def.section = h->u.weakdef->root.u.def.section;
3363
      h->root.u.def.value = h->u.weakdef->root.u.def.value;
3364
      return TRUE;
3365
    }
3366
 
3367
  /* This is a reference to a symbol defined by a dynamic object which
3368
     is not a function.  */
3369
 
3370
  /* If we are creating a shared library, we must presume that the
3371
     only references to the symbol are via the global offset table.
3372
     For such cases we need not do anything here; the relocations will
3373
     be handled correctly by relocate_section.  */
3374
  if (info->shared)
3375
    return TRUE;
3376
 
3377
  /* If there are no references to this symbol that do not use the
3378
     GOT, we don't need to generate a copy reloc.  */
3379
  if (!h->non_got_ref)
3380
    return TRUE;
3381
 
3382
  if (h->size == 0)
3383
    {
3384
      (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
3385
                             h->root.root.string);
3386
      return TRUE;
3387
    }
3388
 
3389
  /* We must allocate the symbol in our .dynbss section, which will
3390
     become part of the .bss section of the executable.  There will be
3391
     an entry for this symbol in the .dynsym section.  The dynamic
3392
     object will contain position independent code, so all references
3393
     from the dynamic object to this symbol will go through the global
3394
     offset table.  The dynamic linker will use the .dynsym entry to
3395
     determine the address it must put in the global offset table, so
3396
     both the dynamic object and the regular object will refer to the
3397
     same memory location for the variable.  */
3398
 
3399
  s = bfd_get_section_by_name (dynobj, ".dynbss");
3400
  BFD_ASSERT (s != NULL);
3401
 
3402
  /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
3403
     copy the initial value out of the dynamic object and into the
3404
     runtime process image.  We need to remember the offset into the
3405
     .rela.bss section we are going to use.  */
3406
  if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
3407
    {
3408
      asection *srel;
3409
 
3410
      srel = bfd_get_section_by_name (dynobj, ".rela.bss");
3411
      BFD_ASSERT (srel != NULL);
3412
      srel->size += sizeof (Elf64_External_Rela);
3413
      h->needs_copy = 1;
3414
    }
3415
 
3416
  return _bfd_elf_adjust_dynamic_copy (h, s);
3417
}
3418
 
3419
/* This function is called via sh_elf_link_hash_traverse if we are
3420
   creating a shared object with -Bsymbolic.  It discards the space
3421
   allocated to copy PC relative relocs against symbols which are
3422
   defined in regular objects.  We allocated space for them in the
3423
   check_relocs routine, but we won't fill them in in the
3424
   relocate_section routine.  */
3425
 
3426
static bfd_boolean
3427
sh64_elf64_discard_copies (struct elf_sh64_link_hash_entry *h,
3428
                           void *ignore ATTRIBUTE_UNUSED)
3429
{
3430
  struct elf_sh64_pcrel_relocs_copied *s;
3431
 
3432
  if (h->root.root.type == bfd_link_hash_warning)
3433
    h = (struct elf_sh64_link_hash_entry *) h->root.root.u.i.link;
3434
 
3435
  /* We only discard relocs for symbols defined in a regular object.  */
3436
  if (!h->root.def_regular)
3437
    return TRUE;
3438
 
3439
  for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
3440
    s->section->size -= s->count * sizeof (Elf64_External_Rela);
3441
 
3442
  return TRUE;
3443
}
3444
 
3445
/* Set the sizes of the dynamic sections.  */
3446
 
3447
static bfd_boolean
3448
sh64_elf64_size_dynamic_sections (bfd *output_bfd,
3449
                                  struct bfd_link_info *info)
3450
{
3451
  bfd *dynobj;
3452
  asection *s;
3453
  bfd_boolean plt;
3454
  bfd_boolean relocs;
3455
  bfd_boolean reltext;
3456
 
3457
  dynobj = elf_hash_table (info)->dynobj;
3458
  BFD_ASSERT (dynobj != NULL);
3459
 
3460
  if (elf_hash_table (info)->dynamic_sections_created)
3461
    {
3462
      /* Set the contents of the .interp section to the interpreter.  */
3463
      if (info->executable)
3464
        {
3465
          s = bfd_get_section_by_name (dynobj, ".interp");
3466
          BFD_ASSERT (s != NULL);
3467
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
3468
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
3469
        }
3470
    }
3471
  else
3472
    {
3473
      /* We may have created entries in the .rela.got section.
3474
         However, if we are not creating the dynamic sections, we will
3475
         not actually use these entries.  Reset the size of .rela.got,
3476
         which will cause it to get stripped from the output file
3477
         below.  */
3478
      s = bfd_get_section_by_name (dynobj, ".rela.got");
3479
      if (s != NULL)
3480
        s->size = 0;
3481
    }
3482
 
3483
  /* If this is a -Bsymbolic shared link, then we need to discard all
3484
     PC relative relocs against symbols defined in a regular object.
3485
     We allocated space for them in the check_relocs routine, but we
3486
     will not fill them in in the relocate_section routine.  */
3487
  if (info->shared && info->symbolic)
3488
    sh64_elf64_link_hash_traverse (elf_hash_table (info),
3489
                                   sh64_elf64_discard_copies, NULL);
3490
 
3491
  /* The check_relocs and adjust_dynamic_symbol entry points have
3492
     determined the sizes of the various dynamic sections.  Allocate
3493
     memory for them.  */
3494
  plt = FALSE;
3495
  relocs = FALSE;
3496
  reltext = FALSE;
3497
  for (s = dynobj->sections; s != NULL; s = s->next)
3498
    {
3499
      const char *name;
3500
 
3501
      if ((s->flags & SEC_LINKER_CREATED) == 0)
3502
        continue;
3503
 
3504
      /* It's OK to base decisions on the section name, because none
3505
         of the dynobj section names depend upon the input files.  */
3506
      name = bfd_get_section_name (dynobj, s);
3507
 
3508
      if (strcmp (name, ".plt") == 0)
3509
        {
3510
          /* Remember whether there is a PLT.  */
3511
          plt = s->size != 0;
3512
        }
3513
      else if (CONST_STRNEQ (name, ".rela"))
3514
        {
3515
          if (s->size != 0)
3516
            {
3517
              asection *target;
3518
 
3519
              /* Remember whether there are any reloc sections other
3520
                 than .rela.plt.  */
3521
              if (strcmp (name, ".rela.plt") != 0)
3522
                {
3523
                  const char *outname;
3524
 
3525
                  relocs = TRUE;
3526
 
3527
                  /* If this relocation section applies to a read only
3528
                     section, then we probably need a DT_TEXTREL
3529
                     entry.  The entries in the .rela.plt section
3530
                     really apply to the .got section, which we
3531
                     created ourselves and so know is not readonly.  */
3532
                  outname = bfd_get_section_name (output_bfd,
3533
                                                  s->output_section);
3534
                  target = bfd_get_section_by_name (output_bfd, outname + 5);
3535
                  if (target != NULL
3536
                      && (target->flags & SEC_READONLY) != 0
3537
                      && (target->flags & SEC_ALLOC) != 0)
3538
                    reltext = TRUE;
3539
                }
3540
 
3541
              /* We use the reloc_count field as a counter if we need
3542
                 to copy relocs into the output file.  */
3543
              s->reloc_count = 0;
3544
            }
3545
        }
3546
      else if (! CONST_STRNEQ (name, ".got")
3547
               && strcmp (name, ".dynbss") != 0)
3548
        {
3549
          /* It's not one of our sections, so don't allocate space.  */
3550
          continue;
3551
        }
3552
 
3553
      if (s->size == 0)
3554
        {
3555
          /* If we don't need this section, strip it from the
3556
             output file.  This is mostly to handle .rela.bss and
3557
             .rela.plt.  We must create both sections in
3558
             create_dynamic_sections, because they must be created
3559
             before the linker maps input sections to output
3560
             sections.  The linker does that before
3561
             adjust_dynamic_symbol is called, and it is that
3562
             function which decides whether anything needs to go
3563
             into these sections.  */
3564
          s->flags |= SEC_EXCLUDE;
3565
          continue;
3566
        }
3567
 
3568
      if ((s->flags & SEC_HAS_CONTENTS) == 0)
3569
        continue;
3570
 
3571
      /* Allocate memory for the section contents.  */
3572
      s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
3573
      if (s->contents == NULL)
3574
        return FALSE;
3575
    }
3576
 
3577
  if (elf_hash_table (info)->dynamic_sections_created)
3578
    {
3579
      /* Add some entries to the .dynamic section.  We fill in the
3580
         values later, in sh64_elf64_finish_dynamic_sections, but we
3581
         must add the entries now so that we get the correct size for
3582
         the .dynamic section.  The DT_DEBUG entry is filled in by the
3583
         dynamic linker and used by the debugger.  */
3584
      if (info->executable)
3585
        {
3586
          if (!_bfd_elf_add_dynamic_entry (info, DT_DEBUG, 0))
3587
            return FALSE;
3588
        }
3589
 
3590
      if (plt)
3591
        {
3592
          if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0)
3593
              || !_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0)
3594
              || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
3595
              || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0))
3596
            return FALSE;
3597
        }
3598
 
3599
      if (relocs)
3600
        {
3601
          if (!_bfd_elf_add_dynamic_entry (info, DT_RELA, 0)
3602
              || !_bfd_elf_add_dynamic_entry (info, DT_RELASZ, 0)
3603
              || !_bfd_elf_add_dynamic_entry (info, DT_RELAENT,
3604
                                              sizeof (Elf64_External_Rela)))
3605
            return FALSE;
3606
        }
3607
 
3608
      if (reltext)
3609
        {
3610
          if (!_bfd_elf_add_dynamic_entry (info, DT_TEXTREL, 0))
3611
            return FALSE;
3612
        }
3613
    }
3614
 
3615
  return TRUE;
3616
}
3617
 
3618
/* Finish up dynamic symbol handling.  We set the contents of various
3619
   dynamic sections here.  */
3620
 
3621
static bfd_boolean
3622
sh64_elf64_finish_dynamic_symbol (bfd *output_bfd,
3623
                                  struct bfd_link_info *info,
3624
                                  struct elf_link_hash_entry *h,
3625
                                  Elf_Internal_Sym *sym)
3626
{
3627
  bfd *dynobj;
3628
 
3629
  dynobj = elf_hash_table (info)->dynobj;
3630
 
3631
  if (h->plt.offset != (bfd_vma) -1)
3632
    {
3633
      asection *splt;
3634
      asection *sgot;
3635
      asection *srel;
3636
 
3637
      bfd_vma plt_index;
3638
      bfd_vma got_offset;
3639
      Elf_Internal_Rela rel;
3640
      bfd_byte *loc;
3641
 
3642
      /* This symbol has an entry in the procedure linkage table.  Set
3643
         it up.  */
3644
 
3645
      BFD_ASSERT (h->dynindx != -1);
3646
 
3647
      splt = bfd_get_section_by_name (dynobj, ".plt");
3648
      sgot = bfd_get_section_by_name (dynobj, ".got.plt");
3649
      srel = bfd_get_section_by_name (dynobj, ".rela.plt");
3650
      BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
3651
 
3652
      /* Get the index in the procedure linkage table which
3653
         corresponds to this symbol.  This is the index of this symbol
3654
         in all the symbols for which we are making plt entries.  The
3655
         first entry in the procedure linkage table is reserved.  */
3656
      plt_index = h->plt.offset / elf_sh64_sizeof_plt (info) - 1;
3657
 
3658
      /* Get the offset into the .got table of the entry that
3659
         corresponds to this function.  Each .got entry is 8 bytes.
3660
         The first three are reserved.  */
3661
      got_offset = (plt_index + 3) * 8;
3662
 
3663
      if (info->shared)
3664
        got_offset -= GOT_BIAS;
3665
 
3666
      /* Fill in the entry in the procedure linkage table.  */
3667
      if (! info->shared)
3668
        {
3669
          if (elf_sh64_plt_entry == NULL)
3670
            {
3671
              elf_sh64_plt_entry = (bfd_big_endian (output_bfd) ?
3672
                                  elf_sh64_plt_entry_be : elf_sh64_plt_entry_le);
3673
            }
3674
          memcpy (splt->contents + h->plt.offset, elf_sh64_plt_entry,
3675
                  elf_sh64_sizeof_plt (info));
3676
          movi_3shori_putval (output_bfd,
3677
                              (sgot->output_section->vma
3678
                               + sgot->output_offset
3679
                               + got_offset),
3680
                              (splt->contents + h->plt.offset
3681
                               + elf_sh64_plt_symbol_offset (info)));
3682
 
3683
          /* Set bottom bit because its for a branch to SHmedia */
3684
          movi_shori_putval (output_bfd,
3685
                             -(h->plt.offset
3686
                              + elf_sh64_plt_plt0_offset (info) + 8)
3687
                             | 1,
3688
                             (splt->contents + h->plt.offset
3689
                              + elf_sh64_plt_plt0_offset (info)));
3690
        }
3691
      else
3692
        {
3693
          if (elf_sh64_pic_plt_entry == NULL)
3694
            {
3695
              elf_sh64_pic_plt_entry = (bfd_big_endian (output_bfd) ?
3696
                                      elf_sh64_pic_plt_entry_be :
3697
                                      elf_sh64_pic_plt_entry_le);
3698
            }
3699
          memcpy (splt->contents + h->plt.offset, elf_sh64_pic_plt_entry,
3700
                  elf_sh64_sizeof_plt (info));
3701
          movi_shori_putval (output_bfd, got_offset,
3702
                             (splt->contents + h->plt.offset
3703
                              + elf_sh64_plt_symbol_offset (info)));
3704
        }
3705
 
3706
      if (info->shared)
3707
        got_offset += GOT_BIAS;
3708
 
3709
      movi_shori_putval (output_bfd,
3710
                         plt_index * sizeof (Elf64_External_Rela),
3711
                         (splt->contents + h->plt.offset
3712
                          + elf_sh64_plt_reloc_offset (info)));
3713
 
3714
      /* Fill in the entry in the global offset table.  */
3715
      bfd_put_64 (output_bfd,
3716
                  (splt->output_section->vma
3717
                   + splt->output_offset
3718
                   + h->plt.offset
3719
                   + elf_sh64_plt_temp_offset (info)),
3720
                  sgot->contents + got_offset);
3721
 
3722
      /* Fill in the entry in the .rela.plt section.  */
3723
      rel.r_offset = (sgot->output_section->vma
3724
                      + sgot->output_offset
3725
                      + got_offset);
3726
      rel.r_info = ELF64_R_INFO (h->dynindx, R_SH_JMP_SLOT64);
3727
      rel.r_addend = 0;
3728
      rel.r_addend = GOT_BIAS;
3729
      loc = srel->contents + plt_index * sizeof (Elf64_External_Rela);
3730
      bfd_elf64_swap_reloca_out (output_bfd, &rel, loc);
3731
 
3732
      if (!h->def_regular)
3733
        {
3734
          /* Mark the symbol as undefined, rather than as defined in
3735
             the .plt section.  Leave the value alone.  */
3736
          sym->st_shndx = SHN_UNDEF;
3737
        }
3738
    }
3739
 
3740
  if (h->got.offset != (bfd_vma) -1)
3741
    {
3742
      asection *sgot;
3743
      asection *srel;
3744
      Elf_Internal_Rela rel;
3745
      bfd_byte *loc;
3746
 
3747
      /* This symbol has an entry in the global offset table.  Set it
3748
         up.  */
3749
 
3750
      sgot = bfd_get_section_by_name (dynobj, ".got");
3751
      srel = bfd_get_section_by_name (dynobj, ".rela.got");
3752
      BFD_ASSERT (sgot != NULL && srel != NULL);
3753
 
3754
      rel.r_offset = (sgot->output_section->vma
3755
                      + sgot->output_offset
3756
                      + (h->got.offset &~ 1));
3757
 
3758
      /* If this is a -Bsymbolic link, and the symbol is defined
3759
         locally, we just want to emit a RELATIVE reloc.  Likewise if
3760
         the symbol was forced to be local because of a version file.
3761
         The entry in the global offset table will already have been
3762
         initialized in the relocate_section function.  */
3763
      if (info->shared
3764
          && (info->symbolic || h->dynindx == -1)
3765
          && h->def_regular)
3766
        {
3767
          rel.r_info = ELF64_R_INFO (0, R_SH_RELATIVE64);
3768
          rel.r_addend = (h->root.u.def.value
3769
                          + h->root.u.def.section->output_section->vma
3770
                          + h->root.u.def.section->output_offset);
3771
        }
3772
      else
3773
        {
3774
          bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
3775
          rel.r_info = ELF64_R_INFO (h->dynindx, R_SH_GLOB_DAT64);
3776
          rel.r_addend = 0;
3777
        }
3778
 
3779
      loc = srel->contents;
3780
      loc += srel->reloc_count++ * sizeof (Elf64_External_Rela);
3781
      bfd_elf64_swap_reloca_out (output_bfd, &rel, loc);
3782
    }
3783
 
3784
  if (h->needs_copy)
3785
    {
3786
      asection *s;
3787
      Elf_Internal_Rela rel;
3788
      bfd_byte *loc;
3789
 
3790
      /* This symbol needs a copy reloc.  Set it up.  */
3791
 
3792
      BFD_ASSERT (h->dynindx != -1
3793
                  && (h->root.type == bfd_link_hash_defined
3794
                      || h->root.type == bfd_link_hash_defweak));
3795
 
3796
      s = bfd_get_section_by_name (h->root.u.def.section->owner,
3797
                                   ".rela.bss");
3798
      BFD_ASSERT (s != NULL);
3799
 
3800
      rel.r_offset = (h->root.u.def.value
3801
                      + h->root.u.def.section->output_section->vma
3802
                      + h->root.u.def.section->output_offset);
3803
      rel.r_info = ELF64_R_INFO (h->dynindx, R_SH_COPY64);
3804
      rel.r_addend = 0;
3805
      loc = s->contents;
3806
      loc += s->reloc_count++ * sizeof (Elf64_External_Rela);
3807
      bfd_elf64_swap_reloca_out (output_bfd, &rel, loc);
3808
    }
3809
 
3810
  /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.  */
3811
  if (strcmp (h->root.root.string, "_DYNAMIC") == 0
3812
      || h == elf_hash_table (info)->hgot)
3813
    sym->st_shndx = SHN_ABS;
3814
 
3815
  return TRUE;
3816
}
3817
 
3818
/* Finish up the dynamic sections.  */
3819
 
3820
static bfd_boolean
3821
sh64_elf64_finish_dynamic_sections (bfd *output_bfd,
3822
                                    struct bfd_link_info *info)
3823
{
3824
  bfd *dynobj;
3825
  asection *sgot;
3826
  asection *sdyn;
3827
 
3828
  dynobj = elf_hash_table (info)->dynobj;
3829
 
3830
  sgot = bfd_get_section_by_name (dynobj, ".got.plt");
3831
  BFD_ASSERT (sgot != NULL);
3832
  sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
3833
 
3834
  if (elf_hash_table (info)->dynamic_sections_created)
3835
    {
3836
      asection *splt;
3837
      Elf64_External_Dyn *dyncon, *dynconend;
3838
 
3839
      BFD_ASSERT (sdyn != NULL);
3840
 
3841
      dyncon = (Elf64_External_Dyn *) sdyn->contents;
3842
      dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
3843
      for (; dyncon < dynconend; dyncon++)
3844
        {
3845
          Elf_Internal_Dyn dyn;
3846
          const char *name;
3847
          asection *s;
3848
          struct elf_link_hash_entry *h;
3849
 
3850
          bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
3851
 
3852
          switch (dyn.d_tag)
3853
            {
3854
            default:
3855
              break;
3856
 
3857
            case DT_INIT:
3858
              name = info->init_function;
3859
              goto get_sym;
3860
 
3861
            case DT_FINI:
3862
              name = info->fini_function;
3863
            get_sym:
3864
              if (dyn.d_un.d_val != 0)
3865
                {
3866
                  h = elf_link_hash_lookup (elf_hash_table (info), name,
3867
                                            FALSE, FALSE, TRUE);
3868
                  if (h != NULL && (h->other & STO_SH5_ISA32))
3869
                    {
3870
                      dyn.d_un.d_val |= 1;
3871
                      bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
3872
                    }
3873
                }
3874
              break;
3875
 
3876
            case DT_PLTGOT:
3877
              name = ".got";
3878
              goto get_vma;
3879
 
3880
            case DT_JMPREL:
3881
              name = ".rela.plt";
3882
            get_vma:
3883
              s = bfd_get_section_by_name (output_bfd, name);
3884
              BFD_ASSERT (s != NULL);
3885
              dyn.d_un.d_ptr = s->vma;
3886
              bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
3887
              break;
3888
 
3889
            case DT_PLTRELSZ:
3890
              s = bfd_get_section_by_name (output_bfd, ".rela.plt");
3891
              BFD_ASSERT (s != NULL);
3892
              dyn.d_un.d_val = s->size;
3893
              bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
3894
              break;
3895
 
3896
            case DT_RELASZ:
3897
              /* My reading of the SVR4 ABI indicates that the
3898
                 procedure linkage table relocs (DT_JMPREL) should be
3899
                 included in the overall relocs (DT_RELA).  This is
3900
                 what Solaris does.  However, UnixWare can not handle
3901
                 that case.  Therefore, we override the DT_RELASZ entry
3902
                 here to make it not include the JMPREL relocs.  Since
3903
                 the linker script arranges for .rela.plt to follow all
3904
                 other relocation sections, we don't have to worry
3905
                 about changing the DT_RELA entry.  */
3906
              s = bfd_get_section_by_name (output_bfd, ".rela.plt");
3907
              if (s != NULL)
3908
                dyn.d_un.d_val -= s->size;
3909
              bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
3910
              break;
3911
            }
3912
        }
3913
 
3914
      /* Fill in the first entry in the procedure linkage table.  */
3915
      splt = bfd_get_section_by_name (dynobj, ".plt");
3916
      if (splt && splt->size > 0)
3917
        {
3918
          if (info->shared)
3919
            {
3920
              if (elf_sh64_pic_plt_entry == NULL)
3921
                {
3922
                  elf_sh64_pic_plt_entry = (bfd_big_endian (output_bfd) ?
3923
                                          elf_sh64_pic_plt_entry_be :
3924
                                          elf_sh64_pic_plt_entry_le);
3925
                }
3926
              memcpy (splt->contents, elf_sh64_pic_plt_entry,
3927
                      elf_sh64_sizeof_plt (info));
3928
            }
3929
          else
3930
            {
3931
              if (elf_sh64_plt0_entry == NULL)
3932
                {
3933
                  elf_sh64_plt0_entry = (bfd_big_endian (output_bfd) ?
3934
                                       elf_sh64_plt0_entry_be :
3935
                                       elf_sh64_plt0_entry_le);
3936
                }
3937
              memcpy (splt->contents, elf_sh64_plt0_entry, PLT_ENTRY_SIZE);
3938
              movi_3shori_putval (output_bfd,
3939
                                  sgot->output_section->vma
3940
                                  + sgot->output_offset,
3941
                                  splt->contents
3942
                                  + elf_sh64_plt0_gotplt_offset (info));
3943
            }
3944
 
3945
          /* UnixWare sets the entsize of .plt to 8, although that doesn't
3946
             really seem like the right value.  */
3947
          elf_section_data (splt->output_section)->this_hdr.sh_entsize = 8;
3948
        }
3949
    }
3950
 
3951
  /* Fill in the first three entries in the global offset table.  */
3952
  if (sgot->size > 0)
3953
    {
3954
      if (sdyn == NULL)
3955
        bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents);
3956
      else
3957
        bfd_put_64 (output_bfd,
3958
                    sdyn->output_section->vma + sdyn->output_offset,
3959
                    sgot->contents);
3960
      bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
3961
      bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + 16);
3962
    }
3963
 
3964
  elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 8;
3965
 
3966
  return TRUE;
3967
}
3968
 
3969
/* Merge non visibility st_other attribute when the symbol comes from
3970
   a dynamic object.  */
3971
static void
3972
sh64_elf64_merge_symbol_attribute (struct elf_link_hash_entry *h,
3973
                                   const Elf_Internal_Sym *isym,
3974
                                   bfd_boolean definition,
3975
                                   bfd_boolean dynamic ATTRIBUTE_UNUSED)
3976
{
3977
  if ((isym->st_other & ~ELF_ST_VISIBILITY (-1)) != 0)
3978
    {
3979
      unsigned char other;
3980
 
3981
      /* Take the balance of OTHER from the definition.  */
3982
      other = (definition ? isym->st_other : h->other);
3983
      other &= ~ ELF_ST_VISIBILITY (-1);
3984
      h->other = other | ELF_ST_VISIBILITY (h->other);
3985
    }
3986
 
3987
  return;
3988
}
3989
 
3990
static const struct bfd_elf_special_section sh64_elf64_special_sections[]=
3991
{
3992
  { STRING_COMMA_LEN (".cranges"), 0, SHT_PROGBITS, 0 },
3993
  { NULL,                       0, 0, 0,            0 }
3994
};
3995
 
3996
#define TARGET_BIG_SYM          bfd_elf64_sh64_vec
3997
#define TARGET_BIG_NAME         "elf64-sh64"
3998
#define TARGET_LITTLE_SYM       bfd_elf64_sh64l_vec
3999
#define TARGET_LITTLE_NAME      "elf64-sh64l"
4000
#define ELF_ARCH                bfd_arch_sh
4001
#define ELF_MACHINE_CODE        EM_SH
4002
#define ELF_MAXPAGESIZE         128
4003
 
4004
#define elf_symbol_leading_char '_'
4005
 
4006
#define bfd_elf64_bfd_reloc_type_lookup sh_elf64_reloc_type_lookup
4007
#define bfd_elf64_bfd_reloc_name_lookup \
4008
                                        sh_elf64_reloc_name_lookup
4009
#define elf_info_to_howto               sh_elf64_info_to_howto
4010
 
4011
/* Note: there's no relaxation at present.  */
4012
 
4013
#define elf_backend_relocate_section    sh_elf64_relocate_section
4014
#define bfd_elf64_bfd_get_relocated_section_contents \
4015
                                        sh_elf64_get_relocated_section_contents
4016
#define elf_backend_object_p            sh_elf64_set_mach_from_flags
4017
#define bfd_elf64_bfd_set_private_flags \
4018
                                        sh_elf64_set_private_flags
4019
#define bfd_elf64_bfd_copy_private_bfd_data \
4020
                                        sh_elf64_copy_private_data
4021
#define bfd_elf64_bfd_merge_private_bfd_data \
4022
                                        sh_elf64_merge_private_data
4023
#define elf_backend_fake_sections       sh64_elf64_fake_sections
4024
 
4025
#define elf_backend_gc_mark_hook        sh_elf64_gc_mark_hook
4026
#define elf_backend_check_relocs        sh_elf64_check_relocs
4027
 
4028
#define elf_backend_can_gc_sections     1
4029
 
4030
#define elf_backend_get_symbol_type     sh64_elf64_get_symbol_type
4031
 
4032
#define elf_backend_add_symbol_hook     sh64_elf64_add_symbol_hook
4033
 
4034
#define elf_backend_link_output_symbol_hook \
4035
        sh64_elf64_link_output_symbol_hook
4036
 
4037
#define elf_backend_merge_symbol_attribute \
4038
        sh64_elf64_merge_symbol_attribute
4039
 
4040
#define elf_backend_final_write_processing \
4041
        sh64_elf64_final_write_processing
4042
 
4043
#define elf_backend_create_dynamic_sections \
4044
                                        sh64_elf64_create_dynamic_sections
4045
#define bfd_elf64_bfd_link_hash_table_create \
4046
                                        sh64_elf64_link_hash_table_create
4047
#define elf_backend_adjust_dynamic_symbol \
4048
                                        sh64_elf64_adjust_dynamic_symbol
4049
#define elf_backend_size_dynamic_sections \
4050
                                        sh64_elf64_size_dynamic_sections
4051
#define elf_backend_omit_section_dynsym \
4052
  ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
4053
#define elf_backend_finish_dynamic_symbol \
4054
                                        sh64_elf64_finish_dynamic_symbol
4055
#define elf_backend_finish_dynamic_sections \
4056
                                        sh64_elf64_finish_dynamic_sections
4057
#define elf_backend_special_sections    sh64_elf64_special_sections
4058
 
4059
#define elf_backend_want_got_plt        1
4060
#define elf_backend_plt_readonly        1
4061
#define elf_backend_want_plt_sym        0
4062
#define elf_backend_got_header_size     24
4063
 
4064
#include "elf64-target.h"
4065
 
4066
/* NetBSD support.  */
4067
#undef  TARGET_BIG_SYM
4068
#define TARGET_BIG_SYM                  bfd_elf64_sh64nbsd_vec
4069
#undef  TARGET_BIG_NAME
4070
#define TARGET_BIG_NAME                 "elf64-sh64-nbsd"
4071
#undef  TARGET_LITTLE_SYM
4072
#define TARGET_LITTLE_SYM               bfd_elf64_sh64lnbsd_vec
4073
#undef  TARGET_LITTLE_NAME
4074
#define TARGET_LITTLE_NAME              "elf64-sh64l-nbsd"
4075
#undef  ELF_MAXPAGESIZE
4076
#define ELF_MAXPAGESIZE                 0x10000
4077
#undef  elf_symbol_leading_char
4078
#define elf_symbol_leading_char         0
4079
 
4080
#define elf64_bed                       elf64_sh64_nbsd_bed
4081
 
4082
#include "elf64-target.h"
4083
 
4084
/* Linux support.  */
4085
#undef  TARGET_BIG_SYM
4086
#define TARGET_BIG_SYM                  bfd_elf64_sh64blin_vec
4087
#undef  TARGET_BIG_NAME
4088
#define TARGET_BIG_NAME                 "elf64-sh64big-linux"
4089
#undef  TARGET_LITTLE_SYM
4090
#define TARGET_LITTLE_SYM               bfd_elf64_sh64lin_vec
4091
#undef  TARGET_LITTLE_NAME
4092
#define TARGET_LITTLE_NAME              "elf64-sh64-linux"
4093
#undef elf64_bed
4094
#define elf64_bed                       elf64_sh64_linux_bed
4095
 
4096
#include "elf64-target.h"

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.