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