1 /* Renesas / SuperH SH specific support for 32-bit ELF
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006 Free Software Foundation, Inc.
4 Contributed by Ian Lance Taylor, Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
27 #include "elf-vxworks.h"
29 #include "libiberty.h"
30 #include "../opcodes/sh-opc.h"
32 static bfd_reloc_status_type sh_elf_reloc
33 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
34 static bfd_reloc_status_type sh_elf_ignore_reloc
35 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
36 static bfd_boolean sh_elf_relax_delete_bytes
37 (bfd *, asection *, bfd_vma, int);
38 static bfd_boolean sh_elf_align_loads
39 (bfd *, asection *, Elf_Internal_Rela *, bfd_byte *, bfd_boolean *);
41 static bfd_boolean sh_elf_swap_insns
42 (bfd *, asection *, void *, bfd_byte *, bfd_vma);
44 static int sh_elf_optimized_tls_reloc
45 (struct bfd_link_info *, int, int);
46 static bfd_vma dtpoff_base
47 (struct bfd_link_info *);
49 (struct bfd_link_info *, bfd_vma);
51 /* The name of the dynamic interpreter. This is put in the .interp
54 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
56 #define MINUS_ONE ((bfd_vma) 0 - 1)
58 #define SH_PARTIAL32 TRUE
59 #define SH_SRC_MASK32 0xffffffff
60 #define SH_ELF_RELOC sh_elf_reloc
61 static reloc_howto_type sh_elf_howto_table[] =
63 #include "elf32-sh-relocs.h"
66 #define SH_PARTIAL32 FALSE
67 #define SH_SRC_MASK32 0
68 #define SH_ELF_RELOC bfd_elf_generic_reloc
69 static reloc_howto_type sh_vxworks_howto_table[] =
71 #include "elf32-sh-relocs.h"
74 /* Return true if OUTPUT_BFD is a VxWorks object. */
77 vxworks_object_p (bfd *abfd ATTRIBUTE_UNUSED)
79 #if !defined INCLUDE_SHMEDIA && !defined SH_TARGET_ALREADY_DEFINED
80 extern const bfd_target bfd_elf32_shlvxworks_vec;
81 extern const bfd_target bfd_elf32_shvxworks_vec;
83 return (abfd->xvec == &bfd_elf32_shlvxworks_vec
84 || abfd->xvec == &bfd_elf32_shvxworks_vec);
90 /* Return the howto table for ABFD. */
92 static reloc_howto_type *
93 get_howto_table (bfd *abfd)
95 if (vxworks_object_p (abfd))
96 return sh_vxworks_howto_table;
97 return sh_elf_howto_table;
100 static bfd_reloc_status_type
101 sh_elf_reloc_loop (int r_type ATTRIBUTE_UNUSED, bfd *input_bfd,
102 asection *input_section, bfd_byte *contents,
103 bfd_vma addr, asection *symbol_section,
104 bfd_vma start, bfd_vma end)
106 static bfd_vma last_addr;
107 static asection *last_symbol_section;
108 bfd_byte *start_ptr, *ptr, *last_ptr;
113 /* Sanity check the address. */
114 if (addr > bfd_get_section_limit (input_bfd, input_section))
115 return bfd_reloc_outofrange;
117 /* We require the start and end relocations to be processed consecutively -
118 although we allow then to be processed forwards or backwards. */
122 last_symbol_section = symbol_section;
125 if (last_addr != addr)
129 if (! symbol_section || last_symbol_section != symbol_section || end < start)
130 return bfd_reloc_outofrange;
132 /* Get the symbol_section contents. */
133 if (symbol_section != input_section)
135 if (elf_section_data (symbol_section)->this_hdr.contents != NULL)
136 contents = elf_section_data (symbol_section)->this_hdr.contents;
139 if (!bfd_malloc_and_get_section (input_bfd, symbol_section,
142 if (contents != NULL)
144 return bfd_reloc_outofrange;
148 #define IS_PPI(PTR) ((bfd_get_16 (input_bfd, (PTR)) & 0xfc00) == 0xf800)
149 start_ptr = contents + start;
150 for (cum_diff = -6, ptr = contents + end; cum_diff < 0 && ptr > start_ptr;)
152 for (last_ptr = ptr, ptr -= 4; ptr >= start_ptr && IS_PPI (ptr);)
155 diff = (last_ptr - ptr) >> 1;
156 cum_diff += diff & 1;
159 /* Calculate the start / end values to load into rs / re minus four -
160 so that will cancel out the four we would otherwise have to add to
161 addr to get the value to subtract in order to get relative addressing. */
165 end = (ptr + cum_diff * 2) - contents;
169 bfd_vma start0 = start - 4;
171 while (start0 && IS_PPI (contents + start0))
173 start0 = start - 2 - ((start - start0) & 2);
174 start = start0 - cum_diff - 2;
179 && elf_section_data (symbol_section)->this_hdr.contents != contents)
182 insn = bfd_get_16 (input_bfd, contents + addr);
184 x = (insn & 0x200 ? end : start) - addr;
185 if (input_section != symbol_section)
186 x += ((symbol_section->output_section->vma + symbol_section->output_offset)
187 - (input_section->output_section->vma
188 + input_section->output_offset));
190 if (x < -128 || x > 127)
191 return bfd_reloc_overflow;
193 x = (insn & ~0xff) | (x & 0xff);
194 bfd_put_16 (input_bfd, (bfd_vma) x, contents + addr);
199 /* This function is used for normal relocs. This used to be like the COFF
200 function, and is almost certainly incorrect for other ELF targets. */
202 static bfd_reloc_status_type
203 sh_elf_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol_in,
204 void *data, asection *input_section, bfd *output_bfd,
205 char **error_message ATTRIBUTE_UNUSED)
209 enum elf_sh_reloc_type r_type;
210 bfd_vma addr = reloc_entry->address;
211 bfd_byte *hit_data = addr + (bfd_byte *) data;
213 r_type = (enum elf_sh_reloc_type) reloc_entry->howto->type;
215 if (output_bfd != NULL)
217 /* Partial linking--do nothing. */
218 reloc_entry->address += input_section->output_offset;
222 /* Almost all relocs have to do with relaxing. If any work must be
223 done for them, it has been done in sh_relax_section. */
224 if (r_type == R_SH_IND12W && (symbol_in->flags & BSF_LOCAL) != 0)
227 if (symbol_in != NULL
228 && bfd_is_und_section (symbol_in->section))
229 return bfd_reloc_undefined;
231 if (bfd_is_com_section (symbol_in->section))
234 sym_value = (symbol_in->value +
235 symbol_in->section->output_section->vma +
236 symbol_in->section->output_offset);
241 insn = bfd_get_32 (abfd, hit_data);
242 insn += sym_value + reloc_entry->addend;
243 bfd_put_32 (abfd, (bfd_vma) insn, hit_data);
246 insn = bfd_get_16 (abfd, hit_data);
247 sym_value += reloc_entry->addend;
248 sym_value -= (input_section->output_section->vma
249 + input_section->output_offset
252 sym_value += (insn & 0xfff) << 1;
255 insn = (insn & 0xf000) | (sym_value & 0xfff);
256 bfd_put_16 (abfd, (bfd_vma) insn, hit_data);
257 if (sym_value < (bfd_vma) -0x1000 || sym_value >= 0x1000)
258 return bfd_reloc_overflow;
268 /* This function is used for relocs which are only used for relaxing,
269 which the linker should otherwise ignore. */
271 static bfd_reloc_status_type
272 sh_elf_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc_entry,
273 asymbol *symbol ATTRIBUTE_UNUSED,
274 void *data ATTRIBUTE_UNUSED, asection *input_section,
276 char **error_message ATTRIBUTE_UNUSED)
278 if (output_bfd != NULL)
279 reloc_entry->address += input_section->output_offset;
283 /* This structure is used to map BFD reloc codes to SH ELF relocs. */
287 bfd_reloc_code_real_type bfd_reloc_val;
288 unsigned char elf_reloc_val;
291 /* An array mapping BFD reloc codes to SH ELF relocs. */
293 static const struct elf_reloc_map sh_reloc_map[] =
295 { BFD_RELOC_NONE, R_SH_NONE },
296 { BFD_RELOC_32, R_SH_DIR32 },
297 { BFD_RELOC_16, R_SH_DIR16 },
298 { BFD_RELOC_8, R_SH_DIR8 },
299 { BFD_RELOC_CTOR, R_SH_DIR32 },
300 { BFD_RELOC_32_PCREL, R_SH_REL32 },
301 { BFD_RELOC_SH_PCDISP8BY2, R_SH_DIR8WPN },
302 { BFD_RELOC_SH_PCDISP12BY2, R_SH_IND12W },
303 { BFD_RELOC_SH_PCRELIMM8BY2, R_SH_DIR8WPZ },
304 { BFD_RELOC_SH_PCRELIMM8BY4, R_SH_DIR8WPL },
305 { BFD_RELOC_8_PCREL, R_SH_SWITCH8 },
306 { BFD_RELOC_SH_SWITCH16, R_SH_SWITCH16 },
307 { BFD_RELOC_SH_SWITCH32, R_SH_SWITCH32 },
308 { BFD_RELOC_SH_USES, R_SH_USES },
309 { BFD_RELOC_SH_COUNT, R_SH_COUNT },
310 { BFD_RELOC_SH_ALIGN, R_SH_ALIGN },
311 { BFD_RELOC_SH_CODE, R_SH_CODE },
312 { BFD_RELOC_SH_DATA, R_SH_DATA },
313 { BFD_RELOC_SH_LABEL, R_SH_LABEL },
314 { BFD_RELOC_VTABLE_INHERIT, R_SH_GNU_VTINHERIT },
315 { BFD_RELOC_VTABLE_ENTRY, R_SH_GNU_VTENTRY },
316 { BFD_RELOC_SH_LOOP_START, R_SH_LOOP_START },
317 { BFD_RELOC_SH_LOOP_END, R_SH_LOOP_END },
318 { BFD_RELOC_SH_TLS_GD_32, R_SH_TLS_GD_32 },
319 { BFD_RELOC_SH_TLS_LD_32, R_SH_TLS_LD_32 },
320 { BFD_RELOC_SH_TLS_LDO_32, R_SH_TLS_LDO_32 },
321 { BFD_RELOC_SH_TLS_IE_32, R_SH_TLS_IE_32 },
322 { BFD_RELOC_SH_TLS_LE_32, R_SH_TLS_LE_32 },
323 { BFD_RELOC_SH_TLS_DTPMOD32, R_SH_TLS_DTPMOD32 },
324 { BFD_RELOC_SH_TLS_DTPOFF32, R_SH_TLS_DTPOFF32 },
325 { BFD_RELOC_SH_TLS_TPOFF32, R_SH_TLS_TPOFF32 },
326 { BFD_RELOC_32_GOT_PCREL, R_SH_GOT32 },
327 { BFD_RELOC_32_PLT_PCREL, R_SH_PLT32 },
328 { BFD_RELOC_SH_COPY, R_SH_COPY },
329 { BFD_RELOC_SH_GLOB_DAT, R_SH_GLOB_DAT },
330 { BFD_RELOC_SH_JMP_SLOT, R_SH_JMP_SLOT },
331 { BFD_RELOC_SH_RELATIVE, R_SH_RELATIVE },
332 { BFD_RELOC_32_GOTOFF, R_SH_GOTOFF },
333 { BFD_RELOC_SH_GOTPC, R_SH_GOTPC },
334 { BFD_RELOC_SH_GOTPLT32, R_SH_GOTPLT32 },
335 #ifdef INCLUDE_SHMEDIA
336 { BFD_RELOC_SH_GOT_LOW16, R_SH_GOT_LOW16 },
337 { BFD_RELOC_SH_GOT_MEDLOW16, R_SH_GOT_MEDLOW16 },
338 { BFD_RELOC_SH_GOT_MEDHI16, R_SH_GOT_MEDHI16 },
339 { BFD_RELOC_SH_GOT_HI16, R_SH_GOT_HI16 },
340 { BFD_RELOC_SH_GOTPLT_LOW16, R_SH_GOTPLT_LOW16 },
341 { BFD_RELOC_SH_GOTPLT_MEDLOW16, R_SH_GOTPLT_MEDLOW16 },
342 { BFD_RELOC_SH_GOTPLT_MEDHI16, R_SH_GOTPLT_MEDHI16 },
343 { BFD_RELOC_SH_GOTPLT_HI16, R_SH_GOTPLT_HI16 },
344 { BFD_RELOC_SH_PLT_LOW16, R_SH_PLT_LOW16 },
345 { BFD_RELOC_SH_PLT_MEDLOW16, R_SH_PLT_MEDLOW16 },
346 { BFD_RELOC_SH_PLT_MEDHI16, R_SH_PLT_MEDHI16 },
347 { BFD_RELOC_SH_PLT_HI16, R_SH_PLT_HI16 },
348 { BFD_RELOC_SH_GOTOFF_LOW16, R_SH_GOTOFF_LOW16 },
349 { BFD_RELOC_SH_GOTOFF_MEDLOW16, R_SH_GOTOFF_MEDLOW16 },
350 { BFD_RELOC_SH_GOTOFF_MEDHI16, R_SH_GOTOFF_MEDHI16 },
351 { BFD_RELOC_SH_GOTOFF_HI16, R_SH_GOTOFF_HI16 },
352 { BFD_RELOC_SH_GOTPC_LOW16, R_SH_GOTPC_LOW16 },
353 { BFD_RELOC_SH_GOTPC_MEDLOW16, R_SH_GOTPC_MEDLOW16 },
354 { BFD_RELOC_SH_GOTPC_MEDHI16, R_SH_GOTPC_MEDHI16 },
355 { BFD_RELOC_SH_GOTPC_HI16, R_SH_GOTPC_HI16 },
356 { BFD_RELOC_SH_COPY64, R_SH_COPY64 },
357 { BFD_RELOC_SH_GLOB_DAT64, R_SH_GLOB_DAT64 },
358 { BFD_RELOC_SH_JMP_SLOT64, R_SH_JMP_SLOT64 },
359 { BFD_RELOC_SH_RELATIVE64, R_SH_RELATIVE64 },
360 { BFD_RELOC_SH_GOT10BY4, R_SH_GOT10BY4 },
361 { BFD_RELOC_SH_GOT10BY8, R_SH_GOT10BY8 },
362 { BFD_RELOC_SH_GOTPLT10BY4, R_SH_GOTPLT10BY4 },
363 { BFD_RELOC_SH_GOTPLT10BY8, R_SH_GOTPLT10BY8 },
364 { BFD_RELOC_SH_PT_16, R_SH_PT_16 },
365 { BFD_RELOC_SH_SHMEDIA_CODE, R_SH_SHMEDIA_CODE },
366 { BFD_RELOC_SH_IMMU5, R_SH_DIR5U },
367 { BFD_RELOC_SH_IMMS6, R_SH_DIR6S },
368 { BFD_RELOC_SH_IMMU6, R_SH_DIR6U },
369 { BFD_RELOC_SH_IMMS10, R_SH_DIR10S },
370 { BFD_RELOC_SH_IMMS10BY2, R_SH_DIR10SW },
371 { BFD_RELOC_SH_IMMS10BY4, R_SH_DIR10SL },
372 { BFD_RELOC_SH_IMMS10BY8, R_SH_DIR10SQ },
373 { BFD_RELOC_SH_IMMS16, R_SH_IMMS16 },
374 { BFD_RELOC_SH_IMMU16, R_SH_IMMU16 },
375 { BFD_RELOC_SH_IMM_LOW16, R_SH_IMM_LOW16 },
376 { BFD_RELOC_SH_IMM_LOW16_PCREL, R_SH_IMM_LOW16_PCREL },
377 { BFD_RELOC_SH_IMM_MEDLOW16, R_SH_IMM_MEDLOW16 },
378 { BFD_RELOC_SH_IMM_MEDLOW16_PCREL, R_SH_IMM_MEDLOW16_PCREL },
379 { BFD_RELOC_SH_IMM_MEDHI16, R_SH_IMM_MEDHI16 },
380 { BFD_RELOC_SH_IMM_MEDHI16_PCREL, R_SH_IMM_MEDHI16_PCREL },
381 { BFD_RELOC_SH_IMM_HI16, R_SH_IMM_HI16 },
382 { BFD_RELOC_SH_IMM_HI16_PCREL, R_SH_IMM_HI16_PCREL },
383 { BFD_RELOC_64, R_SH_64 },
384 { BFD_RELOC_64_PCREL, R_SH_64_PCREL },
385 #endif /* not INCLUDE_SHMEDIA */
388 /* Given a BFD reloc code, return the howto structure for the
389 corresponding SH ELF reloc. */
391 static reloc_howto_type *
392 sh_elf_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code)
396 for (i = 0; i < sizeof (sh_reloc_map) / sizeof (struct elf_reloc_map); i++)
398 if (sh_reloc_map[i].bfd_reloc_val == code)
399 return get_howto_table (abfd) + (int) sh_reloc_map[i].elf_reloc_val;
405 /* Given an ELF reloc, fill in the howto field of a relent. */
408 sh_elf_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)
412 r = ELF32_R_TYPE (dst->r_info);
414 BFD_ASSERT (r < (unsigned int) R_SH_max);
415 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC || r > R_SH_LAST_INVALID_RELOC);
416 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_2 || r > R_SH_LAST_INVALID_RELOC_2);
417 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_3 || r > R_SH_LAST_INVALID_RELOC_3);
418 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_4 || r > R_SH_LAST_INVALID_RELOC_4);
419 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_5 || r > R_SH_LAST_INVALID_RELOC_5);
421 cache_ptr->howto = get_howto_table (abfd) + r;
424 /* This function handles relaxing for SH ELF. See the corresponding
425 function in coff-sh.c for a description of what this does. FIXME:
426 There is a lot of duplication here between this code and the COFF
427 specific code. The format of relocs and symbols is wound deeply
428 into this code, but it would still be better if the duplication
429 could be eliminated somehow. Note in particular that although both
430 functions use symbols like R_SH_CODE, those symbols have different
431 values; in coff-sh.c they come from include/coff/sh.h, whereas here
432 they come from enum elf_sh_reloc_type in include/elf/sh.h. */
435 sh_elf_relax_section (bfd *abfd, asection *sec,
436 struct bfd_link_info *link_info, bfd_boolean *again)
438 Elf_Internal_Shdr *symtab_hdr;
439 Elf_Internal_Rela *internal_relocs;
440 bfd_boolean have_code;
441 Elf_Internal_Rela *irel, *irelend;
442 bfd_byte *contents = NULL;
443 Elf_Internal_Sym *isymbuf = NULL;
447 if (link_info->relocatable
448 || (sec->flags & SEC_RELOC) == 0
449 || sec->reloc_count == 0)
452 #ifdef INCLUDE_SHMEDIA
453 if (elf_section_data (sec)->this_hdr.sh_flags
454 & (SHF_SH5_ISA32 | SHF_SH5_ISA32_MIXED))
460 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
462 internal_relocs = (_bfd_elf_link_read_relocs
463 (abfd, sec, NULL, (Elf_Internal_Rela *) NULL,
464 link_info->keep_memory));
465 if (internal_relocs == NULL)
470 irelend = internal_relocs + sec->reloc_count;
471 for (irel = internal_relocs; irel < irelend; irel++)
473 bfd_vma laddr, paddr, symval;
475 Elf_Internal_Rela *irelfn, *irelscan, *irelcount;
478 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_CODE)
481 if (ELF32_R_TYPE (irel->r_info) != (int) R_SH_USES)
484 /* Get the section contents. */
485 if (contents == NULL)
487 if (elf_section_data (sec)->this_hdr.contents != NULL)
488 contents = elf_section_data (sec)->this_hdr.contents;
491 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
496 /* The r_addend field of the R_SH_USES reloc will point us to
497 the register load. The 4 is because the r_addend field is
498 computed as though it were a jump offset, which are based
499 from 4 bytes after the jump instruction. */
500 laddr = irel->r_offset + 4 + irel->r_addend;
501 if (laddr >= sec->size)
503 (*_bfd_error_handler) (_("%B: 0x%lx: warning: bad R_SH_USES offset"),
505 (unsigned long) irel->r_offset);
508 insn = bfd_get_16 (abfd, contents + laddr);
510 /* If the instruction is not mov.l NN,rN, we don't know what to
512 if ((insn & 0xf000) != 0xd000)
514 ((*_bfd_error_handler)
515 (_("%B: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x"),
516 abfd, (unsigned long) irel->r_offset, insn));
520 /* Get the address from which the register is being loaded. The
521 displacement in the mov.l instruction is quadrupled. It is a
522 displacement from four bytes after the movl instruction, but,
523 before adding in the PC address, two least significant bits
524 of the PC are cleared. We assume that the section is aligned
525 on a four byte boundary. */
528 paddr += (laddr + 4) &~ (bfd_vma) 3;
529 if (paddr >= sec->size)
531 ((*_bfd_error_handler)
532 (_("%B: 0x%lx: warning: bad R_SH_USES load offset"),
533 abfd, (unsigned long) irel->r_offset));
537 /* Get the reloc for the address from which the register is
538 being loaded. This reloc will tell us which function is
539 actually being called. */
540 for (irelfn = internal_relocs; irelfn < irelend; irelfn++)
541 if (irelfn->r_offset == paddr
542 && ELF32_R_TYPE (irelfn->r_info) == (int) R_SH_DIR32)
544 if (irelfn >= irelend)
546 ((*_bfd_error_handler)
547 (_("%B: 0x%lx: warning: could not find expected reloc"),
548 abfd, (unsigned long) paddr));
552 /* Read this BFD's symbols if we haven't done so already. */
553 if (isymbuf == NULL && symtab_hdr->sh_info != 0)
555 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
557 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
558 symtab_hdr->sh_info, 0,
564 /* Get the value of the symbol referred to by the reloc. */
565 if (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
567 /* A local symbol. */
568 Elf_Internal_Sym *isym;
570 isym = isymbuf + ELF32_R_SYM (irelfn->r_info);
572 != (unsigned int) _bfd_elf_section_from_bfd_section (abfd, sec))
574 ((*_bfd_error_handler)
575 (_("%B: 0x%lx: warning: symbol in unexpected section"),
576 abfd, (unsigned long) paddr));
580 symval = (isym->st_value
581 + sec->output_section->vma
582 + sec->output_offset);
587 struct elf_link_hash_entry *h;
589 indx = ELF32_R_SYM (irelfn->r_info) - symtab_hdr->sh_info;
590 h = elf_sym_hashes (abfd)[indx];
591 BFD_ASSERT (h != NULL);
592 if (h->root.type != bfd_link_hash_defined
593 && h->root.type != bfd_link_hash_defweak)
595 /* This appears to be a reference to an undefined
596 symbol. Just ignore it--it will be caught by the
597 regular reloc processing. */
601 symval = (h->root.u.def.value
602 + h->root.u.def.section->output_section->vma
603 + h->root.u.def.section->output_offset);
606 if (get_howto_table (abfd)[R_SH_DIR32].partial_inplace)
607 symval += bfd_get_32 (abfd, contents + paddr);
609 symval += irelfn->r_addend;
611 /* See if this function call can be shortened. */
614 + sec->output_section->vma
617 if (foff < -0x1000 || foff >= 0x1000)
619 /* After all that work, we can't shorten this function call. */
623 /* Shorten the function call. */
625 /* For simplicity of coding, we are going to modify the section
626 contents, the section relocs, and the BFD symbol table. We
627 must tell the rest of the code not to free up this
628 information. It would be possible to instead create a table
629 of changes which have to be made, as is done in coff-mips.c;
630 that would be more work, but would require less memory when
631 the linker is run. */
633 elf_section_data (sec)->relocs = internal_relocs;
634 elf_section_data (sec)->this_hdr.contents = contents;
635 symtab_hdr->contents = (unsigned char *) isymbuf;
637 /* Replace the jsr with a bsr. */
639 /* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and
640 replace the jsr with a bsr. */
641 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irelfn->r_info), R_SH_IND12W);
642 /* We used to test (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
643 here, but that only checks if the symbol is an external symbol,
644 not if the symbol is in a different section. Besides, we need
645 a consistent meaning for the relocation, so we just assume here that
646 the value of the symbol is not available. */
648 /* We can't fully resolve this yet, because the external
649 symbol value may be changed by future relaxing. We let
650 the final link phase handle it. */
651 bfd_put_16 (abfd, (bfd_vma) 0xb000, contents + irel->r_offset);
655 /* See if there is another R_SH_USES reloc referring to the same
657 for (irelscan = internal_relocs; irelscan < irelend; irelscan++)
658 if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_USES
659 && laddr == irelscan->r_offset + 4 + irelscan->r_addend)
661 if (irelscan < irelend)
663 /* Some other function call depends upon this register load,
664 and we have not yet converted that function call.
665 Indeed, we may never be able to convert it. There is
666 nothing else we can do at this point. */
670 /* Look for a R_SH_COUNT reloc on the location where the
671 function address is stored. Do this before deleting any
672 bytes, to avoid confusion about the address. */
673 for (irelcount = internal_relocs; irelcount < irelend; irelcount++)
674 if (irelcount->r_offset == paddr
675 && ELF32_R_TYPE (irelcount->r_info) == (int) R_SH_COUNT)
678 /* Delete the register load. */
679 if (! sh_elf_relax_delete_bytes (abfd, sec, laddr, 2))
682 /* That will change things, so, just in case it permits some
683 other function call to come within range, we should relax
684 again. Note that this is not required, and it may be slow. */
687 /* Now check whether we got a COUNT reloc. */
688 if (irelcount >= irelend)
690 ((*_bfd_error_handler)
691 (_("%B: 0x%lx: warning: could not find expected COUNT reloc"),
692 abfd, (unsigned long) paddr));
696 /* The number of uses is stored in the r_addend field. We've
698 if (irelcount->r_addend == 0)
700 ((*_bfd_error_handler) (_("%B: 0x%lx: warning: bad count"),
702 (unsigned long) paddr));
706 --irelcount->r_addend;
708 /* If there are no more uses, we can delete the address. Reload
709 the address from irelfn, in case it was changed by the
710 previous call to sh_elf_relax_delete_bytes. */
711 if (irelcount->r_addend == 0)
713 if (! sh_elf_relax_delete_bytes (abfd, sec, irelfn->r_offset, 4))
717 /* We've done all we can with that function call. */
720 /* Look for load and store instructions that we can align on four
722 if ((elf_elfheader (abfd)->e_flags & EF_SH_MACH_MASK) != EF_SH4
727 /* Get the section contents. */
728 if (contents == NULL)
730 if (elf_section_data (sec)->this_hdr.contents != NULL)
731 contents = elf_section_data (sec)->this_hdr.contents;
734 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
739 if (! sh_elf_align_loads (abfd, sec, internal_relocs, contents,
745 elf_section_data (sec)->relocs = internal_relocs;
746 elf_section_data (sec)->this_hdr.contents = contents;
747 symtab_hdr->contents = (unsigned char *) isymbuf;
752 && symtab_hdr->contents != (unsigned char *) isymbuf)
754 if (! link_info->keep_memory)
758 /* Cache the symbols for elf_link_input_bfd. */
759 symtab_hdr->contents = (unsigned char *) isymbuf;
764 && elf_section_data (sec)->this_hdr.contents != contents)
766 if (! link_info->keep_memory)
770 /* Cache the section contents for elf_link_input_bfd. */
771 elf_section_data (sec)->this_hdr.contents = contents;
775 if (internal_relocs != NULL
776 && elf_section_data (sec)->relocs != internal_relocs)
777 free (internal_relocs);
783 && symtab_hdr->contents != (unsigned char *) isymbuf)
786 && elf_section_data (sec)->this_hdr.contents != contents)
788 if (internal_relocs != NULL
789 && elf_section_data (sec)->relocs != internal_relocs)
790 free (internal_relocs);
795 /* Delete some bytes from a section while relaxing. FIXME: There is a
796 lot of duplication between this function and sh_relax_delete_bytes
800 sh_elf_relax_delete_bytes (bfd *abfd, asection *sec, bfd_vma addr,
803 Elf_Internal_Shdr *symtab_hdr;
804 unsigned int sec_shndx;
806 Elf_Internal_Rela *irel, *irelend;
807 Elf_Internal_Rela *irelalign;
809 Elf_Internal_Sym *isymbuf, *isym, *isymend;
810 struct elf_link_hash_entry **sym_hashes;
811 struct elf_link_hash_entry **end_hashes;
812 unsigned int symcount;
815 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
816 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
818 sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
820 contents = elf_section_data (sec)->this_hdr.contents;
822 /* The deletion must stop at the next ALIGN reloc for an aligment
823 power larger than the number of bytes we are deleting. */
828 irel = elf_section_data (sec)->relocs;
829 irelend = irel + sec->reloc_count;
830 for (; irel < irelend; irel++)
832 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_ALIGN
833 && irel->r_offset > addr
834 && count < (1 << irel->r_addend))
837 toaddr = irel->r_offset;
842 /* Actually delete the bytes. */
843 memmove (contents + addr, contents + addr + count,
844 (size_t) (toaddr - addr - count));
845 if (irelalign == NULL)
851 #define NOP_OPCODE (0x0009)
853 BFD_ASSERT ((count & 1) == 0);
854 for (i = 0; i < count; i += 2)
855 bfd_put_16 (abfd, (bfd_vma) NOP_OPCODE, contents + toaddr - count + i);
858 /* Adjust all the relocs. */
859 for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)
861 bfd_vma nraddr, stop;
864 int off, adjust, oinsn;
865 bfd_signed_vma voff = 0;
866 bfd_boolean overflow;
868 /* Get the new reloc address. */
869 nraddr = irel->r_offset;
870 if ((irel->r_offset > addr
871 && irel->r_offset < toaddr)
872 || (ELF32_R_TYPE (irel->r_info) == (int) R_SH_ALIGN
873 && irel->r_offset == toaddr))
876 /* See if this reloc was for the bytes we have deleted, in which
877 case we no longer care about it. Don't delete relocs which
878 represent addresses, though. */
879 if (irel->r_offset >= addr
880 && irel->r_offset < addr + count
881 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_ALIGN
882 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_CODE
883 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_DATA
884 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_LABEL)
885 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
888 /* If this is a PC relative reloc, see if the range it covers
889 includes the bytes we have deleted. */
890 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
899 start = irel->r_offset;
900 insn = bfd_get_16 (abfd, contents + nraddr);
904 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
911 /* If this reloc is against a symbol defined in this
912 section, and the symbol will not be adjusted below, we
913 must check the addend to see it will put the value in
914 range to be adjusted, and hence must be changed. */
915 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
917 isym = isymbuf + ELF32_R_SYM (irel->r_info);
918 if (isym->st_shndx == sec_shndx
919 && (isym->st_value <= addr
920 || isym->st_value >= toaddr))
924 if (get_howto_table (abfd)[R_SH_DIR32].partial_inplace)
926 val = bfd_get_32 (abfd, contents + nraddr);
927 val += isym->st_value;
928 if (val > addr && val < toaddr)
929 bfd_put_32 (abfd, val - count, contents + nraddr);
933 val = isym->st_value + irel->r_addend;
934 if (val > addr && val < toaddr)
935 irel->r_addend -= count;
946 stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
953 /* This has been made by previous relaxation. Since the
954 relocation will be against an external symbol, the
955 final relocation will just do the right thing. */
962 stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
964 /* The addend will be against the section symbol, thus
965 for adjusting the addend, the relevant start is the
966 start of the section.
967 N.B. If we want to abandon in-place changes here and
968 test directly using symbol + addend, we have to take into
969 account that the addend has already been adjusted by -4. */
970 if (stop > addr && stop < toaddr)
971 irel->r_addend -= count;
977 stop = start + 4 + off * 2;
982 stop = (start & ~(bfd_vma) 3) + 4 + off * 4;
988 /* These relocs types represent
990 The r_addend field holds the difference between the reloc
991 address and L1. That is the start of the reloc, and
992 adding in the contents gives us the top. We must adjust
993 both the r_offset field and the section contents.
994 N.B. in gas / coff bfd, the elf bfd r_addend is called r_offset,
995 and the elf bfd r_offset is called r_vaddr. */
997 stop = irel->r_offset;
998 start = (bfd_vma) ((bfd_signed_vma) stop - (long) irel->r_addend);
1002 && (stop <= addr || stop >= toaddr))
1003 irel->r_addend += count;
1004 else if (stop > addr
1006 && (start <= addr || start >= toaddr))
1007 irel->r_addend -= count;
1009 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_SWITCH16)
1010 voff = bfd_get_signed_16 (abfd, contents + nraddr);
1011 else if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_SWITCH8)
1012 voff = bfd_get_8 (abfd, contents + nraddr);
1014 voff = bfd_get_signed_32 (abfd, contents + nraddr);
1015 stop = (bfd_vma) ((bfd_signed_vma) start + voff);
1020 start = irel->r_offset;
1021 stop = (bfd_vma) ((bfd_signed_vma) start
1022 + (long) irel->r_addend
1029 && (stop <= addr || stop >= toaddr))
1031 else if (stop > addr
1033 && (start <= addr || start >= toaddr))
1042 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
1051 if ((oinsn & 0xff00) != (insn & 0xff00))
1053 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
1058 if ((oinsn & 0xf000) != (insn & 0xf000))
1060 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
1064 BFD_ASSERT (adjust == count || count >= 4);
1069 if ((irel->r_offset & 3) == 0)
1072 if ((oinsn & 0xff00) != (insn & 0xff00))
1074 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
1079 if (voff < 0 || voff >= 0xff)
1081 bfd_put_8 (abfd, voff, contents + nraddr);
1086 if (voff < - 0x8000 || voff >= 0x8000)
1088 bfd_put_signed_16 (abfd, (bfd_vma) voff, contents + nraddr);
1093 bfd_put_signed_32 (abfd, (bfd_vma) voff, contents + nraddr);
1097 irel->r_addend += adjust;
1103 ((*_bfd_error_handler)
1104 (_("%B: 0x%lx: fatal: reloc overflow while relaxing"),
1105 abfd, (unsigned long) irel->r_offset));
1106 bfd_set_error (bfd_error_bad_value);
1111 irel->r_offset = nraddr;
1114 /* Look through all the other sections. If there contain any IMM32
1115 relocs against internal symbols which we are not going to adjust
1116 below, we may need to adjust the addends. */
1117 for (o = abfd->sections; o != NULL; o = o->next)
1119 Elf_Internal_Rela *internal_relocs;
1120 Elf_Internal_Rela *irelscan, *irelscanend;
1121 bfd_byte *ocontents;
1124 || (o->flags & SEC_RELOC) == 0
1125 || o->reloc_count == 0)
1128 /* We always cache the relocs. Perhaps, if info->keep_memory is
1129 FALSE, we should free them, if we are permitted to, when we
1130 leave sh_coff_relax_section. */
1131 internal_relocs = (_bfd_elf_link_read_relocs
1132 (abfd, o, NULL, (Elf_Internal_Rela *) NULL, TRUE));
1133 if (internal_relocs == NULL)
1137 irelscanend = internal_relocs + o->reloc_count;
1138 for (irelscan = internal_relocs; irelscan < irelscanend; irelscan++)
1140 /* Dwarf line numbers use R_SH_SWITCH32 relocs. */
1141 if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_SWITCH32)
1143 bfd_vma start, stop;
1144 bfd_signed_vma voff;
1146 if (ocontents == NULL)
1148 if (elf_section_data (o)->this_hdr.contents != NULL)
1149 ocontents = elf_section_data (o)->this_hdr.contents;
1152 /* We always cache the section contents.
1153 Perhaps, if info->keep_memory is FALSE, we
1154 should free them, if we are permitted to,
1155 when we leave sh_coff_relax_section. */
1156 if (!bfd_malloc_and_get_section (abfd, o, &ocontents))
1158 if (ocontents != NULL)
1163 elf_section_data (o)->this_hdr.contents = ocontents;
1167 stop = irelscan->r_offset;
1169 = (bfd_vma) ((bfd_signed_vma) stop - (long) irelscan->r_addend);
1171 /* STOP is in a different section, so it won't change. */
1172 if (start > addr && start < toaddr)
1173 irelscan->r_addend += count;
1175 voff = bfd_get_signed_32 (abfd, ocontents + irelscan->r_offset);
1176 stop = (bfd_vma) ((bfd_signed_vma) start + voff);
1180 && (stop <= addr || stop >= toaddr))
1181 bfd_put_signed_32 (abfd, (bfd_vma) voff + count,
1182 ocontents + irelscan->r_offset);
1183 else if (stop > addr
1185 && (start <= addr || start >= toaddr))
1186 bfd_put_signed_32 (abfd, (bfd_vma) voff - count,
1187 ocontents + irelscan->r_offset);
1190 if (ELF32_R_TYPE (irelscan->r_info) != (int) R_SH_DIR32)
1193 if (ELF32_R_SYM (irelscan->r_info) >= symtab_hdr->sh_info)
1197 isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
1198 if (isym->st_shndx == sec_shndx
1199 && (isym->st_value <= addr
1200 || isym->st_value >= toaddr))
1204 if (ocontents == NULL)
1206 if (elf_section_data (o)->this_hdr.contents != NULL)
1207 ocontents = elf_section_data (o)->this_hdr.contents;
1210 /* We always cache the section contents.
1211 Perhaps, if info->keep_memory is FALSE, we
1212 should free them, if we are permitted to,
1213 when we leave sh_coff_relax_section. */
1214 if (!bfd_malloc_and_get_section (abfd, o, &ocontents))
1216 if (ocontents != NULL)
1221 elf_section_data (o)->this_hdr.contents = ocontents;
1225 val = bfd_get_32 (abfd, ocontents + irelscan->r_offset);
1226 val += isym->st_value;
1227 if (val > addr && val < toaddr)
1228 bfd_put_32 (abfd, val - count,
1229 ocontents + irelscan->r_offset);
1234 /* Adjust the local symbols defined in this section. */
1235 isymend = isymbuf + symtab_hdr->sh_info;
1236 for (isym = isymbuf; isym < isymend; isym++)
1238 if (isym->st_shndx == sec_shndx
1239 && isym->st_value > addr
1240 && isym->st_value < toaddr)
1241 isym->st_value -= count;
1244 /* Now adjust the global symbols defined in this section. */
1245 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
1246 - symtab_hdr->sh_info);
1247 sym_hashes = elf_sym_hashes (abfd);
1248 end_hashes = sym_hashes + symcount;
1249 for (; sym_hashes < end_hashes; sym_hashes++)
1251 struct elf_link_hash_entry *sym_hash = *sym_hashes;
1252 if ((sym_hash->root.type == bfd_link_hash_defined
1253 || sym_hash->root.type == bfd_link_hash_defweak)
1254 && sym_hash->root.u.def.section == sec
1255 && sym_hash->root.u.def.value > addr
1256 && sym_hash->root.u.def.value < toaddr)
1258 sym_hash->root.u.def.value -= count;
1262 /* See if we can move the ALIGN reloc forward. We have adjusted
1263 r_offset for it already. */
1264 if (irelalign != NULL)
1266 bfd_vma alignto, alignaddr;
1268 alignto = BFD_ALIGN (toaddr, 1 << irelalign->r_addend);
1269 alignaddr = BFD_ALIGN (irelalign->r_offset,
1270 1 << irelalign->r_addend);
1271 if (alignto != alignaddr)
1273 /* Tail recursion. */
1274 return sh_elf_relax_delete_bytes (abfd, sec, alignaddr,
1275 (int) (alignto - alignaddr));
1282 /* Look for loads and stores which we can align to four byte
1283 boundaries. This is like sh_align_loads in coff-sh.c. */
1286 sh_elf_align_loads (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
1287 Elf_Internal_Rela *internal_relocs,
1288 bfd_byte *contents ATTRIBUTE_UNUSED,
1289 bfd_boolean *pswapped)
1291 Elf_Internal_Rela *irel, *irelend;
1292 bfd_vma *labels = NULL;
1293 bfd_vma *label, *label_end;
1298 irelend = internal_relocs + sec->reloc_count;
1300 /* Get all the addresses with labels on them. */
1301 amt = sec->reloc_count;
1302 amt *= sizeof (bfd_vma);
1303 labels = (bfd_vma *) bfd_malloc (amt);
1307 for (irel = internal_relocs; irel < irelend; irel++)
1309 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_LABEL)
1311 *label_end = irel->r_offset;
1316 /* Note that the assembler currently always outputs relocs in
1317 address order. If that ever changes, this code will need to sort
1318 the label values and the relocs. */
1322 for (irel = internal_relocs; irel < irelend; irel++)
1324 bfd_vma start, stop;
1326 if (ELF32_R_TYPE (irel->r_info) != (int) R_SH_CODE)
1329 start = irel->r_offset;
1331 for (irel++; irel < irelend; irel++)
1332 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_DATA)
1335 stop = irel->r_offset;
1339 if (! _bfd_sh_align_load_span (abfd, sec, contents, sh_elf_swap_insns,
1340 internal_relocs, &label,
1341 label_end, start, stop, pswapped))
1356 /* Swap two SH instructions. This is like sh_swap_insns in coff-sh.c. */
1359 sh_elf_swap_insns (bfd *abfd, asection *sec, void *relocs,
1360 bfd_byte *contents, bfd_vma addr)
1362 Elf_Internal_Rela *internal_relocs = (Elf_Internal_Rela *) relocs;
1363 unsigned short i1, i2;
1364 Elf_Internal_Rela *irel, *irelend;
1366 /* Swap the instructions themselves. */
1367 i1 = bfd_get_16 (abfd, contents + addr);
1368 i2 = bfd_get_16 (abfd, contents + addr + 2);
1369 bfd_put_16 (abfd, (bfd_vma) i2, contents + addr);
1370 bfd_put_16 (abfd, (bfd_vma) i1, contents + addr + 2);
1372 /* Adjust all reloc addresses. */
1373 irelend = internal_relocs + sec->reloc_count;
1374 for (irel = internal_relocs; irel < irelend; irel++)
1376 enum elf_sh_reloc_type type;
1379 /* There are a few special types of relocs that we don't want to
1380 adjust. These relocs do not apply to the instruction itself,
1381 but are only associated with the address. */
1382 type = (enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info);
1383 if (type == R_SH_ALIGN
1384 || type == R_SH_CODE
1385 || type == R_SH_DATA
1386 || type == R_SH_LABEL)
1389 /* If an R_SH_USES reloc points to one of the addresses being
1390 swapped, we must adjust it. It would be incorrect to do this
1391 for a jump, though, since we want to execute both
1392 instructions after the jump. (We have avoided swapping
1393 around a label, so the jump will not wind up executing an
1394 instruction it shouldn't). */
1395 if (type == R_SH_USES)
1399 off = irel->r_offset + 4 + irel->r_addend;
1401 irel->r_offset += 2;
1402 else if (off == addr + 2)
1403 irel->r_offset -= 2;
1406 if (irel->r_offset == addr)
1408 irel->r_offset += 2;
1411 else if (irel->r_offset == addr + 2)
1413 irel->r_offset -= 2;
1422 unsigned short insn, oinsn;
1423 bfd_boolean overflow;
1425 loc = contents + irel->r_offset;
1434 insn = bfd_get_16 (abfd, loc);
1437 if ((oinsn & 0xff00) != (insn & 0xff00))
1439 bfd_put_16 (abfd, (bfd_vma) insn, loc);
1443 insn = bfd_get_16 (abfd, loc);
1446 if ((oinsn & 0xf000) != (insn & 0xf000))
1448 bfd_put_16 (abfd, (bfd_vma) insn, loc);
1452 /* This reloc ignores the least significant 3 bits of
1453 the program counter before adding in the offset.
1454 This means that if ADDR is at an even address, the
1455 swap will not affect the offset. If ADDR is an at an
1456 odd address, then the instruction will be crossing a
1457 four byte boundary, and must be adjusted. */
1458 if ((addr & 3) != 0)
1460 insn = bfd_get_16 (abfd, loc);
1463 if ((oinsn & 0xff00) != (insn & 0xff00))
1465 bfd_put_16 (abfd, (bfd_vma) insn, loc);
1473 ((*_bfd_error_handler)
1474 (_("%B: 0x%lx: fatal: reloc overflow while relaxing"),
1475 abfd, (unsigned long) irel->r_offset));
1476 bfd_set_error (bfd_error_bad_value);
1484 #endif /* defined SH64_ELF */
1486 /* Describes one of the various PLT styles. */
1488 struct elf_sh_plt_info
1490 /* The template for the first PLT entry, or NULL if there is no special
1492 const bfd_byte *plt0_entry;
1494 /* The size of PLT0_ENTRY in bytes, or 0 if PLT0_ENTRY is NULL. */
1495 bfd_vma plt0_entry_size;
1497 /* Index I is the offset into PLT0_ENTRY of a pointer to
1498 _GLOBAL_OFFSET_TABLE_ + I * 4. The value is MINUS_ONE
1499 if there is no such pointer. */
1500 bfd_vma plt0_got_fields[3];
1502 /* The template for a symbol's PLT entry. */
1503 const bfd_byte *symbol_entry;
1505 /* The size of SYMBOL_ENTRY in bytes. */
1506 bfd_vma symbol_entry_size;
1508 /* Byte offsets of fields in SYMBOL_ENTRY. Not all fields are used
1509 on all targets. The comments by each member indicate the value
1510 that the field must hold. */
1512 bfd_vma got_entry; /* the address of the symbol's .got.plt entry */
1513 bfd_vma plt; /* .plt (or a branch to .plt on VxWorks) */
1514 bfd_vma reloc_offset; /* the offset of the symbol's JMP_SLOT reloc */
1517 /* The offset of the resolver stub from the start of SYMBOL_ENTRY. */
1518 bfd_vma symbol_resolve_offset;
1521 #ifdef INCLUDE_SHMEDIA
1523 /* The size in bytes of an entry in the procedure linkage table. */
1525 #define ELF_PLT_ENTRY_SIZE 64
1527 /* First entry in an absolute procedure linkage table look like this. */
1529 static const bfd_byte elf_sh_plt0_entry_be[ELF_PLT_ENTRY_SIZE] =
1531 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 16, r17 */
1532 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
1533 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
1534 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
1535 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
1536 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
1537 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1538 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1539 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1540 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1541 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1542 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1543 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1544 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1545 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1546 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1549 static const bfd_byte elf_sh_plt0_entry_le[ELF_PLT_ENTRY_SIZE] =
1551 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */
1552 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
1553 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
1554 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
1555 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
1556 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
1557 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1558 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1559 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1560 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1561 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1562 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1563 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1564 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1565 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1566 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1569 /* Sebsequent entries in an absolute procedure linkage table look like
1572 static const bfd_byte elf_sh_plt_entry_be[ELF_PLT_ENTRY_SIZE] =
1574 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 16, r25 */
1575 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
1576 0x89, 0x90, 0x01, 0x90, /* ld.l r25, 0, r25 */
1577 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
1578 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
1579 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1580 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1581 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1582 0xcc, 0x00, 0x01, 0x90, /* movi .PLT0 >> 16, r25 */
1583 0xc8, 0x00, 0x01, 0x90, /* shori .PLT0 & 65535, r25 */
1584 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
1585 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
1586 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
1587 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
1588 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1589 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1592 static const bfd_byte elf_sh_plt_entry_le[ELF_PLT_ENTRY_SIZE] =
1594 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */
1595 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
1596 0x90, 0x01, 0x90, 0x89, /* ld.l r25, 0, r25 */
1597 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
1598 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
1599 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1600 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1601 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1602 0x90, 0x01, 0x00, 0xcc, /* movi .PLT0 >> 16, r25 */
1603 0x90, 0x01, 0x00, 0xc8, /* shori .PLT0 & 65535, r25 */
1604 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
1605 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
1606 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
1607 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
1608 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1609 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1612 /* Entries in a PIC procedure linkage table look like this. */
1614 static const bfd_byte elf_sh_pic_plt_entry_be[ELF_PLT_ENTRY_SIZE] =
1616 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */
1617 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
1618 0x40, 0xc2, 0x65, 0x90, /* ldx.l r12, r25, r25 */
1619 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
1620 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
1621 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1622 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1623 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1624 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */
1625 0x00, 0xc8, 0x45, 0x10, /* add.l r12, r17, r17 */
1626 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
1627 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
1628 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
1629 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
1630 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
1631 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
1634 static const bfd_byte elf_sh_pic_plt_entry_le[ELF_PLT_ENTRY_SIZE] =
1636 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */
1637 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
1638 0x90, 0x65, 0xc2, 0x40, /* ldx.l r12, r25, r25 */
1639 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
1640 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
1641 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1642 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1643 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1644 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */
1645 0x10, 0x45, 0xc8, 0x00, /* add.l r12, r17, r17 */
1646 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
1647 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
1648 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
1649 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
1650 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
1651 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
1654 static const struct elf_sh_plt_info elf_sh_plts[2][2] = {
1657 /* Big-endian non-PIC. */
1658 elf_sh_plt0_entry_be,
1660 { 0, MINUS_ONE, MINUS_ONE },
1661 elf_sh_plt_entry_be,
1664 33 /* includes ISA encoding */
1667 /* Little-endian non-PIC. */
1668 elf_sh_plt0_entry_le,
1670 { 0, MINUS_ONE, MINUS_ONE },
1671 elf_sh_plt_entry_le,
1674 33 /* includes ISA encoding */
1679 /* Big-endian PIC. */
1680 elf_sh_plt0_entry_be,
1682 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
1683 elf_sh_pic_plt_entry_be,
1685 { 0, MINUS_ONE, 52 },
1686 33 /* includes ISA encoding */
1689 /* Little-endian PIC. */
1690 elf_sh_plt0_entry_le,
1692 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
1693 elf_sh_pic_plt_entry_le,
1695 { 0, MINUS_ONE, 52 },
1696 33 /* includes ISA encoding */
1701 /* Return offset of the linker in PLT0 entry. */
1702 #define elf_sh_plt0_gotplt_offset(info) 0
1704 /* Install a 32-bit PLT field starting at ADDR, which occurs in OUTPUT_BFD.
1705 VALUE is the field's value and CODE_P is true if VALUE refers to code,
1708 On SH64, each 32-bit field is loaded by a movi/shori pair. */
1711 install_plt_field (bfd *output_bfd, bfd_boolean code_p,
1712 unsigned long value, bfd_byte *addr)
1715 bfd_put_32 (output_bfd,
1716 bfd_get_32 (output_bfd, addr)
1717 | ((value >> 6) & 0x3fffc00),
1719 bfd_put_32 (output_bfd,
1720 bfd_get_32 (output_bfd, addr + 4)
1721 | ((value << 10) & 0x3fffc00),
1725 /* Return the type of PLT associated with ABFD. PIC_P is true if
1726 the object is position-independent. */
1728 static const struct elf_sh_plt_info *
1729 get_plt_info (bfd *abfd ATTRIBUTE_UNUSED, bfd_boolean pic_p)
1731 return &elf_sh_plts[pic_p][!bfd_big_endian (abfd)];
1734 /* The size in bytes of an entry in the procedure linkage table. */
1736 #define ELF_PLT_ENTRY_SIZE 28
1738 /* First entry in an absolute procedure linkage table look like this. */
1740 /* Note - this code has been "optimised" not to use r2. r2 is used by
1741 GCC to return the address of large structures, so it should not be
1742 corrupted here. This does mean however, that this PLT does not conform
1743 to the SH PIC ABI. That spec says that r0 contains the type of the PLT
1744 and r2 contains the GOT id. This version stores the GOT id in r0 and
1745 ignores the type. Loaders can easily detect this difference however,
1746 since the type will always be 0 or 8, and the GOT ids will always be
1747 greater than or equal to 12. */
1748 static const bfd_byte elf_sh_plt0_entry_be[ELF_PLT_ENTRY_SIZE] =
1750 0xd0, 0x05, /* mov.l 2f,r0 */
1751 0x60, 0x02, /* mov.l @r0,r0 */
1752 0x2f, 0x06, /* mov.l r0,@-r15 */
1753 0xd0, 0x03, /* mov.l 1f,r0 */
1754 0x60, 0x02, /* mov.l @r0,r0 */
1755 0x40, 0x2b, /* jmp @r0 */
1756 0x60, 0xf6, /* mov.l @r15+,r0 */
1757 0x00, 0x09, /* nop */
1758 0x00, 0x09, /* nop */
1759 0x00, 0x09, /* nop */
1760 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
1761 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
1764 static const bfd_byte elf_sh_plt0_entry_le[ELF_PLT_ENTRY_SIZE] =
1766 0x05, 0xd0, /* mov.l 2f,r0 */
1767 0x02, 0x60, /* mov.l @r0,r0 */
1768 0x06, 0x2f, /* mov.l r0,@-r15 */
1769 0x03, 0xd0, /* mov.l 1f,r0 */
1770 0x02, 0x60, /* mov.l @r0,r0 */
1771 0x2b, 0x40, /* jmp @r0 */
1772 0xf6, 0x60, /* mov.l @r15+,r0 */
1773 0x09, 0x00, /* nop */
1774 0x09, 0x00, /* nop */
1775 0x09, 0x00, /* nop */
1776 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
1777 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
1780 /* Sebsequent entries in an absolute procedure linkage table look like
1783 static const bfd_byte elf_sh_plt_entry_be[ELF_PLT_ENTRY_SIZE] =
1785 0xd0, 0x04, /* mov.l 1f,r0 */
1786 0x60, 0x02, /* mov.l @(r0,r12),r0 */
1787 0xd1, 0x02, /* mov.l 0f,r1 */
1788 0x40, 0x2b, /* jmp @r0 */
1789 0x60, 0x13, /* mov r1,r0 */
1790 0xd1, 0x03, /* mov.l 2f,r1 */
1791 0x40, 0x2b, /* jmp @r0 */
1792 0x00, 0x09, /* nop */
1793 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
1794 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
1795 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
1798 static const bfd_byte elf_sh_plt_entry_le[ELF_PLT_ENTRY_SIZE] =
1800 0x04, 0xd0, /* mov.l 1f,r0 */
1801 0x02, 0x60, /* mov.l @r0,r0 */
1802 0x02, 0xd1, /* mov.l 0f,r1 */
1803 0x2b, 0x40, /* jmp @r0 */
1804 0x13, 0x60, /* mov r1,r0 */
1805 0x03, 0xd1, /* mov.l 2f,r1 */
1806 0x2b, 0x40, /* jmp @r0 */
1807 0x09, 0x00, /* nop */
1808 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
1809 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
1810 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
1813 /* Entries in a PIC procedure linkage table look like this. */
1815 static const bfd_byte elf_sh_pic_plt_entry_be[ELF_PLT_ENTRY_SIZE] =
1817 0xd0, 0x04, /* mov.l 1f,r0 */
1818 0x00, 0xce, /* mov.l @(r0,r12),r0 */
1819 0x40, 0x2b, /* jmp @r0 */
1820 0x00, 0x09, /* nop */
1821 0x50, 0xc2, /* mov.l @(8,r12),r0 */
1822 0xd1, 0x03, /* mov.l 2f,r1 */
1823 0x40, 0x2b, /* jmp @r0 */
1824 0x50, 0xc1, /* mov.l @(4,r12),r0 */
1825 0x00, 0x09, /* nop */
1826 0x00, 0x09, /* nop */
1827 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
1828 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
1831 static const bfd_byte elf_sh_pic_plt_entry_le[ELF_PLT_ENTRY_SIZE] =
1833 0x04, 0xd0, /* mov.l 1f,r0 */
1834 0xce, 0x00, /* mov.l @(r0,r12),r0 */
1835 0x2b, 0x40, /* jmp @r0 */
1836 0x09, 0x00, /* nop */
1837 0xc2, 0x50, /* mov.l @(8,r12),r0 */
1838 0x03, 0xd1, /* mov.l 2f,r1 */
1839 0x2b, 0x40, /* jmp @r0 */
1840 0xc1, 0x50, /* mov.l @(4,r12),r0 */
1841 0x09, 0x00, /* nop */
1842 0x09, 0x00, /* nop */
1843 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
1844 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
1847 static const struct elf_sh_plt_info elf_sh_plts[2][2] = {
1850 /* Big-endian non-PIC. */
1851 elf_sh_plt0_entry_be,
1853 { MINUS_ONE, 24, 20 },
1854 elf_sh_plt_entry_be,
1860 /* Little-endian non-PIC. */
1861 elf_sh_plt0_entry_le,
1863 { MINUS_ONE, 24, 20 },
1864 elf_sh_plt_entry_le,
1872 /* Big-endian PIC. */
1873 elf_sh_plt0_entry_be,
1875 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
1876 elf_sh_pic_plt_entry_be,
1878 { 20, MINUS_ONE, 24 },
1882 /* Little-endian PIC. */
1883 elf_sh_plt0_entry_le,
1885 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
1886 elf_sh_pic_plt_entry_le,
1888 { 20, MINUS_ONE, 24 },
1894 #define VXWORKS_PLT_HEADER_SIZE 12
1895 #define VXWORKS_PLT_ENTRY_SIZE 24
1897 static const bfd_byte vxworks_sh_plt0_entry_be[VXWORKS_PLT_HEADER_SIZE] =
1899 0xd1, 0x01, /* mov.l @(8,pc),r1 */
1900 0x61, 0x12, /* mov.l @r1,r1 */
1901 0x41, 0x2b, /* jmp @r1 */
1902 0x00, 0x09, /* nop */
1903 0, 0, 0, 0 /* 0: replaced with _GLOBAL_OFFSET_TABLE+8. */
1906 static const bfd_byte vxworks_sh_plt0_entry_le[VXWORKS_PLT_HEADER_SIZE] =
1908 0x01, 0xd1, /* mov.l @(8,pc),r1 */
1909 0x12, 0x61, /* mov.l @r1,r1 */
1910 0x2b, 0x41, /* jmp @r1 */
1911 0x09, 0x00, /* nop */
1912 0, 0, 0, 0 /* 0: replaced with _GLOBAL_OFFSET_TABLE+8. */
1915 static const bfd_byte vxworks_sh_plt_entry_be[VXWORKS_PLT_ENTRY_SIZE] =
1917 0xd0, 0x01, /* mov.l @(8,pc),r0 */
1918 0x60, 0x02, /* mov.l @r0,r0 */
1919 0x40, 0x2b, /* jmp @r0 */
1920 0x00, 0x09, /* nop */
1921 0, 0, 0, 0, /* 0: replaced with address of this symbol in .got. */
1922 0xd0, 0x01, /* mov.l @(8,pc),r0 */
1923 0xa0, 0x00, /* bra PLT (We need to fix the offset.) */
1924 0x00, 0x09, /* nop */
1925 0x00, 0x09, /* nop */
1926 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
1929 static const bfd_byte vxworks_sh_plt_entry_le[VXWORKS_PLT_ENTRY_SIZE] =
1931 0x01, 0xd0, /* mov.l @(8,pc),r0 */
1932 0x02, 0x60, /* mov.l @r0,r0 */
1933 0x2b, 0x40, /* jmp @r0 */
1934 0x09, 0x00, /* nop */
1935 0, 0, 0, 0, /* 0: replaced with address of this symbol in .got. */
1936 0x01, 0xd0, /* mov.l @(8,pc),r0 */
1937 0x00, 0xa0, /* bra PLT (We need to fix the offset.) */
1938 0x09, 0x00, /* nop */
1939 0x09, 0x00, /* nop */
1940 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
1943 static const bfd_byte vxworks_sh_pic_plt_entry_be[VXWORKS_PLT_ENTRY_SIZE] =
1945 0xd0, 0x01, /* mov.l @(8,pc),r0 */
1946 0x00, 0xce, /* mov.l @(r0,r12),r0 */
1947 0x40, 0x2b, /* jmp @r0 */
1948 0x00, 0x09, /* nop */
1949 0, 0, 0, 0, /* 0: replaced with offset of this symbol in .got. */
1950 0xd0, 0x01, /* mov.l @(8,pc),r0 */
1951 0x51, 0xc2, /* mov.l @(8,r12),r1 */
1952 0x41, 0x2b, /* jmp @r1 */
1953 0x00, 0x09, /* nop */
1954 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
1957 static const bfd_byte vxworks_sh_pic_plt_entry_le[VXWORKS_PLT_ENTRY_SIZE] =
1959 0x01, 0xd0, /* mov.l @(8,pc),r0 */
1960 0xce, 0x00, /* mov.l @(r0,r12),r0 */
1961 0x2b, 0x40, /* jmp @r0 */
1962 0x09, 0x00, /* nop */
1963 0, 0, 0, 0, /* 0: replaced with offset of this symbol in .got. */
1964 0x01, 0xd0, /* mov.l @(8,pc),r0 */
1965 0xc2, 0x51, /* mov.l @(8,r12),r1 */
1966 0x2b, 0x41, /* jmp @r1 */
1967 0x09, 0x00, /* nop */
1968 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
1971 static const struct elf_sh_plt_info vxworks_sh_plts[2][2] = {
1974 /* Big-endian non-PIC. */
1975 vxworks_sh_plt0_entry_be,
1976 VXWORKS_PLT_HEADER_SIZE,
1977 { MINUS_ONE, MINUS_ONE, 8 },
1978 vxworks_sh_plt_entry_be,
1979 VXWORKS_PLT_ENTRY_SIZE,
1984 /* Little-endian non-PIC. */
1985 vxworks_sh_plt0_entry_le,
1986 VXWORKS_PLT_HEADER_SIZE,
1987 { MINUS_ONE, MINUS_ONE, 8 },
1988 vxworks_sh_plt_entry_le,
1989 VXWORKS_PLT_ENTRY_SIZE,
1996 /* Big-endian PIC. */
1999 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2000 vxworks_sh_pic_plt_entry_be,
2001 VXWORKS_PLT_ENTRY_SIZE,
2002 { 8, MINUS_ONE, 20 },
2006 /* Little-endian PIC. */
2009 { MINUS_ONE, MINUS_ONE, MINUS_ONE },
2010 vxworks_sh_pic_plt_entry_le,
2011 VXWORKS_PLT_ENTRY_SIZE,
2012 { 8, MINUS_ONE, 20 },
2018 /* Return the type of PLT associated with ABFD. PIC_P is true if
2019 the object is position-independent. */
2021 static const struct elf_sh_plt_info *
2022 get_plt_info (bfd *abfd ATTRIBUTE_UNUSED, bfd_boolean pic_p)
2024 if (vxworks_object_p (abfd))
2025 return &vxworks_sh_plts[pic_p][!bfd_big_endian (abfd)];
2026 return &elf_sh_plts[pic_p][!bfd_big_endian (abfd)];
2029 /* Install a 32-bit PLT field starting at ADDR, which occurs in OUTPUT_BFD.
2030 VALUE is the field's value and CODE_P is true if VALUE refers to code,
2034 install_plt_field (bfd *output_bfd, bfd_boolean code_p ATTRIBUTE_UNUSED,
2035 unsigned long value, bfd_byte *addr)
2037 bfd_put_32 (output_bfd, value, addr);
2041 /* Return the index of the PLT entry at byte offset OFFSET. */
2044 get_plt_index (const struct elf_sh_plt_info *info, bfd_vma offset)
2046 return (offset - info->plt0_entry_size) / info->symbol_entry_size;
2049 /* Do the inverse operation. */
2052 get_plt_offset (const struct elf_sh_plt_info *info, bfd_vma index)
2054 return info->plt0_entry_size + (index * info->symbol_entry_size);
2057 /* The sh linker needs to keep track of the number of relocs that it
2058 decides to copy as dynamic relocs in check_relocs for each symbol.
2059 This is so that it can later discard them if they are found to be
2060 unnecessary. We store the information in a field extending the
2061 regular ELF linker hash table. */
2063 struct elf_sh_dyn_relocs
2065 struct elf_sh_dyn_relocs *next;
2067 /* The input section of the reloc. */
2070 /* Total number of relocs copied for the input section. */
2071 bfd_size_type count;
2073 /* Number of pc-relative relocs copied for the input section. */
2074 bfd_size_type pc_count;
2077 /* sh ELF linker hash entry. */
2079 struct elf_sh_link_hash_entry
2081 struct elf_link_hash_entry root;
2083 #ifdef INCLUDE_SHMEDIA
2086 bfd_signed_vma refcount;
2091 /* Track dynamic relocs copied for this symbol. */
2092 struct elf_sh_dyn_relocs *dyn_relocs;
2094 bfd_signed_vma gotplt_refcount;
2097 GOT_UNKNOWN = 0, GOT_NORMAL, GOT_TLS_GD, GOT_TLS_IE
2101 #define sh_elf_hash_entry(ent) ((struct elf_sh_link_hash_entry *)(ent))
2103 struct sh_elf_obj_tdata
2105 struct elf_obj_tdata root;
2107 /* tls_type for each local got entry. */
2108 char *local_got_tls_type;
2111 #define sh_elf_tdata(abfd) \
2112 ((struct sh_elf_obj_tdata *) (abfd)->tdata.any)
2114 #define sh_elf_local_got_tls_type(abfd) \
2115 (sh_elf_tdata (abfd)->local_got_tls_type)
2117 /* Override the generic function because we need to store sh_elf_obj_tdata
2118 as the specific tdata. */
2121 sh_elf_mkobject (bfd *abfd)
2123 if (abfd->tdata.any == NULL)
2125 bfd_size_type amt = sizeof (struct sh_elf_obj_tdata);
2126 abfd->tdata.any = bfd_zalloc (abfd, amt);
2127 if (abfd->tdata.any == NULL)
2130 return bfd_elf_mkobject (abfd);
2133 /* sh ELF linker hash table. */
2135 struct elf_sh_link_hash_table
2137 struct elf_link_hash_table root;
2139 /* Short-cuts to get to dynamic linker sections. */
2148 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
2151 /* Small local sym to section mapping cache. */
2152 struct sym_sec_cache sym_sec;
2154 /* A counter or offset to track a TLS got entry. */
2157 bfd_signed_vma refcount;
2161 /* The type of PLT to use. */
2162 const struct elf_sh_plt_info *plt_info;
2164 /* True if the target system is VxWorks. */
2165 bfd_boolean vxworks_p;
2168 /* Traverse an sh ELF linker hash table. */
2170 #define sh_elf_link_hash_traverse(table, func, info) \
2171 (elf_link_hash_traverse \
2173 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
2176 /* Get the sh ELF linker hash table from a link_info structure. */
2178 #define sh_elf_hash_table(p) \
2179 ((struct elf_sh_link_hash_table *) ((p)->hash))
2181 /* Create an entry in an sh ELF linker hash table. */
2183 static struct bfd_hash_entry *
2184 sh_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
2185 struct bfd_hash_table *table,
2188 struct elf_sh_link_hash_entry *ret =
2189 (struct elf_sh_link_hash_entry *) entry;
2191 /* Allocate the structure if it has not already been allocated by a
2193 if (ret == (struct elf_sh_link_hash_entry *) NULL)
2194 ret = ((struct elf_sh_link_hash_entry *)
2195 bfd_hash_allocate (table,
2196 sizeof (struct elf_sh_link_hash_entry)));
2197 if (ret == (struct elf_sh_link_hash_entry *) NULL)
2198 return (struct bfd_hash_entry *) ret;
2200 /* Call the allocation method of the superclass. */
2201 ret = ((struct elf_sh_link_hash_entry *)
2202 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2204 if (ret != (struct elf_sh_link_hash_entry *) NULL)
2206 ret->dyn_relocs = NULL;
2207 ret->gotplt_refcount = 0;
2208 #ifdef INCLUDE_SHMEDIA
2209 ret->datalabel_got.refcount = ret->root.got.refcount;
2211 ret->tls_type = GOT_UNKNOWN;
2214 return (struct bfd_hash_entry *) ret;
2217 /* Create an sh ELF linker hash table. */
2219 static struct bfd_link_hash_table *
2220 sh_elf_link_hash_table_create (bfd *abfd)
2222 struct elf_sh_link_hash_table *ret;
2223 bfd_size_type amt = sizeof (struct elf_sh_link_hash_table);
2225 ret = (struct elf_sh_link_hash_table *) bfd_malloc (amt);
2226 if (ret == (struct elf_sh_link_hash_table *) NULL)
2229 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
2230 sh_elf_link_hash_newfunc,
2231 sizeof (struct elf_sh_link_hash_entry)))
2238 ret->sgotplt = NULL;
2239 ret->srelgot = NULL;
2241 ret->srelplt = NULL;
2242 ret->sdynbss = NULL;
2243 ret->srelbss = NULL;
2244 ret->srelplt2 = NULL;
2245 ret->sym_sec.abfd = NULL;
2246 ret->tls_ldm_got.refcount = 0;
2247 ret->plt_info = NULL;
2248 ret->vxworks_p = vxworks_object_p (abfd);
2250 return &ret->root.root;
2253 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
2254 shortcuts to them in our hash table. */
2257 create_got_section (bfd *dynobj, struct bfd_link_info *info)
2259 struct elf_sh_link_hash_table *htab;
2261 if (! _bfd_elf_create_got_section (dynobj, info))
2264 htab = sh_elf_hash_table (info);
2265 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
2266 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
2267 if (! htab->sgot || ! htab->sgotplt)
2270 htab->srelgot = bfd_make_section_with_flags (dynobj, ".rela.got",
2271 (SEC_ALLOC | SEC_LOAD
2274 | SEC_LINKER_CREATED
2276 if (htab->srelgot == NULL
2277 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
2282 /* Create dynamic sections when linking against a dynamic object. */
2285 sh_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
2287 struct elf_sh_link_hash_table *htab;
2288 flagword flags, pltflags;
2289 register asection *s;
2290 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
2293 switch (bed->s->arch_size)
2304 bfd_set_error (bfd_error_bad_value);
2308 htab = sh_elf_hash_table (info);
2309 if (htab->root.dynamic_sections_created)
2312 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
2313 .rel[a].bss sections. */
2315 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2316 | SEC_LINKER_CREATED);
2319 pltflags |= SEC_CODE;
2320 if (bed->plt_not_loaded)
2321 pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
2322 if (bed->plt_readonly)
2323 pltflags |= SEC_READONLY;
2325 s = bfd_make_section_with_flags (abfd, ".plt", pltflags);
2328 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
2331 if (bed->want_plt_sym)
2333 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
2335 struct elf_link_hash_entry *h;
2336 struct bfd_link_hash_entry *bh = NULL;
2338 if (! (_bfd_generic_link_add_one_symbol
2339 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
2340 (bfd_vma) 0, (const char *) NULL, FALSE,
2341 get_elf_backend_data (abfd)->collect, &bh)))
2344 h = (struct elf_link_hash_entry *) bh;
2346 h->type = STT_OBJECT;
2347 htab->root.hplt = h;
2350 && ! bfd_elf_link_record_dynamic_symbol (info, h))
2354 s = bfd_make_section_with_flags (abfd,
2355 bed->default_use_rela_p ? ".rela.plt" : ".rel.plt",
2356 flags | SEC_READONLY);
2359 || ! bfd_set_section_alignment (abfd, s, ptralign))
2362 if (htab->sgot == NULL
2363 && !create_got_section (abfd, info))
2367 const char *secname;
2372 for (sec = abfd->sections; sec; sec = sec->next)
2374 secflags = bfd_get_section_flags (abfd, sec);
2375 if ((secflags & (SEC_DATA | SEC_LINKER_CREATED))
2376 || ((secflags & SEC_HAS_CONTENTS) != SEC_HAS_CONTENTS))
2378 secname = bfd_get_section_name (abfd, sec);
2379 relname = (char *) bfd_malloc ((bfd_size_type) strlen (secname) + 6);
2380 strcpy (relname, ".rela");
2381 strcat (relname, secname);
2382 if (bfd_get_section_by_name (abfd, secname))
2384 s = bfd_make_section_with_flags (abfd, relname,
2385 flags | SEC_READONLY);
2387 || ! bfd_set_section_alignment (abfd, s, ptralign))
2392 if (bed->want_dynbss)
2394 /* The .dynbss section is a place to put symbols which are defined
2395 by dynamic objects, are referenced by regular objects, and are
2396 not functions. We must allocate space for them in the process
2397 image and use a R_*_COPY reloc to tell the dynamic linker to
2398 initialize them at run time. The linker script puts the .dynbss
2399 section into the .bss section of the final image. */
2400 s = bfd_make_section_with_flags (abfd, ".dynbss",
2401 SEC_ALLOC | SEC_LINKER_CREATED);
2406 /* The .rel[a].bss section holds copy relocs. This section is not
2407 normally needed. We need to create it here, though, so that the
2408 linker will map it to an output section. We can't just create it
2409 only if we need it, because we will not know whether we need it
2410 until we have seen all the input files, and the first time the
2411 main linker code calls BFD after examining all the input files
2412 (size_dynamic_sections) the input sections have already been
2413 mapped to the output sections. If the section turns out not to
2414 be needed, we can discard it later. We will never need this
2415 section when generating a shared object, since they do not use
2419 s = bfd_make_section_with_flags (abfd,
2420 (bed->default_use_rela_p
2421 ? ".rela.bss" : ".rel.bss"),
2422 flags | SEC_READONLY);
2425 || ! bfd_set_section_alignment (abfd, s, ptralign))
2430 if (htab->vxworks_p)
2432 if (!elf_vxworks_create_dynamic_sections (abfd, info, &htab->srelplt2))
2439 /* Adjust a symbol defined by a dynamic object and referenced by a
2440 regular object. The current definition is in some section of the
2441 dynamic object, but we're not including those sections. We have to
2442 change the definition to something the rest of the link can
2446 sh_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
2447 struct elf_link_hash_entry *h)
2449 struct elf_sh_link_hash_table *htab;
2450 struct elf_sh_link_hash_entry *eh;
2451 struct elf_sh_dyn_relocs *p;
2453 unsigned int power_of_two;
2455 htab = sh_elf_hash_table (info);
2457 /* Make sure we know what is going on here. */
2458 BFD_ASSERT (htab->root.dynobj != NULL
2460 || h->u.weakdef != NULL
2463 && !h->def_regular)));
2465 /* If this is a function, put it in the procedure linkage table. We
2466 will fill in the contents of the procedure linkage table later,
2467 when we know the address of the .got section. */
2468 if (h->type == STT_FUNC
2471 if (h->plt.refcount <= 0
2472 || SYMBOL_CALLS_LOCAL (info, h)
2473 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
2474 && h->root.type == bfd_link_hash_undefweak))
2476 /* This case can occur if we saw a PLT reloc in an input
2477 file, but the symbol was never referred to by a dynamic
2478 object. In such a case, we don't actually need to build
2479 a procedure linkage table, and we can just do a REL32
2481 h->plt.offset = (bfd_vma) -1;
2488 h->plt.offset = (bfd_vma) -1;
2490 /* If this is a weak symbol, and there is a real definition, the
2491 processor independent code will have arranged for us to see the
2492 real definition first, and we can just use the same value. */
2493 if (h->u.weakdef != NULL)
2495 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
2496 || h->u.weakdef->root.type == bfd_link_hash_defweak);
2497 h->root.u.def.section = h->u.weakdef->root.u.def.section;
2498 h->root.u.def.value = h->u.weakdef->root.u.def.value;
2499 if (info->nocopyreloc)
2500 h->non_got_ref = h->u.weakdef->non_got_ref;
2504 /* This is a reference to a symbol defined by a dynamic object which
2505 is not a function. */
2507 /* If we are creating a shared library, we must presume that the
2508 only references to the symbol are via the global offset table.
2509 For such cases we need not do anything here; the relocations will
2510 be handled correctly by relocate_section. */
2514 /* If there are no references to this symbol that do not use the
2515 GOT, we don't need to generate a copy reloc. */
2516 if (!h->non_got_ref)
2519 /* If -z nocopyreloc was given, we won't generate them either. */
2520 if (info->nocopyreloc)
2526 eh = (struct elf_sh_link_hash_entry *) h;
2527 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2529 s = p->sec->output_section;
2530 if (s != NULL && (s->flags & (SEC_READONLY | SEC_HAS_CONTENTS)) != 0)
2534 /* If we didn't find any dynamic relocs in sections which needs the
2535 copy reloc, then we'll be keeping the dynamic relocs and avoiding
2545 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
2546 h->root.root.string);
2550 /* We must allocate the symbol in our .dynbss section, which will
2551 become part of the .bss section of the executable. There will be
2552 an entry for this symbol in the .dynsym section. The dynamic
2553 object will contain position independent code, so all references
2554 from the dynamic object to this symbol will go through the global
2555 offset table. The dynamic linker will use the .dynsym entry to
2556 determine the address it must put in the global offset table, so
2557 both the dynamic object and the regular object will refer to the
2558 same memory location for the variable. */
2561 BFD_ASSERT (s != NULL);
2563 /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
2564 copy the initial value out of the dynamic object and into the
2565 runtime process image. We need to remember the offset into the
2566 .rela.bss section we are going to use. */
2567 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
2571 srel = htab->srelbss;
2572 BFD_ASSERT (srel != NULL);
2573 srel->size += sizeof (Elf32_External_Rela);
2577 /* We need to figure out the alignment required for this symbol. I
2578 have no idea how ELF linkers handle this. */
2579 power_of_two = bfd_log2 (h->size);
2580 if (power_of_two > 3)
2583 /* Apply the required alignment. */
2584 s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
2585 if (power_of_two > bfd_get_section_alignment (htab->root.dynobj, s))
2587 if (! bfd_set_section_alignment (htab->root.dynobj, s, power_of_two))
2591 /* Define the symbol as being at this point in the section. */
2592 h->root.u.def.section = s;
2593 h->root.u.def.value = s->size;
2595 /* Increment the section size to make room for the symbol. */
2601 /* Allocate space in .plt, .got and associated reloc sections for
2605 allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
2607 struct bfd_link_info *info;
2608 struct elf_sh_link_hash_table *htab;
2609 struct elf_sh_link_hash_entry *eh;
2610 struct elf_sh_dyn_relocs *p;
2612 if (h->root.type == bfd_link_hash_indirect)
2615 if (h->root.type == bfd_link_hash_warning)
2616 /* When warning symbols are created, they **replace** the "real"
2617 entry in the hash table, thus we never get to see the real
2618 symbol in a hash traversal. So look at it now. */
2619 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2621 info = (struct bfd_link_info *) inf;
2622 htab = sh_elf_hash_table (info);
2624 eh = (struct elf_sh_link_hash_entry *) h;
2625 if ((h->got.refcount > 0
2627 && eh->gotplt_refcount > 0)
2629 /* The symbol has been forced local, or we have some direct got refs,
2630 so treat all the gotplt refs as got refs. */
2631 h->got.refcount += eh->gotplt_refcount;
2632 if (h->plt.refcount >= eh->gotplt_refcount)
2633 h->plt.refcount -= eh->gotplt_refcount;
2636 if (htab->root.dynamic_sections_created
2637 && h->plt.refcount > 0
2638 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2639 || h->root.type != bfd_link_hash_undefweak))
2641 /* Make sure this symbol is output as a dynamic symbol.
2642 Undefined weak syms won't yet be marked as dynamic. */
2643 if (h->dynindx == -1
2644 && !h->forced_local)
2646 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2651 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
2653 asection *s = htab->splt;
2655 /* If this is the first .plt entry, make room for the special
2658 s->size += htab->plt_info->plt0_entry_size;
2660 h->plt.offset = s->size;
2662 /* If this symbol is not defined in a regular file, and we are
2663 not generating a shared library, then set the symbol to this
2664 location in the .plt. This is required to make function
2665 pointers compare as equal between the normal executable and
2666 the shared library. */
2670 h->root.u.def.section = s;
2671 h->root.u.def.value = h->plt.offset;
2674 /* Make room for this entry. */
2675 s->size += htab->plt_info->symbol_entry_size;
2677 /* We also need to make an entry in the .got.plt section, which
2678 will be placed in the .got section by the linker script. */
2679 htab->sgotplt->size += 4;
2681 /* We also need to make an entry in the .rel.plt section. */
2682 htab->srelplt->size += sizeof (Elf32_External_Rela);
2684 if (htab->vxworks_p && !info->shared)
2686 /* VxWorks executables have a second set of relocations
2687 for each PLT entry. They go in a separate relocation
2688 section, which is processed by the kernel loader. */
2690 /* There is a relocation for the initial PLT entry:
2691 an R_SH_DIR32 relocation for _GLOBAL_OFFSET_TABLE_. */
2692 if (h->plt.offset == htab->plt_info->plt0_entry_size)
2693 htab->srelplt2->size += sizeof (Elf32_External_Rela);
2695 /* There are two extra relocations for each subsequent
2696 PLT entry: an R_SH_DIR32 relocation for the GOT entry,
2697 and an R_SH_DIR32 relocation for the PLT entry. */
2698 htab->srelplt2->size += sizeof (Elf32_External_Rela) * 2;
2703 h->plt.offset = (bfd_vma) -1;
2709 h->plt.offset = (bfd_vma) -1;
2713 if (h->got.refcount > 0)
2717 int tls_type = sh_elf_hash_entry (h)->tls_type;
2719 /* Make sure this symbol is output as a dynamic symbol.
2720 Undefined weak syms won't yet be marked as dynamic. */
2721 if (h->dynindx == -1
2722 && !h->forced_local)
2724 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2729 h->got.offset = s->size;
2731 /* R_SH_TLS_GD needs 2 consecutive GOT slots. */
2732 if (tls_type == GOT_TLS_GD)
2734 dyn = htab->root.dynamic_sections_created;
2735 /* R_SH_TLS_IE_32 needs one dynamic relocation if dynamic,
2736 R_SH_TLS_GD needs one if local symbol and two if global. */
2737 if ((tls_type == GOT_TLS_GD && h->dynindx == -1)
2738 || (tls_type == GOT_TLS_IE && dyn))
2739 htab->srelgot->size += sizeof (Elf32_External_Rela);
2740 else if (tls_type == GOT_TLS_GD)
2741 htab->srelgot->size += 2 * sizeof (Elf32_External_Rela);
2742 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2743 || h->root.type != bfd_link_hash_undefweak)
2745 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
2746 htab->srelgot->size += sizeof (Elf32_External_Rela);
2749 h->got.offset = (bfd_vma) -1;
2751 #ifdef INCLUDE_SHMEDIA
2752 if (eh->datalabel_got.refcount > 0)
2757 /* Make sure this symbol is output as a dynamic symbol.
2758 Undefined weak syms won't yet be marked as dynamic. */
2759 if (h->dynindx == -1
2760 && !h->forced_local)
2762 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2767 eh->datalabel_got.offset = s->size;
2769 dyn = htab->root.dynamic_sections_created;
2770 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h))
2771 htab->srelgot->size += sizeof (Elf32_External_Rela);
2774 eh->datalabel_got.offset = (bfd_vma) -1;
2777 if (eh->dyn_relocs == NULL)
2780 /* In the shared -Bsymbolic case, discard space allocated for
2781 dynamic pc-relative relocs against symbols which turn out to be
2782 defined in regular objects. For the normal shared case, discard
2783 space for pc-relative relocs that have become local due to symbol
2784 visibility changes. */
2788 if (SYMBOL_CALLS_LOCAL (info, h))
2790 struct elf_sh_dyn_relocs **pp;
2792 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
2794 p->count -= p->pc_count;
2803 /* Also discard relocs on undefined weak syms with non-default
2805 if (eh->dyn_relocs != NULL
2806 && h->root.type == bfd_link_hash_undefweak)
2808 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
2809 eh->dyn_relocs = NULL;
2811 /* Make sure undefined weak symbols are output as a dynamic
2813 else if (h->dynindx == -1
2814 && !h->forced_local)
2816 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2823 /* For the non-shared case, discard space for relocs against
2824 symbols which turn out to need copy relocs or are not
2830 || (htab->root.dynamic_sections_created
2831 && (h->root.type == bfd_link_hash_undefweak
2832 || h->root.type == bfd_link_hash_undefined))))
2834 /* Make sure this symbol is output as a dynamic symbol.
2835 Undefined weak syms won't yet be marked as dynamic. */
2836 if (h->dynindx == -1
2837 && !h->forced_local)
2839 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2843 /* If that succeeded, we know we'll be keeping all the
2845 if (h->dynindx != -1)
2849 eh->dyn_relocs = NULL;
2854 /* Finally, allocate space. */
2855 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2857 asection *sreloc = elf_section_data (p->sec)->sreloc;
2858 sreloc->size += p->count * sizeof (Elf32_External_Rela);
2864 /* Find any dynamic relocs that apply to read-only sections. */
2867 readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf)
2869 struct elf_sh_link_hash_entry *eh;
2870 struct elf_sh_dyn_relocs *p;
2872 if (h->root.type == bfd_link_hash_warning)
2873 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2875 eh = (struct elf_sh_link_hash_entry *) h;
2876 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2878 asection *s = p->sec->output_section;
2880 if (s != NULL && (s->flags & SEC_READONLY) != 0)
2882 struct bfd_link_info *info = (struct bfd_link_info *) inf;
2884 info->flags |= DF_TEXTREL;
2886 /* Not an error, just cut short the traversal. */
2893 /* This function is called after all the input files have been read,
2894 and the input sections have been assigned to output sections.
2895 It's a convenient place to determine the PLT style. */
2898 sh_elf_always_size_sections (bfd *output_bfd, struct bfd_link_info *info)
2900 sh_elf_hash_table (info)->plt_info = get_plt_info (output_bfd, info->shared);
2904 /* Set the sizes of the dynamic sections. */
2907 sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
2908 struct bfd_link_info *info)
2910 struct elf_sh_link_hash_table *htab;
2916 htab = sh_elf_hash_table (info);
2917 dynobj = htab->root.dynobj;
2918 BFD_ASSERT (dynobj != NULL);
2920 if (htab->root.dynamic_sections_created)
2922 /* Set the contents of the .interp section to the interpreter. */
2923 if (info->executable)
2925 s = bfd_get_section_by_name (dynobj, ".interp");
2926 BFD_ASSERT (s != NULL);
2927 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
2928 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
2932 /* Set up .got offsets for local syms, and space for local dynamic
2934 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
2936 bfd_signed_vma *local_got;
2937 bfd_signed_vma *end_local_got;
2938 char *local_tls_type;
2939 bfd_size_type locsymcount;
2940 Elf_Internal_Shdr *symtab_hdr;
2943 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
2946 for (s = ibfd->sections; s != NULL; s = s->next)
2948 struct elf_sh_dyn_relocs *p;
2950 for (p = ((struct elf_sh_dyn_relocs *)
2951 elf_section_data (s)->local_dynrel);
2955 if (! bfd_is_abs_section (p->sec)
2956 && bfd_is_abs_section (p->sec->output_section))
2958 /* Input section has been discarded, either because
2959 it is a copy of a linkonce section or due to
2960 linker script /DISCARD/, so we'll be discarding
2963 else if (p->count != 0)
2965 srel = elf_section_data (p->sec)->sreloc;
2966 srel->size += p->count * sizeof (Elf32_External_Rela);
2967 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
2968 info->flags |= DF_TEXTREL;
2973 local_got = elf_local_got_refcounts (ibfd);
2977 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
2978 locsymcount = symtab_hdr->sh_info;
2979 #ifdef INCLUDE_SHMEDIA
2980 /* Count datalabel local GOT. */
2983 end_local_got = local_got + locsymcount;
2984 local_tls_type = sh_elf_local_got_tls_type (ibfd);
2986 srel = htab->srelgot;
2987 for (; local_got < end_local_got; ++local_got)
2991 *local_got = s->size;
2993 if (*local_tls_type == GOT_TLS_GD)
2996 srel->size += sizeof (Elf32_External_Rela);
2999 *local_got = (bfd_vma) -1;
3004 if (htab->tls_ldm_got.refcount > 0)
3006 /* Allocate 2 got entries and 1 dynamic reloc for R_SH_TLS_LD_32
3008 htab->tls_ldm_got.offset = htab->sgot->size;
3009 htab->sgot->size += 8;
3010 htab->srelgot->size += sizeof (Elf32_External_Rela);
3013 htab->tls_ldm_got.offset = -1;
3015 /* Allocate global sym .plt and .got entries, and space for global
3016 sym dynamic relocs. */
3017 elf_link_hash_traverse (&htab->root, allocate_dynrelocs, info);
3019 /* We now have determined the sizes of the various dynamic sections.
3020 Allocate memory for them. */
3022 for (s = dynobj->sections; s != NULL; s = s->next)
3024 if ((s->flags & SEC_LINKER_CREATED) == 0)
3029 || s == htab->sgotplt
3030 || s == htab->sdynbss)
3032 /* Strip this section if we don't need it; see the
3035 else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
3037 if (s->size != 0 && s != htab->srelplt && s != htab->srelplt2)
3040 /* We use the reloc_count field as a counter if we need
3041 to copy relocs into the output file. */
3046 /* It's not one of our sections, so don't allocate space. */
3052 /* If we don't need this section, strip it from the
3053 output file. This is mostly to handle .rela.bss and
3054 .rela.plt. We must create both sections in
3055 create_dynamic_sections, because they must be created
3056 before the linker maps input sections to output
3057 sections. The linker does that before
3058 adjust_dynamic_symbol is called, and it is that
3059 function which decides whether anything needs to go
3060 into these sections. */
3062 s->flags |= SEC_EXCLUDE;
3066 if ((s->flags & SEC_HAS_CONTENTS) == 0)
3069 /* Allocate memory for the section contents. We use bfd_zalloc
3070 here in case unused entries are not reclaimed before the
3071 section's contents are written out. This should not happen,
3072 but this way if it does, we get a R_SH_NONE reloc instead
3074 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
3075 if (s->contents == NULL)
3079 if (htab->root.dynamic_sections_created)
3081 /* Add some entries to the .dynamic section. We fill in the
3082 values later, in sh_elf_finish_dynamic_sections, but we
3083 must add the entries now so that we get the correct size for
3084 the .dynamic section. The DT_DEBUG entry is filled in by the
3085 dynamic linker and used by the debugger. */
3086 #define add_dynamic_entry(TAG, VAL) \
3087 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3089 if (info->executable)
3091 if (! add_dynamic_entry (DT_DEBUG, 0))
3095 if (htab->splt->size != 0)
3097 if (! add_dynamic_entry (DT_PLTGOT, 0)
3098 || ! add_dynamic_entry (DT_PLTRELSZ, 0)
3099 || ! add_dynamic_entry (DT_PLTREL, DT_RELA)
3100 || ! add_dynamic_entry (DT_JMPREL, 0))
3106 if (! add_dynamic_entry (DT_RELA, 0)
3107 || ! add_dynamic_entry (DT_RELASZ, 0)
3108 || ! add_dynamic_entry (DT_RELAENT,
3109 sizeof (Elf32_External_Rela)))
3112 /* If any dynamic relocs apply to a read-only section,
3113 then we need a DT_TEXTREL entry. */
3114 if ((info->flags & DF_TEXTREL) == 0)
3115 elf_link_hash_traverse (&htab->root, readonly_dynrelocs, info);
3117 if ((info->flags & DF_TEXTREL) != 0)
3119 if (! add_dynamic_entry (DT_TEXTREL, 0))
3124 #undef add_dynamic_entry
3129 /* Relocate an SH ELF section. */
3132 sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
3133 bfd *input_bfd, asection *input_section,
3134 bfd_byte *contents, Elf_Internal_Rela *relocs,
3135 Elf_Internal_Sym *local_syms,
3136 asection **local_sections)
3138 struct elf_sh_link_hash_table *htab;
3139 Elf_Internal_Shdr *symtab_hdr;
3140 struct elf_link_hash_entry **sym_hashes;
3141 Elf_Internal_Rela *rel, *relend;
3143 bfd_vma *local_got_offsets;
3150 htab = sh_elf_hash_table (info);
3151 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3152 sym_hashes = elf_sym_hashes (input_bfd);
3153 dynobj = htab->root.dynobj;
3154 local_got_offsets = elf_local_got_offsets (input_bfd);
3157 sgotplt = htab->sgotplt;
3163 relend = relocs + input_section->reloc_count;
3164 for (; rel < relend; rel++)
3167 reloc_howto_type *howto;
3168 unsigned long r_symndx;
3169 Elf_Internal_Sym *sym;
3171 struct elf_link_hash_entry *h;
3173 bfd_vma addend = (bfd_vma) 0;
3174 bfd_reloc_status_type r;
3175 int seen_stt_datalabel = 0;
3179 r_symndx = ELF32_R_SYM (rel->r_info);
3181 r_type = ELF32_R_TYPE (rel->r_info);
3183 /* Many of the relocs are only used for relaxing, and are
3184 handled entirely by the relaxation code. */
3185 if (r_type >= (int) R_SH_GNU_VTINHERIT
3186 && r_type <= (int) R_SH_LABEL)
3188 if (r_type == (int) R_SH_NONE)
3192 || r_type >= R_SH_max
3193 || (r_type >= (int) R_SH_FIRST_INVALID_RELOC
3194 && r_type <= (int) R_SH_LAST_INVALID_RELOC)
3195 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_3
3196 && r_type <= (int) R_SH_LAST_INVALID_RELOC_3)
3197 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_4
3198 && r_type <= (int) R_SH_LAST_INVALID_RELOC_4)
3199 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_5
3200 && r_type <= (int) R_SH_LAST_INVALID_RELOC_5)
3201 || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_2
3202 && r_type <= (int) R_SH_LAST_INVALID_RELOC_2))
3204 bfd_set_error (bfd_error_bad_value);
3208 howto = get_howto_table (output_bfd) + r_type;
3210 /* For relocs that aren't partial_inplace, we get the addend from
3212 if (! howto->partial_inplace)
3213 addend = rel->r_addend;
3218 if (r_symndx < symtab_hdr->sh_info)
3220 sym = local_syms + r_symndx;
3221 sec = local_sections[r_symndx];
3222 relocation = (sec->output_section->vma
3223 + sec->output_offset
3225 /* A local symbol never has STO_SH5_ISA32, so we don't need
3226 datalabel processing here. Make sure this does not change
3228 if ((sym->st_other & STO_SH5_ISA32) != 0)
3229 ((*info->callbacks->reloc_dangerous)
3231 _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
3232 input_bfd, input_section, rel->r_offset));
3233 if (info->relocatable)
3235 /* This is a relocatable link. We don't have to change
3236 anything, unless the reloc is against a section symbol,
3237 in which case we have to adjust according to where the
3238 section symbol winds up in the output section. */
3239 sym = local_syms + r_symndx;
3240 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
3242 if (! howto->partial_inplace)
3244 /* For relocations with the addend in the
3245 relocation, we need just to update the addend.
3246 All real relocs are of type partial_inplace; this
3247 code is mostly for completeness. */
3248 rel->r_addend += sec->output_offset + sym->st_value;
3253 /* Relocs of type partial_inplace need to pick up the
3254 contents in the contents and add the offset resulting
3255 from the changed location of the section symbol.
3256 Using _bfd_final_link_relocate (e.g. goto
3257 final_link_relocate) here would be wrong, because
3258 relocations marked pc_relative would get the current
3259 location subtracted, and we must only do that at the
3261 r = _bfd_relocate_contents (howto, input_bfd,
3264 contents + rel->r_offset);
3265 goto relocation_done;
3270 else if (! howto->partial_inplace)
3272 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
3273 addend = rel->r_addend;
3275 else if ((sec->flags & SEC_MERGE)
3276 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
3280 if (howto->rightshift || howto->src_mask != 0xffffffff)
3282 (*_bfd_error_handler)
3283 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
3284 input_bfd, input_section,
3285 (long) rel->r_offset, howto->name);
3289 addend = bfd_get_32 (input_bfd, contents + rel->r_offset);
3292 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
3294 addend += msec->output_section->vma + msec->output_offset;
3295 bfd_put_32 (input_bfd, addend, contents + rel->r_offset);
3301 /* FIXME: Ought to make use of the RELOC_FOR_GLOBAL_SYMBOL macro. */
3303 /* Section symbol are never (?) placed in the hash table, so
3304 we can just ignore hash relocations when creating a
3305 relocatable object file. */
3306 if (info->relocatable)
3309 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3310 while (h->root.type == bfd_link_hash_indirect
3311 || h->root.type == bfd_link_hash_warning)
3313 #ifdef INCLUDE_SHMEDIA
3314 /* If the reference passes a symbol marked with
3315 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
3317 seen_stt_datalabel |= h->type == STT_DATALABEL;
3319 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3321 if (h->root.type == bfd_link_hash_defined
3322 || h->root.type == bfd_link_hash_defweak)
3326 dyn = htab->root.dynamic_sections_created;
3327 sec = h->root.u.def.section;
3328 /* In these cases, we don't need the relocation value.
3329 We check specially because in some obscure cases
3330 sec->output_section will be NULL. */
3331 if (r_type == R_SH_GOTPC
3332 || r_type == R_SH_GOTPC_LOW16
3333 || r_type == R_SH_GOTPC_MEDLOW16
3334 || r_type == R_SH_GOTPC_MEDHI16
3335 || r_type == R_SH_GOTPC_HI16
3336 || ((r_type == R_SH_PLT32
3337 || r_type == R_SH_PLT_LOW16
3338 || r_type == R_SH_PLT_MEDLOW16
3339 || r_type == R_SH_PLT_MEDHI16
3340 || r_type == R_SH_PLT_HI16)
3341 && h->plt.offset != (bfd_vma) -1)
3342 || ((r_type == R_SH_GOT32
3343 || r_type == R_SH_GOT_LOW16
3344 || r_type == R_SH_GOT_MEDLOW16
3345 || r_type == R_SH_GOT_MEDHI16
3346 || r_type == R_SH_GOT_HI16)
3347 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
3349 || (! info->symbolic && h->dynindx != -1)
3350 || !h->def_regular))
3351 /* The cases above are those in which relocation is
3352 overwritten in the switch block below. The cases
3353 below are those in which we must defer relocation
3354 to run-time, because we can't resolve absolute
3355 addresses when creating a shared library. */
3357 && ((! info->symbolic && h->dynindx != -1)
3359 && ((r_type == R_SH_DIR32
3360 && !h->forced_local)
3361 || (r_type == R_SH_REL32
3362 && !SYMBOL_CALLS_LOCAL (info, h)))
3363 && ((input_section->flags & SEC_ALLOC) != 0
3364 /* DWARF will emit R_SH_DIR32 relocations in its
3365 sections against symbols defined externally
3366 in shared libraries. We can't do anything
3368 || ((input_section->flags & SEC_DEBUGGING) != 0
3369 && h->def_dynamic)))
3370 /* Dynamic relocs are not propagated for SEC_DEBUGGING
3371 sections because such sections are not SEC_ALLOC and
3372 thus ld.so will not process them. */
3373 || (sec->output_section == NULL
3374 && ((input_section->flags & SEC_DEBUGGING) != 0
3376 || (sec->output_section == NULL
3377 && (sh_elf_hash_entry (h)->tls_type == GOT_TLS_IE
3378 || sh_elf_hash_entry (h)->tls_type == GOT_TLS_GD)))
3380 else if (sec->output_section == NULL)
3382 (*_bfd_error_handler)
3383 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
3386 (long) rel->r_offset,
3388 h->root.root.string);
3392 relocation = ((h->root.u.def.value
3393 + sec->output_section->vma
3394 + sec->output_offset)
3395 /* A STO_SH5_ISA32 causes a "bitor 1" to the
3396 symbol value, unless we've seen
3397 STT_DATALABEL on the way to it. */
3398 | ((h->other & STO_SH5_ISA32) != 0
3399 && ! seen_stt_datalabel));
3401 else if (h->root.type == bfd_link_hash_undefweak)
3403 else if (info->unresolved_syms_in_objects == RM_IGNORE
3404 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
3408 if (! info->callbacks->undefined_symbol
3409 (info, h->root.root.string, input_bfd,
3410 input_section, rel->r_offset,
3411 (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
3412 || ELF_ST_VISIBILITY (h->other))))
3418 switch ((int) r_type)
3420 final_link_relocate:
3421 /* COFF relocs don't use the addend. The addend is used for
3422 R_SH_DIR32 to be compatible with other compilers. */
3423 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
3424 contents, rel->r_offset,
3425 relocation, addend);
3429 goto final_link_relocate;
3434 /* If the reloc is against the start of this section, then
3435 the assembler has already taken care of it and the reloc
3436 is here only to assist in relaxing. If the reloc is not
3437 against the start of this section, then it's against an
3438 external symbol and we must deal with it ourselves. */
3439 if (input_section->output_section->vma + input_section->output_offset
3442 int disp = (relocation
3443 - input_section->output_section->vma
3444 - input_section->output_offset
3450 case R_SH_DIR8WPZ: mask = 1; break;
3451 case R_SH_DIR8WPL: mask = 3; break;
3452 default: mask = 0; break;
3456 ((*_bfd_error_handler)
3457 (_("%B: 0x%lx: fatal: unaligned branch target for relax-support relocation"),
3458 input_section->owner,
3459 (unsigned long) rel->r_offset));
3460 bfd_set_error (bfd_error_bad_value);
3464 goto final_link_relocate;
3470 #ifdef INCLUDE_SHMEDIA
3471 if (shmedia_prepare_reloc (info, input_bfd, input_section,
3472 contents, rel, &relocation))
3473 goto final_link_relocate;
3475 bfd_set_error (bfd_error_bad_value);
3483 goto final_link_relocate;
3489 ((*_bfd_error_handler)
3490 (_("%B: 0x%lx: fatal: unaligned %s relocation 0x%lx"),
3491 input_section->owner,
3492 (unsigned long) rel->r_offset, howto->name,
3493 (unsigned long) relocation));
3494 bfd_set_error (bfd_error_bad_value);
3497 goto final_link_relocate;
3504 ((*_bfd_error_handler)
3505 (_("%B: 0x%lx: fatal: unaligned %s relocation 0x%lx"),
3506 input_section->owner,
3507 (unsigned long) rel->r_offset, howto->name,
3508 (unsigned long) relocation));
3509 bfd_set_error (bfd_error_bad_value);
3512 goto final_link_relocate;
3515 if ((signed int)relocation < -32
3516 || (signed int)relocation > 32)
3518 ((*_bfd_error_handler)
3519 (_("%B: 0x%lx: fatal: R_SH_PSHA relocation %d not in range -32..32"),
3520 input_section->owner,
3521 (unsigned long) rel->r_offset,
3522 (unsigned long) relocation));
3523 bfd_set_error (bfd_error_bad_value);
3526 goto final_link_relocate;
3529 if ((signed int)relocation < -16
3530 || (signed int)relocation > 16)
3532 ((*_bfd_error_handler)
3533 (_("%B: 0x%lx: fatal: R_SH_PSHL relocation %d not in range -32..32"),
3534 input_section->owner,
3535 (unsigned long) rel->r_offset,
3536 (unsigned long) relocation));
3537 bfd_set_error (bfd_error_bad_value);
3540 goto final_link_relocate;
3544 #ifdef INCLUDE_SHMEDIA
3545 case R_SH_IMM_LOW16_PCREL:
3546 case R_SH_IMM_MEDLOW16_PCREL:
3547 case R_SH_IMM_MEDHI16_PCREL:
3548 case R_SH_IMM_HI16_PCREL:
3552 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3553 || h->root.type != bfd_link_hash_undefweak)
3555 && (input_section->flags & SEC_ALLOC) != 0
3556 && (r_type == R_SH_DIR32
3557 || !SYMBOL_CALLS_LOCAL (info, h)))
3559 Elf_Internal_Rela outrel;
3561 bfd_boolean skip, relocate;
3563 /* When generating a shared object, these relocations
3564 are copied into the output file to be resolved at run
3571 name = (bfd_elf_string_from_elf_section
3573 elf_elfheader (input_bfd)->e_shstrndx,
3574 elf_section_data (input_section)->rel_hdr.sh_name));
3578 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
3579 && strcmp (bfd_get_section_name (input_bfd,
3583 sreloc = bfd_get_section_by_name (dynobj, name);
3584 BFD_ASSERT (sreloc != NULL);
3591 _bfd_elf_section_offset (output_bfd, info, input_section,
3593 if (outrel.r_offset == (bfd_vma) -1)
3595 else if (outrel.r_offset == (bfd_vma) -2)
3596 skip = TRUE, relocate = TRUE;
3597 outrel.r_offset += (input_section->output_section->vma
3598 + input_section->output_offset);
3601 memset (&outrel, 0, sizeof outrel);
3602 else if (r_type == R_SH_REL32)
3604 BFD_ASSERT (h != NULL && h->dynindx != -1);
3605 outrel.r_info = ELF32_R_INFO (h->dynindx, R_SH_REL32);
3607 = (howto->partial_inplace
3608 ? bfd_get_32 (input_bfd, contents + rel->r_offset)
3611 #ifdef INCLUDE_SHMEDIA
3612 else if (r_type == R_SH_IMM_LOW16_PCREL
3613 || r_type == R_SH_IMM_MEDLOW16_PCREL
3614 || r_type == R_SH_IMM_MEDHI16_PCREL
3615 || r_type == R_SH_IMM_HI16_PCREL)
3617 BFD_ASSERT (h != NULL && h->dynindx != -1);
3618 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
3619 outrel.r_addend = addend;
3624 /* h->dynindx may be -1 if this symbol was marked to
3627 || ((info->symbolic || h->dynindx == -1)
3630 relocate = howto->partial_inplace;
3631 outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
3635 BFD_ASSERT (h->dynindx != -1);
3636 outrel.r_info = ELF32_R_INFO (h->dynindx, R_SH_DIR32);
3638 outrel.r_addend = relocation;
3640 += (howto->partial_inplace
3641 ? bfd_get_32 (input_bfd, contents + rel->r_offset)
3645 loc = sreloc->contents;
3646 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
3647 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
3649 /* If this reloc is against an external symbol, we do
3650 not want to fiddle with the addend. Otherwise, we
3651 need to include the symbol value so that it becomes
3652 an addend for the dynamic reloc. */
3656 goto final_link_relocate;
3659 #ifdef INCLUDE_SHMEDIA
3660 case R_SH_GOTPLT_LOW16:
3661 case R_SH_GOTPLT_MEDLOW16:
3662 case R_SH_GOTPLT_MEDHI16:
3663 case R_SH_GOTPLT_HI16:
3664 case R_SH_GOTPLT10BY4:
3665 case R_SH_GOTPLT10BY8:
3667 /* Relocation is to the entry for this symbol in the
3668 procedure linkage table. */
3675 || h->plt.offset == (bfd_vma) -1
3676 || h->got.offset != (bfd_vma) -1)
3679 /* Relocation is to the entry for this symbol in the global
3680 offset table extension for the procedure linkage table. */
3682 BFD_ASSERT (sgotplt != NULL);
3683 relocation = (sgotplt->output_offset
3684 + (get_plt_index (htab->plt_info, h->plt.offset)
3688 relocation -= GOT_BIAS;
3691 goto final_link_relocate;
3695 #ifdef INCLUDE_SHMEDIA
3696 case R_SH_GOT_LOW16:
3697 case R_SH_GOT_MEDLOW16:
3698 case R_SH_GOT_MEDHI16:
3703 /* Relocation is to the entry for this symbol in the global
3706 BFD_ASSERT (sgot != NULL);
3712 off = h->got.offset;
3713 #ifdef INCLUDE_SHMEDIA
3714 if (seen_stt_datalabel)
3716 struct elf_sh_link_hash_entry *hsh;
3718 hsh = (struct elf_sh_link_hash_entry *)h;
3719 off = hsh->datalabel_got.offset;
3722 BFD_ASSERT (off != (bfd_vma) -1);
3724 dyn = htab->root.dynamic_sections_created;
3725 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
3727 && SYMBOL_REFERENCES_LOCAL (info, h))
3728 || (ELF_ST_VISIBILITY (h->other)
3729 && h->root.type == bfd_link_hash_undefweak))
3731 /* This is actually a static link, or it is a
3732 -Bsymbolic link and the symbol is defined
3733 locally, or the symbol was forced to be local
3734 because of a version file. We must initialize
3735 this entry in the global offset table. Since the
3736 offset must always be a multiple of 4, we use the
3737 least significant bit to record whether we have
3738 initialized it already.
3740 When doing a dynamic link, we create a .rela.got
3741 relocation entry to initialize the value. This
3742 is done in the finish_dynamic_symbol routine. */
3747 bfd_put_32 (output_bfd, relocation,
3748 sgot->contents + off);
3749 #ifdef INCLUDE_SHMEDIA
3750 if (seen_stt_datalabel)
3752 struct elf_sh_link_hash_entry *hsh;
3754 hsh = (struct elf_sh_link_hash_entry *)h;
3755 hsh->datalabel_got.offset |= 1;
3763 relocation = sgot->output_offset + off;
3767 #ifdef INCLUDE_SHMEDIA
3770 BFD_ASSERT (local_got_offsets != NULL
3771 && (local_got_offsets[symtab_hdr->sh_info
3775 off = local_got_offsets[symtab_hdr->sh_info
3781 BFD_ASSERT (local_got_offsets != NULL
3782 && local_got_offsets[r_symndx] != (bfd_vma) -1);
3784 off = local_got_offsets[r_symndx];
3785 #ifdef INCLUDE_SHMEDIA
3789 /* The offset must always be a multiple of 4. We use
3790 the least significant bit to record whether we have
3791 already generated the necessary reloc. */
3796 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
3800 Elf_Internal_Rela outrel;
3803 if (srelgot == NULL)
3805 srelgot = bfd_get_section_by_name (dynobj,
3807 BFD_ASSERT (srelgot != NULL);
3810 outrel.r_offset = (sgot->output_section->vma
3811 + sgot->output_offset
3813 outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
3814 outrel.r_addend = relocation;
3815 loc = srelgot->contents;
3816 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
3817 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
3820 #ifdef INCLUDE_SHMEDIA
3822 local_got_offsets[symtab_hdr->sh_info + r_symndx] |= 1;
3825 local_got_offsets[r_symndx] |= 1;
3828 relocation = sgot->output_offset + off;
3832 relocation -= GOT_BIAS;
3835 goto final_link_relocate;
3838 #ifdef INCLUDE_SHMEDIA
3839 case R_SH_GOTOFF_LOW16:
3840 case R_SH_GOTOFF_MEDLOW16:
3841 case R_SH_GOTOFF_MEDHI16:
3842 case R_SH_GOTOFF_HI16:
3844 /* Relocation is relative to the start of the global offset
3847 BFD_ASSERT (sgot != NULL);
3849 /* Note that sgot->output_offset is not involved in this
3850 calculation. We always want the start of .got. If we
3851 defined _GLOBAL_OFFSET_TABLE in a different way, as is
3852 permitted by the ABI, we might have to change this
3854 relocation -= sgot->output_section->vma;
3857 relocation -= GOT_BIAS;
3860 addend = rel->r_addend;
3862 goto final_link_relocate;
3865 #ifdef INCLUDE_SHMEDIA
3866 case R_SH_GOTPC_LOW16:
3867 case R_SH_GOTPC_MEDLOW16:
3868 case R_SH_GOTPC_MEDHI16:
3869 case R_SH_GOTPC_HI16:
3871 /* Use global offset table as symbol value. */
3873 BFD_ASSERT (sgot != NULL);
3874 relocation = sgot->output_section->vma;
3877 relocation += GOT_BIAS;
3880 addend = rel->r_addend;
3882 goto final_link_relocate;
3885 #ifdef INCLUDE_SHMEDIA
3886 case R_SH_PLT_LOW16:
3887 case R_SH_PLT_MEDLOW16:
3888 case R_SH_PLT_MEDHI16:
3891 /* Relocation is to the entry for this symbol in the
3892 procedure linkage table. */
3894 /* Resolve a PLT reloc against a local symbol directly,
3895 without using the procedure linkage table. */
3897 goto final_link_relocate;
3899 if (h->forced_local)
3900 goto final_link_relocate;
3902 if (h->plt.offset == (bfd_vma) -1)
3904 /* We didn't make a PLT entry for this symbol. This
3905 happens when statically linking PIC code, or when
3906 using -Bsymbolic. */
3907 goto final_link_relocate;
3910 BFD_ASSERT (splt != NULL);
3911 relocation = (splt->output_section->vma
3912 + splt->output_offset
3915 #ifdef INCLUDE_SHMEDIA
3919 addend = rel->r_addend;
3921 goto final_link_relocate;
3923 case R_SH_LOOP_START:
3925 static bfd_vma start, end;
3927 start = (relocation + rel->r_addend
3928 - (sec->output_section->vma + sec->output_offset));
3929 r = sh_elf_reloc_loop (r_type, input_bfd, input_section, contents,
3930 rel->r_offset, sec, start, end);
3934 end = (relocation + rel->r_addend
3935 - (sec->output_section->vma + sec->output_offset));
3936 r = sh_elf_reloc_loop (r_type, input_bfd, input_section, contents,
3937 rel->r_offset, sec, start, end);
3941 case R_SH_TLS_GD_32:
3942 case R_SH_TLS_IE_32:
3943 r_type = sh_elf_optimized_tls_reloc (info, r_type, h == NULL);
3944 tls_type = GOT_UNKNOWN;
3945 if (h == NULL && local_got_offsets)
3946 tls_type = sh_elf_local_got_tls_type (input_bfd) [r_symndx];
3949 tls_type = sh_elf_hash_entry (h)->tls_type;
3951 && (h->dynindx == -1
3953 r_type = R_SH_TLS_LE_32;
3956 if (r_type == R_SH_TLS_GD_32 && tls_type == GOT_TLS_IE)
3957 r_type = R_SH_TLS_IE_32;
3959 if (r_type == R_SH_TLS_LE_32)
3962 unsigned short insn;
3964 if (ELF32_R_TYPE (rel->r_info) == R_SH_TLS_GD_32)
3966 /* GD->LE transition:
3967 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
3968 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
3969 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
3971 mov.l 1f,r4; stc gbr,r0; add r4,r0; nop;
3973 1: .long x@TPOFF; 2: .long __tls_get_addr@PLT; 3:. */
3975 offset = rel->r_offset;
3976 BFD_ASSERT (offset >= 16);
3977 /* Size of GD instructions is 16 or 18. */
3979 insn = bfd_get_16 (input_bfd, contents + offset + 0);
3980 if ((insn & 0xff00) == 0xc700)
3982 BFD_ASSERT (offset >= 2);
3984 insn = bfd_get_16 (input_bfd, contents + offset + 0);
3987 BFD_ASSERT ((insn & 0xff00) == 0xd400);
3988 insn = bfd_get_16 (input_bfd, contents + offset + 2);
3989 BFD_ASSERT ((insn & 0xff00) == 0xc700);
3990 insn = bfd_get_16 (input_bfd, contents + offset + 4);
3991 BFD_ASSERT ((insn & 0xff00) == 0xd100);
3992 insn = bfd_get_16 (input_bfd, contents + offset + 6);
3993 BFD_ASSERT (insn == 0x310c);
3994 insn = bfd_get_16 (input_bfd, contents + offset + 8);
3995 BFD_ASSERT (insn == 0x410b);
3996 insn = bfd_get_16 (input_bfd, contents + offset + 10);
3997 BFD_ASSERT (insn == 0x34cc);
3999 bfd_put_16 (output_bfd, 0x0012, contents + offset + 2);
4000 bfd_put_16 (output_bfd, 0x304c, contents + offset + 4);
4001 bfd_put_16 (output_bfd, 0x0009, contents + offset + 6);
4002 bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
4003 bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
4009 /* IE->LE transition:
4010 mov.l 1f,r0; stc gbr,rN; mov.l @(r0,r12),rM;
4011 bra 2f; add ...; .align 2; 1: x@GOTTPOFF; 2:
4013 mov.l .Ln,rM; stc gbr,rN; nop; ...;
4016 offset = rel->r_offset;
4017 BFD_ASSERT (offset >= 16);
4018 /* Size of IE instructions is 10 or 12. */
4020 insn = bfd_get_16 (input_bfd, contents + offset + 0);
4021 if ((insn & 0xf0ff) == 0x0012)
4023 BFD_ASSERT (offset >= 2);
4025 insn = bfd_get_16 (input_bfd, contents + offset + 0);
4028 BFD_ASSERT ((insn & 0xff00) == 0xd000);
4029 index = insn & 0x00ff;
4030 insn = bfd_get_16 (input_bfd, contents + offset + 2);
4031 BFD_ASSERT ((insn & 0xf0ff) == 0x0012);
4032 insn = bfd_get_16 (input_bfd, contents + offset + 4);
4033 BFD_ASSERT ((insn & 0xf0ff) == 0x00ce);
4034 insn = 0xd000 | (insn & 0x0f00) | index;
4035 bfd_put_16 (output_bfd, insn, contents + offset + 0);
4036 bfd_put_16 (output_bfd, 0x0009, contents + offset + 4);
4039 bfd_put_32 (output_bfd, tpoff (info, relocation),
4040 contents + rel->r_offset);
4049 off = h->got.offset;
4052 if (local_got_offsets == NULL)
4055 off = local_got_offsets[r_symndx];
4058 /* Relocate R_SH_TLS_IE_32 directly when statically linking. */
4059 if (r_type == R_SH_TLS_IE_32
4060 && ! htab->root.dynamic_sections_created)
4063 bfd_put_32 (output_bfd, tpoff (info, relocation),
4064 sgot->contents + off);
4065 bfd_put_32 (output_bfd, sgot->output_offset + off,
4066 contents + rel->r_offset);
4074 Elf_Internal_Rela outrel;
4078 if (srelgot == NULL)
4080 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
4081 BFD_ASSERT (srelgot != NULL);
4084 outrel.r_offset = (sgot->output_section->vma
4085 + sgot->output_offset + off);
4087 if (h == NULL || h->dynindx == -1)
4092 dr_type = (r_type == R_SH_TLS_GD_32 ? R_SH_TLS_DTPMOD32 :
4094 if (dr_type == R_SH_TLS_TPOFF32 && indx == 0)
4095 outrel.r_addend = relocation - dtpoff_base (info);
4097 outrel.r_addend = 0;
4098 outrel.r_info = ELF32_R_INFO (indx, dr_type);
4099 loc = srelgot->contents;
4100 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
4101 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
4103 if (r_type == R_SH_TLS_GD_32)
4107 bfd_put_32 (output_bfd,
4108 relocation - dtpoff_base (info),
4109 sgot->contents + off + 4);
4113 outrel.r_info = ELF32_R_INFO (indx,
4115 outrel.r_offset += 4;
4116 outrel.r_addend = 0;
4117 srelgot->reloc_count++;
4118 loc += sizeof (Elf32_External_Rela);
4119 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
4126 local_got_offsets[r_symndx] |= 1;
4129 if (off >= (bfd_vma) -2)
4132 if (r_type == (int) ELF32_R_TYPE (rel->r_info))
4133 relocation = sgot->output_offset + off;
4137 unsigned short insn;
4139 /* GD->IE transition:
4140 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
4141 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
4142 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
4144 mov.l 1f,r0; stc gbr,r4; mov.l @(r0,r12),r0; add r4,r0;
4145 nop; nop; bra 3f; nop; .align 2;
4146 1: .long x@TPOFF; 2:...; 3:. */
4148 offset = rel->r_offset;
4149 BFD_ASSERT (offset >= 16);
4150 /* Size of GD instructions is 16 or 18. */
4152 insn = bfd_get_16 (input_bfd, contents + offset + 0);
4153 if ((insn & 0xff00) == 0xc700)
4155 BFD_ASSERT (offset >= 2);
4157 insn = bfd_get_16 (input_bfd, contents + offset + 0);
4160 BFD_ASSERT ((insn & 0xff00) == 0xd400);
4162 /* Replace mov.l 1f,R4 with mov.l 1f,r0. */
4163 bfd_put_16 (output_bfd, insn & 0xf0ff, contents + offset);
4165 insn = bfd_get_16 (input_bfd, contents + offset + 2);
4166 BFD_ASSERT ((insn & 0xff00) == 0xc700);
4167 insn = bfd_get_16 (input_bfd, contents + offset + 4);
4168 BFD_ASSERT ((insn & 0xff00) == 0xd100);
4169 insn = bfd_get_16 (input_bfd, contents + offset + 6);
4170 BFD_ASSERT (insn == 0x310c);
4171 insn = bfd_get_16 (input_bfd, contents + offset + 8);
4172 BFD_ASSERT (insn == 0x410b);
4173 insn = bfd_get_16 (input_bfd, contents + offset + 10);
4174 BFD_ASSERT (insn == 0x34cc);
4176 bfd_put_16 (output_bfd, 0x0412, contents + offset + 2);
4177 bfd_put_16 (output_bfd, 0x00ce, contents + offset + 4);
4178 bfd_put_16 (output_bfd, 0x304c, contents + offset + 6);
4179 bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
4180 bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
4182 bfd_put_32 (output_bfd, sgot->output_offset + off,
4183 contents + rel->r_offset);
4188 addend = rel->r_addend;
4190 goto final_link_relocate;
4192 case R_SH_TLS_LD_32:
4196 unsigned short insn;
4198 /* LD->LE transition:
4199 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
4200 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
4201 1: .long x$TLSLD; 2: .long __tls_get_addr@PLT; 3:
4203 stc gbr,r0; nop; nop; nop;
4204 nop; nop; bra 3f; ...; 3:. */
4206 offset = rel->r_offset;
4207 BFD_ASSERT (offset >= 16);
4208 /* Size of LD instructions is 16 or 18. */
4210 insn = bfd_get_16 (input_bfd, contents + offset + 0);
4211 if ((insn & 0xff00) == 0xc700)
4213 BFD_ASSERT (offset >= 2);
4215 insn = bfd_get_16 (input_bfd, contents + offset + 0);
4218 BFD_ASSERT ((insn & 0xff00) == 0xd400);
4219 insn = bfd_get_16 (input_bfd, contents + offset + 2);
4220 BFD_ASSERT ((insn & 0xff00) == 0xc700);
4221 insn = bfd_get_16 (input_bfd, contents + offset + 4);
4222 BFD_ASSERT ((insn & 0xff00) == 0xd100);
4223 insn = bfd_get_16 (input_bfd, contents + offset + 6);
4224 BFD_ASSERT (insn == 0x310c);
4225 insn = bfd_get_16 (input_bfd, contents + offset + 8);
4226 BFD_ASSERT (insn == 0x410b);
4227 insn = bfd_get_16 (input_bfd, contents + offset + 10);
4228 BFD_ASSERT (insn == 0x34cc);
4230 bfd_put_16 (output_bfd, 0x0012, contents + offset + 0);
4231 bfd_put_16 (output_bfd, 0x0009, contents + offset + 2);
4232 bfd_put_16 (output_bfd, 0x0009, contents + offset + 4);
4233 bfd_put_16 (output_bfd, 0x0009, contents + offset + 6);
4234 bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
4235 bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
4244 off = htab->tls_ldm_got.offset;
4249 Elf_Internal_Rela outrel;
4252 srelgot = htab->srelgot;
4253 if (srelgot == NULL)
4256 outrel.r_offset = (sgot->output_section->vma
4257 + sgot->output_offset + off);
4258 outrel.r_addend = 0;
4259 outrel.r_info = ELF32_R_INFO (0, R_SH_TLS_DTPMOD32);
4260 loc = srelgot->contents;
4261 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
4262 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
4263 htab->tls_ldm_got.offset |= 1;
4266 relocation = sgot->output_offset + off;
4267 addend = rel->r_addend;
4269 goto final_link_relocate;
4271 case R_SH_TLS_LDO_32:
4273 relocation = tpoff (info, relocation);
4275 relocation -= dtpoff_base (info);
4277 addend = rel->r_addend;
4278 goto final_link_relocate;
4280 case R_SH_TLS_LE_32:
4283 Elf_Internal_Rela outrel;
4288 relocation = tpoff (info, relocation);
4289 addend = rel->r_addend;
4290 goto final_link_relocate;
4297 name = (bfd_elf_string_from_elf_section
4299 elf_elfheader (input_bfd)->e_shstrndx,
4300 elf_section_data (input_section)->rel_hdr.sh_name));
4304 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
4305 && strcmp (bfd_get_section_name (input_bfd,
4309 sreloc = bfd_get_section_by_name (dynobj, name);
4310 BFD_ASSERT (sreloc != NULL);
4313 if (h == NULL || h->dynindx == -1)
4318 outrel.r_offset = (input_section->output_section->vma
4319 + input_section->output_offset
4321 outrel.r_info = ELF32_R_INFO (indx, R_SH_TLS_TPOFF32);
4323 outrel.r_addend = relocation - dtpoff_base (info);
4325 outrel.r_addend = 0;
4327 loc = sreloc->contents;
4328 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
4329 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
4335 if (r != bfd_reloc_ok)
4340 case bfd_reloc_outofrange:
4342 case bfd_reloc_overflow:
4350 name = (bfd_elf_string_from_elf_section
4351 (input_bfd, symtab_hdr->sh_link, sym->st_name));
4355 name = bfd_section_name (input_bfd, sec);
4357 if (! ((*info->callbacks->reloc_overflow)
4358 (info, (h ? &h->root : NULL), name, howto->name,
4359 (bfd_vma) 0, input_bfd, input_section,
4371 /* This is a version of bfd_generic_get_relocated_section_contents
4372 which uses sh_elf_relocate_section. */
4375 sh_elf_get_relocated_section_contents (bfd *output_bfd,
4376 struct bfd_link_info *link_info,
4377 struct bfd_link_order *link_order,
4379 bfd_boolean relocatable,
4382 Elf_Internal_Shdr *symtab_hdr;
4383 asection *input_section = link_order->u.indirect.section;
4384 bfd *input_bfd = input_section->owner;
4385 asection **sections = NULL;
4386 Elf_Internal_Rela *internal_relocs = NULL;
4387 Elf_Internal_Sym *isymbuf = NULL;
4389 /* We only need to handle the case of relaxing, or of having a
4390 particular set of section contents, specially. */
4392 || elf_section_data (input_section)->this_hdr.contents == NULL)
4393 return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
4398 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4400 memcpy (data, elf_section_data (input_section)->this_hdr.contents,
4401 (size_t) input_section->size);
4403 if ((input_section->flags & SEC_RELOC) != 0
4404 && input_section->reloc_count > 0)
4407 Elf_Internal_Sym *isym, *isymend;
4410 internal_relocs = (_bfd_elf_link_read_relocs
4411 (input_bfd, input_section, NULL,
4412 (Elf_Internal_Rela *) NULL, FALSE));
4413 if (internal_relocs == NULL)
4416 if (symtab_hdr->sh_info != 0)
4418 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
4419 if (isymbuf == NULL)
4420 isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
4421 symtab_hdr->sh_info, 0,
4423 if (isymbuf == NULL)
4427 amt = symtab_hdr->sh_info;
4428 amt *= sizeof (asection *);
4429 sections = (asection **) bfd_malloc (amt);
4430 if (sections == NULL && amt != 0)
4433 isymend = isymbuf + symtab_hdr->sh_info;
4434 for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp)
4438 if (isym->st_shndx == SHN_UNDEF)
4439 isec = bfd_und_section_ptr;
4440 else if (isym->st_shndx == SHN_ABS)
4441 isec = bfd_abs_section_ptr;
4442 else if (isym->st_shndx == SHN_COMMON)
4443 isec = bfd_com_section_ptr;
4445 isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
4450 if (! sh_elf_relocate_section (output_bfd, link_info, input_bfd,
4451 input_section, data, internal_relocs,
4455 if (sections != NULL)
4458 && symtab_hdr->contents != (unsigned char *) isymbuf)
4460 if (elf_section_data (input_section)->relocs != internal_relocs)
4461 free (internal_relocs);
4467 if (sections != NULL)
4470 && symtab_hdr->contents != (unsigned char *) isymbuf)
4472 if (internal_relocs != NULL
4473 && elf_section_data (input_section)->relocs != internal_relocs)
4474 free (internal_relocs);
4478 /* Return the base VMA address which should be subtracted from real addresses
4479 when resolving @dtpoff relocation.
4480 This is PT_TLS segment p_vaddr. */
4483 dtpoff_base (struct bfd_link_info *info)
4485 /* If tls_sec is NULL, we should have signalled an error already. */
4486 if (elf_hash_table (info)->tls_sec == NULL)
4488 return elf_hash_table (info)->tls_sec->vma;
4491 /* Return the relocation value for R_SH_TLS_TPOFF32.. */
4494 tpoff (struct bfd_link_info *info, bfd_vma address)
4496 /* If tls_sec is NULL, we should have signalled an error already. */
4497 if (elf_hash_table (info)->tls_sec == NULL)
4499 /* SH TLS ABI is variant I and static TLS block start just after tcbhead
4500 structure which has 2 pointer fields. */
4501 return (address - elf_hash_table (info)->tls_sec->vma
4502 + align_power ((bfd_vma) 8,
4503 elf_hash_table (info)->tls_sec->alignment_power));
4507 sh_elf_gc_mark_hook (asection *sec,
4508 struct bfd_link_info *info ATTRIBUTE_UNUSED,
4509 Elf_Internal_Rela *rel, struct elf_link_hash_entry *h,
4510 Elf_Internal_Sym *sym)
4514 switch (ELF32_R_TYPE (rel->r_info))
4516 case R_SH_GNU_VTINHERIT:
4517 case R_SH_GNU_VTENTRY:
4521 #ifdef INCLUDE_SHMEDIA
4522 while (h->root.type == bfd_link_hash_indirect
4523 && h->root.u.i.link)
4524 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4526 switch (h->root.type)
4528 case bfd_link_hash_defined:
4529 case bfd_link_hash_defweak:
4530 return h->root.u.def.section;
4532 case bfd_link_hash_common:
4533 return h->root.u.c.p->section;
4541 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
4546 /* Update the got entry reference counts for the section being removed. */
4549 sh_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
4550 asection *sec, const Elf_Internal_Rela *relocs)
4552 Elf_Internal_Shdr *symtab_hdr;
4553 struct elf_link_hash_entry **sym_hashes;
4554 bfd_signed_vma *local_got_refcounts;
4555 const Elf_Internal_Rela *rel, *relend;
4557 elf_section_data (sec)->local_dynrel = NULL;
4559 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
4560 sym_hashes = elf_sym_hashes (abfd);
4561 local_got_refcounts = elf_local_got_refcounts (abfd);
4563 relend = relocs + sec->reloc_count;
4564 for (rel = relocs; rel < relend; rel++)
4566 unsigned long r_symndx;
4567 unsigned int r_type;
4568 struct elf_link_hash_entry *h = NULL;
4569 #ifdef INCLUDE_SHMEDIA
4570 int seen_stt_datalabel = 0;
4573 r_symndx = ELF32_R_SYM (rel->r_info);
4574 if (r_symndx >= symtab_hdr->sh_info)
4576 struct elf_sh_link_hash_entry *eh;
4577 struct elf_sh_dyn_relocs **pp;
4578 struct elf_sh_dyn_relocs *p;
4580 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4581 while (h->root.type == bfd_link_hash_indirect
4582 || h->root.type == bfd_link_hash_warning)
4584 #ifdef INCLUDE_SHMEDIA
4585 seen_stt_datalabel |= h->type == STT_DATALABEL;
4587 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4589 eh = (struct elf_sh_link_hash_entry *) h;
4590 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
4593 /* Everything must go for SEC. */
4599 r_type = ELF32_R_TYPE (rel->r_info);
4600 switch (sh_elf_optimized_tls_reloc (info, r_type, h != NULL))
4602 case R_SH_TLS_LD_32:
4603 if (sh_elf_hash_table (info)->tls_ldm_got.refcount > 0)
4604 sh_elf_hash_table (info)->tls_ldm_got.refcount -= 1;
4610 #ifdef INCLUDE_SHMEDIA
4611 case R_SH_GOT_LOW16:
4612 case R_SH_GOT_MEDLOW16:
4613 case R_SH_GOT_MEDHI16:
4617 case R_SH_GOTOFF_LOW16:
4618 case R_SH_GOTOFF_MEDLOW16:
4619 case R_SH_GOTOFF_MEDHI16:
4620 case R_SH_GOTOFF_HI16:
4621 case R_SH_GOTPC_LOW16:
4622 case R_SH_GOTPC_MEDLOW16:
4623 case R_SH_GOTPC_MEDHI16:
4624 case R_SH_GOTPC_HI16:
4626 case R_SH_TLS_GD_32:
4627 case R_SH_TLS_IE_32:
4630 #ifdef INCLUDE_SHMEDIA
4631 if (seen_stt_datalabel)
4633 struct elf_sh_link_hash_entry *eh;
4634 eh = (struct elf_sh_link_hash_entry *) h;
4635 if (eh->datalabel_got.refcount > 0)
4636 eh->datalabel_got.refcount -= 1;
4640 if (h->got.refcount > 0)
4641 h->got.refcount -= 1;
4643 else if (local_got_refcounts != NULL)
4645 #ifdef INCLUDE_SHMEDIA
4646 if (rel->r_addend & 1)
4648 if (local_got_refcounts[symtab_hdr->sh_info + r_symndx] > 0)
4649 local_got_refcounts[symtab_hdr->sh_info + r_symndx] -= 1;
4653 if (local_got_refcounts[r_symndx] > 0)
4654 local_got_refcounts[r_symndx] -= 1;
4665 #ifdef INCLUDE_SHMEDIA
4666 case R_SH_PLT_LOW16:
4667 case R_SH_PLT_MEDLOW16:
4668 case R_SH_PLT_MEDHI16:
4673 if (h->plt.refcount > 0)
4674 h->plt.refcount -= 1;
4679 #ifdef INCLUDE_SHMEDIA
4680 case R_SH_GOTPLT_LOW16:
4681 case R_SH_GOTPLT_MEDLOW16:
4682 case R_SH_GOTPLT_MEDHI16:
4683 case R_SH_GOTPLT_HI16:
4684 case R_SH_GOTPLT10BY4:
4685 case R_SH_GOTPLT10BY8:
4689 struct elf_sh_link_hash_entry *eh;
4690 eh = (struct elf_sh_link_hash_entry *) h;
4691 if (eh->gotplt_refcount > 0)
4693 eh->gotplt_refcount -= 1;
4694 if (h->plt.refcount > 0)
4695 h->plt.refcount -= 1;
4697 #ifdef INCLUDE_SHMEDIA
4698 else if (seen_stt_datalabel)
4700 if (eh->datalabel_got.refcount > 0)
4701 eh->datalabel_got.refcount -= 1;
4704 else if (h->got.refcount > 0)
4705 h->got.refcount -= 1;
4707 else if (local_got_refcounts != NULL)
4709 #ifdef INCLUDE_SHMEDIA
4710 if (rel->r_addend & 1)
4712 if (local_got_refcounts[symtab_hdr->sh_info + r_symndx] > 0)
4713 local_got_refcounts[symtab_hdr->sh_info + r_symndx] -= 1;
4717 if (local_got_refcounts[r_symndx] > 0)
4718 local_got_refcounts[r_symndx] -= 1;
4730 /* Copy the extra info we tack onto an elf_link_hash_entry. */
4733 sh_elf_copy_indirect_symbol (struct bfd_link_info *info,
4734 struct elf_link_hash_entry *dir,
4735 struct elf_link_hash_entry *ind)
4737 struct elf_sh_link_hash_entry *edir, *eind;
4739 edir = (struct elf_sh_link_hash_entry *) dir;
4740 eind = (struct elf_sh_link_hash_entry *) ind;
4742 if (eind->dyn_relocs != NULL)
4744 if (edir->dyn_relocs != NULL)
4746 struct elf_sh_dyn_relocs **pp;
4747 struct elf_sh_dyn_relocs *p;
4749 /* Add reloc counts against the indirect sym to the direct sym
4750 list. Merge any entries against the same section. */
4751 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
4753 struct elf_sh_dyn_relocs *q;
4755 for (q = edir->dyn_relocs; q != NULL; q = q->next)
4756 if (q->sec == p->sec)
4758 q->pc_count += p->pc_count;
4759 q->count += p->count;
4766 *pp = edir->dyn_relocs;
4769 edir->dyn_relocs = eind->dyn_relocs;
4770 eind->dyn_relocs = NULL;
4772 edir->gotplt_refcount = eind->gotplt_refcount;
4773 eind->gotplt_refcount = 0;
4774 #ifdef INCLUDE_SHMEDIA
4775 edir->datalabel_got.refcount += eind->datalabel_got.refcount;
4776 eind->datalabel_got.refcount = 0;
4779 if (ind->root.type == bfd_link_hash_indirect
4780 && dir->got.refcount <= 0)
4782 edir->tls_type = eind->tls_type;
4783 eind->tls_type = GOT_UNKNOWN;
4786 if (ind->root.type != bfd_link_hash_indirect
4787 && dir->dynamic_adjusted)
4789 /* If called to transfer flags for a weakdef during processing
4790 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
4791 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
4792 dir->ref_dynamic |= ind->ref_dynamic;
4793 dir->ref_regular |= ind->ref_regular;
4794 dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
4795 dir->needs_plt |= ind->needs_plt;
4798 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
4802 sh_elf_optimized_tls_reloc (struct bfd_link_info *info, int r_type,
4810 case R_SH_TLS_GD_32:
4811 case R_SH_TLS_IE_32:
4813 return R_SH_TLS_LE_32;
4814 return R_SH_TLS_IE_32;
4815 case R_SH_TLS_LD_32:
4816 return R_SH_TLS_LE_32;
4822 /* Look through the relocs for a section during the first phase.
4823 Since we don't do .gots or .plts, we just need to consider the
4824 virtual table relocs for gc. */
4827 sh_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
4828 const Elf_Internal_Rela *relocs)
4830 Elf_Internal_Shdr *symtab_hdr;
4831 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
4832 struct elf_sh_link_hash_table *htab;
4833 const Elf_Internal_Rela *rel;
4834 const Elf_Internal_Rela *rel_end;
4835 bfd_vma *local_got_offsets;
4839 unsigned int r_type;
4840 int tls_type, old_tls_type;
4846 if (info->relocatable)
4849 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
4850 sym_hashes = elf_sym_hashes (abfd);
4851 sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof (Elf32_External_Sym);
4852 if (!elf_bad_symtab (abfd))
4853 sym_hashes_end -= symtab_hdr->sh_info;
4855 htab = sh_elf_hash_table (info);
4856 local_got_offsets = elf_local_got_offsets (abfd);
4858 rel_end = relocs + sec->reloc_count;
4859 for (rel = relocs; rel < rel_end; rel++)
4861 struct elf_link_hash_entry *h;
4862 unsigned long r_symndx;
4863 #ifdef INCLUDE_SHMEDIA
4864 int seen_stt_datalabel = 0;
4867 r_symndx = ELF32_R_SYM (rel->r_info);
4868 r_type = ELF32_R_TYPE (rel->r_info);
4870 if (r_symndx < symtab_hdr->sh_info)
4874 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4875 while (h->root.type == bfd_link_hash_indirect
4876 || h->root.type == bfd_link_hash_warning)
4878 #ifdef INCLUDE_SHMEDIA
4879 seen_stt_datalabel |= h->type == STT_DATALABEL;
4881 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4885 r_type = sh_elf_optimized_tls_reloc (info, r_type, h == NULL);
4887 && r_type == R_SH_TLS_IE_32
4889 && h->root.type != bfd_link_hash_undefined
4890 && h->root.type != bfd_link_hash_undefweak
4891 && (h->dynindx == -1
4893 r_type = R_SH_TLS_LE_32;
4895 /* Some relocs require a global offset table. */
4896 if (htab->sgot == NULL)
4904 #ifdef INCLUDE_SHMEDIA
4905 case R_SH_GOTPLT_LOW16:
4906 case R_SH_GOTPLT_MEDLOW16:
4907 case R_SH_GOTPLT_MEDHI16:
4908 case R_SH_GOTPLT_HI16:
4909 case R_SH_GOTPLT10BY4:
4910 case R_SH_GOTPLT10BY8:
4911 case R_SH_GOT_LOW16:
4912 case R_SH_GOT_MEDLOW16:
4913 case R_SH_GOT_MEDHI16:
4917 case R_SH_GOTOFF_LOW16:
4918 case R_SH_GOTOFF_MEDLOW16:
4919 case R_SH_GOTOFF_MEDHI16:
4920 case R_SH_GOTOFF_HI16:
4921 case R_SH_GOTPC_LOW16:
4922 case R_SH_GOTPC_MEDLOW16:
4923 case R_SH_GOTPC_MEDHI16:
4924 case R_SH_GOTPC_HI16:
4926 case R_SH_TLS_GD_32:
4927 case R_SH_TLS_LD_32:
4928 case R_SH_TLS_IE_32:
4929 if (htab->sgot == NULL)
4931 if (htab->root.dynobj == NULL)
4932 htab->root.dynobj = abfd;
4933 if (!create_got_section (htab->root.dynobj, info))
4945 /* This relocation describes the C++ object vtable hierarchy.
4946 Reconstruct it for later use during GC. */
4947 case R_SH_GNU_VTINHERIT:
4948 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
4952 /* This relocation describes which C++ vtable entries are actually
4953 used. Record for later use during GC. */
4954 case R_SH_GNU_VTENTRY:
4955 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
4959 case R_SH_TLS_IE_32:
4961 info->flags |= DF_STATIC_TLS;
4965 case R_SH_TLS_GD_32:
4967 #ifdef INCLUDE_SHMEDIA
4968 case R_SH_GOT_LOW16:
4969 case R_SH_GOT_MEDLOW16:
4970 case R_SH_GOT_MEDHI16:
4978 tls_type = GOT_NORMAL;
4980 case R_SH_TLS_GD_32:
4981 tls_type = GOT_TLS_GD;
4983 case R_SH_TLS_IE_32:
4984 tls_type = GOT_TLS_IE;
4990 #ifdef INCLUDE_SHMEDIA
4991 if (seen_stt_datalabel)
4993 struct elf_sh_link_hash_entry *eh
4994 = (struct elf_sh_link_hash_entry *) h;
4996 eh->datalabel_got.refcount += 1;
5000 h->got.refcount += 1;
5001 old_tls_type = sh_elf_hash_entry (h)->tls_type;
5005 bfd_signed_vma *local_got_refcounts;
5007 /* This is a global offset table entry for a local
5009 local_got_refcounts = elf_local_got_refcounts (abfd);
5010 if (local_got_refcounts == NULL)
5014 size = symtab_hdr->sh_info;
5015 size *= sizeof (bfd_signed_vma);
5016 #ifdef INCLUDE_SHMEDIA
5017 /* Reserve space for both the datalabel and
5018 codelabel local GOT offsets. */
5021 size += symtab_hdr->sh_info;
5022 local_got_refcounts = ((bfd_signed_vma *)
5023 bfd_zalloc (abfd, size));
5024 if (local_got_refcounts == NULL)
5026 elf_local_got_refcounts (abfd) = local_got_refcounts;
5027 #ifdef INCLUDE_SHMEDIA
5028 /* Take care of both the datalabel and codelabel local
5030 sh_elf_local_got_tls_type (abfd)
5031 = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
5033 sh_elf_local_got_tls_type (abfd)
5034 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
5037 #ifdef INCLUDE_SHMEDIA
5038 if (rel->r_addend & 1)
5039 local_got_refcounts[symtab_hdr->sh_info + r_symndx] += 1;
5042 local_got_refcounts[r_symndx] += 1;
5043 old_tls_type = sh_elf_local_got_tls_type (abfd) [r_symndx];
5046 /* If a TLS symbol is accessed using IE at least once,
5047 there is no point to use dynamic model for it. */
5048 if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
5049 && (old_tls_type != GOT_TLS_GD || tls_type != GOT_TLS_IE))
5051 if (old_tls_type == GOT_TLS_IE && tls_type == GOT_TLS_GD)
5052 tls_type = GOT_TLS_IE;
5055 (*_bfd_error_handler)
5056 (_("%B: `%s' accessed both as normal and thread local symbol"),
5057 abfd, h->root.root.string);
5062 if (old_tls_type != tls_type)
5065 sh_elf_hash_entry (h)->tls_type = tls_type;
5067 sh_elf_local_got_tls_type (abfd) [r_symndx] = tls_type;
5072 case R_SH_TLS_LD_32:
5073 sh_elf_hash_table(info)->tls_ldm_got.refcount += 1;
5077 #ifdef INCLUDE_SHMEDIA
5078 case R_SH_GOTPLT_LOW16:
5079 case R_SH_GOTPLT_MEDLOW16:
5080 case R_SH_GOTPLT_MEDHI16:
5081 case R_SH_GOTPLT_HI16:
5082 case R_SH_GOTPLT10BY4:
5083 case R_SH_GOTPLT10BY8:
5085 /* If this is a local symbol, we resolve it directly without
5086 creating a procedure linkage table entry. */
5092 || h->dynindx == -1)
5096 h->plt.refcount += 1;
5097 ((struct elf_sh_link_hash_entry *) h)->gotplt_refcount += 1;
5102 #ifdef INCLUDE_SHMEDIA
5103 case R_SH_PLT_LOW16:
5104 case R_SH_PLT_MEDLOW16:
5105 case R_SH_PLT_MEDHI16:
5108 /* This symbol requires a procedure linkage table entry. We
5109 actually build the entry in adjust_dynamic_symbol,
5110 because this might be a case of linking PIC code which is
5111 never referenced by a dynamic object, in which case we
5112 don't need to generate a procedure linkage table entry
5115 /* If this is a local symbol, we resolve it directly without
5116 creating a procedure linkage table entry. */
5120 if (h->forced_local)
5124 h->plt.refcount += 1;
5129 #ifdef INCLUDE_SHMEDIA
5130 case R_SH_IMM_LOW16_PCREL:
5131 case R_SH_IMM_MEDLOW16_PCREL:
5132 case R_SH_IMM_MEDHI16_PCREL:
5133 case R_SH_IMM_HI16_PCREL:
5135 if (h != NULL && ! info->shared)
5138 h->plt.refcount += 1;
5141 /* If we are creating a shared library, and this is a reloc
5142 against a global symbol, or a non PC relative reloc
5143 against a local symbol, then we need to copy the reloc
5144 into the shared library. However, if we are linking with
5145 -Bsymbolic, we do not need to copy a reloc against a
5146 global symbol which is defined in an object we are
5147 including in the link (i.e., DEF_REGULAR is set). At
5148 this point we have not seen all the input files, so it is
5149 possible that DEF_REGULAR is not set now but will be set
5150 later (it is never cleared). We account for that
5151 possibility below by storing information in the
5152 dyn_relocs field of the hash table entry. A similar
5153 situation occurs when creating shared libraries and symbol
5154 visibility changes render the symbol local.
5156 If on the other hand, we are creating an executable, we
5157 may need to keep relocations for symbols satisfied by a
5158 dynamic library if we manage to avoid copy relocs for the
5161 && (sec->flags & SEC_ALLOC) != 0
5162 && (r_type != R_SH_REL32
5164 && (! info->symbolic
5165 || h->root.type == bfd_link_hash_defweak
5166 || !h->def_regular))))
5168 && (sec->flags & SEC_ALLOC) != 0
5170 && (h->root.type == bfd_link_hash_defweak
5171 || !h->def_regular)))
5173 struct elf_sh_dyn_relocs *p;
5174 struct elf_sh_dyn_relocs **head;
5176 if (htab->root.dynobj == NULL)
5177 htab->root.dynobj = abfd;
5179 /* When creating a shared object, we must copy these
5180 reloc types into the output file. We create a reloc
5181 section in dynobj and make room for this reloc. */
5186 name = (bfd_elf_string_from_elf_section
5188 elf_elfheader (abfd)->e_shstrndx,
5189 elf_section_data (sec)->rel_hdr.sh_name));
5193 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
5194 && strcmp (bfd_get_section_name (abfd, sec),
5197 sreloc = bfd_get_section_by_name (htab->root.dynobj, name);
5202 flags = (SEC_HAS_CONTENTS | SEC_READONLY
5203 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
5204 if ((sec->flags & SEC_ALLOC) != 0)
5205 flags |= SEC_ALLOC | SEC_LOAD;
5206 sreloc = bfd_make_section_with_flags (htab->root.dynobj,
5210 || ! bfd_set_section_alignment (htab->root.dynobj,
5214 elf_section_data (sec)->sreloc = sreloc;
5217 /* If this is a global symbol, we count the number of
5218 relocations we need for this symbol. */
5220 head = &((struct elf_sh_link_hash_entry *) h)->dyn_relocs;
5226 /* Track dynamic relocs needed for local syms too. */
5227 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
5232 vpp = &elf_section_data (s)->local_dynrel;
5233 head = (struct elf_sh_dyn_relocs **) vpp;
5237 if (p == NULL || p->sec != sec)
5239 bfd_size_type amt = sizeof (*p);
5240 p = bfd_alloc (htab->root.dynobj, amt);
5251 if (r_type == R_SH_REL32
5252 #ifdef INCLUDE_SHMEDIA
5253 || r_type == R_SH_IMM_LOW16_PCREL
5254 || r_type == R_SH_IMM_MEDLOW16_PCREL
5255 || r_type == R_SH_IMM_MEDHI16_PCREL
5256 || r_type == R_SH_IMM_HI16_PCREL
5264 case R_SH_TLS_LE_32:
5267 (*_bfd_error_handler)
5268 (_("%B: TLS local exec code cannot be linked into shared objects"),
5275 case R_SH_TLS_LDO_32:
5276 /* Nothing to do. */
5287 #ifndef sh_elf_set_mach_from_flags
5288 static unsigned int sh_ef_bfd_table[] = { EF_SH_BFD_TABLE };
5291 sh_elf_set_mach_from_flags (bfd *abfd)
5293 flagword flags = elf_elfheader (abfd)->e_flags & EF_SH_MACH_MASK;
5295 if (flags >= sizeof(sh_ef_bfd_table))
5298 if (sh_ef_bfd_table[flags] == 0)
5301 bfd_default_set_arch_mach (abfd, bfd_arch_sh, sh_ef_bfd_table[flags]);
5307 /* Reverse table lookup for sh_ef_bfd_table[].
5308 Given a bfd MACH value from archures.c
5309 return the equivalent ELF flags from the table.
5310 Return -1 if no match is found. */
5313 sh_elf_get_flags_from_mach (unsigned long mach)
5315 int i = ARRAY_SIZE (sh_ef_bfd_table) - 1;
5318 if (sh_ef_bfd_table[i] == mach)
5321 /* shouldn't get here */
5326 #endif /* not sh_elf_set_mach_from_flags */
5328 #ifndef sh_elf_set_private_flags
5329 /* Function to keep SH specific file flags. */
5332 sh_elf_set_private_flags (bfd *abfd, flagword flags)
5334 BFD_ASSERT (! elf_flags_init (abfd)
5335 || elf_elfheader (abfd)->e_flags == flags);
5337 elf_elfheader (abfd)->e_flags = flags;
5338 elf_flags_init (abfd) = TRUE;
5339 return sh_elf_set_mach_from_flags (abfd);
5341 #endif /* not sh_elf_set_private_flags */
5343 #ifndef sh_elf_copy_private_data
5344 /* Copy backend specific data from one object module to another */
5347 sh_elf_copy_private_data (bfd * ibfd, bfd * obfd)
5349 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
5350 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
5353 return sh_elf_set_private_flags (obfd, elf_elfheader (ibfd)->e_flags);
5355 #endif /* not sh_elf_copy_private_data */
5357 #ifndef sh_elf_merge_private_data
5359 /* This function returns the ELF architecture number that
5360 corresponds to the given arch_sh* flags. */
5363 sh_find_elf_flags (unsigned int arch_set)
5365 extern unsigned long sh_get_bfd_mach_from_arch_set (unsigned int);
5366 unsigned long bfd_mach = sh_get_bfd_mach_from_arch_set (arch_set);
5368 return sh_elf_get_flags_from_mach (bfd_mach);
5371 /* This routine initialises the elf flags when required and
5372 calls sh_merge_bfd_arch() to check dsp/fpu compatibility. */
5375 sh_elf_merge_private_data (bfd *ibfd, bfd *obfd)
5377 extern bfd_boolean sh_merge_bfd_arch (bfd *, bfd *);
5379 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
5380 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
5383 if (! elf_flags_init (obfd))
5385 /* This happens when ld starts out with a 'blank' output file. */
5386 elf_flags_init (obfd) = TRUE;
5387 elf_elfheader (obfd)->e_flags = EF_SH1;
5388 sh_elf_set_mach_from_flags (obfd);
5391 if (! sh_merge_bfd_arch (ibfd, obfd))
5393 _bfd_error_handler ("%B: uses instructions which are incompatible "
5394 "with instructions used in previous modules",
5396 bfd_set_error (bfd_error_bad_value);
5400 elf_elfheader (obfd)->e_flags =
5401 sh_elf_get_flags_from_mach (bfd_get_mach (obfd));
5405 #endif /* not sh_elf_merge_private_data */
5407 /* Override the generic function because we need to store sh_elf_obj_tdata
5408 as the specific tdata. We set also the machine architecture from flags
5412 sh_elf_object_p (bfd *abfd)
5414 return sh_elf_set_mach_from_flags (abfd);
5417 /* Finish up dynamic symbol handling. We set the contents of various
5418 dynamic sections here. */
5421 sh_elf_finish_dynamic_symbol (bfd *output_bfd, struct bfd_link_info *info,
5422 struct elf_link_hash_entry *h,
5423 Elf_Internal_Sym *sym)
5425 struct elf_sh_link_hash_table *htab;
5427 htab = sh_elf_hash_table (info);
5429 if (h->plt.offset != (bfd_vma) -1)
5437 Elf_Internal_Rela rel;
5440 /* This symbol has an entry in the procedure linkage table. Set
5443 BFD_ASSERT (h->dynindx != -1);
5446 sgot = htab->sgotplt;
5447 srel = htab->srelplt;
5448 BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
5450 /* Get the index in the procedure linkage table which
5451 corresponds to this symbol. This is the index of this symbol
5452 in all the symbols for which we are making plt entries. The
5453 first entry in the procedure linkage table is reserved. */
5454 plt_index = get_plt_index (htab->plt_info, h->plt.offset);
5456 /* Get the offset into the .got table of the entry that
5457 corresponds to this function. Each .got entry is 4 bytes.
5458 The first three are reserved. */
5459 got_offset = (plt_index + 3) * 4;
5463 got_offset -= GOT_BIAS;
5466 /* Fill in the entry in the procedure linkage table. */
5467 memcpy (splt->contents + h->plt.offset,
5468 htab->plt_info->symbol_entry,
5469 htab->plt_info->symbol_entry_size);
5472 install_plt_field (output_bfd, FALSE, got_offset,
5475 + htab->plt_info->symbol_fields.got_entry));
5478 install_plt_field (output_bfd, FALSE,
5479 (sgot->output_section->vma
5480 + sgot->output_offset
5484 + htab->plt_info->symbol_fields.got_entry));
5485 if (htab->vxworks_p)
5487 unsigned int reachable_plts, plts_per_4k;
5490 /* Divide the PLT into groups. The first group contains
5491 REACHABLE_PLTS entries and the other groups contain
5492 PLTS_PER_4K entries. Entries in the first group can
5493 branch directly to .plt; those in later groups branch
5494 to the last element of the previous group. */
5495 /* ??? It would be better to create multiple copies of
5496 the common resolver stub. */
5497 reachable_plts = ((4096
5498 - htab->plt_info->plt0_entry_size
5499 - (htab->plt_info->symbol_fields.plt + 4))
5500 / htab->plt_info->symbol_entry_size) + 1;
5501 plts_per_4k = (4096 / htab->plt_info->symbol_entry_size);
5502 if (plt_index < reachable_plts)
5503 distance = -(h->plt.offset
5504 + htab->plt_info->symbol_fields.plt);
5506 distance = -(((plt_index - reachable_plts) % plts_per_4k + 1)
5507 * htab->plt_info->symbol_entry_size);
5509 /* Install the 'bra' with this offset. */
5510 bfd_put_16 (output_bfd,
5511 0xa000 | (0x0fff & ((distance - 4) / 2)),
5514 + htab->plt_info->symbol_fields.plt));
5517 install_plt_field (output_bfd, TRUE,
5518 splt->output_section->vma + splt->output_offset,
5521 + htab->plt_info->symbol_fields.plt));
5526 got_offset += GOT_BIAS;
5529 install_plt_field (output_bfd, FALSE,
5530 plt_index * sizeof (Elf32_External_Rela),
5533 + htab->plt_info->symbol_fields.reloc_offset));
5535 /* Fill in the entry in the global offset table. */
5536 bfd_put_32 (output_bfd,
5537 (splt->output_section->vma
5538 + splt->output_offset
5540 + htab->plt_info->symbol_resolve_offset),
5541 sgot->contents + got_offset);
5543 /* Fill in the entry in the .rela.plt section. */
5544 rel.r_offset = (sgot->output_section->vma
5545 + sgot->output_offset
5547 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_JMP_SLOT);
5550 rel.r_addend = GOT_BIAS;
5552 loc = srel->contents + plt_index * sizeof (Elf32_External_Rela);
5553 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
5555 if (htab->vxworks_p && !info->shared)
5557 /* Create the .rela.plt.unloaded relocations for this PLT entry.
5558 Begin by pointing LOC to the first such relocation. */
5559 loc = (htab->srelplt2->contents
5560 + (plt_index * 2 + 1) * sizeof (Elf32_External_Rela));
5562 /* Create a .rela.plt.unloaded R_SH_DIR32 relocation
5563 for the PLT entry's pointer to the .got.plt entry. */
5564 rel.r_offset = (htab->splt->output_section->vma
5565 + htab->splt->output_offset
5567 + htab->plt_info->symbol_fields.got_entry);
5568 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_SH_DIR32);
5569 rel.r_addend = got_offset;
5570 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
5571 loc += sizeof (Elf32_External_Rela);
5573 /* Create a .rela.plt.unloaded R_SH_DIR32 relocation for
5574 the .got.plt entry, which initially points to .plt. */
5575 rel.r_offset = (htab->sgotplt->output_section->vma
5576 + htab->sgotplt->output_offset
5578 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_SH_DIR32);
5580 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
5583 if (!h->def_regular)
5585 /* Mark the symbol as undefined, rather than as defined in
5586 the .plt section. Leave the value alone. */
5587 sym->st_shndx = SHN_UNDEF;
5591 if (h->got.offset != (bfd_vma) -1
5592 && sh_elf_hash_entry (h)->tls_type != GOT_TLS_GD
5593 && sh_elf_hash_entry (h)->tls_type != GOT_TLS_IE)
5597 Elf_Internal_Rela rel;
5600 /* This symbol has an entry in the global offset table. Set it
5604 srel = htab->srelgot;
5605 BFD_ASSERT (sgot != NULL && srel != NULL);
5607 rel.r_offset = (sgot->output_section->vma
5608 + sgot->output_offset
5609 + (h->got.offset &~ (bfd_vma) 1));
5611 /* If this is a static link, or it is a -Bsymbolic link and the
5612 symbol is defined locally or was forced to be local because
5613 of a version file, we just want to emit a RELATIVE reloc.
5614 The entry in the global offset table will already have been
5615 initialized in the relocate_section function. */
5617 && SYMBOL_REFERENCES_LOCAL (info, h))
5619 rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
5620 rel.r_addend = (h->root.u.def.value
5621 + h->root.u.def.section->output_section->vma
5622 + h->root.u.def.section->output_offset);
5626 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
5627 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_GLOB_DAT);
5631 loc = srel->contents;
5632 loc += srel->reloc_count++ * sizeof (Elf32_External_Rela);
5633 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
5636 #ifdef INCLUDE_SHMEDIA
5638 struct elf_sh_link_hash_entry *eh;
5640 eh = (struct elf_sh_link_hash_entry *) h;
5641 if (eh->datalabel_got.offset != (bfd_vma) -1)
5645 Elf_Internal_Rela rel;
5648 /* This symbol has a datalabel entry in the global offset table.
5652 srel = htab->srelgot;
5653 BFD_ASSERT (sgot != NULL && srel != NULL);
5655 rel.r_offset = (sgot->output_section->vma
5656 + sgot->output_offset
5657 + (eh->datalabel_got.offset &~ (bfd_vma) 1));
5659 /* If this is a static link, or it is a -Bsymbolic link and the
5660 symbol is defined locally or was forced to be local because
5661 of a version file, we just want to emit a RELATIVE reloc.
5662 The entry in the global offset table will already have been
5663 initialized in the relocate_section function. */
5665 && SYMBOL_REFERENCES_LOCAL (info, h))
5667 rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
5668 rel.r_addend = (h->root.u.def.value
5669 + h->root.u.def.section->output_section->vma
5670 + h->root.u.def.section->output_offset);
5674 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents
5675 + eh->datalabel_got.offset);
5676 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_GLOB_DAT);
5680 loc = srel->contents;
5681 loc += srel->reloc_count++ * sizeof (Elf32_External_Rela);
5682 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
5690 Elf_Internal_Rela rel;
5693 /* This symbol needs a copy reloc. Set it up. */
5695 BFD_ASSERT (h->dynindx != -1
5696 && (h->root.type == bfd_link_hash_defined
5697 || h->root.type == bfd_link_hash_defweak));
5699 s = bfd_get_section_by_name (h->root.u.def.section->owner,
5701 BFD_ASSERT (s != NULL);
5703 rel.r_offset = (h->root.u.def.value
5704 + h->root.u.def.section->output_section->vma
5705 + h->root.u.def.section->output_offset);
5706 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_COPY);
5708 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
5709 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
5712 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
5713 _GLOBAL_OFFSET_TABLE_ is not absolute: it is relative to the
5715 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
5716 || (!htab->vxworks_p && h == htab->root.hgot))
5717 sym->st_shndx = SHN_ABS;
5722 /* Finish up the dynamic sections. */
5725 sh_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
5727 struct elf_sh_link_hash_table *htab;
5731 htab = sh_elf_hash_table (info);
5732 sgot = htab->sgotplt;
5733 sdyn = bfd_get_section_by_name (htab->root.dynobj, ".dynamic");
5735 if (htab->root.dynamic_sections_created)
5738 Elf32_External_Dyn *dyncon, *dynconend;
5740 BFD_ASSERT (sgot != NULL && sdyn != NULL);
5742 dyncon = (Elf32_External_Dyn *) sdyn->contents;
5743 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
5744 for (; dyncon < dynconend; dyncon++)
5746 Elf_Internal_Dyn dyn;
5748 #ifdef INCLUDE_SHMEDIA
5752 bfd_elf32_swap_dyn_in (htab->root.dynobj, dyncon, &dyn);
5759 #ifdef INCLUDE_SHMEDIA
5761 name = info->init_function;
5765 name = info->fini_function;
5767 if (dyn.d_un.d_val != 0)
5769 struct elf_link_hash_entry *h;
5771 h = elf_link_hash_lookup (&htab->root, name,
5772 FALSE, FALSE, TRUE);
5773 if (h != NULL && (h->other & STO_SH5_ISA32))
5775 dyn.d_un.d_val |= 1;
5776 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5783 s = htab->sgot->output_section;
5787 s = htab->srelplt->output_section;
5789 BFD_ASSERT (s != NULL);
5790 dyn.d_un.d_ptr = s->vma;
5791 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5795 s = htab->srelplt->output_section;
5796 BFD_ASSERT (s != NULL);
5797 dyn.d_un.d_val = s->size;
5798 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5802 /* My reading of the SVR4 ABI indicates that the
5803 procedure linkage table relocs (DT_JMPREL) should be
5804 included in the overall relocs (DT_RELA). This is
5805 what Solaris does. However, UnixWare can not handle
5806 that case. Therefore, we override the DT_RELASZ entry
5807 here to make it not include the JMPREL relocs. Since
5808 the linker script arranges for .rela.plt to follow all
5809 other relocation sections, we don't have to worry
5810 about changing the DT_RELA entry. */
5811 if (htab->srelplt != NULL)
5813 s = htab->srelplt->output_section;
5814 dyn.d_un.d_val -= s->size;
5816 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5821 /* Fill in the first entry in the procedure linkage table. */
5823 if (splt && splt->size > 0 && htab->plt_info->plt0_entry)
5827 memcpy (splt->contents,
5828 htab->plt_info->plt0_entry,
5829 htab->plt_info->plt0_entry_size);
5830 for (i = 0; i < ARRAY_SIZE (htab->plt_info->plt0_got_fields); i++)
5831 if (htab->plt_info->plt0_got_fields[i] != MINUS_ONE)
5832 install_plt_field (output_bfd, FALSE,
5833 (sgot->output_section->vma
5834 + sgot->output_offset
5837 + htab->plt_info->plt0_got_fields[i]));
5839 if (htab->vxworks_p)
5841 /* Finalize the .rela.plt.unloaded contents. */
5842 Elf_Internal_Rela rel;
5845 /* Create a .rela.plt.unloaded R_SH_DIR32 relocation for the
5846 first PLT entry's pointer to _GLOBAL_OFFSET_TABLE_ + 8. */
5847 loc = htab->srelplt2->contents;
5848 rel.r_offset = (splt->output_section->vma
5849 + splt->output_offset
5850 + htab->plt_info->plt0_got_fields[2]);
5851 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_SH_DIR32);
5853 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
5854 loc += sizeof (Elf32_External_Rela);
5856 /* Fix up the remaining .rela.plt.unloaded relocations.
5857 They may have the wrong symbol index for _G_O_T_ or
5858 _P_L_T_ depending on the order in which symbols were
5860 while (loc < htab->srelplt2->contents + htab->srelplt2->size)
5862 /* The PLT entry's pointer to the .got.plt slot. */
5863 bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
5864 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx,
5866 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
5867 loc += sizeof (Elf32_External_Rela);
5869 /* The .got.plt slot's pointer to .plt. */
5870 bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
5871 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx,
5873 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
5874 loc += sizeof (Elf32_External_Rela);
5878 /* UnixWare sets the entsize of .plt to 4, although that doesn't
5879 really seem like the right value. */
5880 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
5884 /* Fill in the first three entries in the global offset table. */
5885 if (sgot && sgot->size > 0)
5888 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
5890 bfd_put_32 (output_bfd,
5891 sdyn->output_section->vma + sdyn->output_offset,
5893 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
5894 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
5896 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
5902 static enum elf_reloc_type_class
5903 sh_elf_reloc_type_class (const Elf_Internal_Rela *rela)
5905 switch ((int) ELF32_R_TYPE (rela->r_info))
5908 return reloc_class_relative;
5910 return reloc_class_plt;
5912 return reloc_class_copy;
5914 return reloc_class_normal;
5918 #if !defined SH_TARGET_ALREADY_DEFINED
5919 /* Support for Linux core dump NOTE sections. */
5922 elf32_shlin_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
5927 switch (note->descsz)
5932 case 168: /* Linux/SH */
5934 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
5937 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
5946 /* Make a ".reg/999" section. */
5947 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
5948 size, note->descpos + offset);
5952 elf32_shlin_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
5954 switch (note->descsz)
5959 case 124: /* Linux/SH elf_prpsinfo */
5960 elf_tdata (abfd)->core_program
5961 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
5962 elf_tdata (abfd)->core_command
5963 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
5966 /* Note that for some reason, a spurious space is tacked
5967 onto the end of the args in some (at least one anyway)
5968 implementations, so strip it off if it exists. */
5971 char *command = elf_tdata (abfd)->core_command;
5972 int n = strlen (command);
5974 if (0 < n && command[n - 1] == ' ')
5975 command[n - 1] = '\0';
5980 #endif /* not SH_TARGET_ALREADY_DEFINED */
5983 /* Return address for Ith PLT stub in section PLT, for relocation REL
5984 or (bfd_vma) -1 if it should not be included. */
5987 sh_elf_plt_sym_val (bfd_vma i, const asection *plt,
5988 const arelent *rel ATTRIBUTE_UNUSED)
5990 const struct elf_sh_plt_info *plt_info;
5992 plt_info = get_plt_info (plt->owner, (plt->owner->flags & DYNAMIC) != 0);
5993 return plt->vma + get_plt_offset (plt_info, i);
5996 #if !defined SH_TARGET_ALREADY_DEFINED
5997 #define TARGET_BIG_SYM bfd_elf32_sh_vec
5998 #define TARGET_BIG_NAME "elf32-sh"
5999 #define TARGET_LITTLE_SYM bfd_elf32_shl_vec
6000 #define TARGET_LITTLE_NAME "elf32-shl"
6003 #define ELF_ARCH bfd_arch_sh
6004 #define ELF_MACHINE_CODE EM_SH
6005 #ifdef __QNXTARGET__
6006 #define ELF_MAXPAGESIZE 0x1000
6008 #define ELF_MAXPAGESIZE 0x80
6011 #define elf_symbol_leading_char '_'
6013 #define bfd_elf32_bfd_reloc_type_lookup sh_elf_reloc_type_lookup
6014 #define elf_info_to_howto sh_elf_info_to_howto
6015 #define bfd_elf32_bfd_relax_section sh_elf_relax_section
6016 #define elf_backend_relocate_section sh_elf_relocate_section
6017 #define bfd_elf32_bfd_get_relocated_section_contents \
6018 sh_elf_get_relocated_section_contents
6019 #define bfd_elf32_mkobject sh_elf_mkobject
6020 #define elf_backend_object_p sh_elf_object_p
6021 #define bfd_elf32_bfd_set_private_bfd_flags \
6022 sh_elf_set_private_flags
6023 #define bfd_elf32_bfd_copy_private_bfd_data \
6024 sh_elf_copy_private_data
6025 #define bfd_elf32_bfd_merge_private_bfd_data \
6026 sh_elf_merge_private_data
6028 #define elf_backend_gc_mark_hook sh_elf_gc_mark_hook
6029 #define elf_backend_gc_sweep_hook sh_elf_gc_sweep_hook
6030 #define elf_backend_check_relocs sh_elf_check_relocs
6031 #define elf_backend_copy_indirect_symbol \
6032 sh_elf_copy_indirect_symbol
6033 #define elf_backend_create_dynamic_sections \
6034 sh_elf_create_dynamic_sections
6035 #define bfd_elf32_bfd_link_hash_table_create \
6036 sh_elf_link_hash_table_create
6037 #define elf_backend_adjust_dynamic_symbol \
6038 sh_elf_adjust_dynamic_symbol
6039 #define elf_backend_always_size_sections \
6040 sh_elf_always_size_sections
6041 #define elf_backend_size_dynamic_sections \
6042 sh_elf_size_dynamic_sections
6043 #define elf_backend_finish_dynamic_symbol \
6044 sh_elf_finish_dynamic_symbol
6045 #define elf_backend_finish_dynamic_sections \
6046 sh_elf_finish_dynamic_sections
6047 #define elf_backend_reloc_type_class sh_elf_reloc_type_class
6048 #define elf_backend_plt_sym_val sh_elf_plt_sym_val
6050 #define elf_backend_can_gc_sections 1
6051 #define elf_backend_can_refcount 1
6052 #define elf_backend_want_got_plt 1
6053 #define elf_backend_plt_readonly 1
6054 #define elf_backend_want_plt_sym 0
6055 #define elf_backend_got_header_size 12
6057 #if !defined INCLUDE_SHMEDIA && !defined SH_TARGET_ALREADY_DEFINED
6059 #include "elf32-target.h"
6061 /* NetBSD support. */
6062 #undef TARGET_BIG_SYM
6063 #define TARGET_BIG_SYM bfd_elf32_shnbsd_vec
6064 #undef TARGET_BIG_NAME
6065 #define TARGET_BIG_NAME "elf32-sh-nbsd"
6066 #undef TARGET_LITTLE_SYM
6067 #define TARGET_LITTLE_SYM bfd_elf32_shlnbsd_vec
6068 #undef TARGET_LITTLE_NAME
6069 #define TARGET_LITTLE_NAME "elf32-shl-nbsd"
6070 #undef ELF_MAXPAGESIZE
6071 #define ELF_MAXPAGESIZE 0x10000
6072 #undef ELF_COMMONPAGESIZE
6073 #undef elf_symbol_leading_char
6074 #define elf_symbol_leading_char 0
6076 #define elf32_bed elf32_sh_nbsd_bed
6078 #include "elf32-target.h"
6081 /* Linux support. */
6082 #undef TARGET_BIG_SYM
6083 #define TARGET_BIG_SYM bfd_elf32_shblin_vec
6084 #undef TARGET_BIG_NAME
6085 #define TARGET_BIG_NAME "elf32-shbig-linux"
6086 #undef TARGET_LITTLE_SYM
6087 #define TARGET_LITTLE_SYM bfd_elf32_shlin_vec
6088 #undef TARGET_LITTLE_NAME
6089 #define TARGET_LITTLE_NAME "elf32-sh-linux"
6090 #undef ELF_COMMONPAGESIZE
6091 #define ELF_COMMONPAGESIZE 0x1000
6093 #undef elf_backend_grok_prstatus
6094 #define elf_backend_grok_prstatus elf32_shlin_grok_prstatus
6095 #undef elf_backend_grok_psinfo
6096 #define elf_backend_grok_psinfo elf32_shlin_grok_psinfo
6098 #define elf32_bed elf32_sh_lin_bed
6100 #include "elf32-target.h"
6102 #undef TARGET_BIG_SYM
6103 #define TARGET_BIG_SYM bfd_elf32_shvxworks_vec
6104 #undef TARGET_BIG_NAME
6105 #define TARGET_BIG_NAME "elf32-sh-vxworks"
6106 #undef TARGET_LITTLE_SYM
6107 #define TARGET_LITTLE_SYM bfd_elf32_shlvxworks_vec
6108 #undef TARGET_LITTLE_NAME
6109 #define TARGET_LITTLE_NAME "elf32-shl-vxworks"
6111 #define elf32_bed elf32_sh_vxworks_bed
6113 #undef elf_backend_want_plt_sym
6114 #define elf_backend_want_plt_sym 1
6115 #undef elf_symbol_leading_char
6116 #define elf_symbol_leading_char '_'
6117 #define elf_backend_want_got_underscore 1
6118 #undef elf_backend_grok_prstatus
6119 #undef elf_backend_grok_psinfo
6120 #undef elf_backend_add_symbol_hook
6121 #define elf_backend_add_symbol_hook elf_vxworks_add_symbol_hook
6122 #undef elf_backend_link_output_symbol_hook
6123 #define elf_backend_link_output_symbol_hook \
6124 elf_vxworks_link_output_symbol_hook
6125 #undef elf_backend_emit_relocs
6126 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
6127 #undef elf_backend_final_write_processing
6128 #define elf_backend_final_write_processing \
6129 elf_vxworks_final_write_processing
6130 #undef ELF_MAXPAGESIZE
6131 #define ELF_MAXPAGESIZE 0x1000
6132 #undef ELF_COMMONPAGESIZE
6134 #include "elf32-target.h"
6136 #endif /* neither INCLUDE_SHMEDIA nor SH_TARGET_ALREADY_DEFINED */