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