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