include/
[deliverable/binutils-gdb.git] / bfd / elf32-sh.c
CommitLineData
ef230218 1/* Renesas / SuperH SH specific support for 32-bit ELF
571fe01f 2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
7898deda 3 Free Software Foundation, Inc.
252b5132
RH
4 Contributed by Ian Lance Taylor, Cygnus Support.
5
571fe01f 6 This file is part of BFD, the Binary File Descriptor library.
252b5132 7
571fe01f
NC
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
252b5132 12
571fe01f
NC
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
252b5132 17
571fe01f
NC
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
252b5132
RH
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
29static bfd_reloc_status_type sh_elf_reloc
30 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
31static bfd_reloc_status_type sh_elf_ignore_reloc
32 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
33static reloc_howto_type *sh_elf_reloc_type_lookup
34 PARAMS ((bfd *, bfd_reloc_code_real_type));
35static void sh_elf_info_to_howto
36 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
b34976b6 37static bfd_boolean sh_elf_set_private_flags
d4845d57 38 PARAMS ((bfd *, flagword));
b34976b6 39static bfd_boolean sh_elf_copy_private_data
d4845d57 40 PARAMS ((bfd *, bfd *));
b34976b6 41static bfd_boolean sh_elf_merge_private_data
d4845d57 42 PARAMS ((bfd *, bfd *));
b34976b6 43static bfd_boolean sh_elf_set_mach_from_flags
d4845d57 44 PARAMS ((bfd *));
b34976b6
AM
45static bfd_boolean sh_elf_relax_section
46 PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *));
47static bfd_boolean sh_elf_relax_delete_bytes
252b5132 48 PARAMS ((bfd *, asection *, bfd_vma, int));
b34976b6
AM
49static bfd_boolean sh_elf_align_loads
50 PARAMS ((bfd *, asection *, Elf_Internal_Rela *, bfd_byte *, bfd_boolean *));
51static bfd_boolean sh_elf_swap_insns
252b5132 52 PARAMS ((bfd *, asection *, PTR, bfd_byte *, bfd_vma));
b34976b6 53static bfd_boolean sh_elf_relocate_section
252b5132
RH
54 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
55 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
56static bfd_byte *sh_elf_get_relocated_section_contents
57 PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
b34976b6 58 bfd_byte *, bfd_boolean, asymbol **));
067653c5
AM
59static void sh_elf_copy_indirect_symbol
60 PARAMS ((struct elf_backend_data *, struct elf_link_hash_entry *,
61 struct elf_link_hash_entry *));
3376eaf5
KK
62static int sh_elf_optimized_tls_reloc
63 PARAMS ((struct bfd_link_info *, int, int));
b34976b6 64static bfd_boolean sh_elf_mkobject
571fe01f 65 PARAMS ((bfd *));
b34976b6 66static bfd_boolean sh_elf_object_p
571fe01f 67 PARAMS ((bfd *));
b34976b6 68static bfd_boolean sh_elf_check_relocs
37c644f2
AO
69 PARAMS ((bfd *, struct bfd_link_info *, asection *,
70 const Elf_Internal_Rela *));
71static struct bfd_hash_entry *sh_elf_link_hash_newfunc
72 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
73static struct bfd_link_hash_table *sh_elf_link_hash_table_create
74 PARAMS ((bfd *));
b34976b6 75static bfd_boolean sh_elf_adjust_dynamic_symbol
37c644f2 76 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
b34976b6 77static bfd_boolean sh_elf_size_dynamic_sections
37c644f2 78 PARAMS ((bfd *, struct bfd_link_info *));
b34976b6 79static bfd_boolean sh_elf_finish_dynamic_symbol
37c644f2
AO
80 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
81 Elf_Internal_Sym *));
b34976b6 82static bfd_boolean sh_elf_finish_dynamic_sections
37c644f2 83 PARAMS ((bfd *, struct bfd_link_info *));
917583ad
NC
84static bfd_reloc_status_type sh_elf_reloc_loop
85 PARAMS ((int, bfd *, asection *, bfd_byte *, bfd_vma, asection *,
86 bfd_vma, bfd_vma));
b34976b6 87static bfd_boolean create_got_section
571fe01f 88 PARAMS ((bfd *, struct bfd_link_info *));
b34976b6 89static bfd_boolean sh_elf_create_dynamic_sections
917583ad 90 PARAMS ((bfd *, struct bfd_link_info *));
3376eaf5
KK
91static bfd_vma dtpoff_base
92 PARAMS ((struct bfd_link_info *));
917583ad 93static asection * sh_elf_gc_mark_hook
1e2f5b6e 94 PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
917583ad 95 struct elf_link_hash_entry *, Elf_Internal_Sym *));
b34976b6 96static bfd_boolean sh_elf_gc_sweep_hook
917583ad
NC
97 PARAMS ((bfd *, struct bfd_link_info *, asection *,
98 const Elf_Internal_Rela *));
b34976b6 99static bfd_boolean allocate_dynrelocs
067653c5 100 PARAMS ((struct elf_link_hash_entry *, PTR));
b34976b6 101static bfd_boolean readonly_dynrelocs
067653c5 102 PARAMS ((struct elf_link_hash_entry *, PTR));
99e4ae17 103static enum elf_reloc_type_class sh_elf_reloc_type_class
f51e552e 104 PARAMS ((const Elf_Internal_Rela *));
518313c3
AO
105#ifdef INCLUDE_SHMEDIA
106inline static void movi_shori_putval PARAMS ((bfd *, unsigned long, char *));
107#endif
b34976b6 108static bfd_boolean elf32_shlin_grok_prstatus
2bc3c89a 109 PARAMS ((bfd *abfd, Elf_Internal_Note *note));
b34976b6 110static bfd_boolean elf32_shlin_grok_psinfo
2bc3c89a 111 PARAMS ((bfd *abfd, Elf_Internal_Note *note));
37c644f2
AO
112
113/* The name of the dynamic interpreter. This is put in the .interp
114 section. */
115
116#define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
252b5132 117
38b1a46c
NC
118static reloc_howto_type sh_elf_howto_table[] =
119{
252b5132
RH
120 /* No relocation. */
121 HOWTO (R_SH_NONE, /* type */
122 0, /* rightshift */
123 0, /* size (0 = byte, 1 = short, 2 = long) */
124 0, /* bitsize */
b34976b6 125 FALSE, /* pc_relative */
252b5132
RH
126 0, /* bitpos */
127 complain_overflow_dont, /* complain_on_overflow */
015551fc 128 sh_elf_ignore_reloc, /* special_function */
252b5132 129 "R_SH_NONE", /* name */
b34976b6 130 FALSE, /* partial_inplace */
252b5132
RH
131 0, /* src_mask */
132 0, /* dst_mask */
b34976b6 133 FALSE), /* pcrel_offset */
252b5132 134
b34976b6 135 /* 32 bit absolute relocation. Setting partial_inplace to TRUE and
252b5132
RH
136 src_mask to a non-zero value is similar to the COFF toolchain. */
137 HOWTO (R_SH_DIR32, /* type */
138 0, /* rightshift */
139 2, /* size (0 = byte, 1 = short, 2 = long) */
140 32, /* bitsize */
b34976b6 141 FALSE, /* pc_relative */
252b5132
RH
142 0, /* bitpos */
143 complain_overflow_bitfield, /* complain_on_overflow */
144 sh_elf_reloc, /* special_function */
145 "R_SH_DIR32", /* name */
b34976b6 146 TRUE, /* partial_inplace */
252b5132
RH
147 0xffffffff, /* src_mask */
148 0xffffffff, /* dst_mask */
b34976b6 149 FALSE), /* pcrel_offset */
252b5132
RH
150
151 /* 32 bit PC relative relocation. */
152 HOWTO (R_SH_REL32, /* type */
153 0, /* rightshift */
154 2, /* size (0 = byte, 1 = short, 2 = long) */
155 32, /* bitsize */
b34976b6 156 TRUE, /* pc_relative */
252b5132
RH
157 0, /* bitpos */
158 complain_overflow_signed, /* complain_on_overflow */
015551fc 159 sh_elf_ignore_reloc, /* special_function */
252b5132 160 "R_SH_REL32", /* name */
b34976b6 161 TRUE, /* partial_inplace */
146be91a 162 0xffffffff, /* src_mask */
252b5132 163 0xffffffff, /* dst_mask */
b34976b6 164 TRUE), /* pcrel_offset */
252b5132
RH
165
166 /* 8 bit PC relative branch divided by 2. */
167 HOWTO (R_SH_DIR8WPN, /* type */
168 1, /* rightshift */
169 1, /* size (0 = byte, 1 = short, 2 = long) */
170 8, /* bitsize */
b34976b6 171 TRUE, /* pc_relative */
252b5132
RH
172 0, /* bitpos */
173 complain_overflow_signed, /* complain_on_overflow */
015551fc 174 sh_elf_ignore_reloc, /* special_function */
252b5132 175 "R_SH_DIR8WPN", /* name */
b34976b6 176 TRUE, /* partial_inplace */
252b5132
RH
177 0xff, /* src_mask */
178 0xff, /* dst_mask */
b34976b6 179 TRUE), /* pcrel_offset */
252b5132
RH
180
181 /* 12 bit PC relative branch divided by 2. */
bdfaef52
JR
182 /* This cannot be partial_inplace because relaxation can't know the
183 eventual value of a symbol. */
252b5132
RH
184 HOWTO (R_SH_IND12W, /* type */
185 1, /* rightshift */
186 1, /* size (0 = byte, 1 = short, 2 = long) */
187 12, /* bitsize */
b34976b6 188 TRUE, /* pc_relative */
252b5132
RH
189 0, /* bitpos */
190 complain_overflow_signed, /* complain_on_overflow */
bdfaef52 191 NULL, /* special_function */
252b5132 192 "R_SH_IND12W", /* name */
bdfaef52
JR
193 FALSE, /* partial_inplace */
194 0x0, /* src_mask */
252b5132 195 0xfff, /* dst_mask */
b34976b6 196 TRUE), /* pcrel_offset */
252b5132
RH
197
198 /* 8 bit unsigned PC relative divided by 4. */
199 HOWTO (R_SH_DIR8WPL, /* type */
200 2, /* rightshift */
201 1, /* size (0 = byte, 1 = short, 2 = long) */
202 8, /* bitsize */
b34976b6 203 TRUE, /* pc_relative */
252b5132
RH
204 0, /* bitpos */
205 complain_overflow_unsigned, /* complain_on_overflow */
015551fc 206 sh_elf_ignore_reloc, /* special_function */
252b5132 207 "R_SH_DIR8WPL", /* name */
b34976b6 208 TRUE, /* partial_inplace */
252b5132
RH
209 0xff, /* src_mask */
210 0xff, /* dst_mask */
b34976b6 211 TRUE), /* pcrel_offset */
252b5132
RH
212
213 /* 8 bit unsigned PC relative divided by 2. */
214 HOWTO (R_SH_DIR8WPZ, /* type */
215 1, /* rightshift */
216 1, /* size (0 = byte, 1 = short, 2 = long) */
217 8, /* bitsize */
b34976b6 218 TRUE, /* pc_relative */
252b5132
RH
219 0, /* bitpos */
220 complain_overflow_unsigned, /* complain_on_overflow */
015551fc 221 sh_elf_ignore_reloc, /* special_function */
252b5132 222 "R_SH_DIR8WPZ", /* name */
b34976b6 223 TRUE, /* partial_inplace */
252b5132
RH
224 0xff, /* src_mask */
225 0xff, /* dst_mask */
b34976b6 226 TRUE), /* pcrel_offset */
252b5132
RH
227
228 /* 8 bit GBR relative. FIXME: This only makes sense if we have some
229 special symbol for the GBR relative area, and that is not
230 implemented. */
231 HOWTO (R_SH_DIR8BP, /* type */
232 0, /* rightshift */
233 1, /* size (0 = byte, 1 = short, 2 = long) */
234 8, /* bitsize */
b34976b6 235 FALSE, /* pc_relative */
252b5132
RH
236 0, /* bitpos */
237 complain_overflow_unsigned, /* complain_on_overflow */
015551fc 238 sh_elf_ignore_reloc, /* special_function */
252b5132 239 "R_SH_DIR8BP", /* name */
b34976b6 240 FALSE, /* partial_inplace */
252b5132
RH
241 0, /* src_mask */
242 0xff, /* dst_mask */
b34976b6 243 TRUE), /* pcrel_offset */
252b5132
RH
244
245 /* 8 bit GBR relative divided by 2. FIXME: This only makes sense if
246 we have some special symbol for the GBR relative area, and that
247 is not implemented. */
248 HOWTO (R_SH_DIR8W, /* type */
249 1, /* rightshift */
250 1, /* size (0 = byte, 1 = short, 2 = long) */
251 8, /* bitsize */
b34976b6 252 FALSE, /* pc_relative */
252b5132
RH
253 0, /* bitpos */
254 complain_overflow_unsigned, /* complain_on_overflow */
015551fc 255 sh_elf_ignore_reloc, /* special_function */
252b5132 256 "R_SH_DIR8W", /* name */
b34976b6 257 FALSE, /* partial_inplace */
252b5132
RH
258 0, /* src_mask */
259 0xff, /* dst_mask */
b34976b6 260 TRUE), /* pcrel_offset */
252b5132
RH
261
262 /* 8 bit GBR relative divided by 4. FIXME: This only makes sense if
263 we have some special symbol for the GBR relative area, and that
264 is not implemented. */
265 HOWTO (R_SH_DIR8L, /* type */
266 2, /* rightshift */
267 1, /* size (0 = byte, 1 = short, 2 = long) */
268 8, /* bitsize */
b34976b6 269 FALSE, /* pc_relative */
252b5132
RH
270 0, /* bitpos */
271 complain_overflow_unsigned, /* complain_on_overflow */
015551fc 272 sh_elf_ignore_reloc, /* special_function */
252b5132 273 "R_SH_DIR8L", /* name */
b34976b6 274 FALSE, /* partial_inplace */
252b5132
RH
275 0, /* src_mask */
276 0xff, /* dst_mask */
b34976b6 277 TRUE), /* pcrel_offset */
252b5132 278
06bb75c1
AO
279 EMPTY_HOWTO (10),
280 EMPTY_HOWTO (11),
281 EMPTY_HOWTO (12),
282 EMPTY_HOWTO (13),
283 EMPTY_HOWTO (14),
284 EMPTY_HOWTO (15),
285 EMPTY_HOWTO (16),
286 EMPTY_HOWTO (17),
5f771d47
ILT
287 EMPTY_HOWTO (18),
288 EMPTY_HOWTO (19),
289 EMPTY_HOWTO (20),
290 EMPTY_HOWTO (21),
291 EMPTY_HOWTO (22),
292 EMPTY_HOWTO (23),
293 EMPTY_HOWTO (24),
252b5132
RH
294
295 /* The remaining relocs are a GNU extension used for relaxing. The
296 final pass of the linker never needs to do anything with any of
297 these relocs. Any required operations are handled by the
298 relaxation code. */
299
300 /* A 16 bit switch table entry. This is generated for an expression
301 such as ``.word L1 - L2''. The offset holds the difference
302 between the reloc address and L2. */
303 HOWTO (R_SH_SWITCH16, /* type */
304 0, /* rightshift */
305 1, /* size (0 = byte, 1 = short, 2 = long) */
306 16, /* bitsize */
b34976b6 307 FALSE, /* pc_relative */
252b5132
RH
308 0, /* bitpos */
309 complain_overflow_unsigned, /* complain_on_overflow */
310 sh_elf_ignore_reloc, /* special_function */
311 "R_SH_SWITCH16", /* name */
b34976b6 312 FALSE, /* partial_inplace */
252b5132
RH
313 0, /* src_mask */
314 0, /* dst_mask */
b34976b6 315 TRUE), /* pcrel_offset */
252b5132
RH
316
317 /* A 32 bit switch table entry. This is generated for an expression
318 such as ``.long L1 - L2''. The offset holds the difference
319 between the reloc address and L2. */
320 HOWTO (R_SH_SWITCH32, /* type */
321 0, /* rightshift */
322 2, /* size (0 = byte, 1 = short, 2 = long) */
323 32, /* bitsize */
b34976b6 324 FALSE, /* pc_relative */
252b5132
RH
325 0, /* bitpos */
326 complain_overflow_unsigned, /* complain_on_overflow */
327 sh_elf_ignore_reloc, /* special_function */
328 "R_SH_SWITCH32", /* name */
b34976b6 329 FALSE, /* partial_inplace */
252b5132
RH
330 0, /* src_mask */
331 0, /* dst_mask */
b34976b6 332 TRUE), /* pcrel_offset */
252b5132
RH
333
334 /* Indicates a .uses pseudo-op. The compiler will generate .uses
335 pseudo-ops when it finds a function call which can be relaxed.
336 The offset field holds the PC relative offset to the instruction
337 which loads the register used in the function call. */
338 HOWTO (R_SH_USES, /* type */
339 0, /* rightshift */
340 1, /* size (0 = byte, 1 = short, 2 = long) */
341 0, /* bitsize */
b34976b6 342 FALSE, /* pc_relative */
252b5132
RH
343 0, /* bitpos */
344 complain_overflow_unsigned, /* complain_on_overflow */
345 sh_elf_ignore_reloc, /* special_function */
346 "R_SH_USES", /* name */
b34976b6 347 FALSE, /* partial_inplace */
252b5132
RH
348 0, /* src_mask */
349 0, /* dst_mask */
b34976b6 350 TRUE), /* pcrel_offset */
252b5132
RH
351
352 /* The assembler will generate this reloc for addresses referred to
353 by the register loads associated with USES relocs. The offset
354 field holds the number of times the address is referenced in the
355 object file. */
356 HOWTO (R_SH_COUNT, /* type */
357 0, /* rightshift */
358 1, /* size (0 = byte, 1 = short, 2 = long) */
359 0, /* bitsize */
b34976b6 360 FALSE, /* pc_relative */
252b5132
RH
361 0, /* bitpos */
362 complain_overflow_unsigned, /* complain_on_overflow */
363 sh_elf_ignore_reloc, /* special_function */
364 "R_SH_COUNT", /* name */
b34976b6 365 FALSE, /* partial_inplace */
252b5132
RH
366 0, /* src_mask */
367 0, /* dst_mask */
b34976b6 368 TRUE), /* pcrel_offset */
252b5132
RH
369
370 /* Indicates an alignment statement. The offset field is the power
371 of 2 to which subsequent portions of the object file must be
372 aligned. */
373 HOWTO (R_SH_ALIGN, /* type */
374 0, /* rightshift */
375 1, /* size (0 = byte, 1 = short, 2 = long) */
376 0, /* bitsize */
b34976b6 377 FALSE, /* pc_relative */
252b5132
RH
378 0, /* bitpos */
379 complain_overflow_unsigned, /* complain_on_overflow */
380 sh_elf_ignore_reloc, /* special_function */
381 "R_SH_ALIGN", /* name */
b34976b6 382 FALSE, /* partial_inplace */
252b5132
RH
383 0, /* src_mask */
384 0, /* dst_mask */
b34976b6 385 TRUE), /* pcrel_offset */
252b5132
RH
386
387 /* The assembler will generate this reloc before a block of
388 instructions. A section should be processed as assumining it
389 contains data, unless this reloc is seen. */
390 HOWTO (R_SH_CODE, /* type */
391 0, /* rightshift */
392 1, /* size (0 = byte, 1 = short, 2 = long) */
393 0, /* bitsize */
b34976b6 394 FALSE, /* pc_relative */
252b5132
RH
395 0, /* bitpos */
396 complain_overflow_unsigned, /* complain_on_overflow */
397 sh_elf_ignore_reloc, /* special_function */
398 "R_SH_CODE", /* name */
b34976b6 399 FALSE, /* partial_inplace */
252b5132
RH
400 0, /* src_mask */
401 0, /* dst_mask */
b34976b6 402 TRUE), /* pcrel_offset */
252b5132
RH
403
404 /* The assembler will generate this reloc after a block of
405 instructions when it sees data that is not instructions. */
406 HOWTO (R_SH_DATA, /* type */
407 0, /* rightshift */
408 1, /* size (0 = byte, 1 = short, 2 = long) */
409 0, /* bitsize */
b34976b6 410 FALSE, /* pc_relative */
252b5132
RH
411 0, /* bitpos */
412 complain_overflow_unsigned, /* complain_on_overflow */
413 sh_elf_ignore_reloc, /* special_function */
414 "R_SH_DATA", /* name */
b34976b6 415 FALSE, /* partial_inplace */
252b5132
RH
416 0, /* src_mask */
417 0, /* dst_mask */
b34976b6 418 TRUE), /* pcrel_offset */
252b5132
RH
419
420 /* The assembler generates this reloc for each label within a block
421 of instructions. This permits the linker to avoid swapping
422 instructions which are the targets of branches. */
423 HOWTO (R_SH_LABEL, /* type */
424 0, /* rightshift */
425 1, /* size (0 = byte, 1 = short, 2 = long) */
426 0, /* bitsize */
b34976b6 427 FALSE, /* pc_relative */
252b5132
RH
428 0, /* bitpos */
429 complain_overflow_unsigned, /* complain_on_overflow */
430 sh_elf_ignore_reloc, /* special_function */
431 "R_SH_LABEL", /* name */
b34976b6 432 FALSE, /* partial_inplace */
252b5132
RH
433 0, /* src_mask */
434 0, /* dst_mask */
b34976b6 435 TRUE), /* pcrel_offset */
252b5132
RH
436
437 /* An 8 bit switch table entry. This is generated for an expression
438 such as ``.word L1 - L2''. The offset holds the difference
439 between the reloc address and L2. */
440 HOWTO (R_SH_SWITCH8, /* type */
441 0, /* rightshift */
442 0, /* size (0 = byte, 1 = short, 2 = long) */
443 8, /* bitsize */
b34976b6 444 FALSE, /* pc_relative */
252b5132
RH
445 0, /* bitpos */
446 complain_overflow_unsigned, /* complain_on_overflow */
447 sh_elf_ignore_reloc, /* special_function */
448 "R_SH_SWITCH8", /* name */
b34976b6 449 FALSE, /* partial_inplace */
252b5132
RH
450 0, /* src_mask */
451 0, /* dst_mask */
b34976b6 452 TRUE), /* pcrel_offset */
252b5132
RH
453
454 /* GNU extension to record C++ vtable hierarchy */
455 HOWTO (R_SH_GNU_VTINHERIT, /* type */
067653c5
AM
456 0, /* rightshift */
457 2, /* size (0 = byte, 1 = short, 2 = long) */
458 0, /* bitsize */
b34976b6 459 FALSE, /* pc_relative */
067653c5
AM
460 0, /* bitpos */
461 complain_overflow_dont, /* complain_on_overflow */
462 NULL, /* special_function */
463 "R_SH_GNU_VTINHERIT", /* name */
b34976b6 464 FALSE, /* partial_inplace */
067653c5
AM
465 0, /* src_mask */
466 0, /* dst_mask */
b34976b6 467 FALSE), /* pcrel_offset */
252b5132
RH
468
469 /* GNU extension to record C++ vtable member usage */
470 HOWTO (R_SH_GNU_VTENTRY, /* type */
067653c5
AM
471 0, /* rightshift */
472 2, /* size (0 = byte, 1 = short, 2 = long) */
473 0, /* bitsize */
b34976b6 474 FALSE, /* pc_relative */
067653c5
AM
475 0, /* bitpos */
476 complain_overflow_dont, /* complain_on_overflow */
477 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
478 "R_SH_GNU_VTENTRY", /* name */
b34976b6 479 FALSE, /* partial_inplace */
067653c5
AM
480 0, /* src_mask */
481 0, /* dst_mask */
b34976b6 482 FALSE), /* pcrel_offset */
252b5132 483
015551fc
JR
484 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
485 HOWTO (R_SH_LOOP_START, /* type */
486 1, /* rightshift */
487 1, /* size (0 = byte, 1 = short, 2 = long) */
488 8, /* bitsize */
b34976b6 489 FALSE, /* pc_relative */
015551fc
JR
490 0, /* bitpos */
491 complain_overflow_signed, /* complain_on_overflow */
492 sh_elf_ignore_reloc, /* special_function */
493 "R_SH_LOOP_START", /* name */
b34976b6 494 TRUE, /* partial_inplace */
015551fc
JR
495 0xff, /* src_mask */
496 0xff, /* dst_mask */
b34976b6 497 TRUE), /* pcrel_offset */
015551fc
JR
498
499 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
500 HOWTO (R_SH_LOOP_END, /* type */
501 1, /* rightshift */
502 1, /* size (0 = byte, 1 = short, 2 = long) */
503 8, /* bitsize */
b34976b6 504 FALSE, /* pc_relative */
015551fc
JR
505 0, /* bitpos */
506 complain_overflow_signed, /* complain_on_overflow */
507 sh_elf_ignore_reloc, /* special_function */
508 "R_SH_LOOP_END", /* name */
b34976b6 509 TRUE, /* partial_inplace */
015551fc
JR
510 0xff, /* src_mask */
511 0xff, /* dst_mask */
b34976b6 512 TRUE), /* pcrel_offset */
015551fc 513
06bb75c1
AO
514 EMPTY_HOWTO (38),
515 EMPTY_HOWTO (39),
516 EMPTY_HOWTO (40),
517 EMPTY_HOWTO (41),
518 EMPTY_HOWTO (42),
519 EMPTY_HOWTO (43),
520 EMPTY_HOWTO (44),
fbca6ad9
AO
521
522#ifdef INCLUDE_SHMEDIA
523 /* Used in SHLLI.L and SHLRI.L. */
524 HOWTO (R_SH_DIR5U, /* type */
525 0, /* rightshift */
526 2, /* size (0 = byte, 1 = short, 2 = long) */
527 5, /* bitsize */
b34976b6 528 FALSE, /* pc_relative */
fbca6ad9
AO
529 10, /* bitpos */
530 complain_overflow_unsigned, /* complain_on_overflow */
531 bfd_elf_generic_reloc, /* special_function */
532 "R_SH_DIR5U", /* name */
b34976b6 533 FALSE, /* partial_inplace */
fbca6ad9
AO
534 0, /* src_mask */
535 0xfc00, /* dst_mask */
b34976b6 536 FALSE), /* pcrel_offset */
fbca6ad9
AO
537
538 /* Used in SHARI, SHLLI et al. */
539 HOWTO (R_SH_DIR6U, /* type */
540 0, /* rightshift */
541 2, /* size (0 = byte, 1 = short, 2 = long) */
542 6, /* bitsize */
b34976b6 543 FALSE, /* pc_relative */
fbca6ad9
AO
544 10, /* bitpos */
545 complain_overflow_unsigned, /* complain_on_overflow */
546 bfd_elf_generic_reloc, /* special_function */
547 "R_SH_DIR6U", /* name */
b34976b6 548 FALSE, /* partial_inplace */
fbca6ad9
AO
549 0, /* src_mask */
550 0xfc00, /* dst_mask */
b34976b6 551 FALSE), /* pcrel_offset */
fbca6ad9
AO
552
553 /* Used in BxxI, LDHI.L et al. */
554 HOWTO (R_SH_DIR6S, /* type */
555 0, /* rightshift */
556 2, /* size (0 = byte, 1 = short, 2 = long) */
557 6, /* bitsize */
b34976b6 558 FALSE, /* pc_relative */
fbca6ad9
AO
559 10, /* bitpos */
560 complain_overflow_signed, /* complain_on_overflow */
561 bfd_elf_generic_reloc, /* special_function */
562 "R_SH_DIR6S", /* name */
b34976b6 563 FALSE, /* partial_inplace */
fbca6ad9
AO
564 0, /* src_mask */
565 0xfc00, /* dst_mask */
b34976b6 566 FALSE), /* pcrel_offset */
fbca6ad9
AO
567
568 /* Used in ADDI, ANDI et al. */
569 HOWTO (R_SH_DIR10S, /* type */
570 0, /* rightshift */
571 2, /* size (0 = byte, 1 = short, 2 = long) */
572 10, /* bitsize */
b34976b6 573 FALSE, /* pc_relative */
fbca6ad9
AO
574 10, /* bitpos */
575 complain_overflow_signed, /* complain_on_overflow */
576 bfd_elf_generic_reloc, /* special_function */
577 "R_SH_DIR10S", /* name */
b34976b6 578 FALSE, /* partial_inplace */
fbca6ad9
AO
579 0, /* src_mask */
580 0xffc00, /* dst_mask */
b34976b6 581 FALSE), /* pcrel_offset */
fbca6ad9 582
067653c5 583 /* Used in LD.UW, ST.W et al. */
fbca6ad9
AO
584 HOWTO (R_SH_DIR10SW, /* type */
585 1, /* rightshift */
586 2, /* size (0 = byte, 1 = short, 2 = long) */
587 11, /* bitsize */
b34976b6 588 FALSE, /* pc_relative */
fbca6ad9
AO
589 10, /* bitpos */
590 complain_overflow_signed, /* complain_on_overflow */
591 bfd_elf_generic_reloc, /* special_function */
592 "R_SH_DIR10SW", /* name */
b34976b6 593 FALSE, /* partial_inplace */
fbca6ad9
AO
594 0, /* src_mask */
595 0xffc00, /* dst_mask */
b34976b6 596 FALSE), /* pcrel_offset */
fbca6ad9 597
067653c5 598 /* Used in LD.L, FLD.S et al. */
fbca6ad9
AO
599 HOWTO (R_SH_DIR10SL, /* type */
600 2, /* rightshift */
601 2, /* size (0 = byte, 1 = short, 2 = long) */
602 12, /* bitsize */
b34976b6 603 FALSE, /* pc_relative */
fbca6ad9
AO
604 10, /* bitpos */
605 complain_overflow_signed, /* complain_on_overflow */
606 bfd_elf_generic_reloc, /* special_function */
607 "R_SH_DIR10SL", /* name */
b34976b6 608 FALSE, /* partial_inplace */
fbca6ad9
AO
609 0, /* src_mask */
610 0xffc00, /* dst_mask */
b34976b6 611 FALSE), /* pcrel_offset */
fbca6ad9
AO
612
613 /* Used in FLD.D, FST.P et al. */
614 HOWTO (R_SH_DIR10SQ, /* type */
615 3, /* rightshift */
616 2, /* size (0 = byte, 1 = short, 2 = long) */
617 13, /* bitsize */
b34976b6 618 FALSE, /* pc_relative */
fbca6ad9
AO
619 10, /* bitpos */
620 complain_overflow_signed, /* complain_on_overflow */
621 bfd_elf_generic_reloc, /* special_function */
622 "R_SH_DIR10SQ", /* name */
b34976b6 623 FALSE, /* partial_inplace */
fbca6ad9
AO
624 0, /* src_mask */
625 0xffc00, /* dst_mask */
b34976b6 626 FALSE), /* pcrel_offset */
fbca6ad9
AO
627
628#else
06bb75c1
AO
629 EMPTY_HOWTO (45),
630 EMPTY_HOWTO (46),
631 EMPTY_HOWTO (47),
632 EMPTY_HOWTO (48),
633 EMPTY_HOWTO (49),
634 EMPTY_HOWTO (50),
635 EMPTY_HOWTO (51),
fbca6ad9
AO
636#endif
637
06bb75c1
AO
638 EMPTY_HOWTO (52),
639 EMPTY_HOWTO (53),
640 EMPTY_HOWTO (54),
641 EMPTY_HOWTO (55),
642 EMPTY_HOWTO (56),
643 EMPTY_HOWTO (57),
644 EMPTY_HOWTO (58),
645 EMPTY_HOWTO (59),
646 EMPTY_HOWTO (60),
647 EMPTY_HOWTO (61),
648 EMPTY_HOWTO (62),
649 EMPTY_HOWTO (63),
650 EMPTY_HOWTO (64),
651 EMPTY_HOWTO (65),
652 EMPTY_HOWTO (66),
653 EMPTY_HOWTO (67),
654 EMPTY_HOWTO (68),
655 EMPTY_HOWTO (69),
656 EMPTY_HOWTO (70),
657 EMPTY_HOWTO (71),
658 EMPTY_HOWTO (72),
659 EMPTY_HOWTO (73),
660 EMPTY_HOWTO (74),
661 EMPTY_HOWTO (75),
662 EMPTY_HOWTO (76),
663 EMPTY_HOWTO (77),
664 EMPTY_HOWTO (78),
665 EMPTY_HOWTO (79),
666 EMPTY_HOWTO (80),
667 EMPTY_HOWTO (81),
668 EMPTY_HOWTO (82),
669 EMPTY_HOWTO (83),
670 EMPTY_HOWTO (84),
671 EMPTY_HOWTO (85),
672 EMPTY_HOWTO (86),
673 EMPTY_HOWTO (87),
674 EMPTY_HOWTO (88),
675 EMPTY_HOWTO (89),
676 EMPTY_HOWTO (90),
677 EMPTY_HOWTO (91),
678 EMPTY_HOWTO (92),
679 EMPTY_HOWTO (93),
680 EMPTY_HOWTO (94),
681 EMPTY_HOWTO (95),
682 EMPTY_HOWTO (96),
683 EMPTY_HOWTO (97),
684 EMPTY_HOWTO (98),
685 EMPTY_HOWTO (99),
686 EMPTY_HOWTO (100),
687 EMPTY_HOWTO (101),
688 EMPTY_HOWTO (102),
689 EMPTY_HOWTO (103),
690 EMPTY_HOWTO (104),
691 EMPTY_HOWTO (105),
692 EMPTY_HOWTO (106),
693 EMPTY_HOWTO (107),
694 EMPTY_HOWTO (108),
695 EMPTY_HOWTO (109),
696 EMPTY_HOWTO (110),
697 EMPTY_HOWTO (111),
698 EMPTY_HOWTO (112),
699 EMPTY_HOWTO (113),
700 EMPTY_HOWTO (114),
701 EMPTY_HOWTO (115),
702 EMPTY_HOWTO (116),
703 EMPTY_HOWTO (117),
704 EMPTY_HOWTO (118),
705 EMPTY_HOWTO (119),
706 EMPTY_HOWTO (120),
707 EMPTY_HOWTO (121),
708 EMPTY_HOWTO (122),
709 EMPTY_HOWTO (123),
710 EMPTY_HOWTO (124),
711 EMPTY_HOWTO (125),
712 EMPTY_HOWTO (126),
713 EMPTY_HOWTO (127),
714 EMPTY_HOWTO (128),
715 EMPTY_HOWTO (129),
716 EMPTY_HOWTO (130),
717 EMPTY_HOWTO (131),
718 EMPTY_HOWTO (132),
719 EMPTY_HOWTO (133),
720 EMPTY_HOWTO (134),
721 EMPTY_HOWTO (135),
722 EMPTY_HOWTO (136),
723 EMPTY_HOWTO (137),
724 EMPTY_HOWTO (138),
725 EMPTY_HOWTO (139),
726 EMPTY_HOWTO (140),
727 EMPTY_HOWTO (141),
728 EMPTY_HOWTO (142),
729 EMPTY_HOWTO (143),
3376eaf5
KK
730
731 HOWTO (R_SH_TLS_GD_32, /* type */
732 0, /* rightshift */
733 2, /* size (0 = byte, 1 = short, 2 = long) */
734 32, /* bitsize */
b34976b6 735 FALSE, /* pc_relative */
3376eaf5
KK
736 0, /* bitpos */
737 complain_overflow_bitfield, /* complain_on_overflow */
738 bfd_elf_generic_reloc, /* */
739 "R_SH_TLS_GD_32", /* name */
b34976b6 740 TRUE, /* partial_inplace */
3376eaf5
KK
741 0xffffffff, /* src_mask */
742 0xffffffff, /* dst_mask */
b34976b6 743 FALSE), /* pcrel_offset */
3376eaf5
KK
744
745 HOWTO (R_SH_TLS_LD_32, /* type */
746 0, /* rightshift */
747 2, /* size (0 = byte, 1 = short, 2 = long) */
748 32, /* bitsize */
b34976b6 749 FALSE, /* pc_relative */
3376eaf5
KK
750 0, /* bitpos */
751 complain_overflow_bitfield, /* complain_on_overflow */
752 bfd_elf_generic_reloc, /* */
753 "R_SH_TLS_LD_32", /* name */
b34976b6 754 TRUE, /* partial_inplace */
3376eaf5
KK
755 0xffffffff, /* src_mask */
756 0xffffffff, /* dst_mask */
b34976b6 757 FALSE), /* pcrel_offset */
3376eaf5
KK
758
759 HOWTO (R_SH_TLS_LDO_32, /* type */
760 0, /* rightshift */
761 2, /* size (0 = byte, 1 = short, 2 = long) */
762 32, /* bitsize */
b34976b6 763 FALSE, /* pc_relative */
3376eaf5
KK
764 0, /* bitpos */
765 complain_overflow_bitfield, /* complain_on_overflow */
766 bfd_elf_generic_reloc, /* */
767 "R_SH_TLS_LDO_32", /* name */
b34976b6 768 TRUE, /* partial_inplace */
3376eaf5
KK
769 0xffffffff, /* src_mask */
770 0xffffffff, /* dst_mask */
b34976b6 771 FALSE), /* pcrel_offset */
3376eaf5
KK
772
773 HOWTO (R_SH_TLS_IE_32, /* type */
774 0, /* rightshift */
775 2, /* size (0 = byte, 1 = short, 2 = long) */
776 32, /* bitsize */
b34976b6 777 FALSE, /* pc_relative */
3376eaf5
KK
778 0, /* bitpos */
779 complain_overflow_bitfield, /* complain_on_overflow */
780 bfd_elf_generic_reloc, /* */
781 "R_SH_TLS_IE_32", /* name */
b34976b6 782 TRUE, /* partial_inplace */
3376eaf5
KK
783 0xffffffff, /* src_mask */
784 0xffffffff, /* dst_mask */
b34976b6 785 FALSE), /* pcrel_offset */
3376eaf5
KK
786
787 HOWTO (R_SH_TLS_LE_32, /* type */
788 0, /* rightshift */
789 2, /* size (0 = byte, 1 = short, 2 = long) */
790 32, /* bitsize */
b34976b6 791 FALSE, /* pc_relative */
3376eaf5
KK
792 0, /* bitpos */
793 complain_overflow_bitfield, /* complain_on_overflow */
794 bfd_elf_generic_reloc, /* */
795 "R_SH_TLS_LE_32", /* name */
b34976b6 796 TRUE, /* partial_inplace */
3376eaf5
KK
797 0xffffffff, /* src_mask */
798 0xffffffff, /* dst_mask */
b34976b6 799 FALSE), /* pcrel_offset */
3376eaf5
KK
800
801 HOWTO (R_SH_TLS_DTPMOD32, /* type */
802 0, /* rightshift */
803 2, /* size (0 = byte, 1 = short, 2 = long) */
804 32, /* bitsize */
b34976b6 805 FALSE, /* pc_relative */
3376eaf5
KK
806 0, /* bitpos */
807 complain_overflow_bitfield, /* complain_on_overflow */
808 bfd_elf_generic_reloc, /* */
809 "R_SH_TLS_DTPMOD32", /* name */
b34976b6 810 TRUE, /* partial_inplace */
3376eaf5
KK
811 0xffffffff, /* src_mask */
812 0xffffffff, /* dst_mask */
b34976b6 813 FALSE), /* pcrel_offset */
3376eaf5
KK
814
815 HOWTO (R_SH_TLS_DTPOFF32, /* type */
816 0, /* rightshift */
817 2, /* size (0 = byte, 1 = short, 2 = long) */
818 32, /* bitsize */
b34976b6 819 FALSE, /* pc_relative */
3376eaf5
KK
820 0, /* bitpos */
821 complain_overflow_bitfield, /* complain_on_overflow */
822 bfd_elf_generic_reloc, /* */
823 "R_SH_TLS_DTPOFF32", /* name */
b34976b6 824 TRUE, /* partial_inplace */
3376eaf5
KK
825 0xffffffff, /* src_mask */
826 0xffffffff, /* dst_mask */
b34976b6 827 FALSE), /* pcrel_offset */
3376eaf5
KK
828
829 HOWTO (R_SH_TLS_TPOFF32, /* type */
830 0, /* rightshift */
831 2, /* size (0 = byte, 1 = short, 2 = long) */
832 32, /* bitsize */
b34976b6 833 FALSE, /* pc_relative */
3376eaf5
KK
834 0, /* bitpos */
835 complain_overflow_bitfield, /* complain_on_overflow */
836 bfd_elf_generic_reloc, /* */
837 "R_SH_TLS_TPOFF32", /* name */
b34976b6 838 TRUE, /* partial_inplace */
3376eaf5
KK
839 0xffffffff, /* src_mask */
840 0xffffffff, /* dst_mask */
b34976b6 841 FALSE), /* pcrel_offset */
3376eaf5 842
06bb75c1
AO
843 EMPTY_HOWTO (152),
844 EMPTY_HOWTO (153),
845 EMPTY_HOWTO (154),
846 EMPTY_HOWTO (155),
847 EMPTY_HOWTO (156),
848 EMPTY_HOWTO (157),
849 EMPTY_HOWTO (158),
850 EMPTY_HOWTO (159),
851
852 HOWTO (R_SH_GOT32, /* type */
853 0, /* rightshift */
854 2, /* size (0 = byte, 1 = short, 2 = long) */
855 32, /* bitsize */
b34976b6 856 FALSE, /* pc_relative */
06bb75c1
AO
857 0, /* bitpos */
858 complain_overflow_bitfield, /* complain_on_overflow */
859 bfd_elf_generic_reloc, /* */
860 "R_SH_GOT32", /* name */
b34976b6 861 TRUE, /* partial_inplace */
06bb75c1
AO
862 0xffffffff, /* src_mask */
863 0xffffffff, /* dst_mask */
b34976b6 864 FALSE), /* pcrel_offset */
06bb75c1
AO
865
866 HOWTO (R_SH_PLT32, /* type */
867 0, /* rightshift */
868 2, /* size (0 = byte, 1 = short, 2 = long) */
869 32, /* bitsize */
b34976b6 870 TRUE, /* pc_relative */
06bb75c1
AO
871 0, /* bitpos */
872 complain_overflow_bitfield, /* complain_on_overflow */
873 bfd_elf_generic_reloc, /* */
874 "R_SH_PLT32", /* name */
b34976b6 875 TRUE, /* partial_inplace */
06bb75c1
AO
876 0xffffffff, /* src_mask */
877 0xffffffff, /* dst_mask */
b34976b6 878 TRUE), /* pcrel_offset */
06bb75c1
AO
879
880 HOWTO (R_SH_COPY, /* type */
881 0, /* rightshift */
882 2, /* size (0 = byte, 1 = short, 2 = long) */
883 32, /* bitsize */
b34976b6 884 FALSE, /* pc_relative */
06bb75c1
AO
885 0, /* bitpos */
886 complain_overflow_bitfield, /* complain_on_overflow */
887 bfd_elf_generic_reloc, /* */
888 "R_SH_COPY", /* name */
b34976b6 889 TRUE, /* partial_inplace */
06bb75c1
AO
890 0xffffffff, /* src_mask */
891 0xffffffff, /* dst_mask */
b34976b6 892 FALSE), /* pcrel_offset */
06bb75c1
AO
893
894 HOWTO (R_SH_GLOB_DAT, /* type */
895 0, /* rightshift */
896 2, /* size (0 = byte, 1 = short, 2 = long) */
897 32, /* bitsize */
b34976b6 898 FALSE, /* pc_relative */
06bb75c1
AO
899 0, /* bitpos */
900 complain_overflow_bitfield, /* complain_on_overflow */
901 bfd_elf_generic_reloc, /* */
902 "R_SH_GLOB_DAT", /* name */
b34976b6 903 TRUE, /* partial_inplace */
06bb75c1
AO
904 0xffffffff, /* src_mask */
905 0xffffffff, /* dst_mask */
b34976b6 906 FALSE), /* pcrel_offset */
06bb75c1
AO
907
908 HOWTO (R_SH_JMP_SLOT, /* type */
909 0, /* rightshift */
910 2, /* size (0 = byte, 1 = short, 2 = long) */
911 32, /* bitsize */
b34976b6 912 FALSE, /* pc_relative */
06bb75c1
AO
913 0, /* bitpos */
914 complain_overflow_bitfield, /* complain_on_overflow */
915 bfd_elf_generic_reloc, /* */
916 "R_SH_JMP_SLOT", /* name */
b34976b6 917 TRUE, /* partial_inplace */
06bb75c1
AO
918 0xffffffff, /* src_mask */
919 0xffffffff, /* dst_mask */
b34976b6 920 FALSE), /* pcrel_offset */
06bb75c1
AO
921
922 HOWTO (R_SH_RELATIVE, /* type */
923 0, /* rightshift */
924 2, /* size (0 = byte, 1 = short, 2 = long) */
925 32, /* bitsize */
b34976b6 926 FALSE, /* pc_relative */
06bb75c1
AO
927 0, /* bitpos */
928 complain_overflow_bitfield, /* complain_on_overflow */
929 bfd_elf_generic_reloc, /* */
930 "R_SH_RELATIVE", /* name */
b34976b6 931 TRUE, /* partial_inplace */
06bb75c1
AO
932 0xffffffff, /* src_mask */
933 0xffffffff, /* dst_mask */
b34976b6 934 FALSE), /* pcrel_offset */
06bb75c1
AO
935
936 HOWTO (R_SH_GOTOFF, /* type */
937 0, /* rightshift */
938 2, /* size (0 = byte, 1 = short, 2 = long) */
939 32, /* bitsize */
b34976b6 940 FALSE, /* pc_relative */
06bb75c1
AO
941 0, /* bitpos */
942 complain_overflow_bitfield, /* complain_on_overflow */
943 bfd_elf_generic_reloc, /* */
944 "R_SH_GOTOFF", /* name */
b34976b6 945 TRUE, /* partial_inplace */
06bb75c1
AO
946 0xffffffff, /* src_mask */
947 0xffffffff, /* dst_mask */
b34976b6 948 FALSE), /* pcrel_offset */
06bb75c1
AO
949
950 HOWTO (R_SH_GOTPC, /* type */
951 0, /* rightshift */
952 2, /* size (0 = byte, 1 = short, 2 = long) */
953 32, /* bitsize */
b34976b6 954 TRUE, /* pc_relative */
06bb75c1
AO
955 0, /* bitpos */
956 complain_overflow_bitfield, /* complain_on_overflow */
957 bfd_elf_generic_reloc, /* */
958 "R_SH_GOTPC", /* name */
b34976b6 959 TRUE, /* partial_inplace */
06bb75c1
AO
960 0xffffffff, /* src_mask */
961 0xffffffff, /* dst_mask */
b34976b6 962 TRUE), /* pcrel_offset */
06bb75c1 963
fbca6ad9
AO
964 HOWTO (R_SH_GOTPLT32, /* type */
965 0, /* rightshift */
966 2, /* size (0 = byte, 1 = short, 2 = long) */
967 32, /* bitsize */
b34976b6 968 FALSE, /* pc_relative */
fbca6ad9
AO
969 0, /* bitpos */
970 complain_overflow_bitfield, /* complain_on_overflow */
971 bfd_elf_generic_reloc, /* */
972 "R_SH_GOTPLT32", /* name */
b34976b6 973 FALSE, /* partial_inplace */
fbca6ad9
AO
974 0xffffffff, /* src_mask */
975 0xffffffff, /* dst_mask */
b34976b6 976 FALSE), /* pcrel_offset */
fbca6ad9
AO
977
978#ifdef INCLUDE_SHMEDIA
979 /* Used in MOVI and SHORI (x & 65536). */
980 HOWTO (R_SH_GOT_LOW16, /* type */
981 0, /* rightshift */
982 2, /* size (0 = byte, 1 = short, 2 = long) */
983 64, /* bitsize */
b34976b6 984 FALSE, /* pc_relative */
fbca6ad9
AO
985 10, /* bitpos */
986 complain_overflow_dont, /* complain_on_overflow */
987 bfd_elf_generic_reloc, /* special_function */
067653c5 988 "R_SH_GOT_LOW16", /* name */
b34976b6 989 FALSE, /* partial_inplace */
fbca6ad9
AO
990 0, /* src_mask */
991 0x3fffc00, /* dst_mask */
b34976b6 992 FALSE), /* pcrel_offset */
fbca6ad9
AO
993
994 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
995 HOWTO (R_SH_GOT_MEDLOW16, /* type */
996 16, /* rightshift */
997 2, /* size (0 = byte, 1 = short, 2 = long) */
998 64, /* bitsize */
b34976b6 999 FALSE, /* pc_relative */
fbca6ad9
AO
1000 10, /* bitpos */
1001 complain_overflow_dont, /* complain_on_overflow */
1002 bfd_elf_generic_reloc, /* special_function */
1003 "R_SH_GOT_MEDLOW16", /* name */
b34976b6 1004 FALSE, /* partial_inplace */
fbca6ad9
AO
1005 0, /* src_mask */
1006 0x3fffc00, /* dst_mask */
b34976b6 1007 FALSE), /* pcrel_offset */
fbca6ad9
AO
1008
1009 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1010 HOWTO (R_SH_GOT_MEDHI16, /* type */
1011 32, /* rightshift */
1012 2, /* size (0 = byte, 1 = short, 2 = long) */
1013 64, /* bitsize */
b34976b6 1014 FALSE, /* pc_relative */
fbca6ad9
AO
1015 10, /* bitpos */
1016 complain_overflow_dont, /* complain_on_overflow */
1017 bfd_elf_generic_reloc, /* special_function */
1018 "R_SH_GOT_MEDHI16", /* name */
b34976b6 1019 FALSE, /* partial_inplace */
fbca6ad9
AO
1020 0, /* src_mask */
1021 0x3fffc00, /* dst_mask */
b34976b6 1022 FALSE), /* pcrel_offset */
fbca6ad9
AO
1023
1024 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1025 HOWTO (R_SH_GOT_HI16, /* type */
1026 48, /* rightshift */
1027 2, /* size (0 = byte, 1 = short, 2 = long) */
1028 64, /* bitsize */
b34976b6 1029 FALSE, /* pc_relative */
fbca6ad9
AO
1030 10, /* bitpos */
1031 complain_overflow_dont, /* complain_on_overflow */
1032 bfd_elf_generic_reloc, /* special_function */
1033 "R_SH_GOT_HI16", /* name */
b34976b6 1034 FALSE, /* partial_inplace */
fbca6ad9
AO
1035 0, /* src_mask */
1036 0x3fffc00, /* dst_mask */
b34976b6 1037 FALSE), /* pcrel_offset */
fbca6ad9
AO
1038
1039 /* Used in MOVI and SHORI (x & 65536). */
1040 HOWTO (R_SH_GOTPLT_LOW16, /* type */
1041 0, /* rightshift */
1042 2, /* size (0 = byte, 1 = short, 2 = long) */
1043 64, /* bitsize */
b34976b6 1044 FALSE, /* pc_relative */
fbca6ad9
AO
1045 10, /* bitpos */
1046 complain_overflow_dont, /* complain_on_overflow */
1047 bfd_elf_generic_reloc, /* special_function */
067653c5 1048 "R_SH_GOTPLT_LOW16", /* name */
b34976b6 1049 FALSE, /* partial_inplace */
fbca6ad9
AO
1050 0, /* src_mask */
1051 0x3fffc00, /* dst_mask */
b34976b6 1052 FALSE), /* pcrel_offset */
fbca6ad9
AO
1053
1054 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1055 HOWTO (R_SH_GOTPLT_MEDLOW16, /* type */
1056 16, /* rightshift */
1057 2, /* size (0 = byte, 1 = short, 2 = long) */
1058 64, /* bitsize */
b34976b6 1059 FALSE, /* pc_relative */
fbca6ad9
AO
1060 10, /* bitpos */
1061 complain_overflow_dont, /* complain_on_overflow */
1062 bfd_elf_generic_reloc, /* special_function */
1063 "R_SH_GOTPLT_MEDLOW16", /* name */
b34976b6 1064 FALSE, /* partial_inplace */
fbca6ad9
AO
1065 0, /* src_mask */
1066 0x3fffc00, /* dst_mask */
b34976b6 1067 FALSE), /* pcrel_offset */
fbca6ad9
AO
1068
1069 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1070 HOWTO (R_SH_GOTPLT_MEDHI16, /* type */
1071 32, /* rightshift */
1072 2, /* size (0 = byte, 1 = short, 2 = long) */
1073 64, /* bitsize */
b34976b6 1074 FALSE, /* pc_relative */
fbca6ad9
AO
1075 10, /* bitpos */
1076 complain_overflow_dont, /* complain_on_overflow */
1077 bfd_elf_generic_reloc, /* special_function */
1078 "R_SH_GOTPLT_MEDHI16", /* name */
b34976b6 1079 FALSE, /* partial_inplace */
fbca6ad9
AO
1080 0, /* src_mask */
1081 0x3fffc00, /* dst_mask */
b34976b6 1082 FALSE), /* pcrel_offset */
fbca6ad9
AO
1083
1084 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1085 HOWTO (R_SH_GOTPLT_HI16, /* type */
1086 48, /* rightshift */
1087 2, /* size (0 = byte, 1 = short, 2 = long) */
1088 64, /* bitsize */
b34976b6 1089 FALSE, /* pc_relative */
fbca6ad9
AO
1090 10, /* bitpos */
1091 complain_overflow_dont, /* complain_on_overflow */
1092 bfd_elf_generic_reloc, /* special_function */
1093 "R_SH_GOTPLT_HI16", /* name */
b34976b6 1094 FALSE, /* partial_inplace */
fbca6ad9
AO
1095 0, /* src_mask */
1096 0x3fffc00, /* dst_mask */
b34976b6 1097 FALSE), /* pcrel_offset */
fbca6ad9
AO
1098
1099 /* Used in MOVI and SHORI (x & 65536). */
1100 HOWTO (R_SH_PLT_LOW16, /* type */
1101 0, /* rightshift */
1102 2, /* size (0 = byte, 1 = short, 2 = long) */
1103 64, /* bitsize */
b34976b6 1104 TRUE, /* pc_relative */
fbca6ad9
AO
1105 10, /* bitpos */
1106 complain_overflow_dont, /* complain_on_overflow */
1107 bfd_elf_generic_reloc, /* special_function */
067653c5 1108 "R_SH_PLT_LOW16", /* name */
b34976b6 1109 FALSE, /* partial_inplace */
fbca6ad9
AO
1110 0, /* src_mask */
1111 0x3fffc00, /* dst_mask */
b34976b6 1112 TRUE), /* pcrel_offset */
fbca6ad9
AO
1113
1114 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1115 HOWTO (R_SH_PLT_MEDLOW16, /* type */
1116 16, /* rightshift */
1117 2, /* size (0 = byte, 1 = short, 2 = long) */
1118 64, /* bitsize */
b34976b6 1119 TRUE, /* pc_relative */
fbca6ad9
AO
1120 10, /* bitpos */
1121 complain_overflow_dont, /* complain_on_overflow */
1122 bfd_elf_generic_reloc, /* special_function */
1123 "R_SH_PLT_MEDLOW16", /* name */
b34976b6 1124 FALSE, /* partial_inplace */
fbca6ad9
AO
1125 0, /* src_mask */
1126 0x3fffc00, /* dst_mask */
b34976b6 1127 TRUE), /* pcrel_offset */
fbca6ad9
AO
1128
1129 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1130 HOWTO (R_SH_PLT_MEDHI16, /* type */
1131 32, /* rightshift */
1132 2, /* size (0 = byte, 1 = short, 2 = long) */
1133 64, /* bitsize */
b34976b6 1134 TRUE, /* pc_relative */
fbca6ad9
AO
1135 10, /* bitpos */
1136 complain_overflow_dont, /* complain_on_overflow */
1137 bfd_elf_generic_reloc, /* special_function */
1138 "R_SH_PLT_MEDHI16", /* name */
b34976b6 1139 FALSE, /* partial_inplace */
fbca6ad9
AO
1140 0, /* src_mask */
1141 0x3fffc00, /* dst_mask */
b34976b6 1142 TRUE), /* pcrel_offset */
fbca6ad9
AO
1143
1144 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1145 HOWTO (R_SH_PLT_HI16, /* type */
1146 48, /* rightshift */
1147 2, /* size (0 = byte, 1 = short, 2 = long) */
1148 64, /* bitsize */
b34976b6 1149 TRUE, /* pc_relative */
fbca6ad9
AO
1150 10, /* bitpos */
1151 complain_overflow_dont, /* complain_on_overflow */
1152 bfd_elf_generic_reloc, /* special_function */
1153 "R_SH_PLT_HI16", /* name */
b34976b6 1154 FALSE, /* partial_inplace */
fbca6ad9
AO
1155 0, /* src_mask */
1156 0x3fffc00, /* dst_mask */
b34976b6 1157 TRUE), /* pcrel_offset */
fbca6ad9
AO
1158
1159 /* Used in MOVI and SHORI (x & 65536). */
1160 HOWTO (R_SH_GOTOFF_LOW16, /* type */
1161 0, /* rightshift */
1162 2, /* size (0 = byte, 1 = short, 2 = long) */
1163 64, /* bitsize */
b34976b6 1164 FALSE, /* pc_relative */
fbca6ad9
AO
1165 10, /* bitpos */
1166 complain_overflow_dont, /* complain_on_overflow */
1167 bfd_elf_generic_reloc, /* special_function */
067653c5 1168 "R_SH_GOTOFF_LOW16", /* name */
b34976b6 1169 FALSE, /* partial_inplace */
fbca6ad9
AO
1170 0, /* src_mask */
1171 0x3fffc00, /* dst_mask */
b34976b6 1172 FALSE), /* pcrel_offset */
fbca6ad9
AO
1173
1174 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1175 HOWTO (R_SH_GOTOFF_MEDLOW16, /* type */
1176 16, /* rightshift */
1177 2, /* size (0 = byte, 1 = short, 2 = long) */
1178 64, /* bitsize */
b34976b6 1179 FALSE, /* pc_relative */
fbca6ad9
AO
1180 10, /* bitpos */
1181 complain_overflow_dont, /* complain_on_overflow */
1182 bfd_elf_generic_reloc, /* special_function */
1183 "R_SH_GOTOFF_MEDLOW16", /* name */
b34976b6 1184 FALSE, /* partial_inplace */
fbca6ad9
AO
1185 0, /* src_mask */
1186 0x3fffc00, /* dst_mask */
b34976b6 1187 FALSE), /* pcrel_offset */
fbca6ad9
AO
1188
1189 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1190 HOWTO (R_SH_GOTOFF_MEDHI16, /* type */
1191 32, /* rightshift */
1192 2, /* size (0 = byte, 1 = short, 2 = long) */
1193 64, /* bitsize */
b34976b6 1194 FALSE, /* pc_relative */
fbca6ad9
AO
1195 10, /* bitpos */
1196 complain_overflow_dont, /* complain_on_overflow */
1197 bfd_elf_generic_reloc, /* special_function */
1198 "R_SH_GOTOFF_MEDHI16", /* name */
b34976b6 1199 FALSE, /* partial_inplace */
fbca6ad9
AO
1200 0, /* src_mask */
1201 0x3fffc00, /* dst_mask */
b34976b6 1202 FALSE), /* pcrel_offset */
fbca6ad9
AO
1203
1204 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1205 HOWTO (R_SH_GOTOFF_HI16, /* type */
1206 48, /* rightshift */
1207 2, /* size (0 = byte, 1 = short, 2 = long) */
1208 64, /* bitsize */
b34976b6 1209 FALSE, /* pc_relative */
fbca6ad9
AO
1210 10, /* bitpos */
1211 complain_overflow_dont, /* complain_on_overflow */
1212 bfd_elf_generic_reloc, /* special_function */
1213 "R_SH_GOTOFF_HI16", /* name */
b34976b6 1214 FALSE, /* partial_inplace */
fbca6ad9
AO
1215 0, /* src_mask */
1216 0x3fffc00, /* dst_mask */
b34976b6 1217 FALSE), /* pcrel_offset */
fbca6ad9
AO
1218
1219 /* Used in MOVI and SHORI (x & 65536). */
1220 HOWTO (R_SH_GOTPC_LOW16, /* type */
1221 0, /* rightshift */
1222 2, /* size (0 = byte, 1 = short, 2 = long) */
1223 64, /* bitsize */
b34976b6 1224 TRUE, /* pc_relative */
fbca6ad9
AO
1225 10, /* bitpos */
1226 complain_overflow_dont, /* complain_on_overflow */
1227 bfd_elf_generic_reloc, /* special_function */
067653c5 1228 "R_SH_GOTPC_LOW16", /* name */
b34976b6 1229 FALSE, /* partial_inplace */
fbca6ad9
AO
1230 0, /* src_mask */
1231 0x3fffc00, /* dst_mask */
b34976b6 1232 TRUE), /* pcrel_offset */
fbca6ad9
AO
1233
1234 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1235 HOWTO (R_SH_GOTPC_MEDLOW16, /* type */
1236 16, /* rightshift */
1237 2, /* size (0 = byte, 1 = short, 2 = long) */
1238 64, /* bitsize */
b34976b6 1239 TRUE, /* pc_relative */
fbca6ad9
AO
1240 10, /* bitpos */
1241 complain_overflow_dont, /* complain_on_overflow */
1242 bfd_elf_generic_reloc, /* special_function */
1243 "R_SH_GOTPC_MEDLOW16", /* name */
b34976b6 1244 FALSE, /* partial_inplace */
fbca6ad9
AO
1245 0, /* src_mask */
1246 0x3fffc00, /* dst_mask */
b34976b6 1247 TRUE), /* pcrel_offset */
fbca6ad9
AO
1248
1249 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1250 HOWTO (R_SH_GOTPC_MEDHI16, /* type */
1251 32, /* rightshift */
1252 2, /* size (0 = byte, 1 = short, 2 = long) */
1253 64, /* bitsize */
b34976b6 1254 TRUE, /* pc_relative */
fbca6ad9
AO
1255 10, /* bitpos */
1256 complain_overflow_dont, /* complain_on_overflow */
1257 bfd_elf_generic_reloc, /* special_function */
1258 "R_SH_GOTPC_MEDHI16", /* name */
b34976b6 1259 FALSE, /* partial_inplace */
fbca6ad9
AO
1260 0, /* src_mask */
1261 0x3fffc00, /* dst_mask */
b34976b6 1262 TRUE), /* pcrel_offset */
fbca6ad9
AO
1263
1264 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1265 HOWTO (R_SH_GOTPC_HI16, /* type */
1266 48, /* rightshift */
1267 2, /* size (0 = byte, 1 = short, 2 = long) */
1268 64, /* bitsize */
b34976b6 1269 TRUE, /* pc_relative */
fbca6ad9
AO
1270 10, /* bitpos */
1271 complain_overflow_dont, /* complain_on_overflow */
1272 bfd_elf_generic_reloc, /* special_function */
1273 "R_SH_GOTPC_HI16", /* name */
b34976b6 1274 FALSE, /* partial_inplace */
fbca6ad9
AO
1275 0, /* src_mask */
1276 0x3fffc00, /* dst_mask */
b34976b6 1277 TRUE), /* pcrel_offset */
fbca6ad9 1278
067653c5 1279 /* Used in LD.L, FLD.S et al. */
fbca6ad9
AO
1280 HOWTO (R_SH_GOT10BY4, /* type */
1281 2, /* rightshift */
1282 2, /* size (0 = byte, 1 = short, 2 = long) */
1283 12, /* bitsize */
b34976b6 1284 FALSE, /* pc_relative */
fbca6ad9
AO
1285 10, /* bitpos */
1286 complain_overflow_signed, /* complain_on_overflow */
1287 bfd_elf_generic_reloc, /* special_function */
1288 "R_SH_GOT10BY4", /* name */
b34976b6 1289 FALSE, /* partial_inplace */
fbca6ad9
AO
1290 0, /* src_mask */
1291 0xffc00, /* dst_mask */
b34976b6 1292 FALSE), /* pcrel_offset */
fbca6ad9 1293
067653c5 1294 /* Used in LD.L, FLD.S et al. */
fbca6ad9
AO
1295 HOWTO (R_SH_GOTPLT10BY4, /* type */
1296 2, /* rightshift */
1297 2, /* size (0 = byte, 1 = short, 2 = long) */
1298 12, /* bitsize */
b34976b6 1299 FALSE, /* pc_relative */
fbca6ad9
AO
1300 10, /* bitpos */
1301 complain_overflow_signed, /* complain_on_overflow */
1302 bfd_elf_generic_reloc, /* special_function */
1303 "R_SH_GOTPLT10BY4", /* name */
b34976b6 1304 FALSE, /* partial_inplace */
fbca6ad9
AO
1305 0, /* src_mask */
1306 0xffc00, /* dst_mask */
b34976b6 1307 FALSE), /* pcrel_offset */
fbca6ad9
AO
1308
1309 /* Used in FLD.D, FST.P et al. */
1310 HOWTO (R_SH_GOT10BY8, /* type */
1311 3, /* rightshift */
1312 2, /* size (0 = byte, 1 = short, 2 = long) */
1313 13, /* bitsize */
b34976b6 1314 FALSE, /* pc_relative */
fbca6ad9
AO
1315 10, /* bitpos */
1316 complain_overflow_signed, /* complain_on_overflow */
1317 bfd_elf_generic_reloc, /* special_function */
1318 "R_SH_GOT10BY8", /* name */
b34976b6 1319 FALSE, /* partial_inplace */
fbca6ad9
AO
1320 0, /* src_mask */
1321 0xffc00, /* dst_mask */
b34976b6 1322 FALSE), /* pcrel_offset */
fbca6ad9
AO
1323
1324 /* Used in FLD.D, FST.P et al. */
1325 HOWTO (R_SH_GOTPLT10BY8, /* type */
1326 3, /* rightshift */
1327 2, /* size (0 = byte, 1 = short, 2 = long) */
1328 13, /* bitsize */
b34976b6 1329 FALSE, /* pc_relative */
fbca6ad9
AO
1330 10, /* bitpos */
1331 complain_overflow_signed, /* complain_on_overflow */
1332 bfd_elf_generic_reloc, /* special_function */
1333 "R_SH_GOTPLT10BY8", /* name */
b34976b6 1334 FALSE, /* partial_inplace */
fbca6ad9
AO
1335 0, /* src_mask */
1336 0xffc00, /* dst_mask */
b34976b6 1337 FALSE), /* pcrel_offset */
fbca6ad9
AO
1338
1339 HOWTO (R_SH_COPY64, /* type */
1340 0, /* rightshift */
1341 4, /* size (0 = byte, 1 = short, 2 = long) */
1342 64, /* bitsize */
b34976b6 1343 FALSE, /* pc_relative */
fbca6ad9
AO
1344 0, /* bitpos */
1345 complain_overflow_dont, /* complain_on_overflow */
1346 bfd_elf_generic_reloc, /* special_function */
067653c5 1347 "R_SH_COPY64", /* name */
b34976b6 1348 FALSE, /* partial_inplace */
fbca6ad9
AO
1349 0, /* src_mask */
1350 ((bfd_vma) 0) - 1, /* dst_mask */
b34976b6 1351 FALSE), /* pcrel_offset */
fbca6ad9
AO
1352
1353 HOWTO (R_SH_GLOB_DAT64, /* type */
1354 0, /* rightshift */
1355 4, /* size (0 = byte, 1 = short, 2 = long) */
1356 64, /* bitsize */
b34976b6 1357 FALSE, /* pc_relative */
fbca6ad9
AO
1358 0, /* bitpos */
1359 complain_overflow_dont, /* complain_on_overflow */
1360 bfd_elf_generic_reloc, /* special_function */
067653c5 1361 "R_SH_GLOB_DAT64", /* name */
b34976b6 1362 FALSE, /* partial_inplace */
fbca6ad9
AO
1363 0, /* src_mask */
1364 ((bfd_vma) 0) - 1, /* dst_mask */
b34976b6 1365 FALSE), /* pcrel_offset */
fbca6ad9
AO
1366
1367 HOWTO (R_SH_JMP_SLOT64, /* type */
1368 0, /* rightshift */
1369 4, /* size (0 = byte, 1 = short, 2 = long) */
1370 64, /* bitsize */
b34976b6 1371 FALSE, /* pc_relative */
fbca6ad9
AO
1372 0, /* bitpos */
1373 complain_overflow_dont, /* complain_on_overflow */
1374 bfd_elf_generic_reloc, /* special_function */
067653c5 1375 "R_SH_JMP_SLOT64", /* name */
b34976b6 1376 FALSE, /* partial_inplace */
fbca6ad9
AO
1377 0, /* src_mask */
1378 ((bfd_vma) 0) - 1, /* dst_mask */
b34976b6 1379 FALSE), /* pcrel_offset */
fbca6ad9
AO
1380
1381 HOWTO (R_SH_RELATIVE64, /* type */
1382 0, /* rightshift */
1383 4, /* size (0 = byte, 1 = short, 2 = long) */
1384 64, /* bitsize */
b34976b6 1385 FALSE, /* pc_relative */
fbca6ad9
AO
1386 0, /* bitpos */
1387 complain_overflow_dont, /* complain_on_overflow */
1388 bfd_elf_generic_reloc, /* special_function */
067653c5 1389 "R_SH_RELATIVE64", /* name */
b34976b6 1390 FALSE, /* partial_inplace */
fbca6ad9
AO
1391 0, /* src_mask */
1392 ((bfd_vma) 0) - 1, /* dst_mask */
b34976b6 1393 FALSE), /* pcrel_offset */
fbca6ad9
AO
1394
1395 EMPTY_HOWTO (197),
1396 EMPTY_HOWTO (198),
1397 EMPTY_HOWTO (199),
1398 EMPTY_HOWTO (200),
1399 EMPTY_HOWTO (201),
1400 EMPTY_HOWTO (202),
1401 EMPTY_HOWTO (203),
1402 EMPTY_HOWTO (204),
1403 EMPTY_HOWTO (205),
1404 EMPTY_HOWTO (206),
1405 EMPTY_HOWTO (207),
1406 EMPTY_HOWTO (208),
1407 EMPTY_HOWTO (209),
1408 EMPTY_HOWTO (210),
1409 EMPTY_HOWTO (211),
1410 EMPTY_HOWTO (212),
1411 EMPTY_HOWTO (213),
1412 EMPTY_HOWTO (214),
1413 EMPTY_HOWTO (215),
1414 EMPTY_HOWTO (216),
1415 EMPTY_HOWTO (217),
1416 EMPTY_HOWTO (218),
1417 EMPTY_HOWTO (219),
1418 EMPTY_HOWTO (220),
1419 EMPTY_HOWTO (221),
1420 EMPTY_HOWTO (222),
1421 EMPTY_HOWTO (223),
1422 EMPTY_HOWTO (224),
1423 EMPTY_HOWTO (225),
1424 EMPTY_HOWTO (226),
1425 EMPTY_HOWTO (227),
1426 EMPTY_HOWTO (228),
1427 EMPTY_HOWTO (229),
1428 EMPTY_HOWTO (230),
1429 EMPTY_HOWTO (231),
1430 EMPTY_HOWTO (232),
1431 EMPTY_HOWTO (233),
1432 EMPTY_HOWTO (234),
1433 EMPTY_HOWTO (235),
1434 EMPTY_HOWTO (236),
1435 EMPTY_HOWTO (237),
1436 EMPTY_HOWTO (238),
1437 EMPTY_HOWTO (239),
1438 EMPTY_HOWTO (240),
1439 EMPTY_HOWTO (241),
1440
1441 /* Relocations for SHmedia code. None of these are partial_inplace or
1442 use the field being relocated (except R_SH_PT_16). */
1443
1444 /* The assembler will generate this reloc before a block of SHmedia
1445 instructions. A section should be processed as assuming it contains
1446 data, unless this reloc is seen. Note that a block of SHcompact
1447 instructions are instead preceded by R_SH_CODE.
1448 This is currently not implemented, but should be used for SHmedia
1449 linker relaxation. */
1450 HOWTO (R_SH_SHMEDIA_CODE, /* type */
1451 0, /* rightshift */
1452 1, /* size (0 = byte, 1 = short, 2 = long) */
1453 0, /* bitsize */
b34976b6 1454 FALSE, /* pc_relative */
fbca6ad9
AO
1455 0, /* bitpos */
1456 complain_overflow_unsigned, /* complain_on_overflow */
1457 sh_elf_ignore_reloc, /* special_function */
1458 "R_SH_SHMEDIA_CODE", /* name */
b34976b6 1459 FALSE, /* partial_inplace */
fbca6ad9
AO
1460 0, /* src_mask */
1461 0, /* dst_mask */
b34976b6 1462 FALSE), /* pcrel_offset */
fbca6ad9
AO
1463
1464 /* The assembler will generate this reloc at a PTA or PTB instruction,
1465 and the linker checks the right type of target, or changes a PTA to a
1466 PTB, if the original insn was PT. */
1467 HOWTO (R_SH_PT_16, /* type */
1468 2, /* rightshift */
1469 2, /* size (0 = byte, 1 = short, 2 = long) */
1470 18, /* bitsize */
b34976b6 1471 TRUE, /* pc_relative */
fbca6ad9
AO
1472 10, /* bitpos */
1473 complain_overflow_signed, /* complain_on_overflow */
1474 bfd_elf_generic_reloc, /* special_function */
1475 "R_SH_PT_16", /* name */
b34976b6 1476 FALSE, /* partial_inplace */
fbca6ad9
AO
1477 0, /* src_mask */
1478 0x3fffc00, /* dst_mask */
b34976b6 1479 TRUE), /* pcrel_offset */
fbca6ad9
AO
1480
1481 /* Used in unexpanded MOVI. */
1482 HOWTO (R_SH_IMMS16, /* type */
1483 0, /* rightshift */
1484 2, /* size (0 = byte, 1 = short, 2 = long) */
1485 16, /* bitsize */
b34976b6 1486 FALSE, /* pc_relative */
fbca6ad9
AO
1487 10, /* bitpos */
1488 complain_overflow_signed, /* complain_on_overflow */
1489 bfd_elf_generic_reloc, /* special_function */
1490 "R_SH_IMMS16", /* name */
b34976b6 1491 FALSE, /* partial_inplace */
fbca6ad9
AO
1492 0, /* src_mask */
1493 0x3fffc00, /* dst_mask */
b34976b6 1494 FALSE), /* pcrel_offset */
fbca6ad9
AO
1495
1496 /* Used in SHORI. */
1497 HOWTO (R_SH_IMMU16, /* type */
1498 0, /* rightshift */
1499 2, /* size (0 = byte, 1 = short, 2 = long) */
1500 16, /* bitsize */
b34976b6 1501 FALSE, /* pc_relative */
fbca6ad9
AO
1502 10, /* bitpos */
1503 complain_overflow_unsigned, /* complain_on_overflow */
1504 bfd_elf_generic_reloc, /* special_function */
1505 "R_SH_IMMU16", /* name */
b34976b6 1506 FALSE, /* partial_inplace */
fbca6ad9
AO
1507 0, /* src_mask */
1508 0x3fffc00, /* dst_mask */
b34976b6 1509 FALSE), /* pcrel_offset */
fbca6ad9
AO
1510
1511 /* Used in MOVI and SHORI (x & 65536). */
1512 HOWTO (R_SH_IMM_LOW16, /* type */
1513 0, /* rightshift */
1514 2, /* size (0 = byte, 1 = short, 2 = long) */
1515 64, /* bitsize */
b34976b6 1516 FALSE, /* pc_relative */
fbca6ad9
AO
1517 10, /* bitpos */
1518 complain_overflow_dont, /* complain_on_overflow */
1519 bfd_elf_generic_reloc, /* special_function */
067653c5 1520 "R_SH_IMM_LOW16", /* name */
b34976b6 1521 FALSE, /* partial_inplace */
fbca6ad9
AO
1522 0, /* src_mask */
1523 0x3fffc00, /* dst_mask */
b34976b6 1524 FALSE), /* pcrel_offset */
fbca6ad9
AO
1525
1526 /* Used in MOVI and SHORI ((x - $) & 65536). */
1527 HOWTO (R_SH_IMM_LOW16_PCREL, /* type */
1528 0, /* rightshift */
1529 2, /* size (0 = byte, 1 = short, 2 = long) */
1530 64, /* bitsize */
b34976b6 1531 TRUE, /* pc_relative */
fbca6ad9
AO
1532 10, /* bitpos */
1533 complain_overflow_dont, /* complain_on_overflow */
1534 bfd_elf_generic_reloc, /* special_function */
1535 "R_SH_IMM_LOW16_PCREL", /* name */
b34976b6 1536 FALSE, /* partial_inplace */
fbca6ad9
AO
1537 0, /* src_mask */
1538 0x3fffc00, /* dst_mask */
b34976b6 1539 TRUE), /* pcrel_offset */
fbca6ad9
AO
1540
1541 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1542 HOWTO (R_SH_IMM_MEDLOW16, /* type */
1543 16, /* rightshift */
1544 2, /* size (0 = byte, 1 = short, 2 = long) */
1545 64, /* bitsize */
b34976b6 1546 FALSE, /* pc_relative */
fbca6ad9
AO
1547 10, /* bitpos */
1548 complain_overflow_dont, /* complain_on_overflow */
1549 bfd_elf_generic_reloc, /* special_function */
1550 "R_SH_IMM_MEDLOW16", /* name */
b34976b6 1551 FALSE, /* partial_inplace */
fbca6ad9
AO
1552 0, /* src_mask */
1553 0x3fffc00, /* dst_mask */
b34976b6 1554 FALSE), /* pcrel_offset */
fbca6ad9
AO
1555
1556 /* Used in MOVI and SHORI (((x - $) >> 16) & 65536). */
1557 HOWTO (R_SH_IMM_MEDLOW16_PCREL, /* type */
1558 16, /* rightshift */
1559 2, /* size (0 = byte, 1 = short, 2 = long) */
1560 64, /* bitsize */
b34976b6 1561 TRUE, /* pc_relative */
fbca6ad9
AO
1562 10, /* bitpos */
1563 complain_overflow_dont, /* complain_on_overflow */
1564 bfd_elf_generic_reloc, /* special_function */
1565 "R_SH_IMM_MEDLOW16_PCREL", /* name */
b34976b6 1566 FALSE, /* partial_inplace */
fbca6ad9
AO
1567 0, /* src_mask */
1568 0x3fffc00, /* dst_mask */
b34976b6 1569 TRUE), /* pcrel_offset */
fbca6ad9
AO
1570
1571 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1572 HOWTO (R_SH_IMM_MEDHI16, /* type */
1573 32, /* rightshift */
1574 2, /* size (0 = byte, 1 = short, 2 = long) */
1575 64, /* bitsize */
b34976b6 1576 FALSE, /* pc_relative */
fbca6ad9
AO
1577 10, /* bitpos */
1578 complain_overflow_dont, /* complain_on_overflow */
1579 bfd_elf_generic_reloc, /* special_function */
1580 "R_SH_IMM_MEDHI16", /* name */
b34976b6 1581 FALSE, /* partial_inplace */
fbca6ad9
AO
1582 0, /* src_mask */
1583 0x3fffc00, /* dst_mask */
b34976b6 1584 FALSE), /* pcrel_offset */
fbca6ad9
AO
1585
1586 /* Used in MOVI and SHORI (((x - $) >> 32) & 65536). */
1587 HOWTO (R_SH_IMM_MEDHI16_PCREL, /* type */
1588 32, /* rightshift */
1589 2, /* size (0 = byte, 1 = short, 2 = long) */
1590 64, /* bitsize */
b34976b6 1591 TRUE, /* pc_relative */
fbca6ad9
AO
1592 10, /* bitpos */
1593 complain_overflow_dont, /* complain_on_overflow */
1594 bfd_elf_generic_reloc, /* special_function */
1595 "R_SH_IMM_MEDHI16_PCREL", /* name */
b34976b6 1596 FALSE, /* partial_inplace */
fbca6ad9
AO
1597 0, /* src_mask */
1598 0x3fffc00, /* dst_mask */
b34976b6 1599 TRUE), /* pcrel_offset */
fbca6ad9
AO
1600
1601 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1602 HOWTO (R_SH_IMM_HI16, /* type */
1603 48, /* rightshift */
1604 2, /* size (0 = byte, 1 = short, 2 = long) */
1605 64, /* bitsize */
b34976b6 1606 FALSE, /* pc_relative */
fbca6ad9
AO
1607 10, /* bitpos */
1608 complain_overflow_dont, /* complain_on_overflow */
1609 bfd_elf_generic_reloc, /* special_function */
1610 "R_SH_IMM_HI16", /* name */
b34976b6 1611 FALSE, /* partial_inplace */
fbca6ad9
AO
1612 0, /* src_mask */
1613 0x3fffc00, /* dst_mask */
b34976b6 1614 FALSE), /* pcrel_offset */
fbca6ad9
AO
1615
1616 /* Used in MOVI and SHORI (((x - $) >> 48) & 65536). */
1617 HOWTO (R_SH_IMM_HI16_PCREL, /* type */
1618 48, /* rightshift */
1619 2, /* size (0 = byte, 1 = short, 2 = long) */
1620 64, /* bitsize */
b34976b6 1621 TRUE, /* pc_relative */
fbca6ad9
AO
1622 10, /* bitpos */
1623 complain_overflow_dont, /* complain_on_overflow */
1624 bfd_elf_generic_reloc, /* special_function */
1625 "R_SH_IMM_HI16_PCREL", /* name */
b34976b6 1626 FALSE, /* partial_inplace */
fbca6ad9
AO
1627 0, /* src_mask */
1628 0x3fffc00, /* dst_mask */
b34976b6 1629 TRUE), /* pcrel_offset */
fbca6ad9
AO
1630
1631 /* For the .uaquad pseudo. */
1632 HOWTO (R_SH_64, /* type */
1633 0, /* rightshift */
1634 4, /* size (0 = byte, 1 = short, 2 = long) */
1635 64, /* bitsize */
b34976b6 1636 FALSE, /* pc_relative */
fbca6ad9
AO
1637 0, /* bitpos */
1638 complain_overflow_dont, /* complain_on_overflow */
1639 bfd_elf_generic_reloc, /* special_function */
067653c5 1640 "R_SH_64", /* name */
b34976b6 1641 FALSE, /* partial_inplace */
fbca6ad9
AO
1642 0, /* src_mask */
1643 ((bfd_vma) 0) - 1, /* dst_mask */
b34976b6 1644 FALSE), /* pcrel_offset */
fbca6ad9
AO
1645
1646 /* For the .uaquad pseudo, (x - $). */
1647 HOWTO (R_SH_64_PCREL, /* type */
1648 48, /* rightshift */
1649 2, /* size (0 = byte, 1 = short, 2 = long) */
1650 64, /* bitsize */
b34976b6 1651 TRUE, /* pc_relative */
fbca6ad9
AO
1652 10, /* bitpos */
1653 complain_overflow_dont, /* complain_on_overflow */
1654 bfd_elf_generic_reloc, /* special_function */
1655 "R_SH_64_PCREL", /* name */
b34976b6 1656 FALSE, /* partial_inplace */
fbca6ad9
AO
1657 0, /* src_mask */
1658 ((bfd_vma) 0) - 1, /* dst_mask */
b34976b6 1659 TRUE), /* pcrel_offset */
fbca6ad9
AO
1660
1661#endif
252b5132
RH
1662};
1663
015551fc
JR
1664static bfd_reloc_status_type
1665sh_elf_reloc_loop (r_type, input_bfd, input_section, contents, addr,
435b1e90 1666 symbol_section, start, end)
61ff1804 1667 int r_type ATTRIBUTE_UNUSED;
015551fc
JR
1668 bfd *input_bfd;
1669 asection *input_section;
1670 bfd_byte *contents;
1671 bfd_vma addr;
1672 asection *symbol_section;
1673 bfd_vma start, end;
1674{
1675 static bfd_vma last_addr;
00fdaf47 1676 static asection *last_symbol_section;
015551fc
JR
1677 bfd_byte *start_ptr, *ptr, *last_ptr;
1678 int diff, cum_diff;
1679 bfd_signed_vma x;
1680 int insn;
1681
1682 /* Sanity check the address. */
1683 if (addr > input_section->_raw_size)
1684 return bfd_reloc_outofrange;
1685
1686 /* We require the start and end relocations to be processed consecutively -
1687 although we allow then to be processed forwards or backwards. */
1688 if (! last_addr)
1689 {
1690 last_addr = addr;
1691 last_symbol_section = symbol_section;
1692 return bfd_reloc_ok;
1693 }
1694 if (last_addr != addr)
1695 abort ();
1696 last_addr = 0;
1697
1698 if (! symbol_section || last_symbol_section != symbol_section || end < start)
1699 return bfd_reloc_outofrange;
1700
1701 /* Get the symbol_section contents. */
1702 if (symbol_section != input_section)
1703 {
1704 if (elf_section_data (symbol_section)->this_hdr.contents != NULL)
1705 contents = elf_section_data (symbol_section)->this_hdr.contents;
1706 else
1707 {
dc810e39 1708 contents = (bfd_byte *) bfd_malloc (symbol_section->_raw_size);
015551fc
JR
1709 if (contents == NULL)
1710 return bfd_reloc_outofrange;
1711 if (! bfd_get_section_contents (input_bfd, symbol_section, contents,
1712 (file_ptr) 0,
1713 symbol_section->_raw_size))
1714 {
1715 free (contents);
1716 return bfd_reloc_outofrange;
1717 }
1718 }
1719 }
1720#define IS_PPI(PTR) ((bfd_get_16 (input_bfd, (PTR)) & 0xfc00) == 0xf800)
1721 start_ptr = contents + start;
1722 for (cum_diff = -6, ptr = contents + end; cum_diff < 0 && ptr > start_ptr;)
1723 {
1724 for (last_ptr = ptr, ptr -= 4; ptr >= start_ptr && IS_PPI (ptr);)
1725 ptr -= 2;
1726 ptr += 2;
61ff1804 1727 diff = (last_ptr - ptr) >> 1;
015551fc
JR
1728 cum_diff += diff & 1;
1729 cum_diff += diff;
1730 }
1731 /* Calculate the start / end values to load into rs / re minus four -
1732 so that will cancel out the four we would otherwise have to add to
1733 addr to get the value to subtract in order to get relative addressing. */
1734 if (cum_diff >= 0)
1735 {
1736 start -= 4;
1737 end = (ptr + cum_diff * 2) - contents;
1738 }
1739 else
1740 {
1741 bfd_vma start0 = start - 4;
1742
a0fc8ba1 1743 while (start0 && IS_PPI (contents + start0))
015551fc
JR
1744 start0 -= 2;
1745 start0 = start - 2 - ((start - start0) & 2);
1746 start = start0 - cum_diff - 2;
1747 end = start0;
1748 }
1749
6cdc0ccc
AM
1750 if (contents != NULL
1751 && elf_section_data (symbol_section)->this_hdr.contents != contents)
1752 free (contents);
015551fc
JR
1753
1754 insn = bfd_get_16 (input_bfd, contents + addr);
1755
1756 x = (insn & 0x200 ? end : start) - addr;
1757 if (input_section != symbol_section)
1758 x += ((symbol_section->output_section->vma + symbol_section->output_offset)
1759 - (input_section->output_section->vma
1760 + input_section->output_offset));
1761 x >>= 1;
1762 if (x < -128 || x > 127)
1763 return bfd_reloc_overflow;
1764
61ff1804 1765 x = (insn & ~0xff) | (x & 0xff);
dc810e39 1766 bfd_put_16 (input_bfd, (bfd_vma) x, contents + addr);
015551fc
JR
1767
1768 return bfd_reloc_ok;
1769}
1770
1771/* This function is used for normal relocs. This used to be like the COFF
252b5132
RH
1772 function, and is almost certainly incorrect for other ELF targets. */
1773
1774static bfd_reloc_status_type
1775sh_elf_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd,
435b1e90 1776 error_message)
252b5132
RH
1777 bfd *abfd;
1778 arelent *reloc_entry;
1779 asymbol *symbol_in;
1780 PTR data;
1781 asection *input_section;
1782 bfd *output_bfd;
5f771d47 1783 char **error_message ATTRIBUTE_UNUSED;
252b5132
RH
1784{
1785 unsigned long insn;
1786 bfd_vma sym_value;
1787 enum elf_sh_reloc_type r_type;
1788 bfd_vma addr = reloc_entry->address;
1789 bfd_byte *hit_data = addr + (bfd_byte *) data;
1790
1791 r_type = (enum elf_sh_reloc_type) reloc_entry->howto->type;
1792
1793 if (output_bfd != NULL)
1794 {
1795 /* Partial linking--do nothing. */
1796 reloc_entry->address += input_section->output_offset;
1797 return bfd_reloc_ok;
1798 }
1799
1800 /* Almost all relocs have to do with relaxing. If any work must be
1801 done for them, it has been done in sh_relax_section. */
015551fc 1802 if (r_type == R_SH_IND12W && (symbol_in->flags & BSF_LOCAL) != 0)
252b5132
RH
1803 return bfd_reloc_ok;
1804
1805 if (symbol_in != NULL
1806 && bfd_is_und_section (symbol_in->section))
1807 return bfd_reloc_undefined;
1808
1809 if (bfd_is_com_section (symbol_in->section))
435b1e90
KH
1810 sym_value = 0;
1811 else
252b5132
RH
1812 sym_value = (symbol_in->value +
1813 symbol_in->section->output_section->vma +
1814 symbol_in->section->output_offset);
1815
1816 switch (r_type)
1817 {
1818 case R_SH_DIR32:
1819 insn = bfd_get_32 (abfd, hit_data);
1820 insn += sym_value + reloc_entry->addend;
dc810e39 1821 bfd_put_32 (abfd, (bfd_vma) insn, hit_data);
252b5132
RH
1822 break;
1823 case R_SH_IND12W:
1824 insn = bfd_get_16 (abfd, hit_data);
1825 sym_value += reloc_entry->addend;
1826 sym_value -= (input_section->output_section->vma
1827 + input_section->output_offset
1828 + addr
1829 + 4);
1830 sym_value += (insn & 0xfff) << 1;
1831 if (insn & 0x800)
1832 sym_value -= 0x1000;
1833 insn = (insn & 0xf000) | (sym_value & 0xfff);
dc810e39 1834 bfd_put_16 (abfd, (bfd_vma) insn, hit_data);
252b5132
RH
1835 if (sym_value < (bfd_vma) -0x1000 || sym_value >= 0x1000)
1836 return bfd_reloc_overflow;
1837 break;
1838 default:
1839 abort ();
1840 break;
1841 }
1842
1843 return bfd_reloc_ok;
1844}
1845
1846/* This function is used for relocs which are only used for relaxing,
1847 which the linker should otherwise ignore. */
1848
1849static bfd_reloc_status_type
1850sh_elf_ignore_reloc (abfd, reloc_entry, symbol, data, input_section,
1851 output_bfd, error_message)
5f771d47 1852 bfd *abfd ATTRIBUTE_UNUSED;
252b5132 1853 arelent *reloc_entry;
5f771d47
ILT
1854 asymbol *symbol ATTRIBUTE_UNUSED;
1855 PTR data ATTRIBUTE_UNUSED;
252b5132
RH
1856 asection *input_section;
1857 bfd *output_bfd;
5f771d47 1858 char **error_message ATTRIBUTE_UNUSED;
252b5132
RH
1859{
1860 if (output_bfd != NULL)
1861 reloc_entry->address += input_section->output_offset;
1862 return bfd_reloc_ok;
1863}
1864
1865/* This structure is used to map BFD reloc codes to SH ELF relocs. */
1866
38b1a46c
NC
1867struct elf_reloc_map
1868{
252b5132
RH
1869 bfd_reloc_code_real_type bfd_reloc_val;
1870 unsigned char elf_reloc_val;
1871};
1872
1873/* An array mapping BFD reloc codes to SH ELF relocs. */
1874
38b1a46c
NC
1875static const struct elf_reloc_map sh_reloc_map[] =
1876{
252b5132
RH
1877 { BFD_RELOC_NONE, R_SH_NONE },
1878 { BFD_RELOC_32, R_SH_DIR32 },
1879 { BFD_RELOC_CTOR, R_SH_DIR32 },
1880 { BFD_RELOC_32_PCREL, R_SH_REL32 },
1881 { BFD_RELOC_SH_PCDISP8BY2, R_SH_DIR8WPN },
1882 { BFD_RELOC_SH_PCDISP12BY2, R_SH_IND12W },
1883 { BFD_RELOC_SH_PCRELIMM8BY2, R_SH_DIR8WPZ },
1884 { BFD_RELOC_SH_PCRELIMM8BY4, R_SH_DIR8WPL },
1885 { BFD_RELOC_8_PCREL, R_SH_SWITCH8 },
1886 { BFD_RELOC_SH_SWITCH16, R_SH_SWITCH16 },
1887 { BFD_RELOC_SH_SWITCH32, R_SH_SWITCH32 },
1888 { BFD_RELOC_SH_USES, R_SH_USES },
1889 { BFD_RELOC_SH_COUNT, R_SH_COUNT },
1890 { BFD_RELOC_SH_ALIGN, R_SH_ALIGN },
1891 { BFD_RELOC_SH_CODE, R_SH_CODE },
1892 { BFD_RELOC_SH_DATA, R_SH_DATA },
1893 { BFD_RELOC_SH_LABEL, R_SH_LABEL },
1894 { BFD_RELOC_VTABLE_INHERIT, R_SH_GNU_VTINHERIT },
1895 { BFD_RELOC_VTABLE_ENTRY, R_SH_GNU_VTENTRY },
015551fc
JR
1896 { BFD_RELOC_SH_LOOP_START, R_SH_LOOP_START },
1897 { BFD_RELOC_SH_LOOP_END, R_SH_LOOP_END },
3376eaf5
KK
1898 { BFD_RELOC_SH_TLS_GD_32, R_SH_TLS_GD_32 },
1899 { BFD_RELOC_SH_TLS_LD_32, R_SH_TLS_LD_32 },
1900 { BFD_RELOC_SH_TLS_LDO_32, R_SH_TLS_LDO_32 },
1901 { BFD_RELOC_SH_TLS_IE_32, R_SH_TLS_IE_32 },
1902 { BFD_RELOC_SH_TLS_LE_32, R_SH_TLS_LE_32 },
1903 { BFD_RELOC_SH_TLS_DTPMOD32, R_SH_TLS_DTPMOD32 },
1904 { BFD_RELOC_SH_TLS_DTPOFF32, R_SH_TLS_DTPOFF32 },
1905 { BFD_RELOC_SH_TLS_TPOFF32, R_SH_TLS_TPOFF32 },
37c644f2
AO
1906 { BFD_RELOC_32_GOT_PCREL, R_SH_GOT32 },
1907 { BFD_RELOC_32_PLT_PCREL, R_SH_PLT32 },
1908 { BFD_RELOC_SH_COPY, R_SH_COPY },
1909 { BFD_RELOC_SH_GLOB_DAT, R_SH_GLOB_DAT },
1910 { BFD_RELOC_SH_JMP_SLOT, R_SH_JMP_SLOT },
1911 { BFD_RELOC_SH_RELATIVE, R_SH_RELATIVE },
1912 { BFD_RELOC_32_GOTOFF, R_SH_GOTOFF },
1913 { BFD_RELOC_SH_GOTPC, R_SH_GOTPC },
fbca6ad9
AO
1914 { BFD_RELOC_SH_GOTPLT32, R_SH_GOTPLT32 },
1915#ifdef INCLUDE_SHMEDIA
1916 { BFD_RELOC_SH_GOT_LOW16, R_SH_GOT_LOW16 },
1917 { BFD_RELOC_SH_GOT_MEDLOW16, R_SH_GOT_MEDLOW16 },
1918 { BFD_RELOC_SH_GOT_MEDHI16, R_SH_GOT_MEDHI16 },
1919 { BFD_RELOC_SH_GOT_HI16, R_SH_GOT_HI16 },
1920 { BFD_RELOC_SH_GOTPLT_LOW16, R_SH_GOTPLT_LOW16 },
1921 { BFD_RELOC_SH_GOTPLT_MEDLOW16, R_SH_GOTPLT_MEDLOW16 },
1922 { BFD_RELOC_SH_GOTPLT_MEDHI16, R_SH_GOTPLT_MEDHI16 },
1923 { BFD_RELOC_SH_GOTPLT_HI16, R_SH_GOTPLT_HI16 },
1924 { BFD_RELOC_SH_PLT_LOW16, R_SH_PLT_LOW16 },
1925 { BFD_RELOC_SH_PLT_MEDLOW16, R_SH_PLT_MEDLOW16 },
1926 { BFD_RELOC_SH_PLT_MEDHI16, R_SH_PLT_MEDHI16 },
1927 { BFD_RELOC_SH_PLT_HI16, R_SH_PLT_HI16 },
1928 { BFD_RELOC_SH_GOTOFF_LOW16, R_SH_GOTOFF_LOW16 },
1929 { BFD_RELOC_SH_GOTOFF_MEDLOW16, R_SH_GOTOFF_MEDLOW16 },
1930 { BFD_RELOC_SH_GOTOFF_MEDHI16, R_SH_GOTOFF_MEDHI16 },
1931 { BFD_RELOC_SH_GOTOFF_HI16, R_SH_GOTOFF_HI16 },
1932 { BFD_RELOC_SH_GOTPC_LOW16, R_SH_GOTPC_LOW16 },
1933 { BFD_RELOC_SH_GOTPC_MEDLOW16, R_SH_GOTPC_MEDLOW16 },
1934 { BFD_RELOC_SH_GOTPC_MEDHI16, R_SH_GOTPC_MEDHI16 },
1935 { BFD_RELOC_SH_GOTPC_HI16, R_SH_GOTPC_HI16 },
1936 { BFD_RELOC_SH_COPY64, R_SH_COPY64 },
1937 { BFD_RELOC_SH_GLOB_DAT64, R_SH_GLOB_DAT64 },
1938 { BFD_RELOC_SH_JMP_SLOT64, R_SH_JMP_SLOT64 },
1939 { BFD_RELOC_SH_RELATIVE64, R_SH_RELATIVE64 },
1940 { BFD_RELOC_SH_GOT10BY4, R_SH_GOT10BY4 },
1941 { BFD_RELOC_SH_GOT10BY8, R_SH_GOT10BY8 },
1942 { BFD_RELOC_SH_GOTPLT10BY4, R_SH_GOTPLT10BY4 },
1943 { BFD_RELOC_SH_GOTPLT10BY8, R_SH_GOTPLT10BY8 },
1944 { BFD_RELOC_SH_PT_16, R_SH_PT_16 },
1945 { BFD_RELOC_SH_SHMEDIA_CODE, R_SH_SHMEDIA_CODE },
1946 { BFD_RELOC_SH_IMMU5, R_SH_DIR5U },
1947 { BFD_RELOC_SH_IMMS6, R_SH_DIR6S },
1948 { BFD_RELOC_SH_IMMU6, R_SH_DIR6U },
1949 { BFD_RELOC_SH_IMMS10, R_SH_DIR10S },
1950 { BFD_RELOC_SH_IMMS10BY2, R_SH_DIR10SW },
1951 { BFD_RELOC_SH_IMMS10BY4, R_SH_DIR10SL },
1952 { BFD_RELOC_SH_IMMS10BY8, R_SH_DIR10SQ },
1953 { BFD_RELOC_SH_IMMS16, R_SH_IMMS16 },
1954 { BFD_RELOC_SH_IMMU16, R_SH_IMMU16 },
1955 { BFD_RELOC_SH_IMM_LOW16, R_SH_IMM_LOW16 },
1956 { BFD_RELOC_SH_IMM_LOW16_PCREL, R_SH_IMM_LOW16_PCREL },
1957 { BFD_RELOC_SH_IMM_MEDLOW16, R_SH_IMM_MEDLOW16 },
1958 { BFD_RELOC_SH_IMM_MEDLOW16_PCREL, R_SH_IMM_MEDLOW16_PCREL },
1959 { BFD_RELOC_SH_IMM_MEDHI16, R_SH_IMM_MEDHI16 },
1960 { BFD_RELOC_SH_IMM_MEDHI16_PCREL, R_SH_IMM_MEDHI16_PCREL },
1961 { BFD_RELOC_SH_IMM_HI16, R_SH_IMM_HI16 },
1962 { BFD_RELOC_SH_IMM_HI16_PCREL, R_SH_IMM_HI16_PCREL },
1963 { BFD_RELOC_64, R_SH_64 },
1964 { BFD_RELOC_64_PCREL, R_SH_64_PCREL },
1965#endif /* not INCLUDE_SHMEDIA */
252b5132
RH
1966};
1967
1968/* Given a BFD reloc code, return the howto structure for the
1969 corresponding SH ELf reloc. */
1970
1971static reloc_howto_type *
1972sh_elf_reloc_type_lookup (abfd, code)
5f771d47 1973 bfd *abfd ATTRIBUTE_UNUSED;
252b5132
RH
1974 bfd_reloc_code_real_type code;
1975{
1976 unsigned int i;
1977
1978 for (i = 0; i < sizeof (sh_reloc_map) / sizeof (struct elf_reloc_map); i++)
1979 {
1980 if (sh_reloc_map[i].bfd_reloc_val == code)
1981 return &sh_elf_howto_table[(int) sh_reloc_map[i].elf_reloc_val];
1982 }
1983
1984 return NULL;
1985}
1986
1987/* Given an ELF reloc, fill in the howto field of a relent. */
1988
1989static void
1990sh_elf_info_to_howto (abfd, cache_ptr, dst)
5f771d47 1991 bfd *abfd ATTRIBUTE_UNUSED;
252b5132
RH
1992 arelent *cache_ptr;
1993 Elf_Internal_Rela *dst;
1994{
1995 unsigned int r;
1996
1997 r = ELF32_R_TYPE (dst->r_info);
1998
1999 BFD_ASSERT (r < (unsigned int) R_SH_max);
2000 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC || r > R_SH_LAST_INVALID_RELOC);
06bb75c1 2001 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_2 || r > R_SH_LAST_INVALID_RELOC_2);
fbca6ad9
AO
2002 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_3 || r > R_SH_LAST_INVALID_RELOC_3);
2003 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_4 || r > R_SH_LAST_INVALID_RELOC_4);
3376eaf5 2004 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_5 || r > R_SH_LAST_INVALID_RELOC_5);
252b5132
RH
2005
2006 cache_ptr->howto = &sh_elf_howto_table[r];
2007}
2008\f
2009/* This function handles relaxing for SH ELF. See the corresponding
2010 function in coff-sh.c for a description of what this does. FIXME:
2011 There is a lot of duplication here between this code and the COFF
2012 specific code. The format of relocs and symbols is wound deeply
2013 into this code, but it would still be better if the duplication
2014 could be eliminated somehow. Note in particular that although both
2015 functions use symbols like R_SH_CODE, those symbols have different
2016 values; in coff-sh.c they come from include/coff/sh.h, whereas here
2017 they come from enum elf_sh_reloc_type in include/elf/sh.h. */
2018
b34976b6 2019static bfd_boolean
252b5132
RH
2020sh_elf_relax_section (abfd, sec, link_info, again)
2021 bfd *abfd;
2022 asection *sec;
2023 struct bfd_link_info *link_info;
b34976b6 2024 bfd_boolean *again;
252b5132
RH
2025{
2026 Elf_Internal_Shdr *symtab_hdr;
2027 Elf_Internal_Rela *internal_relocs;
b34976b6 2028 bfd_boolean have_code;
252b5132
RH
2029 Elf_Internal_Rela *irel, *irelend;
2030 bfd_byte *contents = NULL;
6cdc0ccc 2031 Elf_Internal_Sym *isymbuf = NULL;
252b5132 2032
b34976b6 2033 *again = FALSE;
252b5132
RH
2034
2035 if (link_info->relocateable
2036 || (sec->flags & SEC_RELOC) == 0
2037 || sec->reloc_count == 0)
b34976b6 2038 return TRUE;
252b5132 2039
fbca6ad9
AO
2040#ifdef INCLUDE_SHMEDIA
2041 if (elf_section_data (sec)->this_hdr.sh_flags
2042 & (SHF_SH5_ISA32 | SHF_SH5_ISA32_MIXED))
2043 {
b34976b6 2044 return TRUE;
fbca6ad9
AO
2045 }
2046#endif
2047
252b5132
RH
2048 /* If this is the first time we have been called for this section,
2049 initialize the cooked size. */
2050 if (sec->_cooked_size == 0)
2051 sec->_cooked_size = sec->_raw_size;
2052
2053 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2054
2055 internal_relocs = (_bfd_elf32_link_read_relocs
2056 (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
2057 link_info->keep_memory));
2058 if (internal_relocs == NULL)
2059 goto error_return;
252b5132 2060
b34976b6 2061 have_code = FALSE;
252b5132
RH
2062
2063 irelend = internal_relocs + sec->reloc_count;
2064 for (irel = internal_relocs; irel < irelend; irel++)
2065 {
2066 bfd_vma laddr, paddr, symval;
2067 unsigned short insn;
2068 Elf_Internal_Rela *irelfn, *irelscan, *irelcount;
2069 bfd_signed_vma foff;
2070
2071 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_CODE)
b34976b6 2072 have_code = TRUE;
252b5132
RH
2073
2074 if (ELF32_R_TYPE (irel->r_info) != (int) R_SH_USES)
2075 continue;
2076
2077 /* Get the section contents. */
2078 if (contents == NULL)
2079 {
2080 if (elf_section_data (sec)->this_hdr.contents != NULL)
2081 contents = elf_section_data (sec)->this_hdr.contents;
2082 else
2083 {
2084 contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
2085 if (contents == NULL)
2086 goto error_return;
252b5132
RH
2087
2088 if (! bfd_get_section_contents (abfd, sec, contents,
2089 (file_ptr) 0, sec->_raw_size))
2090 goto error_return;
2091 }
2092 }
2093
2094 /* The r_addend field of the R_SH_USES reloc will point us to
067653c5
AM
2095 the register load. The 4 is because the r_addend field is
2096 computed as though it were a jump offset, which are based
2097 from 4 bytes after the jump instruction. */
252b5132
RH
2098 laddr = irel->r_offset + 4 + irel->r_addend;
2099 if (laddr >= sec->_raw_size)
2100 {
2101 (*_bfd_error_handler) (_("%s: 0x%lx: warning: bad R_SH_USES offset"),
8f615d07 2102 bfd_archive_filename (abfd),
252b5132
RH
2103 (unsigned long) irel->r_offset);
2104 continue;
2105 }
2106 insn = bfd_get_16 (abfd, contents + laddr);
2107
2108 /* If the instruction is not mov.l NN,rN, we don't know what to
067653c5 2109 do. */
252b5132
RH
2110 if ((insn & 0xf000) != 0xd000)
2111 {
2112 ((*_bfd_error_handler)
2113 (_("%s: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x"),
8f615d07 2114 bfd_archive_filename (abfd), (unsigned long) irel->r_offset, insn));
252b5132
RH
2115 continue;
2116 }
2117
2118 /* Get the address from which the register is being loaded. The
99e4ae17
AJ
2119 displacement in the mov.l instruction is quadrupled. It is a
2120 displacement from four bytes after the movl instruction, but,
2121 before adding in the PC address, two least significant bits
2122 of the PC are cleared. We assume that the section is aligned
2123 on a four byte boundary. */
252b5132
RH
2124 paddr = insn & 0xff;
2125 paddr *= 4;
dc810e39 2126 paddr += (laddr + 4) &~ (bfd_vma) 3;
252b5132
RH
2127 if (paddr >= sec->_raw_size)
2128 {
2129 ((*_bfd_error_handler)
2130 (_("%s: 0x%lx: warning: bad R_SH_USES load offset"),
8f615d07 2131 bfd_archive_filename (abfd), (unsigned long) irel->r_offset));
252b5132
RH
2132 continue;
2133 }
2134
2135 /* Get the reloc for the address from which the register is
067653c5
AM
2136 being loaded. This reloc will tell us which function is
2137 actually being called. */
252b5132
RH
2138 for (irelfn = internal_relocs; irelfn < irelend; irelfn++)
2139 if (irelfn->r_offset == paddr
2140 && ELF32_R_TYPE (irelfn->r_info) == (int) R_SH_DIR32)
2141 break;
2142 if (irelfn >= irelend)
2143 {
2144 ((*_bfd_error_handler)
2145 (_("%s: 0x%lx: warning: could not find expected reloc"),
8f615d07 2146 bfd_archive_filename (abfd), (unsigned long) paddr));
252b5132
RH
2147 continue;
2148 }
2149
2150 /* Read this BFD's symbols if we haven't done so already. */
6cdc0ccc 2151 if (isymbuf == NULL && symtab_hdr->sh_info != 0)
252b5132 2152 {
6cdc0ccc
AM
2153 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
2154 if (isymbuf == NULL)
2155 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
2156 symtab_hdr->sh_info, 0,
2157 NULL, NULL, NULL);
2158 if (isymbuf == NULL)
2159 goto error_return;
252b5132
RH
2160 }
2161
2162 /* Get the value of the symbol referred to by the reloc. */
2163 if (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
2164 {
9ad5cbcf 2165 /* A local symbol. */
6cdc0ccc 2166 Elf_Internal_Sym *isym;
252b5132 2167
6cdc0ccc
AM
2168 isym = isymbuf + ELF32_R_SYM (irelfn->r_info);
2169 if (isym->st_shndx
d426c6b0 2170 != (unsigned int) _bfd_elf_section_from_bfd_section (abfd, sec))
252b5132
RH
2171 {
2172 ((*_bfd_error_handler)
2173 (_("%s: 0x%lx: warning: symbol in unexpected section"),
8f615d07 2174 bfd_archive_filename (abfd), (unsigned long) paddr));
252b5132
RH
2175 continue;
2176 }
2177
6cdc0ccc 2178 symval = (isym->st_value
252b5132
RH
2179 + sec->output_section->vma
2180 + sec->output_offset);
2181 }
2182 else
2183 {
2184 unsigned long indx;
2185 struct elf_link_hash_entry *h;
2186
2187 indx = ELF32_R_SYM (irelfn->r_info) - symtab_hdr->sh_info;
2188 h = elf_sym_hashes (abfd)[indx];
2189 BFD_ASSERT (h != NULL);
2190 if (h->root.type != bfd_link_hash_defined
2191 && h->root.type != bfd_link_hash_defweak)
2192 {
2193 /* This appears to be a reference to an undefined
067653c5
AM
2194 symbol. Just ignore it--it will be caught by the
2195 regular reloc processing. */
252b5132
RH
2196 continue;
2197 }
2198
2199 symval = (h->root.u.def.value
2200 + h->root.u.def.section->output_section->vma
2201 + h->root.u.def.section->output_offset);
2202 }
2203
2204 symval += bfd_get_32 (abfd, contents + paddr);
2205
2206 /* See if this function call can be shortened. */
2207 foff = (symval
2208 - (irel->r_offset
2209 + sec->output_section->vma
2210 + sec->output_offset
2211 + 4));
2212 if (foff < -0x1000 || foff >= 0x1000)
2213 {
2214 /* After all that work, we can't shorten this function call. */
2215 continue;
2216 }
2217
2218 /* Shorten the function call. */
2219
2220 /* For simplicity of coding, we are going to modify the section
2221 contents, the section relocs, and the BFD symbol table. We
2222 must tell the rest of the code not to free up this
2223 information. It would be possible to instead create a table
2224 of changes which have to be made, as is done in coff-mips.c;
2225 that would be more work, but would require less memory when
2226 the linker is run. */
2227
2228 elf_section_data (sec)->relocs = internal_relocs;
252b5132 2229 elf_section_data (sec)->this_hdr.contents = contents;
6cdc0ccc 2230 symtab_hdr->contents = (unsigned char *) isymbuf;
252b5132
RH
2231
2232 /* Replace the jsr with a bsr. */
2233
2234 /* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and
067653c5 2235 replace the jsr with a bsr. */
252b5132 2236 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irelfn->r_info), R_SH_IND12W);
bdfaef52
JR
2237 /* We used to test (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
2238 here, but that only checks if the symbol is an external symbol,
2239 not if the symbol is in a different section. Besides, we need
2240 a consistent meaning for the relocation, so we just assume here that
2241 the value of the symbol is not available. */
2242#if 0
252b5132
RH
2243 if (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
2244 {
2245 /* If this needs to be changed because of future relaxing,
067653c5
AM
2246 it will be handled here like other internal IND12W
2247 relocs. */
252b5132 2248 bfd_put_16 (abfd,
dc810e39 2249 (bfd_vma) 0xb000 | ((foff >> 1) & 0xfff),
252b5132
RH
2250 contents + irel->r_offset);
2251 }
2252 else
bdfaef52 2253#endif
252b5132
RH
2254 {
2255 /* We can't fully resolve this yet, because the external
067653c5
AM
2256 symbol value may be changed by future relaxing. We let
2257 the final link phase handle it. */
dc810e39 2258 bfd_put_16 (abfd, (bfd_vma) 0xb000, contents + irel->r_offset);
252b5132 2259 }
bdfaef52 2260 irel->r_addend = -4;
252b5132
RH
2261
2262 /* See if there is another R_SH_USES reloc referring to the same
067653c5 2263 register load. */
252b5132
RH
2264 for (irelscan = internal_relocs; irelscan < irelend; irelscan++)
2265 if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_USES
2266 && laddr == irelscan->r_offset + 4 + irelscan->r_addend)
2267 break;
2268 if (irelscan < irelend)
2269 {
2270 /* Some other function call depends upon this register load,
2271 and we have not yet converted that function call.
2272 Indeed, we may never be able to convert it. There is
2273 nothing else we can do at this point. */
2274 continue;
2275 }
2276
2277 /* Look for a R_SH_COUNT reloc on the location where the
067653c5
AM
2278 function address is stored. Do this before deleting any
2279 bytes, to avoid confusion about the address. */
252b5132
RH
2280 for (irelcount = internal_relocs; irelcount < irelend; irelcount++)
2281 if (irelcount->r_offset == paddr
2282 && ELF32_R_TYPE (irelcount->r_info) == (int) R_SH_COUNT)
2283 break;
2284
2285 /* Delete the register load. */
2286 if (! sh_elf_relax_delete_bytes (abfd, sec, laddr, 2))
2287 goto error_return;
2288
2289 /* That will change things, so, just in case it permits some
067653c5
AM
2290 other function call to come within range, we should relax
2291 again. Note that this is not required, and it may be slow. */
b34976b6 2292 *again = TRUE;
252b5132
RH
2293
2294 /* Now check whether we got a COUNT reloc. */
2295 if (irelcount >= irelend)
2296 {
2297 ((*_bfd_error_handler)
2298 (_("%s: 0x%lx: warning: could not find expected COUNT reloc"),
8f615d07 2299 bfd_archive_filename (abfd), (unsigned long) paddr));
252b5132
RH
2300 continue;
2301 }
2302
2303 /* The number of uses is stored in the r_addend field. We've
067653c5 2304 just deleted one. */
252b5132
RH
2305 if (irelcount->r_addend == 0)
2306 {
2307 ((*_bfd_error_handler) (_("%s: 0x%lx: warning: bad count"),
8f615d07 2308 bfd_archive_filename (abfd),
252b5132
RH
2309 (unsigned long) paddr));
2310 continue;
2311 }
2312
2313 --irelcount->r_addend;
2314
2315 /* If there are no more uses, we can delete the address. Reload
067653c5
AM
2316 the address from irelfn, in case it was changed by the
2317 previous call to sh_elf_relax_delete_bytes. */
252b5132
RH
2318 if (irelcount->r_addend == 0)
2319 {
2320 if (! sh_elf_relax_delete_bytes (abfd, sec, irelfn->r_offset, 4))
2321 goto error_return;
2322 }
2323
2324 /* We've done all we can with that function call. */
2325 }
2326
2327 /* Look for load and store instructions that we can align on four
2328 byte boundaries. */
bdfaef52
JR
2329 if ((elf_elfheader (abfd)->e_flags & EF_SH_MACH_MASK) != EF_SH4
2330 && have_code)
252b5132 2331 {
b34976b6 2332 bfd_boolean swapped;
252b5132
RH
2333
2334 /* Get the section contents. */
2335 if (contents == NULL)
2336 {
2337 if (elf_section_data (sec)->this_hdr.contents != NULL)
2338 contents = elf_section_data (sec)->this_hdr.contents;
2339 else
2340 {
2341 contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
2342 if (contents == NULL)
2343 goto error_return;
252b5132
RH
2344
2345 if (! bfd_get_section_contents (abfd, sec, contents,
2346 (file_ptr) 0, sec->_raw_size))
2347 goto error_return;
2348 }
2349 }
2350
2351 if (! sh_elf_align_loads (abfd, sec, internal_relocs, contents,
2352 &swapped))
2353 goto error_return;
2354
2355 if (swapped)
2356 {
2357 elf_section_data (sec)->relocs = internal_relocs;
252b5132 2358 elf_section_data (sec)->this_hdr.contents = contents;
6cdc0ccc 2359 symtab_hdr->contents = (unsigned char *) isymbuf;
252b5132
RH
2360 }
2361 }
2362
6cdc0ccc
AM
2363 if (isymbuf != NULL
2364 && symtab_hdr->contents != (unsigned char *) isymbuf)
252b5132
RH
2365 {
2366 if (! link_info->keep_memory)
6cdc0ccc 2367 free (isymbuf);
252b5132
RH
2368 else
2369 {
6cdc0ccc
AM
2370 /* Cache the symbols for elf_link_input_bfd. */
2371 symtab_hdr->contents = (unsigned char *) isymbuf;
252b5132 2372 }
9ad5cbcf
AM
2373 }
2374
6cdc0ccc
AM
2375 if (contents != NULL
2376 && elf_section_data (sec)->this_hdr.contents != contents)
252b5132
RH
2377 {
2378 if (! link_info->keep_memory)
6cdc0ccc
AM
2379 free (contents);
2380 else
252b5132 2381 {
6cdc0ccc
AM
2382 /* Cache the section contents for elf_link_input_bfd. */
2383 elf_section_data (sec)->this_hdr.contents = contents;
252b5132 2384 }
252b5132
RH
2385 }
2386
6cdc0ccc
AM
2387 if (internal_relocs != NULL
2388 && elf_section_data (sec)->relocs != internal_relocs)
2389 free (internal_relocs);
2390
b34976b6 2391 return TRUE;
252b5132
RH
2392
2393 error_return:
6cdc0ccc
AM
2394 if (isymbuf != NULL
2395 && symtab_hdr->contents != (unsigned char *) isymbuf)
2396 free (isymbuf);
2397 if (contents != NULL
2398 && elf_section_data (sec)->this_hdr.contents != contents)
2399 free (contents);
2400 if (internal_relocs != NULL
2401 && elf_section_data (sec)->relocs != internal_relocs)
2402 free (internal_relocs);
9ad5cbcf 2403
b34976b6 2404 return FALSE;
252b5132
RH
2405}
2406
2407/* Delete some bytes from a section while relaxing. FIXME: There is a
2408 lot of duplication between this function and sh_relax_delete_bytes
2409 in coff-sh.c. */
2410
b34976b6 2411static bfd_boolean
252b5132
RH
2412sh_elf_relax_delete_bytes (abfd, sec, addr, count)
2413 bfd *abfd;
2414 asection *sec;
2415 bfd_vma addr;
2416 int count;
2417{
2418 Elf_Internal_Shdr *symtab_hdr;
9ad5cbcf 2419 unsigned int sec_shndx;
252b5132
RH
2420 bfd_byte *contents;
2421 Elf_Internal_Rela *irel, *irelend;
2422 Elf_Internal_Rela *irelalign;
2423 bfd_vma toaddr;
6cdc0ccc 2424 Elf_Internal_Sym *isymbuf, *isym, *isymend;
9ad5cbcf
AM
2425 struct elf_link_hash_entry **sym_hashes;
2426 struct elf_link_hash_entry **end_hashes;
2427 unsigned int symcount;
252b5132
RH
2428 asection *o;
2429
2430 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
6cdc0ccc 2431 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
9ad5cbcf
AM
2432
2433 sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
252b5132
RH
2434
2435 contents = elf_section_data (sec)->this_hdr.contents;
2436
2437 /* The deletion must stop at the next ALIGN reloc for an aligment
2438 power larger than the number of bytes we are deleting. */
2439
2440 irelalign = NULL;
2441 toaddr = sec->_cooked_size;
2442
2443 irel = elf_section_data (sec)->relocs;
2444 irelend = irel + sec->reloc_count;
2445 for (; irel < irelend; irel++)
2446 {
2447 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_ALIGN
2448 && irel->r_offset > addr
2449 && count < (1 << irel->r_addend))
2450 {
2451 irelalign = irel;
2452 toaddr = irel->r_offset;
2453 break;
2454 }
2455 }
2456
2457 /* Actually delete the bytes. */
dc810e39
AM
2458 memmove (contents + addr, contents + addr + count,
2459 (size_t) (toaddr - addr - count));
252b5132
RH
2460 if (irelalign == NULL)
2461 sec->_cooked_size -= count;
2462 else
2463 {
2464 int i;
2465
2466#define NOP_OPCODE (0x0009)
2467
2468 BFD_ASSERT ((count & 1) == 0);
2469 for (i = 0; i < count; i += 2)
dc810e39 2470 bfd_put_16 (abfd, (bfd_vma) NOP_OPCODE, contents + toaddr - count + i);
252b5132
RH
2471 }
2472
2473 /* Adjust all the relocs. */
2474 for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)
2475 {
2476 bfd_vma nraddr, stop;
2477 bfd_vma start = 0;
2478 int insn = 0;
252b5132
RH
2479 int off, adjust, oinsn;
2480 bfd_signed_vma voff = 0;
b34976b6 2481 bfd_boolean overflow;
252b5132
RH
2482
2483 /* Get the new reloc address. */
2484 nraddr = irel->r_offset;
2485 if ((irel->r_offset > addr
2486 && irel->r_offset < toaddr)
2487 || (ELF32_R_TYPE (irel->r_info) == (int) R_SH_ALIGN
2488 && irel->r_offset == toaddr))
2489 nraddr -= count;
2490
2491 /* See if this reloc was for the bytes we have deleted, in which
2492 case we no longer care about it. Don't delete relocs which
2493 represent addresses, though. */
2494 if (irel->r_offset >= addr
2495 && irel->r_offset < addr + count
2496 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_ALIGN
2497 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_CODE
2498 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_DATA
2499 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_LABEL)
2500 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
2501 (int) R_SH_NONE);
2502
2503 /* If this is a PC relative reloc, see if the range it covers
067653c5 2504 includes the bytes we have deleted. */
252b5132
RH
2505 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
2506 {
2507 default:
2508 break;
2509
2510 case R_SH_DIR8WPN:
2511 case R_SH_IND12W:
2512 case R_SH_DIR8WPZ:
2513 case R_SH_DIR8WPL:
2514 start = irel->r_offset;
2515 insn = bfd_get_16 (abfd, contents + nraddr);
2516 break;
2517 }
2518
2519 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
2520 {
2521 default:
2522 start = stop = addr;
2523 break;
2524
2525 case R_SH_DIR32:
2526 /* If this reloc is against a symbol defined in this
067653c5
AM
2527 section, and the symbol will not be adjusted below, we
2528 must check the addend to see it will put the value in
2529 range to be adjusted, and hence must be changed. */
252b5132
RH
2530 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
2531 {
6cdc0ccc
AM
2532 isym = isymbuf + ELF32_R_SYM (irel->r_info);
2533 if (isym->st_shndx == sec_shndx
2534 && (isym->st_value <= addr
2535 || isym->st_value >= toaddr))
252b5132
RH
2536 {
2537 bfd_vma val;
2538
2539 val = bfd_get_32 (abfd, contents + nraddr);
6cdc0ccc 2540 val += isym->st_value;
252b5132
RH
2541 if (val > addr && val < toaddr)
2542 bfd_put_32 (abfd, val - count, contents + nraddr);
2543 }
2544 }
2545 start = stop = addr;
2546 break;
2547
2548 case R_SH_DIR8WPN:
2549 off = insn & 0xff;
2550 if (off & 0x80)
2551 off -= 0x100;
2552 stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
2553 break;
2554
2555 case R_SH_IND12W:
bdfaef52
JR
2556 off = insn & 0xfff;
2557 if (! off)
2558 {
2559 /* This has been made by previous relaxation. Since the
2560 relocation will be against an external symbol, the
2561 final relocation will just do the right thing. */
2562 start = stop = addr;
2563 }
252b5132
RH
2564 else
2565 {
252b5132
RH
2566 if (off & 0x800)
2567 off -= 0x1000;
2568 stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
bdfaef52
JR
2569
2570 /* The addend will be against the section symbol, thus
2571 for adjusting the addend, the relevant start is the
2572 start of the section.
2573 N.B. If we want to abandom in-place changes here and
2574 test directly using symbol + addend, we have to take into
2575 account that the addend has already been adjusted by -4. */
2576 if (stop > addr && stop < toaddr)
2577 irel->r_addend -= count;
252b5132
RH
2578 }
2579 break;
2580
2581 case R_SH_DIR8WPZ:
2582 off = insn & 0xff;
2583 stop = start + 4 + off * 2;
2584 break;
2585
2586 case R_SH_DIR8WPL:
2587 off = insn & 0xff;
435b1e90 2588 stop = (start & ~(bfd_vma) 3) + 4 + off * 4;
252b5132
RH
2589 break;
2590
2591 case R_SH_SWITCH8:
2592 case R_SH_SWITCH16:
2593 case R_SH_SWITCH32:
2594 /* These relocs types represent
2595 .word L2-L1
06e1ba78 2596 The r_addend field holds the difference between the reloc
252b5132
RH
2597 address and L1. That is the start of the reloc, and
2598 adding in the contents gives us the top. We must adjust
06e1ba78
JR
2599 both the r_offset field and the section contents.
2600 N.B. in gas / coff bfd, the elf bfd r_addend is called r_offset,
2601 and the elf bfd r_offset is called r_vaddr. */
252b5132 2602
06e1ba78
JR
2603 stop = irel->r_offset;
2604 start = (bfd_vma) ((bfd_signed_vma) stop - (long) irel->r_addend);
252b5132
RH
2605
2606 if (start > addr
2607 && start < toaddr
2608 && (stop <= addr || stop >= toaddr))
2609 irel->r_addend += count;
2610 else if (stop > addr
2611 && stop < toaddr
2612 && (start <= addr || start >= toaddr))
2613 irel->r_addend -= count;
2614
252b5132
RH
2615 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_SWITCH16)
2616 voff = bfd_get_signed_16 (abfd, contents + nraddr);
2617 else if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_SWITCH8)
2618 voff = bfd_get_8 (abfd, contents + nraddr);
2619 else
2620 voff = bfd_get_signed_32 (abfd, contents + nraddr);
2621 stop = (bfd_vma) ((bfd_signed_vma) start + voff);
2622
2623 break;
2624
2625 case R_SH_USES:
2626 start = irel->r_offset;
2627 stop = (bfd_vma) ((bfd_signed_vma) start
2628 + (long) irel->r_addend
2629 + 4);
2630 break;
2631 }
2632
2633 if (start > addr
2634 && start < toaddr
2635 && (stop <= addr || stop >= toaddr))
2636 adjust = count;
2637 else if (stop > addr
2638 && stop < toaddr
2639 && (start <= addr || start >= toaddr))
2640 adjust = - count;
2641 else
2642 adjust = 0;
2643
2644 if (adjust != 0)
2645 {
2646 oinsn = insn;
b34976b6 2647 overflow = FALSE;
252b5132
RH
2648 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
2649 {
2650 default:
2651 abort ();
2652 break;
2653
2654 case R_SH_DIR8WPN:
2655 case R_SH_DIR8WPZ:
2656 insn += adjust / 2;
2657 if ((oinsn & 0xff00) != (insn & 0xff00))
b34976b6 2658 overflow = TRUE;
dc810e39 2659 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
252b5132
RH
2660 break;
2661
2662 case R_SH_IND12W:
2663 insn += adjust / 2;
2664 if ((oinsn & 0xf000) != (insn & 0xf000))
b34976b6 2665 overflow = TRUE;
dc810e39 2666 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
252b5132
RH
2667 break;
2668
2669 case R_SH_DIR8WPL:
2670 BFD_ASSERT (adjust == count || count >= 4);
2671 if (count >= 4)
2672 insn += adjust / 4;
2673 else
2674 {
2675 if ((irel->r_offset & 3) == 0)
2676 ++insn;
2677 }
2678 if ((oinsn & 0xff00) != (insn & 0xff00))
b34976b6 2679 overflow = TRUE;
dc810e39 2680 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
252b5132
RH
2681 break;
2682
851cde10
JR
2683 case R_SH_SWITCH8:
2684 voff += adjust;
2685 if (voff < 0 || voff >= 0xff)
b34976b6 2686 overflow = TRUE;
851cde10
JR
2687 bfd_put_8 (abfd, voff, contents + nraddr);
2688 break;
2689
252b5132
RH
2690 case R_SH_SWITCH16:
2691 voff += adjust;
2692 if (voff < - 0x8000 || voff >= 0x8000)
b34976b6 2693 overflow = TRUE;
dc810e39 2694 bfd_put_signed_16 (abfd, (bfd_vma) voff, contents + nraddr);
252b5132
RH
2695 break;
2696
2697 case R_SH_SWITCH32:
2698 voff += adjust;
dc810e39 2699 bfd_put_signed_32 (abfd, (bfd_vma) voff, contents + nraddr);
252b5132
RH
2700 break;
2701
2702 case R_SH_USES:
2703 irel->r_addend += adjust;
2704 break;
2705 }
2706
2707 if (overflow)
2708 {
2709 ((*_bfd_error_handler)
2710 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
8f615d07 2711 bfd_archive_filename (abfd), (unsigned long) irel->r_offset));
252b5132 2712 bfd_set_error (bfd_error_bad_value);
b34976b6 2713 return FALSE;
252b5132
RH
2714 }
2715 }
2716
2717 irel->r_offset = nraddr;
2718 }
2719
2720 /* Look through all the other sections. If there contain any IMM32
2721 relocs against internal symbols which we are not going to adjust
2722 below, we may need to adjust the addends. */
2723 for (o = abfd->sections; o != NULL; o = o->next)
2724 {
2725 Elf_Internal_Rela *internal_relocs;
2726 Elf_Internal_Rela *irelscan, *irelscanend;
2727 bfd_byte *ocontents;
2728
2729 if (o == sec
2730 || (o->flags & SEC_RELOC) == 0
2731 || o->reloc_count == 0)
2732 continue;
2733
2734 /* We always cache the relocs. Perhaps, if info->keep_memory is
b34976b6 2735 FALSE, we should free them, if we are permitted to, when we
067653c5 2736 leave sh_coff_relax_section. */
252b5132
RH
2737 internal_relocs = (_bfd_elf32_link_read_relocs
2738 (abfd, o, (PTR) NULL, (Elf_Internal_Rela *) NULL,
b34976b6 2739 TRUE));
252b5132 2740 if (internal_relocs == NULL)
b34976b6 2741 return FALSE;
252b5132
RH
2742
2743 ocontents = NULL;
2744 irelscanend = internal_relocs + o->reloc_count;
2745 for (irelscan = internal_relocs; irelscan < irelscanend; irelscan++)
2746 {
084aa3aa
JR
2747 /* Dwarf line numbers use R_SH_SWITCH32 relocs. */
2748 if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_SWITCH32)
2749 {
2750 bfd_vma start, stop;
2751 bfd_signed_vma voff;
2752
2753 if (ocontents == NULL)
2754 {
2755 if (elf_section_data (o)->this_hdr.contents != NULL)
2756 ocontents = elf_section_data (o)->this_hdr.contents;
2757 else
2758 {
2759 /* We always cache the section contents.
b34976b6 2760 Perhaps, if info->keep_memory is FALSE, we
067653c5
AM
2761 should free them, if we are permitted to,
2762 when we leave sh_coff_relax_section. */
084aa3aa
JR
2763 ocontents = (bfd_byte *) bfd_malloc (o->_raw_size);
2764 if (ocontents == NULL)
b34976b6 2765 return FALSE;
084aa3aa
JR
2766 if (! bfd_get_section_contents (abfd, o, ocontents,
2767 (file_ptr) 0,
2768 o->_raw_size))
b34976b6 2769 return FALSE;
084aa3aa
JR
2770 elf_section_data (o)->this_hdr.contents = ocontents;
2771 }
2772 }
2773
2774 stop = irelscan->r_offset;
2775 start
2776 = (bfd_vma) ((bfd_signed_vma) stop - (long) irelscan->r_addend);
2777
2778 /* STOP is in a different section, so it won't change. */
2779 if (start > addr && start < toaddr)
2780 irelscan->r_addend += count;
2781
2782 voff = bfd_get_signed_32 (abfd, ocontents + irelscan->r_offset);
2783 stop = (bfd_vma) ((bfd_signed_vma) start + voff);
2784
2785 if (start > addr
2786 && start < toaddr
2787 && (stop <= addr || stop >= toaddr))
dc810e39 2788 bfd_put_signed_32 (abfd, (bfd_vma) voff + count,
084aa3aa
JR
2789 ocontents + irelscan->r_offset);
2790 else if (stop > addr
2791 && stop < toaddr
2792 && (start <= addr || start >= toaddr))
dc810e39 2793 bfd_put_signed_32 (abfd, (bfd_vma) voff - count,
084aa3aa
JR
2794 ocontents + irelscan->r_offset);
2795 }
2796
252b5132
RH
2797 if (ELF32_R_TYPE (irelscan->r_info) != (int) R_SH_DIR32)
2798 continue;
2799
2800 if (ELF32_R_SYM (irelscan->r_info) >= symtab_hdr->sh_info)
2801 continue;
2802
252b5132 2803
6cdc0ccc
AM
2804 isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
2805 if (isym->st_shndx == sec_shndx
2806 && (isym->st_value <= addr
2807 || isym->st_value >= toaddr))
252b5132
RH
2808 {
2809 bfd_vma val;
2810
2811 if (ocontents == NULL)
2812 {
2813 if (elf_section_data (o)->this_hdr.contents != NULL)
2814 ocontents = elf_section_data (o)->this_hdr.contents;
2815 else
2816 {
2817 /* We always cache the section contents.
b34976b6 2818 Perhaps, if info->keep_memory is FALSE, we
067653c5
AM
2819 should free them, if we are permitted to,
2820 when we leave sh_coff_relax_section. */
252b5132
RH
2821 ocontents = (bfd_byte *) bfd_malloc (o->_raw_size);
2822 if (ocontents == NULL)
b34976b6 2823 return FALSE;
252b5132
RH
2824 if (! bfd_get_section_contents (abfd, o, ocontents,
2825 (file_ptr) 0,
2826 o->_raw_size))
b34976b6 2827 return FALSE;
252b5132
RH
2828 elf_section_data (o)->this_hdr.contents = ocontents;
2829 }
2830 }
2831
2832 val = bfd_get_32 (abfd, ocontents + irelscan->r_offset);
6cdc0ccc 2833 val += isym->st_value;
252b5132
RH
2834 if (val > addr && val < toaddr)
2835 bfd_put_32 (abfd, val - count,
2836 ocontents + irelscan->r_offset);
2837 }
2838 }
2839 }
2840
2841 /* Adjust the local symbols defined in this section. */
6cdc0ccc
AM
2842 isymend = isymbuf + symtab_hdr->sh_info;
2843 for (isym = isymbuf; isym < isymend; isym++)
252b5132 2844 {
6cdc0ccc
AM
2845 if (isym->st_shndx == sec_shndx
2846 && isym->st_value > addr
2847 && isym->st_value < toaddr)
2848 isym->st_value -= count;
252b5132
RH
2849 }
2850
2851 /* Now adjust the global symbols defined in this section. */
9ad5cbcf
AM
2852 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
2853 - symtab_hdr->sh_info);
2854 sym_hashes = elf_sym_hashes (abfd);
2855 end_hashes = sym_hashes + symcount;
2856 for (; sym_hashes < end_hashes; sym_hashes++)
252b5132 2857 {
9ad5cbcf
AM
2858 struct elf_link_hash_entry *sym_hash = *sym_hashes;
2859 if ((sym_hash->root.type == bfd_link_hash_defined
2860 || sym_hash->root.type == bfd_link_hash_defweak)
2861 && sym_hash->root.u.def.section == sec
2862 && sym_hash->root.u.def.value > addr
2863 && sym_hash->root.u.def.value < toaddr)
252b5132 2864 {
9ad5cbcf 2865 sym_hash->root.u.def.value -= count;
252b5132
RH
2866 }
2867 }
2868
2869 /* See if we can move the ALIGN reloc forward. We have adjusted
2870 r_offset for it already. */
2871 if (irelalign != NULL)
2872 {
2873 bfd_vma alignto, alignaddr;
2874
2875 alignto = BFD_ALIGN (toaddr, 1 << irelalign->r_addend);
2876 alignaddr = BFD_ALIGN (irelalign->r_offset,
2877 1 << irelalign->r_addend);
2878 if (alignto != alignaddr)
2879 {
2880 /* Tail recursion. */
2881 return sh_elf_relax_delete_bytes (abfd, sec, alignaddr,
dc810e39 2882 (int) (alignto - alignaddr));
252b5132
RH
2883 }
2884 }
2885
b34976b6 2886 return TRUE;
252b5132
RH
2887}
2888
2889/* Look for loads and stores which we can align to four byte
2890 boundaries. This is like sh_align_loads in coff-sh.c. */
2891
b34976b6 2892static bfd_boolean
252b5132 2893sh_elf_align_loads (abfd, sec, internal_relocs, contents, pswapped)
518313c3 2894 bfd *abfd ATTRIBUTE_UNUSED;
252b5132
RH
2895 asection *sec;
2896 Elf_Internal_Rela *internal_relocs;
518313c3 2897 bfd_byte *contents ATTRIBUTE_UNUSED;
b34976b6 2898 bfd_boolean *pswapped;
252b5132
RH
2899{
2900 Elf_Internal_Rela *irel, *irelend;
2901 bfd_vma *labels = NULL;
2902 bfd_vma *label, *label_end;
dc810e39 2903 bfd_size_type amt;
252b5132 2904
b34976b6 2905 *pswapped = FALSE;
252b5132
RH
2906
2907 irelend = internal_relocs + sec->reloc_count;
2908
2909 /* Get all the addresses with labels on them. */
dc810e39
AM
2910 amt = sec->reloc_count;
2911 amt *= sizeof (bfd_vma);
2912 labels = (bfd_vma *) bfd_malloc (amt);
252b5132
RH
2913 if (labels == NULL)
2914 goto error_return;
2915 label_end = labels;
2916 for (irel = internal_relocs; irel < irelend; irel++)
2917 {
2918 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_LABEL)
2919 {
2920 *label_end = irel->r_offset;
2921 ++label_end;
2922 }
2923 }
2924
2925 /* Note that the assembler currently always outputs relocs in
2926 address order. If that ever changes, this code will need to sort
2927 the label values and the relocs. */
2928
2929 label = labels;
2930
2931 for (irel = internal_relocs; irel < irelend; irel++)
2932 {
2933 bfd_vma start, stop;
2934
2935 if (ELF32_R_TYPE (irel->r_info) != (int) R_SH_CODE)
2936 continue;
2937
2938 start = irel->r_offset;
2939
2940 for (irel++; irel < irelend; irel++)
2941 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_DATA)
2942 break;
2943 if (irel < irelend)
2944 stop = irel->r_offset;
2945 else
2946 stop = sec->_cooked_size;
2947
2948 if (! _bfd_sh_align_load_span (abfd, sec, contents, sh_elf_swap_insns,
2949 (PTR) internal_relocs, &label,
2950 label_end, start, stop, pswapped))
2951 goto error_return;
2952 }
2953
2954 free (labels);
2955
b34976b6 2956 return TRUE;
252b5132
RH
2957
2958 error_return:
2959 if (labels != NULL)
2960 free (labels);
b34976b6 2961 return FALSE;
252b5132
RH
2962}
2963
2964/* Swap two SH instructions. This is like sh_swap_insns in coff-sh.c. */
2965
b34976b6 2966static bfd_boolean
252b5132
RH
2967sh_elf_swap_insns (abfd, sec, relocs, contents, addr)
2968 bfd *abfd;
2969 asection *sec;
2970 PTR relocs;
2971 bfd_byte *contents;
2972 bfd_vma addr;
2973{
2974 Elf_Internal_Rela *internal_relocs = (Elf_Internal_Rela *) relocs;
2975 unsigned short i1, i2;
2976 Elf_Internal_Rela *irel, *irelend;
2977
2978 /* Swap the instructions themselves. */
2979 i1 = bfd_get_16 (abfd, contents + addr);
2980 i2 = bfd_get_16 (abfd, contents + addr + 2);
dc810e39
AM
2981 bfd_put_16 (abfd, (bfd_vma) i2, contents + addr);
2982 bfd_put_16 (abfd, (bfd_vma) i1, contents + addr + 2);
252b5132
RH
2983
2984 /* Adjust all reloc addresses. */
2985 irelend = internal_relocs + sec->reloc_count;
2986 for (irel = internal_relocs; irel < irelend; irel++)
2987 {
2988 enum elf_sh_reloc_type type;
2989 int add;
2990
2991 /* There are a few special types of relocs that we don't want to
067653c5
AM
2992 adjust. These relocs do not apply to the instruction itself,
2993 but are only associated with the address. */
252b5132
RH
2994 type = (enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info);
2995 if (type == R_SH_ALIGN
2996 || type == R_SH_CODE
2997 || type == R_SH_DATA
2998 || type == R_SH_LABEL)
2999 continue;
3000
3001 /* If an R_SH_USES reloc points to one of the addresses being
067653c5
AM
3002 swapped, we must adjust it. It would be incorrect to do this
3003 for a jump, though, since we want to execute both
3004 instructions after the jump. (We have avoided swapping
3005 around a label, so the jump will not wind up executing an
3006 instruction it shouldn't). */
252b5132
RH
3007 if (type == R_SH_USES)
3008 {
3009 bfd_vma off;
3010
3011 off = irel->r_offset + 4 + irel->r_addend;
3012 if (off == addr)
3013 irel->r_offset += 2;
3014 else if (off == addr + 2)
3015 irel->r_offset -= 2;
3016 }
3017
3018 if (irel->r_offset == addr)
3019 {
3020 irel->r_offset += 2;
3021 add = -2;
3022 }
3023 else if (irel->r_offset == addr + 2)
3024 {
3025 irel->r_offset -= 2;
3026 add = 2;
3027 }
3028 else
3029 add = 0;
3030
3031 if (add != 0)
3032 {
3033 bfd_byte *loc;
3034 unsigned short insn, oinsn;
b34976b6 3035 bfd_boolean overflow;
252b5132
RH
3036
3037 loc = contents + irel->r_offset;
b34976b6 3038 overflow = FALSE;
252b5132
RH
3039 switch (type)
3040 {
3041 default:
3042 break;
3043
3044 case R_SH_DIR8WPN:
3045 case R_SH_DIR8WPZ:
3046 insn = bfd_get_16 (abfd, loc);
3047 oinsn = insn;
3048 insn += add / 2;
3049 if ((oinsn & 0xff00) != (insn & 0xff00))
b34976b6 3050 overflow = TRUE;
dc810e39 3051 bfd_put_16 (abfd, (bfd_vma) insn, loc);
252b5132
RH
3052 break;
3053
3054 case R_SH_IND12W:
3055 insn = bfd_get_16 (abfd, loc);
3056 oinsn = insn;
3057 insn += add / 2;
3058 if ((oinsn & 0xf000) != (insn & 0xf000))
b34976b6 3059 overflow = TRUE;
dc810e39 3060 bfd_put_16 (abfd, (bfd_vma) insn, loc);
252b5132
RH
3061 break;
3062
3063 case R_SH_DIR8WPL:
3064 /* This reloc ignores the least significant 3 bits of
067653c5
AM
3065 the program counter before adding in the offset.
3066 This means that if ADDR is at an even address, the
3067 swap will not affect the offset. If ADDR is an at an
3068 odd address, then the instruction will be crossing a
3069 four byte boundary, and must be adjusted. */
252b5132
RH
3070 if ((addr & 3) != 0)
3071 {
3072 insn = bfd_get_16 (abfd, loc);
3073 oinsn = insn;
3074 insn += add / 2;
3075 if ((oinsn & 0xff00) != (insn & 0xff00))
b34976b6 3076 overflow = TRUE;
dc810e39 3077 bfd_put_16 (abfd, (bfd_vma) insn, loc);
252b5132
RH
3078 }
3079
3080 break;
3081 }
3082
3083 if (overflow)
3084 {
3085 ((*_bfd_error_handler)
3086 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
8f615d07 3087 bfd_archive_filename (abfd), (unsigned long) irel->r_offset));
252b5132 3088 bfd_set_error (bfd_error_bad_value);
b34976b6 3089 return FALSE;
252b5132
RH
3090 }
3091 }
3092 }
3093
b34976b6 3094 return TRUE;
252b5132
RH
3095}
3096\f
fbca6ad9
AO
3097#ifdef INCLUDE_SHMEDIA
3098
3099/* The size in bytes of an entry in the procedure linkage table. */
3100
3101#define PLT_ENTRY_SIZE 64
3102
3103/* First entry in an absolute procedure linkage table look like this. */
3104
3105static const bfd_byte elf_sh_plt0_entry_be[PLT_ENTRY_SIZE] =
3106{
3107 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 16, r17 */
3108 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
3109 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
c8614e8e 3110 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
fbca6ad9
AO
3111 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
3112 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3113 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3114 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3115 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3116 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3117 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3118 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3119 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3120 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3121 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3122 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3123};
3124
3125static const bfd_byte elf_sh_plt0_entry_le[PLT_ENTRY_SIZE] =
3126{
3127 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */
3128 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
3129 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
c8614e8e 3130 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
fbca6ad9
AO
3131 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
3132 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3133 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3134 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3135 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3136 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3137 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3138 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3139 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3140 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3141 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3142 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3143};
3144
3145/* Sebsequent entries in an absolute procedure linkage table look like
3146 this. */
3147
3148static const bfd_byte elf_sh_plt_entry_be[PLT_ENTRY_SIZE] =
3149{
3150 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 16, r25 */
3151 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
3152 0x89, 0x90, 0x01, 0x90, /* ld.l r25, 0, r25 */
3153 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3154 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3155 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3156 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3157 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3158 0xcc, 0x00, 0x01, 0x90, /* movi .PLT0 >> 16, r25 */
3159 0xc8, 0x00, 0x01, 0x90, /* shori .PLT0 & 65535, r25 */
3160 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
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 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3165 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3166};
3167
3168static const bfd_byte elf_sh_plt_entry_le[PLT_ENTRY_SIZE] =
3169{
3170 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */
3171 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
3172 0x90, 0x01, 0x90, 0x89, /* ld.l r25, 0, r25 */
3173 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3174 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3175 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3176 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3177 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3178 0x90, 0x01, 0x00, 0xcc, /* movi .PLT0 >> 16, r25 */
3179 0x90, 0x01, 0x00, 0xc8, /* shori .PLT0 & 65535, r25 */
3180 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
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 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3185 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3186};
3187
3188/* Entries in a PIC procedure linkage table look like this. */
3189
3190static const bfd_byte elf_sh_pic_plt_entry_be[PLT_ENTRY_SIZE] =
3191{
3192 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */
3193 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
3194 0x40, 0xc2, 0x65, 0x90, /* ldx.l r12, r25, r25 */
3195 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3196 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3197 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3198 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3199 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3200 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */
0a4ef3f4 3201 0x00, 0xc8, 0x45, 0x10, /* add.l r12, r17, r17 */
fbca6ad9
AO
3202 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
3203 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3204 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
3205 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3206 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3207 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3208};
3209
3210static const bfd_byte elf_sh_pic_plt_entry_le[PLT_ENTRY_SIZE] =
3211{
3212 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */
3213 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
3214 0x90, 0x65, 0xc2, 0x40, /* ldx.l r12, r25, r25 */
3215 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3216 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3217 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3218 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3219 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3220 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */
0a4ef3f4 3221 0x10, 0x45, 0xc8, 0x00, /* add.l r12, r17, r17 */
fbca6ad9
AO
3222 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
3223 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3224 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
3225 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3226 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3227 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3228};
3229
3230static const bfd_byte *elf_sh_plt0_entry;
3231static const bfd_byte *elf_sh_plt_entry;
3232static const bfd_byte *elf_sh_pic_plt_entry;
3233
3234/* Return size of a PLT entry. */
3235#define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE
3236
3237/* Return offset of the PLT0 address in an absolute PLT entry. */
3238#define elf_sh_plt_plt0_offset(info) 32
3239
3240/* Return offset of the linker in PLT0 entry. */
3241#define elf_sh_plt0_gotplt_offset(info) 0
3242
3243/* Return offset of the trampoline in PLT entry */
3244#define elf_sh_plt_temp_offset(info) 33 /* Add one because it's SHmedia. */
3245
3246/* Return offset of the symbol in PLT entry. */
3247#define elf_sh_plt_symbol_offset(info) 0
3248
3249/* Return offset of the relocation in PLT entry. */
3250#define elf_sh_plt_reloc_offset(info) (info->shared ? 52 : 44)
3251
3252inline static void
3253movi_shori_putval (output_bfd, value, addr)
3254 bfd *output_bfd;
3255 unsigned long value;
3256 char *addr;
3257{
3258 bfd_put_32 (output_bfd,
3259 bfd_get_32 (output_bfd, addr)
3260 | ((value >> 6) & 0x3fffc00),
3261 addr);
3262 bfd_put_32 (output_bfd,
3263 bfd_get_32 (output_bfd, addr + 4)
3264 | ((value << 10) & 0x3fffc00),
3265 addr + 4);
3266}
3267
3268#else
37c644f2 3269/* The size in bytes of an entry in the procedure linkage table. */
252b5132 3270
37c644f2
AO
3271#define PLT_ENTRY_SIZE 28
3272
3273/* First entry in an absolute procedure linkage table look like this. */
3274
6c426cf3
NC
3275#if 1
3276/* Note - this code has been "optimised" not to use r2. r2 is used by
3277 GCC to return the address of large strutcures, so it should not be
3278 corrupted here. This does mean however, that this PLT does not conform
3279 to the SH PIC ABI. That spec says that r0 contains the type of the PLT
3280 and r2 contains the GOT id. This version stores the GOT id in r0 and
3281 ignores the type. Loaders can easily detect this difference however,
3282 since the type will always be 0 or 8, and the GOT ids will always be
3283 greater than or equal to 12. */
3284static const bfd_byte elf_sh_plt0_entry_be[PLT_ENTRY_SIZE] =
3285{
3286 0xd0, 0x05, /* mov.l 2f,r0 */
3287 0x60, 0x02, /* mov.l @r0,r0 */
3288 0x2f, 0x06, /* mov.l r0,@-r15 */
3289 0xd0, 0x03, /* mov.l 1f,r0 */
3290 0x60, 0x02, /* mov.l @r0,r0 */
3291 0x40, 0x2b, /* jmp @r0 */
3292 0x60, 0xf6, /* mov.l @r15+,r0 */
3293 0x00, 0x09, /* nop */
3294 0x00, 0x09, /* nop */
3295 0x00, 0x09, /* nop */
3296 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3297 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3298};
3299
3300static const bfd_byte elf_sh_plt0_entry_le[PLT_ENTRY_SIZE] =
3301{
3302 0x05, 0xd0, /* mov.l 2f,r0 */
3303 0x02, 0x60, /* mov.l @r0,r0 */
3304 0x06, 0x2f, /* mov.l r0,@-r15 */
3305 0x03, 0xd0, /* mov.l 1f,r0 */
3306 0x02, 0x60, /* mov.l @r0,r0 */
3307 0x2b, 0x40, /* jmp @r0 */
3308 0xf6, 0x60, /* mov.l @r15+,r0 */
3309 0x09, 0x00, /* nop */
3310 0x09, 0x00, /* nop */
3311 0x09, 0x00, /* nop */
3312 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3313 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3314};
3315
3316/* Sebsequent entries in an absolute procedure linkage table look like
3317 this. */
3318
3319static const bfd_byte elf_sh_plt_entry_be[PLT_ENTRY_SIZE] =
3320{
3321 0xd0, 0x04, /* mov.l 1f,r0 */
3322 0x60, 0x02, /* mov.l @r0,r0 */
3323 0xd1, 0x02, /* mov.l 0f,r1 */
3324 0x40, 0x2b, /* jmp @r0 */
3325 0x60, 0x13, /* mov r1,r0 */
3326 0xd1, 0x03, /* mov.l 2f,r1 */
3327 0x40, 0x2b, /* jmp @r0 */
3328 0x00, 0x09, /* nop */
3329 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3330 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3331 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3332};
3333
3334static const bfd_byte elf_sh_plt_entry_le[PLT_ENTRY_SIZE] =
3335{
3336 0x04, 0xd0, /* mov.l 1f,r0 */
3337 0x02, 0x60, /* mov.l @r0,r0 */
3338 0x02, 0xd1, /* mov.l 0f,r1 */
3339 0x2b, 0x40, /* jmp @r0 */
3340 0x13, 0x60, /* mov r1,r0 */
3341 0x03, 0xd1, /* mov.l 2f,r1 */
3342 0x2b, 0x40, /* jmp @r0 */
3343 0x09, 0x00, /* nop */
3344 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3345 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3346 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3347};
3348
3349/* Entries in a PIC procedure linkage table look like this. */
3350
3351static const bfd_byte elf_sh_pic_plt_entry_be[PLT_ENTRY_SIZE] =
3352{
3353 0xd0, 0x04, /* mov.l 1f,r0 */
3354 0x00, 0xce, /* mov.l @(r0,r12),r0 */
3355 0x40, 0x2b, /* jmp @r0 */
3356 0x00, 0x09, /* nop */
3357 0x50, 0xc2, /* mov.l @(8,r12),r0 */
3358 0xd1, 0x03, /* mov.l 2f,r1 */
3359 0x40, 0x2b, /* jmp @r0 */
3360 0x50, 0xc1, /* mov.l @(4,r12),r0 */
3361 0x00, 0x09, /* nop */
3362 0x00, 0x09, /* nop */
3363 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3364 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3365};
3366
3367static const bfd_byte elf_sh_pic_plt_entry_le[PLT_ENTRY_SIZE] =
3368{
3369 0x04, 0xd0, /* mov.l 1f,r0 */
3370 0xce, 0x00, /* mov.l @(r0,r12),r0 */
3371 0x2b, 0x40, /* jmp @r0 */
3372 0x09, 0x00, /* nop */
3373 0xc2, 0x50, /* mov.l @(8,r12),r0 */
3374 0x03, 0xd1, /* mov.l 2f,r1 */
3375 0x2b, 0x40, /* jmp @r0 */
3376 0xc1, 0x50, /* mov.l @(4,r12),r0 */
3377 0x09, 0x00, /* nop */
3378 0x09, 0x00, /* nop */
3379 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3380 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3381};
3382
3383#else /* These are the old style PLT entries. */
38b1a46c
NC
3384static const bfd_byte elf_sh_plt0_entry_be[PLT_ENTRY_SIZE] =
3385{
37c644f2
AO
3386 0xd0, 0x04, /* mov.l 1f,r0 */
3387 0xd2, 0x05, /* mov.l 2f,r2 */
3388 0x60, 0x02, /* mov.l @r0,r0 */
3389 0x62, 0x22, /* mov.l @r2,r2 */
3390 0x40, 0x2b, /* jmp @r0 */
3391 0xe0, 0x00, /* mov #0,r0 */
3392 0x00, 0x09, /* nop */
3393 0x00, 0x09, /* nop */
3394 0x00, 0x09, /* nop */
3395 0x00, 0x09, /* nop */
3396 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3397 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3398};
252b5132 3399
38b1a46c
NC
3400static const bfd_byte elf_sh_plt0_entry_le[PLT_ENTRY_SIZE] =
3401{
37c644f2
AO
3402 0x04, 0xd0, /* mov.l 1f,r0 */
3403 0x05, 0xd2, /* mov.l 2f,r2 */
3404 0x02, 0x60, /* mov.l @r0,r0 */
3405 0x22, 0x62, /* mov.l @r2,r2 */
3406 0x2b, 0x40, /* jmp @r0 */
3407 0x00, 0xe0, /* mov #0,r0 */
3408 0x09, 0x00, /* nop */
3409 0x09, 0x00, /* nop */
3410 0x09, 0x00, /* nop */
3411 0x09, 0x00, /* nop */
3412 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3413 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3414};
252b5132 3415
37c644f2
AO
3416/* Sebsequent entries in an absolute procedure linkage table look like
3417 this. */
252b5132 3418
38b1a46c
NC
3419static const bfd_byte elf_sh_plt_entry_be[PLT_ENTRY_SIZE] =
3420{
37c644f2
AO
3421 0xd0, 0x04, /* mov.l 1f,r0 */
3422 0x60, 0x02, /* mov.l @r0,r0 */
3423 0xd2, 0x02, /* mov.l 0f,r2 */
3424 0x40, 0x2b, /* jmp @r0 */
3425 0x60, 0x23, /* mov r2,r0 */
3426 0xd1, 0x03, /* mov.l 2f,r1 */
3427 0x40, 0x2b, /* jmp @r0 */
3428 0x00, 0x09, /* nop */
3429 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3430 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3431 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3432};
252b5132 3433
38b1a46c
NC
3434static const bfd_byte elf_sh_plt_entry_le[PLT_ENTRY_SIZE] =
3435{
37c644f2
AO
3436 0x04, 0xd0, /* mov.l 1f,r0 */
3437 0x02, 0x60, /* mov.l @r0,r0 */
3438 0x02, 0xd2, /* mov.l 0f,r2 */
3439 0x2b, 0x40, /* jmp @r0 */
3440 0x23, 0x60, /* mov r2,r0 */
3441 0x03, 0xd1, /* mov.l 2f,r1 */
3442 0x2b, 0x40, /* jmp @r0 */
3443 0x09, 0x00, /* nop */
3444 0, 0, 0, 0, /* 0: replaced with address of .PLT. */
3445 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3446 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3447};
252b5132 3448
37c644f2 3449/* Entries in a PIC procedure linkage table look like this. */
252b5132 3450
38b1a46c
NC
3451static const bfd_byte elf_sh_pic_plt_entry_be[PLT_ENTRY_SIZE] =
3452{
37c644f2
AO
3453 0xd0, 0x04, /* mov.l 1f,r0 */
3454 0x00, 0xce, /* mov.l @(r0,r12),r0 */
3455 0x40, 0x2b, /* jmp @r0 */
3456 0x00, 0x09, /* nop */
3457 0x50, 0xc2, /* 0: mov.l @(8,r12),r0 */
3458 0x52, 0xc1, /* 1: mov.l @(4,r12),r2 */
3459 0xd1, 0x02, /* mov.l 2f,r1 */
3460 0x40, 0x2b, /* jmp @r0 */
3461 0xe0, 0x00, /* mov #0,r0 ! shows the type of PLT. */
3462 0x00, 0x09, /* nop */
3463 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3464 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3465};
252b5132 3466
38b1a46c
NC
3467static const bfd_byte elf_sh_pic_plt_entry_le[PLT_ENTRY_SIZE] =
3468{
37c644f2
AO
3469 0x04, 0xd0, /* mov.l 1f,r0 */
3470 0xce, 0x00, /* mov.l @(r0,r12),r0 */
3471 0x2b, 0x40, /* jmp @r0 */
3472 0x09, 0x00, /* nop */
3473 0xc2, 0x50, /* 0: mov.l @(8,r12),r0 */
3474 0xc1, 0x52, /* 1: mov.l @(4,r12),r2 */
3475 0x02, 0xd1, /* mov.l 2f,r1 */
3476 0x2b, 0x40, /* jmp @r0 */
3477 0x00, 0xe0, /* mov #0,r0 ! shows the type of PLT. */
3478 0x09, 0x00, /* nop */
3479 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3480 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3481};
6c426cf3 3482#endif /* old style PLT entries. */
252b5132 3483
37c644f2
AO
3484static const bfd_byte *elf_sh_plt0_entry;
3485static const bfd_byte *elf_sh_plt_entry;
3486static const bfd_byte *elf_sh_pic_plt_entry;
252b5132 3487
37c644f2
AO
3488/* Return size of a PLT entry. */
3489#define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE
252b5132 3490
37c644f2
AO
3491/* Return offset of the PLT0 address in an absolute PLT entry. */
3492#define elf_sh_plt_plt0_offset(info) 16
252b5132 3493
37c644f2
AO
3494/* Return offset of the linker in PLT0 entry. */
3495#define elf_sh_plt0_linker_offset(info) 20
9bdafcce 3496
37c644f2
AO
3497/* Return offset of the GOT id in PLT0 entry. */
3498#define elf_sh_plt0_gotid_offset(info) 24
9bdafcce 3499
37c644f2
AO
3500/* Return offset of the tempoline in PLT entry */
3501#define elf_sh_plt_temp_offset(info) 8
9bdafcce 3502
37c644f2
AO
3503/* Return offset of the symbol in PLT entry. */
3504#define elf_sh_plt_symbol_offset(info) 20
9bdafcce 3505
37c644f2
AO
3506/* Return offset of the relocation in PLT entry. */
3507#define elf_sh_plt_reloc_offset(info) 24
fbca6ad9 3508#endif
015551fc 3509
37c644f2 3510/* The sh linker needs to keep track of the number of relocs that it
067653c5
AM
3511 decides to copy as dynamic relocs in check_relocs for each symbol.
3512 This is so that it can later discard them if they are found to be
3513 unnecessary. We store the information in a field extending the
3514 regular ELF linker hash table. */
252b5132 3515
067653c5 3516struct elf_sh_dyn_relocs
38b1a46c 3517{
067653c5
AM
3518 struct elf_sh_dyn_relocs *next;
3519
3520 /* The input section of the reloc. */
3521 asection *sec;
3522
3523 /* Total number of relocs copied for the input section. */
37c644f2 3524 bfd_size_type count;
067653c5
AM
3525
3526 /* Number of pc-relative relocs copied for the input section. */
3527 bfd_size_type pc_count;
c95b8a7a
KK
3528
3529 /* If TRUE, R_SH_TLS_TPOFF32 relocation is generated. */
3530 bfd_boolean tls_tpoff32;
37c644f2 3531};
252b5132 3532
37c644f2
AO
3533/* sh ELF linker hash entry. */
3534
38b1a46c
NC
3535struct elf_sh_link_hash_entry
3536{
37c644f2
AO
3537 struct elf_link_hash_entry root;
3538
fbca6ad9 3539#ifdef INCLUDE_SHMEDIA
396a6083
SC
3540 union
3541 {
3542 bfd_signed_vma refcount;
3543 bfd_vma offset;
3544 } datalabel_got;
fbca6ad9
AO
3545#endif
3546
067653c5
AM
3547 /* Track dynamic relocs copied for this symbol. */
3548 struct elf_sh_dyn_relocs *dyn_relocs;
4989d792
SC
3549
3550 bfd_signed_vma gotplt_refcount;
3376eaf5
KK
3551
3552 enum {
3553 GOT_UNKNOWN = 0, GOT_NORMAL, GOT_TLS_GD, GOT_TLS_IE
3554 } tls_type;
3376eaf5
KK
3555};
3556
3557#define sh_elf_hash_entry(ent) ((struct elf_sh_link_hash_entry *)(ent))
3558
3559struct sh_elf_obj_tdata
3560{
3561 struct elf_obj_tdata root;
3562
3563 /* tls_type for each local got entry. */
3564 char *local_got_tls_type;
37c644f2
AO
3565};
3566
3376eaf5
KK
3567#define sh_elf_tdata(abfd) \
3568 ((struct sh_elf_obj_tdata *) (abfd)->tdata.any)
3569
3570#define sh_elf_local_got_tls_type(abfd) \
3571 (sh_elf_tdata (abfd)->local_got_tls_type)
3572
3573/* Override the generic function because we need to store sh_elf_obj_tdata
3574 as the specific tdata. */
3575
b34976b6 3576static bfd_boolean
3376eaf5
KK
3577sh_elf_mkobject (abfd)
3578 bfd *abfd;
3579{
3580 bfd_size_type amt = sizeof (struct sh_elf_obj_tdata);
3581 abfd->tdata.any = bfd_zalloc (abfd, amt);
3582 if (abfd->tdata.any == NULL)
b34976b6
AM
3583 return FALSE;
3584 return TRUE;
3376eaf5 3585}
b34976b6 3586
37c644f2
AO
3587/* sh ELF linker hash table. */
3588
38b1a46c
NC
3589struct elf_sh_link_hash_table
3590{
37c644f2 3591 struct elf_link_hash_table root;
37c644f2 3592
067653c5
AM
3593 /* Short-cuts to get to dynamic linker sections. */
3594 asection *sgot;
3595 asection *sgotplt;
3596 asection *srelgot;
3597 asection *splt;
3598 asection *srelplt;
3599 asection *sdynbss;
3600 asection *srelbss;
37c644f2 3601
067653c5
AM
3602 /* Small local sym to section mapping cache. */
3603 struct sym_sec_cache sym_sec;
3376eaf5
KK
3604
3605 /* A counter or offset to track a TLS got entry. */
3606 union
3607 {
3608 bfd_signed_vma refcount;
3609 bfd_vma offset;
3610 } tls_ldm_got;
067653c5 3611};
37c644f2
AO
3612
3613/* Traverse an sh ELF linker hash table. */
3614
3615#define sh_elf_link_hash_traverse(table, func, info) \
3616 (elf_link_hash_traverse \
3617 (&(table)->root, \
b34976b6 3618 (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
37c644f2
AO
3619 (info)))
3620
3621/* Get the sh ELF linker hash table from a link_info structure. */
3622
3623#define sh_elf_hash_table(p) \
3624 ((struct elf_sh_link_hash_table *) ((p)->hash))
3625
3626/* Create an entry in an sh ELF linker hash table. */
3627
3628static struct bfd_hash_entry *
3629sh_elf_link_hash_newfunc (entry, table, string)
3630 struct bfd_hash_entry *entry;
3631 struct bfd_hash_table *table;
3632 const char *string;
3633{
3634 struct elf_sh_link_hash_entry *ret =
3635 (struct elf_sh_link_hash_entry *) entry;
3636
3637 /* Allocate the structure if it has not already been allocated by a
3638 subclass. */
3639 if (ret == (struct elf_sh_link_hash_entry *) NULL)
3640 ret = ((struct elf_sh_link_hash_entry *)
3641 bfd_hash_allocate (table,
3642 sizeof (struct elf_sh_link_hash_entry)));
3643 if (ret == (struct elf_sh_link_hash_entry *) NULL)
3644 return (struct bfd_hash_entry *) ret;
3645
3646 /* Call the allocation method of the superclass. */
3647 ret = ((struct elf_sh_link_hash_entry *)
3648 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
3649 table, string));
3650 if (ret != (struct elf_sh_link_hash_entry *) NULL)
3651 {
396a6083
SC
3652 ret->dyn_relocs = NULL;
3653 ret->gotplt_refcount = 0;
fbca6ad9 3654#ifdef INCLUDE_SHMEDIA
396a6083 3655 ret->datalabel_got.refcount = ret->root.got.refcount;
fbca6ad9 3656#endif
3376eaf5 3657 ret->tls_type = GOT_UNKNOWN;
37c644f2
AO
3658 }
3659
3660 return (struct bfd_hash_entry *) ret;
3661}
3662
3663/* Create an sh ELF linker hash table. */
3664
3665static struct bfd_link_hash_table *
3666sh_elf_link_hash_table_create (abfd)
3667 bfd *abfd;
3668{
3669 struct elf_sh_link_hash_table *ret;
dc810e39 3670 bfd_size_type amt = sizeof (struct elf_sh_link_hash_table);
37c644f2 3671
e2d34d7d 3672 ret = (struct elf_sh_link_hash_table *) bfd_malloc (amt);
37c644f2
AO
3673 if (ret == (struct elf_sh_link_hash_table *) NULL)
3674 return NULL;
3675
3676 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
3677 sh_elf_link_hash_newfunc))
3678 {
e2d34d7d 3679 free (ret);
37c644f2
AO
3680 return NULL;
3681 }
3682
067653c5
AM
3683 ret->sgot = NULL;
3684 ret->sgotplt = NULL;
3685 ret->srelgot = NULL;
3686 ret->splt = NULL;
3687 ret->srelplt = NULL;
3688 ret->sdynbss = NULL;
3689 ret->srelbss = NULL;
3690 ret->sym_sec.abfd = NULL;
3376eaf5 3691 ret->tls_ldm_got.refcount = 0;
067653c5 3692
37c644f2
AO
3693 return &ret->root.root;
3694}
3695
067653c5
AM
3696/* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
3697 shortcuts to them in our hash table. */
3698
b34976b6 3699static bfd_boolean
067653c5
AM
3700create_got_section (dynobj, info)
3701 bfd *dynobj;
3702 struct bfd_link_info *info;
3703{
3704 struct elf_sh_link_hash_table *htab;
3705
3706 if (! _bfd_elf_create_got_section (dynobj, info))
b34976b6 3707 return FALSE;
067653c5
AM
3708
3709 htab = sh_elf_hash_table (info);
3710 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
3711 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
3712 if (! htab->sgot || ! htab->sgotplt)
3713 abort ();
3714
3715 htab->srelgot = bfd_make_section (dynobj, ".rela.got");
3716 if (htab->srelgot == NULL
3717 || ! bfd_set_section_flags (dynobj, htab->srelgot,
3718 (SEC_ALLOC
3719 | SEC_LOAD
3720 | SEC_HAS_CONTENTS
3721 | SEC_IN_MEMORY
3722 | SEC_LINKER_CREATED
3723 | SEC_READONLY))
3724 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
b34976b6
AM
3725 return FALSE;
3726 return TRUE;
067653c5
AM
3727}
3728
37c644f2
AO
3729/* Create dynamic sections when linking against a dynamic object. */
3730
b34976b6 3731static bfd_boolean
37c644f2
AO
3732sh_elf_create_dynamic_sections (abfd, info)
3733 bfd *abfd;
3734 struct bfd_link_info *info;
3735{
067653c5 3736 struct elf_sh_link_hash_table *htab;
37c644f2
AO
3737 flagword flags, pltflags;
3738 register asection *s;
3739 struct elf_backend_data *bed = get_elf_backend_data (abfd);
3740 int ptralign = 0;
3741
3742 switch (bed->s->arch_size)
3743 {
3744 case 32:
3745 ptralign = 2;
3746 break;
3747
3748 case 64:
3749 ptralign = 3;
3750 break;
3751
3752 default:
3753 bfd_set_error (bfd_error_bad_value);
b34976b6 3754 return FALSE;
37c644f2
AO
3755 }
3756
067653c5
AM
3757 htab = sh_elf_hash_table (info);
3758
37c644f2
AO
3759 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3760 .rel[a].bss sections. */
3761
3762 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3763 | SEC_LINKER_CREATED);
3764
3765 pltflags = flags;
3766 pltflags |= SEC_CODE;
3767 if (bed->plt_not_loaded)
3768 pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
3769 if (bed->plt_readonly)
3770 pltflags |= SEC_READONLY;
3771
3772 s = bfd_make_section (abfd, ".plt");
067653c5 3773 htab->splt = s;
37c644f2
AO
3774 if (s == NULL
3775 || ! bfd_set_section_flags (abfd, s, pltflags)
3776 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
b34976b6 3777 return FALSE;
37c644f2
AO
3778
3779 if (bed->want_plt_sym)
3780 {
3781 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3782 .plt section. */
14a793b2
AM
3783 struct elf_link_hash_entry *h;
3784 struct bfd_link_hash_entry *bh = NULL;
3785
37c644f2
AO
3786 if (! (_bfd_generic_link_add_one_symbol
3787 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
b34976b6 3788 (bfd_vma) 0, (const char *) NULL, FALSE,
14a793b2 3789 get_elf_backend_data (abfd)->collect, &bh)))
b34976b6 3790 return FALSE;
14a793b2
AM
3791
3792 h = (struct elf_link_hash_entry *) bh;
37c644f2
AO
3793 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
3794 h->type = STT_OBJECT;
3795
3796 if (info->shared
3797 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
b34976b6 3798 return FALSE;
37c644f2
AO
3799 }
3800
435b1e90 3801 s = bfd_make_section (abfd,
37c644f2 3802 bed->default_use_rela_p ? ".rela.plt" : ".rel.plt");
067653c5 3803 htab->srelplt = s;
37c644f2
AO
3804 if (s == NULL
3805 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
3806 || ! bfd_set_section_alignment (abfd, s, ptralign))
b34976b6 3807 return FALSE;
37c644f2 3808
067653c5 3809 if (! create_got_section (abfd, info))
b34976b6 3810 return FALSE;
37c644f2
AO
3811
3812 {
3813 const char *secname;
3814 char *relname;
3815 flagword secflags;
3816 asection *sec;
3817
3818 for (sec = abfd->sections; sec; sec = sec->next)
3819 {
3820 secflags = bfd_get_section_flags (abfd, sec);
3821 if ((secflags & (SEC_DATA | SEC_LINKER_CREATED))
3822 || ((secflags & SEC_HAS_CONTENTS) != SEC_HAS_CONTENTS))
3823 continue;
3824 secname = bfd_get_section_name (abfd, sec);
dc810e39 3825 relname = (char *) bfd_malloc ((bfd_size_type) strlen (secname) + 6);
37c644f2
AO
3826 strcpy (relname, ".rela");
3827 strcat (relname, secname);
3828 s = bfd_make_section (abfd, relname);
3829 if (s == NULL
3830 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
3831 || ! bfd_set_section_alignment (abfd, s, ptralign))
b34976b6 3832 return FALSE;
37c644f2
AO
3833 }
3834 }
3835
3836 if (bed->want_dynbss)
3837 {
3838 /* The .dynbss section is a place to put symbols which are defined
3839 by dynamic objects, are referenced by regular objects, and are
3840 not functions. We must allocate space for them in the process
3841 image and use a R_*_COPY reloc to tell the dynamic linker to
3842 initialize them at run time. The linker script puts the .dynbss
3843 section into the .bss section of the final image. */
3844 s = bfd_make_section (abfd, ".dynbss");
067653c5 3845 htab->sdynbss = s;
37c644f2
AO
3846 if (s == NULL
3847 || ! bfd_set_section_flags (abfd, s, SEC_ALLOC))
b34976b6 3848 return FALSE;
37c644f2
AO
3849
3850 /* The .rel[a].bss section holds copy relocs. This section is not
3851 normally needed. We need to create it here, though, so that the
3852 linker will map it to an output section. We can't just create it
3853 only if we need it, because we will not know whether we need it
3854 until we have seen all the input files, and the first time the
3855 main linker code calls BFD after examining all the input files
3856 (size_dynamic_sections) the input sections have already been
3857 mapped to the output sections. If the section turns out not to
3858 be needed, we can discard it later. We will never need this
3859 section when generating a shared object, since they do not use
3860 copy relocs. */
3861 if (! info->shared)
3862 {
435b1e90
KH
3863 s = bfd_make_section (abfd,
3864 (bed->default_use_rela_p
3865 ? ".rela.bss" : ".rel.bss"));
067653c5 3866 htab->srelbss = s;
37c644f2
AO
3867 if (s == NULL
3868 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
3869 || ! bfd_set_section_alignment (abfd, s, ptralign))
b34976b6 3870 return FALSE;
37c644f2
AO
3871 }
3872 }
3873
b34976b6 3874 return TRUE;
37c644f2
AO
3875}
3876\f
37c644f2
AO
3877/* Adjust a symbol defined by a dynamic object and referenced by a
3878 regular object. The current definition is in some section of the
3879 dynamic object, but we're not including those sections. We have to
3880 change the definition to something the rest of the link can
3881 understand. */
3882
b34976b6 3883static bfd_boolean
37c644f2
AO
3884sh_elf_adjust_dynamic_symbol (info, h)
3885 struct bfd_link_info *info;
3886 struct elf_link_hash_entry *h;
3887{
067653c5
AM
3888 struct elf_sh_link_hash_table *htab;
3889 struct elf_sh_link_hash_entry *eh;
3890 struct elf_sh_dyn_relocs *p;
37c644f2
AO
3891 bfd *dynobj;
3892 asection *s;
3893 unsigned int power_of_two;
3894
3895 dynobj = elf_hash_table (info)->dynobj;
3896
3897 /* Make sure we know what is going on here. */
3898 BFD_ASSERT (dynobj != NULL
3899 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
3900 || h->weakdef != NULL
3901 || ((h->elf_link_hash_flags
3902 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
3903 && (h->elf_link_hash_flags
3904 & ELF_LINK_HASH_REF_REGULAR) != 0
3905 && (h->elf_link_hash_flags
3906 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
3907
3908 /* If this is a function, put it in the procedure linkage table. We
3909 will fill in the contents of the procedure linkage table later,
3910 when we know the address of the .got section. */
3911 if (h->type == STT_FUNC
3912 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
3913 {
067653c5
AM
3914 if (h->plt.refcount <= 0
3915 || (! info->shared
3916 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
3917 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0
3918 && h->root.type != bfd_link_hash_undefweak
3919 && h->root.type != bfd_link_hash_undefined))
37c644f2
AO
3920 {
3921 /* This case can occur if we saw a PLT reloc in an input
3922 file, but the symbol was never referred to by a dynamic
3923 object. In such a case, we don't actually need to build
3924 a procedure linkage table, and we can just do a REL32
3925 reloc instead. */
067653c5
AM
3926 h->plt.offset = (bfd_vma) -1;
3927 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
37c644f2
AO
3928 }
3929
b34976b6 3930 return TRUE;
37c644f2 3931 }
067653c5
AM
3932 else
3933 h->plt.offset = (bfd_vma) -1;
37c644f2
AO
3934
3935 /* If this is a weak symbol, and there is a real definition, the
3936 processor independent code will have arranged for us to see the
3937 real definition first, and we can just use the same value. */
3938 if (h->weakdef != NULL)
3939 {
3940 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
3941 || h->weakdef->root.type == bfd_link_hash_defweak);
3942 h->root.u.def.section = h->weakdef->root.u.def.section;
3943 h->root.u.def.value = h->weakdef->root.u.def.value;
b34976b6 3944 return TRUE;
37c644f2
AO
3945 }
3946
3947 /* This is a reference to a symbol defined by a dynamic object which
3948 is not a function. */
3949
3950 /* If we are creating a shared library, we must presume that the
3951 only references to the symbol are via the global offset table.
3952 For such cases we need not do anything here; the relocations will
3953 be handled correctly by relocate_section. */
3954 if (info->shared)
b34976b6 3955 return TRUE;
37c644f2
AO
3956
3957 /* If there are no references to this symbol that do not use the
3958 GOT, we don't need to generate a copy reloc. */
3959 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
b34976b6 3960 return TRUE;
37c644f2 3961
067653c5
AM
3962 /* If -z nocopyreloc was given, we won't generate them either. */
3963 if (info->nocopyreloc)
3964 {
3965 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
b34976b6 3966 return TRUE;
067653c5
AM
3967 }
3968
3969 eh = (struct elf_sh_link_hash_entry *) h;
3970 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3971 {
3972 s = p->sec->output_section;
3973 if (s != NULL && (s->flags & (SEC_READONLY | SEC_HAS_CONTENTS)) != 0)
3974 break;
3975 }
3976
3977 /* If we didn't find any dynamic relocs in sections which needs the
3978 copy reloc, then we'll be keeping the dynamic relocs and avoiding
3979 the copy reloc. */
3980 if (p == NULL)
3981 {
3982 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
b34976b6 3983 return TRUE;
067653c5
AM
3984 }
3985
37c644f2
AO
3986 /* We must allocate the symbol in our .dynbss section, which will
3987 become part of the .bss section of the executable. There will be
3988 an entry for this symbol in the .dynsym section. The dynamic
3989 object will contain position independent code, so all references
3990 from the dynamic object to this symbol will go through the global
3991 offset table. The dynamic linker will use the .dynsym entry to
3992 determine the address it must put in the global offset table, so
3993 both the dynamic object and the regular object will refer to the
3994 same memory location for the variable. */
3995
067653c5
AM
3996 htab = sh_elf_hash_table (info);
3997 s = htab->sdynbss;
37c644f2
AO
3998 BFD_ASSERT (s != NULL);
3999
4000 /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
4001 copy the initial value out of the dynamic object and into the
4002 runtime process image. We need to remember the offset into the
4003 .rela.bss section we are going to use. */
4004 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
4005 {
4006 asection *srel;
4007
067653c5 4008 srel = htab->srelbss;
37c644f2
AO
4009 BFD_ASSERT (srel != NULL);
4010 srel->_raw_size += sizeof (Elf32_External_Rela);
4011 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
4012 }
4013
4014 /* We need to figure out the alignment required for this symbol. I
4015 have no idea how ELF linkers handle this. */
4016 power_of_two = bfd_log2 (h->size);
4017 if (power_of_two > 3)
4018 power_of_two = 3;
4019
4020 /* Apply the required alignment. */
067653c5 4021 s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two));
37c644f2
AO
4022 if (power_of_two > bfd_get_section_alignment (dynobj, s))
4023 {
4024 if (! bfd_set_section_alignment (dynobj, s, power_of_two))
b34976b6 4025 return FALSE;
37c644f2
AO
4026 }
4027
4028 /* Define the symbol as being at this point in the section. */
4029 h->root.u.def.section = s;
4030 h->root.u.def.value = s->_raw_size;
4031
4032 /* Increment the section size to make room for the symbol. */
4033 s->_raw_size += h->size;
4034
b34976b6 4035 return TRUE;
37c644f2
AO
4036}
4037
067653c5
AM
4038/* This is the condition under which sh_elf_finish_dynamic_symbol
4039 will be called from elflink.h. If elflink.h doesn't call our
4040 finish_dynamic_symbol routine, we'll need to do something about
4041 initializing any .plt and .got entries in sh_elf_relocate_section. */
4042#define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
4043 ((DYN) \
4044 && ((INFO)->shared \
4045 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
4046 && ((H)->dynindx != -1 \
4047 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
4048
4049/* Allocate space in .plt, .got and associated reloc sections for
4050 dynamic relocs. */
4051
b34976b6 4052static bfd_boolean
067653c5
AM
4053allocate_dynrelocs (h, inf)
4054 struct elf_link_hash_entry *h;
4055 PTR inf;
4056{
4057 struct bfd_link_info *info;
4058 struct elf_sh_link_hash_table *htab;
4059 struct elf_sh_link_hash_entry *eh;
4060 struct elf_sh_dyn_relocs *p;
4061
4062 if (h->root.type == bfd_link_hash_indirect)
b34976b6 4063 return TRUE;
067653c5
AM
4064
4065 if (h->root.type == bfd_link_hash_warning)
4066 /* When warning symbols are created, they **replace** the "real"
4067 entry in the hash table, thus we never get to see the real
4068 symbol in a hash traversal. So look at it now. */
4069 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4070
4071 info = (struct bfd_link_info *) inf;
4072 htab = sh_elf_hash_table (info);
4073
4989d792
SC
4074 eh = (struct elf_sh_link_hash_entry *) h;
4075 if ((h->got.refcount > 0
4076 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
4077 && eh->gotplt_refcount > 0)
4078 {
4079 /* The symbol has been forced local, or we have some direct got refs,
26e41594 4080 so treat all the gotplt refs as got refs. */
4989d792
SC
4081 h->got.refcount += eh->gotplt_refcount;
4082 if (h->plt.refcount >= eh->gotplt_refcount)
4083 h->plt.refcount -= eh->gotplt_refcount;
4084 }
4085
067653c5
AM
4086 if (htab->root.dynamic_sections_created
4087 && h->plt.refcount > 0)
4088 {
4089 /* Make sure this symbol is output as a dynamic symbol.
4090 Undefined weak syms won't yet be marked as dynamic. */
4091 if (h->dynindx == -1
4092 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
4093 {
4094 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
b34976b6 4095 return FALSE;
067653c5
AM
4096 }
4097
4098 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h))
4099 {
4100 asection *s = htab->splt;
4101
4102 /* If this is the first .plt entry, make room for the special
4103 first entry. */
4104 if (s->_raw_size == 0)
4105 s->_raw_size += PLT_ENTRY_SIZE;
4106
4107 h->plt.offset = s->_raw_size;
4108
4109 /* If this symbol is not defined in a regular file, and we are
4110 not generating a shared library, then set the symbol to this
4111 location in the .plt. This is required to make function
4112 pointers compare as equal between the normal executable and
4113 the shared library. */
4114 if (! info->shared
4115 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
4116 {
4117 h->root.u.def.section = s;
4118 h->root.u.def.value = h->plt.offset;
4119 }
4120
4121 /* Make room for this entry. */
4122 s->_raw_size += PLT_ENTRY_SIZE;
4123
4124 /* We also need to make an entry in the .got.plt section, which
4125 will be placed in the .got section by the linker script. */
4126 htab->sgotplt->_raw_size += 4;
4127
4128 /* We also need to make an entry in the .rel.plt section. */
4129 htab->srelplt->_raw_size += sizeof (Elf32_External_Rela);
4130 }
4131 else
4132 {
4133 h->plt.offset = (bfd_vma) -1;
4134 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
4135 }
4136 }
4137 else
4138 {
4139 h->plt.offset = (bfd_vma) -1;
4140 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
4141 }
4142
4143 if (h->got.refcount > 0)
4144 {
4145 asection *s;
b34976b6 4146 bfd_boolean dyn;
3376eaf5 4147 int tls_type = sh_elf_hash_entry (h)->tls_type;
067653c5
AM
4148
4149 /* Make sure this symbol is output as a dynamic symbol.
4150 Undefined weak syms won't yet be marked as dynamic. */
4151 if (h->dynindx == -1
4152 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
4153 {
4154 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
b34976b6 4155 return FALSE;
067653c5
AM
4156 }
4157
4158 s = htab->sgot;
067653c5 4159 h->got.offset = s->_raw_size;
067653c5 4160 s->_raw_size += 4;
3376eaf5
KK
4161 /* R_SH_TLS_GD needs 2 consecutive GOT slots. */
4162 if (tls_type == GOT_TLS_GD)
4163 s->_raw_size += 4;
067653c5 4164 dyn = htab->root.dynamic_sections_created;
3376eaf5
KK
4165 /* R_SH_TLS_IE_32 needs one dynamic relocation,
4166 R_SH_TLS_GD needs one if local symbol and two if global. */
4167 if ((tls_type == GOT_TLS_GD && h->dynindx == -1)
4168 || tls_type == GOT_TLS_IE)
4169 htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
4170 else if (tls_type == GOT_TLS_GD)
4171 htab->srelgot->_raw_size += 2 * sizeof (Elf32_External_Rela);
4172 else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h))
067653c5
AM
4173 htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
4174 }
4175 else
4176 h->got.offset = (bfd_vma) -1;
4177
396a6083
SC
4178#ifdef INCLUDE_SHMEDIA
4179 if (eh->datalabel_got.refcount > 0)
4180 {
4181 asection *s;
b34976b6 4182 bfd_boolean dyn;
396a6083
SC
4183
4184 /* Make sure this symbol is output as a dynamic symbol.
4185 Undefined weak syms won't yet be marked as dynamic. */
4186 if (h->dynindx == -1
4187 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
4188 {
4189 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
b34976b6 4190 return FALSE;
396a6083
SC
4191 }
4192
4193 s = htab->sgot;
4194 eh->datalabel_got.offset = s->_raw_size;
4195 s->_raw_size += 4;
4196 dyn = htab->root.dynamic_sections_created;
4197 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h))
4198 htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
4199 }
4200 else
4201 eh->datalabel_got.offset = (bfd_vma) -1;
4202#endif
4203
067653c5 4204 if (eh->dyn_relocs == NULL)
b34976b6 4205 return TRUE;
067653c5
AM
4206
4207 /* In the shared -Bsymbolic case, discard space allocated for
4208 dynamic pc-relative relocs against symbols which turn out to be
4209 defined in regular objects. For the normal shared case, discard
4210 space for pc-relative relocs that have become local due to symbol
4211 visibility changes. */
4212
4213 if (info->shared)
4214 {
4215 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
4216 && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
4217 || info->symbolic))
4218 {
4219 struct elf_sh_dyn_relocs **pp;
4220
4221 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
4222 {
4223 p->count -= p->pc_count;
4224 p->pc_count = 0;
4225 if (p->count == 0)
4226 *pp = p->next;
4227 else
4228 pp = &p->next;
4229 }
4230 }
4231 }
4232 else
4233 {
c95b8a7a
KK
4234 for (p = eh->dyn_relocs; p; p = p->next)
4235 if (p->tls_tpoff32)
4236 goto keep;
3376eaf5 4237
067653c5
AM
4238 /* For the non-shared case, discard space for relocs against
4239 symbols which turn out to need copy relocs or are not
4240 dynamic. */
4241
4242 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
4243 && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
4244 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
4245 || (htab->root.dynamic_sections_created
4246 && (h->root.type == bfd_link_hash_undefweak
4247 || h->root.type == bfd_link_hash_undefined))))
4248 {
4249 /* Make sure this symbol is output as a dynamic symbol.
4250 Undefined weak syms won't yet be marked as dynamic. */
4251 if (h->dynindx == -1
4252 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
4253 {
4254 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
b34976b6 4255 return FALSE;
067653c5
AM
4256 }
4257
4258 /* If that succeeded, we know we'll be keeping all the
4259 relocs. */
4260 if (h->dynindx != -1)
4261 goto keep;
4262 }
4263
4264 eh->dyn_relocs = NULL;
4265
4266 keep: ;
4267 }
4268
4269 /* Finally, allocate space. */
4270 for (p = eh->dyn_relocs; p != NULL; p = p->next)
4271 {
4272 asection *sreloc = elf_section_data (p->sec)->sreloc;
4273 sreloc->_raw_size += p->count * sizeof (Elf32_External_Rela);
4274 }
4275
b34976b6 4276 return TRUE;
067653c5
AM
4277}
4278
4279/* Find any dynamic relocs that apply to read-only sections. */
4280
b34976b6 4281static bfd_boolean
067653c5
AM
4282readonly_dynrelocs (h, inf)
4283 struct elf_link_hash_entry *h;
4284 PTR inf;
4285{
4286 struct elf_sh_link_hash_entry *eh;
4287 struct elf_sh_dyn_relocs *p;
4288
4289 if (h->root.type == bfd_link_hash_warning)
4290 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4291
4292 eh = (struct elf_sh_link_hash_entry *) h;
4293 for (p = eh->dyn_relocs; p != NULL; p = p->next)
4294 {
4295 asection *s = p->sec->output_section;
4296
4297 if (s != NULL && (s->flags & SEC_READONLY) != 0)
4298 {
4299 struct bfd_link_info *info = (struct bfd_link_info *) inf;
4300
4301 info->flags |= DF_TEXTREL;
4302
4303 /* Not an error, just cut short the traversal. */
b34976b6 4304 return FALSE;
067653c5
AM
4305 }
4306 }
b34976b6 4307 return TRUE;
067653c5
AM
4308}
4309
37c644f2
AO
4310/* Set the sizes of the dynamic sections. */
4311
b34976b6 4312static bfd_boolean
37c644f2 4313sh_elf_size_dynamic_sections (output_bfd, info)
99e4ae17 4314 bfd *output_bfd ATTRIBUTE_UNUSED;
37c644f2
AO
4315 struct bfd_link_info *info;
4316{
067653c5 4317 struct elf_sh_link_hash_table *htab;
37c644f2
AO
4318 bfd *dynobj;
4319 asection *s;
b34976b6 4320 bfd_boolean relocs;
067653c5 4321 bfd *ibfd;
37c644f2 4322
067653c5
AM
4323 htab = sh_elf_hash_table (info);
4324 dynobj = htab->root.dynobj;
37c644f2
AO
4325 BFD_ASSERT (dynobj != NULL);
4326
067653c5 4327 if (htab->root.dynamic_sections_created)
37c644f2
AO
4328 {
4329 /* Set the contents of the .interp section to the interpreter. */
4330 if (! info->shared)
4331 {
4332 s = bfd_get_section_by_name (dynobj, ".interp");
4333 BFD_ASSERT (s != NULL);
4334 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
4335 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
4336 }
4337 }
37c644f2 4338
067653c5
AM
4339 /* Set up .got offsets for local syms, and space for local dynamic
4340 relocs. */
4341 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
37c644f2 4342 {
067653c5
AM
4343 bfd_signed_vma *local_got;
4344 bfd_signed_vma *end_local_got;
3376eaf5 4345 char *local_tls_type;
067653c5
AM
4346 bfd_size_type locsymcount;
4347 Elf_Internal_Shdr *symtab_hdr;
4348 asection *srel;
37c644f2 4349
067653c5 4350 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
37c644f2
AO
4351 continue;
4352
067653c5 4353 for (s = ibfd->sections; s != NULL; s = s->next)
37c644f2 4354 {
067653c5
AM
4355 struct elf_sh_dyn_relocs *p;
4356
4357 for (p = ((struct elf_sh_dyn_relocs *)
4358 elf_section_data (s)->local_dynrel);
4359 p != NULL;
4360 p = p->next)
37c644f2 4361 {
067653c5
AM
4362 if (! bfd_is_abs_section (p->sec)
4363 && bfd_is_abs_section (p->sec->output_section))
4364 {
4365 /* Input section has been discarded, either because
4366 it is a copy of a linkonce section or due to
4367 linker script /DISCARD/, so we'll be discarding
4368 the relocs too. */
4369 }
4370 else if (p->count != 0)
4371 {
4372 srel = elf_section_data (p->sec)->sreloc;
4373 srel->_raw_size += p->count * sizeof (Elf32_External_Rela);
4374 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
4375 info->flags |= DF_TEXTREL;
4376 }
37c644f2
AO
4377 }
4378 }
067653c5
AM
4379
4380 local_got = elf_local_got_refcounts (ibfd);
4381 if (!local_got)
4382 continue;
4383
4384 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
4385 locsymcount = symtab_hdr->sh_info;
4386#ifdef INCLUDE_SHMEDIA
4387 /* Count datalabel local GOT. */
4388 locsymcount *= 2;
4389#endif
4390 end_local_got = local_got + locsymcount;
3376eaf5 4391 local_tls_type = sh_elf_local_got_tls_type (ibfd);
067653c5
AM
4392 s = htab->sgot;
4393 srel = htab->srelgot;
4394 for (; local_got < end_local_got; ++local_got)
37c644f2 4395 {
067653c5 4396 if (*local_got > 0)
37c644f2 4397 {
067653c5
AM
4398 *local_got = s->_raw_size;
4399 s->_raw_size += 4;
3376eaf5
KK
4400 if (*local_tls_type == GOT_TLS_GD)
4401 s->_raw_size += 4;
067653c5
AM
4402 if (info->shared)
4403 srel->_raw_size += sizeof (Elf32_External_Rela);
37c644f2
AO
4404 }
4405 else
067653c5 4406 *local_got = (bfd_vma) -1;
3376eaf5 4407 ++local_tls_type;
37c644f2 4408 }
067653c5
AM
4409 }
4410
3376eaf5
KK
4411 if (htab->tls_ldm_got.refcount > 0)
4412 {
4413 /* Allocate 2 got entries and 1 dynamic reloc for R_SH_TLS_LD_32
4414 relocs. */
4415 htab->tls_ldm_got.offset = htab->sgot->_raw_size;
4416 htab->sgot->_raw_size += 8;
4417 htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
4418 }
4419 else
4420 htab->tls_ldm_got.offset = -1;
4421
067653c5
AM
4422 /* Allocate global sym .plt and .got entries, and space for global
4423 sym dynamic relocs. */
4424 elf_link_hash_traverse (&htab->root, allocate_dynrelocs, (PTR) info);
4425
4426 /* We now have determined the sizes of the various dynamic sections.
4427 Allocate memory for them. */
b34976b6 4428 relocs = FALSE;
067653c5
AM
4429 for (s = dynobj->sections; s != NULL; s = s->next)
4430 {
4431 if ((s->flags & SEC_LINKER_CREATED) == 0)
4432 continue;
4433
4434 if (s == htab->splt
4435 || s == htab->sgot
4436 || s == htab->sgotplt)
4437 {
4438 /* Strip this section if we don't need it; see the
4439 comment below. */
4440 }
4441 else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
4442 {
4443 if (s->_raw_size != 0 && s != htab->srelplt)
b34976b6 4444 relocs = TRUE;
067653c5
AM
4445
4446 /* We use the reloc_count field as a counter if we need
4447 to copy relocs into the output file. */
4448 s->reloc_count = 0;
4449 }
4450 else
37c644f2
AO
4451 {
4452 /* It's not one of our sections, so don't allocate space. */
4453 continue;
4454 }
4455
067653c5 4456 if (s->_raw_size == 0)
37c644f2 4457 {
067653c5
AM
4458 /* If we don't need this section, strip it from the
4459 output file. This is mostly to handle .rela.bss and
4460 .rela.plt. We must create both sections in
4461 create_dynamic_sections, because they must be created
4462 before the linker maps input sections to output
4463 sections. The linker does that before
4464 adjust_dynamic_symbol is called, and it is that
4465 function which decides whether anything needs to go
4466 into these sections. */
4467
37c644f2
AO
4468 _bfd_strip_section_from_output (info, s);
4469 continue;
4470 }
4471
067653c5
AM
4472 /* Allocate memory for the section contents. We use bfd_zalloc
4473 here in case unused entries are not reclaimed before the
4474 section's contents are written out. This should not happen,
4475 but this way if it does, we get a R_SH_NONE reloc instead
4476 of garbage. */
957dcaa8 4477 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
067653c5 4478 if (s->contents == NULL)
b34976b6 4479 return FALSE;
37c644f2
AO
4480 }
4481
067653c5 4482 if (htab->root.dynamic_sections_created)
37c644f2
AO
4483 {
4484 /* Add some entries to the .dynamic section. We fill in the
4485 values later, in sh_elf_finish_dynamic_sections, but we
4486 must add the entries now so that we get the correct size for
4487 the .dynamic section. The DT_DEBUG entry is filled in by the
4488 dynamic linker and used by the debugger. */
dc810e39
AM
4489#define add_dynamic_entry(TAG, VAL) \
4490 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
4491
37c644f2
AO
4492 if (! info->shared)
4493 {
067653c5 4494 if (! add_dynamic_entry (DT_DEBUG, 0))
b34976b6 4495 return FALSE;
37c644f2
AO
4496 }
4497
067653c5 4498 if (htab->splt->_raw_size != 0)
37c644f2 4499 {
067653c5
AM
4500 if (! add_dynamic_entry (DT_PLTGOT, 0)
4501 || ! add_dynamic_entry (DT_PLTRELSZ, 0)
4502 || ! add_dynamic_entry (DT_PLTREL, DT_RELA)
4503 || ! add_dynamic_entry (DT_JMPREL, 0))
b34976b6 4504 return FALSE;
37c644f2
AO
4505 }
4506
4507 if (relocs)
4508 {
067653c5
AM
4509 if (! add_dynamic_entry (DT_RELA, 0)
4510 || ! add_dynamic_entry (DT_RELASZ, 0)
4511 || ! add_dynamic_entry (DT_RELAENT,
4512 sizeof (Elf32_External_Rela)))
b34976b6 4513 return FALSE;
37c644f2 4514
067653c5
AM
4515 /* If any dynamic relocs apply to a read-only section,
4516 then we need a DT_TEXTREL entry. */
4517 if ((info->flags & DF_TEXTREL) == 0)
4518 elf_link_hash_traverse (&htab->root, readonly_dynrelocs,
4519 (PTR) info);
4520
4521 if ((info->flags & DF_TEXTREL) != 0)
4522 {
4523 if (! add_dynamic_entry (DT_TEXTREL, 0))
b34976b6 4524 return FALSE;
067653c5 4525 }
37c644f2
AO
4526 }
4527 }
dc810e39 4528#undef add_dynamic_entry
37c644f2 4529
b34976b6 4530 return TRUE;
37c644f2 4531}
37c644f2
AO
4532\f
4533/* Relocate an SH ELF section. */
4534
b34976b6 4535static bfd_boolean
37c644f2
AO
4536sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
4537 contents, relocs, local_syms, local_sections)
f8df10f4 4538 bfd *output_bfd;
37c644f2
AO
4539 struct bfd_link_info *info;
4540 bfd *input_bfd;
4541 asection *input_section;
4542 bfd_byte *contents;
4543 Elf_Internal_Rela *relocs;
4544 Elf_Internal_Sym *local_syms;
4545 asection **local_sections;
4546{
067653c5 4547 struct elf_sh_link_hash_table *htab;
37c644f2
AO
4548 Elf_Internal_Shdr *symtab_hdr;
4549 struct elf_link_hash_entry **sym_hashes;
4550 Elf_Internal_Rela *rel, *relend;
4551 bfd *dynobj;
4552 bfd_vma *local_got_offsets;
4553 asection *sgot;
fbca6ad9 4554 asection *sgotplt;
37c644f2
AO
4555 asection *splt;
4556 asection *sreloc;
3376eaf5 4557 asection *srelgot;
37c644f2 4558
067653c5 4559 htab = sh_elf_hash_table (info);
37c644f2
AO
4560 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4561 sym_hashes = elf_sym_hashes (input_bfd);
067653c5 4562 dynobj = htab->root.dynobj;
37c644f2
AO
4563 local_got_offsets = elf_local_got_offsets (input_bfd);
4564
067653c5
AM
4565 sgot = htab->sgot;
4566 sgotplt = htab->sgotplt;
4567 splt = htab->splt;
37c644f2 4568 sreloc = NULL;
3376eaf5 4569 srelgot = NULL;
37c644f2
AO
4570
4571 rel = relocs;
4572 relend = relocs + input_section->reloc_count;
4573 for (; rel < relend; rel++)
4574 {
4575 int r_type;
4576 reloc_howto_type *howto;
4577 unsigned long r_symndx;
4578 Elf_Internal_Sym *sym;
4579 asection *sec;
4580 struct elf_link_hash_entry *h;
4581 bfd_vma relocation;
435b1e90 4582 bfd_vma addend = (bfd_vma) 0;
37c644f2 4583 bfd_reloc_status_type r;
fbca6ad9 4584 int seen_stt_datalabel = 0;
3376eaf5
KK
4585 bfd_vma off;
4586 int tls_type;
37c644f2
AO
4587
4588 r_symndx = ELF32_R_SYM (rel->r_info);
4589
37c644f2
AO
4590 r_type = ELF32_R_TYPE (rel->r_info);
4591
4592 /* Many of the relocs are only used for relaxing, and are
067653c5 4593 handled entirely by the relaxation code. */
37c644f2
AO
4594 if (r_type > (int) R_SH_LAST_INVALID_RELOC
4595 && r_type < (int) R_SH_LOOP_START)
4596 continue;
c5aeb40f
AO
4597 if (r_type == (int) R_SH_NONE)
4598 continue;
37c644f2
AO
4599
4600 if (r_type < 0
4601 || r_type >= R_SH_max
4602 || (r_type >= (int) R_SH_FIRST_INVALID_RELOC
06bb75c1 4603 && r_type <= (int) R_SH_LAST_INVALID_RELOC)
fbca6ad9
AO
4604 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_3
4605 && r_type <= (int) R_SH_LAST_INVALID_RELOC_3)
4606 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_4
4607 && r_type <= (int) R_SH_LAST_INVALID_RELOC_4)
3376eaf5
KK
4608 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_5
4609 && r_type <= (int) R_SH_LAST_INVALID_RELOC_5)
06bb75c1
AO
4610 || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_2
4611 && r_type <= (int) R_SH_LAST_INVALID_RELOC_2))
37c644f2
AO
4612 {
4613 bfd_set_error (bfd_error_bad_value);
b34976b6 4614 return FALSE;
37c644f2
AO
4615 }
4616
4617 howto = sh_elf_howto_table + r_type;
4618
146be91a 4619 /* For relocs that aren't partial_inplace, we get the addend from
067653c5 4620 the relocation. */
146be91a
HPN
4621 if (! howto->partial_inplace)
4622 addend = rel->r_addend;
4623
37c644f2
AO
4624 h = NULL;
4625 sym = NULL;
4626 sec = NULL;
4627 if (r_symndx < symtab_hdr->sh_info)
4628 {
4629 sym = local_syms + r_symndx;
4630 sec = local_sections[r_symndx];
4631 relocation = (sec->output_section->vma
4632 + sec->output_offset
4633 + sym->st_value);
fbca6ad9
AO
4634 /* A local symbol never has STO_SH5_ISA32, so we don't need
4635 datalabel processing here. Make sure this does not change
4636 without notice. */
4637 if ((sym->st_other & STO_SH5_ISA32) != 0)
4638 ((*info->callbacks->reloc_dangerous)
4639 (info,
4640 _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
4641 input_bfd, input_section, rel->r_offset));
8a3975e6
AO
4642 if (info->relocateable)
4643 {
4644 /* This is a relocateable link. We don't have to change
4645 anything, unless the reloc is against a section symbol,
4646 in which case we have to adjust according to where the
4647 section symbol winds up in the output section. */
4648 sym = local_syms + r_symndx;
4649 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
146be91a
HPN
4650 {
4651 if (! howto->partial_inplace)
4652 {
4653 /* For relocations with the addend in the
4654 relocation, we need just to update the addend.
4655 All real relocs are of type partial_inplace; this
4656 code is mostly for completeness. */
4657 rel->r_addend += sec->output_offset + sym->st_value;
4658
4659 continue;
4660 }
4661
4662 /* Relocs of type partial_inplace need to pick up the
4663 contents in the contents and add the offset resulting
4664 from the changed location of the section symbol.
4665 Using _bfd_final_link_relocate (e.g. goto
4666 final_link_relocate) here would be wrong, because
4667 relocations marked pc_relative would get the current
4668 location subtracted, and we must only do that at the
4669 final link. */
4670 r = _bfd_relocate_contents (howto, input_bfd,
4671 sec->output_offset
4672 + sym->st_value,
4673 contents + rel->r_offset);
4674 goto relocation_done;
4675 }
8a3975e6
AO
4676
4677 continue;
4678 }
f8df10f4
JJ
4679 else if (! howto->partial_inplace)
4680 {
4681 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
4682 addend = rel->r_addend;
4683 }
4684 else if ((sec->flags & SEC_MERGE)
4685 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
4686 {
4687 asection *msec;
4688
4689 if (howto->rightshift || howto->src_mask != 0xffffffff)
4690 {
4691 (*_bfd_error_handler)
4692 (_("%s(%s+0x%lx): %s relocation against SEC_MERGE section"),
4693 bfd_archive_filename (input_bfd),
4694 bfd_get_section_name (input_bfd, input_section),
4695 (long) rel->r_offset, howto->name);
b34976b6 4696 return FALSE;
f8df10f4
JJ
4697 }
4698
067653c5
AM
4699 addend = bfd_get_32 (input_bfd, contents + rel->r_offset);
4700 msec = sec;
4701 addend =
c629eae0 4702 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
f8df10f4
JJ
4703 - relocation;
4704 addend += msec->output_section->vma + msec->output_offset;
4705 bfd_put_32 (input_bfd, addend, contents + rel->r_offset);
4706 addend = 0;
4707 }
37c644f2
AO
4708 }
4709 else
4710 {
8a3975e6
AO
4711 /* Section symbol are never (?) placed in the hash table, so
4712 we can just ignore hash relocations when creating a
4713 relocateable object file. */
4714 if (info->relocateable)
4715 continue;
4716
37c644f2
AO
4717 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4718 while (h->root.type == bfd_link_hash_indirect
4719 || h->root.type == bfd_link_hash_warning)
fbca6ad9
AO
4720 {
4721#ifdef INCLUDE_SHMEDIA
4722 /* If the reference passes a symbol marked with
4723 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
4724 doesn't count. */
4725 seen_stt_datalabel |= h->type == STT_DATALABEL;
4726#endif
4727 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4728 }
37c644f2
AO
4729 if (h->root.type == bfd_link_hash_defined
4730 || h->root.type == bfd_link_hash_defweak)
4731 {
b34976b6 4732 bfd_boolean dyn;
067653c5
AM
4733
4734 dyn = htab->root.dynamic_sections_created;
37c644f2
AO
4735 sec = h->root.u.def.section;
4736 /* In these cases, we don't need the relocation value.
4737 We check specially because in some obscure cases
435b1e90 4738 sec->output_section will be NULL. */
37c644f2 4739 if (r_type == R_SH_GOTPC
fbca6ad9
AO
4740 || r_type == R_SH_GOTPC_LOW16
4741 || r_type == R_SH_GOTPC_MEDLOW16
4742 || r_type == R_SH_GOTPC_MEDHI16
4743 || r_type == R_SH_GOTPC_HI16
4744 || ((r_type == R_SH_PLT32
4745 || r_type == R_SH_PLT_LOW16
4746 || r_type == R_SH_PLT_MEDLOW16
4747 || r_type == R_SH_PLT_MEDHI16
4748 || r_type == R_SH_PLT_HI16)
37c644f2 4749 && h->plt.offset != (bfd_vma) -1)
fbca6ad9
AO
4750 || ((r_type == R_SH_GOT32
4751 || r_type == R_SH_GOT_LOW16
4752 || r_type == R_SH_GOT_MEDLOW16
4753 || r_type == R_SH_GOT_MEDHI16
4754 || r_type == R_SH_GOT_HI16)
067653c5 4755 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)
37c644f2
AO
4756 && (! info->shared
4757 || (! info->symbolic && h->dynindx != -1)
4758 || (h->elf_link_hash_flags
4759 & ELF_LINK_HASH_DEF_REGULAR) == 0))
4760 /* The cases above are those in which relocation is
4761 overwritten in the switch block below. The cases
4762 below are those in which we must defer relocation
4763 to run-time, because we can't resolve absolute
4764 addresses when creating a shared library. */
4765 || (info->shared
4766 && ((! info->symbolic && h->dynindx != -1)
4767 || (h->elf_link_hash_flags
4768 & ELF_LINK_HASH_DEF_REGULAR) == 0)
4769 && ((r_type == R_SH_DIR32
067653c5
AM
4770 && (h->elf_link_hash_flags
4771 & ELF_LINK_FORCED_LOCAL) == 0)
37c644f2
AO
4772 || r_type == R_SH_REL32)
4773 && ((input_section->flags & SEC_ALLOC) != 0
4774 /* DWARF will emit R_SH_DIR32 relocations in its
4775 sections against symbols defined externally
4776 in shared libraries. We can't do anything
4777 with them here. */
067653c5
AM
4778 || ((input_section->flags & SEC_DEBUGGING) != 0
4779 && (h->elf_link_hash_flags
3376eaf5 4780 & ELF_LINK_HASH_DEF_DYNAMIC) != 0)))
1448fa32
KK
4781 /* Dynamic relocs are not propagated for SEC_DEBUGGING
4782 sections because such sections are not SEC_ALLOC and
4783 thus ld.so will not process them. */
4784 || (sec->output_section == NULL
4785 && ((input_section->flags & SEC_DEBUGGING) != 0
4786 && (h->elf_link_hash_flags
4787 & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
3376eaf5
KK
4788 || (sec->output_section == NULL
4789 && (sh_elf_hash_entry (h)->tls_type == GOT_TLS_IE
4790 || sh_elf_hash_entry (h)->tls_type == GOT_TLS_GD)))
37c644f2
AO
4791 relocation = 0;
4792 else if (sec->output_section == NULL)
4793 {
4794 (*_bfd_error_handler)
3376eaf5 4795 (_("%s: unresolvable relocation against symbol `%s' from %s section"),
8f615d07 4796 bfd_archive_filename (input_bfd), h->root.root.string,
37c644f2 4797 bfd_get_section_name (input_bfd, input_section));
b34976b6 4798 return FALSE;
37c644f2
AO
4799 }
4800 else
fbca6ad9 4801 relocation = ((h->root.u.def.value
37c644f2 4802 + sec->output_section->vma
fbca6ad9
AO
4803 + sec->output_offset)
4804 /* A STO_SH5_ISA32 causes a "bitor 1" to the
4805 symbol value, unless we've seen
4806 STT_DATALABEL on the way to it. */
4807 | ((h->other & STO_SH5_ISA32) != 0
4808 && ! seen_stt_datalabel));
37c644f2
AO
4809 }
4810 else if (h->root.type == bfd_link_hash_undefweak)
4811 relocation = 0;
671bae9c 4812 else if (info->shared
067653c5
AM
4813 && ! info->no_undefined
4814 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
37c644f2
AO
4815 relocation = 0;
4816 else
4817 {
4818 if (! ((*info->callbacks->undefined_symbol)
4819 (info, h->root.root.string, input_bfd,
067653c5
AM
4820 input_section, rel->r_offset,
4821 (!info->shared || info->no_undefined
4822 || ELF_ST_VISIBILITY (h->other)))))
b34976b6 4823 return FALSE;
37c644f2
AO
4824 relocation = 0;
4825 }
4826 }
4827
435b1e90 4828 switch ((int) r_type)
37c644f2
AO
4829 {
4830 final_link_relocate:
4831 /* COFF relocs don't use the addend. The addend is used for
435b1e90 4832 R_SH_DIR32 to be compatible with other compilers. */
37c644f2
AO
4833 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
4834 contents, rel->r_offset,
4835 relocation, addend);
4836 break;
4837
4838 case R_SH_IND12W:
cd6ec716
DD
4839 goto final_link_relocate;
4840
37c644f2
AO
4841 case R_SH_DIR8WPN:
4842 case R_SH_DIR8WPZ:
4843 case R_SH_DIR8WPL:
cd6ec716
DD
4844 /* If the reloc is against the start of this section, then
4845 the assembler has already taken care of it and the reloc
4846 is here only to assist in relaxing. If the reloc is not
4847 against the start of this section, then it's against an
4848 external symbol and we must deal with it ourselves. */
4849 if (input_section->output_section->vma + input_section->output_offset
4850 != relocation)
4851 {
4852 int disp = (relocation
4853 - input_section->output_section->vma
4854 - input_section->output_offset
4855 - rel->r_offset);
4856 int mask = 0;
4857 switch (r_type)
4858 {
4859 case R_SH_DIR8WPN:
4860 case R_SH_DIR8WPZ: mask = 1; break;
4861 case R_SH_DIR8WPL: mask = 3; break;
4862 default: mask = 0; break;
4863 }
4864 if (disp & mask)
4865 {
4866 ((*_bfd_error_handler)
4867 (_("%s: 0x%lx: fatal: unaligned branch target for relax-support relocation"),
8f615d07 4868 bfd_archive_filename (input_section->owner),
cd6ec716
DD
4869 (unsigned long) rel->r_offset));
4870 bfd_set_error (bfd_error_bad_value);
b34976b6 4871 return FALSE;
cd6ec716
DD
4872 }
4873 relocation -= 4;
4874 goto final_link_relocate;
4875 }
4876 r = bfd_reloc_ok;
4877 break;
37c644f2
AO
4878
4879 default:
fbca6ad9
AO
4880#ifdef INCLUDE_SHMEDIA
4881 if (shmedia_prepare_reloc (info, input_bfd, input_section,
4882 contents, rel, &relocation))
4883 goto final_link_relocate;
4884#endif
37c644f2 4885 bfd_set_error (bfd_error_bad_value);
b34976b6 4886 return FALSE;
37c644f2
AO
4887
4888 case R_SH_DIR32:
4889 case R_SH_REL32:
4890 if (info->shared
ec338859 4891 && r_symndx != 0
37c644f2
AO
4892 && (input_section->flags & SEC_ALLOC) != 0
4893 && (r_type != R_SH_REL32
4894 || (h != NULL
4895 && h->dynindx != -1
4896 && (! info->symbolic
4897 || (h->elf_link_hash_flags
4898 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
4899 {
4900 Elf_Internal_Rela outrel;
947216bf 4901 bfd_byte *loc;
b34976b6 4902 bfd_boolean skip, relocate;
37c644f2
AO
4903
4904 /* When generating a shared object, these relocations
4905 are copied into the output file to be resolved at run
4906 time. */
4907
4908 if (sreloc == NULL)
4909 {
4910 const char *name;
4911
4912 name = (bfd_elf_string_from_elf_section
4913 (input_bfd,
4914 elf_elfheader (input_bfd)->e_shstrndx,
4915 elf_section_data (input_section)->rel_hdr.sh_name));
4916 if (name == NULL)
b34976b6 4917 return FALSE;
37c644f2
AO
4918
4919 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
4920 && strcmp (bfd_get_section_name (input_bfd,
4921 input_section),
4922 name + 5) == 0);
4923
4924 sreloc = bfd_get_section_by_name (dynobj, name);
4925 BFD_ASSERT (sreloc != NULL);
4926 }
4927
b34976b6
AM
4928 skip = FALSE;
4929 relocate = FALSE;
37c644f2 4930
c629eae0
JJ
4931 outrel.r_offset =
4932 _bfd_elf_section_offset (output_bfd, info, input_section,
4933 rel->r_offset);
4934 if (outrel.r_offset == (bfd_vma) -1)
b34976b6 4935 skip = TRUE;
0bb2d96a 4936 else if (outrel.r_offset == (bfd_vma) -2)
b34976b6 4937 skip = TRUE, relocate = TRUE;
37c644f2
AO
4938 outrel.r_offset += (input_section->output_section->vma
4939 + input_section->output_offset);
4940
4941 if (skip)
0bb2d96a 4942 memset (&outrel, 0, sizeof outrel);
37c644f2
AO
4943 else if (r_type == R_SH_REL32)
4944 {
4945 BFD_ASSERT (h != NULL && h->dynindx != -1);
37c644f2 4946 outrel.r_info = ELF32_R_INFO (h->dynindx, R_SH_REL32);
146be91a
HPN
4947 outrel.r_addend
4948 = bfd_get_32 (input_bfd, contents + rel->r_offset);
37c644f2
AO
4949 }
4950 else
4951 {
4952 /* h->dynindx may be -1 if this symbol was marked to
4953 become local. */
4954 if (h == NULL
4955 || ((info->symbolic || h->dynindx == -1)
4956 && (h->elf_link_hash_flags
4957 & ELF_LINK_HASH_DEF_REGULAR) != 0))
4958 {
b34976b6 4959 relocate = TRUE;
37c644f2 4960 outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
146be91a
HPN
4961 outrel.r_addend
4962 = relocation + bfd_get_32 (input_bfd,
4963 contents + rel->r_offset);
37c644f2
AO
4964 }
4965 else
4966 {
4967 BFD_ASSERT (h->dynindx != -1);
37c644f2 4968 outrel.r_info = ELF32_R_INFO (h->dynindx, R_SH_DIR32);
146be91a
HPN
4969 outrel.r_addend
4970 = relocation + bfd_get_32 (input_bfd,
4971 contents + rel->r_offset);
37c644f2
AO
4972 }
4973 }
4974
947216bf
AM
4975 loc = sreloc->contents;
4976 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
4977 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
37c644f2
AO
4978
4979 /* If this reloc is against an external symbol, we do
4980 not want to fiddle with the addend. Otherwise, we
4981 need to include the symbol value so that it becomes
4982 an addend for the dynamic reloc. */
4983 if (! relocate)
4984 continue;
4985 }
37c644f2
AO
4986 goto final_link_relocate;
4987
fbca6ad9
AO
4988 case R_SH_GOTPLT32:
4989#ifdef INCLUDE_SHMEDIA
4990 case R_SH_GOTPLT_LOW16:
4991 case R_SH_GOTPLT_MEDLOW16:
4992 case R_SH_GOTPLT_MEDHI16:
4993 case R_SH_GOTPLT_HI16:
4994 case R_SH_GOTPLT10BY4:
4995 case R_SH_GOTPLT10BY8:
4996#endif
4997 /* Relocation is to the entry for this symbol in the
4998 procedure linkage table. */
4999
5000 if (h == NULL
067653c5 5001 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)
fbca6ad9
AO
5002 || ! info->shared
5003 || info->symbolic
5004 || h->dynindx == -1
5005 || h->plt.offset == (bfd_vma) -1
5006 || h->got.offset != (bfd_vma) -1)
5007 goto force_got;
5008
5009 /* Relocation is to the entry for this symbol in the global
5010 offset table extension for the procedure linkage table. */
fbca6ad9 5011
067653c5 5012 BFD_ASSERT (sgotplt != NULL);
fbca6ad9
AO
5013 relocation = (sgotplt->output_offset
5014 + ((h->plt.offset / elf_sh_sizeof_plt (info)
5015 - 1 + 3) * 4));
5016
5017#ifdef GOT_BIAS
5018 relocation -= GOT_BIAS;
5019#endif
5020
5021 goto final_link_relocate;
5022
5023 force_got:
37c644f2 5024 case R_SH_GOT32:
fbca6ad9
AO
5025#ifdef INCLUDE_SHMEDIA
5026 case R_SH_GOT_LOW16:
5027 case R_SH_GOT_MEDLOW16:
5028 case R_SH_GOT_MEDHI16:
5029 case R_SH_GOT_HI16:
5030 case R_SH_GOT10BY4:
5031 case R_SH_GOT10BY8:
5032#endif
37c644f2
AO
5033 /* Relocation is to the entry for this symbol in the global
5034 offset table. */
067653c5
AM
5035
5036 BFD_ASSERT (sgot != NULL);
37c644f2
AO
5037
5038 if (h != NULL)
5039 {
b34976b6 5040 bfd_boolean dyn;
37c644f2
AO
5041
5042 off = h->got.offset;
fbca6ad9
AO
5043#ifdef INCLUDE_SHMEDIA
5044 if (seen_stt_datalabel)
5045 {
5046 struct elf_sh_link_hash_entry *hsh;
5047
5048 hsh = (struct elf_sh_link_hash_entry *)h;
396a6083 5049 off = hsh->datalabel_got.offset;
fbca6ad9
AO
5050 }
5051#endif
37c644f2
AO
5052 BFD_ASSERT (off != (bfd_vma) -1);
5053
067653c5
AM
5054 dyn = htab->root.dynamic_sections_created;
5055 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)
37c644f2
AO
5056 || (info->shared
5057 && (info->symbolic || h->dynindx == -1
067653c5 5058 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
37c644f2
AO
5059 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
5060 {
5061 /* This is actually a static link, or it is a
5062 -Bsymbolic link and the symbol is defined
5063 locally, or the symbol was forced to be local
5064 because of a version file. We must initialize
5065 this entry in the global offset table. Since the
5066 offset must always be a multiple of 4, we use the
5067 least significant bit to record whether we have
5068 initialized it already.
5069
5070 When doing a dynamic link, we create a .rela.got
5071 relocation entry to initialize the value. This
5072 is done in the finish_dynamic_symbol routine. */
5073 if ((off & 1) != 0)
5074 off &= ~1;
5075 else
5076 {
5077 bfd_put_32 (output_bfd, relocation,
5078 sgot->contents + off);
fbca6ad9
AO
5079#ifdef INCLUDE_SHMEDIA
5080 if (seen_stt_datalabel)
5081 {
5082 struct elf_sh_link_hash_entry *hsh;
5083
5084 hsh = (struct elf_sh_link_hash_entry *)h;
396a6083 5085 hsh->datalabel_got.offset |= 1;
fbca6ad9
AO
5086 }
5087 else
5088#endif
5089 h->got.offset |= 1;
37c644f2
AO
5090 }
5091 }
5092
5093 relocation = sgot->output_offset + off;
5094 }
5095 else
5096 {
fbca6ad9
AO
5097#ifdef INCLUDE_SHMEDIA
5098 if (rel->r_addend)
5099 {
5100 BFD_ASSERT (local_got_offsets != NULL
5101 && (local_got_offsets[symtab_hdr->sh_info
5102 + r_symndx]
5103 != (bfd_vma) -1));
5104
5105 off = local_got_offsets[symtab_hdr->sh_info
5106 + r_symndx];
5107 }
5108 else
5109 {
5110#endif
37c644f2
AO
5111 BFD_ASSERT (local_got_offsets != NULL
5112 && local_got_offsets[r_symndx] != (bfd_vma) -1);
5113
5114 off = local_got_offsets[r_symndx];
fbca6ad9
AO
5115#ifdef INCLUDE_SHMEDIA
5116 }
5117#endif
37c644f2
AO
5118
5119 /* The offset must always be a multiple of 4. We use
5120 the least significant bit to record whether we have
5121 already generated the necessary reloc. */
5122 if ((off & 1) != 0)
5123 off &= ~1;
5124 else
5125 {
5126 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
5127
5128 if (info->shared)
5129 {
37c644f2 5130 Elf_Internal_Rela outrel;
947216bf 5131 bfd_byte *loc;
37c644f2 5132
3376eaf5
KK
5133 if (srelgot == NULL)
5134 {
5135 srelgot = bfd_get_section_by_name (dynobj,
5136 ".rela.got");
5137 BFD_ASSERT (srelgot != NULL);
5138 }
37c644f2
AO
5139
5140 outrel.r_offset = (sgot->output_section->vma
5141 + sgot->output_offset
5142 + off);
5143 outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
5144 outrel.r_addend = relocation;
947216bf
AM
5145 loc = srelgot->contents;
5146 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
5147 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
37c644f2
AO
5148 }
5149
fbca6ad9
AO
5150#ifdef INCLUDE_SHMEDIA
5151 if (rel->r_addend)
5152 local_got_offsets[symtab_hdr->sh_info + r_symndx] |= 1;
5153 else
5154#endif
5155 local_got_offsets[r_symndx] |= 1;
37c644f2
AO
5156 }
5157
5158 relocation = sgot->output_offset + off;
5159 }
5160
fbca6ad9 5161#ifdef GOT_BIAS
067653c5 5162 relocation -= GOT_BIAS;
fbca6ad9
AO
5163#endif
5164
37c644f2
AO
5165 goto final_link_relocate;
5166
5167 case R_SH_GOTOFF:
fbca6ad9
AO
5168#ifdef INCLUDE_SHMEDIA
5169 case R_SH_GOTOFF_LOW16:
5170 case R_SH_GOTOFF_MEDLOW16:
5171 case R_SH_GOTOFF_MEDHI16:
5172 case R_SH_GOTOFF_HI16:
5173#endif
37c644f2
AO
5174 /* Relocation is relative to the start of the global offset
5175 table. */
5176
067653c5 5177 BFD_ASSERT (sgot != NULL);
37c644f2
AO
5178
5179 /* Note that sgot->output_offset is not involved in this
5180 calculation. We always want the start of .got. If we
5181 defined _GLOBAL_OFFSET_TABLE in a different way, as is
5182 permitted by the ABI, we might have to change this
5183 calculation. */
5184 relocation -= sgot->output_section->vma;
5185
fbca6ad9
AO
5186#ifdef GOT_BIAS
5187 relocation -= GOT_BIAS;
5188#endif
5189
5190 addend = rel->r_addend;
5191
37c644f2
AO
5192 goto final_link_relocate;
5193
5194 case R_SH_GOTPC:
fbca6ad9
AO
5195#ifdef INCLUDE_SHMEDIA
5196 case R_SH_GOTPC_LOW16:
5197 case R_SH_GOTPC_MEDLOW16:
5198 case R_SH_GOTPC_MEDHI16:
5199 case R_SH_GOTPC_HI16:
5200#endif
37c644f2
AO
5201 /* Use global offset table as symbol value. */
5202
067653c5 5203 BFD_ASSERT (sgot != NULL);
37c644f2
AO
5204 relocation = sgot->output_section->vma;
5205
fbca6ad9
AO
5206#ifdef GOT_BIAS
5207 relocation += GOT_BIAS;
5208#endif
5209
5210 addend = rel->r_addend;
5211
37c644f2
AO
5212 goto final_link_relocate;
5213
5214 case R_SH_PLT32:
fbca6ad9
AO
5215#ifdef INCLUDE_SHMEDIA
5216 case R_SH_PLT_LOW16:
5217 case R_SH_PLT_MEDLOW16:
5218 case R_SH_PLT_MEDHI16:
5219 case R_SH_PLT_HI16:
5220#endif
37c644f2
AO
5221 /* Relocation is to the entry for this symbol in the
5222 procedure linkage table. */
5223
5224 /* Resolve a PLT reloc against a local symbol directly,
5225 without using the procedure linkage table. */
5226 if (h == NULL)
5227 goto final_link_relocate;
5228
067653c5 5229 if (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)
37c644f2
AO
5230 goto final_link_relocate;
5231
5232 if (h->plt.offset == (bfd_vma) -1)
5233 {
5234 /* We didn't make a PLT entry for this symbol. This
5235 happens when statically linking PIC code, or when
5236 using -Bsymbolic. */
5237 goto final_link_relocate;
5238 }
5239
067653c5 5240 BFD_ASSERT (splt != NULL);
37c644f2
AO
5241 relocation = (splt->output_section->vma
5242 + splt->output_offset
5243 + h->plt.offset);
5244
fbca6ad9
AO
5245#ifdef INCLUDE_SHMEDIA
5246 relocation++;
5247#endif
5248
5249 addend = rel->r_addend;
5250
37c644f2
AO
5251 goto final_link_relocate;
5252
5253 case R_SH_LOOP_START:
5254 {
5255 static bfd_vma start, end;
5256
5257 start = (relocation + rel->r_addend
5258 - (sec->output_section->vma + sec->output_offset));
5259 r = sh_elf_reloc_loop (r_type, input_bfd, input_section, contents,
5260 rel->r_offset, sec, start, end);
5261 break;
5262
5263 case R_SH_LOOP_END:
5264 end = (relocation + rel->r_addend
5265 - (sec->output_section->vma + sec->output_offset));
5266 r = sh_elf_reloc_loop (r_type, input_bfd, input_section, contents,
5267 rel->r_offset, sec, start, end);
5268 break;
5269 }
3376eaf5
KK
5270
5271 case R_SH_TLS_GD_32:
5272 case R_SH_TLS_IE_32:
5273 r_type = sh_elf_optimized_tls_reloc (info, r_type, h == NULL);
5274 tls_type = GOT_UNKNOWN;
5275 if (h == NULL && local_got_offsets)
5276 tls_type = sh_elf_local_got_tls_type (input_bfd) [r_symndx];
5277 else if (h != NULL)
5278 {
5279 tls_type = sh_elf_hash_entry (h)->tls_type;
5280 if (! info->shared
5281 && (h->dynindx == -1
c95b8a7a
KK
5282 || (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
5283 {
5284 struct elf_sh_dyn_relocs *p;
5285
5286 /* If TPOFF32 relocation can be created, convert it. */
5287 for (p = sh_elf_hash_entry (h)->dyn_relocs; p; p = p->next)
5288 if (p->sec == input_section && p->tls_tpoff32)
5289 {
5290 r_type = R_SH_TLS_LE_32;
5291 break;
5292 }
5293 }
3376eaf5
KK
5294 }
5295
5296 if (r_type == R_SH_TLS_GD_32 && tls_type == GOT_TLS_IE)
5297 r_type = R_SH_TLS_IE_32;
5298
5299 if (r_type == R_SH_TLS_LE_32)
5300 {
5301 bfd_vma offset;
5302 unsigned short insn;
5303 int indx;
5304 Elf_Internal_Rela outrel;
947216bf 5305 bfd_byte *loc;
3376eaf5
KK
5306
5307 if (ELF32_R_TYPE (rel->r_info) == R_SH_TLS_GD_32)
5308 {
5309 /* GD->LE transition:
5310 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
b34976b6 5311 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
3376eaf5
KK
5312 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5313 We change it into:
5314 mov.l 1f,r4; stc gbr,r0; add r4,r0; nop;
5315 nop; nop; ...
5316 1: .long x@TPOFF; 2: .long __tls_get_addr@PLT; 3:. */
5317
5318 offset = rel->r_offset;
5319 BFD_ASSERT (offset >= 16);
5320 /* Size of GD instructions is 16 or 18. */
5321 offset -= 16;
5322 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5323 if ((insn & 0xff00) == 0xc700)
5324 {
5325 BFD_ASSERT (offset >= 2);
5326 offset -= 2;
5327 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5328 }
5329
5330 BFD_ASSERT ((insn & 0xff00) == 0xd400);
5331 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5332 BFD_ASSERT ((insn & 0xff00) == 0xc700);
5333 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5334 BFD_ASSERT ((insn & 0xff00) == 0xd100);
5335 insn = bfd_get_16 (input_bfd, contents + offset + 6);
5336 BFD_ASSERT (insn == 0x310c);
5337 insn = bfd_get_16 (input_bfd, contents + offset + 8);
5338 BFD_ASSERT (insn == 0x410b);
5339 insn = bfd_get_16 (input_bfd, contents + offset + 10);
5340 BFD_ASSERT (insn == 0x34cc);
5341
5342 bfd_put_16 (output_bfd, 0x0012, contents + offset + 2);
5343 bfd_put_16 (output_bfd, 0x304c, contents + offset + 4);
5344 bfd_put_16 (output_bfd, 0x0009, contents + offset + 6);
5345 bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
5346 bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
5347 }
5348 else
5349 {
5350 int index;
5351
5352 /* IE->LE transition:
5353 mov.l 1f,r0; stc gbr,rN; mov.l @(r0,r12),rM;
5354 bra 2f; add ...; .align 2; 1: x@GOTTPOFF; 2:
5355 We change it into:
5356 mov.l .Ln,rM; stc gbr,rN; nop; ...;
5357 1: x@TPOFF; 2:. */
5358
5359 offset = rel->r_offset;
5360 BFD_ASSERT (offset >= 16);
5361 /* Size of IE instructions is 10 or 12. */
5362 offset -= 10;
5363 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5364 if ((insn & 0xf0ff) == 0x0012)
5365 {
5366 BFD_ASSERT (offset >= 2);
5367 offset -= 2;
5368 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5369 }
5370
5371 BFD_ASSERT ((insn & 0xff00) == 0xd000);
5372 index = insn & 0x00ff;
5373 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5374 BFD_ASSERT ((insn & 0xf0ff) == 0x0012);
5375 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5376 BFD_ASSERT ((insn & 0xf0ff) == 0x00ce);
5377 insn = 0xd000 | (insn & 0x0f00) | index;
5378 bfd_put_16 (output_bfd, insn, contents + offset + 0);
5379 bfd_put_16 (output_bfd, 0x0009, contents + offset + 4);
5380 }
5381
5382 if (sreloc == NULL)
5383 {
5384 const char *name;
5385
5386 name = (bfd_elf_string_from_elf_section
5387 (input_bfd,
5388 elf_elfheader (input_bfd)->e_shstrndx,
5389 elf_section_data (input_section)->rel_hdr.sh_name));
5390 if (name == NULL)
b34976b6 5391 return FALSE;
3376eaf5
KK
5392
5393 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
5394 && strcmp (bfd_get_section_name (input_bfd,
5395 input_section),
5396 name + 5) == 0);
5397
5398 sreloc = bfd_get_section_by_name (dynobj, name);
5399 BFD_ASSERT (sreloc != NULL);
5400 }
5401
c95b8a7a
KK
5402 if (h == NULL
5403 || h->dynindx == -1
5404 || (! info->shared
5405 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
5406 indx = 0;
5407 else
5408 indx = h->dynindx;
3376eaf5
KK
5409 outrel.r_offset = (input_section->output_section->vma
5410 + input_section->output_offset
5411 + rel->r_offset);
5412 outrel.r_info = ELF32_R_INFO (indx, R_SH_TLS_TPOFF32);
5413 if (indx == 0)
5414 outrel.r_addend = relocation - dtpoff_base (info);
5415 else
5416 outrel.r_addend = 0;
3376eaf5 5417
947216bf
AM
5418 loc = sreloc->contents;
5419 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
5420 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
3376eaf5
KK
5421 continue;
5422 }
5423
5424 sgot = htab->sgot;
5425 if (sgot == NULL)
5426 abort ();
5427
5428 if (h != NULL)
5429 off = h->got.offset;
5430 else
5431 {
5432 if (local_got_offsets == NULL)
5433 abort ();
5434
5435 off = local_got_offsets[r_symndx];
5436 }
5437
5438 if ((off & 1) != 0)
5439 off &= ~1;
26e41594 5440 else
3376eaf5
KK
5441 {
5442 Elf_Internal_Rela outrel;
947216bf 5443 bfd_byte *loc;
3376eaf5
KK
5444 int dr_type, indx;
5445
5446 if (srelgot == NULL)
5447 {
5448 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
5449 BFD_ASSERT (srelgot != NULL);
5450 }
5451
5452 outrel.r_offset = (sgot->output_section->vma
5453 + sgot->output_offset + off);
5454
c95b8a7a
KK
5455 if (h == NULL
5456 || h->dynindx == -1
5457 || (! info->shared
5458 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
5459 indx = 0;
5460 else
5461 indx = h->dynindx;
3376eaf5
KK
5462 dr_type = (r_type == R_SH_TLS_GD_32 ? R_SH_TLS_DTPMOD32 :
5463 R_SH_TLS_TPOFF32);
5464 if (dr_type == R_SH_TLS_TPOFF32 && indx == 0)
5465 outrel.r_addend = relocation - dtpoff_base (info);
5466 else
5467 outrel.r_addend = 0;
5468 outrel.r_info = ELF32_R_INFO (indx, dr_type);
947216bf
AM
5469 loc = srelgot->contents;
5470 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
3376eaf5
KK
5471 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5472
5473 if (r_type == R_SH_TLS_GD_32)
5474 {
5475 if (indx == 0)
5476 {
5477 bfd_put_32 (output_bfd,
5478 relocation - dtpoff_base (info),
5479 sgot->contents + off + 4);
5480 }
5481 else
5482 {
5483 outrel.r_info = ELF32_R_INFO (indx,
5484 R_SH_TLS_DTPOFF32);
5485 outrel.r_offset += 4;
5486 outrel.r_addend = 0;
5487 srelgot->reloc_count++;
947216bf
AM
5488 loc += sizeof (Elf32_External_Rela);
5489 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
3376eaf5
KK
5490 }
5491 }
5492
5493 if (h != NULL)
5494 h->got.offset |= 1;
5495 else
5496 local_got_offsets[r_symndx] |= 1;
5497 }
5498
5499 if (off >= (bfd_vma) -2)
5500 abort ();
5501
5502 if (r_type == (int) ELF32_R_TYPE (rel->r_info))
5503 relocation = sgot->output_offset + off;
5504 else
5505 {
5506 bfd_vma offset;
5507 unsigned short insn;
5508
5509 /* GD->IE transition:
5510 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5511 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5512 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5513 We change it into:
5514 mov.l 1f,r0; stc gbr,r4; mov.l @(r0,r12),r0; add r4,r0;
5515 nop; nop; bra 3f; nop; .align 2;
5516 1: .long x@TPOFF; 2:...; 3:. */
5517
5518 offset = rel->r_offset;
5519 BFD_ASSERT (offset >= 16);
5520 /* Size of GD instructions is 16 or 18. */
5521 offset -= 16;
5522 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5523 if ((insn & 0xff00) == 0xc700)
5524 {
5525 BFD_ASSERT (offset >= 2);
5526 offset -= 2;
5527 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5528 }
5529
5530 BFD_ASSERT ((insn & 0xff00) == 0xd400);
5531
5532 /* Replace mov.l 1f,R4 with mov.l 1f,r0. */
5533 bfd_put_16 (output_bfd, insn & 0xf0ff, contents + offset);
5534
5535 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5536 BFD_ASSERT ((insn & 0xff00) == 0xc700);
5537 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5538 BFD_ASSERT ((insn & 0xff00) == 0xd100);
5539 insn = bfd_get_16 (input_bfd, contents + offset + 6);
5540 BFD_ASSERT (insn == 0x310c);
5541 insn = bfd_get_16 (input_bfd, contents + offset + 8);
5542 BFD_ASSERT (insn == 0x410b);
5543 insn = bfd_get_16 (input_bfd, contents + offset + 10);
5544 BFD_ASSERT (insn == 0x34cc);
5545
5546 bfd_put_16 (output_bfd, 0x0412, contents + offset + 2);
5547 bfd_put_16 (output_bfd, 0x00ce, contents + offset + 4);
5548 bfd_put_16 (output_bfd, 0x304c, contents + offset + 6);
5549 bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
5550 bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
5551
5552 bfd_put_32 (output_bfd, sgot->output_offset + off,
5553 contents + rel->r_offset);
5554
5555 continue;
5556 }
5557
5558 addend = rel->r_addend;
5559
5560 goto final_link_relocate;
5561
5562 case R_SH_TLS_LD_32:
5563 if (! info->shared)
5564 {
5565 bfd_vma offset;
5566 unsigned short insn;
5567
5568 /* LD->LE transition:
5569 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5570 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5571 1: .long x$TLSLD; 2: .long __tls_get_addr@PLT; 3:
5572 We change it into:
5573 stc gbr,r0; nop; nop; nop;
5574 nop; nop; bra 3f; ...; 3:. */
5575
5576 offset = rel->r_offset;
5577 BFD_ASSERT (offset >= 16);
5578 /* Size of LD instructions is 16 or 18. */
5579 offset -= 16;
5580 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5581 if ((insn & 0xff00) == 0xc700)
5582 {
5583 BFD_ASSERT (offset >= 2);
5584 offset -= 2;
5585 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5586 }
5587
5588 BFD_ASSERT ((insn & 0xff00) == 0xd400);
5589 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5590 BFD_ASSERT ((insn & 0xff00) == 0xc700);
5591 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5592 BFD_ASSERT ((insn & 0xff00) == 0xd100);
5593 insn = bfd_get_16 (input_bfd, contents + offset + 6);
5594 BFD_ASSERT (insn == 0x310c);
5595 insn = bfd_get_16 (input_bfd, contents + offset + 8);
5596 BFD_ASSERT (insn == 0x410b);
5597 insn = bfd_get_16 (input_bfd, contents + offset + 10);
5598 BFD_ASSERT (insn == 0x34cc);
5599
5600 bfd_put_16 (output_bfd, 0x0012, contents + offset + 0);
5601 bfd_put_16 (output_bfd, 0x0009, contents + offset + 2);
5602 bfd_put_16 (output_bfd, 0x0009, contents + offset + 4);
5603 bfd_put_16 (output_bfd, 0x0009, contents + offset + 6);
5604 bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
5605 bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
5606
5607 continue;
5608 }
5609
5610 sgot = htab->sgot;
5611 if (sgot == NULL)
5612 abort ();
5613
5614 off = htab->tls_ldm_got.offset;
5615 if (off & 1)
5616 off &= ~1;
5617 else
5618 {
5619 Elf_Internal_Rela outrel;
947216bf 5620 bfd_byte *loc;
3376eaf5
KK
5621
5622 srelgot = htab->srelgot;
5623 if (srelgot == NULL)
5624 abort ();
5625
5626 outrel.r_offset = (sgot->output_section->vma
5627 + sgot->output_offset + off);
5628 outrel.r_addend = 0;
5629 outrel.r_info = ELF32_R_INFO (0, R_SH_TLS_DTPMOD32);
947216bf
AM
5630 loc = srelgot->contents;
5631 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
3376eaf5
KK
5632 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5633 htab->tls_ldm_got.offset |= 1;
5634 }
5635
5636 relocation = sgot->output_offset + off;
5637 addend = rel->r_addend;
5638
5639 goto final_link_relocate;
5640
5641 case R_SH_TLS_LDO_32:
5642 if (! info->shared)
5643 {
5644 int indx;
5645 Elf_Internal_Rela outrel;
947216bf 5646 bfd_byte *loc;
3376eaf5
KK
5647
5648 if (sreloc == NULL)
5649 {
5650 const char *name;
5651
5652 name = (bfd_elf_string_from_elf_section
5653 (input_bfd,
5654 elf_elfheader (input_bfd)->e_shstrndx,
5655 elf_section_data (input_section)->rel_hdr.sh_name));
5656 if (name == NULL)
b34976b6 5657 return FALSE;
3376eaf5
KK
5658
5659 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
5660 && strcmp (bfd_get_section_name (input_bfd,
5661 input_section),
5662 name + 5) == 0);
5663
5664 sreloc = bfd_get_section_by_name (dynobj, name);
5665 BFD_ASSERT (sreloc != NULL);
5666 }
5667
5668 indx = (h && h->dynindx != -1) ? h->dynindx : 0;
5669 outrel.r_offset = (input_section->output_section->vma
5670 + input_section->output_offset
5671 + rel->r_offset);
5672 outrel.r_info = ELF32_R_INFO (indx, R_SH_TLS_TPOFF32);
5673 if (indx == 0)
5674 outrel.r_addend = relocation - dtpoff_base (info);
5675 else
5676 outrel.r_addend = 0;
3376eaf5 5677
947216bf
AM
5678 loc = sreloc->contents;
5679 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
5680 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
3376eaf5
KK
5681 continue;
5682 }
5683 else
5684 relocation -= dtpoff_base (info);
5685
5686 addend = rel->r_addend;
5687 goto final_link_relocate;
5688
5689 case R_SH_TLS_LE_32:
5690 {
5691 int indx;
5692 Elf_Internal_Rela outrel;
947216bf 5693 bfd_byte *loc;
3376eaf5
KK
5694
5695 if (sreloc == NULL)
5696 {
5697 const char *name;
5698
5699 name = (bfd_elf_string_from_elf_section
5700 (input_bfd,
5701 elf_elfheader (input_bfd)->e_shstrndx,
5702 elf_section_data (input_section)->rel_hdr.sh_name));
5703 if (name == NULL)
b34976b6 5704 return FALSE;
3376eaf5
KK
5705
5706 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
5707 && strcmp (bfd_get_section_name (input_bfd,
5708 input_section),
5709 name + 5) == 0);
5710
5711 sreloc = bfd_get_section_by_name (dynobj, name);
5712 BFD_ASSERT (sreloc != NULL);
5713 }
5714
5715 indx = (h && h->dynindx != -1) ? h->dynindx : 0;
5716 outrel.r_offset = (input_section->output_section->vma
5717 + input_section->output_offset
5718 + rel->r_offset);
5719 outrel.r_info = ELF32_R_INFO (indx, R_SH_TLS_TPOFF32);
5720 if (indx == 0)
5721 outrel.r_addend = relocation - dtpoff_base (info);
5722 else
5723 outrel.r_addend = 0;
3376eaf5 5724
947216bf
AM
5725 loc = sreloc->contents;
5726 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
5727 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
3376eaf5
KK
5728 continue;
5729 }
37c644f2
AO
5730 }
5731
146be91a 5732 relocation_done:
37c644f2
AO
5733 if (r != bfd_reloc_ok)
5734 {
5735 switch (r)
5736 {
5737 default:
5738 case bfd_reloc_outofrange:
5739 abort ();
5740 case bfd_reloc_overflow:
5741 {
5742 const char *name;
5743
5744 if (h != NULL)
5745 name = h->root.root.string;
5746 else
5747 {
252b5132
RH
5748 name = (bfd_elf_string_from_elf_section
5749 (input_bfd, symtab_hdr->sh_link, sym->st_name));
5750 if (name == NULL)
b34976b6 5751 return FALSE;
252b5132
RH
5752 if (*name == '\0')
5753 name = bfd_section_name (input_bfd, sec);
5754 }
5755 if (! ((*info->callbacks->reloc_overflow)
5756 (info, name, howto->name, (bfd_vma) 0,
5757 input_bfd, input_section, rel->r_offset)))
b34976b6 5758 return FALSE;
252b5132
RH
5759 }
5760 break;
5761 }
5762 }
5763 }
5764
b34976b6 5765 return TRUE;
252b5132
RH
5766}
5767
5768/* This is a version of bfd_generic_get_relocated_section_contents
5769 which uses sh_elf_relocate_section. */
5770
5771static bfd_byte *
5772sh_elf_get_relocated_section_contents (output_bfd, link_info, link_order,
435b1e90 5773 data, relocateable, symbols)
252b5132
RH
5774 bfd *output_bfd;
5775 struct bfd_link_info *link_info;
5776 struct bfd_link_order *link_order;
5777 bfd_byte *data;
b34976b6 5778 bfd_boolean relocateable;
252b5132
RH
5779 asymbol **symbols;
5780{
5781 Elf_Internal_Shdr *symtab_hdr;
5782 asection *input_section = link_order->u.indirect.section;
5783 bfd *input_bfd = input_section->owner;
5784 asection **sections = NULL;
5785 Elf_Internal_Rela *internal_relocs = NULL;
6cdc0ccc 5786 Elf_Internal_Sym *isymbuf = NULL;
252b5132
RH
5787
5788 /* We only need to handle the case of relaxing, or of having a
5789 particular set of section contents, specially. */
5790 if (relocateable
5791 || elf_section_data (input_section)->this_hdr.contents == NULL)
5792 return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
5793 link_order, data,
5794 relocateable,
5795 symbols);
5796
5797 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
5798
5799 memcpy (data, elf_section_data (input_section)->this_hdr.contents,
dc810e39 5800 (size_t) input_section->_raw_size);
252b5132
RH
5801
5802 if ((input_section->flags & SEC_RELOC) != 0
5803 && input_section->reloc_count > 0)
5804 {
252b5132 5805 asection **secpp;
6cdc0ccc 5806 Elf_Internal_Sym *isym, *isymend;
9ad5cbcf 5807 bfd_size_type amt;
252b5132 5808
252b5132
RH
5809 internal_relocs = (_bfd_elf32_link_read_relocs
5810 (input_bfd, input_section, (PTR) NULL,
b34976b6 5811 (Elf_Internal_Rela *) NULL, FALSE));
252b5132
RH
5812 if (internal_relocs == NULL)
5813 goto error_return;
5814
6cdc0ccc
AM
5815 if (symtab_hdr->sh_info != 0)
5816 {
5817 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
5818 if (isymbuf == NULL)
5819 isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
5820 symtab_hdr->sh_info, 0,
5821 NULL, NULL, NULL);
5822 if (isymbuf == NULL)
5823 goto error_return;
5824 }
252b5132 5825
9ad5cbcf
AM
5826 amt = symtab_hdr->sh_info;
5827 amt *= sizeof (asection *);
5828 sections = (asection **) bfd_malloc (amt);
5829 if (sections == NULL && amt != 0)
252b5132
RH
5830 goto error_return;
5831
6cdc0ccc
AM
5832 isymend = isymbuf + symtab_hdr->sh_info;
5833 for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp)
252b5132
RH
5834 {
5835 asection *isec;
5836
6cdc0ccc 5837 if (isym->st_shndx == SHN_UNDEF)
252b5132 5838 isec = bfd_und_section_ptr;
6cdc0ccc 5839 else if (isym->st_shndx == SHN_ABS)
252b5132 5840 isec = bfd_abs_section_ptr;
6cdc0ccc 5841 else if (isym->st_shndx == SHN_COMMON)
252b5132
RH
5842 isec = bfd_com_section_ptr;
5843 else
6cdc0ccc 5844 isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
252b5132
RH
5845
5846 *secpp = isec;
5847 }
5848
5849 if (! sh_elf_relocate_section (output_bfd, link_info, input_bfd,
5850 input_section, data, internal_relocs,
6cdc0ccc 5851 isymbuf, sections))
252b5132
RH
5852 goto error_return;
5853
5854 if (sections != NULL)
5855 free (sections);
6cdc0ccc
AM
5856 if (isymbuf != NULL
5857 && symtab_hdr->contents != (unsigned char *) isymbuf)
5858 free (isymbuf);
5859 if (elf_section_data (input_section)->relocs != internal_relocs)
252b5132 5860 free (internal_relocs);
252b5132
RH
5861 }
5862
5863 return data;
5864
5865 error_return:
252b5132
RH
5866 if (sections != NULL)
5867 free (sections);
6cdc0ccc
AM
5868 if (isymbuf != NULL
5869 && symtab_hdr->contents != (unsigned char *) isymbuf)
5870 free (isymbuf);
5871 if (internal_relocs != NULL
5872 && elf_section_data (input_section)->relocs != internal_relocs)
5873 free (internal_relocs);
252b5132
RH
5874 return NULL;
5875}
917583ad 5876
3376eaf5
KK
5877/* Return the base VMA address which should be subtracted from real addresses
5878 when resolving @dtpoff relocation.
5879 This is PT_TLS segment p_vaddr. */
5880
5881static bfd_vma
5882dtpoff_base (info)
5883 struct bfd_link_info *info;
5884{
5885 /* If tls_segment is NULL, we should have signalled an error already. */
5886 if (elf_hash_table (info)->tls_segment == NULL)
5887 return 0;
5888 return elf_hash_table (info)->tls_segment->start;
5889}
5890
252b5132 5891static asection *
1e2f5b6e
AM
5892sh_elf_gc_mark_hook (sec, info, rel, h, sym)
5893 asection *sec;
435b1e90
KH
5894 struct bfd_link_info *info ATTRIBUTE_UNUSED;
5895 Elf_Internal_Rela *rel;
5896 struct elf_link_hash_entry *h;
5897 Elf_Internal_Sym *sym;
252b5132
RH
5898{
5899 if (h != NULL)
5900 {
5901 switch (ELF32_R_TYPE (rel->r_info))
435b1e90
KH
5902 {
5903 case R_SH_GNU_VTINHERIT:
5904 case R_SH_GNU_VTENTRY:
5905 break;
252b5132 5906
435b1e90 5907 default:
4972a8e9
SC
5908#ifdef INCLUDE_SHMEDIA
5909 while (h->root.type == bfd_link_hash_indirect
5910 && h->root.u.i.link)
5911 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5912#endif
435b1e90
KH
5913 switch (h->root.type)
5914 {
5915 case bfd_link_hash_defined:
5916 case bfd_link_hash_defweak:
5917 return h->root.u.def.section;
252b5132 5918
435b1e90
KH
5919 case bfd_link_hash_common:
5920 return h->root.u.c.p->section;
e049a0de 5921
435b1e90
KH
5922 default:
5923 break;
5924 }
5925 }
5926 }
5927 else
1e2f5b6e 5928 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
9ad5cbcf 5929
252b5132
RH
5930 return NULL;
5931}
5932
37c644f2
AO
5933/* Update the got entry reference counts for the section being removed. */
5934
b34976b6 5935static bfd_boolean
252b5132 5936sh_elf_gc_sweep_hook (abfd, info, sec, relocs)
067653c5
AM
5937 bfd *abfd;
5938 struct bfd_link_info *info;
5939 asection *sec;
5940 const Elf_Internal_Rela *relocs;
252b5132 5941{
067653c5
AM
5942 Elf_Internal_Shdr *symtab_hdr;
5943 struct elf_link_hash_entry **sym_hashes;
5944 bfd_signed_vma *local_got_refcounts;
5945 const Elf_Internal_Rela *rel, *relend;
067653c5
AM
5946
5947 elf_section_data (sec)->local_dynrel = NULL;
5948
5949 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
5950 sym_hashes = elf_sym_hashes (abfd);
5951 local_got_refcounts = elf_local_got_refcounts (abfd);
5952
5953 relend = relocs + sec->reloc_count;
5954 for (rel = relocs; rel < relend; rel++)
396a6083 5955 {
26e41594
AM
5956 unsigned long r_symndx;
5957 unsigned int r_type;
5958 struct elf_link_hash_entry *h = NULL;
396a6083
SC
5959#ifdef INCLUDE_SHMEDIA
5960 int seen_stt_datalabel = 0;
5961#endif
3376eaf5 5962
396a6083 5963 r_symndx = ELF32_R_SYM (rel->r_info);
26e41594 5964 if (r_symndx >= symtab_hdr->sh_info)
396a6083 5965 {
26e41594
AM
5966 struct elf_sh_link_hash_entry *eh;
5967 struct elf_sh_dyn_relocs **pp;
5968 struct elf_sh_dyn_relocs *p;
5969
396a6083 5970 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
067653c5 5971#ifdef INCLUDE_SHMEDIA
396a6083
SC
5972 while (h->root.type == bfd_link_hash_indirect
5973 || h->root.type == bfd_link_hash_warning)
5974 {
5975 seen_stt_datalabel |= h->type == STT_DATALABEL;
5976 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5977 }
067653c5 5978#endif
26e41594
AM
5979 eh = (struct elf_sh_link_hash_entry *) h;
5980 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
5981 if (p->sec == sec)
5982 {
5983 /* Everything must go for SEC. */
5984 *pp = p->next;
5985 break;
5986 }
396a6083 5987 }
067653c5 5988
26e41594
AM
5989 r_type = ELF32_R_TYPE (rel->r_info);
5990 switch (sh_elf_optimized_tls_reloc (info, r_type, h != NULL))
396a6083
SC
5991 {
5992 case R_SH_TLS_LD_32:
5993 if (sh_elf_hash_table (info)->tls_ldm_got.refcount > 0)
5994 sh_elf_hash_table (info)->tls_ldm_got.refcount -= 1;
5995 break;
5996
5997 case R_SH_GOT32:
5998 case R_SH_GOTOFF:
5999 case R_SH_GOTPC:
6000#ifdef INCLUDE_SHMEDIA
6001 case R_SH_GOT_LOW16:
6002 case R_SH_GOT_MEDLOW16:
6003 case R_SH_GOT_MEDHI16:
6004 case R_SH_GOT_HI16:
6005 case R_SH_GOT10BY4:
6006 case R_SH_GOT10BY8:
6007 case R_SH_GOTOFF_LOW16:
6008 case R_SH_GOTOFF_MEDLOW16:
6009 case R_SH_GOTOFF_MEDHI16:
6010 case R_SH_GOTOFF_HI16:
6011 case R_SH_GOTPC_LOW16:
6012 case R_SH_GOTPC_MEDLOW16:
6013 case R_SH_GOTPC_MEDHI16:
6014 case R_SH_GOTPC_HI16:
6015#endif
6016 case R_SH_TLS_GD_32:
6017 case R_SH_TLS_IE_32:
6018 if (h != NULL)
6019 {
6020#ifdef INCLUDE_SHMEDIA
6021 if (seen_stt_datalabel)
6022 {
26e41594
AM
6023 struct elf_sh_link_hash_entry *eh;
6024 eh = (struct elf_sh_link_hash_entry *) h;
396a6083
SC
6025 if (eh->datalabel_got.refcount > 0)
6026 eh->datalabel_got.refcount -= 1;
6027 }
6028 else
6029#endif
6030 if (h->got.refcount > 0)
6031 h->got.refcount -= 1;
6032 }
6033 else if (local_got_refcounts != NULL)
6034 {
6035#ifdef INCLUDE_SHMEDIA
6036 if (rel->r_addend & 1)
6037 {
6038 if (local_got_refcounts[symtab_hdr->sh_info + r_symndx] > 0)
6039 local_got_refcounts[symtab_hdr->sh_info + r_symndx] -= 1;
6040 }
6041 else
6042#endif
6043 if (local_got_refcounts[r_symndx] > 0)
6044 local_got_refcounts[r_symndx] -= 1;
6045 }
6046 break;
6047
6048 case R_SH_DIR32:
6049 case R_SH_REL32:
26e41594
AM
6050 if (info->shared)
6051 break;
6052 /* Fall thru */
396a6083
SC
6053
6054 case R_SH_PLT32:
6055#ifdef INCLUDE_SHMEDIA
6056 case R_SH_PLT_LOW16:
6057 case R_SH_PLT_MEDLOW16:
6058 case R_SH_PLT_MEDHI16:
6059 case R_SH_PLT_HI16:
6060#endif
6061 if (h != NULL)
6062 {
6063 if (h->plt.refcount > 0)
6064 h->plt.refcount -= 1;
6065 }
6066 break;
067653c5 6067
396a6083
SC
6068 case R_SH_GOTPLT32:
6069#ifdef INCLUDE_SHMEDIA
6070 case R_SH_GOTPLT_LOW16:
6071 case R_SH_GOTPLT_MEDLOW16:
6072 case R_SH_GOTPLT_MEDHI16:
6073 case R_SH_GOTPLT_HI16:
6074 case R_SH_GOTPLT10BY4:
6075 case R_SH_GOTPLT10BY8:
6076#endif
6077 if (h != NULL)
6078 {
26e41594
AM
6079 struct elf_sh_link_hash_entry *eh;
6080 eh = (struct elf_sh_link_hash_entry *) h;
396a6083 6081 if (eh->gotplt_refcount > 0)
067653c5 6082 {
396a6083
SC
6083 eh->gotplt_refcount -= 1;
6084 if (h->plt.refcount > 0)
6085 h->plt.refcount -= 1;
067653c5 6086 }
067653c5 6087#ifdef INCLUDE_SHMEDIA
396a6083
SC
6088 else if (seen_stt_datalabel)
6089 {
6090 if (eh->datalabel_got.refcount > 0)
6091 eh->datalabel_got.refcount -= 1;
6092 }
067653c5 6093#endif
396a6083
SC
6094 else if (h->got.refcount > 0)
6095 h->got.refcount -= 1;
6096 }
6097 else if (local_got_refcounts != NULL)
6098 {
067653c5 6099#ifdef INCLUDE_SHMEDIA
396a6083
SC
6100 if (rel->r_addend & 1)
6101 {
6102 if (local_got_refcounts[symtab_hdr->sh_info + r_symndx] > 0)
6103 local_got_refcounts[symtab_hdr->sh_info + r_symndx] -= 1;
6104 }
6105 else
067653c5 6106#endif
396a6083
SC
6107 if (local_got_refcounts[r_symndx] > 0)
6108 local_got_refcounts[r_symndx] -= 1;
6109 }
6110 break;
067653c5 6111
396a6083
SC
6112 default:
6113 break;
6114 }
6115 }
067653c5 6116
b34976b6 6117 return TRUE;
252b5132
RH
6118}
6119
067653c5
AM
6120/* Copy the extra info we tack onto an elf_link_hash_entry. */
6121
6122static void
6123sh_elf_copy_indirect_symbol (bed, dir, ind)
6124 struct elf_backend_data *bed;
6125 struct elf_link_hash_entry *dir, *ind;
6126{
6127 struct elf_sh_link_hash_entry *edir, *eind;
396a6083
SC
6128#ifdef INCLUDE_SHMEDIA
6129 bfd_signed_vma tmp;
6130#endif
067653c5
AM
6131
6132 edir = (struct elf_sh_link_hash_entry *) dir;
6133 eind = (struct elf_sh_link_hash_entry *) ind;
6134
6135 if (eind->dyn_relocs != NULL)
6136 {
6137 if (edir->dyn_relocs != NULL)
6138 {
6139 struct elf_sh_dyn_relocs **pp;
6140 struct elf_sh_dyn_relocs *p;
6141
6142 BFD_ASSERT (ind->root.type != bfd_link_hash_indirect);
6143
6144 /* Add reloc counts against the weak sym to the strong sym
6145 list. Merge any entries against the same section. */
6146 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
6147 {
6148 struct elf_sh_dyn_relocs *q;
6149
6150 for (q = edir->dyn_relocs; q != NULL; q = q->next)
6151 if (q->sec == p->sec)
6152 {
6153 q->pc_count += p->pc_count;
6154 q->count += p->count;
6155 *pp = p->next;
6156 break;
6157 }
6158 if (q == NULL)
6159 pp = &p->next;
6160 }
6161 *pp = edir->dyn_relocs;
6162 }
6163
6164 edir->dyn_relocs = eind->dyn_relocs;
6165 eind->dyn_relocs = NULL;
6166 }
4989d792
SC
6167 edir->gotplt_refcount = eind->gotplt_refcount;
6168 eind->gotplt_refcount = 0;
396a6083
SC
6169#ifdef INCLUDE_SHMEDIA
6170 tmp = edir->datalabel_got.refcount;
6171 if (tmp < 1)
6172 {
6173 edir->datalabel_got.refcount = eind->datalabel_got.refcount;
6174 eind->datalabel_got.refcount = tmp;
6175 }
6176 else
6177 BFD_ASSERT (eind->datalabel_got.refcount < 1);
6178#endif
067653c5 6179
3376eaf5
KK
6180 if (ind->root.type == bfd_link_hash_indirect
6181 && dir->got.refcount <= 0)
6182 {
6183 edir->tls_type = eind->tls_type;
6184 eind->tls_type = GOT_UNKNOWN;
6185 }
6186
067653c5
AM
6187 _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
6188}
6189
3376eaf5
KK
6190static int
6191sh_elf_optimized_tls_reloc (info, r_type, is_local)
6192 struct bfd_link_info *info;
6193 int r_type;
6194 int is_local;
6195{
6196 if (info->shared)
6197 return r_type;
6198
6199 switch (r_type)
6200 {
6201 case R_SH_TLS_GD_32:
6202 case R_SH_TLS_IE_32:
6203 if (is_local)
6204 return R_SH_TLS_LE_32;
6205 return R_SH_TLS_IE_32;
6206 case R_SH_TLS_LD_32:
6207 return R_SH_TLS_LE_32;
6208 }
6209
6210 return r_type;
6211}
6212
252b5132
RH
6213/* Look through the relocs for a section during the first phase.
6214 Since we don't do .gots or .plts, we just need to consider the
6215 virtual table relocs for gc. */
435b1e90 6216
b34976b6 6217static bfd_boolean
252b5132
RH
6218sh_elf_check_relocs (abfd, info, sec, relocs)
6219 bfd *abfd;
6220 struct bfd_link_info *info;
6221 asection *sec;
6222 const Elf_Internal_Rela *relocs;
6223{
6224 Elf_Internal_Shdr *symtab_hdr;
6225 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
067653c5 6226 struct elf_sh_link_hash_table *htab;
252b5132
RH
6227 const Elf_Internal_Rela *rel;
6228 const Elf_Internal_Rela *rel_end;
37c644f2
AO
6229 bfd *dynobj;
6230 bfd_vma *local_got_offsets;
6231 asection *sgot;
6232 asection *srelgot;
6233 asection *sreloc;
3376eaf5
KK
6234 unsigned int r_type;
6235 int tls_type, old_tls_type;
435b1e90 6236
37c644f2
AO
6237 sgot = NULL;
6238 srelgot = NULL;
6239 sreloc = NULL;
6240
252b5132 6241 if (info->relocateable)
b34976b6 6242 return TRUE;
435b1e90 6243
252b5132
RH
6244 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
6245 sym_hashes = elf_sym_hashes (abfd);
435b1e90 6246 sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof (Elf32_External_Sym);
252b5132
RH
6247 if (!elf_bad_symtab (abfd))
6248 sym_hashes_end -= symtab_hdr->sh_info;
435b1e90 6249
067653c5
AM
6250 htab = sh_elf_hash_table (info);
6251 dynobj = htab->root.dynobj;
37c644f2
AO
6252 local_got_offsets = elf_local_got_offsets (abfd);
6253
252b5132
RH
6254 rel_end = relocs + sec->reloc_count;
6255 for (rel = relocs; rel < rel_end; rel++)
6256 {
6257 struct elf_link_hash_entry *h;
6258 unsigned long r_symndx;
396a6083
SC
6259#ifdef INCLUDE_SHMEDIA
6260 int seen_stt_datalabel = 0;
6261#endif
435b1e90 6262
252b5132 6263 r_symndx = ELF32_R_SYM (rel->r_info);
3376eaf5
KK
6264 r_type = ELF32_R_TYPE (rel->r_info);
6265
252b5132 6266 if (r_symndx < symtab_hdr->sh_info)
435b1e90 6267 h = NULL;
252b5132 6268 else
396a6083
SC
6269 {
6270 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6271#ifdef INCLUDE_SHMEDIA
6272 while (h->root.type == bfd_link_hash_indirect
6273 || h->root.type == bfd_link_hash_warning)
6274 {
6275 seen_stt_datalabel |= h->type == STT_DATALABEL;
6276 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6277 }
6278#endif
6279 }
435b1e90 6280
3376eaf5
KK
6281 r_type = sh_elf_optimized_tls_reloc (info, r_type, h == NULL);
6282 if (! info->shared
6283 && r_type == R_SH_TLS_IE_32
6284 && h != NULL
6285 && h->root.type != bfd_link_hash_undefined
6286 && h->root.type != bfd_link_hash_undefweak
6287 && (h->dynindx == -1
6288 || (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
6289 r_type = R_SH_TLS_LE_32;
6290
37c644f2 6291 /* Some relocs require a global offset table. */
067653c5 6292 if (htab->sgot == NULL)
37c644f2 6293 {
3376eaf5 6294 switch (r_type)
37c644f2 6295 {
fbca6ad9 6296 case R_SH_GOTPLT32:
37c644f2
AO
6297 case R_SH_GOT32:
6298 case R_SH_GOTOFF:
6299 case R_SH_GOTPC:
fbca6ad9
AO
6300#ifdef INCLUDE_SHMEDIA
6301 case R_SH_GOTPLT_LOW16:
6302 case R_SH_GOTPLT_MEDLOW16:
6303 case R_SH_GOTPLT_MEDHI16:
6304 case R_SH_GOTPLT_HI16:
6305 case R_SH_GOTPLT10BY4:
6306 case R_SH_GOTPLT10BY8:
6307 case R_SH_GOT_LOW16:
6308 case R_SH_GOT_MEDLOW16:
6309 case R_SH_GOT_MEDHI16:
6310 case R_SH_GOT_HI16:
6311 case R_SH_GOT10BY4:
6312 case R_SH_GOT10BY8:
6313 case R_SH_GOTOFF_LOW16:
6314 case R_SH_GOTOFF_MEDLOW16:
6315 case R_SH_GOTOFF_MEDHI16:
6316 case R_SH_GOTOFF_HI16:
6317 case R_SH_GOTPC_LOW16:
6318 case R_SH_GOTPC_MEDLOW16:
6319 case R_SH_GOTPC_MEDHI16:
6320 case R_SH_GOTPC_HI16:
6321#endif
3376eaf5
KK
6322 case R_SH_TLS_GD_32:
6323 case R_SH_TLS_LD_32:
6324 case R_SH_TLS_IE_32:
067653c5
AM
6325 if (dynobj == NULL)
6326 htab->root.dynobj = dynobj = abfd;
6327 if (! create_got_section (dynobj, info))
b34976b6 6328 return FALSE;
37c644f2
AO
6329 break;
6330
6331 default:
6332 break;
6333 }
6334 }
6335
3376eaf5 6336 switch (r_type)
067653c5
AM
6337 {
6338 /* This relocation describes the C++ object vtable hierarchy.
6339 Reconstruct it for later use during GC. */
435b1e90
KH
6340 case R_SH_GNU_VTINHERIT:
6341 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
b34976b6 6342 return FALSE;
435b1e90
KH
6343 break;
6344
067653c5
AM
6345 /* This relocation describes which C++ vtable entries are actually
6346 used. Record for later use during GC. */
435b1e90
KH
6347 case R_SH_GNU_VTENTRY:
6348 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
b34976b6 6349 return FALSE;
435b1e90 6350 break;
37c644f2 6351
fbca6ad9 6352 force_got:
3376eaf5
KK
6353 case R_SH_TLS_IE_32:
6354 if (info->shared)
6355 info->flags |= DF_STATIC_TLS;
6356
6357 /* FALLTHROUGH */
6358 case R_SH_TLS_GD_32:
37c644f2 6359 case R_SH_GOT32:
fbca6ad9
AO
6360#ifdef INCLUDE_SHMEDIA
6361 case R_SH_GOT_LOW16:
6362 case R_SH_GOT_MEDLOW16:
6363 case R_SH_GOT_MEDHI16:
6364 case R_SH_GOT_HI16:
6365 case R_SH_GOT10BY4:
6366 case R_SH_GOT10BY8:
6367#endif
3376eaf5
KK
6368 switch (r_type)
6369 {
6370 default:
6371 tls_type = GOT_NORMAL;
6372 break;
6373 case R_SH_TLS_GD_32:
6374 tls_type = GOT_TLS_GD;
6375 break;
6376 case R_SH_TLS_IE_32:
6377 tls_type = GOT_TLS_IE;
6378 break;
6379 }
6380
37c644f2 6381 if (h != NULL)
3376eaf5 6382 {
396a6083
SC
6383#ifdef INCLUDE_SHMEDIA
6384 if (seen_stt_datalabel)
6385 {
b34976b6
AM
6386 struct elf_sh_link_hash_entry *eh
6387 = (struct elf_sh_link_hash_entry *) h;
396a6083
SC
6388
6389 eh->datalabel_got.refcount += 1;
6390 }
6391 else
6392#endif
6393 h->got.refcount += 1;
3376eaf5
KK
6394 old_tls_type = sh_elf_hash_entry (h)->tls_type;
6395 }
37c644f2
AO
6396 else
6397 {
067653c5
AM
6398 bfd_signed_vma *local_got_refcounts;
6399
435b1e90 6400 /* This is a global offset table entry for a local
067653c5
AM
6401 symbol. */
6402 local_got_refcounts = elf_local_got_refcounts (abfd);
6403 if (local_got_refcounts == NULL)
37c644f2 6404 {
dc810e39 6405 bfd_size_type size;
37c644f2 6406
dc810e39 6407 size = symtab_hdr->sh_info;
067653c5 6408 size *= sizeof (bfd_signed_vma);
fbca6ad9
AO
6409#ifdef INCLUDE_SHMEDIA
6410 /* Reserve space for both the datalabel and
6411 codelabel local GOT offsets. */
6412 size *= 2;
6413#endif
3376eaf5 6414 size += symtab_hdr->sh_info;
067653c5
AM
6415 local_got_refcounts = ((bfd_signed_vma *)
6416 bfd_zalloc (abfd, size));
6417 if (local_got_refcounts == NULL)
b34976b6 6418 return FALSE;
067653c5 6419 elf_local_got_refcounts (abfd) = local_got_refcounts;
3376eaf5
KK
6420#ifdef INCLUDE_SHMEDIA
6421 /* Take care of both the datalabel and codelabel local
6422 GOT offsets. */
6423 sh_elf_local_got_tls_type (abfd)
6424 = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
6425#else
6426 sh_elf_local_got_tls_type (abfd)
6427 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
6428#endif
37c644f2 6429 }
396a6083
SC
6430#ifdef INCLUDE_SHMEDIA
6431 if (rel->r_addend & 1)
6432 local_got_refcounts[symtab_hdr->sh_info + r_symndx] += 1;
6433 else
6434#endif
6435 local_got_refcounts[r_symndx] += 1;
3376eaf5
KK
6436 old_tls_type = sh_elf_local_got_tls_type (abfd) [r_symndx];
6437 }
6438
6439 /* If a TLS symbol is accessed using IE at least once,
6440 there is no point to use dynamic model for it. */
6441 if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
6442 && (old_tls_type != GOT_TLS_GD || tls_type != GOT_TLS_IE))
6443 {
6444 if (old_tls_type == GOT_TLS_IE && tls_type == GOT_TLS_GD)
6445 tls_type = GOT_TLS_IE;
6446 else
6447 {
6448 (*_bfd_error_handler)
6449 (_("%s: `%s' accessed both as normal and thread local symbol"),
6450 bfd_archive_filename (abfd), h->root.root.string);
b34976b6 6451 return FALSE;
3376eaf5
KK
6452 }
6453 }
6454
6455 if (old_tls_type != tls_type)
6456 {
6457 if (h != NULL)
6458 sh_elf_hash_entry (h)->tls_type = tls_type;
6459 else
6460 sh_elf_local_got_tls_type (abfd) [r_symndx] = tls_type;
37c644f2 6461 }
3376eaf5
KK
6462
6463 break;
6464
6465 case R_SH_TLS_LD_32:
6466 sh_elf_hash_table(info)->tls_ldm_got.refcount += 1;
37c644f2
AO
6467 break;
6468
fbca6ad9
AO
6469 case R_SH_GOTPLT32:
6470#ifdef INCLUDE_SHMEDIA
6471 case R_SH_GOTPLT_LOW16:
6472 case R_SH_GOTPLT_MEDLOW16:
6473 case R_SH_GOTPLT_MEDHI16:
6474 case R_SH_GOTPLT_HI16:
6475 case R_SH_GOTPLT10BY4:
6476 case R_SH_GOTPLT10BY8:
6477#endif
6478 /* If this is a local symbol, we resolve it directly without
6479 creating a procedure linkage table entry. */
6480
6481 if (h == NULL
067653c5 6482 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)
fbca6ad9
AO
6483 || ! info->shared
6484 || info->symbolic
067653c5 6485 || h->dynindx == -1)
fbca6ad9
AO
6486 goto force_got;
6487
fbca6ad9 6488 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
067653c5 6489 h->plt.refcount += 1;
4989d792 6490 ((struct elf_sh_link_hash_entry *) h)->gotplt_refcount += 1;
fbca6ad9
AO
6491
6492 break;
6493
37c644f2 6494 case R_SH_PLT32:
fbca6ad9
AO
6495#ifdef INCLUDE_SHMEDIA
6496 case R_SH_PLT_LOW16:
6497 case R_SH_PLT_MEDLOW16:
6498 case R_SH_PLT_MEDHI16:
6499 case R_SH_PLT_HI16:
6500#endif
37c644f2
AO
6501 /* This symbol requires a procedure linkage table entry. We
6502 actually build the entry in adjust_dynamic_symbol,
6503 because this might be a case of linking PIC code which is
6504 never referenced by a dynamic object, in which case we
6505 don't need to generate a procedure linkage table entry
6506 after all. */
6507
6508 /* If this is a local symbol, we resolve it directly without
6509 creating a procedure linkage table entry. */
6510 if (h == NULL)
6511 continue;
6512
067653c5 6513 if (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)
37c644f2
AO
6514 break;
6515
6516 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
067653c5 6517 h->plt.refcount += 1;
37c644f2
AO
6518 break;
6519
6520 case R_SH_DIR32:
6521 case R_SH_REL32:
067653c5
AM
6522 if (h != NULL && ! info->shared)
6523 {
6524 h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
6525 h->plt.refcount += 1;
6526 }
37c644f2
AO
6527
6528 /* If we are creating a shared library, and this is a reloc
6529 against a global symbol, or a non PC relative reloc
6530 against a local symbol, then we need to copy the reloc
6531 into the shared library. However, if we are linking with
6532 -Bsymbolic, we do not need to copy a reloc against a
6533 global symbol which is defined in an object we are
6534 including in the link (i.e., DEF_REGULAR is set). At
6535 this point we have not seen all the input files, so it is
6536 possible that DEF_REGULAR is not set now but will be set
6537 later (it is never cleared). We account for that
6538 possibility below by storing information in the
067653c5
AM
6539 dyn_relocs field of the hash table entry. A similar
6540 situation occurs when creating shared libraries and symbol
6541 visibility changes render the symbol local.
6542
6543 If on the other hand, we are creating an executable, we
6544 may need to keep relocations for symbols satisfied by a
6545 dynamic library if we manage to avoid copy relocs for the
6546 symbol. */
6547 if ((info->shared
6548 && (sec->flags & SEC_ALLOC) != 0
3376eaf5 6549 && (r_type != R_SH_REL32
067653c5
AM
6550 || (h != NULL
6551 && (! info->symbolic
6552 || h->root.type == bfd_link_hash_defweak
6553 || (h->elf_link_hash_flags
6554 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
6555 || (! info->shared
6556 && (sec->flags & SEC_ALLOC) != 0
6557 && h != NULL
6558 && (h->root.type == bfd_link_hash_defweak
6559 || (h->elf_link_hash_flags
6560 & ELF_LINK_HASH_DEF_REGULAR) == 0)))
37c644f2 6561 {
067653c5
AM
6562 struct elf_sh_dyn_relocs *p;
6563 struct elf_sh_dyn_relocs **head;
6564
6565 if (dynobj == NULL)
6566 htab->root.dynobj = dynobj = abfd;
6567
37c644f2
AO
6568 /* When creating a shared object, we must copy these
6569 reloc types into the output file. We create a reloc
6570 section in dynobj and make room for this reloc. */
6571 if (sreloc == NULL)
6572 {
6573 const char *name;
6574
6575 name = (bfd_elf_string_from_elf_section
6576 (abfd,
6577 elf_elfheader (abfd)->e_shstrndx,
6578 elf_section_data (sec)->rel_hdr.sh_name));
6579 if (name == NULL)
b34976b6 6580 return FALSE;
37c644f2
AO
6581
6582 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
6583 && strcmp (bfd_get_section_name (abfd, sec),
6584 name + 5) == 0);
6585
6586 sreloc = bfd_get_section_by_name (dynobj, name);
6587 if (sreloc == NULL)
6588 {
6589 flagword flags;
6590
6591 sreloc = bfd_make_section (dynobj, name);
6592 flags = (SEC_HAS_CONTENTS | SEC_READONLY
6593 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
6594 if ((sec->flags & SEC_ALLOC) != 0)
6595 flags |= SEC_ALLOC | SEC_LOAD;
6596 if (sreloc == NULL
6597 || ! bfd_set_section_flags (dynobj, sreloc, flags)
6598 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
b34976b6 6599 return FALSE;
37c644f2 6600 }
99e4ae17
AJ
6601 if (sec->flags & SEC_READONLY)
6602 info->flags |= DF_TEXTREL;
067653c5 6603 elf_section_data (sec)->sreloc = sreloc;
37c644f2
AO
6604 }
6605
067653c5
AM
6606 /* If this is a global symbol, we count the number of
6607 relocations we need for this symbol. */
6608 if (h != NULL)
6609 head = &((struct elf_sh_link_hash_entry *) h)->dyn_relocs;
6610 else
37c644f2 6611 {
067653c5 6612 asection *s;
37c644f2 6613
067653c5
AM
6614 /* Track dynamic relocs needed for local syms too. */
6615 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
6616 sec, r_symndx);
6617 if (s == NULL)
b34976b6 6618 return FALSE;
37c644f2 6619
067653c5
AM
6620 head = ((struct elf_sh_dyn_relocs **)
6621 &elf_section_data (s)->local_dynrel);
6622 }
37c644f2 6623
067653c5
AM
6624 p = *head;
6625 if (p == NULL || p->sec != sec)
6626 {
6627 bfd_size_type amt = sizeof (*p);
6628 p = ((struct elf_sh_dyn_relocs *) bfd_alloc (dynobj, amt));
37c644f2 6629 if (p == NULL)
b34976b6 6630 return FALSE;
067653c5
AM
6631 p->next = *head;
6632 *head = p;
6633 p->sec = sec;
6634 p->count = 0;
6635 p->pc_count = 0;
c95b8a7a 6636 p->tls_tpoff32 = FALSE;
37c644f2 6637 }
067653c5
AM
6638
6639 p->count += 1;
3376eaf5 6640 if (r_type == R_SH_REL32)
067653c5 6641 p->pc_count += 1;
37c644f2
AO
6642 }
6643
6644 break;
3376eaf5
KK
6645
6646 case R_SH_TLS_LE_32:
6647 if (info->shared)
6648 {
6649 (*_bfd_error_handler) (_("%s: TLS local exec code cannot be linked into shared objects"),
6650 bfd_archive_filename (abfd));
b34976b6 6651 return FALSE;
3376eaf5
KK
6652 }
6653
6654 if (ELF32_R_TYPE (rel->r_info) == R_SH_TLS_LD_32)
6655 break;
6656
6657 /* FALLTHROUGH */
6658 case R_SH_TLS_LDO_32:
6659 /* We make a R_SH_TLS_TPOFF32 relocation. Count it as a
6660 copy relocation. */
6661 if (! info->shared)
6662 {
6663 struct elf_sh_dyn_relocs *p;
6664 struct elf_sh_dyn_relocs **head;
6665
6666 if (dynobj == NULL)
6667 htab->root.dynobj = dynobj = abfd;
6668
6669 if (sreloc == NULL)
6670 {
6671 const char *name;
6672
6673 name = (bfd_elf_string_from_elf_section
6674 (abfd,
6675 elf_elfheader (abfd)->e_shstrndx,
6676 elf_section_data (sec)->rel_hdr.sh_name));
6677 if (name == NULL)
b34976b6 6678 return FALSE;
3376eaf5
KK
6679
6680 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
6681 && strcmp (bfd_get_section_name (abfd, sec),
6682 name + 5) == 0);
6683
6684 sreloc = bfd_get_section_by_name (dynobj, name);
6685 if (sreloc == NULL)
6686 {
6687 flagword flags;
6688
6689 sreloc = bfd_make_section (dynobj, name);
6690 flags = (SEC_HAS_CONTENTS | SEC_READONLY
6691 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
6692 if ((sec->flags & SEC_ALLOC) != 0)
6693 flags |= SEC_ALLOC | SEC_LOAD;
6694 if (sreloc == NULL
6695 || ! bfd_set_section_flags (dynobj, sreloc, flags)
6696 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
b34976b6 6697 return FALSE;
3376eaf5
KK
6698 }
6699 elf_section_data (sec)->sreloc = sreloc;
6700 if (sec->flags & SEC_READONLY)
6701 info->flags |= DF_TEXTREL;
6702 }
6703
6704 /* If this is a global symbol, we count the number of
6705 relocations we need for this symbol. */
6706 if (h != NULL)
6707 head = &((struct elf_sh_link_hash_entry *) h)->dyn_relocs;
6708 else
6709 {
6710 asection *s;
6711
6712 /* Track dynamic relocs needed for local syms too. */
6713 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
6714 sec, r_symndx);
6715 if (s == NULL)
b34976b6 6716 return FALSE;
3376eaf5
KK
6717
6718 head = ((struct elf_sh_dyn_relocs **)
6719 &elf_section_data (s)->local_dynrel);
6720 }
6721
6722 p = *head;
6723 if (p == NULL || p->sec != sec)
6724 {
6725 bfd_size_type amt = sizeof (*p);
6726 p = ((struct elf_sh_dyn_relocs *) bfd_alloc (dynobj, amt));
6727 if (p == NULL)
b34976b6 6728 return FALSE;
3376eaf5
KK
6729 p->next = *head;
6730 *head = p;
6731 p->sec = sec;
6732 p->count = 0;
6733 p->pc_count = 0;
c95b8a7a 6734 p->tls_tpoff32 = FALSE;
3376eaf5
KK
6735 }
6736
6737 p->count += 1;
c95b8a7a 6738 p->tls_tpoff32 = TRUE;
3376eaf5
KK
6739 }
6740 break;
6741
6742 default:
6743 break;
435b1e90 6744 }
252b5132 6745 }
435b1e90 6746
b34976b6 6747 return TRUE;
252b5132
RH
6748}
6749
fbca6ad9 6750#ifndef sh_elf_set_mach_from_flags
b34976b6 6751static bfd_boolean
d4845d57 6752sh_elf_set_mach_from_flags (abfd)
435b1e90 6753 bfd *abfd;
d4845d57
JR
6754{
6755 flagword flags = elf_elfheader (abfd)->e_flags;
6756
86033394 6757 switch (flags & EF_SH_MACH_MASK)
d4845d57
JR
6758 {
6759 case EF_SH1:
6760 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh);
6761 break;
6762 case EF_SH2:
6763 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh2);
6764 break;
5177500f
NC
6765 case EF_SH2E:
6766 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh2e);
6767 break;
d4845d57
JR
6768 case EF_SH_DSP:
6769 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh_dsp);
6770 break;
6771 case EF_SH3:
6772 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh3);
6773 break;
6774 case EF_SH3_DSP:
6775 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh3_dsp);
6776 break;
6777 case EF_SH3E:
6778 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh3e);
6779 break;
6780 case EF_SH_UNKNOWN:
6781 case EF_SH4:
6782 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh4);
6783 break;
6784 default:
b34976b6 6785 return FALSE;
d4845d57 6786 }
b34976b6 6787 return TRUE;
d4845d57 6788}
fbca6ad9 6789#endif /* not sh_elf_set_mach_from_flags */
d4845d57 6790
fbca6ad9 6791#ifndef sh_elf_set_private_flags
435b1e90
KH
6792/* Function to keep SH specific file flags. */
6793
b34976b6 6794static bfd_boolean
d4845d57 6795sh_elf_set_private_flags (abfd, flags)
435b1e90 6796 bfd *abfd;
d4845d57
JR
6797 flagword flags;
6798{
6799 BFD_ASSERT (! elf_flags_init (abfd)
6800 || elf_elfheader (abfd)->e_flags == flags);
6801
6802 elf_elfheader (abfd)->e_flags = flags;
b34976b6 6803 elf_flags_init (abfd) = TRUE;
d4845d57
JR
6804 return sh_elf_set_mach_from_flags (abfd);
6805}
fbca6ad9 6806#endif /* not sh_elf_set_private_flags */
d4845d57 6807
fbca6ad9 6808#ifndef sh_elf_copy_private_data
d4845d57 6809/* Copy backend specific data from one object module to another */
435b1e90 6810
b34976b6 6811static bfd_boolean
d4845d57 6812sh_elf_copy_private_data (ibfd, obfd)
38b1a46c
NC
6813 bfd * ibfd;
6814 bfd * obfd;
d4845d57 6815{
38b1a46c 6816 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
d4845d57 6817 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
b34976b6 6818 return TRUE;
d4845d57
JR
6819
6820 return sh_elf_set_private_flags (obfd, elf_elfheader (ibfd)->e_flags);
6821}
fbca6ad9 6822#endif /* not sh_elf_copy_private_data */
d4845d57 6823
fbca6ad9 6824#ifndef sh_elf_merge_private_data
d4845d57
JR
6825/* This routine checks for linking big and little endian objects
6826 together, and for linking sh-dsp with sh3e / sh4 objects. */
6827
b34976b6 6828static bfd_boolean
d4845d57
JR
6829sh_elf_merge_private_data (ibfd, obfd)
6830 bfd *ibfd;
6831 bfd *obfd;
6832{
6833 flagword old_flags, new_flags;
6834
82e51918 6835 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
b34976b6 6836 return FALSE;
d4845d57
JR
6837
6838 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
6839 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
b34976b6 6840 return TRUE;
d4845d57
JR
6841
6842 if (! elf_flags_init (obfd))
6843 {
a39b79b9 6844 /* This happens when ld starts out with a 'blank' output file. */
b34976b6 6845 elf_flags_init (obfd) = TRUE;
a39b79b9 6846 elf_elfheader (obfd)->e_flags = EF_SH1;
d4845d57
JR
6847 }
6848 old_flags = elf_elfheader (obfd)->e_flags;
6849 new_flags = elf_elfheader (ibfd)->e_flags;
6850 if ((EF_SH_HAS_DSP (old_flags) && EF_SH_HAS_FP (new_flags))
6851 || (EF_SH_HAS_DSP (new_flags) && EF_SH_HAS_FP (old_flags)))
6852 {
6853 (*_bfd_error_handler)
6854 ("%s: uses %s instructions while previous modules use %s instructions",
8f615d07 6855 bfd_archive_filename (ibfd),
d4845d57
JR
6856 EF_SH_HAS_DSP (new_flags) ? "dsp" : "floating point",
6857 EF_SH_HAS_DSP (new_flags) ? "floating point" : "dsp");
6858 bfd_set_error (bfd_error_bad_value);
b34976b6 6859 return FALSE;
d4845d57
JR
6860 }
6861 elf_elfheader (obfd)->e_flags = EF_SH_MERGE_MACH (old_flags, new_flags);
6862
6863 return sh_elf_set_mach_from_flags (obfd);
6864}
fbca6ad9 6865#endif /* not sh_elf_merge_private_data */
d4845d57 6866
3376eaf5
KK
6867/* Override the generic function because we need to store sh_elf_obj_tdata
6868 as the specific tdata. We set also the machine architecture from flags
6869 here. */
6870
b34976b6 6871static bfd_boolean
3376eaf5
KK
6872sh_elf_object_p (abfd)
6873 bfd *abfd;
6874{
6875 struct sh_elf_obj_tdata *new_tdata;
6876 bfd_size_type amt = sizeof (struct sh_elf_obj_tdata);
6877
b34976b6
AM
6878 if (!sh_elf_set_mach_from_flags (abfd))
6879 return FALSE;
3376eaf5
KK
6880
6881 /* Allocate our special target data. */
6882 new_tdata = bfd_zalloc (abfd, amt);
6883 if (new_tdata == NULL)
b34976b6 6884 return FALSE;
3376eaf5
KK
6885 new_tdata->root = *abfd->tdata.elf_obj_data;
6886 abfd->tdata.any = new_tdata;
b34976b6 6887 return TRUE;
3376eaf5
KK
6888}
6889
37c644f2
AO
6890/* Finish up dynamic symbol handling. We set the contents of various
6891 dynamic sections here. */
6892
b34976b6 6893static bfd_boolean
37c644f2
AO
6894sh_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
6895 bfd *output_bfd;
6896 struct bfd_link_info *info;
6897 struct elf_link_hash_entry *h;
6898 Elf_Internal_Sym *sym;
6899{
067653c5 6900 struct elf_sh_link_hash_table *htab;
37c644f2
AO
6901 bfd *dynobj;
6902
067653c5
AM
6903 htab = sh_elf_hash_table (info);
6904 dynobj = htab->root.dynobj;
37c644f2
AO
6905
6906 if (h->plt.offset != (bfd_vma) -1)
6907 {
6908 asection *splt;
6909 asection *sgot;
6910 asection *srel;
6911
6912 bfd_vma plt_index;
6913 bfd_vma got_offset;
6914 Elf_Internal_Rela rel;
947216bf 6915 bfd_byte *loc;
37c644f2
AO
6916
6917 /* This symbol has an entry in the procedure linkage table. Set
6918 it up. */
6919
6920 BFD_ASSERT (h->dynindx != -1);
6921
067653c5
AM
6922 splt = htab->splt;
6923 sgot = htab->sgotplt;
6924 srel = htab->srelplt;
37c644f2
AO
6925 BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
6926
6927 /* Get the index in the procedure linkage table which
6928 corresponds to this symbol. This is the index of this symbol
6929 in all the symbols for which we are making plt entries. The
6930 first entry in the procedure linkage table is reserved. */
6931 plt_index = h->plt.offset / elf_sh_sizeof_plt (info) - 1;
6932
6933 /* Get the offset into the .got table of the entry that
6934 corresponds to this function. Each .got entry is 4 bytes.
6935 The first three are reserved. */
6936 got_offset = (plt_index + 3) * 4;
6937
fbca6ad9 6938#ifdef GOT_BIAS
c8614e8e
AM
6939 if (info->shared)
6940 got_offset -= GOT_BIAS;
fbca6ad9
AO
6941#endif
6942
37c644f2
AO
6943 /* Fill in the entry in the procedure linkage table. */
6944 if (! info->shared)
6945 {
6946 if (elf_sh_plt_entry == NULL)
6947 {
435b1e90 6948 elf_sh_plt_entry = (bfd_big_endian (output_bfd) ?
37c644f2
AO
6949 elf_sh_plt_entry_be : elf_sh_plt_entry_le);
6950 }
6951 memcpy (splt->contents + h->plt.offset, elf_sh_plt_entry,
6952 elf_sh_sizeof_plt (info));
fbca6ad9
AO
6953#ifdef INCLUDE_SHMEDIA
6954 movi_shori_putval (output_bfd,
6955 (sgot->output_section->vma
6956 + sgot->output_offset
6957 + got_offset),
6958 (splt->contents + h->plt.offset
6959 + elf_sh_plt_symbol_offset (info)));
6960
c8614e8e 6961 /* Set bottom bit because its for a branch to SHmedia */
fbca6ad9 6962 movi_shori_putval (output_bfd,
c8614e8e
AM
6963 (splt->output_section->vma + splt->output_offset)
6964 | 1,
fbca6ad9
AO
6965 (splt->contents + h->plt.offset
6966 + elf_sh_plt_plt0_offset (info)));
6967#else
37c644f2
AO
6968 bfd_put_32 (output_bfd,
6969 (sgot->output_section->vma
6970 + sgot->output_offset
6971 + got_offset),
6972 (splt->contents + h->plt.offset
6973 + elf_sh_plt_symbol_offset (info)));
6974
6975 bfd_put_32 (output_bfd,
6976 (splt->output_section->vma + splt->output_offset),
6977 (splt->contents + h->plt.offset
6978 + elf_sh_plt_plt0_offset (info)));
fbca6ad9 6979#endif
37c644f2
AO
6980 }
6981 else
6982 {
6983 if (elf_sh_pic_plt_entry == NULL)
6984 {
435b1e90 6985 elf_sh_pic_plt_entry = (bfd_big_endian (output_bfd) ?
37c644f2
AO
6986 elf_sh_pic_plt_entry_be :
6987 elf_sh_pic_plt_entry_le);
6988 }
6989 memcpy (splt->contents + h->plt.offset, elf_sh_pic_plt_entry,
6990 elf_sh_sizeof_plt (info));
fbca6ad9
AO
6991#ifdef INCLUDE_SHMEDIA
6992 movi_shori_putval (output_bfd, got_offset,
6993 (splt->contents + h->plt.offset
6994 + elf_sh_plt_symbol_offset (info)));
6995#else
37c644f2
AO
6996 bfd_put_32 (output_bfd, got_offset,
6997 (splt->contents + h->plt.offset
6998 + elf_sh_plt_symbol_offset (info)));
fbca6ad9 6999#endif
37c644f2
AO
7000 }
7001
fbca6ad9 7002#ifdef GOT_BIAS
c8614e8e
AM
7003 if (info->shared)
7004 got_offset += GOT_BIAS;
fbca6ad9
AO
7005#endif
7006
7007#ifdef INCLUDE_SHMEDIA
7008 movi_shori_putval (output_bfd,
7009 plt_index * sizeof (Elf32_External_Rela),
7010 (splt->contents + h->plt.offset
7011 + elf_sh_plt_reloc_offset (info)));
7012#else
37c644f2
AO
7013 bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
7014 (splt->contents + h->plt.offset
7015 + elf_sh_plt_reloc_offset (info)));
fbca6ad9 7016#endif
37c644f2
AO
7017
7018 /* Fill in the entry in the global offset table. */
7019 bfd_put_32 (output_bfd,
7020 (splt->output_section->vma
7021 + splt->output_offset
7022 + h->plt.offset
7023 + elf_sh_plt_temp_offset (info)),
7024 sgot->contents + got_offset);
7025
7026 /* Fill in the entry in the .rela.plt section. */
7027 rel.r_offset = (sgot->output_section->vma
7028 + sgot->output_offset
7029 + got_offset);
7030 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_JMP_SLOT);
7031 rel.r_addend = 0;
fbca6ad9
AO
7032#ifdef GOT_BIAS
7033 rel.r_addend = GOT_BIAS;
7034#endif
947216bf
AM
7035 loc = srel->contents + plt_index * sizeof (Elf32_External_Rela);
7036 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
37c644f2
AO
7037
7038 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
7039 {
7040 /* Mark the symbol as undefined, rather than as defined in
7041 the .plt section. Leave the value alone. */
7042 sym->st_shndx = SHN_UNDEF;
7043 }
7044 }
7045
3376eaf5
KK
7046 if (h->got.offset != (bfd_vma) -1
7047 && sh_elf_hash_entry (h)->tls_type != GOT_TLS_GD
7048 && sh_elf_hash_entry (h)->tls_type != GOT_TLS_IE)
37c644f2
AO
7049 {
7050 asection *sgot;
7051 asection *srel;
7052 Elf_Internal_Rela rel;
947216bf 7053 bfd_byte *loc;
37c644f2
AO
7054
7055 /* This symbol has an entry in the global offset table. Set it
7056 up. */
7057
067653c5
AM
7058 sgot = htab->sgot;
7059 srel = htab->srelgot;
37c644f2
AO
7060 BFD_ASSERT (sgot != NULL && srel != NULL);
7061
7062 rel.r_offset = (sgot->output_section->vma
7063 + sgot->output_offset
dc810e39 7064 + (h->got.offset &~ (bfd_vma) 1));
37c644f2 7065
067653c5
AM
7066 /* If this is a static link, or it is a -Bsymbolic link and the
7067 symbol is defined locally or was forced to be local because
7068 of a version file, we just want to emit a RELATIVE reloc.
37c644f2
AO
7069 The entry in the global offset table will already have been
7070 initialized in the relocate_section function. */
7071 if (info->shared
067653c5
AM
7072 && (info->symbolic
7073 || h->dynindx == -1
7074 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
37c644f2
AO
7075 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
7076 {
7077 rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
7078 rel.r_addend = (h->root.u.def.value
7079 + h->root.u.def.section->output_section->vma
7080 + h->root.u.def.section->output_offset);
7081 }
7082 else
7083 {
7084 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
7085 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_GLOB_DAT);
7086 rel.r_addend = 0;
7087 }
7088
947216bf
AM
7089 loc = srel->contents;
7090 loc += srel->reloc_count++ * sizeof (Elf32_External_Rela);
7091 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
37c644f2
AO
7092 }
7093
396a6083
SC
7094#ifdef INCLUDE_SHMEDIA
7095 {
7096 struct elf_sh_link_hash_entry *eh;
7097
7098 eh = (struct elf_sh_link_hash_entry *) h;
7099 if (eh->datalabel_got.offset != (bfd_vma) -1)
7100 {
7101 asection *sgot;
7102 asection *srel;
7103 Elf_Internal_Rela rel;
947216bf 7104 bfd_byte *loc;
396a6083
SC
7105
7106 /* This symbol has a datalabel entry in the global offset table.
7107 Set it up. */
7108
7109 sgot = htab->sgot;
7110 srel = htab->srelgot;
7111 BFD_ASSERT (sgot != NULL && srel != NULL);
7112
7113 rel.r_offset = (sgot->output_section->vma
7114 + sgot->output_offset
7115 + (eh->datalabel_got.offset &~ (bfd_vma) 1));
7116
7117 /* If this is a static link, or it is a -Bsymbolic link and the
7118 symbol is defined locally or was forced to be local because
7119 of a version file, we just want to emit a RELATIVE reloc.
7120 The entry in the global offset table will already have been
7121 initialized in the relocate_section function. */
7122 if (info->shared
7123 && (info->symbolic
7124 || h->dynindx == -1
7125 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
7126 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
7127 {
7128 rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
7129 rel.r_addend = (h->root.u.def.value
7130 + h->root.u.def.section->output_section->vma
7131 + h->root.u.def.section->output_offset);
7132 }
7133 else
7134 {
7135 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents
7136 + eh->datalabel_got.offset);
7137 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_GLOB_DAT);
7138 rel.r_addend = 0;
7139 }
7140
947216bf
AM
7141 loc = srel->contents;
7142 loc += srel->reloc_count++ * sizeof (Elf32_External_Rela);
7143 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
396a6083
SC
7144 }
7145 }
7146#endif
7147
37c644f2
AO
7148 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
7149 {
7150 asection *s;
7151 Elf_Internal_Rela rel;
947216bf 7152 bfd_byte *loc;
37c644f2
AO
7153
7154 /* This symbol needs a copy reloc. Set it up. */
7155
7156 BFD_ASSERT (h->dynindx != -1
7157 && (h->root.type == bfd_link_hash_defined
7158 || h->root.type == bfd_link_hash_defweak));
7159
7160 s = bfd_get_section_by_name (h->root.u.def.section->owner,
7161 ".rela.bss");
7162 BFD_ASSERT (s != NULL);
7163
7164 rel.r_offset = (h->root.u.def.value
7165 + h->root.u.def.section->output_section->vma
7166 + h->root.u.def.section->output_offset);
7167 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_COPY);
7168 rel.r_addend = 0;
947216bf
AM
7169 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
7170 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
37c644f2
AO
7171 }
7172
7173 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
7174 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
7175 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
7176 sym->st_shndx = SHN_ABS;
7177
b34976b6 7178 return TRUE;
37c644f2
AO
7179}
7180
7181/* Finish up the dynamic sections. */
7182
b34976b6 7183static bfd_boolean
37c644f2
AO
7184sh_elf_finish_dynamic_sections (output_bfd, info)
7185 bfd *output_bfd;
7186 struct bfd_link_info *info;
7187{
067653c5 7188 struct elf_sh_link_hash_table *htab;
37c644f2
AO
7189 bfd *dynobj;
7190 asection *sgot;
7191 asection *sdyn;
7192
067653c5
AM
7193 htab = sh_elf_hash_table (info);
7194 dynobj = htab->root.dynobj;
37c644f2 7195
067653c5 7196 sgot = htab->sgotplt;
37c644f2
AO
7197 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
7198
067653c5 7199 if (htab->root.dynamic_sections_created)
37c644f2
AO
7200 {
7201 asection *splt;
7202 Elf32_External_Dyn *dyncon, *dynconend;
7203
067653c5 7204 BFD_ASSERT (sgot != NULL && sdyn != NULL);
37c644f2
AO
7205
7206 dyncon = (Elf32_External_Dyn *) sdyn->contents;
7207 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
7208 for (; dyncon < dynconend; dyncon++)
7209 {
7210 Elf_Internal_Dyn dyn;
37c644f2 7211 asection *s;
067653c5
AM
7212#ifdef INCLUDE_SHMEDIA
7213 const char *name;
7214#endif
37c644f2
AO
7215
7216 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
7217
7218 switch (dyn.d_tag)
7219 {
7220 default:
7221 break;
7222
3b587c71
AM
7223#ifdef INCLUDE_SHMEDIA
7224 case DT_INIT:
7225 name = info->init_function;
7226 goto get_sym;
7227
7228 case DT_FINI:
7229 name = info->fini_function;
7230 get_sym:
7231 if (dyn.d_un.d_val != 0)
7232 {
067653c5
AM
7233 struct elf_link_hash_entry *h;
7234
7235 h = elf_link_hash_lookup (&htab->root, name,
b34976b6 7236 FALSE, FALSE, TRUE);
3b587c71
AM
7237 if (h != NULL && (h->other & STO_SH5_ISA32))
7238 {
7239 dyn.d_un.d_val |= 1;
7240 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7241 }
7242 }
7243 break;
7244#endif
7245
37c644f2 7246 case DT_PLTGOT:
067653c5 7247 s = htab->sgot->output_section;
37c644f2
AO
7248 goto get_vma;
7249
7250 case DT_JMPREL:
067653c5 7251 s = htab->srelplt->output_section;
37c644f2 7252 get_vma:
37c644f2
AO
7253 BFD_ASSERT (s != NULL);
7254 dyn.d_un.d_ptr = s->vma;
7255 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7256 break;
7257
7258 case DT_PLTRELSZ:
067653c5 7259 s = htab->srelplt->output_section;
37c644f2
AO
7260 BFD_ASSERT (s != NULL);
7261 if (s->_cooked_size != 0)
7262 dyn.d_un.d_val = s->_cooked_size;
7263 else
7264 dyn.d_un.d_val = s->_raw_size;
7265 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7266 break;
7267
7268 case DT_RELASZ:
7269 /* My reading of the SVR4 ABI indicates that the
7270 procedure linkage table relocs (DT_JMPREL) should be
7271 included in the overall relocs (DT_RELA). This is
7272 what Solaris does. However, UnixWare can not handle
7273 that case. Therefore, we override the DT_RELASZ entry
7274 here to make it not include the JMPREL relocs. Since
7275 the linker script arranges for .rela.plt to follow all
7276 other relocation sections, we don't have to worry
7277 about changing the DT_RELA entry. */
067653c5 7278 if (htab->srelplt != NULL)
37c644f2 7279 {
067653c5 7280 s = htab->srelplt->output_section;
37c644f2
AO
7281 if (s->_cooked_size != 0)
7282 dyn.d_un.d_val -= s->_cooked_size;
7283 else
7284 dyn.d_un.d_val -= s->_raw_size;
7285 }
7286 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7287 break;
7288 }
7289 }
7290
7291 /* Fill in the first entry in the procedure linkage table. */
067653c5 7292 splt = htab->splt;
37c644f2
AO
7293 if (splt && splt->_raw_size > 0)
7294 {
7295 if (info->shared)
7296 {
7297 if (elf_sh_pic_plt_entry == NULL)
7298 {
435b1e90 7299 elf_sh_pic_plt_entry = (bfd_big_endian (output_bfd) ?
37c644f2
AO
7300 elf_sh_pic_plt_entry_be :
7301 elf_sh_pic_plt_entry_le);
7302 }
7303 memcpy (splt->contents, elf_sh_pic_plt_entry,
7304 elf_sh_sizeof_plt (info));
7305 }
7306 else
7307 {
7308 if (elf_sh_plt0_entry == NULL)
7309 {
435b1e90 7310 elf_sh_plt0_entry = (bfd_big_endian (output_bfd) ?
37c644f2
AO
7311 elf_sh_plt0_entry_be :
7312 elf_sh_plt0_entry_le);
7313 }
7314 memcpy (splt->contents, elf_sh_plt0_entry, PLT_ENTRY_SIZE);
fbca6ad9
AO
7315#ifdef INCLUDE_SHMEDIA
7316 movi_shori_putval (output_bfd,
7317 sgot->output_section->vma
7318 + sgot->output_offset,
7319 splt->contents
7320 + elf_sh_plt0_gotplt_offset (info));
7321#else
37c644f2
AO
7322 bfd_put_32 (output_bfd,
7323 sgot->output_section->vma + sgot->output_offset + 4,
7324 splt->contents + elf_sh_plt0_gotid_offset (info));
7325 bfd_put_32 (output_bfd,
7326 sgot->output_section->vma + sgot->output_offset + 8,
7327 splt->contents + elf_sh_plt0_linker_offset (info));
fbca6ad9 7328#endif
37c644f2
AO
7329 }
7330
7331 /* UnixWare sets the entsize of .plt to 4, although that doesn't
7332 really seem like the right value. */
7333 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
7334 }
7335 }
7336
7337 /* Fill in the first three entries in the global offset table. */
067653c5 7338 if (sgot && sgot->_raw_size > 0)
37c644f2
AO
7339 {
7340 if (sdyn == NULL)
7341 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
7342 else
7343 bfd_put_32 (output_bfd,
7344 sdyn->output_section->vma + sdyn->output_offset,
7345 sgot->contents);
7346 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
7347 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
37c644f2 7348
067653c5
AM
7349 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
7350 }
37c644f2 7351
b34976b6 7352 return TRUE;
37c644f2
AO
7353}
7354
99e4ae17 7355static enum elf_reloc_type_class
f51e552e
AM
7356sh_elf_reloc_type_class (rela)
7357 const Elf_Internal_Rela *rela;
99e4ae17 7358{
f51e552e 7359 switch ((int) ELF32_R_TYPE (rela->r_info))
99e4ae17
AJ
7360 {
7361 case R_SH_RELATIVE:
7362 return reloc_class_relative;
7363 case R_SH_JMP_SLOT:
7364 return reloc_class_plt;
7365 case R_SH_COPY:
7366 return reloc_class_copy;
7367 default:
7368 return reloc_class_normal;
7369 }
7370}
7371
571fe01f 7372/* Support for Linux core dump NOTE sections. */
b34976b6 7373static bfd_boolean
2bc3c89a
AM
7374elf32_shlin_grok_prstatus (abfd, note)
7375 bfd *abfd;
7376 Elf_Internal_Note *note;
7377{
7378 int offset;
7379 unsigned int raw_size;
7380
7381 switch (note->descsz)
7382 {
7383 default:
b34976b6 7384 return FALSE;
2bc3c89a
AM
7385
7386 case 168: /* Linux/SH */
7387 /* pr_cursig */
7388 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
7389
7390 /* pr_pid */
7391 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
7392
7393 /* pr_reg */
7394 offset = 72;
7395 raw_size = 92;
7396
7397 break;
7398 }
7399
7400 /* Make a ".reg/999" section. */
7401 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
7402 raw_size, note->descpos + offset);
7403}
7404
b34976b6 7405static bfd_boolean
2bc3c89a
AM
7406elf32_shlin_grok_psinfo (abfd, note)
7407 bfd *abfd;
7408 Elf_Internal_Note *note;
7409{
7410 switch (note->descsz)
7411 {
7412 default:
b34976b6 7413 return FALSE;
2bc3c89a
AM
7414
7415 case 124: /* Linux/SH elf_prpsinfo */
7416 elf_tdata (abfd)->core_program
7417 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
7418 elf_tdata (abfd)->core_command
7419 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
7420 }
7421
7422 /* Note that for some reason, a spurious space is tacked
7423 onto the end of the args in some (at least one anyway)
7424 implementations, so strip it off if it exists. */
7425
7426 {
7427 char *command = elf_tdata (abfd)->core_command;
7428 int n = strlen (command);
7429
7430 if (0 < n && command[n - 1] == ' ')
7431 command[n - 1] = '\0';
7432 }
7433
b34976b6 7434 return TRUE;
2bc3c89a
AM
7435}
7436
252b5132
RH
7437#define TARGET_BIG_SYM bfd_elf32_sh_vec
7438#define TARGET_BIG_NAME "elf32-sh"
7439#define TARGET_LITTLE_SYM bfd_elf32_shl_vec
7440#define TARGET_LITTLE_NAME "elf32-shl"
7441#define ELF_ARCH bfd_arch_sh
7442#define ELF_MACHINE_CODE EM_SH
4bb5e078 7443#define ELF_MAXPAGESIZE 128
252b5132
RH
7444
7445#define elf_symbol_leading_char '_'
7446
7447#define bfd_elf32_bfd_reloc_type_lookup sh_elf_reloc_type_lookup
7448#define elf_info_to_howto sh_elf_info_to_howto
7449#define bfd_elf32_bfd_relax_section sh_elf_relax_section
7450#define elf_backend_relocate_section sh_elf_relocate_section
7451#define bfd_elf32_bfd_get_relocated_section_contents \
7452 sh_elf_get_relocated_section_contents
3376eaf5
KK
7453#define bfd_elf32_mkobject sh_elf_mkobject
7454#define elf_backend_object_p sh_elf_object_p
d4845d57
JR
7455#define bfd_elf32_bfd_set_private_bfd_flags \
7456 sh_elf_set_private_flags
7457#define bfd_elf32_bfd_copy_private_bfd_data \
7458 sh_elf_copy_private_data
875f7f69 7459#define bfd_elf32_bfd_merge_private_bfd_data \
d4845d57 7460 sh_elf_merge_private_data
252b5132 7461
067653c5
AM
7462#define elf_backend_gc_mark_hook sh_elf_gc_mark_hook
7463#define elf_backend_gc_sweep_hook sh_elf_gc_sweep_hook
7464#define elf_backend_check_relocs sh_elf_check_relocs
7465#define elf_backend_copy_indirect_symbol \
7466 sh_elf_copy_indirect_symbol
37c644f2
AO
7467#define elf_backend_create_dynamic_sections \
7468 sh_elf_create_dynamic_sections
7469#define bfd_elf32_bfd_link_hash_table_create \
7470 sh_elf_link_hash_table_create
7471#define elf_backend_adjust_dynamic_symbol \
7472 sh_elf_adjust_dynamic_symbol
7473#define elf_backend_size_dynamic_sections \
7474 sh_elf_size_dynamic_sections
7475#define elf_backend_finish_dynamic_symbol \
7476 sh_elf_finish_dynamic_symbol
7477#define elf_backend_finish_dynamic_sections \
7478 sh_elf_finish_dynamic_sections
99e4ae17 7479#define elf_backend_reloc_type_class sh_elf_reloc_type_class
37c644f2 7480
067653c5
AM
7481#define elf_backend_can_gc_sections 1
7482#define elf_backend_can_refcount 1
37c644f2
AO
7483#define elf_backend_want_got_plt 1
7484#define elf_backend_plt_readonly 1
7485#define elf_backend_want_plt_sym 0
7486#define elf_backend_got_header_size 12
7487#define elf_backend_plt_header_size PLT_ENTRY_SIZE
ed71e111 7488
2bc3c89a
AM
7489#ifndef INCLUDE_SHMEDIA
7490
252b5132 7491#include "elf32-target.h"
ed71e111 7492
2bc3c89a
AM
7493/* NetBSD support. */
7494#undef TARGET_BIG_SYM
7495#define TARGET_BIG_SYM bfd_elf32_shnbsd_vec
7496#undef TARGET_BIG_NAME
7497#define TARGET_BIG_NAME "elf32-sh-nbsd"
7498#undef TARGET_LITTLE_SYM
7499#define TARGET_LITTLE_SYM bfd_elf32_shlnbsd_vec
7500#undef TARGET_LITTLE_NAME
7501#define TARGET_LITTLE_NAME "elf32-shl-nbsd"
7502#undef ELF_MAXPAGESIZE
7503#define ELF_MAXPAGESIZE 0x10000
7504#undef elf_symbol_leading_char
7505#define elf_symbol_leading_char 0
571fe01f 7506#undef elf32_bed
2bc3c89a
AM
7507#define elf32_bed elf32_sh_nbsd_bed
7508
7509#include "elf32-target.h"
7510
2bc3c89a
AM
7511
7512/* Linux support. */
7513#undef TARGET_BIG_SYM
7514#define TARGET_BIG_SYM bfd_elf32_shblin_vec
7515#undef TARGET_BIG_NAME
7516#define TARGET_BIG_NAME "elf32-shbig-linux"
7517#undef TARGET_LITTLE_SYM
7518#define TARGET_LITTLE_SYM bfd_elf32_shlin_vec
7519#undef TARGET_LITTLE_NAME
7520#define TARGET_LITTLE_NAME "elf32-sh-linux"
7521
7522#undef elf_backend_grok_prstatus
7523#define elf_backend_grok_prstatus elf32_shlin_grok_prstatus
7524#undef elf_backend_grok_psinfo
7525#define elf_backend_grok_psinfo elf32_shlin_grok_psinfo
571fe01f 7526#undef elf32_bed
2bc3c89a
AM
7527#define elf32_bed elf32_sh_lin_bed
7528
7529#include "elf32-target.h"
7530
2bc3c89a 7531#endif /* INCLUDE_SHMEDIA */
This page took 0.717918 seconds and 4 git commands to generate.