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