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