1 /* SPARC-specific support for 64-bit ELF
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 /* This is defined if one wants to build upward compatible binaries
27 with the original sparc64-elf toolchain. The support is kept in for
28 now but is turned off by default. dje 970930 */
29 /*#define SPARC64_OLD_RELOCS*/
31 #include "elf/sparc.h"
32 #include "opcode/sparc.h"
34 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
35 #define MINUS_ONE (~ (bfd_vma) 0)
37 static reloc_howto_type
*sparc64_elf_reloc_type_lookup
38 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
39 static void sparc64_elf_info_to_howto
40 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
41 static bfd_boolean sparc64_elf_check_relocs
42 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
43 const Elf_Internal_Rela
*));
44 static bfd_boolean sparc64_elf_adjust_dynamic_symbol
45 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
46 static bfd_boolean allocate_dynrelocs
47 PARAMS ((struct elf_link_hash_entry
*, PTR
));
48 static bfd_boolean readonly_dynrelocs
49 PARAMS ((struct elf_link_hash_entry
*, PTR
));
50 static bfd_boolean sparc64_elf_omit_section_dynsym
51 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*));
52 static bfd_boolean sparc64_elf_size_dynamic_sections
53 PARAMS ((bfd
*, struct bfd_link_info
*));
54 static bfd_boolean sparc64_elf_new_section_hook
55 PARAMS ((bfd
*, asection
*));
56 static bfd_boolean sparc64_elf_relax_section
57 PARAMS ((bfd
*, asection
*, struct bfd_link_info
*, bfd_boolean
*));
58 static bfd_vma dtpoff_base
59 PARAMS ((struct bfd_link_info
*));
61 PARAMS ((struct bfd_link_info
*, bfd_vma
));
62 static bfd_boolean sparc64_elf_relocate_section
63 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
64 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
65 static bfd_boolean sparc64_elf_finish_dynamic_symbol
66 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
68 static bfd_boolean sparc64_elf_finish_dynamic_sections
69 PARAMS ((bfd
*, struct bfd_link_info
*));
70 static bfd_boolean sparc64_elf_merge_private_bfd_data
71 PARAMS ((bfd
*, bfd
*));
72 static struct bfd_hash_entry
*link_hash_newfunc
73 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
74 static struct bfd_link_hash_table
*sparc64_elf_link_hash_table_create
76 static bfd_boolean create_got_section
77 PARAMS ((bfd
*, struct bfd_link_info
*));
78 static bfd_boolean sparc64_elf_create_dynamic_sections
79 PARAMS ((bfd
*, struct bfd_link_info
*));
80 static void sparc64_elf_copy_indirect_symbol
81 PARAMS ((const struct elf_backend_data
*, struct elf_link_hash_entry
*,
82 struct elf_link_hash_entry
*));
83 static int sparc64_elf_tls_transition
84 PARAMS ((struct bfd_link_info
*, int, int));
86 static bfd_boolean sparc64_elf_mkobject
88 static bfd_boolean sparc64_elf_object_p
90 static enum elf_reloc_type_class sparc64_elf_reloc_type_class
91 PARAMS ((const Elf_Internal_Rela
*));
92 static asection
*sparc64_elf_gc_mark_hook
93 PARAMS ((asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
94 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
95 static bfd_boolean sparc64_elf_gc_sweep_hook
96 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
97 const Elf_Internal_Rela
*));
99 static bfd_reloc_status_type init_insn_reloc
100 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*,
101 bfd
*, bfd_vma
*, bfd_vma
*));
102 static int sparc64_plt_entry_build
103 PARAMS ((bfd
*, asection
*, bfd_vma
, bfd_vma
, bfd_vma
*));
104 static int sparc64_elf_get_symbol_type
105 PARAMS (( Elf_Internal_Sym
*, int));
106 static bfd_boolean sparc64_elf_add_symbol_hook
107 PARAMS ((bfd
*, struct bfd_link_info
*, Elf_Internal_Sym
*,
108 const char **, flagword
*, asection
**, bfd_vma
*));
109 static bfd_boolean sparc64_elf_output_arch_syms
110 PARAMS ((bfd
*, struct bfd_link_info
*, PTR
,
111 bfd_boolean (*) (PTR
, const char *, Elf_Internal_Sym
*,
112 asection
*, struct elf_link_hash_entry
*)));
113 static void sparc64_elf_symbol_processing
114 PARAMS ((bfd
*, asymbol
*));
115 static bfd_boolean sparc64_elf_fake_sections
116 PARAMS ((bfd
*, Elf_Internal_Shdr
*, asection
*));
117 static const char *sparc64_elf_print_symbol_all
118 PARAMS ((bfd
*, PTR
, asymbol
*));
119 static long sparc64_elf_get_reloc_upper_bound
120 PARAMS ((bfd
*, asection
*));
121 static long sparc64_elf_get_dynamic_reloc_upper_bound
123 static bfd_boolean sparc64_elf_slurp_one_reloc_table
124 PARAMS ((bfd
*, asection
*, Elf_Internal_Shdr
*, asymbol
**, bfd_boolean
));
125 static bfd_boolean sparc64_elf_slurp_reloc_table
126 PARAMS ((bfd
*, asection
*, asymbol
**, bfd_boolean
));
127 static long sparc64_elf_canonicalize_reloc
128 PARAMS ((bfd
*, asection
*, arelent
**, asymbol
**));
129 static long sparc64_elf_canonicalize_dynamic_reloc
130 PARAMS ((bfd
*, arelent
**, asymbol
**));
131 static void sparc64_elf_write_relocs
132 PARAMS ((bfd
*, asection
*, PTR
));
134 /* The relocation "howto" table. */
136 static bfd_reloc_status_type sparc_elf_notsup_reloc
137 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
138 static bfd_reloc_status_type sparc_elf_wdisp16_reloc
139 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
140 static bfd_reloc_status_type sparc_elf_hix22_reloc
141 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
142 static bfd_reloc_status_type sparc_elf_lox10_reloc
143 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
145 static reloc_howto_type sparc64_elf_howto_table
[] =
147 HOWTO(R_SPARC_NONE
, 0,0, 0,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_NONE", FALSE
,0,0x00000000,TRUE
),
148 HOWTO(R_SPARC_8
, 0,0, 8,FALSE
,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_8", FALSE
,0,0x000000ff,TRUE
),
149 HOWTO(R_SPARC_16
, 0,1,16,FALSE
,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_16", FALSE
,0,0x0000ffff,TRUE
),
150 HOWTO(R_SPARC_32
, 0,2,32,FALSE
,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_32", FALSE
,0,0xffffffff,TRUE
),
151 HOWTO(R_SPARC_DISP8
, 0,0, 8,TRUE
, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_DISP8", FALSE
,0,0x000000ff,TRUE
),
152 HOWTO(R_SPARC_DISP16
, 0,1,16,TRUE
, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_DISP16", FALSE
,0,0x0000ffff,TRUE
),
153 HOWTO(R_SPARC_DISP32
, 0,2,32,TRUE
, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_DISP32", FALSE
,0,0xffffffff,TRUE
),
154 HOWTO(R_SPARC_WDISP30
, 2,2,30,TRUE
, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_WDISP30", FALSE
,0,0x3fffffff,TRUE
),
155 HOWTO(R_SPARC_WDISP22
, 2,2,22,TRUE
, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_WDISP22", FALSE
,0,0x003fffff,TRUE
),
156 HOWTO(R_SPARC_HI22
, 10,2,22,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_HI22", FALSE
,0,0x003fffff,TRUE
),
157 HOWTO(R_SPARC_22
, 0,2,22,FALSE
,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_22", FALSE
,0,0x003fffff,TRUE
),
158 HOWTO(R_SPARC_13
, 0,2,13,FALSE
,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_13", FALSE
,0,0x00001fff,TRUE
),
159 HOWTO(R_SPARC_LO10
, 0,2,10,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_LO10", FALSE
,0,0x000003ff,TRUE
),
160 HOWTO(R_SPARC_GOT10
, 0,2,10,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_GOT10", FALSE
,0,0x000003ff,TRUE
),
161 HOWTO(R_SPARC_GOT13
, 0,2,13,FALSE
,0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_GOT13", FALSE
,0,0x00001fff,TRUE
),
162 HOWTO(R_SPARC_GOT22
, 10,2,22,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_GOT22", FALSE
,0,0x003fffff,TRUE
),
163 HOWTO(R_SPARC_PC10
, 0,2,10,TRUE
, 0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_PC10", FALSE
,0,0x000003ff,TRUE
),
164 HOWTO(R_SPARC_PC22
, 10,2,22,TRUE
, 0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_PC22", FALSE
,0,0x003fffff,TRUE
),
165 HOWTO(R_SPARC_WPLT30
, 2,2,30,TRUE
, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_WPLT30", FALSE
,0,0x3fffffff,TRUE
),
166 HOWTO(R_SPARC_COPY
, 0,0,00,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_COPY", FALSE
,0,0x00000000,TRUE
),
167 HOWTO(R_SPARC_GLOB_DAT
, 0,0,00,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_GLOB_DAT",FALSE
,0,0x00000000,TRUE
),
168 HOWTO(R_SPARC_JMP_SLOT
, 0,0,00,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_JMP_SLOT",FALSE
,0,0x00000000,TRUE
),
169 HOWTO(R_SPARC_RELATIVE
, 0,0,00,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_RELATIVE",FALSE
,0,0x00000000,TRUE
),
170 HOWTO(R_SPARC_UA32
, 0,2,32,FALSE
,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_UA32", FALSE
,0,0xffffffff,TRUE
),
171 #ifndef SPARC64_OLD_RELOCS
172 HOWTO(R_SPARC_PLT32
, 0,2,32,FALSE
,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_PLT32", FALSE
,0,0xffffffff,TRUE
),
173 /* These aren't implemented yet. */
174 HOWTO(R_SPARC_HIPLT22
, 0,0,00,FALSE
,0,complain_overflow_dont
, sparc_elf_notsup_reloc
, "R_SPARC_HIPLT22", FALSE
,0,0x00000000,TRUE
),
175 HOWTO(R_SPARC_LOPLT10
, 0,0,00,FALSE
,0,complain_overflow_dont
, sparc_elf_notsup_reloc
, "R_SPARC_LOPLT10", FALSE
,0,0x00000000,TRUE
),
176 HOWTO(R_SPARC_PCPLT32
, 0,0,00,FALSE
,0,complain_overflow_dont
, sparc_elf_notsup_reloc
, "R_SPARC_PCPLT32", FALSE
,0,0x00000000,TRUE
),
177 HOWTO(R_SPARC_PCPLT22
, 0,0,00,FALSE
,0,complain_overflow_dont
, sparc_elf_notsup_reloc
, "R_SPARC_PCPLT22", FALSE
,0,0x00000000,TRUE
),
178 HOWTO(R_SPARC_PCPLT10
, 0,0,00,FALSE
,0,complain_overflow_dont
, sparc_elf_notsup_reloc
, "R_SPARC_PCPLT10", FALSE
,0,0x00000000,TRUE
),
180 HOWTO(R_SPARC_10
, 0,2,10,FALSE
,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_10", FALSE
,0,0x000003ff,TRUE
),
181 HOWTO(R_SPARC_11
, 0,2,11,FALSE
,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_11", FALSE
,0,0x000007ff,TRUE
),
182 HOWTO(R_SPARC_64
, 0,4,64,FALSE
,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_64", FALSE
,0,MINUS_ONE
, TRUE
),
183 HOWTO(R_SPARC_OLO10
, 0,2,13,FALSE
,0,complain_overflow_signed
, sparc_elf_notsup_reloc
, "R_SPARC_OLO10", FALSE
,0,0x00001fff,TRUE
),
184 HOWTO(R_SPARC_HH22
, 42,2,22,FALSE
,0,complain_overflow_unsigned
,bfd_elf_generic_reloc
, "R_SPARC_HH22", FALSE
,0,0x003fffff,TRUE
),
185 HOWTO(R_SPARC_HM10
, 32,2,10,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_HM10", FALSE
,0,0x000003ff,TRUE
),
186 HOWTO(R_SPARC_LM22
, 10,2,22,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_LM22", FALSE
,0,0x003fffff,TRUE
),
187 HOWTO(R_SPARC_PC_HH22
, 42,2,22,TRUE
, 0,complain_overflow_unsigned
,bfd_elf_generic_reloc
, "R_SPARC_PC_HH22", FALSE
,0,0x003fffff,TRUE
),
188 HOWTO(R_SPARC_PC_HM10
, 32,2,10,TRUE
, 0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_PC_HM10", FALSE
,0,0x000003ff,TRUE
),
189 HOWTO(R_SPARC_PC_LM22
, 10,2,22,TRUE
, 0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_PC_LM22", FALSE
,0,0x003fffff,TRUE
),
190 HOWTO(R_SPARC_WDISP16
, 2,2,16,TRUE
, 0,complain_overflow_signed
, sparc_elf_wdisp16_reloc
,"R_SPARC_WDISP16", FALSE
,0,0x00000000,TRUE
),
191 HOWTO(R_SPARC_WDISP19
, 2,2,19,TRUE
, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_WDISP19", FALSE
,0,0x0007ffff,TRUE
),
192 HOWTO(R_SPARC_UNUSED_42
, 0,0, 0,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_UNUSED_42",FALSE
,0,0x00000000,TRUE
),
193 HOWTO(R_SPARC_7
, 0,2, 7,FALSE
,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_7", FALSE
,0,0x0000007f,TRUE
),
194 HOWTO(R_SPARC_5
, 0,2, 5,FALSE
,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_5", FALSE
,0,0x0000001f,TRUE
),
195 HOWTO(R_SPARC_6
, 0,2, 6,FALSE
,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_6", FALSE
,0,0x0000003f,TRUE
),
196 HOWTO(R_SPARC_DISP64
, 0,4,64,TRUE
, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_DISP64", FALSE
,0,MINUS_ONE
, TRUE
),
197 HOWTO(R_SPARC_PLT64
, 0,4,64,FALSE
,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_PLT64", FALSE
,0,MINUS_ONE
, TRUE
),
198 HOWTO(R_SPARC_HIX22
, 0,4, 0,FALSE
,0,complain_overflow_bitfield
,sparc_elf_hix22_reloc
, "R_SPARC_HIX22", FALSE
,0,MINUS_ONE
, FALSE
),
199 HOWTO(R_SPARC_LOX10
, 0,4, 0,FALSE
,0,complain_overflow_dont
, sparc_elf_lox10_reloc
, "R_SPARC_LOX10", FALSE
,0,MINUS_ONE
, FALSE
),
200 HOWTO(R_SPARC_H44
, 22,2,22,FALSE
,0,complain_overflow_unsigned
,bfd_elf_generic_reloc
, "R_SPARC_H44", FALSE
,0,0x003fffff,FALSE
),
201 HOWTO(R_SPARC_M44
, 12,2,10,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_M44", FALSE
,0,0x000003ff,FALSE
),
202 HOWTO(R_SPARC_L44
, 0,2,13,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_L44", FALSE
,0,0x00000fff,FALSE
),
203 HOWTO(R_SPARC_REGISTER
, 0,4, 0,FALSE
,0,complain_overflow_bitfield
,sparc_elf_notsup_reloc
, "R_SPARC_REGISTER",FALSE
,0,MINUS_ONE
, FALSE
),
204 HOWTO(R_SPARC_UA64
, 0,4,64,FALSE
,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_UA64", FALSE
,0,MINUS_ONE
, TRUE
),
205 HOWTO(R_SPARC_UA16
, 0,1,16,FALSE
,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_UA16", FALSE
,0,0x0000ffff,TRUE
),
206 HOWTO(R_SPARC_TLS_GD_HI22
,10,2,22,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_TLS_GD_HI22",FALSE
,0,0x003fffff,TRUE
),
207 HOWTO(R_SPARC_TLS_GD_LO10
,0,2,10,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_TLS_GD_LO10",FALSE
,0,0x000003ff,TRUE
),
208 HOWTO(R_SPARC_TLS_GD_ADD
,0,0, 0,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_TLS_GD_ADD",FALSE
,0,0x00000000,TRUE
),
209 HOWTO(R_SPARC_TLS_GD_CALL
,2,2,30,TRUE
,0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_TLS_GD_CALL",FALSE
,0,0x3fffffff,TRUE
),
210 HOWTO(R_SPARC_TLS_LDM_HI22
,10,2,22,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_TLS_LDM_HI22",FALSE
,0,0x003fffff,TRUE
),
211 HOWTO(R_SPARC_TLS_LDM_LO10
,0,2,10,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_TLS_LDM_LO10",FALSE
,0,0x000003ff,TRUE
),
212 HOWTO(R_SPARC_TLS_LDM_ADD
,0,0, 0,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_TLS_LDM_ADD",FALSE
,0,0x00000000,TRUE
),
213 HOWTO(R_SPARC_TLS_LDM_CALL
,2,2,30,TRUE
,0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_TLS_LDM_CALL",FALSE
,0,0x3fffffff,TRUE
),
214 HOWTO(R_SPARC_TLS_LDO_HIX22
,0,2,0,FALSE
,0,complain_overflow_bitfield
,sparc_elf_hix22_reloc
,"R_SPARC_TLS_LDO_HIX22",FALSE
,0,0x003fffff, FALSE
),
215 HOWTO(R_SPARC_TLS_LDO_LOX10
,0,2,0,FALSE
,0,complain_overflow_dont
, sparc_elf_lox10_reloc
, "R_SPARC_TLS_LDO_LOX10",FALSE
,0,0x000003ff, FALSE
),
216 HOWTO(R_SPARC_TLS_LDO_ADD
,0,0, 0,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_TLS_LDO_ADD",FALSE
,0,0x00000000,TRUE
),
217 HOWTO(R_SPARC_TLS_IE_HI22
,10,2,22,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_TLS_IE_HI22",FALSE
,0,0x003fffff,TRUE
),
218 HOWTO(R_SPARC_TLS_IE_LO10
,0,2,10,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_TLS_IE_LO10",FALSE
,0,0x000003ff,TRUE
),
219 HOWTO(R_SPARC_TLS_IE_LD
,0,0, 0,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_TLS_IE_LD",FALSE
,0,0x00000000,TRUE
),
220 HOWTO(R_SPARC_TLS_IE_LDX
,0,0, 0,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_TLS_IE_LDX",FALSE
,0,0x00000000,TRUE
),
221 HOWTO(R_SPARC_TLS_IE_ADD
,0,0, 0,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_TLS_IE_ADD",FALSE
,0,0x00000000,TRUE
),
222 HOWTO(R_SPARC_TLS_LE_HIX22
,0,2,0,FALSE
,0,complain_overflow_bitfield
,sparc_elf_hix22_reloc
, "R_SPARC_TLS_LE_HIX22",FALSE
,0,0x003fffff, FALSE
),
223 HOWTO(R_SPARC_TLS_LE_LOX10
,0,2,0,FALSE
,0,complain_overflow_dont
, sparc_elf_lox10_reloc
, "R_SPARC_TLS_LE_LOX10",FALSE
,0,0x000003ff, FALSE
),
224 HOWTO(R_SPARC_TLS_DTPMOD32
,0,0, 0,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_TLS_DTPMOD32",FALSE
,0,0x00000000,TRUE
),
225 HOWTO(R_SPARC_TLS_DTPMOD64
,0,0, 0,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_TLS_DTPMOD64",FALSE
,0,0x00000000,TRUE
),
226 HOWTO(R_SPARC_TLS_DTPOFF32
,0,2,32,FALSE
,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
,"R_SPARC_TLS_DTPOFF32",FALSE
,0,0xffffffff,TRUE
),
227 HOWTO(R_SPARC_TLS_DTPOFF64
,0,4,64,FALSE
,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
,"R_SPARC_TLS_DTPOFF64",FALSE
,0,MINUS_ONE
,TRUE
),
228 HOWTO(R_SPARC_TLS_TPOFF32
,0,0, 0,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_TLS_TPOFF32",FALSE
,0,0x00000000,TRUE
),
229 HOWTO(R_SPARC_TLS_TPOFF64
,0,0, 0,FALSE
,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_TLS_TPOFF64",FALSE
,0,0x00000000,TRUE
)
232 struct elf_reloc_map
{
233 bfd_reloc_code_real_type bfd_reloc_val
;
234 unsigned char elf_reloc_val
;
237 static const struct elf_reloc_map sparc_reloc_map
[] =
239 { BFD_RELOC_NONE
, R_SPARC_NONE
, },
240 { BFD_RELOC_16
, R_SPARC_16
, },
241 { BFD_RELOC_16_PCREL
, R_SPARC_DISP16
},
242 { BFD_RELOC_8
, R_SPARC_8
},
243 { BFD_RELOC_8_PCREL
, R_SPARC_DISP8
},
244 { BFD_RELOC_CTOR
, R_SPARC_64
},
245 { BFD_RELOC_32
, R_SPARC_32
},
246 { BFD_RELOC_32_PCREL
, R_SPARC_DISP32
},
247 { BFD_RELOC_HI22
, R_SPARC_HI22
},
248 { BFD_RELOC_LO10
, R_SPARC_LO10
, },
249 { BFD_RELOC_32_PCREL_S2
, R_SPARC_WDISP30
},
250 { BFD_RELOC_64_PCREL
, R_SPARC_DISP64
},
251 { BFD_RELOC_SPARC22
, R_SPARC_22
},
252 { BFD_RELOC_SPARC13
, R_SPARC_13
},
253 { BFD_RELOC_SPARC_GOT10
, R_SPARC_GOT10
},
254 { BFD_RELOC_SPARC_GOT13
, R_SPARC_GOT13
},
255 { BFD_RELOC_SPARC_GOT22
, R_SPARC_GOT22
},
256 { BFD_RELOC_SPARC_PC10
, R_SPARC_PC10
},
257 { BFD_RELOC_SPARC_PC22
, R_SPARC_PC22
},
258 { BFD_RELOC_SPARC_WPLT30
, R_SPARC_WPLT30
},
259 { BFD_RELOC_SPARC_COPY
, R_SPARC_COPY
},
260 { BFD_RELOC_SPARC_GLOB_DAT
, R_SPARC_GLOB_DAT
},
261 { BFD_RELOC_SPARC_JMP_SLOT
, R_SPARC_JMP_SLOT
},
262 { BFD_RELOC_SPARC_RELATIVE
, R_SPARC_RELATIVE
},
263 { BFD_RELOC_SPARC_WDISP22
, R_SPARC_WDISP22
},
264 { BFD_RELOC_SPARC_UA16
, R_SPARC_UA16
},
265 { BFD_RELOC_SPARC_UA32
, R_SPARC_UA32
},
266 { BFD_RELOC_SPARC_UA64
, R_SPARC_UA64
},
267 { BFD_RELOC_SPARC_10
, R_SPARC_10
},
268 { BFD_RELOC_SPARC_11
, R_SPARC_11
},
269 { BFD_RELOC_SPARC_64
, R_SPARC_64
},
270 { BFD_RELOC_SPARC_OLO10
, R_SPARC_OLO10
},
271 { BFD_RELOC_SPARC_HH22
, R_SPARC_HH22
},
272 { BFD_RELOC_SPARC_HM10
, R_SPARC_HM10
},
273 { BFD_RELOC_SPARC_LM22
, R_SPARC_LM22
},
274 { BFD_RELOC_SPARC_PC_HH22
, R_SPARC_PC_HH22
},
275 { BFD_RELOC_SPARC_PC_HM10
, R_SPARC_PC_HM10
},
276 { BFD_RELOC_SPARC_PC_LM22
, R_SPARC_PC_LM22
},
277 { BFD_RELOC_SPARC_WDISP16
, R_SPARC_WDISP16
},
278 { BFD_RELOC_SPARC_WDISP19
, R_SPARC_WDISP19
},
279 { BFD_RELOC_SPARC_7
, R_SPARC_7
},
280 { BFD_RELOC_SPARC_5
, R_SPARC_5
},
281 { BFD_RELOC_SPARC_6
, R_SPARC_6
},
282 { BFD_RELOC_SPARC_DISP64
, R_SPARC_DISP64
},
283 { BFD_RELOC_SPARC_TLS_GD_HI22
, R_SPARC_TLS_GD_HI22
},
284 { BFD_RELOC_SPARC_TLS_GD_LO10
, R_SPARC_TLS_GD_LO10
},
285 { BFD_RELOC_SPARC_TLS_GD_ADD
, R_SPARC_TLS_GD_ADD
},
286 { BFD_RELOC_SPARC_TLS_GD_CALL
, R_SPARC_TLS_GD_CALL
},
287 { BFD_RELOC_SPARC_TLS_LDM_HI22
, R_SPARC_TLS_LDM_HI22
},
288 { BFD_RELOC_SPARC_TLS_LDM_LO10
, R_SPARC_TLS_LDM_LO10
},
289 { BFD_RELOC_SPARC_TLS_LDM_ADD
, R_SPARC_TLS_LDM_ADD
},
290 { BFD_RELOC_SPARC_TLS_LDM_CALL
, R_SPARC_TLS_LDM_CALL
},
291 { BFD_RELOC_SPARC_TLS_LDO_HIX22
, R_SPARC_TLS_LDO_HIX22
},
292 { BFD_RELOC_SPARC_TLS_LDO_LOX10
, R_SPARC_TLS_LDO_LOX10
},
293 { BFD_RELOC_SPARC_TLS_LDO_ADD
, R_SPARC_TLS_LDO_ADD
},
294 { BFD_RELOC_SPARC_TLS_IE_HI22
, R_SPARC_TLS_IE_HI22
},
295 { BFD_RELOC_SPARC_TLS_IE_LO10
, R_SPARC_TLS_IE_LO10
},
296 { BFD_RELOC_SPARC_TLS_IE_LD
, R_SPARC_TLS_IE_LD
},
297 { BFD_RELOC_SPARC_TLS_IE_LDX
, R_SPARC_TLS_IE_LDX
},
298 { BFD_RELOC_SPARC_TLS_IE_ADD
, R_SPARC_TLS_IE_ADD
},
299 { BFD_RELOC_SPARC_TLS_LE_HIX22
, R_SPARC_TLS_LE_HIX22
},
300 { BFD_RELOC_SPARC_TLS_LE_LOX10
, R_SPARC_TLS_LE_LOX10
},
301 { BFD_RELOC_SPARC_TLS_DTPMOD32
, R_SPARC_TLS_DTPMOD32
},
302 { BFD_RELOC_SPARC_TLS_DTPMOD64
, R_SPARC_TLS_DTPMOD64
},
303 { BFD_RELOC_SPARC_TLS_DTPOFF32
, R_SPARC_TLS_DTPOFF32
},
304 { BFD_RELOC_SPARC_TLS_DTPOFF64
, R_SPARC_TLS_DTPOFF64
},
305 { BFD_RELOC_SPARC_TLS_TPOFF32
, R_SPARC_TLS_TPOFF32
},
306 { BFD_RELOC_SPARC_TLS_TPOFF64
, R_SPARC_TLS_TPOFF64
},
307 #ifndef SPARC64_OLD_RELOCS
308 { BFD_RELOC_SPARC_PLT32
, R_SPARC_PLT32
},
310 { BFD_RELOC_SPARC_PLT64
, R_SPARC_PLT64
},
311 { BFD_RELOC_SPARC_HIX22
, R_SPARC_HIX22
},
312 { BFD_RELOC_SPARC_LOX10
, R_SPARC_LOX10
},
313 { BFD_RELOC_SPARC_H44
, R_SPARC_H44
},
314 { BFD_RELOC_SPARC_M44
, R_SPARC_M44
},
315 { BFD_RELOC_SPARC_L44
, R_SPARC_L44
},
316 { BFD_RELOC_SPARC_REGISTER
, R_SPARC_REGISTER
}
319 static reloc_howto_type
*
320 sparc64_elf_reloc_type_lookup (abfd
, code
)
321 bfd
*abfd ATTRIBUTE_UNUSED
;
322 bfd_reloc_code_real_type code
;
325 for (i
= 0; i
< sizeof (sparc_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
327 if (sparc_reloc_map
[i
].bfd_reloc_val
== code
)
328 return &sparc64_elf_howto_table
[(int) sparc_reloc_map
[i
].elf_reloc_val
];
334 sparc64_elf_info_to_howto (abfd
, cache_ptr
, dst
)
335 bfd
*abfd ATTRIBUTE_UNUSED
;
337 Elf_Internal_Rela
*dst
;
339 BFD_ASSERT (ELF64_R_TYPE_ID (dst
->r_info
) < (unsigned int) R_SPARC_max_std
);
340 cache_ptr
->howto
= &sparc64_elf_howto_table
[ELF64_R_TYPE_ID (dst
->r_info
)];
343 struct sparc64_elf_section_data
345 struct bfd_elf_section_data elf
;
346 unsigned int do_relax
, reloc_count
;
349 #define sec_do_relax(sec) \
350 ((struct sparc64_elf_section_data *) elf_section_data (sec))->do_relax
351 #define canon_reloc_count(sec) \
352 ((struct sparc64_elf_section_data *) elf_section_data (sec))->reloc_count
354 /* Due to the way how we handle R_SPARC_OLO10, each entry in a SHT_RELA
355 section can represent up to two relocs, we must tell the user to allocate
359 sparc64_elf_get_reloc_upper_bound (abfd
, sec
)
360 bfd
*abfd ATTRIBUTE_UNUSED
;
363 return (sec
->reloc_count
* 2 + 1) * sizeof (arelent
*);
367 sparc64_elf_get_dynamic_reloc_upper_bound (abfd
)
370 return _bfd_elf_get_dynamic_reloc_upper_bound (abfd
) * 2;
373 /* Read relocations for ASECT from REL_HDR. There are RELOC_COUNT of
374 them. We cannot use generic elf routines for this, because R_SPARC_OLO10
375 has secondary addend in ELF64_R_TYPE_DATA. We handle it as two relocations
376 for the same location, R_SPARC_LO10 and R_SPARC_13. */
379 sparc64_elf_slurp_one_reloc_table (abfd
, asect
, rel_hdr
, symbols
, dynamic
)
382 Elf_Internal_Shdr
*rel_hdr
;
386 PTR allocated
= NULL
;
387 bfd_byte
*native_relocs
;
394 allocated
= (PTR
) bfd_malloc (rel_hdr
->sh_size
);
395 if (allocated
== NULL
)
398 if (bfd_seek (abfd
, rel_hdr
->sh_offset
, SEEK_SET
) != 0
399 || bfd_bread (allocated
, rel_hdr
->sh_size
, abfd
) != rel_hdr
->sh_size
)
402 native_relocs
= (bfd_byte
*) allocated
;
404 relents
= asect
->relocation
+ canon_reloc_count (asect
);
406 entsize
= rel_hdr
->sh_entsize
;
407 BFD_ASSERT (entsize
== sizeof (Elf64_External_Rela
));
409 count
= rel_hdr
->sh_size
/ entsize
;
411 for (i
= 0, relent
= relents
; i
< count
;
412 i
++, relent
++, native_relocs
+= entsize
)
414 Elf_Internal_Rela rela
;
416 bfd_elf64_swap_reloca_in (abfd
, native_relocs
, &rela
);
418 /* The address of an ELF reloc is section relative for an object
419 file, and absolute for an executable file or shared library.
420 The address of a normal BFD reloc is always section relative,
421 and the address of a dynamic reloc is absolute.. */
422 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0 || dynamic
)
423 relent
->address
= rela
.r_offset
;
425 relent
->address
= rela
.r_offset
- asect
->vma
;
427 if (ELF64_R_SYM (rela
.r_info
) == 0)
428 relent
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
433 ps
= symbols
+ ELF64_R_SYM (rela
.r_info
) - 1;
436 /* Canonicalize ELF section symbols. FIXME: Why? */
437 if ((s
->flags
& BSF_SECTION_SYM
) == 0)
438 relent
->sym_ptr_ptr
= ps
;
440 relent
->sym_ptr_ptr
= s
->section
->symbol_ptr_ptr
;
443 relent
->addend
= rela
.r_addend
;
445 BFD_ASSERT (ELF64_R_TYPE_ID (rela
.r_info
) < (unsigned int) R_SPARC_max_std
);
446 if (ELF64_R_TYPE_ID (rela
.r_info
) == R_SPARC_OLO10
)
448 relent
->howto
= &sparc64_elf_howto_table
[R_SPARC_LO10
];
449 relent
[1].address
= relent
->address
;
451 relent
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
452 relent
->addend
= ELF64_R_TYPE_DATA (rela
.r_info
);
453 relent
->howto
= &sparc64_elf_howto_table
[R_SPARC_13
];
456 relent
->howto
= &sparc64_elf_howto_table
[ELF64_R_TYPE_ID (rela
.r_info
)];
459 canon_reloc_count (asect
) += relent
- relents
;
461 if (allocated
!= NULL
)
467 if (allocated
!= NULL
)
472 /* Read in and swap the external relocs. */
475 sparc64_elf_slurp_reloc_table (abfd
, asect
, symbols
, dynamic
)
481 struct bfd_elf_section_data
* const d
= elf_section_data (asect
);
482 Elf_Internal_Shdr
*rel_hdr
;
483 Elf_Internal_Shdr
*rel_hdr2
;
486 if (asect
->relocation
!= NULL
)
491 if ((asect
->flags
& SEC_RELOC
) == 0
492 || asect
->reloc_count
== 0)
495 rel_hdr
= &d
->rel_hdr
;
496 rel_hdr2
= d
->rel_hdr2
;
498 BFD_ASSERT (asect
->rel_filepos
== rel_hdr
->sh_offset
499 || (rel_hdr2
&& asect
->rel_filepos
== rel_hdr2
->sh_offset
));
503 /* Note that ASECT->RELOC_COUNT tends not to be accurate in this
504 case because relocations against this section may use the
505 dynamic symbol table, and in that case bfd_section_from_shdr
506 in elf.c does not update the RELOC_COUNT. */
507 if (asect
->size
== 0)
510 rel_hdr
= &d
->this_hdr
;
511 asect
->reloc_count
= NUM_SHDR_ENTRIES (rel_hdr
);
515 amt
= asect
->reloc_count
;
516 amt
*= 2 * sizeof (arelent
);
517 asect
->relocation
= (arelent
*) bfd_alloc (abfd
, amt
);
518 if (asect
->relocation
== NULL
)
521 /* The sparc64_elf_slurp_one_reloc_table routine increments
522 canon_reloc_count. */
523 canon_reloc_count (asect
) = 0;
525 if (!sparc64_elf_slurp_one_reloc_table (abfd
, asect
, rel_hdr
, symbols
,
530 && !sparc64_elf_slurp_one_reloc_table (abfd
, asect
, rel_hdr2
, symbols
,
537 /* Canonicalize the relocs. */
540 sparc64_elf_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
548 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
550 if (! bed
->s
->slurp_reloc_table (abfd
, section
, symbols
, FALSE
))
553 tblptr
= section
->relocation
;
554 for (i
= 0; i
< canon_reloc_count (section
); i
++)
555 *relptr
++ = tblptr
++;
559 return canon_reloc_count (section
);
563 /* Canonicalize the dynamic relocation entries. Note that we return
564 the dynamic relocations as a single block, although they are
565 actually associated with particular sections; the interface, which
566 was designed for SunOS style shared libraries, expects that there
567 is only one set of dynamic relocs. Any section that was actually
568 installed in the BFD, and has type SHT_REL or SHT_RELA, and uses
569 the dynamic symbol table, is considered to be a dynamic reloc
573 sparc64_elf_canonicalize_dynamic_reloc (abfd
, storage
, syms
)
581 if (elf_dynsymtab (abfd
) == 0)
583 bfd_set_error (bfd_error_invalid_operation
);
588 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
590 if (elf_section_data (s
)->this_hdr
.sh_link
== elf_dynsymtab (abfd
)
591 && (elf_section_data (s
)->this_hdr
.sh_type
== SHT_RELA
))
596 if (! sparc64_elf_slurp_reloc_table (abfd
, s
, syms
, TRUE
))
598 count
= canon_reloc_count (s
);
600 for (i
= 0; i
< count
; i
++)
611 /* Write out the relocs. */
614 sparc64_elf_write_relocs (abfd
, sec
, data
)
619 bfd_boolean
*failedp
= (bfd_boolean
*) data
;
620 Elf_Internal_Shdr
*rela_hdr
;
621 Elf64_External_Rela
*outbound_relocas
, *src_rela
;
622 unsigned int idx
, count
;
623 asymbol
*last_sym
= 0;
624 int last_sym_idx
= 0;
626 /* If we have already failed, don't do anything. */
630 if ((sec
->flags
& SEC_RELOC
) == 0)
633 /* The linker backend writes the relocs out itself, and sets the
634 reloc_count field to zero to inhibit writing them here. Also,
635 sometimes the SEC_RELOC flag gets set even when there aren't any
637 if (sec
->reloc_count
== 0)
640 /* We can combine two relocs that refer to the same address
641 into R_SPARC_OLO10 if first one is R_SPARC_LO10 and the
642 latter is R_SPARC_13 with no associated symbol. */
644 for (idx
= 0; idx
< sec
->reloc_count
; idx
++)
650 addr
= sec
->orelocation
[idx
]->address
;
651 if (sec
->orelocation
[idx
]->howto
->type
== R_SPARC_LO10
652 && idx
< sec
->reloc_count
- 1)
654 arelent
*r
= sec
->orelocation
[idx
+ 1];
656 if (r
->howto
->type
== R_SPARC_13
657 && r
->address
== addr
658 && bfd_is_abs_section ((*r
->sym_ptr_ptr
)->section
)
659 && (*r
->sym_ptr_ptr
)->value
== 0)
664 rela_hdr
= &elf_section_data (sec
)->rel_hdr
;
666 rela_hdr
->sh_size
= rela_hdr
->sh_entsize
* count
;
667 rela_hdr
->contents
= (PTR
) bfd_alloc (abfd
, rela_hdr
->sh_size
);
668 if (rela_hdr
->contents
== NULL
)
674 /* Figure out whether the relocations are RELA or REL relocations. */
675 if (rela_hdr
->sh_type
!= SHT_RELA
)
678 /* orelocation has the data, reloc_count has the count... */
679 outbound_relocas
= (Elf64_External_Rela
*) rela_hdr
->contents
;
680 src_rela
= outbound_relocas
;
682 for (idx
= 0; idx
< sec
->reloc_count
; idx
++)
684 Elf_Internal_Rela dst_rela
;
689 ptr
= sec
->orelocation
[idx
];
691 /* The address of an ELF reloc is section relative for an object
692 file, and absolute for an executable file or shared library.
693 The address of a BFD reloc is always section relative. */
694 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0)
695 dst_rela
.r_offset
= ptr
->address
;
697 dst_rela
.r_offset
= ptr
->address
+ sec
->vma
;
699 sym
= *ptr
->sym_ptr_ptr
;
702 else if (bfd_is_abs_section (sym
->section
) && sym
->value
== 0)
707 n
= _bfd_elf_symbol_from_bfd_symbol (abfd
, &sym
);
716 if ((*ptr
->sym_ptr_ptr
)->the_bfd
!= NULL
717 && (*ptr
->sym_ptr_ptr
)->the_bfd
->xvec
!= abfd
->xvec
718 && ! _bfd_elf_validate_reloc (abfd
, ptr
))
724 if (ptr
->howto
->type
== R_SPARC_LO10
725 && idx
< sec
->reloc_count
- 1)
727 arelent
*r
= sec
->orelocation
[idx
+ 1];
729 if (r
->howto
->type
== R_SPARC_13
730 && r
->address
== ptr
->address
731 && bfd_is_abs_section ((*r
->sym_ptr_ptr
)->section
)
732 && (*r
->sym_ptr_ptr
)->value
== 0)
736 = ELF64_R_INFO (n
, ELF64_R_TYPE_INFO (r
->addend
,
740 dst_rela
.r_info
= ELF64_R_INFO (n
, R_SPARC_LO10
);
743 dst_rela
.r_info
= ELF64_R_INFO (n
, ptr
->howto
->type
);
745 dst_rela
.r_addend
= ptr
->addend
;
746 bfd_elf64_swap_reloca_out (abfd
, &dst_rela
, (bfd_byte
*) src_rela
);
751 /* The SPARC linker needs to keep track of the number of relocs that it
752 decides to copy as dynamic relocs in check_relocs for each symbol.
753 This is so that it can later discard them if they are found to be
754 unnecessary. We store the information in a field extending the
755 regular ELF linker hash table. */
757 struct sparc64_elf_dyn_relocs
759 struct sparc64_elf_dyn_relocs
*next
;
761 /* The input section of the reloc. */
764 /* Total number of relocs copied for the input section. */
767 /* Number of pc-relative relocs copied for the input section. */
768 bfd_size_type pc_count
;
771 /* SPARC ELF linker hash entry. */
773 struct sparc64_elf_link_hash_entry
775 struct elf_link_hash_entry elf
;
777 /* Track dynamic relocs copied for this symbol. */
778 struct sparc64_elf_dyn_relocs
*dyn_relocs
;
780 #define GOT_UNKNOWN 0
784 unsigned char tls_type
;
787 #define sparc64_elf_hash_entry(ent) ((struct sparc64_elf_link_hash_entry *)(ent))
789 struct sparc64_elf_obj_tdata
791 struct elf_obj_tdata root
;
793 /* tls_type for each local got entry. */
794 char *local_got_tls_type
;
796 /* TRUE if TLS GD relocs has been seen for this object. */
797 bfd_boolean has_tlsgd
;
800 #define sparc64_elf_tdata(abfd) \
801 ((struct sparc64_elf_obj_tdata *) (abfd)->tdata.any)
803 #define sparc64_elf_local_got_tls_type(abfd) \
804 (sparc64_elf_tdata (abfd)->local_got_tls_type)
807 sparc64_elf_mkobject (abfd
)
810 bfd_size_type amt
= sizeof (struct sparc64_elf_obj_tdata
);
811 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
812 if (abfd
->tdata
.any
== NULL
)
817 /* Sparc64 ELF linker hash table. */
819 struct sparc64_elf_app_reg
822 unsigned short shndx
;
827 struct sparc64_elf_link_hash_table
829 struct elf_link_hash_table elf
;
831 /* Short-cuts to get to dynamic linker sections. */
840 bfd_signed_vma refcount
;
844 /* Small local sym to section mapping cache. */
845 struct sym_sec_cache sym_sec
;
847 struct sparc64_elf_app_reg app_regs
[4];
850 /* Get the Sparc64 ELF linker hash table from a link_info structure. */
852 #define sparc64_elf_hash_table(p) \
853 ((struct sparc64_elf_link_hash_table *) ((p)->hash))
855 /* Create an entry in an SPARC ELF linker hash table. */
857 static struct bfd_hash_entry
*
858 link_hash_newfunc (entry
, table
, string
)
859 struct bfd_hash_entry
*entry
;
860 struct bfd_hash_table
*table
;
863 /* Allocate the structure if it has not already been allocated by a
867 entry
= bfd_hash_allocate (table
,
868 sizeof (struct sparc64_elf_link_hash_entry
));
873 /* Call the allocation method of the superclass. */
874 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
877 struct sparc64_elf_link_hash_entry
*eh
;
879 eh
= (struct sparc64_elf_link_hash_entry
*) entry
;
880 eh
->dyn_relocs
= NULL
;
881 eh
->tls_type
= GOT_UNKNOWN
;
887 /* Create a SPARC64 ELF linker hash table. */
889 static struct bfd_link_hash_table
*
890 sparc64_elf_link_hash_table_create (abfd
)
893 struct sparc64_elf_link_hash_table
*ret
;
894 bfd_size_type amt
= sizeof (struct sparc64_elf_link_hash_table
);
896 ret
= (struct sparc64_elf_link_hash_table
*) bfd_zmalloc (amt
);
900 if (! _bfd_elf_link_hash_table_init (&ret
->elf
, abfd
, link_hash_newfunc
))
906 return &ret
->elf
.root
;
909 /* Create .got and .rela.got sections in DYNOBJ, and set up
910 shortcuts to them in our hash table. */
913 create_got_section (dynobj
, info
)
915 struct bfd_link_info
*info
;
917 struct sparc64_elf_link_hash_table
*htab
;
919 if (! _bfd_elf_create_got_section (dynobj
, info
))
922 htab
= sparc64_elf_hash_table (info
);
923 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
924 BFD_ASSERT (htab
->sgot
!= NULL
);
926 htab
->srelgot
= bfd_make_section (dynobj
, ".rela.got");
927 if (htab
->srelgot
== NULL
928 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
, SEC_ALLOC
934 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 3))
939 /* Create .plt, .rela.plt, .got, .rela.got, .dynbss, and
940 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
944 sparc64_elf_create_dynamic_sections (dynobj
, info
)
946 struct bfd_link_info
*info
;
948 struct sparc64_elf_link_hash_table
*htab
;
950 htab
= sparc64_elf_hash_table (info
);
951 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
954 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
957 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
958 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
959 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
961 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
963 if (!htab
->splt
|| !htab
->srelplt
|| !htab
->sdynbss
964 || (!info
->shared
&& !htab
->srelbss
))
970 /* Copy the extra info we tack onto an elf_link_hash_entry. */
973 sparc64_elf_copy_indirect_symbol (bed
, dir
, ind
)
974 const struct elf_backend_data
*bed
;
975 struct elf_link_hash_entry
*dir
, *ind
;
977 struct sparc64_elf_link_hash_entry
*edir
, *eind
;
979 edir
= (struct sparc64_elf_link_hash_entry
*) dir
;
980 eind
= (struct sparc64_elf_link_hash_entry
*) ind
;
982 if (eind
->dyn_relocs
!= NULL
)
984 if (edir
->dyn_relocs
!= NULL
)
986 struct sparc64_elf_dyn_relocs
**pp
;
987 struct sparc64_elf_dyn_relocs
*p
;
989 if (ind
->root
.type
== bfd_link_hash_indirect
)
992 /* Add reloc counts against the weak sym to the strong sym
993 list. Merge any entries against the same section. */
994 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
996 struct sparc64_elf_dyn_relocs
*q
;
998 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
999 if (q
->sec
== p
->sec
)
1001 q
->pc_count
+= p
->pc_count
;
1002 q
->count
+= p
->count
;
1009 *pp
= edir
->dyn_relocs
;
1012 edir
->dyn_relocs
= eind
->dyn_relocs
;
1013 eind
->dyn_relocs
= NULL
;
1016 if (ind
->root
.type
== bfd_link_hash_indirect
1017 && dir
->got
.refcount
<= 0)
1019 edir
->tls_type
= eind
->tls_type
;
1020 eind
->tls_type
= GOT_UNKNOWN
;
1022 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
1026 sparc64_elf_tls_transition (info
, r_type
, is_local
)
1027 struct bfd_link_info
*info
;
1036 case R_SPARC_TLS_GD_HI22
:
1038 return R_SPARC_TLS_LE_HIX22
;
1039 return R_SPARC_TLS_IE_HI22
;
1040 case R_SPARC_TLS_GD_LO10
:
1042 return R_SPARC_TLS_LE_LOX10
;
1043 return R_SPARC_TLS_IE_LO10
;
1044 case R_SPARC_TLS_IE_HI22
:
1046 return R_SPARC_TLS_LE_HIX22
;
1048 case R_SPARC_TLS_IE_LO10
:
1050 return R_SPARC_TLS_LE_LOX10
;
1052 case R_SPARC_TLS_LDM_HI22
:
1053 return R_SPARC_TLS_LE_HIX22
;
1054 case R_SPARC_TLS_LDM_LO10
:
1055 return R_SPARC_TLS_LE_LOX10
;
1062 /* Utility for performing the standard initial work of an instruction
1064 *PRELOCATION will contain the relocated item.
1065 *PINSN will contain the instruction from the input stream.
1066 If the result is `bfd_reloc_other' the caller can continue with
1067 performing the relocation. Otherwise it must stop and return the
1068 value to its caller. */
1070 static bfd_reloc_status_type
1071 init_insn_reloc (abfd
,
1080 arelent
*reloc_entry
;
1083 asection
*input_section
;
1085 bfd_vma
*prelocation
;
1089 reloc_howto_type
*howto
= reloc_entry
->howto
;
1091 if (output_bfd
!= (bfd
*) NULL
1092 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1093 && (! howto
->partial_inplace
1094 || reloc_entry
->addend
== 0))
1096 reloc_entry
->address
+= input_section
->output_offset
;
1097 return bfd_reloc_ok
;
1100 /* This works because partial_inplace is FALSE. */
1101 if (output_bfd
!= NULL
)
1102 return bfd_reloc_continue
;
1104 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1105 return bfd_reloc_outofrange
;
1107 relocation
= (symbol
->value
1108 + symbol
->section
->output_section
->vma
1109 + symbol
->section
->output_offset
);
1110 relocation
+= reloc_entry
->addend
;
1111 if (howto
->pc_relative
)
1113 relocation
-= (input_section
->output_section
->vma
1114 + input_section
->output_offset
);
1115 relocation
-= reloc_entry
->address
;
1118 *prelocation
= relocation
;
1119 *pinsn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1120 return bfd_reloc_other
;
1123 /* For unsupported relocs. */
1125 static bfd_reloc_status_type
1126 sparc_elf_notsup_reloc (abfd
,
1133 bfd
*abfd ATTRIBUTE_UNUSED
;
1134 arelent
*reloc_entry ATTRIBUTE_UNUSED
;
1135 asymbol
*symbol ATTRIBUTE_UNUSED
;
1136 PTR data ATTRIBUTE_UNUSED
;
1137 asection
*input_section ATTRIBUTE_UNUSED
;
1138 bfd
*output_bfd ATTRIBUTE_UNUSED
;
1139 char **error_message ATTRIBUTE_UNUSED
;
1141 return bfd_reloc_notsupported
;
1144 /* Handle the WDISP16 reloc. */
1146 static bfd_reloc_status_type
1147 sparc_elf_wdisp16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1148 output_bfd
, error_message
)
1150 arelent
*reloc_entry
;
1153 asection
*input_section
;
1155 char **error_message ATTRIBUTE_UNUSED
;
1159 bfd_reloc_status_type status
;
1161 status
= init_insn_reloc (abfd
, reloc_entry
, symbol
, data
,
1162 input_section
, output_bfd
, &relocation
, &insn
);
1163 if (status
!= bfd_reloc_other
)
1166 insn
&= ~ (bfd_vma
) 0x303fff;
1167 insn
|= (((relocation
>> 2) & 0xc000) << 6) | ((relocation
>> 2) & 0x3fff);
1168 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1170 if ((bfd_signed_vma
) relocation
< - 0x40000
1171 || (bfd_signed_vma
) relocation
> 0x3ffff)
1172 return bfd_reloc_overflow
;
1174 return bfd_reloc_ok
;
1177 /* Handle the HIX22 reloc. */
1179 static bfd_reloc_status_type
1180 sparc_elf_hix22_reloc (abfd
,
1188 arelent
*reloc_entry
;
1191 asection
*input_section
;
1193 char **error_message ATTRIBUTE_UNUSED
;
1197 bfd_reloc_status_type status
;
1199 status
= init_insn_reloc (abfd
, reloc_entry
, symbol
, data
,
1200 input_section
, output_bfd
, &relocation
, &insn
);
1201 if (status
!= bfd_reloc_other
)
1204 relocation
^= MINUS_ONE
;
1205 insn
= (insn
&~ (bfd_vma
) 0x3fffff) | ((relocation
>> 10) & 0x3fffff);
1206 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1208 if ((relocation
& ~ (bfd_vma
) 0xffffffff) != 0)
1209 return bfd_reloc_overflow
;
1211 return bfd_reloc_ok
;
1214 /* Handle the LOX10 reloc. */
1216 static bfd_reloc_status_type
1217 sparc_elf_lox10_reloc (abfd
,
1225 arelent
*reloc_entry
;
1228 asection
*input_section
;
1230 char **error_message ATTRIBUTE_UNUSED
;
1234 bfd_reloc_status_type status
;
1236 status
= init_insn_reloc (abfd
, reloc_entry
, symbol
, data
,
1237 input_section
, output_bfd
, &relocation
, &insn
);
1238 if (status
!= bfd_reloc_other
)
1241 insn
= (insn
&~ (bfd_vma
) 0x1fff) | 0x1c00 | (relocation
& 0x3ff);
1242 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1244 return bfd_reloc_ok
;
1249 /* Both the headers and the entries are icache aligned. */
1250 #define PLT_ENTRY_SIZE 32
1251 #define PLT_HEADER_SIZE (4 * PLT_ENTRY_SIZE)
1252 #define LARGE_PLT_THRESHOLD 32768
1253 #define GOT_RESERVED_ENTRIES 1
1255 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/sparcv9/ld.so.1"
1257 #define SPARC_NOP 0x01000000
1260 sparc64_plt_entry_build (output_bfd
, splt
, offset
, max
, r_offset
)
1267 unsigned char *entry
= splt
->contents
+ offset
;
1268 const unsigned int nop
= SPARC_NOP
;
1271 if (offset
< (LARGE_PLT_THRESHOLD
* PLT_ENTRY_SIZE
))
1273 unsigned int sethi
, ba
;
1277 index
= (offset
/ PLT_ENTRY_SIZE
);
1279 sethi
= 0x03000000 | (index
* PLT_ENTRY_SIZE
);
1281 | (((splt
->contents
+ PLT_ENTRY_SIZE
) - (entry
+ 4)) / 4 & 0x7ffff);
1283 bfd_put_32 (output_bfd
, (bfd_vma
) sethi
, entry
);
1284 bfd_put_32 (output_bfd
, (bfd_vma
) ba
, entry
+ 4);
1285 bfd_put_32 (output_bfd
, (bfd_vma
) nop
, entry
+ 8);
1286 bfd_put_32 (output_bfd
, (bfd_vma
) nop
, entry
+ 12);
1287 bfd_put_32 (output_bfd
, (bfd_vma
) nop
, entry
+ 16);
1288 bfd_put_32 (output_bfd
, (bfd_vma
) nop
, entry
+ 20);
1289 bfd_put_32 (output_bfd
, (bfd_vma
) nop
, entry
+ 24);
1290 bfd_put_32 (output_bfd
, (bfd_vma
) nop
, entry
+ 28);
1296 int block
, last_block
, ofs
, last_ofs
, chunks_this_block
;
1297 const int insn_chunk_size
= (6 * 4);
1298 const int ptr_chunk_size
= (1 * 8);
1299 const int entries_per_block
= 160;
1300 const int block_size
= entries_per_block
* (insn_chunk_size
1303 /* Entries 32768 and higher are grouped into blocks of 160.
1304 The blocks are further subdivided into 160 sequences of
1305 6 instructions and 160 pointers. If a block does not require
1306 the full 160 entries, let's say it requires N, then there
1307 will be N sequences of 6 instructions and N pointers. */
1309 offset
-= (LARGE_PLT_THRESHOLD
* PLT_ENTRY_SIZE
);
1310 max
-= (LARGE_PLT_THRESHOLD
* PLT_ENTRY_SIZE
);
1312 block
= offset
/ block_size
;
1313 last_block
= max
/ block_size
;
1314 if (block
!= last_block
)
1316 chunks_this_block
= 160;
1320 last_ofs
= max
% block_size
;
1321 chunks_this_block
= last_ofs
/ (insn_chunk_size
+ ptr_chunk_size
);
1324 ofs
= offset
% block_size
;
1326 index
= (LARGE_PLT_THRESHOLD
+
1328 (ofs
/ insn_chunk_size
));
1330 ptr
= splt
->contents
1331 + (LARGE_PLT_THRESHOLD
* PLT_ENTRY_SIZE
)
1332 + (block
* block_size
)
1333 + (chunks_this_block
* insn_chunk_size
)
1334 + (ofs
/ insn_chunk_size
) * ptr_chunk_size
;
1336 *r_offset
= (bfd_vma
) (ptr
- splt
->contents
);
1338 ldx
= 0xc25be000 | ((ptr
- (entry
+4)) & 0x1fff);
1346 bfd_put_32 (output_bfd
, (bfd_vma
) 0x8a10000f, entry
);
1347 bfd_put_32 (output_bfd
, (bfd_vma
) 0x40000002, entry
+ 4);
1348 bfd_put_32 (output_bfd
, (bfd_vma
) SPARC_NOP
, entry
+ 8);
1349 bfd_put_32 (output_bfd
, (bfd_vma
) ldx
, entry
+ 12);
1350 bfd_put_32 (output_bfd
, (bfd_vma
) 0x83c3c001, entry
+ 16);
1351 bfd_put_32 (output_bfd
, (bfd_vma
) 0x9e100005, entry
+ 20);
1353 bfd_put_64 (output_bfd
, (bfd_vma
) (splt
->contents
- (entry
+ 4)), ptr
);
1359 /* Look through the relocs for a section during the first phase, and
1360 allocate space in the global offset table or procedure linkage
1364 sparc64_elf_check_relocs (abfd
, info
, sec
, relocs
)
1366 struct bfd_link_info
*info
;
1368 const Elf_Internal_Rela
*relocs
;
1370 struct sparc64_elf_link_hash_table
*htab
;
1371 Elf_Internal_Shdr
*symtab_hdr
;
1372 struct elf_link_hash_entry
**sym_hashes
;
1373 bfd_vma
*local_got_offsets
;
1374 const Elf_Internal_Rela
*rel
;
1375 const Elf_Internal_Rela
*rel_end
;
1378 if (info
->relocatable
|| !(sec
->flags
& SEC_ALLOC
))
1381 htab
= sparc64_elf_hash_table (info
);
1382 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1383 sym_hashes
= elf_sym_hashes (abfd
);
1384 local_got_offsets
= elf_local_got_offsets (abfd
);
1388 rel_end
= relocs
+ NUM_SHDR_ENTRIES (& elf_section_data (sec
)->rel_hdr
);
1389 for (rel
= relocs
; rel
< rel_end
; rel
++)
1391 unsigned int r_type
;
1392 unsigned long r_symndx
;
1393 struct elf_link_hash_entry
*h
;
1395 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1396 r_type
= ELF64_R_TYPE_ID (rel
->r_info
);
1398 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1400 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
1405 if (r_symndx
< symtab_hdr
->sh_info
)
1408 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1410 r_type
= sparc64_elf_tls_transition (info
, r_type
, h
== NULL
);
1413 case R_SPARC_TLS_LDM_HI22
:
1414 case R_SPARC_TLS_LDM_LO10
:
1415 htab
->tls_ldm_got
.refcount
+= 1;
1418 case R_SPARC_TLS_LE_HIX22
:
1419 case R_SPARC_TLS_LE_LOX10
:
1424 case R_SPARC_TLS_IE_HI22
:
1425 case R_SPARC_TLS_IE_LO10
:
1427 info
->flags
|= DF_STATIC_TLS
;
1433 case R_SPARC_TLS_GD_HI22
:
1434 case R_SPARC_TLS_GD_LO10
:
1435 /* This symbol requires a global offset table entry. */
1437 int tls_type
, old_tls_type
;
1445 tls_type
= GOT_NORMAL
;
1447 case R_SPARC_TLS_GD_HI22
:
1448 case R_SPARC_TLS_GD_LO10
:
1449 tls_type
= GOT_TLS_GD
;
1451 case R_SPARC_TLS_IE_HI22
:
1452 case R_SPARC_TLS_IE_LO10
:
1453 tls_type
= GOT_TLS_IE
;
1459 h
->got
.refcount
+= 1;
1460 old_tls_type
= sparc64_elf_hash_entry(h
)->tls_type
;
1464 bfd_signed_vma
*local_got_refcounts
;
1466 /* This is a global offset table entry for a local symbol. */
1467 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1468 if (local_got_refcounts
== NULL
)
1472 size
= symtab_hdr
->sh_info
;
1473 size
*= (sizeof (bfd_signed_vma
) + sizeof(char));
1474 local_got_refcounts
= ((bfd_signed_vma
*)
1475 bfd_zalloc (abfd
, size
));
1476 if (local_got_refcounts
== NULL
)
1478 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1479 sparc64_elf_local_got_tls_type (abfd
)
1480 = (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1482 local_got_refcounts
[r_symndx
] += 1;
1483 old_tls_type
= sparc64_elf_local_got_tls_type (abfd
) [r_symndx
];
1486 /* If a TLS symbol is accessed using IE at least once,
1487 there is no point to use dynamic model for it. */
1488 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1489 && (old_tls_type
!= GOT_TLS_GD
1490 || tls_type
!= GOT_TLS_IE
))
1492 if (old_tls_type
== GOT_TLS_IE
&& tls_type
== GOT_TLS_GD
)
1493 tls_type
= old_tls_type
;
1496 (*_bfd_error_handler
)
1497 (_("%B: `%s' accessed both as normal and thread local symbol"),
1498 abfd
, h
? h
->root
.root
.string
: "<local>");
1503 if (old_tls_type
!= tls_type
)
1506 sparc64_elf_hash_entry (h
)->tls_type
= tls_type
;
1508 sparc64_elf_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1512 if (htab
->sgot
== NULL
)
1514 if (htab
->elf
.dynobj
== NULL
)
1515 htab
->elf
.dynobj
= abfd
;
1516 if (!create_got_section (htab
->elf
.dynobj
, info
))
1521 case R_SPARC_TLS_GD_CALL
:
1522 case R_SPARC_TLS_LDM_CALL
:
1525 /* These are basically R_SPARC_TLS_WPLT30 relocs against
1527 struct bfd_link_hash_entry
*bh
= NULL
;
1528 if (! _bfd_generic_link_add_one_symbol (info
, abfd
,
1529 "__tls_get_addr", 0,
1530 bfd_und_section_ptr
, 0,
1534 h
= (struct elf_link_hash_entry
*) bh
;
1541 case R_SPARC_WPLT30
:
1542 case R_SPARC_HIPLT22
:
1543 case R_SPARC_LOPLT10
:
1544 case R_SPARC_PCPLT32
:
1545 case R_SPARC_PCPLT22
:
1546 case R_SPARC_PCPLT10
:
1548 /* This symbol requires a procedure linkage table entry. We
1549 actually build the entry in adjust_dynamic_symbol,
1550 because this might be a case of linking PIC code without
1551 linking in any dynamic objects, in which case we don't
1552 need to generate a procedure linkage table after all. */
1556 /* It does not make sense to have a procedure linkage
1557 table entry for a local symbol. */
1558 bfd_set_error (bfd_error_bad_value
);
1564 if (ELF64_R_TYPE_ID (rel
->r_info
) == R_SPARC_PLT32
1565 || ELF64_R_TYPE_ID (rel
->r_info
) == R_SPARC_PLT64
)
1567 h
->plt
.refcount
+= 1;
1572 case R_SPARC_PC_HH22
:
1573 case R_SPARC_PC_HM10
:
1574 case R_SPARC_PC_LM22
:
1579 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
1584 case R_SPARC_DISP16
:
1585 case R_SPARC_DISP32
:
1586 case R_SPARC_DISP64
:
1587 case R_SPARC_WDISP30
:
1588 case R_SPARC_WDISP22
:
1589 case R_SPARC_WDISP19
:
1590 case R_SPARC_WDISP16
:
1620 if (h
!= NULL
&& !info
->shared
)
1622 /* We may need a .plt entry if the function this reloc
1623 refers to is in a shared lib. */
1624 h
->plt
.refcount
+= 1;
1627 /* If we are creating a shared library, and this is a reloc
1628 against a global symbol, or a non PC relative reloc
1629 against a local symbol, then we need to copy the reloc
1630 into the shared library. However, if we are linking with
1631 -Bsymbolic, we do not need to copy a reloc against a
1632 global symbol which is defined in an object we are
1633 including in the link (i.e., DEF_REGULAR is set). At
1634 this point we have not seen all the input files, so it is
1635 possible that DEF_REGULAR is not set now but will be set
1636 later (it is never cleared). In case of a weak definition,
1637 DEF_REGULAR may be cleared later by a strong definition in
1638 a shared library. We account for that possibility below by
1639 storing information in the relocs_copied field of the hash
1640 table entry. A similar situation occurs when creating
1641 shared libraries and symbol visibility changes render the
1644 If on the other hand, we are creating an executable, we
1645 may need to keep relocations for symbols satisfied by a
1646 dynamic library if we manage to avoid copy relocs for the
1649 && (sec
->flags
& SEC_ALLOC
) != 0
1650 && (! sparc64_elf_howto_table
[r_type
].pc_relative
1652 && (! info
->symbolic
1653 || h
->root
.type
== bfd_link_hash_defweak
1654 || !h
->def_regular
))))
1656 && (sec
->flags
& SEC_ALLOC
) != 0
1658 && (h
->root
.type
== bfd_link_hash_defweak
1659 || !h
->def_regular
)))
1661 struct sparc64_elf_dyn_relocs
*p
;
1662 struct sparc64_elf_dyn_relocs
**head
;
1664 /* When creating a shared object, we must copy these
1665 relocs into the output file. We create a reloc
1666 section in dynobj and make room for the reloc. */
1672 name
= (bfd_elf_string_from_elf_section
1674 elf_elfheader (abfd
)->e_shstrndx
,
1675 elf_section_data (sec
)->rel_hdr
.sh_name
));
1679 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
1680 && strcmp (bfd_get_section_name (abfd
, sec
),
1683 if (htab
->elf
.dynobj
== NULL
)
1684 htab
->elf
.dynobj
= abfd
;
1685 dynobj
= htab
->elf
.dynobj
;
1687 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1692 sreloc
= bfd_make_section (dynobj
, name
);
1693 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
1694 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1695 if ((sec
->flags
& SEC_ALLOC
) != 0)
1696 flags
|= SEC_ALLOC
| SEC_LOAD
;
1698 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
1699 || ! bfd_set_section_alignment (dynobj
, sreloc
, 3))
1702 elf_section_data (sec
)->sreloc
= sreloc
;
1705 /* If this is a global symbol, we count the number of
1706 relocations we need for this symbol. */
1708 head
= &((struct sparc64_elf_link_hash_entry
*) h
)->dyn_relocs
;
1711 /* Track dynamic relocs needed for local syms too.
1712 We really need local syms available to do this
1716 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
1721 head
= ((struct sparc64_elf_dyn_relocs
**)
1722 &elf_section_data (s
)->local_dynrel
);
1726 if (p
== NULL
|| p
->sec
!= sec
)
1728 bfd_size_type amt
= sizeof *p
;
1729 p
= ((struct sparc64_elf_dyn_relocs
*)
1730 bfd_alloc (htab
->elf
.dynobj
, amt
));
1741 if (sparc64_elf_howto_table
[r_type
].pc_relative
)
1747 case R_SPARC_REGISTER
:
1748 /* Nothing to do. */
1759 /* Hook called by the linker routine which adds symbols from an object
1760 file. We use it for STT_REGISTER symbols. */
1763 sparc64_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
1765 struct bfd_link_info
*info
;
1766 Elf_Internal_Sym
*sym
;
1768 flagword
*flagsp ATTRIBUTE_UNUSED
;
1769 asection
**secp ATTRIBUTE_UNUSED
;
1770 bfd_vma
*valp ATTRIBUTE_UNUSED
;
1772 static const char *const stt_types
[] = { "NOTYPE", "OBJECT", "FUNCTION" };
1774 if (ELF_ST_TYPE (sym
->st_info
) == STT_REGISTER
)
1777 struct sparc64_elf_app_reg
*p
;
1779 reg
= (int)sym
->st_value
;
1782 case 2: reg
-= 2; break;
1783 case 6: reg
-= 4; break;
1785 (*_bfd_error_handler
)
1786 (_("%B: Only registers %%g[2367] can be declared using STT_REGISTER"),
1791 if (info
->hash
->creator
!= abfd
->xvec
1792 || (abfd
->flags
& DYNAMIC
) != 0)
1794 /* STT_REGISTER only works when linking an elf64_sparc object.
1795 If STT_REGISTER comes from a dynamic object, don't put it into
1796 the output bfd. The dynamic linker will recheck it. */
1801 p
= sparc64_elf_hash_table(info
)->app_regs
+ reg
;
1803 if (p
->name
!= NULL
&& strcmp (p
->name
, *namep
))
1805 (*_bfd_error_handler
)
1806 (_("Register %%g%d used incompatibly: %s in %B, previously %s in %B"),
1807 abfd
, p
->abfd
, (int) sym
->st_value
,
1808 **namep
? *namep
: "#scratch",
1809 *p
->name
? p
->name
: "#scratch");
1813 if (p
->name
== NULL
)
1817 struct elf_link_hash_entry
*h
;
1819 h
= (struct elf_link_hash_entry
*)
1820 bfd_link_hash_lookup (info
->hash
, *namep
, FALSE
, FALSE
, FALSE
);
1824 unsigned char type
= h
->type
;
1826 if (type
> STT_FUNC
)
1828 (*_bfd_error_handler
)
1829 (_("Symbol `%s' has differing types: REGISTER in %B, previously %s in %B"),
1830 abfd
, p
->abfd
, *namep
, stt_types
[type
]);
1834 p
->name
= bfd_hash_allocate (&info
->hash
->table
,
1835 strlen (*namep
) + 1);
1839 strcpy (p
->name
, *namep
);
1843 p
->bind
= ELF_ST_BIND (sym
->st_info
);
1845 p
->shndx
= sym
->st_shndx
;
1849 if (p
->bind
== STB_WEAK
1850 && ELF_ST_BIND (sym
->st_info
) == STB_GLOBAL
)
1852 p
->bind
= STB_GLOBAL
;
1859 else if (*namep
&& **namep
1860 && info
->hash
->creator
== abfd
->xvec
)
1863 struct sparc64_elf_app_reg
*p
;
1865 p
= sparc64_elf_hash_table(info
)->app_regs
;
1866 for (i
= 0; i
< 4; i
++, p
++)
1867 if (p
->name
!= NULL
&& ! strcmp (p
->name
, *namep
))
1869 unsigned char type
= ELF_ST_TYPE (sym
->st_info
);
1871 if (type
> STT_FUNC
)
1873 (*_bfd_error_handler
)
1874 (_("Symbol `%s' has differing types: %s in %B, previously REGISTER in %B"),
1875 abfd
, p
->abfd
, *namep
, stt_types
[type
]);
1882 /* This function takes care of emitting STT_REGISTER symbols
1883 which we cannot easily keep in the symbol hash table. */
1886 sparc64_elf_output_arch_syms (output_bfd
, info
, finfo
, func
)
1887 bfd
*output_bfd ATTRIBUTE_UNUSED
;
1888 struct bfd_link_info
*info
;
1891 PARAMS ((PTR
, const char *, Elf_Internal_Sym
*, asection
*,
1892 struct elf_link_hash_entry
*));
1895 struct sparc64_elf_app_reg
*app_regs
=
1896 sparc64_elf_hash_table(info
)->app_regs
;
1897 Elf_Internal_Sym sym
;
1899 /* We arranged in size_dynamic_sections to put the STT_REGISTER entries
1900 at the end of the dynlocal list, so they came at the end of the local
1901 symbols in the symtab. Except that they aren't STB_LOCAL, so we need
1902 to back up symtab->sh_info. */
1903 if (elf_hash_table (info
)->dynlocal
)
1905 bfd
* dynobj
= elf_hash_table (info
)->dynobj
;
1906 asection
*dynsymsec
= bfd_get_section_by_name (dynobj
, ".dynsym");
1907 struct elf_link_local_dynamic_entry
*e
;
1909 for (e
= elf_hash_table (info
)->dynlocal
; e
; e
= e
->next
)
1910 if (e
->input_indx
== -1)
1914 elf_section_data (dynsymsec
->output_section
)->this_hdr
.sh_info
1919 if (info
->strip
== strip_all
)
1922 for (reg
= 0; reg
< 4; reg
++)
1923 if (app_regs
[reg
].name
!= NULL
)
1925 if (info
->strip
== strip_some
1926 && bfd_hash_lookup (info
->keep_hash
,
1927 app_regs
[reg
].name
,
1928 FALSE
, FALSE
) == NULL
)
1931 sym
.st_value
= reg
< 2 ? reg
+ 2 : reg
+ 4;
1934 sym
.st_info
= ELF_ST_INFO (app_regs
[reg
].bind
, STT_REGISTER
);
1935 sym
.st_shndx
= app_regs
[reg
].shndx
;
1936 if (! (*func
) (finfo
, app_regs
[reg
].name
, &sym
,
1937 sym
.st_shndx
== SHN_ABS
1938 ? bfd_abs_section_ptr
: bfd_und_section_ptr
,
1947 sparc64_elf_get_symbol_type (elf_sym
, type
)
1948 Elf_Internal_Sym
* elf_sym
;
1951 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_REGISTER
)
1952 return STT_REGISTER
;
1957 /* A STB_GLOBAL,STT_REGISTER symbol should be BSF_GLOBAL
1958 even in SHN_UNDEF section. */
1961 sparc64_elf_symbol_processing (abfd
, asym
)
1962 bfd
*abfd ATTRIBUTE_UNUSED
;
1965 elf_symbol_type
*elfsym
;
1967 elfsym
= (elf_symbol_type
*) asym
;
1968 if (elfsym
->internal_elf_sym
.st_info
1969 == ELF_ST_INFO (STB_GLOBAL
, STT_REGISTER
))
1971 asym
->flags
|= BSF_GLOBAL
;
1976 sparc64_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
)
1978 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1979 Elf_Internal_Rela
*rel ATTRIBUTE_UNUSED
;
1980 struct elf_link_hash_entry
*h
;
1981 Elf_Internal_Sym
*sym
;
1985 switch (h
->root
.type
)
1987 case bfd_link_hash_defined
:
1988 case bfd_link_hash_defweak
:
1989 return h
->root
.u
.def
.section
;
1991 case bfd_link_hash_common
:
1992 return h
->root
.u
.c
.p
->section
;
1999 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
2004 /* Update the got entry reference counts for the section being removed. */
2006 sparc64_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
2008 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2010 const Elf_Internal_Rela
*relocs
;
2012 Elf_Internal_Shdr
*symtab_hdr
;
2013 struct elf_link_hash_entry
**sym_hashes
;
2014 bfd_signed_vma
*local_got_refcounts
;
2015 const Elf_Internal_Rela
*rel
, *relend
;
2017 elf_section_data (sec
)->local_dynrel
= NULL
;
2019 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2020 sym_hashes
= elf_sym_hashes (abfd
);
2021 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2023 relend
= relocs
+ sec
->reloc_count
;
2024 for (rel
= relocs
; rel
< relend
; rel
++)
2026 unsigned long r_symndx
;
2027 unsigned int r_type
;
2028 struct elf_link_hash_entry
*h
= NULL
;
2030 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2031 if (r_symndx
>= symtab_hdr
->sh_info
)
2033 struct sparc64_elf_link_hash_entry
*eh
;
2034 struct sparc64_elf_dyn_relocs
**pp
;
2035 struct sparc64_elf_dyn_relocs
*p
;
2037 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2038 while (h
->root
.type
== bfd_link_hash_indirect
2039 || h
->root
.type
== bfd_link_hash_warning
)
2040 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2041 eh
= (struct sparc64_elf_link_hash_entry
*) h
;
2042 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
2045 /* Everything must go for SEC. */
2051 r_type
= ELF64_R_TYPE_ID (rel
->r_info
);
2052 r_type
= sparc64_elf_tls_transition (info
, r_type
, h
!= NULL
);
2055 case R_SPARC_TLS_LDM_HI22
:
2056 case R_SPARC_TLS_LDM_LO10
:
2057 if (sparc64_elf_hash_table (info
)->tls_ldm_got
.refcount
> 0)
2058 sparc64_elf_hash_table (info
)->tls_ldm_got
.refcount
-= 1;
2061 case R_SPARC_TLS_GD_HI22
:
2062 case R_SPARC_TLS_GD_LO10
:
2063 case R_SPARC_TLS_IE_HI22
:
2064 case R_SPARC_TLS_IE_LO10
:
2070 if (h
->got
.refcount
> 0)
2075 if (local_got_refcounts
[r_symndx
] > 0)
2076 local_got_refcounts
[r_symndx
]--;
2082 case R_SPARC_PC_HH22
:
2083 case R_SPARC_PC_HM10
:
2084 case R_SPARC_PC_LM22
:
2086 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2091 case R_SPARC_DISP16
:
2092 case R_SPARC_DISP32
:
2093 case R_SPARC_DISP64
:
2094 case R_SPARC_WDISP30
:
2095 case R_SPARC_WDISP22
:
2096 case R_SPARC_WDISP19
:
2097 case R_SPARC_WDISP16
:
2128 case R_SPARC_WPLT30
:
2131 if (h
->plt
.refcount
> 0)
2144 /* Adjust a symbol defined by a dynamic object and referenced by a
2145 regular object. The current definition is in some section of the
2146 dynamic object, but we're not including those sections. We have to
2147 change the definition to something the rest of the link can
2151 sparc64_elf_adjust_dynamic_symbol (info
, h
)
2152 struct bfd_link_info
*info
;
2153 struct elf_link_hash_entry
*h
;
2155 struct sparc64_elf_link_hash_table
*htab
;
2156 struct sparc64_elf_link_hash_entry
* eh
;
2157 struct sparc64_elf_dyn_relocs
*p
;
2159 unsigned int power_of_two
;
2161 htab
= sparc64_elf_hash_table (info
);
2163 /* Make sure we know what is going on here. */
2164 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
2166 || h
->u
.weakdef
!= NULL
2169 && !h
->def_regular
)));
2171 /* If this is a function, put it in the procedure linkage table. We
2172 will fill in the contents of the procedure linkage table later
2173 (although we could actually do it here). The STT_NOTYPE
2174 condition is a hack specifically for the Oracle libraries
2175 delivered for Solaris; for some inexplicable reason, they define
2176 some of their functions as STT_NOTYPE when they really should be
2178 if (h
->type
== STT_FUNC
2180 || (h
->type
== STT_NOTYPE
2181 && (h
->root
.type
== bfd_link_hash_defined
2182 || h
->root
.type
== bfd_link_hash_defweak
)
2183 && (h
->root
.u
.def
.section
->flags
& SEC_CODE
) != 0))
2185 if (h
->plt
.refcount
<= 0
2189 && h
->root
.type
!= bfd_link_hash_undefweak
2190 && h
->root
.type
!= bfd_link_hash_undefined
))
2192 /* This case can occur if we saw a WPLT30 reloc in an input
2193 file, but the symbol was never referred to by a dynamic
2194 object, or if all references were garbage collected. In
2195 such a case, we don't actually need to build a procedure
2196 linkage table, and we can just do a WDISP30 reloc instead. */
2197 h
->plt
.offset
= (bfd_vma
) -1;
2204 h
->plt
.offset
= (bfd_vma
) -1;
2206 /* If this is a weak symbol, and there is a real definition, the
2207 processor independent code will have arranged for us to see the
2208 real definition first, and we can just use the same value. */
2209 if (h
->u
.weakdef
!= NULL
)
2211 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2212 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2213 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2214 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2218 /* This is a reference to a symbol defined by a dynamic object which
2219 is not a function. */
2221 /* If we are creating a shared library, we must presume that the
2222 only references to the symbol are via the global offset table.
2223 For such cases we need not do anything here; the relocations will
2224 be handled correctly by relocate_section. */
2228 /* If there are no references to this symbol that do not use the
2229 GOT, we don't need to generate a copy reloc. */
2230 if (!h
->non_got_ref
)
2233 eh
= (struct sparc64_elf_link_hash_entry
*) h
;
2234 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2236 s
= p
->sec
->output_section
;
2237 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2241 /* If we didn't find any dynamic relocs in read-only sections, then
2242 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2249 /* We must allocate the symbol in our .dynbss section, which will
2250 become part of the .bss section of the executable. There will be
2251 an entry for this symbol in the .dynsym section. The dynamic
2252 object will contain position independent code, so all references
2253 from the dynamic object to this symbol will go through the global
2254 offset table. The dynamic linker will use the .dynsym entry to
2255 determine the address it must put in the global offset table, so
2256 both the dynamic object and the regular object will refer to the
2257 same memory location for the variable. */
2259 /* We must generate a R_SPARC_COPY reloc to tell the dynamic linker
2260 to copy the initial value out of the dynamic object and into the
2261 runtime process image. We need to remember the offset into the
2262 .rel.bss section we are going to use. */
2263 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2265 htab
->srelbss
->size
+= sizeof (Elf64_External_Rela
);
2269 /* We need to figure out the alignment required for this symbol. I
2270 have no idea how ELF linkers handle this. 16-bytes is the size
2271 of the largest type that requires hard alignment -- long double. */
2272 power_of_two
= bfd_log2 (h
->size
);
2273 if (power_of_two
> 4)
2276 /* Apply the required alignment. */
2278 s
->size
= BFD_ALIGN (s
->size
, (bfd_size_type
) (1 << power_of_two
));
2279 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
2281 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
2285 /* Define the symbol as being at this point in the section. */
2286 h
->root
.u
.def
.section
= s
;
2287 h
->root
.u
.def
.value
= s
->size
;
2289 /* Increment the section size to make room for the symbol. */
2295 /* Allocate space in .plt, .got and associated reloc sections for
2299 allocate_dynrelocs (h
, inf
)
2300 struct elf_link_hash_entry
*h
;
2303 struct bfd_link_info
*info
;
2304 struct sparc64_elf_link_hash_table
*htab
;
2305 struct sparc64_elf_link_hash_entry
*eh
;
2306 struct sparc64_elf_dyn_relocs
*p
;
2308 if (h
->root
.type
== bfd_link_hash_indirect
)
2311 if (h
->root
.type
== bfd_link_hash_warning
)
2312 /* When warning symbols are created, they **replace** the "real"
2313 entry in the hash table, thus we never get to see the real
2314 symbol in a hash traversal. So look at it now. */
2315 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2317 info
= (struct bfd_link_info
*) inf
;
2318 htab
= sparc64_elf_hash_table (info
);
2320 if (htab
->elf
.dynamic_sections_created
2321 && h
->plt
.refcount
> 0)
2323 /* Make sure this symbol is output as a dynamic symbol.
2324 Undefined weak syms won't yet be marked as dynamic. */
2325 if (h
->dynindx
== -1
2326 && !h
->forced_local
)
2328 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2332 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
->shared
, h
))
2334 asection
*s
= htab
->splt
;
2336 /* The first four bit in .plt is reserved. */
2338 s
->size
= PLT_HEADER_SIZE
;
2340 /* The procedure linkage table size is bounded by the magnitude
2341 of the offset we can describe in the entry. */
2342 if (s
->size
>= (bfd_vma
)1 << 32)
2344 bfd_set_error (bfd_error_bad_value
);
2348 if (s
->size
>= LARGE_PLT_THRESHOLD
* PLT_ENTRY_SIZE
)
2350 bfd_vma off
= s
->size
- LARGE_PLT_THRESHOLD
* PLT_ENTRY_SIZE
;
2353 off
= (off
% (160 * PLT_ENTRY_SIZE
)) / PLT_ENTRY_SIZE
;
2355 h
->plt
.offset
= (s
->size
- (off
* 8));
2358 h
->plt
.offset
= s
->size
;
2360 /* If this symbol is not defined in a regular file, and we are
2361 not generating a shared library, then set the symbol to this
2362 location in the .plt. This is required to make function
2363 pointers compare as equal between the normal executable and
2364 the shared library. */
2368 h
->root
.u
.def
.section
= s
;
2369 h
->root
.u
.def
.value
= h
->plt
.offset
;
2372 /* Make room for this entry. */
2373 s
->size
+= PLT_ENTRY_SIZE
;
2375 /* We also need to make an entry in the .rela.plt section. */
2376 htab
->srelplt
->size
+= sizeof (Elf64_External_Rela
);
2380 h
->plt
.offset
= (bfd_vma
) -1;
2386 h
->plt
.offset
= (bfd_vma
) -1;
2390 /* If R_SPARC_TLS_IE_{HI22,LO10} symbol is now local to the binary,
2391 make it a R_SPARC_TLS_LE_{HI22,LO10} requiring no TLS entry. */
2392 if (h
->got
.refcount
> 0
2395 && sparc64_elf_hash_entry(h
)->tls_type
== GOT_TLS_IE
)
2396 h
->got
.offset
= (bfd_vma
) -1;
2397 else if (h
->got
.refcount
> 0)
2401 int tls_type
= sparc64_elf_hash_entry(h
)->tls_type
;
2403 /* Make sure this symbol is output as a dynamic symbol.
2404 Undefined weak syms won't yet be marked as dynamic. */
2405 if (h
->dynindx
== -1
2406 && !h
->forced_local
)
2408 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2413 h
->got
.offset
= s
->size
;
2415 /* R_SPARC_TLS_GD_HI{22,LO10} needs 2 consecutive GOT slots. */
2416 if (tls_type
== GOT_TLS_GD
)
2418 dyn
= htab
->elf
.dynamic_sections_created
;
2419 /* R_SPARC_TLS_IE_{HI22,LO10} needs one dynamic relocation,
2420 R_SPARC_TLS_GD_{HI22,LO10} needs one if local symbol and two if
2422 if ((tls_type
== GOT_TLS_GD
&& h
->dynindx
== -1)
2423 || tls_type
== GOT_TLS_IE
)
2424 htab
->srelgot
->size
+= sizeof (Elf64_External_Rela
);
2425 else if (tls_type
== GOT_TLS_GD
)
2426 htab
->srelgot
->size
+= 2 * sizeof (Elf64_External_Rela
);
2427 else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
))
2428 htab
->srelgot
->size
+= sizeof (Elf64_External_Rela
);
2431 h
->got
.offset
= (bfd_vma
) -1;
2433 eh
= (struct sparc64_elf_link_hash_entry
*) h
;
2434 if (eh
->dyn_relocs
== NULL
)
2437 /* In the shared -Bsymbolic case, discard space allocated for
2438 dynamic pc-relative relocs against symbols which turn out to be
2439 defined in regular objects. For the normal shared case, discard
2440 space for pc-relative relocs that have become local due to symbol
2441 visibility changes. */
2449 struct sparc64_elf_dyn_relocs
**pp
;
2451 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2453 p
->count
-= p
->pc_count
;
2464 /* For the non-shared case, discard space for relocs against
2465 symbols which turn out to need copy relocs or are not
2471 || (htab
->elf
.dynamic_sections_created
2472 && (h
->root
.type
== bfd_link_hash_undefweak
2473 || h
->root
.type
== bfd_link_hash_undefined
))))
2475 /* Make sure this symbol is output as a dynamic symbol.
2476 Undefined weak syms won't yet be marked as dynamic. */
2477 if (h
->dynindx
== -1
2478 && !h
->forced_local
)
2480 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2484 /* If that succeeded, we know we'll be keeping all the
2486 if (h
->dynindx
!= -1)
2490 eh
->dyn_relocs
= NULL
;
2495 /* Finally, allocate space. */
2496 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2498 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
2499 sreloc
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
2505 /* Find any dynamic relocs that apply to read-only sections. */
2508 readonly_dynrelocs (h
, inf
)
2509 struct elf_link_hash_entry
*h
;
2512 struct sparc64_elf_link_hash_entry
*eh
;
2513 struct sparc64_elf_dyn_relocs
*p
;
2515 if (h
->root
.type
== bfd_link_hash_warning
)
2516 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2518 eh
= (struct sparc64_elf_link_hash_entry
*) h
;
2519 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2521 asection
*s
= p
->sec
->output_section
;
2523 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2525 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2527 info
->flags
|= DF_TEXTREL
;
2529 /* Not an error, just cut short the traversal. */
2536 /* Return true if the dynamic symbol for a given section should be
2537 omitted when creating a shared library. */
2540 sparc64_elf_omit_section_dynsym (bfd
*output_bfd
,
2541 struct bfd_link_info
*info
,
2544 /* We keep the .got section symbol so that explicit relocations
2545 against the _GLOBAL_OFFSET_TABLE_ symbol emitted in PIC mode
2546 can be turned into relocations against the .got symbol. */
2547 if (strcmp (p
->name
, ".got") == 0)
2550 return _bfd_elf_link_omit_section_dynsym (output_bfd
, info
, p
);
2553 /* Set the sizes of the dynamic sections. */
2556 sparc64_elf_size_dynamic_sections (output_bfd
, info
)
2558 struct bfd_link_info
*info
;
2560 struct sparc64_elf_link_hash_table
*htab
;
2565 htab
= sparc64_elf_hash_table (info
);
2566 dynobj
= htab
->elf
.dynobj
;
2567 BFD_ASSERT (dynobj
!= NULL
);
2569 if (elf_hash_table (info
)->dynamic_sections_created
)
2571 /* Set the contents of the .interp section to the interpreter. */
2572 if (info
->executable
)
2574 s
= bfd_get_section_by_name (dynobj
, ".interp");
2575 BFD_ASSERT (s
!= NULL
);
2576 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2577 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2581 /* Set up .got offsets for local syms, and space for local dynamic
2583 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2585 bfd_signed_vma
*local_got
;
2586 bfd_signed_vma
*end_local_got
;
2587 char *local_tls_type
;
2588 bfd_size_type locsymcount
;
2589 Elf_Internal_Shdr
*symtab_hdr
;
2592 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
2595 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2597 struct sparc64_elf_dyn_relocs
*p
;
2599 for (p
= *((struct sparc64_elf_dyn_relocs
**)
2600 &elf_section_data (s
)->local_dynrel
);
2604 if (!bfd_is_abs_section (p
->sec
)
2605 && bfd_is_abs_section (p
->sec
->output_section
))
2607 /* Input section has been discarded, either because
2608 it is a copy of a linkonce section or due to
2609 linker script /DISCARD/, so we'll be discarding
2612 else if (p
->count
!= 0)
2614 srel
= elf_section_data (p
->sec
)->sreloc
;
2615 srel
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
2616 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
2617 info
->flags
|= DF_TEXTREL
;
2622 local_got
= elf_local_got_refcounts (ibfd
);
2626 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
2627 locsymcount
= symtab_hdr
->sh_info
;
2628 end_local_got
= local_got
+ locsymcount
;
2629 local_tls_type
= sparc64_elf_local_got_tls_type (ibfd
);
2631 srel
= htab
->srelgot
;
2632 for (; local_got
< end_local_got
; ++local_got
, ++local_tls_type
)
2636 *local_got
= s
->size
;
2638 if (*local_tls_type
== GOT_TLS_GD
)
2641 || *local_tls_type
== GOT_TLS_GD
2642 || *local_tls_type
== GOT_TLS_IE
)
2643 srel
->size
+= sizeof (Elf64_External_Rela
);
2646 *local_got
= (bfd_vma
) -1;
2650 if (htab
->tls_ldm_got
.refcount
> 0)
2652 /* Allocate 2 got entries and 1 dynamic reloc for
2653 R_SPARC_TLS_LDM_{HI22,LO10} relocs. */
2654 htab
->tls_ldm_got
.offset
= htab
->sgot
->size
;
2655 htab
->sgot
->size
+= (2 * 8);
2656 htab
->srelgot
->size
+= sizeof (Elf64_External_Rela
);
2659 htab
->tls_ldm_got
.offset
= -1;
2661 /* Allocate global sym .plt and .got entries, and space for global
2662 sym dynamic relocs. */
2663 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, (PTR
) info
);
2665 /* The 32-bit sparc BFD backend has a hack that, iff the .got
2666 section is larger than 0x1000 bytes, it increments the
2667 .got base by 0x1000 so that 13 bit relocations are more
2670 On 64-bit we have to be more careful, since sethi+or will
2671 not create a proper 64-bit sign extended negative value
2672 for relocations to the first 0x1000 bytes of the .got area.
2673 We could do this using sethi+xor tricks just like the
2674 sparc backend of GCC does, in order to make this work at
2675 some point. Just... not today. */
2677 /* The check_relocs and adjust_dynamic_symbol entry points have
2678 determined the sizes of the various dynamic sections. Allocate
2680 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2683 bfd_boolean strip
= FALSE
;
2685 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2688 /* It's OK to base decisions on the section name, because none
2689 of the dynobj section names depend upon the input files. */
2690 name
= bfd_get_section_name (dynobj
, s
);
2692 if (strncmp (name
, ".rela", 5) == 0)
2696 /* If we don't need this section, strip it from the
2697 output file. This is to handle .rela.bss and
2698 .rel.plt. We must create it in
2699 create_dynamic_sections, because it must be created
2700 before the linker maps input sections to output
2701 sections. The linker does that before
2702 adjust_dynamic_symbol is called, and it is that
2703 function which decides whether anything needs to go
2704 into these sections. */
2709 /* We use the reloc_count field as a counter if we need
2710 to copy relocs into the output file. */
2714 else if (s
!= htab
->splt
&& s
!= htab
->sgot
)
2716 /* It's not one of our sections, so don't allocate space. */
2722 _bfd_strip_section_from_output (info
, s
);
2726 /* Allocate memory for the section contents. Zero the memory
2727 for the benefit of .rela.plt, which has 4 unused entries
2728 at the beginning, and we don't want garbage. */
2729 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
2730 if (s
->contents
== NULL
&& s
->size
!= 0)
2734 if (elf_hash_table (info
)->dynamic_sections_created
)
2736 /* Add some entries to the .dynamic section. We fill in the
2737 values later, in sparc64_elf_finish_dynamic_sections, but we
2738 must add the entries now so that we get the correct size for
2739 the .dynamic section. The DT_DEBUG entry is filled in by the
2740 dynamic linker and used by the debugger. */
2741 #define add_dynamic_entry(TAG, VAL) \
2742 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2745 struct sparc64_elf_app_reg
* app_regs
;
2746 struct elf_strtab_hash
*dynstr
;
2747 struct elf_link_hash_table
*eht
= elf_hash_table (info
);
2749 if (info
->executable
)
2751 if (!add_dynamic_entry (DT_DEBUG
, 0))
2755 if (htab
->srelplt
->size
!= 0)
2757 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2758 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2759 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2760 || !add_dynamic_entry (DT_JMPREL
, 0))
2764 if (!add_dynamic_entry (DT_RELA
, 0)
2765 || !add_dynamic_entry (DT_RELASZ
, 0)
2766 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
2769 /* If any dynamic relocs apply to a read-only section,
2770 then we need a DT_TEXTREL entry. */
2771 if ((info
->flags
& DF_TEXTREL
) == 0)
2772 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
,
2775 if (info
->flags
& DF_TEXTREL
)
2777 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2781 /* Add dynamic STT_REGISTER symbols and corresponding DT_SPARC_REGISTER
2782 entries if needed. */
2783 app_regs
= sparc64_elf_hash_table (info
)->app_regs
;
2784 dynstr
= eht
->dynstr
;
2786 for (reg
= 0; reg
< 4; reg
++)
2787 if (app_regs
[reg
].name
!= NULL
)
2789 struct elf_link_local_dynamic_entry
*entry
, *e
;
2791 if (!add_dynamic_entry (DT_SPARC_REGISTER
, 0))
2794 entry
= (struct elf_link_local_dynamic_entry
*)
2795 bfd_hash_allocate (&info
->hash
->table
, sizeof (*entry
));
2799 /* We cheat here a little bit: the symbol will not be local, so we
2800 put it at the end of the dynlocal linked list. We will fix it
2801 later on, as we have to fix other fields anyway. */
2802 entry
->isym
.st_value
= reg
< 2 ? reg
+ 2 : reg
+ 4;
2803 entry
->isym
.st_size
= 0;
2804 if (*app_regs
[reg
].name
!= '\0')
2806 = _bfd_elf_strtab_add (dynstr
, app_regs
[reg
].name
, FALSE
);
2808 entry
->isym
.st_name
= 0;
2809 entry
->isym
.st_other
= 0;
2810 entry
->isym
.st_info
= ELF_ST_INFO (app_regs
[reg
].bind
,
2812 entry
->isym
.st_shndx
= app_regs
[reg
].shndx
;
2814 entry
->input_bfd
= output_bfd
;
2815 entry
->input_indx
= -1;
2817 if (eht
->dynlocal
== NULL
)
2818 eht
->dynlocal
= entry
;
2821 for (e
= eht
->dynlocal
; e
->next
; e
= e
->next
)
2828 #undef add_dynamic_entry
2834 sparc64_elf_new_section_hook (abfd
, sec
)
2838 struct sparc64_elf_section_data
*sdata
;
2839 bfd_size_type amt
= sizeof (*sdata
);
2841 sdata
= (struct sparc64_elf_section_data
*) bfd_zalloc (abfd
, amt
);
2844 sec
->used_by_bfd
= (PTR
) sdata
;
2846 return _bfd_elf_new_section_hook (abfd
, sec
);
2850 sparc64_elf_relax_section (abfd
, section
, link_info
, again
)
2851 bfd
*abfd ATTRIBUTE_UNUSED
;
2852 asection
*section ATTRIBUTE_UNUSED
;
2853 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
;
2857 sec_do_relax (section
) = 1;
2861 /* Return the base VMA address which should be subtracted from real addresses
2862 when resolving @dtpoff relocation.
2863 This is PT_TLS segment p_vaddr. */
2867 struct bfd_link_info
*info
;
2869 /* If tls_sec is NULL, we should have signalled an error already. */
2870 if (elf_hash_table (info
)->tls_sec
== NULL
)
2872 return elf_hash_table (info
)->tls_sec
->vma
;
2875 /* Return the relocation value for @tpoff relocation
2876 if STT_TLS virtual address is ADDRESS. */
2879 tpoff (info
, address
)
2880 struct bfd_link_info
*info
;
2883 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2885 /* If tls_sec is NULL, we should have signalled an error already. */
2886 if (htab
->tls_sec
== NULL
)
2888 return address
- htab
->tls_size
- htab
->tls_sec
->vma
;
2891 /* Relocate a SPARC64 ELF section. */
2894 sparc64_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2895 contents
, relocs
, local_syms
, local_sections
)
2897 struct bfd_link_info
*info
;
2899 asection
*input_section
;
2901 Elf_Internal_Rela
*relocs
;
2902 Elf_Internal_Sym
*local_syms
;
2903 asection
**local_sections
;
2905 struct sparc64_elf_link_hash_table
*htab
;
2906 Elf_Internal_Shdr
*symtab_hdr
;
2907 struct elf_link_hash_entry
**sym_hashes
;
2908 bfd_vma
*local_got_offsets
;
2911 Elf_Internal_Rela
*rel
;
2912 Elf_Internal_Rela
*relend
;
2914 if (info
->relocatable
)
2917 htab
= sparc64_elf_hash_table (info
);
2918 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2919 sym_hashes
= elf_sym_hashes (input_bfd
);
2920 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2922 if (elf_hash_table (info
)->hgot
== NULL
)
2925 got_base
= elf_hash_table (info
)->hgot
->root
.u
.def
.value
;
2927 sreloc
= elf_section_data (input_section
)->sreloc
;
2930 relend
= relocs
+ NUM_SHDR_ENTRIES (& elf_section_data (input_section
)->rel_hdr
);
2931 for (; rel
< relend
; rel
++)
2933 int r_type
, tls_type
;
2934 reloc_howto_type
*howto
;
2935 unsigned long r_symndx
;
2936 struct elf_link_hash_entry
*h
;
2937 Elf_Internal_Sym
*sym
;
2939 bfd_vma relocation
, off
;
2940 bfd_reloc_status_type r
;
2941 bfd_boolean is_plt
= FALSE
;
2942 bfd_boolean unresolved_reloc
;
2944 r_type
= ELF64_R_TYPE_ID (rel
->r_info
);
2945 if (r_type
< 0 || r_type
>= (int) R_SPARC_max_std
)
2947 bfd_set_error (bfd_error_bad_value
);
2950 howto
= sparc64_elf_howto_table
+ r_type
;
2952 /* This is a final link. */
2953 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2957 unresolved_reloc
= FALSE
;
2958 if (r_symndx
< symtab_hdr
->sh_info
)
2960 sym
= local_syms
+ r_symndx
;
2961 sec
= local_sections
[r_symndx
];
2962 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2968 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2969 r_symndx
, symtab_hdr
, sym_hashes
,
2971 unresolved_reloc
, warned
);
2974 /* To avoid generating warning messages about truncated
2975 relocations, set the relocation's address to be the same as
2976 the start of this section. */
2977 if (input_section
->output_section
!= NULL
)
2978 relocation
= input_section
->output_section
->vma
;
2989 /* Relocation is to the entry for this symbol in the global
2991 if (htab
->sgot
== NULL
)
2998 off
= h
->got
.offset
;
2999 BFD_ASSERT (off
!= (bfd_vma
) -1);
3000 dyn
= elf_hash_table (info
)->dynamic_sections_created
;
3002 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3009 /* This is actually a static link, or it is a
3010 -Bsymbolic link and the symbol is defined
3011 locally, or the symbol was forced to be local
3012 because of a version file. We must initialize
3013 this entry in the global offset table. Since the
3014 offset must always be a multiple of 8, we use the
3015 least significant bit to record whether we have
3016 initialized it already.
3018 When doing a dynamic link, we create a .rela.got
3019 relocation entry to initialize the value. This
3020 is done in the finish_dynamic_symbol routine. */
3025 bfd_put_64 (output_bfd
, relocation
,
3026 htab
->sgot
->contents
+ off
);
3031 unresolved_reloc
= FALSE
;
3035 BFD_ASSERT (local_got_offsets
!= NULL
3036 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
3038 off
= local_got_offsets
[r_symndx
];
3040 /* The offset must always be a multiple of 8. We use
3041 the least significant bit to record whether we have
3042 already processed this entry. */
3051 Elf_Internal_Rela outrel
;
3054 /* We need to generate a R_SPARC_RELATIVE reloc
3055 for the dynamic linker. */
3057 BFD_ASSERT (s
!= NULL
);
3059 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
3060 + htab
->sgot
->output_offset
3062 outrel
.r_info
= ELF64_R_INFO (0, R_SPARC_RELATIVE
);
3063 outrel
.r_addend
= relocation
;
3066 loc
+= s
->reloc_count
++ * sizeof (Elf64_External_Rela
);
3067 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
3070 bfd_put_64 (output_bfd
, relocation
,
3071 htab
->sgot
->contents
+ off
);
3072 local_got_offsets
[r_symndx
] |= 1;
3075 relocation
= htab
->sgot
->output_offset
+ off
- got_base
;
3080 if (h
== NULL
|| h
->plt
.offset
== (bfd_vma
) -1)
3082 r_type
= (r_type
== R_SPARC_PLT32
) ? R_SPARC_32
: R_SPARC_64
;
3087 case R_SPARC_WPLT30
:
3088 case R_SPARC_HIPLT22
:
3089 case R_SPARC_LOPLT10
:
3090 case R_SPARC_PCPLT32
:
3091 case R_SPARC_PCPLT22
:
3092 case R_SPARC_PCPLT10
:
3094 /* Relocation is to the entry for this symbol in the
3095 procedure linkage table. */
3097 /* Relocation is to the entry for this symbol in the
3098 procedure linkage table. */
3099 BFD_ASSERT (h
!= NULL
);
3101 if (h
->plt
.offset
== (bfd_vma
) -1 || htab
->splt
== NULL
)
3103 /* We didn't make a PLT entry for this symbol. This
3104 happens when statically linking PIC code, or when
3105 using -Bsymbolic. */
3109 relocation
= (htab
->splt
->output_section
->vma
3110 + htab
->splt
->output_offset
3112 unresolved_reloc
= FALSE
;
3113 if (r_type
== R_SPARC_PLT32
|| r_type
== R_SPARC_PLT64
)
3115 r_type
= r_type
== R_SPARC_PLT32
? R_SPARC_32
: R_SPARC_64
;
3123 case R_SPARC_PC_HH22
:
3124 case R_SPARC_PC_HM10
:
3125 case R_SPARC_PC_LM22
:
3127 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3131 case R_SPARC_DISP16
:
3132 case R_SPARC_DISP32
:
3133 case R_SPARC_DISP64
:
3134 case R_SPARC_WDISP30
:
3135 case R_SPARC_WDISP22
:
3136 case R_SPARC_WDISP19
:
3137 case R_SPARC_WDISP16
:
3164 /* r_symndx will be zero only for relocs against symbols
3165 from removed linkonce sections, or sections discarded by
3168 || (input_section
->flags
& SEC_ALLOC
) == 0)
3173 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3174 || h
->root
.type
!= bfd_link_hash_undefweak
)
3175 && (! howto
->pc_relative
3178 && (! info
->symbolic
3179 || !h
->def_regular
))))
3186 || h
->root
.type
== bfd_link_hash_undefweak
3187 || h
->root
.type
== bfd_link_hash_undefined
)))
3189 Elf_Internal_Rela outrel
;
3191 bfd_boolean skip
, relocate
= FALSE
;
3193 /* When generating a shared object, these relocations
3194 are copied into the output file to be resolved at run
3197 BFD_ASSERT (sreloc
!= NULL
);
3202 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3204 if (outrel
.r_offset
== (bfd_vma
) -1)
3206 else if (outrel
.r_offset
== (bfd_vma
) -2)
3207 skip
= TRUE
, relocate
= TRUE
;
3208 outrel
.r_offset
+= (input_section
->output_section
->vma
3209 + input_section
->output_offset
);
3211 /* Optimize unaligned reloc usage now that we know where
3212 it finally resides. */
3216 if (outrel
.r_offset
& 1)
3217 r_type
= R_SPARC_UA16
;
3220 if (!(outrel
.r_offset
& 1))
3221 r_type
= R_SPARC_16
;
3224 if (outrel
.r_offset
& 3)
3225 r_type
= R_SPARC_UA32
;
3228 if (!(outrel
.r_offset
& 3))
3229 r_type
= R_SPARC_32
;
3232 if (outrel
.r_offset
& 7)
3233 r_type
= R_SPARC_UA64
;
3236 if (!(outrel
.r_offset
& 7))
3237 r_type
= R_SPARC_64
;
3240 case R_SPARC_DISP16
:
3241 case R_SPARC_DISP32
:
3242 case R_SPARC_DISP64
:
3243 /* If the symbol is not dynamic, we should not keep
3244 a dynamic relocation. But an .rela.* slot has been
3245 allocated for it, output R_SPARC_NONE.
3246 FIXME: Add code tracking needed dynamic relocs as
3248 if (h
->dynindx
== -1)
3249 skip
= TRUE
, relocate
= TRUE
;
3254 memset (&outrel
, 0, sizeof outrel
);
3255 /* h->dynindx may be -1 if the symbol was marked to
3257 else if (h
!= NULL
&& ! is_plt
3258 && ((! info
->symbolic
&& h
->dynindx
!= -1)
3259 || !h
->def_regular
))
3261 BFD_ASSERT (h
->dynindx
!= -1);
3263 = ELF64_R_INFO (h
->dynindx
,
3265 ELF64_R_TYPE_DATA (rel
->r_info
),
3267 outrel
.r_addend
= rel
->r_addend
;
3271 if (r_type
== R_SPARC_64
)
3273 outrel
.r_info
= ELF64_R_INFO (0, R_SPARC_RELATIVE
);
3274 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3283 if (bfd_is_abs_section (sec
))
3285 else if (sec
== NULL
|| sec
->owner
== NULL
)
3287 bfd_set_error (bfd_error_bad_value
);
3294 osec
= sec
->output_section
;
3295 indx
= elf_section_data (osec
)->dynindx
;
3297 /* FIXME: we really should be able to link non-pic
3298 shared libraries. */
3302 (*_bfd_error_handler
)
3303 (_("%B: probably compiled without -fPIC?"),
3305 bfd_set_error (bfd_error_bad_value
);
3311 = ELF64_R_INFO (indx
,
3313 ELF64_R_TYPE_DATA (rel
->r_info
),
3315 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3319 loc
= sreloc
->contents
;
3320 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
3321 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
3323 /* This reloc will be computed at runtime, so there's no
3324 need to do anything now. */
3330 case R_SPARC_TLS_GD_HI22
:
3331 case R_SPARC_TLS_GD_LO10
:
3332 case R_SPARC_TLS_IE_HI22
:
3333 case R_SPARC_TLS_IE_LO10
:
3334 r_type
= sparc64_elf_tls_transition (info
, r_type
, h
== NULL
);
3335 tls_type
= GOT_UNKNOWN
;
3336 if (h
== NULL
&& local_got_offsets
)
3337 tls_type
= sparc64_elf_local_got_tls_type (input_bfd
) [r_symndx
];
3340 tls_type
= sparc64_elf_hash_entry(h
)->tls_type
;
3341 if (!info
->shared
&& h
->dynindx
== -1 && tls_type
== GOT_TLS_IE
)
3342 switch (ELF64_R_TYPE_ID (rel
->r_info
))
3344 case R_SPARC_TLS_GD_HI22
:
3345 case R_SPARC_TLS_IE_HI22
:
3346 r_type
= R_SPARC_TLS_LE_HIX22
;
3349 r_type
= R_SPARC_TLS_LE_LOX10
;
3353 if (tls_type
== GOT_TLS_IE
)
3356 case R_SPARC_TLS_GD_HI22
:
3357 r_type
= R_SPARC_TLS_IE_HI22
;
3359 case R_SPARC_TLS_GD_LO10
:
3360 r_type
= R_SPARC_TLS_IE_LO10
;
3364 if (r_type
== R_SPARC_TLS_LE_HIX22
)
3366 relocation
= tpoff (info
, relocation
);
3369 if (r_type
== R_SPARC_TLS_LE_LOX10
)
3371 /* Change add into xor. */
3372 relocation
= tpoff (info
, relocation
);
3373 bfd_put_32 (output_bfd
, (bfd_get_32 (input_bfd
,
3374 contents
+ rel
->r_offset
)
3375 | 0x80182000), contents
+ rel
->r_offset
);
3381 off
= h
->got
.offset
;
3386 BFD_ASSERT (local_got_offsets
!= NULL
);
3387 off
= local_got_offsets
[r_symndx
];
3388 local_got_offsets
[r_symndx
] |= 1;
3392 if (htab
->sgot
== NULL
)
3399 Elf_Internal_Rela outrel
;
3400 Elf64_External_Rela
*loc
;
3403 if (htab
->srelgot
== NULL
)
3406 bfd_put_64 (output_bfd
, 0, htab
->sgot
->contents
+ off
);
3407 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
3408 + htab
->sgot
->output_offset
+ off
);
3409 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3410 if (r_type
== R_SPARC_TLS_IE_HI22
3411 || r_type
== R_SPARC_TLS_IE_LO10
)
3412 dr_type
= R_SPARC_TLS_TPOFF64
;
3414 dr_type
= R_SPARC_TLS_DTPMOD64
;
3415 if (dr_type
== R_SPARC_TLS_TPOFF64
&& indx
== 0)
3416 outrel
.r_addend
= relocation
- dtpoff_base (info
);
3418 outrel
.r_addend
= 0;
3419 outrel
.r_info
= ELF64_R_INFO (indx
, dr_type
);
3420 loc
= (Elf64_External_Rela
*) htab
->srelgot
->contents
;
3421 loc
+= htab
->srelgot
->reloc_count
++;
3422 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
3425 if (r_type
== R_SPARC_TLS_GD_HI22
3426 || r_type
== R_SPARC_TLS_GD_LO10
)
3430 BFD_ASSERT (! unresolved_reloc
);
3431 bfd_put_64 (output_bfd
,
3432 relocation
- dtpoff_base (info
),
3433 htab
->sgot
->contents
+ off
+ 8);
3437 bfd_put_64 (output_bfd
, 0,
3438 htab
->sgot
->contents
+ off
+ 8);
3439 outrel
.r_info
= ELF64_R_INFO (indx
,
3440 R_SPARC_TLS_DTPOFF64
);
3441 outrel
.r_offset
+= 8;
3442 htab
->srelgot
->reloc_count
++;
3444 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
3448 else if (dr_type
== R_SPARC_TLS_DTPMOD64
)
3450 bfd_put_64 (output_bfd
, 0,
3451 htab
->sgot
->contents
+ off
+ 8);
3455 if (off
>= (bfd_vma
) -2)
3458 relocation
= htab
->sgot
->output_offset
+ off
- got_base
;
3459 unresolved_reloc
= FALSE
;
3460 howto
= sparc64_elf_howto_table
+ r_type
;
3463 case R_SPARC_TLS_LDM_HI22
:
3464 case R_SPARC_TLS_LDM_LO10
:
3467 bfd_put_32 (output_bfd
, SPARC_NOP
, contents
+ rel
->r_offset
);
3470 off
= htab
->tls_ldm_got
.offset
;
3471 htab
->tls_ldm_got
.offset
|= 1;
3472 goto r_sparc_tlsldm
;
3474 case R_SPARC_TLS_LDO_HIX22
:
3475 case R_SPARC_TLS_LDO_LOX10
:
3478 relocation
-= dtpoff_base (info
);
3482 r_type
= (r_type
== R_SPARC_TLS_LDO_HIX22
3483 ? R_SPARC_TLS_LE_HIX22
: R_SPARC_TLS_LE_LOX10
);
3486 case R_SPARC_TLS_LE_HIX22
:
3487 case R_SPARC_TLS_LE_LOX10
:
3490 Elf_Internal_Rela outrel
;
3491 bfd_boolean skip
, relocate
= FALSE
;
3493 BFD_ASSERT (sreloc
!= NULL
);
3496 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3498 if (outrel
.r_offset
== (bfd_vma
) -1)
3500 else if (outrel
.r_offset
== (bfd_vma
) -2)
3501 skip
= TRUE
, relocate
= TRUE
;
3502 outrel
.r_offset
+= (input_section
->output_section
->vma
3503 + input_section
->output_offset
);
3505 memset (&outrel
, 0, sizeof outrel
);
3508 outrel
.r_info
= ELF64_R_INFO (0, r_type
);
3509 outrel
.r_addend
= relocation
- dtpoff_base (info
)
3513 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
3514 (bfd_byte
*) (((Elf64_External_Rela
*)
3516 + sreloc
->reloc_count
));
3517 ++sreloc
->reloc_count
;
3520 relocation
= tpoff (info
, relocation
);
3523 case R_SPARC_TLS_LDM_CALL
:
3527 bfd_put_32 (output_bfd
, 0x90100000, contents
+ rel
->r_offset
);
3532 case R_SPARC_TLS_GD_CALL
:
3533 tls_type
= GOT_UNKNOWN
;
3534 if (h
== NULL
&& local_got_offsets
)
3535 tls_type
= sparc64_elf_local_got_tls_type (input_bfd
) [r_symndx
];
3537 tls_type
= sparc64_elf_hash_entry(h
)->tls_type
;
3539 || (r_type
== R_SPARC_TLS_GD_CALL
&& tls_type
== GOT_TLS_IE
))
3543 if (!info
->shared
&& (h
== NULL
|| h
->dynindx
== -1))
3546 bfd_put_32 (output_bfd
, SPARC_NOP
, contents
+ rel
->r_offset
);
3551 if (rel
+ 1 < relend
3552 && ELF64_R_TYPE_ID (rel
[1].r_info
) == R_SPARC_TLS_GD_ADD
3553 && rel
[1].r_offset
== rel
->r_offset
+ 4
3554 && ELF64_R_SYM (rel
[1].r_info
) == r_symndx
3555 && (((insn
= bfd_get_32 (input_bfd
,
3556 contents
+ rel
[1].r_offset
))
3557 >> 25) & 0x1f) == 8)
3560 call __tls_get_addr, %tgd_call(foo)
3561 add %reg1, %reg2, %o0, %tgd_add(foo)
3562 and change it into IE:
3563 ldx [%reg1 + %reg2], %o0, %tie_ldx(foo)
3564 add %g7, %o0, %o0, %tie_add(foo).
3565 add is 0x80000000 | (rd << 25) | (rs1 << 14) | rs2,
3566 ldx is 0xc0580000 | (rd << 25) | (rs1 << 14) | rs2. */
3567 bfd_put_32 (output_bfd
, insn
| 0xc0580000,
3568 contents
+ rel
->r_offset
);
3569 bfd_put_32 (output_bfd
, 0x9001c008,
3570 contents
+ rel
->r_offset
+ 4);
3575 bfd_put_32 (output_bfd
, 0x9001c008, contents
+ rel
->r_offset
);
3579 h
= (struct elf_link_hash_entry
*)
3580 bfd_link_hash_lookup (info
->hash
, "__tls_get_addr", FALSE
,
3582 BFD_ASSERT (h
!= NULL
);
3583 r_type
= R_SPARC_WPLT30
;
3584 howto
= sparc64_elf_howto_table
+ r_type
;
3585 goto r_sparc_wplt30
;
3587 case R_SPARC_TLS_GD_ADD
:
3588 tls_type
= GOT_UNKNOWN
;
3589 if (h
== NULL
&& local_got_offsets
)
3590 tls_type
= sparc64_elf_local_got_tls_type (input_bfd
) [r_symndx
];
3592 tls_type
= sparc64_elf_hash_entry(h
)->tls_type
;
3593 if (! info
->shared
|| tls_type
== GOT_TLS_IE
)
3595 /* add %reg1, %reg2, %reg3, %tgd_add(foo)
3597 ldx [%reg1 + %reg2], %reg3, %tie_ldx(foo)
3599 add %g7, %reg2, %reg3. */
3600 bfd_vma insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3601 if ((h
!= NULL
&& h
->dynindx
!= -1) || info
->shared
)
3602 relocation
= insn
| 0xc0580000;
3604 relocation
= (insn
& ~0x7c000) | 0x1c000;
3605 bfd_put_32 (output_bfd
, relocation
, contents
+ rel
->r_offset
);
3609 case R_SPARC_TLS_LDM_ADD
:
3611 bfd_put_32 (output_bfd
, SPARC_NOP
, contents
+ rel
->r_offset
);
3614 case R_SPARC_TLS_LDO_ADD
:
3617 /* Change rs1 into %g7. */
3618 bfd_vma insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3619 insn
= (insn
& ~0x7c000) | 0x1c000;
3620 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
3624 case R_SPARC_TLS_IE_LD
:
3625 case R_SPARC_TLS_IE_LDX
:
3626 if (! info
->shared
&& (h
== NULL
|| h
->dynindx
== -1))
3628 bfd_vma insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3629 int rs2
= insn
& 0x1f;
3630 int rd
= (insn
>> 25) & 0x1f;
3633 relocation
= SPARC_NOP
;
3635 relocation
= 0x80100000 | (insn
& 0x3e00001f);
3636 bfd_put_32 (output_bfd
, relocation
, contents
+ rel
->r_offset
);
3640 case R_SPARC_TLS_IE_ADD
:
3641 /* Totally useless relocation. */
3644 case R_SPARC_TLS_DTPOFF64
:
3645 relocation
-= dtpoff_base (info
);
3652 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3653 because such sections are not SEC_ALLOC and thus ld.so will
3654 not process them. */
3655 if (unresolved_reloc
3656 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
3658 (*_bfd_error_handler
)
3659 (_("%B(%A+0x%lx): unresolvable relocation against symbol `%s'"),
3662 (long) rel
->r_offset
,
3663 h
->root
.root
.string
);
3665 r
= bfd_reloc_continue
;
3666 if (r_type
== R_SPARC_OLO10
)
3670 relocation
+= rel
->r_addend
;
3671 relocation
= (relocation
& 0x3ff) + ELF64_R_TYPE_DATA (rel
->r_info
);
3673 x
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3674 x
= (x
& ~(bfd_vma
) 0x1fff) | (relocation
& 0x1fff);
3675 bfd_put_32 (input_bfd
, x
, contents
+ rel
->r_offset
);
3677 r
= bfd_check_overflow (howto
->complain_on_overflow
,
3678 howto
->bitsize
, howto
->rightshift
,
3679 bfd_arch_bits_per_address (input_bfd
),
3682 else if (r_type
== R_SPARC_WDISP16
)
3686 relocation
+= rel
->r_addend
;
3687 relocation
-= (input_section
->output_section
->vma
3688 + input_section
->output_offset
);
3689 relocation
-= rel
->r_offset
;
3691 x
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3692 x
|= ((((relocation
>> 2) & 0xc000) << 6)
3693 | ((relocation
>> 2) & 0x3fff));
3694 bfd_put_32 (input_bfd
, x
, contents
+ rel
->r_offset
);
3696 r
= bfd_check_overflow (howto
->complain_on_overflow
,
3697 howto
->bitsize
, howto
->rightshift
,
3698 bfd_arch_bits_per_address (input_bfd
),
3701 else if (r_type
== R_SPARC_TLS_LDO_HIX22
3702 || r_type
== R_SPARC_TLS_LE_HIX22
)
3706 relocation
+= rel
->r_addend
;
3707 if (r_type
== R_SPARC_TLS_LE_HIX22
)
3708 relocation
^= MINUS_ONE
;
3710 x
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3711 x
= (x
& ~(bfd_vma
) 0x3fffff) | ((relocation
>> 10) & 0x3fffff);
3712 bfd_put_32 (input_bfd
, x
, contents
+ rel
->r_offset
);
3715 if (r_type
== R_SPARC_TLS_LDO_LOX10
3716 || r_type
== R_SPARC_TLS_LE_LOX10
)
3720 relocation
+= rel
->r_addend
;
3721 relocation
&= 0x3ff;
3722 if (r_type
== R_SPARC_TLS_LE_LOX10
)
3723 relocation
|= 0x1c00;
3725 x
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3726 x
= (x
& ~(bfd_vma
) 0x1fff) | relocation
;
3727 bfd_put_32 (input_bfd
, x
, contents
+ rel
->r_offset
);
3731 else if (r_type
== R_SPARC_HIX22
)
3735 relocation
+= rel
->r_addend
;
3736 relocation
= relocation
^ MINUS_ONE
;
3738 x
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3739 x
= (x
& ~(bfd_vma
) 0x3fffff) | ((relocation
>> 10) & 0x3fffff);
3740 bfd_put_32 (input_bfd
, x
, contents
+ rel
->r_offset
);
3742 r
= bfd_check_overflow (howto
->complain_on_overflow
,
3743 howto
->bitsize
, howto
->rightshift
,
3744 bfd_arch_bits_per_address (input_bfd
),
3747 else if (r_type
== R_SPARC_LOX10
)
3751 relocation
+= rel
->r_addend
;
3752 relocation
= (relocation
& 0x3ff) | 0x1c00;
3754 x
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3755 x
= (x
& ~(bfd_vma
) 0x1fff) | relocation
;
3756 bfd_put_32 (input_bfd
, x
, contents
+ rel
->r_offset
);
3760 else if ((r_type
== R_SPARC_WDISP30
|| r_type
== R_SPARC_WPLT30
)
3761 && sec_do_relax (input_section
)
3762 && rel
->r_offset
+ 4 < input_section
->size
)
3766 #define XCC (2 << 20)
3767 #define COND(x) (((x)&0xf)<<25)
3768 #define CONDA COND(0x8)
3769 #define INSN_BPA (F2(0,1) | CONDA | BPRED | XCC)
3770 #define INSN_BA (F2(0,2) | CONDA)
3771 #define INSN_OR F3(2, 0x2, 0)
3772 #define INSN_NOP F2(0,4)
3776 /* If the instruction is a call with either:
3778 arithmetic instruction with rd == %o7
3779 where rs1 != %o7 and rs2 if it is register != %o7
3780 then we can optimize if the call destination is near
3781 by changing the call into a branch always. */
3782 x
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3783 y
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
3784 if ((x
& OP(~0)) == OP(1) && (y
& OP(~0)) == OP(2))
3786 if (((y
& OP3(~0)) == OP3(0x3d) /* restore */
3787 || ((y
& OP3(0x28)) == 0 /* arithmetic */
3788 && (y
& RD(~0)) == RD(O7
)))
3789 && (y
& RS1(~0)) != RS1(O7
)
3791 || (y
& RS2(~0)) != RS2(O7
)))
3795 reloc
= relocation
+ rel
->r_addend
- rel
->r_offset
;
3796 reloc
-= (input_section
->output_section
->vma
3797 + input_section
->output_offset
);
3799 /* Ensure the branch fits into simm22. */
3800 if ((reloc
& 3) == 0
3801 && ((reloc
& ~(bfd_vma
)0x7fffff) == 0
3802 || ((reloc
| 0x7fffff) == ~(bfd_vma
)0)))
3806 /* Check whether it fits into simm19. */
3807 if ((reloc
& 0x3c0000) == 0
3808 || (reloc
& 0x3c0000) == 0x3c0000)
3809 x
= INSN_BPA
| (reloc
& 0x7ffff); /* ba,pt %xcc */
3811 x
= INSN_BA
| (reloc
& 0x3fffff); /* ba */
3812 bfd_put_32 (input_bfd
, x
, contents
+ rel
->r_offset
);
3814 if (rel
->r_offset
>= 4
3815 && (y
& (0xffffffff ^ RS1(~0)))
3816 == (INSN_OR
| RD(O7
) | RS2(G0
)))
3821 z
= bfd_get_32 (input_bfd
,
3822 contents
+ rel
->r_offset
- 4);
3823 if ((z
& (0xffffffff ^ RD(~0)))
3824 != (INSN_OR
| RS1(O7
) | RS2(G0
)))
3832 If call foo was replaced with ba, replace
3833 or %rN, %g0, %o7 with nop. */
3835 reg
= (y
& RS1(~0)) >> 14;
3836 if (reg
!= ((z
& RD(~0)) >> 25)
3837 || reg
== G0
|| reg
== O7
)
3840 bfd_put_32 (input_bfd
, (bfd_vma
) INSN_NOP
,
3841 contents
+ rel
->r_offset
+ 4);
3849 if (r
== bfd_reloc_continue
)
3850 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3851 contents
, rel
->r_offset
,
3852 relocation
, rel
->r_addend
);
3854 if (r
!= bfd_reloc_ok
)
3859 case bfd_reloc_outofrange
:
3861 case bfd_reloc_overflow
:
3869 name
= bfd_elf_string_from_elf_section (input_bfd
,
3870 symtab_hdr
->sh_link
,
3875 name
= bfd_section_name (input_bfd
, sec
);
3877 if (! ((*info
->callbacks
->reloc_overflow
)
3878 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
3879 (bfd_vma
) 0, input_bfd
, input_section
,
3891 /* Finish up dynamic symbol handling. We set the contents of various
3892 dynamic sections here. */
3895 sparc64_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
3897 struct bfd_link_info
*info
;
3898 struct elf_link_hash_entry
*h
;
3899 Elf_Internal_Sym
*sym
;
3902 struct sparc64_elf_link_hash_table
*htab
;
3904 htab
= sparc64_elf_hash_table (info
);
3905 dynobj
= htab
->elf
.dynobj
;
3907 if (h
->plt
.offset
!= (bfd_vma
) -1)
3911 Elf_Internal_Rela rela
;
3916 /* This symbol has an entry in the PLT. Set it up. */
3918 BFD_ASSERT (h
->dynindx
!= -1);
3921 srela
= htab
->srelplt
;
3922 BFD_ASSERT (splt
!= NULL
&& srela
!= NULL
);
3924 /* Fill in the entry in the procedure linkage table. */
3925 rela_index
= sparc64_plt_entry_build (output_bfd
, splt
, h
->plt
.offset
,
3926 splt
->size
, &r_offset
);
3928 /* Fill in the entry in the .rela.plt section. */
3929 rela
.r_offset
= r_offset
3930 + (splt
->output_section
->vma
+ splt
->output_offset
);
3931 if (h
->plt
.offset
< (LARGE_PLT_THRESHOLD
* PLT_ENTRY_SIZE
))
3937 rela
.r_addend
= -(h
->plt
.offset
+ 4)
3938 -(splt
->output_section
->vma
+ splt
->output_offset
);
3940 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SPARC_JMP_SLOT
);
3942 /* Adjust for the first 4 reserved elements in the .plt section
3943 when setting the offset in the .rela.plt section.
3944 Sun forgot to read their own ABI and copied elf32-sparc behaviour,
3945 thus .plt[4] has corresponding .rela.plt[0] and so on. */
3947 loc
= srela
->contents
;
3948 loc
+= rela_index
* sizeof (Elf64_External_Rela
);
3949 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
3951 if (!h
->def_regular
)
3953 /* Mark the symbol as undefined, rather than as defined in
3954 the .plt section. Leave the value alone. */
3955 sym
->st_shndx
= SHN_UNDEF
;
3956 /* If the symbol is weak, we do need to clear the value.
3957 Otherwise, the PLT entry would provide a definition for
3958 the symbol even if the symbol wasn't defined anywhere,
3959 and so the symbol would never be NULL. */
3960 if (!h
->ref_regular_nonweak
)
3965 if (h
->got
.offset
!= (bfd_vma
) -1
3966 && sparc64_elf_hash_entry(h
)->tls_type
!= GOT_TLS_GD
3967 && sparc64_elf_hash_entry(h
)->tls_type
!= GOT_TLS_IE
)
3971 Elf_Internal_Rela rela
;
3974 /* This symbol has an entry in the GOT. Set it up. */
3977 srela
= htab
->srelgot
;
3978 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
3980 rela
.r_offset
= (sgot
->output_section
->vma
3981 + sgot
->output_offset
3982 + (h
->got
.offset
&~ (bfd_vma
) 1));
3984 /* If this is a -Bsymbolic link, and the symbol is defined
3985 locally, we just want to emit a RELATIVE reloc. Likewise if
3986 the symbol was forced to be local because of a version file.
3987 The entry in the global offset table will already have been
3988 initialized in the relocate_section function. */
3990 && (info
->symbolic
|| h
->dynindx
== -1)
3993 asection
*sec
= h
->root
.u
.def
.section
;
3994 rela
.r_info
= ELF64_R_INFO (0, R_SPARC_RELATIVE
);
3995 rela
.r_addend
= (h
->root
.u
.def
.value
3996 + sec
->output_section
->vma
3997 + sec
->output_offset
);
4001 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SPARC_GLOB_DAT
);
4005 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4006 sgot
->contents
+ (h
->got
.offset
&~ (bfd_vma
) 1));
4007 loc
= srela
->contents
;
4008 loc
+= srela
->reloc_count
++ * sizeof (Elf64_External_Rela
);
4009 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
4015 Elf_Internal_Rela rela
;
4018 /* This symbols needs a copy reloc. Set it up. */
4019 BFD_ASSERT (h
->dynindx
!= -1);
4021 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
4023 BFD_ASSERT (s
!= NULL
);
4025 rela
.r_offset
= (h
->root
.u
.def
.value
4026 + h
->root
.u
.def
.section
->output_section
->vma
4027 + h
->root
.u
.def
.section
->output_offset
);
4028 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SPARC_COPY
);
4030 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf64_External_Rela
);
4031 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
4034 /* Mark some specially defined symbols as absolute. */
4035 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4036 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
4037 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
4038 sym
->st_shndx
= SHN_ABS
;
4043 /* Finish up the dynamic sections. */
4046 sparc64_elf_finish_dynamic_sections (output_bfd
, info
)
4048 struct bfd_link_info
*info
;
4051 int stt_regidx
= -1;
4053 struct sparc64_elf_link_hash_table
*htab
;
4055 htab
= sparc64_elf_hash_table (info
);
4056 dynobj
= htab
->elf
.dynobj
;
4058 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4060 if (elf_hash_table (info
)->dynamic_sections_created
)
4063 Elf64_External_Dyn
*dyncon
, *dynconend
;
4065 splt
= bfd_get_section_by_name (dynobj
, ".plt");
4066 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
4068 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
4069 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4070 for (; dyncon
< dynconend
; dyncon
++)
4072 Elf_Internal_Dyn dyn
;
4076 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4080 case DT_PLTGOT
: name
= ".plt"; size
= FALSE
; break;
4081 case DT_PLTRELSZ
: name
= ".rela.plt"; size
= TRUE
; break;
4082 case DT_JMPREL
: name
= ".rela.plt"; size
= FALSE
; break;
4083 case DT_SPARC_REGISTER
:
4084 if (stt_regidx
== -1)
4087 _bfd_elf_link_lookup_local_dynindx (info
, output_bfd
, -1);
4088 if (stt_regidx
== -1)
4091 dyn
.d_un
.d_val
= stt_regidx
++;
4092 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4094 default: name
= NULL
; size
= FALSE
; break;
4101 s
= bfd_get_section_by_name (output_bfd
, name
);
4107 dyn
.d_un
.d_ptr
= s
->vma
;
4109 dyn
.d_un
.d_val
= s
->size
;
4111 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4115 /* Initialize the contents of the .plt section. */
4117 memset (splt
->contents
, 0, 4 * PLT_ENTRY_SIZE
);
4119 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
=
4123 /* Set the first entry in the global offset table to the address of
4124 the dynamic section. */
4125 if (htab
->sgot
&& htab
->sgot
->size
> 0)
4128 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->sgot
->contents
);
4130 bfd_put_64 (output_bfd
,
4131 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4132 htab
->sgot
->contents
);
4136 elf_section_data (htab
->sgot
->output_section
)->this_hdr
.sh_entsize
= 8;
4142 /* Functions for dealing with the e_flags field. */
4144 /* Merge backend specific data from an object file to the output
4145 object file when linking. */
4148 sparc64_elf_merge_private_bfd_data (ibfd
, obfd
)
4153 flagword new_flags
, old_flags
;
4156 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
4157 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
4160 new_flags
= elf_elfheader (ibfd
)->e_flags
;
4161 old_flags
= elf_elfheader (obfd
)->e_flags
;
4163 if (!elf_flags_init (obfd
)) /* First call, no flags set */
4165 elf_flags_init (obfd
) = TRUE
;
4166 elf_elfheader (obfd
)->e_flags
= new_flags
;
4169 else if (new_flags
== old_flags
) /* Compatible flags are ok */
4172 else /* Incompatible flags */
4176 #define EF_SPARC_ISA_EXTENSIONS \
4177 (EF_SPARC_SUN_US1 | EF_SPARC_SUN_US3 | EF_SPARC_HAL_R1)
4179 if ((ibfd
->flags
& DYNAMIC
) != 0)
4181 /* We don't want dynamic objects memory ordering and
4182 architecture to have any role. That's what dynamic linker
4184 new_flags
&= ~(EF_SPARCV9_MM
| EF_SPARC_ISA_EXTENSIONS
);
4185 new_flags
|= (old_flags
4186 & (EF_SPARCV9_MM
| EF_SPARC_ISA_EXTENSIONS
));
4190 /* Choose the highest architecture requirements. */
4191 old_flags
|= (new_flags
& EF_SPARC_ISA_EXTENSIONS
);
4192 new_flags
|= (old_flags
& EF_SPARC_ISA_EXTENSIONS
);
4193 if ((old_flags
& (EF_SPARC_SUN_US1
| EF_SPARC_SUN_US3
))
4194 && (old_flags
& EF_SPARC_HAL_R1
))
4197 (*_bfd_error_handler
)
4198 (_("%B: linking UltraSPARC specific with HAL specific code"),
4201 /* Choose the most restrictive memory ordering. */
4202 old_mm
= (old_flags
& EF_SPARCV9_MM
);
4203 new_mm
= (new_flags
& EF_SPARCV9_MM
);
4204 old_flags
&= ~EF_SPARCV9_MM
;
4205 new_flags
&= ~EF_SPARCV9_MM
;
4206 if (new_mm
< old_mm
)
4208 old_flags
|= old_mm
;
4209 new_flags
|= old_mm
;
4212 /* Warn about any other mismatches */
4213 if (new_flags
!= old_flags
)
4216 (*_bfd_error_handler
)
4217 (_("%B: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
4218 ibfd
, (long) new_flags
, (long) old_flags
);
4221 elf_elfheader (obfd
)->e_flags
= old_flags
;
4225 bfd_set_error (bfd_error_bad_value
);
4232 /* MARCO: Set the correct entry size for the .stab section. */
4235 sparc64_elf_fake_sections (abfd
, hdr
, sec
)
4236 bfd
*abfd ATTRIBUTE_UNUSED
;
4237 Elf_Internal_Shdr
*hdr ATTRIBUTE_UNUSED
;
4242 name
= bfd_get_section_name (abfd
, sec
);
4244 if (strcmp (name
, ".stab") == 0)
4246 /* Even in the 64bit case the stab entries are only 12 bytes long. */
4247 elf_section_data (sec
)->this_hdr
.sh_entsize
= 12;
4253 /* Print a STT_REGISTER symbol to file FILE. */
4256 sparc64_elf_print_symbol_all (abfd
, filep
, symbol
)
4257 bfd
*abfd ATTRIBUTE_UNUSED
;
4261 FILE *file
= (FILE *) filep
;
4264 if (ELF_ST_TYPE (((elf_symbol_type
*) symbol
)->internal_elf_sym
.st_info
)
4268 reg
= ((elf_symbol_type
*) symbol
)->internal_elf_sym
.st_value
;
4269 type
= symbol
->flags
;
4270 fprintf (file
, "REG_%c%c%11s%c%c R", "GOLI" [reg
/ 8], '0' + (reg
& 7), "",
4272 ? (type
& BSF_GLOBAL
) ? '!' : 'l'
4273 : (type
& BSF_GLOBAL
) ? 'g' : ' '),
4274 (type
& BSF_WEAK
) ? 'w' : ' ');
4275 if (symbol
->name
== NULL
|| symbol
->name
[0] == '\0')
4278 return symbol
->name
;
4281 /* Set the right machine number for a SPARC64 ELF file. */
4284 sparc64_elf_object_p (abfd
)
4287 unsigned long mach
= bfd_mach_sparc_v9
;
4289 if (elf_elfheader (abfd
)->e_flags
& EF_SPARC_SUN_US3
)
4290 mach
= bfd_mach_sparc_v9b
;
4291 else if (elf_elfheader (abfd
)->e_flags
& EF_SPARC_SUN_US1
)
4292 mach
= bfd_mach_sparc_v9a
;
4293 return bfd_default_set_arch_mach (abfd
, bfd_arch_sparc
, mach
);
4296 static enum elf_reloc_type_class
4297 sparc64_elf_reloc_type_class (rela
)
4298 const Elf_Internal_Rela
*rela
;
4300 switch ((int) ELF64_R_TYPE (rela
->r_info
))
4302 case R_SPARC_RELATIVE
:
4303 return reloc_class_relative
;
4304 case R_SPARC_JMP_SLOT
:
4305 return reloc_class_plt
;
4307 return reloc_class_copy
;
4309 return reloc_class_normal
;
4313 /* Return address for Ith PLT stub in section PLT, for relocation REL
4314 or (bfd_vma) -1 if it should not be included. */
4317 sparc64_elf_plt_sym_val (bfd_vma i
, const asection
*plt
,
4318 const arelent
*rel ATTRIBUTE_UNUSED
)
4322 i
+= PLT_HEADER_SIZE
/ PLT_ENTRY_SIZE
;
4323 if (i
< LARGE_PLT_THRESHOLD
)
4324 return plt
->vma
+ i
* PLT_ENTRY_SIZE
;
4326 j
= (i
- LARGE_PLT_THRESHOLD
) % 160;
4328 return plt
->vma
+ i
* PLT_ENTRY_SIZE
+ j
* 4 * 6;
4331 /* Relocations in the 64 bit SPARC ELF ABI are more complex than in
4332 standard ELF, because R_SPARC_OLO10 has secondary addend in
4333 ELF64_R_TYPE_DATA field. This structure is used to redirect the
4334 relocation handling routines. */
4336 const struct elf_size_info sparc64_elf_size_info
=
4338 sizeof (Elf64_External_Ehdr
),
4339 sizeof (Elf64_External_Phdr
),
4340 sizeof (Elf64_External_Shdr
),
4341 sizeof (Elf64_External_Rel
),
4342 sizeof (Elf64_External_Rela
),
4343 sizeof (Elf64_External_Sym
),
4344 sizeof (Elf64_External_Dyn
),
4345 sizeof (Elf_External_Note
),
4346 4, /* hash-table entry size. */
4347 /* Internal relocations per external relocations.
4348 For link purposes we use just 1 internal per
4349 1 external, for assembly and slurp symbol table
4352 64, /* arch_size. */
4353 3, /* log_file_align. */
4356 bfd_elf64_write_out_phdrs
,
4357 bfd_elf64_write_shdrs_and_ehdr
,
4358 sparc64_elf_write_relocs
,
4359 bfd_elf64_swap_symbol_in
,
4360 bfd_elf64_swap_symbol_out
,
4361 sparc64_elf_slurp_reloc_table
,
4362 bfd_elf64_slurp_symbol_table
,
4363 bfd_elf64_swap_dyn_in
,
4364 bfd_elf64_swap_dyn_out
,
4365 bfd_elf64_swap_reloc_in
,
4366 bfd_elf64_swap_reloc_out
,
4367 bfd_elf64_swap_reloca_in
,
4368 bfd_elf64_swap_reloca_out
4371 #define TARGET_BIG_SYM bfd_elf64_sparc_vec
4372 #define TARGET_BIG_NAME "elf64-sparc"
4373 #define ELF_ARCH bfd_arch_sparc
4374 #define ELF_MAXPAGESIZE 0x100000
4376 /* This is the official ABI value. */
4377 #define ELF_MACHINE_CODE EM_SPARCV9
4379 /* This is the value that we used before the ABI was released. */
4380 #define ELF_MACHINE_ALT1 EM_OLD_SPARCV9
4382 #define bfd_elf64_bfd_link_hash_table_create \
4383 sparc64_elf_link_hash_table_create
4385 #define elf_info_to_howto \
4386 sparc64_elf_info_to_howto
4387 #define elf_backend_copy_indirect_symbol \
4388 sparc64_elf_copy_indirect_symbol
4389 #define bfd_elf64_get_reloc_upper_bound \
4390 sparc64_elf_get_reloc_upper_bound
4391 #define bfd_elf64_get_dynamic_reloc_upper_bound \
4392 sparc64_elf_get_dynamic_reloc_upper_bound
4393 #define bfd_elf64_canonicalize_reloc \
4394 sparc64_elf_canonicalize_reloc
4395 #define bfd_elf64_canonicalize_dynamic_reloc \
4396 sparc64_elf_canonicalize_dynamic_reloc
4397 #define bfd_elf64_bfd_reloc_type_lookup \
4398 sparc64_elf_reloc_type_lookup
4399 #define bfd_elf64_bfd_relax_section \
4400 sparc64_elf_relax_section
4401 #define bfd_elf64_new_section_hook \
4402 sparc64_elf_new_section_hook
4404 #define elf_backend_create_dynamic_sections \
4405 sparc64_elf_create_dynamic_sections
4406 #define elf_backend_add_symbol_hook \
4407 sparc64_elf_add_symbol_hook
4408 #define elf_backend_get_symbol_type \
4409 sparc64_elf_get_symbol_type
4410 #define elf_backend_symbol_processing \
4411 sparc64_elf_symbol_processing
4412 #define elf_backend_check_relocs \
4413 sparc64_elf_check_relocs
4414 #define elf_backend_adjust_dynamic_symbol \
4415 sparc64_elf_adjust_dynamic_symbol
4416 #define elf_backend_omit_section_dynsym \
4417 sparc64_elf_omit_section_dynsym
4418 #define elf_backend_size_dynamic_sections \
4419 sparc64_elf_size_dynamic_sections
4420 #define elf_backend_relocate_section \
4421 sparc64_elf_relocate_section
4422 #define elf_backend_finish_dynamic_symbol \
4423 sparc64_elf_finish_dynamic_symbol
4424 #define elf_backend_finish_dynamic_sections \
4425 sparc64_elf_finish_dynamic_sections
4426 #define elf_backend_print_symbol_all \
4427 sparc64_elf_print_symbol_all
4428 #define elf_backend_output_arch_syms \
4429 sparc64_elf_output_arch_syms
4430 #define bfd_elf64_bfd_merge_private_bfd_data \
4431 sparc64_elf_merge_private_bfd_data
4432 #define elf_backend_fake_sections \
4433 sparc64_elf_fake_sections
4434 #define elf_backend_plt_sym_val \
4435 sparc64_elf_plt_sym_val
4437 #define elf_backend_size_info \
4438 sparc64_elf_size_info
4439 #define bfd_elf64_mkobject \
4440 sparc64_elf_mkobject
4441 #define elf_backend_object_p \
4442 sparc64_elf_object_p
4443 #define elf_backend_gc_mark_hook \
4444 sparc64_elf_gc_mark_hook
4445 #define elf_backend_gc_sweep_hook \
4446 sparc64_elf_gc_sweep_hook
4447 #define elf_backend_reloc_type_class \
4448 sparc64_elf_reloc_type_class
4450 #define elf_backend_can_gc_sections 1
4451 #define elf_backend_can_refcount 1
4452 #define elf_backend_want_got_plt 0
4453 #define elf_backend_plt_readonly 0
4454 #define elf_backend_want_plt_sym 1
4455 #define elf_backend_got_header_size 8
4456 #define elf_backend_rela_normal 1
4458 /* Section 5.2.4 of the ABI specifies a 256-byte boundary for the table. */
4459 #define elf_backend_plt_alignment 8
4461 #include "elf64-target.h"