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