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