1 /* Renesas / SuperH SH specific support for 32-bit ELF
2 Copyright (C) 1996-2014 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 if (bfd_is_com_section (symbol_in->section))
261 sym_value = (symbol_in->value +
262 symbol_in->section->output_section->vma +
263 symbol_in->section->output_offset);
268 insn = bfd_get_32 (abfd, hit_data);
269 insn += sym_value + reloc_entry->addend;
270 bfd_put_32 (abfd, (bfd_vma) insn, hit_data);
273 insn = bfd_get_16 (abfd, hit_data);
274 sym_value += reloc_entry->addend;
275 sym_value -= (input_section->output_section->vma
276 + input_section->output_offset
279 sym_value += (insn & 0xfff) << 1;
282 insn = (insn & 0xf000) | (sym_value & 0xfff);
283 bfd_put_16 (abfd, (bfd_vma) insn, hit_data);
284 if (sym_value < (bfd_vma) -0x1000 || sym_value >= 0x1000)
285 return bfd_reloc_overflow;
295 /* This function is used for relocs which are only used for relaxing,
296 which the linker should otherwise ignore. */
298 static bfd_reloc_status_type
299 sh_elf_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc_entry,
300 asymbol *symbol ATTRIBUTE_UNUSED,
301 void *data ATTRIBUTE_UNUSED, asection *input_section,
303 char **error_message ATTRIBUTE_UNUSED)
305 if (output_bfd != NULL)
306 reloc_entry->address += input_section->output_offset;
310 /* This structure is used to map BFD reloc codes to SH ELF relocs. */
314 bfd_reloc_code_real_type bfd_reloc_val;
315 unsigned char elf_reloc_val;
318 /* An array mapping BFD reloc codes to SH ELF relocs. */
320 static const struct elf_reloc_map sh_reloc_map[] =
322 { BFD_RELOC_NONE, R_SH_NONE },
323 { BFD_RELOC_32, R_SH_DIR32 },
324 { BFD_RELOC_16, R_SH_DIR16 },
325 { BFD_RELOC_8, R_SH_DIR8 },
326 { BFD_RELOC_CTOR, R_SH_DIR32 },
327 { BFD_RELOC_32_PCREL, R_SH_REL32 },
328 { BFD_RELOC_SH_PCDISP8BY2, R_SH_DIR8WPN },
329 { BFD_RELOC_SH_PCDISP12BY2, R_SH_IND12W },
330 { BFD_RELOC_SH_PCRELIMM8BY2, R_SH_DIR8WPZ },
331 { BFD_RELOC_SH_PCRELIMM8BY4, R_SH_DIR8WPL },
332 { BFD_RELOC_8_PCREL, R_SH_SWITCH8 },
333 { BFD_RELOC_SH_SWITCH16, R_SH_SWITCH16 },
334 { BFD_RELOC_SH_SWITCH32, R_SH_SWITCH32 },
335 { BFD_RELOC_SH_USES, R_SH_USES },
336 { BFD_RELOC_SH_COUNT, R_SH_COUNT },
337 { BFD_RELOC_SH_ALIGN, R_SH_ALIGN },
338 { BFD_RELOC_SH_CODE, R_SH_CODE },
339 { BFD_RELOC_SH_DATA, R_SH_DATA },
340 { BFD_RELOC_SH_LABEL, R_SH_LABEL },
341 { BFD_RELOC_VTABLE_INHERIT, R_SH_GNU_VTINHERIT },
342 { BFD_RELOC_VTABLE_ENTRY, R_SH_GNU_VTENTRY },
343 { BFD_RELOC_SH_LOOP_START, R_SH_LOOP_START },
344 { BFD_RELOC_SH_LOOP_END, R_SH_LOOP_END },
345 { BFD_RELOC_SH_TLS_GD_32, R_SH_TLS_GD_32 },
346 { BFD_RELOC_SH_TLS_LD_32, R_SH_TLS_LD_32 },
347 { BFD_RELOC_SH_TLS_LDO_32, R_SH_TLS_LDO_32 },
348 { BFD_RELOC_SH_TLS_IE_32, R_SH_TLS_IE_32 },
349 { BFD_RELOC_SH_TLS_LE_32, R_SH_TLS_LE_32 },
350 { BFD_RELOC_SH_TLS_DTPMOD32, R_SH_TLS_DTPMOD32 },
351 { BFD_RELOC_SH_TLS_DTPOFF32, R_SH_TLS_DTPOFF32 },
352 { BFD_RELOC_SH_TLS_TPOFF32, R_SH_TLS_TPOFF32 },
353 { BFD_RELOC_32_GOT_PCREL, R_SH_GOT32 },
354 { BFD_RELOC_32_PLT_PCREL, R_SH_PLT32 },
355 { BFD_RELOC_SH_COPY, R_SH_COPY },
356 { BFD_RELOC_SH_GLOB_DAT, R_SH_GLOB_DAT },
357 { BFD_RELOC_SH_JMP_SLOT, R_SH_JMP_SLOT },
358 { BFD_RELOC_SH_RELATIVE, R_SH_RELATIVE },
359 { BFD_RELOC_32_GOTOFF, R_SH_GOTOFF },
360 { BFD_RELOC_SH_GOTPC, R_SH_GOTPC },
361 { BFD_RELOC_SH_GOTPLT32, R_SH_GOTPLT32 },
362 { BFD_RELOC_SH_GOT20, R_SH_GOT20 },
363 { BFD_RELOC_SH_GOTOFF20, R_SH_GOTOFF20 },
364 { BFD_RELOC_SH_GOTFUNCDESC, R_SH_GOTFUNCDESC },
365 { BFD_RELOC_SH_GOTFUNCDESC20, R_SH_GOTFUNCDESC20 },
366 { BFD_RELOC_SH_GOTOFFFUNCDESC, R_SH_GOTOFFFUNCDESC },
367 { BFD_RELOC_SH_GOTOFFFUNCDESC20, R_SH_GOTOFFFUNCDESC20 },
368 { BFD_RELOC_SH_FUNCDESC, R_SH_FUNCDESC },
369 #ifdef INCLUDE_SHMEDIA
370 { BFD_RELOC_SH_GOT_LOW16, R_SH_GOT_LOW16 },
371 { BFD_RELOC_SH_GOT_MEDLOW16, R_SH_GOT_MEDLOW16 },
372 { BFD_RELOC_SH_GOT_MEDHI16, R_SH_GOT_MEDHI16 },
373 { BFD_RELOC_SH_GOT_HI16, R_SH_GOT_HI16 },
374 { BFD_RELOC_SH_GOTPLT_LOW16, R_SH_GOTPLT_LOW16 },
375 { BFD_RELOC_SH_GOTPLT_MEDLOW16, R_SH_GOTPLT_MEDLOW16 },
376 { BFD_RELOC_SH_GOTPLT_MEDHI16, R_SH_GOTPLT_MEDHI16 },
377 { BFD_RELOC_SH_GOTPLT_HI16, R_SH_GOTPLT_HI16 },
378 { BFD_RELOC_SH_PLT_LOW16, R_SH_PLT_LOW16 },
379 { BFD_RELOC_SH_PLT_MEDLOW16, R_SH_PLT_MEDLOW16 },
380 { BFD_RELOC_SH_PLT_MEDHI16, R_SH_PLT_MEDHI16 },
381 { BFD_RELOC_SH_PLT_HI16, R_SH_PLT_HI16 },
382 { BFD_RELOC_SH_GOTOFF_LOW16, R_SH_GOTOFF_LOW16 },
383 { BFD_RELOC_SH_GOTOFF_MEDLOW16, R_SH_GOTOFF_MEDLOW16 },
384 { BFD_RELOC_SH_GOTOFF_MEDHI16, R_SH_GOTOFF_MEDHI16 },
385 { BFD_RELOC_SH_GOTOFF_HI16, R_SH_GOTOFF_HI16 },
386 { BFD_RELOC_SH_GOTPC_LOW16, R_SH_GOTPC_LOW16 },
387 { BFD_RELOC_SH_GOTPC_MEDLOW16, R_SH_GOTPC_MEDLOW16 },
388 { BFD_RELOC_SH_GOTPC_MEDHI16, R_SH_GOTPC_MEDHI16 },
389 { BFD_RELOC_SH_GOTPC_HI16, R_SH_GOTPC_HI16 },
390 { BFD_RELOC_SH_COPY64, R_SH_COPY64 },
391 { BFD_RELOC_SH_GLOB_DAT64, R_SH_GLOB_DAT64 },
392 { BFD_RELOC_SH_JMP_SLOT64, R_SH_JMP_SLOT64 },
393 { BFD_RELOC_SH_RELATIVE64, R_SH_RELATIVE64 },
394 { BFD_RELOC_SH_GOT10BY4, R_SH_GOT10BY4 },
395 { BFD_RELOC_SH_GOT10BY8, R_SH_GOT10BY8 },
396 { BFD_RELOC_SH_GOTPLT10BY4, R_SH_GOTPLT10BY4 },
397 { BFD_RELOC_SH_GOTPLT10BY8, R_SH_GOTPLT10BY8 },
398 { BFD_RELOC_SH_PT_16, R_SH_PT_16 },
399 { BFD_RELOC_SH_SHMEDIA_CODE, R_SH_SHMEDIA_CODE },
400 { BFD_RELOC_SH_IMMU5, R_SH_DIR5U },
401 { BFD_RELOC_SH_IMMS6, R_SH_DIR6S },
402 { BFD_RELOC_SH_IMMU6, R_SH_DIR6U },
403 { BFD_RELOC_SH_IMMS10, R_SH_DIR10S },
404 { BFD_RELOC_SH_IMMS10BY2, R_SH_DIR10SW },
405 { BFD_RELOC_SH_IMMS10BY4, R_SH_DIR10SL },
406 { BFD_RELOC_SH_IMMS10BY8, R_SH_DIR10SQ },
407 { BFD_RELOC_SH_IMMS16, R_SH_IMMS16 },
408 { BFD_RELOC_SH_IMMU16, R_SH_IMMU16 },
409 { BFD_RELOC_SH_IMM_LOW16, R_SH_IMM_LOW16 },
410 { BFD_RELOC_SH_IMM_LOW16_PCREL, R_SH_IMM_LOW16_PCREL },
411 { BFD_RELOC_SH_IMM_MEDLOW16, R_SH_IMM_MEDLOW16 },
412 { BFD_RELOC_SH_IMM_MEDLOW16_PCREL, R_SH_IMM_MEDLOW16_PCREL },
413 { BFD_RELOC_SH_IMM_MEDHI16, R_SH_IMM_MEDHI16 },
414 { BFD_RELOC_SH_IMM_MEDHI16_PCREL, R_SH_IMM_MEDHI16_PCREL },
415 { BFD_RELOC_SH_IMM_HI16, R_SH_IMM_HI16 },
416 { BFD_RELOC_SH_IMM_HI16_PCREL, R_SH_IMM_HI16_PCREL },
417 { BFD_RELOC_64, R_SH_64 },
418 { BFD_RELOC_64_PCREL, R_SH_64_PCREL },
419 #endif /* not INCLUDE_SHMEDIA */
422 /* Given a BFD reloc code, return the howto structure for the
423 corresponding SH ELF reloc. */
425 static reloc_howto_type *
426 sh_elf_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code)
430 for (i = 0; i < sizeof (sh_reloc_map) / sizeof (struct elf_reloc_map); i++)
432 if (sh_reloc_map[i].bfd_reloc_val == code)
433 return get_howto_table (abfd) + (int) sh_reloc_map[i].elf_reloc_val;
439 static reloc_howto_type *
440 sh_elf_reloc_name_lookup (bfd *abfd, const char *r_name)
444 if (vxworks_object_p (abfd))
447 i < (sizeof (sh_vxworks_howto_table)
448 / sizeof (sh_vxworks_howto_table[0]));
450 if (sh_vxworks_howto_table[i].name != NULL
451 && strcasecmp (sh_vxworks_howto_table[i].name, r_name) == 0)
452 return &sh_vxworks_howto_table[i];
457 i < (sizeof (sh_elf_howto_table)
458 / sizeof (sh_elf_howto_table[0]));
460 if (sh_elf_howto_table[i].name != NULL
461 && strcasecmp (sh_elf_howto_table[i].name, r_name) == 0)
462 return &sh_elf_howto_table[i];
468 /* Given an ELF reloc, fill in the howto field of a relent. */
471 sh_elf_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)
475 r = ELF32_R_TYPE (dst->r_info);
477 BFD_ASSERT (r < (unsigned int) R_SH_max);
478 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC || r > R_SH_LAST_INVALID_RELOC);
479 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_2 || r > R_SH_LAST_INVALID_RELOC_2);
480 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_3 || r > R_SH_LAST_INVALID_RELOC_3);
481 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_4 || r > R_SH_LAST_INVALID_RELOC_4);
482 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_5 || r > R_SH_LAST_INVALID_RELOC_5);
483 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_6 || r > R_SH_LAST_INVALID_RELOC_6);
485 cache_ptr->howto = get_howto_table (abfd) + r;
488 /* This function handles relaxing for SH ELF. See the corresponding
489 function in coff-sh.c for a description of what this does. FIXME:
490 There is a lot of duplication here between this code and the COFF
491 specific code. The format of relocs and symbols is wound deeply
492 into this code, but it would still be better if the duplication
493 could be eliminated somehow. Note in particular that although both
494 functions use symbols like R_SH_CODE, those symbols have different
495 values; in coff-sh.c they come from include/coff/sh.h, whereas here
496 they come from enum elf_sh_reloc_type in include/elf/sh.h. */
499 sh_elf_relax_section (bfd *abfd, asection *sec,
500 struct bfd_link_info *link_info, bfd_boolean *again)
502 Elf_Internal_Shdr *symtab_hdr;
503 Elf_Internal_Rela *internal_relocs;
504 bfd_boolean have_code;
505 Elf_Internal_Rela *irel, *irelend;
506 bfd_byte *contents = NULL;
507 Elf_Internal_Sym *isymbuf = NULL;
511 if (link_info->relocatable
512 || (sec->flags & SEC_RELOC) == 0
513 || sec->reloc_count == 0)
516 #ifdef INCLUDE_SHMEDIA
517 if (elf_section_data (sec)->this_hdr.sh_flags
518 & (SHF_SH5_ISA32 | SHF_SH5_ISA32_MIXED))
524 symtab_hdr = &elf_symtab_hdr (abfd);
526 internal_relocs = (_bfd_elf_link_read_relocs
527 (abfd, sec, NULL, (Elf_Internal_Rela *) NULL,
528 link_info->keep_memory));
529 if (internal_relocs == NULL)
534 irelend = internal_relocs + sec->reloc_count;
535 for (irel = internal_relocs; irel < irelend; irel++)
537 bfd_vma laddr, paddr, symval;
539 Elf_Internal_Rela *irelfn, *irelscan, *irelcount;
542 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_CODE)
545 if (ELF32_R_TYPE (irel->r_info) != (int) R_SH_USES)
548 /* Get the section contents. */
549 if (contents == NULL)
551 if (elf_section_data (sec)->this_hdr.contents != NULL)
552 contents = elf_section_data (sec)->this_hdr.contents;
555 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
560 /* The r_addend field of the R_SH_USES reloc will point us to
561 the register load. The 4 is because the r_addend field is
562 computed as though it were a jump offset, which are based
563 from 4 bytes after the jump instruction. */
564 laddr = irel->r_offset + 4 + irel->r_addend;
565 if (laddr >= sec->size)
567 (*_bfd_error_handler) (_("%B: 0x%lx: warning: bad R_SH_USES offset"),
569 (unsigned long) irel->r_offset);
572 insn = bfd_get_16 (abfd, contents + laddr);
574 /* If the instruction is not mov.l NN,rN, we don't know what to
576 if ((insn & 0xf000) != 0xd000)
578 ((*_bfd_error_handler)
579 (_("%B: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x"),
580 abfd, (unsigned long) irel->r_offset, insn));
584 /* Get the address from which the register is being loaded. The
585 displacement in the mov.l instruction is quadrupled. It is a
586 displacement from four bytes after the movl instruction, but,
587 before adding in the PC address, two least significant bits
588 of the PC are cleared. We assume that the section is aligned
589 on a four byte boundary. */
592 paddr += (laddr + 4) &~ (bfd_vma) 3;
593 if (paddr >= sec->size)
595 ((*_bfd_error_handler)
596 (_("%B: 0x%lx: warning: bad R_SH_USES load offset"),
597 abfd, (unsigned long) irel->r_offset));
601 /* Get the reloc for the address from which the register is
602 being loaded. This reloc will tell us which function is
603 actually being called. */
604 for (irelfn = internal_relocs; irelfn < irelend; irelfn++)
605 if (irelfn->r_offset == paddr
606 && ELF32_R_TYPE (irelfn->r_info) == (int) R_SH_DIR32)
608 if (irelfn >= irelend)
610 ((*_bfd_error_handler)
611 (_("%B: 0x%lx: warning: could not find expected reloc"),
612 abfd, (unsigned long) paddr));
616 /* Read this BFD's symbols if we haven't done so already. */
617 if (isymbuf == NULL && symtab_hdr->sh_info != 0)
619 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
621 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
622 symtab_hdr->sh_info, 0,
628 /* Get the value of the symbol referred to by the reloc. */
629 if (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
631 /* A local symbol. */
632 Elf_Internal_Sym *isym;
634 isym = isymbuf + ELF32_R_SYM (irelfn->r_info);
636 != (unsigned int) _bfd_elf_section_from_bfd_section (abfd, sec))
638 ((*_bfd_error_handler)
639 (_("%B: 0x%lx: warning: symbol in unexpected section"),
640 abfd, (unsigned long) paddr));
644 symval = (isym->st_value
645 + sec->output_section->vma
646 + sec->output_offset);
651 struct elf_link_hash_entry *h;
653 indx = ELF32_R_SYM (irelfn->r_info) - symtab_hdr->sh_info;
654 h = elf_sym_hashes (abfd)[indx];
655 BFD_ASSERT (h != NULL);
656 if (h->root.type != bfd_link_hash_defined
657 && h->root.type != bfd_link_hash_defweak)
659 /* This appears to be a reference to an undefined
660 symbol. Just ignore it--it will be caught by the
661 regular reloc processing. */
665 symval = (h->root.u.def.value
666 + h->root.u.def.section->output_section->vma
667 + h->root.u.def.section->output_offset);
670 if (get_howto_table (abfd)[R_SH_DIR32].partial_inplace)
671 symval += bfd_get_32 (abfd, contents + paddr);
673 symval += irelfn->r_addend;
675 /* See if this function call can be shortened. */
678 + sec->output_section->vma
681 /* A branch to an address beyond ours might be increased by an
682 .align that doesn't move when bytes behind us are deleted.
683 So, we add some slop in this calculation to allow for
685 if (foff < -0x1000 || foff >= 0x1000 - 8)
687 /* After all that work, we can't shorten this function call. */
691 /* Shorten the function call. */
693 /* For simplicity of coding, we are going to modify the section
694 contents, the section relocs, and the BFD symbol table. We
695 must tell the rest of the code not to free up this
696 information. It would be possible to instead create a table
697 of changes which have to be made, as is done in coff-mips.c;
698 that would be more work, but would require less memory when
699 the linker is run. */
701 elf_section_data (sec)->relocs = internal_relocs;
702 elf_section_data (sec)->this_hdr.contents = contents;
703 symtab_hdr->contents = (unsigned char *) isymbuf;
705 /* Replace the jsr with a bsr. */
707 /* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and
708 replace the jsr with a bsr. */
709 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irelfn->r_info), R_SH_IND12W);
710 /* We used to test (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
711 here, but that only checks if the symbol is an external symbol,
712 not if the symbol is in a different section. Besides, we need
713 a consistent meaning for the relocation, so we just assume here that
714 the value of the symbol is not available. */
716 /* We can't fully resolve this yet, because the external
717 symbol value may be changed by future relaxing. We let
718 the final link phase handle it. */
719 bfd_put_16 (abfd, (bfd_vma) 0xb000, contents + irel->r_offset);
723 /* When we calculated the symbol "value" we had an offset in the
724 DIR32's word in memory (we read and add it above). However,
725 the jsr we create does NOT have this offset encoded, so we
726 have to add it to the addend to preserve it. */
727 irel->r_addend += bfd_get_32 (abfd, contents + paddr);
729 /* See if there is another R_SH_USES reloc referring to the same
731 for (irelscan = internal_relocs; irelscan < irelend; irelscan++)
732 if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_USES
733 && laddr == irelscan->r_offset + 4 + irelscan->r_addend)
735 if (irelscan < irelend)
737 /* Some other function call depends upon this register load,
738 and we have not yet converted that function call.
739 Indeed, we may never be able to convert it. There is
740 nothing else we can do at this point. */
744 /* Look for a R_SH_COUNT reloc on the location where the
745 function address is stored. Do this before deleting any
746 bytes, to avoid confusion about the address. */
747 for (irelcount = internal_relocs; irelcount < irelend; irelcount++)
748 if (irelcount->r_offset == paddr
749 && ELF32_R_TYPE (irelcount->r_info) == (int) R_SH_COUNT)
752 /* Delete the register load. */
753 if (! sh_elf_relax_delete_bytes (abfd, sec, laddr, 2))
756 /* That will change things, so, just in case it permits some
757 other function call to come within range, we should relax
758 again. Note that this is not required, and it may be slow. */
761 /* Now check whether we got a COUNT reloc. */
762 if (irelcount >= irelend)
764 ((*_bfd_error_handler)
765 (_("%B: 0x%lx: warning: could not find expected COUNT reloc"),
766 abfd, (unsigned long) paddr));
770 /* The number of uses is stored in the r_addend field. We've
772 if (irelcount->r_addend == 0)
774 ((*_bfd_error_handler) (_("%B: 0x%lx: warning: bad count"),
776 (unsigned long) paddr));
780 --irelcount->r_addend;
782 /* If there are no more uses, we can delete the address. Reload
783 the address from irelfn, in case it was changed by the
784 previous call to sh_elf_relax_delete_bytes. */
785 if (irelcount->r_addend == 0)
787 if (! sh_elf_relax_delete_bytes (abfd, sec, irelfn->r_offset, 4))
791 /* We've done all we can with that function call. */
794 /* Look for load and store instructions that we can align on four
796 if ((elf_elfheader (abfd)->e_flags & EF_SH_MACH_MASK) != EF_SH4
801 /* Get the section contents. */
802 if (contents == NULL)
804 if (elf_section_data (sec)->this_hdr.contents != NULL)
805 contents = elf_section_data (sec)->this_hdr.contents;
808 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
813 if (! sh_elf_align_loads (abfd, sec, internal_relocs, contents,
819 elf_section_data (sec)->relocs = internal_relocs;
820 elf_section_data (sec)->this_hdr.contents = contents;
821 symtab_hdr->contents = (unsigned char *) isymbuf;
826 && symtab_hdr->contents != (unsigned char *) isymbuf)
828 if (! link_info->keep_memory)
832 /* Cache the symbols for elf_link_input_bfd. */
833 symtab_hdr->contents = (unsigned char *) isymbuf;
838 && elf_section_data (sec)->this_hdr.contents != contents)
840 if (! link_info->keep_memory)
844 /* Cache the section contents for elf_link_input_bfd. */
845 elf_section_data (sec)->this_hdr.contents = contents;
849 if (internal_relocs != NULL
850 && elf_section_data (sec)->relocs != internal_relocs)
851 free (internal_relocs);
857 && symtab_hdr->contents != (unsigned char *) isymbuf)
860 && elf_section_data (sec)->this_hdr.contents != contents)
862 if (internal_relocs != NULL
863 && elf_section_data (sec)->relocs != internal_relocs)
864 free (internal_relocs);
869 /* Delete some bytes from a section while relaxing. FIXME: There is a
870 lot of duplication between this function and sh_relax_delete_bytes
874 sh_elf_relax_delete_bytes (bfd *abfd, asection *sec, bfd_vma addr,
877 Elf_Internal_Shdr *symtab_hdr;
878 unsigned int sec_shndx;
880 Elf_Internal_Rela *irel, *irelend;
881 Elf_Internal_Rela *irelalign;
883 Elf_Internal_Sym *isymbuf, *isym, *isymend;
884 struct elf_link_hash_entry **sym_hashes;
885 struct elf_link_hash_entry **end_hashes;
886 unsigned int symcount;
889 symtab_hdr = &elf_symtab_hdr (abfd);
890 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
892 sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
894 contents = elf_section_data (sec)->this_hdr.contents;
896 /* The deletion must stop at the next ALIGN reloc for an aligment
897 power larger than the number of bytes we are deleting. */
902 irel = elf_section_data (sec)->relocs;
903 irelend = irel + sec->reloc_count;
904 for (; irel < irelend; irel++)
906 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_ALIGN
907 && irel->r_offset > addr
908 && count < (1 << irel->r_addend))
911 toaddr = irel->r_offset;
916 /* Actually delete the bytes. */
917 memmove (contents + addr, contents + addr + count,
918 (size_t) (toaddr - addr - count));
919 if (irelalign == NULL)
925 #define NOP_OPCODE (0x0009)
927 BFD_ASSERT ((count & 1) == 0);
928 for (i = 0; i < count; i += 2)
929 bfd_put_16 (abfd, (bfd_vma) NOP_OPCODE, contents + toaddr - count + i);
932 /* Adjust all the relocs. */
933 for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)
935 bfd_vma nraddr, stop;
938 int off, adjust, oinsn;
939 bfd_signed_vma voff = 0;
940 bfd_boolean overflow;
942 /* Get the new reloc address. */
943 nraddr = irel->r_offset;
944 if ((irel->r_offset > addr
945 && irel->r_offset < toaddr)
946 || (ELF32_R_TYPE (irel->r_info) == (int) R_SH_ALIGN
947 && irel->r_offset == toaddr))
950 /* See if this reloc was for the bytes we have deleted, in which
951 case we no longer care about it. Don't delete relocs which
952 represent addresses, though. */
953 if (irel->r_offset >= addr
954 && irel->r_offset < addr + count
955 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_ALIGN
956 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_CODE
957 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_DATA
958 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_LABEL)
959 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
962 /* If this is a PC relative reloc, see if the range it covers
963 includes the bytes we have deleted. */
964 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
973 start = irel->r_offset;
974 insn = bfd_get_16 (abfd, contents + nraddr);
978 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
985 /* If this reloc is against a symbol defined in this
986 section, and the symbol will not be adjusted below, we
987 must check the addend to see it will put the value in
988 range to be adjusted, and hence must be changed. */
989 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
991 isym = isymbuf + ELF32_R_SYM (irel->r_info);
992 if (isym->st_shndx == sec_shndx
993 && (isym->st_value <= addr
994 || isym->st_value >= toaddr))
998 if (get_howto_table (abfd)[R_SH_DIR32].partial_inplace)
1000 val = bfd_get_32 (abfd, contents + nraddr);
1001 val += isym->st_value;
1002 if (val > addr && val < toaddr)
1003 bfd_put_32 (abfd, val - count, contents + nraddr);
1007 val = isym->st_value + irel->r_addend;
1008 if (val > addr && val < toaddr)
1009 irel->r_addend -= count;
1013 start = stop = addr;
1020 stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
1027 /* This has been made by previous relaxation. Since the
1028 relocation will be against an external symbol, the
1029 final relocation will just do the right thing. */
1030 start = stop = addr;
1036 stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
1038 /* The addend will be against the section symbol, thus
1039 for adjusting the addend, the relevant start is the
1040 start of the section.
1041 N.B. If we want to abandon in-place changes here and
1042 test directly using symbol + addend, we have to take into
1043 account that the addend has already been adjusted by -4. */
1044 if (stop > addr && stop < toaddr)
1045 irel->r_addend -= count;
1051 stop = start + 4 + off * 2;
1056 stop = (start & ~(bfd_vma) 3) + 4 + off * 4;
1062 /* These relocs types represent
1064 The r_addend field holds the difference between the reloc
1065 address and L1. That is the start of the reloc, and
1066 adding in the contents gives us the top. We must adjust
1067 both the r_offset field and the section contents.
1068 N.B. in gas / coff bfd, the elf bfd r_addend is called r_offset,
1069 and the elf bfd r_offset is called r_vaddr. */
1071 stop = irel->r_offset;
1072 start = (bfd_vma) ((bfd_signed_vma) stop - (long) irel->r_addend);
1076 && (stop <= addr || stop >= toaddr))
1077 irel->r_addend += count;
1078 else if (stop > addr
1080 && (start <= addr || start >= toaddr))
1081 irel->r_addend -= count;
1083 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_SWITCH16)
1084 voff = bfd_get_signed_16 (abfd, contents + nraddr);
1085 else if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_SWITCH8)
1086 voff = bfd_get_8 (abfd, contents + nraddr);
1088 voff = bfd_get_signed_32 (abfd, contents + nraddr);
1089 stop = (bfd_vma) ((bfd_signed_vma) start + voff);
1094 start = irel->r_offset;
1095 stop = (bfd_vma) ((bfd_signed_vma) start
1096 + (long) irel->r_addend
1103 && (stop <= addr || stop >= toaddr))
1105 else if (stop > addr
1107 && (start <= addr || start >= toaddr))
1116 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
1125 if ((oinsn & 0xff00) != (insn & 0xff00))
1127 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
1132 if ((oinsn & 0xf000) != (insn & 0xf000))
1134 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
1138 BFD_ASSERT (adjust == count || count >= 4);
1143 if ((irel->r_offset & 3) == 0)
1146 if ((oinsn & 0xff00) != (insn & 0xff00))
1148 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
1153 if (voff < 0 || voff >= 0xff)
1155 bfd_put_8 (abfd, voff, contents + nraddr);
1160 if (voff < - 0x8000 || voff >= 0x8000)
1162 bfd_put_signed_16 (abfd, (bfd_vma) voff, contents + nraddr);
1167 bfd_put_signed_32 (abfd, (bfd_vma) voff, contents + nraddr);
1171 irel->r_addend += adjust;
1177 ((*_bfd_error_handler)
1178 (_("%B: 0x%lx: fatal: reloc overflow while relaxing"),
1179 abfd, (unsigned long) irel->r_offset));
1180 bfd_set_error (bfd_error_bad_value);
1185 irel->r_offset = nraddr;
1188 /* Look through all the other sections. If there contain any IMM32
1189 relocs against internal symbols which we are not going to adjust
1190 below, we may need to adjust the addends. */
1191 for (o = abfd->sections; o != NULL; o = o->next)
1193 Elf_Internal_Rela *internal_relocs;
1194 Elf_Internal_Rela *irelscan, *irelscanend;
1195 bfd_byte *ocontents;
1198 || (o->flags & SEC_RELOC) == 0
1199 || o->reloc_count == 0)
1202 /* We always cache the relocs. Perhaps, if info->keep_memory is
1203 FALSE, we should free them, if we are permitted to, when we
1204 leave sh_coff_relax_section. */
1205 internal_relocs = (_bfd_elf_link_read_relocs
1206 (abfd, o, NULL, (Elf_Internal_Rela *) NULL, TRUE));
1207 if (internal_relocs == NULL)
1211 irelscanend = internal_relocs + o->reloc_count;
1212 for (irelscan = internal_relocs; irelscan < irelscanend; irelscan++)
1214 /* Dwarf line numbers use R_SH_SWITCH32 relocs. */
1215 if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_SWITCH32)
1217 bfd_vma start, stop;
1218 bfd_signed_vma voff;
1220 if (ocontents == NULL)
1222 if (elf_section_data (o)->this_hdr.contents != NULL)
1223 ocontents = elf_section_data (o)->this_hdr.contents;
1226 /* We always cache the section contents.
1227 Perhaps, if info->keep_memory is FALSE, we
1228 should free them, if we are permitted to,
1229 when we leave sh_coff_relax_section. */
1230 if (!bfd_malloc_and_get_section (abfd, o, &ocontents))
1232 if (ocontents != NULL)
1237 elf_section_data (o)->this_hdr.contents = ocontents;
1241 stop = irelscan->r_offset;
1243 = (bfd_vma) ((bfd_signed_vma) stop - (long) irelscan->r_addend);
1245 /* STOP is in a different section, so it won't change. */
1246 if (start > addr && start < toaddr)
1247 irelscan->r_addend += count;
1249 voff = bfd_get_signed_32 (abfd, ocontents + irelscan->r_offset);
1250 stop = (bfd_vma) ((bfd_signed_vma) start + voff);
1254 && (stop <= addr || stop >= toaddr))
1255 bfd_put_signed_32 (abfd, (bfd_vma) voff + count,
1256 ocontents + irelscan->r_offset);
1257 else if (stop > addr
1259 && (start <= addr || start >= toaddr))
1260 bfd_put_signed_32 (abfd, (bfd_vma) voff - count,
1261 ocontents + irelscan->r_offset);
1264 if (ELF32_R_TYPE (irelscan->r_info) != (int) R_SH_DIR32)
1267 if (ELF32_R_SYM (irelscan->r_info) >= symtab_hdr->sh_info)
1271 isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
1272 if (isym->st_shndx == sec_shndx
1273 && (isym->st_value <= addr
1274 || isym->st_value >= toaddr))
1278 if (ocontents == NULL)
1280 if (elf_section_data (o)->this_hdr.contents != NULL)
1281 ocontents = elf_section_data (o)->this_hdr.contents;
1284 /* We always cache the section contents.
1285 Perhaps, if info->keep_memory is FALSE, we
1286 should free them, if we are permitted to,
1287 when we leave sh_coff_relax_section. */
1288 if (!bfd_malloc_and_get_section (abfd, o, &ocontents))
1290 if (ocontents != NULL)
1295 elf_section_data (o)->this_hdr.contents = ocontents;
1299 val = bfd_get_32 (abfd, ocontents + irelscan->r_offset);
1300 val += isym->st_value;
1301 if (val > addr && val < toaddr)
1302 bfd_put_32 (abfd, val - count,
1303 ocontents + irelscan->r_offset);
1308 /* Adjust the local symbols defined in this section. */
1309 isymend = isymbuf + symtab_hdr->sh_info;
1310 for (isym = isymbuf; isym < isymend; isym++)
1312 if (isym->st_shndx == sec_shndx
1313 && isym->st_value > addr
1314 && isym->st_value < toaddr)
1315 isym->st_value -= count;
1318 /* Now adjust the global symbols defined in this section. */
1319 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
1320 - symtab_hdr->sh_info);
1321 sym_hashes = elf_sym_hashes (abfd);
1322 end_hashes = sym_hashes + symcount;
1323 for (; sym_hashes < end_hashes; sym_hashes++)
1325 struct elf_link_hash_entry *sym_hash = *sym_hashes;
1326 if ((sym_hash->root.type == bfd_link_hash_defined
1327 || sym_hash->root.type == bfd_link_hash_defweak)
1328 && sym_hash->root.u.def.section == sec
1329 && sym_hash->root.u.def.value > addr
1330 && sym_hash->root.u.def.value < toaddr)
1332 sym_hash->root.u.def.value -= count;
1336 /* See if we can move the ALIGN reloc forward. We have adjusted
1337 r_offset for it already. */
1338 if (irelalign != NULL)
1340 bfd_vma alignto, alignaddr;
1342 alignto = BFD_ALIGN (toaddr, 1 << irelalign->r_addend);
1343 alignaddr = BFD_ALIGN (irelalign->r_offset,
1344 1 << irelalign->r_addend);
1345 if (alignto != alignaddr)
1347 /* Tail recursion. */
1348 return sh_elf_relax_delete_bytes (abfd, sec, alignaddr,
1349 (int) (alignto - alignaddr));
1356 /* Look for loads and stores which we can align to four byte
1357 boundaries. This is like sh_align_loads in coff-sh.c. */
1360 sh_elf_align_loads (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
1361 Elf_Internal_Rela *internal_relocs,
1362 bfd_byte *contents ATTRIBUTE_UNUSED,
1363 bfd_boolean *pswapped)
1365 Elf_Internal_Rela *irel, *irelend;
1366 bfd_vma *labels = NULL;
1367 bfd_vma *label, *label_end;
1372 irelend = internal_relocs + sec->reloc_count;
1374 /* Get all the addresses with labels on them. */
1375 amt = sec->reloc_count;
1376 amt *= sizeof (bfd_vma);
1377 labels = (bfd_vma *) bfd_malloc (amt);
1381 for (irel = internal_relocs; irel < irelend; irel++)
1383 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_LABEL)
1385 *label_end = irel->r_offset;
1390 /* Note that the assembler currently always outputs relocs in
1391 address order. If that ever changes, this code will need to sort
1392 the label values and the relocs. */
1396 for (irel = internal_relocs; irel < irelend; irel++)
1398 bfd_vma start, stop;
1400 if (ELF32_R_TYPE (irel->r_info) != (int) R_SH_CODE)
1403 start = irel->r_offset;
1405 for (irel++; irel < irelend; irel++)
1406 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_DATA)
1409 stop = irel->r_offset;
1413 if (! _bfd_sh_align_load_span (abfd, sec, contents, sh_elf_swap_insns,
1414 internal_relocs, &label,
1415 label_end, start, stop, pswapped))
1430 /* Swap two SH instructions. This is like sh_swap_insns in coff-sh.c. */
1433 sh_elf_swap_insns (bfd *abfd, asection *sec, void *relocs,
1434 bfd_byte *contents, bfd_vma addr)
1436 Elf_Internal_Rela *internal_relocs = (Elf_Internal_Rela *) relocs;
1437 unsigned short i1, i2;
1438 Elf_Internal_Rela *irel, *irelend;
1440 /* Swap the instructions themselves. */
1441 i1 = bfd_get_16 (abfd, contents + addr);
1442 i2 = bfd_get_16 (abfd, contents + addr + 2);
1443 bfd_put_16 (abfd, (bfd_vma) i2, contents + addr);
1444 bfd_put_16 (abfd, (bfd_vma) i1, contents + addr + 2);
1446 /* Adjust all reloc addresses. */
1447 irelend = internal_relocs + sec->reloc_count;
1448 for (irel = internal_relocs; irel < irelend; irel++)
1450 enum elf_sh_reloc_type type;
1453 /* There are a few special types of relocs that we don't want to
1454 adjust. These relocs do not apply to the instruction itself,
1455 but are only associated with the address. */
1456 type = (enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info);
1457 if (type == R_SH_ALIGN
1458 || type == R_SH_CODE
1459 || type == R_SH_DATA
1460 || type == R_SH_LABEL)
1463 /* If an R_SH_USES reloc points to one of the addresses being
1464 swapped, we must adjust it. It would be incorrect to do this
1465 for a jump, though, since we want to execute both
1466 instructions after the jump. (We have avoided swapping
1467 around a label, so the jump will not wind up executing an
1468 instruction it shouldn't). */
1469 if (type == R_SH_USES)
1473 off = irel->r_offset + 4 + irel->r_addend;
1475 irel->r_offset += 2;
1476 else if (off == addr + 2)
1477 irel->r_offset -= 2;
1480 if (irel->r_offset == addr)
1482 irel->r_offset += 2;
1485 else if (irel->r_offset == addr + 2)
1487 irel->r_offset -= 2;
1496 unsigned short insn, oinsn;
1497 bfd_boolean overflow;
1499 loc = contents + irel->r_offset;
1508 insn = bfd_get_16 (abfd, loc);
1511 if ((oinsn & 0xff00) != (insn & 0xff00))
1513 bfd_put_16 (abfd, (bfd_vma) insn, loc);
1517 insn = bfd_get_16 (abfd, loc);
1520 if ((oinsn & 0xf000) != (insn & 0xf000))
1522 bfd_put_16 (abfd, (bfd_vma) insn, loc);
1526 /* This reloc ignores the least significant 3 bits of
1527 the program counter before adding in the offset.
1528 This means that if ADDR is at an even address, the
1529 swap will not affect the offset. If ADDR is an at an
1530 odd address, then the instruction will be crossing a
1531 four byte boundary, and must be adjusted. */
1532 if ((addr & 3) != 0)
1534 insn = bfd_get_16 (abfd, loc);
1537 if ((oinsn & 0xff00) != (insn & 0xff00))
1539 bfd_put_16 (abfd, (bfd_vma) insn, loc);
1547 ((*_bfd_error_handler)
1548 (_("%B: 0x%lx: fatal: reloc overflow while relaxing"),
1549 abfd, (unsigned long) irel->r_offset));
1550 bfd_set_error (bfd_error_bad_value);
1558 #endif /* defined SH64_ELF */
1560 /* Describes one of the various PLT styles. */
1562 struct elf_sh_plt_info
1564 /* The template for the first PLT entry, or NULL if there is no special
1566 const bfd_byte *plt0_entry;
1568 /* The size of PLT0_ENTRY in bytes, or 0 if PLT0_ENTRY is NULL. */
1569 bfd_vma plt0_entry_size;
1571 /* Index I is the offset into PLT0_ENTRY of a pointer to
1572 _GLOBAL_OFFSET_TABLE_ + I * 4. The value is MINUS_ONE
1573 if there is no such pointer. */
1574 bfd_vma plt0_got_fields[3];
1576 /* The template for a symbol's PLT entry. */
1577 const bfd_byte *symbol_entry;
1579 /* The size of SYMBOL_ENTRY in bytes. */
1580 bfd_vma symbol_entry_size;
1582 /* Byte offsets of fields in SYMBOL_ENTRY. Not all fields are used
1583 on all targets. The comments by each member indicate the value
1584 that the field must hold. */
1586 bfd_vma got_entry; /* the address of the symbol's .got.plt entry */
1587 bfd_vma plt; /* .plt (or a branch to .plt on VxWorks) */
1588 bfd_vma reloc_offset; /* the offset of the symbol's JMP_SLOT reloc */
1589 bfd_boolean got20; /* TRUE if got_entry points to a movi20
1590 instruction (instead of a constant pool
1594 /* The offset of the resolver stub from the start of SYMBOL_ENTRY. */
1595 bfd_vma symbol_resolve_offset;
1597 /* A different PLT layout which can be used for the first
1598 MAX_SHORT_PLT entries. It must share the same plt0. NULL in
1600 const struct elf_sh_plt_info *short_plt;
1603 #ifdef INCLUDE_SHMEDIA
1605 /* The size in bytes of an entry in the procedure linkage table. */
1607 #define ELF_PLT_ENTRY_SIZE 64
1609 /* First entry in an absolute procedure linkage table look like this. */
1611 static const bfd_byte elf_sh_plt0_entry_be[ELF_PLT_ENTRY_SIZE] =
1613 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 16, r17 */
1614 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
1615 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
1616 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
1617 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
1618 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
1619 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1620 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1621 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1622 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1623 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1624 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1625 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1626 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1627 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1628 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1631 static const bfd_byte elf_sh_plt0_entry_le[ELF_PLT_ENTRY_SIZE] =
1633 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */
1634 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
1635 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
1636 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
1637 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
1638 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
1639 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1640 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1641 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1642 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1643 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1644 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1645 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1646 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1647 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1648 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1651 /* Sebsequent entries in an absolute procedure linkage table look like
1654 static const bfd_byte elf_sh_plt_entry_be[ELF_PLT_ENTRY_SIZE] =
1656 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 16, r25 */
1657 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
1658 0x89, 0x90, 0x01, 0x90, /* ld.l r25, 0, r25 */
1659 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
1660 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
1661 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1662 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1663 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1664 0xcc, 0x00, 0x01, 0x90, /* movi .PLT0 >> 16, r25 */
1665 0xc8, 0x00, 0x01, 0x90, /* shori .PLT0 & 65535, r25 */
1666 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
1667 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
1668 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
1669 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
1670 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1671 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1674 static const bfd_byte elf_sh_plt_entry_le[ELF_PLT_ENTRY_SIZE] =
1676 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */
1677 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
1678 0x90, 0x01, 0x90, 0x89, /* ld.l r25, 0, r25 */
1679 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
1680 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
1681 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1682 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1683 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1684 0x90, 0x01, 0x00, 0xcc, /* movi .PLT0 >> 16, r25 */
1685 0x90, 0x01, 0x00, 0xc8, /* shori .PLT0 & 65535, r25 */
1686 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
1687 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
1688 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
1689 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
1690 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1691 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1694 /* Entries in a PIC procedure linkage table look like this. */
1696 static const bfd_byte elf_sh_pic_plt_entry_be[ELF_PLT_ENTRY_SIZE] =
1698 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */
1699 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
1700 0x40, 0xc2, 0x65, 0x90, /* ldx.l r12, r25, r25 */
1701 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
1702 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
1703 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1704 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1705 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1706 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */
1707 0x00, 0xc8, 0x45, 0x10, /* add.l r12, r17, r17 */
1708 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
1709 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
1710 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
1711 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
1712 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
1713 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
1716 static const bfd_byte elf_sh_pic_plt_entry_le[ELF_PLT_ENTRY_SIZE] =
1718 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */
1719 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
1720 0x90, 0x65, 0xc2, 0x40, /* ldx.l r12, r25, r25 */
1721 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
1722 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
1723 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1724 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1725 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1726 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */
1727 0x10, 0x45, 0xc8, 0x00, /* add.l r12, r17, r17 */
1728 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
1729 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
1730 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
1731 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
1732 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
1733 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
1736 static const struct elf_sh_plt_info elf_sh_plts[2][2] = {
1739 /* Big-endian non-PIC. */
1740 elf_sh_plt0_entry_be,
1742 { 0, MINUS_ONE, MINUS_ONE },
1743 elf_sh_plt_entry_be,
1745 { 0, 32, 48, FALSE },
1746 33, /* includes ISA encoding */
1750 /* Little-endian non-PIC. */
1751 elf_sh_plt0_entry_le,
1753 { 0, MINUS_ONE, MINUS_ONE },
1754 elf_sh_plt_entry_le,
1756 { 0, 32, 48, FALSE },
1757 33, /* includes ISA encoding */
1763 /* Big-endian PIC. */
1764 elf_sh_plt0_entry_be,
1766 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
1767 elf_sh_pic_plt_entry_be,
1769 { 0, MINUS_ONE, 52, FALSE },
1770 33, /* includes ISA encoding */
1774 /* Little-endian PIC. */
1775 elf_sh_plt0_entry_le,
1777 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
1778 elf_sh_pic_plt_entry_le,
1780 { 0, MINUS_ONE, 52, FALSE },
1781 33, /* includes ISA encoding */
1787 /* Return offset of the linker in PLT0 entry. */
1788 #define elf_sh_plt0_gotplt_offset(info) 0
1790 /* Install a 32-bit PLT field starting at ADDR, which occurs in OUTPUT_BFD.
1791 VALUE is the field's value and CODE_P is true if VALUE refers to code,
1794 On SH64, each 32-bit field is loaded by a movi/shori pair. */
1797 install_plt_field (bfd *output_bfd, bfd_boolean code_p,
1798 unsigned long value, bfd_byte *addr)
1801 bfd_put_32 (output_bfd,
1802 bfd_get_32 (output_bfd, addr)
1803 | ((value >> 6) & 0x3fffc00),
1805 bfd_put_32 (output_bfd,
1806 bfd_get_32 (output_bfd, addr + 4)
1807 | ((value << 10) & 0x3fffc00),
1811 /* Return the type of PLT associated with ABFD. PIC_P is true if
1812 the object is position-independent. */
1814 static const struct elf_sh_plt_info *
1815 get_plt_info (bfd *abfd ATTRIBUTE_UNUSED, bfd_boolean pic_p)
1817 return &elf_sh_plts[pic_p][!bfd_big_endian (abfd)];
1820 /* The size in bytes of an entry in the procedure linkage table. */
1822 #define ELF_PLT_ENTRY_SIZE 28
1824 /* First entry in an absolute procedure linkage table look like this. */
1826 /* Note - this code has been "optimised" not to use r2. r2 is used by
1827 GCC to return the address of large structures, so it should not be
1828 corrupted here. This does mean however, that this PLT does not conform
1829 to the SH PIC ABI. That spec says that r0 contains the type of the PLT
1830 and r2 contains the GOT id. This version stores the GOT id in r0 and
1831 ignores the type. Loaders can easily detect this difference however,
1832 since the type will always be 0 or 8, and the GOT ids will always be
1833 greater than or equal to 12. */
1834 static const bfd_byte elf_sh_plt0_entry_be[ELF_PLT_ENTRY_SIZE] =
1836 0xd0, 0x05, /* mov.l 2f,r0 */
1837 0x60, 0x02, /* mov.l @r0,r0 */
1838 0x2f, 0x06, /* mov.l r0,@-r15 */
1839 0xd0, 0x03, /* mov.l 1f,r0 */
1840 0x60, 0x02, /* mov.l @r0,r0 */
1841 0x40, 0x2b, /* jmp @r0 */
1842 0x60, 0xf6, /* mov.l @r15+,r0 */
1843 0x00, 0x09, /* nop */
1844 0x00, 0x09, /* nop */
1845 0x00, 0x09, /* nop */
1846 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
1847 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
1850 static const bfd_byte elf_sh_plt0_entry_le[ELF_PLT_ENTRY_SIZE] =
1852 0x05, 0xd0, /* mov.l 2f,r0 */
1853 0x02, 0x60, /* mov.l @r0,r0 */
1854 0x06, 0x2f, /* mov.l r0,@-r15 */
1855 0x03, 0xd0, /* mov.l 1f,r0 */
1856 0x02, 0x60, /* mov.l @r0,r0 */
1857 0x2b, 0x40, /* jmp @r0 */
1858 0xf6, 0x60, /* mov.l @r15+,r0 */
1859 0x09, 0x00, /* nop */
1860 0x09, 0x00, /* nop */
1861 0x09, 0x00, /* nop */
1862 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
1863 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
1866 /* Sebsequent entries in an absolute procedure linkage table look like
1869 static const bfd_byte elf_sh_plt_entry_be[ELF_PLT_ENTRY_SIZE] =
1871 0xd0, 0x04, /* mov.l 1f,r0 */
1872 0x60, 0x02, /* mov.l @(r0,r12),r0 */
1873 0xd1, 0x02, /* mov.l 0f,r1 */
1874 0x40, 0x2b, /* jmp @r0 */
1875 0x60, 0x13, /* mov r1,r0 */
1876 0xd1, 0x03, /* mov.l 2f,r1 */
1877 0x40, 0x2b, /* jmp @r0 */
1878 0x00, 0x09, /* nop */
1879 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
1880 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
1881 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
1884 static const bfd_byte elf_sh_plt_entry_le[ELF_PLT_ENTRY_SIZE] =
1886 0x04, 0xd0, /* mov.l 1f,r0 */
1887 0x02, 0x60, /* mov.l @r0,r0 */
1888 0x02, 0xd1, /* mov.l 0f,r1 */
1889 0x2b, 0x40, /* jmp @r0 */
1890 0x13, 0x60, /* mov r1,r0 */
1891 0x03, 0xd1, /* mov.l 2f,r1 */
1892 0x2b, 0x40, /* jmp @r0 */
1893 0x09, 0x00, /* nop */
1894 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
1895 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
1896 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
1899 /* Entries in a PIC procedure linkage table look like this. */
1901 static const bfd_byte elf_sh_pic_plt_entry_be[ELF_PLT_ENTRY_SIZE] =
1903 0xd0, 0x04, /* mov.l 1f,r0 */
1904 0x00, 0xce, /* mov.l @(r0,r12),r0 */
1905 0x40, 0x2b, /* jmp @r0 */
1906 0x00, 0x09, /* nop */
1907 0x50, 0xc2, /* mov.l @(8,r12),r0 */
1908 0xd1, 0x03, /* mov.l 2f,r1 */
1909 0x40, 0x2b, /* jmp @r0 */
1910 0x50, 0xc1, /* mov.l @(4,r12),r0 */
1911 0x00, 0x09, /* nop */
1912 0x00, 0x09, /* nop */
1913 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
1914 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
1917 static const bfd_byte elf_sh_pic_plt_entry_le[ELF_PLT_ENTRY_SIZE] =
1919 0x04, 0xd0, /* mov.l 1f,r0 */
1920 0xce, 0x00, /* mov.l @(r0,r12),r0 */
1921 0x2b, 0x40, /* jmp @r0 */
1922 0x09, 0x00, /* nop */
1923 0xc2, 0x50, /* mov.l @(8,r12),r0 */
1924 0x03, 0xd1, /* mov.l 2f,r1 */
1925 0x2b, 0x40, /* jmp @r0 */
1926 0xc1, 0x50, /* mov.l @(4,r12),r0 */
1927 0x09, 0x00, /* nop */
1928 0x09, 0x00, /* nop */
1929 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
1930 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
1933 static const struct elf_sh_plt_info elf_sh_plts[2][2] = {
1936 /* Big-endian non-PIC. */
1937 elf_sh_plt0_entry_be,
1939 { MINUS_ONE, 24, 20 },
1940 elf_sh_plt_entry_be,
1942 { 20, 16, 24, FALSE },
1947 /* Little-endian non-PIC. */
1948 elf_sh_plt0_entry_le,
1950 { MINUS_ONE, 24, 20 },
1951 elf_sh_plt_entry_le,
1953 { 20, 16, 24, FALSE },
1960 /* Big-endian PIC. */
1961 elf_sh_plt0_entry_be,
1963 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
1964 elf_sh_pic_plt_entry_be,
1966 { 20, MINUS_ONE, 24, FALSE },
1971 /* Little-endian PIC. */
1972 elf_sh_plt0_entry_le,
1974 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
1975 elf_sh_pic_plt_entry_le,
1977 { 20, MINUS_ONE, 24, FALSE },
1984 #define VXWORKS_PLT_HEADER_SIZE 12
1985 #define VXWORKS_PLT_ENTRY_SIZE 24
1987 static const bfd_byte vxworks_sh_plt0_entry_be[VXWORKS_PLT_HEADER_SIZE] =
1989 0xd1, 0x01, /* mov.l @(8,pc),r1 */
1990 0x61, 0x12, /* mov.l @r1,r1 */
1991 0x41, 0x2b, /* jmp @r1 */
1992 0x00, 0x09, /* nop */
1993 0, 0, 0, 0 /* 0: replaced with _GLOBAL_OFFSET_TABLE+8. */
1996 static const bfd_byte vxworks_sh_plt0_entry_le[VXWORKS_PLT_HEADER_SIZE] =
1998 0x01, 0xd1, /* mov.l @(8,pc),r1 */
1999 0x12, 0x61, /* mov.l @r1,r1 */
2000 0x2b, 0x41, /* jmp @r1 */
2001 0x09, 0x00, /* nop */
2002 0, 0, 0, 0 /* 0: replaced with _GLOBAL_OFFSET_TABLE+8. */
2005 static const bfd_byte vxworks_sh_plt_entry_be[VXWORKS_PLT_ENTRY_SIZE] =
2007 0xd0, 0x01, /* mov.l @(8,pc),r0 */
2008 0x60, 0x02, /* mov.l @r0,r0 */
2009 0x40, 0x2b, /* jmp @r0 */
2010 0x00, 0x09, /* nop */
2011 0, 0, 0, 0, /* 0: replaced with address of this symbol in .got. */
2012 0xd0, 0x01, /* mov.l @(8,pc),r0 */
2013 0xa0, 0x00, /* bra PLT (We need to fix the offset.) */
2014 0x00, 0x09, /* nop */
2015 0x00, 0x09, /* nop */
2016 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2019 static const bfd_byte vxworks_sh_plt_entry_le[VXWORKS_PLT_ENTRY_SIZE] =
2021 0x01, 0xd0, /* mov.l @(8,pc),r0 */
2022 0x02, 0x60, /* mov.l @r0,r0 */
2023 0x2b, 0x40, /* jmp @r0 */
2024 0x09, 0x00, /* nop */
2025 0, 0, 0, 0, /* 0: replaced with address of this symbol in .got. */
2026 0x01, 0xd0, /* mov.l @(8,pc),r0 */
2027 0x00, 0xa0, /* bra PLT (We need to fix the offset.) */
2028 0x09, 0x00, /* nop */
2029 0x09, 0x00, /* nop */
2030 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2033 static const bfd_byte vxworks_sh_pic_plt_entry_be[VXWORKS_PLT_ENTRY_SIZE] =
2035 0xd0, 0x01, /* mov.l @(8,pc),r0 */
2036 0x00, 0xce, /* mov.l @(r0,r12),r0 */
2037 0x40, 0x2b, /* jmp @r0 */
2038 0x00, 0x09, /* nop */
2039 0, 0, 0, 0, /* 0: replaced with offset of this symbol in .got. */
2040 0xd0, 0x01, /* mov.l @(8,pc),r0 */
2041 0x51, 0xc2, /* mov.l @(8,r12),r1 */
2042 0x41, 0x2b, /* jmp @r1 */
2043 0x00, 0x09, /* nop */
2044 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2047 static const bfd_byte vxworks_sh_pic_plt_entry_le[VXWORKS_PLT_ENTRY_SIZE] =
2049 0x01, 0xd0, /* mov.l @(8,pc),r0 */
2050 0xce, 0x00, /* mov.l @(r0,r12),r0 */
2051 0x2b, 0x40, /* jmp @r0 */
2052 0x09, 0x00, /* nop */
2053 0, 0, 0, 0, /* 0: replaced with offset of this symbol in .got. */
2054 0x01, 0xd0, /* mov.l @(8,pc),r0 */
2055 0xc2, 0x51, /* mov.l @(8,r12),r1 */
2056 0x2b, 0x41, /* jmp @r1 */
2057 0x09, 0x00, /* nop */
2058 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2061 static const struct elf_sh_plt_info vxworks_sh_plts[2][2] = {
2064 /* Big-endian non-PIC. */
2065 vxworks_sh_plt0_entry_be,
2066 VXWORKS_PLT_HEADER_SIZE,
2067 { MINUS_ONE, MINUS_ONE, 8 },
2068 vxworks_sh_plt_entry_be,
2069 VXWORKS_PLT_ENTRY_SIZE,
2070 { 8, 14, 20, FALSE },
2075 /* Little-endian non-PIC. */
2076 vxworks_sh_plt0_entry_le,
2077 VXWORKS_PLT_HEADER_SIZE,
2078 { MINUS_ONE, MINUS_ONE, 8 },
2079 vxworks_sh_plt_entry_le,
2080 VXWORKS_PLT_ENTRY_SIZE,
2081 { 8, 14, 20, FALSE },
2088 /* Big-endian PIC. */
2091 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2092 vxworks_sh_pic_plt_entry_be,
2093 VXWORKS_PLT_ENTRY_SIZE,
2094 { 8, MINUS_ONE, 20, FALSE },
2099 /* Little-endian PIC. */
2102 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2103 vxworks_sh_pic_plt_entry_le,
2104 VXWORKS_PLT_ENTRY_SIZE,
2105 { 8, MINUS_ONE, 20, FALSE },
2112 /* FDPIC PLT entries. Two unimplemented optimizations for lazy
2113 binding are to omit the lazy binding stub when linking with -z now
2114 and to move lazy binding stubs into a separate region for better
2117 #define FDPIC_PLT_ENTRY_SIZE 28
2118 #define FDPIC_PLT_LAZY_OFFSET 20
2120 /* FIXME: The lazy binding stub requires a plt0 - which may need to be
2121 duplicated if it is out of range, or which can be inlined. So
2122 right now it is always inlined, which wastes a word per stub. It
2123 might be easier to handle the duplication if we put the lazy
2124 stubs separately. */
2126 static const bfd_byte fdpic_sh_plt_entry_be[FDPIC_PLT_ENTRY_SIZE] =
2128 0xd0, 0x02, /* mov.l @(12,pc),r0 */
2129 0x01, 0xce, /* mov.l @(r0,r12),r1 */
2130 0x70, 0x04, /* add #4, r0 */
2131 0x41, 0x2b, /* jmp @r1 */
2132 0x0c, 0xce, /* mov.l @(r0,r12),r12 */
2133 0x00, 0x09, /* nop */
2134 0, 0, 0, 0, /* 0: replaced with offset of this symbol's funcdesc */
2135 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2136 0x60, 0xc2, /* mov.l @r12,r0 */
2137 0x40, 0x2b, /* jmp @r0 */
2138 0x53, 0xc1, /* mov.l @(4,r12),r3 */
2139 0x00, 0x09, /* nop */
2142 static const bfd_byte fdpic_sh_plt_entry_le[FDPIC_PLT_ENTRY_SIZE] =
2144 0x02, 0xd0, /* mov.l @(12,pc),r0 */
2145 0xce, 0x01, /* mov.l @(r0,r12),r1 */
2146 0x04, 0x70, /* add #4, r0 */
2147 0x2b, 0x41, /* jmp @r1 */
2148 0xce, 0x0c, /* mov.l @(r0,r12),r12 */
2149 0x09, 0x00, /* nop */
2150 0, 0, 0, 0, /* 0: replaced with offset of this symbol's funcdesc */
2151 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2152 0xc2, 0x60, /* mov.l @r12,r0 */
2153 0x2b, 0x40, /* jmp @r0 */
2154 0xc1, 0x53, /* mov.l @(4,r12),r3 */
2155 0x09, 0x00, /* nop */
2158 static const struct elf_sh_plt_info fdpic_sh_plts[2] = {
2160 /* Big-endian PIC. */
2163 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2164 fdpic_sh_plt_entry_be,
2165 FDPIC_PLT_ENTRY_SIZE,
2166 { 12, MINUS_ONE, 16, FALSE },
2167 FDPIC_PLT_LAZY_OFFSET,
2171 /* Little-endian PIC. */
2174 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2175 fdpic_sh_plt_entry_le,
2176 FDPIC_PLT_ENTRY_SIZE,
2177 { 12, MINUS_ONE, 16, FALSE },
2178 FDPIC_PLT_LAZY_OFFSET,
2183 /* On SH2A, we can use the movi20 instruction to generate shorter PLT
2184 entries for the first 64K slots. We use the normal FDPIC PLT entry
2185 past that point; we could also use movi20s, which might be faster,
2186 but would not be any smaller. */
2188 #define FDPIC_SH2A_PLT_ENTRY_SIZE 24
2189 #define FDPIC_SH2A_PLT_LAZY_OFFSET 16
2191 static const bfd_byte fdpic_sh2a_plt_entry_be[FDPIC_SH2A_PLT_ENTRY_SIZE] =
2193 0, 0, 0, 0, /* movi20 #gotofffuncdesc,r0 */
2194 0x01, 0xce, /* mov.l @(r0,r12),r1 */
2195 0x70, 0x04, /* add #4, r0 */
2196 0x41, 0x2b, /* jmp @r1 */
2197 0x0c, 0xce, /* mov.l @(r0,r12),r12 */
2198 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2199 0x60, 0xc2, /* mov.l @r12,r0 */
2200 0x40, 0x2b, /* jmp @r0 */
2201 0x53, 0xc1, /* mov.l @(4,r12),r3 */
2202 0x00, 0x09, /* nop */
2205 static const bfd_byte fdpic_sh2a_plt_entry_le[FDPIC_SH2A_PLT_ENTRY_SIZE] =
2207 0, 0, 0, 0, /* movi20 #gotofffuncdesc,r0 */
2208 0xce, 0x01, /* mov.l @(r0,r12),r1 */
2209 0x04, 0x70, /* add #4, r0 */
2210 0x2b, 0x41, /* jmp @r1 */
2211 0xce, 0x0c, /* mov.l @(r0,r12),r12 */
2212 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2213 0xc2, 0x60, /* mov.l @r12,r0 */
2214 0x2b, 0x40, /* jmp @r0 */
2215 0xc1, 0x53, /* mov.l @(4,r12),r3 */
2216 0x09, 0x00, /* nop */
2219 static const struct elf_sh_plt_info fdpic_sh2a_short_plt_be = {
2220 /* Big-endian FDPIC, max index 64K. */
2223 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2224 fdpic_sh2a_plt_entry_be,
2225 FDPIC_SH2A_PLT_ENTRY_SIZE,
2226 { 0, MINUS_ONE, 12, TRUE },
2227 FDPIC_SH2A_PLT_LAZY_OFFSET,
2231 static const struct elf_sh_plt_info fdpic_sh2a_short_plt_le = {
2232 /* Little-endian FDPIC, max index 64K. */
2235 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2236 fdpic_sh2a_plt_entry_le,
2237 FDPIC_SH2A_PLT_ENTRY_SIZE,
2238 { 0, MINUS_ONE, 12, TRUE },
2239 FDPIC_SH2A_PLT_LAZY_OFFSET,
2243 static const struct elf_sh_plt_info fdpic_sh2a_plts[2] = {
2245 /* Big-endian PIC. */
2248 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2249 fdpic_sh_plt_entry_be,
2250 FDPIC_PLT_ENTRY_SIZE,
2251 { 12, MINUS_ONE, 16, FALSE },
2252 FDPIC_PLT_LAZY_OFFSET,
2253 &fdpic_sh2a_short_plt_be
2256 /* Little-endian PIC. */
2259 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2260 fdpic_sh_plt_entry_le,
2261 FDPIC_PLT_ENTRY_SIZE,
2262 { 12, MINUS_ONE, 16, FALSE },
2263 FDPIC_PLT_LAZY_OFFSET,
2264 &fdpic_sh2a_short_plt_le
2268 /* Return the type of PLT associated with ABFD. PIC_P is true if
2269 the object is position-independent. */
2271 static const struct elf_sh_plt_info *
2272 get_plt_info (bfd *abfd, bfd_boolean pic_p)
2274 if (fdpic_object_p (abfd))
2276 /* If any input file requires SH2A we can use a shorter PLT
2278 if (sh_get_arch_from_bfd_mach (bfd_get_mach (abfd)) & arch_sh2a_base)
2279 return &fdpic_sh2a_plts[!bfd_big_endian (abfd)];
2281 return &fdpic_sh_plts[!bfd_big_endian (abfd)];
2283 if (vxworks_object_p (abfd))
2284 return &vxworks_sh_plts[pic_p][!bfd_big_endian (abfd)];
2285 return &elf_sh_plts[pic_p][!bfd_big_endian (abfd)];
2288 /* Install a 32-bit PLT field starting at ADDR, which occurs in OUTPUT_BFD.
2289 VALUE is the field's value and CODE_P is true if VALUE refers to code,
2293 install_plt_field (bfd *output_bfd, bfd_boolean code_p ATTRIBUTE_UNUSED,
2294 unsigned long value, bfd_byte *addr)
2296 bfd_put_32 (output_bfd, value, addr);
2300 /* The number of PLT entries which can use a shorter PLT, if any.
2301 Currently always 64K, since only SH-2A FDPIC uses this; a
2302 20-bit movi20 can address that many function descriptors below
2303 _GLOBAL_OFFSET_TABLE_. */
2304 #define MAX_SHORT_PLT 65536
2306 /* Return the index of the PLT entry at byte offset OFFSET. */
2309 get_plt_index (const struct elf_sh_plt_info *info, bfd_vma offset)
2311 bfd_vma plt_index = 0;
2313 offset -= info->plt0_entry_size;
2314 if (info->short_plt != NULL)
2316 if (offset > MAX_SHORT_PLT * info->short_plt->symbol_entry_size)
2318 plt_index = MAX_SHORT_PLT;
2319 offset -= MAX_SHORT_PLT * info->short_plt->symbol_entry_size;
2322 info = info->short_plt;
2324 return plt_index + offset / info->symbol_entry_size;
2327 /* Do the inverse operation. */
2330 get_plt_offset (const struct elf_sh_plt_info *info, bfd_vma plt_index)
2334 if (info->short_plt != NULL)
2336 if (plt_index > MAX_SHORT_PLT)
2338 offset = MAX_SHORT_PLT * info->short_plt->symbol_entry_size;
2339 plt_index -= MAX_SHORT_PLT;
2342 info = info->short_plt;
2344 return (offset + info->plt0_entry_size
2345 + (plt_index * info->symbol_entry_size));
2348 /* The sh linker needs to keep track of the number of relocs that it
2349 decides to copy as dynamic relocs in check_relocs for each symbol.
2350 This is so that it can later discard them if they are found to be
2351 unnecessary. We store the information in a field extending the
2352 regular ELF linker hash table. */
2354 struct elf_sh_dyn_relocs
2356 struct elf_sh_dyn_relocs *next;
2358 /* The input section of the reloc. */
2361 /* Total number of relocs copied for the input section. */
2362 bfd_size_type count;
2364 /* Number of pc-relative relocs copied for the input section. */
2365 bfd_size_type pc_count;
2370 bfd_signed_vma refcount;
2374 /* sh ELF linker hash entry. */
2376 struct elf_sh_link_hash_entry
2378 struct elf_link_hash_entry root;
2380 #ifdef INCLUDE_SHMEDIA
2383 bfd_signed_vma refcount;
2388 /* Track dynamic relocs copied for this symbol. */
2389 struct elf_sh_dyn_relocs *dyn_relocs;
2391 bfd_signed_vma gotplt_refcount;
2393 /* A local function descriptor, for FDPIC. The refcount counts
2394 R_SH_FUNCDESC, R_SH_GOTOFFFUNCDESC, and R_SH_GOTOFFFUNCDESC20
2395 relocations; the PLT and GOT entry are accounted
2396 for separately. After adjust_dynamic_symbol, the offset is
2397 MINUS_ONE if there is no local descriptor (dynamic linker
2398 managed and no PLT entry, or undefined weak non-dynamic).
2399 During check_relocs we do not yet know whether the local
2400 descriptor will be canonical. */
2401 union gotref funcdesc;
2403 /* How many of the above refcounted relocations were R_SH_FUNCDESC,
2404 and thus require fixups or relocations. */
2405 bfd_signed_vma abs_funcdesc_refcount;
2408 GOT_UNKNOWN = 0, GOT_NORMAL, GOT_TLS_GD, GOT_TLS_IE, GOT_FUNCDESC
2412 #define sh_elf_hash_entry(ent) ((struct elf_sh_link_hash_entry *)(ent))
2414 struct sh_elf_obj_tdata
2416 struct elf_obj_tdata root;
2418 /* got_type for each local got entry. */
2419 char *local_got_type;
2421 /* Function descriptor refcount and offset for each local symbol. */
2422 union gotref *local_funcdesc;
2425 #define sh_elf_tdata(abfd) \
2426 ((struct sh_elf_obj_tdata *) (abfd)->tdata.any)
2428 #define sh_elf_local_got_type(abfd) \
2429 (sh_elf_tdata (abfd)->local_got_type)
2431 #define sh_elf_local_funcdesc(abfd) \
2432 (sh_elf_tdata (abfd)->local_funcdesc)
2434 #define is_sh_elf(bfd) \
2435 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2436 && elf_tdata (bfd) != NULL \
2437 && elf_object_id (bfd) == SH_ELF_DATA)
2439 /* Override the generic function because we need to store sh_elf_obj_tdata
2440 as the specific tdata. */
2443 sh_elf_mkobject (bfd *abfd)
2445 return bfd_elf_allocate_object (abfd, sizeof (struct sh_elf_obj_tdata),
2449 /* sh ELF linker hash table. */
2451 struct elf_sh_link_hash_table
2453 struct elf_link_hash_table root;
2455 /* 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->sgot = bfd_get_linker_section (dynobj, ".got");
2613 htab->sgotplt = bfd_get_linker_section (dynobj, ".got.plt");
2614 htab->srelgot = bfd_get_linker_section (dynobj, ".rela.got");
2615 if (! htab->sgot || ! htab->sgotplt || ! htab->srelgot)
2618 htab->sfuncdesc = bfd_make_section_anyway_with_flags (dynobj, ".got.funcdesc",
2619 (SEC_ALLOC | SEC_LOAD
2622 | SEC_LINKER_CREATED));
2623 if (htab->sfuncdesc == NULL
2624 || ! bfd_set_section_alignment (dynobj, htab->sfuncdesc, 2))
2627 htab->srelfuncdesc = bfd_make_section_anyway_with_flags (dynobj,
2628 ".rela.got.funcdesc",
2629 (SEC_ALLOC | SEC_LOAD
2632 | SEC_LINKER_CREATED
2634 if (htab->srelfuncdesc == NULL
2635 || ! bfd_set_section_alignment (dynobj, htab->srelfuncdesc, 2))
2638 /* Also create .rofixup. */
2639 htab->srofixup = bfd_make_section_anyway_with_flags (dynobj, ".rofixup",
2640 (SEC_ALLOC | SEC_LOAD
2643 | SEC_LINKER_CREATED
2645 if (htab->srofixup == NULL
2646 || ! bfd_set_section_alignment (dynobj, htab->srofixup, 2))
2652 /* Create dynamic sections when linking against a dynamic object. */
2655 sh_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
2657 struct elf_sh_link_hash_table *htab;
2658 flagword flags, pltflags;
2660 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
2663 switch (bed->s->arch_size)
2674 bfd_set_error (bfd_error_bad_value);
2678 htab = sh_elf_hash_table (info);
2682 if (htab->root.dynamic_sections_created)
2685 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
2686 .rel[a].bss sections. */
2688 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2689 | SEC_LINKER_CREATED);
2692 pltflags |= SEC_CODE;
2693 if (bed->plt_not_loaded)
2694 pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
2695 if (bed->plt_readonly)
2696 pltflags |= SEC_READONLY;
2698 s = bfd_make_section_anyway_with_flags (abfd, ".plt", pltflags);
2701 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
2704 if (bed->want_plt_sym)
2706 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
2708 struct elf_link_hash_entry *h;
2709 struct bfd_link_hash_entry *bh = NULL;
2711 if (! (_bfd_generic_link_add_one_symbol
2712 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
2713 (bfd_vma) 0, (const char *) NULL, FALSE,
2714 get_elf_backend_data (abfd)->collect, &bh)))
2717 h = (struct elf_link_hash_entry *) bh;
2719 h->type = STT_OBJECT;
2720 htab->root.hplt = h;
2723 && ! bfd_elf_link_record_dynamic_symbol (info, h))
2727 s = bfd_make_section_anyway_with_flags (abfd,
2728 bed->default_use_rela_p
2729 ? ".rela.plt" : ".rel.plt",
2730 flags | SEC_READONLY);
2733 || ! bfd_set_section_alignment (abfd, s, ptralign))
2736 if (htab->sgot == NULL
2737 && !create_got_section (abfd, info))
2740 if (bed->want_dynbss)
2742 /* The .dynbss section is a place to put symbols which are defined
2743 by dynamic objects, are referenced by regular objects, and are
2744 not functions. We must allocate space for them in the process
2745 image and use a R_*_COPY reloc to tell the dynamic linker to
2746 initialize them at run time. The linker script puts the .dynbss
2747 section into the .bss section of the final image. */
2748 s = bfd_make_section_anyway_with_flags (abfd, ".dynbss",
2749 SEC_ALLOC | SEC_LINKER_CREATED);
2754 /* The .rel[a].bss section holds copy relocs. This section is not
2755 normally needed. We need to create it here, though, so that the
2756 linker will map it to an output section. We can't just create it
2757 only if we need it, because we will not know whether we need it
2758 until we have seen all the input files, and the first time the
2759 main linker code calls BFD after examining all the input files
2760 (size_dynamic_sections) the input sections have already been
2761 mapped to the output sections. If the section turns out not to
2762 be needed, we can discard it later. We will never need this
2763 section when generating a shared object, since they do not use
2767 s = bfd_make_section_anyway_with_flags (abfd,
2768 (bed->default_use_rela_p
2769 ? ".rela.bss" : ".rel.bss"),
2770 flags | SEC_READONLY);
2773 || ! bfd_set_section_alignment (abfd, s, ptralign))
2778 if (htab->vxworks_p)
2780 if (!elf_vxworks_create_dynamic_sections (abfd, info, &htab->srelplt2))
2787 /* Adjust a symbol defined by a dynamic object and referenced by a
2788 regular object. The current definition is in some section of the
2789 dynamic object, but we're not including those sections. We have to
2790 change the definition to something the rest of the link can
2794 sh_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
2795 struct elf_link_hash_entry *h)
2797 struct elf_sh_link_hash_table *htab;
2798 struct elf_sh_link_hash_entry *eh;
2799 struct elf_sh_dyn_relocs *p;
2802 htab = sh_elf_hash_table (info);
2806 /* Make sure we know what is going on here. */
2807 BFD_ASSERT (htab->root.dynobj != NULL
2809 || h->u.weakdef != NULL
2812 && !h->def_regular)));
2814 /* If this is a function, put it in the procedure linkage table. We
2815 will fill in the contents of the procedure linkage table later,
2816 when we know the address of the .got section. */
2817 if (h->type == STT_FUNC
2820 if (h->plt.refcount <= 0
2821 || SYMBOL_CALLS_LOCAL (info, h)
2822 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
2823 && h->root.type == bfd_link_hash_undefweak))
2825 /* This case can occur if we saw a PLT reloc in an input
2826 file, but the symbol was never referred to by a dynamic
2827 object. In such a case, we don't actually need to build
2828 a procedure linkage table, and we can just do a REL32
2830 h->plt.offset = (bfd_vma) -1;
2837 h->plt.offset = (bfd_vma) -1;
2839 /* If this is a weak symbol, and there is a real definition, the
2840 processor independent code will have arranged for us to see the
2841 real definition first, and we can just use the same value. */
2842 if (h->u.weakdef != NULL)
2844 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
2845 || h->u.weakdef->root.type == bfd_link_hash_defweak);
2846 h->root.u.def.section = h->u.weakdef->root.u.def.section;
2847 h->root.u.def.value = h->u.weakdef->root.u.def.value;
2848 if (info->nocopyreloc)
2849 h->non_got_ref = h->u.weakdef->non_got_ref;
2853 /* This is a reference to a symbol defined by a dynamic object which
2854 is not a function. */
2856 /* If we are creating a shared library, we must presume that the
2857 only references to the symbol are via the global offset table.
2858 For such cases we need not do anything here; the relocations will
2859 be handled correctly by relocate_section. */
2863 /* If there are no references to this symbol that do not use the
2864 GOT, we don't need to generate a copy reloc. */
2865 if (!h->non_got_ref)
2868 /* If -z nocopyreloc was given, we won't generate them either. */
2869 if (info->nocopyreloc)
2875 eh = (struct elf_sh_link_hash_entry *) h;
2876 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2878 s = p->sec->output_section;
2879 if (s != NULL && (s->flags & (SEC_READONLY | SEC_HAS_CONTENTS)) != 0)
2883 /* If we didn't find any dynamic relocs in sections which needs the
2884 copy reloc, then we'll be keeping the dynamic relocs and avoiding
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 (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_sh_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))
2968 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
2970 asection *s = htab->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 && !info->shared && !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->sgotplt->size += 4;
3005 htab->sgotplt->size += 8;
3007 /* We also need to make an entry in the .rel.plt section. */
3008 htab->srelplt->size += sizeof (Elf32_External_Rela);
3010 if (htab->vxworks_p && !info->shared)
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))
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 && !info->shared
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 && !h->def_dynamic && !info->shared)
3072 /* R_SH_TLS_IE_32 needs one dynamic relocation if dynamic,
3073 R_SH_TLS_GD needs one if local symbol and two if global. */
3074 else if ((got_type == GOT_TLS_GD && h->dynindx == -1)
3075 || got_type == GOT_TLS_IE)
3076 htab->srelgot->size += sizeof (Elf32_External_Rela);
3077 else if (got_type == GOT_TLS_GD)
3078 htab->srelgot->size += 2 * sizeof (Elf32_External_Rela);
3079 else if (got_type == GOT_FUNCDESC)
3081 if (!info->shared && SYMBOL_FUNCDESC_LOCAL (info, h))
3082 htab->srofixup->size += 4;
3084 htab->srelgot->size += sizeof (Elf32_External_Rela);
3086 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3087 || h->root.type != bfd_link_hash_undefweak)
3089 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
3090 htab->srelgot->size += sizeof (Elf32_External_Rela);
3091 else if (htab->fdpic_p && !info->shared && got_type == GOT_NORMAL
3092 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3093 || h->root.type != bfd_link_hash_undefweak))
3094 htab->srofixup->size += 4;
3097 h->got.offset = (bfd_vma) -1;
3099 #ifdef INCLUDE_SHMEDIA
3100 if (eh->datalabel_got.refcount > 0)
3105 /* Make sure this symbol is output as a dynamic symbol.
3106 Undefined weak syms won't yet be marked as dynamic. */
3107 if (h->dynindx == -1
3108 && !h->forced_local)
3110 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3115 eh->datalabel_got.offset = s->size;
3117 dyn = htab->root.dynamic_sections_created;
3118 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h))
3119 htab->srelgot->size += sizeof (Elf32_External_Rela);
3122 eh->datalabel_got.offset = (bfd_vma) -1;
3125 /* Allocate space for any dynamic relocations to function
3126 descriptors, canonical or otherwise. We need to relocate the
3127 reference unless it resolves to zero, which only happens for
3128 undefined weak symbols (either non-default visibility, or when
3129 static linking). Any GOT slot is accounted for elsewhere. */
3130 if (eh->abs_funcdesc_refcount > 0
3131 && (h->root.type != bfd_link_hash_undefweak
3132 || (htab->root.dynamic_sections_created
3133 && ! SYMBOL_CALLS_LOCAL (info, h))))
3135 if (!info->shared && SYMBOL_FUNCDESC_LOCAL (info, h))
3136 htab->srofixup->size += eh->abs_funcdesc_refcount * 4;
3139 += eh->abs_funcdesc_refcount * sizeof (Elf32_External_Rela);
3142 /* We must allocate a function descriptor if there are references to
3143 a canonical descriptor (R_SH_GOTFUNCDESC or R_SH_FUNCDESC) and
3144 the dynamic linker isn't going to allocate it. None of this
3145 applies if we already created one in .got.plt, but if the
3146 canonical function descriptor can be in this object, there
3147 won't be a PLT entry at all. */
3148 if ((eh->funcdesc.refcount > 0
3149 || (h->got.offset != MINUS_ONE && eh->got_type == GOT_FUNCDESC))
3150 && h->root.type != bfd_link_hash_undefweak
3151 && SYMBOL_FUNCDESC_LOCAL (info, h))
3153 /* Make room for this function descriptor. */
3154 eh->funcdesc.offset = htab->sfuncdesc->size;
3155 htab->sfuncdesc->size += 8;
3157 /* We will need a relocation or two fixups to initialize the
3158 function descriptor, so allocate those too. */
3159 if (!info->shared && SYMBOL_CALLS_LOCAL (info, h))
3160 htab->srofixup->size += 8;
3162 htab->srelfuncdesc->size += sizeof (Elf32_External_Rela);
3165 if (eh->dyn_relocs == NULL)
3168 /* In the shared -Bsymbolic case, discard space allocated for
3169 dynamic pc-relative relocs against symbols which turn out to be
3170 defined in regular objects. For the normal shared case, discard
3171 space for pc-relative relocs that have become local due to symbol
3172 visibility changes. */
3176 if (SYMBOL_CALLS_LOCAL (info, h))
3178 struct elf_sh_dyn_relocs **pp;
3180 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
3182 p->count -= p->pc_count;
3191 if (htab->vxworks_p)
3193 struct elf_sh_dyn_relocs **pp;
3195 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
3197 if (strcmp (p->sec->output_section->name, ".tls_vars") == 0)
3204 /* Also discard relocs on undefined weak syms with non-default
3206 if (eh->dyn_relocs != NULL
3207 && h->root.type == bfd_link_hash_undefweak)
3209 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
3210 eh->dyn_relocs = NULL;
3212 /* Make sure undefined weak symbols are output as a dynamic
3214 else if (h->dynindx == -1
3215 && !h->forced_local)
3217 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3224 /* For the non-shared case, discard space for relocs against
3225 symbols which turn out to need copy relocs or are not
3231 || (htab->root.dynamic_sections_created
3232 && (h->root.type == bfd_link_hash_undefweak
3233 || h->root.type == bfd_link_hash_undefined))))
3235 /* Make sure this symbol is output as a dynamic symbol.
3236 Undefined weak syms won't yet be marked as dynamic. */
3237 if (h->dynindx == -1
3238 && !h->forced_local)
3240 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3244 /* If that succeeded, we know we'll be keeping all the
3246 if (h->dynindx != -1)
3250 eh->dyn_relocs = NULL;
3255 /* Finally, allocate space. */
3256 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3258 asection *sreloc = elf_section_data (p->sec)->sreloc;
3259 sreloc->size += p->count * sizeof (Elf32_External_Rela);
3261 /* If we need relocations, we do not need fixups. */
3262 if (htab->fdpic_p && !info->shared)
3263 htab->srofixup->size -= 4 * (p->count - p->pc_count);
3269 /* Find any dynamic relocs that apply to read-only sections. */
3272 readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf)
3274 struct elf_sh_link_hash_entry *eh;
3275 struct elf_sh_dyn_relocs *p;
3277 eh = (struct elf_sh_link_hash_entry *) h;
3278 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3280 asection *s = p->sec->output_section;
3282 if (s != NULL && (s->flags & SEC_READONLY) != 0)
3284 struct bfd_link_info *info = (struct bfd_link_info *) inf;
3286 info->flags |= DF_TEXTREL;
3288 /* Not an error, just cut short the traversal. */
3295 /* This function is called after all the input files have been read,
3296 and the input sections have been assigned to output sections.
3297 It's a convenient place to determine the PLT style. */
3300 sh_elf_always_size_sections (bfd *output_bfd, struct bfd_link_info *info)
3302 sh_elf_hash_table (info)->plt_info = get_plt_info (output_bfd, info->shared);
3304 if (sh_elf_hash_table (info)->fdpic_p && !info->relocatable
3305 && !bfd_elf_stack_segment_size (output_bfd, info,
3306 "__stacksize", DEFAULT_STACK_SIZE))
3311 /* Set the sizes of the dynamic sections. */
3314 sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
3315 struct bfd_link_info *info)
3317 struct elf_sh_link_hash_table *htab;
3323 htab = sh_elf_hash_table (info);
3327 dynobj = htab->root.dynobj;
3328 BFD_ASSERT (dynobj != NULL);
3330 if (htab->root.dynamic_sections_created)
3332 /* Set the contents of the .interp section to the interpreter. */
3333 if (info->executable)
3335 s = bfd_get_linker_section (dynobj, ".interp");
3336 BFD_ASSERT (s != NULL);
3337 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
3338 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
3342 /* Set up .got offsets for local syms, and space for local dynamic
3344 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
3346 bfd_signed_vma *local_got;
3347 bfd_signed_vma *end_local_got;
3348 union gotref *local_funcdesc, *end_local_funcdesc;
3349 char *local_got_type;
3350 bfd_size_type locsymcount;
3351 Elf_Internal_Shdr *symtab_hdr;
3354 if (! is_sh_elf (ibfd))
3357 for (s = ibfd->sections; s != NULL; s = s->next)
3359 struct elf_sh_dyn_relocs *p;
3361 for (p = ((struct elf_sh_dyn_relocs *)
3362 elf_section_data (s)->local_dynrel);
3366 if (! bfd_is_abs_section (p->sec)
3367 && bfd_is_abs_section (p->sec->output_section))
3369 /* Input section has been discarded, either because
3370 it is a copy of a linkonce section or due to
3371 linker script /DISCARD/, so we'll be discarding
3374 else if (htab->vxworks_p
3375 && strcmp (p->sec->output_section->name,
3378 /* Relocations in vxworks .tls_vars sections are
3379 handled specially by the loader. */
3381 else if (p->count != 0)
3383 srel = elf_section_data (p->sec)->sreloc;
3384 srel->size += p->count * sizeof (Elf32_External_Rela);
3385 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
3386 info->flags |= DF_TEXTREL;
3388 /* If we need relocations, we do not need fixups. */
3389 if (htab->fdpic_p && !info->shared)
3390 htab->srofixup->size -= 4 * (p->count - p->pc_count);
3395 symtab_hdr = &elf_symtab_hdr (ibfd);
3396 locsymcount = symtab_hdr->sh_info;
3397 #ifdef INCLUDE_SHMEDIA
3398 /* Count datalabel local GOT. */
3402 srel = htab->srelgot;
3404 local_got = elf_local_got_refcounts (ibfd);
3407 end_local_got = local_got + locsymcount;
3408 local_got_type = sh_elf_local_got_type (ibfd);
3409 local_funcdesc = sh_elf_local_funcdesc (ibfd);
3410 for (; local_got < end_local_got; ++local_got)
3414 *local_got = s->size;
3416 if (*local_got_type == GOT_TLS_GD)
3419 srel->size += sizeof (Elf32_External_Rela);
3421 htab->srofixup->size += 4;
3423 if (*local_got_type == GOT_FUNCDESC)
3425 if (local_funcdesc == NULL)
3429 size = locsymcount * sizeof (union gotref);
3430 local_funcdesc = (union gotref *) bfd_zalloc (ibfd,
3432 if (local_funcdesc == NULL)
3434 sh_elf_local_funcdesc (ibfd) = local_funcdesc;
3435 local_funcdesc += (local_got
3436 - elf_local_got_refcounts (ibfd));
3438 local_funcdesc->refcount++;
3443 *local_got = (bfd_vma) -1;
3448 local_funcdesc = sh_elf_local_funcdesc (ibfd);
3451 end_local_funcdesc = local_funcdesc + locsymcount;
3453 for (; local_funcdesc < end_local_funcdesc; ++local_funcdesc)
3455 if (local_funcdesc->refcount > 0)
3457 local_funcdesc->offset = htab->sfuncdesc->size;
3458 htab->sfuncdesc->size += 8;
3460 htab->srofixup->size += 8;
3462 htab->srelfuncdesc->size += sizeof (Elf32_External_Rela);
3465 local_funcdesc->offset = MINUS_ONE;
3471 if (htab->tls_ldm_got.refcount > 0)
3473 /* Allocate 2 got entries and 1 dynamic reloc for R_SH_TLS_LD_32
3475 htab->tls_ldm_got.offset = htab->sgot->size;
3476 htab->sgot->size += 8;
3477 htab->srelgot->size += sizeof (Elf32_External_Rela);
3480 htab->tls_ldm_got.offset = -1;
3482 /* Only the reserved entries should be present. For FDPIC, they go at
3483 the end of .got.plt. */
3486 BFD_ASSERT (htab->sgotplt && htab->sgotplt->size == 12);
3487 htab->sgotplt->size = 0;
3490 /* Allocate global sym .plt and .got entries, and space for global
3491 sym dynamic relocs. */
3492 elf_link_hash_traverse (&htab->root, allocate_dynrelocs, info);
3494 /* Move the reserved entries and the _GLOBAL_OFFSET_TABLE_ symbol to the
3495 end of the FDPIC .got.plt. */
3498 htab->root.hgot->root.u.def.value = htab->sgotplt->size;
3499 htab->sgotplt->size += 12;
3502 /* At the very end of the .rofixup section is a pointer to the GOT. */
3503 if (htab->fdpic_p && htab->srofixup != NULL)
3504 htab->srofixup->size += 4;
3506 /* We now have determined the sizes of the various dynamic sections.
3507 Allocate memory for them. */
3509 for (s = dynobj->sections; s != NULL; s = s->next)
3511 if ((s->flags & SEC_LINKER_CREATED) == 0)
3516 || s == htab->sgotplt
3517 || s == htab->sfuncdesc
3518 || s == htab->srofixup
3519 || s == htab->sdynbss)
3521 /* Strip this section if we don't need it; see the
3524 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
3526 if (s->size != 0 && s != htab->srelplt && s != htab->srelplt2)
3529 /* We use the reloc_count field as a counter if we need
3530 to copy relocs into the output file. */
3535 /* It's not one of our sections, so don't allocate space. */
3541 /* If we don't need this section, strip it from the
3542 output file. This is mostly to handle .rela.bss and
3543 .rela.plt. We must create both sections in
3544 create_dynamic_sections, because they must be created
3545 before the linker maps input sections to output
3546 sections. The linker does that before
3547 adjust_dynamic_symbol is called, and it is that
3548 function which decides whether anything needs to go
3549 into these sections. */
3551 s->flags |= SEC_EXCLUDE;
3555 if ((s->flags & SEC_HAS_CONTENTS) == 0)
3558 /* Allocate memory for the section contents. We use bfd_zalloc
3559 here in case unused entries are not reclaimed before the
3560 section's contents are written out. This should not happen,
3561 but this way if it does, we get a R_SH_NONE reloc instead
3563 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
3564 if (s->contents == NULL)
3568 if (htab->root.dynamic_sections_created)
3570 /* Add some entries to the .dynamic section. We fill in the
3571 values later, in sh_elf_finish_dynamic_sections, but we
3572 must add the entries now so that we get the correct size for
3573 the .dynamic section. The DT_DEBUG entry is filled in by the
3574 dynamic linker and used by the debugger. */
3575 #define add_dynamic_entry(TAG, VAL) \
3576 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3578 if (info->executable)
3580 if (! add_dynamic_entry (DT_DEBUG, 0))
3584 if (htab->splt->size != 0)
3586 if (! add_dynamic_entry (DT_PLTGOT, 0)
3587 || ! add_dynamic_entry (DT_PLTRELSZ, 0)
3588 || ! add_dynamic_entry (DT_PLTREL, DT_RELA)
3589 || ! add_dynamic_entry (DT_JMPREL, 0))
3592 else if ((elf_elfheader (output_bfd)->e_flags & EF_SH_FDPIC)
3593 && htab->sgot->size != 0)
3595 if (! add_dynamic_entry (DT_PLTGOT, 0))
3601 if (! add_dynamic_entry (DT_RELA, 0)
3602 || ! add_dynamic_entry (DT_RELASZ, 0)
3603 || ! add_dynamic_entry (DT_RELAENT,
3604 sizeof (Elf32_External_Rela)))
3607 /* If any dynamic relocs apply to a read-only section,
3608 then we need a DT_TEXTREL entry. */
3609 if ((info->flags & DF_TEXTREL) == 0)
3610 elf_link_hash_traverse (&htab->root, readonly_dynrelocs, info);
3612 if ((info->flags & DF_TEXTREL) != 0)
3614 if (! add_dynamic_entry (DT_TEXTREL, 0))
3619 && !elf_vxworks_add_dynamic_entries (output_bfd, info))
3622 #undef add_dynamic_entry
3627 /* Add a dynamic relocation to the SRELOC section. */
3629 inline static bfd_vma
3630 sh_elf_add_dyn_reloc (bfd *output_bfd, asection *sreloc, bfd_vma offset,
3631 int reloc_type, long dynindx, bfd_vma addend)
3633 Elf_Internal_Rela outrel;
3634 bfd_vma reloc_offset;
3636 outrel.r_offset = offset;
3637 outrel.r_info = ELF32_R_INFO (dynindx, reloc_type);
3638 outrel.r_addend = addend;
3640 reloc_offset = sreloc->reloc_count * sizeof (Elf32_External_Rela);
3641 BFD_ASSERT (reloc_offset < sreloc->size);
3642 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
3643 sreloc->contents + reloc_offset);
3644 sreloc->reloc_count++;
3646 return reloc_offset;
3649 /* Add an FDPIC read-only fixup. */
3652 sh_elf_add_rofixup (bfd *output_bfd, asection *srofixup, bfd_vma offset)
3654 bfd_vma fixup_offset;
3656 fixup_offset = srofixup->reloc_count++ * 4;
3657 BFD_ASSERT (fixup_offset < srofixup->size);
3658 bfd_put_32 (output_bfd, offset, srofixup->contents + fixup_offset);
3661 /* Return the offset of the generated .got section from the
3662 _GLOBAL_OFFSET_TABLE_ symbol. */
3664 static bfd_signed_vma
3665 sh_elf_got_offset (struct elf_sh_link_hash_table *htab)
3667 return (htab->sgot->output_offset - htab->sgotplt->output_offset
3668 - htab->root.hgot->root.u.def.value);
3671 /* Find the segment number in which OSEC, and output section, is
3675 sh_elf_osec_to_segment (bfd *output_bfd, asection *osec)
3677 Elf_Internal_Phdr *p = NULL;
3679 if (output_bfd->xvec->flavour == bfd_target_elf_flavour)
3680 p = _bfd_elf_find_segment_containing_section (output_bfd, osec);
3682 /* FIXME: Nothing ever says what this index is relative to. The kernel
3683 supplies data in terms of the number of load segments but this is
3684 a phdr index and the first phdr may not be a load segment. */
3685 return (p != NULL) ? p - elf_tdata (output_bfd)->phdr : -1;
3689 sh_elf_osec_readonly_p (bfd *output_bfd, asection *osec)
3691 unsigned seg = sh_elf_osec_to_segment (output_bfd, osec);
3693 return (seg != (unsigned) -1
3694 && ! (elf_tdata (output_bfd)->phdr[seg].p_flags & PF_W));
3697 /* Generate the initial contents of a local function descriptor, along
3698 with any relocations or fixups required. */
3700 sh_elf_initialize_funcdesc (bfd *output_bfd,
3701 struct bfd_link_info *info,
3702 struct elf_link_hash_entry *h,
3707 struct elf_sh_link_hash_table *htab;
3711 htab = sh_elf_hash_table (info);
3713 /* FIXME: The ABI says that the offset to the function goes in the
3714 descriptor, along with the segment index. We're RELA, so it could
3715 go in the reloc instead... */
3717 if (h != NULL && SYMBOL_CALLS_LOCAL (info, h))
3719 section = h->root.u.def.section;
3720 value = h->root.u.def.value;
3723 if (h == NULL || SYMBOL_CALLS_LOCAL (info, h))
3725 dynindx = elf_section_data (section->output_section)->dynindx;
3726 addr = value + section->output_offset;
3727 seg = sh_elf_osec_to_segment (output_bfd, section->output_section);
3731 BFD_ASSERT (h->dynindx != -1);
3732 dynindx = h->dynindx;
3736 if (!info->shared && SYMBOL_CALLS_LOCAL (info, h))
3738 if (h == NULL || h->root.type != bfd_link_hash_undefweak)
3740 sh_elf_add_rofixup (output_bfd, htab->srofixup,
3742 + htab->sfuncdesc->output_section->vma
3743 + htab->sfuncdesc->output_offset);
3744 sh_elf_add_rofixup (output_bfd, htab->srofixup,
3746 + htab->sfuncdesc->output_section->vma
3747 + htab->sfuncdesc->output_offset);
3750 /* There are no dynamic relocations so fill in the final
3751 address and gp value (barring fixups). */
3752 addr += section->output_section->vma;
3753 seg = htab->root.hgot->root.u.def.value
3754 + htab->root.hgot->root.u.def.section->output_section->vma
3755 + htab->root.hgot->root.u.def.section->output_offset;
3758 sh_elf_add_dyn_reloc (output_bfd, htab->srelfuncdesc,
3760 + htab->sfuncdesc->output_section->vma
3761 + htab->sfuncdesc->output_offset,
3762 R_SH_FUNCDESC_VALUE, dynindx, 0);
3764 bfd_put_32 (output_bfd, addr, htab->sfuncdesc->contents + offset);
3765 bfd_put_32 (output_bfd, seg, htab->sfuncdesc->contents + offset + 4);
3770 /* Install a 20-bit movi20 field starting at ADDR, which occurs in OUTPUT_BFD.
3771 VALUE is the field's value. Return bfd_reloc_ok if successful or an error
3774 static bfd_reloc_status_type
3775 install_movi20_field (bfd *output_bfd, unsigned long relocation,
3776 bfd *input_bfd, asection *input_section,
3777 bfd_byte *contents, bfd_vma offset)
3779 unsigned long cur_val;
3781 bfd_reloc_status_type r;
3783 if (offset > bfd_get_section_limit (input_bfd, input_section))
3784 return bfd_reloc_outofrange;
3786 r = bfd_check_overflow (complain_overflow_signed, 20, 0,
3787 bfd_arch_bits_per_address (input_bfd), relocation);
3788 if (r != bfd_reloc_ok)
3791 addr = contents + offset;
3792 cur_val = bfd_get_16 (output_bfd, addr);
3793 bfd_put_16 (output_bfd, cur_val | ((relocation & 0xf0000) >> 12), addr);
3794 bfd_put_16 (output_bfd, relocation & 0xffff, addr + 2);
3796 return bfd_reloc_ok;
3799 /* Relocate an SH ELF section. */
3802 sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
3803 bfd *input_bfd, asection *input_section,
3804 bfd_byte *contents, Elf_Internal_Rela *relocs,
3805 Elf_Internal_Sym *local_syms,
3806 asection **local_sections)
3808 struct elf_sh_link_hash_table *htab;
3809 Elf_Internal_Shdr *symtab_hdr;
3810 struct elf_link_hash_entry **sym_hashes;
3811 Elf_Internal_Rela *rel, *relend;
3813 bfd_vma *local_got_offsets;
3814 asection *sgot = NULL;
3815 asection *sgotplt = NULL;
3816 asection *splt = NULL;
3817 asection *sreloc = NULL;
3818 asection *srelgot = NULL;
3819 bfd_boolean is_vxworks_tls;
3820 unsigned isec_segment, got_segment, plt_segment, check_segment[2];
3821 bfd_boolean fdpic_p = FALSE;
3823 BFD_ASSERT (is_sh_elf (input_bfd));
3825 htab = sh_elf_hash_table (info);
3828 dynobj = htab->root.dynobj;
3830 sgotplt = htab->sgotplt;
3832 fdpic_p = htab->fdpic_p;
3834 symtab_hdr = &elf_symtab_hdr (input_bfd);
3835 sym_hashes = elf_sym_hashes (input_bfd);
3836 local_got_offsets = elf_local_got_offsets (input_bfd);
3838 isec_segment = sh_elf_osec_to_segment (output_bfd,
3839 input_section->output_section);
3840 if (fdpic_p && sgot)
3841 got_segment = sh_elf_osec_to_segment (output_bfd,
3842 sgot->output_section);
3845 if (fdpic_p && splt)
3846 plt_segment = sh_elf_osec_to_segment (output_bfd,
3847 splt->output_section);
3851 /* We have to handle relocations in vxworks .tls_vars sections
3852 specially, because the dynamic loader is 'weird'. */
3853 is_vxworks_tls = (htab && htab->vxworks_p && info->shared
3854 && !strcmp (input_section->output_section->name,
3858 relend = relocs + input_section->reloc_count;
3859 for (; rel < relend; rel++)
3862 reloc_howto_type *howto;
3863 unsigned long r_symndx;
3864 Elf_Internal_Sym *sym;
3866 struct elf_link_hash_entry *h;
3868 bfd_vma addend = (bfd_vma) 0;
3869 bfd_reloc_status_type r;
3870 int seen_stt_datalabel = 0;
3872 enum got_type got_type;
3873 const char *symname = NULL;
3875 r_symndx = ELF32_R_SYM (rel->r_info);
3877 r_type = ELF32_R_TYPE (rel->r_info);
3879 /* Many of the relocs are only used for relaxing, and are
3880 handled entirely by the relaxation code. */
3881 if (r_type >= (int) R_SH_GNU_VTINHERIT
3882 && r_type <= (int) R_SH_LABEL)
3884 if (r_type == (int) R_SH_NONE)
3888 || r_type >= R_SH_max
3889 || (r_type >= (int) R_SH_FIRST_INVALID_RELOC
3890 && r_type <= (int) R_SH_LAST_INVALID_RELOC)
3891 || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_2
3892 && r_type <= (int) R_SH_LAST_INVALID_RELOC_2)
3893 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_3
3894 && r_type <= (int) R_SH_LAST_INVALID_RELOC_3)
3895 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_4
3896 && r_type <= (int) R_SH_LAST_INVALID_RELOC_4)
3897 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_5
3898 && r_type <= (int) R_SH_LAST_INVALID_RELOC_5)
3899 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_6
3900 && r_type <= (int) R_SH_LAST_INVALID_RELOC_6))
3902 bfd_set_error (bfd_error_bad_value);
3906 howto = get_howto_table (output_bfd) + r_type;
3908 /* For relocs that aren't partial_inplace, we get the addend from
3910 if (! howto->partial_inplace)
3911 addend = rel->r_addend;
3916 check_segment[0] = -1;
3917 check_segment[1] = -1;
3918 if (r_symndx < symtab_hdr->sh_info)
3920 sym = local_syms + r_symndx;
3921 sec = local_sections[r_symndx];
3923 symname = bfd_elf_string_from_elf_section
3924 (input_bfd, symtab_hdr->sh_link, sym->st_name);
3925 if (symname == NULL || *symname == '\0')
3926 symname = bfd_section_name (input_bfd, sec);
3928 relocation = (sec->output_section->vma
3929 + sec->output_offset
3931 /* A local symbol never has STO_SH5_ISA32, so we don't need
3932 datalabel processing here. Make sure this does not change
3934 if ((sym->st_other & STO_SH5_ISA32) != 0)
3935 ((*info->callbacks->reloc_dangerous)
3937 _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
3938 input_bfd, input_section, rel->r_offset));
3940 if (sec != NULL && discarded_section (sec))
3941 /* Handled below. */
3943 else if (info->relocatable)
3945 /* This is a relocatable link. We don't have to change
3946 anything, unless the reloc is against a section symbol,
3947 in which case we have to adjust according to where the
3948 section symbol winds up in the output section. */
3949 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
3951 if (! howto->partial_inplace)
3953 /* For relocations with the addend in the
3954 relocation, we need just to update the addend.
3955 All real relocs are of type partial_inplace; this
3956 code is mostly for completeness. */
3957 rel->r_addend += sec->output_offset;
3962 /* Relocs of type partial_inplace need to pick up the
3963 contents in the contents and add the offset resulting
3964 from the changed location of the section symbol.
3965 Using _bfd_final_link_relocate (e.g. goto
3966 final_link_relocate) here would be wrong, because
3967 relocations marked pc_relative would get the current
3968 location subtracted, and we must only do that at the
3970 r = _bfd_relocate_contents (howto, input_bfd,
3973 contents + rel->r_offset);
3974 goto relocation_done;
3979 else if (! howto->partial_inplace)
3981 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
3982 addend = rel->r_addend;
3984 else if ((sec->flags & SEC_MERGE)
3985 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
3989 if (howto->rightshift || howto->src_mask != 0xffffffff)
3991 (*_bfd_error_handler)
3992 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
3993 input_bfd, input_section,
3994 (long) rel->r_offset, howto->name);
3998 addend = bfd_get_32 (input_bfd, contents + rel->r_offset);
4001 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
4003 addend += msec->output_section->vma + msec->output_offset;
4004 bfd_put_32 (input_bfd, addend, contents + rel->r_offset);
4010 /* FIXME: Ought to make use of the RELOC_FOR_GLOBAL_SYMBOL macro. */
4013 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4014 symname = h->root.root.string;
4015 while (h->root.type == bfd_link_hash_indirect
4016 || h->root.type == bfd_link_hash_warning)
4018 #ifdef INCLUDE_SHMEDIA
4019 /* If the reference passes a symbol marked with
4020 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
4022 seen_stt_datalabel |= h->type == STT_DATALABEL;
4024 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4026 if (h->root.type == bfd_link_hash_defined
4027 || h->root.type == bfd_link_hash_defweak)
4031 dyn = htab ? htab->root.dynamic_sections_created : FALSE;
4032 sec = h->root.u.def.section;
4033 /* In these cases, we don't need the relocation value.
4034 We check specially because in some obscure cases
4035 sec->output_section will be NULL. */
4036 if (r_type == R_SH_GOTPC
4037 || r_type == R_SH_GOTPC_LOW16
4038 || r_type == R_SH_GOTPC_MEDLOW16
4039 || r_type == R_SH_GOTPC_MEDHI16
4040 || r_type == R_SH_GOTPC_HI16
4041 || ((r_type == R_SH_PLT32
4042 || r_type == R_SH_PLT_LOW16
4043 || r_type == R_SH_PLT_MEDLOW16
4044 || r_type == R_SH_PLT_MEDHI16
4045 || r_type == R_SH_PLT_HI16)
4046 && h->plt.offset != (bfd_vma) -1)
4047 || ((r_type == R_SH_GOT32
4048 || r_type == R_SH_GOT20
4049 || r_type == R_SH_GOTFUNCDESC
4050 || r_type == R_SH_GOTFUNCDESC20
4051 || r_type == R_SH_GOTOFFFUNCDESC
4052 || r_type == R_SH_GOTOFFFUNCDESC20
4053 || r_type == R_SH_FUNCDESC
4054 || r_type == R_SH_GOT_LOW16
4055 || r_type == R_SH_GOT_MEDLOW16
4056 || r_type == R_SH_GOT_MEDHI16
4057 || r_type == R_SH_GOT_HI16)
4058 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
4060 || (! info->symbolic && h->dynindx != -1)
4061 || !h->def_regular))
4062 /* The cases above are those in which relocation is
4063 overwritten in the switch block below. The cases
4064 below are those in which we must defer relocation
4065 to run-time, because we can't resolve absolute
4066 addresses when creating a shared library. */
4068 && ((! info->symbolic && h->dynindx != -1)
4070 && ((r_type == R_SH_DIR32
4071 && !h->forced_local)
4072 || (r_type == R_SH_REL32
4073 && !SYMBOL_CALLS_LOCAL (info, h)))
4074 && ((input_section->flags & SEC_ALLOC) != 0
4075 /* DWARF will emit R_SH_DIR32 relocations in its
4076 sections against symbols defined externally
4077 in shared libraries. We can't do anything
4079 || ((input_section->flags & SEC_DEBUGGING) != 0
4080 && h->def_dynamic)))
4081 /* Dynamic relocs are not propagated for SEC_DEBUGGING
4082 sections because such sections are not SEC_ALLOC and
4083 thus ld.so will not process them. */
4084 || (sec->output_section == NULL
4085 && ((input_section->flags & SEC_DEBUGGING) != 0
4087 || (sec->output_section == NULL
4088 && (sh_elf_hash_entry (h)->got_type == GOT_TLS_IE
4089 || sh_elf_hash_entry (h)->got_type == GOT_TLS_GD)))
4091 else if (sec->output_section != NULL)
4092 relocation = ((h->root.u.def.value
4093 + sec->output_section->vma
4094 + sec->output_offset)
4095 /* A STO_SH5_ISA32 causes a "bitor 1" to the
4096 symbol value, unless we've seen
4097 STT_DATALABEL on the way to it. */
4098 | ((h->other & STO_SH5_ISA32) != 0
4099 && ! seen_stt_datalabel));
4100 else if (!info->relocatable
4101 && (_bfd_elf_section_offset (output_bfd, info,
4106 (*_bfd_error_handler)
4107 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4110 (long) rel->r_offset,
4112 h->root.root.string);
4116 else if (h->root.type == bfd_link_hash_undefweak)
4118 else if (info->unresolved_syms_in_objects == RM_IGNORE
4119 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
4121 else if (!info->relocatable)
4123 if (! info->callbacks->undefined_symbol
4124 (info, h->root.root.string, input_bfd,
4125 input_section, rel->r_offset,
4126 (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
4127 || ELF_ST_VISIBILITY (h->other))))
4132 if (sec != NULL && discarded_section (sec))
4133 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
4134 rel, 1, relend, howto, 0, contents);
4136 if (info->relocatable)
4139 /* Check for inter-segment relocations in FDPIC files. Most
4140 relocations connect the relocation site to the location of
4141 the target symbol, but there are some exceptions below. */
4142 check_segment[0] = isec_segment;
4144 check_segment[1] = sh_elf_osec_to_segment (output_bfd,
4145 sec->output_section);
4147 check_segment[1] = -1;
4149 switch ((int) r_type)
4151 final_link_relocate:
4152 /* COFF relocs don't use the addend. The addend is used for
4153 R_SH_DIR32 to be compatible with other compilers. */
4154 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
4155 contents, rel->r_offset,
4156 relocation, addend);
4160 goto final_link_relocate;
4165 /* If the reloc is against the start of this section, then
4166 the assembler has already taken care of it and the reloc
4167 is here only to assist in relaxing. If the reloc is not
4168 against the start of this section, then it's against an
4169 external symbol and we must deal with it ourselves. */
4170 if (input_section->output_section->vma + input_section->output_offset
4173 int disp = (relocation
4174 - input_section->output_section->vma
4175 - input_section->output_offset
4181 case R_SH_DIR8WPZ: mask = 1; break;
4182 case R_SH_DIR8WPL: mask = 3; break;
4183 default: mask = 0; break;
4187 ((*_bfd_error_handler)
4188 (_("%B: 0x%lx: fatal: unaligned branch target for relax-support relocation"),
4189 input_section->owner,
4190 (unsigned long) rel->r_offset));
4191 bfd_set_error (bfd_error_bad_value);
4195 goto final_link_relocate;
4201 #ifdef INCLUDE_SHMEDIA
4202 if (shmedia_prepare_reloc (info, input_bfd, input_section,
4203 contents, rel, &relocation))
4204 goto final_link_relocate;
4206 bfd_set_error (bfd_error_bad_value);
4214 goto final_link_relocate;
4220 ((*_bfd_error_handler)
4221 (_("%B: 0x%lx: fatal: unaligned %s relocation 0x%lx"),
4222 input_section->owner,
4223 (unsigned long) rel->r_offset, howto->name,
4224 (unsigned long) relocation));
4225 bfd_set_error (bfd_error_bad_value);
4228 goto final_link_relocate;
4235 ((*_bfd_error_handler)
4236 (_("%B: 0x%lx: fatal: unaligned %s relocation 0x%lx"),
4237 input_section->owner,
4238 (unsigned long) rel->r_offset, howto->name,
4239 (unsigned long) relocation));
4240 bfd_set_error (bfd_error_bad_value);
4243 goto final_link_relocate;
4246 if ((signed int)relocation < -32
4247 || (signed int)relocation > 32)
4249 ((*_bfd_error_handler)
4250 (_("%B: 0x%lx: fatal: R_SH_PSHA relocation %d not in range -32..32"),
4251 input_section->owner,
4252 (unsigned long) rel->r_offset,
4253 (unsigned long) relocation));
4254 bfd_set_error (bfd_error_bad_value);
4257 goto final_link_relocate;
4260 if ((signed int)relocation < -16
4261 || (signed int)relocation > 16)
4263 ((*_bfd_error_handler)
4264 (_("%B: 0x%lx: fatal: R_SH_PSHL relocation %d not in range -32..32"),
4265 input_section->owner,
4266 (unsigned long) rel->r_offset,
4267 (unsigned long) relocation));
4268 bfd_set_error (bfd_error_bad_value);
4271 goto final_link_relocate;
4275 #ifdef INCLUDE_SHMEDIA
4276 case R_SH_IMM_LOW16_PCREL:
4277 case R_SH_IMM_MEDLOW16_PCREL:
4278 case R_SH_IMM_MEDHI16_PCREL:
4279 case R_SH_IMM_HI16_PCREL:
4283 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4284 || h->root.type != bfd_link_hash_undefweak)
4285 && r_symndx != STN_UNDEF
4286 && (input_section->flags & SEC_ALLOC) != 0
4288 && (r_type == R_SH_DIR32
4289 || !SYMBOL_CALLS_LOCAL (info, h)))
4291 Elf_Internal_Rela outrel;
4293 bfd_boolean skip, relocate;
4295 /* When generating a shared object, these relocations
4296 are copied into the output file to be resolved at run
4301 sreloc = _bfd_elf_get_dynamic_reloc_section
4302 (input_bfd, input_section, /*rela?*/ TRUE);
4311 _bfd_elf_section_offset (output_bfd, info, input_section,
4313 if (outrel.r_offset == (bfd_vma) -1)
4315 else if (outrel.r_offset == (bfd_vma) -2)
4316 skip = TRUE, relocate = TRUE;
4317 outrel.r_offset += (input_section->output_section->vma
4318 + input_section->output_offset);
4321 memset (&outrel, 0, sizeof outrel);
4322 else if (r_type == R_SH_REL32)
4324 BFD_ASSERT (h != NULL && h->dynindx != -1);
4325 outrel.r_info = ELF32_R_INFO (h->dynindx, R_SH_REL32);
4327 = (howto->partial_inplace
4328 ? bfd_get_32 (input_bfd, contents + rel->r_offset)
4331 #ifdef INCLUDE_SHMEDIA
4332 else if (r_type == R_SH_IMM_LOW16_PCREL
4333 || r_type == R_SH_IMM_MEDLOW16_PCREL
4334 || r_type == R_SH_IMM_MEDHI16_PCREL
4335 || r_type == R_SH_IMM_HI16_PCREL)
4337 BFD_ASSERT (h != NULL && h->dynindx != -1);
4338 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
4339 outrel.r_addend = addend;
4344 || ((info->symbolic || h->dynindx == -1)
4345 && h->def_regular)))
4349 BFD_ASSERT (sec != NULL);
4350 BFD_ASSERT (sec->output_section != NULL);
4351 dynindx = elf_section_data (sec->output_section)->dynindx;
4352 outrel.r_info = ELF32_R_INFO (dynindx, R_SH_DIR32);
4353 outrel.r_addend = relocation;
4355 += (howto->partial_inplace
4356 ? bfd_get_32 (input_bfd, contents + rel->r_offset)
4358 outrel.r_addend -= sec->output_section->vma;
4362 /* h->dynindx may be -1 if this symbol was marked to
4365 || ((info->symbolic || h->dynindx == -1)
4368 relocate = howto->partial_inplace;
4369 outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
4373 BFD_ASSERT (h->dynindx != -1);
4374 outrel.r_info = ELF32_R_INFO (h->dynindx, R_SH_DIR32);
4376 outrel.r_addend = relocation;
4378 += (howto->partial_inplace
4379 ? bfd_get_32 (input_bfd, contents + rel->r_offset)
4383 loc = sreloc->contents;
4384 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
4385 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
4387 check_segment[0] = check_segment[1] = -1;
4389 /* If this reloc is against an external symbol, we do
4390 not want to fiddle with the addend. Otherwise, we
4391 need to include the symbol value so that it becomes
4392 an addend for the dynamic reloc. */
4396 else if (fdpic_p && !info->shared
4397 && r_type == R_SH_DIR32
4398 && (input_section->flags & SEC_ALLOC) != 0)
4404 if (sh_elf_osec_readonly_p (output_bfd,
4405 input_section->output_section))
4407 (*_bfd_error_handler)
4408 (_("%B(%A+0x%lx): cannot emit fixup to `%s' in read-only section"),
4411 (long) rel->r_offset,
4416 offset = _bfd_elf_section_offset (output_bfd, info,
4417 input_section, rel->r_offset);
4418 if (offset != (bfd_vma)-1)
4419 sh_elf_add_rofixup (output_bfd, htab->srofixup,
4420 input_section->output_section->vma
4421 + input_section->output_offset
4424 check_segment[0] = check_segment[1] = -1;
4426 /* We don't want warnings for non-NULL tests on undefined weak
4428 else if (r_type == R_SH_REL32
4430 && h->root.type == bfd_link_hash_undefweak)
4431 check_segment[0] = check_segment[1] = -1;
4432 goto final_link_relocate;
4435 #ifdef INCLUDE_SHMEDIA
4436 case R_SH_GOTPLT_LOW16:
4437 case R_SH_GOTPLT_MEDLOW16:
4438 case R_SH_GOTPLT_MEDHI16:
4439 case R_SH_GOTPLT_HI16:
4440 case R_SH_GOTPLT10BY4:
4441 case R_SH_GOTPLT10BY8:
4443 /* Relocation is to the entry for this symbol in the
4444 procedure linkage table. */
4451 || h->plt.offset == (bfd_vma) -1
4452 || h->got.offset != (bfd_vma) -1)
4455 /* Relocation is to the entry for this symbol in the global
4456 offset table extension for the procedure linkage table. */
4459 BFD_ASSERT (sgotplt != NULL);
4460 relocation = (sgotplt->output_offset
4461 + (get_plt_index (htab->plt_info, h->plt.offset)
4465 relocation -= GOT_BIAS;
4468 goto final_link_relocate;
4473 #ifdef INCLUDE_SHMEDIA
4474 case R_SH_GOT_LOW16:
4475 case R_SH_GOT_MEDLOW16:
4476 case R_SH_GOT_MEDHI16:
4481 /* Relocation is to the entry for this symbol in the global
4485 BFD_ASSERT (sgot != NULL);
4486 check_segment[0] = check_segment[1] = -1;
4492 off = h->got.offset;
4493 #ifdef INCLUDE_SHMEDIA
4494 if (seen_stt_datalabel)
4496 struct elf_sh_link_hash_entry *hsh;
4498 hsh = (struct elf_sh_link_hash_entry *)h;
4499 off = hsh->datalabel_got.offset;
4502 BFD_ASSERT (off != (bfd_vma) -1);
4504 dyn = htab->root.dynamic_sections_created;
4505 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
4507 && SYMBOL_REFERENCES_LOCAL (info, h))
4508 || (ELF_ST_VISIBILITY (h->other)
4509 && h->root.type == bfd_link_hash_undefweak))
4511 /* This is actually a static link, or it is a
4512 -Bsymbolic link and the symbol is defined
4513 locally, or the symbol was forced to be local
4514 because of a version file. We must initialize
4515 this entry in the global offset table. Since the
4516 offset must always be a multiple of 4, we use the
4517 least significant bit to record whether we have
4518 initialized it already.
4520 When doing a dynamic link, we create a .rela.got
4521 relocation entry to initialize the value. This
4522 is done in the finish_dynamic_symbol routine. */
4527 bfd_put_32 (output_bfd, relocation,
4528 sgot->contents + off);
4529 #ifdef INCLUDE_SHMEDIA
4530 if (seen_stt_datalabel)
4532 struct elf_sh_link_hash_entry *hsh;
4534 hsh = (struct elf_sh_link_hash_entry *)h;
4535 hsh->datalabel_got.offset |= 1;
4541 /* If we initialize the GOT entry here with a valid
4542 symbol address, also add a fixup. */
4543 if (fdpic_p && !info->shared
4544 && sh_elf_hash_entry (h)->got_type == GOT_NORMAL
4545 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4546 || h->root.type != bfd_link_hash_undefweak))
4547 sh_elf_add_rofixup (output_bfd, htab->srofixup,
4548 sgot->output_section->vma
4549 + sgot->output_offset
4554 relocation = sh_elf_got_offset (htab) + off;
4558 #ifdef INCLUDE_SHMEDIA
4561 BFD_ASSERT (local_got_offsets != NULL
4562 && (local_got_offsets[symtab_hdr->sh_info
4566 off = local_got_offsets[symtab_hdr->sh_info
4572 BFD_ASSERT (local_got_offsets != NULL
4573 && local_got_offsets[r_symndx] != (bfd_vma) -1);
4575 off = local_got_offsets[r_symndx];
4576 #ifdef INCLUDE_SHMEDIA
4580 /* The offset must always be a multiple of 4. We use
4581 the least significant bit to record whether we have
4582 already generated the necessary reloc. */
4587 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
4591 Elf_Internal_Rela outrel;
4594 if (srelgot == NULL)
4596 srelgot = bfd_get_linker_section (dynobj,
4598 BFD_ASSERT (srelgot != NULL);
4601 outrel.r_offset = (sgot->output_section->vma
4602 + sgot->output_offset
4607 = elf_section_data (sec->output_section)->dynindx;
4608 outrel.r_info = ELF32_R_INFO (dynindx, R_SH_DIR32);
4609 outrel.r_addend = relocation;
4610 outrel.r_addend -= sec->output_section->vma;
4614 outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
4615 outrel.r_addend = relocation;
4617 loc = srelgot->contents;
4618 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
4619 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
4622 && (sh_elf_local_got_type (input_bfd) [r_symndx]
4624 sh_elf_add_rofixup (output_bfd, htab->srofixup,
4625 sgot->output_section->vma
4626 + sgot->output_offset
4629 #ifdef INCLUDE_SHMEDIA
4631 local_got_offsets[symtab_hdr->sh_info + r_symndx] |= 1;
4634 local_got_offsets[r_symndx] |= 1;
4637 relocation = sh_elf_got_offset (htab) + off;
4641 relocation -= GOT_BIAS;
4644 if (r_type == R_SH_GOT20)
4646 r = install_movi20_field (output_bfd, relocation + addend,
4647 input_bfd, input_section, contents,
4652 goto final_link_relocate;
4656 #ifdef INCLUDE_SHMEDIA
4657 case R_SH_GOTOFF_LOW16:
4658 case R_SH_GOTOFF_MEDLOW16:
4659 case R_SH_GOTOFF_MEDHI16:
4660 case R_SH_GOTOFF_HI16:
4662 /* GOTOFF relocations are relative to _GLOBAL_OFFSET_TABLE_, which
4663 we place at the start of the .got.plt section. This is the same
4664 as the start of the output .got section, unless there are function
4665 descriptors in front of it. */
4667 BFD_ASSERT (sgotplt != NULL);
4668 check_segment[0] = got_segment;
4669 relocation -= sgotplt->output_section->vma + sgotplt->output_offset
4670 + htab->root.hgot->root.u.def.value;
4673 relocation -= GOT_BIAS;
4676 addend = rel->r_addend;
4678 if (r_type == R_SH_GOTOFF20)
4680 r = install_movi20_field (output_bfd, relocation + addend,
4681 input_bfd, input_section, contents,
4686 goto final_link_relocate;
4689 #ifdef INCLUDE_SHMEDIA
4690 case R_SH_GOTPC_LOW16:
4691 case R_SH_GOTPC_MEDLOW16:
4692 case R_SH_GOTPC_MEDHI16:
4693 case R_SH_GOTPC_HI16:
4695 /* Use global offset table as symbol value. */
4697 BFD_ASSERT (sgotplt != NULL);
4698 relocation = sgotplt->output_section->vma + sgotplt->output_offset;
4701 relocation += GOT_BIAS;
4704 addend = rel->r_addend;
4706 goto final_link_relocate;
4709 #ifdef INCLUDE_SHMEDIA
4710 case R_SH_PLT_LOW16:
4711 case R_SH_PLT_MEDLOW16:
4712 case R_SH_PLT_MEDHI16:
4715 /* Relocation is to the entry for this symbol in the
4716 procedure linkage table. */
4718 /* Resolve a PLT reloc against a local symbol directly,
4719 without using the procedure linkage table. */
4721 goto final_link_relocate;
4723 /* We don't want to warn on calls to undefined weak symbols,
4724 as calls to them must be protected by non-NULL tests
4725 anyway, and unprotected calls would invoke undefined
4727 if (h->root.type == bfd_link_hash_undefweak)
4728 check_segment[0] = check_segment[1] = -1;
4730 if (h->forced_local)
4731 goto final_link_relocate;
4733 if (h->plt.offset == (bfd_vma) -1)
4735 /* We didn't make a PLT entry for this symbol. This
4736 happens when statically linking PIC code, or when
4737 using -Bsymbolic. */
4738 goto final_link_relocate;
4741 BFD_ASSERT (splt != NULL);
4742 check_segment[1] = plt_segment;
4743 relocation = (splt->output_section->vma
4744 + splt->output_offset
4747 #ifdef INCLUDE_SHMEDIA
4751 addend = rel->r_addend;
4753 goto final_link_relocate;
4755 /* Relocation is to the canonical function descriptor for this
4756 symbol, possibly via the GOT. Initialize the GOT
4757 entry and function descriptor if necessary. */
4758 case R_SH_GOTFUNCDESC:
4759 case R_SH_GOTFUNCDESC20:
4763 asection *reloc_section;
4764 bfd_vma reloc_offset;
4765 int reloc_type = R_SH_FUNCDESC;
4769 check_segment[0] = check_segment[1] = -1;
4771 /* FIXME: See what FRV does for global symbols in the
4772 executable, with --export-dynamic. Do they need ld.so
4773 to allocate official descriptors? See what this code
4779 if (r_type == R_SH_FUNCDESC)
4781 reloc_section = input_section;
4782 reloc_offset = rel->r_offset;
4786 reloc_section = sgot;
4789 reloc_offset = h->got.offset;
4792 BFD_ASSERT (local_got_offsets != NULL);
4793 reloc_offset = local_got_offsets[r_symndx];
4795 BFD_ASSERT (reloc_offset != MINUS_ONE);
4797 if (reloc_offset & 1)
4800 goto funcdesc_done_got;
4804 if (h && h->root.type == bfd_link_hash_undefweak
4805 && (SYMBOL_CALLS_LOCAL (info, h)
4806 || !htab->root.dynamic_sections_created))
4807 /* Undefined weak symbol which will not be dynamically
4808 resolved later; leave it at zero. */
4809 goto funcdesc_leave_zero;
4810 else if (SYMBOL_CALLS_LOCAL (info, h)
4811 && ! SYMBOL_FUNCDESC_LOCAL (info, h))
4813 /* If the symbol needs a non-local function descriptor
4814 but binds locally (i.e., its visibility is
4815 protected), emit a dynamic relocation decayed to
4816 section+offset. This is an optimization; the dynamic
4817 linker would resolve our function descriptor request
4818 to our copy of the function anyway. */
4819 dynindx = elf_section_data (h->root.u.def.section
4820 ->output_section)->dynindx;
4821 relocation += h->root.u.def.section->output_offset
4822 + h->root.u.def.value;
4824 else if (! SYMBOL_FUNCDESC_LOCAL (info, h))
4826 /* If the symbol is dynamic and there will be dynamic
4827 symbol resolution because we are or are linked with a
4828 shared library, emit a FUNCDESC relocation such that
4829 the dynamic linker will allocate the function
4831 BFD_ASSERT (h->dynindx != -1);
4832 dynindx = h->dynindx;
4838 /* Otherwise, we know we have a private function
4839 descriptor, so reference it directly. */
4840 reloc_type = R_SH_DIR32;
4841 dynindx = elf_section_data (htab->sfuncdesc
4842 ->output_section)->dynindx;
4846 offset = sh_elf_hash_entry (h)->funcdesc.offset;
4847 BFD_ASSERT (offset != MINUS_ONE);
4848 if ((offset & 1) == 0)
4850 if (!sh_elf_initialize_funcdesc (output_bfd, info, h,
4853 sh_elf_hash_entry (h)->funcdesc.offset |= 1;
4858 union gotref *local_funcdesc;
4860 local_funcdesc = sh_elf_local_funcdesc (input_bfd);
4861 offset = local_funcdesc[r_symndx].offset;
4862 BFD_ASSERT (offset != MINUS_ONE);
4863 if ((offset & 1) == 0)
4865 if (!sh_elf_initialize_funcdesc (output_bfd, info, NULL,
4869 local_funcdesc[r_symndx].offset |= 1;
4873 relocation = htab->sfuncdesc->output_offset + (offset & ~1);
4876 if (!info->shared && SYMBOL_FUNCDESC_LOCAL (info, h))
4880 if (sh_elf_osec_readonly_p (output_bfd,
4881 reloc_section->output_section))
4883 (*_bfd_error_handler)
4884 (_("%B(%A+0x%lx): cannot emit fixup to `%s' in read-only section"),
4887 (long) rel->r_offset,
4892 offset = _bfd_elf_section_offset (output_bfd, info,
4893 reloc_section, reloc_offset);
4895 if (offset != (bfd_vma)-1)
4896 sh_elf_add_rofixup (output_bfd, htab->srofixup,
4898 + reloc_section->output_section->vma
4899 + reloc_section->output_offset);
4901 else if ((reloc_section->output_section->flags
4902 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
4906 if (sh_elf_osec_readonly_p (output_bfd,
4907 reloc_section->output_section))
4909 info->callbacks->warning
4911 _("cannot emit dynamic relocations in read-only section"),
4912 symname, input_bfd, reloc_section, reloc_offset);
4916 if (srelgot == NULL)
4918 srelgot = bfd_get_linker_section (dynobj, ".rela.got");
4919 BFD_ASSERT (srelgot != NULL);
4922 offset = _bfd_elf_section_offset (output_bfd, info,
4923 reloc_section, reloc_offset);
4925 if (offset != (bfd_vma)-1)
4926 sh_elf_add_dyn_reloc (output_bfd, srelgot,
4928 + reloc_section->output_section->vma
4929 + reloc_section->output_offset,
4930 reloc_type, dynindx, relocation);
4932 if (r_type == R_SH_FUNCDESC)
4940 goto funcdesc_leave_zero;
4944 if (SYMBOL_FUNCDESC_LOCAL (info, h))
4945 relocation += htab->sfuncdesc->output_section->vma;
4946 funcdesc_leave_zero:
4947 if (r_type != R_SH_FUNCDESC)
4949 bfd_put_32 (output_bfd, relocation,
4950 reloc_section->contents + reloc_offset);
4954 local_got_offsets[r_symndx] |= 1;
4958 relocation = sh_elf_got_offset (htab) + reloc_offset;
4960 relocation -= GOT_BIAS;
4963 if (r_type == R_SH_GOTFUNCDESC20)
4965 r = install_movi20_field (output_bfd, relocation + addend,
4966 input_bfd, input_section, contents,
4971 goto final_link_relocate;
4975 case R_SH_GOTOFFFUNCDESC:
4976 case R_SH_GOTOFFFUNCDESC20:
4977 /* FIXME: See R_SH_FUNCDESC comment about global symbols in the
4978 executable and --export-dynamic. If such symbols get
4979 ld.so-allocated descriptors we can not use R_SH_GOTOFFFUNCDESC
4983 check_segment[0] = check_segment[1] = -1;
4985 addend = rel->r_addend;
4987 if (h && (h->root.type == bfd_link_hash_undefweak
4988 || !SYMBOL_FUNCDESC_LOCAL (info, h)))
4991 (_("%B(%A+0x%lx): %s relocation against external symbol \"%s\""),
4992 input_bfd, input_section, (long) rel->r_offset, howto->name,
4993 h->root.root.string);
5000 /* Otherwise, we know we have a private function
5001 descriptor, so reference it directly. */
5004 offset = sh_elf_hash_entry (h)->funcdesc.offset;
5005 BFD_ASSERT (offset != MINUS_ONE);
5006 if ((offset & 1) == 0)
5008 if (!sh_elf_initialize_funcdesc (output_bfd, info, h,
5011 sh_elf_hash_entry (h)->funcdesc.offset |= 1;
5016 union gotref *local_funcdesc;
5018 local_funcdesc = sh_elf_local_funcdesc (input_bfd);
5019 offset = local_funcdesc[r_symndx].offset;
5020 BFD_ASSERT (offset != MINUS_ONE);
5021 if ((offset & 1) == 0)
5023 if (!sh_elf_initialize_funcdesc (output_bfd, info, NULL,
5027 local_funcdesc[r_symndx].offset |= 1;
5031 relocation = htab->sfuncdesc->output_offset + (offset & ~1);
5034 relocation -= (htab->root.hgot->root.u.def.value
5035 + sgotplt->output_offset);
5037 relocation -= GOT_BIAS;
5040 if (r_type == R_SH_GOTOFFFUNCDESC20)
5042 r = install_movi20_field (output_bfd, relocation + addend,
5043 input_bfd, input_section, contents,
5048 goto final_link_relocate;
5050 case R_SH_LOOP_START:
5052 static bfd_vma start, end;
5054 start = (relocation + rel->r_addend
5055 - (sec->output_section->vma + sec->output_offset));
5056 r = sh_elf_reloc_loop (r_type, input_bfd, input_section, contents,
5057 rel->r_offset, sec, start, end);
5061 end = (relocation + rel->r_addend
5062 - (sec->output_section->vma + sec->output_offset));
5063 r = sh_elf_reloc_loop (r_type, input_bfd, input_section, contents,
5064 rel->r_offset, sec, start, end);
5068 case R_SH_TLS_GD_32:
5069 case R_SH_TLS_IE_32:
5071 check_segment[0] = check_segment[1] = -1;
5072 r_type = sh_elf_optimized_tls_reloc (info, r_type, h == NULL);
5073 got_type = GOT_UNKNOWN;
5074 if (h == NULL && local_got_offsets)
5075 got_type = sh_elf_local_got_type (input_bfd) [r_symndx];
5078 got_type = sh_elf_hash_entry (h)->got_type;
5080 && (h->dynindx == -1
5082 r_type = R_SH_TLS_LE_32;
5085 if (r_type == R_SH_TLS_GD_32 && got_type == GOT_TLS_IE)
5086 r_type = R_SH_TLS_IE_32;
5088 if (r_type == R_SH_TLS_LE_32)
5091 unsigned short insn;
5093 if (ELF32_R_TYPE (rel->r_info) == R_SH_TLS_GD_32)
5095 /* GD->LE transition:
5096 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5097 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5098 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5100 mov.l 1f,r4; stc gbr,r0; add r4,r0; nop;
5102 1: .long x@TPOFF; 2: .long __tls_get_addr@PLT; 3:. */
5104 offset = rel->r_offset;
5105 BFD_ASSERT (offset >= 16);
5106 /* Size of GD instructions is 16 or 18. */
5108 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5109 if ((insn & 0xff00) == 0xc700)
5111 BFD_ASSERT (offset >= 2);
5113 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5116 BFD_ASSERT ((insn & 0xff00) == 0xd400);
5117 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5118 BFD_ASSERT ((insn & 0xff00) == 0xc700);
5119 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5120 BFD_ASSERT ((insn & 0xff00) == 0xd100);
5121 insn = bfd_get_16 (input_bfd, contents + offset + 6);
5122 BFD_ASSERT (insn == 0x310c);
5123 insn = bfd_get_16 (input_bfd, contents + offset + 8);
5124 BFD_ASSERT (insn == 0x410b);
5125 insn = bfd_get_16 (input_bfd, contents + offset + 10);
5126 BFD_ASSERT (insn == 0x34cc);
5128 bfd_put_16 (output_bfd, 0x0012, contents + offset + 2);
5129 bfd_put_16 (output_bfd, 0x304c, contents + offset + 4);
5130 bfd_put_16 (output_bfd, 0x0009, contents + offset + 6);
5131 bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
5132 bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
5138 /* IE->LE transition:
5139 mov.l 1f,r0; stc gbr,rN; mov.l @(r0,r12),rM;
5140 bra 2f; add ...; .align 2; 1: x@GOTTPOFF; 2:
5142 mov.l .Ln,rM; stc gbr,rN; nop; ...;
5145 offset = rel->r_offset;
5146 BFD_ASSERT (offset >= 16);
5147 /* Size of IE instructions is 10 or 12. */
5149 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5150 if ((insn & 0xf0ff) == 0x0012)
5152 BFD_ASSERT (offset >= 2);
5154 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5157 BFD_ASSERT ((insn & 0xff00) == 0xd000);
5158 target = insn & 0x00ff;
5159 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5160 BFD_ASSERT ((insn & 0xf0ff) == 0x0012);
5161 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5162 BFD_ASSERT ((insn & 0xf0ff) == 0x00ce);
5163 insn = 0xd000 | (insn & 0x0f00) | target;
5164 bfd_put_16 (output_bfd, insn, contents + offset + 0);
5165 bfd_put_16 (output_bfd, 0x0009, contents + offset + 4);
5168 bfd_put_32 (output_bfd, tpoff (info, relocation),
5169 contents + rel->r_offset);
5173 if (sgot == NULL || sgotplt == NULL)
5177 off = h->got.offset;
5180 if (local_got_offsets == NULL)
5183 off = local_got_offsets[r_symndx];
5186 /* Relocate R_SH_TLS_IE_32 directly when statically linking. */
5187 if (r_type == R_SH_TLS_IE_32
5188 && ! htab->root.dynamic_sections_created)
5191 bfd_put_32 (output_bfd, tpoff (info, relocation),
5192 sgot->contents + off);
5193 bfd_put_32 (output_bfd, sh_elf_got_offset (htab) + off,
5194 contents + rel->r_offset);
5202 Elf_Internal_Rela outrel;
5206 if (srelgot == NULL)
5208 srelgot = bfd_get_linker_section (dynobj, ".rela.got");
5209 BFD_ASSERT (srelgot != NULL);
5212 outrel.r_offset = (sgot->output_section->vma
5213 + sgot->output_offset + off);
5215 if (h == NULL || h->dynindx == -1)
5220 dr_type = (r_type == R_SH_TLS_GD_32 ? R_SH_TLS_DTPMOD32 :
5222 if (dr_type == R_SH_TLS_TPOFF32 && indx == 0)
5223 outrel.r_addend = relocation - dtpoff_base (info);
5225 outrel.r_addend = 0;
5226 outrel.r_info = ELF32_R_INFO (indx, dr_type);
5227 loc = srelgot->contents;
5228 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
5229 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5231 if (r_type == R_SH_TLS_GD_32)
5235 bfd_put_32 (output_bfd,
5236 relocation - dtpoff_base (info),
5237 sgot->contents + off + 4);
5241 outrel.r_info = ELF32_R_INFO (indx,
5243 outrel.r_offset += 4;
5244 outrel.r_addend = 0;
5245 srelgot->reloc_count++;
5246 loc += sizeof (Elf32_External_Rela);
5247 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5254 local_got_offsets[r_symndx] |= 1;
5257 if (off >= (bfd_vma) -2)
5260 if (r_type == (int) ELF32_R_TYPE (rel->r_info))
5261 relocation = sh_elf_got_offset (htab) + off;
5265 unsigned short insn;
5267 /* GD->IE transition:
5268 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5269 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5270 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5272 mov.l 1f,r0; stc gbr,r4; mov.l @(r0,r12),r0; add r4,r0;
5273 nop; nop; bra 3f; nop; .align 2;
5274 1: .long x@TPOFF; 2:...; 3:. */
5276 offset = rel->r_offset;
5277 BFD_ASSERT (offset >= 16);
5278 /* Size of GD instructions is 16 or 18. */
5280 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5281 if ((insn & 0xff00) == 0xc700)
5283 BFD_ASSERT (offset >= 2);
5285 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5288 BFD_ASSERT ((insn & 0xff00) == 0xd400);
5290 /* Replace mov.l 1f,R4 with mov.l 1f,r0. */
5291 bfd_put_16 (output_bfd, insn & 0xf0ff, contents + offset);
5293 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5294 BFD_ASSERT ((insn & 0xff00) == 0xc700);
5295 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5296 BFD_ASSERT ((insn & 0xff00) == 0xd100);
5297 insn = bfd_get_16 (input_bfd, contents + offset + 6);
5298 BFD_ASSERT (insn == 0x310c);
5299 insn = bfd_get_16 (input_bfd, contents + offset + 8);
5300 BFD_ASSERT (insn == 0x410b);
5301 insn = bfd_get_16 (input_bfd, contents + offset + 10);
5302 BFD_ASSERT (insn == 0x34cc);
5304 bfd_put_16 (output_bfd, 0x0412, contents + offset + 2);
5305 bfd_put_16 (output_bfd, 0x00ce, contents + offset + 4);
5306 bfd_put_16 (output_bfd, 0x304c, contents + offset + 6);
5307 bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
5308 bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
5310 bfd_put_32 (output_bfd, sh_elf_got_offset (htab) + off,
5311 contents + rel->r_offset);
5316 addend = rel->r_addend;
5318 goto final_link_relocate;
5320 case R_SH_TLS_LD_32:
5322 check_segment[0] = check_segment[1] = -1;
5326 unsigned short insn;
5328 /* LD->LE transition:
5329 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5330 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5331 1: .long x$TLSLD; 2: .long __tls_get_addr@PLT; 3:
5333 stc gbr,r0; nop; nop; nop;
5334 nop; nop; bra 3f; ...; 3:. */
5336 offset = rel->r_offset;
5337 BFD_ASSERT (offset >= 16);
5338 /* Size of LD instructions is 16 or 18. */
5340 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5341 if ((insn & 0xff00) == 0xc700)
5343 BFD_ASSERT (offset >= 2);
5345 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5348 BFD_ASSERT ((insn & 0xff00) == 0xd400);
5349 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5350 BFD_ASSERT ((insn & 0xff00) == 0xc700);
5351 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5352 BFD_ASSERT ((insn & 0xff00) == 0xd100);
5353 insn = bfd_get_16 (input_bfd, contents + offset + 6);
5354 BFD_ASSERT (insn == 0x310c);
5355 insn = bfd_get_16 (input_bfd, contents + offset + 8);
5356 BFD_ASSERT (insn == 0x410b);
5357 insn = bfd_get_16 (input_bfd, contents + offset + 10);
5358 BFD_ASSERT (insn == 0x34cc);
5360 bfd_put_16 (output_bfd, 0x0012, contents + offset + 0);
5361 bfd_put_16 (output_bfd, 0x0009, contents + offset + 2);
5362 bfd_put_16 (output_bfd, 0x0009, contents + offset + 4);
5363 bfd_put_16 (output_bfd, 0x0009, contents + offset + 6);
5364 bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
5365 bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
5370 if (sgot == NULL || sgotplt == NULL)
5373 off = htab->tls_ldm_got.offset;
5378 Elf_Internal_Rela outrel;
5381 srelgot = htab->srelgot;
5382 if (srelgot == NULL)
5385 outrel.r_offset = (sgot->output_section->vma
5386 + sgot->output_offset + off);
5387 outrel.r_addend = 0;
5388 outrel.r_info = ELF32_R_INFO (0, R_SH_TLS_DTPMOD32);
5389 loc = srelgot->contents;
5390 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
5391 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5392 htab->tls_ldm_got.offset |= 1;
5395 relocation = sh_elf_got_offset (htab) + off;
5396 addend = rel->r_addend;
5398 goto final_link_relocate;
5400 case R_SH_TLS_LDO_32:
5401 check_segment[0] = check_segment[1] = -1;
5403 relocation = tpoff (info, relocation);
5405 relocation -= dtpoff_base (info);
5407 addend = rel->r_addend;
5408 goto final_link_relocate;
5410 case R_SH_TLS_LE_32:
5413 Elf_Internal_Rela outrel;
5416 check_segment[0] = check_segment[1] = -1;
5418 if (! info->shared || info->pie)
5420 relocation = tpoff (info, relocation);
5421 addend = rel->r_addend;
5422 goto final_link_relocate;
5427 sreloc = _bfd_elf_get_dynamic_reloc_section
5428 (input_bfd, input_section, /*rela?*/ TRUE);
5433 if (h == NULL || h->dynindx == -1)
5438 outrel.r_offset = (input_section->output_section->vma
5439 + input_section->output_offset
5441 outrel.r_info = ELF32_R_INFO (indx, R_SH_TLS_TPOFF32);
5443 outrel.r_addend = relocation - dtpoff_base (info);
5445 outrel.r_addend = 0;
5447 loc = sreloc->contents;
5448 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
5449 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5455 if (fdpic_p && check_segment[0] != (unsigned) -1
5456 && check_segment[0] != check_segment[1])
5458 /* We don't want duplicate errors for undefined symbols. */
5459 if (!h || h->root.type != bfd_link_hash_undefined)
5463 info->callbacks->einfo
5464 (_("%X%C: relocation to \"%s\" references a different segment\n"),
5465 input_bfd, input_section, rel->r_offset, symname);
5469 info->callbacks->einfo
5470 (_("%C: warning: relocation to \"%s\" references a different segment\n"),
5471 input_bfd, input_section, rel->r_offset, symname);
5474 elf_elfheader (output_bfd)->e_flags &= ~EF_SH_PIC;
5477 if (r != bfd_reloc_ok)
5482 case bfd_reloc_outofrange:
5484 case bfd_reloc_overflow:
5492 name = (bfd_elf_string_from_elf_section
5493 (input_bfd, symtab_hdr->sh_link, sym->st_name));
5497 name = bfd_section_name (input_bfd, sec);
5499 if (! ((*info->callbacks->reloc_overflow)
5500 (info, (h ? &h->root : NULL), name, howto->name,
5501 (bfd_vma) 0, input_bfd, input_section,
5513 /* This is a version of bfd_generic_get_relocated_section_contents
5514 which uses sh_elf_relocate_section. */
5517 sh_elf_get_relocated_section_contents (bfd *output_bfd,
5518 struct bfd_link_info *link_info,
5519 struct bfd_link_order *link_order,
5521 bfd_boolean relocatable,
5524 Elf_Internal_Shdr *symtab_hdr;
5525 asection *input_section = link_order->u.indirect.section;
5526 bfd *input_bfd = input_section->owner;
5527 asection **sections = NULL;
5528 Elf_Internal_Rela *internal_relocs = NULL;
5529 Elf_Internal_Sym *isymbuf = NULL;
5531 /* We only need to handle the case of relaxing, or of having a
5532 particular set of section contents, specially. */
5534 || elf_section_data (input_section)->this_hdr.contents == NULL)
5535 return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
5540 symtab_hdr = &elf_symtab_hdr (input_bfd);
5542 memcpy (data, elf_section_data (input_section)->this_hdr.contents,
5543 (size_t) input_section->size);
5545 if ((input_section->flags & SEC_RELOC) != 0
5546 && input_section->reloc_count > 0)
5549 Elf_Internal_Sym *isym, *isymend;
5552 internal_relocs = (_bfd_elf_link_read_relocs
5553 (input_bfd, input_section, NULL,
5554 (Elf_Internal_Rela *) NULL, FALSE));
5555 if (internal_relocs == NULL)
5558 if (symtab_hdr->sh_info != 0)
5560 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
5561 if (isymbuf == NULL)
5562 isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
5563 symtab_hdr->sh_info, 0,
5565 if (isymbuf == NULL)
5569 amt = symtab_hdr->sh_info;
5570 amt *= sizeof (asection *);
5571 sections = (asection **) bfd_malloc (amt);
5572 if (sections == NULL && amt != 0)
5575 isymend = isymbuf + symtab_hdr->sh_info;
5576 for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp)
5580 if (isym->st_shndx == SHN_UNDEF)
5581 isec = bfd_und_section_ptr;
5582 else if (isym->st_shndx == SHN_ABS)
5583 isec = bfd_abs_section_ptr;
5584 else if (isym->st_shndx == SHN_COMMON)
5585 isec = bfd_com_section_ptr;
5587 isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
5592 if (! sh_elf_relocate_section (output_bfd, link_info, input_bfd,
5593 input_section, data, internal_relocs,
5597 if (sections != NULL)
5600 && symtab_hdr->contents != (unsigned char *) isymbuf)
5602 if (elf_section_data (input_section)->relocs != internal_relocs)
5603 free (internal_relocs);
5609 if (sections != NULL)
5612 && symtab_hdr->contents != (unsigned char *) isymbuf)
5614 if (internal_relocs != NULL
5615 && elf_section_data (input_section)->relocs != internal_relocs)
5616 free (internal_relocs);
5620 /* Return the base VMA address which should be subtracted from real addresses
5621 when resolving @dtpoff relocation.
5622 This is PT_TLS segment p_vaddr. */
5625 dtpoff_base (struct bfd_link_info *info)
5627 /* If tls_sec is NULL, we should have signalled an error already. */
5628 if (elf_hash_table (info)->tls_sec == NULL)
5630 return elf_hash_table (info)->tls_sec->vma;
5633 /* Return the relocation value for R_SH_TLS_TPOFF32.. */
5636 tpoff (struct bfd_link_info *info, bfd_vma address)
5638 /* If tls_sec is NULL, we should have signalled an error already. */
5639 if (elf_hash_table (info)->tls_sec == NULL)
5641 /* SH TLS ABI is variant I and static TLS block start just after tcbhead
5642 structure which has 2 pointer fields. */
5643 return (address - elf_hash_table (info)->tls_sec->vma
5644 + align_power ((bfd_vma) 8,
5645 elf_hash_table (info)->tls_sec->alignment_power));
5649 sh_elf_gc_mark_hook (asection *sec,
5650 struct bfd_link_info *info,
5651 Elf_Internal_Rela *rel,
5652 struct elf_link_hash_entry *h,
5653 Elf_Internal_Sym *sym)
5656 switch (ELF32_R_TYPE (rel->r_info))
5658 case R_SH_GNU_VTINHERIT:
5659 case R_SH_GNU_VTENTRY:
5663 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
5666 /* Update the got entry reference counts for the section being removed. */
5669 sh_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
5670 asection *sec, const Elf_Internal_Rela *relocs)
5672 Elf_Internal_Shdr *symtab_hdr;
5673 struct elf_link_hash_entry **sym_hashes;
5674 bfd_signed_vma *local_got_refcounts;
5675 union gotref *local_funcdesc;
5676 const Elf_Internal_Rela *rel, *relend;
5678 if (info->relocatable)
5681 elf_section_data (sec)->local_dynrel = NULL;
5683 symtab_hdr = &elf_symtab_hdr (abfd);
5684 sym_hashes = elf_sym_hashes (abfd);
5685 local_got_refcounts = elf_local_got_refcounts (abfd);
5686 local_funcdesc = sh_elf_local_funcdesc (abfd);
5688 relend = relocs + sec->reloc_count;
5689 for (rel = relocs; rel < relend; rel++)
5691 unsigned long r_symndx;
5692 unsigned int r_type;
5693 struct elf_link_hash_entry *h = NULL;
5694 #ifdef INCLUDE_SHMEDIA
5695 int seen_stt_datalabel = 0;
5698 r_symndx = ELF32_R_SYM (rel->r_info);
5699 if (r_symndx >= symtab_hdr->sh_info)
5701 struct elf_sh_link_hash_entry *eh;
5702 struct elf_sh_dyn_relocs **pp;
5703 struct elf_sh_dyn_relocs *p;
5705 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5706 while (h->root.type == bfd_link_hash_indirect
5707 || h->root.type == bfd_link_hash_warning)
5709 #ifdef INCLUDE_SHMEDIA
5710 seen_stt_datalabel |= h->type == STT_DATALABEL;
5712 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5714 eh = (struct elf_sh_link_hash_entry *) h;
5715 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
5718 /* Everything must go for SEC. */
5724 r_type = ELF32_R_TYPE (rel->r_info);
5725 switch (sh_elf_optimized_tls_reloc (info, r_type, h != NULL))
5727 case R_SH_TLS_LD_32:
5728 if (sh_elf_hash_table (info)->tls_ldm_got.refcount > 0)
5729 sh_elf_hash_table (info)->tls_ldm_got.refcount -= 1;
5737 #ifdef INCLUDE_SHMEDIA
5738 case R_SH_GOT_LOW16:
5739 case R_SH_GOT_MEDLOW16:
5740 case R_SH_GOT_MEDHI16:
5744 case R_SH_GOTOFF_LOW16:
5745 case R_SH_GOTOFF_MEDLOW16:
5746 case R_SH_GOTOFF_MEDHI16:
5747 case R_SH_GOTOFF_HI16:
5748 case R_SH_GOTPC_LOW16:
5749 case R_SH_GOTPC_MEDLOW16:
5750 case R_SH_GOTPC_MEDHI16:
5751 case R_SH_GOTPC_HI16:
5753 case R_SH_TLS_GD_32:
5754 case R_SH_TLS_IE_32:
5755 case R_SH_GOTFUNCDESC:
5756 case R_SH_GOTFUNCDESC20:
5759 #ifdef INCLUDE_SHMEDIA
5760 if (seen_stt_datalabel)
5762 struct elf_sh_link_hash_entry *eh;
5763 eh = (struct elf_sh_link_hash_entry *) h;
5764 if (eh->datalabel_got.refcount > 0)
5765 eh->datalabel_got.refcount -= 1;
5769 if (h->got.refcount > 0)
5770 h->got.refcount -= 1;
5772 else if (local_got_refcounts != NULL)
5774 #ifdef INCLUDE_SHMEDIA
5775 if (rel->r_addend & 1)
5777 if (local_got_refcounts[symtab_hdr->sh_info + r_symndx] > 0)
5778 local_got_refcounts[symtab_hdr->sh_info + r_symndx] -= 1;
5782 if (local_got_refcounts[r_symndx] > 0)
5783 local_got_refcounts[r_symndx] -= 1;
5789 sh_elf_hash_entry (h)->abs_funcdesc_refcount -= 1;
5790 else if (sh_elf_hash_table (info)->fdpic_p && !info->shared)
5791 sh_elf_hash_table (info)->srofixup->size -= 4;
5795 case R_SH_GOTOFFFUNCDESC:
5796 case R_SH_GOTOFFFUNCDESC20:
5798 sh_elf_hash_entry (h)->funcdesc.refcount -= 1;
5800 local_funcdesc[r_symndx].refcount -= 1;
5804 if (sh_elf_hash_table (info)->fdpic_p && !info->shared
5805 && (sec->flags & SEC_ALLOC) != 0)
5806 sh_elf_hash_table (info)->srofixup->size -= 4;
5815 #ifdef INCLUDE_SHMEDIA
5816 case R_SH_PLT_LOW16:
5817 case R_SH_PLT_MEDLOW16:
5818 case R_SH_PLT_MEDHI16:
5823 if (h->plt.refcount > 0)
5824 h->plt.refcount -= 1;
5829 #ifdef INCLUDE_SHMEDIA
5830 case R_SH_GOTPLT_LOW16:
5831 case R_SH_GOTPLT_MEDLOW16:
5832 case R_SH_GOTPLT_MEDHI16:
5833 case R_SH_GOTPLT_HI16:
5834 case R_SH_GOTPLT10BY4:
5835 case R_SH_GOTPLT10BY8:
5839 struct elf_sh_link_hash_entry *eh;
5840 eh = (struct elf_sh_link_hash_entry *) h;
5841 if (eh->gotplt_refcount > 0)
5843 eh->gotplt_refcount -= 1;
5844 if (h->plt.refcount > 0)
5845 h->plt.refcount -= 1;
5847 #ifdef INCLUDE_SHMEDIA
5848 else if (seen_stt_datalabel)
5850 if (eh->datalabel_got.refcount > 0)
5851 eh->datalabel_got.refcount -= 1;
5854 else if (h->got.refcount > 0)
5855 h->got.refcount -= 1;
5857 else if (local_got_refcounts != NULL)
5859 #ifdef INCLUDE_SHMEDIA
5860 if (rel->r_addend & 1)
5862 if (local_got_refcounts[symtab_hdr->sh_info + r_symndx] > 0)
5863 local_got_refcounts[symtab_hdr->sh_info + r_symndx] -= 1;
5867 if (local_got_refcounts[r_symndx] > 0)
5868 local_got_refcounts[r_symndx] -= 1;
5880 /* Copy the extra info we tack onto an elf_link_hash_entry. */
5883 sh_elf_copy_indirect_symbol (struct bfd_link_info *info,
5884 struct elf_link_hash_entry *dir,
5885 struct elf_link_hash_entry *ind)
5887 struct elf_sh_link_hash_entry *edir, *eind;
5889 edir = (struct elf_sh_link_hash_entry *) dir;
5890 eind = (struct elf_sh_link_hash_entry *) ind;
5892 if (eind->dyn_relocs != NULL)
5894 if (edir->dyn_relocs != NULL)
5896 struct elf_sh_dyn_relocs **pp;
5897 struct elf_sh_dyn_relocs *p;
5899 /* Add reloc counts against the indirect sym to the direct sym
5900 list. Merge any entries against the same section. */
5901 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
5903 struct elf_sh_dyn_relocs *q;
5905 for (q = edir->dyn_relocs; q != NULL; q = q->next)
5906 if (q->sec == p->sec)
5908 q->pc_count += p->pc_count;
5909 q->count += p->count;
5916 *pp = edir->dyn_relocs;
5919 edir->dyn_relocs = eind->dyn_relocs;
5920 eind->dyn_relocs = NULL;
5922 edir->gotplt_refcount = eind->gotplt_refcount;
5923 eind->gotplt_refcount = 0;
5924 #ifdef INCLUDE_SHMEDIA
5925 edir->datalabel_got.refcount += eind->datalabel_got.refcount;
5926 eind->datalabel_got.refcount = 0;
5928 edir->funcdesc.refcount += eind->funcdesc.refcount;
5929 eind->funcdesc.refcount = 0;
5930 edir->abs_funcdesc_refcount += eind->abs_funcdesc_refcount;
5931 eind->abs_funcdesc_refcount = 0;
5933 if (ind->root.type == bfd_link_hash_indirect
5934 && dir->got.refcount <= 0)
5936 edir->got_type = eind->got_type;
5937 eind->got_type = GOT_UNKNOWN;
5940 if (ind->root.type != bfd_link_hash_indirect
5941 && dir->dynamic_adjusted)
5943 /* If called to transfer flags for a weakdef during processing
5944 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
5945 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
5946 dir->ref_dynamic |= ind->ref_dynamic;
5947 dir->ref_regular |= ind->ref_regular;
5948 dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
5949 dir->needs_plt |= ind->needs_plt;
5952 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
5956 sh_elf_optimized_tls_reloc (struct bfd_link_info *info, int r_type,
5964 case R_SH_TLS_GD_32:
5965 case R_SH_TLS_IE_32:
5967 return R_SH_TLS_LE_32;
5968 return R_SH_TLS_IE_32;
5969 case R_SH_TLS_LD_32:
5970 return R_SH_TLS_LE_32;
5976 /* Look through the relocs for a section during the first phase.
5977 Since we don't do .gots or .plts, we just need to consider the
5978 virtual table relocs for gc. */
5981 sh_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
5982 const Elf_Internal_Rela *relocs)
5984 Elf_Internal_Shdr *symtab_hdr;
5985 struct elf_link_hash_entry **sym_hashes;
5986 struct elf_sh_link_hash_table *htab;
5987 const Elf_Internal_Rela *rel;
5988 const Elf_Internal_Rela *rel_end;
5990 unsigned int r_type;
5991 enum got_type got_type, old_got_type;
5995 if (info->relocatable)
5998 BFD_ASSERT (is_sh_elf (abfd));
6000 symtab_hdr = &elf_symtab_hdr (abfd);
6001 sym_hashes = elf_sym_hashes (abfd);
6003 htab = sh_elf_hash_table (info);
6007 rel_end = relocs + sec->reloc_count;
6008 for (rel = relocs; rel < rel_end; rel++)
6010 struct elf_link_hash_entry *h;
6011 unsigned long r_symndx;
6012 #ifdef INCLUDE_SHMEDIA
6013 int seen_stt_datalabel = 0;
6016 r_symndx = ELF32_R_SYM (rel->r_info);
6017 r_type = ELF32_R_TYPE (rel->r_info);
6019 if (r_symndx < symtab_hdr->sh_info)
6023 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6024 while (h->root.type == bfd_link_hash_indirect
6025 || h->root.type == bfd_link_hash_warning)
6027 #ifdef INCLUDE_SHMEDIA
6028 seen_stt_datalabel |= h->type == STT_DATALABEL;
6030 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6033 /* PR15323, ref flags aren't set for references in the same
6035 h->root.non_ir_ref = 1;
6038 r_type = sh_elf_optimized_tls_reloc (info, r_type, h == NULL);
6040 && r_type == R_SH_TLS_IE_32
6042 && h->root.type != bfd_link_hash_undefined
6043 && h->root.type != bfd_link_hash_undefweak
6044 && (h->dynindx == -1
6046 r_type = R_SH_TLS_LE_32;
6051 case R_SH_GOTOFFFUNCDESC:
6052 case R_SH_GOTOFFFUNCDESC20:
6054 case R_SH_GOTFUNCDESC:
6055 case R_SH_GOTFUNCDESC20:
6058 if (h->dynindx == -1)
6059 switch (ELF_ST_VISIBILITY (h->other))
6065 bfd_elf_link_record_dynamic_symbol (info, h);
6072 /* Some relocs require a global offset table. */
6073 if (htab->sgot == NULL)
6078 /* This may require an rofixup. */
6087 case R_SH_GOTFUNCDESC:
6088 case R_SH_GOTFUNCDESC20:
6089 case R_SH_GOTOFFFUNCDESC:
6090 case R_SH_GOTOFFFUNCDESC20:
6092 #ifdef INCLUDE_SHMEDIA
6093 case R_SH_GOTPLT_LOW16:
6094 case R_SH_GOTPLT_MEDLOW16:
6095 case R_SH_GOTPLT_MEDHI16:
6096 case R_SH_GOTPLT_HI16:
6097 case R_SH_GOTPLT10BY4:
6098 case R_SH_GOTPLT10BY8:
6099 case R_SH_GOT_LOW16:
6100 case R_SH_GOT_MEDLOW16:
6101 case R_SH_GOT_MEDHI16:
6105 case R_SH_GOTOFF_LOW16:
6106 case R_SH_GOTOFF_MEDLOW16:
6107 case R_SH_GOTOFF_MEDHI16:
6108 case R_SH_GOTOFF_HI16:
6109 case R_SH_GOTPC_LOW16:
6110 case R_SH_GOTPC_MEDLOW16:
6111 case R_SH_GOTPC_MEDHI16:
6112 case R_SH_GOTPC_HI16:
6114 case R_SH_TLS_GD_32:
6115 case R_SH_TLS_LD_32:
6116 case R_SH_TLS_IE_32:
6117 if (htab->root.dynobj == NULL)
6118 htab->root.dynobj = abfd;
6119 if (!create_got_section (htab->root.dynobj, info))
6130 /* This relocation describes the C++ object vtable hierarchy.
6131 Reconstruct it for later use during GC. */
6132 case R_SH_GNU_VTINHERIT:
6133 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
6137 /* This relocation describes which C++ vtable entries are actually
6138 used. Record for later use during GC. */
6139 case R_SH_GNU_VTENTRY:
6140 BFD_ASSERT (h != NULL);
6142 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
6146 case R_SH_TLS_IE_32:
6148 info->flags |= DF_STATIC_TLS;
6152 case R_SH_TLS_GD_32:
6155 #ifdef INCLUDE_SHMEDIA
6156 case R_SH_GOT_LOW16:
6157 case R_SH_GOT_MEDLOW16:
6158 case R_SH_GOT_MEDHI16:
6163 case R_SH_GOTFUNCDESC:
6164 case R_SH_GOTFUNCDESC20:
6168 got_type = GOT_NORMAL;
6170 case R_SH_TLS_GD_32:
6171 got_type = GOT_TLS_GD;
6173 case R_SH_TLS_IE_32:
6174 got_type = GOT_TLS_IE;
6176 case R_SH_GOTFUNCDESC:
6177 case R_SH_GOTFUNCDESC20:
6178 got_type = GOT_FUNCDESC;
6184 #ifdef INCLUDE_SHMEDIA
6185 if (seen_stt_datalabel)
6187 struct elf_sh_link_hash_entry *eh
6188 = (struct elf_sh_link_hash_entry *) h;
6190 eh->datalabel_got.refcount += 1;
6194 h->got.refcount += 1;
6195 old_got_type = sh_elf_hash_entry (h)->got_type;
6199 bfd_signed_vma *local_got_refcounts;
6201 /* This is a global offset table entry for a local
6203 local_got_refcounts = elf_local_got_refcounts (abfd);
6204 if (local_got_refcounts == NULL)
6208 size = symtab_hdr->sh_info;
6209 size *= sizeof (bfd_signed_vma);
6210 #ifdef INCLUDE_SHMEDIA
6211 /* Reserve space for both the datalabel and
6212 codelabel local GOT offsets. */
6215 size += symtab_hdr->sh_info;
6216 local_got_refcounts = ((bfd_signed_vma *)
6217 bfd_zalloc (abfd, size));
6218 if (local_got_refcounts == NULL)
6220 elf_local_got_refcounts (abfd) = local_got_refcounts;
6221 #ifdef INCLUDE_SHMEDIA
6222 /* Take care of both the datalabel and codelabel local
6224 sh_elf_local_got_type (abfd)
6225 = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
6227 sh_elf_local_got_type (abfd)
6228 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
6231 #ifdef INCLUDE_SHMEDIA
6232 if (rel->r_addend & 1)
6233 local_got_refcounts[symtab_hdr->sh_info + r_symndx] += 1;
6236 local_got_refcounts[r_symndx] += 1;
6237 old_got_type = sh_elf_local_got_type (abfd) [r_symndx];
6240 /* If a TLS symbol is accessed using IE at least once,
6241 there is no point to use dynamic model for it. */
6242 if (old_got_type != got_type && old_got_type != GOT_UNKNOWN
6243 && (old_got_type != GOT_TLS_GD || got_type != GOT_TLS_IE))
6245 if (old_got_type == GOT_TLS_IE && got_type == GOT_TLS_GD)
6246 got_type = GOT_TLS_IE;
6249 if ((old_got_type == GOT_FUNCDESC || got_type == GOT_FUNCDESC)
6250 && (old_got_type == GOT_NORMAL || got_type == GOT_NORMAL))
6251 (*_bfd_error_handler)
6252 (_("%B: `%s' accessed both as normal and FDPIC symbol"),
6253 abfd, h->root.root.string);
6254 else if (old_got_type == GOT_FUNCDESC
6255 || got_type == GOT_FUNCDESC)
6256 (*_bfd_error_handler)
6257 (_("%B: `%s' accessed both as FDPIC and thread local symbol"),
6258 abfd, h->root.root.string);
6260 (*_bfd_error_handler)
6261 (_("%B: `%s' accessed both as normal and thread local symbol"),
6262 abfd, h->root.root.string);
6267 if (old_got_type != got_type)
6270 sh_elf_hash_entry (h)->got_type = got_type;
6272 sh_elf_local_got_type (abfd) [r_symndx] = got_type;
6277 case R_SH_TLS_LD_32:
6278 sh_elf_hash_table(info)->tls_ldm_got.refcount += 1;
6282 case R_SH_GOTOFFFUNCDESC:
6283 case R_SH_GOTOFFFUNCDESC20:
6286 (*_bfd_error_handler)
6287 (_("%B: Function descriptor relocation with non-zero addend"),
6294 union gotref *local_funcdesc;
6296 /* We need a function descriptor for a local symbol. */
6297 local_funcdesc = sh_elf_local_funcdesc (abfd);
6298 if (local_funcdesc == NULL)
6302 size = symtab_hdr->sh_info * sizeof (union gotref);
6303 #ifdef INCLUDE_SHMEDIA
6304 /* Count datalabel local GOT. */
6307 local_funcdesc = (union gotref *) bfd_zalloc (abfd, size);
6308 if (local_funcdesc == NULL)
6310 sh_elf_local_funcdesc (abfd) = local_funcdesc;
6312 local_funcdesc[r_symndx].refcount += 1;
6314 if (r_type == R_SH_FUNCDESC)
6317 htab->srofixup->size += 4;
6319 htab->srelgot->size += sizeof (Elf32_External_Rela);
6324 sh_elf_hash_entry (h)->funcdesc.refcount++;
6325 if (r_type == R_SH_FUNCDESC)
6326 sh_elf_hash_entry (h)->abs_funcdesc_refcount++;
6328 /* If there is a function descriptor reference, then
6329 there should not be any non-FDPIC references. */
6330 old_got_type = sh_elf_hash_entry (h)->got_type;
6331 if (old_got_type != GOT_FUNCDESC && old_got_type != GOT_UNKNOWN)
6333 if (old_got_type == GOT_NORMAL)
6334 (*_bfd_error_handler)
6335 (_("%B: `%s' accessed both as normal and FDPIC symbol"),
6336 abfd, h->root.root.string);
6338 (*_bfd_error_handler)
6339 (_("%B: `%s' accessed both as FDPIC and thread local symbol"),
6340 abfd, h->root.root.string);
6346 #ifdef INCLUDE_SHMEDIA
6347 case R_SH_GOTPLT_LOW16:
6348 case R_SH_GOTPLT_MEDLOW16:
6349 case R_SH_GOTPLT_MEDHI16:
6350 case R_SH_GOTPLT_HI16:
6351 case R_SH_GOTPLT10BY4:
6352 case R_SH_GOTPLT10BY8:
6354 /* If this is a local symbol, we resolve it directly without
6355 creating a procedure linkage table entry. */
6361 || h->dynindx == -1)
6365 h->plt.refcount += 1;
6366 ((struct elf_sh_link_hash_entry *) h)->gotplt_refcount += 1;
6371 #ifdef INCLUDE_SHMEDIA
6372 case R_SH_PLT_LOW16:
6373 case R_SH_PLT_MEDLOW16:
6374 case R_SH_PLT_MEDHI16:
6377 /* This symbol requires a procedure linkage table entry. We
6378 actually build the entry in adjust_dynamic_symbol,
6379 because this might be a case of linking PIC code which is
6380 never referenced by a dynamic object, in which case we
6381 don't need to generate a procedure linkage table entry
6384 /* If this is a local symbol, we resolve it directly without
6385 creating a procedure linkage table entry. */
6389 if (h->forced_local)
6393 h->plt.refcount += 1;
6398 #ifdef INCLUDE_SHMEDIA
6399 case R_SH_IMM_LOW16_PCREL:
6400 case R_SH_IMM_MEDLOW16_PCREL:
6401 case R_SH_IMM_MEDHI16_PCREL:
6402 case R_SH_IMM_HI16_PCREL:
6404 if (h != NULL && ! info->shared)
6407 h->plt.refcount += 1;
6410 /* If we are creating a shared library, and this is a reloc
6411 against a global symbol, or a non PC relative reloc
6412 against a local symbol, then we need to copy the reloc
6413 into the shared library. However, if we are linking with
6414 -Bsymbolic, we do not need to copy a reloc against a
6415 global symbol which is defined in an object we are
6416 including in the link (i.e., DEF_REGULAR is set). At
6417 this point we have not seen all the input files, so it is
6418 possible that DEF_REGULAR is not set now but will be set
6419 later (it is never cleared). We account for that
6420 possibility below by storing information in the
6421 dyn_relocs field of the hash table entry. A similar
6422 situation occurs when creating shared libraries and symbol
6423 visibility changes render the symbol local.
6425 If on the other hand, we are creating an executable, we
6426 may need to keep relocations for symbols satisfied by a
6427 dynamic library if we manage to avoid copy relocs for the
6430 && (sec->flags & SEC_ALLOC) != 0
6431 && (r_type != R_SH_REL32
6433 && (! info->symbolic
6434 || h->root.type == bfd_link_hash_defweak
6435 || !h->def_regular))))
6437 && (sec->flags & SEC_ALLOC) != 0
6439 && (h->root.type == bfd_link_hash_defweak
6440 || !h->def_regular)))
6442 struct elf_sh_dyn_relocs *p;
6443 struct elf_sh_dyn_relocs **head;
6445 if (htab->root.dynobj == NULL)
6446 htab->root.dynobj = abfd;
6448 /* When creating a shared object, we must copy these
6449 reloc types into the output file. We create a reloc
6450 section in dynobj and make room for this reloc. */
6453 sreloc = _bfd_elf_make_dynamic_reloc_section
6454 (sec, htab->root.dynobj, 2, abfd, /*rela?*/ TRUE);
6460 /* If this is a global symbol, we count the number of
6461 relocations we need for this symbol. */
6463 head = &((struct elf_sh_link_hash_entry *) h)->dyn_relocs;
6466 /* Track dynamic relocs needed for local syms too. */
6469 Elf_Internal_Sym *isym;
6471 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
6476 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
6480 vpp = &elf_section_data (s)->local_dynrel;
6481 head = (struct elf_sh_dyn_relocs **) vpp;
6485 if (p == NULL || p->sec != sec)
6487 bfd_size_type amt = sizeof (*p);
6488 p = bfd_alloc (htab->root.dynobj, amt);
6499 if (r_type == R_SH_REL32
6500 #ifdef INCLUDE_SHMEDIA
6501 || r_type == R_SH_IMM_LOW16_PCREL
6502 || r_type == R_SH_IMM_MEDLOW16_PCREL
6503 || r_type == R_SH_IMM_MEDHI16_PCREL
6504 || r_type == R_SH_IMM_HI16_PCREL
6510 /* Allocate the fixup regardless of whether we need a relocation.
6511 If we end up generating the relocation, we'll unallocate the
6513 if (htab->fdpic_p && !info->shared
6514 && r_type == R_SH_DIR32
6515 && (sec->flags & SEC_ALLOC) != 0)
6516 htab->srofixup->size += 4;
6519 case R_SH_TLS_LE_32:
6520 if (info->shared && !info->pie)
6522 (*_bfd_error_handler)
6523 (_("%B: TLS local exec code cannot be linked into shared objects"),
6530 case R_SH_TLS_LDO_32:
6531 /* Nothing to do. */
6542 #ifndef sh_elf_set_mach_from_flags
6543 static unsigned int sh_ef_bfd_table[] = { EF_SH_BFD_TABLE };
6546 sh_elf_set_mach_from_flags (bfd *abfd)
6548 flagword flags = elf_elfheader (abfd)->e_flags & EF_SH_MACH_MASK;
6550 if (flags >= sizeof(sh_ef_bfd_table))
6553 if (sh_ef_bfd_table[flags] == 0)
6556 bfd_default_set_arch_mach (abfd, bfd_arch_sh, sh_ef_bfd_table[flags]);
6562 /* Reverse table lookup for sh_ef_bfd_table[].
6563 Given a bfd MACH value from archures.c
6564 return the equivalent ELF flags from the table.
6565 Return -1 if no match is found. */
6568 sh_elf_get_flags_from_mach (unsigned long mach)
6570 int i = ARRAY_SIZE (sh_ef_bfd_table) - 1;
6573 if (sh_ef_bfd_table[i] == mach)
6576 /* shouldn't get here */
6581 #endif /* not sh_elf_set_mach_from_flags */
6583 #ifndef sh_elf_copy_private_data
6584 /* Copy backend specific data from one object module to another */
6587 sh_elf_copy_private_data (bfd * ibfd, bfd * obfd)
6589 if (! is_sh_elf (ibfd) || ! is_sh_elf (obfd))
6592 if (! _bfd_elf_copy_private_bfd_data (ibfd, obfd))
6595 return sh_elf_set_mach_from_flags (obfd);
6597 #endif /* not sh_elf_copy_private_data */
6599 #ifndef sh_elf_merge_private_data
6601 /* This function returns the ELF architecture number that
6602 corresponds to the given arch_sh* flags. */
6605 sh_find_elf_flags (unsigned int arch_set)
6607 extern unsigned long sh_get_bfd_mach_from_arch_set (unsigned int);
6608 unsigned long bfd_mach = sh_get_bfd_mach_from_arch_set (arch_set);
6610 return sh_elf_get_flags_from_mach (bfd_mach);
6613 /* This routine initialises the elf flags when required and
6614 calls sh_merge_bfd_arch() to check dsp/fpu compatibility. */
6617 sh_elf_merge_private_data (bfd *ibfd, bfd *obfd)
6619 extern bfd_boolean sh_merge_bfd_arch (bfd *, bfd *);
6621 if (! is_sh_elf (ibfd) || ! is_sh_elf (obfd))
6624 if (! elf_flags_init (obfd))
6626 /* This happens when ld starts out with a 'blank' output file. */
6627 elf_flags_init (obfd) = TRUE;
6628 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
6629 sh_elf_set_mach_from_flags (obfd);
6630 if (elf_elfheader (obfd)->e_flags & EF_SH_FDPIC)
6631 elf_elfheader (obfd)->e_flags |= EF_SH_PIC;
6634 if (! sh_merge_bfd_arch (ibfd, obfd))
6636 _bfd_error_handler ("%B: uses instructions which are incompatible "
6637 "with instructions used in previous modules",
6639 bfd_set_error (bfd_error_bad_value);
6643 elf_elfheader (obfd)->e_flags &= ~EF_SH_MACH_MASK;
6644 elf_elfheader (obfd)->e_flags |=
6645 sh_elf_get_flags_from_mach (bfd_get_mach (obfd));
6647 if (fdpic_object_p (ibfd) != fdpic_object_p (obfd))
6649 _bfd_error_handler ("%B: attempt to mix FDPIC and non-FDPIC objects",
6651 bfd_set_error (bfd_error_bad_value);
6657 #endif /* not sh_elf_merge_private_data */
6659 /* Override the generic function because we need to store sh_elf_obj_tdata
6660 as the specific tdata. We set also the machine architecture from flags
6664 sh_elf_object_p (bfd *abfd)
6666 if (! sh_elf_set_mach_from_flags (abfd))
6669 return (((elf_elfheader (abfd)->e_flags & EF_SH_FDPIC) != 0)
6670 == fdpic_object_p (abfd));
6673 /* Finish up dynamic symbol handling. We set the contents of various
6674 dynamic sections here. */
6677 sh_elf_finish_dynamic_symbol (bfd *output_bfd, struct bfd_link_info *info,
6678 struct elf_link_hash_entry *h,
6679 Elf_Internal_Sym *sym)
6681 struct elf_sh_link_hash_table *htab;
6683 htab = sh_elf_hash_table (info);
6687 if (h->plt.offset != (bfd_vma) -1)
6695 Elf_Internal_Rela rel;
6697 const struct elf_sh_plt_info *plt_info;
6699 /* This symbol has an entry in the procedure linkage table. Set
6702 BFD_ASSERT (h->dynindx != -1);
6705 sgotplt = htab->sgotplt;
6706 srelplt = htab->srelplt;
6707 BFD_ASSERT (splt != NULL && sgotplt != NULL && srelplt != NULL);
6709 /* Get the index in the procedure linkage table which
6710 corresponds to this symbol. This is the index of this symbol
6711 in all the symbols for which we are making plt entries. The
6712 first entry in the procedure linkage table is reserved. */
6713 plt_index = get_plt_index (htab->plt_info, h->plt.offset);
6715 plt_info = htab->plt_info;
6716 if (plt_info->short_plt != NULL && plt_index <= MAX_SHORT_PLT)
6717 plt_info = plt_info->short_plt;
6719 /* Get the offset into the .got table of the entry that
6720 corresponds to this function. */
6722 /* The offset must be relative to the GOT symbol, twelve bytes
6723 before the end of .got.plt. Each descriptor is eight
6725 got_offset = plt_index * 8 + 12 - sgotplt->size;
6727 /* Each .got entry is 4 bytes. The first three are
6729 got_offset = (plt_index + 3) * 4;
6733 got_offset -= GOT_BIAS;
6736 /* Fill in the entry in the procedure linkage table. */
6737 memcpy (splt->contents + h->plt.offset,
6738 plt_info->symbol_entry,
6739 plt_info->symbol_entry_size);
6741 if (info->shared || htab->fdpic_p)
6743 if (plt_info->symbol_fields.got20)
6745 bfd_reloc_status_type r;
6746 r = install_movi20_field (output_bfd, got_offset,
6747 splt->owner, splt, splt->contents,
6749 + plt_info->symbol_fields.got_entry);
6750 BFD_ASSERT (r == bfd_reloc_ok);
6753 install_plt_field (output_bfd, FALSE, got_offset,
6756 + plt_info->symbol_fields.got_entry));
6760 BFD_ASSERT (!plt_info->symbol_fields.got20);
6762 install_plt_field (output_bfd, FALSE,
6763 (sgotplt->output_section->vma
6764 + sgotplt->output_offset
6768 + plt_info->symbol_fields.got_entry));
6769 if (htab->vxworks_p)
6771 unsigned int reachable_plts, plts_per_4k;
6774 /* Divide the PLT into groups. The first group contains
6775 REACHABLE_PLTS entries and the other groups contain
6776 PLTS_PER_4K entries. Entries in the first group can
6777 branch directly to .plt; those in later groups branch
6778 to the last element of the previous group. */
6779 /* ??? It would be better to create multiple copies of
6780 the common resolver stub. */
6781 reachable_plts = ((4096
6782 - plt_info->plt0_entry_size
6783 - (plt_info->symbol_fields.plt + 4))
6784 / plt_info->symbol_entry_size) + 1;
6785 plts_per_4k = (4096 / plt_info->symbol_entry_size);
6786 if (plt_index < reachable_plts)
6787 distance = -(h->plt.offset
6788 + plt_info->symbol_fields.plt);
6790 distance = -(((plt_index - reachable_plts) % plts_per_4k + 1)
6791 * plt_info->symbol_entry_size);
6793 /* Install the 'bra' with this offset. */
6794 bfd_put_16 (output_bfd,
6795 0xa000 | (0x0fff & ((distance - 4) / 2)),
6798 + plt_info->symbol_fields.plt));
6801 install_plt_field (output_bfd, TRUE,
6802 splt->output_section->vma + splt->output_offset,
6805 + plt_info->symbol_fields.plt));
6808 /* Make got_offset relative to the start of .got.plt. */
6811 got_offset += GOT_BIAS;
6814 got_offset = plt_index * 8;
6816 if (plt_info->symbol_fields.reloc_offset != MINUS_ONE)
6817 install_plt_field (output_bfd, FALSE,
6818 plt_index * sizeof (Elf32_External_Rela),
6821 + plt_info->symbol_fields.reloc_offset));
6823 /* Fill in the entry in the global offset table. */
6824 bfd_put_32 (output_bfd,
6825 (splt->output_section->vma
6826 + splt->output_offset
6828 + plt_info->symbol_resolve_offset),
6829 sgotplt->contents + got_offset);
6831 bfd_put_32 (output_bfd,
6832 sh_elf_osec_to_segment (output_bfd,
6833 htab->splt->output_section),
6834 sgotplt->contents + got_offset + 4);
6836 /* Fill in the entry in the .rela.plt section. */
6837 rel.r_offset = (sgotplt->output_section->vma
6838 + sgotplt->output_offset
6841 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_FUNCDESC_VALUE);
6843 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_JMP_SLOT);
6846 rel.r_addend = GOT_BIAS;
6848 loc = srelplt->contents + plt_index * sizeof (Elf32_External_Rela);
6849 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
6851 if (htab->vxworks_p && !info->shared)
6853 /* Create the .rela.plt.unloaded relocations for this PLT entry.
6854 Begin by pointing LOC to the first such relocation. */
6855 loc = (htab->srelplt2->contents
6856 + (plt_index * 2 + 1) * sizeof (Elf32_External_Rela));
6858 /* Create a .rela.plt.unloaded R_SH_DIR32 relocation
6859 for the PLT entry's pointer to the .got.plt entry. */
6860 rel.r_offset = (htab->splt->output_section->vma
6861 + htab->splt->output_offset
6863 + plt_info->symbol_fields.got_entry);
6864 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_SH_DIR32);
6865 rel.r_addend = got_offset;
6866 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
6867 loc += sizeof (Elf32_External_Rela);
6869 /* Create a .rela.plt.unloaded R_SH_DIR32 relocation for
6870 the .got.plt entry, which initially points to .plt. */
6871 rel.r_offset = (sgotplt->output_section->vma
6872 + sgotplt->output_offset
6874 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_SH_DIR32);
6876 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
6879 if (!h->def_regular)
6881 /* Mark the symbol as undefined, rather than as defined in
6882 the .plt section. Leave the value alone. */
6883 sym->st_shndx = SHN_UNDEF;
6887 if (h->got.offset != (bfd_vma) -1
6888 && sh_elf_hash_entry (h)->got_type != GOT_TLS_GD
6889 && sh_elf_hash_entry (h)->got_type != GOT_TLS_IE
6890 && sh_elf_hash_entry (h)->got_type != GOT_FUNCDESC)
6894 Elf_Internal_Rela rel;
6897 /* This symbol has an entry in the global offset table. Set it
6901 srelgot = htab->srelgot;
6902 BFD_ASSERT (sgot != NULL && srelgot != NULL);
6904 rel.r_offset = (sgot->output_section->vma
6905 + sgot->output_offset
6906 + (h->got.offset &~ (bfd_vma) 1));
6908 /* If this is a static link, or it is a -Bsymbolic link and the
6909 symbol is defined locally or was forced to be local because
6910 of a version file, we just want to emit a RELATIVE reloc.
6911 The entry in the global offset table will already have been
6912 initialized in the relocate_section function. */
6914 && SYMBOL_REFERENCES_LOCAL (info, h))
6918 asection *sec = h->root.u.def.section;
6920 = elf_section_data (sec->output_section)->dynindx;
6922 rel.r_info = ELF32_R_INFO (dynindx, R_SH_DIR32);
6923 rel.r_addend = (h->root.u.def.value
6924 + h->root.u.def.section->output_offset);
6928 rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
6929 rel.r_addend = (h->root.u.def.value
6930 + h->root.u.def.section->output_section->vma
6931 + h->root.u.def.section->output_offset);
6936 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
6937 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_GLOB_DAT);
6941 loc = srelgot->contents;
6942 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
6943 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
6946 #ifdef INCLUDE_SHMEDIA
6948 struct elf_sh_link_hash_entry *eh;
6950 eh = (struct elf_sh_link_hash_entry *) h;
6951 if (eh->datalabel_got.offset != (bfd_vma) -1)
6955 Elf_Internal_Rela rel;
6958 /* This symbol has a datalabel entry in the global offset table.
6962 srelgot = htab->srelgot;
6963 BFD_ASSERT (sgot != NULL && srelgot != NULL);
6965 rel.r_offset = (sgot->output_section->vma
6966 + sgot->output_offset
6967 + (eh->datalabel_got.offset &~ (bfd_vma) 1));
6969 /* If this is a static link, or it is a -Bsymbolic link and the
6970 symbol is defined locally or was forced to be local because
6971 of a version file, we just want to emit a RELATIVE reloc.
6972 The entry in the global offset table will already have been
6973 initialized in the relocate_section function. */
6975 && SYMBOL_REFERENCES_LOCAL (info, h))
6979 asection *sec = h->root.u.def.section;
6981 = elf_section_data (sec->output_section)->dynindx;
6983 rel.r_info = ELF32_R_INFO (dynindx, R_SH_DIR32);
6984 rel.r_addend = (h->root.u.def.value
6985 + h->root.u.def.section->output_offset);
6989 rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
6990 rel.r_addend = (h->root.u.def.value
6991 + h->root.u.def.section->output_section->vma
6992 + h->root.u.def.section->output_offset);
6997 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents
6998 + eh->datalabel_got.offset);
6999 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_GLOB_DAT);
7003 loc = srelgot->contents;
7004 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
7005 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
7013 Elf_Internal_Rela rel;
7016 /* This symbol needs a copy reloc. Set it up. */
7018 BFD_ASSERT (h->dynindx != -1
7019 && (h->root.type == bfd_link_hash_defined
7020 || h->root.type == bfd_link_hash_defweak));
7022 s = bfd_get_linker_section (htab->root.dynobj, ".rela.bss");
7023 BFD_ASSERT (s != NULL);
7025 rel.r_offset = (h->root.u.def.value
7026 + h->root.u.def.section->output_section->vma
7027 + h->root.u.def.section->output_offset);
7028 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_COPY);
7030 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
7031 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
7034 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
7035 _GLOBAL_OFFSET_TABLE_ is not absolute: it is relative to the
7037 if (h == htab->root.hdynamic
7038 || (!htab->vxworks_p && h == htab->root.hgot))
7039 sym->st_shndx = SHN_ABS;
7044 /* Finish up the dynamic sections. */
7047 sh_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
7049 struct elf_sh_link_hash_table *htab;
7053 htab = sh_elf_hash_table (info);
7057 sgotplt = htab->sgotplt;
7058 sdyn = bfd_get_linker_section (htab->root.dynobj, ".dynamic");
7060 if (htab->root.dynamic_sections_created)
7063 Elf32_External_Dyn *dyncon, *dynconend;
7065 BFD_ASSERT (sgotplt != NULL && sdyn != NULL);
7067 dyncon = (Elf32_External_Dyn *) sdyn->contents;
7068 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
7069 for (; dyncon < dynconend; dyncon++)
7071 Elf_Internal_Dyn dyn;
7073 #ifdef INCLUDE_SHMEDIA
7077 bfd_elf32_swap_dyn_in (htab->root.dynobj, dyncon, &dyn);
7083 && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
7084 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7087 #ifdef INCLUDE_SHMEDIA
7089 name = info->init_function;
7093 name = info->fini_function;
7095 if (dyn.d_un.d_val != 0)
7097 struct elf_link_hash_entry *h;
7099 h = elf_link_hash_lookup (&htab->root, name,
7100 FALSE, FALSE, TRUE);
7101 if (h != NULL && (h->other & STO_SH5_ISA32))
7103 dyn.d_un.d_val |= 1;
7104 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7111 BFD_ASSERT (htab->root.hgot != NULL);
7112 s = htab->root.hgot->root.u.def.section;
7113 dyn.d_un.d_ptr = htab->root.hgot->root.u.def.value
7114 + s->output_section->vma + s->output_offset;
7115 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7119 s = htab->srelplt->output_section;
7120 BFD_ASSERT (s != NULL);
7121 dyn.d_un.d_ptr = s->vma;
7122 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7126 s = htab->srelplt->output_section;
7127 BFD_ASSERT (s != NULL);
7128 dyn.d_un.d_val = s->size;
7129 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7133 /* My reading of the SVR4 ABI indicates that the
7134 procedure linkage table relocs (DT_JMPREL) should be
7135 included in the overall relocs (DT_RELA). This is
7136 what Solaris does. However, UnixWare can not handle
7137 that case. Therefore, we override the DT_RELASZ entry
7138 here to make it not include the JMPREL relocs. Since
7139 the linker script arranges for .rela.plt to follow all
7140 other relocation sections, we don't have to worry
7141 about changing the DT_RELA entry. */
7142 if (htab->srelplt != NULL)
7144 s = htab->srelplt->output_section;
7145 dyn.d_un.d_val -= s->size;
7147 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7152 /* Fill in the first entry in the procedure linkage table. */
7154 if (splt && splt->size > 0 && htab->plt_info->plt0_entry)
7158 memcpy (splt->contents,
7159 htab->plt_info->plt0_entry,
7160 htab->plt_info->plt0_entry_size);
7161 for (i = 0; i < ARRAY_SIZE (htab->plt_info->plt0_got_fields); i++)
7162 if (htab->plt_info->plt0_got_fields[i] != MINUS_ONE)
7163 install_plt_field (output_bfd, FALSE,
7164 (sgotplt->output_section->vma
7165 + sgotplt->output_offset
7168 + htab->plt_info->plt0_got_fields[i]));
7170 if (htab->vxworks_p)
7172 /* Finalize the .rela.plt.unloaded contents. */
7173 Elf_Internal_Rela rel;
7176 /* Create a .rela.plt.unloaded R_SH_DIR32 relocation for the
7177 first PLT entry's pointer to _GLOBAL_OFFSET_TABLE_ + 8. */
7178 loc = htab->srelplt2->contents;
7179 rel.r_offset = (splt->output_section->vma
7180 + splt->output_offset
7181 + htab->plt_info->plt0_got_fields[2]);
7182 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_SH_DIR32);
7184 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
7185 loc += sizeof (Elf32_External_Rela);
7187 /* Fix up the remaining .rela.plt.unloaded relocations.
7188 They may have the wrong symbol index for _G_O_T_ or
7189 _P_L_T_ depending on the order in which symbols were
7191 while (loc < htab->srelplt2->contents + htab->srelplt2->size)
7193 /* The PLT entry's pointer to the .got.plt slot. */
7194 bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
7195 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx,
7197 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
7198 loc += sizeof (Elf32_External_Rela);
7200 /* The .got.plt slot's pointer to .plt. */
7201 bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
7202 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx,
7204 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
7205 loc += sizeof (Elf32_External_Rela);
7209 /* UnixWare sets the entsize of .plt to 4, although that doesn't
7210 really seem like the right value. */
7211 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
7215 /* Fill in the first three entries in the global offset table. */
7216 if (sgotplt && sgotplt->size > 0 && !htab->fdpic_p)
7219 bfd_put_32 (output_bfd, (bfd_vma) 0, sgotplt->contents);
7221 bfd_put_32 (output_bfd,
7222 sdyn->output_section->vma + sdyn->output_offset,
7224 bfd_put_32 (output_bfd, (bfd_vma) 0, sgotplt->contents + 4);
7225 bfd_put_32 (output_bfd, (bfd_vma) 0, sgotplt->contents + 8);
7228 if (sgotplt && sgotplt->size > 0)
7229 elf_section_data (sgotplt->output_section)->this_hdr.sh_entsize = 4;
7231 /* At the very end of the .rofixup section is a pointer to the GOT. */
7232 if (htab->fdpic_p && htab->srofixup != NULL)
7234 struct elf_link_hash_entry *hgot = htab->root.hgot;
7235 bfd_vma got_value = hgot->root.u.def.value
7236 + hgot->root.u.def.section->output_section->vma
7237 + hgot->root.u.def.section->output_offset;
7239 sh_elf_add_rofixup (output_bfd, htab->srofixup, got_value);
7241 /* Make sure we allocated and generated the same number of fixups. */
7242 BFD_ASSERT (htab->srofixup->reloc_count * 4 == htab->srofixup->size);
7245 if (htab->srelfuncdesc)
7246 BFD_ASSERT (htab->srelfuncdesc->reloc_count * sizeof (Elf32_External_Rela)
7247 == htab->srelfuncdesc->size);
7250 BFD_ASSERT (htab->srelgot->reloc_count * sizeof (Elf32_External_Rela)
7251 == htab->srelgot->size);
7256 static enum elf_reloc_type_class
7257 sh_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
7258 const asection *rel_sec ATTRIBUTE_UNUSED,
7259 const Elf_Internal_Rela *rela)
7261 switch ((int) ELF32_R_TYPE (rela->r_info))
7264 return reloc_class_relative;
7266 return reloc_class_plt;
7268 return reloc_class_copy;
7270 return reloc_class_normal;
7274 #if !defined SH_TARGET_ALREADY_DEFINED
7275 /* Support for Linux core dump NOTE sections. */
7278 elf32_shlin_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
7283 switch (note->descsz)
7288 case 168: /* Linux/SH */
7290 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
7293 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
7302 /* Make a ".reg/999" section. */
7303 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
7304 size, note->descpos + offset);
7308 elf32_shlin_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
7310 switch (note->descsz)
7315 case 124: /* Linux/SH elf_prpsinfo */
7316 elf_tdata (abfd)->core->program
7317 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
7318 elf_tdata (abfd)->core->command
7319 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
7322 /* Note that for some reason, a spurious space is tacked
7323 onto the end of the args in some (at least one anyway)
7324 implementations, so strip it off if it exists. */
7327 char *command = elf_tdata (abfd)->core->command;
7328 int n = strlen (command);
7330 if (0 < n && command[n - 1] == ' ')
7331 command[n - 1] = '\0';
7336 #endif /* not SH_TARGET_ALREADY_DEFINED */
7339 /* Return address for Ith PLT stub in section PLT, for relocation REL
7340 or (bfd_vma) -1 if it should not be included. */
7343 sh_elf_plt_sym_val (bfd_vma i, const asection *plt,
7344 const arelent *rel ATTRIBUTE_UNUSED)
7346 const struct elf_sh_plt_info *plt_info;
7348 plt_info = get_plt_info (plt->owner, (plt->owner->flags & DYNAMIC) != 0);
7349 return plt->vma + get_plt_offset (plt_info, i);
7352 /* Decide whether to attempt to turn absptr or lsda encodings in
7353 shared libraries into pcrel within the given input section. */
7356 sh_elf_use_relative_eh_frame (bfd *input_bfd ATTRIBUTE_UNUSED,
7357 struct bfd_link_info *info,
7358 asection *eh_frame_section ATTRIBUTE_UNUSED)
7360 struct elf_sh_link_hash_table *htab = sh_elf_hash_table (info);
7362 /* We can't use PC-relative encodings in FDPIC binaries, in general. */
7369 /* Adjust the contents of an eh_frame_hdr section before they're output. */
7372 sh_elf_encode_eh_address (bfd *abfd,
7373 struct bfd_link_info *info,
7374 asection *osec, bfd_vma offset,
7375 asection *loc_sec, bfd_vma loc_offset,
7378 struct elf_sh_link_hash_table *htab = sh_elf_hash_table (info);
7379 struct elf_link_hash_entry *h;
7382 return _bfd_elf_encode_eh_address (abfd, info, osec, offset, loc_sec,
7383 loc_offset, encoded);
7385 h = htab->root.hgot;
7386 BFD_ASSERT (h && h->root.type == bfd_link_hash_defined);
7388 if (! h || (sh_elf_osec_to_segment (abfd, osec)
7389 == sh_elf_osec_to_segment (abfd, loc_sec->output_section)))
7390 return _bfd_elf_encode_eh_address (abfd, info, osec, offset,
7391 loc_sec, loc_offset, encoded);
7393 BFD_ASSERT (sh_elf_osec_to_segment (abfd, osec)
7394 == (sh_elf_osec_to_segment
7395 (abfd, h->root.u.def.section->output_section)));
7397 *encoded = osec->vma + offset
7398 - (h->root.u.def.value
7399 + h->root.u.def.section->output_section->vma
7400 + h->root.u.def.section->output_offset);
7402 return DW_EH_PE_datarel | DW_EH_PE_sdata4;
7405 #if !defined SH_TARGET_ALREADY_DEFINED
7406 #define TARGET_BIG_SYM sh_elf32_vec
7407 #define TARGET_BIG_NAME "elf32-sh"
7408 #define TARGET_LITTLE_SYM sh_elf32_le_vec
7409 #define TARGET_LITTLE_NAME "elf32-shl"
7412 #define ELF_ARCH bfd_arch_sh
7413 #define ELF_TARGET_ID SH_ELF_DATA
7414 #define ELF_MACHINE_CODE EM_SH
7415 #ifdef __QNXTARGET__
7416 #define ELF_MAXPAGESIZE 0x1000
7418 #define ELF_MAXPAGESIZE 0x80
7421 #define elf_symbol_leading_char '_'
7423 #define bfd_elf32_bfd_reloc_type_lookup sh_elf_reloc_type_lookup
7424 #define bfd_elf32_bfd_reloc_name_lookup \
7425 sh_elf_reloc_name_lookup
7426 #define elf_info_to_howto sh_elf_info_to_howto
7427 #define bfd_elf32_bfd_relax_section sh_elf_relax_section
7428 #define elf_backend_relocate_section sh_elf_relocate_section
7429 #define bfd_elf32_bfd_get_relocated_section_contents \
7430 sh_elf_get_relocated_section_contents
7431 #define bfd_elf32_mkobject sh_elf_mkobject
7432 #define elf_backend_object_p sh_elf_object_p
7433 #define bfd_elf32_bfd_copy_private_bfd_data \
7434 sh_elf_copy_private_data
7435 #define bfd_elf32_bfd_merge_private_bfd_data \
7436 sh_elf_merge_private_data
7438 #define elf_backend_gc_mark_hook sh_elf_gc_mark_hook
7439 #define elf_backend_gc_sweep_hook sh_elf_gc_sweep_hook
7440 #define elf_backend_check_relocs sh_elf_check_relocs
7441 #define elf_backend_copy_indirect_symbol \
7442 sh_elf_copy_indirect_symbol
7443 #define elf_backend_create_dynamic_sections \
7444 sh_elf_create_dynamic_sections
7445 #define bfd_elf32_bfd_link_hash_table_create \
7446 sh_elf_link_hash_table_create
7447 #define elf_backend_adjust_dynamic_symbol \
7448 sh_elf_adjust_dynamic_symbol
7449 #define elf_backend_always_size_sections \
7450 sh_elf_always_size_sections
7451 #define elf_backend_size_dynamic_sections \
7452 sh_elf_size_dynamic_sections
7453 #define elf_backend_omit_section_dynsym sh_elf_omit_section_dynsym
7454 #define elf_backend_finish_dynamic_symbol \
7455 sh_elf_finish_dynamic_symbol
7456 #define elf_backend_finish_dynamic_sections \
7457 sh_elf_finish_dynamic_sections
7458 #define elf_backend_reloc_type_class sh_elf_reloc_type_class
7459 #define elf_backend_plt_sym_val sh_elf_plt_sym_val
7460 #define elf_backend_can_make_relative_eh_frame \
7461 sh_elf_use_relative_eh_frame
7462 #define elf_backend_can_make_lsda_relative_eh_frame \
7463 sh_elf_use_relative_eh_frame
7464 #define elf_backend_encode_eh_address \
7465 sh_elf_encode_eh_address
7467 #define elf_backend_stack_align 8
7468 #define elf_backend_can_gc_sections 1
7469 #define elf_backend_can_refcount 1
7470 #define elf_backend_want_got_plt 1
7471 #define elf_backend_plt_readonly 1
7472 #define elf_backend_want_plt_sym 0
7473 #define elf_backend_got_header_size 12
7475 #if !defined INCLUDE_SHMEDIA && !defined SH_TARGET_ALREADY_DEFINED
7477 #include "elf32-target.h"
7479 /* NetBSD support. */
7480 #undef TARGET_BIG_SYM
7481 #define TARGET_BIG_SYM sh_elf32_nbsd_vec
7482 #undef TARGET_BIG_NAME
7483 #define TARGET_BIG_NAME "elf32-sh-nbsd"
7484 #undef TARGET_LITTLE_SYM
7485 #define TARGET_LITTLE_SYM sh_elf32_nbsd_le_vec
7486 #undef TARGET_LITTLE_NAME
7487 #define TARGET_LITTLE_NAME "elf32-shl-nbsd"
7488 #undef ELF_MAXPAGESIZE
7489 #define ELF_MAXPAGESIZE 0x10000
7490 #undef ELF_COMMONPAGESIZE
7491 #undef elf_symbol_leading_char
7492 #define elf_symbol_leading_char 0
7494 #define elf32_bed elf32_sh_nbsd_bed
7496 #include "elf32-target.h"
7499 /* Linux support. */
7500 #undef TARGET_BIG_SYM
7501 #define TARGET_BIG_SYM sh_elf32_linux_be_vec
7502 #undef TARGET_BIG_NAME
7503 #define TARGET_BIG_NAME "elf32-shbig-linux"
7504 #undef TARGET_LITTLE_SYM
7505 #define TARGET_LITTLE_SYM sh_elf32_linux_vec
7506 #undef TARGET_LITTLE_NAME
7507 #define TARGET_LITTLE_NAME "elf32-sh-linux"
7508 #undef ELF_COMMONPAGESIZE
7509 #define ELF_COMMONPAGESIZE 0x1000
7511 #undef elf_backend_grok_prstatus
7512 #define elf_backend_grok_prstatus elf32_shlin_grok_prstatus
7513 #undef elf_backend_grok_psinfo
7514 #define elf_backend_grok_psinfo elf32_shlin_grok_psinfo
7516 #define elf32_bed elf32_sh_lin_bed
7518 #include "elf32-target.h"
7521 /* FDPIC support. */
7522 #undef TARGET_BIG_SYM
7523 #define TARGET_BIG_SYM sh_elf32_fdpic_be_vec
7524 #undef TARGET_BIG_NAME
7525 #define TARGET_BIG_NAME "elf32-shbig-fdpic"
7526 #undef TARGET_LITTLE_SYM
7527 #define TARGET_LITTLE_SYM sh_elf32_fdpic_le_vec
7528 #undef TARGET_LITTLE_NAME
7529 #define TARGET_LITTLE_NAME "elf32-sh-fdpic"
7532 #define elf32_bed elf32_sh_fd_bed
7534 #include "elf32-target.h"
7536 #undef elf_backend_modify_program_headers
7538 /* VxWorks support. */
7539 #undef TARGET_BIG_SYM
7540 #define TARGET_BIG_SYM sh_elf32_vxworks_vec
7541 #undef TARGET_BIG_NAME
7542 #define TARGET_BIG_NAME "elf32-sh-vxworks"
7543 #undef TARGET_LITTLE_SYM
7544 #define TARGET_LITTLE_SYM sh_elf32_vxworks_le_vec
7545 #undef TARGET_LITTLE_NAME
7546 #define TARGET_LITTLE_NAME "elf32-shl-vxworks"
7548 #define elf32_bed elf32_sh_vxworks_bed
7550 #undef elf_backend_want_plt_sym
7551 #define elf_backend_want_plt_sym 1
7552 #undef elf_symbol_leading_char
7553 #define elf_symbol_leading_char '_'
7554 #define elf_backend_want_got_underscore 1
7555 #undef elf_backend_grok_prstatus
7556 #undef elf_backend_grok_psinfo
7557 #undef elf_backend_add_symbol_hook
7558 #define elf_backend_add_symbol_hook elf_vxworks_add_symbol_hook
7559 #undef elf_backend_link_output_symbol_hook
7560 #define elf_backend_link_output_symbol_hook \
7561 elf_vxworks_link_output_symbol_hook
7562 #undef elf_backend_emit_relocs
7563 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
7564 #undef elf_backend_final_write_processing
7565 #define elf_backend_final_write_processing \
7566 elf_vxworks_final_write_processing
7567 #undef ELF_MAXPAGESIZE
7568 #define ELF_MAXPAGESIZE 0x1000
7569 #undef ELF_COMMONPAGESIZE
7571 #include "elf32-target.h"
7573 #endif /* neither INCLUDE_SHMEDIA nor SH_TARGET_ALREADY_DEFINED */