1 /* Renesas / SuperH SH specific support for 32-bit ELF
2 Copyright (C) 1996-2016 Free Software Foundation, Inc.
3 Contributed by Ian Lance Taylor, Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
27 #include "elf-vxworks.h"
30 #include "libiberty.h"
31 #include "../opcodes/sh-opc.h"
33 static bfd_reloc_status_type sh_elf_reloc
34 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
35 static bfd_reloc_status_type sh_elf_ignore_reloc
36 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
37 static bfd_boolean sh_elf_relax_delete_bytes
38 (bfd *, asection *, bfd_vma, int);
39 static bfd_boolean sh_elf_align_loads
40 (bfd *, asection *, Elf_Internal_Rela *, bfd_byte *, bfd_boolean *);
42 static bfd_boolean sh_elf_swap_insns
43 (bfd *, asection *, void *, bfd_byte *, bfd_vma);
45 static int sh_elf_optimized_tls_reloc
46 (struct bfd_link_info *, int, int);
47 static bfd_vma dtpoff_base
48 (struct bfd_link_info *);
50 (struct bfd_link_info *, bfd_vma);
52 /* The name of the dynamic interpreter. This is put in the .interp
55 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
57 /* FDPIC binaries have a default 128K stack. */
58 #define DEFAULT_STACK_SIZE 0x20000
60 #define MINUS_ONE ((bfd_vma) 0 - 1)
62 /* Decide whether a reference to a symbol can be resolved locally or
63 not. If the symbol is protected, we want the local address, but
64 its function descriptor must be assigned by the dynamic linker. */
65 #define SYMBOL_FUNCDESC_LOCAL(INFO, H) \
66 (SYMBOL_REFERENCES_LOCAL (INFO, H) \
67 || ! elf_hash_table (INFO)->dynamic_sections_created)
69 #define SH_PARTIAL32 TRUE
70 #define SH_SRC_MASK32 0xffffffff
71 #define SH_ELF_RELOC sh_elf_reloc
72 static reloc_howto_type sh_elf_howto_table[] =
74 #include "elf32-sh-relocs.h"
77 #define SH_PARTIAL32 FALSE
78 #define SH_SRC_MASK32 0
79 #define SH_ELF_RELOC bfd_elf_generic_reloc
80 static reloc_howto_type sh_vxworks_howto_table[] =
82 #include "elf32-sh-relocs.h"
85 /* Return true if OUTPUT_BFD is a VxWorks object. */
88 vxworks_object_p (bfd *abfd ATTRIBUTE_UNUSED)
90 #if !defined INCLUDE_SHMEDIA && !defined SH_TARGET_ALREADY_DEFINED
91 extern const bfd_target sh_elf32_vxworks_le_vec;
92 extern const bfd_target sh_elf32_vxworks_vec;
94 return (abfd->xvec == &sh_elf32_vxworks_le_vec
95 || abfd->xvec == &sh_elf32_vxworks_vec);
101 /* Return true if OUTPUT_BFD is an FDPIC object. */
104 fdpic_object_p (bfd *abfd ATTRIBUTE_UNUSED)
106 #if !defined INCLUDE_SHMEDIA && !defined SH_TARGET_ALREADY_DEFINED
107 extern const bfd_target sh_elf32_fdpic_le_vec;
108 extern const bfd_target sh_elf32_fdpic_be_vec;
110 return (abfd->xvec == &sh_elf32_fdpic_le_vec
111 || abfd->xvec == &sh_elf32_fdpic_be_vec);
117 /* Return the howto table for ABFD. */
119 static reloc_howto_type *
120 get_howto_table (bfd *abfd)
122 if (vxworks_object_p (abfd))
123 return sh_vxworks_howto_table;
124 return sh_elf_howto_table;
127 static bfd_reloc_status_type
128 sh_elf_reloc_loop (int r_type ATTRIBUTE_UNUSED, bfd *input_bfd,
129 asection *input_section, bfd_byte *contents,
130 bfd_vma addr, asection *symbol_section,
131 bfd_vma start, bfd_vma end)
133 static bfd_vma last_addr;
134 static asection *last_symbol_section;
135 bfd_byte *start_ptr, *ptr, *last_ptr;
140 /* Sanity check the address. */
141 if (addr > bfd_get_section_limit (input_bfd, input_section))
142 return bfd_reloc_outofrange;
144 /* We require the start and end relocations to be processed consecutively -
145 although we allow then to be processed forwards or backwards. */
149 last_symbol_section = symbol_section;
152 if (last_addr != addr)
156 if (! symbol_section || last_symbol_section != symbol_section || end < start)
157 return bfd_reloc_outofrange;
159 /* Get the symbol_section contents. */
160 if (symbol_section != input_section)
162 if (elf_section_data (symbol_section)->this_hdr.contents != NULL)
163 contents = elf_section_data (symbol_section)->this_hdr.contents;
166 if (!bfd_malloc_and_get_section (input_bfd, symbol_section,
169 if (contents != NULL)
171 return bfd_reloc_outofrange;
175 #define IS_PPI(PTR) ((bfd_get_16 (input_bfd, (PTR)) & 0xfc00) == 0xf800)
176 start_ptr = contents + start;
177 for (cum_diff = -6, ptr = contents + end; cum_diff < 0 && ptr > start_ptr;)
179 for (last_ptr = ptr, ptr -= 4; ptr >= start_ptr && IS_PPI (ptr);)
182 diff = (last_ptr - ptr) >> 1;
183 cum_diff += diff & 1;
186 /* Calculate the start / end values to load into rs / re minus four -
187 so that will cancel out the four we would otherwise have to add to
188 addr to get the value to subtract in order to get relative addressing. */
192 end = (ptr + cum_diff * 2) - contents;
196 bfd_vma start0 = start - 4;
198 while (start0 && IS_PPI (contents + start0))
200 start0 = start - 2 - ((start - start0) & 2);
201 start = start0 - cum_diff - 2;
206 && elf_section_data (symbol_section)->this_hdr.contents != contents)
209 insn = bfd_get_16 (input_bfd, contents + addr);
211 x = (insn & 0x200 ? end : start) - addr;
212 if (input_section != symbol_section)
213 x += ((symbol_section->output_section->vma + symbol_section->output_offset)
214 - (input_section->output_section->vma
215 + input_section->output_offset));
217 if (x < -128 || x > 127)
218 return bfd_reloc_overflow;
220 x = (insn & ~0xff) | (x & 0xff);
221 bfd_put_16 (input_bfd, (bfd_vma) x, contents + addr);
226 /* This function is used for normal relocs. This used to be like the COFF
227 function, and is almost certainly incorrect for other ELF targets. */
229 static bfd_reloc_status_type
230 sh_elf_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol_in,
231 void *data, asection *input_section, bfd *output_bfd,
232 char **error_message ATTRIBUTE_UNUSED)
236 enum elf_sh_reloc_type r_type;
237 bfd_vma addr = reloc_entry->address;
238 bfd_byte *hit_data = addr + (bfd_byte *) data;
240 r_type = (enum elf_sh_reloc_type) reloc_entry->howto->type;
242 if (output_bfd != NULL)
244 /* Partial linking--do nothing. */
245 reloc_entry->address += input_section->output_offset;
249 /* Almost all relocs have to do with relaxing. If any work must be
250 done for them, it has been done in sh_relax_section. */
251 if (r_type == R_SH_IND12W && (symbol_in->flags & BSF_LOCAL) != 0)
254 if (symbol_in != NULL
255 && bfd_is_und_section (symbol_in->section))
256 return bfd_reloc_undefined;
258 /* PR 17512: file: 9891ca98. */
259 if (addr * bfd_octets_per_byte (abfd) + bfd_get_reloc_size (reloc_entry->howto)
260 > bfd_get_section_limit_octets (abfd, input_section))
261 return bfd_reloc_outofrange;
263 if (bfd_is_com_section (symbol_in->section))
266 sym_value = (symbol_in->value +
267 symbol_in->section->output_section->vma +
268 symbol_in->section->output_offset);
273 insn = bfd_get_32 (abfd, hit_data);
274 insn += sym_value + reloc_entry->addend;
275 bfd_put_32 (abfd, (bfd_vma) insn, hit_data);
278 insn = bfd_get_16 (abfd, hit_data);
279 sym_value += reloc_entry->addend;
280 sym_value -= (input_section->output_section->vma
281 + input_section->output_offset
284 sym_value += (insn & 0xfff) << 1;
287 insn = (insn & 0xf000) | (sym_value & 0xfff);
288 bfd_put_16 (abfd, (bfd_vma) insn, hit_data);
289 if (sym_value < (bfd_vma) -0x1000 || sym_value >= 0x1000)
290 return bfd_reloc_overflow;
300 /* This function is used for relocs which are only used for relaxing,
301 which the linker should otherwise ignore. */
303 static bfd_reloc_status_type
304 sh_elf_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc_entry,
305 asymbol *symbol ATTRIBUTE_UNUSED,
306 void *data ATTRIBUTE_UNUSED, asection *input_section,
308 char **error_message ATTRIBUTE_UNUSED)
310 if (output_bfd != NULL)
311 reloc_entry->address += input_section->output_offset;
315 /* This structure is used to map BFD reloc codes to SH ELF relocs. */
319 bfd_reloc_code_real_type bfd_reloc_val;
320 unsigned char elf_reloc_val;
323 /* An array mapping BFD reloc codes to SH ELF relocs. */
325 static const struct elf_reloc_map sh_reloc_map[] =
327 { BFD_RELOC_NONE, R_SH_NONE },
328 { BFD_RELOC_32, R_SH_DIR32 },
329 { BFD_RELOC_16, R_SH_DIR16 },
330 { BFD_RELOC_8, R_SH_DIR8 },
331 { BFD_RELOC_CTOR, R_SH_DIR32 },
332 { BFD_RELOC_32_PCREL, R_SH_REL32 },
333 { BFD_RELOC_SH_PCDISP8BY2, R_SH_DIR8WPN },
334 { BFD_RELOC_SH_PCDISP12BY2, R_SH_IND12W },
335 { BFD_RELOC_SH_PCRELIMM8BY2, R_SH_DIR8WPZ },
336 { BFD_RELOC_SH_PCRELIMM8BY4, R_SH_DIR8WPL },
337 { BFD_RELOC_8_PCREL, R_SH_SWITCH8 },
338 { BFD_RELOC_SH_SWITCH16, R_SH_SWITCH16 },
339 { BFD_RELOC_SH_SWITCH32, R_SH_SWITCH32 },
340 { BFD_RELOC_SH_USES, R_SH_USES },
341 { BFD_RELOC_SH_COUNT, R_SH_COUNT },
342 { BFD_RELOC_SH_ALIGN, R_SH_ALIGN },
343 { BFD_RELOC_SH_CODE, R_SH_CODE },
344 { BFD_RELOC_SH_DATA, R_SH_DATA },
345 { BFD_RELOC_SH_LABEL, R_SH_LABEL },
346 { BFD_RELOC_VTABLE_INHERIT, R_SH_GNU_VTINHERIT },
347 { BFD_RELOC_VTABLE_ENTRY, R_SH_GNU_VTENTRY },
348 { BFD_RELOC_SH_LOOP_START, R_SH_LOOP_START },
349 { BFD_RELOC_SH_LOOP_END, R_SH_LOOP_END },
350 { BFD_RELOC_SH_TLS_GD_32, R_SH_TLS_GD_32 },
351 { BFD_RELOC_SH_TLS_LD_32, R_SH_TLS_LD_32 },
352 { BFD_RELOC_SH_TLS_LDO_32, R_SH_TLS_LDO_32 },
353 { BFD_RELOC_SH_TLS_IE_32, R_SH_TLS_IE_32 },
354 { BFD_RELOC_SH_TLS_LE_32, R_SH_TLS_LE_32 },
355 { BFD_RELOC_SH_TLS_DTPMOD32, R_SH_TLS_DTPMOD32 },
356 { BFD_RELOC_SH_TLS_DTPOFF32, R_SH_TLS_DTPOFF32 },
357 { BFD_RELOC_SH_TLS_TPOFF32, R_SH_TLS_TPOFF32 },
358 { BFD_RELOC_32_GOT_PCREL, R_SH_GOT32 },
359 { BFD_RELOC_32_PLT_PCREL, R_SH_PLT32 },
360 { BFD_RELOC_SH_COPY, R_SH_COPY },
361 { BFD_RELOC_SH_GLOB_DAT, R_SH_GLOB_DAT },
362 { BFD_RELOC_SH_JMP_SLOT, R_SH_JMP_SLOT },
363 { BFD_RELOC_SH_RELATIVE, R_SH_RELATIVE },
364 { BFD_RELOC_32_GOTOFF, R_SH_GOTOFF },
365 { BFD_RELOC_SH_GOTPC, R_SH_GOTPC },
366 { BFD_RELOC_SH_GOTPLT32, R_SH_GOTPLT32 },
367 { BFD_RELOC_SH_GOT20, R_SH_GOT20 },
368 { BFD_RELOC_SH_GOTOFF20, R_SH_GOTOFF20 },
369 { BFD_RELOC_SH_GOTFUNCDESC, R_SH_GOTFUNCDESC },
370 { BFD_RELOC_SH_GOTFUNCDESC20, R_SH_GOTFUNCDESC20 },
371 { BFD_RELOC_SH_GOTOFFFUNCDESC, R_SH_GOTOFFFUNCDESC },
372 { BFD_RELOC_SH_GOTOFFFUNCDESC20, R_SH_GOTOFFFUNCDESC20 },
373 { BFD_RELOC_SH_FUNCDESC, R_SH_FUNCDESC },
374 #ifdef INCLUDE_SHMEDIA
375 { BFD_RELOC_SH_GOT_LOW16, R_SH_GOT_LOW16 },
376 { BFD_RELOC_SH_GOT_MEDLOW16, R_SH_GOT_MEDLOW16 },
377 { BFD_RELOC_SH_GOT_MEDHI16, R_SH_GOT_MEDHI16 },
378 { BFD_RELOC_SH_GOT_HI16, R_SH_GOT_HI16 },
379 { BFD_RELOC_SH_GOTPLT_LOW16, R_SH_GOTPLT_LOW16 },
380 { BFD_RELOC_SH_GOTPLT_MEDLOW16, R_SH_GOTPLT_MEDLOW16 },
381 { BFD_RELOC_SH_GOTPLT_MEDHI16, R_SH_GOTPLT_MEDHI16 },
382 { BFD_RELOC_SH_GOTPLT_HI16, R_SH_GOTPLT_HI16 },
383 { BFD_RELOC_SH_PLT_LOW16, R_SH_PLT_LOW16 },
384 { BFD_RELOC_SH_PLT_MEDLOW16, R_SH_PLT_MEDLOW16 },
385 { BFD_RELOC_SH_PLT_MEDHI16, R_SH_PLT_MEDHI16 },
386 { BFD_RELOC_SH_PLT_HI16, R_SH_PLT_HI16 },
387 { BFD_RELOC_SH_GOTOFF_LOW16, R_SH_GOTOFF_LOW16 },
388 { BFD_RELOC_SH_GOTOFF_MEDLOW16, R_SH_GOTOFF_MEDLOW16 },
389 { BFD_RELOC_SH_GOTOFF_MEDHI16, R_SH_GOTOFF_MEDHI16 },
390 { BFD_RELOC_SH_GOTOFF_HI16, R_SH_GOTOFF_HI16 },
391 { BFD_RELOC_SH_GOTPC_LOW16, R_SH_GOTPC_LOW16 },
392 { BFD_RELOC_SH_GOTPC_MEDLOW16, R_SH_GOTPC_MEDLOW16 },
393 { BFD_RELOC_SH_GOTPC_MEDHI16, R_SH_GOTPC_MEDHI16 },
394 { BFD_RELOC_SH_GOTPC_HI16, R_SH_GOTPC_HI16 },
395 { BFD_RELOC_SH_COPY64, R_SH_COPY64 },
396 { BFD_RELOC_SH_GLOB_DAT64, R_SH_GLOB_DAT64 },
397 { BFD_RELOC_SH_JMP_SLOT64, R_SH_JMP_SLOT64 },
398 { BFD_RELOC_SH_RELATIVE64, R_SH_RELATIVE64 },
399 { BFD_RELOC_SH_GOT10BY4, R_SH_GOT10BY4 },
400 { BFD_RELOC_SH_GOT10BY8, R_SH_GOT10BY8 },
401 { BFD_RELOC_SH_GOTPLT10BY4, R_SH_GOTPLT10BY4 },
402 { BFD_RELOC_SH_GOTPLT10BY8, R_SH_GOTPLT10BY8 },
403 { BFD_RELOC_SH_PT_16, R_SH_PT_16 },
404 { BFD_RELOC_SH_SHMEDIA_CODE, R_SH_SHMEDIA_CODE },
405 { BFD_RELOC_SH_IMMU5, R_SH_DIR5U },
406 { BFD_RELOC_SH_IMMS6, R_SH_DIR6S },
407 { BFD_RELOC_SH_IMMU6, R_SH_DIR6U },
408 { BFD_RELOC_SH_IMMS10, R_SH_DIR10S },
409 { BFD_RELOC_SH_IMMS10BY2, R_SH_DIR10SW },
410 { BFD_RELOC_SH_IMMS10BY4, R_SH_DIR10SL },
411 { BFD_RELOC_SH_IMMS10BY8, R_SH_DIR10SQ },
412 { BFD_RELOC_SH_IMMS16, R_SH_IMMS16 },
413 { BFD_RELOC_SH_IMMU16, R_SH_IMMU16 },
414 { BFD_RELOC_SH_IMM_LOW16, R_SH_IMM_LOW16 },
415 { BFD_RELOC_SH_IMM_LOW16_PCREL, R_SH_IMM_LOW16_PCREL },
416 { BFD_RELOC_SH_IMM_MEDLOW16, R_SH_IMM_MEDLOW16 },
417 { BFD_RELOC_SH_IMM_MEDLOW16_PCREL, R_SH_IMM_MEDLOW16_PCREL },
418 { BFD_RELOC_SH_IMM_MEDHI16, R_SH_IMM_MEDHI16 },
419 { BFD_RELOC_SH_IMM_MEDHI16_PCREL, R_SH_IMM_MEDHI16_PCREL },
420 { BFD_RELOC_SH_IMM_HI16, R_SH_IMM_HI16 },
421 { BFD_RELOC_SH_IMM_HI16_PCREL, R_SH_IMM_HI16_PCREL },
422 { BFD_RELOC_64, R_SH_64 },
423 { BFD_RELOC_64_PCREL, R_SH_64_PCREL },
424 #endif /* not INCLUDE_SHMEDIA */
427 /* Given a BFD reloc code, return the howto structure for the
428 corresponding SH ELF reloc. */
430 static reloc_howto_type *
431 sh_elf_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code)
435 for (i = 0; i < sizeof (sh_reloc_map) / sizeof (struct elf_reloc_map); i++)
437 if (sh_reloc_map[i].bfd_reloc_val == code)
438 return get_howto_table (abfd) + (int) sh_reloc_map[i].elf_reloc_val;
444 static reloc_howto_type *
445 sh_elf_reloc_name_lookup (bfd *abfd, const char *r_name)
449 if (vxworks_object_p (abfd))
452 i < (sizeof (sh_vxworks_howto_table)
453 / sizeof (sh_vxworks_howto_table[0]));
455 if (sh_vxworks_howto_table[i].name != NULL
456 && strcasecmp (sh_vxworks_howto_table[i].name, r_name) == 0)
457 return &sh_vxworks_howto_table[i];
462 i < (sizeof (sh_elf_howto_table)
463 / sizeof (sh_elf_howto_table[0]));
465 if (sh_elf_howto_table[i].name != NULL
466 && strcasecmp (sh_elf_howto_table[i].name, r_name) == 0)
467 return &sh_elf_howto_table[i];
473 /* Given an ELF reloc, fill in the howto field of a relent. */
476 sh_elf_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)
480 r = ELF32_R_TYPE (dst->r_info);
483 || (r >= R_SH_FIRST_INVALID_RELOC && r <= R_SH_LAST_INVALID_RELOC)
484 || (r >= R_SH_FIRST_INVALID_RELOC_2 && r <= R_SH_LAST_INVALID_RELOC_2)
485 || (r >= R_SH_FIRST_INVALID_RELOC_3 && r <= R_SH_LAST_INVALID_RELOC_3)
486 || (r >= R_SH_FIRST_INVALID_RELOC_4 && r <= R_SH_LAST_INVALID_RELOC_4)
487 || (r >= R_SH_FIRST_INVALID_RELOC_5 && r <= R_SH_LAST_INVALID_RELOC_5)
488 || (r >= R_SH_FIRST_INVALID_RELOC_6 && r <= R_SH_LAST_INVALID_RELOC_6))
490 _bfd_error_handler (_("%B: unrecognised SH reloc number: %d"),
492 bfd_set_error (bfd_error_bad_value);
496 cache_ptr->howto = get_howto_table (abfd) + r;
499 /* This function handles relaxing for SH ELF. See the corresponding
500 function in coff-sh.c for a description of what this does. FIXME:
501 There is a lot of duplication here between this code and the COFF
502 specific code. The format of relocs and symbols is wound deeply
503 into this code, but it would still be better if the duplication
504 could be eliminated somehow. Note in particular that although both
505 functions use symbols like R_SH_CODE, those symbols have different
506 values; in coff-sh.c they come from include/coff/sh.h, whereas here
507 they come from enum elf_sh_reloc_type in include/elf/sh.h. */
510 sh_elf_relax_section (bfd *abfd, asection *sec,
511 struct bfd_link_info *link_info, bfd_boolean *again)
513 Elf_Internal_Shdr *symtab_hdr;
514 Elf_Internal_Rela *internal_relocs;
515 bfd_boolean have_code;
516 Elf_Internal_Rela *irel, *irelend;
517 bfd_byte *contents = NULL;
518 Elf_Internal_Sym *isymbuf = NULL;
522 if (bfd_link_relocatable (link_info)
523 || (sec->flags & SEC_RELOC) == 0
524 || sec->reloc_count == 0)
527 #ifdef INCLUDE_SHMEDIA
528 if (elf_section_data (sec)->this_hdr.sh_flags
529 & (SHF_SH5_ISA32 | SHF_SH5_ISA32_MIXED))
535 symtab_hdr = &elf_symtab_hdr (abfd);
537 internal_relocs = (_bfd_elf_link_read_relocs
538 (abfd, sec, NULL, (Elf_Internal_Rela *) NULL,
539 link_info->keep_memory));
540 if (internal_relocs == NULL)
545 irelend = internal_relocs + sec->reloc_count;
546 for (irel = internal_relocs; irel < irelend; irel++)
548 bfd_vma laddr, paddr, symval;
550 Elf_Internal_Rela *irelfn, *irelscan, *irelcount;
553 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_CODE)
556 if (ELF32_R_TYPE (irel->r_info) != (int) R_SH_USES)
559 /* Get the section contents. */
560 if (contents == NULL)
562 if (elf_section_data (sec)->this_hdr.contents != NULL)
563 contents = elf_section_data (sec)->this_hdr.contents;
566 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
571 /* The r_addend field of the R_SH_USES reloc will point us to
572 the register load. The 4 is because the r_addend field is
573 computed as though it were a jump offset, which are based
574 from 4 bytes after the jump instruction. */
575 laddr = irel->r_offset + 4 + irel->r_addend;
576 if (laddr >= sec->size)
578 _bfd_error_handler (_("%B: 0x%lx: warning: bad R_SH_USES offset"),
579 abfd, (unsigned long) irel->r_offset);
582 insn = bfd_get_16 (abfd, contents + laddr);
584 /* If the instruction is not mov.l NN,rN, we don't know what to
586 if ((insn & 0xf000) != 0xd000)
589 (_("%B: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x"),
590 abfd, (unsigned long) irel->r_offset, insn);
594 /* Get the address from which the register is being loaded. The
595 displacement in the mov.l instruction is quadrupled. It is a
596 displacement from four bytes after the movl instruction, but,
597 before adding in the PC address, two least significant bits
598 of the PC are cleared. We assume that the section is aligned
599 on a four byte boundary. */
602 paddr += (laddr + 4) &~ (bfd_vma) 3;
603 if (paddr >= sec->size)
606 (_("%B: 0x%lx: warning: bad R_SH_USES load offset"),
607 abfd, (unsigned long) irel->r_offset);
611 /* Get the reloc for the address from which the register is
612 being loaded. This reloc will tell us which function is
613 actually being called. */
614 for (irelfn = internal_relocs; irelfn < irelend; irelfn++)
615 if (irelfn->r_offset == paddr
616 && ELF32_R_TYPE (irelfn->r_info) == (int) R_SH_DIR32)
618 if (irelfn >= irelend)
621 (_("%B: 0x%lx: warning: could not find expected reloc"),
622 abfd, (unsigned long) paddr);
626 /* Read this BFD's symbols if we haven't done so already. */
627 if (isymbuf == NULL && symtab_hdr->sh_info != 0)
629 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
631 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
632 symtab_hdr->sh_info, 0,
638 /* Get the value of the symbol referred to by the reloc. */
639 if (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
641 /* A local symbol. */
642 Elf_Internal_Sym *isym;
644 isym = isymbuf + ELF32_R_SYM (irelfn->r_info);
646 != (unsigned int) _bfd_elf_section_from_bfd_section (abfd, sec))
649 (_("%B: 0x%lx: warning: symbol in unexpected section"),
650 abfd, (unsigned long) paddr);
654 symval = (isym->st_value
655 + sec->output_section->vma
656 + sec->output_offset);
661 struct elf_link_hash_entry *h;
663 indx = ELF32_R_SYM (irelfn->r_info) - symtab_hdr->sh_info;
664 h = elf_sym_hashes (abfd)[indx];
665 BFD_ASSERT (h != NULL);
666 if (h->root.type != bfd_link_hash_defined
667 && h->root.type != bfd_link_hash_defweak)
669 /* This appears to be a reference to an undefined
670 symbol. Just ignore it--it will be caught by the
671 regular reloc processing. */
675 symval = (h->root.u.def.value
676 + h->root.u.def.section->output_section->vma
677 + h->root.u.def.section->output_offset);
680 if (get_howto_table (abfd)[R_SH_DIR32].partial_inplace)
681 symval += bfd_get_32 (abfd, contents + paddr);
683 symval += irelfn->r_addend;
685 /* See if this function call can be shortened. */
688 + sec->output_section->vma
691 /* A branch to an address beyond ours might be increased by an
692 .align that doesn't move when bytes behind us are deleted.
693 So, we add some slop in this calculation to allow for
695 if (foff < -0x1000 || foff >= 0x1000 - 8)
697 /* After all that work, we can't shorten this function call. */
701 /* Shorten the function call. */
703 /* For simplicity of coding, we are going to modify the section
704 contents, the section relocs, and the BFD symbol table. We
705 must tell the rest of the code not to free up this
706 information. It would be possible to instead create a table
707 of changes which have to be made, as is done in coff-mips.c;
708 that would be more work, but would require less memory when
709 the linker is run. */
711 elf_section_data (sec)->relocs = internal_relocs;
712 elf_section_data (sec)->this_hdr.contents = contents;
713 symtab_hdr->contents = (unsigned char *) isymbuf;
715 /* Replace the jmp/jsr with a bra/bsr. */
717 /* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and
718 replace the jmp/jsr with a bra/bsr. */
719 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irelfn->r_info), R_SH_IND12W);
720 /* We used to test (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
721 here, but that only checks if the symbol is an external symbol,
722 not if the symbol is in a different section. Besides, we need
723 a consistent meaning for the relocation, so we just assume here that
724 the value of the symbol is not available. */
726 /* We can't fully resolve this yet, because the external
727 symbol value may be changed by future relaxing. We let
728 the final link phase handle it. */
729 if (bfd_get_16 (abfd, contents + irel->r_offset) & 0x0020)
730 bfd_put_16 (abfd, (bfd_vma) 0xa000, contents + irel->r_offset);
732 bfd_put_16 (abfd, (bfd_vma) 0xb000, contents + irel->r_offset);
736 /* When we calculated the symbol "value" we had an offset in the
737 DIR32's word in memory (we read and add it above). However,
738 the jsr we create does NOT have this offset encoded, so we
739 have to add it to the addend to preserve it. */
740 irel->r_addend += bfd_get_32 (abfd, contents + paddr);
742 /* See if there is another R_SH_USES reloc referring to the same
744 for (irelscan = internal_relocs; irelscan < irelend; irelscan++)
745 if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_USES
746 && laddr == irelscan->r_offset + 4 + irelscan->r_addend)
748 if (irelscan < irelend)
750 /* Some other function call depends upon this register load,
751 and we have not yet converted that function call.
752 Indeed, we may never be able to convert it. There is
753 nothing else we can do at this point. */
757 /* Look for a R_SH_COUNT reloc on the location where the
758 function address is stored. Do this before deleting any
759 bytes, to avoid confusion about the address. */
760 for (irelcount = internal_relocs; irelcount < irelend; irelcount++)
761 if (irelcount->r_offset == paddr
762 && ELF32_R_TYPE (irelcount->r_info) == (int) R_SH_COUNT)
765 /* Delete the register load. */
766 if (! sh_elf_relax_delete_bytes (abfd, sec, laddr, 2))
769 /* That will change things, so, just in case it permits some
770 other function call to come within range, we should relax
771 again. Note that this is not required, and it may be slow. */
774 /* Now check whether we got a COUNT reloc. */
775 if (irelcount >= irelend)
778 (_("%B: 0x%lx: warning: could not find expected COUNT reloc"),
779 abfd, (unsigned long) paddr);
783 /* The number of uses is stored in the r_addend field. We've
785 if (irelcount->r_addend == 0)
787 _bfd_error_handler (_("%B: 0x%lx: warning: bad count"),
788 abfd, (unsigned long) paddr);
792 --irelcount->r_addend;
794 /* If there are no more uses, we can delete the address. Reload
795 the address from irelfn, in case it was changed by the
796 previous call to sh_elf_relax_delete_bytes. */
797 if (irelcount->r_addend == 0)
799 if (! sh_elf_relax_delete_bytes (abfd, sec, irelfn->r_offset, 4))
803 /* We've done all we can with that function call. */
806 /* Look for load and store instructions that we can align on four
808 if ((elf_elfheader (abfd)->e_flags & EF_SH_MACH_MASK) != EF_SH4
813 /* Get the section contents. */
814 if (contents == NULL)
816 if (elf_section_data (sec)->this_hdr.contents != NULL)
817 contents = elf_section_data (sec)->this_hdr.contents;
820 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
825 if (! sh_elf_align_loads (abfd, sec, internal_relocs, contents,
831 elf_section_data (sec)->relocs = internal_relocs;
832 elf_section_data (sec)->this_hdr.contents = contents;
833 symtab_hdr->contents = (unsigned char *) isymbuf;
838 && symtab_hdr->contents != (unsigned char *) isymbuf)
840 if (! link_info->keep_memory)
844 /* Cache the symbols for elf_link_input_bfd. */
845 symtab_hdr->contents = (unsigned char *) isymbuf;
850 && elf_section_data (sec)->this_hdr.contents != contents)
852 if (! link_info->keep_memory)
856 /* Cache the section contents for elf_link_input_bfd. */
857 elf_section_data (sec)->this_hdr.contents = contents;
861 if (internal_relocs != NULL
862 && elf_section_data (sec)->relocs != internal_relocs)
863 free (internal_relocs);
869 && symtab_hdr->contents != (unsigned char *) isymbuf)
872 && elf_section_data (sec)->this_hdr.contents != contents)
874 if (internal_relocs != NULL
875 && elf_section_data (sec)->relocs != internal_relocs)
876 free (internal_relocs);
881 /* Delete some bytes from a section while relaxing. FIXME: There is a
882 lot of duplication between this function and sh_relax_delete_bytes
886 sh_elf_relax_delete_bytes (bfd *abfd, asection *sec, bfd_vma addr,
889 Elf_Internal_Shdr *symtab_hdr;
890 unsigned int sec_shndx;
892 Elf_Internal_Rela *irel, *irelend;
893 Elf_Internal_Rela *irelalign;
895 Elf_Internal_Sym *isymbuf, *isym, *isymend;
896 struct elf_link_hash_entry **sym_hashes;
897 struct elf_link_hash_entry **end_hashes;
898 unsigned int symcount;
901 symtab_hdr = &elf_symtab_hdr (abfd);
902 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
904 sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
906 contents = elf_section_data (sec)->this_hdr.contents;
908 /* The deletion must stop at the next ALIGN reloc for an aligment
909 power larger than the number of bytes we are deleting. */
914 irel = elf_section_data (sec)->relocs;
915 irelend = irel + sec->reloc_count;
916 for (; irel < irelend; irel++)
918 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_ALIGN
919 && irel->r_offset > addr
920 && count < (1 << irel->r_addend))
923 toaddr = irel->r_offset;
928 /* Actually delete the bytes. */
929 memmove (contents + addr, contents + addr + count,
930 (size_t) (toaddr - addr - count));
931 if (irelalign == NULL)
937 #define NOP_OPCODE (0x0009)
939 BFD_ASSERT ((count & 1) == 0);
940 for (i = 0; i < count; i += 2)
941 bfd_put_16 (abfd, (bfd_vma) NOP_OPCODE, contents + toaddr - count + i);
944 /* Adjust all the relocs. */
945 for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)
947 bfd_vma nraddr, stop;
950 int off, adjust, oinsn;
951 bfd_signed_vma voff = 0;
952 bfd_boolean overflow;
954 /* Get the new reloc address. */
955 nraddr = irel->r_offset;
956 if ((irel->r_offset > addr
957 && irel->r_offset < toaddr)
958 || (ELF32_R_TYPE (irel->r_info) == (int) R_SH_ALIGN
959 && irel->r_offset == toaddr))
962 /* See if this reloc was for the bytes we have deleted, in which
963 case we no longer care about it. Don't delete relocs which
964 represent addresses, though. */
965 if (irel->r_offset >= addr
966 && irel->r_offset < addr + count
967 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_ALIGN
968 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_CODE
969 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_DATA
970 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_LABEL)
971 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
974 /* If this is a PC relative reloc, see if the range it covers
975 includes the bytes we have deleted. */
976 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
985 start = irel->r_offset;
986 insn = bfd_get_16 (abfd, contents + nraddr);
990 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
997 /* If this reloc is against a symbol defined in this
998 section, and the symbol will not be adjusted below, we
999 must check the addend to see it will put the value in
1000 range to be adjusted, and hence must be changed. */
1001 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
1003 isym = isymbuf + ELF32_R_SYM (irel->r_info);
1004 if (isym->st_shndx == sec_shndx
1005 && (isym->st_value <= addr
1006 || isym->st_value >= toaddr))
1010 if (get_howto_table (abfd)[R_SH_DIR32].partial_inplace)
1012 val = bfd_get_32 (abfd, contents + nraddr);
1013 val += isym->st_value;
1014 if (val > addr && val < toaddr)
1015 bfd_put_32 (abfd, val - count, contents + nraddr);
1019 val = isym->st_value + irel->r_addend;
1020 if (val > addr && val < toaddr)
1021 irel->r_addend -= count;
1025 start = stop = addr;
1032 stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
1039 /* This has been made by previous relaxation. Since the
1040 relocation will be against an external symbol, the
1041 final relocation will just do the right thing. */
1042 start = stop = addr;
1048 stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
1050 /* The addend will be against the section symbol, thus
1051 for adjusting the addend, the relevant start is the
1052 start of the section.
1053 N.B. If we want to abandon in-place changes here and
1054 test directly using symbol + addend, we have to take into
1055 account that the addend has already been adjusted by -4. */
1056 if (stop > addr && stop < toaddr)
1057 irel->r_addend -= count;
1063 stop = start + 4 + off * 2;
1068 stop = (start & ~(bfd_vma) 3) + 4 + off * 4;
1074 /* These relocs types represent
1076 The r_addend field holds the difference between the reloc
1077 address and L1. That is the start of the reloc, and
1078 adding in the contents gives us the top. We must adjust
1079 both the r_offset field and the section contents.
1080 N.B. in gas / coff bfd, the elf bfd r_addend is called r_offset,
1081 and the elf bfd r_offset is called r_vaddr. */
1083 stop = irel->r_offset;
1084 start = (bfd_vma) ((bfd_signed_vma) stop - (long) irel->r_addend);
1088 && (stop <= addr || stop >= toaddr))
1089 irel->r_addend += count;
1090 else if (stop > addr
1092 && (start <= addr || start >= toaddr))
1093 irel->r_addend -= count;
1095 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_SWITCH16)
1096 voff = bfd_get_signed_16 (abfd, contents + nraddr);
1097 else if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_SWITCH8)
1098 voff = bfd_get_8 (abfd, contents + nraddr);
1100 voff = bfd_get_signed_32 (abfd, contents + nraddr);
1101 stop = (bfd_vma) ((bfd_signed_vma) start + voff);
1106 start = irel->r_offset;
1107 stop = (bfd_vma) ((bfd_signed_vma) start
1108 + (long) irel->r_addend
1115 && (stop <= addr || stop >= toaddr))
1117 else if (stop > addr
1119 && (start <= addr || start >= toaddr))
1128 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
1137 if ((oinsn & 0xff00) != (insn & 0xff00))
1139 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
1144 if ((oinsn & 0xf000) != (insn & 0xf000))
1146 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
1150 BFD_ASSERT (adjust == count || count >= 4);
1155 if ((irel->r_offset & 3) == 0)
1158 if ((oinsn & 0xff00) != (insn & 0xff00))
1160 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
1165 if (voff < 0 || voff >= 0xff)
1167 bfd_put_8 (abfd, voff, contents + nraddr);
1172 if (voff < - 0x8000 || voff >= 0x8000)
1174 bfd_put_signed_16 (abfd, (bfd_vma) voff, contents + nraddr);
1179 bfd_put_signed_32 (abfd, (bfd_vma) voff, contents + nraddr);
1183 irel->r_addend += adjust;
1190 (_("%B: 0x%lx: fatal: reloc overflow while relaxing"),
1191 abfd, (unsigned long) irel->r_offset);
1192 bfd_set_error (bfd_error_bad_value);
1197 irel->r_offset = nraddr;
1200 /* Look through all the other sections. If there contain any IMM32
1201 relocs against internal symbols which we are not going to adjust
1202 below, we may need to adjust the addends. */
1203 for (o = abfd->sections; o != NULL; o = o->next)
1205 Elf_Internal_Rela *internal_relocs;
1206 Elf_Internal_Rela *irelscan, *irelscanend;
1207 bfd_byte *ocontents;
1210 || (o->flags & SEC_RELOC) == 0
1211 || o->reloc_count == 0)
1214 /* We always cache the relocs. Perhaps, if info->keep_memory is
1215 FALSE, we should free them, if we are permitted to, when we
1216 leave sh_coff_relax_section. */
1217 internal_relocs = (_bfd_elf_link_read_relocs
1218 (abfd, o, NULL, (Elf_Internal_Rela *) NULL, TRUE));
1219 if (internal_relocs == NULL)
1223 irelscanend = internal_relocs + o->reloc_count;
1224 for (irelscan = internal_relocs; irelscan < irelscanend; irelscan++)
1226 /* Dwarf line numbers use R_SH_SWITCH32 relocs. */
1227 if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_SWITCH32)
1229 bfd_vma start, stop;
1230 bfd_signed_vma voff;
1232 if (ocontents == NULL)
1234 if (elf_section_data (o)->this_hdr.contents != NULL)
1235 ocontents = elf_section_data (o)->this_hdr.contents;
1238 /* We always cache the section contents.
1239 Perhaps, if info->keep_memory is FALSE, we
1240 should free them, if we are permitted to,
1241 when we leave sh_coff_relax_section. */
1242 if (!bfd_malloc_and_get_section (abfd, o, &ocontents))
1244 if (ocontents != NULL)
1249 elf_section_data (o)->this_hdr.contents = ocontents;
1253 stop = irelscan->r_offset;
1255 = (bfd_vma) ((bfd_signed_vma) stop - (long) irelscan->r_addend);
1257 /* STOP is in a different section, so it won't change. */
1258 if (start > addr && start < toaddr)
1259 irelscan->r_addend += count;
1261 voff = bfd_get_signed_32 (abfd, ocontents + irelscan->r_offset);
1262 stop = (bfd_vma) ((bfd_signed_vma) start + voff);
1266 && (stop <= addr || stop >= toaddr))
1267 bfd_put_signed_32 (abfd, (bfd_vma) voff + count,
1268 ocontents + irelscan->r_offset);
1269 else if (stop > addr
1271 && (start <= addr || start >= toaddr))
1272 bfd_put_signed_32 (abfd, (bfd_vma) voff - count,
1273 ocontents + irelscan->r_offset);
1276 if (ELF32_R_TYPE (irelscan->r_info) != (int) R_SH_DIR32)
1279 if (ELF32_R_SYM (irelscan->r_info) >= symtab_hdr->sh_info)
1283 isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
1284 if (isym->st_shndx == sec_shndx
1285 && (isym->st_value <= addr
1286 || isym->st_value >= toaddr))
1290 if (ocontents == NULL)
1292 if (elf_section_data (o)->this_hdr.contents != NULL)
1293 ocontents = elf_section_data (o)->this_hdr.contents;
1296 /* We always cache the section contents.
1297 Perhaps, if info->keep_memory is FALSE, we
1298 should free them, if we are permitted to,
1299 when we leave sh_coff_relax_section. */
1300 if (!bfd_malloc_and_get_section (abfd, o, &ocontents))
1302 if (ocontents != NULL)
1307 elf_section_data (o)->this_hdr.contents = ocontents;
1311 val = bfd_get_32 (abfd, ocontents + irelscan->r_offset);
1312 val += isym->st_value;
1313 if (val > addr && val < toaddr)
1314 bfd_put_32 (abfd, val - count,
1315 ocontents + irelscan->r_offset);
1320 /* Adjust the local symbols defined in this section. */
1321 isymend = isymbuf + symtab_hdr->sh_info;
1322 for (isym = isymbuf; isym < isymend; isym++)
1324 if (isym->st_shndx == sec_shndx
1325 && isym->st_value > addr
1326 && isym->st_value < toaddr)
1327 isym->st_value -= count;
1330 /* Now adjust the global symbols defined in this section. */
1331 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
1332 - symtab_hdr->sh_info);
1333 sym_hashes = elf_sym_hashes (abfd);
1334 end_hashes = sym_hashes + symcount;
1335 for (; sym_hashes < end_hashes; sym_hashes++)
1337 struct elf_link_hash_entry *sym_hash = *sym_hashes;
1338 if ((sym_hash->root.type == bfd_link_hash_defined
1339 || sym_hash->root.type == bfd_link_hash_defweak)
1340 && sym_hash->root.u.def.section == sec
1341 && sym_hash->root.u.def.value > addr
1342 && sym_hash->root.u.def.value < toaddr)
1344 sym_hash->root.u.def.value -= count;
1348 /* See if we can move the ALIGN reloc forward. We have adjusted
1349 r_offset for it already. */
1350 if (irelalign != NULL)
1352 bfd_vma alignto, alignaddr;
1354 alignto = BFD_ALIGN (toaddr, 1 << irelalign->r_addend);
1355 alignaddr = BFD_ALIGN (irelalign->r_offset,
1356 1 << irelalign->r_addend);
1357 if (alignto != alignaddr)
1359 /* Tail recursion. */
1360 return sh_elf_relax_delete_bytes (abfd, sec, alignaddr,
1361 (int) (alignto - alignaddr));
1368 /* Look for loads and stores which we can align to four byte
1369 boundaries. This is like sh_align_loads in coff-sh.c. */
1372 sh_elf_align_loads (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
1373 Elf_Internal_Rela *internal_relocs,
1374 bfd_byte *contents ATTRIBUTE_UNUSED,
1375 bfd_boolean *pswapped)
1377 Elf_Internal_Rela *irel, *irelend;
1378 bfd_vma *labels = NULL;
1379 bfd_vma *label, *label_end;
1384 irelend = internal_relocs + sec->reloc_count;
1386 /* Get all the addresses with labels on them. */
1387 amt = sec->reloc_count;
1388 amt *= sizeof (bfd_vma);
1389 labels = (bfd_vma *) bfd_malloc (amt);
1393 for (irel = internal_relocs; irel < irelend; irel++)
1395 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_LABEL)
1397 *label_end = irel->r_offset;
1402 /* Note that the assembler currently always outputs relocs in
1403 address order. If that ever changes, this code will need to sort
1404 the label values and the relocs. */
1408 for (irel = internal_relocs; irel < irelend; irel++)
1410 bfd_vma start, stop;
1412 if (ELF32_R_TYPE (irel->r_info) != (int) R_SH_CODE)
1415 start = irel->r_offset;
1417 for (irel++; irel < irelend; irel++)
1418 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_DATA)
1421 stop = irel->r_offset;
1425 if (! _bfd_sh_align_load_span (abfd, sec, contents, sh_elf_swap_insns,
1426 internal_relocs, &label,
1427 label_end, start, stop, pswapped))
1442 /* Swap two SH instructions. This is like sh_swap_insns in coff-sh.c. */
1445 sh_elf_swap_insns (bfd *abfd, asection *sec, void *relocs,
1446 bfd_byte *contents, bfd_vma addr)
1448 Elf_Internal_Rela *internal_relocs = (Elf_Internal_Rela *) relocs;
1449 unsigned short i1, i2;
1450 Elf_Internal_Rela *irel, *irelend;
1452 /* Swap the instructions themselves. */
1453 i1 = bfd_get_16 (abfd, contents + addr);
1454 i2 = bfd_get_16 (abfd, contents + addr + 2);
1455 bfd_put_16 (abfd, (bfd_vma) i2, contents + addr);
1456 bfd_put_16 (abfd, (bfd_vma) i1, contents + addr + 2);
1458 /* Adjust all reloc addresses. */
1459 irelend = internal_relocs + sec->reloc_count;
1460 for (irel = internal_relocs; irel < irelend; irel++)
1462 enum elf_sh_reloc_type type;
1465 /* There are a few special types of relocs that we don't want to
1466 adjust. These relocs do not apply to the instruction itself,
1467 but are only associated with the address. */
1468 type = (enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info);
1469 if (type == R_SH_ALIGN
1470 || type == R_SH_CODE
1471 || type == R_SH_DATA
1472 || type == R_SH_LABEL)
1475 /* If an R_SH_USES reloc points to one of the addresses being
1476 swapped, we must adjust it. It would be incorrect to do this
1477 for a jump, though, since we want to execute both
1478 instructions after the jump. (We have avoided swapping
1479 around a label, so the jump will not wind up executing an
1480 instruction it shouldn't). */
1481 if (type == R_SH_USES)
1485 off = irel->r_offset + 4 + irel->r_addend;
1487 irel->r_offset += 2;
1488 else if (off == addr + 2)
1489 irel->r_offset -= 2;
1492 if (irel->r_offset == addr)
1494 irel->r_offset += 2;
1497 else if (irel->r_offset == addr + 2)
1499 irel->r_offset -= 2;
1508 unsigned short insn, oinsn;
1509 bfd_boolean overflow;
1511 loc = contents + irel->r_offset;
1520 insn = bfd_get_16 (abfd, loc);
1523 if ((oinsn & 0xff00) != (insn & 0xff00))
1525 bfd_put_16 (abfd, (bfd_vma) insn, loc);
1529 insn = bfd_get_16 (abfd, loc);
1532 if ((oinsn & 0xf000) != (insn & 0xf000))
1534 bfd_put_16 (abfd, (bfd_vma) insn, loc);
1538 /* This reloc ignores the least significant 3 bits of
1539 the program counter before adding in the offset.
1540 This means that if ADDR is at an even address, the
1541 swap will not affect the offset. If ADDR is an at an
1542 odd address, then the instruction will be crossing a
1543 four byte boundary, and must be adjusted. */
1544 if ((addr & 3) != 0)
1546 insn = bfd_get_16 (abfd, loc);
1549 if ((oinsn & 0xff00) != (insn & 0xff00))
1551 bfd_put_16 (abfd, (bfd_vma) insn, loc);
1560 (_("%B: 0x%lx: fatal: reloc overflow while relaxing"),
1561 abfd, (unsigned long) irel->r_offset);
1562 bfd_set_error (bfd_error_bad_value);
1570 #endif /* defined SH64_ELF */
1572 /* Describes one of the various PLT styles. */
1574 struct elf_sh_plt_info
1576 /* The template for the first PLT entry, or NULL if there is no special
1578 const bfd_byte *plt0_entry;
1580 /* The size of PLT0_ENTRY in bytes, or 0 if PLT0_ENTRY is NULL. */
1581 bfd_vma plt0_entry_size;
1583 /* Index I is the offset into PLT0_ENTRY of a pointer to
1584 _GLOBAL_OFFSET_TABLE_ + I * 4. The value is MINUS_ONE
1585 if there is no such pointer. */
1586 bfd_vma plt0_got_fields[3];
1588 /* The template for a symbol's PLT entry. */
1589 const bfd_byte *symbol_entry;
1591 /* The size of SYMBOL_ENTRY in bytes. */
1592 bfd_vma symbol_entry_size;
1594 /* Byte offsets of fields in SYMBOL_ENTRY. Not all fields are used
1595 on all targets. The comments by each member indicate the value
1596 that the field must hold. */
1598 bfd_vma got_entry; /* the address of the symbol's .got.plt entry */
1599 bfd_vma plt; /* .plt (or a branch to .plt on VxWorks) */
1600 bfd_vma reloc_offset; /* the offset of the symbol's JMP_SLOT reloc */
1601 bfd_boolean got20; /* TRUE if got_entry points to a movi20
1602 instruction (instead of a constant pool
1606 /* The offset of the resolver stub from the start of SYMBOL_ENTRY. */
1607 bfd_vma symbol_resolve_offset;
1609 /* A different PLT layout which can be used for the first
1610 MAX_SHORT_PLT entries. It must share the same plt0. NULL in
1612 const struct elf_sh_plt_info *short_plt;
1615 #ifdef INCLUDE_SHMEDIA
1617 /* The size in bytes of an entry in the procedure linkage table. */
1619 #define ELF_PLT_ENTRY_SIZE 64
1621 /* First entry in an absolute procedure linkage table look like this. */
1623 static const bfd_byte elf_sh_plt0_entry_be[ELF_PLT_ENTRY_SIZE] =
1625 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 16, r17 */
1626 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
1627 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
1628 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
1629 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
1630 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
1631 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1632 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1633 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1634 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1635 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1636 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1637 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1638 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1639 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1640 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1643 static const bfd_byte elf_sh_plt0_entry_le[ELF_PLT_ENTRY_SIZE] =
1645 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */
1646 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
1647 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
1648 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
1649 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
1650 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
1651 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1652 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1653 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1654 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1655 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1656 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1657 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1658 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1659 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1660 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1663 /* Sebsequent entries in an absolute procedure linkage table look like
1666 static const bfd_byte elf_sh_plt_entry_be[ELF_PLT_ENTRY_SIZE] =
1668 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 16, r25 */
1669 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
1670 0x89, 0x90, 0x01, 0x90, /* ld.l r25, 0, r25 */
1671 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
1672 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
1673 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1674 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1675 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1676 0xcc, 0x00, 0x01, 0x90, /* movi .PLT0 >> 16, r25 */
1677 0xc8, 0x00, 0x01, 0x90, /* shori .PLT0 & 65535, r25 */
1678 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
1679 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
1680 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
1681 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
1682 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1683 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1686 static const bfd_byte elf_sh_plt_entry_le[ELF_PLT_ENTRY_SIZE] =
1688 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */
1689 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
1690 0x90, 0x01, 0x90, 0x89, /* ld.l r25, 0, r25 */
1691 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
1692 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
1693 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1694 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1695 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1696 0x90, 0x01, 0x00, 0xcc, /* movi .PLT0 >> 16, r25 */
1697 0x90, 0x01, 0x00, 0xc8, /* shori .PLT0 & 65535, r25 */
1698 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
1699 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
1700 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
1701 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
1702 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1703 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1706 /* Entries in a PIC procedure linkage table look like this. */
1708 static const bfd_byte elf_sh_pic_plt_entry_be[ELF_PLT_ENTRY_SIZE] =
1710 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */
1711 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
1712 0x40, 0xc2, 0x65, 0x90, /* ldx.l r12, r25, r25 */
1713 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
1714 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
1715 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1716 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1717 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1718 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */
1719 0x00, 0xc8, 0x45, 0x10, /* add.l r12, r17, r17 */
1720 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
1721 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
1722 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
1723 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
1724 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
1725 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
1728 static const bfd_byte elf_sh_pic_plt_entry_le[ELF_PLT_ENTRY_SIZE] =
1730 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */
1731 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
1732 0x90, 0x65, 0xc2, 0x40, /* ldx.l r12, r25, r25 */
1733 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
1734 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
1735 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1736 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1737 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1738 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */
1739 0x10, 0x45, 0xc8, 0x00, /* add.l r12, r17, r17 */
1740 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
1741 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
1742 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
1743 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
1744 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
1745 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
1748 static const struct elf_sh_plt_info elf_sh_plts[2][2] = {
1751 /* Big-endian non-PIC. */
1752 elf_sh_plt0_entry_be,
1754 { 0, MINUS_ONE, MINUS_ONE },
1755 elf_sh_plt_entry_be,
1757 { 0, 32, 48, FALSE },
1758 33, /* includes ISA encoding */
1762 /* Little-endian non-PIC. */
1763 elf_sh_plt0_entry_le,
1765 { 0, MINUS_ONE, MINUS_ONE },
1766 elf_sh_plt_entry_le,
1768 { 0, 32, 48, FALSE },
1769 33, /* includes ISA encoding */
1775 /* Big-endian PIC. */
1776 elf_sh_plt0_entry_be,
1778 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
1779 elf_sh_pic_plt_entry_be,
1781 { 0, MINUS_ONE, 52, FALSE },
1782 33, /* includes ISA encoding */
1786 /* Little-endian PIC. */
1787 elf_sh_plt0_entry_le,
1789 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
1790 elf_sh_pic_plt_entry_le,
1792 { 0, MINUS_ONE, 52, FALSE },
1793 33, /* includes ISA encoding */
1799 /* Return offset of the linker in PLT0 entry. */
1800 #define elf_sh_plt0_gotplt_offset(info) 0
1802 /* Install a 32-bit PLT field starting at ADDR, which occurs in OUTPUT_BFD.
1803 VALUE is the field's value and CODE_P is true if VALUE refers to code,
1806 On SH64, each 32-bit field is loaded by a movi/shori pair. */
1809 install_plt_field (bfd *output_bfd, bfd_boolean code_p,
1810 unsigned long value, bfd_byte *addr)
1813 bfd_put_32 (output_bfd,
1814 bfd_get_32 (output_bfd, addr)
1815 | ((value >> 6) & 0x3fffc00),
1817 bfd_put_32 (output_bfd,
1818 bfd_get_32 (output_bfd, addr + 4)
1819 | ((value << 10) & 0x3fffc00),
1823 /* Return the type of PLT associated with ABFD. PIC_P is true if
1824 the object is position-independent. */
1826 static const struct elf_sh_plt_info *
1827 get_plt_info (bfd *abfd ATTRIBUTE_UNUSED, bfd_boolean pic_p)
1829 return &elf_sh_plts[pic_p][!bfd_big_endian (abfd)];
1832 /* The size in bytes of an entry in the procedure linkage table. */
1834 #define ELF_PLT_ENTRY_SIZE 28
1836 /* First entry in an absolute procedure linkage table look like this. */
1838 /* Note - this code has been "optimised" not to use r2. r2 is used by
1839 GCC to return the address of large structures, so it should not be
1840 corrupted here. This does mean however, that this PLT does not conform
1841 to the SH PIC ABI. That spec says that r0 contains the type of the PLT
1842 and r2 contains the GOT id. This version stores the GOT id in r0 and
1843 ignores the type. Loaders can easily detect this difference however,
1844 since the type will always be 0 or 8, and the GOT ids will always be
1845 greater than or equal to 12. */
1846 static const bfd_byte elf_sh_plt0_entry_be[ELF_PLT_ENTRY_SIZE] =
1848 0xd0, 0x05, /* mov.l 2f,r0 */
1849 0x60, 0x02, /* mov.l @r0,r0 */
1850 0x2f, 0x06, /* mov.l r0,@-r15 */
1851 0xd0, 0x03, /* mov.l 1f,r0 */
1852 0x60, 0x02, /* mov.l @r0,r0 */
1853 0x40, 0x2b, /* jmp @r0 */
1854 0x60, 0xf6, /* mov.l @r15+,r0 */
1855 0x00, 0x09, /* nop */
1856 0x00, 0x09, /* nop */
1857 0x00, 0x09, /* nop */
1858 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
1859 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
1862 static const bfd_byte elf_sh_plt0_entry_le[ELF_PLT_ENTRY_SIZE] =
1864 0x05, 0xd0, /* mov.l 2f,r0 */
1865 0x02, 0x60, /* mov.l @r0,r0 */
1866 0x06, 0x2f, /* mov.l r0,@-r15 */
1867 0x03, 0xd0, /* mov.l 1f,r0 */
1868 0x02, 0x60, /* mov.l @r0,r0 */
1869 0x2b, 0x40, /* jmp @r0 */
1870 0xf6, 0x60, /* mov.l @r15+,r0 */
1871 0x09, 0x00, /* nop */
1872 0x09, 0x00, /* nop */
1873 0x09, 0x00, /* nop */
1874 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
1875 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
1878 /* Sebsequent entries in an absolute procedure linkage table look like
1881 static const bfd_byte elf_sh_plt_entry_be[ELF_PLT_ENTRY_SIZE] =
1883 0xd0, 0x04, /* mov.l 1f,r0 */
1884 0x60, 0x02, /* mov.l @(r0,r12),r0 */
1885 0xd1, 0x02, /* mov.l 0f,r1 */
1886 0x40, 0x2b, /* jmp @r0 */
1887 0x60, 0x13, /* mov r1,r0 */
1888 0xd1, 0x03, /* mov.l 2f,r1 */
1889 0x40, 0x2b, /* jmp @r0 */
1890 0x00, 0x09, /* nop */
1891 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
1892 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
1893 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
1896 static const bfd_byte elf_sh_plt_entry_le[ELF_PLT_ENTRY_SIZE] =
1898 0x04, 0xd0, /* mov.l 1f,r0 */
1899 0x02, 0x60, /* mov.l @r0,r0 */
1900 0x02, 0xd1, /* mov.l 0f,r1 */
1901 0x2b, 0x40, /* jmp @r0 */
1902 0x13, 0x60, /* mov r1,r0 */
1903 0x03, 0xd1, /* mov.l 2f,r1 */
1904 0x2b, 0x40, /* jmp @r0 */
1905 0x09, 0x00, /* nop */
1906 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
1907 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
1908 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
1911 /* Entries in a PIC procedure linkage table look like this. */
1913 static const bfd_byte elf_sh_pic_plt_entry_be[ELF_PLT_ENTRY_SIZE] =
1915 0xd0, 0x04, /* mov.l 1f,r0 */
1916 0x00, 0xce, /* mov.l @(r0,r12),r0 */
1917 0x40, 0x2b, /* jmp @r0 */
1918 0x00, 0x09, /* nop */
1919 0x50, 0xc2, /* mov.l @(8,r12),r0 */
1920 0xd1, 0x03, /* mov.l 2f,r1 */
1921 0x40, 0x2b, /* jmp @r0 */
1922 0x50, 0xc1, /* mov.l @(4,r12),r0 */
1923 0x00, 0x09, /* nop */
1924 0x00, 0x09, /* nop */
1925 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
1926 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
1929 static const bfd_byte elf_sh_pic_plt_entry_le[ELF_PLT_ENTRY_SIZE] =
1931 0x04, 0xd0, /* mov.l 1f,r0 */
1932 0xce, 0x00, /* mov.l @(r0,r12),r0 */
1933 0x2b, 0x40, /* jmp @r0 */
1934 0x09, 0x00, /* nop */
1935 0xc2, 0x50, /* mov.l @(8,r12),r0 */
1936 0x03, 0xd1, /* mov.l 2f,r1 */
1937 0x2b, 0x40, /* jmp @r0 */
1938 0xc1, 0x50, /* mov.l @(4,r12),r0 */
1939 0x09, 0x00, /* nop */
1940 0x09, 0x00, /* nop */
1941 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
1942 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
1945 static const struct elf_sh_plt_info elf_sh_plts[2][2] = {
1948 /* Big-endian non-PIC. */
1949 elf_sh_plt0_entry_be,
1951 { MINUS_ONE, 24, 20 },
1952 elf_sh_plt_entry_be,
1954 { 20, 16, 24, FALSE },
1959 /* Little-endian non-PIC. */
1960 elf_sh_plt0_entry_le,
1962 { MINUS_ONE, 24, 20 },
1963 elf_sh_plt_entry_le,
1965 { 20, 16, 24, FALSE },
1972 /* Big-endian PIC. */
1973 elf_sh_plt0_entry_be,
1975 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
1976 elf_sh_pic_plt_entry_be,
1978 { 20, MINUS_ONE, 24, FALSE },
1983 /* Little-endian PIC. */
1984 elf_sh_plt0_entry_le,
1986 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
1987 elf_sh_pic_plt_entry_le,
1989 { 20, MINUS_ONE, 24, FALSE },
1996 #define VXWORKS_PLT_HEADER_SIZE 12
1997 #define VXWORKS_PLT_ENTRY_SIZE 24
1999 static const bfd_byte vxworks_sh_plt0_entry_be[VXWORKS_PLT_HEADER_SIZE] =
2001 0xd1, 0x01, /* mov.l @(8,pc),r1 */
2002 0x61, 0x12, /* mov.l @r1,r1 */
2003 0x41, 0x2b, /* jmp @r1 */
2004 0x00, 0x09, /* nop */
2005 0, 0, 0, 0 /* 0: replaced with _GLOBAL_OFFSET_TABLE+8. */
2008 static const bfd_byte vxworks_sh_plt0_entry_le[VXWORKS_PLT_HEADER_SIZE] =
2010 0x01, 0xd1, /* mov.l @(8,pc),r1 */
2011 0x12, 0x61, /* mov.l @r1,r1 */
2012 0x2b, 0x41, /* jmp @r1 */
2013 0x09, 0x00, /* nop */
2014 0, 0, 0, 0 /* 0: replaced with _GLOBAL_OFFSET_TABLE+8. */
2017 static const bfd_byte vxworks_sh_plt_entry_be[VXWORKS_PLT_ENTRY_SIZE] =
2019 0xd0, 0x01, /* mov.l @(8,pc),r0 */
2020 0x60, 0x02, /* mov.l @r0,r0 */
2021 0x40, 0x2b, /* jmp @r0 */
2022 0x00, 0x09, /* nop */
2023 0, 0, 0, 0, /* 0: replaced with address of this symbol in .got. */
2024 0xd0, 0x01, /* mov.l @(8,pc),r0 */
2025 0xa0, 0x00, /* bra PLT (We need to fix the offset.) */
2026 0x00, 0x09, /* nop */
2027 0x00, 0x09, /* nop */
2028 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2031 static const bfd_byte vxworks_sh_plt_entry_le[VXWORKS_PLT_ENTRY_SIZE] =
2033 0x01, 0xd0, /* mov.l @(8,pc),r0 */
2034 0x02, 0x60, /* mov.l @r0,r0 */
2035 0x2b, 0x40, /* jmp @r0 */
2036 0x09, 0x00, /* nop */
2037 0, 0, 0, 0, /* 0: replaced with address of this symbol in .got. */
2038 0x01, 0xd0, /* mov.l @(8,pc),r0 */
2039 0x00, 0xa0, /* bra PLT (We need to fix the offset.) */
2040 0x09, 0x00, /* nop */
2041 0x09, 0x00, /* nop */
2042 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2045 static const bfd_byte vxworks_sh_pic_plt_entry_be[VXWORKS_PLT_ENTRY_SIZE] =
2047 0xd0, 0x01, /* mov.l @(8,pc),r0 */
2048 0x00, 0xce, /* mov.l @(r0,r12),r0 */
2049 0x40, 0x2b, /* jmp @r0 */
2050 0x00, 0x09, /* nop */
2051 0, 0, 0, 0, /* 0: replaced with offset of this symbol in .got. */
2052 0xd0, 0x01, /* mov.l @(8,pc),r0 */
2053 0x51, 0xc2, /* mov.l @(8,r12),r1 */
2054 0x41, 0x2b, /* jmp @r1 */
2055 0x00, 0x09, /* nop */
2056 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2059 static const bfd_byte vxworks_sh_pic_plt_entry_le[VXWORKS_PLT_ENTRY_SIZE] =
2061 0x01, 0xd0, /* mov.l @(8,pc),r0 */
2062 0xce, 0x00, /* mov.l @(r0,r12),r0 */
2063 0x2b, 0x40, /* jmp @r0 */
2064 0x09, 0x00, /* nop */
2065 0, 0, 0, 0, /* 0: replaced with offset of this symbol in .got. */
2066 0x01, 0xd0, /* mov.l @(8,pc),r0 */
2067 0xc2, 0x51, /* mov.l @(8,r12),r1 */
2068 0x2b, 0x41, /* jmp @r1 */
2069 0x09, 0x00, /* nop */
2070 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2073 static const struct elf_sh_plt_info vxworks_sh_plts[2][2] = {
2076 /* Big-endian non-PIC. */
2077 vxworks_sh_plt0_entry_be,
2078 VXWORKS_PLT_HEADER_SIZE,
2079 { MINUS_ONE, MINUS_ONE, 8 },
2080 vxworks_sh_plt_entry_be,
2081 VXWORKS_PLT_ENTRY_SIZE,
2082 { 8, 14, 20, FALSE },
2087 /* Little-endian non-PIC. */
2088 vxworks_sh_plt0_entry_le,
2089 VXWORKS_PLT_HEADER_SIZE,
2090 { MINUS_ONE, MINUS_ONE, 8 },
2091 vxworks_sh_plt_entry_le,
2092 VXWORKS_PLT_ENTRY_SIZE,
2093 { 8, 14, 20, FALSE },
2100 /* Big-endian PIC. */
2103 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2104 vxworks_sh_pic_plt_entry_be,
2105 VXWORKS_PLT_ENTRY_SIZE,
2106 { 8, MINUS_ONE, 20, FALSE },
2111 /* Little-endian PIC. */
2114 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2115 vxworks_sh_pic_plt_entry_le,
2116 VXWORKS_PLT_ENTRY_SIZE,
2117 { 8, MINUS_ONE, 20, FALSE },
2124 /* FDPIC PLT entries. Two unimplemented optimizations for lazy
2125 binding are to omit the lazy binding stub when linking with -z now
2126 and to move lazy binding stubs into a separate region for better
2129 #define FDPIC_PLT_ENTRY_SIZE 28
2130 #define FDPIC_PLT_LAZY_OFFSET 20
2132 /* FIXME: The lazy binding stub requires a plt0 - which may need to be
2133 duplicated if it is out of range, or which can be inlined. So
2134 right now it is always inlined, which wastes a word per stub. It
2135 might be easier to handle the duplication if we put the lazy
2136 stubs separately. */
2138 static const bfd_byte fdpic_sh_plt_entry_be[FDPIC_PLT_ENTRY_SIZE] =
2140 0xd0, 0x02, /* mov.l @(12,pc),r0 */
2141 0x01, 0xce, /* mov.l @(r0,r12),r1 */
2142 0x70, 0x04, /* add #4, r0 */
2143 0x41, 0x2b, /* jmp @r1 */
2144 0x0c, 0xce, /* mov.l @(r0,r12),r12 */
2145 0x00, 0x09, /* nop */
2146 0, 0, 0, 0, /* 0: replaced with offset of this symbol's funcdesc */
2147 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2148 0x60, 0xc2, /* mov.l @r12,r0 */
2149 0x40, 0x2b, /* jmp @r0 */
2150 0x53, 0xc1, /* mov.l @(4,r12),r3 */
2151 0x00, 0x09, /* nop */
2154 static const bfd_byte fdpic_sh_plt_entry_le[FDPIC_PLT_ENTRY_SIZE] =
2156 0x02, 0xd0, /* mov.l @(12,pc),r0 */
2157 0xce, 0x01, /* mov.l @(r0,r12),r1 */
2158 0x04, 0x70, /* add #4, r0 */
2159 0x2b, 0x41, /* jmp @r1 */
2160 0xce, 0x0c, /* mov.l @(r0,r12),r12 */
2161 0x09, 0x00, /* nop */
2162 0, 0, 0, 0, /* 0: replaced with offset of this symbol's funcdesc */
2163 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2164 0xc2, 0x60, /* mov.l @r12,r0 */
2165 0x2b, 0x40, /* jmp @r0 */
2166 0xc1, 0x53, /* mov.l @(4,r12),r3 */
2167 0x09, 0x00, /* nop */
2170 static const struct elf_sh_plt_info fdpic_sh_plts[2] = {
2172 /* Big-endian PIC. */
2175 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2176 fdpic_sh_plt_entry_be,
2177 FDPIC_PLT_ENTRY_SIZE,
2178 { 12, MINUS_ONE, 16, FALSE },
2179 FDPIC_PLT_LAZY_OFFSET,
2183 /* Little-endian PIC. */
2186 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2187 fdpic_sh_plt_entry_le,
2188 FDPIC_PLT_ENTRY_SIZE,
2189 { 12, MINUS_ONE, 16, FALSE },
2190 FDPIC_PLT_LAZY_OFFSET,
2195 /* On SH2A, we can use the movi20 instruction to generate shorter PLT
2196 entries for the first 64K slots. We use the normal FDPIC PLT entry
2197 past that point; we could also use movi20s, which might be faster,
2198 but would not be any smaller. */
2200 #define FDPIC_SH2A_PLT_ENTRY_SIZE 24
2201 #define FDPIC_SH2A_PLT_LAZY_OFFSET 16
2203 static const bfd_byte fdpic_sh2a_plt_entry_be[FDPIC_SH2A_PLT_ENTRY_SIZE] =
2205 0, 0, 0, 0, /* movi20 #gotofffuncdesc,r0 */
2206 0x01, 0xce, /* mov.l @(r0,r12),r1 */
2207 0x70, 0x04, /* add #4, r0 */
2208 0x41, 0x2b, /* jmp @r1 */
2209 0x0c, 0xce, /* mov.l @(r0,r12),r12 */
2210 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2211 0x60, 0xc2, /* mov.l @r12,r0 */
2212 0x40, 0x2b, /* jmp @r0 */
2213 0x53, 0xc1, /* mov.l @(4,r12),r3 */
2214 0x00, 0x09, /* nop */
2217 static const bfd_byte fdpic_sh2a_plt_entry_le[FDPIC_SH2A_PLT_ENTRY_SIZE] =
2219 0, 0, 0, 0, /* movi20 #gotofffuncdesc,r0 */
2220 0xce, 0x01, /* mov.l @(r0,r12),r1 */
2221 0x04, 0x70, /* add #4, r0 */
2222 0x2b, 0x41, /* jmp @r1 */
2223 0xce, 0x0c, /* mov.l @(r0,r12),r12 */
2224 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2225 0xc2, 0x60, /* mov.l @r12,r0 */
2226 0x2b, 0x40, /* jmp @r0 */
2227 0xc1, 0x53, /* mov.l @(4,r12),r3 */
2228 0x09, 0x00, /* nop */
2231 static const struct elf_sh_plt_info fdpic_sh2a_short_plt_be = {
2232 /* Big-endian FDPIC, max index 64K. */
2235 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2236 fdpic_sh2a_plt_entry_be,
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_short_plt_le = {
2244 /* Little-endian FDPIC, max index 64K. */
2247 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2248 fdpic_sh2a_plt_entry_le,
2249 FDPIC_SH2A_PLT_ENTRY_SIZE,
2250 { 0, MINUS_ONE, 12, TRUE },
2251 FDPIC_SH2A_PLT_LAZY_OFFSET,
2255 static const struct elf_sh_plt_info fdpic_sh2a_plts[2] = {
2257 /* Big-endian PIC. */
2260 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2261 fdpic_sh_plt_entry_be,
2262 FDPIC_PLT_ENTRY_SIZE,
2263 { 12, MINUS_ONE, 16, FALSE },
2264 FDPIC_PLT_LAZY_OFFSET,
2265 &fdpic_sh2a_short_plt_be
2268 /* Little-endian PIC. */
2271 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2272 fdpic_sh_plt_entry_le,
2273 FDPIC_PLT_ENTRY_SIZE,
2274 { 12, MINUS_ONE, 16, FALSE },
2275 FDPIC_PLT_LAZY_OFFSET,
2276 &fdpic_sh2a_short_plt_le
2280 /* Return the type of PLT associated with ABFD. PIC_P is true if
2281 the object is position-independent. */
2283 static const struct elf_sh_plt_info *
2284 get_plt_info (bfd *abfd, bfd_boolean pic_p)
2286 if (fdpic_object_p (abfd))
2288 /* If any input file requires SH2A we can use a shorter PLT
2290 if (sh_get_arch_from_bfd_mach (bfd_get_mach (abfd)) & arch_sh2a_base)
2291 return &fdpic_sh2a_plts[!bfd_big_endian (abfd)];
2293 return &fdpic_sh_plts[!bfd_big_endian (abfd)];
2295 if (vxworks_object_p (abfd))
2296 return &vxworks_sh_plts[pic_p][!bfd_big_endian (abfd)];
2297 return &elf_sh_plts[pic_p][!bfd_big_endian (abfd)];
2300 /* Install a 32-bit PLT field starting at ADDR, which occurs in OUTPUT_BFD.
2301 VALUE is the field's value and CODE_P is true if VALUE refers to code,
2305 install_plt_field (bfd *output_bfd, bfd_boolean code_p ATTRIBUTE_UNUSED,
2306 unsigned long value, bfd_byte *addr)
2308 bfd_put_32 (output_bfd, value, addr);
2312 /* The number of PLT entries which can use a shorter PLT, if any.
2313 Currently always 64K, since only SH-2A FDPIC uses this; a
2314 20-bit movi20 can address that many function descriptors below
2315 _GLOBAL_OFFSET_TABLE_. */
2316 #define MAX_SHORT_PLT 65536
2318 /* Return the index of the PLT entry at byte offset OFFSET. */
2321 get_plt_index (const struct elf_sh_plt_info *info, bfd_vma offset)
2323 bfd_vma plt_index = 0;
2325 offset -= info->plt0_entry_size;
2326 if (info->short_plt != NULL)
2328 if (offset > MAX_SHORT_PLT * info->short_plt->symbol_entry_size)
2330 plt_index = MAX_SHORT_PLT;
2331 offset -= MAX_SHORT_PLT * info->short_plt->symbol_entry_size;
2334 info = info->short_plt;
2336 return plt_index + offset / info->symbol_entry_size;
2339 /* Do the inverse operation. */
2342 get_plt_offset (const struct elf_sh_plt_info *info, bfd_vma plt_index)
2346 if (info->short_plt != NULL)
2348 if (plt_index > MAX_SHORT_PLT)
2350 offset = MAX_SHORT_PLT * info->short_plt->symbol_entry_size;
2351 plt_index -= MAX_SHORT_PLT;
2354 info = info->short_plt;
2356 return (offset + info->plt0_entry_size
2357 + (plt_index * info->symbol_entry_size));
2360 /* The sh linker needs to keep track of the number of relocs that it
2361 decides to copy as dynamic relocs in check_relocs for each symbol.
2362 This is so that it can later discard them if they are found to be
2363 unnecessary. We store the information in a field extending the
2364 regular ELF linker hash table. */
2366 struct elf_sh_dyn_relocs
2368 struct elf_sh_dyn_relocs *next;
2370 /* The input section of the reloc. */
2373 /* Total number of relocs copied for the input section. */
2374 bfd_size_type count;
2376 /* Number of pc-relative relocs copied for the input section. */
2377 bfd_size_type pc_count;
2382 bfd_signed_vma refcount;
2386 /* sh ELF linker hash entry. */
2388 struct elf_sh_link_hash_entry
2390 struct elf_link_hash_entry root;
2392 #ifdef INCLUDE_SHMEDIA
2395 bfd_signed_vma refcount;
2400 /* Track dynamic relocs copied for this symbol. */
2401 struct elf_sh_dyn_relocs *dyn_relocs;
2403 bfd_signed_vma gotplt_refcount;
2405 /* A local function descriptor, for FDPIC. The refcount counts
2406 R_SH_FUNCDESC, R_SH_GOTOFFFUNCDESC, and R_SH_GOTOFFFUNCDESC20
2407 relocations; the PLT and GOT entry are accounted
2408 for separately. After adjust_dynamic_symbol, the offset is
2409 MINUS_ONE if there is no local descriptor (dynamic linker
2410 managed and no PLT entry, or undefined weak non-dynamic).
2411 During check_relocs we do not yet know whether the local
2412 descriptor will be canonical. */
2413 union gotref funcdesc;
2415 /* How many of the above refcounted relocations were R_SH_FUNCDESC,
2416 and thus require fixups or relocations. */
2417 bfd_signed_vma abs_funcdesc_refcount;
2420 GOT_UNKNOWN = 0, GOT_NORMAL, GOT_TLS_GD, GOT_TLS_IE, GOT_FUNCDESC
2424 #define sh_elf_hash_entry(ent) ((struct elf_sh_link_hash_entry *)(ent))
2426 struct sh_elf_obj_tdata
2428 struct elf_obj_tdata root;
2430 /* got_type for each local got entry. */
2431 char *local_got_type;
2433 /* Function descriptor refcount and offset for each local symbol. */
2434 union gotref *local_funcdesc;
2437 #define sh_elf_tdata(abfd) \
2438 ((struct sh_elf_obj_tdata *) (abfd)->tdata.any)
2440 #define sh_elf_local_got_type(abfd) \
2441 (sh_elf_tdata (abfd)->local_got_type)
2443 #define sh_elf_local_funcdesc(abfd) \
2444 (sh_elf_tdata (abfd)->local_funcdesc)
2446 #define is_sh_elf(bfd) \
2447 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2448 && elf_tdata (bfd) != NULL \
2449 && elf_object_id (bfd) == SH_ELF_DATA)
2451 /* Override the generic function because we need to store sh_elf_obj_tdata
2452 as the specific tdata. */
2455 sh_elf_mkobject (bfd *abfd)
2457 return bfd_elf_allocate_object (abfd, sizeof (struct sh_elf_obj_tdata),
2461 /* sh ELF linker hash table. */
2463 struct elf_sh_link_hash_table
2465 struct elf_link_hash_table root;
2467 /* Short-cuts to get to dynamic linker sections. */
2475 asection *sfuncdesc;
2476 asection *srelfuncdesc;
2479 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
2482 /* Small local sym cache. */
2483 struct sym_cache sym_cache;
2485 /* A counter or offset to track a TLS got entry. */
2488 bfd_signed_vma refcount;
2492 /* The type of PLT to use. */
2493 const struct elf_sh_plt_info *plt_info;
2495 /* True if the target system is VxWorks. */
2496 bfd_boolean vxworks_p;
2498 /* True if the target system uses FDPIC. */
2499 bfd_boolean fdpic_p;
2502 /* Traverse an sh ELF linker hash table. */
2504 #define sh_elf_link_hash_traverse(table, func, info) \
2505 (elf_link_hash_traverse \
2507 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
2510 /* Get the sh ELF linker hash table from a link_info structure. */
2512 #define sh_elf_hash_table(p) \
2513 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
2514 == SH_ELF_DATA ? ((struct elf_sh_link_hash_table *) ((p)->hash)) : NULL)
2516 /* Create an entry in an sh ELF linker hash table. */
2518 static struct bfd_hash_entry *
2519 sh_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
2520 struct bfd_hash_table *table,
2523 struct elf_sh_link_hash_entry *ret =
2524 (struct elf_sh_link_hash_entry *) entry;
2526 /* Allocate the structure if it has not already been allocated by a
2528 if (ret == (struct elf_sh_link_hash_entry *) NULL)
2529 ret = ((struct elf_sh_link_hash_entry *)
2530 bfd_hash_allocate (table,
2531 sizeof (struct elf_sh_link_hash_entry)));
2532 if (ret == (struct elf_sh_link_hash_entry *) NULL)
2533 return (struct bfd_hash_entry *) ret;
2535 /* Call the allocation method of the superclass. */
2536 ret = ((struct elf_sh_link_hash_entry *)
2537 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2539 if (ret != (struct elf_sh_link_hash_entry *) NULL)
2541 ret->dyn_relocs = NULL;
2542 ret->gotplt_refcount = 0;
2543 #ifdef INCLUDE_SHMEDIA
2544 ret->datalabel_got.refcount = ret->root.got.refcount;
2546 ret->funcdesc.refcount = 0;
2547 ret->abs_funcdesc_refcount = 0;
2548 ret->got_type = GOT_UNKNOWN;
2551 return (struct bfd_hash_entry *) ret;
2554 /* Create an sh ELF linker hash table. */
2556 static struct bfd_link_hash_table *
2557 sh_elf_link_hash_table_create (bfd *abfd)
2559 struct elf_sh_link_hash_table *ret;
2560 bfd_size_type amt = sizeof (struct elf_sh_link_hash_table);
2562 ret = (struct elf_sh_link_hash_table *) bfd_zmalloc (amt);
2563 if (ret == (struct elf_sh_link_hash_table *) NULL)
2566 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
2567 sh_elf_link_hash_newfunc,
2568 sizeof (struct elf_sh_link_hash_entry),
2575 ret->vxworks_p = vxworks_object_p (abfd);
2576 ret->fdpic_p = fdpic_object_p (abfd);
2578 return &ret->root.root;
2582 sh_elf_omit_section_dynsym (bfd *output_bfd ATTRIBUTE_UNUSED,
2583 struct bfd_link_info *info, asection *p)
2585 struct elf_sh_link_hash_table *htab = sh_elf_hash_table (info);
2587 /* Non-FDPIC binaries do not need dynamic symbols for sections. */
2591 /* We need dynamic symbols for every section, since segments can
2592 relocate independently. */
2593 switch (elf_section_data (p)->this_hdr.sh_type)
2597 /* If sh_type is yet undecided, assume it could be
2598 SHT_PROGBITS/SHT_NOBITS. */
2602 /* There shouldn't be section relative relocations
2603 against any other section. */
2609 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
2610 shortcuts to them in our hash table. */
2613 create_got_section (bfd *dynobj, struct bfd_link_info *info)
2615 struct elf_sh_link_hash_table *htab;
2617 if (! _bfd_elf_create_got_section (dynobj, info))
2620 htab = sh_elf_hash_table (info);
2624 htab->sgot = bfd_get_linker_section (dynobj, ".got");
2625 htab->sgotplt = bfd_get_linker_section (dynobj, ".got.plt");
2626 htab->srelgot = bfd_get_linker_section (dynobj, ".rela.got");
2627 if (! htab->sgot || ! htab->sgotplt || ! htab->srelgot)
2630 htab->sfuncdesc = bfd_make_section_anyway_with_flags (dynobj, ".got.funcdesc",
2631 (SEC_ALLOC | SEC_LOAD
2634 | SEC_LINKER_CREATED));
2635 if (htab->sfuncdesc == NULL
2636 || ! bfd_set_section_alignment (dynobj, htab->sfuncdesc, 2))
2639 htab->srelfuncdesc = bfd_make_section_anyway_with_flags (dynobj,
2640 ".rela.got.funcdesc",
2641 (SEC_ALLOC | SEC_LOAD
2644 | SEC_LINKER_CREATED
2646 if (htab->srelfuncdesc == NULL
2647 || ! bfd_set_section_alignment (dynobj, htab->srelfuncdesc, 2))
2650 /* Also create .rofixup. */
2651 htab->srofixup = bfd_make_section_anyway_with_flags (dynobj, ".rofixup",
2652 (SEC_ALLOC | SEC_LOAD
2655 | SEC_LINKER_CREATED
2657 if (htab->srofixup == NULL
2658 || ! bfd_set_section_alignment (dynobj, htab->srofixup, 2))
2664 /* Create dynamic sections when linking against a dynamic object. */
2667 sh_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
2669 struct elf_sh_link_hash_table *htab;
2670 flagword flags, pltflags;
2672 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
2675 switch (bed->s->arch_size)
2686 bfd_set_error (bfd_error_bad_value);
2690 htab = sh_elf_hash_table (info);
2694 if (htab->root.dynamic_sections_created)
2697 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
2698 .rel[a].bss sections. */
2700 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2701 | SEC_LINKER_CREATED);
2704 pltflags |= SEC_CODE;
2705 if (bed->plt_not_loaded)
2706 pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
2707 if (bed->plt_readonly)
2708 pltflags |= SEC_READONLY;
2710 s = bfd_make_section_anyway_with_flags (abfd, ".plt", pltflags);
2713 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
2716 if (bed->want_plt_sym)
2718 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
2720 struct elf_link_hash_entry *h;
2721 struct bfd_link_hash_entry *bh = NULL;
2723 if (! (_bfd_generic_link_add_one_symbol
2724 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
2725 (bfd_vma) 0, (const char *) NULL, FALSE,
2726 get_elf_backend_data (abfd)->collect, &bh)))
2729 h = (struct elf_link_hash_entry *) bh;
2731 h->type = STT_OBJECT;
2732 htab->root.hplt = h;
2734 if (bfd_link_pic (info)
2735 && ! bfd_elf_link_record_dynamic_symbol (info, h))
2739 s = bfd_make_section_anyway_with_flags (abfd,
2740 bed->default_use_rela_p
2741 ? ".rela.plt" : ".rel.plt",
2742 flags | SEC_READONLY);
2745 || ! bfd_set_section_alignment (abfd, s, ptralign))
2748 if (htab->sgot == NULL
2749 && !create_got_section (abfd, info))
2752 if (bed->want_dynbss)
2754 /* The .dynbss section is a place to put symbols which are defined
2755 by dynamic objects, are referenced by regular objects, and are
2756 not functions. We must allocate space for them in the process
2757 image and use a R_*_COPY reloc to tell the dynamic linker to
2758 initialize them at run time. The linker script puts the .dynbss
2759 section into the .bss section of the final image. */
2760 s = bfd_make_section_anyway_with_flags (abfd, ".dynbss",
2761 SEC_ALLOC | SEC_LINKER_CREATED);
2766 /* The .rel[a].bss section holds copy relocs. This section is not
2767 normally needed. We need to create it here, though, so that the
2768 linker will map it to an output section. We can't just create it
2769 only if we need it, because we will not know whether we need it
2770 until we have seen all the input files, and the first time the
2771 main linker code calls BFD after examining all the input files
2772 (size_dynamic_sections) the input sections have already been
2773 mapped to the output sections. If the section turns out not to
2774 be needed, we can discard it later. We will never need this
2775 section when generating a shared object, since they do not use
2777 if (! bfd_link_pic (info))
2779 s = bfd_make_section_anyway_with_flags (abfd,
2780 (bed->default_use_rela_p
2781 ? ".rela.bss" : ".rel.bss"),
2782 flags | SEC_READONLY);
2785 || ! bfd_set_section_alignment (abfd, s, ptralign))
2790 if (htab->vxworks_p)
2792 if (!elf_vxworks_create_dynamic_sections (abfd, info, &htab->srelplt2))
2799 /* Adjust a symbol defined by a dynamic object and referenced by a
2800 regular object. The current definition is in some section of the
2801 dynamic object, but we're not including those sections. We have to
2802 change the definition to something the rest of the link can
2806 sh_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
2807 struct elf_link_hash_entry *h)
2809 struct elf_sh_link_hash_table *htab;
2810 struct elf_sh_link_hash_entry *eh;
2811 struct elf_sh_dyn_relocs *p;
2814 htab = sh_elf_hash_table (info);
2818 /* Make sure we know what is going on here. */
2819 BFD_ASSERT (htab->root.dynobj != NULL
2821 || h->u.weakdef != NULL
2824 && !h->def_regular)));
2826 /* If this is a function, put it in the procedure linkage table. We
2827 will fill in the contents of the procedure linkage table later,
2828 when we know the address of the .got section. */
2829 if (h->type == STT_FUNC
2832 if (h->plt.refcount <= 0
2833 || SYMBOL_CALLS_LOCAL (info, h)
2834 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
2835 && h->root.type == bfd_link_hash_undefweak))
2837 /* This case can occur if we saw a PLT reloc in an input
2838 file, but the symbol was never referred to by a dynamic
2839 object. In such a case, we don't actually need to build
2840 a procedure linkage table, and we can just do a REL32
2842 h->plt.offset = (bfd_vma) -1;
2849 h->plt.offset = (bfd_vma) -1;
2851 /* If this is a weak symbol, and there is a real definition, the
2852 processor independent code will have arranged for us to see the
2853 real definition first, and we can just use the same value. */
2854 if (h->u.weakdef != NULL)
2856 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
2857 || h->u.weakdef->root.type == bfd_link_hash_defweak);
2858 h->root.u.def.section = h->u.weakdef->root.u.def.section;
2859 h->root.u.def.value = h->u.weakdef->root.u.def.value;
2860 if (info->nocopyreloc)
2861 h->non_got_ref = h->u.weakdef->non_got_ref;
2865 /* This is a reference to a symbol defined by a dynamic object which
2866 is not a function. */
2868 /* If we are creating a shared library, we must presume that the
2869 only references to the symbol are via the global offset table.
2870 For such cases we need not do anything here; the relocations will
2871 be handled correctly by relocate_section. */
2872 if (bfd_link_pic (info))
2875 /* If there are no references to this symbol that do not use the
2876 GOT, we don't need to generate a copy reloc. */
2877 if (!h->non_got_ref)
2880 /* If -z nocopyreloc was given, we won't generate them either. */
2881 if (info->nocopyreloc)
2887 eh = (struct elf_sh_link_hash_entry *) h;
2888 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2890 s = p->sec->output_section;
2891 if (s != NULL && (s->flags & (SEC_READONLY | SEC_HAS_CONTENTS)) != 0)
2895 /* If we didn't find any dynamic relocs in sections which needs the
2896 copy reloc, then we'll be keeping the dynamic relocs and avoiding
2904 /* We must allocate the symbol in our .dynbss section, which will
2905 become part of the .bss section of the executable. There will be
2906 an entry for this symbol in the .dynsym section. The dynamic
2907 object will contain position independent code, so all references
2908 from the dynamic object to this symbol will go through the global
2909 offset table. The dynamic linker will use the .dynsym entry to
2910 determine the address it must put in the global offset table, so
2911 both the dynamic object and the regular object will refer to the
2912 same memory location for the variable. */
2915 BFD_ASSERT (s != NULL);
2917 /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
2918 copy the initial value out of the dynamic object and into the
2919 runtime process image. We need to remember the offset into the
2920 .rela.bss section we are going to use. */
2921 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
2925 srel = htab->srelbss;
2926 BFD_ASSERT (srel != NULL);
2927 srel->size += sizeof (Elf32_External_Rela);
2931 return _bfd_elf_adjust_dynamic_copy (info, h, s);
2934 /* Allocate space in .plt, .got and associated reloc sections for
2938 allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
2940 struct bfd_link_info *info;
2941 struct elf_sh_link_hash_table *htab;
2942 struct elf_sh_link_hash_entry *eh;
2943 struct elf_sh_dyn_relocs *p;
2945 if (h->root.type == bfd_link_hash_indirect)
2948 info = (struct bfd_link_info *) inf;
2949 htab = sh_elf_hash_table (info);
2953 eh = (struct elf_sh_link_hash_entry *) h;
2954 if ((h->got.refcount > 0
2956 && eh->gotplt_refcount > 0)
2958 /* The symbol has been forced local, or we have some direct got refs,
2959 so treat all the gotplt refs as got refs. */
2960 h->got.refcount += eh->gotplt_refcount;
2961 if (h->plt.refcount >= eh->gotplt_refcount)
2962 h->plt.refcount -= eh->gotplt_refcount;
2965 if (htab->root.dynamic_sections_created
2966 && h->plt.refcount > 0
2967 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2968 || h->root.type != bfd_link_hash_undefweak))
2970 /* Make sure this symbol is output as a dynamic symbol.
2971 Undefined weak syms won't yet be marked as dynamic. */
2972 if (h->dynindx == -1
2973 && !h->forced_local)
2975 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2979 if (bfd_link_pic (info)
2980 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
2982 asection *s = htab->splt;
2983 const struct elf_sh_plt_info *plt_info;
2985 /* If this is the first .plt entry, make room for the special
2988 s->size += htab->plt_info->plt0_entry_size;
2990 h->plt.offset = s->size;
2992 /* If this symbol is not defined in a regular file, and we are
2993 not generating a shared library, then set the symbol to this
2994 location in the .plt. This is required to make function
2995 pointers compare as equal between the normal executable and
2996 the shared library. Skip this for FDPIC, since the
2997 function's address will be the address of the canonical
2998 function descriptor. */
2999 if (!htab->fdpic_p && !bfd_link_pic (info) && !h->def_regular)
3001 h->root.u.def.section = s;
3002 h->root.u.def.value = h->plt.offset;
3005 /* Make room for this entry. */
3006 plt_info = htab->plt_info;
3007 if (plt_info->short_plt != NULL
3008 && (get_plt_index (plt_info->short_plt, s->size) < MAX_SHORT_PLT))
3009 plt_info = plt_info->short_plt;
3010 s->size += plt_info->symbol_entry_size;
3012 /* We also need to make an entry in the .got.plt section, which
3013 will be placed in the .got section by the linker script. */
3015 htab->sgotplt->size += 4;
3017 htab->sgotplt->size += 8;
3019 /* We also need to make an entry in the .rel.plt section. */
3020 htab->srelplt->size += sizeof (Elf32_External_Rela);
3022 if (htab->vxworks_p && !bfd_link_pic (info))
3024 /* VxWorks executables have a second set of relocations
3025 for each PLT entry. They go in a separate relocation
3026 section, which is processed by the kernel loader. */
3028 /* There is a relocation for the initial PLT entry:
3029 an R_SH_DIR32 relocation for _GLOBAL_OFFSET_TABLE_. */
3030 if (h->plt.offset == htab->plt_info->plt0_entry_size)
3031 htab->srelplt2->size += sizeof (Elf32_External_Rela);
3033 /* There are two extra relocations for each subsequent
3034 PLT entry: an R_SH_DIR32 relocation for the GOT entry,
3035 and an R_SH_DIR32 relocation for the PLT entry. */
3036 htab->srelplt2->size += sizeof (Elf32_External_Rela) * 2;
3041 h->plt.offset = (bfd_vma) -1;
3047 h->plt.offset = (bfd_vma) -1;
3051 if (h->got.refcount > 0)
3055 enum got_type got_type = sh_elf_hash_entry (h)->got_type;
3057 /* Make sure this symbol is output as a dynamic symbol.
3058 Undefined weak syms won't yet be marked as dynamic. */
3059 if (h->dynindx == -1
3060 && !h->forced_local)
3062 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3067 h->got.offset = s->size;
3069 /* R_SH_TLS_GD needs 2 consecutive GOT slots. */
3070 if (got_type == GOT_TLS_GD)
3072 dyn = htab->root.dynamic_sections_created;
3075 /* No dynamic relocations required. */
3076 if (htab->fdpic_p && !bfd_link_pic (info)
3077 && h->root.type != bfd_link_hash_undefweak
3078 && (got_type == GOT_NORMAL || got_type == GOT_FUNCDESC))
3079 htab->srofixup->size += 4;
3081 /* No dynamic relocations required when IE->LE conversion happens. */
3082 else if (got_type == GOT_TLS_IE
3084 && !bfd_link_pic (info))
3086 /* R_SH_TLS_IE_32 needs one dynamic relocation if dynamic,
3087 R_SH_TLS_GD needs one if local symbol and two if global. */
3088 else if ((got_type == GOT_TLS_GD && h->dynindx == -1)
3089 || got_type == GOT_TLS_IE)
3090 htab->srelgot->size += sizeof (Elf32_External_Rela);
3091 else if (got_type == GOT_TLS_GD)
3092 htab->srelgot->size += 2 * sizeof (Elf32_External_Rela);
3093 else if (got_type == GOT_FUNCDESC)
3095 if (!bfd_link_pic (info) && SYMBOL_FUNCDESC_LOCAL (info, h))
3096 htab->srofixup->size += 4;
3098 htab->srelgot->size += sizeof (Elf32_External_Rela);
3100 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3101 || h->root.type != bfd_link_hash_undefweak)
3102 && (bfd_link_pic (info)
3103 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
3104 htab->srelgot->size += sizeof (Elf32_External_Rela);
3105 else if (htab->fdpic_p
3106 && !bfd_link_pic (info)
3107 && got_type == GOT_NORMAL
3108 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3109 || h->root.type != bfd_link_hash_undefweak))
3110 htab->srofixup->size += 4;
3113 h->got.offset = (bfd_vma) -1;
3115 #ifdef INCLUDE_SHMEDIA
3116 if (eh->datalabel_got.refcount > 0)
3121 /* Make sure this symbol is output as a dynamic symbol.
3122 Undefined weak syms won't yet be marked as dynamic. */
3123 if (h->dynindx == -1
3124 && !h->forced_local)
3126 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3131 eh->datalabel_got.offset = s->size;
3133 dyn = htab->root.dynamic_sections_created;
3134 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h))
3135 htab->srelgot->size += sizeof (Elf32_External_Rela);
3138 eh->datalabel_got.offset = (bfd_vma) -1;
3141 /* Allocate space for any dynamic relocations to function
3142 descriptors, canonical or otherwise. We need to relocate the
3143 reference unless it resolves to zero, which only happens for
3144 undefined weak symbols (either non-default visibility, or when
3145 static linking). Any GOT slot is accounted for elsewhere. */
3146 if (eh->abs_funcdesc_refcount > 0
3147 && (h->root.type != bfd_link_hash_undefweak
3148 || (htab->root.dynamic_sections_created
3149 && ! SYMBOL_CALLS_LOCAL (info, h))))
3151 if (!bfd_link_pic (info) && SYMBOL_FUNCDESC_LOCAL (info, h))
3152 htab->srofixup->size += eh->abs_funcdesc_refcount * 4;
3155 += eh->abs_funcdesc_refcount * sizeof (Elf32_External_Rela);
3158 /* We must allocate a function descriptor if there are references to
3159 a canonical descriptor (R_SH_GOTFUNCDESC or R_SH_FUNCDESC) and
3160 the dynamic linker isn't going to allocate it. None of this
3161 applies if we already created one in .got.plt, but if the
3162 canonical function descriptor can be in this object, there
3163 won't be a PLT entry at all. */
3164 if ((eh->funcdesc.refcount > 0
3165 || (h->got.offset != MINUS_ONE && eh->got_type == GOT_FUNCDESC))
3166 && h->root.type != bfd_link_hash_undefweak
3167 && SYMBOL_FUNCDESC_LOCAL (info, h))
3169 /* Make room for this function descriptor. */
3170 eh->funcdesc.offset = htab->sfuncdesc->size;
3171 htab->sfuncdesc->size += 8;
3173 /* We will need a relocation or two fixups to initialize the
3174 function descriptor, so allocate those too. */
3175 if (!bfd_link_pic (info) && SYMBOL_CALLS_LOCAL (info, h))
3176 htab->srofixup->size += 8;
3178 htab->srelfuncdesc->size += sizeof (Elf32_External_Rela);
3181 if (eh->dyn_relocs == NULL)
3184 /* In the shared -Bsymbolic case, discard space allocated for
3185 dynamic pc-relative relocs against symbols which turn out to be
3186 defined in regular objects. For the normal shared case, discard
3187 space for pc-relative relocs that have become local due to symbol
3188 visibility changes. */
3190 if (bfd_link_pic (info))
3192 if (SYMBOL_CALLS_LOCAL (info, h))
3194 struct elf_sh_dyn_relocs **pp;
3196 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
3198 p->count -= p->pc_count;
3207 if (htab->vxworks_p)
3209 struct elf_sh_dyn_relocs **pp;
3211 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
3213 if (strcmp (p->sec->output_section->name, ".tls_vars") == 0)
3220 /* Also discard relocs on undefined weak syms with non-default
3222 if (eh->dyn_relocs != NULL
3223 && h->root.type == bfd_link_hash_undefweak)
3225 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
3226 eh->dyn_relocs = NULL;
3228 /* Make sure undefined weak symbols are output as a dynamic
3230 else if (h->dynindx == -1
3231 && !h->forced_local)
3233 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3240 /* For the non-shared case, discard space for relocs against
3241 symbols which turn out to need copy relocs or are not
3247 || (htab->root.dynamic_sections_created
3248 && (h->root.type == bfd_link_hash_undefweak
3249 || h->root.type == bfd_link_hash_undefined))))
3251 /* Make sure this symbol is output as a dynamic symbol.
3252 Undefined weak syms won't yet be marked as dynamic. */
3253 if (h->dynindx == -1
3254 && !h->forced_local)
3256 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3260 /* If that succeeded, we know we'll be keeping all the
3262 if (h->dynindx != -1)
3266 eh->dyn_relocs = NULL;
3271 /* Finally, allocate space. */
3272 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3274 asection *sreloc = elf_section_data (p->sec)->sreloc;
3275 sreloc->size += p->count * sizeof (Elf32_External_Rela);
3277 /* If we need relocations, we do not need fixups. */
3278 if (htab->fdpic_p && !bfd_link_pic (info))
3279 htab->srofixup->size -= 4 * (p->count - p->pc_count);
3285 /* Find any dynamic relocs that apply to read-only sections. */
3288 readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf)
3290 struct elf_sh_link_hash_entry *eh;
3291 struct elf_sh_dyn_relocs *p;
3293 eh = (struct elf_sh_link_hash_entry *) h;
3294 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3296 asection *s = p->sec->output_section;
3298 if (s != NULL && (s->flags & SEC_READONLY) != 0)
3300 struct bfd_link_info *info = (struct bfd_link_info *) inf;
3302 info->flags |= DF_TEXTREL;
3304 /* Not an error, just cut short the traversal. */
3311 /* This function is called after all the input files have been read,
3312 and the input sections have been assigned to output sections.
3313 It's a convenient place to determine the PLT style. */
3316 sh_elf_always_size_sections (bfd *output_bfd, struct bfd_link_info *info)
3318 sh_elf_hash_table (info)->plt_info = get_plt_info (output_bfd,
3319 bfd_link_pic (info));
3321 if (sh_elf_hash_table (info)->fdpic_p && !bfd_link_relocatable (info)
3322 && !bfd_elf_stack_segment_size (output_bfd, info,
3323 "__stacksize", DEFAULT_STACK_SIZE))
3328 /* Set the sizes of the dynamic sections. */
3331 sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
3332 struct bfd_link_info *info)
3334 struct elf_sh_link_hash_table *htab;
3340 htab = sh_elf_hash_table (info);
3344 dynobj = htab->root.dynobj;
3345 BFD_ASSERT (dynobj != NULL);
3347 if (htab->root.dynamic_sections_created)
3349 /* Set the contents of the .interp section to the interpreter. */
3350 if (bfd_link_executable (info) && !info->nointerp)
3352 s = bfd_get_linker_section (dynobj, ".interp");
3353 BFD_ASSERT (s != NULL);
3354 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
3355 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
3359 /* Set up .got offsets for local syms, and space for local dynamic
3361 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
3363 bfd_signed_vma *local_got;
3364 bfd_signed_vma *end_local_got;
3365 union gotref *local_funcdesc, *end_local_funcdesc;
3366 char *local_got_type;
3367 bfd_size_type locsymcount;
3368 Elf_Internal_Shdr *symtab_hdr;
3371 if (! is_sh_elf (ibfd))
3374 for (s = ibfd->sections; s != NULL; s = s->next)
3376 struct elf_sh_dyn_relocs *p;
3378 for (p = ((struct elf_sh_dyn_relocs *)
3379 elf_section_data (s)->local_dynrel);
3383 if (! bfd_is_abs_section (p->sec)
3384 && bfd_is_abs_section (p->sec->output_section))
3386 /* Input section has been discarded, either because
3387 it is a copy of a linkonce section or due to
3388 linker script /DISCARD/, so we'll be discarding
3391 else if (htab->vxworks_p
3392 && strcmp (p->sec->output_section->name,
3395 /* Relocations in vxworks .tls_vars sections are
3396 handled specially by the loader. */
3398 else if (p->count != 0)
3400 srel = elf_section_data (p->sec)->sreloc;
3401 srel->size += p->count * sizeof (Elf32_External_Rela);
3402 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
3403 info->flags |= DF_TEXTREL;
3405 /* If we need relocations, we do not need fixups. */
3406 if (htab->fdpic_p && !bfd_link_pic (info))
3407 htab->srofixup->size -= 4 * (p->count - p->pc_count);
3412 symtab_hdr = &elf_symtab_hdr (ibfd);
3413 locsymcount = symtab_hdr->sh_info;
3414 #ifdef INCLUDE_SHMEDIA
3415 /* Count datalabel local GOT. */
3419 srel = htab->srelgot;
3421 local_got = elf_local_got_refcounts (ibfd);
3424 end_local_got = local_got + locsymcount;
3425 local_got_type = sh_elf_local_got_type (ibfd);
3426 local_funcdesc = sh_elf_local_funcdesc (ibfd);
3427 for (; local_got < end_local_got; ++local_got)
3431 *local_got = s->size;
3433 if (*local_got_type == GOT_TLS_GD)
3435 if (bfd_link_pic (info))
3436 srel->size += sizeof (Elf32_External_Rela);
3438 htab->srofixup->size += 4;
3440 if (*local_got_type == GOT_FUNCDESC)
3442 if (local_funcdesc == NULL)
3446 size = locsymcount * sizeof (union gotref);
3447 local_funcdesc = (union gotref *) bfd_zalloc (ibfd,
3449 if (local_funcdesc == NULL)
3451 sh_elf_local_funcdesc (ibfd) = local_funcdesc;
3452 local_funcdesc += (local_got
3453 - elf_local_got_refcounts (ibfd));
3455 local_funcdesc->refcount++;
3460 *local_got = (bfd_vma) -1;
3465 local_funcdesc = sh_elf_local_funcdesc (ibfd);
3468 end_local_funcdesc = local_funcdesc + locsymcount;
3470 for (; local_funcdesc < end_local_funcdesc; ++local_funcdesc)
3472 if (local_funcdesc->refcount > 0)
3474 local_funcdesc->offset = htab->sfuncdesc->size;
3475 htab->sfuncdesc->size += 8;
3476 if (!bfd_link_pic (info))
3477 htab->srofixup->size += 8;
3479 htab->srelfuncdesc->size += sizeof (Elf32_External_Rela);
3482 local_funcdesc->offset = MINUS_ONE;
3488 if (htab->tls_ldm_got.refcount > 0)
3490 /* Allocate 2 got entries and 1 dynamic reloc for R_SH_TLS_LD_32
3492 htab->tls_ldm_got.offset = htab->sgot->size;
3493 htab->sgot->size += 8;
3494 htab->srelgot->size += sizeof (Elf32_External_Rela);
3497 htab->tls_ldm_got.offset = -1;
3499 /* Only the reserved entries should be present. For FDPIC, they go at
3500 the end of .got.plt. */
3503 BFD_ASSERT (htab->sgotplt && htab->sgotplt->size == 12);
3504 htab->sgotplt->size = 0;
3507 /* Allocate global sym .plt and .got entries, and space for global
3508 sym dynamic relocs. */
3509 elf_link_hash_traverse (&htab->root, allocate_dynrelocs, info);
3511 /* Move the reserved entries and the _GLOBAL_OFFSET_TABLE_ symbol to the
3512 end of the FDPIC .got.plt. */
3515 htab->root.hgot->root.u.def.value = htab->sgotplt->size;
3516 htab->sgotplt->size += 12;
3519 /* At the very end of the .rofixup section is a pointer to the GOT. */
3520 if (htab->fdpic_p && htab->srofixup != NULL)
3521 htab->srofixup->size += 4;
3523 /* We now have determined the sizes of the various dynamic sections.
3524 Allocate memory for them. */
3526 for (s = dynobj->sections; s != NULL; s = s->next)
3528 if ((s->flags & SEC_LINKER_CREATED) == 0)
3533 || s == htab->sgotplt
3534 || s == htab->sfuncdesc
3535 || s == htab->srofixup
3536 || s == htab->sdynbss)
3538 /* Strip this section if we don't need it; see the
3541 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
3543 if (s->size != 0 && s != htab->srelplt && s != htab->srelplt2)
3546 /* We use the reloc_count field as a counter if we need
3547 to copy relocs into the output file. */
3552 /* It's not one of our sections, so don't allocate space. */
3558 /* If we don't need this section, strip it from the
3559 output file. This is mostly to handle .rela.bss and
3560 .rela.plt. We must create both sections in
3561 create_dynamic_sections, because they must be created
3562 before the linker maps input sections to output
3563 sections. The linker does that before
3564 adjust_dynamic_symbol is called, and it is that
3565 function which decides whether anything needs to go
3566 into these sections. */
3568 s->flags |= SEC_EXCLUDE;
3572 if ((s->flags & SEC_HAS_CONTENTS) == 0)
3575 /* Allocate memory for the section contents. We use bfd_zalloc
3576 here in case unused entries are not reclaimed before the
3577 section's contents are written out. This should not happen,
3578 but this way if it does, we get a R_SH_NONE reloc instead
3580 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
3581 if (s->contents == NULL)
3585 if (htab->root.dynamic_sections_created)
3587 /* Add some entries to the .dynamic section. We fill in the
3588 values later, in sh_elf_finish_dynamic_sections, but we
3589 must add the entries now so that we get the correct size for
3590 the .dynamic section. The DT_DEBUG entry is filled in by the
3591 dynamic linker and used by the debugger. */
3592 #define add_dynamic_entry(TAG, VAL) \
3593 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3595 if (bfd_link_executable (info))
3597 if (! add_dynamic_entry (DT_DEBUG, 0))
3601 if (htab->splt->size != 0)
3603 if (! add_dynamic_entry (DT_PLTGOT, 0)
3604 || ! add_dynamic_entry (DT_PLTRELSZ, 0)
3605 || ! add_dynamic_entry (DT_PLTREL, DT_RELA)
3606 || ! add_dynamic_entry (DT_JMPREL, 0))
3609 else if ((elf_elfheader (output_bfd)->e_flags & EF_SH_FDPIC))
3611 if (! add_dynamic_entry (DT_PLTGOT, 0))
3617 if (! add_dynamic_entry (DT_RELA, 0)
3618 || ! add_dynamic_entry (DT_RELASZ, 0)
3619 || ! add_dynamic_entry (DT_RELAENT,
3620 sizeof (Elf32_External_Rela)))
3623 /* If any dynamic relocs apply to a read-only section,
3624 then we need a DT_TEXTREL entry. */
3625 if ((info->flags & DF_TEXTREL) == 0)
3626 elf_link_hash_traverse (&htab->root, readonly_dynrelocs, info);
3628 if ((info->flags & DF_TEXTREL) != 0)
3630 if (! add_dynamic_entry (DT_TEXTREL, 0))
3635 && !elf_vxworks_add_dynamic_entries (output_bfd, info))
3638 #undef add_dynamic_entry
3643 /* Add a dynamic relocation to the SRELOC section. */
3645 inline static bfd_vma
3646 sh_elf_add_dyn_reloc (bfd *output_bfd, asection *sreloc, bfd_vma offset,
3647 int reloc_type, long dynindx, bfd_vma addend)
3649 Elf_Internal_Rela outrel;
3650 bfd_vma reloc_offset;
3652 outrel.r_offset = offset;
3653 outrel.r_info = ELF32_R_INFO (dynindx, reloc_type);
3654 outrel.r_addend = addend;
3656 reloc_offset = sreloc->reloc_count * sizeof (Elf32_External_Rela);
3657 BFD_ASSERT (reloc_offset < sreloc->size);
3658 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
3659 sreloc->contents + reloc_offset);
3660 sreloc->reloc_count++;
3662 return reloc_offset;
3665 /* Add an FDPIC read-only fixup. */
3668 sh_elf_add_rofixup (bfd *output_bfd, asection *srofixup, bfd_vma offset)
3670 bfd_vma fixup_offset;
3672 fixup_offset = srofixup->reloc_count++ * 4;
3673 BFD_ASSERT (fixup_offset < srofixup->size);
3674 bfd_put_32 (output_bfd, offset, srofixup->contents + fixup_offset);
3677 /* Return the offset of the generated .got section from the
3678 _GLOBAL_OFFSET_TABLE_ symbol. */
3680 static bfd_signed_vma
3681 sh_elf_got_offset (struct elf_sh_link_hash_table *htab)
3683 return (htab->sgot->output_offset - htab->sgotplt->output_offset
3684 - htab->root.hgot->root.u.def.value);
3687 /* Find the segment number in which OSEC, and output section, is
3691 sh_elf_osec_to_segment (bfd *output_bfd, asection *osec)
3693 Elf_Internal_Phdr *p = NULL;
3695 if (output_bfd->xvec->flavour == bfd_target_elf_flavour
3696 /* PR ld/17110: Do not look for output segments in an input bfd. */
3697 && output_bfd->direction != read_direction)
3698 p = _bfd_elf_find_segment_containing_section (output_bfd, osec);
3700 /* FIXME: Nothing ever says what this index is relative to. The kernel
3701 supplies data in terms of the number of load segments but this is
3702 a phdr index and the first phdr may not be a load segment. */
3703 return (p != NULL) ? p - elf_tdata (output_bfd)->phdr : -1;
3707 sh_elf_osec_readonly_p (bfd *output_bfd, asection *osec)
3709 unsigned seg = sh_elf_osec_to_segment (output_bfd, osec);
3711 return (seg != (unsigned) -1
3712 && ! (elf_tdata (output_bfd)->phdr[seg].p_flags & PF_W));
3715 /* Generate the initial contents of a local function descriptor, along
3716 with any relocations or fixups required. */
3718 sh_elf_initialize_funcdesc (bfd *output_bfd,
3719 struct bfd_link_info *info,
3720 struct elf_link_hash_entry *h,
3725 struct elf_sh_link_hash_table *htab;
3729 htab = sh_elf_hash_table (info);
3731 /* FIXME: The ABI says that the offset to the function goes in the
3732 descriptor, along with the segment index. We're RELA, so it could
3733 go in the reloc instead... */
3735 if (h != NULL && SYMBOL_CALLS_LOCAL (info, h))
3737 section = h->root.u.def.section;
3738 value = h->root.u.def.value;
3741 if (h == NULL || SYMBOL_CALLS_LOCAL (info, h))
3743 dynindx = elf_section_data (section->output_section)->dynindx;
3744 addr = value + section->output_offset;
3745 seg = sh_elf_osec_to_segment (output_bfd, section->output_section);
3749 BFD_ASSERT (h->dynindx != -1);
3750 dynindx = h->dynindx;
3754 if (!bfd_link_pic (info) && SYMBOL_CALLS_LOCAL (info, h))
3756 if (h == NULL || h->root.type != bfd_link_hash_undefweak)
3758 sh_elf_add_rofixup (output_bfd, htab->srofixup,
3760 + htab->sfuncdesc->output_section->vma
3761 + htab->sfuncdesc->output_offset);
3762 sh_elf_add_rofixup (output_bfd, htab->srofixup,
3764 + htab->sfuncdesc->output_section->vma
3765 + htab->sfuncdesc->output_offset);
3768 /* There are no dynamic relocations so fill in the final
3769 address and gp value (barring fixups). */
3770 addr += section->output_section->vma;
3771 seg = htab->root.hgot->root.u.def.value
3772 + htab->root.hgot->root.u.def.section->output_section->vma
3773 + htab->root.hgot->root.u.def.section->output_offset;
3776 sh_elf_add_dyn_reloc (output_bfd, htab->srelfuncdesc,
3778 + htab->sfuncdesc->output_section->vma
3779 + htab->sfuncdesc->output_offset,
3780 R_SH_FUNCDESC_VALUE, dynindx, 0);
3782 bfd_put_32 (output_bfd, addr, htab->sfuncdesc->contents + offset);
3783 bfd_put_32 (output_bfd, seg, htab->sfuncdesc->contents + offset + 4);
3788 /* Install a 20-bit movi20 field starting at ADDR, which occurs in OUTPUT_BFD.
3789 VALUE is the field's value. Return bfd_reloc_ok if successful or an error
3792 static bfd_reloc_status_type
3793 install_movi20_field (bfd *output_bfd, unsigned long relocation,
3794 bfd *input_bfd, asection *input_section,
3795 bfd_byte *contents, bfd_vma offset)
3797 unsigned long cur_val;
3799 bfd_reloc_status_type r;
3801 if (offset > bfd_get_section_limit (input_bfd, input_section))
3802 return bfd_reloc_outofrange;
3804 r = bfd_check_overflow (complain_overflow_signed, 20, 0,
3805 bfd_arch_bits_per_address (input_bfd), relocation);
3806 if (r != bfd_reloc_ok)
3809 addr = contents + offset;
3810 cur_val = bfd_get_16 (output_bfd, addr);
3811 bfd_put_16 (output_bfd, cur_val | ((relocation & 0xf0000) >> 12), addr);
3812 bfd_put_16 (output_bfd, relocation & 0xffff, addr + 2);
3814 return bfd_reloc_ok;
3817 /* Relocate an SH ELF section. */
3820 sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
3821 bfd *input_bfd, asection *input_section,
3822 bfd_byte *contents, Elf_Internal_Rela *relocs,
3823 Elf_Internal_Sym *local_syms,
3824 asection **local_sections)
3826 struct elf_sh_link_hash_table *htab;
3827 Elf_Internal_Shdr *symtab_hdr;
3828 struct elf_link_hash_entry **sym_hashes;
3829 Elf_Internal_Rela *rel, *relend;
3831 bfd_vma *local_got_offsets;
3832 asection *sgot = NULL;
3833 asection *sgotplt = NULL;
3834 asection *splt = NULL;
3835 asection *sreloc = NULL;
3836 asection *srelgot = NULL;
3837 bfd_boolean is_vxworks_tls;
3838 unsigned isec_segment, got_segment, plt_segment, check_segment[2];
3839 bfd_boolean fdpic_p = FALSE;
3841 BFD_ASSERT (is_sh_elf (input_bfd));
3843 htab = sh_elf_hash_table (info);
3846 dynobj = htab->root.dynobj;
3848 sgotplt = htab->sgotplt;
3850 fdpic_p = htab->fdpic_p;
3852 symtab_hdr = &elf_symtab_hdr (input_bfd);
3853 sym_hashes = elf_sym_hashes (input_bfd);
3854 local_got_offsets = elf_local_got_offsets (input_bfd);
3856 isec_segment = sh_elf_osec_to_segment (output_bfd,
3857 input_section->output_section);
3858 if (fdpic_p && sgot)
3859 got_segment = sh_elf_osec_to_segment (output_bfd,
3860 sgot->output_section);
3863 if (fdpic_p && splt)
3864 plt_segment = sh_elf_osec_to_segment (output_bfd,
3865 splt->output_section);
3869 /* We have to handle relocations in vxworks .tls_vars sections
3870 specially, because the dynamic loader is 'weird'. */
3871 is_vxworks_tls = (htab && htab->vxworks_p && bfd_link_pic (info)
3872 && !strcmp (input_section->output_section->name,
3876 relend = relocs + input_section->reloc_count;
3877 for (; rel < relend; rel++)
3880 reloc_howto_type *howto;
3881 unsigned long r_symndx;
3882 Elf_Internal_Sym *sym;
3884 struct elf_link_hash_entry *h;
3886 bfd_vma addend = (bfd_vma) 0;
3887 bfd_reloc_status_type r;
3888 int seen_stt_datalabel = 0;
3890 enum got_type got_type;
3891 const char *symname = NULL;
3893 r_symndx = ELF32_R_SYM (rel->r_info);
3895 r_type = ELF32_R_TYPE (rel->r_info);
3897 /* Many of the relocs are only used for relaxing, and are
3898 handled entirely by the relaxation code. */
3899 if (r_type >= (int) R_SH_GNU_VTINHERIT
3900 && r_type <= (int) R_SH_LABEL)
3902 if (r_type == (int) R_SH_NONE)
3906 || r_type >= R_SH_max
3907 || (r_type >= (int) R_SH_FIRST_INVALID_RELOC
3908 && r_type <= (int) R_SH_LAST_INVALID_RELOC)
3909 || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_2
3910 && r_type <= (int) R_SH_LAST_INVALID_RELOC_2)
3911 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_3
3912 && r_type <= (int) R_SH_LAST_INVALID_RELOC_3)
3913 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_4
3914 && r_type <= (int) R_SH_LAST_INVALID_RELOC_4)
3915 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_5
3916 && r_type <= (int) R_SH_LAST_INVALID_RELOC_5)
3917 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_6
3918 && r_type <= (int) R_SH_LAST_INVALID_RELOC_6))
3920 bfd_set_error (bfd_error_bad_value);
3924 howto = get_howto_table (output_bfd) + r_type;
3926 /* For relocs that aren't partial_inplace, we get the addend from
3928 if (! howto->partial_inplace)
3929 addend = rel->r_addend;
3934 check_segment[0] = -1;
3935 check_segment[1] = -1;
3936 if (r_symndx < symtab_hdr->sh_info)
3938 sym = local_syms + r_symndx;
3939 sec = local_sections[r_symndx];
3941 symname = bfd_elf_string_from_elf_section
3942 (input_bfd, symtab_hdr->sh_link, sym->st_name);
3943 if (symname == NULL || *symname == '\0')
3944 symname = bfd_section_name (input_bfd, sec);
3946 relocation = (sec->output_section->vma
3947 + sec->output_offset
3949 /* A local symbol never has STO_SH5_ISA32, so we don't need
3950 datalabel processing here. Make sure this does not change
3952 if ((sym->st_other & STO_SH5_ISA32) != 0)
3953 (*info->callbacks->reloc_dangerous)
3955 _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
3956 input_bfd, input_section, rel->r_offset);
3958 if (sec != NULL && discarded_section (sec))
3959 /* Handled below. */
3961 else if (bfd_link_relocatable (info))
3963 /* This is a relocatable link. We don't have to change
3964 anything, unless the reloc is against a section symbol,
3965 in which case we have to adjust according to where the
3966 section symbol winds up in the output section. */
3967 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
3969 if (! howto->partial_inplace)
3971 /* For relocations with the addend in the
3972 relocation, we need just to update the addend.
3973 All real relocs are of type partial_inplace; this
3974 code is mostly for completeness. */
3975 rel->r_addend += sec->output_offset;
3980 /* Relocs of type partial_inplace need to pick up the
3981 contents in the contents and add the offset resulting
3982 from the changed location of the section symbol.
3983 Using _bfd_final_link_relocate (e.g. goto
3984 final_link_relocate) here would be wrong, because
3985 relocations marked pc_relative would get the current
3986 location subtracted, and we must only do that at the
3988 r = _bfd_relocate_contents (howto, input_bfd,
3991 contents + rel->r_offset);
3992 goto relocation_done;
3997 else if (! howto->partial_inplace)
3999 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
4000 addend = rel->r_addend;
4002 else if ((sec->flags & SEC_MERGE)
4003 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
4007 if (howto->rightshift || howto->src_mask != 0xffffffff)
4010 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
4011 input_bfd, input_section,
4012 (long) rel->r_offset, howto->name);
4016 addend = bfd_get_32 (input_bfd, contents + rel->r_offset);
4019 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
4021 addend += msec->output_section->vma + msec->output_offset;
4022 bfd_put_32 (input_bfd, addend, contents + rel->r_offset);
4028 /* FIXME: Ought to make use of the RELOC_FOR_GLOBAL_SYMBOL macro. */
4031 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4032 symname = h->root.root.string;
4033 while (h->root.type == bfd_link_hash_indirect
4034 || h->root.type == bfd_link_hash_warning)
4036 #ifdef INCLUDE_SHMEDIA
4037 /* If the reference passes a symbol marked with
4038 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
4040 seen_stt_datalabel |= h->type == STT_DATALABEL;
4042 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4044 if (h->root.type == bfd_link_hash_defined
4045 || h->root.type == bfd_link_hash_defweak)
4049 dyn = htab ? htab->root.dynamic_sections_created : FALSE;
4050 sec = h->root.u.def.section;
4051 /* In these cases, we don't need the relocation value.
4052 We check specially because in some obscure cases
4053 sec->output_section will be NULL. */
4054 if (r_type == R_SH_GOTPC
4055 || r_type == R_SH_GOTPC_LOW16
4056 || r_type == R_SH_GOTPC_MEDLOW16
4057 || r_type == R_SH_GOTPC_MEDHI16
4058 || r_type == R_SH_GOTPC_HI16
4059 || ((r_type == R_SH_PLT32
4060 || r_type == R_SH_PLT_LOW16
4061 || r_type == R_SH_PLT_MEDLOW16
4062 || r_type == R_SH_PLT_MEDHI16
4063 || r_type == R_SH_PLT_HI16)
4064 && h->plt.offset != (bfd_vma) -1)
4065 || ((r_type == R_SH_GOT32
4066 || r_type == R_SH_GOT20
4067 || r_type == R_SH_GOTFUNCDESC
4068 || r_type == R_SH_GOTFUNCDESC20
4069 || r_type == R_SH_GOTOFFFUNCDESC
4070 || r_type == R_SH_GOTOFFFUNCDESC20
4071 || r_type == R_SH_FUNCDESC
4072 || r_type == R_SH_GOT_LOW16
4073 || r_type == R_SH_GOT_MEDLOW16
4074 || r_type == R_SH_GOT_MEDHI16
4075 || r_type == R_SH_GOT_HI16)
4076 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
4077 bfd_link_pic (info),
4079 && (! bfd_link_pic (info)
4080 || (! info->symbolic && h->dynindx != -1)
4081 || !h->def_regular))
4082 /* The cases above are those in which relocation is
4083 overwritten in the switch block below. The cases
4084 below are those in which we must defer relocation
4085 to run-time, because we can't resolve absolute
4086 addresses when creating a shared library. */
4087 || (bfd_link_pic (info)
4088 && ((! info->symbolic && h->dynindx != -1)
4090 && ((r_type == R_SH_DIR32
4091 && !h->forced_local)
4092 || (r_type == R_SH_REL32
4093 && !SYMBOL_CALLS_LOCAL (info, h)))
4094 && ((input_section->flags & SEC_ALLOC) != 0
4095 /* DWARF will emit R_SH_DIR32 relocations in its
4096 sections against symbols defined externally
4097 in shared libraries. We can't do anything
4099 || ((input_section->flags & SEC_DEBUGGING) != 0
4100 && h->def_dynamic)))
4101 /* Dynamic relocs are not propagated for SEC_DEBUGGING
4102 sections because such sections are not SEC_ALLOC and
4103 thus ld.so will not process them. */
4104 || (sec->output_section == NULL
4105 && ((input_section->flags & SEC_DEBUGGING) != 0
4107 || (sec->output_section == NULL
4108 && (sh_elf_hash_entry (h)->got_type == GOT_TLS_IE
4109 || sh_elf_hash_entry (h)->got_type == GOT_TLS_GD)))
4111 else if (sec->output_section != NULL)
4112 relocation = ((h->root.u.def.value
4113 + sec->output_section->vma
4114 + sec->output_offset)
4115 /* A STO_SH5_ISA32 causes a "bitor 1" to the
4116 symbol value, unless we've seen
4117 STT_DATALABEL on the way to it. */
4118 | ((h->other & STO_SH5_ISA32) != 0
4119 && ! seen_stt_datalabel));
4120 else if (!bfd_link_relocatable (info)
4121 && (_bfd_elf_section_offset (output_bfd, info,
4127 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4130 (long) rel->r_offset,
4132 h->root.root.string);
4136 else if (h->root.type == bfd_link_hash_undefweak)
4138 else if (info->unresolved_syms_in_objects == RM_IGNORE
4139 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
4141 else if (!bfd_link_relocatable (info))
4142 (*info->callbacks->undefined_symbol)
4143 (info, h->root.root.string, input_bfd,
4144 input_section, rel->r_offset,
4145 (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
4146 || ELF_ST_VISIBILITY (h->other)));
4149 if (sec != NULL && discarded_section (sec))
4150 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
4151 rel, 1, relend, howto, 0, contents);
4153 if (bfd_link_relocatable (info))
4156 /* Check for inter-segment relocations in FDPIC files. Most
4157 relocations connect the relocation site to the location of
4158 the target symbol, but there are some exceptions below. */
4159 check_segment[0] = isec_segment;
4161 check_segment[1] = sh_elf_osec_to_segment (output_bfd,
4162 sec->output_section);
4164 check_segment[1] = -1;
4166 switch ((int) r_type)
4168 final_link_relocate:
4169 /* COFF relocs don't use the addend. The addend is used for
4170 R_SH_DIR32 to be compatible with other compilers. */
4171 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
4172 contents, rel->r_offset,
4173 relocation, addend);
4177 goto final_link_relocate;
4182 /* If the reloc is against the start of this section, then
4183 the assembler has already taken care of it and the reloc
4184 is here only to assist in relaxing. If the reloc is not
4185 against the start of this section, then it's against an
4186 external symbol and we must deal with it ourselves. */
4187 if (input_section->output_section->vma + input_section->output_offset
4190 int disp = (relocation
4191 - input_section->output_section->vma
4192 - input_section->output_offset
4198 case R_SH_DIR8WPZ: mask = 1; break;
4199 case R_SH_DIR8WPL: mask = 3; break;
4200 default: mask = 0; break;
4205 (_("%B: 0x%lx: fatal: unaligned branch target for relax-support relocation"),
4206 input_section->owner,
4207 (unsigned long) rel->r_offset);
4208 bfd_set_error (bfd_error_bad_value);
4212 goto final_link_relocate;
4218 #ifdef INCLUDE_SHMEDIA
4219 if (shmedia_prepare_reloc (info, input_bfd, input_section,
4220 contents, rel, &relocation))
4221 goto final_link_relocate;
4223 bfd_set_error (bfd_error_bad_value);
4231 goto final_link_relocate;
4238 (_("%B: 0x%lx: fatal: unaligned %s relocation 0x%lx"),
4239 input_section->owner,
4240 (unsigned long) rel->r_offset, howto->name,
4241 (unsigned long) relocation);
4242 bfd_set_error (bfd_error_bad_value);
4245 goto final_link_relocate;
4253 (_("%B: 0x%lx: fatal: unaligned %s relocation 0x%lx"),
4254 input_section->owner,
4255 (unsigned long) rel->r_offset, howto->name,
4256 (unsigned long) relocation);
4257 bfd_set_error (bfd_error_bad_value);
4260 goto final_link_relocate;
4263 if ((signed int)relocation < -32
4264 || (signed int)relocation > 32)
4267 (_("%B: 0x%lx: fatal: R_SH_PSHA relocation %d not in range -32..32"),
4268 input_section->owner,
4269 (unsigned long) rel->r_offset,
4270 (unsigned long) relocation);
4271 bfd_set_error (bfd_error_bad_value);
4274 goto final_link_relocate;
4277 if ((signed int)relocation < -16
4278 || (signed int)relocation > 16)
4281 (_("%B: 0x%lx: fatal: R_SH_PSHL relocation %d not in range -32..32"),
4282 input_section->owner,
4283 (unsigned long) rel->r_offset,
4284 (unsigned long) relocation);
4285 bfd_set_error (bfd_error_bad_value);
4288 goto final_link_relocate;
4292 #ifdef INCLUDE_SHMEDIA
4293 case R_SH_IMM_LOW16_PCREL:
4294 case R_SH_IMM_MEDLOW16_PCREL:
4295 case R_SH_IMM_MEDHI16_PCREL:
4296 case R_SH_IMM_HI16_PCREL:
4298 if (bfd_link_pic (info)
4300 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4301 || h->root.type != bfd_link_hash_undefweak)
4302 && r_symndx != STN_UNDEF
4303 && (input_section->flags & SEC_ALLOC) != 0
4305 && (r_type == R_SH_DIR32
4306 || !SYMBOL_CALLS_LOCAL (info, h)))
4308 Elf_Internal_Rela outrel;
4310 bfd_boolean skip, relocate;
4312 /* When generating a shared object, these relocations
4313 are copied into the output file to be resolved at run
4318 sreloc = _bfd_elf_get_dynamic_reloc_section
4319 (input_bfd, input_section, /*rela?*/ TRUE);
4328 _bfd_elf_section_offset (output_bfd, info, input_section,
4330 if (outrel.r_offset == (bfd_vma) -1)
4332 else if (outrel.r_offset == (bfd_vma) -2)
4333 skip = TRUE, relocate = TRUE;
4334 outrel.r_offset += (input_section->output_section->vma
4335 + input_section->output_offset);
4338 memset (&outrel, 0, sizeof outrel);
4339 else if (r_type == R_SH_REL32)
4341 BFD_ASSERT (h != NULL && h->dynindx != -1);
4342 outrel.r_info = ELF32_R_INFO (h->dynindx, R_SH_REL32);
4344 = (howto->partial_inplace
4345 ? bfd_get_32 (input_bfd, contents + rel->r_offset)
4348 #ifdef INCLUDE_SHMEDIA
4349 else if (r_type == R_SH_IMM_LOW16_PCREL
4350 || r_type == R_SH_IMM_MEDLOW16_PCREL
4351 || r_type == R_SH_IMM_MEDHI16_PCREL
4352 || r_type == R_SH_IMM_HI16_PCREL)
4354 BFD_ASSERT (h != NULL && h->dynindx != -1);
4355 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
4356 outrel.r_addend = addend;
4361 || ((info->symbolic || h->dynindx == -1)
4362 && h->def_regular)))
4366 BFD_ASSERT (sec != NULL);
4367 BFD_ASSERT (sec->output_section != NULL);
4368 dynindx = elf_section_data (sec->output_section)->dynindx;
4369 outrel.r_info = ELF32_R_INFO (dynindx, R_SH_DIR32);
4370 outrel.r_addend = relocation;
4372 += (howto->partial_inplace
4373 ? bfd_get_32 (input_bfd, contents + rel->r_offset)
4375 outrel.r_addend -= sec->output_section->vma;
4379 /* h->dynindx may be -1 if this symbol was marked to
4382 || ((info->symbolic || h->dynindx == -1)
4385 relocate = howto->partial_inplace;
4386 outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
4390 BFD_ASSERT (h->dynindx != -1);
4391 outrel.r_info = ELF32_R_INFO (h->dynindx, R_SH_DIR32);
4393 outrel.r_addend = relocation;
4395 += (howto->partial_inplace
4396 ? bfd_get_32 (input_bfd, contents + rel->r_offset)
4400 loc = sreloc->contents;
4401 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
4402 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
4404 check_segment[0] = check_segment[1] = -1;
4406 /* If this reloc is against an external symbol, we do
4407 not want to fiddle with the addend. Otherwise, we
4408 need to include the symbol value so that it becomes
4409 an addend for the dynamic reloc. */
4413 else if (fdpic_p && !bfd_link_pic (info)
4414 && r_type == R_SH_DIR32
4415 && (input_section->flags & SEC_ALLOC) != 0)
4421 if (sh_elf_osec_readonly_p (output_bfd,
4422 input_section->output_section))
4425 (_("%B(%A+0x%lx): cannot emit fixup to `%s' in read-only section"),
4428 (long) rel->r_offset,
4433 offset = _bfd_elf_section_offset (output_bfd, info,
4434 input_section, rel->r_offset);
4435 if (offset != (bfd_vma)-1)
4436 sh_elf_add_rofixup (output_bfd, htab->srofixup,
4437 input_section->output_section->vma
4438 + input_section->output_offset
4441 check_segment[0] = check_segment[1] = -1;
4443 /* We don't want warnings for non-NULL tests on undefined weak
4445 else if (r_type == R_SH_REL32
4447 && h->root.type == bfd_link_hash_undefweak)
4448 check_segment[0] = check_segment[1] = -1;
4449 goto final_link_relocate;
4452 #ifdef INCLUDE_SHMEDIA
4453 case R_SH_GOTPLT_LOW16:
4454 case R_SH_GOTPLT_MEDLOW16:
4455 case R_SH_GOTPLT_MEDHI16:
4456 case R_SH_GOTPLT_HI16:
4457 case R_SH_GOTPLT10BY4:
4458 case R_SH_GOTPLT10BY8:
4460 /* Relocation is to the entry for this symbol in the
4461 procedure linkage table. */
4465 || ! bfd_link_pic (info)
4468 || h->plt.offset == (bfd_vma) -1
4469 || h->got.offset != (bfd_vma) -1)
4472 /* Relocation is to the entry for this symbol in the global
4473 offset table extension for the procedure linkage table. */
4476 BFD_ASSERT (sgotplt != NULL);
4477 relocation = (sgotplt->output_offset
4478 + (get_plt_index (htab->plt_info, h->plt.offset)
4482 relocation -= GOT_BIAS;
4485 goto final_link_relocate;
4490 #ifdef INCLUDE_SHMEDIA
4491 case R_SH_GOT_LOW16:
4492 case R_SH_GOT_MEDLOW16:
4493 case R_SH_GOT_MEDHI16:
4498 /* Relocation is to the entry for this symbol in the global
4502 BFD_ASSERT (sgot != NULL);
4503 check_segment[0] = check_segment[1] = -1;
4509 off = h->got.offset;
4510 #ifdef INCLUDE_SHMEDIA
4511 if (seen_stt_datalabel)
4513 struct elf_sh_link_hash_entry *hsh;
4515 hsh = (struct elf_sh_link_hash_entry *)h;
4516 off = hsh->datalabel_got.offset;
4519 BFD_ASSERT (off != (bfd_vma) -1);
4521 dyn = htab->root.dynamic_sections_created;
4522 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
4523 bfd_link_pic (info),
4525 || (bfd_link_pic (info)
4526 && SYMBOL_REFERENCES_LOCAL (info, h))
4527 || (ELF_ST_VISIBILITY (h->other)
4528 && h->root.type == bfd_link_hash_undefweak))
4530 /* This is actually a static link, or it is a
4531 -Bsymbolic link and the symbol is defined
4532 locally, or the symbol was forced to be local
4533 because of a version file. We must initialize
4534 this entry in the global offset table. Since the
4535 offset must always be a multiple of 4, we use the
4536 least significant bit to record whether we have
4537 initialized it already.
4539 When doing a dynamic link, we create a .rela.got
4540 relocation entry to initialize the value. This
4541 is done in the finish_dynamic_symbol routine. */
4546 bfd_put_32 (output_bfd, relocation,
4547 sgot->contents + off);
4548 #ifdef INCLUDE_SHMEDIA
4549 if (seen_stt_datalabel)
4551 struct elf_sh_link_hash_entry *hsh;
4553 hsh = (struct elf_sh_link_hash_entry *)h;
4554 hsh->datalabel_got.offset |= 1;
4560 /* If we initialize the GOT entry here with a valid
4561 symbol address, also add a fixup. */
4562 if (fdpic_p && !bfd_link_pic (info)
4563 && sh_elf_hash_entry (h)->got_type == GOT_NORMAL
4564 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4565 || h->root.type != bfd_link_hash_undefweak))
4566 sh_elf_add_rofixup (output_bfd, htab->srofixup,
4567 sgot->output_section->vma
4568 + sgot->output_offset
4573 relocation = sh_elf_got_offset (htab) + off;
4577 #ifdef INCLUDE_SHMEDIA
4580 BFD_ASSERT (local_got_offsets != NULL
4581 && (local_got_offsets[symtab_hdr->sh_info
4585 off = local_got_offsets[symtab_hdr->sh_info
4591 BFD_ASSERT (local_got_offsets != NULL
4592 && local_got_offsets[r_symndx] != (bfd_vma) -1);
4594 off = local_got_offsets[r_symndx];
4595 #ifdef INCLUDE_SHMEDIA
4599 /* The offset must always be a multiple of 4. We use
4600 the least significant bit to record whether we have
4601 already generated the necessary reloc. */
4606 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
4608 if (bfd_link_pic (info))
4610 Elf_Internal_Rela outrel;
4613 if (srelgot == NULL)
4615 srelgot = bfd_get_linker_section (dynobj,
4617 BFD_ASSERT (srelgot != NULL);
4620 outrel.r_offset = (sgot->output_section->vma
4621 + sgot->output_offset
4626 = elf_section_data (sec->output_section)->dynindx;
4627 outrel.r_info = ELF32_R_INFO (dynindx, R_SH_DIR32);
4628 outrel.r_addend = relocation;
4629 outrel.r_addend -= sec->output_section->vma;
4633 outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
4634 outrel.r_addend = relocation;
4636 loc = srelgot->contents;
4637 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
4638 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
4641 && (sh_elf_local_got_type (input_bfd) [r_symndx]
4643 sh_elf_add_rofixup (output_bfd, htab->srofixup,
4644 sgot->output_section->vma
4645 + sgot->output_offset
4648 #ifdef INCLUDE_SHMEDIA
4650 local_got_offsets[symtab_hdr->sh_info + r_symndx] |= 1;
4653 local_got_offsets[r_symndx] |= 1;
4656 relocation = sh_elf_got_offset (htab) + off;
4660 relocation -= GOT_BIAS;
4663 if (r_type == R_SH_GOT20)
4665 r = install_movi20_field (output_bfd, relocation + addend,
4666 input_bfd, input_section, contents,
4671 goto final_link_relocate;
4675 #ifdef INCLUDE_SHMEDIA
4676 case R_SH_GOTOFF_LOW16:
4677 case R_SH_GOTOFF_MEDLOW16:
4678 case R_SH_GOTOFF_MEDHI16:
4679 case R_SH_GOTOFF_HI16:
4681 /* GOTOFF relocations are relative to _GLOBAL_OFFSET_TABLE_, which
4682 we place at the start of the .got.plt section. This is the same
4683 as the start of the output .got section, unless there are function
4684 descriptors in front of it. */
4686 BFD_ASSERT (sgotplt != NULL);
4687 check_segment[0] = got_segment;
4688 relocation -= sgotplt->output_section->vma + sgotplt->output_offset
4689 + htab->root.hgot->root.u.def.value;
4692 relocation -= GOT_BIAS;
4695 addend = rel->r_addend;
4697 if (r_type == R_SH_GOTOFF20)
4699 r = install_movi20_field (output_bfd, relocation + addend,
4700 input_bfd, input_section, contents,
4705 goto final_link_relocate;
4708 #ifdef INCLUDE_SHMEDIA
4709 case R_SH_GOTPC_LOW16:
4710 case R_SH_GOTPC_MEDLOW16:
4711 case R_SH_GOTPC_MEDHI16:
4712 case R_SH_GOTPC_HI16:
4714 /* Use global offset table as symbol value. */
4716 BFD_ASSERT (sgotplt != NULL);
4717 relocation = sgotplt->output_section->vma + sgotplt->output_offset;
4720 relocation += GOT_BIAS;
4723 addend = rel->r_addend;
4725 goto final_link_relocate;
4728 #ifdef INCLUDE_SHMEDIA
4729 case R_SH_PLT_LOW16:
4730 case R_SH_PLT_MEDLOW16:
4731 case R_SH_PLT_MEDHI16:
4734 /* Relocation is to the entry for this symbol in the
4735 procedure linkage table. */
4737 /* Resolve a PLT reloc against a local symbol directly,
4738 without using the procedure linkage table. */
4740 goto final_link_relocate;
4742 /* We don't want to warn on calls to undefined weak symbols,
4743 as calls to them must be protected by non-NULL tests
4744 anyway, and unprotected calls would invoke undefined
4746 if (h->root.type == bfd_link_hash_undefweak)
4747 check_segment[0] = check_segment[1] = -1;
4749 if (h->forced_local)
4750 goto final_link_relocate;
4752 if (h->plt.offset == (bfd_vma) -1)
4754 /* We didn't make a PLT entry for this symbol. This
4755 happens when statically linking PIC code, or when
4756 using -Bsymbolic. */
4757 goto final_link_relocate;
4760 BFD_ASSERT (splt != NULL);
4761 check_segment[1] = plt_segment;
4762 relocation = (splt->output_section->vma
4763 + splt->output_offset
4766 #ifdef INCLUDE_SHMEDIA
4770 addend = rel->r_addend;
4772 goto final_link_relocate;
4774 /* Relocation is to the canonical function descriptor for this
4775 symbol, possibly via the GOT. Initialize the GOT
4776 entry and function descriptor if necessary. */
4777 case R_SH_GOTFUNCDESC:
4778 case R_SH_GOTFUNCDESC20:
4782 asection *reloc_section;
4783 bfd_vma reloc_offset;
4784 int reloc_type = R_SH_FUNCDESC;
4788 check_segment[0] = check_segment[1] = -1;
4790 /* FIXME: See what FRV does for global symbols in the
4791 executable, with --export-dynamic. Do they need ld.so
4792 to allocate official descriptors? See what this code
4798 if (r_type == R_SH_FUNCDESC)
4800 reloc_section = input_section;
4801 reloc_offset = rel->r_offset;
4805 reloc_section = sgot;
4808 reloc_offset = h->got.offset;
4811 BFD_ASSERT (local_got_offsets != NULL);
4812 reloc_offset = local_got_offsets[r_symndx];
4814 BFD_ASSERT (reloc_offset != MINUS_ONE);
4816 if (reloc_offset & 1)
4819 goto funcdesc_done_got;
4823 if (h && h->root.type == bfd_link_hash_undefweak
4824 && (SYMBOL_CALLS_LOCAL (info, h)
4825 || !htab->root.dynamic_sections_created))
4826 /* Undefined weak symbol which will not be dynamically
4827 resolved later; leave it at zero. */
4828 goto funcdesc_leave_zero;
4829 else if (SYMBOL_CALLS_LOCAL (info, h)
4830 && ! SYMBOL_FUNCDESC_LOCAL (info, h))
4832 /* If the symbol needs a non-local function descriptor
4833 but binds locally (i.e., its visibility is
4834 protected), emit a dynamic relocation decayed to
4835 section+offset. This is an optimization; the dynamic
4836 linker would resolve our function descriptor request
4837 to our copy of the function anyway. */
4838 dynindx = elf_section_data (h->root.u.def.section
4839 ->output_section)->dynindx;
4840 relocation += h->root.u.def.section->output_offset
4841 + h->root.u.def.value;
4843 else if (! SYMBOL_FUNCDESC_LOCAL (info, h))
4845 /* If the symbol is dynamic and there will be dynamic
4846 symbol resolution because we are or are linked with a
4847 shared library, emit a FUNCDESC relocation such that
4848 the dynamic linker will allocate the function
4850 BFD_ASSERT (h->dynindx != -1);
4851 dynindx = h->dynindx;
4857 /* Otherwise, we know we have a private function
4858 descriptor, so reference it directly. */
4859 reloc_type = R_SH_DIR32;
4860 dynindx = elf_section_data (htab->sfuncdesc
4861 ->output_section)->dynindx;
4865 offset = sh_elf_hash_entry (h)->funcdesc.offset;
4866 BFD_ASSERT (offset != MINUS_ONE);
4867 if ((offset & 1) == 0)
4869 if (!sh_elf_initialize_funcdesc (output_bfd, info, h,
4872 sh_elf_hash_entry (h)->funcdesc.offset |= 1;
4877 union gotref *local_funcdesc;
4879 local_funcdesc = sh_elf_local_funcdesc (input_bfd);
4880 offset = local_funcdesc[r_symndx].offset;
4881 BFD_ASSERT (offset != MINUS_ONE);
4882 if ((offset & 1) == 0)
4884 if (!sh_elf_initialize_funcdesc (output_bfd, info, NULL,
4888 local_funcdesc[r_symndx].offset |= 1;
4892 relocation = htab->sfuncdesc->output_offset + (offset & ~1);
4895 if (!bfd_link_pic (info) && SYMBOL_FUNCDESC_LOCAL (info, h))
4899 if (sh_elf_osec_readonly_p (output_bfd,
4900 reloc_section->output_section))
4903 (_("%B(%A+0x%lx): cannot emit fixup to `%s' in read-only section"),
4906 (long) rel->r_offset,
4911 offset = _bfd_elf_section_offset (output_bfd, info,
4912 reloc_section, reloc_offset);
4914 if (offset != (bfd_vma)-1)
4915 sh_elf_add_rofixup (output_bfd, htab->srofixup,
4917 + reloc_section->output_section->vma
4918 + reloc_section->output_offset);
4920 else if ((reloc_section->output_section->flags
4921 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
4925 if (sh_elf_osec_readonly_p (output_bfd,
4926 reloc_section->output_section))
4928 info->callbacks->warning
4930 _("cannot emit dynamic relocations in read-only section"),
4931 symname, input_bfd, reloc_section, reloc_offset);
4935 if (srelgot == NULL)
4937 srelgot = bfd_get_linker_section (dynobj, ".rela.got");
4938 BFD_ASSERT (srelgot != NULL);
4941 offset = _bfd_elf_section_offset (output_bfd, info,
4942 reloc_section, reloc_offset);
4944 if (offset != (bfd_vma)-1)
4945 sh_elf_add_dyn_reloc (output_bfd, srelgot,
4947 + reloc_section->output_section->vma
4948 + reloc_section->output_offset,
4949 reloc_type, dynindx, relocation);
4951 if (r_type == R_SH_FUNCDESC)
4959 goto funcdesc_leave_zero;
4963 if (SYMBOL_FUNCDESC_LOCAL (info, h))
4964 relocation += htab->sfuncdesc->output_section->vma;
4965 funcdesc_leave_zero:
4966 if (r_type != R_SH_FUNCDESC)
4968 bfd_put_32 (output_bfd, relocation,
4969 reloc_section->contents + reloc_offset);
4973 local_got_offsets[r_symndx] |= 1;
4977 relocation = sh_elf_got_offset (htab) + reloc_offset;
4979 relocation -= GOT_BIAS;
4982 if (r_type == R_SH_GOTFUNCDESC20)
4984 r = install_movi20_field (output_bfd, relocation + addend,
4985 input_bfd, input_section, contents,
4990 goto final_link_relocate;
4994 case R_SH_GOTOFFFUNCDESC:
4995 case R_SH_GOTOFFFUNCDESC20:
4996 /* FIXME: See R_SH_FUNCDESC comment about global symbols in the
4997 executable and --export-dynamic. If such symbols get
4998 ld.so-allocated descriptors we can not use R_SH_GOTOFFFUNCDESC
5002 check_segment[0] = check_segment[1] = -1;
5004 addend = rel->r_addend;
5006 if (h && (h->root.type == bfd_link_hash_undefweak
5007 || !SYMBOL_FUNCDESC_LOCAL (info, h)))
5010 (_("%B(%A+0x%lx): %s relocation against external symbol \"%s\""),
5011 input_bfd, input_section, (long) rel->r_offset, howto->name,
5012 h->root.root.string);
5019 /* Otherwise, we know we have a private function
5020 descriptor, so reference it directly. */
5023 offset = sh_elf_hash_entry (h)->funcdesc.offset;
5024 BFD_ASSERT (offset != MINUS_ONE);
5025 if ((offset & 1) == 0)
5027 if (!sh_elf_initialize_funcdesc (output_bfd, info, h,
5030 sh_elf_hash_entry (h)->funcdesc.offset |= 1;
5035 union gotref *local_funcdesc;
5037 local_funcdesc = sh_elf_local_funcdesc (input_bfd);
5038 offset = local_funcdesc[r_symndx].offset;
5039 BFD_ASSERT (offset != MINUS_ONE);
5040 if ((offset & 1) == 0)
5042 if (!sh_elf_initialize_funcdesc (output_bfd, info, NULL,
5046 local_funcdesc[r_symndx].offset |= 1;
5050 relocation = htab->sfuncdesc->output_offset + (offset & ~1);
5053 relocation -= (htab->root.hgot->root.u.def.value
5054 + sgotplt->output_offset);
5056 relocation -= GOT_BIAS;
5059 if (r_type == R_SH_GOTOFFFUNCDESC20)
5061 r = install_movi20_field (output_bfd, relocation + addend,
5062 input_bfd, input_section, contents,
5067 goto final_link_relocate;
5069 case R_SH_LOOP_START:
5071 static bfd_vma start, end;
5073 start = (relocation + rel->r_addend
5074 - (sec->output_section->vma + sec->output_offset));
5075 r = sh_elf_reloc_loop (r_type, input_bfd, input_section, contents,
5076 rel->r_offset, sec, start, end);
5080 end = (relocation + rel->r_addend
5081 - (sec->output_section->vma + sec->output_offset));
5082 r = sh_elf_reloc_loop (r_type, input_bfd, input_section, contents,
5083 rel->r_offset, sec, start, end);
5087 case R_SH_TLS_GD_32:
5088 case R_SH_TLS_IE_32:
5090 check_segment[0] = check_segment[1] = -1;
5091 r_type = sh_elf_optimized_tls_reloc (info, r_type, h == NULL);
5092 got_type = GOT_UNKNOWN;
5093 if (h == NULL && local_got_offsets)
5094 got_type = sh_elf_local_got_type (input_bfd) [r_symndx];
5097 got_type = sh_elf_hash_entry (h)->got_type;
5098 if (! bfd_link_pic (info)
5099 && (h->dynindx == -1
5101 r_type = R_SH_TLS_LE_32;
5104 if (r_type == R_SH_TLS_GD_32 && got_type == GOT_TLS_IE)
5105 r_type = R_SH_TLS_IE_32;
5107 if (r_type == R_SH_TLS_LE_32)
5110 unsigned short insn;
5112 if (ELF32_R_TYPE (rel->r_info) == R_SH_TLS_GD_32)
5114 /* GD->LE transition:
5115 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5116 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5117 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5119 mov.l 1f,r4; stc gbr,r0; add r4,r0; nop;
5121 1: .long x@TPOFF; 2: .long __tls_get_addr@PLT; 3:. */
5123 offset = rel->r_offset;
5124 BFD_ASSERT (offset >= 16);
5125 /* Size of GD instructions is 16 or 18. */
5127 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5128 if ((insn & 0xff00) == 0xc700)
5130 BFD_ASSERT (offset >= 2);
5132 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5135 BFD_ASSERT ((insn & 0xff00) == 0xd400);
5136 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5137 BFD_ASSERT ((insn & 0xff00) == 0xc700);
5138 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5139 BFD_ASSERT ((insn & 0xff00) == 0xd100);
5140 insn = bfd_get_16 (input_bfd, contents + offset + 6);
5141 BFD_ASSERT (insn == 0x310c);
5142 insn = bfd_get_16 (input_bfd, contents + offset + 8);
5143 BFD_ASSERT (insn == 0x410b);
5144 insn = bfd_get_16 (input_bfd, contents + offset + 10);
5145 BFD_ASSERT (insn == 0x34cc);
5147 bfd_put_16 (output_bfd, 0x0012, contents + offset + 2);
5148 bfd_put_16 (output_bfd, 0x304c, contents + offset + 4);
5149 bfd_put_16 (output_bfd, 0x0009, contents + offset + 6);
5150 bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
5151 bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
5157 /* IE->LE transition:
5158 mov.l 1f,r0; stc gbr,rN; mov.l @(r0,r12),rM;
5159 bra 2f; add ...; .align 2; 1: x@GOTTPOFF; 2:
5161 mov.l .Ln,rM; stc gbr,rN; nop; ...;
5164 offset = rel->r_offset;
5165 BFD_ASSERT (offset >= 16);
5166 /* Size of IE instructions is 10 or 12. */
5168 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5169 if ((insn & 0xf0ff) == 0x0012)
5171 BFD_ASSERT (offset >= 2);
5173 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5176 BFD_ASSERT ((insn & 0xff00) == 0xd000);
5177 target = insn & 0x00ff;
5178 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5179 BFD_ASSERT ((insn & 0xf0ff) == 0x0012);
5180 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5181 BFD_ASSERT ((insn & 0xf0ff) == 0x00ce);
5182 insn = 0xd000 | (insn & 0x0f00) | target;
5183 bfd_put_16 (output_bfd, insn, contents + offset + 0);
5184 bfd_put_16 (output_bfd, 0x0009, contents + offset + 4);
5187 bfd_put_32 (output_bfd, tpoff (info, relocation),
5188 contents + rel->r_offset);
5192 if (sgot == NULL || sgotplt == NULL)
5196 off = h->got.offset;
5199 if (local_got_offsets == NULL)
5202 off = local_got_offsets[r_symndx];
5205 /* Relocate R_SH_TLS_IE_32 directly when statically linking. */
5206 if (r_type == R_SH_TLS_IE_32
5207 && ! htab->root.dynamic_sections_created)
5210 bfd_put_32 (output_bfd, tpoff (info, relocation),
5211 sgot->contents + off);
5212 bfd_put_32 (output_bfd, sh_elf_got_offset (htab) + off,
5213 contents + rel->r_offset);
5221 Elf_Internal_Rela outrel;
5225 if (srelgot == NULL)
5227 srelgot = bfd_get_linker_section (dynobj, ".rela.got");
5228 BFD_ASSERT (srelgot != NULL);
5231 outrel.r_offset = (sgot->output_section->vma
5232 + sgot->output_offset + off);
5234 if (h == NULL || h->dynindx == -1)
5239 dr_type = (r_type == R_SH_TLS_GD_32 ? R_SH_TLS_DTPMOD32 :
5241 if (dr_type == R_SH_TLS_TPOFF32 && indx == 0)
5242 outrel.r_addend = relocation - dtpoff_base (info);
5244 outrel.r_addend = 0;
5245 outrel.r_info = ELF32_R_INFO (indx, dr_type);
5246 loc = srelgot->contents;
5247 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
5248 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5250 if (r_type == R_SH_TLS_GD_32)
5254 bfd_put_32 (output_bfd,
5255 relocation - dtpoff_base (info),
5256 sgot->contents + off + 4);
5260 outrel.r_info = ELF32_R_INFO (indx,
5262 outrel.r_offset += 4;
5263 outrel.r_addend = 0;
5264 srelgot->reloc_count++;
5265 loc += sizeof (Elf32_External_Rela);
5266 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5273 local_got_offsets[r_symndx] |= 1;
5276 if (off >= (bfd_vma) -2)
5279 if (r_type == (int) ELF32_R_TYPE (rel->r_info))
5280 relocation = sh_elf_got_offset (htab) + off;
5284 unsigned short insn;
5286 /* GD->IE transition:
5287 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5288 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5289 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5291 mov.l 1f,r0; stc gbr,r4; mov.l @(r0,r12),r0; add r4,r0;
5292 nop; nop; bra 3f; nop; .align 2;
5293 1: .long x@TPOFF; 2:...; 3:. */
5295 offset = rel->r_offset;
5296 BFD_ASSERT (offset >= 16);
5297 /* Size of GD instructions is 16 or 18. */
5299 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5300 if ((insn & 0xff00) == 0xc700)
5302 BFD_ASSERT (offset >= 2);
5304 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5307 BFD_ASSERT ((insn & 0xff00) == 0xd400);
5309 /* Replace mov.l 1f,R4 with mov.l 1f,r0. */
5310 bfd_put_16 (output_bfd, insn & 0xf0ff, contents + offset);
5312 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5313 BFD_ASSERT ((insn & 0xff00) == 0xc700);
5314 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5315 BFD_ASSERT ((insn & 0xff00) == 0xd100);
5316 insn = bfd_get_16 (input_bfd, contents + offset + 6);
5317 BFD_ASSERT (insn == 0x310c);
5318 insn = bfd_get_16 (input_bfd, contents + offset + 8);
5319 BFD_ASSERT (insn == 0x410b);
5320 insn = bfd_get_16 (input_bfd, contents + offset + 10);
5321 BFD_ASSERT (insn == 0x34cc);
5323 bfd_put_16 (output_bfd, 0x0412, contents + offset + 2);
5324 bfd_put_16 (output_bfd, 0x00ce, contents + offset + 4);
5325 bfd_put_16 (output_bfd, 0x304c, contents + offset + 6);
5326 bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
5327 bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
5329 bfd_put_32 (output_bfd, sh_elf_got_offset (htab) + off,
5330 contents + rel->r_offset);
5335 addend = rel->r_addend;
5337 goto final_link_relocate;
5339 case R_SH_TLS_LD_32:
5341 check_segment[0] = check_segment[1] = -1;
5342 if (! bfd_link_pic (info))
5345 unsigned short insn;
5347 /* LD->LE transition:
5348 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5349 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5350 1: .long x$TLSLD; 2: .long __tls_get_addr@PLT; 3:
5352 stc gbr,r0; nop; nop; nop;
5353 nop; nop; bra 3f; ...; 3:. */
5355 offset = rel->r_offset;
5356 BFD_ASSERT (offset >= 16);
5357 /* Size of LD instructions is 16 or 18. */
5359 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5360 if ((insn & 0xff00) == 0xc700)
5362 BFD_ASSERT (offset >= 2);
5364 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5367 BFD_ASSERT ((insn & 0xff00) == 0xd400);
5368 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5369 BFD_ASSERT ((insn & 0xff00) == 0xc700);
5370 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5371 BFD_ASSERT ((insn & 0xff00) == 0xd100);
5372 insn = bfd_get_16 (input_bfd, contents + offset + 6);
5373 BFD_ASSERT (insn == 0x310c);
5374 insn = bfd_get_16 (input_bfd, contents + offset + 8);
5375 BFD_ASSERT (insn == 0x410b);
5376 insn = bfd_get_16 (input_bfd, contents + offset + 10);
5377 BFD_ASSERT (insn == 0x34cc);
5379 bfd_put_16 (output_bfd, 0x0012, contents + offset + 0);
5380 bfd_put_16 (output_bfd, 0x0009, contents + offset + 2);
5381 bfd_put_16 (output_bfd, 0x0009, contents + offset + 4);
5382 bfd_put_16 (output_bfd, 0x0009, contents + offset + 6);
5383 bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
5384 bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
5389 if (sgot == NULL || sgotplt == NULL)
5392 off = htab->tls_ldm_got.offset;
5397 Elf_Internal_Rela outrel;
5400 srelgot = htab->srelgot;
5401 if (srelgot == NULL)
5404 outrel.r_offset = (sgot->output_section->vma
5405 + sgot->output_offset + off);
5406 outrel.r_addend = 0;
5407 outrel.r_info = ELF32_R_INFO (0, R_SH_TLS_DTPMOD32);
5408 loc = srelgot->contents;
5409 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
5410 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5411 htab->tls_ldm_got.offset |= 1;
5414 relocation = sh_elf_got_offset (htab) + off;
5415 addend = rel->r_addend;
5417 goto final_link_relocate;
5419 case R_SH_TLS_LDO_32:
5420 check_segment[0] = check_segment[1] = -1;
5421 if (! bfd_link_pic (info))
5422 relocation = tpoff (info, relocation);
5424 relocation -= dtpoff_base (info);
5426 addend = rel->r_addend;
5427 goto final_link_relocate;
5429 case R_SH_TLS_LE_32:
5432 Elf_Internal_Rela outrel;
5435 check_segment[0] = check_segment[1] = -1;
5437 if (!bfd_link_dll (info))
5439 relocation = tpoff (info, relocation);
5440 addend = rel->r_addend;
5441 goto final_link_relocate;
5446 sreloc = _bfd_elf_get_dynamic_reloc_section
5447 (input_bfd, input_section, /*rela?*/ TRUE);
5452 if (h == NULL || h->dynindx == -1)
5457 outrel.r_offset = (input_section->output_section->vma
5458 + input_section->output_offset
5460 outrel.r_info = ELF32_R_INFO (indx, R_SH_TLS_TPOFF32);
5462 outrel.r_addend = relocation - dtpoff_base (info);
5464 outrel.r_addend = 0;
5466 loc = sreloc->contents;
5467 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
5468 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5474 if (fdpic_p && check_segment[0] != (unsigned) -1
5475 && check_segment[0] != check_segment[1])
5477 /* We don't want duplicate errors for undefined symbols. */
5478 if (!h || h->root.type != bfd_link_hash_undefined)
5480 if (bfd_link_pic (info))
5482 info->callbacks->einfo
5483 (_("%X%C: relocation to \"%s\" references a different segment\n"),
5484 input_bfd, input_section, rel->r_offset, symname);
5488 info->callbacks->einfo
5489 (_("%C: warning: relocation to \"%s\" references a different segment\n"),
5490 input_bfd, input_section, rel->r_offset, symname);
5493 elf_elfheader (output_bfd)->e_flags |= EF_SH_PIC;
5496 if (r != bfd_reloc_ok)
5501 case bfd_reloc_outofrange:
5503 case bfd_reloc_overflow:
5511 name = (bfd_elf_string_from_elf_section
5512 (input_bfd, symtab_hdr->sh_link, sym->st_name));
5516 name = bfd_section_name (input_bfd, sec);
5518 (*info->callbacks->reloc_overflow)
5519 (info, (h ? &h->root : NULL), name, howto->name,
5520 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
5530 /* This is a version of bfd_generic_get_relocated_section_contents
5531 which uses sh_elf_relocate_section. */
5534 sh_elf_get_relocated_section_contents (bfd *output_bfd,
5535 struct bfd_link_info *link_info,
5536 struct bfd_link_order *link_order,
5538 bfd_boolean relocatable,
5541 Elf_Internal_Shdr *symtab_hdr;
5542 asection *input_section = link_order->u.indirect.section;
5543 bfd *input_bfd = input_section->owner;
5544 asection **sections = NULL;
5545 Elf_Internal_Rela *internal_relocs = NULL;
5546 Elf_Internal_Sym *isymbuf = NULL;
5548 /* We only need to handle the case of relaxing, or of having a
5549 particular set of section contents, specially. */
5551 || elf_section_data (input_section)->this_hdr.contents == NULL)
5552 return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
5557 symtab_hdr = &elf_symtab_hdr (input_bfd);
5559 memcpy (data, elf_section_data (input_section)->this_hdr.contents,
5560 (size_t) input_section->size);
5562 if ((input_section->flags & SEC_RELOC) != 0
5563 && input_section->reloc_count > 0)
5566 Elf_Internal_Sym *isym, *isymend;
5569 internal_relocs = (_bfd_elf_link_read_relocs
5570 (input_bfd, input_section, NULL,
5571 (Elf_Internal_Rela *) NULL, FALSE));
5572 if (internal_relocs == NULL)
5575 if (symtab_hdr->sh_info != 0)
5577 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
5578 if (isymbuf == NULL)
5579 isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
5580 symtab_hdr->sh_info, 0,
5582 if (isymbuf == NULL)
5586 amt = symtab_hdr->sh_info;
5587 amt *= sizeof (asection *);
5588 sections = (asection **) bfd_malloc (amt);
5589 if (sections == NULL && amt != 0)
5592 isymend = isymbuf + symtab_hdr->sh_info;
5593 for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp)
5597 if (isym->st_shndx == SHN_UNDEF)
5598 isec = bfd_und_section_ptr;
5599 else if (isym->st_shndx == SHN_ABS)
5600 isec = bfd_abs_section_ptr;
5601 else if (isym->st_shndx == SHN_COMMON)
5602 isec = bfd_com_section_ptr;
5604 isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
5609 if (! sh_elf_relocate_section (output_bfd, link_info, input_bfd,
5610 input_section, data, internal_relocs,
5614 if (sections != NULL)
5617 && symtab_hdr->contents != (unsigned char *) isymbuf)
5619 if (elf_section_data (input_section)->relocs != internal_relocs)
5620 free (internal_relocs);
5626 if (sections != NULL)
5629 && symtab_hdr->contents != (unsigned char *) isymbuf)
5631 if (internal_relocs != NULL
5632 && elf_section_data (input_section)->relocs != internal_relocs)
5633 free (internal_relocs);
5637 /* Return the base VMA address which should be subtracted from real addresses
5638 when resolving @dtpoff relocation.
5639 This is PT_TLS segment p_vaddr. */
5642 dtpoff_base (struct bfd_link_info *info)
5644 /* If tls_sec is NULL, we should have signalled an error already. */
5645 if (elf_hash_table (info)->tls_sec == NULL)
5647 return elf_hash_table (info)->tls_sec->vma;
5650 /* Return the relocation value for R_SH_TLS_TPOFF32.. */
5653 tpoff (struct bfd_link_info *info, bfd_vma address)
5655 /* If tls_sec is NULL, we should have signalled an error already. */
5656 if (elf_hash_table (info)->tls_sec == NULL)
5658 /* SH TLS ABI is variant I and static TLS block start just after tcbhead
5659 structure which has 2 pointer fields. */
5660 return (address - elf_hash_table (info)->tls_sec->vma
5661 + align_power ((bfd_vma) 8,
5662 elf_hash_table (info)->tls_sec->alignment_power));
5666 sh_elf_gc_mark_hook (asection *sec,
5667 struct bfd_link_info *info,
5668 Elf_Internal_Rela *rel,
5669 struct elf_link_hash_entry *h,
5670 Elf_Internal_Sym *sym)
5673 switch (ELF32_R_TYPE (rel->r_info))
5675 case R_SH_GNU_VTINHERIT:
5676 case R_SH_GNU_VTENTRY:
5680 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
5683 /* Copy the extra info we tack onto an elf_link_hash_entry. */
5686 sh_elf_copy_indirect_symbol (struct bfd_link_info *info,
5687 struct elf_link_hash_entry *dir,
5688 struct elf_link_hash_entry *ind)
5690 struct elf_sh_link_hash_entry *edir, *eind;
5692 edir = (struct elf_sh_link_hash_entry *) dir;
5693 eind = (struct elf_sh_link_hash_entry *) ind;
5695 if (eind->dyn_relocs != NULL)
5697 if (edir->dyn_relocs != NULL)
5699 struct elf_sh_dyn_relocs **pp;
5700 struct elf_sh_dyn_relocs *p;
5702 /* Add reloc counts against the indirect sym to the direct sym
5703 list. Merge any entries against the same section. */
5704 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
5706 struct elf_sh_dyn_relocs *q;
5708 for (q = edir->dyn_relocs; q != NULL; q = q->next)
5709 if (q->sec == p->sec)
5711 q->pc_count += p->pc_count;
5712 q->count += p->count;
5719 *pp = edir->dyn_relocs;
5722 edir->dyn_relocs = eind->dyn_relocs;
5723 eind->dyn_relocs = NULL;
5725 edir->gotplt_refcount = eind->gotplt_refcount;
5726 eind->gotplt_refcount = 0;
5727 #ifdef INCLUDE_SHMEDIA
5728 edir->datalabel_got.refcount += eind->datalabel_got.refcount;
5729 eind->datalabel_got.refcount = 0;
5731 edir->funcdesc.refcount += eind->funcdesc.refcount;
5732 eind->funcdesc.refcount = 0;
5733 edir->abs_funcdesc_refcount += eind->abs_funcdesc_refcount;
5734 eind->abs_funcdesc_refcount = 0;
5736 if (ind->root.type == bfd_link_hash_indirect
5737 && dir->got.refcount <= 0)
5739 edir->got_type = eind->got_type;
5740 eind->got_type = GOT_UNKNOWN;
5743 if (ind->root.type != bfd_link_hash_indirect
5744 && dir->dynamic_adjusted)
5746 /* If called to transfer flags for a weakdef during processing
5747 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
5748 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
5749 dir->ref_dynamic |= ind->ref_dynamic;
5750 dir->ref_regular |= ind->ref_regular;
5751 dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
5752 dir->needs_plt |= ind->needs_plt;
5755 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
5759 sh_elf_optimized_tls_reloc (struct bfd_link_info *info, int r_type,
5762 if (bfd_link_pic (info))
5767 case R_SH_TLS_GD_32:
5768 case R_SH_TLS_IE_32:
5770 return R_SH_TLS_LE_32;
5771 return R_SH_TLS_IE_32;
5772 case R_SH_TLS_LD_32:
5773 return R_SH_TLS_LE_32;
5779 /* Look through the relocs for a section during the first phase.
5780 Since we don't do .gots or .plts, we just need to consider the
5781 virtual table relocs for gc. */
5784 sh_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
5785 const Elf_Internal_Rela *relocs)
5787 Elf_Internal_Shdr *symtab_hdr;
5788 struct elf_link_hash_entry **sym_hashes;
5789 struct elf_sh_link_hash_table *htab;
5790 const Elf_Internal_Rela *rel;
5791 const Elf_Internal_Rela *rel_end;
5793 unsigned int r_type;
5794 enum got_type got_type, old_got_type;
5798 if (bfd_link_relocatable (info))
5801 BFD_ASSERT (is_sh_elf (abfd));
5803 symtab_hdr = &elf_symtab_hdr (abfd);
5804 sym_hashes = elf_sym_hashes (abfd);
5806 htab = sh_elf_hash_table (info);
5810 rel_end = relocs + sec->reloc_count;
5811 for (rel = relocs; rel < rel_end; rel++)
5813 struct elf_link_hash_entry *h;
5814 unsigned long r_symndx;
5815 #ifdef INCLUDE_SHMEDIA
5816 int seen_stt_datalabel = 0;
5819 r_symndx = ELF32_R_SYM (rel->r_info);
5820 r_type = ELF32_R_TYPE (rel->r_info);
5822 if (r_symndx < symtab_hdr->sh_info)
5826 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5827 while (h->root.type == bfd_link_hash_indirect
5828 || h->root.type == bfd_link_hash_warning)
5830 #ifdef INCLUDE_SHMEDIA
5831 seen_stt_datalabel |= h->type == STT_DATALABEL;
5833 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5836 /* PR15323, ref flags aren't set for references in the same
5838 h->root.non_ir_ref = 1;
5841 r_type = sh_elf_optimized_tls_reloc (info, r_type, h == NULL);
5842 if (! bfd_link_pic (info)
5843 && r_type == R_SH_TLS_IE_32
5845 && h->root.type != bfd_link_hash_undefined
5846 && h->root.type != bfd_link_hash_undefweak
5847 && (h->dynindx == -1
5849 r_type = R_SH_TLS_LE_32;
5854 case R_SH_GOTOFFFUNCDESC:
5855 case R_SH_GOTOFFFUNCDESC20:
5857 case R_SH_GOTFUNCDESC:
5858 case R_SH_GOTFUNCDESC20:
5861 if (h->dynindx == -1)
5862 switch (ELF_ST_VISIBILITY (h->other))
5868 bfd_elf_link_record_dynamic_symbol (info, h);
5875 /* Some relocs require a global offset table. */
5876 if (htab->sgot == NULL)
5881 /* This may require an rofixup. */
5891 case R_SH_GOTFUNCDESC:
5892 case R_SH_GOTFUNCDESC20:
5893 case R_SH_GOTOFFFUNCDESC:
5894 case R_SH_GOTOFFFUNCDESC20:
5896 #ifdef INCLUDE_SHMEDIA
5897 case R_SH_GOTPLT_LOW16:
5898 case R_SH_GOTPLT_MEDLOW16:
5899 case R_SH_GOTPLT_MEDHI16:
5900 case R_SH_GOTPLT_HI16:
5901 case R_SH_GOTPLT10BY4:
5902 case R_SH_GOTPLT10BY8:
5903 case R_SH_GOT_LOW16:
5904 case R_SH_GOT_MEDLOW16:
5905 case R_SH_GOT_MEDHI16:
5909 case R_SH_GOTOFF_LOW16:
5910 case R_SH_GOTOFF_MEDLOW16:
5911 case R_SH_GOTOFF_MEDHI16:
5912 case R_SH_GOTOFF_HI16:
5913 case R_SH_GOTPC_LOW16:
5914 case R_SH_GOTPC_MEDLOW16:
5915 case R_SH_GOTPC_MEDHI16:
5916 case R_SH_GOTPC_HI16:
5918 case R_SH_TLS_GD_32:
5919 case R_SH_TLS_LD_32:
5920 case R_SH_TLS_IE_32:
5921 if (htab->root.dynobj == NULL)
5922 htab->root.dynobj = abfd;
5923 if (!create_got_section (htab->root.dynobj, info))
5934 /* This relocation describes the C++ object vtable hierarchy.
5935 Reconstruct it for later use during GC. */
5936 case R_SH_GNU_VTINHERIT:
5937 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
5941 /* This relocation describes which C++ vtable entries are actually
5942 used. Record for later use during GC. */
5943 case R_SH_GNU_VTENTRY:
5944 BFD_ASSERT (h != NULL);
5946 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
5950 case R_SH_TLS_IE_32:
5951 if (bfd_link_pic (info))
5952 info->flags |= DF_STATIC_TLS;
5956 case R_SH_TLS_GD_32:
5959 #ifdef INCLUDE_SHMEDIA
5960 case R_SH_GOT_LOW16:
5961 case R_SH_GOT_MEDLOW16:
5962 case R_SH_GOT_MEDHI16:
5967 case R_SH_GOTFUNCDESC:
5968 case R_SH_GOTFUNCDESC20:
5972 got_type = GOT_NORMAL;
5974 case R_SH_TLS_GD_32:
5975 got_type = GOT_TLS_GD;
5977 case R_SH_TLS_IE_32:
5978 got_type = GOT_TLS_IE;
5980 case R_SH_GOTFUNCDESC:
5981 case R_SH_GOTFUNCDESC20:
5982 got_type = GOT_FUNCDESC;
5988 #ifdef INCLUDE_SHMEDIA
5989 if (seen_stt_datalabel)
5991 struct elf_sh_link_hash_entry *eh
5992 = (struct elf_sh_link_hash_entry *) h;
5994 eh->datalabel_got.refcount += 1;
5998 h->got.refcount += 1;
5999 old_got_type = sh_elf_hash_entry (h)->got_type;
6003 bfd_signed_vma *local_got_refcounts;
6005 /* This is a global offset table entry for a local
6007 local_got_refcounts = elf_local_got_refcounts (abfd);
6008 if (local_got_refcounts == NULL)
6012 size = symtab_hdr->sh_info;
6013 size *= sizeof (bfd_signed_vma);
6014 #ifdef INCLUDE_SHMEDIA
6015 /* Reserve space for both the datalabel and
6016 codelabel local GOT offsets. */
6019 size += symtab_hdr->sh_info;
6020 local_got_refcounts = ((bfd_signed_vma *)
6021 bfd_zalloc (abfd, size));
6022 if (local_got_refcounts == NULL)
6024 elf_local_got_refcounts (abfd) = local_got_refcounts;
6025 #ifdef INCLUDE_SHMEDIA
6026 /* Take care of both the datalabel and codelabel local
6028 sh_elf_local_got_type (abfd)
6029 = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
6031 sh_elf_local_got_type (abfd)
6032 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
6035 #ifdef INCLUDE_SHMEDIA
6036 if (rel->r_addend & 1)
6037 local_got_refcounts[symtab_hdr->sh_info + r_symndx] += 1;
6040 local_got_refcounts[r_symndx] += 1;
6041 old_got_type = sh_elf_local_got_type (abfd) [r_symndx];
6044 /* If a TLS symbol is accessed using IE at least once,
6045 there is no point to use dynamic model for it. */
6046 if (old_got_type != got_type && old_got_type != GOT_UNKNOWN
6047 && (old_got_type != GOT_TLS_GD || got_type != GOT_TLS_IE))
6049 if (old_got_type == GOT_TLS_IE && got_type == GOT_TLS_GD)
6050 got_type = GOT_TLS_IE;
6053 if ((old_got_type == GOT_FUNCDESC || got_type == GOT_FUNCDESC)
6054 && (old_got_type == GOT_NORMAL || got_type == GOT_NORMAL))
6056 (_("%B: `%s' accessed both as normal and FDPIC symbol"),
6057 abfd, h->root.root.string);
6058 else if (old_got_type == GOT_FUNCDESC
6059 || got_type == GOT_FUNCDESC)
6061 (_("%B: `%s' accessed both as FDPIC and thread local symbol"),
6062 abfd, h->root.root.string);
6065 (_("%B: `%s' accessed both as normal and thread local symbol"),
6066 abfd, h->root.root.string);
6071 if (old_got_type != got_type)
6074 sh_elf_hash_entry (h)->got_type = got_type;
6076 sh_elf_local_got_type (abfd) [r_symndx] = got_type;
6081 case R_SH_TLS_LD_32:
6082 sh_elf_hash_table(info)->tls_ldm_got.refcount += 1;
6086 case R_SH_GOTOFFFUNCDESC:
6087 case R_SH_GOTOFFFUNCDESC20:
6091 (_("%B: Function descriptor relocation with non-zero addend"),
6098 union gotref *local_funcdesc;
6100 /* We need a function descriptor for a local symbol. */
6101 local_funcdesc = sh_elf_local_funcdesc (abfd);
6102 if (local_funcdesc == NULL)
6106 size = symtab_hdr->sh_info * sizeof (union gotref);
6107 #ifdef INCLUDE_SHMEDIA
6108 /* Count datalabel local GOT. */
6111 local_funcdesc = (union gotref *) bfd_zalloc (abfd, size);
6112 if (local_funcdesc == NULL)
6114 sh_elf_local_funcdesc (abfd) = local_funcdesc;
6116 local_funcdesc[r_symndx].refcount += 1;
6118 if (r_type == R_SH_FUNCDESC)
6120 if (!bfd_link_pic (info))
6121 htab->srofixup->size += 4;
6123 htab->srelgot->size += sizeof (Elf32_External_Rela);
6128 sh_elf_hash_entry (h)->funcdesc.refcount++;
6129 if (r_type == R_SH_FUNCDESC)
6130 sh_elf_hash_entry (h)->abs_funcdesc_refcount++;
6132 /* If there is a function descriptor reference, then
6133 there should not be any non-FDPIC references. */
6134 old_got_type = sh_elf_hash_entry (h)->got_type;
6135 if (old_got_type != GOT_FUNCDESC && old_got_type != GOT_UNKNOWN)
6137 if (old_got_type == GOT_NORMAL)
6139 (_("%B: `%s' accessed both as normal and FDPIC symbol"),
6140 abfd, h->root.root.string);
6143 (_("%B: `%s' accessed both as FDPIC and thread local symbol"),
6144 abfd, h->root.root.string);
6150 #ifdef INCLUDE_SHMEDIA
6151 case R_SH_GOTPLT_LOW16:
6152 case R_SH_GOTPLT_MEDLOW16:
6153 case R_SH_GOTPLT_MEDHI16:
6154 case R_SH_GOTPLT_HI16:
6155 case R_SH_GOTPLT10BY4:
6156 case R_SH_GOTPLT10BY8:
6158 /* If this is a local symbol, we resolve it directly without
6159 creating a procedure linkage table entry. */
6163 || ! bfd_link_pic (info)
6165 || h->dynindx == -1)
6169 h->plt.refcount += 1;
6170 ((struct elf_sh_link_hash_entry *) h)->gotplt_refcount += 1;
6175 #ifdef INCLUDE_SHMEDIA
6176 case R_SH_PLT_LOW16:
6177 case R_SH_PLT_MEDLOW16:
6178 case R_SH_PLT_MEDHI16:
6181 /* This symbol requires a procedure linkage table entry. We
6182 actually build the entry in adjust_dynamic_symbol,
6183 because this might be a case of linking PIC code which is
6184 never referenced by a dynamic object, in which case we
6185 don't need to generate a procedure linkage table entry
6188 /* If this is a local symbol, we resolve it directly without
6189 creating a procedure linkage table entry. */
6193 if (h->forced_local)
6197 h->plt.refcount += 1;
6202 #ifdef INCLUDE_SHMEDIA
6203 case R_SH_IMM_LOW16_PCREL:
6204 case R_SH_IMM_MEDLOW16_PCREL:
6205 case R_SH_IMM_MEDHI16_PCREL:
6206 case R_SH_IMM_HI16_PCREL:
6208 if (h != NULL && ! bfd_link_pic (info))
6211 h->plt.refcount += 1;
6214 /* If we are creating a shared library, and this is a reloc
6215 against a global symbol, or a non PC relative reloc
6216 against a local symbol, then we need to copy the reloc
6217 into the shared library. However, if we are linking with
6218 -Bsymbolic, we do not need to copy a reloc against a
6219 global symbol which is defined in an object we are
6220 including in the link (i.e., DEF_REGULAR is set). At
6221 this point we have not seen all the input files, so it is
6222 possible that DEF_REGULAR is not set now but will be set
6223 later (it is never cleared). We account for that
6224 possibility below by storing information in the
6225 dyn_relocs field of the hash table entry. A similar
6226 situation occurs when creating shared libraries and symbol
6227 visibility changes render the symbol local.
6229 If on the other hand, we are creating an executable, we
6230 may need to keep relocations for symbols satisfied by a
6231 dynamic library if we manage to avoid copy relocs for the
6233 if ((bfd_link_pic (info)
6234 && (sec->flags & SEC_ALLOC) != 0
6235 && (r_type != R_SH_REL32
6237 && (! info->symbolic
6238 || h->root.type == bfd_link_hash_defweak
6239 || !h->def_regular))))
6240 || (! bfd_link_pic (info)
6241 && (sec->flags & SEC_ALLOC) != 0
6243 && (h->root.type == bfd_link_hash_defweak
6244 || !h->def_regular)))
6246 struct elf_sh_dyn_relocs *p;
6247 struct elf_sh_dyn_relocs **head;
6249 if (htab->root.dynobj == NULL)
6250 htab->root.dynobj = abfd;
6252 /* When creating a shared object, we must copy these
6253 reloc types into the output file. We create a reloc
6254 section in dynobj and make room for this reloc. */
6257 sreloc = _bfd_elf_make_dynamic_reloc_section
6258 (sec, htab->root.dynobj, 2, abfd, /*rela?*/ TRUE);
6264 /* If this is a global symbol, we count the number of
6265 relocations we need for this symbol. */
6267 head = &((struct elf_sh_link_hash_entry *) h)->dyn_relocs;
6270 /* Track dynamic relocs needed for local syms too. */
6273 Elf_Internal_Sym *isym;
6275 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
6280 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
6284 vpp = &elf_section_data (s)->local_dynrel;
6285 head = (struct elf_sh_dyn_relocs **) vpp;
6289 if (p == NULL || p->sec != sec)
6291 bfd_size_type amt = sizeof (*p);
6292 p = bfd_alloc (htab->root.dynobj, amt);
6303 if (r_type == R_SH_REL32
6304 #ifdef INCLUDE_SHMEDIA
6305 || r_type == R_SH_IMM_LOW16_PCREL
6306 || r_type == R_SH_IMM_MEDLOW16_PCREL
6307 || r_type == R_SH_IMM_MEDHI16_PCREL
6308 || r_type == R_SH_IMM_HI16_PCREL
6314 /* Allocate the fixup regardless of whether we need a relocation.
6315 If we end up generating the relocation, we'll unallocate the
6317 if (htab->fdpic_p && !bfd_link_pic (info)
6318 && r_type == R_SH_DIR32
6319 && (sec->flags & SEC_ALLOC) != 0)
6320 htab->srofixup->size += 4;
6323 case R_SH_TLS_LE_32:
6324 if (bfd_link_dll (info))
6327 (_("%B: TLS local exec code cannot be linked into shared objects"),
6334 case R_SH_TLS_LDO_32:
6335 /* Nothing to do. */
6346 #ifndef sh_elf_set_mach_from_flags
6347 static unsigned int sh_ef_bfd_table[] = { EF_SH_BFD_TABLE };
6350 sh_elf_set_mach_from_flags (bfd *abfd)
6352 flagword flags = elf_elfheader (abfd)->e_flags & EF_SH_MACH_MASK;
6354 if (flags >= sizeof(sh_ef_bfd_table))
6357 if (sh_ef_bfd_table[flags] == 0)
6360 bfd_default_set_arch_mach (abfd, bfd_arch_sh, sh_ef_bfd_table[flags]);
6366 /* Reverse table lookup for sh_ef_bfd_table[].
6367 Given a bfd MACH value from archures.c
6368 return the equivalent ELF flags from the table.
6369 Return -1 if no match is found. */
6372 sh_elf_get_flags_from_mach (unsigned long mach)
6374 int i = ARRAY_SIZE (sh_ef_bfd_table) - 1;
6377 if (sh_ef_bfd_table[i] == mach)
6380 /* shouldn't get here */
6385 #endif /* not sh_elf_set_mach_from_flags */
6387 #ifndef sh_elf_copy_private_data
6388 /* Copy backend specific data from one object module to another */
6391 sh_elf_copy_private_data (bfd * ibfd, bfd * obfd)
6393 if (! is_sh_elf (ibfd) || ! is_sh_elf (obfd))
6396 if (! _bfd_elf_copy_private_bfd_data (ibfd, obfd))
6399 return sh_elf_set_mach_from_flags (obfd);
6401 #endif /* not sh_elf_copy_private_data */
6403 #ifndef sh_elf_merge_private_data
6405 /* This function returns the ELF architecture number that
6406 corresponds to the given arch_sh* flags. */
6409 sh_find_elf_flags (unsigned int arch_set)
6411 extern unsigned long sh_get_bfd_mach_from_arch_set (unsigned int);
6412 unsigned long bfd_mach = sh_get_bfd_mach_from_arch_set (arch_set);
6414 return sh_elf_get_flags_from_mach (bfd_mach);
6417 /* Merge the architecture type of two BFD files, such that the
6418 resultant architecture supports all the features required
6419 by the two input BFDs.
6420 If the input BFDs are multually incompatible - i.e. one uses
6421 DSP while the other uses FPU - or there is no known architecture
6422 that fits the requirements then an error is emitted. */
6425 sh_merge_bfd_arch (bfd *ibfd, struct bfd_link_info *info)
6427 bfd *obfd = info->output_bfd;
6428 unsigned int old_arch, new_arch, merged_arch;
6430 if (! _bfd_generic_verify_endian_match (ibfd, info))
6433 old_arch = sh_get_arch_up_from_bfd_mach (bfd_get_mach (obfd));
6434 new_arch = sh_get_arch_up_from_bfd_mach (bfd_get_mach (ibfd));
6436 merged_arch = SH_MERGE_ARCH_SET (old_arch, new_arch);
6438 if (!SH_VALID_CO_ARCH_SET (merged_arch))
6441 ("%B: uses %s instructions while previous modules "
6442 "use %s instructions",
6444 SH_ARCH_SET_HAS_DSP (new_arch) ? "dsp" : "floating point",
6445 SH_ARCH_SET_HAS_DSP (new_arch) ? "floating point" : "dsp");
6446 bfd_set_error (bfd_error_bad_value);
6449 else if (!SH_VALID_ARCH_SET (merged_arch))
6452 ("internal error: merge of architecture '%s' with "
6453 "architecture '%s' produced unknown architecture",
6454 bfd_printable_name (obfd),
6455 bfd_printable_name (ibfd));
6456 bfd_set_error (bfd_error_bad_value);
6460 bfd_default_set_arch_mach (obfd, bfd_arch_sh,
6461 sh_get_bfd_mach_from_arch_set (merged_arch));
6466 /* This routine initialises the elf flags when required and
6467 calls sh_merge_bfd_arch() to check dsp/fpu compatibility. */
6470 sh_elf_merge_private_data (bfd *ibfd, struct bfd_link_info *info)
6472 bfd *obfd = info->output_bfd;
6474 if (! is_sh_elf (ibfd) || ! is_sh_elf (obfd))
6477 if (! elf_flags_init (obfd))
6479 /* This happens when ld starts out with a 'blank' output file. */
6480 elf_flags_init (obfd) = TRUE;
6481 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
6482 sh_elf_set_mach_from_flags (obfd);
6483 if (elf_elfheader (obfd)->e_flags & EF_SH_FDPIC)
6484 elf_elfheader (obfd)->e_flags &= ~EF_SH_PIC;
6487 if (! sh_merge_bfd_arch (ibfd, info))
6489 _bfd_error_handler ("%B: uses instructions which are incompatible "
6490 "with instructions used in previous modules",
6492 bfd_set_error (bfd_error_bad_value);
6496 elf_elfheader (obfd)->e_flags &= ~EF_SH_MACH_MASK;
6497 elf_elfheader (obfd)->e_flags |=
6498 sh_elf_get_flags_from_mach (bfd_get_mach (obfd));
6500 if (fdpic_object_p (ibfd) != fdpic_object_p (obfd))
6502 _bfd_error_handler ("%B: attempt to mix FDPIC and non-FDPIC objects",
6504 bfd_set_error (bfd_error_bad_value);
6510 #endif /* not sh_elf_merge_private_data */
6512 /* Override the generic function because we need to store sh_elf_obj_tdata
6513 as the specific tdata. We set also the machine architecture from flags
6517 sh_elf_object_p (bfd *abfd)
6519 if (! sh_elf_set_mach_from_flags (abfd))
6522 return (((elf_elfheader (abfd)->e_flags & EF_SH_FDPIC) != 0)
6523 == fdpic_object_p (abfd));
6526 /* Finish up dynamic symbol handling. We set the contents of various
6527 dynamic sections here. */
6530 sh_elf_finish_dynamic_symbol (bfd *output_bfd, struct bfd_link_info *info,
6531 struct elf_link_hash_entry *h,
6532 Elf_Internal_Sym *sym)
6534 struct elf_sh_link_hash_table *htab;
6536 htab = sh_elf_hash_table (info);
6540 if (h->plt.offset != (bfd_vma) -1)
6548 Elf_Internal_Rela rel;
6550 const struct elf_sh_plt_info *plt_info;
6552 /* This symbol has an entry in the procedure linkage table. Set
6555 BFD_ASSERT (h->dynindx != -1);
6558 sgotplt = htab->sgotplt;
6559 srelplt = htab->srelplt;
6560 BFD_ASSERT (splt != NULL && sgotplt != NULL && srelplt != NULL);
6562 /* Get the index in the procedure linkage table which
6563 corresponds to this symbol. This is the index of this symbol
6564 in all the symbols for which we are making plt entries. The
6565 first entry in the procedure linkage table is reserved. */
6566 plt_index = get_plt_index (htab->plt_info, h->plt.offset);
6568 plt_info = htab->plt_info;
6569 if (plt_info->short_plt != NULL && plt_index <= MAX_SHORT_PLT)
6570 plt_info = plt_info->short_plt;
6572 /* Get the offset into the .got table of the entry that
6573 corresponds to this function. */
6575 /* The offset must be relative to the GOT symbol, twelve bytes
6576 before the end of .got.plt. Each descriptor is eight
6578 got_offset = plt_index * 8 + 12 - sgotplt->size;
6580 /* Each .got entry is 4 bytes. The first three are
6582 got_offset = (plt_index + 3) * 4;
6585 if (bfd_link_pic (info))
6586 got_offset -= GOT_BIAS;
6589 /* Fill in the entry in the procedure linkage table. */
6590 memcpy (splt->contents + h->plt.offset,
6591 plt_info->symbol_entry,
6592 plt_info->symbol_entry_size);
6594 if (bfd_link_pic (info) || htab->fdpic_p)
6596 if (plt_info->symbol_fields.got20)
6598 bfd_reloc_status_type r;
6599 r = install_movi20_field (output_bfd, got_offset,
6600 splt->owner, splt, splt->contents,
6602 + plt_info->symbol_fields.got_entry);
6603 BFD_ASSERT (r == bfd_reloc_ok);
6606 install_plt_field (output_bfd, FALSE, got_offset,
6609 + plt_info->symbol_fields.got_entry));
6613 BFD_ASSERT (!plt_info->symbol_fields.got20);
6615 install_plt_field (output_bfd, FALSE,
6616 (sgotplt->output_section->vma
6617 + sgotplt->output_offset
6621 + plt_info->symbol_fields.got_entry));
6622 if (htab->vxworks_p)
6624 unsigned int reachable_plts, plts_per_4k;
6627 /* Divide the PLT into groups. The first group contains
6628 REACHABLE_PLTS entries and the other groups contain
6629 PLTS_PER_4K entries. Entries in the first group can
6630 branch directly to .plt; those in later groups branch
6631 to the last element of the previous group. */
6632 /* ??? It would be better to create multiple copies of
6633 the common resolver stub. */
6634 reachable_plts = ((4096
6635 - plt_info->plt0_entry_size
6636 - (plt_info->symbol_fields.plt + 4))
6637 / plt_info->symbol_entry_size) + 1;
6638 plts_per_4k = (4096 / plt_info->symbol_entry_size);
6639 if (plt_index < reachable_plts)
6640 distance = -(h->plt.offset
6641 + plt_info->symbol_fields.plt);
6643 distance = -(((plt_index - reachable_plts) % plts_per_4k + 1)
6644 * plt_info->symbol_entry_size);
6646 /* Install the 'bra' with this offset. */
6647 bfd_put_16 (output_bfd,
6648 0xa000 | (0x0fff & ((distance - 4) / 2)),
6651 + plt_info->symbol_fields.plt));
6654 install_plt_field (output_bfd, TRUE,
6655 splt->output_section->vma + splt->output_offset,
6658 + plt_info->symbol_fields.plt));
6661 /* Make got_offset relative to the start of .got.plt. */
6663 if (bfd_link_pic (info))
6664 got_offset += GOT_BIAS;
6667 got_offset = plt_index * 8;
6669 if (plt_info->symbol_fields.reloc_offset != MINUS_ONE)
6670 install_plt_field (output_bfd, FALSE,
6671 plt_index * sizeof (Elf32_External_Rela),
6674 + plt_info->symbol_fields.reloc_offset));
6676 /* Fill in the entry in the global offset table. */
6677 bfd_put_32 (output_bfd,
6678 (splt->output_section->vma
6679 + splt->output_offset
6681 + plt_info->symbol_resolve_offset),
6682 sgotplt->contents + got_offset);
6684 bfd_put_32 (output_bfd,
6685 sh_elf_osec_to_segment (output_bfd,
6686 htab->splt->output_section),
6687 sgotplt->contents + got_offset + 4);
6689 /* Fill in the entry in the .rela.plt section. */
6690 rel.r_offset = (sgotplt->output_section->vma
6691 + sgotplt->output_offset
6694 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_FUNCDESC_VALUE);
6696 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_JMP_SLOT);
6699 rel.r_addend = GOT_BIAS;
6701 loc = srelplt->contents + plt_index * sizeof (Elf32_External_Rela);
6702 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
6704 if (htab->vxworks_p && !bfd_link_pic (info))
6706 /* Create the .rela.plt.unloaded relocations for this PLT entry.
6707 Begin by pointing LOC to the first such relocation. */
6708 loc = (htab->srelplt2->contents
6709 + (plt_index * 2 + 1) * sizeof (Elf32_External_Rela));
6711 /* Create a .rela.plt.unloaded R_SH_DIR32 relocation
6712 for the PLT entry's pointer to the .got.plt entry. */
6713 rel.r_offset = (htab->splt->output_section->vma
6714 + htab->splt->output_offset
6716 + plt_info->symbol_fields.got_entry);
6717 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_SH_DIR32);
6718 rel.r_addend = got_offset;
6719 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
6720 loc += sizeof (Elf32_External_Rela);
6722 /* Create a .rela.plt.unloaded R_SH_DIR32 relocation for
6723 the .got.plt entry, which initially points to .plt. */
6724 rel.r_offset = (sgotplt->output_section->vma
6725 + sgotplt->output_offset
6727 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_SH_DIR32);
6729 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
6732 if (!h->def_regular)
6734 /* Mark the symbol as undefined, rather than as defined in
6735 the .plt section. Leave the value alone. */
6736 sym->st_shndx = SHN_UNDEF;
6740 if (h->got.offset != (bfd_vma) -1
6741 && sh_elf_hash_entry (h)->got_type != GOT_TLS_GD
6742 && sh_elf_hash_entry (h)->got_type != GOT_TLS_IE
6743 && sh_elf_hash_entry (h)->got_type != GOT_FUNCDESC)
6747 Elf_Internal_Rela rel;
6750 /* This symbol has an entry in the global offset table. Set it
6754 srelgot = htab->srelgot;
6755 BFD_ASSERT (sgot != NULL && srelgot != NULL);
6757 rel.r_offset = (sgot->output_section->vma
6758 + sgot->output_offset
6759 + (h->got.offset &~ (bfd_vma) 1));
6761 /* If this is a static link, or it is a -Bsymbolic link and the
6762 symbol is defined locally or was forced to be local because
6763 of a version file, we just want to emit a RELATIVE reloc.
6764 The entry in the global offset table will already have been
6765 initialized in the relocate_section function. */
6766 if (bfd_link_pic (info)
6767 && SYMBOL_REFERENCES_LOCAL (info, h))
6771 asection *sec = h->root.u.def.section;
6773 = elf_section_data (sec->output_section)->dynindx;
6775 rel.r_info = ELF32_R_INFO (dynindx, R_SH_DIR32);
6776 rel.r_addend = (h->root.u.def.value
6777 + h->root.u.def.section->output_offset);
6781 rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
6782 rel.r_addend = (h->root.u.def.value
6783 + h->root.u.def.section->output_section->vma
6784 + h->root.u.def.section->output_offset);
6789 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
6790 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_GLOB_DAT);
6794 loc = srelgot->contents;
6795 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
6796 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
6799 #ifdef INCLUDE_SHMEDIA
6801 struct elf_sh_link_hash_entry *eh;
6803 eh = (struct elf_sh_link_hash_entry *) h;
6804 if (eh->datalabel_got.offset != (bfd_vma) -1)
6808 Elf_Internal_Rela rel;
6811 /* This symbol has a datalabel entry in the global offset table.
6815 srelgot = htab->srelgot;
6816 BFD_ASSERT (sgot != NULL && srelgot != NULL);
6818 rel.r_offset = (sgot->output_section->vma
6819 + sgot->output_offset
6820 + (eh->datalabel_got.offset &~ (bfd_vma) 1));
6822 /* If this is a static link, or it is a -Bsymbolic link and the
6823 symbol is defined locally or was forced to be local because
6824 of a version file, we just want to emit a RELATIVE reloc.
6825 The entry in the global offset table will already have been
6826 initialized in the relocate_section function. */
6827 if (bfd_link_pic (info)
6828 && SYMBOL_REFERENCES_LOCAL (info, h))
6832 asection *sec = h->root.u.def.section;
6834 = elf_section_data (sec->output_section)->dynindx;
6836 rel.r_info = ELF32_R_INFO (dynindx, R_SH_DIR32);
6837 rel.r_addend = (h->root.u.def.value
6838 + h->root.u.def.section->output_offset);
6842 rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
6843 rel.r_addend = (h->root.u.def.value
6844 + h->root.u.def.section->output_section->vma
6845 + h->root.u.def.section->output_offset);
6850 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents
6851 + eh->datalabel_got.offset);
6852 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_GLOB_DAT);
6856 loc = srelgot->contents;
6857 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
6858 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
6866 Elf_Internal_Rela rel;
6869 /* This symbol needs a copy reloc. Set it up. */
6871 BFD_ASSERT (h->dynindx != -1
6872 && (h->root.type == bfd_link_hash_defined
6873 || h->root.type == bfd_link_hash_defweak));
6875 s = bfd_get_linker_section (htab->root.dynobj, ".rela.bss");
6876 BFD_ASSERT (s != NULL);
6878 rel.r_offset = (h->root.u.def.value
6879 + h->root.u.def.section->output_section->vma
6880 + h->root.u.def.section->output_offset);
6881 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_COPY);
6883 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
6884 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
6887 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
6888 _GLOBAL_OFFSET_TABLE_ is not absolute: it is relative to the
6890 if (h == htab->root.hdynamic
6891 || (!htab->vxworks_p && h == htab->root.hgot))
6892 sym->st_shndx = SHN_ABS;
6897 /* Finish up the dynamic sections. */
6900 sh_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
6902 struct elf_sh_link_hash_table *htab;
6906 htab = sh_elf_hash_table (info);
6910 sgotplt = htab->sgotplt;
6911 sdyn = bfd_get_linker_section (htab->root.dynobj, ".dynamic");
6913 if (htab->root.dynamic_sections_created)
6916 Elf32_External_Dyn *dyncon, *dynconend;
6918 BFD_ASSERT (sgotplt != NULL && sdyn != NULL);
6920 dyncon = (Elf32_External_Dyn *) sdyn->contents;
6921 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
6922 for (; dyncon < dynconend; dyncon++)
6924 Elf_Internal_Dyn dyn;
6926 #ifdef INCLUDE_SHMEDIA
6930 bfd_elf32_swap_dyn_in (htab->root.dynobj, dyncon, &dyn);
6936 && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
6937 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6940 #ifdef INCLUDE_SHMEDIA
6942 name = info->init_function;
6946 name = info->fini_function;
6948 if (dyn.d_un.d_val != 0)
6950 struct elf_link_hash_entry *h;
6952 h = elf_link_hash_lookup (&htab->root, name,
6953 FALSE, FALSE, TRUE);
6954 if (h != NULL && (h->other & STO_SH5_ISA32))
6956 dyn.d_un.d_val |= 1;
6957 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6964 BFD_ASSERT (htab->root.hgot != NULL);
6965 s = htab->root.hgot->root.u.def.section;
6966 dyn.d_un.d_ptr = htab->root.hgot->root.u.def.value
6967 + s->output_section->vma + s->output_offset;
6968 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6972 s = htab->srelplt->output_section;
6973 BFD_ASSERT (s != NULL);
6974 dyn.d_un.d_ptr = s->vma;
6975 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6979 s = htab->srelplt->output_section;
6980 BFD_ASSERT (s != NULL);
6981 dyn.d_un.d_val = s->size;
6982 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6986 /* My reading of the SVR4 ABI indicates that the
6987 procedure linkage table relocs (DT_JMPREL) should be
6988 included in the overall relocs (DT_RELA). This is
6989 what Solaris does. However, UnixWare can not handle
6990 that case. Therefore, we override the DT_RELASZ entry
6991 here to make it not include the JMPREL relocs. Since
6992 the linker script arranges for .rela.plt to follow all
6993 other relocation sections, we don't have to worry
6994 about changing the DT_RELA entry. */
6995 if (htab->srelplt != NULL)
6997 s = htab->srelplt->output_section;
6998 dyn.d_un.d_val -= s->size;
7000 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7005 /* Fill in the first entry in the procedure linkage table. */
7007 if (splt && splt->size > 0 && htab->plt_info->plt0_entry)
7011 memcpy (splt->contents,
7012 htab->plt_info->plt0_entry,
7013 htab->plt_info->plt0_entry_size);
7014 for (i = 0; i < ARRAY_SIZE (htab->plt_info->plt0_got_fields); i++)
7015 if (htab->plt_info->plt0_got_fields[i] != MINUS_ONE)
7016 install_plt_field (output_bfd, FALSE,
7017 (sgotplt->output_section->vma
7018 + sgotplt->output_offset
7021 + htab->plt_info->plt0_got_fields[i]));
7023 if (htab->vxworks_p)
7025 /* Finalize the .rela.plt.unloaded contents. */
7026 Elf_Internal_Rela rel;
7029 /* Create a .rela.plt.unloaded R_SH_DIR32 relocation for the
7030 first PLT entry's pointer to _GLOBAL_OFFSET_TABLE_ + 8. */
7031 loc = htab->srelplt2->contents;
7032 rel.r_offset = (splt->output_section->vma
7033 + splt->output_offset
7034 + htab->plt_info->plt0_got_fields[2]);
7035 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_SH_DIR32);
7037 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
7038 loc += sizeof (Elf32_External_Rela);
7040 /* Fix up the remaining .rela.plt.unloaded relocations.
7041 They may have the wrong symbol index for _G_O_T_ or
7042 _P_L_T_ depending on the order in which symbols were
7044 while (loc < htab->srelplt2->contents + htab->srelplt2->size)
7046 /* The PLT entry's pointer to the .got.plt slot. */
7047 bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
7048 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx,
7050 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
7051 loc += sizeof (Elf32_External_Rela);
7053 /* The .got.plt slot's pointer to .plt. */
7054 bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
7055 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx,
7057 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
7058 loc += sizeof (Elf32_External_Rela);
7062 /* UnixWare sets the entsize of .plt to 4, although that doesn't
7063 really seem like the right value. */
7064 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
7068 /* Fill in the first three entries in the global offset table. */
7069 if (sgotplt && sgotplt->size > 0 && !htab->fdpic_p)
7072 bfd_put_32 (output_bfd, (bfd_vma) 0, sgotplt->contents);
7074 bfd_put_32 (output_bfd,
7075 sdyn->output_section->vma + sdyn->output_offset,
7077 bfd_put_32 (output_bfd, (bfd_vma) 0, sgotplt->contents + 4);
7078 bfd_put_32 (output_bfd, (bfd_vma) 0, sgotplt->contents + 8);
7081 if (sgotplt && sgotplt->size > 0)
7082 elf_section_data (sgotplt->output_section)->this_hdr.sh_entsize = 4;
7084 /* At the very end of the .rofixup section is a pointer to the GOT. */
7085 if (htab->fdpic_p && htab->srofixup != NULL)
7087 struct elf_link_hash_entry *hgot = htab->root.hgot;
7088 bfd_vma got_value = hgot->root.u.def.value
7089 + hgot->root.u.def.section->output_section->vma
7090 + hgot->root.u.def.section->output_offset;
7092 sh_elf_add_rofixup (output_bfd, htab->srofixup, got_value);
7094 /* Make sure we allocated and generated the same number of fixups. */
7095 BFD_ASSERT (htab->srofixup->reloc_count * 4 == htab->srofixup->size);
7098 if (htab->srelfuncdesc)
7099 BFD_ASSERT (htab->srelfuncdesc->reloc_count * sizeof (Elf32_External_Rela)
7100 == htab->srelfuncdesc->size);
7103 BFD_ASSERT (htab->srelgot->reloc_count * sizeof (Elf32_External_Rela)
7104 == htab->srelgot->size);
7109 static enum elf_reloc_type_class
7110 sh_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
7111 const asection *rel_sec ATTRIBUTE_UNUSED,
7112 const Elf_Internal_Rela *rela)
7114 switch ((int) ELF32_R_TYPE (rela->r_info))
7117 return reloc_class_relative;
7119 return reloc_class_plt;
7121 return reloc_class_copy;
7123 return reloc_class_normal;
7127 #if !defined SH_TARGET_ALREADY_DEFINED
7128 /* Support for Linux core dump NOTE sections. */
7131 elf32_shlin_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
7136 switch (note->descsz)
7141 case 168: /* Linux/SH */
7143 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
7146 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
7155 /* Make a ".reg/999" section. */
7156 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
7157 size, note->descpos + offset);
7161 elf32_shlin_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
7163 switch (note->descsz)
7168 case 124: /* Linux/SH elf_prpsinfo */
7169 elf_tdata (abfd)->core->program
7170 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
7171 elf_tdata (abfd)->core->command
7172 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
7175 /* Note that for some reason, a spurious space is tacked
7176 onto the end of the args in some (at least one anyway)
7177 implementations, so strip it off if it exists. */
7180 char *command = elf_tdata (abfd)->core->command;
7181 int n = strlen (command);
7183 if (0 < n && command[n - 1] == ' ')
7184 command[n - 1] = '\0';
7189 #endif /* not SH_TARGET_ALREADY_DEFINED */
7192 /* Return address for Ith PLT stub in section PLT, for relocation REL
7193 or (bfd_vma) -1 if it should not be included. */
7196 sh_elf_plt_sym_val (bfd_vma i, const asection *plt,
7197 const arelent *rel ATTRIBUTE_UNUSED)
7199 const struct elf_sh_plt_info *plt_info;
7201 plt_info = get_plt_info (plt->owner, (plt->owner->flags & DYNAMIC) != 0);
7202 return plt->vma + get_plt_offset (plt_info, i);
7205 /* Decide whether to attempt to turn absptr or lsda encodings in
7206 shared libraries into pcrel within the given input section. */
7209 sh_elf_use_relative_eh_frame (bfd *input_bfd ATTRIBUTE_UNUSED,
7210 struct bfd_link_info *info,
7211 asection *eh_frame_section ATTRIBUTE_UNUSED)
7213 struct elf_sh_link_hash_table *htab = sh_elf_hash_table (info);
7215 /* We can't use PC-relative encodings in FDPIC binaries, in general. */
7222 /* Adjust the contents of an eh_frame_hdr section before they're output. */
7225 sh_elf_encode_eh_address (bfd *abfd,
7226 struct bfd_link_info *info,
7227 asection *osec, bfd_vma offset,
7228 asection *loc_sec, bfd_vma loc_offset,
7231 struct elf_sh_link_hash_table *htab = sh_elf_hash_table (info);
7232 struct elf_link_hash_entry *h;
7235 return _bfd_elf_encode_eh_address (abfd, info, osec, offset, loc_sec,
7236 loc_offset, encoded);
7238 h = htab->root.hgot;
7239 BFD_ASSERT (h && h->root.type == bfd_link_hash_defined);
7241 if (! h || (sh_elf_osec_to_segment (abfd, osec)
7242 == sh_elf_osec_to_segment (abfd, loc_sec->output_section)))
7243 return _bfd_elf_encode_eh_address (abfd, info, osec, offset,
7244 loc_sec, loc_offset, encoded);
7246 BFD_ASSERT (sh_elf_osec_to_segment (abfd, osec)
7247 == (sh_elf_osec_to_segment
7248 (abfd, h->root.u.def.section->output_section)));
7250 *encoded = osec->vma + offset
7251 - (h->root.u.def.value
7252 + h->root.u.def.section->output_section->vma
7253 + h->root.u.def.section->output_offset);
7255 return DW_EH_PE_datarel | DW_EH_PE_sdata4;
7258 #if !defined SH_TARGET_ALREADY_DEFINED
7259 #define TARGET_BIG_SYM sh_elf32_vec
7260 #define TARGET_BIG_NAME "elf32-sh"
7261 #define TARGET_LITTLE_SYM sh_elf32_le_vec
7262 #define TARGET_LITTLE_NAME "elf32-shl"
7265 #define ELF_ARCH bfd_arch_sh
7266 #define ELF_TARGET_ID SH_ELF_DATA
7267 #define ELF_MACHINE_CODE EM_SH
7268 #ifdef __QNXTARGET__
7269 #define ELF_MAXPAGESIZE 0x1000
7271 #define ELF_MAXPAGESIZE 0x80
7274 #define elf_symbol_leading_char '_'
7276 #define bfd_elf32_bfd_reloc_type_lookup sh_elf_reloc_type_lookup
7277 #define bfd_elf32_bfd_reloc_name_lookup \
7278 sh_elf_reloc_name_lookup
7279 #define elf_info_to_howto sh_elf_info_to_howto
7280 #define bfd_elf32_bfd_relax_section sh_elf_relax_section
7281 #define elf_backend_relocate_section sh_elf_relocate_section
7282 #define bfd_elf32_bfd_get_relocated_section_contents \
7283 sh_elf_get_relocated_section_contents
7284 #define bfd_elf32_mkobject sh_elf_mkobject
7285 #define elf_backend_object_p sh_elf_object_p
7286 #define bfd_elf32_bfd_copy_private_bfd_data \
7287 sh_elf_copy_private_data
7288 #define bfd_elf32_bfd_merge_private_bfd_data \
7289 sh_elf_merge_private_data
7291 #define elf_backend_gc_mark_hook sh_elf_gc_mark_hook
7292 #define elf_backend_check_relocs sh_elf_check_relocs
7293 #define elf_backend_copy_indirect_symbol \
7294 sh_elf_copy_indirect_symbol
7295 #define elf_backend_create_dynamic_sections \
7296 sh_elf_create_dynamic_sections
7297 #define bfd_elf32_bfd_link_hash_table_create \
7298 sh_elf_link_hash_table_create
7299 #define elf_backend_adjust_dynamic_symbol \
7300 sh_elf_adjust_dynamic_symbol
7301 #define elf_backend_always_size_sections \
7302 sh_elf_always_size_sections
7303 #define elf_backend_size_dynamic_sections \
7304 sh_elf_size_dynamic_sections
7305 #define elf_backend_omit_section_dynsym sh_elf_omit_section_dynsym
7306 #define elf_backend_finish_dynamic_symbol \
7307 sh_elf_finish_dynamic_symbol
7308 #define elf_backend_finish_dynamic_sections \
7309 sh_elf_finish_dynamic_sections
7310 #define elf_backend_reloc_type_class sh_elf_reloc_type_class
7311 #define elf_backend_plt_sym_val sh_elf_plt_sym_val
7312 #define elf_backend_can_make_relative_eh_frame \
7313 sh_elf_use_relative_eh_frame
7314 #define elf_backend_can_make_lsda_relative_eh_frame \
7315 sh_elf_use_relative_eh_frame
7316 #define elf_backend_encode_eh_address \
7317 sh_elf_encode_eh_address
7319 #define elf_backend_stack_align 8
7320 #define elf_backend_can_gc_sections 1
7321 #define elf_backend_can_refcount 1
7322 #define elf_backend_want_got_plt 1
7323 #define elf_backend_plt_readonly 1
7324 #define elf_backend_want_plt_sym 0
7325 #define elf_backend_got_header_size 12
7327 #if !defined INCLUDE_SHMEDIA && !defined SH_TARGET_ALREADY_DEFINED
7329 #include "elf32-target.h"
7331 /* NetBSD support. */
7332 #undef TARGET_BIG_SYM
7333 #define TARGET_BIG_SYM sh_elf32_nbsd_vec
7334 #undef TARGET_BIG_NAME
7335 #define TARGET_BIG_NAME "elf32-sh-nbsd"
7336 #undef TARGET_LITTLE_SYM
7337 #define TARGET_LITTLE_SYM sh_elf32_nbsd_le_vec
7338 #undef TARGET_LITTLE_NAME
7339 #define TARGET_LITTLE_NAME "elf32-shl-nbsd"
7340 #undef ELF_MAXPAGESIZE
7341 #define ELF_MAXPAGESIZE 0x10000
7342 #undef ELF_COMMONPAGESIZE
7343 #undef elf_symbol_leading_char
7344 #define elf_symbol_leading_char 0
7346 #define elf32_bed elf32_sh_nbsd_bed
7348 #include "elf32-target.h"
7351 /* Linux support. */
7352 #undef TARGET_BIG_SYM
7353 #define TARGET_BIG_SYM sh_elf32_linux_be_vec
7354 #undef TARGET_BIG_NAME
7355 #define TARGET_BIG_NAME "elf32-shbig-linux"
7356 #undef TARGET_LITTLE_SYM
7357 #define TARGET_LITTLE_SYM sh_elf32_linux_vec
7358 #undef TARGET_LITTLE_NAME
7359 #define TARGET_LITTLE_NAME "elf32-sh-linux"
7360 #undef ELF_COMMONPAGESIZE
7361 #define ELF_COMMONPAGESIZE 0x1000
7363 #undef elf_backend_grok_prstatus
7364 #define elf_backend_grok_prstatus elf32_shlin_grok_prstatus
7365 #undef elf_backend_grok_psinfo
7366 #define elf_backend_grok_psinfo elf32_shlin_grok_psinfo
7368 #define elf32_bed elf32_sh_lin_bed
7370 #include "elf32-target.h"
7373 /* FDPIC support. */
7374 #undef TARGET_BIG_SYM
7375 #define TARGET_BIG_SYM sh_elf32_fdpic_be_vec
7376 #undef TARGET_BIG_NAME
7377 #define TARGET_BIG_NAME "elf32-shbig-fdpic"
7378 #undef TARGET_LITTLE_SYM
7379 #define TARGET_LITTLE_SYM sh_elf32_fdpic_le_vec
7380 #undef TARGET_LITTLE_NAME
7381 #define TARGET_LITTLE_NAME "elf32-sh-fdpic"
7384 #define elf32_bed elf32_sh_fd_bed
7386 #include "elf32-target.h"
7388 #undef elf_backend_modify_program_headers
7390 /* VxWorks support. */
7391 #undef TARGET_BIG_SYM
7392 #define TARGET_BIG_SYM sh_elf32_vxworks_vec
7393 #undef TARGET_BIG_NAME
7394 #define TARGET_BIG_NAME "elf32-sh-vxworks"
7395 #undef TARGET_LITTLE_SYM
7396 #define TARGET_LITTLE_SYM sh_elf32_vxworks_le_vec
7397 #undef TARGET_LITTLE_NAME
7398 #define TARGET_LITTLE_NAME "elf32-shl-vxworks"
7400 #define elf32_bed elf32_sh_vxworks_bed
7402 #undef elf_backend_want_plt_sym
7403 #define elf_backend_want_plt_sym 1
7404 #undef elf_symbol_leading_char
7405 #define elf_symbol_leading_char '_'
7406 #define elf_backend_want_got_underscore 1
7407 #undef elf_backend_grok_prstatus
7408 #undef elf_backend_grok_psinfo
7409 #undef elf_backend_add_symbol_hook
7410 #define elf_backend_add_symbol_hook elf_vxworks_add_symbol_hook
7411 #undef elf_backend_link_output_symbol_hook
7412 #define elf_backend_link_output_symbol_hook \
7413 elf_vxworks_link_output_symbol_hook
7414 #undef elf_backend_emit_relocs
7415 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
7416 #undef elf_backend_final_write_processing
7417 #define elf_backend_final_write_processing \
7418 elf_vxworks_final_write_processing
7419 #undef ELF_MAXPAGESIZE
7420 #define ELF_MAXPAGESIZE 0x1000
7421 #undef ELF_COMMONPAGESIZE
7423 #include "elf32-target.h"
7425 #endif /* neither INCLUDE_SHMEDIA nor SH_TARGET_ALREADY_DEFINED */