1 /* Renesas / SuperH SH specific support for 32-bit ELF
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006, 2007, 2008, 2009, 2010, 2011 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 3 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,
21 MA 02110-1301, USA. */
28 #include "elf-vxworks.h"
31 #include "libiberty.h"
32 #include "../opcodes/sh-opc.h"
34 static bfd_reloc_status_type sh_elf_reloc
35 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
36 static bfd_reloc_status_type sh_elf_ignore_reloc
37 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
38 static bfd_boolean sh_elf_relax_delete_bytes
39 (bfd
*, asection
*, bfd_vma
, int);
40 static bfd_boolean sh_elf_align_loads
41 (bfd
*, asection
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_boolean
*);
43 static bfd_boolean sh_elf_swap_insns
44 (bfd
*, asection
*, void *, bfd_byte
*, bfd_vma
);
46 static int sh_elf_optimized_tls_reloc
47 (struct bfd_link_info
*, int, int);
48 static bfd_vma dtpoff_base
49 (struct bfd_link_info
*);
51 (struct bfd_link_info
*, bfd_vma
);
53 /* The name of the dynamic interpreter. This is put in the .interp
56 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
58 /* FDPIC binaries have a default 128K stack. */
59 #define DEFAULT_STACK_SIZE 0x20000
61 #define MINUS_ONE ((bfd_vma) 0 - 1)
63 /* Decide whether a reference to a symbol can be resolved locally or
64 not. If the symbol is protected, we want the local address, but
65 its function descriptor must be assigned by the dynamic linker. */
66 #define SYMBOL_FUNCDESC_LOCAL(INFO, H) \
67 (SYMBOL_REFERENCES_LOCAL (INFO, H) \
68 || ! elf_hash_table (INFO)->dynamic_sections_created)
70 #define SH_PARTIAL32 TRUE
71 #define SH_SRC_MASK32 0xffffffff
72 #define SH_ELF_RELOC sh_elf_reloc
73 static reloc_howto_type sh_elf_howto_table
[] =
75 #include "elf32-sh-relocs.h"
78 #define SH_PARTIAL32 FALSE
79 #define SH_SRC_MASK32 0
80 #define SH_ELF_RELOC bfd_elf_generic_reloc
81 static reloc_howto_type sh_vxworks_howto_table
[] =
83 #include "elf32-sh-relocs.h"
86 /* Return true if OUTPUT_BFD is a VxWorks object. */
89 vxworks_object_p (bfd
*abfd ATTRIBUTE_UNUSED
)
91 #if !defined INCLUDE_SHMEDIA && !defined SH_TARGET_ALREADY_DEFINED
92 extern const bfd_target bfd_elf32_shlvxworks_vec
;
93 extern const bfd_target bfd_elf32_shvxworks_vec
;
95 return (abfd
->xvec
== &bfd_elf32_shlvxworks_vec
96 || abfd
->xvec
== &bfd_elf32_shvxworks_vec
);
102 /* Return true if OUTPUT_BFD is an FDPIC object. */
105 fdpic_object_p (bfd
*abfd ATTRIBUTE_UNUSED
)
107 #if !defined INCLUDE_SHMEDIA && !defined SH_TARGET_ALREADY_DEFINED
108 extern const bfd_target bfd_elf32_shfd_vec
;
109 extern const bfd_target bfd_elf32_shbfd_vec
;
111 return (abfd
->xvec
== &bfd_elf32_shfd_vec
112 || abfd
->xvec
== &bfd_elf32_shbfd_vec
);
118 /* Return the howto table for ABFD. */
120 static reloc_howto_type
*
121 get_howto_table (bfd
*abfd
)
123 if (vxworks_object_p (abfd
))
124 return sh_vxworks_howto_table
;
125 return sh_elf_howto_table
;
128 static bfd_reloc_status_type
129 sh_elf_reloc_loop (int r_type ATTRIBUTE_UNUSED
, bfd
*input_bfd
,
130 asection
*input_section
, bfd_byte
*contents
,
131 bfd_vma addr
, asection
*symbol_section
,
132 bfd_vma start
, bfd_vma end
)
134 static bfd_vma last_addr
;
135 static asection
*last_symbol_section
;
136 bfd_byte
*start_ptr
, *ptr
, *last_ptr
;
141 /* Sanity check the address. */
142 if (addr
> bfd_get_section_limit (input_bfd
, input_section
))
143 return bfd_reloc_outofrange
;
145 /* We require the start and end relocations to be processed consecutively -
146 although we allow then to be processed forwards or backwards. */
150 last_symbol_section
= symbol_section
;
153 if (last_addr
!= addr
)
157 if (! symbol_section
|| last_symbol_section
!= symbol_section
|| end
< start
)
158 return bfd_reloc_outofrange
;
160 /* Get the symbol_section contents. */
161 if (symbol_section
!= input_section
)
163 if (elf_section_data (symbol_section
)->this_hdr
.contents
!= NULL
)
164 contents
= elf_section_data (symbol_section
)->this_hdr
.contents
;
167 if (!bfd_malloc_and_get_section (input_bfd
, symbol_section
,
170 if (contents
!= NULL
)
172 return bfd_reloc_outofrange
;
176 #define IS_PPI(PTR) ((bfd_get_16 (input_bfd, (PTR)) & 0xfc00) == 0xf800)
177 start_ptr
= contents
+ start
;
178 for (cum_diff
= -6, ptr
= contents
+ end
; cum_diff
< 0 && ptr
> start_ptr
;)
180 for (last_ptr
= ptr
, ptr
-= 4; ptr
>= start_ptr
&& IS_PPI (ptr
);)
183 diff
= (last_ptr
- ptr
) >> 1;
184 cum_diff
+= diff
& 1;
187 /* Calculate the start / end values to load into rs / re minus four -
188 so that will cancel out the four we would otherwise have to add to
189 addr to get the value to subtract in order to get relative addressing. */
193 end
= (ptr
+ cum_diff
* 2) - contents
;
197 bfd_vma start0
= start
- 4;
199 while (start0
&& IS_PPI (contents
+ start0
))
201 start0
= start
- 2 - ((start
- start0
) & 2);
202 start
= start0
- cum_diff
- 2;
207 && elf_section_data (symbol_section
)->this_hdr
.contents
!= contents
)
210 insn
= bfd_get_16 (input_bfd
, contents
+ addr
);
212 x
= (insn
& 0x200 ? end
: start
) - addr
;
213 if (input_section
!= symbol_section
)
214 x
+= ((symbol_section
->output_section
->vma
+ symbol_section
->output_offset
)
215 - (input_section
->output_section
->vma
216 + input_section
->output_offset
));
218 if (x
< -128 || x
> 127)
219 return bfd_reloc_overflow
;
221 x
= (insn
& ~0xff) | (x
& 0xff);
222 bfd_put_16 (input_bfd
, (bfd_vma
) x
, contents
+ addr
);
227 /* This function is used for normal relocs. This used to be like the COFF
228 function, and is almost certainly incorrect for other ELF targets. */
230 static bfd_reloc_status_type
231 sh_elf_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol_in
,
232 void *data
, asection
*input_section
, bfd
*output_bfd
,
233 char **error_message ATTRIBUTE_UNUSED
)
237 enum elf_sh_reloc_type r_type
;
238 bfd_vma addr
= reloc_entry
->address
;
239 bfd_byte
*hit_data
= addr
+ (bfd_byte
*) data
;
241 r_type
= (enum elf_sh_reloc_type
) reloc_entry
->howto
->type
;
243 if (output_bfd
!= NULL
)
245 /* Partial linking--do nothing. */
246 reloc_entry
->address
+= input_section
->output_offset
;
250 /* Almost all relocs have to do with relaxing. If any work must be
251 done for them, it has been done in sh_relax_section. */
252 if (r_type
== R_SH_IND12W
&& (symbol_in
->flags
& BSF_LOCAL
) != 0)
255 if (symbol_in
!= NULL
256 && bfd_is_und_section (symbol_in
->section
))
257 return bfd_reloc_undefined
;
259 if (bfd_is_com_section (symbol_in
->section
))
262 sym_value
= (symbol_in
->value
+
263 symbol_in
->section
->output_section
->vma
+
264 symbol_in
->section
->output_offset
);
269 insn
= bfd_get_32 (abfd
, hit_data
);
270 insn
+= sym_value
+ reloc_entry
->addend
;
271 bfd_put_32 (abfd
, (bfd_vma
) insn
, hit_data
);
274 insn
= bfd_get_16 (abfd
, hit_data
);
275 sym_value
+= reloc_entry
->addend
;
276 sym_value
-= (input_section
->output_section
->vma
277 + input_section
->output_offset
280 sym_value
+= (insn
& 0xfff) << 1;
283 insn
= (insn
& 0xf000) | (sym_value
& 0xfff);
284 bfd_put_16 (abfd
, (bfd_vma
) insn
, hit_data
);
285 if (sym_value
< (bfd_vma
) -0x1000 || sym_value
>= 0x1000)
286 return bfd_reloc_overflow
;
296 /* This function is used for relocs which are only used for relaxing,
297 which the linker should otherwise ignore. */
299 static bfd_reloc_status_type
300 sh_elf_ignore_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
301 asymbol
*symbol ATTRIBUTE_UNUSED
,
302 void *data ATTRIBUTE_UNUSED
, asection
*input_section
,
304 char **error_message ATTRIBUTE_UNUSED
)
306 if (output_bfd
!= NULL
)
307 reloc_entry
->address
+= input_section
->output_offset
;
311 /* This structure is used to map BFD reloc codes to SH ELF relocs. */
315 bfd_reloc_code_real_type bfd_reloc_val
;
316 unsigned char elf_reloc_val
;
319 /* An array mapping BFD reloc codes to SH ELF relocs. */
321 static const struct elf_reloc_map sh_reloc_map
[] =
323 { BFD_RELOC_NONE
, R_SH_NONE
},
324 { BFD_RELOC_32
, R_SH_DIR32
},
325 { BFD_RELOC_16
, R_SH_DIR16
},
326 { BFD_RELOC_8
, R_SH_DIR8
},
327 { BFD_RELOC_CTOR
, R_SH_DIR32
},
328 { BFD_RELOC_32_PCREL
, R_SH_REL32
},
329 { BFD_RELOC_SH_PCDISP8BY2
, R_SH_DIR8WPN
},
330 { BFD_RELOC_SH_PCDISP12BY2
, R_SH_IND12W
},
331 { BFD_RELOC_SH_PCRELIMM8BY2
, R_SH_DIR8WPZ
},
332 { BFD_RELOC_SH_PCRELIMM8BY4
, R_SH_DIR8WPL
},
333 { BFD_RELOC_8_PCREL
, R_SH_SWITCH8
},
334 { BFD_RELOC_SH_SWITCH16
, R_SH_SWITCH16
},
335 { BFD_RELOC_SH_SWITCH32
, R_SH_SWITCH32
},
336 { BFD_RELOC_SH_USES
, R_SH_USES
},
337 { BFD_RELOC_SH_COUNT
, R_SH_COUNT
},
338 { BFD_RELOC_SH_ALIGN
, R_SH_ALIGN
},
339 { BFD_RELOC_SH_CODE
, R_SH_CODE
},
340 { BFD_RELOC_SH_DATA
, R_SH_DATA
},
341 { BFD_RELOC_SH_LABEL
, R_SH_LABEL
},
342 { BFD_RELOC_VTABLE_INHERIT
, R_SH_GNU_VTINHERIT
},
343 { BFD_RELOC_VTABLE_ENTRY
, R_SH_GNU_VTENTRY
},
344 { BFD_RELOC_SH_LOOP_START
, R_SH_LOOP_START
},
345 { BFD_RELOC_SH_LOOP_END
, R_SH_LOOP_END
},
346 { BFD_RELOC_SH_TLS_GD_32
, R_SH_TLS_GD_32
},
347 { BFD_RELOC_SH_TLS_LD_32
, R_SH_TLS_LD_32
},
348 { BFD_RELOC_SH_TLS_LDO_32
, R_SH_TLS_LDO_32
},
349 { BFD_RELOC_SH_TLS_IE_32
, R_SH_TLS_IE_32
},
350 { BFD_RELOC_SH_TLS_LE_32
, R_SH_TLS_LE_32
},
351 { BFD_RELOC_SH_TLS_DTPMOD32
, R_SH_TLS_DTPMOD32
},
352 { BFD_RELOC_SH_TLS_DTPOFF32
, R_SH_TLS_DTPOFF32
},
353 { BFD_RELOC_SH_TLS_TPOFF32
, R_SH_TLS_TPOFF32
},
354 { BFD_RELOC_32_GOT_PCREL
, R_SH_GOT32
},
355 { BFD_RELOC_32_PLT_PCREL
, R_SH_PLT32
},
356 { BFD_RELOC_SH_COPY
, R_SH_COPY
},
357 { BFD_RELOC_SH_GLOB_DAT
, R_SH_GLOB_DAT
},
358 { BFD_RELOC_SH_JMP_SLOT
, R_SH_JMP_SLOT
},
359 { BFD_RELOC_SH_RELATIVE
, R_SH_RELATIVE
},
360 { BFD_RELOC_32_GOTOFF
, R_SH_GOTOFF
},
361 { BFD_RELOC_SH_GOTPC
, R_SH_GOTPC
},
362 { BFD_RELOC_SH_GOTPLT32
, R_SH_GOTPLT32
},
363 { BFD_RELOC_SH_GOT20
, R_SH_GOT20
},
364 { BFD_RELOC_SH_GOTOFF20
, R_SH_GOTOFF20
},
365 { BFD_RELOC_SH_GOTFUNCDESC
, R_SH_GOTFUNCDESC
},
366 { BFD_RELOC_SH_GOTFUNCDESC20
, R_SH_GOTFUNCDESC20
},
367 { BFD_RELOC_SH_GOTOFFFUNCDESC
, R_SH_GOTOFFFUNCDESC
},
368 { BFD_RELOC_SH_GOTOFFFUNCDESC20
, R_SH_GOTOFFFUNCDESC20
},
369 { BFD_RELOC_SH_FUNCDESC
, R_SH_FUNCDESC
},
370 #ifdef INCLUDE_SHMEDIA
371 { BFD_RELOC_SH_GOT_LOW16
, R_SH_GOT_LOW16
},
372 { BFD_RELOC_SH_GOT_MEDLOW16
, R_SH_GOT_MEDLOW16
},
373 { BFD_RELOC_SH_GOT_MEDHI16
, R_SH_GOT_MEDHI16
},
374 { BFD_RELOC_SH_GOT_HI16
, R_SH_GOT_HI16
},
375 { BFD_RELOC_SH_GOTPLT_LOW16
, R_SH_GOTPLT_LOW16
},
376 { BFD_RELOC_SH_GOTPLT_MEDLOW16
, R_SH_GOTPLT_MEDLOW16
},
377 { BFD_RELOC_SH_GOTPLT_MEDHI16
, R_SH_GOTPLT_MEDHI16
},
378 { BFD_RELOC_SH_GOTPLT_HI16
, R_SH_GOTPLT_HI16
},
379 { BFD_RELOC_SH_PLT_LOW16
, R_SH_PLT_LOW16
},
380 { BFD_RELOC_SH_PLT_MEDLOW16
, R_SH_PLT_MEDLOW16
},
381 { BFD_RELOC_SH_PLT_MEDHI16
, R_SH_PLT_MEDHI16
},
382 { BFD_RELOC_SH_PLT_HI16
, R_SH_PLT_HI16
},
383 { BFD_RELOC_SH_GOTOFF_LOW16
, R_SH_GOTOFF_LOW16
},
384 { BFD_RELOC_SH_GOTOFF_MEDLOW16
, R_SH_GOTOFF_MEDLOW16
},
385 { BFD_RELOC_SH_GOTOFF_MEDHI16
, R_SH_GOTOFF_MEDHI16
},
386 { BFD_RELOC_SH_GOTOFF_HI16
, R_SH_GOTOFF_HI16
},
387 { BFD_RELOC_SH_GOTPC_LOW16
, R_SH_GOTPC_LOW16
},
388 { BFD_RELOC_SH_GOTPC_MEDLOW16
, R_SH_GOTPC_MEDLOW16
},
389 { BFD_RELOC_SH_GOTPC_MEDHI16
, R_SH_GOTPC_MEDHI16
},
390 { BFD_RELOC_SH_GOTPC_HI16
, R_SH_GOTPC_HI16
},
391 { BFD_RELOC_SH_COPY64
, R_SH_COPY64
},
392 { BFD_RELOC_SH_GLOB_DAT64
, R_SH_GLOB_DAT64
},
393 { BFD_RELOC_SH_JMP_SLOT64
, R_SH_JMP_SLOT64
},
394 { BFD_RELOC_SH_RELATIVE64
, R_SH_RELATIVE64
},
395 { BFD_RELOC_SH_GOT10BY4
, R_SH_GOT10BY4
},
396 { BFD_RELOC_SH_GOT10BY8
, R_SH_GOT10BY8
},
397 { BFD_RELOC_SH_GOTPLT10BY4
, R_SH_GOTPLT10BY4
},
398 { BFD_RELOC_SH_GOTPLT10BY8
, R_SH_GOTPLT10BY8
},
399 { BFD_RELOC_SH_PT_16
, R_SH_PT_16
},
400 { BFD_RELOC_SH_SHMEDIA_CODE
, R_SH_SHMEDIA_CODE
},
401 { BFD_RELOC_SH_IMMU5
, R_SH_DIR5U
},
402 { BFD_RELOC_SH_IMMS6
, R_SH_DIR6S
},
403 { BFD_RELOC_SH_IMMU6
, R_SH_DIR6U
},
404 { BFD_RELOC_SH_IMMS10
, R_SH_DIR10S
},
405 { BFD_RELOC_SH_IMMS10BY2
, R_SH_DIR10SW
},
406 { BFD_RELOC_SH_IMMS10BY4
, R_SH_DIR10SL
},
407 { BFD_RELOC_SH_IMMS10BY8
, R_SH_DIR10SQ
},
408 { BFD_RELOC_SH_IMMS16
, R_SH_IMMS16
},
409 { BFD_RELOC_SH_IMMU16
, R_SH_IMMU16
},
410 { BFD_RELOC_SH_IMM_LOW16
, R_SH_IMM_LOW16
},
411 { BFD_RELOC_SH_IMM_LOW16_PCREL
, R_SH_IMM_LOW16_PCREL
},
412 { BFD_RELOC_SH_IMM_MEDLOW16
, R_SH_IMM_MEDLOW16
},
413 { BFD_RELOC_SH_IMM_MEDLOW16_PCREL
, R_SH_IMM_MEDLOW16_PCREL
},
414 { BFD_RELOC_SH_IMM_MEDHI16
, R_SH_IMM_MEDHI16
},
415 { BFD_RELOC_SH_IMM_MEDHI16_PCREL
, R_SH_IMM_MEDHI16_PCREL
},
416 { BFD_RELOC_SH_IMM_HI16
, R_SH_IMM_HI16
},
417 { BFD_RELOC_SH_IMM_HI16_PCREL
, R_SH_IMM_HI16_PCREL
},
418 { BFD_RELOC_64
, R_SH_64
},
419 { BFD_RELOC_64_PCREL
, R_SH_64_PCREL
},
420 #endif /* not INCLUDE_SHMEDIA */
423 /* Given a BFD reloc code, return the howto structure for the
424 corresponding SH ELF reloc. */
426 static reloc_howto_type
*
427 sh_elf_reloc_type_lookup (bfd
*abfd
, bfd_reloc_code_real_type code
)
431 for (i
= 0; i
< sizeof (sh_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
433 if (sh_reloc_map
[i
].bfd_reloc_val
== code
)
434 return get_howto_table (abfd
) + (int) sh_reloc_map
[i
].elf_reloc_val
;
440 static reloc_howto_type
*
441 sh_elf_reloc_name_lookup (bfd
*abfd
, const char *r_name
)
445 if (vxworks_object_p (abfd
))
448 i
< (sizeof (sh_vxworks_howto_table
)
449 / sizeof (sh_vxworks_howto_table
[0]));
451 if (sh_vxworks_howto_table
[i
].name
!= NULL
452 && strcasecmp (sh_vxworks_howto_table
[i
].name
, r_name
) == 0)
453 return &sh_vxworks_howto_table
[i
];
458 i
< (sizeof (sh_elf_howto_table
)
459 / sizeof (sh_elf_howto_table
[0]));
461 if (sh_elf_howto_table
[i
].name
!= NULL
462 && strcasecmp (sh_elf_howto_table
[i
].name
, r_name
) == 0)
463 return &sh_elf_howto_table
[i
];
469 /* Given an ELF reloc, fill in the howto field of a relent. */
472 sh_elf_info_to_howto (bfd
*abfd
, arelent
*cache_ptr
, Elf_Internal_Rela
*dst
)
476 r
= ELF32_R_TYPE (dst
->r_info
);
478 BFD_ASSERT (r
< (unsigned int) R_SH_max
);
479 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC
|| r
> R_SH_LAST_INVALID_RELOC
);
480 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_2
|| r
> R_SH_LAST_INVALID_RELOC_2
);
481 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_3
|| r
> R_SH_LAST_INVALID_RELOC_3
);
482 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_4
|| r
> R_SH_LAST_INVALID_RELOC_4
);
483 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_5
|| r
> R_SH_LAST_INVALID_RELOC_5
);
484 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_6
|| r
> R_SH_LAST_INVALID_RELOC_6
);
486 cache_ptr
->howto
= get_howto_table (abfd
) + r
;
489 /* This function handles relaxing for SH ELF. See the corresponding
490 function in coff-sh.c for a description of what this does. FIXME:
491 There is a lot of duplication here between this code and the COFF
492 specific code. The format of relocs and symbols is wound deeply
493 into this code, but it would still be better if the duplication
494 could be eliminated somehow. Note in particular that although both
495 functions use symbols like R_SH_CODE, those symbols have different
496 values; in coff-sh.c they come from include/coff/sh.h, whereas here
497 they come from enum elf_sh_reloc_type in include/elf/sh.h. */
500 sh_elf_relax_section (bfd
*abfd
, asection
*sec
,
501 struct bfd_link_info
*link_info
, bfd_boolean
*again
)
503 Elf_Internal_Shdr
*symtab_hdr
;
504 Elf_Internal_Rela
*internal_relocs
;
505 bfd_boolean have_code
;
506 Elf_Internal_Rela
*irel
, *irelend
;
507 bfd_byte
*contents
= NULL
;
508 Elf_Internal_Sym
*isymbuf
= NULL
;
512 if (link_info
->relocatable
513 || (sec
->flags
& SEC_RELOC
) == 0
514 || sec
->reloc_count
== 0)
517 #ifdef INCLUDE_SHMEDIA
518 if (elf_section_data (sec
)->this_hdr
.sh_flags
519 & (SHF_SH5_ISA32
| SHF_SH5_ISA32_MIXED
))
525 symtab_hdr
= &elf_symtab_hdr (abfd
);
527 internal_relocs
= (_bfd_elf_link_read_relocs
528 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
529 link_info
->keep_memory
));
530 if (internal_relocs
== NULL
)
535 irelend
= internal_relocs
+ sec
->reloc_count
;
536 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
538 bfd_vma laddr
, paddr
, symval
;
540 Elf_Internal_Rela
*irelfn
, *irelscan
, *irelcount
;
543 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_CODE
)
546 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_USES
)
549 /* Get the section contents. */
550 if (contents
== NULL
)
552 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
553 contents
= elf_section_data (sec
)->this_hdr
.contents
;
556 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
561 /* The r_addend field of the R_SH_USES reloc will point us to
562 the register load. The 4 is because the r_addend field is
563 computed as though it were a jump offset, which are based
564 from 4 bytes after the jump instruction. */
565 laddr
= irel
->r_offset
+ 4 + irel
->r_addend
;
566 if (laddr
>= sec
->size
)
568 (*_bfd_error_handler
) (_("%B: 0x%lx: warning: bad R_SH_USES offset"),
570 (unsigned long) irel
->r_offset
);
573 insn
= bfd_get_16 (abfd
, contents
+ laddr
);
575 /* If the instruction is not mov.l NN,rN, we don't know what to
577 if ((insn
& 0xf000) != 0xd000)
579 ((*_bfd_error_handler
)
580 (_("%B: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x"),
581 abfd
, (unsigned long) irel
->r_offset
, insn
));
585 /* Get the address from which the register is being loaded. The
586 displacement in the mov.l instruction is quadrupled. It is a
587 displacement from four bytes after the movl instruction, but,
588 before adding in the PC address, two least significant bits
589 of the PC are cleared. We assume that the section is aligned
590 on a four byte boundary. */
593 paddr
+= (laddr
+ 4) &~ (bfd_vma
) 3;
594 if (paddr
>= sec
->size
)
596 ((*_bfd_error_handler
)
597 (_("%B: 0x%lx: warning: bad R_SH_USES load offset"),
598 abfd
, (unsigned long) irel
->r_offset
));
602 /* Get the reloc for the address from which the register is
603 being loaded. This reloc will tell us which function is
604 actually being called. */
605 for (irelfn
= internal_relocs
; irelfn
< irelend
; irelfn
++)
606 if (irelfn
->r_offset
== paddr
607 && ELF32_R_TYPE (irelfn
->r_info
) == (int) R_SH_DIR32
)
609 if (irelfn
>= irelend
)
611 ((*_bfd_error_handler
)
612 (_("%B: 0x%lx: warning: could not find expected reloc"),
613 abfd
, (unsigned long) paddr
));
617 /* Read this BFD's symbols if we haven't done so already. */
618 if (isymbuf
== NULL
&& symtab_hdr
->sh_info
!= 0)
620 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
622 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
623 symtab_hdr
->sh_info
, 0,
629 /* Get the value of the symbol referred to by the reloc. */
630 if (ELF32_R_SYM (irelfn
->r_info
) < symtab_hdr
->sh_info
)
632 /* A local symbol. */
633 Elf_Internal_Sym
*isym
;
635 isym
= isymbuf
+ ELF32_R_SYM (irelfn
->r_info
);
637 != (unsigned int) _bfd_elf_section_from_bfd_section (abfd
, sec
))
639 ((*_bfd_error_handler
)
640 (_("%B: 0x%lx: warning: symbol in unexpected section"),
641 abfd
, (unsigned long) paddr
));
645 symval
= (isym
->st_value
646 + sec
->output_section
->vma
647 + sec
->output_offset
);
652 struct elf_link_hash_entry
*h
;
654 indx
= ELF32_R_SYM (irelfn
->r_info
) - symtab_hdr
->sh_info
;
655 h
= elf_sym_hashes (abfd
)[indx
];
656 BFD_ASSERT (h
!= NULL
);
657 if (h
->root
.type
!= bfd_link_hash_defined
658 && h
->root
.type
!= bfd_link_hash_defweak
)
660 /* This appears to be a reference to an undefined
661 symbol. Just ignore it--it will be caught by the
662 regular reloc processing. */
666 symval
= (h
->root
.u
.def
.value
667 + h
->root
.u
.def
.section
->output_section
->vma
668 + h
->root
.u
.def
.section
->output_offset
);
671 if (get_howto_table (abfd
)[R_SH_DIR32
].partial_inplace
)
672 symval
+= bfd_get_32 (abfd
, contents
+ paddr
);
674 symval
+= irelfn
->r_addend
;
676 /* See if this function call can be shortened. */
679 + sec
->output_section
->vma
682 /* A branch to an address beyond ours might be increased by an
683 .align that doesn't move when bytes behind us are deleted.
684 So, we add some slop in this calculation to allow for
686 if (foff
< -0x1000 || foff
>= 0x1000 - 8)
688 /* After all that work, we can't shorten this function call. */
692 /* Shorten the function call. */
694 /* For simplicity of coding, we are going to modify the section
695 contents, the section relocs, and the BFD symbol table. We
696 must tell the rest of the code not to free up this
697 information. It would be possible to instead create a table
698 of changes which have to be made, as is done in coff-mips.c;
699 that would be more work, but would require less memory when
700 the linker is run. */
702 elf_section_data (sec
)->relocs
= internal_relocs
;
703 elf_section_data (sec
)->this_hdr
.contents
= contents
;
704 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
706 /* Replace the jsr with a bsr. */
708 /* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and
709 replace the jsr with a bsr. */
710 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irelfn
->r_info
), R_SH_IND12W
);
711 /* We used to test (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
712 here, but that only checks if the symbol is an external symbol,
713 not if the symbol is in a different section. Besides, we need
714 a consistent meaning for the relocation, so we just assume here that
715 the value of the symbol is not available. */
717 /* We can't fully resolve this yet, because the external
718 symbol value may be changed by future relaxing. We let
719 the final link phase handle it. */
720 bfd_put_16 (abfd
, (bfd_vma
) 0xb000, contents
+ irel
->r_offset
);
724 /* When we calculated the symbol "value" we had an offset in the
725 DIR32's word in memory (we read and add it above). However,
726 the jsr we create does NOT have this offset encoded, so we
727 have to add it to the addend to preserve it. */
728 irel
->r_addend
+= bfd_get_32 (abfd
, contents
+ paddr
);
730 /* See if there is another R_SH_USES reloc referring to the same
732 for (irelscan
= internal_relocs
; irelscan
< irelend
; irelscan
++)
733 if (ELF32_R_TYPE (irelscan
->r_info
) == (int) R_SH_USES
734 && laddr
== irelscan
->r_offset
+ 4 + irelscan
->r_addend
)
736 if (irelscan
< irelend
)
738 /* Some other function call depends upon this register load,
739 and we have not yet converted that function call.
740 Indeed, we may never be able to convert it. There is
741 nothing else we can do at this point. */
745 /* Look for a R_SH_COUNT reloc on the location where the
746 function address is stored. Do this before deleting any
747 bytes, to avoid confusion about the address. */
748 for (irelcount
= internal_relocs
; irelcount
< irelend
; irelcount
++)
749 if (irelcount
->r_offset
== paddr
750 && ELF32_R_TYPE (irelcount
->r_info
) == (int) R_SH_COUNT
)
753 /* Delete the register load. */
754 if (! sh_elf_relax_delete_bytes (abfd
, sec
, laddr
, 2))
757 /* That will change things, so, just in case it permits some
758 other function call to come within range, we should relax
759 again. Note that this is not required, and it may be slow. */
762 /* Now check whether we got a COUNT reloc. */
763 if (irelcount
>= irelend
)
765 ((*_bfd_error_handler
)
766 (_("%B: 0x%lx: warning: could not find expected COUNT reloc"),
767 abfd
, (unsigned long) paddr
));
771 /* The number of uses is stored in the r_addend field. We've
773 if (irelcount
->r_addend
== 0)
775 ((*_bfd_error_handler
) (_("%B: 0x%lx: warning: bad count"),
777 (unsigned long) paddr
));
781 --irelcount
->r_addend
;
783 /* If there are no more uses, we can delete the address. Reload
784 the address from irelfn, in case it was changed by the
785 previous call to sh_elf_relax_delete_bytes. */
786 if (irelcount
->r_addend
== 0)
788 if (! sh_elf_relax_delete_bytes (abfd
, sec
, irelfn
->r_offset
, 4))
792 /* We've done all we can with that function call. */
795 /* Look for load and store instructions that we can align on four
797 if ((elf_elfheader (abfd
)->e_flags
& EF_SH_MACH_MASK
) != EF_SH4
802 /* Get the section contents. */
803 if (contents
== NULL
)
805 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
806 contents
= elf_section_data (sec
)->this_hdr
.contents
;
809 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
814 if (! sh_elf_align_loads (abfd
, sec
, internal_relocs
, contents
,
820 elf_section_data (sec
)->relocs
= internal_relocs
;
821 elf_section_data (sec
)->this_hdr
.contents
= contents
;
822 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
827 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
829 if (! link_info
->keep_memory
)
833 /* Cache the symbols for elf_link_input_bfd. */
834 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
839 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
841 if (! link_info
->keep_memory
)
845 /* Cache the section contents for elf_link_input_bfd. */
846 elf_section_data (sec
)->this_hdr
.contents
= contents
;
850 if (internal_relocs
!= NULL
851 && elf_section_data (sec
)->relocs
!= internal_relocs
)
852 free (internal_relocs
);
858 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
861 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
863 if (internal_relocs
!= NULL
864 && elf_section_data (sec
)->relocs
!= internal_relocs
)
865 free (internal_relocs
);
870 /* Delete some bytes from a section while relaxing. FIXME: There is a
871 lot of duplication between this function and sh_relax_delete_bytes
875 sh_elf_relax_delete_bytes (bfd
*abfd
, asection
*sec
, bfd_vma addr
,
878 Elf_Internal_Shdr
*symtab_hdr
;
879 unsigned int sec_shndx
;
881 Elf_Internal_Rela
*irel
, *irelend
;
882 Elf_Internal_Rela
*irelalign
;
884 Elf_Internal_Sym
*isymbuf
, *isym
, *isymend
;
885 struct elf_link_hash_entry
**sym_hashes
;
886 struct elf_link_hash_entry
**end_hashes
;
887 unsigned int symcount
;
890 symtab_hdr
= &elf_symtab_hdr (abfd
);
891 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
893 sec_shndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
895 contents
= elf_section_data (sec
)->this_hdr
.contents
;
897 /* The deletion must stop at the next ALIGN reloc for an aligment
898 power larger than the number of bytes we are deleting. */
903 irel
= elf_section_data (sec
)->relocs
;
904 irelend
= irel
+ sec
->reloc_count
;
905 for (; irel
< irelend
; irel
++)
907 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_ALIGN
908 && irel
->r_offset
> addr
909 && count
< (1 << irel
->r_addend
))
912 toaddr
= irel
->r_offset
;
917 /* Actually delete the bytes. */
918 memmove (contents
+ addr
, contents
+ addr
+ count
,
919 (size_t) (toaddr
- addr
- count
));
920 if (irelalign
== NULL
)
926 #define NOP_OPCODE (0x0009)
928 BFD_ASSERT ((count
& 1) == 0);
929 for (i
= 0; i
< count
; i
+= 2)
930 bfd_put_16 (abfd
, (bfd_vma
) NOP_OPCODE
, contents
+ toaddr
- count
+ i
);
933 /* Adjust all the relocs. */
934 for (irel
= elf_section_data (sec
)->relocs
; irel
< irelend
; irel
++)
936 bfd_vma nraddr
, stop
;
939 int off
, adjust
, oinsn
;
940 bfd_signed_vma voff
= 0;
941 bfd_boolean overflow
;
943 /* Get the new reloc address. */
944 nraddr
= irel
->r_offset
;
945 if ((irel
->r_offset
> addr
946 && irel
->r_offset
< toaddr
)
947 || (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_ALIGN
948 && irel
->r_offset
== toaddr
))
951 /* See if this reloc was for the bytes we have deleted, in which
952 case we no longer care about it. Don't delete relocs which
953 represent addresses, though. */
954 if (irel
->r_offset
>= addr
955 && irel
->r_offset
< addr
+ count
956 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_ALIGN
957 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_CODE
958 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_DATA
959 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_LABEL
)
960 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
963 /* If this is a PC relative reloc, see if the range it covers
964 includes the bytes we have deleted. */
965 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
974 start
= irel
->r_offset
;
975 insn
= bfd_get_16 (abfd
, contents
+ nraddr
);
979 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
986 /* If this reloc is against a symbol defined in this
987 section, and the symbol will not be adjusted below, we
988 must check the addend to see it will put the value in
989 range to be adjusted, and hence must be changed. */
990 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
992 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
993 if (isym
->st_shndx
== sec_shndx
994 && (isym
->st_value
<= addr
995 || isym
->st_value
>= toaddr
))
999 if (get_howto_table (abfd
)[R_SH_DIR32
].partial_inplace
)
1001 val
= bfd_get_32 (abfd
, contents
+ nraddr
);
1002 val
+= isym
->st_value
;
1003 if (val
> addr
&& val
< toaddr
)
1004 bfd_put_32 (abfd
, val
- count
, contents
+ nraddr
);
1008 val
= isym
->st_value
+ irel
->r_addend
;
1009 if (val
> addr
&& val
< toaddr
)
1010 irel
->r_addend
-= count
;
1014 start
= stop
= addr
;
1021 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ 4 + off
* 2);
1028 /* This has been made by previous relaxation. Since the
1029 relocation will be against an external symbol, the
1030 final relocation will just do the right thing. */
1031 start
= stop
= addr
;
1037 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ 4 + off
* 2);
1039 /* The addend will be against the section symbol, thus
1040 for adjusting the addend, the relevant start is the
1041 start of the section.
1042 N.B. If we want to abandon in-place changes here and
1043 test directly using symbol + addend, we have to take into
1044 account that the addend has already been adjusted by -4. */
1045 if (stop
> addr
&& stop
< toaddr
)
1046 irel
->r_addend
-= count
;
1052 stop
= start
+ 4 + off
* 2;
1057 stop
= (start
& ~(bfd_vma
) 3) + 4 + off
* 4;
1063 /* These relocs types represent
1065 The r_addend field holds the difference between the reloc
1066 address and L1. That is the start of the reloc, and
1067 adding in the contents gives us the top. We must adjust
1068 both the r_offset field and the section contents.
1069 N.B. in gas / coff bfd, the elf bfd r_addend is called r_offset,
1070 and the elf bfd r_offset is called r_vaddr. */
1072 stop
= irel
->r_offset
;
1073 start
= (bfd_vma
) ((bfd_signed_vma
) stop
- (long) irel
->r_addend
);
1077 && (stop
<= addr
|| stop
>= toaddr
))
1078 irel
->r_addend
+= count
;
1079 else if (stop
> addr
1081 && (start
<= addr
|| start
>= toaddr
))
1082 irel
->r_addend
-= count
;
1084 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_SWITCH16
)
1085 voff
= bfd_get_signed_16 (abfd
, contents
+ nraddr
);
1086 else if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_SWITCH8
)
1087 voff
= bfd_get_8 (abfd
, contents
+ nraddr
);
1089 voff
= bfd_get_signed_32 (abfd
, contents
+ nraddr
);
1090 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ voff
);
1095 start
= irel
->r_offset
;
1096 stop
= (bfd_vma
) ((bfd_signed_vma
) start
1097 + (long) irel
->r_addend
1104 && (stop
<= addr
|| stop
>= toaddr
))
1106 else if (stop
> addr
1108 && (start
<= addr
|| start
>= toaddr
))
1117 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
1126 if ((oinsn
& 0xff00) != (insn
& 0xff00))
1128 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
1133 if ((oinsn
& 0xf000) != (insn
& 0xf000))
1135 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
1139 BFD_ASSERT (adjust
== count
|| count
>= 4);
1144 if ((irel
->r_offset
& 3) == 0)
1147 if ((oinsn
& 0xff00) != (insn
& 0xff00))
1149 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
1154 if (voff
< 0 || voff
>= 0xff)
1156 bfd_put_8 (abfd
, voff
, contents
+ nraddr
);
1161 if (voff
< - 0x8000 || voff
>= 0x8000)
1163 bfd_put_signed_16 (abfd
, (bfd_vma
) voff
, contents
+ nraddr
);
1168 bfd_put_signed_32 (abfd
, (bfd_vma
) voff
, contents
+ nraddr
);
1172 irel
->r_addend
+= adjust
;
1178 ((*_bfd_error_handler
)
1179 (_("%B: 0x%lx: fatal: reloc overflow while relaxing"),
1180 abfd
, (unsigned long) irel
->r_offset
));
1181 bfd_set_error (bfd_error_bad_value
);
1186 irel
->r_offset
= nraddr
;
1189 /* Look through all the other sections. If there contain any IMM32
1190 relocs against internal symbols which we are not going to adjust
1191 below, we may need to adjust the addends. */
1192 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
1194 Elf_Internal_Rela
*internal_relocs
;
1195 Elf_Internal_Rela
*irelscan
, *irelscanend
;
1196 bfd_byte
*ocontents
;
1199 || (o
->flags
& SEC_RELOC
) == 0
1200 || o
->reloc_count
== 0)
1203 /* We always cache the relocs. Perhaps, if info->keep_memory is
1204 FALSE, we should free them, if we are permitted to, when we
1205 leave sh_coff_relax_section. */
1206 internal_relocs
= (_bfd_elf_link_read_relocs
1207 (abfd
, o
, NULL
, (Elf_Internal_Rela
*) NULL
, TRUE
));
1208 if (internal_relocs
== NULL
)
1212 irelscanend
= internal_relocs
+ o
->reloc_count
;
1213 for (irelscan
= internal_relocs
; irelscan
< irelscanend
; irelscan
++)
1215 /* Dwarf line numbers use R_SH_SWITCH32 relocs. */
1216 if (ELF32_R_TYPE (irelscan
->r_info
) == (int) R_SH_SWITCH32
)
1218 bfd_vma start
, stop
;
1219 bfd_signed_vma voff
;
1221 if (ocontents
== NULL
)
1223 if (elf_section_data (o
)->this_hdr
.contents
!= NULL
)
1224 ocontents
= elf_section_data (o
)->this_hdr
.contents
;
1227 /* We always cache the section contents.
1228 Perhaps, if info->keep_memory is FALSE, we
1229 should free them, if we are permitted to,
1230 when we leave sh_coff_relax_section. */
1231 if (!bfd_malloc_and_get_section (abfd
, o
, &ocontents
))
1233 if (ocontents
!= NULL
)
1238 elf_section_data (o
)->this_hdr
.contents
= ocontents
;
1242 stop
= irelscan
->r_offset
;
1244 = (bfd_vma
) ((bfd_signed_vma
) stop
- (long) irelscan
->r_addend
);
1246 /* STOP is in a different section, so it won't change. */
1247 if (start
> addr
&& start
< toaddr
)
1248 irelscan
->r_addend
+= count
;
1250 voff
= bfd_get_signed_32 (abfd
, ocontents
+ irelscan
->r_offset
);
1251 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ voff
);
1255 && (stop
<= addr
|| stop
>= toaddr
))
1256 bfd_put_signed_32 (abfd
, (bfd_vma
) voff
+ count
,
1257 ocontents
+ irelscan
->r_offset
);
1258 else if (stop
> addr
1260 && (start
<= addr
|| start
>= toaddr
))
1261 bfd_put_signed_32 (abfd
, (bfd_vma
) voff
- count
,
1262 ocontents
+ irelscan
->r_offset
);
1265 if (ELF32_R_TYPE (irelscan
->r_info
) != (int) R_SH_DIR32
)
1268 if (ELF32_R_SYM (irelscan
->r_info
) >= symtab_hdr
->sh_info
)
1272 isym
= isymbuf
+ ELF32_R_SYM (irelscan
->r_info
);
1273 if (isym
->st_shndx
== sec_shndx
1274 && (isym
->st_value
<= addr
1275 || isym
->st_value
>= toaddr
))
1279 if (ocontents
== NULL
)
1281 if (elf_section_data (o
)->this_hdr
.contents
!= NULL
)
1282 ocontents
= elf_section_data (o
)->this_hdr
.contents
;
1285 /* We always cache the section contents.
1286 Perhaps, if info->keep_memory is FALSE, we
1287 should free them, if we are permitted to,
1288 when we leave sh_coff_relax_section. */
1289 if (!bfd_malloc_and_get_section (abfd
, o
, &ocontents
))
1291 if (ocontents
!= NULL
)
1296 elf_section_data (o
)->this_hdr
.contents
= ocontents
;
1300 val
= bfd_get_32 (abfd
, ocontents
+ irelscan
->r_offset
);
1301 val
+= isym
->st_value
;
1302 if (val
> addr
&& val
< toaddr
)
1303 bfd_put_32 (abfd
, val
- count
,
1304 ocontents
+ irelscan
->r_offset
);
1309 /* Adjust the local symbols defined in this section. */
1310 isymend
= isymbuf
+ symtab_hdr
->sh_info
;
1311 for (isym
= isymbuf
; isym
< isymend
; isym
++)
1313 if (isym
->st_shndx
== sec_shndx
1314 && isym
->st_value
> addr
1315 && isym
->st_value
< toaddr
)
1316 isym
->st_value
-= count
;
1319 /* Now adjust the global symbols defined in this section. */
1320 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
1321 - symtab_hdr
->sh_info
);
1322 sym_hashes
= elf_sym_hashes (abfd
);
1323 end_hashes
= sym_hashes
+ symcount
;
1324 for (; sym_hashes
< end_hashes
; sym_hashes
++)
1326 struct elf_link_hash_entry
*sym_hash
= *sym_hashes
;
1327 if ((sym_hash
->root
.type
== bfd_link_hash_defined
1328 || sym_hash
->root
.type
== bfd_link_hash_defweak
)
1329 && sym_hash
->root
.u
.def
.section
== sec
1330 && sym_hash
->root
.u
.def
.value
> addr
1331 && sym_hash
->root
.u
.def
.value
< toaddr
)
1333 sym_hash
->root
.u
.def
.value
-= count
;
1337 /* See if we can move the ALIGN reloc forward. We have adjusted
1338 r_offset for it already. */
1339 if (irelalign
!= NULL
)
1341 bfd_vma alignto
, alignaddr
;
1343 alignto
= BFD_ALIGN (toaddr
, 1 << irelalign
->r_addend
);
1344 alignaddr
= BFD_ALIGN (irelalign
->r_offset
,
1345 1 << irelalign
->r_addend
);
1346 if (alignto
!= alignaddr
)
1348 /* Tail recursion. */
1349 return sh_elf_relax_delete_bytes (abfd
, sec
, alignaddr
,
1350 (int) (alignto
- alignaddr
));
1357 /* Look for loads and stores which we can align to four byte
1358 boundaries. This is like sh_align_loads in coff-sh.c. */
1361 sh_elf_align_loads (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
,
1362 Elf_Internal_Rela
*internal_relocs
,
1363 bfd_byte
*contents ATTRIBUTE_UNUSED
,
1364 bfd_boolean
*pswapped
)
1366 Elf_Internal_Rela
*irel
, *irelend
;
1367 bfd_vma
*labels
= NULL
;
1368 bfd_vma
*label
, *label_end
;
1373 irelend
= internal_relocs
+ sec
->reloc_count
;
1375 /* Get all the addresses with labels on them. */
1376 amt
= sec
->reloc_count
;
1377 amt
*= sizeof (bfd_vma
);
1378 labels
= (bfd_vma
*) bfd_malloc (amt
);
1382 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
1384 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_LABEL
)
1386 *label_end
= irel
->r_offset
;
1391 /* Note that the assembler currently always outputs relocs in
1392 address order. If that ever changes, this code will need to sort
1393 the label values and the relocs. */
1397 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
1399 bfd_vma start
, stop
;
1401 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_CODE
)
1404 start
= irel
->r_offset
;
1406 for (irel
++; irel
< irelend
; irel
++)
1407 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_DATA
)
1410 stop
= irel
->r_offset
;
1414 if (! _bfd_sh_align_load_span (abfd
, sec
, contents
, sh_elf_swap_insns
,
1415 internal_relocs
, &label
,
1416 label_end
, start
, stop
, pswapped
))
1431 /* Swap two SH instructions. This is like sh_swap_insns in coff-sh.c. */
1434 sh_elf_swap_insns (bfd
*abfd
, asection
*sec
, void *relocs
,
1435 bfd_byte
*contents
, bfd_vma addr
)
1437 Elf_Internal_Rela
*internal_relocs
= (Elf_Internal_Rela
*) relocs
;
1438 unsigned short i1
, i2
;
1439 Elf_Internal_Rela
*irel
, *irelend
;
1441 /* Swap the instructions themselves. */
1442 i1
= bfd_get_16 (abfd
, contents
+ addr
);
1443 i2
= bfd_get_16 (abfd
, contents
+ addr
+ 2);
1444 bfd_put_16 (abfd
, (bfd_vma
) i2
, contents
+ addr
);
1445 bfd_put_16 (abfd
, (bfd_vma
) i1
, contents
+ addr
+ 2);
1447 /* Adjust all reloc addresses. */
1448 irelend
= internal_relocs
+ sec
->reloc_count
;
1449 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
1451 enum elf_sh_reloc_type type
;
1454 /* There are a few special types of relocs that we don't want to
1455 adjust. These relocs do not apply to the instruction itself,
1456 but are only associated with the address. */
1457 type
= (enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
);
1458 if (type
== R_SH_ALIGN
1459 || type
== R_SH_CODE
1460 || type
== R_SH_DATA
1461 || type
== R_SH_LABEL
)
1464 /* If an R_SH_USES reloc points to one of the addresses being
1465 swapped, we must adjust it. It would be incorrect to do this
1466 for a jump, though, since we want to execute both
1467 instructions after the jump. (We have avoided swapping
1468 around a label, so the jump will not wind up executing an
1469 instruction it shouldn't). */
1470 if (type
== R_SH_USES
)
1474 off
= irel
->r_offset
+ 4 + irel
->r_addend
;
1476 irel
->r_offset
+= 2;
1477 else if (off
== addr
+ 2)
1478 irel
->r_offset
-= 2;
1481 if (irel
->r_offset
== addr
)
1483 irel
->r_offset
+= 2;
1486 else if (irel
->r_offset
== addr
+ 2)
1488 irel
->r_offset
-= 2;
1497 unsigned short insn
, oinsn
;
1498 bfd_boolean overflow
;
1500 loc
= contents
+ irel
->r_offset
;
1509 insn
= bfd_get_16 (abfd
, loc
);
1512 if ((oinsn
& 0xff00) != (insn
& 0xff00))
1514 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
1518 insn
= bfd_get_16 (abfd
, loc
);
1521 if ((oinsn
& 0xf000) != (insn
& 0xf000))
1523 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
1527 /* This reloc ignores the least significant 3 bits of
1528 the program counter before adding in the offset.
1529 This means that if ADDR is at an even address, the
1530 swap will not affect the offset. If ADDR is an at an
1531 odd address, then the instruction will be crossing a
1532 four byte boundary, and must be adjusted. */
1533 if ((addr
& 3) != 0)
1535 insn
= bfd_get_16 (abfd
, loc
);
1538 if ((oinsn
& 0xff00) != (insn
& 0xff00))
1540 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
1548 ((*_bfd_error_handler
)
1549 (_("%B: 0x%lx: fatal: reloc overflow while relaxing"),
1550 abfd
, (unsigned long) irel
->r_offset
));
1551 bfd_set_error (bfd_error_bad_value
);
1559 #endif /* defined SH64_ELF */
1561 /* Describes one of the various PLT styles. */
1563 struct elf_sh_plt_info
1565 /* The template for the first PLT entry, or NULL if there is no special
1567 const bfd_byte
*plt0_entry
;
1569 /* The size of PLT0_ENTRY in bytes, or 0 if PLT0_ENTRY is NULL. */
1570 bfd_vma plt0_entry_size
;
1572 /* Index I is the offset into PLT0_ENTRY of a pointer to
1573 _GLOBAL_OFFSET_TABLE_ + I * 4. The value is MINUS_ONE
1574 if there is no such pointer. */
1575 bfd_vma plt0_got_fields
[3];
1577 /* The template for a symbol's PLT entry. */
1578 const bfd_byte
*symbol_entry
;
1580 /* The size of SYMBOL_ENTRY in bytes. */
1581 bfd_vma symbol_entry_size
;
1583 /* Byte offsets of fields in SYMBOL_ENTRY. Not all fields are used
1584 on all targets. The comments by each member indicate the value
1585 that the field must hold. */
1587 bfd_vma got_entry
; /* the address of the symbol's .got.plt entry */
1588 bfd_vma plt
; /* .plt (or a branch to .plt on VxWorks) */
1589 bfd_vma reloc_offset
; /* the offset of the symbol's JMP_SLOT reloc */
1590 bfd_boolean got20
; /* TRUE if got_entry points to a movi20
1591 instruction (instead of a constant pool
1595 /* The offset of the resolver stub from the start of SYMBOL_ENTRY. */
1596 bfd_vma symbol_resolve_offset
;
1598 /* A different PLT layout which can be used for the first
1599 MAX_SHORT_PLT entries. It must share the same plt0. NULL in
1601 const struct elf_sh_plt_info
*short_plt
;
1604 #ifdef INCLUDE_SHMEDIA
1606 /* The size in bytes of an entry in the procedure linkage table. */
1608 #define ELF_PLT_ENTRY_SIZE 64
1610 /* First entry in an absolute procedure linkage table look like this. */
1612 static const bfd_byte elf_sh_plt0_entry_be
[ELF_PLT_ENTRY_SIZE
] =
1614 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 16, r17 */
1615 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
1616 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
1617 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
1618 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
1619 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
1620 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1621 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1622 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1623 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1624 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1625 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1626 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1627 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1628 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1629 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1632 static const bfd_byte elf_sh_plt0_entry_le
[ELF_PLT_ENTRY_SIZE
] =
1634 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */
1635 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
1636 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
1637 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
1638 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
1639 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
1640 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1641 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1642 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1643 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1644 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1645 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1646 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1647 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1648 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1649 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1652 /* Sebsequent entries in an absolute procedure linkage table look like
1655 static const bfd_byte elf_sh_plt_entry_be
[ELF_PLT_ENTRY_SIZE
] =
1657 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 16, r25 */
1658 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
1659 0x89, 0x90, 0x01, 0x90, /* ld.l r25, 0, r25 */
1660 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
1661 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
1662 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1663 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1664 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1665 0xcc, 0x00, 0x01, 0x90, /* movi .PLT0 >> 16, r25 */
1666 0xc8, 0x00, 0x01, 0x90, /* shori .PLT0 & 65535, r25 */
1667 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
1668 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
1669 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
1670 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
1671 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1672 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1675 static const bfd_byte elf_sh_plt_entry_le
[ELF_PLT_ENTRY_SIZE
] =
1677 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */
1678 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
1679 0x90, 0x01, 0x90, 0x89, /* ld.l r25, 0, r25 */
1680 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
1681 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
1682 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1683 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1684 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1685 0x90, 0x01, 0x00, 0xcc, /* movi .PLT0 >> 16, r25 */
1686 0x90, 0x01, 0x00, 0xc8, /* shori .PLT0 & 65535, r25 */
1687 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
1688 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
1689 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
1690 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
1691 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1692 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1695 /* Entries in a PIC procedure linkage table look like this. */
1697 static const bfd_byte elf_sh_pic_plt_entry_be
[ELF_PLT_ENTRY_SIZE
] =
1699 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */
1700 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
1701 0x40, 0xc2, 0x65, 0x90, /* ldx.l r12, r25, r25 */
1702 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
1703 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
1704 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1705 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1706 0x6f, 0xf0, 0xff, 0xf0, /* nop */
1707 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */
1708 0x00, 0xc8, 0x45, 0x10, /* add.l r12, r17, r17 */
1709 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
1710 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
1711 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
1712 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
1713 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
1714 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
1717 static const bfd_byte elf_sh_pic_plt_entry_le
[ELF_PLT_ENTRY_SIZE
] =
1719 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */
1720 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
1721 0x90, 0x65, 0xc2, 0x40, /* ldx.l r12, r25, r25 */
1722 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
1723 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
1724 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1725 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1726 0xf0, 0xff, 0xf0, 0x6f, /* nop */
1727 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */
1728 0x10, 0x45, 0xc8, 0x00, /* add.l r12, r17, r17 */
1729 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
1730 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
1731 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
1732 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
1733 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
1734 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
1737 static const struct elf_sh_plt_info elf_sh_plts
[2][2] = {
1740 /* Big-endian non-PIC. */
1741 elf_sh_plt0_entry_be
,
1743 { 0, MINUS_ONE
, MINUS_ONE
},
1744 elf_sh_plt_entry_be
,
1746 { 0, 32, 48, FALSE
},
1747 33, /* includes ISA encoding */
1751 /* Little-endian non-PIC. */
1752 elf_sh_plt0_entry_le
,
1754 { 0, MINUS_ONE
, MINUS_ONE
},
1755 elf_sh_plt_entry_le
,
1757 { 0, 32, 48, FALSE
},
1758 33, /* includes ISA encoding */
1764 /* Big-endian PIC. */
1765 elf_sh_plt0_entry_be
,
1767 { MINUS_ONE
, MINUS_ONE
, MINUS_ONE
},
1768 elf_sh_pic_plt_entry_be
,
1770 { 0, MINUS_ONE
, 52, FALSE
},
1771 33, /* includes ISA encoding */
1775 /* Little-endian PIC. */
1776 elf_sh_plt0_entry_le
,
1778 { MINUS_ONE
, MINUS_ONE
, MINUS_ONE
},
1779 elf_sh_pic_plt_entry_le
,
1781 { 0, MINUS_ONE
, 52, FALSE
},
1782 33, /* includes ISA encoding */
1788 /* Return offset of the linker in PLT0 entry. */
1789 #define elf_sh_plt0_gotplt_offset(info) 0
1791 /* Install a 32-bit PLT field starting at ADDR, which occurs in OUTPUT_BFD.
1792 VALUE is the field's value and CODE_P is true if VALUE refers to code,
1795 On SH64, each 32-bit field is loaded by a movi/shori pair. */
1798 install_plt_field (bfd
*output_bfd
, bfd_boolean code_p
,
1799 unsigned long value
, bfd_byte
*addr
)
1802 bfd_put_32 (output_bfd
,
1803 bfd_get_32 (output_bfd
, addr
)
1804 | ((value
>> 6) & 0x3fffc00),
1806 bfd_put_32 (output_bfd
,
1807 bfd_get_32 (output_bfd
, addr
+ 4)
1808 | ((value
<< 10) & 0x3fffc00),
1812 /* Return the type of PLT associated with ABFD. PIC_P is true if
1813 the object is position-independent. */
1815 static const struct elf_sh_plt_info
*
1816 get_plt_info (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_boolean pic_p
)
1818 return &elf_sh_plts
[pic_p
][!bfd_big_endian (abfd
)];
1821 /* The size in bytes of an entry in the procedure linkage table. */
1823 #define ELF_PLT_ENTRY_SIZE 28
1825 /* First entry in an absolute procedure linkage table look like this. */
1827 /* Note - this code has been "optimised" not to use r2. r2 is used by
1828 GCC to return the address of large structures, so it should not be
1829 corrupted here. This does mean however, that this PLT does not conform
1830 to the SH PIC ABI. That spec says that r0 contains the type of the PLT
1831 and r2 contains the GOT id. This version stores the GOT id in r0 and
1832 ignores the type. Loaders can easily detect this difference however,
1833 since the type will always be 0 or 8, and the GOT ids will always be
1834 greater than or equal to 12. */
1835 static const bfd_byte elf_sh_plt0_entry_be
[ELF_PLT_ENTRY_SIZE
] =
1837 0xd0, 0x05, /* mov.l 2f,r0 */
1838 0x60, 0x02, /* mov.l @r0,r0 */
1839 0x2f, 0x06, /* mov.l r0,@-r15 */
1840 0xd0, 0x03, /* mov.l 1f,r0 */
1841 0x60, 0x02, /* mov.l @r0,r0 */
1842 0x40, 0x2b, /* jmp @r0 */
1843 0x60, 0xf6, /* mov.l @r15+,r0 */
1844 0x00, 0x09, /* nop */
1845 0x00, 0x09, /* nop */
1846 0x00, 0x09, /* nop */
1847 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
1848 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
1851 static const bfd_byte elf_sh_plt0_entry_le
[ELF_PLT_ENTRY_SIZE
] =
1853 0x05, 0xd0, /* mov.l 2f,r0 */
1854 0x02, 0x60, /* mov.l @r0,r0 */
1855 0x06, 0x2f, /* mov.l r0,@-r15 */
1856 0x03, 0xd0, /* mov.l 1f,r0 */
1857 0x02, 0x60, /* mov.l @r0,r0 */
1858 0x2b, 0x40, /* jmp @r0 */
1859 0xf6, 0x60, /* mov.l @r15+,r0 */
1860 0x09, 0x00, /* nop */
1861 0x09, 0x00, /* nop */
1862 0x09, 0x00, /* nop */
1863 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
1864 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
1867 /* Sebsequent entries in an absolute procedure linkage table look like
1870 static const bfd_byte elf_sh_plt_entry_be
[ELF_PLT_ENTRY_SIZE
] =
1872 0xd0, 0x04, /* mov.l 1f,r0 */
1873 0x60, 0x02, /* mov.l @(r0,r12),r0 */
1874 0xd1, 0x02, /* mov.l 0f,r1 */
1875 0x40, 0x2b, /* jmp @r0 */
1876 0x60, 0x13, /* mov r1,r0 */
1877 0xd1, 0x03, /* mov.l 2f,r1 */
1878 0x40, 0x2b, /* jmp @r0 */
1879 0x00, 0x09, /* nop */
1880 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
1881 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
1882 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
1885 static const bfd_byte elf_sh_plt_entry_le
[ELF_PLT_ENTRY_SIZE
] =
1887 0x04, 0xd0, /* mov.l 1f,r0 */
1888 0x02, 0x60, /* mov.l @r0,r0 */
1889 0x02, 0xd1, /* mov.l 0f,r1 */
1890 0x2b, 0x40, /* jmp @r0 */
1891 0x13, 0x60, /* mov r1,r0 */
1892 0x03, 0xd1, /* mov.l 2f,r1 */
1893 0x2b, 0x40, /* jmp @r0 */
1894 0x09, 0x00, /* nop */
1895 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
1896 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
1897 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
1900 /* Entries in a PIC procedure linkage table look like this. */
1902 static const bfd_byte elf_sh_pic_plt_entry_be
[ELF_PLT_ENTRY_SIZE
] =
1904 0xd0, 0x04, /* mov.l 1f,r0 */
1905 0x00, 0xce, /* mov.l @(r0,r12),r0 */
1906 0x40, 0x2b, /* jmp @r0 */
1907 0x00, 0x09, /* nop */
1908 0x50, 0xc2, /* mov.l @(8,r12),r0 */
1909 0xd1, 0x03, /* mov.l 2f,r1 */
1910 0x40, 0x2b, /* jmp @r0 */
1911 0x50, 0xc1, /* mov.l @(4,r12),r0 */
1912 0x00, 0x09, /* nop */
1913 0x00, 0x09, /* nop */
1914 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
1915 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
1918 static const bfd_byte elf_sh_pic_plt_entry_le
[ELF_PLT_ENTRY_SIZE
] =
1920 0x04, 0xd0, /* mov.l 1f,r0 */
1921 0xce, 0x00, /* mov.l @(r0,r12),r0 */
1922 0x2b, 0x40, /* jmp @r0 */
1923 0x09, 0x00, /* nop */
1924 0xc2, 0x50, /* mov.l @(8,r12),r0 */
1925 0x03, 0xd1, /* mov.l 2f,r1 */
1926 0x2b, 0x40, /* jmp @r0 */
1927 0xc1, 0x50, /* mov.l @(4,r12),r0 */
1928 0x09, 0x00, /* nop */
1929 0x09, 0x00, /* nop */
1930 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
1931 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
1934 static const struct elf_sh_plt_info elf_sh_plts
[2][2] = {
1937 /* Big-endian non-PIC. */
1938 elf_sh_plt0_entry_be
,
1940 { MINUS_ONE
, 24, 20 },
1941 elf_sh_plt_entry_be
,
1943 { 20, 16, 24, FALSE
},
1948 /* Little-endian non-PIC. */
1949 elf_sh_plt0_entry_le
,
1951 { MINUS_ONE
, 24, 20 },
1952 elf_sh_plt_entry_le
,
1954 { 20, 16, 24, FALSE
},
1961 /* Big-endian PIC. */
1962 elf_sh_plt0_entry_be
,
1964 { MINUS_ONE
, MINUS_ONE
, MINUS_ONE
},
1965 elf_sh_pic_plt_entry_be
,
1967 { 20, MINUS_ONE
, 24, FALSE
},
1972 /* Little-endian PIC. */
1973 elf_sh_plt0_entry_le
,
1975 { MINUS_ONE
, MINUS_ONE
, MINUS_ONE
},
1976 elf_sh_pic_plt_entry_le
,
1978 { 20, MINUS_ONE
, 24, FALSE
},
1985 #define VXWORKS_PLT_HEADER_SIZE 12
1986 #define VXWORKS_PLT_ENTRY_SIZE 24
1988 static const bfd_byte vxworks_sh_plt0_entry_be
[VXWORKS_PLT_HEADER_SIZE
] =
1990 0xd1, 0x01, /* mov.l @(8,pc),r1 */
1991 0x61, 0x12, /* mov.l @r1,r1 */
1992 0x41, 0x2b, /* jmp @r1 */
1993 0x00, 0x09, /* nop */
1994 0, 0, 0, 0 /* 0: replaced with _GLOBAL_OFFSET_TABLE+8. */
1997 static const bfd_byte vxworks_sh_plt0_entry_le
[VXWORKS_PLT_HEADER_SIZE
] =
1999 0x01, 0xd1, /* mov.l @(8,pc),r1 */
2000 0x12, 0x61, /* mov.l @r1,r1 */
2001 0x2b, 0x41, /* jmp @r1 */
2002 0x09, 0x00, /* nop */
2003 0, 0, 0, 0 /* 0: replaced with _GLOBAL_OFFSET_TABLE+8. */
2006 static const bfd_byte vxworks_sh_plt_entry_be
[VXWORKS_PLT_ENTRY_SIZE
] =
2008 0xd0, 0x01, /* mov.l @(8,pc),r0 */
2009 0x60, 0x02, /* mov.l @r0,r0 */
2010 0x40, 0x2b, /* jmp @r0 */
2011 0x00, 0x09, /* nop */
2012 0, 0, 0, 0, /* 0: replaced with address of this symbol in .got. */
2013 0xd0, 0x01, /* mov.l @(8,pc),r0 */
2014 0xa0, 0x00, /* bra PLT (We need to fix the offset.) */
2015 0x00, 0x09, /* nop */
2016 0x00, 0x09, /* nop */
2017 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2020 static const bfd_byte vxworks_sh_plt_entry_le
[VXWORKS_PLT_ENTRY_SIZE
] =
2022 0x01, 0xd0, /* mov.l @(8,pc),r0 */
2023 0x02, 0x60, /* mov.l @r0,r0 */
2024 0x2b, 0x40, /* jmp @r0 */
2025 0x09, 0x00, /* nop */
2026 0, 0, 0, 0, /* 0: replaced with address of this symbol in .got. */
2027 0x01, 0xd0, /* mov.l @(8,pc),r0 */
2028 0x00, 0xa0, /* bra PLT (We need to fix the offset.) */
2029 0x09, 0x00, /* nop */
2030 0x09, 0x00, /* nop */
2031 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2034 static const bfd_byte vxworks_sh_pic_plt_entry_be
[VXWORKS_PLT_ENTRY_SIZE
] =
2036 0xd0, 0x01, /* mov.l @(8,pc),r0 */
2037 0x00, 0xce, /* mov.l @(r0,r12),r0 */
2038 0x40, 0x2b, /* jmp @r0 */
2039 0x00, 0x09, /* nop */
2040 0, 0, 0, 0, /* 0: replaced with offset of this symbol in .got. */
2041 0xd0, 0x01, /* mov.l @(8,pc),r0 */
2042 0x51, 0xc2, /* mov.l @(8,r12),r1 */
2043 0x41, 0x2b, /* jmp @r1 */
2044 0x00, 0x09, /* nop */
2045 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2048 static const bfd_byte vxworks_sh_pic_plt_entry_le
[VXWORKS_PLT_ENTRY_SIZE
] =
2050 0x01, 0xd0, /* mov.l @(8,pc),r0 */
2051 0xce, 0x00, /* mov.l @(r0,r12),r0 */
2052 0x2b, 0x40, /* jmp @r0 */
2053 0x09, 0x00, /* nop */
2054 0, 0, 0, 0, /* 0: replaced with offset of this symbol in .got. */
2055 0x01, 0xd0, /* mov.l @(8,pc),r0 */
2056 0xc2, 0x51, /* mov.l @(8,r12),r1 */
2057 0x2b, 0x41, /* jmp @r1 */
2058 0x09, 0x00, /* nop */
2059 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2062 static const struct elf_sh_plt_info vxworks_sh_plts
[2][2] = {
2065 /* Big-endian non-PIC. */
2066 vxworks_sh_plt0_entry_be
,
2067 VXWORKS_PLT_HEADER_SIZE
,
2068 { MINUS_ONE
, MINUS_ONE
, 8 },
2069 vxworks_sh_plt_entry_be
,
2070 VXWORKS_PLT_ENTRY_SIZE
,
2071 { 8, 14, 20, FALSE
},
2076 /* Little-endian non-PIC. */
2077 vxworks_sh_plt0_entry_le
,
2078 VXWORKS_PLT_HEADER_SIZE
,
2079 { MINUS_ONE
, MINUS_ONE
, 8 },
2080 vxworks_sh_plt_entry_le
,
2081 VXWORKS_PLT_ENTRY_SIZE
,
2082 { 8, 14, 20, FALSE
},
2089 /* Big-endian PIC. */
2092 { MINUS_ONE
, MINUS_ONE
, MINUS_ONE
},
2093 vxworks_sh_pic_plt_entry_be
,
2094 VXWORKS_PLT_ENTRY_SIZE
,
2095 { 8, MINUS_ONE
, 20, FALSE
},
2100 /* Little-endian PIC. */
2103 { MINUS_ONE
, MINUS_ONE
, MINUS_ONE
},
2104 vxworks_sh_pic_plt_entry_le
,
2105 VXWORKS_PLT_ENTRY_SIZE
,
2106 { 8, MINUS_ONE
, 20, FALSE
},
2113 /* FDPIC PLT entries. Two unimplemented optimizations for lazy
2114 binding are to omit the lazy binding stub when linking with -z now
2115 and to move lazy binding stubs into a separate region for better
2118 #define FDPIC_PLT_ENTRY_SIZE 28
2119 #define FDPIC_PLT_LAZY_OFFSET 20
2121 /* FIXME: The lazy binding stub requires a plt0 - which may need to be
2122 duplicated if it is out of range, or which can be inlined. So
2123 right now it is always inlined, which wastes a word per stub. It
2124 might be easier to handle the duplication if we put the lazy
2125 stubs separately. */
2127 static const bfd_byte fdpic_sh_plt_entry_be
[FDPIC_PLT_ENTRY_SIZE
] =
2129 0xd0, 0x02, /* mov.l @(12,pc),r0 */
2130 0x01, 0xce, /* mov.l @(r0,r12),r1 */
2131 0x70, 0x04, /* add #4, r0 */
2132 0x41, 0x2b, /* jmp @r1 */
2133 0x0c, 0xce, /* mov.l @(r0,r12),r12 */
2134 0x00, 0x09, /* nop */
2135 0, 0, 0, 0, /* 0: replaced with offset of this symbol's funcdesc */
2136 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2137 0x60, 0xc2, /* mov.l @r12,r0 */
2138 0x40, 0x2b, /* jmp @r0 */
2139 0x53, 0xc1, /* mov.l @(4,r12),r3 */
2140 0x00, 0x09, /* nop */
2143 static const bfd_byte fdpic_sh_plt_entry_le
[FDPIC_PLT_ENTRY_SIZE
] =
2145 0x02, 0xd0, /* mov.l @(12,pc),r0 */
2146 0xce, 0x01, /* mov.l @(r0,r12),r1 */
2147 0x04, 0x70, /* add #4, r0 */
2148 0x2b, 0x41, /* jmp @r1 */
2149 0xce, 0x0c, /* mov.l @(r0,r12),r12 */
2150 0x09, 0x00, /* nop */
2151 0, 0, 0, 0, /* 0: replaced with offset of this symbol's funcdesc */
2152 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2153 0xc2, 0x60, /* mov.l @r12,r0 */
2154 0x2b, 0x40, /* jmp @r0 */
2155 0xc1, 0x53, /* mov.l @(4,r12),r3 */
2156 0x09, 0x00, /* nop */
2159 static const struct elf_sh_plt_info fdpic_sh_plts
[2] = {
2161 /* Big-endian PIC. */
2164 { MINUS_ONE
, MINUS_ONE
, MINUS_ONE
},
2165 fdpic_sh_plt_entry_be
,
2166 FDPIC_PLT_ENTRY_SIZE
,
2167 { 12, MINUS_ONE
, 16, FALSE
},
2168 FDPIC_PLT_LAZY_OFFSET
,
2172 /* Little-endian PIC. */
2175 { MINUS_ONE
, MINUS_ONE
, MINUS_ONE
},
2176 fdpic_sh_plt_entry_le
,
2177 FDPIC_PLT_ENTRY_SIZE
,
2178 { 12, MINUS_ONE
, 16, FALSE
},
2179 FDPIC_PLT_LAZY_OFFSET
,
2184 /* On SH2A, we can use the movi20 instruction to generate shorter PLT
2185 entries for the first 64K slots. We use the normal FDPIC PLT entry
2186 past that point; we could also use movi20s, which might be faster,
2187 but would not be any smaller. */
2189 #define FDPIC_SH2A_PLT_ENTRY_SIZE 24
2190 #define FDPIC_SH2A_PLT_LAZY_OFFSET 16
2192 static const bfd_byte fdpic_sh2a_plt_entry_be
[FDPIC_SH2A_PLT_ENTRY_SIZE
] =
2194 0, 0, 0, 0, /* movi20 #gotofffuncdesc,r0 */
2195 0x01, 0xce, /* mov.l @(r0,r12),r1 */
2196 0x70, 0x04, /* add #4, r0 */
2197 0x41, 0x2b, /* jmp @r1 */
2198 0x0c, 0xce, /* mov.l @(r0,r12),r12 */
2199 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2200 0x60, 0xc2, /* mov.l @r12,r0 */
2201 0x40, 0x2b, /* jmp @r0 */
2202 0x53, 0xc1, /* mov.l @(4,r12),r3 */
2203 0x00, 0x09, /* nop */
2206 static const bfd_byte fdpic_sh2a_plt_entry_le
[FDPIC_SH2A_PLT_ENTRY_SIZE
] =
2208 0, 0, 0, 0, /* movi20 #gotofffuncdesc,r0 */
2209 0xce, 0x01, /* mov.l @(r0,r12),r1 */
2210 0x04, 0x70, /* add #4, r0 */
2211 0x2b, 0x41, /* jmp @r1 */
2212 0xce, 0x0c, /* mov.l @(r0,r12),r12 */
2213 0, 0, 0, 0, /* 1: replaced with offset into relocation table. */
2214 0xc2, 0x60, /* mov.l @r12,r0 */
2215 0x2b, 0x40, /* jmp @r0 */
2216 0xc1, 0x53, /* mov.l @(4,r12),r3 */
2217 0x09, 0x00, /* nop */
2220 static const struct elf_sh_plt_info fdpic_sh2a_short_plt_be
= {
2221 /* Big-endian FDPIC, max index 64K. */
2224 { MINUS_ONE
, MINUS_ONE
, MINUS_ONE
},
2225 fdpic_sh2a_plt_entry_be
,
2226 FDPIC_SH2A_PLT_ENTRY_SIZE
,
2227 { 0, MINUS_ONE
, 12, TRUE
},
2228 FDPIC_SH2A_PLT_LAZY_OFFSET
,
2232 static const struct elf_sh_plt_info fdpic_sh2a_short_plt_le
= {
2233 /* Little-endian FDPIC, max index 64K. */
2236 { MINUS_ONE
, MINUS_ONE
, MINUS_ONE
},
2237 fdpic_sh2a_plt_entry_le
,
2238 FDPIC_SH2A_PLT_ENTRY_SIZE
,
2239 { 0, MINUS_ONE
, 12, TRUE
},
2240 FDPIC_SH2A_PLT_LAZY_OFFSET
,
2244 static const struct elf_sh_plt_info fdpic_sh2a_plts
[2] = {
2246 /* Big-endian PIC. */
2249 { MINUS_ONE
, MINUS_ONE
, MINUS_ONE
},
2250 fdpic_sh_plt_entry_be
,
2251 FDPIC_PLT_ENTRY_SIZE
,
2252 { 12, MINUS_ONE
, 16, FALSE
},
2253 FDPIC_PLT_LAZY_OFFSET
,
2254 &fdpic_sh2a_short_plt_be
2257 /* Little-endian PIC. */
2260 { MINUS_ONE
, MINUS_ONE
, MINUS_ONE
},
2261 fdpic_sh_plt_entry_le
,
2262 FDPIC_PLT_ENTRY_SIZE
,
2263 { 12, MINUS_ONE
, 16, FALSE
},
2264 FDPIC_PLT_LAZY_OFFSET
,
2265 &fdpic_sh2a_short_plt_le
2269 /* Return the type of PLT associated with ABFD. PIC_P is true if
2270 the object is position-independent. */
2272 static const struct elf_sh_plt_info
*
2273 get_plt_info (bfd
*abfd
, bfd_boolean pic_p
)
2275 if (fdpic_object_p (abfd
))
2277 /* If any input file requires SH2A we can use a shorter PLT
2279 if (sh_get_arch_from_bfd_mach (bfd_get_mach (abfd
)) & arch_sh2a_base
)
2280 return &fdpic_sh2a_plts
[!bfd_big_endian (abfd
)];
2282 return &fdpic_sh_plts
[!bfd_big_endian (abfd
)];
2284 if (vxworks_object_p (abfd
))
2285 return &vxworks_sh_plts
[pic_p
][!bfd_big_endian (abfd
)];
2286 return &elf_sh_plts
[pic_p
][!bfd_big_endian (abfd
)];
2289 /* Install a 32-bit PLT field starting at ADDR, which occurs in OUTPUT_BFD.
2290 VALUE is the field's value and CODE_P is true if VALUE refers to code,
2294 install_plt_field (bfd
*output_bfd
, bfd_boolean code_p ATTRIBUTE_UNUSED
,
2295 unsigned long value
, bfd_byte
*addr
)
2297 bfd_put_32 (output_bfd
, value
, addr
);
2301 /* The number of PLT entries which can use a shorter PLT, if any.
2302 Currently always 64K, since only SH-2A FDPIC uses this; a
2303 20-bit movi20 can address that many function descriptors below
2304 _GLOBAL_OFFSET_TABLE_. */
2305 #define MAX_SHORT_PLT 65536
2307 /* Return the index of the PLT entry at byte offset OFFSET. */
2310 get_plt_index (const struct elf_sh_plt_info
*info
, bfd_vma offset
)
2312 bfd_vma plt_index
= 0;
2314 offset
-= info
->plt0_entry_size
;
2315 if (info
->short_plt
!= NULL
)
2317 if (offset
> MAX_SHORT_PLT
* info
->short_plt
->symbol_entry_size
)
2319 plt_index
= MAX_SHORT_PLT
;
2320 offset
-= MAX_SHORT_PLT
* info
->short_plt
->symbol_entry_size
;
2323 info
= info
->short_plt
;
2325 return plt_index
+ offset
/ info
->symbol_entry_size
;
2328 /* Do the inverse operation. */
2331 get_plt_offset (const struct elf_sh_plt_info
*info
, bfd_vma plt_index
)
2335 if (info
->short_plt
!= NULL
)
2337 if (plt_index
> MAX_SHORT_PLT
)
2339 offset
= MAX_SHORT_PLT
* info
->short_plt
->symbol_entry_size
;
2340 plt_index
-= MAX_SHORT_PLT
;
2343 info
= info
->short_plt
;
2345 return (offset
+ info
->plt0_entry_size
2346 + (plt_index
* info
->symbol_entry_size
));
2349 /* The sh linker needs to keep track of the number of relocs that it
2350 decides to copy as dynamic relocs in check_relocs for each symbol.
2351 This is so that it can later discard them if they are found to be
2352 unnecessary. We store the information in a field extending the
2353 regular ELF linker hash table. */
2355 struct elf_sh_dyn_relocs
2357 struct elf_sh_dyn_relocs
*next
;
2359 /* The input section of the reloc. */
2362 /* Total number of relocs copied for the input section. */
2363 bfd_size_type count
;
2365 /* Number of pc-relative relocs copied for the input section. */
2366 bfd_size_type pc_count
;
2371 bfd_signed_vma refcount
;
2375 /* sh ELF linker hash entry. */
2377 struct elf_sh_link_hash_entry
2379 struct elf_link_hash_entry root
;
2381 #ifdef INCLUDE_SHMEDIA
2384 bfd_signed_vma refcount
;
2389 /* Track dynamic relocs copied for this symbol. */
2390 struct elf_sh_dyn_relocs
*dyn_relocs
;
2392 bfd_signed_vma gotplt_refcount
;
2394 /* A local function descriptor, for FDPIC. The refcount counts
2395 R_SH_FUNCDESC, R_SH_GOTOFFFUNCDESC, and R_SH_GOTOFFFUNCDESC20
2396 relocations; the PLT and GOT entry are accounted
2397 for separately. After adjust_dynamic_symbol, the offset is
2398 MINUS_ONE if there is no local descriptor (dynamic linker
2399 managed and no PLT entry, or undefined weak non-dynamic).
2400 During check_relocs we do not yet know whether the local
2401 descriptor will be canonical. */
2402 union gotref funcdesc
;
2404 /* How many of the above refcounted relocations were R_SH_FUNCDESC,
2405 and thus require fixups or relocations. */
2406 bfd_signed_vma abs_funcdesc_refcount
;
2409 GOT_UNKNOWN
= 0, GOT_NORMAL
, GOT_TLS_GD
, GOT_TLS_IE
, GOT_FUNCDESC
2413 #define sh_elf_hash_entry(ent) ((struct elf_sh_link_hash_entry *)(ent))
2415 struct sh_elf_obj_tdata
2417 struct elf_obj_tdata root
;
2419 /* got_type for each local got entry. */
2420 char *local_got_type
;
2422 /* Function descriptor refcount and offset for each local symbol. */
2423 union gotref
*local_funcdesc
;
2426 #define sh_elf_tdata(abfd) \
2427 ((struct sh_elf_obj_tdata *) (abfd)->tdata.any)
2429 #define sh_elf_local_got_type(abfd) \
2430 (sh_elf_tdata (abfd)->local_got_type)
2432 #define sh_elf_local_funcdesc(abfd) \
2433 (sh_elf_tdata (abfd)->local_funcdesc)
2435 #define is_sh_elf(bfd) \
2436 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2437 && elf_tdata (bfd) != NULL \
2438 && elf_object_id (bfd) == SH_ELF_DATA)
2440 /* Override the generic function because we need to store sh_elf_obj_tdata
2441 as the specific tdata. */
2444 sh_elf_mkobject (bfd
*abfd
)
2446 return bfd_elf_allocate_object (abfd
, sizeof (struct sh_elf_obj_tdata
),
2450 /* sh ELF linker hash table. */
2452 struct elf_sh_link_hash_table
2454 struct elf_link_hash_table root
;
2456 /* Short-cuts to get to dynamic linker sections. */
2464 asection
*sfuncdesc
;
2465 asection
*srelfuncdesc
;
2468 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
2471 /* Small local sym cache. */
2472 struct sym_cache sym_cache
;
2474 /* A counter or offset to track a TLS got entry. */
2477 bfd_signed_vma refcount
;
2481 /* The type of PLT to use. */
2482 const struct elf_sh_plt_info
*plt_info
;
2484 /* True if the target system is VxWorks. */
2485 bfd_boolean vxworks_p
;
2487 /* True if the target system uses FDPIC. */
2488 bfd_boolean fdpic_p
;
2491 /* Traverse an sh ELF linker hash table. */
2493 #define sh_elf_link_hash_traverse(table, func, info) \
2494 (elf_link_hash_traverse \
2496 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
2499 /* Get the sh ELF linker hash table from a link_info structure. */
2501 #define sh_elf_hash_table(p) \
2502 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
2503 == SH_ELF_DATA ? ((struct elf_sh_link_hash_table *) ((p)->hash)) : NULL)
2505 /* Create an entry in an sh ELF linker hash table. */
2507 static struct bfd_hash_entry
*
2508 sh_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
2509 struct bfd_hash_table
*table
,
2512 struct elf_sh_link_hash_entry
*ret
=
2513 (struct elf_sh_link_hash_entry
*) entry
;
2515 /* Allocate the structure if it has not already been allocated by a
2517 if (ret
== (struct elf_sh_link_hash_entry
*) NULL
)
2518 ret
= ((struct elf_sh_link_hash_entry
*)
2519 bfd_hash_allocate (table
,
2520 sizeof (struct elf_sh_link_hash_entry
)));
2521 if (ret
== (struct elf_sh_link_hash_entry
*) NULL
)
2522 return (struct bfd_hash_entry
*) ret
;
2524 /* Call the allocation method of the superclass. */
2525 ret
= ((struct elf_sh_link_hash_entry
*)
2526 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2528 if (ret
!= (struct elf_sh_link_hash_entry
*) NULL
)
2530 ret
->dyn_relocs
= NULL
;
2531 ret
->gotplt_refcount
= 0;
2532 #ifdef INCLUDE_SHMEDIA
2533 ret
->datalabel_got
.refcount
= ret
->root
.got
.refcount
;
2535 ret
->funcdesc
.refcount
= 0;
2536 ret
->abs_funcdesc_refcount
= 0;
2537 ret
->got_type
= GOT_UNKNOWN
;
2540 return (struct bfd_hash_entry
*) ret
;
2543 /* Create an sh ELF linker hash table. */
2545 static struct bfd_link_hash_table
*
2546 sh_elf_link_hash_table_create (bfd
*abfd
)
2548 struct elf_sh_link_hash_table
*ret
;
2549 bfd_size_type amt
= sizeof (struct elf_sh_link_hash_table
);
2551 ret
= (struct elf_sh_link_hash_table
*) bfd_malloc (amt
);
2552 if (ret
== (struct elf_sh_link_hash_table
*) NULL
)
2555 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
2556 sh_elf_link_hash_newfunc
,
2557 sizeof (struct elf_sh_link_hash_entry
),
2565 ret
->sgotplt
= NULL
;
2566 ret
->srelgot
= NULL
;
2568 ret
->srelplt
= NULL
;
2569 ret
->sdynbss
= NULL
;
2570 ret
->srelbss
= NULL
;
2571 ret
->srelplt2
= NULL
;
2572 ret
->sym_cache
.abfd
= NULL
;
2573 ret
->tls_ldm_got
.refcount
= 0;
2574 ret
->plt_info
= NULL
;
2575 ret
->vxworks_p
= vxworks_object_p (abfd
);
2576 ret
->fdpic_p
= fdpic_object_p (abfd
);
2578 return &ret
->root
.root
;
2582 sh_elf_omit_section_dynsym (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2583 struct bfd_link_info
*info
, asection
*p
)
2585 struct elf_sh_link_hash_table
*htab
= sh_elf_hash_table (info
);
2587 /* Non-FDPIC binaries do not need dynamic symbols for sections. */
2591 /* We need dynamic symbols for every section, since segments can
2592 relocate independently. */
2593 switch (elf_section_data (p
)->this_hdr
.sh_type
)
2597 /* If sh_type is yet undecided, assume it could be
2598 SHT_PROGBITS/SHT_NOBITS. */
2602 /* There shouldn't be section relative relocations
2603 against any other section. */
2609 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
2610 shortcuts to them in our hash table. */
2613 create_got_section (bfd
*dynobj
, struct bfd_link_info
*info
)
2615 struct elf_sh_link_hash_table
*htab
;
2617 if (! _bfd_elf_create_got_section (dynobj
, info
))
2620 htab
= sh_elf_hash_table (info
);
2624 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
2625 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
2626 htab
->srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
2627 if (! htab
->sgot
|| ! htab
->sgotplt
|| ! htab
->srelgot
)
2630 htab
->sfuncdesc
= bfd_make_section_with_flags (dynobj
, ".got.funcdesc",
2631 (SEC_ALLOC
| SEC_LOAD
2634 | SEC_LINKER_CREATED
));
2635 if (htab
->sfuncdesc
== NULL
2636 || ! bfd_set_section_alignment (dynobj
, htab
->sfuncdesc
, 2))
2639 htab
->srelfuncdesc
= bfd_make_section_with_flags (dynobj
,
2640 ".rela.got.funcdesc",
2641 (SEC_ALLOC
| SEC_LOAD
2644 | SEC_LINKER_CREATED
2646 if (htab
->srelfuncdesc
== NULL
2647 || ! bfd_set_section_alignment (dynobj
, htab
->srelfuncdesc
, 2))
2650 /* Also create .rofixup. */
2651 htab
->srofixup
= bfd_make_section_with_flags (dynobj
, ".rofixup",
2652 (SEC_ALLOC
| SEC_LOAD
2655 | SEC_LINKER_CREATED
2657 if (htab
->srofixup
== NULL
2658 || ! bfd_set_section_alignment (dynobj
, htab
->srofixup
, 2))
2664 /* Create dynamic sections when linking against a dynamic object. */
2667 sh_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
2669 struct elf_sh_link_hash_table
*htab
;
2670 flagword flags
, pltflags
;
2672 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
2675 switch (bed
->s
->arch_size
)
2686 bfd_set_error (bfd_error_bad_value
);
2690 htab
= sh_elf_hash_table (info
);
2694 if (htab
->root
.dynamic_sections_created
)
2697 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
2698 .rel[a].bss sections. */
2700 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2701 | SEC_LINKER_CREATED
);
2704 pltflags
|= SEC_CODE
;
2705 if (bed
->plt_not_loaded
)
2706 pltflags
&= ~ (SEC_LOAD
| SEC_HAS_CONTENTS
);
2707 if (bed
->plt_readonly
)
2708 pltflags
|= SEC_READONLY
;
2710 s
= bfd_make_section_with_flags (abfd
, ".plt", pltflags
);
2713 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
2716 if (bed
->want_plt_sym
)
2718 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
2720 struct elf_link_hash_entry
*h
;
2721 struct bfd_link_hash_entry
*bh
= NULL
;
2723 if (! (_bfd_generic_link_add_one_symbol
2724 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
,
2725 (bfd_vma
) 0, (const char *) NULL
, FALSE
,
2726 get_elf_backend_data (abfd
)->collect
, &bh
)))
2729 h
= (struct elf_link_hash_entry
*) bh
;
2731 h
->type
= STT_OBJECT
;
2732 htab
->root
.hplt
= h
;
2735 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2739 s
= bfd_make_section_with_flags (abfd
,
2740 bed
->default_use_rela_p
? ".rela.plt" : ".rel.plt",
2741 flags
| SEC_READONLY
);
2744 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
2747 if (htab
->sgot
== NULL
2748 && !create_got_section (abfd
, info
))
2752 const char *secname
;
2757 for (sec
= abfd
->sections
; sec
; sec
= sec
->next
)
2759 secflags
= bfd_get_section_flags (abfd
, sec
);
2760 if ((secflags
& (SEC_DATA
| SEC_LINKER_CREATED
))
2761 || ((secflags
& SEC_HAS_CONTENTS
) != SEC_HAS_CONTENTS
))
2763 secname
= bfd_get_section_name (abfd
, sec
);
2764 relname
= (char *) bfd_malloc ((bfd_size_type
) strlen (secname
) + 6);
2765 strcpy (relname
, ".rela");
2766 strcat (relname
, secname
);
2767 if (bfd_get_section_by_name (abfd
, secname
))
2769 s
= bfd_make_section_with_flags (abfd
, relname
,
2770 flags
| SEC_READONLY
);
2772 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
2777 if (bed
->want_dynbss
)
2779 /* The .dynbss section is a place to put symbols which are defined
2780 by dynamic objects, are referenced by regular objects, and are
2781 not functions. We must allocate space for them in the process
2782 image and use a R_*_COPY reloc to tell the dynamic linker to
2783 initialize them at run time. The linker script puts the .dynbss
2784 section into the .bss section of the final image. */
2785 s
= bfd_make_section_with_flags (abfd
, ".dynbss",
2786 SEC_ALLOC
| SEC_LINKER_CREATED
);
2791 /* The .rel[a].bss section holds copy relocs. This section is not
2792 normally needed. We need to create it here, though, so that the
2793 linker will map it to an output section. We can't just create it
2794 only if we need it, because we will not know whether we need it
2795 until we have seen all the input files, and the first time the
2796 main linker code calls BFD after examining all the input files
2797 (size_dynamic_sections) the input sections have already been
2798 mapped to the output sections. If the section turns out not to
2799 be needed, we can discard it later. We will never need this
2800 section when generating a shared object, since they do not use
2804 s
= bfd_make_section_with_flags (abfd
,
2805 (bed
->default_use_rela_p
2806 ? ".rela.bss" : ".rel.bss"),
2807 flags
| SEC_READONLY
);
2810 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
2815 if (htab
->vxworks_p
)
2817 if (!elf_vxworks_create_dynamic_sections (abfd
, info
, &htab
->srelplt2
))
2824 /* Adjust a symbol defined by a dynamic object and referenced by a
2825 regular object. The current definition is in some section of the
2826 dynamic object, but we're not including those sections. We have to
2827 change the definition to something the rest of the link can
2831 sh_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2832 struct elf_link_hash_entry
*h
)
2834 struct elf_sh_link_hash_table
*htab
;
2835 struct elf_sh_link_hash_entry
*eh
;
2836 struct elf_sh_dyn_relocs
*p
;
2839 htab
= sh_elf_hash_table (info
);
2843 /* Make sure we know what is going on here. */
2844 BFD_ASSERT (htab
->root
.dynobj
!= NULL
2846 || h
->u
.weakdef
!= NULL
2849 && !h
->def_regular
)));
2851 /* If this is a function, put it in the procedure linkage table. We
2852 will fill in the contents of the procedure linkage table later,
2853 when we know the address of the .got section. */
2854 if (h
->type
== STT_FUNC
2857 if (h
->plt
.refcount
<= 0
2858 || SYMBOL_CALLS_LOCAL (info
, h
)
2859 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2860 && h
->root
.type
== bfd_link_hash_undefweak
))
2862 /* This case can occur if we saw a PLT reloc in an input
2863 file, but the symbol was never referred to by a dynamic
2864 object. In such a case, we don't actually need to build
2865 a procedure linkage table, and we can just do a REL32
2867 h
->plt
.offset
= (bfd_vma
) -1;
2874 h
->plt
.offset
= (bfd_vma
) -1;
2876 /* If this is a weak symbol, and there is a real definition, the
2877 processor independent code will have arranged for us to see the
2878 real definition first, and we can just use the same value. */
2879 if (h
->u
.weakdef
!= NULL
)
2881 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2882 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2883 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2884 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2885 if (info
->nocopyreloc
)
2886 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
2890 /* This is a reference to a symbol defined by a dynamic object which
2891 is not a function. */
2893 /* If we are creating a shared library, we must presume that the
2894 only references to the symbol are via the global offset table.
2895 For such cases we need not do anything here; the relocations will
2896 be handled correctly by relocate_section. */
2900 /* If there are no references to this symbol that do not use the
2901 GOT, we don't need to generate a copy reloc. */
2902 if (!h
->non_got_ref
)
2905 /* If -z nocopyreloc was given, we won't generate them either. */
2906 if (info
->nocopyreloc
)
2912 eh
= (struct elf_sh_link_hash_entry
*) h
;
2913 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2915 s
= p
->sec
->output_section
;
2916 if (s
!= NULL
&& (s
->flags
& (SEC_READONLY
| SEC_HAS_CONTENTS
)) != 0)
2920 /* If we didn't find any dynamic relocs in sections which needs the
2921 copy reloc, then we'll be keeping the dynamic relocs and avoiding
2931 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
2932 h
->root
.root
.string
);
2936 /* We must allocate the symbol in our .dynbss section, which will
2937 become part of the .bss section of the executable. There will be
2938 an entry for this symbol in the .dynsym section. The dynamic
2939 object will contain position independent code, so all references
2940 from the dynamic object to this symbol will go through the global
2941 offset table. The dynamic linker will use the .dynsym entry to
2942 determine the address it must put in the global offset table, so
2943 both the dynamic object and the regular object will refer to the
2944 same memory location for the variable. */
2947 BFD_ASSERT (s
!= NULL
);
2949 /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
2950 copy the initial value out of the dynamic object and into the
2951 runtime process image. We need to remember the offset into the
2952 .rela.bss section we are going to use. */
2953 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2957 srel
= htab
->srelbss
;
2958 BFD_ASSERT (srel
!= NULL
);
2959 srel
->size
+= sizeof (Elf32_External_Rela
);
2963 return _bfd_elf_adjust_dynamic_copy (h
, s
);
2966 /* Allocate space in .plt, .got and associated reloc sections for
2970 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2972 struct bfd_link_info
*info
;
2973 struct elf_sh_link_hash_table
*htab
;
2974 struct elf_sh_link_hash_entry
*eh
;
2975 struct elf_sh_dyn_relocs
*p
;
2977 if (h
->root
.type
== bfd_link_hash_indirect
)
2980 info
= (struct bfd_link_info
*) inf
;
2981 htab
= sh_elf_hash_table (info
);
2985 eh
= (struct elf_sh_link_hash_entry
*) h
;
2986 if ((h
->got
.refcount
> 0
2988 && eh
->gotplt_refcount
> 0)
2990 /* The symbol has been forced local, or we have some direct got refs,
2991 so treat all the gotplt refs as got refs. */
2992 h
->got
.refcount
+= eh
->gotplt_refcount
;
2993 if (h
->plt
.refcount
>= eh
->gotplt_refcount
)
2994 h
->plt
.refcount
-= eh
->gotplt_refcount
;
2997 if (htab
->root
.dynamic_sections_created
2998 && h
->plt
.refcount
> 0
2999 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3000 || h
->root
.type
!= bfd_link_hash_undefweak
))
3002 /* Make sure this symbol is output as a dynamic symbol.
3003 Undefined weak syms won't yet be marked as dynamic. */
3004 if (h
->dynindx
== -1
3005 && !h
->forced_local
)
3007 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3012 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
3014 asection
*s
= htab
->splt
;
3015 const struct elf_sh_plt_info
*plt_info
;
3017 /* If this is the first .plt entry, make room for the special
3020 s
->size
+= htab
->plt_info
->plt0_entry_size
;
3022 h
->plt
.offset
= s
->size
;
3024 /* If this symbol is not defined in a regular file, and we are
3025 not generating a shared library, then set the symbol to this
3026 location in the .plt. This is required to make function
3027 pointers compare as equal between the normal executable and
3028 the shared library. Skip this for FDPIC, since the
3029 function's address will be the address of the canonical
3030 function descriptor. */
3031 if (!htab
->fdpic_p
&& !info
->shared
&& !h
->def_regular
)
3033 h
->root
.u
.def
.section
= s
;
3034 h
->root
.u
.def
.value
= h
->plt
.offset
;
3037 /* Make room for this entry. */
3038 plt_info
= htab
->plt_info
;
3039 if (plt_info
->short_plt
!= NULL
3040 && (get_plt_index (plt_info
->short_plt
, s
->size
) < MAX_SHORT_PLT
))
3041 plt_info
= plt_info
->short_plt
;
3042 s
->size
+= plt_info
->symbol_entry_size
;
3044 /* We also need to make an entry in the .got.plt section, which
3045 will be placed in the .got section by the linker script. */
3047 htab
->sgotplt
->size
+= 4;
3049 htab
->sgotplt
->size
+= 8;
3051 /* We also need to make an entry in the .rel.plt section. */
3052 htab
->srelplt
->size
+= sizeof (Elf32_External_Rela
);
3054 if (htab
->vxworks_p
&& !info
->shared
)
3056 /* VxWorks executables have a second set of relocations
3057 for each PLT entry. They go in a separate relocation
3058 section, which is processed by the kernel loader. */
3060 /* There is a relocation for the initial PLT entry:
3061 an R_SH_DIR32 relocation for _GLOBAL_OFFSET_TABLE_. */
3062 if (h
->plt
.offset
== htab
->plt_info
->plt0_entry_size
)
3063 htab
->srelplt2
->size
+= sizeof (Elf32_External_Rela
);
3065 /* There are two extra relocations for each subsequent
3066 PLT entry: an R_SH_DIR32 relocation for the GOT entry,
3067 and an R_SH_DIR32 relocation for the PLT entry. */
3068 htab
->srelplt2
->size
+= sizeof (Elf32_External_Rela
) * 2;
3073 h
->plt
.offset
= (bfd_vma
) -1;
3079 h
->plt
.offset
= (bfd_vma
) -1;
3083 if (h
->got
.refcount
> 0)
3087 int got_type
= sh_elf_hash_entry (h
)->got_type
;
3089 /* Make sure this symbol is output as a dynamic symbol.
3090 Undefined weak syms won't yet be marked as dynamic. */
3091 if (h
->dynindx
== -1
3092 && !h
->forced_local
)
3094 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3099 h
->got
.offset
= s
->size
;
3101 /* R_SH_TLS_GD needs 2 consecutive GOT slots. */
3102 if (got_type
== GOT_TLS_GD
)
3104 dyn
= htab
->root
.dynamic_sections_created
;
3107 /* No dynamic relocations required. */
3108 if (htab
->fdpic_p
&& !info
->shared
3109 && h
->root
.type
!= bfd_link_hash_undefweak
3110 && (got_type
== GOT_NORMAL
|| got_type
== GOT_FUNCDESC
))
3111 htab
->srofixup
->size
+= 4;
3113 /* R_SH_TLS_IE_32 needs one dynamic relocation if dynamic,
3114 R_SH_TLS_GD needs one if local symbol and two if global. */
3115 else if ((got_type
== GOT_TLS_GD
&& h
->dynindx
== -1)
3116 || got_type
== GOT_TLS_IE
)
3117 htab
->srelgot
->size
+= sizeof (Elf32_External_Rela
);
3118 else if (got_type
== GOT_TLS_GD
)
3119 htab
->srelgot
->size
+= 2 * sizeof (Elf32_External_Rela
);
3120 else if (got_type
== GOT_FUNCDESC
)
3122 if (!info
->shared
&& SYMBOL_FUNCDESC_LOCAL (info
, h
))
3123 htab
->srofixup
->size
+= 4;
3125 htab
->srelgot
->size
+= sizeof (Elf32_External_Rela
);
3127 else if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3128 || h
->root
.type
!= bfd_link_hash_undefweak
)
3130 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
3131 htab
->srelgot
->size
+= sizeof (Elf32_External_Rela
);
3132 else if (htab
->fdpic_p
&& !info
->shared
&& got_type
== GOT_NORMAL
3133 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3134 || h
->root
.type
!= bfd_link_hash_undefweak
))
3135 htab
->srofixup
->size
+= 4;
3138 h
->got
.offset
= (bfd_vma
) -1;
3140 #ifdef INCLUDE_SHMEDIA
3141 if (eh
->datalabel_got
.refcount
> 0)
3146 /* Make sure this symbol is output as a dynamic symbol.
3147 Undefined weak syms won't yet be marked as dynamic. */
3148 if (h
->dynindx
== -1
3149 && !h
->forced_local
)
3151 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3156 eh
->datalabel_got
.offset
= s
->size
;
3158 dyn
= htab
->root
.dynamic_sections_created
;
3159 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
))
3160 htab
->srelgot
->size
+= sizeof (Elf32_External_Rela
);
3163 eh
->datalabel_got
.offset
= (bfd_vma
) -1;
3166 /* Allocate space for any dynamic relocations to function
3167 descriptors, canonical or otherwise. We need to relocate the
3168 reference unless it resolves to zero, which only happens for
3169 undefined weak symbols (either non-default visibility, or when
3170 static linking). Any GOT slot is accounted for elsewhere. */
3171 if (eh
->abs_funcdesc_refcount
> 0
3172 && (h
->root
.type
!= bfd_link_hash_undefweak
3173 || (htab
->root
.dynamic_sections_created
3174 && ! SYMBOL_CALLS_LOCAL (info
, h
))))
3176 if (!info
->shared
&& SYMBOL_FUNCDESC_LOCAL (info
, h
))
3177 htab
->srofixup
->size
+= eh
->abs_funcdesc_refcount
* 4;
3180 += eh
->abs_funcdesc_refcount
* sizeof (Elf32_External_Rela
);
3183 /* We must allocate a function descriptor if there are references to
3184 a canonical descriptor (R_SH_GOTFUNCDESC or R_SH_FUNCDESC) and
3185 the dynamic linker isn't going to allocate it. None of this
3186 applies if we already created one in .got.plt, but if the
3187 canonical function descriptor can be in this object, there
3188 won't be a PLT entry at all. */
3189 if ((eh
->funcdesc
.refcount
> 0
3190 || (h
->got
.offset
!= MINUS_ONE
&& eh
->got_type
== GOT_FUNCDESC
))
3191 && h
->root
.type
!= bfd_link_hash_undefweak
3192 && SYMBOL_FUNCDESC_LOCAL (info
, h
))
3194 /* Make room for this function descriptor. */
3195 eh
->funcdesc
.offset
= htab
->sfuncdesc
->size
;
3196 htab
->sfuncdesc
->size
+= 8;
3198 /* We will need a relocation or two fixups to initialize the
3199 function descriptor, so allocate those too. */
3200 if (!info
->shared
&& SYMBOL_CALLS_LOCAL (info
, h
))
3201 htab
->srofixup
->size
+= 8;
3203 htab
->srelfuncdesc
->size
+= sizeof (Elf32_External_Rela
);
3206 if (eh
->dyn_relocs
== NULL
)
3209 /* In the shared -Bsymbolic case, discard space allocated for
3210 dynamic pc-relative relocs against symbols which turn out to be
3211 defined in regular objects. For the normal shared case, discard
3212 space for pc-relative relocs that have become local due to symbol
3213 visibility changes. */
3217 if (SYMBOL_CALLS_LOCAL (info
, h
))
3219 struct elf_sh_dyn_relocs
**pp
;
3221 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3223 p
->count
-= p
->pc_count
;
3232 if (htab
->vxworks_p
)
3234 struct elf_sh_dyn_relocs
**pp
;
3236 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3238 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
3245 /* Also discard relocs on undefined weak syms with non-default
3247 if (eh
->dyn_relocs
!= NULL
3248 && h
->root
.type
== bfd_link_hash_undefweak
)
3250 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
3251 eh
->dyn_relocs
= NULL
;
3253 /* Make sure undefined weak symbols are output as a dynamic
3255 else if (h
->dynindx
== -1
3256 && !h
->forced_local
)
3258 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3265 /* For the non-shared case, discard space for relocs against
3266 symbols which turn out to need copy relocs or are not
3272 || (htab
->root
.dynamic_sections_created
3273 && (h
->root
.type
== bfd_link_hash_undefweak
3274 || h
->root
.type
== bfd_link_hash_undefined
))))
3276 /* Make sure this symbol is output as a dynamic symbol.
3277 Undefined weak syms won't yet be marked as dynamic. */
3278 if (h
->dynindx
== -1
3279 && !h
->forced_local
)
3281 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3285 /* If that succeeded, we know we'll be keeping all the
3287 if (h
->dynindx
!= -1)
3291 eh
->dyn_relocs
= NULL
;
3296 /* Finally, allocate space. */
3297 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3299 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
3300 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
3302 /* If we need relocations, we do not need fixups. */
3303 if (htab
->fdpic_p
&& !info
->shared
)
3304 htab
->srofixup
->size
-= 4 * (p
->count
- p
->pc_count
);
3310 /* Find any dynamic relocs that apply to read-only sections. */
3313 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
3315 struct elf_sh_link_hash_entry
*eh
;
3316 struct elf_sh_dyn_relocs
*p
;
3318 eh
= (struct elf_sh_link_hash_entry
*) h
;
3319 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3321 asection
*s
= p
->sec
->output_section
;
3323 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3325 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
3327 info
->flags
|= DF_TEXTREL
;
3329 /* Not an error, just cut short the traversal. */
3336 /* This function is called after all the input files have been read,
3337 and the input sections have been assigned to output sections.
3338 It's a convenient place to determine the PLT style. */
3341 sh_elf_always_size_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
3343 sh_elf_hash_table (info
)->plt_info
= get_plt_info (output_bfd
, info
->shared
);
3345 if (sh_elf_hash_table (info
)->fdpic_p
&& !info
->relocatable
)
3347 struct elf_link_hash_entry
*h
;
3349 /* Force a PT_GNU_STACK segment to be created. */
3350 if (! elf_tdata (output_bfd
)->stack_flags
)
3351 elf_tdata (output_bfd
)->stack_flags
= PF_R
| PF_W
| PF_X
;
3353 /* Define __stacksize if it's not defined yet. */
3354 h
= elf_link_hash_lookup (elf_hash_table (info
), "__stacksize",
3355 FALSE
, FALSE
, FALSE
);
3356 if (! h
|| h
->root
.type
!= bfd_link_hash_defined
3357 || h
->type
!= STT_OBJECT
3360 struct bfd_link_hash_entry
*bh
= NULL
;
3362 if (!(_bfd_generic_link_add_one_symbol
3363 (info
, output_bfd
, "__stacksize",
3364 BSF_GLOBAL
, bfd_abs_section_ptr
, DEFAULT_STACK_SIZE
,
3365 (const char *) NULL
, FALSE
,
3366 get_elf_backend_data (output_bfd
)->collect
, &bh
)))
3369 h
= (struct elf_link_hash_entry
*) bh
;
3371 h
->type
= STT_OBJECT
;
3377 #if !defined INCLUDE_SHMEDIA && !defined SH_TARGET_ALREADY_DEFINED
3380 sh_elf_modify_program_headers (bfd
*output_bfd
, struct bfd_link_info
*info
)
3382 struct elf_obj_tdata
*tdata
= elf_tdata (output_bfd
);
3383 struct elf_segment_map
*m
;
3384 Elf_Internal_Phdr
*p
;
3386 /* objcopy and strip preserve what's already there using
3387 sh_elf_copy_private_bfd_data (). */
3391 for (p
= tdata
->phdr
, m
= tdata
->segment_map
; m
!= NULL
; m
= m
->next
, p
++)
3392 if (m
->p_type
== PT_GNU_STACK
)
3397 struct elf_link_hash_entry
*h
;
3399 /* Obtain the pointer to the __stacksize symbol. */
3400 h
= elf_link_hash_lookup (elf_hash_table (info
), "__stacksize",
3401 FALSE
, FALSE
, FALSE
);
3404 while (h
->root
.type
== bfd_link_hash_indirect
3405 || h
->root
.type
== bfd_link_hash_warning
)
3406 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3407 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
3410 /* Set the header p_memsz from the symbol value. We
3411 intentionally ignore the symbol section. */
3412 if (h
&& h
->root
.type
== bfd_link_hash_defined
)
3413 p
->p_memsz
= h
->root
.u
.def
.value
;
3415 p
->p_memsz
= DEFAULT_STACK_SIZE
;
3425 /* Set the sizes of the dynamic sections. */
3428 sh_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3429 struct bfd_link_info
*info
)
3431 struct elf_sh_link_hash_table
*htab
;
3437 htab
= sh_elf_hash_table (info
);
3441 dynobj
= htab
->root
.dynobj
;
3442 BFD_ASSERT (dynobj
!= NULL
);
3444 if (htab
->root
.dynamic_sections_created
)
3446 /* Set the contents of the .interp section to the interpreter. */
3447 if (info
->executable
)
3449 s
= bfd_get_section_by_name (dynobj
, ".interp");
3450 BFD_ASSERT (s
!= NULL
);
3451 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3452 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3456 /* Set up .got offsets for local syms, and space for local dynamic
3458 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
3460 bfd_signed_vma
*local_got
;
3461 bfd_signed_vma
*end_local_got
;
3462 union gotref
*local_funcdesc
, *end_local_funcdesc
;
3463 char *local_got_type
;
3464 bfd_size_type locsymcount
;
3465 Elf_Internal_Shdr
*symtab_hdr
;
3468 if (! is_sh_elf (ibfd
))
3471 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3473 struct elf_sh_dyn_relocs
*p
;
3475 for (p
= ((struct elf_sh_dyn_relocs
*)
3476 elf_section_data (s
)->local_dynrel
);
3480 if (! bfd_is_abs_section (p
->sec
)
3481 && bfd_is_abs_section (p
->sec
->output_section
))
3483 /* Input section has been discarded, either because
3484 it is a copy of a linkonce section or due to
3485 linker script /DISCARD/, so we'll be discarding
3488 else if (htab
->vxworks_p
3489 && strcmp (p
->sec
->output_section
->name
,
3492 /* Relocations in vxworks .tls_vars sections are
3493 handled specially by the loader. */
3495 else if (p
->count
!= 0)
3497 srel
= elf_section_data (p
->sec
)->sreloc
;
3498 srel
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
3499 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
3500 info
->flags
|= DF_TEXTREL
;
3502 /* If we need relocations, we do not need fixups. */
3503 if (htab
->fdpic_p
&& !info
->shared
)
3504 htab
->srofixup
->size
-= 4 * (p
->count
- p
->pc_count
);
3509 symtab_hdr
= &elf_symtab_hdr (ibfd
);
3510 locsymcount
= symtab_hdr
->sh_info
;
3511 #ifdef INCLUDE_SHMEDIA
3512 /* Count datalabel local GOT. */
3516 srel
= htab
->srelgot
;
3518 local_got
= elf_local_got_refcounts (ibfd
);
3521 end_local_got
= local_got
+ locsymcount
;
3522 local_got_type
= sh_elf_local_got_type (ibfd
);
3523 local_funcdesc
= sh_elf_local_funcdesc (ibfd
);
3524 for (; local_got
< end_local_got
; ++local_got
)
3528 *local_got
= s
->size
;
3530 if (*local_got_type
== GOT_TLS_GD
)
3533 srel
->size
+= sizeof (Elf32_External_Rela
);
3535 htab
->srofixup
->size
+= 4;
3537 if (*local_got_type
== GOT_FUNCDESC
)
3539 if (local_funcdesc
== NULL
)
3543 size
= locsymcount
* sizeof (union gotref
);
3544 local_funcdesc
= (union gotref
*) bfd_zalloc (ibfd
,
3546 if (local_funcdesc
== NULL
)
3548 sh_elf_local_funcdesc (ibfd
) = local_funcdesc
;
3549 local_funcdesc
+= (local_got
3550 - elf_local_got_refcounts (ibfd
));
3552 local_funcdesc
->refcount
++;
3557 *local_got
= (bfd_vma
) -1;
3562 local_funcdesc
= sh_elf_local_funcdesc (ibfd
);
3565 end_local_funcdesc
= local_funcdesc
+ locsymcount
;
3567 for (; local_funcdesc
< end_local_funcdesc
; ++local_funcdesc
)
3569 if (local_funcdesc
->refcount
> 0)
3571 local_funcdesc
->offset
= htab
->sfuncdesc
->size
;
3572 htab
->sfuncdesc
->size
+= 8;
3574 htab
->srofixup
->size
+= 8;
3576 htab
->srelfuncdesc
->size
+= sizeof (Elf32_External_Rela
);
3579 local_funcdesc
->offset
= MINUS_ONE
;
3585 if (htab
->tls_ldm_got
.refcount
> 0)
3587 /* Allocate 2 got entries and 1 dynamic reloc for R_SH_TLS_LD_32
3589 htab
->tls_ldm_got
.offset
= htab
->sgot
->size
;
3590 htab
->sgot
->size
+= 8;
3591 htab
->srelgot
->size
+= sizeof (Elf32_External_Rela
);
3594 htab
->tls_ldm_got
.offset
= -1;
3596 /* Only the reserved entries should be present. For FDPIC, they go at
3597 the end of .got.plt. */
3600 BFD_ASSERT (htab
->sgotplt
&& htab
->sgotplt
->size
== 12);
3601 htab
->sgotplt
->size
= 0;
3604 /* Allocate global sym .plt and .got entries, and space for global
3605 sym dynamic relocs. */
3606 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, info
);
3608 /* Move the reserved entries and the _GLOBAL_OFFSET_TABLE_ symbol to the
3609 end of the FDPIC .got.plt. */
3612 htab
->root
.hgot
->root
.u
.def
.value
= htab
->sgotplt
->size
;
3613 htab
->sgotplt
->size
+= 12;
3616 /* At the very end of the .rofixup section is a pointer to the GOT. */
3617 if (htab
->fdpic_p
&& htab
->srofixup
!= NULL
)
3618 htab
->srofixup
->size
+= 4;
3620 /* We now have determined the sizes of the various dynamic sections.
3621 Allocate memory for them. */
3623 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3625 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3630 || s
== htab
->sgotplt
3631 || s
== htab
->sfuncdesc
3632 || s
== htab
->srofixup
3633 || s
== htab
->sdynbss
)
3635 /* Strip this section if we don't need it; see the
3638 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
3640 if (s
->size
!= 0 && s
!= htab
->srelplt
&& s
!= htab
->srelplt2
)
3643 /* We use the reloc_count field as a counter if we need
3644 to copy relocs into the output file. */
3649 /* It's not one of our sections, so don't allocate space. */
3655 /* If we don't need this section, strip it from the
3656 output file. This is mostly to handle .rela.bss and
3657 .rela.plt. We must create both sections in
3658 create_dynamic_sections, because they must be created
3659 before the linker maps input sections to output
3660 sections. The linker does that before
3661 adjust_dynamic_symbol is called, and it is that
3662 function which decides whether anything needs to go
3663 into these sections. */
3665 s
->flags
|= SEC_EXCLUDE
;
3669 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3672 /* Allocate memory for the section contents. We use bfd_zalloc
3673 here in case unused entries are not reclaimed before the
3674 section's contents are written out. This should not happen,
3675 but this way if it does, we get a R_SH_NONE reloc instead
3677 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
3678 if (s
->contents
== NULL
)
3682 if (htab
->root
.dynamic_sections_created
)
3684 /* Add some entries to the .dynamic section. We fill in the
3685 values later, in sh_elf_finish_dynamic_sections, but we
3686 must add the entries now so that we get the correct size for
3687 the .dynamic section. The DT_DEBUG entry is filled in by the
3688 dynamic linker and used by the debugger. */
3689 #define add_dynamic_entry(TAG, VAL) \
3690 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3692 if (info
->executable
)
3694 if (! add_dynamic_entry (DT_DEBUG
, 0))
3698 if (htab
->splt
->size
!= 0)
3700 if (! add_dynamic_entry (DT_PLTGOT
, 0)
3701 || ! add_dynamic_entry (DT_PLTRELSZ
, 0)
3702 || ! add_dynamic_entry (DT_PLTREL
, DT_RELA
)
3703 || ! add_dynamic_entry (DT_JMPREL
, 0))
3706 else if ((elf_elfheader (output_bfd
)->e_flags
& EF_SH_FDPIC
)
3707 && htab
->sgot
->size
!= 0)
3709 if (! add_dynamic_entry (DT_PLTGOT
, 0))
3715 if (! add_dynamic_entry (DT_RELA
, 0)
3716 || ! add_dynamic_entry (DT_RELASZ
, 0)
3717 || ! add_dynamic_entry (DT_RELAENT
,
3718 sizeof (Elf32_External_Rela
)))
3721 /* If any dynamic relocs apply to a read-only section,
3722 then we need a DT_TEXTREL entry. */
3723 if ((info
->flags
& DF_TEXTREL
) == 0)
3724 elf_link_hash_traverse (&htab
->root
, readonly_dynrelocs
, info
);
3726 if ((info
->flags
& DF_TEXTREL
) != 0)
3728 if (! add_dynamic_entry (DT_TEXTREL
, 0))
3733 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
3736 #undef add_dynamic_entry
3741 /* Add a dynamic relocation to the SRELOC section. */
3743 inline static bfd_vma
3744 sh_elf_add_dyn_reloc (bfd
*output_bfd
, asection
*sreloc
, bfd_vma offset
,
3745 int reloc_type
, long dynindx
, bfd_vma addend
)
3747 Elf_Internal_Rela outrel
;
3748 bfd_vma reloc_offset
;
3750 outrel
.r_offset
= offset
;
3751 outrel
.r_info
= ELF32_R_INFO (dynindx
, reloc_type
);
3752 outrel
.r_addend
= addend
;
3754 reloc_offset
= sreloc
->reloc_count
* sizeof (Elf32_External_Rela
);
3755 BFD_ASSERT (reloc_offset
< sreloc
->size
);
3756 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3757 sreloc
->contents
+ reloc_offset
);
3758 sreloc
->reloc_count
++;
3760 return reloc_offset
;
3763 /* Add an FDPIC read-only fixup. */
3766 sh_elf_add_rofixup (bfd
*output_bfd
, asection
*srofixup
, bfd_vma offset
)
3768 bfd_vma fixup_offset
;
3770 fixup_offset
= srofixup
->reloc_count
++ * 4;
3771 BFD_ASSERT (fixup_offset
< srofixup
->size
);
3772 bfd_put_32 (output_bfd
, offset
, srofixup
->contents
+ fixup_offset
);
3775 /* Return the offset of the generated .got section from the
3776 _GLOBAL_OFFSET_TABLE_ symbol. */
3778 static bfd_signed_vma
3779 sh_elf_got_offset (struct elf_sh_link_hash_table
*htab
)
3781 return (htab
->sgot
->output_offset
- htab
->sgotplt
->output_offset
3782 - htab
->root
.hgot
->root
.u
.def
.value
);
3785 /* Find the segment number in which OSEC, and output section, is
3789 sh_elf_osec_to_segment (bfd
*output_bfd
, asection
*osec
)
3791 Elf_Internal_Phdr
*p
= _bfd_elf_find_segment_containing_section (output_bfd
,
3794 /* FIXME: Nothing ever says what this index is relative to. The kernel
3795 supplies data in terms of the number of load segments but this is
3796 a phdr index and the first phdr may not be a load segment. */
3797 return (p
!= NULL
) ? p
- elf_tdata (output_bfd
)->phdr
: -1;
3801 sh_elf_osec_readonly_p (bfd
*output_bfd
, asection
*osec
)
3803 unsigned seg
= sh_elf_osec_to_segment (output_bfd
, osec
);
3805 return ! (elf_tdata (output_bfd
)->phdr
[seg
].p_flags
& PF_W
);
3808 /* Generate the initial contents of a local function descriptor, along
3809 with any relocations or fixups required. */
3811 sh_elf_initialize_funcdesc (bfd
*output_bfd
,
3812 struct bfd_link_info
*info
,
3813 struct elf_link_hash_entry
*h
,
3818 struct elf_sh_link_hash_table
*htab
;
3822 htab
= sh_elf_hash_table (info
);
3824 /* FIXME: The ABI says that the offset to the function goes in the
3825 descriptor, along with the segment index. We're RELA, so it could
3826 go in the reloc instead... */
3828 if (h
!= NULL
&& SYMBOL_CALLS_LOCAL (info
, h
))
3830 section
= h
->root
.u
.def
.section
;
3831 value
= h
->root
.u
.def
.value
;
3834 if (h
== NULL
|| SYMBOL_CALLS_LOCAL (info
, h
))
3836 dynindx
= elf_section_data (section
->output_section
)->dynindx
;
3837 addr
= value
+ section
->output_offset
;
3838 seg
= sh_elf_osec_to_segment (output_bfd
, section
->output_section
);
3842 BFD_ASSERT (h
->dynindx
!= -1);
3843 dynindx
= h
->dynindx
;
3847 if (!info
->shared
&& SYMBOL_CALLS_LOCAL (info
, h
))
3849 if (h
== NULL
|| h
->root
.type
!= bfd_link_hash_undefweak
)
3851 sh_elf_add_rofixup (output_bfd
, htab
->srofixup
,
3853 + htab
->sfuncdesc
->output_section
->vma
3854 + htab
->sfuncdesc
->output_offset
);
3855 sh_elf_add_rofixup (output_bfd
, htab
->srofixup
,
3857 + htab
->sfuncdesc
->output_section
->vma
3858 + htab
->sfuncdesc
->output_offset
);
3861 /* There are no dynamic relocations so fill in the final
3862 address and gp value (barring fixups). */
3863 addr
+= section
->output_section
->vma
;
3864 seg
= htab
->root
.hgot
->root
.u
.def
.value
3865 + htab
->root
.hgot
->root
.u
.def
.section
->output_section
->vma
3866 + htab
->root
.hgot
->root
.u
.def
.section
->output_offset
;
3869 sh_elf_add_dyn_reloc (output_bfd
, htab
->srelfuncdesc
,
3871 + htab
->sfuncdesc
->output_section
->vma
3872 + htab
->sfuncdesc
->output_offset
,
3873 R_SH_FUNCDESC_VALUE
, dynindx
, 0);
3875 bfd_put_32 (output_bfd
, addr
, htab
->sfuncdesc
->contents
+ offset
);
3876 bfd_put_32 (output_bfd
, seg
, htab
->sfuncdesc
->contents
+ offset
+ 4);
3881 /* Install a 20-bit movi20 field starting at ADDR, which occurs in OUTPUT_BFD.
3882 VALUE is the field's value. Return bfd_reloc_ok if successful or an error
3885 static bfd_reloc_status_type
3886 install_movi20_field (bfd
*output_bfd
, unsigned long relocation
,
3887 bfd
*input_bfd
, asection
*input_section
,
3888 bfd_byte
*contents
, bfd_vma offset
)
3890 unsigned long cur_val
;
3892 bfd_reloc_status_type r
;
3894 if (offset
> bfd_get_section_limit (input_bfd
, input_section
))
3895 return bfd_reloc_outofrange
;
3897 r
= bfd_check_overflow (complain_overflow_signed
, 20, 0,
3898 bfd_arch_bits_per_address (input_bfd
), relocation
);
3899 if (r
!= bfd_reloc_ok
)
3902 addr
= contents
+ offset
;
3903 cur_val
= bfd_get_16 (output_bfd
, addr
);
3904 bfd_put_16 (output_bfd
, cur_val
| ((relocation
& 0xf0000) >> 12), addr
);
3905 bfd_put_16 (output_bfd
, relocation
& 0xffff, addr
+ 2);
3907 return bfd_reloc_ok
;
3910 /* Relocate an SH ELF section. */
3913 sh_elf_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
3914 bfd
*input_bfd
, asection
*input_section
,
3915 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
3916 Elf_Internal_Sym
*local_syms
,
3917 asection
**local_sections
)
3919 struct elf_sh_link_hash_table
*htab
;
3920 Elf_Internal_Shdr
*symtab_hdr
;
3921 struct elf_link_hash_entry
**sym_hashes
;
3922 Elf_Internal_Rela
*rel
, *relend
;
3924 bfd_vma
*local_got_offsets
;
3925 asection
*sgot
= NULL
;
3926 asection
*sgotplt
= NULL
;
3927 asection
*splt
= NULL
;
3928 asection
*sreloc
= NULL
;
3929 asection
*srelgot
= NULL
;
3930 bfd_boolean is_vxworks_tls
;
3931 unsigned isec_segment
, got_segment
, plt_segment
, check_segment
[2];
3932 bfd_boolean fdpic_p
= FALSE
;
3934 BFD_ASSERT (is_sh_elf (input_bfd
));
3936 htab
= sh_elf_hash_table (info
);
3939 dynobj
= htab
->root
.dynobj
;
3941 sgotplt
= htab
->sgotplt
;
3943 fdpic_p
= htab
->fdpic_p
;
3945 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
3946 sym_hashes
= elf_sym_hashes (input_bfd
);
3947 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3949 isec_segment
= sh_elf_osec_to_segment (output_bfd
,
3950 input_section
->output_section
);
3951 if (fdpic_p
&& sgot
)
3952 got_segment
= sh_elf_osec_to_segment (output_bfd
,
3953 sgot
->output_section
);
3956 if (fdpic_p
&& splt
)
3957 plt_segment
= sh_elf_osec_to_segment (output_bfd
,
3958 splt
->output_section
);
3962 /* We have to handle relocations in vxworks .tls_vars sections
3963 specially, because the dynamic loader is 'weird'. */
3964 is_vxworks_tls
= (htab
&& htab
->vxworks_p
&& info
->shared
3965 && !strcmp (input_section
->output_section
->name
,
3969 relend
= relocs
+ input_section
->reloc_count
;
3970 for (; rel
< relend
; rel
++)
3973 reloc_howto_type
*howto
;
3974 unsigned long r_symndx
;
3975 Elf_Internal_Sym
*sym
;
3977 struct elf_link_hash_entry
*h
;
3979 bfd_vma addend
= (bfd_vma
) 0;
3980 bfd_reloc_status_type r
;
3981 int seen_stt_datalabel
= 0;
3984 const char *symname
= NULL
;
3986 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3988 r_type
= ELF32_R_TYPE (rel
->r_info
);
3990 /* Many of the relocs are only used for relaxing, and are
3991 handled entirely by the relaxation code. */
3992 if (r_type
>= (int) R_SH_GNU_VTINHERIT
3993 && r_type
<= (int) R_SH_LABEL
)
3995 if (r_type
== (int) R_SH_NONE
)
3999 || r_type
>= R_SH_max
4000 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC
4001 && r_type
<= (int) R_SH_LAST_INVALID_RELOC
)
4002 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC_2
4003 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_2
)
4004 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_3
4005 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_3
)
4006 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_4
4007 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_4
)
4008 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_5
4009 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_5
)
4010 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_6
4011 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_6
))
4013 bfd_set_error (bfd_error_bad_value
);
4017 howto
= get_howto_table (output_bfd
) + r_type
;
4019 /* For relocs that aren't partial_inplace, we get the addend from
4021 if (! howto
->partial_inplace
)
4022 addend
= rel
->r_addend
;
4027 check_segment
[0] = -1;
4028 check_segment
[1] = -1;
4029 if (r_symndx
< symtab_hdr
->sh_info
)
4031 sym
= local_syms
+ r_symndx
;
4032 sec
= local_sections
[r_symndx
];
4034 symname
= bfd_elf_string_from_elf_section
4035 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
);
4036 if (symname
== NULL
|| *symname
== '\0')
4037 symname
= bfd_section_name (input_bfd
, sec
);
4039 relocation
= (sec
->output_section
->vma
4040 + sec
->output_offset
4042 /* A local symbol never has STO_SH5_ISA32, so we don't need
4043 datalabel processing here. Make sure this does not change
4045 if ((sym
->st_other
& STO_SH5_ISA32
) != 0)
4046 ((*info
->callbacks
->reloc_dangerous
)
4048 _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
4049 input_bfd
, input_section
, rel
->r_offset
));
4051 if (sec
!= NULL
&& elf_discarded_section (sec
))
4052 /* Handled below. */
4054 else if (info
->relocatable
)
4056 /* This is a relocatable link. We don't have to change
4057 anything, unless the reloc is against a section symbol,
4058 in which case we have to adjust according to where the
4059 section symbol winds up in the output section. */
4060 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4062 if (! howto
->partial_inplace
)
4064 /* For relocations with the addend in the
4065 relocation, we need just to update the addend.
4066 All real relocs are of type partial_inplace; this
4067 code is mostly for completeness. */
4068 rel
->r_addend
+= sec
->output_offset
;
4073 /* Relocs of type partial_inplace need to pick up the
4074 contents in the contents and add the offset resulting
4075 from the changed location of the section symbol.
4076 Using _bfd_final_link_relocate (e.g. goto
4077 final_link_relocate) here would be wrong, because
4078 relocations marked pc_relative would get the current
4079 location subtracted, and we must only do that at the
4081 r
= _bfd_relocate_contents (howto
, input_bfd
,
4084 contents
+ rel
->r_offset
);
4085 goto relocation_done
;
4090 else if (! howto
->partial_inplace
)
4092 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
4093 addend
= rel
->r_addend
;
4095 else if ((sec
->flags
& SEC_MERGE
)
4096 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4100 if (howto
->rightshift
|| howto
->src_mask
!= 0xffffffff)
4102 (*_bfd_error_handler
)
4103 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
4104 input_bfd
, input_section
,
4105 (long) rel
->r_offset
, howto
->name
);
4109 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4112 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
4114 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
4115 bfd_put_32 (input_bfd
, addend
, contents
+ rel
->r_offset
);
4121 /* FIXME: Ought to make use of the RELOC_FOR_GLOBAL_SYMBOL macro. */
4124 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4125 symname
= h
->root
.root
.string
;
4126 while (h
->root
.type
== bfd_link_hash_indirect
4127 || h
->root
.type
== bfd_link_hash_warning
)
4129 #ifdef INCLUDE_SHMEDIA
4130 /* If the reference passes a symbol marked with
4131 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
4133 seen_stt_datalabel
|= h
->type
== STT_DATALABEL
;
4135 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4137 if (h
->root
.type
== bfd_link_hash_defined
4138 || h
->root
.type
== bfd_link_hash_defweak
)
4142 dyn
= htab
? htab
->root
.dynamic_sections_created
: FALSE
;
4143 sec
= h
->root
.u
.def
.section
;
4144 /* In these cases, we don't need the relocation value.
4145 We check specially because in some obscure cases
4146 sec->output_section will be NULL. */
4147 if (r_type
== R_SH_GOTPC
4148 || r_type
== R_SH_GOTPC_LOW16
4149 || r_type
== R_SH_GOTPC_MEDLOW16
4150 || r_type
== R_SH_GOTPC_MEDHI16
4151 || r_type
== R_SH_GOTPC_HI16
4152 || ((r_type
== R_SH_PLT32
4153 || r_type
== R_SH_PLT_LOW16
4154 || r_type
== R_SH_PLT_MEDLOW16
4155 || r_type
== R_SH_PLT_MEDHI16
4156 || r_type
== R_SH_PLT_HI16
)
4157 && h
->plt
.offset
!= (bfd_vma
) -1)
4158 || ((r_type
== R_SH_GOT32
4159 || r_type
== R_SH_GOT20
4160 || r_type
== R_SH_GOTFUNCDESC
4161 || r_type
== R_SH_GOTFUNCDESC20
4162 || r_type
== R_SH_GOTOFFFUNCDESC
4163 || r_type
== R_SH_GOTOFFFUNCDESC20
4164 || r_type
== R_SH_FUNCDESC
4165 || r_type
== R_SH_GOT_LOW16
4166 || r_type
== R_SH_GOT_MEDLOW16
4167 || r_type
== R_SH_GOT_MEDHI16
4168 || r_type
== R_SH_GOT_HI16
)
4169 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
4171 || (! info
->symbolic
&& h
->dynindx
!= -1)
4172 || !h
->def_regular
))
4173 /* The cases above are those in which relocation is
4174 overwritten in the switch block below. The cases
4175 below are those in which we must defer relocation
4176 to run-time, because we can't resolve absolute
4177 addresses when creating a shared library. */
4179 && ((! info
->symbolic
&& h
->dynindx
!= -1)
4181 && ((r_type
== R_SH_DIR32
4182 && !h
->forced_local
)
4183 || (r_type
== R_SH_REL32
4184 && !SYMBOL_CALLS_LOCAL (info
, h
)))
4185 && ((input_section
->flags
& SEC_ALLOC
) != 0
4186 /* DWARF will emit R_SH_DIR32 relocations in its
4187 sections against symbols defined externally
4188 in shared libraries. We can't do anything
4190 || ((input_section
->flags
& SEC_DEBUGGING
) != 0
4191 && h
->def_dynamic
)))
4192 /* Dynamic relocs are not propagated for SEC_DEBUGGING
4193 sections because such sections are not SEC_ALLOC and
4194 thus ld.so will not process them. */
4195 || (sec
->output_section
== NULL
4196 && ((input_section
->flags
& SEC_DEBUGGING
) != 0
4198 || (sec
->output_section
== NULL
4199 && (sh_elf_hash_entry (h
)->got_type
== GOT_TLS_IE
4200 || sh_elf_hash_entry (h
)->got_type
== GOT_TLS_GD
)))
4202 else if (sec
->output_section
!= NULL
)
4203 relocation
= ((h
->root
.u
.def
.value
4204 + sec
->output_section
->vma
4205 + sec
->output_offset
)
4206 /* A STO_SH5_ISA32 causes a "bitor 1" to the
4207 symbol value, unless we've seen
4208 STT_DATALABEL on the way to it. */
4209 | ((h
->other
& STO_SH5_ISA32
) != 0
4210 && ! seen_stt_datalabel
));
4211 else if (!info
->relocatable
)
4213 (*_bfd_error_handler
)
4214 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4217 (long) rel
->r_offset
,
4219 h
->root
.root
.string
);
4223 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4225 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
4226 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
4228 else if (!info
->relocatable
)
4230 if (! info
->callbacks
->undefined_symbol
4231 (info
, h
->root
.root
.string
, input_bfd
,
4232 input_section
, rel
->r_offset
,
4233 (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
4234 || ELF_ST_VISIBILITY (h
->other
))))
4239 if (sec
!= NULL
&& elf_discarded_section (sec
))
4240 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
4241 rel
, relend
, howto
, contents
);
4243 if (info
->relocatable
)
4246 /* Check for inter-segment relocations in FDPIC files. Most
4247 relocations connect the relocation site to the location of
4248 the target symbol, but there are some exceptions below. */
4249 check_segment
[0] = isec_segment
;
4251 check_segment
[1] = sh_elf_osec_to_segment (output_bfd
,
4252 sec
->output_section
);
4254 check_segment
[1] = -1;
4256 switch ((int) r_type
)
4258 final_link_relocate
:
4259 /* COFF relocs don't use the addend. The addend is used for
4260 R_SH_DIR32 to be compatible with other compilers. */
4261 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4262 contents
, rel
->r_offset
,
4263 relocation
, addend
);
4267 goto final_link_relocate
;
4272 /* If the reloc is against the start of this section, then
4273 the assembler has already taken care of it and the reloc
4274 is here only to assist in relaxing. If the reloc is not
4275 against the start of this section, then it's against an
4276 external symbol and we must deal with it ourselves. */
4277 if (input_section
->output_section
->vma
+ input_section
->output_offset
4280 int disp
= (relocation
4281 - input_section
->output_section
->vma
4282 - input_section
->output_offset
4288 case R_SH_DIR8WPZ
: mask
= 1; break;
4289 case R_SH_DIR8WPL
: mask
= 3; break;
4290 default: mask
= 0; break;
4294 ((*_bfd_error_handler
)
4295 (_("%B: 0x%lx: fatal: unaligned branch target for relax-support relocation"),
4296 input_section
->owner
,
4297 (unsigned long) rel
->r_offset
));
4298 bfd_set_error (bfd_error_bad_value
);
4302 goto final_link_relocate
;
4308 #ifdef INCLUDE_SHMEDIA
4309 if (shmedia_prepare_reloc (info
, input_bfd
, input_section
,
4310 contents
, rel
, &relocation
))
4311 goto final_link_relocate
;
4313 bfd_set_error (bfd_error_bad_value
);
4321 goto final_link_relocate
;
4327 ((*_bfd_error_handler
)
4328 (_("%B: 0x%lx: fatal: unaligned %s relocation 0x%lx"),
4329 input_section
->owner
,
4330 (unsigned long) rel
->r_offset
, howto
->name
,
4331 (unsigned long) relocation
));
4332 bfd_set_error (bfd_error_bad_value
);
4335 goto final_link_relocate
;
4342 ((*_bfd_error_handler
)
4343 (_("%B: 0x%lx: fatal: unaligned %s relocation 0x%lx"),
4344 input_section
->owner
,
4345 (unsigned long) rel
->r_offset
, howto
->name
,
4346 (unsigned long) relocation
));
4347 bfd_set_error (bfd_error_bad_value
);
4350 goto final_link_relocate
;
4353 if ((signed int)relocation
< -32
4354 || (signed int)relocation
> 32)
4356 ((*_bfd_error_handler
)
4357 (_("%B: 0x%lx: fatal: R_SH_PSHA relocation %d not in range -32..32"),
4358 input_section
->owner
,
4359 (unsigned long) rel
->r_offset
,
4360 (unsigned long) relocation
));
4361 bfd_set_error (bfd_error_bad_value
);
4364 goto final_link_relocate
;
4367 if ((signed int)relocation
< -16
4368 || (signed int)relocation
> 16)
4370 ((*_bfd_error_handler
)
4371 (_("%B: 0x%lx: fatal: R_SH_PSHL relocation %d not in range -32..32"),
4372 input_section
->owner
,
4373 (unsigned long) rel
->r_offset
,
4374 (unsigned long) relocation
));
4375 bfd_set_error (bfd_error_bad_value
);
4378 goto final_link_relocate
;
4382 #ifdef INCLUDE_SHMEDIA
4383 case R_SH_IMM_LOW16_PCREL
:
4384 case R_SH_IMM_MEDLOW16_PCREL
:
4385 case R_SH_IMM_MEDHI16_PCREL
:
4386 case R_SH_IMM_HI16_PCREL
:
4390 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4391 || h
->root
.type
!= bfd_link_hash_undefweak
)
4392 && r_symndx
!= STN_UNDEF
4393 && (input_section
->flags
& SEC_ALLOC
) != 0
4395 && (r_type
== R_SH_DIR32
4396 || !SYMBOL_CALLS_LOCAL (info
, h
)))
4398 Elf_Internal_Rela outrel
;
4400 bfd_boolean skip
, relocate
;
4402 /* When generating a shared object, these relocations
4403 are copied into the output file to be resolved at run
4408 sreloc
= _bfd_elf_get_dynamic_reloc_section
4409 (input_bfd
, input_section
, /*rela?*/ TRUE
);
4418 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4420 if (outrel
.r_offset
== (bfd_vma
) -1)
4422 else if (outrel
.r_offset
== (bfd_vma
) -2)
4423 skip
= TRUE
, relocate
= TRUE
;
4424 outrel
.r_offset
+= (input_section
->output_section
->vma
4425 + input_section
->output_offset
);
4428 memset (&outrel
, 0, sizeof outrel
);
4429 else if (r_type
== R_SH_REL32
)
4431 BFD_ASSERT (h
!= NULL
&& h
->dynindx
!= -1);
4432 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_REL32
);
4434 = (howto
->partial_inplace
4435 ? bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
)
4438 #ifdef INCLUDE_SHMEDIA
4439 else if (r_type
== R_SH_IMM_LOW16_PCREL
4440 || r_type
== R_SH_IMM_MEDLOW16_PCREL
4441 || r_type
== R_SH_IMM_MEDHI16_PCREL
4442 || r_type
== R_SH_IMM_HI16_PCREL
)
4444 BFD_ASSERT (h
!= NULL
&& h
->dynindx
!= -1);
4445 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
4446 outrel
.r_addend
= addend
;
4451 || ((info
->symbolic
|| h
->dynindx
== -1)
4452 && h
->def_regular
)))
4456 BFD_ASSERT (sec
!= NULL
);
4457 BFD_ASSERT (sec
->output_section
!= NULL
);
4458 dynindx
= elf_section_data (sec
->output_section
)->dynindx
;
4459 outrel
.r_info
= ELF32_R_INFO (dynindx
, R_SH_DIR32
);
4460 outrel
.r_addend
= relocation
;
4462 += (howto
->partial_inplace
4463 ? bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
)
4465 outrel
.r_addend
-= sec
->output_section
->vma
;
4469 /* h->dynindx may be -1 if this symbol was marked to
4472 || ((info
->symbolic
|| h
->dynindx
== -1)
4475 relocate
= howto
->partial_inplace
;
4476 outrel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
4480 BFD_ASSERT (h
->dynindx
!= -1);
4481 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_DIR32
);
4483 outrel
.r_addend
= relocation
;
4485 += (howto
->partial_inplace
4486 ? bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
)
4490 loc
= sreloc
->contents
;
4491 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4492 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4494 check_segment
[0] = check_segment
[1] = -1;
4496 /* If this reloc is against an external symbol, we do
4497 not want to fiddle with the addend. Otherwise, we
4498 need to include the symbol value so that it becomes
4499 an addend for the dynamic reloc. */
4503 else if (fdpic_p
&& !info
->shared
4504 && r_type
== R_SH_DIR32
4505 && (input_section
->flags
& SEC_ALLOC
) != 0)
4511 if (sh_elf_osec_readonly_p (output_bfd
,
4512 input_section
->output_section
))
4514 (*_bfd_error_handler
)
4515 (_("%B(%A+0x%lx): cannot emit fixup to `%s' in read-only section"),
4518 (long) rel
->r_offset
,
4523 offset
= _bfd_elf_section_offset (output_bfd
, info
,
4524 input_section
, rel
->r_offset
);
4525 if (offset
!= (bfd_vma
)-1)
4526 sh_elf_add_rofixup (output_bfd
, htab
->srofixup
,
4527 input_section
->output_section
->vma
4528 + input_section
->output_offset
4531 check_segment
[0] = check_segment
[1] = -1;
4533 goto final_link_relocate
;
4536 #ifdef INCLUDE_SHMEDIA
4537 case R_SH_GOTPLT_LOW16
:
4538 case R_SH_GOTPLT_MEDLOW16
:
4539 case R_SH_GOTPLT_MEDHI16
:
4540 case R_SH_GOTPLT_HI16
:
4541 case R_SH_GOTPLT10BY4
:
4542 case R_SH_GOTPLT10BY8
:
4544 /* Relocation is to the entry for this symbol in the
4545 procedure linkage table. */
4552 || h
->plt
.offset
== (bfd_vma
) -1
4553 || h
->got
.offset
!= (bfd_vma
) -1)
4556 /* Relocation is to the entry for this symbol in the global
4557 offset table extension for the procedure linkage table. */
4560 BFD_ASSERT (sgotplt
!= NULL
);
4561 relocation
= (sgotplt
->output_offset
4562 + (get_plt_index (htab
->plt_info
, h
->plt
.offset
)
4566 relocation
-= GOT_BIAS
;
4569 goto final_link_relocate
;
4574 #ifdef INCLUDE_SHMEDIA
4575 case R_SH_GOT_LOW16
:
4576 case R_SH_GOT_MEDLOW16
:
4577 case R_SH_GOT_MEDHI16
:
4582 /* Relocation is to the entry for this symbol in the global
4586 BFD_ASSERT (sgot
!= NULL
);
4587 check_segment
[0] = check_segment
[1] = -1;
4593 off
= h
->got
.offset
;
4594 #ifdef INCLUDE_SHMEDIA
4595 if (seen_stt_datalabel
)
4597 struct elf_sh_link_hash_entry
*hsh
;
4599 hsh
= (struct elf_sh_link_hash_entry
*)h
;
4600 off
= hsh
->datalabel_got
.offset
;
4603 BFD_ASSERT (off
!= (bfd_vma
) -1);
4605 dyn
= htab
->root
.dynamic_sections_created
;
4606 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
4608 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4609 || (ELF_ST_VISIBILITY (h
->other
)
4610 && h
->root
.type
== bfd_link_hash_undefweak
))
4612 /* This is actually a static link, or it is a
4613 -Bsymbolic link and the symbol is defined
4614 locally, or the symbol was forced to be local
4615 because of a version file. We must initialize
4616 this entry in the global offset table. Since the
4617 offset must always be a multiple of 4, we use the
4618 least significant bit to record whether we have
4619 initialized it already.
4621 When doing a dynamic link, we create a .rela.got
4622 relocation entry to initialize the value. This
4623 is done in the finish_dynamic_symbol routine. */
4628 bfd_put_32 (output_bfd
, relocation
,
4629 sgot
->contents
+ off
);
4630 #ifdef INCLUDE_SHMEDIA
4631 if (seen_stt_datalabel
)
4633 struct elf_sh_link_hash_entry
*hsh
;
4635 hsh
= (struct elf_sh_link_hash_entry
*)h
;
4636 hsh
->datalabel_got
.offset
|= 1;
4642 /* If we initialize the GOT entry here with a valid
4643 symbol address, also add a fixup. */
4644 if (fdpic_p
&& !info
->shared
4645 && sh_elf_hash_entry (h
)->got_type
== GOT_NORMAL
4646 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4647 || h
->root
.type
!= bfd_link_hash_undefweak
))
4648 sh_elf_add_rofixup (output_bfd
, htab
->srofixup
,
4649 sgot
->output_section
->vma
4650 + sgot
->output_offset
4655 relocation
= sh_elf_got_offset (htab
) + off
;
4659 #ifdef INCLUDE_SHMEDIA
4662 BFD_ASSERT (local_got_offsets
!= NULL
4663 && (local_got_offsets
[symtab_hdr
->sh_info
4667 off
= local_got_offsets
[symtab_hdr
->sh_info
4673 BFD_ASSERT (local_got_offsets
!= NULL
4674 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
4676 off
= local_got_offsets
[r_symndx
];
4677 #ifdef INCLUDE_SHMEDIA
4681 /* The offset must always be a multiple of 4. We use
4682 the least significant bit to record whether we have
4683 already generated the necessary reloc. */
4688 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
4692 Elf_Internal_Rela outrel
;
4695 if (srelgot
== NULL
)
4697 srelgot
= bfd_get_section_by_name (dynobj
,
4699 BFD_ASSERT (srelgot
!= NULL
);
4702 outrel
.r_offset
= (sgot
->output_section
->vma
4703 + sgot
->output_offset
4708 = elf_section_data (sec
->output_section
)->dynindx
;
4709 outrel
.r_info
= ELF32_R_INFO (dynindx
, R_SH_DIR32
);
4710 outrel
.r_addend
= relocation
;
4711 outrel
.r_addend
-= sec
->output_section
->vma
;
4715 outrel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
4716 outrel
.r_addend
= relocation
;
4718 loc
= srelgot
->contents
;
4719 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4720 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4723 && (sh_elf_local_got_type (input_bfd
) [r_symndx
]
4725 sh_elf_add_rofixup (output_bfd
, htab
->srofixup
,
4726 sgot
->output_section
->vma
4727 + sgot
->output_offset
4730 #ifdef INCLUDE_SHMEDIA
4732 local_got_offsets
[symtab_hdr
->sh_info
+ r_symndx
] |= 1;
4735 local_got_offsets
[r_symndx
] |= 1;
4738 relocation
= sh_elf_got_offset (htab
) + off
;
4742 relocation
-= GOT_BIAS
;
4745 if (r_type
== R_SH_GOT20
)
4747 r
= install_movi20_field (output_bfd
, relocation
+ addend
,
4748 input_bfd
, input_section
, contents
,
4753 goto final_link_relocate
;
4757 #ifdef INCLUDE_SHMEDIA
4758 case R_SH_GOTOFF_LOW16
:
4759 case R_SH_GOTOFF_MEDLOW16
:
4760 case R_SH_GOTOFF_MEDHI16
:
4761 case R_SH_GOTOFF_HI16
:
4763 /* GOTOFF relocations are relative to _GLOBAL_OFFSET_TABLE_, which
4764 we place at the start of the .got.plt section. This is the same
4765 as the start of the output .got section, unless there are function
4766 descriptors in front of it. */
4768 BFD_ASSERT (sgotplt
!= NULL
);
4769 check_segment
[0] = got_segment
;
4770 relocation
-= sgotplt
->output_section
->vma
+ sgotplt
->output_offset
4771 + htab
->root
.hgot
->root
.u
.def
.value
;
4774 relocation
-= GOT_BIAS
;
4777 addend
= rel
->r_addend
;
4779 if (r_type
== R_SH_GOTOFF20
)
4781 r
= install_movi20_field (output_bfd
, relocation
+ addend
,
4782 input_bfd
, input_section
, contents
,
4787 goto final_link_relocate
;
4790 #ifdef INCLUDE_SHMEDIA
4791 case R_SH_GOTPC_LOW16
:
4792 case R_SH_GOTPC_MEDLOW16
:
4793 case R_SH_GOTPC_MEDHI16
:
4794 case R_SH_GOTPC_HI16
:
4796 /* Use global offset table as symbol value. */
4798 BFD_ASSERT (sgotplt
!= NULL
);
4799 relocation
= sgotplt
->output_section
->vma
+ sgotplt
->output_offset
;
4802 relocation
+= GOT_BIAS
;
4805 addend
= rel
->r_addend
;
4807 goto final_link_relocate
;
4810 #ifdef INCLUDE_SHMEDIA
4811 case R_SH_PLT_LOW16
:
4812 case R_SH_PLT_MEDLOW16
:
4813 case R_SH_PLT_MEDHI16
:
4816 /* Relocation is to the entry for this symbol in the
4817 procedure linkage table. */
4819 /* Resolve a PLT reloc against a local symbol directly,
4820 without using the procedure linkage table. */
4822 goto final_link_relocate
;
4824 /* We don't want to warn on calls to undefined weak symbols,
4825 as calls to them must be protected by non-NULL tests
4826 anyway, and unprotected calls would invoke undefined
4828 if (h
->root
.type
== bfd_link_hash_undefweak
)
4829 check_segment
[0] = check_segment
[1] = -1;
4831 if (h
->forced_local
)
4832 goto final_link_relocate
;
4834 if (h
->plt
.offset
== (bfd_vma
) -1)
4836 /* We didn't make a PLT entry for this symbol. This
4837 happens when statically linking PIC code, or when
4838 using -Bsymbolic. */
4839 goto final_link_relocate
;
4842 BFD_ASSERT (splt
!= NULL
);
4843 check_segment
[1] = plt_segment
;
4844 relocation
= (splt
->output_section
->vma
4845 + splt
->output_offset
4848 #ifdef INCLUDE_SHMEDIA
4852 addend
= rel
->r_addend
;
4854 goto final_link_relocate
;
4856 /* Relocation is to the canonical function descriptor for this
4857 symbol, possibly via the GOT. Initialize the GOT
4858 entry and function descriptor if necessary. */
4859 case R_SH_GOTFUNCDESC
:
4860 case R_SH_GOTFUNCDESC20
:
4864 asection
*reloc_section
;
4865 bfd_vma reloc_offset
;
4866 int reloc_type
= R_SH_FUNCDESC
;
4870 check_segment
[0] = check_segment
[1] = -1;
4872 /* FIXME: See what FRV does for global symbols in the
4873 executable, with --export-dynamic. Do they need ld.so
4874 to allocate official descriptors? See what this code
4880 if (r_type
== R_SH_FUNCDESC
)
4882 reloc_section
= input_section
;
4883 reloc_offset
= rel
->r_offset
;
4887 reloc_section
= sgot
;
4890 reloc_offset
= h
->got
.offset
;
4893 BFD_ASSERT (local_got_offsets
!= NULL
);
4894 reloc_offset
= local_got_offsets
[r_symndx
];
4896 BFD_ASSERT (reloc_offset
!= MINUS_ONE
);
4898 if (reloc_offset
& 1)
4901 goto funcdesc_done_got
;
4905 if (h
&& h
->root
.type
== bfd_link_hash_undefweak
4906 && (SYMBOL_CALLS_LOCAL (info
, h
)
4907 || !htab
->root
.dynamic_sections_created
))
4908 /* Undefined weak symbol which will not be dynamically
4909 resolved later; leave it at zero. */
4910 goto funcdesc_leave_zero
;
4911 else if (SYMBOL_CALLS_LOCAL (info
, h
)
4912 && ! SYMBOL_FUNCDESC_LOCAL (info
, h
))
4914 /* If the symbol needs a non-local function descriptor
4915 but binds locally (i.e., its visibility is
4916 protected), emit a dynamic relocation decayed to
4917 section+offset. This is an optimization; the dynamic
4918 linker would resolve our function descriptor request
4919 to our copy of the function anyway. */
4920 dynindx
= elf_section_data (h
->root
.u
.def
.section
4921 ->output_section
)->dynindx
;
4922 relocation
+= h
->root
.u
.def
.section
->output_offset
4923 + h
->root
.u
.def
.value
;
4925 else if (! SYMBOL_FUNCDESC_LOCAL (info
, h
))
4927 /* If the symbol is dynamic and there will be dynamic
4928 symbol resolution because we are or are linked with a
4929 shared library, emit a FUNCDESC relocation such that
4930 the dynamic linker will allocate the function
4932 BFD_ASSERT (h
->dynindx
!= -1);
4933 dynindx
= h
->dynindx
;
4939 /* Otherwise, we know we have a private function
4940 descriptor, so reference it directly. */
4941 reloc_type
= R_SH_DIR32
;
4942 dynindx
= elf_section_data (htab
->sfuncdesc
4943 ->output_section
)->dynindx
;
4947 offset
= sh_elf_hash_entry (h
)->funcdesc
.offset
;
4948 BFD_ASSERT (offset
!= MINUS_ONE
);
4949 if ((offset
& 1) == 0)
4951 if (!sh_elf_initialize_funcdesc (output_bfd
, info
, h
,
4954 sh_elf_hash_entry (h
)->funcdesc
.offset
|= 1;
4959 union gotref
*local_funcdesc
;
4961 local_funcdesc
= sh_elf_local_funcdesc (input_bfd
);
4962 offset
= local_funcdesc
[r_symndx
].offset
;
4963 BFD_ASSERT (offset
!= MINUS_ONE
);
4964 if ((offset
& 1) == 0)
4966 if (!sh_elf_initialize_funcdesc (output_bfd
, info
, NULL
,
4970 local_funcdesc
[r_symndx
].offset
|= 1;
4974 relocation
= htab
->sfuncdesc
->output_offset
+ (offset
& ~1);
4977 if (!info
->shared
&& SYMBOL_FUNCDESC_LOCAL (info
, h
))
4981 if (sh_elf_osec_readonly_p (output_bfd
,
4982 reloc_section
->output_section
))
4984 (*_bfd_error_handler
)
4985 (_("%B(%A+0x%lx): cannot emit fixup to `%s' in read-only section"),
4988 (long) rel
->r_offset
,
4993 offset
= _bfd_elf_section_offset (output_bfd
, info
,
4994 reloc_section
, reloc_offset
);
4996 if (offset
!= (bfd_vma
)-1)
4997 sh_elf_add_rofixup (output_bfd
, htab
->srofixup
,
4999 + reloc_section
->output_section
->vma
5000 + reloc_section
->output_offset
);
5002 else if ((reloc_section
->output_section
->flags
5003 & (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
5007 if (sh_elf_osec_readonly_p (output_bfd
,
5008 reloc_section
->output_section
))
5010 info
->callbacks
->warning
5012 _("cannot emit dynamic relocations in read-only section"),
5013 symname
, input_bfd
, reloc_section
, reloc_offset
);
5017 if (srelgot
== NULL
)
5019 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
5020 BFD_ASSERT (srelgot
!= NULL
);
5023 offset
= _bfd_elf_section_offset (output_bfd
, info
,
5024 reloc_section
, reloc_offset
);
5026 if (offset
!= (bfd_vma
)-1)
5027 sh_elf_add_dyn_reloc (output_bfd
, srelgot
,
5029 + reloc_section
->output_section
->vma
5030 + reloc_section
->output_offset
,
5031 reloc_type
, dynindx
, relocation
);
5033 if (r_type
== R_SH_FUNCDESC
)
5041 goto funcdesc_leave_zero
;
5045 if (SYMBOL_FUNCDESC_LOCAL (info
, h
))
5046 relocation
+= htab
->sfuncdesc
->output_section
->vma
;
5047 funcdesc_leave_zero
:
5048 if (r_type
!= R_SH_FUNCDESC
)
5050 bfd_put_32 (output_bfd
, relocation
,
5051 reloc_section
->contents
+ reloc_offset
);
5055 local_got_offsets
[r_symndx
] |= 1;
5059 relocation
= sh_elf_got_offset (htab
) + reloc_offset
;
5061 relocation
-= GOT_BIAS
;
5064 if (r_type
== R_SH_GOTFUNCDESC20
)
5066 r
= install_movi20_field (output_bfd
, relocation
+ addend
,
5067 input_bfd
, input_section
, contents
,
5072 goto final_link_relocate
;
5076 case R_SH_GOTOFFFUNCDESC
:
5077 case R_SH_GOTOFFFUNCDESC20
:
5078 /* FIXME: See R_SH_FUNCDESC comment about global symbols in the
5079 executable and --export-dynamic. If such symbols get
5080 ld.so-allocated descriptors we can not use R_SH_GOTOFFFUNCDESC
5084 check_segment
[0] = check_segment
[1] = -1;
5086 addend
= rel
->r_addend
;
5088 if (h
&& (h
->root
.type
== bfd_link_hash_undefweak
5089 || !SYMBOL_FUNCDESC_LOCAL (info
, h
)))
5092 (_("%B(%A+0x%lx): %s relocation against external symbol \"%s\""),
5093 input_bfd
, input_section
, (long) rel
->r_offset
, howto
->name
,
5094 h
->root
.root
.string
);
5101 /* Otherwise, we know we have a private function
5102 descriptor, so reference it directly. */
5105 offset
= sh_elf_hash_entry (h
)->funcdesc
.offset
;
5106 BFD_ASSERT (offset
!= MINUS_ONE
);
5107 if ((offset
& 1) == 0)
5109 if (!sh_elf_initialize_funcdesc (output_bfd
, info
, h
,
5112 sh_elf_hash_entry (h
)->funcdesc
.offset
|= 1;
5117 union gotref
*local_funcdesc
;
5119 local_funcdesc
= sh_elf_local_funcdesc (input_bfd
);
5120 offset
= local_funcdesc
[r_symndx
].offset
;
5121 BFD_ASSERT (offset
!= MINUS_ONE
);
5122 if ((offset
& 1) == 0)
5124 if (!sh_elf_initialize_funcdesc (output_bfd
, info
, NULL
,
5128 local_funcdesc
[r_symndx
].offset
|= 1;
5132 relocation
= htab
->sfuncdesc
->output_offset
+ (offset
& ~1);
5135 relocation
-= (htab
->root
.hgot
->root
.u
.def
.value
5136 + sgotplt
->output_offset
);
5138 relocation
-= GOT_BIAS
;
5141 if (r_type
== R_SH_GOTOFFFUNCDESC20
)
5143 r
= install_movi20_field (output_bfd
, relocation
+ addend
,
5144 input_bfd
, input_section
, contents
,
5149 goto final_link_relocate
;
5151 case R_SH_LOOP_START
:
5153 static bfd_vma start
, end
;
5155 start
= (relocation
+ rel
->r_addend
5156 - (sec
->output_section
->vma
+ sec
->output_offset
));
5157 r
= sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
,
5158 rel
->r_offset
, sec
, start
, end
);
5162 end
= (relocation
+ rel
->r_addend
5163 - (sec
->output_section
->vma
+ sec
->output_offset
));
5164 r
= sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
,
5165 rel
->r_offset
, sec
, start
, end
);
5169 case R_SH_TLS_GD_32
:
5170 case R_SH_TLS_IE_32
:
5172 check_segment
[0] = check_segment
[1] = -1;
5173 r_type
= sh_elf_optimized_tls_reloc (info
, r_type
, h
== NULL
);
5174 got_type
= GOT_UNKNOWN
;
5175 if (h
== NULL
&& local_got_offsets
)
5176 got_type
= sh_elf_local_got_type (input_bfd
) [r_symndx
];
5179 got_type
= sh_elf_hash_entry (h
)->got_type
;
5181 && (h
->dynindx
== -1
5183 r_type
= R_SH_TLS_LE_32
;
5186 if (r_type
== R_SH_TLS_GD_32
&& got_type
== GOT_TLS_IE
)
5187 r_type
= R_SH_TLS_IE_32
;
5189 if (r_type
== R_SH_TLS_LE_32
)
5192 unsigned short insn
;
5194 if (ELF32_R_TYPE (rel
->r_info
) == R_SH_TLS_GD_32
)
5196 /* GD->LE transition:
5197 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5198 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5199 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5201 mov.l 1f,r4; stc gbr,r0; add r4,r0; nop;
5203 1: .long x@TPOFF; 2: .long __tls_get_addr@PLT; 3:. */
5205 offset
= rel
->r_offset
;
5206 BFD_ASSERT (offset
>= 16);
5207 /* Size of GD instructions is 16 or 18. */
5209 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5210 if ((insn
& 0xff00) == 0xc700)
5212 BFD_ASSERT (offset
>= 2);
5214 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5217 BFD_ASSERT ((insn
& 0xff00) == 0xd400);
5218 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5219 BFD_ASSERT ((insn
& 0xff00) == 0xc700);
5220 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5221 BFD_ASSERT ((insn
& 0xff00) == 0xd100);
5222 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 6);
5223 BFD_ASSERT (insn
== 0x310c);
5224 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 8);
5225 BFD_ASSERT (insn
== 0x410b);
5226 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 10);
5227 BFD_ASSERT (insn
== 0x34cc);
5229 bfd_put_16 (output_bfd
, 0x0012, contents
+ offset
+ 2);
5230 bfd_put_16 (output_bfd
, 0x304c, contents
+ offset
+ 4);
5231 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 6);
5232 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 8);
5233 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 10);
5239 /* IE->LE transition:
5240 mov.l 1f,r0; stc gbr,rN; mov.l @(r0,r12),rM;
5241 bra 2f; add ...; .align 2; 1: x@GOTTPOFF; 2:
5243 mov.l .Ln,rM; stc gbr,rN; nop; ...;
5246 offset
= rel
->r_offset
;
5247 BFD_ASSERT (offset
>= 16);
5248 /* Size of IE instructions is 10 or 12. */
5250 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5251 if ((insn
& 0xf0ff) == 0x0012)
5253 BFD_ASSERT (offset
>= 2);
5255 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5258 BFD_ASSERT ((insn
& 0xff00) == 0xd000);
5259 target
= insn
& 0x00ff;
5260 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5261 BFD_ASSERT ((insn
& 0xf0ff) == 0x0012);
5262 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5263 BFD_ASSERT ((insn
& 0xf0ff) == 0x00ce);
5264 insn
= 0xd000 | (insn
& 0x0f00) | target
;
5265 bfd_put_16 (output_bfd
, insn
, contents
+ offset
+ 0);
5266 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 4);
5269 bfd_put_32 (output_bfd
, tpoff (info
, relocation
),
5270 contents
+ rel
->r_offset
);
5274 if (sgot
== NULL
|| sgotplt
== NULL
)
5278 off
= h
->got
.offset
;
5281 if (local_got_offsets
== NULL
)
5284 off
= local_got_offsets
[r_symndx
];
5287 /* Relocate R_SH_TLS_IE_32 directly when statically linking. */
5288 if (r_type
== R_SH_TLS_IE_32
5289 && ! htab
->root
.dynamic_sections_created
)
5292 bfd_put_32 (output_bfd
, tpoff (info
, relocation
),
5293 sgot
->contents
+ off
);
5294 bfd_put_32 (output_bfd
, sh_elf_got_offset (htab
) + off
,
5295 contents
+ rel
->r_offset
);
5303 Elf_Internal_Rela outrel
;
5307 if (srelgot
== NULL
)
5309 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
5310 BFD_ASSERT (srelgot
!= NULL
);
5313 outrel
.r_offset
= (sgot
->output_section
->vma
5314 + sgot
->output_offset
+ off
);
5316 if (h
== NULL
|| h
->dynindx
== -1)
5321 dr_type
= (r_type
== R_SH_TLS_GD_32
? R_SH_TLS_DTPMOD32
:
5323 if (dr_type
== R_SH_TLS_TPOFF32
&& indx
== 0)
5324 outrel
.r_addend
= relocation
- dtpoff_base (info
);
5326 outrel
.r_addend
= 0;
5327 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
5328 loc
= srelgot
->contents
;
5329 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5330 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5332 if (r_type
== R_SH_TLS_GD_32
)
5336 bfd_put_32 (output_bfd
,
5337 relocation
- dtpoff_base (info
),
5338 sgot
->contents
+ off
+ 4);
5342 outrel
.r_info
= ELF32_R_INFO (indx
,
5344 outrel
.r_offset
+= 4;
5345 outrel
.r_addend
= 0;
5346 srelgot
->reloc_count
++;
5347 loc
+= sizeof (Elf32_External_Rela
);
5348 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5355 local_got_offsets
[r_symndx
] |= 1;
5358 if (off
>= (bfd_vma
) -2)
5361 if (r_type
== (int) ELF32_R_TYPE (rel
->r_info
))
5362 relocation
= sh_elf_got_offset (htab
) + off
;
5366 unsigned short insn
;
5368 /* GD->IE transition:
5369 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5370 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5371 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5373 mov.l 1f,r0; stc gbr,r4; mov.l @(r0,r12),r0; add r4,r0;
5374 nop; nop; bra 3f; nop; .align 2;
5375 1: .long x@TPOFF; 2:...; 3:. */
5377 offset
= rel
->r_offset
;
5378 BFD_ASSERT (offset
>= 16);
5379 /* Size of GD instructions is 16 or 18. */
5381 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5382 if ((insn
& 0xff00) == 0xc700)
5384 BFD_ASSERT (offset
>= 2);
5386 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5389 BFD_ASSERT ((insn
& 0xff00) == 0xd400);
5391 /* Replace mov.l 1f,R4 with mov.l 1f,r0. */
5392 bfd_put_16 (output_bfd
, insn
& 0xf0ff, contents
+ offset
);
5394 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5395 BFD_ASSERT ((insn
& 0xff00) == 0xc700);
5396 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5397 BFD_ASSERT ((insn
& 0xff00) == 0xd100);
5398 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 6);
5399 BFD_ASSERT (insn
== 0x310c);
5400 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 8);
5401 BFD_ASSERT (insn
== 0x410b);
5402 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 10);
5403 BFD_ASSERT (insn
== 0x34cc);
5405 bfd_put_16 (output_bfd
, 0x0412, contents
+ offset
+ 2);
5406 bfd_put_16 (output_bfd
, 0x00ce, contents
+ offset
+ 4);
5407 bfd_put_16 (output_bfd
, 0x304c, contents
+ offset
+ 6);
5408 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 8);
5409 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 10);
5411 bfd_put_32 (output_bfd
, sh_elf_got_offset (htab
) + off
,
5412 contents
+ rel
->r_offset
);
5417 addend
= rel
->r_addend
;
5419 goto final_link_relocate
;
5421 case R_SH_TLS_LD_32
:
5423 check_segment
[0] = check_segment
[1] = -1;
5427 unsigned short insn
;
5429 /* LD->LE transition:
5430 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5431 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5432 1: .long x$TLSLD; 2: .long __tls_get_addr@PLT; 3:
5434 stc gbr,r0; nop; nop; nop;
5435 nop; nop; bra 3f; ...; 3:. */
5437 offset
= rel
->r_offset
;
5438 BFD_ASSERT (offset
>= 16);
5439 /* Size of LD instructions is 16 or 18. */
5441 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5442 if ((insn
& 0xff00) == 0xc700)
5444 BFD_ASSERT (offset
>= 2);
5446 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5449 BFD_ASSERT ((insn
& 0xff00) == 0xd400);
5450 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5451 BFD_ASSERT ((insn
& 0xff00) == 0xc700);
5452 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5453 BFD_ASSERT ((insn
& 0xff00) == 0xd100);
5454 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 6);
5455 BFD_ASSERT (insn
== 0x310c);
5456 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 8);
5457 BFD_ASSERT (insn
== 0x410b);
5458 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 10);
5459 BFD_ASSERT (insn
== 0x34cc);
5461 bfd_put_16 (output_bfd
, 0x0012, contents
+ offset
+ 0);
5462 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 2);
5463 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 4);
5464 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 6);
5465 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 8);
5466 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 10);
5471 if (sgot
== NULL
|| sgotplt
== NULL
)
5474 off
= htab
->tls_ldm_got
.offset
;
5479 Elf_Internal_Rela outrel
;
5482 srelgot
= htab
->srelgot
;
5483 if (srelgot
== NULL
)
5486 outrel
.r_offset
= (sgot
->output_section
->vma
5487 + sgot
->output_offset
+ off
);
5488 outrel
.r_addend
= 0;
5489 outrel
.r_info
= ELF32_R_INFO (0, R_SH_TLS_DTPMOD32
);
5490 loc
= srelgot
->contents
;
5491 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5492 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5493 htab
->tls_ldm_got
.offset
|= 1;
5496 relocation
= sh_elf_got_offset (htab
) + off
;
5497 addend
= rel
->r_addend
;
5499 goto final_link_relocate
;
5501 case R_SH_TLS_LDO_32
:
5502 check_segment
[0] = check_segment
[1] = -1;
5504 relocation
= tpoff (info
, relocation
);
5506 relocation
-= dtpoff_base (info
);
5508 addend
= rel
->r_addend
;
5509 goto final_link_relocate
;
5511 case R_SH_TLS_LE_32
:
5514 Elf_Internal_Rela outrel
;
5517 check_segment
[0] = check_segment
[1] = -1;
5519 if (! info
->shared
|| info
->pie
)
5521 relocation
= tpoff (info
, relocation
);
5522 addend
= rel
->r_addend
;
5523 goto final_link_relocate
;
5528 sreloc
= _bfd_elf_get_dynamic_reloc_section
5529 (input_bfd
, input_section
, /*rela?*/ TRUE
);
5534 if (h
== NULL
|| h
->dynindx
== -1)
5539 outrel
.r_offset
= (input_section
->output_section
->vma
5540 + input_section
->output_offset
5542 outrel
.r_info
= ELF32_R_INFO (indx
, R_SH_TLS_TPOFF32
);
5544 outrel
.r_addend
= relocation
- dtpoff_base (info
);
5546 outrel
.r_addend
= 0;
5548 loc
= sreloc
->contents
;
5549 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5550 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5556 if (fdpic_p
&& check_segment
[0] != (unsigned) -1
5557 && check_segment
[0] != check_segment
[1])
5559 /* We don't want duplicate errors for undefined symbols. */
5560 if (!h
|| h
->root
.type
!= bfd_link_hash_undefined
)
5564 info
->callbacks
->einfo
5565 (_("%X%C: relocation to \"%s\" references a different segment\n"),
5566 input_bfd
, input_section
, rel
->r_offset
, symname
);
5570 info
->callbacks
->einfo
5571 (_("%C: warning: relocation to \"%s\" references a different segment\n"),
5572 input_bfd
, input_section
, rel
->r_offset
, symname
);
5575 elf_elfheader (output_bfd
)->e_flags
&= ~EF_SH_PIC
;
5578 if (r
!= bfd_reloc_ok
)
5583 case bfd_reloc_outofrange
:
5585 case bfd_reloc_overflow
:
5593 name
= (bfd_elf_string_from_elf_section
5594 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
5598 name
= bfd_section_name (input_bfd
, sec
);
5600 if (! ((*info
->callbacks
->reloc_overflow
)
5601 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
5602 (bfd_vma
) 0, input_bfd
, input_section
,
5614 /* This is a version of bfd_generic_get_relocated_section_contents
5615 which uses sh_elf_relocate_section. */
5618 sh_elf_get_relocated_section_contents (bfd
*output_bfd
,
5619 struct bfd_link_info
*link_info
,
5620 struct bfd_link_order
*link_order
,
5622 bfd_boolean relocatable
,
5625 Elf_Internal_Shdr
*symtab_hdr
;
5626 asection
*input_section
= link_order
->u
.indirect
.section
;
5627 bfd
*input_bfd
= input_section
->owner
;
5628 asection
**sections
= NULL
;
5629 Elf_Internal_Rela
*internal_relocs
= NULL
;
5630 Elf_Internal_Sym
*isymbuf
= NULL
;
5632 /* We only need to handle the case of relaxing, or of having a
5633 particular set of section contents, specially. */
5635 || elf_section_data (input_section
)->this_hdr
.contents
== NULL
)
5636 return bfd_generic_get_relocated_section_contents (output_bfd
, link_info
,
5641 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
5643 memcpy (data
, elf_section_data (input_section
)->this_hdr
.contents
,
5644 (size_t) input_section
->size
);
5646 if ((input_section
->flags
& SEC_RELOC
) != 0
5647 && input_section
->reloc_count
> 0)
5650 Elf_Internal_Sym
*isym
, *isymend
;
5653 internal_relocs
= (_bfd_elf_link_read_relocs
5654 (input_bfd
, input_section
, NULL
,
5655 (Elf_Internal_Rela
*) NULL
, FALSE
));
5656 if (internal_relocs
== NULL
)
5659 if (symtab_hdr
->sh_info
!= 0)
5661 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5662 if (isymbuf
== NULL
)
5663 isymbuf
= bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
5664 symtab_hdr
->sh_info
, 0,
5666 if (isymbuf
== NULL
)
5670 amt
= symtab_hdr
->sh_info
;
5671 amt
*= sizeof (asection
*);
5672 sections
= (asection
**) bfd_malloc (amt
);
5673 if (sections
== NULL
&& amt
!= 0)
5676 isymend
= isymbuf
+ symtab_hdr
->sh_info
;
5677 for (isym
= isymbuf
, secpp
= sections
; isym
< isymend
; ++isym
, ++secpp
)
5681 if (isym
->st_shndx
== SHN_UNDEF
)
5682 isec
= bfd_und_section_ptr
;
5683 else if (isym
->st_shndx
== SHN_ABS
)
5684 isec
= bfd_abs_section_ptr
;
5685 else if (isym
->st_shndx
== SHN_COMMON
)
5686 isec
= bfd_com_section_ptr
;
5688 isec
= bfd_section_from_elf_index (input_bfd
, isym
->st_shndx
);
5693 if (! sh_elf_relocate_section (output_bfd
, link_info
, input_bfd
,
5694 input_section
, data
, internal_relocs
,
5698 if (sections
!= NULL
)
5701 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
5703 if (elf_section_data (input_section
)->relocs
!= internal_relocs
)
5704 free (internal_relocs
);
5710 if (sections
!= NULL
)
5713 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
5715 if (internal_relocs
!= NULL
5716 && elf_section_data (input_section
)->relocs
!= internal_relocs
)
5717 free (internal_relocs
);
5721 /* Return the base VMA address which should be subtracted from real addresses
5722 when resolving @dtpoff relocation.
5723 This is PT_TLS segment p_vaddr. */
5726 dtpoff_base (struct bfd_link_info
*info
)
5728 /* If tls_sec is NULL, we should have signalled an error already. */
5729 if (elf_hash_table (info
)->tls_sec
== NULL
)
5731 return elf_hash_table (info
)->tls_sec
->vma
;
5734 /* Return the relocation value for R_SH_TLS_TPOFF32.. */
5737 tpoff (struct bfd_link_info
*info
, bfd_vma address
)
5739 /* If tls_sec is NULL, we should have signalled an error already. */
5740 if (elf_hash_table (info
)->tls_sec
== NULL
)
5742 /* SH TLS ABI is variant I and static TLS block start just after tcbhead
5743 structure which has 2 pointer fields. */
5744 return (address
- elf_hash_table (info
)->tls_sec
->vma
5745 + align_power ((bfd_vma
) 8,
5746 elf_hash_table (info
)->tls_sec
->alignment_power
));
5750 sh_elf_gc_mark_hook (asection
*sec
,
5751 struct bfd_link_info
*info
,
5752 Elf_Internal_Rela
*rel
,
5753 struct elf_link_hash_entry
*h
,
5754 Elf_Internal_Sym
*sym
)
5757 switch (ELF32_R_TYPE (rel
->r_info
))
5759 case R_SH_GNU_VTINHERIT
:
5760 case R_SH_GNU_VTENTRY
:
5764 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
5767 /* Update the got entry reference counts for the section being removed. */
5770 sh_elf_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
5771 asection
*sec
, const Elf_Internal_Rela
*relocs
)
5773 Elf_Internal_Shdr
*symtab_hdr
;
5774 struct elf_link_hash_entry
**sym_hashes
;
5775 bfd_signed_vma
*local_got_refcounts
;
5776 union gotref
*local_funcdesc
;
5777 const Elf_Internal_Rela
*rel
, *relend
;
5779 if (info
->relocatable
)
5782 elf_section_data (sec
)->local_dynrel
= NULL
;
5784 symtab_hdr
= &elf_symtab_hdr (abfd
);
5785 sym_hashes
= elf_sym_hashes (abfd
);
5786 local_got_refcounts
= elf_local_got_refcounts (abfd
);
5787 local_funcdesc
= sh_elf_local_funcdesc (abfd
);
5789 relend
= relocs
+ sec
->reloc_count
;
5790 for (rel
= relocs
; rel
< relend
; rel
++)
5792 unsigned long r_symndx
;
5793 unsigned int r_type
;
5794 struct elf_link_hash_entry
*h
= NULL
;
5795 #ifdef INCLUDE_SHMEDIA
5796 int seen_stt_datalabel
= 0;
5799 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5800 if (r_symndx
>= symtab_hdr
->sh_info
)
5802 struct elf_sh_link_hash_entry
*eh
;
5803 struct elf_sh_dyn_relocs
**pp
;
5804 struct elf_sh_dyn_relocs
*p
;
5806 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5807 while (h
->root
.type
== bfd_link_hash_indirect
5808 || h
->root
.type
== bfd_link_hash_warning
)
5810 #ifdef INCLUDE_SHMEDIA
5811 seen_stt_datalabel
|= h
->type
== STT_DATALABEL
;
5813 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5815 eh
= (struct elf_sh_link_hash_entry
*) h
;
5816 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
5819 /* Everything must go for SEC. */
5825 r_type
= ELF32_R_TYPE (rel
->r_info
);
5826 switch (sh_elf_optimized_tls_reloc (info
, r_type
, h
!= NULL
))
5828 case R_SH_TLS_LD_32
:
5829 if (sh_elf_hash_table (info
)->tls_ldm_got
.refcount
> 0)
5830 sh_elf_hash_table (info
)->tls_ldm_got
.refcount
-= 1;
5838 #ifdef INCLUDE_SHMEDIA
5839 case R_SH_GOT_LOW16
:
5840 case R_SH_GOT_MEDLOW16
:
5841 case R_SH_GOT_MEDHI16
:
5845 case R_SH_GOTOFF_LOW16
:
5846 case R_SH_GOTOFF_MEDLOW16
:
5847 case R_SH_GOTOFF_MEDHI16
:
5848 case R_SH_GOTOFF_HI16
:
5849 case R_SH_GOTPC_LOW16
:
5850 case R_SH_GOTPC_MEDLOW16
:
5851 case R_SH_GOTPC_MEDHI16
:
5852 case R_SH_GOTPC_HI16
:
5854 case R_SH_TLS_GD_32
:
5855 case R_SH_TLS_IE_32
:
5856 case R_SH_GOTFUNCDESC
:
5857 case R_SH_GOTFUNCDESC20
:
5860 #ifdef INCLUDE_SHMEDIA
5861 if (seen_stt_datalabel
)
5863 struct elf_sh_link_hash_entry
*eh
;
5864 eh
= (struct elf_sh_link_hash_entry
*) h
;
5865 if (eh
->datalabel_got
.refcount
> 0)
5866 eh
->datalabel_got
.refcount
-= 1;
5870 if (h
->got
.refcount
> 0)
5871 h
->got
.refcount
-= 1;
5873 else if (local_got_refcounts
!= NULL
)
5875 #ifdef INCLUDE_SHMEDIA
5876 if (rel
->r_addend
& 1)
5878 if (local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] > 0)
5879 local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] -= 1;
5883 if (local_got_refcounts
[r_symndx
] > 0)
5884 local_got_refcounts
[r_symndx
] -= 1;
5890 sh_elf_hash_entry (h
)->abs_funcdesc_refcount
-= 1;
5891 else if (sh_elf_hash_table (info
)->fdpic_p
&& !info
->shared
)
5892 sh_elf_hash_table (info
)->srofixup
->size
-= 4;
5896 case R_SH_GOTOFFFUNCDESC
:
5897 case R_SH_GOTOFFFUNCDESC20
:
5899 sh_elf_hash_entry (h
)->funcdesc
.refcount
-= 1;
5901 local_funcdesc
[r_symndx
].refcount
-= 1;
5905 if (sh_elf_hash_table (info
)->fdpic_p
&& !info
->shared
5906 && (sec
->flags
& SEC_ALLOC
) != 0)
5907 sh_elf_hash_table (info
)->srofixup
->size
-= 4;
5916 #ifdef INCLUDE_SHMEDIA
5917 case R_SH_PLT_LOW16
:
5918 case R_SH_PLT_MEDLOW16
:
5919 case R_SH_PLT_MEDHI16
:
5924 if (h
->plt
.refcount
> 0)
5925 h
->plt
.refcount
-= 1;
5930 #ifdef INCLUDE_SHMEDIA
5931 case R_SH_GOTPLT_LOW16
:
5932 case R_SH_GOTPLT_MEDLOW16
:
5933 case R_SH_GOTPLT_MEDHI16
:
5934 case R_SH_GOTPLT_HI16
:
5935 case R_SH_GOTPLT10BY4
:
5936 case R_SH_GOTPLT10BY8
:
5940 struct elf_sh_link_hash_entry
*eh
;
5941 eh
= (struct elf_sh_link_hash_entry
*) h
;
5942 if (eh
->gotplt_refcount
> 0)
5944 eh
->gotplt_refcount
-= 1;
5945 if (h
->plt
.refcount
> 0)
5946 h
->plt
.refcount
-= 1;
5948 #ifdef INCLUDE_SHMEDIA
5949 else if (seen_stt_datalabel
)
5951 if (eh
->datalabel_got
.refcount
> 0)
5952 eh
->datalabel_got
.refcount
-= 1;
5955 else if (h
->got
.refcount
> 0)
5956 h
->got
.refcount
-= 1;
5958 else if (local_got_refcounts
!= NULL
)
5960 #ifdef INCLUDE_SHMEDIA
5961 if (rel
->r_addend
& 1)
5963 if (local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] > 0)
5964 local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] -= 1;
5968 if (local_got_refcounts
[r_symndx
] > 0)
5969 local_got_refcounts
[r_symndx
] -= 1;
5981 /* Copy the extra info we tack onto an elf_link_hash_entry. */
5984 sh_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
5985 struct elf_link_hash_entry
*dir
,
5986 struct elf_link_hash_entry
*ind
)
5988 struct elf_sh_link_hash_entry
*edir
, *eind
;
5990 edir
= (struct elf_sh_link_hash_entry
*) dir
;
5991 eind
= (struct elf_sh_link_hash_entry
*) ind
;
5993 if (eind
->dyn_relocs
!= NULL
)
5995 if (edir
->dyn_relocs
!= NULL
)
5997 struct elf_sh_dyn_relocs
**pp
;
5998 struct elf_sh_dyn_relocs
*p
;
6000 /* Add reloc counts against the indirect sym to the direct sym
6001 list. Merge any entries against the same section. */
6002 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
6004 struct elf_sh_dyn_relocs
*q
;
6006 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
6007 if (q
->sec
== p
->sec
)
6009 q
->pc_count
+= p
->pc_count
;
6010 q
->count
+= p
->count
;
6017 *pp
= edir
->dyn_relocs
;
6020 edir
->dyn_relocs
= eind
->dyn_relocs
;
6021 eind
->dyn_relocs
= NULL
;
6023 edir
->gotplt_refcount
= eind
->gotplt_refcount
;
6024 eind
->gotplt_refcount
= 0;
6025 #ifdef INCLUDE_SHMEDIA
6026 edir
->datalabel_got
.refcount
+= eind
->datalabel_got
.refcount
;
6027 eind
->datalabel_got
.refcount
= 0;
6029 edir
->funcdesc
.refcount
+= eind
->funcdesc
.refcount
;
6030 eind
->funcdesc
.refcount
= 0;
6031 edir
->abs_funcdesc_refcount
+= eind
->abs_funcdesc_refcount
;
6032 eind
->abs_funcdesc_refcount
= 0;
6034 if (ind
->root
.type
== bfd_link_hash_indirect
6035 && dir
->got
.refcount
<= 0)
6037 edir
->got_type
= eind
->got_type
;
6038 eind
->got_type
= GOT_UNKNOWN
;
6041 if (ind
->root
.type
!= bfd_link_hash_indirect
6042 && dir
->dynamic_adjusted
)
6044 /* If called to transfer flags for a weakdef during processing
6045 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
6046 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
6047 dir
->ref_dynamic
|= ind
->ref_dynamic
;
6048 dir
->ref_regular
|= ind
->ref_regular
;
6049 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
6050 dir
->needs_plt
|= ind
->needs_plt
;
6053 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
6057 sh_elf_optimized_tls_reloc (struct bfd_link_info
*info
, int r_type
,
6065 case R_SH_TLS_GD_32
:
6066 case R_SH_TLS_IE_32
:
6068 return R_SH_TLS_LE_32
;
6069 return R_SH_TLS_IE_32
;
6070 case R_SH_TLS_LD_32
:
6071 return R_SH_TLS_LE_32
;
6077 /* Look through the relocs for a section during the first phase.
6078 Since we don't do .gots or .plts, we just need to consider the
6079 virtual table relocs for gc. */
6082 sh_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
, asection
*sec
,
6083 const Elf_Internal_Rela
*relocs
)
6085 Elf_Internal_Shdr
*symtab_hdr
;
6086 struct elf_link_hash_entry
**sym_hashes
;
6087 struct elf_sh_link_hash_table
*htab
;
6088 const Elf_Internal_Rela
*rel
;
6089 const Elf_Internal_Rela
*rel_end
;
6091 unsigned int r_type
;
6092 int got_type
, old_got_type
;
6096 if (info
->relocatable
)
6099 BFD_ASSERT (is_sh_elf (abfd
));
6101 symtab_hdr
= &elf_symtab_hdr (abfd
);
6102 sym_hashes
= elf_sym_hashes (abfd
);
6104 htab
= sh_elf_hash_table (info
);
6108 rel_end
= relocs
+ sec
->reloc_count
;
6109 for (rel
= relocs
; rel
< rel_end
; rel
++)
6111 struct elf_link_hash_entry
*h
;
6112 unsigned long r_symndx
;
6113 #ifdef INCLUDE_SHMEDIA
6114 int seen_stt_datalabel
= 0;
6117 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6118 r_type
= ELF32_R_TYPE (rel
->r_info
);
6120 if (r_symndx
< symtab_hdr
->sh_info
)
6124 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6125 while (h
->root
.type
== bfd_link_hash_indirect
6126 || h
->root
.type
== bfd_link_hash_warning
)
6128 #ifdef INCLUDE_SHMEDIA
6129 seen_stt_datalabel
|= h
->type
== STT_DATALABEL
;
6131 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6135 r_type
= sh_elf_optimized_tls_reloc (info
, r_type
, h
== NULL
);
6137 && r_type
== R_SH_TLS_IE_32
6139 && h
->root
.type
!= bfd_link_hash_undefined
6140 && h
->root
.type
!= bfd_link_hash_undefweak
6141 && (h
->dynindx
== -1
6143 r_type
= R_SH_TLS_LE_32
;
6148 case R_SH_GOTOFFFUNCDESC
:
6149 case R_SH_GOTOFFFUNCDESC20
:
6151 case R_SH_GOTFUNCDESC
:
6152 case R_SH_GOTFUNCDESC20
:
6155 if (h
->dynindx
== -1)
6156 switch (ELF_ST_VISIBILITY (h
->other
))
6162 bfd_elf_link_record_dynamic_symbol (info
, h
);
6169 /* Some relocs require a global offset table. */
6170 if (htab
->sgot
== NULL
)
6175 /* This may require an rofixup. */
6184 case R_SH_GOTFUNCDESC
:
6185 case R_SH_GOTFUNCDESC20
:
6186 case R_SH_GOTOFFFUNCDESC
:
6187 case R_SH_GOTOFFFUNCDESC20
:
6189 #ifdef INCLUDE_SHMEDIA
6190 case R_SH_GOTPLT_LOW16
:
6191 case R_SH_GOTPLT_MEDLOW16
:
6192 case R_SH_GOTPLT_MEDHI16
:
6193 case R_SH_GOTPLT_HI16
:
6194 case R_SH_GOTPLT10BY4
:
6195 case R_SH_GOTPLT10BY8
:
6196 case R_SH_GOT_LOW16
:
6197 case R_SH_GOT_MEDLOW16
:
6198 case R_SH_GOT_MEDHI16
:
6202 case R_SH_GOTOFF_LOW16
:
6203 case R_SH_GOTOFF_MEDLOW16
:
6204 case R_SH_GOTOFF_MEDHI16
:
6205 case R_SH_GOTOFF_HI16
:
6206 case R_SH_GOTPC_LOW16
:
6207 case R_SH_GOTPC_MEDLOW16
:
6208 case R_SH_GOTPC_MEDHI16
:
6209 case R_SH_GOTPC_HI16
:
6211 case R_SH_TLS_GD_32
:
6212 case R_SH_TLS_LD_32
:
6213 case R_SH_TLS_IE_32
:
6214 if (htab
->root
.dynobj
== NULL
)
6215 htab
->root
.dynobj
= abfd
;
6216 if (!create_got_section (htab
->root
.dynobj
, info
))
6227 /* This relocation describes the C++ object vtable hierarchy.
6228 Reconstruct it for later use during GC. */
6229 case R_SH_GNU_VTINHERIT
:
6230 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6234 /* This relocation describes which C++ vtable entries are actually
6235 used. Record for later use during GC. */
6236 case R_SH_GNU_VTENTRY
:
6237 BFD_ASSERT (h
!= NULL
);
6239 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
6243 case R_SH_TLS_IE_32
:
6245 info
->flags
|= DF_STATIC_TLS
;
6249 case R_SH_TLS_GD_32
:
6252 #ifdef INCLUDE_SHMEDIA
6253 case R_SH_GOT_LOW16
:
6254 case R_SH_GOT_MEDLOW16
:
6255 case R_SH_GOT_MEDHI16
:
6260 case R_SH_GOTFUNCDESC
:
6261 case R_SH_GOTFUNCDESC20
:
6265 got_type
= GOT_NORMAL
;
6267 case R_SH_TLS_GD_32
:
6268 got_type
= GOT_TLS_GD
;
6270 case R_SH_TLS_IE_32
:
6271 got_type
= GOT_TLS_IE
;
6273 case R_SH_GOTFUNCDESC
:
6274 case R_SH_GOTFUNCDESC20
:
6275 got_type
= GOT_FUNCDESC
;
6281 #ifdef INCLUDE_SHMEDIA
6282 if (seen_stt_datalabel
)
6284 struct elf_sh_link_hash_entry
*eh
6285 = (struct elf_sh_link_hash_entry
*) h
;
6287 eh
->datalabel_got
.refcount
+= 1;
6291 h
->got
.refcount
+= 1;
6292 old_got_type
= sh_elf_hash_entry (h
)->got_type
;
6296 bfd_signed_vma
*local_got_refcounts
;
6298 /* This is a global offset table entry for a local
6300 local_got_refcounts
= elf_local_got_refcounts (abfd
);
6301 if (local_got_refcounts
== NULL
)
6305 size
= symtab_hdr
->sh_info
;
6306 size
*= sizeof (bfd_signed_vma
);
6307 #ifdef INCLUDE_SHMEDIA
6308 /* Reserve space for both the datalabel and
6309 codelabel local GOT offsets. */
6312 size
+= symtab_hdr
->sh_info
;
6313 local_got_refcounts
= ((bfd_signed_vma
*)
6314 bfd_zalloc (abfd
, size
));
6315 if (local_got_refcounts
== NULL
)
6317 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
6318 #ifdef INCLUDE_SHMEDIA
6319 /* Take care of both the datalabel and codelabel local
6321 sh_elf_local_got_type (abfd
)
6322 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
6324 sh_elf_local_got_type (abfd
)
6325 = (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
6328 #ifdef INCLUDE_SHMEDIA
6329 if (rel
->r_addend
& 1)
6330 local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] += 1;
6333 local_got_refcounts
[r_symndx
] += 1;
6334 old_got_type
= sh_elf_local_got_type (abfd
) [r_symndx
];
6337 /* If a TLS symbol is accessed using IE at least once,
6338 there is no point to use dynamic model for it. */
6339 if (old_got_type
!= got_type
&& old_got_type
!= GOT_UNKNOWN
6340 && (old_got_type
!= GOT_TLS_GD
|| got_type
!= GOT_TLS_IE
))
6342 if (old_got_type
== GOT_TLS_IE
&& got_type
== GOT_TLS_GD
)
6343 got_type
= GOT_TLS_IE
;
6346 if ((old_got_type
== GOT_FUNCDESC
|| got_type
== GOT_FUNCDESC
)
6347 && (old_got_type
== GOT_NORMAL
|| got_type
== GOT_NORMAL
))
6348 (*_bfd_error_handler
)
6349 (_("%B: `%s' accessed both as normal and FDPIC symbol"),
6350 abfd
, h
->root
.root
.string
);
6351 else if (old_got_type
== GOT_FUNCDESC
6352 || got_type
== GOT_FUNCDESC
)
6353 (*_bfd_error_handler
)
6354 (_("%B: `%s' accessed both as FDPIC and thread local symbol"),
6355 abfd
, h
->root
.root
.string
);
6357 (*_bfd_error_handler
)
6358 (_("%B: `%s' accessed both as normal and thread local symbol"),
6359 abfd
, h
->root
.root
.string
);
6364 if (old_got_type
!= got_type
)
6367 sh_elf_hash_entry (h
)->got_type
= got_type
;
6369 sh_elf_local_got_type (abfd
) [r_symndx
] = got_type
;
6374 case R_SH_TLS_LD_32
:
6375 sh_elf_hash_table(info
)->tls_ldm_got
.refcount
+= 1;
6379 case R_SH_GOTOFFFUNCDESC
:
6380 case R_SH_GOTOFFFUNCDESC20
:
6383 (*_bfd_error_handler
)
6384 (_("%B: Function descriptor relocation with non-zero addend"),
6391 union gotref
*local_funcdesc
;
6393 /* We need a function descriptor for a local symbol. */
6394 local_funcdesc
= sh_elf_local_funcdesc (abfd
);
6395 if (local_funcdesc
== NULL
)
6399 size
= symtab_hdr
->sh_info
* sizeof (union gotref
);
6400 #ifdef INCLUDE_SHMEDIA
6401 /* Count datalabel local GOT. */
6404 local_funcdesc
= (union gotref
*) bfd_zalloc (abfd
, size
);
6405 if (local_funcdesc
== NULL
)
6407 sh_elf_local_funcdesc (abfd
) = local_funcdesc
;
6409 local_funcdesc
[r_symndx
].refcount
+= 1;
6411 if (r_type
== R_SH_FUNCDESC
)
6414 htab
->srofixup
->size
+= 4;
6416 htab
->srelgot
->size
+= sizeof (Elf32_External_Rela
);
6421 sh_elf_hash_entry (h
)->funcdesc
.refcount
++;
6422 if (r_type
== R_SH_FUNCDESC
)
6423 sh_elf_hash_entry (h
)->abs_funcdesc_refcount
++;
6425 /* If there is a function descriptor reference, then
6426 there should not be any non-FDPIC references. */
6427 old_got_type
= sh_elf_hash_entry (h
)->got_type
;
6428 if (old_got_type
!= GOT_FUNCDESC
&& old_got_type
!= GOT_UNKNOWN
)
6430 if (old_got_type
== GOT_NORMAL
)
6431 (*_bfd_error_handler
)
6432 (_("%B: `%s' accessed both as normal and FDPIC symbol"),
6433 abfd
, h
->root
.root
.string
);
6435 (*_bfd_error_handler
)
6436 (_("%B: `%s' accessed both as FDPIC and thread local symbol"),
6437 abfd
, h
->root
.root
.string
);
6443 #ifdef INCLUDE_SHMEDIA
6444 case R_SH_GOTPLT_LOW16
:
6445 case R_SH_GOTPLT_MEDLOW16
:
6446 case R_SH_GOTPLT_MEDHI16
:
6447 case R_SH_GOTPLT_HI16
:
6448 case R_SH_GOTPLT10BY4
:
6449 case R_SH_GOTPLT10BY8
:
6451 /* If this is a local symbol, we resolve it directly without
6452 creating a procedure linkage table entry. */
6458 || h
->dynindx
== -1)
6462 h
->plt
.refcount
+= 1;
6463 ((struct elf_sh_link_hash_entry
*) h
)->gotplt_refcount
+= 1;
6468 #ifdef INCLUDE_SHMEDIA
6469 case R_SH_PLT_LOW16
:
6470 case R_SH_PLT_MEDLOW16
:
6471 case R_SH_PLT_MEDHI16
:
6474 /* This symbol requires a procedure linkage table entry. We
6475 actually build the entry in adjust_dynamic_symbol,
6476 because this might be a case of linking PIC code which is
6477 never referenced by a dynamic object, in which case we
6478 don't need to generate a procedure linkage table entry
6481 /* If this is a local symbol, we resolve it directly without
6482 creating a procedure linkage table entry. */
6486 if (h
->forced_local
)
6490 h
->plt
.refcount
+= 1;
6495 #ifdef INCLUDE_SHMEDIA
6496 case R_SH_IMM_LOW16_PCREL
:
6497 case R_SH_IMM_MEDLOW16_PCREL
:
6498 case R_SH_IMM_MEDHI16_PCREL
:
6499 case R_SH_IMM_HI16_PCREL
:
6501 if (h
!= NULL
&& ! info
->shared
)
6504 h
->plt
.refcount
+= 1;
6507 /* If we are creating a shared library, and this is a reloc
6508 against a global symbol, or a non PC relative reloc
6509 against a local symbol, then we need to copy the reloc
6510 into the shared library. However, if we are linking with
6511 -Bsymbolic, we do not need to copy a reloc against a
6512 global symbol which is defined in an object we are
6513 including in the link (i.e., DEF_REGULAR is set). At
6514 this point we have not seen all the input files, so it is
6515 possible that DEF_REGULAR is not set now but will be set
6516 later (it is never cleared). We account for that
6517 possibility below by storing information in the
6518 dyn_relocs field of the hash table entry. A similar
6519 situation occurs when creating shared libraries and symbol
6520 visibility changes render the symbol local.
6522 If on the other hand, we are creating an executable, we
6523 may need to keep relocations for symbols satisfied by a
6524 dynamic library if we manage to avoid copy relocs for the
6527 && (sec
->flags
& SEC_ALLOC
) != 0
6528 && (r_type
!= R_SH_REL32
6530 && (! info
->symbolic
6531 || h
->root
.type
== bfd_link_hash_defweak
6532 || !h
->def_regular
))))
6534 && (sec
->flags
& SEC_ALLOC
) != 0
6536 && (h
->root
.type
== bfd_link_hash_defweak
6537 || !h
->def_regular
)))
6539 struct elf_sh_dyn_relocs
*p
;
6540 struct elf_sh_dyn_relocs
**head
;
6542 if (htab
->root
.dynobj
== NULL
)
6543 htab
->root
.dynobj
= abfd
;
6545 /* When creating a shared object, we must copy these
6546 reloc types into the output file. We create a reloc
6547 section in dynobj and make room for this reloc. */
6550 sreloc
= _bfd_elf_make_dynamic_reloc_section
6551 (sec
, htab
->root
.dynobj
, 2, abfd
, /*rela?*/ TRUE
);
6557 /* If this is a global symbol, we count the number of
6558 relocations we need for this symbol. */
6560 head
= &((struct elf_sh_link_hash_entry
*) h
)->dyn_relocs
;
6563 /* Track dynamic relocs needed for local syms too. */
6566 Elf_Internal_Sym
*isym
;
6568 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
6573 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
6577 vpp
= &elf_section_data (s
)->local_dynrel
;
6578 head
= (struct elf_sh_dyn_relocs
**) vpp
;
6582 if (p
== NULL
|| p
->sec
!= sec
)
6584 bfd_size_type amt
= sizeof (*p
);
6585 p
= bfd_alloc (htab
->root
.dynobj
, amt
);
6596 if (r_type
== R_SH_REL32
6597 #ifdef INCLUDE_SHMEDIA
6598 || r_type
== R_SH_IMM_LOW16_PCREL
6599 || r_type
== R_SH_IMM_MEDLOW16_PCREL
6600 || r_type
== R_SH_IMM_MEDHI16_PCREL
6601 || r_type
== R_SH_IMM_HI16_PCREL
6607 /* Allocate the fixup regardless of whether we need a relocation.
6608 If we end up generating the relocation, we'll unallocate the
6610 if (htab
->fdpic_p
&& !info
->shared
6611 && r_type
== R_SH_DIR32
6612 && (sec
->flags
& SEC_ALLOC
) != 0)
6613 htab
->srofixup
->size
+= 4;
6616 case R_SH_TLS_LE_32
:
6617 if (info
->shared
&& !info
->pie
)
6619 (*_bfd_error_handler
)
6620 (_("%B: TLS local exec code cannot be linked into shared objects"),
6627 case R_SH_TLS_LDO_32
:
6628 /* Nothing to do. */
6639 #ifndef sh_elf_set_mach_from_flags
6640 static unsigned int sh_ef_bfd_table
[] = { EF_SH_BFD_TABLE
};
6643 sh_elf_set_mach_from_flags (bfd
*abfd
)
6645 flagword flags
= elf_elfheader (abfd
)->e_flags
& EF_SH_MACH_MASK
;
6647 if (flags
>= sizeof(sh_ef_bfd_table
))
6650 if (sh_ef_bfd_table
[flags
] == 0)
6653 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, sh_ef_bfd_table
[flags
]);
6659 /* Reverse table lookup for sh_ef_bfd_table[].
6660 Given a bfd MACH value from archures.c
6661 return the equivalent ELF flags from the table.
6662 Return -1 if no match is found. */
6665 sh_elf_get_flags_from_mach (unsigned long mach
)
6667 int i
= ARRAY_SIZE (sh_ef_bfd_table
) - 1;
6670 if (sh_ef_bfd_table
[i
] == mach
)
6673 /* shouldn't get here */
6678 #endif /* not sh_elf_set_mach_from_flags */
6680 #ifndef sh_elf_set_private_flags
6681 /* Function to keep SH specific file flags. */
6684 sh_elf_set_private_flags (bfd
*abfd
, flagword flags
)
6686 BFD_ASSERT (! elf_flags_init (abfd
)
6687 || elf_elfheader (abfd
)->e_flags
== flags
);
6689 elf_elfheader (abfd
)->e_flags
= flags
;
6690 elf_flags_init (abfd
) = TRUE
;
6691 return sh_elf_set_mach_from_flags (abfd
);
6693 #endif /* not sh_elf_set_private_flags */
6695 #ifndef sh_elf_copy_private_data
6696 /* Copy backend specific data from one object module to another */
6699 sh_elf_copy_private_data (bfd
* ibfd
, bfd
* obfd
)
6701 /* Copy object attributes. */
6702 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
6704 if (! is_sh_elf (ibfd
) || ! is_sh_elf (obfd
))
6707 /* Copy the stack size. */
6708 if (elf_tdata (ibfd
)->phdr
&& elf_tdata (obfd
)->phdr
6709 && fdpic_object_p (ibfd
) && fdpic_object_p (obfd
))
6713 for (i
= 0; i
< elf_elfheader (ibfd
)->e_phnum
; i
++)
6714 if (elf_tdata (ibfd
)->phdr
[i
].p_type
== PT_GNU_STACK
)
6716 Elf_Internal_Phdr
*iphdr
= &elf_tdata (ibfd
)->phdr
[i
];
6718 for (i
= 0; i
< elf_elfheader (obfd
)->e_phnum
; i
++)
6719 if (elf_tdata (obfd
)->phdr
[i
].p_type
== PT_GNU_STACK
)
6721 memcpy (&elf_tdata (obfd
)->phdr
[i
], iphdr
, sizeof (*iphdr
));
6723 /* Rewrite the phdrs, since we're only called after they
6724 were first written. */
6726 (bfd_signed_vma
) get_elf_backend_data (obfd
)
6727 ->s
->sizeof_ehdr
, SEEK_SET
) != 0
6728 || get_elf_backend_data (obfd
)->s
6729 ->write_out_phdrs (obfd
, elf_tdata (obfd
)->phdr
,
6730 elf_elfheader (obfd
)->e_phnum
) != 0)
6739 return sh_elf_set_private_flags (obfd
, elf_elfheader (ibfd
)->e_flags
);
6741 #endif /* not sh_elf_copy_private_data */
6743 #ifndef sh_elf_merge_private_data
6745 /* This function returns the ELF architecture number that
6746 corresponds to the given arch_sh* flags. */
6749 sh_find_elf_flags (unsigned int arch_set
)
6751 extern unsigned long sh_get_bfd_mach_from_arch_set (unsigned int);
6752 unsigned long bfd_mach
= sh_get_bfd_mach_from_arch_set (arch_set
);
6754 return sh_elf_get_flags_from_mach (bfd_mach
);
6757 /* This routine initialises the elf flags when required and
6758 calls sh_merge_bfd_arch() to check dsp/fpu compatibility. */
6761 sh_elf_merge_private_data (bfd
*ibfd
, bfd
*obfd
)
6763 extern bfd_boolean
sh_merge_bfd_arch (bfd
*, bfd
*);
6765 if (! is_sh_elf (ibfd
) || ! is_sh_elf (obfd
))
6768 if (! elf_flags_init (obfd
))
6770 /* This happens when ld starts out with a 'blank' output file. */
6771 elf_flags_init (obfd
) = TRUE
;
6772 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
6773 sh_elf_set_mach_from_flags (obfd
);
6774 if (elf_elfheader (obfd
)->e_flags
& EF_SH_FDPIC
)
6775 elf_elfheader (obfd
)->e_flags
|= EF_SH_PIC
;
6778 if (! sh_merge_bfd_arch (ibfd
, obfd
))
6780 _bfd_error_handler ("%B: uses instructions which are incompatible "
6781 "with instructions used in previous modules",
6783 bfd_set_error (bfd_error_bad_value
);
6787 elf_elfheader (obfd
)->e_flags
&= ~EF_SH_MACH_MASK
;
6788 elf_elfheader (obfd
)->e_flags
|=
6789 sh_elf_get_flags_from_mach (bfd_get_mach (obfd
));
6791 if (fdpic_object_p (ibfd
) != fdpic_object_p (obfd
))
6793 _bfd_error_handler ("%B: attempt to mix FDPIC and non-FDPIC objects",
6795 bfd_set_error (bfd_error_bad_value
);
6801 #endif /* not sh_elf_merge_private_data */
6803 /* Override the generic function because we need to store sh_elf_obj_tdata
6804 as the specific tdata. We set also the machine architecture from flags
6808 sh_elf_object_p (bfd
*abfd
)
6810 if (! sh_elf_set_mach_from_flags (abfd
))
6813 return (((elf_elfheader (abfd
)->e_flags
& EF_SH_FDPIC
) != 0)
6814 == fdpic_object_p (abfd
));
6817 /* Finish up dynamic symbol handling. We set the contents of various
6818 dynamic sections here. */
6821 sh_elf_finish_dynamic_symbol (bfd
*output_bfd
, struct bfd_link_info
*info
,
6822 struct elf_link_hash_entry
*h
,
6823 Elf_Internal_Sym
*sym
)
6825 struct elf_sh_link_hash_table
*htab
;
6827 htab
= sh_elf_hash_table (info
);
6831 if (h
->plt
.offset
!= (bfd_vma
) -1)
6839 Elf_Internal_Rela rel
;
6841 const struct elf_sh_plt_info
*plt_info
;
6843 /* This symbol has an entry in the procedure linkage table. Set
6846 BFD_ASSERT (h
->dynindx
!= -1);
6849 sgotplt
= htab
->sgotplt
;
6850 srelplt
= htab
->srelplt
;
6851 BFD_ASSERT (splt
!= NULL
&& sgotplt
!= NULL
&& srelplt
!= NULL
);
6853 /* Get the index in the procedure linkage table which
6854 corresponds to this symbol. This is the index of this symbol
6855 in all the symbols for which we are making plt entries. The
6856 first entry in the procedure linkage table is reserved. */
6857 plt_index
= get_plt_index (htab
->plt_info
, h
->plt
.offset
);
6859 plt_info
= htab
->plt_info
;
6860 if (plt_info
->short_plt
!= NULL
&& plt_index
<= MAX_SHORT_PLT
)
6861 plt_info
= plt_info
->short_plt
;
6863 /* Get the offset into the .got table of the entry that
6864 corresponds to this function. */
6866 /* The offset must be relative to the GOT symbol, twelve bytes
6867 before the end of .got.plt. Each descriptor is eight
6869 got_offset
= plt_index
* 8 + 12 - sgotplt
->size
;
6871 /* Each .got entry is 4 bytes. The first three are
6873 got_offset
= (plt_index
+ 3) * 4;
6877 got_offset
-= GOT_BIAS
;
6880 /* Fill in the entry in the procedure linkage table. */
6881 memcpy (splt
->contents
+ h
->plt
.offset
,
6882 plt_info
->symbol_entry
,
6883 plt_info
->symbol_entry_size
);
6885 if (info
->shared
|| htab
->fdpic_p
)
6887 if (plt_info
->symbol_fields
.got20
)
6889 bfd_reloc_status_type r
;
6890 r
= install_movi20_field (output_bfd
, got_offset
,
6891 splt
->owner
, splt
, splt
->contents
,
6893 + plt_info
->symbol_fields
.got_entry
);
6894 BFD_ASSERT (r
== bfd_reloc_ok
);
6897 install_plt_field (output_bfd
, FALSE
, got_offset
,
6900 + plt_info
->symbol_fields
.got_entry
));
6904 BFD_ASSERT (!plt_info
->symbol_fields
.got20
);
6906 install_plt_field (output_bfd
, FALSE
,
6907 (sgotplt
->output_section
->vma
6908 + sgotplt
->output_offset
6912 + plt_info
->symbol_fields
.got_entry
));
6913 if (htab
->vxworks_p
)
6915 unsigned int reachable_plts
, plts_per_4k
;
6918 /* Divide the PLT into groups. The first group contains
6919 REACHABLE_PLTS entries and the other groups contain
6920 PLTS_PER_4K entries. Entries in the first group can
6921 branch directly to .plt; those in later groups branch
6922 to the last element of the previous group. */
6923 /* ??? It would be better to create multiple copies of
6924 the common resolver stub. */
6925 reachable_plts
= ((4096
6926 - plt_info
->plt0_entry_size
6927 - (plt_info
->symbol_fields
.plt
+ 4))
6928 / plt_info
->symbol_entry_size
) + 1;
6929 plts_per_4k
= (4096 / plt_info
->symbol_entry_size
);
6930 if (plt_index
< reachable_plts
)
6931 distance
= -(h
->plt
.offset
6932 + plt_info
->symbol_fields
.plt
);
6934 distance
= -(((plt_index
- reachable_plts
) % plts_per_4k
+ 1)
6935 * plt_info
->symbol_entry_size
);
6937 /* Install the 'bra' with this offset. */
6938 bfd_put_16 (output_bfd
,
6939 0xa000 | (0x0fff & ((distance
- 4) / 2)),
6942 + plt_info
->symbol_fields
.plt
));
6945 install_plt_field (output_bfd
, TRUE
,
6946 splt
->output_section
->vma
+ splt
->output_offset
,
6949 + plt_info
->symbol_fields
.plt
));
6952 /* Make got_offset relative to the start of .got.plt. */
6955 got_offset
+= GOT_BIAS
;
6958 got_offset
= plt_index
* 8;
6960 if (plt_info
->symbol_fields
.reloc_offset
!= MINUS_ONE
)
6961 install_plt_field (output_bfd
, FALSE
,
6962 plt_index
* sizeof (Elf32_External_Rela
),
6965 + plt_info
->symbol_fields
.reloc_offset
));
6967 /* Fill in the entry in the global offset table. */
6968 bfd_put_32 (output_bfd
,
6969 (splt
->output_section
->vma
6970 + splt
->output_offset
6972 + plt_info
->symbol_resolve_offset
),
6973 sgotplt
->contents
+ got_offset
);
6975 bfd_put_32 (output_bfd
,
6976 sh_elf_osec_to_segment (output_bfd
,
6977 htab
->splt
->output_section
),
6978 sgotplt
->contents
+ got_offset
+ 4);
6980 /* Fill in the entry in the .rela.plt section. */
6981 rel
.r_offset
= (sgotplt
->output_section
->vma
6982 + sgotplt
->output_offset
6985 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_FUNCDESC_VALUE
);
6987 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_JMP_SLOT
);
6990 rel
.r_addend
= GOT_BIAS
;
6992 loc
= srelplt
->contents
+ plt_index
* sizeof (Elf32_External_Rela
);
6993 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
6995 if (htab
->vxworks_p
&& !info
->shared
)
6997 /* Create the .rela.plt.unloaded relocations for this PLT entry.
6998 Begin by pointing LOC to the first such relocation. */
6999 loc
= (htab
->srelplt2
->contents
7000 + (plt_index
* 2 + 1) * sizeof (Elf32_External_Rela
));
7002 /* Create a .rela.plt.unloaded R_SH_DIR32 relocation
7003 for the PLT entry's pointer to the .got.plt entry. */
7004 rel
.r_offset
= (htab
->splt
->output_section
->vma
7005 + htab
->splt
->output_offset
7007 + plt_info
->symbol_fields
.got_entry
);
7008 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_SH_DIR32
);
7009 rel
.r_addend
= got_offset
;
7010 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
7011 loc
+= sizeof (Elf32_External_Rela
);
7013 /* Create a .rela.plt.unloaded R_SH_DIR32 relocation for
7014 the .got.plt entry, which initially points to .plt. */
7015 rel
.r_offset
= (sgotplt
->output_section
->vma
7016 + sgotplt
->output_offset
7018 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_SH_DIR32
);
7020 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
7023 if (!h
->def_regular
)
7025 /* Mark the symbol as undefined, rather than as defined in
7026 the .plt section. Leave the value alone. */
7027 sym
->st_shndx
= SHN_UNDEF
;
7031 if (h
->got
.offset
!= (bfd_vma
) -1
7032 && sh_elf_hash_entry (h
)->got_type
!= GOT_TLS_GD
7033 && sh_elf_hash_entry (h
)->got_type
!= GOT_TLS_IE
7034 && sh_elf_hash_entry (h
)->got_type
!= GOT_FUNCDESC
)
7038 Elf_Internal_Rela rel
;
7041 /* This symbol has an entry in the global offset table. Set it
7045 srelgot
= htab
->srelgot
;
7046 BFD_ASSERT (sgot
!= NULL
&& srelgot
!= NULL
);
7048 rel
.r_offset
= (sgot
->output_section
->vma
7049 + sgot
->output_offset
7050 + (h
->got
.offset
&~ (bfd_vma
) 1));
7052 /* If this is a static link, or it is a -Bsymbolic link and the
7053 symbol is defined locally or was forced to be local because
7054 of a version file, we just want to emit a RELATIVE reloc.
7055 The entry in the global offset table will already have been
7056 initialized in the relocate_section function. */
7058 && SYMBOL_REFERENCES_LOCAL (info
, h
))
7062 asection
*sec
= h
->root
.u
.def
.section
;
7064 = elf_section_data (sec
->output_section
)->dynindx
;
7066 rel
.r_info
= ELF32_R_INFO (dynindx
, R_SH_DIR32
);
7067 rel
.r_addend
= (h
->root
.u
.def
.value
7068 + h
->root
.u
.def
.section
->output_offset
);
7072 rel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
7073 rel
.r_addend
= (h
->root
.u
.def
.value
7074 + h
->root
.u
.def
.section
->output_section
->vma
7075 + h
->root
.u
.def
.section
->output_offset
);
7080 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
7081 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_GLOB_DAT
);
7085 loc
= srelgot
->contents
;
7086 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
7087 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
7090 #ifdef INCLUDE_SHMEDIA
7092 struct elf_sh_link_hash_entry
*eh
;
7094 eh
= (struct elf_sh_link_hash_entry
*) h
;
7095 if (eh
->datalabel_got
.offset
!= (bfd_vma
) -1)
7099 Elf_Internal_Rela rel
;
7102 /* This symbol has a datalabel entry in the global offset table.
7106 srelgot
= htab
->srelgot
;
7107 BFD_ASSERT (sgot
!= NULL
&& srelgot
!= NULL
);
7109 rel
.r_offset
= (sgot
->output_section
->vma
7110 + sgot
->output_offset
7111 + (eh
->datalabel_got
.offset
&~ (bfd_vma
) 1));
7113 /* If this is a static link, or it is a -Bsymbolic link and the
7114 symbol is defined locally or was forced to be local because
7115 of a version file, we just want to emit a RELATIVE reloc.
7116 The entry in the global offset table will already have been
7117 initialized in the relocate_section function. */
7119 && SYMBOL_REFERENCES_LOCAL (info
, h
))
7123 asection
*sec
= h
->root
.u
.def
.section
;
7125 = elf_section_data (sec
->output_section
)->dynindx
;
7127 rel
.r_info
= ELF32_R_INFO (dynindx
, R_SH_DIR32
);
7128 rel
.r_addend
= (h
->root
.u
.def
.value
7129 + h
->root
.u
.def
.section
->output_offset
);
7133 rel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
7134 rel
.r_addend
= (h
->root
.u
.def
.value
7135 + h
->root
.u
.def
.section
->output_section
->vma
7136 + h
->root
.u
.def
.section
->output_offset
);
7141 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
7142 + eh
->datalabel_got
.offset
);
7143 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_GLOB_DAT
);
7147 loc
= srelgot
->contents
;
7148 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
7149 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
7157 Elf_Internal_Rela rel
;
7160 /* This symbol needs a copy reloc. Set it up. */
7162 BFD_ASSERT (h
->dynindx
!= -1
7163 && (h
->root
.type
== bfd_link_hash_defined
7164 || h
->root
.type
== bfd_link_hash_defweak
));
7166 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
7168 BFD_ASSERT (s
!= NULL
);
7170 rel
.r_offset
= (h
->root
.u
.def
.value
7171 + h
->root
.u
.def
.section
->output_section
->vma
7172 + h
->root
.u
.def
.section
->output_offset
);
7173 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_COPY
);
7175 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
7176 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
7179 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
7180 _GLOBAL_OFFSET_TABLE_ is not absolute: it is relative to the
7182 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
7183 || (!htab
->vxworks_p
&& h
== htab
->root
.hgot
))
7184 sym
->st_shndx
= SHN_ABS
;
7189 /* Finish up the dynamic sections. */
7192 sh_elf_finish_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
7194 struct elf_sh_link_hash_table
*htab
;
7198 htab
= sh_elf_hash_table (info
);
7202 sgotplt
= htab
->sgotplt
;
7203 sdyn
= bfd_get_section_by_name (htab
->root
.dynobj
, ".dynamic");
7205 if (htab
->root
.dynamic_sections_created
)
7208 Elf32_External_Dyn
*dyncon
, *dynconend
;
7210 BFD_ASSERT (sgotplt
!= NULL
&& sdyn
!= NULL
);
7212 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
7213 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
7214 for (; dyncon
< dynconend
; dyncon
++)
7216 Elf_Internal_Dyn dyn
;
7218 #ifdef INCLUDE_SHMEDIA
7222 bfd_elf32_swap_dyn_in (htab
->root
.dynobj
, dyncon
, &dyn
);
7228 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
7229 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7232 #ifdef INCLUDE_SHMEDIA
7234 name
= info
->init_function
;
7238 name
= info
->fini_function
;
7240 if (dyn
.d_un
.d_val
!= 0)
7242 struct elf_link_hash_entry
*h
;
7244 h
= elf_link_hash_lookup (&htab
->root
, name
,
7245 FALSE
, FALSE
, TRUE
);
7246 if (h
!= NULL
&& (h
->other
& STO_SH5_ISA32
))
7248 dyn
.d_un
.d_val
|= 1;
7249 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7256 BFD_ASSERT (htab
->root
.hgot
!= NULL
);
7257 s
= htab
->root
.hgot
->root
.u
.def
.section
;
7258 dyn
.d_un
.d_ptr
= htab
->root
.hgot
->root
.u
.def
.value
7259 + s
->output_section
->vma
+ s
->output_offset
;
7260 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7264 s
= htab
->srelplt
->output_section
;
7265 BFD_ASSERT (s
!= NULL
);
7266 dyn
.d_un
.d_ptr
= s
->vma
;
7267 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7271 s
= htab
->srelplt
->output_section
;
7272 BFD_ASSERT (s
!= NULL
);
7273 dyn
.d_un
.d_val
= s
->size
;
7274 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7278 /* My reading of the SVR4 ABI indicates that the
7279 procedure linkage table relocs (DT_JMPREL) should be
7280 included in the overall relocs (DT_RELA). This is
7281 what Solaris does. However, UnixWare can not handle
7282 that case. Therefore, we override the DT_RELASZ entry
7283 here to make it not include the JMPREL relocs. Since
7284 the linker script arranges for .rela.plt to follow all
7285 other relocation sections, we don't have to worry
7286 about changing the DT_RELA entry. */
7287 if (htab
->srelplt
!= NULL
)
7289 s
= htab
->srelplt
->output_section
;
7290 dyn
.d_un
.d_val
-= s
->size
;
7292 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7297 /* Fill in the first entry in the procedure linkage table. */
7299 if (splt
&& splt
->size
> 0 && htab
->plt_info
->plt0_entry
)
7303 memcpy (splt
->contents
,
7304 htab
->plt_info
->plt0_entry
,
7305 htab
->plt_info
->plt0_entry_size
);
7306 for (i
= 0; i
< ARRAY_SIZE (htab
->plt_info
->plt0_got_fields
); i
++)
7307 if (htab
->plt_info
->plt0_got_fields
[i
] != MINUS_ONE
)
7308 install_plt_field (output_bfd
, FALSE
,
7309 (sgotplt
->output_section
->vma
7310 + sgotplt
->output_offset
7313 + htab
->plt_info
->plt0_got_fields
[i
]));
7315 if (htab
->vxworks_p
)
7317 /* Finalize the .rela.plt.unloaded contents. */
7318 Elf_Internal_Rela rel
;
7321 /* Create a .rela.plt.unloaded R_SH_DIR32 relocation for the
7322 first PLT entry's pointer to _GLOBAL_OFFSET_TABLE_ + 8. */
7323 loc
= htab
->srelplt2
->contents
;
7324 rel
.r_offset
= (splt
->output_section
->vma
7325 + splt
->output_offset
7326 + htab
->plt_info
->plt0_got_fields
[2]);
7327 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_SH_DIR32
);
7329 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
7330 loc
+= sizeof (Elf32_External_Rela
);
7332 /* Fix up the remaining .rela.plt.unloaded relocations.
7333 They may have the wrong symbol index for _G_O_T_ or
7334 _P_L_T_ depending on the order in which symbols were
7336 while (loc
< htab
->srelplt2
->contents
+ htab
->srelplt2
->size
)
7338 /* The PLT entry's pointer to the .got.plt slot. */
7339 bfd_elf32_swap_reloc_in (output_bfd
, loc
, &rel
);
7340 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
,
7342 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
7343 loc
+= sizeof (Elf32_External_Rela
);
7345 /* The .got.plt slot's pointer to .plt. */
7346 bfd_elf32_swap_reloc_in (output_bfd
, loc
, &rel
);
7347 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
,
7349 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
7350 loc
+= sizeof (Elf32_External_Rela
);
7354 /* UnixWare sets the entsize of .plt to 4, although that doesn't
7355 really seem like the right value. */
7356 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
7360 /* Fill in the first three entries in the global offset table. */
7361 if (sgotplt
&& sgotplt
->size
> 0 && !htab
->fdpic_p
)
7364 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgotplt
->contents
);
7366 bfd_put_32 (output_bfd
,
7367 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
7369 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgotplt
->contents
+ 4);
7370 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgotplt
->contents
+ 8);
7373 if (sgotplt
&& sgotplt
->size
> 0)
7374 elf_section_data (sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
7376 /* At the very end of the .rofixup section is a pointer to the GOT. */
7377 if (htab
->fdpic_p
&& htab
->srofixup
!= NULL
)
7379 struct elf_link_hash_entry
*hgot
= htab
->root
.hgot
;
7380 bfd_vma got_value
= hgot
->root
.u
.def
.value
7381 + hgot
->root
.u
.def
.section
->output_section
->vma
7382 + hgot
->root
.u
.def
.section
->output_offset
;
7384 sh_elf_add_rofixup (output_bfd
, htab
->srofixup
, got_value
);
7386 /* Make sure we allocated and generated the same number of fixups. */
7387 BFD_ASSERT (htab
->srofixup
->reloc_count
* 4 == htab
->srofixup
->size
);
7390 if (htab
->srelfuncdesc
)
7391 BFD_ASSERT (htab
->srelfuncdesc
->reloc_count
* sizeof (Elf32_External_Rela
)
7392 == htab
->srelfuncdesc
->size
);
7395 BFD_ASSERT (htab
->srelgot
->reloc_count
* sizeof (Elf32_External_Rela
)
7396 == htab
->srelgot
->size
);
7401 static enum elf_reloc_type_class
7402 sh_elf_reloc_type_class (const Elf_Internal_Rela
*rela
)
7404 switch ((int) ELF32_R_TYPE (rela
->r_info
))
7407 return reloc_class_relative
;
7409 return reloc_class_plt
;
7411 return reloc_class_copy
;
7413 return reloc_class_normal
;
7417 #if !defined SH_TARGET_ALREADY_DEFINED
7418 /* Support for Linux core dump NOTE sections. */
7421 elf32_shlin_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
7426 switch (note
->descsz
)
7431 case 168: /* Linux/SH */
7433 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
7436 elf_tdata (abfd
)->core_lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
7445 /* Make a ".reg/999" section. */
7446 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
7447 size
, note
->descpos
+ offset
);
7451 elf32_shlin_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
7453 switch (note
->descsz
)
7458 case 124: /* Linux/SH elf_prpsinfo */
7459 elf_tdata (abfd
)->core_program
7460 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
7461 elf_tdata (abfd
)->core_command
7462 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
7465 /* Note that for some reason, a spurious space is tacked
7466 onto the end of the args in some (at least one anyway)
7467 implementations, so strip it off if it exists. */
7470 char *command
= elf_tdata (abfd
)->core_command
;
7471 int n
= strlen (command
);
7473 if (0 < n
&& command
[n
- 1] == ' ')
7474 command
[n
- 1] = '\0';
7479 #endif /* not SH_TARGET_ALREADY_DEFINED */
7482 /* Return address for Ith PLT stub in section PLT, for relocation REL
7483 or (bfd_vma) -1 if it should not be included. */
7486 sh_elf_plt_sym_val (bfd_vma i
, const asection
*plt
,
7487 const arelent
*rel ATTRIBUTE_UNUSED
)
7489 const struct elf_sh_plt_info
*plt_info
;
7491 plt_info
= get_plt_info (plt
->owner
, (plt
->owner
->flags
& DYNAMIC
) != 0);
7492 return plt
->vma
+ get_plt_offset (plt_info
, i
);
7495 /* Decide whether to attempt to turn absptr or lsda encodings in
7496 shared libraries into pcrel within the given input section. */
7499 sh_elf_use_relative_eh_frame (bfd
*input_bfd ATTRIBUTE_UNUSED
,
7500 struct bfd_link_info
*info
,
7501 asection
*eh_frame_section ATTRIBUTE_UNUSED
)
7503 struct elf_sh_link_hash_table
*htab
= sh_elf_hash_table (info
);
7505 /* We can't use PC-relative encodings in FDPIC binaries, in general. */
7512 /* Adjust the contents of an eh_frame_hdr section before they're output. */
7515 sh_elf_encode_eh_address (bfd
*abfd
,
7516 struct bfd_link_info
*info
,
7517 asection
*osec
, bfd_vma offset
,
7518 asection
*loc_sec
, bfd_vma loc_offset
,
7521 struct elf_sh_link_hash_table
*htab
= sh_elf_hash_table (info
);
7522 struct elf_link_hash_entry
*h
;
7525 return _bfd_elf_encode_eh_address (abfd
, info
, osec
, offset
, loc_sec
,
7526 loc_offset
, encoded
);
7528 h
= htab
->root
.hgot
;
7529 BFD_ASSERT (h
&& h
->root
.type
== bfd_link_hash_defined
);
7531 if (! h
|| (sh_elf_osec_to_segment (abfd
, osec
)
7532 == sh_elf_osec_to_segment (abfd
, loc_sec
->output_section
)))
7533 return _bfd_elf_encode_eh_address (abfd
, info
, osec
, offset
,
7534 loc_sec
, loc_offset
, encoded
);
7536 BFD_ASSERT (sh_elf_osec_to_segment (abfd
, osec
)
7537 == (sh_elf_osec_to_segment
7538 (abfd
, h
->root
.u
.def
.section
->output_section
)));
7540 *encoded
= osec
->vma
+ offset
7541 - (h
->root
.u
.def
.value
7542 + h
->root
.u
.def
.section
->output_section
->vma
7543 + h
->root
.u
.def
.section
->output_offset
);
7545 return DW_EH_PE_datarel
| DW_EH_PE_sdata4
;
7548 #if !defined SH_TARGET_ALREADY_DEFINED
7549 #define TARGET_BIG_SYM bfd_elf32_sh_vec
7550 #define TARGET_BIG_NAME "elf32-sh"
7551 #define TARGET_LITTLE_SYM bfd_elf32_shl_vec
7552 #define TARGET_LITTLE_NAME "elf32-shl"
7555 #define ELF_ARCH bfd_arch_sh
7556 #define ELF_TARGET_ID SH_ELF_DATA
7557 #define ELF_MACHINE_CODE EM_SH
7558 #ifdef __QNXTARGET__
7559 #define ELF_MAXPAGESIZE 0x1000
7561 #define ELF_MAXPAGESIZE 0x80
7564 #define elf_symbol_leading_char '_'
7566 #define bfd_elf32_bfd_reloc_type_lookup sh_elf_reloc_type_lookup
7567 #define bfd_elf32_bfd_reloc_name_lookup \
7568 sh_elf_reloc_name_lookup
7569 #define elf_info_to_howto sh_elf_info_to_howto
7570 #define bfd_elf32_bfd_relax_section sh_elf_relax_section
7571 #define elf_backend_relocate_section sh_elf_relocate_section
7572 #define bfd_elf32_bfd_get_relocated_section_contents \
7573 sh_elf_get_relocated_section_contents
7574 #define bfd_elf32_mkobject sh_elf_mkobject
7575 #define elf_backend_object_p sh_elf_object_p
7576 #define bfd_elf32_bfd_set_private_bfd_flags \
7577 sh_elf_set_private_flags
7578 #define bfd_elf32_bfd_copy_private_bfd_data \
7579 sh_elf_copy_private_data
7580 #define bfd_elf32_bfd_merge_private_bfd_data \
7581 sh_elf_merge_private_data
7583 #define elf_backend_gc_mark_hook sh_elf_gc_mark_hook
7584 #define elf_backend_gc_sweep_hook sh_elf_gc_sweep_hook
7585 #define elf_backend_check_relocs sh_elf_check_relocs
7586 #define elf_backend_copy_indirect_symbol \
7587 sh_elf_copy_indirect_symbol
7588 #define elf_backend_create_dynamic_sections \
7589 sh_elf_create_dynamic_sections
7590 #define bfd_elf32_bfd_link_hash_table_create \
7591 sh_elf_link_hash_table_create
7592 #define elf_backend_adjust_dynamic_symbol \
7593 sh_elf_adjust_dynamic_symbol
7594 #define elf_backend_always_size_sections \
7595 sh_elf_always_size_sections
7596 #define elf_backend_size_dynamic_sections \
7597 sh_elf_size_dynamic_sections
7598 #define elf_backend_omit_section_dynsym sh_elf_omit_section_dynsym
7599 #define elf_backend_finish_dynamic_symbol \
7600 sh_elf_finish_dynamic_symbol
7601 #define elf_backend_finish_dynamic_sections \
7602 sh_elf_finish_dynamic_sections
7603 #define elf_backend_reloc_type_class sh_elf_reloc_type_class
7604 #define elf_backend_plt_sym_val sh_elf_plt_sym_val
7605 #define elf_backend_can_make_relative_eh_frame \
7606 sh_elf_use_relative_eh_frame
7607 #define elf_backend_can_make_lsda_relative_eh_frame \
7608 sh_elf_use_relative_eh_frame
7609 #define elf_backend_encode_eh_address \
7610 sh_elf_encode_eh_address
7612 #define elf_backend_can_gc_sections 1
7613 #define elf_backend_can_refcount 1
7614 #define elf_backend_want_got_plt 1
7615 #define elf_backend_plt_readonly 1
7616 #define elf_backend_want_plt_sym 0
7617 #define elf_backend_got_header_size 12
7619 #if !defined INCLUDE_SHMEDIA && !defined SH_TARGET_ALREADY_DEFINED
7621 #include "elf32-target.h"
7623 /* NetBSD support. */
7624 #undef TARGET_BIG_SYM
7625 #define TARGET_BIG_SYM bfd_elf32_shnbsd_vec
7626 #undef TARGET_BIG_NAME
7627 #define TARGET_BIG_NAME "elf32-sh-nbsd"
7628 #undef TARGET_LITTLE_SYM
7629 #define TARGET_LITTLE_SYM bfd_elf32_shlnbsd_vec
7630 #undef TARGET_LITTLE_NAME
7631 #define TARGET_LITTLE_NAME "elf32-shl-nbsd"
7632 #undef ELF_MAXPAGESIZE
7633 #define ELF_MAXPAGESIZE 0x10000
7634 #undef ELF_COMMONPAGESIZE
7635 #undef elf_symbol_leading_char
7636 #define elf_symbol_leading_char 0
7638 #define elf32_bed elf32_sh_nbsd_bed
7640 #include "elf32-target.h"
7643 /* Linux support. */
7644 #undef TARGET_BIG_SYM
7645 #define TARGET_BIG_SYM bfd_elf32_shblin_vec
7646 #undef TARGET_BIG_NAME
7647 #define TARGET_BIG_NAME "elf32-shbig-linux"
7648 #undef TARGET_LITTLE_SYM
7649 #define TARGET_LITTLE_SYM bfd_elf32_shlin_vec
7650 #undef TARGET_LITTLE_NAME
7651 #define TARGET_LITTLE_NAME "elf32-sh-linux"
7652 #undef ELF_COMMONPAGESIZE
7653 #define ELF_COMMONPAGESIZE 0x1000
7655 #undef elf_backend_grok_prstatus
7656 #define elf_backend_grok_prstatus elf32_shlin_grok_prstatus
7657 #undef elf_backend_grok_psinfo
7658 #define elf_backend_grok_psinfo elf32_shlin_grok_psinfo
7660 #define elf32_bed elf32_sh_lin_bed
7662 #include "elf32-target.h"
7665 /* FDPIC support. */
7666 #undef TARGET_BIG_SYM
7667 #define TARGET_BIG_SYM bfd_elf32_shbfd_vec
7668 #undef TARGET_BIG_NAME
7669 #define TARGET_BIG_NAME "elf32-shbig-fdpic"
7670 #undef TARGET_LITTLE_SYM
7671 #define TARGET_LITTLE_SYM bfd_elf32_shfd_vec
7672 #undef TARGET_LITTLE_NAME
7673 #define TARGET_LITTLE_NAME "elf32-sh-fdpic"
7674 #undef elf_backend_modify_program_headers
7675 #define elf_backend_modify_program_headers \
7676 sh_elf_modify_program_headers
7679 #define elf32_bed elf32_sh_fd_bed
7681 #include "elf32-target.h"
7683 #undef elf_backend_modify_program_headers
7685 /* VxWorks support. */
7686 #undef TARGET_BIG_SYM
7687 #define TARGET_BIG_SYM bfd_elf32_shvxworks_vec
7688 #undef TARGET_BIG_NAME
7689 #define TARGET_BIG_NAME "elf32-sh-vxworks"
7690 #undef TARGET_LITTLE_SYM
7691 #define TARGET_LITTLE_SYM bfd_elf32_shlvxworks_vec
7692 #undef TARGET_LITTLE_NAME
7693 #define TARGET_LITTLE_NAME "elf32-shl-vxworks"
7695 #define elf32_bed elf32_sh_vxworks_bed
7697 #undef elf_backend_want_plt_sym
7698 #define elf_backend_want_plt_sym 1
7699 #undef elf_symbol_leading_char
7700 #define elf_symbol_leading_char '_'
7701 #define elf_backend_want_got_underscore 1
7702 #undef elf_backend_grok_prstatus
7703 #undef elf_backend_grok_psinfo
7704 #undef elf_backend_add_symbol_hook
7705 #define elf_backend_add_symbol_hook elf_vxworks_add_symbol_hook
7706 #undef elf_backend_link_output_symbol_hook
7707 #define elf_backend_link_output_symbol_hook \
7708 elf_vxworks_link_output_symbol_hook
7709 #undef elf_backend_emit_relocs
7710 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
7711 #undef elf_backend_final_write_processing
7712 #define elf_backend_final_write_processing \
7713 elf_vxworks_final_write_processing
7714 #undef ELF_MAXPAGESIZE
7715 #define ELF_MAXPAGESIZE 0x1000
7716 #undef ELF_COMMONPAGESIZE
7718 #include "elf32-target.h"
7720 #endif /* neither INCLUDE_SHMEDIA nor SH_TARGET_ALREADY_DEFINED */