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