1 /* Renesas / SuperH SH specific support for 32-bit ELF
2 Copyright (C) 1996-2018 Free Software Foundation, Inc.
3 Contributed by Ian Lance Taylor, Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
27 #include "elf-vxworks.h"
30 #include "libiberty.h"
31 #include "../opcodes/sh-opc.h"
33 static bfd_reloc_status_type sh_elf_reloc
34 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
35 static bfd_reloc_status_type sh_elf_ignore_reloc
36 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
37 static bfd_boolean sh_elf_relax_delete_bytes
38 (bfd *, asection *, bfd_vma, int);
39 static bfd_boolean sh_elf_align_loads
40 (bfd *, asection *, Elf_Internal_Rela *, bfd_byte *, bfd_boolean *);
42 static bfd_boolean sh_elf_swap_insns
43 (bfd *, asection *, void *, bfd_byte *, bfd_vma);
45 static int sh_elf_optimized_tls_reloc
46 (struct bfd_link_info *, int, int);
47 static bfd_vma dtpoff_base
48 (struct bfd_link_info *);
50 (struct bfd_link_info *, bfd_vma);
52 /* The name of the dynamic interpreter. This is put in the .interp
55 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
57 /* FDPIC binaries have a default 128K stack. */
58 #define DEFAULT_STACK_SIZE 0x20000
60 #define MINUS_ONE ((bfd_vma) 0 - 1)
62 /* Decide whether a reference to a symbol can be resolved locally or
63 not. If the symbol is protected, we want the local address, but
64 its function descriptor must be assigned by the dynamic linker. */
65 #define SYMBOL_FUNCDESC_LOCAL(INFO, H) \
66 (SYMBOL_REFERENCES_LOCAL (INFO, H) \
67 || ! elf_hash_table (INFO)->dynamic_sections_created)
69 #define SH_PARTIAL32 TRUE
70 #define SH_SRC_MASK32 0xffffffff
71 #define SH_ELF_RELOC sh_elf_reloc
72 static reloc_howto_type sh_elf_howto_table[] =
74 #include "elf32-sh-relocs.h"
77 #define SH_PARTIAL32 FALSE
78 #define SH_SRC_MASK32 0
79 #define SH_ELF_RELOC bfd_elf_generic_reloc
80 static reloc_howto_type sh_vxworks_howto_table[] =
82 #include "elf32-sh-relocs.h"
85 /* Return true if OUTPUT_BFD is a VxWorks object. */
88 vxworks_object_p (bfd *abfd ATTRIBUTE_UNUSED)
90 #if !defined INCLUDE_SHMEDIA && !defined SH_TARGET_ALREADY_DEFINED
91 extern const bfd_target sh_elf32_vxworks_le_vec;
92 extern const bfd_target sh_elf32_vxworks_vec;
94 return (abfd->xvec == &sh_elf32_vxworks_le_vec
95 || abfd->xvec == &sh_elf32_vxworks_vec);
101 /* Return true if OUTPUT_BFD is an FDPIC object. */
104 fdpic_object_p (bfd *abfd ATTRIBUTE_UNUSED)
106 #if !defined INCLUDE_SHMEDIA && !defined SH_TARGET_ALREADY_DEFINED
107 extern const bfd_target sh_elf32_fdpic_le_vec;
108 extern const bfd_target sh_elf32_fdpic_be_vec;
110 return (abfd->xvec == &sh_elf32_fdpic_le_vec
111 || abfd->xvec == &sh_elf32_fdpic_be_vec);
117 /* Return the howto table for ABFD. */
119 static reloc_howto_type *
120 get_howto_table (bfd *abfd)
122 if (vxworks_object_p (abfd))
123 return sh_vxworks_howto_table;
124 return sh_elf_howto_table;
127 static bfd_reloc_status_type
128 sh_elf_reloc_loop (int r_type ATTRIBUTE_UNUSED, bfd *input_bfd,
129 asection *input_section, bfd_byte *contents,
130 bfd_vma addr, asection *symbol_section,
131 bfd_vma start, bfd_vma end)
133 static bfd_vma last_addr;
134 static asection *last_symbol_section;
135 bfd_byte *start_ptr, *ptr, *last_ptr;
140 /* Sanity check the address. */
141 if (addr > bfd_get_section_limit (input_bfd, input_section))
142 return bfd_reloc_outofrange;
144 /* We require the start and end relocations to be processed consecutively -
145 although we allow then to be processed forwards or backwards. */
149 last_symbol_section = symbol_section;
152 if (last_addr != addr)
156 if (! symbol_section || last_symbol_section != symbol_section || end < start)
157 return bfd_reloc_outofrange;
159 /* Get the symbol_section contents. */
160 if (symbol_section != input_section)
162 if (elf_section_data (symbol_section)->this_hdr.contents != NULL)
163 contents = elf_section_data (symbol_section)->this_hdr.contents;
166 if (!bfd_malloc_and_get_section (input_bfd, symbol_section,
169 if (contents != NULL)
171 return bfd_reloc_outofrange;
175 #define IS_PPI(PTR) ((bfd_get_16 (input_bfd, (PTR)) & 0xfc00) == 0xf800)
176 start_ptr = contents + start;
177 for (cum_diff = -6, ptr = contents + end; cum_diff < 0 && ptr > start_ptr;)
179 for (last_ptr = ptr, ptr -= 4; ptr >= start_ptr && IS_PPI (ptr);)
182 diff = (last_ptr - ptr) >> 1;
183 cum_diff += diff & 1;
186 /* Calculate the start / end values to load into rs / re minus four -
187 so that will cancel out the four we would otherwise have to add to
188 addr to get the value to subtract in order to get relative addressing. */
192 end = (ptr + cum_diff * 2) - contents;
196 bfd_vma start0 = start - 4;
198 while (start0 && IS_PPI (contents + start0))
200 start0 = start - 2 - ((start - start0) & 2);
201 start = start0 - cum_diff - 2;
206 && elf_section_data (symbol_section)->this_hdr.contents != contents)
209 insn = bfd_get_16 (input_bfd, contents + addr);
211 x = (insn & 0x200 ? end : start) - addr;
212 if (input_section != symbol_section)
213 x += ((symbol_section->output_section->vma + symbol_section->output_offset)
214 - (input_section->output_section->vma
215 + input_section->output_offset));
217 if (x < -128 || x > 127)
218 return bfd_reloc_overflow;
220 x = (insn & ~0xff) | (x & 0xff);
221 bfd_put_16 (input_bfd, (bfd_vma) x, contents + addr);
226 /* This function is used for normal relocs. This used to be like the COFF
227 function, and is almost certainly incorrect for other ELF targets. */
229 static bfd_reloc_status_type
230 sh_elf_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol_in,
231 void *data, asection *input_section, bfd *output_bfd,
232 char **error_message ATTRIBUTE_UNUSED)
236 enum elf_sh_reloc_type r_type;
237 bfd_vma addr = reloc_entry->address;
238 bfd_byte *hit_data = addr + (bfd_byte *) data;
240 r_type = (enum elf_sh_reloc_type) reloc_entry->howto->type;
242 if (output_bfd != NULL)
244 /* Partial linking--do nothing. */
245 reloc_entry->address += input_section->output_offset;
249 /* Almost all relocs have to do with relaxing. If any work must be
250 done for them, it has been done in sh_relax_section. */
251 if (r_type == R_SH_IND12W && (symbol_in->flags & BSF_LOCAL) != 0)
254 if (symbol_in != NULL
255 && bfd_is_und_section (symbol_in->section))
256 return bfd_reloc_undefined;
258 /* PR 17512: file: 9891ca98. */
259 if (addr * bfd_octets_per_byte (abfd) + bfd_get_reloc_size (reloc_entry->howto)
260 > bfd_get_section_limit_octets (abfd, input_section))
261 return bfd_reloc_outofrange;
263 if (bfd_is_com_section (symbol_in->section))
266 sym_value = (symbol_in->value +
267 symbol_in->section->output_section->vma +
268 symbol_in->section->output_offset);
273 insn = bfd_get_32 (abfd, hit_data);
274 insn += sym_value + reloc_entry->addend;
275 bfd_put_32 (abfd, (bfd_vma) insn, hit_data);
278 insn = bfd_get_16 (abfd, hit_data);
279 sym_value += reloc_entry->addend;
280 sym_value -= (input_section->output_section->vma
281 + input_section->output_offset
284 sym_value += (insn & 0xfff) << 1;
287 insn = (insn & 0xf000) | (sym_value & 0xfff);
288 bfd_put_16 (abfd, (bfd_vma) insn, hit_data);
289 if (sym_value < (bfd_vma) -0x1000 || sym_value >= 0x1000)
290 return bfd_reloc_overflow;
300 /* This function is used for relocs which are only used for relaxing,
301 which the linker should otherwise ignore. */
303 static bfd_reloc_status_type
304 sh_elf_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc_entry,
305 asymbol *symbol ATTRIBUTE_UNUSED,
306 void *data ATTRIBUTE_UNUSED, asection *input_section,
308 char **error_message ATTRIBUTE_UNUSED)
310 if (output_bfd != NULL)
311 reloc_entry->address += input_section->output_offset;
315 /* This structure is used to map BFD reloc codes to SH ELF relocs. */
319 bfd_reloc_code_real_type bfd_reloc_val;
320 unsigned char elf_reloc_val;
323 /* An array mapping BFD reloc codes to SH ELF relocs. */
325 static const struct elf_reloc_map sh_reloc_map[] =
327 { BFD_RELOC_NONE, R_SH_NONE },
328 { BFD_RELOC_32, R_SH_DIR32 },
329 { BFD_RELOC_16, R_SH_DIR16 },
330 { BFD_RELOC_8, R_SH_DIR8 },
331 { BFD_RELOC_CTOR, R_SH_DIR32 },
332 { BFD_RELOC_32_PCREL, R_SH_REL32 },
333 { BFD_RELOC_SH_PCDISP8BY2, R_SH_DIR8WPN },
334 { BFD_RELOC_SH_PCDISP12BY2, R_SH_IND12W },
335 { BFD_RELOC_SH_PCRELIMM8BY2, R_SH_DIR8WPZ },
336 { BFD_RELOC_SH_PCRELIMM8BY4, R_SH_DIR8WPL },
337 { BFD_RELOC_8_PCREL, R_SH_SWITCH8 },
338 { BFD_RELOC_SH_SWITCH16, R_SH_SWITCH16 },
339 { BFD_RELOC_SH_SWITCH32, R_SH_SWITCH32 },
340 { BFD_RELOC_SH_USES, R_SH_USES },
341 { BFD_RELOC_SH_COUNT, R_SH_COUNT },
342 { BFD_RELOC_SH_ALIGN, R_SH_ALIGN },
343 { BFD_RELOC_SH_CODE, R_SH_CODE },
344 { BFD_RELOC_SH_DATA, R_SH_DATA },
345 { BFD_RELOC_SH_LABEL, R_SH_LABEL },
346 { BFD_RELOC_VTABLE_INHERIT, R_SH_GNU_VTINHERIT },
347 { BFD_RELOC_VTABLE_ENTRY, R_SH_GNU_VTENTRY },
348 { BFD_RELOC_SH_LOOP_START, R_SH_LOOP_START },
349 { BFD_RELOC_SH_LOOP_END, R_SH_LOOP_END },
350 { BFD_RELOC_SH_TLS_GD_32, R_SH_TLS_GD_32 },
351 { BFD_RELOC_SH_TLS_LD_32, R_SH_TLS_LD_32 },
352 { BFD_RELOC_SH_TLS_LDO_32, R_SH_TLS_LDO_32 },
353 { BFD_RELOC_SH_TLS_IE_32, R_SH_TLS_IE_32 },
354 { BFD_RELOC_SH_TLS_LE_32, R_SH_TLS_LE_32 },
355 { BFD_RELOC_SH_TLS_DTPMOD32, R_SH_TLS_DTPMOD32 },
356 { BFD_RELOC_SH_TLS_DTPOFF32, R_SH_TLS_DTPOFF32 },
357 { BFD_RELOC_SH_TLS_TPOFF32, R_SH_TLS_TPOFF32 },
358 { BFD_RELOC_32_GOT_PCREL, R_SH_GOT32 },
359 { BFD_RELOC_32_PLT_PCREL, R_SH_PLT32 },
360 { BFD_RELOC_SH_COPY, R_SH_COPY },
361 { BFD_RELOC_SH_GLOB_DAT, R_SH_GLOB_DAT },
362 { BFD_RELOC_SH_JMP_SLOT, R_SH_JMP_SLOT },
363 { BFD_RELOC_SH_RELATIVE, R_SH_RELATIVE },
364 { BFD_RELOC_32_GOTOFF, R_SH_GOTOFF },
365 { BFD_RELOC_SH_GOTPC, R_SH_GOTPC },
366 { BFD_RELOC_SH_GOTPLT32, R_SH_GOTPLT32 },
367 { BFD_RELOC_SH_GOT20, R_SH_GOT20 },
368 { BFD_RELOC_SH_GOTOFF20, R_SH_GOTOFF20 },
369 { BFD_RELOC_SH_GOTFUNCDESC, R_SH_GOTFUNCDESC },
370 { BFD_RELOC_SH_GOTFUNCDESC20, R_SH_GOTFUNCDESC20 },
371 { BFD_RELOC_SH_GOTOFFFUNCDESC, R_SH_GOTOFFFUNCDESC },
372 { BFD_RELOC_SH_GOTOFFFUNCDESC20, R_SH_GOTOFFFUNCDESC20 },
373 { BFD_RELOC_SH_FUNCDESC, R_SH_FUNCDESC },
374 #ifdef INCLUDE_SHMEDIA
375 { BFD_RELOC_SH_GOT_LOW16, R_SH_GOT_LOW16 },
376 { BFD_RELOC_SH_GOT_MEDLOW16, R_SH_GOT_MEDLOW16 },
377 { BFD_RELOC_SH_GOT_MEDHI16, R_SH_GOT_MEDHI16 },
378 { BFD_RELOC_SH_GOT_HI16, R_SH_GOT_HI16 },
379 { BFD_RELOC_SH_GOTPLT_LOW16, R_SH_GOTPLT_LOW16 },
380 { BFD_RELOC_SH_GOTPLT_MEDLOW16, R_SH_GOTPLT_MEDLOW16 },
381 { BFD_RELOC_SH_GOTPLT_MEDHI16, R_SH_GOTPLT_MEDHI16 },
382 { BFD_RELOC_SH_GOTPLT_HI16, R_SH_GOTPLT_HI16 },
383 { BFD_RELOC_SH_PLT_LOW16, R_SH_PLT_LOW16 },
384 { BFD_RELOC_SH_PLT_MEDLOW16, R_SH_PLT_MEDLOW16 },
385 { BFD_RELOC_SH_PLT_MEDHI16, R_SH_PLT_MEDHI16 },
386 { BFD_RELOC_SH_PLT_HI16, R_SH_PLT_HI16 },
387 { BFD_RELOC_SH_GOTOFF_LOW16, R_SH_GOTOFF_LOW16 },
388 { BFD_RELOC_SH_GOTOFF_MEDLOW16, R_SH_GOTOFF_MEDLOW16 },
389 { BFD_RELOC_SH_GOTOFF_MEDHI16, R_SH_GOTOFF_MEDHI16 },
390 { BFD_RELOC_SH_GOTOFF_HI16, R_SH_GOTOFF_HI16 },
391 { BFD_RELOC_SH_GOTPC_LOW16, R_SH_GOTPC_LOW16 },
392 { BFD_RELOC_SH_GOTPC_MEDLOW16, R_SH_GOTPC_MEDLOW16 },
393 { BFD_RELOC_SH_GOTPC_MEDHI16, R_SH_GOTPC_MEDHI16 },
394 { BFD_RELOC_SH_GOTPC_HI16, R_SH_GOTPC_HI16 },
395 { BFD_RELOC_SH_COPY64, R_SH_COPY64 },
396 { BFD_RELOC_SH_GLOB_DAT64, R_SH_GLOB_DAT64 },
397 { BFD_RELOC_SH_JMP_SLOT64, R_SH_JMP_SLOT64 },
398 { BFD_RELOC_SH_RELATIVE64, R_SH_RELATIVE64 },
399 { BFD_RELOC_SH_GOT10BY4, R_SH_GOT10BY4 },
400 { BFD_RELOC_SH_GOT10BY8, R_SH_GOT10BY8 },
401 { BFD_RELOC_SH_GOTPLT10BY4, R_SH_GOTPLT10BY4 },
402 { BFD_RELOC_SH_GOTPLT10BY8, R_SH_GOTPLT10BY8 },
403 { BFD_RELOC_SH_PT_16, R_SH_PT_16 },
404 { BFD_RELOC_SH_SHMEDIA_CODE, R_SH_SHMEDIA_CODE },
405 { BFD_RELOC_SH_IMMU5, R_SH_DIR5U },
406 { BFD_RELOC_SH_IMMS6, R_SH_DIR6S },
407 { BFD_RELOC_SH_IMMU6, R_SH_DIR6U },
408 { BFD_RELOC_SH_IMMS10, R_SH_DIR10S },
409 { BFD_RELOC_SH_IMMS10BY2, R_SH_DIR10SW },
410 { BFD_RELOC_SH_IMMS10BY4, R_SH_DIR10SL },
411 { BFD_RELOC_SH_IMMS10BY8, R_SH_DIR10SQ },
412 { BFD_RELOC_SH_IMMS16, R_SH_IMMS16 },
413 { BFD_RELOC_SH_IMMU16, R_SH_IMMU16 },
414 { BFD_RELOC_SH_IMM_LOW16, R_SH_IMM_LOW16 },
415 { BFD_RELOC_SH_IMM_LOW16_PCREL, R_SH_IMM_LOW16_PCREL },
416 { BFD_RELOC_SH_IMM_MEDLOW16, R_SH_IMM_MEDLOW16 },
417 { BFD_RELOC_SH_IMM_MEDLOW16_PCREL, R_SH_IMM_MEDLOW16_PCREL },
418 { BFD_RELOC_SH_IMM_MEDHI16, R_SH_IMM_MEDHI16 },
419 { BFD_RELOC_SH_IMM_MEDHI16_PCREL, R_SH_IMM_MEDHI16_PCREL },
420 { BFD_RELOC_SH_IMM_HI16, R_SH_IMM_HI16 },
421 { BFD_RELOC_SH_IMM_HI16_PCREL, R_SH_IMM_HI16_PCREL },
422 { BFD_RELOC_64, R_SH_64 },
423 { BFD_RELOC_64_PCREL, R_SH_64_PCREL },
424 #endif /* not INCLUDE_SHMEDIA */
427 /* Given a BFD reloc code, return the howto structure for the
428 corresponding SH ELF reloc. */
430 static reloc_howto_type *
431 sh_elf_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code)
435 for (i = 0; i < sizeof (sh_reloc_map) / sizeof (struct elf_reloc_map); i++)
437 if (sh_reloc_map[i].bfd_reloc_val == code)
438 return get_howto_table (abfd) + (int) sh_reloc_map[i].elf_reloc_val;
444 static reloc_howto_type *
445 sh_elf_reloc_name_lookup (bfd *abfd, const char *r_name)
449 if (vxworks_object_p (abfd))
452 i < (sizeof (sh_vxworks_howto_table)
453 / sizeof (sh_vxworks_howto_table[0]));
455 if (sh_vxworks_howto_table[i].name != NULL
456 && strcasecmp (sh_vxworks_howto_table[i].name, r_name) == 0)
457 return &sh_vxworks_howto_table[i];
462 i < (sizeof (sh_elf_howto_table)
463 / sizeof (sh_elf_howto_table[0]));
465 if (sh_elf_howto_table[i].name != NULL
466 && strcasecmp (sh_elf_howto_table[i].name, r_name) == 0)
467 return &sh_elf_howto_table[i];
473 /* Given an ELF reloc, fill in the howto field of a relent. */
476 sh_elf_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)
480 r = ELF32_R_TYPE (dst->r_info);
483 || (r >= R_SH_FIRST_INVALID_RELOC && r <= R_SH_LAST_INVALID_RELOC)
484 || (r >= R_SH_FIRST_INVALID_RELOC_2 && r <= R_SH_LAST_INVALID_RELOC_2)
485 || (r >= R_SH_FIRST_INVALID_RELOC_3 && r <= R_SH_LAST_INVALID_RELOC_3)
486 || (r >= R_SH_FIRST_INVALID_RELOC_4 && r <= R_SH_LAST_INVALID_RELOC_4)
487 || (r >= R_SH_FIRST_INVALID_RELOC_5 && r <= R_SH_LAST_INVALID_RELOC_5)
488 || (r >= R_SH_FIRST_INVALID_RELOC_6 && r <= R_SH_LAST_INVALID_RELOC_6))
490 /* xgettext:c-format */
491 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
493 bfd_set_error (bfd_error_bad_value);
497 cache_ptr->howto = get_howto_table (abfd) + r;
500 /* This function handles relaxing for SH ELF. See the corresponding
501 function in coff-sh.c for a description of what this does. FIXME:
502 There is a lot of duplication here between this code and the COFF
503 specific code. The format of relocs and symbols is wound deeply
504 into this code, but it would still be better if the duplication
505 could be eliminated somehow. Note in particular that although both
506 functions use symbols like R_SH_CODE, those symbols have different
507 values; in coff-sh.c they come from include/coff/sh.h, whereas here
508 they come from enum elf_sh_reloc_type in include/elf/sh.h. */
511 sh_elf_relax_section (bfd *abfd, asection *sec,
512 struct bfd_link_info *link_info, bfd_boolean *again)
514 Elf_Internal_Shdr *symtab_hdr;
515 Elf_Internal_Rela *internal_relocs;
516 bfd_boolean have_code;
517 Elf_Internal_Rela *irel, *irelend;
518 bfd_byte *contents = NULL;
519 Elf_Internal_Sym *isymbuf = NULL;
523 if (bfd_link_relocatable (link_info)
524 || (sec->flags & SEC_RELOC) == 0
525 || sec->reloc_count == 0)
528 #ifdef INCLUDE_SHMEDIA
529 if (elf_section_data (sec)->this_hdr.sh_flags
530 & (SHF_SH5_ISA32 | SHF_SH5_ISA32_MIXED))
536 symtab_hdr = &elf_symtab_hdr (abfd);
538 internal_relocs = (_bfd_elf_link_read_relocs
539 (abfd, sec, NULL, (Elf_Internal_Rela *) NULL,
540 link_info->keep_memory));
541 if (internal_relocs == NULL)
546 irelend = internal_relocs + sec->reloc_count;
547 for (irel = internal_relocs; irel < irelend; irel++)
549 bfd_vma laddr, paddr, symval;
551 Elf_Internal_Rela *irelfn, *irelscan, *irelcount;
554 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_CODE)
557 if (ELF32_R_TYPE (irel->r_info) != (int) R_SH_USES)
560 /* Get the section contents. */
561 if (contents == NULL)
563 if (elf_section_data (sec)->this_hdr.contents != NULL)
564 contents = elf_section_data (sec)->this_hdr.contents;
567 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
572 /* The r_addend field of the R_SH_USES reloc will point us to
573 the register load. The 4 is because the r_addend field is
574 computed as though it were a jump offset, which are based
575 from 4 bytes after the jump instruction. */
576 laddr = irel->r_offset + 4 + irel->r_addend;
577 if (laddr >= sec->size)
579 /* xgettext:c-format */
581 (_("%pB: %#" PRIx64 ": warning: bad R_SH_USES offset"),
582 abfd, (uint64_t) irel->r_offset);
585 insn = bfd_get_16 (abfd, contents + laddr);
587 /* If the instruction is not mov.l NN,rN, we don't know what to
589 if ((insn & 0xf000) != 0xd000)
592 /* xgettext:c-format */
593 (_("%pB: %#" PRIx64 ": warning: "
594 "R_SH_USES points to unrecognized insn 0x%x"),
595 abfd, (uint64_t) irel->r_offset, insn);
599 /* Get the address from which the register is being loaded. The
600 displacement in the mov.l instruction is quadrupled. It is a
601 displacement from four bytes after the movl instruction, but,
602 before adding in the PC address, two least significant bits
603 of the PC are cleared. We assume that the section is aligned
604 on a four byte boundary. */
607 paddr += (laddr + 4) &~ (bfd_vma) 3;
608 if (paddr >= sec->size)
611 /* xgettext:c-format */
612 (_("%pB: %#" PRIx64 ": warning: bad R_SH_USES load offset"),
613 abfd, (uint64_t) irel->r_offset);
617 /* Get the reloc for the address from which the register is
618 being loaded. This reloc will tell us which function is
619 actually being called. */
620 for (irelfn = internal_relocs; irelfn < irelend; irelfn++)
621 if (irelfn->r_offset == paddr
622 && ELF32_R_TYPE (irelfn->r_info) == (int) R_SH_DIR32)
624 if (irelfn >= irelend)
627 /* xgettext:c-format */
628 (_("%pB: %#" PRIx64 ": warning: could not find expected reloc"),
629 abfd, (uint64_t) paddr);
633 /* Read this BFD's symbols if we haven't done so already. */
634 if (isymbuf == NULL && symtab_hdr->sh_info != 0)
636 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
638 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
639 symtab_hdr->sh_info, 0,
645 /* Get the value of the symbol referred to by the reloc. */
646 if (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
648 /* A local symbol. */
649 Elf_Internal_Sym *isym;
651 isym = isymbuf + ELF32_R_SYM (irelfn->r_info);
653 != (unsigned int) _bfd_elf_section_from_bfd_section (abfd, sec))
656 /* xgettext:c-format */
657 (_("%pB: %#" PRIx64 ": warning: symbol in unexpected section"),
658 abfd, (uint64_t) paddr);
662 symval = (isym->st_value
663 + sec->output_section->vma
664 + sec->output_offset);
669 struct elf_link_hash_entry *h;
671 indx = ELF32_R_SYM (irelfn->r_info) - symtab_hdr->sh_info;
672 h = elf_sym_hashes (abfd)[indx];
673 BFD_ASSERT (h != NULL);
674 if (h->root.type != bfd_link_hash_defined
675 && h->root.type != bfd_link_hash_defweak)
677 /* This appears to be a reference to an undefined
678 symbol. Just ignore it--it will be caught by the
679 regular reloc processing. */
683 symval = (h->root.u.def.value
684 + h->root.u.def.section->output_section->vma
685 + h->root.u.def.section->output_offset);
688 if (get_howto_table (abfd)[R_SH_DIR32].partial_inplace)
689 symval += bfd_get_32 (abfd, contents + paddr);
691 symval += irelfn->r_addend;
693 /* See if this function call can be shortened. */
696 + sec->output_section->vma
699 /* A branch to an address beyond ours might be increased by an
700 .align that doesn't move when bytes behind us are deleted.
701 So, we add some slop in this calculation to allow for
703 if (foff < -0x1000 || foff >= 0x1000 - 8)
705 /* After all that work, we can't shorten this function call. */
709 /* Shorten the function call. */
711 /* For simplicity of coding, we are going to modify the section
712 contents, the section relocs, and the BFD symbol table. We
713 must tell the rest of the code not to free up this
714 information. It would be possible to instead create a table
715 of changes which have to be made, as is done in coff-mips.c;
716 that would be more work, but would require less memory when
717 the linker is run. */
719 elf_section_data (sec)->relocs = internal_relocs;
720 elf_section_data (sec)->this_hdr.contents = contents;
721 symtab_hdr->contents = (unsigned char *) isymbuf;
723 /* Replace the jmp/jsr with a bra/bsr. */
725 /* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and
726 replace the jmp/jsr with a bra/bsr. */
727 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irelfn->r_info), R_SH_IND12W);
728 /* We used to test (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
729 here, but that only checks if the symbol is an external symbol,
730 not if the symbol is in a different section. Besides, we need
731 a consistent meaning for the relocation, so we just assume here that
732 the value of the symbol is not available. */
734 /* We can't fully resolve this yet, because the external
735 symbol value may be changed by future relaxing. We let
736 the final link phase handle it. */
737 if (bfd_get_16 (abfd, contents + irel->r_offset) & 0x0020)
738 bfd_put_16 (abfd, (bfd_vma) 0xa000, contents + irel->r_offset);
740 bfd_put_16 (abfd, (bfd_vma) 0xb000, contents + irel->r_offset);
744 /* When we calculated the symbol "value" we had an offset in the
745 DIR32's word in memory (we read and add it above). However,
746 the jsr we create does NOT have this offset encoded, so we
747 have to add it to the addend to preserve it. */
748 irel->r_addend += bfd_get_32 (abfd, contents + paddr);
750 /* See if there is another R_SH_USES reloc referring to the same
752 for (irelscan = internal_relocs; irelscan < irelend; irelscan++)
753 if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_USES
754 && laddr == irelscan->r_offset + 4 + irelscan->r_addend)
756 if (irelscan < irelend)
758 /* Some other function call depends upon this register load,
759 and we have not yet converted that function call.
760 Indeed, we may never be able to convert it. There is
761 nothing else we can do at this point. */
765 /* Look for a R_SH_COUNT reloc on the location where the
766 function address is stored. Do this before deleting any
767 bytes, to avoid confusion about the address. */
768 for (irelcount = internal_relocs; irelcount < irelend; irelcount++)
769 if (irelcount->r_offset == paddr
770 && ELF32_R_TYPE (irelcount->r_info) == (int) R_SH_COUNT)
773 /* Delete the register load. */
774 if (! sh_elf_relax_delete_bytes (abfd, sec, laddr, 2))
777 /* That will change things, so, just in case it permits some
778 other function call to come within range, we should relax
779 again. Note that this is not required, and it may be slow. */
782 /* Now check whether we got a COUNT reloc. */
783 if (irelcount >= irelend)
786 /* xgettext:c-format */
787 (_("%pB: %#" PRIx64 ": warning: "
788 "could not find expected COUNT reloc"),
789 abfd, (uint64_t) paddr);
793 /* The number of uses is stored in the r_addend field. We've
795 if (irelcount->r_addend == 0)
797 /* xgettext:c-format */
798 _bfd_error_handler (_("%pB: %#" PRIx64 ": warning: bad count"),
799 abfd, (uint64_t) paddr);
803 --irelcount->r_addend;
805 /* If there are no more uses, we can delete the address. Reload
806 the address from irelfn, in case it was changed by the
807 previous call to sh_elf_relax_delete_bytes. */
808 if (irelcount->r_addend == 0)
810 if (! sh_elf_relax_delete_bytes (abfd, sec, irelfn->r_offset, 4))
814 /* We've done all we can with that function call. */
817 /* Look for load and store instructions that we can align on four
819 if ((elf_elfheader (abfd)->e_flags & EF_SH_MACH_MASK) != EF_SH4
824 /* Get the section contents. */
825 if (contents == NULL)
827 if (elf_section_data (sec)->this_hdr.contents != NULL)
828 contents = elf_section_data (sec)->this_hdr.contents;
831 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
836 if (! sh_elf_align_loads (abfd, sec, internal_relocs, contents,
842 elf_section_data (sec)->relocs = internal_relocs;
843 elf_section_data (sec)->this_hdr.contents = contents;
844 symtab_hdr->contents = (unsigned char *) isymbuf;
849 && symtab_hdr->contents != (unsigned char *) isymbuf)
851 if (! link_info->keep_memory)
855 /* Cache the symbols for elf_link_input_bfd. */
856 symtab_hdr->contents = (unsigned char *) isymbuf;
861 && elf_section_data (sec)->this_hdr.contents != contents)
863 if (! link_info->keep_memory)
867 /* Cache the section contents for elf_link_input_bfd. */
868 elf_section_data (sec)->this_hdr.contents = contents;
872 if (internal_relocs != NULL
873 && elf_section_data (sec)->relocs != internal_relocs)
874 free (internal_relocs);
880 && symtab_hdr->contents != (unsigned char *) isymbuf)
883 && elf_section_data (sec)->this_hdr.contents != contents)
885 if (internal_relocs != NULL
886 && elf_section_data (sec)->relocs != internal_relocs)
887 free (internal_relocs);
892 /* Delete some bytes from a section while relaxing. FIXME: There is a
893 lot of duplication between this function and sh_relax_delete_bytes
897 sh_elf_relax_delete_bytes (bfd *abfd, asection *sec, bfd_vma addr,
900 Elf_Internal_Shdr *symtab_hdr;
901 unsigned int sec_shndx;
903 Elf_Internal_Rela *irel, *irelend;
904 Elf_Internal_Rela *irelalign;
906 Elf_Internal_Sym *isymbuf, *isym, *isymend;
907 struct elf_link_hash_entry **sym_hashes;
908 struct elf_link_hash_entry **end_hashes;
909 unsigned int symcount;
912 symtab_hdr = &elf_symtab_hdr (abfd);
913 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
915 sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
917 contents = elf_section_data (sec)->this_hdr.contents;
919 /* The deletion must stop at the next ALIGN reloc for an alignment
920 power larger than the number of bytes we are deleting. */
925 irel = elf_section_data (sec)->relocs;
926 irelend = irel + sec->reloc_count;
927 for (; irel < irelend; irel++)
929 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_ALIGN
930 && irel->r_offset > addr
931 && count < (1 << irel->r_addend))
934 toaddr = irel->r_offset;
939 /* Actually delete the bytes. */
940 memmove (contents + addr, contents + addr + count,
941 (size_t) (toaddr - addr - count));
942 if (irelalign == NULL)
948 #define NOP_OPCODE (0x0009)
950 BFD_ASSERT ((count & 1) == 0);
951 for (i = 0; i < count; i += 2)
952 bfd_put_16 (abfd, (bfd_vma) NOP_OPCODE, contents + toaddr - count + i);
955 /* Adjust all the relocs. */
956 for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)
958 bfd_vma nraddr, stop;
961 int off, adjust, oinsn;
962 bfd_signed_vma voff = 0;
963 bfd_boolean overflow;
965 /* Get the new reloc address. */
966 nraddr = irel->r_offset;
967 if ((irel->r_offset > addr
968 && irel->r_offset < toaddr)
969 || (ELF32_R_TYPE (irel->r_info) == (int) R_SH_ALIGN
970 && irel->r_offset == toaddr))
973 /* See if this reloc was for the bytes we have deleted, in which
974 case we no longer care about it. Don't delete relocs which
975 represent addresses, though. */
976 if (irel->r_offset >= addr
977 && irel->r_offset < addr + count
978 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_ALIGN
979 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_CODE
980 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_DATA
981 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_LABEL)
982 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
985 /* If this is a PC relative reloc, see if the range it covers
986 includes the bytes we have deleted. */
987 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
996 start = irel->r_offset;
997 insn = bfd_get_16 (abfd, contents + nraddr);
1001 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
1004 start = stop = addr;
1008 /* If this reloc is against a symbol defined in this
1009 section, and the symbol will not be adjusted below, we
1010 must check the addend to see it will put the value in
1011 range to be adjusted, and hence must be changed. */
1012 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
1014 isym = isymbuf + ELF32_R_SYM (irel->r_info);
1015 if (isym->st_shndx == sec_shndx
1016 && (isym->st_value <= addr
1017 || isym->st_value >= toaddr))
1021 if (get_howto_table (abfd)[R_SH_DIR32].partial_inplace)
1023 val = bfd_get_32 (abfd, contents + nraddr);
1024 val += isym->st_value;
1025 if (val > addr && val < toaddr)
1026 bfd_put_32 (abfd, val - count, contents + nraddr);
1030 val = isym->st_value + irel->r_addend;
1031 if (val > addr && val < toaddr)
1032 irel->r_addend -= count;
1036 start = stop = addr;
1043 stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
1050 /* This has been made by previous relaxation. Since the
1051 relocation will be against an external symbol, the
1052 final relocation will just do the right thing. */
1053 start = stop = addr;
1059 stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
1061 /* The addend will be against the section symbol, thus
1062 for adjusting the addend, the relevant start is the
1063 start of the section.
1064 N.B. If we want to abandon in-place changes here and
1065 test directly using symbol + addend, we have to take into
1066 account that the addend has already been adjusted by -4. */
1067 if (stop > addr && stop < toaddr)
1068 irel->r_addend -= count;
1074 stop = start + 4 + off * 2;
1079 stop = (start & ~(bfd_vma) 3) + 4 + off * 4;
1085 /* These relocs types represent
1087 The r_addend field holds the difference between the reloc
1088 address and L1. That is the start of the reloc, and
1089 adding in the contents gives us the top. We must adjust
1090 both the r_offset field and the section contents.
1091 N.B. in gas / coff bfd, the elf bfd r_addend is called r_offset,
1092 and the elf bfd r_offset is called r_vaddr. */
1094 stop = irel->r_offset;
1095 start = (bfd_vma) ((bfd_signed_vma) stop - (long) irel->r_addend);
1099 && (stop <= addr || stop >= toaddr))
1100 irel->r_addend += count;
1101 else if (stop > addr
1103 && (start <= addr || start >= toaddr))
1104 irel->r_addend -= count;
1106 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_SWITCH16)
1107 voff = bfd_get_signed_16 (abfd, contents + nraddr);
1108 else if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_SWITCH8)
1109 voff = bfd_get_8 (abfd, contents + nraddr);
1111 voff = bfd_get_signed_32 (abfd, contents + nraddr);
1112 stop = (bfd_vma) ((bfd_signed_vma) start + voff);
1117 start = irel->r_offset;
1118 stop = (bfd_vma) ((bfd_signed_vma) start
1119 + (long) irel->r_addend
1126 && (stop <= addr || stop >= toaddr))
1128 else if (stop > addr
1130 && (start <= addr || start >= toaddr))
1139 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
1148 if ((oinsn & 0xff00) != (insn & 0xff00))
1150 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
1155 if ((oinsn & 0xf000) != (insn & 0xf000))
1157 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
1161 BFD_ASSERT (adjust == count || count >= 4);
1166 if ((irel->r_offset & 3) == 0)
1169 if ((oinsn & 0xff00) != (insn & 0xff00))
1171 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
1176 if (voff < 0 || voff >= 0xff)
1178 bfd_put_8 (abfd, voff, contents + nraddr);
1183 if (voff < - 0x8000 || voff >= 0x8000)
1185 bfd_put_signed_16 (abfd, (bfd_vma) voff, contents + nraddr);
1190 bfd_put_signed_32 (abfd, (bfd_vma) voff, contents + nraddr);
1194 irel->r_addend += adjust;
1201 /* xgettext:c-format */
1202 (_("%pB: %#" PRIx64 ": fatal: reloc overflow while relaxing"),
1203 abfd, (uint64_t) irel->r_offset);
1204 bfd_set_error (bfd_error_bad_value);
1209 irel->r_offset = nraddr;
1212 /* Look through all the other sections. If there contain any IMM32
1213 relocs against internal symbols which we are not going to adjust
1214 below, we may need to adjust the addends. */
1215 for (o = abfd->sections; o != NULL; o = o->next)
1217 Elf_Internal_Rela *internal_relocs;
1218 Elf_Internal_Rela *irelscan, *irelscanend;
1219 bfd_byte *ocontents;
1222 || (o->flags & SEC_RELOC) == 0
1223 || o->reloc_count == 0)
1226 /* We always cache the relocs. Perhaps, if info->keep_memory is
1227 FALSE, we should free them, if we are permitted to, when we
1228 leave sh_coff_relax_section. */
1229 internal_relocs = (_bfd_elf_link_read_relocs
1230 (abfd, o, NULL, (Elf_Internal_Rela *) NULL, TRUE));
1231 if (internal_relocs == NULL)
1235 irelscanend = internal_relocs + o->reloc_count;
1236 for (irelscan = internal_relocs; irelscan < irelscanend; irelscan++)
1238 /* Dwarf line numbers use R_SH_SWITCH32 relocs. */
1239 if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_SWITCH32)
1241 bfd_vma start, stop;
1242 bfd_signed_vma voff;
1244 if (ocontents == NULL)
1246 if (elf_section_data (o)->this_hdr.contents != NULL)
1247 ocontents = elf_section_data (o)->this_hdr.contents;
1250 /* We always cache the section contents.
1251 Perhaps, if info->keep_memory is FALSE, we
1252 should free them, if we are permitted to,
1253 when we leave sh_coff_relax_section. */
1254 if (!bfd_malloc_and_get_section (abfd, o, &ocontents))
1256 if (ocontents != NULL)
1261 elf_section_data (o)->this_hdr.contents = ocontents;
1265 stop = irelscan->r_offset;
1267 = (bfd_vma) ((bfd_signed_vma) stop - (long) irelscan->r_addend);
1269 /* STOP is in a different section, so it won't change. */
1270 if (start > addr && start < toaddr)
1271 irelscan->r_addend += count;
1273 voff = bfd_get_signed_32 (abfd, ocontents + irelscan->r_offset);
1274 stop = (bfd_vma) ((bfd_signed_vma) start + voff);
1278 && (stop <= addr || stop >= toaddr))
1279 bfd_put_signed_32 (abfd, (bfd_vma) voff + count,
1280 ocontents + irelscan->r_offset);
1281 else if (stop > addr
1283 && (start <= addr || start >= toaddr))
1284 bfd_put_signed_32 (abfd, (bfd_vma) voff - count,
1285 ocontents + irelscan->r_offset);
1288 if (ELF32_R_TYPE (irelscan->r_info) != (int) R_SH_DIR32)
1291 if (ELF32_R_SYM (irelscan->r_info) >= symtab_hdr->sh_info)
1295 isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
1296 if (isym->st_shndx == sec_shndx
1297 && (isym->st_value <= addr
1298 || isym->st_value >= toaddr))
1302 if (ocontents == NULL)
1304 if (elf_section_data (o)->this_hdr.contents != NULL)
1305 ocontents = elf_section_data (o)->this_hdr.contents;
1308 /* We always cache the section contents.
1309 Perhaps, if info->keep_memory is FALSE, we
1310 should free them, if we are permitted to,
1311 when we leave sh_coff_relax_section. */
1312 if (!bfd_malloc_and_get_section (abfd, o, &ocontents))
1314 if (ocontents != NULL)
1319 elf_section_data (o)->this_hdr.contents = ocontents;
1323 val = bfd_get_32 (abfd, ocontents + irelscan->r_offset);
1324 val += isym->st_value;
1325 if (val > addr && val < toaddr)
1326 bfd_put_32 (abfd, val - count,
1327 ocontents + irelscan->r_offset);
1332 /* Adjust the local symbols defined in this section. */
1333 isymend = isymbuf + symtab_hdr->sh_info;
1334 for (isym = isymbuf; isym < isymend; isym++)
1336 if (isym->st_shndx == sec_shndx
1337 && isym->st_value > addr
1338 && isym->st_value < toaddr)
1339 isym->st_value -= count;
1342 /* Now adjust the global symbols defined in this section. */
1343 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
1344 - symtab_hdr->sh_info);
1345 sym_hashes = elf_sym_hashes (abfd);
1346 end_hashes = sym_hashes + symcount;
1347 for (; sym_hashes < end_hashes; sym_hashes++)
1349 struct elf_link_hash_entry *sym_hash = *sym_hashes;
1350 if ((sym_hash->root.type == bfd_link_hash_defined
1351 || sym_hash->root.type == bfd_link_hash_defweak)
1352 && sym_hash->root.u.def.section == sec
1353 && sym_hash->root.u.def.value > addr
1354 && sym_hash->root.u.def.value < toaddr)
1356 sym_hash->root.u.def.value -= count;
1360 /* See if we can move the ALIGN reloc forward. We have adjusted
1361 r_offset for it already. */
1362 if (irelalign != NULL)
1364 bfd_vma alignto, alignaddr;
1366 alignto = BFD_ALIGN (toaddr, 1 << irelalign->r_addend);
1367 alignaddr = BFD_ALIGN (irelalign->r_offset,
1368 1 << irelalign->r_addend);
1369 if (alignto != alignaddr)
1371 /* Tail recursion. */
1372 return sh_elf_relax_delete_bytes (abfd, sec, alignaddr,
1373 (int) (alignto - alignaddr));
1380 /* Look for loads and stores which we can align to four byte
1381 boundaries. This is like sh_align_loads in coff-sh.c. */
1384 sh_elf_align_loads (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
1385 Elf_Internal_Rela *internal_relocs,
1386 bfd_byte *contents ATTRIBUTE_UNUSED,
1387 bfd_boolean *pswapped)
1389 Elf_Internal_Rela *irel, *irelend;
1390 bfd_vma *labels = NULL;
1391 bfd_vma *label, *label_end;
1396 irelend = internal_relocs + sec->reloc_count;
1398 /* Get all the addresses with labels on them. */
1399 amt = sec->reloc_count;
1400 amt *= sizeof (bfd_vma);
1401 labels = (bfd_vma *) bfd_malloc (amt);
1405 for (irel = internal_relocs; irel < irelend; irel++)
1407 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_LABEL)
1409 *label_end = irel->r_offset;
1414 /* Note that the assembler currently always outputs relocs in
1415 address order. If that ever changes, this code will need to sort
1416 the label values and the relocs. */
1420 for (irel = internal_relocs; irel < irelend; irel++)
1422 bfd_vma start, stop;
1424 if (ELF32_R_TYPE (irel->r_info) != (int) R_SH_CODE)
1427 start = irel->r_offset;
1429 for (irel++; irel < irelend; irel++)
1430 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_DATA)
1433 stop = irel->r_offset;
1437 if (! _bfd_sh_align_load_span (abfd, sec, contents, sh_elf_swap_insns,
1438 internal_relocs, &label,
1439 label_end, start, stop, pswapped))
1454 /* Swap two SH instructions. This is like sh_swap_insns in coff-sh.c. */
1457 sh_elf_swap_insns (bfd *abfd, asection *sec, void *relocs,
1458 bfd_byte *contents, bfd_vma addr)
1460 Elf_Internal_Rela *internal_relocs = (Elf_Internal_Rela *) relocs;
1461 unsigned short i1, i2;
1462 Elf_Internal_Rela *irel, *irelend;
1464 /* Swap the instructions themselves. */
1465 i1 = bfd_get_16 (abfd, contents + addr);
1466 i2 = bfd_get_16 (abfd, contents + addr + 2);
1467 bfd_put_16 (abfd, (bfd_vma) i2, contents + addr);
1468 bfd_put_16 (abfd, (bfd_vma) i1, contents + addr + 2);
1470 /* Adjust all reloc addresses. */
1471 irelend = internal_relocs + sec->reloc_count;
1472 for (irel = internal_relocs; irel < irelend; irel++)
1474 enum elf_sh_reloc_type type;
1477 /* There are a few special types of relocs that we don't want to
1478 adjust. These relocs do not apply to the instruction itself,
1479 but are only associated with the address. */
1480 type = (enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info);
1481 if (type == R_SH_ALIGN
1482 || type == R_SH_CODE
1483 || type == R_SH_DATA
1484 || type == R_SH_LABEL)
1487 /* If an R_SH_USES reloc points to one of the addresses being
1488 swapped, we must adjust it. It would be incorrect to do this
1489 for a jump, though, since we want to execute both
1490 instructions after the jump. (We have avoided swapping
1491 around a label, so the jump will not wind up executing an
1492 instruction it shouldn't). */
1493 if (type == R_SH_USES)
1497 off = irel->r_offset + 4 + irel->r_addend;
1499 irel->r_offset += 2;
1500 else if (off == addr + 2)
1501 irel->r_offset -= 2;
1504 if (irel->r_offset == addr)
1506 irel->r_offset += 2;
1509 else if (irel->r_offset == addr + 2)
1511 irel->r_offset -= 2;
1520 unsigned short insn, oinsn;
1521 bfd_boolean overflow;
1523 loc = contents + irel->r_offset;
1532 insn = bfd_get_16 (abfd, loc);
1535 if ((oinsn & 0xff00) != (insn & 0xff00))
1537 bfd_put_16 (abfd, (bfd_vma) insn, loc);
1541 insn = bfd_get_16 (abfd, loc);
1544 if ((oinsn & 0xf000) != (insn & 0xf000))
1546 bfd_put_16 (abfd, (bfd_vma) insn, loc);
1550 /* This reloc ignores the least significant 3 bits of
1551 the program counter before adding in the offset.
1552 This means that if ADDR is at an even address, the
1553 swap will not affect the offset. If ADDR is an at an
1554 odd address, then the instruction will be crossing a
1555 four byte boundary, and must be adjusted. */
1556 if ((addr & 3) != 0)
1558 insn = bfd_get_16 (abfd, loc);
1561 if ((oinsn & 0xff00) != (insn & 0xff00))
1563 bfd_put_16 (abfd, (bfd_vma) insn, loc);
1572 /* xgettext:c-format */
1573 (_("%pB: %#" PRIx64 ": fatal: reloc overflow while relaxing"),
1574 abfd, (uint64_t) irel->r_offset);
1575 bfd_set_error (bfd_error_bad_value);
1583 #endif /* defined SH64_ELF */
1585 /* Describes one of the various PLT styles. */
1587 struct elf_sh_plt_info
1589 /* The template for the first PLT entry, or NULL if there is no special
1591 const bfd_byte *plt0_entry;
1593 /* The size of PLT0_ENTRY in bytes, or 0 if PLT0_ENTRY is NULL. */
1594 bfd_vma plt0_entry_size;
1596 /* Index I is the offset into PLT0_ENTRY of a pointer to
1597 _GLOBAL_OFFSET_TABLE_ + I * 4. The value is MINUS_ONE
1598 if there is no such pointer. */
1599 bfd_vma plt0_got_fields[3];
1601 /* The template for a symbol's PLT entry. */
1602 const bfd_byte *symbol_entry;
1604 /* The size of SYMBOL_ENTRY in bytes. */
1605 bfd_vma symbol_entry_size;
1607 /* Byte offsets of fields in SYMBOL_ENTRY. Not all fields are used
1608 on all targets. The comments by each member indicate the value
1609 that the field must hold. */
1611 bfd_vma got_entry; /* the address of the symbol's .got.plt entry */
1612 bfd_vma plt; /* .plt (or a branch to .plt on VxWorks) */
1613 bfd_vma reloc_offset; /* the offset of the symbol's JMP_SLOT reloc */
1614 bfd_boolean got20; /* TRUE if got_entry points to a movi20
1615 instruction (instead of a constant pool
1619 /* The offset of the resolver stub from the start of SYMBOL_ENTRY. */
1620 bfd_vma symbol_resolve_offset;
1622 /* A different PLT layout which can be used for the first
1623 MAX_SHORT_PLT entries. It must share the same plt0. NULL in
1625 const struct elf_sh_plt_info *short_plt;
1628 #ifdef INCLUDE_SHMEDIA
1630 /* The size in bytes of an entry in the procedure linkage table. */
1632 #define ELF_PLT_ENTRY_SIZE 64
1634 /* First entry in an absolute procedure linkage table look like this. */
1636 static const bfd_byte elf_sh_plt0_entry_be[ELF_PLT_ENTRY_SIZE] =
1638 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 16, r17 */
1639 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
1640 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
1641 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
1642 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
1643 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
1644 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1645 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1646 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1647 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1648 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1649 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1650 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1651 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1652 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1653 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1656 static const bfd_byte elf_sh_plt0_entry_le[ELF_PLT_ENTRY_SIZE] =
1658 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */
1659 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
1660 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
1661 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
1662 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
1663 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
1664 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1665 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1666 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1667 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1668 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1669 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1670 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1671 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1672 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1673 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1676 /* Sebsequent entries in an absolute procedure linkage table look like
1679 static const bfd_byte elf_sh_plt_entry_be[ELF_PLT_ENTRY_SIZE] =
1681 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 16, r25 */
1682 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
1683 0x89, 0x90, 0x01, 0x90, /* ld.l r25, 0, r25 */
1684 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
1685 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
1686 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1687 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1688 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1689 0xcc, 0x00, 0x01, 0x90, /* movi .PLT0 >> 16, r25 */
1690 0xc8, 0x00, 0x01, 0x90, /* shori .PLT0 & 65535, r25 */
1691 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
1692 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
1693 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
1694 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
1695 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1696 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1699 static const bfd_byte elf_sh_plt_entry_le[ELF_PLT_ENTRY_SIZE] =
1701 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */
1702 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
1703 0x90, 0x01, 0x90, 0x89, /* ld.l r25, 0, r25 */
1704 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
1705 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
1706 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1707 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1708 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1709 0x90, 0x01, 0x00, 0xcc, /* movi .PLT0 >> 16, r25 */
1710 0x90, 0x01, 0x00, 0xc8, /* shori .PLT0 & 65535, r25 */
1711 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
1712 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
1713 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
1714 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
1715 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1716 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1719 /* Entries in a PIC procedure linkage table look like this. */
1721 static const bfd_byte elf_sh_pic_plt_entry_be[ELF_PLT_ENTRY_SIZE] =
1723 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */
1724 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
1725 0x40, 0xc2, 0x65, 0x90, /* ldx.l r12, r25, r25 */
1726 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
1727 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
1728 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1729 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1730 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1731 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */
1732 0x00, 0xc8, 0x45, 0x10, /* add.l r12, r17, r17 */
1733 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
1734 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
1735 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
1736 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
1737 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
1738 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
1741 static const bfd_byte elf_sh_pic_plt_entry_le[ELF_PLT_ENTRY_SIZE] =
1743 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */
1744 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
1745 0x90, 0x65, 0xc2, 0x40, /* ldx.l r12, r25, r25 */
1746 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
1747 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
1748 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1749 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1750 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1751 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */
1752 0x10, 0x45, 0xc8, 0x00, /* add.l r12, r17, r17 */
1753 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
1754 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
1755 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
1756 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
1757 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
1758 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
1761 static const struct elf_sh_plt_info elf_sh_plts[2][2] = {
1764 /* Big-endian non-PIC. */
1765 elf_sh_plt0_entry_be,
1767 { 0, MINUS_ONE, MINUS_ONE },
1768 elf_sh_plt_entry_be,
1770 { 0, 32, 48, FALSE },
1771 33, /* includes ISA encoding */
1775 /* Little-endian non-PIC. */
1776 elf_sh_plt0_entry_le,
1778 { 0, MINUS_ONE, MINUS_ONE },
1779 elf_sh_plt_entry_le,
1781 { 0, 32, 48, FALSE },
1782 33, /* includes ISA encoding */
1788 /* Big-endian PIC. */
1789 elf_sh_plt0_entry_be,
1791 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
1792 elf_sh_pic_plt_entry_be,
1794 { 0, MINUS_ONE, 52, FALSE },
1795 33, /* includes ISA encoding */
1799 /* Little-endian PIC. */
1800 elf_sh_plt0_entry_le,
1802 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
1803 elf_sh_pic_plt_entry_le,
1805 { 0, MINUS_ONE, 52, FALSE },
1806 33, /* includes ISA encoding */
1812 /* Return offset of the linker in PLT0 entry. */
1813 #define elf_sh_plt0_gotplt_offset(info) 0
1815 /* Install a 32-bit PLT field starting at ADDR, which occurs in OUTPUT_BFD.
1816 VALUE is the field's value and CODE_P is true if VALUE refers to code,
1819 On SH64, each 32-bit field is loaded by a movi/shori pair. */
1822 install_plt_field (bfd *output_bfd, bfd_boolean code_p,
1823 unsigned long value, bfd_byte *addr)
1826 bfd_put_32 (output_bfd,
1827 bfd_get_32 (output_bfd, addr)
1828 | ((value >> 6) & 0x3fffc00),
1830 bfd_put_32 (output_bfd,
1831 bfd_get_32 (output_bfd, addr + 4)
1832 | ((value << 10) & 0x3fffc00),
1836 /* Return the type of PLT associated with ABFD. PIC_P is true if
1837 the object is position-independent. */
1839 static const struct elf_sh_plt_info *
1840 get_plt_info (bfd *abfd ATTRIBUTE_UNUSED, bfd_boolean pic_p)
1842 return &elf_sh_plts[pic_p][!bfd_big_endian (abfd)];
1845 /* The size in bytes of an entry in the procedure linkage table. */
1847 #define ELF_PLT_ENTRY_SIZE 28
1849 /* First entry in an absolute procedure linkage table look like this. */
1851 /* Note - this code has been "optimised" not to use r2. r2 is used by
1852 GCC to return the address of large structures, so it should not be
1853 corrupted here. This does mean however, that this PLT does not conform
1854 to the SH PIC ABI. That spec says that r0 contains the type of the PLT
1855 and r2 contains the GOT id. This version stores the GOT id in r0 and
1856 ignores the type. Loaders can easily detect this difference however,
1857 since the type will always be 0 or 8, and the GOT ids will always be
1858 greater than or equal to 12. */
1859 static const bfd_byte elf_sh_plt0_entry_be[ELF_PLT_ENTRY_SIZE] =
1861 0xd0, 0x05, /* mov.l 2f,r0 */
1862 0x60, 0x02, /* mov.l @r0,r0 */
1863 0x2f, 0x06, /* mov.l r0,@-r15 */
1864 0xd0, 0x03, /* mov.l 1f,r0 */
1865 0x60, 0x02, /* mov.l @r0,r0 */
1866 0x40, 0x2b, /* jmp @r0 */
1867 0x60, 0xf6, /* mov.l @r15+,r0 */
1868 0x00, 0x09, /* nop */
1869 0x00, 0x09, /* nop */
1870 0x00, 0x09, /* nop */
1871 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
1872 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
1875 static const bfd_byte elf_sh_plt0_entry_le[ELF_PLT_ENTRY_SIZE] =
1877 0x05, 0xd0, /* mov.l 2f,r0 */
1878 0x02, 0x60, /* mov.l @r0,r0 */
1879 0x06, 0x2f, /* mov.l r0,@-r15 */
1880 0x03, 0xd0, /* mov.l 1f,r0 */
1881 0x02, 0x60, /* mov.l @r0,r0 */
1882 0x2b, 0x40, /* jmp @r0 */
1883 0xf6, 0x60, /* mov.l @r15+,r0 */
1884 0x09, 0x00, /* nop */
1885 0x09, 0x00, /* nop */
1886 0x09, 0x00, /* nop */
1887 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
1888 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
1891 /* Sebsequent entries in an absolute procedure linkage table look like
1894 static const bfd_byte elf_sh_plt_entry_be[ELF_PLT_ENTRY_SIZE] =
1896 0xd0, 0x04, /* mov.l 1f,r0 */
1897 0x60, 0x02, /* mov.l @(r0,r12),r0 */
1898 0xd1, 0x02, /* mov.l 0f,r1 */
1899 0x40, 0x2b, /* jmp @r0 */
1900 0x60, 0x13, /* mov r1,r0 */
1901 0xd1, 0x03, /* mov.l 2f,r1 */
1902 0x40, 0x2b, /* jmp @r0 */
1903 0x00, 0x09, /* nop */
1904 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
1905 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
1906 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
1909 static const bfd_byte elf_sh_plt_entry_le[ELF_PLT_ENTRY_SIZE] =
1911 0x04, 0xd0, /* mov.l 1f,r0 */
1912 0x02, 0x60, /* mov.l @r0,r0 */
1913 0x02, 0xd1, /* mov.l 0f,r1 */
1914 0x2b, 0x40, /* jmp @r0 */
1915 0x13, 0x60, /* mov r1,r0 */
1916 0x03, 0xd1, /* mov.l 2f,r1 */
1917 0x2b, 0x40, /* jmp @r0 */
1918 0x09, 0x00, /* nop */
1919 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
1920 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
1921 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
1924 /* Entries in a PIC procedure linkage table look like this. */
1926 static const bfd_byte elf_sh_pic_plt_entry_be[ELF_PLT_ENTRY_SIZE] =
1928 0xd0, 0x04, /* mov.l 1f,r0 */
1929 0x00, 0xce, /* mov.l @(r0,r12),r0 */
1930 0x40, 0x2b, /* jmp @r0 */
1931 0x00, 0x09, /* nop */
1932 0x50, 0xc2, /* mov.l @(8,r12),r0 */
1933 0xd1, 0x03, /* mov.l 2f,r1 */
1934 0x40, 0x2b, /* jmp @r0 */
1935 0x50, 0xc1, /* mov.l @(4,r12),r0 */
1936 0x00, 0x09, /* nop */
1937 0x00, 0x09, /* nop */
1938 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
1939 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
1942 static const bfd_byte elf_sh_pic_plt_entry_le[ELF_PLT_ENTRY_SIZE] =
1944 0x04, 0xd0, /* mov.l 1f,r0 */
1945 0xce, 0x00, /* mov.l @(r0,r12),r0 */
1946 0x2b, 0x40, /* jmp @r0 */
1947 0x09, 0x00, /* nop */
1948 0xc2, 0x50, /* mov.l @(8,r12),r0 */
1949 0x03, 0xd1, /* mov.l 2f,r1 */
1950 0x2b, 0x40, /* jmp @r0 */
1951 0xc1, 0x50, /* mov.l @(4,r12),r0 */
1952 0x09, 0x00, /* nop */
1953 0x09, 0x00, /* nop */
1954 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
1955 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
1958 static const struct elf_sh_plt_info elf_sh_plts[2][2] = {
1961 /* Big-endian non-PIC. */
1962 elf_sh_plt0_entry_be,
1964 { MINUS_ONE, 24, 20 },
1965 elf_sh_plt_entry_be,
1967 { 20, 16, 24, FALSE },
1972 /* Little-endian non-PIC. */
1973 elf_sh_plt0_entry_le,
1975 { MINUS_ONE, 24, 20 },
1976 elf_sh_plt_entry_le,
1978 { 20, 16, 24, FALSE },
1985 /* Big-endian PIC. */
1986 elf_sh_plt0_entry_be,
1988 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
1989 elf_sh_pic_plt_entry_be,
1991 { 20, MINUS_ONE, 24, FALSE },
1996 /* Little-endian PIC. */
1997 elf_sh_plt0_entry_le,
1999 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2000 elf_sh_pic_plt_entry_le,
2002 { 20, MINUS_ONE, 24, FALSE },
2009 #define VXWORKS_PLT_HEADER_SIZE 12
2010 #define VXWORKS_PLT_ENTRY_SIZE 24
2012 static const bfd_byte vxworks_sh_plt0_entry_be[VXWORKS_PLT_HEADER_SIZE] =
2014 0xd1, 0x01, /* mov.l @(8,pc),r1 */
2015 0x61, 0x12, /* mov.l @r1,r1 */
2016 0x41, 0x2b, /* jmp @r1 */
2017 0x00, 0x09, /* nop */
2018 0, 0, 0, 0 /* 0: replaced with _GLOBAL_OFFSET_TABLE+8. */
2021 static const bfd_byte vxworks_sh_plt0_entry_le[VXWORKS_PLT_HEADER_SIZE] =
2023 0x01, 0xd1, /* mov.l @(8,pc),r1 */
2024 0x12, 0x61, /* mov.l @r1,r1 */
2025 0x2b, 0x41, /* jmp @r1 */
2026 0x09, 0x00, /* nop */
2027 0, 0, 0, 0 /* 0: replaced with _GLOBAL_OFFSET_TABLE+8. */
2030 static const bfd_byte vxworks_sh_plt_entry_be[VXWORKS_PLT_ENTRY_SIZE] =
2032 0xd0, 0x01, /* mov.l @(8,pc),r0 */
2033 0x60, 0x02, /* mov.l @r0,r0 */
2034 0x40, 0x2b, /* jmp @r0 */
2035 0x00, 0x09, /* nop */
2036 0, 0, 0, 0, /* 0: replaced with address of this symbol in .got. */
2037 0xd0, 0x01, /* mov.l @(8,pc),r0 */
2038 0xa0, 0x00, /* bra PLT (We need to fix the offset.) */
2039 0x00, 0x09, /* nop */
2040 0x00, 0x09, /* nop */
2041 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2044 static const bfd_byte vxworks_sh_plt_entry_le[VXWORKS_PLT_ENTRY_SIZE] =
2046 0x01, 0xd0, /* mov.l @(8,pc),r0 */
2047 0x02, 0x60, /* mov.l @r0,r0 */
2048 0x2b, 0x40, /* jmp @r0 */
2049 0x09, 0x00, /* nop */
2050 0, 0, 0, 0, /* 0: replaced with address of this symbol in .got. */
2051 0x01, 0xd0, /* mov.l @(8,pc),r0 */
2052 0x00, 0xa0, /* bra PLT (We need to fix the offset.) */
2053 0x09, 0x00, /* nop */
2054 0x09, 0x00, /* nop */
2055 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2058 static const bfd_byte vxworks_sh_pic_plt_entry_be[VXWORKS_PLT_ENTRY_SIZE] =
2060 0xd0, 0x01, /* mov.l @(8,pc),r0 */
2061 0x00, 0xce, /* mov.l @(r0,r12),r0 */
2062 0x40, 0x2b, /* jmp @r0 */
2063 0x00, 0x09, /* nop */
2064 0, 0, 0, 0, /* 0: replaced with offset of this symbol in .got. */
2065 0xd0, 0x01, /* mov.l @(8,pc),r0 */
2066 0x51, 0xc2, /* mov.l @(8,r12),r1 */
2067 0x41, 0x2b, /* jmp @r1 */
2068 0x00, 0x09, /* nop */
2069 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2072 static const bfd_byte vxworks_sh_pic_plt_entry_le[VXWORKS_PLT_ENTRY_SIZE] =
2074 0x01, 0xd0, /* mov.l @(8,pc),r0 */
2075 0xce, 0x00, /* mov.l @(r0,r12),r0 */
2076 0x2b, 0x40, /* jmp @r0 */
2077 0x09, 0x00, /* nop */
2078 0, 0, 0, 0, /* 0: replaced with offset of this symbol in .got. */
2079 0x01, 0xd0, /* mov.l @(8,pc),r0 */
2080 0xc2, 0x51, /* mov.l @(8,r12),r1 */
2081 0x2b, 0x41, /* jmp @r1 */
2082 0x09, 0x00, /* nop */
2083 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2086 static const struct elf_sh_plt_info vxworks_sh_plts[2][2] = {
2089 /* Big-endian non-PIC. */
2090 vxworks_sh_plt0_entry_be,
2091 VXWORKS_PLT_HEADER_SIZE,
2092 { MINUS_ONE, MINUS_ONE, 8 },
2093 vxworks_sh_plt_entry_be,
2094 VXWORKS_PLT_ENTRY_SIZE,
2095 { 8, 14, 20, FALSE },
2100 /* Little-endian non-PIC. */
2101 vxworks_sh_plt0_entry_le,
2102 VXWORKS_PLT_HEADER_SIZE,
2103 { MINUS_ONE, MINUS_ONE, 8 },
2104 vxworks_sh_plt_entry_le,
2105 VXWORKS_PLT_ENTRY_SIZE,
2106 { 8, 14, 20, FALSE },
2113 /* Big-endian PIC. */
2116 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2117 vxworks_sh_pic_plt_entry_be,
2118 VXWORKS_PLT_ENTRY_SIZE,
2119 { 8, MINUS_ONE, 20, FALSE },
2124 /* Little-endian PIC. */
2127 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2128 vxworks_sh_pic_plt_entry_le,
2129 VXWORKS_PLT_ENTRY_SIZE,
2130 { 8, MINUS_ONE, 20, FALSE },
2137 /* FDPIC PLT entries. Two unimplemented optimizations for lazy
2138 binding are to omit the lazy binding stub when linking with -z now
2139 and to move lazy binding stubs into a separate region for better
2142 #define FDPIC_PLT_ENTRY_SIZE 28
2143 #define FDPIC_PLT_LAZY_OFFSET 20
2145 /* FIXME: The lazy binding stub requires a plt0 - which may need to be
2146 duplicated if it is out of range, or which can be inlined. So
2147 right now it is always inlined, which wastes a word per stub. It
2148 might be easier to handle the duplication if we put the lazy
2149 stubs separately. */
2151 static const bfd_byte fdpic_sh_plt_entry_be[FDPIC_PLT_ENTRY_SIZE] =
2153 0xd0, 0x02, /* mov.l @(12,pc),r0 */
2154 0x01, 0xce, /* mov.l @(r0,r12),r1 */
2155 0x70, 0x04, /* add #4, r0 */
2156 0x41, 0x2b, /* jmp @r1 */
2157 0x0c, 0xce, /* mov.l @(r0,r12),r12 */
2158 0x00, 0x09, /* nop */
2159 0, 0, 0, 0, /* 0: replaced with offset of this symbol's funcdesc */
2160 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2161 0x60, 0xc2, /* mov.l @r12,r0 */
2162 0x40, 0x2b, /* jmp @r0 */
2163 0x53, 0xc1, /* mov.l @(4,r12),r3 */
2164 0x00, 0x09, /* nop */
2167 static const bfd_byte fdpic_sh_plt_entry_le[FDPIC_PLT_ENTRY_SIZE] =
2169 0x02, 0xd0, /* mov.l @(12,pc),r0 */
2170 0xce, 0x01, /* mov.l @(r0,r12),r1 */
2171 0x04, 0x70, /* add #4, r0 */
2172 0x2b, 0x41, /* jmp @r1 */
2173 0xce, 0x0c, /* mov.l @(r0,r12),r12 */
2174 0x09, 0x00, /* nop */
2175 0, 0, 0, 0, /* 0: replaced with offset of this symbol's funcdesc */
2176 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2177 0xc2, 0x60, /* mov.l @r12,r0 */
2178 0x2b, 0x40, /* jmp @r0 */
2179 0xc1, 0x53, /* mov.l @(4,r12),r3 */
2180 0x09, 0x00, /* nop */
2183 static const struct elf_sh_plt_info fdpic_sh_plts[2] = {
2185 /* Big-endian PIC. */
2188 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2189 fdpic_sh_plt_entry_be,
2190 FDPIC_PLT_ENTRY_SIZE,
2191 { 12, MINUS_ONE, 16, FALSE },
2192 FDPIC_PLT_LAZY_OFFSET,
2196 /* Little-endian PIC. */
2199 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2200 fdpic_sh_plt_entry_le,
2201 FDPIC_PLT_ENTRY_SIZE,
2202 { 12, MINUS_ONE, 16, FALSE },
2203 FDPIC_PLT_LAZY_OFFSET,
2208 /* On SH2A, we can use the movi20 instruction to generate shorter PLT
2209 entries for the first 64K slots. We use the normal FDPIC PLT entry
2210 past that point; we could also use movi20s, which might be faster,
2211 but would not be any smaller. */
2213 #define FDPIC_SH2A_PLT_ENTRY_SIZE 24
2214 #define FDPIC_SH2A_PLT_LAZY_OFFSET 16
2216 static const bfd_byte fdpic_sh2a_plt_entry_be[FDPIC_SH2A_PLT_ENTRY_SIZE] =
2218 0, 0, 0, 0, /* movi20 #gotofffuncdesc,r0 */
2219 0x01, 0xce, /* mov.l @(r0,r12),r1 */
2220 0x70, 0x04, /* add #4, r0 */
2221 0x41, 0x2b, /* jmp @r1 */
2222 0x0c, 0xce, /* mov.l @(r0,r12),r12 */
2223 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2224 0x60, 0xc2, /* mov.l @r12,r0 */
2225 0x40, 0x2b, /* jmp @r0 */
2226 0x53, 0xc1, /* mov.l @(4,r12),r3 */
2227 0x00, 0x09, /* nop */
2230 static const bfd_byte fdpic_sh2a_plt_entry_le[FDPIC_SH2A_PLT_ENTRY_SIZE] =
2232 0, 0, 0, 0, /* movi20 #gotofffuncdesc,r0 */
2233 0xce, 0x01, /* mov.l @(r0,r12),r1 */
2234 0x04, 0x70, /* add #4, r0 */
2235 0x2b, 0x41, /* jmp @r1 */
2236 0xce, 0x0c, /* mov.l @(r0,r12),r12 */
2237 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2238 0xc2, 0x60, /* mov.l @r12,r0 */
2239 0x2b, 0x40, /* jmp @r0 */
2240 0xc1, 0x53, /* mov.l @(4,r12),r3 */
2241 0x09, 0x00, /* nop */
2244 static const struct elf_sh_plt_info fdpic_sh2a_short_plt_be = {
2245 /* Big-endian FDPIC, max index 64K. */
2248 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2249 fdpic_sh2a_plt_entry_be,
2250 FDPIC_SH2A_PLT_ENTRY_SIZE,
2251 { 0, MINUS_ONE, 12, TRUE },
2252 FDPIC_SH2A_PLT_LAZY_OFFSET,
2256 static const struct elf_sh_plt_info fdpic_sh2a_short_plt_le = {
2257 /* Little-endian FDPIC, max index 64K. */
2260 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2261 fdpic_sh2a_plt_entry_le,
2262 FDPIC_SH2A_PLT_ENTRY_SIZE,
2263 { 0, MINUS_ONE, 12, TRUE },
2264 FDPIC_SH2A_PLT_LAZY_OFFSET,
2268 static const struct elf_sh_plt_info fdpic_sh2a_plts[2] = {
2270 /* Big-endian PIC. */
2273 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2274 fdpic_sh_plt_entry_be,
2275 FDPIC_PLT_ENTRY_SIZE,
2276 { 12, MINUS_ONE, 16, FALSE },
2277 FDPIC_PLT_LAZY_OFFSET,
2278 &fdpic_sh2a_short_plt_be
2281 /* Little-endian PIC. */
2284 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2285 fdpic_sh_plt_entry_le,
2286 FDPIC_PLT_ENTRY_SIZE,
2287 { 12, MINUS_ONE, 16, FALSE },
2288 FDPIC_PLT_LAZY_OFFSET,
2289 &fdpic_sh2a_short_plt_le
2293 /* Return the type of PLT associated with ABFD. PIC_P is true if
2294 the object is position-independent. */
2296 static const struct elf_sh_plt_info *
2297 get_plt_info (bfd *abfd, bfd_boolean pic_p)
2299 if (fdpic_object_p (abfd))
2301 /* If any input file requires SH2A we can use a shorter PLT
2303 if (sh_get_arch_from_bfd_mach (bfd_get_mach (abfd)) & arch_sh2a_base)
2304 return &fdpic_sh2a_plts[!bfd_big_endian (abfd)];
2306 return &fdpic_sh_plts[!bfd_big_endian (abfd)];
2308 if (vxworks_object_p (abfd))
2309 return &vxworks_sh_plts[pic_p][!bfd_big_endian (abfd)];
2310 return &elf_sh_plts[pic_p][!bfd_big_endian (abfd)];
2313 /* Install a 32-bit PLT field starting at ADDR, which occurs in OUTPUT_BFD.
2314 VALUE is the field's value and CODE_P is true if VALUE refers to code,
2318 install_plt_field (bfd *output_bfd, bfd_boolean code_p ATTRIBUTE_UNUSED,
2319 unsigned long value, bfd_byte *addr)
2321 bfd_put_32 (output_bfd, value, addr);
2325 /* The number of PLT entries which can use a shorter PLT, if any.
2326 Currently always 64K, since only SH-2A FDPIC uses this; a
2327 20-bit movi20 can address that many function descriptors below
2328 _GLOBAL_OFFSET_TABLE_. */
2329 #define MAX_SHORT_PLT 65536
2331 /* Return the index of the PLT entry at byte offset OFFSET. */
2334 get_plt_index (const struct elf_sh_plt_info *info, bfd_vma offset)
2336 bfd_vma plt_index = 0;
2338 offset -= info->plt0_entry_size;
2339 if (info->short_plt != NULL)
2341 if (offset > MAX_SHORT_PLT * info->short_plt->symbol_entry_size)
2343 plt_index = MAX_SHORT_PLT;
2344 offset -= MAX_SHORT_PLT * info->short_plt->symbol_entry_size;
2347 info = info->short_plt;
2349 return plt_index + offset / info->symbol_entry_size;
2352 /* Do the inverse operation. */
2355 get_plt_offset (const struct elf_sh_plt_info *info, bfd_vma plt_index)
2359 if (info->short_plt != NULL)
2361 if (plt_index > MAX_SHORT_PLT)
2363 offset = MAX_SHORT_PLT * info->short_plt->symbol_entry_size;
2364 plt_index -= MAX_SHORT_PLT;
2367 info = info->short_plt;
2369 return (offset + info->plt0_entry_size
2370 + (plt_index * info->symbol_entry_size));
2375 bfd_signed_vma refcount;
2379 /* sh ELF linker hash entry. */
2381 struct elf_sh_link_hash_entry
2383 struct elf_link_hash_entry root;
2385 #ifdef INCLUDE_SHMEDIA
2388 bfd_signed_vma refcount;
2393 /* Track dynamic relocs copied for this symbol. */
2394 struct elf_dyn_relocs *dyn_relocs;
2396 bfd_signed_vma gotplt_refcount;
2398 /* A local function descriptor, for FDPIC. The refcount counts
2399 R_SH_FUNCDESC, R_SH_GOTOFFFUNCDESC, and R_SH_GOTOFFFUNCDESC20
2400 relocations; the PLT and GOT entry are accounted
2401 for separately. After adjust_dynamic_symbol, the offset is
2402 MINUS_ONE if there is no local descriptor (dynamic linker
2403 managed and no PLT entry, or undefined weak non-dynamic).
2404 During check_relocs we do not yet know whether the local
2405 descriptor will be canonical. */
2406 union gotref funcdesc;
2408 /* How many of the above refcounted relocations were R_SH_FUNCDESC,
2409 and thus require fixups or relocations. */
2410 bfd_signed_vma abs_funcdesc_refcount;
2413 GOT_UNKNOWN = 0, GOT_NORMAL, GOT_TLS_GD, GOT_TLS_IE, GOT_FUNCDESC
2417 #define sh_elf_hash_entry(ent) ((struct elf_sh_link_hash_entry *)(ent))
2419 struct sh_elf_obj_tdata
2421 struct elf_obj_tdata root;
2423 /* got_type for each local got entry. */
2424 char *local_got_type;
2426 /* Function descriptor refcount and offset for each local symbol. */
2427 union gotref *local_funcdesc;
2430 #define sh_elf_tdata(abfd) \
2431 ((struct sh_elf_obj_tdata *) (abfd)->tdata.any)
2433 #define sh_elf_local_got_type(abfd) \
2434 (sh_elf_tdata (abfd)->local_got_type)
2436 #define sh_elf_local_funcdesc(abfd) \
2437 (sh_elf_tdata (abfd)->local_funcdesc)
2439 #define is_sh_elf(bfd) \
2440 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2441 && elf_tdata (bfd) != NULL \
2442 && elf_object_id (bfd) == SH_ELF_DATA)
2444 /* Override the generic function because we need to store sh_elf_obj_tdata
2445 as the specific tdata. */
2448 sh_elf_mkobject (bfd *abfd)
2450 return bfd_elf_allocate_object (abfd, sizeof (struct sh_elf_obj_tdata),
2454 /* sh ELF linker hash table. */
2456 struct elf_sh_link_hash_table
2458 struct elf_link_hash_table root;
2460 /* Short-cuts to get to dynamic linker sections. */
2463 asection *sfuncdesc;
2464 asection *srelfuncdesc;
2467 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
2470 /* Small local sym cache. */
2471 struct sym_cache sym_cache;
2473 /* A counter or offset to track a TLS got entry. */
2476 bfd_signed_vma refcount;
2480 /* The type of PLT to use. */
2481 const struct elf_sh_plt_info *plt_info;
2483 /* True if the target system is VxWorks. */
2484 bfd_boolean vxworks_p;
2486 /* True if the target system uses FDPIC. */
2487 bfd_boolean fdpic_p;
2490 /* Traverse an sh ELF linker hash table. */
2492 #define sh_elf_link_hash_traverse(table, func, info) \
2493 (elf_link_hash_traverse \
2495 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
2498 /* Get the sh ELF linker hash table from a link_info structure. */
2500 #define sh_elf_hash_table(p) \
2501 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
2502 == SH_ELF_DATA ? ((struct elf_sh_link_hash_table *) ((p)->hash)) : NULL)
2504 /* Create an entry in an sh ELF linker hash table. */
2506 static struct bfd_hash_entry *
2507 sh_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
2508 struct bfd_hash_table *table,
2511 struct elf_sh_link_hash_entry *ret =
2512 (struct elf_sh_link_hash_entry *) entry;
2514 /* Allocate the structure if it has not already been allocated by a
2516 if (ret == (struct elf_sh_link_hash_entry *) NULL)
2517 ret = ((struct elf_sh_link_hash_entry *)
2518 bfd_hash_allocate (table,
2519 sizeof (struct elf_sh_link_hash_entry)));
2520 if (ret == (struct elf_sh_link_hash_entry *) NULL)
2521 return (struct bfd_hash_entry *) ret;
2523 /* Call the allocation method of the superclass. */
2524 ret = ((struct elf_sh_link_hash_entry *)
2525 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2527 if (ret != (struct elf_sh_link_hash_entry *) NULL)
2529 ret->dyn_relocs = NULL;
2530 ret->gotplt_refcount = 0;
2531 #ifdef INCLUDE_SHMEDIA
2532 ret->datalabel_got.refcount = ret->root.got.refcount;
2534 ret->funcdesc.refcount = 0;
2535 ret->abs_funcdesc_refcount = 0;
2536 ret->got_type = GOT_UNKNOWN;
2539 return (struct bfd_hash_entry *) ret;
2542 /* Create an sh ELF linker hash table. */
2544 static struct bfd_link_hash_table *
2545 sh_elf_link_hash_table_create (bfd *abfd)
2547 struct elf_sh_link_hash_table *ret;
2548 bfd_size_type amt = sizeof (struct elf_sh_link_hash_table);
2550 ret = (struct elf_sh_link_hash_table *) bfd_zmalloc (amt);
2551 if (ret == (struct elf_sh_link_hash_table *) NULL)
2554 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
2555 sh_elf_link_hash_newfunc,
2556 sizeof (struct elf_sh_link_hash_entry),
2563 ret->vxworks_p = vxworks_object_p (abfd);
2564 ret->fdpic_p = fdpic_object_p (abfd);
2566 return &ret->root.root;
2570 sh_elf_omit_section_dynsym (bfd *output_bfd ATTRIBUTE_UNUSED,
2571 struct bfd_link_info *info, asection *p)
2573 struct elf_sh_link_hash_table *htab = sh_elf_hash_table (info);
2575 /* Non-FDPIC binaries do not need dynamic symbols for sections. */
2579 /* We need dynamic symbols for every section, since segments can
2580 relocate independently. */
2581 switch (elf_section_data (p)->this_hdr.sh_type)
2585 /* If sh_type is yet undecided, assume it could be
2586 SHT_PROGBITS/SHT_NOBITS. */
2590 /* There shouldn't be section relative relocations
2591 against any other section. */
2597 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
2598 shortcuts to them in our hash table. */
2601 create_got_section (bfd *dynobj, struct bfd_link_info *info)
2603 struct elf_sh_link_hash_table *htab;
2605 if (! _bfd_elf_create_got_section (dynobj, info))
2608 htab = sh_elf_hash_table (info);
2612 htab->sfuncdesc = bfd_make_section_anyway_with_flags (dynobj, ".got.funcdesc",
2613 (SEC_ALLOC | SEC_LOAD
2616 | SEC_LINKER_CREATED));
2617 if (htab->sfuncdesc == NULL
2618 || ! bfd_set_section_alignment (dynobj, htab->sfuncdesc, 2))
2621 htab->srelfuncdesc = bfd_make_section_anyway_with_flags (dynobj,
2622 ".rela.got.funcdesc",
2623 (SEC_ALLOC | SEC_LOAD
2626 | SEC_LINKER_CREATED
2628 if (htab->srelfuncdesc == NULL
2629 || ! bfd_set_section_alignment (dynobj, htab->srelfuncdesc, 2))
2632 /* Also create .rofixup. */
2633 htab->srofixup = bfd_make_section_anyway_with_flags (dynobj, ".rofixup",
2634 (SEC_ALLOC | SEC_LOAD
2637 | SEC_LINKER_CREATED
2639 if (htab->srofixup == NULL
2640 || ! bfd_set_section_alignment (dynobj, htab->srofixup, 2))
2646 /* Create dynamic sections when linking against a dynamic object. */
2649 sh_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
2651 struct elf_sh_link_hash_table *htab;
2652 flagword flags, pltflags;
2654 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
2657 switch (bed->s->arch_size)
2668 bfd_set_error (bfd_error_bad_value);
2672 htab = sh_elf_hash_table (info);
2676 if (htab->root.dynamic_sections_created)
2679 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
2680 .rel[a].bss sections. */
2682 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2683 | SEC_LINKER_CREATED);
2686 pltflags |= SEC_CODE;
2687 if (bed->plt_not_loaded)
2688 pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
2689 if (bed->plt_readonly)
2690 pltflags |= SEC_READONLY;
2692 s = bfd_make_section_anyway_with_flags (abfd, ".plt", pltflags);
2693 htab->root.splt = s;
2695 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
2698 if (bed->want_plt_sym)
2700 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
2702 struct elf_link_hash_entry *h;
2703 struct bfd_link_hash_entry *bh = NULL;
2705 if (! (_bfd_generic_link_add_one_symbol
2706 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
2707 (bfd_vma) 0, (const char *) NULL, FALSE,
2708 get_elf_backend_data (abfd)->collect, &bh)))
2711 h = (struct elf_link_hash_entry *) bh;
2713 h->type = STT_OBJECT;
2714 htab->root.hplt = h;
2716 if (bfd_link_pic (info)
2717 && ! bfd_elf_link_record_dynamic_symbol (info, h))
2721 s = bfd_make_section_anyway_with_flags (abfd,
2722 bed->default_use_rela_p
2723 ? ".rela.plt" : ".rel.plt",
2724 flags | SEC_READONLY);
2725 htab->root.srelplt = s;
2727 || ! bfd_set_section_alignment (abfd, s, ptralign))
2730 if (htab->root.sgot == NULL
2731 && !create_got_section (abfd, info))
2734 if (bed->want_dynbss)
2736 /* The .dynbss section is a place to put symbols which are defined
2737 by dynamic objects, are referenced by regular objects, and are
2738 not functions. We must allocate space for them in the process
2739 image and use a R_*_COPY reloc to tell the dynamic linker to
2740 initialize them at run time. The linker script puts the .dynbss
2741 section into the .bss section of the final image. */
2742 s = bfd_make_section_anyway_with_flags (abfd, ".dynbss",
2743 SEC_ALLOC | SEC_LINKER_CREATED);
2748 /* The .rel[a].bss section holds copy relocs. This section is not
2749 normally needed. We need to create it here, though, so that the
2750 linker will map it to an output section. We can't just create it
2751 only if we need it, because we will not know whether we need it
2752 until we have seen all the input files, and the first time the
2753 main linker code calls BFD after examining all the input files
2754 (size_dynamic_sections) the input sections have already been
2755 mapped to the output sections. If the section turns out not to
2756 be needed, we can discard it later. We will never need this
2757 section when generating a shared object, since they do not use
2759 if (! bfd_link_pic (info))
2761 s = bfd_make_section_anyway_with_flags (abfd,
2762 (bed->default_use_rela_p
2763 ? ".rela.bss" : ".rel.bss"),
2764 flags | SEC_READONLY);
2767 || ! bfd_set_section_alignment (abfd, s, ptralign))
2772 if (htab->vxworks_p)
2774 if (!elf_vxworks_create_dynamic_sections (abfd, info, &htab->srelplt2))
2781 /* Find dynamic relocs for H that apply to read-only sections. */
2784 readonly_dynrelocs (struct elf_link_hash_entry *h)
2786 struct elf_dyn_relocs *p;
2788 for (p = sh_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
2790 asection *s = p->sec->output_section;
2792 if (s != NULL && (s->flags & SEC_READONLY) != 0)
2798 /* Adjust a symbol defined by a dynamic object and referenced by a
2799 regular object. The current definition is in some section of the
2800 dynamic object, but we're not including those sections. We have to
2801 change the definition to something the rest of the link can
2805 sh_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
2806 struct elf_link_hash_entry *h)
2808 struct elf_sh_link_hash_table *htab;
2811 htab = sh_elf_hash_table (info);
2815 /* Make sure we know what is going on here. */
2816 BFD_ASSERT (htab->root.dynobj != NULL
2821 && !h->def_regular)));
2823 /* If this is a function, put it in the procedure linkage table. We
2824 will fill in the contents of the procedure linkage table later,
2825 when we know the address of the .got section. */
2826 if (h->type == STT_FUNC
2829 if (h->plt.refcount <= 0
2830 || SYMBOL_CALLS_LOCAL (info, h)
2831 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
2832 && h->root.type == bfd_link_hash_undefweak))
2834 /* This case can occur if we saw a PLT reloc in an input
2835 file, but the symbol was never referred to by a dynamic
2836 object. In such a case, we don't actually need to build
2837 a procedure linkage table, and we can just do a REL32
2839 h->plt.offset = (bfd_vma) -1;
2846 h->plt.offset = (bfd_vma) -1;
2848 /* If this is a weak symbol, and there is a real definition, the
2849 processor independent code will have arranged for us to see the
2850 real definition first, and we can just use the same value. */
2851 if (h->is_weakalias)
2853 struct elf_link_hash_entry *def = weakdef (h);
2854 BFD_ASSERT (def->root.type == bfd_link_hash_defined);
2855 h->root.u.def.section = def->root.u.def.section;
2856 h->root.u.def.value = def->root.u.def.value;
2857 if (info->nocopyreloc)
2858 h->non_got_ref = def->non_got_ref;
2862 /* This is a reference to a symbol defined by a dynamic object which
2863 is not a function. */
2865 /* If we are creating a shared library, we must presume that the
2866 only references to the symbol are via the global offset table.
2867 For such cases we need not do anything here; the relocations will
2868 be handled correctly by relocate_section. */
2869 if (bfd_link_pic (info))
2872 /* If there are no references to this symbol that do not use the
2873 GOT, we don't need to generate a copy reloc. */
2874 if (!h->non_got_ref)
2877 /* If -z nocopyreloc was given, we won't generate them either. */
2878 if (0 && info->nocopyreloc)
2884 /* If we don't find any dynamic relocs in read-only sections, then
2885 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2886 if (0 && !readonly_dynrelocs (h))
2892 /* We must allocate the symbol in our .dynbss section, which will
2893 become part of the .bss section of the executable. There will be
2894 an entry for this symbol in the .dynsym section. The dynamic
2895 object will contain position independent code, so all references
2896 from the dynamic object to this symbol will go through the global
2897 offset table. The dynamic linker will use the .dynsym entry to
2898 determine the address it must put in the global offset table, so
2899 both the dynamic object and the regular object will refer to the
2900 same memory location for the variable. */
2903 BFD_ASSERT (s != NULL);
2905 /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
2906 copy the initial value out of the dynamic object and into the
2907 runtime process image. We need to remember the offset into the
2908 .rela.bss section we are going to use. */
2909 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
2913 srel = htab->srelbss;
2914 BFD_ASSERT (srel != NULL);
2915 srel->size += sizeof (Elf32_External_Rela);
2919 return _bfd_elf_adjust_dynamic_copy (info, h, s);
2922 /* Allocate space in .plt, .got and associated reloc sections for
2926 allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
2928 struct bfd_link_info *info;
2929 struct elf_sh_link_hash_table *htab;
2930 struct elf_sh_link_hash_entry *eh;
2931 struct elf_dyn_relocs *p;
2933 if (h->root.type == bfd_link_hash_indirect)
2936 info = (struct bfd_link_info *) inf;
2937 htab = sh_elf_hash_table (info);
2941 eh = (struct elf_sh_link_hash_entry *) h;
2942 if ((h->got.refcount > 0
2944 && eh->gotplt_refcount > 0)
2946 /* The symbol has been forced local, or we have some direct got refs,
2947 so treat all the gotplt refs as got refs. */
2948 h->got.refcount += eh->gotplt_refcount;
2949 if (h->plt.refcount >= eh->gotplt_refcount)
2950 h->plt.refcount -= eh->gotplt_refcount;
2953 if (htab->root.dynamic_sections_created
2954 && h->plt.refcount > 0
2955 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2956 || h->root.type != bfd_link_hash_undefweak))
2958 /* Make sure this symbol is output as a dynamic symbol.
2959 Undefined weak syms won't yet be marked as dynamic. */
2960 if (h->dynindx == -1
2961 && !h->forced_local)
2963 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2967 if (bfd_link_pic (info)
2968 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
2970 asection *s = htab->root.splt;
2971 const struct elf_sh_plt_info *plt_info;
2973 /* If this is the first .plt entry, make room for the special
2976 s->size += htab->plt_info->plt0_entry_size;
2978 h->plt.offset = s->size;
2980 /* If this symbol is not defined in a regular file, and we are
2981 not generating a shared library, then set the symbol to this
2982 location in the .plt. This is required to make function
2983 pointers compare as equal between the normal executable and
2984 the shared library. Skip this for FDPIC, since the
2985 function's address will be the address of the canonical
2986 function descriptor. */
2987 if (!htab->fdpic_p && !bfd_link_pic (info) && !h->def_regular)
2989 h->root.u.def.section = s;
2990 h->root.u.def.value = h->plt.offset;
2993 /* Make room for this entry. */
2994 plt_info = htab->plt_info;
2995 if (plt_info->short_plt != NULL
2996 && (get_plt_index (plt_info->short_plt, s->size) < MAX_SHORT_PLT))
2997 plt_info = plt_info->short_plt;
2998 s->size += plt_info->symbol_entry_size;
3000 /* We also need to make an entry in the .got.plt section, which
3001 will be placed in the .got section by the linker script. */
3003 htab->root.sgotplt->size += 4;
3005 htab->root.sgotplt->size += 8;
3007 /* We also need to make an entry in the .rel.plt section. */
3008 htab->root.srelplt->size += sizeof (Elf32_External_Rela);
3010 if (htab->vxworks_p && !bfd_link_pic (info))
3012 /* VxWorks executables have a second set of relocations
3013 for each PLT entry. They go in a separate relocation
3014 section, which is processed by the kernel loader. */
3016 /* There is a relocation for the initial PLT entry:
3017 an R_SH_DIR32 relocation for _GLOBAL_OFFSET_TABLE_. */
3018 if (h->plt.offset == htab->plt_info->plt0_entry_size)
3019 htab->srelplt2->size += sizeof (Elf32_External_Rela);
3021 /* There are two extra relocations for each subsequent
3022 PLT entry: an R_SH_DIR32 relocation for the GOT entry,
3023 and an R_SH_DIR32 relocation for the PLT entry. */
3024 htab->srelplt2->size += sizeof (Elf32_External_Rela) * 2;
3029 h->plt.offset = (bfd_vma) -1;
3035 h->plt.offset = (bfd_vma) -1;
3039 if (h->got.refcount > 0)
3043 enum got_type got_type = sh_elf_hash_entry (h)->got_type;
3045 /* Make sure this symbol is output as a dynamic symbol.
3046 Undefined weak syms won't yet be marked as dynamic. */
3047 if (h->dynindx == -1
3048 && !h->forced_local)
3050 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3054 s = htab->root.sgot;
3055 h->got.offset = s->size;
3057 /* R_SH_TLS_GD needs 2 consecutive GOT slots. */
3058 if (got_type == GOT_TLS_GD)
3060 dyn = htab->root.dynamic_sections_created;
3063 /* No dynamic relocations required. */
3064 if (htab->fdpic_p && !bfd_link_pic (info)
3065 && h->root.type != bfd_link_hash_undefweak
3066 && (got_type == GOT_NORMAL || got_type == GOT_FUNCDESC))
3067 htab->srofixup->size += 4;
3069 /* No dynamic relocations required when IE->LE conversion happens. */
3070 else if (got_type == GOT_TLS_IE
3072 && !bfd_link_pic (info))
3074 /* R_SH_TLS_IE_32 needs one dynamic relocation if dynamic,
3075 R_SH_TLS_GD needs one if local symbol and two if global. */
3076 else if ((got_type == GOT_TLS_GD && h->dynindx == -1)
3077 || got_type == GOT_TLS_IE)
3078 htab->root.srelgot->size += sizeof (Elf32_External_Rela);
3079 else if (got_type == GOT_TLS_GD)
3080 htab->root.srelgot->size += 2 * sizeof (Elf32_External_Rela);
3081 else if (got_type == GOT_FUNCDESC)
3083 if (!bfd_link_pic (info) && SYMBOL_FUNCDESC_LOCAL (info, h))
3084 htab->srofixup->size += 4;
3086 htab->root.srelgot->size += sizeof (Elf32_External_Rela);
3088 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3089 || h->root.type != bfd_link_hash_undefweak)
3090 && (bfd_link_pic (info)
3091 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
3092 htab->root.srelgot->size += sizeof (Elf32_External_Rela);
3093 else if (htab->fdpic_p
3094 && !bfd_link_pic (info)
3095 && got_type == GOT_NORMAL
3096 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3097 || h->root.type != bfd_link_hash_undefweak))
3098 htab->srofixup->size += 4;
3101 h->got.offset = (bfd_vma) -1;
3103 #ifdef INCLUDE_SHMEDIA
3104 if (eh->datalabel_got.refcount > 0)
3109 /* Make sure this symbol is output as a dynamic symbol.
3110 Undefined weak syms won't yet be marked as dynamic. */
3111 if (h->dynindx == -1
3112 && !h->forced_local)
3114 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3118 s = htab->root.sgot;
3119 eh->datalabel_got.offset = s->size;
3121 dyn = htab->root.dynamic_sections_created;
3122 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h))
3123 htab->root.srelgot->size += sizeof (Elf32_External_Rela);
3126 eh->datalabel_got.offset = (bfd_vma) -1;
3129 /* Allocate space for any dynamic relocations to function
3130 descriptors, canonical or otherwise. We need to relocate the
3131 reference unless it resolves to zero, which only happens for
3132 undefined weak symbols (either non-default visibility, or when
3133 static linking). Any GOT slot is accounted for elsewhere. */
3134 if (eh->abs_funcdesc_refcount > 0
3135 && (h->root.type != bfd_link_hash_undefweak
3136 || (htab->root.dynamic_sections_created
3137 && ! SYMBOL_CALLS_LOCAL (info, h))))
3139 if (!bfd_link_pic (info) && SYMBOL_FUNCDESC_LOCAL (info, h))
3140 htab->srofixup->size += eh->abs_funcdesc_refcount * 4;
3142 htab->root.srelgot->size
3143 += eh->abs_funcdesc_refcount * sizeof (Elf32_External_Rela);
3146 /* We must allocate a function descriptor if there are references to
3147 a canonical descriptor (R_SH_GOTFUNCDESC or R_SH_FUNCDESC) and
3148 the dynamic linker isn't going to allocate it. None of this
3149 applies if we already created one in .got.plt, but if the
3150 canonical function descriptor can be in this object, there
3151 won't be a PLT entry at all. */
3152 if ((eh->funcdesc.refcount > 0
3153 || (h->got.offset != MINUS_ONE && eh->got_type == GOT_FUNCDESC))
3154 && h->root.type != bfd_link_hash_undefweak
3155 && SYMBOL_FUNCDESC_LOCAL (info, h))
3157 /* Make room for this function descriptor. */
3158 eh->funcdesc.offset = htab->sfuncdesc->size;
3159 htab->sfuncdesc->size += 8;
3161 /* We will need a relocation or two fixups to initialize the
3162 function descriptor, so allocate those too. */
3163 if (!bfd_link_pic (info) && SYMBOL_CALLS_LOCAL (info, h))
3164 htab->srofixup->size += 8;
3166 htab->srelfuncdesc->size += sizeof (Elf32_External_Rela);
3169 if (eh->dyn_relocs == NULL)
3172 /* In the shared -Bsymbolic case, discard space allocated for
3173 dynamic pc-relative relocs against symbols which turn out to be
3174 defined in regular objects. For the normal shared case, discard
3175 space for pc-relative relocs that have become local due to symbol
3176 visibility changes. */
3178 if (bfd_link_pic (info))
3180 if (SYMBOL_CALLS_LOCAL (info, h))
3182 struct elf_dyn_relocs **pp;
3184 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
3186 p->count -= p->pc_count;
3195 if (htab->vxworks_p)
3197 struct elf_dyn_relocs **pp;
3199 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
3201 if (strcmp (p->sec->output_section->name, ".tls_vars") == 0)
3208 /* Also discard relocs on undefined weak syms with non-default
3210 if (eh->dyn_relocs != NULL
3211 && h->root.type == bfd_link_hash_undefweak)
3213 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
3214 || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
3215 eh->dyn_relocs = NULL;
3217 /* Make sure undefined weak symbols are output as a dynamic
3219 else if (h->dynindx == -1
3220 && !h->forced_local)
3222 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3229 /* For the non-shared case, discard space for relocs against
3230 symbols which turn out to need copy relocs or are not
3236 || (htab->root.dynamic_sections_created
3237 && (h->root.type == bfd_link_hash_undefweak
3238 || h->root.type == bfd_link_hash_undefined))))
3240 /* Make sure this symbol is output as a dynamic symbol.
3241 Undefined weak syms won't yet be marked as dynamic. */
3242 if (h->dynindx == -1
3243 && !h->forced_local)
3245 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3249 /* If that succeeded, we know we'll be keeping all the
3251 if (h->dynindx != -1)
3255 eh->dyn_relocs = NULL;
3260 /* Finally, allocate space. */
3261 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3263 asection *sreloc = elf_section_data (p->sec)->sreloc;
3264 sreloc->size += p->count * sizeof (Elf32_External_Rela);
3266 /* If we need relocations, we do not need fixups. */
3267 if (htab->fdpic_p && !bfd_link_pic (info))
3268 htab->srofixup->size -= 4 * (p->count - p->pc_count);
3274 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
3275 read-only sections. */
3278 maybe_set_textrel (struct elf_link_hash_entry *h, void *info_p)
3282 if (h->root.type == bfd_link_hash_indirect)
3285 sec = readonly_dynrelocs (h);
3288 struct bfd_link_info *info = (struct bfd_link_info *) info_p;
3290 info->flags |= DF_TEXTREL;
3291 info->callbacks->minfo
3292 (_("%pB: dynamic relocation against `%pT' in read-only section `%pA'\n"),
3293 sec->owner, h->root.root.string, sec);
3295 /* Not an error, just cut short the traversal. */
3301 /* This function is called after all the input files have been read,
3302 and the input sections have been assigned to output sections.
3303 It's a convenient place to determine the PLT style. */
3306 sh_elf_always_size_sections (bfd *output_bfd, struct bfd_link_info *info)
3308 sh_elf_hash_table (info)->plt_info = get_plt_info (output_bfd,
3309 bfd_link_pic (info));
3311 if (sh_elf_hash_table (info)->fdpic_p && !bfd_link_relocatable (info)
3312 && !bfd_elf_stack_segment_size (output_bfd, info,
3313 "__stacksize", DEFAULT_STACK_SIZE))
3318 /* Set the sizes of the dynamic sections. */
3321 sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
3322 struct bfd_link_info *info)
3324 struct elf_sh_link_hash_table *htab;
3330 htab = sh_elf_hash_table (info);
3334 dynobj = htab->root.dynobj;
3335 BFD_ASSERT (dynobj != NULL);
3337 if (htab->root.dynamic_sections_created)
3339 /* Set the contents of the .interp section to the interpreter. */
3340 if (bfd_link_executable (info) && !info->nointerp)
3342 s = bfd_get_linker_section (dynobj, ".interp");
3343 BFD_ASSERT (s != NULL);
3344 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
3345 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
3349 /* Set up .got offsets for local syms, and space for local dynamic
3351 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
3353 bfd_signed_vma *local_got;
3354 bfd_signed_vma *end_local_got;
3355 union gotref *local_funcdesc, *end_local_funcdesc;
3356 char *local_got_type;
3357 bfd_size_type locsymcount;
3358 Elf_Internal_Shdr *symtab_hdr;
3361 if (! is_sh_elf (ibfd))
3364 for (s = ibfd->sections; s != NULL; s = s->next)
3366 struct elf_dyn_relocs *p;
3368 for (p = ((struct elf_dyn_relocs *)
3369 elf_section_data (s)->local_dynrel);
3373 if (! bfd_is_abs_section (p->sec)
3374 && bfd_is_abs_section (p->sec->output_section))
3376 /* Input section has been discarded, either because
3377 it is a copy of a linkonce section or due to
3378 linker script /DISCARD/, so we'll be discarding
3381 else if (htab->vxworks_p
3382 && strcmp (p->sec->output_section->name,
3385 /* Relocations in vxworks .tls_vars sections are
3386 handled specially by the loader. */
3388 else if (p->count != 0)
3390 srel = elf_section_data (p->sec)->sreloc;
3391 srel->size += p->count * sizeof (Elf32_External_Rela);
3392 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
3394 info->flags |= DF_TEXTREL;
3395 info->callbacks->minfo (_("%pB: dynamic relocation in read-only section `%pA'\n"),
3396 p->sec->owner, p->sec);
3399 /* If we need relocations, we do not need fixups. */
3400 if (htab->fdpic_p && !bfd_link_pic (info))
3401 htab->srofixup->size -= 4 * (p->count - p->pc_count);
3406 symtab_hdr = &elf_symtab_hdr (ibfd);
3407 locsymcount = symtab_hdr->sh_info;
3408 #ifdef INCLUDE_SHMEDIA
3409 /* Count datalabel local GOT. */
3412 s = htab->root.sgot;
3413 srel = htab->root.srelgot;
3415 local_got = elf_local_got_refcounts (ibfd);
3418 end_local_got = local_got + locsymcount;
3419 local_got_type = sh_elf_local_got_type (ibfd);
3420 local_funcdesc = sh_elf_local_funcdesc (ibfd);
3421 for (; local_got < end_local_got; ++local_got)
3425 *local_got = s->size;
3427 if (*local_got_type == GOT_TLS_GD)
3429 if (bfd_link_pic (info))
3430 srel->size += sizeof (Elf32_External_Rela);
3432 htab->srofixup->size += 4;
3434 if (*local_got_type == GOT_FUNCDESC)
3436 if (local_funcdesc == NULL)
3440 size = locsymcount * sizeof (union gotref);
3441 local_funcdesc = (union gotref *) bfd_zalloc (ibfd,
3443 if (local_funcdesc == NULL)
3445 sh_elf_local_funcdesc (ibfd) = local_funcdesc;
3446 local_funcdesc += (local_got
3447 - elf_local_got_refcounts (ibfd));
3449 local_funcdesc->refcount++;
3454 *local_got = (bfd_vma) -1;
3459 local_funcdesc = sh_elf_local_funcdesc (ibfd);
3462 end_local_funcdesc = local_funcdesc + locsymcount;
3464 for (; local_funcdesc < end_local_funcdesc; ++local_funcdesc)
3466 if (local_funcdesc->refcount > 0)
3468 local_funcdesc->offset = htab->sfuncdesc->size;
3469 htab->sfuncdesc->size += 8;
3470 if (!bfd_link_pic (info))
3471 htab->srofixup->size += 8;
3473 htab->srelfuncdesc->size += sizeof (Elf32_External_Rela);
3476 local_funcdesc->offset = MINUS_ONE;
3482 if (htab->tls_ldm_got.refcount > 0)
3484 /* Allocate 2 got entries and 1 dynamic reloc for R_SH_TLS_LD_32
3486 htab->tls_ldm_got.offset = htab->root.sgot->size;
3487 htab->root.sgot->size += 8;
3488 htab->root.srelgot->size += sizeof (Elf32_External_Rela);
3491 htab->tls_ldm_got.offset = -1;
3493 /* Only the reserved entries should be present. For FDPIC, they go at
3494 the end of .got.plt. */
3497 BFD_ASSERT (htab->root.sgotplt && htab->root.sgotplt->size == 12);
3498 htab->root.sgotplt->size = 0;
3501 /* Allocate global sym .plt and .got entries, and space for global
3502 sym dynamic relocs. */
3503 elf_link_hash_traverse (&htab->root, allocate_dynrelocs, info);
3505 /* Move the reserved entries and the _GLOBAL_OFFSET_TABLE_ symbol to the
3506 end of the FDPIC .got.plt. */
3509 htab->root.hgot->root.u.def.value = htab->root.sgotplt->size;
3510 htab->root.sgotplt->size += 12;
3513 /* At the very end of the .rofixup section is a pointer to the GOT. */
3514 if (htab->fdpic_p && htab->srofixup != NULL)
3515 htab->srofixup->size += 4;
3517 /* We now have determined the sizes of the various dynamic sections.
3518 Allocate memory for them. */
3520 for (s = dynobj->sections; s != NULL; s = s->next)
3522 if ((s->flags & SEC_LINKER_CREATED) == 0)
3525 if (s == htab->root.splt
3526 || s == htab->root.sgot
3527 || s == htab->root.sgotplt
3528 || s == htab->sfuncdesc
3529 || s == htab->srofixup
3530 || s == htab->sdynbss)
3532 /* Strip this section if we don't need it; see the
3535 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
3537 if (s->size != 0 && s != htab->root.srelplt && s != htab->srelplt2)
3540 /* We use the reloc_count field as a counter if we need
3541 to copy relocs into the output file. */
3546 /* It's not one of our sections, so don't allocate space. */
3552 /* If we don't need this section, strip it from the
3553 output file. This is mostly to handle .rela.bss and
3554 .rela.plt. We must create both sections in
3555 create_dynamic_sections, because they must be created
3556 before the linker maps input sections to output
3557 sections. The linker does that before
3558 adjust_dynamic_symbol is called, and it is that
3559 function which decides whether anything needs to go
3560 into these sections. */
3562 s->flags |= SEC_EXCLUDE;
3566 if ((s->flags & SEC_HAS_CONTENTS) == 0)
3569 /* Allocate memory for the section contents. We use bfd_zalloc
3570 here in case unused entries are not reclaimed before the
3571 section's contents are written out. This should not happen,
3572 but this way if it does, we get a R_SH_NONE reloc instead
3574 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
3575 if (s->contents == NULL)
3579 if (htab->root.dynamic_sections_created)
3581 /* Add some entries to the .dynamic section. We fill in the
3582 values later, in sh_elf_finish_dynamic_sections, but we
3583 must add the entries now so that we get the correct size for
3584 the .dynamic section. The DT_DEBUG entry is filled in by the
3585 dynamic linker and used by the debugger. */
3586 #define add_dynamic_entry(TAG, VAL) \
3587 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3589 if (bfd_link_executable (info))
3591 if (! add_dynamic_entry (DT_DEBUG, 0))
3595 if (htab->root.splt->size != 0)
3597 if (! add_dynamic_entry (DT_PLTGOT, 0)
3598 || ! add_dynamic_entry (DT_PLTRELSZ, 0)
3599 || ! add_dynamic_entry (DT_PLTREL, DT_RELA)
3600 || ! add_dynamic_entry (DT_JMPREL, 0))
3603 else if ((elf_elfheader (output_bfd)->e_flags & EF_SH_FDPIC))
3605 if (! add_dynamic_entry (DT_PLTGOT, 0))
3611 if (! add_dynamic_entry (DT_RELA, 0)
3612 || ! add_dynamic_entry (DT_RELASZ, 0)
3613 || ! add_dynamic_entry (DT_RELAENT,
3614 sizeof (Elf32_External_Rela)))
3617 /* If any dynamic relocs apply to a read-only section,
3618 then we need a DT_TEXTREL entry. */
3619 if ((info->flags & DF_TEXTREL) == 0)
3620 elf_link_hash_traverse (&htab->root, maybe_set_textrel, info);
3622 if ((info->flags & DF_TEXTREL) != 0)
3624 if (! add_dynamic_entry (DT_TEXTREL, 0))
3629 && !elf_vxworks_add_dynamic_entries (output_bfd, info))
3632 #undef add_dynamic_entry
3637 /* Add a dynamic relocation to the SRELOC section. */
3639 inline static bfd_vma
3640 sh_elf_add_dyn_reloc (bfd *output_bfd, asection *sreloc, bfd_vma offset,
3641 int reloc_type, long dynindx, bfd_vma addend)
3643 Elf_Internal_Rela outrel;
3644 bfd_vma reloc_offset;
3646 outrel.r_offset = offset;
3647 outrel.r_info = ELF32_R_INFO (dynindx, reloc_type);
3648 outrel.r_addend = addend;
3650 reloc_offset = sreloc->reloc_count * sizeof (Elf32_External_Rela);
3651 BFD_ASSERT (reloc_offset < sreloc->size);
3652 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
3653 sreloc->contents + reloc_offset);
3654 sreloc->reloc_count++;
3656 return reloc_offset;
3659 /* Add an FDPIC read-only fixup. */
3662 sh_elf_add_rofixup (bfd *output_bfd, asection *srofixup, bfd_vma offset)
3664 bfd_vma fixup_offset;
3666 fixup_offset = srofixup->reloc_count++ * 4;
3667 BFD_ASSERT (fixup_offset < srofixup->size);
3668 bfd_put_32 (output_bfd, offset, srofixup->contents + fixup_offset);
3671 /* Return the offset of the generated .got section from the
3672 _GLOBAL_OFFSET_TABLE_ symbol. */
3674 static bfd_signed_vma
3675 sh_elf_got_offset (struct elf_sh_link_hash_table *htab)
3677 return (htab->root.sgot->output_offset - htab->root.sgotplt->output_offset
3678 - htab->root.hgot->root.u.def.value);
3681 /* Find the segment number in which OSEC, and output section, is
3685 sh_elf_osec_to_segment (bfd *output_bfd, asection *osec)
3687 Elf_Internal_Phdr *p = NULL;
3689 if (output_bfd->xvec->flavour == bfd_target_elf_flavour
3690 /* PR ld/17110: Do not look for output segments in an input bfd. */
3691 && output_bfd->direction != read_direction)
3692 p = _bfd_elf_find_segment_containing_section (output_bfd, osec);
3694 /* FIXME: Nothing ever says what this index is relative to. The kernel
3695 supplies data in terms of the number of load segments but this is
3696 a phdr index and the first phdr may not be a load segment. */
3697 return (p != NULL) ? p - elf_tdata (output_bfd)->phdr : -1;
3701 sh_elf_osec_readonly_p (bfd *output_bfd, asection *osec)
3703 unsigned seg = sh_elf_osec_to_segment (output_bfd, osec);
3705 return (seg != (unsigned) -1
3706 && ! (elf_tdata (output_bfd)->phdr[seg].p_flags & PF_W));
3709 /* Generate the initial contents of a local function descriptor, along
3710 with any relocations or fixups required. */
3712 sh_elf_initialize_funcdesc (bfd *output_bfd,
3713 struct bfd_link_info *info,
3714 struct elf_link_hash_entry *h,
3719 struct elf_sh_link_hash_table *htab;
3723 htab = sh_elf_hash_table (info);
3725 /* FIXME: The ABI says that the offset to the function goes in the
3726 descriptor, along with the segment index. We're RELA, so it could
3727 go in the reloc instead... */
3729 if (h != NULL && SYMBOL_CALLS_LOCAL (info, h))
3731 section = h->root.u.def.section;
3732 value = h->root.u.def.value;
3735 if (h == NULL || SYMBOL_CALLS_LOCAL (info, h))
3737 dynindx = elf_section_data (section->output_section)->dynindx;
3738 addr = value + section->output_offset;
3739 seg = sh_elf_osec_to_segment (output_bfd, section->output_section);
3743 BFD_ASSERT (h->dynindx != -1);
3744 dynindx = h->dynindx;
3748 if (!bfd_link_pic (info) && SYMBOL_CALLS_LOCAL (info, h))
3750 if (h == NULL || h->root.type != bfd_link_hash_undefweak)
3752 sh_elf_add_rofixup (output_bfd, htab->srofixup,
3754 + htab->sfuncdesc->output_section->vma
3755 + htab->sfuncdesc->output_offset);
3756 sh_elf_add_rofixup (output_bfd, htab->srofixup,
3758 + htab->sfuncdesc->output_section->vma
3759 + htab->sfuncdesc->output_offset);
3762 /* There are no dynamic relocations so fill in the final
3763 address and gp value (barring fixups). */
3764 addr += section->output_section->vma;
3765 seg = htab->root.hgot->root.u.def.value
3766 + htab->root.hgot->root.u.def.section->output_section->vma
3767 + htab->root.hgot->root.u.def.section->output_offset;
3770 sh_elf_add_dyn_reloc (output_bfd, htab->srelfuncdesc,
3772 + htab->sfuncdesc->output_section->vma
3773 + htab->sfuncdesc->output_offset,
3774 R_SH_FUNCDESC_VALUE, dynindx, 0);
3776 bfd_put_32 (output_bfd, addr, htab->sfuncdesc->contents + offset);
3777 bfd_put_32 (output_bfd, seg, htab->sfuncdesc->contents + offset + 4);
3782 /* Install a 20-bit movi20 field starting at ADDR, which occurs in OUTPUT_BFD.
3783 VALUE is the field's value. Return bfd_reloc_ok if successful or an error
3786 static bfd_reloc_status_type
3787 install_movi20_field (bfd *output_bfd, unsigned long relocation,
3788 bfd *input_bfd, asection *input_section,
3789 bfd_byte *contents, bfd_vma offset)
3791 unsigned long cur_val;
3793 bfd_reloc_status_type r;
3795 if (offset > bfd_get_section_limit (input_bfd, input_section))
3796 return bfd_reloc_outofrange;
3798 r = bfd_check_overflow (complain_overflow_signed, 20, 0,
3799 bfd_arch_bits_per_address (input_bfd), relocation);
3800 if (r != bfd_reloc_ok)
3803 addr = contents + offset;
3804 cur_val = bfd_get_16 (output_bfd, addr);
3805 bfd_put_16 (output_bfd, cur_val | ((relocation & 0xf0000) >> 12), addr);
3806 bfd_put_16 (output_bfd, relocation & 0xffff, addr + 2);
3808 return bfd_reloc_ok;
3811 /* Relocate an SH ELF section. */
3814 sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
3815 bfd *input_bfd, asection *input_section,
3816 bfd_byte *contents, Elf_Internal_Rela *relocs,
3817 Elf_Internal_Sym *local_syms,
3818 asection **local_sections)
3820 struct elf_sh_link_hash_table *htab;
3821 Elf_Internal_Shdr *symtab_hdr;
3822 struct elf_link_hash_entry **sym_hashes;
3823 Elf_Internal_Rela *rel, *relend;
3824 bfd_vma *local_got_offsets;
3825 asection *sgot = NULL;
3826 asection *sgotplt = NULL;
3827 asection *splt = NULL;
3828 asection *sreloc = NULL;
3829 asection *srelgot = NULL;
3830 bfd_boolean is_vxworks_tls;
3831 unsigned isec_segment, got_segment, plt_segment, check_segment[2];
3832 bfd_boolean fdpic_p = FALSE;
3834 BFD_ASSERT (is_sh_elf (input_bfd));
3836 htab = sh_elf_hash_table (info);
3839 sgot = htab->root.sgot;
3840 sgotplt = htab->root.sgotplt;
3841 srelgot = htab->root.srelgot;
3842 splt = htab->root.splt;
3843 fdpic_p = htab->fdpic_p;
3845 symtab_hdr = &elf_symtab_hdr (input_bfd);
3846 sym_hashes = elf_sym_hashes (input_bfd);
3847 local_got_offsets = elf_local_got_offsets (input_bfd);
3849 isec_segment = sh_elf_osec_to_segment (output_bfd,
3850 input_section->output_section);
3851 if (fdpic_p && sgot)
3852 got_segment = sh_elf_osec_to_segment (output_bfd,
3853 sgot->output_section);
3856 if (fdpic_p && splt)
3857 plt_segment = sh_elf_osec_to_segment (output_bfd,
3858 splt->output_section);
3862 /* We have to handle relocations in vxworks .tls_vars sections
3863 specially, because the dynamic loader is 'weird'. */
3864 is_vxworks_tls = (htab && htab->vxworks_p && bfd_link_pic (info)
3865 && !strcmp (input_section->output_section->name,
3869 relend = relocs + input_section->reloc_count;
3870 for (; rel < relend; rel++)
3873 reloc_howto_type *howto;
3874 unsigned long r_symndx;
3875 Elf_Internal_Sym *sym;
3877 struct elf_link_hash_entry *h;
3879 bfd_vma addend = (bfd_vma) 0;
3880 bfd_reloc_status_type r;
3881 int seen_stt_datalabel = 0;
3883 enum got_type got_type;
3884 const char *symname = NULL;
3885 bfd_boolean resolved_to_zero;
3887 r_symndx = ELF32_R_SYM (rel->r_info);
3889 r_type = ELF32_R_TYPE (rel->r_info);
3891 /* Many of the relocs are only used for relaxing, and are
3892 handled entirely by the relaxation code. */
3893 if (r_type >= (int) R_SH_GNU_VTINHERIT
3894 && r_type <= (int) R_SH_LABEL)
3896 if (r_type == (int) R_SH_NONE)
3900 || r_type >= R_SH_max
3901 || (r_type >= (int) R_SH_FIRST_INVALID_RELOC
3902 && r_type <= (int) R_SH_LAST_INVALID_RELOC)
3903 || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_2
3904 && r_type <= (int) R_SH_LAST_INVALID_RELOC_2)
3905 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_3
3906 && r_type <= (int) R_SH_LAST_INVALID_RELOC_3)
3907 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_4
3908 && r_type <= (int) R_SH_LAST_INVALID_RELOC_4)
3909 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_5
3910 && r_type <= (int) R_SH_LAST_INVALID_RELOC_5)
3911 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_6
3912 && r_type <= (int) R_SH_LAST_INVALID_RELOC_6))
3914 bfd_set_error (bfd_error_bad_value);
3918 howto = get_howto_table (output_bfd) + r_type;
3920 /* For relocs that aren't partial_inplace, we get the addend from
3922 if (! howto->partial_inplace)
3923 addend = rel->r_addend;
3925 resolved_to_zero = FALSE;
3929 check_segment[0] = -1;
3930 check_segment[1] = -1;
3931 if (r_symndx < symtab_hdr->sh_info)
3933 sym = local_syms + r_symndx;
3934 sec = local_sections[r_symndx];
3936 symname = bfd_elf_string_from_elf_section
3937 (input_bfd, symtab_hdr->sh_link, sym->st_name);
3938 if (symname == NULL || *symname == '\0')
3939 symname = bfd_section_name (input_bfd, sec);
3941 relocation = (sec->output_section->vma
3942 + sec->output_offset
3944 /* A local symbol never has STO_SH5_ISA32, so we don't need
3945 datalabel processing here. Make sure this does not change
3947 if ((sym->st_other & STO_SH5_ISA32) != 0)
3948 (*info->callbacks->reloc_dangerous)
3950 _("unexpected STO_SH5_ISA32 on local symbol is not handled"),
3951 input_bfd, input_section, rel->r_offset);
3953 if (sec != NULL && discarded_section (sec))
3954 /* Handled below. */
3956 else if (bfd_link_relocatable (info))
3958 /* This is a relocatable link. We don't have to change
3959 anything, unless the reloc is against a section symbol,
3960 in which case we have to adjust according to where the
3961 section symbol winds up in the output section. */
3962 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
3964 if (! howto->partial_inplace)
3966 /* For relocations with the addend in the
3967 relocation, we need just to update the addend.
3968 All real relocs are of type partial_inplace; this
3969 code is mostly for completeness. */
3970 rel->r_addend += sec->output_offset;
3975 /* Relocs of type partial_inplace need to pick up the
3976 contents in the contents and add the offset resulting
3977 from the changed location of the section symbol.
3978 Using _bfd_final_link_relocate (e.g. goto
3979 final_link_relocate) here would be wrong, because
3980 relocations marked pc_relative would get the current
3981 location subtracted, and we must only do that at the
3983 r = _bfd_relocate_contents (howto, input_bfd,
3986 contents + rel->r_offset);
3987 goto relocation_done;
3992 else if (! howto->partial_inplace)
3994 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
3995 addend = rel->r_addend;
3997 else if ((sec->flags & SEC_MERGE)
3998 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
4002 if (howto->rightshift || howto->src_mask != 0xffffffff)
4005 /* xgettext:c-format */
4006 (_("%pB(%pA+%#" PRIx64 "): "
4007 "%s relocation against SEC_MERGE section"),
4008 input_bfd, input_section,
4009 (uint64_t) rel->r_offset, howto->name);
4013 addend = bfd_get_32 (input_bfd, contents + rel->r_offset);
4016 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
4018 addend += msec->output_section->vma + msec->output_offset;
4019 bfd_put_32 (input_bfd, addend, contents + rel->r_offset);
4025 /* FIXME: Ought to make use of the RELOC_FOR_GLOBAL_SYMBOL macro. */
4028 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4029 symname = h->root.root.string;
4030 while (h->root.type == bfd_link_hash_indirect
4031 || h->root.type == bfd_link_hash_warning)
4033 #ifdef INCLUDE_SHMEDIA
4034 /* If the reference passes a symbol marked with
4035 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
4037 seen_stt_datalabel |= h->type == STT_DATALABEL;
4039 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4041 if (h->root.type == bfd_link_hash_defined
4042 || h->root.type == bfd_link_hash_defweak)
4046 dyn = htab ? htab->root.dynamic_sections_created : FALSE;
4047 sec = h->root.u.def.section;
4048 /* In these cases, we don't need the relocation value.
4049 We check specially because in some obscure cases
4050 sec->output_section will be NULL. */
4051 if (r_type == R_SH_GOTPC
4052 || r_type == R_SH_GOTPC_LOW16
4053 || r_type == R_SH_GOTPC_MEDLOW16
4054 || r_type == R_SH_GOTPC_MEDHI16
4055 || r_type == R_SH_GOTPC_HI16
4056 || ((r_type == R_SH_PLT32
4057 || r_type == R_SH_PLT_LOW16
4058 || r_type == R_SH_PLT_MEDLOW16
4059 || r_type == R_SH_PLT_MEDHI16
4060 || r_type == R_SH_PLT_HI16)
4061 && h->plt.offset != (bfd_vma) -1)
4062 || ((r_type == R_SH_GOT32
4063 || r_type == R_SH_GOT20
4064 || r_type == R_SH_GOTFUNCDESC
4065 || r_type == R_SH_GOTFUNCDESC20
4066 || r_type == R_SH_GOTOFFFUNCDESC
4067 || r_type == R_SH_GOTOFFFUNCDESC20
4068 || r_type == R_SH_FUNCDESC
4069 || r_type == R_SH_GOT_LOW16
4070 || r_type == R_SH_GOT_MEDLOW16
4071 || r_type == R_SH_GOT_MEDHI16
4072 || r_type == R_SH_GOT_HI16)
4073 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
4074 bfd_link_pic (info),
4076 && (! bfd_link_pic (info)
4077 || (! info->symbolic && h->dynindx != -1)
4078 || !h->def_regular))
4079 /* The cases above are those in which relocation is
4080 overwritten in the switch block below. The cases
4081 below are those in which we must defer relocation
4082 to run-time, because we can't resolve absolute
4083 addresses when creating a shared library. */
4084 || (bfd_link_pic (info)
4085 && ((! info->symbolic && h->dynindx != -1)
4087 && ((r_type == R_SH_DIR32
4088 && !h->forced_local)
4089 || (r_type == R_SH_REL32
4090 && !SYMBOL_CALLS_LOCAL (info, h)))
4091 && ((input_section->flags & SEC_ALLOC) != 0
4092 /* DWARF will emit R_SH_DIR32 relocations in its
4093 sections against symbols defined externally
4094 in shared libraries. We can't do anything
4096 || ((input_section->flags & SEC_DEBUGGING) != 0
4097 && h->def_dynamic)))
4098 /* Dynamic relocs are not propagated for SEC_DEBUGGING
4099 sections because such sections are not SEC_ALLOC and
4100 thus ld.so will not process them. */
4101 || (sec->output_section == NULL
4102 && ((input_section->flags & SEC_DEBUGGING) != 0
4104 || (sec->output_section == NULL
4105 && (sh_elf_hash_entry (h)->got_type == GOT_TLS_IE
4106 || sh_elf_hash_entry (h)->got_type == GOT_TLS_GD)))
4108 else if (sec->output_section != NULL)
4109 relocation = ((h->root.u.def.value
4110 + sec->output_section->vma
4111 + sec->output_offset)
4112 /* A STO_SH5_ISA32 causes a "bitor 1" to the
4113 symbol value, unless we've seen
4114 STT_DATALABEL on the way to it. */
4115 | ((h->other & STO_SH5_ISA32) != 0
4116 && ! seen_stt_datalabel));
4117 else if (!bfd_link_relocatable (info)
4118 && (_bfd_elf_section_offset (output_bfd, info,
4124 /* xgettext:c-format */
4125 (_("%pB(%pA+%#" PRIx64 "): "
4126 "unresolvable %s relocation against symbol `%s'"),
4129 (uint64_t) rel->r_offset,
4131 h->root.root.string);
4135 else if (h->root.type == bfd_link_hash_undefweak)
4136 resolved_to_zero = UNDEFWEAK_NO_DYNAMIC_RELOC (info, h);
4137 else if (info->unresolved_syms_in_objects == RM_IGNORE
4138 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
4140 else if (!bfd_link_relocatable (info))
4141 (*info->callbacks->undefined_symbol)
4142 (info, h->root.root.string, input_bfd,
4143 input_section, rel->r_offset,
4144 (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
4145 || ELF_ST_VISIBILITY (h->other)));
4148 if (sec != NULL && discarded_section (sec))
4149 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
4150 rel, 1, relend, howto, 0, contents);
4152 if (bfd_link_relocatable (info))
4155 /* Check for inter-segment relocations in FDPIC files. Most
4156 relocations connect the relocation site to the location of
4157 the target symbol, but there are some exceptions below. */
4158 check_segment[0] = isec_segment;
4160 check_segment[1] = sh_elf_osec_to_segment (output_bfd,
4161 sec->output_section);
4163 check_segment[1] = -1;
4165 switch ((int) r_type)
4167 final_link_relocate:
4168 /* COFF relocs don't use the addend. The addend is used for
4169 R_SH_DIR32 to be compatible with other compilers. */
4170 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
4171 contents, rel->r_offset,
4172 relocation, addend);
4176 goto final_link_relocate;
4181 /* If the reloc is against the start of this section, then
4182 the assembler has already taken care of it and the reloc
4183 is here only to assist in relaxing. If the reloc is not
4184 against the start of this section, then it's against an
4185 external symbol and we must deal with it ourselves. */
4186 if (input_section->output_section->vma + input_section->output_offset
4189 int disp = (relocation
4190 - input_section->output_section->vma
4191 - input_section->output_offset
4197 case R_SH_DIR8WPZ: mask = 1; break;
4198 case R_SH_DIR8WPL: mask = 3; break;
4199 default: mask = 0; break;
4204 /* xgettext:c-format */
4205 (_("%pB: %#" PRIx64 ": fatal: "
4206 "unaligned branch target for relax-support relocation"),
4207 input_section->owner,
4208 (uint64_t) rel->r_offset);
4209 bfd_set_error (bfd_error_bad_value);
4213 goto final_link_relocate;
4219 #ifdef INCLUDE_SHMEDIA
4220 if (shmedia_prepare_reloc (info, input_bfd, input_section,
4221 contents, rel, &relocation))
4222 goto final_link_relocate;
4224 bfd_set_error (bfd_error_bad_value);
4232 goto final_link_relocate;
4239 /* xgettext:c-format */
4240 (_("%pB: %#" PRIx64 ": fatal: "
4241 "unaligned %s relocation %#" PRIx64),
4242 input_section->owner, (uint64_t) rel->r_offset,
4243 howto->name, (uint64_t) relocation);
4244 bfd_set_error (bfd_error_bad_value);
4247 goto final_link_relocate;
4255 /* xgettext:c-format */
4256 (_("%pB: %#" PRIx64 ": fatal: "
4257 "unaligned %s relocation %#" PRIx64 ""),
4258 input_section->owner,
4259 (uint64_t) rel->r_offset, howto->name,
4260 (uint64_t) relocation);
4261 bfd_set_error (bfd_error_bad_value);
4264 goto final_link_relocate;
4267 if ((signed int)relocation < -32
4268 || (signed int)relocation > 32)
4271 /* xgettext:c-format */
4272 (_("%pB: %#" PRIx64 ": fatal: R_SH_PSHA relocation %" PRId64
4273 " not in range -32..32"),
4274 input_section->owner,
4275 (uint64_t) rel->r_offset,
4276 (int64_t) relocation);
4277 bfd_set_error (bfd_error_bad_value);
4280 goto final_link_relocate;
4283 if ((signed int)relocation < -16
4284 || (signed int)relocation > 16)
4287 /* xgettext:c-format */
4288 (_("%pB: %#" PRIx64 ": fatal: R_SH_PSHL relocation %" PRId64
4289 " not in range -32..32"),
4290 input_section->owner,
4291 (uint64_t) rel->r_offset,
4292 (int64_t) relocation);
4293 bfd_set_error (bfd_error_bad_value);
4296 goto final_link_relocate;
4300 #ifdef INCLUDE_SHMEDIA
4301 case R_SH_IMM_LOW16_PCREL:
4302 case R_SH_IMM_MEDLOW16_PCREL:
4303 case R_SH_IMM_MEDHI16_PCREL:
4304 case R_SH_IMM_HI16_PCREL:
4306 if (bfd_link_pic (info)
4308 || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4309 && !resolved_to_zero)
4310 || h->root.type != bfd_link_hash_undefweak)
4311 && r_symndx != STN_UNDEF
4312 && (input_section->flags & SEC_ALLOC) != 0
4314 && (r_type == R_SH_DIR32
4315 || !SYMBOL_CALLS_LOCAL (info, h)))
4317 Elf_Internal_Rela outrel;
4319 bfd_boolean skip, relocate;
4321 /* When generating a shared object, these relocations
4322 are copied into the output file to be resolved at run
4327 sreloc = _bfd_elf_get_dynamic_reloc_section
4328 (input_bfd, input_section, /*rela?*/ TRUE);
4337 _bfd_elf_section_offset (output_bfd, info, input_section,
4339 if (outrel.r_offset == (bfd_vma) -1)
4341 else if (outrel.r_offset == (bfd_vma) -2)
4342 skip = TRUE, relocate = TRUE;
4343 outrel.r_offset += (input_section->output_section->vma
4344 + input_section->output_offset);
4347 memset (&outrel, 0, sizeof outrel);
4348 else if (r_type == R_SH_REL32)
4350 BFD_ASSERT (h != NULL && h->dynindx != -1);
4351 outrel.r_info = ELF32_R_INFO (h->dynindx, R_SH_REL32);
4353 = (howto->partial_inplace
4354 ? bfd_get_32 (input_bfd, contents + rel->r_offset)
4357 #ifdef INCLUDE_SHMEDIA
4358 else if (r_type == R_SH_IMM_LOW16_PCREL
4359 || r_type == R_SH_IMM_MEDLOW16_PCREL
4360 || r_type == R_SH_IMM_MEDHI16_PCREL
4361 || r_type == R_SH_IMM_HI16_PCREL)
4363 BFD_ASSERT (h != NULL && h->dynindx != -1);
4364 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
4365 outrel.r_addend = addend;
4370 || ((info->symbolic || h->dynindx == -1)
4371 && h->def_regular)))
4375 BFD_ASSERT (sec != NULL);
4376 BFD_ASSERT (sec->output_section != NULL);
4377 dynindx = elf_section_data (sec->output_section)->dynindx;
4378 outrel.r_info = ELF32_R_INFO (dynindx, R_SH_DIR32);
4379 outrel.r_addend = relocation;
4381 += (howto->partial_inplace
4382 ? bfd_get_32 (input_bfd, contents + rel->r_offset)
4384 outrel.r_addend -= sec->output_section->vma;
4388 /* h->dynindx may be -1 if this symbol was marked to
4391 || ((info->symbolic || h->dynindx == -1)
4394 relocate = howto->partial_inplace;
4395 outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
4399 BFD_ASSERT (h->dynindx != -1);
4400 outrel.r_info = ELF32_R_INFO (h->dynindx, R_SH_DIR32);
4402 outrel.r_addend = relocation;
4404 += (howto->partial_inplace
4405 ? bfd_get_32 (input_bfd, contents + rel->r_offset)
4409 loc = sreloc->contents;
4410 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
4411 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
4413 check_segment[0] = check_segment[1] = -1;
4415 /* If this reloc is against an external symbol, we do
4416 not want to fiddle with the addend. Otherwise, we
4417 need to include the symbol value so that it becomes
4418 an addend for the dynamic reloc. */
4422 else if (fdpic_p && !bfd_link_pic (info)
4423 && r_type == R_SH_DIR32
4424 && (input_section->flags & SEC_ALLOC) != 0)
4430 if (sh_elf_osec_readonly_p (output_bfd,
4431 input_section->output_section))
4434 /* xgettext:c-format */
4435 (_("%pB(%pA+%#" PRIx64 "): "
4436 "cannot emit fixup to `%s' in read-only section"),
4439 (uint64_t) rel->r_offset,
4444 offset = _bfd_elf_section_offset (output_bfd, info,
4445 input_section, rel->r_offset);
4446 if (offset != (bfd_vma)-1)
4447 sh_elf_add_rofixup (output_bfd, htab->srofixup,
4448 input_section->output_section->vma
4449 + input_section->output_offset
4452 check_segment[0] = check_segment[1] = -1;
4454 /* We don't want warnings for non-NULL tests on undefined weak
4456 else if (r_type == R_SH_REL32
4458 && h->root.type == bfd_link_hash_undefweak)
4459 check_segment[0] = check_segment[1] = -1;
4460 goto final_link_relocate;
4463 #ifdef INCLUDE_SHMEDIA
4464 case R_SH_GOTPLT_LOW16:
4465 case R_SH_GOTPLT_MEDLOW16:
4466 case R_SH_GOTPLT_MEDHI16:
4467 case R_SH_GOTPLT_HI16:
4468 case R_SH_GOTPLT10BY4:
4469 case R_SH_GOTPLT10BY8:
4471 /* Relocation is to the entry for this symbol in the
4472 procedure linkage table. */
4476 || ! bfd_link_pic (info)
4479 || h->plt.offset == (bfd_vma) -1
4480 || h->got.offset != (bfd_vma) -1)
4483 /* Relocation is to the entry for this symbol in the global
4484 offset table extension for the procedure linkage table. */
4487 BFD_ASSERT (sgotplt != NULL);
4488 relocation = (sgotplt->output_offset
4489 + (get_plt_index (htab->plt_info, h->plt.offset)
4493 relocation -= GOT_BIAS;
4496 goto final_link_relocate;
4501 #ifdef INCLUDE_SHMEDIA
4502 case R_SH_GOT_LOW16:
4503 case R_SH_GOT_MEDLOW16:
4504 case R_SH_GOT_MEDHI16:
4509 /* Relocation is to the entry for this symbol in the global
4513 BFD_ASSERT (sgot != NULL);
4514 check_segment[0] = check_segment[1] = -1;
4520 off = h->got.offset;
4521 #ifdef INCLUDE_SHMEDIA
4522 if (seen_stt_datalabel)
4524 struct elf_sh_link_hash_entry *hsh;
4526 hsh = (struct elf_sh_link_hash_entry *)h;
4527 off = hsh->datalabel_got.offset;
4530 BFD_ASSERT (off != (bfd_vma) -1);
4532 dyn = htab->root.dynamic_sections_created;
4533 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
4534 bfd_link_pic (info),
4536 || (bfd_link_pic (info)
4537 && SYMBOL_REFERENCES_LOCAL (info, h))
4538 || ((ELF_ST_VISIBILITY (h->other)
4539 || resolved_to_zero)
4540 && h->root.type == bfd_link_hash_undefweak))
4542 /* This is actually a static link, or it is a
4543 -Bsymbolic link and the symbol is defined
4544 locally, or the symbol was forced to be local
4545 because of a version file. We must initialize
4546 this entry in the global offset table. Since the
4547 offset must always be a multiple of 4, we use the
4548 least significant bit to record whether we have
4549 initialized it already.
4551 When doing a dynamic link, we create a .rela.got
4552 relocation entry to initialize the value. This
4553 is done in the finish_dynamic_symbol routine. */
4558 bfd_put_32 (output_bfd, relocation,
4559 sgot->contents + off);
4560 #ifdef INCLUDE_SHMEDIA
4561 if (seen_stt_datalabel)
4563 struct elf_sh_link_hash_entry *hsh;
4565 hsh = (struct elf_sh_link_hash_entry *)h;
4566 hsh->datalabel_got.offset |= 1;
4572 /* If we initialize the GOT entry here with a valid
4573 symbol address, also add a fixup. */
4574 if (fdpic_p && !bfd_link_pic (info)
4575 && sh_elf_hash_entry (h)->got_type == GOT_NORMAL
4576 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4577 || h->root.type != bfd_link_hash_undefweak))
4578 sh_elf_add_rofixup (output_bfd, htab->srofixup,
4579 sgot->output_section->vma
4580 + sgot->output_offset
4585 relocation = sh_elf_got_offset (htab) + off;
4589 #ifdef INCLUDE_SHMEDIA
4592 BFD_ASSERT (local_got_offsets != NULL
4593 && (local_got_offsets[symtab_hdr->sh_info
4597 off = local_got_offsets[symtab_hdr->sh_info
4603 BFD_ASSERT (local_got_offsets != NULL
4604 && local_got_offsets[r_symndx] != (bfd_vma) -1);
4606 off = local_got_offsets[r_symndx];
4607 #ifdef INCLUDE_SHMEDIA
4611 /* The offset must always be a multiple of 4. We use
4612 the least significant bit to record whether we have
4613 already generated the necessary reloc. */
4618 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
4620 if (bfd_link_pic (info))
4622 Elf_Internal_Rela outrel;
4625 outrel.r_offset = (sgot->output_section->vma
4626 + sgot->output_offset
4631 = elf_section_data (sec->output_section)->dynindx;
4632 outrel.r_info = ELF32_R_INFO (dynindx, R_SH_DIR32);
4633 outrel.r_addend = relocation;
4634 outrel.r_addend -= sec->output_section->vma;
4638 outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
4639 outrel.r_addend = relocation;
4641 loc = srelgot->contents;
4642 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
4643 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
4646 && (sh_elf_local_got_type (input_bfd) [r_symndx]
4648 sh_elf_add_rofixup (output_bfd, htab->srofixup,
4649 sgot->output_section->vma
4650 + sgot->output_offset
4653 #ifdef INCLUDE_SHMEDIA
4655 local_got_offsets[symtab_hdr->sh_info + r_symndx] |= 1;
4658 local_got_offsets[r_symndx] |= 1;
4661 relocation = sh_elf_got_offset (htab) + off;
4665 relocation -= GOT_BIAS;
4668 if (r_type == R_SH_GOT20)
4670 r = install_movi20_field (output_bfd, relocation + addend,
4671 input_bfd, input_section, contents,
4676 goto final_link_relocate;
4680 #ifdef INCLUDE_SHMEDIA
4681 case R_SH_GOTOFF_LOW16:
4682 case R_SH_GOTOFF_MEDLOW16:
4683 case R_SH_GOTOFF_MEDHI16:
4684 case R_SH_GOTOFF_HI16:
4686 /* GOTOFF relocations are relative to _GLOBAL_OFFSET_TABLE_, which
4687 we place at the start of the .got.plt section. This is the same
4688 as the start of the output .got section, unless there are function
4689 descriptors in front of it. */
4691 BFD_ASSERT (sgotplt != NULL);
4692 check_segment[0] = got_segment;
4693 relocation -= sgotplt->output_section->vma + sgotplt->output_offset
4694 + htab->root.hgot->root.u.def.value;
4697 relocation -= GOT_BIAS;
4700 addend = rel->r_addend;
4702 if (r_type == R_SH_GOTOFF20)
4704 r = install_movi20_field (output_bfd, relocation + addend,
4705 input_bfd, input_section, contents,
4710 goto final_link_relocate;
4713 #ifdef INCLUDE_SHMEDIA
4714 case R_SH_GOTPC_LOW16:
4715 case R_SH_GOTPC_MEDLOW16:
4716 case R_SH_GOTPC_MEDHI16:
4717 case R_SH_GOTPC_HI16:
4719 /* Use global offset table as symbol value. */
4721 BFD_ASSERT (sgotplt != NULL);
4722 relocation = sgotplt->output_section->vma + sgotplt->output_offset;
4725 relocation += GOT_BIAS;
4728 addend = rel->r_addend;
4730 goto final_link_relocate;
4733 #ifdef INCLUDE_SHMEDIA
4734 case R_SH_PLT_LOW16:
4735 case R_SH_PLT_MEDLOW16:
4736 case R_SH_PLT_MEDHI16:
4739 /* Relocation is to the entry for this symbol in the
4740 procedure linkage table. */
4742 /* Resolve a PLT reloc against a local symbol directly,
4743 without using the procedure linkage table. */
4745 goto final_link_relocate;
4747 /* We don't want to warn on calls to undefined weak symbols,
4748 as calls to them must be protected by non-NULL tests
4749 anyway, and unprotected calls would invoke undefined
4751 if (h->root.type == bfd_link_hash_undefweak)
4752 check_segment[0] = check_segment[1] = -1;
4754 if (h->forced_local)
4755 goto final_link_relocate;
4757 if (h->plt.offset == (bfd_vma) -1)
4759 /* We didn't make a PLT entry for this symbol. This
4760 happens when statically linking PIC code, or when
4761 using -Bsymbolic. */
4762 goto final_link_relocate;
4765 BFD_ASSERT (splt != NULL);
4766 check_segment[1] = plt_segment;
4767 relocation = (splt->output_section->vma
4768 + splt->output_offset
4771 #ifdef INCLUDE_SHMEDIA
4775 addend = rel->r_addend;
4777 goto final_link_relocate;
4779 /* Relocation is to the canonical function descriptor for this
4780 symbol, possibly via the GOT. Initialize the GOT
4781 entry and function descriptor if necessary. */
4782 case R_SH_GOTFUNCDESC:
4783 case R_SH_GOTFUNCDESC20:
4787 asection *reloc_section;
4788 bfd_vma reloc_offset;
4789 int reloc_type = R_SH_FUNCDESC;
4793 check_segment[0] = check_segment[1] = -1;
4795 /* FIXME: See what FRV does for global symbols in the
4796 executable, with --export-dynamic. Do they need ld.so
4797 to allocate official descriptors? See what this code
4803 if (r_type == R_SH_FUNCDESC)
4805 reloc_section = input_section;
4806 reloc_offset = rel->r_offset;
4810 reloc_section = sgot;
4813 reloc_offset = h->got.offset;
4816 BFD_ASSERT (local_got_offsets != NULL);
4817 reloc_offset = local_got_offsets[r_symndx];
4819 BFD_ASSERT (reloc_offset != MINUS_ONE);
4821 if (reloc_offset & 1)
4824 goto funcdesc_done_got;
4828 if (h && h->root.type == bfd_link_hash_undefweak
4829 && (SYMBOL_CALLS_LOCAL (info, h)
4830 || !htab->root.dynamic_sections_created))
4831 /* Undefined weak symbol which will not be dynamically
4832 resolved later; leave it at zero. */
4833 goto funcdesc_leave_zero;
4834 else if (SYMBOL_CALLS_LOCAL (info, h)
4835 && ! SYMBOL_FUNCDESC_LOCAL (info, h))
4837 /* If the symbol needs a non-local function descriptor
4838 but binds locally (i.e., its visibility is
4839 protected), emit a dynamic relocation decayed to
4840 section+offset. This is an optimization; the dynamic
4841 linker would resolve our function descriptor request
4842 to our copy of the function anyway. */
4843 dynindx = elf_section_data (h->root.u.def.section
4844 ->output_section)->dynindx;
4845 relocation += h->root.u.def.section->output_offset
4846 + h->root.u.def.value;
4848 else if (! SYMBOL_FUNCDESC_LOCAL (info, h))
4850 /* If the symbol is dynamic and there will be dynamic
4851 symbol resolution because we are or are linked with a
4852 shared library, emit a FUNCDESC relocation such that
4853 the dynamic linker will allocate the function
4855 BFD_ASSERT (h->dynindx != -1);
4856 dynindx = h->dynindx;
4862 /* Otherwise, we know we have a private function
4863 descriptor, so reference it directly. */
4864 reloc_type = R_SH_DIR32;
4865 dynindx = elf_section_data (htab->sfuncdesc
4866 ->output_section)->dynindx;
4870 offset = sh_elf_hash_entry (h)->funcdesc.offset;
4871 BFD_ASSERT (offset != MINUS_ONE);
4872 if ((offset & 1) == 0)
4874 if (!sh_elf_initialize_funcdesc (output_bfd, info, h,
4877 sh_elf_hash_entry (h)->funcdesc.offset |= 1;
4882 union gotref *local_funcdesc;
4884 local_funcdesc = sh_elf_local_funcdesc (input_bfd);
4885 offset = local_funcdesc[r_symndx].offset;
4886 BFD_ASSERT (offset != MINUS_ONE);
4887 if ((offset & 1) == 0)
4889 if (!sh_elf_initialize_funcdesc (output_bfd, info, NULL,
4893 local_funcdesc[r_symndx].offset |= 1;
4897 relocation = htab->sfuncdesc->output_offset + (offset & ~1);
4900 if (!bfd_link_pic (info) && SYMBOL_FUNCDESC_LOCAL (info, h))
4904 if (sh_elf_osec_readonly_p (output_bfd,
4905 reloc_section->output_section))
4908 /* xgettext:c-format */
4909 (_("%pB(%pA+%#" PRIx64 "): "
4910 "cannot emit fixup to `%s' in read-only section"),
4913 (uint64_t) rel->r_offset,
4918 offset = _bfd_elf_section_offset (output_bfd, info,
4919 reloc_section, reloc_offset);
4921 if (offset != (bfd_vma)-1)
4922 sh_elf_add_rofixup (output_bfd, htab->srofixup,
4924 + reloc_section->output_section->vma
4925 + reloc_section->output_offset);
4927 else if ((reloc_section->output_section->flags
4928 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
4932 if (sh_elf_osec_readonly_p (output_bfd,
4933 reloc_section->output_section))
4935 info->callbacks->warning
4937 _("cannot emit dynamic relocations in read-only section"),
4938 symname, input_bfd, reloc_section, reloc_offset);
4942 offset = _bfd_elf_section_offset (output_bfd, info,
4943 reloc_section, reloc_offset);
4945 if (offset != (bfd_vma)-1)
4946 sh_elf_add_dyn_reloc (output_bfd, srelgot,
4948 + reloc_section->output_section->vma
4949 + reloc_section->output_offset,
4950 reloc_type, dynindx, relocation);
4952 if (r_type == R_SH_FUNCDESC)
4960 goto funcdesc_leave_zero;
4964 if (SYMBOL_FUNCDESC_LOCAL (info, h))
4965 relocation += htab->sfuncdesc->output_section->vma;
4966 funcdesc_leave_zero:
4967 if (r_type != R_SH_FUNCDESC)
4969 bfd_put_32 (output_bfd, relocation,
4970 reloc_section->contents + reloc_offset);
4974 local_got_offsets[r_symndx] |= 1;
4978 relocation = sh_elf_got_offset (htab) + reloc_offset;
4980 relocation -= GOT_BIAS;
4983 if (r_type == R_SH_GOTFUNCDESC20)
4985 r = install_movi20_field (output_bfd, relocation + addend,
4986 input_bfd, input_section, contents,
4991 goto final_link_relocate;
4995 case R_SH_GOTOFFFUNCDESC:
4996 case R_SH_GOTOFFFUNCDESC20:
4997 /* FIXME: See R_SH_FUNCDESC comment about global symbols in the
4998 executable and --export-dynamic. If such symbols get
4999 ld.so-allocated descriptors we can not use R_SH_GOTOFFFUNCDESC
5003 check_segment[0] = check_segment[1] = -1;
5005 addend = rel->r_addend;
5007 if (h && (h->root.type == bfd_link_hash_undefweak
5008 || !SYMBOL_FUNCDESC_LOCAL (info, h)))
5011 /* xgettext:c-format */
5012 (_("%pB(%pA+%#" PRIx64 "): "
5013 "%s relocation against external symbol \"%s\""),
5014 input_bfd, input_section, (uint64_t) rel->r_offset,
5015 howto->name, h->root.root.string);
5022 /* Otherwise, we know we have a private function
5023 descriptor, so reference it directly. */
5026 offset = sh_elf_hash_entry (h)->funcdesc.offset;
5027 BFD_ASSERT (offset != MINUS_ONE);
5028 if ((offset & 1) == 0)
5030 if (!sh_elf_initialize_funcdesc (output_bfd, info, h,
5033 sh_elf_hash_entry (h)->funcdesc.offset |= 1;
5038 union gotref *local_funcdesc;
5040 local_funcdesc = sh_elf_local_funcdesc (input_bfd);
5041 offset = local_funcdesc[r_symndx].offset;
5042 BFD_ASSERT (offset != MINUS_ONE);
5043 if ((offset & 1) == 0)
5045 if (!sh_elf_initialize_funcdesc (output_bfd, info, NULL,
5049 local_funcdesc[r_symndx].offset |= 1;
5053 relocation = htab->sfuncdesc->output_offset + (offset & ~1);
5056 relocation -= (htab->root.hgot->root.u.def.value
5057 + sgotplt->output_offset);
5059 relocation -= GOT_BIAS;
5062 if (r_type == R_SH_GOTOFFFUNCDESC20)
5064 r = install_movi20_field (output_bfd, relocation + addend,
5065 input_bfd, input_section, contents,
5070 goto final_link_relocate;
5072 case R_SH_LOOP_START:
5074 static bfd_vma start, end;
5076 start = (relocation + rel->r_addend
5077 - (sec->output_section->vma + sec->output_offset));
5078 r = sh_elf_reloc_loop (r_type, input_bfd, input_section, contents,
5079 rel->r_offset, sec, start, end);
5083 end = (relocation + rel->r_addend
5084 - (sec->output_section->vma + sec->output_offset));
5085 r = sh_elf_reloc_loop (r_type, input_bfd, input_section, contents,
5086 rel->r_offset, sec, start, end);
5090 case R_SH_TLS_GD_32:
5091 case R_SH_TLS_IE_32:
5093 check_segment[0] = check_segment[1] = -1;
5094 r_type = sh_elf_optimized_tls_reloc (info, r_type, h == NULL);
5095 got_type = GOT_UNKNOWN;
5096 if (h == NULL && local_got_offsets)
5097 got_type = sh_elf_local_got_type (input_bfd) [r_symndx];
5100 got_type = sh_elf_hash_entry (h)->got_type;
5101 if (! bfd_link_pic (info)
5102 && (h->dynindx == -1
5104 r_type = R_SH_TLS_LE_32;
5107 if (r_type == R_SH_TLS_GD_32 && got_type == GOT_TLS_IE)
5108 r_type = R_SH_TLS_IE_32;
5110 if (r_type == R_SH_TLS_LE_32)
5113 unsigned short insn;
5115 if (ELF32_R_TYPE (rel->r_info) == R_SH_TLS_GD_32)
5117 /* GD->LE transition:
5118 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5119 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5120 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5122 mov.l 1f,r4; stc gbr,r0; add r4,r0; nop;
5124 1: .long x@TPOFF; 2: .long __tls_get_addr@PLT; 3:. */
5126 offset = rel->r_offset;
5127 BFD_ASSERT (offset >= 16);
5128 /* Size of GD instructions is 16 or 18. */
5130 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5131 if ((insn & 0xff00) == 0xc700)
5133 BFD_ASSERT (offset >= 2);
5135 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5138 BFD_ASSERT ((insn & 0xff00) == 0xd400);
5139 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5140 BFD_ASSERT ((insn & 0xff00) == 0xc700);
5141 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5142 BFD_ASSERT ((insn & 0xff00) == 0xd100);
5143 insn = bfd_get_16 (input_bfd, contents + offset + 6);
5144 BFD_ASSERT (insn == 0x310c);
5145 insn = bfd_get_16 (input_bfd, contents + offset + 8);
5146 BFD_ASSERT (insn == 0x410b);
5147 insn = bfd_get_16 (input_bfd, contents + offset + 10);
5148 BFD_ASSERT (insn == 0x34cc);
5150 bfd_put_16 (output_bfd, 0x0012, contents + offset + 2);
5151 bfd_put_16 (output_bfd, 0x304c, contents + offset + 4);
5152 bfd_put_16 (output_bfd, 0x0009, contents + offset + 6);
5153 bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
5154 bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
5160 /* IE->LE transition:
5161 mov.l 1f,r0; stc gbr,rN; mov.l @(r0,r12),rM;
5162 bra 2f; add ...; .align 2; 1: x@GOTTPOFF; 2:
5164 mov.l .Ln,rM; stc gbr,rN; nop; ...;
5167 offset = rel->r_offset;
5168 BFD_ASSERT (offset >= 16);
5169 /* Size of IE instructions is 10 or 12. */
5171 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5172 if ((insn & 0xf0ff) == 0x0012)
5174 BFD_ASSERT (offset >= 2);
5176 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5179 BFD_ASSERT ((insn & 0xff00) == 0xd000);
5180 target = insn & 0x00ff;
5181 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5182 BFD_ASSERT ((insn & 0xf0ff) == 0x0012);
5183 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5184 BFD_ASSERT ((insn & 0xf0ff) == 0x00ce);
5185 insn = 0xd000 | (insn & 0x0f00) | target;
5186 bfd_put_16 (output_bfd, insn, contents + offset + 0);
5187 bfd_put_16 (output_bfd, 0x0009, contents + offset + 4);
5190 bfd_put_32 (output_bfd, tpoff (info, relocation),
5191 contents + rel->r_offset);
5195 if (sgot == NULL || sgotplt == NULL)
5199 off = h->got.offset;
5202 if (local_got_offsets == NULL)
5205 off = local_got_offsets[r_symndx];
5208 /* Relocate R_SH_TLS_IE_32 directly when statically linking. */
5209 if (r_type == R_SH_TLS_IE_32
5210 && ! htab->root.dynamic_sections_created)
5213 bfd_put_32 (output_bfd, tpoff (info, relocation),
5214 sgot->contents + off);
5215 bfd_put_32 (output_bfd, sh_elf_got_offset (htab) + off,
5216 contents + rel->r_offset);
5224 Elf_Internal_Rela outrel;
5228 outrel.r_offset = (sgot->output_section->vma
5229 + sgot->output_offset + off);
5231 if (h == NULL || h->dynindx == -1)
5236 dr_type = (r_type == R_SH_TLS_GD_32 ? R_SH_TLS_DTPMOD32 :
5238 if (dr_type == R_SH_TLS_TPOFF32 && indx == 0)
5239 outrel.r_addend = relocation - dtpoff_base (info);
5241 outrel.r_addend = 0;
5242 outrel.r_info = ELF32_R_INFO (indx, dr_type);
5243 loc = srelgot->contents;
5244 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
5245 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5247 if (r_type == R_SH_TLS_GD_32)
5251 bfd_put_32 (output_bfd,
5252 relocation - dtpoff_base (info),
5253 sgot->contents + off + 4);
5257 outrel.r_info = ELF32_R_INFO (indx,
5259 outrel.r_offset += 4;
5260 outrel.r_addend = 0;
5261 srelgot->reloc_count++;
5262 loc += sizeof (Elf32_External_Rela);
5263 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5270 local_got_offsets[r_symndx] |= 1;
5273 if (off >= (bfd_vma) -2)
5276 if (r_type == (int) ELF32_R_TYPE (rel->r_info))
5277 relocation = sh_elf_got_offset (htab) + off;
5281 unsigned short insn;
5283 /* GD->IE transition:
5284 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5285 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5286 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5288 mov.l 1f,r0; stc gbr,r4; mov.l @(r0,r12),r0; add r4,r0;
5289 nop; nop; bra 3f; nop; .align 2;
5290 1: .long x@TPOFF; 2:...; 3:. */
5292 offset = rel->r_offset;
5293 BFD_ASSERT (offset >= 16);
5294 /* Size of GD instructions is 16 or 18. */
5296 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5297 if ((insn & 0xff00) == 0xc700)
5299 BFD_ASSERT (offset >= 2);
5301 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5304 BFD_ASSERT ((insn & 0xff00) == 0xd400);
5306 /* Replace mov.l 1f,R4 with mov.l 1f,r0. */
5307 bfd_put_16 (output_bfd, insn & 0xf0ff, contents + offset);
5309 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5310 BFD_ASSERT ((insn & 0xff00) == 0xc700);
5311 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5312 BFD_ASSERT ((insn & 0xff00) == 0xd100);
5313 insn = bfd_get_16 (input_bfd, contents + offset + 6);
5314 BFD_ASSERT (insn == 0x310c);
5315 insn = bfd_get_16 (input_bfd, contents + offset + 8);
5316 BFD_ASSERT (insn == 0x410b);
5317 insn = bfd_get_16 (input_bfd, contents + offset + 10);
5318 BFD_ASSERT (insn == 0x34cc);
5320 bfd_put_16 (output_bfd, 0x0412, contents + offset + 2);
5321 bfd_put_16 (output_bfd, 0x00ce, contents + offset + 4);
5322 bfd_put_16 (output_bfd, 0x304c, contents + offset + 6);
5323 bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
5324 bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
5326 bfd_put_32 (output_bfd, sh_elf_got_offset (htab) + off,
5327 contents + rel->r_offset);
5332 addend = rel->r_addend;
5334 goto final_link_relocate;
5336 case R_SH_TLS_LD_32:
5338 check_segment[0] = check_segment[1] = -1;
5339 if (! bfd_link_pic (info))
5342 unsigned short insn;
5344 /* LD->LE transition:
5345 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5346 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5347 1: .long x$TLSLD; 2: .long __tls_get_addr@PLT; 3:
5349 stc gbr,r0; nop; nop; nop;
5350 nop; nop; bra 3f; ...; 3:. */
5352 offset = rel->r_offset;
5353 BFD_ASSERT (offset >= 16);
5354 /* Size of LD instructions is 16 or 18. */
5356 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5357 if ((insn & 0xff00) == 0xc700)
5359 BFD_ASSERT (offset >= 2);
5361 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5364 BFD_ASSERT ((insn & 0xff00) == 0xd400);
5365 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5366 BFD_ASSERT ((insn & 0xff00) == 0xc700);
5367 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5368 BFD_ASSERT ((insn & 0xff00) == 0xd100);
5369 insn = bfd_get_16 (input_bfd, contents + offset + 6);
5370 BFD_ASSERT (insn == 0x310c);
5371 insn = bfd_get_16 (input_bfd, contents + offset + 8);
5372 BFD_ASSERT (insn == 0x410b);
5373 insn = bfd_get_16 (input_bfd, contents + offset + 10);
5374 BFD_ASSERT (insn == 0x34cc);
5376 bfd_put_16 (output_bfd, 0x0012, contents + offset + 0);
5377 bfd_put_16 (output_bfd, 0x0009, contents + offset + 2);
5378 bfd_put_16 (output_bfd, 0x0009, contents + offset + 4);
5379 bfd_put_16 (output_bfd, 0x0009, contents + offset + 6);
5380 bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
5381 bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
5386 if (sgot == NULL || sgotplt == NULL)
5389 off = htab->tls_ldm_got.offset;
5394 Elf_Internal_Rela outrel;
5397 outrel.r_offset = (sgot->output_section->vma
5398 + sgot->output_offset + off);
5399 outrel.r_addend = 0;
5400 outrel.r_info = ELF32_R_INFO (0, R_SH_TLS_DTPMOD32);
5401 loc = srelgot->contents;
5402 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
5403 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5404 htab->tls_ldm_got.offset |= 1;
5407 relocation = sh_elf_got_offset (htab) + off;
5408 addend = rel->r_addend;
5410 goto final_link_relocate;
5412 case R_SH_TLS_LDO_32:
5413 check_segment[0] = check_segment[1] = -1;
5414 if (! bfd_link_pic (info))
5415 relocation = tpoff (info, relocation);
5417 relocation -= dtpoff_base (info);
5419 addend = rel->r_addend;
5420 goto final_link_relocate;
5422 case R_SH_TLS_LE_32:
5425 Elf_Internal_Rela outrel;
5428 check_segment[0] = check_segment[1] = -1;
5430 if (!bfd_link_dll (info))
5432 relocation = tpoff (info, relocation);
5433 addend = rel->r_addend;
5434 goto final_link_relocate;
5439 sreloc = _bfd_elf_get_dynamic_reloc_section
5440 (input_bfd, input_section, /*rela?*/ TRUE);
5445 if (h == NULL || h->dynindx == -1)
5450 outrel.r_offset = (input_section->output_section->vma
5451 + input_section->output_offset
5453 outrel.r_info = ELF32_R_INFO (indx, R_SH_TLS_TPOFF32);
5455 outrel.r_addend = relocation - dtpoff_base (info);
5457 outrel.r_addend = 0;
5459 loc = sreloc->contents;
5460 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
5461 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5467 if (fdpic_p && check_segment[0] != (unsigned) -1
5468 && check_segment[0] != check_segment[1])
5470 /* We don't want duplicate errors for undefined symbols. */
5471 if (!h || h->root.type != bfd_link_hash_undefined)
5473 if (bfd_link_pic (info))
5475 info->callbacks->einfo
5476 /* xgettext:c-format */
5477 (_("%X%C: relocation to \"%s\" references a different segment\n"),
5478 input_bfd, input_section, rel->r_offset, symname);
5482 info->callbacks->einfo
5483 /* xgettext:c-format */
5484 (_("%C: warning: relocation to \"%s\" references a different segment\n"),
5485 input_bfd, input_section, rel->r_offset, symname);
5488 elf_elfheader (output_bfd)->e_flags |= EF_SH_PIC;
5491 if (r != bfd_reloc_ok)
5496 case bfd_reloc_outofrange:
5498 case bfd_reloc_overflow:
5506 name = (bfd_elf_string_from_elf_section
5507 (input_bfd, symtab_hdr->sh_link, sym->st_name));
5511 name = bfd_section_name (input_bfd, sec);
5513 (*info->callbacks->reloc_overflow)
5514 (info, (h ? &h->root : NULL), name, howto->name,
5515 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
5525 /* This is a version of bfd_generic_get_relocated_section_contents
5526 which uses sh_elf_relocate_section. */
5529 sh_elf_get_relocated_section_contents (bfd *output_bfd,
5530 struct bfd_link_info *link_info,
5531 struct bfd_link_order *link_order,
5533 bfd_boolean relocatable,
5536 Elf_Internal_Shdr *symtab_hdr;
5537 asection *input_section = link_order->u.indirect.section;
5538 bfd *input_bfd = input_section->owner;
5539 asection **sections = NULL;
5540 Elf_Internal_Rela *internal_relocs = NULL;
5541 Elf_Internal_Sym *isymbuf = NULL;
5543 /* We only need to handle the case of relaxing, or of having a
5544 particular set of section contents, specially. */
5546 || elf_section_data (input_section)->this_hdr.contents == NULL)
5547 return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
5552 symtab_hdr = &elf_symtab_hdr (input_bfd);
5554 memcpy (data, elf_section_data (input_section)->this_hdr.contents,
5555 (size_t) input_section->size);
5557 if ((input_section->flags & SEC_RELOC) != 0
5558 && input_section->reloc_count > 0)
5561 Elf_Internal_Sym *isym, *isymend;
5564 internal_relocs = (_bfd_elf_link_read_relocs
5565 (input_bfd, input_section, NULL,
5566 (Elf_Internal_Rela *) NULL, FALSE));
5567 if (internal_relocs == NULL)
5570 if (symtab_hdr->sh_info != 0)
5572 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
5573 if (isymbuf == NULL)
5574 isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
5575 symtab_hdr->sh_info, 0,
5577 if (isymbuf == NULL)
5581 amt = symtab_hdr->sh_info;
5582 amt *= sizeof (asection *);
5583 sections = (asection **) bfd_malloc (amt);
5584 if (sections == NULL && amt != 0)
5587 isymend = isymbuf + symtab_hdr->sh_info;
5588 for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp)
5592 if (isym->st_shndx == SHN_UNDEF)
5593 isec = bfd_und_section_ptr;
5594 else if (isym->st_shndx == SHN_ABS)
5595 isec = bfd_abs_section_ptr;
5596 else if (isym->st_shndx == SHN_COMMON)
5597 isec = bfd_com_section_ptr;
5599 isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
5604 if (! sh_elf_relocate_section (output_bfd, link_info, input_bfd,
5605 input_section, data, internal_relocs,
5609 if (sections != NULL)
5612 && symtab_hdr->contents != (unsigned char *) isymbuf)
5614 if (elf_section_data (input_section)->relocs != internal_relocs)
5615 free (internal_relocs);
5621 if (sections != NULL)
5624 && symtab_hdr->contents != (unsigned char *) isymbuf)
5626 if (internal_relocs != NULL
5627 && elf_section_data (input_section)->relocs != internal_relocs)
5628 free (internal_relocs);
5632 /* Return the base VMA address which should be subtracted from real addresses
5633 when resolving @dtpoff relocation.
5634 This is PT_TLS segment p_vaddr. */
5637 dtpoff_base (struct bfd_link_info *info)
5639 /* If tls_sec is NULL, we should have signalled an error already. */
5640 if (elf_hash_table (info)->tls_sec == NULL)
5642 return elf_hash_table (info)->tls_sec->vma;
5645 /* Return the relocation value for R_SH_TLS_TPOFF32.. */
5648 tpoff (struct bfd_link_info *info, bfd_vma address)
5650 /* If tls_sec is NULL, we should have signalled an error already. */
5651 if (elf_hash_table (info)->tls_sec == NULL)
5653 /* SH TLS ABI is variant I and static TLS block start just after tcbhead
5654 structure which has 2 pointer fields. */
5655 return (address - elf_hash_table (info)->tls_sec->vma
5656 + align_power ((bfd_vma) 8,
5657 elf_hash_table (info)->tls_sec->alignment_power));
5661 sh_elf_gc_mark_hook (asection *sec,
5662 struct bfd_link_info *info,
5663 Elf_Internal_Rela *rel,
5664 struct elf_link_hash_entry *h,
5665 Elf_Internal_Sym *sym)
5668 switch (ELF32_R_TYPE (rel->r_info))
5670 case R_SH_GNU_VTINHERIT:
5671 case R_SH_GNU_VTENTRY:
5675 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
5678 /* Copy the extra info we tack onto an elf_link_hash_entry. */
5681 sh_elf_copy_indirect_symbol (struct bfd_link_info *info,
5682 struct elf_link_hash_entry *dir,
5683 struct elf_link_hash_entry *ind)
5685 struct elf_sh_link_hash_entry *edir, *eind;
5687 edir = (struct elf_sh_link_hash_entry *) dir;
5688 eind = (struct elf_sh_link_hash_entry *) ind;
5690 if (eind->dyn_relocs != NULL)
5692 if (edir->dyn_relocs != NULL)
5694 struct elf_dyn_relocs **pp;
5695 struct elf_dyn_relocs *p;
5697 /* Add reloc counts against the indirect sym to the direct sym
5698 list. Merge any entries against the same section. */
5699 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
5701 struct elf_dyn_relocs *q;
5703 for (q = edir->dyn_relocs; q != NULL; q = q->next)
5704 if (q->sec == p->sec)
5706 q->pc_count += p->pc_count;
5707 q->count += p->count;
5714 *pp = edir->dyn_relocs;
5717 edir->dyn_relocs = eind->dyn_relocs;
5718 eind->dyn_relocs = NULL;
5720 edir->gotplt_refcount = eind->gotplt_refcount;
5721 eind->gotplt_refcount = 0;
5722 #ifdef INCLUDE_SHMEDIA
5723 edir->datalabel_got.refcount += eind->datalabel_got.refcount;
5724 eind->datalabel_got.refcount = 0;
5726 edir->funcdesc.refcount += eind->funcdesc.refcount;
5727 eind->funcdesc.refcount = 0;
5728 edir->abs_funcdesc_refcount += eind->abs_funcdesc_refcount;
5729 eind->abs_funcdesc_refcount = 0;
5731 if (ind->root.type == bfd_link_hash_indirect
5732 && dir->got.refcount <= 0)
5734 edir->got_type = eind->got_type;
5735 eind->got_type = GOT_UNKNOWN;
5738 if (ind->root.type != bfd_link_hash_indirect
5739 && dir->dynamic_adjusted)
5741 /* If called to transfer flags for a weakdef during processing
5742 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
5743 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
5744 if (dir->versioned != versioned_hidden)
5745 dir->ref_dynamic |= ind->ref_dynamic;
5746 dir->ref_regular |= ind->ref_regular;
5747 dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
5748 dir->needs_plt |= ind->needs_plt;
5751 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
5755 sh_elf_optimized_tls_reloc (struct bfd_link_info *info, int r_type,
5758 if (bfd_link_pic (info))
5763 case R_SH_TLS_GD_32:
5764 case R_SH_TLS_IE_32:
5766 return R_SH_TLS_LE_32;
5767 return R_SH_TLS_IE_32;
5768 case R_SH_TLS_LD_32:
5769 return R_SH_TLS_LE_32;
5775 /* Look through the relocs for a section during the first phase.
5776 Since we don't do .gots or .plts, we just need to consider the
5777 virtual table relocs for gc. */
5780 sh_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
5781 const Elf_Internal_Rela *relocs)
5783 Elf_Internal_Shdr *symtab_hdr;
5784 struct elf_link_hash_entry **sym_hashes;
5785 struct elf_sh_link_hash_table *htab;
5786 const Elf_Internal_Rela *rel;
5787 const Elf_Internal_Rela *rel_end;
5789 unsigned int r_type;
5790 enum got_type got_type, old_got_type;
5794 if (bfd_link_relocatable (info))
5797 /* Don't do anything special with non-loaded, non-alloced sections.
5798 In particular, any relocs in such sections should not affect GOT
5799 and PLT reference counting (ie. we don't allow them to create GOT
5800 or PLT entries), there's no possibility or desire to optimize TLS
5801 relocs, and there's not much point in propagating relocs to shared
5802 libs that the dynamic linker won't relocate. */
5803 if ((sec->flags & SEC_ALLOC) == 0)
5806 BFD_ASSERT (is_sh_elf (abfd));
5808 symtab_hdr = &elf_symtab_hdr (abfd);
5809 sym_hashes = elf_sym_hashes (abfd);
5811 htab = sh_elf_hash_table (info);
5815 rel_end = relocs + sec->reloc_count;
5816 for (rel = relocs; rel < rel_end; rel++)
5818 struct elf_link_hash_entry *h;
5819 unsigned long r_symndx;
5820 #ifdef INCLUDE_SHMEDIA
5821 int seen_stt_datalabel = 0;
5824 r_symndx = ELF32_R_SYM (rel->r_info);
5825 r_type = ELF32_R_TYPE (rel->r_info);
5827 if (r_symndx < symtab_hdr->sh_info)
5831 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5832 while (h->root.type == bfd_link_hash_indirect
5833 || h->root.type == bfd_link_hash_warning)
5835 #ifdef INCLUDE_SHMEDIA
5836 seen_stt_datalabel |= h->type == STT_DATALABEL;
5838 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5842 r_type = sh_elf_optimized_tls_reloc (info, r_type, h == NULL);
5843 if (! bfd_link_pic (info)
5844 && r_type == R_SH_TLS_IE_32
5846 && h->root.type != bfd_link_hash_undefined
5847 && h->root.type != bfd_link_hash_undefweak
5848 && (h->dynindx == -1
5850 r_type = R_SH_TLS_LE_32;
5855 case R_SH_GOTOFFFUNCDESC:
5856 case R_SH_GOTOFFFUNCDESC20:
5858 case R_SH_GOTFUNCDESC:
5859 case R_SH_GOTFUNCDESC20:
5862 if (h->dynindx == -1)
5863 switch (ELF_ST_VISIBILITY (h->other))
5869 bfd_elf_link_record_dynamic_symbol (info, h);
5876 /* Some relocs require a global offset table. */
5877 if (htab->root.sgot == NULL)
5882 /* This may require an rofixup. */
5892 case R_SH_GOTFUNCDESC:
5893 case R_SH_GOTFUNCDESC20:
5894 case R_SH_GOTOFFFUNCDESC:
5895 case R_SH_GOTOFFFUNCDESC20:
5897 #ifdef INCLUDE_SHMEDIA
5898 case R_SH_GOTPLT_LOW16:
5899 case R_SH_GOTPLT_MEDLOW16:
5900 case R_SH_GOTPLT_MEDHI16:
5901 case R_SH_GOTPLT_HI16:
5902 case R_SH_GOTPLT10BY4:
5903 case R_SH_GOTPLT10BY8:
5904 case R_SH_GOT_LOW16:
5905 case R_SH_GOT_MEDLOW16:
5906 case R_SH_GOT_MEDHI16:
5910 case R_SH_GOTOFF_LOW16:
5911 case R_SH_GOTOFF_MEDLOW16:
5912 case R_SH_GOTOFF_MEDHI16:
5913 case R_SH_GOTOFF_HI16:
5914 case R_SH_GOTPC_LOW16:
5915 case R_SH_GOTPC_MEDLOW16:
5916 case R_SH_GOTPC_MEDHI16:
5917 case R_SH_GOTPC_HI16:
5919 case R_SH_TLS_GD_32:
5920 case R_SH_TLS_LD_32:
5921 case R_SH_TLS_IE_32:
5922 if (htab->root.dynobj == NULL)
5923 htab->root.dynobj = abfd;
5924 if (!create_got_section (htab->root.dynobj, info))
5935 /* This relocation describes the C++ object vtable hierarchy.
5936 Reconstruct it for later use during GC. */
5937 case R_SH_GNU_VTINHERIT:
5938 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
5942 /* This relocation describes which C++ vtable entries are actually
5943 used. Record for later use during GC. */
5944 case R_SH_GNU_VTENTRY:
5945 BFD_ASSERT (h != NULL);
5947 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
5951 case R_SH_TLS_IE_32:
5952 if (bfd_link_pic (info))
5953 info->flags |= DF_STATIC_TLS;
5957 case R_SH_TLS_GD_32:
5960 #ifdef INCLUDE_SHMEDIA
5961 case R_SH_GOT_LOW16:
5962 case R_SH_GOT_MEDLOW16:
5963 case R_SH_GOT_MEDHI16:
5968 case R_SH_GOTFUNCDESC:
5969 case R_SH_GOTFUNCDESC20:
5973 got_type = GOT_NORMAL;
5975 case R_SH_TLS_GD_32:
5976 got_type = GOT_TLS_GD;
5978 case R_SH_TLS_IE_32:
5979 got_type = GOT_TLS_IE;
5981 case R_SH_GOTFUNCDESC:
5982 case R_SH_GOTFUNCDESC20:
5983 got_type = GOT_FUNCDESC;
5989 #ifdef INCLUDE_SHMEDIA
5990 if (seen_stt_datalabel)
5992 struct elf_sh_link_hash_entry *eh
5993 = (struct elf_sh_link_hash_entry *) h;
5995 eh->datalabel_got.refcount += 1;
5999 h->got.refcount += 1;
6000 old_got_type = sh_elf_hash_entry (h)->got_type;
6004 bfd_signed_vma *local_got_refcounts;
6006 /* This is a global offset table entry for a local
6008 local_got_refcounts = elf_local_got_refcounts (abfd);
6009 if (local_got_refcounts == NULL)
6013 size = symtab_hdr->sh_info;
6014 size *= sizeof (bfd_signed_vma);
6015 #ifdef INCLUDE_SHMEDIA
6016 /* Reserve space for both the datalabel and
6017 codelabel local GOT offsets. */
6020 size += symtab_hdr->sh_info;
6021 local_got_refcounts = ((bfd_signed_vma *)
6022 bfd_zalloc (abfd, size));
6023 if (local_got_refcounts == NULL)
6025 elf_local_got_refcounts (abfd) = local_got_refcounts;
6026 #ifdef INCLUDE_SHMEDIA
6027 /* Take care of both the datalabel and codelabel local
6029 sh_elf_local_got_type (abfd)
6030 = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
6032 sh_elf_local_got_type (abfd)
6033 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
6036 #ifdef INCLUDE_SHMEDIA
6037 if (rel->r_addend & 1)
6038 local_got_refcounts[symtab_hdr->sh_info + r_symndx] += 1;
6041 local_got_refcounts[r_symndx] += 1;
6042 old_got_type = sh_elf_local_got_type (abfd) [r_symndx];
6045 /* If a TLS symbol is accessed using IE at least once,
6046 there is no point to use dynamic model for it. */
6047 if (old_got_type != got_type && old_got_type != GOT_UNKNOWN
6048 && (old_got_type != GOT_TLS_GD || got_type != GOT_TLS_IE))
6050 if (old_got_type == GOT_TLS_IE && got_type == GOT_TLS_GD)
6051 got_type = GOT_TLS_IE;
6054 if ((old_got_type == GOT_FUNCDESC || got_type == GOT_FUNCDESC)
6055 && (old_got_type == GOT_NORMAL || got_type == GOT_NORMAL))
6057 /* xgettext:c-format */
6058 (_("%pB: `%s' accessed both as normal and FDPIC symbol"),
6059 abfd, h->root.root.string);
6060 else if (old_got_type == GOT_FUNCDESC
6061 || got_type == GOT_FUNCDESC)
6063 /* xgettext:c-format */
6064 (_("%pB: `%s' accessed both as FDPIC and thread local symbol"),
6065 abfd, h->root.root.string);
6068 /* xgettext:c-format */
6069 (_("%pB: `%s' accessed both as normal and thread local symbol"),
6070 abfd, h->root.root.string);
6075 if (old_got_type != got_type)
6078 sh_elf_hash_entry (h)->got_type = got_type;
6080 sh_elf_local_got_type (abfd) [r_symndx] = got_type;
6085 case R_SH_TLS_LD_32:
6086 sh_elf_hash_table(info)->tls_ldm_got.refcount += 1;
6090 case R_SH_GOTOFFFUNCDESC:
6091 case R_SH_GOTOFFFUNCDESC20:
6095 (_("%pB: Function descriptor relocation with non-zero addend"),
6102 union gotref *local_funcdesc;
6104 /* We need a function descriptor for a local symbol. */
6105 local_funcdesc = sh_elf_local_funcdesc (abfd);
6106 if (local_funcdesc == NULL)
6110 size = symtab_hdr->sh_info * sizeof (union gotref);
6111 #ifdef INCLUDE_SHMEDIA
6112 /* Count datalabel local GOT. */
6115 local_funcdesc = (union gotref *) bfd_zalloc (abfd, size);
6116 if (local_funcdesc == NULL)
6118 sh_elf_local_funcdesc (abfd) = local_funcdesc;
6120 local_funcdesc[r_symndx].refcount += 1;
6122 if (r_type == R_SH_FUNCDESC)
6124 if (!bfd_link_pic (info))
6125 htab->srofixup->size += 4;
6127 htab->root.srelgot->size += sizeof (Elf32_External_Rela);
6132 sh_elf_hash_entry (h)->funcdesc.refcount++;
6133 if (r_type == R_SH_FUNCDESC)
6134 sh_elf_hash_entry (h)->abs_funcdesc_refcount++;
6136 /* If there is a function descriptor reference, then
6137 there should not be any non-FDPIC references. */
6138 old_got_type = sh_elf_hash_entry (h)->got_type;
6139 if (old_got_type != GOT_FUNCDESC && old_got_type != GOT_UNKNOWN)
6141 if (old_got_type == GOT_NORMAL)
6143 /* xgettext:c-format */
6144 (_("%pB: `%s' accessed both as normal and FDPIC symbol"),
6145 abfd, h->root.root.string);
6148 /* xgettext:c-format */
6149 (_("%pB: `%s' accessed both as FDPIC and thread local symbol"),
6150 abfd, h->root.root.string);
6156 #ifdef INCLUDE_SHMEDIA
6157 case R_SH_GOTPLT_LOW16:
6158 case R_SH_GOTPLT_MEDLOW16:
6159 case R_SH_GOTPLT_MEDHI16:
6160 case R_SH_GOTPLT_HI16:
6161 case R_SH_GOTPLT10BY4:
6162 case R_SH_GOTPLT10BY8:
6164 /* If this is a local symbol, we resolve it directly without
6165 creating a procedure linkage table entry. */
6169 || ! bfd_link_pic (info)
6171 || h->dynindx == -1)
6175 h->plt.refcount += 1;
6176 ((struct elf_sh_link_hash_entry *) h)->gotplt_refcount += 1;
6181 #ifdef INCLUDE_SHMEDIA
6182 case R_SH_PLT_LOW16:
6183 case R_SH_PLT_MEDLOW16:
6184 case R_SH_PLT_MEDHI16:
6187 /* This symbol requires a procedure linkage table entry. We
6188 actually build the entry in adjust_dynamic_symbol,
6189 because this might be a case of linking PIC code which is
6190 never referenced by a dynamic object, in which case we
6191 don't need to generate a procedure linkage table entry
6194 /* If this is a local symbol, we resolve it directly without
6195 creating a procedure linkage table entry. */
6199 if (h->forced_local)
6203 h->plt.refcount += 1;
6208 #ifdef INCLUDE_SHMEDIA
6209 case R_SH_IMM_LOW16_PCREL:
6210 case R_SH_IMM_MEDLOW16_PCREL:
6211 case R_SH_IMM_MEDHI16_PCREL:
6212 case R_SH_IMM_HI16_PCREL:
6214 if (h != NULL && ! bfd_link_pic (info))
6217 h->plt.refcount += 1;
6220 /* If we are creating a shared library, and this is a reloc
6221 against a global symbol, or a non PC relative reloc
6222 against a local symbol, then we need to copy the reloc
6223 into the shared library. However, if we are linking with
6224 -Bsymbolic, we do not need to copy a reloc against a
6225 global symbol which is defined in an object we are
6226 including in the link (i.e., DEF_REGULAR is set). At
6227 this point we have not seen all the input files, so it is
6228 possible that DEF_REGULAR is not set now but will be set
6229 later (it is never cleared). We account for that
6230 possibility below by storing information in the
6231 dyn_relocs field of the hash table entry. A similar
6232 situation occurs when creating shared libraries and symbol
6233 visibility changes render the symbol local.
6235 If on the other hand, we are creating an executable, we
6236 may need to keep relocations for symbols satisfied by a
6237 dynamic library if we manage to avoid copy relocs for the
6239 if ((bfd_link_pic (info)
6240 && (sec->flags & SEC_ALLOC) != 0
6241 && (r_type != R_SH_REL32
6243 && (! info->symbolic
6244 || h->root.type == bfd_link_hash_defweak
6245 || !h->def_regular))))
6246 || (! bfd_link_pic (info)
6247 && (sec->flags & SEC_ALLOC) != 0
6249 && (h->root.type == bfd_link_hash_defweak
6250 || !h->def_regular)))
6252 struct elf_dyn_relocs *p;
6253 struct elf_dyn_relocs **head;
6255 if (htab->root.dynobj == NULL)
6256 htab->root.dynobj = abfd;
6258 /* When creating a shared object, we must copy these
6259 reloc types into the output file. We create a reloc
6260 section in dynobj and make room for this reloc. */
6263 sreloc = _bfd_elf_make_dynamic_reloc_section
6264 (sec, htab->root.dynobj, 2, abfd, /*rela?*/ TRUE);
6270 /* If this is a global symbol, we count the number of
6271 relocations we need for this symbol. */
6273 head = &((struct elf_sh_link_hash_entry *) h)->dyn_relocs;
6276 /* Track dynamic relocs needed for local syms too. */
6279 Elf_Internal_Sym *isym;
6281 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
6286 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
6290 vpp = &elf_section_data (s)->local_dynrel;
6291 head = (struct elf_dyn_relocs **) vpp;
6295 if (p == NULL || p->sec != sec)
6297 bfd_size_type amt = sizeof (*p);
6298 p = bfd_alloc (htab->root.dynobj, amt);
6309 if (r_type == R_SH_REL32
6310 #ifdef INCLUDE_SHMEDIA
6311 || r_type == R_SH_IMM_LOW16_PCREL
6312 || r_type == R_SH_IMM_MEDLOW16_PCREL
6313 || r_type == R_SH_IMM_MEDHI16_PCREL
6314 || r_type == R_SH_IMM_HI16_PCREL
6320 /* Allocate the fixup regardless of whether we need a relocation.
6321 If we end up generating the relocation, we'll unallocate the
6323 if (htab->fdpic_p && !bfd_link_pic (info)
6324 && r_type == R_SH_DIR32
6325 && (sec->flags & SEC_ALLOC) != 0)
6326 htab->srofixup->size += 4;
6329 case R_SH_TLS_LE_32:
6330 if (bfd_link_dll (info))
6333 (_("%pB: TLS local exec code cannot be linked into shared objects"),
6340 case R_SH_TLS_LDO_32:
6341 /* Nothing to do. */
6352 #ifndef sh_elf_set_mach_from_flags
6353 static unsigned int sh_ef_bfd_table[] = { EF_SH_BFD_TABLE };
6356 sh_elf_set_mach_from_flags (bfd *abfd)
6358 flagword flags = elf_elfheader (abfd)->e_flags & EF_SH_MACH_MASK;
6360 if (flags >= ARRAY_SIZE (sh_ef_bfd_table))
6363 if (sh_ef_bfd_table[flags] == 0)
6366 bfd_default_set_arch_mach (abfd, bfd_arch_sh, sh_ef_bfd_table[flags]);
6372 /* Reverse table lookup for sh_ef_bfd_table[].
6373 Given a bfd MACH value from archures.c
6374 return the equivalent ELF flags from the table.
6375 Return -1 if no match is found. */
6378 sh_elf_get_flags_from_mach (unsigned long mach)
6380 int i = ARRAY_SIZE (sh_ef_bfd_table) - 1;
6383 if (sh_ef_bfd_table[i] == mach)
6386 /* shouldn't get here */
6391 #endif /* not sh_elf_set_mach_from_flags */
6393 #ifndef sh_elf_copy_private_data
6394 /* Copy backend specific data from one object module to another */
6397 sh_elf_copy_private_data (bfd * ibfd, bfd * obfd)
6399 if (! is_sh_elf (ibfd) || ! is_sh_elf (obfd))
6402 if (! _bfd_elf_copy_private_bfd_data (ibfd, obfd))
6405 return sh_elf_set_mach_from_flags (obfd);
6407 #endif /* not sh_elf_copy_private_data */
6409 #ifndef sh_elf_merge_private_data
6411 /* This function returns the ELF architecture number that
6412 corresponds to the given arch_sh* flags. */
6415 sh_find_elf_flags (unsigned int arch_set)
6417 extern unsigned long sh_get_bfd_mach_from_arch_set (unsigned int);
6418 unsigned long bfd_mach = sh_get_bfd_mach_from_arch_set (arch_set);
6420 return sh_elf_get_flags_from_mach (bfd_mach);
6423 /* Merge the architecture type of two BFD files, such that the
6424 resultant architecture supports all the features required
6425 by the two input BFDs.
6426 If the input BFDs are multually incompatible - i.e. one uses
6427 DSP while the other uses FPU - or there is no known architecture
6428 that fits the requirements then an error is emitted. */
6431 sh_merge_bfd_arch (bfd *ibfd, struct bfd_link_info *info)
6433 bfd *obfd = info->output_bfd;
6434 unsigned int old_arch, new_arch, merged_arch;
6436 if (! _bfd_generic_verify_endian_match (ibfd, info))
6439 old_arch = sh_get_arch_up_from_bfd_mach (bfd_get_mach (obfd));
6440 new_arch = sh_get_arch_up_from_bfd_mach (bfd_get_mach (ibfd));
6442 merged_arch = SH_MERGE_ARCH_SET (old_arch, new_arch);
6444 if (!SH_VALID_CO_ARCH_SET (merged_arch))
6447 /* xgettext:c-format */
6448 (_("%pB: uses %s instructions while previous modules "
6449 "use %s instructions"),
6451 SH_ARCH_SET_HAS_DSP (new_arch) ? "dsp" : "floating point",
6452 SH_ARCH_SET_HAS_DSP (new_arch) ? "floating point" : "dsp");
6453 bfd_set_error (bfd_error_bad_value);
6456 else if (!SH_VALID_ARCH_SET (merged_arch))
6459 /* xgettext:c-format */
6460 (_("internal error: merge of architecture '%s' with "
6461 "architecture '%s' produced unknown architecture"),
6462 bfd_printable_name (obfd),
6463 bfd_printable_name (ibfd));
6464 bfd_set_error (bfd_error_bad_value);
6468 bfd_default_set_arch_mach (obfd, bfd_arch_sh,
6469 sh_get_bfd_mach_from_arch_set (merged_arch));
6474 /* This routine initialises the elf flags when required and
6475 calls sh_merge_bfd_arch() to check dsp/fpu compatibility. */
6478 sh_elf_merge_private_data (bfd *ibfd, struct bfd_link_info *info)
6480 bfd *obfd = info->output_bfd;
6482 if (! is_sh_elf (ibfd) || ! is_sh_elf (obfd))
6485 if (! elf_flags_init (obfd))
6487 /* This happens when ld starts out with a 'blank' output file. */
6488 elf_flags_init (obfd) = TRUE;
6489 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
6490 sh_elf_set_mach_from_flags (obfd);
6491 if (elf_elfheader (obfd)->e_flags & EF_SH_FDPIC)
6492 elf_elfheader (obfd)->e_flags &= ~EF_SH_PIC;
6495 if (! sh_merge_bfd_arch (ibfd, info))
6497 _bfd_error_handler (_("%pB: uses instructions which are incompatible "
6498 "with instructions used in previous modules"),
6500 bfd_set_error (bfd_error_bad_value);
6504 elf_elfheader (obfd)->e_flags &= ~EF_SH_MACH_MASK;
6505 elf_elfheader (obfd)->e_flags |=
6506 sh_elf_get_flags_from_mach (bfd_get_mach (obfd));
6508 if (fdpic_object_p (ibfd) != fdpic_object_p (obfd))
6510 _bfd_error_handler (_("%pB: attempt to mix FDPIC and non-FDPIC objects"),
6512 bfd_set_error (bfd_error_bad_value);
6518 #endif /* not sh_elf_merge_private_data */
6520 /* Override the generic function because we need to store sh_elf_obj_tdata
6521 as the specific tdata. We set also the machine architecture from flags
6525 sh_elf_object_p (bfd *abfd)
6527 if (! sh_elf_set_mach_from_flags (abfd))
6530 return (((elf_elfheader (abfd)->e_flags & EF_SH_FDPIC) != 0)
6531 == fdpic_object_p (abfd));
6534 /* Finish up dynamic symbol handling. We set the contents of various
6535 dynamic sections here. */
6538 sh_elf_finish_dynamic_symbol (bfd *output_bfd, struct bfd_link_info *info,
6539 struct elf_link_hash_entry *h,
6540 Elf_Internal_Sym *sym)
6542 struct elf_sh_link_hash_table *htab;
6544 htab = sh_elf_hash_table (info);
6548 if (h->plt.offset != (bfd_vma) -1)
6556 Elf_Internal_Rela rel;
6558 const struct elf_sh_plt_info *plt_info;
6560 /* This symbol has an entry in the procedure linkage table. Set
6563 BFD_ASSERT (h->dynindx != -1);
6565 splt = htab->root.splt;
6566 sgotplt = htab->root.sgotplt;
6567 srelplt = htab->root.srelplt;
6568 BFD_ASSERT (splt != NULL && sgotplt != NULL && srelplt != NULL);
6570 /* Get the index in the procedure linkage table which
6571 corresponds to this symbol. This is the index of this symbol
6572 in all the symbols for which we are making plt entries. The
6573 first entry in the procedure linkage table is reserved. */
6574 plt_index = get_plt_index (htab->plt_info, h->plt.offset);
6576 plt_info = htab->plt_info;
6577 if (plt_info->short_plt != NULL && plt_index <= MAX_SHORT_PLT)
6578 plt_info = plt_info->short_plt;
6580 /* Get the offset into the .got table of the entry that
6581 corresponds to this function. */
6583 /* The offset must be relative to the GOT symbol, twelve bytes
6584 before the end of .got.plt. Each descriptor is eight
6586 got_offset = plt_index * 8 + 12 - sgotplt->size;
6588 /* Each .got entry is 4 bytes. The first three are
6590 got_offset = (plt_index + 3) * 4;
6593 if (bfd_link_pic (info))
6594 got_offset -= GOT_BIAS;
6597 /* Fill in the entry in the procedure linkage table. */
6598 memcpy (splt->contents + h->plt.offset,
6599 plt_info->symbol_entry,
6600 plt_info->symbol_entry_size);
6602 if (bfd_link_pic (info) || htab->fdpic_p)
6604 if (plt_info->symbol_fields.got20)
6606 bfd_reloc_status_type r;
6607 r = install_movi20_field (output_bfd, got_offset,
6608 splt->owner, splt, splt->contents,
6610 + plt_info->symbol_fields.got_entry);
6611 BFD_ASSERT (r == bfd_reloc_ok);
6614 install_plt_field (output_bfd, FALSE, got_offset,
6617 + plt_info->symbol_fields.got_entry));
6621 BFD_ASSERT (!plt_info->symbol_fields.got20);
6623 install_plt_field (output_bfd, FALSE,
6624 (sgotplt->output_section->vma
6625 + sgotplt->output_offset
6629 + plt_info->symbol_fields.got_entry));
6630 if (htab->vxworks_p)
6632 unsigned int reachable_plts, plts_per_4k;
6635 /* Divide the PLT into groups. The first group contains
6636 REACHABLE_PLTS entries and the other groups contain
6637 PLTS_PER_4K entries. Entries in the first group can
6638 branch directly to .plt; those in later groups branch
6639 to the last element of the previous group. */
6640 /* ??? It would be better to create multiple copies of
6641 the common resolver stub. */
6642 reachable_plts = ((4096
6643 - plt_info->plt0_entry_size
6644 - (plt_info->symbol_fields.plt + 4))
6645 / plt_info->symbol_entry_size) + 1;
6646 plts_per_4k = (4096 / plt_info->symbol_entry_size);
6647 if (plt_index < reachable_plts)
6648 distance = -(h->plt.offset
6649 + plt_info->symbol_fields.plt);
6651 distance = -(((plt_index - reachable_plts) % plts_per_4k + 1)
6652 * plt_info->symbol_entry_size);
6654 /* Install the 'bra' with this offset. */
6655 bfd_put_16 (output_bfd,
6656 0xa000 | (0x0fff & ((distance - 4) / 2)),
6659 + plt_info->symbol_fields.plt));
6662 install_plt_field (output_bfd, TRUE,
6663 splt->output_section->vma + splt->output_offset,
6666 + plt_info->symbol_fields.plt));
6669 /* Make got_offset relative to the start of .got.plt. */
6671 if (bfd_link_pic (info))
6672 got_offset += GOT_BIAS;
6675 got_offset = plt_index * 8;
6677 if (plt_info->symbol_fields.reloc_offset != MINUS_ONE)
6678 install_plt_field (output_bfd, FALSE,
6679 plt_index * sizeof (Elf32_External_Rela),
6682 + plt_info->symbol_fields.reloc_offset));
6684 /* Fill in the entry in the global offset table. */
6685 bfd_put_32 (output_bfd,
6686 (splt->output_section->vma
6687 + splt->output_offset
6689 + plt_info->symbol_resolve_offset),
6690 sgotplt->contents + got_offset);
6692 bfd_put_32 (output_bfd,
6693 sh_elf_osec_to_segment (output_bfd, splt->output_section),
6694 sgotplt->contents + got_offset + 4);
6696 /* Fill in the entry in the .rela.plt section. */
6697 rel.r_offset = (sgotplt->output_section->vma
6698 + sgotplt->output_offset
6701 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_FUNCDESC_VALUE);
6703 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_JMP_SLOT);
6706 rel.r_addend = GOT_BIAS;
6708 loc = srelplt->contents + plt_index * sizeof (Elf32_External_Rela);
6709 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
6711 if (htab->vxworks_p && !bfd_link_pic (info))
6713 /* Create the .rela.plt.unloaded relocations for this PLT entry.
6714 Begin by pointing LOC to the first such relocation. */
6715 loc = (htab->srelplt2->contents
6716 + (plt_index * 2 + 1) * sizeof (Elf32_External_Rela));
6718 /* Create a .rela.plt.unloaded R_SH_DIR32 relocation
6719 for the PLT entry's pointer to the .got.plt entry. */
6720 rel.r_offset = (splt->output_section->vma
6721 + splt->output_offset
6723 + plt_info->symbol_fields.got_entry);
6724 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_SH_DIR32);
6725 rel.r_addend = got_offset;
6726 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
6727 loc += sizeof (Elf32_External_Rela);
6729 /* Create a .rela.plt.unloaded R_SH_DIR32 relocation for
6730 the .got.plt entry, which initially points to .plt. */
6731 rel.r_offset = (sgotplt->output_section->vma
6732 + sgotplt->output_offset
6734 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_SH_DIR32);
6736 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
6739 if (!h->def_regular)
6741 /* Mark the symbol as undefined, rather than as defined in
6742 the .plt section. Leave the value alone. */
6743 sym->st_shndx = SHN_UNDEF;
6747 if (h->got.offset != (bfd_vma) -1
6748 && sh_elf_hash_entry (h)->got_type != GOT_TLS_GD
6749 && sh_elf_hash_entry (h)->got_type != GOT_TLS_IE
6750 && sh_elf_hash_entry (h)->got_type != GOT_FUNCDESC)
6754 Elf_Internal_Rela rel;
6757 /* This symbol has an entry in the global offset table. Set it
6760 sgot = htab->root.sgot;
6761 srelgot = htab->root.srelgot;
6762 BFD_ASSERT (sgot != NULL && srelgot != NULL);
6764 rel.r_offset = (sgot->output_section->vma
6765 + sgot->output_offset
6766 + (h->got.offset &~ (bfd_vma) 1));
6768 /* If this is a static link, or it is a -Bsymbolic link and the
6769 symbol is defined locally or was forced to be local because
6770 of a version file, we just want to emit a RELATIVE reloc.
6771 The entry in the global offset table will already have been
6772 initialized in the relocate_section function. */
6773 if (bfd_link_pic (info)
6774 && SYMBOL_REFERENCES_LOCAL (info, h))
6778 asection *sec = h->root.u.def.section;
6780 = elf_section_data (sec->output_section)->dynindx;
6782 rel.r_info = ELF32_R_INFO (dynindx, R_SH_DIR32);
6783 rel.r_addend = (h->root.u.def.value
6784 + h->root.u.def.section->output_offset);
6788 rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
6789 rel.r_addend = (h->root.u.def.value
6790 + h->root.u.def.section->output_section->vma
6791 + h->root.u.def.section->output_offset);
6796 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
6797 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_GLOB_DAT);
6801 loc = srelgot->contents;
6802 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
6803 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
6806 #ifdef INCLUDE_SHMEDIA
6808 struct elf_sh_link_hash_entry *eh;
6810 eh = (struct elf_sh_link_hash_entry *) h;
6811 if (eh->datalabel_got.offset != (bfd_vma) -1)
6815 Elf_Internal_Rela rel;
6818 /* This symbol has a datalabel entry in the global offset table.
6821 sgot = htab->root.sgot;
6822 srelgot = htab->root.srelgot;
6823 BFD_ASSERT (sgot != NULL && srelgot != NULL);
6825 rel.r_offset = (sgot->output_section->vma
6826 + sgot->output_offset
6827 + (eh->datalabel_got.offset &~ (bfd_vma) 1));
6829 /* If this is a static link, or it is a -Bsymbolic link and the
6830 symbol is defined locally or was forced to be local because
6831 of a version file, we just want to emit a RELATIVE reloc.
6832 The entry in the global offset table will already have been
6833 initialized in the relocate_section function. */
6834 if (bfd_link_pic (info)
6835 && SYMBOL_REFERENCES_LOCAL (info, h))
6839 asection *sec = h->root.u.def.section;
6841 = elf_section_data (sec->output_section)->dynindx;
6843 rel.r_info = ELF32_R_INFO (dynindx, R_SH_DIR32);
6844 rel.r_addend = (h->root.u.def.value
6845 + h->root.u.def.section->output_offset);
6849 rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
6850 rel.r_addend = (h->root.u.def.value
6851 + h->root.u.def.section->output_section->vma
6852 + h->root.u.def.section->output_offset);
6857 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents
6858 + eh->datalabel_got.offset);
6859 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_GLOB_DAT);
6863 loc = srelgot->contents;
6864 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
6865 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
6873 Elf_Internal_Rela rel;
6876 /* This symbol needs a copy reloc. Set it up. */
6878 BFD_ASSERT (h->dynindx != -1
6879 && (h->root.type == bfd_link_hash_defined
6880 || h->root.type == bfd_link_hash_defweak));
6882 s = bfd_get_linker_section (htab->root.dynobj, ".rela.bss");
6883 BFD_ASSERT (s != NULL);
6885 rel.r_offset = (h->root.u.def.value
6886 + h->root.u.def.section->output_section->vma
6887 + h->root.u.def.section->output_offset);
6888 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_COPY);
6890 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
6891 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
6894 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
6895 _GLOBAL_OFFSET_TABLE_ is not absolute: it is relative to the
6897 if (h == htab->root.hdynamic
6898 || (!htab->vxworks_p && h == htab->root.hgot))
6899 sym->st_shndx = SHN_ABS;
6904 /* Finish up the dynamic sections. */
6907 sh_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
6909 struct elf_sh_link_hash_table *htab;
6913 htab = sh_elf_hash_table (info);
6917 sgotplt = htab->root.sgotplt;
6918 sdyn = bfd_get_linker_section (htab->root.dynobj, ".dynamic");
6920 if (htab->root.dynamic_sections_created)
6923 Elf32_External_Dyn *dyncon, *dynconend;
6925 BFD_ASSERT (sgotplt != NULL && sdyn != NULL);
6927 dyncon = (Elf32_External_Dyn *) sdyn->contents;
6928 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
6929 for (; dyncon < dynconend; dyncon++)
6931 Elf_Internal_Dyn dyn;
6933 #ifdef INCLUDE_SHMEDIA
6937 bfd_elf32_swap_dyn_in (htab->root.dynobj, dyncon, &dyn);
6943 && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
6944 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6947 #ifdef INCLUDE_SHMEDIA
6949 name = info->init_function;
6953 name = info->fini_function;
6955 if (dyn.d_un.d_val != 0)
6957 struct elf_link_hash_entry *h;
6959 h = elf_link_hash_lookup (&htab->root, name,
6960 FALSE, FALSE, TRUE);
6961 if (h != NULL && (h->other & STO_SH5_ISA32))
6963 dyn.d_un.d_val |= 1;
6964 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6971 BFD_ASSERT (htab->root.hgot != NULL);
6972 s = htab->root.hgot->root.u.def.section;
6973 dyn.d_un.d_ptr = htab->root.hgot->root.u.def.value
6974 + s->output_section->vma + s->output_offset;
6975 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6979 s = htab->root.srelplt->output_section;
6980 BFD_ASSERT (s != NULL);
6981 dyn.d_un.d_ptr = s->vma;
6982 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6986 s = htab->root.srelplt->output_section;
6987 BFD_ASSERT (s != NULL);
6988 dyn.d_un.d_val = s->size;
6989 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6994 /* Fill in the first entry in the procedure linkage table. */
6995 splt = htab->root.splt;
6996 if (splt && splt->size > 0 && htab->plt_info->plt0_entry)
7000 memcpy (splt->contents,
7001 htab->plt_info->plt0_entry,
7002 htab->plt_info->plt0_entry_size);
7003 for (i = 0; i < ARRAY_SIZE (htab->plt_info->plt0_got_fields); i++)
7004 if (htab->plt_info->plt0_got_fields[i] != MINUS_ONE)
7005 install_plt_field (output_bfd, FALSE,
7006 (sgotplt->output_section->vma
7007 + sgotplt->output_offset
7010 + htab->plt_info->plt0_got_fields[i]));
7012 if (htab->vxworks_p)
7014 /* Finalize the .rela.plt.unloaded contents. */
7015 Elf_Internal_Rela rel;
7018 /* Create a .rela.plt.unloaded R_SH_DIR32 relocation for the
7019 first PLT entry's pointer to _GLOBAL_OFFSET_TABLE_ + 8. */
7020 loc = htab->srelplt2->contents;
7021 rel.r_offset = (splt->output_section->vma
7022 + splt->output_offset
7023 + htab->plt_info->plt0_got_fields[2]);
7024 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_SH_DIR32);
7026 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
7027 loc += sizeof (Elf32_External_Rela);
7029 /* Fix up the remaining .rela.plt.unloaded relocations.
7030 They may have the wrong symbol index for _G_O_T_ or
7031 _P_L_T_ depending on the order in which symbols were
7033 while (loc < htab->srelplt2->contents + htab->srelplt2->size)
7035 /* The PLT entry's pointer to the .got.plt slot. */
7036 bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
7037 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx,
7039 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
7040 loc += sizeof (Elf32_External_Rela);
7042 /* The .got.plt slot's pointer to .plt. */
7043 bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
7044 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx,
7046 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
7047 loc += sizeof (Elf32_External_Rela);
7051 /* UnixWare sets the entsize of .plt to 4, although that doesn't
7052 really seem like the right value. */
7053 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
7057 /* Fill in the first three entries in the global offset table. */
7058 if (sgotplt && sgotplt->size > 0 && !htab->fdpic_p)
7061 bfd_put_32 (output_bfd, (bfd_vma) 0, sgotplt->contents);
7063 bfd_put_32 (output_bfd,
7064 sdyn->output_section->vma + sdyn->output_offset,
7066 bfd_put_32 (output_bfd, (bfd_vma) 0, sgotplt->contents + 4);
7067 bfd_put_32 (output_bfd, (bfd_vma) 0, sgotplt->contents + 8);
7070 if (sgotplt && sgotplt->size > 0)
7071 elf_section_data (sgotplt->output_section)->this_hdr.sh_entsize = 4;
7073 /* At the very end of the .rofixup section is a pointer to the GOT. */
7074 if (htab->fdpic_p && htab->srofixup != NULL)
7076 struct elf_link_hash_entry *hgot = htab->root.hgot;
7077 bfd_vma got_value = hgot->root.u.def.value
7078 + hgot->root.u.def.section->output_section->vma
7079 + hgot->root.u.def.section->output_offset;
7081 sh_elf_add_rofixup (output_bfd, htab->srofixup, got_value);
7083 /* Make sure we allocated and generated the same number of fixups. */
7084 BFD_ASSERT (htab->srofixup->reloc_count * 4 == htab->srofixup->size);
7087 if (htab->srelfuncdesc)
7088 BFD_ASSERT (htab->srelfuncdesc->reloc_count * sizeof (Elf32_External_Rela)
7089 == htab->srelfuncdesc->size);
7091 if (htab->root.srelgot)
7092 BFD_ASSERT (htab->root.srelgot->reloc_count * sizeof (Elf32_External_Rela)
7093 == htab->root.srelgot->size);
7098 static enum elf_reloc_type_class
7099 sh_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
7100 const asection *rel_sec ATTRIBUTE_UNUSED,
7101 const Elf_Internal_Rela *rela)
7103 switch ((int) ELF32_R_TYPE (rela->r_info))
7106 return reloc_class_relative;
7108 return reloc_class_plt;
7110 return reloc_class_copy;
7112 return reloc_class_normal;
7116 #if !defined SH_TARGET_ALREADY_DEFINED
7117 /* Support for Linux core dump NOTE sections. */
7120 elf32_shlin_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
7125 switch (note->descsz)
7130 case 168: /* Linux/SH */
7132 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
7135 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
7144 /* Make a ".reg/999" section. */
7145 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
7146 size, note->descpos + offset);
7150 elf32_shlin_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
7152 switch (note->descsz)
7157 case 124: /* Linux/SH elf_prpsinfo */
7158 elf_tdata (abfd)->core->program
7159 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
7160 elf_tdata (abfd)->core->command
7161 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
7164 /* Note that for some reason, a spurious space is tacked
7165 onto the end of the args in some (at least one anyway)
7166 implementations, so strip it off if it exists. */
7169 char *command = elf_tdata (abfd)->core->command;
7170 int n = strlen (command);
7172 if (0 < n && command[n - 1] == ' ')
7173 command[n - 1] = '\0';
7178 #endif /* not SH_TARGET_ALREADY_DEFINED */
7181 /* Return address for Ith PLT stub in section PLT, for relocation REL
7182 or (bfd_vma) -1 if it should not be included. */
7185 sh_elf_plt_sym_val (bfd_vma i, const asection *plt,
7186 const arelent *rel ATTRIBUTE_UNUSED)
7188 const struct elf_sh_plt_info *plt_info;
7190 plt_info = get_plt_info (plt->owner, (plt->owner->flags & DYNAMIC) != 0);
7191 return plt->vma + get_plt_offset (plt_info, i);
7194 /* Decide whether to attempt to turn absptr or lsda encodings in
7195 shared libraries into pcrel within the given input section. */
7198 sh_elf_use_relative_eh_frame (bfd *input_bfd ATTRIBUTE_UNUSED,
7199 struct bfd_link_info *info,
7200 asection *eh_frame_section ATTRIBUTE_UNUSED)
7202 struct elf_sh_link_hash_table *htab = sh_elf_hash_table (info);
7204 /* We can't use PC-relative encodings in FDPIC binaries, in general. */
7211 /* Adjust the contents of an eh_frame_hdr section before they're output. */
7214 sh_elf_encode_eh_address (bfd *abfd,
7215 struct bfd_link_info *info,
7216 asection *osec, bfd_vma offset,
7217 asection *loc_sec, bfd_vma loc_offset,
7220 struct elf_sh_link_hash_table *htab = sh_elf_hash_table (info);
7221 struct elf_link_hash_entry *h;
7224 return _bfd_elf_encode_eh_address (abfd, info, osec, offset, loc_sec,
7225 loc_offset, encoded);
7227 h = htab->root.hgot;
7228 BFD_ASSERT (h && h->root.type == bfd_link_hash_defined);
7230 if (! h || (sh_elf_osec_to_segment (abfd, osec)
7231 == sh_elf_osec_to_segment (abfd, loc_sec->output_section)))
7232 return _bfd_elf_encode_eh_address (abfd, info, osec, offset,
7233 loc_sec, loc_offset, encoded);
7235 BFD_ASSERT (sh_elf_osec_to_segment (abfd, osec)
7236 == (sh_elf_osec_to_segment
7237 (abfd, h->root.u.def.section->output_section)));
7239 *encoded = osec->vma + offset
7240 - (h->root.u.def.value
7241 + h->root.u.def.section->output_section->vma
7242 + h->root.u.def.section->output_offset);
7244 return DW_EH_PE_datarel | DW_EH_PE_sdata4;
7247 #if !defined SH_TARGET_ALREADY_DEFINED
7248 #define TARGET_BIG_SYM sh_elf32_vec
7249 #define TARGET_BIG_NAME "elf32-sh"
7250 #define TARGET_LITTLE_SYM sh_elf32_le_vec
7251 #define TARGET_LITTLE_NAME "elf32-shl"
7254 #define ELF_ARCH bfd_arch_sh
7255 #define ELF_TARGET_ID SH_ELF_DATA
7256 #define ELF_MACHINE_CODE EM_SH
7257 #ifdef __QNXTARGET__
7258 #define ELF_MAXPAGESIZE 0x1000
7260 #define ELF_MAXPAGESIZE 0x80
7263 #define elf_symbol_leading_char '_'
7265 #define bfd_elf32_bfd_reloc_type_lookup sh_elf_reloc_type_lookup
7266 #define bfd_elf32_bfd_reloc_name_lookup \
7267 sh_elf_reloc_name_lookup
7268 #define elf_info_to_howto sh_elf_info_to_howto
7269 #define bfd_elf32_bfd_relax_section sh_elf_relax_section
7270 #define elf_backend_relocate_section sh_elf_relocate_section
7271 #define bfd_elf32_bfd_get_relocated_section_contents \
7272 sh_elf_get_relocated_section_contents
7273 #define bfd_elf32_mkobject sh_elf_mkobject
7274 #define elf_backend_object_p sh_elf_object_p
7275 #define bfd_elf32_bfd_copy_private_bfd_data \
7276 sh_elf_copy_private_data
7277 #define bfd_elf32_bfd_merge_private_bfd_data \
7278 sh_elf_merge_private_data
7280 #define elf_backend_gc_mark_hook sh_elf_gc_mark_hook
7281 #define elf_backend_check_relocs sh_elf_check_relocs
7282 #define elf_backend_copy_indirect_symbol \
7283 sh_elf_copy_indirect_symbol
7284 #define elf_backend_create_dynamic_sections \
7285 sh_elf_create_dynamic_sections
7286 #define bfd_elf32_bfd_link_hash_table_create \
7287 sh_elf_link_hash_table_create
7288 #define elf_backend_adjust_dynamic_symbol \
7289 sh_elf_adjust_dynamic_symbol
7290 #define elf_backend_always_size_sections \
7291 sh_elf_always_size_sections
7292 #define elf_backend_size_dynamic_sections \
7293 sh_elf_size_dynamic_sections
7294 #define elf_backend_omit_section_dynsym sh_elf_omit_section_dynsym
7295 #define elf_backend_finish_dynamic_symbol \
7296 sh_elf_finish_dynamic_symbol
7297 #define elf_backend_finish_dynamic_sections \
7298 sh_elf_finish_dynamic_sections
7299 #define elf_backend_reloc_type_class sh_elf_reloc_type_class
7300 #define elf_backend_plt_sym_val sh_elf_plt_sym_val
7301 #define elf_backend_can_make_relative_eh_frame \
7302 sh_elf_use_relative_eh_frame
7303 #define elf_backend_can_make_lsda_relative_eh_frame \
7304 sh_elf_use_relative_eh_frame
7305 #define elf_backend_encode_eh_address \
7306 sh_elf_encode_eh_address
7308 #define elf_backend_stack_align 8
7309 #define elf_backend_can_gc_sections 1
7310 #define elf_backend_can_refcount 1
7311 #define elf_backend_want_got_plt 1
7312 #define elf_backend_plt_readonly 1
7313 #define elf_backend_want_plt_sym 0
7314 #define elf_backend_got_header_size 12
7315 #define elf_backend_dtrel_excludes_plt 1
7317 #define elf_backend_linux_prpsinfo32_ugid16 TRUE
7319 #if !defined INCLUDE_SHMEDIA && !defined SH_TARGET_ALREADY_DEFINED
7321 #include "elf32-target.h"
7323 /* NetBSD support. */
7324 #undef TARGET_BIG_SYM
7325 #define TARGET_BIG_SYM sh_elf32_nbsd_vec
7326 #undef TARGET_BIG_NAME
7327 #define TARGET_BIG_NAME "elf32-sh-nbsd"
7328 #undef TARGET_LITTLE_SYM
7329 #define TARGET_LITTLE_SYM sh_elf32_nbsd_le_vec
7330 #undef TARGET_LITTLE_NAME
7331 #define TARGET_LITTLE_NAME "elf32-shl-nbsd"
7332 #undef ELF_MAXPAGESIZE
7333 #define ELF_MAXPAGESIZE 0x10000
7334 #undef ELF_COMMONPAGESIZE
7335 #undef elf_symbol_leading_char
7336 #define elf_symbol_leading_char 0
7338 #define elf32_bed elf32_sh_nbsd_bed
7340 #include "elf32-target.h"
7343 /* Linux support. */
7344 #undef TARGET_BIG_SYM
7345 #define TARGET_BIG_SYM sh_elf32_linux_be_vec
7346 #undef TARGET_BIG_NAME
7347 #define TARGET_BIG_NAME "elf32-shbig-linux"
7348 #undef TARGET_LITTLE_SYM
7349 #define TARGET_LITTLE_SYM sh_elf32_linux_vec
7350 #undef TARGET_LITTLE_NAME
7351 #define TARGET_LITTLE_NAME "elf32-sh-linux"
7352 #undef ELF_COMMONPAGESIZE
7353 #define ELF_COMMONPAGESIZE 0x1000
7355 #undef elf_backend_grok_prstatus
7356 #define elf_backend_grok_prstatus elf32_shlin_grok_prstatus
7357 #undef elf_backend_grok_psinfo
7358 #define elf_backend_grok_psinfo elf32_shlin_grok_psinfo
7360 #define elf32_bed elf32_sh_lin_bed
7362 #include "elf32-target.h"
7365 /* FDPIC support. */
7366 #undef TARGET_BIG_SYM
7367 #define TARGET_BIG_SYM sh_elf32_fdpic_be_vec
7368 #undef TARGET_BIG_NAME
7369 #define TARGET_BIG_NAME "elf32-shbig-fdpic"
7370 #undef TARGET_LITTLE_SYM
7371 #define TARGET_LITTLE_SYM sh_elf32_fdpic_le_vec
7372 #undef TARGET_LITTLE_NAME
7373 #define TARGET_LITTLE_NAME "elf32-sh-fdpic"
7376 #define elf32_bed elf32_sh_fd_bed
7378 #include "elf32-target.h"
7380 #undef elf_backend_modify_program_headers
7382 /* VxWorks support. */
7383 #undef TARGET_BIG_SYM
7384 #define TARGET_BIG_SYM sh_elf32_vxworks_vec
7385 #undef TARGET_BIG_NAME
7386 #define TARGET_BIG_NAME "elf32-sh-vxworks"
7387 #undef TARGET_LITTLE_SYM
7388 #define TARGET_LITTLE_SYM sh_elf32_vxworks_le_vec
7389 #undef TARGET_LITTLE_NAME
7390 #define TARGET_LITTLE_NAME "elf32-shl-vxworks"
7392 #define elf32_bed elf32_sh_vxworks_bed
7394 #undef elf_backend_want_plt_sym
7395 #define elf_backend_want_plt_sym 1
7396 #undef elf_symbol_leading_char
7397 #define elf_symbol_leading_char '_'
7398 #define elf_backend_want_got_underscore 1
7399 #undef elf_backend_grok_prstatus
7400 #undef elf_backend_grok_psinfo
7401 #undef elf_backend_add_symbol_hook
7402 #define elf_backend_add_symbol_hook elf_vxworks_add_symbol_hook
7403 #undef elf_backend_link_output_symbol_hook
7404 #define elf_backend_link_output_symbol_hook \
7405 elf_vxworks_link_output_symbol_hook
7406 #undef elf_backend_emit_relocs
7407 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
7408 #undef elf_backend_final_write_processing
7409 #define elf_backend_final_write_processing \
7410 elf_vxworks_final_write_processing
7411 #undef ELF_MAXPAGESIZE
7412 #define ELF_MAXPAGESIZE 0x1000
7413 #undef ELF_COMMONPAGESIZE
7415 #include "elf32-target.h"
7417 #endif /* neither INCLUDE_SHMEDIA nor SH_TARGET_ALREADY_DEFINED */