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